From 228c1f9f1be3791327f7b4d61bb9fbe564446082 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 19 Dec 2016 18:51:04 +0100 Subject: [PATCH 0001/1006] #557 add Javadoc for the Accessor --- .../ap/internal/model/common/TypeFactory.java | 18 +++++---------- .../ap/internal/util/accessor/Accessor.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 83b2dd617d..d53f2c3cf0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -261,11 +261,13 @@ else if ( type.isPrimitive() ) { * Get the ExecutableType for given method as part of usedMapper. Possibly parameterized types in method declaration * will be evaluated to concrete types then. * + * IMPORTANT: This should only be used from the Processors, as they are operating over executable elements. + * The internals should not be using this function and should not be using the {@link ExecutableElement} directly. + * * @param includingType the type on which's scope the method type shall be evaluated * @param method the method * @return the ExecutableType representing the method as part of usedMapper */ - @Deprecated public ExecutableType getMethodType(DeclaredType includingType, ExecutableElement method) { TypeMirror asMemberOf = typeUtils.asMemberOf( includingType, method ); return (ExecutableType) asMemberOf; @@ -301,10 +303,11 @@ public Parameter getSingleParameter(DeclaredType includingType, Accessor method) public List getParameters(DeclaredType includingType, Accessor accessor) { ExecutableElement method = accessor.getExecutable(); - if ( method == null ) { + TypeMirror methodType = getMethodType( includingType, accessor.getElement() ); + if ( method == null || methodType.getKind() != TypeKind.EXECUTABLE ) { return new ArrayList(); } - return getParameters( getMethodType( includingType, method ), method ); + return getParameters( (ExecutableType) methodType, method ); } public List getParameters(ExecutableType methodType, ExecutableElement method) { @@ -330,11 +333,6 @@ public List getParameters(ExecutableType methodType, ExecutableElemen return result; } - @Deprecated - public Type getReturnType(DeclaredType includingType, ExecutableElement method) { - return getReturnType( getMethodType( includingType, method ) ); - } - public Type getReturnType(DeclaredType includingType, Accessor accessor) { Type type; TypeMirror accessorType = getMethodType( includingType, accessor.getElement() ); @@ -356,10 +354,6 @@ public Type getReturnType(ExecutableType method) { return getType( method.getReturnType() ); } - public List getThrownTypes(DeclaredType includingType, ExecutableElement method) { - return getThrownTypes( getMethodType( includingType, method ) ); - } - public List getThrownTypes(ExecutableType method) { List thrownTypes = new ArrayList(); for ( TypeMirror exceptionType : method.getThrownTypes() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index 0fa3dec8ce..aaa4e49d9a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -26,17 +26,39 @@ import javax.lang.model.type.TypeMirror; /** + * This represents an Accessor that can be used for writing/reading a property to/from a bean. + * * @author Filip Hrisafov */ public interface Accessor { + /** + * This returns the type that this accessor gives as a return. + * + * e.g. The {@link ExecutableElement#getReturnType()} if this is a method accessor, + * or {@link javax.lang.model.element.VariableElement#asType()} for field accessors. + * + * @return the type that the accessor gives as a return + */ TypeMirror getAccessedType(); + /** + * @return the simple name of the accessor + */ Name getSimpleName(); + /** + * @return the set of modifiers that the accessor has + */ Set getModifiers(); + /** + * @return the {@link ExecutableElement}, or {@code null} if the accessor does not have one + */ ExecutableElement getExecutable(); + /** + * @return the underlying {@link Element} + */ Element getElement(); } From 81ce66044fd47e97a4096634e5216eed6032fda8 Mon Sep 17 00:00:00 2001 From: navpil Date: Thu, 29 Sep 2016 11:11:59 +0300 Subject: [PATCH 0002/1006] #60 automapping --- parent/pom.xml | 2 +- .../ap/internal/model/BeanMappingMethod.java | 135 +++++++++++++--- .../internal/model/IterableMappingMethod.java | 87 ++++++++--- .../ap/internal/model/MapMappingMethod.java | 98 +++++++++--- .../ap/internal/model/MappingMethod.java | 31 +++- .../ap/internal/model/PropertyMapping.java | 144 ++++++++++++++---- .../internal/model/source/ForgedMethod.java | 59 ++++++- .../model/source/ForgedMethodHistory.java | 65 ++++++++ .../processor/MapperCreationProcessor.java | 113 +++++++++++--- .../creation/MappingResolverImpl.java | 20 +-- .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../ReferencedMapperDefaultSame.java | 2 +- .../referenced/ReferencedMapperPrivate.java | 2 +- .../referenced/ReferencedMapperProtected.java | 2 +- .../referenced/ReferencedTarget.java | 10 +- .../SourceTargetmapperPrivateBase.java | 2 +- .../SourceTargetmapperProtectedBase.java | 2 +- .../a/ReferencedMapperDefaultOther.java | 2 +- .../ErroneousCollectionMappingTest.java | 12 +- .../mapstruct/ap/test/nestedbeans/Car.java | 100 ++++++++++++ .../mapstruct/ap/test/nestedbeans/CarDto.java | 100 ++++++++++++ .../mapstruct/ap/test/nestedbeans/House.java | 100 ++++++++++++ .../ap/test/nestedbeans/HouseDto.java | 98 ++++++++++++ .../NestedSimpleBeansMappingTest.java | 54 +++++++ .../mapstruct/ap/test/nestedbeans/Roof.java | 46 ++++++ .../ap/test/nestedbeans/RoofDto.java | 66 ++++++++ .../ap/test/nestedbeans/TestData.java | 40 +++++ .../TestMultipleForgedMethodsTest.java | 52 +++++++ .../mapstruct/ap/test/nestedbeans/User.java | 98 ++++++++++++ .../ap/test/nestedbeans/UserDto.java | 98 ++++++++++++ .../nestedbeans/UserDtoMapperClassic.java | 43 ++++++ .../test/nestedbeans/UserDtoMapperSmart.java | 31 ++++ .../mapstruct/ap/test/nestedbeans/Wheel.java | 99 ++++++++++++ .../ap/test/nestedbeans/WheelDto.java | 80 ++++++++++ .../test/nestedbeans/maps/AutoMapMapper.java | 31 ++++ .../ap/test/nestedbeans/maps/Bar.java | 32 ++++ .../ap/test/nestedbeans/maps/BarDto.java | 32 ++++ .../ap/test/nestedbeans/maps/Dto.java | 34 +++++ .../ap/test/nestedbeans/maps/Entity.java | 34 +++++ .../multiplecollections/Garage.java | 45 ++++++ .../multiplecollections/GarageDto.java | 46 ++++++ .../MultipleListMapper.java | 31 ++++ .../selection/generics/ConversionTest.java | 3 +- .../selection/generics/ErroneousTarget6.java | 6 +- .../ErroneousCompanyMapper1.java | 4 +- .../updatemethods/UnmappableCompanyDto.java | 46 ++++++ .../UnmappableDepartmentDto.java | 58 +++++++ .../test/updatemethods/UpdateMethodsTest.java | 7 +- 49 files changed, 2143 insertions(+), 162 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java diff --git a/parent/pom.xml b/parent/pom.xml index 8ac6ba1add..4a1fc84fd6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -46,7 +46,7 @@ 2.19.1 2.10.3 4.0.3.RELEASE - 0.23.1 + 0.26.0 7.2 1 diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 7f416519d2..24dffe5a20 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -47,7 +47,10 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; @@ -78,11 +81,12 @@ public class BeanMappingMethod extends MappingMethod { private final boolean mapNullToDefault; private final Type resultType; private final NestedTargetObjects nestedTargetObjects; + private final boolean overridden; public static class Builder { private MappingBuilderContext ctx; - private SourceMethod method; + private Method method; private Map unprocessedTargetProperties; private Set targetProperties; private final List propertyMappings = new ArrayList(); @@ -91,6 +95,8 @@ public static class Builder { private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet(); private NestedTargetObjects nestedTargetObjects; + private Map> methodMappings; + private SingleMappingByTargetPropertyNameFunction singleMapping; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -98,14 +104,25 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { } public Builder souceMethod(SourceMethod sourceMethod) { + singleMapping = new SourceMethodSingleMapping( sourceMethod ); + return setupMethodWithMapping( sourceMethod, sourceMethod.getMappingOptions().getMappings() ); + } + + public Builder forgedMethod(Method sourceMethod) { + singleMapping = new EmptySingleMapping(); + return setupMethodWithMapping( sourceMethod, Collections.>emptyMap() ); + } + + private Builder setupMethodWithMapping(Method sourceMethod, Map> mappings) { this.method = sourceMethod; + this.methodMappings = mappings; CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); Map accessors = method.getResultType().getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); this.nestedTargetObjects = new NestedTargetObjects.Builder() .existingVariableNames( existingVariableNames ) - .mappings( method.getMappingOptions().getMappings() ) + .mappings( mappings ) .mappingBuilderContext( ctx ) .sourceMethod( method ) .build(); @@ -155,7 +172,8 @@ public BeanMappingMethod build() { factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), - selectionParameters ); + selectionParameters + ); } // if there's no factory method, try the resultType in the @BeanMapping @@ -183,6 +201,11 @@ public BeanMappingMethod build() { List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); + List allForgedMethods = new ArrayList(); + for ( PropertyMapping propertyMapping : propertyMappings ) { + allForgedMethods.addAll( propertyMapping.getForgedMethods() ); + } + return new BeanMappingMethod( method, propertyMappings, @@ -192,7 +215,8 @@ public BeanMappingMethod build() { existingVariableNames, beforeMappingMethods, afterMappingMethods, - nestedTargetObjects + nestedTargetObjects, + allForgedMethods ); } @@ -248,7 +272,7 @@ private boolean handleDefinedSourceMappings() { boolean errorOccurred = false; Set handledTargets = new HashSet(); - for ( Map.Entry> entry : method.getMappingOptions().getMappings().entrySet() ) { + for ( Map.Entry> entry : methodMappings.entrySet() ) { for ( Mapping mapping : entry.getValue() ) { PropertyMapping propertyMapping = null; @@ -259,10 +283,11 @@ private boolean handleDefinedSourceMappings() { resultPropertyName = first( targetRef.getPropertyEntries() ).getName(); } - if (!unprocessedTargetProperties.containsKey( resultPropertyName ) ) { - boolean hasReadAccessor = + if ( !unprocessedTargetProperties.containsKey( resultPropertyName ) ) { + boolean hasReadAccessor = method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), hasReadAccessor ? Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE : @@ -415,7 +440,8 @@ private void applyPropertyNameBasedMapping() { sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); if ( sourceReadAccessor != null ) { - Mapping mapping = method.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); + Mapping mapping = singleMapping.getSingleMappingByTargetPropertyName( + targetProperty.getKey() ); DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); SourceReference sourceRef = new SourceReference.BuilderFromProperty() @@ -480,7 +506,7 @@ private void applyParameterNameBasedMapping() { Parameter sourceParameter = sourceParameters.next(); if ( sourceParameter.getName().equals( targetProperty.getKey() ) ) { - Mapping mapping = method.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); + Mapping mapping = singleMapping.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) @@ -523,7 +549,43 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { // fetch settings from element to implement ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); - if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { + //we handle forged methods differently than the usual source ones. in + if ( method instanceof ForgedMethod ) { + if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { + + ForgedMethod forgedMethod = (ForgedMethod) this.method; + + if ( forgedMethod.getHistory() == null ) { + Type sourceType = this.method.getParameters().get( 0 ).getType(); + Type targetType = this.method.getReturnType(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, + sourceType, + targetType, + targetType, + sourceType + ); + } + else { + ForgedMethodHistory history = forgedMethod.getHistory(); + while ( history.getPrevHistory() != null ) { + history = history.getPrevHistory(); + } + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + history.getSourceElement(), + history.getTargetType(), + history.getTargetPropertyName(), + history.getTargetType(), + history.getSourceType() + ); + } + + } + } + else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; @@ -541,7 +603,7 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { } } - private BeanMappingMethod(SourceMethod method, + private BeanMappingMethod(Method method, List propertyMappings, MethodReference factoryMethod, boolean mapNullToDefault, @@ -549,8 +611,9 @@ private BeanMappingMethod(SourceMethod method, Collection existingVariableNames, List beforeMappingReferences, List afterMappingReferences, - NestedTargetObjects nestedTargetObjects ) { - super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences ); + NestedTargetObjects nestedTargetObjects, + List allForgedMethods) { + super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences, allForgedMethods ); this.propertyMappings = propertyMappings; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a @@ -571,6 +634,7 @@ private BeanMappingMethod(SourceMethod method, this.mapNullToDefault = mapNullToDefault; this.resultType = resultType; this.nestedTargetObjects = nestedTargetObjects.init( this.getResultName() ); + this.overridden = method.overridesMethod(); } public List getPropertyMappings() { @@ -597,6 +661,10 @@ public boolean isMapNullToDefault() { return mapNullToDefault; } + public boolean isOverridden() { + return overridden; + } + @Override public Type getResultType() { if ( resultType == null ) { @@ -644,7 +712,7 @@ public MethodReference getFactoryMethod() { return this.factoryMethod; } - private static class NestedTargetObjects { + private static class NestedTargetObjects { private final Set localVariables; private final Set nestedAssignments; @@ -664,7 +732,7 @@ private static class Builder { private Map> mappings; private Set existingVariableNames; private MappingBuilderContext ctx; - private SourceMethod method; + private Method method; private Builder mappings(Map> mappings) { this.mappings = mappings; @@ -681,7 +749,7 @@ private Builder mappingBuilderContext(MappingBuilderContext ctx) { return this; } - private Builder sourceMethod(SourceMethod method) { + private Builder sourceMethod(Method method) { this.method = method; return this; } @@ -748,7 +816,7 @@ private NestedTargetObjects build() { } private NestedTargetObjects(Set localVariables, Map localVariableNames, - Set relations) { + Set relations) { this.localVariables = localVariables; this.localVariableNames = localVariableNames; this.nestedAssignments = relations; @@ -757,7 +825,8 @@ private NestedTargetObjects(Set localVariables, Map(), + "collection element" ); Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, targetElementType, null, // there is no targetPropertyName formattingParameters, selectionParameters, - new SourceRHS( loopVariableName, sourceElementType, new HashSet(), "collection element" ), + sourceRHS, false ); if ( assignment == null ) { - if ( method instanceof ForgedMethod ) { - // leave messaging to calling property mapping - return null; - } - else { - ctx.getMessager().printMessage( method.getExecutable(), Message.ITERABLEMAPPING_MAPPING_NOT_FOUND ); - } + + assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); + } else { if ( method instanceof ForgedMethod ) { @@ -140,7 +140,7 @@ public IterableMappingMethod build() { // mapNullToDefault boolean mapNullToDefault = false; if ( method.getMapperConfiguration() != null ) { - mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); + mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); } MethodReference factoryMethod = null; @@ -163,23 +163,66 @@ public IterableMappingMethod build() { existingVariables ); return new IterableMappingMethod( - method, - assignment, - factoryMethod, - mapNullToDefault, - loopVariableName, - beforeMappingMethods, - afterMappingMethods, - selectionParameters ); + method, + assignment, + factoryMethod, + mapNullToDefault, + loopVariableName, + beforeMappingMethods, + afterMappingMethods, + selectionParameters, + forgedMethod + ); } + + private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + + ForgedMethodHistory forgedMethodHistory = null; + if ( method instanceof ForgedMethod ) { + forgedMethodHistory = ( (ForgedMethod) method ).getHistory(); + } + String name = getName( sourceType, targetType ); + forgedMethod = new ForgedMethod( + name, + sourceType, + targetType, + method.getMapperConfiguration(), + method.getExecutable(), + forgedMethodHistory + ); + + Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + assignment.setAssignment( sourceRHS ); + + return assignment; + } + + private String getName(Type sourceType, Type targetType) { + String fromName = getName( sourceType ); + String toName = getName( targetType ); + return Strings.decapitalize( fromName + "To" + toName ); + } + + private String getName(Type type) { + StringBuilder builder = new StringBuilder(); + for ( Type typeParam : type.getTypeParameters() ) { + builder.append( typeParam.getIdentification() ); + } + builder.append( type.getIdentification() ); + return builder.toString(); + } + } private IterableMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, - List beforeMappingReferences, - List afterMappingReferences, - SelectionParameters selectionParameters ) { - super( method, beforeMappingReferences, afterMappingReferences ); + List beforeMappingReferences, + List afterMappingReferences, + SelectionParameters selectionParameters, ForgedMethod forgedMethod) { + super( method, beforeMappingReferences, afterMappingReferences, + forgedMethod == null ? Collections.emptyList() : + java.util.Collections.singletonList( forgedMethod ) + ); this.elementAssignment = parameterAssignment; this.factoryMethod = factoryMethod; this.overridden = method.overridesMethod(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index bb43f2b84c..0471f01bea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -20,6 +20,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -30,11 +31,11 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; /** @@ -60,6 +61,7 @@ public static class Builder { private NullValueMappingStrategyPrism nullValueMappingStrategy; private SelectionParameters keySelectionParameters; private SelectionParameters valueSelectionParameters; + private List forgedMethods = new ArrayList(); public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -106,38 +108,43 @@ public MapMappingMethod build() { Type keySourceType = sourceTypeParams.get( 0 ).getTypeBound(); Type keyTargetType = resultTypeParams.get( 0 ).getTypeBound(); + SourceRHS keySourceRHS = new SourceRHS( "entry.getKey()", keySourceType, new HashSet(), "map key" ); Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method, keyTargetType, null, // there is no targetPropertyName keyFormattingParameters, keySelectionParameters, - new SourceRHS( "entry.getKey()", keySourceType, new HashSet(), "map key" ), + keySourceRHS, false ); if ( keyAssignment == null ) { - if ( method instanceof ForgedMethod ) { - // leave messaging to calling property mapping - return null; - } - else { - ctx.getMessager().printMessage( method.getExecutable(), - Message.MAPMAPPING_KEY_MAPPING_NOT_FOUND ); - } + + keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); +// if ( method instanceof ForgedMethod ) { +// // leave messaging to calling property mapping +// return null; +// } +// else { +// ctx.getMessager().printMessage( method.getExecutable(), +// Message.MAPMAPPING_KEY_MAPPING_NOT_FOUND ); +// } } // find mapping method or conversion for value Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound(); Type valueTargetType = resultTypeParams.get( 1 ).getTypeBound(); + SourceRHS valueSourceRHS = new SourceRHS( "entry.getValue()", valueSourceType, new HashSet(), + "map value" ); Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method, valueTargetType, null, // there is no targetPropertyName valueFormattingParameters, valueSelectionParameters, - new SourceRHS( "entry.getValue()", valueSourceType, new HashSet(), "map value" ), + valueSourceRHS, false ); @@ -152,20 +159,23 @@ public MapMappingMethod build() { } if ( valueAssignment == null ) { - if ( method instanceof ForgedMethod ) { - // leave messaging to calling property mapping - return null; - } - else { - ctx.getMessager().printMessage( method.getExecutable(), - Message.MAPMAPPING_VALUE_MAPPING_NOT_FOUND ); - } + + valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); + +// if ( method instanceof ForgedMethod ) { +// // leave messaging to calling property mapping +// return null; +// } +// else { +// ctx.getMessager().printMessage( method.getExecutable(), +// Message.MAPMAPPING_VALUE_MAPPING_NOT_FOUND ); +// } } // mapNullToDefault boolean mapNullToDefault = false; if ( method.getMapperConfiguration() != null ) { - mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); + mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); } MethodReference factoryMethod = null; @@ -189,16 +199,58 @@ public MapMappingMethod build() { factoryMethod, mapNullToDefault, beforeMappingMethods, - afterMappingMethods + afterMappingMethods, + forgedMethods + ); + } + + private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + + String name = getName( sourceType, targetType ); + ForgedMethodHistory history = null; + if ( method instanceof ForgedMethod ) { + history = ( (ForgedMethod) method ).getHistory(); + } + ForgedMethod forgedMethod = new ForgedMethod( + name, + sourceType, + targetType, + method.getMapperConfiguration(), + method.getExecutable(), + history ); + + Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + assignment.setAssignment( sourceRHS ); + + forgedMethods.add( forgedMethod ); + + return assignment; } + + private String getName(Type sourceType, Type targetType) { + String fromName = getName( sourceType ); + String toName = getName( targetType ); + return Strings.decapitalize( fromName + "To" + toName ); + } + + private String getName(Type type) { + StringBuilder builder = new StringBuilder(); + for ( Type typeParam : type.getTypeParameters() ) { + builder.append( typeParam.getIdentification() ); + } + builder.append( type.getIdentification() ); + return builder.toString(); + } + } private MapMappingMethod(Method method, Assignment keyAssignment, Assignment valueAssignment, MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, - List afterMappingReferences) { - super( method, beforeMappingReferences, afterMappingReferences ); + List afterMappingReferences, + List forgedMethods) { + super( method, beforeMappingReferences, afterMappingReferences, forgedMethods ); this.keyAssignment = keyAssignment; this.valueAssignment = valueAssignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 48b55d4c5c..59416d86ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -31,6 +32,7 @@ import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; /** @@ -51,6 +53,7 @@ public abstract class MappingMethod extends ModelElement { private final List beforeMappingReferencesWithMappingTarget; private final List beforeMappingReferencesWithoutMappingTarget; private final List afterMappingReferences; + private final List forgedMethods; /** * constructor to be overloaded when local variable names are required prior to calling this constructor. (e.g. for @@ -64,12 +67,14 @@ public abstract class MappingMethod extends ModelElement { protected MappingMethod(Method method, Collection existingVariableNames, List beforeMappingReferences, List afterMappingReferences) { - this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences ); + this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences, + Collections.emptyList() ); } protected MappingMethod(Method method, List parameters, Collection existingVariableNames, List beforeMappingReferences, - List afterMappingReferences) { + List afterMappingReferences, + List forgedMethods) { this.name = method.getName(); this.parameters = parameters; this.returnType = method.getReturnType(); @@ -81,10 +86,11 @@ protected MappingMethod(Method method, List parameters, Collection parameters) { - this( method, parameters, method.getParameterNames(), null, null ); + this( method, parameters, method.getParameterNames(), null, null, Collections.emptyList() ); } protected MappingMethod(Method method) { @@ -96,6 +102,21 @@ protected MappingMethod(Method method, List be this( method, method.getParameterNames(), beforeMappingReferences, afterMappingReferences ); } + protected MappingMethod(Method method, List beforeMappingReferences, + List afterMappingReferences, + List forgedMethods) { + this( method, method.getParameters(), method.getParameterNames(), beforeMappingReferences, + afterMappingReferences, forgedMethods ); + } + + public MappingMethod(Method method, Collection existingVariableNames, + List beforeMappingReferences, + List afterMappingReferences, + List allForgedMethods) { + this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences, + allForgedMethods ); + } + private String initResultName(Collection existingVarNames) { if ( targetParameter != null ) { return targetParameter.getName(); @@ -221,4 +242,8 @@ public List getBeforeMappingReferencesWithMapp public List getBeforeMappingReferencesWithoutMappingTarget() { return beforeMappingReferencesWithoutMappingTarget; } + + public List getForgedMethods() { + return forgedMethods; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 052de7a3af..7dae55e7a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -26,6 +26,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -48,10 +49,11 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -78,6 +80,11 @@ public class PropertyMapping extends ModelElement { private final Assignment assignment; private final List dependsOn; private final Assignment defaultValueAssignment; + private List forgedMethods = new ArrayList(); + + public List getForgedMethods() { + return forgedMethods; + } private enum TargetWriteAccessorType { FIELD, @@ -105,7 +112,7 @@ else if ( Executables.isGetterMethod( accessor ) ) { private static class MappingBuilderBase> { protected MappingBuilderContext ctx; - protected SourceMethod method; + protected Method method; protected Accessor targetWriteAccessor; protected TargetWriteAccessorType targetWriteAccessorType; @@ -123,12 +130,12 @@ public T mappingContext(MappingBuilderContext mappingContext) { return (T) this; } - public T sourceMethod(SourceMethod sourceMethod) { + public T sourceMethod(Method sourceMethod) { this.method = sourceMethod; return (T) this; } - public T targetProperty( PropertyEntry targetProp ) { + public T targetProperty(PropertyEntry targetProp) { this.targetReadAccessor = targetProp.getReadAccessor(); this.targetWriteAccessor = targetProp.getWriteAccessor(); this.targetType = targetProp.getType(); @@ -155,7 +162,7 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { return (T) this; } - public T localTargetVarName( String localTargetVarName ) { + public T localTargetVarName(String localTargetVarName) { this.localTargetVarName = localTargetVarName; return (T) this; } @@ -206,6 +213,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase forgedMethods = new ArrayList(); public PropertyMappingBuilder sourceReference(SourceReference sourceReference) { this.sourceReference = sourceReference; @@ -261,6 +269,9 @@ public PropertyMapping build() { else if ( sourceType.isMapType() && targetType.isMapType() ) { assignment = forgeMapMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); } + else { + assignment = forgeMapping( rightHandSide ); + } } if ( assignment != null ) { @@ -295,7 +306,8 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get localTargetVarName, assignment, dependsOn, - getDefaultValueAssignment( assignment ) + getDefaultValueAssignment( assignment ), + forgedMethods ); } @@ -304,24 +316,24 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { && ( !rhs.getSourceType().isPrimitive() || rhs.getSourcePresenceCheckerReference() != null) ) { // cannot check on null source if source is primitive unless it has a presenche checker PropertyMapping build = new ConstantMappingBuilder() - .constantExpression( '"' + defaultValue + '"' ) - .formattingParameters( formattingParameters ) - .selectionParameters( selectionParameters ) - .dependsOn( dependsOn ) - .existingVariableNames( existingVariableNames ) - .mappingContext( ctx ) - .sourceMethod( method ) - .targetPropertyName( targetPropertyName ) - .targetReadAccessor( targetReadAccessor ) - .targetWriteAccessor( targetWriteAccessor ) - .build(); + .constantExpression( '"' + defaultValue + '"' ) + .formattingParameters( formattingParameters ) + .selectionParameters( selectionParameters ) + .dependsOn( dependsOn ) + .existingVariableNames( existingVariableNames ) + .mappingContext( ctx ) + .sourceMethod( method ) + .targetPropertyName( targetPropertyName ) + .targetReadAccessor( targetReadAccessor ) + .targetWriteAccessor( targetWriteAccessor ) + .build(); return build.getAssignment(); } return null; } private Assignment assignToPlain(Type sourceType, Type targetType, TargetWriteAccessorType targetAccessorType, - Assignment rightHandSide) { + Assignment rightHandSide) { Assignment result; @@ -342,9 +354,11 @@ private Assignment assignToPlainViaSetter(Type sourceType, Type targetType, Assi if ( rhs.isUpdateMethod() ) { if ( targetReadAccessor == null ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, - targetPropertyName ); + targetPropertyName + ); } Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); result = new UpdateWrapper( rhs, method.getThrownTypes(), factoryMethod, @@ -428,9 +442,11 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t if ( result.isUpdateMethod() ) { // call to an update method if ( targetReadAccessor == null ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, - targetPropertyName ); + targetPropertyName + ); } Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); result = new UpdateWrapper( @@ -569,7 +585,7 @@ private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { } private Assignment forgeIterableMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + ExecutableElement element) { Assignment assignment = null; String name = getName( sourceType, targetType ); @@ -577,7 +593,14 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); - ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element ); + ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element, + new ForgedMethodHistory( getForgedMethodHistory( source ), + source.getSourceErrorMessagePart(), + targetPropertyName, + source.getSourceType(), + targetType + ) + ); IterableMappingMethod.Builder builder = new IterableMappingMethod.Builder(); IterableMappingMethod iterableMappingMethod = builder @@ -597,13 +620,15 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source assignment = new MethodReference( methodRef, null, targetType ); assignment.setAssignment( source ); + + forgedMethods.addAll( iterableMappingMethod.getForgedMethods() ); } return assignment; } private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + ExecutableElement element) { Assignment assignment = null; @@ -612,7 +637,14 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); - ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element ); + ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element, + new ForgedMethodHistory( getForgedMethodHistory( source ), + source.getSourceErrorMessagePart(), + targetPropertyName, + source.getSourceType(), + targetType + ) + ); MapMappingMethod.Builder builder = new MapMappingMethod.Builder(); MapMappingMethod mapMappingMethod = builder @@ -630,12 +662,51 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s } assignment = new MethodReference( methodRef, null, targetType ); assignment.setAssignment( source ); + + forgedMethods.addAll( mapMappingMethod.getForgedMethods() ); + } + + return assignment; + } + + private Assignment forgeMapping(SourceRHS sourceRHS) { + + Type sourceType = sourceRHS.getSourceType(); + + //Fail fast. If we could not find the method by now, no need to try + if ( sourceType.isPrimitive() || targetType.isPrimitive() ) { + return null; } + String name = getName( sourceType, targetType ); + ForgedMethod forgedMethod = new ForgedMethod( + name, + sourceType, + targetType, + method.getMapperConfiguration(), + method.getExecutable(), + getForgedMethodHistory( sourceRHS ) + ); + + Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + assignment.setAssignment( sourceRHS ); + + this.forgedMethods.add( forgedMethod ); return assignment; } - private String getName(Type sourceType, Type targetType ) { + private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { + ForgedMethodHistory history = null; + if ( method instanceof ForgedMethod ) { + ForgedMethod method = (ForgedMethod) this.method; + history = method.getHistory(); + } + return new ForgedMethodHistory( history, sourceRHS.getSourceErrorMessagePart(), + targetPropertyName, sourceRHS.getSourceType(), targetType + ); + } + + private String getName(Type sourceType, Type targetType) { String fromName = getName( sourceType ); String toName = getName( targetType ); return Strings.decapitalize( fromName + "To" + toName ); @@ -702,9 +773,11 @@ public PropertyMapping build() { // target accessor is setter, so decorate assignment as setter if ( assignment.isUpdateMethod() ) { if ( targetReadAccessor == null ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), Message.CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, - targetPropertyName ); + targetPropertyName + ); } Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); @@ -760,7 +833,8 @@ private Assignment getEnumAssignment() { assignment = new EnumConstantWrapper( assignment, targetType ); } else { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), Message.CONSTANTMAPPING_NON_EXISTING_CONSTANT, constantExpression, targetType, @@ -819,13 +893,15 @@ private PropertyMapping(String name, String targetWriteAccessorName, Type targetType, String localTargetVarName, Assignment propertyAssignment, List dependsOn, Assignment defaultValueAssignment ) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, - targetType, localTargetVarName, propertyAssignment, dependsOn, defaultValueAssignment ); + targetType, localTargetVarName, propertyAssignment, dependsOn, defaultValueAssignment, + Collections.emptyList() ); } private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, ValueProvider targetReadAccessorProvider, Type targetType, String localTargetVarName, Assignment assignment, - List dependsOn, Assignment defaultValueAssignment ) { + List dependsOn, Assignment defaultValueAssignment, + List forgedMethods) { this.name = name; this.sourceBeanName = sourceBeanName; this.targetWriteAccessorName = targetWriteAccessorName; @@ -836,6 +912,7 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.assignment = assignment; this.dependsOn = dependsOn != null ? dependsOn : Collections.emptyList(); this.defaultValueAssignment = defaultValueAssignment; + this.forgedMethods = forgedMethods; } /** @@ -882,7 +959,8 @@ public Set getImportTypes() { return org.mapstruct.ap.internal.util.Collections.asSet( assignment.getImportTypes(), - defaultValueAssignment.getImportTypes() ); + defaultValueAssignment.getImportTypes() + ); } public List getDependsOn() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 6662c13cd1..f0e74a6d51 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -45,8 +45,9 @@ public class ForgedMethod implements Method { private final ExecutableElement positionHintElement; private final List thrownTypes; private final MapperConfiguration mapperConfiguration; + private ForgedMethodHistory history; - /** + /** * Creates a new forged method with the given name. * * @param name the (unique name) for this method @@ -67,6 +68,29 @@ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfigu this.positionHintElement = positionHintElement; } + /** + * Creates a new forged method with the given name. + * + * @param name the (unique name) for this method + * @param sourceType the source type + * @param targetType the target type. + * @param mapperConfiguration the mapper configuration + * @param positionHintElement element used to for reference to the position in the source file. + * @param history a parent forged method if this is a forged method within a forged method + */ + public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfiguration mapperConfiguration, + ExecutableElement positionHintElement, ForgedMethodHistory history) { + String sourceParamName = Strings.decapitalize( sourceType.getName() ); + String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); + this.parameters = Arrays.asList( new Parameter( sourceParamSafeName, sourceType ) ); + this.returnType = targetType; + this.thrownTypes = new ArrayList(); + this.name = Strings.sanitizeIdentifierName( name ); + this.mapperConfiguration = mapperConfiguration; + this.positionHintElement = positionHintElement; + this.history = history; + } + /** * creates a new ForgedMethod with the same arguments but with a new name * @param name the new name @@ -144,6 +168,10 @@ public List getThrownTypes() { return thrownTypes; } + public ForgedMethodHistory getHistory() { + return history; + } + public void addThrownTypes(List thrownTypesToAdd) { for ( Type thrownType : thrownTypesToAdd ) { // make sure there are no duplicates coming from the keyAssignment thrown types. @@ -226,4 +254,33 @@ public boolean isUpdateMethod() { public boolean isObjectFactory() { return false; } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + ForgedMethod that = (ForgedMethod) o; + + if ( parameters != null ? !parameters.equals( that.parameters ) : that.parameters != null ) { + return false; + } + if ( returnType != null ? !returnType.equals( that.returnType ) : that.returnType != null ) { + return false; + } + return name != null ? name.equals( that.name ) : that.name == null; + + } + + @Override + public int hashCode() { + int result = parameters != null ? parameters.hashCode() : 0; + result = 31 * result + ( returnType != null ? returnType.hashCode() : 0 ); + result = 31 * result + ( name != null ? name.hashCode() : 0 ); + return result; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java new file mode 100644 index 0000000000..e6d79dba0b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java @@ -0,0 +1,65 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source; + +import org.mapstruct.ap.internal.model.common.Type; + +/** + * Keeps the context where the ForgedMethod is generated, especially handy with nested forged methods + * + * @author Dmytro Polovinkin + */ +public class ForgedMethodHistory { + + private final ForgedMethodHistory prevHistory; + private final String sourceElement; + private final String targetPropertyName; + private final Type targetType; + private final Type sourceType; + + public ForgedMethodHistory(ForgedMethodHistory history, String sourceElement, String targetPropertyName, + Type sourceType, Type targetType) { + prevHistory = history; + this.sourceElement = sourceElement; + this.targetPropertyName = targetPropertyName; + this.sourceType = sourceType; + this.targetType = targetType; + } + + public String getSourceElement() { + return sourceElement; + } + + public String getTargetPropertyName() { + return targetPropertyName; + } + + public Type getTargetType() { + return targetType; + } + + public Type getSourceType() { + return sourceType; + } + + public ForgedMethodHistory getPrevHistory() { + return prevHistory; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index e41fa17329..9dea5d0a94 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -23,8 +23,12 @@ import static org.mapstruct.ap.internal.util.Collections.join; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; @@ -50,8 +54,10 @@ import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; @@ -106,11 +112,13 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L elementUtils, typeUtils, typeFactory, - sourceModel, + new ArrayList( sourceModel ), mapperReferences ), mapperTypeElement, - sourceModel, + //sourceModel is passed only to fetch the after/before mapping methods in lifecycleCallbackFactory; + //Consider removing those methods directly into MappingBuilderContext. + Collections.unmodifiableList( sourceModel ), mapperReferences ); this.mappingContext = ctx; @@ -143,7 +151,7 @@ private List initReferencedMappers(TypeElement element, MapperC private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List methods) { List mapperReferences = mappingContext.getMapperReferences(); - List mappingMethods = getMappingMethods( mapperConfig, methods ); + List mappingMethods = getAllMappingMethods( mapperConfig, methods ); mappingMethods.addAll( mappingContext.getUsedVirtualMappings() ); mappingMethods.addAll( mappingContext.getMappingsToGenerate() ); @@ -154,7 +162,7 @@ private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, .options( options ) .versionInformation( versionInformation ) .decorator( getDecorator( element, methods, mapperConfig.implementationName(), - mapperConfig.implementationPackage() ) ) + mapperConfig.implementationPackage() ) ) .typeFactory( typeFactory ) .elementUtils( elementUtils ) .extraImports( getExtraImports( element ) ) @@ -190,7 +198,7 @@ private Decorator getDecorator(TypeElement element, List methods, } } Type declaringMapper = mappingMethod.getDeclaringMapper(); - if ( implementationRequired && !( mappingMethod.isDefault() || mappingMethod.isStatic()) ) { + if ( implementationRequired && !( mappingMethod.isDefault() || mappingMethod.isStatic() ) ) { if ( ( declaringMapper == null ) || declaringMapper.equals( typeFactory.getType( element ) ) ) { mappingMethods.add( new DelegatingMethod( mappingMethod ) ); } @@ -218,18 +226,18 @@ else if ( constructor.getParameters().size() == 1 ) { } Decorator decorator = new Decorator.Builder() - .elementUtils( elementUtils ) - .typeFactory( typeFactory ) - .mapperElement( element ) - .decoratorPrism( decoratorPrism ) - .methods( mappingMethods ) - .hasDelegateConstructor( hasDelegateConstructor ) - .options( options ) - .versionInformation( versionInformation ) + .elementUtils( elementUtils ) + .typeFactory( typeFactory ) + .mapperElement( element ) + .decoratorPrism( decoratorPrism ) + .methods( mappingMethods ) + .hasDelegateConstructor( hasDelegateConstructor ) + .options( options ) + .versionInformation( versionInformation ) .implName( implName ) .implPackage( implPackage ) .extraImports( getExtraImports( element ) ) - .build(); + .build(); return decorator; } @@ -252,6 +260,62 @@ private SortedSet getExtraImports(TypeElement element) { return extraImports; } + private List getAllMappingMethods(MapperConfiguration mapperConfig, List methods) { + List mappingMethods = getMappingMethods( mapperConfig, methods ); + + Collection excludedForgedMethods = new HashSet( ); + Collection forgedMethods = collectAllForgedMethods( mappingMethods, excludedForgedMethods ); + + while ( !forgedMethods.isEmpty() ) { + List mappingMethodsFromForged = createBeanMapping( forgedMethods ); + forgedMethods = collectAllForgedMethods( mappingMethodsFromForged, excludedForgedMethods ); + mappingMethods.addAll( mappingMethodsFromForged ); + } + + return mappingMethods; + } + + private List createBeanMapping(Collection forgedMethods) { + List mappingMethods = new ArrayList(); + + for ( ForgedMethod method : forgedMethods ) { + + BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); + BeanMappingMethod beanMappingMethod = builder + .mappingContext( mappingContext ) + .forgedMethod( method ) + .build(); + + + if ( beanMappingMethod != null ) { + boolean hasFactoryMethod = beanMappingMethod.getFactoryMethod() != null; + mappingMethods.add( beanMappingMethod ); + if ( !hasFactoryMethod ) { + // A factory method is allowed to return an interface type and hence, the generated + // implementation as well. The check below must only be executed if there's no factory + // method that could be responsible. + reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType( method ); + } + } + } + + return mappingMethods; + } + + private Collection collectAllForgedMethods(Collection mappingMethods, + Collection excludedForgedMethods) { + Set forgedMethods = new HashSet(); + for ( MappingMethod mappingMethod : mappingMethods ) { + for ( ForgedMethod forgedMethod : mappingMethod.getForgedMethods() ) { + if ( !excludedForgedMethods.contains( forgedMethod )) { + forgedMethods.add( forgedMethod ); + excludedForgedMethods.add( forgedMethod ); + } + } + } + return forgedMethods; + } + private List getMappingMethods(MapperConfiguration mapperConfig, List methods) { List mappingMethods = new ArrayList(); @@ -435,7 +499,7 @@ else if ( applicablePrototypeMethods.size() > 1 ) { mappingOptions.markAsFullyInitialized(); } - private void reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType(SourceMethod method) { + private void reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType(Method method) { if ( method.getReturnType().getTypeMirror().getKind() != TypeKind.VOID && method.getReturnType().isInterface() && method.getReturnType().getImplementationType() == null ) { @@ -542,7 +606,7 @@ private MappingOptions getTemplateMappingOptions(List rawMethods, method.getExecutable() ); - if (forwardPrism != null) { + if ( forwardPrism != null ) { reportErrorWhenInheritForwardAlsoHasInheritReverseMapping( method ); List candidates = new ArrayList(); @@ -594,7 +658,7 @@ else if ( nameFilteredcandidates.size() > 1 ) { private void reportErrorWhenInheritForwardAlsoHasInheritReverseMapping(SourceMethod method) { InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( - method.getExecutable() + method.getExecutable() ); if ( reversePrism != null ) { messager.printMessage( method.getExecutable(), reversePrism.mirror, Message.INHERITCONFIGURATION_BOTH ); @@ -631,7 +695,7 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } private void reportErrorWhenNoSuitableConstrutor( SourceMethod method, - InheritInverseConfigurationPrism reversePrism) { + InheritInverseConfigurationPrism reversePrism ) { messager.printMessage( method.getExecutable(), reversePrism.mirror, @@ -654,7 +718,7 @@ private void reportErrorWhenSeveralNamesMatch(List candidates, Sou } private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, - InheritInverseConfigurationPrism reversePrism) { + InheritInverseConfigurationPrism reversePrism) { messager.printMessage( method.getExecutable(), reversePrism.mirror, @@ -665,7 +729,7 @@ private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMe } private void reportErrorWhenAmbigousMapping(List candidates, SourceMethod method, - InheritConfigurationPrism prism) { + InheritConfigurationPrism prism) { List candidateNames = new ArrayList(); for ( SourceMethod candidate : candidates ) { @@ -681,7 +745,8 @@ private void reportErrorWhenAmbigousMapping(List candidates, Sourc ); } else { - messager.printMessage( method.getExecutable(), + messager.printMessage( + method.getExecutable(), prism.mirror, Message.INHERITCONFIGURATION_INVALIDNAME, Strings.join( candidateNames, "(), " ), @@ -693,7 +758,8 @@ private void reportErrorWhenAmbigousMapping(List candidates, Sourc private void reportErrorWhenSeveralNamesMatch(List candidates, SourceMethod method, InheritConfigurationPrism prism) { - messager.printMessage( method.getExecutable(), + messager.printMessage( + method.getExecutable(), prism.mirror, Message.INHERITCONFIGURATION_DUPLICATE_MATCHES, prism.name(), @@ -704,7 +770,8 @@ private void reportErrorWhenSeveralNamesMatch(List candidates, Sou private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, InheritConfigurationPrism prims) { - messager.printMessage( method.getExecutable(), + messager.printMessage( + method.getExecutable(), prims.mirror, Message.INHERITCONFIGURATION_NO_NAME_MATCH, prims.name(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 4d6fe508a3..4287a596cf 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -75,7 +75,7 @@ public class MappingResolverImpl implements MappingResolver { private final Types typeUtils; private final TypeFactory typeFactory; - private final List sourceModel; + private final List sourceModel; private final List mapperReferences; private final Conversions conversions; @@ -89,7 +89,7 @@ public class MappingResolverImpl implements MappingResolver { private final Set usedVirtualMappings = new HashSet(); public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, - TypeFactory typeFactory, List sourceModel, + TypeFactory typeFactory, List sourceModel, List mapperReferences) { this.messager = messager; this.typeUtils = typeUtils; @@ -143,12 +143,12 @@ public MethodReference getFactoryMethod(final Method mappingMethod, Type targetT ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, mappingMethod, null, null, null, criteria ); - List matchingSourceMethods = attempt.getMatches( sourceModel, null, targetType ); + List matchingSourceMethods = attempt.getMatches( sourceModel, null, targetType ); List factoryRefsWithAssigments = new ArrayList(); - List factoryRefSources = new ArrayList(); + List factoryRefSources = new ArrayList(); - for ( SourceMethod matchingSourceMethod : matchingSourceMethods ) { + for ( Method matchingSourceMethod : matchingSourceMethods ) { if ( matchingSourceMethod != null ) { MapperReference ref = attempt.findMapperReference( matchingSourceMethod ); @@ -197,7 +197,7 @@ else if ( factoryRefsWithAssigments.size() == 1 ) { private class ResolvingAttempt { private final Method mappingMethod; - private final List methods; + private final List methods; private final String dateFormat; private final String numberFormat; private final SelectionCriteria selectionCriteria; @@ -209,7 +209,7 @@ private class ResolvingAttempt { // so this set must be cleared. private final Set virtualMethodCandidates; - private ResolvingAttempt(List sourceModel, Method mappingMethod, String dateFormat, + private ResolvingAttempt(List sourceModel, Method mappingMethod, String dateFormat, String numberFormat, SourceRHS sourceRHS, SelectionCriteria criteria) { this.mappingMethod = mappingMethod; @@ -315,7 +315,7 @@ private Assignment resolveViaConversion(Type sourceType, Type targetType) { private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean considerBuiltInMethods) { // first try to find a matching source method - SourceMethod matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); + Method matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); if ( matchingSourceMethod != null ) { return getMappingMethodReference( matchingSourceMethod, targetType ); @@ -539,7 +539,7 @@ private T getBestMatch(List methods, Type sourceType, Type return null; } - private Assignment getMappingMethodReference(SourceMethod method, + private Assignment getMappingMethodReference(Method method, Type targetType) { MapperReference mapperReference = findMapperReference( method ); @@ -549,7 +549,7 @@ private Assignment getMappingMethodReference(SourceMethod method, ); } - private MapperReference findMapperReference(SourceMethod method) { + private MapperReference findMapperReference(Method method) { for ( MapperReference ref : mapperReferences ) { if ( ref.getType().equals( method.getDeclaringMapper() ) ) { ref.setUsed( !method.isStatic() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index bace188b0a..f1fe928610 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -40,6 +40,7 @@ public enum Message { BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), + PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "Can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ), PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 40d565700b..662d3cb581 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -18,7 +18,7 @@ limitations under the License. --> -@Override +<#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java index fcb6b496ee..e3024786b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java @@ -26,7 +26,7 @@ public class ReferencedMapperDefaultSame { ReferencedTarget sourceToTarget( ReferencedSource source ) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java index 53192f8e90..25a10af57a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java @@ -26,7 +26,7 @@ public class ReferencedMapperPrivate { @SuppressWarnings("unused") private ReferencedTarget sourceToTarget(ReferencedSource source) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java index 0e8edb9297..2a9a4aa3ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java @@ -26,7 +26,7 @@ public class ReferencedMapperProtected { protected ReferencedTarget sourceToTarget( ReferencedSource source ) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java index 1b0523e8da..16ef5d57f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java @@ -22,13 +22,13 @@ * @author Sjaak Derksen */ public class ReferencedTarget { - private String foo; + private String bar; - public String getFoo() { - return foo; + public String getBar() { + return bar; } - public void setFoo(String foo) { - this.foo = foo; + public void setBar(String bar) { + this.bar = bar; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java index 9534707cb9..082642d6cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java @@ -26,7 +26,7 @@ public class SourceTargetmapperPrivateBase { @SuppressWarnings("unused") private ReferencedTarget sourceToTarget(ReferencedSource source) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java index fb387ecf7c..cb10ccea3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java @@ -26,7 +26,7 @@ public class SourceTargetmapperProtectedBase { protected ReferencedTarget sourceToTarget( ReferencedSource source ) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java index 75c1fdda12..b22065c235 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java @@ -30,7 +30,7 @@ public class ReferencedMapperDefaultOther { ReferencedTarget sourceToTarget( ReferencedSource source ) { ReferencedTarget target = new ReferencedTarget(); - target.setFoo( source.getFoo() ); + target.setBar( source.getFoo() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index feba68fe21..de5c0f5d3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -115,8 +115,8 @@ public void shouldFailOnEmptyMapAnnotation() { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "No implementation can be generated for this method. Found no method nor implicit " - + "conversion for mapping source element type into target element type.") + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFound() { @@ -131,8 +131,8 @@ public void shouldFailOnNoElementMappingFound() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "No implementation can be generated for this method. Found no method nor implicit " - + "conversion for mapping source key type to target key type.") + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoKeyMappingFound() { @@ -147,8 +147,8 @@ public void shouldFailOnNoKeyMappingFound() { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "No implementation can be generated for this method. Found no method nor implicit " - + "conversion for mapping source value type to target value type.") + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoValueMappingFound() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java new file mode 100644 index 0000000000..9b0f3422ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java @@ -0,0 +1,100 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.List; + +public class Car { + + private String name; + private int year; + private List wheels; + + public Car() { + } + + public Car(String name, int year, List wheels) { + this.name = name; + this.year = year; + this.wheels = wheels; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public List getWheels() { + return wheels; + } + + public void setWheels(List wheels) { + this.wheels = wheels; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Car car = (Car) o; + + if ( year != car.year ) { + return false; + } + if ( name != null ? !name.equals( car.name ) : car.name != null ) { + return false; + } + return wheels != null ? wheels.equals( car.wheels ) : car.wheels == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( wheels != null ? wheels.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "Car{" + + "name='" + name + '\'' + + ", year=" + year + + ", wheels=" + wheels + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java new file mode 100644 index 0000000000..7c8caa550b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java @@ -0,0 +1,100 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.List; + +public class CarDto { + + private String name; + private int year; + private List wheels; + + public CarDto() { + } + + public CarDto(String name, int year, List wheels) { + this.name = name; + this.year = year; + this.wheels = wheels; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public List getWheels() { + return wheels; + } + + public void setWheels(List wheels) { + this.wheels = wheels; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + CarDto carDto = (CarDto) o; + + if ( year != carDto.year ) { + return false; + } + if ( name != null ? !name.equals( carDto.name ) : carDto.name != null ) { + return false; + } + return wheels != null ? wheels.equals( carDto.wheels ) : carDto.wheels == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( wheels != null ? wheels.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "CarDto{" + + "name='" + name + '\'' + + ", year=" + year + + ", wheels=" + wheels + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java new file mode 100644 index 0000000000..7a3159f066 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java @@ -0,0 +1,100 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class House { + + private String name; + private int year; + private Roof roof; + + public House() { + } + + public House(String name, int year, Roof roof) { + + + this.name = name; + this.year = year; + this.roof = roof; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public Roof getRoof() { + return roof; + } + + public void setRoof(Roof roof) { + this.roof = roof; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + House house = (House) o; + + if ( year != house.year ) { + return false; + } + if ( name != null ? !name.equals( house.name ) : house.name != null ) { + return false; + } + return roof != null ? roof.equals( house.roof ) : house.roof == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( roof != null ? roof.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "House{" + + "name='" + name + '\'' + + ", year=" + year + + ", roof=" + roof + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java new file mode 100644 index 0000000000..0d13ff0657 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class HouseDto { + + private String name; + private int year; + private RoofDto roof; + + public HouseDto() { + } + + public HouseDto(String name, int year, RoofDto roof) { + this.name = name; + this.year = year; + this.roof = roof; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public RoofDto getRoof() { + return roof; + } + + public void setRoof(RoofDto roof) { + this.roof = roof; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + HouseDto houseDto = (HouseDto) o; + + if ( year != houseDto.year ) { + return false; + } + if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) { + return false; + } + return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( roof != null ? roof.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "HouseDto{" + + "name='" + name + '\'' + + ", year=" + year + + ", roof=" + roof + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java new file mode 100644 index 0000000000..e365e7c981 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -0,0 +1,54 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + User.class, UserDto.class, Car.class, CarDto.class, House.class, HouseDto.class, + Wheel.class, WheelDto.class, + Roof.class, RoofDto.class, + UserDtoMapperClassic.class, + UserDtoMapperSmart.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class NestedSimpleBeansMappingTest { + + @Test + public void shouldMapNestedBeans() { + + User user = TestData.createUser(); + + UserDto classicMapping = UserDtoMapperClassic.INSTANCE.userToUserDto( user ); + UserDto smartMapping = UserDtoMapperSmart.INSTANCE.userToUserDto( user ); + + System.out.println( smartMapping ); + System.out.println( classicMapping ); + + + assertThat( smartMapping ).isNotNull(); + assertThat( smartMapping ).isEqualTo( classicMapping ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java new file mode 100644 index 0000000000..5d46847158 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class Roof { + private int color; + + public Roof() { + } + + public Roof(int color) { + this.color = color; + } + + public int getColor() { + return color; + } + + public void setColor(int color) { + this.color = color; + } + + @Override + public String toString() { + return "Roof{" + + "color='" + color + '\'' + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java new file mode 100644 index 0000000000..102ff8a3c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class RoofDto { + private String color; + + public RoofDto() { + } + + public RoofDto(String color) { + this.color = color; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + RoofDto roofDto = (RoofDto) o; + + return color != null ? color.equals( roofDto.color ) : roofDto.color == null; + + } + + @Override + public int hashCode() { + return color != null ? color.hashCode() : 0; + } + + @Override + public String toString() { + return "RoofDto{" + + "color='" + color + '\'' + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java new file mode 100644 index 0000000000..607c481cab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.Arrays; + +public class TestData { + + private TestData() { + + } + + public static User createUser() { + return new User( "John", new Car( "Chrysler", 1955, Arrays.asList( + new Wheel().front().left(), + new Wheel().front().right(), + new Wheel().rear().left(), + new Wheel().rear().right() + ) ), + new House( "Black", 1834, new Roof( 1 ) ) + ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java new file mode 100644 index 0000000000..13e1537d18 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper; +import org.mapstruct.ap.test.nestedbeans.maps.Bar; +import org.mapstruct.ap.test.nestedbeans.maps.BarDto; +import org.mapstruct.ap.test.nestedbeans.maps.Dto; +import org.mapstruct.ap.test.nestedbeans.maps.Entity; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@RunWith(AnnotationProcessorTestRunner.class) +public class TestMultipleForgedMethodsTest { + + @WithClasses({ + Bar.class, BarDto.class, Dto.class, Entity.class, AutoMapMapper.class + }) + @Test + public void testNestedMapsAutoMap() { + AutoMapMapper.INSTANCE.entityToDto( new Dto() ); + } + + @WithClasses( {MultipleListMapper.class, Garage.class, GarageDto.class, Car.class, CarDto.class, + Wheel.class, WheelDto.class}) + @Test + public void testMultipleCollections() { + MultipleListMapper.INSTANCE.convert( new Garage() ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java new file mode 100644 index 0000000000..f528022124 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class User { + + private String name; + private Car car; + private House house; + + public User() { + } + + public User(String name, Car car, House house) { + this.name = name; + this.car = car; + this.house = house; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Car getCar() { + return car; + } + + public void setCar(Car car) { + this.car = car; + } + + public House getHouse() { + return house; + } + + public void setHouse(House house) { + this.house = house; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + User user = (User) o; + + if ( name != null ? !name.equals( user.name ) : user.name != null ) { + return false; + } + if ( car != null ? !car.equals( user.car ) : user.car != null ) { + return false; + } + return house != null ? house.equals( user.house ) : user.house == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( car != null ? car.hashCode() : 0 ); + result = 31 * result + ( house != null ? house.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "User{" + + "name='" + name + '\'' + + ", car=" + car + + ", house=" + house + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java new file mode 100644 index 0000000000..b6d86fda67 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class UserDto { + + private String name; + private CarDto car; + private HouseDto house; + + public UserDto() { + } + + public UserDto(String name, CarDto car, HouseDto house) { + this.name = name; + this.car = car; + this.house = house; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public CarDto getCar() { + return car; + } + + public void setCar(CarDto car) { + this.car = car; + } + + public HouseDto getHouse() { + return house; + } + + public void setHouse(HouseDto house) { + this.house = house; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + UserDto userDto = (UserDto) o; + + if ( name != null ? !name.equals( userDto.name ) : userDto.name != null ) { + return false; + } + if ( car != null ? !car.equals( userDto.car ) : userDto.car != null ) { + return false; + } + return house != null ? house.equals( userDto.house ) : userDto.house == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( car != null ? car.hashCode() : 0 ); + result = 31 * result + ( house != null ? house.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "UserDto{" + + "name='" + name + '\'' + + ", car=" + car + + ", house=" + house + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java new file mode 100644 index 0000000000..9c6b8b2106 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +@Mapper +public interface UserDtoMapperClassic { + + UserDtoMapperClassic INSTANCE = Mappers.getMapper( UserDtoMapperClassic.class ); + + UserDto userToUserDto(User user); + + CarDto carToCarDto(Car car); + + HouseDto houseToHouseDto(House house); + + RoofDto roofToRoofDto(Roof roof); + + List mapWheels(List wheels); + + WheelDto mapWheel(Wheel wheels); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java new file mode 100644 index 0000000000..caf115b410 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface UserDtoMapperSmart { + + UserDtoMapperSmart INSTANCE = Mappers.getMapper( UserDtoMapperSmart.class ); + + UserDto userToUserDto(User user); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java new file mode 100644 index 0000000000..036aaabdce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java @@ -0,0 +1,99 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class Wheel { + private boolean front; + private boolean right; + + public Wheel() { + } + + public Wheel(boolean front, boolean right) { + this.front = front; + this.right = right; + } + + public boolean isFront() { + return front; + } + + public void setFront(boolean front) { + this.front = front; + } + + public boolean isRight() { + return right; + } + + public void setRight(boolean right) { + this.right = right; + } + + public Wheel left() { + return new Wheel( this.front, false ); + } + + public Wheel right() { + return new Wheel( this.front, true ); + } + + public Wheel front() { + return new Wheel( true, this.right ); + } + + public Wheel rear() { + return new Wheel( false, this.right ); + } + + @Override + public boolean equals(Object o) { + + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Wheel wheel = (Wheel) o; + + if ( front != wheel.front ) { + return false; + } + return right == wheel.right; + + } + + @Override + public int hashCode() { + int result = ( front ? 1 : 0 ); + result = 31 * result + ( right ? 1 : 0 ); + return result; + } + + @Override + public String toString() { + return "Wheel{" + + "front=" + front + + ", right=" + right + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java new file mode 100644 index 0000000000..8f25508d5d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java @@ -0,0 +1,80 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +public class WheelDto { + private boolean front; + private boolean right; + + public WheelDto() { + } + + public WheelDto(boolean front, boolean right) { + this.front = front; + this.right = right; + } + + public boolean isFront() { + return front; + } + + public void setFront(boolean front) { + this.front = front; + } + + public boolean isRight() { + return right; + } + + public void setRight(boolean right) { + this.right = right; + } + + @Override + public boolean equals(Object o) { + + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + WheelDto wheel = (WheelDto) o; + + if ( front != wheel.front ) { + return false; + } + return right == wheel.right; + + } + + @Override + public int hashCode() { + int result = ( front ? 1 : 0 ); + result = 31 * result + ( right ? 1 : 0 ); + return result; + } + + @Override + public String toString() { + return "Wheel{" + ( front ? "front" : "rear" ) + ";" + ( right ? "right" : "left" ) + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java new file mode 100644 index 0000000000..5789376f8a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.maps; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface AutoMapMapper { + + AutoMapMapper INSTANCE = Mappers.getMapper( AutoMapMapper.class ); + + Entity entityToDto(Dto dto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java new file mode 100644 index 0000000000..17ed99c5dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.maps; + +public class Bar { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java new file mode 100644 index 0000000000..4ce5d23140 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.maps; + +public class BarDto { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java new file mode 100644 index 0000000000..6f1738d504 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.maps; + +import java.util.Map; + +public class Dto { + private Map map; + + public Map getMap() { + return map; + } + + public void setMap( Map map) { + this.map = map; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java new file mode 100644 index 0000000000..c05cbfc9a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.maps; + +import java.util.Map; + +public class Entity { + private Map map; + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java new file mode 100644 index 0000000000..5b7f112da5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.multiplecollections; + +import java.util.List; + +import org.mapstruct.ap.test.nestedbeans.Car; + +public class Garage { + private List cars; + private List usedCars; + + public List getCars() { + return cars; + } + + public void setCars(List cars) { + this.cars = cars; + } + + public List getUsedCars() { + return usedCars; + } + + public void setUsedCars(List usedCars) { + this.usedCars = usedCars; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java new file mode 100644 index 0000000000..d37b523049 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.multiplecollections; + +import java.util.List; + +import org.mapstruct.ap.test.nestedbeans.CarDto; + +public class GarageDto { + + private List cars; + private List usedCars; + + public List getCars() { + return cars; + } + + public void setCars(List cars) { + this.cars = cars; + } + + public List getUsedCars() { + return usedCars; + } + + public void setUsedCars(List usedCars) { + this.usedCars = usedCars; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java new file mode 100644 index 0000000000..c2777eea1d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.multiplecollections; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface MultipleListMapper { + + MultipleListMapper INSTANCE = Mappers.getMapper( MultipleListMapper.class ); + + GarageDto convert(Garage garage); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 9679794732..523a48d7ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -170,7 +170,8 @@ public void shouldFailOnSuperBounds2() { line = 29, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + " foo\" to" - + " \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper foo\"") + + " \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + + " foo\"") }) public void shouldFailOnNonMatchingWildCards() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java index 05dcf5879b..76a54bdb27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java @@ -20,13 +20,13 @@ public class ErroneousTarget6 { - private WildCardSuperWrapper foo; + private WildCardSuperWrapper foo; - public WildCardSuperWrapper getFoo() { + public WildCardSuperWrapper getFoo() { return foo; } - public void setFoo(WildCardSuperWrapper foo) { + public void setFoo(WildCardSuperWrapper foo) { this.foo = foo; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousCompanyMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousCompanyMapper1.java index fadf941452..b76de915eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousCompanyMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousCompanyMapper1.java @@ -33,9 +33,9 @@ public interface ErroneousCompanyMapper1 { ErroneousCompanyMapper1 INSTANCE = Mappers.getMapper( ErroneousCompanyMapper1.class ); - void toCompanyEntity(CompanyDto dto, @MappingTarget CompanyEntity entity); + void toCompanyEntity(UnmappableCompanyDto dto, @MappingTarget CompanyEntity entity); - void toInBetween(DepartmentDto dto, @MappingTarget DepartmentInBetween entity); + void toInBetween(UnmappableDepartmentDto dto, @MappingTarget DepartmentInBetween entity); @Mappings({ @Mapping( target = "employees", ignore = true ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java new file mode 100644 index 0000000000..1f36a6f32d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods; + +/** + * + * @author Dmytro Polovinkin + */ +public class UnmappableCompanyDto { + + private String name; + private UnmappableDepartmentDto department; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public UnmappableDepartmentDto getDepartment() { + return department; + } + + public void setDepartment(UnmappableDepartmentDto department) { + this.department = department; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java new file mode 100644 index 0000000000..1b71f840ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods; + +import java.util.List; +import java.util.Map; + +/** + * + * @author Dmytro Polovinkin + */ +public class UnmappableDepartmentDto { + + private String name; + private List workers; + private Map secretaryToEmployee; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getWorkers() { + return workers; + } + + public void setWorkers(List employees) { + this.workers = employees; + } + + public Map getSecretaryToEmployee() { + return secretaryToEmployee; + } + + public void setSecretaryToEmployee(Map secretaryToEmployee) { + this.secretaryToEmployee = secretaryToEmployee; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index b703723190..8291dae34e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -182,7 +182,9 @@ public void testShouldFailOnConstantMappingNoPropertyGetter() { } @Test @WithClasses( { ErroneousCompanyMapper1.class, - DepartmentInBetween.class + DepartmentInBetween.class, + UnmappableCompanyDto.class, + UnmappableDepartmentDto.class } ) @ExpectedCompilationOutcome( @@ -191,7 +193,8 @@ public void testShouldFailOnConstantMappingNoPropertyGetter() { } @Diagnostic(type = ErroneousCompanyMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 36, - messageRegExp = "Can't map property \".*DepartmentDto department\" to \".*DepartmentEntity department.") + messageRegExp = "Can't map property \".*UnmappableDepartmentDto department\" to \".*DepartmentEntity " + + "department.") } ) public void testShouldFailOnTwoNestedUpdateMethods() { } From d398618aa5e514eb5c87ccfdf7ebc72fe4ecedfe Mon Sep 17 00:00:00 2001 From: sjaakd Date: Mon, 19 Dec 2016 21:44:36 +0100 Subject: [PATCH 0003/1006] #60 automapping removing commented-out-code and copyright --- copyright.txt | 1 + .../mapstruct/ap/internal/model/MapMappingMethod.java | 9 --------- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 8 ++++---- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/copyright.txt b/copyright.txt index 01b7b4dc96..b59651d462 100644 --- a/copyright.txt +++ b/copyright.txt @@ -6,6 +6,7 @@ Christian Schuster Christophe Labouisse Ciaran Liedeman Dilip Krishnan +Dmytro Polovinkin Ewald Volkert Filip Hrisafov Gunnar Morling diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 0471f01bea..75179453b3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -120,16 +120,7 @@ public MapMappingMethod build() { ); if ( keyAssignment == null ) { - keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); -// if ( method instanceof ForgedMethod ) { -// // leave messaging to calling property mapping -// return null; -// } -// else { -// ctx.getMessager().printMessage( method.getExecutable(), -// Message.MAPMAPPING_KEY_MAPPING_NOT_FOUND ); -// } } // find mapping method or conversion for value diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 7dae55e7a4..253603b7b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -82,10 +82,6 @@ public class PropertyMapping extends ModelElement { private final Assignment defaultValueAssignment; private List forgedMethods = new ArrayList(); - public List getForgedMethods() { - return forgedMethods; - } - private enum TargetWriteAccessorType { FIELD, GETTER, @@ -967,6 +963,10 @@ public List getDependsOn() { return dependsOn; } + public List getForgedMethods() { + return forgedMethods; + } + @Override public String toString() { return "PropertyMapping {" From 70896245d779650b05275abbc3d8a848ad02f406 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Mon, 5 Dec 2016 23:15:20 +0100 Subject: [PATCH 0004/1006] #973 Setter and Update wrapper refactoring and cleanup --- .../ap/internal/model/MethodReference.java | 7 +- .../ap/internal/model/PropertyMapping.java | 93 +++++-------------- .../ap/internal/model/SourceRHS.java | 11 ++- .../ap/internal/model/TypeConversion.java | 7 +- .../model/assignment/AdderWrapper.java | 13 +-- .../internal/model/assignment/Assignment.java | 39 ++++++-- .../model/assignment/AssignmentWrapper.java | 9 +- .../GetterWrapperForCollectionsAndMaps.java | 12 +-- .../model/assignment/SetterWrapper.java | 46 ++++++++- .../SetterWrapperForCollectionsAndMaps.java | 15 +-- .../model/assignment/UpdateWrapper.java | 15 ++- .../WrapperForCollectionsAndMaps.java | 31 +++---- .../model/assignment/AdderWrapper.ftl | 2 +- .../GetterWrapperForCollectionsAndMaps.ftl | 3 +- .../model/assignment/SetterWrapper.ftl | 63 ++++++------- .../SetterWrapperForCollectionsAndMaps.ftl | 11 ++- .../model/assignment/UpdateWrapper.ftl | 37 ++++---- .../ap/internal/model/macro/CommonMacros.ftl | 44 ++++++++- 18 files changed, 256 insertions(+), 202 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 58e6c1b6df..099655cd85 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -152,6 +152,11 @@ public void setSourceLocalVarName(String sourceLocalVarName) { assignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceParameterName() { + return assignment.getSourceParameterName(); + } + /** * @return the type of the single source parameter that is not the {@code @TargetType} parameter */ @@ -206,7 +211,7 @@ public AssignmentType getType() { } @Override - public boolean isUpdateMethod() { + public boolean isCallingUpdateMethod() { return isUpdateMethod; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 253603b7b0..e7dcb6f438 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -19,9 +19,6 @@ package org.mapstruct.ap.internal.model; import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.MAPPED_TYPE_CONVERTED; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.TYPE_CONVERTED_MAPPED; import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; @@ -43,7 +40,6 @@ import org.mapstruct.ap.internal.model.assignment.NullCheckWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; -import org.mapstruct.ap.internal.model.assignment.UpdateNullCheckWrapper; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; @@ -55,6 +51,7 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; @@ -335,7 +332,7 @@ private Assignment assignToPlain(Type sourceType, Type targetType, TargetWriteAc if ( targetAccessorType == TargetWriteAccessorType.SETTER || targetAccessorType == TargetWriteAccessorType.FIELD ) { - result = assignToPlainViaSetter( sourceType, targetType, rightHandSide ); + result = assignToPlainViaSetter( targetType, rightHandSide ); } else { result = assignToPlainViaAdder( rightHandSide ); @@ -344,11 +341,9 @@ private Assignment assignToPlain(Type sourceType, Type targetType, TargetWriteAc } - private Assignment assignToPlainViaSetter(Type sourceType, Type targetType, Assignment rhs) { + private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { - Assignment result; - - if ( rhs.isUpdateMethod() ) { + if ( rhs.isCallingUpdateMethod() ) { if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -356,59 +351,13 @@ private Assignment assignToPlainViaSetter(Type sourceType, Type targetType, Assi targetPropertyName ); } - Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); - result = new UpdateWrapper( rhs, method.getThrownTypes(), factoryMethod, - targetType, isFieldAssignment() - ); + Assignment factory = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + return new UpdateWrapper( rhs, method.getThrownTypes(), factory, isFieldAssignment(), targetType, + true ); } else { - result = new SetterWrapper( rhs, method.getThrownTypes(), isFieldAssignment() ); - } - - // if the sourceReference is the bean mapping method parameter itself, no null check is required - // since this is handled by the BeanMapping - if ( sourceReference.getPropertyEntries().isEmpty() ) { - return result; - } - - // add a null / presence checked when required - if ( sourceType.isPrimitive() ) { - if ( rhs.getSourcePresenceCheckerReference() != null ) { - result = new NullCheckWrapper( result ); - } - } - else { - - if ( result.isUpdateMethod() ) { - result = new UpdateNullCheckWrapper( result, isFieldAssignment() ); - } - else if ( rhs.getSourcePresenceCheckerReference() != null ) { - result = new NullCheckWrapper( result ); - } - else if ( ALWAYS.equals( method.getMapperConfiguration().getNullValueCheckStrategy() ) ) { - result = new NullCheckWrapper( result ); - useLocalVarWhenNested( result ); - } - else if ( result.getType() == TYPE_CONVERTED - || result.getType() == TYPE_CONVERTED_MAPPED - || result.getType() == MAPPED_TYPE_CONVERTED - || (result.getType() == DIRECT && targetType.isPrimitive() ) ) { - // for primitive types null check is not possible at all, but a conversion needs - // a null check. - result = new NullCheckWrapper( result ); - useLocalVarWhenNested( result ); - } - } - - return result; - } - - private void useLocalVarWhenNested(Assignment rightHandSide) { - if ( sourceReference.getPropertyEntries().size() > 1 ) { - String name = first( sourceReference.getPropertyEntries() ).getName(); - String safeName = Strings.getSaveVariableName( name, existingVariableNames ); - existingVariableNames.add( safeName ); - rightHandSide.setSourceLocalVarName( safeName ); + NullValueCheckStrategyPrism nvcs = method.getMapperConfiguration().getNullValueCheckStrategy(); + return new SetterWrapper( rhs, method.getThrownTypes(), nvcs, isFieldAssignment(), targetType ); } } @@ -421,8 +370,7 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { } else { // Possibly adding null to a target collection. So should be surrounded by an null check. - result = new SetterWrapper( result, method.getThrownTypes(), isFieldAssignment() ); - result = new NullCheckWrapper( result ); + result = new SetterWrapper( result, method.getThrownTypes(), ALWAYS, isFieldAssignment(), targetType ); } return result; } @@ -435,7 +383,7 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t if ( targetAccessorType == TargetWriteAccessorType.SETTER || targetAccessorType == TargetWriteAccessorType.FIELD ) { - if ( result.isUpdateMethod() ) { + if ( result.isCallingUpdateMethod() ) { // call to an update method if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( @@ -449,8 +397,9 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t result, method.getThrownTypes(), factoryMethod, + isFieldAssignment(), targetType, - isFieldAssignment() + true ); } else { @@ -458,9 +407,8 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t result = new SetterWrapperForCollectionsAndMaps( result, method.getThrownTypes(), - existingVariableNames, targetType, - ALWAYS == method.getMapperConfiguration().getNullValueCheckStrategy(), + method.getMapperConfiguration().getNullValueCheckStrategy(), ctx.getTypeFactory(), targetWriteAccessorType == TargetWriteAccessorType.FIELD ); @@ -470,7 +418,6 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t // target accessor is getter, so wrap the setter in getter map/ collection handling result = new GetterWrapperForCollectionsAndMaps( result, method.getThrownTypes(), - existingVariableNames, targetType, isFieldAssignment() ); @@ -560,6 +507,11 @@ else if ( propertyEntries.size() == 1 ) { existingVariableNames, sourceReference.toString() ); + + // create a local variable to which forged method can be assigned. + String desiredName = first( sourceReference.getPropertyEntries() ).getName(); + sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) ); + return sourceRhs; } @@ -767,7 +719,7 @@ public PropertyMapping build() { Executables.isFieldAccessor( targetWriteAccessor ) ) { // target accessor is setter, so decorate assignment as setter - if ( assignment.isUpdateMethod() ) { + if ( assignment.isCallingUpdateMethod() ) { if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -778,8 +730,7 @@ public PropertyMapping build() { Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); assignment = new UpdateWrapper( assignment, method.getThrownTypes(), factoryMethod, - targetType, isFieldAssignment() - ); + isFieldAssignment(), targetType, false ); } else { assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); @@ -790,7 +741,6 @@ targetType, isFieldAssignment() // target accessor is getter, so getter map/ collection handling assignment = new GetterWrapperForCollectionsAndMaps( assignment, method.getThrownTypes(), - existingVariableNames, targetType, isFieldAssignment() ); @@ -863,7 +813,6 @@ public PropertyMapping build() { // target accessor is getter, so wrap the setter in getter map/ collection handling assignment = new GetterWrapperForCollectionsAndMaps( assignment, method.getThrownTypes(), - existingVariableNames, targetType, isFieldAssignment() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java index 58ef565fa7..5a2f555d3a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java @@ -47,7 +47,7 @@ public class SourceRHS extends ModelElement implements Assignment { public SourceRHS(String sourceReference, Type sourceType, Set existingVariableNames, String sourceErrorMessagePart ) { - this( null, sourceReference, null, sourceType, existingVariableNames, sourceErrorMessagePart ); + this( sourceReference, sourceReference, null, sourceType, existingVariableNames, sourceErrorMessagePart ); } public SourceRHS(String sourceParameterName, String sourceReference, String sourcePresenceCheckerReference, @@ -77,7 +77,9 @@ public Type getSourceType() { @Override public String createLocalVarName(String desiredName) { - return Strings.getSaveVariableName( desiredName, existingVariableNames ); + String result = Strings.getSaveVariableName( desiredName, existingVariableNames ); + existingVariableNames.add( result ); + return result; } @Override @@ -111,7 +113,7 @@ public AssignmentType getType() { } @Override - public boolean isUpdateMethod() { + public boolean isCallingUpdateMethod() { return false; } @@ -137,12 +139,13 @@ public Type getSourceTypeForMatching() { /** * For collection type, use element as source type to find a suitable mapping method. * - * @param useElementAsSourceTypeForMatching + * @param useElementAsSourceTypeForMatching uses the element of a collection as source type for the matching process */ public void setUseElementAsSourceTypeForMatching(boolean useElementAsSourceTypeForMatching) { this.useElementAsSourceTypeForMatching = useElementAsSourceTypeForMatching; } + @Override public String getSourceParameterName() { return sourceParameterName; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index afd94fad56..d7a83075bd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -111,6 +111,11 @@ public void setSourceLocalVarName(String sourceLocalVarName) { assignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceParameterName() { + return assignment.getSourceParameterName(); + } + @Override public void setAssignment( Assignment assignment ) { this.assignment = assignment; @@ -130,7 +135,7 @@ public Assignment.AssignmentType getType() { } @Override - public boolean isUpdateMethod() { + public boolean isCallingUpdateMethod() { return false; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 1843301c6f..9d6142ed61 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -33,14 +33,12 @@ public class AdderWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; - private final String sourceIteratorName; - public AdderWrapper( Assignment decoratedAssignment, List thrownTypesToExclude, boolean fieldAssignment ) { - super( decoratedAssignment, fieldAssignment ); + public AdderWrapper( Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment ) { + super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; - String desiredName = decoratedAssignment.getSourceType().getTypeParameters().get( 0 ).getName(); - this.sourceIteratorName = decoratedAssignment.createLocalVarName( desiredName ); - decoratedAssignment.setSourceLocalVarName( sourceIteratorName ); + String desiredName = rhs.getSourceType().getTypeParameters().get( 0 ).getName(); + rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); } @Override @@ -65,7 +63,4 @@ public Set getImportTypes() { return imported; } - public String getSourceIteratorName() { - return sourceIteratorName; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java index d02b5410eb..09ef8bed1b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java @@ -32,17 +32,34 @@ public interface Assignment { enum AssignmentType { /** assignment is direct */ - DIRECT, + DIRECT( true, false ), /** assignment is type converted */ - TYPE_CONVERTED, + TYPE_CONVERTED( false, true ), /** assignment is mapped (builtin/custom) */ - MAPPED, + MAPPED( false, false ), /** 2 mapping methods (builtin/custom) are applied to get the target */ - MAPPED_TWICE, + MAPPED_TWICE( false, false ), /** assignment is first mapped (builtin/custom), then the result is type converted */ - MAPPED_TYPE_CONVERTED, + MAPPED_TYPE_CONVERTED( false, true ), /** assignment is first type converted, and then mapped (builtin/custom) */ - TYPE_CONVERTED_MAPPED + TYPE_CONVERTED_MAPPED( false, true ); + + private final boolean direct; + private final boolean converted; + + AssignmentType( boolean isDirect, boolean isConverted ) { + this.direct = isDirect; + this.converted = isConverted; + } + + public boolean isDirect() { + return direct; + } + + public boolean isConverted() { + return converted; + } + } /** @@ -106,6 +123,14 @@ enum AssignmentType { */ String getSourceLocalVarName(); + /** + * Returns the source parameter name, to which this assignment applies. Note: the source parameter itself might + * be mapped by this assignment, or one of its properties + * + * @return the source parameter name + */ + String getSourceParameterName(); + /** * Use sourceLocalVarName iso sourceReference * @param sourceLocalVarName source local variable name @@ -119,5 +144,5 @@ enum AssignmentType { */ AssignmentType getType(); - boolean isUpdateMethod(); + boolean isCallingUpdateMethod(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 50d2058a45..8ed573f956 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -83,14 +83,19 @@ public void setSourceLocalVarName(String sourceLocalVarName) { decoratedAssignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceParameterName() { + return decoratedAssignment.getSourceParameterName(); + } + @Override public AssignmentType getType() { return decoratedAssignment.getType(); } @Override - public boolean isUpdateMethod() { - return decoratedAssignment.isUpdateMethod(); + public boolean isCallingUpdateMethod() { + return decoratedAssignment.isCallingUpdateMethod(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 80bb060bf8..2c25f0a463 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -19,7 +19,6 @@ package org.mapstruct.ap.internal.model.assignment; import java.util.List; -import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; @@ -39,22 +38,19 @@ public class GetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAndMaps { /** - * @param decoratedAssignment - * @param thrownTypesToExclude - * @param existingVariableNames - * @param targetType - * @param fieldAssignment + * @param decoratedAssignment source RHS + * @param thrownTypesToExclude set of types to exclude from re-throwing + * @param targetType the target type + * @param fieldAssignment true when this the assignment is to a field rather than via accessors */ public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List thrownTypesToExclude, - Set existingVariableNames, Type targetType, boolean fieldAssignment) { super( decoratedAssignment, thrownTypesToExclude, - existingVariableNames, targetType, fieldAssignment ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index 7595109f23..8fe40dd30d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -22,6 +22,9 @@ import java.util.List; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; + +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; /** * Wraps the assignment in a target setter. @@ -31,10 +34,23 @@ public class SetterWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; + private final boolean includeSourceNullCheck; + + public SetterWrapper(Assignment rhs, + List thrownTypesToExclude, + NullValueCheckStrategyPrism nvms, + boolean fieldAssignment, + Type targetType) { + + super( rhs, fieldAssignment ); + this.thrownTypesToExclude = thrownTypesToExclude; + this.includeSourceNullCheck = includeSourceNullCheck( rhs, nvms, targetType ); + } - public SetterWrapper(Assignment decoratedAssignment, List thrownTypesToExclude, boolean fieldAssignment) { - super( decoratedAssignment, fieldAssignment ); + public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment ) { + super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; + this.includeSourceNullCheck = false; } @Override @@ -51,4 +67,30 @@ public List getThrownTypes() { return result; } + public boolean isIncludeSourceNullCheck() { + return includeSourceNullCheck; + } + + /** + * Wraps the assignment in a target setter. include a null check when + * + * - Not if source is the parameter iso property, because the null check is than handled by the bean mapping + * - Not when source is primitive, you can't null check a primitive + * - The source property is fed to a conversion somehow before its assigned to the target + * - The user decided to ALLWAYS include a null check + * - When there's a source local variable name defined (e.g. nested source properties) + * - TODO: The last one I forgot..? + * + * @param rhs the source righthand side + * @param nvms null value check strategy + * @param targetType the target type + * + * @return include a null check + */ + private boolean includeSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvms, Type targetType) { + return !rhs.getSourceReference().equals( rhs.getSourceParameterName() ) + && !rhs.getSourceType().isPrimitive() + && (ALWAYS == nvms || rhs.getType().isConverted() || rhs.getSourceLocalVarName() != null + || (rhs.getType().isDirect() && targetType.isPrimitive())); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java index a97490a571..a6b179e0d1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java @@ -26,6 +26,9 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; + +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; /** * This wrapper handles the situation were an assignment is done via the setter. @@ -41,26 +44,24 @@ */ public class SetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAndMaps { - private final boolean allwaysIncludeNullCheck; + private final boolean includeSourceNullCheck; private final Type targetType; private final TypeFactory typeFactory; public SetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List thrownTypesToExclude, - Set existingVariableNames, Type targetType, - boolean allwaysIncludeNullCheck, + NullValueCheckStrategyPrism nvms, TypeFactory typeFactory, boolean fieldAssignment) { super( decoratedAssignment, thrownTypesToExclude, - existingVariableNames, targetType, fieldAssignment ); - this.allwaysIncludeNullCheck = allwaysIncludeNullCheck; + this.includeSourceNullCheck = ALWAYS == nvms; this.targetType = targetType; this.typeFactory = typeFactory; } @@ -83,8 +84,8 @@ public Set getImportTypes() { return imported; } - public boolean isAllwaysIncludeNullCheck() { - return allwaysIncludeNullCheck; + public boolean isIncludeSourceNullCheck() { + return includeSourceNullCheck; } public boolean isDirectAssignment() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index e610c1f64f..a5bdb99e93 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -35,13 +35,19 @@ public class UpdateWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; private final Assignment factoryMethod; private final Type targetImplementationType; + private final boolean includeSourceNullCheck; - public UpdateWrapper(Assignment decoratedAssignment, List thrownTypesToExclude, Assignment factoryMethod, - Type targetImplementationType, boolean fieldAssignment ) { + public UpdateWrapper( Assignment decoratedAssignment, + List thrownTypesToExclude, + Assignment factoryMethod, + boolean fieldAssignment, + Type targetType, + boolean includeSourceNullCheck ) { super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; - this.targetImplementationType = determineImplType( factoryMethod, targetImplementationType ); + this.targetImplementationType = determineImplType( factoryMethod, targetType ); + this.includeSourceNullCheck = includeSourceNullCheck; } private static Type determineImplType(Assignment factoryMethod, Type targetType) { @@ -87,4 +93,7 @@ public Assignment getFactoryMethod() { return factoryMethod; } + public boolean isIncludeSourceNullCheck() { + return includeSourceNullCheck; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index a00a585e64..592d5c0ef3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -24,7 +24,6 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.util.Strings; /** * This is the base class for the {@link GetterWrapperForCollectionsAndMaps} and @@ -35,26 +34,24 @@ public class WrapperForCollectionsAndMaps extends AssignmentWrapper { private final List thrownTypesToExclude; - private final String localVarName; - private final Type localVarType; + private final String nullCheckLocalVarName; + private final Type nullCheckLocalVarType; - public WrapperForCollectionsAndMaps(Assignment decoratedAssignment, + public WrapperForCollectionsAndMaps(Assignment rhs, List thrownTypesToExclude, - Set existingVariableNames, Type targetType, boolean fieldAssignment) { - super( decoratedAssignment, fieldAssignment ); + super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; - if ( getType() == AssignmentType.DIRECT && getSourceType() != null ) { - this.localVarType = getSourceType(); + if ( rhs.getType() == AssignmentType.DIRECT && rhs.getSourceType() != null ) { + this.nullCheckLocalVarType = rhs.getSourceType(); } else { - this.localVarType = targetType; + this.nullCheckLocalVarType = targetType; } - this.localVarName = Strings.getSaveVariableName( localVarType.getName(), existingVariableNames ); - existingVariableNames.add( this.localVarName ); + this.nullCheckLocalVarName = rhs.createLocalVarName( nullCheckLocalVarType.getName() ); } @Override @@ -75,16 +72,16 @@ public List getThrownTypes() { public Set getImportTypes() { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); - imported.add( localVarType ); - imported.addAll( localVarType.getTypeParameters() ); + imported.add( nullCheckLocalVarType ); + imported.addAll( nullCheckLocalVarType.getTypeParameters() ); return imported; } - public String getLocalVarName() { - return localVarName; + public String getNullCheckLocalVarName() { + return nullCheckLocalVarName; } - public Type getLocalVarType() { - return localVarType; + public Type getNullCheckLocalVarType() { + return nullCheckLocalVarType; } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index fa454e92fb..14aa224390 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -21,7 +21,7 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> if ( ${sourceReference} != null ) { - for ( <@includeModel object=sourceType.typeParameters[0]/> ${sourceIteratorName} : ${sourceReference} ) { + for ( <@includeModel object=sourceType.typeParameters[0]/> ${sourceLocalVarName} : ${sourceReference} ) { ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index d66dcbe314..1cc8cad11b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -19,13 +19,14 @@ --> <#import "../macro/CommonMacros.ftl" as lib> +<@lib.sourceLocalVarAssignment/> if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing /> != null ) { <@lib.handleExceptions> <#if ext.existingInstanceMapping> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.clear(); <@lib.handleNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( ${localVarName} ); + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index a02142f522..468e6fcf02 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -19,44 +19,33 @@ --> <#import "../macro/CommonMacros.ftl" as lib> -<#if (thrownTypes?size == 0) > - <@assignment_w_defaultValue/> -<#else> - try { - <@assignment_w_defaultValue/> - } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - -<#macro _assignment> - <@includeModel object=assignment - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=ext.targetReadAccessorName - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType - defaultValueAssignment=ext.defaultValueAssignment/> - -<#macro _defaultValueAssignment> - <@includeModel object=ext.defaultValueAssignment.assignment - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType/> - -<#macro assignment_w_defaultValue> - <#if ext.defaultValueAssignment?? > - <#-- if the assignee property is a primitive, defaulValueAssignment will not be set --> - if ( ${sourceReference} != null ) { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@_assignment/>; +<@lib.handleExceptions> + <@lib.sourceLocalVarAssignment/> + <#if sourcePresenceCheckerReference??> + if ( ${sourcePresenceCheckerReference} ) { + <@assignment/>; } - else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@_defaultValueAssignment/>; + <@elseDefaultAssignment/> + <#elseif includeSourceNullCheck || ext.defaultValueAssignment??> + if ( <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { + <@assignment/>; } + <@elseDefaultAssignment/> <#else> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@_assignment/>; + <@assignment/>; + + +<#-- + standard assignment +--> +<#macro assignment>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/> +<#-- + add default assignment when required +--> +<#macro elseDefaultAssignment> + <#if ext.defaultValueAssignment?? > + else { + <@lib.handeDefaultAssigment/> + } - + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index f9bbbfe313..ef6c1e0c75 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -19,14 +19,15 @@ --> <#import "../macro/CommonMacros.ftl" as lib> +<@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> <#if ext.existingInstanceMapping> if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} != null ) { <@lib.handleNullCheck> ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); - ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( ${localVarName} ); + ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); - <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !allwaysIncludeNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleNullCheck --> + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleNullCheck --> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; } @@ -43,7 +44,7 @@ --> <#macro callTargetWriteAccessor> <@lib.handleNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else>${localVarName}; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else>${nullCheckLocalVarName}; <#-- @@ -51,8 +52,8 @@ --> <#macro wrapLocalVarInCollectionInitializer><@compress single_line=true> <#if enumSet> - EnumSet.copyOf( ${localVarName} ) + EnumSet.copyOf( ${nullCheckLocalVarName} ) <#else> - new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${localVarName} ) + new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 59a9156346..28e7bbe778 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -19,28 +19,25 @@ --> <#import '../macro/CommonMacros.ftl' as lib > -<#if (thrownTypes?size == 0) > - <@_assignment/>; -<#else> - try { - <@_assignment/>; +<@lib.handleExceptions> + <#if includeSourceNullCheck> + if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else>${sourceReference} != null ) { + <@assignToExistingTarget/> + <@lib.handleAssignment/>; } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); + else { + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; } - - -<#macro _assignment> + <#else> + <@assignToExistingTarget/> + <@lib.handleAssignment/>; + + +<#-- + target innner check and assignment +--> +<#macro assignToExistingTarget> if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} == null ) { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if factoryMethod??><@includeModel object=factoryMethod targetType=ext.targetType/><#else><@_newObject/>; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.initTargetObject/>; } - <@includeModel object=assignment - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=ext.targetReadAccessorName - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType/> -<#macro _newObject>new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>() - diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 060fcb513c..c79a8e66ea 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -30,18 +30,18 @@ <#macro handleNullCheck> <#if sourcePresenceCheckerReference??> if ( ${sourcePresenceCheckerReference} ) { - <@includeModel object=localVarType/> ${localVarName} = <@lib.handleAssignment/>; + <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; <#nested> } <#else> - <@includeModel object=localVarType/> ${localVarName} = <@lib.handleAssignment/>; - if ( ${localVarName} != null ) { + <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; + if ( ${nullCheckLocalVarName} != null ) { <#nested> } <#if ext.defaultValueAssignment?? > else { - <@lib.handeDefaultAssigment/> + <@handeDefaultAssigment/> } @@ -104,4 +104,38 @@ Performs a default assignment with a default value. --> <#macro handleWriteAccesing> <#t><#if fieldAssignment><#else>() - \ No newline at end of file + +<#-- + macro: initTargetObject + + purpose: To factorize or construct a new target object +--> +<#macro initTargetObject><@compress single_line=true> + <#if factoryMethod??> + <@includeModel object=factoryMethod targetType=ext.targetType/> + <#else> + new <@constructTargetObject/>() + + +<#-- + macro: constructTargetObject + + purpose: Either call the constructor of the target object directly or of the implementing type. +--> +<#macro constructTargetObject><@compress single_line=true> + <#if ext.targetType.implementationType??> + <@includeModel object=ext.targetType.implementationType/> + <#else> + <@includeModel object=ext.targetType/> + + +<#-- + macro: sourceLocalVarAssignment + + purpose: assigment for source local variables +--> +<#macro sourceLocalVarAssignment> + <#if sourceLocalVarName??> + <@includeModel object=sourceType/> ${sourceLocalVarName} = ${sourceReference}; + + From 46363028bd5bf73382b34c2fafdf7b12447841c6 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Thu, 8 Dec 2016 22:47:48 +0100 Subject: [PATCH 0005/1006] #988 Strange enters in templates --- .../mapstruct/ap/internal/model/macro/CommonMacros.ftl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index c79a8e66ea..2a52ed235b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -26,6 +26,8 @@ a local variable. Note that the local variable assignemnt is inside the IF statement for the source presence check. Note also, that the else clause contains the default variable assignment if present. + + TODO: is only used by collection mapping currently.. should perhas be moved to there and not in common --> <#macro handleNullCheck> <#if sourcePresenceCheckerReference??> @@ -93,18 +95,14 @@ Performs a default assignment with a default value. purpose: To handle the writing to a field or using a method. The line is not closed with ';' --> -<#macro handleWrite> - <#t><#if fieldAssignment> = <#nested><#else>( <#nested> ) - +<#macro handleWrite><#if fieldAssignment> = <#nested><#else>( <#nested> ) <#-- macro: handleWriteAccesing purpose: To handle accesing the write target type --> -<#macro handleWriteAccesing> - <#t><#if fieldAssignment><#else>() - +<#macro handleWriteAccesing><#if fieldAssignment><#else>() <#-- macro: initTargetObject From 79f87e8833e53b232eb93985c1555378abb52db3 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Sun, 18 Dec 2016 00:48:20 +0100 Subject: [PATCH 0006/1006] #975 Refactor method-matching to unify selection and rendering of mapping method, factories and lifecycle methods --- .../internal/model/IterableMappingMethod.java | 7 +- .../model/LifecycleCallbackFactory.java | 124 +++---------- .../LifecycleCallbackMethodReference.java | 34 +--- .../ap/internal/model/MapMappingMethod.java | 7 +- .../ap/internal/model/MethodReference.java | 17 +- .../model/ParameterAssignmentUtil.java | 98 ---------- .../ap/internal/model/PropertyMapping.java | 20 +- .../ap/internal/model/common/Parameter.java | 11 +- .../model/common/ParameterBinding.java | 124 +++++++++++++ .../ap/internal/model/common/Type.java | 7 +- .../ap/internal/model/common/TypeFactory.java | 3 +- .../internal/model/source/ForgedMethod.java | 2 +- .../internal/model/source/MethodMatcher.java | 27 +-- .../selector/CreateOrUpdateSelector.java | 19 +- .../source/selector/InheritanceSelector.java | 28 +-- ...elector.java => MethodFamilySelector.java} | 21 ++- .../model/source/selector/MethodSelector.java | 15 +- .../source/selector/MethodSelectors.java | 48 +++-- .../source/selector/QualifierSelector.java | 24 +-- .../selector/SelectedMethod.java} | 34 ++-- .../source/selector/SelectionCriteria.java | 26 ++- .../source/selector/TargetTypeSelector.java | 17 +- .../model/source/selector/TypeSelector.java | 173 +++++++++++++++++- .../selector/XmlElementDeclSelector.java | 19 +- .../creation/MappingResolverImpl.java | 130 +++++-------- .../LifecycleCallbackMethodReference.ftl | 5 +- .../ap/internal/model/MethodReference.ftl | 10 +- .../model/ObjectFactoryMethodReference.ftl | 46 ----- .../runner/AnnotationProcessorTestRunner.java | 3 +- 29 files changed, 587 insertions(+), 512 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/ParameterAssignmentUtil.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java rename processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/{ObjectFactorySelector.java => MethodFamilySelector.java} (53%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{ObjectFactoryMethodReference.java => source/selector/SelectedMethod.java} (52%) delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index eff6fa2253..2dd04235d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; @@ -191,7 +192,11 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe forgedMethodHistory ); - Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + Assignment assignment = new MethodReference( + forgedMethod, + null, + ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); + assignment.setAssignment( sourceRHS ); return assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java index 648ba8a221..8d658768cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java @@ -19,17 +19,16 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Set; -import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.model.source.selector.QualifierSelector; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; +import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; /** @@ -84,45 +83,36 @@ private static List collectLifecycleCallbackMe Method method, SelectionParameters selectionParameters, List callbackMethods, MappingBuilderContext ctx, Set existingVariableNames) { - Map> parameterAssignmentsForSourceMethod - = new HashMap>(); + MethodSelectors selectors = + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory() ); - List candidates = - filterCandidatesByType( method, callbackMethods, parameterAssignmentsForSourceMethod, ctx ); - - candidates = filterCandidatesByQualifiers( method, selectionParameters, candidates, ctx ); + List> matchingMethods = selectors.getMatchingMethods( + method, + callbackMethods, + Collections. emptyList(), + method.getResultType(), + SelectionCriteria.forLifecycleMethods( selectionParameters ) ); return toLifecycleCallbackMethodRefs( method, - candidates, - parameterAssignmentsForSourceMethod, + matchingMethods, ctx, existingVariableNames ); } - private static List filterCandidatesByQualifiers(Method method, - SelectionParameters selectionParameters, - List candidates, - MappingBuilderContext ctx) { - QualifierSelector selector = new QualifierSelector( ctx.getTypeUtils(), ctx.getElementUtils() ); - - return selector.getMatchingMethods( method, candidates, null, null, new SelectionCriteria( - selectionParameters, - null, - false, - false) ); - } - private static List toLifecycleCallbackMethodRefs(Method method, - List candidates, Map> parameterAssignmentsForSourceMethod, - MappingBuilderContext ctx, Set existingVariableNames) { + List> candidates, + MappingBuilderContext ctx, + Set existingVariableNames) { + List result = new ArrayList(); - for ( SourceMethod candidate : candidates ) { - markMapperReferenceAsUsed( ctx.getMapperReferences(), candidate ); + for ( SelectedMethod candidate : candidates ) { + MapperReference mapperReference = findMapperReference( ctx.getMapperReferences(), candidate.getMethod() ); result.add( new LifecycleCallbackMethodReference( - candidate, - parameterAssignmentsForSourceMethod.get( candidate ), + candidate.getMethod(), + mapperReference, + candidate.getParameterBindings(), method.getReturnType(), method.getResultType(), existingVariableNames ) ); @@ -130,77 +120,15 @@ private static List toLifecycleCallbackMethodR return result; } - private static List filterCandidatesByType(Method method, - List callbackMethods, Map> parameterAssignmentsForSourceMethod, - MappingBuilderContext ctx) { - - List candidates = new ArrayList(); - - List availableParams = getAvailableParameters( method, ctx ); - for ( SourceMethod callback : callbackMethods ) { - List parameterAssignments = - ParameterAssignmentUtil.getParameterAssignments( availableParams, callback.getParameters() ); - - if ( isValidCandidate( callback, method, parameterAssignments ) ) { - parameterAssignmentsForSourceMethod.put( callback, parameterAssignments ); - candidates.add( callback ); - } - } - return candidates; - } - - private static boolean isValidCandidate(SourceMethod candidate, Method method, - List parameterAssignments) { - if ( parameterAssignments == null ) { - return false; - } - if ( !candidate.matches( extractSourceTypes( parameterAssignments ), method.getResultType() ) ) { - return false; - } - return ( candidate.getReturnType().isVoid() || candidate.getReturnType().isTypeVar() - || candidate.getReturnType().isAssignableTo( method.getResultType() ) ); - } - - private static List getAvailableParameters(Method method, MappingBuilderContext ctx) { - List availableParams = new ArrayList( method.getParameters() ); - if ( method.getMappingTargetParameter() == null ) { - availableParams.add( new Parameter( null, method.getResultType(), true, false, false) ); - } - - Parameter targetTypeParameter = new Parameter( - null, - ctx.getTypeFactory().classTypeOf( method.getResultType() ), - false, - true, - false ); - - availableParams.add( targetTypeParameter ); - return availableParams; - } - - private static void markMapperReferenceAsUsed(List references, Method method) { - for ( MapperReference ref : references ) { + private static MapperReference findMapperReference(List mapperReferences, SourceMethod method) { + for ( MapperReference ref : mapperReferences ) { if ( ref.getType().equals( method.getDeclaringMapper() ) ) { - if ( !ref.isUsed() && !method.isStatic() ) { - ref.setUsed( true ); - } + ref.setUsed( ref.isUsed() || !method.isStatic() ); ref.setTypeRequiresImport( true ); - - return; - } - } - } - - private static List extractSourceTypes(List parameters) { - List result = new ArrayList( parameters.size() ); - - for ( Parameter param : parameters ) { - if ( !param.isMappingTarget() && !param.isTargetType() ) { - result.add( param.getType() ); + return ref; } } - - return result; + return null; } private static List filterBeforeMappingMethods(List methods) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java index 0ffc67441d..e9bb202509 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java @@ -18,11 +18,10 @@ */ package org.mapstruct.ap.internal.model; -import java.beans.Introspector; import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; @@ -34,35 +33,22 @@ * * @author Andreas Gudian */ -public class LifecycleCallbackMethodReference extends MappingMethod { +public class LifecycleCallbackMethodReference extends MethodReference { private final Type declaringType; - private final List parameterAssignments; private final Type methodReturnType; private final Type methodResultType; - private final String instanceVariableName; private final String targetVariableName; - public LifecycleCallbackMethodReference(SourceMethod method, List parameterAssignments, + public LifecycleCallbackMethodReference(SourceMethod method, MapperReference mapperReference, + List parameterBindings, Type methodReturnType, Type methodResultType, Set existingVariableNames) { - super( method ); + super( method, mapperReference, parameterBindings ); this.declaringType = method.getDeclaringMapper(); - this.parameterAssignments = parameterAssignments; this.methodReturnType = methodReturnType; this.methodResultType = methodResultType; - if ( isStatic() ) { - this.instanceVariableName = declaringType.getName(); - } - else if ( declaringType != null ) { - this.instanceVariableName = - Strings.getSaveVariableName( Introspector.decapitalize( declaringType.getName() ) ); - } - else { - this.instanceVariableName = null; - } - if ( hasReturnType() ) { this.targetVariableName = Strings.getSaveVariableName( "target", existingVariableNames ); existingVariableNames.add( this.targetVariableName ); @@ -76,10 +62,6 @@ public Type getDeclaringType() { return declaringType; } - public String getInstanceVariableName() { - return instanceVariableName; - } - /** * Returns the return type of the mapping method in which this callback method is called * @@ -109,12 +91,8 @@ public Set getImportTypes() { return declaringType != null ? Collections.asSet( declaringType ) : java.util.Collections. emptySet(); } - public List getParameterAssignments() { - return parameterAssignments; - } - public boolean hasMappingTargetParameter() { - for ( Parameter param : parameterAssignments ) { + for ( ParameterBinding param : getParameterBindings() ) { if ( param.isMappingTarget() ) { return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 75179453b3..7506b69fde 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -29,6 +29,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; @@ -211,7 +212,11 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe history ); - Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + Assignment assignment = new MethodReference( + forgedMethod, + null, + ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); + assignment.setAssignment( sourceRHS ); forgedMethods.add( forgedMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 099655cd85..e6a43955a0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -27,6 +27,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; @@ -62,18 +63,19 @@ public class MethodReference extends MappingMethod implements Assignment { private Assignment assignment; private final Type definingType; + private final List parameterBindings; /** * Creates a new reference to the given method. * * @param method the target method of the reference * @param declaringMapper the method declaring the mapper; {@code null} if the current mapper itself - * @param targetType in case the referenced method has a parameter for passing the target type, the given - * target type, otherwise {@code null} + * @param parameterBindings the parameter bindings of this method reference */ - public MethodReference(Method method, MapperReference declaringMapper, Type targetType) { + public MethodReference(Method method, MapperReference declaringMapper, List parameterBindings) { super( method ); this.declaringMapper = declaringMapper; + this.parameterBindings = parameterBindings; this.contextParam = null; Set imported = new HashSet(); @@ -81,8 +83,8 @@ public MethodReference(Method method, MapperReference declaringMapper, Type targ imported.addAll( type.getImportTypes() ); } - if ( targetType != null ) { - imported.addAll( targetType.getImportTypes() ); + for ( ParameterBinding binding : parameterBindings ) { + imported.addAll( binding.getImportTypes() ); } this.importTypes = Collections.unmodifiableSet( imported ); @@ -99,6 +101,7 @@ public MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.thrownTypes = Collections.emptyList(); this.definingType = null; this.isUpdateMethod = method.getMappingTargetParameter() != null; + this.parameterBindings = ParameterBinding.fromParameters( method.getParameters() ); } public MapperReference getDeclaringMapper() { @@ -214,4 +217,8 @@ public AssignmentType getType() { public boolean isCallingUpdateMethod() { return isUpdateMethod; } + + public List getParameterBindings() { + return parameterBindings; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ParameterAssignmentUtil.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ParameterAssignmentUtil.java deleted file mode 100644 index 1a6b1fcadf..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ParameterAssignmentUtil.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.internal.model; - -import java.util.ArrayList; -import java.util.List; - -import javax.lang.model.type.TypeKind; - -import org.mapstruct.ap.internal.model.common.Parameter; - -public class ParameterAssignmentUtil { - - private ParameterAssignmentUtil() { - } - - public static List getParameterAssignments(List availableParams, - List methodParameters) { - List result = new ArrayList( methodParameters.size() ); - - for ( Parameter methodParam : methodParameters ) { - List assignableParams = findCandidateParameters( availableParams, methodParam ); - - if ( assignableParams.isEmpty() ) { - return null; - } - - if ( assignableParams.size() == 1 ) { - result.add( assignableParams.get( 0 ) ); - } - else if ( assignableParams.size() > 1 ) { - Parameter paramWithMatchingName = findParameterWithName( assignableParams, methodParam.getName() ); - - if ( paramWithMatchingName != null ) { - result.add( paramWithMatchingName ); - } - else { - return null; - } - } - } - - return result; - } - - private static Parameter findParameterWithName(List parameters, String name) { - for ( Parameter param : parameters ) { - if ( name.equals( param.getName() ) ) { - return param; - } - } - - return null; - } - - /** - * @param candidateParameters available for assignment. - * @param parameter that need assignment from one of the candidate parameters. - * @return list of matching candidate parameters that can be assigned. - */ - private static List findCandidateParameters(List candidateParameters, Parameter parameter) { - List result = new ArrayList( candidateParameters.size() ); - - for ( Parameter candidate : candidateParameters ) { - if ( ( isTypeVarOrWildcard( parameter ) || candidate.getType().isAssignableTo( parameter.getType() ) ) - && parameter.isMappingTarget() == candidate.isMappingTarget() && !parameter.isTargetType() - && !candidate.isTargetType() ) { - result.add( candidate ); - } - else if ( parameter.isTargetType() && candidate.isTargetType() ) { - result.add( candidate ); - } - } - - return result; - } - - private static boolean isTypeVarOrWildcard(Parameter parameter) { - TypeKind kind = parameter.getType().getTypeMirror().getKind(); - return kind == TypeKind.TYPEVAR || kind == TypeKind.WILDCARD; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index e7dcb6f438..dcb9c08d52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -43,13 +43,14 @@ import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.Executables; @@ -566,7 +567,11 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source methodRef = new ForgedMethod( existingName, methodRef ); } - assignment = new MethodReference( methodRef, null, targetType ); + assignment = new MethodReference( + methodRef, + null, + ParameterBinding.fromParameters( methodRef.getParameters() ) ); + assignment.setAssignment( source ); forgedMethods.addAll( iterableMappingMethod.getForgedMethods() ); @@ -608,7 +613,10 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s String existingName = ctx.getExistingMappingMethod( mapMappingMethod ).getName(); methodRef = new ForgedMethod( existingName, methodRef ); } - assignment = new MethodReference( methodRef, null, targetType ); + assignment = new MethodReference( + methodRef, + null, + ParameterBinding.fromParameters( methodRef.getParameters() ) ); assignment.setAssignment( source ); forgedMethods.addAll( mapMappingMethod.getForgedMethods() ); @@ -635,7 +643,11 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { getForgedMethodHistory( sourceRHS ) ); - Assignment assignment = new MethodReference( forgedMethod, null, targetType ); + Assignment assignment = new MethodReference( + forgedMethod, + null, + ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); + assignment.setAssignment( sourceRHS ); this.forgedMethods.add( forgedMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 826dcee0ff..76cffe2218 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -34,20 +34,18 @@ public class Parameter extends ModelElement { private final Type type; private final boolean mappingTarget; private final boolean targetType; - private final boolean mappingSource; - public Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingSource) { + public Parameter(String name, Type type, boolean mappingTarget, boolean targetType) { // issue #909: FreeMarker doesn't like "values" as a parameter name this.name = "values".equals( name ) ? "values_" : name; this.originalName = name; this.type = type; this.mappingTarget = mappingTarget; this.targetType = targetType; - this.mappingSource = mappingSource; } public Parameter(String name, Type type) { - this( name, type, false, false, false ); + this( name, type, false, false ); } public String getName() { @@ -62,10 +60,6 @@ public Type getType() { return type; } - public boolean isMappingSource() { - return mappingSource; - } - public boolean isMappingTarget() { return mappingTarget; } @@ -106,5 +100,4 @@ public boolean equals(Object obj) { } return true; } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java new file mode 100644 index 0000000000..0b3382a9d0 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -0,0 +1,124 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.common; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * Represents how one parameter of a method to be called is populated. + * + * @author Andreas Gudian + */ +public class ParameterBinding { + + private final Type type; + private final String variableName; + private final boolean targetType; + private final boolean mappingTarget; + + private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType) { + this.type = parameterType; + this.variableName = variableName; + this.targetType = targetType; + this.mappingTarget = mappingTarget; + } + + /** + * @return the name of the variable (or parameter) that is being used as argument for the parameter being bound. + */ + public String getVariableName() { + return variableName; + } + + /** + * @return {@code true}, if the parameter being bound is a {@code @TargetType} parameter. + */ + public boolean isTargetType() { + return targetType; + } + + /** + * @return {@code true}, if the parameter being bound is a {@code @MappingTarget} parameter. + */ + public boolean isMappingTarget() { + return mappingTarget; + } + + /** + * @return the type of the parameter that is bound + */ + public Type getType() { + return type; + } + + public Set getImportTypes() { + if ( targetType ) { + return type.getImportTypes(); + } + + return Collections.emptySet(); + } + + /** + * @param parameter parameter + * @return a parameter binding reflecting the given parameter as being used as argument for a method call + */ + public static ParameterBinding fromParameter(Parameter parameter) { + return new ParameterBinding( + parameter.getType(), + parameter.getName(), + parameter.isMappingTarget(), + parameter.isTargetType() ); + } + + public static List fromParameters(List parameters) { + List result = new ArrayList( parameters.size() ); + for ( Parameter param : parameters ) { + result.add( fromParameter( param ) ); + } + return result; + } + + /** + * @param classTypeOf the type representing {@code Class} for the target type {@code X} + * @return a parameter binding representing a target type parameter + */ + public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { + return new ParameterBinding( classTypeOf, null, false, true ); + } + + /** + * @param resultType type of the mapping target + * @return a parameter binding representing a mapping target parameter + */ + public static ParameterBinding forMappingTargetBinding(Type resultType) { + return new ParameterBinding( resultType, null, true, false ); + } + + /** + * @param sourceType type of the parameter + * @return a parameter binding representing a mapping source type + */ + public static ParameterBinding forSourceTypeBinding(Type sourceType) { + return new ParameterBinding( sourceType, null, false, false ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index aaaed4c805..668161eccc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -754,11 +754,7 @@ public String getNull() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( name == null ) ? 0 : name.hashCode() ); - result = prime * result + ( ( packageName == null ) ? 0 : packageName.hashCode() ); - return result; + return typeMirror.hashCode(); } @Override @@ -787,7 +783,6 @@ public String toString() { return typeMirror.toString(); } - /** * * @return an identification that can be used as part in a forged method name. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index d53f2c3cf0..e1a2e6e7c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -326,8 +326,7 @@ public List getParameters(ExecutableType methodType, ExecutableElemen parameter.getSimpleName().toString(), getType( parameterType ), MappingTargetPrism.getInstanceOn( parameter ) != null, - TargetTypePrism.getInstanceOn( parameter ) != null, - false) ); + TargetTypePrism.getInstanceOn( parameter ) != null ) ); } return result; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index f0e74a6d51..2202f96715 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -116,7 +116,7 @@ public boolean matches(List sourceTypes, Type targetType) { return false; } - if ( !first( sourceTypes ).equals( parameters.get( 0 ).getType() ) ) { + if ( !first( sourceTypes ).equals( first( parameters ).getType() ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 4e74e9995c..7ad386749d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.model.source; -import static org.mapstruct.ap.internal.util.Collections.hasNonNullElements; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -90,27 +88,18 @@ boolean matches(List sourceTypes, Type resultType) { // check & collect generic types. Map genericTypesMap = new HashMap(); - if ( hasNonNullElements( sourceTypes ) ) { - // if sourceTypes contains non-null elements then only methods with all source parameters matching qualify - if ( candidateMethod.getSourceParameters().size() == sourceTypes.size() ) { - int i = 0; - for ( Parameter candidateSourceParam : candidateMethod.getSourceParameters() ) { - Type sourceType = sourceTypes.get( i++ ); - if ( sourceType == null - || !matchSourceType( sourceType, candidateSourceParam.getType(), genericTypesMap ) ) { - return false; - } + if ( candidateMethod.getParameters().size() == sourceTypes.size() ) { + int i = 0; + for ( Parameter candidateParam : candidateMethod.getParameters() ) { + Type sourceType = sourceTypes.get( i++ ); + if ( sourceType == null + || !matchSourceType( sourceType, candidateParam.getType(), genericTypesMap ) ) { + return false; } } - else { - return false; - } } else { - // if the sourceTypes empty/contains only nulls then only factory and lifecycle methods qualify - if ( !candidateMethod.isObjectFactory() && !candidateMethod.isLifecycleCallbackMethod() ) { - return false; - } + return false; } // check if the method matches the proper result type to construct diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index 1b7573f8ec..c4586c0860 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -42,14 +42,19 @@ public class CreateOrUpdateSelector implements MethodSelector { @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { - List createCandidates = new ArrayList(); - List updateCandidates = new ArrayList(); - for ( T method : methods ) { - boolean isCreateCandidate = method.getMappingTargetParameter() == null; + if ( criteria.isLifecycleCallbackRequired() || criteria.isObjectFactoryRequired() ) { + return methods; + } + + List> createCandidates = new ArrayList>(); + List> updateCandidates = new ArrayList>(); + for ( SelectedMethod method : methods ) { + boolean isCreateCandidate = method.getMethod().getMappingTargetParameter() == null; if ( isCreateCandidate ) { createCandidates.add( method ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index c190dd2f24..086493d8e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -35,26 +35,26 @@ public class InheritanceSelector implements MethodSelector { @Override - public List getMatchingMethods( - Method mappingMethod, - List methods, - Type sourceType, - Type targetType, - SelectionCriteria criteria - ) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, + Type targetType, + SelectionCriteria criteria) { - if ( sourceType == null ) { + if ( sourceTypes.size() != 1 ) { return methods; } - List candidatesWithBestMatchingSourceType = new ArrayList(); + Type singleSourceType = first( sourceTypes ); + + List> candidatesWithBestMatchingSourceType = new ArrayList>(); int bestMatchingSourceTypeDistance = Integer.MAX_VALUE; // find the methods with the minimum distance regarding getParameter getParameter type - for ( T method : methods ) { - Parameter singleSourceParam = first( method.getSourceParameters() ); + for ( SelectedMethod method : methods ) { + Parameter singleSourceParam = first( method.getMethod().getSourceParameters() ); - int sourceTypeDistance = sourceType.distanceTo( singleSourceParam.getType() ); + int sourceTypeDistance = singleSourceType.distanceTo( singleSourceParam.getType() ); bestMatchingSourceTypeDistance = addToCandidateListIfMinimal( candidatesWithBestMatchingSourceType, @@ -66,8 +66,8 @@ public List getMatchingMethods( return candidatesWithBestMatchingSourceType; } - private int addToCandidateListIfMinimal(List candidatesWithBestMathingType, - int bestMatchingTypeDistance, T method, + private int addToCandidateListIfMinimal(List> candidatesWithBestMathingType, + int bestMatchingTypeDistance, SelectedMethod method, int currentTypeDistance) { if ( currentTypeDistance == bestMatchingTypeDistance ) { candidatesWithBestMathingType.add( method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/ObjectFactorySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java similarity index 53% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/ObjectFactorySelector.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index 741505f009..c4b4944cb6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/ObjectFactorySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -23,23 +23,26 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.MethodMatcher; /** - * Selects those methods from the given input set which match whether a factory was requested ({@link MethodMatcher} and - * {@link org.mapstruct.ObjectFactory}). + * Selects those methods from the given input set which match for the requested family of methods: factory methods, + * lifecycle callback methods, or any other mapping methods. * * @author Remo Meier */ -public class ObjectFactorySelector implements MethodSelector { +public class MethodFamilySelector implements MethodSelector { @Override - public List getMatchingMethods(Method mappingMethod, List methods, Type sourceType, - Type targetType, SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, + Type targetType, SelectionCriteria criteria) { + + List> result = new ArrayList>( methods.size() ); + for ( SelectedMethod method : methods ) { + if ( method.getMethod().isObjectFactory() == criteria.isObjectFactoryRequired() + && method.getMethod().isLifecycleCallbackMethod() == criteria.isLifecycleCallbackRequired() ) { - List result = new ArrayList(); - for ( T method : methods ) { - if ( method.isObjectFactory() == criteria.isObjectFactoryRequired() ) { result.add( method ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java index a52d4f5c16..b6e0025296 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java @@ -30,20 +30,21 @@ * * @author Sjaak Derksen */ -public interface MethodSelector { +interface MethodSelector { /** * Selects those methods which match the given types and other criteria * * @param either SourceMethod or BuiltInMethod * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out - * @param methods list of available methods - * @param sourceType parameter type that should be matched - * @param targetType return type that should be matched + * @param candidates list of available methods + * @param sourceTypes parameter type(s) that should be matched + * @param targetType result type that should be matched * @param criteria criteria used in the selection process - * * @return list of methods that passes the matching process */ - List getMatchingMethods(Method mappingMethod, List methods, Type sourceType, - Type targetType, SelectionCriteria criteria); + List> getMatchingMethods(Method mappingMethod, + List> candidates, + List sourceTypes, + Type targetType, SelectionCriteria criteria); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 25dd993c94..9ee1629ae7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -34,38 +34,48 @@ * * @author Sjaak Derksen */ -public class MethodSelectors implements MethodSelector { +public class MethodSelectors { private final List selectors; public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeFactory) { - selectors = - Arrays.asList( - new ObjectFactorySelector(), - new TypeSelector(), - new QualifierSelector( typeUtils, elementUtils ), - new TargetTypeSelector( typeUtils, elementUtils ), - new XmlElementDeclSelector( typeUtils, elementUtils ), - new InheritanceSelector(), - new CreateOrUpdateSelector() - ); + selectors = Arrays.asList( + new MethodFamilySelector(), + new TypeSelector( typeFactory ), + new QualifierSelector( typeUtils, elementUtils ), + new TargetTypeSelector( typeUtils, elementUtils ), + new XmlElementDeclSelector( typeUtils, elementUtils ), + new InheritanceSelector(), + new CreateOrUpdateSelector() ); } - @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { + /** + * Selects those methods which match the given types and other criteria + * + * @param either SourceMethod or BuiltInMethod + * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out + * @param methods list of available methods + * @param sourceTypes parameter type(s) that should be matched + * @param targetType return type that should be matched + * @param criteria criteria used in the selection process + * @return list of methods that passes the matching process + */ + public List> getMatchingMethods(Method mappingMethod, List methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { - List candidates = new ArrayList( methods ); + List> candidates = new ArrayList>( methods.size() ); + for ( T method : methods ) { + candidates.add( new SelectedMethod( method ) ); + } for ( MethodSelector selector : selectors ) { candidates = selector.getMatchingMethods( mappingMethod, candidates, - sourceType, + sourceTypes, targetType, - criteria - ); + criteria ); } return candidates; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 84e9e3e5b3..bd34dc858a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -63,9 +63,10 @@ public QualifierSelector( Types typeUtils, Elements elementUtils ) { } @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { int numberOfQualifiersToMatch = 0; @@ -89,11 +90,11 @@ public List getMatchingMethods(Method mappingMethod, List< // Check there are qualfiers for this mapping: Mapping#qualifier or Mapping#qualfiedByName if ( qualifierTypes.isEmpty() ) { // When no qualifiers, disqualify all methods marked with a qualifier by removing them from the candidates - List nonQualiferAnnotatedMethods = new ArrayList(); - for ( T candidate : methods ) { + List> nonQualiferAnnotatedMethods = new ArrayList>( methods.size() ); + for ( SelectedMethod candidate : methods ) { - if ( candidate instanceof SourceMethod ) { - Set qualifierAnnotations = getQualifierAnnotationMirrors( candidate ); + if ( candidate.getMethod() instanceof SourceMethod ) { + Set qualifierAnnotations = getQualifierAnnotationMirrors( candidate.getMethod() ); if ( qualifierAnnotations.isEmpty() ) { nonQualiferAnnotatedMethods.add( candidate ); } @@ -107,15 +108,16 @@ public List getMatchingMethods(Method mappingMethod, List< } else { // Check all methods marked with qualfier (or methods in Mappers marked wiht a qualfier) for matches. - List matches = new ArrayList(); - for ( T candidate : methods ) { + List> matches = new ArrayList>( methods.size() ); + for ( SelectedMethod candidate : methods ) { - if ( !( candidate instanceof SourceMethod ) ) { + if ( !( candidate.getMethod() instanceof SourceMethod ) ) { continue; } // retrieve annotations - Set qualifierAnnotationMirrors = getQualifierAnnotationMirrors( candidate ); + Set qualifierAnnotationMirrors = + getQualifierAnnotationMirrors( candidate.getMethod() ); // now count if all qualifiers are matched int matchingQualifierCounter = 0; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java similarity index 52% rename from processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java index 68f0b3a3d6..0f9d10ee75 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java @@ -16,28 +16,40 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.internal.model; +package org.mapstruct.ap.internal.model.source.selector; import java.util.List; -import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.source.Method; /** - * Represents a reference to a factory method. + * A selected method with additional metadata that might be required for further usage of the selected method. * - * @author Remo Meier + * @author Andreas Gudian */ -public class ObjectFactoryMethodReference extends MethodReference { +public class SelectedMethod { + private T method; + private List parameterBindings; - private final List parameterAssignments; + public SelectedMethod(T method) { + this.method = method; + } + + public T getMethod() { + return method; + } + + public List getParameterBindings() { + return parameterBindings; + } - public ObjectFactoryMethodReference(Method method, MapperReference ref, List parameterAssignments) { - super( method, ref, null ); - this.parameterAssignments = parameterAssignments; + public void setParameterBindings(List parameterBindings) { + this.parameterBindings = parameterBindings; } - public List getParameterAssignments() { - return parameterAssignments; + @Override + public String toString() { + return method.toString(); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 7c0c161a0e..3b7159fd8b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -22,6 +22,7 @@ import java.util.List; import javax.lang.model.type.TypeMirror; + import org.mapstruct.ap.internal.model.source.SelectionParameters; /** @@ -37,9 +38,11 @@ public class SelectionCriteria { private final TypeMirror qualifyingResultType; private boolean preferUpdateMapping; private final boolean objectFactoryRequired; + private final boolean lifecycleCallbackRequired; public SelectionCriteria(SelectionParameters selectionParameters, String targetPropertyName, - boolean preferUpdateMapping, boolean objectFactoryRequired) { + boolean preferUpdateMapping, boolean objectFactoryRequired, + boolean lifecycleCallbackRequired) { if ( selectionParameters != null ) { qualifiers.addAll( selectionParameters.getQualifiers() ); qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); @@ -51,6 +54,7 @@ public SelectionCriteria(SelectionParameters selectionParameters, String targetP this.targetPropertyName = targetPropertyName; this.preferUpdateMapping = preferUpdateMapping; this.objectFactoryRequired = objectFactoryRequired; + this.lifecycleCallbackRequired = lifecycleCallbackRequired; } /** @@ -60,6 +64,13 @@ public boolean isObjectFactoryRequired() { return objectFactoryRequired; } + /** + * @return true if lifecycle callback methods should be selected, false otherwise. + */ + public boolean isLifecycleCallbackRequired() { + return lifecycleCallbackRequired; + } + public List getQualifiers() { return qualifiers; } @@ -84,4 +95,17 @@ public void setPreferUpdateMapping(boolean preferUpdateMapping) { this.preferUpdateMapping = preferUpdateMapping; } + public static SelectionCriteria forMappingMethods(SelectionParameters selectionParameters, + String targetPropertyName, boolean preferUpdateMapping) { + + return new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping, false, false ); + } + + public static SelectionCriteria forFactoryMethods(SelectionParameters selectionParameters) { + return new SelectionCriteria( selectionParameters, null, false, true, false ); + } + + public static SelectionCriteria forLifecycleMethods(SelectionParameters selectionParameters) { + return new SelectionCriteria( selectionParameters, null, false, false, true ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index 07c90d808a..c41e3047e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -45,16 +45,19 @@ public TargetTypeSelector( Types typeUtils, Elements elementUtils ) { } @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { TypeMirror qualifyingTypeMirror = criteria.getQualifyingResultType(); - if ( qualifyingTypeMirror != null ) { + if ( qualifyingTypeMirror != null && !criteria.isLifecycleCallbackRequired() ) { - List candidatesWithQualifyingTargetType = new ArrayList(); - for ( T method : methods ) { - TypeMirror resultTypeMirror = method.getResultType().getTypeElement().asType(); + List> candidatesWithQualifyingTargetType = + new ArrayList>( methods.size() ); + + for ( SelectedMethod method : methods ) { + TypeMirror resultTypeMirror = method.getMethod().getResultType().getTypeElement().asType(); if ( typeUtils.isSameType( qualifyingTypeMirror, resultTypeMirror ) ) { candidatesWithQualifyingTargetType.add( method ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index aa7b6ba2a5..5ca492e65b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -18,11 +18,15 @@ */ package org.mapstruct.ap.internal.model.source.selector; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.ArrayList; -import java.util.Arrays; import java.util.List; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.MethodMatcher; @@ -34,17 +38,168 @@ */ public class TypeSelector implements MethodSelector { + private TypeFactory typeFactory; + + public TypeSelector(TypeFactory typeFactory) { + this.typeFactory = typeFactory; + } + @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { - - List result = new ArrayList(); - for ( T method : methods ) { - if ( !method.isLifecycleCallbackMethod() && method.matches( Arrays.asList( sourceType ), targetType ) ) { - result.add( method ); + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { + + if ( methods.isEmpty() ) { + return methods; + } + + List> result = new ArrayList>(); + + List availableBindings; + if ( sourceTypes.isEmpty() ) { + // if no source types are given, we have a factory or lifecycle method + availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod ); + } + else { + availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType ); + } + + for ( SelectedMethod method : methods ) { + List> parameterBindingPermutations = + getCandidateParameterBindingPermutations( availableBindings, method.getMethod().getParameters() ); + + if ( parameterBindingPermutations != null ) { + SelectedMethod matchingMethod = + getFirstMatchingParameterBinding( targetType, method, parameterBindingPermutations ); + + if ( matchingMethod != null ) { + result.add( matchingMethod ); + } } } return result; } + + private List getAvailableParameterBindingsFromMethod(Method method) { + List availableParams = new ArrayList( method.getParameters().size() + 2 ); + + availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); + addMappingTargetAndTargetTypeBindings( availableParams, method.getResultType() ); + + return availableParams; + } + + private List getAvailableParameterBindingsFromSourceTypes(List sourceTypes, + Type targetType) { + + List availableParams = new ArrayList( sourceTypes.size() + 2 ); + + addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + + for ( Type sourceType : sourceTypes ) { + availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); + } + + return availableParams; + } + + private void addMappingTargetAndTargetTypeBindings(List availableParams, Type targetType) { + availableParams.add( ParameterBinding.forMappingTargetBinding( targetType ) ); + availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); + } + + private SelectedMethod getFirstMatchingParameterBinding(Type targetType, + SelectedMethod method, List> parameterAssignmentVariants) { + + for ( List parameterAssignments : parameterAssignmentVariants ) { + if ( method.getMethod().matches( extractTypes( parameterAssignments ), targetType ) ) { + method.setParameterBindings( parameterAssignments ); + return method; + } + } + return null; + } + + /** + * @param availableParams parameter bindings available in the scope of the method call + * @param methodParameters parameters of the method that is inspected + * @return all parameter binding permutations for which proper type checks need to be conducted. + */ + private static List> getCandidateParameterBindingPermutations( + List availableParams, + List methodParameters) { + + if ( methodParameters.size() > availableParams.size() ) { + return null; + } + + List> bindingPermutations = new ArrayList>( 1 ); + bindingPermutations.add( new ArrayList( methodParameters.size() ) ); + + for ( Parameter methodParam : methodParameters ) { + List candidateBindings = + findCandidateBindingsForParameter( availableParams, methodParam ); + + if ( candidateBindings.isEmpty() ) { + return null; + } + + if ( candidateBindings.size() == 1 ) { + // short-cut to avoid list-copies for the usual case where only one binding fits + for ( List variant : bindingPermutations ) { + // add binding to each existing variant + variant.add( first( candidateBindings ) ); + } + } + else { + List> newVariants = + new ArrayList>( bindingPermutations.size() * candidateBindings.size() ); + for ( List variant : bindingPermutations ) { + // create a copy of each variant for each binding + for ( ParameterBinding binding : candidateBindings ) { + List extendedVariant = + new ArrayList( methodParameters.size() ); + extendedVariant.addAll( variant ); + extendedVariant.add( binding ); + + newVariants.add( extendedVariant ); + } + } + + bindingPermutations = newVariants; + } + } + + return bindingPermutations; + } + + /** + * @param candidateParameters available for assignment. + * @param parameter that need assignment from one of the candidate parameter bindings. + * @return list of candidate parameter bindings that might be assignable. + */ + private static List findCandidateBindingsForParameter(List candidateParameters, + Parameter parameter) { + List result = new ArrayList( candidateParameters.size() ); + + for ( ParameterBinding candidate : candidateParameters ) { + if ( parameter.isTargetType() == candidate.isTargetType() + && parameter.isMappingTarget() == candidate.isMappingTarget() ) { + result.add( candidate ); + } + } + + return result; + } + + private static List extractTypes(List parameters) { + List result = new ArrayList( parameters.size() ); + + for ( ParameterBinding param : parameters ) { + result.add( param.getType() ); + } + + return result; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index d2b6165af4..254d5e6661 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -61,9 +61,10 @@ public XmlElementDeclSelector( Types typeUtils, Elements elementUtils) { } @Override - public List getMatchingMethods(Method mappingMethod, List methods, - Type sourceType, Type targetType, - SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { // only true source methods are qualifying if ( !(mappingMethod instanceof SourceMethod) ) { @@ -72,18 +73,18 @@ public List getMatchingMethods(Method mappingMethod, List< SourceMethod sourceMappingMethod = (SourceMethod) mappingMethod; - List nameMatches = new ArrayList(); - List scopeMatches = new ArrayList(); - List nameAndScopeMatches = new ArrayList(); + List> nameMatches = new ArrayList>(); + List> scopeMatches = new ArrayList>(); + List> nameAndScopeMatches = new ArrayList>(); XmlElementRefInfo xmlElementRefInfo = findXmlElementRef( sourceMappingMethod.getResultType(), criteria.getTargetPropertyName() ); - for ( T candidate : methods ) { - if ( !( candidate instanceof SourceMethod ) ) { + for ( SelectedMethod candidate : methods ) { + if ( !( candidate.getMethod() instanceof SourceMethod ) ) { continue; } - SourceMethod candidateMethod = (SourceMethod) candidate; + SourceMethod candidateMethod = (SourceMethod) candidate.getMethod(); XmlElementDeclPrism xmlElememtDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() ); if ( xmlElememtDecl == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 4287a596cf..16c1cd103a 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -18,6 +18,9 @@ */ package org.mapstruct.ap.internal.processor.creation; +import static java.util.Collections.singletonList; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -39,23 +42,20 @@ import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver; import org.mapstruct.ap.internal.model.MethodReference; -import org.mapstruct.ap.internal.model.ObjectFactoryMethodReference; -import org.mapstruct.ap.internal.model.ParameterAssignmentUtil; import org.mapstruct.ap.internal.model.SourceRHS; import org.mapstruct.ap.internal.model.VirtualMappingMethod; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; -import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -109,7 +109,7 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, Str boolean preferUpdateMapping) { SelectionCriteria criteria = - new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping, false ); + SelectionCriteria.forMappingMethods( selectionParameters, targetPropertyName, preferUpdateMapping ); String dateFormat = null; String numberFormat = null; @@ -139,58 +139,46 @@ public Set getUsedVirtualMappings() { public MethodReference getFactoryMethod(final Method mappingMethod, Type targetType, SelectionParameters selectionParameters) { - SelectionCriteria criteria = new SelectionCriteria( selectionParameters, null, false, true ); - - ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, mappingMethod, null, null, null, criteria ); - - List matchingSourceMethods = attempt.getMatches( sourceModel, null, targetType ); - - List factoryRefsWithAssigments = new ArrayList(); - List factoryRefSources = new ArrayList(); - - for ( Method matchingSourceMethod : matchingSourceMethods ) { - - if ( matchingSourceMethod != null ) { - MapperReference ref = attempt.findMapperReference( matchingSourceMethod ); + List> matchingFactoryMethods = + methodSelectors.getMatchingMethods( + mappingMethod, + sourceModel, + java.util.Collections. emptyList(), + targetType, + SelectionCriteria.forFactoryMethods( selectionParameters ) ); - if ( matchingSourceMethod.getSourceParameters().isEmpty() ) { - // factory taking no argument - factoryRefsWithAssigments.add( new MethodReference( matchingSourceMethod, ref, null ) ); - factoryRefSources.add( matchingSourceMethod ); - } - else { - // check whether factory have has a valid assignment, if so, choose as candidate - List availableParameters = new ArrayList(); - availableParameters.addAll( mappingMethod.getSourceParameters() ); - availableParameters.add( - new Parameter( null, - typeFactory.classTypeOf( targetType ), - false, true, false ) ); - List factoryParamAssinment = - ParameterAssignmentUtil.getParameterAssignments( availableParameters, - matchingSourceMethod.getParameters() ); - if ( factoryParamAssinment != null ) { - factoryRefSources.add( matchingSourceMethod ); - factoryRefsWithAssigments.add( - new ObjectFactoryMethodReference( matchingSourceMethod, ref, factoryParamAssinment ) ); - } - } - } + if (matchingFactoryMethods.isEmpty()) { + return null; } - if ( factoryRefsWithAssigments.size() > 1 ) { + if ( matchingFactoryMethods.size() > 1 ) { messager.printMessage( mappingMethod.getExecutable(), Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, targetType, - Strings.join( factoryRefSources, ", " ) ); - } - else if ( factoryRefsWithAssigments.size() == 1 ) { - // factory methods with assignment are favored over the ones without any - return factoryRefsWithAssigments.get( 0 ); + Strings.join( matchingFactoryMethods, ", " ) ); + + return null; } - // no factory found + SelectedMethod matchingFactoryMethod = first( matchingFactoryMethods ); + + MapperReference ref = findMapperReference( matchingFactoryMethod.getMethod() ); + + return new MethodReference( + matchingFactoryMethod.getMethod(), + ref, + matchingFactoryMethod.getParameterBindings() ); + } + + private MapperReference findMapperReference(Method method) { + for ( MapperReference ref : mapperReferences ) { + if ( ref.getType().equals( method.getDeclaringMapper() ) ) { + ref.setUsed( ref.isUsed() || !method.isStatic() ); + ref.setTypeRequiresImport( true ); + return ref; + } + } return null; } @@ -315,7 +303,7 @@ private Assignment resolveViaConversion(Type sourceType, Type targetType) { private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean considerBuiltInMethods) { // first try to find a matching source method - Method matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); + SelectedMethod matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); if ( matchingSourceMethod != null ) { return getMappingMethodReference( matchingSourceMethod, targetType ); @@ -329,15 +317,15 @@ private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean co } private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { - BuiltInMethod matchingBuiltInMethod = + SelectedMethod matchingBuiltInMethod = getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType ); if ( matchingBuiltInMethod != null ) { - virtualMethodCandidates.add( new VirtualMappingMethod( matchingBuiltInMethod ) ); + virtualMethodCandidates.add( new VirtualMappingMethod( matchingBuiltInMethod.getMethod() ) ); ConversionContext ctx = new DefaultConversionContext( typeFactory, messager, sourceType, targetType, dateFormat, numberFormat); - Assignment methodReference = new MethodReference( matchingBuiltInMethod, ctx ); + Assignment methodReference = new MethodReference( matchingBuiltInMethod.getMethod(), ctx ); methodReference.setAssignment( sourceRHS ); return methodReference; } @@ -491,22 +479,12 @@ private boolean isUpdateMethodForMapping(Method methodCandidate) { && !methodCandidate.isLifecycleCallbackMethod(); } - private List getMatches(List methods, Type sourceType, Type returnType) { - return methodSelectors.getMatchingMethods( - mappingMethod, - methods, - sourceType, - returnType, - selectionCriteria - ); - } - - private T getBestMatch(List methods, Type sourceType, Type returnType) { + private SelectedMethod getBestMatch(List methods, Type sourceType, Type returnType) { - List candidates = methodSelectors.getMatchingMethods( + List> candidates = methodSelectors.getMatchingMethods( mappingMethod, methods, - sourceType, + singletonList( sourceType ), returnType, selectionCriteria ); @@ -533,33 +511,23 @@ private T getBestMatch(List methods, Type sourceType, Type } if ( !candidates.isEmpty() ) { - return candidates.get( 0 ); + return first( candidates ); } return null; } - private Assignment getMappingMethodReference(Method method, + private Assignment getMappingMethodReference(SelectedMethod method, Type targetType) { - MapperReference mapperReference = findMapperReference( method ); + MapperReference mapperReference = findMapperReference( method.getMethod() ); - return new MethodReference( method, + return new MethodReference( + method.getMethod(), mapperReference, - SourceMethod.containsTargetTypeParameter( method.getParameters() ) ? targetType : null + method.getParameterBindings() ); } - private MapperReference findMapperReference(Method method) { - for ( MapperReference ref : mapperReferences ) { - if ( ref.getType().equals( method.getDeclaringMapper() ) ) { - ref.setUsed( !method.isStatic() ); - ref.setTypeRequiresImport( true ); - return ref; - } - } - return null; - } - /** * Whether the given source and target type are both a collection type or both a map type and the source value * can be propagated via a copy constructor. diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl index 3fd081ad90..a8dab4aaf4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl @@ -22,10 +22,7 @@ <#if hasReturnType()> <@includeModel object=methodResultType /> ${targetVariableName} = - <#if declaringType??>${instanceVariableName}.${name}( - <#list parameterAssignments as param> - <#if param.targetType><@includeModel object=ext.targetType raw=true/>.class<#elseif param.mappingTarget>${ext.targetBeanName}<#else>${param.name}<#if param_has_next>,<#else> - ); + <#include 'MethodReference.ftl'>; <#if hasReturnType()><#nt> if ( ${targetVariableName} != null ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 667b7c81ee..f098c93230 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -28,18 +28,20 @@ <#macro params> <@compress> - ${name}<#if (parameters?size > 0)>( <@arguments/> )<#else>() + ${name}<#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() <#macro arguments> - <#list parameters as param> + <#list parameterBindings as param> <#if param.targetType> <#-- a class is passed on for casting, see @TargetType --> <@includeModel object=ext.targetType raw=true/>.class<#t> <#elseif param.mappingTarget> - ${ext.targetBeanName}.${ext.targetReadAccessorName} + ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> + <#elseif assignment??> + <@_assignment/><#t> <#else> - <@_assignment/> + ${param.variableName}<#t> <#if param_has_next>, <#t> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.ftl deleted file mode 100644 index 2d7a55df6a..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ObjectFactoryMethodReference.ftl +++ /dev/null @@ -1,46 +0,0 @@ -<#-- - - Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<@compress single_line=true> - <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> - <#if declaringMapper??><#if static><@includeModel object=declaringMapper.type/><#else>${mapperVariableName}.<@params/> - <#-- method is referenced java8 static method in the mapper to implement (interface) --> - <#elseif static><@includeModel object=definingType/>.<@params/> - <#else> - <@params/> - - <#macro params> - <@compress> - ${name}<#if (parameterAssignments?size > 0)>( <@arguments/> )<#else>() - - - <#macro arguments> - <#list parameterAssignments as param> - <#if param.targetType> - <#-- a class is passed on for casting, see @TargetType --> - <@includeModel object=ext.targetType raw=true/>.class<#t> - <#elseif param.mappingTarget> - ${ext.targetBeanName}.${ext.targetReadAccessorName}() - <#else>${param.name}<#if param_has_next>, <#t> - - <#-- context parameter, e.g. for builtin methods concerning date conversion --> - <#if contextParam??>, ${contextParam}<#t> - - diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java index 8cfabf29d1..782fecac4a 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java @@ -73,7 +73,8 @@ private List createRunners(Class klass) throws Exception { return Arrays. asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK ), - new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE ) ); + new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE ) + ); } @Override From fc0f13a7a1ad1a26ba761582edf6c64621a98613 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 20 Dec 2016 00:06:12 +0100 Subject: [PATCH 0007/1006] #999 make sure that the qualifiedName of the class is trimmed before doing any comparisons for import check --- .../ap/internal/model/common/TypeFactory.java | 19 ++++++++++++++++--- .../ap/test/array/ArrayMappingTest.java | 18 ++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index e1a2e6e7c8..db5674b217 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -36,7 +36,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; - import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -444,16 +443,17 @@ private TypeMirror getComponentType(TypeMirror mirror) { private boolean isImported(String name, String qualifiedName) { String trimmedName = TypeFactory.trimSimpleClassName( name ); + String trimmedQualifiedName = TypeFactory.trimSimpleClassName( qualifiedName ); String importedType = importedQualifiedTypesBySimpleName.get( trimmedName ); boolean imported = false; if ( importedType != null ) { - if ( importedType.equals( qualifiedName ) ) { + if ( importedType.equals( trimmedQualifiedName ) ) { imported = true; } } else { - importedQualifiedTypesBySimpleName.put( trimmedName, qualifiedName ); + importedQualifiedTypesBySimpleName.put( trimmedName, trimmedQualifiedName ); imported = true; } return imported; @@ -530,6 +530,19 @@ else if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { return typeMirror; } + /** + * It strips the all the {@code []} from the {@code className}. + * + * E.g. + *
+     *     trimSimpleClassName("String[][][]") -> "String"
+     *     trimSimpleClassName("String[]") -> "String"
+     * 
+ * + * @param className that needs to be trimmed + * + * @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null} + */ static String trimSimpleClassName(String className) { if ( className == null ) { return null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index beedfbe2d9..2a664ef9a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -18,11 +18,10 @@ */ package org.mapstruct.ap.test.array; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.List; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.array._target.ScientistDto; @@ -30,12 +29,22 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses( { Scientist.class, ScientistDto.class, ScienceMapper.class } ) @RunWith(AnnotationProcessorTestRunner.class) @IssueKey("108") public class ArrayMappingTest { + private final GeneratedSource generatedSource = new GeneratedSource(); + + @Rule + public GeneratedSource getGeneratedSource() { + return generatedSource; + } + @Test public void shouldCopyArraysInBean() { @@ -226,4 +235,9 @@ public void shouldVoidMapintWhenReturnDefault() { assertThat( existingTarget ).containsOnly( new long[] { 0L } ); } + @Test + @IssueKey( "999" ) + public void shouldNotContainFQNForStringArray() { + getGeneratedSource().forMapper( ScienceMapper.class ).content().doesNotContain( "java.lang.String[]" ); + } } From 1f0533ca948ea7902de4df6b10288de87c6c83dc Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Dec 2016 22:43:14 +0100 Subject: [PATCH 0008/1006] #996 refactor ArrayCopyWrapper --- .../ap/internal/model/MapMappingMethod.java | 10 ----- .../ap/internal/model/PropertyMapping.java | 4 +- .../model/assignment/ArrayCopyWrapper.java | 22 ++++----- .../internal/model/assignment/Assignment.java | 13 +++--- .../model/assignment/NullCheckWrapper.java | 32 ------------- .../assignment/UpdateNullCheckWrapper.java | 33 -------------- .../model/assignment/ArrayCopyWrapper.ftl | 28 +++--------- .../GetterWrapperForCollectionsAndMaps.ftl | 4 +- .../model/assignment/NullCheckWrapper.ftl | 45 ------------------- .../model/assignment/SetterWrapper.ftl | 32 ++----------- .../SetterWrapperForCollectionsAndMaps.ftl | 10 ++--- .../assignment/UpdateNullCheckWrapper.ftl | 32 ------------- .../ap/internal/model/macro/CommonMacros.ftl | 45 ++++++++++++++++--- 13 files changed, 74 insertions(+), 236 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.java delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.ftl delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 7506b69fde..35c8f81d22 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -151,17 +151,7 @@ public MapMappingMethod build() { } if ( valueAssignment == null ) { - valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); - -// if ( method instanceof ForgedMethod ) { -// // leave messaging to calling property mapping -// return null; -// } -// else { -// ctx.getMessager().printMessage( method.getExecutable(), -// Message.MAPMAPPING_VALUE_MAPPING_NOT_FOUND ); -// } } // mapNullToDefault diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index dcb9c08d52..0d9d217f76 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -37,7 +37,6 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; -import org.mapstruct.ap.internal.model.assignment.NullCheckWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; @@ -435,10 +434,9 @@ private Assignment assignToArray(Type targetType, Assignment rightHandSide) { targetPropertyName, arrayType, targetType, - existingVariableNames, isFieldAssignment() ); - return new NullCheckWrapper( assignment ); + return assignment; } private SourceRHS getSourceRHS( SourceReference sourceReference ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index fd187329b8..f11eb94519 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -18,16 +18,10 @@ */ package org.mapstruct.ap.internal.model.assignment; -import static org.mapstruct.ap.internal.util.Strings.decapitalize; -import static org.mapstruct.ap.internal.util.Strings.getSaveVariableName; - -import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.util.Strings; /** * Decorates the assignment as a Map or Collection constructor @@ -36,16 +30,18 @@ */ public class ArrayCopyWrapper extends AssignmentWrapper { - private final String targetPropertyName; private final Type arraysType; private final Type targetType; - public ArrayCopyWrapper(Assignment decoratedAssignment, String targetPropertyName, Type arraysType, - Type targetType, Collection existingVariableNames, boolean fieldAssignment) { - super( decoratedAssignment, fieldAssignment ); - this.targetPropertyName = Strings.getSaveVariableName( targetPropertyName, existingVariableNames ); + public ArrayCopyWrapper(Assignment rhs, + String targetPropertyName, + Type arraysType, + Type targetType, + boolean fieldAssignment) { + super( rhs, fieldAssignment ); this.arraysType = arraysType; this.targetType = targetType; + rhs.setSourceLocalVarName( rhs.createLocalVarName( targetPropertyName ) ); } @Override @@ -57,7 +53,7 @@ public Set getImportTypes() { return imported; } - public String getLocalVarName() { - return getSaveVariableName( decapitalize( targetPropertyName ), Collections.emptyList() ); + public boolean isIncludeSourceNullCheck() { + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java index 09ef8bed1b..2573cb9f7b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java @@ -109,17 +109,18 @@ public boolean isConverted() { Type getSourceType(); /** - * safe (local) element variable name when dealing with collections. + * Creates an unique safe (local) variable name. * * @param desiredName the desired name - * @return the desired name, made unique + * + * @return the desired name, made unique in the scope of the bean mapping. */ String createLocalVarName( String desiredName ); /** - * a local variable name for supporting a null check and avoiding executing a nested method forged method twice + * See {@link #setSourceLocalVarName(java.lang.String) } * - * @return local variable name (can be null) + * @return local variable name (can be null if not set) */ String getSourceLocalVarName(); @@ -132,7 +133,9 @@ public boolean isConverted() { String getSourceParameterName(); /** - * Use sourceLocalVarName iso sourceReference + * Replaces the sourceReference at the call site in the assignment in the template with this sourceLocalVarName. + * The sourceLocalVarName can subsequently be used for e.g. null checking. + * * @param sourceLocalVarName source local variable name */ void setSourceLocalVarName(String sourceLocalVarName); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.java deleted file mode 100644 index 937465d998..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.internal.model.assignment; - -/** - * Wraps the assignment in a null check. - * - * @author Sjaak Derksen - */ -public class NullCheckWrapper extends AssignmentWrapper { - - public NullCheckWrapper( Assignment decoratedAssignment ) { - super( decoratedAssignment, false ); - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.java deleted file mode 100644 index c769f36588..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.internal.model.assignment; - -/** - * Wraps an update-assignment in a null check and sets the target property to {@code null}, if the source is - * {@code null}. - * - * @author Andreas Gudian - */ -public class UpdateNullCheckWrapper extends AssignmentWrapper { - - public UpdateNullCheckWrapper(Assignment decoratedAssignment, boolean fieldAssignment) { - super( decoratedAssignment, fieldAssignment ); - } - -} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl index 767b9ede8d..408ccd3825 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl @@ -19,25 +19,9 @@ --> <#import "../macro/CommonMacros.ftl" as lib> -<#if (thrownTypes?size == 0) > - <@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>; - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>Arrays.copyOf( ${localVarName}, ${localVarName}.length ); -<#else> - try { - <@includeModel object=ext.targetType/> ${localVarName} = <@_assignment/>; - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>Arrays.copyOf(>Arrays.copyOf( ${localVarName}, ${localVarName}.length ); - } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - - -<#macro _assignment> - <@includeModel object=assignment - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=ext.targetReadAccessorName - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType/> - +<@lib.handleExceptions> + <@lib.sourceLocalVarAssignment/> + <@lib.handleSourceReferenceNullCheck> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>Arrays.copyOf( ${sourceLocalVarName}, ${sourceLocalVarName}.length ); + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index 1cc8cad11b..ec220a9309 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -25,8 +25,8 @@ if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesi <#if ext.existingInstanceMapping> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.clear(); - <@lib.handleNullCheck> + <@lib.handleLocalVarNullCheck> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); - + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.ftl deleted file mode 100644 index 1f0037942b..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NullCheckWrapper.ftl +++ /dev/null @@ -1,45 +0,0 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.NullCheckWrapper" --> -<#-- - - Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<#if sourceLocalVarName??> -<@includeModel object=sourceType/> ${sourceLocalVarName} = ${sourceReference}; -if ( ${sourceLocalVarName} != null ) { - <@_assignment object=assignment defaultValue=ext.defaultValueAssignment/> -} -<#else> -if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else>${sourceReference} != null ) { - <@_assignment object=assignment defaultValue=ext.defaultValueAssignment/> -} - -<#if ext.defaultValueAssignment?? > -else { - <@_assignment object=ext.defaultValueAssignment/> -} - -<#macro _assignment object defaultValue=""> - <@includeModel object=object - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=ext.targetReadAccessorName - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType - defaultValue=defaultValue/> - diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index 468e6fcf02..3eb6251278 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -21,31 +21,7 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> <@lib.sourceLocalVarAssignment/> - <#if sourcePresenceCheckerReference??> - if ( ${sourcePresenceCheckerReference} ) { - <@assignment/>; - } - <@elseDefaultAssignment/> - <#elseif includeSourceNullCheck || ext.defaultValueAssignment??> - if ( <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { - <@assignment/>; - } - <@elseDefaultAssignment/> - <#else> - <@assignment/>; - - -<#-- - standard assignment ---> -<#macro assignment>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/> -<#-- - add default assignment when required ---> -<#macro elseDefaultAssignment> - <#if ext.defaultValueAssignment?? > - else { - <@lib.handeDefaultAssigment/> - } - - \ No newline at end of file + <@lib.handleSourceReferenceNullCheck> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index ef6c1e0c75..0018150dc3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -23,11 +23,11 @@ <@lib.handleExceptions> <#if ext.existingInstanceMapping> if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} != null ) { - <@lib.handleNullCheck> + <@lib.handleLocalVarNullCheck> ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); - - <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleNullCheck --> + + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; } @@ -43,9 +43,9 @@ assigns the target via the regular target write accessor (usually the setter) --> <#macro callTargetWriteAccessor> - <@lib.handleNullCheck> + <@lib.handleLocalVarNullCheck> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else>${nullCheckLocalVarName}; - + <#-- wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.ftl deleted file mode 100644 index 1e87e687a9..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateNullCheckWrapper.ftl +++ /dev/null @@ -1,32 +0,0 @@ -<#-- - - Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<#import '../macro/CommonMacros.ftl' as lib> -if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else>${sourceReference} != null ) { - <@includeModel object=assignment - targetBeanName=ext.targetBeanName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=ext.targetReadAccessorName - targetWriteAccessorName=ext.targetWriteAccessorName - targetType=ext.targetType/> -} -else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; -} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 2a52ed235b..34d93b8277 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -18,18 +18,51 @@ limitations under the License. --> +<#-- + macro: handleSourceReferenceNullCheck + + purpose: macro surrounds nested with either a source presence checker or a null check. It acts directly on the + source reference. It adds an else clause with the default assigment when applicable. + requires: caller to implement boolean:getIncludeSourceNullCheck() +--> +<#macro handleSourceReferenceNullCheck> + <#if sourcePresenceCheckerReference??> + if ( ${sourcePresenceCheckerReference} ) { + <#nested> + } + <@elseDefaultAssignment/> + <#elseif includeSourceNullCheck || ext.defaultValueAssignment??> + if ( <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { + <#nested> + } + <@elseDefaultAssignment/> + <#else> + <#nested> + + +<#-- + local macro related to handleSourceReferenceNullCheck +--> +<#macro elseDefaultAssignment> + <#if ext.defaultValueAssignment?? > + else { + <@handeDefaultAssigment/> + } + + <#-- - macro: handleNullCheck + macro: handleLocalVarNullCheck purpose: macro surrounds nested with either a source presence checker or a null check. It always uses a local variable. Note that the local variable assignemnt is inside the IF statement for the source presence check. Note also, that the else clause contains the default variable assignment if present. - TODO: is only used by collection mapping currently.. should perhas be moved to there and not in common + requires: caller to implement String:getNullCheckLocalVarName() + caller to implement Type:getNullCheckLocalVarType() --> -<#macro handleNullCheck> +<#macro handleLocalVarNullCheck> <#if sourcePresenceCheckerReference??> if ( ${sourcePresenceCheckerReference} ) { <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; @@ -47,7 +80,6 @@ } - <#-- macro: handleExceptions @@ -130,10 +162,11 @@ Performs a default assignment with a default value. <#-- macro: sourceLocalVarAssignment - purpose: assigment for source local variables + purpose: assignment for source local variables. The sourceLocalVarName replaces the sourceReference in the + assignmentcall. --> <#macro sourceLocalVarAssignment> <#if sourceLocalVarName??> <@includeModel object=sourceType/> ${sourceLocalVarName} = ${sourceReference}; - + \ No newline at end of file From ea6493d983c9182b56b0f85cbdafe50c73947382 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 20 Dec 2016 23:31:57 +0100 Subject: [PATCH 0009/1006] #657 Using bean mapping result types works when the map return type is not an interface --- .../processor/MapperCreationProcessor.java | 5 ++- .../ap/test/selection/resulttype/Apple.java | 2 +- .../resulttype/InheritanceSelectionTest.java | 28 +++++++++++++ .../ap/test/selection/resulttype/IsFruit.java | 30 ++++++++++++++ ...tructingFruitInterfaceErroneousMapper.java | 37 ++++++++++++++++++ ...tTypeConstructingFruitInterfaceMapper.java | 39 +++++++++++++++++++ 6 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 9dea5d0a94..7a3cd1ff39 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -429,7 +429,10 @@ else if ( method.isEnumMapping() ) { .build(); if ( beanMappingMethod != null ) { - hasFactoryMethod = beanMappingMethod.getFactoryMethod() != null; + // We can consider that the mapping method has a factory method if it has one, + // or if the result type of the methods is not an interface + hasFactoryMethod = beanMappingMethod.getFactoryMethod() != null || + !beanMappingMethod.getResultType().isInterface(); mappingMethods.add( beanMappingMethod ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java index af562703d7..6d7b66a680 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java @@ -22,7 +22,7 @@ * * @author Sjaak Derksen */ -public class Apple extends Fruit { +public class Apple extends Fruit implements IsFruit { public Apple() { super( "constructed-by-constructor" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 8760d007be..1273ac4eb1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -42,6 +42,7 @@ */ @IssueKey("385") @WithClasses({ + IsFruit.class, Fruit.class, FruitDto.class, Apple.class, @@ -88,6 +89,33 @@ public void testResultTypeBasedConstructionOfResult() { assertThat( fruit.getType() ).isEqualTo( "constructed-by-constructor" ); } + @Test + @IssueKey("657") + @WithClasses( { ResultTypeConstructingFruitInterfaceMapper.class } ) + public void testResultTypeBasedConstructionOfResultForInterface() { + + FruitDto fruitDto = new FruitDto( null ); + IsFruit fruit = ResultTypeConstructingFruitInterfaceMapper.INSTANCE.map( fruitDto ); + assertThat( fruit ).isNotNull(); + assertThat( fruit.getType() ).isEqualTo( "constructed-by-constructor" ); + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ResultTypeConstructingFruitInterfaceErroneousMapper.class, + kind = Kind.ERROR, + line = 36, + messageRegExp = "No implementation type is registered for return type .*\\.IsFruit." + ) + } + ) + @IssueKey("657") + @WithClasses({ ResultTypeConstructingFruitInterfaceErroneousMapper.class }) + public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { + } + @Test @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java new file mode 100644 index 0000000000..f5e1d1b88a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.selection.resulttype; + +/** + * + * @author Filip Hrisafov + */ +public interface IsFruit { + + String getType(); + + void setType(String type); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java new file mode 100644 index 0000000000..2afc08d33a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface ResultTypeConstructingFruitInterfaceErroneousMapper { + + ResultTypeConstructingFruitInterfaceErroneousMapper INSTANCE = Mappers.getMapper( + ResultTypeConstructingFruitInterfaceErroneousMapper.class ); + + @Mapping(target = "type", ignore = true) + IsFruit map(FruitDto source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java new file mode 100644 index 0000000000..a68aaf692f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface ResultTypeConstructingFruitInterfaceMapper { + + ResultTypeConstructingFruitInterfaceMapper INSTANCE = Mappers.getMapper( + ResultTypeConstructingFruitInterfaceMapper.class ); + + @BeanMapping(resultType = Apple.class) + @Mapping(target = "type", ignore = true) + IsFruit map(FruitDto source); +} From d1388c3a4586e59650c9450e20a4affc71fa041f Mon Sep 17 00:00:00 2001 From: sjaakd Date: Wed, 21 Dec 2016 00:26:21 +0100 Subject: [PATCH 0010/1006] #941 undesired too postfixes in local variable names --- .../mapstruct/ap/internal/model/MappingMethod.java | 12 +++++++----- .../ap/internal/model/source/SourceMethod.java | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 59416d86ec..26024250fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -90,23 +90,25 @@ protected MappingMethod(Method method, List parameters, Collection parameters) { - this( method, parameters, method.getParameterNames(), null, null, Collections.emptyList() ); + this( method, parameters, new ArrayList( method.getParameterNames() ), null, null, + Collections.emptyList() ); } protected MappingMethod(Method method) { - this( method, method.getParameterNames(), null, null ); + this( method, new ArrayList( method.getParameterNames() ), null, null ); } protected MappingMethod(Method method, List beforeMappingReferences, List afterMappingReferences) { - this( method, method.getParameterNames(), beforeMappingReferences, afterMappingReferences ); + this( method, new ArrayList( method.getParameterNames() ), beforeMappingReferences, + afterMappingReferences ); } protected MappingMethod(Method method, List beforeMappingReferences, List afterMappingReferences, List forgedMethods) { - this( method, method.getParameters(), method.getParameterNames(), beforeMappingReferences, - afterMappingReferences, forgedMethods ); + this( method, method.getParameters(), new ArrayList( method.getParameterNames() ), + beforeMappingReferences, afterMappingReferences, forgedMethods ); } public MappingMethod(Method method, Collection existingVariableNames, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index d59df8df37..13becab3f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -314,11 +314,13 @@ public List getSourceParameters() { @Override public List getParameterNames() { if ( parameterNames == null ) { - parameterNames = new ArrayList( parameters.size() ); + List names = new ArrayList( parameters.size() ); for ( Parameter parameter : parameters ) { - parameterNames.add( parameter.getName() ); + names.add( parameter.getName() ); } + + parameterNames = Collections.unmodifiableList( names ); } return parameterNames; From 2fdd392e19dfad7f9d2365fffb7945f5b8049140 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Wed, 21 Dec 2016 19:31:08 +0100 Subject: [PATCH 0011/1006] #941 adapting strategy naming of safe variable names --- .../mapstruct/ap/internal/util/Strings.java | 12 +++++++--- .../ap/internal/util/StringsTest.java | 24 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index d0c6dcb63f..a0bf265af9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -156,11 +156,17 @@ public static String getSaveVariableName(String name, Collection existin Set conflictingNames = new HashSet( KEYWORDS ); conflictingNames.addAll( existingVariableNames ); - while ( conflictingNames.contains( name ) ) { - name = name + "_"; + if ( !conflictingNames.contains( name ) ) { + return name; } - return name; + int c = 1; + String seperator = Character.isDigit( name.charAt( name.length() - 1 ) ) ? "_" : ""; + while ( conflictingNames.contains( name + seperator + c ) ) { + c++; + } + + return name + seperator + c; } /** diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 2bf21b5e60..0ac09d1e84 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -73,21 +73,27 @@ public void testIsEmpty() throws Exception { @Test public void testGetSaveVariableNameWithArrayExistingVariables() throws Exception { assertThat( Strings.getSaveVariableName( "int[]" ) ).isEqualTo( "intArray" ); - assertThat( Strings.getSaveVariableName( "Extends" ) ).isEqualTo( "extends_" ); - assertThat( Strings.getSaveVariableName( "class" ) ).isEqualTo( "class_" ); - assertThat( Strings.getSaveVariableName( "Class" ) ).isEqualTo( "class_" ); - assertThat( Strings.getSaveVariableName( "Case" ) ).isEqualTo( "case_" ); - assertThat( Strings.getSaveVariableName( "Synchronized" ) ).isEqualTo( "synchronized_" ); - assertThat( Strings.getSaveVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop__" ); + assertThat( Strings.getSaveVariableName( "Extends" ) ).isEqualTo( "extends1" ); + assertThat( Strings.getSaveVariableName( "class" ) ).isEqualTo( "class1" ); + assertThat( Strings.getSaveVariableName( "Class" ) ).isEqualTo( "class1" ); + assertThat( Strings.getSaveVariableName( "Case" ) ).isEqualTo( "case1" ); + assertThat( Strings.getSaveVariableName( "Synchronized" ) ).isEqualTo( "synchronized1" ); + assertThat( Strings.getSaveVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); + } + + @Test + public void testGetSaveVariableNameVariablesEndingOnNumberVariables() throws Exception { + assertThat( Strings.getSaveVariableName( "prop1", "prop1" ) ).isEqualTo( "prop1_1" ); + assertThat( Strings.getSaveVariableName( "prop1", "prop1", "prop1_1" ) ).isEqualTo( "prop1_2" ); } @Test public void testGetSaveVariableNameWithCollection() throws Exception { assertThat( Strings.getSaveVariableName( "int[]", new ArrayList() ) ).isEqualTo( "intArray" ); - assertThat( Strings.getSaveVariableName( "Extends", new ArrayList() ) ).isEqualTo( "extends_" ); - assertThat( Strings.getSaveVariableName( "prop", Arrays.asList( "prop", "prop_" ) ) ).isEqualTo( "prop__" ); + assertThat( Strings.getSaveVariableName( "Extends", new ArrayList() ) ).isEqualTo( "extends1" ); + assertThat( Strings.getSaveVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); assertThat( Strings.getSaveVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) - .isEqualTo( "propFont__" ); + .isEqualTo( "propFont1" ); } @Test From 78db48f7cb74da9a77c18c68723b3ff59acbe739 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Wed, 21 Dec 2016 19:43:15 +0100 Subject: [PATCH 0012/1006] #941 adapting more logical names for local variables --- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 4 ++-- .../ap/internal/model/assignment/AdderWrapper.java | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 0d9d217f76..4192c58540 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -366,7 +366,7 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { Assignment result = rightHandSide; if ( result.getSourceType().isCollectionType() ) { - result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment() ); + result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName ); } else { // Possibly adding null to a target collection. So should be surrounded by an null check. @@ -508,7 +508,7 @@ else if ( propertyEntries.size() == 1 ) { ); // create a local variable to which forged method can be assigned. - String desiredName = first( sourceReference.getPropertyEntries() ).getName(); + String desiredName = last( sourceReference.getPropertyEntries() ).getName(); sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) ); return sourceRhs; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 9d6142ed61..9052c0c9e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -24,6 +24,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Nouns; /** * Wraps the assignment in a target setter. @@ -34,10 +35,13 @@ public class AdderWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; - public AdderWrapper( Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment ) { + public AdderWrapper( Assignment rhs, + List thrownTypesToExclude, + boolean fieldAssignment, + String targetPropertyName ) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; - String desiredName = rhs.getSourceType().getTypeParameters().get( 0 ).getName(); + String desiredName = Nouns.singularize( targetPropertyName ); rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); } From 00b8ae01a1e08ca4c82e84b4509be4aeb050682b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 22 Dec 2016 23:07:49 +0100 Subject: [PATCH 0013/1006] #1014 do not generate FQN for extends/super bound Types --- .../ap/internal/model/common/Type.ftl | 18 +++++++++++++++++- .../test/collection/wildcard/WildCardTest.java | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index c843b2d63f..0103202b36 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> <#-- Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) @@ -18,4 +19,19 @@ limitations under the License. --> -<#if imported>${name}<#else>${fullyQualifiedName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > \ No newline at end of file +<@compress single_line=true> + <#if wildCardExtendsBound> + ? extends <@includeModel object=typeBound /> + <#elseif wildCardSuperBound> + ? super <@includeModel object=typeBound /> + <#else> + <#if imported> + ${name} + <#else> + ${fullyQualifiedName} + + + <#if (!ext.raw?? && typeParameters?size > 0) > + <<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > + + \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index c8460b63df..2b48533ef8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -25,6 +25,7 @@ import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -33,6 +34,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/527. @@ -43,6 +45,9 @@ @RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + @Test @WithClasses({ ExtendsBoundSourceTargetMapper.class, @@ -59,7 +64,10 @@ public void shouldGenerateExtendsBoundSourceForgedIterableMethod() { assertThat( target ).isNotNull(); assertThat( target.getElements() ).isNull(); - + generatedSource.forMapper( ExtendsBoundSourceTargetMapper.class ) + .content() + .as( "Should not contain FQN after extends" ) + .doesNotContain( "? extends org.mapstruct.ap.test.collection.wildcard.Idea" ); } @Test @@ -78,7 +86,10 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { assertThat( target ).isNotNull(); assertThat( target.getElements() ).isNull(); - + generatedSource.forMapper( SourceSuperBoundTargetMapper.class ) + .content() + .as( "Should not contain FQN after super" ) + .doesNotContain( "? super org.mapstruct.ap.test.collection.wildcard.Idea" ); } @Test From 44fe197d3b307276ef69b61c4e7a2eddc2a6bce6 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Tue, 20 Dec 2016 19:29:38 +0100 Subject: [PATCH 0014/1006] #975 Introduce @Context annotation for passing context parameters through generated mapping methods to custom methods --- .../src/main/java/org/mapstruct/Context.java | 89 +++++++++++++ .../ap/internal/model/HelperMethod.java | 9 +- .../internal/model/IterableMappingMethod.java | 3 +- .../ap/internal/model/MapMappingMethod.java | 3 +- .../ap/internal/model/MappingMethod.java | 12 +- .../model/NestedPropertyMappingMethod.java | 2 +- .../ap/internal/model/PropertyMapping.java | 32 +++-- .../ap/internal/model/common/Parameter.java | 62 +++++++++- .../model/common/ParameterBinding.java | 21 +++- .../ap/internal/model/common/TypeFactory.java | 9 +- .../internal/model/source/ForgedMethod.java | 58 ++++++--- .../ap/internal/model/source/Method.java | 14 ++- .../internal/model/source/SourceMethod.java | 51 +++----- .../model/source/builtin/BuiltInMethod.java | 5 + .../model/source/selector/TypeSelector.java | 13 +- .../ap/internal/prism/PrismGenerator.java | 2 + .../processor/MethodRetrievalProcessor.java | 40 +++--- .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/internal/model/MethodReference.ftl | 4 +- .../{AttributeDTO.java => AttributeDto.java} | 10 +- .../CallbacksWithReturnValuesTest.java | 10 +- .../returning/{NodeDTO.java => NodeDto.java} | 23 ++-- .../returning/NodeMapperDefault.java | 8 +- .../returning/NodeMapperWithContext.java | 8 +- .../AutomappingNodeMapperWithContext.java | 39 ++++++ .../ContextParameterErroneousTest.java | 60 +++++++++ .../ap/test/context/ContextParameterTest.java | 117 ++++++++++++++++++ .../ap/test/context/CycleContext.java | 42 +++++++ .../context/CycleContextLifecycleMethods.java | 52 ++++++++ .../ap/test/context/FactoryContext.java | 46 +++++++ .../org/mapstruct/ap/test/context/Node.java | 100 +++++++++++++++ .../mapstruct/ap/test/context/NodeDto.java | 114 +++++++++++++++++ .../test/context/NodeMapperWithContext.java | 45 +++++++ ...usNodeMapperWithNonUniqueContextTypes.java | 34 +++++ 34 files changed, 989 insertions(+), 149 deletions(-) create mode 100644 core-common/src/main/java/org/mapstruct/Context.java rename processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/{AttributeDTO.java => AttributeDto.java} (87%) rename processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/{NodeDTO.java => NodeDto.java} (74%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/Node.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core-common/src/main/java/org/mapstruct/Context.java new file mode 100644 index 0000000000..b066f0ac9a --- /dev/null +++ b/core-common/src/main/java/org/mapstruct/Context.java @@ -0,0 +1,89 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a parameter of a method to be treated as mapping context. Such parameters are passed to other mapping + * methods, {@link ObjectFactory} methods or {@link BeforeMapping}/{@link AfterMapping} methods when applicable and can + * thus be used in custom code. The {@link Context} parameters are otherwise ignored by MapStruct. + *

+ * For generated code to call a method that is declared with {@link Context} parameters, the declaration of the mapping + * method being generated needs to contain at least those (or assignable) {@link Context} parameters as well. MapStruct + * will not create new instances of missing {@link Context} parameters nor will it pass {@code null} instead. + *

+ * Example: + * + *

+ * 
+ * // multiple @Context parameters can be added
+ * public abstract CarDto toCar(Car car, @Context VehicleRegistration context, @Context Locale localeToUse);
+ *
+ * protected OwnerManualDto translateOwnerManual(OwnerManual ownerManual, @Context Locale locale) {
+ *     // manually implemented logic to translate the OwnerManual with the given Locale
+ * }
+ *
+ * @BeforeMapping
+ * protected void registerVehicle(Vehicle mappedVehicle, @Context VehicleRegistration context) {
+ *     context.register( mappedVehicle );
+ * }
+ *
+ * @BeforeMapping
+ * protected void logMappedVehicle(Vehicle mappedVehicle) {
+ *     // do something with the vehicle
+ * }
+ *
+ * @BeforeMapping
+ * protected void notCalled(Vehicle mappedVehicle, @Context DifferentMappingContextType context) {
+ *     // not called, because DifferentMappingContextType is not available
+ *     // within toCar(Car, VehicleRegistration, Locale)
+ * }
+ *
+ * // generates:
+ *
+ * public CarDto toCar(Car car, VehicleRegistration context, Locale localeToUse) {
+ *     registerVehicle( car, context );
+ *     logMappedVehicle( car );
+ *
+ *     if ( car == null ) {
+ *         return null;
+ *     }
+ *
+ *     CarDto carDto = new CarDto();
+ *
+ *     carDto.setOwnerManual( translateOwnerManual( car.getOwnerManual(), localeToUse );
+ *     // more generated mapping code
+ *
+ *     return carDto;
+ * }
+ * 
+ * 
+ * + * @author Andreas Gudian + * @since 1.2 + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.CLASS) +public @interface Context { + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 8c63c727e8..40c57d2db0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -23,7 +23,9 @@ import java.util.Collections; import java.util.List; import java.util.Set; + import javax.lang.model.element.ExecutableElement; + import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; @@ -44,8 +46,6 @@ * @author Sjaak Derksen */ public abstract class HelperMethod implements Method { - - /** * {@inheritDoc } * @@ -84,6 +84,11 @@ public List getSourceParameters() { return getParameters(); } + @Override + public List getContextParameters() { + return Collections.emptyList(); + } + /** * {@inheritDoc} *

diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 2dd04235d6..f59a577ecd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -189,6 +189,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe targetType, method.getMapperConfiguration(), method.getExecutable(), + method.getContextParameters(), forgedMethodHistory ); @@ -238,7 +239,7 @@ private IterableMappingMethod(Method method, Assignment parameterAssignment, Met public Parameter getSourceParameter() { for ( Parameter parameter : getParameters() ) { - if ( !parameter.isMappingTarget() ) { + if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { return parameter; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 35c8f81d22..4efece5ff3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -199,6 +199,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe targetType, method.getMapperConfiguration(), method.getExecutable(), + method.getContextParameters(), history ); @@ -247,7 +248,7 @@ private MapMappingMethod(Method method, Assignment keyAssignment, Assignment val public Parameter getSourceParameter() { for ( Parameter parameter : getParameters() ) { - if ( !parameter.isMappingTarget() ) { + if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { return parameter; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 26024250fa..4c50ab3209 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -43,7 +43,8 @@ public abstract class MappingMethod extends ModelElement { private final String name; - private List parameters; + private final List parameters; + private final List sourceParameters; private final Type returnType; private final Parameter targetParameter; private final Accessibility accessibility; @@ -77,6 +78,7 @@ protected MappingMethod(Method method, List parameters, Collection forgedMethods) { this.name = method.getName(); this.parameters = parameters; + this.sourceParameters = Parameter.getSourceParameters( parameters ); this.returnType = method.getReturnType(); this.targetParameter = method.getMappingTargetParameter(); this.accessibility = method.getAccessibility(); @@ -144,14 +146,6 @@ public List getParameters() { } public List getSourceParameters() { - List sourceParameters = new ArrayList(); - - for ( Parameter parameter : parameters ) { - if ( !parameter.isMappingTarget() ) { - sourceParameters.add( parameter ); - } - } - return sourceParameters; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 1a20414d6c..007cda462c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -79,7 +79,7 @@ private NestedPropertyMappingMethod( Method method, List sour public Parameter getSourceParameter() { for ( Parameter parameter : getParameters() ) { - if ( !parameter.isMappingTarget() ) { + if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { return parameter; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 4192c58540..832693cf87 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -479,12 +479,14 @@ else if ( propertyEntries.size() == 1 ) { // forge a method from the parameter type to the last entry type. String forgedName = Strings.joinAndCamelize( sourceReference.getElementNames() ); forgedName = Strings.getSaveVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() ); - ForgedMethod methodRef = new ForgedMethod( forgedName, - sourceReference.getParameter().getType(), - sourceType, - config, - method.getExecutable() - ); + ForgedMethod methodRef = new ForgedMethod( + forgedName, + sourceReference.getParameter().getType(), + sourceType, + config, + method.getExecutable(), + method.getContextParameters() ); + NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder(); NestedPropertyMappingMethod nestedPropertyMapping = builder .method( methodRef ) @@ -540,7 +542,13 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); - ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element, + ForgedMethod methodRef = new ForgedMethod( + name, + sourceType, + targetType, + config, + element, + method.getContextParameters(), new ForgedMethodHistory( getForgedMethodHistory( source ), source.getSourceErrorMessagePart(), targetPropertyName, @@ -588,7 +596,14 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); - ForgedMethod methodRef = new ForgedMethod( name, sourceType, targetType, config, element, + ForgedMethod methodRef = + new ForgedMethod( + name, + sourceType, + targetType, + config, + element, + method.getContextParameters(), new ForgedMethodHistory( getForgedMethodHistory( source ), source.getSourceErrorMessagePart(), targetPropertyName, @@ -638,6 +653,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { targetType, method.getMapperConfiguration(), method.getExecutable(), + method.getContextParameters(), getForgedMethodHistory( sourceRHS ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 76cffe2218..2248fe34f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -18,8 +18,15 @@ */ package org.mapstruct.ap.internal.model.common; +import java.util.ArrayList; +import java.util.List; import java.util.Set; +import javax.lang.model.element.VariableElement; + +import org.mapstruct.ap.internal.prism.ContextPrism; +import org.mapstruct.ap.internal.prism.MappingTargetPrism; +import org.mapstruct.ap.internal.prism.TargetTypePrism; import org.mapstruct.ap.internal.util.Collections; /** @@ -34,18 +41,20 @@ public class Parameter extends ModelElement { private final Type type; private final boolean mappingTarget; private final boolean targetType; + private final boolean mappingContext; - public Parameter(String name, Type type, boolean mappingTarget, boolean targetType) { + private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext) { // issue #909: FreeMarker doesn't like "values" as a parameter name this.name = "values".equals( name ) ? "values_" : name; this.originalName = name; this.type = type; this.mappingTarget = mappingTarget; this.targetType = targetType; + this.mappingContext = mappingContext; } public Parameter(String name, Type type) { - this( name, type, false, false ); + this( name, type, false, false, false ); } public String getName() { @@ -66,7 +75,9 @@ public boolean isMappingTarget() { @Override public String toString() { - return ( mappingTarget ? "@MappingTarget " : "" ) + ( targetType ? "@TargetType " : "" ) + return ( mappingTarget ? "@MappingTarget " : "" ) + + ( targetType ? "@TargetType " : "" ) + + ( mappingContext ? "@Context " : "" ) + type.toString() + " " + name; } @@ -79,6 +90,10 @@ public boolean isTargetType() { return targetType; } + public boolean isMappingContext() { + return mappingContext; + } + @Override public int hashCode() { int hash = 5; @@ -100,4 +115,45 @@ public boolean equals(Object obj) { } return true; } + + public static Parameter forElementAndType(VariableElement element, Type parameterType) { + return new Parameter( + element.getSimpleName().toString(), + parameterType, + MappingTargetPrism.getInstanceOn( element ) != null, + TargetTypePrism.getInstanceOn( element ) != null, + ContextPrism.getInstanceOn( element ) != null ); + } + + /** + * @param parameters the parameters to filter + * @return the parameters from the given list that are considered 'source parameters' + */ + public static List getSourceParameters(List parameters) { + List sourceParameters = new ArrayList( parameters.size() ); + + for ( Parameter parameter : parameters ) { + if ( !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext() ) { + sourceParameters.add( parameter ); + } + } + + return sourceParameters; + } + + /** + * @param parameters the parameters to filter + * @return the parameters from the given list that are marked as 'mapping context parameters' + */ + public static List getContextParameters(List parameters) { + List contextParameters = new ArrayList( parameters.size() ); + + for ( Parameter parameter : parameters ) { + if ( parameter.isMappingContext() ) { + contextParameters.add( parameter ); + } + } + + return contextParameters; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 0b3382a9d0..a435fbcf48 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -34,12 +34,15 @@ public class ParameterBinding { private final String variableName; private final boolean targetType; private final boolean mappingTarget; + private final boolean mappingContext; - private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType) { + private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType, + boolean mappingContext) { this.type = parameterType; this.variableName = variableName; this.targetType = targetType; this.mappingTarget = mappingTarget; + this.mappingContext = mappingContext; } /** @@ -63,6 +66,13 @@ public boolean isMappingTarget() { return mappingTarget; } + /** + * @return {@code true}, if the parameter being bound is a {@code @MappingContext} parameter. + */ + public boolean isMappingContext() { + return mappingContext; + } + /** * @return the type of the parameter that is bound */ @@ -87,7 +97,8 @@ public static ParameterBinding fromParameter(Parameter parameter) { parameter.getType(), parameter.getName(), parameter.isMappingTarget(), - parameter.isTargetType() ); + parameter.isTargetType(), + parameter.isMappingContext() ); } public static List fromParameters(List parameters) { @@ -103,7 +114,7 @@ public static List fromParameters(List parameters) * @return a parameter binding representing a target type parameter */ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, true ); + return new ParameterBinding( classTypeOf, null, false, true, false ); } /** @@ -111,7 +122,7 @@ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { * @return a parameter binding representing a mapping target parameter */ public static ParameterBinding forMappingTargetBinding(Type resultType) { - return new ParameterBinding( resultType, null, true, false ); + return new ParameterBinding( resultType, null, true, false, false ); } /** @@ -119,6 +130,6 @@ public static ParameterBinding forMappingTargetBinding(Type resultType) { * @return a parameter binding representing a mapping source type */ public static ParameterBinding forSourceTypeBinding(Type sourceType) { - return new ParameterBinding( sourceType, null, false, false ); + return new ParameterBinding( sourceType, null, false, false, false ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index db5674b217..34fc1cbac8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; + import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -52,8 +53,6 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.prism.MappingTargetPrism; -import org.mapstruct.ap.internal.prism.TargetTypePrism; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -321,11 +320,7 @@ public List getParameters(ExecutableType methodType, ExecutableElemen VariableElement parameter = varIt.next(); TypeMirror parameterType = typesIt.next(); - result.add( new Parameter( - parameter.getSimpleName().toString(), - getType( parameterType ), - MappingTargetPrism.getInstanceOn( parameter ) != null, - TargetTypePrism.getInstanceOn( parameter ) != null ) ); + result.add( Parameter.forElementAndType( parameter, getType( parameterType ) ) ); } return result; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 2202f96715..1a6a7e6298 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -18,10 +18,8 @@ */ package org.mapstruct.ap.internal.model.source; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; -import java.util.Arrays; +import java.util.Iterator; import java.util.List; import javax.lang.model.element.ExecutableElement; @@ -45,7 +43,10 @@ public class ForgedMethod implements Method { private final ExecutableElement positionHintElement; private final List thrownTypes; private final MapperConfiguration mapperConfiguration; - private ForgedMethodHistory history; + private final ForgedMethodHistory history; + + private final List sourceParameters; + private final List contextParameters; /** * Creates a new forged method with the given name. @@ -55,17 +56,11 @@ public class ForgedMethod implements Method { * @param targetType the target type. * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. + * @param additionalParameters additional parameters to add to the forged method */ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement) { - String sourceParamName = Strings.decapitalize( sourceType.getName() ); - String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); - this.parameters = Arrays.asList( new Parameter( sourceParamSafeName, sourceType ) ); - this.returnType = targetType; - this.thrownTypes = new ArrayList(); - this.name = Strings.sanitizeIdentifierName( name ); - this.mapperConfiguration = mapperConfiguration; - this.positionHintElement = positionHintElement; + ExecutableElement positionHintElement, List additionalParameters) { + this( name, sourceType, targetType, mapperConfiguration, positionHintElement, additionalParameters, null ); } /** @@ -76,13 +71,21 @@ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfigu * @param targetType the target type. * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. + * @param additionalParameters additional parameters to add to the forged method * @param history a parent forged method if this is a forged method within a forged method */ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, ForgedMethodHistory history) { + ExecutableElement positionHintElement, List additionalParameters, + ForgedMethodHistory history) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); - this.parameters = Arrays.asList( new Parameter( sourceParamSafeName, sourceType ) ); + + this.parameters = new ArrayList( 1 + additionalParameters.size() ); + this.parameters.add( new Parameter( sourceParamSafeName, sourceType ) ); + this.parameters.addAll( additionalParameters ); + this.sourceParameters = Parameter.getSourceParameters( parameters ); + this.contextParameters = Parameter.getContextParameters( parameters ); + this.returnType = targetType; this.thrownTypes = new ArrayList(); this.name = Strings.sanitizeIdentifierName( name ); @@ -102,6 +105,11 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.thrownTypes = new ArrayList(); this.mapperConfiguration = forgedMethod.mapperConfiguration; this.positionHintElement = forgedMethod.positionHintElement; + this.history = forgedMethod.history; + + this.sourceParameters = Parameter.getSourceParameters( parameters ); + this.contextParameters = Parameter.getContextParameters( parameters ); + this.name = name; } @@ -112,12 +120,19 @@ public boolean matches(List sourceTypes, Type targetType) { return false; } - if ( parameters.size() != 1 || sourceTypes.size() != 1 ) { + if ( parameters.size() != sourceTypes.size() ) { return false; } - if ( !first( sourceTypes ).equals( first( parameters ).getType() ) ) { - return false; + Iterator srcTypeIt = sourceTypes.iterator(); + Iterator paramIt = parameters.iterator(); + + while ( srcTypeIt.hasNext() && paramIt.hasNext() ) { + Type sourceType = srcTypeIt.next(); + Parameter param = paramIt.next(); + if ( !sourceType.equals( param.getType() ) ) { + return false; + } } return true; @@ -140,7 +155,12 @@ public List getParameters() { @Override public List getSourceParameters() { - return parameters; + return sourceParameters; + } + + @Override + public List getContextParameters() { + return contextParameters; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index f292de91cc..9ecbdff5e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -70,15 +70,23 @@ public interface Method { List getParameters(); /** - * returns the list of 'true' source parameters excluding the parameter(s) that is designated as - * target by means of the target annotation {@link #getMappingTargetParameter() }. + * returns the list of 'true' source parameters excluding the parameter(s) that are designated as target, target + * type or context parameter. * * @return list of 'true' source parameters */ List getSourceParameters(); /** - * Returns the parameter designated as mapping target (if present) {@link org.mapstruct.MappingTarget } + * returns the list of mapping context parameters, i.e. those parameters that are annotated with + * {@link org.mapstruct.Context}. + * + * @return list of context parameters + */ + List getContextParameters(); + + /** + * Returns the parameter designated as mapping target (if present) {@link org.mapstruct.MappingTarget} * * @return mapping target parameter (when present) null otherwise. */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 13becab3f6..5bc711adea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -69,7 +69,8 @@ public class SourceMethod implements Method { private final List prototypeMethods; private final Type mapperToImplement; - private List sourceParameters; + private final List sourceParameters; + private final List contextParameters; private List parameterNames; @@ -100,9 +101,6 @@ public static class Builder { private List prototypeMethods = Collections.emptyList(); private List valueMappings; - public Builder() { - } - public Builder setDeclaringMapper(Type declaringMapper) { this.declaringMapper = declaringMapper; return this; @@ -226,6 +224,9 @@ private SourceMethod(Type declaringMapper, ExecutableElement executable, List parameters) { @@ -264,9 +267,6 @@ private Parameter determineTargetTypeParameter(Iterable parameters) { return null; } - /** - * {@inheritDoc} {@link Method} - */ @Override public Type getDeclaringMapper() { return declaringMapper; @@ -277,40 +277,26 @@ public ExecutableElement getExecutable() { return executable; } - /** - * {@inheritDoc} {@link Method} - */ @Override public String getName() { return executable.getSimpleName().toString(); } - /** - * {@inheritDoc} {@link Method} - */ @Override public List getParameters() { return parameters; } - /** - * {@inheritDoc} {@link Method} - */ @Override public List getSourceParameters() { - if ( sourceParameters == null ) { - sourceParameters = new ArrayList(); - - for ( Parameter parameter : parameters ) { - if ( !parameter.isMappingTarget() && !parameter.isTargetType() ) { - sourceParameters.add( parameter ); - } - } - } - return sourceParameters; } + @Override + public List getContextParameters() { + return contextParameters; + } + @Override public List getParameterNames() { if ( parameterNames == null ) { @@ -331,9 +317,6 @@ public Type getResultType() { return mappingTargetParameter != null ? mappingTargetParameter.getType() : returnType; } - /** - * {@inheritDoc} {@link Method} - */ @Override public Type getReturnType() { return returnType; @@ -544,9 +527,6 @@ public boolean overridesMethod() { return declaringMapper == null && executable.getModifiers().contains( Modifier.ABSTRACT ); } - /** - * {@inheritDoc} {@link Method} - */ @Override public boolean matches(List sourceTypes, Type targetType) { MethodMatcher matcher = new MethodMatcher( typeUtils, typeFactory, this ); @@ -614,5 +594,4 @@ public boolean isBeforeMappingMethod() { public boolean isUpdateMethod() { return getMappingTargetParameter() != null; } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index a8aaa43c5d..578a2519b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -103,6 +103,11 @@ public List getSourceParameters() { return getParameters(); } + @Override + public List getContextParameters() { + return Collections.emptyList(); + } + /** * {@inheritDoc} *

diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 5ca492e65b..99d212e0f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -62,7 +62,7 @@ public List> getMatchingMethods(Method mapp availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod ); } else { - availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType ); + availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType, mappingMethod ); } for ( SelectedMethod method : methods ) { @@ -91,7 +91,7 @@ private List getAvailableParameterBindingsFromMethod(Method me } private List getAvailableParameterBindingsFromSourceTypes(List sourceTypes, - Type targetType) { + Type targetType, Method mappingMethod) { List availableParams = new ArrayList( sourceTypes.size() + 2 ); @@ -101,6 +101,12 @@ private List getAvailableParameterBindingsFromSourceTypes(List availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); } + for ( Parameter param : mappingMethod.getParameters() ) { + if ( param.isMappingContext() ) { + availableParams.add( ParameterBinding.fromParameter( param ) ); + } + } + return availableParams; } @@ -185,7 +191,8 @@ private static List findCandidateBindingsForParameter(List prototypeMethods ) { Type returnType = typeFactory.getReturnType( methodType ); List exceptionTypes = typeFactory.getThrownTypes( methodType ); - List sourceParameters = extractSourceParameters( parameters ); + List sourceParameters = Parameter.getSourceParameters( parameters ); + List contextParameters = Parameter.getContextParameters( parameters ); Parameter targetParameter = extractTargetParameter( parameters ); Type resultType = selectResultType( returnType, targetParameter ); @@ -223,6 +226,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, method, sourceParameters, targetParameter, + contextParameters, resultType, returnType, containsTargetTypeParameter @@ -316,20 +320,17 @@ private boolean isValidReferencedOrFactoryMethod(int sourceParamCount, int targe if ( param.isMappingTarget() ) { targetParameters++; } - - if ( param.isTargetType() ) { + else if ( param.isTargetType() ) { targetTypeParameters++; } - - if ( !param.isMappingTarget() && !param.isTargetType() ) { + else if ( !param.isMappingContext() ) { validSourceParameters++; } } return validSourceParameters == sourceParamCount && targetParameters <= targetParamCount - && targetTypeParameters <= 1 - && parameters.size() == validSourceParameters + targetParameters + targetTypeParameters; + && targetTypeParameters <= 1; } private Parameter extractTargetParameter(List parameters) { @@ -342,17 +343,6 @@ private Parameter extractTargetParameter(List parameters) { return null; } - private List extractSourceParameters(List parameters) { - List sourceParameters = new ArrayList( parameters.size() ); - for ( Parameter param : parameters ) { - if ( !param.isMappingTarget() ) { - sourceParameters.add( param ); - } - } - - return sourceParameters; - } - private Type selectResultType(Type returnType, Parameter targetParameter) { if ( null != targetParameter ) { return targetParameter.getType(); @@ -363,14 +353,16 @@ private Type selectResultType(Type returnType, Parameter targetParameter) { } private boolean checkParameterAndReturnType(ExecutableElement method, List sourceParameters, - Parameter targetParameter, Type resultType, Type returnType, + Parameter targetParameter, List contextParameters, + Type resultType, Type returnType, boolean containsTargetTypeParameter) { if ( sourceParameters.isEmpty() ) { messager.printMessage( method, Message.RETRIEVAL_NO_INPUT_ARGS ); return false; } - if ( targetParameter != null && ( sourceParameters.size() + 1 != method.getParameters().size() ) ) { + if ( targetParameter != null + && ( sourceParameters.size() + contextParameters.size() + 1 != method.getParameters().size() ) ) { messager.printMessage( method, Message.RETRIEVAL_DUPLICATE_MAPPING_TARGETS ); return false; } @@ -393,6 +385,14 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List contextParameterTypes = new HashSet(); + for ( Parameter contextParameter : contextParameters ) { + if ( !contextParameterTypes.add( contextParameter.getType() ) ) { + messager.printMessage( method, Message.RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE ); + return false; + } + } + if ( returnType.isTypeVar() || resultType.isTypeVar() ) { messager.printMessage( method, Message.RETRIEVAL_TYPE_VAR_RESULT ); return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index f1fe928610..691a513cbc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -98,6 +98,7 @@ public enum Message { RETRIEVAL_TYPE_VAR_RESULT( "Can't generate mapping method for a generic type variable target." ), RETRIEVAL_WILDCARD_SUPER_BOUND_SOURCE( "Can't generate mapping method for a wildcard super bound source." ), RETRIEVAL_WILDCARD_EXTENDS_BOUND_RESULT( "Can't generate mapping method for a wildcard extends bound result." ), + RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE( "The types of @Context parameters must be unique." ), INHERITCONFIGURATION_BOTH( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index f098c93230..ea707f9380 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -37,7 +37,9 @@ <#-- a class is passed on for casting, see @TargetType --> <@includeModel object=ext.targetType raw=true/>.class<#t> <#elseif param.mappingTarget> - ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> + ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> + <#elseif param.mappingContext> + ${param.variableName}<#t> <#elseif assignment??> <@_assignment/><#t> <#else> diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDTO.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDTO.java rename to processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java index db2821ccea..ae65889902 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDTO.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java @@ -21,17 +21,17 @@ /** * @author Pascal Grün */ -public class AttributeDTO { - private NodeDTO node; +public class AttributeDto { + private NodeDto node; private String name; private String value; - public NodeDTO getNode() { + public NodeDto getNode() { return node; } - public void setNode(NodeDTO node) { + public void setNode(NodeDto node) { this.node = node; } @@ -53,6 +53,6 @@ public void setValue(String value) { @Override public String toString() { - return "AttributeDTO [name=" + name + ", value=" + value + "]"; + return "AttributeDto [name=" + name + ", value=" + value + "]"; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index f609bf31ed..f0cb5e039d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -36,7 +36,7 @@ * @author Pascal Grün */ @IssueKey( "469" ) -@WithClasses( { Attribute.class, AttributeDTO.class, Node.class, NodeDTO.class, NodeMapperDefault.class, +@WithClasses( { Attribute.class, AttributeDto.class, Node.class, NodeDto.class, NodeMapperDefault.class, NodeMapperWithContext.class, NodeMapperContext.class, Number.class, NumberMapperDefault.class, NumberMapperContext.class, NumberMapperWithContext.class } ) @RunWith( AnnotationProcessorTestRunner.class ) @@ -44,13 +44,13 @@ public class CallbacksWithReturnValuesTest { @Test( expected = StackOverflowError.class ) public void mappingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); - NodeMapperDefault.INSTANCE.nodeToNodeDTO( root ); + NodeMapperDefault.INSTANCE.nodeToNodeDto( root ); } @Test( expected = StackOverflowError.class ) public void updatingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); - NodeMapperDefault.INSTANCE.nodeToNodeDTO( root, new NodeDTO() ); + NodeMapperDefault.INSTANCE.nodeToNodeDto( root, new NodeDto() ); } @Test @@ -66,8 +66,8 @@ public void methodCalled(Integer level, String method, Object source, Object tar NodeMapperContext.addContextListener( contextListener ); try { Node root = buildNodes(); - NodeDTO rootDTO = NodeMapperWithContext.INSTANCE.nodeToNodeDTO( root ); - assertThat( rootDTO ).isNotNull(); + NodeDto rootDto = NodeMapperWithContext.INSTANCE.nodeToNodeDto( root ); + assertThat( rootDto ).isNotNull(); assertThat( contextLevel.get() ).isEqualTo( Integer.valueOf( 1 ) ); } finally { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDTO.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDTO.java rename to processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java index 97339009a3..3f74866a01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDTO.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java @@ -23,19 +23,18 @@ /** * @author Pascal Grün */ -public class NodeDTO { - private NodeDTO parent; +public class NodeDto { + private NodeDto parent; private String name; + private List children; + private List attributes; - private List children; - private List attributes; - - public NodeDTO getParent() { + public NodeDto getParent() { return parent; } - public void setParent(NodeDTO parent) { + public void setParent(NodeDto parent) { this.parent = parent; } @@ -47,24 +46,24 @@ public void setName(String name) { this.name = name; } - public List getChildren() { + public List getChildren() { return children; } - public void setChildren(List children) { + public void setChildren(List children) { this.children = children; } - public List getAttributes() { + public List getAttributes() { return attributes; } - public void setAttributes(List attributes) { + public void setAttributes(List attributes) { this.attributes = attributes; } @Override public String toString() { - return "NodeDTO [name=" + name + "]"; + return "NodeDto [name=" + name + "]"; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java index 88be582b57..7cf98d527a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java @@ -29,11 +29,11 @@ public abstract class NodeMapperDefault { public static final NodeMapperDefault INSTANCE = Mappers.getMapper( NodeMapperDefault.class ); - public abstract NodeDTO nodeToNodeDTO(Node node); + public abstract NodeDto nodeToNodeDto(Node node); - public abstract void nodeToNodeDTO(Node node, @MappingTarget NodeDTO nodeDto); + public abstract void nodeToNodeDto(Node node, @MappingTarget NodeDto nodeDto); - protected abstract AttributeDTO attributeToAttributeDTO(Attribute attribute); + protected abstract AttributeDto attributeToAttributeDto(Attribute attribute); - protected abstract void attributeToAttributeDTO(Attribute attribute, @MappingTarget AttributeDTO nodeDto); + protected abstract void attributeToAttributeDto(Attribute attribute, @MappingTarget AttributeDto nodeDto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java index 6ac7bdda04..391930fd68 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java @@ -29,11 +29,11 @@ public abstract class NodeMapperWithContext { public static final NodeMapperWithContext INSTANCE = Mappers.getMapper( NodeMapperWithContext.class ); - public abstract NodeDTO nodeToNodeDTO(Node node); + public abstract NodeDto nodeToNodeDto(Node node); - public abstract void nodeToNodeDTO(Node node, @MappingTarget NodeDTO nodeDto); + public abstract void nodeToNodeDto(Node node, @MappingTarget NodeDto nodeDto); - protected abstract AttributeDTO attributeToAttributeDTO(Attribute attribute); + protected abstract AttributeDto attributeToAttributeDto(Attribute attribute); - protected abstract void attributeToAttributeDTO(Attribute attribute, @MappingTarget AttributeDTO nodeDto); + protected abstract void attributeToAttributeDto(Attribute attribute, @MappingTarget AttributeDto nodeDto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java new file mode 100644 index 0000000000..19ef75a745 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + */ +@Mapper(uses = CycleContextLifecycleMethods.class) +public interface AutomappingNodeMapperWithContext { + + AutomappingNodeMapperWithContext INSTANCE = + Mappers.getMapper( AutomappingNodeMapperWithContext.class ); + + NodeDto nodeToNodeDto(Node node, @Context CycleContext cycleContext, @Context FactoryContext factoryContext); + + void nodeToNodeDto(Node node, @MappingTarget NodeDto nodeDto, @Context CycleContext cycleContext, + @Context FactoryContext factoryContext); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java new file mode 100644 index 0000000000..654d54807a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -0,0 +1,60 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import javax.tools.Diagnostic.Kind; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.Context; +import org.mapstruct.ap.test.context.erroneous.ErroneousNodeMapperWithNonUniqueContextTypes; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Tests the erroneous usage of the {@link Context} annotation in the following situations: + *

    + *
  • using the the same context parameter type twice in the same method + *
+ * + * @author Andreas Gudian + */ +@IssueKey("975") +@WithClasses({ + Node.class, + NodeDto.class, + CycleContext.class }) +@RunWith(AnnotationProcessorTestRunner.class) +public class ContextParameterErroneousTest { + + @Test + @WithClasses(ErroneousNodeMapperWithNonUniqueContextTypes.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + kind = Kind.ERROR, + line = 33, + type = ErroneousNodeMapperWithNonUniqueContextTypes.class, + messageRegExp = "The types of @Context parameters must be unique")) + public void reportsNonUniqueContextParamType() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java new file mode 100644 index 0000000000..4e0721ca8b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java @@ -0,0 +1,117 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.ObjectFactory; +import org.mapstruct.ap.test.context.Node.Attribute; +import org.mapstruct.ap.test.context.NodeDto.AttributeDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Tests the usage of the {@link Context} annotation in the following situations: + *
    + *
  • passing the parameter to property mapping methods (create and update) + *
  • passing the parameter to forged iterable methods + *
  • passing the parameter to forged bean mapping methods + *
  • passing the parameter to factory methods (with and without {@link ObjectFactory}) + *
  • passing the parameter to lifecycle methods (in this case, {@link BeforeMapping} + *
  • passing multiple parameters, with varied order of context params and mapping source params + *
+ * + * @author Andreas Gudian + */ +@IssueKey("975") +@WithClasses({ + Node.class, + NodeDto.class, + NodeMapperWithContext.class, + AutomappingNodeMapperWithContext.class, + CycleContext.class, + FactoryContext.class, + CycleContextLifecycleMethods.class }) +@RunWith(AnnotationProcessorTestRunner.class) +public class ContextParameterTest { + + private static final int MAGIC_NUMBER_OFFSET = 10; + + @Test + public void mappingWithContextCorrectlyResolvesCycles() { + Node root = buildNodes(); + NodeDto rootDto = + NodeMapperWithContext.INSTANCE.nodeToNodeDto( new FactoryContext( 0, 10 ), root, new CycleContext() ); + assertResult( rootDto ); + + NodeDto updated = new NodeDto( 0 ); + NodeMapperWithContext.INSTANCE.nodeToNodeDto( new FactoryContext( 1, 10 ), root, updated, new CycleContext() ); + assertResult( updated ); + } + + @Test + public void automappingWithContextCorrectlyResolvesCycles() { + Node root = buildNodes(); + NodeDto rootDto = AutomappingNodeMapperWithContext.INSTANCE + .nodeToNodeDto( root, new CycleContext(), new FactoryContext( 0, MAGIC_NUMBER_OFFSET ) ); + assertResult( rootDto ); + + NodeDto updated = new NodeDto( 0 ); + AutomappingNodeMapperWithContext.INSTANCE + .nodeToNodeDto( root, updated, new CycleContext(), new FactoryContext( 1, 10 ) ); + assertResult( updated ); + } + + private void assertResult(NodeDto rootDto) { + assertThat( rootDto ).isNotNull(); + assertThat( rootDto.getId() ).isEqualTo( 0 ); + + AttributeDto rootAttribute = rootDto.getAttributes().get( 0 ); + assertThat( rootAttribute.getNode() ).isSameAs( rootDto ); + assertThat( rootAttribute.getMagicNumber() ).isEqualTo( 1 + MAGIC_NUMBER_OFFSET ); + + assertThat( rootDto.getChildren() ).hasSize( 1 ); + + NodeDto node1 = rootDto.getChildren().get( 0 ); + assertThat( node1.getParent() ).isSameAs( rootDto ); + assertThat( node1.getId() ).isEqualTo( 1 ); + + AttributeDto node1Attribute = node1.getAttributes().get( 0 ); + assertThat( node1Attribute.getNode() ).isSameAs( node1 ); + assertThat( node1Attribute.getMagicNumber() ).isEqualTo( 2 + MAGIC_NUMBER_OFFSET ); + + } + + private static Node buildNodes() { + Node root = new Node( "root" ); + root.addAttribute( new Attribute( "name", "root", 1 ) ); + + Node node1 = new Node( "node1" ); + node1.addAttribute( new Attribute( "name", "node1", 2 ) ); + + root.addChild( node1 ); + + return root; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java new file mode 100644 index 0000000000..842f42a4f2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import java.util.IdentityHashMap; +import java.util.Map; + +import org.mapstruct.Context; + +/** + * A type to be used as {@link Context} parameter to track cycles in graphs + * + * @author Andreas Gudian + */ +public class CycleContext { + private Map knownInstances = new IdentityHashMap(); + + @SuppressWarnings("unchecked") + public T getMappedInstance(Object source, Class targetType) { + return (T) knownInstances.get( source ); + } + + public void storeMappedInstance(Object source, Object target) { + knownInstances.put( source, target ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java new file mode 100644 index 0000000000..9997cf8f36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.MappingTarget; +import org.mapstruct.ObjectFactory; +import org.mapstruct.TargetType; +import org.mapstruct.ap.test.context.Node.Attribute; +import org.mapstruct.ap.test.context.NodeDto.AttributeDto; + +/** + * @author Andreas Gudian + */ +public class CycleContextLifecycleMethods { + + public NodeDto createNodeDto(@Context FactoryContext context) { + return context.createNode(); + } + + @ObjectFactory + public AttributeDto createAttributeDto(Attribute source, @Context FactoryContext context) { + return context.createAttributeDto( source ); + } + + @BeforeMapping + public T getInstance(Object source, @TargetType Class type, @Context CycleContext cycleContext) { + return cycleContext.getMappedInstance( source, type ); + } + + @BeforeMapping + public void setInstance(Object source, @MappingTarget Object target, @Context CycleContext cycleContext) { + cycleContext.storeMappedInstance( source, target ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java new file mode 100644 index 0000000000..cc612cb1dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.Context; +import org.mapstruct.ap.test.context.Node.Attribute; +import org.mapstruct.ap.test.context.NodeDto.AttributeDto; + +/** + * A type to be used as {@link Context} parameter to create NodeDto and AttributeDto instances + * + * @author Andreas Gudian + */ +public class FactoryContext { + private int nodeCounter; + private int attributeMagicNumberOffset; + + public FactoryContext(int initialCounter, int attributeMaticNumberOffset) { + this.nodeCounter = initialCounter; + this.attributeMagicNumberOffset = attributeMaticNumberOffset; + } + + public NodeDto createNode() { + return new NodeDto( nodeCounter++ ); + } + + public AttributeDto createAttributeDto(Attribute source) { + return new AttributeDto( source.getMagicNumber() + attributeMagicNumberOffset ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/Node.java b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java new file mode 100644 index 0000000000..f024cdd169 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java @@ -0,0 +1,100 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Andreas Gudian + */ +public class Node { + private Node parent; + + private String name; + + private List children; + private List attributes; + + public Node(String name) { + this.name = name; + this.children = new ArrayList(); + this.attributes = new ArrayList(); + } + + public Node getParent() { + return parent; + } + + public String getName() { + return name; + } + + public List getChildren() { + return children; + } + + public void addChild(Node node) { + children.add( node ); + node.parent = this; + } + + public List getAttributes() { + return attributes; + } + + public void addAttribute(Attribute attribute) { + attributes.add( attribute ); + attribute.setNode( this ); + } + + public static class Attribute { + private Node node; + + private String name; + private String value; + private int magicNumber; + + public Attribute(String name, String value, int magicNumber) { + this.name = name; + this.value = value; + this.magicNumber = magicNumber; + } + + public Node getNode() { + return node; + } + + public void setNode(Node node) { + this.node = node; + } + + public String getName() { + return name; + } + + public String getValue() { + return value; + } + + public int getMagicNumber() { + return magicNumber; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java b/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java new file mode 100644 index 0000000000..e5f6ab1a7b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java @@ -0,0 +1,114 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import java.util.List; + +/** + * @author Andreas Gudian + */ +public class NodeDto { + private NodeDto parent; + + private int id; + private String name; + + private List children; + private List attributes; + + public NodeDto(int id) { + this.id = id; + } + + public NodeDto getParent() { + return parent; + } + + public void setParent(NodeDto parent) { + this.parent = parent; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + + public static class AttributeDto { + private NodeDto node; + + private String name; + private String value; + private int magicNumber; + + public AttributeDto(int magicNumber) { + this.magicNumber = magicNumber; + } + + public NodeDto getNode() { + return node; + } + + public void setNode(NodeDto node) { + this.node = node; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getMagicNumber() { + return magicNumber; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java new file mode 100644 index 0000000000..bb44f1d1dd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ap.test.context.Node.Attribute; +import org.mapstruct.ap.test.context.NodeDto.AttributeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + */ +@Mapper(uses = CycleContextLifecycleMethods.class) +public interface NodeMapperWithContext { + NodeMapperWithContext INSTANCE = Mappers.getMapper( NodeMapperWithContext.class ); + + NodeDto nodeToNodeDto(@Context FactoryContext factoryContext, Node node, @Context CycleContext cycleContext); + + void nodeToNodeDto(@Context FactoryContext factoryContext, Node node, @MappingTarget NodeDto nodeDto, + @Context CycleContext cycleContext); + + AttributeDto attributeToAttributeDto(Attribute attribute, @Context CycleContext cycleContext, + @Context FactoryContext factoryContext); + + void attributeToAttributeDto(Attribute attribute, @MappingTarget AttributeDto nodeDto, + @Context CycleContext cycleContext, @Context FactoryContext factoryContext); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java b/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java new file mode 100644 index 0000000000..2bda0290a0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.erroneous; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.context.CycleContext; +import org.mapstruct.ap.test.context.Node; +import org.mapstruct.ap.test.context.NodeDto; + +/** + * @author Andreas Gudian + */ +@Mapper +public interface ErroneousNodeMapperWithNonUniqueContextTypes { + + NodeDto nodeToNodeDto(Node node, @Context CycleContext cycleContext, @Context CycleContext otherCycleContext); +} From 3b84ff797c8d3565d9199d2f53d522b28e1de5df Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 25 Dec 2016 15:36:56 +0100 Subject: [PATCH 0015/1006] #1009 avoid including non used createDecimalFormat helper method --- .../conversion/BigDecimalToStringConversion.java | 9 ++++++--- .../conversion/BigIntegerToStringConversion.java | 9 ++++++--- .../bignumbers/BigNumbersConversionTest.java | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index e03e215d0d..09663855a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -21,7 +21,7 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; import java.math.BigDecimal; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -74,8 +74,11 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - HelperMethod helperMethod = new CreateDecimalFormat( conversionContext.getTypeFactory() ); - return Arrays.asList( helperMethod ); + List helpers = new ArrayList(); + if ( conversionContext.getNumberFormat() != null ) { + helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); + } + return helpers; } private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index b5f5a34219..51693cd9c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -21,7 +21,7 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; import java.math.BigInteger; -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -81,8 +81,11 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - HelperMethod helperMethod = new CreateDecimalFormat( conversionContext.getTypeFactory() ); - return Arrays.asList( helperMethod ); + List helpers = new ArrayList(); + if ( conversionContext.getNumberFormat() != null ) { + helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); + } + return helpers; } private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java index 9f18468a0a..9e91f0f1e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java @@ -22,12 +22,14 @@ import java.math.BigDecimal; import java.math.BigInteger; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * Tests conversions between {@link BigInteger} and numbers as well as String. @@ -37,6 +39,13 @@ @RunWith(AnnotationProcessorTestRunner.class) public class BigNumbersConversionTest { + private final GeneratedSource generatedSource = new GeneratedSource(); + + @Rule + public GeneratedSource getGeneratedSource() { + return generatedSource; + } + @Test @IssueKey("21") @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) @@ -188,4 +197,11 @@ public void shouldApplyReverseBigDecimalConversions() { assertThat( source.getString() ).isEqualTo( new BigDecimal( "13.45" ) ); assertThat( source.getBigInteger() ).isEqualTo( new BigDecimal( "14" ) ); } + + @Test + @IssueKey("1009") + @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) + public void shouldNotGenerateCreateDecimalFormatMethod() { + getGeneratedSource().forMapper( BigIntegerMapper.class ).content().doesNotContain( "createDecimalFormat" ); + } } From 4d3aaf15ff1e75b460b44b88750b03058479fd97 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sat, 24 Dec 2016 14:35:30 +0100 Subject: [PATCH 0016/1006] #285 JAXB object factory method selection for forged lists --- .../mapstruct/ap/internal/model/Field.java | 23 ++++++++++++ .../internal/model/IterableMappingMethod.java | 17 ++++++++- .../ap/internal/model/MapMappingMethod.java | 9 +++++ .../ap/internal/model/MappingMethod.java | 36 +++++++++++++++++++ .../ap/internal/model/MethodReference.java | 26 ++++++++++++++ .../ap/internal/model/PropertyMapping.java | 1 + .../selector/XmlElementDeclSelector.java | 9 +---- .../ap/test/selection/jaxb/OrderDto.java | 12 +++++++ .../ap/test/selection/jaxb/OrderMapper.java | 7 ---- .../selection/jaxb/test1/ObjectFactory.java | 8 +++++ .../test/selection/jaxb/test1/OrderType.java | 12 +++++++ 11 files changed, 144 insertions(+), 16 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index 0021e88fba..0adc43c1d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -105,4 +105,27 @@ public void setTypeRequiresImport(boolean typeRequiresImport) { this.typeRequiresImport = typeRequiresImport; } + @Override + public int hashCode() { + int hash = 5; + hash = 43 * hash + (this.variableName != null ? this.variableName.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final Field other = (Field) obj; + return !( (this.variableName == null) ? + (other.variableName != null) : !this.variableName.equals( other.variableName ) ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index f59a577ecd..05abb2a5df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -64,6 +64,7 @@ public static class Builder { private FormattingParameters formattingParameters; private NullValueMappingStrategyPrism nullValueMappingStrategy; private ForgedMethod forgedMethod; + private String callingContextTargetPropertyName; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -90,6 +91,11 @@ public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueM return this; } + public Builder callingContextTargetPropertyName(String callingContextTargetPropertyName) { + this.callingContextTargetPropertyName = callingContextTargetPropertyName; + return this; + } + public IterableMappingMethod build() { @@ -111,7 +117,7 @@ public IterableMappingMethod build() { Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, targetElementType, - null, // there is no targetPropertyName + callingContextTargetPropertyName, formattingParameters, selectionParameters, sourceRHS, @@ -380,6 +386,15 @@ else if ( other.selectionParameters != null ) { return false; } + if ( this.factoryMethod != null ) { + if ( !this.factoryMethod.equals( other.factoryMethod ) ) { + return false; + } + } + else if ( other.factoryMethod != null ) { + return false; + } + return isMapNullToDefault() == other.isMapNullToDefault(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 4efece5ff3..283c60c422 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -368,6 +368,15 @@ public boolean equals(Object obj) { } } + if ( this.factoryMethod != null ) { + if ( !this.factoryMethod.equals( other.factoryMethod ) ) { + return false; + } + } + else if ( other.factoryMethod != null ) { + return false; + } + return isMapNullToDefault() == other.isMapNullToDefault(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 4c50ab3209..b6848d3610 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -242,4 +242,40 @@ public List getBeforeMappingReferencesWithoutM public List getForgedMethods() { return forgedMethods; } + + @Override + public int hashCode() { + int hash = 7; + hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 83 * hash + (this.parameters != null ? this.parameters.hashCode() : 0); + hash = 83 * hash + (this.returnType != null ? this.returnType.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final MappingMethod other = (MappingMethod) obj; + if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { + return false; + } + if ( this.parameters != other.parameters && + (this.parameters == null || !this.parameters.equals( other.parameters )) ) { + return false; + } + if ( this.returnType != other.returnType && + (this.returnType == null || !this.returnType.equals( other.returnType )) ) { + return false; + } + return true; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index e6a43955a0..db86c017c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -221,4 +221,30 @@ public boolean isCallingUpdateMethod() { public List getParameterBindings() { return parameterBindings; } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + (this.declaringMapper != null ? this.declaringMapper.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final MethodReference other = (MethodReference) obj; + if ( this.declaringMapper != other.declaringMapper && (this.declaringMapper == null + || !this.declaringMapper.equals( other.declaringMapper )) ) { + return false; + } + return super.equals( obj ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 832693cf87..6d93af4cff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -562,6 +562,7 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source .mappingContext( ctx ) .method( methodRef ) .selectionParameters( selectionParameters ) + .callingContextTargetPropertyName( targetPropertyName ) .build(); if ( iterableMappingMethod != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 254d5e6661..81fbfd2e81 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -66,18 +66,11 @@ public List> getMatchingMethods(Method mapp List sourceTypes, Type targetType, SelectionCriteria criteria) { - // only true source methods are qualifying - if ( !(mappingMethod instanceof SourceMethod) ) { - return methods; - } - - SourceMethod sourceMappingMethod = (SourceMethod) mappingMethod; - List> nameMatches = new ArrayList>(); List> scopeMatches = new ArrayList>(); List> nameAndScopeMatches = new ArrayList>(); XmlElementRefInfo xmlElementRefInfo = - findXmlElementRef( sourceMappingMethod.getResultType(), criteria.getTargetPropertyName() ); + findXmlElementRef( mappingMethod.getResultType(), criteria.getTargetPropertyName() ); for ( SelectedMethod candidate : methods ) { if ( !( candidate.getMethod() instanceof SourceMethod ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java index 83aee66a4f..76fe25526e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.test.selection.jaxb; +import java.util.List; + /** * @author Sjaak Derksen */ @@ -26,6 +28,7 @@ public class OrderDto { private Long orderNumber1; private Long orderNumber2; private OrderShippingDetailsDto shippingDetails; + private List description; public Long getOrderNumber1() { return orderNumber1; @@ -50,4 +53,13 @@ public OrderShippingDetailsDto getShippingDetails() { public void setShippingDetails(OrderShippingDetailsDto shippingDetails) { this.shippingDetails = shippingDetails; } + + public List getDescription() { + return description; + } + + public void setDescription(List description) { + this.description = description; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java index 93a4b2dd9e..0ff04153e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.selection.jaxb; -import javax.xml.bind.JAXBElement; - import org.mapstruct.Mapper; import org.mapstruct.ap.test.selection.jaxb.test1.ObjectFactory; import org.mapstruct.ap.test.selection.jaxb.test1.OrderType; @@ -42,9 +40,4 @@ public abstract class OrderMapper { public abstract OrderShippingDetailsType dtoToOrderShippingDetailsType(OrderShippingDetailsDto target); - // TODO, remove this method when #134 is fixed - public JAXBElement dtoToOrderShippingDetailsTypeJB(OrderShippingDetailsDto target) { - ObjectFactory of1 = new ObjectFactory(); - return of1.createOrderTypeShippingDetails( INSTANCE.dtoToOrderShippingDetailsType( target ) ); - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java index 594ad48773..812ff5a78e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java @@ -36,6 +36,8 @@ public class ObjectFactory { new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber2" ); public static final QName ORDER_TYPE_SHIPPING_DETAILS_QNAME = new QName( "http://www.mapstruct.org/ap/test/jaxb/selection/test1", "shippingDetails" ); + public static final QName ORDER_TYPE_DESCRIPTION_QNAME = + new QName("http://www.mapstruct.org/itest/jaxb/xsd/test1", "description"); public ObjectFactory() { } @@ -70,4 +72,10 @@ public JAXBElement createOrderTypeShippingDetails(Orde ); } + @XmlElementDecl(namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1", + name = "description", scope = OrderType.class) + public JAXBElement createOrderTypeDescription(String value) { + return new JAXBElement(ORDER_TYPE_DESCRIPTION_QNAME, String.class, OrderType.class, value); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java index ea8c3f22aa..1c19377baf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.selection.jaxb.test1; +import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; @@ -43,6 +44,9 @@ public class OrderType { @XmlElementRef(name = "shippingDetails", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", type = JAXBElement.class) private JAXBElement shippingDetails; + @XmlElementRef(name = "description", namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1", + type = JAXBElement.class) + protected List> description; public JAXBElement getOrderNumber1() { return orderNumber1; @@ -68,4 +72,12 @@ public void setShippingDetails(JAXBElement value) { this.shippingDetails = value; } + public List> getDescription() { + return description; + } + + public void setDescription(List> description) { + this.description = description; + } + } From a2bd4a021f7b9de972433c2efee6949197014327 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 28 Dec 2016 09:43:39 +0100 Subject: [PATCH 0017/1006] #965 fix wrong reference to NullValueMappingStrategy --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 81e01bb1f8..3bcfb6d292 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1736,7 +1736,7 @@ The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` [[checking-source-property-for-null-arguments]] === Controlling checking result for 'null' properties in bean mapping -MapStruct offers control over when to generate a `null` check. By default (`nullValueCheckStrategy = NullValueMappingStrategy.ON_IMPLICIT_CONVERSION`) a `null` check will be generated for: +MapStruct offers control over when to generate a `null` check. By default (`nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION`) a `null` check will be generated for: * direct setting of source value to target value when target is primitive and is source not. * applying type conversion and then: @@ -1746,9 +1746,9 @@ MapStruct offers control over when to generate a `null` check. By default (`null First calling a mapping method on the source property is not protected by a null check. Therefor generated mapping methods will do a null check prior to carrying out mapping on a source property. Handwritten mapping methods must take care of null value checking. They have the possibility to add 'meaning' to `null`. For instance: mapping `null` to a default value. -The option `nullValueCheckStrategy = NullValueMappingStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. +The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. -The strategy works in a hierarchical fashion. `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`. +The strategy works in a hierarchical fashion. `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. [[source-presence-check]] === Source presence checking From 8654d8f45a4623464082343e88ef6b7c15e0fd35 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 30 Dec 2016 19:03:45 +0100 Subject: [PATCH 0018/1006] #1007 add base for comparing generated code to a fixed baseline --- .../ap/test/array/ArrayMappingTest.java | 6 + .../testutil/assertions/JavaFileAssert.java | 85 ++++- .../ap/testutil/runner/GeneratedSource.java | 70 +++- .../ap/test/array/ScienceMapperImpl.java | 351 ++++++++++++++++++ 4 files changed, 508 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index ea3d7e3f5d..47db02d594 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.List; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.array._target.ScientistDto; @@ -30,12 +31,17 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; @WithClasses( { Scientist.class, ScientistDto.class, ScienceMapper.class } ) @RunWith(AnnotationProcessorTestRunner.class) @IssueKey("108") public class ArrayMappingTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( ScienceMapper.class ); + @Test public void shouldCopyArraysInBean() { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 39a5d9d987..334bd6b06d 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -20,13 +20,23 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import com.google.common.base.Charsets; +import com.google.common.io.Files; import org.assertj.core.api.AbstractCharSequenceAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.FileAssert; +import org.assertj.core.api.exception.RuntimeIOException; +import org.assertj.core.error.ShouldHaveSameContent; +import org.assertj.core.internal.Diff; +import org.assertj.core.internal.Failures; +import org.assertj.core.util.diff.Delta; -import com.google.common.base.Charsets; -import com.google.common.io.Files; +import static java.lang.String.format; /** * Allows to perform assertions on .java source files. @@ -34,6 +44,14 @@ * @author Andreas Gudian */ public class JavaFileAssert extends FileAssert { + + private static final String FIRST_LINE_LICENSE_REGEX = ".*Copyright 2012-\\d{4} Gunnar Morling.*"; + private static final String GENERATED_DATE_REGEX = "\\s+date = " + + "\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{4}\","; + private static final String GENERATED_COMMENTS_REGEX = "\\s+comments = \"version: , compiler: .*, environment: " + + ".*\""; + + private Diff diff = new Diff(); /** * @param actual the actual file */ @@ -76,6 +94,69 @@ public void containsNoImportFor(Class importedClass) { content().doesNotContain( getClassImportDeclaration( importedClass ) ); } + /** + * Verifies that the expected file has the same content as this Java file. The verification ignores + * the license header and the date/comments line from the {@code @Generated} annotation. + * + * @param expected the file that should be matched + */ + public void hasSameMapperContent(File expected) { + Charset charset = Charset.forName( "UTF-8" ); + try { + List> diffs = new ArrayList>( this.diff.diff( + actual, + charset, + expected, + charset + ) ); + Iterator> iterator = diffs.iterator(); + while ( iterator.hasNext() ) { + Delta delta = iterator.next(); + if ( ignoreDelta( delta ) ) { + iterator.remove(); + } + } + if ( !diffs.isEmpty() ) { + throw Failures.instance() + .failure( info, ShouldHaveSameContent.shouldHaveSameContent( actual, expected, diffs ) ); + } + } + catch ( IOException e ) { + throw new RuntimeIOException( format( + "Unable to compare contents of files:<%s> and:<%s>", + actual, + expected + ), e ); + } + } + + /** + * Checks if the delta should be ignored. The delta is ignored if it is a deletion type for the license header + * or if it is a change delta for the date/comments part of a {@code @Generated} annotation. + * + * @param delta that needs to be checked + * + * @return {@code true} if this delta should be ignored, {@code false} otherwise + */ + private boolean ignoreDelta(Delta delta) { + if ( delta.getType() == Delta.TYPE.DELETE ) { + List lines = delta.getOriginal().getLines(); + return lines.size() > 2 && lines.get( 1 ).matches( FIRST_LINE_LICENSE_REGEX ); + } + else if ( delta.getType() == Delta.TYPE.CHANGE ) { + List lines = delta.getOriginal().getLines(); + if ( lines.size() == 1 ) { + return lines.get( 0 ).matches( GENERATED_DATE_REGEX ); + } + else if ( lines.size() == 2 ) { + return lines.get( 0 ).matches( GENERATED_DATE_REGEX ) && + lines.get( 1 ).matches( GENERATED_COMMENTS_REGEX ); + } + } + + return false; + } + /** * Build a class import declaration string. * diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index 38740117ff..db86ca53b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -19,12 +19,19 @@ package org.mapstruct.ap.testutil.runner; import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.List; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.mapstruct.ap.testutil.assertions.JavaFileAssert; +import static org.assertj.core.api.Assertions.fail; + /** * A {@link TestRule} to perform assertions on generated source files. *

@@ -39,15 +46,19 @@ */ public class GeneratedSource implements TestRule { + private static final String FIXTURES_ROOT = "fixtures/"; + /** * static ThreadLocal, as the {@link CompilingStatement} must inject itself statically for this rule to gain access * to the statement's information. As test execution of different classes in parallel is supported. */ private static ThreadLocal compilingStatement = new ThreadLocal(); + private List> fixturesFor = new ArrayList>(); + @Override public Statement apply(Statement base, Description description) { - return base; + return new GeneratedSourceStatement( base ); } static void setCompilingStatement(CompilingStatement compilingStatement) { @@ -58,16 +69,37 @@ static void clearCompilingStatement() { GeneratedSource.compilingStatement.remove(); } + + /** + * Adds more mappers that need to be compared. + * + * The comparison is done for mappers and the are compared against a Java file that matches the name of the + * Mapper that would have been created for the fixture. + * + * @param fixturesFor the classes that need to be compared with + * @return the same rule for chaining + */ + public GeneratedSource addComparisonToFixtureFor(Class... fixturesFor) { + for ( Class fixture : fixturesFor ) { + this.fixturesFor.add( fixture ); + } + return this; + } + /** * @param mapperClass the class annotated with {@code @Mapper} * * @return an assert for the *Impl.java for the given mapper */ public JavaFileAssert forMapper(Class mapperClass) { - String generatedJavaFileName = mapperClass.getName().replace( '.', '/' ).concat( "Impl.java" ); + String generatedJavaFileName = getMapperName( mapperClass ); return forJavaFile( generatedJavaFileName ); } + private String getMapperName(Class mapperClass) { + return mapperClass.getName().replace( '.', '/' ).concat( "Impl.java" ); + } + /** * @param mapperClass the class annotated with {@code @Mapper} and {@code @DecoratedWith(..)} * @@ -86,4 +118,38 @@ public JavaFileAssert forDecoratedMapper(Class mapperClass) { public JavaFileAssert forJavaFile(String path) { return new JavaFileAssert( new File( compilingStatement.get().getSourceOutputDir() + "/" + path ) ); } + + private class GeneratedSourceStatement extends Statement { + private final Statement next; + + private GeneratedSourceStatement(Statement next) { + this.next = next; + } + + @Override + public void evaluate() throws Throwable { + next.evaluate(); + handleFixtureComparison(); + } + } + + private void handleFixtureComparison() throws UnsupportedEncodingException { + for ( Class fixture : fixturesFor ) { + String expectedFixture = FIXTURES_ROOT + getMapperName( fixture ); + URL expectedFile = getClass().getClassLoader().getResource( expectedFixture ); + if ( expectedFile == null ) { + fail( String.format( + "No reference file could be found for Mapper %s. You should create a file %s", + fixture.getName(), + expectedFixture + ) ); + } + else { + File expectedResource = new File( URLDecoder.decode( expectedFile.getFile(), "UTF-8" ) ); + forMapper( fixture ).hasSameMapperContent( expectedResource ); + } + fixture.getPackage().getName(); + } + + } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java new file mode 100644 index 0000000000..605a6c5480 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java @@ -0,0 +1,351 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.array; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; +import org.mapstruct.ap.test.array._target.ScientistDto; +import org.mapstruct.ap.test.array.source.Scientist; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-28T17:52:06+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class ScienceMapperImpl implements ScienceMapper { + + @Override + public ScientistDto scientistToDto(Scientist scientist) { + if ( scientist == null ) { + return null; + } + + ScientistDto scientistDto = new ScientistDto(); + + scientistDto.setName( scientist.getName() ); + if ( scientist.getPublications() != null ) { + java.lang.String[] publications = scientist.getPublications(); + scientistDto.setPublications( Arrays.copyOf( publications, publications.length ) ); + } + scientistDto.setPublicationYears( stringArrayTointArray( scientist.getPublicationYears() ) ); + + return scientistDto; + } + + @Override + public org.mapstruct.ap.test.array._target.ScientistDto[] scientistsToDtos(org.mapstruct.ap.test.array.source.Scientist[] scientists) { + if ( scientists == null ) { + return null; + } + + ScientistDto[] scientistDtoTmp = new ScientistDto[scientists.length]; + int i = 0; + for ( Scientist scientist : scientists ) { + scientistDtoTmp[i] = scientistToDto( scientist ); + i++; + } + + return scientistDtoTmp; + } + + @Override + public org.mapstruct.ap.test.array._target.ScientistDto[] scientistsToDtos(List scientists) { + if ( scientists == null ) { + return null; + } + + ScientistDto[] scientistDtoTmp = new ScientistDto[scientists.size()]; + int i = 0; + for ( Scientist scientist : scientists ) { + scientistDtoTmp[i] = scientistToDto( scientist ); + i++; + } + + return scientistDtoTmp; + } + + @Override + public List scientistsToDtosAsList(org.mapstruct.ap.test.array.source.Scientist[] scientists) { + if ( scientists == null ) { + return null; + } + + List list = new ArrayList(); + for ( Scientist scientist : scientists ) { + list.add( scientistToDto( scientist ) ); + } + + return list; + } + + @Override + public org.mapstruct.ap.test.array._target.ScientistDto[] scientistsToDtos(org.mapstruct.ap.test.array.source.Scientist[] scientists, org.mapstruct.ap.test.array._target.ScientistDto[] target) { + if ( scientists == null ) { + return null; + } + + int i = 0; + for ( Scientist scientist : scientists ) { + if ( ( i >= target.length ) || ( i >= scientists.length ) ) { + break; + } + target[i] = scientistToDto( scientist ); + i++; + } + + return target; + } + + @Override + public boolean[] nvmMapping(boolean[] source) { + if ( source == null ) { + return new boolean[0]; + } + + boolean[] booleanTmp = new boolean[source.length]; + int i = 0; + for ( boolean boolean_ : source ) { + booleanTmp[i] = boolean_; + i++; + } + + return booleanTmp; + } + + @Override + public boolean[] nvmMapping(boolean[] source, boolean[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = false; + } + return target; + } + + int i = 0; + for ( boolean boolean_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = boolean_; + i++; + } + + return target; + } + + @Override + public short[] nvmMapping(int[] source, short[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = (short) int_; + i++; + } + + return target; + } + + @Override + public char[] nvmMapping(java.lang.String[] source, char[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0; + } + return target; + } + + int i = 0; + for ( String string : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = string.charAt( 0 ); + i++; + } + + return target; + } + + @Override + public int[] nvmMapping(int[] source, int[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + + return target; + } + + @Override + public long[] nvmMapping(int[] source, long[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0L; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + + return target; + } + + @Override + public float[] nvmMapping(int[] source, float[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0.0f; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + + return target; + } + + @Override + public double[] nvmMapping(int[] source, double[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0.0d; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + + return target; + } + + @Override + public java.lang.String[] nvmMapping(int[] source, java.lang.String[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = null; + } + return target; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = new DecimalFormat( "" ).format( int_ ); + i++; + } + + return target; + } + + @Override + public void nvmMappingVoidReturnNull(int[] source, long[] target) { + if ( source == null ) { + return; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + } + + @Override + public void nvmMappingVoidReturnDefault(int[] source, long[] target) { + if ( source == null ) { + for (int j = 0; j < target.length; j++ ) { + target[j] = 0L; + } + return; + } + + int i = 0; + for ( int int_ : source ) { + if ( ( i >= target.length ) || ( i >= source.length ) ) { + break; + } + target[i] = int_; + i++; + } + } + + protected int[] stringArrayTointArray(java.lang.String[] stringArray) { + if ( stringArray == null ) { + return null; + } + + int[] intTmp = new int[stringArray.length]; + int i = 0; + for ( String string : stringArray ) { + intTmp[i] = Integer.parseInt( string ); + i++; + } + + return intTmp; + } +} From ec6913618ea1e5c92e4e092beb0f234be1fc293e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 4 Jan 2017 09:32:02 +0100 Subject: [PATCH 0019/1006] #1007 Add additional generated code tests --- ...ssue913SetterMapperForCollectionsTest.java | 14 +- .../ap/test/collection/adder/AdderTest.java | 18 +- .../string/StringConversionTest.java | 10 +- .../test/updatemethods/UpdateMethodsTest.java | 13 +- .../selection/ExternalSelectionTest.java | 16 +- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 252 ++++++++++++++++ .../DomainDtoWithNvmsDefaultMapperImpl.java | 273 +++++++++++++++++ .../_913/DomainDtoWithNvmsNullMapperImpl.java | 276 ++++++++++++++++++ .../DomainDtoWithPresenceCheckMapperImpl.java | 252 ++++++++++++++++ .../adder/Source2Target2MapperImpl.java | 49 ++++ .../adder/SourceTargetMapperImpl.java | 213 ++++++++++++++ ...SourceTargetMapperStrategyDefaultImpl.java | 55 ++++ ...rgetMapperStrategySetterPreferredImpl.java | 55 ++++ .../string/SourceTargetMapperImpl.java | 134 +++++++++ .../test/updatemethods/CompanyMapperImpl.java | 71 +++++ .../updatemethods/OrganizationMapperImpl.java | 98 +++++++ .../selection/DepartmentMapperImpl.java | 82 ++++++ .../selection/ExternalMapperImpl.java | 40 +++ .../selection/OrganizationMapper1Impl.java | 54 ++++ .../selection/OrganizationMapper2Impl.java | 53 ++++ .../selection/OrganizationMapper3Impl.java | 53 ++++ 21 files changed, 2070 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index 20b9df33b4..66c4194efe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -20,12 +20,16 @@ import java.util.HashSet; import java.util.Set; -import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; /** * All these test cases test the possible combinations in the SetterMapperForCollections. @@ -47,6 +51,14 @@ @IssueKey( "913" ) public class Issue913SetterMapperForCollectionsTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + DomainDtoWithNvmsNullMapper.class, + DomainDtoWithNvmsDefaultMapper.class, + DomainDtoWithPresenceCheckMapper.class, + DomainDtoWithNcvsAlwaysMapper.class + ); + /** * The null value mapping strategy on type level (Mapper) should generate forged methods for the * conversion from string to long that return null in the entire mapper, so also for the forged diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index 1f74d5ec01..36c06bde80 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -18,13 +18,10 @@ */ package org.mapstruct.ap.test.collection.adder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Arrays; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.collection.adder._target.AdderUsageObserver; @@ -46,6 +43,11 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; /** * @author Sjaak Derksen @@ -75,6 +77,13 @@ @RunWith(AnnotationProcessorTestRunner.class) public class AdderTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + SourceTargetMapper.class, + SourceTargetMapperStrategyDefault.class, + SourceTargetMapperStrategySetterPreferred.class + ); + @IssueKey("241") @Test public void testAdd() throws DogException { @@ -252,6 +261,7 @@ public void testSingleElementSource() throws DogException { Foo.class } ) public void testMissingImport() throws DogException { + generatedSource.addComparisonToFixtureFor( Source2Target2Mapper.class ); Source2 source = new Source2(); source.setAttributes( Arrays.asList( new Foo() ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java index 4624e8a80b..b68b313780 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java @@ -18,13 +18,15 @@ */ package org.mapstruct.ap.test.conversion.string; -import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, @@ -36,6 +38,10 @@ public class StringConversionTest { private static final String STRING_CONSTANT = "String constant"; + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + SourceTargetMapper.class ); + @Test public void shouldApplyStringConversions() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index b703723190..ca7ceaec45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -18,8 +18,7 @@ */ package org.mapstruct.ap.test.updatemethods; -import static org.assertj.core.api.Assertions.assertThat; - +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -28,6 +27,9 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -52,11 +54,15 @@ }) public class UpdateMethodsTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + @Test @WithClasses( { OrganizationMapper.class } ) public void testPreferUpdateMethod() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper.class ); OrganizationEntity organizationEntity = new OrganizationEntity(); CompanyEntity companyEntity = new CompanyEntity(); @@ -85,6 +91,7 @@ public void testPreferUpdateMethod() { OrganizationMapper.class } ) public void testUpdateMethodClearsExistingValues() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper.class ); OrganizationEntity organizationEntity = new OrganizationEntity(); CompanyEntity companyEntity = new CompanyEntity(); @@ -109,6 +116,7 @@ public void testUpdateMethodClearsExistingValues() { OrganizationMapper.class }) public void testPreferUpdateMethodSourceObjectNotDefined() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper.class ); OrganizationEntity organizationEntity = new OrganizationEntity(); @@ -134,6 +142,7 @@ public void testPreferUpdateMethodSourceObjectNotDefined() { DepartmentInBetween.class } ) public void testPreferUpdateMethodEncapsulatingCreateMethod() { + generatedSource.addComparisonToFixtureFor( CompanyMapper.class ); CompanyEntity companyEntity = new CompanyEntity(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java index ffd247ab1c..eced906a99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java @@ -18,12 +18,11 @@ */ package org.mapstruct.ap.test.updatemethods.selection; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.updatemethods.BossDto; @@ -41,6 +40,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -68,11 +70,19 @@ }) public class ExternalSelectionTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + OrganizationMapper1.class, + ExternalMapper.class, + DepartmentMapper.class + ); + @Test @WithClasses({ OrganizationMapper1.class }) public void shouldSelectGeneratedExternalMapper() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper1.class ); CompanyEntity entity = new CompanyEntity(); CompanyDto dto = new CompanyDto(); @@ -85,6 +95,7 @@ public void shouldSelectGeneratedExternalMapper() { }) @IssueKey("604") public void shouldSelectGeneratedExternalMapperWithImportForPropertyType() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper3.class ); BossEntity entity = new BossEntity(); BossDto dto = new BossDto(); @@ -96,6 +107,7 @@ public void shouldSelectGeneratedExternalMapperWithImportForPropertyType() { OrganizationMapper2.class }) public void shouldSelectGeneratedHandWrittenExternalMapper() { + generatedSource.addComparisonToFixtureFor( OrganizationMapper2.class ); CompanyEntity entity = new CompanyEntity(); CompanyDto dto = new CompanyDto(); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java new file mode 100644 index 0000000000..f144faa2d6 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -0,0 +1,252 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:07:28+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DomainDtoWithNcvsAlwaysMapperImpl implements DomainDtoWithNcvsAlwaysMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(DtoWithPresenceCheck source) { + if ( source == null ) { + return null; + } + + Domain domain = new Domain(); + + if ( source.hasStringsInitialized() ) { + Set set = stringListToLongSet( source.getStringsInitialized() ); + domain.setLongsInitialized( set ); + } + if ( source.hasStrings() ) { + Set set_ = stringListToLongSet( source.getStrings() ); + domain.setLongs( set_ ); + } + if ( source.hasStrings() ) { + List list = source.getStrings(); + domain.setStrings( new HashSet( list ) + ); + } + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + domain.setStringsInitialized( new HashSet( list__ ) + ); + } + + return domain; + } + + @Override + public void update(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + } + else { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + } + + @Override + public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return null; + } + + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + } + else { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = new HashSet(); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java new file mode 100644 index 0000000000..d6ba35d852 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -0,0 +1,273 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:07:27+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DomainDtoWithNvmsDefaultMapperImpl implements DomainDtoWithNvmsDefaultMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(Dto source) { + + Domain domain = new Domain(); + + if ( source != null ) { + Set set = stringListToLongSet( source.getStringsInitialized() ); + if ( set != null ) { + domain.setLongsInitialized( set ); + } + Set set_ = stringListToLongSet( source.getStrings() ); + if ( set_ != null ) { + domain.setLongs( set_ ); + } + List list = source.getStrings(); + if ( list != null ) { + domain.setStrings( new HashSet( list ) + ); + } + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + domain.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + domain.setStringsInitialized( new HashSet( list__ ) + ); + } + } + + return domain; + } + + @Override + public void update(Dto source, Domain target) { + + if ( source != null ) { + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + } + } + + @Override + public Domain updateWithReturn(Dto source, Domain target) { + + if ( source != null ) { + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return new HashSet(); + } + + Set set = new HashSet(); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java new file mode 100644 index 0000000000..cc67c73c3e --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -0,0 +1,276 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:07:28+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DomainDtoWithNvmsNullMapperImpl implements DomainDtoWithNvmsNullMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(Dto source) { + if ( source == null ) { + return null; + } + + Domain domain = new Domain(); + + Set set = stringListToLongSet( source.getStringsInitialized() ); + if ( set != null ) { + domain.setLongsInitialized( set ); + } + Set set_ = stringListToLongSet( source.getStrings() ); + if ( set_ != null ) { + domain.setLongs( set_ ); + } + List list = source.getStrings(); + if ( list != null ) { + domain.setStrings( new HashSet( list ) + ); + } + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + domain.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + domain.setStringsInitialized( new HashSet( list__ ) + ); + } + + return domain; + } + + @Override + public void update(Dto source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + } + + @Override + public Domain updateWithReturn(Dto source, Domain target) { + if ( source == null ) { + return null; + } + + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + if ( set_ != null ) { + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list_ = source.getStringsWithDefault(); + if ( list_ != null ) { + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list__ = source.getStringsInitialized(); + if ( list__ != null ) { + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = new HashSet(); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java new file mode 100644 index 0000000000..9f38733cde --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -0,0 +1,252 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:07:28+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DomainDtoWithPresenceCheckMapperImpl implements DomainDtoWithPresenceCheckMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(DtoWithPresenceCheck source) { + if ( source == null ) { + return null; + } + + Domain domain = new Domain(); + + if ( source.hasStringsInitialized() ) { + Set set = stringListToLongSet( source.getStringsInitialized() ); + domain.setLongsInitialized( set ); + } + if ( source.hasStrings() ) { + Set set_ = stringListToLongSet( source.getStrings() ); + domain.setLongs( set_ ); + } + if ( source.hasStrings() ) { + List list = source.getStrings(); + domain.setStrings( new HashSet( list ) + ); + } + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + domain.setStringsInitialized( new HashSet( list__ ) + ); + } + + return domain; + } + + @Override + public void update(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + } + else { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + } + + @Override + public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return null; + } + + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + } + else { + if ( source.hasStrings() ) { + Set set = stringListToLongSet( source.getStrings() ); + target.setLongs( set ); + } + } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) + ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set_ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + Set set_ = stringListToLongSet( source.getStringsInitialized() ); + target.setLongsInitialized( set_ ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list_ ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list_ = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list_ ) + ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list__ ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list__ = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list__ ) + ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = new HashSet(); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java new file mode 100644 index 0000000000..efafeedf35 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.adder; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.collection.adder._target.Target2; +import org.mapstruct.ap.test.collection.adder.source.Foo; +import org.mapstruct.ap.test.collection.adder.source.Source2; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:10:39+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class Source2Target2MapperImpl extends Source2Target2Mapper { + + @Override + public Target2 toTarget(Source2 source) { + if ( source == null ) { + return null; + } + + Target2 target2 = new Target2(); + + if ( source.getAttributes() != null ) { + for ( Foo attribute : source.getAttributes() ) { + target2.addAttribute( attribute ); + } + } + + return target2; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..c64697535b --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java @@ -0,0 +1,213 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.adder; + +import java.util.List; +import javax.annotation.Generated; +import org.mapstruct.ap.test.collection.adder._target.IndoorPet; +import org.mapstruct.ap.test.collection.adder._target.Target; +import org.mapstruct.ap.test.collection.adder._target.TargetDali; +import org.mapstruct.ap.test.collection.adder._target.TargetHuman; +import org.mapstruct.ap.test.collection.adder._target.TargetOnlyGetter; +import org.mapstruct.ap.test.collection.adder._target.TargetViaTargetType; +import org.mapstruct.ap.test.collection.adder.source.SingleElementSource; +import org.mapstruct.ap.test.collection.adder.source.Source; +import org.mapstruct.ap.test.collection.adder.source.SourceTeeth; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:10:39+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + private final PetMapper petMapper = new PetMapper(); + private final TeethMapper teethMapper = new TeethMapper(); + + @Override + public Target toTarget(Source source) throws DogException { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getPets() != null ) { + try { + for ( String pet : source.getPets() ) { + target.addPet( petMapper.toPet( pet ) ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + } + + return target; + } + + @Override + public Source toSource(Target source) { + if ( source == null ) { + return null; + } + + Source source_ = new Source(); + + try { + List list = petMapper.toSourcePets( source.getPets() ); + if ( list != null ) { + source_.setPets( list ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + catch ( DogException e ) { + throw new RuntimeException( e ); + } + + return source_; + } + + @Override + public void toExistingTarget(Source source, Target target) { + if ( source == null ) { + return; + } + + if ( source.getPets() != null ) { + try { + for ( String pet : source.getPets() ) { + target.addPet( petMapper.toPet( pet ) ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + catch ( DogException e ) { + throw new RuntimeException( e ); + } + } + } + + @Override + public TargetDali toTargetDali(SourceTeeth source) { + if ( source == null ) { + return null; + } + + TargetDali targetDali = new TargetDali(); + + if ( source.getTeeth() != null ) { + for ( String teeth : source.getTeeth() ) { + targetDali.addTeeth( teethMapper.toTooth( teeth ) ); + } + } + + return targetDali; + } + + @Override + public TargetHuman toTargetHuman(SourceTeeth source) { + if ( source == null ) { + return null; + } + + TargetHuman targetHuman = new TargetHuman(); + + if ( source.getTeeth() != null ) { + for ( String tooth : source.getTeeth() ) { + targetHuman.addTooth( teethMapper.toTooth( tooth ) ); + } + } + + return targetHuman; + } + + @Override + public TargetOnlyGetter toTargetOnlyGetter(Source source) throws DogException { + if ( source == null ) { + return null; + } + + TargetOnlyGetter targetOnlyGetter = new TargetOnlyGetter(); + + if ( source.getPets() != null ) { + try { + for ( String pet : source.getPets() ) { + targetOnlyGetter.addPet( petMapper.toPet( pet ) ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + } + + return targetOnlyGetter; + } + + @Override + public TargetViaTargetType toTargetViaTargetType(Source source) { + if ( source == null ) { + return null; + } + + TargetViaTargetType targetViaTargetType = new TargetViaTargetType(); + + if ( source.getPets() != null ) { + try { + for ( String pet : source.getPets() ) { + targetViaTargetType.addPet( petMapper.toPet( pet, IndoorPet.class ) ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + catch ( DogException e ) { + throw new RuntimeException( e ); + } + } + + return targetViaTargetType; + } + + @Override + public Target fromSingleElementSource(SingleElementSource source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getPet() != null ) { + try { + target.addPet( petMapper.toPet( source.getPet() ) ); + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + catch ( DogException e ) { + throw new RuntimeException( e ); + } + } + + return target; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java new file mode 100644 index 0000000000..2926f33e4f --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.adder; + +import java.util.List; +import javax.annotation.Generated; +import org.mapstruct.ap.test.collection.adder._target.Target; +import org.mapstruct.ap.test.collection.adder.source.Source; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:10:39+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class SourceTargetMapperStrategyDefaultImpl implements SourceTargetMapperStrategyDefault { + + private final PetMapper petMapper = new PetMapper(); + + @Override + public Target shouldFallBackToAdder(Source source) throws DogException { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + try { + List list = petMapper.toPets( source.getPets() ); + if ( list != null ) { + target.setPets( list ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + + return target; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java new file mode 100644 index 0000000000..83fce867a7 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.adder; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.collection.adder._target.TargetWithoutSetter; +import org.mapstruct.ap.test.collection.adder.source.Source; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:10:39+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class SourceTargetMapperStrategySetterPreferredImpl implements SourceTargetMapperStrategySetterPreferred { + + private final PetMapper petMapper = new PetMapper(); + + @Override + public TargetWithoutSetter toTargetDontUseAdder(Source source) throws DogException { + if ( source == null ) { + return null; + } + + TargetWithoutSetter targetWithoutSetter = new TargetWithoutSetter(); + + if ( source.getPets() != null ) { + try { + for ( String pet : source.getPets() ) { + targetWithoutSetter.addPet( petMapper.toPet( pet ) ); + } + } + catch ( CatException e ) { + throw new RuntimeException( e ); + } + } + + return targetWithoutSetter; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..3081046449 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java @@ -0,0 +1,134 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.string; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:22:52+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setB( String.valueOf( source.getB() ) ); + if ( source.getBb() != null ) { + target.setBb( String.valueOf( source.getBb() ) ); + } + target.setS( String.valueOf( source.getS() ) ); + if ( source.getSs() != null ) { + target.setSs( String.valueOf( source.getSs() ) ); + } + target.setI( String.valueOf( source.getI() ) ); + if ( source.getIi() != null ) { + target.setIi( String.valueOf( source.getIi() ) ); + } + target.setL( String.valueOf( source.getL() ) ); + if ( source.getLl() != null ) { + target.setLl( String.valueOf( source.getLl() ) ); + } + target.setF( String.valueOf( source.getF() ) ); + if ( source.getFf() != null ) { + target.setFf( String.valueOf( source.getFf() ) ); + } + target.setD( String.valueOf( source.getD() ) ); + if ( source.getDd() != null ) { + target.setDd( String.valueOf( source.getDd() ) ); + } + target.setBool( String.valueOf( source.getBool() ) ); + if ( source.getBoolBool() != null ) { + target.setBoolBool( String.valueOf( source.getBoolBool() ) ); + } + target.setC( String.valueOf( source.getC() ) ); + if ( source.getCc() != null ) { + target.setCc( source.getCc().toString() ); + } + + return target; + } + + @Override + public Source targetToSource(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getB() != null ) { + source.setB( Byte.parseByte( target.getB() ) ); + } + if ( target.getBb() != null ) { + source.setBb( Byte.parseByte( target.getBb() ) ); + } + if ( target.getS() != null ) { + source.setS( Short.parseShort( target.getS() ) ); + } + if ( target.getSs() != null ) { + source.setSs( Short.parseShort( target.getSs() ) ); + } + if ( target.getI() != null ) { + source.setI( Integer.parseInt( target.getI() ) ); + } + if ( target.getIi() != null ) { + source.setIi( Integer.parseInt( target.getIi() ) ); + } + if ( target.getL() != null ) { + source.setL( Long.parseLong( target.getL() ) ); + } + if ( target.getLl() != null ) { + source.setLl( Long.parseLong( target.getLl() ) ); + } + if ( target.getF() != null ) { + source.setF( Float.parseFloat( target.getF() ) ); + } + if ( target.getFf() != null ) { + source.setFf( Float.parseFloat( target.getFf() ) ); + } + if ( target.getD() != null ) { + source.setD( Double.parseDouble( target.getD() ) ); + } + if ( target.getDd() != null ) { + source.setDd( Double.parseDouble( target.getDd() ) ); + } + if ( target.getBool() != null ) { + source.setBool( Boolean.parseBoolean( target.getBool() ) ); + } + if ( target.getBoolBool() != null ) { + source.setBoolBool( Boolean.parseBoolean( target.getBoolBool() ) ); + } + if ( target.getC() != null ) { + source.setC( target.getC().charAt( 0 ) ); + } + if ( target.getCc() != null ) { + source.setCc( target.getCc().charAt( 0 ) ); + } + source.setObject( target.getObject() ); + + return source; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java new file mode 100644 index 0000000000..d1e7159c6a --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java @@ -0,0 +1,71 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:11:46+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class CompanyMapperImpl implements CompanyMapper { + + private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); + + @Override + public void toCompanyEntity(CompanyDto dto, CompanyEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( dto.getDepartment() != null ) { + if ( entity.getDepartment() == null ) { + entity.setDepartment( departmentEntityFactory.createDepartmentEntity() ); + } + toDepartmentEntity( toInBetween( dto.getDepartment() ), entity.getDepartment() ); + } + else { + entity.setDepartment( null ); + } + } + + @Override + public DepartmentInBetween toInBetween(DepartmentDto dto) { + if ( dto == null ) { + return null; + } + + DepartmentInBetween departmentInBetween_ = new DepartmentInBetween(); + + departmentInBetween_.setName( dto.getName() ); + + return departmentInBetween_; + } + + @Override + public void toDepartmentEntity(DepartmentInBetween dto, DepartmentEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java new file mode 100644 index 0000000000..d2c64af1dd --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:11:45+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class OrganizationMapperImpl implements OrganizationMapper { + + private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); + + @Override + public void toOrganizationEntity(OrganizationDto dto, OrganizationEntity entity) { + if ( dto == null ) { + return; + } + + if ( dto.getCompany() != null ) { + if ( entity.getCompany() == null ) { + entity.setCompany( new CompanyEntity() ); + } + toCompanyEntity( dto.getCompany(), entity.getCompany() ); + } + else { + entity.setCompany( null ); + } + + if ( entity.getType() == null ) { + entity.setType( new OrganizationTypeEntity() ); + } + toName( "commercial", entity.getType() ); + if ( entity.getTypeNr() == null ) { + entity.setTypeNr( new OrganizationTypeNrEntity() ); + } + toNumber( Integer.parseInt( "5" ), entity.getTypeNr() ); + } + + @Override + public void toCompanyEntity(CompanyDto dto, CompanyEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + entity.setDepartment( toDepartmentEntity( dto.getDepartment() ) ); + } + + @Override + public DepartmentEntity toDepartmentEntity(DepartmentDto dto) { + if ( dto == null ) { + return null; + } + + DepartmentEntity departmentEntity_ = departmentEntityFactory.createDepartmentEntity(); + + departmentEntity_.setName( dto.getName() ); + + return departmentEntity_; + } + + @Override + public void toName(String type, OrganizationTypeEntity entity) { + if ( type == null ) { + return; + } + + entity.setType( type ); + } + + @Override + public void toNumber(Integer number, OrganizationTypeNrEntity entity) { + if ( number == null ) { + return; + } + + entity.setNumber( number ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java new file mode 100644 index 0000000000..2150b37bb7 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java @@ -0,0 +1,82 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods.selection; + +import java.util.ArrayList; +import java.util.HashMap; +import javax.annotation.Generated; +import org.mapstruct.ap.test.updatemethods.DepartmentDto; +import org.mapstruct.ap.test.updatemethods.DepartmentEntity; +import org.mapstruct.ap.test.updatemethods.EmployeeDto; +import org.mapstruct.ap.test.updatemethods.EmployeeEntity; +import org.mapstruct.ap.test.updatemethods.SecretaryDto; +import org.mapstruct.ap.test.updatemethods.SecretaryEntity; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:17:50+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DepartmentMapperImpl implements DepartmentMapper { + + private final ExternalHandWrittenMapper externalHandWrittenMapper = new ExternalHandWrittenMapper(); + + @Override + public void toDepartmentEntity(DepartmentDto dto, DepartmentEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( entity.getEmployees() == null ) { + entity.setEmployees( new ArrayList() ); + } + externalHandWrittenMapper.toEmployeeEntityList( dto.getEmployees(), entity.getEmployees() ); + if ( entity.getSecretaryToEmployee() == null ) { + entity.setSecretaryToEmployee( new HashMap() ); + } + externalHandWrittenMapper.toSecretaryEmployeeEntityMap( dto.getSecretaryToEmployee(), entity.getSecretaryToEmployee() ); + } + + @Override + public EmployeeEntity toEmployeeEntity(EmployeeDto dto) { + if ( dto == null ) { + return null; + } + + EmployeeEntity employeeEntity = new EmployeeEntity(); + + employeeEntity.setName( dto.getName() ); + + return employeeEntity; + } + + @Override + public SecretaryEntity toSecretaryEntity(SecretaryDto dto) { + if ( dto == null ) { + return null; + } + + SecretaryEntity secretaryEntity = new SecretaryEntity(); + + secretaryEntity.setName( dto.getName() ); + + return secretaryEntity; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java new file mode 100644 index 0000000000..00a5c22289 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods.selection; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.updatemethods.DepartmentDto; +import org.mapstruct.ap.test.updatemethods.DepartmentEntity; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:17:50+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class ExternalMapperImpl implements ExternalMapper { + + @Override + public void toDepartmentEntity(DepartmentDto dto, DepartmentEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java new file mode 100644 index 0000000000..fd9501fac7 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java @@ -0,0 +1,54 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods.selection; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.updatemethods.CompanyDto; +import org.mapstruct.ap.test.updatemethods.CompanyEntity; +import org.mapstruct.ap.test.updatemethods.DepartmentEntityFactory; +import org.mapstruct.factory.Mappers; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:17:50+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class OrganizationMapper1Impl implements OrganizationMapper1 { + + private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class ); + private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); + + @Override + public void toCompanyEntity(CompanyDto dto, CompanyEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( dto.getDepartment() != null ) { + if ( entity.getDepartment() == null ) { + entity.setDepartment( departmentEntityFactory.createDepartmentEntity() ); + } + externalMapper.toDepartmentEntity( dto.getDepartment(), entity.getDepartment() ); + } + else { + entity.setDepartment( null ); + } + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java new file mode 100644 index 0000000000..a0a426f772 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods.selection; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.updatemethods.CompanyDto; +import org.mapstruct.ap.test.updatemethods.CompanyEntity; +import org.mapstruct.ap.test.updatemethods.DepartmentEntityFactory; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:17:47+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class OrganizationMapper2Impl implements OrganizationMapper2 { + + private final ExternalHandWrittenMapper externalHandWrittenMapper = new ExternalHandWrittenMapper(); + private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); + + @Override + public void toCompanyEntity(CompanyDto dto, CompanyEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( dto.getDepartment() != null ) { + if ( entity.getDepartment() == null ) { + entity.setDepartment( departmentEntityFactory.createDepartmentEntity() ); + } + externalHandWrittenMapper.toDepartmentEntity( dto.getDepartment(), entity.getDepartment() ); + } + else { + entity.setDepartment( null ); + } + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java new file mode 100644 index 0000000000..830fcde812 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2016 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.updatemethods.selection; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.updatemethods.BossDto; +import org.mapstruct.ap.test.updatemethods.BossEntity; +import org.mapstruct.ap.test.updatemethods.ConstructableDepartmentEntity; +import org.mapstruct.factory.Mappers; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2016-12-30T19:17:49+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class OrganizationMapper3Impl implements OrganizationMapper3 { + + private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class ); + + @Override + public void toBossEntity(BossDto dto, BossEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( dto.getDepartment() != null ) { + if ( entity.getDepartment() == null ) { + entity.setDepartment( new ConstructableDepartmentEntity() ); + } + externalMapper.toDepartmentEntity( dto.getDepartment(), entity.getDepartment() ); + } + else { + entity.setDepartment( null ); + } + } +} From b02f8e5df50e8d50ac707daba72c35f83c7b5563 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 5 Jan 2017 18:55:20 +0100 Subject: [PATCH 0020/1006] #1032 Update license headers to 2017 --- .gitignore | 1 + build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-common/src/main/java/org/mapstruct/AfterMapping.java | 2 +- core-common/src/main/java/org/mapstruct/BeanMapping.java | 2 +- core-common/src/main/java/org/mapstruct/BeforeMapping.java | 2 +- .../src/main/java/org/mapstruct/CollectionMappingStrategy.java | 2 +- core-common/src/main/java/org/mapstruct/DecoratedWith.java | 2 +- .../src/main/java/org/mapstruct/InheritConfiguration.java | 2 +- .../main/java/org/mapstruct/InheritInverseConfiguration.java | 2 +- core-common/src/main/java/org/mapstruct/IterableMapping.java | 2 +- core-common/src/main/java/org/mapstruct/MapMapping.java | 2 +- core-common/src/main/java/org/mapstruct/Mapper.java | 2 +- core-common/src/main/java/org/mapstruct/MapperConfig.java | 2 +- core-common/src/main/java/org/mapstruct/MappingConstants.java | 2 +- .../src/main/java/org/mapstruct/MappingInheritanceStrategy.java | 2 +- core-common/src/main/java/org/mapstruct/MappingTarget.java | 2 +- core-common/src/main/java/org/mapstruct/Named.java | 2 +- .../src/main/java/org/mapstruct/NullValueCheckStrategy.java | 2 +- .../src/main/java/org/mapstruct/NullValueMappingStrategy.java | 2 +- core-common/src/main/java/org/mapstruct/Qualifier.java | 2 +- core-common/src/main/java/org/mapstruct/ReportingPolicy.java | 2 +- core-common/src/main/java/org/mapstruct/TargetType.java | 2 +- core-common/src/main/java/org/mapstruct/factory/Mappers.java | 2 +- .../src/main/java/org/mapstruct/factory/package-info.java | 2 +- core-common/src/main/java/org/mapstruct/package-info.java | 2 +- core-common/src/main/java/org/mapstruct/util/Experimental.java | 2 +- .../src/test/java/org/mapstruct/factory/MappersTest.java | 2 +- core-common/src/test/java/org/mapstruct/test/model/Foo.java | 2 +- core-common/src/test/java/org/mapstruct/test/model/FooImpl.java | 2 +- core-jdk8/pom.xml | 2 +- core-jdk8/src/main/java/org/mapstruct/Mapping.java | 2 +- core-jdk8/src/main/java/org/mapstruct/Mappings.java | 2 +- core-jdk8/src/main/java/org/mapstruct/ValueMapping.java | 2 +- core-jdk8/src/main/java/org/mapstruct/ValueMappings.java | 2 +- core/pom.xml | 2 +- core/src/main/java/org/mapstruct/Mapping.java | 2 +- core/src/main/java/org/mapstruct/Mappings.java | 2 +- core/src/main/java/org/mapstruct/ValueMapping.java | 2 +- core/src/main/java/org/mapstruct/ValueMappings.java | 2 +- distribution/pom.xml | 2 +- distribution/src/main/assembly/dist.xml | 2 +- documentation/pom.xml | 2 +- etc/license.txt | 2 +- integrationtest/pom.xml | 2 +- .../src/test/java/org/mapstruct/itest/tests/CdiTest.java | 2 +- .../org/mapstruct/itest/tests/FullFeatureCompilationTest.java | 2 +- .../src/test/java/org/mapstruct/itest/tests/Java8Test.java | 2 +- .../src/test/java/org/mapstruct/itest/tests/JaxbTest.java | 2 +- .../src/test/java/org/mapstruct/itest/tests/Jsr330Test.java | 2 +- .../test/java/org/mapstruct/itest/tests/NamingStrategyTest.java | 2 +- .../src/test/java/org/mapstruct/itest/tests/SimpleTest.java | 2 +- .../src/test/java/org/mapstruct/itest/tests/SpringTest.java | 2 +- .../java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java | 2 +- .../org/mapstruct/itest/testutil/runner/ProcessorSuite.java | 2 +- .../mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java | 2 +- .../java/org/mapstruct/itest/testutil/runner/Toolchain.java | 2 +- .../org/mapstruct/itest/testutil/runner/xml/Toolchains.java | 2 +- integrationtest/src/test/resources/cdiTest/pom.xml | 2 +- .../org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java | 2 +- .../cdiTest/src/main/java/org/mapstruct/itest/cdi/Source.java | 2 +- .../main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java | 2 +- .../org/mapstruct/itest/cdi/SourceTargetMapperDecorator.java | 2 +- .../cdiTest/src/main/java/org/mapstruct/itest/cdi/Target.java | 2 +- .../src/main/java/org/mapstruct/itest/cdi/other/DateMapper.java | 2 +- .../test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java | 2 +- integrationtest/src/test/resources/fullFeatureTest/pom.xml | 2 +- .../src/test/java/org/mapstruct/itest/simple/AnimalTest.java | 2 +- integrationtest/src/test/resources/java8Test/pom.xml | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_603/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_603/SourceTargetMapper.java | 2 +- .../ap/test/bugs/_603/SourceTargetMapperDecorator.java | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_603/Target.java | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_636/Bar.java | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_636/Foo.java | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_636/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_636/SourceTargetBaseMapper.java | 2 +- .../org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java | 2 +- .../src/main/java/org/mapstruct/ap/test/bugs/_636/Target.java | 2 +- .../src/main/java/org/mapstruct/itest/java8/Java8Mapper.java | 2 +- .../src/main/java/org/mapstruct/itest/java8/Source.java | 2 +- .../src/main/java/org/mapstruct/itest/java8/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java | 2 +- .../test/java/org/mapstruct/itest/java8/Java8MapperTest.java | 2 +- integrationtest/src/test/resources/jaxbTest/pom.xml | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/JaxbMapper.java | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/OrderDetailsDto.java | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/OrderDto.java | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/OrderStatusDto.java | 2 +- .../main/java/org/mapstruct/itest/jaxb/ShippingAddressDto.java | 2 +- .../main/java/org/mapstruct/itest/jaxb/SourceTargetMapper.java | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/SubTypeDto.java | 2 +- .../src/main/java/org/mapstruct/itest/jaxb/SuperTypeDto.java | 2 +- .../resources/jaxbTest/src/main/resources/binding/binding.xjb | 2 +- .../test/resources/jaxbTest/src/main/resources/schema/test1.xsd | 2 +- .../test/resources/jaxbTest/src/main/resources/schema/test2.xsd | 2 +- .../jaxbTest/src/main/resources/schema/underscores.xsd | 2 +- .../test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java | 2 +- integrationtest/src/test/resources/jsr330Test/pom.xml | 2 +- .../org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java | 2 +- .../itest/jsr330/SecondDecoratedSourceTargetMapper.java | 2 +- .../itest/jsr330/SecondSourceTargetMapperDecorator.java | 2 +- .../src/main/java/org/mapstruct/itest/jsr330/Source.java | 2 +- .../java/org/mapstruct/itest/jsr330/SourceTargetMapper.java | 2 +- .../org/mapstruct/itest/jsr330/SourceTargetMapperDecorator.java | 2 +- .../src/main/java/org/mapstruct/itest/jsr330/Target.java | 2 +- .../main/java/org/mapstruct/itest/jsr330/other/DateMapper.java | 2 +- .../java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java | 2 +- integrationtest/src/test/resources/namingStrategyTest/pom.xml | 2 +- .../src/test/resources/namingStrategyTest/strategy/pom.xml | 2 +- .../mapstruct/itest/naming/CustomAccessorNamingStrategy.java | 2 +- .../src/test/resources/namingStrategyTest/usage/pom.xml | 2 +- .../src/main/java/org/mapstruct/itest/naming/GolfPlayer.java | 2 +- .../src/main/java/org/mapstruct/itest/naming/GolfPlayerDto.java | 2 +- .../main/java/org/mapstruct/itest/naming/GolfPlayerMapper.java | 2 +- .../src/test/java/org/mapstruct/itest/naming/NamingTest.java | 2 +- integrationtest/src/test/resources/pom.xml | 2 +- integrationtest/src/test/resources/simpleTest/pom.xml | 2 +- .../src/main/java/org/mapstruct/itest/simple/BaseType.java | 2 +- .../java/org/mapstruct/itest/simple/ReferencedCustomMapper.java | 2 +- .../src/main/java/org/mapstruct/itest/simple/SomeOtherType.java | 2 +- .../src/main/java/org/mapstruct/itest/simple/SomeType.java | 2 +- .../src/main/java/org/mapstruct/itest/simple/Source.java | 2 +- .../org/mapstruct/itest/simple/SourceTargetAbstractMapper.java | 2 +- .../java/org/mapstruct/itest/simple/SourceTargetMapper.java | 2 +- .../src/main/java/org/mapstruct/itest/simple/Target.java | 2 +- .../main/java/org/mapstruct/itest/simple/YetAnotherType.java | 2 +- .../test/java/org/mapstruct/itest/simple/ConversionTest.java | 2 +- integrationtest/src/test/resources/springTest/pom.xml | 2 +- .../org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java | 2 +- .../itest/spring/SecondDecoratedSourceTargetMapper.java | 2 +- .../itest/spring/SecondSourceTargetMapperDecorator.java | 2 +- .../src/main/java/org/mapstruct/itest/spring/Source.java | 2 +- .../java/org/mapstruct/itest/spring/SourceTargetMapper.java | 2 +- .../org/mapstruct/itest/spring/SourceTargetMapperDecorator.java | 2 +- .../src/main/java/org/mapstruct/itest/spring/Target.java | 2 +- .../main/java/org/mapstruct/itest/spring/other/DateMapper.java | 2 +- .../java/org/mapstruct/itest/spring/SpringBasedMapperTest.java | 2 +- .../itest/supertypegeneration/BaseGenerationProcessor.java | 2 +- .../java/org/mapstruct/itest/supertypegeneration/GenBase.java | 2 +- .../META-INF/services/javax.annotation.processing.Processor | 2 +- .../src/test/resources/superTypeGenerationTest/pom.xml | 2 +- .../itest/supertypegeneration/usage/AnotherOrderMapper.java | 2 +- .../org/mapstruct/itest/supertypegeneration/usage/Order.java | 2 +- .../org/mapstruct/itest/supertypegeneration/usage/OrderDto.java | 2 +- .../mapstruct/itest/supertypegeneration/usage/OrderMapper.java | 2 +- .../itest/supertypegeneration/usage/GeneratedBasesTest.java | 2 +- parent/pom.xml | 2 +- processor/pom.xml | 2 +- processor/src/main/java/org/mapstruct/ap/MappingProcessor.java | 2 +- .../internal/conversion/AbstractJavaTimeToStringConversion.java | 2 +- .../internal/conversion/AbstractJodaTypeToStringConversion.java | 2 +- .../internal/conversion/AbstractNumberToStringConversion.java | 2 +- .../internal/conversion/BigDecimalToBigIntegerConversion.java | 2 +- .../ap/internal/conversion/BigDecimalToPrimitiveConversion.java | 2 +- .../ap/internal/conversion/BigDecimalToStringConversion.java | 2 +- .../ap/internal/conversion/BigDecimalToWrapperConversion.java | 2 +- .../ap/internal/conversion/BigIntegerToPrimitiveConversion.java | 2 +- .../ap/internal/conversion/BigIntegerToStringConversion.java | 2 +- .../ap/internal/conversion/BigIntegerToWrapperConversion.java | 2 +- .../ap/internal/conversion/CharToStringConversion.java | 2 +- .../ap/internal/conversion/CharWrapperToStringConversion.java | 2 +- .../mapstruct/ap/internal/conversion/ConversionProvider.java | 2 +- .../java/org/mapstruct/ap/internal/conversion/Conversions.java | 2 +- .../mapstruct/ap/internal/conversion/CreateDecimalFormat.java | 2 +- .../ap/internal/conversion/DateToSqlDateConversion.java | 2 +- .../ap/internal/conversion/DateToSqlTimeConversion.java | 2 +- .../ap/internal/conversion/DateToSqlTimestampConversion.java | 2 +- .../ap/internal/conversion/DateToStringConversion.java | 2 +- .../mapstruct/ap/internal/conversion/EnumStringConversion.java | 2 +- .../internal/conversion/JavaLocalDateTimeToDateConversion.java | 2 +- .../conversion/JavaLocalDateTimeToStringConversion.java | 2 +- .../ap/internal/conversion/JavaLocalDateToDateConversion.java | 2 +- .../ap/internal/conversion/JavaLocalDateToStringConversion.java | 2 +- .../ap/internal/conversion/JavaLocalTimeToStringConversion.java | 2 +- .../internal/conversion/JavaZonedDateTimeToDateConversion.java | 2 +- .../conversion/JavaZonedDateTimeToStringConversion.java | 2 +- .../internal/conversion/JodaDateTimeToCalendarConversion.java | 2 +- .../ap/internal/conversion/JodaDateTimeToStringConversion.java | 2 +- .../conversion/JodaLocalDateTimeToStringConversion.java | 2 +- .../ap/internal/conversion/JodaLocalDateToStringConversion.java | 2 +- .../ap/internal/conversion/JodaLocalTimeToStringConversion.java | 2 +- .../ap/internal/conversion/JodaTimeToDateConversion.java | 2 +- .../ap/internal/conversion/PrimitiveToPrimitiveConversion.java | 2 +- .../ap/internal/conversion/PrimitiveToStringConversion.java | 2 +- .../ap/internal/conversion/PrimitiveToWrapperConversion.java | 2 +- .../org/mapstruct/ap/internal/conversion/ReverseConversion.java | 2 +- .../org/mapstruct/ap/internal/conversion/SimpleConversion.java | 2 +- .../ap/internal/conversion/WrapperToStringConversion.java | 2 +- .../ap/internal/conversion/WrapperToWrapperConversion.java | 2 +- .../java/org/mapstruct/ap/internal/conversion/package-info.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/Annotation.java | 2 +- .../mapstruct/ap/internal/model/AnnotationMapperReference.java | 2 +- .../java/org/mapstruct/ap/internal/model/BeanMappingMethod.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/Constructor.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/Decorator.java | 2 +- .../org/mapstruct/ap/internal/model/DecoratorConstructor.java | 2 +- .../org/mapstruct/ap/internal/model/DefaultMapperReference.java | 2 +- .../java/org/mapstruct/ap/internal/model/DelegatingMethod.java | 2 +- .../java/org/mapstruct/ap/internal/model/EnumMappingMethod.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/model/Field.java | 2 +- .../java/org/mapstruct/ap/internal/model/GeneratedType.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/HelperMethod.java | 2 +- .../org/mapstruct/ap/internal/model/IterableMappingMethod.java | 2 +- .../mapstruct/ap/internal/model/LifecycleCallbackFactory.java | 2 +- .../ap/internal/model/LifecycleCallbackMethodReference.java | 2 +- .../java/org/mapstruct/ap/internal/model/LocalVariable.java | 2 +- .../java/org/mapstruct/ap/internal/model/MapMappingMethod.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/model/Mapper.java | 2 +- .../java/org/mapstruct/ap/internal/model/MapperReference.java | 2 +- .../org/mapstruct/ap/internal/model/MappingBuilderContext.java | 2 +- .../java/org/mapstruct/ap/internal/model/MappingMethod.java | 2 +- .../java/org/mapstruct/ap/internal/model/MethodReference.java | 2 +- .../ap/internal/model/NestedLocalVariableAssignment.java | 2 +- .../ap/internal/model/NestedPropertyMappingMethod.java | 2 +- .../java/org/mapstruct/ap/internal/model/PropertyMapping.java | 2 +- .../java/org/mapstruct/ap/internal/model/ServicesEntry.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/SourceRHS.java | 2 +- .../java/org/mapstruct/ap/internal/model/TypeConversion.java | 2 +- .../org/mapstruct/ap/internal/model/ValueMappingMethod.java | 2 +- .../org/mapstruct/ap/internal/model/VirtualMappingMethod.java | 2 +- .../mapstruct/ap/internal/model/assignment/AdderWrapper.java | 2 +- .../ap/internal/model/assignment/ArrayCopyWrapper.java | 2 +- .../org/mapstruct/ap/internal/model/assignment/Assignment.java | 2 +- .../ap/internal/model/assignment/AssignmentWrapper.java | 2 +- .../ap/internal/model/assignment/EnumConstantWrapper.java | 2 +- .../model/assignment/GetterWrapperForCollectionsAndMaps.java | 2 +- .../mapstruct/ap/internal/model/assignment/LocalVarWrapper.java | 2 +- .../ap/internal/model/assignment/NullCheckWrapper.java | 2 +- .../mapstruct/ap/internal/model/assignment/SetterWrapper.java | 2 +- .../model/assignment/SetterWrapperForCollectionsAndMaps.java | 2 +- .../ap/internal/model/assignment/UpdateNullCheckWrapper.java | 2 +- .../mapstruct/ap/internal/model/assignment/UpdateWrapper.java | 2 +- .../internal/model/assignment/WrapperForCollectionsAndMaps.java | 2 +- .../mapstruct/ap/internal/model/assignment/package-info.java | 2 +- .../org/mapstruct/ap/internal/model/common/Accessibility.java | 2 +- .../mapstruct/ap/internal/model/common/ConversionContext.java | 2 +- .../ap/internal/model/common/DateFormatValidationResult.java | 2 +- .../mapstruct/ap/internal/model/common/DateFormatValidator.java | 2 +- .../ap/internal/model/common/DateFormatValidatorFactory.java | 2 +- .../ap/internal/model/common/DefaultConversionContext.java | 2 +- .../org/mapstruct/ap/internal/model/common/ModelElement.java | 2 +- .../java/org/mapstruct/ap/internal/model/common/Parameter.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/common/Type.java | 2 +- .../org/mapstruct/ap/internal/model/common/TypeFactory.java | 2 +- .../org/mapstruct/ap/internal/model/common/package-info.java | 2 +- .../mapstruct/ap/internal/model/dependency/GraphAnalyzer.java | 2 +- .../java/org/mapstruct/ap/internal/model/dependency/Node.java | 2 +- .../main/java/org/mapstruct/ap/internal/model/package-info.java | 2 +- .../org/mapstruct/ap/internal/model/source/BeanMapping.java | 2 +- .../org/mapstruct/ap/internal/model/source/EnumMapping.java | 2 +- .../org/mapstruct/ap/internal/model/source/ForgedMethod.java | 2 +- .../ap/internal/model/source/FormattingParameters.java | 2 +- .../org/mapstruct/ap/internal/model/source/IterableMapping.java | 2 +- .../java/org/mapstruct/ap/internal/model/source/MapMapping.java | 2 +- .../java/org/mapstruct/ap/internal/model/source/Mapping.java | 2 +- .../org/mapstruct/ap/internal/model/source/MappingOptions.java | 2 +- .../java/org/mapstruct/ap/internal/model/source/Method.java | 2 +- .../org/mapstruct/ap/internal/model/source/MethodMatcher.java | 2 +- .../org/mapstruct/ap/internal/model/source/PropertyEntry.java | 2 +- .../mapstruct/ap/internal/model/source/SelectionParameters.java | 2 +- .../org/mapstruct/ap/internal/model/source/SourceMethod.java | 2 +- .../org/mapstruct/ap/internal/model/source/SourceReference.java | 2 +- .../org/mapstruct/ap/internal/model/source/TargetReference.java | 2 +- .../org/mapstruct/ap/internal/model/source/ValueMapping.java | 2 +- .../ap/internal/model/source/builtin/BuiltInMappingMethods.java | 2 +- .../ap/internal/model/source/builtin/BuiltInMethod.java | 2 +- .../model/source/builtin/CalendarToXmlGregorianCalendar.java | 2 +- .../internal/model/source/builtin/CalendarToZonedDateTime.java | 2 +- .../model/source/builtin/DateToXmlGregorianCalendar.java | 2 +- .../ap/internal/model/source/builtin/JaxbElemToValue.java | 2 +- .../source/builtin/JodaDateTimeToXmlGregorianCalendar.java | 2 +- .../source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java | 2 +- .../source/builtin/JodaLocalDateToXmlGregorianCalendar.java | 2 +- .../source/builtin/JodaLocalTimeToXmlGregorianCalendar.java | 2 +- .../model/source/builtin/LocalDateToXmlGregorianCalendar.java | 2 +- .../model/source/builtin/StringToXmlGregorianCalendar.java | 2 +- .../model/source/builtin/XmlGregorianCalendarToCalendar.java | 2 +- .../model/source/builtin/XmlGregorianCalendarToDate.java | 2 +- .../source/builtin/XmlGregorianCalendarToJodaDateTime.java | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalDate.java | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalTime.java | 2 +- .../model/source/builtin/XmlGregorianCalendarToLocalDate.java | 2 +- .../model/source/builtin/XmlGregorianCalendarToString.java | 2 +- .../internal/model/source/builtin/ZonedDateTimeToCalendar.java | 2 +- .../ap/internal/model/source/builtin/package-info.java | 2 +- .../org/mapstruct/ap/internal/model/source/package-info.java | 2 +- .../internal/model/source/selector/CreateOrUpdateSelector.java | 2 +- .../ap/internal/model/source/selector/InheritanceSelector.java | 2 +- .../ap/internal/model/source/selector/MethodSelector.java | 2 +- .../ap/internal/model/source/selector/MethodSelectors.java | 2 +- .../ap/internal/model/source/selector/QualifierSelector.java | 2 +- .../ap/internal/model/source/selector/SelectionCriteria.java | 2 +- .../ap/internal/model/source/selector/TargetTypeSelector.java | 2 +- .../ap/internal/model/source/selector/TypeSelector.java | 2 +- .../internal/model/source/selector/XmlElementDeclSelector.java | 2 +- .../ap/internal/model/source/selector/package-info.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/option/Options.java | 2 +- .../java/org/mapstruct/ap/internal/option/package-info.java | 2 +- .../ap/internal/prism/CollectionMappingStrategyPrism.java | 2 +- .../org/mapstruct/ap/internal/prism/MappingConstantsPrism.java | 2 +- .../ap/internal/prism/MappingInheritanceStrategyPrism.java | 2 +- .../ap/internal/prism/NullValueCheckStrategyPrism.java | 2 +- .../ap/internal/prism/NullValueMappingStrategyPrism.java | 2 +- .../java/org/mapstruct/ap/internal/prism/PrismGenerator.java | 2 +- .../org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java | 2 +- .../main/java/org/mapstruct/ap/internal/prism/package-info.java | 2 +- .../processor/AnnotationBasedComponentModelProcessor.java | 2 +- .../mapstruct/ap/internal/processor/CdiComponentProcessor.java | 2 +- .../internal/processor/DefaultModelElementProcessorContext.java | 2 +- .../ap/internal/processor/DefaultVersionInformation.java | 2 +- .../ap/internal/processor/Jsr330ComponentProcessor.java | 2 +- .../ap/internal/processor/MapperCreationProcessor.java | 2 +- .../ap/internal/processor/MapperRenderingProcessor.java | 2 +- .../mapstruct/ap/internal/processor/MapperServiceProcessor.java | 2 +- .../ap/internal/processor/MethodRetrievalProcessor.java | 2 +- .../mapstruct/ap/internal/processor/ModelElementProcessor.java | 2 +- .../ap/internal/processor/SpringComponentProcessor.java | 2 +- .../ap/internal/processor/creation/MappingResolverImpl.java | 2 +- .../mapstruct/ap/internal/processor/creation/package-info.java | 2 +- .../java/org/mapstruct/ap/internal/processor/package-info.java | 2 +- .../ap/internal/util/AnnotationProcessingException.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/Collections.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/Executables.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/util/Filters.java | 2 +- .../java/org/mapstruct/ap/internal/util/FormattingMessager.java | 2 +- .../java/org/mapstruct/ap/internal/util/JavaTimeConstants.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/JaxbConstants.java | 2 +- .../java/org/mapstruct/ap/internal/util/JodaTimeConstants.java | 2 +- .../org/mapstruct/ap/internal/util/MapperConfiguration.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/util/Message.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/NativeTypes.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/util/Nouns.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/util/Services.java | 2 +- .../src/main/java/org/mapstruct/ap/internal/util/Strings.java | 2 +- .../ap/internal/util/TypeHierarchyErroneousException.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/package-info.java | 2 +- .../internal/util/workarounds/EclipseAsMemberOfWorkaround.java | 2 +- .../ap/internal/util/workarounds/EclipseClassLoaderBridge.java | 2 +- .../internal/util/workarounds/SpecificCompilerWorkarounds.java | 2 +- .../mapstruct/ap/internal/util/workarounds/TypesDecorator.java | 2 +- .../org/mapstruct/ap/internal/version/VersionInformation.java | 2 +- .../java/org/mapstruct/ap/internal/version/package-info.java | 2 +- .../ap/internal/writer/FreeMarkerModelElementWriter.java | 2 +- .../org/mapstruct/ap/internal/writer/FreeMarkerWritable.java | 2 +- .../ap/internal/writer/IndentationCorrectingWriter.java | 2 +- .../org/mapstruct/ap/internal/writer/ModelIncludeDirective.java | 2 +- .../main/java/org/mapstruct/ap/internal/writer/ModelWriter.java | 2 +- .../main/java/org/mapstruct/ap/internal/writer/Writable.java | 2 +- .../java/org/mapstruct/ap/internal/writer/package-info.java | 2 +- processor/src/main/java/org/mapstruct/ap/package-info.java | 2 +- .../main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java | 2 +- .../org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java | 2 +- processor/src/main/java/org/mapstruct/ap/spi/MethodType.java | 2 +- processor/src/main/java/org/mapstruct/ap/spi/package-info.java | 2 +- .../META-INF/services/javax.annotation.processing.Processor | 2 +- .../org.mapstruct.ap.internal.processor.ModelElementProcessor | 2 +- .../mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/Annotation.ftl | 2 +- .../mapstruct/ap/internal/model/AnnotationMapperReference.ftl | 2 +- .../org/mapstruct/ap/internal/model/BeanMappingMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/ConversionMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/DecoratorConstructor.ftl | 2 +- .../org/mapstruct/ap/internal/model/DefaultMapperReference.ftl | 2 +- .../org/mapstruct/ap/internal/model/DelegatingMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/EnumMappingMethod.ftl | 2 +- .../main/resources/org/mapstruct/ap/internal/model/Field.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/GeneratedType.ftl | 2 +- .../org/mapstruct/ap/internal/model/IterableMappingMethod.ftl | 2 +- .../ap/internal/model/LifecycleCallbackMethodReference.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/LocalVariable.ftl | 2 +- .../org/mapstruct/ap/internal/model/MapMappingMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/MethodReference.ftl | 2 +- .../ap/internal/model/NestedLocalVariableAssignment.ftl | 2 +- .../mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/PropertyMapping.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/SourceRHS.ftl | 2 +- .../org/mapstruct/ap/internal/model/TypeConversion.ftl | 2 +- .../org/mapstruct/ap/internal/model/ValueMappingMethod.ftl | 2 +- .../org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl | 2 +- .../mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl | 2 +- .../ap/internal/model/assignment/EnumConstantWrapper.ftl | 2 +- .../model/assignment/GetterWrapperForCollectionsAndMaps.ftl | 2 +- .../mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl | 2 +- .../mapstruct/ap/internal/model/assignment/NullCheckWrapper.ftl | 2 +- .../mapstruct/ap/internal/model/assignment/SetterWrapper.ftl | 2 +- .../model/assignment/SetterWrapperForCollectionsAndMaps.ftl | 2 +- .../ap/internal/model/assignment/UpdateNullCheckWrapper.ftl | 2 +- .../mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl | 2 +- .../org/mapstruct/ap/internal/model/common/Parameter.ftl | 2 +- .../resources/org/mapstruct/ap/internal/model/common/Type.ftl | 2 +- .../org/mapstruct/ap/internal/model/macro/CommonMacros.ftl | 2 +- .../model/source/builtin/CalendarToXmlGregorianCalendar.ftl | 2 +- .../internal/model/source/builtin/CalendarToZonedDateTime.ftl | 2 +- .../model/source/builtin/DateToXmlGregorianCalendar.ftl | 2 +- .../ap/internal/model/source/builtin/JaxbElemToValue.ftl | 2 +- .../model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl | 2 +- .../source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl | 2 +- .../source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl | 2 +- .../source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl | 2 +- .../model/source/builtin/LocalDateToXmlGregorianCalendar.ftl | 2 +- .../model/source/builtin/StringToXmlGregorianCalendar.ftl | 2 +- .../model/source/builtin/XmlGregorianCalendarToCalendar.ftl | 2 +- .../model/source/builtin/XmlGregorianCalendarToDate.ftl | 2 +- .../model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl | 2 +- .../source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl | 2 +- .../model/source/builtin/XmlGregorianCalendarToLocalDate.ftl | 2 +- .../model/source/builtin/XmlGregorianCalendarToString.ftl | 2 +- .../internal/model/source/builtin/ZonedDateTimeToCalendar.ftl | 2 +- .../internal/model/common/DateFormatValidatorFactoryTest.java | 2 +- .../ap/internal/model/common/DefaultConversionContextTest.java | 2 +- .../org/mapstruct/ap/internal/model/common/TypeFactoryTest.java | 2 +- .../java/org/mapstruct/ap/internal/util/NativeTypesTest.java | 2 +- .../test/java/org/mapstruct/ap/internal/util/StringsTest.java | 2 +- .../org/mapstruct/ap/test/abstractclass/AbstractBaseMapper.java | 2 +- .../org/mapstruct/ap/test/abstractclass/AbstractClassTest.java | 2 +- .../java/org/mapstruct/ap/test/abstractclass/AbstractDto.java | 2 +- .../ap/test/abstractclass/AbstractReferencedMapper.java | 2 +- .../java/org/mapstruct/ap/test/abstractclass/AlsoHasId.java | 2 +- .../mapstruct/ap/test/abstractclass/BaseMapperInterface.java | 2 +- .../test/java/org/mapstruct/ap/test/abstractclass/HasId.java | 2 +- .../java/org/mapstruct/ap/test/abstractclass/Identifiable.java | 2 +- .../java/org/mapstruct/ap/test/abstractclass/Measurable.java | 2 +- .../org/mapstruct/ap/test/abstractclass/ReferencedMapper.java | 2 +- .../ap/test/abstractclass/ReferencedMapperInterface.java | 2 +- .../test/java/org/mapstruct/ap/test/abstractclass/Source.java | 2 +- .../org/mapstruct/ap/test/abstractclass/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/abstractclass/Target.java | 2 +- .../ap/test/abstractclass/generics/AbstractAnimal.java | 2 +- .../mapstruct/ap/test/abstractclass/generics/AbstractHuman.java | 2 +- .../org/mapstruct/ap/test/abstractclass/generics/AnimalKey.java | 2 +- .../org/mapstruct/ap/test/abstractclass/generics/Child.java | 2 +- .../org/mapstruct/ap/test/abstractclass/generics/Elephant.java | 2 +- .../ap/test/abstractclass/generics/GenericIdentifiable.java | 2 +- .../ap/test/abstractclass/generics/GenericsHierarchyMapper.java | 2 +- .../ap/test/abstractclass/generics/GenericsHierarchyTest.java | 2 +- .../org/mapstruct/ap/test/abstractclass/generics/IAnimal.java | 2 +- .../mapstruct/ap/test/abstractclass/generics/Identifiable.java | 2 +- .../java/org/mapstruct/ap/test/abstractclass/generics/Key.java | 2 +- .../ap/test/abstractclass/generics/KeyOfAllBeings.java | 2 +- .../org/mapstruct/ap/test/abstractclass/generics/Target.java | 2 +- .../org/mapstruct/ap/test/accessibility/AccessibilityTest.java | 2 +- .../ap/test/accessibility/DefaultSourceTargetMapperAbstr.java | 2 +- .../ap/test/accessibility/DefaultSourceTargetMapperIfc.java | 2 +- .../test/java/org/mapstruct/ap/test/accessibility/Source.java | 2 +- .../test/java/org/mapstruct/ap/test/accessibility/Target.java | 2 +- .../referenced/AbstractSourceTargetMapperProtected.java | 2 +- .../referenced/ErroneousAbstractSourceTargetMapperPrivate.java | 2 +- .../referenced/ErroneousSourceTargetMapperDefaultOther.java | 2 +- .../referenced/ErroneousSourceTargetMapperPrivate.java | 2 +- .../accessibility/referenced/ReferencedAccessibilityTest.java | 2 +- .../accessibility/referenced/ReferencedMapperDefaultSame.java | 2 +- .../test/accessibility/referenced/ReferencedMapperPrivate.java | 2 +- .../accessibility/referenced/ReferencedMapperProtected.java | 2 +- .../ap/test/accessibility/referenced/ReferencedSource.java | 2 +- .../ap/test/accessibility/referenced/ReferencedTarget.java | 2 +- .../org/mapstruct/ap/test/accessibility/referenced/Source.java | 2 +- .../accessibility/referenced/SourceTargetMapperDefaultSame.java | 2 +- .../accessibility/referenced/SourceTargetMapperProtected.java | 2 +- .../accessibility/referenced/SourceTargetmapperPrivateBase.java | 2 +- .../referenced/SourceTargetmapperProtectedBase.java | 2 +- .../org/mapstruct/ap/test/accessibility/referenced/Target.java | 2 +- .../referenced/a/ReferencedMapperDefaultOther.java | 2 +- .../test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java | 2 +- .../test/java/org/mapstruct/ap/test/array/ScienceMapper.java | 2 +- .../java/org/mapstruct/ap/test/array/_target/ScientistDto.java | 2 +- .../test/java/org/mapstruct/ap/test/array/source/Scientist.java | 2 +- .../java/org/mapstruct/ap/test/bool/BooleanMappingTest.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/bool/Person.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bool/PersonDto.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bool/PersonMapper.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/bool/YesNo.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bool/YesNoMapper.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_289/Issue289Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_289/Source.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_289/SourceElement.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_289/TargetElement.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_289/TargetWithSetter.java | 2 +- .../org/mapstruct/ap/test/bugs/_289/TargetWithoutSetter.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_306/Issue306Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_306/Source.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_306/Target.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_373/Branch.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_373/BranchLocation.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_373/Country.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_373/Issue373Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_373/ResultDto.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_374/Issue374Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java | 2 +- .../org/mapstruct/ap/test/bugs/_374/Issue374VoidMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_374/Source.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_374/Target.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_375/Case.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_375/Int.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_375/Issue375Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_375/Target.java | 2 +- .../ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java | 2 +- .../ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java | 2 +- .../org/mapstruct/ap/test/bugs/_394/_target/AnotherCar.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_394/_target/Cars.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_394/source/AnotherCar.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_394/source/Cars.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_405/EntityFactory.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_405/People.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_405/Person.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_513/Issue513Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_513/MappingException.java | 2 +- .../org/mapstruct/ap/test/bugs/_513/MappingKeyException.java | 2 +- .../org/mapstruct/ap/test/bugs/_513/MappingValueException.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_513/Source.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_513/SourceElement.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_513/SourceKey.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_513/SourceValue.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_513/Target.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_513/TargetElement.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_515/Issue515Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_515/Source.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_515/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_516/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_516/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_577/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_577/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_577/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java | 2 +- .../org/mapstruct/ap/test/bugs/_581/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_581/_target/Car.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_581/source/Car.java | 2 +- .../ap/test/bugs/_590/ErroneousSourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_625/ObjectFactory.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_625/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_625/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_625/Target.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_631/Base1.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_631/Base2.java | 2 +- .../ap/test/bugs/_631/ErroneousSourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_634/Bar.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_634/Foo.java | 2 +- .../org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_634/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_634/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_634/Target.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_775/IterableContainer.java | 2 +- .../ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_775/ListContainer.java | 2 +- .../ap/test/bugs/_775/MapperWithCustomListMapping.java | 2 +- .../ap/test/bugs/_775/MapperWithForgedIterableMapping.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_843/TagInfo.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_843/TagMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_855/OrderedSource.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_855/OrderedTarget.java | 2 +- .../org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java | 2 +- .../org/mapstruct/ap/test/bugs/_865/ProjCoreUserEntity.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_865/ProjMemberDto.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_865/ProjectDto.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_865/ProjectEntity.java | 2 +- .../mapstruct/ap/test/bugs/_865/ProjectEntityWithoutSetter.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_865/ProjectMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java | 2 +- .../ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java | 2 +- .../ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_891/Dest.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_891/Src.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_891/SrcNested.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_892/Issue892Mapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_895/MultiArrayMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java | 2 +- .../org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java | 2 +- .../bugs/_913/DomainWithoutSetterDtoWithNvmsDefaultMapper.java | 2 +- .../bugs/_913/DomainWithoutSetterDtoWithNvmsNullMapper.java | 2 +- .../_913/DomainWithoutSetterDtoWithPresenceCheckMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java | 2 +- .../org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_913/Helper.java | 2 +- .../test/bugs/_913/Issue913GetterMapperForCollectionsTest.java | 2 +- .../test/bugs/_913/Issue913SetterMapperForCollectionsTest.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_931/Nested.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_931/Source.java | 2 +- .../org/mapstruct/ap/test/bugs/_931/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_931/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_955/CarMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_955/CustomMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java | 2 +- .../src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Car.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_955/dto/Person.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_955/dto/SuperCar.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_971/CollectionSource.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_971/CollectionTarget.java | 2 +- .../mapstruct/ap/test/bugs/_971/Issue971CollectionMapper.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_971/Issue971MapMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_971/MapSource.java | 2 +- .../test/java/org/mapstruct/ap/test/bugs/_971/MapTarget.java | 2 +- .../test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java | 2 +- .../org/mapstruct/ap/test/builtin/_target/IterableTarget.java | 2 +- .../java/org/mapstruct/ap/test/builtin/_target/MapTarget.java | 2 +- .../org/mapstruct/ap/test/builtin/bean/CalendarProperty.java | 2 +- .../java/org/mapstruct/ap/test/builtin/bean/DateProperty.java | 2 +- .../mapstruct/ap/test/builtin/bean/JaxbElementListProperty.java | 2 +- .../org/mapstruct/ap/test/builtin/bean/JaxbElementProperty.java | 2 +- .../org/mapstruct/ap/test/builtin/bean/StringListProperty.java | 2 +- .../java/org/mapstruct/ap/test/builtin/bean/StringProperty.java | 2 +- .../ap/test/builtin/bean/XmlGregorianCalendarProperty.java | 2 +- .../ap/test/builtin/java8time/bean/ZonedDateTimeProperty.java | 2 +- .../builtin/java8time/mapper/CalendarToZonedDateTimeMapper.java | 2 +- .../builtin/java8time/mapper/ZonedDateTimeToCalendarMapper.java | 2 +- .../org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java | 2 +- .../mapstruct/ap/test/builtin/jodatime/bean/DateTimeBean.java | 2 +- .../mapstruct/ap/test/builtin/jodatime/bean/LocalDateBean.java | 2 +- .../ap/test/builtin/jodatime/bean/LocalDateTimeBean.java | 2 +- .../mapstruct/ap/test/builtin/jodatime/bean/LocalTimeBean.java | 2 +- .../ap/test/builtin/jodatime/bean/XmlGregorianCalendarBean.java | 2 +- .../builtin/jodatime/mapper/DateTimeToXmlGregorianCalendar.java | 2 +- .../jodatime/mapper/LocalDateTimeToXmlGregorianCalendar.java | 2 +- .../jodatime/mapper/LocalDateToXmlGregorianCalendar.java | 2 +- .../jodatime/mapper/LocalTimeToXmlGregorianCalendar.java | 2 +- .../builtin/jodatime/mapper/XmlGregorianCalendarToDateTime.java | 2 +- .../jodatime/mapper/XmlGregorianCalendarToLocalDate.java | 2 +- .../jodatime/mapper/XmlGregorianCalendarToLocalDateTime.java | 2 +- .../jodatime/mapper/XmlGregorianCalendarToLocalTime.java | 2 +- .../mapstruct/ap/test/builtin/mapper/CalendarToDateMapper.java | 2 +- .../ap/test/builtin/mapper/CalendarToStringMapper.java | 2 +- .../ap/test/builtin/mapper/CalendarToXmlGregCalMapper.java | 2 +- .../mapstruct/ap/test/builtin/mapper/DateToCalendarMapper.java | 2 +- .../ap/test/builtin/mapper/DateToXmlGregCalMapper.java | 2 +- .../ap/test/builtin/mapper/IterableSourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/builtin/mapper/JaxbListMapper.java | 2 +- .../java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java | 2 +- .../mapstruct/ap/test/builtin/mapper/MapSourceTargetMapper.java | 2 +- .../ap/test/builtin/mapper/StringToCalendarMapper.java | 2 +- .../ap/test/builtin/mapper/StringToXmlGregCalMapper.java | 2 +- .../ap/test/builtin/mapper/XmlGregCalToCalendarMapper.java | 2 +- .../ap/test/builtin/mapper/XmlGregCalToDateMapper.java | 2 +- .../ap/test/builtin/mapper/XmlGregCalToStringMapper.java | 2 +- .../org/mapstruct/ap/test/builtin/source/IterableSource.java | 2 +- .../java/org/mapstruct/ap/test/builtin/source/MapSource.java | 2 +- .../test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java | 2 +- .../org/mapstruct/ap/test/callbacks/CallbackMethodTest.java | 2 +- .../mapstruct/ap/test/callbacks/ClassContainingCallbacks.java | 2 +- .../test/java/org/mapstruct/ap/test/callbacks/Invocation.java | 2 +- .../test/java/org/mapstruct/ap/test/callbacks/Qualified.java | 2 +- .../src/test/java/org/mapstruct/ap/test/callbacks/Source.java | 2 +- .../test/java/org/mapstruct/ap/test/callbacks/SourceEnum.java | 2 +- .../ap/test/callbacks/SourceTargetCollectionMapper.java | 2 +- .../org/mapstruct/ap/test/callbacks/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/callbacks/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/callbacks/TargetEnum.java | 2 +- .../mapstruct/ap/test/callbacks/ongeneratedmethods/Address.java | 2 +- .../ap/test/callbacks/ongeneratedmethods/AddressDto.java | 2 +- .../mapstruct/ap/test/callbacks/ongeneratedmethods/Company.java | 2 +- .../ap/test/callbacks/ongeneratedmethods/CompanyDto.java | 2 +- .../ap/test/callbacks/ongeneratedmethods/CompanyMapper.java | 2 +- .../ongeneratedmethods/CompanyMapperPostProcessing.java | 2 +- .../ap/test/callbacks/ongeneratedmethods/Employee.java | 2 +- .../ap/test/callbacks/ongeneratedmethods/EmployeeDto.java | 2 +- .../ongeneratedmethods/MappingResultPostprocessorTest.java | 2 +- .../callbacks/typematching/CallbackMethodTypeMatchingTest.java | 2 +- .../org/mapstruct/ap/test/callbacks/typematching/CarMapper.java | 2 +- .../org/mapstruct/ap/test/collection/CollectionMappingTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/collection/Colour.java | 2 +- .../src/test/java/org/mapstruct/ap/test/collection/Source.java | 2 +- .../org/mapstruct/ap/test/collection/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/collection/StringHolder.java | 2 +- .../org/mapstruct/ap/test/collection/StringHolderArrayList.java | 2 +- .../org/mapstruct/ap/test/collection/StringHolderToLongMap.java | 2 +- .../src/test/java/org/mapstruct/ap/test/collection/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/collection/TestList.java | 2 +- .../src/test/java/org/mapstruct/ap/test/collection/TestMap.java | 2 +- .../java/org/mapstruct/ap/test/collection/adder/AdderTest.java | 2 +- .../org/mapstruct/ap/test/collection/adder/CatException.java | 2 +- .../org/mapstruct/ap/test/collection/adder/DogException.java | 2 +- .../java/org/mapstruct/ap/test/collection/adder/PetMapper.java | 2 +- .../ap/test/collection/adder/Source2Target2Mapper.java | 2 +- .../mapstruct/ap/test/collection/adder/SourceTargetMapper.java | 2 +- .../collection/adder/SourceTargetMapperStrategyDefault.java | 2 +- .../adder/SourceTargetMapperStrategySetterPreferred.java | 2 +- .../org/mapstruct/ap/test/collection/adder/TeethMapper.java | 2 +- .../ap/test/collection/adder/_target/AdderUsageObserver.java | 2 +- .../mapstruct/ap/test/collection/adder/_target/IndoorPet.java | 2 +- .../mapstruct/ap/test/collection/adder/_target/OutdoorPet.java | 2 +- .../org/mapstruct/ap/test/collection/adder/_target/Pet.java | 2 +- .../org/mapstruct/ap/test/collection/adder/_target/Target.java | 2 +- .../org/mapstruct/ap/test/collection/adder/_target/Target2.java | 2 +- .../mapstruct/ap/test/collection/adder/_target/TargetDali.java | 2 +- .../mapstruct/ap/test/collection/adder/_target/TargetHuman.java | 2 +- .../ap/test/collection/adder/_target/TargetOnlyGetter.java | 2 +- .../ap/test/collection/adder/_target/TargetViaTargetType.java | 2 +- .../ap/test/collection/adder/_target/TargetWithoutSetter.java | 2 +- .../java/org/mapstruct/ap/test/collection/adder/source/Foo.java | 2 +- .../ap/test/collection/adder/source/SingleElementSource.java | 2 +- .../org/mapstruct/ap/test/collection/adder/source/Source.java | 2 +- .../org/mapstruct/ap/test/collection/adder/source/Source2.java | 2 +- .../mapstruct/ap/test/collection/adder/source/SourceTeeth.java | 2 +- .../DefaultCollectionImplementationTest.java | 2 +- .../defaultimplementation/NoSetterCollectionMappingTest.java | 2 +- .../test/collection/defaultimplementation/NoSetterMapper.java | 2 +- .../test/collection/defaultimplementation/NoSetterSource.java | 2 +- .../test/collection/defaultimplementation/NoSetterTarget.java | 2 +- .../ap/test/collection/defaultimplementation/Source.java | 2 +- .../ap/test/collection/defaultimplementation/SourceFoo.java | 2 +- .../collection/defaultimplementation/SourceTargetMapper.java | 2 +- .../ap/test/collection/defaultimplementation/Target.java | 2 +- .../ap/test/collection/defaultimplementation/TargetFoo.java | 2 +- .../test/collection/erroneous/EmptyItererableMappingMapper.java | 2 +- .../ap/test/collection/erroneous/EmptyMapMappingMapper.java | 2 +- .../collection/erroneous/ErroneousCollectionMappingTest.java | 2 +- .../erroneous/ErroneousCollectionNoElementMappingFound.java | 2 +- .../erroneous/ErroneousCollectionNoKeyMappingFound.java | 2 +- .../erroneous/ErroneousCollectionNoValueMappingFound.java | 2 +- .../erroneous/ErroneousCollectionToNonCollectionMapper.java | 2 +- .../erroneous/ErroneousCollectionToPrimitivePropertyMapper.java | 2 +- .../java/org/mapstruct/ap/test/collection/erroneous/Source.java | 2 +- .../java/org/mapstruct/ap/test/collection/erroneous/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/collection/forged/Bar.java | 2 +- .../mapstruct/ap/test/collection/forged/CollectionMapper.java | 2 +- .../forged/CollectionMapperNullValueMappingReturnDefault.java | 2 +- .../ap/test/collection/forged/CollectionMappingTest.java | 2 +- .../forged/ErroneousCollectionNonMappableMapMapper.java | 2 +- .../forged/ErroneousCollectionNonMappableSetMapper.java | 2 +- .../test/collection/forged/ErroneousNonMappableMapSource.java | 2 +- .../test/collection/forged/ErroneousNonMappableMapTarget.java | 2 +- .../test/collection/forged/ErroneousNonMappableSetSource.java | 2 +- .../test/collection/forged/ErroneousNonMappableSetTarget.java | 2 +- .../test/java/org/mapstruct/ap/test/collection/forged/Foo.java | 2 +- .../java/org/mapstruct/ap/test/collection/forged/Source.java | 2 +- .../java/org/mapstruct/ap/test/collection/forged/Target.java | 2 +- .../iterabletononiterable/IterableToNonIterableMappingTest.java | 2 +- .../ap/test/collection/iterabletononiterable/Source.java | 2 +- .../collection/iterabletononiterable/SourceTargetMapper.java | 2 +- .../test/collection/iterabletononiterable/StringListMapper.java | 2 +- .../ap/test/collection/iterabletononiterable/Target.java | 2 +- .../mapstruct/ap/test/collection/map/CustomNumberMapper.java | 2 +- .../org/mapstruct/ap/test/collection/map/MapMappingTest.java | 2 +- .../test/java/org/mapstruct/ap/test/collection/map/Source.java | 2 +- .../mapstruct/ap/test/collection/map/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/collection/map/Target.java | 2 +- .../mapstruct/ap/test/collection/map/other/ImportedType.java | 2 +- .../org/mapstruct/ap/test/collection/wildcard/BeanMapper.java | 2 +- .../org/mapstruct/ap/test/collection/wildcard/CunningPlan.java | 2 +- .../wildcard/ErroneousIterableExtendsBoundTargetMapper.java | 2 +- .../wildcard/ErroneousIterableSuperBoundSourceMapper.java | 2 +- .../wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java | 2 +- .../wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java | 2 +- .../ap/test/collection/wildcard/ExtendsBoundSource.java | 2 +- .../collection/wildcard/ExtendsBoundSourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/collection/wildcard/GoodIdea.java | 2 +- .../java/org/mapstruct/ap/test/collection/wildcard/Idea.java | 2 +- .../java/org/mapstruct/ap/test/collection/wildcard/Plan.java | 2 +- .../java/org/mapstruct/ap/test/collection/wildcard/Source.java | 2 +- .../test/collection/wildcard/SourceSuperBoundTargetMapper.java | 2 +- .../mapstruct/ap/test/collection/wildcard/SuperBoundTarget.java | 2 +- .../java/org/mapstruct/ap/test/collection/wildcard/Target.java | 2 +- .../org/mapstruct/ap/test/collection/wildcard/WildCardTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/complex/CarMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/complex/CarMapperTest.java | 2 +- .../test/java/org/mapstruct/ap/test/complex/_target/CarDto.java | 2 +- .../java/org/mapstruct/ap/test/complex/_target/PersonDto.java | 2 +- .../java/org/mapstruct/ap/test/complex/other/DateMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/complex/source/Car.java | 2 +- .../java/org/mapstruct/ap/test/complex/source/Category.java | 2 +- .../test/java/org/mapstruct/ap/test/complex/source/Person.java | 2 +- .../java/org/mapstruct/ap/test/conversion/ConversionTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/conversion/Source.java | 2 +- .../org/mapstruct/ap/test/conversion/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/conversion/Target.java | 2 +- .../ap/test/conversion/bignumbers/BigDecimalMapper.java | 2 +- .../ap/test/conversion/bignumbers/BigDecimalSource.java | 2 +- .../ap/test/conversion/bignumbers/BigDecimalTarget.java | 2 +- .../ap/test/conversion/bignumbers/BigIntegerMapper.java | 2 +- .../ap/test/conversion/bignumbers/BigIntegerSource.java | 2 +- .../ap/test/conversion/bignumbers/BigIntegerTarget.java | 2 +- .../ap/test/conversion/bignumbers/BigNumbersConversionTest.java | 2 +- .../mapstruct/ap/test/conversion/date/DateConversionTest.java | 2 +- .../test/java/org/mapstruct/ap/test/conversion/date/Source.java | 2 +- .../mapstruct/ap/test/conversion/date/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/conversion/date/Target.java | 2 +- .../ap/test/conversion/java8time/Java8TimeConversionTest.java | 2 +- .../LocalDateToXMLGregorianCalendarConversionTest.java | 2 +- .../java/org/mapstruct/ap/test/conversion/java8time/Source.java | 2 +- .../ap/test/conversion/java8time/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/conversion/java8time/Target.java | 2 +- .../localdatetoxmlgregoriancalendarconversion/Source.java | 2 +- .../SourceTargetMapper.java | 2 +- .../localdatetoxmlgregoriancalendarconversion/Target.java | 2 +- .../ap/test/conversion/jodatime/JodaConversionTest.java | 2 +- .../java/org/mapstruct/ap/test/conversion/jodatime/Source.java | 2 +- .../ap/test/conversion/jodatime/SourceTargetMapper.java | 2 +- .../ap/test/conversion/jodatime/SourceWithStringDate.java | 2 +- .../ap/test/conversion/jodatime/StringToLocalDateMapper.java | 2 +- .../java/org/mapstruct/ap/test/conversion/jodatime/Target.java | 2 +- .../ap/test/conversion/jodatime/TargetWithLocalDate.java | 2 +- .../ap/test/conversion/nativetypes/BooleanConversionTest.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/BooleanMapper.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/BooleanSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/BooleanTarget.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/ByteSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/ByteTarget.java | 2 +- .../ap/test/conversion/nativetypes/ByteWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/ByteWrapperTarget.java | 2 +- .../ap/test/conversion/nativetypes/CharConversionTest.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/CharMapper.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/CharSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/CharTarget.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/DoubleSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/DoubleTarget.java | 2 +- .../ap/test/conversion/nativetypes/DoubleWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/DoubleWrapperTarget.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/FloatSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/FloatTarget.java | 2 +- .../ap/test/conversion/nativetypes/FloatWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/FloatWrapperTarget.java | 2 +- .../org/mapstruct/ap/test/conversion/nativetypes/IntSource.java | 2 +- .../org/mapstruct/ap/test/conversion/nativetypes/IntTarget.java | 2 +- .../ap/test/conversion/nativetypes/IntWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/IntWrapperTarget.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/LongSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/LongTarget.java | 2 +- .../ap/test/conversion/nativetypes/LongWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/LongWrapperTarget.java | 2 +- .../ap/test/conversion/nativetypes/NumberConversionTest.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/ShortSource.java | 2 +- .../mapstruct/ap/test/conversion/nativetypes/ShortTarget.java | 2 +- .../ap/test/conversion/nativetypes/ShortWrapperSource.java | 2 +- .../ap/test/conversion/nativetypes/ShortWrapperTarget.java | 2 +- .../ap/test/conversion/nativetypes/SourceTargetMapper.java | 2 +- .../ap/test/conversion/numbers/NumberFormatConversionTest.java | 2 +- .../java/org/mapstruct/ap/test/conversion/numbers/Source.java | 2 +- .../ap/test/conversion/numbers/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/conversion/numbers/Target.java | 2 +- .../mapstruct/ap/test/conversion/precedence/ConversionTest.java | 2 +- .../ap/test/conversion/precedence/IntegerStringMapper.java | 2 +- .../org/mapstruct/ap/test/conversion/precedence/Source.java | 2 +- .../ap/test/conversion/precedence/SourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/conversion/precedence/Target.java | 2 +- .../java/org/mapstruct/ap/test/conversion/string/Source.java | 2 +- .../mapstruct/ap/test/conversion/string/SourceTargetMapper.java | 2 +- .../ap/test/conversion/string/StringConversionTest.java | 2 +- .../java/org/mapstruct/ap/test/conversion/string/Target.java | 2 +- .../src/test/java/org/mapstruct/ap/test/decorator/Address.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/AddressDto.java | 2 +- .../org/mapstruct/ap/test/decorator/AnotherPersonMapper.java | 2 +- .../ap/test/decorator/AnotherPersonMapperDecorator.java | 2 +- .../java/org/mapstruct/ap/test/decorator/DecoratorTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/decorator/Employer.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/EmployerDto.java | 2 +- .../java/org/mapstruct/ap/test/decorator/EmployerMapper.java | 2 +- .../org/mapstruct/ap/test/decorator/ErroneousPersonMapper.java | 2 +- .../ap/test/decorator/ErroneousPersonMapperDecorator.java | 2 +- .../src/test/java/org/mapstruct/ap/test/decorator/Person.java | 2 +- .../src/test/java/org/mapstruct/ap/test/decorator/Person2.java | 2 +- .../java/org/mapstruct/ap/test/decorator/Person2Mapper.java | 2 +- .../org/mapstruct/ap/test/decorator/Person2MapperDecorator.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/PersonDto.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/PersonDto2.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/PersonMapper.java | 2 +- .../org/mapstruct/ap/test/decorator/PersonMapperDecorator.java | 2 +- .../test/java/org/mapstruct/ap/test/decorator/SportsClub.java | 2 +- .../java/org/mapstruct/ap/test/decorator/SportsClubDto.java | 2 +- .../org/mapstruct/ap/test/decorator/YetAnotherPersonMapper.java | 2 +- .../ap/test/decorator/YetAnotherPersonMapperDecorator.java | 2 +- .../mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java | 2 +- .../org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java | 2 +- .../ap/test/decorator/jsr330/PersonMapperDecorator.java | 2 +- .../org/mapstruct/ap/test/decorator/spring/PersonMapper.java | 2 +- .../ap/test/decorator/spring/PersonMapperDecorator.java | 2 +- .../mapstruct/ap/test/decorator/spring/SpringDecoratorTest.java | 2 +- .../java/org/mapstruct/ap/test/defaultvalue/CountryDts.java | 2 +- .../java/org/mapstruct/ap/test/defaultvalue/CountryEntity.java | 2 +- .../java/org/mapstruct/ap/test/defaultvalue/CountryMapper.java | 2 +- .../org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java | 2 +- .../org/mapstruct/ap/test/defaultvalue/ErroneousMapper.java | 2 +- .../org/mapstruct/ap/test/defaultvalue/ErroneousMapper2.java | 2 +- .../test/java/org/mapstruct/ap/test/defaultvalue/Region.java | 2 +- .../org/mapstruct/ap/test/defaultvalue/other/Continent.java | 2 +- .../src/test/java/org/mapstruct/ap/test/dependency/Address.java | 2 +- .../test/java/org/mapstruct/ap/test/dependency/AddressDto.java | 2 +- .../java/org/mapstruct/ap/test/dependency/AddressMapper.java | 2 +- .../dependency/ErroneousAddressMapperWithCyclicDependency.java | 2 +- .../ErroneousAddressMapperWithUnknownPropertyInDependsOn.java | 2 +- .../org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java | 2 +- .../java/org/mapstruct/ap/test/dependency/OrderingTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/dependency/Person.java | 2 +- .../test/java/org/mapstruct/ap/test/dependency/PersonDto.java | 2 +- .../ap/test/destination/AbstractDestinationClassNameMapper.java | 2 +- .../test/destination/AbstractDestinationPackageNameMapper.java | 2 +- .../ap/test/destination/DestinationClassNameMapper.java | 2 +- .../ap/test/destination/DestinationClassNameMapperConfig.java | 2 +- .../test/destination/DestinationClassNameMapperDecorated.java | 2 +- .../test/destination/DestinationClassNameMapperDecorator.java | 2 +- .../test/destination/DestinationClassNameMapperWithConfig.java | 2 +- .../DestinationClassNameMapperWithConfigOverride.java | 2 +- .../mapstruct/ap/test/destination/DestinationClassNameTest.java | 2 +- .../test/destination/DestinationClassNameWithJsr330Mapper.java | 2 +- .../ap/test/destination/DestinationPackageNameMapper.java | 2 +- .../ap/test/destination/DestinationPackageNameMapperConfig.java | 2 +- .../test/destination/DestinationPackageNameMapperDecorated.java | 2 +- .../test/destination/DestinationPackageNameMapperDecorator.java | 2 +- .../destination/DestinationPackageNameMapperWithConfig.java | 2 +- .../DestinationPackageNameMapperWithConfigOverride.java | 2 +- .../destination/DestinationPackageNameMapperWithSuffix.java | 2 +- .../ap/test/destination/DestinationPackageNameTest.java | 2 +- .../test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java | 2 +- .../enums/ErroneousOrderMapperMappingSameConstantTwice.java | 2 +- ...usOrderMapperNotMappingConstantWithoutMatchInTargetType.java | 2 +- .../enums/ErroneousOrderMapperUsingUnknownEnumConstants.java | 2 +- .../java/org/mapstruct/ap/test/enums/ExternalOrderType.java | 2 +- .../src/test/java/org/mapstruct/ap/test/enums/OrderDto.java | 2 +- .../src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java | 2 +- .../src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/enums/OrderType.java | 2 +- .../mapstruct/ap/test/erroneous/ambiguousfactorymethod/Bar.java | 2 +- .../ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java | 2 +- .../mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java | 2 +- .../ap/test/erroneous/ambiguousfactorymethod/Source.java | 2 +- .../ambiguousfactorymethod/SourceTargetMapperAndBarFactory.java | 2 +- .../ap/test/erroneous/ambiguousfactorymethod/Target.java | 2 +- .../ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java | 2 +- .../erroneous/annotationnotfound/AnnotationNotFoundTest.java | 2 +- .../ap/test/erroneous/annotationnotfound/ErroneousMapper.java | 2 +- .../test/erroneous/annotationnotfound/NotFoundAnnotation.java | 2 +- .../mapstruct/ap/test/erroneous/annotationnotfound/Source.java | 2 +- .../mapstruct/ap/test/erroneous/annotationnotfound/Target.java | 2 +- .../ap/test/erroneous/attributereference/AnotherTarget.java | 2 +- .../ap/test/erroneous/attributereference/DummySource.java | 2 +- .../ap/test/erroneous/attributereference/ErroneousMapper.java | 2 +- .../ap/test/erroneous/attributereference/ErroneousMapper1.java | 2 +- .../ap/test/erroneous/attributereference/ErroneousMapper2.java | 2 +- .../erroneous/attributereference/ErroneousMappingsTest.java | 2 +- .../mapstruct/ap/test/erroneous/attributereference/Source.java | 2 +- .../mapstruct/ap/test/erroneous/attributereference/Target.java | 2 +- .../ap/test/erroneous/typemismatch/ErroneousMapper.java | 2 +- .../ap/test/erroneous/typemismatch/ErroneousMappingsTest.java | 2 +- .../org/mapstruct/ap/test/erroneous/typemismatch/Source.java | 2 +- .../org/mapstruct/ap/test/erroneous/typemismatch/Target.java | 2 +- .../java/org/mapstruct/ap/test/exceptions/ExceptionTest.java | 2 +- .../mapstruct/ap/test/exceptions/ExceptionTestDecorator.java | 2 +- .../org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/exceptions/Source.java | 2 +- .../org/mapstruct/ap/test/exceptions/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/exceptions/Target.java | 2 +- .../java/org/mapstruct/ap/test/exceptions/TestException2.java | 2 +- .../mapstruct/ap/test/exceptions/imports/TestException1.java | 2 +- .../mapstruct/ap/test/exceptions/imports/TestExceptionBase.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Bar1.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Bar2.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Bar3.java | 2 +- .../test/java/org/mapstruct/ap/test/factories/CustomList.java | 2 +- .../java/org/mapstruct/ap/test/factories/CustomListImpl.java | 2 +- .../test/java/org/mapstruct/ap/test/factories/CustomMap.java | 2 +- .../java/org/mapstruct/ap/test/factories/CustomMapImpl.java | 2 +- .../java/org/mapstruct/ap/test/factories/FactoryCreatable.java | 2 +- .../test/java/org/mapstruct/ap/test/factories/FactoryTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Foo1.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Foo2.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Foo3.java | 2 +- .../java/org/mapstruct/ap/test/factories/GenericFactory.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Source.java | 2 +- .../ap/test/factories/SourceTargetMapperAndBar2Factory.java | 2 +- .../ap/test/factories/SourceTargetMapperWithGenericFactory.java | 2 +- .../src/test/java/org/mapstruct/ap/test/factories/Target.java | 2 +- .../test/java/org/mapstruct/ap/test/factories/a/BarFactory.java | 2 +- .../test/java/org/mapstruct/ap/test/factories/b/BarFactory.java | 2 +- .../org/mapstruct/ap/test/generics/AbstractIdHoldingTo.java | 2 +- .../test/java/org/mapstruct/ap/test/generics/AbstractTo.java | 2 +- .../test/java/org/mapstruct/ap/test/generics/GenericsTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/generics/Source.java | 2 +- .../java/org/mapstruct/ap/test/generics/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/generics/TargetTo.java | 2 +- .../mapstruct/ap/test/generics/genericsupertype/MapperBase.java | 2 +- .../genericsupertype/MapperWithGenericSuperClassTest.java | 2 +- .../ap/test/generics/genericsupertype/SearchResult.java | 2 +- .../org/mapstruct/ap/test/generics/genericsupertype/Vessel.java | 2 +- .../mapstruct/ap/test/generics/genericsupertype/VesselDto.java | 2 +- .../generics/genericsupertype/VesselSearchResultMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/ignore/Animal.java | 2 +- .../src/test/java/org/mapstruct/ap/test/ignore/AnimalDto.java | 2 +- .../test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java | 2 +- .../ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java | 2 +- .../java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/ignore/Preditor.java | 2 +- .../src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java | 2 +- .../mapstruct/ap/test/imports/ConflictingTypesNamesTest.java | 2 +- .../org/mapstruct/ap/test/imports/InnerClassesImportsTest.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/imports/List.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/imports/Map.java | 2 +- .../src/test/java/org/mapstruct/ap/test/imports/Named.java | 2 +- .../test/java/org/mapstruct/ap/test/imports/ParseException.java | 2 +- .../org/mapstruct/ap/test/imports/SecondSourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/imports/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/imports/decorator/Actor.java | 2 +- .../java/org/mapstruct/ap/test/imports/decorator/ActorDto.java | 2 +- .../org/mapstruct/ap/test/imports/decorator/ActorMapper.java | 2 +- .../test/imports/decorator/DecoratorInAnotherPackageTest.java | 2 +- .../ap/test/imports/decorator/other/ActorMapperDecorator.java | 2 +- .../src/test/java/org/mapstruct/ap/test/imports/from/Foo.java | 2 +- .../java/org/mapstruct/ap/test/imports/from/FooWrapper.java | 2 +- .../org/mapstruct/ap/test/imports/innerclasses/BeanFacade.java | 2 +- .../ap/test/imports/innerclasses/BeanWithInnerEnum.java | 2 +- .../ap/test/imports/innerclasses/BeanWithInnerEnumMapper.java | 2 +- .../ap/test/imports/innerclasses/InnerClassMapper.java | 2 +- .../ap/test/imports/innerclasses/SourceWithInnerClass.java | 2 +- .../ap/test/imports/innerclasses/TargetWithInnerClass.java | 2 +- .../org/mapstruct/ap/test/imports/referenced/GenericMapper.java | 2 +- .../ap/test/imports/referenced/NotImportedDatatype.java | 2 +- .../java/org/mapstruct/ap/test/imports/referenced/Source.java | 2 +- .../java/org/mapstruct/ap/test/imports/referenced/Target.java | 2 +- .../SourceTypeContainsCollectionWithExtendsBoundTest.java | 2 +- .../ap/test/imports/sourcewithextendsbound/SpaceshipMapper.java | 2 +- .../sourcewithextendsbound/astronautmapper/AstronautMapper.java | 2 +- .../test/imports/sourcewithextendsbound/dto/AstronautDto.java | 2 +- .../test/imports/sourcewithextendsbound/dto/SpaceshipDto.java | 2 +- .../test/imports/sourcewithextendsbound/entity/Astronaut.java | 2 +- .../test/imports/sourcewithextendsbound/entity/Spaceship.java | 2 +- .../src/test/java/org/mapstruct/ap/test/imports/to/Foo.java | 2 +- .../test/java/org/mapstruct/ap/test/imports/to/FooWrapper.java | 2 +- .../java/org/mapstruct/ap/test/inheritance/InheritanceTest.java | 2 +- .../test/java/org/mapstruct/ap/test/inheritance/SourceBase.java | 2 +- .../test/java/org/mapstruct/ap/test/inheritance/SourceExt.java | 2 +- .../org/mapstruct/ap/test/inheritance/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/inheritance/TargetBase.java | 2 +- .../test/java/org/mapstruct/ap/test/inheritance/TargetExt.java | 2 +- .../ap/test/inheritance/attribute/AttributeInheritanceTest.java | 2 +- .../test/inheritance/attribute/ErroneousTargetSourceMapper.java | 2 +- .../org/mapstruct/ap/test/inheritance/attribute/Source.java | 2 +- .../ap/test/inheritance/attribute/SourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/inheritance/attribute/Target.java | 2 +- .../ap/test/inheritance/complex/AdditionalFooSource.java | 2 +- .../ap/test/inheritance/complex/AdditionalMappingHelper.java | 2 +- .../ap/test/inheritance/complex/ComplexInheritanceTest.java | 2 +- .../complex/ErroneousSourceCompositeTargetCompositeMapper.java | 2 +- .../org/mapstruct/ap/test/inheritance/complex/Reference.java | 2 +- .../org/mapstruct/ap/test/inheritance/complex/SourceBase.java | 2 +- .../ap/test/inheritance/complex/SourceBaseMappingHelper.java | 2 +- .../mapstruct/ap/test/inheritance/complex/SourceComposite.java | 2 +- .../complex/SourceCompositeTargetCompositeMapper.java | 2 +- .../org/mapstruct/ap/test/inheritance/complex/SourceExt.java | 2 +- .../org/mapstruct/ap/test/inheritance/complex/SourceExt2.java | 2 +- .../complex/StandaloneSourceCompositeTargetCompositeMapper.java | 2 +- .../mapstruct/ap/test/inheritance/complex/TargetComposite.java | 2 +- .../mapstruct/ap/test/inheritedmappingmethod/BoundMappable.java | 2 +- .../org/mapstruct/ap/test/inheritedmappingmethod/CarMapper.java | 2 +- .../mapstruct/ap/test/inheritedmappingmethod/FastCarMapper.java | 2 +- .../test/inheritedmappingmethod/InheritedMappingMethodTest.java | 2 +- .../ap/test/inheritedmappingmethod/UnboundMappable.java | 2 +- .../ap/test/inheritedmappingmethod/_target/CarDto.java | 2 +- .../ap/test/inheritedmappingmethod/_target/FastCarDto.java | 2 +- .../mapstruct/ap/test/inheritedmappingmethod/source/Car.java | 2 +- .../ap/test/inheritedmappingmethod/source/FastCar.java | 2 +- .../ap/test/inheritfromconfig/AutoInheritedConfig.java | 2 +- .../ap/test/inheritfromconfig/AutoInheritedDriverConfig.java | 2 +- .../org/mapstruct/ap/test/inheritfromconfig/BaseVehicleDto.java | 2 +- .../mapstruct/ap/test/inheritfromconfig/BaseVehicleEntity.java | 2 +- .../java/org/mapstruct/ap/test/inheritfromconfig/CarDto.java | 2 +- .../java/org/mapstruct/ap/test/inheritfromconfig/CarEntity.java | 2 +- .../ap/test/inheritfromconfig/CarMapperWithAutoInheritance.java | 2 +- .../inheritfromconfig/CarMapperWithExplicitInheritance.java | 2 +- .../ap/test/inheritfromconfig/CarWithDriverEntity.java | 2 +- .../CarWithDriverMapperWithAutoInheritance.java | 2 +- .../java/org/mapstruct/ap/test/inheritfromconfig/DriverDto.java | 2 +- .../mapstruct/ap/test/inheritfromconfig/Erroneous1Config.java | 2 +- .../mapstruct/ap/test/inheritfromconfig/Erroneous1Mapper.java | 2 +- .../mapstruct/ap/test/inheritfromconfig/Erroneous2Mapper.java | 2 +- .../ap/test/inheritfromconfig/InheritFromConfigTest.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/BarDto.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/BarEntity.java | 2 +- .../java/org/mapstruct/ap/test/mapperconfig/CentralConfig.java | 2 +- .../java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java | 2 +- .../mapstruct/ap/test/mapperconfig/CustomMapperViaMapper.java | 2 +- .../ap/test/mapperconfig/CustomMapperViaMapperConfig.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/FooDto.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/FooEntity.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/Source.java | 2 +- .../org/mapstruct/ap/test/mapperconfig/SourceTargetMapper.java | 2 +- .../ap/test/mapperconfig/SourceTargetMapperErroneous.java | 2 +- .../mapstruct/ap/test/mapperconfig/SourceTargetMapperWarn.java | 2 +- .../test/java/org/mapstruct/ap/test/mapperconfig/Target.java | 2 +- .../java/org/mapstruct/ap/test/mapperconfig/TargetNoFoo.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/naming/Break.java | 2 +- .../src/test/java/org/mapstruct/ap/test/naming/Source.java | 2 +- .../java/org/mapstruct/ap/test/naming/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/naming/VariableNamingTest.java | 2 +- processor/src/test/java/org/mapstruct/ap/test/naming/While.java | 2 +- .../ap/test/naming/spi/CustomAccessorNamingStrategy.java | 2 +- .../mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java | 2 +- .../test/java/org/mapstruct/ap/test/naming/spi/GolfPlayer.java | 2 +- .../java/org/mapstruct/ap/test/naming/spi/GolfPlayerDto.java | 2 +- .../java/org/mapstruct/ap/test/naming/spi/GolfPlayerMapper.java | 2 +- .../nestedmethodcall/NestedMappingMethodInvocationTest.java | 2 +- .../org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java | 2 +- .../org/mapstruct/ap/test/nestedmethodcall/OrderDetailsDto.java | 2 +- .../mapstruct/ap/test/nestedmethodcall/OrderDetailsType.java | 2 +- .../java/org/mapstruct/ap/test/nestedmethodcall/OrderDto.java | 2 +- .../java/org/mapstruct/ap/test/nestedmethodcall/OrderType.java | 2 +- .../ap/test/nestedmethodcall/OrderTypeToOrderDtoMapper.java | 2 +- .../java/org/mapstruct/ap/test/nestedmethodcall/SourceType.java | 2 +- .../ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java | 2 +- .../java/org/mapstruct/ap/test/nestedmethodcall/TargetDto.java | 2 +- .../mapstruct/ap/test/nestedproperties/simple/SimpleMapper.java | 2 +- .../nestedproperties/simple/SimpleNestedPropertiesTest.java | 2 +- .../ap/test/nestedproperties/simple/_target/TargetObject.java | 2 +- .../ap/test/nestedproperties/simple/source/SourceProps.java | 2 +- .../ap/test/nestedproperties/simple/source/SourceRoot.java | 2 +- .../org/mapstruct/ap/test/nestedsource/parameter/FontDto.java | 2 +- .../org/mapstruct/ap/test/nestedsource/parameter/LetterDto.java | 2 +- .../mapstruct/ap/test/nestedsource/parameter/LetterEntity.java | 2 +- .../mapstruct/ap/test/nestedsource/parameter/LetterMapper.java | 2 +- .../ap/test/nestedsource/parameter/NormalizingTest.java | 2 +- .../ap/test/nestedsourceproperties/ArtistToChartEntry.java | 2 +- .../ap/test/nestedsourceproperties/ArtistToChartEntryAdder.java | 2 +- .../ArtistToChartEntryComposedReverse.java | 2 +- .../test/nestedsourceproperties/ArtistToChartEntryConfig.java | 2 +- .../nestedsourceproperties/ArtistToChartEntryErroneous.java | 2 +- .../test/nestedsourceproperties/ArtistToChartEntryGetter.java | 2 +- .../test/nestedsourceproperties/ArtistToChartEntryReverse.java | 2 +- .../nestedsourceproperties/ArtistToChartEntryUpdateReverse.java | 2 +- .../ArtistToChartEntryWithConfigReverse.java | 2 +- .../ArtistToChartEntryWithFactoryReverse.java | 2 +- .../ArtistToChartEntryWithIgnoresReverse.java | 2 +- .../ArtistToChartEntryWithMappingReverse.java | 2 +- .../test/nestedsourceproperties/NestedSourcePropertiesTest.java | 2 +- .../ReversingNestedSourcePropertiesTest.java | 2 +- .../test/nestedsourceproperties/_target/AdderUsageObserver.java | 2 +- .../ap/test/nestedsourceproperties/_target/BaseChartEntry.java | 2 +- .../ap/test/nestedsourceproperties/_target/ChartEntry.java | 2 +- .../test/nestedsourceproperties/_target/ChartEntryComposed.java | 2 +- .../ap/test/nestedsourceproperties/_target/ChartEntryLabel.java | 2 +- .../test/nestedsourceproperties/_target/ChartEntryWithBase.java | 2 +- .../nestedsourceproperties/_target/ChartEntryWithMapping.java | 2 +- .../ap/test/nestedsourceproperties/_target/ChartPositions.java | 2 +- .../mapstruct/ap/test/nestedsourceproperties/source/Artist.java | 2 +- .../mapstruct/ap/test/nestedsourceproperties/source/Chart.java | 2 +- .../mapstruct/ap/test/nestedsourceproperties/source/Label.java | 2 +- .../mapstruct/ap/test/nestedsourceproperties/source/Song.java | 2 +- .../ap/test/nestedsourceproperties/source/SourceDtoFactory.java | 2 +- .../mapstruct/ap/test/nestedsourceproperties/source/Studio.java | 2 +- .../ap/test/nestedtargetproperties/ChartEntryToArtist.java | 2 +- .../test/nestedtargetproperties/NestedTargetPropertiesTest.java | 2 +- .../test/java/org/mapstruct/ap/test/nonvoidsetter/Actor.java | 2 +- .../test/java/org/mapstruct/ap/test/nonvoidsetter/ActorDto.java | 2 +- .../java/org/mapstruct/ap/test/nonvoidsetter/ActorMapper.java | 2 +- .../org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java | 2 +- .../test/java/org/mapstruct/ap/test/nullcheck/CustomMapper.java | 2 +- .../java/org/mapstruct/ap/test/nullcheck/MyBigIntWrapper.java | 2 +- .../java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java | 2 +- .../java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java | 2 +- .../test/java/org/mapstruct/ap/test/nullcheck/NullObject.java | 2 +- .../java/org/mapstruct/ap/test/nullcheck/NullObjectMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/nullcheck/Source.java | 2 +- .../org/mapstruct/ap/test/nullcheck/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/nullcheck/Target.java | 2 +- .../java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java | 2 +- .../ap/test/nullvaluemapping/CarMapperSettingOnConfig.java | 2 +- .../ap/test/nullvaluemapping/CarMapperSettingOnMapper.java | 2 +- .../org/mapstruct/ap/test/nullvaluemapping/CentralConfig.java | 2 +- .../ap/test/nullvaluemapping/NullValueMappingTest.java | 2 +- .../org/mapstruct/ap/test/nullvaluemapping/_target/CarDto.java | 2 +- .../ap/test/nullvaluemapping/_target/DriverAndCarDto.java | 2 +- .../java/org/mapstruct/ap/test/nullvaluemapping/source/Car.java | 2 +- .../org/mapstruct/ap/test/nullvaluemapping/source/Driver.java | 2 +- .../src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/oneway/Source.java | 2 +- .../java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/oneway/Target.java | 2 +- .../src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java | 2 +- .../test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/references/Bar.java | 2 +- .../test/java/org/mapstruct/ap/test/references/BaseType.java | 2 +- .../src/test/java/org/mapstruct/ap/test/references/Foo.java | 2 +- .../test/java/org/mapstruct/ap/test/references/FooMapper.java | 2 +- .../java/org/mapstruct/ap/test/references/GenericWrapper.java | 2 +- .../mapstruct/ap/test/references/ReferencedCustomMapper.java | 2 +- .../org/mapstruct/ap/test/references/ReferencedMapperTest.java | 2 +- .../java/org/mapstruct/ap/test/references/SomeOtherType.java | 2 +- .../test/java/org/mapstruct/ap/test/references/SomeType.java | 2 +- .../src/test/java/org/mapstruct/ap/test/references/Source.java | 2 +- .../org/mapstruct/ap/test/references/SourceTargetMapper.java | 2 +- .../ap/test/references/SourceTargetMapperWithPrimitives.java | 2 +- .../org/mapstruct/ap/test/references/SourceWithWrappers.java | 2 +- .../src/test/java/org/mapstruct/ap/test/references/Target.java | 2 +- .../org/mapstruct/ap/test/references/TargetWithPrimitives.java | 2 +- .../ap/test/references/samename/Jsr330SourceTargetMapper.java | 2 +- .../SeveralReferencedMappersWithSameSimpleNameTest.java | 2 +- .../ap/test/references/samename/SourceTargetMapper.java | 2 +- .../test/references/samename/a/AnotherSourceTargetMapper.java | 2 +- .../mapstruct/ap/test/references/samename/a/CustomMapper.java | 2 +- .../mapstruct/ap/test/references/samename/b/CustomMapper.java | 2 +- .../org/mapstruct/ap/test/references/samename/model/Source.java | 2 +- .../org/mapstruct/ap/test/references/samename/model/Target.java | 2 +- .../java/org/mapstruct/ap/test/references/statics/Beer.java | 2 +- .../java/org/mapstruct/ap/test/references/statics/BeerDto.java | 2 +- .../org/mapstruct/ap/test/references/statics/BeerMapper.java | 2 +- .../ap/test/references/statics/BeerMapperWithNonUsedMapper.java | 2 +- .../java/org/mapstruct/ap/test/references/statics/Category.java | 2 +- .../org/mapstruct/ap/test/references/statics/CustomMapper.java | 2 +- .../org/mapstruct/ap/test/references/statics/StaticsTest.java | 2 +- .../ap/test/references/statics/nonused/NonUsedMapper.java | 2 +- .../ap/test/reverse/InheritInverseConfigurationTest.java | 2 +- .../src/test/java/org/mapstruct/ap/test/reverse/Source.java | 2 +- .../java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/reverse/Target.java | 2 +- .../ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java | 2 +- .../ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java | 2 +- .../ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java | 2 +- .../reverse/erroneous/SourceTargetMapperNonMatchingName.java | 2 +- .../org/mapstruct/ap/test/selection/generics/ArrayWrapper.java | 2 +- .../mapstruct/ap/test/selection/generics/ConversionTest.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource1.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource2.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource3.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource4.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource5.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousSource6.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper1.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper2.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper3.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper4.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper5.java | 2 +- .../test/selection/generics/ErroneousSourceTargetMapper6.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget1.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget2.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget3.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget4.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget5.java | 2 +- .../mapstruct/ap/test/selection/generics/ErroneousTarget6.java | 2 +- .../mapstruct/ap/test/selection/generics/GenericTypeMapper.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/Source.java | 2 +- .../ap/test/selection/generics/SourceTargetMapper.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/Target.java | 2 +- .../org/mapstruct/ap/test/selection/generics/TwoArgHolder.java | 2 +- .../org/mapstruct/ap/test/selection/generics/TwoArgWrapper.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/TypeA.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/TypeB.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/TypeC.java | 2 +- .../mapstruct/ap/test/selection/generics/UpperBoundWrapper.java | 2 +- .../ap/test/selection/generics/WildCardExtendsMBWrapper.java | 2 +- .../ap/test/selection/generics/WildCardExtendsWrapper.java | 2 +- .../ap/test/selection/generics/WildCardSuperWrapper.java | 2 +- .../java/org/mapstruct/ap/test/selection/generics/Wrapper.java | 2 +- .../ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java | 2 +- .../java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java | 2 +- .../java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java | 2 +- .../ap/test/selection/jaxb/OrderShippingDetailsDto.java | 2 +- .../ap/test/selection/jaxb/UnderscoreSelectionTest.java | 2 +- .../mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java | 2 +- .../org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java | 2 +- .../mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java | 2 +- .../ap/test/selection/jaxb/test2/OrderShippingDetailsType.java | 2 +- .../ap/test/selection/jaxb/underscores/ObjectFactory.java | 2 +- .../mapstruct/ap/test/selection/jaxb/underscores/SubType.java | 2 +- .../mapstruct/ap/test/selection/jaxb/underscores/SuperType.java | 2 +- .../ap/test/selection/jaxb/underscores/UnderscoreMapper.java | 2 +- .../ap/test/selection/jaxb/underscores/UnderscoreType.java | 2 +- .../java/org/mapstruct/ap/test/selection/primitives/MyLong.java | 2 +- .../mapstruct/ap/test/selection/primitives/PrimitiveMapper.java | 2 +- .../selection/primitives/PrimitiveVsWrappedSelectionTest.java | 2 +- .../java/org/mapstruct/ap/test/selection/primitives/Source.java | 2 +- .../ap/test/selection/primitives/SourceTargetMapper.java | 2 +- .../test/selection/primitives/SourceTargetMapperPrimitive.java | 2 +- .../ap/test/selection/primitives/SourceTargetMapperWrapped.java | 2 +- .../java/org/mapstruct/ap/test/selection/primitives/Target.java | 2 +- .../mapstruct/ap/test/selection/primitives/WrappedMapper.java | 2 +- .../mapstruct/ap/test/selection/qualifier/ErroneousMapper.java | 2 +- .../test/selection/qualifier/ErroneousMovieFactoryMapper.java | 2 +- .../org/mapstruct/ap/test/selection/qualifier/FactMapper.java | 2 +- .../mapstruct/ap/test/selection/qualifier/KeyWordMapper.java | 2 +- .../ap/test/selection/qualifier/MapperWithoutQualifiedBy.java | 2 +- .../ap/test/selection/qualifier/MovieFactoryMapper.java | 2 +- .../org/mapstruct/ap/test/selection/qualifier/MovieMapper.java | 2 +- .../mapstruct/ap/test/selection/qualifier/QualifierTest.java | 2 +- .../selection/qualifier/annotation/CreateGermanRelease.java | 2 +- .../ap/test/selection/qualifier/annotation/EnglishToGerman.java | 2 +- .../selection/qualifier/annotation/NonQualifierAnnotated.java | 2 +- .../ap/test/selection/qualifier/annotation/TitleTranslator.java | 2 +- .../ap/test/selection/qualifier/bean/AbstractEntry.java | 2 +- .../ap/test/selection/qualifier/bean/GermanRelease.java | 2 +- .../ap/test/selection/qualifier/bean/OriginalRelease.java | 2 +- .../ap/test/selection/qualifier/bean/ReleaseFactory.java | 2 +- .../ap/test/selection/qualifier/handwritten/Facts.java | 2 +- .../ap/test/selection/qualifier/handwritten/PlotWords.java | 2 +- .../ap/test/selection/qualifier/handwritten/Reverse.java | 2 +- .../test/selection/qualifier/handwritten/SomeOtherMapper.java | 2 +- .../ap/test/selection/qualifier/handwritten/Titles.java | 2 +- .../test/selection/qualifier/handwritten/YetAnotherMapper.java | 2 +- .../ap/test/selection/qualifier/hybrid/HybridTest.java | 2 +- .../ap/test/selection/qualifier/hybrid/ReleaseMapper.java | 2 +- .../ap/test/selection/qualifier/hybrid/SourceRelease.java | 2 +- .../ap/test/selection/qualifier/hybrid/TargetRelease.java | 2 +- .../mapstruct/ap/test/selection/qualifier/iterable/CityDto.java | 2 +- .../ap/test/selection/qualifier/iterable/CityEntity.java | 2 +- .../selection/qualifier/iterable/IterableAndQualifiersTest.java | 2 +- .../ap/test/selection/qualifier/iterable/RiverDto.java | 2 +- .../ap/test/selection/qualifier/iterable/RiverEntity.java | 2 +- .../ap/test/selection/qualifier/iterable/TopologyDto.java | 2 +- .../ap/test/selection/qualifier/iterable/TopologyEntity.java | 2 +- .../test/selection/qualifier/iterable/TopologyFeatureDto.java | 2 +- .../selection/qualifier/iterable/TopologyFeatureEntity.java | 2 +- .../ap/test/selection/qualifier/iterable/TopologyMapper.java | 2 +- .../ap/test/selection/qualifier/named/ErroneousMapper.java | 2 +- .../mapstruct/ap/test/selection/qualifier/named/FactMapper.java | 2 +- .../ap/test/selection/qualifier/named/KeyWordMapper.java | 2 +- .../ap/test/selection/qualifier/named/MovieFactoryMapper.java | 2 +- .../ap/test/selection/qualifier/named/MovieMapper.java | 2 +- .../mapstruct/ap/test/selection/qualifier/named/NamedTest.java | 2 +- .../java/org/mapstruct/ap/test/selection/resulttype/Apple.java | 2 +- .../org/mapstruct/ap/test/selection/resulttype/AppleDto.java | 2 +- .../mapstruct/ap/test/selection/resulttype/AppleFactory.java | 2 +- .../org/mapstruct/ap/test/selection/resulttype/AppleFamily.java | 2 +- .../mapstruct/ap/test/selection/resulttype/AppleFamilyDto.java | 2 +- .../java/org/mapstruct/ap/test/selection/resulttype/Banana.java | 2 +- .../org/mapstruct/ap/test/selection/resulttype/BananaDto.java | 2 +- .../ap/test/selection/resulttype/ConflictingFruitFactory.java | 2 +- .../ap/test/selection/resulttype/ErroneousFruitMapper.java | 2 +- .../ap/test/selection/resulttype/ErroneousFruitMapper2.java | 2 +- .../java/org/mapstruct/ap/test/selection/resulttype/Fruit.java | 2 +- .../org/mapstruct/ap/test/selection/resulttype/FruitDto.java | 2 +- .../ap/test/selection/resulttype/FruitFamilyMapper.java | 2 +- .../mapstruct/ap/test/selection/resulttype/GoldenDelicious.java | 2 +- .../ap/test/selection/resulttype/GoldenDeliciousDto.java | 2 +- .../ap/test/selection/resulttype/InheritanceSelectionTest.java | 2 +- .../selection/resulttype/ResultTypeConstructingFruitMapper.java | 2 +- .../selection/resulttype/ResultTypeSelectingFruitMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/severalsources/Address.java | 2 +- .../org/mapstruct/ap/test/severalsources/DeliveryAddress.java | 2 +- .../ap/test/severalsources/ErroneousSourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/severalsources/Person.java | 2 +- .../org/mapstruct/ap/test/severalsources/ReferencedMapper.java | 2 +- .../ap/test/severalsources/SeveralSourceParametersTest.java | 2 +- .../mapstruct/ap/test/severalsources/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/severaltargets/Source.java | 2 +- .../test/severaltargets/SourcePropertyMapSeveralTimesTest.java | 2 +- .../mapstruct/ap/test/severaltargets/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/severaltargets/Target.java | 2 +- .../org/mapstruct/ap/test/severaltargets/TimeAndFormat.java | 2 +- .../mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java | 2 +- .../org/mapstruct/ap/test/source/constants/CountryEnum.java | 2 +- .../mapstruct/ap/test/source/constants/ErroneousMapper1.java | 2 +- .../mapstruct/ap/test/source/constants/ErroneousMapper2.java | 2 +- .../mapstruct/ap/test/source/constants/ErroneousMapper3.java | 2 +- .../mapstruct/ap/test/source/constants/ErroneousMapper4.java | 2 +- .../mapstruct/ap/test/source/constants/ErroneousMapper5.java | 2 +- .../java/org/mapstruct/ap/test/source/constants/Source.java | 2 +- .../java/org/mapstruct/ap/test/source/constants/Source1.java | 2 +- .../java/org/mapstruct/ap/test/source/constants/Source2.java | 2 +- .../mapstruct/ap/test/source/constants/SourceConstantsTest.java | 2 +- .../mapstruct/ap/test/source/constants/SourceTargetMapper.java | 2 +- .../test/source/constants/SourceTargetMapperSeveralSources.java | 2 +- .../mapstruct/ap/test/source/constants/StringListMapper.java | 2 +- .../java/org/mapstruct/ap/test/source/constants/Target.java | 2 +- .../java/org/mapstruct/ap/test/source/constants/Target2.java | 2 +- .../test/source/expressions/java/BooleanWorkAroundMapper.java | 2 +- .../ap/test/source/expressions/java/JavaExpressionTest.java | 2 +- .../org/mapstruct/ap/test/source/expressions/java/Source.java | 2 +- .../org/mapstruct/ap/test/source/expressions/java/Source2.java | 2 +- .../test/source/expressions/java/SourceBooleanWorkAround.java | 2 +- .../mapstruct/ap/test/source/expressions/java/SourceList.java | 2 +- .../ap/test/source/expressions/java/SourceTargetListMapper.java | 2 +- .../ap/test/source/expressions/java/SourceTargetMapper.java | 2 +- .../expressions/java/SourceTargetMapperSeveralSources.java | 2 +- .../org/mapstruct/ap/test/source/expressions/java/Target.java | 2 +- .../test/source/expressions/java/TargetBooleanWorkAround.java | 2 +- .../mapstruct/ap/test/source/expressions/java/TargetList.java | 2 +- .../ap/test/source/expressions/java/mapper/TimeAndFormat.java | 2 +- .../test/source/nullvaluecheckstrategy/PresenceCheckTest.java | 2 +- .../test/source/nullvaluecheckstrategy/RockFestivalMapper.java | 2 +- .../source/nullvaluecheckstrategy/RockFestivalMapperConfig.java | 2 +- .../RockFestivalMapperOveridingConfig.java | 2 +- .../nullvaluecheckstrategy/RockFestivalMapperWithConfig.java | 2 +- .../test/source/nullvaluecheckstrategy/RockFestivalSource.java | 2 +- .../test/source/nullvaluecheckstrategy/RockFestivalTarget.java | 2 +- .../mapstruct/ap/test/source/nullvaluecheckstrategy/Stage.java | 2 +- .../mapstruct/ap/test/source/presencecheck/spi/GoalKeeper.java | 2 +- .../ap/test/source/presencecheck/spi/PresenceCheckTest.java | 2 +- .../ap/test/source/presencecheck/spi/SoccerTeamMapper.java | 2 +- .../ap/test/source/presencecheck/spi/SoccerTeamSource.java | 2 +- .../ap/test/source/presencecheck/spi/SoccerTeamTarget.java | 2 +- .../org/mapstruct/ap/test/source/presencecheck/spi/Source.java | 2 +- .../ap/test/source/presencecheck/spi/SourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/source/presencecheck/spi/Target.java | 2 +- .../mapstruct/ap/test/template/InheritConfigurationTest.java | 2 +- .../test/java/org/mapstruct/ap/test/template/NestedSource.java | 2 +- .../src/test/java/org/mapstruct/ap/test/template/Source.java | 2 +- .../mapstruct/ap/test/template/SourceTargetMapperMultiple.java | 2 +- .../ap/test/template/SourceTargetMapperSeveralArgs.java | 2 +- .../mapstruct/ap/test/template/SourceTargetMapperSingle.java | 2 +- .../src/test/java/org/mapstruct/ap/test/template/Target.java | 2 +- .../test/template/erroneous/SourceTargetMapperAmbiguous1.java | 2 +- .../test/template/erroneous/SourceTargetMapperAmbiguous2.java | 2 +- .../test/template/erroneous/SourceTargetMapperAmbiguous3.java | 2 +- .../template/erroneous/SourceTargetMapperNonMatchingName.java | 2 +- .../test/unmappedtarget/ErroneousStrictSourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/unmappedtarget/Source.java | 2 +- .../mapstruct/ap/test/unmappedtarget/SourceTargetMapper.java | 2 +- .../test/java/org/mapstruct/ap/test/unmappedtarget/Target.java | 2 +- .../mapstruct/ap/test/unmappedtarget/UnmappedTargetTest.java | 2 +- .../test/java/org/mapstruct/ap/test/updatemethods/BossDto.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/BossEntity.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/CompanyDto.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/CompanyEntity.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/CompanyMapper.java | 2 +- .../ap/test/updatemethods/ConstructableDepartmentEntity.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/DepartmentDto.java | 2 +- .../org/mapstruct/ap/test/updatemethods/DepartmentEntity.java | 2 +- .../ap/test/updatemethods/DepartmentEntityFactory.java | 2 +- .../mapstruct/ap/test/updatemethods/DepartmentInBetween.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/EmployeeDto.java | 2 +- .../org/mapstruct/ap/test/updatemethods/EmployeeEntity.java | 2 +- .../ap/test/updatemethods/ErroneousCompanyMapper1.java | 2 +- .../ap/test/updatemethods/ErroneousOrganizationMapper1.java | 2 +- .../ap/test/updatemethods/ErroneousOrganizationMapper2.java | 2 +- .../org/mapstruct/ap/test/updatemethods/OrganizationDto.java | 2 +- .../org/mapstruct/ap/test/updatemethods/OrganizationEntity.java | 2 +- .../org/mapstruct/ap/test/updatemethods/OrganizationMapper.java | 2 +- .../mapstruct/ap/test/updatemethods/OrganizationTypeEntity.java | 2 +- .../ap/test/updatemethods/OrganizationTypeNrEntity.java | 2 +- .../updatemethods/OrganizationWithoutCompanyGetterEntity.java | 2 +- .../test/updatemethods/OrganizationWithoutTypeGetterEntity.java | 2 +- .../java/org/mapstruct/ap/test/updatemethods/SecretaryDto.java | 2 +- .../org/mapstruct/ap/test/updatemethods/SecretaryEntity.java | 2 +- .../org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java | 2 +- .../ap/test/updatemethods/selection/DepartmentMapper.java | 2 +- .../test/updatemethods/selection/ExternalHandWrittenMapper.java | 2 +- .../ap/test/updatemethods/selection/ExternalMapper.java | 2 +- .../ap/test/updatemethods/selection/ExternalSelectionTest.java | 2 +- .../ap/test/updatemethods/selection/OrganizationMapper1.java | 2 +- .../ap/test/updatemethods/selection/OrganizationMapper2.java | 2 +- .../ap/test/updatemethods/selection/OrganizationMapper3.java | 2 +- .../java/org/mapstruct/ap/test/value/DefaultOrderMapper.java | 2 +- .../java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java | 2 +- .../ap/test/value/ErroneousOrderMapperDuplicateANY.java | 2 +- .../value/ErroneousOrderMapperMappingSameConstantTwice.java | 2 +- ...usOrderMapperNotMappingConstantWithoutMatchInTargetType.java | 2 +- .../value/ErroneousOrderMapperUsingUnknownEnumConstants.java | 2 +- .../java/org/mapstruct/ap/test/value/ExternalOrderType.java | 2 +- .../src/test/java/org/mapstruct/ap/test/value/OrderDto.java | 2 +- .../src/test/java/org/mapstruct/ap/test/value/OrderEntity.java | 2 +- .../src/test/java/org/mapstruct/ap/test/value/OrderMapper.java | 2 +- .../src/test/java/org/mapstruct/ap/test/value/OrderType.java | 2 +- .../java/org/mapstruct/ap/test/value/SpecialOrderMapper.java | 2 +- .../java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java | 2 +- .../java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java | 2 +- processor/src/test/java/org/mapstruct/ap/testutil/IssueKey.java | 2 +- .../src/test/java/org/mapstruct/ap/testutil/WithClasses.java | 2 +- .../org/mapstruct/ap/testutil/WithServiceImplementation.java | 2 +- .../org/mapstruct/ap/testutil/WithServiceImplementations.java | 2 +- .../org/mapstruct/ap/testutil/assertions/JavaFileAssert.java | 2 +- .../ap/testutil/compilation/annotation/CompilationResult.java | 2 +- .../ap/testutil/compilation/annotation/Diagnostic.java | 2 +- .../compilation/annotation/ExpectedCompilationOutcome.java | 2 +- .../ap/testutil/compilation/annotation/ProcessorOption.java | 2 +- .../ap/testutil/compilation/annotation/ProcessorOptions.java | 2 +- .../compilation/model/CompilationOutcomeDescriptor.java | 2 +- .../ap/testutil/compilation/model/DiagnosticDescriptor.java | 2 +- .../ap/testutil/runner/AnnotationProcessorTestRunner.java | 2 +- .../java/org/mapstruct/ap/testutil/runner/CompilationCache.java | 2 +- .../org/mapstruct/ap/testutil/runner/CompilationRequest.java | 2 +- .../test/java/org/mapstruct/ap/testutil/runner/Compiler.java | 2 +- .../org/mapstruct/ap/testutil/runner/CompilingStatement.java | 2 +- .../mapstruct/ap/testutil/runner/EclipseCompilingStatement.java | 2 +- .../ap/testutil/runner/FilteringParentClassLoader.java | 2 +- .../java/org/mapstruct/ap/testutil/runner/GeneratedSource.java | 2 +- .../ap/testutil/runner/InnerAnnotationProcessorRunner.java | 2 +- .../org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java | 2 +- .../mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java | 2 +- .../org/mapstruct/ap/testutil/runner/ReplacableTestClass.java | 2 +- .../org/mapstruct/ap/testutil/runner/WithSingleCompiler.java | 2 +- .../fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java | 2 +- .../ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java | 2 +- .../ap/test/collection/adder/Source2Target2MapperImpl.java | 2 +- .../ap/test/collection/adder/SourceTargetMapperImpl.java | 2 +- .../collection/adder/SourceTargetMapperStrategyDefaultImpl.java | 2 +- .../adder/SourceTargetMapperStrategySetterPreferredImpl.java | 2 +- .../ap/test/conversion/string/SourceTargetMapperImpl.java | 2 +- .../org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java | 2 +- .../mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java | 2 +- .../ap/test/updatemethods/selection/DepartmentMapperImpl.java | 2 +- .../ap/test/updatemethods/selection/ExternalMapperImpl.java | 2 +- .../test/updatemethods/selection/OrganizationMapper1Impl.java | 2 +- .../test/updatemethods/selection/OrganizationMapper2Impl.java | 2 +- .../test/updatemethods/selection/OrganizationMapper3Impl.java | 2 +- 1527 files changed, 1527 insertions(+), 1526 deletions(-) diff --git a/.gitignore b/.gitignore index afbd80b6e3..4fc554ede8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Eclipse .metadata +.recommenders .classpath .project .settings diff --git a/build-config/pom.xml b/build-config/pom.xml index a284638a72..7e6b94e4dc 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -1,7 +1,7 @@ +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<#if overridden>@Override +<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { + <#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable--> + <#list beforeMappingReferencesWithoutMappingTarget as callback> + <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + <#if !callback_has_next> + + + + if ( ${sourceParameter.name} == null ) { + <#if !mapNullToDefault> + <#-- returned target type starts to miss-align here with target handed via param, TODO is this right? --> + return<#if returnType.name != "void"> null; + <#else> + <#if resultType.arrayType> + <#if existingInstanceMapping> + <#-- we can't clear an existing array, so we've got to clear by setting values to default --> + for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) { + ${resultName}[${index2Name}] = ${defaultValue}; + } + return<#if returnType.name != "void"> ${resultName}; + <#else> + return new <@includeModel object=resultElementType/>[0]; + + <#elseif resultType.iterableType> + <#if existingInstanceMapping> + ${resultName}.clear(); + return<#if returnType.name != "void"> ${resultName}; + <#else> + return <@iterableCreation/>; + + <#else> + <#if existingInstanceMapping> + <#-- We cannot update an existing stream so we just return the old one --> + return<#if returnType.name != "void"> ${resultName}; + <#else> + return Stream.empty(); + + + + } + + <#-- A variable needs to be defined if there are before mappings and this is not exisitingInstanceMapping --> + <#assign needVarDefine = beforeMappingReferencesWithMappingTarget?has_content && !existingInstanceMapping /> + + <#if resultType.arrayType> + <#if !existingInstanceMapping && needVarDefine> + <#assign needVarDefine = false /> + <#-- We create a null array which later will be directly assigned from the stream--> + ${resultElementType}[] ${resultName} = null; + + <#elseif resultType.iterableType> + <#if existingInstanceMapping> + ${resultName}.clear(); + <#elseif needVarDefine> + <#assign needVarDefine = false /> + <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> + <@iterableLocalVarDef/> ${resultName} = <@iterableCreation/>; + + <#else> + <#-- Streams are immutable so we can't update them --> + <#if !existingInstanceMapping && needVarDefine> + <#assign needVarDefine = false /> + <@iterableLocalVarDef/> ${resultName} = Stream.empty(); + + + + <#list beforeMappingReferencesWithMappingTarget as callback> + <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + <#if !callback_has_next> + + + + + <#-- If there are no after mappings, no variable was created before i.e. no before mappings + and this is not an existingInstanceMapping then we can return immediatelly --> + <#assign canReturnImmediatelly = !afterMappingReferences?has_content && !needVarDefine && !existingInstanceMapping/> + + <#if resultType.arrayType> + <#if existingInstanceMapping> + int ${index1Name} = 0; + for ( <@includeModel object=resultElementType/> ${loopVariableName} : ${sourceParameter.name}.limit( ${resultName}.length )<@streamMapSupplier />.toArray( ${resultElementType}[]::new ) ) { + if ( ( ${index1Name} >= ${resultName}.length ) ) { + break; + } + ${resultName}[${index1Name}++] = ${loopVariableName}; + } + <#else> + <#if canReturnImmediatelly><#if returnType.name != "void">return <#else> <#if needVarDefine>${resultElementType}[] <#else>${resultName} = ${sourceParameter.name}<@streamMapSupplier /> + .toArray( <@includeModel object=resultElementType/>[]::new ); + + <#elseif resultType.iterableType> + <#if existingInstanceMapping || !canReturnImmediatelly> + ${resultName}.addAll( ${sourceParameter.name}<@streamMapSupplier /> + .collect( Collectors.toCollection( <@iterableCollectionSupplier /> ) ) + ); + <#else> + <@returnLocalVarDefOrUpdate> + <#lt>${sourceParameter.name}<@streamMapSupplier /> + .collect( Collectors.toCollection( <@iterableCollectionSupplier /> ) ); + + + + <#else> + <#-- Streams are immutable so we can't update them --> + <#if !existingInstanceMapping> + <#--TODO fhr: after the the result is no longer the same instance, how does it affect the + Before mapping methods. Does it even make sense to have before mapping on a stream? --> + <#if sourceParameter.type.arrayType> + <@returnLocalVarDefOrUpdate>Stream.of( ${sourceParameter.name} )<@streamMapSupplier />; + <#elseif sourceParameter.type.collectionType> + <@returnLocalVarDefOrUpdate>${sourceParameter.name}.stream()<@streamMapSupplier />; + <#elseif sourceParameter.type.iterableType> + <@returnLocalVarDefOrUpdate>StreamSupport.stream( ${sourceParameter.name}.spliterator(), false )<@streamMapSupplier />; + <#else> + <@returnLocalVarDefOrUpdate>${sourceParameter.name}<@streamMapSupplier />; + + + + + + <#list afterMappingReferences as callback> + <#if callback_index = 0> + + + <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + + + <#if !canReturnImmediatelly && returnType.name != "void"> + return ${resultName}; + +} +<#macro throws> + <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> + <#list thrownTypes as exceptionType> + <@includeModel object=exceptionType/> + <#if exceptionType_has_next>, <#t> + + + +<#macro iterableSize> + <@compress single_line=true> + <#if sourceParameter.type.arrayType> + ${sourceParameter.name}.length + <#else> + ${sourceParameter.name}.size() + + + +<#macro iterableLocalVarDef> + <@compress single_line=true> + <#if resultType.fullyQualifiedName == "java.lang.Iterable"> + <@includeModel object=resultType.implementationType/> + <#else> + <@includeModel object=resultType/> + + + +<#macro iterableCreation> + <@compress single_line=true> + <#if factoryMethod??> + <@includeModel object=factoryMethod targetType=resultType/> + <#else> + new + <#if resultType.implementationType??> + <@includeModel object=resultType.implementationType/> + <#else> + <@includeModel object=resultType/>() + + + +<#macro iterableCollectionSupplier> + <@compress single_line=true> + <#if resultType.implementationType??> + <@includeModel object=resultType.implementationType/> + <#else> + <@includeModel object=resultType/>::new + + +<#macro streamMapSupplier> + <@compress> + <#if !elementAssignment.directAssignment?? || !elementAssignment.directAssignment> + .map( <@includeModel object=elementAssignment targetBeanName=resultName targetType=resultElementType/> ) + + + +<#macro returnLocalVarDefOrUpdate> + <#if canReturnImmediatelly><#if returnType.name != "void">return <#elseif !needVarDefine><@iterableLocalVarDef/> ${resultName} = <#else>${resultName} = <#nested /> + diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl new file mode 100644 index 0000000000..1cb9729d0c --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl @@ -0,0 +1,51 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference} +<#if (thrownTypes?size == 0) > + <#compress> + <#if directAssignment> + Function.identity() + <#else> + ${sourceVarName} -> <@_assignment/> + +<#else> + <#compress> + ${sourceVarName} -> { + try { + return <@_assignment/>; + } + <#list thrownTypes as exceptionType> + catch ( <@includeModel object=exceptionType/> e ) { + throw new RuntimeException( e ); + } + + } + + +<#macro _assignment> + <@includeModel object=assignment + targetBeanName=ext.targetBeanName + existingInstanceMapping=ext.existingInstanceMapping + targetReadAccessorName=ext.targetReadAccessorName + targetWriteAccessorName=ext.targetWriteAccessorName + targetType=ext.targetType/> + diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 4068fcd5a9..7c68b9394d 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -181,6 +181,7 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + false, false ); } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index ec27cce952..3995946c2f 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -118,6 +118,7 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + false, false ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java new file mode 100644 index 0000000000..023baa52e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java @@ -0,0 +1,23 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +public enum Colour { + RED, GREEN, BLUE; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java new file mode 100644 index 0000000000..98f37575c0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java @@ -0,0 +1,103 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import java.util.stream.Stream; + +public class Source { + + private Stream stringStream; + private Stream stringArrayStream; + + private Stream stringStreamToSet; + + private Stream integerStream; + + private Stream anotherIntegerStream; + + private Stream colours; + + private Stream stringStream2; + + private Stream stringStream3; + + public Stream getStringStream() { + return stringStream; + } + + public void setStringStream(Stream stringStream) { + this.stringStream = stringStream; + } + + public Stream getStringArrayStream() { + return stringArrayStream; + } + + public void setStringArrayStream(Stream stringArrayStream) { + this.stringArrayStream = stringArrayStream; + } + + public Stream getStringStreamToSet() { + return stringStreamToSet; + } + + public void setStringStreamToSet(Stream stringStreamToSet) { + this.stringStreamToSet = stringStreamToSet; + } + + public Stream getIntegerStream() { + return integerStream; + } + + public void setIntegerStream(Stream integerStream) { + this.integerStream = integerStream; + } + + public Stream getAnotherIntegerStream() { + return anotherIntegerStream; + } + + public void setAnotherIntegerStream(Stream anotherIntegerStream) { + this.anotherIntegerStream = anotherIntegerStream; + } + + public Stream getColours() { + return colours; + } + + public void setColours(Stream colours) { + this.colours = colours; + } + + public Stream getStringStream2() { + return stringStream2; + } + + public void setStringStream2(Stream stringStream2) { + this.stringStream2 = stringStream2; + } + + public Stream getStringStream3() { + return stringStream3; + } + + public void setStringStream3(Stream stringStream3) { + this.stringStream3 = stringStream3; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java new file mode 100644 index 0000000000..071efcfe13 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java @@ -0,0 +1,73 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import java.util.Set; +import java.util.stream.Stream; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class SourceTargetMapper { + + static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mappings({ + @Mapping(source = "stringStream", target = "stringList"), + @Mapping(source = "stringArrayStream", target = "stringArrayList"), + @Mapping(source = "stringStreamToSet", target = "stringSet"), + @Mapping(source = "integerStream", target = "integerCollection"), + @Mapping(source = "anotherIntegerStream", target = "anotherStringSet"), + @Mapping(source = "stringStream2", target = "stringListNoSetter"), + @Mapping(source = "stringStream3", target = "nonGenericStringList") + }) + public abstract Target sourceToTarget(Source source); + + @InheritInverseConfiguration( name = "sourceToTarget" ) + public abstract Source targetToSource(Target target); + + @InheritConfiguration + public abstract Target sourceToTargetTwoArg(Source source, @MappingTarget Target target); + + public abstract Set integerSetToStringSet(Set integers); + + @InheritInverseConfiguration + public abstract Set stringSetToIntegerSet(Set strings); + + public abstract Set colourSetToStringSet(Set colours); + + @InheritInverseConfiguration + public abstract Set stringSetToColourSet(Set colours); + + public abstract Set integerSetToNumberSet(Stream integers); + + protected StringHolder toStringHolder(String string) { + return new StringHolder( string ); + } + + protected String toString(StringHolder string) { + return string.getString(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java new file mode 100644 index 0000000000..16bdbf455d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java @@ -0,0 +1,244 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@WithClasses({ + Source.class, + Target.class, + Colour.class, + SourceTargetMapper.class, + TestList.class, + StringHolderArrayList.class, + StringHolder.class +}) +@IssueKey( "962" ) +@RunWith(AnnotationProcessorTestRunner.class) +public class StreamMappingTest { + + @Test + public void shouldMapNullList() { + Source source = new Source(); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringList() ).isNull(); + } + + @Test + public void shouldReverseMapNullList() { + Target target = new Target(); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getStringStream() ).isNull(); + } + + @Test + public void shouldMapList() { + Source source = new Source(); + source.setStringStream( Arrays.asList( "Bob", "Alice" ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringList() ).containsExactly( "Bob", "Alice" ); + } + + @Test + public void shouldMapListWithoutSetter() { + Source source = new Source(); + source.setStringStream2( Arrays.asList( "Bob", "Alice" ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringListNoSetter() ).containsExactly( "Bob", "Alice" ); + } + + @Test + public void shouldReverseMapList() { + Target target = new Target(); + target.setStringList( Arrays.asList( "Bob", "Alice" ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getStringStream() ).containsExactly( "Bob", "Alice" ); + } + + @Test + public void shouldMapArrayList() { + Source source = new Source(); + source.setStringArrayStream( new ArrayList( Arrays.asList( "Bob", "Alice" ) ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringArrayList() ).containsExactly( "Bob", "Alice" ); + } + + @Test + public void shouldReverseMapArrayList() { + Target target = new Target(); + target.setStringArrayList( new ArrayList( Arrays.asList( "Bob", "Alice" ) ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getStringArrayStream() ).containsExactly( "Bob", "Alice" ); + } + + @Test + public void shouldMapSet() { + Source source = new Source(); + source.setStringStreamToSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringSet() ).contains( "Bob", "Alice" ); + } + + @Test + public void shouldReverseMapSet() { + Target target = new Target(); + target.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getStringStreamToSet() ).contains( "Bob", "Alice" ); + } + + @Test + public void shouldMapListToCollection() { + Source source = new Source(); + source.setIntegerStream( Arrays.asList( 1, 2 ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getIntegerCollection() ).containsOnly( 1, 2 ); + } + + @Test + public void shouldReverseMapListToCollection() { + Target target = new Target(); + target.setIntegerCollection( Arrays.asList( 1, 2 ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getIntegerStream() ).containsOnly( 1, 2 ); + } + + @Test + public void shouldMapIntegerSetToStringSet() { + Source source = new Source(); + source.setAnotherIntegerStream( new HashSet( Arrays.asList( 1, 2 ) ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getAnotherStringSet() ).containsOnly( "1", "2" ); + } + + @Test + public void shouldReverseMapIntegerSetToStringSet() { + Target target = new Target(); + target.setAnotherStringSet( new HashSet( Arrays.asList( "1", "2" ) ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getAnotherIntegerStream() ).containsOnly( 1, 2 ); + } + + @Test + public void shouldMapSetOfEnumToStringSet() { + Source source = new Source(); + source.setColours( EnumSet.of( Colour.BLUE, Colour.GREEN ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getColours() ).containsOnly( "BLUE", "GREEN" ); + } + + @Test + public void shouldReverseMapSetOfEnumToStringSet() { + Target target = new Target(); + target.setColours( new HashSet( Arrays.asList( "BLUE", "GREEN" ) ) ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getColours() ).containsOnly( Colour.GREEN, Colour.BLUE ); + } + + @Test + public void shouldMapIntegerSetToNumberSet() { + Set numbers = SourceTargetMapper.INSTANCE + .integerSetToNumberSet( new HashSet( Arrays.asList( 123, 456 ) ).stream() ); + + assertThat( numbers ).isNotNull(); + assertThat( numbers ).containsOnly( 123, 456 ); + } + + @Test + public void shouldMapNonGenericList() { + Source source = new Source(); + source.setStringStream3( new ArrayList( Arrays.asList( "Bob", "Alice" ) ).stream() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getNonGenericStringList() ).containsExactly( + new StringHolder( "Bob" ), + new StringHolder( "Alice" ) + ); + + // Inverse direction + Target newTarget = new Target(); + StringHolderArrayList nonGenericStringList = new StringHolderArrayList(); + nonGenericStringList.addAll( Arrays.asList( new StringHolder( "Bill" ), new StringHolder( "Bob" ) ) ); + newTarget.setNonGenericStringList( nonGenericStringList ); + + Source mappedSource = SourceTargetMapper.INSTANCE.targetToSource( newTarget ); + + assertThat( mappedSource ).isNotNull(); + assertThat( mappedSource.getStringStream3() ).containsExactly( "Bill", "Bob" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java new file mode 100644 index 0000000000..153c848fc8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +/** + * @author Andreas Gudian + * + */ +public class StringHolder { + private final String string; + + public StringHolder(String string) { + this.string = string; + } + + public String getString() { + return string; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( string == null ) ? 0 : string.hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + StringHolder other = (StringHolder) obj; + if ( string == null ) { + if ( other.string != null ) { + return false; + } + } + else if ( !string.equals( other.string ) ) { + return false; + } + return true; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java new file mode 100644 index 0000000000..ccf8ed0299 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import java.util.ArrayList; + +/** + * @author Filip Hrisafov + */ +public class StringHolderArrayList extends ArrayList { + + private static final long serialVersionUID = 1L; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java new file mode 100644 index 0000000000..29b338aa6d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java @@ -0,0 +1,105 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +public class Target { + + private List stringList; + private ArrayList stringArrayList; + + private Set stringSet; + + private Collection integerCollection; + + private Set anotherStringSet; + + private Set colours; + + private List stringListNoSetter; + + private StringHolderArrayList nonGenericStringList; + + public List getStringList() { + return stringList; + } + + public void setStringList(List stringList) { + this.stringList = stringList; + } + + public ArrayList getStringArrayList() { + return stringArrayList; + } + + public void setStringArrayList(ArrayList stringArrayList) { + this.stringArrayList = stringArrayList; + } + + public Set getStringSet() { + return stringSet; + } + + public void setStringSet(Set stringSet) { + this.stringSet = stringSet; + } + + public Collection getIntegerCollection() { + return integerCollection; + } + + public void setIntegerCollection(Collection integerCollection) { + this.integerCollection = integerCollection; + } + + public Set getAnotherStringSet() { + return anotherStringSet; + } + + public void setAnotherStringSet(Set anotherStringSet) { + this.anotherStringSet = anotherStringSet; + } + + public void setColours(Set colours) { + this.colours = colours; + } + + public Set getColours() { + return colours; + } + + public List getStringListNoSetter() { + if ( stringListNoSetter == null ) { + stringListNoSetter = new ArrayList(); + } + return stringListNoSetter; + } + + public StringHolderArrayList getNonGenericStringList() { + return nonGenericStringList; + } + + public void setNonGenericStringList(StringHolderArrayList nonGenericStringList) { + this.nonGenericStringList = nonGenericStringList; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java new file mode 100644 index 0000000000..53617cddf0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * @author Sjaak Derksen + */ +public class TestList extends ArrayList { + + private static final long serialVersionUID = 1L; + + private static boolean addAllCalled = false; + + public static boolean isAddAllCalled() { + return addAllCalled; + } + + public static void setAddAllCalled(boolean addAllCalled) { + TestList.addAllCalled = addAllCalled; + } + + @Override + public boolean addAll(Collection c) { + addAllCalled = true; + return super.addAll( c ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java new file mode 100644 index 0000000000..7e2a71fbe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +/** + * @author Filip Hrisafov + */ +public class MyCustomException extends Exception { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java new file mode 100644 index 0000000000..a0deb021bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java @@ -0,0 +1,138 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +import java.util.List; +import java.util.stream.Stream; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private List ints; + + private Stream stream; + + private Stream stringStream; + + private Stream stringCollection; + + private Stream integerSet; + + private Stream integerIterable; + + private Stream sortedSet; + + private Stream navigableSet; + + private Stream intToStringStream; + + private Stream stringArrayStream; + + private Stream sourceElements; + + public List getInts() { + return ints; + } + + public void setInts(List ints) { + this.ints = ints; + } + + public Stream getStream() { + return stream; + } + + public void setStream(Stream stream) { + this.stream = stream; + } + + public Stream getStringStream() { + return stringStream; + } + + public void setStringStream(Stream stringStream) { + this.stringStream = stringStream; + } + + public Stream getStringCollection() { + return stringCollection; + } + + public void setStringCollection(Stream stringCollection) { + this.stringCollection = stringCollection; + } + + public Stream getIntegerSet() { + return integerSet; + } + + public void setIntegerSet(Stream integerSet) { + this.integerSet = integerSet; + } + + public Stream getIntegerIterable() { + return integerIterable; + } + + public void setIntegerIterable(Stream integerIterable) { + this.integerIterable = integerIterable; + } + + public Stream getSortedSet() { + return sortedSet; + } + + public void setSortedSet(Stream sortedSet) { + this.sortedSet = sortedSet; + } + + public Stream getNavigableSet() { + return navigableSet; + } + + public void setNavigableSet(Stream navigableSet) { + this.navigableSet = navigableSet; + } + + public Stream getIntToStringStream() { + return intToStringStream; + } + + public void setIntToStringStream(Stream intToStringStream) { + this.intToStringStream = intToStringStream; + } + + public Stream getStringArrayStream() { + return stringArrayStream; + } + + public void setStringArrayStream(Stream stringArrayStream) { + this.stringArrayStream = stringArrayStream; + } + + public Stream getSourceElements() { + return sourceElements; + } + + public void setSourceElements(Stream sourceElements) { + this.sourceElements = sourceElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java new file mode 100644 index 0000000000..a0a95aecaa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +/** + * @author Filip Hrisafov + */ +public class SourceElement { + + private String source; + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java new file mode 100644 index 0000000000..0b4b05e0f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface StreamMapper { + + StreamMapper INSTANCE = Mappers.getMapper( StreamMapper.class ); + + @Mappings( { + @Mapping( source = "stream", target = "targetStream"), + @Mapping( source = "sourceElements", target = "targetElements") + } ) + Target map(Source source); + + @InheritInverseConfiguration + Source map(Target target); + + SourceElement mapElement(TargetElement targetElement) throws MyCustomException; + + @InheritInverseConfiguration + TargetElement mapElement(SourceElement sourceElement); + + @InheritInverseConfiguration + Source updateSource(Target target, @MappingTarget Source source) throws MyCustomException; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java new file mode 100644 index 0000000000..b66f603267 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java @@ -0,0 +1,131 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +import java.util.Arrays; +import java.util.List; +import java.util.TreeSet; +import java.util.stream.Stream; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Source.class, + Target.class, + StreamMapper.class, + MyCustomException.class, + TargetElement.class, + SourceElement.class +}) +public class StreamsTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + public void shouldNotContainFunctionIdentity() throws Exception { + generatedSource.forMapper( StreamMapper.class ) + .content() + .as( "The Mapper implementation should not use Function.identity()" ) + .doesNotContain( "Function.identity()" ); + } + + @Test + public void shouldMapSourceStream() throws Exception { + List someInts = Arrays.asList( 1, 2, 3 ); + Stream stream = someInts.stream(); + Source source = new Source(); + source.setStream( stream ); + source.setStringStream( Arrays.asList( "4", "5", "6", "7" ).stream() ); + source.setInts( Arrays.asList( 1, 2, 3 ) ); + source.setIntegerSet( Arrays.asList( 1, 1, 2, 2, 4, 4 ).stream() ); + source.setStringCollection( Arrays.asList( "1", "1", "2", "3" ).stream().distinct() ); + source.setIntegerIterable( Arrays.asList( 10, 11, 12 ).stream() ); + source.setSortedSet( Arrays.asList( 12, 11, 10 ).stream() ); + source.setNavigableSet( Arrays.asList( 12, 11, 10 ).stream() ); + source.setIntToStringStream( Arrays.asList( 10, 11, 12 ).stream() ); + source.setStringArrayStream( Arrays.asList( "4", "5", "6", "6" ).stream().limit( 2 ) ); + + SourceElement element = new SourceElement(); + element.setSource( "source1" ); + source.setSourceElements( Arrays.asList( element ).stream() ); + + + Target target = StreamMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getTargetStream() ).isSameAs( stream ); + assertThat( target.getStringStream() ).containsExactly( "4", "5", "6", "7" ); + assertThat( target.getInts() ).containsExactly( 1, 2, 3 ); + assertThat( target.getIntegerSet() ).containsOnly( 1, 2, 4 ); + assertThat( target.getStringCollection() ).containsExactly( "1", "2", "3" ).isInstanceOf( List.class ); + assertThat( target.getIntegerIterable() ).containsExactly( 10, 11, 12 ).isInstanceOf( List.class ); + assertThat( target.getSortedSet() ).containsExactly( 10, 11, 12 ).isInstanceOf( TreeSet.class ); + assertThat( target.getNavigableSet() ).containsExactly( 10, 11, 12 ).isInstanceOf( TreeSet.class ); + assertThat( target.getIntToStringStream() ).containsExactly( "10", "11", "12" ); + assertThat( target.getStringArrayStream() ).containsExactly( 4, 5 ); + assertThat( target.getTargetElements().get( 0 ).getSource() ).isEqualTo( "source1" ); + } + + @Test + public void shouldMapTargetStream() throws Exception { + List someInts = Arrays.asList( 1, 2, 3 ); + Stream stream = someInts.stream(); + Target target = new Target(); + target.setTargetStream( stream ); + target.setStringStream( Arrays.asList( "4", "5", "6", "7" ) ); + target.setInts( Arrays.asList( 1, 2, 3 ).stream() ); + target.setIntegerSet( Collections.asSet( 1, 1, 2, 2, 4, 4 ) ); + target.setStringCollection( Collections.asSet( "1", "1", "2", "3" ) ); + target.setIntegerIterable( Arrays.asList( 10, 11, 12 ) ); + target.setSortedSet( new TreeSet( Arrays.asList( 12, 11, 10 ) ) ); + target.setNavigableSet( new TreeSet( Arrays.asList( 12, 11, 10 ) ) ); + target.setIntToStringStream( Arrays.asList( "4", "5", "6" ) ); + target.setStringArrayStream( new Integer[] { 10, 11, 12 } ); + + + Source source = StreamMapper.INSTANCE.map( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getStream() ).isSameAs( stream ); + assertThat( source.getStringStream() ).containsExactly( "4", "5", "6", "7" ); + assertThat( source.getInts() ).containsExactly( 1, 2, 3 ); + assertThat( source.getIntegerSet() ).containsOnly( 1, 2, 4 ); + assertThat( source.getStringCollection() ).containsExactly( "1", "2", "3" ); + assertThat( source.getIntegerIterable() ).containsExactly( 10, 11, 12 ); + assertThat( source.getSortedSet() ).containsExactly( 10, 11, 12 ); + assertThat( source.getNavigableSet() ).containsExactly( 10, 11, 12 ); + assertThat( source.getIntToStringStream() ).containsExactly( 4, 5, 6 ); + assertThat( source.getStringArrayStream() ).containsExactly( "10", "11", "12" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java new file mode 100644 index 0000000000..babaf78a6f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java @@ -0,0 +1,142 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +import java.util.Collection; +import java.util.List; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.stream.Stream; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Stream ints; + + private Stream targetStream; + + private List stringStream; + + private Collection stringCollection; + + private Set integerSet; + + private Iterable integerIterable; + + private SortedSet sortedSet; + + private NavigableSet navigableSet; + + private List intToStringStream; + + private Integer[] stringArrayStream; + + private List targetElements; + + public Stream getInts() { + return ints; + } + + public void setInts(Stream ints) { + this.ints = ints; + } + + public Stream getTargetStream() { + return targetStream; + } + + public void setTargetStream(Stream targetStream) { + this.targetStream = targetStream; + } + + public List getStringStream() { + return stringStream; + } + + public void setStringStream(List stringStream) { + this.stringStream = stringStream; + } + + public Collection getStringCollection() { + return stringCollection; + } + + public void setStringCollection(Collection stringCollection) { + this.stringCollection = stringCollection; + } + + public Set getIntegerSet() { + return integerSet; + } + + public void setIntegerSet(Set integerSet) { + this.integerSet = integerSet; + } + + public Iterable getIntegerIterable() { + return integerIterable; + } + + public void setIntegerIterable(Iterable integerIterable) { + this.integerIterable = integerIterable; + } + + public SortedSet getSortedSet() { + return sortedSet; + } + + public void setSortedSet(SortedSet sortedSet) { + this.sortedSet = sortedSet; + } + + public NavigableSet getNavigableSet() { + return navigableSet; + } + + public void setNavigableSet(NavigableSet navigableSet) { + this.navigableSet = navigableSet; + } + + public List getIntToStringStream() { + return intToStringStream; + } + + public void setIntToStringStream(List intToStringStream) { + this.intToStringStream = intToStringStream; + } + + public Integer[] getStringArrayStream() { + return stringArrayStream; + } + + public void setStringArrayStream(Integer[] stringArrayStream) { + this.stringArrayStream = stringArrayStream; + } + + public List getTargetElements() { + return targetElements; + } + + public void setTargetElements(List targetElements) { + this.targetElements = targetElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java new file mode 100644 index 0000000000..4c0f647070 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.base; + +/** + * @author Filip Hrisafov + */ +public class TargetElement { + + private String source; + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java new file mode 100644 index 0000000000..834abec16b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.context; + +import java.util.Collection; +import java.util.stream.Stream; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.MappingTarget; + +/** + * @author Filip Hrisafov + */ +public class StreamContext { + + @BeforeMapping + public void beforeArrayMapping(Integer[] strings) { + if ( strings != null && strings.length > 0 ) { + strings[0] = 30; + } + } + + @BeforeMapping + public void beforeMapping(@MappingTarget Stream stream) { + + } + + @BeforeMapping + public void beforeMapping(@MappingTarget Collection collection) { + collection.add( "23" ); + } + + @AfterMapping + public void afterMapping(@MappingTarget Collection collection) { + collection.add( "230" ); + } + + @AfterMapping + public Stream afterMapping(@MappingTarget Stream stringStream) { + return stringStream.limit( 2 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java new file mode 100644 index 0000000000..a98758a9e7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.context; + +import java.util.Collection; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = StreamContext.class) +public interface StreamWithContextMapper { + + StreamWithContextMapper INSTANCE = Mappers.getMapper( StreamWithContextMapper.class ); + + Collection streamToCollection(Stream integerStream); + + Stream collectionToStream(Collection integerCollection); + + String[] streamToArray(Stream integerStream); + + Stream arrayToStream(Integer[] integers); + + Stream streamToStream(Stream stringStream); + + Stream intStreamToStringStream(Stream integerStream); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java new file mode 100644 index 0000000000..78b705c890 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java @@ -0,0 +1,64 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.context; + +import java.util.Arrays; +import java.util.Collection; +import java.util.stream.Stream; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ StreamContext.class, StreamWithContextMapper.class }) +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class StreamWithContextTest { + + @Test + public void shouldApplyAfterMapping() throws Exception { + Stream stringStream = StreamWithContextMapper.INSTANCE.intStreamToStringStream( + Arrays.asList( 1, 2, 3, 5 ).stream() ); + + assertThat( stringStream ).containsOnly( "1", "2" ); + } + + @Test + public void shouldApplyBeforeMappingOnArray() throws Exception { + Integer[] integers = new Integer[] { 1, 3 }; + Stream stringStream = StreamWithContextMapper.INSTANCE.arrayToStream( integers ); + + assertThat( stringStream ).containsOnly( 30, 3 ); + } + + @Test + public void shouldApplyBeforeAndAfterMappingOnCollection() throws Exception { + Collection stringsStream = StreamWithContextMapper.INSTANCE.streamToCollection( + Arrays.asList( 10, 20, 40 ).stream() ); + + assertThat( stringsStream ).containsOnly( "23", "10", "20", "40", "230" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java new file mode 100644 index 0000000000..21c4c997f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java @@ -0,0 +1,190 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Stream; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@WithClasses({ + Source.class, + Target.class, + SourceFoo.class, + TargetFoo.class, + SourceTargetMapper.class +}) +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class DefaultStreamImplementationTest { + + @Test + public void shouldUseDefaultImplementationForNavigableSet() { + NavigableSet target = + SourceTargetMapper.INSTANCE.streamToNavigableSet( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( TreeSet.class ); + } + + @Test + public void shouldUseDefaultImplementationForCollection() { + Collection target = + SourceTargetMapper.INSTANCE.streamToCollection( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( ArrayList.class ); + } + + @Test + public void shouldUseDefaultImplementationForIterable() { + Iterable target = + SourceTargetMapper.INSTANCE.streamToIterable( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( ArrayList.class ); + } + + @Test + public void shouldUseDefaultImplementationForList() { + List target = SourceTargetMapper.INSTANCE.streamToList( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( ArrayList.class ); + } + + @Test + public void shouldUseDefaultImplementationForSet() { + Set target = + SourceTargetMapper.INSTANCE.streamToSet( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( HashSet.class ); + } + + @Test + public void shouldUseDefaultImplementationForSortedSet() { + SortedSet target = + SourceTargetMapper.INSTANCE.streamToSortedSet( createSourceFooStream() ); + + assertResultList( target ); + assertThat( target ).isInstanceOf( TreeSet.class ); + } + + @Test + public void shouldUseTargetParameterForMapping() { + List target = new ArrayList(); + SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter( + target, + createSourceFooStream() + ); + + assertResultList( target ); + } + + @Test + public void shouldUseTargetParameterForArrayMapping() { + TargetFoo[] target = new TargetFoo[3]; + SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameter( + target, + createSourceFooStream() + ); + + assertThat( target ).isNotNull(); + assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ), null ); + } + + @Test + public void shouldUseTargetParameterForArrayMappingAndSmallerArray() { + TargetFoo[] target = new TargetFoo[1]; + SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameter( + target, + createSourceFooStream() + ); + + assertThat( target ).isNotNull(); + assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); + } + + @Test + public void shouldUseAndReturnTargetParameterForArrayMapping() { + TargetFoo[] target = new TargetFoo[3]; + TargetFoo[] result = + SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameterAndReturn( createSourceFooStream(), target ); + + assertThat( result ).isSameAs( target ); + assertThat( target ).isNotNull(); + assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ), null ); + } + + @Test + public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() { + TargetFoo[] target = new TargetFoo[1]; + TargetFoo[] result = + SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameterAndReturn( createSourceFooStream(), target ); + + assertThat( result ).isSameAs( target ); + assertThat( target ).isNotNull(); + assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); + } + + @Test + public void shouldUseAndReturnTargetParameterForMapping() { + List target = new ArrayList(); + Iterable result = + SourceTargetMapper.INSTANCE + .sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooStream(), target ); + + assertThat( result ).isSameAs( target ); + assertResultList( target ); + } + + @Test + public void shouldUseDefaultImplementationForListWithoutSetter() { + Source source = new Source(); + source.setFooStream( createSourceFooStream() ); + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getFooListNoSetter() ).containsExactly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) ); + } + + private void assertResultList(Iterable fooIterable) { + assertThat( fooIterable ).isNotNull(); + assertThat( fooIterable ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) ); + } + + private Stream createSourceFooStream() { + return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) ).stream(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java new file mode 100644 index 0000000000..392f84c4ca --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * + */ +@Mapper +public interface NoSetterMapper { + + NoSetterMapper INSTANCE = Mappers.getMapper( NoSetterMapper.class ); + + NoSetterTarget toTarget(NoSetterSource source); + + NoSetterTarget toTargetWithExistingTarget(NoSetterSource source, @MappingTarget NoSetterTarget preExistTarget); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java new file mode 100644 index 0000000000..336a6572b8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import java.util.stream.Stream; + +/** + * @author Filip Hrisafov + * + */ +public class NoSetterSource { + private Stream listValues; + + public Stream getListValues() { + return listValues; + } + + public void setListValues(Stream listValues) { + this.listValues = listValues; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java new file mode 100644 index 0000000000..2966005cf7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java @@ -0,0 +1,61 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisfaov + * + */ +@WithClasses({ NoSetterMapper.class, NoSetterSource.class, NoSetterTarget.class }) +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class NoSetterStreamMappingTest { + + @Test + public void compilesAndMapsCorrectly() { + NoSetterSource source = new NoSetterSource(); + source.setListValues( Arrays.asList( "foo", "bar" ).stream() ); + + NoSetterTarget target = NoSetterMapper.INSTANCE.toTarget( source ); + + assertThat( target.getListValues() ).containsExactly( "foo", "bar" ); + + // now test existing instances + + NoSetterSource source2 = new NoSetterSource(); + source2.setListValues( Arrays.asList( "baz" ).stream() ); + List originalCollectionInstance = target.getListValues(); + + NoSetterTarget target2 = NoSetterMapper.INSTANCE.toTargetWithExistingTarget( source2, target ); + + assertThat( target2.getListValues() ).isSameAs( originalCollectionInstance ); + assertThat( target2.getListValues() ).containsExactly( "baz" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java new file mode 100644 index 0000000000..4de11a1d0e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Filip Hrisafov + * + */ +public class NoSetterTarget { + private List listValues = new ArrayList(); + + public List getListValues() { + return listValues; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java new file mode 100644 index 0000000000..33134f4c38 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import java.util.stream.Stream; + +public class Source { + + private Stream fooStream; + + public Stream getFooStream() { + return fooStream; + } + + public void setFooStream(Stream fooStream) { + this.fooStream = fooStream; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java new file mode 100644 index 0000000000..9533f6cc29 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +public class SourceFoo { + + private String name; + + public SourceFoo() { + } + + public SourceFoo(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java new file mode 100644 index 0000000000..c42f4997eb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java @@ -0,0 +1,65 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import java.util.Collection; +import java.util.List; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedSet; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(source = "fooStream", target = "fooListNoSetter") + Target sourceToTarget(Source source); + + TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo); + + List streamToList(Stream foos); + + Set streamToSet(Stream foos); + + Collection streamToCollection(Stream foos); + + Iterable streamToIterable(Stream foos); + + void sourceFoosToTargetFoosUsingTargetParameter(@MappingTarget List targetFoos, + Stream sourceFoos); + + Iterable sourceFoosToTargetFoosUsingTargetParameterAndReturn(Stream sourceFoos, + @MappingTarget List targetFoos); + + SortedSet streamToSortedSet(Stream foos); + + NavigableSet streamToNavigableSet(Stream foos); + + void streamToArrayUsingTargetParameter(@MappingTarget TargetFoo[] targetFoos, Stream sourceFoo); + + TargetFoo[] streamToArrayUsingTargetParameterAndReturn(Stream sourceFoos, + @MappingTarget TargetFoo[] targetFoos); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java new file mode 100644 index 0000000000..98c366e427 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +import java.util.ArrayList; +import java.util.List; + +public class Target { + + private List fooListNoSetter; + + public List getFooListNoSetter() { + if ( fooListNoSetter == null ) { + fooListNoSetter = new ArrayList(); + } + return fooListNoSetter; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java new file mode 100644 index 0000000000..6e9f29ed53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java @@ -0,0 +1,75 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.defaultimplementation; + +public class TargetFoo implements Comparable { + + private String name; + + public TargetFoo() { + } + + public TargetFoo(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( name == null ) ? 0 : name.hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + TargetFoo other = (TargetFoo) obj; + if ( name == null ) { + if ( other.name != null ) { + return false; + } + } + else if ( !name.equals( other.name ) ) { + return false; + } + return true; + } + + @Override + public int compareTo(TargetFoo o) { + return getName().compareTo( o.getName() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java new file mode 100644 index 0000000000..c74bb9403d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.util.Date; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.IterableMapping; +import org.mapstruct.Mapper; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface EmptyStreamMappingMapper { + + @IterableMapping + Stream dateStreamToStringStream(Stream dates); + + @IterableMapping + Stream dateListToStringStream(List dates); + + @IterableMapping + List dateListToStringStream(Stream dates); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java new file mode 100644 index 0000000000..df8c7f1826 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousListToStreamNoElementMappingFound { + + ErroneousListToStreamNoElementMappingFound INSTANCE = + Mappers.getMapper( ErroneousListToStreamNoElementMappingFound.class ); + + Stream mapCollectionToStream(List source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java new file mode 100644 index 0000000000..b743092cb6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -0,0 +1,154 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import javax.tools.Diagnostic.Kind; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Test for illegal mappings between collection/stream types, iterable and non-iterable types etc. + * + * Currently org.mapstruct.ap.test.stream.erroneous.ErroneousStreamMappingTest#shouldFailOnNoElementMappingFound + * and org.mapstruct.ap.test.stream.erroneous + * .ErroneousStreamMappingTest#shouldFailOnEmptyIterableAnnotationStreamMappings + * fail with the eclipse compiler, because when the result type is a Stream also the Message.GENERAL_NO_IMPLEMENTATION + * is reported, because Stream is an Interface. However, maybe if the resultType is stream when we + * do StreamMethodMapping in the MapperCreationProcessor we need to say that there is a factory method + * + * @author Filip Hrisafov + */ +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class ErroneousStreamMappingTest { + + @Test + @WithClasses({ ErroneousStreamToNonStreamMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, + kind = Kind.ERROR, + line = 28, + messageRegExp = "Can't generate mapping method from iterable type to non-iterable type"), + @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, + kind = Kind.ERROR, + line = 30, + messageRegExp = "Can't generate mapping method from non-iterable type to iterable type") + } + ) + public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterable() { + } + + @Test + @WithClasses({ ErroneousStreamToPrimitivePropertyMapper.class, Source.class, Target.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToPrimitivePropertyMapper.class, + kind = Kind.ERROR, + line = 26, + messageRegExp = + "Can't map property \"java.util.stream.Stream strings\" to \"int strings\". " + + + "Consider to declare/implement a mapping method: \"int map\\(java.util.stream.Stream" + + " value\\)\"") + } + ) + public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { + } + + @Test + @WithClasses({ EmptyStreamMappingMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = EmptyStreamMappingMapper.class, + kind = Kind.ERROR, + line = 36, + messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + + "undefined in @IterableMapping, define at least one of them."), + @Diagnostic(type = EmptyStreamMappingMapper.class, + kind = Kind.ERROR, + line = 39, + messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + + "undefined in @IterableMapping, define at least one of them."), + @Diagnostic(type = EmptyStreamMappingMapper.class, + kind = Kind.ERROR, + line = 42, + messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + + "undefined in @IterableMapping, define at least one of them.") + } + ) + public void shouldFailOnEmptyIterableAnnotationStreamMappings() { + } + + @Test + @WithClasses({ ErroneousStreamToStreamNoElementMappingFound.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, + kind = Kind.ERROR, + line = 36, + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoElementMappingFoundForStreamToStream() { + } + + @Test + @WithClasses({ ErroneousListToStreamNoElementMappingFound.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, + kind = Kind.ERROR, + line = 37, + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoElementMappingFoundForListToStream() { + } + + @Test + @WithClasses({ ErroneousStreamToListNoElementMappingFound.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, + kind = Kind.ERROR, + line = 37, + messageRegExp = "Can't map .*AttributedString to .*String. " + + "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoElementMappingFoundForStreamToList() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java new file mode 100644 index 0000000000..f3bc534664 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousStreamToListNoElementMappingFound { + + ErroneousStreamToListNoElementMappingFound INSTANCE = + Mappers.getMapper( ErroneousStreamToListNoElementMappingFound.class ); + + List mapStreamToCollection(Stream source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java new file mode 100644 index 0000000000..a1607d9c7b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +@Mapper +public interface ErroneousStreamToNonStreamMapper { + + Integer stringStreamToInteger(Stream strings); + + Stream integerToStringStream(Integer integer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java new file mode 100644 index 0000000000..73ca458ee6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public interface ErroneousStreamToPrimitivePropertyMapper { + + Target mapStreamToNonStreamAsProperty(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java new file mode 100644 index 0000000000..66cfcbbad0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousStreamToStreamNoElementMappingFound { + + ErroneousStreamToStreamNoElementMappingFound INSTANCE = + Mappers.getMapper( ErroneousStreamToStreamNoElementMappingFound.class ); + + Stream mapStreamToStream(Stream source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java new file mode 100644 index 0000000000..d85c7ea7d5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.util.stream.Stream; + +public class Source { + + private Stream strings; + + public Stream getStrings() { + return strings; + } + + public void setStrings(Stream strings) { + this.strings = strings; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java new file mode 100644 index 0000000000..ae5ae0b709 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +public class Target { + + private int strings; + + public int getStrings() { + return strings; + } + + public void setStrings(int strings) { + this.strings = strings; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java new file mode 100644 index 0000000000..15e24a728b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +/** + * + * @author Filip Hrisafov + */ +public class Bar { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java new file mode 100644 index 0000000000..da2d603a7e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import java.util.stream.Stream; + +public class ErroneousNonMappableStreamSource { + + private Stream nonMappableStream; + + public Stream getNonMappableStream() { + return nonMappableStream; + } + + public void setNonMappableStream(Stream nonMappableStream) { + this.nonMappableStream = nonMappableStream; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java new file mode 100644 index 0000000000..50d5c1bbdc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import java.util.stream.Stream; + +public class ErroneousNonMappableStreamTarget { + + private Stream nonMappableStream; + + public Stream getNonMappableStream() { + return nonMappableStream; + } + + public void setNonMappableStream(Stream nonMappableStream) { + this.nonMappableStream = nonMappableStream; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java new file mode 100644 index 0000000000..e36f78376b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousStreamNonMappableStreamMapper { + + ErroneousStreamNonMappableStreamMapper INSTANCE = + Mappers.getMapper( ErroneousStreamNonMappableStreamMapper.class ); + + ErroneousNonMappableStreamTarget sourceToTarget(ErroneousNonMappableStreamSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java new file mode 100644 index 0000000000..fb80ee460a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +/** + * + * @author Sjaak Derksen + */ +public class Foo { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java new file mode 100644 index 0000000000..d791519d38 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -0,0 +1,132 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.tools.Diagnostic.Kind; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * Test for mappings between collection and stream types, + * + * @author Filip Hrisafov + */ +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class ForgedStreamMappingTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ StreamMapper.class, Source.class, Target.class }) + public void shouldForgeNewIterableMappingMethod() { + + Source source = new Source(); + source.setFooStream( Collections.asSet( "1", "2" ).stream() ); + + Target target = StreamMapper.INSTANCE.sourceToTarget( source ); + assertThat( target ).isNotNull(); + assertThat( target.getFooStream() ).contains( 1L, 2L ); + + Source source2 = StreamMapper.INSTANCE.targetToSource( target ); + assertThat( source2 ).isNotNull(); + assertThat( source2.getFooStream() ).contains( "1", "2" ); + + generatedSource.forMapper( StreamMapper.class ) + .content() + .as( "Mapper should not uas addAll" ) + .doesNotContain( "addAll( " ) + .as( "Mapper should not use Stream.empty()" ) + .doesNotContain( "Stream.empty()" ); + } + + @Test + @WithClasses({ + ErroneousStreamNonMappableStreamMapper.class, + ErroneousNonMappableStreamSource.class, + ErroneousNonMappableStreamTarget.class, + Foo.class, + Bar.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, + kind = Kind.ERROR, + line = 30, + messageRegExp = "Can't map property \".* nonMappableStream\" to \".* nonMappableStream\". " + + "Consider to declare/implement a mapping method: .*."), + } + ) + public void shouldGenerateNonMappableMethodForSetMapping() { + } + + @Test + @WithClasses({ StreamMapper.class, Source.class, Target.class }) + public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() { + + Source source = new Source(); + source.setFooStream( null ); + source.setFooStream3( null ); + + Target target = StreamMapper.INSTANCE.sourceToTarget( source ); + assertThat( target ).isNotNull(); + assertThat( target.getFooStream() ).isNull(); + + Source source2 = StreamMapper.INSTANCE.targetToSource( target ); + assertThat( source2 ).isNotNull(); + assertThat( source2.getFooStream() ).isNull(); + assertThat( source2.getFooStream3() ).isNull(); + } + + @Test + @WithClasses({ StreamMapperNullValueMappingReturnDefault.class, Source.class, Target.class }) + public void shouldForgeNewIterableMappingMethodReturnEmptyOnNullSource() { + + Source source = new Source(); + source.setFooStream( null ); + source.setFooStream3( null ); + + Target target = StreamMapperNullValueMappingReturnDefault.INSTANCE.sourceToTarget( source ); + assertThat( target ).isNotNull(); + assertThat( target.getFooStream() ).isEmpty(); + assertThat( target.getFooStream3() ).isEmpty(); + + //The empty stream was already consumed so need to set a new one + target.setFooStream3( null ); + + Source source2 = StreamMapperNullValueMappingReturnDefault.INSTANCE.targetToSource( target ); + assertThat( source2 ).isNotNull(); + assertThat( source2.getFooStream() ).isEmpty(); + assertThat( source2.getFooStream3() ).isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java new file mode 100644 index 0000000000..47ec385886 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import java.util.Set; +import java.util.stream.Stream; + +public class Source { + + private Stream fooStream; + private Set fooStream2; + private Stream fooStream3; + + public Stream getFooStream() { + return fooStream; + } + + public void setFooStream(Stream fooStream) { + this.fooStream = fooStream; + } + + public Set getFooStream2() { + return fooStream2; + } + + public void setFooStream2(Set fooStream2) { + this.fooStream2 = fooStream2; + } + + public Stream getFooStream3() { + return fooStream3; + } + + public void setFooStream3(Stream fooStream3) { + this.fooStream3 = fooStream3; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java new file mode 100644 index 0000000000..61692c16e3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface StreamMapper { + + StreamMapper INSTANCE = Mappers.getMapper( StreamMapper.class ); + + Target sourceToTarget(Source source); + + Source targetToSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java new file mode 100644 index 0000000000..13a0757c0f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) +public interface StreamMapperNullValueMappingReturnDefault { + + StreamMapperNullValueMappingReturnDefault INSTANCE = + Mappers.getMapper( StreamMapperNullValueMappingReturnDefault.class ); + + Target sourceToTarget(Source source); + + Source targetToSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java new file mode 100644 index 0000000000..02bee8ea84 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.forged; + +import java.util.Set; +import java.util.stream.Stream; + +public class Target { + + private Set fooStream; + private Stream fooStream2; + private Stream fooStream3; + + public Set getFooStream() { + return fooStream; + } + + public void setFooStream(Set fooStream) { + this.fooStream = fooStream; + } + + public Stream getFooStream2() { + return fooStream2; + } + + public void setFooStream2(Stream fooStream2) { + this.fooStream2 = fooStream2; + } + + public Stream getFooStream3() { + return fooStream3; + } + + public void setFooStream3(Stream fooStream3) { + this.fooStream3 = fooStream3; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java new file mode 100644 index 0000000000..a4136a8ee9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.streamtononiterable; + +import java.util.stream.Stream; + +public class Source { + + private Stream names; + + public Stream getNames() { + return names; + } + + public void setNames(Stream names) { + this.names = names; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java new file mode 100644 index 0000000000..f83d2a03cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.streamtononiterable; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = StringListMapper.class) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + Target sourceToTarget(Source source); + + Source targetToSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java new file mode 100644 index 0000000000..f877b5536e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.streamtononiterable; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class }) +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class StreamToNonIterableMappingTest { + + @Test + public void shouldMapStringStreamToStringUsingCustomMapper() { + Source source = new Source(); + source.setNames( Arrays.asList( "Alice", "Bob", "Jim" ).stream() ); + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getNames() ).isEqualTo( "Alice-Bob-Jim" ); + } + + @Test + public void shouldReverseMapStringStreamToStringUsingCustomMapper() { + Target target = new Target(); + target.setNames( "Alice-Bob-Jim" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getNames() ).containsExactly( "Alice", "Bob", "Jim" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java new file mode 100644 index 0000000000..f8bbc79ec2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.streamtononiterable; + +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class StringListMapper { + + public String stringListToString(Stream strings) { + return strings == null ? null : strings.collect( Collectors.joining( "-" ) ); + } + + public Stream stringToStringList(String string) { + return string == null ? null : Arrays.asList( string.split( "-" ) ).stream(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java new file mode 100644 index 0000000000..a0593d4b68 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.streamtononiterable; + +public class Target { + + private String names; + + public String getNames() { + return names; + } + + public void setNames(String names) { + this.names = names; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java new file mode 100644 index 0000000000..77d368a9e8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousIterableExtendsBoundTargetMapper { + + List map(Stream in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java new file mode 100644 index 0000000000..24340bf49f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ErroneousIterableSuperBoundSourceMapper { + + List map(Stream in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java new file mode 100644 index 0000000000..fb1008a709 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousIterableTypeVarBoundMapperOnMapper { + + List map(Stream in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java new file mode 100644 index 0000000000..d32637dcfc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.math.BigDecimal; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousIterableTypeVarBoundMapperOnMethod { + + List map(Stream in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java new file mode 100644 index 0000000000..9235fb726c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.util.List; +import java.util.stream.Stream; + +/** + * + * @author Filip Hrisafov + */ +public class ExtendsBoundSource { + + private Stream elements; + + private List listElements; + + public Stream getElements() { + return elements; + } + + public void setElements(Stream elements) { + this.elements = elements; + } + + public List getListElements() { + return listElements; + } + + public void setListElements(List listElements) { + this.listElements = listElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java new file mode 100644 index 0000000000..e5c9e6d9e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ExtendsBoundSourceTargetMapper { + + ExtendsBoundSourceTargetMapper STM = Mappers.getMapper( ExtendsBoundSourceTargetMapper.class ); + + Target map(ExtendsBoundSource source); + + Plan map(Idea in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java new file mode 100644 index 0000000000..e3e42c0984 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +/** + * + * @author Sjaak Derksen + */ +public class Idea { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java new file mode 100644 index 0000000000..15b28ff2f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +/** + * + * @author Sjaak Derksen + */ +public class Plan { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java new file mode 100644 index 0000000000..02f08a9e1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.util.List; +import java.util.stream.Stream; + +/** + * + * @author Filip Hrisafov + */ +public class Source { + + private Stream elements; + + private List listElements; + + public Stream getElements() { + return elements; + } + + public void setElements(Stream elements) { + this.elements = elements; + } + + public List getListElements() { + return listElements; + } + + public void setListElements(List listElements) { + this.listElements = listElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java new file mode 100644 index 0000000000..6704dbfa99 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface SourceSuperBoundTargetMapper { + + SourceSuperBoundTargetMapper STM = Mappers.getMapper( SourceSuperBoundTargetMapper.class ); + + SuperBoundTarget map(Source source); + + Plan map(Idea in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java new file mode 100644 index 0000000000..7d30efceab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.util.List; +import java.util.stream.Stream; + +/** + * + * @author Filip Hrisafov + */ +public class SuperBoundTarget { + + private List elements; + + private Stream listElements; + + public List getElements() { + return elements; + } + + public void setElements(List elements) { + this.elements = elements; + } + + public Stream getListElements() { + return listElements; + } + + public void setListElements(Stream listElements) { + this.listElements = listElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java new file mode 100644 index 0000000000..b657985bd8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import java.util.List; +import java.util.stream.Stream; + +/** + * + * @author Filip Hrisafov + */ +public class Target { + + private List elements; + + private Stream listElements; + + public List getElements() { + return elements; + } + + public void setElements(List elements) { + this.elements = elements; + } + + public Stream getListElements() { + return listElements; + } + + public void setListElements(Stream listElements) { + this.listElements = listElements; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java new file mode 100644 index 0000000000..67db736ac8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java @@ -0,0 +1,134 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.wildcard; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("962") +@RunWith(AnnotationProcessorTestRunner.class) +public class WildCardTest { + + @Test + @WithClasses({ + ExtendsBoundSourceTargetMapper.class, + ExtendsBoundSource.class, + Target.class, + Plan.class, + Idea.class + }) + public void shouldGenerateExtendsBoundSourceForgedStreamMethod() { + + ExtendsBoundSource source = new ExtendsBoundSource(); + + Target target = ExtendsBoundSourceTargetMapper.STM.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getElements() ).isNull(); + assertThat( target.getListElements() ).isNull(); + + } + + @Test + @WithClasses({ + SourceSuperBoundTargetMapper.class, + Source.class, + SuperBoundTarget.class, + Plan.class, + Idea.class + }) + public void shouldGenerateSuperBoundTargetForgedIterableMethod() { + + Source source = new Source(); + + SuperBoundTarget target = SourceSuperBoundTargetMapper.STM.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getElements() ).isNull(); + assertThat( target.getListElements() ).isNull(); + + } + + @Test + @WithClasses({ ErroneousIterableSuperBoundSourceMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIterableSuperBoundSourceMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + messageRegExp = "Can't generate mapping method for a wildcard super bound source.") + } + ) + public void shouldFailOnSuperBoundSource() { + } + + @Test + @WithClasses({ ErroneousIterableExtendsBoundTargetMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIterableExtendsBoundTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + messageRegExp = "Can't generate mapping method for a wildcard extends bound result.") + } + ) + public void shouldFailOnExtendsBoundTarget() { + } + + @Test + @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMethod.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMethod.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + messageRegExp = "Can't generate mapping method for a generic type variable target.") + } + ) + public void shouldFailOnTypeVarSource() { + } + + @Test + @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + messageRegExp = "Can't generate mapping method for a generic type variable source.") + } + ) + public void shouldFailOnTypeVarTarget() { + } +} From 4063bd2eca45d2886d4d21fcb6bff4f954b1abe7 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 5 Jan 2017 22:55:31 +0100 Subject: [PATCH 0024/1006] #1029 Don't show an error when explicitly ignoring read-only properties --- .../ap/internal/model/BeanMappingMethod.java | 32 ++++-- .../bugs/_1029/ErroneousIssue1029Mapper.java | 101 ++++++++++++++++++ .../ap/test/bugs/_1029/Issue1029Test.java | 53 +++++++++ ...roneousTargetHasNoWriteAccessorMapper.java | 2 +- .../ap/test/ignore/IgnorePropertyTest.java | 7 +- .../mapstruct/ap/test/ignore/Preditor.java | 11 +- .../mapstruct/ap/test/ignore/PreditorDto.java | 6 +- 7 files changed, 190 insertions(+), 22 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a41204c302..bf9d91cad2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -255,17 +255,31 @@ private boolean handleDefinedSourceMappings() { resultPropertyName = first( targetRef.getPropertyEntries() ).getName(); } - if (!unprocessedTargetProperties.containsKey( resultPropertyName ) ) { - boolean hasReadAccessor = + if ( !unprocessedTargetProperties.containsKey( resultPropertyName ) ) { + boolean hasReadAccessor = method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); - ctx.getMessager().printMessage( method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - hasReadAccessor ? Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE : + + if ( hasReadAccessor ) { + if ( !mapping.isIgnored() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue(), + Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, + mapping.getTargetName() ); + errorOccurred = true; + } + } + else { + ctx.getMessager().printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue(), Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, - mapping.getTargetName() - ); - errorOccurred = true; + mapping.getTargetName() ); + errorOccurred = true; + } + continue; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java new file mode 100644 index 0000000000..479c72df22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java @@ -0,0 +1,101 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1029; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Map; +import java.util.TreeMap; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Andreas Gudian + */ +@Mapper +public interface ErroneousIssue1029Mapper { + + /** + * reports unmapped properties 'lastUpdated' and 'computedMapping' + */ + Deck toDeck(DeckForm form); + + /** + * reports unmapped property 'lastUpdated'. Property 'outdated' is read-only anyway, but can still be ignored + * explicitly without raising any errors. + */ + @Mappings({ + @Mapping(target = "outdated", ignore = true), + @Mapping(target = "computedMapping", ignore = true) + }) + Deck toDeckWithSomeIgnores(DeckForm form); + + /** + * reports unknown property 'unknownProp' as error. + */ + @Mapping(target = "unknownProp", ignore = true) + Deck toDeckWithUnknownProperty(DeckForm form); + + class DeckForm { + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + } + + class Deck { + private Long id; + + private LocalDateTime lastUpdated; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public LocalDateTime getLastUpdated() { + return lastUpdated; + } + + public void setLastUpdated(LocalDateTime lastUpdated) { + this.lastUpdated = lastUpdated; + } + + // COMPUTED getters + + public boolean isOutdated() { + long daysBetween = ChronoUnit.DAYS.between( lastUpdated, LocalDateTime.now() ); + return daysBetween > 30; + } + + public Map getComputedMapping() { + return new TreeMap(); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java new file mode 100644 index 0000000000..0b2adeed62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1029; + +import javax.tools.Diagnostic.Kind; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Verifies that read-only properties can be explicitly mentioned as {@code ignored=true} without raising an error. + * + * @author Andreas Gudian + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(ErroneousIssue1029Mapper.class) +@IssueKey("1029") +public class Issue1029Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(kind = Kind.WARNING, line = 39, type = ErroneousIssue1029Mapper.class, + messageRegExp = "Unmapped target properties: \"lastUpdated, computedMapping\"\\."), + @Diagnostic(kind = Kind.WARNING, line = 49, type = ErroneousIssue1029Mapper.class, + messageRegExp = "Unmapped target property: \"lastUpdated\"\\."), + @Diagnostic(kind = Kind.ERROR, line = 54, type = ErroneousIssue1029Mapper.class, + messageRegExp = "Unknown property \"unknownProp\" in return type\\.") + }) + public void reportsProperWarningsAndError() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java index 0e2ee96355..eec8c64ded 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java @@ -32,7 +32,7 @@ public interface ErroneousTargetHasNoWriteAccessorMapper { ErroneousTargetHasNoWriteAccessorMapper INSTANCE = Mappers.getMapper( ErroneousTargetHasNoWriteAccessorMapper.class ); - @Mapping( target = "hasTallons", ignore = true ) + @Mapping(target = "hasClaws", constant = "true") PreditorDto preditorToDto( Preditor preditor ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 7eeec4a195..78ffc09f6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -18,9 +18,10 @@ */ package org.mapstruct.ap.test.ignore; -import javax.tools.Diagnostic.Kind; import static org.assertj.core.api.Assertions.assertThat; +import javax.tools.Diagnostic.Kind; + import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -88,9 +89,9 @@ public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTarget @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, kind = Kind.ERROR, line = 35, - messageRegExp = "Property \"hasTallons\" has no write accessor\\.") + messageRegExp = "Property \"hasClaws\" has no write accessor\\.") } ) - public void shouldGiveWringingOnUnmapped() { + public void shouldGiveErrorOnMappingForReadOnlyProp() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java index 449b5b2729..6a7deeb3eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java @@ -24,14 +24,13 @@ */ public class Preditor { - private boolean hasTallons; + private boolean hasClaws; - public boolean isHasTallons() { - return hasTallons; + public boolean isHasClaws() { + return hasClaws; } - public void setHasTallons(boolean hasTallons) { - this.hasTallons = hasTallons; + public void setHasClaws(boolean hasClaws) { + this.hasClaws = hasClaws; } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java index 816f96aedb..e20d6f9f12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java @@ -24,10 +24,10 @@ */ public class PreditorDto { - private boolean hasTallons; + private boolean hasClaws; - public boolean isHasTallons() { - return hasTallons; + public boolean isHasClaws() { + return hasClaws; } } From a69627de663b37adee46fdfa918fabe3f48a5c89 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 25 Dec 2016 14:01:14 +0100 Subject: [PATCH 0025/1006] #1013 Inherit(Reverse)Configuration must only consider abstract methods --- .../ap/internal/model/source/SourceMethod.java | 16 +++++++++++++--- .../CarMapperWithExplicitInheritance.java | 15 ++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 804180b807..09ae561e47 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -185,7 +185,7 @@ public Builder setDefininingType(Type definingType) { public SourceMethod build() { MappingOptions mappingOptions = - new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings ); + new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings ); SourceMethod sourceMethod = new SourceMethod( declaringMapper, @@ -334,7 +334,8 @@ public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { } public boolean reverses(SourceMethod method) { - return getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 + return isAbstract() + && getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 && equals( first( getSourceParameters() ).getType(), method.getResultType() ) && equals( getResultType(), first( method.getSourceParameters() ).getType() ); } @@ -346,7 +347,8 @@ && equals( first( getSourceParameters() ).getType(), first( method.getSourcePara } public boolean canInheritFrom(SourceMethod method) { - return isMapMapping() == method.isMapMapping() + return method.isAbstract() + && isMapMapping() == method.isMapMapping() && isIterableMapping() == method.isIterableMapping() && isEnumMapping() == method.isEnumMapping() && getResultType().isAssignableTo( method.getResultType() ) @@ -602,6 +604,14 @@ public boolean isBeforeMappingMethod() { return Executables.isBeforeMappingMethod( getExecutable() ); } + /** + * @return returns true for interface methods (see jls 9.4) lacking a default or static modifier and for abstract + * methods + */ + public boolean isAbstract() { + return executable.getModifiers().contains( Modifier.ABSTRACT ); + } + @Override public boolean isUpdateMethod() { return getMappingTargetParameter() != null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java index c7df3a98e4..365b2db57d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java @@ -23,6 +23,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; /** @@ -32,17 +33,21 @@ config = AutoInheritedConfig.class, mappingInheritanceStrategy = MappingInheritanceStrategy.EXPLICIT ) -public interface CarMapperWithExplicitInheritance { - CarMapperWithExplicitInheritance INSTANCE = Mappers.getMapper( CarMapperWithExplicitInheritance.class ); +public abstract class CarMapperWithExplicitInheritance { + public static final CarMapperWithExplicitInheritance INSTANCE = + Mappers.getMapper( CarMapperWithExplicitInheritance.class ); @InheritConfiguration(name = "baseDtoToEntity") @Mapping(target = "color", source = "colour") - CarEntity toCarEntity(CarDto carDto); + public abstract CarEntity toCarEntity(CarDto carDto); @InheritInverseConfiguration(name = "toCarEntity") - CarDto toCarDto(CarEntity entity); + public abstract CarDto toCarDto(CarEntity entity); @InheritConfiguration(name = "toCarEntity") @Mapping(target = "auditTrail", constant = "fixed") - CarEntity toCarEntityWithFixedAuditTrail(CarDto carDto); + public abstract CarEntity toCarEntityWithFixedAuditTrail(CarDto carDto); + + // this method should not be considered. See issue #1013 + public void toCarEntity(CarDto carDto, @MappingTarget CarEntity carEntity) { } } From 1ee4731752fd88dd1e72a54ee347649ce36e2e9e Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 8 Jan 2017 20:18:27 +0100 Subject: [PATCH 0026/1006] #1027 do not consider Inherit(Inverse)Configuration in used mappers --- .../mapstruct-reference-guide.asciidoc | 10 +++++ .../internal/model/source/SourceMethod.java | 6 ++- .../CarMapperWithExplicitInheritance.java | 1 + .../InheritFromConfigTest.java | 3 +- .../inheritfromconfig/NotToBeUsedMapper.java | 38 +++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 171e9d39db..5a3560e306 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1869,6 +1869,11 @@ In case more than one method is applicable as source for the inheritance, the me A method can use `@InheritConfiguration` and override or amend the configuration by additionally applying `@Mapping`, `@BeanMapping`, etc. +[NOTE] +==== +`@InheritConfiguration` cannot refer to methods in a used mapper. +==== + [[inverse-mappings]] === Inverse mappings @@ -1905,6 +1910,11 @@ If multiple methods qualify, the method from which to inherit the configuration Expressions and constants are excluded (silently ignored). Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. +[NOTE] +==== +`@InheritInverseConfiguration` cannot refer to methods in a used mapper. +==== + [[shared-configurations]] === Shared configurations diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 09ae561e47..a012c119ab 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -334,7 +334,8 @@ public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { } public boolean reverses(SourceMethod method) { - return isAbstract() + return getDeclaringMapper() == null + && isAbstract() && getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 && equals( first( getSourceParameters() ).getType(), method.getResultType() ) && equals( getResultType(), first( method.getSourceParameters() ).getType() ); @@ -347,7 +348,8 @@ && equals( first( getSourceParameters() ).getType(), first( method.getSourcePara } public boolean canInheritFrom(SourceMethod method) { - return method.isAbstract() + return method.getDeclaringMapper() == null + && method.isAbstract() && isMapMapping() == method.isMapMapping() && isIterableMapping() == method.isIterableMapping() && isEnumMapping() == method.isEnumMapping() diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java index 365b2db57d..0cced4dd12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java @@ -30,6 +30,7 @@ * @author Andreas Gudian */ @Mapper( + uses = NotToBeUsedMapper.class, config = AutoInheritedConfig.class, mappingInheritanceStrategy = MappingInheritanceStrategy.EXPLICIT ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index 6bbbcfb850..bfa84a3f24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -42,7 +42,8 @@ CarEntity.class, CarMapperWithAutoInheritance.class, CarMapperWithExplicitInheritance.class, - AutoInheritedConfig.class + AutoInheritedConfig.class, + NotToBeUsedMapper.class }) @IssueKey("168") public class InheritFromConfigTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java new file mode 100644 index 0000000000..eb2f75c297 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface NotToBeUsedMapper { + + @Mappings({ + @Mapping(target = "primaryKey", ignore = true), + @Mapping(target = "auditTrail", ignore = true), + @Mapping(target = "color", ignore = true) + }) + CarEntity toCarEntity(CarDto carDto); +} From 090cfe3db235953c4a4ecd36bb72ce82b26a9b28 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 27 Dec 2016 17:09:38 +0100 Subject: [PATCH 0027/1006] #1012 extract common class between IterableMappingMethod and StreamMappingMethod --- .../internal/model/IterableMappingMethod.java | 168 +-------------- .../internal/model/StreamMappingMethod.java | 162 ++------------- .../model/WithElementMappingMethod.java | 195 ++++++++++++++++++ 3 files changed, 218 insertions(+), 307 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index b4e357f339..c8e1cf577b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -20,17 +20,13 @@ import static org.mapstruct.ap.internal.util.Collections.first; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.lang.model.type.TypeKind; - import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; -import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; @@ -47,14 +43,7 @@ * * @author Gunnar Morling */ -public class IterableMappingMethod extends MappingMethod { - - private final Assignment elementAssignment; - private final MethodReference factoryMethod; - private final boolean overridden; - private final boolean mapNullToDefault; - private final String loopVariableName; - private final SelectionParameters selectionParameters; +public class IterableMappingMethod extends WithElementMappingMethod { public static class Builder { @@ -231,81 +220,17 @@ private IterableMappingMethod(Method method, Assignment parameterAssignment, Met List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters, ForgedMethod forgedMethod) { - super( method, beforeMappingReferences, afterMappingReferences, - forgedMethod == null ? Collections.emptyList() : - java.util.Collections.singletonList( forgedMethod ) + super( + method, + parameterAssignment, + factoryMethod, + mapNullToDefault, + loopVariableName, + beforeMappingReferences, + afterMappingReferences, + selectionParameters, + forgedMethod ); - this.elementAssignment = parameterAssignment; - this.factoryMethod = factoryMethod; - this.overridden = method.overridesMethod(); - this.mapNullToDefault = mapNullToDefault; - this.loopVariableName = loopVariableName; - this.selectionParameters = selectionParameters; - } - - public Parameter getSourceParameter() { - for ( Parameter parameter : getParameters() ) { - if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { - return parameter; - } - } - - throw new IllegalStateException( "Method " + this + " has no source parameter." ); - } - - public Assignment getElementAssignment() { - return elementAssignment; - } - - @Override - public Set getImportTypes() { - Set types = super.getImportTypes(); - if ( elementAssignment != null ) { - types.addAll( elementAssignment.getImportTypes() ); - } - if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { - if ( getReturnType().getImplementationType() != null ) { - types.addAll( getReturnType().getImplementationType().getImportTypes() ); - } - } - return types; - } - - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - - public boolean isOverridden() { - return overridden; - } - - public String getLoopVariableName() { - return loopVariableName; - } - - public String getDefaultValue() { - TypeKind kind = getResultElementType().getTypeMirror().getKind(); - switch ( kind ) { - case BOOLEAN: - return "false"; - case BYTE: - case SHORT: - case INT: - case CHAR: /*"'\u0000'" would have been better, but depends on platformencoding */ - return "0"; - case LONG: - return "0L"; - case FLOAT: - return "0.0f"; - case DOUBLE: - return "0.0d"; - default: - return "null"; - } - } - - public MethodReference getFactoryMethod() { - return this.factoryMethod; } public Type getSourceElementType() { @@ -327,75 +252,4 @@ public Type getResultElementType() { return first( getResultType().determineTypeArguments( Iterable.class ) ); } } - - public String getIndex1Name() { - return Strings.getSaveVariableName( "i", loopVariableName, getSourceParameter().getName(), getResultName() ); - } - - public String getIndex2Name() { - return Strings.getSaveVariableName( "j", loopVariableName, getSourceParameter().getName(), getResultName() ); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); - return result; - } - - @Override - public boolean equals(Object obj) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - IterableMappingMethod other = (IterableMappingMethod) obj; - - if ( !getResultType().equals( other.getResultType() ) ) { - return false; - } - - if ( getSourceParameters().size() != other.getSourceParameters().size() ) { - return false; - } - - for ( int i = 0; i < getSourceParameters().size(); i++ ) { - if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { - return false; - } - List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); - List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); - - if ( !thisTypeParameters.equals( otherTypeParameters ) ) { - return false; - } - } - - if ( this.selectionParameters != null ) { - if ( !this.selectionParameters.equals( other.selectionParameters ) ) { - return false; - } - } - else if ( other.selectionParameters != null ) { - return false; - } - - if ( this.factoryMethod != null ) { - if ( !this.factoryMethod.equals( other.factoryMethod ) ) { - return false; - } - } - else if ( other.factoryMethod != null ) { - return false; - } - - return isMapNullToDefault() == other.isMapNullToDefault(); - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 929a03317e..69adc95ea8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -18,19 +18,15 @@ */ package org.mapstruct.ap.internal.model; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import javax.lang.model.type.TypeKind; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; -import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; @@ -49,14 +45,8 @@ * * @author Filip Hrisafov */ -public class StreamMappingMethod extends MappingMethod { - - private final Assignment elementAssignment; - private final MethodReference factoryMethod; - private final boolean overridden; - private final boolean mapNullToDefault; - private final String loopVariableName; - private final SelectionParameters selectionParameters; +public class StreamMappingMethod extends WithElementMappingMethod { + private final Set helperImports; public static class Builder { @@ -237,86 +227,29 @@ private StreamMappingMethod(Method method, Assignment parameterAssignment, Metho List afterMappingReferences, SelectionParameters selectionParameters, Set helperImports, ForgedMethod forgedMethod) { - super( method, beforeMappingReferences, afterMappingReferences, - forgedMethod == null ? new ArrayList() : Collections.singletonList( forgedMethod ) + super( + method, + parameterAssignment, + factoryMethod, + mapNullToDefault, + loopVariableName, + beforeMappingReferences, + afterMappingReferences, + selectionParameters, + forgedMethod ); - this.elementAssignment = parameterAssignment; - this.factoryMethod = factoryMethod; - this.overridden = method.overridesMethod(); - this.mapNullToDefault = mapNullToDefault; - this.loopVariableName = loopVariableName; - this.selectionParameters = selectionParameters; this.helperImports = helperImports; } - public Parameter getSourceParameter() { - for ( Parameter parameter : getParameters() ) { - if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { - return parameter; - } - } - - throw new IllegalStateException( "Method " + this + " has no source parameter." ); - } - - public Assignment getElementAssignment() { - return elementAssignment; - } - @Override public Set getImportTypes() { Set types = super.getImportTypes(); - if ( elementAssignment != null ) { - types.addAll( elementAssignment.getImportTypes() ); - } - if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { - if ( getReturnType().getImplementationType() != null ) { - types.addAll( getReturnType().getImplementationType().getImportTypes() ); - } - } types.addAll( helperImports ); return types; } - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - - public boolean isOverridden() { - return overridden; - } - - public String getLoopVariableName() { - return loopVariableName; - } - - public String getDefaultValue() { - TypeKind kind = getResultElementType().getTypeMirror().getKind(); - switch ( kind ) { - case BOOLEAN: - return "false"; - case BYTE: - case SHORT: - case INT: - case CHAR: /*"'\u0000'" would have been better, but depends on platformencoding */ - return "0"; - case LONG: - return "0L"; - case FLOAT: - return "0.0f"; - case DOUBLE: - return "0.0d"; - default: - return "null"; - } - } - - public MethodReference getFactoryMethod() { - return this.factoryMethod; - } - public Type getSourceElementType() { return getElementType( getSourceParameter().getType() ); } @@ -325,77 +258,6 @@ public Type getResultElementType() { return getElementType( getResultType() ); } - public String getIndex1Name() { - return Strings.getSaveVariableName( "i", loopVariableName, getSourceParameter().getName(), getResultName() ); - } - - public String getIndex2Name() { - return Strings.getSaveVariableName( "j", loopVariableName, getSourceParameter().getName(), getResultName() ); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); - return result; - } - - @Override - public boolean equals(Object obj) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - StreamMappingMethod other = (StreamMappingMethod) obj; - - if ( !getResultType().equals( other.getResultType() ) ) { - return false; - } - - if ( getSourceParameters().size() != other.getSourceParameters().size() ) { - return false; - } - - for ( int i = 0; i < getSourceParameters().size(); i++ ) { - if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { - return false; - } - - List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); - List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); - - if ( !thisTypeParameters.equals( otherTypeParameters ) ) { - return false; - } - } - - if ( this.selectionParameters != null ) { - if ( !this.selectionParameters.equals( other.selectionParameters ) ) { - return false; - } - } - else if ( other.selectionParameters != null ) { - return false; - } - - if ( this.factoryMethod != null ) { - if ( !this.factoryMethod.equals( other.factoryMethod ) ) { - return false; - } - } - else if ( other.factoryMethod != null ) { - return false; - } - - return isMapNullToDefault() == other.isMapNullToDefault(); - } - private static Type getElementType(Type parameterType) { if ( parameterType.isArrayType() ) { return parameterType.getComponentType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java new file mode 100644 index 0000000000..86440c638f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java @@ -0,0 +1,195 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import javax.lang.model.type.TypeKind; + +import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.util.Strings; + +/** + * A {@link MappingMethod} implemented by a {@link Mapper} class which does mapping of typed based methods. + * For example Iterable or Stream. + * The typed elements are mapped either by a {@link TypeConversion} or another mapping method. + * + * @author Filip Hrisafov + */ +abstract class WithElementMappingMethod extends MappingMethod { + private final Assignment elementAssignment; + private final MethodReference factoryMethod; + private final boolean overridden; + private final boolean mapNullToDefault; + private final String loopVariableName; + private final SelectionParameters selectionParameters; + + WithElementMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, + boolean mapNullToDefault, String loopVariableName, + List beforeMappingReferences, + List afterMappingReferences, + SelectionParameters selectionParameters, ForgedMethod forgedMethod) { + super( method, beforeMappingReferences, afterMappingReferences, + forgedMethod == null ? Collections.emptyList() : + java.util.Collections.singletonList( forgedMethod ) + ); + this.elementAssignment = parameterAssignment; + this.factoryMethod = factoryMethod; + this.overridden = method.overridesMethod(); + this.mapNullToDefault = mapNullToDefault; + this.loopVariableName = loopVariableName; + this.selectionParameters = selectionParameters; + } + + public Parameter getSourceParameter() { + for ( Parameter parameter : getParameters() ) { + if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { + return parameter; + } + } + + throw new IllegalStateException( "Method " + this + " has no source parameter." ); + } + + public Assignment getElementAssignment() { + return elementAssignment; + } + + @Override + public Set getImportTypes() { + Set types = super.getImportTypes(); + if ( elementAssignment != null ) { + types.addAll( elementAssignment.getImportTypes() ); + } + if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { + if ( getReturnType().getImplementationType() != null ) { + types.addAll( getReturnType().getImplementationType().getImportTypes() ); + } + } + return types; + } + + public boolean isMapNullToDefault() { + return mapNullToDefault; + } + + public boolean isOverridden() { + return overridden; + } + + public String getLoopVariableName() { + return loopVariableName; + } + + public String getDefaultValue() { + TypeKind kind = getResultElementType().getTypeMirror().getKind(); + switch ( kind ) { + case BOOLEAN: + return "false"; + case BYTE: + case SHORT: + case INT: + case CHAR: /*"'\u0000'" would have been better, but depends on platformencoding */ + return "0"; + case LONG: + return "0L"; + case FLOAT: + return "0.0f"; + case DOUBLE: + return "0.0d"; + default: + return "null"; + } + } + + public MethodReference getFactoryMethod() { + return this.factoryMethod; + } + + public abstract Type getResultElementType(); + + public String getIndex1Name() { + return Strings.getSaveVariableName( "i", loopVariableName, getSourceParameter().getName(), getResultName() ); + } + + public String getIndex2Name() { + return Strings.getSaveVariableName( "j", loopVariableName, getSourceParameter().getName(), getResultName() ); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + WithElementMappingMethod other = (WithElementMappingMethod) obj; + + if ( !getResultType().equals( other.getResultType() ) ) { + return false; + } + + if ( getSourceParameters().size() != other.getSourceParameters().size() ) { + return false; + } + + for ( int i = 0; i < getSourceParameters().size(); i++ ) { + if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { + return false; + } + List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); + List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); + + if ( !thisTypeParameters.equals( otherTypeParameters ) ) { + return false; + } + } + + if ( this.selectionParameters != null ) { + if ( !this.selectionParameters.equals( other.selectionParameters ) ) { + return false; + } + } + else if ( other.selectionParameters != null ) { + return false; + } + + return isMapNullToDefault() == other.isMapNullToDefault(); + } + +} From 029368494bdc118a34060ecdfd9f95cf7aa46e21 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 27 Dec 2016 19:39:48 +0100 Subject: [PATCH 0028/1006] #1012 extract common builder for the StreamMappingMethods and IterableMappingMethod --- .../model/AbstractMappingMethodBuilder.java | 43 ++++ .../internal/model/IterableMappingMethod.java | 169 ++------------ .../ap/internal/model/PropertyMapping.java | 23 +- .../internal/model/StreamMappingMethod.java | 162 ++----------- .../model/WithElementMappingMethod.java | 2 +- .../WithElementMappingMethodBuilder.java | 213 ++++++++++++++++++ .../processor/MapperCreationProcessor.java | 48 ++-- 7 files changed, 320 insertions(+), 340 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java new file mode 100644 index 0000000000..683e1c8e6d --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.internal.model; + +/** + * An abstract builder that can be reused for building {@link MappingMethod}(s). + * + * @author Filip Hrisafov + */ +public abstract class AbstractMappingMethodBuilder, + M extends MappingMethod> { + + protected B myself; + protected MappingBuilderContext ctx; + + public AbstractMappingMethodBuilder(Class selfType) { + myself = selfType.cast( this ); + } + + public B mappingContext(MappingBuilderContext mappingContext) { + this.ctx = mappingContext; + return myself; + } + + public abstract M build(); +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index c8e1cf577b..989add6e9e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -20,22 +20,15 @@ import static org.mapstruct.ap.internal.util.Collections.first; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; -import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.util.Strings; /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one iterable type to another. The collection @@ -45,119 +38,36 @@ */ public class IterableMappingMethod extends WithElementMappingMethod { - public static class Builder { + public static class Builder extends WithElementMappingMethodBuilder { - private Method method; - private MappingBuilderContext ctx; - private SelectionParameters selectionParameters; - private FormattingParameters formattingParameters; - private NullValueMappingStrategyPrism nullValueMappingStrategy; - private ForgedMethod forgedMethod; - private String callingContextTargetPropertyName; - - public Builder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public Builder method(Method sourceMethod) { - this.method = sourceMethod; - return this; - } - - public Builder formattingParameters(FormattingParameters formattingParameters) { - this.formattingParameters = formattingParameters; - return this; - } - - public Builder selectionParameters(SelectionParameters selectionParameters) { - this.selectionParameters = selectionParameters; - return this; + public Builder() { + super( Builder.class, "collection element" ); } - public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) { - this.nullValueMappingStrategy = nullValueMappingStrategy; - return this; + @Override + protected Type getElementType(Type parameterType) { + return parameterType.isArrayType() ? parameterType.getComponentType() : first( + parameterType.determineTypeArguments( Iterable.class ) ).getTypeBound(); } - public Builder callingContextTargetPropertyName(String callingContextTargetPropertyName) { - this.callingContextTargetPropertyName = callingContextTargetPropertyName; - return this; - } - - public IterableMappingMethod build() { - - - Type sourceParameterType = first( method.getSourceParameters() ).getType(); + @Override + protected Assignment getWrapper(Assignment assignment, Method method) { Type resultType = method.getResultType(); - - Type sourceElementType = - sourceParameterType.isArrayType() ? sourceParameterType.getComponentType() : first( - sourceParameterType.determineTypeArguments( Iterable.class ) ).getTypeBound(); - Type targetElementType = - resultType.isArrayType() ? resultType.getComponentType() : first( - resultType.determineTypeArguments( Iterable.class ) ).getTypeBound(); - - String loopVariableName = - Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() ); - - SourceRHS sourceRHS = new SourceRHS( loopVariableName, sourceElementType, new HashSet(), - "collection element" ); - Assignment assignment = ctx.getMappingResolver().getTargetAssignment( - method, - targetElementType, - callingContextTargetPropertyName, - formattingParameters, - selectionParameters, - sourceRHS, - false - ); - - if ( assignment == null ) { - - assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); - - } - else { - if ( method instanceof ForgedMethod ) { - ForgedMethod forgedMethod = (ForgedMethod) method; - forgedMethod.addThrownTypes( assignment.getThrownTypes() ); - - } - } // target accessor is setter, so decorate assignment as setter if ( resultType.isArrayType() ) { - assignment = new LocalVarWrapper( assignment, method.getThrownTypes(), resultType, false ); + return new LocalVarWrapper( assignment, method.getThrownTypes(), resultType, false ); } else { - assignment = new SetterWrapper( assignment, method.getThrownTypes(), false ); + return new SetterWrapper( assignment, method.getThrownTypes(), false ); } + } - // mapNullToDefault - boolean mapNullToDefault = false; - if ( method.getMapperConfiguration() != null ) { - mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); - } - - MethodReference factoryMethod = null; - if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); - } - - Set existingVariables = new HashSet( method.getParameterNames() ); - existingVariables.add( loopVariableName ); - - List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( - method, - selectionParameters, - ctx, - existingVariables ); - List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( - method, - selectionParameters, - ctx, - existingVariables ); - + @Override + protected IterableMappingMethod instantiateMappingMethod(Method method, Assignment assignment, + MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, + List beforeMappingMethods, + List afterMappingMethods, SelectionParameters selectionParameters, + ForgedMethod forgedMethod) { return new IterableMappingMethod( method, assignment, @@ -170,49 +80,6 @@ public IterableMappingMethod build() { forgedMethod ); } - - private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { - - ForgedMethodHistory forgedMethodHistory = null; - if ( method instanceof ForgedMethod ) { - forgedMethodHistory = ( (ForgedMethod) method ).getHistory(); - } - String name = getName( sourceType, targetType ); - forgedMethod = new ForgedMethod( - name, - sourceType, - targetType, - method.getMapperConfiguration(), - method.getExecutable(), - method.getContextParameters(), - forgedMethodHistory - ); - - Assignment assignment = new MethodReference( - forgedMethod, - null, - ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); - - assignment.setAssignment( sourceRHS ); - - return assignment; - } - - private String getName(Type sourceType, Type targetType) { - String fromName = getName( sourceType ); - String toName = getName( targetType ); - return Strings.decapitalize( fromName + "To" + toName ); - } - - private String getName(Type type) { - StringBuilder builder = new StringBuilder(); - for ( Type typeParam : type.getTypeParameters() ) { - builder.append( typeParam.getIdentification() ); - } - builder.append( type.getIdentification() ); - return builder.toString(); - } - } private IterableMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 8ab6ff6c05..3cb7e139df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -232,7 +232,6 @@ public PropertyMapping build() { this.rightHandSide = getSourceRHS( sourceReference ); rightHandSide.setUseElementAsSourceTypeForMatching( targetWriteAccessorType == TargetWriteAccessorType.ADDER ); - Type sourceType = rightHandSide.getSourceType(); // all the tricky cases will be excluded for the time being. boolean preferUpdateMethods; @@ -253,6 +252,7 @@ public PropertyMapping build() { preferUpdateMethods ); + Type sourceType = rightHandSide.getSourceType(); // No mapping found. Try to forge a mapping if ( assignment == null ) { if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) { @@ -540,26 +540,23 @@ private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { private Assignment forgeStreamMapping(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element) { - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); - StreamMappingMethod.Builder builder = new StreamMappingMethod.Builder(); - StreamMappingMethod streamMappingMethod = builder - .mappingContext( ctx ) - .method( methodRef ) - .selectionParameters( selectionParameters ) - .callingContextTargetPropertyName( targetPropertyName ) - .build(); - - return getForgedAssignment( source, methodRef, streamMappingMethod ); + return forgeWithElementMapping( sourceType, targetType, source, element, builder ); } private Assignment forgeIterableMapping(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element) { - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); IterableMappingMethod.Builder builder = new IterableMappingMethod.Builder(); + return forgeWithElementMapping( sourceType, targetType, source, element, builder ); + } + + private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source, + ExecutableElement element, WithElementMappingMethodBuilder builder) { + + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); - IterableMappingMethod iterableMappingMethod = builder + WithElementMappingMethod iterableMappingMethod = builder .mappingContext( ctx ) .method( methodRef ) .selectionParameters( selectionParameters ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 69adc95ea8..ebf68019fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -27,15 +27,10 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; -import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.util.Strings; import static org.mapstruct.ap.internal.util.Collections.first; @@ -49,116 +44,35 @@ public class StreamMappingMethod extends WithElementMappingMethod { private final Set helperImports; - public static class Builder { + public static class Builder extends WithElementMappingMethodBuilder { - private Method method; - private MappingBuilderContext ctx; - private SelectionParameters selectionParameters; - private FormattingParameters formattingParameters; - private NullValueMappingStrategyPrism nullValueMappingStrategy; - private ForgedMethod forgedMethod; - private String callingContextTargetPropertyName; - - public Builder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public Builder method(Method sourceMethod) { - this.method = sourceMethod; - return this; - } - - public Builder formattingParameters(FormattingParameters formattingParameters) { - this.formattingParameters = formattingParameters; - return this; - } - - public Builder selectionParameters(SelectionParameters selectionParameters) { - this.selectionParameters = selectionParameters; - return this; + public Builder() { + super( Builder.class, "stream element" ); } - public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) { - this.nullValueMappingStrategy = nullValueMappingStrategy; - return this; + @Override + protected Type getElementType(Type parameterType) { + return StreamMappingMethod.getElementType( parameterType ); } - public Builder callingContextTargetPropertyName(String callingContextTargetPropertyName) { - this.callingContextTargetPropertyName = callingContextTargetPropertyName; - return this; + @Override + protected Assignment getWrapper(Assignment assignment, Method method) { + return new Java8FunctionWrapper( assignment ); } - public StreamMappingMethod build() { - //TODO the building of the methods is the same as the IterableMappingMethod, the only difference being - // the static extracted getElementType and the wrapper of the assignment using Java8FunctionWrapper - - Type sourceParameterType = first( method.getSourceParameters() ).getType(); - Type resultType = method.getResultType(); - - Type sourceElementType = getElementType( sourceParameterType ); - Type targetElementType = getElementType( resultType ); - - String loopVariableName = - Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() ); - - SourceRHS sourceRHS = new SourceRHS( loopVariableName, sourceElementType, new HashSet(), - "stream element" - ); - Assignment assignment = ctx.getMappingResolver().getTargetAssignment( - method, - targetElementType, - callingContextTargetPropertyName, - formattingParameters, - selectionParameters, - sourceRHS, - false - ); - - if ( assignment == null ) { - assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); - } - else { - if ( method instanceof ForgedMethod ) { - ForgedMethod forgedMethod = (ForgedMethod) method; - forgedMethod.addThrownTypes( assignment.getThrownTypes() ); - } - } - - assignment = new Java8FunctionWrapper( assignment ); - - // mapNullToDefault - boolean mapNullToDefault = false; - if ( method.getMapperConfiguration() != null ) { - mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); - } - - MethodReference factoryMethod = null; - if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); - } - - Set existingVariables = new HashSet( method.getParameterNames() ); - existingVariables.add( loopVariableName ); - - List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( - method, - selectionParameters, - ctx, - existingVariables - ); - List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( - method, - selectionParameters, - ctx, - existingVariables - ); + @Override + protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment assignment, + MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, + List beforeMappingMethods, + List afterMappingMethods, SelectionParameters selectionParameters, + ForgedMethod forgedMethod) { Set helperImports = new HashSet(); - if ( resultType.isIterableType() ) { + if ( method.getResultType().isIterableType() ) { helperImports.add( ctx.getTypeFactory().getType( Collectors.class ) ); } + Type sourceParameterType = first( method.getSourceParameters() ).getType(); if ( !sourceParameterType.isCollectionType() && !sourceParameterType.isArrayType() && sourceParameterType.isIterableType() ) { helperImports.add( ctx.getTypeFactory().getType( StreamSupport.class ) ); @@ -177,48 +91,6 @@ public StreamMappingMethod build() { forgedMethod ); } - - private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { - ForgedMethodHistory forgedMethodHistory = null; - if ( method instanceof ForgedMethod ) { - forgedMethodHistory = ( (ForgedMethod) method ).getHistory(); - } - String name = getName( sourceType, targetType ); - forgedMethod = new ForgedMethod( - name, - sourceType, - targetType, - method.getMapperConfiguration(), - method.getExecutable(), - method.getContextParameters(), - forgedMethodHistory - ); - - Assignment assignment = new MethodReference( - forgedMethod, - null, - ParameterBinding.fromParameters( forgedMethod.getParameters() ) - ); - - assignment.setAssignment( sourceRHS ); - - return assignment; - } - - private String getName(Type sourceType, Type targetType) { - String fromName = getName( sourceType ); - String toName = getName( targetType ); - return Strings.decapitalize( fromName + "To" + toName ); - } - - private String getName(Type type) { - StringBuilder builder = new StringBuilder(); - for ( Type typeParam : type.getTypeParameters() ) { - builder.append( typeParam.getIdentification() ); - } - builder.append( type.getIdentification() ); - return builder.toString(); - } } private StreamMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java index 86440c638f..e1f45c37ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java @@ -39,7 +39,7 @@ * * @author Filip Hrisafov */ -abstract class WithElementMappingMethod extends MappingMethod { +public abstract class WithElementMappingMethod extends MappingMethod { private final Assignment elementAssignment; private final MethodReference factoryMethod; private final boolean overridden; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java new file mode 100644 index 0000000000..2073ef0df2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java @@ -0,0 +1,213 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; +import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.util.Strings; + +import static org.mapstruct.ap.internal.util.Collections.first; + +/** + * Builder that can be used to build {@link WithElementMappingMethod}(s). + * + * @author Filip Hrisafov + */ +public abstract class WithElementMappingMethodBuilder, + M extends WithElementMappingMethod> extends AbstractMappingMethodBuilder { + + private Method method; + private SelectionParameters selectionParameters; + private FormattingParameters formattingParameters; + private NullValueMappingStrategyPrism nullValueMappingStrategy; + private ForgedMethod forgedMethod; + private String errorMessagePart; + private String callingContextTargetPropertyName; + + WithElementMappingMethodBuilder(Class selfType, String errorMessagePart) { + super( selfType ); + this.errorMessagePart = errorMessagePart; + } + + public B method(Method sourceMethod) { + this.method = sourceMethod; + return myself; + } + + public B formattingParameters(FormattingParameters formattingParameters) { + this.formattingParameters = formattingParameters; + return myself; + } + + public B selectionParameters(SelectionParameters selectionParameters) { + this.selectionParameters = selectionParameters; + return myself; + } + + public B nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) { + this.nullValueMappingStrategy = nullValueMappingStrategy; + return myself; + } + + public B callingContextTargetPropertyName(String callingContextTargetPropertyName) { + this.callingContextTargetPropertyName = callingContextTargetPropertyName; + return myself; + } + + public final M build() { + Type sourceParameterType = first( method.getSourceParameters() ).getType(); + Type resultType = method.getResultType(); + + Type sourceElementType = getElementType( sourceParameterType ); + Type targetElementType = getElementType( resultType ); + + String loopVariableName = + Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() ); + + SourceRHS sourceRHS = new SourceRHS( + loopVariableName, + sourceElementType, + new HashSet(), + errorMessagePart + ); + Assignment assignment = ctx.getMappingResolver().getTargetAssignment( + method, + targetElementType, + callingContextTargetPropertyName, + formattingParameters, + selectionParameters, + sourceRHS, + false + ); + + if ( assignment == null ) { + assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); + } + else { + if ( method instanceof ForgedMethod ) { + ForgedMethod forgedMethod = (ForgedMethod) method; + forgedMethod.addThrownTypes( assignment.getThrownTypes() ); + } + } + + assignment = getWrapper( assignment, method ); + + // mapNullToDefault + boolean mapNullToDefault = false; + if ( method.getMapperConfiguration() != null ) { + mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); + } + + MethodReference factoryMethod = null; + if ( !method.isUpdateMethod() ) { + factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); + } + + Set existingVariables = new HashSet( method.getParameterNames() ); + existingVariables.add( loopVariableName ); + + List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( + method, + selectionParameters, + ctx, + existingVariables + ); + List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( + method, + selectionParameters, + ctx, + existingVariables + ); + + return instantiateMappingMethod( + method, + assignment, + factoryMethod, + mapNullToDefault, + loopVariableName, + beforeMappingMethods, + afterMappingMethods, + selectionParameters, + forgedMethod + ); + } + + protected abstract M instantiateMappingMethod(Method method, Assignment assignment, MethodReference factoryMethod, + boolean mapNullToDefault, String loopVariableName, + List beforeMappingMethods, + List afterMappingMethods, + SelectionParameters selectionParameters, ForgedMethod forgedMethod); + + protected abstract Type getElementType(Type parameterType); + + protected abstract Assignment getWrapper(Assignment assignment, Method method); + + private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + ForgedMethodHistory forgedMethodHistory = null; + if ( method instanceof ForgedMethod ) { + forgedMethodHistory = ( (ForgedMethod) method ).getHistory(); + } + String name = getName( sourceType, targetType ); + forgedMethod = new ForgedMethod( + name, + sourceType, + targetType, + method.getMapperConfiguration(), + method.getExecutable(), + method.getContextParameters(), + forgedMethodHistory + ); + + Assignment assignment = new MethodReference( + forgedMethod, + null, + ParameterBinding.fromParameters( forgedMethod.getParameters() ) + ); + + assignment.setAssignment( sourceRHS ); + + return assignment; + } + + private String getName(Type sourceType, Type targetType) { + String fromName = getName( sourceType ); + String toName = getName( targetType ); + return Strings.decapitalize( fromName + "To" + toName ); + } + + private String getName(Type type) { + StringBuilder builder = new StringBuilder(); + for ( Type typeParam : type.getTypeParameters() ) { + builder.append( typeParam.getIdentification() ); + } + builder.append( type.getIdentification() ); + return builder.toString(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 1195b435ae..6ddc71b3a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -18,10 +18,6 @@ */ package org.mapstruct.ap.internal.processor; -import static org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism.AUTO_INHERIT_FROM_CONFIG; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.join; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -31,7 +27,6 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeKind; @@ -53,6 +48,8 @@ import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.StreamMappingMethod; import org.mapstruct.ap.internal.model.ValueMappingMethod; +import org.mapstruct.ap.internal.model.WithElementMappingMethod; +import org.mapstruct.ap.internal.model.WithElementMappingMethodBuilder; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; @@ -74,6 +71,10 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; +import static org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism.AUTO_INHERIT_FROM_CONFIG; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.join; + /** * A {@link ModelElementProcessor} which creates a {@link Mapper} from the given * list of {@link SourceMethod}s. @@ -332,26 +333,11 @@ private List getMappingMethods(MapperConfiguration mapperConfig, boolean hasFactoryMethod = false; if ( method.isIterableMapping() ) { - - IterableMappingMethod.Builder builder = new IterableMappingMethod.Builder(); - - FormattingParameters formattingParameters = null; - SelectionParameters selectionParameters = null; - NullValueMappingStrategyPrism nullValueMappingStrategy = null; - - if ( mappingOptions.getIterableMapping() != null ) { - formattingParameters = mappingOptions.getIterableMapping().getFormattingParameters(); - selectionParameters = mappingOptions.getIterableMapping().getSelectionParameters(); - nullValueMappingStrategy = mappingOptions.getIterableMapping().getNullValueMappingStrategy(); - } - - IterableMappingMethod iterableMappingMethod = builder - .mappingContext( mappingContext ) - .method( method ) - .formattingParameters( formattingParameters ) - .selectionParameters( selectionParameters ) - .nullValueMappingStrategy( nullValueMappingStrategy ) - .build(); + IterableMappingMethod iterableMappingMethod = createWithElementMappingMethod( + method, + mappingOptions, + new IterableMappingMethod.Builder() + ); hasFactoryMethod = iterableMappingMethod.getFactoryMethod() != null; mappingMethods.add( iterableMappingMethod ); @@ -413,7 +399,11 @@ else if ( method.isEnumMapping() ) { } } else if ( method.isStreamMapping() ) { - StreamMappingMethod streamMappingMethod = createStreamMappingMethod( method, mappingOptions ); + StreamMappingMethod streamMappingMethod = createWithElementMappingMethod( + method, + mappingOptions, + new StreamMappingMethod.Builder() + ); // If we do StreamMapping that means that internally there is a way to generate the result type hasFactoryMethod = @@ -456,10 +446,8 @@ else if ( method.isStreamMapping() ) { return mappingMethods; } - private StreamMappingMethod createStreamMappingMethod(SourceMethod method, MappingOptions mappingOptions) { - // TODO this is the same as the if with the isIterableMapping, I think that we need - // to refactor the IterableMapping Builder and be able to reuse the common logic - StreamMappingMethod.Builder builder = new StreamMappingMethod.Builder(); + private M createWithElementMappingMethod(SourceMethod method, + MappingOptions mappingOptions, WithElementMappingMethodBuilder builder) { FormattingParameters formattingParameters = null; SelectionParameters selectionParameters = null; From 5cb80cbb9794cebf15a4e136c20fe64c9e1d11f9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 10 Jan 2017 20:57:00 +0100 Subject: [PATCH 0029/1006] #1012 rename new abstract builder and mapping methods; improve Javadoc --- ...MappingMethod.java => ContainerMappingMethod.java} | 10 +++++----- ...uilder.java => ContainerMappingMethodBuilder.java} | 11 +++++++---- .../ap/internal/model/IterableMappingMethod.java | 4 ++-- .../mapstruct/ap/internal/model/PropertyMapping.java | 4 ++-- .../ap/internal/model/StreamMappingMethod.java | 4 ++-- .../internal/processor/MapperCreationProcessor.java | 8 ++++---- 6 files changed, 22 insertions(+), 19 deletions(-) rename processor/src/main/java/org/mapstruct/ap/internal/model/{WithElementMappingMethod.java => ContainerMappingMethod.java} (94%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{WithElementMappingMethodBuilder.java => ContainerMappingMethodBuilder.java} (94%) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java similarity index 94% rename from processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index e1f45c37ec..6f58fb964a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -33,13 +33,13 @@ import org.mapstruct.ap.internal.util.Strings; /** - * A {@link MappingMethod} implemented by a {@link Mapper} class which does mapping of typed based methods. + * A {@link MappingMethod} implemented by a {@link Mapper} class which does mapping of generic types. * For example Iterable or Stream. - * The typed elements are mapped either by a {@link TypeConversion} or another mapping method. + * The generic elements are mapped either by a {@link TypeConversion} or another mapping method. * * @author Filip Hrisafov */ -public abstract class WithElementMappingMethod extends MappingMethod { +public abstract class ContainerMappingMethod extends MappingMethod { private final Assignment elementAssignment; private final MethodReference factoryMethod; private final boolean overridden; @@ -47,7 +47,7 @@ public abstract class WithElementMappingMethod extends MappingMethod { private final String loopVariableName; private final SelectionParameters selectionParameters; - WithElementMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, + ContainerMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, @@ -158,7 +158,7 @@ public boolean equals(Object obj) { if ( getClass() != obj.getClass() ) { return false; } - WithElementMappingMethod other = (WithElementMappingMethod) obj; + ContainerMappingMethod other = (ContainerMappingMethod) obj; if ( !getResultType().equals( other.getResultType() ) ) { return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java similarity index 94% rename from processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 2073ef0df2..447583d27c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/WithElementMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -36,12 +36,15 @@ import static org.mapstruct.ap.internal.util.Collections.first; /** - * Builder that can be used to build {@link WithElementMappingMethod}(s). + * Builder that can be used to build {@link ContainerMappingMethod}(s). + * + * @param the builder itself that needs to be used for chaining + * @param the method that the builder builds * * @author Filip Hrisafov */ -public abstract class WithElementMappingMethodBuilder, - M extends WithElementMappingMethod> extends AbstractMappingMethodBuilder { +public abstract class ContainerMappingMethodBuilder, + M extends ContainerMappingMethod> extends AbstractMappingMethodBuilder { private Method method; private SelectionParameters selectionParameters; @@ -51,7 +54,7 @@ public abstract class WithElementMappingMethodBuilder selfType, String errorMessagePart) { + ContainerMappingMethodBuilder(Class selfType, String errorMessagePart) { super( selfType ); this.errorMessagePart = errorMessagePart; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 989add6e9e..85bac06a87 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -36,9 +36,9 @@ * * @author Gunnar Morling */ -public class IterableMappingMethod extends WithElementMappingMethod { +public class IterableMappingMethod extends ContainerMappingMethod { - public static class Builder extends WithElementMappingMethodBuilder { + public static class Builder extends ContainerMappingMethodBuilder { public Builder() { super( Builder.class, "collection element" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 3cb7e139df..ac1c59a5ea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -552,11 +552,11 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source } private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element, WithElementMappingMethodBuilder builder) { + ExecutableElement element, ContainerMappingMethodBuilder builder) { ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); - WithElementMappingMethod iterableMappingMethod = builder + ContainerMappingMethod iterableMappingMethod = builder .mappingContext( ctx ) .method( methodRef ) .selectionParameters( selectionParameters ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index ebf68019fa..ed8b7ceb1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -40,11 +40,11 @@ * * @author Filip Hrisafov */ -public class StreamMappingMethod extends WithElementMappingMethod { +public class StreamMappingMethod extends ContainerMappingMethod { private final Set helperImports; - public static class Builder extends WithElementMappingMethodBuilder { + public static class Builder extends ContainerMappingMethodBuilder { public Builder() { super( Builder.class, "stream element" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 6ddc71b3a3..1d075c81e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -36,6 +36,8 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.BeanMappingMethod; +import org.mapstruct.ap.internal.model.ContainerMappingMethod; +import org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder; import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.DefaultMapperReference; import org.mapstruct.ap.internal.model.DelegatingMethod; @@ -48,8 +50,6 @@ import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.StreamMappingMethod; import org.mapstruct.ap.internal.model.ValueMappingMethod; -import org.mapstruct.ap.internal.model.WithElementMappingMethod; -import org.mapstruct.ap.internal.model.WithElementMappingMethodBuilder; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; @@ -446,8 +446,8 @@ else if ( method.isStreamMapping() ) { return mappingMethods; } - private M createWithElementMappingMethod(SourceMethod method, - MappingOptions mappingOptions, WithElementMappingMethodBuilder builder) { + private M createWithElementMappingMethod(SourceMethod method, + MappingOptions mappingOptions, ContainerMappingMethodBuilder builder) { FormattingParameters formattingParameters = null; SelectionParameters selectionParameters = null; From 0188dcbdcc1dfa0b2fceb46b9f916e333601aedf Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 8 Jan 2017 21:43:37 +0100 Subject: [PATCH 0030/1006] #1001 auto mapping support for update methods --- .../ap/internal/model/PropertyMapping.java | 14 ++++++-- .../ap/internal/model/common/Parameter.java | 29 ++++++++++++++++ .../ap/internal/model/common/TypeFactory.java | 9 +++++ .../internal/model/source/ForgedMethod.java | 20 ++++++----- .../internal/model/source/SourceMethod.java | 24 ++------------ .../NestedSimpleBeansMappingTest.java | 26 +++++++++++++-- .../nestedbeans/UserDtoUpdateMapperSmart.java | 33 +++++++++++++++++++ 7 files changed, 121 insertions(+), 34 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index ac1c59a5ea..8d3feb0414 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -635,14 +635,24 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { if ( sourceType.isPrimitive() || targetType.isPrimitive() ) { return null; } + String name = getName( sourceType, targetType ); + List parameters = new ArrayList( method.getContextParameters() ); + Type returnType; + if ( method.isUpdateMethod() ) { + parameters.add( Parameter.forForgedMappingTarget( targetType ) ); + returnType = ctx.getTypeFactory().createVoidType(); + } + else { + returnType = targetType; + } ForgedMethod forgedMethod = new ForgedMethod( name, sourceType, - targetType, + returnType, method.getMapperConfiguration(), method.getExecutable(), - method.getContextParameters(), + parameters, getForgedMethodHistory( sourceRHS ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 0e9bb5eb74..e238b58b59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -125,6 +125,15 @@ public static Parameter forElementAndType(VariableElement element, Type paramete ContextPrism.getInstanceOn( element ) != null ); } + public static Parameter forForgedMappingTarget(Type parameterType) { + return new Parameter( + "mappingTarget", + parameterType, + true, + false, + false); + } + /** * @param parameters the parameters to filter * @return the parameters from the given list that are considered 'source parameters' @@ -156,4 +165,24 @@ public static List getContextParameters(List parameters) { return contextParameters; } + + public static Parameter getMappingTargetParameter(List parameters) { + for ( Parameter parameter : parameters ) { + if ( parameter.isMappingTarget() ) { + return parameter; + } + } + + return null; + } + + public static Parameter getTargetTypeParameter(List parameters) { + for ( Parameter parameter : parameters ) { + if ( parameter.isTargetType() ) { + return parameter; + } + } + + return null; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index eedf7fb72d..8738eea495 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -493,6 +493,15 @@ else if ( collectionOrMap.isMapType() return collectionOrMap; } + /** + * creates a void return type + * + * @return void type + */ + public Type createVoidType() { + return getType( typeUtils.getNoType( TypeKind.VOID ) ); + } + /** * Establishes the type bound: *

    diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index a09e0e921f..3c6c0377ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -47,20 +47,21 @@ public class ForgedMethod implements Method { private final List sourceParameters; private final List contextParameters; + private final Parameter mappingTargetParameter; /** * Creates a new forged method with the given name. * * @param name the (unique name) for this method * @param sourceType the source type - * @param targetType the target type. + * @param returnType the return type. * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method */ - public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfiguration mapperConfiguration, + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters) { - this( name, sourceType, targetType, mapperConfiguration, positionHintElement, additionalParameters, null ); + this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null ); } /** @@ -68,13 +69,13 @@ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfigu * * @param name the (unique name) for this method * @param sourceType the source type - * @param targetType the target type. + * @param returnType the return type. * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method * @param history a parent forged method if this is a forged method within a forged method */ - public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfiguration mapperConfiguration, + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters, ForgedMethodHistory history) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); @@ -85,8 +86,9 @@ public ForgedMethod(String name, Type sourceType, Type targetType, MapperConfigu this.parameters.addAll( additionalParameters ); this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); + this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); - this.returnType = targetType; + this.returnType = returnType; this.thrownTypes = new ArrayList(); this.name = Strings.sanitizeIdentifierName( name ); this.mapperConfiguration = mapperConfiguration; @@ -109,6 +111,7 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); + this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.name = name; } @@ -165,7 +168,7 @@ public List getContextParameters() { @Override public Parameter getMappingTargetParameter() { - return null; + return mappingTargetParameter; } @Override @@ -203,7 +206,7 @@ public void addThrownTypes(List thrownTypesToAdd) { @Override public Type getResultType() { - return returnType; + return mappingTargetParameter != null ? mappingTargetParameter.getType() : returnType; } @Override @@ -303,4 +306,5 @@ public int hashCode() { result = 31 * result + ( name != null ? name.hashCode() : 0 ); return result; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index a012c119ab..bd2da2b460 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -228,8 +228,8 @@ private SourceMethod(Type declaringMapper, ExecutableElement executable, List parameters) { - for ( Parameter parameter : parameters ) { - if ( parameter.isMappingTarget() ) { - return parameter; - } - } - - return null; - } - - private Parameter determineTargetTypeParameter(Iterable parameters) { - for ( Parameter parameter : parameters ) { - if ( parameter.isTargetType() ) { - return parameter; - } - } - - return null; - } - @Override public Type getDeclaringMapper() { return declaringMapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index c26af14323..4c780bc711 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -30,7 +30,8 @@ Wheel.class, WheelDto.class, Roof.class, RoofDto.class, UserDtoMapperClassic.class, - UserDtoMapperSmart.class + UserDtoMapperSmart.class, + UserDtoUpdateMapperSmart.class }) @RunWith(AnnotationProcessorTestRunner.class) public class NestedSimpleBeansMappingTest { @@ -46,9 +47,30 @@ public void shouldMapNestedBeans() { System.out.println( smartMapping ); System.out.println( classicMapping ); - assertThat( smartMapping ).isNotNull(); assertThat( smartMapping ).isEqualTo( classicMapping ); } + @Test + public void shouldMapUpdateNestedBeans() { + + User user = TestData.createUser(); + user.getCar().setName( null ); + + // create a pre-exsiting smartMapping + UserDto smartMapping = new UserDto(); + smartMapping.setCar( new CarDto() ); + smartMapping.getCar().setName( "Toyota" ); + + // create a classic mapping and adapt expected result to Toyota + UserDto classicMapping = UserDtoMapperClassic.INSTANCE.userToUserDto( TestData.createUser() ); + classicMapping.getCar().setName( "Toyota" ); + + // action + UserDtoUpdateMapperSmart.INSTANCE.userToUserDto( smartMapping, user ); + + // result + assertThat( smartMapping ).isNotNull(); + assertThat( smartMapping ).isEqualTo( classicMapping ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java new file mode 100644 index 0000000000..adc1a43adf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface UserDtoUpdateMapperSmart { + + UserDtoUpdateMapperSmart INSTANCE = Mappers.getMapper( UserDtoUpdateMapperSmart.class ); + + void userToUserDto(@MappingTarget UserDto userDto, User user); + +} From ba20dc5700288a309ed00154d054eb9fb24470af Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 12 Jan 2017 23:00:53 +0100 Subject: [PATCH 0031/1006] #1005 Report an error if the resulting type in the BeanMappingMethod is abstract --- .../ap/internal/model/BeanMappingMethod.java | 18 +++- .../ap/internal/model/common/Type.java | 4 + .../processor/MapperCreationProcessor.java | 14 +-- .../mapstruct/ap/internal/util/Message.java | 2 + .../ap/test/bugs/_1005/AbstractEntity.java | 35 +++++++ .../mapstruct/ap/test/bugs/_1005/HasKey.java | 29 ++++++ .../ap/test/bugs/_1005/HasPrimaryKey.java | 25 +++++ ...1005ErroneousAbstractResultTypeMapper.java | 32 +++++++ ...1005ErroneousAbstractReturnTypeMapper.java | 30 ++++++ ...005ErroneousInterfaceResultTypeMapper.java | 32 +++++++ ...005ErroneousInterfaceReturnTypeMapper.java | 30 ++++++ .../ap/test/bugs/_1005/Issue1005Test.java | 93 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1005/Order.java | 25 +++++ .../ap/test/bugs/_1005/OrderDto.java | 35 +++++++ .../selection/qualifier/QualifierTest.java | 28 +++--- .../resulttype/InheritanceSelectionTest.java | 8 +- 16 files changed, 412 insertions(+), 28 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 30cf8f9cdf..c53d9e0a07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -181,7 +181,16 @@ public BeanMappingMethod build() { if ( factoryMethod == null ) { if ( selectionParameters != null && selectionParameters.getResultType() != null ) { resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ); - if ( !resultType.isAssignableTo( method.getResultType() ) ) { + if ( resultType.isAbstract() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + beanMappingPrism.mirror, + Message.BEANMAPPING_ABSTRACT, + resultType, + method.getResultType() + ); + } + else if ( !resultType.isAssignableTo( method.getResultType() ) ) { ctx.getMessager().printMessage( method.getExecutable(), beanMappingPrism.mirror, @@ -189,6 +198,13 @@ public BeanMappingMethod build() { ); } } + else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_ABSTRACT_RETURN_TYPE, + method.getReturnType() + ); + } } sortPropertyMappingsByDependencies(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 341a6223bd..219c02ea07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -189,6 +189,10 @@ public boolean isVoid() { return isVoid; } + public boolean isAbstract() { + return typeElement != null && typeElement.getModifiers().contains( Modifier.ABSTRACT ); + } + /** * @return this type's enum constants in case it is an enum, an empty list otherwise. */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 1d075c81e5..f0c72477e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -290,14 +290,7 @@ private List createBeanMapping(Collection forgedMet if ( beanMappingMethod != null ) { - boolean hasFactoryMethod = beanMappingMethod.getFactoryMethod() != null; mappingMethods.add( beanMappingMethod ); - if ( !hasFactoryMethod ) { - // A factory method is allowed to return an interface type and hence, the generated - // implementation as well. The check below must only be executed if there's no factory - // method that could be responsible. - reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType( method ); - } } } @@ -428,10 +421,9 @@ else if ( method.isStreamMapping() ) { .build(); if ( beanMappingMethod != null ) { - // We can consider that the mapping method has a factory method if it has one, - // or if the result type of the methods is not an interface - hasFactoryMethod = beanMappingMethod.getFactoryMethod() != null || - !beanMappingMethod.getResultType().isInterface(); + // We can consider that the bean mapping method can always be constructed. If there is a problem + // it would have been reported in its build + hasFactoryMethod = true; mappingMethods.add( beanMappingMethod ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 8bdae086ae..3ac151f944 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -30,6 +30,7 @@ public enum Message { // CHECKSTYLE:OFF BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), + BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in return type." ), BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE( "Property \"%s\" has no write accessor." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), @@ -77,6 +78,7 @@ public enum Message { DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ), + GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), GENERAL_AMBIGIOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s." ), GENERAL_AMBIGIOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s." ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java new file mode 100644 index 0000000000..7bd16b45a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +/** + * @author Filip Hrisafov + */ +public abstract class AbstractEntity implements HasPrimaryKey { + + private Integer key; + + public Integer getKey() { + return key; + } + + public void setKey(Integer key) { + this.key = key; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java new file mode 100644 index 0000000000..6f130710d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +/** + * @author Filip Hrisafov + */ +public interface HasKey { + + Integer getKey(); + + void setKey(Integer key); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java new file mode 100644 index 0000000000..f507ba52cf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +/** + * @author Filip Hrisafov + */ +public interface HasPrimaryKey extends HasKey { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java new file mode 100644 index 0000000000..fa8658189d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1005ErroneousAbstractResultTypeMapper { + + @BeanMapping(resultType = AbstractEntity.class) + HasKey map(OrderDto orderDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java new file mode 100644 index 0000000000..48a6069a89 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1005ErroneousAbstractReturnTypeMapper { + + AbstractEntity map(OrderDto orderDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java new file mode 100644 index 0000000000..0c61c60163 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1005ErroneousInterfaceResultTypeMapper { + + @BeanMapping(resultType = HasPrimaryKey.class) + HasKey map(OrderDto orderDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java new file mode 100644 index 0000000000..01007b6579 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1005ErroneousInterfaceReturnTypeMapper { + + HasKey map(OrderDto orderDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java new file mode 100644 index 0000000000..2aac9adfe1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -0,0 +1,93 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1005") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + AbstractEntity.class, + HasKey.class, + HasPrimaryKey.class, + Order.class, + OrderDto.class +}) +public class Issue1005Test { + + @WithClasses(Issue1005ErroneousAbstractResultTypeMapper.class) + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue1005ErroneousAbstractResultTypeMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 30, + messageRegExp = "The result type .*\\.AbstractEntity may not be an abstract class nor interface.") + }) + public void shouldFailDueToAbstractResultType() throws Exception { + } + + @WithClasses(Issue1005ErroneousAbstractReturnTypeMapper.class) + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue1005ErroneousAbstractReturnTypeMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "The return type .*\\.AbstractEntity is an abstract class or interface. Provide a non" + + " abstract / non interface result type or a factory method.") + }) + public void shouldFailDueToAbstractReturnType() throws Exception { + } + + @WithClasses(Issue1005ErroneousInterfaceResultTypeMapper.class) + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue1005ErroneousInterfaceResultTypeMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 30, + messageRegExp = "The result type .*\\.HasPrimaryKey may not be an abstract class nor interface.") + }) + public void shouldFailDueToInterfaceResultType() throws Exception { + } + + @WithClasses(Issue1005ErroneousInterfaceReturnTypeMapper.class) + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue1005ErroneousInterfaceReturnTypeMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "The return type .*\\.HasKey is an abstract class or interface. Provide a non " + + "abstract / non interface result type or a factory method.") + }) + public void shouldFailDueToInterfaceReturnType() throws Exception { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java new file mode 100644 index 0000000000..8086328965 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +/** + * @author Filip Hrisafov + */ +public class Order extends AbstractEntity { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java new file mode 100644 index 0000000000..7dcdb85fd7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1005; + +/** + * @author Filip Hrisafov + */ +public class OrderDto { + + private String key; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 1591c04162..f6b1a10e78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -18,14 +18,10 @@ */ package org.mapstruct.ap.test.selection.qualifier; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.tools.Diagnostic.Kind; import org.junit.Test; @@ -51,6 +47,9 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + /** * * @author Sjaak Derksen @@ -183,14 +182,19 @@ public void testFactorySelectionWithQualifier() { ErroneousMovieFactoryMapper.class } ) @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ErroneousMovieFactoryMapper.class, - kind = Kind.ERROR, - line = 37, - messageRegExp = "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in " - + "@BeanMapping, define at least one of them." ) - } + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMovieFactoryMapper.class, + kind = Kind.ERROR, + line = 37, + messageRegExp = "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in " + + "@BeanMapping, define at least one of them."), + @Diagnostic(type = ErroneousMovieFactoryMapper.class, + kind = Kind.ERROR, + line = 37, + messageRegExp = "The return type .*\\.AbstractEntry is an abstract class or interface. Provide a non " + + "abstract / non interface result type or a factory method.") + } ) public void testEmptyBeanMapping() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 1218470db4..48180a71ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -18,13 +18,10 @@ */ package org.mapstruct.ap.test.selection.resulttype; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.tools.Diagnostic.Kind; import org.junit.Test; @@ -36,6 +33,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * * @author Sjaak Derksen @@ -107,7 +106,8 @@ public void testResultTypeBasedConstructionOfResultForInterface() { @Diagnostic(type = ResultTypeConstructingFruitInterfaceErroneousMapper.class, kind = Kind.ERROR, line = 36, - messageRegExp = "No implementation type is registered for return type .*\\.IsFruit." + messageRegExp = "The return type .*\\.IsFruit is an abstract class or interface. Provide a non " + + "abstract / non interface result type or a factory method." ) } ) From 32738251e361f3b5cb12b7690b17df016789029d Mon Sep 17 00:00:00 2001 From: navpil Date: Thu, 22 Dec 2016 09:55:46 +0200 Subject: [PATCH 0032/1006] #1001 Dotted error messages --- .../ap/internal/model/BeanMappingMethod.java | 7 +- .../model/ContainerMappingMethodBuilder.java | 9 +- .../ap/internal/model/MapMappingMethod.java | 9 +- .../ap/internal/model/PropertyMapping.java | 35 ++-- .../model/source/ForgedMethodHistory.java | 88 +++++++-- .../mapstruct/ap/internal/util/Strings.java | 11 ++ .../ErroneousCollectionMappingTest.java | 17 +- .../forged/CollectionMappingTest.java | 4 +- .../erroneous/ErroneousStreamMappingTest.java | 12 +- .../forged/ForgedStreamMappingTest.java | 2 +- .../nestedbeans/DottedErrorMessageTest.java | 186 ++++++++++++++++++ .../ap/test/nestedbeans/erroneous/Car.java | 53 +++++ .../ap/test/nestedbeans/erroneous/CarDto.java | 53 +++++ .../ap/test/nestedbeans/erroneous/Cat.java | 33 ++++ .../ap/test/nestedbeans/erroneous/CatDto.java | 32 +++ .../ap/test/nestedbeans/erroneous/Color.java | 38 ++++ .../test/nestedbeans/erroneous/ColorDto.java | 32 +++ .../test/nestedbeans/erroneous/Computer.java | 32 +++ .../nestedbeans/erroneous/ComputerDto.java | 32 +++ .../nestedbeans/erroneous/Dictionary.java | 35 ++++ .../nestedbeans/erroneous/DictionaryDto.java | 35 ++++ .../nestedbeans/erroneous/ForeignWord.java | 32 +++ .../nestedbeans/erroneous/ForeignWordDto.java | 31 +++ .../ap/test/nestedbeans/erroneous/House.java | 51 +++++ .../test/nestedbeans/erroneous/HouseDto.java | 51 +++++ .../ap/test/nestedbeans/erroneous/Info.java | 31 +++ .../test/nestedbeans/erroneous/InfoDto.java | 31 +++ .../ap/test/nestedbeans/erroneous/Roof.java | 31 +++ .../test/nestedbeans/erroneous/RoofDto.java | 31 +++ ...ppableCollectionElementPropertyMapper.java | 43 ++++ .../erroneous/UnmappableDeepListMapper.java | 43 ++++ .../erroneous/UnmappableDeepMapKeyMapper.java | 48 +++++ .../UnmappableDeepMapValueMapper.java | 48 +++++ .../UnmappableDeepNestingMapper.java | 44 +++++ .../UnmappableValuePropertyMapper.java | 43 ++++ .../ap/test/nestedbeans/erroneous/User.java | 85 ++++++++ .../test/nestedbeans/erroneous/UserDto.java | 81 ++++++++ .../ap/test/nestedbeans/erroneous/Wheel.java | 41 ++++ .../test/nestedbeans/erroneous/WheelDto.java | 40 ++++ .../ap/test/nestedbeans/erroneous/Word.java | 32 +++ .../test/nestedbeans/erroneous/WordDto.java | 31 +++ .../selection/generics/ConversionTest.java | 8 +- 42 files changed, 1581 insertions(+), 50 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Cat.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CatDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Color.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ColorDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Computer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ComputerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Dictionary.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/DictionaryDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWord.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWordDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/House.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/HouseDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Info.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/InfoDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/User.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UserDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Wheel.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WheelDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Word.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WordDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c53d9e0a07..1f2aae28e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -598,15 +598,12 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { } else { ForgedMethodHistory history = forgedMethod.getHistory(); - while ( history.getPrevHistory() != null ) { - history = history.getPrevHistory(); - } ctx.getMessager().printMessage( this.method.getExecutable(), Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, - history.getSourceElement(), + history.createSourcePropertyErrorMessage(), history.getTargetType(), - history.getTargetPropertyName(), + history.createTargetPropertyName(), history.getTargetType(), history.getSourceType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 447583d27c..79bb7574ae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -185,7 +185,14 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe method.getMapperConfiguration(), method.getExecutable(), method.getContextParameters(), - forgedMethodHistory + new ForgedMethodHistory( forgedMethodHistory, + Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), + Strings.stubPropertyName( targetType.getName() ), + sourceRHS.getSourceType(), + targetType, + false, + sourceRHS.getSourceErrorMessagePart() + ) ); Assignment assignment = new MethodReference( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 438a9d5030..5ca3456774 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -200,7 +200,14 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe method.getMapperConfiguration(), method.getExecutable(), method.getContextParameters(), - history + new ForgedMethodHistory( history, + Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), + Strings.stubPropertyName( targetType.getName() ), + sourceRHS.getSourceType(), + targetType, + true, + sourceRHS.getSourceErrorMessagePart() + ) ); Assignment assignment = new MethodReference( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 8d3feb0414..4bac7add37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -554,7 +554,7 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element, ContainerMappingMethodBuilder builder) { - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "[]" ); ContainerMappingMethod iterableMappingMethod = builder .mappingContext( ctx ) @@ -591,7 +591,7 @@ private Assignment getForgedAssignment(SourceRHS source, ForgedMethod methodRef, } private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + ExecutableElement element, String suffix) { String name = getName( sourceType, targetType ); name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); @@ -604,19 +604,14 @@ private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, Sourc config, element, method.getContextParameters(), - new ForgedMethodHistory( getForgedMethodHistory( source ), - source.getSourceErrorMessagePart(), - targetPropertyName, - source.getSourceType(), - targetType - ) + getForgedMethodHistory( source, suffix ) ); } private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element) { - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element ); + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "{}" ); MapMappingMethod.Builder builder = new MapMappingMethod.Builder(); MapMappingMethod mapMappingMethod = builder @@ -669,13 +664,17 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { } private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { + return getForgedMethodHistory( sourceRHS, "" ); + } + + private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS, String suffix) { ForgedMethodHistory history = null; if ( method instanceof ForgedMethod ) { ForgedMethod method = (ForgedMethod) this.method; history = method.getHistory(); } - return new ForgedMethodHistory( history, sourceRHS.getSourceErrorMessagePart(), - targetPropertyName, sourceRHS.getSourceType(), targetType + return new ForgedMethodHistory( history, getSourceElementName() + suffix, + targetPropertyName + suffix, sourceRHS.getSourceType(), targetType, true, "property" ); } @@ -694,6 +693,20 @@ private String getName(Type type) { return builder.toString(); } + private String getSourceElementName() { + Parameter sourceParam = sourceReference.getParameter(); + List propertyEntries = sourceReference.getPropertyEntries(); + if ( propertyEntries.isEmpty() ) { + return sourceParam.getName(); + } + else if ( propertyEntries.size() == 1 ) { + PropertyEntry propertyEntry = propertyEntries.get( 0 ); + return propertyEntry.getName(); + } + else { + return Strings.join( sourceReference.getElementNames(), "." ); + } + } } public static class ConstantMappingBuilder extends MappingBuilderBase { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java index 2a793e27b8..754866bafa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java @@ -19,6 +19,7 @@ package org.mapstruct.ap.internal.model.source; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Strings; /** * Keeps the context where the ForgedMethod is generated, especially handy with nested forged methods @@ -32,22 +33,18 @@ public class ForgedMethodHistory { private final String targetPropertyName; private final Type targetType; private final Type sourceType; + private final boolean usePropertyNames; + private String elementType; public ForgedMethodHistory(ForgedMethodHistory history, String sourceElement, String targetPropertyName, - Type sourceType, Type targetType) { + Type sourceType, Type targetType, boolean usePropertyNames, String elementType) { prevHistory = history; this.sourceElement = sourceElement; this.targetPropertyName = targetPropertyName; this.sourceType = sourceType; this.targetType = targetType; - } - - public String getSourceElement() { - return sourceElement; - } - - public String getTargetPropertyName() { - return targetPropertyName; + this.usePropertyNames = usePropertyNames; + this.elementType = elementType; } public Type getTargetType() { @@ -58,8 +55,77 @@ public Type getSourceType() { return sourceType; } - public ForgedMethodHistory getPrevHistory() { - return prevHistory; + public String createSourcePropertyErrorMessage() { + return conditionallyCapitalizedElementType() + " \"" + getSourceType() + " " + + stripBrackets( getDottedSourceElement() ) + "\""; + } + + /** + * Capitalization mostly matters to avoid the funny "Can't map map key" message. However it's irrelevant for the + * "Can't map property" message. + * + * @return capitalized or non-capitalized element type + */ + private String conditionallyCapitalizedElementType() { + if ( "property".equals( elementType ) ) { + return elementType; + } + else { + return Strings.capitalize( elementType ); + } + } + + public String createTargetPropertyName() { + return stripBrackets( getDottedTargetPropertyName() ); + } + + private String getDottedSourceElement() { + if ( prevHistory == null ) { + return sourceElement; + } + else { + if ( usePropertyNames ) { + return getCorrectDottedPath( prevHistory.getDottedSourceElement(), sourceElement ); + } + else { + return prevHistory.getDottedSourceElement(); + } + } } + private String getDottedTargetPropertyName() { + if ( prevHistory == null ) { + return targetPropertyName; + } + else { + if ( usePropertyNames ) { + return getCorrectDottedPath( prevHistory.getDottedTargetPropertyName(), targetPropertyName ); + } + else { + return prevHistory.getDottedTargetPropertyName(); + } + + } + } + + private String getCorrectDottedPath(String previousPath, String currentProperty) { + if ( "map key".equals( elementType ) ) { + return stripBrackets( previousPath ) + "{:key}"; + } + else if ( "map value".equals( elementType ) ) { + return stripBrackets( previousPath ) + "{:value}"; + } + else { + return previousPath + "." + currentProperty; + } + } + + private String stripBrackets(String dottedName) { + if ( dottedName.endsWith( "[]" ) || dottedName.endsWith( "{}" ) ) { + dottedName = dottedName.substring( 0, dottedName.length() - 2 ); + } + return dottedName; + } } + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 2fc325ba30..4c670b15a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -177,6 +177,17 @@ public static String sanitizeIdentifierName(String identifier) { return identifier.replace( "[]", "Array" ); } + /** + * Returns a stub property name from full class name by stripping away the package and decapitalizing the name + * For example will return {@code fooBar} for {@code com.foo.bar.baz.FooBar} class name + * + * @param fullyQualifiedName fully qualified class name, such as com.foo.bar.baz.FooBar + * @return stup property name, such as fooBar + */ + public static String stubPropertyName(String fullyQualifiedName) { + return Strings.decapitalize( fullyQualifiedName.substring( fullyQualifiedName.lastIndexOf( '.' ) + 1 ) ); + } + /** * It removes the dots from the name and creates an {@link Iterable} from them. * diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 7dfb648d04..5c605a5bc1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -66,8 +66,8 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection( kind = Kind.ERROR, line = 26, messageRegExp = "Can't map property \"java.util.List strings\" to \"int strings\". " - + "Consider to declare/implement a mapping method: \"int map\\(java.util.List" - + " value\\)\"") + + "Consider to declare/implement a mapping method: \"int map\\(java.util.List" + + " value\\)\"") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @@ -115,8 +115,9 @@ public void shouldFailOnEmptyMapAnnotation() { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = + "Can't map Collection element \".*AttributedString attributedString\" to \".*String string\". " + + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFound() { @@ -131,8 +132,8 @@ public void shouldFailOnNoElementMappingFound() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map Map key \".*AttributedString attributedString\" to \".*String string\". " + + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoKeyMappingFound() { @@ -147,8 +148,8 @@ public void shouldFailOnNoKeyMappingFound() { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map Map value \".*AttributedString attributedString\" to \".*String string\". " + + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoValueMappingFound() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 3851c94ab3..7e650e640a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -100,7 +100,7 @@ public void shouldForgeNewMapMappingMethod() { @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, kind = Kind.ERROR, line = 30, - messageRegExp = "Can't map property \".* nonMappableSet\" to \".* nonMappableSet\". " + messageRegExp = "Can't map Collection element \".* nonMappableSet\" to \".* nonMappableSet\". " + "Consider to declare/implement a mapping method: .*."), } ) @@ -120,7 +120,7 @@ public void shouldGenerateNonMappleMethodForSetMapping() { @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 30, - messageRegExp = "Can't map property \".* nonMappableMap\" to \".* nonMappableMap\". " + messageRegExp = "Can't map Map key \".* nonMappableMap\\{:key\\}\" to \".* nonMappableMap\\{:key\\}\". " + "Consider to declare/implement a mapping method: .*."), } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index b743092cb6..093eb75c85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -115,8 +115,8 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 36, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." + + " Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { @@ -130,8 +130,8 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map .*AttributedString attributedString\" to .*String string\". " + + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFoundForListToStream() { @@ -145,8 +145,8 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString to .*String. " + - "Consider to implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." + + " Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index d791519d38..16f8379429 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -83,7 +83,7 @@ public void shouldForgeNewIterableMappingMethod() { @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, kind = Kind.ERROR, line = 30, - messageRegExp = "Can't map property \".* nonMappableStream\" to \".* nonMappableStream\". " + messageRegExp = "Can't map Stream element \".* nonMappableStream\" to \".* nonMappableStream\". " + "Consider to declare/implement a mapping method: .*."), } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java new file mode 100644 index 0000000000..c3923e6dfe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -0,0 +1,186 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.junit.Test; + +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.erroneous.Computer; +import org.mapstruct.ap.test.nestedbeans.erroneous.ComputerDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Dictionary; +import org.mapstruct.ap.test.nestedbeans.erroneous.DictionaryDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.ForeignWord; +import org.mapstruct.ap.test.nestedbeans.erroneous.ForeignWordDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Cat; +import org.mapstruct.ap.test.nestedbeans.erroneous.CatDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Info; +import org.mapstruct.ap.test.nestedbeans.erroneous.InfoDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableCollectionElementPropertyMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepListMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepMapKeyMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepMapValueMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableValuePropertyMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UserDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.User; +import org.mapstruct.ap.test.nestedbeans.erroneous.WheelDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Wheel; +import org.mapstruct.ap.test.nestedbeans.erroneous.Car; +import org.mapstruct.ap.test.nestedbeans.erroneous.CarDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.House; +import org.mapstruct.ap.test.nestedbeans.erroneous.HouseDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Color; +import org.mapstruct.ap.test.nestedbeans.erroneous.ColorDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.Roof; +import org.mapstruct.ap.test.nestedbeans.erroneous.RoofDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepNestingMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.Word; +import org.mapstruct.ap.test.nestedbeans.erroneous.WordDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@WithClasses({ + Car.class, CarDto.class, Color.class, ColorDto.class, + House.class, HouseDto.class, Roof.class, RoofDto.class, + User.class, UserDto.class, Wheel.class, WheelDto.class, + Dictionary.class, DictionaryDto.class, Word.class, WordDto.class, + ForeignWord.class, ForeignWordDto.class, + Computer.class, ComputerDto.class, + Cat.class, CatDto.class, Info.class, InfoDto.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class DottedErrorMessageTest { + + private static final String PROPERTY = "property"; + private static final String COLLECTION_ELEMENT = "Collection element"; + private static final String MAP_KEY = "Map key"; + private static final String MAP_VALUE = "Map value"; + + @Test + @WithClasses({ + UnmappableDeepNestingMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableDeepNestingMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + PROPERTY + + " \".*Color house\\.roof\\.color\" to \".*house\\.roof\\.color\"\\. " + + "Consider to declare/implement a mapping method: \".*ColorDto map\\(.*Color value\\)\"\\.") + } + ) + public void testDeepNestedBeans() { + } + + @Test + @WithClasses({ + UnmappableDeepListMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableDeepListMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + COLLECTION_ELEMENT + + " \".*Wheel car\\.wheels\" to \".*car\\.wheels\"\\. " + + "Consider to declare/implement a mapping method: \".*WheelDto map\\(.*Wheel value\\)\"\\.") + } + ) + public void testIterables() { + } + + @Test + @WithClasses({ + UnmappableDeepMapKeyMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableDeepMapKeyMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + MAP_KEY + + " \".*Word dictionary\\.wordMap\\{:key\\}\" to \".*dictionary\\.wordMap\\{:key\\}\"\\. " + + "Consider to declare/implement a mapping method: \".*WordDto map\\(.*Word value\\)\"\\.") + } + ) + public void testMapKeys() { + } + + @Test + @WithClasses({ + UnmappableDeepMapValueMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableDeepMapValueMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + MAP_VALUE + + " \".*ForeignWord dictionary\\.wordMap\\{:value\\}\" " + + "to \".*dictionary\\.wordMap\\{:value\\}\"\\. " + + "Consider to declare/implement a mapping method: " + + "\".*ForeignWordDto map\\(.*ForeignWord value\\)\"\\.") + } + ) + public void testMapValues() { + } + + @Test + @WithClasses({ + UnmappableCollectionElementPropertyMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableCollectionElementPropertyMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + PROPERTY + + " \".*Info computers\\[\\].info\" to \".*computers\\[\\].info\"\\. " + + "Consider to declare/implement a mapping method: \".*InfoDto map\\(.*Info value\\)\"\\.") + } + ) + public void testCollectionElementProperty() { + } + + @Test + @WithClasses({ + UnmappableValuePropertyMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableValuePropertyMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "Can't map " + PROPERTY + + " \".*Info catNameMap\\{:value\\}.info\" to \".*catNameMap\\{:value\\}.info\"\\. " + + "Consider to declare/implement a mapping method: \".*InfoDto map\\(.*Info value\\)\"\\.") + } + ) + public void testMapValueProperty() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Car.java new file mode 100644 index 0000000000..b74ed368e4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Car.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.List; + +public class Car { + + private String name; + private int year; + private List wheels; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public List getWheels() { + return wheels; + } + + public void setWheels(List wheels) { + this.wheels = wheels; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CarDto.java new file mode 100644 index 0000000000..d8c9a80e64 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CarDto.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.List; + +public class CarDto { + + private String name; + private int year; + private List wheels; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public List getWheels() { + return wheels; + } + + public void setWheels(List wheels) { + this.wheels = wheels; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Cat.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Cat.java new file mode 100644 index 0000000000..c5ed659ba9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Cat.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Cat { + + private Info info; + + public Info getInfo() { + return info; + } + + public void setInfo(Info info) { + this.info = info; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CatDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CatDto.java new file mode 100644 index 0000000000..cf33217309 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/CatDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class CatDto { + + private InfoDto info; + + public InfoDto getInfo() { + return info; + } + + public void setInfo(InfoDto info) { + this.info = info; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Color.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Color.java new file mode 100644 index 0000000000..eddc7dfe7d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Color.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Color { + private String cmyk; + + public Color() { + } + + public Color(String cmyk) { + this.cmyk = cmyk; + } + + public String getCmyk() { + return cmyk; + } + + public void setCmyk(String cmyk) { + this.cmyk = cmyk; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ColorDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ColorDto.java new file mode 100644 index 0000000000..30eb261408 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ColorDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class ColorDto { + private String rgb; + + public String getRgb() { + return rgb; + } + + public void setRgb(String rgb) { + this.rgb = rgb; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Computer.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Computer.java new file mode 100644 index 0000000000..6cd2bee32e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Computer.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Computer { + + private Info info; + + public Info getInfo() { + return info; + } + + public void setInfo(Info info) { + this.info = info; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ComputerDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ComputerDto.java new file mode 100644 index 0000000000..660ec226f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ComputerDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class ComputerDto { + + private InfoDto info; + + public InfoDto getInfo() { + return info; + } + + public void setInfo(InfoDto info) { + this.info = info; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Dictionary.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Dictionary.java new file mode 100644 index 0000000000..3ac5a27f52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Dictionary.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.Map; + +public class Dictionary { + + private Map wordMap; + + public Map getWordMap() { + return wordMap; + } + + public void setWordMap( + Map wordMap) { + this.wordMap = wordMap; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/DictionaryDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/DictionaryDto.java new file mode 100644 index 0000000000..21e55f7d53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/DictionaryDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.Map; + +public class DictionaryDto { + + private Map wordMap; + + public Map getWordMap() { + return wordMap; + } + + public void setWordMap( + Map wordMap) { + this.wordMap = wordMap; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWord.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWord.java new file mode 100644 index 0000000000..1b94862d85 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWord.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class ForeignWord { + + private String meaning; + + public String getMeaning() { + return meaning; + } + + public void setMeaning(String meaning) { + this.meaning = meaning; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWordDto.java new file mode 100644 index 0000000000..3f64cc9c04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ForeignWordDto.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class ForeignWordDto { + private String pronunciation; + + public String getPronunciation() { + return pronunciation; + } + + public void setPronunciation(String pronunciation) { + this.pronunciation = pronunciation; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/House.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/House.java new file mode 100644 index 0000000000..0f7ae15dcd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/House.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class House { + + private String name; + private int year; + private Roof roof; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public Roof getRoof() { + return roof; + } + + public void setRoof(Roof roof) { + this.roof = roof; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/HouseDto.java new file mode 100644 index 0000000000..19e95b637d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/HouseDto.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class HouseDto { + + private String name; + private int year; + private RoofDto roof; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public RoofDto getRoof() { + return roof; + } + + public void setRoof(RoofDto roof) { + this.roof = roof; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Info.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Info.java new file mode 100644 index 0000000000..8bbb21d406 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Info.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Info { + private String size; + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/InfoDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/InfoDto.java new file mode 100644 index 0000000000..b8a804aefd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/InfoDto.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class InfoDto { + private String color; + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java new file mode 100644 index 0000000000..b62268a417 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Roof { + private Color color; + + public Color getColor() { + return color; + } + + public void setColor(Color color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java new file mode 100644 index 0000000000..3768fd44d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class RoofDto { + private ColorDto color; + + public ColorDto getColor() { + return color; + } + + public void setColor(ColorDto color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java new file mode 100644 index 0000000000..1fb4f584c1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableCollectionElementPropertyMapper { + + abstract UserDto userToUserDto(User user); + + public HouseDto map(House house) { + return new HouseDto(); + } + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public DictionaryDto map(Dictionary dictionary) { + return new DictionaryDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java new file mode 100644 index 0000000000..78d6faabf1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableDeepListMapper { + + abstract UserDto userToUserDto(User user); + + public HouseDto map(House house) { + return new HouseDto(); + } + + public DictionaryDto map(Dictionary dictionary) { + return new DictionaryDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java new file mode 100644 index 0000000000..00fe65b563 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableDeepMapKeyMapper { + + abstract UserDto userToUserDto(User user); + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public HouseDto map(House house) { + return new HouseDto(); + } + + public ForeignWordDto map(ForeignWord word) { + return new ForeignWordDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java new file mode 100644 index 0000000000..a2aafa2675 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableDeepMapValueMapper { + + abstract UserDto userToUserDto(User user); + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public HouseDto map(House house) { + return new HouseDto(); + } + + public WordDto map(Word word) { + return new WordDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java new file mode 100644 index 0000000000..a01896cadf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableDeepNestingMapper { + + abstract UserDto userToUserDto(User user); + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public DictionaryDto map(Dictionary dictionary) { + return new DictionaryDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java new file mode 100644 index 0000000000..40f79307c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableValuePropertyMapper { + + abstract UserDto userToUserDto(User user); + + public HouseDto map(House house) { + return new HouseDto(); + } + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public DictionaryDto map(Dictionary dictionary) { + return new DictionaryDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/User.java new file mode 100644 index 0000000000..10ce16b70e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/User.java @@ -0,0 +1,85 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.List; +import java.util.Map; + +public class User { + + private String name; + //list of Wheels inside + private Car car; + //deep nesting inside Roof->Color + private House house; + //unmappable keys/values + private Dictionary dictionary; + //collection element's property can't be mapped + private List computers; + //map value property can't be mapped + private Map catNameMap; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Car getCar() { + return car; + } + + public void setCar(Car car) { + this.car = car; + } + + public House getHouse() { + return house; + } + + public void setHouse(House house) { + this.house = house; + } + + public Dictionary getDictionary() { + return dictionary; + } + + public void setDictionary(Dictionary dictionary) { + this.dictionary = dictionary; + } + + public List getComputers() { + return computers; + } + + public void setComputers(List computers) { + this.computers = computers; + } + + public Map getCatNameMap() { + return catNameMap; + } + + public void setCatNameMap(Map catNameMap) { + this.catNameMap = catNameMap; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UserDto.java new file mode 100644 index 0000000000..9f0048b12c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UserDto.java @@ -0,0 +1,81 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import java.util.List; +import java.util.Map; + +public class UserDto { + + private String name; + private CarDto car; + private HouseDto house; + private DictionaryDto dictionary; + private List computers; + private Map catNameMap; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public CarDto getCar() { + return car; + } + + public void setCar(CarDto car) { + this.car = car; + } + + public HouseDto getHouse() { + return house; + } + + public void setHouse(HouseDto house) { + this.house = house; + } + + public DictionaryDto getDictionary() { + return dictionary; + } + + public void setDictionary(DictionaryDto dictionary) { + this.dictionary = dictionary; + } + + public List getComputers() { + return computers; + } + + public void setComputers(List computers) { + this.computers = computers; + } + + public Map getCatNameMap() { + return catNameMap; + } + + public void setCatNameMap( + Map catNameMap) { + this.catNameMap = catNameMap; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Wheel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Wheel.java new file mode 100644 index 0000000000..1c7102a6c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Wheel.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Wheel { + private boolean front; + private boolean right; + + public boolean isFront() { + return front; + } + + public void setFront(boolean front) { + this.front = front; + } + + public boolean isRight() { + return right; + } + + public void setRight(boolean right) { + this.right = right; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WheelDto.java new file mode 100644 index 0000000000..7e185b073c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WheelDto.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class WheelDto { + private boolean front; + private boolean left; + + public boolean isFront() { + return front; + } + + public void setFront(boolean front) { + this.front = front; + } + + public boolean isLeft() { + return left; + } + + public void setLeft(boolean left) { + this.left = left; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Word.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Word.java new file mode 100644 index 0000000000..b27767783f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Word.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class Word { + + private String meaning; + + public String getMeaning() { + return meaning; + } + + public void setMeaning(String meaning) { + this.meaning = meaning; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WordDto.java new file mode 100644 index 0000000000..fdce91ef22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/WordDto.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +public class WordDto { + private String pronunciation; + + public String getPronunciation() { + return pronunciation; + } + + public void setPronunciation(String pronunciation) { + this.pronunciation = pronunciation; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index b28350da10..9398e634b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -168,10 +168,10 @@ public void shouldFailOnSuperBounds2() { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" - + " foo\" to" - + " \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + - " foo\"") + messageRegExp = "Can't map property \"java.lang.String " + + "foo\\.wrapped\" to" + + " \"org.mapstruct.ap.test.selection.generics.TypeA " + + "foo\\.wrapped\"") }) public void shouldFailOnNonMatchingWildCards() { } From 5088aa062b75021ad3dd6cdd2e01f425dd14bd80 Mon Sep 17 00:00:00 2001 From: navpil Date: Tue, 24 Jan 2017 12:23:13 +0200 Subject: [PATCH 0033/1006] #1001 Change TestMultipleForgedMethodsTest as suggested --- .../MultipleForgedMethodsTest.java | 108 ++++++++++++++++++ .../TestMultipleForgedMethodsTest.java | 52 --------- .../ap/test/nestedbeans/maps/Bar.java | 26 +++++ .../ap/test/nestedbeans/maps/BarDto.java | 26 +++++ .../ap/test/nestedbeans/maps/Dto.java | 28 ++++- .../ap/test/nestedbeans/maps/Entity.java | 26 +++++ .../multiplecollections/Garage.java | 32 ++++++ .../multiplecollections/GarageDto.java | 32 ++++++ 8 files changed, 277 insertions(+), 53 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java new file mode 100644 index 0000000000..9720776b86 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java @@ -0,0 +1,108 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper; +import org.mapstruct.ap.test.nestedbeans.maps.Bar; +import org.mapstruct.ap.test.nestedbeans.maps.BarDto; +import org.mapstruct.ap.test.nestedbeans.maps.Dto; +import org.mapstruct.ap.test.nestedbeans.maps.Entity; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto; +import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import java.util.Arrays; +import java.util.HashMap; + +/** + * This test is for a case when several identical methods could be generated, what is an easy edge case to miss. + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class MultipleForgedMethodsTest { + + @WithClasses({ + Bar.class, BarDto.class, Dto.class, Entity.class, AutoMapMapper.class + }) + @Test + public void testNestedMapsAutoMap() { + + HashMap dtoMap = new HashMap(); + HashMap entityMap = new HashMap(); + for ( int i = 0; i < 10; i++ ) { + String key = "key-" + i; + String value = "value-" + i; + dtoMap.put( new BarDto( key ), new BarDto( value ) ); + entityMap.put( new Bar( key ), new Bar( value ) ); + } + + Entity mappedEntity = AutoMapMapper.INSTANCE.entityToDto( new Dto( dtoMap ) ); + + Assert.assertEquals( "Mapper did not map dto to entity correctly", new Entity( entityMap ), mappedEntity ); + } + + @WithClasses({ + MultipleListMapper.class, Garage.class, GarageDto.class, Car.class, CarDto.class, + Wheel.class, WheelDto.class + }) + @Test + public void testMultipleCollections() { + GarageDto dto = new GarageDto( + Arrays.asList( new CarDto( + "New car", + 2017, + Arrays.asList( new WheelDto( true, false ), new WheelDto( true, true ) ) + ) ), + Arrays.asList( + new CarDto( + "Old car-1", + 1978, + Arrays.asList( new WheelDto( false, false ), new WheelDto( false, true ) ) + ), + new CarDto( + "Old car-2", + 1934, + Arrays.asList( new WheelDto( false, true ), new WheelDto( false, false ) ) + ) + ) + ); + + Garage entity = new Garage( + Arrays.asList( new Car( + "New car", + 2017, + Arrays.asList( new Wheel( true, false ), new Wheel( true, true ) ) + ) ), + Arrays.asList( + new Car( "Old car-1", 1978, Arrays.asList( new Wheel( false, false ), new Wheel( false, true ) ) ), + new Car( "Old car-2", 1934, Arrays.asList( new Wheel( false, true ), new Wheel( false, false ) ) ) + ) + ); + + GarageDto mappedDto = MultipleListMapper.INSTANCE.convert( entity ); + + Assert.assertEquals( "Mapper did not map entity to dto correctly", dto, mappedDto ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java deleted file mode 100644 index 73b7da5d22..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestMultipleForgedMethodsTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.test.nestedbeans; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper; -import org.mapstruct.ap.test.nestedbeans.maps.Bar; -import org.mapstruct.ap.test.nestedbeans.maps.BarDto; -import org.mapstruct.ap.test.nestedbeans.maps.Dto; -import org.mapstruct.ap.test.nestedbeans.maps.Entity; -import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage; -import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto; -import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; - -@RunWith(AnnotationProcessorTestRunner.class) -public class TestMultipleForgedMethodsTest { - - @WithClasses({ - Bar.class, BarDto.class, Dto.class, Entity.class, AutoMapMapper.class - }) - @Test - public void testNestedMapsAutoMap() { - AutoMapMapper.INSTANCE.entityToDto( new Dto() ); - } - - @WithClasses( {MultipleListMapper.class, Garage.class, GarageDto.class, Car.class, CarDto.class, - Wheel.class, WheelDto.class}) - @Test - public void testMultipleCollections() { - MultipleListMapper.INSTANCE.convert( new Garage() ); - } - -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java index 41196cea85..ada5ad6296 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java @@ -21,6 +21,13 @@ public class Bar { private String name; + public Bar() { + } + + public Bar(String name) { + this.name = name; + } + public String getName() { return name; } @@ -29,4 +36,23 @@ public void setName(String name) { this.name = name; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Bar bar = (Bar) o; + + return name != null ? name.equals( bar.name ) : bar.name == null; + + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java index b4d6df3e5c..02d5cc0c4d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java @@ -21,6 +21,13 @@ public class BarDto { private String name; + public BarDto() { + } + + public BarDto(String name) { + this.name = name; + } + public String getName() { return name; } @@ -29,4 +36,23 @@ public void setName(String name) { this.name = name; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + BarDto barDto = (BarDto) o; + + return name != null ? name.equals( barDto.name ) : barDto.name == null; + + } + + @Override + public int hashCode() { + return name != null ? name.hashCode() : 0; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java index d0c84f38c5..c908135003 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java @@ -23,12 +23,38 @@ public class Dto { private Map map; + public Dto() { + } + + public Dto(Map map) { + this.map = map; + } + public Map getMap() { return map; } - public void setMap( Map map) { + public void setMap(Map map) { this.map = map; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Dto dto = (Dto) o; + + return map != null ? map.equals( dto.map ) : dto.map == null; + + } + + @Override + public int hashCode() { + return map != null ? map.hashCode() : 0; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java index f84f1b7e27..977a704db7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java @@ -23,6 +23,13 @@ public class Entity { private Map map; + public Entity() { + } + + public Entity(Map map) { + this.map = map; + } + public Map getMap() { return map; } @@ -31,4 +38,23 @@ public void setMap(Map map) { this.map = map; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Entity entity = (Entity) o; + + return map != null ? map.equals( entity.map ) : entity.map == null; + + } + + @Override + public int hashCode() { + return map != null ? map.hashCode() : 0; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java index beab92bd32..f40fdae5cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java @@ -26,6 +26,14 @@ public class Garage { private List cars; private List usedCars; + public Garage() { + } + + public Garage(List cars, List usedCars) { + this.cars = cars; + this.usedCars = usedCars; + } + public List getCars() { return cars; } @@ -42,4 +50,28 @@ public void setUsedCars(List usedCars) { this.usedCars = usedCars; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + Garage garage = (Garage) o; + + if ( cars != null ? !cars.equals( garage.cars ) : garage.cars != null ) { + return false; + } + return usedCars != null ? usedCars.equals( garage.usedCars ) : garage.usedCars == null; + + } + + @Override + public int hashCode() { + int result = cars != null ? cars.hashCode() : 0; + result = 31 * result + ( usedCars != null ? usedCars.hashCode() : 0 ); + return result; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java index 214e0261a0..f66d9f46e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java @@ -27,6 +27,14 @@ public class GarageDto { private List cars; private List usedCars; + public GarageDto() { + } + + public GarageDto(List cars, List usedCars) { + this.cars = cars; + this.usedCars = usedCars; + } + public List getCars() { return cars; } @@ -43,4 +51,28 @@ public void setUsedCars(List usedCars) { this.usedCars = usedCars; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + GarageDto garageDto = (GarageDto) o; + + if ( cars != null ? !cars.equals( garageDto.cars ) : garageDto.cars != null ) { + return false; + } + return usedCars != null ? usedCars.equals( garageDto.usedCars ) : garageDto.usedCars == null; + + } + + @Override + public int hashCode() { + int result = cars != null ? cars.hashCode() : 0; + result = 31 * result + ( usedCars != null ? usedCars.hashCode() : 0 ); + return result; + } } From ef1c95ad1bac1b3f54cc5d741d7df4b61841056e Mon Sep 17 00:00:00 2001 From: navpil Date: Wed, 25 Jan 2017 10:51:56 +0200 Subject: [PATCH 0034/1006] #1001 Change meaningless names in MultipleForgedMethodTest to Dictionaries and Words to make test data easier to understand --- .../MultipleForgedMethodsTest.java | 37 ++++++++++++------- .../{Dto.java => AntonymsDictionary.java} | 24 ++++++------ ...Entity.java => AntonymsDictionaryDto.java} | 25 +++++++------ .../test/nestedbeans/maps/AutoMapMapper.java | 2 +- .../nestedbeans/maps/{Bar.java => Word.java} | 24 ++++++------ .../maps/{BarDto.java => WordDto.java} | 24 ++++++------ 6 files changed, 73 insertions(+), 63 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/{Dto.java => AntonymsDictionary.java} (65%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/{Entity.java => AntonymsDictionaryDto.java} (63%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/{Bar.java => Word.java} (70%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/{BarDto.java => WordDto.java} (69%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java index 9720776b86..33d0b855e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java @@ -21,11 +21,11 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionary; +import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionaryDto; import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper; -import org.mapstruct.ap.test.nestedbeans.maps.Bar; -import org.mapstruct.ap.test.nestedbeans.maps.BarDto; -import org.mapstruct.ap.test.nestedbeans.maps.Dto; -import org.mapstruct.ap.test.nestedbeans.maps.Entity; +import org.mapstruct.ap.test.nestedbeans.maps.Word; +import org.mapstruct.ap.test.nestedbeans.maps.WordDto; import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage; import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto; import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper; @@ -42,23 +42,32 @@ public class MultipleForgedMethodsTest { @WithClasses({ - Bar.class, BarDto.class, Dto.class, Entity.class, AutoMapMapper.class + Word.class, WordDto.class, AntonymsDictionaryDto.class, AntonymsDictionary.class, AutoMapMapper.class }) @Test public void testNestedMapsAutoMap() { - HashMap dtoMap = new HashMap(); - HashMap entityMap = new HashMap(); - for ( int i = 0; i < 10; i++ ) { - String key = "key-" + i; - String value = "value-" + i; - dtoMap.put( new BarDto( key ), new BarDto( value ) ); - entityMap.put( new Bar( key ), new Bar( value ) ); + HashMap dtoAntonyms = new HashMap(); + HashMap entityAntonyms = new HashMap(); + + String[] words = { "black", "good", "up", "left", "fast" }; + String[] antonyms = { "white", "bad", "down", "right", "slow" }; + + assert words.length == antonyms.length : "Words length and antonyms length differ, please fix test data"; + + for ( int i = 0; i < words.length; i++ ) { + String word = words[i]; + String antonym = antonyms[i]; + dtoAntonyms.put( new WordDto( word ), new WordDto( antonym ) ); + entityAntonyms.put( new Word( word ), new Word( antonym ) ); } - Entity mappedEntity = AutoMapMapper.INSTANCE.entityToDto( new Dto( dtoMap ) ); + AntonymsDictionary mappedAntonymsDictionary = AutoMapMapper.INSTANCE.entityToDto( + new AntonymsDictionaryDto( dtoAntonyms ) ); - Assert.assertEquals( "Mapper did not map dto to entity correctly", new Entity( entityMap ), mappedEntity ); + Assert.assertEquals( "Mapper did not map dto to entity correctly", new AntonymsDictionary( entityAntonyms ), + mappedAntonymsDictionary + ); } @WithClasses({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java similarity index 65% rename from processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java index c908135003..78a27df9ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java @@ -20,22 +20,22 @@ import java.util.Map; -public class Dto { - private Map map; +public class AntonymsDictionary { + private Map antonyms; - public Dto() { + public AntonymsDictionary() { } - public Dto(Map map) { - this.map = map; + public AntonymsDictionary(Map antonyms) { + this.antonyms = antonyms; } - public Map getMap() { - return map; + public Map getAntonyms() { + return antonyms; } - public void setMap(Map map) { - this.map = map; + public void setAntonyms(Map antonyms) { + this.antonyms = antonyms; } @Override @@ -47,14 +47,14 @@ public boolean equals(Object o) { return false; } - Dto dto = (Dto) o; + AntonymsDictionary antonymsDictionary = (AntonymsDictionary) o; - return map != null ? map.equals( dto.map ) : dto.map == null; + return antonyms != null ? antonyms.equals( antonymsDictionary.antonyms ) : antonymsDictionary.antonyms == null; } @Override public int hashCode() { - return map != null ? map.hashCode() : 0; + return antonyms != null ? antonyms.hashCode() : 0; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java similarity index 63% rename from processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java index 977a704db7..89df76bc7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java @@ -20,22 +20,22 @@ import java.util.Map; -public class Entity { - private Map map; +public class AntonymsDictionaryDto { + private Map antonyms; - public Entity() { + public AntonymsDictionaryDto() { } - public Entity(Map map) { - this.map = map; + public AntonymsDictionaryDto(Map antonyms) { + this.antonyms = antonyms; } - public Map getMap() { - return map; + public Map getAntonyms() { + return antonyms; } - public void setMap(Map map) { - this.map = map; + public void setAntonyms(Map antonyms) { + this.antonyms = antonyms; } @Override @@ -47,14 +47,15 @@ public boolean equals(Object o) { return false; } - Entity entity = (Entity) o; + AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o; - return map != null ? map.equals( entity.map ) : entity.map == null; + return antonyms != null ? antonyms.equals( antonymsDictionaryDto.antonyms ) : + antonymsDictionaryDto.antonyms == null; } @Override public int hashCode() { - return map != null ? map.hashCode() : 0; + return antonyms != null ? antonyms.hashCode() : 0; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java index feffe4e16c..e1f2a33c2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java @@ -26,6 +26,6 @@ public interface AutoMapMapper { AutoMapMapper INSTANCE = Mappers.getMapper( AutoMapMapper.class ); - Entity entityToDto(Dto dto); + AntonymsDictionary entityToDto(AntonymsDictionaryDto antonymsDictionaryDto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java similarity index 70% rename from processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java index ada5ad6296..f503700f63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java @@ -18,22 +18,22 @@ */ package org.mapstruct.ap.test.nestedbeans.maps; -public class Bar { - private String name; +public class Word { + private String textValue; - public Bar() { + public Word() { } - public Bar(String name) { - this.name = name; + public Word(String textValue) { + this.textValue = textValue; } - public String getName() { - return name; + public String getTextValue() { + return textValue; } - public void setName(String name) { - this.name = name; + public void setTextValue(String textValue) { + this.textValue = textValue; } @Override @@ -45,14 +45,14 @@ public boolean equals(Object o) { return false; } - Bar bar = (Bar) o; + Word word = (Word) o; - return name != null ? name.equals( bar.name ) : bar.name == null; + return textValue != null ? textValue.equals( word.textValue ) : word.textValue == null; } @Override public int hashCode() { - return name != null ? name.hashCode() : 0; + return textValue != null ? textValue.hashCode() : 0; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java similarity index 69% rename from processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java index 02d5cc0c4d..a74eef2136 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/BarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java @@ -18,22 +18,22 @@ */ package org.mapstruct.ap.test.nestedbeans.maps; -public class BarDto { - private String name; +public class WordDto { + private String textValue; - public BarDto() { + public WordDto() { } - public BarDto(String name) { - this.name = name; + public WordDto(String textValue) { + this.textValue = textValue; } - public String getName() { - return name; + public String getTextValue() { + return textValue; } - public void setName(String name) { - this.name = name; + public void setTextValue(String textValue) { + this.textValue = textValue; } @Override @@ -45,14 +45,14 @@ public boolean equals(Object o) { return false; } - BarDto barDto = (BarDto) o; + WordDto wordDto = (WordDto) o; - return name != null ? name.equals( barDto.name ) : barDto.name == null; + return textValue != null ? textValue.equals( wordDto.textValue ) : wordDto.textValue == null; } @Override public int hashCode() { - return name != null ? name.hashCode() : 0; + return textValue != null ? textValue.hashCode() : 0; } } From 754877cece080d6947861e94460e9ceba8947840 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sat, 14 Jan 2017 18:17:41 +0100 Subject: [PATCH 0035/1006] #510 Adding experimental SPI for letting AST-modifying annotation processors such as Lombok tell us about future modifications --- .../java/org/mapstruct/util/Experimental.java | 2 +- .../org/mapstruct/ap/MappingProcessor.java | 18 ++++-- .../ap/internal/model/common/TypeFactory.java | 37 ++++++++++- .../DefaultModelElementProcessorContext.java | 8 ++- .../util/AnnotationProcessorContext.java | 59 +++++++++++++++++ .../ap/internal/util/RoundContext.java | 64 +++++++++++++++++++ .../util/TypeHierarchyErroneousException.java | 17 +++-- .../spi/AstModifyingAnnotationProcessor.java | 50 +++++++++++++++ 8 files changed, 239 insertions(+), 16 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java diff --git a/core-common/src/main/java/org/mapstruct/util/Experimental.java b/core-common/src/main/java/org/mapstruct/util/Experimental.java index 0f7f6f3505..58cedeb932 100644 --- a/core-common/src/main/java/org/mapstruct/util/Experimental.java +++ b/core-common/src/main/java/org/mapstruct/util/Experimental.java @@ -30,5 +30,5 @@ @Documented @Retention(RetentionPolicy.SOURCE) public @interface Experimental { - + String value() default ""; } diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 3b301cb221..76c4f6a838 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -50,6 +50,8 @@ import org.mapstruct.ap.internal.processor.ModelElementProcessor; import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext; import org.mapstruct.ap.internal.util.AnnotationProcessingException; +import org.mapstruct.ap.internal.util.AnnotationProcessorContext; +import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException; /** @@ -107,6 +109,8 @@ public class MappingProcessor extends AbstractProcessor { private Options options; + private AnnotationProcessorContext annotationProcessorContext; + /** * Any mappers for which an implementation cannot be generated in the current round because they have source/target * types with incomplete hierarchies (as super-types are to be generated by other processors). They will be @@ -123,6 +127,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { super.init( processingEnv ); options = createOptions(); + annotationProcessorContext = new AnnotationProcessorContext(); } private Options createOptions() { @@ -146,13 +151,15 @@ public SourceVersion getSupportedSourceVersion() { public boolean process(final Set annotations, final RoundEnvironment roundEnvironment) { // nothing to do in the last round if ( !roundEnvironment.processingOver() ) { + RoundContext roundContext = new RoundContext( annotationProcessorContext ); + // process any mappers left over from previous rounds Set deferredMappers = getAndResetDeferredMappers(); - processMapperElements( deferredMappers ); + processMapperElements( deferredMappers, roundContext ); // get and process any mappers from this round Set mappers = getMappers( annotations, roundEnvironment ); - processMapperElements( mappers ); + processMapperElements( mappers, roundContext ); } return ANNOTATIONS_CLAIMED_EXCLUSIVELY; @@ -204,7 +211,7 @@ private Set getMappers(final Set annotations return mapperTypes; } - private void processMapperElements(Set mapperElements) { + private void processMapperElements(Set mapperElements, RoundContext roundContext) { for ( TypeElement mapperElement : mapperElements ) { try { // create a new context for each generated mapper in order to have imports of referenced types @@ -212,7 +219,10 @@ private void processMapperElements(Set mapperElements) { // note that this assumes that a new source file is created for each mapper which must not // necessarily be the case, e.g. in case of several mapper interfaces declared as inner types // of one outer interface - ProcessorContext context = new DefaultModelElementProcessorContext( processingEnv, options ); + ProcessorContext context = new DefaultModelElementProcessorContext( + processingEnv, options, roundContext + ); + processMapperTypeElement( context, mapperElement ); } catch ( TypeHierarchyErroneousException thie ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 8738eea495..d6ded05fd0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -54,9 +54,12 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.util.AnnotationProcessingException; -import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.JavaStreamConstants; +import org.mapstruct.ap.internal.util.RoundContext; +import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException; +import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; /** * Factory creating {@link Type} instances. @@ -67,6 +70,7 @@ public class TypeFactory { private final Elements elementUtils; private final Types typeUtils; + private RoundContext roundContext; private final TypeMirror iterableType; private final TypeMirror collectionType; @@ -76,9 +80,10 @@ public class TypeFactory { private final Map implementationTypes = new HashMap(); private final Map importedQualifiedTypesBySimpleName = new HashMap(); - public TypeFactory(Elements elementUtils, Types typeUtils) { + public TypeFactory(Elements elementUtils, Types typeUtils, RoundContext roundContext) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; + this.roundContext = roundContext; iterableType = typeUtils.erasure( elementUtils.getTypeElement( Iterable.class.getCanonicalName() ).asType() ); collectionType = @@ -146,6 +151,10 @@ public Type getType(TypeMirror mirror) { throw new AnnotationProcessingException( "Encountered erroneous type " + mirror ); } + if ( !isCleared( mirror ) ) { + throw new TypeHierarchyErroneousException( mirror ); + } + Type implementationType = getImplementationType( mirror ); boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); @@ -161,7 +170,6 @@ public Type getType(TypeMirror mirror) { TypeElement typeElement; Type componentType; - if ( mirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) mirror; @@ -565,4 +573,27 @@ static String trimSimpleClassName(String className) { return trimmedClassName; } + private boolean isCleared(TypeMirror type) { + if ( type.getKind() != TypeKind.DECLARED ) { + return true; + } + + if ( roundContext.isCleared( type ) ) { + return true; + } + + List astModifyingAnnotationProcessors = roundContext + .getAnnotationProcessorContext() + .getAstModifyingAnnotationProcessors(); + + for ( AstModifyingAnnotationProcessor processor : astModifyingAnnotationProcessors ) { + if ( !processor.isTypeComplete( type ) ) { + return false; + } + } + + roundContext.addClearedType( type ); + + return true; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index cbc181ecd2..1715849b31 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -33,6 +33,7 @@ import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.workarounds.TypesDecorator; import org.mapstruct.ap.internal.version.VersionInformation; @@ -50,14 +51,17 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final VersionInformation versionInformation; private final Types delegatingTypes; - public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options) { + public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options, + RoundContext roundContext) { + this.processingEnvironment = processingEnvironment; this.messager = new DelegatingMessager( processingEnvironment.getMessager() ); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); this.delegatingTypes = new TypesDecorator( processingEnvironment, versionInformation ); this.typeFactory = new TypeFactory( processingEnvironment.getElementUtils(), - delegatingTypes + delegatingTypes, + roundContext ); this.options = options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java new file mode 100644 index 0000000000..2474c1558f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ServiceLoader; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * Keeps contextual data in the scope of the entire annotation processor ("application scope"). + * + * @author Gunnar Morling + */ +public class AnnotationProcessorContext { + + private List astModifyingAnnotationProcessors; + + public AnnotationProcessorContext() { + astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( + findAstModifyingAnnotationProcessors() ); + } + + private static List findAstModifyingAnnotationProcessors() { + List processors = new ArrayList(); + + ServiceLoader loader = ServiceLoader.load( + AstModifyingAnnotationProcessor.class, AnnotationProcessorContext.class.getClassLoader() + ); + + for ( Iterator it = loader.iterator(); it.hasNext(); ) { + processors.add( it.next() ); + } + + return processors; + } + + public List getAstModifyingAnnotationProcessors() { + return astModifyingAnnotationProcessors; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java new file mode 100644 index 0000000000..253af596c7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -0,0 +1,64 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +import java.util.HashSet; +import java.util.Set; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * Keeps contextual data in the scope of one annotation processing round. + * + * @author Gunnar Morling + */ +public class RoundContext { + + private final AnnotationProcessorContext annotationProcessorContext; + private final Set clearedTypes; + + public RoundContext(AnnotationProcessorContext annotationProcessorContext) { + this.annotationProcessorContext = annotationProcessorContext; + this.clearedTypes = new HashSet(); + } + + public AnnotationProcessorContext getAnnotationProcessorContext() { + return annotationProcessorContext; + } + + /** + * Marks the given type as being ready for further processing. + */ + public void addClearedType(TypeMirror type) { + clearedTypes.add( type ); + } + + /** + * Whether the given type has been found to be ready for further processing or not. This is the case if the type's + * hierarchy is complete (no super-types need to be generated by other procesors) an no processors have signaled the + * intention to amend the given type. + * + * @see AstModifyingAnnotationProcessor + */ + public boolean isCleared(TypeMirror type) { + return clearedTypes.contains( type ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java b/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java index 8ea61096de..18194c222c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java @@ -19,23 +19,28 @@ package org.mapstruct.ap.internal.util; import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; /** - * Indicates a type element was visited whose hierarchy was erroneous, because it has a non-existing super-type. + * Indicates a type was visited whose hierarchy was erroneous, because it has a non-existing super-type. * * @author Gunnar Morling - * */ public class TypeHierarchyErroneousException extends RuntimeException { + private static final long serialVersionUID = 1L; - private TypeElement element; + private final TypeMirror type; public TypeHierarchyErroneousException(TypeElement element) { - this.element = element; + this( element.asType() ); + } + + public TypeHierarchyErroneousException(TypeMirror type) { + this.type = type; } - public TypeElement getElement() { - return element; + public TypeMirror getType() { + return type; } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java new file mode 100644 index 0000000000..524bf43a2d --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.util.Experimental; + +/** + * A contract to be implemented by other annotation processors which - against the design philosophy of JSR 269 - alter + * the types under compilation. + *

    + * This contract will be queried by MapStruct when examining types referenced by mappers to be generated, most notably + * the source and target types of mapping methods. If at least one AST-modifying processor announces further changes to + * such type, the generation of the affected mapper(s) will be deferred to a future round in the annnotation processing + * cycle. + *

    + * Implementations are discovered via the service loader, i.e. a JAR providing an AST-modifying processor needs to + * declare its implementation in a file {@code META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor}. + * + * @author Gunnar Morling + */ +@Experimental( "This interface may change in future revisions" ) +public interface AstModifyingAnnotationProcessor { + + /** + * Whether the specified type has been fully processed by this processor or not (i.e. this processor will amend the + * given type's structure after this invocation). + * + * @param type The type of interest + * @return {@code true} if this processor has fully processed the given type, {@code false} otherwise. + */ + boolean isTypeComplete(TypeMirror type); +} From 5e59f3484c65f63d6f6f7d314e78564a5e7237ae Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Tue, 31 Jan 2017 22:02:29 +0100 Subject: [PATCH 0036/1006] #510 Adding experimental SPI for letting AST-modifying annotation processors such as Lombok tell us about future modifications --- .../ap/internal/model/common/TypeFactory.java | 16 +++++++++++----- .../mapstruct/ap/internal/util/RoundContext.java | 8 ++++---- .../ap/spi/AstModifyingAnnotationProcessor.java | 3 ++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index d6ded05fd0..b99242b23b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -70,7 +70,7 @@ public class TypeFactory { private final Elements elementUtils; private final Types typeUtils; - private RoundContext roundContext; + private final RoundContext roundContext; private final TypeMirror iterableType; private final TypeMirror collectionType; @@ -147,11 +147,12 @@ public Type getType(TypeElement typeElement) { } public Type getType(TypeMirror mirror) { + if ( mirror.getKind() == TypeKind.ERROR ) { throw new AnnotationProcessingException( "Encountered erroneous type " + mirror ); } - if ( !isCleared( mirror ) ) { + if ( !canBeProcessed( mirror ) ) { throw new TypeHierarchyErroneousException( mirror ); } @@ -573,12 +574,17 @@ static String trimSimpleClassName(String className) { return trimmedClassName; } - private boolean isCleared(TypeMirror type) { + /** + * Whether the given type is ready to be processed or not. It can be processed if it is not of kind + * {@link TypeKind#ERROR} and all {@link AstModifyingAnnotationProcessor}s (if any) indicated that they've fully + * processed the type. + */ + private boolean canBeProcessed(TypeMirror type) { if ( type.getKind() != TypeKind.DECLARED ) { return true; } - if ( roundContext.isCleared( type ) ) { + if ( roundContext.isReadyForProcessing( type ) ) { return true; } @@ -592,7 +598,7 @@ private boolean isCleared(TypeMirror type) { } } - roundContext.addClearedType( type ); + roundContext.addTypeReadyForProcessing( type ); return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java index 253af596c7..23182100e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -47,18 +47,18 @@ public AnnotationProcessorContext getAnnotationProcessorContext() { /** * Marks the given type as being ready for further processing. */ - public void addClearedType(TypeMirror type) { + public void addTypeReadyForProcessing(TypeMirror type) { clearedTypes.add( type ); } /** * Whether the given type has been found to be ready for further processing or not. This is the case if the type's - * hierarchy is complete (no super-types need to be generated by other procesors) an no processors have signaled the - * intention to amend the given type. + * hierarchy is complete (no super-types need to be generated by other processors) an no processors have signaled + * the intention to amend the given type. * * @see AstModifyingAnnotationProcessor */ - public boolean isCleared(TypeMirror type) { + public boolean isReadyForProcessing(TypeMirror type) { return clearedTypes.contains( type ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java index 524bf43a2d..aa263ab12d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java @@ -44,7 +44,8 @@ public interface AstModifyingAnnotationProcessor { * given type's structure after this invocation). * * @param type The type of interest - * @return {@code true} if this processor has fully processed the given type, {@code false} otherwise. + * @return {@code true} if this processor has fully processed the given type (or has no interest in processing this + * type altogether), {@code false} otherwise. */ boolean isTypeComplete(TypeMirror type); } From 6e545347d09591ebbc889ebfb8c17ee6c7d076ff Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Tue, 31 Jan 2017 22:03:31 +0100 Subject: [PATCH 0037/1006] #1045 Supporting mappers with generated source/target types by deferring their generation to a later round --- .../itest/tests/TargetTypeGenerationTest.java | 34 ++++++++ .../generator/pom.xml | 39 +++++++++ .../DtoGenerationProcessor.java | 80 +++++++++++++++++++ .../javax.annotation.processing.Processor | 17 ++++ .../targetTypeGenerationTest/pom.xml | 40 ++++++++++ .../targetTypeGenerationTest/usage/pom.xml | 47 +++++++++++ .../targettypegeneration/usage/Order.java | 35 ++++++++ .../usage/OrderMapper.java | 33 ++++++++ .../usage/GeneratedTargetTypeTest.java | 41 ++++++++++ .../ap/internal/model/common/TypeFactory.java | 9 +-- 10 files changed, 370 insertions(+), 5 deletions(-) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java create mode 100644 integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java new file mode 100644 index 0000000000..04b9155c52 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * Tests usage of MapStruct with another processor that generates the target type of a mapping method. + * + * @author Gunnar Morling + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite(baseDir = "targetTypeGenerationTest", processorTypes = ProcessorType.ORACLE_JAVA_8) +public class TargetTypeGenerationTest { +} diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml new file mode 100644 index 0000000000..589af8215b --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + + org.mapstruct.itest + itest-targettypegeneration-aggregator + 1.0.0 + ../pom.xml + + + itest-targettypegeneration-generator + jar + + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + -proc:none + + + + + + diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java new file mode 100644 index 0000000000..e4d27a885d --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java @@ -0,0 +1,80 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.targettypegeneration; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.Name; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; + +/** + * Generates a DTO. + * + * @author Gunnar Morling + * + */ +@SupportedAnnotationTypes("*") +public class DtoGenerationProcessor extends AbstractProcessor { + + private boolean hasRun = false; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if ( !hasRun ) { + try { + JavaFileObject dto = processingEnv.getFiler().createSourceFile( "org.mapstruct.itest.targettypegeneration.usage.OrderDto" ); + Writer writer = dto.openWriter(); + + writer.append( "package org.mapstruct.itest.targettypegeneration.usage;" ); + writer.append( "\n" ); + writer.append( "public class OrderDto {" ); + writer.append( "\n" ); + writer.append( " private String item;" ); + writer.append( "\n" ); + writer.append( " public String getItem() {" ); + writer.append( " return item;" ); + writer.append( " }" ); + writer.append( "\n" ); + writer.append( " public void setItem(String item) {" ); + writer.append( " this.item = item;" ); + writer.append( " }" ); + writer.append( "}" ); + + writer.flush(); + writer.close(); + } + catch (IOException e) { + throw new RuntimeException( e ); + } + + hasRun = true; + } + + return false; + } +} diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000000..1bd0775000 --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,17 @@ +# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) +# and/or other contributors as indicated by the @authors tag. See the +# copyright.txt file in the distribution for a full listing of all +# contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +org.mapstruct.itest.targettypegeneration.DtoGenerationProcessor diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml new file mode 100644 index 0000000000..5f77262044 --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml @@ -0,0 +1,40 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + org.mapstruct.itest + itest-targettypegeneration-aggregator + pom + + + generator + usage + + diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml new file mode 100644 index 0000000000..520576dad5 --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -0,0 +1,47 @@ + + 4.0.0 + + + org.mapstruct.itest + itest-targettypegeneration-aggregator + 1.0.0 + ../pom.xml + + + itest-targettypegeneration-usage + jar + + + + junit + junit + 4.12 + test + + + org.mapstruct.itest + itest-targettypegeneration-generator + 1.0.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + -XprintProcessorInfo + -XprintRounds + + + + + + diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java new file mode 100644 index 0000000000..c6a4961124 --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.targettypegeneration.usage; + +/** + * @author Gunnar Morling + */ +public class Order { + + private String item; + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } +} diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java new file mode 100644 index 0000000000..cb842c60f9 --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.targettypegeneration.usage; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Gunnar Morling + */ +@Mapper +public abstract class OrderMapper { + + public static final OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); + + public abstract OrderDto orderToDto(Order order); +} diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java new file mode 100644 index 0000000000..724754958d --- /dev/null +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.targettypegeneration.usage; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Integration test for using MapStruct with another annotation processor that generates the target type of a mapping + * method. + * + * @author Gunnar Morling + */ +public class GeneratedTargetTypeTest { + + @Test + public void considersPropertiesOnGeneratedSourceAndTargetTypes() { + Order order = new Order(); + order.setItem( "my item" ); + + OrderDto dto = OrderMapper.INSTANCE.orderToDto( order ); + assertEquals( order.getItem(), dto.getItem() ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index b99242b23b..7001b6bfa8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -147,11 +147,6 @@ public Type getType(TypeElement typeElement) { } public Type getType(TypeMirror mirror) { - - if ( mirror.getKind() == TypeKind.ERROR ) { - throw new AnnotationProcessingException( "Encountered erroneous type " + mirror ); - } - if ( !canBeProcessed( mirror ) ) { throw new TypeHierarchyErroneousException( mirror ); } @@ -580,6 +575,10 @@ static String trimSimpleClassName(String className) { * processed the type. */ private boolean canBeProcessed(TypeMirror type) { + if ( type.getKind() == TypeKind.ERROR ) { + return false; + } + if ( type.getKind() != TypeKind.DECLARED ) { return true; } From b3cbfb82064250b238838bfe45580521a734958d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 24 Jan 2017 22:33:14 +0100 Subject: [PATCH 0038/1006] #1001 remove ForgedMethod from MappingMethods and directly create MappingMethods instead --- .../internal/model/AbstractBaseBuilder.java | 88 +++++++++++++++ .../model/AbstractMappingMethodBuilder.java | 65 ++++++++++-- .../ap/internal/model/BeanMappingMethod.java | 13 +-- .../model/ContainerMappingMethod.java | 16 +-- .../model/ContainerMappingMethodBuilder.java | 64 +---------- .../internal/model/IterableMappingMethod.java | 12 +-- .../ap/internal/model/MapMappingMethod.java | 79 ++------------ .../ap/internal/model/MappingMethod.java | 32 +----- .../ap/internal/model/PropertyMapping.java | 82 +++++--------- .../internal/model/StreamMappingMethod.java | 13 +-- .../processor/MapperCreationProcessor.java | 55 +--------- .../forged/CollectionMappingTest.java | 5 + .../NestedSimpleBeansMappingTest.java | 5 + .../mapstruct/ap/test/nestedbeans/User.java | 9 ++ .../ap/test/nestedbeans/UserDto.java | 9 ++ .../test/nestedbeans/UserDtoMapperSmart.java | 1 + .../ap/test/nestedbeans/other/CarDto.java | 100 ++++++++++++++++++ .../ap/test/nestedbeans/other/HouseDto.java | 98 +++++++++++++++++ .../ap/test/nestedbeans/other/RoofDto.java | 66 ++++++++++++ .../ap/test/nestedbeans/other/UserDto.java | 98 +++++++++++++++++ .../ap/test/nestedbeans/other/WheelDto.java | 80 ++++++++++++++ 21 files changed, 673 insertions(+), 317 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java new file mode 100644 index 0000000000..6a87431b95 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -0,0 +1,88 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * @author Filip Hrisafov + */ +class AbstractBaseBuilder> { + + protected B myself; + protected MappingBuilderContext ctx; + protected Method method; + + AbstractBaseBuilder(Class selfType) { + myself = selfType.cast( this ); + } + + public B mappingContext(MappingBuilderContext mappingContext) { + this.ctx = mappingContext; + return myself; + } + + public B method(Method sourceMethod) { + this.method = sourceMethod; + return myself; + } + + /** + * Creates a forged assignment from the provided {@code sourceRHS} and {@code forgedMethod}. If a mapping method + * for the {@code forgedMethod} already exists, then this method used for the assignment. + * + * @param sourceRHS that needs to be used for the assignment + * @param forgedMethod the forged method for which we want to create an {@link Assignment} + * + * @return See above + */ + Assignment createForgedBeanAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) { + BeanMappingMethod forgedMappingMethod = new BeanMappingMethod.Builder() + .forgedMethod( forgedMethod ) + .mappingContext( ctx ) + .build(); + + return createForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethod ); + } + + Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, MappingMethod mappingMethod) { + if ( mappingMethod == null ) { + return null; + } + if ( !ctx.getMappingsToGenerate().contains( mappingMethod ) ) { + ctx.getMappingsToGenerate().add( mappingMethod ); + } + else { + String existingName = ctx.getExistingMappingMethod( mappingMethod ).getName(); + methodRef = new ForgedMethod( existingName, methodRef ); + } + + Assignment assignment = new MethodReference( + methodRef, + null, + ParameterBinding.fromParameters( methodRef.getParameters() ) + ); + assignment.setAssignment( source ); + + return assignment; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 683e1c8e6d..25e8de0f43 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -19,25 +19,72 @@ package org.mapstruct.ap.internal.model; +import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; +import org.mapstruct.ap.internal.util.Strings; + /** * An abstract builder that can be reused for building {@link MappingMethod}(s). * * @author Filip Hrisafov */ public abstract class AbstractMappingMethodBuilder, - M extends MappingMethod> { - - protected B myself; - protected MappingBuilderContext ctx; + M extends MappingMethod> extends AbstractBaseBuilder { public AbstractMappingMethodBuilder(Class selfType) { - myself = selfType.cast( this ); + super( selfType ); } - public B mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return myself; + public abstract M build(); + + /** + * @return {@code true} if property names should be used for the creation of the {@link ForgedMethodHistory}. + */ + protected abstract boolean shouldUsePropertyNamesInHistory(); + + Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + + String name = getName( sourceType, targetType ); + name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + ForgedMethodHistory history = null; + if ( method instanceof ForgedMethod ) { + history = ( (ForgedMethod) method ).getHistory(); + } + ForgedMethod forgedMethod = new ForgedMethod( + name, + sourceType, + targetType, + method.getMapperConfiguration(), + method.getExecutable(), + method.getContextParameters(), + new ForgedMethodHistory( + history, + Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), + Strings.stubPropertyName( targetType.getName() ), + sourceRHS.getSourceType(), + targetType, + shouldUsePropertyNamesInHistory(), + sourceRHS.getSourceErrorMessagePart() + ) + ); + + return createForgedBeanAssignment( sourceRHS, forgedMethod ); } - public abstract M build(); + private String getName(Type sourceType, Type targetType) { + String fromName = getName( sourceType ); + String toName = getName( targetType ); + return Strings.decapitalize( fromName + "To" + toName ); + } + + private String getName(Type type) { + StringBuilder builder = new StringBuilder(); + for ( Type typeParam : type.getTypeParameters() ) { + builder.append( typeParam.getIdentification() ); + } + builder.append( type.getIdentification() ); + return builder.toString(); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1f2aae28e8..149e26d21a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -217,11 +217,6 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); - List allForgedMethods = new ArrayList(); - for ( PropertyMapping propertyMapping : propertyMappings ) { - allForgedMethods.addAll( propertyMapping.getForgedMethods() ); - } - return new BeanMappingMethod( method, propertyMappings, @@ -231,8 +226,7 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { existingVariableNames, beforeMappingMethods, afterMappingMethods, - nestedTargetObjects, - allForgedMethods + nestedTargetObjects ); } @@ -637,9 +631,8 @@ private BeanMappingMethod(Method method, Collection existingVariableNames, List beforeMappingReferences, List afterMappingReferences, - NestedTargetObjects nestedTargetObjects, - List allForgedMethods) { - super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences, allForgedMethods ); + NestedTargetObjects nestedTargetObjects) { + super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences ); this.propertyMappings = propertyMappings; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 6f58fb964a..cc6dfa367f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -18,16 +18,13 @@ */ package org.mapstruct.ap.internal.model; -import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.type.TypeKind; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.util.Strings; @@ -48,14 +45,11 @@ public abstract class ContainerMappingMethod extends MappingMethod { private final SelectionParameters selectionParameters; ContainerMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, - boolean mapNullToDefault, String loopVariableName, - List beforeMappingReferences, - List afterMappingReferences, - SelectionParameters selectionParameters, ForgedMethod forgedMethod) { - super( method, beforeMappingReferences, afterMappingReferences, - forgedMethod == null ? Collections.emptyList() : - java.util.Collections.singletonList( forgedMethod ) - ); + boolean mapNullToDefault, String loopVariableName, + List beforeMappingReferences, + List afterMappingReferences, + SelectionParameters selectionParameters) { + super( method, beforeMappingReferences, afterMappingReferences ); this.elementAssignment = parameterAssignment; this.factoryMethod = factoryMethod; this.overridden = method.overridesMethod(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 79bb7574ae..81c791a3cc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -23,10 +23,8 @@ import java.util.Set; import org.mapstruct.ap.internal.model.assignment.Assignment; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -46,11 +44,9 @@ public abstract class ContainerMappingMethodBuilder, M extends ContainerMappingMethod> extends AbstractMappingMethodBuilder { - private Method method; private SelectionParameters selectionParameters; private FormattingParameters formattingParameters; private NullValueMappingStrategyPrism nullValueMappingStrategy; - private ForgedMethod forgedMethod; private String errorMessagePart; private String callingContextTargetPropertyName; @@ -59,11 +55,6 @@ public abstract class ContainerMappingMethodBuilder beforeMappingMethods, List afterMappingMethods, - SelectionParameters selectionParameters, ForgedMethod forgedMethod); + SelectionParameters selectionParameters); protected abstract Type getElementType(Type parameterType); protected abstract Assignment getWrapper(Assignment assignment, Method method); - private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { - ForgedMethodHistory forgedMethodHistory = null; - if ( method instanceof ForgedMethod ) { - forgedMethodHistory = ( (ForgedMethod) method ).getHistory(); - } - String name = getName( sourceType, targetType ); - forgedMethod = new ForgedMethod( - name, - sourceType, - targetType, - method.getMapperConfiguration(), - method.getExecutable(), - method.getContextParameters(), - new ForgedMethodHistory( forgedMethodHistory, - Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), - Strings.stubPropertyName( targetType.getName() ), - sourceRHS.getSourceType(), - targetType, - false, - sourceRHS.getSourceErrorMessagePart() - ) - ); - - Assignment assignment = new MethodReference( - forgedMethod, - null, - ParameterBinding.fromParameters( forgedMethod.getParameters() ) - ); - - assignment.setAssignment( sourceRHS ); - - return assignment; - } - - private String getName(Type sourceType, Type targetType) { - String fromName = getName( sourceType ); - String toName = getName( targetType ); - return Strings.decapitalize( fromName + "To" + toName ); - } - - private String getName(Type type) { - StringBuilder builder = new StringBuilder(); - for ( Type typeParam : type.getTypeParameters() ) { - builder.append( typeParam.getIdentification() ); - } - builder.append( type.getIdentification() ); - return builder.toString(); + @Override + protected boolean shouldUsePropertyNamesInHistory() { + return false; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 85bac06a87..44f743c492 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -26,7 +26,6 @@ import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -66,8 +65,7 @@ protected Assignment getWrapper(Assignment assignment, Method method) { protected IterableMappingMethod instantiateMappingMethod(Method method, Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingMethods, - List afterMappingMethods, SelectionParameters selectionParameters, - ForgedMethod forgedMethod) { + List afterMappingMethods, SelectionParameters selectionParameters) { return new IterableMappingMethod( method, assignment, @@ -76,8 +74,7 @@ protected IterableMappingMethod instantiateMappingMethod(Method method, Assignme loopVariableName, beforeMappingMethods, afterMappingMethods, - selectionParameters, - forgedMethod + selectionParameters ); } } @@ -86,7 +83,7 @@ private IterableMappingMethod(Method method, Assignment parameterAssignment, Met boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, - SelectionParameters selectionParameters, ForgedMethod forgedMethod) { + SelectionParameters selectionParameters) { super( method, parameterAssignment, @@ -95,8 +92,7 @@ private IterableMappingMethod(Method method, Assignment parameterAssignment, Met loopVariableName, beforeMappingReferences, afterMappingReferences, - selectionParameters, - forgedMethod + selectionParameters ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 5ca3456774..f37729e74f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -20,7 +20,6 @@ import static org.mapstruct.ap.internal.util.Collections.first; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -29,10 +28,8 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -53,25 +50,16 @@ public class MapMappingMethod extends MappingMethod { private final boolean overridden; private final boolean mapNullToDefault; - public static class Builder { + public static class Builder extends AbstractMappingMethodBuilder { private FormattingParameters keyFormattingParameters; private FormattingParameters valueFormattingParameters; - private Method method; - private MappingBuilderContext ctx; private NullValueMappingStrategyPrism nullValueMappingStrategy; private SelectionParameters keySelectionParameters; private SelectionParameters valueSelectionParameters; - private List forgedMethods = new ArrayList(); - public Builder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public Builder method(Method sourceMethod) { - this.method = sourceMethod; - return this; + public Builder() { + super( Builder.class ); } public Builder keySelectionParameters(SelectionParameters keySelectionParameters) { @@ -181,70 +169,21 @@ public MapMappingMethod build() { factoryMethod, mapNullToDefault, beforeMappingMethods, - afterMappingMethods, - forgedMethods + afterMappingMethods ); } - private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { - - String name = getName( sourceType, targetType ); - ForgedMethodHistory history = null; - if ( method instanceof ForgedMethod ) { - history = ( (ForgedMethod) method ).getHistory(); - } - ForgedMethod forgedMethod = new ForgedMethod( - name, - sourceType, - targetType, - method.getMapperConfiguration(), - method.getExecutable(), - method.getContextParameters(), - new ForgedMethodHistory( history, - Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), - Strings.stubPropertyName( targetType.getName() ), - sourceRHS.getSourceType(), - targetType, - true, - sourceRHS.getSourceErrorMessagePart() - ) - ); - - Assignment assignment = new MethodReference( - forgedMethod, - null, - ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); - - assignment.setAssignment( sourceRHS ); - - forgedMethods.add( forgedMethod ); - - return assignment; - } - - private String getName(Type sourceType, Type targetType) { - String fromName = getName( sourceType ); - String toName = getName( targetType ); - return Strings.decapitalize( fromName + "To" + toName ); - } - - private String getName(Type type) { - StringBuilder builder = new StringBuilder(); - for ( Type typeParam : type.getTypeParameters() ) { - builder.append( typeParam.getIdentification() ); - } - builder.append( type.getIdentification() ); - return builder.toString(); + @Override + protected boolean shouldUsePropertyNamesInHistory() { + return true; } - } private MapMappingMethod(Method method, Assignment keyAssignment, Assignment valueAssignment, MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, - List afterMappingReferences, - List forgedMethods) { - super( method, beforeMappingReferences, afterMappingReferences, forgedMethods ); + List afterMappingReferences) { + super( method, beforeMappingReferences, afterMappingReferences ); this.keyAssignment = keyAssignment; this.valueAssignment = valueAssignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index f832084373..e746f4bf4c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -32,7 +31,6 @@ import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; /** @@ -54,7 +52,6 @@ public abstract class MappingMethod extends ModelElement { private final List beforeMappingReferencesWithMappingTarget; private final List beforeMappingReferencesWithoutMappingTarget; private final List afterMappingReferences; - private final List forgedMethods; /** * constructor to be overloaded when local variable names are required prior to calling this constructor. (e.g. for @@ -68,14 +65,12 @@ public abstract class MappingMethod extends ModelElement { protected MappingMethod(Method method, Collection existingVariableNames, List beforeMappingReferences, List afterMappingReferences) { - this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences, - Collections.emptyList() ); + this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences ); } protected MappingMethod(Method method, List parameters, Collection existingVariableNames, List beforeMappingReferences, - List afterMappingReferences, - List forgedMethods) { + List afterMappingReferences) { this.name = method.getName(); this.parameters = parameters; this.sourceParameters = Parameter.getSourceParameters( parameters ); @@ -88,12 +83,10 @@ protected MappingMethod(Method method, List parameters, Collection parameters) { - this( method, parameters, new ArrayList( method.getParameterNames() ), null, null, - Collections.emptyList() ); + this( method, parameters, new ArrayList( method.getParameterNames() ), null, null ); } protected MappingMethod(Method method) { @@ -106,21 +99,6 @@ protected MappingMethod(Method method, List be afterMappingReferences ); } - protected MappingMethod(Method method, List beforeMappingReferences, - List afterMappingReferences, - List forgedMethods) { - this( method, method.getParameters(), new ArrayList( method.getParameterNames() ), - beforeMappingReferences, afterMappingReferences, forgedMethods ); - } - - public MappingMethod(Method method, Collection existingVariableNames, - List beforeMappingReferences, - List afterMappingReferences, - List allForgedMethods) { - this( method, method.getParameters(), existingVariableNames, beforeMappingReferences, afterMappingReferences, - allForgedMethods ); - } - private String initResultName(Collection existingVarNames) { if ( targetParameter != null ) { return targetParameter.getName(); @@ -239,10 +217,6 @@ public List getBeforeMappingReferencesWithoutM return beforeMappingReferencesWithoutMappingTarget; } - public List getForgedMethods() { - return forgedMethods; - } - @Override public int hashCode() { int hash = 7; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 4bac7add37..a0fa78d2ba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -36,7 +36,6 @@ import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; @@ -76,7 +75,6 @@ public class PropertyMapping extends ModelElement { private final Assignment assignment; private final List dependsOn; private final Assignment defaultValueAssignment; - private List forgedMethods = new ArrayList(); private enum TargetWriteAccessorType { FIELD, @@ -101,10 +99,7 @@ else if ( Executables.isGetterMethod( accessor ) ) { } @SuppressWarnings("unchecked") - private static class MappingBuilderBase> { - - protected MappingBuilderContext ctx; - protected Method method; + private static class MappingBuilderBase> extends AbstractBaseBuilder { protected Accessor targetWriteAccessor; protected TargetWriteAccessorType targetWriteAccessorType; @@ -117,14 +112,12 @@ private static class MappingBuilderBase> { protected List dependsOn; protected Set existingVariableNames; - public T mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return (T) this; + MappingBuilderBase(Class selfType) { + super( selfType ); } public T sourceMethod(Method sourceMethod) { - this.method = sourceMethod; - return (T) this; + return super.method( sourceMethod ); } public T targetProperty(PropertyEntry targetProp) { @@ -205,7 +198,10 @@ public static class PropertyMappingBuilder extends MappingBuilderBase forgedMethods = new ArrayList(); + + PropertyMappingBuilder() { + super( PropertyMappingBuilder.class ); + } public PropertyMappingBuilder sourceReference(SourceReference sourceReference) { this.sourceReference = sourceReference; @@ -303,8 +299,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get localTargetVarName, assignment, dependsOn, - getDefaultValueAssignment( assignment ), - forgedMethods + getDefaultValueAssignment( assignment ) ); } @@ -563,31 +558,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou .callingContextTargetPropertyName( targetPropertyName ) .build(); - return getForgedAssignment( source, methodRef, iterableMappingMethod ); - } - - private Assignment getForgedAssignment(SourceRHS source, ForgedMethod methodRef, - MappingMethod mappingMethod) { - Assignment assignment = null; - if ( mappingMethod != null ) { - if ( !ctx.getMappingsToGenerate().contains( mappingMethod ) ) { - ctx.getMappingsToGenerate().add( mappingMethod ); - } - else { - String existingName = ctx.getExistingMappingMethod( mappingMethod ).getName(); - methodRef = new ForgedMethod( existingName, methodRef ); - } - - assignment = new MethodReference( - methodRef, - null, - ParameterBinding.fromParameters( methodRef.getParameters() ) - ); - assignment.setAssignment( source ); - forgedMethods.addAll( mappingMethod.getForgedMethods() ); - } - - return assignment; + return createForgedAssignment( source, methodRef, iterableMappingMethod ); } private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, @@ -619,7 +590,7 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s .method( methodRef ) .build(); - return getForgedAssignment( source, methodRef, mapMappingMethod ); + return createForgedAssignment( source, methodRef, mapMappingMethod ); } private Assignment forgeMapping(SourceRHS sourceRHS) { @@ -632,6 +603,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { } String name = getName( sourceType, targetType ); + name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); List parameters = new ArrayList( method.getContextParameters() ); Type returnType; if ( method.isUpdateMethod() ) { @@ -651,16 +623,8 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { getForgedMethodHistory( sourceRHS ) ); - Assignment assignment = new MethodReference( - forgedMethod, - null, - ParameterBinding.fromParameters( forgedMethod.getParameters() ) ); - - assignment.setAssignment( sourceRHS ); - this.forgedMethods.add( forgedMethod ); - - return assignment; + return createForgedBeanAssignment( sourceRHS, forgedMethod ); } private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { @@ -715,6 +679,10 @@ public static class ConstantMappingBuilder extends MappingBuilderBase dependsOn, Assignment defaultValueAssignment ) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, - targetType, localTargetVarName, propertyAssignment, dependsOn, defaultValueAssignment, - Collections.emptyList() ); + targetType, localTargetVarName, propertyAssignment, dependsOn, defaultValueAssignment + ); } private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, ValueProvider targetReadAccessorProvider, Type targetType, String localTargetVarName, Assignment assignment, - List dependsOn, Assignment defaultValueAssignment, - List forgedMethods) { + List dependsOn, Assignment defaultValueAssignment) { this.name = name; this.sourceBeanName = sourceBeanName; this.targetWriteAccessorName = targetWriteAccessorName; @@ -895,7 +866,6 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.assignment = assignment; this.dependsOn = dependsOn != null ? dependsOn : Collections.emptyList(); this.defaultValueAssignment = defaultValueAssignment; - this.forgedMethods = forgedMethods; } /** @@ -950,10 +920,6 @@ public List getDependsOn() { return dependsOn; } - public List getForgedMethods() { - return forgedMethods; - } - @Override public String toString() { return "PropertyMapping {" diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index ed8b7ceb1f..318831bba6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -28,7 +28,6 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -64,8 +63,7 @@ protected Assignment getWrapper(Assignment assignment, Method method) { protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingMethods, - List afterMappingMethods, SelectionParameters selectionParameters, - ForgedMethod forgedMethod) { + List afterMappingMethods, SelectionParameters selectionParameters) { Set helperImports = new HashSet(); if ( method.getResultType().isIterableType() ) { @@ -87,8 +85,7 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment beforeMappingMethods, afterMappingMethods, selectionParameters, - helperImports, - forgedMethod + helperImports ); } } @@ -97,8 +94,7 @@ private StreamMappingMethod(Method method, Assignment parameterAssignment, Metho boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, - SelectionParameters selectionParameters, Set helperImports, - ForgedMethod forgedMethod) { + SelectionParameters selectionParameters, Set helperImports) { super( method, parameterAssignment, @@ -107,8 +103,7 @@ private StreamMappingMethod(Method method, Assignment parameterAssignment, Metho loopVariableName, beforeMappingReferences, afterMappingReferences, - selectionParameters, - forgedMethod + selectionParameters ); this.helperImports = helperImports; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index f0c72477e5..00d5a7f93d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -19,12 +19,9 @@ package org.mapstruct.ap.internal.processor; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; -import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import javax.lang.model.element.ExecutableElement; @@ -52,7 +49,6 @@ import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; @@ -153,7 +149,7 @@ private List initReferencedMappers(TypeElement element, MapperC private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List methods) { List mapperReferences = mappingContext.getMapperReferences(); - List mappingMethods = getAllMappingMethods( mapperConfig, methods ); + List mappingMethods = getMappingMethods( mapperConfig, methods ); mappingMethods.addAll( mappingContext.getUsedVirtualMappings() ); mappingMethods.addAll( mappingContext.getMappingsToGenerate() ); @@ -262,55 +258,6 @@ private SortedSet getExtraImports(TypeElement element) { return extraImports; } - private List getAllMappingMethods(MapperConfiguration mapperConfig, List methods) { - List mappingMethods = getMappingMethods( mapperConfig, methods ); - - Collection excludedForgedMethods = new HashSet( ); - Collection forgedMethods = collectAllForgedMethods( mappingMethods, excludedForgedMethods ); - - while ( !forgedMethods.isEmpty() ) { - List mappingMethodsFromForged = createBeanMapping( forgedMethods ); - forgedMethods = collectAllForgedMethods( mappingMethodsFromForged, excludedForgedMethods ); - mappingMethods.addAll( mappingMethodsFromForged ); - } - - return mappingMethods; - } - - private List createBeanMapping(Collection forgedMethods) { - List mappingMethods = new ArrayList(); - - for ( ForgedMethod method : forgedMethods ) { - - BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); - BeanMappingMethod beanMappingMethod = builder - .mappingContext( mappingContext ) - .forgedMethod( method ) - .build(); - - - if ( beanMappingMethod != null ) { - mappingMethods.add( beanMappingMethod ); - } - } - - return mappingMethods; - } - - private Collection collectAllForgedMethods(Collection mappingMethods, - Collection excludedForgedMethods) { - Set forgedMethods = new HashSet(); - for ( MappingMethod mappingMethod : mappingMethods ) { - for ( ForgedMethod forgedMethod : mappingMethod.getForgedMethods() ) { - if ( !excludedForgedMethods.contains( forgedMethod )) { - forgedMethods.add( forgedMethod ); - excludedForgedMethods.add( forgedMethod ); - } - } - } - return forgedMethods; - } - private List getMappingMethods(MapperConfiguration mapperConfig, List methods) { List mappingMethods = new ArrayList(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 7e650e640a..629f74efc1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -122,6 +122,11 @@ public void shouldGenerateNonMappleMethodForSetMapping() { line = 30, messageRegExp = "Can't map Map key \".* nonMappableMap\\{:key\\}\" to \".* nonMappableMap\\{:key\\}\". " + "Consider to declare/implement a mapping method: .*."), + @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, + kind = Kind.ERROR, + line = 30, + messageRegExp = "Can't map Map value \".* nonMappableMap\\{:value\\}\" to \".* " + + "nonMappableMap\\{:value\\}\". Consider to declare/implement a mapping method: .*."), } ) public void shouldGenerateNonMappleMethodForMapMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 4c780bc711..c01bc54067 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -29,6 +29,11 @@ User.class, UserDto.class, Car.class, CarDto.class, House.class, HouseDto.class, Wheel.class, WheelDto.class, Roof.class, RoofDto.class, + org.mapstruct.ap.test.nestedbeans.other.CarDto.class, + org.mapstruct.ap.test.nestedbeans.other.UserDto.class, + org.mapstruct.ap.test.nestedbeans.other.HouseDto.class, + org.mapstruct.ap.test.nestedbeans.other.RoofDto.class, + org.mapstruct.ap.test.nestedbeans.other.WheelDto.class, UserDtoMapperClassic.class, UserDtoMapperSmart.class, UserDtoUpdateMapperSmart.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java index 23bf6544de..6b50b65f31 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java @@ -22,6 +22,7 @@ public class User { private String name; private Car car; + private Car secondCar; private House house; public User() { @@ -49,6 +50,14 @@ public void setCar(Car car) { this.car = car; } + public Car getSecondCar() { + return secondCar; + } + + public void setSecondCar(Car secondCar) { + this.secondCar = secondCar; + } + public House getHouse() { return house; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java index 3ff64bd9f4..a36b08ca09 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java @@ -22,6 +22,7 @@ public class UserDto { private String name; private CarDto car; + private CarDto secondCar; private HouseDto house; public UserDto() { @@ -49,6 +50,14 @@ public void setCar(CarDto car) { this.car = car; } + public CarDto getSecondCar() { + return secondCar; + } + + public void setSecondCar(CarDto secondCar) { + this.secondCar = secondCar; + } + public HouseDto getHouse() { return house; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java index 86598904bf..90e5322cc1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java @@ -28,4 +28,5 @@ public interface UserDtoMapperSmart { UserDto userToUserDto(User user); + org.mapstruct.ap.test.nestedbeans.other.UserDto userToUserDto2( User user ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java new file mode 100644 index 0000000000..40678c5f96 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java @@ -0,0 +1,100 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.other; + +import java.util.List; + +public class CarDto { + + private String name; + private int year; + private List wheels; + + public CarDto() { + } + + public CarDto(String name, int year, List wheels) { + this.name = name; + this.year = year; + this.wheels = wheels; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public List getWheels() { + return wheels; + } + + public void setWheels(List wheels) { + this.wheels = wheels; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + CarDto carDto = (CarDto) o; + + if ( year != carDto.year ) { + return false; + } + if ( name != null ? !name.equals( carDto.name ) : carDto.name != null ) { + return false; + } + return wheels != null ? wheels.equals( carDto.wheels ) : carDto.wheels == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( wheels != null ? wheels.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "CarDto{" + + "name='" + name + '\'' + + ", year=" + year + + ", wheels=" + wheels + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java new file mode 100644 index 0000000000..fd927131af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.other; + +public class HouseDto { + + private String name; + private int year; + private RoofDto roof; + + public HouseDto() { + } + + public HouseDto(String name, int year, RoofDto roof) { + this.name = name; + this.year = year; + this.roof = roof; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + public RoofDto getRoof() { + return roof; + } + + public void setRoof(RoofDto roof) { + this.roof = roof; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + HouseDto houseDto = (HouseDto) o; + + if ( year != houseDto.year ) { + return false; + } + if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) { + return false; + } + return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + year; + result = 31 * result + ( roof != null ? roof.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "HouseDto{" + + "name='" + name + '\'' + + ", year=" + year + + ", roof=" + roof + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java new file mode 100644 index 0000000000..1101df7c82 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.other; + +public class RoofDto { + private String color; + + public RoofDto() { + } + + public RoofDto(String color) { + this.color = color; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + RoofDto roofDto = (RoofDto) o; + + return color != null ? color.equals( roofDto.color ) : roofDto.color == null; + + } + + @Override + public int hashCode() { + return color != null ? color.hashCode() : 0; + } + + @Override + public String toString() { + return "RoofDto{" + + "color='" + color + '\'' + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java new file mode 100644 index 0000000000..3ede3acbaa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.other; + +public class UserDto { + + private String name; + private CarDto car; + private HouseDto house; + + public UserDto() { + } + + public UserDto(String name, CarDto car, HouseDto house) { + this.name = name; + this.car = car; + this.house = house; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public CarDto getCar() { + return car; + } + + public void setCar(CarDto car) { + this.car = car; + } + + public HouseDto getHouse() { + return house; + } + + public void setHouse(HouseDto house) { + this.house = house; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + UserDto userDto = (UserDto) o; + + if ( name != null ? !name.equals( userDto.name ) : userDto.name != null ) { + return false; + } + if ( car != null ? !car.equals( userDto.car ) : userDto.car != null ) { + return false; + } + return house != null ? house.equals( userDto.house ) : userDto.house == null; + + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( car != null ? car.hashCode() : 0 ); + result = 31 * result + ( house != null ? house.hashCode() : 0 ); + return result; + } + + @Override + public String toString() { + return "UserDto{" + + "name='" + name + '\'' + + ", car=" + car + + ", house=" + house + + '}'; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java new file mode 100644 index 0000000000..feb4de4eac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java @@ -0,0 +1,80 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.other; + +public class WheelDto { + private boolean front; + private boolean right; + + public WheelDto() { + } + + public WheelDto(boolean front, boolean right) { + this.front = front; + this.right = right; + } + + public boolean isFront() { + return front; + } + + public void setFront(boolean front) { + this.front = front; + } + + public boolean isRight() { + return right; + } + + public void setRight(boolean right) { + this.right = right; + } + + @Override + public boolean equals(Object o) { + + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + + WheelDto wheel = (WheelDto) o; + + if ( front != wheel.front ) { + return false; + } + return right == wheel.right; + + } + + @Override + public int hashCode() { + int result = ( front ? 1 : 0 ); + result = 31 * result + ( right ? 1 : 0 ); + return result; + } + + @Override + public String toString() { + return "Wheel{" + ( front ? "front" : "rear" ) + ";" + ( right ? "right" : "left" ) + '}'; + } + +} From 12fcf7ce87a84032663f16846bc22fa937d41a40 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sat, 21 Jan 2017 10:30:25 +0100 Subject: [PATCH 0039/1006] #1047 removing unneeded NPE check for source parameter for update method --- .../org/mapstruct/ap/internal/model/MethodReference.java | 5 +++++ .../org/mapstruct/ap/internal/model/PropertyMapping.java | 6 +++--- .../java/org/mapstruct/ap/internal/model/SourceRHS.java | 5 +++++ .../org/mapstruct/ap/internal/model/TypeConversion.java | 5 +++++ .../mapstruct/ap/internal/model/assignment/Assignment.java | 6 ++++++ .../ap/internal/model/assignment/AssignmentWrapper.java | 5 +++++ .../ap/internal/model/assignment/SetterWrapper.java | 2 +- 7 files changed, 30 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index aea798f6d8..d28fd5ed63 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -160,6 +160,11 @@ public String getSourceParameterName() { return assignment.getSourceParameterName(); } + @Override + public boolean isSourceReferenceParameter() { + return assignment.isSourceReferenceParameter(); + } + /** * @return the type of the single source parameter that is not the {@code @TargetType} parameter */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index a0fa78d2ba..080631ab68 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -275,7 +275,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get assignment = assignToArray( targetType, assignment ); } else { - assignment = assignToPlain( sourceType, targetType, targetWriteAccessorType, assignment ); + assignment = assignToPlain( targetType, targetWriteAccessorType, assignment ); } } else { @@ -324,7 +324,7 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { return null; } - private Assignment assignToPlain(Type sourceType, Type targetType, TargetWriteAccessorType targetAccessorType, + private Assignment assignToPlain(Type targetType, TargetWriteAccessorType targetAccessorType, Assignment rightHandSide) { Assignment result; @@ -352,7 +352,7 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { } Assignment factory = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); return new UpdateWrapper( rhs, method.getThrownTypes(), factory, isFieldAssignment(), targetType, - true ); + !rhs.isSourceReferenceParameter() ); } else { NullValueCheckStrategyPrism nvcs = method.getMapperConfiguration().getNullValueCheckStrategy(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java index 14ba7a3c58..cdcd1d2a2b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java @@ -65,6 +65,11 @@ public String getSourceReference() { return sourceReference; } + @Override + public boolean isSourceReferenceParameter() { + return sourceReference.equals( sourceParameterName ); + } + @Override public String getSourcePresenceCheckerReference() { return sourcePresenceCheckerReference; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index 1e2a00749e..c5d62aff76 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -86,6 +86,11 @@ public String getSourceReference() { return assignment.getSourceReference(); } + @Override + public boolean isSourceReferenceParameter() { + return assignment.isSourceReferenceParameter(); + } + @Override public String getSourcePresenceCheckerReference() { return assignment.getSourcePresenceCheckerReference(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java index 1807c9e97e..e7e282dc39 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java @@ -94,6 +94,12 @@ public boolean isConverted() { */ String getSourceReference(); + /** + * + * @return true when the source reference is the source parameter (and not a property of the source parameter type) + */ + boolean isSourceReferenceParameter(); + /** * the source presence checker reference * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 2a72120434..641c1e61ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -63,6 +63,11 @@ public String getSourceReference() { return decoratedAssignment.getSourceReference(); } + @Override + public boolean isSourceReferenceParameter() { + return decoratedAssignment.isSourceReferenceParameter(); + } + @Override public String getSourcePresenceCheckerReference() { return decoratedAssignment.getSourcePresenceCheckerReference(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index 03467686b3..c3c79afb32 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -88,7 +88,7 @@ public boolean isIncludeSourceNullCheck() { * @return include a null check */ private boolean includeSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvms, Type targetType) { - return !rhs.getSourceReference().equals( rhs.getSourceParameterName() ) + return !rhs.isSourceReferenceParameter() && !rhs.getSourceType().isPrimitive() && (ALWAYS == nvms || rhs.getType().isConverted() || rhs.getSourceLocalVarName() != null || (rhs.getType().isDirect() && targetType.isPrimitive())); From 1406c0b6db7740bfe663edeae936cc3399bc72bb Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sat, 21 Jan 2017 11:14:11 +0100 Subject: [PATCH 0040/1006] #1011 Using ForgedMethods to forge nested target mappings --- .../conversion/CreateDecimalFormat.java | 5 + .../ap/internal/model/BeanMappingMethod.java | 511 ++++++++---------- .../ap/internal/model/LocalVariable.java | 88 --- .../model/NestedLocalVariableAssignment.java | 137 ----- .../ap/internal/model/PropertyMapping.java | 118 ++-- .../internal/model/source/ForgedMethod.java | 63 ++- .../ap/internal/model/source/Mapping.java | 47 +- .../internal/model/source/MappingOptions.java | 171 +++++- .../ap/internal/model/source/Method.java | 6 + .../internal/model/source/PropertyEntry.java | 43 +- .../internal/model/source/SourceMethod.java | 2 +- .../model/source/SourceReference.java | 23 + .../model/source/TargetReference.java | 24 +- .../model/source/builtin/BuiltInMethod.java | 6 + .../ap/internal/model/BeanMappingMethod.ftl | 9 - .../ap/internal/model/LocalVariable.ftl | 21 - .../model/NestedLocalVariableAssignment.ftl | 22 - .../ap/internal/model/PropertyMapping.ftl | 12 +- .../ChartEntryToArtist.java | 6 +- .../ChartEntryToArtistUpdate.java | 70 +++ .../FishTankMapper.java | 38 ++ .../NestedTargetPropertiesTest.java | 87 ++- .../_target/FishDto.java | 47 ++ .../_target/FishTankDto.java | 46 ++ .../_target/WaterPlantDto.java | 37 ++ .../nestedtargetproperties/source/Fish.java | 37 ++ .../source/FishTank.java | 55 ++ .../source/WaterPlant.java | 37 ++ 28 files changed, 1126 insertions(+), 642 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/LocalVariable.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.java delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/LocalVariable.ftl delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java index 3ae9f27fb2..d881a9fc1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java @@ -27,6 +27,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.MappingOptions; /** * HelperMethod that creates a {@link java.text.DecimalFormat} @@ -63,4 +64,8 @@ public Type getReturnType() { return returnType; } + @Override + public MappingOptions getMappingOptions() { + return MappingOptions.empty(); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 149e26d21a..580d53dd62 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -19,12 +19,9 @@ package org.mapstruct.ap.internal.model; import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; -import static org.mapstruct.ap.internal.util.Strings.getSaveVariableName; import java.text.MessageFormat; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -42,7 +39,6 @@ import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; @@ -50,6 +46,7 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -72,7 +69,7 @@ * * @author Gunnar Morling */ -public class BeanMappingMethod extends MappingMethod { +public class BeanMappingMethod extends ContainerMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; @@ -80,7 +77,6 @@ public class BeanMappingMethod extends MappingMethod { private final MethodReference factoryMethod; private final boolean mapNullToDefault; private final Type resultType; - private final NestedTargetObjects nestedTargetObjects; private final boolean overridden; public static class Builder { @@ -94,7 +90,6 @@ public static class Builder { private NullValueMappingStrategyPrism nullValueMappingStrategy; private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet(); - private NestedTargetObjects nestedTargetObjects; private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; @@ -105,28 +100,21 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { public Builder souceMethod(SourceMethod sourceMethod) { singleMapping = new SourceMethodSingleMapping( sourceMethod ); - return setupMethodWithMapping( sourceMethod, sourceMethod.getMappingOptions().getMappings() ); + return setupMethodWithMapping( sourceMethod ); } - public Builder forgedMethod(Method sourceMethod) { + public Builder forgedMethod(Method method ) { singleMapping = new EmptySingleMapping(); - return setupMethodWithMapping( sourceMethod, Collections.>emptyMap() ); + return setupMethodWithMapping( method ); } - private Builder setupMethodWithMapping(Method sourceMethod, Map> mappings) { + private Builder setupMethodWithMapping(Method sourceMethod) { this.method = sourceMethod; - this.methodMappings = mappings; + this.methodMappings = sourceMethod.getMappingOptions().getMappings(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); Map accessors = method.getResultType().getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); - this.nestedTargetObjects = new NestedTargetObjects.Builder() - .existingVariableNames( existingVariableNames ) - .mappings( mappings ) - .mappingBuilderContext( ctx ) - .sourceMethod( method ) - .build(); - this.unprocessedTargetProperties = new LinkedHashMap( accessors ); for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); @@ -147,16 +135,19 @@ public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueM public BeanMappingMethod build() { // map properties with mapping - boolean mappingErrorOccured = handleDefinedSourceMappings(); + boolean mappingErrorOccured = handleDefinedMappings(); if ( mappingErrorOccured ) { return null; } - // map properties without a mapping - applyPropertyNameBasedMapping(); + if ( !method.getMappingOptions().isRestrictToDefinedMappings() ) { + + // map properties without a mapping + applyPropertyNameBasedMapping(); - // map parameters without a mapping - applyParameterNameBasedMapping(); + // map parameters without a mapping + applyParameterNameBasedMapping(); + } // report errors on unmapped properties reportErrorForUnmappedTargetPropertiesIfRequired(); @@ -223,10 +214,8 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { factoryMethod, mapNullToDefault, resultType, - existingVariableNames, beforeMappingMethods, - afterMappingMethods, - nestedTargetObjects + afterMappingMethods ); } @@ -277,152 +266,200 @@ public int compare(PropertyMapping o1, PropertyMapping o2) { * It is furthermore checked whether the given mappings are correct. When an error occurs, the method continues * in search of more problems. */ - private boolean handleDefinedSourceMappings() { + private boolean handleDefinedMappings() { boolean errorOccurred = false; Set handledTargets = new HashSet(); + if ( method.getMappingOptions().hasNestedTargetReferences() ) { + handleDefinedNestedTargetMapping( handledTargets ); + } + for ( Map.Entry> entry : methodMappings.entrySet() ) { for ( Mapping mapping : entry.getValue() ) { - - PropertyMapping propertyMapping = null; - - TargetReference targetRef = mapping.getTargetReference(); - String resultPropertyName = null; - if ( targetRef.isValid() ) { - resultPropertyName = first( targetRef.getPropertyEntries() ).getName(); - } - - if ( !unprocessedTargetProperties.containsKey( resultPropertyName ) ) { - boolean hasReadAccessor = - method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); - - if ( hasReadAccessor ) { - if ( !mapping.isIgnored() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, - mapping.getTargetName() ); + TargetReference targetReference = mapping.getTargetReference(); + if ( targetReference.isValid() ) { + if ( !handledTargets.contains( first( targetReference.getPropertyEntries() ).getFullName() ) ) { + if ( handleDefinedMapping( mapping, handledTargets ) ) { errorOccurred = true; } } - else { - ctx.getMessager().printMessage( - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, - mapping.getTargetName() ); - errorOccurred = true; - } - - continue; } + else if ( reportErrorOnTargetObject( mapping ) ) { + errorOccurred = true; + } + } + } + for ( String handledTarget : handledTargets ) { + // In order to avoid: "Unknown property foo in return type" in case of duplicate + // target mappings + unprocessedTargetProperties.remove( handledTarget ); + } - PropertyEntry targetProperty = last( targetRef.getPropertyEntries() ); + return errorOccurred; + } - // unknown properties given via dependsOn()? - for ( String dependency : mapping.getDependsOn() ) { - if ( !targetProperties.contains( dependency ) ) { - ctx.getMessager().printMessage( - method.getExecutable(), - mapping.getMirror(), - mapping.getDependsOnAnnotationValue(), - Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON, - dependency - ); - errorOccurred = true; - } - } + private void handleDefinedNestedTargetMapping(Set handledTargets) { - // check the mapping options - // its an ignored property mapping - if ( mapping.isIgnored() ) { - propertyMapping = null; - handledTargets.add( mapping.getTargetName() ); - } + Map optionsByNestedTarget = + method.getMappingOptions().groupByPoppedTargetReferences(); + for ( Entry entryByTP : optionsByNestedTarget.entrySet() ) { - // its a plain-old property mapping - else if ( mapping.getSourceName() != null ) { + Map optionsBySourceParam = entryByTP.getValue().groupBySourceParameter(); + for ( Entry entryByParam : optionsBySourceParam.entrySet() ) { - // determine source parameter - SourceReference sourceRef = mapping.getSourceReference(); - if ( sourceRef.isValid() ) { + SourceReference sourceRef = new SourceReference.BuilderFromProperty() + .sourceParameter( entryByParam.getKey() ) + .name( entryByTP.getKey().getName() ) + .build(); - // targetProperty == null can occur: we arrived here because we want as many errors - // as possible before we stop analysing - propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) - .sourceReference( sourceRef ) - .selectionParameters( mapping.getSelectionParameters() ) - .formattingParameters( mapping.getFormattingParameters() ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mapping.getDependsOn() ) - .defaultValue( mapping.getDefaultValue() ) - .localTargetVarName( nestedTargetObjects.getLocalVariableName( targetRef ) ) - .build(); - handledTargets.add( resultPropertyName ); - unprocessedSourceParameters.remove( sourceRef.getParameter() ); - } - else { - errorOccurred = true; - continue; - } + PropertyMapping propertyMapping = new PropertyMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .targetProperty( entryByTP.getKey() ) + .targetPropertyName( entryByTP.getKey().getName() ) + .sourceReference( sourceRef ) + .existingVariableNames( existingVariableNames ) + .dependsOn( entryByParam.getValue().collectNestedDependsOn() ) + .forgeMethodWithMappingOptions( entryByParam.getValue() ) + .build(); + unprocessedSourceParameters.remove( sourceRef.getParameter() ); + + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); } + } + handledTargets.add( entryByTP.getKey().getName() ); + } - // its a constant - else if ( mapping.getConstant() != null ) { + } - propertyMapping = new ConstantMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .constantExpression( "\"" + mapping.getConstant() + "\"" ) - .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) - .formattingParameters( mapping.getFormattingParameters() ) - .selectionParameters( mapping.getSelectionParameters() ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mapping.getDependsOn() ) - .localTargetVarName( nestedTargetObjects.getLocalVariableName( targetRef ) ) - .build(); - handledTargets.add( mapping.getTargetName() ); - } + private boolean handleDefinedMapping(Mapping mapping, Set handledTargets) { - // its an expression - else if ( mapping.getJavaExpression() != null ) { + boolean errorOccured = false; - propertyMapping = new JavaExpressionMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .javaExpression( mapping.getJavaExpression() ) - .existingVariableNames( existingVariableNames ) - .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) - .dependsOn( mapping.getDependsOn() ) - .localTargetVarName( nestedTargetObjects.getLocalVariableName( targetRef ) ) - .build(); - handledTargets.add( mapping.getTargetName() ); - } + PropertyMapping propertyMapping = null; - // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers + TargetReference targetRef = mapping.getTargetReference(); + PropertyEntry targetProperty = first( targetRef.getPropertyEntries() ); - if ( propertyMapping != null ) { - propertyMappings.add( propertyMapping ); - } + // unknown properties given via dependsOn()? + for ( String dependency : mapping.getDependsOn() ) { + if ( !targetProperties.contains( dependency ) ) { + ctx.getMessager().printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getDependsOnAnnotationValue(), + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON, + dependency + ); + errorOccured = true; } } - for ( String handledTarget : handledTargets ) { - // In order to avoid: "Unknown property foo in return type" in case of duplicate - // target mappings - unprocessedTargetProperties.remove( handledTarget ); + // check the mapping options + // its an ignored property mapping + if ( mapping.isIgnored() ) { + propertyMapping = null; + handledTargets.add( mapping.getTargetName() ); + } + + // its a plain-old property mapping + else if ( mapping.getSourceName() != null ) { + + // determine source parameter + SourceReference sourceRef = mapping.getSourceReference(); + if ( sourceRef.isValid() ) { + + // targetProperty == null can occur: we arrived here because we want as many errors + // as possible before we stop analysing + propertyMapping = new PropertyMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .targetProperty( targetProperty ) + .targetPropertyName( mapping.getTargetName() ) + .sourceReference( sourceRef ) + .selectionParameters( mapping.getSelectionParameters() ) + .formattingParameters( mapping.getFormattingParameters() ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mapping.getDependsOn() ) + .defaultValue( mapping.getDefaultValue() ) + .build(); + handledTargets.add( targetProperty.getName() ); + unprocessedSourceParameters.remove( sourceRef.getParameter() ); + } + else { + errorOccured = true; + } + } + + // its a constant + else if ( mapping.getConstant() != null ) { + + propertyMapping = new ConstantMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .constantExpression( "\"" + mapping.getConstant() + "\"" ) + .targetProperty( targetProperty ) + .targetPropertyName( mapping.getTargetName() ) + .formattingParameters( mapping.getFormattingParameters() ) + .selectionParameters( mapping.getSelectionParameters() ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mapping.getDependsOn() ) + .build(); + handledTargets.add( mapping.getTargetName() ); + } + + // its an expression + else if ( mapping.getJavaExpression() != null ) { + + propertyMapping = new JavaExpressionMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .javaExpression( mapping.getJavaExpression() ) + .existingVariableNames( existingVariableNames ) + .targetProperty( targetProperty ) + .targetPropertyName( mapping.getTargetName() ) + .dependsOn( mapping.getDependsOn() ) + .build(); + handledTargets.add( mapping.getTargetName() ); } + // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); + } + + return errorOccured; + } + + private boolean reportErrorOnTargetObject(Mapping mapping) { + + boolean errorOccurred = false; + + boolean hasReadAccessor + = method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); + + if ( hasReadAccessor ) { + if ( !mapping.isIgnored() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue(), + Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, + mapping.getTargetName() ); + errorOccurred = true; + } + } + else { + ctx.getMessager().printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue(), + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, + mapping.getTargetName() ); + errorOccurred = true; + } return errorOccurred; } @@ -574,9 +611,10 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { //we handle forged methods differently than the usual source ones. in if ( method instanceof ForgedMethod ) { - if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { - ForgedMethod forgedMethod = (ForgedMethod) this.method; + ForgedMethod forgedMethod = (ForgedMethod) this.method; + if ( forgedMethod.isAutoMapping() + && ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) ) { if ( forgedMethod.getHistory() == null ) { Type sourceType = this.method.getParameters().get( 0 ).getType(); @@ -628,11 +666,19 @@ private BeanMappingMethod(Method method, MethodReference factoryMethod, boolean mapNullToDefault, Type resultType, - Collection existingVariableNames, List beforeMappingReferences, - List afterMappingReferences, - NestedTargetObjects nestedTargetObjects) { - super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences ); + List afterMappingReferences) { + super( + method, + null, + factoryMethod, + mapNullToDefault, + null, + beforeMappingReferences, + afterMappingReferences, + null + ); + this.propertyMappings = propertyMappings; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a @@ -652,7 +698,6 @@ private BeanMappingMethod(Method method, this.factoryMethod = factoryMethod; this.mapNullToDefault = mapNullToDefault; this.resultType = resultType; - this.nestedTargetObjects = nestedTargetObjects.init( this.getResultName() ); this.overridden = method.overridesMethod(); } @@ -668,18 +713,12 @@ public Map> getPropertyMappingsByParameter() { return mappingsByParameter; } - public Set getLocalVariablesToCreate() { - return this.nestedTargetObjects.localVariables; - } - - public Set getNestedLocalVariableAssignments() { - return this.nestedTargetObjects.nestedAssignments; - } - + @Override public boolean isMapNullToDefault() { return mapNullToDefault; } + @Override public boolean isOverridden() { return overridden; } @@ -701,7 +740,6 @@ public Set getImportTypes() { for ( PropertyMapping propertyMapping : propertyMappings ) { types.addAll( propertyMapping.getImportTypes() ); } - types.addAll( nestedTargetObjects.getImportTypes() ); return types; } @@ -727,148 +765,45 @@ public List getSourcePrimitiveParameters() { return sourceParameters; } + @Override public MethodReference getFactoryMethod() { return this.factoryMethod; } - private static class NestedTargetObjects { - - private final Set localVariables; - private final Set nestedAssignments; - // local variable names indexed by fullname - private final Map localVariableNames; - - private Set getImportTypes() { - Set importedTypes = new HashSet(); - for ( LocalVariable localVariableToCreate : localVariables ) { - importedTypes.add( localVariableToCreate.getType() ); - } - return importedTypes; - } - - private static class Builder { - - private Map> mappings; - private Set existingVariableNames; - private MappingBuilderContext ctx; - private Method method; - - private Builder mappings(Map> mappings) { - this.mappings = mappings; - return this; - } - - private Builder existingVariableNames(Set existingVariableNames) { - this.existingVariableNames = existingVariableNames; - return this; - } - - private Builder mappingBuilderContext(MappingBuilderContext ctx) { - this.ctx = ctx; - return this; - } - - private Builder sourceMethod(Method method) { - this.method = method; - return this; - } - - private NestedTargetObjects build() { - - Map uniquePropertyEntries = new HashMap(); - Map localVariableNames = new HashMap(); - Set localVariables = new HashSet(); - - // colllect unique local variables - for ( Map.Entry> mapping : mappings.entrySet() ) { - - TargetReference targetRef = first( mapping.getValue() ).getTargetReference(); - List propertyEntries = targetRef.getPropertyEntries(); - - for ( int i = 0; i < propertyEntries.size() - 1; i++ ) { - PropertyEntry entry = propertyEntries.get( i ); - uniquePropertyEntries.put( entry.getFullName(), entry ); - } - - } - - // assign variable names and create local variables. - for ( PropertyEntry propertyEntry : uniquePropertyEntries.values() ) { - String name = getSaveVariableName( propertyEntry.getName(), existingVariableNames ); - existingVariableNames.add( name ); - Type type = propertyEntry.getType(); - Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, type, null ); - localVariables.add( new LocalVariable( name, type, factoryMethod ) ); - localVariableNames.put( propertyEntry.getFullName(), name ); - } - - - Set relations = new HashSet(); - - // create relations branches (getter / setter) -- need to go to postInit() - for ( Map.Entry> mapping : mappings.entrySet() ) { + @Override + public Type getResultElementType() { + return null; + } - TargetReference targetRef = first( mapping.getValue() ).getTargetReference(); - List propertyEntries = targetRef.getPropertyEntries(); + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); + return result; + } - for ( int i = 0; i < propertyEntries.size() - 1; i++ ) { - // null means the targetBean is the methods targetBean. Needs to be set later. - String targetBean = null; - if ( i > 0 ) { - PropertyEntry targetPropertyEntry = propertyEntries.get( i - 1 ); - targetBean = localVariableNames.get( targetPropertyEntry.getFullName() ); - } - PropertyEntry sourcePropertyEntry = propertyEntries.get( i ); - String targetAccessor = sourcePropertyEntry.getWriteAccessor().getSimpleName().toString(); - String sourceRef = localVariableNames.get( sourcePropertyEntry.getFullName() ); - relations.add( new NestedLocalVariableAssignment( - targetBean, - targetAccessor, - sourceRef, - sourcePropertyEntry.getWriteAccessor().getExecutable() == null - ) ); - } - } + @Override + public boolean equals(Object obj) { - return new NestedTargetObjects( localVariables, localVariableNames, relations ); - } + if ( this == obj ) { + return true; } - - private NestedTargetObjects(Set localVariables, Map localVariableNames, - Set relations) { - this.localVariables = localVariables; - this.localVariableNames = localVariableNames; - this.nestedAssignments = relations; + if ( obj == null || getClass() != obj.getClass() ) { + return false; } - /** - * returns a local vaRriable name when relevant (so when not the 'parameter' targetBean should be used) - * - * @param targetRef - * - * @return generated local variable name - */ - private String getLocalVariableName(TargetReference targetRef) { - String result = null; - List propertyEntries = targetRef.getPropertyEntries(); - if ( propertyEntries.size() > 1 ) { - result = localVariableNames.get( propertyEntries.get( propertyEntries.size() - 2 ).getFullName() ); - } - return result; - } + BeanMappingMethod that = (BeanMappingMethod) obj; - private NestedTargetObjects init(String targetBeanName) { - for ( NestedLocalVariableAssignment nestedAssignment : nestedAssignments ) { - if ( nestedAssignment.getTargetBean() == null ) { - nestedAssignment.setTargetBean( targetBeanName ); - } - } - return this; + if ( !super.equals( obj ) ) { + return false; } - + return propertyMappings != null ? propertyMappings.equals( that.propertyMappings ) : + that.propertyMappings == null; } private interface SingleMappingByTargetPropertyNameFunction { + Mapping getSingleMappingByTargetPropertyName(String targetPropertyName); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LocalVariable.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LocalVariable.java deleted file mode 100644 index ebe29e1cc6..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LocalVariable.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.internal.model; - -import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; -import org.mapstruct.ap.internal.model.common.ModelElement; -import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.util.Collections; - -/** - * Local variable used in a mapping method. - * - * @author Sjaak Derksen - */ -public class LocalVariable extends ModelElement { - - private final String name; - private final Type type; - private final Assignment factoryMethod; - - public LocalVariable( String name, Type type, Assignment factoryMethod ) { - this.name = name; - this.type = type; - this.factoryMethod = factoryMethod; - } - - public String getName() { - return name; - } - - public Type getType() { - return type; - } - - public Assignment getFactoryMethod() { - return factoryMethod; - } - - @Override - public String toString() { - return type.toString() + " " + name; - } - - @Override - public Set getImportTypes() { - return Collections.asSet( type ); - } - - @Override - public int hashCode() { - int hash = 5; - hash = 23 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object obj) { - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - final LocalVariable other = (LocalVariable) obj; - if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { - return false; - } - return true; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.java deleted file mode 100644 index 90d7a08446..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.internal.model; - -import static java.util.Collections.emptySet; - -import java.util.Set; - -import org.mapstruct.ap.internal.model.common.ModelElement; -import org.mapstruct.ap.internal.model.common.Type; - -/** - * - * @author Sjaak Derksen - * - * In the process of creating target mappings, MapStruct creates local variables. - *

    - * {@code Chart chart = new Chart();
    - *
    - *       Label label = new Label();
    - *       Artist artist = new Artist();
    - *       Song song = new Song();
    - *       Studio studio = new Studio();
    - *       artist.setLabel( label ); // NestedLocalVariableAssignment
    - *       song.setArtist( artist ); // NestedLocalVariableAssignment
    - *       label.setStudio( studio );// NestedLocalVariableAssignment
    - *       chart.setSong( song ); // NestedLocalVariableAssignment
    - * }
    - *
    - */ -public class NestedLocalVariableAssignment extends ModelElement { - - private String targetBean; - private final String setterName; - private final String sourceRef; - private final boolean fieldAssignment; - - public NestedLocalVariableAssignment(String targetBean, String setterName, String sourceRef, - boolean fieldAssignment) { - this.targetBean = targetBean; - this.setterName = setterName; - this.sourceRef = sourceRef; - this.fieldAssignment = fieldAssignment; - } - - /** - * - * @return the targetBean on which the property setter with {@link setterName} is called - */ - public String getTargetBean() { - return targetBean; - } - - /** - * - * @param targetBean the targetBean on which the property setter with {@link setterName} is called - */ - public void setTargetBean(String targetBean) { - this.targetBean = targetBean; - } - - /** - * - * @return the name of the setter (target accessor for the property) - */ - public String getSetterName() { - return setterName; - } - - /** - * - * @return source reference, to be used a argument in the setter. - */ - public String getSourceRef() { - return sourceRef; - } - - @Override - public Set getImportTypes() { - return emptySet(); - } - - /** - * @return {@code true}if field assignment should be used, {@code false} otherwise - */ - public boolean isFieldAssignment() { - return fieldAssignment; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 97 * hash + ( this.targetBean != null ? this.targetBean.hashCode() : 0 ); - hash = 97 * hash + ( this.sourceRef != null ? this.sourceRef.hashCode() : 0 ); - hash = 97 * hash + ( this.fieldAssignment ? 1 : 0 ); - return hash; - } - - @Override - public boolean equals(Object obj) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - final NestedLocalVariableAssignment other = (NestedLocalVariableAssignment) obj; - if ( ( this.targetBean == null ) ? ( other.targetBean != null ) : - !this.targetBean.equals( other.targetBean ) ) { - return false; - } - if ( ( this.sourceRef == null ) ? ( other.sourceRef != null ) : !this.sourceRef.equals( other.sourceRef ) ) { - return false; - } - return this.fieldAssignment == other.fieldAssignment; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 080631ab68..3f1435395b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -40,6 +40,7 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -70,7 +71,6 @@ public class PropertyMapping extends ModelElement { private final String sourceBeanName; private final String targetWriteAccessorName; private final ValueProvider targetReadAccessorProvider; - private final String localTargetVarName; private final Type targetType; private final Assignment assignment; private final List dependsOn; @@ -107,7 +107,6 @@ private static class MappingBuilderBase> extends protected Accessor targetReadAccessor; protected TargetWriteAccessorType targetReadAccessorType; protected String targetPropertyName; - protected String localTargetVarName; protected List dependsOn; protected Set existingVariableNames; @@ -147,11 +146,6 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { return (T) this; } - public T localTargetVarName(String localTargetVarName) { - this.localTargetVarName = localTargetVarName; - return (T) this; - } - private Type determineTargetType() { // This is a bean mapping method, so we know the result is a declared type DeclaredType resultType = (DeclaredType) method.getResultType().getTypeMirror(); @@ -198,6 +192,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase parameters = new ArrayList( method.getContextParameters() ); Type returnType; - if ( method.isUpdateMethod() ) { + // there's only one case for forging a method with mapping options: nested target properties. + // they should always forge an update method + if ( method.isUpdateMethod() || forgeMethodWithMappingOptions != null ) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } else { returnType = targetType; } - ForgedMethod forgedMethod = new ForgedMethod( - name, - sourceType, - returnType, - method.getMapperConfiguration(), - method.getExecutable(), - parameters, - getForgedMethodHistory( sourceRHS ) - ); - + ForgedMethod forgedMethod; + if ( forgeMethodWithMappingOptions != null ) { + forgedMethod = new ForgedMethod( + name, + sourceType, + returnType, + method.getMapperConfiguration(), + method.getExecutable(), + parameters, + forgeMethodWithMappingOptions + ); + } + else { + forgedMethod = new ForgedMethod( + name, + sourceType, + returnType, + method.getMapperConfiguration(), + method.getExecutable(), + parameters, + getForgedMethodHistory( sourceRHS ) + ); + } return createForgedBeanAssignment( sourceRHS, forgedMethod ); } @@ -768,7 +787,6 @@ public PropertyMapping build() { targetWriteAccessor.getSimpleName().toString(), ValueProvider.of( targetReadAccessor ), targetType, - localTargetVarName, assignment, dependsOn, null @@ -833,7 +851,6 @@ public PropertyMapping build() { targetWriteAccessor.getSimpleName().toString(), ValueProvider.of( targetReadAccessor ), targetType, - localTargetVarName, assignment, dependsOn, null @@ -845,15 +862,15 @@ public PropertyMapping build() { // Constructor for creating mappings of constant expressions. private PropertyMapping(String name, String targetWriteAccessorName, ValueProvider targetReadAccessorProvider, - Type targetType, String localTargetVarName, Assignment propertyAssignment, + Type targetType, Assignment propertyAssignment, List dependsOn, Assignment defaultValueAssignment ) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, - targetType, localTargetVarName, propertyAssignment, dependsOn, defaultValueAssignment + targetType, propertyAssignment, dependsOn, defaultValueAssignment ); } private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, - ValueProvider targetReadAccessorProvider, Type targetType, String localTargetVarName, + ValueProvider targetReadAccessorProvider, Type targetType, Assignment assignment, List dependsOn, Assignment defaultValueAssignment) { this.name = name; @@ -861,7 +878,6 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.targetWriteAccessorName = targetWriteAccessorName; this.targetReadAccessorProvider = targetReadAccessorProvider; this.targetType = targetType; - this.localTargetVarName = localTargetVarName; this.assignment = assignment; this.dependsOn = dependsOn != null ? dependsOn : Collections.emptyList(); @@ -891,10 +907,6 @@ public Type getTargetType() { return targetType; } - public String getLocalTargetVarName() { - return localTargetVarName; - } - public Assignment getAssignment() { return assignment; } @@ -920,6 +932,36 @@ public List getDependsOn() { return dependsOn; } + @Override + public int hashCode() { + int hash = 5; + hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0); + hash = 67 * hash + (this.targetType != null ? this.targetType.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final PropertyMapping other = (PropertyMapping) obj; + if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { + return false; + } + if ( this.targetType != other.targetType && (this.targetType == null || + !this.targetType.equals( other.targetType )) ) { + return false; + } + return true; + } + @Override public String toString() { return "PropertyMapping {" diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 3c6c0377ce..f555cfa464 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -48,6 +48,8 @@ public class ForgedMethod implements Method { private final List sourceParameters; private final List contextParameters; private final Parameter mappingTargetParameter; + private final MappingOptions mappingOptions; + private boolean autoMapping; /** * Creates a new forged method with the given name. @@ -61,7 +63,43 @@ public class ForgedMethod implements Method { */ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters) { - this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null ); + this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null, + false, MappingOptions.empty() ); + } + + /** + * Creates a new forged method with the given name with history + * + * @param name the (unique name) for this method + * @param sourceType the source type + * @param returnType the return type. + * @param mapperConfiguration the mapper configuration + * @param positionHintElement element used to for reference to the position in the source file. + * @param additionalParameters additional parameters to add to the forged method + * @param history a parent forged method if this is a forged method within a forged method + */ + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, + ExecutableElement positionHintElement, List additionalParameters, ForgedMethodHistory history) { + this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, history, + true, MappingOptions.empty() ); + } + + /** + * Creates a new forged method with the given name with mapping options + * + * @param name the (unique name) for this method + * @param sourceType the source type + * @param returnType the return type. + * @param mapperConfiguration the mapper configuration + * @param positionHintElement element used to for reference to the position in the source file. + * @param additionalParameters additional parameters to add to the forged method + * @param mappingOptions with mapping options + */ + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, + ExecutableElement positionHintElement, List additionalParameters, + MappingOptions mappingOptions) { + this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null, + false, mappingOptions ); } /** @@ -74,15 +112,17 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method * @param history a parent forged method if this is a forged method within a forged method + * @param mappingOptions the mapping options for this method */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, + private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters, - ForgedMethodHistory history) { + ForgedMethodHistory history, boolean autoMapping, MappingOptions mappingOptions) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); this.parameters = new ArrayList( 1 + additionalParameters.size() ); - this.parameters.add( new Parameter( sourceParamSafeName, sourceType ) ); + Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); + this.parameters.add( sourceParameter ); this.parameters.addAll( additionalParameters ); this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); @@ -94,6 +134,9 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu this.mapperConfiguration = mapperConfiguration; this.positionHintElement = positionHintElement; this.history = history; + this.autoMapping = autoMapping; + this.mappingOptions = mappingOptions; + this.mappingOptions.initWithParameter( sourceParameter ); } /** @@ -108,10 +151,12 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.mapperConfiguration = forgedMethod.mapperConfiguration; this.positionHintElement = forgedMethod.positionHintElement; this.history = forgedMethod.history; + this.autoMapping = forgedMethod.autoMapping; this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); + this.mappingOptions = forgedMethod.mappingOptions; this.name = name; } @@ -195,6 +240,10 @@ public ForgedMethodHistory getHistory() { return history; } + public boolean isAutoMapping() { + return autoMapping; + } + public void addThrownTypes(List thrownTypesToAdd) { for ( Type thrownType : thrownTypesToAdd ) { // make sure there are no duplicates coming from the keyAssignment thrown types. @@ -278,6 +327,11 @@ public boolean isObjectFactory() { return false; } + @Override + public MappingOptions getMappingOptions() { + return mappingOptions; + } + @Override public boolean equals(Object o) { if ( this == o ) { @@ -306,5 +360,4 @@ public int hashCode() { result = 31 * result + ( name != null ? name.hashCode() : 0 ); return result; } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index bfcabfaca8..e3517ea015 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ElementKind; @@ -33,13 +32,14 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; - +import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.Strings; /** * Represents a property mapping as configured via {@code @Mapping}. @@ -184,6 +184,24 @@ private Mapping( String sourceName, String constant, String javaExpression, Stri this.dependsOn = dependsOn; } + private Mapping( Mapping mapping, TargetReference targetReference ) { + this.sourceName = mapping.sourceName; + this.constant = mapping.constant; + this.javaExpression = mapping.javaExpression; + this.targetName = Strings.join( targetReference.getElementNames(), "." ); + this.defaultValue = mapping.defaultValue; + this.isIgnored = mapping.isIgnored; + this.mirror = mapping.mirror; + this.sourceAnnotationValue = mapping.sourceAnnotationValue; + this.targetAnnotationValue = mapping.targetAnnotationValue; + this.formattingParameters = mapping.formattingParameters; + this.selectionParameters = mapping.selectionParameters; + this.dependsOnAnnotationValue = mapping.dependsOnAnnotationValue; + this.dependsOn = mapping.dependsOn; + this.sourceReference = mapping.sourceReference; + this.targetReference = targetReference; + } + private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, FormattingMessager messager) { if ( mappingPrism.expression().isEmpty() ) { @@ -228,6 +246,21 @@ public void init(SourceMethod method, FormattingMessager messager, TypeFactory t } } + /** + * Initializes the mapping with a new source parameter. + * + * @param sourceParameter + */ + public void init( Parameter sourceParameter ) { + if ( sourceReference != null ) { + SourceReference oldSourceReference = sourceReference; + sourceReference = new SourceReference.BuilderFromSourceReference() + .sourceParameter( sourceParameter ) + .sourceReference( oldSourceReference ) + .build(); + } + } + /** * Returns the complete source name of this mapping, either a qualified (e.g. {@code parameter1.foo}) or * unqualified (e.g. {@code foo}) property reference. @@ -290,6 +323,16 @@ public TargetReference getTargetReference() { return targetReference; } + public Mapping popTargetReference() { + if ( targetReference != null ) { + TargetReference newTargetReference = targetReference.pop(); + if (newTargetReference != null ) { + return new Mapping(this, newTargetReference ); + } + } + return null; + } + public List getDependsOn() { return dependsOn; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index bf08ab5175..91412342d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -21,6 +21,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -28,6 +29,7 @@ import java.util.Map; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -43,14 +45,37 @@ public class MappingOptions { private BeanMapping beanMapping; private List valueMappings; private boolean fullyInitialized; + private final boolean restrictToDefinedMappings; public MappingOptions(Map> mappings, IterableMapping iterableMapping, MapMapping mapMapping, - BeanMapping beanMapping, List valueMappings ) { + BeanMapping beanMapping, List valueMappings, boolean restrictToDefinedMappings ) { this.mappings = mappings; this.iterableMapping = iterableMapping; this.mapMapping = mapMapping; this.beanMapping = beanMapping; this.valueMappings = valueMappings; + this.restrictToDefinedMappings = restrictToDefinedMappings; + } + + /** + * creates empty mapping options + * + * @return empty mapping options + */ + public static MappingOptions empty() { + return new MappingOptions( Collections.>emptyMap(), null, null, null, + Collections.emptyList(), false ); + } + + /** + * creates mapping options with only regular mappings + * + * @param mappings regular mappings to add + * @return MappingOptions with only regular mappings + */ + public static MappingOptions forMappingsOnly( Map> mappings ) { + return new MappingOptions( mappings, null, null, null, Collections.emptyList(), true ); + } /** @@ -61,6 +86,146 @@ public Map> getMappings() { return mappings; } + /** + * The target references are popped. The MappingOptions are keyed on the unique first entries of the + * target references. + * + * So, take + * + * targetReference 1: propertyEntryX.propertyEntryX1.propertyEntryX1a + * targetReference 2: propertyEntryX.propertyEntryX2 + * targetReference 3: propertyEntryY.propertyY1 + * targetReference 4: propertyEntryZ + * + * will be popped and grouped into entries: + * + * propertyEntryX - MappingOptions ( targetReference1: propertyEntryX1.propertyEntryX1a, + * targetReference2: propertyEntryX2 ) + * propertyEntryY - MappingOptions ( targetReference1: propertyEntryY1 ) + * + * The key will be the former top level property, the MappingOptions will contain the remainders. + * + * So, 2 cloned new MappingOptions with popped targetReferences. Also Note that the not nested targetReference4 + * disappeared. + * + * @return See above + */ + public Map groupByPoppedTargetReferences() { + + // group all mappings based on the top level name before popping + Map> mappingsKeyedByProperty = new HashMap>(); + for ( List mapping : mappings.values() ) { + Mapping newMapping = first( mapping ).popTargetReference(); + if ( newMapping != null ) { + // group properties on current name. + PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); + if ( !mappingsKeyedByProperty.containsKey( property ) ) { + mappingsKeyedByProperty.put( property, new ArrayList() ); + } + mappingsKeyedByProperty.get( property ).add( newMapping ); + } + } + + // now group them into mapping options + Map result = new HashMap(); + for ( Map.Entry> mappingKeyedByProperty : mappingsKeyedByProperty.entrySet() ) { + Map> newEntries = new HashMap>(); + for ( Mapping newEntry : mappingKeyedByProperty.getValue() ) { + newEntries.put( newEntry.getTargetName(), Arrays.asList( newEntry ) ); + } + result.put( mappingKeyedByProperty.getKey(), forMappingsOnly( newEntries ) ); + } + return result; + } + + /** + * Check there are nested target references for this mapping options. + * + * @return boolean, true if there are nested target references + */ + public boolean hasNestedTargetReferences() { + for ( List mappingList : mappings.values() ) { + for ( Mapping mapping : mappingList ) { + TargetReference targetReference = mapping.getTargetReference(); + if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { + return true; + } + } + } + return false; + } + + /** + * + * @return all dependencies to other properties the contained mappings are dependent on + */ + public List collectNestedDependsOn() { + + List nestedDependsOn = new ArrayList(); + for ( List mappingList : mappings.values() ) { + for ( Mapping mapping : mappingList ) { + nestedDependsOn.addAll( mapping.getDependsOn() ); + } + } + return nestedDependsOn; + } + + /** + * Splits the MappingOptions into possibly more MappingOptions based on each source method parameter type. + * + * Note: this method is used for forging nested update methods. For that purpose, the same method with all + * joined mappings should be generated. See also: NestedTargetPropertiesTest#shouldMapNestedComposedTarget + * + * @return the split mapping options. + * + */ + public Map groupBySourceParameter() { + + Map> mappingsKeyedByParameterType = new HashMap>(); + for ( List mappingList : mappings.values() ) { + for ( Mapping mapping : mappingList ) { + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { + Parameter parameter = mapping.getSourceReference().getParameter(); + if ( !mappingsKeyedByParameterType.containsKey( parameter ) ) { + mappingsKeyedByParameterType.put( parameter, new ArrayList() ); + } + mappingsKeyedByParameterType.get( parameter ).add( mapping ); + } + } + } + + Map result = new HashMap(); + for ( Map.Entry> entry : mappingsKeyedByParameterType.entrySet() ) { + result.put( entry.getKey(), MappingOptions.forMappingsOnly( groupByTargetName( entry.getValue() ) ) ); + } + return result; + } + + private Map> groupByTargetName( List mappingList ) { + Map> result = new HashMap>(); + for ( Mapping mapping : mappingList ) { + if ( !result.containsKey( mapping.getTargetName() ) ) { + result.put( mapping.getTargetName(), new ArrayList() ); + } + result.get( mapping.getTargetName() ).add( mapping ); + } + return result; + } + + /** + * Initializes the underlying mappings with a new property. Specifically used in in combination with forged methods + * where the new parameter name needs to be established at a later moment. + * + * @param sourceParameter the new source parameter + */ + public void initWithParameter( Parameter sourceParameter ) { + for ( List mappingList : mappings.values() ) { + for ( Mapping mapping : mappingList ) { + mapping.init( sourceParameter ); + } + } + } + public IterableMapping getIterableMapping() { return iterableMapping; } @@ -223,4 +388,8 @@ private void filterNestedTargetIgnores( Map> mappings) { } + public boolean isRestrictToDefinedMappings() { + return restrictToDefinedMappings; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index ab0159f87a..2e77eabc8c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -189,4 +189,10 @@ public interface Method { * {@code @MappingTarget}. */ boolean isUpdateMethod(); + + /** + * + * @return the mapping options for this method + */ + MappingOptions getMappingOptions(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java index e86b836ac9..b88b3cbe0a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java @@ -29,14 +29,6 @@ /** * A PropertyEntry contains information on the name, readAccessor (for source), readAccessor and writeAccessor * (for targets) and return type of a property. - * - * It can be shared between several nested properties. For example - * - * bean - * - * nestedMapping1 = "x.y1.z1" nestedMapping2 = "x.y1.z2" nestedMapping3 = "x.y2.z3" - * - * has property entries x, y1, y2, z1, z2, z3. */ public class PropertyEntry { @@ -115,4 +107,39 @@ public String getFullName() { return Strings.join( Arrays.asList( fullName ), "." ); } + public PropertyEntry pop() { + if ( fullName.length > 1 ) { + String[] newFullName = Arrays.copyOfRange( fullName, 1, fullName.length ); + return new PropertyEntry(newFullName, readAccessor, writeAccessor, presenceChecker, type ); + } + else { + return null; + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + Arrays.deepHashCode( this.fullName ); + return hash; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + final PropertyEntry other = (PropertyEntry) obj; + if ( !Arrays.deepEquals( this.fullName, other.fullName ) ) { + return false; + } + return true; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index bd2da2b460..5f07249bf7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -185,7 +185,7 @@ public Builder setDefininingType(Type definingType) { public SourceMethod build() { MappingOptions mappingOptions = - new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings ); + new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings, false ); SourceMethod sourceMethod = new SourceMethod( declaringMapper, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 200355fa0c..1cd4063dce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -248,6 +248,29 @@ public SourceReference build() { } } + /** + * Builds a {@link SourceReference} from a property. + */ + public static class BuilderFromSourceReference { + + private Parameter sourceParameter; + private SourceReference sourceReference; + + public BuilderFromSourceReference sourceReference(SourceReference sourceReference) { + this.sourceReference = sourceReference; + return this; + } + + public BuilderFromSourceReference sourceParameter(Parameter sourceParameter) { + this.sourceParameter = sourceParameter; + return this; + } + + public SourceReference build() { + return new SourceReference( sourceParameter, sourceReference.propertyEntries, true ); + } + } + private SourceReference(Parameter sourceParameter, List sourcePropertyEntries, boolean isValid) { this.parameter = sourceParameter; this.propertyEntries = sourcePropertyEntries; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 8f52179e5b..a6259ea9b1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -202,14 +202,30 @@ public boolean isValid() { } public List getElementNames() { - List elementName = new ArrayList(); + List elementNames = new ArrayList(); if ( parameter != null ) { // only relevant for source properties - elementName.add( parameter.getName() ); + elementNames.add( parameter.getName() ); } for ( PropertyEntry propertyEntry : propertyEntries ) { - elementName.add( propertyEntry.getName() ); + elementNames.add( propertyEntry.getName() ); + } + return elementNames; + } + + public TargetReference pop() { + if ( propertyEntries.size() > 1 ) { + List newPropertyEntries = new ArrayList( propertyEntries.size() - 1 ); + for ( PropertyEntry propertyEntry : propertyEntries ) { + PropertyEntry newPropertyEntry = propertyEntry.pop(); + if ( newPropertyEntry != null ) { + newPropertyEntries.add( newPropertyEntry ); + } + } + return new TargetReference( null, newPropertyEntries, isValid ); + } + else { + return null; } - return elementName; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 9be91a3f95..4ba6e3c3aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -33,6 +33,7 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; @@ -276,4 +277,9 @@ public boolean isLifecycleCallbackMethod() { public boolean isUpdateMethod() { return getMappingTargetParameter() != null; } + + @Override + public MappingOptions getMappingOptions() { + return MappingOptions.empty(); + } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 86c8a6f659..2d9a738f52 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -42,7 +42,6 @@ - <@nestedTargetObjects/> <#if (sourceParameters?size > 1)> <#list sourceParametersExcludingPrimitives as sourceParam> <#if (propertyMappingsByParameter[sourceParam.name]?size > 0)> @@ -88,12 +87,4 @@ <#if exceptionType_has_next>, <#t> - -<#macro nestedTargetObjects> - <#list localVariablesToCreate as localVariable> - <@includeModel object=localVariable/> = <#if localVariable.factoryMethod??><@includeModel object=localVariable.factoryMethod targetType=localVariable.type/><#else>new <@includeModel object=localVariable.type/>(); - - <#list nestedLocalVariableAssignments as nestedLocalVariableAssignment> - <@includeModel object=nestedLocalVariableAssignment/> - \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/LocalVariable.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/LocalVariable.ftl deleted file mode 100644 index 45ed5e1344..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/LocalVariable.ftl +++ /dev/null @@ -1,21 +0,0 @@ -<#-- - - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<@includeModel object=type/> ${name} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.ftl deleted file mode 100644 index d8fd9783b8..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedLocalVariableAssignment.ftl +++ /dev/null @@ -1,22 +0,0 @@ -<#-- - - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ---> -<#import "macro/CommonMacros.ftl" as lib> -${targetBean}.${setterName}<@lib.handleWrite>${sourceRef}; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index 477f7d7a68..a623008778 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -18,20 +18,10 @@ limitations under the License. --> -<#if localTargetVarName??> -<@includeModel object=assignment - targetBeanName=localTargetVarName - existingInstanceMapping=ext.existingInstanceMapping - targetReadAccessorName=targetReadAccessorName - targetWriteAccessorName=targetWriteAccessorName - targetType=targetType - defaultValueAssignment=defaultValueAssignment /> -<#else> <@includeModel object=assignment targetBeanName=ext.targetBeanName existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=targetReadAccessorName targetWriteAccessorName=targetWriteAccessorName targetType=targetType - defaultValueAssignment=defaultValueAssignment /> - + defaultValueAssignment=defaultValueAssignment /> \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java index 7e81a10e96..966deb68ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java @@ -18,8 +18,8 @@ */ package org.mapstruct.ap.test.nestedtargetproperties; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.mapstruct.InheritInverseConfiguration; @@ -65,10 +65,10 @@ public abstract class ChartEntryToArtist { protected List mapPosition(Integer in) { if ( in != null ) { - return Arrays.asList( in ); + return new ArrayList( Arrays.asList( in ) ); } else { - return Collections.emptyList(); + return new ArrayList(); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java new file mode 100644 index 0000000000..3d5859ffb7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java @@ -0,0 +1,70 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; +import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS ) +public abstract class ChartEntryToArtistUpdate { + + public static final ChartEntryToArtistUpdate MAPPER = Mappers.getMapper( ChartEntryToArtistUpdate.class ); + + @Mappings({ + @Mapping(target = "type", ignore = true), + @Mapping(target = "name", source = "chartName"), + @Mapping(target = "song.title", source = "songTitle" ), + @Mapping(target = "song.artist.name", source = "artistName" ), + @Mapping(target = "song.artist.label.studio.name", source = "recordedAt"), + @Mapping(target = "song.artist.label.studio.city", source = "city" ), + @Mapping(target = "song.positions", source = "position" ) + }) + public abstract void map(ChartEntry chartEntry, @MappingTarget Chart chart ); + + protected List mapPosition(Integer in) { + if ( in != null ) { + return Arrays.asList( in ); + } + else { + return Collections.emptyList(); + } + } + + protected Integer mapPosition(List in) { + if ( in != null && !in.isEmpty() ) { + return in.get( 0 ); + } + else { + return null; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java new file mode 100644 index 0000000000..6e434804fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; +import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface FishTankMapper { + + FishTankMapper INSTANCE = Mappers.getMapper( FishTankMapper.class ); + + @Mapping(target = "fish.kind", source = "fish.type") + FishTankDto map( FishTank source ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java index 4f46663503..8d05cc6526 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java @@ -27,6 +27,12 @@ import org.mapstruct.ap.test.nestedsourceproperties.source.Label; import org.mapstruct.ap.test.nestedsourceproperties.source.Song; import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; +import org.mapstruct.ap.test.nestedtargetproperties._target.FishDto; +import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; +import org.mapstruct.ap.test.nestedtargetproperties._target.WaterPlantDto; +import org.mapstruct.ap.test.nestedtargetproperties.source.Fish; +import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; +import org.mapstruct.ap.test.nestedtargetproperties.source.WaterPlant; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @@ -35,13 +41,28 @@ * * @author Sjaak Derksen */ -@WithClasses({Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class}) +@WithClasses({ + Song.class, + Artist.class, + Chart.class, + Label.class, + Studio.class, + ChartEntry.class, + FishDto.class, + FishTankDto.class, + WaterPlantDto.class, + Fish.class, + FishTank.class, + WaterPlant.class, + ChartEntryToArtist.class, + ChartEntryToArtistUpdate.class, + FishTankMapper.class +}) @IssueKey("389") @RunWith(AnnotationProcessorTestRunner.class) public class NestedTargetPropertiesTest { @Test - @WithClasses({ChartEntryToArtist.class}) public void shouldMapNestedTarget() { ChartEntry chartEntry = new ChartEntry(); @@ -71,7 +92,6 @@ public void shouldMapNestedTarget() { } @Test - @WithClasses({ChartEntryToArtist.class}) public void shouldMapNestedComposedTarget() { ChartEntry chartEntry1 = new ChartEntry(); @@ -103,7 +123,6 @@ public void shouldMapNestedComposedTarget() { } @Test - @WithClasses({ChartEntryToArtist.class}) public void shouldReverseNestedTarget() { ChartEntry chartEntry = new ChartEntry(); @@ -125,4 +144,64 @@ public void shouldReverseNestedTarget() { assertThat( result.getRecordedAt() ).isEqualTo( "Live, First Avenue, Minneapolis" ); assertThat( result.getSongTitle() ).isEqualTo( "Purple Rain" ); } + + @Test + public void shouldMapNestedTargetWitUpdate() { + + ChartEntry chartEntry = new ChartEntry(); + chartEntry.setArtistName( "Prince" ); + chartEntry.setChartName( "US Billboard Hot Rock Songs" ); + chartEntry.setCity( "Minneapolis" ); + chartEntry.setPosition( 1 ); + chartEntry.setRecordedAt( "Live, First Avenue, Minneapolis" ); + chartEntry.setSongTitle( null ); + + Chart result = new Chart(); + result.setSong( new Song() ); + result.getSong().setTitle( "Raspberry Beret" ); + + ChartEntryToArtistUpdate.MAPPER.map( chartEntry, result ); + + assertThat( result.getName() ).isEqualTo( "US Billboard Hot Rock Songs" ); + assertThat( result.getSong() ).isNotNull(); + assertThat( result.getSong().getArtist() ).isNotNull(); + assertThat( result.getSong().getTitle() ).isEqualTo( "Raspberry Beret" ); + assertThat( result.getSong().getArtist().getName() ).isEqualTo( "Prince" ); + assertThat( result.getSong().getArtist().getLabel() ).isNotNull(); + assertThat( result.getSong().getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( result.getSong().getArtist().getLabel().getStudio().getName() ) + .isEqualTo( "Live, First Avenue, Minneapolis" ); + assertThat( result.getSong().getArtist().getLabel().getStudio().getCity() ) + .isEqualTo( "Minneapolis" ); + assertThat( result.getSong().getPositions() ).hasSize( 1 ); + assertThat( result.getSong().getPositions().get( 0 ) ).isEqualTo( 1 ); + + } + + @Test + public void automappingAndTargetNestingDemonstrator() { + + FishTank source = new FishTank(); + source.setName( "MyLittleFishTank" ); + Fish fish = new Fish(); + fish.setType( "Carp" ); + WaterPlant waterplant = new WaterPlant(); + waterplant.setKind( "Water Hyacinth" ); + source.setFish( fish ); + source.setPlant( waterplant ); + + FishTankDto target = FishTankMapper.INSTANCE.map( source ); + + // the nested property generates a method fishTankToFishDto(FishTank fishTank, FishDto mappingTarget) + // when name based mapping continues MapStruct searches for a property called `name` in fishTank (type + // 'FishTank'. If it is there, it should most cerntainly not be mapped to a mappingTarget of type 'FishDto' + assertThat( target.getFish() ).isNotNull(); + assertThat( target.getFish().getKind() ).isEqualTo( "Carp" ); + assertThat( target.getFish().getName() ).isNull(); + + // automapping takes care of mapping property "waterPlant". + assertThat( target.getPlant() ).isNotNull(); + assertThat( target.getPlant().getKind() ).isEqualTo( "Water Hyacinth" ); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java new file mode 100644 index 0000000000..c4dee02692 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties._target; + +/** + * + * @author Sjaak Derksen + */ +public class FishDto { + + private String kind; + + // make sure that mapping on name does not happen based on name mapping + private String name; + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java new file mode 100644 index 0000000000..081b567bba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties._target; + +/** + * + * @author Sjaak Derksen + */ +public class FishTankDto { + + private FishDto fish; + private WaterPlantDto plant; + + public FishDto getFish() { + return fish; + } + + public void setFish(FishDto fish) { + this.fish = fish; + } + + public WaterPlantDto getPlant() { + return plant; + } + + public void setPlant(WaterPlantDto plant) { + this.plant = plant; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java new file mode 100644 index 0000000000..1118fd7fa3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties._target; + +/** + * + * @author Sjaak Derksen + */ +public class WaterPlantDto { + + private String kind; + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java new file mode 100644 index 0000000000..97b29c6e70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties.source; + +/** + * + * @author Sjaak Derksen + */ +public class Fish { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java new file mode 100644 index 0000000000..d250898c41 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties.source; + +/** + * + * @author Sjaak Derksen + */ +public class FishTank { + + private Fish fish; + private WaterPlant plant; + private String name; + + public Fish getFish() { + return fish; + } + + public void setFish(Fish fish) { + this.fish = fish; + } + + public WaterPlant getPlant() { + return plant; + } + + public void setPlant(WaterPlant plant) { + this.plant = plant; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java new file mode 100644 index 0000000000..138686c9cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties.source; + +/** + * + * @author Sjaak Derksen + */ +public class WaterPlant { + + private String kind; + + public String getKind() { + return kind; + } + + public void setKind(String kind) { + this.kind = kind; + } + +} From ac039991706af914e38c84568abc9b3acb019939 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 2 Feb 2017 21:57:03 +0100 Subject: [PATCH 0041/1006] #975 Allow calling BeforeMapping/AfterMapping methods directly on @Context params --- .../main/java/org/mapstruct/BeanMapping.java | 16 +-- .../src/main/java/org/mapstruct/Context.java | 83 +++++++++++-- .../java/org/mapstruct/ObjectFactory.java | 53 ++++----- .../main/java/org/mapstruct/Qualifier.java | 4 +- .../mapstruct-reference-guide.asciidoc | 95 +++++++++++---- .../internal/model/AbstractBaseBuilder.java | 6 +- .../model/AbstractMappingMethodBuilder.java | 1 + .../model/ContainerMappingMethodBuilder.java | 5 +- .../ap/internal/model/HelperMethod.java | 6 + .../internal/model/IterableMappingMethod.java | 1 + .../model/LifecycleCallbackFactory.java | 52 ++++++-- .../LifecycleCallbackMethodReference.java | 48 ++++++-- .../ap/internal/model/MethodReference.java | 69 ++++++++--- .../ap/internal/model/PropertyMapping.java | 26 ++-- .../internal/model/source/ForgedMethod.java | 70 +++++++++-- .../ap/internal/model/source/Method.java | 5 + .../source/ParameterProvidedMethods.java | 111 ++++++++++++++++++ .../internal/model/source/SourceMethod.java | 55 +++++---- .../model/source/builtin/BuiltInMethod.java | 6 + .../processor/MethodRetrievalProcessor.java | 91 +++++++++----- .../creation/MappingResolverImpl.java | 9 +- .../ap/internal/model/MethodReference.ftl | 10 +- .../AutomappingNodeMapperWithContext.java | 2 +- ...ngNodeMapperWithSelfContainingContext.java | 40 +++++++ .../ap/test/context/ContextParameterTest.java | 26 +++- .../context/CycleContextLifecycleMethods.java | 12 -- .../ap/test/context/FactoryContext.java | 4 +- .../test/context/FactoryContextMethods.java | 39 ++++++ .../test/context/NodeMapperWithContext.java | 2 +- .../context/SelfContainingCycleContext.java | 47 ++++++++ 30 files changed, 774 insertions(+), 220 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index a1e5003e79..50df1ae392 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -27,7 +27,7 @@ /** * Configures the mapping between two bean types. *

    - * Either {@link #resultType()} , {@link #qualifiedBy()} or {@link #nullValueMappingStrategy()} must be specified. + * Either {@link #resultType()}, {@link #qualifiedBy()} or {@link #nullValueMappingStrategy()} must be specified. *

    * * @author Sjaak Derksen @@ -44,21 +44,23 @@ Class resultType() default void.class; /** - * A qualifier can be specified to aid the selection process of a suitable factory method. This is useful in case - * multiple factory method (hand written of internal) qualify and result in an 'Ambiguous factory methods' error. - * + * A qualifier can be specified to aid the selection process of a suitable factory method or filtering applicable + * {@code @}{@link BeforeMapping} / {@code @}{@link AfterMapping} methods. This is useful in case multiple factory + * method (hand written of internal) qualify and result in an 'Ambiguous factory methods' error. + *

    * A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method. * * @return the qualifiers + * @see BeanMapping#qualifiedByName() */ Class[] qualifiedBy() default { }; /** - * See: { @link #qualifiedBy() }. String form of a predefined { @link @Qualifier }. The { @link @Qualifier } - * is more verbose, but offers more flexibility in terms of for instance refactoring. At the other hand, there - * is no need to define own annotations. + * Similar to {@link #qualifiedBy()}, but used in combination with {@code @}{@link Named} in case no custom + * qualifier annotation is defined. * * @return the qualifiers + * @see Named */ String[] qualifiedByName() default { }; diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core-common/src/main/java/org/mapstruct/Context.java index 83ace22ac8..7432e66ad1 100644 --- a/core-common/src/main/java/org/mapstruct/Context.java +++ b/core-common/src/main/java/org/mapstruct/Context.java @@ -25,14 +25,22 @@ /** * Marks a parameter of a method to be treated as mapping context. Such parameters are passed to other mapping - * methods, {@link ObjectFactory} methods or {@link BeforeMapping}/{@link AfterMapping} methods when applicable and can - * thus be used in custom code. The {@link Context} parameters are otherwise ignored by MapStruct. + * methods, {@code @}{@link ObjectFactory} methods or {@code @}{@link BeforeMapping}/{@code @}{@link AfterMapping} + * methods when applicable and can thus be used in custom code. *

    - * For generated code to call a method that is declared with {@link Context} parameters, the declaration of the mapping - * method being generated needs to contain at least those (or assignable) {@link Context} parameters as well. MapStruct - * will not create new instances of missing {@link Context} parameters nor will it pass {@code null} instead. + * The type of an {@code @Context} parameter is also inspected for + * {@code @}{@link BeforeMapping}/{@code @}{@link AfterMapping} methods, which are called on the provided context + * parameter value if applicable. *

    - * Example: + * Note: no {@code null} checks are performed before calling before/after mapping methods on context + * parameters. The caller needs to make sure that no {@code null} are passed in that case. + *

    + * For generated code to call a method that is declared with {@code @Context} parameters, the declaration of the mapping + * method being generated needs to contain at least those (or assignable) {@code @Context} parameters as well. MapStruct + * will not create new instances of missing {@code @Context} parameters nor will it pass {@code null} instead. + *

    + * Example 1: Using {@code @Context} parameters for passing data down to hand-written property mapping + * methods and {@code @}{@link BeforeMapping} methods: * *

      * 
    @@ -49,13 +57,8 @@
      * }
      *
      * @BeforeMapping
    - * protected void logMappedVehicle(Vehicle mappedVehicle) {
    - *     // do something with the vehicle
    - * }
    - *
    - * @BeforeMapping
      * protected void notCalled(Vehicle mappedVehicle, @Context DifferentMappingContextType context) {
    - *     // not called, because DifferentMappingContextType is not available
    + *     // not called, because no context parameter of type DifferentMappingContextType is available
      *     // within toCar(Car, VehicleRegistration, Locale)
      * }
      *
    @@ -63,7 +66,6 @@
      *
      * public CarDto toCar(Car car, VehicleRegistration context, Locale localeToUse) {
      *     registerVehicle( car, context );
    - *     logMappedVehicle( car );
      *
      *     if ( car == null ) {
      *         return null;
    @@ -78,6 +80,61 @@
      * }
      * 
      * 
    + *

    + * Example 2: Using an {@code @Context} parameter with a type that provides its own {@code @} + * {@link BeforeMapping} methods to handle cycles in Graph structures: + * + *

    + * 
    + * // type of the context parameter
    + * public class CyclicGraphContext {
    + *     private Map<Object, Object> knownInstances = new IdentityHashMap<>();
    + *
    + *     @BeforeMapping
    + *     public <T extends NodeDto> T getMappedInstance(Object source, @TargetType Class<T> targetType) {
    + *         return (T) knownInstances.get( source );
    + *     }
    + *
    + *     @BeforeMapping
    + *     public void storeMappedInstance(Object source, @MappingTarget NodeDto target) {
    + *         knownInstances.put( source, target );
    + *     }
    + * }
    + *
    + * @Mapper
    + * public interface GraphMapper {
    + *     NodeDto toNodeDto(Node node, @Context CyclicGraphContext cycleContext);
    + * }
    + *
    + *
    + * // generates:
    + *
    + * public NodeDto toNodeDto(Node node, CyclicGraphContext cycleContext) {
    + *     NodeDto target = cycleContext.getMappedInstance( node, NodeDto.class );
    + *     if ( target != null ) {
    + *         return target;
    + *     }
    + *
    + *     if ( node == null ) {
    + *         return null;
    + *     }
    + *
    + *     NodeDto nodeDto = new NodeDto();
    + *
    + *     cycleContext.storeMappedInstance( node, nodeDto );
    + *
    + *     nodeDto.setParent( toNodeDto( node.getParent(), cycleContext ) );
    + *     List<NodeDto> list = nodeListToNodeDtoList( node.getChildren(), cycleContext );
    + *     if ( list != null ) {
    + *         nodeDto.setChildren( list );
    + *     }
    + *
    + *     // more mapping code
    + *
    + *     return nodeDto;
    + * }
    + * 
    + * 
    * * @author Andreas Gudian * @since 1.2 diff --git a/core-common/src/main/java/org/mapstruct/ObjectFactory.java b/core-common/src/main/java/org/mapstruct/ObjectFactory.java index e798f7dbe1..13f7f246cc 100644 --- a/core-common/src/main/java/org/mapstruct/ObjectFactory.java +++ b/core-common/src/main/java/org/mapstruct/ObjectFactory.java @@ -24,44 +24,43 @@ import java.lang.annotation.Target; /** - * By default beans are created during the mapping process with the default constructor. - * This method allows to mark a method as a factory method to create beans. - * The type of the factory method is determined by its return type. A factory is used - * to create a bean if their types match. + * This annotation marks a method as a factory method to create beans. *

    - * The factory method can retrieve the mapping sources by specifying - * them as parameters, exactly like mapping and lifecycle methods do. This allows the factory - * method to create target beans based on source beans. - * The use of source parameters opens up a variety of possibilities. For example, - * a factory method for entities can look up an - * EntityManager to check whether the entity already exists and then return its - * managed instance. + * By default beans are created during the mapping process with the default constructor. If a factory method with a + * return type that is assignable to the required object type is present, then the factory method is used instead. + *

    + * Factory methods can be defined without parameters, with an {@code @}{@link TargetType} parameter, a {@code @} + * {@link Context} parameter, or with a mapping methods source parameter. If any of those parameters are defined, then + * the mapping method that is supposed to use the factory method needs to be declared with an assignable result type, + * assignable context parameter, and/or assignable source types. + *

    + * Note: the usage of this annotation is optional if no source parameters are part of the + * signature, i.e. it is declared without parameters or only with {@code @}{@link TargetType} and/or {@code @} + * {@link Context}. + *

    + * Example: Using a factory method for entities to check whether the entity already exists in the + * EntityManager and then returns the managed instance: * *

    - * {@literal @}ApplicationScoped // CDI component model
    + * 
    + * @ApplicationScoped // CDI component model
      * public class ReferenceMapper {
      *
    - *     {@literal @}PersistenceContext
    + *     @PersistenceContext
      *     private EntityManager em;
      *
    - *     {@literal @}ObjectFactory
    - *     public SomeEntity resolve(SomeDto dto) {
    - *         SomeEntity entity = em.find(SomeEntity.class, dto.getId());
    - *         return entity != null ? entity : new SomeEntity();
    + *     @ObjectFactory
    + *     public <T extends AbstractEntity> T resolve(AbstractDto sourceDto, @TargetType Class<T> type) {
    + *         T entity = em.find( type, sourceDto.getId() );
    + *         return entity != null ? entity : type.newInstance();
      *     }
      * }
    + * 
      * 
    - * - * If no such parameters - * are provided, the use of this annotation is optional. - * *

    - * If there are two factory methods, both serving the same type, one with no parameters - * and one taking sources as input, then the one with the source parameters is favored. - * If multiple factory method take sources as input, them the one is chosen which allows a - * valid assignment from mapping source parameters to those factory parameters. If - * there are multiple such factories, an ambiguity exception is thrown. - *

    + * If there are two factory methods, both serving the same type, one with no parameters and one taking sources as input, + * then the one with the source parameters is favored. If there are multiple such factories, an ambiguity error is + * shown. * * @author Remo Meier * @since 1.2 diff --git a/core-common/src/main/java/org/mapstruct/Qualifier.java b/core-common/src/main/java/org/mapstruct/Qualifier.java index 0004275d68..0581da2da4 100644 --- a/core-common/src/main/java/org/mapstruct/Qualifier.java +++ b/core-common/src/main/java/org/mapstruct/Qualifier.java @@ -30,6 +30,7 @@ * For more info see: *
      *
    • {@link Mapping#qualifiedBy() }
    • + *
    • {@link BeanMapping#qualifiedBy() }
    • *
    • {@link IterableMapping#qualifiedBy() }
    • *
    • {@link MapMapping#keyQualifiedBy() }
    • *
    • {@link MapMapping#valueQualifiedBy() }
    • @@ -44,9 +45,10 @@ * } * * - * NOTE: Qualifiers should have {@link RetentionPolicy#CLASS}. + * NOTE: Qualifiers should have {@link RetentionPolicy#CLASS}. * * @author Sjaak Derksen + * @see Named */ @Target(ElementType.ANNOTATION_TYPE) @Retention(RetentionPolicy.CLASS) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 5a3560e306..d1e0d9174d 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -924,6 +924,54 @@ public class CarMapperImpl implements CarMapper { ---- ==== +[[passing-context]] +=== Passing context or state objects to custom methods + +Additional _context_ or _state_ information can be passed through generated mapping methods to custom methods with `@Context` parameters. Such parameters are passed to other mapping methods, `@ObjectFactory` methods (see <>) or `@BeforeMapping` / `@AfterMapping` methods (see <>) when applicable and can thus be used in custom code. + +`@Context` parameters are also searched for `@BeforeMapping` / `@AfterMapping` methods, which are called on the provided context parameter value if applicable. + +*Note:* no `null` checks are performed before calling before/after mapping methods on context parameters. The caller needs to make sure that `null` is not passed in that case. + +For generated code to call a method that is declared with `@Context` parameters, the declaration of the mapping method being generated needs to contain at least those (or assignable) `@Context` parameters as well. The generated code will not create new instances of missing `@Context` parameters nor will it pass a literal `null` instead. + +.Using `@Context` parameters for passing data down to hand-written property mapping methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public abstract CarDto toCar(Car car, @Context Locale translationLocale); + +protected OwnerManualDto translateOwnerManual(OwnerManual ownerManual, @Context Locale locale) { + // manually implemented logic to translate the OwnerManual with the given Locale +} +---- +==== + +MapStruct will then generate something like this: + +.Generated code +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +public CarDto toCar(Car car, Locale translationLocale) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + carDto.setOwnerManual( translateOwnerManual( car.getOwnerManual(), translationLocale ); + // more generated mapping code + + return carDto; +} +---- +==== + + [[mapping-method-resolution]] === Mapping method resolution @@ -1492,8 +1540,7 @@ By default, the generated code for mapping one bean type into another will call Alternatively you can plug in custom object factories which will be invoked to obtain instances of the target type. One use case for this is JAXB which creates `ObjectFactory` classes for obtaining new instances of schema types. -To make use of custom factories register them via `@Mapper#uses()` as described in <>. When creating the target object of a bean mapping, MapStruct will look for a parameterless method, -a method annotated with `@ObjectFactory`, or a method with only one `@TargetType` parameter that returns the required target type and invoke this method instead of calling the default constructor: +To make use of custom factories register them via `@Mapper#uses()` as described in <>, or implement them directly in your mapper. When creating the target object of a bean mapping, MapStruct will look for a parameterless method, a method annotated with `@ObjectFactory`, or a method with only one `@TargetType` parameter that returns the required target type and invoke this method instead of calling the default constructor: .Custom object factories ==== @@ -1569,9 +1616,9 @@ public class CarMapperImpl implements CarMapper { ---- ==== -In addition, annotating a factory with `@ObjectFactory` lets you gain access to the mapping sources. +In addition, annotating a factory method with `@ObjectFactory` lets you gain access to the mapping sources. Source objects can be added as parameters in the same way as for mapping method. The `@ObjectFactory` -annotation is necessary to let MapStruct know that the given method is only a factory method. +annotation is necessary to let MapStruct know that the given method is only a factory method. .Custom object factories with `@ObjectFactory` @@ -1583,7 +1630,7 @@ public class DtoFactory { @ObjectFactory public CarDto createCarDto(Car car) { - return // ... custom factory logic + return // ... custom factory logic } } ---- @@ -1908,7 +1955,7 @@ Methods that are considered for inverse inheritance need to be defined in the cu If multiple methods qualify, the method from which to inherit the configuration needs to be specified using the `name` property like this: `@InheritInverseConfiguration(name = "carToDto")`. -Expressions and constants are excluded (silently ignored). Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. +Expressions and constants are excluded (silently ignored). Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. [NOTE] ==== @@ -2142,7 +2189,7 @@ private PersonMapper personMapper; // injects the decorator, with the injected o Decorators may not always fit the needs when it comes to customizing mappers. For example, if you need to perform the customization not only for a few selected methods, but for all methods that map specific super-types: in that case, you can use *callback methods* that are invoked before the mapping starts or after the mapping finished. -Callback methods can be implemented in the abstract mapper itself or in a type reference in `Mapper#uses`. +Callback methods can be implemented in the abstract mapper itself, in a type reference in `Mapper#uses`, or in a type used as `@Context` parameter. .Mapper with @BeforeMapping and @AfterMapping hooks ==== @@ -2187,16 +2234,14 @@ public class VehicleMapperImpl extends VehicleMapper { ---- ==== -If the `@BeforeMapping` / `@AfterMapping` method has parameters, the method invocation is only generated if all parameters can be *assigned* by the source or target parameters of the mapping method: +If the `@BeforeMapping` / `@AfterMapping` method has parameters, the method invocation is only generated if the return type of the method (if non-`void`) is assignable to the return type of the mapping method and all parameters can be *assigned* by the source or target parameters of the mapping method: * A parameter annotated with `@MappingTarget` is populated with the target instance of the mapping. * A parameter annotated with `@TargetType` is populated with the target type of the mapping. -* Any other parameter is populated with a source parameter of the mapping, whereas each source parameter is used once at most. +* Parameters annotated with `@Context` are populated with the context parameters of the mapping method. +* Any other parameter is populated with a source parameter of the mapping. -If the before/after-mapping method has a return type other than `void`, it will be checked to match the target type of the mapping methods. -Only the callback methods with a matching return type (or `void`) will be called in that mapping method. - -If a callback method returns a non-null value, this value will be returned from the mapping method. +For non-`void` methods, the return value of the method invocation is returned as the result of the mapping method if it is not `null`. As with mapping methods, it is possible to specify type parameters for before/after-mapping methods. @@ -2243,17 +2288,23 @@ public class VehicleMapperImpl extends VehicleMapper { All before/after-mapping methods that *can* be applied to a mapping method *will* be used. <> can be used to further control which methods may be chosen and which not. For that, the qualifier annotation needs to be applied to the before/after-method and referenced in `BeanMapping#qualifiedBy` or `IterableMapping#qualifiedBy`. -The order in which the selected methods are applied is roughly determined by their location of definition (although you should consider it a *code smell* if you need to rely on their order): +The order of the method invocation is determined primarily by their variant: + +1. `@BeforeMapping` methods without an `@MappingTarget` parameter are called before any null-checks on source + parameters and constructing a new target bean. +2. `@BeforeMapping` methods with an `@MappingTarget` parameter are called after constructing a new target bean. +3. `@AfterMapping` methods are called at the end of the mapping method before the last `return` statement. + +Within those groups, the method invocations are ordered by their location of definition: + +1. Methods declared on `@Context` parameters, ordered by the parameter order. +2. Methods implemented in the mapper itself. +3. Methods from types referenced in `Mapper#uses()`, in the order of the type declaration in the annotation. +4. Methods declared in one type are used after methods declared in their super-type. + +*Important:* the order of methods declared within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. -* The order of methods within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. -* Methods declared in one type are used after methods declared in their super-type. -* Methods implemented in the mapper itself are used before methods from types referenced in `Mapper#uses`. -* Types referenced in `Mapper#uses` are searched for before/after-mapping methods in the order specified in the annotation. -[WARNING] -==== -`@BeforeMapping` and `@AfterMapping` are considered experimental as of the 1.0.0.CR1 release. Details in the selection of before/after mapping methods that are applicable for a mapping method or the order in which they are called might still be changed. -==== [[using-spi]] == Using the MapStruct SPI === Custom Accessor Naming Strategy diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 6a87431b95..cb809924bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -76,11 +76,9 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp methodRef = new ForgedMethod( existingName, methodRef ); } - Assignment assignment = new MethodReference( + Assignment assignment = MethodReference.forForgedMethod( methodRef, - null, - ParameterBinding.fromParameters( methodRef.getParameters() ) - ); + ParameterBinding.fromParameters( methodRef.getParameters() ) ); assignment.setAssignment( source ); return assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 25e8de0f43..cf1735b7b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -59,6 +59,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { method.getMapperConfiguration(), method.getExecutable(), method.getContextParameters(), + method.getContextProvidedMethods(), new ForgedMethodHistory( history, Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 81c791a3cc..009f507cd7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.HashSet; import java.util.List; import java.util.Set; @@ -31,8 +33,6 @@ import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Strings; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * Builder that can be used to build {@link ContainerMappingMethod}(s). * @@ -75,6 +75,7 @@ public B callingContextTargetPropertyName(String callingContextTargetPropertyNam return myself; } + @Override public final M build() { Type sourceParameterType = first( method.getSourceParameters() ).getType(); Type resultType = method.getResultType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 91dc55ba89..8121f7def7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; @@ -89,6 +90,11 @@ public List getContextParameters() { return Collections.emptyList(); } + @Override + public ParameterProvidedMethods getContextProvidedMethods() { + return ParameterProvidedMethods.empty(); + } + /** * {@inheritDoc} *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 44f743c492..1f264afd31 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -107,6 +107,7 @@ public Type getSourceElementType() { } } + @Override public Type getResultElementType() { if ( getResultType().isArrayType() ) { return getResultType().getComponentType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java index ec1d5a40e9..b5f31160ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java @@ -23,12 +23,14 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; /** @@ -55,7 +57,7 @@ public static List beforeMappingMethods(Method return collectLifecycleCallbackMethods( method, selectionParameters, - filterBeforeMappingMethods( ctx.getSourceModel() ), + filterBeforeMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, existingVariableNames ); } @@ -74,11 +76,29 @@ public static List afterMappingMethods(Method return collectLifecycleCallbackMethods( method, selectionParameters, - filterAfterMappingMethods( ctx.getSourceModel() ), + filterAfterMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, existingVariableNames ); } + private static List getAllAvailableMethods(Method method, List sourceModelMethods) { + ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods(); + if ( contextProvidedMethods.isEmpty() ) { + return sourceModelMethods; + } + + List methodsProvidedByParams = contextProvidedMethods + .getAllProvidedMethodsInParameterOrder( method.getContextParameters() ); + + List availableMethods = + new ArrayList( methodsProvidedByParams.size() + sourceModelMethods.size() ); + + availableMethods.addAll( methodsProvidedByParams ); + availableMethods.addAll( sourceModelMethods ); + + return availableMethods; + } + private static List collectLifecycleCallbackMethods( Method method, SelectionParameters selectionParameters, List callbackMethods, MappingBuilderContext ctx, Set existingVariableNames) { @@ -107,15 +127,27 @@ private static List toLifecycleCallbackMethodR List result = new ArrayList(); for ( SelectedMethod candidate : candidates ) { - MapperReference mapperReference = findMapperReference( ctx.getMapperReferences(), candidate.getMethod() ); - result.add( - new LifecycleCallbackMethodReference( - candidate.getMethod(), + Parameter providingParameter = + method.getContextProvidedMethods().getParameterForProvidedMethod( candidate.getMethod() ); + + if ( providingParameter != null ) { + result.add( LifecycleCallbackMethodReference.forParameterProvidedMethod( + candidate, + providingParameter, + method, + existingVariableNames ) ); + } + else { + MapperReference mapperReference = findMapperReference( + ctx.getMapperReferences(), + candidate.getMethod() ); + + result.add( LifecycleCallbackMethodReference.forMethodReference( + candidate, mapperReference, - candidate.getParameterBindings(), - method.getReturnType(), - method.getResultType(), + method, existingVariableNames ) ); + } } return result; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java index f8edfbf287..252655e741 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java @@ -18,13 +18,14 @@ */ package org.mapstruct.ap.internal.model; -import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.Strings; @@ -40,14 +41,18 @@ public class LifecycleCallbackMethodReference extends MethodReference { private final Type methodResultType; private final String targetVariableName; - public LifecycleCallbackMethodReference(SourceMethod method, MapperReference mapperReference, - List parameterBindings, - Type methodReturnType, Type methodResultType, - Set existingVariableNames) { - super( method, mapperReference, parameterBindings ); - this.declaringType = method.getDeclaringMapper(); - this.methodReturnType = methodReturnType; - this.methodResultType = methodResultType; + private LifecycleCallbackMethodReference(SelectedMethod lifecycleMethod, + MapperReference mapperReference, Parameter providingParameter, + Method containingMethod, Set existingVariableNames) { + super( + lifecycleMethod.getMethod(), + mapperReference, + providingParameter, + lifecycleMethod.getParameterBindings() ); + + this.declaringType = lifecycleMethod.getMethod().getDeclaringMapper(); + this.methodReturnType = containingMethod.getReturnType(); + this.methodResultType = containingMethod.getResultType(); if ( hasReturnType() ) { this.targetVariableName = Strings.getSaveVariableName( "target", existingVariableNames ); @@ -107,4 +112,29 @@ public boolean hasMappingTargetParameter() { public boolean hasReturnType() { return !getReturnType().isVoid(); } + + public static LifecycleCallbackMethodReference forParameterProvidedMethod( + SelectedMethod lifecycleMethod, + Parameter providingParameter, Method containingMethod, + Set existingVariableNames) { + + return new LifecycleCallbackMethodReference( + lifecycleMethod, + null, + providingParameter, + containingMethod, + existingVariableNames ); + } + + public static LifecycleCallbackMethodReference forMethodReference(SelectedMethod lifecycleMethod, + MapperReference mapperReference, Method containingMethod, + Set existingVariableNames) { + + return new LifecycleCallbackMethodReference( + lifecycleMethod, + mapperReference, + null, + containingMethod, + existingVariableNames ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index d28fd5ed63..aee3fd30f3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -39,7 +39,6 @@ * @author Gunnar Morling */ public class MethodReference extends MappingMethod implements Assignment { - private final MapperReference declaringMapper; private final Set importTypes; private final List thrownTypes; @@ -52,29 +51,32 @@ public class MethodReference extends MappingMethod implements Assignment { */ private final String contextParam; - /** * A reference to another mapping method or typeConversion in case this is a two-step mapping, e.g. from * {@code JAXBElement} to {@code Foo} to for which a nested method call will be generated: - * {@code setFoo(barToFoo( jaxbElemToValue( bar) ) )} - * - * If there's no nested typeConversion or other mapping method, this will be a {@link Direct} assignment. + * {@code setFoo(barToFoo( jaxbElemToValue( bar) ) )}. If there's no nested typeConversion or other mapping method, + * this will be a direct assignment. */ private Assignment assignment; private final Type definingType; private final List parameterBindings; + private final Parameter providingParameter; /** * Creates a new reference to the given method. * * @param method the target method of the reference * @param declaringMapper the method declaring the mapper; {@code null} if the current mapper itself + * @param providingParameter The parameter providing the mapper, or {@code null} if the method is defined by the + * mapper itself or by {@code declaringMapper}. * @param parameterBindings the parameter bindings of this method reference */ - public MethodReference(Method method, MapperReference declaringMapper, List parameterBindings) { + protected MethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, + List parameterBindings) { super( method ); this.declaringMapper = declaringMapper; + this.providingParameter = providingParameter; this.parameterBindings = parameterBindings; this.contextParam = null; Set imported = new HashSet(); @@ -93,9 +95,10 @@ public MethodReference(Method method, MapperReference declaringMapper, List getParameterBindings() { @Override public int hashCode() { - int hash = 7; - hash = 19 * hash + (this.declaringMapper != null ? this.declaringMapper.hashCode() : 0); - return hash; + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ( ( declaringMapper == null ) ? 0 : declaringMapper.hashCode() ); + result = prime * result + ( ( providingParameter == null ) ? 0 : providingParameter.hashCode() ); + return result; } @Override @@ -239,17 +248,47 @@ public boolean equals(Object obj) { if ( this == obj ) { return true; } - if ( obj == null ) { + if ( !super.equals( obj ) ) { return false; } if ( getClass() != obj.getClass() ) { return false; } - final MethodReference other = (MethodReference) obj; - if ( this.declaringMapper != other.declaringMapper && (this.declaringMapper == null - || !this.declaringMapper.equals( other.declaringMapper )) ) { + MethodReference other = (MethodReference) obj; + if ( declaringMapper == null ) { + if ( other.declaringMapper != null ) { + return false; + } + } + else if ( !declaringMapper.equals( other.declaringMapper ) ) { return false; } - return super.equals( obj ); + if ( providingParameter == null ) { + if ( other.providingParameter != null ) { + return false; + } + } + else if ( !providingParameter.equals( other.providingParameter ) ) { + return false; + } + return true; + } + + public static MethodReference forBuiltInMethod(BuiltInMethod method, ConversionContext contextParam) { + return new MethodReference( method, contextParam ); + } + + public static MethodReference forForgedMethod(Method method, List parameterBindings) { + return new MethodReference( method, null, null, parameterBindings ); + } + + public static MethodReference forParameterProvidedMethod(Method method, Parameter providingParameter, + List parameterBindings) { + return new MethodReference( method, null, providingParameter, parameterBindings ); + } + + public static MethodReference forMapperReference(Method method, MapperReference declaringMapper, + List parameterBindings) { + return new MethodReference( method, declaringMapper, null, parameterBindings ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 3f1435395b..b6308e28d3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -18,11 +18,17 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; + import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; @@ -53,11 +59,6 @@ import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; - /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to * {@code int Target#bar}. Name and type of source and target property can differ. If they have different types, the @@ -105,7 +106,6 @@ private static class MappingBuilderBase> extends protected TargetWriteAccessorType targetWriteAccessorType; protected Type targetType; protected Accessor targetReadAccessor; - protected TargetWriteAccessorType targetReadAccessorType; protected String targetPropertyName; protected List dependsOn; @@ -124,17 +124,11 @@ public T targetProperty(PropertyEntry targetProp) { this.targetWriteAccessor = targetProp.getWriteAccessor(); this.targetType = targetProp.getType(); this.targetWriteAccessorType = TargetWriteAccessorType.of( targetWriteAccessor ); - if ( targetReadAccessor != null ) { - this.targetReadAccessorType = TargetWriteAccessorType.of( targetReadAccessor ); - } return (T) this; } public T targetReadAccessor(Accessor targetReadAccessor) { this.targetReadAccessor = targetReadAccessor; - if ( targetReadAccessor != null ) { - this.targetReadAccessorType = TargetWriteAccessorType.of( targetReadAccessor ); - } return (T) this; } @@ -487,7 +481,8 @@ else if ( propertyEntries.size() == 1 ) { sourceType, config, method.getExecutable(), - method.getContextParameters() ); + method.getContextParameters(), + method.getContextProvidedMethods() ); NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder(); NestedPropertyMappingMethod nestedPropertyMapping = builder @@ -578,6 +573,7 @@ private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, Sourc config, element, method.getContextParameters(), + method.getContextProvidedMethods(), getForgedMethodHistory( source, suffix ) ); } @@ -608,7 +604,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { String name = getName( sourceType, targetType ); name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); - List parameters = new ArrayList( method.getContextParameters() ); + List parameters = new ArrayList( method.getContextParameters() ); Type returnType; // there's only one case for forging a method with mapping options: nested target properties. // they should always forge an update method @@ -628,6 +624,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { method.getMapperConfiguration(), method.getExecutable(), parameters, + method.getContextProvidedMethods(), forgeMethodWithMappingOptions ); } @@ -639,6 +636,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { method.getMapperConfiguration(), method.getExecutable(), parameters, + method.getContextProvidedMethods(), getForgedMethodHistory( sourceRHS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index f555cfa464..2a890b802a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -49,7 +49,8 @@ public class ForgedMethod implements Method { private final List contextParameters; private final Parameter mappingTargetParameter; private final MappingOptions mappingOptions; - private boolean autoMapping; + private final boolean autoMapping; + private final ParameterProvidedMethods contextProvidedMethods; /** * Creates a new forged method with the given name. @@ -60,11 +61,23 @@ public class ForgedMethod implements Method { * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method + * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context + * parameters */ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters) { - this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null, - false, MappingOptions.empty() ); + ExecutableElement positionHintElement, List additionalParameters, + ParameterProvidedMethods parameterProvidedMethods) { + this( + name, + sourceType, + returnType, + mapperConfiguration, + positionHintElement, + additionalParameters, + parameterProvidedMethods, + null, + false, + MappingOptions.empty() ); } /** @@ -76,12 +89,24 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method + * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context + * parameters * @param history a parent forged method if this is a forged method within a forged method */ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, ForgedMethodHistory history) { - this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, history, - true, MappingOptions.empty() ); + ExecutableElement positionHintElement, List additionalParameters, + ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history) { + this( + name, + sourceType, + returnType, + mapperConfiguration, + positionHintElement, + additionalParameters, + parameterProvidedMethods, + history, + true, + MappingOptions.empty() ); } /** @@ -93,13 +118,24 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method + * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context + * parameters * @param mappingOptions with mapping options */ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - MappingOptions mappingOptions) { - this( name, sourceType, returnType, mapperConfiguration, positionHintElement, additionalParameters, null, - false, mappingOptions ); + ExecutableElement positionHintElement, List additionalParameters, + ParameterProvidedMethods parameterProvidedMethods, MappingOptions mappingOptions) { + this( + name, + sourceType, + returnType, + mapperConfiguration, + positionHintElement, + additionalParameters, + parameterProvidedMethods, + null, + false, + mappingOptions ); } /** @@ -111,12 +147,15 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param mapperConfiguration the mapper configuration * @param positionHintElement element used to for reference to the position in the source file. * @param additionalParameters additional parameters to add to the forged method + * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context + * parameters * @param history a parent forged method if this is a forged method within a forged method * @param mappingOptions the mapping options for this method */ private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters, - ForgedMethodHistory history, boolean autoMapping, MappingOptions mappingOptions) { + ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, + boolean autoMapping, MappingOptions mappingOptions) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); @@ -127,6 +166,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfig this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); + this.contextProvidedMethods = parameterProvidedMethods; this.returnType = returnType; this.thrownTypes = new ArrayList(); @@ -157,6 +197,7 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.contextParameters = Parameter.getContextParameters( parameters ); this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.mappingOptions = forgedMethod.mappingOptions; + this.contextProvidedMethods = forgedMethod.contextProvidedMethods; this.name = name; } @@ -211,6 +252,11 @@ public List getContextParameters() { return contextParameters; } + @Override + public ParameterProvidedMethods getContextProvidedMethods() { + return contextProvidedMethods; + } + @Override public Parameter getMappingTargetParameter() { return mappingTargetParameter; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 2e77eabc8c..9f93205a12 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -85,6 +85,11 @@ public interface Method { */ List getContextParameters(); + /** + * @return a mapping between {@link #getContextParameters()} to factory and lifecycle methods provided by them. + */ + ParameterProvidedMethods getContextProvidedMethods(); + /** * Returns the parameter designated as mapping target (if present) {@link org.mapstruct.MappingTarget} * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java new file mode 100644 index 0000000000..79a0aa8d40 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java @@ -0,0 +1,111 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.mapstruct.ap.internal.model.common.Parameter; + +/** + * Provides access to the {@link SourceMethod}s that are provided by {@link org.mapstruct.Context} parameters of a + * {@link Method} and maintains the relationship between those methods and their originating parameter. + * + * @author Andreas Gudian + */ +public class ParameterProvidedMethods { + private static final ParameterProvidedMethods EMPTY = + new ParameterProvidedMethods( Collections.> emptyMap() ); + + private final Map> parameterToProvidedMethods; + private final Map methodToProvidingParameter; + + private ParameterProvidedMethods(Map> parameterToProvidedMethods) { + this.parameterToProvidedMethods = parameterToProvidedMethods; + this.methodToProvidingParameter = new IdentityHashMap(); + for ( Entry> entry : parameterToProvidedMethods.entrySet() ) { + for ( SourceMethod method : entry.getValue() ) { + methodToProvidingParameter.put( method, entry.getKey() ); + } + } + } + + /** + * @param orderedParameters The parameters of which the provided methods are to be returned. + * @return The methods provided by the given parameters in the order as defined by the parameter list, with the + * methods of each parameter ordered based on their definition in that parameter's type. + */ + public List getAllProvidedMethodsInParameterOrder(List orderedParameters) { + List result = new ArrayList(); + + for ( Parameter parameter : orderedParameters ) { + List methods = parameterToProvidedMethods.get( parameter ); + if ( methods != null ) { + result.addAll( methods ); + } + } + + return result; + } + + /** + * @param method The method for which the defining parameter is to be returned. + * @return The Parameter on which's type the provided method is defined, or {@code null} if the method was not + * defined on one of the tracked parameters. + */ + public Parameter getParameterForProvidedMethod(Method method) { + return methodToProvidingParameter.get( method ); + } + + /** + * @return {@code true}, if no methods are provided by the tracked parameters or no parameters are tracked at all. + */ + public boolean isEmpty() { + return methodToProvidingParameter.isEmpty(); + } + + public static Builder builder() { + return new Builder(); + } + + public static ParameterProvidedMethods empty() { + return EMPTY; + } + + public static class Builder { + private Map> contextProvidedMethods = + new HashMap>(); + + private Builder() { + } + + public void addMethodsForParameter(Parameter param, List methods) { + contextProvidedMethods.put( param, methods ); + } + + public ParameterProvidedMethods build() { + return new ParameterProvidedMethods( contextProvidedMethods ); + } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 5f07249bf7..9361ddb3e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -71,6 +71,7 @@ public class SourceMethod implements Method { private final List sourceParameters; private final List contextParameters; + private final ParameterProvidedMethods contextProvidedMethods; private List parameterNames; @@ -101,6 +102,7 @@ public static class Builder { private MapperConfiguration mapperConfig = null; private List prototypeMethods = Collections.emptyList(); private List valueMappings; + private ParameterProvidedMethods contextProvidedMethods; public Builder setDeclaringMapper(Type declaringMapper) { this.declaringMapper = declaringMapper; @@ -182,23 +184,17 @@ public Builder setDefininingType(Type definingType) { return this; } + public Builder setContextProvidedMethods(ParameterProvidedMethods contextProvidedMethods) { + this.contextProvidedMethods = contextProvidedMethods; + return this; + } + public SourceMethod build() { MappingOptions mappingOptions = new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings, false ); - SourceMethod sourceMethod = new SourceMethod( - declaringMapper, - executable, - parameters, - returnType, - exceptionTypes, - mappingOptions, - typeUtils, - typeFactory, - mapperConfig, - prototypeMethods, - definingType ); + SourceMethod sourceMethod = new SourceMethod( this, mappingOptions ); if ( mappings != null ) { for ( Map.Entry> entry : mappings.entrySet() ) { @@ -211,32 +207,29 @@ public SourceMethod build() { } } - @SuppressWarnings( "checkstyle:parameternumber" ) - private SourceMethod(Type declaringMapper, ExecutableElement executable, List parameters, - Type returnType, List exceptionTypes, MappingOptions mappingOptions, Types typeUtils, - TypeFactory typeFactory, MapperConfiguration config, List prototypeMethods, - Type mapperToImplement) { - this.declaringMapper = declaringMapper; - this.executable = executable; - this.parameters = parameters; - this.returnType = returnType; - this.exceptionTypes = exceptionTypes; - this.accessibility = Accessibility.fromModifiers( executable.getModifiers() ); + private SourceMethod(Builder builder, MappingOptions mappingOptions) { + this.declaringMapper = builder.declaringMapper; + this.executable = builder.executable; + this.parameters = builder.parameters; + this.returnType = builder.returnType; + this.exceptionTypes = builder.exceptionTypes; + this.accessibility = Accessibility.fromModifiers( builder.executable.getModifiers() ); this.mappingOptions = mappingOptions; this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); + this.contextProvidedMethods = builder.contextProvidedMethods; this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); this.isObjectFactory = determineIfIsObjectFactory( executable ); - this.typeUtils = typeUtils; - this.typeFactory = typeFactory; - this.config = config; - this.prototypeMethods = prototypeMethods; - this.mapperToImplement = mapperToImplement; + this.typeUtils = builder.typeUtils; + this.typeFactory = builder.typeFactory; + this.config = builder.mapperConfig; + this.prototypeMethods = builder.prototypeMethods; + this.mapperToImplement = builder.definingType; } private boolean determineIfIsObjectFactory(ExecutableElement executable) { @@ -278,6 +271,11 @@ public List getContextParameters() { return contextParameters; } + @Override + public ParameterProvidedMethods getContextProvidedMethods() { + return contextProvidedMethods; + } + @Override public List getParameterNames() { if ( parameterNames == null ) { @@ -549,6 +547,7 @@ public List getThrownTypes() { return exceptionTypes; } + @Override public MappingOptions getMappingOptions() { return mappingOptions; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 4ba6e3c3aa..60c939c691 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -35,6 +35,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; @@ -109,6 +110,11 @@ public List getContextParameters() { return Collections.emptyList(); } + @Override + public ParameterProvidedMethods getContextProvidedMethods() { + return ParameterProvidedMethods.empty(); + } + /** * {@inheritDoc} *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index dee29e18e0..59772cd462 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -44,6 +44,7 @@ import org.mapstruct.ap.internal.model.source.IterableMapping; import org.mapstruct.ap.internal.model.source.MapMapping; import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.ValueMapping; import org.mapstruct.ap.internal.prism.BeanMappingPrism; @@ -91,7 +92,7 @@ public List process(ProcessorContext context, TypeElement mapperTy mapperConfig.getAnnotationMirror() ); } - List prototypeMethods = retrievePrototypeMethods( mapperConfig ); + List prototypeMethods = retrievePrototypeMethods( mapperTypeElement, mapperConfig ); return retrieveMethods( mapperTypeElement, mapperTypeElement, mapperConfig, prototypeMethods ); } @@ -100,7 +101,8 @@ public int getPriority() { return 1; } - private List retrievePrototypeMethods(MapperConfiguration mapperConfig ) { + private List retrievePrototypeMethods(TypeElement mapperTypeElement, + MapperConfiguration mapperConfig) { if ( mapperConfig.config() == null ) { return Collections.emptyList(); } @@ -123,7 +125,8 @@ private List retrievePrototypeMethods(MapperConfiguration mapperCo parameters, containsTargetTypeParameter, mapperConfig, - prototypeMethods + prototypeMethods, + mapperTypeElement ); if ( method != null ) { @@ -198,7 +201,8 @@ private SourceMethod getMethod(TypeElement usedMapper, parameters, containsTargetTypeParameter, mapperConfig, - prototypeMethods ); + prototypeMethods, + mapperToImplement ); } // otherwise add reference to existing mapper method else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( method, parameters, returnType ) @@ -211,10 +215,11 @@ else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( method, } private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, ExecutableElement method, - List parameters, - boolean containsTargetTypeParameter, - MapperConfiguration mapperConfig, - List prototypeMethods ) { + List parameters, + boolean containsTargetTypeParameter, + MapperConfiguration mapperConfig, + List prototypeMethods, + TypeElement mapperToImplement) { Type returnType = typeFactory.getReturnType( methodType ); List exceptionTypes = typeFactory.getThrownTypes( methodType ); List sourceParameters = Parameter.getSourceParameters( parameters ); @@ -236,32 +241,58 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, return null; } + ParameterProvidedMethods contextProvidedMethods = + retrieveLifecycleMethodsFromContext( contextParameters, mapperToImplement, mapperConfig ); + return new SourceMethod.Builder() - .setExecutable( method ) - .setParameters( parameters ) - .setReturnType( returnType ) - .setExceptionTypes( exceptionTypes ) - .setMappings( getMappings( method ) ) - .setIterableMapping( - IterableMapping.fromPrism( - IterableMappingPrism.getInstanceOn( method ), method, messager - ) - ) - .setMapMapping( - MapMapping.fromPrism( MapMappingPrism.getInstanceOn( method ), method, messager ) - ) - .setBeanMapping( - BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager ) - ) - .setValueMappings( getValueMappings( method ) ) - .setTypeUtils( typeUtils ) - .setMessager( messager ) - .setTypeFactory( typeFactory ) - .setMapperConfiguration( mapperConfig ) - .setPrototypeMethods( prototypeMethods ) + .setExecutable( method ) + .setParameters( parameters ) + .setReturnType( returnType ) + .setExceptionTypes( exceptionTypes ) + .setMappings( getMappings( method ) ) + .setIterableMapping( + IterableMapping.fromPrism( + IterableMappingPrism.getInstanceOn( method ), + method, + messager ) ) + .setMapMapping( + MapMapping.fromPrism( MapMappingPrism.getInstanceOn( method ), method, messager ) ) + .setBeanMapping( + BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager ) ) + .setValueMappings( getValueMappings( method ) ) + .setTypeUtils( typeUtils ) + .setMessager( messager ) + .setTypeFactory( typeFactory ) + .setMapperConfiguration( mapperConfig ) + .setPrototypeMethods( prototypeMethods ) + .setContextProvidedMethods( contextProvidedMethods ) .build(); } + private ParameterProvidedMethods retrieveLifecycleMethodsFromContext( + List contextParameters, TypeElement mapperToImplement, MapperConfiguration mapperConfig) { + + ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder(); + for ( Parameter contextParam : contextParameters ) { + List contextParamMethods = retrieveMethods( + contextParam.getType().getTypeElement(), + mapperToImplement, + mapperConfig, + Collections. emptyList() ); + + List lifecycleMethods = new ArrayList( contextParamMethods.size() ); + for ( SourceMethod sourceMethod : contextParamMethods ) { + if ( sourceMethod.isLifecycleCallbackMethod() ) { + lifecycleMethods.add( sourceMethod ); + } + } + + builder.addMethodsForParameter( contextParam, lifecycleMethods ); + } + + return builder.build(); + } + private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType methodType, ExecutableElement method, TypeElement mapperToImplement, List parameters) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index ea38ab1b7e..f261d34756 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -165,7 +165,7 @@ java.util.Collections. emptyList(), MapperReference ref = findMapperReference( matchingFactoryMethod.getMethod() ); - return new MethodReference( + return MethodReference.forMapperReference( matchingFactoryMethod.getMethod(), ref, matchingFactoryMethod.getParameterBindings() ); @@ -325,7 +325,7 @@ private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { ConversionContext ctx = new DefaultConversionContext( typeFactory, messager, sourceType, targetType, dateFormat, numberFormat); - Assignment methodReference = new MethodReference( matchingBuiltInMethod.getMethod(), ctx ); + Assignment methodReference = MethodReference.forBuiltInMethod( matchingBuiltInMethod.getMethod(), ctx ); methodReference.setAssignment( sourceRHS ); return methodReference; } @@ -521,11 +521,10 @@ private Assignment getMappingMethodReference(SelectedMethod method, Type targetType) { MapperReference mapperReference = findMapperReference( method.getMethod() ); - return new MethodReference( + return MethodReference.forMapperReference( method.getMethod(), mapperReference, - method.getParameterBindings() - ); + method.getParameterBindings() ); } /** diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 2a37f31067..c7af8d074d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -20,13 +20,15 @@ --> <@compress single_line=true> <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> - <#if declaringMapper??><#if static><@includeModel object=declaringMapper.type/><#else>${mapperVariableName}.<@params/> + <#if declaringMapper??><#if static><@includeModel object=declaringMapper.type/><#else>${mapperVariableName}.<@methodCall/> + <#-- method is provided by a context parameter --> + <#elseif providingParameter??><#if static><@includeModel object=providingParameter.type/><#else>${providingParameter.name}.<@methodCall/> <#-- method is referenced java8 static method in the mapper to implement (interface) --> - <#elseif static><@includeModel object=definingType/>.<@params/> + <#elseif static><@includeModel object=definingType/>.<@methodCall/> <#else> - <@params/> + <@methodCall/> - <#macro params> + <#macro methodCall> <@compress> ${name}<#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java index 773911bb96..a0afc9af5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java @@ -26,7 +26,7 @@ /** * @author Andreas Gudian */ -@Mapper(uses = CycleContextLifecycleMethods.class) +@Mapper(uses = { CycleContextLifecycleMethods.class, FactoryContextMethods.class }) public interface AutomappingNodeMapperWithContext { AutomappingNodeMapperWithContext INSTANCE = diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java new file mode 100644 index 0000000000..af3ffc396f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + */ +@Mapper(uses = FactoryContextMethods.class) +public interface AutomappingNodeMapperWithSelfContainingContext { + + AutomappingNodeMapperWithSelfContainingContext INSTANCE = + Mappers.getMapper( AutomappingNodeMapperWithSelfContainingContext.class ); + + NodeDto nodeToNodeDto(Node node, @Context SelfContainingCycleContext cycleContext, + @Context FactoryContext factoryContext); + + void nodeToNodeDto(Node node, @MappingTarget NodeDto nodeDto, @Context SelfContainingCycleContext cycleContext, + @Context FactoryContext factoryContext); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java index 25b74cd9f9..b84fa21ec3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java @@ -40,6 +40,7 @@ *

    • passing the parameter to factory methods (with and without {@link ObjectFactory}) *
    • passing the parameter to lifecycle methods (in this case, {@link BeforeMapping} *
    • passing multiple parameters, with varied order of context params and mapping source params + *
    • calling lifecycle methods on context params *
    * * @author Andreas Gudian @@ -50,9 +51,12 @@ NodeDto.class, NodeMapperWithContext.class, AutomappingNodeMapperWithContext.class, + AutomappingNodeMapperWithSelfContainingContext.class, CycleContext.class, FactoryContext.class, - CycleContextLifecycleMethods.class }) + CycleContextLifecycleMethods.class, + FactoryContextMethods.class, + SelfContainingCycleContext.class }) @RunWith(AnnotationProcessorTestRunner.class) public class ContextParameterTest { @@ -83,6 +87,26 @@ public void automappingWithContextCorrectlyResolvesCycles() { assertResult( updated ); } + @Test + public void automappingWithSelfContainingContextCorrectlyResolvesCycles() { + Node root = buildNodes(); + NodeDto rootDto = AutomappingNodeMapperWithSelfContainingContext.INSTANCE + .nodeToNodeDto( + root, + new SelfContainingCycleContext(), + new FactoryContext( 0, MAGIC_NUMBER_OFFSET ) ); + assertResult( rootDto ); + + NodeDto updated = new NodeDto( 0 ); + AutomappingNodeMapperWithSelfContainingContext.INSTANCE + .nodeToNodeDto( + root, + updated, + new SelfContainingCycleContext(), + new FactoryContext( 1, 10 ) ); + assertResult( updated ); + } + private void assertResult(NodeDto rootDto) { assertThat( rootDto ).isNotNull(); assertThat( rootDto.getId() ).isEqualTo( 0 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java index 47684f0646..ffb2a970f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java @@ -21,25 +21,13 @@ import org.mapstruct.BeforeMapping; import org.mapstruct.Context; import org.mapstruct.MappingTarget; -import org.mapstruct.ObjectFactory; import org.mapstruct.TargetType; -import org.mapstruct.ap.test.context.Node.Attribute; -import org.mapstruct.ap.test.context.NodeDto.AttributeDto; /** * @author Andreas Gudian */ public class CycleContextLifecycleMethods { - public NodeDto createNodeDto(@Context FactoryContext context) { - return context.createNode(); - } - - @ObjectFactory - public AttributeDto createAttributeDto(Attribute source, @Context FactoryContext context) { - return context.createAttributeDto( source ); - } - @BeforeMapping public T getInstance(Object source, @TargetType Class type, @Context CycleContext cycleContext) { return cycleContext.getMappedInstance( source, type ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java index 1592f88070..df6b07ddce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java @@ -31,9 +31,9 @@ public class FactoryContext { private int nodeCounter; private int attributeMagicNumberOffset; - public FactoryContext(int initialCounter, int attributeMaticNumberOffset) { + public FactoryContext(int initialCounter, int attributeMagicNumberOffset) { this.nodeCounter = initialCounter; - this.attributeMagicNumberOffset = attributeMaticNumberOffset; + this.attributeMagicNumberOffset = attributeMagicNumberOffset; } public NodeDto createNode() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java new file mode 100644 index 0000000000..6eb9ddbd4a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import org.mapstruct.Context; +import org.mapstruct.ObjectFactory; +import org.mapstruct.ap.test.context.Node.Attribute; +import org.mapstruct.ap.test.context.NodeDto.AttributeDto; + +/** + * @author Andreas Gudian + */ +public class FactoryContextMethods { + + public NodeDto createNodeDto(@Context FactoryContext context) { + return context.createNode(); + } + + @ObjectFactory + public AttributeDto createAttributeDto(Attribute source, @Context FactoryContext context) { + return context.createAttributeDto( source ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java index 9d5a39723f..374363f9b4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java @@ -28,7 +28,7 @@ /** * @author Andreas Gudian */ -@Mapper(uses = CycleContextLifecycleMethods.class) +@Mapper(uses = { CycleContextLifecycleMethods.class, FactoryContextMethods.class }) public interface NodeMapperWithContext { NodeMapperWithContext INSTANCE = Mappers.getMapper( NodeMapperWithContext.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java new file mode 100644 index 0000000000..7f062d5c7d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context; + +import java.util.IdentityHashMap; +import java.util.Map; + +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetType; + +/** + * A type to be used as {@link Context} parameter to track cycles in graphs. + * + * @author Andreas Gudian + */ +public class SelfContainingCycleContext { + private Map knownInstances = new IdentityHashMap(); + + @BeforeMapping + @SuppressWarnings("unchecked") + public T getMappedInstance(Object source, @TargetType Class targetType) { + return (T) knownInstances.get( source ); + } + + @BeforeMapping + public void storeMappedInstance(Object source, @MappingTarget Object target) { + knownInstances.put( source, target ); + } +} From 32bf03642c541aeaea450f7f60d3778fbe4c4330 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Mon, 2 Jan 2017 00:17:25 +0100 Subject: [PATCH 0042/1006] #983, #975 rephrase documentation of AfterMapping/BeforeMapping and document @Context usage --- .../main/java/org/mapstruct/AfterMapping.java | 46 +++++++++-------- .../java/org/mapstruct/BeforeMapping.java | 51 ++++++++++--------- 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/core-common/src/main/java/org/mapstruct/AfterMapping.java b/core-common/src/main/java/org/mapstruct/AfterMapping.java index 21849573a2..f6d8350ea5 100644 --- a/core-common/src/main/java/org/mapstruct/AfterMapping.java +++ b/core-common/src/main/java/org/mapstruct/AfterMapping.java @@ -23,36 +23,40 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.mapstruct.util.Experimental; - /** * Marks a method to be invoked at the end of a generated mapping method, right before the last {@code return} statement - * of the mapping method. The method can be implemented in an abstract mapper class or be declared in a type (class or - * interface) referenced in {@link Mapper#uses()} in order to be used in a mapping method. - *

    - * Only methods with return type {@code void} may be annotated with this annotation. + * of the mapping method. The method can be implemented in an abstract mapper class, be declared in a type (class or + * interface) referenced in {@link Mapper#uses()}, or in a type used as {@code @}{@link Context} parameter in order to + * be used in a mapping method. *

    - * If the method has parameters, the method invocation is only generated if all parameters can be assigned by - * the source or target parameters of the mapping method: + * The method invocation is only generated if the return type of the method (if non-{@code void}) is assignable to the + * return type of the mapping method and all parameters can be assigned by the available source, target or + * context parameters of the mapping method: *

      *
    • A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping. *
    • *
    • A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.
    • - *
    • Any other parameter is populated with a source parameter of the mapping, whereas each source parameter is used - * once at most.
    • + *
    • Parameters annotated with {@code @}{@link Context} are populated with the context parameters of the mapping + * method.
    • + *
    • Any other parameter is populated with a source parameter of the mapping.
    • *
    *

    - * All after-mapping methods that can be applied to a mapping method will be used. Their order is determined by - * their location of definition: - *

      - *
    • The order of methods within one type can not be guaranteed, as it depends on the compiler and the processing - * environment implementation.
    • - *
    • Methods declared in one type are used after methods declared in their super-type.
    • - *
    • Methods implemented in the mapper itself are used before methods from types referenced in {@link Mapper#uses()}. + * For non-{@code void} methods, the return value of the method invocation is returned as the result of the mapping + * method if it is not {@code null}. + *

      + * All after-mapping methods that can be applied to a mapping method will be used. {@code @}{@link Qualifier} / + * {@code @}{@link Named} can be used to filter the methods to use. + *

      + * The order of the method invocation is determined by their location of definition: + *

        + *
      1. Methods declared on {@code @}{@link Context} parameters, ordered by the parameter order.
      2. + *
      3. Methods implemented in the mapper itself.
      4. + *
      5. Methods from types referenced in {@link Mapper#uses()}, in the order of the type declaration in the annotation. *
      6. - *
      7. Types referenced in {@link Mapper#uses()} are searched for after-mapping methods in the order specified - * in the annotation.
      8. - *
    + *
  1. Methods declared in one type are used after methods declared in their super-type
  2. + *
+ * Important: the order of methods declared within one type can not be guaranteed, as it depends on the + * compiler and the processing environment implementation. *

* Example: * @@ -97,8 +101,8 @@ * * @author Andreas Gudian * @see BeforeMapping + * @see Context */ -@Experimental @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) public @interface AfterMapping { diff --git a/core-common/src/main/java/org/mapstruct/BeforeMapping.java b/core-common/src/main/java/org/mapstruct/BeforeMapping.java index 122b302349..626e918ed8 100644 --- a/core-common/src/main/java/org/mapstruct/BeforeMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeforeMapping.java @@ -23,39 +23,42 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.mapstruct.util.Experimental; - /** * Marks a method to be invoked at the beginning of a generated mapping method. The method can be implemented in an - * abstract mapper class or be declared in a type (class or interface) referenced in {@link Mapper#uses()} in order to - * be used in a mapping method. - *

- * Only methods with return type {@code void} may be annotated with this annotation. + * abstract mapper class, be declared in a type (class or interface) referenced in {@link Mapper#uses()}, or in a type + * used as {@code @}{@link Context} parameter in order to be used in a mapping method. *

- * If the method has parameters, the method invocation is only generated if all parameters can be assigned by - * the source or target parameters of the mapping method: + * The method invocation is only generated if the return type of the method (if non-{@code void}) is assignable to the + * return type of the mapping method and all parameters can be assigned by the available source, target or + * context parameters of the mapping method: *

    *
  • A parameter annotated with {@code @}{@link MappingTarget} is populated with the target instance of the mapping. *
  • *
  • A parameter annotated with {@code @}{@link TargetType} is populated with the target type of the mapping.
  • - *
  • Any other parameter is populated with a source parameter of the mapping, whereas each source parameter is used - * once at most.
  • + *
  • Parameters annotated with {@code @}{@link Context} are populated with the context parameters of the mapping + * method.
  • + *
  • Any other parameter is populated with a source parameter of the mapping.
  • *
- * If a before-mapping method does not contain a {@code @}{@link MappingTarget} parameter, it is invoked - * directly at the beginning of the applicable mapping method. If it contains a {@code @}{@link MappingTarget} - * parameter, the method is invoked after the target parameter has been initialized in the mapping method. *

- * All before-mapping methods that can be applied to a mapping method will be used. Their order is determined - * by their location of definition: - *

    - *
  • The order of methods within one type can not be guaranteed, as it depends on the compiler and the processing - * environment implementation.
  • - *
  • Methods declared in one type are used after methods declared in their super-type.
  • - *
  • Methods implemented in the mapper itself are used before methods from types referenced in {@link Mapper#uses()}. + * For non-{@code void} methods, the return value of the method invocation is returned as the result of the mapping + * method if it is not {@code null}. + *

    + * All before-mapping methods that can be applied to a mapping method will be used. {@code @}{@link Qualifier} + * / {@code @}{@link Named} can be used to filter the methods to use. + *

    + * The order of the method invocation is determined by their their variant and their location of definition: + *

      + *
    1. Methods without an {@code @}{@link MappingTarget} parameter are called before any null-checks on source + * parameters and constructing a new target bean.
    2. + *
    3. Methods with an {@code @}{@link MappingTarget} parameter are called after constructing a new target bean.
    4. + *
    5. Methods declared on {@code @}{@link Context} parameters, ordered by the parameter order.
    6. + *
    7. Methods implemented in the mapper itself.
    8. + *
    9. Methods from types referenced in {@link Mapper#uses()}, in the order of the type declaration in the annotation. *
    10. - *
    11. Types referenced in {@link Mapper#uses()} are searched for after-mapping methods in the order specified - * in the annotation.
    12. - *
+ *
  • Methods declared in one type are used after methods declared in their super-type
  • + * + * Important: the order of methods declared within one type can not be guaranteed, as it depends on the + * compiler and the processing environment implementation. *

    * Example: * @@ -101,8 +104,8 @@ * * @author Andreas Gudian * @see AfterMapping + * @see Context */ -@Experimental @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) public @interface BeforeMapping { From 9c30727262316f36ae981f1e9ed083141cde1319 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Feb 2017 08:56:36 +0100 Subject: [PATCH 0043/1006] #1061 Support for generating Mappers in the default package --- .../ap/internal/model/GeneratedType.java | 5 +++ .../processor/MapperRenderingProcessor.java | 6 ++- .../ap/internal/model/GeneratedType.ftl | 3 ++ .../ap/test/bugs/_1061/Issue1061Test.java | 39 +++++++++++++++++++ .../test/bugs/_1061/SourceTargetMapper.java | 32 +++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 0fe1409fff..5ae330af44 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; /** @@ -108,6 +109,10 @@ public String getPackageName() { return packageName; } + public boolean hasPackageName() { + return !Strings.isEmpty( packageName ); + } + public String getName() { return name; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java index 687e71eab9..c91cd08ceb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java @@ -57,7 +57,11 @@ private void writeToSourceFile(Filer filer, Mapper model) { } private void createSourceFile(GeneratedType model, ModelWriter modelWriter, Filer filer) { - String fileName = model.getPackageName() + "." + model.getName(); + String fileName = ""; + if ( model.hasPackageName() ) { + fileName += model.getPackageName() + "."; + } + fileName += model.getName(); JavaFileObject sourceFile; try { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 20dca0b950..01fe414e58 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.GeneratedType" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) @@ -18,7 +19,9 @@ limitations under the License. --> +<#if hasPackageName()> package ${packageName}; + <#list importTypes as importedType> import ${importedType.importName}; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java new file mode 100644 index 0000000000..22d681d8ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1061; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1061") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(SourceTargetMapper.class) +public class Issue1061Test { + + @Test + public void shouldCompile() throws Exception { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java new file mode 100644 index 0000000000..ff677f581e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1061; + +import java.util.List; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(implementationPackage = "") +public interface SourceTargetMapper { + + List map(List strings); +} From 79acfff9c3c29f1b2d6730da8b0aa00ba3f4b2cf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 1 Feb 2017 20:33:29 +0100 Subject: [PATCH 0044/1006] #1050 remove duplicate properties which are already defined in the parent --- .../ap/internal/model/BeanMappingMethod.java | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 580d53dd62..d3e6c9473e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -74,10 +74,7 @@ public class BeanMappingMethod extends ContainerMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; private final List constantMappings; - private final MethodReference factoryMethod; - private final boolean mapNullToDefault; private final Type resultType; - private final boolean overridden; public static class Builder { @@ -695,10 +692,7 @@ private BeanMappingMethod(Method method, } } } - this.factoryMethod = factoryMethod; - this.mapNullToDefault = mapNullToDefault; this.resultType = resultType; - this.overridden = method.overridesMethod(); } public List getPropertyMappings() { @@ -713,16 +707,6 @@ public Map> getPropertyMappingsByParameter() { return mappingsByParameter; } - @Override - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - - @Override - public boolean isOverridden() { - return overridden; - } - @Override public Type getResultType() { if ( resultType == null ) { @@ -765,11 +749,6 @@ public List getSourcePrimitiveParameters() { return sourceParameters; } - @Override - public MethodReference getFactoryMethod() { - return this.factoryMethod; - } - @Override public Type getResultElementType() { return null; From c9a313ac151d30dd234dd3d907c213a8e91fac04 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 1 Feb 2017 21:03:25 +0100 Subject: [PATCH 0045/1006] #1050 Extract a common MappingMethod for the normal (non-enum / non-value) mapping methods that are used within MapStruct --- .../ap/internal/model/BeanMappingMethod.java | 18 +-- .../model/ContainerMappingMethod.java | 54 ++------- .../ap/internal/model/MapMappingMethod.java | 87 +------------ .../model/NormalTypeMappingMethod.java | 114 ++++++++++++++++++ 4 files changed, 129 insertions(+), 144 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d3e6c9473e..7797edaebe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -69,7 +69,7 @@ * * @author Gunnar Morling */ -public class BeanMappingMethod extends ContainerMappingMethod { +public class BeanMappingMethod extends NormalTypeMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; @@ -667,13 +667,10 @@ private BeanMappingMethod(Method method, List afterMappingReferences) { super( method, - null, factoryMethod, mapNullToDefault, - null, beforeMappingReferences, - afterMappingReferences, - null + afterMappingReferences ); this.propertyMappings = propertyMappings; @@ -749,17 +746,10 @@ public List getSourcePrimitiveParameters() { return sourceParameters; } - @Override - public Type getResultElementType() { - return null; - } - @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); - return result; + //Needed for Checkstyle, otherwise it fails due to EqualsHashCode rule + return super.hashCode(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index cc6dfa367f..608ed8b17e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -36,11 +36,8 @@ * * @author Filip Hrisafov */ -public abstract class ContainerMappingMethod extends MappingMethod { +public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { private final Assignment elementAssignment; - private final MethodReference factoryMethod; - private final boolean overridden; - private final boolean mapNullToDefault; private final String loopVariableName; private final SelectionParameters selectionParameters; @@ -49,11 +46,8 @@ public abstract class ContainerMappingMethod extends MappingMethod { List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters) { - super( method, beforeMappingReferences, afterMappingReferences ); + super( method, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); this.elementAssignment = parameterAssignment; - this.factoryMethod = factoryMethod; - this.overridden = method.overridesMethod(); - this.mapNullToDefault = mapNullToDefault; this.loopVariableName = loopVariableName; this.selectionParameters = selectionParameters; } @@ -78,22 +72,9 @@ public Set getImportTypes() { if ( elementAssignment != null ) { types.addAll( elementAssignment.getImportTypes() ); } - if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { - if ( getReturnType().getImplementationType() != null ) { - types.addAll( getReturnType().getImplementationType().getImportTypes() ); - } - } return types; } - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - - public boolean isOverridden() { - return overridden; - } - public String getLoopVariableName() { return loopVariableName; } @@ -119,10 +100,6 @@ public String getDefaultValue() { } } - public MethodReference getFactoryMethod() { - return this.factoryMethod; - } - public abstract Type getResultElementType(); public String getIndex1Name() { @@ -135,10 +112,8 @@ public String getIndex2Name() { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); - return result; + //Needed for Checkstyle, otherwise it fails due to EqualsHashCode rule + return super.hashCode(); } @Override @@ -152,27 +127,12 @@ public boolean equals(Object obj) { if ( getClass() != obj.getClass() ) { return false; } - ContainerMappingMethod other = (ContainerMappingMethod) obj; - if ( !getResultType().equals( other.getResultType() ) ) { + if ( !super.equals( obj ) ) { return false; } - if ( getSourceParameters().size() != other.getSourceParameters().size() ) { - return false; - } - - for ( int i = 0; i < getSourceParameters().size(); i++ ) { - if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { - return false; - } - List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); - List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); - - if ( !thisTypeParameters.equals( otherTypeParameters ) ) { - return false; - } - } + ContainerMappingMethod other = (ContainerMappingMethod) obj; if ( this.selectionParameters != null ) { if ( !this.selectionParameters.equals( other.selectionParameters ) ) { @@ -183,7 +143,7 @@ else if ( other.selectionParameters != null ) { return false; } - return isMapNullToDefault() == other.isMapNullToDefault(); + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index f37729e74f..861cd4b1ae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.HashSet; import java.util.List; import java.util.Map; @@ -36,19 +34,18 @@ import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one {@code Map} type to another. Keys and * values are mapped either by a {@link TypeConversion} or another mapping method if required. * * @author Gunnar Morling */ -public class MapMappingMethod extends MappingMethod { +public class MapMappingMethod extends NormalTypeMappingMethod { private final Assignment keyAssignment; private final Assignment valueAssignment; - private final MethodReference factoryMethod; - private final boolean overridden; - private final boolean mapNullToDefault; public static class Builder extends AbstractMappingMethodBuilder { @@ -183,13 +180,10 @@ private MapMappingMethod(Method method, Assignment keyAssignment, Assignment val MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, List afterMappingReferences) { - super( method, beforeMappingReferences, afterMappingReferences ); + super( method, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); this.keyAssignment = keyAssignment; this.valueAssignment = valueAssignment; - this.factoryMethod = factoryMethod; - this.overridden = method.overridesMethod(); - this.mapNullToDefault = mapNullToDefault; } public Parameter getSourceParameter() { @@ -229,12 +223,6 @@ public Set getImportTypes() { if ( valueAssignment != null ) { types.addAll( valueAssignment.getImportTypes() ); } - if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { - types.addAll( getReturnType().getImportTypes() ); - if ( getReturnType().getImplementationType() != null ) { - types.addAll( getReturnType().getImplementationType().getImportTypes() ); - } - } return types; } @@ -259,71 +247,4 @@ public String getEntryVariableName() { getParameterNames() ); } - - public MethodReference getFactoryMethod() { - return this.factoryMethod; - } - - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - - public boolean isOverridden() { - return overridden; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); - return result; - } - - @Override - public boolean equals(Object obj) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - MapMappingMethod other = (MapMappingMethod) obj; - - if ( !getResultType().equals( other.getResultType() ) ) { - return false; - } - - if ( getSourceParameters().size() != other.getSourceParameters().size() ) { - return false; - } - - for ( int i = 0; i < getSourceParameters().size(); i++ ) { - if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { - return false; - } - - List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); - List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); - - if ( !thisTypeParameters.equals( otherTypeParameters ) ) { - return false; - } - } - - if ( this.factoryMethod != null ) { - if ( !this.factoryMethod.equals( other.factoryMethod ) ) { - return false; - } - } - else if ( other.factoryMethod != null ) { - return false; - } - - return isMapNullToDefault() == other.isMapNullToDefault(); - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java new file mode 100644 index 0000000000..9a5f7863c8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -0,0 +1,114 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * A {@link MappingMethod} that is used by the main mapping methods ({@link BeanMappingMethod}, + * {@link MapMappingMethod}, {@link IterableMappingMethod} and {@link StreamMappingMethod} (non-enum / non-value + * mapping) + * + * @author Filip Hrisafov + */ +public abstract class NormalTypeMappingMethod extends MappingMethod { + private final MethodReference factoryMethod; + private final boolean overridden; + private final boolean mapNullToDefault; + + NormalTypeMappingMethod(Method method, MethodReference factoryMethod, boolean mapNullToDefault, + List beforeMappingReferences, + List afterMappingReferences) { + super( method, beforeMappingReferences, afterMappingReferences ); + this.factoryMethod = factoryMethod; + this.overridden = method.overridesMethod(); + this.mapNullToDefault = mapNullToDefault; + } + + @Override + public Set getImportTypes() { + Set types = super.getImportTypes(); + if ( ( factoryMethod == null ) && ( !isExistingInstanceMapping() ) ) { + if ( getReturnType().getImplementationType() != null ) { + types.addAll( getReturnType().getImplementationType().getImportTypes() ); + } + } + return types; + } + + public boolean isMapNullToDefault() { + return mapNullToDefault; + } + + public boolean isOverridden() { + return overridden; + } + + public MethodReference getFactoryMethod() { + return this.factoryMethod; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + NormalTypeMappingMethod other = (NormalTypeMappingMethod) obj; + + if ( !getResultType().equals( other.getResultType() ) ) { + return false; + } + + if ( getSourceParameters().size() != other.getSourceParameters().size() ) { + return false; + } + + for ( int i = 0; i < getSourceParameters().size(); i++ ) { + if ( !getSourceParameters().get( i ).getType().equals( other.getSourceParameters().get( i ).getType() ) ) { + return false; + } + List thisTypeParameters = getSourceParameters().get( i ).getType().getTypeParameters(); + List otherTypeParameters = other.getSourceParameters().get( i ).getType().getTypeParameters(); + + if ( !thisTypeParameters.equals( otherTypeParameters ) ) { + return false; + } + } + + return isMapNullToDefault() == other.isMapNullToDefault(); + } +} From 56ea9dd168932071c957403470b2231e3aac33c9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Feb 2017 10:16:55 +0100 Subject: [PATCH 0046/1006] #1050 Use the getNull method from the Type instead of the getDefaultValue --- .../model/ContainerMappingMethod.java | 22 ------------------- .../ap/internal/model/common/Type.java | 5 +++-- .../internal/model/IterableMappingMethod.ftl | 2 +- .../ap/internal/model/StreamMappingMethod.ftl | 2 +- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 608ed8b17e..171a69a0e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Set; -import javax.lang.model.type.TypeKind; import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Parameter; @@ -79,27 +78,6 @@ public String getLoopVariableName() { return loopVariableName; } - public String getDefaultValue() { - TypeKind kind = getResultElementType().getTypeMirror().getKind(); - switch ( kind ) { - case BOOLEAN: - return "false"; - case BYTE: - case SHORT: - case INT: - case CHAR: /*"'\u0000'" would have been better, but depends on platformencoding */ - return "0"; - case LONG: - return "0L"; - case FLOAT: - return "0.0f"; - case DOUBLE: - return "0.0d"; - default: - return "null"; - } - } - public abstract Type getResultElementType(); public String getIndex1Name() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 219c02ea07..5603de2faa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -758,10 +758,11 @@ public String getNull() { return "0"; } if ( "char".equals( getName() ) ) { - return "'\\u0000'"; + //"'\u0000'" would have been better, but depends on platform encoding + return "0"; } if ( "double".equals( getName() ) ) { - return "0.0"; + return "0.0d"; } if ( "float".equals( getName() ) ) { return "0.0f"; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index c616ad5100..502e99fc13 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -35,7 +35,7 @@ <#if existingInstanceMapping> <#-- we can't clear an existing array, so we've got to clear by setting values to default --> for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) { - ${resultName}[${index2Name}] = ${defaultValue}; + ${resultName}[${index2Name}] = ${resultElementType.null}; } return<#if returnType.name != "void"> ${resultName}; <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index ca42302740..eadfa67b50 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -37,7 +37,7 @@ <#if existingInstanceMapping> <#-- we can't clear an existing array, so we've got to clear by setting values to default --> for (int ${index2Name} = 0; ${index2Name} < ${resultName}.length; ${index2Name}++ ) { - ${resultName}[${index2Name}] = ${defaultValue}; + ${resultName}[${index2Name}] = ${resultElementType.null}; } return<#if returnType.name != "void"> ${resultName}; <#else> From 40fc5612cb4d0d8b6f4ed652bfcb61c3ef0e64d8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 10 Feb 2017 19:57:41 +0100 Subject: [PATCH 0047/1006] #1060 Use update methods if there are multiple source parameters --- .../ap/internal/model/BeanMappingMethod.java | 2 + .../ap/internal/model/MappingMethod.java | 7 +- .../model/NormalTypeMappingMethod.java | 6 +- .../ap/internal/model/PropertyMapping.java | 16 +- .../NestedTargetPropertiesTest.java | 9 + .../ChartEntryToArtistImpl.java | 338 ++++++++++++++++++ .../ChartEntryToArtistUpdateImpl.java | 116 ++++++ .../FishTankMapperImpl.java | 92 +++++ 8 files changed, 579 insertions(+), 7 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 7797edaebe..6584f26121 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -303,6 +303,7 @@ private void handleDefinedNestedTargetMapping(Set handledTargets) { for ( Entry entryByTP : optionsByNestedTarget.entrySet() ) { Map optionsBySourceParam = entryByTP.getValue().groupBySourceParameter(); + boolean forceUpdateMethod = optionsBySourceParam.keySet().size() > 1; for ( Entry entryByParam : optionsBySourceParam.entrySet() ) { SourceReference sourceRef = new SourceReference.BuilderFromProperty() @@ -319,6 +320,7 @@ private void handleDefinedNestedTargetMapping(Set handledTargets) { .existingVariableNames( existingVariableNames ) .dependsOn( entryByParam.getValue().collectNestedDependsOn() ) .forgeMethodWithMappingOptions( entryByParam.getValue() ) + .forceUpdateMethod( forceUpdateMethod ) .build(); unprocessedSourceParameters.remove( sourceRef.getParameter() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index e746f4bf4c..0f80ddd11c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -220,7 +220,6 @@ public List getBeforeMappingReferencesWithoutM @Override public int hashCode() { int hash = 7; - hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0); hash = 83 * hash + (this.parameters != null ? this.parameters.hashCode() : 0); hash = 83 * hash + (this.returnType != null ? this.returnType.hashCode() : 0); return hash; @@ -237,10 +236,10 @@ public boolean equals(Object obj) { if ( getClass() != obj.getClass() ) { return false; } + //Do not add name to the equals check. + //Reason: Whenever we forge methods we can reuse mappings if they are the same. However, if we take the name + // into consideration, they'll never be the same, because we create safe methods names. final MappingMethod other = (MappingMethod) obj; - if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { - return false; - } if ( this.parameters != other.parameters && (this.parameters == null || !this.parameters.equals( other.parameters )) ) { return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index 9a5f7863c8..e1e72eb62d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -71,7 +71,7 @@ public MethodReference getFactoryMethod() { @Override public int hashCode() { final int prime = 31; - int result = 1; + int result = super.hashCode(); result = prime * result + ( ( getResultType() == null ) ? 0 : getResultType().hashCode() ); return result; } @@ -89,6 +89,10 @@ public boolean equals(Object obj) { } NormalTypeMappingMethod other = (NormalTypeMappingMethod) obj; + if ( !super.equals( obj ) ) { + return false; + } + if ( !getResultType().equals( other.getResultType() ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index b6308e28d3..9eb1290acd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -187,6 +187,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase parameters = new ArrayList( method.getContextParameters() ); Type returnType; // there's only one case for forging a method with mapping options: nested target properties. - // they should always forge an update method - if ( method.isUpdateMethod() || forgeMethodWithMappingOptions != null ) { + // They should forge an update method only if we set the forceUpdateMethod. This is set to true, + // because we are forging a Mapping for a method with multiple source parameters. + if ( method.isUpdateMethod() || forceUpdateMethod ) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java index 8d05cc6526..b7e9f94e3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java @@ -19,6 +19,7 @@ package org.mapstruct.ap.test.nestedtargetproperties; import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; @@ -36,6 +37,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @@ -62,6 +64,13 @@ @RunWith(AnnotationProcessorTestRunner.class) public class NestedTargetPropertiesTest { + @Rule + public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + ChartEntryToArtist.class, + ChartEntryToArtistUpdate.class, + FishTankMapper.class + ); + @Test public void shouldMapNestedTarget() { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java new file mode 100644 index 0000000000..2e030f22bb --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -0,0 +1,338 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties; + +import java.util.List; +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; +import org.mapstruct.ap.test.nestedsourceproperties.source.Artist; +import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; +import org.mapstruct.ap.test.nestedsourceproperties.source.Label; +import org.mapstruct.ap.test.nestedsourceproperties.source.Song; +import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-07T21:05:06+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class ChartEntryToArtistImpl extends ChartEntryToArtist { + + @Override + public Chart map(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Chart chart = new Chart(); + + chart.setSong( chartEntryToSong( chartEntry ) ); + chart.setName( chartEntry.getChartName() ); + + return chart; + } + + @Override + public Chart map(ChartEntry chartEntry1, ChartEntry chartEntry2) { + if ( chartEntry1 == null && chartEntry2 == null ) { + return null; + } + + Chart chart = new Chart(); + + if ( chartEntry1 != null ) { + if ( chart.getSong() == null ) { + chart.setSong( new Song() ); + } + chartEntryToSong1( chartEntry1, chart.getSong() ); + } + if ( chartEntry2 != null ) { + if ( chart.getSong() == null ) { + chart.setSong( new Song() ); + } + chartEntryToSong2( chartEntry2, chart.getSong() ); + chart.setName( chartEntry2.getChartName() ); + } + + return chart; + } + + @Override + public ChartEntry map(Chart chart) { + if ( chart == null ) { + return null; + } + + ChartEntry chartEntry = new ChartEntry(); + + String title = chartSongTitle( chart ); + if ( title != null ) { + chartEntry.setSongTitle( title ); + } + chartEntry.setChartName( chart.getName() ); + String city = chartSongArtistLabelStudioCity( chart ); + if ( city != null ) { + chartEntry.setCity( city ); + } + String name = chartSongArtistLabelStudioName( chart ); + if ( name != null ) { + chartEntry.setRecordedAt( name ); + } + String name1 = chartSongArtistName( chart ); + if ( name1 != null ) { + chartEntry.setArtistName( name1 ); + } + List positions = chartSongPositions( chart ); + if ( positions != null ) { + chartEntry.setPosition( mapPosition( positions ) ); + } + + return chartEntry; + } + + protected Studio chartEntryToStudio(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Studio studio = new Studio(); + + studio.setCity( chartEntry.getCity() ); + studio.setName( chartEntry.getRecordedAt() ); + + return studio; + } + + protected Label chartEntryToLabel(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Label label = new Label(); + + label.setStudio( chartEntryToStudio( chartEntry ) ); + + return label; + } + + protected Artist chartEntryToArtist(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Artist artist = new Artist(); + + artist.setLabel( chartEntryToLabel( chartEntry ) ); + artist.setName( chartEntry.getArtistName() ); + + return artist; + } + + protected Song chartEntryToSong(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Song song = new Song(); + + song.setArtist( chartEntryToArtist( chartEntry ) ); + List list = mapPosition( chartEntry.getPosition() ); + if ( list != null ) { + song.setPositions( list ); + } + song.setTitle( chartEntry.getSongTitle() ); + + return song; + } + + protected void chartEntryToStudio1(ChartEntry chartEntry, Studio mappingTarget) { + if ( chartEntry == null ) { + return; + } + + mappingTarget.setCity( chartEntry.getCity() ); + mappingTarget.setName( chartEntry.getRecordedAt() ); + } + + protected void chartEntryToLabel1(ChartEntry chartEntry, Label mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getStudio() == null ) { + mappingTarget.setStudio( new Studio() ); + } + chartEntryToStudio1( chartEntry, mappingTarget.getStudio() ); + } + + protected void chartEntryToArtist1(ChartEntry chartEntry, Artist mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getLabel() == null ) { + mappingTarget.setLabel( new Label() ); + } + chartEntryToLabel1( chartEntry, mappingTarget.getLabel() ); + mappingTarget.setName( chartEntry.getArtistName() ); + } + + protected void chartEntryToSong1(ChartEntry chartEntry, Song mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getArtist() == null ) { + mappingTarget.setArtist( new Artist() ); + } + chartEntryToArtist1( chartEntry, mappingTarget.getArtist() ); + mappingTarget.setTitle( chartEntry.getSongTitle() ); + } + + protected void chartEntryToSong2(ChartEntry chartEntry, Song mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getPositions() != null ) { + List list = mapPosition( chartEntry.getPosition() ); + if ( list != null ) { + mappingTarget.getPositions().clear(); + mappingTarget.getPositions().addAll( list ); + } + else { + mappingTarget.setPositions( null ); + } + } + else { + List list = mapPosition( chartEntry.getPosition() ); + if ( list != null ) { + mappingTarget.setPositions( list ); + } + } + } + + private String chartSongTitle(Chart chart) { + + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + String title = song.getTitle(); + if ( title == null ) { + return null; + } + return title; + } + + private String chartSongArtistLabelStudioCity(Chart chart) { + + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; + } + + private String chartSongArtistLabelStudioName(Chart chart) { + + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String name = studio.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String chartSongArtistName(Chart chart) { + + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + String name = artist.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private List chartSongPositions(Chart chart) { + + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + List positions = song.getPositions(); + if ( positions == null ) { + return null; + } + return positions; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java new file mode 100644 index 0000000000..990bf30c93 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java @@ -0,0 +1,116 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties; + +import java.util.List; +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; +import org.mapstruct.ap.test.nestedsourceproperties.source.Artist; +import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; +import org.mapstruct.ap.test.nestedsourceproperties.source.Label; +import org.mapstruct.ap.test.nestedsourceproperties.source.Song; +import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-07T21:05:06+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class ChartEntryToArtistUpdateImpl extends ChartEntryToArtistUpdate { + + @Override + public void map(ChartEntry chartEntry, Chart chart) { + if ( chartEntry == null ) { + return; + } + + if ( chart.getSong() == null ) { + chart.setSong( new Song() ); + } + chartEntryToSong( chartEntry, chart.getSong() ); + if ( chartEntry.getChartName() != null ) { + chart.setName( chartEntry.getChartName() ); + } + } + + protected void chartEntryToStudio(ChartEntry chartEntry, Studio mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( chartEntry.getCity() != null ) { + mappingTarget.setCity( chartEntry.getCity() ); + } + if ( chartEntry.getRecordedAt() != null ) { + mappingTarget.setName( chartEntry.getRecordedAt() ); + } + } + + protected void chartEntryToLabel(ChartEntry chartEntry, Label mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getStudio() == null ) { + mappingTarget.setStudio( new Studio() ); + } + chartEntryToStudio( chartEntry, mappingTarget.getStudio() ); + } + + protected void chartEntryToArtist(ChartEntry chartEntry, Artist mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getLabel() == null ) { + mappingTarget.setLabel( new Label() ); + } + chartEntryToLabel( chartEntry, mappingTarget.getLabel() ); + if ( chartEntry.getArtistName() != null ) { + mappingTarget.setName( chartEntry.getArtistName() ); + } + } + + protected void chartEntryToSong(ChartEntry chartEntry, Song mappingTarget) { + if ( chartEntry == null ) { + return; + } + + if ( mappingTarget.getArtist() == null ) { + mappingTarget.setArtist( new Artist() ); + } + chartEntryToArtist( chartEntry, mappingTarget.getArtist() ); + if ( mappingTarget.getPositions() != null ) { + List list = mapPosition( chartEntry.getPosition() ); + if ( list != null ) { + mappingTarget.getPositions().clear(); + mappingTarget.getPositions().addAll( list ); + } + } + else { + List list = mapPosition( chartEntry.getPosition() ); + if ( list != null ) { + mappingTarget.setPositions( list ); + } + } + if ( chartEntry.getSongTitle() != null ) { + mappingTarget.setTitle( chartEntry.getSongTitle() ); + } + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java new file mode 100644 index 0000000000..8632961c59 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java @@ -0,0 +1,92 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedtargetproperties; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedtargetproperties._target.FishDto; +import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; +import org.mapstruct.ap.test.nestedtargetproperties._target.WaterPlantDto; +import org.mapstruct.ap.test.nestedtargetproperties.source.Fish; +import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; +import org.mapstruct.ap.test.nestedtargetproperties.source.WaterPlant; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-07T21:05:06+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class FishTankMapperImpl implements FishTankMapper { + + @Override + public FishTankDto map(FishTank source) { + if ( source == null ) { + return null; + } + + FishTankDto fishTankDto = new FishTankDto(); + + fishTankDto.setFish( fishTankToFishDto( source ) ); + fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); + + return fishTankDto; + } + + private String fishTankFishType(FishTank fishTank) { + + if ( fishTank == null ) { + return null; + } + Fish fish = fishTank.getFish(); + if ( fish == null ) { + return null; + } + String type = fish.getType(); + if ( type == null ) { + return null; + } + return type; + } + + protected FishDto fishTankToFishDto(FishTank fishTank) { + if ( fishTank == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + String type = fishTankFishType( fishTank ); + if ( type != null ) { + fishDto.setKind( type ); + } + + return fishDto; + } + + protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { + if ( waterPlant == null ) { + return null; + } + + WaterPlantDto waterPlantDto = new WaterPlantDto(); + + waterPlantDto.setKind( waterPlant.getKind() ); + + return waterPlantDto; + } +} From 5564c53f414a13a59fe9e6f5c3d8b2ca35b89982 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sat, 4 Feb 2017 21:39:36 +0100 Subject: [PATCH 0048/1006] #1056 Making sure indentation level in formatting writer never goes below 0 --- .../writer/IndentationCorrectingWriter.java | 36 +++++++++---- .../MapperWithMalformedExpression.java | 29 ++++++++++ .../MisbalancedBracesTest.java | 54 +++++++++++++++++++ .../erroneous/misbalancedbraces/Source.java | 25 +++++++++ .../erroneous/misbalancedbraces/Target.java | 25 +++++++++ .../annotation/DisableCheckstyle.java | 34 ++++++++++++ .../testutil/runner/CompilingStatement.java | 7 ++- 7 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java index c99b96af81..0ff950dc1b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java @@ -117,11 +117,11 @@ State doHandleCharacter(char c, StateContext context) { switch ( c ) { case '{': case '(': - context.indentationLevel++; + context.incrementIndentationLevel(); return IN_TEXT; case '}': case ')': - context.indentationLevel--; + context.decrementIndentationLevel(); return IN_TEXT; case '\"': return IN_STRING; @@ -139,10 +139,11 @@ State doHandleCharacter(char c, StateContext context) { */ @Override void doOnEntry(StateContext context) throws IOException { - context.writer.write( getIndentation( context.indentationLevel ) ); + context.writer.write( getIndentation( context.getIndentationLevel() ) ); if ( DEBUG ) { - System.out.print( new String( getIndentation( context.indentationLevel ) ).replace( " ", "_" ) ); + System.out.print( new String( getIndentation( context.getIndentationLevel() ) ) + .replace( " ", "_" ) ); } } @@ -173,11 +174,11 @@ State doHandleCharacter(char c, StateContext context) { switch ( c ) { case '{': case '(': - context.indentationLevel++; + context.incrementIndentationLevel(); return IN_TEXT; case '}': case ')': - context.indentationLevel--; + context.decrementIndentationLevel(); return IN_TEXT; case '\"': return IN_STRING; @@ -298,14 +299,14 @@ State doHandleCharacter(char c, StateContext context) { switch ( c ) { case '{': case '(': - context.indentationLevel++; + context.incrementIndentationLevel(); return START_OF_LINE; case '}': if ( context.consecutiveLineBreaks > 0 ) { context.consecutiveLineBreaks = 0; // remove previous blank lines } case ')': - context.indentationLevel--; + context.decrementIndentationLevel(); return START_OF_LINE; case '\r': return isWindows() ? IN_LINE_BREAK : AFTER_LINE_BREAK; @@ -407,7 +408,7 @@ private static class StateContext { /** * Keeps track of the current indentation level, as implied by brace characters. */ - int indentationLevel; + private int indentationLevel; /** * The number of consecutive line-breaks when within {@link State#AFTER_LINE_BREAK}. @@ -423,5 +424,22 @@ void reset(char[] characters, int off) { this.lastStateChange = off; this.currentIndex = 0; } + + void incrementIndentationLevel() { + indentationLevel++; + } + + void decrementIndentationLevel() { + // decrementing below 0 indicates misbalanced braces in the code, typically because too many closing braces + // are given in an expression; we let that code pass through, the compiler will complain eventually about + // the malformed source file + if ( indentationLevel > 0 ) { + indentationLevel--; + } + } + + int getIndentationLevel() { + return indentationLevel; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java new file mode 100644 index 0000000000..7fb159871f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.erroneous.misbalancedbraces; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface MapperWithMalformedExpression { + + @Mapping(target = "foo", expression = "java( Boolean.valueOf( source.foo > 0 ) ) )") + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java new file mode 100644 index 0000000000..97353ad811 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java @@ -0,0 +1,54 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.erroneous.misbalancedbraces; + +import javax.tools.Diagnostic.Kind; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Test for making sure that expressions with too many closing braces are passed through, letting the compiler raise an + * error. + * + * @author Gunnar Morling + */ +@WithClasses({ MapperWithMalformedExpression.class, Source.class, Target.class }) +@DisableCheckstyle +@RunWith(AnnotationProcessorTestRunner.class) +public class MisbalancedBracesTest { + + // the compiler messages due to the additional closing brace differ between JDK and Eclipse, hence we can only + // assert on the line number but not the message + @Test + @IssueKey("1056") + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { @Diagnostic(kind = Kind.ERROR, line = 20) } + ) + public void expressionWithMisbalancedBracesIsPassedThrough() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java new file mode 100644 index 0000000000..be8bcbbac0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.erroneous.misbalancedbraces; + +public class Source { + + //CHECKSTYLE:OFF + public int foo; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java new file mode 100644 index 0000000000..d7fc738177 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.erroneous.misbalancedbraces; + +public class Target { + + //CHECKSTYLE:OFF + public boolean foo; +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java new file mode 100644 index 0000000000..ee21d45886 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.testutil.compilation.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Disables CheckStyle for the sources generated by this test. + * + * @author Gunnar Morling + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface DisableCheckstyle { +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index fc536bf984..95b4a91e4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -43,6 +43,7 @@ import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithServiceImplementations; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions; @@ -78,6 +79,7 @@ abstract class CompilingStatement extends Statement { private final FrameworkMethod method; private final CompilationCache compilationCache; + private final boolean runCheckstyle; private Statement next; private String classOutputDir; @@ -88,6 +90,7 @@ abstract class CompilingStatement extends Statement { CompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { this.method = method; this.compilationCache = compilationCache; + this.runCheckstyle = !method.getMethod().getDeclaringClass().isAnnotationPresent( DisableCheckstyle.class ); this.compilationRequest = new CompilationRequest( getTestClasses(), getServices(), getProcessorOptions() ); } @@ -202,7 +205,9 @@ protected void generateMapperImplementation() throws Exception { assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() ); - assertCheckstyleRules(); + if ( runCheckstyle ) { + assertCheckstyleRules(); + } } private void assertCheckstyleRules() throws Exception { From 106214cb9f3363075778d51964518953c5a4de5e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Feb 2017 22:52:02 +0100 Subject: [PATCH 0049/1006] #1011 extract the generation of the nested target properties mappings into a separate class --- .../ap/internal/model/BeanMappingMethod.java | 40 ++---- .../NestedTargetPropertyMappingHolder.java | 126 ++++++++++++++++++ 2 files changed, 134 insertions(+), 32 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 6584f26121..be2d17d040 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -46,7 +46,6 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Mapping; -import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -298,38 +297,15 @@ else if ( reportErrorOnTargetObject( mapping ) ) { private void handleDefinedNestedTargetMapping(Set handledTargets) { - Map optionsByNestedTarget = - method.getMappingOptions().groupByPoppedTargetReferences(); - for ( Entry entryByTP : optionsByNestedTarget.entrySet() ) { + NestedTargetPropertyMappingHolder holder = new NestedTargetPropertyMappingHolder.Builder() + .mappingContext( ctx ) + .method( method ) + .existingVariableNames( existingVariableNames ) + .build(); - Map optionsBySourceParam = entryByTP.getValue().groupBySourceParameter(); - boolean forceUpdateMethod = optionsBySourceParam.keySet().size() > 1; - for ( Entry entryByParam : optionsBySourceParam.entrySet() ) { - - SourceReference sourceRef = new SourceReference.BuilderFromProperty() - .sourceParameter( entryByParam.getKey() ) - .name( entryByTP.getKey().getName() ) - .build(); - - PropertyMapping propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .targetProperty( entryByTP.getKey() ) - .targetPropertyName( entryByTP.getKey().getName() ) - .sourceReference( sourceRef ) - .existingVariableNames( existingVariableNames ) - .dependsOn( entryByParam.getValue().collectNestedDependsOn() ) - .forgeMethodWithMappingOptions( entryByParam.getValue() ) - .forceUpdateMethod( forceUpdateMethod ) - .build(); - unprocessedSourceParameters.remove( sourceRef.getParameter() ); - - if ( propertyMapping != null ) { - propertyMappings.add( propertyMapping ); - } - } - handledTargets.add( entryByTP.getKey().getName() ); - } + unprocessedSourceParameters.removeAll( holder.getProcessedSourceParameters() ); + propertyMappings.addAll( holder.getPropertyMappings() ); + handledTargets.addAll( holder.getHandledTargets() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java new file mode 100644 index 0000000000..d2542dd4a1 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -0,0 +1,126 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.PropertyEntry; +import org.mapstruct.ap.internal.model.source.SourceReference; + +/** + * This is a helper class that holds the generated {@link PropertyMapping}(s) and all the information associated with + * it for nested target properties. + * + * @author Filip Hrisafov + */ +public class NestedTargetPropertyMappingHolder { + + private final List processedSourceParameters; + private final Set handledTargets; + private final List propertyMappings; + + public NestedTargetPropertyMappingHolder( + List processedSourceParameters, Set handledTargets, + List propertyMappings) { + this.processedSourceParameters = processedSourceParameters; + this.handledTargets = handledTargets; + this.propertyMappings = propertyMappings; + } + + public List getProcessedSourceParameters() { + return processedSourceParameters; + } + + public Set getHandledTargets() { + return handledTargets; + } + + public List getPropertyMappings() { + return propertyMappings; + } + + public static class Builder { + + private Method method; + private MappingBuilderContext mappingContext; + private Set existingVariableNames; + + public Builder method(Method method) { + this.method = method; + return this; + } + + public Builder mappingContext(MappingBuilderContext mappingContext) { + this.mappingContext = mappingContext; + return this; + } + + public Builder existingVariableNames(Set existingVariableNames) { + this.existingVariableNames = existingVariableNames; + return this; + } + + public NestedTargetPropertyMappingHolder build() { + List processedSourceParameters = new ArrayList(); + Set handledTargets = new HashSet(); + List propertyMappings = new ArrayList(); + + Map optionsByNestedTarget = + method.getMappingOptions().groupByPoppedTargetReferences(); + for ( Map.Entry entryByTP : optionsByNestedTarget.entrySet() ) { + + Map optionsBySourceParam = entryByTP.getValue().groupBySourceParameter(); + boolean forceUpdateMethod = optionsBySourceParam.keySet().size() > 1; + for ( Map.Entry entryByParam : optionsBySourceParam.entrySet() ) { + + SourceReference sourceRef = new SourceReference.BuilderFromProperty() + .sourceParameter( entryByParam.getKey() ) + .name( entryByTP.getKey().getName() ) + .build(); + + PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() + .mappingContext( mappingContext ) + .sourceMethod( method ) + .targetProperty( entryByTP.getKey() ) + .targetPropertyName( entryByTP.getKey().getName() ) + .sourceReference( sourceRef ) + .existingVariableNames( existingVariableNames ) + .dependsOn( entryByParam.getValue().collectNestedDependsOn() ) + .forgeMethodWithMappingOptions( entryByParam.getValue() ) + .forceUpdateMethod( forceUpdateMethod ) + .build(); + processedSourceParameters.add( sourceRef.getParameter() ); + + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); + } + } + handledTargets.add( entryByTP.getKey().getName() ); + } + return new NestedTargetPropertyMappingHolder( processedSourceParameters, handledTargets, propertyMappings ); + } + } +} From c751100272693fa89a5b1cc9936d593561d4811e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Feb 2017 23:20:25 +0100 Subject: [PATCH 0050/1006] #1011 extract the grouping of the nested target properties out of the MappingOptions into its own class --- .../NestedTargetPropertyMappingHolder.java | 112 ++++++++++++++++-- .../internal/model/source/MappingOptions.java | 95 --------------- 2 files changed, 104 insertions(+), 103 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index d2542dd4a1..0ae6e9afe8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -19,17 +19,21 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.source.Mapping; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SourceReference; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * This is a helper class that holds the generated {@link PropertyMapping}(s) and all the information associated with * it for nested target properties. @@ -50,14 +54,25 @@ public NestedTargetPropertyMappingHolder( this.propertyMappings = propertyMappings; } + /** + * @return The source parameters that were processed during the generation of the property mappings + */ public List getProcessedSourceParameters() { return processedSourceParameters; } + /** + * + * @return all the targets that were hanled + */ public Set getHandledTargets() { return handledTargets; } + /** + * + * @return the generated property mappings + */ public List getPropertyMappings() { return propertyMappings; } @@ -88,18 +103,20 @@ public NestedTargetPropertyMappingHolder build() { Set handledTargets = new HashSet(); List propertyMappings = new ArrayList(); - Map optionsByNestedTarget = - method.getMappingOptions().groupByPoppedTargetReferences(); - for ( Map.Entry entryByTP : optionsByNestedTarget.entrySet() ) { + Map> groupedByTP = groupByPoppedTargetReferences( method.getMappingOptions() ); - Map optionsBySourceParam = entryByTP.getValue().groupBySourceParameter(); - boolean forceUpdateMethod = optionsBySourceParam.keySet().size() > 1; - for ( Map.Entry entryByParam : optionsBySourceParam.entrySet() ) { + for ( Map.Entry> entryByTP : groupedByTP.entrySet() ) { + Map> groupedBySourceParam = groupBySourceParameter( entryByTP.getValue() ); + boolean forceUpdateMethod = groupedBySourceParam.keySet().size() > 1; + for ( Map.Entry> entryByParam : groupedBySourceParam.entrySet() ) { SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( entryByParam.getKey() ) .name( entryByTP.getKey().getName() ) .build(); + MappingOptions mappingOptions = MappingOptions.forMappingsOnly( + groupByTargetName( entryByParam.getValue() ) + ); PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() .mappingContext( mappingContext ) @@ -108,8 +125,8 @@ public NestedTargetPropertyMappingHolder build() { .targetPropertyName( entryByTP.getKey().getName() ) .sourceReference( sourceRef ) .existingVariableNames( existingVariableNames ) - .dependsOn( entryByParam.getValue().collectNestedDependsOn() ) - .forgeMethodWithMappingOptions( entryByParam.getValue() ) + .dependsOn( mappingOptions.collectNestedDependsOn() ) + .forgeMethodWithMappingOptions( mappingOptions ) .forceUpdateMethod( forceUpdateMethod ) .build(); processedSourceParameters.add( sourceRef.getParameter() ); @@ -120,7 +137,86 @@ public NestedTargetPropertyMappingHolder build() { } handledTargets.add( entryByTP.getKey().getName() ); } + return new NestedTargetPropertyMappingHolder( processedSourceParameters, handledTargets, propertyMappings ); } + + /** + * The target references are popped. The {@code List<}{@link Mapping}{@code >} are keyed on the unique first + * entries of the target references. + * + * So, take + * + * targetReference 1: propertyEntryX.propertyEntryX1.propertyEntryX1a + * targetReference 2: propertyEntryX.propertyEntryX2 + * targetReference 3: propertyEntryY.propertyY1 + * targetReference 4: propertyEntryZ + * + * will be popped and grouped into entries: + * + * propertyEntryX - List ( targetReference1: propertyEntryX1.propertyEntryX1a, + * targetReference2: propertyEntryX2 ) + * propertyEntryY - List ( targetReference1: propertyEntryY1 ) + * + * The key will be the former top level property, the MappingOptions will contain the remainders. + * + * So, 2 cloned new MappingOptions with popped targetReferences. Also Note that the not nested targetReference4 + * disappeared. + * + * @return See above + */ + public Map> groupByPoppedTargetReferences(MappingOptions mappingOptions) { + Map> mappings = mappingOptions.getMappings(); + // group all mappings based on the top level name before popping + Map> mappingsKeyedByProperty = new HashMap>(); + for ( List mapping : mappings.values() ) { + Mapping newMapping = first( mapping ).popTargetReference(); + if ( newMapping != null ) { + // group properties on current name. + PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); + if ( !mappingsKeyedByProperty.containsKey( property ) ) { + mappingsKeyedByProperty.put( property, new ArrayList() ); + } + mappingsKeyedByProperty.get( property ).add( newMapping ); + } + } + + return mappingsKeyedByProperty; + } + + /** + * Splits the List of Mappings into possibly more Mappings based on each source method parameter type. + * + * Note: this method is used for forging nested update methods. For that purpose, the same method with all + * joined mappings should be generated. See also: NestedTargetPropertiesTest#shouldMapNestedComposedTarget + * + * @return the split mapping options. + */ + public Map> groupBySourceParameter(List mappings) { + + Map> mappingsKeyedByParameter = new HashMap>(); + for ( Mapping mapping : mappings ) { + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { + Parameter parameter = mapping.getSourceReference().getParameter(); + if ( !mappingsKeyedByParameter.containsKey( parameter ) ) { + mappingsKeyedByParameter.put( parameter, new ArrayList() ); + } + mappingsKeyedByParameter.get( parameter ).add( mapping ); + } + } + + return mappingsKeyedByParameter; + } + + private Map> groupByTargetName(List mappingList) { + Map> result = new HashMap>(); + for ( Mapping mapping : mappingList ) { + if ( !result.containsKey( mapping.getTargetName() ) ) { + result.put( mapping.getTargetName(), new ArrayList() ); + } + result.get( mapping.getTargetName() ).add( mapping ); + } + return result; + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 91412342d7..707f08ed28 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -21,7 +21,6 @@ import static org.mapstruct.ap.internal.util.Collections.first; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -86,58 +85,6 @@ public Map> getMappings() { return mappings; } - /** - * The target references are popped. The MappingOptions are keyed on the unique first entries of the - * target references. - * - * So, take - * - * targetReference 1: propertyEntryX.propertyEntryX1.propertyEntryX1a - * targetReference 2: propertyEntryX.propertyEntryX2 - * targetReference 3: propertyEntryY.propertyY1 - * targetReference 4: propertyEntryZ - * - * will be popped and grouped into entries: - * - * propertyEntryX - MappingOptions ( targetReference1: propertyEntryX1.propertyEntryX1a, - * targetReference2: propertyEntryX2 ) - * propertyEntryY - MappingOptions ( targetReference1: propertyEntryY1 ) - * - * The key will be the former top level property, the MappingOptions will contain the remainders. - * - * So, 2 cloned new MappingOptions with popped targetReferences. Also Note that the not nested targetReference4 - * disappeared. - * - * @return See above - */ - public Map groupByPoppedTargetReferences() { - - // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty = new HashMap>(); - for ( List mapping : mappings.values() ) { - Mapping newMapping = first( mapping ).popTargetReference(); - if ( newMapping != null ) { - // group properties on current name. - PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); - if ( !mappingsKeyedByProperty.containsKey( property ) ) { - mappingsKeyedByProperty.put( property, new ArrayList() ); - } - mappingsKeyedByProperty.get( property ).add( newMapping ); - } - } - - // now group them into mapping options - Map result = new HashMap(); - for ( Map.Entry> mappingKeyedByProperty : mappingsKeyedByProperty.entrySet() ) { - Map> newEntries = new HashMap>(); - for ( Mapping newEntry : mappingKeyedByProperty.getValue() ) { - newEntries.put( newEntry.getTargetName(), Arrays.asList( newEntry ) ); - } - result.put( mappingKeyedByProperty.getKey(), forMappingsOnly( newEntries ) ); - } - return result; - } - /** * Check there are nested target references for this mapping options. * @@ -170,48 +117,6 @@ public List collectNestedDependsOn() { return nestedDependsOn; } - /** - * Splits the MappingOptions into possibly more MappingOptions based on each source method parameter type. - * - * Note: this method is used for forging nested update methods. For that purpose, the same method with all - * joined mappings should be generated. See also: NestedTargetPropertiesTest#shouldMapNestedComposedTarget - * - * @return the split mapping options. - * - */ - public Map groupBySourceParameter() { - - Map> mappingsKeyedByParameterType = new HashMap>(); - for ( List mappingList : mappings.values() ) { - for ( Mapping mapping : mappingList ) { - if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { - Parameter parameter = mapping.getSourceReference().getParameter(); - if ( !mappingsKeyedByParameterType.containsKey( parameter ) ) { - mappingsKeyedByParameterType.put( parameter, new ArrayList() ); - } - mappingsKeyedByParameterType.get( parameter ).add( mapping ); - } - } - } - - Map result = new HashMap(); - for ( Map.Entry> entry : mappingsKeyedByParameterType.entrySet() ) { - result.put( entry.getKey(), MappingOptions.forMappingsOnly( groupByTargetName( entry.getValue() ) ) ); - } - return result; - } - - private Map> groupByTargetName( List mappingList ) { - Map> result = new HashMap>(); - for ( Mapping mapping : mappingList ) { - if ( !result.containsKey( mapping.getTargetName() ) ) { - result.put( mapping.getTargetName(), new ArrayList() ); - } - result.get( mapping.getTargetName() ).add( mapping ); - } - return result; - } - /** * Initializes the underlying mappings with a new property. Specifically used in in combination with forged methods * where the new parameter name needs to be established at a later moment. From 8d8d1c37f208c056f4a234155bc226229d9b0ac3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 16 Feb 2017 22:25:40 +0100 Subject: [PATCH 0051/1006] Use static instance instead of always initialising the empty MappingOptions --- .../ap/internal/model/source/MappingOptions.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 707f08ed28..232fc1001c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -38,6 +38,13 @@ * @author Andreas Gudian */ public class MappingOptions { + private static final MappingOptions EMPTY = new MappingOptions( Collections.>emptyMap(), + null, + null, + null, + Collections.emptyList(), + false + ); private Map> mappings; private IterableMapping iterableMapping; private MapMapping mapMapping; @@ -62,8 +69,7 @@ public MappingOptions(Map> mappings, IterableMapping itera * @return empty mapping options */ public static MappingOptions empty() { - return new MappingOptions( Collections.>emptyMap(), null, null, null, - Collections.emptyList(), false ); + return EMPTY; } /** From af8e70d84c585ab006326e6ee2ad12f6b9698031 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 12 Feb 2017 21:40:26 +0100 Subject: [PATCH 0052/1006] Javadoc cleanup --- .../java/org/mapstruct/ap/internal/util/RoundContext.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java index 23182100e8..c06a335440 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -46,6 +46,7 @@ public AnnotationProcessorContext getAnnotationProcessorContext() { /** * Marks the given type as being ready for further processing. + * @param type the type that is ready for further processing by MapStruct */ public void addTypeReadyForProcessing(TypeMirror type) { clearedTypes.add( type ); @@ -56,6 +57,9 @@ public void addTypeReadyForProcessing(TypeMirror type) { * hierarchy is complete (no super-types need to be generated by other processors) an no processors have signaled * the intention to amend the given type. * + * @param type the typed to be checked for its readiness + * @return true when the type is ready to be processed by MapStruct + * * @see AstModifyingAnnotationProcessor */ public boolean isReadyForProcessing(TypeMirror type) { From 9899504db9d83346852b70088cb74a61d1456b2e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 17 Feb 2017 21:11:39 +0100 Subject: [PATCH 0053/1006] #1073 Change NestedPropertyMappingMethod to not use name in its equality, but to use the Safe Properties --- .../model/NestedPropertyMappingMethod.java | 39 +++- .../NestedSourcePropertiesTest.java | 6 + .../ArtistToChartEntryImpl.java | 170 ++++++++++++++++++ 3 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 3bacd1b406..91e240ee18 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -118,9 +118,10 @@ public boolean equals( Object obj ) { if ( getClass() != obj.getClass() ) { return false; } + NestedPropertyMappingMethod other = (NestedPropertyMappingMethod) obj; - if ( !getReturnType().equals( other.getReturnType() ) ) { + if ( !super.equals( obj ) ) { return false; } @@ -134,7 +135,7 @@ public boolean equals( Object obj ) { } } - if ( !getName().equals( other.getName() ) ) { + if ( !safePropertyEntries.equals( other.safePropertyEntries ) ) { return false; } @@ -176,6 +177,40 @@ public Type getType() { return type; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !( o instanceof SafePropertyEntry ) ) { + return false; + } + + SafePropertyEntry that = (SafePropertyEntry) o; + + if ( readAccessorName != null ? !readAccessorName.equals( that.readAccessorName ) : + that.readAccessorName != null ) { + return false; + } + + if ( presenceCheckerName != null ? !presenceCheckerName.equals( that.presenceCheckerName ) : + that.presenceCheckerName != null ) { + return false; + } + + if ( type != null ? !type.equals( that.type ) : that.type != null ) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = readAccessorName != null ? readAccessorName.hashCode() : 0; + result = 31 * result + ( presenceCheckerName != null ? presenceCheckerName.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + return result; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index e594b7c6eb..2fed7b0fd0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -24,6 +24,7 @@ import java.util.Arrays; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedsourceproperties._target.AdderUsageObserver; @@ -40,6 +41,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Sjaak Derksen @@ -49,9 +51,13 @@ @RunWith(AnnotationProcessorTestRunner.class) public class NestedSourcePropertiesTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + @Test @WithClasses({ ArtistToChartEntry.class }) public void shouldGenerateImplementationForPropertyNamesOnly() { + generatedSource.addComparisonToFixtureFor( ArtistToChartEntry.class ); Studio studio = new Studio(); studio.setName( "Abbey Road" ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java new file mode 100644 index 0000000000..486fdd6fe9 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -0,0 +1,170 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsourceproperties; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; +import org.mapstruct.ap.test.nestedsourceproperties.source.Artist; +import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; +import org.mapstruct.ap.test.nestedsourceproperties.source.Label; +import org.mapstruct.ap.test.nestedsourceproperties.source.Song; +import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-17T20:44:15+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class ArtistToChartEntryImpl implements ArtistToChartEntry { + + @Override + public ChartEntry map(Chart chart, Song song, Integer position) { + if ( chart == null && song == null && position == null ) { + return null; + } + + ChartEntry chartEntry = new ChartEntry(); + + if ( chart != null ) { + chartEntry.setChartName( chart.getName() ); + } + if ( song != null ) { + chartEntry.setSongTitle( song.getTitle() ); + String city = songArtistLabelStudioCity( song ); + if ( city != null ) { + chartEntry.setCity( city ); + } + String name = songArtistLabelStudioName( song ); + if ( name != null ) { + chartEntry.setRecordedAt( name ); + } + String name1 = songArtistName( song ); + if ( name1 != null ) { + chartEntry.setArtistName( name1 ); + } + } + if ( position != null ) { + chartEntry.setPosition( position ); + } + + return chartEntry; + } + + @Override + public ChartEntry map(Song song) { + if ( song == null ) { + return null; + } + + ChartEntry chartEntry = new ChartEntry(); + + chartEntry.setSongTitle( song.getTitle() ); + String city = songArtistLabelStudioCity( song ); + if ( city != null ) { + chartEntry.setCity( city ); + } + String name = songArtistLabelStudioName( song ); + if ( name != null ) { + chartEntry.setRecordedAt( name ); + } + String name1 = songArtistName( song ); + if ( name1 != null ) { + chartEntry.setArtistName( name1 ); + } + + return chartEntry; + } + + @Override + public ChartEntry map(Chart name) { + if ( name == null ) { + return null; + } + + ChartEntry chartEntry = new ChartEntry(); + + chartEntry.setChartName( name.getName() ); + + return chartEntry; + } + + private String songArtistLabelStudioCity(Song song) { + + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; + } + + private String songArtistLabelStudioName(Song song) { + + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String name = studio.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String songArtistName(Song song) { + + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + String name = artist.getName(); + if ( name == null ) { + return null; + } + return name; + } +} From 8dbcc43a8edcf6429618c9c2928eb5e7090979ea Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Feb 2017 15:53:34 +0100 Subject: [PATCH 0054/1006] #1082 Do not generate an empty line after method start for NestedPropertyMappingMethod --- .../ap/internal/model/NestedPropertyMappingMethod.ftl | 1 - .../test/nestedsourceproperties/ArtistToChartEntryImpl.java | 3 --- .../test/nestedtargetproperties/ChartEntryToArtistImpl.java | 5 ----- .../ap/test/nestedtargetproperties/FishTankMapperImpl.java | 1 - 4 files changed, 10 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 917182f20e..5921682ebc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -19,7 +19,6 @@ --> <#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { - if ( ${sourceParameter.name} == null ) { return ${returnType.null}; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java index 486fdd6fe9..ca3a27297e 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -105,7 +105,6 @@ public ChartEntry map(Chart name) { } private String songArtistLabelStudioCity(Song song) { - if ( song == null ) { return null; } @@ -129,7 +128,6 @@ private String songArtistLabelStudioCity(Song song) { } private String songArtistLabelStudioName(Song song) { - if ( song == null ) { return null; } @@ -153,7 +151,6 @@ private String songArtistLabelStudioName(Song song) { } private String songArtistName(Song song) { - if ( song == null ) { return null; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index 2e030f22bb..181bb89bea 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -229,7 +229,6 @@ protected void chartEntryToSong2(ChartEntry chartEntry, Song mappingTarget) { } private String chartSongTitle(Chart chart) { - if ( chart == null ) { return null; } @@ -245,7 +244,6 @@ private String chartSongTitle(Chart chart) { } private String chartSongArtistLabelStudioCity(Chart chart) { - if ( chart == null ) { return null; } @@ -273,7 +271,6 @@ private String chartSongArtistLabelStudioCity(Chart chart) { } private String chartSongArtistLabelStudioName(Chart chart) { - if ( chart == null ) { return null; } @@ -301,7 +298,6 @@ private String chartSongArtistLabelStudioName(Chart chart) { } private String chartSongArtistName(Chart chart) { - if ( chart == null ) { return null; } @@ -321,7 +317,6 @@ private String chartSongArtistName(Chart chart) { } private List chartSongPositions(Chart chart) { - if ( chart == null ) { return null; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java index 8632961c59..12e5062e96 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java @@ -48,7 +48,6 @@ public FishTankDto map(FishTank source) { } private String fishTankFishType(FishTank fishTank) { - if ( fishTank == null ) { return null; } From bdbee40dcfbce8acb04f11bf70e268cfdb7568f1 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Fri, 10 Feb 2017 22:21:07 +0100 Subject: [PATCH 0055/1006] #1057 Add reproducer tests --- .../mixed/AutomappingAndNestedTest.java | 281 ++++++++++++++ .../nestedbeans/mixed/FishTankMapper.java | 59 +++ .../mixed/FishTankMapperConstant.java | 47 +++ .../mixed/FishTankMapperExpression.java | 47 +++ .../mixed/FishTankMapperWithDocument.java | 48 +++ .../mixed}/_target/FishDto.java | 2 +- .../mixed/_target/FishTankDto.java | 82 ++++ .../FishTankWithNestedDocumentDto.java | 82 ++++ .../mixed/_target/MaterialDto.java | 46 +++ .../mixed/_target/MaterialTypeDto.java} | 23 +- .../mixed/_target/OrnamentDto.java} | 23 +- .../mixed}/_target/WaterPlantDto.java | 2 +- .../mixed/_target/WaterQualityDto.java | 37 ++ .../_target/WaterQualityOrganisationDto.java} | 31 +- .../mixed/_target/WaterQualityReportDto.java | 46 +++ .../_target/WaterQualityWithDocumentDto.java | 37 ++ .../mixed}/source/Fish.java | 2 +- .../nestedbeans/mixed/source/FishTank.java | 82 ++++ .../nestedbeans/mixed/source/Interior.java | 45 +++ .../mixed/source/MaterialType.java | 37 ++ .../nestedbeans/mixed/source/Ornament.java | 37 ++ .../mixed}/source/WaterPlant.java | 2 +- .../mixed/source/WaterQuality.java | 37 ++ .../mixed/source/WaterQualityReport.java | 46 +++ .../NestedTargetPropertiesTest.java | 47 +-- .../mixed/FishTankMapperConstantImpl.java} | 45 +-- .../nestedbeans/mixed/FishTankMapperImpl.java | 358 ++++++++++++++++++ 27 files changed, 1505 insertions(+), 126 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties => nestedbeans/mixed}/_target/FishDto.java (95%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties/_target/FishTankDto.java => nestedbeans/mixed/_target/MaterialTypeDto.java} (67%) rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties/FishTankMapper.java => nestedbeans/mixed/_target/OrnamentDto.java} (62%) rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties => nestedbeans/mixed}/_target/WaterPlantDto.java (94%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties/source/FishTank.java => nestedbeans/mixed/_target/WaterQualityOrganisationDto.java} (72%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties => nestedbeans/mixed}/source/Fish.java (94%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java rename processor/src/test/java/org/mapstruct/ap/test/{nestedtargetproperties => nestedbeans/mixed}/source/WaterPlant.java (94%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java rename processor/src/test/resources/fixtures/org/mapstruct/ap/test/{nestedtargetproperties/FishTankMapperImpl.java => nestedbeans/mixed/FishTankMapperConstantImpl.java} (59%) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java new file mode 100644 index 0000000000..34206fdb9d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java @@ -0,0 +1,281 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankWithNestedDocumentDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialTypeDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.OrnamentDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterPlantDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityOrganisationDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityReportDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityWithDocumentDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Interior; +import org.mapstruct.ap.test.nestedbeans.mixed.source.MaterialType; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Ornament; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterPlant; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQuality; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQualityReport; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * + * @author Sjaak Derksen + */ +@WithClasses({ + FishDto.class, + FishTankDto.class, + WaterPlantDto.class, + MaterialDto.class, + MaterialTypeDto.class, + OrnamentDto.class, + WaterQualityDto.class, + WaterQualityReportDto.class, + WaterQualityOrganisationDto.class, + Fish.class, + FishTank.class, + WaterPlant.class, + MaterialType.class, + Interior.class, + Ornament.class, + WaterQuality.class, + WaterQualityReport.class, + FishTankWithNestedDocumentDto.class, + WaterQualityWithDocumentDto.class, + FishTankMapper.class, + FishTankMapperConstant.class, + FishTankMapperExpression.class, + FishTankMapperWithDocument.class +}) +@IssueKey("1057") +@RunWith(AnnotationProcessorTestRunner.class) +public class AutomappingAndNestedTest { + + @Rule + public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + FishTankMapperConstant.class + ); + + @Test + public void shouldAutomapAndHandleSourceAndTargetPropertyNesting() { + + // -- prepare + FishTank source = createFishTank(); + + // -- action + FishTankDto target = FishTankMapper.INSTANCE.map( source ); + + // -- result + assertThat( target.getName() ).isEqualTo( source.getName() ); + + // fish and fishDto can be automapped + assertThat( target.getFish() ).isNotNull(); + assertThat( target.getFish().getKind() ).isEqualTo( source.getFish().getType() ); + assertThat( target.getFish().getName() ).isNull(); + + // automapping takes care of mapping property "waterPlant". + assertThat( target.getPlant() ).isNotNull(); + assertThat( target.getPlant().getKind() ).isEqualTo( source.getPlant().getKind() ); + + // ornament (nested asymetric source) + assertThat( target.getOrnament() ).isNotNull(); + assertThat( target.getOrnament().getType() ).isEqualTo( source.getInterior().getOrnament().getType() ); + + // material (nested asymetric target) + assertThat( target.getMaterial() ).isNotNull(); + assertThat( target.getMaterial().getManufacturer() ).isNull(); + assertThat( target.getMaterial().getMaterialType() ).isNotNull(); + assertThat( target.getMaterial().getMaterialType().getType() ).isEqualTo( source.getMaterial().getType() ); + + // first symetric then asymetric + assertThat( target.getQuality() ).isNotNull(); + assertThat( target.getQuality().getReport() ).isNotNull(); + assertThat( target.getQuality().getReport().getVerdict() ) + .isEqualTo( source.getQuality().getReport().getVerdict() ); + assertThat( target.getQuality().getReport().getOrganisation().getApproval() ).isNull(); + assertThat( target.getQuality().getReport().getOrganisation() ).isNotNull(); + assertThat( target.getQuality().getReport().getOrganisation().getName() ) + .isEqualTo( source.getQuality().getReport().getOrganisationName() ); + } + + @Test + public void shouldAutomapAndHandleSourceAndTargetPropertyNestingReverse() { + + // -- prepare + FishTank source = createFishTank(); + + // -- action + FishTankDto target = FishTankMapper.INSTANCE.map( source ); + FishTank source2 = FishTankMapper.INSTANCE.map( target ); + + // -- result + assertThat( source2.getName() ).isEqualTo( source.getName() ); + + // fish + assertThat( source2.getFish() ).isNotNull(); + assertThat( source2.getFish().getType() ).isEqualTo( source.getFish().getType() ); + + // interior, designer will not be mapped (asymetric) to target. Here it shows. + assertThat( source2.getInterior() ).isNotNull(); + assertThat( source2.getInterior().getDesigner() ).isNull(); + assertThat( source2.getInterior().getOrnament() ).isNotNull(); + assertThat( source2.getInterior().getOrnament().getType() ) + .isEqualTo( source.getInterior().getOrnament().getType() ); + + // material + assertThat( source2.getMaterial() ).isNotNull(); + assertThat( source2.getMaterial().getType() ).isEqualTo( source.getMaterial().getType() ); + + // plant + assertThat( source2.getPlant().getKind() ).isEqualTo( source.getPlant().getKind() ); + + // quality + assertThat( source2.getQuality().getReport() ).isNotNull(); + assertThat( source2.getQuality().getReport().getOrganisationName() ) + .isEqualTo( source.getQuality().getReport().getOrganisationName() ); + assertThat( source2.getQuality().getReport().getVerdict() ) + .isEqualTo( source.getQuality().getReport().getVerdict() ); + } + + @Test + public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndConstant() { + + // -- prepare + FishTank source = createFishTank(); + + // -- action + FishTankDto target = FishTankMapperConstant.INSTANCE.map( source ); + + // -- result + + // fixed value + assertThat( target.getFish().getName() ).isEqualTo( "Nemo" ); + + // automapping takes care of mapping property "waterPlant". + assertThat( target.getPlant() ).isNotNull(); + assertThat( target.getPlant().getKind() ).isEqualTo( source.getPlant().getKind() ); + + // non-nested and constant + assertThat( target.getMaterial() ).isNotNull(); + assertThat( target.getMaterial().getManufacturer() ).isEqualTo( "MMM" ); + assertThat( target.getMaterial().getMaterialType() ).isNotNull(); + assertThat( target.getMaterial().getMaterialType().getType() ).isEqualTo( source.getMaterial().getType() ); + + assertThat( target.getOrnament() ).isNull(); + assertThat( target.getQuality() ).isNull(); + + } + + @Test + public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndExpresion() { + + // -- prepare + FishTank source = createFishTank(); + + // -- action + FishTankDto target = FishTankMapperExpression.INSTANCE.map( source ); + + // -- result + assertThat( target.getFish().getName() ).isEqualTo( "Jaws" ); + + assertThat( target.getMaterial() ).isNull(); + assertThat( target.getOrnament() ).isNull(); + assertThat( target.getPlant() ).isNull(); + + assertThat( target.getQuality() ).isNotNull(); + assertThat( target.getQuality().getReport() ).isNotNull(); + assertThat( target.getQuality().getReport().getVerdict() ) + .isEqualTo( source.getQuality().getReport().getVerdict() ); + assertThat( target.getQuality().getReport().getOrganisation() ).isNotNull(); + assertThat( target.getQuality().getReport().getOrganisation().getApproval() ).isNull(); + assertThat( target.getQuality().getReport().getOrganisation().getName() ).isEqualTo( "Dunno" ); + } + + @Test + public void shouldAutomapIntermediateLevelAndMapConstant() { + + // -- prepare + FishTank source = createFishTank(); + + // -- action + FishTankWithNestedDocumentDto target = FishTankMapperWithDocument.INSTANCE.map( source ); + + // -- result + assertThat( target.getFish().getName() ).isEqualTo( "Jaws" ); + + assertThat( target.getMaterial() ).isNull(); + assertThat( target.getOrnament() ).isNull(); + assertThat( target.getPlant() ).isNull(); + + assertThat( target.getQuality() ).isNotNull(); + assertThat( target.getQuality().getDocument() ).isNotNull(); + assertThat( target.getQuality().getDocument().getVerdict() ) + .isEqualTo( source.getQuality().getReport().getVerdict() ); + assertThat( target.getQuality().getDocument().getOrganisation() ).isNotNull(); + assertThat( target.getQuality().getDocument().getOrganisation().getApproval() ).isNull(); + assertThat( target.getQuality().getDocument().getOrganisation().getName() ).isEqualTo( "NoIdeaInc" ); + } + + private FishTank createFishTank() { + FishTank fishTank = new FishTank(); + + Fish fish = new Fish(); + fish.setType( "Carp" ); + + WaterPlant waterplant = new WaterPlant(); + waterplant.setKind( "Water Hyacinth" ); + + Interior interior = new Interior(); + interior.setDesigner( "MrVeryFamous" ); + Ornament ornament = new Ornament(); + ornament.setType( "castle" ); + interior.setOrnament( ornament ); + + WaterQuality quality = new WaterQuality(); + WaterQualityReport report = new WaterQualityReport(); + report.setVerdict( "PASSED" ); + report.setOrganisationName( "ACME" ); + quality.setReport( report ); + + MaterialType materialType = new MaterialType(); + materialType.setType( "myMaterialType" ); + + fishTank.setName( "MyLittleFishTank" ); + fishTank.setFish( fish ); + fishTank.setPlant( waterplant ); + fishTank.setInterior( interior ); + fishTank.setMaterial( materialType ); + fishTank.setQuality( quality ); + + return fishTank; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java new file mode 100644 index 0000000000..ab806c0999 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface FishTankMapper { + + FishTankMapper INSTANCE = Mappers.getMapper( FishTankMapper.class ); + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", ignore = true), + @Mapping(target = "ornament", source = "interior.ornament"), + @Mapping(target = "material.materialType", source = "material"), + @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") + }) + FishTankDto map( FishTank source ); + + @Mappings({ + @Mapping(target = "fish.kind", source = "source.fish.type"), + @Mapping(target = "fish.name", ignore = true), + @Mapping(target = "ornament", source = "source.interior.ornament"), + @Mapping(target = "material.materialType", source = "source.material"), + @Mapping(target = "quality.report.organisation.name", source = "source.quality.report.organisationName") + }) + FishTankDto mapAsWell( FishTank source ); + + @InheritInverseConfiguration( name = "map" ) + FishTank map( FishTankDto source ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java new file mode 100644 index 0000000000..955d7e7043 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface FishTankMapperConstant { + + FishTankMapperConstant INSTANCE = Mappers.getMapper( FishTankMapperConstant.class ); + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", constant = "Nemo"), + @Mapping(target = "ornament", ignore = true ), + @Mapping(target = "material.materialType", source = "material"), + @Mapping(target = "material.manufacturer", constant = "MMM" ), + @Mapping(target = "quality", ignore = true) + }) + FishTankDto map( FishTank source ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java new file mode 100644 index 0000000000..b76abb957f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface FishTankMapperExpression { + + FishTankMapperExpression INSTANCE = Mappers.getMapper( FishTankMapperExpression.class ); + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), + @Mapping(target = "plant", ignore = true ), + @Mapping(target = "ornament", ignore = true ), + @Mapping(target = "material", ignore = true), + @Mapping(target = "quality.report.organisation.name", expression = "java(\"Dunno\")" ) + }) + FishTankDto map( FishTank source ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java new file mode 100644 index 0000000000..d5571afea5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankWithNestedDocumentDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface FishTankMapperWithDocument { + + FishTankMapperWithDocument INSTANCE = Mappers.getMapper( FishTankMapperWithDocument.class ); + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), + @Mapping(target = "plant", ignore = true ), + @Mapping(target = "ornament", ignore = true ), + @Mapping(target = "material", ignore = true), + @Mapping(target = "quality.document", source = "quality.report"), + @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) + }) + FishTankWithNestedDocumentDto map( FishTank source ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java similarity index 95% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java index c4dee02692..a7fffe1ec5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties._target; +package org.mapstruct.ap.test.nestedbeans.mixed._target; /** * diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java new file mode 100644 index 0000000000..04693823c7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java @@ -0,0 +1,82 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class FishTankDto { + + private FishDto fish; + private WaterPlantDto plant; + private String name; + private MaterialDto material; + private OrnamentDto ornament; + private WaterQualityDto quality; + + public FishDto getFish() { + return fish; + } + + public void setFish(FishDto fish) { + this.fish = fish; + } + + public WaterPlantDto getPlant() { + return plant; + } + + public void setPlant(WaterPlantDto plant) { + this.plant = plant; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public MaterialDto getMaterial() { + return material; + } + + public void setMaterial(MaterialDto material) { + this.material = material; + } + + public OrnamentDto getOrnament() { + return ornament; + } + + public void setOrnament(OrnamentDto ornament) { + this.ornament = ornament; + } + + public WaterQualityDto getQuality() { + return quality; + } + + public void setQuality(WaterQualityDto quality) { + this.quality = quality; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java new file mode 100644 index 0000000000..0fddf165b6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java @@ -0,0 +1,82 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class FishTankWithNestedDocumentDto { + + private FishDto fish; + private WaterPlantDto plant; + private String name; + private MaterialDto material; + private OrnamentDto ornament; + private WaterQualityWithDocumentDto quality; + + public FishDto getFish() { + return fish; + } + + public void setFish(FishDto fish) { + this.fish = fish; + } + + public WaterPlantDto getPlant() { + return plant; + } + + public void setPlant(WaterPlantDto plant) { + this.plant = plant; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public MaterialDto getMaterial() { + return material; + } + + public void setMaterial(MaterialDto material) { + this.material = material; + } + + public OrnamentDto getOrnament() { + return ornament; + } + + public void setOrnament(OrnamentDto ornament) { + this.ornament = ornament; + } + + public WaterQualityWithDocumentDto getQuality() { + return quality; + } + + public void setQuality(WaterQualityWithDocumentDto quality) { + this.quality = quality; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java new file mode 100644 index 0000000000..8932b88595 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class MaterialDto { + + private String manufacturer; + private MaterialTypeDto materialType; + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public MaterialTypeDto getMaterialType() { + return materialType; + } + + public void setMaterialType(MaterialTypeDto materialType) { + this.materialType = materialType; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java similarity index 67% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java index 081b567bba..a9d46ff27d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/FishTankDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java @@ -16,31 +16,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties._target; +package org.mapstruct.ap.test.nestedbeans.mixed._target; /** * * @author Sjaak Derksen */ -public class FishTankDto { +public class MaterialTypeDto { - private FishDto fish; - private WaterPlantDto plant; + private String type; - public FishDto getFish() { - return fish; + public String getType() { + return type; } - public void setFish(FishDto fish) { - this.fish = fish; - } - - public WaterPlantDto getPlant() { - return plant; - } - - public void setPlant(WaterPlantDto plant) { - this.plant = plant; + public void setType(String type) { + this.type = type; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java similarity index 62% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java index 6e434804fb..6c8153873f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java @@ -16,23 +16,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; -import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; -import org.mapstruct.factory.Mappers; +package org.mapstruct.ap.test.nestedbeans.mixed._target; /** * * @author Sjaak Derksen */ -@Mapper -public interface FishTankMapper { +public class OrnamentDto { + + private String type; + + public String getType() { + return type; + } - FishTankMapper INSTANCE = Mappers.getMapper( FishTankMapper.class ); + public void setType(String type) { + this.type = type; + } - @Mapping(target = "fish.kind", source = "fish.type") - FishTankDto map( FishTank source ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java similarity index 94% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java index 1118fd7fa3..e527e6ec7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/_target/WaterPlantDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties._target; +package org.mapstruct.ap.test.nestedbeans.mixed._target; /** * diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java new file mode 100644 index 0000000000..84f7dc229f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class WaterQualityDto { + + private WaterQualityReportDto report; + + public WaterQualityReportDto getReport() { + return report; + } + + public void setReport(WaterQualityReportDto report) { + this.report = report; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java similarity index 72% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java index d250898c41..e8833d35de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/FishTank.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java @@ -16,33 +16,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties.source; +package org.mapstruct.ap.test.nestedbeans.mixed._target; /** * * @author Sjaak Derksen */ -public class FishTank { +public class WaterQualityOrganisationDto { - private Fish fish; - private WaterPlant plant; private String name; - - public Fish getFish() { - return fish; - } - - public void setFish(Fish fish) { - this.fish = fish; - } - - public WaterPlant getPlant() { - return plant; - } - - public void setPlant(WaterPlant plant) { - this.plant = plant; - } + private String approval; public String getName() { return name; @@ -52,4 +35,12 @@ public void setName(String name) { this.name = name; } + public String getApproval() { + return approval; + } + + public void setApproval(String approval) { + this.approval = approval; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java new file mode 100644 index 0000000000..d5456a3090 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class WaterQualityReportDto { + + private WaterQualityOrganisationDto organisation; + private String verdict; + + public WaterQualityOrganisationDto getOrganisation() { + return organisation; + } + + public void setOrganisation(WaterQualityOrganisationDto organisation) { + this.organisation = organisation; + } + + public String getVerdict() { + return verdict; + } + + public void setVerdict(String verdict) { + this.verdict = verdict; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java new file mode 100644 index 0000000000..35c86b243c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed._target; + +/** + * + * @author Sjaak Derksen + */ +public class WaterQualityWithDocumentDto { + + private WaterQualityReportDto document; + + public WaterQualityReportDto getDocument() { + return document; + } + + public void setDocument(WaterQualityReportDto document) { + this.document = document; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java similarity index 94% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java index 97b29c6e70..51250f42a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/Fish.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties.source; +package org.mapstruct.ap.test.nestedbeans.mixed.source; /** * diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java new file mode 100644 index 0000000000..2cfc48bb97 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java @@ -0,0 +1,82 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class FishTank { + + private Fish fish; + private WaterPlant plant; + private String name; + private MaterialType material; + private Interior interior; + private WaterQuality quality; + + public Fish getFish() { + return fish; + } + + public void setFish(Fish fish) { + this.fish = fish; + } + + public WaterPlant getPlant() { + return plant; + } + + public void setPlant(WaterPlant plant) { + this.plant = plant; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public MaterialType getMaterial() { + return material; + } + + public void setMaterial(MaterialType material) { + this.material = material; + } + + public Interior getInterior() { + return interior; + } + + public void setInterior(Interior interior) { + this.interior = interior; + } + + public WaterQuality getQuality() { + return quality; + } + + public void setQuality(WaterQuality quality) { + this.quality = quality; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java new file mode 100644 index 0000000000..ae84726637 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class Interior { + + private String designer; + private Ornament ornament; + + public String getDesigner() { + return designer; + } + + public void setDesigner(String designer) { + this.designer = designer; + } + + public Ornament getOrnament() { + return ornament; + } + + public void setOrnament(Ornament ornament) { + this.ornament = ornament; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java new file mode 100644 index 0000000000..8f83fdb16d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class MaterialType { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java new file mode 100644 index 0000000000..80cc128f3c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class Ornament { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java similarity index 94% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java index 138686c9cd..52799646c5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/source/WaterPlant.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties.source; +package org.mapstruct.ap.test.nestedbeans.mixed.source; /** * diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java new file mode 100644 index 0000000000..77a0e454e6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class WaterQuality { + + private WaterQualityReport report; + + public WaterQualityReport getReport() { + return report; + } + + public void setReport(WaterQualityReport report) { + this.report = report; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java new file mode 100644 index 0000000000..76dbd7cbfc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed.source; + +/** + * + * @author Sjaak Derksen + */ +public class WaterQualityReport { + + private String organisationName; + private String verdict; + + public String getOrganisationName() { + return organisationName; + } + + public void setOrganisationName(String organisationName) { + this.organisationName = organisationName; + } + + public String getVerdict() { + return verdict; + } + + public void setVerdict(String verdict) { + this.verdict = verdict; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java index b7e9f94e3f..c9600ad9ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java @@ -28,12 +28,6 @@ import org.mapstruct.ap.test.nestedsourceproperties.source.Label; import org.mapstruct.ap.test.nestedsourceproperties.source.Song; import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; -import org.mapstruct.ap.test.nestedtargetproperties._target.FishDto; -import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; -import org.mapstruct.ap.test.nestedtargetproperties._target.WaterPlantDto; -import org.mapstruct.ap.test.nestedtargetproperties.source.Fish; -import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; -import org.mapstruct.ap.test.nestedtargetproperties.source.WaterPlant; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @@ -50,16 +44,9 @@ Label.class, Studio.class, ChartEntry.class, - FishDto.class, - FishTankDto.class, - WaterPlantDto.class, - Fish.class, - FishTank.class, - WaterPlant.class, ChartEntryToArtist.class, - ChartEntryToArtistUpdate.class, - FishTankMapper.class -}) + ChartEntryToArtistUpdate.class +} ) @IssueKey("389") @RunWith(AnnotationProcessorTestRunner.class) public class NestedTargetPropertiesTest { @@ -67,8 +54,7 @@ public class NestedTargetPropertiesTest { @Rule public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( ChartEntryToArtist.class, - ChartEntryToArtistUpdate.class, - FishTankMapper.class + ChartEntryToArtistUpdate.class ); @Test @@ -186,31 +172,4 @@ public void shouldMapNestedTargetWitUpdate() { assertThat( result.getSong().getPositions().get( 0 ) ).isEqualTo( 1 ); } - - @Test - public void automappingAndTargetNestingDemonstrator() { - - FishTank source = new FishTank(); - source.setName( "MyLittleFishTank" ); - Fish fish = new Fish(); - fish.setType( "Carp" ); - WaterPlant waterplant = new WaterPlant(); - waterplant.setKind( "Water Hyacinth" ); - source.setFish( fish ); - source.setPlant( waterplant ); - - FishTankDto target = FishTankMapper.INSTANCE.map( source ); - - // the nested property generates a method fishTankToFishDto(FishTank fishTank, FishDto mappingTarget) - // when name based mapping continues MapStruct searches for a property called `name` in fishTank (type - // 'FishTank'. If it is there, it should most cerntainly not be mapped to a mappingTarget of type 'FishDto' - assertThat( target.getFish() ).isNotNull(); - assertThat( target.getFish().getKind() ).isEqualTo( "Carp" ); - assertThat( target.getFish().getName() ).isNull(); - - // automapping takes care of mapping property "waterPlant". - assertThat( target.getPlant() ).isNotNull(); - assertThat( target.getPlant().getKind() ).isEqualTo( "Water Hyacinth" ); - } - } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java similarity index 59% rename from processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java rename to processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java index 12e5062e96..62f8a0aef1 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java @@ -16,22 +16,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.nestedtargetproperties; +package org.mapstruct.ap.test.nestedbeans.mixed; import javax.annotation.Generated; -import org.mapstruct.ap.test.nestedtargetproperties._target.FishDto; -import org.mapstruct.ap.test.nestedtargetproperties._target.FishTankDto; -import org.mapstruct.ap.test.nestedtargetproperties._target.WaterPlantDto; -import org.mapstruct.ap.test.nestedtargetproperties.source.Fish; -import org.mapstruct.ap.test.nestedtargetproperties.source.FishTank; -import org.mapstruct.ap.test.nestedtargetproperties.source.WaterPlant; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterPlantDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterPlant; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-07T21:05:06+0100", + date = "2017-02-13T00:35:18+0100", comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" ) -public class FishTankMapperImpl implements FishTankMapper { +public class FishTankMapperConstantImpl implements FishTankMapperConstant { @Override public FishTankDto map(FishTank source) { @@ -41,38 +41,23 @@ public FishTankDto map(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setFish( fishTankToFishDto( source ) ); + fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); + fishTankDto.setName( source.getName() ); return fishTankDto; } - private String fishTankFishType(FishTank fishTank) { - if ( fishTank == null ) { - return null; - } - Fish fish = fishTank.getFish(); + protected FishDto fishToFishDto(Fish fish) { if ( fish == null ) { return null; } - String type = fish.getType(); - if ( type == null ) { - return null; - } - return type; - } - - protected FishDto fishTankToFishDto(FishTank fishTank) { - if ( fishTank == null ) { - return null; - } FishDto fishDto = new FishDto(); - String type = fishTankFishType( fishTank ); - if ( type != null ) { - fishDto.setKind( type ); - } + fishDto.setKind( fish.getType() ); + + fishDto.setName( "Nemo" ); return fishDto; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java new file mode 100644 index 0000000000..905133851e --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -0,0 +1,358 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialTypeDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.OrnamentDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterPlantDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityOrganisationDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityReportDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Interior; +import org.mapstruct.ap.test.nestedbeans.mixed.source.MaterialType; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Ornament; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterPlant; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQuality; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQualityReport; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-12T21:48:04+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_45 (Oracle Corporation)" +) +public class FishTankMapperImpl implements FishTankMapper { + + @Override + public FishTankDto map(FishTank source) { + if ( source == null ) { + return null; + } + + FishTankDto fishTankDto = new FishTankDto(); + + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); + fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); + Ornament ornament = sourceInteriorOrnament( source ); + if ( ornament != null ) { + fishTankDto.setOrnament( ornamentToOrnamentDto( ornament ) ); + } + fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); + fishTankDto.setName( source.getName() ); + + return fishTankDto; + } + + @Override + public FishTankDto mapAsWell(FishTank source) { + if ( source == null ) { + return null; + } + + FishTankDto fishTankDto = new FishTankDto(); + + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); + fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); + Ornament ornament = sourceInteriorOrnament1( source ); + if ( ornament != null ) { + fishTankDto.setOrnament( ornamentToOrnamentDto( ornament ) ); + } + fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); + fishTankDto.setName( source.getName() ); + + return fishTankDto; + } + + @Override + public FishTank map(FishTankDto source) { + if ( source == null ) { + return null; + } + + FishTank fishTank = new FishTank(); + + fishTank.setFish( fishDtoToFish( source.getFish() ) ); + fishTank.setQuality( waterQualityDtoToWaterQuality( source.getQuality() ) ); + fishTank.setInterior( fishTankDtoToInterior( source ) ); + MaterialTypeDto materialType = sourceMaterialMaterialType( source ); + if ( materialType != null ) { + fishTank.setMaterial( materialTypeDtoToMaterialType( materialType ) ); + } + fishTank.setPlant( waterPlantDtoToWaterPlant( source.getPlant() ) ); + fishTank.setName( source.getName() ); + + return fishTank; + } + + protected MaterialTypeDto materialTypeToMaterialTypeDto(MaterialType materialType) { + if ( materialType == null ) { + return null; + } + + MaterialTypeDto materialTypeDto = new MaterialTypeDto(); + + materialTypeDto.setType( materialType.getType() ); + + return materialTypeDto; + } + + protected MaterialDto fishTankToMaterialDto(FishTank fishTank) { + if ( fishTank == null ) { + return null; + } + + MaterialDto materialDto = new MaterialDto(); + + materialDto.setMaterialType( materialTypeToMaterialTypeDto( fishTank.getMaterial() ) ); + + return materialDto; + } + + protected FishDto fishToFishDto(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + return fishDto; + } + + protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisationDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityOrganisationDto waterQualityOrganisationDto = new WaterQualityOrganisationDto(); + + waterQualityOrganisationDto.setName( waterQualityReport.getOrganisationName() ); + + return waterQualityOrganisationDto; + } + + protected WaterQualityReportDto waterQualityReportToWaterQualityReportDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityReportDto waterQualityReportDto = new WaterQualityReportDto(); + + waterQualityReportDto.setOrganisation( waterQualityReportToWaterQualityOrganisationDto( waterQualityReport ) ); + waterQualityReportDto.setVerdict( waterQualityReport.getVerdict() ); + + return waterQualityReportDto; + } + + protected WaterQualityDto waterQualityToWaterQualityDto(WaterQuality waterQuality) { + if ( waterQuality == null ) { + return null; + } + + WaterQualityDto waterQualityDto = new WaterQualityDto(); + + waterQualityDto.setReport( waterQualityReportToWaterQualityReportDto( waterQuality.getReport() ) ); + + return waterQualityDto; + } + + private Ornament sourceInteriorOrnament(FishTank fishTank) { + + if ( fishTank == null ) { + return null; + } + Interior interior = fishTank.getInterior(); + if ( interior == null ) { + return null; + } + Ornament ornament = interior.getOrnament(); + if ( ornament == null ) { + return null; + } + return ornament; + } + + protected OrnamentDto ornamentToOrnamentDto(Ornament ornament) { + if ( ornament == null ) { + return null; + } + + OrnamentDto ornamentDto = new OrnamentDto(); + + ornamentDto.setType( ornament.getType() ); + + return ornamentDto; + } + + protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { + if ( waterPlant == null ) { + return null; + } + + WaterPlantDto waterPlantDto = new WaterPlantDto(); + + waterPlantDto.setKind( waterPlant.getKind() ); + + return waterPlantDto; + } + + private Ornament sourceInteriorOrnament1(FishTank fishTank) { + + if ( fishTank == null ) { + return null; + } + Interior interior = fishTank.getInterior(); + if ( interior == null ) { + return null; + } + Ornament ornament = interior.getOrnament(); + if ( ornament == null ) { + return null; + } + return ornament; + } + + protected Fish fishDtoToFish(FishDto fishDto) { + if ( fishDto == null ) { + return null; + } + + Fish fish = new Fish(); + + fish.setType( fishDto.getKind() ); + + return fish; + } + + private String waterQualityReportDtoOrganisationName(WaterQualityReportDto waterQualityReportDto) { + + if ( waterQualityReportDto == null ) { + return null; + } + WaterQualityOrganisationDto organisation = waterQualityReportDto.getOrganisation(); + if ( organisation == null ) { + return null; + } + String name = organisation.getName(); + if ( name == null ) { + return null; + } + return name; + } + + protected WaterQualityReport waterQualityReportDtoToWaterQualityReport(WaterQualityReportDto waterQualityReportDto) { + if ( waterQualityReportDto == null ) { + return null; + } + + WaterQualityReport waterQualityReport = new WaterQualityReport(); + + String name = waterQualityReportDtoOrganisationName( waterQualityReportDto ); + if ( name != null ) { + waterQualityReport.setOrganisationName( name ); + } + waterQualityReport.setVerdict( waterQualityReportDto.getVerdict() ); + + return waterQualityReport; + } + + protected WaterQuality waterQualityDtoToWaterQuality(WaterQualityDto waterQualityDto) { + if ( waterQualityDto == null ) { + return null; + } + + WaterQuality waterQuality = new WaterQuality(); + + waterQuality.setReport( waterQualityReportDtoToWaterQualityReport( waterQualityDto.getReport() ) ); + + return waterQuality; + } + + protected Ornament ornamentDtoToOrnament(OrnamentDto ornamentDto) { + if ( ornamentDto == null ) { + return null; + } + + Ornament ornament = new Ornament(); + + ornament.setType( ornamentDto.getType() ); + + return ornament; + } + + protected Interior fishTankDtoToInterior(FishTankDto fishTankDto) { + if ( fishTankDto == null ) { + return null; + } + + Interior interior = new Interior(); + + interior.setOrnament( ornamentDtoToOrnament( fishTankDto.getOrnament() ) ); + + return interior; + } + + private MaterialTypeDto sourceMaterialMaterialType(FishTankDto fishTankDto) { + + if ( fishTankDto == null ) { + return null; + } + MaterialDto material = fishTankDto.getMaterial(); + if ( material == null ) { + return null; + } + MaterialTypeDto materialType = material.getMaterialType(); + if ( materialType == null ) { + return null; + } + return materialType; + } + + protected MaterialType materialTypeDtoToMaterialType(MaterialTypeDto materialTypeDto) { + if ( materialTypeDto == null ) { + return null; + } + + MaterialType materialType = new MaterialType(); + + materialType.setType( materialTypeDto.getType() ); + + return materialType; + } + + protected WaterPlant waterPlantDtoToWaterPlant(WaterPlantDto waterPlantDto) { + if ( waterPlantDto == null ) { + return null; + } + + WaterPlant waterPlant = new WaterPlant(); + + waterPlant.setKind( waterPlantDto.getKind() ); + + return waterPlant; + } +} From 6f51cf4a8a2a04eb29722a4402efb52b072c5761 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Fri, 10 Feb 2017 22:21:07 +0100 Subject: [PATCH 0056/1006] #1057 Towards controlling name based mapping from root @Mapping --- .../model/AbstractMappingMethodBuilder.java | 3 +- .../ap/internal/model/PropertyMapping.java | 41 ++++------- .../internal/model/source/ForgedMethod.java | 72 ++----------------- .../ap/internal/model/source/Mapping.java | 2 +- 4 files changed, 22 insertions(+), 96 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index cf1735b7b4..5be3fb186e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -68,7 +68,8 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { targetType, shouldUsePropertyNamesInHistory(), sourceRHS.getSourceErrorMessagePart() - ) + ), + null ); return createForgedBeanAssignment( sourceRHS, forgedMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 9eb1290acd..e036e1d906 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -222,6 +222,7 @@ public PropertyMappingBuilder forgeMethodWithMappingOptions(MappingOptions mappi * Force the created mapping to use update methods when forging a method. * * @param forceUpdateMethod whether the mapping should force update method for forged mappings + * @return the builder for chaining */ public PropertyMappingBuilder forceUpdateMethod(boolean forceUpdateMethod) { this.forceUpdateMethod = forceUpdateMethod; @@ -585,7 +586,8 @@ private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, Sourc element, method.getContextParameters(), method.getContextProvidedMethods(), - getForgedMethodHistory( source, suffix ) + getForgedMethodHistory( source, suffix ), + null ); } @@ -627,32 +629,17 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { else { returnType = targetType; } - ForgedMethod forgedMethod; - if ( forgeMethodWithMappingOptions != null ) { - forgedMethod = new ForgedMethod( - name, - sourceType, - returnType, - method.getMapperConfiguration(), - method.getExecutable(), - parameters, - method.getContextProvidedMethods(), - forgeMethodWithMappingOptions - ); - } - else { - forgedMethod = new ForgedMethod( - name, - sourceType, - returnType, - method.getMapperConfiguration(), - method.getExecutable(), - parameters, - method.getContextProvidedMethods(), - getForgedMethodHistory( sourceRHS ) - ); - } - + ForgedMethod forgedMethod = new ForgedMethod( + name, + sourceType, + returnType, + method.getMapperConfiguration(), + method.getExecutable(), + parameters, + method.getContextProvidedMethods(), + getForgedMethodHistory( sourceRHS ), + forgeMethodWithMappingOptions + ); return createForgedBeanAssignment( sourceRHS, forgedMethod ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 2a890b802a..88517f6c10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -49,7 +49,6 @@ public class ForgedMethod implements Method { private final List contextParameters; private final Parameter mappingTargetParameter; private final MappingOptions mappingOptions; - private final boolean autoMapping; private final ParameterProvidedMethods contextProvidedMethods; /** @@ -76,66 +75,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu additionalParameters, parameterProvidedMethods, null, - false, - MappingOptions.empty() ); - } - - /** - * Creates a new forged method with the given name with history - * - * @param name the (unique name) for this method - * @param sourceType the source type - * @param returnType the return type. - * @param mapperConfiguration the mapper configuration - * @param positionHintElement element used to for reference to the position in the source file. - * @param additionalParameters additional parameters to add to the forged method - * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context - * parameters - * @param history a parent forged method if this is a forged method within a forged method - */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history) { - this( - name, - sourceType, - returnType, - mapperConfiguration, - positionHintElement, - additionalParameters, - parameterProvidedMethods, - history, - true, - MappingOptions.empty() ); - } - - /** - * Creates a new forged method with the given name with mapping options - * - * @param name the (unique name) for this method - * @param sourceType the source type - * @param returnType the return type. - * @param mapperConfiguration the mapper configuration - * @param positionHintElement element used to for reference to the position in the source file. - * @param additionalParameters additional parameters to add to the forged method - * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context - * parameters - * @param mappingOptions with mapping options - */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - ParameterProvidedMethods parameterProvidedMethods, MappingOptions mappingOptions) { - this( - name, - sourceType, - returnType, - mapperConfiguration, - positionHintElement, - additionalParameters, - parameterProvidedMethods, - null, - false, - mappingOptions ); + null ); } /** @@ -152,10 +92,10 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param history a parent forged method if this is a forged method within a forged method * @param mappingOptions the mapping options for this method */ - private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, ExecutableElement positionHintElement, List additionalParameters, ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, - boolean autoMapping, MappingOptions mappingOptions) { + MappingOptions mappingOptions) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); @@ -174,8 +114,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, MapperConfig this.mapperConfiguration = mapperConfiguration; this.positionHintElement = positionHintElement; this.history = history; - this.autoMapping = autoMapping; - this.mappingOptions = mappingOptions; + this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions; this.mappingOptions.initWithParameter( sourceParameter ); } @@ -191,7 +130,6 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.mapperConfiguration = forgedMethod.mapperConfiguration; this.positionHintElement = forgedMethod.positionHintElement; this.history = forgedMethod.history; - this.autoMapping = forgedMethod.autoMapping; this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); @@ -287,7 +225,7 @@ public ForgedMethodHistory getHistory() { } public boolean isAutoMapping() { - return autoMapping; + return mappingOptions.getValueMappings().isEmpty(); } public void addThrownTypes(List thrownTypesToAdd) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index e3517ea015..9eac9f92da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -249,7 +249,7 @@ public void init(SourceMethod method, FormattingMessager messager, TypeFactory t /** * Initializes the mapping with a new source parameter. * - * @param sourceParameter + * @param sourceParameter sets the source parameter that acts as a basis for this mapping */ public void init( Parameter sourceParameter ) { if ( sourceReference != null ) { From 378961fc53f6cb25a57fd34f38f6295520212e02 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 Feb 2017 13:04:35 +0100 Subject: [PATCH 0057/1006] #1057 Add ReportingPolicy to the BeanMapping Use ReportingPolicy for explicitly ignoring unmapped target properties in forged methods. --- .../ap/internal/model/BeanMappingMethod.java | 14 ++++++++---- .../ap/internal/model/source/BeanMapping.java | 22 +++++++++++++++++-- .../internal/model/source/MappingOptions.java | 9 +++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index be2d17d040..0a22215037 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -46,6 +46,7 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -574,6 +575,12 @@ private Accessor getTargetPropertyReadAccessor(String propertyName) { } private ReportingPolicyPrism getUnmappedTargetPolicy() { + MappingOptions mappingOptions = method.getMappingOptions(); + if ( mappingOptions.getBeanMapping() != null && + mappingOptions.getBeanMapping().getReportingPolicy() != null ) { + return mappingOptions.getBeanMapping().getReportingPolicy(); + } + MapperConfiguration mapperSettings = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ); return mapperSettings.unmappedTargetPolicy( ctx.getOptions() ); @@ -584,12 +591,11 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { // fetch settings from element to implement ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); - //we handle forged methods differently than the usual source ones. in - if ( method instanceof ForgedMethod ) { + //we handle automapping forged methods differently than the usual source ones. in + if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isAutoMapping() ) { ForgedMethod forgedMethod = (ForgedMethod) this.method; - if ( forgedMethod.isAutoMapping() - && ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) ) { + if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { if ( forgedMethod.getHistory() == null ) { Type sourceType = this.method.getParameters().get( 0 ).getType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index 2ab40fd92d..b11f9d3e42 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -23,6 +23,7 @@ import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -35,6 +36,7 @@ public class BeanMapping { private final SelectionParameters selectionParameters; private final NullValueMappingStrategyPrism nullValueMappingStrategy; + private final ReportingPolicyPrism reportingPolicy; public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, FormattingMessager messager) { @@ -61,12 +63,25 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem beanMapping.qualifiedByName(), resultTypeIsDefined ? beanMapping.resultType() : null ); - return new BeanMapping(cmp, nullValueMappingStrategy ); + //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? + return new BeanMapping( cmp, nullValueMappingStrategy, null ); } - private BeanMapping( SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms ) { + /** + * This method should be used to generate BeanMappings for our internal generated Mappings. Like forged update + * methods. + * + * @return bean mapping that needs to be used for Mappings + */ + public static BeanMapping forMappingsOnly() { + return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE ); + } + + private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, + ReportingPolicyPrism reportingPolicy) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; + this.reportingPolicy = reportingPolicy; } public SelectionParameters getSelectionParameters() { @@ -77,4 +92,7 @@ public NullValueMappingStrategyPrism getNullValueMappingStrategy() { return nullValueMappingStrategy; } + public ReportingPolicyPrism getReportingPolicy() { + return reportingPolicy; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 232fc1001c..aabb1116c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -79,7 +79,14 @@ public static MappingOptions empty() { * @return MappingOptions with only regular mappings */ public static MappingOptions forMappingsOnly( Map> mappings ) { - return new MappingOptions( mappings, null, null, null, Collections.emptyList(), true ); + return new MappingOptions( + mappings, + null, + null, + BeanMapping.forMappingsOnly(), + Collections.emptyList(), + true + ); } From f0646c6287191a38d324cf93683deb38cc954edd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 Feb 2017 13:04:35 +0100 Subject: [PATCH 0058/1006] #1057 Add full support for controlling name based mapping from root level with @Mapping --- .../ap/internal/model/BeanMappingMethod.java | 80 +++- .../NestedTargetPropertyMappingHolder.java | 359 ++++++++++++++++-- .../ap/internal/model/source/BeanMapping.java | 2 +- .../ap/internal/model/source/Mapping.java | 28 ++ .../internal/model/source/MappingOptions.java | 8 +- .../model/source/SourceReference.java | 11 + .../mapstruct/ap/internal/util/Extractor.java | 39 ++ 7 files changed, 481 insertions(+), 46 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0a22215037..314659d526 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -89,6 +89,7 @@ public static class Builder { private final Set existingVariableNames = new HashSet(); private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; + private final Map> unprocessedDefinedTargets = new HashMap>(); public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -146,6 +147,8 @@ public BeanMappingMethod build() { applyParameterNameBasedMapping(); } + handleUnprocessedDefinedTargets(); + // report errors on unmapped properties reportErrorForUnmappedTargetPropertiesIfRequired(); @@ -216,6 +219,50 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { ); } + /** + * If there were nested defined targets that have not been handled. The we need to process them at he end. + */ + private void handleUnprocessedDefinedTargets() { + Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); + + while ( iterator.hasNext() ) { + Entry> entry = iterator.next(); + String propertyName = entry.getKey(); + if ( !unprocessedTargetProperties.containsKey( propertyName ) ) { + continue; + } + List sourceParameters = method.getSourceParameters(); + boolean forceUpdateMethod = sourceParameters.size() > 1; + for ( Parameter sourceParameter : sourceParameters ) { + SourceReference reference = new SourceReference.BuilderFromProperty() + .sourceParameter( sourceParameter ) + .name( propertyName ) + .build(); + + MappingOptions mappingOptions = extractAdditionalOptions( propertyName, true ); + PropertyMapping propertyMapping = new PropertyMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .targetWriteAccessor( unprocessedTargetProperties.get( propertyName ) ) + .targetReadAccessor( getTargetPropertyReadAccessor( propertyName ) ) + .targetPropertyName( propertyName ) + .sourceReference( reference ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mappingOptions.collectNestedDependsOn() ) + .forgeMethodWithMappingOptions( mappingOptions ) + .forceUpdateMethod( forceUpdateMethod ) + .forgedNamedBased( false ) + .build(); + + if ( propertyMapping != null ) { + unprocessedTargetProperties.remove( propertyName ); + iterator.remove(); + propertyMappings.add( propertyMapping ); + } + } + } + } + /** * Sources the given mappings as per the dependency relationships given via {@code dependsOn()}. If a cycle is * detected, an error is reported. @@ -291,6 +338,7 @@ else if ( reportErrorOnTargetObject( mapping ) ) { // In order to avoid: "Unknown property foo in return type" in case of duplicate // target mappings unprocessedTargetProperties.remove( handledTarget ); + unprocessedDefinedTargets.remove( handledTarget ); } return errorOccurred; @@ -307,7 +355,12 @@ private void handleDefinedNestedTargetMapping(Set handledTargets) { unprocessedSourceParameters.removeAll( holder.getProcessedSourceParameters() ); propertyMappings.addAll( holder.getPropertyMappings() ); handledTargets.addAll( holder.getHandledTargets() ); - + for ( Entry> entry : holder.getUnprocessedDefinedTarget().entrySet() ) { + if ( entry.getValue().isEmpty() ) { + continue; + } + unprocessedDefinedTargets.put( entry.getKey().getName(), entry.getValue() ); + } } private boolean handleDefinedMapping(Mapping mapping, Set handledTargets) { @@ -318,6 +371,7 @@ private boolean handleDefinedMapping(Mapping mapping, Set handledTargets TargetReference targetRef = mapping.getTargetReference(); PropertyEntry targetProperty = first( targetRef.getPropertyEntries() ); + String propertyName = targetProperty.getName(); // unknown properties given via dependsOn()? for ( String dependency : mapping.getDependsOn() ) { @@ -361,7 +415,7 @@ else if ( mapping.getSourceName() != null ) { .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) .build(); - handledTargets.add( targetProperty.getName() ); + handledTargets.add( propertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { @@ -370,7 +424,7 @@ else if ( mapping.getSourceName() != null ) { } // its a constant - else if ( mapping.getConstant() != null ) { + else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { propertyMapping = new ConstantMappingBuilder() .mappingContext( ctx ) @@ -387,7 +441,7 @@ else if ( mapping.getConstant() != null ) { } // its an expression - else if ( mapping.getJavaExpression() != null ) { + else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { propertyMapping = new JavaExpressionMappingBuilder() .mappingContext( ctx ) @@ -500,6 +554,7 @@ private void applyPropertyNameBasedMapping() { .defaultValue( mapping != null ? mapping.getDefaultValue() : null ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) + .forgeMethodWithMappingOptions( extractAdditionalOptions( targetPropertyName, false ) ) .build(); unprocessedSourceParameters.remove( sourceParameter ); @@ -523,6 +578,7 @@ else if ( newPropertyMapping != null ) { if ( propertyMapping != null ) { propertyMappings.add( propertyMapping ); targetPropertyEntriesIterator.remove(); + unprocessedDefinedTargets.remove( targetPropertyName ); } } } @@ -560,16 +616,32 @@ private void applyParameterNameBasedMapping() { .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) + .forgeMethodWithMappingOptions( extractAdditionalOptions( targetProperty.getKey(), false ) ) .build(); propertyMappings.add( propertyMapping ); targetPropertyEntriesIterator.remove(); sourceParameters.remove(); + unprocessedDefinedTargets.remove( targetProperty.getKey() ); } } } } + private MappingOptions extractAdditionalOptions(String targetProperty, boolean restrictToDefinedMappings) { + MappingOptions additionalOptions = null; + if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { + + Map> mappings = new HashMap>(); + mappings.put( + targetProperty, + unprocessedDefinedTargets.get( targetProperty ) + ); + additionalOptions = MappingOptions.forMappingsOnly( mappings, restrictToDefinedMappings ); + } + return additionalOptions; + } + private Accessor getTargetPropertyReadAccessor(String propertyName) { return method.getResultType().getPropertyReadAccessors().get( propertyName ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 0ae6e9afe8..3788cc6034 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.util.Extractor; import static org.mapstruct.ap.internal.util.Collections.first; @@ -42,16 +43,35 @@ */ public class NestedTargetPropertyMappingHolder { + private static final Extractor SOURCE_PARAM_EXTRACTOR = new + Extractor() { + @Override + public Parameter apply(SourceReference sourceReference) { + return sourceReference.getParameter(); + } + }; + + private static final Extractor PROPERTY_EXTRACTOR = new + Extractor() { + @Override + public PropertyEntry apply(SourceReference sourceReference) { + return first( sourceReference.getPropertyEntries() ); + } + }; + private final List processedSourceParameters; private final Set handledTargets; private final List propertyMappings; + private final Map> unprocessedDefinedTarget; public NestedTargetPropertyMappingHolder( List processedSourceParameters, Set handledTargets, - List propertyMappings) { + List propertyMappings, + Map> unprocessedDefinedTarget) { this.processedSourceParameters = processedSourceParameters; this.handledTargets = handledTargets; this.propertyMappings = propertyMappings; + this.unprocessedDefinedTarget = unprocessedDefinedTarget; } /** @@ -62,7 +82,6 @@ public List getProcessedSourceParameters() { } /** - * * @return all the targets that were hanled */ public Set getHandledTargets() { @@ -70,13 +89,19 @@ public Set getHandledTargets() { } /** - * * @return the generated property mappings */ public List getPropertyMappings() { return propertyMappings; } + /** + * @return a map of all the unprocessed defined targets that can be applied to name forged base methods + */ + public Map> getUnprocessedDefinedTarget() { + return unprocessedDefinedTarget; + } + public static class Builder { private Method method; @@ -103,42 +128,92 @@ public NestedTargetPropertyMappingHolder build() { Set handledTargets = new HashSet(); List propertyMappings = new ArrayList(); - Map> groupedByTP = groupByPoppedTargetReferences( method.getMappingOptions() ); + GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); + Map> unprocessedDefinedTarget = new HashMap>(); + + for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { + PropertyEntry targetProperty = entryByTP.getKey(); + GroupedBySourceParameters groupedBySourceParam = groupBySourceParameter( + entryByTP.getValue(), + groupedByTP.singleTargetReferences.get( targetProperty ) + ); + boolean forceUpdateMethod = groupedBySourceParam.groupedBySourceParameter.keySet().size() > 1; + + unprocessedDefinedTarget.put( targetProperty, groupedBySourceParam.notProcessedAppliesToAll ); + for ( Map.Entry> entryByParam : groupedBySourceParam + .groupedBySourceParameter.entrySet() ) { - for ( Map.Entry> entryByTP : groupedByTP.entrySet() ) { - Map> groupedBySourceParam = groupBySourceParameter( entryByTP.getValue() ); - boolean forceUpdateMethod = groupedBySourceParam.keySet().size() > 1; - for ( Map.Entry> entryByParam : groupedBySourceParam.entrySet() ) { + Parameter sourceParameter = entryByParam.getKey(); - SourceReference sourceRef = new SourceReference.BuilderFromProperty() - .sourceParameter( entryByParam.getKey() ) - .name( entryByTP.getKey().getName() ) - .build(); - MappingOptions mappingOptions = MappingOptions.forMappingsOnly( - groupByTargetName( entryByParam.getValue() ) + GroupedSourceReferences groupedSourceReferences = groupByPoppedSourceReferences( + entryByParam.getValue(), + groupedByTP.singleTargetReferences.get( targetProperty ) ); - PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() - .mappingContext( mappingContext ) - .sourceMethod( method ) - .targetProperty( entryByTP.getKey() ) - .targetPropertyName( entryByTP.getKey().getName() ) - .sourceReference( sourceRef ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mappingOptions.collectNestedDependsOn() ) - .forgeMethodWithMappingOptions( mappingOptions ) - .forceUpdateMethod( forceUpdateMethod ) - .build(); - processedSourceParameters.add( sourceRef.getParameter() ); - - if ( propertyMapping != null ) { - propertyMappings.add( propertyMapping ); + for ( Map.Entry> entryBySP : groupedSourceReferences + .groupedBySourceReferences + .entrySet() ) { + PropertyEntry sourceEntry = entryBySP.getKey(); + MappingOptions sourceMappingOptions = MappingOptions.forMappingsOnly( + groupByTargetName( entryBySP.getValue() ), + forceUpdateMethod + ); + SourceReference sourceRef = new SourceReference.BuilderFromProperty() + .sourceParameter( sourceParameter ) + .type( sourceEntry.getType() ) + .readAccessor( sourceEntry.getReadAccessor() ) + .presenceChecker( sourceEntry.getPresenceChecker() ) + .name( targetProperty.getName() ) + .build(); + + PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( + sourceMappingOptions, + targetProperty, + sourceRef, + forceUpdateMethod + ); + + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); + } + + handledTargets.add( entryByTP.getKey().getName() ); + } + + if ( !groupedSourceReferences.nonNested.isEmpty() ) { + MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( + groupByTargetName( groupedSourceReferences.nonNested ), + true + ); + SourceReference reference = new SourceReference.BuilderFromProperty() + .sourceParameter( sourceParameter ) + .name( targetProperty.getName() ) + .build(); + + PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( + nonNestedOptions, + targetProperty, + reference, + forceUpdateMethod + ); + + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); + } + + handledTargets.add( entryByTP.getKey().getName() ); } + + unprocessedDefinedTarget.put( targetProperty, groupedSourceReferences.notProcessedAppliesToAll ); } - handledTargets.add( entryByTP.getKey().getName() ); } - return new NestedTargetPropertyMappingHolder( processedSourceParameters, handledTargets, propertyMappings ); + return new NestedTargetPropertyMappingHolder( + processedSourceParameters, + handledTargets, + propertyMappings, + unprocessedDefinedTarget + ); } /** @@ -160,28 +235,38 @@ public NestedTargetPropertyMappingHolder build() { * * The key will be the former top level property, the MappingOptions will contain the remainders. * - * So, 2 cloned new MappingOptions with popped targetReferences. Also Note that the not nested targetReference4 - * disappeared. + * If the target reference cannot be popped it is stored in a different map. That looks like: + * + * propertyEntryZ - List ( targetReference4: propertyEntryZ ) + * + * @param mappingOptions that need to be used to create the {@link GroupedTargetReferences} * * @return See above */ - public Map> groupByPoppedTargetReferences(MappingOptions mappingOptions) { + private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOptions) { Map> mappings = mappingOptions.getMappings(); // group all mappings based on the top level name before popping Map> mappingsKeyedByProperty = new HashMap>(); + Map> singleTargetReferences = new HashMap>(); for ( List mapping : mappings.values() ) { + PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); Mapping newMapping = first( mapping ).popTargetReference(); if ( newMapping != null ) { // group properties on current name. - PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); if ( !mappingsKeyedByProperty.containsKey( property ) ) { mappingsKeyedByProperty.put( property, new ArrayList() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } + else { + if ( !singleTargetReferences.containsKey( property ) ) { + singleTargetReferences.put( property, new ArrayList() ); + } + singleTargetReferences.get( property ).add( first( mapping ) ); + } } - return mappingsKeyedByProperty; + return new GroupedTargetReferences( mappingsKeyedByProperty, singleTargetReferences ); } /** @@ -190,11 +275,16 @@ public Map> groupByPoppedTargetReferences(MappingOp * Note: this method is used for forging nested update methods. For that purpose, the same method with all * joined mappings should be generated. See also: NestedTargetPropertiesTest#shouldMapNestedComposedTarget * + * @param mappings that mappings that need to be used for the grouping + * @param singleTargetReferences a List containing all non-nested mappings for the same grouped target + * property as the {@code mappings} * @return the split mapping options. */ - public Map> groupBySourceParameter(List mappings) { + private GroupedBySourceParameters groupBySourceParameter(List mappings, + List singleTargetReferences) { Map> mappingsKeyedByParameter = new HashMap>(); + List appliesToAll = new ArrayList(); for ( Mapping mapping : mappings ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { Parameter parameter = mapping.getSourceReference().getParameter(); @@ -203,9 +293,84 @@ public Map> groupBySourceParameter(List mappin } mappingsKeyedByParameter.get( parameter ).add( mapping ); } + else { + appliesToAll.add( mapping ); + } + } + + populateWithSingleTargetReferences( + mappingsKeyedByParameter, + singleTargetReferences, + SOURCE_PARAM_EXTRACTOR + ); + + for ( Map.Entry> entry : mappingsKeyedByParameter.entrySet() ) { + entry.getValue().addAll( appliesToAll ); } - return mappingsKeyedByParameter; + List notProcessAppliesToAll = + mappingsKeyedByParameter.isEmpty() ? appliesToAll : new ArrayList(); + + return new GroupedBySourceParameters( mappingsKeyedByParameter, notProcessAppliesToAll ); + } + + /** + * Creates a nested grouping by popping the source mappings. See the description of the class to see what is + * generated. + * + * @param mappings the list of {@link Mapping} that needs to be used for grouping on popped source references + * @param singleTargetReferences the single target references that match the source mappings + * + * @return the Grouped Source References + */ + private GroupedSourceReferences groupByPoppedSourceReferences(List mappings, + List singleTargetReferences) { + List nonNested = new ArrayList(); + List appliesToAll = new ArrayList(); + // group all mappings based on the top level name before popping + Map> mappingsKeyedByProperty = new HashMap>(); + for ( Mapping mapping : mappings ) { + + Mapping newMapping = mapping.popSourceReference(); + if ( newMapping != null ) { + // group properties on current name. + PropertyEntry property = first( mapping.getSourceReference().getPropertyEntries() ); + if ( !mappingsKeyedByProperty.containsKey( property ) ) { + mappingsKeyedByProperty.put( property, new ArrayList() ); + } + mappingsKeyedByProperty.get( property ).add( newMapping ); + } + //This is an ignore, or some expression, or a default. We apply these to all + else if ( mapping.getSourceReference() == null ) { + appliesToAll.add( mapping ); + } + else { + nonNested.add( mapping ); + } + } + + populateWithSingleTargetReferences( mappingsKeyedByProperty, singleTargetReferences, PROPERTY_EXTRACTOR ); + + for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { + entry.getValue().addAll( appliesToAll ); + } + + List notProcessedAppliesToAll = new ArrayList(); + // If the applied to all were not added to all properties because they were empty, and the non-nested + // one are not empty, add them to the non-nested ones + if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { + nonNested.addAll( appliesToAll ); + } + // Otherwise if the non-nested are empty, just pass them along so they can be processed later on + else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { + notProcessedAppliesToAll.addAll( appliesToAll ); + } + + return new GroupedSourceReferences( + mappingsKeyedByProperty, + nonNested, + notProcessedAppliesToAll + ); } private Map> groupByTargetName(List mappingList) { @@ -218,5 +383,123 @@ private Map> groupByTargetName(List mappingList) } return result; } + + private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mappingOptions, + PropertyEntry targetProperty, SourceReference sourceReference, boolean forceUpdateMethod) { + PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() + .mappingContext( mappingContext ) + .sourceMethod( method ) + .targetProperty( targetProperty ) + .targetPropertyName( targetProperty.getName() ) + .sourceReference( sourceReference ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mappingOptions.collectNestedDependsOn() ) + .forgeMethodWithMappingOptions( mappingOptions ) + .forceUpdateMethod( forceUpdateMethod ) + .forgedNamedBased( false ) + .build(); + return propertyMapping; + } + + /** + * If a single target mapping has a valid {@link SourceReference} and the {@link SourceReference} has more + * then 0 {@link PropertyEntry} and if the {@code map} does not contain an entry with the extracted key then + * an entry with the extracted key and an empty list is added. + * + * @param map that needs to be populated + * @param singleTargetReferences to use + * @param keyExtractor to be used to extract a key + */ + private void populateWithSingleTargetReferences(Map> map, + List singleTargetReferences, Extractor keyExtractor) { + if ( singleTargetReferences != null ) { + //This are non nested target references only their property needs to be added as they most probably + // define it + for ( Mapping mapping : singleTargetReferences ) { + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() + && !mapping.getSourceReference().getPropertyEntries().isEmpty() ) { + //TODO is this OK? Why there are no propertyEntries? For the Inverse LetterMapper for example + K key = keyExtractor.apply( mapping.getSourceReference() ); + if ( !map.containsKey( key ) ) { + map.put( key, new ArrayList() ); + } + } + } + } + } + } + + private static class GroupedBySourceParameters { + private final Map> groupedBySourceParameter; + private final List notProcessedAppliesToAll; + + private GroupedBySourceParameters(Map> groupedBySourceParameter, + List notProcessedAppliesToAll) { + this.groupedBySourceParameter = groupedBySourceParameter; + this.notProcessedAppliesToAll = notProcessedAppliesToAll; + } + } + + /** + * The grouped target references. This class contains the poppedTarget references and the single target + * references (target references that were not nested). + */ + private static class GroupedTargetReferences { + private final Map> poppedTargetReferences; + private final Map> singleTargetReferences; + + private GroupedTargetReferences(Map> poppedTargetReferences, + Map> singleTargetReferences) { + this.poppedTargetReferences = poppedTargetReferences; + this.singleTargetReferences = singleTargetReferences; + } + } + + /** + * This class is used to group Source references in respected to the nestings that they have. + * + * This class contains all groupings by Property Entries if they are nested, or a list of all the other options + * that could not have been popped. + * + * So, take + * + * sourceReference 1: propertyEntryX.propertyEntryX1.propertyEntryX1a + * sourceReference 2: propertyEntryX.propertyEntryX2 + * sourceReference 3: propertyEntryY.propertyY1 + * sourceReference 4: propertyEntryZ + * sourceReference 5: propertyEntryZ2 + * + * We will have a map with entries: + *

    +     *
    +     * propertyEntryX - ( sourceReference1: propertyEntryX1.propertyEntryX1a,
    +     *                    sourceReference2 propertyEntryX2 )
    +     * propertyEntryY - ( sourceReference1: propertyEntryY1 )
    +     *
    +     * 
    + * + * If non-nested mappings were found they will be located in a List. + *
    +     * sourceReference 4: propertyEntryZ
    +     * sourceReference 5: propertyEntryZ2
    +     * 
    + * + *
    + * If Mappings that should apply to all were found, but no grouping was found, they will be located in a + * different list: + */ + private static class GroupedSourceReferences { + + private final Map> groupedBySourceReferences; + private final List nonNested; + private final List notProcessedAppliesToAll; + + private GroupedSourceReferences(Map> groupedBySourceReferences, + List nonNested, List notProcessedAppliesToAll) { + this.groupedBySourceReferences = groupedBySourceReferences; + this.nonNested = nonNested; + this.notProcessedAppliesToAll = notProcessedAppliesToAll; + + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index b11f9d3e42..dbe0eee278 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -73,7 +73,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem * * @return bean mapping that needs to be used for Mappings */ - public static BeanMapping forMappingsOnly() { + public static BeanMapping forForgedMethods() { return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 9eac9f92da..137628f71c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -202,6 +202,24 @@ private Mapping( Mapping mapping, TargetReference targetReference ) { this.targetReference = targetReference; } + private Mapping( Mapping mapping, SourceReference sourceReference ) { + this.sourceName = Strings.join( sourceReference.getElementNames(), "." ); + this.constant = mapping.constant; + this.javaExpression = mapping.javaExpression; + this.targetName = mapping.targetName; + this.defaultValue = mapping.defaultValue; + this.isIgnored = mapping.isIgnored; + this.mirror = mapping.mirror; + this.sourceAnnotationValue = mapping.sourceAnnotationValue; + this.targetAnnotationValue = mapping.targetAnnotationValue; + this.formattingParameters = mapping.formattingParameters; + this.selectionParameters = mapping.selectionParameters; + this.dependsOnAnnotationValue = mapping.dependsOnAnnotationValue; + this.dependsOn = mapping.dependsOn; + this.sourceReference = sourceReference; + this.targetReference = mapping.targetReference; + } + private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, FormattingMessager messager) { if ( mappingPrism.expression().isEmpty() ) { @@ -333,6 +351,16 @@ public Mapping popTargetReference() { return null; } + public Mapping popSourceReference() { + if ( sourceReference != null ) { + SourceReference newSourceReference = sourceReference.pop(); + if (newSourceReference != null ) { + return new Mapping(this, newSourceReference ); + } + } + return null; + } + public List getDependsOn() { return dependsOn; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index aabb1116c4..aa2d0cbea5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -76,16 +76,18 @@ public static MappingOptions empty() { * creates mapping options with only regular mappings * * @param mappings regular mappings to add + * @param restrictToDefinedMappings whether to restrict the mappings only to the defined mappings * @return MappingOptions with only regular mappings */ - public static MappingOptions forMappingsOnly( Map> mappings ) { + public static MappingOptions forMappingsOnly(Map> mappings, + boolean restrictToDefinedMappings) { return new MappingOptions( mappings, null, null, - BeanMapping.forMappingsOnly(), + restrictToDefinedMappings ? BeanMapping.forForgedMethods() : null, Collections.emptyList(), - true + restrictToDefinedMappings ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 1cd4063dce..d81c265408 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -320,6 +320,17 @@ public SourceReference copyForInheritanceTo(SourceMethod method) { return new SourceReference( replacement, propertyEntries, isValid ); } + public SourceReference pop() { + if ( propertyEntries.size() > 1 ) { + List newPropertyEntries = + new ArrayList( propertyEntries.subList( 1, propertyEntries.size() ) ); + return new SourceReference( parameter, newPropertyEntries, isValid ); + } + else { + return null; + } + } + @Override public String toString() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java new file mode 100644 index 0000000000..ec70657afd --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +/** + * This is a helper interface until we migrate to Java 8. It allows us to abstract our code easier. + * + * @param the type of the input to the function + * @param the type of the result of the function + * + * @author Filip Hrisafov + */ +public interface Extractor { + + /** + * Extract a value from the passed parameter. + * + * @param t the value that we need to extract from + * + * @return the result from the extraction + */ + R apply(T t); +} From 665f2571b6991fff634a4f349d397c38d5567ead Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 Feb 2017 19:09:56 +0100 Subject: [PATCH 0059/1006] #1057 Add forged named based parameter to distinguish between our methods that MapStruct has to create and methods that we create for the internal framework --- .../model/AbstractMappingMethodBuilder.java | 3 ++- .../ap/internal/model/BeanMappingMethod.java | 2 +- .../ap/internal/model/PropertyMapping.java | 17 +++++++++++++++-- .../ap/internal/model/source/ForgedMethod.java | 13 +++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 5be3fb186e..1c34d85ad7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -69,7 +69,8 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { shouldUsePropertyNamesInHistory(), sourceRHS.getSourceErrorMessagePart() ), - null + null, + true ); return createForgedBeanAssignment( sourceRHS, forgedMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 314659d526..b9ba81639c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -664,7 +664,7 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); //we handle automapping forged methods differently than the usual source ones. in - if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isAutoMapping() ) { + if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isForgedNamedBased() ) { ForgedMethod forgedMethod = (ForgedMethod) this.method; if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index e036e1d906..6e3bcd30db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -188,6 +188,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase additionalParameters, ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, - MappingOptions mappingOptions) { + MappingOptions mappingOptions, boolean forgedNameBased) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); @@ -116,6 +119,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu this.history = history; this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions; this.mappingOptions.initWithParameter( sourceParameter ); + this.forgedNameBased = forgedNameBased; } /** @@ -138,6 +142,7 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.contextProvidedMethods = forgedMethod.contextProvidedMethods; this.name = name; + this.forgedNameBased = forgedMethod.forgedNameBased; } @Override @@ -224,8 +229,8 @@ public ForgedMethodHistory getHistory() { return history; } - public boolean isAutoMapping() { - return mappingOptions.getValueMappings().isEmpty(); + public boolean isForgedNamedBased() { + return forgedNameBased; } public void addThrownTypes(List thrownTypesToAdd) { From 3192345e3365d8b99bebfee053f907b6064f0bfc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 15 Feb 2017 01:09:56 +0100 Subject: [PATCH 0060/1006] #1057 Add source fixtures for tests --- .../mixed/AutomappingAndNestedTest.java | 5 +- .../mixed/FishTankMapperConstantImpl.java | 32 +++++- .../mixed/FishTankMapperExpressionImpl.java | 104 ++++++++++++++++++ .../nestedbeans/mixed/FishTankMapperImpl.java | 25 +---- .../mixed/FishTankMapperWithDocumentImpl.java | 104 ++++++++++++++++++ 5 files changed, 246 insertions(+), 24 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java index 34206fdb9d..11522e05f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java @@ -82,7 +82,10 @@ public class AutomappingAndNestedTest { @Rule public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( - FishTankMapperConstant.class + FishTankMapper.class, + FishTankMapperConstant.class, + FishTankMapperExpression.class, + FishTankMapperWithDocument.class ); @Test diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java index 62f8a0aef1..14449cd99b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java @@ -21,14 +21,17 @@ import javax.annotation.Generated; import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.MaterialTypeDto; import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterPlantDto; import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.MaterialType; import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterPlant; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-13T00:35:18+0100", + date = "2017-02-19T16:25:03+0100", comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" ) public class FishTankMapperConstantImpl implements FishTankMapperConstant { @@ -41,6 +44,7 @@ public FishTankDto map(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); @@ -48,6 +52,32 @@ public FishTankDto map(FishTank source) { return fishTankDto; } + protected MaterialTypeDto materialTypeToMaterialTypeDto(MaterialType materialType) { + if ( materialType == null ) { + return null; + } + + MaterialTypeDto materialTypeDto = new MaterialTypeDto(); + + materialTypeDto.setType( materialType.getType() ); + + return materialTypeDto; + } + + protected MaterialDto fishTankToMaterialDto(FishTank fishTank) { + if ( fishTank == null ) { + return null; + } + + MaterialDto materialDto = new MaterialDto(); + + materialDto.setMaterialType( materialTypeToMaterialTypeDto( fishTank.getMaterial() ) ); + + materialDto.setManufacturer( "MMM" ); + + return materialDto; + } + protected FishDto fishToFishDto(Fish fish) { if ( fish == null ) { return null; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java new file mode 100644 index 0000000000..ed43e60741 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java @@ -0,0 +1,104 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityOrganisationDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityReportDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQuality; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQualityReport; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-19T16:25:03+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class FishTankMapperExpressionImpl implements FishTankMapperExpression { + + @Override + public FishTankDto map(FishTank source) { + if ( source == null ) { + return null; + } + + FishTankDto fishTankDto = new FishTankDto(); + + fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setName( source.getName() ); + fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); + + return fishTankDto; + } + + protected FishDto fishToFishDto(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + fishDto.setName( "Jaws" ); + + return fishDto; + } + + protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisationDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityOrganisationDto waterQualityOrganisationDto = new WaterQualityOrganisationDto(); + + waterQualityOrganisationDto.setName( "Dunno" ); + + return waterQualityOrganisationDto; + } + + protected WaterQualityReportDto waterQualityReportToWaterQualityReportDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityReportDto waterQualityReportDto = new WaterQualityReportDto(); + + waterQualityReportDto.setVerdict( waterQualityReport.getVerdict() ); + waterQualityReportDto.setOrganisation( waterQualityReportToWaterQualityOrganisationDto( waterQualityReport ) ); + + return waterQualityReportDto; + } + + protected WaterQualityDto waterQualityToWaterQualityDto(WaterQuality waterQuality) { + if ( waterQuality == null ) { + return null; + } + + WaterQualityDto waterQualityDto = new WaterQualityDto(); + + waterQualityDto.setReport( waterQualityReportToWaterQualityReportDto( waterQuality.getReport() ) ); + + return waterQualityDto; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 905133851e..974fa32afc 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -39,8 +39,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-12T21:48:04+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_45 (Oracle Corporation)" + date = "2017-02-19T16:25:02+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" ) public class FishTankMapperImpl implements FishTankMapper { @@ -76,7 +76,7 @@ public FishTankDto mapAsWell(FishTank source) { fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); - Ornament ornament = sourceInteriorOrnament1( source ); + Ornament ornament = sourceInteriorOrnament( source ); if ( ornament != null ) { fishTankDto.setOrnament( ornamentToOrnamentDto( ornament ) ); } @@ -181,7 +181,6 @@ protected WaterQualityDto waterQualityToWaterQualityDto(WaterQuality waterQualit } private Ornament sourceInteriorOrnament(FishTank fishTank) { - if ( fishTank == null ) { return null; } @@ -220,22 +219,6 @@ protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { return waterPlantDto; } - private Ornament sourceInteriorOrnament1(FishTank fishTank) { - - if ( fishTank == null ) { - return null; - } - Interior interior = fishTank.getInterior(); - if ( interior == null ) { - return null; - } - Ornament ornament = interior.getOrnament(); - if ( ornament == null ) { - return null; - } - return ornament; - } - protected Fish fishDtoToFish(FishDto fishDto) { if ( fishDto == null ) { return null; @@ -249,7 +232,6 @@ protected Fish fishDtoToFish(FishDto fishDto) { } private String waterQualityReportDtoOrganisationName(WaterQualityReportDto waterQualityReportDto) { - if ( waterQualityReportDto == null ) { return null; } @@ -317,7 +299,6 @@ protected Interior fishTankDtoToInterior(FishTankDto fishTankDto) { } private MaterialTypeDto sourceMaterialMaterialType(FishTankDto fishTankDto) { - if ( fishTankDto == null ) { return null; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java new file mode 100644 index 0000000000..141bf8bbc2 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java @@ -0,0 +1,104 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.mixed; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankWithNestedDocumentDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityOrganisationDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityReportDto; +import org.mapstruct.ap.test.nestedbeans.mixed._target.WaterQualityWithDocumentDto; +import org.mapstruct.ap.test.nestedbeans.mixed.source.Fish; +import org.mapstruct.ap.test.nestedbeans.mixed.source.FishTank; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQuality; +import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQualityReport; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-19T16:25:03+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class FishTankMapperWithDocumentImpl implements FishTankMapperWithDocument { + + @Override + public FishTankWithNestedDocumentDto map(FishTank source) { + if ( source == null ) { + return null; + } + + FishTankWithNestedDocumentDto fishTankWithNestedDocumentDto = new FishTankWithNestedDocumentDto(); + + fishTankWithNestedDocumentDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankWithNestedDocumentDto.setQuality( waterQualityToWaterQualityWithDocumentDto( source.getQuality() ) ); + fishTankWithNestedDocumentDto.setName( source.getName() ); + + return fishTankWithNestedDocumentDto; + } + + protected FishDto fishToFishDto(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + fishDto.setName( "Jaws" ); + + return fishDto; + } + + protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisationDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityOrganisationDto waterQualityOrganisationDto = new WaterQualityOrganisationDto(); + + waterQualityOrganisationDto.setName( "NoIdeaInc" ); + + return waterQualityOrganisationDto; + } + + protected WaterQualityReportDto waterQualityReportToWaterQualityReportDto(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityReportDto waterQualityReportDto = new WaterQualityReportDto(); + + waterQualityReportDto.setVerdict( waterQualityReport.getVerdict() ); + waterQualityReportDto.setOrganisation( waterQualityReportToWaterQualityOrganisationDto( waterQualityReport ) ); + + return waterQualityReportDto; + } + + protected WaterQualityWithDocumentDto waterQualityToWaterQualityWithDocumentDto(WaterQuality waterQuality) { + if ( waterQuality == null ) { + return null; + } + + WaterQualityWithDocumentDto waterQualityWithDocumentDto = new WaterQualityWithDocumentDto(); + + waterQualityWithDocumentDto.setDocument( waterQualityReportToWaterQualityReportDto( waterQuality.getReport() ) ); + + return waterQualityWithDocumentDto; + } +} From d4b0f3324b433e0c3e652ae816cb8e29fbf03348 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Feb 2017 01:25:33 +0100 Subject: [PATCH 0061/1006] #1057 Add some explanatory comments / Javadoc --- .../ap/internal/model/BeanMappingMethod.java | 11 +- .../NestedTargetPropertyMappingHolder.java | 153 ++++++++++++++++-- 2 files changed, 149 insertions(+), 15 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b9ba81639c..c9e438bd6f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -147,6 +147,7 @@ public BeanMappingMethod build() { applyParameterNameBasedMapping(); } + // Process the unprocessed defined targets handleUnprocessedDefinedTargets(); // report errors on unmapped properties @@ -220,11 +221,13 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { } /** - * If there were nested defined targets that have not been handled. The we need to process them at he end. + * If there were nested defined targets that have not been handled. Then we need to process them at the end. */ private void handleUnprocessedDefinedTargets() { Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); + // For each of the unprocessed defined targets forge a mapping for each of the + // method source parameters. The generated mappings are not going to use forged name based mappings. while ( iterator.hasNext() ) { Entry> entry = iterator.next(); String propertyName = entry.getKey(); @@ -315,6 +318,7 @@ private boolean handleDefinedMappings() { boolean errorOccurred = false; Set handledTargets = new HashSet(); + // first we have to handle nested target mappings if ( method.getMappingOptions().hasNestedTargetReferences() ) { handleDefinedNestedTargetMapping( handledTargets ); } @@ -355,6 +359,7 @@ private void handleDefinedNestedTargetMapping(Set handledTargets) { unprocessedSourceParameters.removeAll( holder.getProcessedSourceParameters() ); propertyMappings.addAll( holder.getPropertyMappings() ); handledTargets.addAll( holder.getHandledTargets() ); + // Store all the unprocessed defined targets. for ( Entry> entry : holder.getUnprocessedDefinedTarget().entrySet() ) { if ( entry.getValue().isEmpty() ) { continue; @@ -424,6 +429,8 @@ else if ( mapping.getSourceName() != null ) { } // its a constant + // if we have an unprocessed target that means that it most probably is nested and we should + // not generated any mapping for it now. Eventually it will be done though else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { propertyMapping = new ConstantMappingBuilder() @@ -441,6 +448,8 @@ else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKe } // its an expression + // if we have an unprocessed target that means that it most probably is nested and we should + // not generated any mapping for it now. Eventually it will be done though else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { propertyMapping = new JavaExpressionMappingBuilder() diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 3788cc6034..53223f1b7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -128,28 +128,39 @@ public NestedTargetPropertyMappingHolder build() { Set handledTargets = new HashSet(); List propertyMappings = new ArrayList(); + // first we group by the first property in the target properties and for each of those + // properties we get the new mappings as if the first property did not exist. GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); Map> unprocessedDefinedTarget = new HashMap>(); for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { PropertyEntry targetProperty = entryByTP.getKey(); + //Now we are grouping the already popped mappings by the source parameter(s) of the method GroupedBySourceParameters groupedBySourceParam = groupBySourceParameter( entryByTP.getValue(), groupedByTP.singleTargetReferences.get( targetProperty ) ); boolean forceUpdateMethod = groupedBySourceParam.groupedBySourceParameter.keySet().size() > 1; + // All not processed mappings that should have been applied to all are part of the unprocessed + // defined targets unprocessedDefinedTarget.put( targetProperty, groupedBySourceParam.notProcessedAppliesToAll ); for ( Map.Entry> entryByParam : groupedBySourceParam .groupedBySourceParameter.entrySet() ) { Parameter sourceParameter = entryByParam.getKey(); + // Lastly we need to group by the source references. This will allow us to actually create + // the next mappings by popping source elements GroupedSourceReferences groupedSourceReferences = groupByPoppedSourceReferences( entryByParam.getValue(), groupedByTP.singleTargetReferences.get( targetProperty ) ); + // For all the groupedBySourceReferences we need to create property mappings + // from the Mappings and not restrict on the defined mappings (allow to forge name based mapping) + // if we have composite methods i.e. more then 2 parameters then we have to force a creation + // of an update method in our generation for ( Map.Entry> entryBySP : groupedSourceReferences .groupedBySourceReferences .entrySet() ) { @@ -180,6 +191,9 @@ public NestedTargetPropertyMappingHolder build() { handledTargets.add( entryByTP.getKey().getName() ); } + // For the nonNested mappings (assymetric) Mappings we also forge mappings + // However, here we do not forge name based mappings and we only + // do update on the defined Mappings. if ( !groupedSourceReferences.nonNested.isEmpty() ) { MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( groupByTargetName( groupedSourceReferences.nonNested ), @@ -220,24 +234,43 @@ public NestedTargetPropertyMappingHolder build() { * The target references are popped. The {@code List<}{@link Mapping}{@code >} are keyed on the unique first * entries of the target references. * - * So, take + *

    + *

    + * Group all target references by their first property and for each such mapping use a new one where the + * first property will be removed from it. If a {@link org.mapstruct.Mapping} cannot be popped, i.e. it + * contains a non nested target property just keep it as is (this is usually needed to control how an + * intermediary level can be mapped). * - * targetReference 1: propertyEntryX.propertyEntryX1.propertyEntryX1a - * targetReference 2: propertyEntryX.propertyEntryX2 - * targetReference 3: propertyEntryY.propertyY1 - * targetReference 4: propertyEntryZ + *

    + *

    + * We start with the following mappings: * - * will be popped and grouped into entries: + *

    +         * {@literal @}Mapping(target = "fish.kind", source = "fish.type"),
    +         * {@literal @}Mapping(target = "fish.name", ignore = true),
    +         * {@literal @}Mapping(target = "ornament", ignore = true ),
    +         * {@literal @}Mapping(target = "material.materialType", source = "material"),
    +         * {@literal @}Mapping(target = "document", source = "report"),
    +         * {@literal @}Mapping(target = "document.organisation.name", source = "report.organisationName")
    +         * 
    * - * propertyEntryX - List ( targetReference1: propertyEntryX1.propertyEntryX1a, - * targetReference2: propertyEntryX2 ) - * propertyEntryY - List ( targetReference1: propertyEntryY1 ) + * We will get this: * - * The key will be the former top level property, the MappingOptions will contain the remainders. + *
    +         * // All target references are popped and grouped by their first property
    +         * GroupedTargetReferences.poppedTargetReferences {
    +         *     fish:     {@literal @}Mapping(target = "kind", source = "fish.type"),
    +         *               {@literal @}Mapping(target = "name", ignore = true);
    +         *     material: {@literal @}Mapping(target = "materialType", source = "material");
    +         *     document: {@literal @}Mapping(target = "organization.name", source = "report.organizationName");
    +         * }
              *
    -         * If the target reference cannot be popped it is stored in a different map. That looks like:
    -         *
    -         * propertyEntryZ - List ( targetReference4: propertyEntryZ )
    +         * //This references are not nested and we they stay as they were
    +         * GroupedTargetReferences.singleTargetReferences {
    +         *     document: {@literal @}Mapping(target = "document", source = "report");
    +         *     ornament: {@literal @}Mapping(target = "ornament", ignore = true );
    +         * }
    +         * 
    * * @param mappingOptions that need to be used to create the {@link GroupedTargetReferences} * @@ -275,6 +308,78 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp * Note: this method is used for forging nested update methods. For that purpose, the same method with all * joined mappings should be generated. See also: NestedTargetPropertiesTest#shouldMapNestedComposedTarget * + * Mappings: + *
    +         * {@literal @}Mapping(target = "organization.name", source = "report.organizationName");
    +         * 
    + * + * singleTargetReferences: + *
    +         * {@literal @}Mapping(target = "document", source = "report");
    +         * 
    + * + * We assume that all properties belong to the same source parameter (fish). We are getting this in return: + * + *
    +         * GroupedBySourceParameters.groupedBySourceParameter {
    +         *     fish: {@literal @}Mapping(target = "organization.name", source = "report.organizationName");
    +         * }
    +         *
    +         * GroupedBySourceParameters.notProcessedAppliesToAll {} //empty
    +         *
    +         * 
    + * + * Notice how the {@code singleTargetReferences} are missing. They are used for situations when there are + * mappings without source. Such as: + * Mappings: + *
    +         * {@literal @}Mapping(target = "organization.name", expression="java(\"Dunno\")");
    +         * 
    + * + * singleTargetReferences: + *
    +         * {@literal @}Mapping(target = "document", source = "report");
    +         * 
    + * + * The mappings have no source reference so we cannot extract the source parameter from them. When mappings + * have no source properties then we apply those to all of them. In this case we have a single target + * reference that can provide a source parameter. So we will get: + *
    +         * GroupedBySourceParameters.groupedBySourceParameter {
    +         *     fish: {@literal @}Mapping(target = "organization.name", expression="java(\"Dunno\")");
    +         * }
    +         *
    +         * GroupedBySourceParameters.notProcessedAppliesToAll {} //empty
    +         * 
    + * + *

    + * See also how the {@code singleTargetReferences} are not part of the mappings. They are used only to + * make sure that their source parameter is taken into consideration in the next step. + * + *

    + * The {@code notProcessedAppliesToAll} contains all Mappings that should have been applied to all but have not + * because there were no other mappings that we could have used to pass them along. These + * {@link org.mapstruct.Mapping}(s) are used later on for normal mapping. + * + *

    + * If we only had: + *

    +         * {@literal @}Mapping(target = "document", source = "report");
    +         * {@literal @}Mapping(target = "ornament", ignore = true );
    +         * 
    + * + * Then we only would have had: + *
    +         * GroupedBySourceParameters.notProcessedAppliesToAll {
    +         * {@literal @}Mapping(target = "document", source = "report");
    +         * {@literal @}Mapping(target = "ornament", ignore = true );
    +         * }
    +         * 
    + * + * These mappings will be part of the {@code GroupedBySourceParameters.notProcessedAppliesToAll} and are + * used to be passed to the normal defined mapping. + * + * * @param mappings that mappings that need to be used for the grouping * @param singleTargetReferences a List containing all non-nested mappings for the same grouped target * property as the {@code mappings} @@ -318,6 +423,26 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, * Creates a nested grouping by popping the source mappings. See the description of the class to see what is * generated. * + * Mappings: + *
    +         * {@literal @}Mapping(target = "organization.name", source = "report.organizationName");
    +         * 
    + * + * singleTargetReferences: + *
    +         * {@literal @}Mapping(target = "document", source = "report");
    +         * 
    + * + * And we get: + * + *
    +         * GroupedSourceReferences.groupedBySourceReferences {
    +         *     report: {@literal @}Mapping(target = "organization.name", source = "organizationName");
    +         * }
    +         * 
    + * + * + * * @param mappings the list of {@link Mapping} that needs to be used for grouping on popped source references * @param singleTargetReferences the single target references that match the source mappings * @@ -484,7 +609,7 @@ private GroupedTargetReferences(Map> poppedTargetRe * sourceReference 5: propertyEntryZ2 * * - *
    + *

    * If Mappings that should apply to all were found, but no grouping was found, they will be located in a * different list: */ From 51e5976a7f99006f7cc1372854a13aa81882ce3d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 20 Feb 2017 19:19:42 +0100 Subject: [PATCH 0062/1006] #1001 Update documentation for the new automapping --- .../mapstruct-reference-guide.asciidoc | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index d1e0d9174d..9e0f26449b 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -338,6 +338,7 @@ public class CarMapperImpl implements CarMapper { if ( car.getCategory() != null ) { carDto.setCategory( car.getCategory().toString() ); } + carDto.setEngine( engineTtoEngineDto( car.getEngine() ) ); return carDto; } @@ -346,13 +347,31 @@ public class CarMapperImpl implements CarMapper { public PersonDto personToPersonDto(Person person) { //... } + + private EngineDto engineToEngineDto(Engine engine) { + if ( engine == null ) { + return null; + } + + EngineDto engineDto = new EngineDto(); + + engineDto.setHorsePower(engine.getHorsePower()); + engineDto.setFuel(engine.getFuel()); + + return engineDto; + } } ---- ==== The general philosophy of MapStruct is to generate code which looks as much as possible as if you had written it yourself from hand. In particular this means that the values are copied from source to target by plain getter/setter invocations instead of reflection or similar. -As the example shows the generated code takes into account any name mappings specified via `@Mapping`. If the type of a mapped attribute is different in source and target entity, MapStruct will either apply an automatic conversion (as e.g. for the _price_ property, see also <>) or optionally invoke another mapping method (as e.g. for the _driver_ property, see also <>). +As the example shows the generated code takes into account any name mappings specified via `@Mapping`. +If the type of a mapped attribute is different in source and target entity, +MapStruct will either apply an automatic conversion (as e.g. for the _price_ property, see also <>) +or optionally invoke / create another mapping method (as e.g. for the _driver_ / _engine_ property, see also <>). +MapStruct will only create a new mapping method if and only if the source and target property are properties of a Bean and they themselves are Beans or simple properties. +i.e. they are not `Collection` or `Map` type properties. Collection-typed attributes with the same element type will be copied by creating a new instance of the target collection type containing the elements from the source property. For collection-typed attributes with different element types each element will be mapped individually and added to the target collection (see <>). @@ -805,7 +824,8 @@ When generating the implementation of a mapping method, MapStruct will apply the * If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. * If source and target attribute type differ, check whether there is a another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. * If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. -* Otherwise an error will be raised at build time, indicating the non-mappable attribute. +* If no such method was found MapStruct will try to generate an internal method that will do the mapping between the source and target attributes +* If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. [[invoking-other-mappers]] === Invoking other mappers From 582bbe44128581d6841b737beddbbdea216f1362 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Mon, 20 Feb 2017 19:21:15 +0100 Subject: [PATCH 0063/1006] #1057 documentation for Controlling forged name based bean mapping from root level with @Mapping --- .../controlling-nested-bean-mappings.asciidoc | 87 +++++++++++++++++++ .../mapstruct-reference-guide.asciidoc | 36 +++----- 2 files changed, 101 insertions(+), 22 deletions(-) create mode 100644 documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc diff --git a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc new file mode 100644 index 0000000000..4fdcdf5570 --- /dev/null +++ b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc @@ -0,0 +1,87 @@ +[[controlling-nested-bean-mappings]] +=== Controlling nested bean mappings + +As explained above, MapStruct will generate a method based on the name of the source and target property. Unfortunately, in many occasions these names do not match. + +The ‘.’ notation in an `@Mapping` source or target type can be used to control how properties should be mapped when names do not match. +There is an elaborate https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-nested-bean-mappings[example] in our examples repository to explain how this problem can be overcome. + +In the simplest scenario there’s a property on a nested level that needs to be corrected. +Take for instance a property `fish` which has an identical name in `FishTankDto` and `FishTank`. +For this property MapStruct automatically generates a mapping: `FishDto fishToFishDto(Fish fish)`. +MapStruct cannot possibly be aware of the deviating properties `kind` and `type`. +Therefore this can be addressed in a mapping rule: `@Mapping(target="fish.kind", source="fish.type")`. +This tells MapStruct to deviate from looking for a name `kind` at this level and map it to `type`. + +.Mapper controlling nested beans mappings I +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface FishTankMapper { + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", ignore = true), + @Mapping(target = "ornament", source = "interior.ornament"), + @Mapping(target = "material.materialType", source = "material"), + @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") + }) + FishTankDto map( FishTank source ); +} +---- +==== + +The same constructs can be used to ignore certain properties at a nesting level, as is demonstrated in the second `@Mapping` rule. + +MapStruct can even be used to “cherry pick” properties when source and target do not share the same nesting level (the same number of properties). +This can be done in the source – and in the target type. This is demonstrated in the next 2 rules: `@Mapping(target="ornament", source="interior.ornament")` and `@Mapping(target="material.materialType", source="material")`. + +The latter can even be done when mappings first share a common base. +For example: all properties that share the same name of `Quality` are mapped to `QualityDto`. +Likewise, all properties of `Report` are mapped to `ReportDto`, with one exception: `organisation` in `OrganisationDto` is left empty (since there is no organization at the source level). +Only the `name` is populated with the `organisationName` from `Report`. +This is demonstrated in `@Mapping(target="quality.report.organisation.name", source="quality.report.organisationName")` + +Coming back to the original example: what if `kind` and `type` would be beans themselves? +In that case MapStruct would again generate a method continuing to map. +Such is demonstrated in the next example: + + +.Mapper controlling nested beans mappings II +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface FishTankMapperWithDocument { + + @Mappings({ + @Mapping(target = "fish.kind", source = "fish.type"), + @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), + @Mapping(target = "plant", ignore = true ), + @Mapping(target = "ornament", ignore = true ), + @Mapping(target = "material", ignore = true), + @Mapping(target = "quality.document", source = "quality.report"), + @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) + }) + FishTankWithNestedDocumentDto map( FishTank source ); + +} +---- +==== + +Note what happens in `@Mapping(target="quality.document", source="quality.report")`. +`DocumentDto` does not exist as such on the target side. It is mapped from `Report`. +MapStruct continues to generate mapping code here. That mapping it self can be guided towards another name. +This even works for constants and expression. Which is shown in the final example: `@Mapping(target="quality.document.organisation.name", constant="NoIdeaInc")`. + +MapStruct will perform a null check on each nested property in the source. + +[TIP] +==== +Instead of configuring everything via the parent method we encourage users to explicitly write their own nested methods. +This puts the configuration of the nested mapping into one place (method) where it can be reused from several methods in the upper level, +instead of re-configuring the same things on all of those upper methods. +==== diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 9e0f26449b..6fe7ddcb00 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -466,36 +466,26 @@ Specifying the parameter in which the property resides is mandatory when using t Mapping methods with several source parameters will return `null` in case all the source parameters are `null`. Otherwise the target object will be instantiated and all properties from the provided parameters will be propagated. ==== -[[nested-mappings]] -=== Nested mappings +MapStruct also offers the possibility to directly refer to a source parameter. -MapStruct will handle nested mappings (in source), by means of the `.` notation: - -.Mapping method with several source parameters +.Mapping method directly referring to a source parameter ==== [source, java, linenums] [subs="verbatim,attributes"] ---- -@Mappings({ - @Mapping(target = "chartName", source = "chart.name"), - @Mapping(target = "title", source = "song.title"), - @Mapping(target = "artistName", source = "song.artist.name"), - @Mapping(target = "recordedAt", source = "song.artist.label.studio.name"), - @Mapping(target = "city", source = "song.artist.label.studio.city"), - @Mapping(target = "position", source = "position") -}) -ChartEntry map(Chart chart, Song song, Integer position); +@Mapper +public interface AddressMapper { + + @Mappings({ + @Mapping(source = "person.description", target = "description"), + @Mapping(source = "hn", target = "houseNumber") + }) + DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn); +} ---- ==== -Note: the parameter name (`chart`, `song`, `position`) is required, since there are several source parameters in the mapping. If there's only one source parameter, the parameter name can be ommited. - -MapStruct will perform a null check on each nested property in the source. - -[TIP] -==== -Also non java bean source parameters (like the `java.lang.Integer`) can be mapped in this fashion. -==== +In this case the source parameter is directly mapped into the target as the example above demonstrates. The parameter `hn`, a non bean type (in this case `java.lang.Integer`) is mapped to `houseNumber`. [[updating-bean-instances]] === Updating existing bean instances @@ -827,6 +817,8 @@ When generating the implementation of a mapping method, MapStruct will apply the * If no such method was found MapStruct will try to generate an internal method that will do the mapping between the source and target attributes * If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. +include::controlling-nested-bean-mappings.asciidoc[] + [[invoking-other-mappers]] === Invoking other mappers From 520451bcd86713be950e1d215ff9b9baec5ed023 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Mon, 20 Feb 2017 20:58:12 +0100 Subject: [PATCH 0064/1006] [maven-release-plugin] prepare release 1.2.0.Beta1 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..be98ef8384 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..d37de3b983 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 171f5b0765..ee0e8abea9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ae7ca0e79b..fb7da1e869 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..f7d465e12e 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..9ef430c09a 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..57d1924337 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 3026e8737e..3eb53f7ded 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta1 diff --git a/pom.xml b/pom.xml index 63b61ce435..4ca65e7c14 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta1 diff --git a/processor/pom.xml b/processor/pom.xml index 2a2c9c9296..618c31bd9b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta1 ../parent/pom.xml From 3cc89721265f24a743c850c288842909791134af Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Mon, 20 Feb 2017 20:58:14 +0100 Subject: [PATCH 0065/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index be98ef8384..f857058844 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d37de3b983..d5555f9220 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index ee0e8abea9..171f5b0765 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index fb7da1e869..ae7ca0e79b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f7d465e12e..b2dcceaefa 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 9ef430c09a..e24f75f1f6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 57d1924337..0b8fb827cf 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 3eb53f7ded..3026e8737e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta1 + HEAD diff --git a/pom.xml b/pom.xml index 4ca65e7c14..63b61ce435 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 618c31bd9b..2a2c9c9296 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta1 + 1.2.0-SNAPSHOT ../parent/pom.xml From 10aeb444f531d3f9fa9344d3b7eae5f4501c1a06 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 21 Feb 2017 20:43:19 +0100 Subject: [PATCH 0066/1006] #1091 Map ANY_REMAINING Enum source to null --- .../ap/internal/model/ValueMappingMethod.java | 4 +- .../ap/test/value/EnumToEnumMappingTest.java | 32 ++++++ .../ap/test/value/SpecialOrderMapper.java | 14 ++- .../ap/test/value/DefaultOrderMapperImpl.java | 57 ++++++++++ .../ap/test/value/OrderMapperImpl.java | 90 +++++++++++++++ .../ap/test/value/SpecialOrderMapperImpl.java | 107 ++++++++++++++++++ 6 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index f4533a3110..6831c20fa3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -105,7 +105,9 @@ public ValueMappingMethod build( ) { nullTarget = nullTargetValue.getTarget(); } if ( defaultTargetValue != null ) { - defaultTarget = defaultTargetValue.getTarget(); + // If the default target value is NULL then we should map it to null + defaultTarget = MappingConstantsPrism.NULL.equals( defaultTargetValue.getTarget() ) ? null : + defaultTargetValue.getTarget(); } else { throwIllegalArgumentException = true; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java index 85e03a4ff9..96ecef590f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java @@ -22,6 +22,7 @@ import javax.tools.Diagnostic.Kind; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -30,6 +31,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * Test for the generation and invocation of enum mapping methods. @@ -42,6 +44,13 @@ @RunWith(AnnotationProcessorTestRunner.class) public class EnumToEnumMappingTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + DefaultOrderMapper.class, + OrderMapper.class, + SpecialOrderMapper.class + ); + @Test public void shouldGenerateEnumMappingMethod() { ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.B2B ); @@ -188,6 +197,29 @@ public void shouldMappAllUnmappedToDefault() { } + @IssueKey( "1091" ) + @Test + public void shouldMapAnyRemainingToNullCorrectly() throws Exception { + ExternalOrderType externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.RETAIL ); + assertThat( externalOrderType ) + .isNotNull() + .isEqualTo( ExternalOrderType.RETAIL ); + + externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.B2B ); + assertThat( externalOrderType ) + .isNotNull() + .isEqualTo( ExternalOrderType.B2B ); + + externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.EXTRA ); + assertThat( externalOrderType ).isNull(); + + externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.STANDARD ); + assertThat( externalOrderType ).isNull(); + + externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.NORMAL ); + assertThat( externalOrderType ).isNull(); + } + @Test @WithClasses(ErroneousOrderMapperMappingSameConstantTwice.class) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java index 3f215b0655..396bd82eac 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java @@ -20,7 +20,9 @@ import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.MappingConstants; +import org.mapstruct.Named; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; import org.mapstruct.factory.Mappers; @@ -33,8 +35,11 @@ public interface SpecialOrderMapper { SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); + + @Mapping(target = "orderType", source = "orderType", qualifiedByName = "orderTypeToExternalOrderType") OrderDto orderEntityToDto(OrderEntity order); + @Named("orderTypeToExternalOrderType") @ValueMappings({ @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ), @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ), @@ -42,7 +47,14 @@ public interface SpecialOrderMapper { }) ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); - @InheritInverseConfiguration + @InheritInverseConfiguration(name = "orderTypeToExternalOrderType") @ValueMapping( target = "EXTRA", source = "SPECIAL" ) OrderType externalOrderTypeToOrderType(ExternalOrderType orderType); + + @ValueMappings({ + @ValueMapping(source = MappingConstants.NULL, target = "DEFAULT"), + @ValueMapping(source = "STANDARD", target = MappingConstants.NULL), + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + }) + ExternalOrderType anyRemainingToNull(OrderType orderType); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java new file mode 100644 index 0000000000..270f31168c --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java @@ -0,0 +1,57 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.value; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-20T21:25:45+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class DefaultOrderMapperImpl implements DefaultOrderMapper { + + @Override + public OrderDto orderEntityToDto(OrderEntity order) { + if ( order == null ) { + return null; + } + + OrderDto orderDto = new OrderDto(); + + orderDto.setOrderType( orderTypeToExternalOrderType( order.getOrderType() ) ); + + return orderDto; + } + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java new file mode 100644 index 0000000000..8fc0647061 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java @@ -0,0 +1,90 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.value; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-20T21:25:45+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class OrderMapperImpl implements OrderMapper { + + @Override + public OrderDto orderEntityToDto(OrderEntity order) { + if ( order == null ) { + return null; + } + + OrderDto orderDto = new OrderDto(); + + orderDto.setOrderType( orderTypeToExternalOrderType( order.getOrderType() ) ); + + return orderDto; + } + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case EXTRA: externalOrderType = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } + + @Override + public OrderType externalOrderTypeToOrderType(ExternalOrderType orderType) { + if ( orderType == null ) { + return null; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = OrderType.STANDARD; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java new file mode 100644 index 0000000000..489af7dfc1 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java @@ -0,0 +1,107 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.value; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-02-20T21:25:45+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class SpecialOrderMapperImpl implements SpecialOrderMapper { + + @Override + public OrderDto orderEntityToDto(OrderEntity order) { + if ( order == null ) { + return null; + } + + OrderDto orderDto = new OrderDto(); + + orderDto.setOrderType( orderTypeToExternalOrderType( order.getOrderType() ) ); + + return orderDto; + } + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return ExternalOrderType.DEFAULT; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case STANDARD: externalOrderType = null; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = ExternalOrderType.SPECIAL; + } + + return externalOrderType; + } + + @Override + public OrderType externalOrderTypeToOrderType(ExternalOrderType orderType) { + if ( orderType == null ) { + return OrderType.STANDARD; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = null; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } + + @Override + public ExternalOrderType anyRemainingToNull(OrderType orderType) { + if ( orderType == null ) { + return ExternalOrderType.DEFAULT; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case STANDARD: externalOrderType = null; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = null; + } + + return externalOrderType; + } +} From 0f6d5ff0f87d13c61fb2148d57b418360b7212f6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 21 Feb 2017 21:25:25 +0100 Subject: [PATCH 0067/1006] Fix checkstyle error --- .../java/org/mapstruct/ap/test/value/SpecialOrderMapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java index 396bd82eac..fb4e197c0c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java @@ -34,8 +34,7 @@ public interface SpecialOrderMapper { SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); - - + @Mapping(target = "orderType", source = "orderType", qualifiedByName = "orderTypeToExternalOrderType") OrderDto orderEntityToDto(OrderEntity order); From f654da256350b8d72d29c7a30d29cf6e7c266a06 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 21 Feb 2017 21:13:41 +0100 Subject: [PATCH 0068/1006] #1059 Add ftlvariable to the ftl files so we can have autocomplete with IntelliJ --- .../mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl | 1 + .../resources/org/mapstruct/ap/internal/model/Annotation.ftl | 1 + .../mapstruct/ap/internal/model/AnnotationMapperReference.ftl | 1 + .../org/mapstruct/ap/internal/model/BeanMappingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/DecoratorConstructor.ftl | 1 + .../org/mapstruct/ap/internal/model/DefaultMapperReference.ftl | 1 + .../org/mapstruct/ap/internal/model/DelegatingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/EnumMappingMethod.ftl | 1 + .../main/resources/org/mapstruct/ap/internal/model/Field.ftl | 1 + .../org/mapstruct/ap/internal/model/IterableMappingMethod.ftl | 1 + .../ap/internal/model/LifecycleCallbackMethodReference.ftl | 1 + .../org/mapstruct/ap/internal/model/MapMappingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/MethodReference.ftl | 1 + .../mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/PropertyMapping.ftl | 1 + .../resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl | 1 + .../resources/org/mapstruct/ap/internal/model/SourceRHS.ftl | 1 + .../org/mapstruct/ap/internal/model/TypeConversion.ftl | 1 + .../org/mapstruct/ap/internal/model/ValueMappingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl | 1 + .../mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl | 1 + .../ap/internal/model/assignment/EnumConstantWrapper.ftl | 1 + .../model/assignment/GetterWrapperForCollectionsAndMaps.ftl | 1 + .../mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl | 1 + .../mapstruct/ap/internal/model/assignment/SetterWrapper.ftl | 1 + .../model/assignment/SetterWrapperForCollectionsAndMaps.ftl | 1 + .../mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl | 1 + .../org/mapstruct/ap/internal/model/common/Parameter.ftl | 1 + .../resources/org/mapstruct/ap/internal/model/common/Type.ftl | 2 +- .../model/source/builtin/CalendarToXmlGregorianCalendar.ftl | 1 + .../internal/model/source/builtin/CalendarToZonedDateTime.ftl | 1 + .../model/source/builtin/DateToXmlGregorianCalendar.ftl | 1 + .../ap/internal/model/source/builtin/JaxbElemToValue.ftl | 1 + .../model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl | 1 + .../source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl | 1 + .../source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl | 1 + .../source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl | 1 + .../model/source/builtin/LocalDateToXmlGregorianCalendar.ftl | 1 + .../model/source/builtin/StringToXmlGregorianCalendar.ftl | 1 + .../model/source/builtin/XmlGregorianCalendarToCalendar.ftl | 1 + .../model/source/builtin/XmlGregorianCalendarToDate.ftl | 1 + .../model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl | 1 + .../source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl | 1 + .../source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl | 1 + .../source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl | 1 + .../model/source/builtin/XmlGregorianCalendarToLocalDate.ftl | 1 + .../model/source/builtin/XmlGregorianCalendarToString.ftl | 1 + .../internal/model/source/builtin/ZonedDateTimeToCalendar.ftl | 1 + 48 files changed, 48 insertions(+), 1 deletion(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl index 1ac9a988ff..4c8894abf4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index 12f39775ba..2be168662c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl index 586ac6914d..fa4e5dcfb7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotationMapperReference" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 2d9a738f52..1db3e2586b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.BeanMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl index 22e9d22cbc..46dee8b6ef 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DecoratorConstructor" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl index f43d709bb6..034a5ff812 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl index ca56ba2b8c..bdbc8f3829 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DelegatingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl index fbac4c719e..b8d0498cee 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.EnumMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl index 2a6d8f28ac..a21e77fecd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Field" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 502e99fc13..a06c5d9e56 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl index 348e6704fb..e34de1733b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.LifecycleCallbackMethodReference" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 8185dea2a9..9acca2636d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index c7af8d074d..0706a3a1eb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReference" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 5921682ebc..51f6fae684 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index a623008778..86a623e177 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.PropertyMapping" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl index 483f86b183..1963e84eb2 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ServicesEntry" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl index 03ae93b8fd..4b3df1fd1a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SourceRHS" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl index 02189fe6a6..b9469b048a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.TypeConversion" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 1d06e9ee10..2f648fda9d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index 2a4f833a17..a3a781aabd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.AdderWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl index 649cd7e540..d1b43febb8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl index f540da2655..03f8f385d9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index 0ed03abbd6..01dd1899b7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl index 5e4945b483..00bed2a9e3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.LocalVarWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index b12f246ea6..6df7b17148 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index f5292173b5..c681e2a8ee 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index dd069f27c3..2b65784425 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.UpdateWrapper" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl index 45ed5e1344..ab33a5100a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Parameter" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 503c266f02..1d63cb3201 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -1,4 +1,4 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> + <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl index 602c574aeb..b716b46f2c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl index 3d32cb9089..8ca07603a3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl index 677cbb5793..6442c12ec7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl index e140bbc034..af314d442f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl index 7b2e211db1..386ea8b8fb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl index 36357b60a7..04c5c98108 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl index 96f7a78f7e..f3244626e3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl index 42cc51c653..c518fb8524 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl index 5a628c6921..6103838c80 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl index 41bd594021..0cac9015ce 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl index 820ab1fc31..782ba83d7e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl index b75c0c08d3..a62cf38cdf 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl index ed5d6d0c8e..80cdf46610 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl index 93d335d028..24ec1391d7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl index 56cdaa79e2..a57e607baa 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl index ef7dbee62f..9d0c2af94d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl index ed37379fc5..2a53fcd6eb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl index 553ba83a96..63437c8b6a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl index 8703f4e53e..88c943e5fc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) From 7d56a85dbd5ab14202d5259f143def77eddc0dc2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 21 Feb 2017 21:35:13 +0100 Subject: [PATCH 0069/1006] Fix checkstyle error --- .../java/org/mapstruct/ap/test/value/SpecialOrderMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java index fb4e197c0c..26fca87004 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java @@ -34,7 +34,7 @@ public interface SpecialOrderMapper { SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); - + @Mapping(target = "orderType", source = "orderType", qualifiedByName = "orderTypeToExternalOrderType") OrderDto orderEntityToDto(OrderEntity order); From 13c3d878d83ccdce66d686a44e51774e8dae21df Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Wed, 22 Feb 2017 20:31:19 +0100 Subject: [PATCH 0070/1006] Updating link to ref guide --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 8fc37db50c..4be2eda1d6 100644 --- a/readme.md +++ b/readme.md @@ -117,7 +117,7 @@ If you don't work with a dependency management tool you can obtain a distributio ## Documentation and getting help -To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation) covers all provided functionality in detail. If you need help, come and join the [mapstruct-users](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) group. +To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help, come and join the [mapstruct-users](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) group. ## Licensing From fa20d030511ee5b07af78baac05bf7f11e64f084 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 5 Feb 2017 23:08:47 +0100 Subject: [PATCH 0071/1006] #1065 @InheritReverseConfiguration from MappingConfig --- .../internal/model/source/SourceMethod.java | 23 ++++++++-- .../processor/MapperCreationProcessor.java | 28 +++++++++++-- .../mapstruct/ap/internal/util/Message.java | 1 + ...rMapperReverseWithExplicitInheritance.java | 42 +++++++++++++++++++ .../InheritFromConfigTest.java | 15 +++++++ .../ArtistToChartEntryConfig.java | 2 +- .../ArtistToChartEntryWithConfigReverse.java | 2 +- 7 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 9361ddb3e6..f0f6108d83 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -76,6 +76,7 @@ public class SourceMethod implements Method { private List parameterNames; private List applicablePrototypeMethods; + private List applicableReversePrototypeMethods; private Boolean isBeanMapping; private Boolean isEnumMapping; @@ -312,11 +313,11 @@ public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { } public boolean reverses(SourceMethod method) { - return getDeclaringMapper() == null - && isAbstract() + return method.getDeclaringMapper() == null + && method.isAbstract() && getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 - && equals( first( getSourceParameters() ).getType(), method.getResultType() ) - && equals( getResultType(), first( method.getSourceParameters() ).getType() ); + && first( getSourceParameters() ).getType().isAssignableTo( method.getResultType() ) + && getResultType().isAssignableTo( first( method.getSourceParameters() ).getType() ); } public boolean isSame(SourceMethod method) { @@ -486,6 +487,20 @@ public List getApplicablePrototypeMethods() { return applicablePrototypeMethods; } + public List getApplicableReversePrototypeMethods() { + if ( applicableReversePrototypeMethods == null ) { + applicableReversePrototypeMethods = new ArrayList(); + + for ( SourceMethod prototype : prototypeMethods ) { + if ( reverses( prototype ) ) { + applicableReversePrototypeMethods.add( prototype ); + } + } + } + + return applicableReversePrototypeMethods; + } + private static boolean allParametersAreAssignable(List fromParams, List toParams) { if ( fromParams.size() == toParams.size() ) { Set unaccountedToParams = new HashSet( toParams ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 00d5a7f93d..6c8e78a4d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -424,10 +424,15 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp initializingMethods.add( method ); MappingOptions mappingOptions = method.getMappingOptions(); - List applicablePrototypeMethods = method.getApplicablePrototypeMethods(); + List applicableReversePrototypeMethods = method.getApplicableReversePrototypeMethods(); MappingOptions inverseMappingOptions = - getInverseMappingOptions( availableMethods, method, initializingMethods, mapperConfig ); + getInverseMappingOptions( join( availableMethods, applicableReversePrototypeMethods ), + method, + initializingMethods, + mapperConfig ); + + List applicablePrototypeMethods = method.getApplicablePrototypeMethods(); MappingOptions templateMappingOptions = getTemplateMappingOptions( @@ -457,6 +462,21 @@ else if ( applicablePrototypeMethods.size() > 1 ) { Message.INHERITCONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, Strings.join( applicablePrototypeMethods, ", " ) ); } + + if ( applicableReversePrototypeMethods.size() == 1 ) { + mappingOptions.applyInheritedOptions( + first( applicableReversePrototypeMethods ).getMappingOptions(), + true, + method, + messager, + typeFactory ); + } + else if ( applicableReversePrototypeMethods.size() > 1 ) { + messager.printMessage( + method.getExecutable(), + Message.INHERITINVERSECONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, + Strings.join( applicablePrototypeMethods, ", " ) ); + } } mappingOptions.markAsFullyInitialized(); @@ -497,7 +517,7 @@ private MappingOptions getInverseMappingOptions(List rawMethods, S // method is configured as being reverse method, collect candidates List candidates = new ArrayList(); for ( SourceMethod oneMethod : rawMethods ) { - if ( oneMethod.reverses( method ) ) { + if ( method.reverses( oneMethod ) ) { candidates.add( oneMethod ); } } @@ -559,7 +579,7 @@ private MappingOptions extractInitializedOptions(SourceMethod resultMethod, * Returns the configuring forward method's options in case the given method is annotated with * {@code @InheritConfiguration} and exactly one such configuring method can unambiguously be selected (as per the * source/target type and optionally the name given via {@code @InheritConfiguration}). The method cannot be marked - * forward mapping itself (hence 'ohter'). And neither can it contain an {@code @InheritReverseConfiguration} + * forward mapping itself (hence 'other'). And neither can it contain an {@code @InheritReverseConfiguration} */ private MappingOptions getTemplateMappingOptions(List rawMethods, SourceMethod method, List initializingMethods, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 3ac151f944..1da8d2706d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -113,6 +113,7 @@ public enum Message { INHERITCONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s." ), INHERITCONFIGURATION_NO_NAME_MATCH( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ), INHERITCONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH( "More than one configuration prototype method is applicable. Use @InheritConfiguration to select one of them explicitly: %s." ), + INHERITINVERSECONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH( "More than one configuration prototype method is applicable. Use @InheritInverseConfiguration to select one of them explicitly: %s." ), INHERITCONFIGURATION_CYCLE( "Cycle detected while evaluating inherited configurations. Inheritance path: %s" ), VALUEMAPPING_DUPLICATE_SOURCE( "Source value mapping: \"%s\" cannot be mapped more than once." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java new file mode 100644 index 0000000000..0dec597902 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + */ +@Mapper( + config = AutoInheritedConfig.class, + mappingInheritanceStrategy = MappingInheritanceStrategy.EXPLICIT +) +public abstract class CarMapperReverseWithExplicitInheritance { + public static final CarMapperReverseWithExplicitInheritance INSTANCE = + Mappers.getMapper( CarMapperReverseWithExplicitInheritance.class ); + + @InheritInverseConfiguration(name = "baseDtoToEntity") + @Mapping( target = "colour", source = "color" ) + public abstract CarDto toCarDto(CarEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index bfa84a3f24..c3f6fd5bf9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -125,6 +125,21 @@ public void explicitInheritedMappingIsAppliedInReverse() { assertThat( carDto.getId() ).isEqualTo( 42L ); } + @Test + @IssueKey( "1065" ) + @WithClasses({ CarMapperReverseWithExplicitInheritance.class } ) + public void explicitInheritedMappingIsAppliedInReverseDirectlyFromConfig() { + + CarEntity carEntity = new CarEntity(); + carEntity.setColor( "red" ); + carEntity.setPrimaryKey( 42L ); + + CarDto carDto = CarMapperReverseWithExplicitInheritance.INSTANCE.toCarDto( carEntity ); + + assertThat( carDto.getColour() ).isEqualTo( "red" ); + assertThat( carDto.getId() ).isEqualTo( 42L ); + } + @Test public void explicitInheritedMappingWithTwoLevelsIsOverriddenAtMethodLevel() { CarDto carDto = newTestDto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java index aebc6616af..c4c1c6613f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java @@ -37,5 +37,5 @@ public interface ArtistToChartEntryConfig { @Mapping(target = "artistName", source = "artist.name"), @Mapping(target = "chartName", ignore = true ) }) - BaseChartEntry mapForward( Song song ); + BaseChartEntry mapForwardConfig( Song song ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java index ed6eadbe1e..bd934dc10c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java @@ -44,7 +44,7 @@ public abstract class ArtistToChartEntryWithConfigReverse { }) abstract ChartEntryWithBase mapForward(Song song); - @InheritInverseConfiguration + @InheritInverseConfiguration( name = "mapForward" ) @Mapping(target = "positions", ignore = true) abstract Song mapReverse(ChartEntryWithBase ce); } From 8353f53ab9813c36fa6865aca44be00ee370ad82 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sun, 26 Feb 2017 09:53:18 +0100 Subject: [PATCH 0072/1006] #1101 Fixing confusing method name in test mapper --- .../org/mapstruct/ap/test/java8stream/SourceTargetMapper.java | 2 +- .../org/mapstruct/ap/test/java8stream/StreamMappingTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java index 071efcfe13..c2e3c5b39e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java @@ -61,7 +61,7 @@ public abstract class SourceTargetMapper { @InheritInverseConfiguration public abstract Set stringSetToColourSet(Set colours); - public abstract Set integerSetToNumberSet(Stream integers); + public abstract Set integerStreamToNumberSet(Stream integers); protected StringHolder toStringHolder(String string) { return new StringHolder( string ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java index 16bdbf455d..da4b162019 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java @@ -209,9 +209,9 @@ public void shouldReverseMapSetOfEnumToStringSet() { } @Test - public void shouldMapIntegerSetToNumberSet() { + public void shouldMapIntegerStreamToNumberSet() { Set numbers = SourceTargetMapper.INSTANCE - .integerSetToNumberSet( new HashSet( Arrays.asList( 123, 456 ) ).stream() ); + .integerStreamToNumberSet( Arrays.asList( 123, 456 ).stream() ); assertThat( numbers ).isNotNull(); assertThat( numbers ).containsOnly( 123, 456 ); From 58992b8edf9ab9c534f33f522e5ebe58f2c09d09 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 26 Feb 2017 11:39:14 +0100 Subject: [PATCH 0073/1006] #1105 cleaning up MethodReference freemarker template --- .../ap/internal/model/MethodReference.ftl | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 0706a3a1eb..7b603d7848 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -21,44 +21,57 @@ --> <@compress single_line=true> <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> - <#if declaringMapper??><#if static><@includeModel object=declaringMapper.type/><#else>${mapperVariableName}.<@methodCall/> + <#if declaringMapper??> + <#if static><@includeModel object=declaringMapper.type/><#else>${mapperVariableName}.<@methodCall/> <#-- method is provided by a context parameter --> - <#elseif providingParameter??><#if static><@includeModel object=providingParameter.type/><#else>${providingParameter.name}.<@methodCall/> + <#elseif providingParameter??> + <#if static><@includeModel object=providingParameter.type/><#else>${providingParameter.name}.<@methodCall/> <#-- method is referenced java8 static method in the mapper to implement (interface) --> - <#elseif static><@includeModel object=definingType/>.<@methodCall/> + <#elseif static> + <@includeModel object=definingType/>.<@methodCall/> <#else> - <@methodCall/> + <@methodCall/> - <#macro methodCall> - <@compress> - ${name}<#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() - - - <#macro arguments> - <#list parameterBindings as param> - <#if param.targetType> - <#-- a class is passed on for casting, see @TargetType --> - <@includeModel object=ext.targetType raw=true/>.class<#t> - <#elseif param.mappingTarget> - ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> - <#elseif param.mappingContext> - ${param.variableName}<#t> - <#elseif assignment??> - <@_assignment/><#t> - <#else> - ${param.variableName}<#t> - + +<#-- + macro: methodCall + purpose: the actual method call (stuff following the dot) +--> +<#macro methodCall> + <#lt>${name}<#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() + +<#-- + macro: arguments + purpose: the arguments in the method call +--> +<#macro arguments> + <#list parameterBindings as param> + <#if param.targetType> + <#-- a class is passed on for casting, see @TargetType --> + <@includeModel object=ext.targetType raw=true/>.class<#t> + <#elseif param.mappingTarget> + ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> + <#elseif param.mappingContext> + ${param.variableName}<#t> + <#elseif assignment??> + <@_assignment/><#t> + <#else> + ${param.variableName}<#t> + <#if param_has_next>, <#t> - <#-- context parameter, e.g. for builtin methods concerning date conversion --> - <#if contextParam??>, ${contextParam}<#t> - - <#macro _assignment> - <@includeModel object=assignment - targetBeanName=ext.targetBeanName + <#-- context parameter, e.g. for builtin methods concerning date conversion --> + <#if contextParam??>, ${contextParam}<#t> + +<#-- + macro: assignment + purpose: note: takes its targetyType from the singleSourceParameterType +--> +<#macro _assignment> + <@includeModel object=assignment + targetBeanName=ext.targetBeanName existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName targetType=singleSourceParameterType/> - - + \ No newline at end of file From 880ae56652e6788b2447ae34bb5b3dcdbce98e94 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 1 Mar 2017 00:39:00 +0100 Subject: [PATCH 0074/1006] #1109 Add import for @Qualifier in the documentation --- .../main/asciidoc/mapstruct-reference-guide.asciidoc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 6fe7ddcb00..b4d537b80f 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -999,7 +999,11 @@ When working with JAXB, e.g. when converting a `String` to a corresponding `JAXB [[selection-based-on-qualifiers]] === Mapping method selection based on qualifiers -In many occasions one requires mapping methods with the same method signature (appart from the name) that have different behavior. MapStruct has a handy mechanism to deal with such situations: `@Qualifier`. A ‘qualifier’ is a custom annotation that the user can write, ‘stick onto’ a mapping method which is included as used mapper, and can be referred to in a bean property mapping, iterable mapping or map mapping. Multiple qualifiers can be ‘stuck onto’ a method and mapping. +In many occasions one requires mapping methods with the same method signature (appart from the name) that have different behavior. +MapStruct has a handy mechanism to deal with such situations: `@Qualifier` (`org.mapstruct.Qualifier`). +A ‘qualifier’ is a custom annotation that the user can write, ‘stick onto’ a mapping method which is included as used mapper +and can be referred to in a bean property mapping, iterable mapping or map mapping. +Multiple qualifiers can be ‘stuck onto’ a method and mapping. So, lets say there is a hand-written method to map titles with a `String` return type and `String` argument amongst many other referenced mappers with the same `String` return type - `String` argument signature: @@ -1046,6 +1050,8 @@ Enter the qualifier approach: [source, java, linenums] [subs="verbatim,attributes"] ---- +import org.mapstruct.Qualifier; + @Qualifier @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) @@ -1061,6 +1067,8 @@ And, some qualifiers to indicate which translator to use to map from source lang [source, java, linenums] [subs="verbatim,attributes"] ---- +import org.mapstruct.Qualifier; + @Qualifier @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) @@ -1070,6 +1078,8 @@ public @interface EnglishToGerman { [source, java, linenums] [subs="verbatim,attributes"] ---- +import org.mapstruct.Qualifier; + @Qualifier @Target(ElementType.METHOD) @Retention(RetentionPolicy.CLASS) From 8fab3dd4e5002a2c9f2288efa9635f46386fd04f Mon Sep 17 00:00:00 2001 From: sjaakd Date: Wed, 1 Mar 2017 22:23:00 +0100 Subject: [PATCH 0075/1006] #1111 local variabele should not clash with loop variable --- .../ap/internal/model/BeanMappingMethod.java | 4 ++ .../model/ContainerMappingMethod.java | 16 ++++-- .../model/ContainerMappingMethodBuilder.java | 5 +- .../internal/model/IterableMappingMethod.java | 11 ++-- .../ap/internal/model/MapMappingMethod.java | 9 ++-- .../model/NormalTypeMappingMethod.java | 6 ++- .../internal/model/StreamMappingMethod.java | 11 ++-- .../ap/test/bugs/_1111/Issue1111Mapper.java | 44 +++++++++++++++ .../ap/test/bugs/_1111/Issue1111Test.java | 53 +++++++++++++++++++ 9 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c9e438bd6f..8911fef2df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -22,6 +22,7 @@ import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -211,6 +212,7 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { return new BeanMappingMethod( method, + existingVariableNames, propertyMappings, factoryMethod, mapNullToDefault, @@ -724,6 +726,7 @@ else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.require } private BeanMappingMethod(Method method, + Collection existingVariableNames, List propertyMappings, MethodReference factoryMethod, boolean mapNullToDefault, @@ -732,6 +735,7 @@ private BeanMappingMethod(Method method, List afterMappingReferences) { super( method, + existingVariableNames, factoryMethod, mapNullToDefault, beforeMappingReferences, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 171a69a0e9..8628ebe5b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -39,16 +40,21 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { private final Assignment elementAssignment; private final String loopVariableName; private final SelectionParameters selectionParameters; + private final String index1Name; + private final String index2Name; - ContainerMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, - boolean mapNullToDefault, String loopVariableName, + ContainerMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters) { - super( method, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); + super( method, existingVariables, factoryMethod, mapNullToDefault, beforeMappingReferences, + afterMappingReferences ); this.elementAssignment = parameterAssignment; this.loopVariableName = loopVariableName; this.selectionParameters = selectionParameters; + this.index1Name = Strings.getSaveVariableName( "i", existingVariables ); + this.index2Name = Strings.getSaveVariableName( "j", existingVariables ); } public Parameter getSourceParameter() { @@ -81,11 +87,11 @@ public String getLoopVariableName() { public abstract Type getResultElementType(); public String getIndex1Name() { - return Strings.getSaveVariableName( "i", loopVariableName, getSourceParameter().getName(), getResultName() ); + return index1Name; } public String getIndex2Name() { - return Strings.getSaveVariableName( "j", loopVariableName, getSourceParameter().getName(), getResultName() ); + return index2Name; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 009f507cd7..be5d4ea998 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -20,6 +20,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -143,6 +144,7 @@ public final M build() { return instantiateMappingMethod( method, + existingVariables, assignment, factoryMethod, mapNullToDefault, @@ -153,7 +155,8 @@ public final M build() { ); } - protected abstract M instantiateMappingMethod(Method method, Assignment assignment, MethodReference factoryMethod, + protected abstract M instantiateMappingMethod(Method method, Collection existingVariables, + Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingMethods, List afterMappingMethods, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 1f264afd31..2edafea3b6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -20,6 +20,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; +import java.util.Collection; import java.util.List; import org.mapstruct.ap.internal.model.assignment.Assignment; @@ -62,12 +63,13 @@ protected Assignment getWrapper(Assignment assignment, Method method) { } @Override - protected IterableMappingMethod instantiateMappingMethod(Method method, Assignment assignment, - MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, + protected IterableMappingMethod instantiateMappingMethod(Method method, Collection existingVariables, + Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingMethods, List afterMappingMethods, SelectionParameters selectionParameters) { return new IterableMappingMethod( method, + existingVariables, assignment, factoryMethod, mapNullToDefault, @@ -79,13 +81,14 @@ protected IterableMappingMethod instantiateMappingMethod(Method method, Assignme } } - private IterableMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, - boolean mapNullToDefault, String loopVariableName, + private IterableMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters) { super( method, + existingVariables, parameterAssignment, factoryMethod, mapNullToDefault, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 861cd4b1ae..d7f59ecf7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -161,6 +162,7 @@ public MapMappingMethod build() { return new MapMappingMethod( method, + existingVariables, keyAssignment, valueAssignment, factoryMethod, @@ -176,11 +178,12 @@ protected boolean shouldUsePropertyNamesInHistory() { } } - private MapMappingMethod(Method method, Assignment keyAssignment, Assignment valueAssignment, - MethodReference factoryMethod, boolean mapNullToDefault, + private MapMappingMethod(Method method, Collection existingVariableNames, Assignment keyAssignment, + Assignment valueAssignment, MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, List afterMappingReferences) { - super( method, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); + super( method, existingVariableNames, factoryMethod, mapNullToDefault, beforeMappingReferences, + afterMappingReferences ); this.keyAssignment = keyAssignment; this.valueAssignment = valueAssignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index e1e72eb62d..0743987b40 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -36,10 +37,11 @@ public abstract class NormalTypeMappingMethod extends MappingMethod { private final boolean overridden; private final boolean mapNullToDefault; - NormalTypeMappingMethod(Method method, MethodReference factoryMethod, boolean mapNullToDefault, + NormalTypeMappingMethod(Method method, Collection existingVariableNames, MethodReference factoryMethod, + boolean mapNullToDefault, List beforeMappingReferences, List afterMappingReferences) { - super( method, beforeMappingReferences, afterMappingReferences ); + super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences ); this.factoryMethod = factoryMethod; this.overridden = method.overridesMethod(); this.mapNullToDefault = mapNullToDefault; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 318831bba6..e4f41caefa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -60,8 +61,8 @@ protected Assignment getWrapper(Assignment assignment, Method method) { } @Override - protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment assignment, - MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, + protected StreamMappingMethod instantiateMappingMethod(Method method, Collection existingVariables, + Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingMethods, List afterMappingMethods, SelectionParameters selectionParameters) { @@ -78,6 +79,7 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment return new StreamMappingMethod( method, + existingVariables, assignment, factoryMethod, mapNullToDefault, @@ -90,13 +92,14 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Assignment } } - private StreamMappingMethod(Method method, Assignment parameterAssignment, MethodReference factoryMethod, - boolean mapNullToDefault, String loopVariableName, + private StreamMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters, Set helperImports) { super( method, + existingVariables, parameterAssignment, factoryMethod, mapNullToDefault, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java new file mode 100644 index 0000000000..8a81d91ed4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1111; + +import java.util.List; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface Issue1111Mapper { + + Issue1111Mapper INSTANCE = Mappers.getMapper( Issue1111Mapper.class ); + + Target toTarget(Source in); + + List list(List in); + + List> listList(List> in); + + class Source { } + + class Target { } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java new file mode 100644 index 0000000000..a908491e7c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1111; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._1111.Issue1111Mapper.Source; +import org.mapstruct.ap.test.bugs._1111.Issue1111Mapper.Target; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * + * @author Sjaak Derksen + */ +@IssueKey( "1111") +@WithClasses({Issue1111Mapper.class}) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1111Test { + + @Test + public void shouldCompile() { + + List> source = Arrays.asList( Arrays.asList( new Source() ) ); + + List> target = Issue1111Mapper.INSTANCE.listList( source ); + + assertThat( target ).hasSize( 1 ); + assertThat( target.get( 0 ) ).hasSize( 1 ); + assertThat( target.get( 0 ).get( 0 ) ).isInstanceOf( Target.class ); + } +} From 86d05f64d2d158e82bec753f53f10cbc4f412115 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sun, 26 Feb 2017 11:17:19 +0100 Subject: [PATCH 0076/1006] #1119 removing superfluous method override --- .../mapstruct/ap/internal/model/common/ModelElement.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java index f243734950..4d2e77b1c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java @@ -18,10 +18,8 @@ */ package org.mapstruct.ap.internal.model.common; -import java.io.Writer; import java.util.Set; -import org.mapstruct.ap.internal.writer.FreeMarkerModelElementWriter; import org.mapstruct.ap.internal.writer.FreeMarkerWritable; import org.mapstruct.ap.internal.writer.Writable; @@ -33,11 +31,6 @@ */ public abstract class ModelElement extends FreeMarkerWritable { - @Override - public void write(Context context, Writer writer) throws Exception { - new FreeMarkerModelElementWriter().write( this, context, writer ); - } - /** * Returns a set containing those {@link Type}s referenced by this model element for which an import statement needs * to be declared. From 12f1cc07775b23464dfce4dba007f8679d130bc9 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Tue, 7 Mar 2017 23:20:27 +0100 Subject: [PATCH 0077/1006] #1121 TypeMirror should not be used as hashCode base for Type --- .../itest/tests/ExternalBeanJarTest.java | 35 +++++++++++++++ .../resources/externalbeanjar/beanjar/pom.xml | 35 +++++++++++++++ .../itest/externalbeanjar/Source.java | 34 ++++++++++++++ .../itest/externalbeanjar/Target.java | 32 ++++++++++++++ .../resources/externalbeanjar/mapper/pom.xml | 42 ++++++++++++++++++ .../externalbeanjar/Issue1121Mapper.java | 44 +++++++++++++++++++ .../itest/externalbeanjar/ConversionTest.java | 42 ++++++++++++++++++ .../test/resources/externalbeanjar/pom.xml | 38 ++++++++++++++++ .../ap/internal/model/common/Type.java | 9 +++- 9 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java create mode 100644 integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml create mode 100644 integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java create mode 100644 integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java create mode 100644 integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml create mode 100644 integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java create mode 100644 integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java create mode 100644 integrationtest/src/test/resources/externalbeanjar/pom.xml diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java new file mode 100644 index 0000000000..87010b9e85 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * + * See: https://github.com/mapstruct/mapstruct/issues/1121 + * + * @author Sjaak Derksen + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite(baseDir = "externalbeanjar", processorTypes = ProcessorSuite.ProcessorType.ORACLE_JAVA_8) +public class ExternalBeanJarTest { + +} diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml b/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml new file mode 100644 index 0000000000..58eb8735a3 --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml @@ -0,0 +1,35 @@ + + + + 4.0.0 + + + org.mapstruct + externalbeanjar + 1.0.0 + ../pom.xml + + + beanjar + jar + + diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java new file mode 100644 index 0000000000..36b01ab954 --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.externalbeanjar; + +import java.math.BigDecimal; + +public class Source { + + private BigDecimal bigDecimal; + + public BigDecimal getBigDecimal() { + return bigDecimal; + } + + public void setBigDecimal(BigDecimal bigDecimal) { + this.bigDecimal = bigDecimal; + } +} diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java new file mode 100644 index 0000000000..da78a4e03f --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.externalbeanjar; + +public class Target { + + private Integer integer; + + public Integer getInteger() { + return integer; + } + + public void setInteger(Integer integer) { + this.integer = integer; + } +} diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml b/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml new file mode 100644 index 0000000000..e45abc0302 --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.mapstruct + externalbeanjar + 1.0.0 + ../pom.xml + + + mapper + jar + + + + org.mapstruct + beanjar + 1.0.0 + + + diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java b/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java new file mode 100644 index 0000000000..45d861bde6 --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.mapstruct.itest.externalbeanjar; + +import org.mapstruct.itest.externalbeanjar.Source; +import org.mapstruct.itest.externalbeanjar.Target; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface Issue1121Mapper { + + Issue1121Mapper INSTANCE = Mappers.getMapper( Issue1121Mapper.class ); + + @Mapping(target = "integer", source = "bigDecimal") + Target map(Source source); + +} diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java new file mode 100644 index 0000000000..9177041631 --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.simple; + +import java.math.BigDecimal; +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.externalbeanjar.Source; +import org.mapstruct.itest.externalbeanjar.Issue1121Mapper; +import org.mapstruct.itest.externalbeanjar.Target; + +public class ConversionTest { + + @Test + public void shouldApplyConversions() { + Source source = new Source(); + source.setBigDecimal( new BigDecimal( "42" ) ); + + Target target = Issue1121Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getInteger() ).isEqualTo( 42 ); + } + +} diff --git a/integrationtest/src/test/resources/externalbeanjar/pom.xml b/integrationtest/src/test/resources/externalbeanjar/pom.xml new file mode 100644 index 0000000000..9fe0dff28b --- /dev/null +++ b/integrationtest/src/test/resources/externalbeanjar/pom.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + externalbeanjar + pom + + beanjar + mapper + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 5603de2faa..4440ee4619 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -781,7 +781,14 @@ public String getNull() { @Override public int hashCode() { - return typeMirror.hashCode(); + // javadoc typemirror: "Types should be compared using the utility methods in Types. There is no guarantee + // that any particular type will always be represented by the same object." This is true when the objects + // are in another jar than the mapper. So the qualfiedName is a better candidate. + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((packageName == null) ? 0 : packageName.hashCode()); + return result; } @Override From d4c6250944ec7c9f78a9469efe7faaf85cef1065 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Mar 2017 15:34:46 +0100 Subject: [PATCH 0078/1006] #1102 Add support for Auto forging of Enum properties --- .../internal/model/AbstractBaseBuilder.java | 21 +- .../model/AbstractMappingMethodBuilder.java | 2 +- .../ap/internal/model/PropertyMapping.java | 5 +- .../ap/internal/model/ValueMappingMethod.java | 29 ++- .../model/source/MappingMethodUtils.java | 48 ++++ .../internal/model/source/SourceMethod.java | 4 +- .../processor/MapperCreationProcessor.java | 2 +- .../mapstruct/ap/internal/util/Message.java | 2 +- .../ap/internal/model/ValueMappingMethod.ftl | 4 +- .../nestedbeans/DottedErrorMessageTest.java | 24 ++ .../ap/test/nestedbeans/ExternalRoofType.java | 28 +++ .../NestedSimpleBeansMappingTest.java | 126 +++++++++- .../mapstruct/ap/test/nestedbeans/Roof.java | 13 +- .../ap/test/nestedbeans/RoofDto.java | 20 +- .../ap/test/nestedbeans/RoofType.java | 28 +++ .../ap/test/nestedbeans/TestData.java | 2 +- .../nestedbeans/UserDtoMapperClassic.java | 2 + .../erroneous/ExternalRoofType.java | 28 +++ .../ap/test/nestedbeans/erroneous/Roof.java | 10 + .../test/nestedbeans/erroneous/RoofDto.java | 9 + .../test/nestedbeans/erroneous/RoofType.java | 28 +++ .../nestedbeans/erroneous/RoofTypeMapper.java | 32 +++ ...ppableCollectionElementPropertyMapper.java | 2 +- .../erroneous/UnmappableDeepListMapper.java | 2 +- .../erroneous/UnmappableDeepMapKeyMapper.java | 2 +- .../UnmappableDeepMapValueMapper.java | 2 +- .../UnmappableDeepNestingMapper.java | 2 +- .../erroneous/UnmappableEnumMapper.java | 47 ++++ .../UnmappableValuePropertyMapper.java | 2 +- .../nestedbeans/UserDtoMapperClassicImpl.java | 143 ++++++++++++ .../nestedbeans/UserDtoMapperSmartImpl.java | 221 ++++++++++++++++++ .../UserDtoUpdateMapperSmartImpl.java | 170 ++++++++++++++ 32 files changed, 1018 insertions(+), 42 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ExternalRoofType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableEnumMapper.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index cb809924bc..6584053ffc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -21,6 +21,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.MappingMethodUtils; import org.mapstruct.ap.internal.model.source.Method; /** @@ -55,11 +56,21 @@ public B method(Method sourceMethod) { * * @return See above */ - Assignment createForgedBeanAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) { - BeanMappingMethod forgedMappingMethod = new BeanMappingMethod.Builder() - .forgedMethod( forgedMethod ) - .mappingContext( ctx ) - .build(); + Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) { + MappingMethod forgedMappingMethod; + if ( MappingMethodUtils.isEnumMapping( forgedMethod ) ) { + forgedMappingMethod = new ValueMappingMethod.Builder() + .method( forgedMethod ) + .valueMappings( forgedMethod.getMappingOptions().getValueMappings() ) + .mappingContext( ctx ) + .build(); + } + else { + forgedMappingMethod = new BeanMappingMethod.Builder() + .forgedMethod( forgedMethod ) + .mappingContext( ctx ) + .build(); + } return createForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethod ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 1c34d85ad7..f28540834d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -73,7 +73,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { true ); - return createForgedBeanAssignment( sourceRHS, forgedMethod ); + return createForgedAssignment( sourceRHS, forgedMethod ); } private String getName(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 6e3bcd30db..ed8d52c966 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -634,7 +634,8 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { // there's only one case for forging a method with mapping options: nested target properties. // They should forge an update method only if we set the forceUpdateMethod. This is set to true, // because we are forging a Mapping for a method with multiple source parameters. - if ( method.isUpdateMethod() || forceUpdateMethod ) { + // If the target type is enum, then we can't create an update method + if ( !targetType.isEnumType() && ( method.isUpdateMethod() || forceUpdateMethod ) ) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } @@ -653,7 +654,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { forgeMethodWithMappingOptions, forgedNamedBased ); - return createForgedBeanAssignment( sourceRHS, forgedMethod ); + return createForgedAssignment( sourceRHS, forgedMethod ); } private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 6831c20fa3..c7fc97010a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -28,9 +28,10 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.source.ForgedMethod; +import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.ValueMapping; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.MappingConstantsPrism; @@ -49,10 +50,11 @@ public class ValueMappingMethod extends MappingMethod { private final String defaultTarget; private final String nullTarget; private final boolean throwIllegalArgumentException; + private final boolean overridden; public static class Builder { - private SourceMethod method; + private Method method; private MappingBuilderContext ctx; private final List trueValueMappings = new ArrayList(); private ValueMapping defaultTargetValue = null; @@ -64,7 +66,7 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { return this; } - public Builder souceMethod(SourceMethod sourceMethod) { + public Builder method(Method sourceMethod) { this.method = sourceMethod; return this; } @@ -128,7 +130,7 @@ public ValueMappingMethod build( ) { throwIllegalArgumentException, beforeMappingMethods, afterMappingMethods ); } - private List enumToEnumMapping(SourceMethod method) { + private List enumToEnumMapping(Method method) { List mappings = new ArrayList(); List unmappedSourceConstants @@ -161,10 +163,20 @@ private List enumToEnumMapping(SourceMethod method) { } if ( defaultTargetValue == null && !unmappedSourceConstants.isEmpty() ) { + String sourceErrorMessage = "source"; + String targetErrorMessage = "target"; + if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).getHistory() != null ) { + ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory(); + sourceErrorMessage = history.createSourcePropertyErrorMessage(); + targetErrorMessage = + "\"" + history.getTargetType().toString() + " " + history.createTargetPropertyName() + "\""; + } // all sources should now be matched, there's no default to fall back to, so if sources remain, // we have an issue. ctx.getMessager().printMessage( method.getExecutable(), Message.VALUE_MAPPING_UNMAPPED_SOURCES, + sourceErrorMessage, + targetErrorMessage, Strings.join( unmappedSourceConstants, ", " ) ); @@ -173,7 +185,7 @@ private List enumToEnumMapping(SourceMethod method) { return mappings; } - private SelectionParameters getSelectionParameters(SourceMethod method) { + private SelectionParameters getSelectionParameters(Method method) { BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); if ( beanMappingPrism != null ) { List qualifiers = beanMappingPrism.qualifiedBy(); @@ -184,7 +196,7 @@ private SelectionParameters getSelectionParameters(SourceMethod method) { return null; } - private boolean reportErrorIfMappedEnumConstantsDontExist(SourceMethod method) { + private boolean reportErrorIfMappedEnumConstantsDontExist(Method method) { List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); List targetEnumConstants = method.getReturnType().getEnumConstants(); @@ -251,6 +263,7 @@ private ValueMappingMethod(Method method, List enumMappings, Strin this.nullTarget = nullTarget; this.defaultTarget = defaultTarget; this.throwIllegalArgumentException = throwIllegalArgumentException; + this.overridden = method.overridesMethod(); } public List getValueMappings() { @@ -273,6 +286,10 @@ public Parameter getSourceParameter() { return first( getParameters() ); } + public boolean isOverridden() { + return overridden; + } + public static class MappingEntry { private final String source; private final String target; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java new file mode 100644 index 0000000000..d38451785a --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source; + +import static org.mapstruct.ap.internal.util.Collections.first; + +/** + * @author Filip Hrisafov + */ +public final class MappingMethodUtils { + + /** + * Hide default constructor. + */ + private MappingMethodUtils() { + } + + + /** + * Checks if the provided {@code method} is for enum mapping. A Method is an Enum Mapping method when the + * source parameter and result type are enum types. + * + * @param method to check + * + * @return {@code true} if the method is for enum mapping, {@code false} otherwise + */ + public static boolean isEnumMapping(Method method) { + return method.getSourceParameters().size() == 1 + && first( method.getSourceParameters() ).getType().isEnumType() + && method.getResultType().isEnumType(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index f0f6108d83..3c7142395b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -381,9 +381,7 @@ && first( getSourceParameters() ).getType().isMapType() public boolean isEnumMapping() { if ( isEnumMapping == null ) { - isEnumMapping = getSourceParameters().size() == 1 - && first( getSourceParameters() ).getType().isEnumType() - && getResultType().isEnumType(); + isEnumMapping = MappingMethodUtils.isEnumMapping( this ); } return isEnumMapping; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 6c8e78a4d0..6178754e69 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -317,7 +317,7 @@ else if ( method.isValueMapping() ) { // prefer value mappings over enum mapping ValueMappingMethod valueMappingMethod = new ValueMappingMethod.Builder() .mappingContext( mappingContext ) - .souceMethod( method ) + .method( method ) .valueMappings( mappingOptions.getValueMappings() ) .build(); mappingMethods.add( valueMappingMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 1da8d2706d..78169e9dff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -118,7 +118,7 @@ public enum Message { VALUEMAPPING_DUPLICATE_SOURCE( "Source value mapping: \"%s\" cannot be mapped more than once." ), VALUEMAPPING_ANY_AREADY_DEFINED( "Source = \"\" or \"\" can only be used once." ), - VALUE_MAPPING_UNMAPPED_SOURCES( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: %s." ), + VALUE_MAPPING_UNMAPPED_SOURCES( "The following constants from the %s enum have no corresponding constant in the %s enum and must be be mapped via adding additional mappings: %s." ), VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); // CHECKSTYLE:ON diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 2f648fda9d..ba2d8f9650 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -19,8 +19,8 @@ limitations under the License. --> -@Override -public <@includeModel object=returnType/> ${name}(<@includeModel object=sourceParameter/>) { +<#if overridden>@Override +<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<@includeModel object=sourceParameter/>) { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> <#if !callback_has_next> diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index c3923e6dfe..8fb7c3e2c3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -31,10 +31,12 @@ import org.mapstruct.ap.test.nestedbeans.erroneous.CatDto; import org.mapstruct.ap.test.nestedbeans.erroneous.Info; import org.mapstruct.ap.test.nestedbeans.erroneous.InfoDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.RoofTypeMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableCollectionElementPropertyMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepListMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepMapKeyMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepMapValueMapper; +import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableEnumMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableValuePropertyMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.UserDto; import org.mapstruct.ap.test.nestedbeans.erroneous.User; @@ -42,11 +44,13 @@ import org.mapstruct.ap.test.nestedbeans.erroneous.Wheel; import org.mapstruct.ap.test.nestedbeans.erroneous.Car; import org.mapstruct.ap.test.nestedbeans.erroneous.CarDto; +import org.mapstruct.ap.test.nestedbeans.erroneous.ExternalRoofType; import org.mapstruct.ap.test.nestedbeans.erroneous.House; import org.mapstruct.ap.test.nestedbeans.erroneous.HouseDto; import org.mapstruct.ap.test.nestedbeans.erroneous.Color; import org.mapstruct.ap.test.nestedbeans.erroneous.ColorDto; import org.mapstruct.ap.test.nestedbeans.erroneous.Roof; +import org.mapstruct.ap.test.nestedbeans.erroneous.RoofType; import org.mapstruct.ap.test.nestedbeans.erroneous.RoofDto; import org.mapstruct.ap.test.nestedbeans.erroneous.UnmappableDeepNestingMapper; import org.mapstruct.ap.test.nestedbeans.erroneous.Word; @@ -60,6 +64,7 @@ @WithClasses({ Car.class, CarDto.class, Color.class, ColorDto.class, House.class, HouseDto.class, Roof.class, RoofDto.class, + RoofType.class, ExternalRoofType.class, RoofTypeMapper.class, User.class, UserDto.class, Wheel.class, WheelDto.class, Dictionary.class, DictionaryDto.class, Word.class, WordDto.class, ForeignWord.class, ForeignWordDto.class, @@ -183,4 +188,23 @@ public void testCollectionElementProperty() { ) public void testMapValueProperty() { } + + @Test + @WithClasses({ + UnmappableEnumMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = UnmappableEnumMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "The following constants from the property \".*RoofType house\\.roof\\.type\" enum " + + "have no corresponding constant in the \".*ExternalRoofType house\\.roof\\.type\" enum and must " + + "be be mapped via adding additional mappings: NORMAL\\." + ) + } + ) + public void testMapEnumProperty() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java new file mode 100644 index 0000000000..9f86ca22c6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + + +/** + * @author Filip Hrisafov + */ +public enum ExternalRoofType { + + OPEN, BOX, GAMBREL, STANDARD, NORMAL +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index c01bc54067..0cfaf9ee02 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -18,17 +18,28 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.assertj.core.groups.Tuple; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; @WithClasses({ User.class, UserDto.class, Car.class, CarDto.class, House.class, HouseDto.class, Wheel.class, WheelDto.class, Roof.class, RoofDto.class, + RoofType.class, ExternalRoofType.class, org.mapstruct.ap.test.nestedbeans.other.CarDto.class, org.mapstruct.ap.test.nestedbeans.other.UserDto.class, org.mapstruct.ap.test.nestedbeans.other.HouseDto.class, @@ -41,6 +52,59 @@ @RunWith(AnnotationProcessorTestRunner.class) public class NestedSimpleBeansMappingTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + UserDtoMapperClassic.class, + UserDtoMapperSmart.class, + UserDtoUpdateMapperSmart.class + ); + + /** + * Extracts all non synthetic declared fields from a class. This is needed, because jacoco adds a synthetic field + * to the classes and also assertj does not support testing that all fields are exactly there. + * This will be needed until 953 from + * assertj-core is implemented. + * + * @param clazz to extract from + * + * @return all the non synthetic declared fields + */ + private static List extractAllFields(Class clazz) { + List nonSyntheticFields = new ArrayList(); + for ( Field field : clazz.getDeclaredFields() ) { + if ( !field.isSynthetic() ) { + nonSyntheticFields.add( field ); + } + } + + return nonSyntheticFields; + } + + @Test + public void shouldHaveAllFields() throws Exception { + // If this test fails that means something new was added to the structure of the User/UserDto. + // Make sure that the other tests are also updated (the new field is asserted) + Object[] userFields = new String[] { "name", "car", "secondCar", "house" }; + assertThat( extractAllFields( User.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields ); + assertThat( extractAllFields( UserDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields ); + + Object[] carFields = new String[] { "name", "year", "wheels" }; + assertThat( extractAllFields( Car.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields ); + assertThat( extractAllFields( CarDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields ); + + Object[] wheelFields = new String[] { "front", "right" }; + assertThat( extractAllFields( Wheel.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields ); + assertThat( extractAllFields( WheelDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields ); + + Object[] houseFields = new String[] { "name", "year", "roof" }; + assertThat( extractAllFields( House.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields ); + assertThat( extractAllFields( HouseDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields ); + + Object[] roofFields = new String[] { "color", "type" }; + assertThat( extractAllFields( Roof.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields ); + assertThat( extractAllFields( RoofDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields ); + } + @Test public void shouldMapNestedBeans() { @@ -49,11 +113,8 @@ public void shouldMapNestedBeans() { UserDto classicMapping = UserDtoMapperClassic.INSTANCE.userToUserDto( user ); UserDto smartMapping = UserDtoMapperSmart.INSTANCE.userToUserDto( user ); - System.out.println( smartMapping ); - System.out.println( classicMapping ); - - assertThat( smartMapping ).isNotNull(); - assertThat( smartMapping ).isEqualTo( classicMapping ); + assertUserDto( classicMapping, user ); + assertUserDto( smartMapping, user ); } @Test @@ -67,15 +128,58 @@ public void shouldMapUpdateNestedBeans() { smartMapping.setCar( new CarDto() ); smartMapping.getCar().setName( "Toyota" ); - // create a classic mapping and adapt expected result to Toyota - UserDto classicMapping = UserDtoMapperClassic.INSTANCE.userToUserDto( TestData.createUser() ); - classicMapping.getCar().setName( "Toyota" ); - // action UserDtoUpdateMapperSmart.INSTANCE.userToUserDto( smartMapping, user ); // result - assertThat( smartMapping ).isNotNull(); - assertThat( smartMapping ).isEqualTo( classicMapping ); + assertThat( smartMapping.getName() ).isEqualTo( user.getName() ); + assertThat( smartMapping.getCar().getYear() ).isEqualTo( user.getCar().getYear() ); + assertThat( smartMapping.getCar().getName() ).isEqualTo( "Toyota" ); + assertThat( user.getCar().getName() ).isNull(); + assertWheels( smartMapping.getCar().getWheels(), user.getCar().getWheels() ); + assertCar( smartMapping.getSecondCar(), user.getSecondCar() ); + assertHouse( smartMapping.getHouse(), user.getHouse() ); + } + + private static void assertUserDto(UserDto userDto, User user) { + assertThat( userDto ).isNotNull(); + assertThat( userDto.getName() ).isEqualTo( user.getName() ); + assertCar( userDto.getCar(), user.getCar() ); + assertCar( userDto.getSecondCar(), user.getSecondCar() ); + assertHouse( userDto.getHouse(), user.getHouse() ); + } + + private static void assertCar(CarDto carDto, Car car) { + if ( car == null ) { + assertThat( carDto ).isNull(); + } + else { + assertThat( carDto.getName() ).isEqualTo( car.getName() ); + assertThat( carDto.getYear() ).isEqualTo( car.getYear() ); + assertWheels( carDto.getWheels(), car.getWheels() ); + } + } + + private static void assertWheels(List wheelDtos, List wheels) { + List wheelTuples = wheels.stream().map( new Function() { + @Override + public Tuple apply(Wheel wheel) { + return tuple( wheel.isFront(), wheel.isRight() ); + } + } ).collect( Collectors.toList() ); + assertThat( wheelDtos ) + .extracting( "front", "right" ) + .containsExactlyElementsOf( wheelTuples ); + } + + private static void assertHouse(HouseDto houseDto, House house) { + assertThat( houseDto.getName() ).isEqualTo( house.getName() ); + assertThat( houseDto.getYear() ).isEqualTo( house.getYear() ); + assertRoof( houseDto.getRoof(), house.getRoof() ); + } + + private static void assertRoof(RoofDto roofDto, Roof roof) { + assertThat( roofDto.getColor() ).isEqualTo( String.valueOf( roof.getColor() ) ); + assertThat( roofDto.getType().name() ).isEqualTo( roof.getType().name() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java index 52762dabb4..e3c98cbb65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java @@ -20,12 +20,14 @@ public class Roof { private int color; + private RoofType type; public Roof() { } - public Roof(int color) { + public Roof(int color, RoofType type) { this.color = color; + this.type = type; } public int getColor() { @@ -40,7 +42,16 @@ public void setColor(int color) { public String toString() { return "Roof{" + "color='" + color + '\'' + + "type='" + type + '\'' + '}'; } + public RoofType getType() { + return type; + } + + public Roof setType(RoofType type) { + this.type = type; + return this; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java index 3070408f55..c999cd10bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java @@ -20,6 +20,7 @@ public class RoofDto { private String color; + private ExternalRoofType type; public RoofDto() { } @@ -36,6 +37,15 @@ public void setColor(String color) { this.color = color; } + public ExternalRoofType getType() { + return type; + } + + public RoofDto setType(ExternalRoofType type) { + this.type = type; + return this; + } + @Override public boolean equals(Object o) { if ( this == o ) { @@ -47,20 +57,26 @@ public boolean equals(Object o) { RoofDto roofDto = (RoofDto) o; + if ( type != ( (RoofDto) o ).type ) { + return false; + } + return color != null ? color.equals( roofDto.color ) : roofDto.color == null; } @Override public int hashCode() { - return color != null ? color.hashCode() : 0; + int result = color != null ? color.hashCode() : 0; + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + return result; } @Override public String toString() { return "RoofDto{" + "color='" + color + '\'' + + "type='" + type + '\'' + '}'; } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java new file mode 100644 index 0000000000..91abcb366f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + + +/** + * @author Filip Hrisafov + */ +public enum RoofType { + + OPEN, BOX, GAMBREL +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java index 7e602c2060..3335e367ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java @@ -33,7 +33,7 @@ public static User createUser() { new Wheel().rear().left(), new Wheel().rear().right() ) ), - new House( "Black", 1834, new Roof( 1 ) ) + new House( "Black", 1834, new Roof( 1, RoofType.BOX ) ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java index 486c9bc81b..d461d90d83 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java @@ -40,4 +40,6 @@ public interface UserDtoMapperClassic { WheelDto mapWheel(Wheel wheels); + ExternalRoofType mapRoofType(RoofType roofType); + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ExternalRoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ExternalRoofType.java new file mode 100644 index 0000000000..c7b5ac1018 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/ExternalRoofType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + + +/** + * @author Filip Hrisafov + */ +public enum ExternalRoofType { + + OPEN, BOX, GAMBREL, STANDARD +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java index b62268a417..facb668427 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/Roof.java @@ -20,6 +20,7 @@ public class Roof { private Color color; + private RoofType type; public Color getColor() { return color; @@ -28,4 +29,13 @@ public Color getColor() { public void setColor(Color color) { this.color = color; } + + public RoofType getType() { + return type; + } + + public Roof setType(RoofType type) { + this.type = type; + return this; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java index 3768fd44d0..aad665e93b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofDto.java @@ -20,6 +20,7 @@ public class RoofDto { private ColorDto color; + private ExternalRoofType type; public ColorDto getColor() { return color; @@ -28,4 +29,12 @@ public ColorDto getColor() { public void setColor(ColorDto color) { this.color = color; } + + public ExternalRoofType getType() { + return type; + } + + public void setType(ExternalRoofType type) { + this.type = type; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofType.java new file mode 100644 index 0000000000..2554c748ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofType.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + + +/** + * @author Filip Hrisafov + */ +public enum RoofType { + + OPEN, BOX, GAMBREL, NORMAL +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofTypeMapper.java new file mode 100644 index 0000000000..2a54d66110 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/RoofTypeMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface RoofTypeMapper { + + @ValueMapping( source = "NORMAL", target = "STANDARD") + ExternalRoofType map(RoofType type); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java index 1fb4f584c1..6005e977d7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableCollectionElementPropertyMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableCollectionElementPropertyMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java index 78d6faabf1..990505aa91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepListMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableDeepListMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java index 00fe65b563..371882c809 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapKeyMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableDeepMapKeyMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java index a2aafa2675..ecd6255b24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepMapValueMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableDeepMapValueMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java index a01896cadf..b898f310a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableDeepNestingMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableDeepNestingMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableEnumMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableEnumMapper.java new file mode 100644 index 0000000000..7386c5941d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableEnumMapper.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.erroneous; + +import org.mapstruct.Mapper; + +@Mapper +public abstract class UnmappableEnumMapper { + + abstract UserDto userToUserDto(User user); + + public ColorDto map(Color color) { + return new ColorDto(); + } + + public CarDto map(Car carDto) { + return new CarDto(); + } + + public DictionaryDto map(Dictionary dictionary) { + return new DictionaryDto(); + } + + public ComputerDto map(Computer computer) { + return new ComputerDto(); + } + + public CatDto map(Cat cat) { + return new CatDto(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java index 40f79307c8..84d6ae826f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/erroneous/UnmappableValuePropertyMapper.java @@ -20,7 +20,7 @@ import org.mapstruct.Mapper; -@Mapper +@Mapper(uses = RoofTypeMapper.class) public abstract class UnmappableValuePropertyMapper { abstract UserDto userToUserDto(User user); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java new file mode 100644 index 0000000000..9c27118005 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java @@ -0,0 +1,143 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-03-01T22:15:21+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class UserDtoMapperClassicImpl implements UserDtoMapperClassic { + + @Override + public UserDto userToUserDto(User user) { + if ( user == null ) { + return null; + } + + UserDto userDto = new UserDto(); + + userDto.setName( user.getName() ); + userDto.setCar( carToCarDto( user.getCar() ) ); + userDto.setSecondCar( carToCarDto( user.getSecondCar() ) ); + userDto.setHouse( houseToHouseDto( user.getHouse() ) ); + + return userDto; + } + + @Override + public CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + carDto.setName( car.getName() ); + carDto.setYear( car.getYear() ); + List list = mapWheels( car.getWheels() ); + if ( list != null ) { + carDto.setWheels( list ); + } + + return carDto; + } + + @Override + public HouseDto houseToHouseDto(House house) { + if ( house == null ) { + return null; + } + + HouseDto houseDto = new HouseDto(); + + houseDto.setName( house.getName() ); + houseDto.setYear( house.getYear() ); + houseDto.setRoof( roofToRoofDto( house.getRoof() ) ); + + return houseDto; + } + + @Override + public RoofDto roofToRoofDto(Roof roof) { + if ( roof == null ) { + return null; + } + + RoofDto roofDto = new RoofDto(); + + roofDto.setColor( String.valueOf( roof.getColor() ) ); + roofDto.setType( mapRoofType( roof.getType() ) ); + + return roofDto; + } + + @Override + public List mapWheels(List wheels) { + if ( wheels == null ) { + return null; + } + + List list = new ArrayList(); + for ( Wheel wheel : wheels ) { + list.add( mapWheel( wheel ) ); + } + + return list; + } + + @Override + public WheelDto mapWheel(Wheel wheels) { + if ( wheels == null ) { + return null; + } + + WheelDto wheelDto = new WheelDto(); + + wheelDto.setFront( wheels.isFront() ); + wheelDto.setRight( wheels.isRight() ); + + return wheelDto; + } + + @Override + public ExternalRoofType mapRoofType(RoofType roofType) { + if ( roofType == null ) { + return null; + } + + ExternalRoofType externalRoofType; + + switch ( roofType ) { + case OPEN: externalRoofType = ExternalRoofType.OPEN; + break; + case BOX: externalRoofType = ExternalRoofType.BOX; + break; + case GAMBREL: externalRoofType = ExternalRoofType.GAMBREL; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + roofType ); + } + + return externalRoofType; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java new file mode 100644 index 0000000000..65347a32b1 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java @@ -0,0 +1,221 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-03-01T22:15:23+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class UserDtoMapperSmartImpl implements UserDtoMapperSmart { + + @Override + public UserDto userToUserDto(User user) { + if ( user == null ) { + return null; + } + + UserDto userDto = new UserDto(); + + userDto.setName( user.getName() ); + userDto.setCar( carToCarDto( user.getCar() ) ); + userDto.setSecondCar( carToCarDto( user.getSecondCar() ) ); + userDto.setHouse( houseToHouseDto( user.getHouse() ) ); + + return userDto; + } + + @Override + public org.mapstruct.ap.test.nestedbeans.other.UserDto userToUserDto2(User user) { + if ( user == null ) { + return null; + } + + org.mapstruct.ap.test.nestedbeans.other.UserDto userDto = new org.mapstruct.ap.test.nestedbeans.other.UserDto(); + + userDto.setName( user.getName() ); + userDto.setCar( carToCarDto1( user.getCar() ) ); + userDto.setHouse( houseToHouseDto1( user.getHouse() ) ); + + return userDto; + } + + protected WheelDto wheelToWheelDto(Wheel wheel) { + if ( wheel == null ) { + return null; + } + + WheelDto wheelDto = new WheelDto(); + + wheelDto.setFront( wheel.isFront() ); + wheelDto.setRight( wheel.isRight() ); + + return wheelDto; + } + + protected List wheelListToWheelDtoList(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList(); + for ( Wheel wheel : list ) { + list1.add( wheelToWheelDto( wheel ) ); + } + + return list1; + } + + protected CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + carDto.setName( car.getName() ); + carDto.setYear( car.getYear() ); + List list = wheelListToWheelDtoList( car.getWheels() ); + if ( list != null ) { + carDto.setWheels( list ); + } + + return carDto; + } + + protected ExternalRoofType roofTypeToExternalRoofType(RoofType roofType) { + if ( roofType == null ) { + return null; + } + + ExternalRoofType externalRoofType; + + switch ( roofType ) { + case OPEN: externalRoofType = ExternalRoofType.OPEN; + break; + case BOX: externalRoofType = ExternalRoofType.BOX; + break; + case GAMBREL: externalRoofType = ExternalRoofType.GAMBREL; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + roofType ); + } + + return externalRoofType; + } + + protected RoofDto roofToRoofDto(Roof roof) { + if ( roof == null ) { + return null; + } + + RoofDto roofDto = new RoofDto(); + + roofDto.setColor( String.valueOf( roof.getColor() ) ); + roofDto.setType( roofTypeToExternalRoofType( roof.getType() ) ); + + return roofDto; + } + + protected HouseDto houseToHouseDto(House house) { + if ( house == null ) { + return null; + } + + HouseDto houseDto = new HouseDto(); + + houseDto.setName( house.getName() ); + houseDto.setYear( house.getYear() ); + houseDto.setRoof( roofToRoofDto( house.getRoof() ) ); + + return houseDto; + } + + protected org.mapstruct.ap.test.nestedbeans.other.WheelDto wheelToWheelDto1(Wheel wheel) { + if ( wheel == null ) { + return null; + } + + org.mapstruct.ap.test.nestedbeans.other.WheelDto wheelDto = new org.mapstruct.ap.test.nestedbeans.other.WheelDto(); + + wheelDto.setFront( wheel.isFront() ); + wheelDto.setRight( wheel.isRight() ); + + return wheelDto; + } + + protected List wheelListToWheelDtoList1(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList(); + for ( Wheel wheel : list ) { + list1.add( wheelToWheelDto1( wheel ) ); + } + + return list1; + } + + protected org.mapstruct.ap.test.nestedbeans.other.CarDto carToCarDto1(Car car) { + if ( car == null ) { + return null; + } + + org.mapstruct.ap.test.nestedbeans.other.CarDto carDto = new org.mapstruct.ap.test.nestedbeans.other.CarDto(); + + carDto.setName( car.getName() ); + carDto.setYear( car.getYear() ); + List list = wheelListToWheelDtoList1( car.getWheels() ); + if ( list != null ) { + carDto.setWheels( list ); + } + + return carDto; + } + + protected org.mapstruct.ap.test.nestedbeans.other.RoofDto roofToRoofDto1(Roof roof) { + if ( roof == null ) { + return null; + } + + org.mapstruct.ap.test.nestedbeans.other.RoofDto roofDto = new org.mapstruct.ap.test.nestedbeans.other.RoofDto(); + + roofDto.setColor( String.valueOf( roof.getColor() ) ); + + return roofDto; + } + + protected org.mapstruct.ap.test.nestedbeans.other.HouseDto houseToHouseDto1(House house) { + if ( house == null ) { + return null; + } + + org.mapstruct.ap.test.nestedbeans.other.HouseDto houseDto = new org.mapstruct.ap.test.nestedbeans.other.HouseDto(); + + houseDto.setName( house.getName() ); + houseDto.setYear( house.getYear() ); + houseDto.setRoof( roofToRoofDto1( house.getRoof() ) ); + + return houseDto; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java new file mode 100644 index 0000000000..c24ec17072 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java @@ -0,0 +1,170 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-03-01T22:15:22+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" +) +public class UserDtoUpdateMapperSmartImpl implements UserDtoUpdateMapperSmart { + + @Override + public void userToUserDto(UserDto userDto, User user) { + if ( user == null ) { + return; + } + + if ( user.getName() != null ) { + userDto.setName( user.getName() ); + } + if ( user.getCar() != null ) { + if ( userDto.getCar() == null ) { + userDto.setCar( new CarDto() ); + } + carToCarDto( user.getCar(), userDto.getCar() ); + } + else { + userDto.setCar( null ); + } + if ( user.getSecondCar() != null ) { + if ( userDto.getSecondCar() == null ) { + userDto.setSecondCar( new CarDto() ); + } + carToCarDto( user.getSecondCar(), userDto.getSecondCar() ); + } + else { + userDto.setSecondCar( null ); + } + if ( user.getHouse() != null ) { + if ( userDto.getHouse() == null ) { + userDto.setHouse( new HouseDto() ); + } + houseToHouseDto( user.getHouse(), userDto.getHouse() ); + } + else { + userDto.setHouse( null ); + } + } + + protected WheelDto wheelToWheelDto(Wheel wheel) { + if ( wheel == null ) { + return null; + } + + WheelDto wheelDto = new WheelDto(); + + wheelDto.setFront( wheel.isFront() ); + wheelDto.setRight( wheel.isRight() ); + + return wheelDto; + } + + protected List wheelListToWheelDtoList(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList(); + for ( Wheel wheel : list ) { + list1.add( wheelToWheelDto( wheel ) ); + } + + return list1; + } + + protected void carToCarDto(Car car, CarDto mappingTarget) { + if ( car == null ) { + return; + } + + if ( car.getName() != null ) { + mappingTarget.setName( car.getName() ); + } + mappingTarget.setYear( car.getYear() ); + if ( mappingTarget.getWheels() != null ) { + List list = wheelListToWheelDtoList( car.getWheels() ); + if ( list != null ) { + mappingTarget.getWheels().clear(); + mappingTarget.getWheels().addAll( list ); + } + } + else { + List list = wheelListToWheelDtoList( car.getWheels() ); + if ( list != null ) { + mappingTarget.setWheels( list ); + } + } + } + + protected ExternalRoofType roofTypeToExternalRoofType(RoofType roofType) { + if ( roofType == null ) { + return null; + } + + ExternalRoofType externalRoofType; + + switch ( roofType ) { + case OPEN: externalRoofType = ExternalRoofType.OPEN; + break; + case BOX: externalRoofType = ExternalRoofType.BOX; + break; + case GAMBREL: externalRoofType = ExternalRoofType.GAMBREL; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + roofType ); + } + + return externalRoofType; + } + + protected void roofToRoofDto(Roof roof, RoofDto mappingTarget) { + if ( roof == null ) { + return; + } + + mappingTarget.setColor( String.valueOf( roof.getColor() ) ); + if ( roof.getType() != null ) { + mappingTarget.setType( roofTypeToExternalRoofType( roof.getType() ) ); + } + } + + protected void houseToHouseDto(House house, HouseDto mappingTarget) { + if ( house == null ) { + return; + } + + if ( house.getName() != null ) { + mappingTarget.setName( house.getName() ); + } + mappingTarget.setYear( house.getYear() ); + if ( house.getRoof() != null ) { + if ( mappingTarget.getRoof() == null ) { + mappingTarget.setRoof( new RoofDto() ); + } + roofToRoofDto( house.getRoof(), mappingTarget.getRoof() ); + } + else { + mappingTarget.setRoof( null ); + } + } +} From f7b6d91d5e4fe48059fd5d625f530601537f9358 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Sun, 12 Mar 2017 16:03:09 +0100 Subject: [PATCH 0079/1006] #1124 Don't pass context parameters to forged methods for nested property mapping methods --- .../ap/internal/model/PropertyMapping.java | 5 +- .../ap/test/bugs/_1124/Issue1124Mapper.java | 77 +++++++++++++++++++ .../ap/test/bugs/_1124/Issue1124Test.java | 50 ++++++++++++ 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index ed8d52c966..2e235cd269 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -48,6 +48,7 @@ import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; @@ -504,8 +505,8 @@ else if ( propertyEntries.size() == 1 ) { sourceType, config, method.getExecutable(), - method.getContextParameters(), - method.getContextProvidedMethods() ); + Collections. emptyList(), + ParameterProvidedMethods.empty() ); NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder(); NestedPropertyMappingMethod nestedPropertyMapping = builder diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java new file mode 100644 index 0000000000..940d78cfee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java @@ -0,0 +1,77 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1124; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Andreas Gudian + */ +@Mapper +public interface Issue1124Mapper { + class Entity { + private Long id; + private Entity entity; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Entity getEntity() { + return entity; + } + + public void setEntity(Entity entity) { + this.entity = entity; + } + } + + class DTO { + private Long id; + private DTO entity; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public DTO getEntity() { + return entity; + } + + public void setEntity(DTO entity) { + this.entity = entity; + } + } + + class MappingContext { + } + + @Mapping(source = "entity.id", target = "id") + DTO map(Entity entity, @Context MappingContext context); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java new file mode 100644 index 0000000000..e064e7e7be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1124; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.DTO; +import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.Entity; +import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.MappingContext; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; + +/** + * @author Andreas Gudian + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(Issue1124Mapper.class) +public class Issue1124Test { + @Test + public void nestedPropertyWithContextCompiles() { + Entity entity = new Entity(); + + Entity subEntity = new Entity(); + subEntity.setId( 42L ); + entity.setEntity( subEntity ); + + DTO dto = Mappers.getMapper( Issue1124Mapper.class ).map( entity, new MappingContext() ); + + assertThat( dto.getId() ).isEqualTo( 42L ); + } +} From 57bf93bb8438f4f1e829f40798862c8c1efa0159 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 13 Mar 2017 18:55:57 +0100 Subject: [PATCH 0080/1006] #1092 Add github id next to contributers --- copyright.txt | 56 +++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/copyright.txt b/copyright.txt index b59651d462..d37d89bfe0 100644 --- a/copyright.txt +++ b/copyright.txt @@ -1,31 +1,31 @@ Contributors ============ -Andreas Gudian -Christian Schuster -Christophe Labouisse -Ciaran Liedeman -Dilip Krishnan -Dmytro Polovinkin -Ewald Volkert -Filip Hrisafov -Gunnar Morling -Ivo Smid -Markus Heberling -Michael Pardo -Mustafa Caylak -Oliver Ehrenmüller -Paul Strugnell -Pascal Grün -Pavel Makhov -Peter Larson -Remko Plantenga -Remo Meier -Samuel Wright -Sebastian Hasait -Sean Huang -Sjaak Derksen -Stefan May -Timo Eckhardt -Tomek Gubala -Vincent Alexander Beelte +Andreas Gudian - https://github.com/agudian +Christian Schuster - https://github.com/chschu +Christophe Labouisse - https://github.com/ggtools +Ciaran Liedeman - https://github.com/cliedeman +Dilip Krishnan - https://github.com/dilipkrish +Dmytro Polovinkin - https://github.com/navpil +Ewald Volkert - https://github.com/eforest +Filip Hrisafov - https://github.com/filiphr +Gunnar Morling - https://github.com/gunnarmorling +Ivo Smid - https://github.com/bedla +Markus Heberling - https://github.com/tisoft +Michael Pardo - https://github.com/pardom +Mustafa Caylak - https://github.com/luxmeter +Oliver Ehrenmüller - https://github.com/greuelpirat +Paul Strugnell - https://github.com/ps-powa +Pascal Grün - https://github.com/pascalgn +Pavel Makhov - https://github.com/streetturtle +Peter Larson - https://github.com/pjlarson +Remko Plantenga - https://github.com/sonata82 +Remo Meier - https://github.com/remmeier +Samuel Wright - https://github.com/samwright +Sebastian Hasait - https://github.com/shasait +Sean Huang - https://github.com/seanjob +Sjaak Derksen - https://github.com/sjaakd +Stefan May - https://github.com/osthus-sm +Timo Eckhardt - https://github.com/timoe +Tomek Gubala - https://github.com/vgtworld +Vincent Alexander Beelte - https://github.com/grandmasterpixel From cab7596a4782b2ef515738e1d569cdddbc032a1a Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Mon, 13 Mar 2017 22:11:34 +0100 Subject: [PATCH 0081/1006] #1130 Consider the right target type for object factory methods --- .../model/source/selector/TypeSelector.java | 6 +- .../ap/test/bugs/_1124/Issue1124Test.java | 2 + .../ap/test/bugs/_1130/Issue1130Mapper.java | 80 +++++++++++++++++++ .../ap/test/bugs/_1130/Issue1130Test.java | 55 +++++++++++++ 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 884953a46f..d2258239d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -59,7 +59,7 @@ public List> getMatchingMethods(Method mapp List availableBindings; if ( sourceTypes.isEmpty() ) { // if no source types are given, we have a factory or lifecycle method - availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod ); + availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod, targetType ); } else { availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType, mappingMethod ); @@ -81,11 +81,11 @@ public List> getMatchingMethods(Method mapp return result; } - private List getAvailableParameterBindingsFromMethod(Method method) { + private List getAvailableParameterBindingsFromMethod(Method method, Type targetType) { List availableParams = new ArrayList( method.getParameters().size() + 2 ); availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); - addMappingTargetAndTargetTypeBindings( availableParams, method.getResultType() ); + addMappingTargetAndTargetTypeBindings( availableParams, targetType ); return availableParams; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java index e064e7e7be..ef2ddc9143 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java @@ -25,6 +25,7 @@ import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.DTO; import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.Entity; import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.MappingContext; +import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; @@ -32,6 +33,7 @@ /** * @author Andreas Gudian */ +@IssueKey("1124") @RunWith(AnnotationProcessorTestRunner.class) @WithClasses(Issue1124Mapper.class) public class Issue1124Test { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java new file mode 100644 index 0000000000..0746671992 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java @@ -0,0 +1,80 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1130; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ObjectFactory; +import org.mapstruct.TargetType; + +/** + * Test mapper similar to the one provided in the issue. + * + * @author Andreas Gudian + */ +@Mapper +public abstract class Issue1130Mapper { + static class AEntity { + private BEntity b; + + public BEntity getB() { + return b; + } + + public void setB(BEntity b) { + this.b = b; + } + } + + static class BEntity { + } + + static class ADto { + private BDto b; + + public BDto getB() { + return b; + } + + public void setB(BDto b) { + this.b = b; + } + } + + class BDto { + private final String passedViaConstructor; + + BDto(String passedViaConstructor) { + this.passedViaConstructor = passedViaConstructor; + } + + String getPassedViaConstructor() { + return passedViaConstructor; + } + } + + abstract void mergeA(AEntity source, @MappingTarget ADto target); + + abstract void mergeB(BEntity source, @MappingTarget BDto target); + + @ObjectFactory + protected BDto createB(@TargetType Class clazz) { + return new BDto( "created by factory" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java new file mode 100644 index 0000000000..fd0027b42d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1130; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.TargetType; +import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.ADto; +import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.AEntity; +import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.BEntity; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; + +/** + * Tests that when calling an update method for a previously null property, the factory method is called even if that + * factory method has a {@link TargetType} annotation. + * + * @author Andreas Gudian + */ +@IssueKey("1130") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(Issue1130Mapper.class) +public class Issue1130Test { + @Test + public void factoryMethodWithTargetTypeInUpdateMethods() { + AEntity aEntity = new AEntity(); + aEntity.setB( new BEntity() ); + + ADto aDto = new ADto(); + Mappers.getMapper( Issue1130Mapper.class ).mergeA( aEntity, aDto ); + + assertThat( aDto.getB() ).isNotNull(); + assertThat( aDto.getB().getPassedViaConstructor() ).isEqualTo( "created by factory" ); + } +} From e154452d53bc3c5867cde948def4842f2064d373 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sat, 11 Mar 2017 11:23:49 +0100 Subject: [PATCH 0082/1006] #1126 Add new CollectionMappingStrategy TARGET_IMMUTABLE --- .../mapstruct/CollectionMappingStrategy.java | 13 +++- .../mapstruct-reference-guide.asciidoc | 11 ++- .../ap/internal/model/PropertyMapping.java | 22 +++++- .../SetterWrapperForCollectionsAndMaps.java | 9 ++- .../ap/internal/model/common/Type.java | 3 +- .../prism/CollectionMappingStrategyPrism.java | 3 +- .../mapstruct/ap/internal/util/Message.java | 1 + .../SetterWrapperForCollectionsAndMaps.ftl | 2 +- .../immutabletarget/CupboardDto.java | 38 ++++++++++ .../immutabletarget/CupboardEntity.java | 38 ++++++++++ .../CupboardEntityOnlyGetter.java | 35 +++++++++ .../immutabletarget/CupboardMapper.java | 36 +++++++++ .../ErroneousCupboardMapper.java | 36 +++++++++ .../immutabletarget/ImmutableTargetTest.java | 75 +++++++++++++++++++ 14 files changed, 311 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java diff --git a/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java b/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java index 55979672ec..556e8aab01 100644 --- a/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java +++ b/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java @@ -30,7 +30,8 @@ public enum CollectionMappingStrategy { * {@code orderDto.setOrderLines(order.getOrderLines)}. *

    * If no setter is available but a getter method, this will be used, under the assumption it has been initialized: - * {@code orderDto.getOrderLines().addAll(order.getOrderLines)}. + * {@code orderDto.getOrderLines().addAll(order.getOrderLines)}. This will also be the case when using + * {@link MappingTarget} (updating existing instances). */ ACCESSOR_ONLY, @@ -51,5 +52,13 @@ public enum CollectionMappingStrategy { * Identical to {@link #SETTER_PREFERRED}, only that adder methods will be preferred over setter methods, if both * are present for a given collection-typed property. */ - ADDER_PREFERRED; + ADDER_PREFERRED, + + /** + * Identical to {@link #SETTER_PREFERRED}, however the target collection will not be cleared and accessed via + * addAll in case of updating existing bean instances, see: {@link MappingTarget}. + * + * Instead the target accessor (e.g. set) will be used on the target bean to set the collection. + */ + TARGET_IMMUTABLE; } diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index b4d537b80f..c70b53a672 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -466,7 +466,7 @@ Specifying the parameter in which the property resides is mandatory when using t Mapping methods with several source parameters will return `null` in case all the source parameters are `null`. Otherwise the target object will be instantiated and all properties from the provided parameters will be propagated. ==== -MapStruct also offers the possibility to directly refer to a source parameter. +MapStruct also offers the possibility to directly refer to a source parameter. .Mapping method directly referring to a source parameter ==== @@ -1338,7 +1338,7 @@ public Map stringStringMapToLongDateMap(Map source) [[collection-mapping-strategies]] === Collection mapping strategies -MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED` and `ADDER_PREFERRED`. +MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED`, `ADDER_PREFERRED` and `TARGET_IMMUTABLE`. In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are apply to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: @@ -1366,6 +1366,13 @@ In the table below, the dash `-` indicates a property name. Next, the trailing ` |add- |get-s |get-s + +|`TARGET_IMMUTABLE` +|set-s +|exception +|set-s +|exception +|set-s |=== Some background: An `adder` method is typically used in case of http://www.eclipse.org/webtools/dali/[generated (JPA) entities], to add a single element (entity) to an underlying collection. Invoking the adder establishes a parent-child relation between parent - the bean (entity) on which the adder is invoked - and its child(ren), the elements (entities) in the collection. To find the appropriate `adder`, MapStruct will try to make a match between the generic parameter type of the underlying collection and the single argument of a candidate `adder`. When there are more candidates, the plural `setter` / `getter` name is converted to singular and will be used in addition to make a match. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 2e235cd269..d8edebf6af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -52,6 +52,7 @@ import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -400,10 +401,15 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t Assignment result = rhs; + CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); + boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE; + if ( targetAccessorType == TargetWriteAccessorType.SETTER || - targetAccessorType == TargetWriteAccessorType.FIELD ) { + targetAccessorType == TargetWriteAccessorType.FIELD ) { + + + if ( result.isCallingUpdateMethod() && !targetImmutable) { - if ( result.isCallingUpdateMethod() ) { // call to an update method if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( @@ -423,6 +429,7 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t ); } else { + // target accessor is setter, so wrap the setter in setter map/ collection handling result = new SetterWrapperForCollectionsAndMaps( result, @@ -430,11 +437,20 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t targetType, method.getMapperConfiguration().getNullValueCheckStrategy(), ctx.getTypeFactory(), - targetWriteAccessorType == TargetWriteAccessorType.FIELD + targetWriteAccessorType == TargetWriteAccessorType.FIELD, + targetImmutable ); } } else { + if ( targetImmutable ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE, + targetPropertyName + ); + } + // target accessor is getter, so wrap the setter in getter map/ collection handling result = new GetterWrapperForCollectionsAndMaps( result, method.getThrownTypes(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java index db5faa0740..76817d208e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java @@ -47,13 +47,15 @@ public class SetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAnd private final boolean includeSourceNullCheck; private final Type targetType; private final TypeFactory typeFactory; + private final boolean targetImmutable; public SetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List thrownTypesToExclude, Type targetType, NullValueCheckStrategyPrism nvms, TypeFactory typeFactory, - boolean fieldAssignment) { + boolean fieldAssignment, + boolean targetImmutable ) { super( decoratedAssignment, @@ -64,6 +66,7 @@ public SetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, this.includeSourceNullCheck = ALWAYS == nvms; this.targetType = targetType; this.typeFactory = typeFactory; + this.targetImmutable = targetImmutable; } @Override @@ -96,4 +99,8 @@ public boolean isEnumSet() { return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); } + public boolean isTargetImmutable() { + return targetImmutable; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 4440ee4619..3be8057233 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -469,7 +469,8 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg // the current target accessor can also be a getter method. // The following if block, checks if the target accessor should be overruled by an add method. if ( cmStrategy == CollectionMappingStrategyPrism.SETTER_PREFERRED - || cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED ) { + || cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED + || cmStrategy == CollectionMappingStrategyPrism.TARGET_IMMUTABLE ) { // first check if there's a setter method. Accessor adderMethod = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java index 96851100e7..a68fa477b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java @@ -27,5 +27,6 @@ public enum CollectionMappingStrategyPrism { ACCESSOR_ONLY, SETTER_PREFERRED, - ADDER_PREFERRED; + ADDER_PREFERRED, + TARGET_IMMUTABLE; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 78169e9dff..9b2a37bdcb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -55,6 +55,7 @@ public enum Message { PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s)." ), PROPERTYMAPPING_NO_PRESENCE_CHECKER_FOR_SOURCE_TYPE( "Using custom source value presence checking strategy, but no presence checker found for %s in source type." ), PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), + PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ), CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index c681e2a8ee..a31bf3dae1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -22,7 +22,7 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> - <#if ext.existingInstanceMapping> + <#if ext.existingInstanceMapping && !targetImmutable> if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} != null ) { <@lib.handleLocalVarNullCheck> ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java new file mode 100644 index 0000000000..10fdda78b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class CupboardDto { + + private List content; + + public List getContent() { + return content; + } + + public void setContent(List content) { + this.content = content; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java new file mode 100644 index 0000000000..3579215535 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class CupboardEntity { + + private List content; + + public List getContent() { + return content; + } + + public void setContent(List content) { + this.content = content; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java new file mode 100644 index 0000000000..1552ccc89e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import java.util.List; + +/** + * + * @author Sjaak Derksen + */ +public class CupboardEntityOnlyGetter { + + private List content; + + public List getContent() { + return content; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java new file mode 100644 index 0000000000..de536286c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE ) +public interface CupboardMapper { + + CupboardMapper INSTANCE = Mappers.getMapper( CupboardMapper.class ); + + void map( CupboardDto in, @MappingTarget CupboardEntity out ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java new file mode 100644 index 0000000000..4f59ca7020 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE ) +public interface ErroneousCupboardMapper { + + ErroneousCupboardMapper INSTANCE = Mappers.getMapper( ErroneousCupboardMapper.class ); + + void map( CupboardDto in, @MappingTarget CupboardEntityOnlyGetter out ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java new file mode 100644 index 0000000000..5d331a4f8e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java @@ -0,0 +1,75 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.immutabletarget; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * + * @author Sjaak Derksen + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({CupboardDto.class, CupboardEntity.class, CupboardMapper.class}) +@IssueKey( "1126" ) +public class ImmutableTargetTest { + + @Test + public void shouldHandleImmutableTarget() { + + CupboardDto in = new CupboardDto(); + in.setContent( Arrays.asList( "cups", "soucers" ) ); + CupboardEntity out = new CupboardEntity(); + out.setContent( Collections.emptyList() ); + + CupboardMapper.INSTANCE.map( in, out ); + + assertThat( out.getContent() ).isNotNull(); + assertThat( out.getContent() ).containsExactly( "cups", "soucers" ); + } + + @Test + @WithClasses({ + ErroneousCupboardMapper.class, + CupboardEntityOnlyGetter.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCupboardMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = "No write accessor found for property \"content\" in target type.") + } + ) + public void testShouldFailOnPropertyMappingNoPropertySetterOnlyGetter() { + } + +} From 9881a8803cead1ebf7594940c5d71ebc6cadf743 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 15 Mar 2017 22:04:58 +0100 Subject: [PATCH 0083/1006] #1104 use unmapped target policy for forged name based mappings --- .../ap/internal/model/BeanMappingMethod.java | 89 +++++--- .../mapstruct/ap/internal/util/Message.java | 2 + ...=> AbstractSourceTargetMapperPrivate.java} | 6 +- .../ReferencedAccessibilityTest.java | 83 ++++--- ...va => SourceTargetMapperDefaultOther.java} | 6 +- ...te.java => SourceTargetMapperPrivate.java} | 4 +- .../nestedbeans/DottedErrorMessageTest.java | 214 ++++++++++++------ .../BaseCollectionElementPropertyMapper.java} | 9 +- .../BaseDeepListMapper.java} | 9 +- .../BaseDeepMapKeyMapper.java} | 9 +- .../BaseDeepMapValueMapper.java} | 9 +- .../BaseDeepNestingMapper.java} | 9 +- .../BaseValuePropertyMapper.java} | 9 +- .../{erroneous => unmappable}/Car.java | 2 +- .../{erroneous => unmappable}/CarDto.java | 2 +- .../{erroneous => unmappable}/Cat.java | 2 +- .../{erroneous => unmappable}/CatDto.java | 2 +- .../{erroneous => unmappable}/Color.java | 2 +- .../{erroneous => unmappable}/ColorDto.java | 2 +- .../{erroneous => unmappable}/Computer.java | 2 +- .../ComputerDto.java | 2 +- .../{erroneous => unmappable}/Dictionary.java | 2 +- .../DictionaryDto.java | 2 +- .../ExternalRoofType.java | 2 +- .../ForeignWord.java | 2 +- .../ForeignWordDto.java | 2 +- .../{erroneous => unmappable}/House.java | 2 +- .../{erroneous => unmappable}/HouseDto.java | 2 +- .../{erroneous => unmappable}/Info.java | 2 +- .../{erroneous => unmappable}/InfoDto.java | 2 +- .../{erroneous => unmappable}/Roof.java | 2 +- .../{erroneous => unmappable}/RoofDto.java | 2 +- .../{erroneous => unmappable}/RoofType.java | 2 +- .../RoofTypeMapper.java | 2 +- .../{erroneous => unmappable}/User.java | 2 +- .../{erroneous => unmappable}/UserDto.java | 2 +- .../{erroneous => unmappable}/Wheel.java | 2 +- .../{erroneous => unmappable}/WheelDto.java | 2 +- .../{erroneous => unmappable}/Word.java | 2 +- .../{erroneous => unmappable}/WordDto.java | 2 +- ...ppableCollectionElementPropertyMapper.java | 28 +++ .../erroneous/UnmappableDeepListMapper.java | 28 +++ .../erroneous/UnmappableDeepMapKeyMapper.java | 28 +++ .../UnmappableDeepMapValueMapper.java | 28 +++ .../UnmappableDeepNestingMapper.java | 28 +++ .../erroneous/UnmappableEnumMapper.java | 14 +- .../UnmappableValuePropertyMapper.java | 28 +++ ...IgnoreCollectionElementPropertyMapper.java | 28 +++ .../UnmappableIgnoreDeepListMapper.java | 28 +++ .../UnmappableIgnoreDeepMapKeyMapper.java | 28 +++ .../UnmappableIgnoreDeepMapValueMapper.java | 28 +++ .../UnmappableIgnoreDeepNestingMapper.java | 28 +++ .../UnmappableIgnoreValuePropertyMapper.java | 28 +++ ...leWarnCollectionElementPropertyMapper.java | 27 +++ .../warn/UnmappableWarnDeepListMapper.java | 27 +++ .../warn/UnmappableWarnDeepMapKeyMapper.java | 27 +++ .../UnmappableWarnDeepMapValueMapper.java | 27 +++ .../warn/UnmappableWarnDeepNestingMapper.java | 27 +++ .../UnmappableWarnValuePropertyMapper.java | 27 +++ ...ompanyMapper1.java => CompanyMapper1.java} | 4 +- .../test/updatemethods/UpdateMethodsTest.java | 16 +- ...AbstractSourceTargetMapperPrivateImpl.java | 52 +++++ .../SourceTargetMapperDefaultOtherImpl.java | 52 +++++ .../SourceTargetMapperPrivateImpl.java | 52 +++++ .../updatemethods/CompanyMapper1Impl.java | 133 +++++++++++ 65 files changed, 1114 insertions(+), 219 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/{ErroneousAbstractSourceTargetMapperPrivate.java => AbstractSourceTargetMapperPrivate.java} (80%) rename processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/{ErroneousSourceTargetMapperDefaultOther.java => SourceTargetMapperDefaultOther.java} (86%) rename processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/{ErroneousSourceTargetMapperPrivate.java => SourceTargetMapperPrivate.java} (87%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableCollectionElementPropertyMapper.java => unmappable/BaseCollectionElementPropertyMapper.java} (82%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableDeepListMapper.java => unmappable/BaseDeepListMapper.java} (84%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableDeepMapKeyMapper.java => unmappable/BaseDeepMapKeyMapper.java} (84%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableDeepMapValueMapper.java => unmappable/BaseDeepMapValueMapper.java} (84%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableDeepNestingMapper.java => unmappable/BaseDeepNestingMapper.java} (83%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous/UnmappableValuePropertyMapper.java => unmappable/BaseValuePropertyMapper.java} (83%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Car.java (96%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/CarDto.java (96%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Cat.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/CatDto.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Color.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/ColorDto.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Computer.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/ComputerDto.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Dictionary.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/DictionaryDto.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/ExternalRoofType.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/ForeignWord.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/ForeignWordDto.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/House.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/HouseDto.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Info.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/InfoDto.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Roof.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/RoofDto.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/RoofType.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/RoofTypeMapper.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/User.java (97%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/UserDto.java (97%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Wheel.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/WheelDto.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/Word.java (94%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{erroneous => unmappable}/WordDto.java (95%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepNestingMapper.java rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/{ => unmappable}/erroneous/UnmappableEnumMapper.java (62%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableValuePropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepNestingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreValuePropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepNestingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnValuePropertyMapper.java rename processor/src/test/java/org/mapstruct/ap/test/updatemethods/{ErroneousCompanyMapper1.java => CompanyMapper1.java} (91%) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivateImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOtherImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 8911fef2df..39e942965c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -674,52 +674,71 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { // fetch settings from element to implement ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); - //we handle automapping forged methods differently than the usual source ones. in - if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).isForgedNamedBased() ) { - - ForgedMethod forgedMethod = (ForgedMethod) this.method; - if ( targetProperties.isEmpty() || !unprocessedTargetProperties.isEmpty() ) { - - if ( forgedMethod.getHistory() == null ) { - Type sourceType = this.method.getParameters().get( 0 ).getType(); - Type targetType = this.method.getReturnType(); - ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, - sourceType, - targetType, - targetType, - sourceType - ); - } - else { - ForgedMethodHistory history = forgedMethod.getHistory(); - ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, - history.createSourcePropertyErrorMessage(), - history.getTargetType(), - history.createTargetPropertyName(), - history.getTargetType(), - history.getSourceType() - ); - } - + if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) { + //TODO until we solve 1140 we report this error when the target properties are empty + ForgedMethod forgedMethod = (ForgedMethod) method; + if ( forgedMethod.getHistory() == null ) { + Type sourceType = this.method.getParameters().get( 0 ).getType(); + Type targetType = this.method.getReturnType(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, + sourceType, + targetType, + targetType, + sourceType + ); + } + else { + ForgedMethodHistory history = forgedMethod.getHistory(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + history.createSourcePropertyErrorMessage(), + history.getTargetType(), + history.createTargetPropertyName(), + history.getTargetType(), + history.getSourceType() + ); } } else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; - - ctx.getMessager().printMessage( - method.getExecutable(), - msg, + Object[] args = new Object[] { MessageFormat.format( "{0,choice,1#property|1 secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = new HashMap(); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() ); + EmployeeEntity value = employeeDtoToEmployeeEntity( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } + + protected void unmappableDepartmentDtoToDepartmentEntity(UnmappableDepartmentDto unmappableDepartmentDto, DepartmentEntity mappingTarget) { + if ( unmappableDepartmentDto == null ) { + return; + } + + mappingTarget.setName( unmappableDepartmentDto.getName() ); + if ( mappingTarget.getSecretaryToEmployee() != null ) { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.getSecretaryToEmployee().clear(); + mappingTarget.getSecretaryToEmployee().putAll( map ); + } + else { + mappingTarget.setSecretaryToEmployee( null ); + } + } + else { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.setSecretaryToEmployee( map ); + } + } + } +} From fc8ded0dec6495415408fbb83e70d766c3a8d383 Mon Sep 17 00:00:00 2001 From: navpil Date: Thu, 16 Mar 2017 21:00:05 +0200 Subject: [PATCH 0084/1006] #1103 Fix issue with recursive mapping throwing a StackOverflow --- .../internal/model/AbstractBaseBuilder.java | 19 ++- .../internal/model/MappingBuilderContext.java | 18 +++ .../NestedTargetPropertyMappingHolder.java | 18 ++- .../ap/internal/model/common/Parameter.java | 23 +-- .../internal/model/source/ForgedMethod.java | 6 +- .../processor/MapperCreationProcessor.java | 5 + .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/test/nestedbeans/RecursionTest.java | 131 +++++++++++++++++ .../recursive/RecursionMapper.java | 130 +++++++++++++++++ .../recursive/TreeRecursionMapper.java | 132 ++++++++++++++++++ .../NestedTargetPropertiesTest.java | 3 +- .../nestedbeans/mixed/FishTankMapperImpl.java | 28 ++-- 12 files changed, 475 insertions(+), 39 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 6584053ffc..09c8d1e2ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -57,6 +57,14 @@ public B method(Method sourceMethod) { * @return See above */ Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) { + + if ( ctx.getForgedMethodsUnderCreation().containsKey( forgedMethod ) ) { + return createAssignment( sourceRHS, ctx.getForgedMethodsUnderCreation().get( forgedMethod ) ); + } + else { + ctx.getForgedMethodsUnderCreation().put( forgedMethod, forgedMethod ); + } + MappingMethod forgedMappingMethod; if ( MappingMethodUtils.isEnumMapping( forgedMethod ) ) { forgedMappingMethod = new ValueMappingMethod.Builder() @@ -72,7 +80,9 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod .build(); } - return createForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethod ); + Assignment forgedAssignment = createForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethod ); + ctx.getForgedMethodsUnderCreation().remove( forgedMethod ); + return forgedAssignment; } Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, MappingMethod mappingMethod) { @@ -87,9 +97,14 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp methodRef = new ForgedMethod( existingName, methodRef ); } + return createAssignment( source, methodRef ); + } + + private Assignment createAssignment(SourceRHS source, ForgedMethod methodRef) { Assignment assignment = MethodReference.forForgedMethod( methodRef, - ParameterBinding.fromParameters( methodRef.getParameters() ) ); + ParameterBinding.fromParameters( methodRef.getParameters() ) + ); assignment.setAssignment( source ); return assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 98acb9b84f..9053fdc30b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -19,7 +19,9 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.lang.model.element.TypeElement; @@ -29,6 +31,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -120,6 +123,8 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, String tar private final List mapperReferences; private final MappingResolver mappingResolver; private final List mappingsToGenerate = new ArrayList(); + private final Map forgedMethodsUnderCreation = + new HashMap( ); public MappingBuilderContext(TypeFactory typeFactory, Elements elementUtils, @@ -141,6 +146,19 @@ public MappingBuilderContext(TypeFactory typeFactory, this.mapperReferences = mapperReferences; } + /** + * Returns a map which is used to track which forged methods are under creation. + * Used for cutting the possible infinite recursion of forged method creation. + * + * Map is used instead of set because not all fields of ForgedMethods are used in equals/hashCode and we are + * interested only in the first created ForgedMethod + * + * @return map of forged methods + */ + public Map getForgedMethodsUnderCreation() { + return forgedMethodsUnderCreation; + } + public TypeElement getMapperTypeElement() { return mapperTypeElement; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 53223f1b7a..744112338e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -19,7 +19,7 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -131,7 +131,8 @@ public NestedTargetPropertyMappingHolder build() { // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); - Map> unprocessedDefinedTarget = new HashMap>(); + Map> unprocessedDefinedTarget + = new LinkedHashMap>(); for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { PropertyEntry targetProperty = entryByTP.getKey(); @@ -279,8 +280,10 @@ public NestedTargetPropertyMappingHolder build() { private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOptions) { Map> mappings = mappingOptions.getMappings(); // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty = new HashMap>(); - Map> singleTargetReferences = new HashMap>(); + Map> mappingsKeyedByProperty + = new LinkedHashMap>(); + Map> singleTargetReferences + = new LinkedHashMap>(); for ( List mapping : mappings.values() ) { PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); Mapping newMapping = first( mapping ).popTargetReference(); @@ -388,7 +391,7 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp private GroupedBySourceParameters groupBySourceParameter(List mappings, List singleTargetReferences) { - Map> mappingsKeyedByParameter = new HashMap>(); + Map> mappingsKeyedByParameter = new LinkedHashMap>(); List appliesToAll = new ArrayList(); for ( Mapping mapping : mappings ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { @@ -453,7 +456,8 @@ private GroupedSourceReferences groupByPoppedSourceReferences(List mapp List nonNested = new ArrayList(); List appliesToAll = new ArrayList(); // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty = new HashMap>(); + Map> mappingsKeyedByProperty + = new LinkedHashMap>(); for ( Mapping mapping : mappings ) { Mapping newMapping = mapping.popSourceReference(); @@ -499,7 +503,7 @@ else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { } private Map> groupByTargetName(List mappingList) { - Map> result = new HashMap>(); + Map> result = new LinkedHashMap>(); for ( Mapping mapping : mappingList ) { if ( !result.containsKey( mapping.getTargetName() ) ) { result.put( mapping.getTargetName(), new ArrayList() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index e238b58b59..e10f8730c7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -96,24 +96,27 @@ public boolean isMappingContext() { @Override public int hashCode() { - int hash = 5; - hash = 23 * hash + (this.name != null ? this.name.hashCode() : 0); - return hash; + int result = name != null ? name.hashCode() : 0; + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + return result; } @Override - public boolean equals(Object obj) { - if ( obj == null ) { - return false; + public boolean equals(Object o) { + if ( this == o ) { + return true; } - if ( getClass() != obj.getClass() ) { + if ( o == null || getClass() != o.getClass() ) { return false; } - final Parameter other = (Parameter) obj; - if ( (this.name == null) ? (other.name != null) : !this.name.equals( other.name ) ) { + + Parameter parameter = (Parameter) o; + + if ( name != null ? !name.equals( parameter.name ) : parameter.name != null ) { return false; } - return true; + return type != null ? type.equals( parameter.type ) : parameter.type == null; + } public static Parameter forElementAndType(VariableElement element, Type parameterType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 47f1a8d7b2..97523a2a60 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -335,10 +335,7 @@ public boolean equals(Object o) { if ( parameters != null ? !parameters.equals( that.parameters ) : that.parameters != null ) { return false; } - if ( returnType != null ? !returnType.equals( that.returnType ) : that.returnType != null ) { - return false; - } - return name != null ? name.equals( that.name ) : that.name == null; + return returnType != null ? returnType.equals( that.returnType ) : that.returnType == null; } @@ -346,7 +343,6 @@ public boolean equals(Object o) { public int hashCode() { int result = parameters != null ? parameters.hashCode() : 0; result = 31 * result + ( returnType != null ? returnType.hashCode() : 0 ); - result = 31 * result + ( name != null ? name.hashCode() : 0 ); return result; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 6178754e69..1ae005cb0a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -168,6 +168,11 @@ private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, .implPackage( mapperConfig.implementationPackage() ) .build(); + if ( !mappingContext.getForgedMethodsUnderCreation().isEmpty() ) { + messager.printMessage( element, Message.GENERAL_NOT_ALL_FORGED_CREATED, + mappingContext.getForgedMethodsUnderCreation().keySet() ); + } + return mapper; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index b50cc0fdc2..c2b4aef72b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -87,6 +87,7 @@ public enum Message { GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ), + GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java new file mode 100644 index 0000000000..97eb5b0661 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java @@ -0,0 +1,131 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.recursive.RecursionMapper; +import org.mapstruct.ap.test.nestedbeans.recursive.TreeRecursionMapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(AnnotationProcessorTestRunner.class) +public class RecursionTest { + + @WithClasses({ + RecursionMapper.class + }) + @Test + @IssueKey("1103") + public void testRecursiveAutoMap() { + RecursionMapper.RootDto rootDto = new RecursionMapper.RootDto( + new RecursionMapper.ChildDto( "Sub Root", new RecursionMapper.ChildDto( + "Sub child", null + ) ) + ); + RecursionMapper.Root root = RecursionMapper.INSTANCE.mapRoot( rootDto ); + + assertRootEquals( rootDto, root ); + } + + private void assertRootEquals(RecursionMapper.RootDto rootDto, RecursionMapper.Root root) { + if (bothNull( root, rootDto )) { + return; + } + assertNotNull( root ); + assertNotNull( rootDto ); + assertChildEquals( rootDto.getChild(), root.getChild() ); + } + + private void assertChildEquals(RecursionMapper.ChildDto childDto, RecursionMapper.Child child) { + if ( bothNull( childDto, child ) ) { + return; + } + assertNotNull( childDto ); + assertNotNull( child ); + assertEquals( childDto.getName(), child.getName() ); + assertChildEquals( childDto.getChild(), child.getChild() ); + } + + @WithClasses({ + TreeRecursionMapper.class + }) + @Test + @IssueKey("1103") + public void testRecursiveTreeAutoMap() { + TreeRecursionMapper.RootDto rootDto = new TreeRecursionMapper.RootDto( + Collections.singletonList( new TreeRecursionMapper.ChildDto( + "Sub Root", + Collections.singletonList( new TreeRecursionMapper.ChildDto( + "Sub child", null + ) ) + ) ) + ); + TreeRecursionMapper.Root root = TreeRecursionMapper.INSTANCE.mapRoot( rootDto ); + + assertTreeRootEquals( + rootDto, + root + ); + } + + private void assertTreeRootEquals(TreeRecursionMapper.RootDto rootDto, TreeRecursionMapper.Root root) { + if (bothNull( root, rootDto )) { + return; + } + assertNotNull( root ); + assertNotNull( rootDto ); + assertChildrenEqual( rootDto.getChild(), root.getChild() ); + } + + private void assertChildrenEqual(List childrenDto, + List children) { + if (bothNull( children, childrenDto )) { + return; + } + assertNotNull( childrenDto ); + assertNotNull( children ); + assertEquals( children.size(), childrenDto.size() ); + Iterator iterator = children.iterator(); + Iterator dtoIterator = childrenDto.iterator(); + while ( iterator.hasNext() ) { + assertTreeTreeChildEquals( dtoIterator.next(), iterator.next() ); + } + } + + private void assertTreeTreeChildEquals(TreeRecursionMapper.ChildDto childDto, TreeRecursionMapper.Child child) { + assertNotNull( child ); + assertNotNull( childDto ); + assertEquals( child.getName(), childDto.getName() ); + assertChildrenEqual( childDto.getChild(), child.getChild() ); + } + + private boolean bothNull(Object o1, Object o2) { + return o1 == null && o2 == null; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java new file mode 100644 index 0000000000..1ab1fe0f46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java @@ -0,0 +1,130 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.recursive; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class RecursionMapper { + + public static final RecursionMapper INSTANCE = Mappers.getMapper( RecursionMapper.class ); + + public abstract Root mapRoot(RootDto rootDto); + + public static class Root { + private Child child; + + public Root() { + } + + public Root(Child child) { + this.child = child; + } + + public Child getChild() { + return child; + } + + public void setChild(Child child) { + this.child = child; + } + + } + + public static class Child { + private String name; + private Child child; + + public Child() { + } + + public Child(String name, Child child) { + this.name = name; + this.child = child; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Child getChild() { + return child; + } + + public void setChild(Child child) { + this.child = child; + } + + } + + public static class RootDto { + private ChildDto child; + + public RootDto() { + } + + public RootDto(ChildDto child) { + this.child = child; + } + + public ChildDto getChild() { + return child; + } + + public void setChild(ChildDto child) { + this.child = child; + } + + } + + public static class ChildDto { + private String name; + private ChildDto child; + + public ChildDto() { + } + + public ChildDto(String name, ChildDto child) { + this.name = name; + this.child = child; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ChildDto getChild() { + return child; + } + + public void setChild(ChildDto child) { + this.child = child; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java new file mode 100644 index 0000000000..6914fd0e36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java @@ -0,0 +1,132 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.recursive; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class TreeRecursionMapper { + + public static final TreeRecursionMapper INSTANCE = Mappers.getMapper( TreeRecursionMapper.class ); + + public abstract Root mapRoot(RootDto rootDto); + + public static class Root { + private List child; + + public Root() { + } + + public Root(List child) { + this.child = child; + } + + public List getChild() { + return child; + } + + public void setChild(List child) { + this.child = child; + } + + } + + public static class Child { + private String name; + private List child; + + public Child() { + } + + public Child(String name, List child) { + this.name = name; + this.child = child; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChild() { + return child; + } + + public void setChild(List child) { + this.child = child; + } + + } + + public static class RootDto { + private List child; + + public RootDto() { + } + + public RootDto(List child) { + this.child = child; + } + + public List getChild() { + return child; + } + + public void setChild(List child) { + this.child = child; + } + + } + + public static class ChildDto { + private String name; + private List child; + + public ChildDto() { + } + + public ChildDto(String name, List child) { + this.name = name; + this.child = child; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getChild() { + return child; + } + + public void setChild(List child) { + this.child = child; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java index c9600ad9ef..c1976d656d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.test.nestedtargetproperties; -import static org.assertj.core.api.Assertions.assertThat; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,6 +32,8 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * * @author Sjaak Derksen diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 974fa32afc..40b8254e2d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -52,8 +52,8 @@ public FishTankDto map(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); Ornament ornament = sourceInteriorOrnament( source ); if ( ornament != null ) { @@ -73,8 +73,8 @@ public FishTankDto mapAsWell(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); Ornament ornament = sourceInteriorOrnament( source ); if ( ornament != null ) { @@ -107,6 +107,18 @@ public FishTank map(FishTankDto source) { return fishTank; } + protected FishDto fishToFishDto(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + return fishDto; + } + protected MaterialTypeDto materialTypeToMaterialTypeDto(MaterialType materialType) { if ( materialType == null ) { return null; @@ -131,18 +143,6 @@ protected MaterialDto fishTankToMaterialDto(FishTank fishTank) { return materialDto; } - protected FishDto fishToFishDto(Fish fish) { - if ( fish == null ) { - return null; - } - - FishDto fishDto = new FishDto(); - - fishDto.setKind( fish.getType() ); - - return fishDto; - } - protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisationDto(WaterQualityReport waterQualityReport) { if ( waterQualityReport == null ) { return null; From daedc88425f6a3cb6648e8768e00470b9b76dacf Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 16 Mar 2017 20:33:19 +0100 Subject: [PATCH 0085/1006] [maven-release-plugin] prepare release 1.2.0.Beta2 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..6c5d266069 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..0afb5f1fd5 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 171f5b0765..a1f26d9d4a 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ae7ca0e79b..8db02d5742 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..b110f390ec 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..b89fdaf771 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..40bce89ebb 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 3026e8737e..cf9d54246f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta2 diff --git a/pom.xml b/pom.xml index 63b61ce435..a8d63fd23e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta2 diff --git a/processor/pom.xml b/processor/pom.xml index 2a2c9c9296..07f27afbaa 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta2 ../parent/pom.xml From 01d9997ed6ca1cec21131be51efd6ee52370c7b0 Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Thu, 16 Mar 2017 20:33:20 +0100 Subject: [PATCH 0086/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c5d266069..f857058844 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index 0afb5f1fd5..d5555f9220 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index a1f26d9d4a..171f5b0765 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8db02d5742..ae7ca0e79b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b110f390ec..b2dcceaefa 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index b89fdaf771..e24f75f1f6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 40bce89ebb..0b8fb827cf 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index cf9d54246f..3026e8737e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta2 + HEAD diff --git a/pom.xml b/pom.xml index a8d63fd23e..63b61ce435 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta2 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 07f27afbaa..2a2c9c9296 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta2 + 1.2.0-SNAPSHOT ../parent/pom.xml From c465dd27c665bde3c93e926d0b53889d10ed7e6d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 25 Mar 2017 08:44:21 +0100 Subject: [PATCH 0087/1006] #1155 Field accessors should be considered when resolving nested target properties --- .../model/source/TargetReference.java | 5 +- .../mapstruct/ap/test/bugs/_1155/Entity.java | 43 ++++++++++++++++ .../ap/test/bugs/_1155/Issue1155Mapper.java | 35 +++++++++++++ .../ap/test/bugs/_1155/Issue1155Test.java | 50 +++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index a6259ea9b1..00487d23e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -149,8 +149,9 @@ private List getTargetEntries(Type type, String[] entryNames) { break; } - if ( (i == entryNames.length - 1) || (Executables.isSetterMethod( targetWriteAccessor ) ) ) { - // only intermediate nested properties when they are a true setter + if ( ( i == entryNames.length - 1 ) || ( Executables.isSetterMethod( targetWriteAccessor ) + || Executables.isFieldAccessor( targetWriteAccessor ) ) ) { + // only intermediate nested properties when they are a true setter or field accessor // the last may be other readAccessor (setter / getter / adder). if ( Executables.isGetterMethod( targetWriteAccessor ) || diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java new file mode 100644 index 0000000000..62a2394350 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1155; + +/** + * @author Filip Hrisafov + */ +class Entity { + + static class Client { + + //CHECKSTYLE:OFF + public long id; + //CHECKSTYLE:ON + } + + static class Dto { + + //CHECKSTYLE:OFF + public long clientId; + //CHECKSTYLE:ON + } + + //CHECKSTYLE:OFF + public Client client; + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java new file mode 100644 index 0000000000..5db16bd460 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1155; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1155Mapper { + + Issue1155Mapper INSTANCE = Mappers.getMapper( Issue1155Mapper.class ); + + @Mapping(source = "clientId", target = "client.id") + Entity toEntity(Entity.Dto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java new file mode 100644 index 0000000000..730c81b7e8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1155; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Entity.class, + Issue1155Mapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1155") +public class Issue1155Test { + + @Test + public void shouldCompile() throws Exception { + + Entity.Dto dto = new Entity.Dto(); + dto.clientId = 10; + Entity entity = Issue1155Mapper.INSTANCE.toEntity( dto ); + + assertThat( entity.client ).isNotNull(); + assertThat( entity.client.id ).isEqualTo( 10 ); + } +} From fdf37cf45100c3de685aba5ef397a6701e47d349 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 30 Mar 2017 19:18:57 +0200 Subject: [PATCH 0088/1006] #725 Flag the Annotation element with the wrong dateFormat --- .../model/ContainerMappingMethodBuilder.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 2 +- .../internal/model/MappingBuilderContext.java | 2 +- .../ap/internal/model/PropertyMapping.java | 2 +- .../common/DateFormatValidationResult.java | 17 ++- .../common/DefaultConversionContext.java | 15 ++- .../FormattingParameters.java | 28 ++++- .../model/source/IterableMapping.java | 7 +- .../ap/internal/model/source/MapMapping.java | 13 +- .../ap/internal/model/source/Mapping.java | 10 +- .../processor/MapperCreationProcessor.java | 2 +- .../creation/MappingResolverImpl.java | 42 +++---- .../common/DefaultConversionContextTest.java | 27 +++- .../erroneous/ErroneousFormatMapper.java | 58 +++++++++ .../erroneous/InvalidDateFormatTest.java | 98 +++++++++++++++ .../ap/test/conversion/erroneous/Source.java | 117 ++++++++++++++++++ .../ap/test/conversion/erroneous/Target.java | 109 ++++++++++++++++ 17 files changed, 508 insertions(+), 43 deletions(-) rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => common}/FormattingParameters.java (54%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index be5d4ea998..a96f738131 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -28,7 +28,7 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index d7f59ecf7a..681f6b54ea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -29,7 +29,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 9053fdc30b..cb713ee784 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -32,7 +32,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index d8edebf6af..9fcff9eaf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -45,7 +45,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java index 597ece891e..4409d50eab 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java @@ -18,6 +18,10 @@ */ package org.mapstruct.ap.internal.model.common; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; + import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -47,8 +51,17 @@ public boolean isValid() { return isValid; } - public void printErrorMessage(FormattingMessager messager) { - messager.printMessage( validationInfo, validationInfoArgs ); + /** + * Print the error with the most specific information possible. + * + * @param messager the messager to print the error message to + * @param element the element that had the error + * @param annotation the mirror of the annotation that had an error + * @param value the value of the annotation that had an error + */ + public void printErrorMessage(FormattingMessager messager, Element element, AnnotationMirror annotation, + AnnotationValue value) { + messager.printMessage( element, annotation, value, validationInfo, validationInfoArgs ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java index 236968a742..d1af4e85ef 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java @@ -31,18 +31,20 @@ public class DefaultConversionContext implements ConversionContext { private final FormattingMessager messager; private final Type sourceType; private final Type targetType; + private final FormattingParameters formattingParameters; private final String dateFormat; private final String numberFormat; private final TypeFactory typeFactory; public DefaultConversionContext(TypeFactory typeFactory, FormattingMessager messager, Type sourceType, - Type targetType, String dateFormat, String numberFormat) { + Type targetType, FormattingParameters formattingParameters) { this.typeFactory = typeFactory; this.messager = messager; this.sourceType = sourceType; this.targetType = targetType; - this.dateFormat = dateFormat; - this.numberFormat = numberFormat; + this.formattingParameters = formattingParameters; + this.dateFormat = this.formattingParameters.getDate(); + this.numberFormat = this.formattingParameters.getNumber(); validateDateFormat(); } @@ -55,7 +57,12 @@ private void validateDateFormat() { DateFormatValidationResult validationResult = dateFormatValidator.validate( dateFormat ); if ( !validationResult.isValid() ) { - validationResult.printErrorMessage( messager ); + validationResult.printErrorMessage( + messager, + formattingParameters.getElement(), + formattingParameters.getMirror(), + formattingParameters.getDateAnnotationValue() + ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/FormattingParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java similarity index 54% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/FormattingParameters.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java index 7d4e406a98..57428684fb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/FormattingParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java @@ -16,7 +16,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model.common; + +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; /** * @@ -24,12 +28,21 @@ */ public class FormattingParameters { + public static final FormattingParameters EMPTY = new FormattingParameters( null, null, null, null, null ); + private final String date; private final String number; + private final AnnotationMirror mirror; + private final AnnotationValue dateAnnotationValue; + private final Element element; - public FormattingParameters(String date, String number) { + public FormattingParameters(String date, String number, AnnotationMirror mirror, + AnnotationValue dateAnnotationValue, Element element) { this.date = date; this.number = number; + this.mirror = mirror; + this.dateAnnotationValue = dateAnnotationValue; + this.element = element; } public String getDate() { @@ -40,4 +53,15 @@ public String getNumber() { return number; } + public AnnotationMirror getMirror() { + return mirror; + } + + public AnnotationValue getDateAnnotationValue() { + return dateAnnotationValue; + } + + public Element getElement() { + return element; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java index 4121459de6..f7cdcdc2e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java @@ -22,6 +22,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.prism.IterableMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -69,7 +70,11 @@ public static IterableMapping fromPrism(IterableMappingPrism iterableMapping, Ex FormattingParameters formatting = new FormattingParameters( iterableMapping.dateFormat(), - iterableMapping.numberFormat() ); + iterableMapping.numberFormat(), + iterableMapping.mirror, + iterableMapping.values.dateFormat(), + method + ); return new IterableMapping( formatting, selection, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java index 7b73ad30d2..ecfe67ff57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java @@ -22,6 +22,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.prism.MapMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -82,11 +83,19 @@ public static MapMapping fromPrism(MapMappingPrism mapMapping, ExecutableElement FormattingParameters keyFormatting = new FormattingParameters( mapMapping.keyDateFormat(), - mapMapping.keyNumberFormat() ); + mapMapping.keyNumberFormat(), + mapMapping.mirror, + mapMapping.values.keyDateFormat(), + method + ); FormattingParameters valueFormatting = new FormattingParameters( mapMapping.valueDateFormat(), - mapMapping.valueNumberFormat() ); + mapMapping.valueNumberFormat(), + mapMapping.mirror, + mapMapping.values.valueDateFormat(), + method + ); return new MapMapping( keyFormatting, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 137628f71c..c225adc138 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -32,6 +32,8 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; @@ -140,7 +142,13 @@ else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultV mappingPrism.dependsOn() != null ? mappingPrism.dependsOn() : Collections.emptyList(); - FormattingParameters formattingParam = new FormattingParameters( dateFormat, numberFormat ); + FormattingParameters formattingParam = new FormattingParameters( + dateFormat, + numberFormat, + mappingPrism.mirror, + mappingPrism.values.dateFormat(), + element + ); SelectionParameters selectionParams = new SelectionParameters( mappingPrism.qualifiedBy(), mappingPrism.qualifiedByName(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 1ae005cb0a..a6908c4afb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -49,7 +49,7 @@ import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index f261d34756..e86e7c7fef 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -49,7 +49,7 @@ import org.mapstruct.ap.internal.model.common.DefaultConversionContext; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.source.FormattingParameters; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; @@ -111,18 +111,10 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, Str SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, targetPropertyName, preferUpdateMapping ); - String dateFormat = null; - String numberFormat = null; - if ( formattingParameters != null ) { - dateFormat = formattingParameters.getDate(); - numberFormat = formattingParameters.getNumber(); - } - ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, mappingMethod, - dateFormat, - numberFormat, + formattingParameters, sourceRHS, criteria ); @@ -186,24 +178,23 @@ private class ResolvingAttempt { private final Method mappingMethod; private final List methods; - private final String dateFormat; - private final String numberFormat; private final SelectionCriteria selectionCriteria; private final SourceRHS sourceRHS; private final boolean savedPreferUpdateMapping; + private final FormattingParameters formattingParameters; // resolving via 2 steps creates the possibillity of wrong matches, first builtin method matches, // second doesn't. In that case, the first builtin method should not lead to a virtual method // so this set must be cleared. private final Set virtualMethodCandidates; - private ResolvingAttempt(List sourceModel, Method mappingMethod, String dateFormat, - String numberFormat, SourceRHS sourceRHS, SelectionCriteria criteria) { + private ResolvingAttempt(List sourceModel, Method mappingMethod, + FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria) { this.mappingMethod = mappingMethod; this.methods = filterPossibleCandidateMethods( sourceModel ); - this.dateFormat = dateFormat; - this.numberFormat = numberFormat; + this.formattingParameters = + formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; this.virtualMethodCandidates = new HashSet(); this.selectionCriteria = criteria; @@ -286,8 +277,13 @@ private Assignment resolveViaConversion(Type sourceType, Type targetType) { if ( conversionProvider == null ) { return null; } - ConversionContext ctx = new DefaultConversionContext( typeFactory, messager, sourceType, targetType, - dateFormat, numberFormat ); + ConversionContext ctx = new DefaultConversionContext( + typeFactory, + messager, + sourceType, + targetType, + formattingParameters + ); // add helper methods required in conversion for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) { @@ -322,9 +318,13 @@ private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { if ( matchingBuiltInMethod != null ) { virtualMethodCandidates.add( new VirtualMappingMethod( matchingBuiltInMethod.getMethod() ) ); - ConversionContext ctx = new DefaultConversionContext( typeFactory, messager, - sourceType, - targetType, dateFormat, numberFormat); + ConversionContext ctx = new DefaultConversionContext( + typeFactory, + messager, + sourceType, + targetType, + formattingParameters + ); Assignment methodReference = MethodReference.forBuiltInMethod( matchingBuiltInMethod.getMethod(), ctx ); methodReference.setAssignment( sourceRHS ); return methodReference; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 3995946c2f..c6b5ce2cf6 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -78,7 +78,12 @@ public void testInvalidDateFormatValidation() { Type type = typeWithFQN( JavaTimeConstants.ZONED_DATE_TIME_FQN ); StatefulMessagerMock statefulMessagerMock = new StatefulMessagerMock(); new DefaultConversionContext( - null, statefulMessagerMock, type, type, "qwertz", null); + null, + statefulMessagerMock, + type, + type, + new FormattingParameters( "qwertz", null, null, null, null ) + ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isEqualTo( Diagnostic.Kind.ERROR ); } @@ -87,7 +92,12 @@ public void testNullDateFormatValidation() { Type type = typeWithFQN( JavaTimeConstants.ZONED_DATE_TIME_FQN ); StatefulMessagerMock statefulMessagerMock = new StatefulMessagerMock(); new DefaultConversionContext( - null, statefulMessagerMock, type, type, null, null); + null, + statefulMessagerMock, + type, + type, + new FormattingParameters( null, null, null, null, null ) + ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isNull(); } @@ -95,8 +105,12 @@ public void testNullDateFormatValidation() { public void testUnsupportedType() { Type type = typeWithFQN( "java.lang.String" ); StatefulMessagerMock statefulMessagerMock = new StatefulMessagerMock(); - new DefaultConversionContext( - null, statefulMessagerMock, type, type, "qwertz", null); + new DefaultConversionContext( null, + statefulMessagerMock, + type, + type, + new FormattingParameters( "qwertz", null, null, null, null ) + ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isNull(); } @@ -128,19 +142,22 @@ private static class StatefulMessagerMock implements FormattingMessager { @Override public void printMessage(Message msg, Object... arg) { - lastKindPrinted = msg.getDiagnosticKind(); + throw new UnsupportedOperationException( "Should not be called" ); } @Override public void printMessage(Element e, Message msg, Object... arg) { + throw new UnsupportedOperationException( "Should not be called" ); } @Override public void printMessage(Element e, AnnotationMirror a, Message msg, Object... arg) { + throw new UnsupportedOperationException( "Should not be called" ); } @Override public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, Object... arg) { + lastKindPrinted = msg.getDiagnosticKind(); } public Diagnostic.Kind getLastKindPrinted() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java new file mode 100644 index 0000000000..7f059125d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.erroneous; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousFormatMapper { + + @Mappings( { + @Mapping(target = "date", dateFormat = "qwertz"), + @Mapping(target = "zonedDateTime", dateFormat = "qwertz"), + @Mapping(target = "localDateTime", dateFormat = "qwertz"), + @Mapping(target = "localDate", dateFormat = "qwertz"), + @Mapping(target = "localTime", dateFormat = "qwertz"), + @Mapping(target = "dateTime", dateFormat = "qwertz"), + @Mapping(target = "jodaLocalDateTime", dateFormat = "qwertz"), + @Mapping(target = "jodaLocalDate", dateFormat = "qwertz"), + @Mapping(target = "jodaLocalTime", dateFormat = "qwertz") + } ) + Target sourceToTarget(Source source); + + @IterableMapping(dateFormat = "qwertz") + List fromDates(List dates); + + @MapMapping(keyDateFormat = "qwertz") + Map fromDateKeys(Map dates); + + @MapMapping(valueDateFormat = "qwertz") + Map fromDateValues(Map dates); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java new file mode 100644 index 0000000000..09c4ad2c3e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -0,0 +1,98 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.erroneous; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Source.class, + Target.class +}) +@IssueKey("725") +@RunWith(AnnotationProcessorTestRunner.class) +public class InvalidDateFormatTest { + + @WithClasses({ + ErroneousFormatMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 38, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 39, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 40, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 41, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 42, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 43, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 44, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 45, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 46, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 50, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 53, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + @Diagnostic(type = ErroneousFormatMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 56, + messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"") + }) + @Test + public void shouldFailWithInvalidDateFormats() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java new file mode 100644 index 0000000000..8614d1d6d2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java @@ -0,0 +1,117 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.erroneous; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; +import java.util.Date; + +import org.joda.time.DateTime; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private Date date; + + private ZonedDateTime zonedDateTime; + private LocalDateTime localDateTime; + private LocalDate localDate; + private LocalTime localTime; + + private DateTime dateTime; + private org.joda.time.LocalDateTime jodaLocalDateTime; + private org.joda.time.LocalDate jodaLocalDate; + private org.joda.time.LocalTime jodaLocalTime; + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(ZonedDateTime zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public void setLocalDate(LocalDate localDate) { + this.localDate = localDate; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public void setLocalTime(LocalTime localTime) { + this.localTime = localTime; + } + + public DateTime getDateTime() { + return dateTime; + } + + public void setDateTime(DateTime dateTime) { + this.dateTime = dateTime; + } + + public org.joda.time.LocalDateTime getJodaLocalDateTime() { + return jodaLocalDateTime; + } + + public void setJodaLocalDateTime(org.joda.time.LocalDateTime jodaLocalDateTime) { + this.jodaLocalDateTime = jodaLocalDateTime; + } + + public org.joda.time.LocalDate getJodaLocalDate() { + return jodaLocalDate; + } + + public void setJodaLocalDate(org.joda.time.LocalDate jodaLocalDate) { + this.jodaLocalDate = jodaLocalDate; + } + + public org.joda.time.LocalTime getJodaLocalTime() { + return jodaLocalTime; + } + + public void setJodaLocalTime(org.joda.time.LocalTime jodaLocalTime) { + this.jodaLocalTime = jodaLocalTime; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java new file mode 100644 index 0000000000..a6a71b8fdd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java @@ -0,0 +1,109 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.erroneous; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String date; + + private String zonedDateTime; + private String localDateTime; + private String localDate; + private String localTime; + + private String dateTime; + private String jodaLocalDateTime; + private String jodaLocalDate; + private String jodaLocalTime; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(String zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } + + public String getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(String localDateTime) { + this.localDateTime = localDateTime; + } + + public String getLocalDate() { + return localDate; + } + + public void setLocalDate(String localDate) { + this.localDate = localDate; + } + + public String getLocalTime() { + return localTime; + } + + public void setLocalTime(String localTime) { + this.localTime = localTime; + } + + public String getDateTime() { + return dateTime; + } + + public void setDateTime(String dateTime) { + this.dateTime = dateTime; + } + + public String getJodaLocalDateTime() { + return jodaLocalDateTime; + } + + public void setJodaLocalDateTime(String jodaLocalDateTime) { + this.jodaLocalDateTime = jodaLocalDateTime; + } + + public String getJodaLocalDate() { + return jodaLocalDate; + } + + public void setJodaLocalDate(String jodaLocalDate) { + this.jodaLocalDate = jodaLocalDate; + } + + public String getJodaLocalTime() { + return jodaLocalTime; + } + + public void setJodaLocalTime(String jodaLocalTime) { + this.jodaLocalTime = jodaLocalTime; + } +} From bbff0c03499faf9ef1b0a8b99fa50b860d8e100f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 31 Mar 2017 21:41:08 +0200 Subject: [PATCH 0089/1006] #1164 Make sure that all import types of a Type are imported for the collection and map wrappers --- .../WrapperForCollectionsAndMaps.java | 3 +- .../ap/test/bugs/_1164/GenericHolder.java | 35 ++++++++++ .../ap/test/bugs/_1164/Issue1164Test.java | 43 ++++++++++++ .../mapstruct/ap/test/bugs/_1164/Source.java | 59 +++++++++++++++++ .../test/bugs/_1164/SourceTargetMapper.java | 47 ++++++++++++++ .../mapstruct/ap/test/bugs/_1164/Target.java | 65 +++++++++++++++++++ 6 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index 512012bba4..f286a45f09 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -72,8 +72,7 @@ public List getThrownTypes() { public Set getImportTypes() { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); - imported.add( nullCheckLocalVarType ); - imported.addAll( nullCheckLocalVarType.getTypeParameters() ); + imported.addAll( nullCheckLocalVarType.getImportTypes() ); return imported; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java new file mode 100644 index 0000000000..7d5dd28d6b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1164; + +/** + * @author Filip Hrisafov + */ +class GenericHolder { + + private T value; + + public T getValue() { + return value; + } + + public void setValue(T value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java new file mode 100644 index 0000000000..fd2990b1b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1164; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses( { + Source.class, + Target.class, + GenericHolder.class, + SourceTargetMapper.class +} ) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey( "1164" ) +public class Issue1164Test { + + @Test + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java new file mode 100644 index 0000000000..e59304c77d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1164; + +import java.util.List; +import java.util.Map; + +/** + * @author Filip Hrisafov + */ +class Source { + + public static class SourceNested { + } + + private List> nestedLists; + private Map> nestedMaps; + private GenericHolder> genericHolder; + + public List> getNestedLists() { + return nestedLists; + } + + public void setNestedLists(List> nestedLists) { + this.nestedLists = nestedLists; + } + + public Map> getNestedMaps() { + return nestedMaps; + } + + public void setNestedMaps(Map> nestedMaps) { + this.nestedMaps = nestedMaps; + } + + public GenericHolder> getGenericHolder() { + return genericHolder; + } + + public void setGenericHolder(GenericHolder> genericHolder) { + this.genericHolder = genericHolder; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java new file mode 100644 index 0000000000..9761dfa015 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1164; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class SourceTargetMapper { + + public abstract Target map(Source source); + + protected List> mapLists(List> lists) { + return new ArrayList>(); + } + + protected Map> map(Map> map) { + return new HashMap>(); + } + + protected GenericHolder> map(GenericHolder> genericHolder) { + return new GenericHolder>(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java new file mode 100644 index 0000000000..c80a8ecc22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java @@ -0,0 +1,65 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1164; + +import java.util.List; +import java.util.Map; + +/** + * @author Filip Hrisafov + */ +class Target { + + public static class TargetNested { + } + + public static class MapNested { + } + + public static class GenericNested { + } + + private List> nestedLists; + private Map> nestedMaps; + private GenericHolder> genericHolder; + + public List> getNestedLists() { + return nestedLists; + } + + public void setNestedLists(List> nestedLists) { + this.nestedLists = nestedLists; + } + + public Map> getNestedMaps() { + return nestedMaps; + } + + public void setNestedMaps(Map> nestedMaps) { + this.nestedMaps = nestedMaps; + } + + public GenericHolder> getGenericHolder() { + return genericHolder; + } + + public void setGenericHolder(GenericHolder> genericHolder) { + this.genericHolder = genericHolder; + } +} From 5fccc6c2d5ee291f99c6ced730980145fa62c893 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 6 Apr 2017 21:22:38 +0200 Subject: [PATCH 0090/1006] #1171 Add Travis CI (#1172) --- .travis.yml | 14 ++++++++++++ etc/toolchains-travis-jenkins.xml | 37 +++++++++++++++++++++++++++++++ parent/pom.xml | 2 ++ 3 files changed, 53 insertions(+) create mode 100644 .travis.yml create mode 100644 etc/toolchains-travis-jenkins.xml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..73df7ae834 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: java +jdk: + - oraclejdk8 +install: true +script: mvn clean install -DprocessorIntegrationTest.toolchainsFile=etc/toolchains-travis-jenkins.xml -B -V + +sudo: false +cache: + directories: + - $HOME/.m2 +addons: + apt: + packages: + - oracle-java8-installer diff --git a/etc/toolchains-travis-jenkins.xml b/etc/toolchains-travis-jenkins.xml new file mode 100644 index 0000000000..8d49c8e7ef --- /dev/null +++ b/etc/toolchains-travis-jenkins.xml @@ -0,0 +1,37 @@ + + + + jdk + + 1.6 + oracle + jdk1.6 + + + /usr/lib/jvm/java-6-openjdk-amd64/ + + + + jdk + + 1.7 + oracle + jdk1.7 + + + /usr/lib/jvm/java-7-oracle/ + + + + jdk + + 1.8 + oracle + jdk1.8 + + + /usr/lib/jvm/java-8-oracle/ + + + + diff --git a/parent/pom.xml b/parent/pom.xml index 3026e8737e..30bb2a27ea 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -397,6 +397,8 @@ ${org.apache.maven.plugins.surefire.version} ${forkCount} + + -Xms1024m -Xmx3072m From 267c2e98f9d894eed6d690bd3a62f7ef02d06cc0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 20 Apr 2017 23:37:16 +0200 Subject: [PATCH 0091/1006] #993 Add support for disabling the generation of forged mapping methods --- .../src/main/java/org/mapstruct/Mapper.java | 19 +++++ .../main/java/org/mapstruct/MapperConfig.java | 18 +++++ .../internal/model/AbstractBaseBuilder.java | 30 ++++++++ .../model/AbstractMappingMethodBuilder.java | 3 + .../model/ContainerMappingMethodBuilder.java | 15 ++++ .../ap/internal/model/MapMappingMethod.java | 41 +++++++++++ .../ap/internal/model/PropertyMapping.java | 13 ++-- .../ap/internal/util/MapperConfiguration.java | 12 +++ .../ErroneousCollectionMappingTest.java | 49 +++++++++++++ ...tionNoElementMappingFoundDisabledAuto.java | 33 +++++++++ ...llectionNoKeyMappingFoundDisabledAuto.java | 33 +++++++++ ...ectionNoValueMappingFoundDisabledAuto.java | 33 +++++++++ ...reamNoElementMappingFoundDisabledAuto.java | 34 +++++++++ .../erroneous/ErroneousStreamMappingTest.java | 61 ++++++++++++++-- ...ListNoElementMappingFoundDisabledAuto.java | 34 +++++++++ ...reamNoElementMappingFoundDisabledAuto.java | 33 +++++++++ .../ap/test/nestedbeans/DisableConfig.java | 28 +++++++ ...DisablingNestedSimpleBeansMappingTest.java | 73 +++++++++++++++++++ .../ErroneousDisabledHouseMapper.java | 30 ++++++++ ...ErroneousDisabledViaConfigHouseMapper.java | 30 ++++++++ 20 files changed, 611 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index 6fe6275b33..f41e63df4e 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -159,4 +159,23 @@ * @return strategy how to do null checking */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + + /** + * If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a + * sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to + * automatically generate sub-mapping methods. + *

    + * Can be configured by the {@link MapperConfig#disableSubMappingMethodsGeneration()} as well. + *

    + * Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at + * mapstruct.org or + * github.com/mapstruct/mapstruct to share what problem you + * are facing with the automatic sub-mapping generation. + * + * @return whether the automatic generation of sub-mapping methods is disabled + * + * @since 1.2 + */ + boolean disableSubMappingMethodsGeneration() default false; + } diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index 6091b6d48e..89db2bed58 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -146,4 +146,22 @@ MappingInheritanceStrategy mappingInheritanceStrategy() * @return strategy how to do null checking */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + + /** + * If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a + * sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to + * automatically generate sub-mapping methods. + *

    + * Can be overridden by {@link Mapper#disableSubMappingMethodsGeneration()} + *

    + * Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at + * mapstruct.org or + * github.com/mapstruct/mapstruct to share what problem you + * are facing with the automatic sub-mapping generation. + * + * @return whether the automatic generation of sub-mapping methods is disabled + * + * @since 1.2 + */ + boolean disableSubMappingMethodsGeneration() default false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 09c8d1e2ca..8f11684abd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -20,9 +20,12 @@ import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.MappingMethodUtils; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.util.MapperConfiguration; +import org.mapstruct.ap.internal.util.Message; /** * @author Filip Hrisafov @@ -47,6 +50,11 @@ public B method(Method sourceMethod) { return myself; } + boolean isDisableSubMappingMethodsGeneration() { + MapperConfiguration configuration = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ); + return configuration.isDisableSubMappingMethodsGeneration(); + } + /** * Creates a forged assignment from the provided {@code sourceRHS} and {@code forgedMethod}. If a mapping method * for the {@code forgedMethod} already exists, then this method used for the assignment. @@ -109,4 +117,26 @@ private Assignment createAssignment(SourceRHS source, ForgedMethod methodRef) { return assignment; } + + /** + * Reports that a mapping could not be created. + * + * @param method the method that should be mapped + * @param sourceErrorMessagePart the error message part for the source + * @param sourceRHS the {@link SourceRHS} + * @param targetType the type of the target mapping + * @param targetPropertyName the name of the target property + */ + void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, SourceRHS sourceRHS, Type targetType, + String targetPropertyName) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + sourceErrorMessagePart, + targetType, + targetPropertyName, + targetType, + sourceRHS.getSourceType() /* original source type */ + ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index f28540834d..943724dba7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -45,6 +45,9 @@ public AbstractMappingMethodBuilder(Class selfType) { protected abstract boolean shouldUsePropertyNamesInHistory(); Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + if ( isDisableSubMappingMethodsGeneration() ) { + return null; + } String name = getName( sourceType, targetType ); name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index a96f738131..cd972660bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -112,6 +112,21 @@ public final M build() { forgedMethod.addThrownTypes( assignment.getThrownTypes() ); } } + if ( assignment == null ) { + if ( method instanceof ForgedMethod ) { + // leave messaging to calling property mapping + return null; + } + else { + reportCannotCreateMapping( + method, + String.format( "%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), sourceRHS.getSourceType() ), + sourceRHS, + targetElementType, + "" + ); + } + } assignment = getWrapper( assignment, method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 681f6b54ea..b94a18b37b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -110,6 +110,27 @@ public MapMappingMethod build() { keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); } + + if ( keyAssignment == null ) { + if ( method instanceof ForgedMethod ) { + // leave messaging to calling property mapping + return null; + } + else { + reportCannotCreateMapping( + method, + String.format( + "%s \"%s\"", + keySourceRHS.getSourceErrorMessagePart(), + keySourceRHS.getSourceType() + ), + keySourceRHS, + keyTargetType, + "" + ); + } + } + // find mapping method or conversion for value Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound(); Type valueTargetType = resultTypeParams.get( 1 ).getTypeBound(); @@ -140,6 +161,26 @@ public MapMappingMethod build() { valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); } + if ( valueAssignment == null ) { + if ( method instanceof ForgedMethod ) { + // leave messaging to calling property mapping + return null; + } + else { + reportCannotCreateMapping( + method, + String.format( + "%s \"%s\"", + valueSourceRHS.getSourceErrorMessagePart(), + valueSourceRHS.getSourceType() + ), + valueSourceRHS, + valueTargetType, + "" + ); + } + } + // mapNullToDefault boolean mapNullToDefault = false; if ( method.getMapperConfiguration() != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 9fcff9eaf4..cc2a0d8277 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -302,14 +302,12 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get } } else { - ctx.getMessager().printMessage( - method.getExecutable(), - Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + reportCannotCreateMapping( + method, rightHandSide.getSourceErrorMessagePart(), + rightHandSide, targetType, - targetPropertyName, - targetType, - rightHandSide.getSourceType() /* original source type */ + targetPropertyName ); } @@ -635,6 +633,9 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s } private Assignment forgeMapping(SourceRHS sourceRHS) { + if ( forgedNamedBased && isDisableSubMappingMethodsGeneration() ) { + return null; + } Type sourceType = sourceRHS.getSourceType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 5bb0993ea7..3d1a98cdb1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -194,6 +194,18 @@ public String componentModel(Options options) { return mapperPrism.componentModel(); // fall back to default defined in the annotation } + public boolean isDisableSubMappingMethodsGeneration() { + if ( mapperPrism.disableSubMappingMethodsGeneration() ) { + return mapperPrism.disableSubMappingMethodsGeneration(); + } + + if ( mapperConfigPrism != null && mapperConfigPrism.disableSubMappingMethodsGeneration() ) { + return mapperConfigPrism.disableSubMappingMethodsGeneration(); + } + + return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation + } + public DeclaredType config() { return config; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 5c605a5bc1..46544819e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -123,6 +123,23 @@ public void shouldFailOnEmptyMapAnnotation() { public void shouldFailOnNoElementMappingFound() { } + @Test + @IssueKey("993") + @WithClasses({ ErroneousCollectionNoElementMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCollectionNoElementMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 32, + messageRegExp = + "Can't map collection element \".*AttributedString\" to \".*String \". " + + "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + } + ) + public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { + } + @Test @IssueKey("459") @WithClasses({ ErroneousCollectionNoKeyMappingFound.class }) @@ -139,6 +156,22 @@ public void shouldFailOnNoElementMappingFound() { public void shouldFailOnNoKeyMappingFound() { } + @Test + @IssueKey("993") + @WithClasses({ ErroneousCollectionNoKeyMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCollectionNoKeyMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 32, + messageRegExp = "Can't map map key \".*AttributedString\" to \".*String \". " + + "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + } + ) + public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { + } + @Test @IssueKey("459") @WithClasses({ ErroneousCollectionNoValueMappingFound.class }) @@ -154,4 +187,20 @@ public void shouldFailOnNoKeyMappingFound() { ) public void shouldFailOnNoValueMappingFound() { } + + @Test + @IssueKey("993") + @WithClasses({ ErroneousCollectionNoValueMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCollectionNoValueMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 32, + messageRegExp = "Can't map map value \".*AttributedString\" to \".*String \". " + + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoValueMappingFoundWithDisabledAuto() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..43a159f5bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.erroneous; + +import java.text.AttributedString; +import java.util.List; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousCollectionNoElementMappingFoundDisabledAuto { + + List map(List source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..c0cd8fcb71 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.erroneous; + +import java.text.AttributedString; +import java.util.Map; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousCollectionNoKeyMappingFoundDisabledAuto { + + Map map(Map source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..365c62a757 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.erroneous; + +import java.text.AttributedString; +import java.util.Map; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousCollectionNoValueMappingFoundDisabledAuto { + + Map map(Map source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..157146ee92 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousListToStreamNoElementMappingFoundDisabledAuto { + + Stream mapCollectionToStream(List source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index 093eb75c85..ae35c39734 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -115,13 +115,30 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 36, - messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." + - " Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = "Can't map Stream element \".*AttributedString attributedString\" to \".*String " + + "string\". Consider to declare/implement a mapping method: \".*String map(.*AttributedString " + + "value)") } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { } + @Test + @IssueKey("993") + @WithClasses({ ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 32, + messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + + "declare/implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() { + } + @Test @WithClasses({ ErroneousListToStreamNoElementMappingFound.class }) @ExpectedCompilationOutcome( @@ -130,13 +147,30 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map .*AttributedString attributedString\" to .*String string\". " + - "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + messageRegExp = + "Can't map Stream element \".*AttributedString attributedString\" to \".*String string\". " + + "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") } ) public void shouldFailOnNoElementMappingFoundForListToStream() { } + @Test + @IssueKey("993") + @WithClasses({ ErroneousListToStreamNoElementMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 33, + messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + + "declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + } + ) + public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { + } + @Test @WithClasses({ ErroneousStreamToListNoElementMappingFound.class }) @ExpectedCompilationOutcome( @@ -145,10 +179,27 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, line = 37, - messageRegExp = "Can't map Stream element .*AttributedString attributedString\" to .*String string\"." + + messageRegExp = + "Can't map Stream element \".*AttributedString attributedString\" to .*String string\"." + " Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { } + + @Test + @IssueKey("993") + @WithClasses({ ErroneousStreamToListNoElementMappingFoundDisabledAuto.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousStreamToListNoElementMappingFoundDisabledAuto.class, + kind = Kind.ERROR, + line = 33, + messageRegExp = "Can't map stream element \".*AttributedString\" to .*String \". Consider to " + + "declare/implement a mapping method: \".*String map(.*AttributedString value)") + } + ) + public void shouldFailOnNoElementMappingFoundForStreamToListWithDisabledAuto() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..a3c1c7e65c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.List; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousStreamToListNoElementMappingFoundDisabledAuto { + + List mapStreamToCollection(Stream source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java new file mode 100644 index 0000000000..56efd7e330 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.java8stream.erroneous; + +import java.text.AttributedString; +import java.util.stream.Stream; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousStreamToStreamNoElementMappingFoundDisabledAuto { + + Stream mapStreamToStream(Stream source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java new file mode 100644 index 0000000000..8c49d6090e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(disableSubMappingMethodsGeneration = true) +public interface DisableConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java new file mode 100644 index 0000000000..2452936082 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -0,0 +1,73 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + House.class, HouseDto.class, + Wheel.class, WheelDto.class, + Roof.class, RoofDto.class, + RoofType.class, ExternalRoofType.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class DisablingNestedSimpleBeansMappingTest { + + @WithClasses({ + ErroneousDisabledHouseMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDisabledHouseMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + + "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." + ) + }) + @Test + public void shouldUseDisabledMethodGenerationOnMapper() throws Exception { + } + + @WithClasses({ + ErroneousDisabledViaConfigHouseMapper.class, + DisableConfig.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDisabledViaConfigHouseMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + + "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." + ) + }) + @Test + public void shouldUseDisabledMethodGenerationOnMapperConfig() throws Exception { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java new file mode 100644 index 0000000000..d5617b70f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(disableSubMappingMethodsGeneration = true) +public interface ErroneousDisabledHouseMapper { + + HouseDto houseToHouseDto(House house); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java new file mode 100644 index 0000000000..ff5ceabf3b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = DisableConfig.class) +public interface ErroneousDisabledViaConfigHouseMapper { + + HouseDto houseToHouseDto(House house); +} From 63689e67a01fa845f0c46e023403f2c49148906a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Apr 2017 13:08:47 +0200 Subject: [PATCH 0092/1006] Make sure that surefire keeps the argline modified by jacoco --- processor/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/processor/pom.xml b/processor/pom.xml index 2a2c9c9296..9aa1c36041 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -143,6 +143,11 @@ org.apache.maven.plugins maven-surefire-plugin + + + @{argLine} + org.apache.maven.plugins From 25401794b0e506ef061f1489fa59f8a3f99479d0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Apr 2017 13:23:15 +0200 Subject: [PATCH 0093/1006] Add the workaround for Travis in the processor pom --- processor/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/pom.xml b/processor/pom.xml index 9aa1c36041..30594a6e6c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -146,7 +146,7 @@ - @{argLine} + @{argLine} -Xms1024m -Xmx3072m From 763deaa9177a83c13df987687d3ef5d02546a6b5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 25 Apr 2017 22:41:51 +0200 Subject: [PATCH 0094/1006] #1164 Split the SetterWrapperForCollections into multiple models: * SetterWrapperForCollectionsAndMaps - Does a simple assignment without doing any null checks * SetterWrapperForCollectionsAndMapsWithNullCheck - Does an assignment that does a null check before assignment and takes direct assignment into consideration * ExistingInstanceSetterWrapperForCollectionsAndMaps - Used for wrapping an assignment when the method is an update method Additionally don't do local var assignment if there are presence checkers --- .../model/CollectionAssignmentBuilder.java | 185 ++++++++++++++++++ .../ap/internal/model/PropertyMapping.java | 81 ++------ ...nceSetterWrapperForCollectionsAndMaps.java | 66 +++++++ .../GetterWrapperForCollectionsAndMaps.java | 10 + .../SetterWrapperForCollectionsAndMaps.java | 70 +------ ...perForCollectionsAndMapsWithNullCheck.java | 85 ++++++++ .../WrapperForCollectionsAndMaps.java | 10 - ...anceSetterWrapperForCollectionsAndMaps.ftl | 56 ++++++ .../GetterWrapperForCollectionsAndMaps.ftl | 4 +- .../SetterWrapperForCollectionsAndMaps.ftl | 38 +--- ...pperForCollectionsAndMapsWithNullCheck.ftl | 48 +++++ .../ap/internal/model/macro/CommonMacros.ftl | 17 +- .../mapstruct/ap/test/bugs/_913/Domain.java | 7 +- ...ssue913SetterMapperForCollectionsTest.java | 42 ++-- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 64 +++--- .../DomainDtoWithNvmsDefaultMapperImpl.java | 20 +- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 20 +- .../DomainDtoWithPresenceCheckMapperImpl.java | 62 +++--- .../adder/SourceTargetMapperImpl.java | 10 +- ...SourceTargetMapperStrategyDefaultImpl.java | 10 +- .../nestedbeans/UserDtoMapperClassicImpl.java | 9 +- .../nestedbeans/UserDtoMapperSmartImpl.java | 14 +- .../ChartEntryToArtistImpl.java | 9 +- 23 files changed, 612 insertions(+), 325 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java new file mode 100644 index 0000000000..ea9f6dd6b0 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -0,0 +1,185 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps; +import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; +import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; +import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck; +import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.accessor.Accessor; + +/** + * A builder that is used for creating an assignment to a collection. + * + * The created assignments to the following null checks: + *

      + *
    • source-null-check - For this the {@link SetterWrapperForCollectionsAndMapsWithNullCheck} is used when a + * direct assignment is done or the {@link org.mapstruct.NullValueCheckStrategy} is + * {@link org.mapstruct.NullValueCheckStrategy#ALWAYS}. It is also done in + * {@link ExistingInstanceSetterWrapperForCollectionsAndMaps} which extends + * {@link SetterWrapperForCollectionsAndMapsWithNullCheck}
    • + *
    • target-null-check - Done in the {@link ExistingInstanceSetterWrapperForCollectionsAndMaps}
    • + *
    • local-var-null-check - Done in {@link ExistingInstanceSetterWrapperForCollectionsAndMaps}, and + * {@link SetterWrapperForCollectionsAndMapsWithNullCheck}
    • + *
    + * + * A local-var-null-check is needed in the following cases: + * + *
      + *
    • Presence check with direct assignment - We need a null check before setting, because we use the copy + * constructor
    • + *
    • Presence check for existing instance mapping - We need the null check because we call addAll / putAll.
    • + *
    • No Presence check and direct assignment - We use the copy constructor
    • + *
    • No Presence check and {@link org.mapstruct.NullValueCheckStrategy#ALWAYS} - the user requested one
    • + *
    + * + * @author Filip Hrisafov + */ +public class CollectionAssignmentBuilder { + private MappingBuilderContext ctx; + private Method method; + private Accessor targetReadAccessor; + private Type targetType; + private String targetPropertyName; + private PropertyMapping.TargetWriteAccessorType targetAccessorType; + private Assignment rhs; + + public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) { + this.ctx = ctx; + return this; + } + + public CollectionAssignmentBuilder method(Method method) { + this.method = method; + return this; + } + + public CollectionAssignmentBuilder targetReadAccessor(Accessor targetReadAccessor) { + this.targetReadAccessor = targetReadAccessor; + return this; + } + + public CollectionAssignmentBuilder targetType(Type targetType) { + this.targetType = targetType; + return this; + } + + public CollectionAssignmentBuilder targetPropertyName(String targetPropertyName) { + this.targetPropertyName = targetPropertyName; + return this; + } + + public CollectionAssignmentBuilder targetAccessorType(PropertyMapping.TargetWriteAccessorType targetAccessorType) { + this.targetAccessorType = targetAccessorType; + return this; + } + + public CollectionAssignmentBuilder rightHandSide(Assignment rhs) { + this.rhs = rhs; + return this; + } + + public Assignment build() { + Assignment result = rhs; + + CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); + boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE; + + if ( targetAccessorType == PropertyMapping.TargetWriteAccessorType.SETTER || + targetAccessorType == PropertyMapping.TargetWriteAccessorType.FIELD ) { + + if ( result.isCallingUpdateMethod() && !targetImmutable ) { + + // call to an update method + if ( targetReadAccessor == null ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, + targetPropertyName + ); + } + Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + result = new UpdateWrapper( + result, + method.getThrownTypes(), + factoryMethod, + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), + targetType, + true + ); + } + else if ( method.isUpdateMethod() && !targetImmutable ) { + result = new ExistingInstanceSetterWrapperForCollectionsAndMaps( + result, + method.getThrownTypes(), + targetType, + method.getMapperConfiguration().getNullValueCheckStrategy(), + ctx.getTypeFactory(), + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + ); + } + else if ( result.getType() == Assignment.AssignmentType.DIRECT || + method.getMapperConfiguration().getNullValueCheckStrategy() == NullValueCheckStrategyPrism.ALWAYS ) { + result = new SetterWrapperForCollectionsAndMapsWithNullCheck( + result, + method.getThrownTypes(), + targetType, + ctx.getTypeFactory(), + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + ); + } + else { + + // target accessor is setter, so wrap the setter in setter map/ collection handling + result = new SetterWrapperForCollectionsAndMaps( + result, + method.getThrownTypes(), + targetType, + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + ); + } + } + else { + if ( targetImmutable ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE, + targetPropertyName + ); + } + + // target accessor is getter, so wrap the setter in getter map/ collection handling + result = new GetterWrapperForCollectionsAndMaps( + result, + method.getThrownTypes(), + targetType, + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + ); + } + + return result; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index cc2a0d8277..e8a109996a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -38,21 +38,19 @@ import org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; -import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -79,7 +77,7 @@ public class PropertyMapping extends ModelElement { private final List dependsOn; private final Assignment defaultValueAssignment; - private enum TargetWriteAccessorType { + public enum TargetWriteAccessorType { FIELD, GETTER, SETTER, @@ -99,6 +97,10 @@ else if ( Executables.isGetterMethod( accessor ) ) { return TargetWriteAccessorType.FIELD; } } + + public static boolean isFieldAssignment(TargetWriteAccessorType accessorType) { + return accessorType == FIELD; + } } @SuppressWarnings("unchecked") @@ -396,68 +398,15 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { private Assignment assignToCollection(Type targetType, TargetWriteAccessorType targetAccessorType, Assignment rhs) { - - Assignment result = rhs; - - CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); - boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE; - - if ( targetAccessorType == TargetWriteAccessorType.SETTER || - targetAccessorType == TargetWriteAccessorType.FIELD ) { - - - if ( result.isCallingUpdateMethod() && !targetImmutable) { - - // call to an update method - if ( targetReadAccessor == null ) { - ctx.getMessager().printMessage( - method.getExecutable(), - Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, - targetPropertyName - ); - } - Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); - result = new UpdateWrapper( - result, - method.getThrownTypes(), - factoryMethod, - isFieldAssignment(), - targetType, - true - ); - } - else { - - // target accessor is setter, so wrap the setter in setter map/ collection handling - result = new SetterWrapperForCollectionsAndMaps( - result, - method.getThrownTypes(), - targetType, - method.getMapperConfiguration().getNullValueCheckStrategy(), - ctx.getTypeFactory(), - targetWriteAccessorType == TargetWriteAccessorType.FIELD, - targetImmutable - ); - } - } - else { - if ( targetImmutable ) { - ctx.getMessager().printMessage( - method.getExecutable(), - Message.PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE, - targetPropertyName - ); - } - - // target accessor is getter, so wrap the setter in getter map/ collection handling - result = new GetterWrapperForCollectionsAndMaps( result, - method.getThrownTypes(), - targetType, - isFieldAssignment() - ); - } - - return result; + return new CollectionAssignmentBuilder() + .mappingBuilderContext( ctx ) + .method( method ) + .targetReadAccessor( targetReadAccessor ) + .targetType( targetType ) + .targetPropertyName( targetPropertyName ) + .targetAccessorType( targetAccessorType ) + .rightHandSide( rhs ) + .build(); } private Assignment assignToArray(Type targetType, Assignment rightHandSide) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java new file mode 100644 index 0000000000..b6b1aac7e4 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.assignment; + +import java.util.List; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; + +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; + +/** + * This wrapper handles the situation where an assignment is done for an update method. + * + * In case of a pre-existing target the wrapper checks if there is an collection or map initialized on the target bean + * (not null). If so it uses the addAll (for collections) or putAll (for maps). The collection / map is cleared in case + * of a pre-existing target {@link org.mapstruct.MappingTarget }before adding the source entries. + * + * If there is no pre-existing target, or the target Collection / Map is not initialized (null) the setter is used to + * create a new Collection / Map with the copy constructor. + * + * @author Sjaak Derksen + */ +public class ExistingInstanceSetterWrapperForCollectionsAndMaps + extends SetterWrapperForCollectionsAndMapsWithNullCheck { + + private final boolean includeSourceNullCheck; + + public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, + List thrownTypesToExclude, + Type targetType, + NullValueCheckStrategyPrism nvms, + TypeFactory typeFactory, + boolean fieldAssignment) { + + super( + decoratedAssignment, + thrownTypesToExclude, + targetType, + typeFactory, + fieldAssignment + ); + this.includeSourceNullCheck = ALWAYS == nvms; + } + + public boolean isIncludeSourceNullCheck() { + return includeSourceNullCheck; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index aac3842578..47dcae6e13 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -18,7 +18,9 @@ */ package org.mapstruct.ap.internal.model.assignment; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; @@ -56,4 +58,12 @@ public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, ); } + @Override + public Set getImportTypes() { + Set imported = new HashSet( super.getImportTypes() ); + if ( getSourcePresenceCheckerReference() == null ) { + imported.addAll( getNullCheckLocalVarType().getImportTypes() ); + } + return imported; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java index 76817d208e..ffcb387c6f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java @@ -18,44 +18,21 @@ */ package org.mapstruct.ap.internal.model.assignment; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; - -import java.util.EnumSet; import java.util.List; -import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; - -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; /** - * This wrapper handles the situation were an assignment is done via the setter. - * - * In case of a pre-existing target the wrapper checks if there is an collection or map initialized on the target bean - * (not null). If so it uses the addAll (for collections) or putAll (for maps). The collection / map is cleared in case - * of a pre-existing target {@link org.mapstruct.MappingTarget }before adding the source entries. - * - * If there is no pre-existing target, or the target Collection / Map is not initialized (null) the setter is used to - * create a new Collection / Map with the copy constructor. + * This wrapper handles the situation where an assignment is done via the setter, without doing anything special. * * @author Sjaak Derksen */ public class SetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAndMaps { - private final boolean includeSourceNullCheck; - private final Type targetType; - private final TypeFactory typeFactory; - private final boolean targetImmutable; - public SetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, - List thrownTypesToExclude, - Type targetType, - NullValueCheckStrategyPrism nvms, - TypeFactory typeFactory, - boolean fieldAssignment, - boolean targetImmutable ) { + List thrownTypesToExclude, + Type targetType, + boolean fieldAssignment) { super( decoratedAssignment, @@ -63,44 +40,5 @@ public SetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, targetType, fieldAssignment ); - this.includeSourceNullCheck = ALWAYS == nvms; - this.targetType = targetType; - this.typeFactory = typeFactory; - this.targetImmutable = targetImmutable; } - - @Override - public Set getImportTypes() { - Set imported = super.getImportTypes(); - if ( isDirectAssignment() ) { - if ( targetType.getImplementationType() != null ) { - imported.addAll( targetType.getImplementationType().getImportTypes() ); - } - else { - imported.addAll( targetType.getImportTypes() ); - } - - if ( isEnumSet() ) { - imported.add( typeFactory.getType( EnumSet.class ) ); - } - } - return imported; - } - - public boolean isIncludeSourceNullCheck() { - return includeSourceNullCheck; - } - - public boolean isDirectAssignment() { - return getType() == DIRECT; - } - - public boolean isEnumSet() { - return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); - } - - public boolean isTargetImmutable() { - return targetImmutable; - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java new file mode 100644 index 0000000000..dc6921fae3 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -0,0 +1,85 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.assignment; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; + +/** + * This wrapper handles the situation where an assignment is done via the setter and a null check is needed. + * This is needed when a direct assignment is used, or if the user has chosen the appropriate strategy + * + * @author Sjaak Derksen + */ +public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForCollectionsAndMaps { + + private final Type targetType; + private final TypeFactory typeFactory; + + public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssignment, + List thrownTypesToExclude, + Type targetType, + TypeFactory typeFactory, + boolean fieldAssignment) { + super( + decoratedAssignment, + thrownTypesToExclude, + targetType, + fieldAssignment + ); + this.targetType = targetType; + this.typeFactory = typeFactory; + } + + @Override + public Set getImportTypes() { + Set imported = new HashSet( super.getImportTypes() ); + if ( isDirectAssignment() ) { + if ( targetType.getImplementationType() != null ) { + imported.addAll( targetType.getImplementationType().getImportTypes() ); + } + else { + imported.addAll( targetType.getImportTypes() ); + } + + if ( isEnumSet() ) { + imported.add( typeFactory.getType( EnumSet.class ) ); + } + } + if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) { + imported.addAll( getNullCheckLocalVarType().getImportTypes() ); + } + return imported; + } + + public boolean isDirectAssignment() { + return getType() == DIRECT; + } + + public boolean isEnumSet() { + return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index f286a45f09..b28a7de99e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -19,9 +19,7 @@ package org.mapstruct.ap.internal.model.assignment; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; @@ -68,14 +66,6 @@ public List getThrownTypes() { return result; } - @Override - public Set getImportTypes() { - Set imported = new HashSet(); - imported.addAll( super.getImportTypes() ); - imported.addAll( nullCheckLocalVarType.getImportTypes() ); - return imported; - } - public String getNullCheckLocalVarName() { return nullCheckLocalVarName; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl new file mode 100644 index 0000000000..09b4bf4d19 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -0,0 +1,56 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<#import "../macro/CommonMacros.ftl" as lib> +<@lib.sourceLocalVarAssignment/> +<@lib.handleExceptions> + if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} != null ) { + <@lib.handleLocalVarNullCheck needs_explicit_local_var=false> + ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); + ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); + + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; + } + + } + else { + <@callTargetWriteAccessor/> + } + +<#-- + assigns the target via the regular target write accessor (usually the setter) +--> +<#macro callTargetWriteAccessor> + <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; + + +<#-- + wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) +--> +<#macro wrapLocalVarInCollectionInitializer><@compress single_line=true> + <#if enumSet> + EnumSet.copyOf( ${nullCheckLocalVarName} ) + <#else> + new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index 01dd1899b7..69f9fd6748 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -26,8 +26,8 @@ if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesi <#if ext.existingInstanceMapping> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.clear(); - <@lib.handleLocalVarNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); + <@lib.handleLocalVarNullCheck needs_explicit_local_var=false> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index a31bf3dae1..9d413fd4d5 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -22,39 +22,5 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> - <#if ext.existingInstanceMapping && !targetImmutable> - if ( ${ext.targetBeanName}.${ext.targetReadAccessorName} != null ) { - <@lib.handleLocalVarNullCheck> - ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); - ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); - - <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; - } - - } - else { - <@callTargetWriteAccessor/> - } - <#else> - <@callTargetWriteAccessor/> - - -<#-- - assigns the target via the regular target write accessor (usually the setter) ---> -<#macro callTargetWriteAccessor> - <@lib.handleLocalVarNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else>${nullCheckLocalVarName}; - - -<#-- - wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) ---> -<#macro wrapLocalVarInCollectionInitializer><@compress single_line=true> - <#if enumSet> - EnumSet.copyOf( ${nullCheckLocalVarName} ) - <#else> - new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) - - \ No newline at end of file + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl new file mode 100644 index 0000000000..ec934e1648 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -0,0 +1,48 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<#import "../macro/CommonMacros.ftl" as lib> +<@lib.sourceLocalVarAssignment/> +<@lib.handleExceptions> + <@callTargetWriteAccessor/> + <#if !ext.defaultValueAssignment??>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; + } + + +<#-- + assigns the target via the regular target write accessor (usually the setter) +--> +<#macro callTargetWriteAccessor> + <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; + + +<#-- + wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) +--> +<#macro wrapLocalVarInCollectionInitializer><@compress single_line=true> + <#if enumSet> + EnumSet.copyOf( ${nullCheckLocalVarName} ) + <#else> + new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>( ${nullCheckLocalVarName} ) + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 355c7bb735..094102039c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -62,11 +62,15 @@ requires: caller to implement String:getNullCheckLocalVarName() caller to implement Type:getNullCheckLocalVarType() --> -<#macro handleLocalVarNullCheck> +<#macro handleLocalVarNullCheck needs_explicit_local_var> <#if sourcePresenceCheckerReference??> if ( ${sourcePresenceCheckerReference} ) { - <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; - <#nested> + <#if needs_explicit_local_var> + <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; + <#nested> + <#else> + <#nested> + } <#else> <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; @@ -80,6 +84,13 @@ } +<#-- + Gives the value that needs to be assigned. If there is a sourcePresenceCheckerReference then a direct + lib.handleAssignment is done, otherwise nullCheckLocalVarName is used. + + requires: caller to implement String:getNullCheckLocalVarName() +--> +<#macro handleWithAssignmentOrNullCheckVar><#if sourcePresenceCheckerReference??><@lib.handleAssignment/><#else>${nullCheckLocalVarName} <#-- macro: handleExceptions diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java index 43bbdb4991..022a937c95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.bugs._913; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -26,9 +27,11 @@ * @author Sjaak Derksen */ public class Domain { + static final Set DEFAULT_STRINGS = new HashSet(); + static final Set DEFAULT_LONGS = new HashSet(); - private Set strings; - private Set longs; + private Set strings = DEFAULT_STRINGS; + private Set longs = DEFAULT_LONGS; private Set stringsInitialized; private Set longsInitialized; private List stringsWithDefault; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index dc2f15253c..87836abd38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -63,6 +63,10 @@ public class Issue913SetterMapperForCollectionsTest { * The null value mapping strategy on type level (Mapper) should generate forged methods for the * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. + * + * The generated code should not use a local variable for setting {@code longs}, but it should use a local + * variable for setting {@code strings} as a direct assignment and the copy constructor is used, in case the + * assignment is {@code null} then {@code null} should be set for {@code string} */ @Test public void shouldReturnNullForNvmsReturnNullForCreate() { @@ -173,6 +177,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { Dto dto = new Dto(); Domain domain = new Domain(); Set longIn = new HashSet(); + longIn.add( 10L ); domain.setLongs( longIn ); domain.setStrings( new HashSet() ); DomainDtoWithNvmsDefaultMapper.INSTANCE.update( dto, domain ); @@ -198,10 +203,13 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { Dto dto = new Dto(); Domain domain1 = new Domain(); Set longIn = new HashSet(); + longIn.add( 10L ); domain1.setLongs( longIn ); domain1.setStrings( new HashSet() ); + domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithNvmsDefaultMapper.INSTANCE.updateWithReturn( dto, domain1 ); + assertThat( domain2 ).isSameAs( domain1 ); doControlAsserts( domain1, domain2 ); assertThat( domain1.getLongs() ).isEqualTo( domain2.getLongs() ); assertThat( domain1.getStrings() ).isNull(); @@ -240,12 +248,14 @@ public void shouldReturnNullForUpdateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain = new Domain(); domain.setLongs( new HashSet() ); + domain.getLongs().add( 10L ); domain.setStrings( new HashSet() ); + domain.getStrings().add( "30" ); DomainDtoWithPresenceCheckMapper.INSTANCE.update( dto, domain ); doControlAsserts( domain ); - assertThat( domain.getStrings() ).isEmpty(); - assertThat( domain.getLongs() ).isEmpty(); + assertThat( domain.getStrings() ).containsExactly( "30" ); + assertThat( domain.getLongs() ).containsExactly( 10L ); } /** @@ -261,15 +271,18 @@ public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain1 = new Domain(); domain1.setLongs( new HashSet() ); + domain1.getLongs().add( 10L ); domain1.setStrings( new HashSet() ); + domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithPresenceCheckMapper.INSTANCE.updateWithReturn( dto, domain1 ); + assertThat( domain2 ).isSameAs( domain1 ); doControlAsserts( domain1, domain2 ); assertThat( domain1.getLongs() ).isEqualTo( domain2.getLongs() ); - assertThat( domain1.getStrings() ).isEmpty(); - assertThat( domain1.getLongs() ).isEmpty(); - assertThat( domain2.getStrings() ).isEmpty(); - assertThat( domain2.getLongs() ).isEmpty(); + assertThat( domain1.getStrings() ).containsExactly( "30" ); + assertThat( domain1.getLongs() ).containsExactly( 10L ); + assertThat( domain2.getStrings() ).containsExactly( "30" ); + assertThat( domain2.getLongs() ).containsExactly( 10L ); } /** @@ -301,12 +314,14 @@ public void shouldReturnNullForUpdateWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain = new Domain(); domain.setLongs( new HashSet() ); + domain.getLongs().add( 10L ); domain.setStrings( new HashSet() ); + domain.getStrings().add( "30" ); DomainDtoWithNcvsAlwaysMapper.INSTANCE.update( dto, domain ); doControlAsserts( domain ); - assertThat( domain.getStrings() ).isEmpty(); - assertThat( domain.getLongs() ).isEmpty(); + assertThat( domain.getStrings() ).containsExactly( "30" ); + assertThat( domain.getLongs() ).containsExactly( 10L ); } /** @@ -322,15 +337,18 @@ public void shouldReturnNullForUpdateWithReturnWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain1 = new Domain(); domain1.setLongs( new HashSet() ); + domain1.getLongs().add( 10L ); domain1.setStrings( new HashSet() ); + domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithNcvsAlwaysMapper.INSTANCE.updateWithReturn( dto, domain1 ); + assertThat( domain2 ).isSameAs( domain1 ); doControlAsserts( domain1, domain2 ); assertThat( domain1.getLongs() ).isEqualTo( domain2.getLongs() ); - assertThat( domain1.getStrings() ).isEmpty(); - assertThat( domain1.getLongs() ).isEmpty(); - assertThat( domain2.getStrings() ).isEmpty(); - assertThat( domain2.getLongs() ).isEmpty(); + assertThat( domain1.getStrings() ).containsExactly( "30" ); + assertThat( domain1.getLongs() ).containsExactly( 10L ); + assertThat( domain2.getStrings() ).containsExactly( "30" ); + assertThat( domain2.getLongs() ).containsExactly( 10L ); } /** diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index 46fb7e688b..bb1a5356d1 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:07:28+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-22T09:19:18+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithNcvsAlwaysMapperImpl implements DomainDtoWithNcvsAlwaysMapper { @@ -42,17 +42,24 @@ public Domain create(DtoWithPresenceCheck source) { Domain domain = new Domain(); if ( source.hasStringsInitialized() ) { - Set set = stringListToLongSet( source.getStringsInitialized() ); - domain.setLongsInitialized( set ); + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + else { + domain.setLongsInitialized( null ); } if ( source.hasStrings() ) { - Set set1 = stringListToLongSet( source.getStrings() ); - domain.setLongs( set1 ); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + } + else { + domain.setLongs( null ); } if ( source.hasStrings() ) { List list = source.getStrings(); domain.setStrings( new HashSet( list ) ); } + else { + domain.setStrings( null ); + } if ( source.hasStringsWithDefault() ) { List list1 = source.getStringsWithDefault(); domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -64,6 +71,9 @@ public Domain create(DtoWithPresenceCheck source) { List list2 = source.getStringsInitialized(); domain.setStringsInitialized( new HashSet( list2 ) ); } + else { + domain.setStringsInitialized( null ); + } return domain; } @@ -76,22 +86,19 @@ public void update(DtoWithPresenceCheck source, Domain target) { if ( target.getLongs() != null ) { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); target.getLongs().clear(); - target.getLongs().addAll( set ); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); } } else { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); - target.setLongs( set ); + target.setLongs( stringListToLongSet( source.getStrings() ) ); } } if ( target.getStrings() != null ) { if ( source.hasStrings() ) { - List list = source.getStrings(); target.getStrings().clear(); - target.getStrings().addAll( list ); + target.getStrings().addAll( source.getStrings() ); } } else { @@ -102,22 +109,19 @@ public void update(DtoWithPresenceCheck source, Domain target) { } if ( target.getLongsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); target.getLongsInitialized().clear(); - target.getLongsInitialized().addAll( set1 ); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); } } else { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); - target.setLongsInitialized( set1 ); + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } } if ( target.getStringsWithDefault() != null ) { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -134,9 +138,8 @@ public void update(DtoWithPresenceCheck source, Domain target) { } if ( target.getStringsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { @@ -155,22 +158,19 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { if ( target.getLongs() != null ) { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); target.getLongs().clear(); - target.getLongs().addAll( set ); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); } } else { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); - target.setLongs( set ); + target.setLongs( stringListToLongSet( source.getStrings() ) ); } } if ( target.getStrings() != null ) { if ( source.hasStrings() ) { - List list = source.getStrings(); target.getStrings().clear(); - target.getStrings().addAll( list ); + target.getStrings().addAll( source.getStrings() ); } } else { @@ -181,22 +181,19 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } if ( target.getLongsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); target.getLongsInitialized().clear(); - target.getLongsInitialized().addAll( set1 ); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); } } else { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); - target.setLongsInitialized( set1 ); + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } } if ( target.getStringsWithDefault() != null ) { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -213,9 +210,8 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } if ( target.getStringsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 4ba2c5e453..cad3066b54 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:07:27+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:02:48+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class DomainDtoWithNvmsDefaultMapperImpl implements DomainDtoWithNvmsDefaultMapper { @@ -39,18 +39,15 @@ public Domain create(Dto source) { Domain domain = new Domain(); if ( source != null ) { - Set set = stringListToLongSet( source.getStringsInitialized() ); - if ( set != null ) { - domain.setLongsInitialized( set ); - } - Set set1 = stringListToLongSet( source.getStrings() ); - if ( set1 != null ) { - domain.setLongs( set1 ); - } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list = source.getStrings(); if ( list != null ) { domain.setStrings( new HashSet( list ) ); } + else { + domain.setStrings( null ); + } List list1 = source.getStringsWithDefault(); if ( list1 != null ) { domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -62,6 +59,9 @@ public Domain create(Dto source) { if ( list2 != null ) { domain.setStringsInitialized( new HashSet( list2 ) ); } + else { + domain.setStringsInitialized( null ); + } } return domain; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index fa7f567091..e4683414bd 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:07:28+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:02:47+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class DomainDtoWithNvmsNullMapperImpl implements DomainDtoWithNvmsNullMapper { @@ -41,18 +41,15 @@ public Domain create(Dto source) { Domain domain = new Domain(); - Set set = stringListToLongSet( source.getStringsInitialized() ); - if ( set != null ) { - domain.setLongsInitialized( set ); - } - Set set1 = stringListToLongSet( source.getStrings() ); - if ( set1 != null ) { - domain.setLongs( set1 ); - } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list = source.getStrings(); if ( list != null ) { domain.setStrings( new HashSet( list ) ); } + else { + domain.setStrings( null ); + } List list1 = source.getStringsWithDefault(); if ( list1 != null ) { domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -64,6 +61,9 @@ public Domain create(Dto source) { if ( list2 != null ) { domain.setStringsInitialized( new HashSet( list2 ) ); } + else { + domain.setStringsInitialized( null ); + } return domain; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index a6f89f31c3..1b9bb3bbca 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:07:28+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-22T09:19:17+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithPresenceCheckMapperImpl implements DomainDtoWithPresenceCheckMapper { @@ -41,18 +41,15 @@ public Domain create(DtoWithPresenceCheck source) { Domain domain = new Domain(); - if ( source.hasStringsInitialized() ) { - Set set = stringListToLongSet( source.getStringsInitialized() ); - domain.setLongsInitialized( set ); - } - if ( source.hasStrings() ) { - Set set1 = stringListToLongSet( source.getStrings() ); - domain.setLongs( set1 ); - } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); if ( source.hasStrings() ) { List list = source.getStrings(); domain.setStrings( new HashSet( list ) ); } + else { + domain.setStrings( null ); + } if ( source.hasStringsWithDefault() ) { List list1 = source.getStringsWithDefault(); domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -64,6 +61,9 @@ public Domain create(DtoWithPresenceCheck source) { List list2 = source.getStringsInitialized(); domain.setStringsInitialized( new HashSet( list2 ) ); } + else { + domain.setStringsInitialized( null ); + } return domain; } @@ -76,22 +76,19 @@ public void update(DtoWithPresenceCheck source, Domain target) { if ( target.getLongs() != null ) { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); target.getLongs().clear(); - target.getLongs().addAll( set ); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); } } else { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); - target.setLongs( set ); + target.setLongs( stringListToLongSet( source.getStrings() ) ); } } if ( target.getStrings() != null ) { if ( source.hasStrings() ) { - List list = source.getStrings(); target.getStrings().clear(); - target.getStrings().addAll( list ); + target.getStrings().addAll( source.getStrings() ); } } else { @@ -102,22 +99,19 @@ public void update(DtoWithPresenceCheck source, Domain target) { } if ( target.getLongsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); target.getLongsInitialized().clear(); - target.getLongsInitialized().addAll( set1 ); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); } } else { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); - target.setLongsInitialized( set1 ); + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } } if ( target.getStringsWithDefault() != null ) { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -134,9 +128,8 @@ public void update(DtoWithPresenceCheck source, Domain target) { } if ( target.getStringsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { @@ -155,22 +148,19 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { if ( target.getLongs() != null ) { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); target.getLongs().clear(); - target.getLongs().addAll( set ); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); } } else { if ( source.hasStrings() ) { - Set set = stringListToLongSet( source.getStrings() ); - target.setLongs( set ); + target.setLongs( stringListToLongSet( source.getStrings() ) ); } } if ( target.getStrings() != null ) { if ( source.hasStrings() ) { - List list = source.getStrings(); target.getStrings().clear(); - target.getStrings().addAll( list ); + target.getStrings().addAll( source.getStrings() ); } } else { @@ -181,22 +171,19 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } if ( target.getLongsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); target.getLongsInitialized().clear(); - target.getLongsInitialized().addAll( set1 ); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); } } else { if ( source.hasStringsInitialized() ) { - Set set1 = stringListToLongSet( source.getStringsInitialized() ); - target.setLongsInitialized( set1 ); + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } } if ( target.getStringsWithDefault() != null ) { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); @@ -213,9 +200,8 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } if ( target.getStringsInitialized() != null ) { if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java index 7f6a8620fb..de1df9f68c 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.test.collection.adder; -import java.util.List; import javax.annotation.Generated; import org.mapstruct.ap.test.collection.adder._target.IndoorPet; import org.mapstruct.ap.test.collection.adder._target.Target; @@ -32,8 +31,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:10:39+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:05:40+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class SourceTargetMapperImpl implements SourceTargetMapper { @@ -71,10 +70,7 @@ public Source toSource(Target source) { Source source1 = new Source(); try { - List list = petMapper.toSourcePets( source.getPets() ); - if ( list != null ) { - source1.setPets( list ); - } + source1.setPets( petMapper.toSourcePets( source.getPets() ) ); } catch ( CatException e ) { throw new RuntimeException( e ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java index 73b7a78625..4cf29185e0 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java @@ -18,15 +18,14 @@ */ package org.mapstruct.ap.test.collection.adder; -import java.util.List; import javax.annotation.Generated; import org.mapstruct.ap.test.collection.adder._target.Target; import org.mapstruct.ap.test.collection.adder.source.Source; @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:10:39+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:05:40+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class SourceTargetMapperStrategyDefaultImpl implements SourceTargetMapperStrategyDefault { @@ -41,10 +40,7 @@ public Target shouldFallBackToAdder(Source source) throws DogException { Target target = new Target(); try { - List list = petMapper.toPets( source.getPets() ); - if ( list != null ) { - target.setPets( list ); - } + target.setPets( petMapper.toPets( source.getPets() ) ); } catch ( CatException e ) { throw new RuntimeException( e ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java index 9c27118005..b2616c8923 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-03-01T22:15:21+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:25:54+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class UserDtoMapperClassicImpl implements UserDtoMapperClassic { @@ -55,10 +55,7 @@ public CarDto carToCarDto(Car car) { carDto.setName( car.getName() ); carDto.setYear( car.getYear() ); - List list = mapWheels( car.getWheels() ); - if ( list != null ) { - carDto.setWheels( list ); - } + carDto.setWheels( mapWheels( car.getWheels() ) ); return carDto; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java index 65347a32b1..5f16703a43 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-03-01T22:15:23+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:25:54+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class UserDtoMapperSmartImpl implements UserDtoMapperSmart { @@ -95,10 +95,7 @@ protected CarDto carToCarDto(Car car) { carDto.setName( car.getName() ); carDto.setYear( car.getYear() ); - List list = wheelListToWheelDtoList( car.getWheels() ); - if ( list != null ) { - carDto.setWheels( list ); - } + carDto.setWheels( wheelListToWheelDtoList( car.getWheels() ) ); return carDto; } @@ -185,10 +182,7 @@ protected org.mapstruct.ap.test.nestedbeans.other.CarDto carToCarDto1(Car car) { carDto.setName( car.getName() ); carDto.setYear( car.getYear() ); - List list = wheelListToWheelDtoList1( car.getWheels() ); - if ( list != null ) { - carDto.setWheels( list ); - } + carDto.setWheels( wheelListToWheelDtoList1( car.getWheels() ) ); return carDto; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index 181bb89bea..acd8332331 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -29,8 +29,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-07T21:05:06+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-09T23:27:41+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" ) public class ChartEntryToArtistImpl extends ChartEntryToArtist { @@ -152,10 +152,7 @@ protected Song chartEntryToSong(ChartEntry chartEntry) { Song song = new Song(); song.setArtist( chartEntryToArtist( chartEntry ) ); - List list = mapPosition( chartEntry.getPosition() ); - if ( list != null ) { - song.setPositions( list ); - } + song.setPositions( mapPosition( chartEntry.getPosition() ) ); song.setTitle( chartEntry.getSongTitle() ); return song; From 15133d5a0fa3c5dabcea6696ce31848967a8f3f0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 May 2017 15:04:42 +0200 Subject: [PATCH 0095/1006] #777 Set initial capacity for new collection / map element in collection / map mappings --- .../model/ContainerMappingMethod.java | 12 + .../ap/internal/model/IterableCreation.java | 87 ++++++ .../ap/internal/model/MapMappingMethod.java | 12 + .../model/common/ImplementationType.java | 87 ++++++ .../ap/internal/model/common/Type.java | 8 +- .../ap/internal/model/common/TypeFactory.java | 46 +-- .../ap/internal/model/IterableCreation.ftl | 50 ++++ .../internal/model/IterableMappingMethod.ftl | 19 +- .../ap/internal/model/MapMappingMethod.ftl | 19 +- .../ap/internal/model/StreamMappingMethod.ftl | 17 +- .../DefaultCollectionImplementationTest.java | 6 + .../ap/test/array/ScienceMapperImpl.java | 6 +- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 4 +- .../DomainDtoWithNvmsDefaultMapperImpl.java | 6 +- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 6 +- .../DomainDtoWithPresenceCheckMapperImpl.java | 4 +- .../SourceTargetMapperImpl.java | 272 ++++++++++++++++++ .../nestedbeans/UserDtoMapperClassicImpl.java | 6 +- .../nestedbeans/UserDtoMapperSmartImpl.java | 8 +- .../UserDtoUpdateMapperSmartImpl.java | 6 +- .../updatemethods/CompanyMapper1Impl.java | 6 +- 21 files changed, 595 insertions(+), 92 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 8628ebe5b0..984753509c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -42,6 +42,7 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { private final SelectionParameters selectionParameters; private final String index1Name; private final String index2Name; + private IterableCreation iterableCreation; ContainerMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, @@ -67,6 +68,13 @@ public Parameter getSourceParameter() { throw new IllegalStateException( "Method " + this + " has no source parameter." ); } + public IterableCreation getIterableCreation() { + if ( iterableCreation == null ) { + iterableCreation = IterableCreation.create( this, getSourceParameter() ); + } + return iterableCreation; + } + public Assignment getElementAssignment() { return elementAssignment; } @@ -77,6 +85,10 @@ public Set getImportTypes() { if ( elementAssignment != null ) { types.addAll( elementAssignment.getImportTypes() ); } + + if ( iterableCreation != null ) { + types.addAll( iterableCreation.getImportTypes() ); + } return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java new file mode 100644 index 0000000000..e54cd98b8b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -0,0 +1,87 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.HashSet; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * Model element that can be used to create a type of {@link Iterable} or {@link java.util.Map}. If an implementation + * type is used and the target type has a constructor with {@link int} as parameter and the source parameter is of + * {@link java.util.Collection}, {@link java.util.Map} or {@code Array} type then MapStruct will use that constructor + * with the {@code size} / {@code length} from the source parameter. + * + * @author Filip Hrisafov + */ +public class IterableCreation extends ModelElement { + + private final Type resultType; + private final Parameter sourceParameter; + private final MethodReference factoryMethod; + private final boolean canUseSize; + private final boolean loadFactorAdjustment; + + private IterableCreation(Type resultType, Parameter sourceParameter, MethodReference factoryMethod) { + this.resultType = resultType; + this.sourceParameter = sourceParameter; + this.factoryMethod = factoryMethod; + this.canUseSize = ( sourceParameter.getType().isCollectionOrMapType() || + sourceParameter.getType().isArrayType() ) + && resultType.getImplementation() != null && resultType.getImplementation().hasInitialCapacityConstructor(); + this.loadFactorAdjustment = this.canUseSize && resultType.getImplementation().isLoadFactorAdjustment(); + + } + + public static IterableCreation create(NormalTypeMappingMethod mappingMethod, Parameter sourceParameter) { + return new IterableCreation( mappingMethod.getResultType(), sourceParameter, mappingMethod.getFactoryMethod() ); + } + + public Type getResultType() { + return resultType; + } + + public Parameter getSourceParameter() { + return sourceParameter; + } + + public MethodReference getFactoryMethod() { + return this.factoryMethod; + } + + public boolean isCanUseSize() { + return canUseSize; + } + + public boolean isLoadFactorAdjustment() { + return loadFactorAdjustment; + } + + @Override + public Set getImportTypes() { + Set types = new HashSet(); + if ( factoryMethod == null && resultType.getImplementationType() != null ) { + types.addAll( resultType.getImplementationType().getImportTypes() ); + } + return types; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index b94a18b37b..6b781a3cc7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -47,6 +47,7 @@ public class MapMappingMethod extends NormalTypeMappingMethod { private final Assignment keyAssignment; private final Assignment valueAssignment; + private IterableCreation iterableCreation; public static class Builder extends AbstractMappingMethodBuilder { @@ -268,6 +269,10 @@ public Set getImportTypes() { types.addAll( valueAssignment.getImportTypes() ); } + if ( iterableCreation != null ) { + types.addAll( iterableCreation.getImportTypes() ); + } + return types; } @@ -291,4 +296,11 @@ public String getEntryVariableName() { getParameterNames() ); } + + public IterableCreation getIterableCreation() { + if ( iterableCreation == null ) { + iterableCreation = IterableCreation.create( this, getSourceParameter() ); + } + return iterableCreation; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java new file mode 100644 index 0000000000..8ddb2356b1 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java @@ -0,0 +1,87 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.common; + +/** + * This is a wrapper class for the Implementation types that are used within MapStruct. It contains all the + * information needed for an Iterable creation + * + * @author Filip Hrisafov + */ +public class ImplementationType { + + private final Type type; + private final boolean initialCapacityConstructor; + private final boolean loadFactorAdjustment; + + private ImplementationType(Type type, boolean initialCapacityConstructor, boolean loadFactorAdjustment) { + this.type = type; + this.initialCapacityConstructor = initialCapacityConstructor; + this.loadFactorAdjustment = loadFactorAdjustment; + } + + public static ImplementationType withDefaultConstructor(Type type) { + return new ImplementationType( type, false, false ); + } + + public static ImplementationType withInitialCapacity(Type type) { + return new ImplementationType( type, true, false ); + } + + public static ImplementationType withLoadFactorAdjustment(Type type) { + return new ImplementationType( type, true, true ); + } + + /** + * Creates new {@link ImplementationType} that has the same {@link #initialCapacityConstructor} and + * {@link #loadFactorAdjustment}, but a different underlying {@link Type} + * + * @param type to be replaced + * + * @return a new implementation type with the given {@code type} + */ + public ImplementationType createNew(Type type) { + return new ImplementationType( type, initialCapacityConstructor, loadFactorAdjustment ); + } + + /** + * @return the underlying {@link Type} + */ + public Type getType() { + return type; + } + + /** + * @return {@code true} if the underlying type has a constructor for {@link int} {@code initialCapacity}, {@code + * false} otherwise + */ + public boolean hasInitialCapacityConstructor() { + return initialCapacityConstructor; + } + + /** + * If this method returns {@code true} then {@link #hasInitialCapacityConstructor()} also returns {@code true} + * + * @return {@code true} if the underlying type needs adjustment for the initial capacity constructor, {@code + * false} otherwise + */ + public boolean isLoadFactorAdjustment() { + return loadFactorAdjustment; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 3be8057233..cb089e6e71 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -70,7 +70,7 @@ public class Type extends ModelElement implements Comparable { private final TypeElement typeElement; private final List typeParameters; - private final Type implementationType; + private final ImplementationType implementationType; private final Type componentType; private final String packageName; @@ -103,7 +103,7 @@ public class Type extends ModelElement implements Comparable { //CHECKSTYLE:OFF public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, TypeMirror typeMirror, TypeElement typeElement, - List typeParameters, Type implementationType, Type componentType, + List typeParameters, ImplementationType implementationType, Type componentType, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported) { @@ -209,6 +209,10 @@ public List getEnumConstants() { * type, {@code null} otherwise. */ public Type getImplementationType() { + return implementationType != null ? implementationType.getType() : null; + } + + public ImplementationType getImplementation() { return implementationType; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 7001b6bfa8..b8a40333db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -61,6 +61,10 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; +import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity; +import static org.mapstruct.ap.internal.model.common.ImplementationType.withLoadFactorAdjustment; + /** * Factory creating {@link Type} instances. * @@ -77,7 +81,7 @@ public class TypeFactory { private final TypeMirror mapType; private final TypeMirror streamType; - private final Map implementationTypes = new HashMap(); + private final Map implementationTypes = new HashMap(); private final Map importedQualifiedTypesBySimpleName = new HashMap(); public TypeFactory(Elements elementUtils, Types typeUtils, RoundContext roundContext) { @@ -92,19 +96,25 @@ public TypeFactory(Elements elementUtils, Types typeUtils, RoundContext roundCon TypeElement streamTypeElement = elementUtils.getTypeElement( JavaStreamConstants.STREAM_FQN ); streamType = streamTypeElement == null ? null : typeUtils.erasure( streamTypeElement.asType() ); - implementationTypes.put( Iterable.class.getName(), getType( ArrayList.class ) ); - implementationTypes.put( Collection.class.getName(), getType( ArrayList.class ) ); - implementationTypes.put( List.class.getName(), getType( ArrayList.class ) ); + implementationTypes.put( Iterable.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); + implementationTypes.put( Collection.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); + implementationTypes.put( List.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); - implementationTypes.put( Set.class.getName(), getType( HashSet.class ) ); - implementationTypes.put( SortedSet.class.getName(), getType( TreeSet.class ) ); - implementationTypes.put( NavigableSet.class.getName(), getType( TreeSet.class ) ); + implementationTypes.put( Set.class.getName(), withLoadFactorAdjustment( getType( HashSet.class ) ) ); + implementationTypes.put( SortedSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); + implementationTypes.put( NavigableSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); - implementationTypes.put( Map.class.getName(), getType( HashMap.class ) ); - implementationTypes.put( SortedMap.class.getName(), getType( TreeMap.class ) ); - implementationTypes.put( NavigableMap.class.getName(), getType( TreeMap.class ) ); - implementationTypes.put( ConcurrentMap.class.getName(), getType( ConcurrentHashMap.class ) ); - implementationTypes.put( ConcurrentNavigableMap.class.getName(), getType( ConcurrentSkipListMap.class ) ); + implementationTypes.put( Map.class.getName(), withLoadFactorAdjustment( getType( HashMap.class ) ) ); + implementationTypes.put( SortedMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); + implementationTypes.put( NavigableMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); + implementationTypes.put( + ConcurrentMap.class.getName(), + withLoadFactorAdjustment( getType( ConcurrentHashMap.class ) ) + ); + implementationTypes.put( + ConcurrentNavigableMap.class.getName(), + withDefaultConstructor( getType( ConcurrentSkipListMap.class ) ) + ); } public Type getType(Class type) { @@ -151,7 +161,7 @@ public Type getType(TypeMirror mirror) { throw new TypeHierarchyErroneousException( mirror ); } - Type implementationType = getImplementationType( mirror ); + ImplementationType implementationType = getImplementationType( mirror ); boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); boolean isCollectionType = typeUtils.isSubtype( mirror, collectionType ); @@ -397,20 +407,21 @@ private TypeMirror getPrimitiveType(Class primitiveType) { typeUtils.getPrimitiveType( TypeKind.VOID ); } - private Type getImplementationType(TypeMirror mirror) { + private ImplementationType getImplementationType(TypeMirror mirror) { if ( mirror.getKind() != TypeKind.DECLARED ) { return null; } DeclaredType declaredType = (DeclaredType) mirror; - Type implementationType = implementationTypes.get( + ImplementationType implementation = implementationTypes.get( ( (TypeElement) declaredType.asElement() ).getQualifiedName() .toString() ); - if ( implementationType != null ) { - return new Type( + if ( implementation != null ) { + Type implementationType = implementation.getType(); + Type replacement = new Type( typeUtils, elementUtils, this, @@ -433,6 +444,7 @@ private Type getImplementationType(TypeMirror mirror) { implementationType.isStreamType(), isImported( implementationType.getName(), implementationType.getFullyQualifiedName() ) ); + return implementation.createNew( replacement ); } return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl new file mode 100644 index 0000000000..5c3f95c49c --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl @@ -0,0 +1,50 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableCreation" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<@compress single_line=true> + <#if factoryMethod??> + <@includeModel object=factoryMethod targetType=resultType/> + <#else> + new + <#if resultType.implementationType??> + <@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>() + <#else> + <@includeModel object=resultType/>() + + +<#macro sizeForCreation> + <@compress single_line=true> + <#if loadFactorAdjustment> + Math.max( (int) ( <@iterableSize/> / .75f ) + 1, 16 ) + <#else> + <@iterableSize/> + + + +<#macro iterableSize> + <@compress single_line=true> + <#if sourceParameter.type.arrayType> + ${sourceParameter.name}.length + <#else> + ${sourceParameter.name}.size() + + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index a06c5d9e56..3e404ede61 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -47,7 +47,7 @@ ${resultName}.clear(); return<#if returnType.name != "void"> ${resultName}; <#else> - return <@iterableCreation/>; + return <@includeModel object=iterableCreation useSizeIfPossible=false/>; @@ -63,7 +63,7 @@ ${resultName}.clear(); <#else> <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> - <@iterableLocalVarDef/> ${resultName} = <@iterableCreation/>; + <@iterableLocalVarDef/> ${resultName} = <@includeModel object=iterableCreation useSizeIfPossible=true/>; <#list beforeMappingReferencesWithMappingTarget as callback> @@ -124,17 +124,4 @@ <@includeModel object=resultType/> - -<#macro iterableCreation> - <@compress single_line=true> - <#if factoryMethod??> - <@includeModel object=factoryMethod targetType=resultType/> - <#else> - new - <#if resultType.implementationType??> - <@includeModel object=resultType.implementationType/> - <#else> - <@includeModel object=resultType/>() - - - + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 9acca2636d..ed6d903006 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -35,7 +35,7 @@ ${resultName}.clear(); return<#if returnType.name != "void"> ${resultName}; <#else> - return <@returnObjectCreation/>; + return <@includeModel object=iterableCreation useSizeIfPossible=false/>; } @@ -43,7 +43,7 @@ <#if existingInstanceMapping> ${resultName}.clear(); <#else> - <@includeModel object=resultType /> ${resultName} = <@returnObjectCreation/>; + <@includeModel object=resultType /> ${resultName} = <@includeModel object=iterableCreation useSizeIfPossible=true/>; <#list beforeMappingReferencesWithMappingTarget as callback> @@ -82,17 +82,4 @@ <#if exceptionType_has_next>, <#t> - -<#macro returnObjectCreation> - <@compress single_line=true> - <#if factoryMethod??> - <@includeModel object=factoryMethod targetType=resultType/> - <#else> - new - <#if resultType.implementationType??> - <@includeModel object=resultType.implementationType /> - <#else> - <@includeModel object=resultType />() - - - + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index eadfa67b50..f8877a02e5 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -48,7 +48,7 @@ ${resultName}.clear(); return<#if returnType.name != "void"> ${resultName}; <#else> - return <@iterableCreation/>; + return <@includeModel object=iterableCreation useSizeIfPossible=false/>; <#else> <#if existingInstanceMapping> @@ -76,7 +76,7 @@ <#elseif needVarDefine> <#assign needVarDefine = false /> <#-- Use the interface type on the left side, except it is java.lang.Iterable; use the implementation type - if present - on the right side --> - <@iterableLocalVarDef/> ${resultName} = <@iterableCreation/>; + <@iterableLocalVarDef/> ${resultName} = <@includeModel object=iterableCreation useSizeIfPossible=true/>; <#else> <#-- Streams are immutable so we can't update them --> @@ -177,19 +177,6 @@ -<#macro iterableCreation> - <@compress single_line=true> - <#if factoryMethod??> - <@includeModel object=factoryMethod targetType=resultType/> - <#else> - new - <#if resultType.implementationType??> - <@includeModel object=resultType.implementationType/> - <#else> - <@includeModel object=resultType/>() - - - <#macro iterableCollectionSupplier> <@compress single_line=true> <#if resultType.implementationType??> diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java index 3dba235cd0..ce6a0a245c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java @@ -36,11 +36,13 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; @WithClasses({ Source.class, @@ -52,6 +54,10 @@ @RunWith(AnnotationProcessorTestRunner.class) public class DefaultCollectionImplementationTest { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( SourceTargetMapper.class ); + @Test @IssueKey("6") public void shouldUseDefaultImplementationForConcurrentMap() { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java index 71db5a9da4..b2769fa890 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java @@ -28,8 +28,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-28T17:52:06+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-05-03T23:47:43+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class ScienceMapperImpl implements ScienceMapper { @@ -94,7 +94,7 @@ public List scientistsToDtosAsList(Scientist[] scientists) { return null; } - List list = new ArrayList(); + List list = new ArrayList( scientists.length ); for ( Scientist scientist : scientists ) { list.add( scientistToDto( scientist ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index bb1a5356d1..22427cba8b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -26,7 +26,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-22T09:19:18+0200", + date = "2017-05-06T00:06:20+0200", comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithNcvsAlwaysMapperImpl implements DomainDtoWithNcvsAlwaysMapper { @@ -229,7 +229,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet(); + Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index cad3066b54..241edfc2f0 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-09T23:02:48+0200", - comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" + date = "2017-05-06T00:06:21+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithNvmsDefaultMapperImpl implements DomainDtoWithNvmsDefaultMapper { @@ -254,7 +254,7 @@ protected Set stringListToLongSet(List list) { return new HashSet(); } - Set set = new HashSet(); + Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index e4683414bd..21cadd539e 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -26,8 +26,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-09T23:02:47+0200", - comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" + date = "2017-05-06T00:06:20+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithNvmsNullMapperImpl implements DomainDtoWithNvmsNullMapper { @@ -257,7 +257,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet(); + Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index 1b9bb3bbca..37dc9ceab3 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -26,7 +26,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-22T09:19:17+0200", + date = "2017-05-06T00:06:21+0200", comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class DomainDtoWithPresenceCheckMapperImpl implements DomainDtoWithPresenceCheckMapper { @@ -219,7 +219,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet(); + Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..7b39e52bc4 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java @@ -0,0 +1,272 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.collection.defaultimplementation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2017-05-06T00:20:29+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( target.getFooListNoSetter() != null ) { + List list = sourceFoosToTargetFoos( source.getFooList() ); + if ( list != null ) { + target.getFooListNoSetter().addAll( list ); + } + } + + return target; + } + + @Override + public TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo) { + if ( sourceFoo == null ) { + return null; + } + + TargetFoo targetFoo = new TargetFoo(); + + targetFoo.setName( sourceFoo.getName() ); + + return targetFoo; + } + + @Override + public List sourceFoosToTargetFoos(List foos) { + if ( foos == null ) { + return null; + } + + List list = new ArrayList( foos.size() ); + for ( SourceFoo sourceFoo : foos ) { + list.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return list; + } + + @Override + public Set sourceFoosToTargetFoos(Set foos) { + if ( foos == null ) { + return null; + } + + Set set = new HashSet( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + for ( SourceFoo sourceFoo : foos ) { + set.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return set; + } + + @Override + public Collection sourceFoosToTargetFoos(Collection foos) { + if ( foos == null ) { + return null; + } + + Collection collection = new ArrayList( foos.size() ); + for ( SourceFoo sourceFoo : foos ) { + collection.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return collection; + } + + @Override + public Iterable sourceFoosToTargetFoos(Iterable foos) { + if ( foos == null ) { + return null; + } + + ArrayList iterable = new ArrayList(); + for ( SourceFoo sourceFoo : foos ) { + iterable.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return iterable; + } + + @Override + public void sourceFoosToTargetFoosUsingTargetParameter(List targetFoos, Iterable sourceFoos) { + if ( sourceFoos == null ) { + return; + } + + targetFoos.clear(); + for ( SourceFoo sourceFoo : sourceFoos ) { + targetFoos.add( sourceFooToTargetFoo( sourceFoo ) ); + } + } + + @Override + public Iterable sourceFoosToTargetFoosUsingTargetParameterAndReturn(Iterable sourceFoos, List targetFoos) { + if ( sourceFoos == null ) { + return null; + } + + targetFoos.clear(); + for ( SourceFoo sourceFoo : sourceFoos ) { + targetFoos.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return targetFoos; + } + + @Override + public SortedSet sourceFoosToTargetFooSortedSet(Collection foos) { + if ( foos == null ) { + return null; + } + + SortedSet sortedSet = new TreeSet(); + for ( SourceFoo sourceFoo : foos ) { + sortedSet.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return sortedSet; + } + + @Override + public NavigableSet sourceFoosToTargetFooNavigableSet(Collection foos) { + if ( foos == null ) { + return null; + } + + NavigableSet navigableSet = new TreeSet(); + for ( SourceFoo sourceFoo : foos ) { + navigableSet.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return navigableSet; + } + + @Override + public Map sourceFooMapToTargetFooMap(Map foos) { + if ( foos == null ) { + return null; + } + + Map map = new HashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public SortedMap sourceFooMapToTargetFooSortedMap(Map foos) { + if ( foos == null ) { + return null; + } + + SortedMap sortedMap = new TreeMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + sortedMap.put( key, value ); + } + + return sortedMap; + } + + @Override + public NavigableMap sourceFooMapToTargetFooNavigableMap(Map foos) { + if ( foos == null ) { + return null; + } + + NavigableMap navigableMap = new TreeMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + navigableMap.put( key, value ); + } + + return navigableMap; + } + + @Override + public ConcurrentMap sourceFooMapToTargetFooConcurrentMap(Map foos) { + if ( foos == null ) { + return null; + } + + ConcurrentMap concurrentMap = new ConcurrentHashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + concurrentMap.put( key, value ); + } + + return concurrentMap; + } + + @Override + public ConcurrentNavigableMap sourceFooMapToTargetFooConcurrentNavigableMap(Map foos) { + if ( foos == null ) { + return null; + } + + ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + concurrentNavigableMap.put( key, value ); + } + + return concurrentNavigableMap; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java index b2616c8923..00517eb4a8 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-09T23:25:54+0200", - comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" + date = "2017-05-04T00:00:46+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class UserDtoMapperClassicImpl implements UserDtoMapperClassic { @@ -95,7 +95,7 @@ public List mapWheels(List wheels) { return null; } - List list = new ArrayList(); + List list = new ArrayList( wheels.size() ); for ( Wheel wheel : wheels ) { list.add( mapWheel( wheel ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java index 5f16703a43..12bcc738e7 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-04-09T23:25:54+0200", - comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" + date = "2017-05-04T00:00:47+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class UserDtoMapperSmartImpl implements UserDtoMapperSmart { @@ -78,7 +78,7 @@ protected List wheelListToWheelDtoList(List list) { return null; } - List list1 = new ArrayList(); + List list1 = new ArrayList( list.size() ); for ( Wheel wheel : list ) { list1.add( wheelToWheelDto( wheel ) ); } @@ -165,7 +165,7 @@ protected List wheelListToWhee return null; } - List list1 = new ArrayList(); + List list1 = new ArrayList( list.size() ); for ( Wheel wheel : list ) { list1.add( wheelToWheelDto1( wheel ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java index c24ec17072..28594ec1a3 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-03-01T22:15:22+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-05-04T00:00:45+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class UserDtoUpdateMapperSmartImpl implements UserDtoUpdateMapperSmart { @@ -85,7 +85,7 @@ protected List wheelListToWheelDtoList(List list) { return null; } - List list1 = new ArrayList(); + List list1 = new ArrayList( list.size() ); for ( Wheel wheel : list ) { list1.add( wheelToWheelDto( wheel ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java index d1f212f5da..352b0a10e9 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java @@ -24,8 +24,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-03-13T22:32:15+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_121 (Oracle Corporation)" + date = "2017-05-06T00:11:06+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class CompanyMapper1Impl implements CompanyMapper1 { @@ -96,7 +96,7 @@ protected Map secretaryDtoEmployeeDtoMapToSecre return null; } - Map map1 = new HashMap(); + Map map1 = new HashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : map.entrySet() ) { SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() ); From aa6cda117701c41ca0697f4872f4631808ec6e4d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 May 2017 15:15:16 +0200 Subject: [PATCH 0096/1006] Use anchors for the sections and add Filip to the authors --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index c70b53a672..765f6a4be3 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1,7 +1,8 @@ = MapStruct {mapstructVersion} Reference Guide :revdate: {docdate} :toc: right -:Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen and the MapStruct community +:sectanchors: +:Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen, Filip Hrisafov and the MapStruct community [[Preface]] == Preface From 459354b6b81ef8f98eaa4a7a8894354e09c6a3c1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 May 2017 23:26:51 +0200 Subject: [PATCH 0097/1006] #1153 Do not use invalid TargetReferences when creating nested target mappings * Move the error generation for the invalid TargetReference into the BuilderFromTargetMapping * TargetReference will strip the first entry name in the following cases only if the first entry name matches the MappingTarget parameter, or for reverse mappings it matches the source parameter name * Pass the reverse source parameter when initializing a reverse mapping --- .../ap/internal/model/BeanMappingMethod.java | 37 +--- .../NestedTargetPropertyMappingHolder.java | 34 +++- .../ap/internal/model/source/Mapping.java | 25 ++- .../internal/model/source/SourceMethod.java | 2 +- .../model/source/TargetReference.java | 171 +++++++++++++++--- .../bugs/_1153/ErroneousIssue1153Mapper.java | 99 ++++++++++ .../ap/test/bugs/_1153/Issue1153Test.java | 56 ++++++ 7 files changed, 358 insertions(+), 66 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 39e942965c..4e9acc991f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -322,7 +322,7 @@ private boolean handleDefinedMappings() { // first we have to handle nested target mappings if ( method.getMappingOptions().hasNestedTargetReferences() ) { - handleDefinedNestedTargetMapping( handledTargets ); + errorOccurred = handleDefinedNestedTargetMapping( handledTargets ); } for ( Map.Entry> entry : methodMappings.entrySet() ) { @@ -335,7 +335,7 @@ private boolean handleDefinedMappings() { } } } - else if ( reportErrorOnTargetObject( mapping ) ) { + else { errorOccurred = true; } } @@ -350,7 +350,7 @@ else if ( reportErrorOnTargetObject( mapping ) ) { return errorOccurred; } - private void handleDefinedNestedTargetMapping(Set handledTargets) { + private boolean handleDefinedNestedTargetMapping(Set handledTargets) { NestedTargetPropertyMappingHolder holder = new NestedTargetPropertyMappingHolder.Builder() .mappingContext( ctx ) @@ -368,6 +368,7 @@ private void handleDefinedNestedTargetMapping(Set handledTargets) { } unprocessedDefinedTargets.put( entry.getKey().getName(), entry.getValue() ); } + return holder.hasErrorOccurred(); } private boolean handleDefinedMapping(Mapping mapping, Set handledTargets) { @@ -474,36 +475,6 @@ else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.cont return errorOccured; } - private boolean reportErrorOnTargetObject(Mapping mapping) { - - boolean errorOccurred = false; - - boolean hasReadAccessor - = method.getResultType().getPropertyReadAccessors().containsKey( mapping.getTargetName() ); - - if ( hasReadAccessor ) { - if ( !mapping.isIgnored() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, - mapping.getTargetName() ); - errorOccurred = true; - } - } - else { - ctx.getMessager().printMessage( - method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), - Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, - mapping.getTargetName() ); - errorOccurred = true; - } - return errorOccurred; - } - /** * Iterates over all target properties and all source parameters. *

    diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 744112338e..e6bb66274d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.model.source.TargetReference; import org.mapstruct.ap.internal.util.Extractor; import static org.mapstruct.ap.internal.util.Collections.first; @@ -63,15 +64,17 @@ public PropertyEntry apply(SourceReference sourceReference) { private final Set handledTargets; private final List propertyMappings; private final Map> unprocessedDefinedTarget; + private final boolean errorOccurred; public NestedTargetPropertyMappingHolder( List processedSourceParameters, Set handledTargets, List propertyMappings, - Map> unprocessedDefinedTarget) { + Map> unprocessedDefinedTarget, boolean errorOccurred) { this.processedSourceParameters = processedSourceParameters; this.handledTargets = handledTargets; this.propertyMappings = propertyMappings; this.unprocessedDefinedTarget = unprocessedDefinedTarget; + this.errorOccurred = errorOccurred; } /** @@ -102,6 +105,13 @@ public Map> getUnprocessedDefinedTarget() { return unprocessedDefinedTarget; } + /** + * @return {@code true} if an error occurred during the creation of the nested mappings + */ + public boolean hasErrorOccurred() { + return errorOccurred; + } + public static class Builder { private Method method; @@ -227,7 +237,8 @@ public NestedTargetPropertyMappingHolder build() { processedSourceParameters, handledTargets, propertyMappings, - unprocessedDefinedTarget + unprocessedDefinedTarget, + groupedByTP.errorOccurred ); } @@ -284,9 +295,16 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp = new LinkedHashMap>(); Map> singleTargetReferences = new LinkedHashMap>(); + boolean errorOccurred = false; for ( List mapping : mappings.values() ) { - PropertyEntry property = first( first( mapping ).getTargetReference().getPropertyEntries() ); - Mapping newMapping = first( mapping ).popTargetReference(); + Mapping firstMapping = first( mapping ); + TargetReference targetReference = firstMapping.getTargetReference(); + if ( !targetReference.isValid() ) { + errorOccurred = true; + continue; + } + PropertyEntry property = first( targetReference.getPropertyEntries() ); + Mapping newMapping = firstMapping.popTargetReference(); if ( newMapping != null ) { // group properties on current name. if ( !mappingsKeyedByProperty.containsKey( property ) ) { @@ -298,11 +316,11 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp if ( !singleTargetReferences.containsKey( property ) ) { singleTargetReferences.put( property, new ArrayList() ); } - singleTargetReferences.get( property ).add( first( mapping ) ); + singleTargetReferences.get( property ).add( firstMapping ); } } - return new GroupedTargetReferences( mappingsKeyedByProperty, singleTargetReferences ); + return new GroupedTargetReferences( mappingsKeyedByProperty, singleTargetReferences, errorOccurred ); } /** @@ -576,11 +594,13 @@ private GroupedBySourceParameters(Map> groupedBySourceP private static class GroupedTargetReferences { private final Map> poppedTargetReferences; private final Map> singleTargetReferences; + private final boolean errorOccurred; private GroupedTargetReferences(Map> poppedTargetReferences, - Map> singleTargetReferences) { + Map> singleTargetReferences, boolean errorOccurred) { this.poppedTargetReferences = poppedTargetReferences; this.singleTargetReferences = singleTargetReferences; + this.errorOccurred = errorOccurred; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index c225adc138..61d1358b56 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -252,7 +252,21 @@ private static boolean isEnumType(TypeMirror mirror) { ( (DeclaredType) mirror ).asElement().getKind() == ElementKind.ENUM; } - public void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, boolean isReverse) { + public void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory) { + init( method, messager, typeFactory, false, null ); + } + + /** + * Initialize the Mapping. + * + * @param method the source method that the mapping belongs to + * @param messager the messager that can be used for outputting messages + * @param typeFactory the type factory + * @param isReverse whether the init is for a reverse mapping + * @param reverseSourceParameter the source parameter from the revers mapping + */ + private void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, boolean isReverse, + Parameter reverseSourceParameter) { if ( !method.isEnumMapping() ) { sourceReference = new SourceReference.BuilderFromMapping() @@ -268,6 +282,7 @@ public void init(SourceMethod method, FormattingMessager messager, TypeFactory t .method( method ) .messager( messager ) .typeFactory( typeFactory ) + .reverseSourceParameter( reverseSourceParameter ) .build(); } } @@ -408,7 +423,13 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac Collections.emptyList() ); - reverse.init( method, messager, typeFactory, true ); + reverse.init( + method, + messager, + typeFactory, + true, + sourceReference != null ? sourceReference.getParameter() : null + ); return reverse; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 3c7142395b..73ebc0825c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -200,7 +200,7 @@ public SourceMethod build() { if ( mappings != null ) { for ( Map.Entry> entry : mappings.entrySet() ) { for ( Mapping mapping : entry.getValue() ) { - mapping.init( sourceMethod, messager, typeFactory, false ); + mapping.init( sourceMethod, messager, typeFactory ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 00487d23e6..fc2aaab9d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -72,6 +72,30 @@ public static class BuilderFromTargetMapping { private SourceMethod method; private FormattingMessager messager; private TypeFactory typeFactory; + private boolean isReverse; + /** + * Needed when we are building from reverse mapping. It is needed, so we can remove the first level if it is + * needed. + * E.g. If we have a mapping like: + * + * {@literal @}Mapping( target = "letterSignature", source = "dto.signature" ) + * + * + * When it is reversed it will look like: + * + * {@literal @}Mapping( target = "dto.signature", source = "letterSignature" ) + * + * + * The {@code dto} needs to be considered as a possibility for a target name only if a Target Reference for + * a reverse is created. + */ + private Parameter reverseSourceParameter; + /** + * During {@link #getTargetEntries(Type, String[])} an error can occur. However, we are invoking + * that multiple times because the first entry can also be the name of the parameter. Therefore we keep + * the error message until the end when we can report it. + */ + private Message errorMessage; public BuilderFromTargetMapping messager(FormattingMessager messager) { this.messager = messager; @@ -94,6 +118,12 @@ public BuilderFromTargetMapping typeFactory(TypeFactory typeFactory) { } public BuilderFromTargetMapping isReverse(boolean isReverse) { + this.isReverse = isReverse; + return this; + } + + public BuilderFromTargetMapping reverseSourceParameter(Parameter reverseSourceParameter) { + this.reverseSourceParameter = reverseSourceParameter; return this; } @@ -112,20 +142,28 @@ public TargetReference build() { boolean foundEntryMatch; Type resultType = method.getResultType(); - // there can be 3 situations + // there can be 4 situations // 1. Return type - // 2. @MappingTarget, with - // 3. or without parameter name. + // 2. A reverse target reference where the source parameter name is used in the original mapping + // 3. @MappingTarget, with + // 4. or without parameter name. String[] targetPropertyNames = segments; List entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); - if ( !foundEntryMatch && segments.length > 1 ) { + if ( !foundEntryMatch && segments.length > 1 + && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParameter, isReverse ) ) { targetPropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); } - // foundEntryMatch = isValid, errors are handled in the BeanMapping, where the error context is known + if ( !foundEntryMatch && errorMessage != null) { + // This is called only for reporting errors + reportMappingError( errorMessage, mapping.getTargetName() ); + } + + // foundEntryMatch = isValid, errors are handled here, and the BeanMapping uses that to ignore + // the creation of mapping for invalid TargetReferences return new TargetReference( parameter, entries, foundEntryMatch ); } @@ -142,46 +180,133 @@ private List getTargetEntries(Type type, String[] entryNames) { Accessor targetReadAccessor = nextType.getPropertyReadAccessors().get( entryNames[i] ); Accessor targetWriteAccessor = nextType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); - if ( targetWriteAccessor == null || ( i < entryNames.length - 1 && targetReadAccessor == null) ) { - // there should always be a write accessor and there should be read accessor mandatory for all - // but the last - // TODO error handling when full fledged target mapping is in place. + boolean isLast = i == entryNames.length - 1; + boolean isNotLast = i < entryNames.length - 1; + if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast ) + || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, mapping, isLast ) + || ( isNotLast && targetReadAccessor == null ) ) { + // there should always be a write accessor (except for the last when the mapping is ignored and + // there is a read accessor) and there should be read accessor mandatory for all but the last + setErrorMessage( targetWriteAccessor, targetReadAccessor ); break; } - if ( ( i == entryNames.length - 1 ) || ( Executables.isSetterMethod( targetWriteAccessor ) + if ( isLast || ( Executables.isSetterMethod( targetWriteAccessor ) || Executables.isFieldAccessor( targetWriteAccessor ) ) ) { // only intermediate nested properties when they are a true setter or field accessor // the last may be other readAccessor (setter / getter / adder). - if ( Executables.isGetterMethod( targetWriteAccessor ) || - Executables.isFieldAccessor( targetWriteAccessor ) ) { - nextType = typeFactory.getReturnType( - (DeclaredType) nextType.getTypeMirror(), - targetWriteAccessor ); - } - else { - nextType = typeFactory.getSingleParameter( - (DeclaredType) nextType.getTypeMirror(), - targetWriteAccessor ).getType(); - } + nextType = findNextType( nextType, targetWriteAccessor, targetReadAccessor ); // check if an entry alread exists, otherwise create String[] fullName = Arrays.copyOfRange( entryNames, 0, i + 1 ); PropertyEntry propertyEntry = PropertyEntry.forTargetReference( fullName, targetReadAccessor, targetWriteAccessor, nextType ); targetEntries.add( propertyEntry ); - } - } + } + return targetEntries; } + /** + * Finds the next type based on the initial type. + * + * @param initial for which a next type should be found + * @param targetWriteAccessor the write accessor + * @param targetReadAccessor the read accessor + * @return the next type that should be used for finding a property entry + */ + private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor targetReadAccessor) { + Type nextType; + Accessor toUse = targetWriteAccessor != null ? targetWriteAccessor : targetReadAccessor; + if ( Executables.isGetterMethod( toUse ) || + Executables.isFieldAccessor( toUse ) ) { + nextType = typeFactory.getReturnType( + (DeclaredType) initial.getTypeMirror(), + toUse + ); + } + else { + nextType = typeFactory.getSingleParameter( + (DeclaredType) initial.getTypeMirror(), + toUse + ).getType(); + } + return nextType; + } + + private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAccessor) { + if ( targetWriteAccessor == null && targetReadAccessor == null ) { + errorMessage = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; + } + else if ( targetWriteAccessor == null ) { + errorMessage = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE; + } + } + private void reportMappingError(Message msg, Object... objects) { messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), msg, objects ); } + + /** + * A write accessor is not valid if it is {@code null} and it is not last. i.e. for nested target mappings + * there must be a write accessor for all entries except the last one. + * + * @param accessor that needs to be checked + * @param isNotLast whether or not this is the last write accessor in the entry chain + * + * @return {@code true} if the accessor is not valid, {@code false} otherwise + */ + private static boolean isWriteAccessorNotValidWhenNotLast(Accessor accessor, boolean isNotLast) { + return accessor == null && isNotLast; + } + + /** + * For a last accessor to be valid, a read accessor should exist and the mapping should be ignored. All other + * cases represent an invalid write accessor. This method will evaluate to {@code true} if the following is + * {@code true}: + *

      + *
    • {@code writeAccessor} is {@code null}
    • + *
    • It is for the last entry
    • + *
    • A read accessor does not exist, or the mapping is not ignored
    • + *
    + * + * @param writeAccessor that needs to be checked + * @param readAccessor that is used + * @param mapping that is used + * @param isLast whether or not this is the last write accessor in the entry chain + * + * @return {@code true} if the write accessor is not valid, {@code false} otherwise. See description for more + * information + */ + private static boolean isWriteAccessorNotValidWhenLast(Accessor writeAccessor, Accessor readAccessor, + Mapping mapping, boolean isLast) { + return writeAccessor == null && isLast && ( readAccessor == null || !mapping.isIgnored() ); + } + + /** + * Validates that the {@code segment} is the same as the {@code targetParameter} or the {@code + * reverseSourceParameter} names + * + * @param segment that needs to be checked + * @param targetParameter the target parameter if it exists + * @param reverseSourceParameter the reverse source parameter if it exists + * @param isReverse whether a reverse {@link TargetReference} is being built + * + * @return {@code true} if the segment matches the name of the {@code targetParameter} or the name of the + * {@code reverseSourceParameter} when this is a reverse {@link TargetReference} is being built, {@code + * false} otherwise + */ + private static boolean matchesSourceOrTargetParameter(String segment, Parameter targetParameter, + Parameter reverseSourceParameter, boolean isReverse) { + boolean matchesTargetParameter = + targetParameter != null && targetParameter.getName().equals( segment ); + return matchesTargetParameter + || isReverse && reverseSourceParameter != null && reverseSourceParameter.getName().equals( segment ); + } } private TargetReference(Parameter sourceParameter, List sourcePropertyEntries, boolean isValid) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java new file mode 100644 index 0000000000..67f87bcf9f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java @@ -0,0 +1,99 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1153; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousIssue1153Mapper { + + @Mappings( { + @Mapping( target = "readOnly", source = "nonNested"), + @Mapping( target = "nestedTarget.readOnly", source = "nestedSource.nested"), + @Mapping( target = "nestedTarget.writable", source = "nestedSource.writable"), + @Mapping( target = "nestedTarget2.readOnly", ignore = true), + @Mapping( target = "nestedTarget2.writable2", source = "nestedSource.writable"), + } ) + Target map(Source source); + + class Source { + + public static class NestedSource { + //CHECKSTYLE:OFF + public String nested; + public String writable; + //CHECKSTYLE:ON + } + + //CHECKSTYLE:OFF + public String nonNested; + public NestedSource nestedSource; + public NestedSource nestedSource2; + //CHECKSTYLE:ON + } + + class Target { + + public static class NestedTarget { + private String readOnly; + private String writable; + + public String getReadOnly() { + return readOnly; + } + + public String getWritable() { + return writable; + } + + public void setWritable(String writable) { + this.writable = writable; + } + } + + private String readOnly; + private NestedTarget nestedTarget; + private NestedTarget nestedTarget2; + + public String getReadOnly() { + return readOnly; + } + + public NestedTarget getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(NestedTarget nestedTarget) { + this.nestedTarget = nestedTarget; + } + + public NestedTarget getNestedTarget2() { + return nestedTarget2; + } + + public void setNestedTarget2(NestedTarget nestedTarget2) { + this.nestedTarget2 = nestedTarget2; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java new file mode 100644 index 0000000000..7ddbcd4276 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1153; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(ErroneousIssue1153Mapper.class) +@IssueKey("1153") +public class Issue1153Test { + + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIssue1153Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = "Property \"readOnly\" has no write accessor\\."), + @Diagnostic(type = ErroneousIssue1153Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 33, + messageRegExp = "Property \"nestedTarget.readOnly\" has no write accessor\\."), + @Diagnostic(type = ErroneousIssue1153Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 36, + messageRegExp = "Unknown property \"nestedTarget2.writable2\" in return type\\.") + }) + @Test + public void shouldReportErrorsCorrectly() { + } +} From 7cf77f4c264a8c7513a04e298e01b036e9e4315d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 17 May 2017 22:34:23 +0200 Subject: [PATCH 0098/1006] #1154 Add SPI for excluding types/elements from automatic sub-mapping generation Default implementation of SPI ignores types in the java/javax packages --- .../mapstruct-reference-guide.asciidoc | 61 ++++++++++++++++- .../internal/model/AbstractBaseBuilder.java | 28 ++++++-- .../model/AbstractMappingMethodBuilder.java | 2 +- .../model/ContainerMappingMethodBuilder.java | 2 +- .../DefaultMappingExclusionProvider.java | 49 ++++++++++++++ .../ap/internal/model/MapMappingMethod.java | 4 +- .../internal/model/MappingBuilderContext.java | 28 +++++++- .../ap/internal/model/PropertyMapping.java | 37 ++++++++--- .../ap/spi/MappingExclusionProvider.java | 66 +++++++++++++++++++ .../org/mapstruct/ap/test/NoProperties.java | 25 +++++++ .../org/mapstruct/ap/test/WithProperties.java | 35 ++++++++++ .../ErroneousCollectionMappingTest.java | 30 +++++---- ...oneousCollectionNoElementMappingFound.java | 5 +- .../ErroneousCollectionNoKeyMappingFound.java | 5 +- ...rroneousCollectionNoValueMappingFound.java | 5 +- ...eousListToStreamNoElementMappingFound.java | 5 +- .../erroneous/ErroneousStreamMappingTest.java | 29 ++++---- ...eousStreamToListNoElementMappingFound.java | 5 +- ...usStreamToStreamNoElementMappingFound.java | 5 +- .../ErroneousJavaInternalMapper.java | 30 +++++++++ .../exclusions/ErroneousJavaInternalTest.java | 65 ++++++++++++++++++ .../test/nestedbeans/exclusions/Source.java | 54 +++++++++++++++ .../test/nestedbeans/exclusions/Target.java | 48 ++++++++++++++ .../CustomMappingExclusionProvider.java | 47 +++++++++++++ .../ErroneousCustomExclusionMapper.java | 32 +++++++++ .../custom/ErroneousCustomExclusionTest.java | 57 ++++++++++++++++ .../nestedbeans/exclusions/custom/Source.java | 55 ++++++++++++++++ .../nestedbeans/exclusions/custom/Target.java | 55 ++++++++++++++++ .../selection/generics/ConversionTest.java | 14 ++-- .../selection/generics/ErroneousSource6.java | 8 ++- 30 files changed, 826 insertions(+), 65 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/NoProperties.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/WithProperties.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 765f6a4be3..68f95a4df2 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -3,6 +3,8 @@ :toc: right :sectanchors: :Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen, Filip Hrisafov and the MapStruct community +:processor-dir: ../../../../processor +:processor-ap-test: {processor-dir}/src/test/java/org/mapstruct/ap/test [[Preface]] == Preface @@ -815,7 +817,7 @@ When generating the implementation of a mapping method, MapStruct will apply the * If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. * If source and target attribute type differ, check whether there is a another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. * If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. -* If no such method was found MapStruct will try to generate an internal method that will do the mapping between the source and target attributes +* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes * If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. include::controlling-nested-bean-mappings.asciidoc[] @@ -2458,9 +2460,64 @@ public class CustomAccessorNamingStrategy extends DefaultAccessorNamingStrategy ==== The `CustomAccessorNamingStrategy` makes use of the `DefaultAccessorNamingStrategy` (also available in mapstruct-processor) and relies on that class to leave most of the default behaviour unchanged. -To use a custom SPI implementation, it must be located in a seperate .jar file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This .jar file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). +To use a custom SPI implementation, it must be located in a separate JAR file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). [TIP] Fore more details: There's the above example is present in our our examples repository (https://github.com/mapstruct/mapstruct-examples). +[mapping-exclusion-provider] +=== Mapping Exclusion Provider +MapStruct offers the possibility to override the `MappingExclusionProvider` via the Service Provider Interface (SPI). +A nice example is to not allow MapStruct to create an automatic sub-mapping for a certain type, +i.e. MapStruct will not try to generate an automatic sub-mapping method for an excluded type. + +[NOTE] +==== +The `DefaultMappingExclusionProvider` will exclude all types under the `java` or `javax` packages. +This means that MapStruct will not try to generate an automatic sub-mapping method between some custom type and some type declared in the Java class library. +==== + +.Source object +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/Source.java[tag=documentation] +---- +==== + +.Target object +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/Target.java[tag=documentation] +---- +==== + +.Mapper definition +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java[tag=documentation] +---- +==== + +We want to exclude the `NestedTarget` from the automatic sub-mapping method generation. + +.CustomMappingExclusionProvider +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java[tag=documentation] +---- +==== + +To use a custom SPI implementation, it must be located in a separate JAR file +together with the file `META-INF/services/org.mapstruct.ap.spi.MappingExclusionProvider` with the fully qualified name of your custom implementation as content +(e.g. `org.mapstruct.example.CustomMappingExclusionProvider`). +This JAR file needs to be added to the annotation processor classpath +(i.e. add it next to the place where you added the mapstruct-processor jar). diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 8f11684abd..55b0885b71 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -50,7 +50,27 @@ public B method(Method sourceMethod) { return myself; } - boolean isDisableSubMappingMethodsGeneration() { + /** + * Checks if MapStruct is allowed to generate an automatic sub-mapping between {@code sourceType} and @{code + * targetType}. + * This will evaluate to {@code true}, when: + *
  • + *
      Automatic sub-mapping methods generation is not disabled
    + *
      MapStruct is allowed to generate an automatic sub-mapping between the {@code sourceType} and {@code + * targetType}
    + *
  • + * + * @param sourceType candidate source type to generate a sub-mapping from + * @param targetType candidate target type to generate a sub-mapping for + * + * @return {@code true} if MapStruct can try to generate an automatic sub-mapping between the types. + */ + boolean canGenerateAutoSubMappingBetween(Type sourceType, Type targetType) { + return !isDisableSubMappingMethodsGeneration() && + ctx.canGenerateAutoSubMappingBetween( sourceType, targetType ); + } + + private boolean isDisableSubMappingMethodsGeneration() { MapperConfiguration configuration = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ); return configuration.isDisableSubMappingMethodsGeneration(); } @@ -123,11 +143,11 @@ private Assignment createAssignment(SourceRHS source, ForgedMethod methodRef) { * * @param method the method that should be mapped * @param sourceErrorMessagePart the error message part for the source - * @param sourceRHS the {@link SourceRHS} + * @param sourceType the source type of the mapping * @param targetType the type of the target mapping * @param targetPropertyName the name of the target property */ - void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, SourceRHS sourceRHS, Type targetType, + void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, Type sourceType, Type targetType, String targetPropertyName) { ctx.getMessager().printMessage( method.getExecutable(), @@ -136,7 +156,7 @@ void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, Sou targetType, targetPropertyName, targetType, - sourceRHS.getSourceType() /* original source type */ + sourceType ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 943724dba7..da40bf0dd8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -45,7 +45,7 @@ public AbstractMappingMethodBuilder(Class selfType) { protected abstract boolean shouldUsePropertyNamesInHistory(); Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { - if ( isDisableSubMappingMethodsGeneration() ) { + if ( !canGenerateAutoSubMappingBetween( sourceType, targetType ) ) { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index cd972660bc..7a262fb46f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -121,7 +121,7 @@ public final M build() { reportCannotCreateMapping( method, String.format( "%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), sourceRHS.getSourceType() ), - sourceRHS, + sourceRHS.getSourceType(), targetElementType, "" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java new file mode 100644 index 0000000000..66656e6ea2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.regex.Pattern; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; + +import org.mapstruct.ap.spi.MappingExclusionProvider; + +/** + * The default implementation of the {@link MappingExclusionProvider} service provider interface. + * + * With the default implementation, MapStruct will not consider classes in the {@code java} and {@code javax} package + * as source / target for an automatic sub-mapping. The only exception is the {@link java.util.Collection}, + * {@link java.util.Map} and {@link java.util.stream.Stream} types. + * + * @author Filip Hrisafov + * @since 1.2 + */ +class DefaultMappingExclusionProvider implements MappingExclusionProvider { + private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + + @Override + public boolean isExcluded(TypeElement typeElement) { + Name name = typeElement.getQualifiedName(); + return name.length() != 0 && isFullyQualifiedNameExcluded( name ); + } + + protected boolean isFullyQualifiedNameExcluded(Name name) { + return JAVA_JAVAX_PACKAGE.matcher( name ).matches(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 6b781a3cc7..d7733479d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -125,7 +125,7 @@ public MapMappingMethod build() { keySourceRHS.getSourceErrorMessagePart(), keySourceRHS.getSourceType() ), - keySourceRHS, + keySourceRHS.getSourceType(), keyTargetType, "" ); @@ -175,7 +175,7 @@ public MapMappingMethod build() { valueSourceRHS.getSourceErrorMessagePart(), valueSourceRHS.getSourceType() ), - valueSourceRHS, + valueSourceRHS.getSourceType(), valueTargetType, "" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index cb713ee784..e1e466a36c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -29,15 +29,17 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Services; +import org.mapstruct.ap.spi.MappingExclusionProvider; /** * This class provides the context for the builders. @@ -54,6 +56,11 @@ */ public class MappingBuilderContext { + private static final MappingExclusionProvider SUB_MAPPING_EXCLUSION_PROVIDER = Services.get( + MappingExclusionProvider.class, + new DefaultMappingExclusionProvider() + ); + /** * Resolves the most suitable way for mapping an element (property, iterable element etc.) from source to target. * There are 2 basic types of mappings: @@ -222,4 +229,23 @@ public Set getUsedVirtualMappings() { return mappingResolver.getUsedVirtualMappings(); } + /** + * @param sourceType from which an automatic sub-mapping needs to be generated + * @param targetType to which an automatic sub-mapping needs to be generated + * + * @return {@code true} if MapStruct is allowed to try and generate an automatic sub-mapping between the + * source and target {@link Type} + */ + public boolean canGenerateAutoSubMappingBetween(Type sourceType, Type targetType) { + return canGenerateAutoSubMappingFor( sourceType ) && canGenerateAutoSubMappingFor( targetType ); + } + + /** + * @param type that MapStruct wants to use to genrate an autoamtic sub-mapping for/from + * + * @return {@code true} if the type is not excluded from the {@link MappingExclusionProvider} + */ + private boolean canGenerateAutoSubMappingFor(Type type) { + return type.getTypeElement() != null && !SUB_MAPPING_EXCLUSION_PROVIDER.isExcluded( type.getTypeElement() ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index e8a109996a..51cb0da68c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -304,13 +304,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get } } else { - reportCannotCreateMapping( - method, - rightHandSide.getSourceErrorMessagePart(), - rightHandSide, - targetType, - targetPropertyName - ); + reportCannotCreateMapping(); } return new PropertyMapping( @@ -325,6 +319,31 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get ); } + /** + * Report that a mapping could not be created. + */ + private void reportCannotCreateMapping() { + if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).getHistory() != null ) { + ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory(); + reportCannotCreateMapping( + method, + history.createSourcePropertyErrorMessage(), + history.getSourceType(), + history.getTargetType(), + history.createTargetPropertyName() + ); + } + else { + reportCannotCreateMapping( + method, + rightHandSide.getSourceErrorMessagePart(), + rightHandSide.getSourceType(), + targetType, + targetPropertyName + ); + } + } + private Assignment getDefaultValueAssignment( Assignment rhs ) { if ( defaultValue != null && ( !rhs.getSourceType().isPrimitive() || rhs.getSourcePresenceCheckerReference() != null) ) { @@ -582,11 +601,11 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s } private Assignment forgeMapping(SourceRHS sourceRHS) { - if ( forgedNamedBased && isDisableSubMappingMethodsGeneration() ) { + Type sourceType = sourceRHS.getSourceType(); + if ( forgedNamedBased && !canGenerateAutoSubMappingBetween( sourceType, targetType ) ) { return null; } - Type sourceType = sourceRHS.getSourceType(); //Fail fast. If we could not find the method by now, no need to try if ( sourceType.isPrimitive() || targetType.isPrimitive() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java new file mode 100644 index 0000000000..98d329643f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.element.TypeElement; + +import org.mapstruct.util.Experimental; + +/** + * A service provider interface that is used to control if MapStruct is allowed to generate automatic sub-mapping for + * a given {@link TypeElement}. + * + * When generating the implementation of a mapping method, MapStruct will apply the following routine for each + * attribute pair in the source and target object: + * + *
      + *
    • If source and target attribute have the same type, the value will be simply copied from source to target. + * If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target + * attribute.
    • + *
    • If source and target attribute type differ, check whether there is a another mapping method which has the + * type of the source attribute as parameter type and the type of the target attribute as return type. If such a + * method exists it will be invoked in the generated mapping implementation.
    • + *
    • If no such method exists MapStruct will look whether a built-in conversion for the source and target type + * of the attribute exists. If this is the case, the generated mapping code will apply this conversion.
    • + *
    • If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do + * the mapping between the source and target attributes
    • + *
    • If MapStruct could not create a name based mapping method an error will be raised at build time, + * indicating the non-mappable attribute and its path.
    • + *
    + * + * With this SPI the last step before raising an error can be controlled. i.e. A user can control whether MapStruct + * is allowed to generate such automatic sub-mapping method (for the source or target type) or not. + * + * @author Filip Hrisafov + * @since 1.2 + */ +@Experimental("This SPI can have it's signature changed in subsequent releases") +public interface MappingExclusionProvider { + + /** + * Checks if MapStruct should not generate an automatic sub-mapping for the provided {@link TypeElement}, i.e. + * MapStruct will not try to descent into this class and won't try to automatically map it with some other type. + * The given {@code typeElement} will be excluded from the automatic sub-mapping generation + * + * @param typeElement that needs to be checked + * + * @return {@code true} if MapStruct should exclude the provided {@link TypeElement} from an automatic sub-mapping + */ + boolean isExcluded(TypeElement typeElement); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java b/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java new file mode 100644 index 0000000000..4a2c74081e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test; + +/** + * @author Filip Hrisafov + */ +public class NoProperties { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java b/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java new file mode 100644 index 0000000000..5d879dbdcc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test; + +/** + * @author Filip Hrisafov + */ +public class WithProperties { + + private String string; + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 46544819e7..5f76775943 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -22,6 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -108,16 +110,16 @@ public void shouldFailOnEmptyMapAnnotation() { @Test @IssueKey("459") - @WithClasses({ ErroneousCollectionNoElementMappingFound.class }) + @WithClasses({ ErroneousCollectionNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, - line = 37, - messageRegExp = - "Can't map Collection element \".*AttributedString attributedString\" to \".*String string\". " + - "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + line = 38, + messageRegExp = "Can't map Collection element \".*WithProperties withProperties\" to \".*NoProperties" + + " noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + ".*WithProperties value\\)") } ) public void shouldFailOnNoElementMappingFound() { @@ -142,15 +144,16 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @Test @IssueKey("459") - @WithClasses({ ErroneousCollectionNoKeyMappingFound.class }) + @WithClasses({ ErroneousCollectionNoKeyMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, - line = 37, - messageRegExp = "Can't map Map key \".*AttributedString attributedString\" to \".*String string\". " + - "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + line = 38, + messageRegExp = "Can't map Map key \".*WithProperties withProperties\" to \".*NoProperties " + + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + ".*WithProperties value\\)") } ) public void shouldFailOnNoKeyMappingFound() { @@ -174,15 +177,16 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @Test @IssueKey("459") - @WithClasses({ ErroneousCollectionNoValueMappingFound.class }) + @WithClasses({ ErroneousCollectionNoValueMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, - line = 37, - messageRegExp = "Can't map Map value \".*AttributedString attributedString\" to \".*String string\". " + - "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + line = 38, + messageRegExp = "Can't map Map value \".*WithProperties withProperties\" to \".*NoProperties " + + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + ".*WithProperties value\\)") } ) public void shouldFailOnNoValueMappingFound() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java index d78ce5fb33..2b153913c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java @@ -18,10 +18,11 @@ */ package org.mapstruct.ap.test.collection.erroneous; -import java.text.AttributedString; import java.util.List; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -34,6 +35,6 @@ public interface ErroneousCollectionNoElementMappingFound { ErroneousCollectionNoElementMappingFound INSTANCE = Mappers.getMapper( ErroneousCollectionNoElementMappingFound.class ); - List map(List source); + List map(List source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java index 4b5f749568..8891b2da92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java @@ -18,10 +18,11 @@ */ package org.mapstruct.ap.test.collection.erroneous; -import java.text.AttributedString; import java.util.Map; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -34,6 +35,6 @@ public interface ErroneousCollectionNoKeyMappingFound { ErroneousCollectionNoKeyMappingFound INSTANCE = Mappers.getMapper( ErroneousCollectionNoKeyMappingFound.class ); - Map map(Map source); + Map map(Map source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java index a05de5427c..9bfd418f31 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java @@ -18,10 +18,11 @@ */ package org.mapstruct.ap.test.collection.erroneous; -import java.text.AttributedString; import java.util.Map; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -34,6 +35,6 @@ public interface ErroneousCollectionNoValueMappingFound { ErroneousCollectionNoValueMappingFound INSTANCE = Mappers.getMapper( ErroneousCollectionNoValueMappingFound.class ); - Map map(Map source); + Map map(Map source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java index df8c7f1826..31189594f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java @@ -18,11 +18,12 @@ */ package org.mapstruct.ap.test.java8stream.erroneous; -import java.text.AttributedString; import java.util.List; import java.util.stream.Stream; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -34,5 +35,5 @@ public interface ErroneousListToStreamNoElementMappingFound { ErroneousListToStreamNoElementMappingFound INSTANCE = Mappers.getMapper( ErroneousListToStreamNoElementMappingFound.class ); - Stream mapCollectionToStream(List source); + Stream mapCollectionToStream(List source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index ae35c39734..7122e730e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -22,6 +22,8 @@ import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -108,16 +110,16 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { } @Test - @WithClasses({ ErroneousStreamToStreamNoElementMappingFound.class }) + @WithClasses({ ErroneousStreamToStreamNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, - line = 36, - messageRegExp = "Can't map Stream element \".*AttributedString attributedString\" to \".*String " + - "string\". Consider to declare/implement a mapping method: \".*String map(.*AttributedString " + - "value)") + line = 37, + messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties " + + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + ".*WithProperties value\\)") } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { @@ -140,16 +142,17 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() } @Test - @WithClasses({ ErroneousListToStreamNoElementMappingFound.class }) + @WithClasses({ ErroneousListToStreamNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, - line = 37, + line = 38, messageRegExp = - "Can't map Stream element \".*AttributedString attributedString\" to \".*String string\". " + - "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties noProperties\"." + + " Consider to declare/implement a mapping method: \".*NoProperties map\\(.*WithProperties " + + "value\\)") } ) public void shouldFailOnNoElementMappingFoundForListToStream() { @@ -172,16 +175,16 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { } @Test - @WithClasses({ ErroneousStreamToListNoElementMappingFound.class }) + @WithClasses({ ErroneousStreamToListNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, - line = 37, + line = 38, messageRegExp = - "Can't map Stream element \".*AttributedString attributedString\" to .*String string\"." + - " Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + "Can't map Stream element \".*WithProperties withProperties\" to .*NoProperties noProperties\"." + + " Consider to declare/implement a mapping method: \".*NoProperties map(.*WithProperties value)") } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java index f3bc534664..8fd1b67e13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java @@ -18,11 +18,12 @@ */ package org.mapstruct.ap.test.java8stream.erroneous; -import java.text.AttributedString; import java.util.List; import java.util.stream.Stream; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -34,5 +35,5 @@ public interface ErroneousStreamToListNoElementMappingFound { ErroneousStreamToListNoElementMappingFound INSTANCE = Mappers.getMapper( ErroneousStreamToListNoElementMappingFound.class ); - List mapStreamToCollection(Stream source); + List mapStreamToCollection(Stream source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java index 66cfcbbad0..ac5d28a7a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java @@ -18,10 +18,11 @@ */ package org.mapstruct.ap.test.java8stream.erroneous; -import java.text.AttributedString; import java.util.stream.Stream; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.NoProperties; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.factory.Mappers; /** @@ -33,5 +34,5 @@ public interface ErroneousStreamToStreamNoElementMappingFound { ErroneousStreamToStreamNoElementMappingFound INSTANCE = Mappers.getMapper( ErroneousStreamToStreamNoElementMappingFound.class ); - Stream mapStreamToStream(Stream source); + Stream mapStreamToStream(Stream source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java new file mode 100644 index 0000000000..842199c466 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousJavaInternalMapper { + + Target map(Source entity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java new file mode 100644 index 0000000000..db2e37e71f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -0,0 +1,65 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Source.class, + Target.class, + ErroneousJavaInternalMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1154") +public class ErroneousJavaInternalTest { + + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousJavaInternalMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*MyType date\" to \"java\\.util\\.Date date\"\\. Consider to " + + "declare/implement a mapping method: \"java\\.util\\.Date map\\(.*MyType value\\)\"\\."), + @Diagnostic(type = ErroneousJavaInternalMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*MyType calendar\" to \"java\\.util\\.GregorianCalendar " + + "calendar\"\\. Consider to declare/implement a mapping method: \"java\\.util\\.GregorianCalendar " + + "map\\(.*MyType value\\)\"\\."), + @Diagnostic(type = ErroneousJavaInternalMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*List<.*MyType> types\" to \".*List<.*String> types\"\\" + + ". Consider to declare/implement a mapping method: \".*List<.*String> map\\(.*List<.*MyType> " + + "value\\)\"\\.") + }) + @Test + public void shouldNotNestIntoJavaPackageObjects() throws Exception { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java new file mode 100644 index 0000000000..da8e64d32c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java @@ -0,0 +1,54 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +class Source { + + static class DeepNestedType { + //CHECKSTYLE:OFF + public List types; + //CHECKSTYLE:ON + } + + static class NestedMyType { + //CHECKSTYLE:OFF + public DeepNestedType deepNestedType; + //CHECKSTYLE:ON + } + + static class MyType { + //CHECKSTYLE:OFF + public String someProperty; + //CHECKSTYLE:ON + } + + //CHECKSTYLE:OFF + public MyType date; + public MyType calendar; + public List types; + //TODO Nested error messages do not work yet. I think that this should be solved as part of #1150 + // (or we solve that one first :)) + //public NestedMyType nestedMyType; + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java new file mode 100644 index 0000000000..7ceedbd355 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions; + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; + +/** + * @author Filip Hrisafov + */ +class Target { + + class TargetDeepNested { + //CHECKSTYLE:OFF + public List types; + //CHECKSTYLE:ON + } + + class TargetNested { + //CHECKSTYLE:OFF + public TargetDeepNested deepNestedType; + //CHECKSTYLE:ON + } + + //CHECKSTYLE:OFF + public Date date; + public GregorianCalendar calendar; + public List types; + //public TargetNested nestedMyType; + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java new file mode 100644 index 0000000000..ad3461ff58 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions.custom; + +// tag::documentation[] + +import java.util.regex.Pattern; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; + +import org.mapstruct.ap.spi.MappingExclusionProvider; + +// end::documentation[] +/** + * @author Filip Hrisafov + */ +// tag::documentation[] +public class CustomMappingExclusionProvider implements MappingExclusionProvider { + private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + + @Override + public boolean isExcluded(TypeElement typeElement) { + // end::documentation[] + //For some reason the eclipse compiler does not work when you try to do NestedTarget.class + // tag::documentation[] + Name name = typeElement.getQualifiedName(); + return name.length() != 0 && ( JAVA_JAVAX_PACKAGE.matcher( name ).matches() || + name.toString().equals( "org.mapstruct.ap.test.nestedbeans.exclusions.custom.Target.NestedTarget" ) ); + } +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java new file mode 100644 index 0000000000..51497f05bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions.custom; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +// tag::documentation[] +@Mapper +public interface ErroneousCustomExclusionMapper { + + Target map(Source source); +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java new file mode 100644 index 0000000000..3196bef2e9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -0,0 +1,57 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions.custom; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Source.class, + Target.class, + ErroneousCustomExclusionMapper.class +}) +@WithServiceImplementation( CustomMappingExclusionProvider.class ) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1154") +public class ErroneousCustomExclusionTest { + + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomExclusionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 30, + messageRegExp = "Can't map property \".*NestedSource nested\" to \".*NestedTarget nested\"\\. " + + "Consider to declare/implement a mapping method: \".*NestedTarget map\\(.*NestedSource value\\)" + + "\"\\.") + } + ) + @Test + public void shouldFailToCreateMappingForExcludedClass() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java new file mode 100644 index 0000000000..969334da42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions.custom; + +/** + * @author Filip Hrisafov + */ +// tag::documentation[] +public class Source { + + static class NestedSource { + private String property; + // getters and setters + // end::documentation[] + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + // tag::documentation[] + } + + private NestedSource nested; + // getters and setters + // end::documentation[] + + public NestedSource getNested() { + return nested; + } + + public void setNested(NestedSource nested) { + this.nested = nested; + } + // tag::documentation[] +} +// tag::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java new file mode 100644 index 0000000000..e6d4b1ef22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exclusions.custom; + +/** + * @author Filip Hrisafov + */ +// tag::documentation[] +public class Target { + + static class NestedTarget { + private String property; + // getters and setters + // end::documentation[] + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + // tag::documentation[] + } + + private NestedTarget nested; + // getters and setters + // end::documentation[] + + public NestedTarget getNested() { + return nested; + } + + public void setNested(NestedTarget nested) { + this.nested = nested; + } + // tag::documentation[] +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 9398e634b3..67495c38c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -18,12 +18,11 @@ */ package org.mapstruct.ap.test.selection.generics; -import static org.assertj.core.api.Assertions.assertThat; - import java.math.BigDecimal; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.NoProperties; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -31,6 +30,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for the invocation of generic methods for mapping bean properties. * @@ -162,13 +163,18 @@ public void shouldFailOnSuperBounds2() { } @Test - @WithClasses({ ErroneousSource6.class, ErroneousTarget6.class, ErroneousSourceTargetMapper6.class }) + @WithClasses({ + ErroneousSource6.class, + ErroneousTarget6.class, + ErroneousSourceTargetMapper6.class, + NoProperties.class + }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, - messageRegExp = "Can't map property \"java.lang.String " + messageRegExp = "Can't map property \".*NoProperties " + "foo\\.wrapped\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA " + "foo\\.wrapped\"") diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java index c4b3adefcf..92662c8b7b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java @@ -18,15 +18,17 @@ */ package org.mapstruct.ap.test.selection.generics; +import org.mapstruct.ap.test.NoProperties; + public class ErroneousSource6 { - private WildCardSuperWrapper foo; + private WildCardSuperWrapper foo; - public WildCardSuperWrapper getFoo() { + public WildCardSuperWrapper getFoo() { return foo; } - public void setFoo(WildCardSuperWrapper foo) { + public void setFoo(WildCardSuperWrapper foo) { this.foo = foo; } } From 65b0e4d3c596e093aeb587370d462f5daafc0d09 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 7 May 2017 18:17:57 +0200 Subject: [PATCH 0099/1006] #1194 Setup code coverage analysis with codecov --- .codecov.yml | 7 +++++++ .travis.yml | 2 ++ parent/pom.xml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000000..9a590a70a8 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,7 @@ +coverage: + status: + project: + default: + # basic + threshold: 0.05 +comment: off diff --git a/.travis.yml b/.travis.yml index 73df7ae834..a9aec42c6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ jdk: - oraclejdk8 install: true script: mvn clean install -DprocessorIntegrationTest.toolchainsFile=etc/toolchains-travis-jenkins.xml -B -V +after_success: + - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" sudo: false cache: diff --git a/parent/pom.xml b/parent/pom.xml index 30bb2a27ea..97e4692348 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -494,7 +494,7 @@ org.jacoco jacoco-maven-plugin - 0.7.1.201405082137 + 0.7.9 org.jvnet.jaxb2.maven2 From 9415bb0999522b0ec1c11beda01f6c137e66f4e8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 7 May 2017 18:18:15 +0200 Subject: [PATCH 0100/1006] Add travis, codecov, license and gitter badges --- readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.md b/readme.md index 4be2eda1d6..0f16d2afca 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,11 @@ [![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.1.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) +[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) + +[![Build Status](https://img.shields.io/travis/mapstruct/mapstruct.svg)](https://travis-ci.org/mapstruct/mapstruct) +[![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct) +[![Gitter](https://img.shields.io/gitter/room/mapstruct/mapstruct.svg)](https://gitter.im/mapstruct/mapstruct-users) * [What is MapStruct?](#what-is-mapstruct) * [Requirements](#requirements) From 5dd0097cc9bf2da28d8dec14c9a6a3321f3a46a9 Mon Sep 17 00:00:00 2001 From: navpil Date: Wed, 10 May 2017 11:44:49 +0300 Subject: [PATCH 0101/1006] #122 Suggest property name in error message when referring to a non-existent property --- .../model/source/SourceReference.java | 24 +++- .../model/source/TargetReference.java | 88 ++++++++++++-- .../mapstruct/ap/internal/util/Message.java | 4 +- .../mapstruct/ap/internal/util/Strings.java | 45 +++++++ .../ap/internal/util/StringsTest.java | 9 ++ .../bugs/_1029/ErroneousIssue1029Mapper.java | 13 ++- .../ap/test/bugs/_1029/Issue1029Test.java | 8 +- .../ap/test/bugs/_1153/Issue1153Test.java | 3 +- .../ErroneousMappingsTest.java | 8 +- .../ap/test/namesuggestion/ColorRgb.java | 32 +++++ .../ap/test/namesuggestion/ColorRgbDto.java | 32 +++++ .../ap/test/namesuggestion/Garage.java | 32 +++++ .../ap/test/namesuggestion/GarageDto.java | 32 +++++ .../ap/test/namesuggestion/Person.java | 52 +++++++++ .../ap/test/namesuggestion/PersonDto.java | 52 +++++++++ .../SuggestMostSimilarNameTest.java | 110 ++++++++++++++++++ .../erroneous/PersonAgeMapper.java | 35 ++++++ .../PersonGarageWrongSourceMapper.java | 38 ++++++ .../PersonGarageWrongTargetMapper.java | 37 ++++++ .../erroneous/PersonNameMapper.java | 35 ++++++ 20 files changed, 666 insertions(+), 23 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index d81c265408..e8234614d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -164,7 +164,29 @@ public SourceReference build() { Strings.join( Arrays.asList( sourcePropertyNames ), "." ) ); } else { - reportMappingError( Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName() ); + int notFoundPropertyIndex; + Type sourceType; + if ( entries.isEmpty() ) { + notFoundPropertyIndex = 0; + sourceType = method.getParameters().get( 0 ).getType(); + } + else { + int lastFoundEntryIndex = entries.size() - 1; + notFoundPropertyIndex = lastFoundEntryIndex + 1; + sourceType = entries.get( lastFoundEntryIndex ).getType(); + } + String mostSimilarWord = Strings.getMostSimilarWord( + sourcePropertyNames[notFoundPropertyIndex], + sourceType.getPropertyReadAccessors().keySet() + ); + String prefix = ""; + for ( int i = 0; i < notFoundPropertyIndex; i++ ) { + prefix += sourcePropertyNames[i] + "."; + } + reportMappingError( + Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), + prefix + mostSimilarWord + ); } isValid = false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index fc2aaab9d2..e04bae36c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import javax.lang.model.type.DeclaredType; @@ -32,6 +33,7 @@ import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; /** @@ -95,7 +97,7 @@ public static class BuilderFromTargetMapping { * that multiple times because the first entry can also be the name of the parameter. Therefore we keep * the error message until the end when we can report it. */ - private Message errorMessage; + private MappingErrorMessage errorMessage; public BuilderFromTargetMapping messager(FormattingMessager messager) { this.messager = messager; @@ -159,7 +161,7 @@ && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParamete if ( !foundEntryMatch && errorMessage != null) { // This is called only for reporting errors - reportMappingError( errorMessage, mapping.getTargetName() ); + errorMessage.report(); } // foundEntryMatch = isValid, errors are handled here, and the BeanMapping uses that to ignore @@ -187,7 +189,7 @@ private List getTargetEntries(Type type, String[] entryNames) { || ( isNotLast && targetReadAccessor == null ) ) { // there should always be a write accessor (except for the last when the mapping is ignored and // there is a read accessor) and there should be read accessor mandatory for all but the last - setErrorMessage( targetWriteAccessor, targetReadAccessor ); + setErrorMessage( targetWriteAccessor, targetReadAccessor, entryNames, i, nextType ); break; } @@ -237,20 +239,16 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t return nextType; } - private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAccessor) { + private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAccessor, String[] entryNames, + int index, Type nextType) { if ( targetWriteAccessor == null && targetReadAccessor == null ) { - errorMessage = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; + errorMessage = new NoPropertyErrorMessage( mapping, method, messager, entryNames, index, nextType ); } else if ( targetWriteAccessor == null ) { - errorMessage = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE; + errorMessage = new NoWriteAccessorErrorMessage( mapping, method, messager ); } } - private void reportMappingError(Message msg, Object... objects) { - messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), - msg, objects ); - } - /** * A write accessor is not valid if it is {@code null} and it is not last. i.e. for nested target mappings * there must be a write accessor for all entries except the last one. @@ -354,4 +352,72 @@ public TargetReference pop() { return null; } } + + private abstract static class MappingErrorMessage { + private final Mapping mapping; + private final SourceMethod method; + private final FormattingMessager messager; + + private MappingErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager) { + this.mapping = mapping; + this.method = method; + this.messager = messager; + } + + abstract void report(); + + protected void printErrorMessage(Message message, Object... args) { + Object[] errorArgs = new Object[args.length + 1]; + errorArgs[0] = mapping.getTargetName(); + System.arraycopy( args, 0, errorArgs, 1, args.length ); + messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), + message, errorArgs + ); + } + } + + private static class NoWriteAccessorErrorMessage extends MappingErrorMessage { + + private NoWriteAccessorErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager) { + super( mapping, method, messager ); + } + + @Override + public void report() { + printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE ); + } + } + + private static class NoPropertyErrorMessage extends MappingErrorMessage { + + private final String[] entryNames; + private final int index; + private final Type nextType; + + private NoPropertyErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager, + String[] entryNames, int index, Type nextType) { + super( mapping, method, messager ); + this.entryNames = entryNames; + this.index = index; + this.nextType = nextType; + } + + @Override + public void report() { + + Set readAccessors = nextType.getPropertyReadAccessors().keySet(); + String mostSimilarProperty = Strings.getMostSimilarWord( + entryNames[index], + readAccessors + ); + + String prefix = ""; + for ( int i = 0; i < index; i++ ) { + prefix += entryNames[i] + "."; + } + + printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, prefix + mostSimilarProperty ); + } + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index c2b4aef72b..530f6238a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -31,7 +31,7 @@ public enum Message { BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), - BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in return type." ), + BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in return type. Did you mean \"%s\"?" ), BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE( "Property \"%s\" has no write accessor." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ), @@ -54,7 +54,7 @@ public enum Message { PROPERTYMAPPING_INVALID_EXPRESSION( "Value must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no parameter named \"%s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), - PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s)." ), + PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s). Did you mean \"%s\"?" ), PROPERTYMAPPING_NO_PRESENCE_CHECKER_FOR_SOURCE_TYPE( "Using custom source value presence checking strategy, but no presence checker found for %s in source type." ), PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 4c670b15a5..fa811612af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -199,4 +199,49 @@ public static String stubPropertyName(String fullyQualifiedName) { static Iterable extractParts(String name) { return Arrays.asList( name.split( "\\." ) ); } + + public static String getMostSimilarWord(String word, Collection similarWords) { + int minLevenstein = Integer.MAX_VALUE; + String mostSimilarWord = null; + for ( String similarWord : similarWords ) { + int levensteinDistance = levenshteinDistance( similarWord, word ); + if ( levensteinDistance < minLevenstein ) { + minLevenstein = levensteinDistance; + mostSimilarWord = similarWord; + } + } + return mostSimilarWord; + } + + private static int levenshteinDistance(String s, String t) { + int sLength = s.length() + 1; + int tLength = t.length() + 1; + + int[][] distances = new int[tLength][]; + for ( int i = 0; i < tLength; i++ ) { + distances[i] = new int[sLength]; + } + + for ( int i = 0; i < tLength; i++ ) { + distances[i][0] = i; + } + for ( int i = 0; i < sLength; i++ ) { + distances[0][i] = i; + } + + for ( int i = 1; i < tLength; i++ ) { + for ( int j = 1; j < sLength; j++ ) { + int cost = s.charAt( j - 1 ) == t.charAt( i - 1 ) ? 0 : 1; + distances[i][j] = Math.min( + Math.min( + distances[i - 1][j] + 1, + distances[i][j - 1] + 1 + ), + distances[i - 1][j - 1] + cost + ); + } + } + + return distances[tLength - 1][sLength - 1]; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index af88a2a0f8..12fa47c276 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -102,4 +102,13 @@ public void testSanitizeIdentifierName() throws Exception { assertThat( Strings.sanitizeIdentifierName( "int[]" ) ).isEqualTo( "intArray" ); } + @Test + public void findMostSimilarWord() throws Exception { + String mostSimilarWord = Strings.getMostSimilarWord( + "fulName", + Arrays.asList( "fullAge", "fullName", "address", "status" ) + ); + assertThat( mostSimilarWord ).isEqualTo( "fullName" ); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java index 479c72df22..b9ccfdc463 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java @@ -44,7 +44,8 @@ public interface ErroneousIssue1029Mapper { */ @Mappings({ @Mapping(target = "outdated", ignore = true), - @Mapping(target = "computedMapping", ignore = true) + @Mapping(target = "computedMapping", ignore = true), + @Mapping(target = "knownProp", ignore = true) }) Deck toDeckWithSomeIgnores(DeckForm form); @@ -71,6 +72,8 @@ class Deck { private LocalDateTime lastUpdated; + private String knownProp; + public Long getId() { return id; } @@ -79,6 +82,14 @@ public void setId(Long id) { this.id = id; } + public String getKnownProp() { + return knownProp; + } + + public void setKnownProp(String knownProp) { + this.knownProp = knownProp; + } + public LocalDateTime getLastUpdated() { return lastUpdated; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index 0b2adeed62..eecf82e1fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -42,11 +42,11 @@ public class Issue1029Test { @Test @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = Kind.WARNING, line = 39, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unmapped target properties: \"lastUpdated, computedMapping\"\\."), - @Diagnostic(kind = Kind.WARNING, line = 49, type = ErroneousIssue1029Mapper.class, + messageRegExp = "Unmapped target properties: \"knownProp, lastUpdated, computedMapping\"\\."), + @Diagnostic(kind = Kind.WARNING, line = 50, type = ErroneousIssue1029Mapper.class, messageRegExp = "Unmapped target property: \"lastUpdated\"\\."), - @Diagnostic(kind = Kind.ERROR, line = 54, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unknown property \"unknownProp\" in return type\\.") + @Diagnostic(kind = Kind.ERROR, line = 55, type = ErroneousIssue1029Mapper.class, + messageRegExp = "Unknown property \"unknownProp\" in return type\\. Did you mean \"knownProp\"?") }) public void reportsProperWarningsAndError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index 7ddbcd4276..a2dc85c0f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -48,7 +48,8 @@ public class Issue1153Test { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 36, - messageRegExp = "Unknown property \"nestedTarget2.writable2\" in return type\\.") + messageRegExp = "Unknown property \"nestedTarget2.writable2\" in return type\\. " + + "Did you mean \"nestedTarget2\\.writable\"") }) @Test public void shouldReportErrorsCorrectly() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index 1d75fa3b8c..64e695a436 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -47,15 +47,17 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 29, - messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)"), + messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)\\. " + + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 30, - messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)"), + messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)\\. " + + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 31, - messageRegExp = "Unknown property \"bar\" in return type"), + messageRegExp = "Unknown property \"bar\" in return type. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 33, diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java new file mode 100644 index 0000000000..9fa53911ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class ColorRgb { + + private String rgb; + + public String getRgb() { + return rgb; + } + + public void setRgb(String rgb) { + this.rgb = rgb; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java new file mode 100644 index 0000000000..55d5b05c63 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class ColorRgbDto { + + private String rgb; + + public String getRgb() { + return rgb; + } + + public void setRgb(String rgb) { + this.rgb = rgb; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java new file mode 100644 index 0000000000..67c713be16 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class Garage { + + private ColorRgb color; + + public ColorRgb getColor() { + return color; + } + + public void setColor(ColorRgb color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java new file mode 100644 index 0000000000..37543eb12a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class GarageDto { + + private ColorRgbDto color; + + public ColorRgbDto getColor() { + return color; + } + + public void setColor(ColorRgbDto color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java new file mode 100644 index 0000000000..e80adb708f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class Person { + + private String fullName; + + private int fullAge; + + private Garage garage; + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + + public int getFullAge() { + return fullAge; + } + + public void setFullAge(int fullAge) { + this.fullAge = fullAge; + } + + public Garage getGarage() { + return garage; + } + + public void setGarage(Garage garage) { + this.garage = garage; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java new file mode 100644 index 0000000000..13a804a9f1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +public class PersonDto { + + private String name; + + private int age; + + private GarageDto garage; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public GarageDto getGarage() { + return garage; + } + + public void setGarage(GarageDto garage) { + this.garage = garage; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java new file mode 100644 index 0000000000..0b81d07020 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -0,0 +1,110 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.namesuggestion.erroneous.PersonAgeMapper; +import org.mapstruct.ap.test.namesuggestion.erroneous.PersonGarageWrongSourceMapper; +import org.mapstruct.ap.test.namesuggestion.erroneous.PersonGarageWrongTargetMapper; +import org.mapstruct.ap.test.namesuggestion.erroneous.PersonNameMapper; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Person.class, PersonDto.class, Garage.class, GarageDto.class, ColorRgb.class, ColorRgbDto.class +}) +public class SuggestMostSimilarNameTest { + + @Test + @WithClasses({ + PersonAgeMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = PersonAgeMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = ".*Did you mean \"age\"\\?") + } + ) + public void testAgeSuggestion() { + } + + @Test + @WithClasses({ + PersonNameMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = PersonNameMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = ".*Did you mean \"fullName\"\\?") + } + ) + public void testNameSuggestion() { + } + + @Test + @WithClasses({ + PersonGarageWrongTargetMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = PersonGarageWrongTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = "Unknown property \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), + @Diagnostic(type = PersonGarageWrongTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = "Unknown property \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") + } + ) + public void testGarageTargetSuggestion() { + } + + @Test + @WithClasses({ + PersonGarageWrongSourceMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = PersonGarageWrongSourceMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = "No property named \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), + @Diagnostic(type = PersonGarageWrongSourceMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = "No property named \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") + } + ) + public void testGarageSourceSuggestion() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java new file mode 100644 index 0000000000..e40058c6f0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.namesuggestion.Person; +import org.mapstruct.ap.test.namesuggestion.PersonDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PersonAgeMapper { + + PersonAgeMapper MAPPER = Mappers.getMapper( PersonAgeMapper.class ); + + @Mapping(source = "agee", target = "fullAge") + Person mapPerson(PersonDto dto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java new file mode 100644 index 0000000000..40c5dc8f56 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.namesuggestion.Person; +import org.mapstruct.ap.test.namesuggestion.PersonDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PersonGarageWrongSourceMapper { + + PersonGarageWrongSourceMapper MAPPER = Mappers.getMapper( PersonGarageWrongSourceMapper.class ); + + @Mapping(source = "garage.colour.rgb", target = "garage.color.rgb") + Person mapPerson(PersonDto dto); + + @Mapping(source = "garage.colour", target = "garage.color") + Person mapPersonGarage(PersonDto dto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java new file mode 100644 index 0000000000..d462f54c16 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.namesuggestion.Person; +import org.mapstruct.ap.test.namesuggestion.PersonDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PersonGarageWrongTargetMapper { + + PersonGarageWrongTargetMapper MAPPER = Mappers.getMapper( PersonGarageWrongTargetMapper.class ); + + @Mapping(source = "garage.color.rgb", target = "garage.colour.rgb") + Person mapPerson(PersonDto dto); + + @Mapping(source = "garage.color", target = "garage.colour") + Person mapPersonGarage(PersonDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java new file mode 100644 index 0000000000..a6dab48610 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.namesuggestion.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.namesuggestion.Person; +import org.mapstruct.ap.test.namesuggestion.PersonDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface PersonNameMapper { + + PersonNameMapper MAPPER = Mappers.getMapper( PersonNameMapper.class ); + + @Mapping(source = "name", target = "fulName") + Person mapPerson(PersonDto dto); + +} From 75fa2fb0f70578b7e6ec0fe17b987eff2352891f Mon Sep 17 00:00:00 2001 From: navpil Date: Wed, 10 May 2017 15:11:18 +0300 Subject: [PATCH 0102/1006] #122 Minor formatting changes --- .../ap/internal/model/BeanMappingMethod.java | 9 ++++---- .../model/source/SourceReference.java | 23 +++++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4e9acc991f..1b05739100 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -102,9 +102,9 @@ public Builder souceMethod(SourceMethod sourceMethod) { return setupMethodWithMapping( sourceMethod ); } - public Builder forgedMethod(Method method ) { + public Builder forgedMethod(Method method) { singleMapping = new EmptySingleMapping(); - return setupMethodWithMapping( method ); + return setupMethodWithMapping( method ); } private Builder setupMethodWithMapping(Method sourceMethod) { @@ -206,7 +206,8 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { method, selectionParameters, ctx, - existingVariableNames ); + existingVariableNames + ); List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); @@ -427,7 +428,7 @@ else if ( mapping.getSourceName() != null ) { unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { - errorOccured = true; + errorOccured = true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index e8234614d4..582e0fed7e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -127,7 +127,7 @@ public SourceReference build() { if ( segments.length > 1 && parameter != null ) { sourcePropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = (entries.size() == sourcePropertyNames.length); + foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); } else { // its only a parameter, no property @@ -141,14 +141,14 @@ public SourceReference build() { sourcePropertyNames = segments; parameter = method.getSourceParameters().get( 0 ); entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = (entries.size() == sourcePropertyNames.length); + foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); if ( !foundEntryMatch ) { //Lets see if the expression contains the parameterName, so parameterName.propName1.propName2 if ( parameter.getName().equals( segments[0] ) ) { sourcePropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = (entries.size() == sourcePropertyNames.length); + foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); } else { // segment[0] cannot be attributed to the parameter name. @@ -161,7 +161,8 @@ public SourceReference build() { if ( parameter != null ) { reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(), - Strings.join( Arrays.asList( sourcePropertyNames ), "." ) ); + Strings.join( Arrays.asList( sourcePropertyNames ), "." ) + ); } else { int notFoundPropertyIndex; @@ -202,12 +203,15 @@ private List getSourceEntries(Type type, String[] entryNames) { Map sourceReadAccessors = newType.getPropertyReadAccessors(); Map sourcePresenceCheckers = newType.getPropertyPresenceCheckers(); - for ( Map.Entry getter : sourceReadAccessors.entrySet() ) { + for ( Map.Entry getter : sourceReadAccessors.entrySet() ) { if ( getter.getKey().equals( entryName ) ) { - newType = typeFactory.getReturnType( (DeclaredType) newType.getTypeMirror(), - getter.getValue() ); + newType = typeFactory.getReturnType( + (DeclaredType) newType.getTypeMirror(), + getter.getValue() + ); sourceEntries.add( forSourceReference( entryName, getter.getValue(), - sourcePresenceCheckers.get( entryName ), newType ) ); + sourcePresenceCheckers.get( entryName ), newType + ) ); matchFound = true; break; } @@ -221,7 +225,8 @@ private List getSourceEntries(Type type, String[] entryNames) { private void reportMappingError(Message msg, Object... objects) { messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), - msg, objects ); + msg, objects + ); } } From 70dbdcde0d2a8940587aabc2d6ec7e4899cb77a0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 23 May 2017 22:13:52 +0200 Subject: [PATCH 0103/1006] Disable codecov/patch statuses --- .codecov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codecov.yml b/.codecov.yml index 9a590a70a8..e3b6c8ff8f 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,5 +1,6 @@ coverage: status: + patch: off project: default: # basic From f2ad90042c60f982d405a2b031d7e96938090c31 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 May 2017 08:07:59 +0200 Subject: [PATCH 0104/1006] Update assertj and used dedicated method in tests (#1204) --- parent/pom.xml | 2 +- .../NestedSimpleBeansMappingTest.java | 53 ++++++------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 97e4692348..b8cd6ebca1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -50,7 +50,7 @@ 7.2 1 - 3.5.2 + 3.7.0 diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 0cfaf9ee02..3ce4fe9804 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.test.nestedbeans; -import java.lang.reflect.Field; -import java.util.ArrayList; import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; @@ -59,50 +57,29 @@ public class NestedSimpleBeansMappingTest { UserDtoUpdateMapperSmart.class ); - /** - * Extracts all non synthetic declared fields from a class. This is needed, because jacoco adds a synthetic field - * to the classes and also assertj does not support testing that all fields are exactly there. - * This will be needed until 953 from - * assertj-core is implemented. - * - * @param clazz to extract from - * - * @return all the non synthetic declared fields - */ - private static List extractAllFields(Class clazz) { - List nonSyntheticFields = new ArrayList(); - for ( Field field : clazz.getDeclaredFields() ) { - if ( !field.isSynthetic() ) { - nonSyntheticFields.add( field ); - } - } - - return nonSyntheticFields; - } - @Test public void shouldHaveAllFields() throws Exception { // If this test fails that means something new was added to the structure of the User/UserDto. // Make sure that the other tests are also updated (the new field is asserted) - Object[] userFields = new String[] { "name", "car", "secondCar", "house" }; - assertThat( extractAllFields( User.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields ); - assertThat( extractAllFields( UserDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields ); + String[] userFields = new String[] { "name", "car", "secondCar", "house" }; + assertThat( User.class ).hasOnlyDeclaredFields( userFields ); + assertThat( UserDto.class ).hasOnlyDeclaredFields( userFields ); - Object[] carFields = new String[] { "name", "year", "wheels" }; - assertThat( extractAllFields( Car.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields ); - assertThat( extractAllFields( CarDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields ); + String[] carFields = new String[] { "name", "year", "wheels" }; + assertThat( Car.class ).hasOnlyDeclaredFields( carFields ); + assertThat( CarDto.class ).hasOnlyDeclaredFields( carFields ); - Object[] wheelFields = new String[] { "front", "right" }; - assertThat( extractAllFields( Wheel.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields ); - assertThat( extractAllFields( WheelDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields ); + String[] wheelFields = new String[] { "front", "right" }; + assertThat( Wheel.class ).hasOnlyDeclaredFields( wheelFields ); + assertThat( WheelDto.class ).hasOnlyDeclaredFields( wheelFields ); - Object[] houseFields = new String[] { "name", "year", "roof" }; - assertThat( extractAllFields( House.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields ); - assertThat( extractAllFields( HouseDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields ); + String[] houseFields = new String[] { "name", "year", "roof" }; + assertThat( House.class ).hasOnlyDeclaredFields( houseFields ); + assertThat( HouseDto.class ).hasOnlyDeclaredFields( houseFields ); - Object[] roofFields = new String[] { "color", "type" }; - assertThat( extractAllFields( Roof.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields ); - assertThat( extractAllFields( RoofDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields ); + String[] roofFields = new String[] { "color", "type" }; + assertThat( Roof.class ).hasOnlyDeclaredFields( roofFields ); + assertThat( RoofDto.class ).hasOnlyDeclaredFields( roofFields ); } @Test From 2e09944b19360d417623a93aee13f797d76d7cc1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 May 2017 14:15:46 +0200 Subject: [PATCH 0105/1006] #1213 General code cleanups: * #122 Use util methods when possible * Fix some warnings in Javadoc generation * Don't use raw classes when not needed * Add .yml, binding.xjb and .asciidoc files to license check exclusion --- .../org/mapstruct/NullValueCheckStrategy.java | 5 ++-- parent/pom.xml | 3 +++ .../BigDecimalToStringConversion.java | 2 +- .../BigIntegerToStringConversion.java | 2 +- .../ap/internal/model/IterableCreation.java | 2 +- .../model/common/ImplementationType.java | 2 +- .../ap/internal/model/common/Type.java | 8 +++--- .../ap/internal/model/common/TypeFactory.java | 8 +++--- .../model/source/SourceReference.java | 26 ++++++++----------- .../model/source/TargetReference.java | 8 +++--- .../test/collection/wildcard/BeanMapper.java | 2 +- .../collection/wildcard/WildCardTest.java | 2 +- 12 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java index c6294ffffa..c6c0dbfd5d 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -30,12 +30,13 @@ public enum NullValueCheckStrategy { /** * This option includes a null check. When: - *

    + *
    + *
    *

      *
    1. a source value is directly assigned to a target
    2. *
    3. a source value assigned to a target by calling a type conversion on the target first
    4. *
    - *

    + *
    * NOTE: mapping methods (generated or hand written) are excluded from this null check. They are intended to * handle a null source value as 'valid' input. * diff --git a/parent/pom.xml b/parent/pom.xml index b8cd6ebca1..531714a9ff 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -534,6 +534,9 @@ .gitignore .factorypath .checkstyle + *.yml + **/*.asciidoc + **/binding.xjb diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index c3b7953b0f..2e19ee8aa6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -74,7 +74,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index e55bb3eeed..6b99b0fd19 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -81,7 +81,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java index e54cd98b8b..a1afac6f71 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -27,7 +27,7 @@ /** * Model element that can be used to create a type of {@link Iterable} or {@link java.util.Map}. If an implementation - * type is used and the target type has a constructor with {@link int} as parameter and the source parameter is of + * type is used and the target type has a constructor with {@code int} as parameter and the source parameter is of * {@link java.util.Collection}, {@link java.util.Map} or {@code Array} type then MapStruct will use that constructor * with the {@code size} / {@code length} from the source parameter. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java index 8ddb2356b1..15fb300b99 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java @@ -68,7 +68,7 @@ public Type getType() { } /** - * @return {@code true} if the underlying type has a constructor for {@link int} {@code initialCapacity}, {@code + * @return {@code true} if the underlying type has a constructor for {@code int} {@code initialCapacity}, {@code * false} otherwise */ public boolean hasInitialCapacityConstructor() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index cb089e6e71..a0dad2c0ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -838,10 +838,10 @@ public String getIdentification() { /** * Establishes the type bound: *

      - *
    1. {@code}, returns Number
    2. - *
    3. {@code}, returns Number
    4. - *
    5. {@code}, returns Object
    6. - *
    7. {@code, returns Number}
    8. + *
    9. {@code }, returns Number
    10. + *
    11. {@code }, returns Number
    12. + *
    13. {@code }, returns Object
    14. + *
    15. {@code , returns Number}
    16. *
    * @return the bound for this parameter */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index b8a40333db..a2dc7709f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -521,10 +521,10 @@ public Type createVoidType() { /** * Establishes the type bound: *
      - *
    1. {@code}, returns Number
    2. - *
    3. {@code}, returns Number
    4. - *
    5. {@code}, returns Object
    6. - *
    7. {@code, returns Number}
    8. + *
    9. {@code }, returns Number
    10. + *
    11. {@code }, returns Number
    12. + *
    13. {@code }, returns Object
    14. + *
    15. {@code , returns Number}
    16. *
    * * @param typeMirror the type to return the bound for diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 582e0fed7e..c8374db8aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -20,6 +20,7 @@ import static org.mapstruct.ap.internal.model.source.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; import java.util.ArrayList; import java.util.Arrays; @@ -165,28 +166,23 @@ public SourceReference build() { ); } else { - int notFoundPropertyIndex; - Type sourceType; - if ( entries.isEmpty() ) { - notFoundPropertyIndex = 0; - sourceType = method.getParameters().get( 0 ).getType(); - } - else { - int lastFoundEntryIndex = entries.size() - 1; - notFoundPropertyIndex = lastFoundEntryIndex + 1; - sourceType = entries.get( lastFoundEntryIndex ).getType(); + int notFoundPropertyIndex = 0; + Type sourceType = method.getParameters().get( 0 ).getType(); + if ( !entries.isEmpty() ) { + notFoundPropertyIndex = entries.size(); + sourceType = last( entries ).getType(); } String mostSimilarWord = Strings.getMostSimilarWord( sourcePropertyNames[notFoundPropertyIndex], sourceType.getPropertyReadAccessors().keySet() ); - String prefix = ""; - for ( int i = 0; i < notFoundPropertyIndex; i++ ) { - prefix += sourcePropertyNames[i] + "."; - } + List elements = new ArrayList( + Arrays.asList( sourcePropertyNames ).subList( 0, notFoundPropertyIndex ) + ); + elements.add( mostSimilarWord ); reportMappingError( Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), - prefix + mostSimilarWord + Strings.join( elements, "." ) ); } isValid = false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index e04bae36c0..5e17c7cd1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -411,12 +411,10 @@ public void report() { readAccessors ); - String prefix = ""; - for ( int i = 0; i < index; i++ ) { - prefix += entryNames[i] + "."; - } + List elements = new ArrayList( Arrays.asList( entryNames ).subList( 0, index ) ); + elements.add( mostSimilarProperty ); - printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, prefix + mostSimilarProperty ); + printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java index 1f94bab64c..d759020eb4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java @@ -42,7 +42,7 @@ BigDecimal map(JAXBElement value) { } JAXBElement map(BigDecimal value) { - return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); + return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index e35bcc668b..cf6758ece9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -153,7 +153,7 @@ public void shouldFailOnTypeVarTarget() { public void shouldMapBean() { GoodIdea aGoodIdea = new GoodIdea(); - aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); + aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); aGoodIdea.setDescription( BigDecimal.ZERO ); CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea ); From 6187a72a2b6d55674c2026dbf1028ef31d1b721c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 May 2017 22:32:05 +0200 Subject: [PATCH 0106/1006] #1148 Always add the generated MappingMethod if the MappingOptions are restricted to the defined mappings --- .../internal/model/AbstractBaseBuilder.java | 5 +- .../internal/model/source/PropertyEntry.java | 4 + .../mapstruct/ap/test/bugs/_1148/Entity.java | 115 +++++++++++++ .../ap/test/bugs/_1148/Issue1148Mapper.java | 57 +++++++ .../ap/test/bugs/_1148/Issue1148Test.java | 157 ++++++++++++++++++ .../nestedbeans/mixed/FishTankMapperImpl.java | 30 +++- 6 files changed, 364 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 55b0885b71..a7bc1b77ba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -117,7 +117,10 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp if ( mappingMethod == null ) { return null; } - if ( !ctx.getMappingsToGenerate().contains( mappingMethod ) ) { + if (methodRef.getMappingOptions().isRestrictToDefinedMappings() || + !ctx.getMappingsToGenerate().contains( mappingMethod )) { + // If the mapping options are restricted only to the defined mappings, then use the mapping method. + // See https://github.com/mapstruct/mapstruct/issues/1148 ctx.getMappingsToGenerate().add( mappingMethod ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java index b88b3cbe0a..4e189015c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java @@ -142,4 +142,8 @@ public boolean equals(Object obj) { return true; } + @Override + public String toString() { + return type + " " + Strings.join( Arrays.asList( fullName ), "." ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java new file mode 100644 index 0000000000..6ed4f1e48b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java @@ -0,0 +1,115 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1148; + +/** + * @author Filip Hrisafov + */ +class Entity { + + static class NestedClient { + //CHECKSTYLE:OFF + public long id; + //CHECKSTYLE:ON + } + + static class Client { + + //CHECKSTYLE:OFF + public NestedClient nestedClient; + //CHECKSTYLE:ON + } + + static class Dto { + + //CHECKSTYLE:OFF + public long recipientId; + public long senderId; + public NestedDto nestedDto; + public NestedDto nestedDto2; + public ClientDto sameLevel; + public ClientDto sameLevel2; + public ClientDto level; + public ClientDto level2; + //CHECKSTYLE:ON + } + + static class ClientDto { + //CHECKSTYLE:OFF + public NestedDto client; + + //CHECKSTYLE:ON + ClientDto(NestedDto client) { + this.client = client; + } + } + + static class NestedDto { + //CHECKSTYLE:OFF + public long id; + //CHECKSTYLE:ON + + NestedDto(long id) { + this.id = id; + } + } + + //CHECKSTYLE:OFF + public Client client; + public Client client2; + public NestedClient nested; + public NestedClient nested2; + private Client recipient; + private Client sender; + private long id; + private long id2; + //CHECKSTYLE:OFF + + public Client getRecipient() { + return recipient; + } + + public void setRecipient(Client recipient) { + this.recipient = recipient; + } + + public Client getSender() { + return sender; + } + + public void setSender(Client sender) { + this.sender = sender; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public long getId2() { + return id2; + } + + public void setId2(long id2) { + this.id2 = id2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java new file mode 100644 index 0000000000..f4ae218ca1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java @@ -0,0 +1,57 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1148; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1148Mapper { + + Issue1148Mapper INSTANCE = Mappers.getMapper( Issue1148Mapper.class ); + + @Mappings({ + @Mapping(source = "senderId", target = "sender.nestedClient.id"), + @Mapping(source = "recipientId", target = "recipient.nestedClient.id"), + @Mapping(source = "sameLevel.client.id", target = "client.nestedClient.id"), + @Mapping(source = "sameLevel2.client.id", target = "client2.nestedClient.id"), + @Mapping(source = "level.client.id", target = "nested.id"), + @Mapping(source = "level2.client.id", target = "nested2.id"), + @Mapping(source = "nestedDto.id", target = "id"), + @Mapping(source = "nestedDto2.id", target = "id2") + }) + Entity toEntity(Entity.Dto dto); + + @Mappings({ + @Mapping(source = "dto2.senderId", target = "sender.nestedClient.id"), + @Mapping(source = "dto1.recipientId", target = "recipient.nestedClient.id"), + @Mapping(source = "dto1.sameLevel.client.id", target = "client.nestedClient.id"), + @Mapping(source = "dto2.sameLevel2.client.id", target = "client2.nestedClient.id"), + @Mapping(source = "dto1.level.client.id", target = "nested.id"), + @Mapping(source = "dto2.level2.client.id", target = "nested2.id"), + @Mapping(source = "dto1.nestedDto.id", target = "id"), + @Mapping(source = "dto2.nestedDto2.id", target = "id2") + }) + Entity toEntity(Entity.Dto dto1, Entity.Dto dto2); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java new file mode 100644 index 0000000000..5997b93d66 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java @@ -0,0 +1,157 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1148; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Entity.class, + Issue1148Mapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1148") +public class Issue1148Test { + + @Test + public void shouldNotUseSameMethodForDifferentMappingsNestedSource() throws Exception { + Entity.Dto dto = new Entity.Dto(); + dto.nestedDto = new Entity.NestedDto( 30 ); + dto.nestedDto2 = new Entity.NestedDto( 40 ); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto ); + + assertThat( entity.getId() ).isEqualTo( 30 ); + assertThat( entity.getId2() ).isEqualTo( 40 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() throws Exception { + Entity.Dto dto = new Entity.Dto(); + dto.recipientId = 10; + dto.senderId = 20; + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto ); + + assertThat( entity.getRecipient() ).isNotNull(); + assertThat( entity.getRecipient().nestedClient ).isNotNull(); + assertThat( entity.getRecipient().nestedClient.id ).isEqualTo( 10 ); + + assertThat( entity.getSender() ).isNotNull(); + assertThat( entity.getSender().nestedClient ).isNotNull(); + assertThat( entity.getSender().nestedClient.id ).isEqualTo( 20 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsSymmetric() throws Exception { + Entity.Dto dto = new Entity.Dto(); + dto.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); + dto.sameLevel2 = new Entity.ClientDto(new Entity.NestedDto( 40 )); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto ); + + assertThat( entity.client ).isNotNull(); + assertThat( entity.client.nestedClient ).isNotNull(); + assertThat( entity.client.nestedClient.id ).isEqualTo( 30 ); + + assertThat( entity.client2 ).isNotNull(); + assertThat( entity.client2.nestedClient ).isNotNull(); + assertThat( entity.client2.nestedClient.id ).isEqualTo( 40 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() throws Exception { + Entity.Dto dto = new Entity.Dto(); + dto.level = new Entity.ClientDto(new Entity.NestedDto( 80 )); + dto.level2 = new Entity.ClientDto(new Entity.NestedDto( 90 )); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto ); + + assertThat( entity.nested ).isNotNull(); + assertThat( entity.nested.id ).isEqualTo( 80 ); + + assertThat( entity.nested2 ).isNotNull(); + assertThat( entity.nested2.id ).isEqualTo( 90 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() throws Exception { + Entity.Dto dto1 = new Entity.Dto(); + dto1.nestedDto = new Entity.NestedDto( 30 ); + Entity.Dto dto2 = new Entity.Dto(); + dto2.nestedDto2 = new Entity.NestedDto( 40 ); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto1, dto2 ); + + assertThat( entity.getId() ).isEqualTo( 30 ); + assertThat( entity.getId2() ).isEqualTo( 40 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() throws Exception { + Entity.Dto dto1 = new Entity.Dto(); + dto1.recipientId = 10; + Entity.Dto dto2 = new Entity.Dto(); + dto2.senderId = 20; + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto1, dto2 ); + + assertThat( entity.getRecipient() ).isNotNull(); + assertThat( entity.getRecipient().nestedClient ).isNotNull(); + assertThat( entity.getRecipient().nestedClient.id ).isEqualTo( 10 ); + + assertThat( entity.getSender() ).isNotNull(); + assertThat( entity.getSender().nestedClient ).isNotNull(); + assertThat( entity.getSender().nestedClient.id ).isEqualTo( 20 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsSymmetricMultiple() throws Exception { + Entity.Dto dto1 = new Entity.Dto(); + dto1.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); + Entity.Dto dto2 = new Entity.Dto(); + dto2.sameLevel2 = new Entity.ClientDto(new Entity.NestedDto( 40 )); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto1, dto2 ); + + assertThat( entity.client ).isNotNull(); + assertThat( entity.client.nestedClient ).isNotNull(); + assertThat( entity.client.nestedClient.id ).isEqualTo( 30 ); + + assertThat( entity.client2 ).isNotNull(); + assertThat( entity.client2.nestedClient ).isNotNull(); + assertThat( entity.client2.nestedClient.id ).isEqualTo( 40 ); + } + + @Test + public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetricMultiple() { + Entity.Dto dto1 = new Entity.Dto(); + dto1.level = new Entity.ClientDto(new Entity.NestedDto( 80 )); + Entity.Dto dto2 = new Entity.Dto(); + dto2.level2 = new Entity.ClientDto(new Entity.NestedDto( 90 )); + Entity entity = Issue1148Mapper.INSTANCE.toEntity( dto1, dto2 ); + + assertThat( entity.nested ).isNotNull(); + assertThat( entity.nested.id ).isEqualTo( 80 ); + + assertThat( entity.nested2 ).isNotNull(); + assertThat( entity.nested2.id ).isEqualTo( 90 ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 40b8254e2d..b2bd752066 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -39,8 +39,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-19T16:25:02+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2017-04-24T17:26:46+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" ) public class FishTankMapperImpl implements FishTankMapper { @@ -74,7 +74,7 @@ public FishTankDto mapAsWell(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); - fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); + fishTankDto.setMaterial( fishTankToMaterialDto1( source ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); Ornament ornament = sourceInteriorOrnament( source ); if ( ornament != null ) { @@ -219,6 +219,30 @@ protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { return waterPlantDto; } + protected MaterialDto fishTankToMaterialDto1(FishTank fishTank) { + if ( fishTank == null ) { + return null; + } + + MaterialDto materialDto = new MaterialDto(); + + materialDto.setMaterialType( materialTypeToMaterialTypeDto( fishTank.getMaterial() ) ); + + return materialDto; + } + + protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisationDto1(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityOrganisationDto waterQualityOrganisationDto = new WaterQualityOrganisationDto(); + + waterQualityOrganisationDto.setName( waterQualityReport.getOrganisationName() ); + + return waterQualityOrganisationDto; + } + protected Fish fishDtoToFish(FishDto fishDto) { if ( fishDto == null ) { return null; From ceaa869c65599de472f20255408497bc0c1e9a57 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 30 May 2017 21:35:39 +0200 Subject: [PATCH 0107/1006] #1215 Add import correctly for array types --- .../ap/internal/model/GeneratedType.java | 10 +++- .../ap/internal/model/common/Type.java | 2 +- .../ap/internal/model/common/TypeFactory.java | 20 ++++++-- .../ap/internal/model/GeneratedType.ftl | 4 +- .../ap/test/bugs/_1215/Issue1215Test.java | 49 +++++++++++++++++++ .../ap/test/bugs/_1215/dto/EntityDTO.java | 46 +++++++++++++++++ .../ap/test/bugs/_1215/entity/AnotherTag.java | 34 +++++++++++++ .../ap/test/bugs/_1215/entity/Entity.java | 43 ++++++++++++++++ .../ap/test/bugs/_1215/entity/Tag.java | 34 +++++++++++++ .../bugs/_1215/mapper/Issue1215Mapper.java | 31 ++++++++++++ 10 files changed, 265 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 5ae330af44..c9eb107d69 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -199,6 +199,14 @@ public SortedSet getImportTypes() { return importedTypes; } + public SortedSet getImportTypeNames() { + SortedSet importTypeNames = new TreeSet(); + for ( Type type : getImportTypes() ) { + importTypeNames.add( type.getImportName() ); + } + return importTypeNames; + } + public Constructor getConstructor() { return constructor; } @@ -222,7 +230,7 @@ private boolean needsImportDeclaration(Type typeToAdd) { return false; } - if ( typeToAdd.getTypeMirror().getKind() != TypeKind.DECLARED ) { + if ( typeToAdd.getTypeMirror().getKind() != TypeKind.DECLARED && !typeToAdd.isArrayType() ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index a0dad2c0ef..46b884396b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -290,7 +290,7 @@ public String getFullyQualifiedName() { * @return The name of this type as to be used within import statements. */ public String getImportName() { - return isArrayType() ? qualifiedName.substring( 0, qualifiedName.length() - 2 ) : qualifiedName; + return isArrayType() ? TypeFactory.trimSimpleClassName( qualifiedName ) : qualifiedName; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index a2dc7709f4..89c3a2d90f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -175,6 +175,7 @@ public Type getType(TypeMirror mirror) { String qualifiedName; TypeElement typeElement; Type componentType; + boolean isImported; if ( mirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) mirror; @@ -195,28 +196,38 @@ public Type getType(TypeMirror mirror) { } componentType = null; + isImported = isImported( name, qualifiedName ); } else if ( mirror.getKind() == TypeKind.ARRAY ) { TypeMirror componentTypeMirror = getComponentType( mirror ); + StringBuilder builder = new StringBuilder("[]"); + + while ( componentTypeMirror.getKind() == TypeKind.ARRAY ) { + componentTypeMirror = getComponentType( componentTypeMirror ); + builder.append( "[]" ); + } if ( componentTypeMirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) componentTypeMirror; TypeElement componentTypeElement = (TypeElement) declaredType.asElement(); - name = componentTypeElement.getSimpleName().toString() + "[]"; + String arraySuffix = builder.toString(); + name = componentTypeElement.getSimpleName().toString() + arraySuffix; packageName = elementUtils.getPackageOf( componentTypeElement ).getQualifiedName().toString(); - qualifiedName = componentTypeElement.getQualifiedName().toString() + "[]"; + qualifiedName = componentTypeElement.getQualifiedName().toString() + arraySuffix; + isImported = isImported( name, qualifiedName ); } else { name = mirror.toString(); packageName = null; qualifiedName = name; + isImported = false; } isEnumType = false; isInterface = false; typeElement = null; - componentType = getType( componentTypeMirror ); + componentType = getType( getComponentType( mirror ) ); } else { isEnumType = false; @@ -226,6 +237,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { qualifiedName = name; typeElement = null; componentType = null; + isImported = false; } return new Type( @@ -244,7 +256,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { isCollectionType, isMapType, isStreamType, - isImported( name, qualifiedName ) + isImported ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 01fe414e58..0656686b4f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -23,8 +23,8 @@ package ${packageName}; -<#list importTypes as importedType> -import ${importedType.importName}; +<#list importTypeNames as importedType> +import ${importedType}; <#if !generatedTypeAvailable>/* diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java new file mode 100644 index 0000000000..1e4255eb0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._1215.dto.EntityDTO; +import org.mapstruct.ap.test.bugs._1215.entity.AnotherTag; +import org.mapstruct.ap.test.bugs._1215.entity.Entity; +import org.mapstruct.ap.test.bugs._1215.entity.Tag; +import org.mapstruct.ap.test.bugs._1215.mapper.Issue1215Mapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses( { + EntityDTO.class, + Entity.class, + Tag.class, + AnotherTag.class, + Issue1215Mapper.class +} ) +@IssueKey( "1215" ) +@RunWith( AnnotationProcessorTestRunner.class ) +public class Issue1215Test { + + @Test + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java new file mode 100644 index 0000000000..364dda4b12 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215.dto; + +import org.mapstruct.ap.test.bugs._1215.entity.AnotherTag; +import org.mapstruct.ap.test.bugs._1215.entity.Tag; + +/** + * @author Filip Hrisafov + */ +public class EntityDTO { + private Tag[] tags; + private AnotherTag[][] otherTags; + + public Tag[] getTags() { + return tags; + } + + public void setTags(Tag[] tags) { + this.tags = tags; + } + + public AnotherTag[][] getOtherTags() { + return otherTags; + } + + public void setOtherTags(AnotherTag[][] otherTags) { + this.otherTags = otherTags; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java new file mode 100644 index 0000000000..16f454567b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215.entity; + +/** + * @author Filip Hrisafov + */ +public class AnotherTag { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java new file mode 100644 index 0000000000..e6e9a170f8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215.entity; + +/** + * @author Filip Hrisafov + */ +public class Entity { + private Tag[] tags; + private AnotherTag[][] otherTags; + + public Tag[] getTags() { + return tags; + } + + public void setTags(Tag[] tags) { + this.tags = tags; + } + + public AnotherTag[][] getOtherTags() { + return otherTags; + } + + public void setOtherTags(AnotherTag[][] otherTags) { + this.otherTags = otherTags; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java new file mode 100644 index 0000000000..b5962fee1d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215.entity; + +/** + * @author Filip Hrisafov + */ +public class Tag { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java new file mode 100644 index 0000000000..da517a25bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1215.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._1215.dto.EntityDTO; +import org.mapstruct.ap.test.bugs._1215.entity.Entity; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1215Mapper { + Entity fromDTO(EntityDTO dto); +} From 9fc111f7df40b921d06c72725bceafcb3b8fafba Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 18 May 2017 00:31:45 +0200 Subject: [PATCH 0108/1006] #1129 Do not use equals and hashCode from TypeMirror --- .../ap/internal/model/EnumMappingMethod.java | 7 +- .../ap/internal/model/ValueMappingMethod.java | 7 +- .../ap/internal/model/common/Type.java | 2 +- .../ap/internal/model/source/BeanMapping.java | 7 +- .../model/source/IterableMapping.java | 7 +- .../ap/internal/model/source/MapMapping.java | 11 +- .../ap/internal/model/source/Mapping.java | 12 +- .../internal/model/source/MethodMatcher.java | 2 +- .../model/source/SelectionParameters.java | 34 +- .../processor/MethodRetrievalProcessor.java | 12 +- .../model/source/SelectionParametersTest.java | 389 ++++++++++++++++++ 11 files changed, 462 insertions(+), 28 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index 9dffd83af6..eb401b56d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -26,6 +26,7 @@ import java.util.Set; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.source.EnumMapping; @@ -99,7 +100,7 @@ enumConstant, first( mappedConstants ).getTargetName() } } - SelectionParameters selectionParameters = getSelecionParameters( method ); + SelectionParameters selectionParameters = getSelecionParameters( method, ctx.getTypeUtils() ); Set existingVariables = new HashSet( method.getParameterNames() ); List beforeMappingMethods = @@ -110,13 +111,13 @@ enumConstant, first( mappedConstants ).getTargetName() return new EnumMappingMethod( method, enumMappings, beforeMappingMethods, afterMappingMethods ); } - private static SelectionParameters getSelecionParameters(SourceMethod method) { + private static SelectionParameters getSelecionParameters(SourceMethod method, Types typeUtils) { BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); if ( beanMappingPrism != null ) { List qualifiers = beanMappingPrism.qualifiedBy(); List qualifyingNames = beanMappingPrism.qualifiedByName(); TypeMirror resultType = beanMappingPrism.resultType(); - return new SelectionParameters( qualifiers, qualifyingNames, resultType ); + return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); } return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index c7fc97010a..2d3789419e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -26,6 +26,7 @@ import java.util.Set; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.source.ForgedMethod; @@ -118,7 +119,7 @@ public ValueMappingMethod build( ) { } // do before / after lifecycle mappings - SelectionParameters selectionParameters = getSelectionParameters( method ); + SelectionParameters selectionParameters = getSelectionParameters( method, ctx.getTypeUtils() ); Set existingVariables = new HashSet( method.getParameterNames() ); List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); @@ -185,13 +186,13 @@ private List enumToEnumMapping(Method method) { return mappings; } - private SelectionParameters getSelectionParameters(Method method) { + private SelectionParameters getSelectionParameters(Method method, Types typeUtils) { BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); if ( beanMappingPrism != null ) { List qualifiers = beanMappingPrism.qualifiedBy(); List qualifyingNames = beanMappingPrism.qualifiedByName(); TypeMirror resultType = beanMappingPrism.resultType(); - return new SelectionParameters( qualifiers, qualifyingNames, resultType ); + return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); } return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 46b884396b..4a3350461f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -572,7 +572,7 @@ private Accessor getAdderForType(Type collectionProperty, String pluralPropertyN continue; } VariableElement arg = executable.getParameters().get( 0 ); - if ( arg.asType().equals( typeArg ) ) { + if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { candidates.add( adder ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index dbe0eee278..dccc14f7d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -20,6 +20,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -39,7 +40,7 @@ public class BeanMapping { private final ReportingPolicyPrism reportingPolicy; public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, - FormattingMessager messager) { + FormattingMessager messager, Types typeUtils) { if ( beanMapping == null ) { return null; @@ -61,7 +62,9 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem SelectionParameters cmp = new SelectionParameters( beanMapping.qualifiedBy(), beanMapping.qualifiedByName(), - resultTypeIsDefined ? beanMapping.resultType() : null ); + resultTypeIsDefined ? beanMapping.resultType() : null, + typeUtils + ); //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? return new BeanMapping( cmp, nullValueMappingStrategy, null ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java index f7cdcdc2e9..8e96790a22 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java @@ -21,6 +21,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.prism.IterableMappingPrism; @@ -41,7 +42,7 @@ public class IterableMapping { private final NullValueMappingStrategyPrism nullValueMappingStrategy; public static IterableMapping fromPrism(IterableMappingPrism iterableMapping, ExecutableElement method, - FormattingMessager messager) { + FormattingMessager messager, Types typeUtils) { if ( iterableMapping == null ) { return null; } @@ -66,7 +67,9 @@ public static IterableMapping fromPrism(IterableMappingPrism iterableMapping, Ex SelectionParameters selection = new SelectionParameters( iterableMapping.qualifiedBy(), iterableMapping.qualifiedByName(), - elementTargetTypeIsDefined ? iterableMapping.elementTargetType() : null ); + elementTargetTypeIsDefined ? iterableMapping.elementTargetType() : null, + typeUtils + ); FormattingParameters formatting = new FormattingParameters( iterableMapping.dateFormat(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java index ecfe67ff57..adeac692c7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java @@ -21,6 +21,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.prism.MapMappingPrism; @@ -43,7 +44,7 @@ public class MapMapping { private final NullValueMappingStrategyPrism nullValueMappingStrategy; public static MapMapping fromPrism(MapMappingPrism mapMapping, ExecutableElement method, - FormattingMessager messager) { + FormattingMessager messager, Types typeUtils) { if ( mapMapping == null ) { return null; } @@ -74,12 +75,16 @@ public static MapMapping fromPrism(MapMappingPrism mapMapping, ExecutableElement SelectionParameters keySelection = new SelectionParameters( mapMapping.keyQualifiedBy(), mapMapping.keyQualifiedByName(), - keyTargetTypeIsDefined ? mapMapping.keyTargetType() : null); + keyTargetTypeIsDefined ? mapMapping.keyTargetType() : null, + typeUtils + ); SelectionParameters valueSelection = new SelectionParameters( mapMapping.valueQualifiedBy(), mapMapping.valueQualifiedByName(), - valueTargetTypeIsDefined ? mapMapping.valueTargetType() : null); + valueTargetTypeIsDefined ? mapMapping.valueTargetType() : null, + typeUtils + ); FormattingParameters keyFormatting = new FormattingParameters( mapMapping.keyDateFormat(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 61d1358b56..e26d431260 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -32,6 +32,7 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; @@ -72,12 +73,11 @@ public class Mapping { private TargetReference targetReference; public static Map> fromMappingsPrism(MappingsPrism mappingsAnnotation, - ExecutableElement method, - FormattingMessager messager) { + ExecutableElement method, FormattingMessager messager, Types typeUtils) { Map> mappings = new HashMap>(); for ( MappingPrism mappingPrism : mappingsAnnotation.value() ) { - Mapping mapping = fromMappingPrism( mappingPrism, method, messager ); + Mapping mapping = fromMappingPrism( mappingPrism, method, messager, typeUtils ); if ( mapping != null ) { List mappingsOfProperty = mappings.get( mappingPrism.target() ); if ( mappingsOfProperty == null ) { @@ -97,7 +97,7 @@ public static Map> fromMappingsPrism(MappingsPrism mapping } public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElement element, - FormattingMessager messager) { + FormattingMessager messager, Types typeUtils) { if ( mappingPrism.target().isEmpty() ) { messager.printMessage( @@ -152,7 +152,9 @@ else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultV SelectionParameters selectionParams = new SelectionParameters( mappingPrism.qualifiedBy(), mappingPrism.qualifiedByName(), - resultTypeIsDefined ? mappingPrism.resultType() : null); + resultTypeIsDefined ? mappingPrism.resultType() : null, + typeUtils + ); return new Mapping( source, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 5ae250ecfc..91cc151064 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -395,7 +395,7 @@ public Boolean visitWildcard(WildcardType t, TypeMirror p) { */ private TypeParameterElement getTypeParamFromCandidate(TypeMirror t) { for ( TypeParameterElement candidateTypeParam : candidateMethod.getExecutable().getTypeParameters() ) { - if ( candidateTypeParam.asType().equals( t ) ) { + if ( typeUtils.isSameType( candidateTypeParam.asType(), t ) ) { return candidateTypeParam; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index f14869903a..9c3aa84c35 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -20,6 +20,7 @@ import java.util.List; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; /** * Holding parameters common to the selection process, common to IterableMapping, BeanMapping, PropertyMapping and @@ -32,11 +33,14 @@ public class SelectionParameters { private final List qualifiers; private final List qualifyingNames; private final TypeMirror resultType; + private final Types typeUtils; - public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType ) { + public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, + Types typeUtils) { this.qualifiers = qualifiers; this.qualifyingNames = qualifyingNames; this.resultType = resultType; + this.typeUtils = typeUtils; } /** @@ -67,9 +71,8 @@ public TypeMirror getResultType() { @Override public int hashCode() { int hash = 3; - hash = 97 * hash + (this.qualifiers != null ? this.qualifiers.hashCode() : 0); hash = 97 * hash + (this.qualifyingNames != null ? this.qualifyingNames.hashCode() : 0); - hash = 97 * hash + (this.resultType != null ? this.resultType.hashCode() : 0); + hash = 97 * hash + (this.resultType != null ? this.resultType.toString().hashCode() : 0); return hash; } @@ -105,4 +108,29 @@ private boolean equals(Object object1, Object object2) { return object1.equals( object2 ); } } + + private boolean equals(List mirrors1, List mirrors2) { + if ( mirrors1 == null ) { + return (mirrors2 == null); + } + else if ( mirrors2 == null || mirrors1.size() != mirrors2.size() ) { + return false; + } + + for ( int i = 0; i < mirrors1.size(); i++ ) { + if ( !equals( mirrors1.get( i ), mirrors2.get( i ) ) ) { + return false; + } + } + return true; + } + + private boolean equals(TypeMirror mirror1, TypeMirror mirror2) { + if ( mirror1 == null ) { + return (mirror2 == null); + } + else { + return mirror2 != null && typeUtils.isSameType( mirror1, mirror2 ); + } + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 59772cd462..d434aa41b6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -254,11 +254,13 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, IterableMapping.fromPrism( IterableMappingPrism.getInstanceOn( method ), method, - messager ) ) + messager, + typeUtils + ) ) .setMapMapping( - MapMapping.fromPrism( MapMappingPrism.getInstanceOn( method ), method, messager ) ) + MapMapping.fromPrism( MapMappingPrism.getInstanceOn( method ), method, messager, typeUtils ) ) .setBeanMapping( - BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager ) ) + BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager, typeUtils ) ) .setValueMappings( getValueMappings( method ) ) .setTypeUtils( typeUtils ) .setMessager( messager ) @@ -510,14 +512,14 @@ private Map> getMappings(ExecutableElement method) { if ( !mappings.containsKey( mappingAnnotation.target() ) ) { mappings.put( mappingAnnotation.target(), new ArrayList() ); } - Mapping mapping = Mapping.fromMappingPrism( mappingAnnotation, method, messager ); + Mapping mapping = Mapping.fromMappingPrism( mappingAnnotation, method, messager, typeUtils ); if ( mapping != null ) { mappings.get( mappingAnnotation.target() ).add( mapping ); } } if ( mappingsAnnotation != null ) { - mappings.putAll( Mapping.fromMappingsPrism( mappingsAnnotation, method, messager ) ); + mappings.putAll( Mapping.fromMappingsPrism( mappingsAnnotation, method, messager, typeUtils ) ); } return mappings; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java new file mode 100644 index 0000000000..b5ff2a7f44 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java @@ -0,0 +1,389 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.ArrayType; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.ExecutableType; +import javax.lang.model.type.NoType; +import javax.lang.model.type.NullType; +import javax.lang.model.type.PrimitiveType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVisitor; +import javax.lang.model.type.WildcardType; +import javax.lang.model.util.Types; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +public class SelectionParametersTest { + + private static class TestTypeMirror implements TypeMirror { + + private final String name; + + private TestTypeMirror(String name) { + this.name = name; + } + + @Override + public TypeKind getKind() { + return null; + } + + @Override + public R accept(TypeVisitor v, P p) { + return null; + } + + @Override + public List getAnnotationMirrors() { + return null; + } + + @Override + public A getAnnotation(Class annotationType) { + return null; + } + + @Override + public A[] getAnnotationsByType(Class annotationType) { + return null; + } + + @Override + public String toString() { + return name; + } + } + + private final Types typeUtils = new Types() { + @Override + public Element asElement(TypeMirror t) { + throw new UnsupportedOperationException( "asElement is not supported" ); + } + + @Override + public boolean isSameType(TypeMirror t1, TypeMirror t2) { + return t1.toString().equals( t2.toString() ); + } + + @Override + public boolean isSubtype(TypeMirror t1, TypeMirror t2) { + throw new UnsupportedOperationException( "isSubType is not supported" ); + } + + @Override + public boolean isAssignable(TypeMirror t1, TypeMirror t2) { + throw new UnsupportedOperationException( "isAssignable is not supported" ); + } + + @Override + public boolean contains(TypeMirror t1, TypeMirror t2) { + throw new UnsupportedOperationException( "contains is not supported" ); + } + + @Override + public boolean isSubsignature(ExecutableType m1, ExecutableType m2) { + throw new UnsupportedOperationException( "isSubSignature is not supported" ); + } + + @Override + public List directSupertypes(TypeMirror t) { + throw new UnsupportedOperationException( "directSupertypes is not supported" ); + } + + @Override + public TypeMirror erasure(TypeMirror t) { + throw new UnsupportedOperationException( "erasure is not supported" ); + } + + @Override + public TypeElement boxedClass(PrimitiveType p) { + throw new UnsupportedOperationException( "boxedClass is not supported" ); + } + + @Override + public PrimitiveType unboxedType(TypeMirror t) { + throw new UnsupportedOperationException( "unboxedType is not supported" ); + } + + @Override + public TypeMirror capture(TypeMirror t) { + throw new UnsupportedOperationException( "capture is not supported" ); + } + + @Override + public PrimitiveType getPrimitiveType(TypeKind kind) { + throw new UnsupportedOperationException( "getPrimitiveType is not supported" ); + } + + @Override + public NullType getNullType() { + throw new UnsupportedOperationException( "nullType is not supported" ); + } + + @Override + public NoType getNoType(TypeKind kind) { + throw new UnsupportedOperationException( "noType is not supported" ); + } + + @Override + public ArrayType getArrayType(TypeMirror componentType) { + throw new UnsupportedOperationException( "getArrayType is not supported" ); + } + + @Override + public WildcardType getWildcardType(TypeMirror extendsBound, TypeMirror superBound) { + throw new UnsupportedOperationException( "getWildCardType is not supported" ); + } + + @Override + public DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) { + throw new UnsupportedOperationException( "getDeclaredType is not supported" ); + } + + @Override + public DeclaredType getDeclaredType(DeclaredType containing, TypeElement typeElem, TypeMirror... typeArgs) { + throw new UnsupportedOperationException( "getDeclaredType is not supported" ); + } + + @Override + public TypeMirror asMemberOf(DeclaredType containing, Element element) { + throw new UnsupportedOperationException( "asMemberOf is not supported" ); + } + }; + + @Test + public void testGetters() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + assertThat( params.getResultType() ).isSameAs( resultType ); + assertThat( params.getQualifiers() ).hasSameElementsAs( qualifiers ); + assertThat( params.getQualifyingNames() ).hasSameElementsAs( qualifyingNames ); + } + + @Test + public void testHashCode() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + SelectionParameters params = new SelectionParameters( null, qualifyingNames, resultType, null ); + + int expectedHash = 3 * 97 + qualifyingNames.hashCode(); + expectedHash = 97 * expectedHash + "resultType".hashCode(); + assertThat( params.hashCode() ).as( "Expected HashCode" ).isEqualTo( expectedHash ); + } + + @Test + public void testHashCodeWithAllNulls() { + SelectionParameters params = new SelectionParameters( null, null, null, null ); + + assertThat( params.hashCode() ).as( "All nulls hashCode" ).isEqualTo( 3 * 97 * 97 ); + } + + @Test + public void testHashCodeWithNullQualifyingNames() { + TypeMirror resultType = new TestTypeMirror( "someType" ); + SelectionParameters params = new SelectionParameters( null, null, resultType, null ); + + assertThat( params.hashCode() ) + .as( "QualifyingNames null hashCode" ) + .isEqualTo( 3 * 97 * 97 + "someType".hashCode() ); + } + + @Test + public void testHashCodeWithNullResultType() { + List qualifyingNames = Collections.singletonList( "mapstruct" ); + SelectionParameters params = new SelectionParameters( null, qualifyingNames, null, null ); + + assertThat( params.hashCode() ) + .as( "ResultType nulls hashCode" ) + .isEqualTo( ( 3 * 97 + qualifyingNames.hashCode() ) * 97 ); + } + + @Test + public void testEqualsSameInstance() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + assertThat( params.equals( params ) ).as( "Self equals" ).isTrue(); + } + + @Test + public void testEqualsWitNull() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + assertThat( params.equals( null ) ).as( "Equals with null" ).isFalse(); + } + + @Test + public void testEqualsQualifiersOneNull() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + SelectionParameters params2 = new SelectionParameters( null, qualifyingNames, resultType, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Second null qualifiers" ).isFalse(); + assertThat( params2.equals( params ) ).as( "First null qualifiers" ).isFalse(); + } + + @Test + public void testEqualsQualifiersInDifferentOrder() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames, resultType, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Different order for qualifiers" ).isFalse(); + assertThat( params2.equals( params ) ).as( "Different order for qualifiers" ).isFalse(); + } + + @Test + public void testEqualsQualifyingNamesOneNull() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, null, resultType, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Second null qualifyingNames" ).isFalse(); + assertThat( params2.equals( params ) ).as( "First null qualifyingNames" ).isFalse(); + } + + @Test + public void testEqualsQualifyingNamesInDifferentOrder() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifyingNames2 = Arrays.asList( "german", "language" ); + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Different order for qualifyingNames" ).isFalse(); + assertThat( params2.equals( params ) ).as( "Different order for qualifyingNames" ).isFalse(); + } + + @Test + public void testEqualsResultTypeOneNull() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifyingNames2 = Arrays.asList( "language", "german" ); + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, null, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Second null resultType" ).isFalse(); + assertThat( params2.equals( params ) ).as( "First null resultType" ).isFalse(); + } + + @Test + public void testAllEqual() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifyingNames2 = Arrays.asList( "language", "german" ); + TypeMirror resultType2 = new TestTypeMirror( "resultType" ); + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType2, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "All equal" ).isTrue(); + assertThat( params2.equals( params ) ).as( "All equal" ).isTrue(); + } + + @Test + public void testDifferentResultTypes() { + List qualifyingNames = Arrays.asList( "language", "german" ); + TypeMirror resultType = new TestTypeMirror( "resultType" ); + List qualifiers = new ArrayList(); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); + + List qualifyingNames2 = Arrays.asList( "language", "german" ); + TypeMirror resultType2 = new TestTypeMirror( "otherResultType" ); + List qualifiers2 = new ArrayList(); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); + qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); + SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType2, typeUtils ); + + assertThat( params.equals( params2 ) ).as( "Different resultType" ).isFalse(); + assertThat( params2.equals( params ) ).as( "Different resultType" ).isFalse(); + } +} From 2acaffa3ec4c0658adb912aad4391fda11fee14b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 30 May 2017 22:32:27 +0200 Subject: [PATCH 0109/1006] #1129 Add forbidden apis plugin to fail on illegal TypeMirror usages --- etc/forbidden-apis.txt | 4 ++++ parent/pom.xml | 11 +++++++++++ processor/pom.xml | 11 +++++++++++ 3 files changed, 26 insertions(+) create mode 100644 etc/forbidden-apis.txt diff --git a/etc/forbidden-apis.txt b/etc/forbidden-apis.txt new file mode 100644 index 0000000000..b0e7d62039 --- /dev/null +++ b/etc/forbidden-apis.txt @@ -0,0 +1,4 @@ + +@defaultMessage TypeMirror equals and hashCode are not stable. Types.isSameType(TypeMirror, TypeMirror) should be used +javax.lang.model.type.TypeMirror#hashCode() +javax.lang.model.type.TypeMirror#equals(java.lang.Object) diff --git a/parent/pom.xml b/parent/pom.xml index 531714a9ff..d186839760 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -506,6 +506,16 @@ properties-maven-plugin 1.0-alpha-2
    + + de.thetaphi + forbiddenapis + 2.3 + + + ${project.basedir}/../etc/forbidden-apis.txt + + + @@ -525,6 +535,7 @@ **/mapstruct.xml **/toolchains-*.xml **/eclipse-formatter-config.xml + **/forbidden-apis.txt **/checkstyle-for-generated-sources.xml **/nb-configuration.xml maven-settings.xml diff --git a/processor/pom.xml b/processor/pom.xml index 30594a6e6c..06d88925ca 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -319,6 +319,17 @@ + + de.thetaphi + forbiddenapis + + + + check + + + + From b3e7c5207666f8ec43ad7d973ea774492b83fc25 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 30 May 2017 23:27:40 +0200 Subject: [PATCH 0110/1006] [maven-release-plugin] prepare release 1.2.0.Beta3 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..89be958519 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..cfd78b6347 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 171f5b0765..1692ea1dc4 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ae7ca0e79b..8b21005201 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..ad728d61e4 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..a719324be8 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..fb3e4131b7 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index d186839760..1226eb1a49 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta3 diff --git a/pom.xml b/pom.xml index 63b61ce435..788e91d27c 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Beta3 diff --git a/processor/pom.xml b/processor/pom.xml index 06d88925ca..2a69507c5a 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Beta3 ../parent/pom.xml From 0d66618d45a8337a37b7bfe16b54535aadd89cef Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 30 May 2017 23:27:41 +0200 Subject: [PATCH 0111/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 89be958519..f857058844 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index cfd78b6347..d5555f9220 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 1692ea1dc4..171f5b0765 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8b21005201..ae7ca0e79b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index ad728d61e4..b2dcceaefa 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index a719324be8..e24f75f1f6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index fb3e4131b7..0b8fb827cf 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 1226eb1a49..d186839760 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta3 + HEAD diff --git a/pom.xml b/pom.xml index 788e91d27c..63b61ce435 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Beta3 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 2a69507c5a..06d88925ca 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Beta3 + 1.2.0-SNAPSHOT ../parent/pom.xml From e6d5831aa7f43f53daf3e48e6ec12cb469f3ab8d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Jun 2017 12:35:56 +0200 Subject: [PATCH 0112/1006] #1227 Make sure that only types belonging to java.lang are not imported --- .../ap/internal/model/GeneratedType.java | 4 +- .../ap/test/bugs/_1227/Issue1227Mapper.java | 32 +++++++++++++++ .../ap/test/bugs/_1227/Issue1227Test.java | 41 +++++++++++++++++++ .../ap/test/bugs/_1227/ThreadDto.java | 35 ++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index c9eb107d69..98d499ef87 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -235,7 +235,9 @@ private boolean needsImportDeclaration(Type typeToAdd) { } if ( typeToAdd.getPackageName() != null ) { - if ( typeToAdd.getPackageName().startsWith( JAVA_LANG_PACKAGE ) ) { + if ( typeToAdd.getPackageName().equals( JAVA_LANG_PACKAGE ) ) { + // only the types in the java.lang package are implicitly imported, the packages under java.lang + // like java.lang.management are not. return false; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java new file mode 100644 index 0000000000..443cf12f1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1227; + +import java.lang.management.ThreadInfo; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1227Mapper { + + ThreadDto map(ThreadInfo source, String s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java new file mode 100644 index 0000000000..cf9231a71e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1227; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1227") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1227Mapper.class, + ThreadDto.class +}) +public class Issue1227Test { + + @Test + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java new file mode 100644 index 0000000000..f503f3c112 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1227; + +/** + * @author Filip Hrisafov + */ +public class ThreadDto { + + private String threadName; + + public String getThreadName() { + return threadName; + } + + public void setThreadName(String threadName) { + this.threadName = threadName; + } +} From 89d7463c934a8ed63415f3ee847376632c3f5637 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 5 Jun 2017 16:19:14 +0200 Subject: [PATCH 0113/1006] #1219 Mention ability to turn of automatic sub-mapping generation in documentation --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 68f95a4df2..aaa2752701 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -820,6 +820,11 @@ When generating the implementation of a mapping method, MapStruct will apply the * If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes * If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. +[NOTE] +==== +In order to stop MapStruct from generating automatic sub-mapping methods, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. +==== + include::controlling-nested-bean-mappings.asciidoc[] [[invoking-other-mappers]] From b5b0c04313355932aa6f53d8b66cad659e2328cc Mon Sep 17 00:00:00 2001 From: Cornelius Date: Thu, 29 Jun 2017 00:01:49 +0200 Subject: [PATCH 0114/1006] #1170 Fix wildcards in collection adder mappings --- .../tests/FullFeatureCompilationTest.java | 1 + .../model/assignment/AdderWrapper.java | 2 +- .../ap/internal/model/common/Type.java | 10 +- .../model/assignment/AdderWrapper.ftl | 2 +- .../bugs/_1170/AdderSourceTargetMapper.java | 40 ++++++ .../ap/test/bugs/_1170/AdderTest.java | 85 +++++++++++++ .../ap/test/bugs/_1170/PetMapper.java | 89 +++++++++++++ .../ap/test/bugs/_1170/_target/Target.java | 120 ++++++++++++++++++ .../ap/test/bugs/_1170/source/Source.java | 120 ++++++++++++++++++ 9 files changed, 463 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java index c89461deed..f53b673d90 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java @@ -69,6 +69,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorType proces switch ( processorType ) { case ORACLE_JAVA_6: additionalExcludes.add( "org/mapstruct/ap/test/abstractclass/generics/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1170/*.java" ); case ECLIPSE_JDT_JAVA_6: case ORACLE_JAVA_7: case ECLIPSE_JDT_JAVA_7: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 723ed044da..b41aa683ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -63,7 +63,7 @@ public List getThrownTypes() { public Set getImportTypes() { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); - imported.add( getSourceType().getTypeParameters().get( 0 ) ); + imported.add( getSourceType().getTypeParameters().get( 0 ).getTypeBound() ); return imported; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 4a3350461f..6fd311338c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -375,14 +375,16 @@ public Type erasure() { * * @return {@code true} if and only if this type is assignable to the given other type. */ - // TODO This doesn't yet take wild card types into account; e.g. ? extends Integer wouldn't be assignable to Number - // atm. + // TODO This doesn't yet take super wild card types into account; + // e.g. Number wouldn't be assignable to ? super Number atm. (is there any practical use case) public boolean isAssignableTo(Type other) { if ( equals( other ) ) { return true; } - return typeUtils.isAssignable( typeMirror, other.typeMirror ); + TypeMirror typeMirrorToMatch = isWildCardExtendsBound() ? getTypeBound().typeMirror : typeMirror; + + return typeUtils.isAssignable( typeMirrorToMatch, other.typeMirror ); } /** @@ -560,7 +562,7 @@ private Accessor getAdderForType(Type collectionProperty, String pluralPropertyN // this is a collection, so this can be done always if ( !collectionProperty.getTypeParameters().isEmpty() ) { // there's only one type arg to a collection - TypeMirror typeArg = collectionProperty.getTypeParameters().get( 0 ).getTypeMirror(); + TypeMirror typeArg = collectionProperty.getTypeParameters().get( 0 ).getTypeBound().getTypeMirror(); // now, look for a method that // 1) starts with add, // 2) and has typeArg as one and only arg diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index a3a781aabd..c039f459cb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -22,7 +22,7 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> if ( ${sourceReference} != null ) { - for ( <@includeModel object=sourceType.typeParameters[0]/> ${sourceLocalVarName} : ${sourceReference} ) { + for ( <@includeModel object=sourceType.typeParameters[0].typeBound/> ${sourceLocalVarName} : ${sourceReference} ) { ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java new file mode 100644 index 0000000000..a966299759 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1170; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._1170._target.Target; +import org.mapstruct.ap.test.bugs._1170.source.Source; +import org.mapstruct.factory.Mappers; + +/** + * @author Cornelius Dirmeier + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED, + uses = { PetMapper.class }) +public interface AdderSourceTargetMapper { + + AdderSourceTargetMapper INSTANCE = Mappers.getMapper( AdderSourceTargetMapper.class ); + + Target toTarget(Source source); + + Source toSource(Target source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java new file mode 100644 index 0000000000..90b19f92e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java @@ -0,0 +1,85 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1170; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._1170._target.Target; +import org.mapstruct.ap.test.bugs._1170.source.Source; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Cornelius Dirmeier + */ +@WithClasses({ + Source.class, + Target.class, + AdderSourceTargetMapper.class, + PetMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class AdderTest { + + @IssueKey("1170") + @Test + public void testWildcardAdder() { + Source source = new Source(); + source.addWithoutWildcard( "mouse" ); + source.addWildcardInTarget( "mouse" ); + source.addWildcardInSource( "mouse" ); + source.addWildcardInBoth( "mouse" ); + source.addWildcardAdderToSetter( "mouse" ); + + Target target = AdderSourceTargetMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getWithoutWildcards() ).containsExactly( 2L ); + assertThat( target.getWildcardInSources() ).containsExactly( 2L ); + assertThat( target.getWildcardInTargets() ).containsExactly( 2L ); + assertThat( target.getWildcardInBoths() ).containsExactly( 2L ); + assertThat( target.getWildcardAdderToSetters() ).containsExactly( 2L ); + } + + @IssueKey("1170") + @Test + public void testWildcardAdderTargetToSource() { + Target target = new Target(); + target.addWithoutWildcard( 2L ); + target.addWildcardInTarget( 2L ); + target.getWildcardInSources().add( 2L ); + target.addWildcardInBoth( 2L ); + target.setWildcardAdderToSetters( Arrays.asList( 2L ) ); + + Source source = AdderSourceTargetMapper.INSTANCE.toSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getWithoutWildcards() ).containsExactly( "mouse" ); + assertThat( source.getWildcardInSources() ).containsExactly( "mouse" ); + assertThat( source.getWildcardInTargets() ).containsExactly( "mouse" ); + assertThat( source.getWildcardInBoths() ).containsExactly( "mouse" ); + assertThat( source.getWildcardAdderToSetters() ).containsExactly( "mouse" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java new file mode 100644 index 0000000000..847ec04245 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java @@ -0,0 +1,89 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1170; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.mapstruct.Mapper; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Cornelius Dirmeier + */ +@Mapper +public class PetMapper { + + private static final Map PETS_TO_TARGET = ImmutableMap.builder() + .put( "rabbit", 1L ) + .put( "mouse", 2L ).build(); + + private static final Map PETS_TO_SOURCE = ImmutableMap.builder() + .put( 1L, "rabbit" ) + .put( 2L, "mouse" ) + .put( 3L, "cat" ) + .put( 4L, "dog" ).build(); + + + /** + * method to be used when using an adder + * + * @param pet + * + * @return + * + * @throws DogException + */ + public Long toPet(String pet) { + return PETS_TO_TARGET.get( pet ); + } + + public String toSourcePets(Long pet) { + return PETS_TO_SOURCE.get( pet ); + } + + /** + * Method to be used when not using an adder + * + * @param pets + * + * @return + * + * @throws CatException + * @throws DogException + */ + public List toPets(List pets) { + List result = new ArrayList(); + for ( String pet : pets ) { + result.add( toPet( pet ) ); + } + return result; + } + + public List toSourcePets(List pets) { + List result = new ArrayList(); + for ( Long pet : pets ) { + result.add( PETS_TO_SOURCE.get( pet ) ); + } + return result; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java new file mode 100644 index 0000000000..4e57ce7ff5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java @@ -0,0 +1,120 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1170._target; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Cornelius Dirmeier + */ +public class Target { + + private List withoutWildcards = new ArrayList(); + + private List wildcardInSources = new ArrayList(); + + private List wildcardInTargets = new ArrayList(); + + private List wildcardInBoths = new ArrayList(); + + private List wildcardAdderToSetters = new ArrayList(); + + private List wildcardInSourcesAddAll = new ArrayList(); + + private List sameTypeWildcardInSources = new ArrayList(); + + private List sameTypeWildcardInTargets = new ArrayList(); + + private List sameTypeWildcardInBoths = new ArrayList(); + + public List getWithoutWildcards() { + return withoutWildcards; + } + + public Long addWithoutWildcard(Long pet) { + withoutWildcards.add( pet ); + return pet; + } + + public List getWildcardInSources() { + return wildcardInSources; + } + + public Long addWildcardInSource(Long pet) { + wildcardInSources.add( pet ); + return pet; + } + + public List getWildcardInTargets() { + return wildcardInTargets; + } + + public Long addWildcardInTarget(Long pet) { + wildcardInTargets.add( pet ); + return pet; + } + + public List getWildcardInBoths() { + return wildcardInTargets; + } + + public Long addWildcardInBoth(Long pet) { + wildcardInBoths.add( pet ); + return pet; + } + + public List getWildcardAdderToSetters() { + return wildcardAdderToSetters; + } + + public void setWildcardAdderToSetters(List pets) { + wildcardAdderToSetters = pets; + } + + public List getWildcardInSourcesAddAll() { + return wildcardInSourcesAddAll; + } + + public List getSameTypeWildcardInSources() { + return sameTypeWildcardInSources; + } + + public void addSameTypeWildcardInSource(BigDecimal pet) { + sameTypeWildcardInSources.add( pet ); + } + + public List getSameTypeWildcardInTargets() { + return sameTypeWildcardInTargets; + } + + public void addSameTypeWildcardInTarget(BigDecimal pet) { + sameTypeWildcardInTargets.add( pet ); + } + + public List getSameTypeWildcardInBoths() { + return sameTypeWildcardInBoths; + } + + public void addSameTypeWildcardInBoth(BigDecimal pet) { + sameTypeWildcardInBoths.add( pet ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java new file mode 100644 index 0000000000..07c5d671bc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java @@ -0,0 +1,120 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1170.source; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Cornelius Dirmeier + */ +public class Source { + + private List withoutWildcards = new ArrayList(); + + private List wildcardInSources = new ArrayList(); + + private List wildcardInTargets = new ArrayList(); + + private List wildcardInBoths = new ArrayList(); + + private List wildcardInSourcesAddAll = new ArrayList(); + + private List wildcardAdderToSetters = new ArrayList(); + + private List sameTypeWildcardInSources = new ArrayList(); + + private List sameTypeWildcardInTargets = new ArrayList(); + + private List sameTypeWildcardInBoths = new ArrayList(); + + public List getWithoutWildcards() { + return withoutWildcards; + } + + public void addWithoutWildcard(String pet) { + this.withoutWildcards.add( pet ); + } + + public List getWildcardInSources() { + return wildcardInSources; + } + + public void addWildcardInSource(String pet) { + wildcardInSources.add( pet ); + } + + public List getWildcardInTargets() { + return wildcardInTargets; + } + + public void addWildcardInTarget(String pet) { + wildcardInTargets.add( pet ); + } + + public List getWildcardInBoths() { + return wildcardInBoths; + } + + public void addWildcardInBoth(String pet) { + wildcardInBoths.add( pet ); + } + + public List getWildcardInSourcesAddAll() { + return wildcardInSourcesAddAll; + } + + public void addWildcardInSourcesAddAll(String pet) { + wildcardInSourcesAddAll.add( pet ); + } + + public List getWildcardAdderToSetters() { + return wildcardAdderToSetters; + } + + public void addWildcardAdderToSetter(String pet) { + wildcardAdderToSetters.add( pet ); + } + + public List getSameTypeWildcardInSources() { + return sameTypeWildcardInSources; + } + + public void addSameTypeWildcardInSource(BigDecimal pet) { + sameTypeWildcardInSources.add( pet ); + } + + public List getSameTypeWildcardInTargets() { + return sameTypeWildcardInTargets; + } + + public void addSameTypeWildcardInTarget(BigDecimal pet) { + sameTypeWildcardInTargets.add( pet ); + } + + public List getSameTypeWildcardInBoths() { + return sameTypeWildcardInBoths; + } + + public void addSameTypeWildcardInBoth(BigDecimal pet) { + sameTypeWildcardInBoths.add( pet ); + } + +} From a3eca8c8caf17905246e5ed5e4e0ddf32afe8e5a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2017 00:05:05 +0200 Subject: [PATCH 0115/1006] #1170 Adding Cornelius Dirmeier to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index d37d89bfe0..45002816f0 100644 --- a/copyright.txt +++ b/copyright.txt @@ -5,6 +5,7 @@ Andreas Gudian - https://github.com/agudian Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman +Cornelius Dirmeier - https://github.com/cornzy Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil Ewald Volkert - https://github.com/eforest From 7a9464c525443a197a2df7081a9bb544bd8847a1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2017 20:25:42 +0200 Subject: [PATCH 0116/1006] #1150 Improve error reporting for nested properties --- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 4 +++- .../nestedbeans/exclusions/ErroneousJavaInternalTest.java | 8 +++++++- .../mapstruct/ap/test/nestedbeans/exclusions/Source.java | 4 +--- .../mapstruct/ap/test/nestedbeans/exclusions/Target.java | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 51cb0da68c..db7fa579f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -324,7 +324,9 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get */ private void reportCannotCreateMapping() { if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).getHistory() != null ) { - ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory(); + // The history that is part of the ForgedMethod misses the information from the current right hand + // side. Therefore we need to extract the most relevant history and use that in the error reporting. + ForgedMethodHistory history = getForgedMethodHistory( rightHandSide ); reportCannotCreateMapping( method, history.createSourcePropertyErrorMessage(), diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index db2e37e71f..b367dbf57f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -57,7 +57,13 @@ public class ErroneousJavaInternalTest { line = 29, messageRegExp = "Can't map property \".*List<.*MyType> types\" to \".*List<.*String> types\"\\" + ". Consider to declare/implement a mapping method: \".*List<.*String> map\\(.*List<.*MyType> " + - "value\\)\"\\.") + "value\\)\"\\."), + @Diagnostic(type = ErroneousJavaInternalMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = "Can't map property \".*List<.*MyType> nestedMyType\\.deepNestedType\\.types\" to \"" + + ".*List<.*String> nestedMyType\\.deepNestedType\\.types\"\\. Consider to declare/implement a " + + "mapping method: \".*List<.*String> map\\(.*List<.*MyType> value\\)\"\\.") }) @Test public void shouldNotNestIntoJavaPackageObjects() throws Exception { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java index da8e64d32c..adeaba1266 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java @@ -47,8 +47,6 @@ static class MyType { public MyType date; public MyType calendar; public List types; - //TODO Nested error messages do not work yet. I think that this should be solved as part of #1150 - // (or we solve that one first :)) - //public NestedMyType nestedMyType; + public NestedMyType nestedMyType; //CHECKSTYLE:ON } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java index 7ceedbd355..3691541eda 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java @@ -43,6 +43,6 @@ class TargetNested { public Date date; public GregorianCalendar calendar; public List types; - //public TargetNested nestedMyType; + public TargetNested nestedMyType; //CHECKSTYLE:ON } From 324e1fadbed5470f3480dc75547df90a40feafd8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2017 23:04:05 +0200 Subject: [PATCH 0117/1006] #1086 Mention the fact that prototype methods are not considered for automatic sub mapping methods --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index aaa2752701..c98afcda69 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -825,6 +825,12 @@ When generating the implementation of a mapping method, MapStruct will apply the In order to stop MapStruct from generating automatic sub-mapping methods, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. ==== +[NOTE] +==== +During the generation of automatic sub-mapping methods <> will not be taken into consideration, yet. +Follow issue https://github.com/mapstruct/mapstruct/issues/1086[#1086] for more information. +==== + include::controlling-nested-bean-mappings.asciidoc[] [[invoking-other-mappers]] From dc031bf916e59c585f7afd7ff82bfd7a112f7474 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jun 2017 23:15:48 +0200 Subject: [PATCH 0118/1006] #1185 display the specific type for a property for which no write accessor exists or it is unknown --- .../ap/internal/model/source/TargetReference.java | 5 +++-- .../java/org/mapstruct/ap/internal/util/Message.java | 4 ++-- .../org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java | 3 ++- .../org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java | 9 ++++++--- .../attributereference/ErroneousMappingsTest.java | 3 ++- .../org/mapstruct/ap/test/ignore/IgnorePropertyTest.java | 3 ++- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 5e17c7cd1f..ce19c078f7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -367,9 +367,10 @@ private MappingErrorMessage(Mapping mapping, SourceMethod method, FormattingMess abstract void report(); protected void printErrorMessage(Message message, Object... args) { - Object[] errorArgs = new Object[args.length + 1]; + Object[] errorArgs = new Object[args.length + 2]; errorArgs[0] = mapping.getTargetName(); - System.arraycopy( args, 0, errorArgs, 1, args.length ); + errorArgs[1] = method.getResultType(); + System.arraycopy( args, 0, errorArgs, 2, args.length ); messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), message, errorArgs ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 530f6238a1..49edbef593 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -31,8 +31,8 @@ public enum Message { BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), - BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in return type. Did you mean \"%s\"?" ), - BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE( "Property \"%s\" has no write accessor." ), + BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in result type %s. Did you mean \"%s\"?" ), + BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE( "Property \"%s\" has no write accessor in %s." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ), BEANMAPPING_UNMAPPED_TARGETS_WARNING( "Unmapped target %s.", Diagnostic.Kind.WARNING ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index eecf82e1fa..93832bb68e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -46,7 +46,8 @@ public class Issue1029Test { @Diagnostic(kind = Kind.WARNING, line = 50, type = ErroneousIssue1029Mapper.class, messageRegExp = "Unmapped target property: \"lastUpdated\"\\."), @Diagnostic(kind = Kind.ERROR, line = 55, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unknown property \"unknownProp\" in return type\\. Did you mean \"knownProp\"?") + messageRegExp = "Unknown property \"unknownProp\" in result type " + + "org.mapstruct.ap.test.bugs._1029.ErroneousIssue1029Mapper.Deck\\. Did you mean \"knownProp\"?") }) public void reportsProperWarningsAndError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index a2dc85c0f1..e28eeb59b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -40,15 +40,18 @@ public class Issue1153Test { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 32, - messageRegExp = "Property \"readOnly\" has no write accessor\\."), + messageRegExp = "Property \"readOnly\" has no write accessor in " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 33, - messageRegExp = "Property \"nestedTarget.readOnly\" has no write accessor\\."), + messageRegExp = "Property \"nestedTarget.readOnly\" has no write accessor in " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 36, - messageRegExp = "Unknown property \"nestedTarget2.writable2\" in return type\\. " + + messageRegExp = "Unknown property \"nestedTarget2.writable2\" in result type " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\. " + "Did you mean \"nestedTarget2\\.writable\"") }) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index 64e695a436..cc3ea1fb40 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -57,7 +57,8 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 31, - messageRegExp = "Unknown property \"bar\" in return type. Did you mean \"foo\"?"), + messageRegExp = "Unknown property \"bar\" in result type " + + "org.mapstruct.ap.test.erroneous.attributereference.Target. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 33, diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 5be5232410..525d18f7bf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -93,7 +93,8 @@ public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTarget @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, kind = Kind.ERROR, line = 35, - messageRegExp = "Property \"hasClaws\" has no write accessor\\.") + messageRegExp = "Property \"hasClaws\" has no write accessor in " + + "org.mapstruct.ap.test.ignore.PreditorDto\\.") } ) public void shouldGiveErrorOnMappingForReadOnlyProp() { From 82da71199ddc4436e9f2e9be2a58de139a2f3ba9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Jul 2017 20:25:35 +0200 Subject: [PATCH 0119/1006] #543 Make sure that the bound type is imported if the type is wildcard --- .../ap/internal/model/common/Type.java | 4 +- .../ap/internal/model/common/Type.ftl | 1 + .../ap/test/bugs/_543/Issue543Mapper.java | 34 ++++++++++++++ .../ap/test/bugs/_543/Issue543Test.java | 45 +++++++++++++++++++ .../ap/test/bugs/_543/SourceUtil.java | 39 ++++++++++++++++ .../ap/test/bugs/_543/dto/Source.java | 35 +++++++++++++++ .../ap/test/bugs/_543/dto/Target.java | 31 +++++++++++++ 7 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6fd311338c..c668b207f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -309,8 +309,8 @@ public Set getImportTypes() { result.addAll( parameter.getImportTypes() ); } - if ( boundingBase != null ) { - result.addAll( boundingBase.getImportTypes() ); + if ( ( isWildCardExtendsBound() || isWildCardSuperBound() ) && getTypeBound() != null ) { + result.addAll( getTypeBound().getImportTypes() ); } return result; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 1d63cb3201..15fbc47d84 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -1,3 +1,4 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> <#-- diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java new file mode 100644 index 0000000000..798870ced7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._543; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._543.dto.Source; +import org.mapstruct.ap.test.bugs._543.dto.Target; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = { SourceUtil.class }) +public interface Issue543Mapper { + + List map(List source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java new file mode 100644 index 0000000000..a1f43a3791 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._543; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._543.dto.Source; +import org.mapstruct.ap.test.bugs._543.dto.Target; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("543") +@WithClasses({ + Issue543Mapper.class, + Source.class, + SourceUtil.class, + Target.class +}) +public class Issue543Test { + + @Test + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java new file mode 100644 index 0000000000..7c5808fb87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._543; + +import org.mapstruct.ap.test.bugs._543.dto.Source; +import org.mapstruct.ap.test.bugs._543.dto.Target; + +/** + * @author Filip Hrisafov + */ +public class SourceUtil { + + private SourceUtil() { + + } + + public static Target from(Source source) { + if ( source == null ) { + return null; + } + return new Target( source.getString() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java new file mode 100644 index 0000000000..1c6148d5f0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._543.dto; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String string; + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java new file mode 100644 index 0000000000..25a423db9b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._543.dto; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String string; + + public Target(String string) { + this.string = string; + } +} From dfbe8767a57b8bfc8c6772e97999b03d14aa1804 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Thu, 6 Jul 2017 17:08:58 +0200 Subject: [PATCH 0120/1006] #543 Adding assertion to test that the bound type is added to the import statements --- .../java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java index a1f43a3791..2626dd4934 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.bugs._543; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._543.dto.Source; @@ -25,6 +26,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Filip Hrisafov @@ -39,7 +41,11 @@ }) public class Issue543Test { + @Rule + public GeneratedSource generatedSource = new GeneratedSource(); + @Test public void shouldCompile() { + generatedSource.forMapper( Issue543Mapper.class ).containsImportFor( Source.class ); } } From 614f0ea4ee5fd0ece5b6bd5ca77fd4e900a145f4 Mon Sep 17 00:00:00 2001 From: Alexandr Shalugin Date: Thu, 29 Jun 2017 11:22:03 +0300 Subject: [PATCH 0121/1006] =?UTF-8?q?#883=20generated=20variable=20names?= =?UTF-8?q?=20with=20=C4=B1=20instead=20i?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapstruct/ap/internal/util/Strings.java | 5 +- .../ap/internal/util/StringsTest.java | 55 +++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index fa811612af..a4a000cccd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.Locale; import java.util.Set; /** @@ -89,11 +90,11 @@ private Strings() { } public static String capitalize(String string) { - return string == null ? null : string.substring( 0, 1 ).toUpperCase() + string.substring( 1 ); + return string == null ? null : string.substring( 0, 1 ).toUpperCase( Locale.ROOT ) + string.substring( 1 ); } public static String decapitalize(String string) { - return string == null ? null : string.substring( 0, 1 ).toLowerCase() + string.substring( 1 ); + return string == null ? null : string.substring( 0, 1 ).toLowerCase( Locale.ROOT ) + string.substring( 1 ); } public static String join(Iterable iterable, String separator) { diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 12fa47c276..d65202ec4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -22,13 +22,30 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Locale; +import org.junit.After; +import org.junit.Before; import org.junit.Test; /** * @author Filip Hrisafov */ public class StringsTest { + + private static final Locale TURKEY_LOCALE = getTurkeyLocale(); + private Locale defaultLocale; + + @Before + public void before() { + defaultLocale = Locale.getDefault(); + } + + @After + public void after() { + Locale.setDefault( defaultLocale ); + } + @Test public void testCapitalize() throws Exception { assertThat( Strings.capitalize( null ) ).isNull(); @@ -111,4 +128,42 @@ public void findMostSimilarWord() throws Exception { assertThat( mostSimilarWord ).isEqualTo( "fullName" ); } + @Test + public void capitalizeEnglish() { + Locale.setDefault( Locale.ENGLISH ); + String international = Strings.capitalize( "international" ); + assertThat( international ).isEqualTo( "International" ); + } + + @Test + public void decapitalizeEnglish() { + Locale.setDefault( Locale.ENGLISH ); + String international = Strings.decapitalize( "International" ); + assertThat( international ).isEqualTo( "international" ); + } + + @Test + public void capitalizeTurkish() { + Locale.setDefault( TURKEY_LOCALE ); + String international = Strings.capitalize( "international" ); + assertThat( international ).isEqualTo( "International" ); + } + + @Test + public void decapitalizeTurkish() { + Locale.setDefault( TURKEY_LOCALE ); + String international = Strings.decapitalize( "International" ); + assertThat( international ).isEqualTo( "international" ); + } + + private static Locale getTurkeyLocale() { + Locale[] availableLocales = Locale.getAvailableLocales(); + for ( Locale locale : availableLocales ) { + if ( locale.getLanguage().equals( "tr" ) ) { + return locale; + } + } + throw new IllegalStateException( "Can't find Turkey locale." ); + } + } From aae152735258935d9f580edbca3a132e174bec7b Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Fri, 7 Jul 2017 17:52:09 +0200 Subject: [PATCH 0122/1006] #883 Simplifying look-up of test locale --- .../org/mapstruct/ap/internal/util/StringsTest.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index d65202ec4f..3959d6ac17 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -157,13 +157,12 @@ public void decapitalizeTurkish() { } private static Locale getTurkeyLocale() { - Locale[] availableLocales = Locale.getAvailableLocales(); - for ( Locale locale : availableLocales ) { - if ( locale.getLanguage().equals( "tr" ) ) { - return locale; - } + Locale turkeyLocale = Locale.forLanguageTag( "tr" ); + + if ( turkeyLocale == null ) { + throw new IllegalStateException( "Can't find Turkey locale." ); } - throw new IllegalStateException( "Can't find Turkey locale." ); - } + return turkeyLocale; + } } From 3b9584ff13e68dc809ca3502adc20811329255db Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Fri, 7 Jul 2017 18:03:35 +0200 Subject: [PATCH 0123/1006] #883 Adding Alexander to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 45002816f0..e2dcb44016 100644 --- a/copyright.txt +++ b/copyright.txt @@ -1,6 +1,7 @@ Contributors ============ +Alexandr Shalugin - https://github.com/shalugin Andreas Gudian - https://github.com/agudian Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools From 00385a1cdb1fc548b3d1f079577be52adf6ce821 Mon Sep 17 00:00:00 2001 From: Tillerino Date: Fri, 7 Jul 2017 19:03:56 +0200 Subject: [PATCH 0124/1006] #611 Allow nested declaration of Mappers * #611 Allow nested declaration of Mappers Up until now, if a Mapper was declared as a nested interface, say EnclosingClass.NestedMapper, the implementation of the mapper was generated as NestedMapperImpl in the same package. The Mappers factory class then tried to load EnclosingClass$NestedMapperImpl, which would fail. --- .../org/mapstruct/factory/MappersTest.java | 11 +++ .../test/model/SomeClass$FooImpl.java | 33 +++++++++ .../model/SomeClass$NestedClass$FooImpl.java | 33 +++++++++ .../org/mapstruct/test/model/SomeClass.java | 32 +++++++++ .../ap/internal/model/Decorator.java | 2 +- .../mapstruct/ap/internal/model/Mapper.java | 19 ++++- .../ap/test/bugs/_611/Issue611Test.java | 71 +++++++++++++++++++ .../ap/test/bugs/_611/SomeClass.java | 55 ++++++++++++++ .../ap/test/bugs/_611/SomeOtherClass.java | 40 +++++++++++ 9 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java create mode 100644 core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java create mode 100644 core-common/src/test/java/org/mapstruct/test/model/SomeClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java diff --git a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java index 10ce0e8c6e..990907fe0a 100644 --- a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java +++ b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java @@ -22,6 +22,7 @@ import org.junit.Test; import org.mapstruct.test.model.Foo; +import org.mapstruct.test.model.SomeClass; /** * Unit test for {@link Mappers}. @@ -36,4 +37,14 @@ public void shouldReturnImplementationInstance() { Foo mapper = Mappers.getMapper( Foo.class ); assertThat( mapper ).isNotNull(); } + + /** + * Checks if an implementation of a nested mapper can be found. This is a special case since + * it is named + */ + @Test + public void findsNestedMapperImpl() throws Exception { + assertThat( Mappers.getMapper( SomeClass.Foo.class ) ).isNotNull(); + assertThat( Mappers.getMapper( SomeClass.NestedClass.Foo.class ) ).isNotNull(); + } } diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java new file mode 100644 index 0000000000..0e2e0dd181 --- /dev/null +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.test.model; + +/** + * For testing naming of implementations of nested mappers (issue 611). + * + * @author Tillmann Gaida + */ +/* + * Turn off checkstyle since the underscore introduced by issue 611 violates the class naming + * convention. + */ +// CHECKSTYLE:OFF +public class SomeClass$FooImpl implements SomeClass.Foo { + +} diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java new file mode 100644 index 0000000000..27b1fec379 --- /dev/null +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.test.model; + +/** + * For testing naming of implementations of nested mappers (issue 611). + * + * @author Tillmann Gaida + */ +/* + * Turn off checkstyle since the underscore introduced by issue 611 violates the class naming + * convention. + */ +// CHECKSTYLE:OFF +public class SomeClass$NestedClass$FooImpl implements SomeClass.NestedClass.Foo { + +} diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java new file mode 100644 index 0000000000..f8fc1437e0 --- /dev/null +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.test.model; + +/** + * The sole purpose of this class is to have a place to nest the Foo interface. + * + * @author Tillmann Gaida + */ +public class SomeClass { + public interface Foo { } + + public static class NestedClass { + public interface Foo { } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index ecc868d02c..ae67c4ff29 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -111,7 +111,7 @@ public Builder extraImports(SortedSet extraImportedTypes) { public Decorator build() { String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER, - mapperElement.getSimpleName() ); + Mapper.getFlatName( mapperElement ) ); Type decoratorType = typeFactory.getType( decoratorPrism.value() ); DecoratorConstructor decoratorConstructor = new DecoratorConstructor( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index f89ef45a96..efe8e49d01 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.SortedSet; +import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; @@ -153,7 +154,7 @@ public Builder implPackage(String implPackage) { } public Mapper build() { - String implementationName = implName.replace( CLASS_NAME_PLACEHOLDER, element.getSimpleName() ) + + String implementationName = implName.replace( CLASS_NAME_PLACEHOLDER, getFlatName( element ) ) + ( decorator == null ? "" : "_" ); String elementPackage = elementUtils.getPackageOf( element ).getQualifiedName().toString(); @@ -199,4 +200,20 @@ public boolean hasCustomImplementation() { protected String getTemplateName() { return getTemplateNameForClass( GeneratedType.class ); } + + /** + * Returns the same as {@link Class#getName()} but without the package declaration. + */ + public static String getFlatName(TypeElement element) { + if (!(element.getEnclosingElement() instanceof TypeElement)) { + return element.getSimpleName().toString(); + } + StringBuilder nameBuilder = new StringBuilder( element.getSimpleName().toString() ); + for (Element enclosing = element.getEnclosingElement(); enclosing instanceof TypeElement; enclosing = + enclosing.getEnclosingElement()) { + nameBuilder.insert( 0, '$' ); + nameBuilder.insert( 0, enclosing.getSimpleName().toString() ); + } + return nameBuilder.toString(); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java new file mode 100644 index 0000000000..f8e96ec75d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java @@ -0,0 +1,71 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._611; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Tillmann Gaida + */ +@IssueKey("611") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + SomeClass.class, + SomeOtherClass.class +}) +public class Issue611Test { + /** + * Checks if an implementation of a nested mapper can be loaded at all. + */ + @Test + public void mapperIsFound() { + assertThat( SomeClass.InnerMapper.INSTANCE ).isNotNull(); + } + + /** + * Checks if an implementation of a nested mapper can be loaded which is nested into an already + * nested class. + */ + @Test + public void mapperNestedInsideNestedClassIsFound() { + assertThat( SomeClass.SomeInnerClass.InnerMapper.INSTANCE ).isNotNull(); + } + + /** + * Checks if it is possible to load two mapper implementations which have equal simple names + * in the same package. + */ + @Test + public void rightMapperIsFound() { + SomeClass.InnerMapper.Source source1 = new SomeClass.InnerMapper.Source(); + SomeOtherClass.InnerMapper.Source source2 = new SomeOtherClass.InnerMapper.Source(); + + SomeClass.InnerMapper.Target target1 = SomeClass.InnerMapper.INSTANCE.toTarget( source1 ); + SomeOtherClass.InnerMapper.Target target2 = SomeOtherClass.InnerMapper.INSTANCE.toTarget( source2 ); + + assertThat( target1 ).isExactlyInstanceOf( SomeClass.InnerMapper.Target.class ); + assertThat( target2 ).isExactlyInstanceOf( SomeOtherClass.InnerMapper.Target.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java new file mode 100644 index 0000000000..ea9bd23f9f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._611; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Tillmann Gaida + */ +public class SomeClass { + @Mapper + public interface InnerMapper { + InnerMapper INSTANCE = Mappers.getMapper( InnerMapper.class ); + + Target toTarget(Source in); + + class Source { + } + + class Target { + } + } + + public static class SomeInnerClass { + @Mapper + public interface InnerMapper { + InnerMapper INSTANCE = Mappers.getMapper( InnerMapper.class ); + + Target toTarget(Source in); + + class Source { + } + + class Target { + } + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java new file mode 100644 index 0000000000..aa0c560027 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._611; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Tillmann Gaida + */ +public class SomeOtherClass { + @Mapper + public interface InnerMapper { + InnerMapper INSTANCE = Mappers.getMapper( InnerMapper.class ); + + Target toTarget(Source in); + + class Source { + } + + class Target { + } + } +} From c983b6d1e4bea45adb116b3b181d501368b69126 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 7 Jul 2017 19:06:28 +0200 Subject: [PATCH 0125/1006] Adding Tillerino to copyright.txt --- copyright.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copyright.txt b/copyright.txt index e2dcb44016..3ad9a03341 100644 --- a/copyright.txt +++ b/copyright.txt @@ -13,7 +13,6 @@ Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla -Markus Heberling - https://github.com/tisoft Michael Pardo - https://github.com/pardom Mustafa Caylak - https://github.com/luxmeter Oliver Ehrenmüller - https://github.com/greuelpirat @@ -28,6 +27,7 @@ Sebastian Hasait - https://github.com/shasait Sean Huang - https://github.com/seanjob Sjaak Derksen - https://github.com/sjaakd Stefan May - https://github.com/osthus-sm +Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld Vincent Alexander Beelte - https://github.com/grandmasterpixel From ca0721d931b1a02dc22ed7bddf3240c5842a22fd Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sat, 8 Jul 2017 15:24:39 +0200 Subject: [PATCH 0126/1006] #1224 Adding Automatic-Module-Name headers to mapstruct, mapstruct-jdk8 and mapstruct-processor JARs --- core-jdk8/pom.xml | 5 +++++ core/pom.xml | 5 +++++ processor/pom.xml | 3 +++ 3 files changed, 13 insertions(+) diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 171f5b0765..6d26c56ee5 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -152,6 +152,11 @@ org.apache.felix maven-bundle-plugin + + + org.mapstruct + + maven-jar-plugin diff --git a/core/pom.xml b/core/pom.xml index ae7ca0e79b..c7718ea5f7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -143,6 +143,11 @@ org.apache.felix maven-bundle-plugin + + + org.mapstruct + + maven-jar-plugin diff --git a/processor/pom.xml b/processor/pom.xml index 06d88925ca..a45ec6a9de 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -137,6 +137,9 @@ true + + org.mapstruct.processor + From acdab556040f3b4fa67ef582076ccdb054b642bf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 9 Jul 2017 10:19:38 +0200 Subject: [PATCH 0127/1006] #1196 Use dedicated property name for the jacoco argument line and have an empty property in order to work with Netbeans --- processor/pom.xml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/processor/pom.xml b/processor/pom.xml index a45ec6a9de..ab7ae83a7c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -35,6 +35,9 @@ ${project.build.directory}/generated-sources/prims + + @@ -149,7 +152,9 @@ - @{argLine} -Xms1024m -Xmx3072m + + @{jacocoArgLine} -Xms1024m -Xmx3072m @@ -308,6 +313,9 @@ + + jacocoArgLine + org.apache.maven.plugins From 3ebd09eec935ad3ad0caf96a0b458c086fb6cf1e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 10 Jul 2017 20:37:09 +0200 Subject: [PATCH 0128/1006] #1244 Fix problems with special word for FreeMarker in some cases --- .../ap/internal/model/BeanMappingMethod.java | 5 +- .../ap/internal/model/common/Parameter.java | 3 +- .../ap/internal/model/BeanMappingMethod.ftl | 10 ++-- .../ap/test/bugs/_1244/Issue1244Test.java | 46 +++++++++++++++ .../ap/test/bugs/_1244/SizeMapper.java | 58 +++++++++++++++++++ .../ap/test/bugs/_909/ValuesMapper.java | 4 ++ 6 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1b05739100..484b93b40e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -760,8 +760,9 @@ public List getConstantMappings() { return constantMappings; } - public Map> getPropertyMappingsByParameter() { - return mappingsByParameter; + public List propertyMappingsByParameter(Parameter parameter) { + // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value + return mappingsByParameter.get( parameter.getName() ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index e10f8730c7..98fb5dab56 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -44,8 +44,7 @@ public class Parameter extends ModelElement { private final boolean mappingContext; private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext) { - // issue #909: FreeMarker doesn't like "values" as a parameter name - this.name = "values".equals( name ) ? "values_" : name; + this.name = name; this.originalName = name; this.type = type; this.mappingTarget = mappingTarget; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 1db3e2586b..d19ee8a769 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -45,24 +45,24 @@ <#if (sourceParameters?size > 1)> <#list sourceParametersExcludingPrimitives as sourceParam> - <#if (propertyMappingsByParameter[sourceParam.name]?size > 0)> + <#if (propertyMappingsByParameter(sourceParam)?size > 0)> if ( ${sourceParam.name} != null ) { - <#list propertyMappingsByParameter[sourceParam.name] as propertyMapping> + <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> } <#list sourcePrimitiveParameters as sourceParam> - <#if (propertyMappingsByParameter[sourceParam.name]?size > 0)> - <#list propertyMappingsByParameter[sourceParam.name] as propertyMapping> + <#if (propertyMappingsByParameter(sourceParam)?size > 0)> + <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> <#else> <#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) { - <#list propertyMappingsByParameter[sourceParameters[0].name] as propertyMapping> + <#list propertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> <#if mapNullToDefault>} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java new file mode 100644 index 0000000000..42b8076f17 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1244; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1244") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses( SizeMapper.class ) +public class Issue1244Test { + + @Test + public void properlyCreatesMapperWithSizeAsParameterName() { + SizeMapper.SizeHolder sizeHolder = new SizeMapper.SizeHolder(); + sizeHolder.setSize( "size" ); + + SizeMapper.SizeHolderDto dto = Mappers.getMapper( SizeMapper.class ).convert( sizeHolder ); + assertThat( dto.getSize() ).isEqualTo( "size" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java new file mode 100644 index 0000000000..8de1c6874c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1244; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SizeMapper { + + SizeHolderDto convert(SizeHolder size); + + SizeHolderDto convert(SizeHolder size, int test); + + SizeHolderDto convertOther(SizeHolder sizeHolder, int size); + + class SizeHolder { + private String size; + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + } + + class SizeHolderDto { + private String size; + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java index 5198104be6..2061e8d51f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java @@ -27,6 +27,10 @@ public interface ValuesMapper { ValuesHolderDto convert(ValuesHolder values); + ValuesHolderDto convert(ValuesHolder values, int test); + + ValuesHolderDto convertOther(ValuesHolder valuesHolder, int values); + class ValuesHolder { private String values; From 3004ea28c5ec4159e25a07c013777878bd7a1c67 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 11 Jul 2017 21:53:38 +0200 Subject: [PATCH 0129/1006] #1131 Use SourceRHS source type for update methods factories If a SourceRHS is present then the source type of the SourceRHS and the MappingContext parameters are considered for the factory method selection, i.e. the other source parameters are ignored --- .../java/org/mapstruct/ObjectFactory.java | 2 +- .../mapstruct-reference-guide.asciidoc | 72 +++++++++++++++- .../conversion/ConversionProvider.java | 2 +- .../conversion/DateToStringConversion.java | 4 +- .../conversion/ReverseConversion.java | 2 +- .../internal/conversion/SimpleConversion.java | 2 +- .../internal/model/AbstractBaseBuilder.java | 3 +- .../model/AbstractMappingMethodBuilder.java | 3 +- .../model/CollectionAssignmentBuilder.java | 31 +++++-- .../model/ContainerMappingMethod.java | 2 +- .../model/ContainerMappingMethodBuilder.java | 5 +- .../internal/model/IterableMappingMethod.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 5 +- .../internal/model/MappingBuilderContext.java | 3 +- .../ap/internal/model/MethodReference.java | 2 +- .../ap/internal/model/PropertyMapping.java | 11 ++- .../internal/model/StreamMappingMethod.java | 2 +- .../ap/internal/model/TypeConversion.java | 2 +- .../model/assignment/AdderWrapper.java | 1 + .../model/assignment/ArrayCopyWrapper.java | 1 + .../model/assignment/AssignmentWrapper.java | 1 + .../model/assignment/EnumConstantWrapper.java | 2 + ...nceSetterWrapperForCollectionsAndMaps.java | 1 + .../GetterWrapperForCollectionsAndMaps.java | 1 + .../assignment/Java8FunctionWrapper.java | 3 +- .../model/assignment/LocalVarWrapper.java | 1 + .../model/assignment/SetterWrapper.java | 1 + .../SetterWrapperForCollectionsAndMaps.java | 1 + ...perForCollectionsAndMapsWithNullCheck.java | 3 +- .../model/assignment/UpdateWrapper.java | 16 ++-- .../WrapperForCollectionsAndMaps.java | 1 + .../{assignment => common}/Assignment.java | 4 +- .../model/common/ParameterBinding.java | 29 +++++-- .../model/{ => common}/SourceRHS.java | 5 +- .../model/source/SelectionParameters.java | 31 +++++++ .../source/selector/SelectionCriteria.java | 8 ++ .../model/source/selector/TypeSelector.java | 20 ++++- .../creation/MappingResolverImpl.java | 6 +- .../ap/internal/model/MethodReference.ftl | 8 +- .../internal/model/{ => common}/SourceRHS.ftl | 2 +- .../ap/test/bugs/_1131/Issue1131Mapper.java | 60 +++++++++++++ .../_1131/Issue1131MapperWithContext.java | 79 +++++++++++++++++ .../ap/test/bugs/_1131/Issue1131Test.java | 86 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1131/Source.java | 58 +++++++++++++ .../mapstruct/ap/test/bugs/_1131/Target.java | 67 +++++++++++++++ 45 files changed, 590 insertions(+), 61 deletions(-) rename processor/src/main/java/org/mapstruct/ap/internal/model/{assignment => common}/Assignment.java (97%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{ => common}/SourceRHS.java (95%) rename processor/src/main/resources/org/mapstruct/ap/internal/model/{ => common}/SourceRHS.ftl (97%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java diff --git a/core-common/src/main/java/org/mapstruct/ObjectFactory.java b/core-common/src/main/java/org/mapstruct/ObjectFactory.java index 13f7f246cc..7319900b66 100644 --- a/core-common/src/main/java/org/mapstruct/ObjectFactory.java +++ b/core-common/src/main/java/org/mapstruct/ObjectFactory.java @@ -30,7 +30,7 @@ * return type that is assignable to the required object type is present, then the factory method is used instead. *

    * Factory methods can be defined without parameters, with an {@code @}{@link TargetType} parameter, a {@code @} - * {@link Context} parameter, or with a mapping methods source parameter. If any of those parameters are defined, then + * {@link Context} parameter, or with the mapping source parameter. If any of those parameters are defined, then * the mapping method that is supposed to use the factory method needs to be declared with an assignable result type, * assignable context parameter, and/or assignable source types. *

    diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index c98afcda69..f3011a5315 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1579,7 +1579,7 @@ The mapping of enum to enum via the `@Mapping` annotation is *DEPRECATED*. It wi [[object-factories]] == Object factories -By default, the generated code for mapping one bean type into another will call the default constructor to instantiate the target type. +By default, the generated code for mapping one bean type into another or updating a bean will call the default constructor to instantiate the target type. Alternatively you can plug in custom object factories which will be invoked to obtain instances of the target type. One use case for this is JAXB which creates `ObjectFactory` classes for obtaining new instances of schema types. @@ -1613,7 +1613,7 @@ public class EntityFactory { @Mapper(uses= { DtoFactory.class, EntityFactory.class } ) public interface CarMapper { - OrderMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); CarDto carToCarDto(Car car); @@ -1659,6 +1659,74 @@ public class CarMapperImpl implements CarMapper { ---- ==== +.Custom object factories with update methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses = { DtoFactory.class, EntityFactory.class, CarMapper.class } ) +public interface OwnerMapper { + + OwnerMapper INSTANCE = Mappers.getMapper( OwnerMapper.class ); + + void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto); + + void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner); +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +public class OwnerMapperImpl implements OwnerMapper { + + private final DtoFactory dtoFactory = new DtoFactory(); + + private final EntityFactory entityFactory = new EntityFactory(); + + private final OwnerMapper ownerMapper = Mappers.getMapper( OwnerMapper.class ); + + @Override + public void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto) { + if ( owner == null ) { + return; + } + + if ( owner.getCar() != null ) { + if ( ownerDto.getCar() == null ) { + ownerDto.setCar( dtoFactory.createCarDto() ); + } + // update car within ownerDto + } + else { + ownerDto.setCar( null ); + } + + // updating other properties + } + + @Override + public void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner) { + if ( ownerDto == null ) { + return; + } + + if ( ownerDto.getCar() != null ) { + if ( owner.getCar() == null ) { + owner.setCar( entityFactory.createEntity( Car.class ) ); + } + // update car within owner + } + else { + owner.setCar( null ); + } + + // updating other properties + } +} +---- +==== + In addition, annotating a factory method with `@ObjectFactory` lets you gain access to the mapping sources. Source objects can be added as parameters in the same way as for mapping method. The `@ObjectFactory` annotation is necessary to let MapStruct know that the given method is only a factory method. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java index f0095c1e43..574f73dcae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java @@ -20,7 +20,7 @@ import java.util.List; import org.mapstruct.ap.internal.model.TypeConversion; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.HelperMethod; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index 9a27a9c79e..f16a50095b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -27,10 +27,10 @@ import java.util.Date; import java.util.List; -import org.mapstruct.ap.internal.model.assignment.Assignment; -import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.TypeConversion; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java index 282c87f027..3c914591e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.List; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.HelperMethod; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java index 12846bad7f..a69cbfbca7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java @@ -23,7 +23,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.TypeConversion; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.common.Type; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index a7bc1b77ba..9a2ec6b4ad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -18,8 +18,9 @@ */ package org.mapstruct.ap.internal.model; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.MappingMethodUtils; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index da40bf0dd8..597ad093b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -19,7 +19,8 @@ package org.mapstruct.ap.internal.model; -import org.mapstruct.ap.internal.model.assignment.Assignment; +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.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index ea9f6dd6b0..ee8e3e8eea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -18,14 +18,16 @@ */ package org.mapstruct.ap.internal.model; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; +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.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.Message; @@ -65,7 +67,8 @@ public class CollectionAssignmentBuilder { private Type targetType; private String targetPropertyName; private PropertyMapping.TargetWriteAccessorType targetAccessorType; - private Assignment rhs; + private Assignment assignment; + private SourceRHS sourceRHS; public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) { this.ctx = ctx; @@ -97,13 +100,28 @@ public CollectionAssignmentBuilder targetAccessorType(PropertyMapping.TargetWrit return this; } - public CollectionAssignmentBuilder rightHandSide(Assignment rhs) { - this.rhs = rhs; + /** + * @param assignment the assignment that needs to be invoked + * + * @return this builder for chaining + */ + public CollectionAssignmentBuilder assignment(Assignment assignment) { + this.assignment = assignment; + return this; + } + + /** + * @param sourceRHS the source right hand side for getting the property for mapping + * + * @return this builder for chaining + */ + public CollectionAssignmentBuilder rightHandSide(SourceRHS sourceRHS) { + this.sourceRHS = sourceRHS; return this; } public Assignment build() { - Assignment result = rhs; + Assignment result = assignment; CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE; @@ -121,7 +139,8 @@ public Assignment build() { targetPropertyName ); } - Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + Assignment factoryMethod = ctx.getMappingResolver() + .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( sourceRHS ) ); result = new UpdateWrapper( result, method.getThrownTypes(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 984753509c..1bb72088a7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 7a262fb46f..5e7ce49959 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -25,10 +25,11 @@ import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 2edafea3b6..d9f2b41cab 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -23,9 +23,9 @@ import java.util.Collection; import java.util.List; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index d7733479d2..1f02b7756c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -24,12 +24,13 @@ import java.util.Map; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index e1e466a36c..77bca9fcf8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -28,8 +28,9 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index aee3fd30f3..17c8629629 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -24,7 +24,7 @@ import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index db7fa579f0..a4dc9f3dfc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; @@ -34,14 +34,15 @@ import org.mapstruct.ap.internal.model.assignment.AdderWrapper; import org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; @@ -393,7 +394,8 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { targetPropertyName ); } - Assignment factory = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + Assignment factory = ctx.getMappingResolver() + .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ) ); return new UpdateWrapper( rhs, method.getThrownTypes(), factory, isFieldAssignment(), targetType, !rhs.isSourceReferenceParameter() ); } @@ -426,7 +428,8 @@ private Assignment assignToCollection(Type targetType, TargetWriteAccessorType t .targetType( targetType ) .targetPropertyName( targetPropertyName ) .targetAccessorType( targetAccessorType ) - .rightHandSide( rhs ) + .rightHandSide( rightHandSide ) + .assignment( rhs ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index e4f41caefa..6e2d067b86 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -26,8 +26,8 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.mapstruct.ap.internal.model.assignment.Assignment; import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index c5d62aff76..19c6a6f9eb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Type; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index b41aa683ca..3c7e03505c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Nouns; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index c0354f053f..2dfc5b6cd8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 641c1e61ef..6bcdb93ff8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Type; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java index 2d6bf8a638..80d9e403c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java @@ -20,6 +20,8 @@ import java.util.HashSet; import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index b6b1aac7e4..0e4ba1dc8f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -20,6 +20,7 @@ import java.util.List; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 47dcae6e13..2d0c2429a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java index 74c111b114..6d4a00e5f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** @@ -53,7 +54,7 @@ public Set getImportTypes() { /** * * @return {@code true} if the wrapped assignment is - * {@link org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType#DIRECT}, {@code false} otherwise + * {@link Assignment.AssignmentType#DIRECT}, {@code false} otherwise */ public boolean isDirectAssignment() { return getAssignment().getType() == AssignmentType.DIRECT; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java index 88052ef3f3..8b28b331fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index c3c79afb32..97ccc25f00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java index ffcb387c6f..98b298f567 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java @@ -20,6 +20,7 @@ import java.util.List; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index dc6921fae3..cd5b9eb075 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -23,10 +23,11 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import static org.mapstruct.ap.internal.model.assignment.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; /** * This wrapper handles the situation where an assignment is done via the setter and a null check is needed. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index 8fb5b9e5f8..e23f59899d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** @@ -51,17 +52,17 @@ public UpdateWrapper( Assignment decoratedAssignment, } private static Type determineImplType(Assignment factoryMethod, Type targetType) { + if ( factoryMethod != null ) { + //If we have factory method then we won't use the targetType + return null; + } if ( targetType.getImplementationType() != null ) { // it's probably a collection or something return targetType.getImplementationType(); } - if ( factoryMethod == null ) { - // no factory method means we create a new instance ourself and thus need to import the type - return targetType; - } - - return null; + // no factory method means we create a new instance ourself and thus need to import the type + return targetType; } @Override @@ -82,6 +83,9 @@ public List getThrownTypes() { public Set getImportTypes() { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); + if ( factoryMethod != null ) { + imported.addAll( factoryMethod.getImportTypes() ); + } if ( targetImplementationType != null ) { imported.add( targetImplementationType ); imported.addAll( targetImplementationType.getTypeParameters() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index b28a7de99e..44411a4448 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java similarity index 97% rename from processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index e7e282dc39..a25fab69c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -16,13 +16,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.internal.model.assignment; +package org.mapstruct.ap.internal.model.common; import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.common.Type; - /** * Assignment represents all kind of manners a source can be assigned to a target. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index fcf57d26d1..9cfdfcaeca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -35,14 +35,16 @@ public class ParameterBinding { private final boolean targetType; private final boolean mappingTarget; private final boolean mappingContext; + private final SourceRHS sourceRHS; private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType, - boolean mappingContext) { + boolean mappingContext, SourceRHS sourceRHS) { this.type = parameterType; this.variableName = variableName; this.targetType = targetType; this.mappingTarget = mappingTarget; this.mappingContext = mappingContext; + this.sourceRHS = sourceRHS; } /** @@ -80,11 +82,22 @@ public Type getType() { return type; } + /** + * @return the sourceRHS that this parameter is bound to + */ + public SourceRHS getSourceRHS() { + return sourceRHS; + } + public Set getImportTypes() { if ( targetType ) { return type.getImportTypes(); } + if ( sourceRHS != null ) { + return sourceRHS.getImportTypes(); + } + return Collections.emptySet(); } @@ -98,7 +111,9 @@ public static ParameterBinding fromParameter(Parameter parameter) { parameter.getName(), parameter.isMappingTarget(), parameter.isTargetType(), - parameter.isMappingContext() ); + parameter.isMappingContext(), + null + ); } public static List fromParameters(List parameters) { @@ -114,7 +129,7 @@ public static List fromParameters(List parameters) * @return a parameter binding representing a target type parameter */ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, true, false ); + return new ParameterBinding( classTypeOf, null, false, true, false, null ); } /** @@ -122,7 +137,7 @@ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { * @return a parameter binding representing a mapping target parameter */ public static ParameterBinding forMappingTargetBinding(Type resultType) { - return new ParameterBinding( resultType, null, true, false, false ); + return new ParameterBinding( resultType, null, true, false, false, null ); } /** @@ -130,6 +145,10 @@ public static ParameterBinding forMappingTargetBinding(Type resultType) { * @return a parameter binding representing a mapping source type */ public static ParameterBinding forSourceTypeBinding(Type sourceType) { - return new ParameterBinding( sourceType, null, false, false, false ); + return new ParameterBinding( sourceType, null, false, false, false, null ); + } + + public static ParameterBinding fromSourceRHS(SourceRHS sourceRHS) { + return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, sourceRHS ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java similarity index 95% rename from processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index cdcd1d2a2b..90493453b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -16,15 +16,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.internal.model; +package org.mapstruct.ap.internal.model.common; import java.util.Collections; import java.util.List; import java.util.Set; -import org.mapstruct.ap.internal.model.assignment.Assignment; -import org.mapstruct.ap.internal.model.common.ModelElement; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Strings; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index 9c3aa84c35..de95e77b3b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -18,10 +18,13 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.Collections; import java.util.List; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.model.common.SourceRHS; + /** * Holding parameters common to the selection process, common to IterableMapping, BeanMapping, PropertyMapping and * MapMapping @@ -34,13 +37,20 @@ public class SelectionParameters { private final List qualifyingNames; private final TypeMirror resultType; private final Types typeUtils; + private final SourceRHS sourceRHS; public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, Types typeUtils) { + this( qualifiers, qualifyingNames, resultType, typeUtils, null ); + } + + private SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, + Types typeUtils, SourceRHS sourceRHS) { this.qualifiers = qualifiers; this.qualifyingNames = qualifyingNames; this.resultType = resultType; this.typeUtils = typeUtils; + this.sourceRHS = sourceRHS; } /** @@ -68,6 +78,13 @@ public TypeMirror getResultType() { return resultType; } + /** + * @return sourceRHS used for further selection of an appropriate factory method + */ + public SourceRHS getSourceRHS() { + return sourceRHS; + } + @Override public int hashCode() { int hash = 3; @@ -97,6 +114,10 @@ public boolean equals(Object obj) { return false; } + if ( !equals( this.sourceRHS, other.sourceRHS ) ) { + return false; + } + return equals( this.resultType, other.resultType ); } @@ -133,4 +154,14 @@ private boolean equals(TypeMirror mirror1, TypeMirror mirror2) { return mirror2 != null && typeUtils.isSameType( mirror1, mirror2 ); } } + + public static SelectionParameters forSourceRHS(SourceRHS sourceRHS) { + return new SelectionParameters( + Collections.emptyList(), + Collections.emptyList(), + null, + null, + sourceRHS + ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 522f422c65..9856dd9281 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -23,6 +23,7 @@ import javax.lang.model.type.TypeMirror; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.source.SelectionParameters; /** @@ -36,6 +37,7 @@ public class SelectionCriteria { private final List qualifiedByNames = new ArrayList(); private final String targetPropertyName; private final TypeMirror qualifyingResultType; + private final SourceRHS sourceRHS; private boolean preferUpdateMapping; private final boolean objectFactoryRequired; private final boolean lifecycleCallbackRequired; @@ -47,9 +49,11 @@ public SelectionCriteria(SelectionParameters selectionParameters, String targetP qualifiers.addAll( selectionParameters.getQualifiers() ); qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); qualifyingResultType = selectionParameters.getResultType(); + sourceRHS = selectionParameters.getSourceRHS(); } else { this.qualifyingResultType = null; + sourceRHS = null; } this.targetPropertyName = targetPropertyName; this.preferUpdateMapping = preferUpdateMapping; @@ -91,6 +95,10 @@ public boolean isPreferUpdateMapping() { return preferUpdateMapping; } + public SourceRHS getSourceRHS() { + return sourceRHS; + } + public void setPreferUpdateMapping(boolean preferUpdateMapping) { this.preferUpdateMapping = preferUpdateMapping; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index d2258239d7..ce977f5664 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -25,6 +25,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; @@ -59,7 +60,11 @@ public List> getMatchingMethods(Method mapp List availableBindings; if ( sourceTypes.isEmpty() ) { // if no source types are given, we have a factory or lifecycle method - availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod, targetType ); + availableBindings = getAvailableParameterBindingsFromMethod( + mappingMethod, + targetType, + criteria.getSourceRHS() + ); } else { availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType, mappingMethod ); @@ -81,11 +86,18 @@ public List> getMatchingMethods(Method mapp return result; } - private List getAvailableParameterBindingsFromMethod(Method method, Type targetType) { - List availableParams = new ArrayList( method.getParameters().size() + 2 ); + private List getAvailableParameterBindingsFromMethod(Method method, Type targetType, + SourceRHS sourceRHS) { + List availableParams = new ArrayList( method.getParameters().size() + 3 ); - availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + if ( sourceRHS != null ) { + availableParams.addAll( ParameterBinding.fromParameters( method.getContextParameters() ) ); + availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); + } + else { + availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); + } return availableParams; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index e86e7c7fef..19d23b9d7f 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -42,14 +42,14 @@ import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver; import org.mapstruct.ap.internal.model.MethodReference; -import org.mapstruct.ap.internal.model.SourceRHS; import org.mapstruct.ap.internal.model.VirtualMappingMethod; -import org.mapstruct.ap.internal.model.assignment.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; +import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 7b603d7848..8f4a31ddc6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -53,8 +53,10 @@ ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> <#elseif param.mappingContext> ${param.variableName}<#t> + <#elseif param.sourceRHS??> + <@_assignment assignmentToUse=param.sourceRHS/><#t> <#elseif assignment??> - <@_assignment/><#t> + <@_assignment assignmentToUse=assignment/><#t> <#else> ${param.variableName}<#t> @@ -67,8 +69,8 @@ macro: assignment purpose: note: takes its targetyType from the singleSourceParameterType --> -<#macro _assignment> - <@includeModel object=assignment +<#macro _assignment assignmentToUse> + <@includeModel object=assignmentToUse targetBeanName=ext.targetBeanName existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl similarity index 97% rename from processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl rename to processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl index 4b3df1fd1a..1e22080cff 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl @@ -1,4 +1,4 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SourceRHS" --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" --> <#-- Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java new file mode 100644 index 0000000000..5059ffe6ce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java @@ -0,0 +1,60 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1131; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ObjectFactory; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class Issue1131Mapper { + public static final Issue1131Mapper INSTANCE = Mappers.getMapper( Issue1131Mapper.class ); + + public static final List CALLED_METHODS = new ArrayList(); + + public abstract void merge(Source source, @MappingTarget Target target); + + public abstract void mergeNested(List source, @MappingTarget List target); + + @ObjectFactory + protected Target.Nested create(Source.Nested source) { + CALLED_METHODS.add( "create(Source.Nested)" ); + return new Target.Nested( "from object factory" ); + } + + @ObjectFactory + protected Target.Nested createWithSource(Source source) { + throw new IllegalArgumentException( "Should not use create with source" ); + } + + @ObjectFactory + protected List createWithSourceList(List source) { + CALLED_METHODS.add( "create(List)" ); + List result = new ArrayList(); + result.add( new Target.Nested( "from createWithSourceList" ) ); + return result; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java new file mode 100644 index 0000000000..c75a967756 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java @@ -0,0 +1,79 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1131; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ObjectFactory; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class Issue1131MapperWithContext { + public static final Issue1131MapperWithContext INSTANCE = Mappers.getMapper( Issue1131MapperWithContext.class ); + + public static class MappingContext { + private final List calledMethods = new ArrayList(); + + public Target.Nested create(Source.Nested source) { + calledMethods.add( "create(Source.Nested)" ); + return new Target.Nested( "from within @Context" ); + } + + public List create(List source) { + calledMethods.add( "create(List)" ); + if ( source == null ) { + return new ArrayList(); + } + else { + return new ArrayList( source.size() ); + } + } + + public List getCalledMethods() { + return calledMethods; + } + } + + public abstract void merge(Source source, @MappingTarget Target target, @Context MappingContext context); + + public abstract void merge(List source, @MappingTarget List target, + @Context MappingContext context); + + @ObjectFactory + protected Target.Nested create(Source.Nested source, @Context MappingContext context) { + return context.create( source ); + } + + @ObjectFactory + protected Target.Nested createWithSource(Source source, @Context MappingContext context) { + throw new IllegalArgumentException( "Should not use create with source" ); + } + + @ObjectFactory + protected List createWithSourceList(List source, @Context MappingContext context) { + return context.create( source ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java new file mode 100644 index 0000000000..3f1d167769 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java @@ -0,0 +1,86 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1131; + +import java.util.ArrayList; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1131") +@WithClasses({ + Issue1131Mapper.class, + Issue1131MapperWithContext.class, + Source.class, + Target.class +}) +public class Issue1131Test { + + @Test + public void shouldUseCreateWithSourceNested() { + + Source source = new Source(); + source.setNested( new Source.Nested() ); + source.getNested().setProperty( "something" ); + source.setMoreNested( new ArrayList() ); + + Target target = new Target(); + + Issue1131Mapper.INSTANCE.merge( source, target ); + + assertThat( target.getNested() ).isNotNull(); + assertThat( target.getNested().getProperty() ).isEqualTo( "something" ); + assertThat( target.getNested().getInternal() ).isEqualTo( "from object factory" ); + assertThat( Issue1131Mapper.CALLED_METHODS ).containsExactly( + "create(Source.Nested)", + "create(List)" + ); + } + + @Test + public void shouldUseContextObjectFactory() { + + Source source = new Source(); + source.setNested( new Source.Nested() ); + source.getNested().setProperty( "something" ); + source.setMoreNested( new ArrayList() ); + + Target target = new Target(); + + Issue1131MapperWithContext.MappingContext context = new Issue1131MapperWithContext.MappingContext(); + Issue1131MapperWithContext.INSTANCE.merge( source, target, context ); + + assertThat( target.getNested() ).isNotNull(); + assertThat( target.getNested().getProperty() ).isEqualTo( "something" ); + assertThat( target.getNested().getInternal() ).isEqualTo( "from within @Context" ); + assertThat( context.getCalledMethods() ).containsExactly( + "create(Source.Nested)", + "create(List)" + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java new file mode 100644 index 0000000000..fef5f8d435 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1131; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Source { + + public static class Nested { + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } + + private Nested nested; + private List moreNested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + + public List getMoreNested() { + return moreNested; + } + + public void setMoreNested(List moreNested) { + this.moreNested = moreNested; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java new file mode 100644 index 0000000000..d97617950d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java @@ -0,0 +1,67 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1131; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Target { + + public static class Nested { + private final String internal; + private String property; + + public Nested(String internal) { + this.internal = internal; + } + + public String getInternal() { + return internal; + } + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } + + private Nested nested; + private List moreNested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + + public List getMoreNested() { + return moreNested; + } + + public void setMoreNested(List moreNested) { + this.moreNested = moreNested; + } +} From d9821a0cc89c8276090f78918db59548d15ac3ed Mon Sep 17 00:00:00 2001 From: Andreas Gudian Date: Tue, 11 Jul 2017 23:03:44 +0200 Subject: [PATCH 0130/1006] #1242 Fix favoring of a single factory method with source params before others without source params. From the Javadoc of @ObjectFactory: If there are two factory methods, both serving the same type, one with no parameters and one taking sources as input, then the one with the source parameters is favored. If there are multiple such factories, an ambiguity error is shown. --- .../selector/FactoryParameterSelector.java | 62 ++++++++++++++ .../source/selector/MethodSelectors.java | 3 +- ...roneousIssue1242MapperMultipleSources.java | 39 +++++++++ .../ap/test/bugs/_1242/Issue1242Mapper.java | 38 +++++++++ .../ap/test/bugs/_1242/Issue1242Test.java | 83 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1242/SourceA.java | 34 ++++++++ .../mapstruct/ap/test/bugs/_1242/SourceB.java | 25 ++++++ .../mapstruct/ap/test/bugs/_1242/TargetA.java | 34 ++++++++ .../mapstruct/ap/test/bugs/_1242/TargetB.java | 34 ++++++++ .../ap/test/bugs/_1242/TargetFactories.java | 43 ++++++++++ 10 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java new file mode 100644 index 0000000000..8571f51831 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java @@ -0,0 +1,62 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source.selector; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * For factory methods, the candidate list is checked if it contains a method with a source parameter which is to be + * favored compared to factory methods without a source parameter. It returns the original list of candidates in case of + * ambiguities. + * + * @author Andreas Gudian + */ +public class FactoryParameterSelector implements MethodSelector { + + @Override + public List> getMatchingMethods(Method mappingMethod, + List> methods, + ListsourceTypes, + Type targetType, + SelectionCriteria criteria) { + if ( !criteria.isObjectFactoryRequired() || methods.size() <= 1 ) { + return methods; + } + + List> sourceParamFactoryMethods = new ArrayList>( methods.size() ); + + for ( SelectedMethod candidate : methods ) { + if ( !candidate.getMethod().getSourceParameters().isEmpty() ) { + sourceParamFactoryMethods.add( candidate ); + } + } + + if ( sourceParamFactoryMethods.size() == 1 ) { + // there is exactly one candidate with source params, so favor that one. + return sourceParamFactoryMethods; + } + + // let the caller produce an ambiguity error referencing all possibly matching methods + return methods; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 4fca9c9c8f..e651082f1e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -46,7 +46,8 @@ public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeF new TargetTypeSelector( typeUtils, elementUtils ), new XmlElementDeclSelector( typeUtils, elementUtils ), new InheritanceSelector(), - new CreateOrUpdateSelector() ); + new CreateOrUpdateSelector(), + new FactoryParameterSelector() ); } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java new file mode 100644 index 0000000000..3732aca923 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +import org.mapstruct.Mapper; +import org.mapstruct.ObjectFactory; + +/** + * Results in an ambiguous factory method error, as there are two methods with matching source types available. + * + * @author Andreas Gudian + */ +@Mapper(uses = TargetFactories.class) +public abstract class ErroneousIssue1242MapperMultipleSources { + abstract TargetA toTargetA(SourceA source); + + abstract TargetB toTargetB(SourceB source); + + @ObjectFactory + protected TargetB anotherTargetBCreator(SourceB source) { + throw new RuntimeException( "never to be called" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java new file mode 100644 index 0000000000..45e7547fdd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; + +/** + * Test mapper for properly resolving the best fitting factory method + * + * @author Andreas Gudian + */ +@Mapper(uses = TargetFactories.class) +public abstract class Issue1242Mapper { + abstract TargetA toTargetA(SourceA source); + + abstract TargetB toTargetB(SourceB source); + + abstract void mergeA(SourceA source, @MappingTarget TargetA target); + + abstract void mergeB(SourceB source, @MappingTarget TargetB target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java new file mode 100644 index 0000000000..2a65e99d94 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -0,0 +1,83 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; + +/** + * Tests that if multiple factory methods are applicable but only one of them has a source parameter, the one with the + * source param is chosen. + * + * @author Andreas Gudian + */ +@IssueKey("1242") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1242Mapper.class, + SourceA.class, + SourceB.class, + TargetA.class, + TargetB.class, + TargetFactories.class +}) +public class Issue1242Test { + @Test + public void factoryMethodWithSourceParamIsChosen() { + SourceA sourceA = new SourceA(); + sourceA.setB( new SourceB() ); + + TargetA targetA = new TargetA(); + Mappers.getMapper( Issue1242Mapper.class ).mergeA( sourceA, targetA ); + + assertThat( targetA.getB() ).isNotNull(); + assertThat( targetA.getB().getPassedViaConstructor() ).isEqualTo( "created by factory" ); + + targetA = Mappers.getMapper( Issue1242Mapper.class ).toTargetA( sourceA ); + + assertThat( targetA.getB() ).isNotNull(); + assertThat( targetA.getB().getPassedViaConstructor() ).isEqualTo( "created by factory" ); + } + + @Test + @WithClasses(ErroneousIssue1242MapperMultipleSources.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 33, + messageRegExp = "Ambiguous factory methods found for creating .*TargetB:" + + " .*TargetB anotherTargetBCreator\\(.*SourceB source\\)," + + " .*TargetB .*TargetFactories\\.createTargetB\\(.*SourceB source," + + " @TargetType .*Class<.*TargetB> clazz\\)," + + " .*TargetB .*TargetFactories\\.createTargetB\\(@TargetType java.lang.Class<.*TargetB> clazz\\)," + + " .*TargetB .*TargetFactories\\.createTargetB\\(\\).") + }) + public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java new file mode 100644 index 0000000000..874732508a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +/** + * @author Andreas Gudian + */ +class SourceA { + private SourceB b; + + public SourceB getB() { + return b; + } + + public void setB(SourceB b) { + this.b = b; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java new file mode 100644 index 0000000000..caf301c803 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +/** + * @author Andreas Gudian + */ +class SourceB { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java new file mode 100644 index 0000000000..a100c51a70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +/** + * @author Andreas Gudian + */ +class TargetA { + private TargetB b; + + public TargetB getB() { + return b; + } + + public void setB(TargetB b) { + this.b = b; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java new file mode 100644 index 0000000000..f6b690073b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +/** + * @author Andreas Gudian + */ +class TargetB { + private final String passedViaConstructor; + + TargetB(String passedViaConstructor) { + this.passedViaConstructor = passedViaConstructor; + } + + String getPassedViaConstructor() { + return passedViaConstructor; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java new file mode 100644 index 0000000000..b4476bcd2d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1242; + +import org.mapstruct.ObjectFactory; +import org.mapstruct.TargetType; + +/** + * Contains non-conflicting factory methods for {@link TargetB}. + * + * @author Andreas Gudian + */ +public class TargetFactories { + + @ObjectFactory + protected TargetB createTargetB(SourceB source, @TargetType Class clazz) { + return new TargetB( "created by factory" ); + } + + protected TargetB createTargetB(@TargetType Class clazz) { + throw new RuntimeException( "This method is not to be called" ); + } + + protected TargetB createTargetB() { + throw new RuntimeException( "This method is not to be called" ); + } +} From db3bb5eba0f95d352cb1ad06ec18e2f40dea6ed3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 13 Jul 2017 18:52:57 +0200 Subject: [PATCH 0131/1006] #1247 Make sure that nested target mappings works correctly for multiple source parameters --- .../NestedTargetPropertyMappingHolder.java | 142 ++++++++++++++++-- .../internal/model/source/MappingOptions.java | 16 +- .../mapstruct/ap/test/bugs/_1247/DtoIn.java | 41 +++++ .../mapstruct/ap/test/bugs/_1247/DtoOut.java | 44 ++++++ .../ap/test/bugs/_1247/InternalData.java | 37 +++++ .../ap/test/bugs/_1247/InternalDto.java | 44 ++++++ .../ap/test/bugs/_1247/Issue1247Mapper.java | 51 +++++++ .../ap/test/bugs/_1247/Issue1247Test.java | 101 +++++++++++++ .../ap/test/bugs/_1247/OtherDtoOut.java | 53 +++++++ .../ap/test/bugs/_1247/OtherInternalData.java | 46 ++++++ .../ap/test/bugs/_1247/OtherInternalDto.java | 53 +++++++ 11 files changed, 613 insertions(+), 15 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index e6bb66274d..730b91c1e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -19,8 +19,9 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -56,7 +57,8 @@ public Parameter apply(SourceReference sourceReference) { Extractor() { @Override public PropertyEntry apply(SourceReference sourceReference) { - return first( sourceReference.getPropertyEntries() ); + return sourceReference.getPropertyEntries().isEmpty() ? null : + first( sourceReference.getPropertyEntries() ); } }; @@ -117,6 +119,8 @@ public static class Builder { private Method method; private MappingBuilderContext mappingContext; private Set existingVariableNames; + private List propertyMappings; + private Set handledTargets; public Builder method(Method method) { this.method = method; @@ -135,8 +139,8 @@ public Builder existingVariableNames(Set existingVariableNames) { public NestedTargetPropertyMappingHolder build() { List processedSourceParameters = new ArrayList(); - Set handledTargets = new HashSet(); - List propertyMappings = new ArrayList(); + handledTargets = new HashSet(); + propertyMappings = new ArrayList(); // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. @@ -164,7 +168,7 @@ public NestedTargetPropertyMappingHolder build() { // Lastly we need to group by the source references. This will allow us to actually create // the next mappings by popping source elements GroupedSourceReferences groupedSourceReferences = groupByPoppedSourceReferences( - entryByParam.getValue(), + entryByParam, groupedByTP.singleTargetReferences.get( targetProperty ) ); @@ -229,6 +233,13 @@ public NestedTargetPropertyMappingHolder build() { handledTargets.add( entryByTP.getKey().getName() ); } + handleSourceParameterMappings( + groupedSourceReferences.sourceParameterMappings, + targetProperty, + sourceParameter, + forceUpdateMethod + ); + unprocessedDefinedTarget.put( targetProperty, groupedSourceReferences.notProcessedAppliesToAll ); } } @@ -242,6 +253,43 @@ public NestedTargetPropertyMappingHolder build() { ); } + /** + * Handle the {@link PropertyMapping} creation for source parameter mappings. + * + * @param sourceParameterMappings the source parameter mappings for which property mapping should be done + * @param targetProperty the target property that is being mapped + * @param sourceParameter the source parameter that is used + * @param forceUpdateMethod whether we need to force an update method + */ + private void handleSourceParameterMappings(List sourceParameterMappings, PropertyEntry targetProperty, + Parameter sourceParameter, boolean forceUpdateMethod) { + if ( !sourceParameterMappings.isEmpty() ) { + // The source parameter mappings have no mappings, the source name is actually the parameter itself + MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( + new HashMap>(), + false, + true + ); + SourceReference reference = new SourceReference.BuilderFromProperty() + .sourceParameter( sourceParameter ) + .name( targetProperty.getName() ) + .build(); + + PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( + nonNestedOptions, + targetProperty, + reference, + forceUpdateMethod + ); + + if ( propertyMapping != null ) { + propertyMappings.add( propertyMapping ); + } + + handledTargets.add( targetProperty.getName() ); + } + } + /** * The target references are popped. The {@code List<}{@link Mapping}{@code >} are keyed on the unique first * entries of the target references. @@ -464,15 +512,18 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, * * * - * @param mappings the list of {@link Mapping} that needs to be used for grouping on popped source references + * @param entryByParam the entry of a {@link Parameter} and it's associated {@link Mapping}(s) that need to + * be used for grouping on popped source references * @param singleTargetReferences the single target references that match the source mappings * * @return the Grouped Source References */ - private GroupedSourceReferences groupByPoppedSourceReferences(List mappings, + private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry> entryByParam, List singleTargetReferences) { + List mappings = entryByParam.getValue(); List nonNested = new ArrayList(); List appliesToAll = new ArrayList(); + List sourceParameterMappings = new ArrayList(); // group all mappings based on the top level name before popping Map> mappingsKeyedByProperty = new LinkedHashMap>(); @@ -496,7 +547,24 @@ else if ( mapping.getSourceReference() == null ) { } } - populateWithSingleTargetReferences( mappingsKeyedByProperty, singleTargetReferences, PROPERTY_EXTRACTOR ); + // We consider that there were no mappings if there are no mappingsKeyedByProperty + // and no nonNested. appliesToAll Mappings are mappings that have no source reference and need to be + // applied to everything. + boolean hasNoMappings = mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty(); + Parameter sourceParameter = entryByParam.getKey(); + List singleTargetReferencesToUse = + extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( + singleTargetReferences, + sourceParameterMappings, + hasNoMappings, + sourceParameter + ); + + populateWithSingleTargetReferences( + mappingsKeyedByProperty, + singleTargetReferencesToUse, + PROPERTY_EXTRACTOR + ); for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { entry.getValue().addAll( appliesToAll ); @@ -516,10 +584,55 @@ else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { return new GroupedSourceReferences( mappingsKeyedByProperty, nonNested, - notProcessedAppliesToAll + notProcessedAppliesToAll, + sourceParameterMappings ); } + /** + * Extracts all relevant single target references and populates the {@code sourceParameterMappings} if needed. + * A relevant single target reference mapping is a mapping that has a valid source reference and is for + * the {@code sourceParameter}. If there are no mappings i.e. {@code hasNoMappings = true} and the source + * reference in the mapping has no property entries then add that to the {@code sourceParameterMappings} + * (mappings like this have found themselves here because there is a mapping method with multiple parameters + * and that are using the same sub-path in the target properties). + * + * @param singleTargetReferences All the single target references for a target property + * @param sourceParameterMappings a List that needs to be populated with valid mappings when {@code + * hasNoMappings = true} and there are no property entries in the source reference + * @param hasNoMappings parameter indicating whether there were any extracted mappings for this target property + * @param sourceParameter the source parameter for which the grouping is being done + * + * @return a list with valid single target references + */ + private List extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( + List singleTargetReferences, List sourceParameterMappings, boolean hasNoMappings, + Parameter sourceParameter) { + List singleTargetReferencesToUse = null; + if ( singleTargetReferences != null ) { + singleTargetReferencesToUse = new ArrayList( singleTargetReferences.size() ); + for ( Mapping mapping : singleTargetReferences ) { + if ( mapping.getSourceReference() == null || !mapping.getSourceReference().isValid() || + !sourceParameter.equals( mapping.getSourceReference().getParameter() ) ) { + // If the mapping has no sourceReference, it is not valid or it does not have the same source + // parameter then we need to ignore it. When a mapping method has multiple parameters it can + // happen that different parameters somehow have same path in the nesting + continue; + } + if ( hasNoMappings && mapping.getSourceReference().getPropertyEntries().isEmpty() ) { + // If there were no mappings for this source parameter and there are no property entries + // that means that this could be for a mapping method with multiple parameters. + // We have to consider and map this separately + sourceParameterMappings.add( mapping ); + } + else { + singleTargetReferencesToUse.add( mapping ); + } + } + } + return singleTargetReferencesToUse; + } + private Map> groupByTargetName(List mappingList) { Map> result = new LinkedHashMap>(); for ( Mapping mapping : mappingList ) { @@ -563,11 +676,9 @@ private void populateWithSingleTargetReferences(Map> map, //This are non nested target references only their property needs to be added as they most probably // define it for ( Mapping mapping : singleTargetReferences ) { - if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() - && !mapping.getSourceReference().getPropertyEntries().isEmpty() ) { - //TODO is this OK? Why there are no propertyEntries? For the Inverse LetterMapper for example + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { K key = keyExtractor.apply( mapping.getSourceReference() ); - if ( !map.containsKey( key ) ) { + if ( key != null && !map.containsKey( key ) ) { map.put( key, new ArrayList() ); } } @@ -642,12 +753,15 @@ private static class GroupedSourceReferences { private final Map> groupedBySourceReferences; private final List nonNested; private final List notProcessedAppliesToAll; + private final List sourceParameterMappings; private GroupedSourceReferences(Map> groupedBySourceReferences, - List nonNested, List notProcessedAppliesToAll) { + List nonNested, List notProcessedAppliesToAll, + List sourceParameterMappings) { this.groupedBySourceReferences = groupedBySourceReferences; this.nonNested = nonNested; this.notProcessedAppliesToAll = notProcessedAppliesToAll; + this.sourceParameterMappings = sourceParameterMappings; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index aa2d0cbea5..c09ff785a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -81,11 +81,25 @@ public static MappingOptions empty() { */ public static MappingOptions forMappingsOnly(Map> mappings, boolean restrictToDefinedMappings) { + return forMappingsOnly( mappings, restrictToDefinedMappings, restrictToDefinedMappings ); + + } + + /** + * creates mapping options with only regular mappings + * + * @param mappings regular mappings to add + * @param restrictToDefinedMappings whether to restrict the mappings only to the defined mappings + * @param forForgedMethods whether the mappings are for forged methods + * @return MappingOptions with only regular mappings + */ + public static MappingOptions forMappingsOnly(Map> mappings, + boolean restrictToDefinedMappings, boolean forForgedMethods) { return new MappingOptions( mappings, null, null, - restrictToDefinedMappings ? BeanMapping.forForgedMethods() : null, + forForgedMethods ? BeanMapping.forForgedMethods() : null, Collections.emptyList(), restrictToDefinedMappings ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java new file mode 100644 index 0000000000..5012d60b85 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +/** + * @author Filip Hrisafov + */ +public class DtoIn { + + private final String data; + private final String data2; + + public DtoIn(String data, String data2) { + this.data = data; + this.data2 = data2; + } + + public String getData() { + return data; + } + + public String getData2() { + return data2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java new file mode 100644 index 0000000000..1a5cefc57f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +/** + * @author Filip Hrisafov + */ +public class DtoOut { + + private String data; + private InternalDto internal; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public InternalDto getInternal() { + return internal; + } + + public void setInternal(InternalDto internal) { + this.internal = internal; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java new file mode 100644 index 0000000000..aafdc6838d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class InternalData { + + private List list; + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java new file mode 100644 index 0000000000..6e3ec8a5af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +/** + * @author Filip Hrisafov + */ +public class InternalDto { + + private String data2; + private InternalData internalData; + + public String getData2() { + return data2; + } + + public void setData2(String data2) { + this.data2 = data2; + } + + public InternalData getInternalData() { + return internalData; + } + + public void setInternalData(InternalData internalData) { + this.internalData = internalData; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java new file mode 100644 index 0000000000..ba3086631c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1247Mapper { + + Issue1247Mapper INSTANCE = Mappers.getMapper( Issue1247Mapper.class ); + + @Mappings( { + @Mapping(target = "internal", source = "in"), + @Mapping(target = "internal.internalData.list", source = "list") + } ) + DtoOut map(DtoIn in, List list); + + @Mappings( { + @Mapping(target = "internal", source = "in"), + @Mapping(target = "internal.expression", expression = "java(\"testingExpression\")"), + @Mapping(target = "internal.internalData.list", source = "list"), + @Mapping(target = "internal.internalData.defaultValue", source = "in.data2", defaultValue = "missing"), + @Mapping(target = "constant", constant = "someConstant") + } ) + OtherDtoOut mapWithConstantExpressionAndDefault(DtoIn in, List list); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java new file mode 100644 index 0000000000..beaef236cf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java @@ -0,0 +1,101 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1247") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1247Mapper.class, + DtoIn.class, + DtoOut.class, + InternalData.class, + InternalDto.class, + OtherDtoOut.class, + OtherInternalData.class, + OtherInternalDto.class +}) +public class Issue1247Test { + + @Test + public void shouldCorrectlyUseMappings() { + + DtoIn in = new DtoIn( "data", "data2" ); + List list = Arrays.asList( "first", "second" ); + DtoOut out = Issue1247Mapper.INSTANCE.map( in, list ); + + assertThat( out ).isNotNull(); + assertThat( out.getData() ).isEqualTo( "data" ); + assertThat( out.getInternal() ).isNotNull(); + assertThat( out.getInternal().getData2() ).isEqualTo( "data2" ); + assertThat( out.getInternal().getInternalData() ).isNotNull(); + assertThat( out.getInternal().getInternalData().getList() ).containsExactly( "first", "second" ); + } + + @Test + public void shouldCorrectlyUseMappingsWithConstantsExpressionsAndDefaults() { + + DtoIn in = new DtoIn( "data", "data2" ); + List list = Arrays.asList( "first", "second" ); + OtherDtoOut out = Issue1247Mapper.INSTANCE.mapWithConstantExpressionAndDefault( in, list ); + + assertThat( out ).isNotNull(); + assertThat( out.getData() ).isEqualTo( "data" ); + assertThat( out.getConstant() ).isEqualTo( "someConstant" ); + assertThat( out.getInternal() ).isNotNull(); + // This will not be mapped by the @Mapping(target = "internal", source = "in") because we have one more + // symmetric mapping @Mapping(target = "internal.expression", expression = "java(\"testingExpression\")") + assertThat( out.getInternal().getData2() ).isNull(); + assertThat( out.getInternal().getExpression() ).isEqualTo( "testingExpression" ); + assertThat( out.getInternal().getInternalData() ).isNotNull(); + assertThat( out.getInternal().getInternalData().getList() ).containsExactly( "first", "second" ); + assertThat( out.getInternal().getInternalData().getDefaultValue() ).isEqualTo( "data2" ); + } + + @Test + public void shouldCorrectlyUseMappingsWithConstantsExpressionsAndUseDefault() { + + DtoIn in = new DtoIn( "data", null ); + List list = Arrays.asList( "first", "second" ); + OtherDtoOut out = Issue1247Mapper.INSTANCE.mapWithConstantExpressionAndDefault( in, list ); + + assertThat( out ).isNotNull(); + assertThat( out.getData() ).isEqualTo( "data" ); + assertThat( out.getConstant() ).isEqualTo( "someConstant" ); + assertThat( out.getInternal() ).isNotNull(); + assertThat( out.getInternal().getData2() ).isNull(); + assertThat( out.getInternal().getExpression() ).isEqualTo( "testingExpression" ); + assertThat( out.getInternal().getInternalData() ).isNotNull(); + assertThat( out.getInternal().getInternalData().getList() ).containsExactly( "first", "second" ); + assertThat( out.getInternal().getInternalData().getDefaultValue() ).isEqualTo( "missing" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java new file mode 100644 index 0000000000..36439f0ceb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +/** + * @author Filip Hrisafov + */ +public class OtherDtoOut { + + private String data; + private OtherInternalDto internal; + private String constant; + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public OtherInternalDto getInternal() { + return internal; + } + + public void setInternal(OtherInternalDto internal) { + this.internal = internal; + } + + public String getConstant() { + return constant; + } + + public void setConstant(String constant) { + this.constant = constant; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java new file mode 100644 index 0000000000..f06bacde4f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class OtherInternalData { + + private List list; + private String defaultValue; + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public String getDefaultValue() { + return defaultValue; + } + + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java new file mode 100644 index 0000000000..91fe5d7eaf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1247; + +/** + * @author Filip Hrisafov + */ +public class OtherInternalDto { + + private String data2; + private String expression; + private OtherInternalData internalData; + + public String getData2() { + return data2; + } + + public void setData2(String data2) { + this.data2 = data2; + } + + public String getExpression() { + return expression; + } + + public void setExpression(String expression) { + this.expression = expression; + } + + public OtherInternalData getInternalData() { + return internalData; + } + + public void setInternalData(OtherInternalData internalData) { + this.internalData = internalData; + } +} From b2e3ff0727c9771dadcd87817f9a58a0ac3da65e Mon Sep 17 00:00:00 2001 From: Darren Rambaud Date: Fri, 14 Jul 2017 14:30:09 -0500 Subject: [PATCH 0132/1006] Fixed a minor typo On line 14, changed "repostory" to "repository" --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index f3011a5315..f52e7133ee 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -11,7 +11,7 @@ This is the reference documentation of MapStruct, an annotation processor for generating type-safe, performant and dependency-free bean mapping code. This guide covers all the functionality provided by MapStruct. In case this guide doesn't answer all your questions just join the MapStruct https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users[Google group] to get help. -You found a typo or other error in this guide? Please let us know by opening an issue in the https://github.com/mapstruct/mapstruct[MapStruct GitHub repostory], +You found a typo or other error in this guide? Please let us know by opening an issue in the https://github.com/mapstruct/mapstruct[MapStruct GitHub repository], or, better yet, help the community and send a pull request for fixing it! This work is licensed under the http://creativecommons.org/licenses/by-sa/4.0/[Creative Commons Attribution-ShareAlike 4.0 International License]. From 03f6434aa75ba2663642892053d75abf4c64659f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 15 Jul 2017 10:21:41 +0200 Subject: [PATCH 0133/1006] [maven-release-plugin] prepare release 1.2.0.CR1 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..7b23f35bb9 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..6e3560f2c0 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 6d26c56ee5..d68e8010ce 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c7718ea5f7..1d196bde41 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..3ef622f30d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..969c9330ca 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..53f05002e9 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index d186839760..6e43028b13 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.CR1 diff --git a/pom.xml b/pom.xml index 63b61ce435..5d09f56223 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.CR1 diff --git a/processor/pom.xml b/processor/pom.xml index ab7ae83a7c..61472ea253 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR1 ../parent/pom.xml From 0540a00263e5db6e7fca2230322065ba05b28885 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 15 Jul 2017 10:21:42 +0200 Subject: [PATCH 0134/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 7b23f35bb9..f857058844 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index 6e3560f2c0..d5555f9220 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index d68e8010ce..6d26c56ee5 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 1d196bde41..c7718ea5f7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 3ef622f30d..b2dcceaefa 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 969c9330ca..e24f75f1f6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 53f05002e9..0b8fb827cf 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 6e43028b13..d186839760 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.CR1 + HEAD diff --git a/pom.xml b/pom.xml index 5d09f56223..63b61ce435 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.CR1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 61472ea253..ab7ae83a7c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR1 + 1.2.0-SNAPSHOT ../parent/pom.xml From d0bd0a2fdf71ae2e00f97cade5b0220e6ff7f314 Mon Sep 17 00:00:00 2001 From: Darren Rambaud Date: Mon, 24 Jul 2017 12:33:46 -0500 Subject: [PATCH 0135/1006] Fixed a couple of typos (#1260) * Fixed 2 typos in the documentation --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index f52e7133ee..319f105b5b 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -305,7 +305,7 @@ In the generated method implementations all readable properties from the source [TIP] ==== -The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans spefication] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. +The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans specification] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. ==== [TIP] @@ -646,7 +646,7 @@ Note that mappers generated by MapStruct are thread-safe and thus can safely be If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection as well. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. -Currently there is support for CDI and Spring (the later either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: +Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: .A mapper using the CDI component model ==== From 2f4cf7c905acd99d055a00286c807fc630c96a2a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 16 Aug 2017 22:19:49 +0200 Subject: [PATCH 0136/1006] #748 Add note that the passed parameter to MappingTarget must not be null --- core-common/src/main/java/org/mapstruct/MappingTarget.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-common/src/main/java/org/mapstruct/MappingTarget.java b/core-common/src/main/java/org/mapstruct/MappingTarget.java index e7fe6f2285..f99c79885d 100644 --- a/core-common/src/main/java/org/mapstruct/MappingTarget.java +++ b/core-common/src/main/java/org/mapstruct/MappingTarget.java @@ -27,6 +27,8 @@ * Declares a parameter of a mapping method to be the target of the mapping. *

    * Not more than one parameter can be declared as {@code MappingTarget}. + *

    + * NOTE: The parameter passed as a mapping target must not be {@code null}. * * @author Andreas Gudian */ From 17da0cf912288b60f9f9d4e41611a81c7ea77a41 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 17 Aug 2017 00:10:04 +0200 Subject: [PATCH 0137/1006] #1231 Add japicmp for the MapStruct API --- core-jdk8/pom.xml | 4 ++++ core/pom.xml | 4 ++++ parent/pom.xml | 25 +++++++++++++++++++++++++ processor/pom.xml | 15 +++++++++++++++ 4 files changed, 48 insertions(+) diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 6d26c56ee5..b15220d69d 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -166,6 +166,10 @@ + + com.github.siom79.japicmp + japicmp-maven-plugin + diff --git a/core/pom.xml b/core/pom.xml index c7718ea5f7..8e8cbaaa9f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -157,6 +157,10 @@ + + com.github.siom79.japicmp + japicmp-maven-plugin + diff --git a/parent/pom.xml b/parent/pom.xml index d186839760..8c9b48bf65 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -516,6 +516,31 @@ + + com.github.siom79.japicmp + japicmp-maven-plugin + 0.10.0 + + + verify + + cmp + + + + + + + ${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging} + + + + \d+\.\d+\.\d+\.Final + true + + + + diff --git a/processor/pom.xml b/processor/pom.xml index ab7ae83a7c..834791ced2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -341,6 +341,21 @@ + + com.github.siom79.japicmp + japicmp-maven-plugin + + + + org.mapstruct.ap + + + org.mapstruct.ap.internal + org.mapstruct.ap.shaded + + + + From 6377e51efa837b08352ed6a219cd8534b1f1f60f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 18 Aug 2017 19:41:24 +0200 Subject: [PATCH 0138/1006] #1251 Deploy SNAPSHOTS from Travis CI --- .travis.yml | 7 +++++++ etc/travis-settings.xml | 11 +++++++++++ parent/pom.xml | 1 + 3 files changed, 19 insertions(+) create mode 100644 etc/travis-settings.xml diff --git a/.travis.yml b/.travis.yml index a9aec42c6d..9d4d9f6366 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,13 @@ script: mvn clean install -DprocessorIntegrationTest.toolchainsFile=etc/toolchai after_success: - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" +deploy: + provider: script + script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true deploy" + skip_cleanup: true + on: + branch: master + sudo: false cache: directories: diff --git a/etc/travis-settings.xml b/etc/travis-settings.xml new file mode 100644 index 0000000000..e267e9cd4d --- /dev/null +++ b/etc/travis-settings.xml @@ -0,0 +1,11 @@ + + + + sonatype-nexus-snapshots + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + diff --git a/parent/pom.xml b/parent/pom.xml index 8c9b48bf65..07f19905cf 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -559,6 +559,7 @@ **/LICENSE.txt **/mapstruct.xml **/toolchains-*.xml + **/travis-settings.xml **/eclipse-formatter-config.xml **/forbidden-apis.txt **/checkstyle-for-generated-sources.xml From 4d8bc29347e37bcf22d121829802e7f58603afbb Mon Sep 17 00:00:00 2001 From: sjaakd Date: Thu, 17 Aug 2017 22:57:17 +0200 Subject: [PATCH 0139/1006] #1255 Extension of autoInheritanceStrategy, removing of name based ignore reverse mapping --- .../mapstruct/MappingInheritanceStrategy.java | 18 ++++- .../mapstruct/itest/simple/AnimalTest.java | 12 --- .../ap/internal/model/source/Mapping.java | 10 +-- .../MappingInheritanceStrategyPrism.java | 30 +++++++- .../processor/MapperCreationProcessor.java | 63 ++++++++------- .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/test/bugs/_1255/AbstractA.java | 36 +++++++++ .../ap/test/bugs/_1255/Issue1255Test.java | 67 ++++++++++++++++ .../mapstruct/ap/test/bugs/_1255/SomeA.java | 36 +++++++++ .../mapstruct/ap/test/bugs/_1255/SomeB.java | 45 +++++++++++ .../ap/test/bugs/_1255/SomeMapper.java | 36 +++++++++ .../ap/test/bugs/_1255/SomeMapperConfig.java | 39 ++++++++++ .../ap/test/ignore/IgnorePropertyTest.java | 16 +--- .../AutoInheritedAllConfig.java | 40 ++++++++++ .../AutoInheritedReverseConfig.java | 40 ++++++++++ .../CarMapperAllWithAutoInheritance.java | 41 ++++++++++ .../CarMapperReverseWithAutoInheritance.java | 38 +++++++++ .../inheritfromconfig/Erroneous3Config.java | 46 +++++++++++ .../inheritfromconfig/Erroneous3Mapper.java | 37 +++++++++ .../ErroneousMapperAutoInheritance.java | 36 +++++++++ ...neousMapperReverseWithAutoInheritance.java | 38 +++++++++ .../InheritFromConfigTest.java | 77 +++++++++++++++++++ 22 files changed, 734 insertions(+), 68 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java diff --git a/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java b/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java index 082bfaf340..03f5ee0e77 100644 --- a/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java +++ b/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java @@ -32,8 +32,20 @@ public enum MappingInheritanceStrategy { EXPLICIT, /** - * Inherit the method-level configuration annotations automatically if source and target types of the prototype - * method are assignable from the types of a given mapping method. + * Inherit the method-level forward configuration annotations automatically if source and target types of the + * prototype method are assignable from the types of a given mapping method. */ - AUTO_INHERIT_FROM_CONFIG; + AUTO_INHERIT_FROM_CONFIG, + + /** + * Inherit the method-level reverse configuration annotations automatically if source and target types of the + * prototype method are assignable from the target and source types of a given mapping method. + */ + AUTO_INHERIT_REVERSE_FROM_CONFIG, + + /** + * Inherit the method-level forward and reverse configuration annotations automatically if source and target types + * of the prototype method are assignable from the types of a given mapping method. + */ + AUTO_INHERIT_ALL_FROM_CONFIG; } diff --git a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java index 4c7485f95f..26147bdf7b 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java +++ b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java @@ -46,18 +46,6 @@ public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { assertThat( animalDto.getColor() ).isNull(); } - @Test - public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenNameIsSame() { - AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); - - Animal animal = AnimalMapper.INSTANCE.animalDtoToAnimal( animalDto ); - - assertThat( animal ).isNotNull(); - assertThat( animalDto.getName() ).isEqualTo( "Bruno" ); - assertThat( animalDto.getSize() ).isEqualTo( 100 ); - assertThat( animal.getAge() ).isNull(); - } - @Test public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTargetAreSpecified() { AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index e26d431260..1536c54f7e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -398,17 +398,11 @@ private boolean hasPropertyInReverseMethod(String name, SourceMethod method) { public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory) { // mapping can only be reversed if the source was not a constant nor an expression nor a nested property - if ( constant != null || javaExpression != null ) { + // and the mapping is not a 'target-source-ignore' mapping + if ( constant != null || javaExpression != null || ( isIgnored && sourceName == null ) ) { return null; } - // should only ignore a property when 1) there is a sourceName defined or 2) there's a name match - if ( isIgnored ) { - if ( sourceName == null && !hasPropertyInReverseMethod( targetName, method ) ) { - return null; - } - } - Mapping reverse = new Mapping( sourceName != null ? targetName : null, null, // constant diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java index 4bf88d1198..5a18f80832 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java @@ -25,6 +25,32 @@ * @author Andreas Gudian */ public enum MappingInheritanceStrategyPrism { - EXPLICIT, - AUTO_INHERIT_FROM_CONFIG; + + EXPLICIT( false, false, false ), + AUTO_INHERIT_FROM_CONFIG( true, true, false ), + AUTO_INHERIT_REVERSE_FROM_CONFIG( true, false, true ), + AUTO_INHERIT_ALL_FROM_CONFIG( true, true, true ); + + private final boolean autoInherit; + private final boolean applyForward; + private final boolean applyReverse; + + MappingInheritanceStrategyPrism(boolean isAutoInherit, boolean applyForward, boolean applyReverse) { + this.autoInherit = isAutoInherit; + this.applyForward = applyForward; + this.applyReverse = applyReverse; + } + + public boolean isAutoInherit() { + return autoInherit; + } + + public boolean isApplyForward() { + return applyForward; + } + + public boolean isApplyReverse() { + return applyReverse; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index a6908c4afb..1ab5e94851 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -59,6 +59,7 @@ import org.mapstruct.ap.internal.prism.InheritConfigurationPrism; import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism; import org.mapstruct.ap.internal.prism.MapperPrism; +import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -67,7 +68,6 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; -import static org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism.AUTO_INHERIT_FROM_CONFIG; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.join; @@ -446,41 +446,48 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp initializingMethods, mapperConfig ); + MappingInheritanceStrategyPrism inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy(); + if ( templateMappingOptions != null ) { mappingOptions.applyInheritedOptions( templateMappingOptions, false, method, messager, typeFactory ); } else if ( inverseMappingOptions != null ) { mappingOptions.applyInheritedOptions( inverseMappingOptions, true, method, messager, typeFactory ); } - else if ( mapperConfig.getMappingInheritanceStrategy() == AUTO_INHERIT_FROM_CONFIG ) { - if ( applicablePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( - first( applicablePrototypeMethods ).getMappingOptions(), - false, - method, - messager, - typeFactory ); - } - else if ( applicablePrototypeMethods.size() > 1 ) { - messager.printMessage( - method.getExecutable(), - Message.INHERITCONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, - Strings.join( applicablePrototypeMethods, ", " ) ); + else if ( inheritanceStrategy.isAutoInherit() ) { + + if ( inheritanceStrategy.isApplyForward() ) { + if ( applicablePrototypeMethods.size() == 1 ) { + mappingOptions.applyInheritedOptions( + first( applicablePrototypeMethods ).getMappingOptions(), + false, + method, + messager, + typeFactory ); + } + else if ( applicablePrototypeMethods.size() > 1 ) { + messager.printMessage( + method.getExecutable(), + Message.INHERITCONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, + Strings.join( applicablePrototypeMethods, ", " ) ); + } } - if ( applicableReversePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( - first( applicableReversePrototypeMethods ).getMappingOptions(), - true, - method, - messager, - typeFactory ); - } - else if ( applicableReversePrototypeMethods.size() > 1 ) { - messager.printMessage( - method.getExecutable(), - Message.INHERITINVERSECONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, - Strings.join( applicablePrototypeMethods, ", " ) ); + if ( inheritanceStrategy.isApplyReverse() ) { + if ( applicableReversePrototypeMethods.size() == 1 ) { + mappingOptions.applyInheritedOptions( + first( applicableReversePrototypeMethods ).getMappingOptions(), + true, + method, + messager, + typeFactory ); + } + else if ( applicableReversePrototypeMethods.size() > 1 ) { + messager.printMessage( + method.getExecutable(), + Message.INHERITINVERSECONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH, + Strings.join( applicableReversePrototypeMethods, ", " ) ); + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 49edbef593..e3bd87950c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -47,6 +47,7 @@ public enum Message { PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ), PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ), + PROPERTYMAPPING_SOURCE_AND_IGNORE_BOTH_DEFINED( "Source and ignore are both defined in @Mapping, make explicit in reverse mapping when the intent is to ignore the reverse mapping." ), PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED( "Source and expression are both defined in @Mapping, either define a source or an expression." ), PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ), PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED( "Expression and default value are both defined in @Mapping, either define a defaultValue or an expression." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java new file mode 100644 index 0000000000..0b9c107ca8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +/** + * + * @author Sjaak Derksen + */ +public abstract class AbstractA { + + private String field1; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java new file mode 100644 index 0000000000..924e8533bc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java @@ -0,0 +1,67 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * + * @author Sjaak Derksen + */ +@IssueKey("1255") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + AbstractA.class, + SomeA.class, + SomeB.class, + SomeMapper.class, + SomeMapperConfig.class}) +public class Issue1255Test { + + @Test + public void shouldMapSomeBToSomeAWithoutField1() throws Exception { + SomeB someB = new SomeB(); + someB.setField1( "value1" ); + someB.setField2( "value2" ); + + SomeA someA = SomeMapper.INSTANCE.toSomeA( someB ); + + assertThat( someA.getField1() ) + .isNotEqualTo( someB.getField1() ) + .isNull(); + assertThat( someA.getField2() ).isEqualTo( someB.getField2() ); + } + + @Test + public void shouldMapSomeAToSomeB() throws Exception { + SomeA someA = new SomeA(); + someA.setField1( "value1" ); + someA.setField2( "value2" ); + + SomeB someB = SomeMapper.INSTANCE.toSomeB( someA ); + + assertThat( someB.getField1() ).isEqualTo( someA.getField1() ); + assertThat( someB.getField2() ).isEqualTo( someA.getField2() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java new file mode 100644 index 0000000000..a9e030f7dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +/** + * + * @author Sjaak Derksen + */ +public class SomeA extends AbstractA { + + private String field2; + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java new file mode 100644 index 0000000000..1820b96764 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +/** + * + * @author Sjaak Derksen + */ +public class SomeB { + + private String field1; + private String field2; + + public String getField1() { + return field1; + } + + public void setField1(String field1) { + this.field1 = field1; + } + + public String getField2() { + return field2; + } + + public void setField2(String field2) { + this.field2 = field2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java new file mode 100644 index 0000000000..0fb3137c05 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper(config = SomeMapperConfig.class) +public interface SomeMapper { + + SomeMapper INSTANCE = Mappers.getMapper( SomeMapper.class ); + + SomeA toSomeA(SomeB source); + + SomeB toSomeB(SomeA source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java new file mode 100644 index 0000000000..dfe711f50e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1255; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.Mappings; + +/** + * + * @author Sjaak Derksen + */ +@MapperConfig( + mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG +) +public interface SomeMapperConfig { + + @Mappings({ + @Mapping(target = "field1", ignore = true) + }) + AbstractA toAbstractA(SomeB source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 525d18f7bf..170fe31136 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -56,23 +56,9 @@ public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { assertThat( animalDto.publicColor ).isNull(); } - @Test - @IssueKey("72") - public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenNameIsSame() { - AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); - - Animal animal = AnimalMapper.INSTANCE.animalDtoToAnimal( animalDto ); - - assertThat( animal ).isNotNull(); - assertThat( animalDto.getName() ).isEqualTo( "Bruno" ); - assertThat( animalDto.getSize() ).isEqualTo( 100 ); - assertThat( animal.getAge() ).isNull(); - assertThat( animal.publicAge ).isNull(); - } - @Test @IssueKey("337") - public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTargetAreSpecified() { + public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore() { AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); Animal animal = AnimalMapper.INSTANCE.animalDtoToAnimal( animalDto ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java new file mode 100644 index 0000000000..c9ab6eddc6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; + +/** + * @author Sjaak Derksen + */ +@MapperConfig( + mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG, + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface AutoInheritedAllConfig { + @Mappings({ + @Mapping(target = "primaryKey", source = "id"), + @Mapping(target = "auditTrail", ignore = true) + }) + BaseVehicleEntity baseDtoToEntity(BaseVehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java new file mode 100644 index 0000000000..5be48cc9e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; + +/** + * @author Sjaak Derksen + */ +@MapperConfig( + mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_REVERSE_FROM_CONFIG, + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface AutoInheritedReverseConfig { + @Mappings({ + @Mapping(target = "primaryKey", source = "id"), + @Mapping(target = "auditTrail", ignore = true) + }) + BaseVehicleEntity baseDtoToEntity(BaseVehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java new file mode 100644 index 0000000000..12eed022d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( + config = AutoInheritedAllConfig.class +) +public abstract class CarMapperAllWithAutoInheritance { + public static final CarMapperAllWithAutoInheritance INSTANCE = + Mappers.getMapper( CarMapperAllWithAutoInheritance.class ); + + @Mapping(target = "color", source = "colour") + public abstract CarEntity toCarEntity(CarDto carDto); + + @Mapping( target = "colour", source = "color" ) + public abstract CarDto toCarDto(CarEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java new file mode 100644 index 0000000000..041f4e172b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( + config = AutoInheritedReverseConfig.class +) +public abstract class CarMapperReverseWithAutoInheritance { + public static final CarMapperReverseWithAutoInheritance INSTANCE = + Mappers.getMapper( CarMapperReverseWithAutoInheritance.class ); + + @Mapping( target = "colour", source = "color" ) + public abstract CarDto toCarDto(CarEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java new file mode 100644 index 0000000000..ad53c8510e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; + +/** + * @author Sjaak Derksen + */ +@MapperConfig( + mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_REVERSE_FROM_CONFIG, + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface Erroneous3Config { + @Mappings({ + @Mapping(target = "primaryKey", source = "id"), + @Mapping(target = "auditTrail", ignore = true) + }) + BaseVehicleEntity baseDtoToEntity(BaseVehicleDto dto); + + @Mappings({ + @Mapping(target = "primaryKey", source = "id"), + @Mapping(target = "auditTrail", ignore = true) + }) + BaseVehicleEntity baseDtoToEntity2(BaseVehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java new file mode 100644 index 0000000000..34fae8634e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( + config = Erroneous3Config.class +) +public abstract class Erroneous3Mapper { + public static final Erroneous3Mapper INSTANCE = Mappers.getMapper( Erroneous3Mapper.class ); + + @Mapping( target = "colour", source = "color" ) + public abstract CarDto toCarDto(CarEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java new file mode 100644 index 0000000000..8e7dccfb13 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( + config = AutoInheritedReverseConfig.class +) +public interface ErroneousMapperAutoInheritance { + ErroneousMapperAutoInheritance INSTANCE = Mappers.getMapper( ErroneousMapperAutoInheritance.class ); + + @Mapping(target = "color", source = "colour") + CarEntity toCarEntity(CarDto carDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java new file mode 100644 index 0000000000..7a32767a4f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( + config = AutoInheritedConfig.class +) +public abstract class ErroneousMapperReverseWithAutoInheritance { + public static final ErroneousMapperReverseWithAutoInheritance INSTANCE = + Mappers.getMapper( ErroneousMapperReverseWithAutoInheritance.class ); + + @Mapping( target = "colour", source = "color" ) + public abstract CarDto toCarDto(CarEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index c3f6fd5bf9..2cd07e7d0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -140,6 +140,35 @@ public void explicitInheritedMappingIsAppliedInReverseDirectlyFromConfig() { assertThat( carDto.getId() ).isEqualTo( 42L ); } + @Test + @IssueKey( "1255" ) + @WithClasses({ CarMapperReverseWithAutoInheritance.class, AutoInheritedReverseConfig.class } ) + public void autoInheritedMappingIsAppliedInReverseDirectlyFromConfig() { + + CarEntity carEntity = new CarEntity(); + carEntity.setColor( "red" ); + carEntity.setPrimaryKey( 42L ); + + CarDto carDto = CarMapperReverseWithAutoInheritance.INSTANCE.toCarDto( carEntity ); + + assertThat( carDto.getColour() ).isEqualTo( "red" ); + assertThat( carDto.getId() ).isEqualTo( 42L ); + } + + @Test + @IssueKey( "1255" ) + @WithClasses({ CarMapperAllWithAutoInheritance.class, AutoInheritedAllConfig.class } ) + public void autoInheritedMappingIsAppliedInForwardAndReverseDirectlyFromConfig() { + + CarDto carDto = newTestDto(); + + CarEntity carEntity = CarMapperAllWithAutoInheritance.INSTANCE.toCarEntity( carDto ); + CarDto carDto2 = CarMapperAllWithAutoInheritance.INSTANCE.toCarDto( carEntity ); + + assertThat( carDto.getColour() ).isEqualTo( carDto2.getColour() ); + assertThat( carDto.getId() ).isEqualTo( carDto2.getId() ); + } + @Test public void explicitInheritedMappingWithTwoLevelsIsOverriddenAtMethodLevel() { CarDto carDto = newTestDto(); @@ -230,4 +259,52 @@ public void erroneous1MultiplePrototypeMethodsMatch() { public void erroneous2InheritanceCycle() { } + + @Test + @IssueKey( "1255" ) + @WithClasses({ ErroneousMapperAutoInheritance.class, AutoInheritedReverseConfig.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapperAutoInheritance.class, + kind = Kind.ERROR, + line = 35, + messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\.") + } + ) + public void erroneousWrongReverseConfigInherited() { } + + @Test + @IssueKey( "1255" ) + @WithClasses({ ErroneousMapperReverseWithAutoInheritance.class, AutoInheritedConfig.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapperReverseWithAutoInheritance.class, + kind = Kind.ERROR, + line = 36, + messageRegExp = "Unmapped target property: \"id\"\\.") + } + ) + public void erroneousWrongConfigInherited() { } + + @Test + @IssueKey( "1255" ) + @WithClasses({ Erroneous3Mapper.class, Erroneous3Config.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Erroneous3Mapper.class, + kind = Kind.ERROR, + line = 35, + messageRegExp = "More than one configuration prototype method is applicable. " + + "Use @InheritInverseConfiguration.*"), + @Diagnostic(type = Erroneous3Mapper.class, + kind = Kind.ERROR, + line = 35, + messageRegExp = "Unmapped target property: \"id\"\\.") + } + ) + public void erroneousDuplicateReverse() { } + } From 5cead7ae5e09ecc07739265e263dd366b3c8d0cf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 27 Aug 2017 18:59:17 +0200 Subject: [PATCH 0140/1006] #1269 use update methods for different sources for nested targets --- .../controlling-nested-bean-mappings.asciidoc | 6 ++ .../NestedTargetPropertyMappingHolder.java | 32 ++++++-- .../ap/test/bugs/_1269/Issue1269Test.java | 78 +++++++++++++++++++ .../ap/test/bugs/_1269/dto/VehicleDto.java | 36 +++++++++ .../test/bugs/_1269/dto/VehicleImageDto.java | 45 +++++++++++ .../test/bugs/_1269/dto/VehicleInfoDto.java | 68 ++++++++++++++++ .../test/bugs/_1269/mapper/VehicleMapper.java | 40 ++++++++++ .../ap/test/bugs/_1269/model/Vehicle.java | 44 +++++++++++ .../test/bugs/_1269/model/VehicleImage.java | 42 ++++++++++ .../bugs/_1269/model/VehicleTypeInfo.java | 49 ++++++++++++ 10 files changed, 435 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java diff --git a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc index 4fdcdf5570..113d39bdcc 100644 --- a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc +++ b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc @@ -85,3 +85,9 @@ Instead of configuring everything via the parent method we encourage users to ex This puts the configuration of the nested mapping into one place (method) where it can be reused from several methods in the upper level, instead of re-configuring the same things on all of those upper methods. ==== + +[NOTE] +==== +In some cases the `ReportingPolicy` that is going to be used for the generated nested method would be `IGNORE`. +This means that it is possible for MapStruct not to report unmapped target properties in nested mappings. +==== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 730b91c1e7..7dd3ca680a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -155,7 +155,8 @@ public NestedTargetPropertyMappingHolder build() { entryByTP.getValue(), groupedByTP.singleTargetReferences.get( targetProperty ) ); - boolean forceUpdateMethod = groupedBySourceParam.groupedBySourceParameter.keySet().size() > 1; + boolean multipleSourceParametersForTP = + groupedBySourceParam.groupedBySourceParameter.keySet().size() > 1; // All not processed mappings that should have been applied to all are part of the unprocessed // defined targets @@ -180,9 +181,21 @@ public NestedTargetPropertyMappingHolder build() { .groupedBySourceReferences .entrySet() ) { PropertyEntry sourceEntry = entryBySP.getKey(); + boolean forceUpdateMethodOrNonNestedReferencesPresent = + multipleSourceParametersForTP || !groupedSourceReferences.nonNested.isEmpty(); + // If there are multiple source parameters that are mapped to the target reference + // then we restrict the mapping only to the defined mappings. And we create MappingOptions + // for forged methods (which means that any unmapped target properties are ignored) + // MappingOptions for forged methods is also created if we have something like this: + //@Mappings({ + // @Mapping(target = "vehicleInfo", source = "vehicleTypeInfo"), + // @Mapping(target = "vehicleInfo.images", source = "images") + //}) + // See Issue1269Test, Issue1247Test, AutomappingAndNestedTest for more info as well MappingOptions sourceMappingOptions = MappingOptions.forMappingsOnly( groupByTargetName( entryBySP.getValue() ), - forceUpdateMethod + multipleSourceParametersForTP, + forceUpdateMethodOrNonNestedReferencesPresent ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) @@ -192,11 +205,14 @@ public NestedTargetPropertyMappingHolder build() { .name( targetProperty.getName() ) .build(); + // If we have multiple source parameters that are mapped to the target reference, or + // parts of the nested properties are mapped to different sources (see comment above as well) + // we would force an update method PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( sourceMappingOptions, targetProperty, sourceRef, - forceUpdateMethod + forceUpdateMethodOrNonNestedReferencesPresent ); if ( propertyMapping != null ) { @@ -219,11 +235,17 @@ public NestedTargetPropertyMappingHolder build() { .name( targetProperty.getName() ) .build(); + boolean forceUpdateMethodForNonNested = + multipleSourceParametersForTP || + !groupedSourceReferences.groupedBySourceReferences.isEmpty(); + // If an update method is forced or there are groupedBySourceReferences then we must create + // an update method. The reason is that they might be for the same reference and we should + // use update for it PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( nonNestedOptions, targetProperty, reference, - forceUpdateMethod + forceUpdateMethodForNonNested ); if ( propertyMapping != null ) { @@ -237,7 +259,7 @@ public NestedTargetPropertyMappingHolder build() { groupedSourceReferences.sourceParameterMappings, targetProperty, sourceParameter, - forceUpdateMethod + multipleSourceParametersForTP ); unprocessedDefinedTarget.put( targetProperty, groupedSourceReferences.notProcessedAppliesToAll ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java new file mode 100644 index 0000000000..9329eddabb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java @@ -0,0 +1,78 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._1269.dto.VehicleDto; +import org.mapstruct.ap.test.bugs._1269.dto.VehicleImageDto; +import org.mapstruct.ap.test.bugs._1269.dto.VehicleInfoDto; +import org.mapstruct.ap.test.bugs._1269.mapper.VehicleMapper; +import org.mapstruct.ap.test.bugs._1269.model.Vehicle; +import org.mapstruct.ap.test.bugs._1269.model.VehicleImage; +import org.mapstruct.ap.test.bugs._1269.model.VehicleTypeInfo; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey( "1269" ) +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( { + VehicleDto.class, + VehicleImageDto.class, + VehicleInfoDto.class, + Vehicle.class, + VehicleImage.class, + VehicleTypeInfo.class, + VehicleMapper.class +} ) +public class Issue1269Test { + + @Test + public void shouldMapNestedPropertiesCorrectly() { + + VehicleTypeInfo sourceTypeInfo = new VehicleTypeInfo( "Opel", "Corsa", 3 ); + + List sourceImages = Arrays.asList( + new VehicleImage( 100, "something" ), + new VehicleImage( 150, "somethingElse" ) + ); + Vehicle source = new Vehicle( sourceTypeInfo, sourceImages ); + + VehicleDto target = VehicleMapper.INSTANCE.map( source ); + + assertThat( target.getVehicleInfo() ).isNotNull(); + assertThat( target.getVehicleInfo().getDoors() ).isEqualTo( 3 ); + assertThat( target.getVehicleInfo().getType() ).isEqualTo( "Opel" ); + assertThat( target.getVehicleInfo().getName() ).isEqualTo( "Corsa" ); + assertThat( target.getVehicleInfo().getImages() ).hasSize( 2 ); + assertThat( target.getVehicleInfo().getImages().get( 0 ) ) + .isEqualToComparingFieldByField( sourceImages.get( 0 ) ); + assertThat( target.getVehicleInfo().getImages().get( 1 ) ) + .isEqualToComparingFieldByField( sourceImages.get( 1 ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java new file mode 100755 index 0000000000..046972b5f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.dto; + +/** + * @author Filip Hrisafov + */ +public class VehicleDto { + + private VehicleInfoDto vehicleInfo; + + public VehicleInfoDto getVehicleInfo() { + return vehicleInfo; + } + + public void setVehicleInfo(VehicleInfoDto vehicleInfo) { + this.vehicleInfo = vehicleInfo; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java new file mode 100755 index 0000000000..50de755f7b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.dto; + +/** + * @author Filip Hrisafov + */ +public class VehicleImageDto { + + private Integer pictureSize; + + private String src; + + public Integer getPictureSize() { + return pictureSize; + } + + public void setPictureSize(Integer pictureSize) { + this.pictureSize = pictureSize; + } + + public String getSrc() { + return src; + } + + public void setSrc(String src) { + this.src = src; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java new file mode 100755 index 0000000000..55f6ef7ddc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.dto; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class VehicleInfoDto { + + private String type; + + private String name; + + private Integer doors; + + // make sure that mapping on images does not happen based on images mapping + private List images; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getDoors() { + return doors; + } + + public void setDoors(Integer doors) { + this.doors = doors; + } + + public List getImages() { + return images; + } + + public void setImages(List images) { + this.images = images; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java new file mode 100755 index 0000000000..9db3fdfb0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.bugs._1269.dto.VehicleDto; +import org.mapstruct.ap.test.bugs._1269.model.Vehicle; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface VehicleMapper { + VehicleMapper INSTANCE = Mappers.getMapper( VehicleMapper.class ); + + @Mappings({ + @Mapping(target = "vehicleInfo", source = "vehicleTypeInfo"), + @Mapping(target = "vehicleInfo.images", source = "images") + }) + VehicleDto map(Vehicle in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java new file mode 100755 index 0000000000..ba19f8d16c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.model; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Vehicle { + + private final VehicleTypeInfo vehicleTypeInfo; + + private final List images; + + public Vehicle(VehicleTypeInfo vehicleTypeInfo, List images) { + this.vehicleTypeInfo = vehicleTypeInfo; + this.images = images; + } + + public VehicleTypeInfo getVehicleTypeInfo() { + return vehicleTypeInfo; + } + + public List getImages() { + return images; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java new file mode 100755 index 0000000000..f9ff4fed44 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.model; + +/** + * @author Filip Hrisafov + */ +public class VehicleImage { + + private final Integer pictureSize; + + private final String src; + + public VehicleImage(Integer pictureSize, String src) { + this.pictureSize = pictureSize; + this.src = src; + } + + public Integer getPictureSize() { + return pictureSize; + } + + public String getSrc() { + return src; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java new file mode 100755 index 0000000000..dc803dc520 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1269.model; + +/** + * @author Filip Hrisafov + */ +public class VehicleTypeInfo { + + private final String type; + + private final String name; + + private final Integer doors; + + public VehicleTypeInfo(String type, String name, Integer doors) { + this.type = type; + this.name = name; + this.doors = doors; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public Integer getDoors() { + return doors; + } +} From 322e77e52be00e17984a641c361e0ff93e8cbe61 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 28 Aug 2017 20:22:54 +0200 Subject: [PATCH 0141/1006] [maven-release-plugin] prepare release 1.2.0.CR2 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..94c7a675e0 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..6cff8be3b3 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index b15220d69d..7245bc891c 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8e8cbaaa9f..ea3667dd25 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..4a9b8ecfba 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..98646e4178 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..cf3d38d441 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 07f19905cf..37ed5e77bb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.CR2 diff --git a/pom.xml b/pom.xml index 63b61ce435..ee50721860 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.CR2 diff --git a/processor/pom.xml b/processor/pom.xml index 834791ced2..b3423ab21a 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.CR2 ../parent/pom.xml From e79949ed0f5e9af69342e014cd78c9366ff10343 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 28 Aug 2017 20:22:54 +0200 Subject: [PATCH 0142/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 94c7a675e0..f857058844 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index 6cff8be3b3..d5555f9220 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 7245bc891c..b15220d69d 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ea3667dd25..8e8cbaaa9f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4a9b8ecfba..b2dcceaefa 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 98646e4178..e24f75f1f6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index cf3d38d441..0b8fb827cf 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 37ed5e77bb..07f19905cf 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT pom MapStruct Parent @@ -74,7 +74,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.CR2 + HEAD diff --git a/pom.xml b/pom.xml index ee50721860..63b61ce435 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT parent/pom.xml @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.CR2 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index b3423ab21a..834791ced2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.CR2 + 1.2.0-SNAPSHOT ../parent/pom.xml From 1be6d352bbd71f29034bca34819b41872e152224 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 3 Sep 2017 13:03:53 +0200 Subject: [PATCH 0143/1006] Switch to OpenJDK 7 on Travis (Oracle Java 7 is no longer present) --- etc/toolchains-travis-jenkins.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/toolchains-travis-jenkins.xml b/etc/toolchains-travis-jenkins.xml index 8d49c8e7ef..75ac0de574 100644 --- a/etc/toolchains-travis-jenkins.xml +++ b/etc/toolchains-travis-jenkins.xml @@ -19,7 +19,7 @@ jdk1.7 - /usr/lib/jvm/java-7-oracle/ + /usr/lib/jvm/java-7-openjdk-amd64/ From 079d14d12e986f962fe394e53ac7026b3718762c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 3 Sep 2017 16:30:19 +0200 Subject: [PATCH 0144/1006] Run build in VM (fixes issues when build is killed by Travis containers) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9d4d9f6366..8ce15e93ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ deploy: on: branch: master -sudo: false +sudo: required cache: directories: - $HOME/.m2 From 47697a2391acc3c22b990420c2358f574d291a11 Mon Sep 17 00:00:00 2001 From: Thomas Eckl <31189692+ecktoteckto@users.noreply.github.com> Date: Sun, 3 Sep 2017 18:42:01 +0200 Subject: [PATCH 0145/1006] Fix a few errors in reference guide and readme --- .../controlling-nested-bean-mappings.asciidoc | 2 +- .../mapstruct-reference-guide.asciidoc | 32 ++++++++++--------- readme.md | 4 +-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc index 113d39bdcc..18e9f54998 100644 --- a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc +++ b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc @@ -74,7 +74,7 @@ public interface FishTankMapperWithDocument { Note what happens in `@Mapping(target="quality.document", source="quality.report")`. `DocumentDto` does not exist as such on the target side. It is mapped from `Report`. -MapStruct continues to generate mapping code here. That mapping it self can be guided towards another name. +MapStruct continues to generate mapping code here. That mapping itself can be guided towards another name. This even works for constants and expression. Which is shown in the final example: `@Mapping(target="quality.document.organisation.name", constant="NoIdeaInc")`. MapStruct will perform a null check on each nested property in the source. diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 319f105b5b..ca8cdf66f7 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -31,7 +31,9 @@ Compared to dynamic mapping frameworks, MapStruct offers the following advantage * Fast execution by using plain method invocations instead of reflection * Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc. -* Clear error-reports at build time, if entities or attributes can't be mapped +* Clear error-reports at build time, if + ** mappings are incomplete (not all target properties are mapped) + ** mappings are incorrect (cannot find a proper mapping method or type conversion) [[setup]] == Set up @@ -261,7 +263,7 @@ If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, MapStruct can be used with Java 9, but as that Java version has not been finalized yet, support for it is experimental. -A core theme of Java 9 is the modularization of the JDK. One effect of this that a specific module need to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. +A core theme of Java 9 is the modularization of the JDK. One effect of this is that a specific module needs to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. To allow usage of the `@Generated` annotation the module _java.annotations.common_ must be enabled. When using Maven, this can be done like this: @@ -526,7 +528,7 @@ considered as a write accessor. Small example: -.Examples classes for mapping +.Example classes for mapping ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -815,9 +817,9 @@ That way it is possible to map arbitrary deep object graphs. When mapping from e When generating the implementation of a mapping method, MapStruct will apply the following routine for each attribute pair in the source and target object: * If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. -* If source and target attribute type differ, check whether there is a another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. +* If source and target attribute type differ, check whether there is another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. * If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. -* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes +* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. * If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. [NOTE] @@ -1013,13 +1015,13 @@ When working with JAXB, e.g. when converting a `String` to a corresponding `JAXB [[selection-based-on-qualifiers]] === Mapping method selection based on qualifiers -In many occasions one requires mapping methods with the same method signature (appart from the name) that have different behavior. +In many occasions one requires mapping methods with the same method signature (apart from the name) that have different behavior. MapStruct has a handy mechanism to deal with such situations: `@Qualifier` (`org.mapstruct.Qualifier`). A ‘qualifier’ is a custom annotation that the user can write, ‘stick onto’ a mapping method which is included as used mapper and can be referred to in a bean property mapping, iterable mapping or map mapping. Multiple qualifiers can be ‘stuck onto’ a method and mapping. -So, lets say there is a hand-written method to map titles with a `String` return type and `String` argument amongst many other referenced mappers with the same `String` return type - `String` argument signature: +So, let's say there is a hand-written method to map titles with a `String` return type and `String` argument amongst many other referenced mappers with the same `String` return type - `String` argument signature: .Several mapping methods with identical source and target types ==== @@ -1354,7 +1356,7 @@ public Map stringStringMapToLongDateMap(Map source) MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED`, `ADDER_PREFERRED` and `TARGET_IMMUTABLE`. -In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are apply to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: +In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are applied to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: .Collection mapping strategy options |=== @@ -1391,11 +1393,11 @@ In the table below, the dash `-` indicates a property name. Next, the trailing ` Some background: An `adder` method is typically used in case of http://www.eclipse.org/webtools/dali/[generated (JPA) entities], to add a single element (entity) to an underlying collection. Invoking the adder establishes a parent-child relation between parent - the bean (entity) on which the adder is invoked - and its child(ren), the elements (entities) in the collection. To find the appropriate `adder`, MapStruct will try to make a match between the generic parameter type of the underlying collection and the single argument of a candidate `adder`. When there are more candidates, the plural `setter` / `getter` name is converted to singular and will be used in addition to make a match. -The option `DEFAULT` should not be used explicitely. It is used to distinguish between an explicit user desire to override the default in a `@MapperConfig` from the implicit Mapstruct choice in a `@Mapper`. The option `DEFAULT` is synonymous to `ACCESSOR_ONLY`. +The option `DEFAULT` should not be used explicitly. It is used to distinguish between an explicit user desire to override the default in a `@MapperConfig` from the implicit Mapstruct choice in a `@Mapper`. The option `DEFAULT` is synonymous to `ACCESSOR_ONLY`. [TIP] ==== -When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with intialized collections in stead of Mapstruct creating the target entity by its constructor. +When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with intialized collections instead of Mapstruct creating the target entity by its constructor. ==== [[implementation-types-for-collection-mappings]] @@ -1756,7 +1758,7 @@ This chapter describes several advanced options which allow to fine-tune the beh Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values and are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. -A mapping with a constant must not include a reference to a source property. The following examples shows some mappings using default values and constants: +A mapping with a constant must not include a reference to a source property. The following example shows some mappings using default values and constants: .Mapping method with default values and constants ==== @@ -1811,7 +1813,7 @@ public interface SourceTargetMapper { ---- ==== -The example demonstrates how the source properties `time` and `format` are composed into one target property `TimeAndFormat`. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `TimeAndFormat` class (unless its used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining `imports` on the `@Mapper` annotation. +The example demonstrates how the source properties `time` and `format` are composed into one target property `TimeAndFormat`. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `TimeAndFormat` class (unless it's used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining `imports` on the `@Mapper` annotation. .Declaring an import ==== @@ -1835,7 +1837,7 @@ public interface SourceTargetMapper { [[determining-result-type]] === Determining the result type -When result types have an inheritance relation, selecting either mapping method (`@Mapping`) or a factory method (`@BeanMapping`) can becomes ambigious. Suppose an Apple and a Banana, which is are both specializations of Fruit. +When result types have an inheritance relation, selecting either mapping method (`@Mapping`) or a factory method (`@BeanMapping`) can become ambiguous. Suppose an Apple and a Banana, which are both specializations of Fruit. .Specifying the result type of a bean mapping method ==== @@ -1898,7 +1900,7 @@ The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` MapStruct offers control over when to generate a `null` check. By default (`nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION`) a `null` check will be generated for: -* direct setting of source value to target value when target is primitive and is source not. +* direct setting of source value to target value when target is primitive and source is not. * applying type conversion and then: .. calling the setter on the target. .. calling another type conversion and subsequently calling the setter on the target. @@ -2542,7 +2544,7 @@ The `CustomAccessorNamingStrategy` makes use of the `DefaultAccessorNamingStrate To use a custom SPI implementation, it must be located in a separate JAR file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). [TIP] -Fore more details: There's the above example is present in our our examples repository (https://github.com/mapstruct/mapstruct-examples). +Fore more details: The example above is present in our examples repository (https://github.com/mapstruct/mapstruct-examples). [mapping-exclusion-provider] === Mapping Exclusion Provider diff --git a/readme.md b/readme.md index 0f16d2afca..0c79fdfd01 100644 --- a/readme.md +++ b/readme.md @@ -45,8 +45,8 @@ Compared to mapping frameworks working at runtime MapStruct offers the following * Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc. * Self-contained code, no runtime dependencies * Clear error-reports at build time if - * mappings are incomplete (not all target properties are mapped) - * mappings are incorrect (cannot find a proper mapping method or type conversion) + * mappings are incomplete (not all target properties are mapped) + * mappings are incorrect (cannot find a proper mapping method or type conversion) * Mapping code is easy to debug (or edited by hand e.g. in case of a bug in the generator) ## Requirements From 779c16cc2ab4cb51d3b7ce126e2ced3a6711c492 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 7 Sep 2017 17:44:53 +0200 Subject: [PATCH 0146/1006] #1283 Handle no suitable empty constructor during BeanMappingMethod creation --- .../ap/internal/model/BeanMappingMethod.java | 15 ++++ .../ap/internal/model/common/Type.java | 3 +- .../internal/model/source/SourceMethod.java | 11 --- .../model/source/TargetReference.java | 30 +++++--- .../processor/MapperCreationProcessor.java | 20 ------ .../mapstruct/ap/internal/util/Message.java | 2 +- .../ap/test/bugs/_1242/Issue1242Test.java | 6 +- ...eTargetHasNoSuitableConstructorMapper.java | 36 ++++++++++ ...sTargetHasNoSuitableConstructorMapper.java | 32 +++++++++ .../ap/test/bugs/_1283/Issue1283Test.java | 70 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1283/Source.java | 39 +++++++++++ .../mapstruct/ap/test/bugs/_1283/Target.java | 35 ++++++++++ .../AmbiguousAnnotatedFactoryTest.java | 8 ++- .../ambiguousfactorymethod/FactoryTest.java | 7 +- .../NestedSourcePropertiesTest.java | 2 +- .../selection/generics/ConversionTest.java | 8 ++- ...ousResultTypeNoEmptyConstructorMapper.java | 34 +++++++++ .../resulttype/InheritanceSelectionTest.java | 21 +++++- .../test/updatemethods/UpdateMethodsTest.java | 10 ++- 19 files changed, 338 insertions(+), 51 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 484b93b40e..21e918eb5e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -190,6 +190,14 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) { Message.BEANMAPPING_NOT_ASSIGNABLE, resultType, method.getResultType() ); } + else if ( !resultType.hasEmptyAccessibleContructor() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + beanMappingPrism.mirror, + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + resultType + ); + } } else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { ctx.getMessager().printMessage( @@ -198,6 +206,13 @@ else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { method.getReturnType() ); } + else if ( !method.isUpdateMethod() && !method.getReturnType().hasEmptyAccessibleContructor() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + method.getReturnType() + ); + } } sortPropertyMappingsByDependencies(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index c668b207f5..d9ae2d68f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -863,8 +863,7 @@ public boolean hasEmptyAccessibleContructor() { hasEmptyAccessibleContructor = false; List constructors = ElementFilter.constructorsIn( typeElement.getEnclosedElements() ); for ( ExecutableElement constructor : constructors ) { - if ( (constructor.getModifiers().contains( Modifier.PUBLIC ) - || constructor.getModifiers().contains( Modifier.PROTECTED ) ) + if ( !constructor.getModifiers().contains( Modifier.PRIVATE ) && constructor.getParameters().isEmpty() ) { hasEmptyAccessibleContructor = true; break; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 73ebc0825c..e678a43723 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -386,17 +386,6 @@ public boolean isEnumMapping() { return isEnumMapping; } - public boolean isBeanMapping() { - if ( isBeanMapping == null ) { - isBeanMapping = !isIterableMapping() - && !isMapMapping() - && !isEnumMapping() - && !isValueMapping() - && !isStreamMapping(); - } - return isBeanMapping; - } - /** * The default enum mapping (no mappings specified) will from now on be handled as a value mapping. If there * are any @Mapping / @Mappings defined on the method, then the deprecated enum behavior should be executed. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index ce19c078f7..bd51a09481 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -23,16 +23,17 @@ import java.util.List; import java.util.Set; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.DeclaredType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; - import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -161,7 +162,7 @@ && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParamete if ( !foundEntryMatch && errorMessage != null) { // This is called only for reporting errors - errorMessage.report(); + errorMessage.report( isReverse ); } // foundEntryMatch = isValid, errors are handled here, and the BeanMapping uses that to ignore @@ -364,14 +365,21 @@ private MappingErrorMessage(Mapping mapping, SourceMethod method, FormattingMess this.messager = messager; } - abstract void report(); + abstract void report(boolean isReverse); - protected void printErrorMessage(Message message, Object... args) { + protected void printErrorMessage(Message message, boolean isReverse, Object... args) { Object[] errorArgs = new Object[args.length + 2]; errorArgs[0] = mapping.getTargetName(); errorArgs[1] = method.getResultType(); System.arraycopy( args, 0, errorArgs, 2, args.length ); - messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), + AnnotationMirror annotationMirror = mapping.getMirror(); + if ( isReverse ) { + InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( + method.getExecutable() ); + + annotationMirror = reversePrism == null ? annotationMirror : reversePrism.mirror; + } + messager.printMessage( method.getExecutable(), annotationMirror, mapping.getSourceAnnotationValue(), message, errorArgs ); } @@ -384,8 +392,8 @@ private NoWriteAccessorErrorMessage(Mapping mapping, SourceMethod method, Format } @Override - public void report() { - printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE ); + public void report(boolean isReverse) { + printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, isReverse ); } } @@ -404,7 +412,7 @@ private NoPropertyErrorMessage(Mapping mapping, SourceMethod method, FormattingM } @Override - public void report() { + public void report(boolean isReverse) { Set readAccessors = nextType.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( @@ -415,7 +423,11 @@ public void report() { List elements = new ArrayList( Arrays.asList( entryNames ).subList( 0, index ) ); elements.add( mostSimilarProperty ); - printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); + printErrorMessage( + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, + isReverse, + Strings.join( elements, "." ) + ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 1ab5e94851..fe54645964 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -517,15 +517,6 @@ private MappingOptions getInverseMappingOptions(List rawMethods, S if ( reversePrism != null ) { - // is there a suitable constructor - if ( method.isBeanMapping() - && !method.isUpdateMethod() - && !method.getReturnType().isCollectionOrMapType() - && !method.getReturnType().hasEmptyAccessibleContructor() ) { - reportErrorWhenNoSuitableConstrutor( method, reversePrism ); - return null; - } - // method is configured as being reverse method, collect candidates List candidates = new ArrayList(); for ( SourceMethod oneMethod : rawMethods ) { @@ -689,17 +680,6 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } } - private void reportErrorWhenNoSuitableConstrutor( SourceMethod method, - InheritInverseConfigurationPrism reversePrism ) { - - messager.printMessage( method.getExecutable(), - reversePrism.mirror, - Message.INHERITINVERSECONFIGURATION_NO_SUITABLE_CONSTRUCTOR, - reversePrism.name() - - ); - } - private void reportErrorWhenSeveralNamesMatch(List candidates, SourceMethod method, InheritInverseConfigurationPrism reversePrism) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index e3bd87950c..8440c868f9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -89,6 +89,7 @@ public enum Message { GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), + GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible empty constructor." ), RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), @@ -111,7 +112,6 @@ public enum Message { INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ), INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s." ), - INHERITINVERSECONFIGURATION_NO_SUITABLE_CONSTRUCTOR( "There is no suitable result type constructor for reversing this method." ), INHERITINVERSECONFIGURATION_NO_NAME_MATCH( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\"." ), INHERITCONFIGURATION_DUPLICATES( "Several matching methods exist: %s(). Specify a name explicitly." ), INHERITCONFIGURATION_INVALIDNAME( "None of the candidates %s() matches given name: \"%s\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 2a65e99d94..7b7cc133ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -76,7 +76,11 @@ public void factoryMethodWithSourceParamIsChosen() { + " .*TargetB .*TargetFactories\\.createTargetB\\(.*SourceB source," + " @TargetType .*Class<.*TargetB> clazz\\)," + " .*TargetB .*TargetFactories\\.createTargetB\\(@TargetType java.lang.Class<.*TargetB> clazz\\)," - + " .*TargetB .*TargetFactories\\.createTargetB\\(\\).") + + " .*TargetB .*TargetFactories\\.createTargetB\\(\\)."), + @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 33, + messageRegExp = ".*TargetB does not have an accessible empty constructor\\.") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java new file mode 100644 index 0000000000..db16b4c166 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1283; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousInverseTargetHasNoSuitableConstructorMapper { + + @Mapping(target = "target", source = "source") + Target fromSource(Source source); + + @InheritInverseConfiguration + Source fromTarget(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java new file mode 100644 index 0000000000..fac5677d87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1283; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousTargetHasNoSuitableConstructorMapper { + + @Mapping(target = "source", source = "target") + Source fromTarget(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java new file mode 100644 index 0000000000..b7919e1036 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -0,0 +1,70 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1283; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1283") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Source.class, + Target.class +}) +public class Issue1283Test { + + @Test + @WithClasses(ErroneousInverseTargetHasNoSuitableConstructorMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35L, + messageRegExp = ".*\\._1283\\.Source does not have an accessible empty constructor" + ) + } + ) + public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { + } + + @Test + @WithClasses(ErroneousTargetHasNoSuitableConstructorMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 31L, + messageRegExp = ".*\\._1283\\.Source does not have an accessible empty constructor" + ) + } + ) + public void returnTypeHasNoSuitableConstructor() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java new file mode 100644 index 0000000000..a55fa332c0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1283; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String source; + + public Source(String source) { + this.source = source; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java new file mode 100644 index 0000000000..2285de7015 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1283; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String target; + + public String getTarget() { + return target; + } + + public void setTarget(String target) { + this.target = target; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index a9ea638f1a..cee618c0e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -49,7 +49,13 @@ public class AmbiguousAnnotatedFactoryTest { + "createBar\\(org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Foo foo\\), " + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar " + ".*AmbiguousBarFactory.createBar\\(org.mapstruct.ap.test.erroneous." - + "ambiguousannotatedfactorymethod.Foo foo\\)." ) + + "ambiguousannotatedfactorymethod.Foo foo\\)."), + @Diagnostic(type = SourceTargetMapperAndBarFactory.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = ".*\\.ambiguousannotatedfactorymethod.Bar does not have an accessible empty " + + "constructor\\.") + } ) public void shouldUseTwoFactoryMethods() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index 2f8746fefe..e141e13472 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -50,7 +50,12 @@ public class FactoryTest { messageRegExp = "Ambiguous factory methods found for creating " + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar: " + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar createBar\\(\\), " - + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar .*BarFactory.createBar\\(\\)." ) + + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar .*BarFactory.createBar\\(\\)."), + @Diagnostic(type = SourceTargetMapperAndBarFactory.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = ".*\\.ambiguousfactorymethod\\.Bar does not have an accessible empty constructor\\.") + } ) public void shouldUseTwoFactoryMethods() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 2fed7b0fd0..364ec0b73f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -184,7 +184,7 @@ public void shouldUseGetAsTargetAccessor() { @Diagnostic( type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 46, - messageRegExp = "There is no suitable result type constructor for reversing this method\\." ) + messageRegExp = "Unknown property \"position\" in result type java\\.lang\\.Integer\\." ) } ) @WithClasses({ ArtistToChartEntryErroneous.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 67495c38c2..f1a416ea5a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -177,7 +177,13 @@ public void shouldFailOnSuperBounds2() { messageRegExp = "Can't map property \".*NoProperties " + "foo\\.wrapped\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA " + - "foo\\.wrapped\"") + "foo\\.wrapped\""), + @Diagnostic(type = ErroneousSourceTargetMapper6.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + messageRegExp = ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " + + "accessible empty constructor\\.") + }) public void shouldFailOnNonMatchingWildCards() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java new file mode 100644 index 0000000000..8752c88baf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousResultTypeNoEmptyConstructorMapper { + + @BeanMapping(resultType = Banana.class) + @Mapping(target = "type", ignore = true) + Fruit map(FruitDto source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 48180a71ee..113a5fa5b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -60,12 +60,31 @@ public class InheritanceSelectionTest { line = 36, messageRegExp = "Ambiguous factory methods found for creating .*Fruit: " + ".*Apple .*ConflictingFruitFactory\\.createApple\\(\\), " - + ".*Banana .*ConflictingFruitFactory\\.createBanana\\(\\)\\.") + + ".*Banana .*ConflictingFruitFactory\\.createBanana\\(\\)\\."), + @Diagnostic(type = ErroneousFruitMapper.class, + kind = Kind.ERROR, + line = 36, + messageRegExp = ".*Fruit does not have an accessible empty constructor\\.") } ) public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() { } + @IssueKey("1283") + @Test + @WithClasses( { ErroneousResultTypeNoEmptyConstructorMapper.class, Banana.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousResultTypeNoEmptyConstructorMapper.class, + kind = Kind.ERROR, + line = 31, + messageRegExp = ".*\\.resulttype\\.Banana does not have an accessible empty constructor\\.") + } + ) + public void testResultTypeHasNoSuitableEmptyConstructor() { + } + @Test @WithClasses( { ConflictingFruitFactory.class, ResultTypeSelectingFruitMapper.class, Banana.class } ) public void testResultTypeBasedFactoryMethodSelection() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index fb3c4a75c1..d8d594f09c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -184,8 +184,14 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 37, - messageRegExp = "No read accessor found for property \"type\" in target type.") - } ) + messageRegExp = "No read accessor found for property \"type\" in target type."), + @Diagnostic(type = ErroneousOrganizationMapper2.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 48, + messageRegExp = ".*\\.updatemethods\\.DepartmentEntity does not have an accessible empty " + + "constructor\\.") + + }) public void testShouldFailOnConstantMappingNoPropertyGetter() { } @Test From af8d48c797f27b6c3fff154bc803eb29e7ecffe3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 7 Sep 2017 17:47:18 +0200 Subject: [PATCH 0147/1006] #1281 Do not depend on deprecated sonatype parent --- build-config/pom.xml | 14 ++------ core-common/pom.xml | 8 +---- integrationtest/pom.xml | 8 +---- parent/pom.xml | 74 +++++++++++++++++++++++++++++++---------- pom.xml | 10 ++---- 5 files changed, 65 insertions(+), 49 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f857058844..da667708b4 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -33,15 +33,7 @@ jar MapStruct Build Configuration - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - + + true + diff --git a/core-common/pom.xml b/core-common/pom.xml index d5555f9220..bbc08622a6 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -35,6 +35,7 @@ true + true @@ -65,13 +66,6 @@ - - org.apache.maven.plugins - maven-deploy-plugin - - true - - diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0b8fb827cf..d066c5e594 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -35,6 +35,7 @@ ${project.version} + true @@ -79,13 +80,6 @@ 1.8 - - org.apache.maven.plugins - maven-deploy-plugin - - true - - org.apache.maven.plugins maven-surefire-plugin diff --git a/parent/pom.xml b/parent/pom.xml index 07f19905cf..e3cec21190 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -22,13 +22,6 @@ 4.0.0 - - org.sonatype.oss - oss-parent - 7 - - - org.mapstruct mapstruct-parent 1.2.0-SNAPSHOT @@ -44,7 +37,7 @@ 1.0.0 1.2 2.19.1 - 2.10.3 + 3.0.0-M1 4.0.3.RELEASE 0.26.0 7.2 @@ -77,14 +70,27 @@ HEAD + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + GitHub Issues https://github.com/mapstruct/mapstruct/issues - Jenkins - https://mapstruct.ci.cloudbees.com/ + Travis CI + https://travis-ci.org/mapstruct/mapstruct @@ -317,6 +323,14 @@ org.apache.maven.plugins maven-deploy-plugin 2.8.2 + + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 org.apache.maven.plugins @@ -352,7 +366,7 @@ org.apache.maven.plugins maven-jar-plugin - 2.4 + 3.0.2 org.apache.maven.plugins @@ -366,14 +380,16 @@ org.apache.maven.plugins maven-release-plugin - 2.5.1 + 2.5.3 - -Psonatype-oss-release -DskipTests ${add.release.arguments} + -DskipTests ${add.release.arguments} clean install false true @{project.version} true + false + release @@ -384,12 +400,12 @@ org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.0.1 org.apache.maven.plugins maven-site-plugin - 3.3 + 3.6 org.apache.maven.plugins @@ -661,13 +677,24 @@ - sonatype-oss-release + release + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar-no-fork + + + + org.apache.maven.plugins maven-javadoc-plugin - ${org.apache.maven.plugins.javadoc.version} attach-javadocs @@ -677,6 +704,19 @@ + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + diff --git a/pom.xml b/pom.xml index 63b61ce435..c523ce0b0c 100644 --- a/pom.xml +++ b/pom.xml @@ -43,16 +43,12 @@ processor integrationtest + + true + - - org.apache.maven.plugins - maven-deploy-plugin - - true - - com.mycila.maven-license-plugin maven-license-plugin From 499dbd4561305c747f869013c717137dfe6a5fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Sun, 17 Sep 2017 23:03:24 +0200 Subject: [PATCH 0148/1006] #1273 Fix for NullValueMappingStrategy#RETURN_DEFAULT when using collections When mapping a collection using NullValueMappingStrategy#RETURN_DEFAULT and the source is null, the target will be an empty collection. --- .../model/CollectionAssignmentBuilder.java | 19 ++++-- .../ap/internal/model/PropertyMapping.java | 14 ++++- ...nceSetterWrapperForCollectionsAndMaps.java | 10 +-- ...perForCollectionsAndMapsWithNullCheck.java | 14 ++++- .../model/assignment/UpdateWrapper.java | 9 ++- .../ap/internal/util/MapperConfiguration.java | 9 +++ ...anceSetterWrapperForCollectionsAndMaps.ftl | 2 +- ...pperForCollectionsAndMapsWithNullCheck.ftl | 2 +- .../model/assignment/UpdateWrapper.ftl | 2 +- .../org/mapstruct/ap/test/bugs/_1273/Dto.java | 35 +++++++++++ .../mapstruct/ap/test/bugs/_1273/Entity.java | 35 +++++++++++ .../bugs/_1273/EntityMapperReturnDefault.java | 29 +++++++++ .../bugs/_1273/EntityMapperReturnNull.java | 29 +++++++++ .../ap/test/bugs/_1273/Issue1273Test.java | 62 +++++++++++++++++++ ...ssue913SetterMapperForCollectionsTest.java | 14 ++--- .../DomainDtoWithNvmsDefaultMapperImpl.java | 20 +++--- 16 files changed, 271 insertions(+), 34 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index ee8e3e8eea..e6197b8079 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -30,6 +30,7 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -139,6 +140,7 @@ public Assignment build() { targetPropertyName ); } + Assignment factoryMethod = ctx.getMappingResolver() .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( sourceRHS ) ); result = new UpdateWrapper( @@ -147,31 +149,35 @@ public Assignment build() { factoryMethod, PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), targetType, - true + true, + mapNullToDefault() ); } else if ( method.isUpdateMethod() && !targetImmutable ) { + result = new ExistingInstanceSetterWrapperForCollectionsAndMaps( result, method.getThrownTypes(), targetType, method.getMapperConfiguration().getNullValueCheckStrategy(), ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), + mapNullToDefault() ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || method.getMapperConfiguration().getNullValueCheckStrategy() == NullValueCheckStrategyPrism.ALWAYS ) { + result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, method.getThrownTypes(), targetType, ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), + mapNullToDefault() ); } else { - // target accessor is setter, so wrap the setter in setter map/ collection handling result = new SetterWrapperForCollectionsAndMaps( result, @@ -201,4 +207,9 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || return result; } + + private boolean mapNullToDefault() { + return method.getMapperConfiguration().getNullValueMappingStrategy() + == NullValueMappingStrategyPrism.RETURN_DEFAULT; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index a4dc9f3dfc..6a3cda066a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -53,6 +53,7 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; @@ -394,10 +395,14 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { targetPropertyName ); } + + boolean mapNullToDefault = method.getMapperConfiguration(). + getNullValueMappingStrategy() == NullValueMappingStrategyPrism.RETURN_DEFAULT; + Assignment factory = ctx.getMappingResolver() .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ) ); return new UpdateWrapper( rhs, method.getThrownTypes(), factory, isFieldAssignment(), targetType, - !rhs.isSourceReferenceParameter() ); + !rhs.isSourceReferenceParameter(), mapNullToDefault ); } else { NullValueCheckStrategyPrism nvcs = method.getMapperConfiguration().getNullValueCheckStrategy(); @@ -754,10 +759,15 @@ public PropertyMapping build() { targetPropertyName ); } + + boolean mapNullToDefault = method.getMapperConfiguration(). + getNullValueMappingStrategy() == NullValueMappingStrategyPrism.RETURN_DEFAULT; + Assignment factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + assignment = new UpdateWrapper( assignment, method.getThrownTypes(), factoryMethod, - isFieldAssignment(), targetType, false ); + isFieldAssignment(), targetType, false, mapNullToDefault ); } else { assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index 0e4ba1dc8f..2326b144b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.internal.model.assignment; +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; + import java.util.List; import org.mapstruct.ap.internal.model.common.Assignment; @@ -25,8 +27,6 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; - /** * This wrapper handles the situation where an assignment is done for an update method. * @@ -49,14 +49,16 @@ public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAs Type targetType, NullValueCheckStrategyPrism nvms, TypeFactory typeFactory, - boolean fieldAssignment) { + boolean fieldAssignment, + boolean mapNullToDefault) { super( decoratedAssignment, thrownTypesToExclude, targetType, typeFactory, - fieldAssignment + fieldAssignment, + mapNullToDefault ); this.includeSourceNullCheck = ALWAYS == nvms; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index cd5b9eb075..dca19ec1c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.internal.model.assignment; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; + import java.util.EnumSet; import java.util.HashSet; import java.util.List; @@ -27,8 +29,6 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; - /** * This wrapper handles the situation where an assignment is done via the setter and a null check is needed. * This is needed when a direct assignment is used, or if the user has chosen the appropriate strategy @@ -39,12 +39,14 @@ public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForC private final Type targetType; private final TypeFactory typeFactory; + private final boolean mapNullToDefault; public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssignment, List thrownTypesToExclude, Type targetType, TypeFactory typeFactory, - boolean fieldAssignment) { + boolean fieldAssignment, + boolean mapNullToDefault) { super( decoratedAssignment, thrownTypesToExclude, @@ -53,6 +55,7 @@ public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssig ); this.targetType = targetType; this.typeFactory = typeFactory; + this.mapNullToDefault = mapNullToDefault; } @Override @@ -83,4 +86,9 @@ public boolean isDirectAssignment() { public boolean isEnumSet() { return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); } + + public boolean isMapNullToDefault() { + return mapNullToDefault; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index e23f59899d..17f6bd4fc9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -37,18 +37,21 @@ public class UpdateWrapper extends AssignmentWrapper { private final Assignment factoryMethod; private final Type targetImplementationType; private final boolean includeSourceNullCheck; + private final boolean mapNullToDefault; public UpdateWrapper( Assignment decoratedAssignment, List thrownTypesToExclude, Assignment factoryMethod, boolean fieldAssignment, Type targetType, - boolean includeSourceNullCheck ) { + boolean includeSourceNullCheck, + boolean mapNullToDefault ) { super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; this.targetImplementationType = determineImplType( factoryMethod, targetType ); this.includeSourceNullCheck = includeSourceNullCheck; + this.mapNullToDefault = mapNullToDefault; } private static Type determineImplType(Assignment factoryMethod, Type targetType) { @@ -100,4 +103,8 @@ public Assignment getFactoryMethod() { public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } + + public boolean isMapNullToDefault() { + return mapNullToDefault; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 3d1a98cdb1..e9118a585e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -155,6 +155,15 @@ public NullValueCheckStrategyPrism getNullValueCheckStrategy() { } } + public NullValueMappingStrategyPrism getNullValueMappingStrategy() { + if ( mapperConfigPrism != null && mapperPrism.values.nullValueMappingStrategy() == null ) { + return NullValueMappingStrategyPrism.valueOf( mapperConfigPrism.nullValueMappingStrategy() ); + } + else { + return NullValueMappingStrategyPrism.valueOf( mapperPrism.nullValueMappingStrategy() ); + } + } + public boolean isMapToDefault(NullValueMappingStrategyPrism mapNullToDefault) { // check on method level diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index 09b4bf4d19..9a50ebbdf2 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -28,7 +28,7 @@ ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index ec934e1648..102966164d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -24,7 +24,7 @@ <@lib.handleExceptions> <@callTargetWriteAccessor/> <#if !ext.defaultValueAssignment??>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 2b65784425..44f37eec2b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -27,7 +27,7 @@ <@lib.handleAssignment/>; } else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>null; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; } <#else> <@assignToExistingTarget/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java new file mode 100644 index 0000000000..b38fcaec61 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1273; + +import java.util.ArrayList; +import java.util.List; + +public class Dto { + + List longs = new ArrayList(); + + public List getLongs() { + return longs; + } + + public void setLongs(List longs) { + this.longs = longs; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java new file mode 100644 index 0000000000..f93a3578f2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1273; + +import java.util.ArrayList; +import java.util.List; + +public class Entity { + + List longs = new ArrayList(); + + public List getLongs() { + return longs; + } + + public void setLongs(List longs) { + this.longs = longs; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java new file mode 100644 index 0000000000..38e2a1f5ac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1273; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; + +@Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT ) +public interface EntityMapperReturnDefault { + + Dto asTarget(Entity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java new file mode 100644 index 0000000000..bd9c284b22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1273; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; + +@Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL ) +public interface EntityMapperReturnNull { + + Dto asTarget(Entity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java new file mode 100644 index 0000000000..f50e9c2c9c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java @@ -0,0 +1,62 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1273; + +import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; + +@IssueKey( "1273" ) +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( { EntityMapperReturnDefault.class, EntityMapperReturnNull.class, Dto.class, Entity.class } ) +public class Issue1273Test { + + @Test + public void shouldCorrectlyMapCollectionWithNullValueMappingStrategyReturnDefault() { + EntityMapperReturnDefault entityMapper = Mappers.getMapper( EntityMapperReturnDefault.class ); + + Entity entity = createEntityWithEmptyList(); + + Dto dto = entityMapper.asTarget( entity ); + assertThat( dto.getLongs() ).isNotNull(); + } + + @Test + public void shouldCorrectlyMapCollectionWithNullValueMappingStrategyReturnNull() { + EntityMapperReturnNull entityMapper = Mappers.getMapper( EntityMapperReturnNull.class ); + + Entity entity = createEntityWithEmptyList(); + + Dto dto = entityMapper.asTarget( entity ); + assertThat( dto.getLongs() ).isNull(); + } + + private Entity createEntityWithEmptyList() { + Entity entity = new Entity(); + entity.setLongs( null ); + + return entity; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index 87836abd38..2665883464 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -151,7 +151,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { * conversion from string to long that return default in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. * - * However, for plain mappings (strings to strings) the result will be null. + * However, for plain mappings (strings to strings) the result will also be an empty collection. */ @Test public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { @@ -160,7 +160,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { Domain domain = DomainDtoWithNvmsDefaultMapper.INSTANCE.create( dto ); doControlAsserts( domain ); - assertThat( domain.getStrings() ).isNull(); + assertThat( domain.getStrings() ).isEmpty(); assertThat( domain.getLongs() ).isEmpty(); } @@ -169,7 +169,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { * string to long that return default in the entire mapper, so also for the forged mapper. Note the default NVMS is * RETURN_NULL. * - * However, for plain mappings (strings to strings) the result will be null. + * However, for plain mappings (strings to strings) the result will also be an empty collection. */ @Test public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { @@ -183,7 +183,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { DomainDtoWithNvmsDefaultMapper.INSTANCE.update( dto, domain ); doControlAsserts( domain ); - assertThat( domain.getStrings() ).isNull(); + assertThat( domain.getStrings() ).isEmpty(); assertThat( domain.getLongs() ).isEmpty(); assertThat( domain.getLongs() ).isSameAs( longIn ); // make sure add all is used. } @@ -194,7 +194,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { * mapper. Note the default NVMS is * RETURN_NULL. * - * However, for plain mappings (strings to strings) the result will be null. + * However, for plain mappings (strings to strings) the result will also be an empty collection. * */ @Test @@ -212,9 +212,9 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { assertThat( domain2 ).isSameAs( domain1 ); doControlAsserts( domain1, domain2 ); assertThat( domain1.getLongs() ).isEqualTo( domain2.getLongs() ); - assertThat( domain1.getStrings() ).isNull(); + assertThat( domain1.getStrings() ).isEmpty(); assertThat( domain1.getLongs() ).isEmpty(); - assertThat( domain2.getStrings() ).isNull(); + assertThat( domain2.getStrings() ).isEmpty(); assertThat( domain2.getLongs() ).isEmpty(); assertThat( domain1.getLongs() ).isSameAs( longIn ); // make sure that add all is used assertThat( domain2.getLongs() ).isSameAs( longIn ); // make sure that add all is used diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 241edfc2f0..5c8692f803 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -46,7 +46,7 @@ public Domain create(Dto source) { domain.setStrings( new HashSet( list ) ); } else { - domain.setStrings( null ); + domain.setStrings( new HashSet() ); } List list1 = source.getStringsWithDefault(); if ( list1 != null ) { @@ -60,7 +60,7 @@ public Domain create(Dto source) { domain.setStringsInitialized( new HashSet( list2 ) ); } else { - domain.setStringsInitialized( null ); + domain.setStringsInitialized( new HashSet() ); } } @@ -78,7 +78,7 @@ public void update(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( null ); + target.setLongs( new HashSet() ); } } else { @@ -94,7 +94,7 @@ public void update(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( null ); + target.setStrings( new HashSet() ); } } else { @@ -110,7 +110,7 @@ public void update(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( null ); + target.setLongsInitialized( new HashSet() ); } } else { @@ -145,7 +145,7 @@ public void update(Dto source, Domain target) { target.getStringsInitialized().addAll( list2 ); } else { - target.setStringsInitialized( null ); + target.setStringsInitialized( new HashSet() ); } } else { @@ -168,7 +168,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( null ); + target.setLongs( new HashSet() ); } } else { @@ -184,7 +184,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( null ); + target.setStrings( new HashSet() ); } } else { @@ -200,7 +200,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( null ); + target.setLongsInitialized( new HashSet() ); } } else { @@ -235,7 +235,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStringsInitialized().addAll( list2 ); } else { - target.setStringsInitialized( null ); + target.setStringsInitialized( new HashSet() ); } } else { From 98bdc3612f5beb6d89596a280e5974cd2dce282b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 Sep 2017 23:22:59 +0200 Subject: [PATCH 0149/1006] Adding Kevin to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 3ad9a03341..f2544f8fc9 100644 --- a/copyright.txt +++ b/copyright.txt @@ -13,6 +13,7 @@ Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla +Kevin Grüneberg - https://github.com/kevcodez Michael Pardo - https://github.com/pardom Mustafa Caylak - https://github.com/luxmeter Oliver Ehrenmüller - https://github.com/greuelpirat From 22e17f9c4b86033ed80a3efca43b0db47f3c21a4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 17 Oct 2017 20:57:05 +0200 Subject: [PATCH 0150/1006] #744 Improve support for Java 9 When compilig with Java 9 and and source version 1.8 Elements#getTypeElement(CharSequence) returns the types from all modules (such as java.xml.bind or java.xml.datatype). However if the required modules are not added the classes cannot be used. Therefore, apart from using the Elements we are also checking if the class is also there. If source version 9 is used then Elements#getTypeElement(CharSequence) works correctly and does not return the types if the modules are not there --- .../common/DateFormatValidatorFactory.java | 4 +- .../source/builtin/BuiltInMappingMethods.java | 37 +++++--- .../selector/XmlElementDeclSelector.java | 8 +- .../ap/internal/util/ClassUtils.java | 89 +++++++++++++++++++ .../ap/internal/util/JaxbConstants.java | 11 +++ .../ap/internal/util/XmlConstants.java | 43 +++++++++ 6 files changed, 173 insertions(+), 19 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index 649c3c7a73..dddd6d6850 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -25,6 +25,7 @@ import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.XmlConstants; /** * Factory for {@link DateFormatValidator}.

    Based on the types of source / target type a specific {@link @@ -42,7 +43,6 @@ final class DateFormatValidatorFactory { private static final String ORG_JODA_TIME_FORMAT_DATE_TIME_FORMAT = "org.joda.time.format.DateTimeFormat"; private static final String FOR_PATTERN = "forPattern"; - private static final String JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; private DateFormatValidatorFactory() { } @@ -85,7 +85,7 @@ public DateFormatValidationResult validate(String dateFormat) { private static boolean isXmlGregorianCalendarSupposedToBeMapped(Type sourceType, Type targetType) { return typesEqualsOneOf( - sourceType, targetType, JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + sourceType, targetType, XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); } private static boolean isJodaDateTimeSupposed(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 87de5c13c3..9675bf386a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -18,13 +18,14 @@ */ package org.mapstruct.ap.internal.model.source.builtin; +import java.util.ArrayList; import java.util.List; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JaxbConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; /** * Registry for all built-in methods. @@ -36,27 +37,32 @@ public class BuiltInMappingMethods { private final List builtInMethods; public BuiltInMappingMethods(TypeFactory typeFactory) { - builtInMethods = Collections.newArrayList( - new DateToXmlGregorianCalendar( typeFactory ), - new XmlGregorianCalendarToDate( typeFactory ), - new StringToXmlGregorianCalendar( typeFactory ), - new XmlGregorianCalendarToString( typeFactory ), - new CalendarToXmlGregorianCalendar( typeFactory ), - new XmlGregorianCalendarToCalendar( typeFactory ) - ); + boolean isXmlGregorianCalendarPresent = isXmlGregorianCalendarAvailable( typeFactory ); + builtInMethods = new ArrayList( 20 ); + if ( isXmlGregorianCalendarPresent ) { + builtInMethods.add( new DateToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new XmlGregorianCalendarToDate( typeFactory ) ); + builtInMethods.add( new StringToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new XmlGregorianCalendarToString( typeFactory ) ); + builtInMethods.add( new CalendarToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new XmlGregorianCalendarToCalendar( typeFactory ) ); + } if ( isJaxbAvailable( typeFactory ) ) { builtInMethods.add( new JaxbElemToValue( typeFactory ) ); } + if ( isJava8TimeAvailable( typeFactory ) ) { builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) ); - builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); - builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); + if ( isXmlGregorianCalendarPresent ) { + builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); + builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); + } } - if ( isJodaTimeAvailable( typeFactory ) ) { + if ( isJodaTimeAvailable( typeFactory ) && isXmlGregorianCalendarPresent ) { builtInMethods.add( new JodaDateTimeToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new XmlGregorianCalendarToJodaDateTime( typeFactory ) ); builtInMethods.add( new JodaLocalDateTimeToXmlGregorianCalendar( typeFactory ) ); @@ -69,13 +75,18 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { } private static boolean isJaxbAvailable(TypeFactory typeFactory) { - return typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); + return JaxbConstants.isJaxbElementPresent() && typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); } private static boolean isJava8TimeAvailable(TypeFactory typeFactory) { return typeFactory.isTypeAvailable( JavaTimeConstants.ZONED_DATE_TIME_FQN ); } + private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) { + return XmlConstants.isXmlGregorianCalendarPresent() && + typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + } + private static boolean isJodaTimeAvailable(TypeFactory typeFactory) { return typeFactory.isTypeAvailable( JodaTimeConstants.DATE_TIME_FQN ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 0eae22302f..6051ad11e3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -27,8 +27,6 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import javax.xml.bind.annotation.XmlElementDecl; -import javax.xml.bind.annotation.XmlElementRef; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; @@ -37,9 +35,11 @@ import org.mapstruct.ap.internal.prism.XmlElementRefPrism; /** - * Finds the {@link XmlElementRef} annotation on a field (of the mapping result type or its super types) matching the + * Finds the {@link javax.xml.bind.annotation.XmlElementRef} annotation on a field (of the mapping result type or its + * super types) matching the * target property name. Then selects those methods with matching {@code name} and {@code scope} attributes of the - * {@link XmlElementDecl} annotation, if that is present. Matching happens in the following order: + * {@link javax.xml.bind.annotation.XmlElementDecl} annotation, if that is present. Matching happens in the following + * order: *

      *
    1. Name and Scope matches
    2. *
    3. Scope matches
    4. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java new file mode 100644 index 0000000000..95d5bfbe99 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java @@ -0,0 +1,89 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +/** + * Utilities for working with classes. It is mainly needed because using the {@link javax.lang.model.util.Elements} + * is not always correct. For example when compiling with JDK 9 and source version 8 classes from different modules + * are available by {@link javax.lang.model.util.Elements#getTypeElement(CharSequence)} but they are actually not + * if those modules are not added during compilation. + * + * @author Filip Hrisafov + */ +class ClassUtils { + + private ClassUtils() { + } + + /** + * Determine whether the {@link Class} identified by the supplied name is present + * and can be loaded. Will return {@code false} if either the class or + * one of its dependencies is not present or cannot be loaded. + * + * @param className the name of the class to check + * @param classLoader the class loader to use + * (may be {@code null}, which indicates the default class loader) + * + * @return whether the specified class is present + */ + static boolean isPresent(String className, ClassLoader classLoader) { + try { + ClassLoader classLoaderToUse = classLoader; + if ( classLoaderToUse == null ) { + classLoaderToUse = getDefaultClassLoader(); + } + classLoaderToUse.loadClass( className ); + return true; + } + catch ( ClassNotFoundException ex ) { + // Class or one of its dependencies is not present... + return false; + } + } + + /** + * Return the default ClassLoader to use: typically the thread context + * ClassLoader, if available; the ClassLoader that loaded the ClassUtils + * class will be used as fallback. + *

      Call this method if you intend to use the thread context ClassLoader + * in a scenario where you absolutely need a non-null ClassLoader reference: + * for example, for class path resource loading (but not necessarily for + * {@code Class.forName}, which accepts a {@code null} ClassLoader + * reference as well). + * + * @return the default ClassLoader (never {@code null}) + * + * @see Thread#getContextClassLoader() + */ + private static ClassLoader getDefaultClassLoader() { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } + catch ( Throwable ex ) { + // Cannot access thread context ClassLoader - falling back to system class loader... + } + if ( cl == null ) { + // No thread context class loader -> use class loader of this class. + cl = ClassUtils.class.getClassLoader(); + } + return cl; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java index 7edf655a45..c7c9e6c55c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java @@ -24,7 +24,18 @@ public final class JaxbConstants { public static final String JAXB_ELEMENT_FQN = "javax.xml.bind.JAXBElement"; + private static final boolean IS_JAXB_ELEMENT_PRESENT = ClassUtils.isPresent( + JAXB_ELEMENT_FQN, + JaxbConstants.class.getClassLoader() + ); private JaxbConstants() { } + + /** + * @return {@code true} if {@link javax.xml.bind.JAXBElement} is present, {@code false} otherwise + */ + public static boolean isJaxbElementPresent() { + return IS_JAXB_ELEMENT_PRESENT; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java new file mode 100644 index 0000000000..5a341d8815 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +/** + * Helper holding JAXB time full qualified class names for conversion registration + * + * @author Filip Hrisafov + */ +public final class XmlConstants { + + public static final String JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; + private static final boolean IS_XML_GREGORIAN_CALENDAR_PRESENT = ClassUtils.isPresent( + JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR, + XmlConstants.class.getClassLoader() + ); + + private XmlConstants() { + } + + /** + * @return {@code true} if the {@link javax.xml.datatype.XMLGregorianCalendar} is present, {@code false} otherwise + */ + public static boolean isXmlGregorianCalendarPresent() { + return IS_XML_GREGORIAN_CALENDAR_PRESENT; + } +} From aef1e3b14bb945b73a120f92540011f02ce77f88 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 17 Oct 2017 21:10:59 +0200 Subject: [PATCH 0151/1006] #1304 Add thrown exceptions to the generated nested mapping methods --- .../ap/internal/model/BeanMappingMethod.java | 4 ++ .../model/ContainerMappingMethodBuilder.java | 11 ++-- .../nestedbeans/exceptions/EntityFactory.java | 49 ++++++++++++++++++ .../exceptions/MappingException.java | 30 +++++++++++ .../NestedMappingsWithExceptionTest.java | 51 +++++++++++++++++++ .../nestedbeans/exceptions/ProjectMapper.java | 33 ++++++++++++ .../exceptions/_target/DeveloperDto.java | 36 +++++++++++++ .../exceptions/_target/ProjectDto.java | 38 ++++++++++++++ .../exceptions/source/Developer.java | 36 +++++++++++++ .../exceptions/source/Project.java | 38 ++++++++++++++ 10 files changed, 320 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 21e918eb5e..9be385b624 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -226,6 +226,10 @@ else if ( !method.isUpdateMethod() && !method.getReturnType().hasEmptyAccessible List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); + if (factoryMethod != null && method instanceof ForgedMethod ) { + ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); + } + return new BeanMappingMethod( method, existingVariableNames, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 5e7ce49959..7225947204 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -107,12 +107,7 @@ public final M build() { if ( assignment == null ) { assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); } - else { - if ( method instanceof ForgedMethod ) { - ForgedMethod forgedMethod = (ForgedMethod) method; - forgedMethod.addThrownTypes( assignment.getThrownTypes() ); - } - } + if ( assignment == null ) { if ( method instanceof ForgedMethod ) { // leave messaging to calling property mapping @@ -128,6 +123,10 @@ public final M build() { ); } } + else if ( method instanceof ForgedMethod ) { + ForgedMethod forgedMethod = (ForgedMethod) method; + forgedMethod.addThrownTypes( assignment.getThrownTypes() ); + } assignment = getWrapper( assignment, method ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java new file mode 100644 index 0000000000..7302445e51 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions; + +import org.mapstruct.ObjectFactory; +import org.mapstruct.TargetType; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class EntityFactory { + + @ObjectFactory + public T createEntity(@TargetType Class entityClass) throws MappingException { + T entity; + + try { + entity = entityClass.newInstance(); + } + catch ( IllegalAccessException exception ) { + throw new MappingException( "Rare exception thrown, refer to stack trace", exception ); + } + catch ( InstantiationException exception ) { + throw new MappingException( "Rare exception thrown, refer to stack trace", exception ); + } + catch ( Exception exception ) { + throw new MappingException( "I don't know how you got here, refer to stack trace", exception ); + } + + return entity; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java new file mode 100644 index 0000000000..7e72786ff7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class MappingException extends Exception { + + public MappingException(String message, Throwable cause) { + super( message, cause ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java new file mode 100644 index 0000000000..acb1353453 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.nestedbeans.exceptions._target.DeveloperDto; +import org.mapstruct.ap.test.nestedbeans.exceptions._target.ProjectDto; +import org.mapstruct.ap.test.nestedbeans.exceptions.source.Developer; +import org.mapstruct.ap.test.nestedbeans.exceptions.source.Project; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + DeveloperDto.class, + ProjectDto.class, + Developer.class, + Project.class, + ProjectMapper.class, + MappingException.class, + EntityFactory.class +}) +@IssueKey("1304") +@RunWith(AnnotationProcessorTestRunner.class) +public class NestedMappingsWithExceptionTest { + + @Test + public void shouldGenerateCodeThatCompiles() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java new file mode 100644 index 0000000000..58ce299738 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.nestedbeans.exceptions._target.ProjectDto; +import org.mapstruct.ap.test.nestedbeans.exceptions.source.Project; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +@Mapper(uses = EntityFactory.class) +public interface ProjectMapper { + + Project map(ProjectDto source) throws MappingException; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java new file mode 100644 index 0000000000..c813bca133 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions._target; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class DeveloperDto { + + private String firstName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java new file mode 100644 index 0000000000..9cd1386ca6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions._target; + +import java.util.List; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class ProjectDto { + + private List assignedDevelopers; + + public List getAssignedDevelopers() { + return assignedDevelopers; + } + + public void setAssignedDevelopers(List assignedDevelopers) { + this.assignedDevelopers = assignedDevelopers; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java new file mode 100644 index 0000000000..6c453480e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions.source; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class Developer { + + private String firstName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java new file mode 100644 index 0000000000..8b5e0771ef --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedbeans.exceptions.source; + +import java.util.List; + +/** + * @author Filip Hrisafov + * @author Darren Rambaud + */ +public class Project { + + private List assignedDevelopers; + + public List getAssignedDevelopers() { + return assignedDevelopers; + } + + public void setAssignedDevelopers(List assignedDevelopers) { + this.assignedDevelopers = assignedDevelopers; + } +} From 0e8c22c95fce8f66be524e414d91daa248da1450 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 17 Oct 2017 22:14:35 +0200 Subject: [PATCH 0152/1006] Add Darren to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index f2544f8fc9..b927905fdb 100644 --- a/copyright.txt +++ b/copyright.txt @@ -7,6 +7,7 @@ Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman Cornelius Dirmeier - https://github.com/cornzy +Darren Rambaud - https://github.com/xyzst Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil Ewald Volkert - https://github.com/eforest From a2176493e75f894324afae5905eb535cd98f161a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 17 Oct 2017 23:12:52 +0200 Subject: [PATCH 0153/1006] [maven-release-plugin] prepare release 1.2.0.Final --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index da667708b4..ec83b26e1c 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index bbc08622a6..d14f3098bf 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index b15220d69d..476e0839d3 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8e8cbaaa9f..11d8723dc6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b2dcceaefa..f2233ec226 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index e24f75f1f6..9710192bc2 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index d066c5e594..6504a37380 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e3cec21190..3d0df4e3e6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -24,7 +24,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final pom MapStruct Parent @@ -67,7 +67,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Final diff --git a/pom.xml b/pom.xml index c523ce0b0c..52509f051e 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final parent/pom.xml @@ -67,7 +67,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.2.0.Final diff --git a/processor/pom.xml b/processor/pom.xml index 834791ced2..8869af0259 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0-SNAPSHOT + 1.2.0.Final ../parent/pom.xml From de76a870196be36c21eb2e98856255d176fc812f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 17 Oct 2017 23:12:53 +0200 Subject: [PATCH 0154/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index ec83b26e1c..930f5ded4e 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index d14f3098bf..b1d066a4bf 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 476e0839d3..89ffba54da 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 11d8723dc6..1f4a7a65df 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f2233ec226..e155e87b15 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 9710192bc2..4802c6149f 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 6504a37380..2e377915cd 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 3d0df4e3e6..5978ff7d1f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -24,7 +24,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT pom MapStruct Parent @@ -67,7 +67,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Final + HEAD diff --git a/pom.xml b/pom.xml index 52509f051e..d920177b63 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT parent/pom.xml @@ -67,7 +67,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.2.0.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 8869af0259..da0b426d0c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -25,7 +25,7 @@ org.mapstruct mapstruct-parent - 1.2.0.Final + 1.3.0-SNAPSHOT ../parent/pom.xml From bfa2509439fa3e2f0f029bafacde73883ebbc735 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 18 Oct 2017 00:06:29 +0200 Subject: [PATCH 0155/1006] Update latest stable badge with 1.2.0.Final --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0c79fdfd01..393c9b2620 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.1.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.2.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) From e2391df04f7a631ec2cc13455e251e9cb7a68ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Fri, 20 Oct 2017 21:26:38 +0200 Subject: [PATCH 0156/1006] #1297 Add IntelliJ Formatter to CONTRIBUTING.md --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9ee866a684..1c2c0bbafe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,6 +12,8 @@ MapStruct follows the _Fork & Pull_ development approach. To get started just fo When doing changes, keep the following best practices in mind: * Provide test cases +* Use the code formatter for your IDE + * [IntelliJ Formatter](https://github.com/mapstruct/mapstruct/blob/master/etc/mapstruct.xml) * Update the [reference documentation](mapstruct.org/documentation) on [mapstruct.org](mapstruct.org) where required * Discuss new features you'd like to implement at the [Google group](https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users) before getting started * Create one pull request per feature From 0192bdaf836212108edbb97a5e55ce0ca1b61dd1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Sun, 30 Jul 2017 20:53:45 +0200 Subject: [PATCH 0157/1006] #571 Add Constructor Injection for Annotation Based Component Model - Allow configuring of injection strategy (Constructor / Field) - Default injection strategy is Field --- .../java/org/mapstruct/InjectionStrategy.java | 34 +++++ .../src/main/java/org/mapstruct/Mapper.java | 10 ++ .../main/java/org/mapstruct/MapperConfig.java | 12 ++ .../internal/model/AnnotatedConstructor.java | 79 ++++++++++ .../model/AnnotationMapperReference.java | 32 +++- .../ap/internal/model/Constructor.java | 8 +- .../ap/internal/model/GeneratedType.java | 21 ++- .../ap/internal/model/PropertyMapping.java | 10 +- .../prism/InjectionStrategyPrism.java | 30 ++++ ...nnotationBasedComponentModelProcessor.java | 142 ++++++++++++++++-- .../processor/CdiComponentProcessor.java | 5 + .../ap/internal/util/MapperConfiguration.java | 10 ++ .../internal/model/AnnotatedConstructor.ftl | 35 +++++ .../model/AnnotationMapperReference.ftl | 10 +- .../spring/constructor/PersonMapper.java | 38 +++++ .../constructor/PersonMapperDecorator.java | 39 +++++ .../constructor/SpringDecoratorTest.java | 107 +++++++++++++ .../spring/{ => field}/PersonMapper.java | 5 +- .../{ => field}/PersonMapperDecorator.java | 2 +- .../{ => field}/SpringDecoratorTest.java | 2 +- .../constructor/ConstructorJsr330Config.java | 29 ++++ .../CustomerJsr330ConstructorMapper.java | 38 +++++ .../GenderJsr330ConstructorMapper.java | 38 +++++ .../Jsr330ConstructorMapperTest.java | 107 +++++++++++++ .../field/CustomerJsr330FieldMapper.java | 33 ++++ .../jsr330/field/FieldJsr330Config.java | 29 ++++ .../jsr330/field/GenderJsr330FieldMapper.java | 38 +++++ .../jsr330/field/Jsr330FieldMapperTest.java | 109 ++++++++++++++ .../injectionstrategy/shared/CustomerDto.java | 45 ++++++ .../shared/CustomerEntity.java | 45 ++++++ .../test/injectionstrategy/shared/Gender.java | 28 ++++ .../injectionstrategy/shared/GenderDto.java | 28 ++++ .../constructor/ConstructorSpringConfig.java | 29 ++++ .../CustomerSpringConstructorMapper.java | 37 +++++ .../GenderSpringConstructorMapper.java | 38 +++++ .../SpringConstructorMapperTest.java | 107 +++++++++++++ .../field/CustomerSpringFieldMapper.java | 33 ++++ .../spring/field/FieldSpringConfig.java | 29 ++++ .../spring/field/GenderSpringFieldMapper.java | 38 +++++ .../spring/field/SpringFieldMapperTest.java | 106 +++++++++++++ .../ap/test/prism/EnumPrismsTest.java | 8 + 41 files changed, 1584 insertions(+), 39 deletions(-) create mode 100644 core-common/src/main/java/org/mapstruct/InjectionStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java rename processor/src/test/java/org/mapstruct/ap/test/decorator/spring/{ => field}/PersonMapper.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/decorator/spring/{ => field}/PersonMapperDecorator.java (96%) rename processor/src/test/java/org/mapstruct/ap/test/decorator/spring/{ => field}/SpringDecoratorTest.java (98%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java diff --git a/core-common/src/main/java/org/mapstruct/InjectionStrategy.java b/core-common/src/main/java/org/mapstruct/InjectionStrategy.java new file mode 100644 index 0000000000..75728d139f --- /dev/null +++ b/core-common/src/main/java/org/mapstruct/InjectionStrategy.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct; + +/** + * Strategy for handling injection. This is only used on annotated based component models such as CDI, Spring and + * JSR330. + * + * @author Kevin Grüneberg + */ +public enum InjectionStrategy { + + /** Annotations are written on the field **/ + FIELD, + + /** Annotations are written on the constructor **/ + CONSTRUCTOR +} diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index f41e63df4e..85458b39e0 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -160,6 +160,16 @@ */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + /** + * Determines whether to use field or constructor injection. This is only used on annotated based component models + * such as CDI, Spring and JSR 330. + * + * If no strategy is configured, {@link InjectionStrategy#FIELD} will be used as default. + * + * @return strategy how to inject + */ + InjectionStrategy injectionStrategy() default InjectionStrategy.FIELD; + /** * If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a * sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index 89db2bed58..fdf27a4677 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -147,6 +147,18 @@ MappingInheritanceStrategy mappingInheritanceStrategy() */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + /** + * Determines whether to use field or constructor injection. This is only used on annotated based component models + * such as CDI, Spring and JSR 330. + * + * Can be overridden by the one on {@link Mapper}. + * + * If no strategy is configured, {@link InjectionStrategy#FIELD} will be used as default. + * + * @return strategy how to inject + */ + InjectionStrategy injectionStrategy() default InjectionStrategy.FIELD; + /** * If MapStruct could not find another mapping method or apply an automatic conversion it will try to generate a * sub-mapping method between the two beans. If this property is set to {@code true} MapStruct will not try to diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java new file mode 100644 index 0000000000..7a12cf61db --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java @@ -0,0 +1,79 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * Represents a constructor that is used for constructor injection. + * + * @author Kevin Grüneberg + */ +public class AnnotatedConstructor extends ModelElement implements Constructor { + + private final String name; + private final List mapperReferences; + private final List annotations; + private final boolean publicEmptyConstructor; + + public AnnotatedConstructor(String name, List mapperReferences, + List annotations, boolean publicEmptyConstructor) { + this.name = name; + this.mapperReferences = mapperReferences; + this.annotations = annotations; + this.publicEmptyConstructor = publicEmptyConstructor; + } + + @Override + public Set getImportTypes() { + Set types = new HashSet(); + + for ( MapperReference mapperReference : mapperReferences ) { + types.addAll( mapperReference.getImportTypes() ); + } + + for ( Annotation annotation : annotations ) { + types.addAll( annotation.getImportTypes() ); + } + + return types; + } + + @Override + public String getName() { + return name; + } + + public List getMapperReferences() { + return mapperReferences; + } + + public List getAnnotations() { + return annotations; + } + + public boolean isPublicEmptyConstructor() { + return publicEmptyConstructor; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java index b913fd7d98..88d8dbe294 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java @@ -25,18 +25,28 @@ import org.mapstruct.ap.internal.model.common.Type; /** - * Mapper reference which is retrieved via Annotation-based dependency injection. + * Mapper reference which is retrieved via Annotation-based dependency injection.
      + * The dependency injection may vary between field and constructor injection. Thus, it is possible to define, whether to + * include annotations on the field. * * @author Gunnar Morling * @author Andreas Gudian + * @author Kevin Grüneberg */ public class AnnotationMapperReference extends MapperReference { private final List annotations; - public AnnotationMapperReference(Type type, String variableName, List annotations, boolean isUsed) { + private final boolean fieldFinal; + + private final boolean includeAnnotationsOnField; + + public AnnotationMapperReference(Type type, String variableName, List annotations, boolean isUsed, + boolean fieldFinal, boolean includeAnnotationsOnField) { super( type, variableName, isUsed ); this.annotations = annotations; + this.fieldFinal = fieldFinal; + this.includeAnnotationsOnField = includeAnnotationsOnField; } public List getAnnotations() { @@ -54,4 +64,22 @@ public Set getImportTypes() { return types; } + + public boolean isFieldFinal() { + return fieldFinal; + } + + public boolean isIncludeAnnotationsOnField() { + return includeAnnotationsOnField; + } + + public AnnotationMapperReference withNewAnnotations(List annotations) { + return new AnnotationMapperReference( + getType(), + getVariableName(), + annotations, + isUsed(), + isFieldFinal(), + isIncludeAnnotationsOnField() ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java index b6e1916a5b..0f07dd528a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java @@ -18,8 +18,12 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Type; + /** - * Basic interface class that facilitates an empty constructor + * Basic interface class that facilitates an empty constructor. * * @author Sjaak Derksen */ @@ -27,4 +31,6 @@ public interface Constructor { String getName(); + Set getImportTypes(); + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 98d499ef87..592620997e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -68,14 +68,9 @@ public abstract class GeneratedType extends ModelElement { // CHECKSTYLE:OFF protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName, - String interfacePackage, String interfaceName, - List methods, - List fields, - Options options, - VersionInformation versionInformation, - Accessibility accessibility, - SortedSet extraImportedTypes, - Constructor constructor ) { + String interfacePackage, String interfaceName, List methods, + List fields, Options options, VersionInformation versionInformation, + Accessibility accessibility, SortedSet extraImportedTypes, Constructor constructor) { this.packageName = packageName; this.name = name; this.superClassName = superClassName; @@ -169,6 +164,10 @@ public Accessibility getAccessibility() { return accessibility; } + public void setConstructor(Constructor constructor) { + this.constructor = constructor; + } + @Override public SortedSet getImportTypes() { SortedSet importedTypes = new TreeSet(); @@ -196,6 +195,12 @@ public SortedSet getImportTypes() { addIfImportRequired( importedTypes, extraImport ); } + if ( constructor != null ) { + for ( Type type : constructor.getImportTypes() ) { + addIfImportRequired( importedTypes, type ); + } + } + return importedTypes; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 6a3cda066a..b893cf312a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -18,11 +18,6 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -61,6 +56,11 @@ import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; + /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to * {@code int Target#bar}. Name and type of source and target property can differ. If they have different types, the diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java new file mode 100644 index 0000000000..18860bc37e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.prism; + +/** + * Prism for the enum {@link org.mapstruct.InjectionStrategy}. + * + * @author Kevin Grüneberg + */ +public enum InjectionStrategyPrism { + + FIELD, + CONSTRUCTOR; +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index bd59486a40..421ce0d991 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -20,27 +20,32 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.ListIterator; +import java.util.Set; import javax.lang.model.element.TypeElement; +import org.mapstruct.ap.internal.model.AnnotatedConstructor; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.AnnotationMapperReference; import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.MapperReference; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; import org.mapstruct.ap.internal.util.MapperConfiguration; /** - * An {@link ModelElementProcessor} which converts the given {@link Mapper} - * object into an annotation based component model in case a matching model is selected as - * target component model for this mapper. + * An {@link ModelElementProcessor} which converts the given {@link Mapper} object into an annotation based component + * model in case a matching model is selected as target component model for this mapper. * * @author Gunnar Morling * @author Andreas Gudian + * @author Kevin Grüneberg */ public abstract class AnnotationBasedComponentModelProcessor implements ModelElementProcessor { @@ -50,8 +55,10 @@ public abstract class AnnotationBasedComponentModelProcessor implements ModelEle public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, Mapper mapper) { this.typeFactory = context.getTypeFactory(); - String componentModel = MapperConfiguration.getInstanceOn( mapperTypeElement ) - .componentModel( context.getOptions() ); + MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn( mapperTypeElement ); + + String componentModel = mapperConfiguration.componentModel( context.getOptions() ); + InjectionStrategyPrism injectionStrategy = mapperConfiguration.getInjectionStrategy(); if ( !getComponentModelIdentifier().equalsIgnoreCase( componentModel ) ) { return mapper; @@ -65,21 +72,26 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, M mapper.removeDecorator(); } else if ( mapper.getDecorator() != null ) { - adjustDecorator( mapper ); + adjustDecorator( mapper, injectionStrategy ); } List annotations = getMapperReferenceAnnotations(); ListIterator iterator = mapper.getReferencedMappers().listIterator(); + while ( iterator.hasNext() ) { MapperReference reference = iterator.next(); iterator.remove(); - iterator.add( replacementMapperReference( reference, annotations ) ); + iterator.add( replacementMapperReference( reference, annotations, injectionStrategy ) ); + } + + if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) { + buildConstructors( mapper ); } return mapper; } - protected void adjustDecorator(Mapper mapper) { + protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionStrategy) { Decorator decorator = mapper.getDecorator(); for ( Annotation typeAnnotation : getDecoratorAnnotations() ) { @@ -88,17 +100,111 @@ protected void adjustDecorator(Mapper mapper) { decorator.removeConstructor(); - List annotations = getDelegatorReferenceAnnotations( mapper ); List replacement = new ArrayList(); if ( !decorator.getMethods().isEmpty() ) { for ( Field field : decorator.getFields() ) { - replacement.add( replacementMapperReference( field, annotations ) ); + replacement.add( replacementMapperReference( field, annotations, injectionStrategy ) ); } } decorator.setFields( replacement ); } + private void buildConstructors(Mapper mapper) { + if ( !mapper.getReferencedMappers().isEmpty() ) { + AnnotatedConstructor annotatedConstructor = buildAnnotatedConstructorForMapper( mapper ); + + if ( !annotatedConstructor.getMapperReferences().isEmpty() ) { + mapper.setConstructor( annotatedConstructor ); + } + } + + Decorator decorator = mapper.getDecorator(); + + if ( decorator != null ) { + AnnotatedConstructor decoratorConstructor = buildAnnotatedConstructorForDecorator( decorator ); + if ( !decoratorConstructor.getMapperReferences().isEmpty() ) { + decorator.setConstructor( decoratorConstructor ); + } + } + } + + private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { + List mapperReferencesForConstructor = + new ArrayList( mapper.getReferencedMappers().size() ); + + for ( MapperReference mapperReference : mapper.getReferencedMappers() ) { + mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference ); + } + + List mapperReferenceAnnotations = getMapperReferenceAnnotations(); + + removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); + + return new AnnotatedConstructor( + mapper.getName(), + mapperReferencesForConstructor, + mapperReferenceAnnotations, + additionalPublicEmptyConstructor() ); + } + + private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) { + List mapperReferencesForConstructor = + new ArrayList( decorator.getFields().size() ); + + for ( Field field : decorator.getFields() ) { + if ( field instanceof AnnotationMapperReference ) { + mapperReferencesForConstructor.add( (AnnotationMapperReference) field ); + } + } + + List mapperReferenceAnnotations = getMapperReferenceAnnotations(); + + removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); + + return new AnnotatedConstructor( + decorator.getName(), + mapperReferencesForConstructor, + mapperReferenceAnnotations, + additionalPublicEmptyConstructor() ); + } + + /** + * Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it + * does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject + * annotation is on the constructor and does not need to be on the constructor parameters. + * + * @param annotationMapperReferences annotations to annotate the constructor parameter with + * @param mapperReferenceAnnotations annotations to annotate the constructor with + */ + private void removeDuplicateAnnotations(List annotationMapperReferences, + List mapperReferenceAnnotations) { + ListIterator mapperReferenceIterator = annotationMapperReferences.listIterator(); + + Set mapperReferenceAnnotationsTypes = new HashSet(); + for ( Annotation annotation : mapperReferenceAnnotations ) { + mapperReferenceAnnotationsTypes.add( annotation.getType() ); + } + + while ( mapperReferenceIterator.hasNext() ) { + AnnotationMapperReference annotationMapperReference = mapperReferenceIterator.next(); + mapperReferenceIterator.remove(); + + List qualifiers = new ArrayList(); + for ( Annotation annotation : annotationMapperReference.getAnnotations() ) { + if ( !mapperReferenceAnnotationsTypes.contains( annotation.getType() ) ) { + qualifiers.add( annotation ); + } + } + + mapperReferenceIterator.add( annotationMapperReference.withNewAnnotations( qualifiers ) ); + } + } + + protected boolean additionalPublicEmptyConstructor() { + return false; + } + protected List getDelegatorReferenceAnnotations(Mapper mapper) { return Collections.emptyList(); } @@ -106,16 +212,23 @@ protected List getDelegatorReferenceAnnotations(Mapper mapper) { /** * @param originalReference the reference to be replaced * @param annotations the list of annotations - * + * @param injectionStrategyPrism strategy for injection * @return the mapper reference replacing the original one */ - protected MapperReference replacementMapperReference(Field originalReference, List annotations) { + protected MapperReference replacementMapperReference(Field originalReference, List annotations, + InjectionStrategyPrism injectionStrategyPrism) { + boolean finalField = + injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor(); + + boolean includeAnnotationsOnField = injectionStrategyPrism == InjectionStrategyPrism.FIELD; + return new AnnotationMapperReference( originalReference.getType(), originalReference.getVariableName(), annotations, - originalReference.isUsed() - ); + originalReference.isUsed(), + finalField, + includeAnnotationsOnField ); } /** @@ -125,7 +238,6 @@ protected MapperReference replacementMapperReference(Field originalReference, Li /** * @param mapper the mapper - * * @return the annotation(s) to be added at the mapper type implementation */ protected abstract List getTypeAnnotations(Mapper mapper); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java index 582439c05c..cb41987785 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java @@ -55,4 +55,9 @@ protected List getMapperReferenceAnnotations() { protected boolean requiresGenerationOfDecoratorClass() { return false; } + + @Override + protected boolean additionalPublicEmptyConstructor() { + return true; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index e9118a585e..721a7dfff5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -29,6 +29,7 @@ import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; import org.mapstruct.ap.internal.prism.MapperConfigPrism; import org.mapstruct.ap.internal.prism.MapperPrism; import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; @@ -155,6 +156,15 @@ public NullValueCheckStrategyPrism getNullValueCheckStrategy() { } } + public InjectionStrategyPrism getInjectionStrategy() { + if ( mapperConfigPrism != null && mapperPrism.values.injectionStrategy() == null ) { + return InjectionStrategyPrism.valueOf( mapperConfigPrism.injectionStrategy() ); + } + else { + return InjectionStrategyPrism.valueOf( mapperPrism.injectionStrategy() ); + } + } + public NullValueMappingStrategyPrism getNullValueMappingStrategy() { if ( mapperConfigPrism != null && mapperPrism.values.nullValueMappingStrategy() == null ) { return NullValueMappingStrategyPrism.valueOf( mapperConfigPrism.nullValueMappingStrategy() ); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl new file mode 100644 index 0000000000..78c3a76c4a --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl @@ -0,0 +1,35 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotatedConstructor" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + +<#if publicEmptyConstructor> +public ${name}() { +} + + +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + +public ${name}(<#list mapperReferences as mapperReference><#list mapperReference.annotations as annotation><@includeModel object=annotation/> <@includeModel object=mapperReference.type/> ${mapperReference.variableName}<#if mapperReference_has_next>, ) { + <#list mapperReferences as mapperReference> + this.${mapperReference.variableName} = ${mapperReference.variableName}; + +} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl index fa4e5dcfb7..ac42d221e3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl @@ -19,7 +19,9 @@ limitations under the License. --> -<#list annotations as annotation> -<#nt><@includeModel object=annotation/> - -private <@includeModel object=type/> ${variableName}; \ No newline at end of file +<#if includeAnnotationsOnField> + <#list annotations as annotation> + <#nt><@includeModel object=annotation/> + + +private <#if fieldFinal>final <@includeModel object=type/> ${variableName}; \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java new file mode 100644 index 0000000000..7dd675c9bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.decorator.spring.constructor; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@DecoratedWith(PersonMapperDecorator.class) +public interface PersonMapper { + + @Mapping( target = "name", ignore = true ) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java new file mode 100644 index 0000000000..0f7c0e726e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.decorator.spring.constructor; + +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +public abstract class PersonMapperDecorator implements PersonMapper { + + @Autowired + @Qualifier("delegate") + private PersonMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java new file mode 100644 index 0000000000..dd3aefcfbf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java @@ -0,0 +1,107 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.decorator.spring.constructor; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Calendar; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +/** + * Test for the application of decorators using component model spring. + * + * @author Andreas Gudian + */ +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + PersonMapper.class, + PersonMapperDecorator.class +}) +@IssueKey("592") +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = SpringDecoratorTest.class) +@Configuration +public class SpringDecoratorTest { + + @Autowired + private PersonMapper personMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldInvokeDecoratorMethods() { + //given + Calendar birthday = Calendar.getInstance(); + birthday.set( 1928, 4, 23 ); + Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); + + //when + PersonDto personDto = personMapper.personToPersonDto( person ); + + //then + assertThat( personDto ).isNotNull(); + assertThat( personDto.getName() ).isEqualTo( "Gary Crant" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } + + @Test + public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { + //given + Address address = new Address( "42 Ocean View Drive" ); + + //when + AddressDto addressDto = personMapper.addressToAddressDto( address ); + + //then + assertThat( addressDto ).isNotNull(); + assertThat( addressDto.getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java index decbb04a5f..3fdbd0dd6e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java @@ -16,9 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.decorator.spring; +package org.mapstruct.ap.test.decorator.spring.field; import org.mapstruct.DecoratedWith; +import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.ap.test.decorator.Address; @@ -26,7 +27,7 @@ import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; -@Mapper(componentModel = "spring") +@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) @DecoratedWith(PersonMapperDecorator.class) public interface PersonMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java similarity index 96% rename from processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapperDecorator.java rename to processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java index 9870460fb3..c9069cf9e1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/PersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.decorator.spring; +package org.mapstruct.ap.test.decorator.spring.field; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java similarity index 98% rename from processor/src/test/java/org/mapstruct/ap/test/decorator/spring/SpringDecoratorTest.java rename to processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java index ddae3084f0..e95fa9a6f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.decorator.spring; +package org.mapstruct.ap.test.decorator.spring.field; import static org.assertj.core.api.Assertions.assertThat; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java new file mode 100644 index 0000000000..d83d38f081 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +public interface ConstructorJsr330Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java new file mode 100644 index 0000000000..2193fe58cb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Kevin Grüneberg + */ +@Mapper( componentModel = "jsr330", + uses = GenderJsr330ConstructorMapper.class, + injectionStrategy = InjectionStrategy.CONSTRUCTOR ) +public interface CustomerJsr330ConstructorMapper { + + @Mapping(source = "gender", target = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java new file mode 100644 index 0000000000..fa813ce841 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Kevin Grüneberg + */ +@Mapper(config = ConstructorJsr330Config.class) +public interface GenderJsr330ConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java new file mode 100644 index 0000000000..3f85a13535 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -0,0 +1,107 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test constructor injection for component model spring. + * + * @author Kevin Grüneberg + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330ConstructorMapper.class, + GenderJsr330ConstructorMapper.class, + ConstructorJsr330Config.class +}) +@IssueKey("571") +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class) +@Configuration +public class Jsr330ConstructorMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerJsr330ConstructorMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveConstructorInjection() { + generatedSource.forMapper( CustomerJsr330ConstructorMapper.class ) + .content() + .contains( "private final GenderJsr330ConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJsr330ConstructorMapperImpl(GenderJsr330ConstructorMapper" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java new file mode 100644 index 0000000000..55dba208dd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Kevin Grüneberg + */ +@Mapper(componentModel = "jsr330", uses = GenderJsr330FieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) +public interface CustomerJsr330FieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java new file mode 100644 index 0000000000..2dab52dc57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.FIELD) +public interface FieldJsr330Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java new file mode 100644 index 0000000000..b72ec8078c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.field; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Kevin Grüneberg + */ +@Mapper(config = FieldJsr330Config.class) +public interface GenderJsr330FieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java new file mode 100644 index 0000000000..ac42d731af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -0,0 +1,109 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.field; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test field injection for component model spring. + * + * @author Kevin Grüneberg + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330FieldMapper.class, + GenderJsr330FieldMapper.class, + FieldJsr330Config.class +}) +@IssueKey("571") +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class) +@Configuration +public class Jsr330FieldMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Inject + @Named + private CustomerJsr330FieldMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerJsr330FieldMapper.class ) + .content() + .contains( "@Inject" + lineSeparator() + " private GenderJsr330FieldMapper" ) + .doesNotContain( "public CustomerJsr330FieldMapperImpl(" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java new file mode 100644 index 0000000000..398b890899 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +/** + * @author Kevin Grüneberg + */ +public class CustomerDto { + + private GenderDto gender; + + private String name; + + public GenderDto getGender() { + return gender; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void setGender(GenderDto gender) { + this.gender = gender; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java new file mode 100644 index 0000000000..862e7156a8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +/** + * @author Kevin Grüneberg + */ +public class CustomerEntity { + + private Gender gender; + + private String name; + + public Gender getGender() { + return gender; + } + + public void setGender(Gender gender) { + this.gender = gender; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java new file mode 100644 index 0000000000..5d923ab921 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +/** + * @author Kevin Grüneberg + */ +public enum Gender { + + MALE, FEMALE + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java new file mode 100644 index 0000000000..567aac964b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +/** + * @author Kevin Grüneberg + */ +public enum GenderDto { + + M, F + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java new file mode 100644 index 0000000000..33f941afe9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +public interface ConstructorSpringConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java new file mode 100644 index 0000000000..d5812bb8ba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Kevin Grüneberg + */ +@Mapper( componentModel = "spring", + uses = GenderSpringConstructorMapper.class, + injectionStrategy = InjectionStrategy.CONSTRUCTOR ) +public interface CustomerSpringConstructorMapper { + + @Mapping( source = "gender", target = "gender" ) + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java new file mode 100644 index 0000000000..bc2667deed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.constructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Kevin Grüneberg + */ +@Mapper(config = ConstructorSpringConfig.class) +public interface GenderSpringConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java new file mode 100644 index 0000000000..1b0dba77e8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -0,0 +1,107 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.constructor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test constructor injection for component model spring. + * + * @author Kevin Grüneberg + */ +@WithClasses( { + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerSpringConstructorMapper.class, + GenderSpringConstructorMapper.class, + ConstructorSpringConfig.class +} ) +@IssueKey( "571" ) +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class) +@Configuration +public class SpringConstructorMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerSpringConstructorMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveConstructorInjection() { + generatedSource.forMapper( CustomerSpringConstructorMapper.class ) + .content() + .contains( "private final GenderSpringConstructorMapper" ) + .contains( "@Autowired" + lineSeparator() + + " public CustomerSpringConstructorMapperImpl(GenderSpringConstructorMapper" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java new file mode 100644 index 0000000000..d0a685825b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Kevin Grüneberg + */ +@Mapper(componentModel = "spring", uses = GenderSpringFieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) +public interface CustomerSpringFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java new file mode 100644 index 0000000000..f712d14788 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) +public interface FieldSpringConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java new file mode 100644 index 0000000000..655a640a8a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.field; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Kevin Grüneberg + */ +@Mapper(config = FieldSpringConfig.class) +public interface GenderSpringFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java new file mode 100644 index 0000000000..37ac7ff989 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java @@ -0,0 +1,106 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring.field; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test field injection for component model spring. + * + * @author Kevin Grüneberg + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerSpringFieldMapper.class, + GenderSpringFieldMapper.class, + FieldSpringConfig.class +}) +@IssueKey("571") +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerSpringFieldMapper.class) +@Configuration +public class SpringFieldMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerSpringFieldMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerSpringFieldMapper.class ) + .content() + .contains( "@Autowired" + lineSeparator() + " private GenderSpringFieldMapper" ) + .doesNotContain( "public CustomerSpringFieldMapperImpl(" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java index e91c9bf90c..be2ccb41dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java @@ -25,11 +25,13 @@ import org.junit.Test; import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.InjectionStrategy; import org.mapstruct.MappingInheritanceStrategy; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ReportingPolicy; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -71,6 +73,12 @@ public void reportingPolicyPrismIsCorrect() { namesOf( ReportingPolicyPrism.values() ) ); } + @Test + public void injectionStrategyPrismIsCorrect() { + assertThat( namesOf( InjectionStrategy.values() ) ).isEqualTo( + namesOf( InjectionStrategyPrism.values() ) ); + } + private static List namesOf(Enum[] values) { List names = new ArrayList( values.length ); From 8143aa81e21ef3385449858959ae73182c29f66f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 5 Sep 2017 22:04:50 +0200 Subject: [PATCH 0158/1006] #571 Add test for default injection strategy --- .../_default/CustomerSpringDefaultMapper.java | 32 ++++++ .../_default/GenderSpringDefaultMapper.java | 38 +++++++ .../_default/SpringDefaultMapperTest.java | 105 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java new file mode 100644 index 0000000000..8c9b38ecb9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring._default; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = "spring", uses = GenderSpringDefaultMapper.class ) +public interface CustomerSpringDefaultMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java new file mode 100644 index 0000000000..18085d4072 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring._default; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = "spring") +public interface GenderSpringDefaultMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java new file mode 100644 index 0000000000..e07db6a465 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java @@ -0,0 +1,105 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.injectionstrategy.spring._default; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test field injection for component model spring. + * + * @author Filip Hrisafov + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerSpringDefaultMapper.class, + GenderSpringDefaultMapper.class +}) +@IssueKey("571") +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerSpringDefaultMapper.class) +@Configuration +public class SpringDefaultMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerSpringDefaultMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerSpringDefaultMapper.class ) + .content() + .contains( "@Autowired" + lineSeparator() + " private GenderSpringDefaultMapper" ) + .doesNotContain( "public CustomerSpringDefaultMapperImpl(" ); + } +} From 946b8c86315049c22b6beea472a8c7aeb5b62544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Fri, 20 Oct 2017 23:28:41 +0200 Subject: [PATCH 0159/1006] #1312 Change MapStruct Version in README to latest 1.2.0.Final --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 393c9b2620..52904f7559 100644 --- a/readme.md +++ b/readme.md @@ -66,7 +66,7 @@ For Maven-based projects add the following to your POM file in order to use MapS ```xml ... - 1.1.0.Final + 1.2.0.Final ... @@ -111,9 +111,9 @@ plugins { } dependencies { ... - compile 'org.mapstruct:mapstruct:1.1.0.Final' // OR use this with Java 8 and beyond: org.mapstruct:mapstruct-jdk8:... + compile 'org.mapstruct:mapstruct:1.2.0.Final' // OR use this with Java 8 and beyond: org.mapstruct:mapstruct-jdk8:... - apt 'org.mapstruct:mapstruct-processor:1.1.0.Final' + apt 'org.mapstruct:mapstruct-processor:1.2.0.Final' } ... ``` From 92fe1093e4200e63e614fbdc715beaa70dde0c3c Mon Sep 17 00:00:00 2001 From: spoerri Date: Sun, 22 Oct 2017 15:06:17 -0400 Subject: [PATCH 0160/1006] #610 Add support for unmappedSourcePolicy --- .../src/main/java/org/mapstruct/Mapper.java | 9 ++ .../main/java/org/mapstruct/MapperConfig.java | 8 ++ .../mapstruct-reference-guide.asciidoc | 12 ++ .../org/mapstruct/ap/MappingProcessor.java | 4 + .../ap/internal/model/BeanMappingMethod.java | 44 ++++++ .../mapstruct/ap/internal/option/Options.java | 7 + .../ap/internal/util/MapperConfiguration.java | 17 +++ .../mapstruct/ap/internal/util/Message.java | 2 + .../ap/test/unmappedsource/Config.java | 30 ++++ .../ErroneousStrictSourceTargetMapper.java | 36 +++++ .../unmappedsource/SourceTargetMapper.java | 36 +++++ .../unmappedsource/UnmappedSourceTest.java | 134 ++++++++++++++++++ .../UsesConfigFromAnnotationMapper.java | 36 +++++ 13 files changed, 375 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/ErroneousStrictSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UsesConfigFromAnnotationMapper.java diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index 85458b39e0..c01cf96868 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -54,6 +54,15 @@ */ Class[] imports() default { }; + /** + * How unmapped properties of the source type of a mapping should be + * reported. The method overrides an unmappedSourcePolicy set in a central + * configuration set by {@link #config() } + * + * @return The reporting policy for unmapped source properties. + */ + ReportingPolicy unmappedSourcePolicy() default ReportingPolicy.IGNORE; + /** * How unmapped properties of the target type of a mapping should be * reported. The method overrides an unmappedTargetPolicy set in a central diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index fdf27a4677..343966e5ae 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -57,6 +57,14 @@ */ Class[] uses() default { }; + /** + * How unmapped properties of the source type of a mapping should be + * reported. + * + * @return The reporting policy for unmapped source properties. + */ + ReportingPolicy unmappedSourcePolicy() default ReportingPolicy.IGNORE; + /** * How unmapped properties of the target type of a mapping should be * reported. diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index ca8cdf66f7..cbc2573534 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -257,6 +257,18 @@ Supported values are: If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. |`WARN` + +|`mapstruct.unmappedSourcePolicy` +|The default reporting policy to be applied in case an attribute of the source object of a mapping method is not populating an attribute of the target object. + +Supported values are: + +* `ERROR`: any unmapped source property will cause the mapping code generation to fail +* `WARN`: any unmapped source property will cause a warning at build time +* `IGNORE`: unmapped source properties are ignored + +If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence. +|`IGNORE` |=== === Using MapStruct on Java 9 diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 76c4f6a838..74f81b8208 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -91,6 +91,7 @@ MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP, MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, MappingProcessor.UNMAPPED_TARGET_POLICY, + MappingProcessor.UNMAPPED_SOURCE_POLICY, MappingProcessor.DEFAULT_COMPONENT_MODEL }) public class MappingProcessor extends AbstractProcessor { @@ -104,6 +105,7 @@ public class MappingProcessor extends AbstractProcessor { protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT = "mapstruct.suppressGeneratorVersionInfoComment"; protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; + protected static final String UNMAPPED_SOURCE_POLICY = "mapstruct.unmappedSourcePolicy"; protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; @@ -132,11 +134,13 @@ public synchronized void init(ProcessingEnvironment processingEnv) { private Options createOptions() { String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY ); + String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); return new Options( Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, + unmappedSourcePolicy != null ? ReportingPolicyPrism.valueOf( unmappedSourcePolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 9be385b624..811b7dee07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -82,6 +82,7 @@ public static class Builder { private MappingBuilderContext ctx; private Method method; private Map unprocessedTargetProperties; + private Map unprocessedSourceProperties; private Set targetProperties; private final List propertyMappings = new ArrayList(); private final Set unprocessedSourceParameters = new HashSet(); @@ -115,8 +116,17 @@ private Builder setupMethodWithMapping(Method sourceMethod) { this.targetProperties = accessors.keySet(); this.unprocessedTargetProperties = new LinkedHashMap( accessors ); + this.unprocessedSourceProperties = new LinkedHashMap(); for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); + + if ( sourceParameter.getType().isPrimitive() ) { + continue; + } + Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); + for ( String key : readAccessors.keySet() ) { + unprocessedSourceProperties.put( key, readAccessors.get( key ) ); + } } existingVariableNames.addAll( method.getParameterNames() ); return this; @@ -153,6 +163,7 @@ public BeanMappingMethod build() { // report errors on unmapped properties reportErrorForUnmappedTargetPropertiesIfRequired(); + reportErrorForUnmappedSourcePropertiesIfRequired(); // mapNullToDefault boolean mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); @@ -281,6 +292,7 @@ private void handleUnprocessedDefinedTargets() { if ( propertyMapping != null ) { unprocessedTargetProperties.remove( propertyName ); + unprocessedSourceProperties.remove( propertyName ); iterator.remove(); propertyMappings.add( propertyMapping ); } @@ -365,6 +377,7 @@ private boolean handleDefinedMappings() { // target mappings unprocessedTargetProperties.remove( handledTarget ); unprocessedDefinedTargets.remove( handledTarget ); + unprocessedSourceProperties.remove( handledTarget ); } return errorOccurred; @@ -581,6 +594,7 @@ else if ( newPropertyMapping != null ) { propertyMappings.add( propertyMapping ); targetPropertyEntriesIterator.remove(); unprocessedDefinedTargets.remove( targetPropertyName ); + unprocessedSourceProperties.remove( targetPropertyName ); } } } @@ -625,6 +639,7 @@ private void applyParameterNameBasedMapping() { targetPropertyEntriesIterator.remove(); sourceParameters.remove(); unprocessedDefinedTargets.remove( targetProperty.getKey() ); + unprocessedSourceProperties.remove( targetProperty.getKey() ); } } } @@ -733,6 +748,35 @@ else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.require ); } } + + private ReportingPolicyPrism getUnmappedSourcePolicy() { + MapperConfiguration mapperSettings = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ); + + return mapperSettings.unmappedSourcePolicy( ctx.getOptions() ); + } + + private void reportErrorForUnmappedSourcePropertiesIfRequired() { + ReportingPolicyPrism unmappedSourcePolicy = getUnmappedSourcePolicy(); + + if ( !unprocessedSourceProperties.isEmpty() && unmappedSourcePolicy.requiresReport() ) { + + Message msg = unmappedSourcePolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? + Message.BEANMAPPING_UNMAPPED_SOURCES_ERROR : Message.BEANMAPPING_UNMAPPED_SOURCES_WARNING; + Object[] args = new Object[] { + MessageFormat.format( + "{0,choice,1#property|1 Date: Sun, 22 Oct 2017 23:20:03 +0200 Subject: [PATCH 0161/1006] #610 remove unmapped source policy processor option --- .../mapstruct-reference-guide.asciidoc | 12 ----- .../org/mapstruct/ap/MappingProcessor.java | 4 -- .../ap/internal/model/BeanMappingMethod.java | 2 +- .../mapstruct/ap/internal/option/Options.java | 7 --- .../ap/internal/util/MapperConfiguration.java | 6 +-- .../unmappedsource/UnmappedSourceTest.java | 48 ------------------- 6 files changed, 2 insertions(+), 77 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index cbc2573534..ca8cdf66f7 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -257,18 +257,6 @@ Supported values are: If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. |`WARN` - -|`mapstruct.unmappedSourcePolicy` -|The default reporting policy to be applied in case an attribute of the source object of a mapping method is not populating an attribute of the target object. - -Supported values are: - -* `ERROR`: any unmapped source property will cause the mapping code generation to fail -* `WARN`: any unmapped source property will cause a warning at build time -* `IGNORE`: unmapped source properties are ignored - -If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence. -|`IGNORE` |=== === Using MapStruct on Java 9 diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 74f81b8208..76c4f6a838 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -91,7 +91,6 @@ MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP, MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, MappingProcessor.UNMAPPED_TARGET_POLICY, - MappingProcessor.UNMAPPED_SOURCE_POLICY, MappingProcessor.DEFAULT_COMPONENT_MODEL }) public class MappingProcessor extends AbstractProcessor { @@ -105,7 +104,6 @@ public class MappingProcessor extends AbstractProcessor { protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT = "mapstruct.suppressGeneratorVersionInfoComment"; protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; - protected static final String UNMAPPED_SOURCE_POLICY = "mapstruct.unmappedSourcePolicy"; protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; @@ -134,13 +132,11 @@ public synchronized void init(ProcessingEnvironment processingEnv) { private Options createOptions() { String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY ); - String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); return new Options( Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, - unmappedSourcePolicy != null ? ReportingPolicyPrism.valueOf( unmappedSourcePolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 811b7dee07..ae73e22975 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -752,7 +752,7 @@ else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.require private ReportingPolicyPrism getUnmappedSourcePolicy() { MapperConfiguration mapperSettings = MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ); - return mapperSettings.unmappedSourcePolicy( ctx.getOptions() ); + return mapperSettings.unmappedSourcePolicy(); } private void reportErrorForUnmappedSourcePropertiesIfRequired() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 66ee051c51..03adaa3544 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -30,18 +30,15 @@ public class Options { private final boolean suppressGeneratorTimestamp; private final boolean suppressGeneratorVersionComment; private final ReportingPolicyPrism unmappedTargetPolicy; - private final ReportingPolicyPrism unmappedSourcePolicy; private final boolean alwaysGenerateSpi; private final String defaultComponentModel; public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyPrism unmappedTargetPolicy, - ReportingPolicyPrism unmappedSourcePolicy, String defaultComponentModel, boolean alwaysGenerateSpi) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; - this.unmappedSourcePolicy = unmappedSourcePolicy; this.defaultComponentModel = defaultComponentModel; this.alwaysGenerateSpi = alwaysGenerateSpi; } @@ -58,10 +55,6 @@ public ReportingPolicyPrism getUnmappedTargetPolicy() { return unmappedTargetPolicy; } - public ReportingPolicyPrism getUnmappedSourcePolicy() { - return unmappedSourcePolicy; - } - public String getDefaultComponentModel() { return defaultComponentModel; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 7db9c4f1a7..4576015383 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -129,7 +129,7 @@ public ReportingPolicyPrism unmappedTargetPolicy(Options options) { return ReportingPolicyPrism.valueOf( mapperPrism.unmappedTargetPolicy() ); } - public ReportingPolicyPrism unmappedSourcePolicy(Options options) { + public ReportingPolicyPrism unmappedSourcePolicy() { if ( mapperPrism.values.unmappedSourcePolicy() != null ) { return ReportingPolicyPrism.valueOf( mapperPrism.unmappedSourcePolicy() ); } @@ -138,10 +138,6 @@ public ReportingPolicyPrism unmappedSourcePolicy(Options options) { return ReportingPolicyPrism.valueOf( mapperConfigPrism.unmappedSourcePolicy() ); } - if ( options.getUnmappedSourcePolicy() != null ) { - return options.getUnmappedSourcePolicy(); - } - // fall back to default defined in the annotation return ReportingPolicyPrism.valueOf( mapperPrism.unmappedSourcePolicy() ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 817a648d98..37f4c8c5f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -28,7 +28,6 @@ import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.test.unmappedtarget.Source; import org.mapstruct.ap.test.unmappedtarget.Target; @@ -84,51 +83,4 @@ public void shouldLeaveUnmappedSourcePropertyUnset() { ) public void shouldRaiseErrorDueToUnsetSourceProperty() { } - - @Test - @WithClasses({ Source.class, Target.class, org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class }) - @ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "ERROR") - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class, - kind = Kind.ERROR, - line = 29, - messageRegExp = "Unmapped source property: \"qux\""), - @Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class, - kind = Kind.WARNING, - line = 29, - messageRegExp = "Unmapped target property: \"bar\""), - @Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class, - kind = Kind.ERROR, - line = 31, - messageRegExp = "Unmapped source property: \"bar\""), - @Diagnostic(type = org.mapstruct.ap.test.unmappedtarget.SourceTargetMapper.class, - kind = Kind.WARNING, - line = 31, - messageRegExp = "Unmapped target property: \"qux\"") - } - ) - public void shouldRaiseErrorDueToUnsetSourcePropertyWithPolicySetViaProcessorOption() { - } - - @Test - @WithClasses({ Source.class, Target.class, UsesConfigFromAnnotationMapper.class, Config.class }) - @ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "ERROR") - @ExpectedCompilationOutcome( - value = CompilationResult.SUCCEEDED, - diagnostics = { - @Diagnostic(type = UsesConfigFromAnnotationMapper.class, - kind = Kind.WARNING, - line = 33, - messageRegExp = "Unmapped source property: \"qux\""), - @Diagnostic(type = UsesConfigFromAnnotationMapper.class, - kind = Kind.WARNING, - line = 35, - messageRegExp = "Unmapped source property: \"bar\"") - } - ) - public void shouldRaiseErrorBecauseConfiguredByAnnotation() { - } - } From a0b60a6bf47ed099b7a2ae16597957bdc921149a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Mon, 23 Oct 2017 19:59:03 +0200 Subject: [PATCH 0162/1006] #1314 Injection Strategy docs --- .../mapstruct-reference-guide.asciidoc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index ca8cdf66f7..9a5a37fda9 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -678,6 +678,32 @@ private CarMapper mapper; A mapper which uses other mapper classes (see <>) will obtain these mappers using the configured component model. So if `CarMapper` from the previous example was using another mapper, this other mapper would have to be an injectable CDI bean as well. +[[injection-strategy]] +=== Injection strategy + +When using <>, you can choose between field and constructor injection. +This can be done by either providing the injection strategy via `Mapper` or `MapperConfig` annotation. + +.Obtaining a mapper via dependency injection +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) +public interface CarMapper { + CarDto carToCarDto(Car car); +} +---- +==== + +The generated mapper will inject all classes defined in the **uses** attribute. +When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. +When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. +For now, the default injection strategy is field injection. +It is recommended to use constructor injection to simplify testing. + +TIP: For abstract classes or decorators setter injection should be used. + [[datatype-conversions]] == Data type conversions From 3df399f69331e7ced44c89b5b40da6482df07d10 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 23 Oct 2017 20:02:09 +0200 Subject: [PATCH 0163/1006] #1314 Fix some typos --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 9a5a37fda9..1998c554ac 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -682,9 +682,9 @@ A mapper which uses other mapper classes (see <>) will o === Injection strategy When using <>, you can choose between field and constructor injection. -This can be done by either providing the injection strategy via `Mapper` or `MapperConfig` annotation. +This can be done by either providing the injection strategy via `@Mapper` or `@MapperConfig` annotation. -.Obtaining a mapper via dependency injection +.Using constructor injection ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -702,7 +702,10 @@ When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. For now, the default injection strategy is field injection. It is recommended to use constructor injection to simplify testing. -TIP: For abstract classes or decorators setter injection should be used. +[TIP] +==== +For abstract classes or decorators setter injection should be used. +==== [[datatype-conversions]] == Data type conversions From e4839fce5d03580fe68b293c879e6179ddfb59be Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Nov 2017 09:34:25 +0100 Subject: [PATCH 0164/1006] #1333 Add since tags for unmappedSourcePolicy() --- core-common/src/main/java/org/mapstruct/Mapper.java | 2 ++ core-common/src/main/java/org/mapstruct/MapperConfig.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index c01cf96868..bb92a58d2f 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -60,6 +60,8 @@ * configuration set by {@link #config() } * * @return The reporting policy for unmapped source properties. + * + * @since 1.3 */ ReportingPolicy unmappedSourcePolicy() default ReportingPolicy.IGNORE; diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index 343966e5ae..e9bbec0aaf 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -62,6 +62,8 @@ * reported. * * @return The reporting policy for unmapped source properties. + * + * @since 1.3 */ ReportingPolicy unmappedSourcePolicy() default ReportingPolicy.IGNORE; From 49e39e0ed5438953692c1732192196ebb0dfb954 Mon Sep 17 00:00:00 2001 From: Richard Lea Date: Fri, 24 Nov 2017 07:41:42 +0900 Subject: [PATCH 0165/1006] #1332 Fix exceptions declaration missing in generated nested private methods --- .../model/NestedPropertyMappingMethod.java | 18 +++++-- .../ap/internal/model/PropertyMapping.java | 1 + .../ap/internal/model/common/TypeFactory.java | 19 +++++++- .../model/NestedPropertyMappingMethod.ftl | 10 +++- .../test/nestedsource/exceptions/Bucket.java | 37 +++++++++++++++ .../exceptions/NestedExceptionTest.java | 47 +++++++++++++++++++ .../nestedsource/exceptions/NoSuchUser.java | 30 ++++++++++++ .../nestedsource/exceptions/Resource.java | 32 +++++++++++++ .../nestedsource/exceptions/ResourceDto.java | 37 +++++++++++++++ .../exceptions/ResourceMapper.java | 37 +++++++++++++++ .../ap/test/nestedsource/exceptions/User.java | 44 +++++++++++++++++ 11 files changed, 306 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 91e240ee18..973761f7c7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -24,7 +24,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; @@ -44,10 +44,11 @@ public class NestedPropertyMappingMethod extends MappingMethod { public static class Builder { - private Method method; + private MappingBuilderContext ctx; + private ForgedMethod method; private List propertyEntries; - public Builder method( Method sourceMethod ) { + public Builder method( ForgedMethod sourceMethod ) { this.method = sourceMethod; return this; } @@ -57,22 +58,31 @@ public Builder propertyEntries( List propertyEntries ) { return this; } + public Builder mappingContext(MappingBuilderContext mappingContext) { + this.ctx = mappingContext; + return this; + } + public NestedPropertyMappingMethod build() { List existingVariableNames = new ArrayList(); for ( Parameter parameter : method.getSourceParameters() ) { existingVariableNames.add( parameter.getName() ); } + final List thrownTypes = new ArrayList(); List safePropertyEntries = new ArrayList(); for ( PropertyEntry propertyEntry : propertyEntries ) { String safeName = Strings.getSaveVariableName( propertyEntry.getName(), existingVariableNames ); safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); existingVariableNames.add( safeName ); + thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( + propertyEntry.getReadAccessor() ) ); } + method.addThrownTypes( thrownTypes ); return new NestedPropertyMappingMethod( method, safePropertyEntries ); } } - private NestedPropertyMappingMethod( Method method, List sourcePropertyEntries ) { + private NestedPropertyMappingMethod( ForgedMethod method, List sourcePropertyEntries ) { super( method ); this.safePropertyEntries = sourcePropertyEntries; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index b893cf312a..a455f6d784 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -504,6 +504,7 @@ Collections. emptyList(), NestedPropertyMappingMethod nestedPropertyMapping = builder .method( methodRef ) .propertyEntries( sourceReference.getPropertyEntries() ) + .mappingContext( ctx ) .build(); // add if not yet existing diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 89c3a2d90f..062d67fa6d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -382,7 +382,24 @@ public Type getReturnType(ExecutableType method) { public List getThrownTypes(ExecutableType method) { List thrownTypes = new ArrayList(); for ( TypeMirror exceptionType : method.getThrownTypes() ) { - thrownTypes.add( getType( exceptionType ) ); + Type t = getType( exceptionType ); + if (!thrownTypes.contains( t )) { + thrownTypes.add( t ); + } + } + return thrownTypes; + } + + public List getThrownTypes(Accessor accessor) { + if (accessor.getExecutable() == null) { + return new ArrayList(); + } + List thrownTypes = new ArrayList(); + for (TypeMirror thrownType : accessor.getExecutable().getThrownTypes()) { + Type t = getType( thrownType ); + if (!thrownTypes.contains( t )) { + thrownTypes.add( t ); + } } return thrownTypes; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 51f6fae684..337c6d5564 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -19,7 +19,7 @@ limitations under the License. --> -<#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { +<#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { if ( ${sourceParameter.name} == null ) { return ${returnType.null}; } @@ -43,3 +43,11 @@ } <#macro localVarName index><#if index == 0>${sourceParameter.name}<#else>${propertyEntries[index-1].name} +<#macro throws> + <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> + <#list thrownTypes as exceptionType> + <@includeModel object=exceptionType/> + <#if exceptionType_has_next>, <#t> + + + \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java new file mode 100644 index 0000000000..d541723c27 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +/** + * + * @author Richard Lea + */ +public class Bucket { + + String userId; + + public Bucket(String userId) { + this.userId = userId; + } + + public User getUser() throws NoSuchUser { + throw new NoSuchUser(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java new file mode 100644 index 0000000000..06b481eac2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * + * @author Richard Lea + */ +@WithClasses({ + Bucket.class, + User.class, + Resource.class, + ResourceDto.class, + NoSuchUser.class, + ResourceMapper.class +}) +@IssueKey("1332") +@RunWith(AnnotationProcessorTestRunner.class) +public class NestedExceptionTest { + + @Test + public void shouldGenerateCodeThatCompiles() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java new file mode 100644 index 0000000000..a7e21a4807 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +/** + * + * @author Richard Lea + */ +public class NoSuchUser extends Exception { + + public NoSuchUser() { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java new file mode 100644 index 0000000000..255e05e103 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +/** + * + * @author Richard Lea + */ +public class Resource { + + private final Bucket bucket = new Bucket("2345"); + + public Bucket getBucket() { + return bucket; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java new file mode 100644 index 0000000000..00c720aa75 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +/** + * + * @author Richard Lea + */ +public class ResourceDto { + + private String userId; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java new file mode 100644 index 0000000000..86c43b48f8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * + * @author Richard Lea + */ +@Mapper() +public interface ResourceMapper { + + @Mappings({ + @Mapping(source = "bucket.user.uuid", target = "userId") + }) + ResourceDto map(Resource r) throws NoSuchUser; + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java new file mode 100644 index 0000000000..b7c81e33f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.nestedsource.exceptions; + +/** + * + * @author Richard Lea + */ +public class User { + + private final String uuid; + + private final String name; + + public User(String uuid, String name) { + this.uuid = uuid; + this.name = name; + } + + public String getName() { + return name; + } + + public String getUuid() { + return uuid; + } + +} From faabbf7ec0e6422b30b3f73a0614ebc7239fbc89 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 23 Nov 2017 23:45:08 +0100 Subject: [PATCH 0166/1006] Add Richard and Joshua to copyright.txt --- copyright.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/copyright.txt b/copyright.txt index b927905fdb..2a04f7623d 100644 --- a/copyright.txt +++ b/copyright.txt @@ -14,6 +14,7 @@ Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla +Joshua Spoerri - https://github.com/spoerri Kevin Grüneberg - https://github.com/kevcodez Michael Pardo - https://github.com/pardom Mustafa Caylak - https://github.com/luxmeter @@ -24,6 +25,7 @@ Pavel Makhov - https://github.com/streetturtle Peter Larson - https://github.com/pjlarson Remko Plantenga - https://github.com/sonata82 Remo Meier - https://github.com/remmeier +Richard Lea - https://github.com/chigix Samuel Wright - https://github.com/samwright Sebastian Hasait - https://github.com/shasait Sean Huang - https://github.com/seanjob From 1af702e44bba9e61c8f81a0c507880477073981f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 23 Nov 2017 23:51:18 +0100 Subject: [PATCH 0167/1006] Polish after PR merge * Extract common TypeMirror extraction into a separate method * Remove not needed code from tests --- .../ap/internal/model/common/TypeFactory.java | 26 ++++++++----------- .../nestedsource/exceptions/NoSuchUser.java | 4 --- .../exceptions/ResourceMapper.java | 7 ++--- .../ap/test/nestedsource/exceptions/User.java | 9 +------ 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 062d67fa6d..964bb79c06 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -380,28 +380,24 @@ public Type getReturnType(ExecutableType method) { } public List getThrownTypes(ExecutableType method) { - List thrownTypes = new ArrayList(); - for ( TypeMirror exceptionType : method.getThrownTypes() ) { - Type t = getType( exceptionType ); - if (!thrownTypes.contains( t )) { - thrownTypes.add( t ); - } - } - return thrownTypes; + return extractTypes( method.getThrownTypes() ); } public List getThrownTypes(Accessor accessor) { if (accessor.getExecutable() == null) { return new ArrayList(); } - List thrownTypes = new ArrayList(); - for (TypeMirror thrownType : accessor.getExecutable().getThrownTypes()) { - Type t = getType( thrownType ); - if (!thrownTypes.contains( t )) { - thrownTypes.add( t ); - } + return extractTypes( accessor.getExecutable().getThrownTypes() ); + } + + private List extractTypes(List typeMirrors) { + Set types = new HashSet( typeMirrors.size() ); + + for ( TypeMirror typeMirror : typeMirrors ) { + types.add( getType( typeMirror ) ); } - return thrownTypes; + + return new ArrayList( types ); } private List getTypeParameters(TypeMirror mirror, boolean isImplementationType) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java index a7e21a4807..0a8044639a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java @@ -23,8 +23,4 @@ * @author Richard Lea */ public class NoSuchUser extends Exception { - - public NoSuchUser() { - } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java index 86c43b48f8..0b8b706cae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java @@ -20,18 +20,15 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; /** * * @author Richard Lea */ -@Mapper() +@Mapper public interface ResourceMapper { - @Mappings({ - @Mapping(source = "bucket.user.uuid", target = "userId") - }) + @Mapping(source = "bucket.user.uuid", target = "userId") ResourceDto map(Resource r) throws NoSuchUser; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java index b7c81e33f4..0f7724b81c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java @@ -26,15 +26,8 @@ public class User { private final String uuid; - private final String name; - - public User(String uuid, String name) { + public User(String uuid) { this.uuid = uuid; - this.name = name; - } - - public String getName() { - return name; } public String getUuid() { From 2190ae324b46282da26350ceef48a659f9bf92ea Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 23 Nov 2017 00:47:22 +0100 Subject: [PATCH 0168/1006] #1339 Primitive Context parameters should be skipped when looking for lifecycle methods --- .../processor/MethodRetrievalProcessor.java | 3 ++ .../ap/test/bugs/_1339/Callback.java | 34 +++++++++++++ .../ap/test/bugs/_1339/Issue1339Mapper.java | 51 +++++++++++++++++++ .../ap/test/bugs/_1339/Issue1339Test.java | 49 ++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index d434aa41b6..5ac734d3b6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -276,6 +276,9 @@ private ParameterProvidedMethods retrieveLifecycleMethodsFromContext( ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder(); for ( Parameter contextParam : contextParameters ) { + if ( contextParam.getType().isPrimitive() ) { + continue; + } List contextParamMethods = retrieveMethods( contextParam.getType().getTypeElement(), mapperToImplement, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java new file mode 100644 index 0000000000..5724322c01 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1339; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Context; +import org.mapstruct.MappingTarget; + +/** + * @author Filip Hrisafov + */ +public class Callback { + + @AfterMapping + public void afterMapping(@MappingTarget Issue1339Mapper.Target target, @Context int primitive) { + target.otherField = primitive; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java new file mode 100644 index 0000000000..d11d41f4b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1339; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = { + Callback.class +}) +public interface Issue1339Mapper { + + Issue1339Mapper INSTANCE = Mappers.getMapper( Issue1339Mapper.class ); + + class Source { + //CHECKSTYLE:OFF + public String field; + //CHECKSTYLE:ON + } + + class Target { + //CHECKSTYLE:OFF + public String field; + public int otherField; + //CHECKSTYLE:ON + } + + @Mapping(target = "otherField", ignore = true) + Target map(Source source, int primitive1, @Context int primitive2); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java new file mode 100644 index 0000000000..63dcc1f100 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1339; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue1339Mapper.class, + Callback.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1339") +public class Issue1339Test { + + @Test + public void shouldCompile() { + Issue1339Mapper.Source source = new Issue1339Mapper.Source(); + source.field = "test"; + Issue1339Mapper.Target target = Issue1339Mapper.INSTANCE.map( source, 10, 50 ); + + assertThat( target.otherField ).isEqualTo( 50 ); + assertThat( target.field ).isEqualTo( "test" ); + } +} From 460e87eef6eb71245b387fdb0509c726676a8e19 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 22 Nov 2017 21:44:39 +0100 Subject: [PATCH 0169/1006] #1340 Create correct overriden method for Value Mappings * The Value / Enum Mappings should copy all the parameters from the method that is being overriden * The source parameter should be the first source parameter --- .../ap/internal/model/EnumMappingMethod.java | 2 +- .../ap/internal/model/ValueMappingMethod.java | 2 +- .../ap/internal/model/EnumMappingMethod.ftl | 2 +- .../ap/internal/model/ValueMappingMethod.ftl | 2 +- .../ap/test/bugs/_1340/Issue1340Mapper.java | 46 +++++++++++++++++++ .../ap/test/bugs/_1340/Issue1340Test.java | 40 ++++++++++++++++ 6 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index eb401b56d7..f91e6231c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -209,6 +209,6 @@ public List getEnumMappings() { } public Parameter getSourceParameter() { - return first( getParameters() ); + return first( getSourceParameters() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 2d3789419e..c1568a2f07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -284,7 +284,7 @@ public boolean isThrowIllegalArgumentException() { } public Parameter getSourceParameter() { - return first( getParameters() ); + return first( getSourceParameters() ); } public boolean isOverridden() { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl index b8d0498cee..628d760fc6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl @@ -20,7 +20,7 @@ --> @Override -public <@includeModel object=returnType/> ${name}(<@includeModel object=sourceParameter/>) { +public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> <#if !callback_has_next> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index ba2d8f9650..9163417f2c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -20,7 +20,7 @@ --> <#if overridden>@Override -<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<@includeModel object=sourceParameter/>) { +<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> <#if !callback_has_next> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java new file mode 100644 index 0000000000..72cd7b2997 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1340; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1340Mapper { + + Issue1340Mapper INSTANCE = Mappers.getMapper( Issue1340Mapper.class ); + + enum Quote { + SINGLE, + MULTI + } + + enum QuoteDto { + SINGLE, + MULTI + } + + QuoteDto map(Quote quote, @Context Integer locale); + + Quote map(@Context Integer locale, QuoteDto quoteDto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java new file mode 100644 index 0000000000..b303beb4d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1340; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue1340Mapper.class +}) +@IssueKey("1340") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1340Test { + + @Test + public void shouldCompile() { + } +} From 3f8b1e46d46203ddb3d4ef72c74fd8490d9709d9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 26 Nov 2017 22:23:02 +0100 Subject: [PATCH 0170/1006] #1320 Properly create additional options for unprocessed defined targets Create mappings for each unprocessed defined target based on their name and the mapping --- .../ap/internal/model/BeanMappingMethod.java | 7 +- .../ap/test/bugs/_1320/Issue1320Mapper.java | 39 +++++++++++ .../ap/test/bugs/_1320/Issue1320Test.java | 49 +++++++++++++ .../mapstruct/ap/test/bugs/_1320/Target.java | 68 +++++++++++++++++++ 4 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index ae73e22975..9981deac7c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -650,10 +650,9 @@ private MappingOptions extractAdditionalOptions(String targetProperty, boolean r if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { Map> mappings = new HashMap>(); - mappings.put( - targetProperty, - unprocessedDefinedTargets.get( targetProperty ) - ); + for ( Mapping mapping : unprocessedDefinedTargets.get( targetProperty ) ) { + mappings.put( mapping.getTargetName(), Collections.singletonList( mapping ) ); + } additionalOptions = MappingOptions.forMappingsOnly( mappings, restrictToDefinedMappings ); } return additionalOptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java new file mode 100644 index 0000000000..f7e09e6d00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1320; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1320Mapper { + + Issue1320Mapper INSTANCE = Mappers.getMapper( Issue1320Mapper.class ); + + @Mappings({ + @Mapping(target = "address.city.cityName", constant = "myCity"), + @Mapping(target = "address.city.stateName", constant = "myState") + }) + Target map(Integer dummy); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java new file mode 100644 index 0000000000..563ffbfd2f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1320; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1320") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1320Mapper.class, + Target.class +}) +public class Issue1320Test { + + @Test + public void shouldCreateDeepNestedConstantsCorrectly() { + Target target = Issue1320Mapper.INSTANCE.map( 10 ); + + assertThat( target.getAddress() ).isNotNull(); + assertThat( target.getAddress().getCity() ).isNotNull(); + assertThat( target.getAddress().getCity().getCityName() ).isEqualTo( "myCity" ); + assertThat( target.getAddress().getCity().getStateName() ).isEqualTo( "myState" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java new file mode 100644 index 0000000000..b848d25f38 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1320; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Address address; + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public static class Address { + private City city; + + public City getCity() { + return city; + } + + public void setCity(City city) { + this.city = city; + } + } + + public static class City { + private String cityName; + private String stateName; + + public String getCityName() { + return cityName; + } + + public void setCityName(String cityName) { + this.cityName = cityName; + } + + public String getStateName() { + return stateName; + } + + public void setStateName(String stateName) { + this.stateName = stateName; + } + } +} From f31d234ba0d8a124b3cc5befe7c4a873f32f5b43 Mon Sep 17 00:00:00 2001 From: Jeff Smyth Date: Fri, 29 Dec 2017 16:18:20 -0500 Subject: [PATCH 0171/1006] #1353 Add a trim for source and target mappings, but log a warning message if trimmed. --- .../model/source/SourceReference.java | 13 +++- .../model/source/TargetReference.java | 14 +++- .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/test/bugs/_1353/Issue1353Mapper.java | 38 ++++++++++ .../ap/test/bugs/_1353/Issue1353Test.java | 71 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1353/Source.java | 35 +++++++++ .../mapstruct/ap/test/bugs/_1353/Target.java | 35 +++++++++ 7 files changed, 204 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index c8374db8aa..60353dc94b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -108,8 +108,19 @@ public SourceReference build() { boolean isValid = true; boolean foundEntryMatch; + String sourceNameTrimmed = sourceName.trim(); + if ( !sourceName.equals( sourceNameTrimmed ) ) { + messager.printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getSourceAnnotationValue(), + Message.PROPERTYMAPPING_WHITESPACE_TRIMMED, + sourceName, + sourceNameTrimmed + ); + } String[] sourcePropertyNames = new String[0]; - String[] segments = sourceName.split( "\\." ); + String[] segments = sourceNameTrimmed.split( "\\." ); Parameter parameter = null; List entries = new ArrayList(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index bd51a09481..b298194f3e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -138,8 +138,18 @@ public TargetReference build() { return null; } - - String[] segments = targetName.split( "\\." ); + String targetNameTrimmed = targetName.trim(); + if ( !targetName.equals( targetNameTrimmed ) ) { + messager.printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + Message.PROPERTYMAPPING_WHITESPACE_TRIMMED, + targetName, + targetNameTrimmed + ); + } + String[] segments = targetNameTrimmed.split( "\\." ); Parameter parameter = method.getMappingTargetParameter(); boolean foundEntryMatch; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 7a664cf204..ce86aa06cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -61,6 +61,7 @@ public enum Message { PROPERTYMAPPING_NO_PRESENCE_CHECKER_FOR_SOURCE_TYPE( "Using custom source value presence checking strategy, but no presence checker found for %s in source type." ), PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), + PROPERTYMAPPING_WHITESPACE_TRIMMED( "The property named \"%s\" has whitespaces, using trimmed property \"%s\" instead.", Diagnostic.Kind.WARNING ), CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ), CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java new file mode 100644 index 0000000000..f94551460d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1353; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Jeffrey Smyth + */ +@Mapper +public interface Issue1353Mapper { + + Issue1353Mapper INSTANCE = Mappers.getMapper( Issue1353Mapper.class ); + + @Mappings ({ + @Mapping (target = "string2 ", source = " source.string1") + }) + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java new file mode 100644 index 0000000000..ad074548ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java @@ -0,0 +1,71 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1353; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Jeffrey Smyth + */ +@IssueKey ("1353") +@RunWith (AnnotationProcessorTestRunner.class) +@WithClasses ({ + Issue1353Mapper.class, + Source.class, + Target.class +}) +public class Issue1353Test { + + @Test + @ExpectedCompilationOutcome ( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic (type = Issue1353Mapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 35, + messageRegExp = "The property named \" source.string1\" has whitespaces," + + " using trimmed property \"source.string1\" instead." + ), + @Diagnostic (type = Issue1353Mapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 35, + messageRegExp = "The property named \"string2 \" has whitespaces," + + " using trimmed property \"string2\" instead." + ) + } + ) + public void shouldTrimArguments() { + Source source = new Source(); + source.setString1( "TestString" ); + + Target target = Issue1353Mapper.INSTANCE.sourceToTarget( source ); + + assertThat( target.getString2() ).isNotNull(); + assertThat( target.getString2() ).isEqualTo( source.getString1() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java new file mode 100644 index 0000000000..d216236bf2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1353; + +/** + * @author Jeffrey Smyth + */ +public class Source { + + private String string1; + + public String getString1() { + return string1; + } + + public void setString1(String string1) { + this.string1 = string1; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java new file mode 100644 index 0000000000..3197f092d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1353; + +/** + * @author Jeffrey Smyth + */ +public class Target { + + private String string2; + + public String getString2() { + return string2; + } + + public void setString2(String string2) { + this.string2 = string2; + } +} From 6dee8fbe66302645626e9d8af9cfa74c65c01ce7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 29 Dec 2017 22:33:29 +0100 Subject: [PATCH 0172/1006] Add Jeff to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 2a04f7623d..c1010269c6 100644 --- a/copyright.txt +++ b/copyright.txt @@ -14,6 +14,7 @@ Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla +Jeff Smyth - https://github.com/smythie86 Joshua Spoerri - https://github.com/spoerri Kevin Grüneberg - https://github.com/kevcodez Michael Pardo - https://github.com/pardom From 3d26318301b4e12f99ffc97d42e89e9c1e0f7982 Mon Sep 17 00:00:00 2001 From: Daniel Strobusch Date: Sun, 14 Jan 2018 11:56:35 +0100 Subject: [PATCH 0173/1006] Fixed caption of listing --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 1998c554ac..deaa323fe4 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -281,7 +281,7 @@ In this section you'll learn how to define a bean mapper with MapStruct and whic To create a mapper simply define a Java interface with the required mapping method(s) and annotate it with the `org.mapstruct.Mapper` annotation: -.Maven configuration +.Java interface to define a mapper ==== [source, java, linenums] [subs="verbatim,attributes"] From 4c1dcc5272f372ac6f07c6b1722d2c28e657c261 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Thu, 11 Jan 2018 23:15:17 +0100 Subject: [PATCH 0174/1006] #1345 ignoring reversed mappings with no target accessor silently --- .../ap/internal/model/source/Mapping.java | 12 ++-- .../model/source/TargetReference.java | 2 +- .../ap/test/bugs/_1345/Issue1345Mapper.java | 62 +++++++++++++++++++ .../ap/test/bugs/_1345/Issue1345Test.java | 40 ++++++++++++ .../NestedSourcePropertiesTest.java | 4 +- 5 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 1536c54f7e..b5fa77b6e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -37,7 +37,6 @@ import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -390,11 +389,6 @@ public List getDependsOn() { return dependsOn; } - private boolean hasPropertyInReverseMethod(String name, SourceMethod method) { - CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); - return method.getResultType().getPropertyWriteAccessors( cms ).containsKey( name ); - } - public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory) { // mapping can only be reversed if the source was not a constant nor an expression nor a nested property @@ -426,6 +420,12 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac true, sourceReference != null ? sourceReference.getParameter() : null ); + + // check if the reverse mapping has indeed a write accessor, otherwise the mapping cannot be reversed + if ( !reverse.targetReference.isValid() ) { + return null; + } + return reverse; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index b298194f3e..f4eb768a9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -170,7 +170,7 @@ && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParamete foundEntryMatch = (entries.size() == targetPropertyNames.length); } - if ( !foundEntryMatch && errorMessage != null) { + if ( !foundEntryMatch && errorMessage != null && !isReverse ) { // This is called only for reporting errors errorMessage.report( isReverse ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java new file mode 100644 index 0000000000..5b8733b951 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java @@ -0,0 +1,62 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1345; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface Issue1345Mapper { + + Issue1345Mapper INSTANCE = Mappers.getMapper( Issue1345Mapper.class ); + + @Mapping(target = "property", source = "readOnlyProperty") + B a2B(A a); + + @InheritInverseConfiguration(name = "a2B") + A b2A(B b); + + class A { + + private String readOnlyProperty; + + public String getReadOnlyProperty() { + return readOnlyProperty; + } + } + + class B { + + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java new file mode 100644 index 0000000000..0397fdc89d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1345; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ + Issue1345Mapper.class +}) +@IssueKey("1345") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1345Test { + + @Test + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 364ec0b73f..9fd9c14305 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -183,8 +183,8 @@ public void shouldUseGetAsTargetAccessor() { diagnostics = { @Diagnostic( type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 46, - messageRegExp = "Unknown property \"position\" in result type java\\.lang\\.Integer\\." ) + line = 47, + messageRegExp = "java.lang.Integer does not have an accessible empty constructor." ) } ) @WithClasses({ ArtistToChartEntryErroneous.class }) From 5707f35c8535fac90a835928686cb0d9dc7f494a Mon Sep 17 00:00:00 2001 From: sjaakd Date: Mon, 15 Jan 2018 21:14:13 +0100 Subject: [PATCH 0175/1006] #1345 cleanup non required isReverse in printing messages --- .../model/source/TargetReference.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index f4eb768a9b..56d3890240 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -30,7 +30,6 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -172,7 +171,7 @@ && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParamete if ( !foundEntryMatch && errorMessage != null && !isReverse ) { // This is called only for reporting errors - errorMessage.report( isReverse ); + errorMessage.report( ); } // foundEntryMatch = isValid, errors are handled here, and the BeanMapping uses that to ignore @@ -375,20 +374,14 @@ private MappingErrorMessage(Mapping mapping, SourceMethod method, FormattingMess this.messager = messager; } - abstract void report(boolean isReverse); + abstract void report(); - protected void printErrorMessage(Message message, boolean isReverse, Object... args) { + protected void printErrorMessage(Message message, Object... args) { Object[] errorArgs = new Object[args.length + 2]; errorArgs[0] = mapping.getTargetName(); errorArgs[1] = method.getResultType(); System.arraycopy( args, 0, errorArgs, 2, args.length ); AnnotationMirror annotationMirror = mapping.getMirror(); - if ( isReverse ) { - InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( - method.getExecutable() ); - - annotationMirror = reversePrism == null ? annotationMirror : reversePrism.mirror; - } messager.printMessage( method.getExecutable(), annotationMirror, mapping.getSourceAnnotationValue(), message, errorArgs ); @@ -402,8 +395,8 @@ private NoWriteAccessorErrorMessage(Mapping mapping, SourceMethod method, Format } @Override - public void report(boolean isReverse) { - printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE, isReverse ); + public void report() { + printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE ); } } @@ -422,22 +415,15 @@ private NoPropertyErrorMessage(Mapping mapping, SourceMethod method, FormattingM } @Override - public void report(boolean isReverse) { + public void report() { Set readAccessors = nextType.getPropertyReadAccessors().keySet(); - String mostSimilarProperty = Strings.getMostSimilarWord( - entryNames[index], - readAccessors - ); + String mostSimilarProperty = Strings.getMostSimilarWord( entryNames[index], readAccessors ); List elements = new ArrayList( Arrays.asList( entryNames ).subList( 0, index ) ); elements.add( mostSimilarProperty ); - printErrorMessage( - Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, - isReverse, - Strings.join( elements, "." ) - ); + printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); } } From 24ca295448a225132f733255e02367eb3288907a Mon Sep 17 00:00:00 2001 From: sjaakd Date: Tue, 30 Jan 2018 22:27:42 +0100 Subject: [PATCH 0176/1006] #1345 adapting fault message empty constructor to parameterless --- .../src/main/java/org/mapstruct/ap/internal/util/Message.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java | 2 +- .../java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java | 4 ++-- .../AmbiguousAnnotatedFactoryTest.java | 2 +- .../ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java | 3 ++- .../nestedsourceproperties/NestedSourcePropertiesTest.java | 2 +- .../mapstruct/ap/test/selection/generics/ConversionTest.java | 2 +- .../test/selection/resulttype/InheritanceSelectionTest.java | 4 ++-- .../mapstruct/ap/test/updatemethods/UpdateMethodsTest.java | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index ce86aa06cf..ac74b44ecb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -92,7 +92,7 @@ public enum Message { GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), - GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible empty constructor." ), + GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible parameterless constructor." ), RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 7b7cc133ab..bf548e0108 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -80,7 +80,7 @@ public void factoryMethodWithSourceParamIsChosen() { @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 33, - messageRegExp = ".*TargetB does not have an accessible empty constructor\\.") + messageRegExp = ".*TargetB does not have an accessible parameterless constructor\\.") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index b7919e1036..951976d53f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -46,7 +46,7 @@ public class Issue1283Test { @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35L, - messageRegExp = ".*\\._1283\\.Source does not have an accessible empty constructor" + messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" ) } ) @@ -61,7 +61,7 @@ public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 31L, - messageRegExp = ".*\\._1283\\.Source does not have an accessible empty constructor" + messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index cee618c0e5..24c25d8858 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -53,7 +53,7 @@ public class AmbiguousAnnotatedFactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35, - messageRegExp = ".*\\.ambiguousannotatedfactorymethod.Bar does not have an accessible empty " + + messageRegExp = ".*\\.ambiguousannotatedfactorymethod.Bar does not have an accessible parameterless " + "constructor\\.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index e141e13472..c35ed41a03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -54,7 +54,8 @@ public class FactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35, - messageRegExp = ".*\\.ambiguousfactorymethod\\.Bar does not have an accessible empty constructor\\.") + messageRegExp = ".*\\.ambiguousfactorymethod\\.Bar does not have an accessible parameterless " + + "constructor\\.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 9fd9c14305..8edf24f685 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -184,7 +184,7 @@ public void shouldUseGetAsTargetAccessor() { @Diagnostic( type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 47, - messageRegExp = "java.lang.Integer does not have an accessible empty constructor." ) + messageRegExp = "java.lang.Integer does not have an accessible parameterless constructor." ) } ) @WithClasses({ ArtistToChartEntryErroneous.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index f1a416ea5a..17ec7e7d04 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -182,7 +182,7 @@ public void shouldFailOnSuperBounds2() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, messageRegExp = ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " + - "accessible empty constructor\\.") + "accessible parameterless constructor\\.") }) public void shouldFailOnNonMatchingWildCards() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 113a5fa5b2..23a77954c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -64,7 +64,7 @@ public class InheritanceSelectionTest { @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, line = 36, - messageRegExp = ".*Fruit does not have an accessible empty constructor\\.") + messageRegExp = ".*Fruit does not have an accessible parameterless constructor\\.") } ) public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() { @@ -79,7 +79,7 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() @Diagnostic(type = ErroneousResultTypeNoEmptyConstructorMapper.class, kind = Kind.ERROR, line = 31, - messageRegExp = ".*\\.resulttype\\.Banana does not have an accessible empty constructor\\.") + messageRegExp = ".*\\.resulttype\\.Banana does not have an accessible parameterless constructor\\.") } ) public void testResultTypeHasNoSuitableEmptyConstructor() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index d8d594f09c..46df3377eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -188,7 +188,7 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 48, - messageRegExp = ".*\\.updatemethods\\.DepartmentEntity does not have an accessible empty " + + messageRegExp = ".*\\.updatemethods\\.DepartmentEntity does not have an accessible parameterless " + "constructor\\.") }) From d5bb33f51df342e830a9710106f0287529605274 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Feb 2018 12:48:40 +0100 Subject: [PATCH 0177/1006] #1375 Allow using target references when there is no intermediary read accessor --- .../model/source/TargetReference.java | 3 +- .../ap/test/bugs/_1375/Issue1375Mapper.java | 35 +++++++++++++ .../ap/test/bugs/_1375/Issue1375Test.java | 50 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1375/Source.java | 35 +++++++++++++ .../mapstruct/ap/test/bugs/_1375/Target.java | 44 ++++++++++++++++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 56d3890240..0697ba074d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -195,8 +195,7 @@ private List getTargetEntries(Type type, String[] entryNames) { boolean isLast = i == entryNames.length - 1; boolean isNotLast = i < entryNames.length - 1; if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast ) - || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, mapping, isLast ) - || ( isNotLast && targetReadAccessor == null ) ) { + || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, mapping, isLast ) ) { // there should always be a write accessor (except for the last when the mapping is ignored and // there is a read accessor) and there should be read accessor mandatory for all but the last setErrorMessage( targetWriteAccessor, targetReadAccessor, entryNames, i, nextType ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java new file mode 100644 index 0000000000..3890db403d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1375; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1375Mapper { + + Issue1375Mapper INSTANCE = Mappers.getMapper( Issue1375Mapper.class ); + + @Mapping(target = "nested.value", source = "value") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java new file mode 100644 index 0000000000..85e70dd0dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1375; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses( { + Target.class, + Source.class, + Issue1375Mapper.class +} ) +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey( "1375" ) +public class Issue1375Test { + + @Test + public void shouldGenerateCorrectMapperWhenIntermediaryReadAccessorIsMissing() { + + Target target = Issue1375Mapper.INSTANCE.map( new Source( "test value" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.nested ).isNotNull(); + assertThat( target.nested.getValue() ).isEqualTo( "test value" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java new file mode 100644 index 0000000000..4d6b7bfa07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1375; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java new file mode 100644 index 0000000000..3cb4996cdf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1375; + +/** + * @author Filip Hrisafov + */ +public class Target { + + Nested nested; + + public void setNested(Nested nested) { + this.nested = nested; + } + + public static class Nested { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} From 8f88c6baa70b33e2a2085ccfd922e15900a00425 Mon Sep 17 00:00:00 2001 From: Darren Rambaud Date: Sun, 18 Feb 2018 12:02:56 -0600 Subject: [PATCH 0178/1006] #1355: Adds Implicit Conversion Between java.util.Currency <~> String (#1381) * #1355: Setting up the test(s) for new conversion between java.util.Currency and String * #1355: Added SimpleConversion subclass to convert a Currency object to a String object and vice-versa, and registered the class to Conversions * #1355: Initial tests written, may need to re-write some test files for readability and/or add more test case(s). Basic tests are passing at this time * #1355: Added copyright statement, added documentation for new implicit conversion * #1355: Added clarity to documentation * #1355: Replaced use of one letter variables * #1355: Resolved CheckStyle errors * #1355: Fixes license header spacing so the license plugin no longer fails the build * Small cleanups --- .../mapstruct-reference-guide.asciidoc | 3 + .../ap/internal/conversion/Conversions.java | 4 + .../CurrencyToStringConversion.java | 46 ++++++++++++ .../currency/CurrencyConversionTest.java | 73 +++++++++++++++++++ .../conversion/currency/CurrencyMapper.java | 34 +++++++++ .../conversion/currency/CurrencySource.java | 47 ++++++++++++ .../conversion/currency/CurrencyTarget.java | 46 ++++++++++++ 7 files changed, 253 insertions(+) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index deaa323fe4..30e12f1434 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -817,6 +817,9 @@ public interface CarMapper { * When converting from a `String`, omitting `Mapping#dateFormat`, it leads to usage of the default pattern and date format symbols for the default locale. An exception to this rule is `XmlGregorianCalendar` which results in parsing the `String` according to http://www.w3.org/TR/xmlschema-2/#dateTime[XML Schema 1.0 Part 2, Section 3.2.7-14.1, Lexical Representation]. +* Between `java.util.Currency` and `String`. +** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown + [[mapping-object-references]] === Mapping object references diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index f60937cb14..239c060b3d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -25,6 +25,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; +import java.util.Currency; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -194,6 +195,9 @@ public Conversions(Elements elementUtils, TypeFactory typeFactory) { register( Date.class, Time.class, new DateToSqlTimeConversion() ); register( Date.class, java.sql.Date.class, new DateToSqlDateConversion() ); register( Date.class, Timestamp.class, new DateToSqlTimestampConversion() ); + + // java.util.Currency <~> String + register( Currency.class, String.class, new CurrencyToStringConversion() ); } private void registerJodaConversions() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java new file mode 100644 index 0000000000..536c684048 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.conversion; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import java.util.Currency; +import java.util.Set; + +/** + * @author Darren Rambaud + */ +public class CurrencyToStringConversion extends SimpleConversion { + @Override + protected String getToExpression(final ConversionContext conversionContext) { + return ".getCurrencyCode()"; + } + + @Override + protected String getFromExpression(final ConversionContext conversionContext) { + return "Currency.getInstance( )"; + } + + @Override + protected Set getFromConversionImportTypes(final ConversionContext conversionContext) { + return Collections.asSet( conversionContext.getTypeFactory().getType( Currency.class ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java new file mode 100644 index 0000000000..190ce76234 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java @@ -0,0 +1,73 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.currency; + +import java.util.Currency; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Darren Rambaud + */ +@WithClasses({ CurrencyMapper.class, CurrencySource.class, CurrencyTarget.class }) +@IssueKey("1355") +@RunWith(AnnotationProcessorTestRunner.class) +public class CurrencyConversionTest { + + @Test + public void shouldApplyCurrencyConversions() { + final CurrencySource source = new CurrencySource(); + source.setCurrencyA( Currency.getInstance( "USD" ) ); + Set currencies = new HashSet(); + currencies.add( Currency.getInstance( "EUR" ) ); + currencies.add( Currency.getInstance( "CHF" ) ); + source.setUniqueCurrencies( currencies ); + + CurrencyTarget target = CurrencyMapper.INSTANCE.currencySourceToCurrencyTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getCurrencyA() ).isEqualTo( "USD" ); + assertThat( target.getUniqueCurrencies() ) + .isNotEmpty() + .containsExactlyInAnyOrder( "EUR", "CHF" ); + } + + @Test + public void shouldApplyReverseConversions() { + final CurrencyTarget target = new CurrencyTarget(); + target.setCurrencyA( "USD" ); + target.setUniqueCurrencies( Collections.asSet( "JPY" ) ); + + CurrencySource source = CurrencyMapper.INSTANCE.currencyTargetToCurrencySource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getCurrencyA().getCurrencyCode() ).isEqualTo( Currency.getInstance( "USD" ) + .getCurrencyCode() ); + assertThat( source.getUniqueCurrencies() ).containsExactlyInAnyOrder( Currency.getInstance( "JPY" ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java new file mode 100644 index 0000000000..8c0b916d1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.currency; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Darren Rambaud + */ +@Mapper +public interface CurrencyMapper { + CurrencyMapper INSTANCE = Mappers.getMapper( CurrencyMapper.class ); + + CurrencyTarget currencySourceToCurrencyTarget(CurrencySource source); + + CurrencySource currencyTargetToCurrencySource(CurrencyTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java new file mode 100644 index 0000000000..b9b2b0149f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.currency; + +import java.util.Currency; +import java.util.Set; + +/** + * @author Darren Rambaud + */ +public class CurrencySource { + + private Currency currencyA; + private Set uniqueCurrencies; + + public Currency getCurrencyA() { + return this.currencyA; + } + + public void setCurrencyA(final Currency currencyA) { + this.currencyA = currencyA; + } + + public Set getUniqueCurrencies() { + return this.uniqueCurrencies; + } + + public void setUniqueCurrencies(final Set uniqueCurrencies) { + this.uniqueCurrencies = uniqueCurrencies; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java new file mode 100644 index 0000000000..dcf29ba691 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.conversion.currency; + +import java.util.Set; + +/** + * @author Darren Rambaud + */ +public class CurrencyTarget { + + private String currencyA; + private Set uniqueCurrencies; + + public String getCurrencyA() { + return this.currencyA; + } + + public void setCurrencyA(final String currencyA) { + this.currencyA = currencyA; + } + + public Set getUniqueCurrencies() { + return this.uniqueCurrencies; + } + + public void setUniqueCurrencies(final Set uniqueCurrencies) { + this.uniqueCurrencies = uniqueCurrencies; + } +} From 48b9bd72be453af0f038f508cb0933a68d9155f9 Mon Sep 17 00:00:00 2001 From: Jeff Smyth Date: Mon, 19 Feb 2018 17:01:51 -0500 Subject: [PATCH 0179/1006] #1363 Add support for using default expression --- .../src/main/java/org/mapstruct/Mapper.java | 3 +- .../src/main/java/org/mapstruct/Mapping.java | 37 ++++- core/src/main/java/org/mapstruct/Mapping.java | 37 ++++- .../mapstruct-reference-guide.asciidoc | 31 +++- .../ap/internal/model/BeanMappingMethod.java | 1 + .../ap/internal/model/PropertyMapping.java | 23 ++- .../ap/internal/model/source/Mapping.java | 47 +++++- .../mapstruct/ap/internal/util/Message.java | 6 +- ...oneousDefaultExpressionConstantMapper.java | 39 +++++ ...usDefaultExpressionDefaultValueMapper.java | 39 +++++ ...eousDefaultExpressionExpressionMapper.java | 40 +++++ .../ErroneousDefaultExpressionMapper.java | 39 +++++ .../java/JavaDefaultExpressionTest.java | 142 ++++++++++++++++++ .../defaultExpressions/java/Source.java | 50 ++++++ .../java/SourceTargetMapper.java | 41 +++++ .../defaultExpressions/java/Target.java | 46 ++++++ 16 files changed, 609 insertions(+), 12 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index bb92a58d2f..17bb1115c2 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -47,7 +47,8 @@ /** * Additional types for which an import statement is to be added to the generated mapper implementation class. - * This allows to refer to those types from within mapping expressions given via {@link Mapping#expression()} using + * This allows to refer to those types from within mapping expressions given via {@link Mapping#expression()}, + * {@link Mapping#defaultExpression()} or using * their simple name rather than their fully-qualified name. * * @return classes to add in the imports of the generated implementation. diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java index 055e02b8fb..4358729e50 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java @@ -98,7 +98,8 @@ * property is not of type {@code String}, the value will be converted by applying a matching conversion method or * built-in conversion. *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()} or {@link #expression()}. + * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, + * {@link #defaultExpression()} or {@link #expression()}. * * @return A constant {@code String} constant specifying the value for the designated target property */ @@ -123,12 +124,41 @@ * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be * imported via {@link Mapper#imports()}. *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()} or {@link #constant()}. + * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, + * {@link #defaultExpression()} or {@link #constant()}. * * @return An expression specifying the value for the designated target property */ String expression() default ""; + /** + * A defaultExpression {@link String} based on which the specified target property is to be set + * if and only if the specified source property is null. + *

      + * Currently, Java is the only supported "expression language" and expressions must be given in form of Java + * expressions using the following format: {@code java()}. For instance the mapping: + *

      
      +     * @Mapping(
      +     *     target = "someProp",
      +     *     defaultExpression = "java(new TimeAndFormat( s.getTime(), s.getFormat() ))"
      +     * )
      +     * 
      + *

      + * will cause the following target property assignment to be generated: + *

      + * {@code targetBean.setSomeProp( new TimeAndFormat( s.getTime(), s.getFormat() ) )}. + *

      + * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be + * imported via {@link Mapper#imports()}. + *

      + * This attribute can not be used together with {@link #expression()}, {@link #defaultValue()} + * or {@link #constant()}. + * + * @return An expression specifying a defaultValue for the designated target property if the designated source + * property is null + */ + String defaultExpression() default ""; + /** * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not. * This can be useful when certain attributes should not be propagated from source or target or when properties in @@ -186,7 +216,8 @@ * target property is not of type {@code String}, the value will be converted by applying a matching conversion * method or built-in conversion. *

      - * This attribute can not be used together with {@link #constant()} or {@link #expression()}. + * This attribute can not be used together with {@link #constant()}, {@link #expression()} + * or {@link #defaultExpression()}. * * @return Default value to set in case the source property is {@code null}. */ diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index d1b03f8057..ebe545de60 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -96,7 +96,8 @@ * property is not of type {@code String}, the value will be converted by applying a matching conversion method or * built-in conversion. *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()} or {@link #expression()}. + * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, + * {@link #defaultExpression()} or {@link #expression()}. * * @return A constant {@code String} constant specifying the value for the designated target property */ @@ -121,12 +122,41 @@ * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be * imported via {@link Mapper#imports()}. *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()} or {@link #constant()}. + * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, + * {@link #defaultExpression()} or {@link #constant()}. * * @return An expression specifying the value for the designated target property */ String expression() default ""; + /** + * A defaultExpression {@link String} based on which the specified target property is to be set + * if and only if the specified source property is null. + *

      + * Currently, Java is the only supported "expression language" and expressions must be given in form of Java + * expressions using the following format: {@code java()}. For instance the mapping: + *

      
      +     * @Mapping(
      +     *     target = "someProp",
      +     *     defaultExpression = "java(new TimeAndFormat( s.getTime(), s.getFormat() ))"
      +     * )
      +     * 
      + *

      + * will cause the following target property assignment to be generated: + *

      + * {@code targetBean.setSomeProp( new TimeAndFormat( s.getTime(), s.getFormat() ) )}. + *

      + * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be + * imported via {@link Mapper#imports()}. + *

      + * This attribute can not be used together with {@link #expression()}, {@link #defaultValue()} + * or {@link #constant()}. + * + * @return An expression specifying a defaultValue for the designated target property if the designated source + * property is null + */ + String defaultExpression() default ""; + /** * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not. * This can be useful when certain attributes should not be propagated from source or target or when properties in @@ -185,7 +215,8 @@ * target property is not of type {@code String}, the value will be converted by applying a matching conversion * method or built-in conversion. *

      - * This attribute can not be used together with {@link #constant()} or {@link #expression()}. + * This attribute can not be used together with {@link #constant()}, {@link #expression()} + * or {@link #defaultExpression()}. * * @return Default value to set in case the source property is {@code null}. */ diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 30e12f1434..7a2b4cde13 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1824,7 +1824,7 @@ The String `"Constant Value"` is set as is to the target property `stringConstan By means of Expressions it will be possible to include constructs from a number of languages. -Currently only Java is supported as language. This feature is e.g. useful to invoke constructors. The entire source object is available for usage in the expression. Care should be taken to insert only valid Java code: MapStruct will not validate the expression at generation-time, but errors will show up in the generated classes during compilation. +Currently only Java is supported as a language. This feature is e.g. useful to invoke constructors. The entire source object is available for usage in the expression. Care should be taken to insert only valid Java code: MapStruct will not validate the expression at generation-time, but errors will show up in the generated classes during compilation. The example below demonstrates how two source properties can be mapped to one target: @@ -1866,6 +1866,35 @@ public interface SourceTargetMapper { ---- ==== +[[default-expressions]] +=== Default Expressions + +Default expressions are a combination of default values and expressions. They will only be used when the source attribute is `null`. + +The same warnings and restrictions apply to default expressions that apply to expressions. Only Java is supported, and MapStruct will not validate the expression at generation-time. + +The example below demonstrates how two source properties can be mapped to one target: + +.Mapping method using a default expression +=== +[source, java, linenums] +[subs="verbatim,attributes"] +--- +imports java.util.UUID; + +@Mapper( imports = UUID.class ) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target="id", source="sourceId", defaultExpression = "java( UUID.randomUUID().toString() )") + Target sourceToTarget(Source s); +} +--- +=== + +The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation ((see <>). + [[determining-result-type]] === Determining the result type diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 9981deac7c..9a6d9e9b55 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -455,6 +455,7 @@ else if ( mapping.getSourceName() != null ) { .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) + .defaultJavaExpression( mapping.getDefaultJavaExpression() ) .build(); handledTargets.add( propertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index a455f6d784..aaec86f4b1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -188,6 +188,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase dependsOn ) { this.sourceName = sourceName; this.constant = constant; this.javaExpression = javaExpression; + this.defaultJavaExpression = defaultJavaExpression; this.targetName = targetName; this.defaultValue = defaultValue; this.isIgnored = isIgnored; @@ -197,6 +213,7 @@ private Mapping( Mapping mapping, TargetReference targetReference ) { this.sourceName = mapping.sourceName; this.constant = mapping.constant; this.javaExpression = mapping.javaExpression; + this.defaultJavaExpression = mapping.defaultJavaExpression; this.targetName = Strings.join( targetReference.getElementNames(), "." ); this.defaultValue = mapping.defaultValue; this.isIgnored = mapping.isIgnored; @@ -215,6 +232,7 @@ private Mapping( Mapping mapping, SourceReference sourceReference ) { this.sourceName = Strings.join( sourceReference.getElementNames(), "." ); this.constant = mapping.constant; this.javaExpression = mapping.javaExpression; + this.defaultJavaExpression = mapping.defaultJavaExpression; this.targetName = mapping.targetName; this.defaultValue = mapping.defaultValue; this.isIgnored = mapping.isIgnored; @@ -248,6 +266,25 @@ private static String getExpression(MappingPrism mappingPrism, ExecutableElement return javaExpressionMatcher.group( 1 ).trim(); } + private static String getDefaultExpression(MappingPrism mappingPrism, ExecutableElement element, + FormattingMessager messager) { + if ( mappingPrism.defaultExpression().isEmpty() ) { + return null; + } + + Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.defaultExpression() ); + + if ( !javaExpressionMatcher.matches() ) { + messager.printMessage( + element, mappingPrism.mirror, mappingPrism.values.defaultExpression(), + Message.PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION + ); + return null; + } + + return javaExpressionMatcher.group( 1 ).trim(); + } + private static boolean isEnumType(TypeMirror mirror) { return mirror.getKind() == TypeKind.DECLARED && ( (DeclaredType) mirror ).asElement().getKind() == ElementKind.ENUM; @@ -321,6 +358,10 @@ public String getJavaExpression() { return javaExpression; } + public String getDefaultJavaExpression() { + return defaultJavaExpression; + } + public String getTargetName() { return targetName; } @@ -401,6 +442,7 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac sourceName != null ? targetName : null, null, // constant null, // expression + null, // defaultExpression sourceName != null ? sourceName : targetName, null, isIgnored, @@ -440,6 +482,7 @@ public Mapping copyForInheritanceTo(SourceMethod method) { sourceName, constant, javaExpression, + defaultJavaExpression, targetName, defaultValue, isIgnored, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index ac74b44ecb..4ef42f4f0c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -54,7 +54,11 @@ public enum Message { PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED( "Expression and constant are both defined in @Mapping, either define an expression or a constant." ), PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED( "Expression and default value are both defined in @Mapping, either define a defaultValue or an expression." ), PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED( "Constant and default value are both defined in @Mapping, either define a defaultValue or a constant." ), - PROPERTYMAPPING_INVALID_EXPRESSION( "Value must be given in the form \"java()\"." ), + PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Expression and default expression are both defined in @Mapping, either define an expression or a default expression." ), + PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Constant and default expression are both defined in @Mapping, either define a constant or a default expression." ), + PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Default value and default expression are both defined in @Mapping, either define a default value or a default expression." ), + PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), + PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no parameter named \"%s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s). Did you mean \"%s\"?" ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java new file mode 100644 index 0000000000..1b64cf01cc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.util.Date; +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Jeffrey Smyth + */ +@Mapper(imports = { UUID.class, Date.class }) +public interface ErroneousDefaultExpressionConstantMapper { + + @Mappings({ + @Mapping(target = "sourceId", constant = "3", defaultExpression = "java( UUID.randomUUID().toString() )"), + @Mapping(target = "sourceDate", source = "date", defaultExpression = "java( new Date())") + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java new file mode 100644 index 0000000000..0687c99377 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.util.Date; +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Jeffrey Smyth + */ +@Mapper(imports = { UUID.class, Date.class }) +public interface ErroneousDefaultExpressionDefaultValueMapper { + + @Mappings({ + @Mapping(target = "sourceId", defaultValue = "3", defaultExpression = "java( UUID.randomUUID().toString() )"), + @Mapping(target = "sourceDate", source = "date", defaultExpression = "java( new Date())") + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java new file mode 100644 index 0000000000..211a0a0f70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.util.Date; +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * @author Jeffrey Smyth + */ +@Mapper(imports = { UUID.class, Date.class }) +public interface ErroneousDefaultExpressionExpressionMapper { + + @Mappings({ + @Mapping(target = "sourceId", expression = "java( UUID.randomUUID().toString() )", + defaultExpression = "java( UUID.randomUUID().toString() )"), + @Mapping(target = "sourceDate", source = "date", defaultExpression = "java( new Date())") + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java new file mode 100644 index 0000000000..dd896b8685 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +import java.util.Date; +import java.util.UUID; + +/** + * @author Jeffrey Smyth + */ +@Mapper(imports = { UUID.class, Date.class }) +public interface ErroneousDefaultExpressionMapper { + + @Mappings({ + @Mapping(target = "sourceId", source = "id", defaultExpression = "UUID.randomUUID().toString()"), + @Mapping(target = "sourceDate", source = "date", defaultExpression = "java( new Date())") + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java new file mode 100644 index 0000000000..149438f1ad --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -0,0 +1,142 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import java.util.Date; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Jeffrey Smyth + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class JavaDefaultExpressionTest { + + @Test + @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) + public void testJavaDefaultExpressionWithValues() { + Source source = new Source(); + source.setId( 123 ); + source.setDate( new Date( 0L ) ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getSourceId() ).isEqualTo( "123" ); + assertThat( target.getSourceDate() ).isEqualTo( source.getDate() ); + } + + @Test + @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) + public void testJavaDefaultExpressionWithNoValues() { + Source source = new Source(); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getSourceId() ).isEqualTo( "test" ); + assertThat( target.getSourceDate() ).isEqualTo( new Date( 30L ) ); + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 39, + messageRegExp = "Expression and default expression are both defined in @Mapping," + + " either define an expression or a default expression." + ), + @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 39, + messageRegExp = "Unmapped target property: \"sourceId\"" + ) + } + ) + @WithClasses({ Source.class, Target.class, ErroneousDefaultExpressionExpressionMapper.class }) + public void testJavaDefaultExpressionExpression() { + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 38, + messageRegExp = "Constant and default expression are both defined in @Mapping," + + " either define a constant or a default expression." + ), + @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 38, + messageRegExp = "Unmapped target property: \"sourceId\"" + ) + } + ) + @WithClasses({ Source.class, Target.class, ErroneousDefaultExpressionConstantMapper.class }) + public void testJavaDefaultExpressionConstant() { + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 38, + messageRegExp = "Default value and default expression are both defined in @Mapping," + + " either define a default value or a default expression." + ), + @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 38, + messageRegExp = "Unmapped target property: \"sourceId\"" + ) + } + ) + @WithClasses({ Source.class, Target.class, ErroneousDefaultExpressionDefaultValueMapper.class }) + public void testJavaDefaultExpressionDefaultValue() { + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDefaultExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 35, + messageRegExp = "Value for default expression must be given in the form \"java\\(\\)\"" + ) + } + ) + @WithClasses({ Source.class, Target.class, ErroneousDefaultExpressionMapper.class }) + public void testJavaDefaultExpressionInvalidExpression() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java new file mode 100644 index 0000000000..a186e52c28 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.util.Date; + +/** + * @author Jeffrey Smyth + */ +public class Source { + + private int id = -1; + private Date date; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public boolean hasId() { + return id != -1; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java new file mode 100644 index 0000000000..03481c84aa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +import java.util.Date; + +/** + * @author Jeffrey Smyth + */ +@Mapper(imports = { Date.class }) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mappings({ + @Mapping(target = "sourceId", source = "id", defaultExpression = "java( String.valueOf( \"test\" ) )"), + @Mapping(target = "sourceDate", source = "date", defaultExpression = "java( new Date( 30L ))") + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java new file mode 100644 index 0000000000..1679f5db1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.util.Date; + +/** + * @author Jeffrey Smyth + */ +public class Target { + + private String sourceId; + private Date sourceDate; + + public String getSourceId() { + return sourceId; + } + + public void setSourceId(String sourceId) { + this.sourceId = sourceId; + } + + public Date getSourceDate() { + return sourceDate; + } + + public void setSourceDate(Date sourceDate) { + this.sourceDate = sourceDate; + } +} From 49efb4fd6ce3bc33bc2f5b509da87a2b1c15980e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 14 Mar 2018 21:29:18 +0100 Subject: [PATCH 0180/1006] #1395 Unused mappers should not be used in constructor injection --- ...nnotationBasedComponentModelProcessor.java | 4 +- .../ap/test/bugs/_1395/Issue1395Mapper.java | 31 +++++++++++++ .../ap/test/bugs/_1395/Issue1395Test.java | 44 +++++++++++++++++++ .../ap/test/bugs/_1395/NotUsedService.java | 25 +++++++++++ .../mapstruct/ap/test/bugs/_1395/Source.java | 35 +++++++++++++++ .../mapstruct/ap/test/bugs/_1395/Target.java | 35 +++++++++++++++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 421ce0d991..40ef3c9c5d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -134,7 +134,9 @@ private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { new ArrayList( mapper.getReferencedMappers().size() ); for ( MapperReference mapperReference : mapper.getReferencedMappers() ) { - mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference ); + if ( mapperReference.isUsed() ) { + mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference ); + } } List mapperReferenceAnnotations = getMapperReferenceAnnotations(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java new file mode 100644 index 0000000000..96ba139cb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1395; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = "spring", uses = NotUsedService.class) +public interface Issue1395Mapper { + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java new file mode 100644 index 0000000000..b1333a4a09 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1395; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses( { + Issue1395Mapper.class, + NotUsedService.class, + Source.class, + Target.class +} ) +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey( "1395" ) +public class Issue1395Test { + + @Test + public void shouldGenerateValidCode() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java new file mode 100644 index 0000000000..95f39909c2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1395; + +/** + * @author Filip Hrisafov + */ +public interface NotUsedService { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java new file mode 100644 index 0000000000..f79943b2ef --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1395; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java new file mode 100644 index 0000000000..1eb6c41522 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1395; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} From 6b363f87c17bad64b6ce63fb057ca1970a5b2bf8 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 25 Feb 2018 22:00:17 +0100 Subject: [PATCH 0181/1006] #1367 aligning @Inherit(Inverse)Conf. with strategy AUTO_INHERIT_* --- .../mapstruct-reference-guide.asciidoc | 24 +++-- .../processor/MapperCreationProcessor.java | 33 +++--- .../mapstruct/ap/internal/util/Message.java | 1 - .../inheritfromconfig/multiple/BaseDto.java | 45 ++++++++ .../multiple/BaseEntity.java | 75 +++++++++++++ .../inheritfromconfig/multiple/Car2Dto.java | 47 ++++++++ .../multiple/Car2Entity.java | 47 ++++++++ .../inheritfromconfig/multiple/CarDto.java | 43 ++++++++ .../inheritfromconfig/multiple/CarEntity.java | 43 ++++++++ .../inheritfromconfig/multiple/CarMapper.java | 55 ++++++++++ .../multiple/CarMapper2.java | 52 +++++++++ .../multiple/CarMapperTest.java | 101 ++++++++++++++++++ .../multiple/EntityToDtoMappingConfig.java | 46 ++++++++ 13 files changed, 583 insertions(+), 29 deletions(-) create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 7a2b4cde13..b54db46942 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -681,7 +681,7 @@ A mapper which uses other mapper classes (see <>) will o [[injection-strategy]] === Injection strategy -When using <>, you can choose between field and constructor injection. +When using <>, you can choose between field and constructor injection. This can be done by either providing the injection strategy via `@Mapper` or `@MapperConfig` annotation. .Using constructor injection @@ -696,10 +696,10 @@ public interface CarMapper { ---- ==== -The generated mapper will inject all classes defined in the **uses** attribute. -When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. -When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. -For now, the default injection strategy is field injection. +The generated mapper will inject all classes defined in the **uses** attribute. +When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. +When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. +For now, the default injection strategy is field injection. It is recommended to use constructor injection to simplify testing. [TIP] @@ -2129,11 +2129,17 @@ Methods that are considered for inverse inheritance need to be defined in the cu If multiple methods qualify, the method from which to inherit the configuration needs to be specified using the `name` property like this: `@InheritInverseConfiguration(name = "carToDto")`. -Expressions and constants are excluded (silently ignored). Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. +`@InheritConfiguration` takes, in case of conflict precedence over `@InheritInverseConfiguration`. + +Configurations are inherited transitively. So if method `C` defines a mapping `@Mapping( target = "x", ignore = true)`, `B` defines a mapping `@Mapping( target = "y", ignore = true)`, then if `A` inherits from `B` inherits from `C`, `A` will inherit mappings for both property `x` and `y`. + +Expressions and constants are excluded (silently ignored) in `@InheritInverseConfiguration`. + +Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. [NOTE] ==== -`@InheritInverseConfiguration` cannot refer to methods in a used mapper. +`@InheritConfiguration` or `@InheritInverseConfiguration` cannot refer to methods in a used mapper. ==== [[shared-configurations]] @@ -2207,7 +2213,9 @@ public interface SourceTargetMapper { The attributes `@Mapper#mappingInheritanceStrategy()` / `@MapperConfig#mappingInheritanceStrategy()` configure when the method-level mapping configuration annotations are inherited from prototype methods in the interface to methods in the mapper: * `EXPLICIT` (default): the configuration will only be inherited, if the target mapping method is annotated with `@InheritConfiguration` and the source and target types are assignable to the corresponding types of the prototype method, all as described in <>. -* `AUTO_INHERIT_FROM_CONFIG`: the configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritConfiguration(name = ...)`. +* `AUTO_INHERIT_FROM_CONFIG`: the configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritConfiguration(name = ...)` which will cause `AUTO_INHERIT_FROM_CONFIG` to be ignored. +* `AUTO_INHERIT_REVERSE_FROM_CONFIG`: the inverse configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritInverseConfiguration(name = ...)` which will cause ``AUTO_INHERIT_REVERSE_FROM_CONFIG` to be ignored. +* `AUTO_INHERIT_ALL_FROM_CONFIG`: both the configuration and the inverse configuration will be inherited automatically. The same rules apply as for `AUTO_INHERIT_FROM_CONFIG` or `AUTO_INHERIT_REVERSE_FROM_CONFIG`. == Customizing mappings diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index fe54645964..ec56229fc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -439,24 +439,27 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp List applicablePrototypeMethods = method.getApplicablePrototypeMethods(); - MappingOptions templateMappingOptions = + MappingOptions forwardMappingOptions = getTemplateMappingOptions( join( availableMethods, applicablePrototypeMethods ), method, initializingMethods, mapperConfig ); - MappingInheritanceStrategyPrism inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy(); - - if ( templateMappingOptions != null ) { - mappingOptions.applyInheritedOptions( templateMappingOptions, false, method, messager, typeFactory ); + // apply defined (@InheritConfiguration, @InheritInverseConfiguration) mappings + if ( forwardMappingOptions != null ) { + mappingOptions.applyInheritedOptions( forwardMappingOptions, false, method, messager, typeFactory ); } - else if ( inverseMappingOptions != null ) { + if ( inverseMappingOptions != null ) { mappingOptions.applyInheritedOptions( inverseMappingOptions, true, method, messager, typeFactory ); } - else if ( inheritanceStrategy.isAutoInherit() ) { - if ( inheritanceStrategy.isApplyForward() ) { + // apply auto inherited options + MappingInheritanceStrategyPrism inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy(); + if ( inheritanceStrategy.isAutoInherit() ) { + + // but.. there should not be an @InheritedConfiguration + if ( forwardMappingOptions == null && inheritanceStrategy.isApplyForward() ) { if ( applicablePrototypeMethods.size() == 1 ) { mappingOptions.applyInheritedOptions( first( applicablePrototypeMethods ).getMappingOptions(), @@ -473,7 +476,8 @@ else if ( applicablePrototypeMethods.size() > 1 ) { } } - if ( inheritanceStrategy.isApplyReverse() ) { + // or no @InheritInverseConfiguration + if ( inverseMappingOptions == null && inheritanceStrategy.isApplyReverse() ) { if ( applicableReversePrototypeMethods.size() == 1 ) { mappingOptions.applyInheritedOptions( first( applicableReversePrototypeMethods ).getMappingOptions(), @@ -593,7 +597,6 @@ private MappingOptions getTemplateMappingOptions(List rawMethods, ); if ( forwardPrism != null ) { - reportErrorWhenInheritForwardAlsoHasInheritReverseMapping( method ); List candidates = new ArrayList(); for ( SourceMethod oneMethod : rawMethods ) { @@ -642,16 +645,6 @@ else if ( nameFilteredcandidates.size() > 1 ) { return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods ); } - private void reportErrorWhenInheritForwardAlsoHasInheritReverseMapping(SourceMethod method) { - InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( - method.getExecutable() - ); - if ( reversePrism != null ) { - messager.printMessage( method.getExecutable(), reversePrism.mirror, Message.INHERITCONFIGURATION_BOTH ); - } - - } - private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, InheritInverseConfigurationPrism reversePrism) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4ef42f4f0c..5850f43da6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -115,7 +115,6 @@ public enum Message { RETRIEVAL_WILDCARD_EXTENDS_BOUND_RESULT( "Can't generate mapping method for a wildcard extends bound result." ), RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE( "The types of @Context parameters must be unique." ), - INHERITCONFIGURATION_BOTH( "Method cannot be annotated with both a @InheritConfiguration and @InheritInverseConfiguration." ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ), INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES( "Given name \"%s\" matches several candidate methods: %s." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java new file mode 100755 index 0000000000..699ac21370 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import java.util.List; + +public class BaseDto { + + private Long dbId; + + private List links; + + public Long getDbId() { + return dbId; + } + + public void setDbId(Long dbId) { + this.dbId = dbId; + } + + public List getLinks() { + return links; + } + + public void setLinks(List links) { + this.links = links; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java new file mode 100755 index 0000000000..7a5a2cc3bf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java @@ -0,0 +1,75 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import java.util.Date; + +public abstract class BaseEntity { + + private Long id; + + protected String createdBy; + + protected Date creationDate; + + protected String lastModifiedBy; + + protected Date lastModifiedDate; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public Date getLastModifiedDate() { + return lastModifiedDate; + } + + public void setLastModifiedDate(Date lastModifiedDate) { + this.lastModifiedDate = lastModifiedDate; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java new file mode 100644 index 0000000000..c8e6f71634 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +/** + * + * @author Sjaak Derksen + */ +public class Car2Dto { + + private int seatCount; + + private String maker; + + public int getSeatCount() { + return seatCount; + } + + public void setSeatCount(int seatCount) { + this.seatCount = seatCount; + } + + public String getMaker() { + return maker; + } + + public void setMaker(String maker) { + this.maker = maker; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java new file mode 100644 index 0000000000..8a5ab0ca52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java @@ -0,0 +1,47 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +/** + * + * @author Sjaak Derksen + */ +public class Car2Entity { + + private String manufacturer; + + private int numberOfSeats; + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + public void setNumberOfSeats(int numberOfSeats) { + this.numberOfSeats = numberOfSeats; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java new file mode 100755 index 0000000000..a0eb1a8a22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +public class CarDto extends BaseDto { + + private int seatCount; + + private String maker; + + public int getSeatCount() { + return seatCount; + } + + public void setSeatCount(int seatCount) { + this.seatCount = seatCount; + } + + public String getMaker() { + return maker; + } + + public void setMaker(String maker) { + this.maker = maker; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java new file mode 100755 index 0000000000..30e1c42758 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +public class CarEntity extends BaseEntity { + + private String manufacturer; + + private int numberOfSeats; + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + public void setNumberOfSeats(int numberOfSeats) { + this.numberOfSeats = numberOfSeats; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java new file mode 100755 index 0000000000..511b3c96c2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper(config = EntityToDtoMappingConfig.class) +public abstract class CarMapper { + + public static final CarMapper MAPPER = Mappers.getMapper( CarMapper.class ); + + @Mappings({ + @Mapping(target = "maker", source = "manufacturer"), + @Mapping(target = "seatCount", source = "numberOfSeats") + }) + // additional mapping inherited from EntityToDtoMappingConfig.entityToDto method : + // @Mapping(target = "dbId", source = "id") + // @Mapping(target = "links", ignore = true) + @InheritConfiguration(name = "entityToDto") + public abstract CarDto mapTo(CarEntity car); + + @InheritInverseConfiguration(name = "mapTo") + @InheritConfiguration(name = "dtoToEntity") + // @inheritInverseConfiguration should map both maker and seatCount properties. + // additional mapping should also be inherited from EntityToDtoMappingConfig.dtoToEntity method, + // @Mapping(target = "id", source = "dbId") + // @Mapping(target = "createdBy", ignore = true) + // @Mapping(target = "creationDate", ignore = true) + // @Mapping(target = "lastModifiedBy", constant = "restApiUser") + // @Mapping(target = "lastModifiedDate", ignore = true) + public abstract CarEntity mapFrom(CarDto carDto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java new file mode 100644 index 0000000000..97b7db5b6a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class CarMapper2 { + public static final CarMapper2 MAPPER = Mappers.getMapper( CarMapper2.class ); + + @Mappings({ + @Mapping(target = "maker", source = "manufacturer"), + @Mapping(target = "seatCount", source = "numberOfSeats") + }) + public abstract Car2Dto mapToBase(Car2Entity car); + + @Mappings({ + @Mapping(target = "manufacturer", constant = "ford"), + @Mapping(target = "numberOfSeats", ignore = true) + }) + public abstract Car2Entity mapFromBase(Car2Dto carDto); + + @InheritConfiguration(name = "mapToBase") + @InheritInverseConfiguration(name = "mapFromBase") + public abstract Car2Dto mapTo(Car2Entity car); + + @InheritConfiguration(name = "mapFromBase") + @InheritInverseConfiguration(name = "mapToBase") + public abstract Car2Entity mapFrom(Car2Dto carDto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java new file mode 100755 index 0000000000..3aded6b9ec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java @@ -0,0 +1,101 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Date; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + BaseDto.class, + BaseEntity.class, + CarDto.class, + CarEntity.class, + CarMapper.class, + EntityToDtoMappingConfig.class, + Car2Dto.class, + Car2Entity.class, + CarMapper2.class +}) +@IssueKey("1367") +public class CarMapperTest { + + @Test + public void testMapEntityToDto() { + CarDto dto = CarMapper.MAPPER.mapTo( newCar() ); + assertThat( dto.getDbId() ).isEqualTo( 9L ); + assertThat( dto.getMaker() ).isEqualTo( "Nissan" ); + assertThat( dto.getSeatCount() ).isEqualTo( 5 ); + } + + @Test + public void testMapDtoToEntity() { + CarEntity car = CarMapper.MAPPER.mapFrom( newCarDto() ); + assertThat( car.getId() ).isEqualTo( 9L ); + assertThat( car.getManufacturer() ).isEqualTo( "Nissan" ); + assertThat( car.getNumberOfSeats() ).isEqualTo( 5 ); + assertThat( car.getLastModifiedBy() ).isEqualTo( "restApiUser" ); + assertThat( car.getCreationDate() ).isNull(); + } + + @Test + public void testForwardMappingShouldTakePrecedence() { + Car2Dto dto = new Car2Dto(); + dto.setMaker( "mazda" ); + dto.setSeatCount( 5 ); + + Car2Entity entity = CarMapper2.MAPPER.mapFrom( dto ); + assertThat( entity.getManufacturer() ).isEqualTo( "ford" ); + assertThat( entity.getNumberOfSeats( ) ).isEqualTo( 0 ); + + Car2Entity entity2 = new Car2Entity(); + entity2.setManufacturer( "mazda" ); + entity2.setNumberOfSeats( 5 ); + + Car2Dto dto2 = CarMapper2.MAPPER.mapTo( entity2 ); + assertThat( dto2.getMaker() ).isEqualTo( "mazda" ); + assertThat( dto2.getSeatCount() ).isEqualTo( 5 ); + } + + private CarEntity newCar() { + CarEntity car = new CarEntity(); + car.setId( 9L ); + car.setCreatedBy( "admin" ); + car.setCreationDate( new Date() ); + car.setManufacturer( "Nissan" ); + car.setNumberOfSeats( 5 ); + return car; + } + + private CarDto newCarDto() { + CarDto carDto = new CarDto(); + carDto.setDbId( 9L ); + carDto.setMaker( "Nissan" ); + carDto.setSeatCount( 5 ); + return carDto; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java new file mode 100755 index 0000000000..e764396f4a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.inheritfromconfig.multiple; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * Shared configuration from Entities to Dto instances + */ +@MapperConfig +public interface EntityToDtoMappingConfig { + + @Mappings({ + @Mapping(target = "dbId", source = "id"), + @Mapping(target = "links", ignore = true) + }) + BaseDto entityToDto(BaseEntity entity); + + @Mappings({ + @Mapping(target = "id", source = "dbId"), + @Mapping(target = "createdBy", ignore = true), + @Mapping(target = "creationDate", ignore = true), + @Mapping(target = "lastModifiedBy", constant = "restApiUser"), // force modifiedBy with restApiUser constant + @Mapping(target = "lastModifiedDate", ignore = true) + }) + BaseEntity dtoToEntity(BaseDto dto); + +} From f2ef33030425f4766bbdcba1bed80186a7251284 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Mar 2018 11:18:55 +0100 Subject: [PATCH 0182/1006] Use correct link for the JAXBBasedMapperTest --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index b54db46942..d5e0f84d9c 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1041,7 +1041,7 @@ The algorithm for finding a mapping or factory method resembles Java's method re [TIP] ==== -When working with JAXB, e.g. when converting a `String` to a corresponding `JAXBElement`, MapStruct will take the `scope` and `name` attributes of `@XmlElementDecl` annotations into account when looking for a mapping method. This makes sure that the created `JAXBElement` instances will have the right QNAME value. You can find a test which maps JAXB objects https://github.com/mapstruct/mapstruct/blob/{mapstructVersion}/integrationtest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java[here]. +When working with JAXB, e.g. when converting a `String` to a corresponding `JAXBElement`, MapStruct will take the `scope` and `name` attributes of `@XmlElementDecl` annotations into account when looking for a mapping method. This makes sure that the created `JAXBElement` instances will have the right QNAME value. You can find a test which maps JAXB objects https://github.com/mapstruct/mapstruct/blob/{mapstructVersion}/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java[here]. ==== [[selection-based-on-qualifiers]] From 2ead42da25806f65b55985f5cc21a45f1bdf49a9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Mar 2018 20:36:00 +0100 Subject: [PATCH 0183/1006] #1378 Use Types instead of searching for type elements --- .../ap/internal/model/source/selector/MethodSelectors.java | 2 +- .../model/source/selector/XmlElementDeclSelector.java | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index e651082f1e..1495b3e6e0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -44,7 +44,7 @@ public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeF new TypeSelector( typeFactory ), new QualifierSelector( typeUtils, elementUtils ), new TargetTypeSelector( typeUtils, elementUtils ), - new XmlElementDeclSelector( typeUtils, elementUtils ), + new XmlElementDeclSelector( typeUtils ), new InheritanceSelector(), new CreateOrUpdateSelector(), new FactoryParameterSelector() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 6051ad11e3..ad35d691b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -25,7 +25,6 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Type; @@ -53,11 +52,9 @@ public class XmlElementDeclSelector implements MethodSelector { private final Types typeUtils; - private final Elements elementUtils; - public XmlElementDeclSelector( Types typeUtils, Elements elementUtils) { + public XmlElementDeclSelector(Types typeUtils) { this.typeUtils = typeUtils; - this.elementUtils = elementUtils; } @Override @@ -163,7 +160,7 @@ private XmlElementRefInfo findXmlElementRef(Type resultType, String targetProper } } currentMirror = currentElement.getSuperclass(); - currentElement = elementUtils.getTypeElement( currentMirror.toString() ); + currentElement = (TypeElement) typeUtils.asElement( currentMirror ); } return defaultInfo; } From 4693a2581ce4956886f57db7005c088826d3f201 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 4 Feb 2018 11:47:32 +0100 Subject: [PATCH 0184/1006] MethodReference should not extend MappingMethod --- .../ap/internal/model/MethodReference.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 17c8629629..2eca505935 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -26,6 +26,7 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; @@ -38,7 +39,10 @@ * * @author Gunnar Morling */ -public class MethodReference extends MappingMethod implements Assignment { +public class MethodReference extends ModelElement implements Assignment { + private final String name; + private final List sourceParameters; + private final Type returnType; private final MapperReference declaringMapper; private final Set importTypes; private final List thrownTypes; @@ -62,6 +66,7 @@ public class MethodReference extends MappingMethod implements Assignment { private final Type definingType; private final List parameterBindings; private final Parameter providingParameter; + private final boolean isStatic; /** * Creates a new reference to the given method. @@ -74,8 +79,9 @@ public class MethodReference extends MappingMethod implements Assignment { */ protected MethodReference(Method method, MapperReference declaringMapper, Parameter providingParameter, List parameterBindings) { - super( method ); this.declaringMapper = declaringMapper; + this.sourceParameters = Parameter.getSourceParameters( method.getParameters() ); + this.returnType = method.getReturnType(); this.providingParameter = providingParameter; this.parameterBindings = parameterBindings; this.contextParam = null; @@ -93,10 +99,13 @@ protected MethodReference(Method method, MapperReference declaringMapper, Parame this.thrownTypes = method.getThrownTypes(); this.isUpdateMethod = method.getMappingTargetParameter() != null; this.definingType = method.getDefiningType(); + this.isStatic = method.isStatic(); + this.name = method.getName(); } private MethodReference(BuiltInMethod method, ConversionContext contextParam) { - super( method ); + this.sourceParameters = Parameter.getSourceParameters( method.getParameters() ); + this.returnType = method.getReturnType(); this.declaringMapper = null; this.providingParameter = null; this.contextParam = method.getContextParameter( contextParam ); @@ -105,6 +114,8 @@ private MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.definingType = null; this.isUpdateMethod = method.getMappingTargetParameter() != null; this.parameterBindings = ParameterBinding.fromParameters( method.getParameters() ); + this.isStatic = method.isStatic(); + this.name = method.getName(); } public MapperReference getDeclaringMapper() { @@ -127,6 +138,14 @@ public Assignment getAssignment() { return assignment; } + public String getName() { + return name; + } + + public List getSourceParameters() { + return sourceParameters; + } + @Override public void setAssignment( Assignment assignment ) { this.assignment = assignment; @@ -225,11 +244,20 @@ public AssignmentType getType() { } } + @Override + public Type getReturnType() { + return returnType; + } + @Override public boolean isCallingUpdateMethod() { return isUpdateMethod; } + public boolean isStatic() { + return isStatic; + } + public List getParameterBindings() { return parameterBindings; } From 3d45d072e77e6f047b31b8eab5b5dc2a72cd54c1 Mon Sep 17 00:00:00 2001 From: Eric Martineau Date: Mon, 4 Dec 2017 15:10:39 -0800 Subject: [PATCH 0185/1006] #782 Add tests for builders --- .../itest/tests/LombokBuilderTest.java | 31 ++++++++ .../test/resources/lombokBuilderTest/pom.xml | 42 ++++++++++ .../org/mapstruct/itest/lombok/Address.java | 28 +++++++ .../mapstruct/itest/lombok/AddressDto.java | 31 ++++++++ .../org/mapstruct/itest/lombok/Person.java | 32 ++++++++ .../org/mapstruct/itest/lombok/PersonDto.java | 32 ++++++++ .../mapstruct/itest/lombok/PersonMapper.java | 32 ++++++++ .../itest/lombok/LombokMapperTest.java | 56 ++++++++++++++ parent/pom.xml | 6 ++ .../abstractBuilder/AbstractBuilderTest.java | 70 +++++++++++++++++ .../AbstractImmutableTarget.java | 35 +++++++++ .../AbstractTargetBuilder.java | 31 ++++++++ .../abstractBuilder/ImmutableTarget.java | 52 +++++++++++++ .../ImmutableTargetMapper.java | 32 ++++++++ .../test/builder/abstractBuilder/Source.java | 48 ++++++++++++ .../test/builder/abstractBuilder/Target.java | 25 ++++++ .../AbstractChildTarget.java | 23 ++++++ .../AbstractParentTarget.java | 27 +++++++ .../AbstractTargetBuilderTest.java | 61 +++++++++++++++ .../AbstractTargetMapper.java | 39 ++++++++++ .../abstractGenericTarget/ChildSource.java | 38 ++++++++++ .../ImmutableChildTargetImpl.java | 48 ++++++++++++ .../ImmutableParentTargetImpl.java | 76 +++++++++++++++++++ .../MutableChildTargetImpl.java | 32 ++++++++ .../MutableParentTargetImpl.java | 52 +++++++++++++ .../abstractGenericTarget/ParentSource.java | 49 ++++++++++++ .../simple/BuilderInfoTargetTest.java | 53 +++++++++++++ .../simple/InvalidSimpleBuilderMapper.java | 26 +++++++ .../simple/SimpleBuilderMapper.java | 39 ++++++++++ .../simple/SimpleImmutableTarget.java | 60 +++++++++++++++ .../simple/SimpleMutableSource.java | 40 ++++++++++ .../nestedprop/BuilderNestedPropertyTest.java | 49 ++++++++++++ .../builder/nestedprop/ExpandedTarget.java | 72 ++++++++++++++++++ .../builder/nestedprop/FlattenedMapper.java | 36 +++++++++ .../builder/nestedprop/FlattenedSource.java | 60 +++++++++++++++ .../nestedprop/ImmutableTargetContainer.java | 48 ++++++++++++ .../builder/parentchild/ImmutableChild.java | 49 ++++++++++++ .../builder/parentchild/ImmutableParent.java | 62 +++++++++++++++ .../builder/parentchild/MutableChild.java | 38 ++++++++++ .../builder/parentchild/MutableParent.java | 42 ++++++++++ .../parentchild/ParentChildBuilderTest.java | 68 +++++++++++++++++ .../parentchild/ParentChildMapper.java | 34 +++++++++ .../simple/ErroneousSimpleBuilderMapper.java | 28 +++++++ .../builder/simple/SimpleBuilderMapper.java | 29 +++++++ .../simple/SimpleImmutableBuilderTest.java | 68 +++++++++++++++++ .../builder/simple/SimpleImmutableTarget.java | 60 +++++++++++++++ .../builder/simple/SimpleMutableSource.java | 40 ++++++++++ 47 files changed, 2029 insertions(+) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/pom.xml create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java create mode 100644 integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java new file mode 100644 index 0000000000..756f2ed9b9 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * @author Eric Martineau + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite( baseDir = "lombokBuilderTest" ) +public class LombokBuilderTest { +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml new file mode 100644 index 0000000000..e96551d6da --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + lombokIntegrationTest + jar + + + + org.projectlombok + lombok + compile + + + diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java new file mode 100644 index 0000000000..e367a8e086 --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class Address { + private final String addressLine; +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java new file mode 100644 index 0000000000..871fd58237 --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AddressDto { + + private String addressLine; +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java new file mode 100644 index 0000000000..92a97ec686 --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import lombok.Builder; +import lombok.Getter; + +//TODO make MapStruct DefaultBuilderProvider work with custom builder name +//@Builder(builderMethodName = "foo", buildMethodName = "create", builderClassName = "Builder") +@Builder(builderClassName = "Builder") +@Getter +public class Person { + private final String name; + private final int age; + private final Address address; +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java new file mode 100644 index 0000000000..90443f548d --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class PersonDto { + private String name; + private int age; + private AddressDto address; +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java new file mode 100644 index 0000000000..d2b766fb99 --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person fromDto(PersonDto personDto); + PersonDto toDto(Person personDto); +} diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java new file mode 100644 index 0000000000..36188efc42 --- /dev/null +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.lombok; + +import org.junit.Test; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Lombok Builder Mapper implementations + * + * @author Eric Martineau + */ +public class LombokMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.builder() + .age( 33 ) + .name( "Bob" ) + .address( Address.builder() + .addressLine( "Wild Drive" ) + .build() ) + .build() ); + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 5978ff7d1f..e87a80569c 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -194,6 +194,12 @@ 1.1.3 + + org.projectlombok + lombok + 1.16.18 + + joda-time diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java new file mode 100644 index 0000000000..cba7830a83 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java @@ -0,0 +1,70 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * This test is for abstract builders, where some of the target properties are written by the abstract + * builder class, and some of the properties are written by the concrete builder implementation. + */ +@WithClasses({ + Target.class, + AbstractTargetBuilder.class, + AbstractImmutableTarget.class, + ImmutableTarget.class, + Source.class, + ImmutableTargetMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class AbstractBuilderTest { + + /** + * This test verifies that: + * WHEN - a mapping method's return type is an immutable/built target, AND + * - the mapped properties are split between the abstract and concrete builder, AND + * THEN + * - the builder is "discovered" + * - all values are mapped + * - all values are set properly + */ + @Test + public void testThatAbstractBuilderMapsAllProperties() { + ImmutableTarget sourceOne = ImmutableTargetMapper.INSTANCE.fromMutable( new Source( "foo", 31 ) ); + + assertThat( sourceOne.getBar() ).isEqualTo( 31 ); + assertThat( sourceOne.getFoo() ).isEqualTo( "foo" ); + } + + @Test + public void testThatAbstractBuilderReverseMapsAllProperties() { + Source sourceOne = ImmutableTargetMapper.INSTANCE.fromImmutable( ImmutableTarget.builder() + .bar( 31 ) + .foo( "foo" ) + .build() ); + + assertThat( sourceOne.getBar() ).isEqualTo( 31 ); + assertThat( sourceOne.getFoo() ).isEqualTo( "foo" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java new file mode 100644 index 0000000000..6c59b4b5a8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +/** + * @author Filip Hrisafov + */ +public abstract class AbstractImmutableTarget implements Target { + + private final String foo; + + public AbstractImmutableTarget(AbstractTargetBuilder builder) { + this.foo = builder.foo; + } + + public String getFoo() { + return foo; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java new file mode 100644 index 0000000000..4869dbe36f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +public abstract class AbstractTargetBuilder { + + protected String foo; + + public AbstractTargetBuilder foo(String foo) { + this.foo = foo; + return this; + } + + abstract T build(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java new file mode 100644 index 0000000000..a09cfedf5f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +public class ImmutableTarget extends AbstractImmutableTarget { + + private final Integer bar; + + public ImmutableTarget(ImmutableTargetBuilder builder) { + super( builder ); + this.bar = builder.bar; + } + + public static ImmutableTargetBuilder builder() { + return new ImmutableTargetBuilder(); + } + + @Override + public Integer getBar() { + return bar; + } + + public static class ImmutableTargetBuilder extends AbstractTargetBuilder { + private Integer bar; + + public ImmutableTargetBuilder bar(Integer bar) { + this.bar = bar; + return this; + } + + @Override + public ImmutableTarget build() { + return new ImmutableTarget( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java new file mode 100644 index 0000000000..f41bfe3c71 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ImmutableTargetMapper { + + ImmutableTargetMapper INSTANCE = Mappers.getMapper( ImmutableTargetMapper.class ); + + ImmutableTarget fromMutable(Source source); + + Source fromImmutable(ImmutableTarget source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java new file mode 100644 index 0000000000..b7e57cec64 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +public class Source { + private String foo; + private Integer bar; + + public Source() { + } + + public Source(String foo, Integer bar) { + this.foo = foo; + this.bar = bar; + } + + public String getFoo() { + return foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } + + public Integer getBar() { + return bar; + } + + public void setBar(Integer bar) { + this.bar = bar; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java new file mode 100644 index 0000000000..855cf5b1fd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java @@ -0,0 +1,25 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractBuilder; + +public interface Target { + String getFoo(); + + Integer getBar(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java new file mode 100644 index 0000000000..0d8e5c2905 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java @@ -0,0 +1,23 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public interface AbstractChildTarget { + String getBar(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java new file mode 100644 index 0000000000..5fa08e4cb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java @@ -0,0 +1,27 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public interface AbstractParentTarget { + int getCount(); + + T getNested(); + + AbstractChildTarget getNonGenericizedNested(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java new file mode 100644 index 0000000000..02e751078f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java @@ -0,0 +1,61 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Verifies that abstract builders work when mapping to an abstract property type. + */ +@WithClasses({ + AbstractChildTarget.class, + AbstractParentTarget.class, + ChildSource.class, + ImmutableChildTargetImpl.class, + ImmutableParentTargetImpl.class, + MutableChildTargetImpl.class, + MutableParentTargetImpl.class, + ParentSource.class, + AbstractTargetMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class AbstractTargetBuilderTest { + + @Test + public void testAbstractTargetMapper() { + ParentSource parent = new ParentSource(); + parent.setCount( 4 ); + parent.setNested( new ChildSource( "Phineas" ) ); + + // transform + AbstractParentTarget immutableTarget = AbstractTargetMapper.INSTANCE.toImmutable( parent ); + AbstractParentTarget mutableTarget = AbstractTargetMapper.INSTANCE.toMutable( parent ); + + assertThat( mutableTarget.getCount() ).isEqualTo( 4 ); + assertThat( mutableTarget.getNested().getBar() ).isEqualTo( "Phineas" ); + + assertThat( immutableTarget.getCount() ).isEqualTo( 4 ); + assertThat( immutableTarget.getNested().getBar() ).isEqualTo( "Phineas" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java new file mode 100644 index 0000000000..a1e5217aec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface AbstractTargetMapper { + + AbstractTargetMapper INSTANCE = Mappers.getMapper( AbstractTargetMapper.class ); + + ImmutableParentTargetImpl toImmutable(ParentSource parentSource); + + MutableParentTargetImpl toMutable(ParentSource parentSource); + + /** + * This method allows mapstruct to successfully write to {@link ImmutableParentTargetImpl#nonGenericizedNested} + * by providing a concrete class to convert to. + */ + ImmutableChildTargetImpl toChild(ChildSource child); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java new file mode 100644 index 0000000000..704c809d07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class ChildSource { + private String bar; + + public ChildSource() { + } + + public ChildSource(String bar) { + this.bar = bar; + } + + public String getBar() { + return bar; + } + + public void setBar(String bar) { + this.bar = bar; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java new file mode 100644 index 0000000000..67bb62546c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class ImmutableChildTargetImpl implements AbstractChildTarget { + private final String bar; + + private ImmutableChildTargetImpl(ImmutableChildTargetImpl.Builder builder) { + this.bar = builder.bar; + } + + public static ImmutableChildTargetImpl.Builder builder() { + return new ImmutableChildTargetImpl.Builder(); + } + + public String getBar() { + return bar; + } + + public static class Builder { + private String bar; + + public ImmutableChildTargetImpl.Builder bar(String bar) { + this.bar = bar; + return this; + } + + public ImmutableChildTargetImpl build() { + return new ImmutableChildTargetImpl( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java new file mode 100644 index 0000000000..6973943cca --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java @@ -0,0 +1,76 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class ImmutableParentTargetImpl implements AbstractParentTarget { + private final int count; + private final ImmutableChildTargetImpl nested; + private final AbstractChildTarget nonGenericizedNested; + + public ImmutableParentTargetImpl(Builder builder) { + this.count = builder.count; + this.nested = builder.nested; + this.nonGenericizedNested = builder.nonGenericizedNested; + } + + public static Builder builder() { + return new Builder(); + } + + @Override + public AbstractChildTarget getNonGenericizedNested() { + return nonGenericizedNested; + } + + @Override + public int getCount() { + return count; + } + + @Override + public ImmutableChildTargetImpl getNested() { + return nested; + } + + public static class Builder { + private int count; + private ImmutableChildTargetImpl nested; + private AbstractChildTarget nonGenericizedNested; + + public Builder count(int count) { + this.count = count; + return this; + } + + public Builder nonGenericizedNested(AbstractChildTarget nonGenericizedNested) { + this.nonGenericizedNested = nonGenericizedNested; + return this; + } + + public Builder nested(ImmutableChildTargetImpl nested) { + this.nested = nested; + return this; + } + + public ImmutableParentTargetImpl build() { + return new ImmutableParentTargetImpl( this ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java new file mode 100644 index 0000000000..136958f044 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class MutableChildTargetImpl implements AbstractChildTarget { + private String bar; + + @Override + public String getBar() { + return null; + } + + public void setBar(String bar) { + this.bar = bar; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java new file mode 100644 index 0000000000..7ddead8550 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class MutableParentTargetImpl implements AbstractParentTarget { + private int count; + private ImmutableChildTargetImpl nested; + private AbstractChildTarget nonGenericizedNested; + + @Override + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + @Override + public ImmutableChildTargetImpl getNested() { + return nested; + } + + public void setNested(ImmutableChildTargetImpl nested) { + this.nested = nested; + } + + @Override + public AbstractChildTarget getNonGenericizedNested() { + return nonGenericizedNested; + } + + public void setNonGenericizedNested(AbstractChildTarget nonGenericizedNested) { + this.nonGenericizedNested = nonGenericizedNested; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java new file mode 100644 index 0000000000..4470547c0c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.abstractGenericTarget; + +public class ParentSource { + private int count; + private ChildSource nested; + private ChildSource nonGenericizedNested; + + public ChildSource getNonGenericizedNested() { + return nonGenericizedNested; + } + + public void setNonGenericizedNested(ChildSource nonGenericizedNested) { + this.nonGenericizedNested = nonGenericizedNested; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public ChildSource getNested() { + return nested; + } + + public void setNested(ChildSource nested) { + this.nested = nested; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java new file mode 100644 index 0000000000..83976f1a42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + SimpleMutableSource.class, + SimpleImmutableTarget.class, + SimpleBuilderMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class BuilderInfoTargetTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + public void testSimpleImmutableBuilderHappyPath() { + SimpleMutableSource source = new SimpleMutableSource(); + source.setAge( 3 ); + source.setFullName( "Bob" ); + SimpleImmutableTarget targetObject = SimpleBuilderMapper.INSTANCE.toImmutable( + source, + SimpleImmutableTarget.builder() + ); + assertThat( targetObject.getAge() ).isEqualTo( 3 ); + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java new file mode 100644 index 0000000000..519fb64de3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java @@ -0,0 +1,26 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +import org.mapstruct.Mapper; + +@Mapper +public interface InvalidSimpleBuilderMapper { + SimpleImmutableTarget toImmutable(SimpleMutableSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java new file mode 100644 index 0000000000..0c98c29305 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SimpleBuilderMapper { + + SimpleBuilderMapper INSTANCE = Mappers.getMapper( SimpleBuilderMapper.class ); + + @Mapping(target = "builder.name", source = "source.fullName") + SimpleImmutableTarget toImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget.Builder builder); + + @Mapping(target = "builder.name", source = "source.fullName") + void updateImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget.Builder builder); + + @Mapping(target = "name", source = "fullName") + SimpleImmutableTarget toImmutable(SimpleMutableSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java new file mode 100644 index 0000000000..50b62be8f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java @@ -0,0 +1,60 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +public class SimpleImmutableTarget { + private final String name; + private final int age; + + SimpleImmutableTarget(Builder builder) { + this.name = builder.name; + this.age = builder.age; + } + + public static Builder builder() { + return new Builder(); + } + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + + public static class Builder { + private String name; + private int age; + + public Builder age(int age) { + this.age = age; + return this; + } + + public SimpleImmutableTarget build() { + return new SimpleImmutableTarget( this ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java new file mode 100644 index 0000000000..4b23a79938 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +public class SimpleMutableSource { + private String fullName; + private int age; + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java new file mode 100644 index 0000000000..3eca56c8fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Verifies that nested property mapping works with an immutable intermediate type. + */ +@WithClasses({ + FlattenedSource.class, + ExpandedTarget.class, + ImmutableTargetContainer.class, + FlattenedMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class BuilderNestedPropertyTest { + + @Test + public void testNestedImmutablePropertyMapper() { + ExpandedTarget expandedTarget = FlattenedMapper.INSTANCE.writeToNestedProperty( new FlattenedSource( + "Foo", + "Bar", + 33 + ) ); + assertThat( expandedTarget ).isNotNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java new file mode 100644 index 0000000000..32be350071 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java @@ -0,0 +1,72 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop; + +public class ExpandedTarget { + private final int count; + private final ImmutableTargetContainer first; + private final ImmutableTargetContainer second; + + ExpandedTarget(Builder builder) { + this.count = builder.count; + this.first = builder.first; + this.second = builder.second; + } + + public static Builder builder() { + return new Builder(); + } + + public int getCount() { + return count; + } + + public ImmutableTargetContainer getFirst() { + return first; + } + + public ImmutableTargetContainer getSecond() { + return second; + } + + public static class Builder { + private int count; + private ImmutableTargetContainer first; + private ImmutableTargetContainer second; + + public Builder count(int age) { + this.count = count; + return this; + } + + public Builder first(ImmutableTargetContainer first) { + this.first = first; + return this; + } + + public Builder second(ImmutableTargetContainer second) { + this.second = second; + return this; + } + + public ExpandedTarget build() { + return new ExpandedTarget( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java new file mode 100644 index 0000000000..e74251e8f1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface FlattenedMapper { + + FlattenedMapper INSTANCE = Mappers.getMapper( FlattenedMapper.class ); + + @Mappings({ + @Mapping(target = "first.foo", source = "count"), + @Mapping(target = "second", ignore = true) + }) + ExpandedTarget writeToNestedProperty(FlattenedSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java new file mode 100644 index 0000000000..8bd210b02f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java @@ -0,0 +1,60 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class FlattenedSource { + private String foo; + private String bar; + private int count; + + public FlattenedSource() { + } + + public FlattenedSource(String foo, String bar, int count) { + this.foo = checkNotNull( foo ); + this.bar = checkNotNull( bar ); + this.count = count; + } + + public String getFoo() { + return foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getBar() { + return bar; + } + + public void setBar(String bar) { + this.bar = bar; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java new file mode 100644 index 0000000000..07eb0468c6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop; + +public class ImmutableTargetContainer { + private final String foo; + + ImmutableTargetContainer(ImmutableTargetContainer.Builder builder) { + this.foo = builder.foo; + } + + public static ImmutableTargetContainer.Builder builder() { + return new ImmutableTargetContainer.Builder(); + } + + public String getFoo() { + return foo; + } + + public static class Builder { + private String foo; + + public ImmutableTargetContainer build() { + return new ImmutableTargetContainer( this ); + } + + public ImmutableTargetContainer.Builder foo(String foo) { + this.foo = foo; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java new file mode 100644 index 0000000000..8c7e45a82c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +public class ImmutableChild { + + private final String bar; + + private ImmutableChild(Builder builder) { + this.bar = builder.bar; + } + + public static Builder builder() { + return new Builder(); + } + + public String getBar() { + return bar; + } + + public static class Builder { + private String bar; + + public ImmutableChild.Builder bar(String bar) { + this.bar = bar; + return this; + } + + public ImmutableChild build() { + return new ImmutableChild( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java new file mode 100644 index 0000000000..88d9967c02 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java @@ -0,0 +1,62 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +import java.util.List; + +public class ImmutableParent { + private final int count; + private final List children; + + ImmutableParent(Builder builder) { + this.count = builder.count; + this.children = builder.children; + } + + public static Builder builder() { + return new Builder(); + } + + public int getCount() { + return count; + } + + public List getChildren() { + return children; + } + + public static class Builder { + private List children; + private int count; + + public Builder children(List children) { + this.children = children; + return this; + } + + public ImmutableParent build() { + return new ImmutableParent( this ); + } + + public Builder count(int count) { + this.count = count; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java new file mode 100644 index 0000000000..692a6414d6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +public class MutableChild { + public MutableChild() { + } + + public MutableChild(String foo) { + this.foo = foo; + } + + private String foo; + + public String getFoo() { + return foo; + } + + public void setFoo(String foo) { + this.foo = foo; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java new file mode 100644 index 0000000000..b0b975b35a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +import java.util.List; + +public class MutableParent { + private int count; + private List children; + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java new file mode 100644 index 0000000000..4d7d9b2cc1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +import java.util.ArrayList; + +import org.assertj.core.api.Condition; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + MutableParent.class, + MutableChild.class, + ImmutableChild.class, + ImmutableParent.class, + ParentChildMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ParentChildBuilderTest { + + @Test + public void testParentChildBuilderMapper() { + final MutableParent parent = new MutableParent(); + parent.setCount( 4 ); + parent.setChildren( new ArrayList() ); + parent.getChildren().add( new MutableChild( "Phineas" ) ); + parent.getChildren().add( new MutableChild( "Ferb" ) ); + + // transform + ImmutableParent immutableParent = ParentChildMapper.INSTANCE.toParent( parent ); + + assertThat( immutableParent.getCount() ).isEqualTo( 4 ); + assertThat( immutableParent.getChildren() ).hasSize( 2 ); + assertThat( immutableParent.getChildren() ) + .hasSize( 2 ) + .areExactly( 1, hasMatchingName( "Phineas" ) ) + .areExactly( 1, hasMatchingName( "Ferb" ) ); + } + + private Condition hasMatchingName(final String name) { + return new Condition( "Matching name" ) { + @Override + public boolean matches(ImmutableChild value) { + return name.equals( value.getBar() ); + } + }; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java new file mode 100644 index 0000000000..2a66469a6c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.parentchild; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ParentChildMapper { + + ParentChildMapper INSTANCE = Mappers.getMapper( ParentChildMapper.class ); + + ImmutableParent toParent(MutableParent source); + + @Mapping(target = "bar", source = "foo") + ImmutableChild toChild(MutableChild source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java new file mode 100644 index 0000000000..076a754d9e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.simple; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface ErroneousSimpleBuilderMapper { + + SimpleImmutableTarget toImmutable(SimpleMutableSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java new file mode 100644 index 0000000000..aece401112 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.simple; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface SimpleBuilderMapper { + + @Mapping(target = "name", source = "fullName") + SimpleImmutableTarget toImmutable(SimpleMutableSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java new file mode 100644 index 0000000000..197f8a4f44 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.simple; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + SimpleMutableSource.class, + SimpleImmutableTarget.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class SimpleImmutableBuilderTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ SimpleBuilderMapper.class }) + public void testSimpleImmutableBuilderHappyPath() { + SimpleBuilderMapper mapper = Mappers.getMapper( SimpleBuilderMapper.class ); + SimpleMutableSource source = new SimpleMutableSource(); + source.setAge( 3 ); + source.setFullName( "Bob" ); + + SimpleImmutableTarget targetObject = mapper.toImmutable( source ); + + assertThat( targetObject.getAge() ).isEqualTo( 3 ); + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + } + + @Test + @WithClasses({ ErroneousSimpleBuilderMapper.class }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSimpleBuilderMapper.class, + line = 27, + messageRegExp = "Unmapped target property: \"name\"\\.")) + public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java new file mode 100644 index 0000000000..8e6365a34f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java @@ -0,0 +1,60 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.simple; + +public class SimpleImmutableTarget { + private final String name; + private final int age; + + SimpleImmutableTarget(Builder builder) { + this.name = builder.name; + this.age = builder.age; + } + + public static Builder builder() { + return new Builder(); + } + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + + public static class Builder { + private String name; + private int age; + + public Builder age(int age) { + this.age = age; + return this; + } + + public SimpleImmutableTarget build() { + return new SimpleImmutableTarget( this ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java new file mode 100644 index 0000000000..2548ab7781 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.simple; + +public class SimpleMutableSource { + private String fullName; + private int age; + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } +} From bf8f037a19d2e9d2ab72a50eb7dc879e8ec6ffb5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 16 Dec 2017 17:14:38 +0100 Subject: [PATCH 0186/1006] #782 Add integration tests for builders with immutables --- .../itest/tests/ImmutablesBuilderTest.java | 31 ++++++++++ .../resources/immutablesBuilderTest/pom.xml | 42 ++++++++++++++ .../mapstruct/itest/immutables/Address.java | 26 +++++++++ .../itest/immutables/AddressDto.java | 40 +++++++++++++ .../mapstruct/itest/immutables/Person.java | 28 +++++++++ .../mapstruct/itest/immutables/PersonDto.java | 58 +++++++++++++++++++ .../itest/immutables/PersonMapper.java | 32 ++++++++++ .../immutables/ImmutablesMapperTest.java | 55 ++++++++++++++++++ parent/pom.xml | 5 ++ 9 files changed, 317 insertions(+) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/pom.xml create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java new file mode 100644 index 0000000000..e8d3922fc2 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite( baseDir = "immutablesBuilderTest" ) +public class ImmutablesBuilderTest { +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml new file mode 100644 index 0000000000..4906dc997d --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + immutablesIntegrationTest + jar + + + + org.immutables + value + provided + + + diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java new file mode 100644 index 0000000000..2e96845e6f --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java @@ -0,0 +1,26 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +import org.immutables.value.Value; + +@Value.Immutable +public interface Address { + String getAddressLine(); +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java new file mode 100644 index 0000000000..7accf8559b --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +public class AddressDto { + + private String addressLine; + + public AddressDto() { + + } + + public AddressDto(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } + + public void setAddressLine(String addressLine) { + this.addressLine = addressLine; + } +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java new file mode 100644 index 0000000000..2951023942 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java @@ -0,0 +1,28 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +import org.immutables.value.Value; + +@Value.Immutable +public interface Person { + String getName(); + int getAge(); + Address getAddress(); +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java new file mode 100644 index 0000000000..99027926bb --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +public class PersonDto { + private String name; + private int age; + private AddressDto address; + + public PersonDto() { + } + + public PersonDto(String name, int age, AddressDto address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public AddressDto getAddress() { + return address; + } + + public void setAddress(AddressDto address) { + this.address = address; + } +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java new file mode 100644 index 0000000000..b52821fe6f --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person fromDto(PersonDto personDto); + PersonDto toDto(Person personDto); +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java b/integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java new file mode 100644 index 0000000000..9b526f1a54 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Lombok Builder Mapper implementations + * + * @author Eric Martineau + */ +public class ImmutablesMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( ImmutablePerson.builder() + .age( 33 ) + .name( "Bob" ) + .address( ImmutableAddress.builder() + .addressLine( "Wild Drive" ) + .build() ) + .build() ); + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index e87a80569c..57ee907357 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -199,6 +199,11 @@ lombok 1.16.18 + + org.immutables + value + 2.5.6 + From 45ab6e1c52ae15f875f80f53f3f15ebdfc5d4902 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 Dec 2017 01:15:54 +0100 Subject: [PATCH 0187/1006] #782 Add integration tests for builders with AutoValue --- .../itest/tests/AutoValueBuilderTest.java | 31 ++++++++++ .../resources/autoValueBuilderTest/pom.xml | 42 ++++++++++++++ .../mapstruct/itest/auto/value/Address.java | 37 ++++++++++++ .../itest/auto/value/AddressDto.java | 40 +++++++++++++ .../mapstruct/itest/auto/value/Person.java | 41 +++++++++++++ .../mapstruct/itest/auto/value/PersonDto.java | 58 +++++++++++++++++++ .../itest/auto/value/PersonMapper.java | 32 ++++++++++ .../itest/auto/value/AutoValueMapperTest.java | 55 ++++++++++++++++++ parent/pom.xml | 5 ++ 9 files changed, 341 insertions(+) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/pom.xml create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java create mode 100644 integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java new file mode 100644 index 0000000000..cdf071ed16 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite( baseDir = "autoValueBuilderTest" ) +public class AutoValueBuilderTest { +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml b/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml new file mode 100644 index 0000000000..3d37a1d024 --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + autoValueIntegrationTest + jar + + + + com.google.auto.value + auto-value + provided + + + diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java new file mode 100644 index 0000000000..ff0da32ecb --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +import com.google.auto.value.AutoValue; + +@AutoValue +public abstract class Address { + public abstract String getAddressLine(); + + public static Builder builder() { + return new AutoValue_Address.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder addressLine(String addressLine); + + public abstract Address build(); + } +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java new file mode 100644 index 0000000000..fe3d6d9ee7 --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +public class AddressDto { + + private String addressLine; + + public AddressDto() { + + } + + public AddressDto(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } + + public void setAddressLine(String addressLine) { + this.addressLine = addressLine; + } +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java new file mode 100644 index 0000000000..af46d576ec --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +import com.google.auto.value.AutoValue; + +@AutoValue +public abstract class Person { + public abstract String getName(); + public abstract int getAge(); + public abstract Address getAddress(); + + public static Builder builder() { + return new AutoValue_Person.Builder(); + } + + @AutoValue.Builder + public abstract static class Builder { + public abstract Builder name(String name); + public abstract Builder age(int age); + public abstract Builder address(Address address); + + public abstract Person build(); + } +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java new file mode 100644 index 0000000000..13f8d084df --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +public class PersonDto { + private String name; + private int age; + private AddressDto address; + + public PersonDto() { + } + + public PersonDto(String name, int age, AddressDto address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public AddressDto getAddress() { + return address; + } + + public void setAddress(AddressDto address) { + this.address = address; + } +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java new file mode 100644 index 0000000000..2e585c545c --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person fromDto(PersonDto personDto); + PersonDto toDto(Person personDto); +} diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java new file mode 100644 index 0000000000..93f5d58958 --- /dev/null +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.auto.value; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Lombok Builder Mapper implementations + * + * @author Eric Martineau + */ +public class AutoValueMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.builder() + .age( 33 ) + .name( "Bob" ) + .address( Address.builder() + .addressLine( "Wild Drive" ) + .build() ) + .build() ); + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 57ee907357..707e38c187 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -204,6 +204,11 @@ value 2.5.6 + + com.google.auto.value + auto-value + 1.5 + From dbc7c8a84d608a1b881e19205cdb388858ca650a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 Dec 2017 01:59:23 +0100 Subject: [PATCH 0188/1006] #782 Add integration tests for builders with FreeBuilder --- .../itest/tests/FreeBuilderBuilderTest.java | 31 ++++++++++ .../resources/freeBuilderBuilderTest/pom.xml | 42 ++++++++++++++ .../mapstruct/itest/freebuilder/Address.java | 32 ++++++++++ .../itest/freebuilder/AddressDto.java | 40 +++++++++++++ .../mapstruct/itest/freebuilder/Person.java | 34 +++++++++++ .../itest/freebuilder/PersonDto.java | 58 +++++++++++++++++++ .../itest/freebuilder/PersonMapper.java | 32 ++++++++++ .../freebuilder/FreeBuilderMapperTest.java | 55 ++++++++++++++++++ parent/pom.xml | 5 ++ 9 files changed, 329 insertions(+) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java create mode 100644 integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java new file mode 100644 index 0000000000..2b3c29451c --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java @@ -0,0 +1,31 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith( ProcessorSuiteRunner.class ) +@ProcessorSuite( baseDir = "freeBuilderBuilderTest" ) +public class FreeBuilderBuilderTest { +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml b/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml new file mode 100644 index 0000000000..0b02094fb7 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml @@ -0,0 +1,42 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + freeBuilderIntegrationTest + jar + + + + org.inferred + freebuilder + provided + + + diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java new file mode 100644 index 0000000000..0cc549a778 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +import org.inferred.freebuilder.FreeBuilder; + +@FreeBuilder +public abstract class Address { + public abstract String getAddressLine(); + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Address_Builder { } +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java new file mode 100644 index 0000000000..948efa42e3 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +public class AddressDto { + + private String addressLine; + + public AddressDto() { + + } + + public AddressDto(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } + + public void setAddressLine(String addressLine) { + this.addressLine = addressLine; + } +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java new file mode 100644 index 0000000000..81538dcf60 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +import org.inferred.freebuilder.FreeBuilder; + +@FreeBuilder +public abstract class Person { + public abstract String getName(); + public abstract int getAge(); + public abstract Address getAddress(); + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends Person_Builder { } +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java new file mode 100644 index 0000000000..e9b2c52e30 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java @@ -0,0 +1,58 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +public class PersonDto { + private String name; + private int age; + private AddressDto address; + + public PersonDto() { + } + + public PersonDto(String name, int age, AddressDto address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public AddressDto getAddress() { + return address; + } + + public void setAddress(AddressDto address) { + this.address = address; + } +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java new file mode 100644 index 0000000000..934a805848 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person fromDto(PersonDto personDto); + PersonDto toDto(Person personDto); +} diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java new file mode 100644 index 0000000000..0aacabd7a9 --- /dev/null +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.freebuilder; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Lombok Builder Mapper implementations + * + * @author Eric Martineau + */ +public class FreeBuilderMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.builder() + .setAge( 33 ) + .setName( "Bob" ) + .setAddress( Address.builder() + .setAddressLine( "Wild Drive" ) + .build() ) + .build() ); + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 707e38c187..a088ddd778 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -209,6 +209,11 @@ auto-value 1.5 + + org.inferred + freebuilder + 1.14.6 + From 70419f91b0725fee1b2d5e009eb29e13b2a4824d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 4 Feb 2018 12:18:30 +0100 Subject: [PATCH 0189/1006] #782 The builder type from lombok is not present during the annotation processing phase --- .../java/org/mapstruct/itest/lombok/PersonMapper.java | 6 ++++++ 1 file changed, 6 insertions(+) rename integrationtest/src/test/resources/lombokBuilderTest/src/{main => test}/java/org/mapstruct/itest/lombok/PersonMapper.java (81%) diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java similarity index 81% rename from integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java rename to integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java index d2b766fb99..120396af0b 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java @@ -22,6 +22,12 @@ import org.mapstruct.ReportingPolicy; import org.mapstruct.factory.Mappers; +/** + * The Builder creation method is not present during the annotation processing of the mapper. + * Therefore we put the mapper into a separate class. + * + * @see Lombok Issue #1538 + */ @Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) public interface PersonMapper { From d99a4cc2175be36002fe189a768d56a68dbf688b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 13 Dec 2017 18:43:11 +0100 Subject: [PATCH 0190/1006] #782 Add support for mapping immutable classes with builders --- .../ap/internal/model/BeanMappingMethod.java | 56 +++++++++-- .../ap/internal/model/MethodReference.java | 20 +++- .../ap/internal/model/PropertyMapping.java | 2 +- .../ap/internal/model/common/Type.java | 12 +++ .../ap/internal/model/common/TypeFactory.java | 16 ++++ .../model/source/TargetReference.java | 5 + .../processor/MethodRetrievalProcessor.java | 3 +- .../creation/MappingResolverImpl.java | 38 +++++++- .../org/mapstruct/ap/spi/BuilderProvider.java | 33 +++++++ .../ap/spi/DefaultAccessorNamingStrategy.java | 18 +++- .../ap/spi/DefaultBuilderProvider.java | 95 +++++++++++++++++++ .../ap/internal/model/BeanMappingMethod.ftl | 10 +- .../DateFormatValidatorFactoryTest.java | 1 + .../common/DefaultConversionContextTest.java | 1 + .../nestedprop/BuilderNestedPropertyTest.java | 2 + 15 files changed, 297 insertions(+), 15 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 9a6d9e9b55..6a5b1d09a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -41,6 +41,7 @@ import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; @@ -76,6 +77,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final Map> mappingsByParameter; private final List constantMappings; private final Type resultType; + private final MethodReference finalizeMethod; public static class Builder { @@ -112,7 +114,7 @@ private Builder setupMethodWithMapping(Method sourceMethod) { this.method = sourceMethod; this.methodMappings = sourceMethod.getMappingOptions().getMappings(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); - Map accessors = method.getResultType().getPropertyWriteAccessors( cms ); + Map accessors = method.getResultType().getMappingType().getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); this.unprocessedTargetProperties = new LinkedHashMap( accessors ); @@ -184,7 +186,7 @@ public BeanMappingMethod build() { Type resultType = null; if ( factoryMethod == null ) { if ( selectionParameters != null && selectionParameters.getResultType() != null ) { - resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ); + resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getMappingType(); if ( resultType.isAbstract() ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -210,18 +212,19 @@ else if ( !resultType.hasEmptyAccessibleContructor() ) { ); } } - else if ( !method.isUpdateMethod() && method.getReturnType().isAbstract() ) { + else if ( !method.isUpdateMethod() && method.getReturnType().getMappingType().isAbstract() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_ABSTRACT_RETURN_TYPE, - method.getReturnType() + method.getReturnType().getMappingType() ); } - else if ( !method.isUpdateMethod() && !method.getReturnType().hasEmptyAccessibleContructor() ) { + else if ( !method.isUpdateMethod() && + !method.getReturnType().getMappingType().hasEmptyAccessibleContructor() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - method.getReturnType() + method.getReturnType().getMappingType() ); } } @@ -241,6 +244,34 @@ else if ( !method.isUpdateMethod() && !method.getReturnType().hasEmptyAccessible ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); } + MethodReference finalizeMethod = null; + if ( + !method.getReturnType().isVoid() && + ( resultType != null + && !ctx.getTypeUtils().isAssignable( + resultType.getMappingType().getTypeMirror(), + resultType.getTypeMirror() + ) || + !ctx.getTypeUtils().isSameType( + method.getReturnType().getMappingType().getTypeMirror(), + method.getReturnType().getTypeMirror() + ) + ) + ) { + finalizeMethod = MethodReference.forForgedMethod( + new ForgedMethod( + "build", + method.getReturnType(), + method.getReturnType(), + null, + null, + Collections.emptyList(), + null + ), + Collections.emptyList() + ); + } + return new BeanMappingMethod( method, existingVariableNames, @@ -249,7 +280,8 @@ else if ( !method.isUpdateMethod() && !method.getReturnType().hasEmptyAccessible mapNullToDefault, resultType, beforeMappingMethods, - afterMappingMethods + afterMappingMethods, + finalizeMethod ); } @@ -786,7 +818,8 @@ private BeanMappingMethod(Method method, boolean mapNullToDefault, Type resultType, List beforeMappingReferences, - List afterMappingReferences) { + List afterMappingReferences, + MethodReference finalizeMethod) { super( method, existingVariableNames, @@ -797,6 +830,7 @@ private BeanMappingMethod(Method method, ); this.propertyMappings = propertyMappings; + this.finalizeMethod = finalizeMethod; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. @@ -838,6 +872,10 @@ public Type getResultType() { } } + public MethodReference getFinalizeMethod() { + return finalizeMethod; + } + @Override public Set getImportTypes() { Set types = super.getImportTypes(); @@ -846,6 +884,8 @@ public Set getImportTypes() { types.addAll( propertyMapping.getImportTypes() ); } + types.add( getResultType().getMappingType() ); + return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 2eca505935..db21246cee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -118,6 +118,21 @@ private MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.name = method.getName(); } + private MethodReference(String name, Type definingType) { + this.name = name; + this.definingType = definingType; + this.sourceParameters = Collections.emptyList(); + this.returnType = null; + this.declaringMapper = null; + this.importTypes = Collections.emptySet(); + this.thrownTypes = Collections.emptyList(); + this.isUpdateMethod = false; + this.contextParam = null; + this.parameterBindings = Collections.emptyList(); + this.providingParameter = null; + this.isStatic = true; + } + public MapperReference getDeclaringMapper() { return declaringMapper; } @@ -244,7 +259,6 @@ public AssignmentType getType() { } } - @Override public Type getReturnType() { return returnType; } @@ -319,4 +333,8 @@ public static MethodReference forMapperReference(Method method, MapperReference List parameterBindings) { return new MethodReference( method, declaringMapper, null, parameterBindings ); } + + public static MethodReference forStaticBuilder(String builderCreationMethod, Type definingType) { + return new MethodReference( builderCreationMethod, definingType ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index aaec86f4b1..f6e750b07a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -148,7 +148,7 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { private Type determineTargetType() { // This is a bean mapping method, so we know the result is a declared type - DeclaredType resultType = (DeclaredType) method.getResultType().getTypeMirror(); + DeclaredType resultType = (DeclaredType) method.getResultType().getMappingType().getTypeMirror(); switch ( targetWriteAccessorType ) { case ADDER: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index d9ae2d68f1..cfcd29d388 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -72,6 +72,7 @@ public class Type extends ModelElement implements Comparable { private final ImplementationType implementationType; private final Type componentType; + private final Type builderType; private final String packageName; private final String name; @@ -104,6 +105,7 @@ public class Type extends ModelElement implements Comparable { public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, TypeMirror typeMirror, TypeElement typeElement, List typeParameters, ImplementationType implementationType, Type componentType, + Type builderType, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported) { @@ -117,6 +119,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.typeParameters = typeParameters; this.componentType = componentType; this.implementationType = implementationType; + this.builderType = builderType; this.packageName = packageName; this.name = name; @@ -173,6 +176,14 @@ public Type getComponentType() { return componentType; } + public Type getBuilderType() { + return builderType; + } + + public Type getMappingType() { + return builderType != null ? builderType : this; + } + public boolean isPrimitive() { return typeMirror.getKind().isPrimitive(); } @@ -355,6 +366,7 @@ public Type erasure() { typeParameters, implementationType, componentType, + builderType, packageName, name, qualifiedName, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 964bb79c06..377b9648f8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -57,9 +57,12 @@ import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.RoundContext; +import org.mapstruct.ap.internal.util.Services; import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.DefaultBuilderProvider; import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity; @@ -72,6 +75,11 @@ */ public class TypeFactory { + private static final BuilderProvider BUILDER_PROVIDER = Services.get( + BuilderProvider.class, + new DefaultBuilderProvider() + ); + private final Elements elementUtils; private final Types typeUtils; private final RoundContext roundContext; @@ -162,6 +170,7 @@ public Type getType(TypeMirror mirror) { } ImplementationType implementationType = getImplementationType( mirror ); + Type builderType = findBuilder( mirror ); boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); boolean isCollectionType = typeUtils.isSubtype( mirror, collectionType ); @@ -247,6 +256,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { getTypeParameters( mirror, false ), implementationType, componentType, + builderType, packageName, name, qualifiedName, @@ -458,6 +468,7 @@ private ImplementationType getImplementationType(TypeMirror mirror) { getTypeParameters( mirror, true ), null, null, + null, implementationType.getPackageName(), implementationType.getName(), implementationType.getFullyQualifiedName(), @@ -475,6 +486,11 @@ private ImplementationType getImplementationType(TypeMirror mirror) { return null; } + private Type findBuilder(TypeMirror type) { + TypeMirror builder = BUILDER_PROVIDER.findBuilder( type, elementUtils, typeUtils ); + return builder == null ? null : getType( builder ); + } + private TypeMirror getComponentType(TypeMirror mirror) { if ( mirror.getKind() != TypeKind.ARRAY ) { return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 0697ba074d..e1824529c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -153,6 +153,7 @@ public TargetReference build() { boolean foundEntryMatch; Type resultType = method.getResultType(); + resultType = resultType.getMappingType(); // there can be 4 situations // 1. Return type @@ -256,6 +257,10 @@ private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAc else if ( targetWriteAccessor == null ) { errorMessage = new NoWriteAccessorErrorMessage( mapping, method, messager ); } + else { + //TODO there is no read accessor. What should we do here? + errorMessage = new NoPropertyErrorMessage( mapping, method, messager, entryNames, index, nextType ); + } } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 5ac734d3b6..9a4d469b20 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -409,7 +409,8 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List emptyList(), SelectionCriteria.forFactoryMethods( selectionParameters ) ); if (matchingFactoryMethods.isEmpty()) { - return null; + return findBuilderFactoryMethod( mappingMethod, targetType ); } if ( matchingFactoryMethods.size() > 1 ) { @@ -163,6 +166,39 @@ java.util.Collections. emptyList(), matchingFactoryMethod.getParameterBindings() ); } + private MethodReference findBuilderFactoryMethod(Method mappingMethod, Type targetType) { + if ( targetType.getBuilderType() == null ) { + return null; + } + Type builderType = targetType.getBuilderType(); + + Type returnType = mappingMethod.getReturnType(); + List builderCreators = new ArrayList(); + for ( ExecutableElement executableElement : Executables.getAllEnclosedExecutableElements( + elementsUtils, + returnType.getTypeElement() + ) ) { + if ( !executableElement.getModifiers().containsAll( Arrays.asList( Modifier.PUBLIC, Modifier.STATIC ) ) + || !executableElement.getParameters().isEmpty() + || !typeUtils.isSameType( executableElement.getReturnType(), builderType.getTypeMirror() )) { + continue; + } + builderCreators.add( executableElement ); + } + + if ( builderCreators.size() == 1 ) { + return MethodReference.forStaticBuilder( first( builderCreators ).getSimpleName().toString(), targetType ); + } + else if ( builderCreators.size() > 1 ) { + //error + return null; + } + + // Find the default constructor, if it exists, and construct the FactoryMethod + // We could also live with assuming it exists + return null; + } + private MapperReference findMapperReference(Method method) { for ( MapperReference ref : mapperReferences ) { if ( ref.getType().equals( method.getDeclaringMapper() ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java new file mode 100644 index 0000000000..2eb50dcc94 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +/** + * A service provider interface that is used to detect types that require a builder for mapping. This interface could + * support automatic detection of builders for projects like Lombok, Immutables, AutoValue, etc. + * @author Filip Hrisafov + */ +public interface BuilderProvider { + + TypeMirror findBuilder(TypeMirror type, Elements elements, Types types); +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index e691eeb9c0..0744f75821 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -19,6 +19,7 @@ package org.mapstruct.ap.spi; import java.beans.Introspector; +import java.util.regex.Pattern; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; @@ -36,6 +37,8 @@ */ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { + private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + @Override public MethodType getMethodType(ExecutableElement method) { if ( isGetterMethod( method ) ) { @@ -93,7 +96,14 @@ public boolean isGetterMethod(ExecutableElement method) { public boolean isSetterMethod(ExecutableElement method) { String methodName = method.getSimpleName().toString(); - return methodName.startsWith( "set" ) && methodName.length() > 3; + return methodName.startsWith( "set" ) && methodName.length() > 3 || isBuilderSetter( method ); + } + + protected boolean isBuilderSetter(ExecutableElement method) { + return method.getParameters().size() == 1 && + !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && + //TODO The Types need to be compared with Types#isSameType(TypeMirror, TypeMirror) + method.getReturnType().toString().equals( method.getEnclosingElement().asType().toString() ); } /** @@ -145,6 +155,12 @@ public boolean isPresenceCheckMethod(ExecutableElement method) { @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); + if ( methodName.startsWith( "is" ) || methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { + return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); + } + else if ( isBuilderSetter( getterOrSetterMethod ) ) { + return methodName; + } return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java new file mode 100644 index 0000000000..4efcd8e3b7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -0,0 +1,95 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import java.util.List; +import java.util.regex.Pattern; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.ElementFilter; +import javax.lang.model.util.Elements; +import javax.lang.model.util.SimpleElementVisitor6; +import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.Types; + +/** + * Default implementation of {@link BuilderProvider} + * + * @author Filip Hrisafov + */ +public class DefaultBuilderProvider implements BuilderProvider { + + private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + + @Override + public TypeMirror findBuilder(TypeMirror type, Elements elements, Types types) { + DeclaredType declaredType = type.accept( + new SimpleTypeVisitor6() { + @Override + public DeclaredType visitDeclared(DeclaredType t, Void p) { + return t; + } + }, + null + ); + + if ( declaredType == null ) { + return null; + } + + TypeElement typeElement = declaredType.asElement().accept( + new SimpleElementVisitor6() { + @Override + public TypeElement visitType(TypeElement e, Void p) { + return e; + } + }, + null + ); + + return findBuilder( typeElement, elements, types ); + } + + protected TypeMirror findBuilder(TypeElement typeElement, Elements elements, Types types) { + Name name = typeElement.getQualifiedName(); + if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { + return null; + } + List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); + + for ( ExecutableElement method : methods ) { + if ( isBuilderMethod( method ) ) { + return method.getReturnType(); + } + } + + return findBuilder( typeElement.getSuperclass(), elements, types ); + } + + protected boolean isBuilderMethod(ExecutableElement method) { + return method.getParameters().isEmpty() + && method.getSimpleName().toString().equals( "builder" ) + && method.getModifiers().contains( Modifier.PUBLIC ) + && method.getModifiers().contains( Modifier.STATIC ); + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index d19ee8a769..168f93d21b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -34,7 +34,7 @@ <#if !existingInstanceMapping> - <@includeModel object=resultType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType/><#else>new <@includeModel object=resultType/>(); + <@includeModel object=resultType.mappingType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.mappingType/><#else>new <@includeModel object=resultType.mappingType/>(); <#list beforeMappingReferencesWithMappingTarget as callback> @@ -78,7 +78,13 @@ <#if returnType.name != "void"> - return ${resultName}; + <#if resultType.builderType??> + return ${resultName}.build(); + <#elseif finalizeMethod??> + return ${resultName}.<@includeModel object=finalizeMethod />; + <#else> + return ${resultName}; + } <#macro throws> diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 7c68b9394d..e74b9574e6 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -175,6 +175,7 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, + null, fullQualifiedName, false, false, diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index c6b5ce2cf6..5770868197 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -126,6 +126,7 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, + null, fullQualifiedName, false, false, diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java index 3eca56c8fc..c673cb18dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.builder.nestedprop; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.WithClasses; @@ -35,6 +36,7 @@ FlattenedMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) +@Ignore("Nested target not working yet") public class BuilderNestedPropertyTest { @Test From 45abe9e35b46a53a7aad20dfd8dbf2a4086a9bb0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 10 Feb 2018 15:33:14 +0100 Subject: [PATCH 0191/1006] #782 Add BuilderInfo to SPI The implementors of the SPI should return all the required information --- .../org/mapstruct/ap/MappingProcessor.java | 2 +- .../ap/internal/model/BeanMappingMethod.java | 45 +++---- .../ap/internal/model/MethodReference.java | 10 +- .../ap/internal/model/common/BuilderType.java | 113 ++++++++++++++++++ .../ap/internal/model/common/Type.java | 14 ++- .../ap/internal/model/common/TypeFactory.java | 12 +- .../creation/MappingResolverImpl.java | 42 +++---- .../ap/internal/util/Executables.java | 1 + .../org/mapstruct/ap/spi/BuilderInfo.java | 68 +++++++++++ .../org/mapstruct/ap/spi/BuilderProvider.java | 2 +- .../ap/spi/DefaultBuilderProvider.java | 77 +++++++++--- .../TypeHierarchyErroneousException.java | 2 +- .../ap/internal/model/BeanMappingMethod.ftl | 4 +- 13 files changed, 299 insertions(+), 93 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java rename processor/src/main/java/org/mapstruct/ap/{internal/util => spi}/TypeHierarchyErroneousException.java (97%) diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 76c4f6a838..a5bcc66139 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -52,7 +52,7 @@ import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.AnnotationProcessorContext; import org.mapstruct.ap.internal.util.RoundContext; -import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** * A JSR 269 annotation {@link Processor} which generates the implementations for mapper interfaces (interfaces diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 6a5b1d09a9..29cba8dbb8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -40,8 +40,8 @@ import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; @@ -244,33 +244,8 @@ else if ( !method.isUpdateMethod() && ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); } - MethodReference finalizeMethod = null; - if ( - !method.getReturnType().isVoid() && - ( resultType != null - && !ctx.getTypeUtils().isAssignable( - resultType.getMappingType().getTypeMirror(), - resultType.getTypeMirror() - ) || - !ctx.getTypeUtils().isSameType( - method.getReturnType().getMappingType().getTypeMirror(), - method.getReturnType().getTypeMirror() - ) - ) - ) { - finalizeMethod = MethodReference.forForgedMethod( - new ForgedMethod( - "build", - method.getReturnType(), - method.getReturnType(), - null, - null, - Collections.emptyList(), - null - ), - Collections.emptyList() - ); - } + MethodReference finalizeMethod = getFinalizeMethod( + resultType == null ? method.getReturnType() : resultType ); return new BeanMappingMethod( method, @@ -285,6 +260,20 @@ else if ( !method.isUpdateMethod() && ); } + private MethodReference getFinalizeMethod(Type resultType) { + if ( method.getReturnType().isVoid() || + resultType.getMappingType().isAssignableTo( resultType ) ) { + return null; + } + BuilderType builderType = resultType.getBuilderType(); + if ( builderType == null ) { + // If the mapping type is assignable to the result type this should never happen + return null; + } + + return MethodReference.forMethodCall( builderType.getBuildMethod() ); + } + /** * If there were nested defined targets that have not been handled. Then we need to process them at the end. */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index db21246cee..003c196ab0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -118,7 +118,7 @@ private MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.name = method.getName(); } - private MethodReference(String name, Type definingType) { + private MethodReference(String name, Type definingType, boolean isStatic) { this.name = name; this.definingType = definingType; this.sourceParameters = Collections.emptyList(); @@ -130,7 +130,7 @@ private MethodReference(String name, Type definingType) { this.contextParam = null; this.parameterBindings = Collections.emptyList(); this.providingParameter = null; - this.isStatic = true; + this.isStatic = isStatic; } public MapperReference getDeclaringMapper() { @@ -335,6 +335,10 @@ public static MethodReference forMapperReference(Method method, MapperReference } public static MethodReference forStaticBuilder(String builderCreationMethod, Type definingType) { - return new MethodReference( builderCreationMethod, definingType ); + return new MethodReference( builderCreationMethod, definingType, true ); + } + + public static MethodReference forMethodCall(String methodName) { + return new MethodReference( methodName, null, false ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java new file mode 100644 index 0000000000..36e4c5f8ea --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -0,0 +1,113 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.common; + +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; + +import org.mapstruct.ap.spi.BuilderInfo; + +/** + * @author Filip Hrisafov + */ +public class BuilderType { + + private final Type builder; + private final Type owner; + private final Type buildingType; + private final ExecutableElement builderCreationMethod; + private final ExecutableElement buildMethod; + + private BuilderType( + Type builder, + Type owner, + Type buildingType, + ExecutableElement builderCreationMethod, + ExecutableElement buildMethod + ) { + this.builder = builder; + this.owner = owner; + this.buildingType = buildingType; + this.builderCreationMethod = builderCreationMethod; + this.buildMethod = buildMethod; + } + + public Type getBuilder() { + return builder; + } + + public Type getOwner() { + return owner; + } + + public Type getBuildingType() { + return buildingType; + } + + public ExecutableElement getBuilderCreationMethod() { + return builderCreationMethod; + } + + public String getBuildMethod() { + return buildMethod.getSimpleName().toString(); + } + + public BuilderInfo asBuilderInfo() { + return new BuilderInfo.Builder() + .builderCreationMethod( this.builderCreationMethod ) + .buildMethod( this.buildMethod ) + .build(); + } + + public static BuilderType create(BuilderInfo builderInfo, Type typeToBuild, TypeFactory typeFactory, + Types typeUtils) { + if ( builderInfo == null ) { + return null; + } + ExecutableElement buildMethod = builderInfo.getBuildMethod(); + if ( !typeUtils.isAssignable( buildMethod.getReturnType(), typeToBuild.getTypeMirror() ) ) { + //TODO throw error + throw new IllegalArgumentException( "Build return type is not assignable" ); + } + + Type builder = typeFactory.getType( builderInfo.getBuilderCreationMethod().getReturnType() ); + ExecutableElement builderCreationMethod = builderInfo.getBuilderCreationMethod(); + Type owner; + TypeMirror builderCreationOwner = builderCreationMethod.getEnclosingElement().asType(); + if ( typeUtils.isSameType( builderCreationOwner, typeToBuild.getTypeMirror() ) ) { + owner = typeToBuild; + } + else if ( typeUtils.isSameType( builder.getTypeMirror(), builderCreationOwner ) ) { + owner = builder; + } + else { + owner = typeFactory.getType( builderCreationOwner ); + } + + + return new BuilderType( + builder, + owner, + typeToBuild, + builderCreationMethod, + buildMethod + ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index cfcd29d388..ee7b7b445e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -49,6 +49,7 @@ import org.mapstruct.ap.internal.util.Nouns; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; +import org.mapstruct.ap.spi.BuilderInfo; /** * Represents (a reference to) the type of a bean property, parameter etc. Types are managed per generated source file. @@ -72,7 +73,7 @@ public class Type extends ModelElement implements Comparable { private final ImplementationType implementationType; private final Type componentType; - private final Type builderType; + private final BuilderType builderType; private final String packageName; private final String name; @@ -105,7 +106,7 @@ public class Type extends ModelElement implements Comparable { public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, TypeMirror typeMirror, TypeElement typeElement, List typeParameters, ImplementationType implementationType, Type componentType, - Type builderType, + BuilderInfo builderInfo, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported) { @@ -119,7 +120,6 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.typeParameters = typeParameters; this.componentType = componentType; this.implementationType = implementationType; - this.builderType = builderType; this.packageName = packageName; this.name = name; @@ -149,6 +149,8 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, else { enumConstants = Collections.emptyList(); } + + this.builderType = BuilderType.create( builderInfo, this, this.typeFactory, this.typeUtils ); } //CHECKSTYLE:ON @@ -176,12 +178,12 @@ public Type getComponentType() { return componentType; } - public Type getBuilderType() { + public BuilderType getBuilderType() { return builderType; } public Type getMappingType() { - return builderType != null ? builderType : this; + return builderType != null ? builderType.getBuilder() : this; } public boolean isPrimitive() { @@ -366,7 +368,7 @@ public Type erasure() { typeParameters, implementationType, componentType, - builderType, + builderType == null ? null : builderType.asBuilderInfo(), packageName, name, qualifiedName, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 377b9648f8..8780596829 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -58,11 +58,12 @@ import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.Services; -import org.mapstruct.ap.internal.util.TypeHierarchyErroneousException; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.spi.BuilderInfo; import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity; @@ -170,7 +171,7 @@ public Type getType(TypeMirror mirror) { } ImplementationType implementationType = getImplementationType( mirror ); - Type builderType = findBuilder( mirror ); + BuilderInfo builderInfo = findBuilder( mirror ); boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); boolean isCollectionType = typeUtils.isSubtype( mirror, collectionType ); @@ -256,7 +257,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { getTypeParameters( mirror, false ), implementationType, componentType, - builderType, + builderInfo, packageName, name, qualifiedName, @@ -486,9 +487,8 @@ private ImplementationType getImplementationType(TypeMirror mirror) { return null; } - private Type findBuilder(TypeMirror type) { - TypeMirror builder = BUILDER_PROVIDER.findBuilder( type, elementUtils, typeUtils ); - return builder == null ? null : getType( builder ); + private BuilderInfo findBuilder(TypeMirror type) { + return BUILDER_PROVIDER.findBuilderInfo( type, elementUtils, typeUtils ); } private TypeMirror getComponentType(TypeMirror mirror) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 9c3cccb521..01f26e04c5 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -22,13 +22,12 @@ import static org.mapstruct.ap.internal.util.Collections.first; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; @@ -46,6 +45,7 @@ import org.mapstruct.ap.internal.model.MethodReference; import org.mapstruct.ap.internal.model.VirtualMappingMethod; import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -60,7 +60,6 @@ import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Collections; -import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -143,7 +142,7 @@ java.util.Collections. emptyList(), SelectionCriteria.forFactoryMethods( selectionParameters ) ); if (matchingFactoryMethods.isEmpty()) { - return findBuilderFactoryMethod( mappingMethod, targetType ); + return findBuilderFactoryMethod( targetType ); } if ( matchingFactoryMethods.size() > 1 ) { @@ -166,37 +165,24 @@ java.util.Collections. emptyList(), matchingFactoryMethod.getParameterBindings() ); } - private MethodReference findBuilderFactoryMethod(Method mappingMethod, Type targetType) { - if ( targetType.getBuilderType() == null ) { + private MethodReference findBuilderFactoryMethod(Type targetType) { + BuilderType builder = targetType.getBuilderType(); + if ( builder == null ) { return null; } - Type builderType = targetType.getBuilderType(); - - Type returnType = mappingMethod.getReturnType(); - List builderCreators = new ArrayList(); - for ( ExecutableElement executableElement : Executables.getAllEnclosedExecutableElements( - elementsUtils, - returnType.getTypeElement() - ) ) { - if ( !executableElement.getModifiers().containsAll( Arrays.asList( Modifier.PUBLIC, Modifier.STATIC ) ) - || !executableElement.getParameters().isEmpty() - || !typeUtils.isSameType( executableElement.getReturnType(), builderType.getTypeMirror() )) { - continue; - } - builderCreators.add( executableElement ); - } - if ( builderCreators.size() == 1 ) { - return MethodReference.forStaticBuilder( first( builderCreators ).getSimpleName().toString(), targetType ); + ExecutableElement builderCreationMethod = builder.getBuilderCreationMethod(); + if ( builderCreationMethod.getKind() == ElementKind.CONSTRUCTOR ) { + // If the builder creation method is a constructor it would be handled properly down the line + return null; } - else if ( builderCreators.size() > 1 ) { - //error + + if ( !builder.getBuildingType().isAssignableTo( targetType ) ) { + //TODO print error message return null; } - // Find the default constructor, if it exists, and construct the FactoryMethod - // We could also live with assuming it exists - return null; + return MethodReference.forStaticBuilder( builderCreationMethod.getSimpleName().toString(), builder.getOwner() ); } private MapperReference findMapperReference(Method method) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 3b087b59c7..f70b5fcffc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -47,6 +47,7 @@ import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.MethodType; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** * Provides functionality around {@link ExecutableElement}s. diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java new file mode 100644 index 0000000000..24cbe36ead --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -0,0 +1,68 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.element.ExecutableElement; + +/** + * @author Filip Hrisafov + */ +public class BuilderInfo { + + private final ExecutableElement builderCreationMethod; + private final ExecutableElement buildMethod; + + private BuilderInfo(ExecutableElement builderCreationMethod, ExecutableElement buildMethod) { + this.builderCreationMethod = builderCreationMethod; + this.buildMethod = buildMethod; + } + + public ExecutableElement getBuilderCreationMethod() { + return builderCreationMethod; + } + + public ExecutableElement getBuildMethod() { + return buildMethod; + } + + public static class Builder { + private ExecutableElement builderCreationMethod; + private ExecutableElement buildMethod; + + public Builder builderCreationMethod(ExecutableElement method) { + this.builderCreationMethod = method; + return this; + } + + public Builder buildMethod(ExecutableElement method) { + this.buildMethod = method; + return this; + } + + public BuilderInfo build() { + if ( builderCreationMethod == null ) { + throw new IllegalArgumentException( "Builder creation method is mandatory" ); + } + else if ( buildMethod == null ) { + throw new IllegalArgumentException( "Build method is mandatory" ); + } + return new BuilderInfo( builderCreationMethod, buildMethod ); + } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index 2eb50dcc94..038578b690 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -29,5 +29,5 @@ */ public interface BuilderProvider { - TypeMirror findBuilder(TypeMirror type, Elements elements, Types types); + BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 4efcd8e3b7..c1fb980d51 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -22,9 +22,9 @@ import java.util.regex.Pattern; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; -import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; @@ -42,7 +42,19 @@ public class DefaultBuilderProvider implements BuilderProvider { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); @Override - public TypeMirror findBuilder(TypeMirror type, Elements elements, Types types) { + public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types) { + TypeElement typeElement = getTypeElement( type ); + if ( typeElement == null ) { + return null; + } + + return findBuilderInfo( typeElement, elements, types ); + } + + protected TypeElement getTypeElement(TypeMirror type) { + if ( type.getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( type ); + } DeclaredType declaredType = type.accept( new SimpleTypeVisitor6() { @Override @@ -57,7 +69,7 @@ public DeclaredType visitDeclared(DeclaredType t, Void p) { return null; } - TypeElement typeElement = declaredType.asElement().accept( + return declaredType.asElement().accept( new SimpleElementVisitor6() { @Override public TypeElement visitType(TypeElement e, Void p) { @@ -66,30 +78,63 @@ public TypeElement visitType(TypeElement e, Void p) { }, null ); - - return findBuilder( typeElement, elements, types ); } - protected TypeMirror findBuilder(TypeElement typeElement, Elements elements, Types types) { - Name name = typeElement.getQualifiedName(); - if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { + protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + if ( shouldIgnore( typeElement ) ) { return null; } - List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); + List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); for ( ExecutableElement method : methods ) { - if ( isBuilderMethod( method ) ) { - return method.getReturnType(); + if ( isPossibleBuilderCreationMethod( method, typeElement, types ) ) { + TypeElement builderElement = getTypeElement( method.getReturnType() ); + ExecutableElement buildMethod = findBuildMethod( builderElement, typeElement, types ); + if ( buildMethod != null ) { + return new BuilderInfo.Builder() + .builderCreationMethod( method ) + .buildMethod( buildMethod ) + .build(); + } } } - - return findBuilder( typeElement.getSuperclass(), elements, types ); + return findBuilderInfo( typeElement.getSuperclass(), elements, types ); } - protected boolean isBuilderMethod(ExecutableElement method) { + protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, TypeElement typeElement, Types types) { return method.getParameters().isEmpty() - && method.getSimpleName().toString().equals( "builder" ) && method.getModifiers().contains( Modifier.PUBLIC ) - && method.getModifiers().contains( Modifier.STATIC ); + && method.getModifiers().contains( Modifier.STATIC ) + && !types.isSameType( method.getReturnType(), typeElement.asType() ); + } + + protected ExecutableElement findBuildMethod(TypeElement builderElement, TypeElement typeElement, Types types) { + if ( shouldIgnore( builderElement ) ) { + return null; + } + + List builderMethods = ElementFilter.methodsIn( builderElement.getEnclosedElements() ); + for ( ExecutableElement buildMethod : builderMethods ) { + if ( isBuildMethod( buildMethod, typeElement, types ) ) { + return buildMethod; + } + } + + return findBuildMethod( + getTypeElement( builderElement.getSuperclass() ), + typeElement, + types + ); + } + + protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement, + Types types) { + return buildMethod.getParameters().isEmpty() && + buildMethod.getModifiers().contains( Modifier.PUBLIC ) + && types.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); + } + + protected boolean shouldIgnore(TypeElement typeElement) { + return typeElement == null || JAVA_JAVAX_PACKAGE.matcher( typeElement.getQualifiedName() ).matches(); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java similarity index 97% rename from processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java rename to processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java index 18194c222c..e4c975b171 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/TypeHierarchyErroneousException.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.internal.util; +package org.mapstruct.ap.spi; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 168f93d21b..d36a9fc230 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -78,9 +78,7 @@ <#if returnType.name != "void"> - <#if resultType.builderType??> - return ${resultName}.build(); - <#elseif finalizeMethod??> + <#if finalizeMethod??> return ${resultName}.<@includeModel object=finalizeMethod />; <#else> return ${resultName}; From 252af70baec91f6e152f960258f165a334fe812d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 10 Feb 2018 15:34:39 +0100 Subject: [PATCH 0192/1006] Add new processor suite that ignores the maven procesor plugin The maven-processor-plugin does not take classpath dependencies during the processing --- .../org/mapstruct/itest/tests/AutoValueBuilderTest.java | 3 ++- .../org/mapstruct/itest/tests/FreeBuilderBuilderTest.java | 3 ++- .../org/mapstruct/itest/tests/ImmutablesBuilderTest.java | 3 ++- .../java/org/mapstruct/itest/tests/LombokBuilderTest.java | 3 ++- .../org/mapstruct/itest/testutil/runner/ProcessorSuite.java | 6 ++++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java index cdf071ed16..3d69d052f9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java @@ -26,6 +26,7 @@ * @author Filip Hrisafov */ @RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "autoValueBuilderTest" ) +@ProcessorSuite(baseDir = "autoValueBuilderTest", + processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) public class AutoValueBuilderTest { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java index 2b3c29451c..78b5465c83 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java @@ -26,6 +26,7 @@ * @author Filip Hrisafov */ @RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "freeBuilderBuilderTest" ) +@ProcessorSuite( baseDir = "freeBuilderBuilderTest", + processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) public class FreeBuilderBuilderTest { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java index e8d3922fc2..2bc395486e 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java @@ -26,6 +26,7 @@ * @author Filip Hrisafov */ @RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "immutablesBuilderTest" ) +@ProcessorSuite( baseDir = "immutablesBuilderTest", + processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) public class ImmutablesBuilderTest { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java index 756f2ed9b9..133a4047b4 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java @@ -26,6 +26,7 @@ * @author Eric Martineau */ @RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "lombokBuilderTest" ) +@ProcessorSuite( baseDir = "lombokBuilderTest", + processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) public class LombokBuilderTest { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java index b873522318..62ad61f936 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java @@ -96,6 +96,12 @@ enum ProcessorType { */ PROCESSOR_PLUGIN_JAVA_8( null, null, "1.8" ), + /** + * Use all processing variants, but without the maven-procesor-plugin + */ + ALL_WITHOUT_PROCESSOR_PLUGIN(ORACLE_JAVA_6, ORACLE_JAVA_7, ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_6, + ECLIPSE_JDT_JAVA_7, ECLIPSE_JDT_JAVA_8), + /** * Use all available processing variants */ From 22c337a947437a685facab11c400b45bfc12416b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 10 Feb 2018 17:39:48 +0100 Subject: [PATCH 0193/1006] #782 Add custom SPI implementations for Immutables in the integration tests --- .../immutablesBuilderTest/extras/pom.xml | 24 +++++ .../ImmutablesAccessorNamingStrategy.java | 34 +++++++ .../extras/ImmutablesBuilderProvider.java | 97 +++++++++++++++++++ .../immutablesBuilderTest/mapper/pom.xml | 28 ++++++ .../mapstruct/itest/immutables/Address.java | 0 .../itest/immutables/AddressDto.java | 0 .../mapstruct/itest/immutables/Person.java | 0 .../mapstruct/itest/immutables/PersonDto.java | 0 .../itest/immutables/PersonMapper.java | 0 ...rg.mapstruct.ap.spi.AccessorNamingStrategy | 18 ++++ .../org.mapstruct.ap.spi.BuilderProvider | 18 ++++ .../immutables/ImmutablesMapperTest.java | 0 .../resources/immutablesBuilderTest/pom.xml | 15 ++- 13 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/main/java/org/mapstruct/itest/immutables/Address.java (100%) rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/main/java/org/mapstruct/itest/immutables/AddressDto.java (100%) rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/main/java/org/mapstruct/itest/immutables/Person.java (100%) rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/main/java/org/mapstruct/itest/immutables/PersonDto.java (100%) rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java (100%) create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy create mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider rename integrationtest/src/test/resources/immutablesBuilderTest/{ => mapper}/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java (100%) diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml new file mode 100644 index 0000000000..c7f6a13f92 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + + immutablesIntegrationTest + org.mapstruct + 1.0.0 + + + itest-immutables-mapping-extras + + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + provided + + + + \ No newline at end of file diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java new file mode 100644 index 0000000000..56fef54689 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables.extras; + +import javax.lang.model.element.ExecutableElement; + +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; + +/** + * @author Filip Hrisafov + */ +public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + @Override + protected boolean isBuilderSetter(ExecutableElement method) { + return super.isBuilderSetter( method ) && !method.getSimpleName().toString().equals( "from" ); + } +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java new file mode 100644 index 0000000000..63c6ae26a6 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java @@ -0,0 +1,97 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.itest.immutables.extras; + +import java.util.regex.Pattern; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.Name; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; + +/** + * @author Filip Hrisafov + */ +public class ImmutablesBuilderProvider extends DefaultBuilderProvider { + + private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + + @Override + protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + Name name = typeElement.getQualifiedName(); + if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { + return null; + } + TypeElement immutableAnnotation = elements.getTypeElement( "org.immutables.value.Value.Immutable" ); + if ( immutableAnnotation != null ) { + BuilderInfo info = findBuilderInfoForImmutables( + typeElement, + immutableAnnotation, + elements, + types + ); + if ( info != null ) { + return info; + } + } + + return super.findBuilderInfo( typeElement, elements, types ); + } + + protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, + TypeElement immutableAnnotation, Elements elements, Types types) { + for ( AnnotationMirror annotationMirror : elements.getAllAnnotationMirrors( typeElement ) ) { + if ( types.isSameType( annotationMirror.getAnnotationType(), immutableAnnotation.asType() ) ) { + TypeElement immutableElement = asImmutableElement( typeElement, elements ); + if ( immutableElement != null ) { + return super.findBuilderInfo( immutableElement, elements, types ); + } + else { + throw new TypeHierarchyErroneousException( typeElement ); + } + } + } + return null; + } + + private TypeElement asImmutableElement(TypeElement typeElement, Elements elements) { + Element enclosingElement = typeElement.getEnclosingElement(); + StringBuilder builderQualifiedName = new StringBuilder( typeElement.getQualifiedName().length() + 17 ); + if ( enclosingElement.getKind() == ElementKind.PACKAGE ) { + builderQualifiedName.append( ( (PackageElement) enclosingElement ).getQualifiedName().toString() ); + } + else { + builderQualifiedName.append( ( (TypeElement) enclosingElement ).getQualifiedName().toString() ); + } + + if ( builderQualifiedName.length() > 0 ) { + builderQualifiedName.append( "." ); + } + + builderQualifiedName.append( "Immutable" ).append( typeElement.getSimpleName() ); + return elements.getTypeElement( builderQualifiedName ); + } +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml new file mode 100644 index 0000000000..cbe79c972e --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + + immutablesIntegrationTest + org.mapstruct + 1.0.0 + + + itest-immutables-mapper + + + + + org.immutables + value + provided + + + org.mapstruct + itest-immutables-mapping-extras + 1.0.0 + + + \ No newline at end of file diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Address.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/AddressDto.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/Person.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonDto.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy new file mode 100644 index 0000000000..a908131ba1 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy @@ -0,0 +1,18 @@ +# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) +# and/or other contributors as indicated by the @authors tag. See the +# copyright.txt file in the distribution for a full listing of all +# contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +org.mapstruct.itest.immutables.extras.ImmutablesAccessorNamingStrategy diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider new file mode 100644 index 0000000000..2ab5dab768 --- /dev/null +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider @@ -0,0 +1,18 @@ +# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) +# and/or other contributors as indicated by the @authors tag. See the +# copyright.txt file in the distribution for a full listing of all +# contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +org.mapstruct.itest.immutables.extras.ImmutablesBuilderProvider diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java similarity index 100% rename from integrationtest/src/test/resources/immutablesBuilderTest/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java rename to integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml index 4906dc997d..19a738894d 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml @@ -30,13 +30,10 @@ immutablesIntegrationTest - jar - - - - org.immutables - value - provided - - + pom + + + extras + mapper + From c3f009969894bff86ed425428cf71a3c698ecbdf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 10 Feb 2018 17:40:33 +0100 Subject: [PATCH 0194/1006] #782 Do not use JDT for the Lombok integration tests Lombok uses internals of the Java and Eclipse compilers. In order for it to work with the Eclipse compiler, we need to add some extra jar. Therefore, we are only testing Lombok with the Java compiler --- .../java/org/mapstruct/itest/tests/LombokBuilderTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java index 133a4047b4..a86a1b805c 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java @@ -27,6 +27,12 @@ */ @RunWith( ProcessorSuiteRunner.class ) @ProcessorSuite( baseDir = "lombokBuilderTest", - processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) + processorTypes = { + ProcessorSuite.ProcessorType.ORACLE_JAVA_6, + ProcessorSuite.ProcessorType.ORACLE_JAVA_7, + ProcessorSuite.ProcessorType.ORACLE_JAVA_8, + ProcessorSuite.ProcessorType.ORACLE_JAVA_9, + } +) public class LombokBuilderTest { } From 06a49090cc321b33f5b47a9c86b7e87f32f10f1b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Feb 2018 13:38:51 +0100 Subject: [PATCH 0195/1006] #782 Nested target properties should work for builders as well --- .../ap/internal/model/source/TargetReference.java | 9 +++++---- .../builder/nestedprop/BuilderNestedPropertyTest.java | 6 ++++-- .../ap/test/builder/nestedprop/ExpandedTarget.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index e1824529c9..36306aa843 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -191,8 +191,9 @@ private List getTargetEntries(Type type, String[] entryNames) { // last entry for ( int i = 0; i < entryNames.length; i++ ) { - Accessor targetReadAccessor = nextType.getPropertyReadAccessors().get( entryNames[i] ); - Accessor targetWriteAccessor = nextType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); + Type mappingType = nextType.getMappingType(); + Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); + Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); boolean isLast = i == entryNames.length - 1; boolean isNotLast = i < entryNames.length - 1; if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast ) @@ -236,13 +237,13 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t if ( Executables.isGetterMethod( toUse ) || Executables.isFieldAccessor( toUse ) ) { nextType = typeFactory.getReturnType( - (DeclaredType) initial.getTypeMirror(), + (DeclaredType) initial.getMappingType().getTypeMirror(), toUse ); } else { nextType = typeFactory.getSingleParameter( - (DeclaredType) initial.getTypeMirror(), + (DeclaredType) initial.getMappingType().getTypeMirror(), toUse ).getType(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java index c673cb18dc..d4117ccfa0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java @@ -18,7 +18,6 @@ */ package org.mapstruct.ap.test.builder.nestedprop; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.WithClasses; @@ -36,7 +35,6 @@ FlattenedMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) -@Ignore("Nested target not working yet") public class BuilderNestedPropertyTest { @Test @@ -47,5 +45,9 @@ public void testNestedImmutablePropertyMapper() { 33 ) ); assertThat( expandedTarget ).isNotNull(); + assertThat( expandedTarget.getCount() ).isEqualTo( 33 ); + assertThat( expandedTarget.getSecond() ).isNull(); + assertThat( expandedTarget.getFirst() ).isNotNull(); + assertThat( expandedTarget.getFirst().getFoo() ).isEqualTo( "33" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java index 32be350071..d83d67f507 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java @@ -50,7 +50,7 @@ public static class Builder { private ImmutableTargetContainer first; private ImmutableTargetContainer second; - public Builder count(int age) { + public Builder count(int count) { this.count = count; return this; } From ee439d84c56b3fe55ba8c3072fd435365820cd49 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 25 Feb 2018 18:43:16 +0100 Subject: [PATCH 0196/1006] #782 Add javadoc to the new spi elements --- .../org/mapstruct/ap/spi/BuilderInfo.java | 28 ++++ .../org/mapstruct/ap/spi/BuilderProvider.java | 12 ++ .../ap/spi/DefaultBuilderProvider.java | 136 +++++++++++++++++- .../spi/TypeHierarchyErroneousException.java | 3 + 4 files changed, 176 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java index 24cbe36ead..9e6157688d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -21,6 +21,8 @@ import javax.lang.model.element.ExecutableElement; /** + * Holder for the builder information. + * * @author Filip Hrisafov */ public class BuilderInfo { @@ -33,10 +35,26 @@ private BuilderInfo(ExecutableElement builderCreationMethod, ExecutableElement b this.buildMethod = buildMethod; } + /** + * The method that can be used for instantiating a builder. This can be: + *

        + *
      • A {@code public static} method in the type being build
      • + *
      • A {@code public static} method in the builder itself
      • + *
      • The default constructor of the builder
      • + *
      + * + * @return the creation method for the builder + */ public ExecutableElement getBuilderCreationMethod() { return builderCreationMethod; } + /** + * The method that can be used to build the type being built. + * This should be a {@code public} method within the builder itself + * + * @return the build method for the type + */ public ExecutableElement getBuildMethod() { return buildMethod; } @@ -45,16 +63,26 @@ public static class Builder { private ExecutableElement builderCreationMethod; private ExecutableElement buildMethod; + /** + * @see BuilderInfo#getBuilderCreationMethod() + */ public Builder builderCreationMethod(ExecutableElement method) { this.builderCreationMethod = method; return this; } + /** + * @see BuilderInfo#getBuildMethod() + */ public Builder buildMethod(ExecutableElement method) { this.buildMethod = method; return this; } + /** + * Create the {@link BuilderInfo}. + * @throws IllegalArgumentException if the builder creation or build methods are {@code null} + */ public BuilderInfo build() { if ( builderCreationMethod == null ) { throw new IllegalArgumentException( "Builder creation method is mandatory" ); diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index 038578b690..96c3375433 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -29,5 +29,17 @@ */ public interface BuilderProvider { + /** + * Find the builder information, if any, for the {@code type}. + * + * @param type the type for which a builder should be found + * @param elements the util elements that can be used for operations on program elements + * @param types the util types that can be used for operations on {@link TypeMirror}(s) + * + * @return the builder info for the {@code type} if it exists, or {@code null} if there is no builder + * + * @throws TypeHierarchyErroneousException if the type that needs to be visited is not ready yet, this signals the + * MapStruct processor to postpone the generation of the mappers to the next round + */ BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index c1fb980d51..75b83f55ad 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -33,7 +33,53 @@ import javax.lang.model.util.Types; /** - * Default implementation of {@link BuilderProvider} + * Default implementation of {@link BuilderProvider}. + * + * The default builder provider considers all public static parameterless methods of a {@link TypeMirror} + * as potential builder creation methods. For each potential builder creation method checks in the return type + * of the method if there exists a method that returns the initial {@link TypeMirror} if such a combination is found + * the {@link BuilderInfo} is created with those 2 methods. + * Example: + *
      
      + * public class Person {
      + *
      + *     private final String firstName;
      + *     private final String lastName;
      + *
      + *     private Person(String firstName, String lastName) {
      + *         this.firstName = firstName;
      + *         this.lastName = lastName;
      + *     }
      + *
      + *     //getters
      + *
      + *     public static Builder builder() {
      + *         return new Builder();
      + *     }
      +
      + *     public static class Builder {
      + *
      + *         private String firstName;
      + *         private String lastName;
      + *
      + *         private Builder() {}
      + *
      + *         //fluent setters
      + *
      + *         public Person create() {
      + *             return new Person( firstName, lastName );
      + *         }
      + *     }
      + * }
      + * 
      + * + * In the example above, when searching for a builder for the {@code Person} type. The {@code Person#builder} method + * would be a builder creation candidate. Then the return type of {@code Person#builder}, {@code Builder}, is + * investigated for a parameterless method that returns {@code Person}. When {@code Builder#create} is found + * the {@link BuilderInfo} is created with the {@code Person#builder} as a builder creation method and + * {@code Builder#create} as a build method. + *

      + * IMPORTANT: Types from the {@code java} and {@code javax} packages are excluded from inspection * * @author Filip Hrisafov */ @@ -51,6 +97,16 @@ public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types typ return findBuilderInfo( typeElement, elements, types ); } + /** + * Find the {@link TypeElement} for the given {@link TypeMirror}. + * + * @param type for which the {@link TypeElement} needs to be found/ + * + * @return the type element or {@code null} if the {@link TypeMirror} is not a {@link DeclaredType} + * and the declared type element is not {@link TypeElement} + * + * @throws TypeHierarchyErroneousException if the {@link TypeMirror} is of kind {@link TypeKind#ERROR} + */ protected TypeElement getTypeElement(TypeMirror type) { if ( type.getKind() == TypeKind.ERROR ) { throw new TypeHierarchyErroneousException( type ); @@ -80,6 +136,23 @@ public TypeElement visitType(TypeElement e, Void p) { ); } + /** + * Find the {@link BuilderInfo} for the given {@code typeElement}. + *

      + * The default implementation iterates over all the methods in {@code typeElement} and uses + * {@link DefaultBuilderProvider#isPossibleBuilderCreationMethod(ExecutableElement, TypeElement, Types)} and + * {@link DefaultBuilderProvider#findBuildMethod(TypeElement, TypeElement, Types)} to create the + * {@link BuilderInfo}. + *

      + * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the + * {@code typeElement} should be ignored. + * + * @param typeElement the type element for which a builder searched + * @param elements the util elements that can be used for operating on the type element + * @param types the util types that can be used for operation on {@link TypeMirror}(s) + * + * @return the {@link BuilderInfo} or {@code null} if no builder was found for the type + */ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { if ( shouldIgnore( typeElement ) ) { return null; @@ -101,6 +174,23 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements return findBuilderInfo( typeElement.getSuperclass(), elements, types ); } + /** + * Checks if the {@code method} is a possible builder creation method. + *

      + * The default implementation considers a method as a possible creation method if the following is satisfied: + *

        + *
      • The method has no parameters
      • + *
      • It is a {@code public static} method
      • + *
      • The return type of the {@code method} is not the same as the {@code typeElement}
      • + *
      • + *
      + * + * @param method The method that needs to be checked + * @param typeElement the enclosing element of the method, i.e. the type in which the method is located in + * @param types the util types that can be used for operations on {@link TypeMirror}(s) + * + * @return {@code true} if the {@code method} is a possible builder creation method, {@code false} otherwise + */ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, TypeElement typeElement, Types types) { return method.getParameters().isEmpty() && method.getModifiers().contains( Modifier.PUBLIC ) @@ -108,6 +198,22 @@ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, Type && !types.isSameType( method.getReturnType(), typeElement.asType() ); } + /** + * Searches for a build method for {@code typeElement} within the {@code builderElement}. + *

      + * The default implementation iterates over each method in {@code builderElement} and uses + * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement, Types)} to check if the method is a + * build method for {@code typeElement}. + *

      + * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the + * {@code builderElement} should be ignored, i.e. not checked for build elements. + * + * @param builderElement the element for the builder + * @param typeElement the element for the type that is being built + * @param types the util types tat can be used for operations on {@link TypeMirror}(s) + * + * @return the build method for the {@code typeElement} if it exists, or {@code null} if it does not + */ protected ExecutableElement findBuildMethod(TypeElement builderElement, TypeElement typeElement, Types types) { if ( shouldIgnore( builderElement ) ) { return null; @@ -127,13 +233,37 @@ protected ExecutableElement findBuildMethod(TypeElement builderElement, TypeElem ); } - protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement, - Types types) { + /** + * Checks if the {@code buildMethod} is a method that creates {@code typeElement}. + *

      + * The default implementation considers a method to be a build method if the following is satisfied: + *

        + *
      • The method has no parameters
      • + *
      • The method is public
      • + *
      • The return type of method is assignable to the {@code typeElement}
      • + *
      + * + * @param buildMethod the method that should be checked + * @param typeElement the type element that needs to be built + * @param types the util types that can be used for operations on {@link TypeMirror}(s) + * + * @return {@code true} if the {@code buildMethod} is a build method for {@code typeElement}, {@code false} + * otherwise + */ + protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement, Types types) { return buildMethod.getParameters().isEmpty() && buildMethod.getModifiers().contains( Modifier.PUBLIC ) && types.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); } + /** + * Whether the {@code typeElement} should be ignored, i.e. not used in inspection. + *

      + * The default implementations ignores {@code null} elements and elements that belong to the {@code java} and + * {@code javax} packages + * @param typeElement that needs to be checked + * @return {@code true} if the element should be ignored, {@code false} otherwise + */ protected boolean shouldIgnore(TypeElement typeElement) { return typeElement == null || JAVA_JAVAX_PACKAGE.matcher( typeElement.getQualifiedName() ).matches(); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java index e4c975b171..c79ff31d01 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java @@ -23,6 +23,9 @@ /** * Indicates a type was visited whose hierarchy was erroneous, because it has a non-existing super-type. + *

      + * This exception can be used to signal the MapStruct processor to postpone the generation of the mappers to the next + * round * * @author Gunnar Morling */ From 2b9fdac7f7671ec110fce0d03f9b1d9ff26eea0e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 25 Feb 2018 19:20:28 +0100 Subject: [PATCH 0197/1006] #782 Wording cleanup after PR review --- .../ap/internal/model/BeanMappingMethod.java | 32 +++++++++-------- .../ap/internal/model/PropertyMapping.java | 2 +- .../ap/internal/model/common/BuilderType.java | 36 ++++++++++++++++--- .../ap/internal/model/common/Type.java | 6 +++- .../model/source/TargetReference.java | 8 ++--- .../processor/MethodRetrievalProcessor.java | 2 +- .../creation/MappingResolverImpl.java | 5 ++- .../ap/internal/model/BeanMappingMethod.ftl | 6 ++-- 8 files changed, 66 insertions(+), 31 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 29cba8dbb8..7eaf9f6599 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -77,7 +77,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final Map> mappingsByParameter; private final List constantMappings; private final Type resultType; - private final MethodReference finalizeMethod; + private final MethodReference finalizerMethod; public static class Builder { @@ -114,7 +114,9 @@ private Builder setupMethodWithMapping(Method sourceMethod) { this.method = sourceMethod; this.methodMappings = sourceMethod.getMappingOptions().getMappings(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); - Map accessors = method.getResultType().getMappingType().getPropertyWriteAccessors( cms ); + Map accessors = method.getResultType() + .getEffectiveType() + .getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); this.unprocessedTargetProperties = new LinkedHashMap( accessors ); @@ -186,7 +188,7 @@ public BeanMappingMethod build() { Type resultType = null; if ( factoryMethod == null ) { if ( selectionParameters != null && selectionParameters.getResultType() != null ) { - resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getMappingType(); + resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getEffectiveType(); if ( resultType.isAbstract() ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -212,19 +214,19 @@ else if ( !resultType.hasEmptyAccessibleContructor() ) { ); } } - else if ( !method.isUpdateMethod() && method.getReturnType().getMappingType().isAbstract() ) { + else if ( !method.isUpdateMethod() && method.getReturnType().getEffectiveType().isAbstract() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_ABSTRACT_RETURN_TYPE, - method.getReturnType().getMappingType() + method.getReturnType().getEffectiveType() ); } else if ( !method.isUpdateMethod() && - !method.getReturnType().getMappingType().hasEmptyAccessibleContructor() ) { + !method.getReturnType().getEffectiveType().hasEmptyAccessibleContructor() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - method.getReturnType().getMappingType() + method.getReturnType().getEffectiveType() ); } } @@ -244,7 +246,7 @@ else if ( !method.isUpdateMethod() && ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); } - MethodReference finalizeMethod = getFinalizeMethod( + MethodReference finalizeMethod = getFinalizerMethod( resultType == null ? method.getReturnType() : resultType ); return new BeanMappingMethod( @@ -260,9 +262,9 @@ else if ( !method.isUpdateMethod() && ); } - private MethodReference getFinalizeMethod(Type resultType) { + private MethodReference getFinalizerMethod(Type resultType) { if ( method.getReturnType().isVoid() || - resultType.getMappingType().isAssignableTo( resultType ) ) { + resultType.getEffectiveType().isAssignableTo( resultType ) ) { return null; } BuilderType builderType = resultType.getBuilderType(); @@ -808,7 +810,7 @@ private BeanMappingMethod(Method method, Type resultType, List beforeMappingReferences, List afterMappingReferences, - MethodReference finalizeMethod) { + MethodReference finalizerMethod) { super( method, existingVariableNames, @@ -819,7 +821,7 @@ private BeanMappingMethod(Method method, ); this.propertyMappings = propertyMappings; - this.finalizeMethod = finalizeMethod; + this.finalizerMethod = finalizerMethod; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. @@ -861,8 +863,8 @@ public Type getResultType() { } } - public MethodReference getFinalizeMethod() { - return finalizeMethod; + public MethodReference getFinalizerMethod() { + return finalizerMethod; } @Override @@ -873,7 +875,7 @@ public Set getImportTypes() { types.addAll( propertyMapping.getImportTypes() ); } - types.add( getResultType().getMappingType() ); + types.add( getResultType().getEffectiveType() ); return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index f6e750b07a..9f10ab2b40 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -148,7 +148,7 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { private Type determineTargetType() { // This is a bean mapping method, so we know the result is a declared type - DeclaredType resultType = (DeclaredType) method.getResultType().getMappingType().getTypeMirror(); + DeclaredType resultType = (DeclaredType) method.getResultType().getEffectiveType().getTypeMirror(); switch ( targetWriteAccessorType ) { case ADDER: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 36e4c5f8ea..25ed3beae0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -30,41 +30,67 @@ public class BuilderType { private final Type builder; - private final Type owner; + private final Type owningType; private final Type buildingType; private final ExecutableElement builderCreationMethod; private final ExecutableElement buildMethod; private BuilderType( Type builder, - Type owner, + Type owningType, Type buildingType, ExecutableElement builderCreationMethod, ExecutableElement buildMethod ) { this.builder = builder; - this.owner = owner; + this.owningType = owningType; this.buildingType = buildingType; this.builderCreationMethod = builderCreationMethod; this.buildMethod = buildMethod; } + /** + * The type of the builder itself. + * + * @return the type for the builder + */ public Type getBuilder() { return builder; } - public Type getOwner() { - return owner; + /** + * The owning type of the builder, this can be the builder itself, the type that is build by the builder or some + * other type. + * + * @return the owning type + */ + public Type getOwningType() { + return owningType; } + /** + * The type that is being built by the builder. + * + * @return the type that is being built + */ public Type getBuildingType() { return buildingType; } + /** + * The creation method for the builder. + * + * @return the creation method for the builder + */ public ExecutableElement getBuilderCreationMethod() { return builderCreationMethod; } + /** + * The name of the method that needs to be invoked on the builder to create the type being built. + * + * @return the name of the method that needs to be invoked on the type that is being built + */ public String getBuildMethod() { return buildMethod.getSimpleName().toString(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ee7b7b445e..0f88cc81a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -182,7 +182,11 @@ public BuilderType getBuilderType() { return builderType; } - public Type getMappingType() { + /** + * The effective type that should be used when searching for getters / setters, creating new types etc + * @return the effective type for mappings + */ + public Type getEffectiveType() { return builderType != null ? builderType.getBuilder() : this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 36306aa843..fc9da48695 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -153,7 +153,7 @@ public TargetReference build() { boolean foundEntryMatch; Type resultType = method.getResultType(); - resultType = resultType.getMappingType(); + resultType = resultType.getEffectiveType(); // there can be 4 situations // 1. Return type @@ -191,7 +191,7 @@ private List getTargetEntries(Type type, String[] entryNames) { // last entry for ( int i = 0; i < entryNames.length; i++ ) { - Type mappingType = nextType.getMappingType(); + Type mappingType = nextType.getEffectiveType(); Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); boolean isLast = i == entryNames.length - 1; @@ -237,13 +237,13 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t if ( Executables.isGetterMethod( toUse ) || Executables.isFieldAccessor( toUse ) ) { nextType = typeFactory.getReturnType( - (DeclaredType) initial.getMappingType().getTypeMirror(), + (DeclaredType) initial.getEffectiveType().getTypeMirror(), toUse ); } else { nextType = typeFactory.getSingleParameter( - (DeclaredType) initial.getMappingType().getTypeMirror(), + (DeclaredType) initial.getEffectiveType().getTypeMirror(), toUse ).getType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 9a4d469b20..19e3d538f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -410,7 +410,7 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List <#if !existingInstanceMapping> - <@includeModel object=resultType.mappingType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.mappingType/><#else>new <@includeModel object=resultType.mappingType/>(); + <@includeModel object=resultType.effectiveType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.effectiveType/><#else>new <@includeModel object=resultType.effectiveType/>(); <#list beforeMappingReferencesWithMappingTarget as callback> @@ -78,8 +78,8 @@ <#if returnType.name != "void"> - <#if finalizeMethod??> - return ${resultName}.<@includeModel object=finalizeMethod />; + <#if finalizerMethod??> + return ${resultName}.<@includeModel object=finalizerMethod />; <#else> return ${resultName}; From 73711cc6837bc20394d612759f3de66764300c5d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 25 Feb 2018 21:58:05 +0100 Subject: [PATCH 0198/1006] #782 Rename Lombok Integration test classes --- .../abstractBuilder/AbstractBuilderTest.java | 28 ++++++------ ...get.java => AbstractImmutableProduct.java} | 12 ++--- ...ilder.java => AbstractProductBuilder.java} | 8 ++-- ...tableTarget.java => ImmutableProduct.java} | 28 ++++++------ .../{Target.java => Product.java} | 6 +-- .../{Source.java => ProductDto.java} | 30 ++++++------- ...leTargetMapper.java => ProductMapper.java} | 8 ++-- ... => AbstractGenericTargetBuilderTest.java} | 44 ++++++++++++------- .../{AbstractChildTarget.java => Child.java} | 4 +- .../abstractGenericTarget/ChildSource.java | 14 +++--- ...ildTargetImpl.java => ImmutableChild.java} | 26 +++++------ ...ntTargetImpl.java => ImmutableParent.java} | 36 +++++++-------- ...ChildTargetImpl.java => MutableChild.java} | 12 ++--- ...rentTargetImpl.java => MutableParent.java} | 22 +++++----- ...{AbstractParentTarget.java => Parent.java} | 6 +-- ...actTargetMapper.java => ParentMapper.java} | 12 ++--- .../abstractGenericTarget/ParentSource.java | 20 ++++----- ...getTest.java => ImmutableProductTest.java} | 2 +- ...yTest.java => ProductTypeFactoryTest.java} | 2 +- ....java => NestedProductPropertiesTest.java} | 2 +- ...rgetTest.java => UnmappedProductTest.java} | 2 +- 21 files changed, 167 insertions(+), 157 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{AbstractImmutableTarget.java => AbstractImmutableProduct.java} (77%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{AbstractTargetBuilder.java => AbstractProductBuilder.java} (83%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{ImmutableTarget.java => ImmutableProduct.java} (59%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{Target.java => Product.java} (92%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{Source.java => ProductDto.java} (66%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/{ImmutableTargetMapper.java => ProductMapper.java} (80%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{AbstractTargetBuilderTest.java => AbstractGenericTargetBuilderTest.java} (56%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{AbstractChildTarget.java => Child.java} (93%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{ImmutableChildTargetImpl.java => ImmutableChild.java} (61%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{ImmutableParentTargetImpl.java => ImmutableParent.java} (58%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{MutableChildTargetImpl.java => MutableChild.java} (81%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{MutableParentTargetImpl.java => MutableParent.java} (64%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{AbstractParentTarget.java => Parent.java} (86%) rename processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/{AbstractTargetMapper.java => ParentMapper.java} (74%) rename processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/{ImmutableTargetTest.java => ImmutableProductTest.java} (98%) rename processor/src/test/java/org/mapstruct/ap/test/factories/targettype/{TargetTypeFactoryTest.java => ProductTypeFactoryTest.java} (98%) rename processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/{NestedTargetPropertiesTest.java => NestedProductPropertiesTest.java} (99%) rename processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/{UnmappedTargetTest.java => UnmappedProductTest.java} (99%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java index cba7830a83..94ccde4b89 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java @@ -30,12 +30,12 @@ * builder class, and some of the properties are written by the concrete builder implementation. */ @WithClasses({ - Target.class, - AbstractTargetBuilder.class, - AbstractImmutableTarget.class, - ImmutableTarget.class, - Source.class, - ImmutableTargetMapper.class + Product.class, + AbstractProductBuilder.class, + AbstractImmutableProduct.class, + ImmutableProduct.class, + ProductDto.class, + ProductMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) public class AbstractBuilderTest { @@ -51,20 +51,20 @@ public class AbstractBuilderTest { */ @Test public void testThatAbstractBuilderMapsAllProperties() { - ImmutableTarget sourceOne = ImmutableTargetMapper.INSTANCE.fromMutable( new Source( "foo", 31 ) ); + ImmutableProduct product = ProductMapper.INSTANCE.fromMutable( new ProductDto( "router", 31 ) ); - assertThat( sourceOne.getBar() ).isEqualTo( 31 ); - assertThat( sourceOne.getFoo() ).isEqualTo( "foo" ); + assertThat( product.getPrice() ).isEqualTo( 31 ); + assertThat( product.getName() ).isEqualTo( "router" ); } @Test public void testThatAbstractBuilderReverseMapsAllProperties() { - Source sourceOne = ImmutableTargetMapper.INSTANCE.fromImmutable( ImmutableTarget.builder() - .bar( 31 ) - .foo( "foo" ) + ProductDto product = ProductMapper.INSTANCE.fromImmutable( ImmutableProduct.builder() + .price( 31000 ) + .name( "car" ) .build() ); - assertThat( sourceOne.getBar() ).isEqualTo( 31 ); - assertThat( sourceOne.getFoo() ).isEqualTo( "foo" ); + assertThat( product.getPrice() ).isEqualTo( 31000 ); + assertThat( product.getName() ).isEqualTo( "car" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java similarity index 77% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java index 6c59b4b5a8..4be4ab3cae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java @@ -21,15 +21,15 @@ /** * @author Filip Hrisafov */ -public abstract class AbstractImmutableTarget implements Target { +public abstract class AbstractImmutableProduct implements Product { - private final String foo; + private final String name; - public AbstractImmutableTarget(AbstractTargetBuilder builder) { - this.foo = builder.foo; + public AbstractImmutableProduct(AbstractProductBuilder builder) { + this.name = builder.name; } - public String getFoo() { - return foo; + public String getName() { + return name; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java similarity index 83% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java index 4869dbe36f..b462b67759 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractTargetBuilder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java @@ -18,12 +18,12 @@ */ package org.mapstruct.ap.test.builder.abstractBuilder; -public abstract class AbstractTargetBuilder { +public abstract class AbstractProductBuilder { - protected String foo; + protected String name; - public AbstractTargetBuilder foo(String foo) { - this.foo = foo; + public AbstractProductBuilder name(String name) { + this.name = name; return this; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java similarity index 59% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java index a09cfedf5f..9745673ec6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java @@ -18,35 +18,35 @@ */ package org.mapstruct.ap.test.builder.abstractBuilder; -public class ImmutableTarget extends AbstractImmutableTarget { +public class ImmutableProduct extends AbstractImmutableProduct { - private final Integer bar; + private final Integer price; - public ImmutableTarget(ImmutableTargetBuilder builder) { + public ImmutableProduct(ImmutableProductBuilder builder) { super( builder ); - this.bar = builder.bar; + this.price = builder.price; } - public static ImmutableTargetBuilder builder() { - return new ImmutableTargetBuilder(); + public static ImmutableProductBuilder builder() { + return new ImmutableProductBuilder(); } @Override - public Integer getBar() { - return bar; + public Integer getPrice() { + return price; } - public static class ImmutableTargetBuilder extends AbstractTargetBuilder { - private Integer bar; + public static class ImmutableProductBuilder extends AbstractProductBuilder { + private Integer price; - public ImmutableTargetBuilder bar(Integer bar) { - this.bar = bar; + public ImmutableProductBuilder price(Integer price) { + this.price = price; return this; } @Override - public ImmutableTarget build() { - return new ImmutableTarget( this ); + public ImmutableProduct build() { + return new ImmutableProduct( this ); } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java similarity index 92% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java index 855cf5b1fd..b8b8197407 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java @@ -18,8 +18,8 @@ */ package org.mapstruct.ap.test.builder.abstractBuilder; -public interface Target { - String getFoo(); +public interface Product { + String getName(); - Integer getBar(); + Integer getPrice(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java similarity index 66% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java index b7e57cec64..30b4c9d8a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java @@ -18,31 +18,31 @@ */ package org.mapstruct.ap.test.builder.abstractBuilder; -public class Source { - private String foo; - private Integer bar; +public class ProductDto { + private String name; + private Integer price; - public Source() { + public ProductDto() { } - public Source(String foo, Integer bar) { - this.foo = foo; - this.bar = bar; + public ProductDto(String name, Integer price) { + this.name = name; + this.price = price; } - public String getFoo() { - return foo; + public String getName() { + return name; } - public void setFoo(String foo) { - this.foo = foo; + public void setName(String name) { + this.name = name; } - public Integer getBar() { - return bar; + public Integer getPrice() { + return price; } - public void setBar(Integer bar) { - this.bar = bar; + public void setPrice(Integer price) { + this.price = price; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java similarity index 80% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java index f41bfe3c71..937935a377 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java @@ -22,11 +22,11 @@ import org.mapstruct.factory.Mappers; @Mapper -public interface ImmutableTargetMapper { +public interface ProductMapper { - ImmutableTargetMapper INSTANCE = Mappers.getMapper( ImmutableTargetMapper.class ); + ProductMapper INSTANCE = Mappers.getMapper( ProductMapper.class ); - ImmutableTarget fromMutable(Source source); + ImmutableProduct fromMutable(ProductDto source); - Source fromImmutable(ImmutableTarget source); + ProductDto fromImmutable(ImmutableProduct source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java similarity index 56% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java index 02e751078f..cf3913c179 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java @@ -18,44 +18,54 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * Verifies that abstract builders work when mapping to an abstract property type. */ @WithClasses({ - AbstractChildTarget.class, - AbstractParentTarget.class, + Child.class, + Parent.class, ChildSource.class, - ImmutableChildTargetImpl.class, - ImmutableParentTargetImpl.class, - MutableChildTargetImpl.class, - MutableParentTargetImpl.class, + ImmutableChild.class, + ImmutableParent.class, + MutableChild.class, + MutableParent.class, ParentSource.class, - AbstractTargetMapper.class + ParentMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) -public class AbstractTargetBuilderTest { +public class AbstractGenericTargetBuilderTest { @Test public void testAbstractTargetMapper() { ParentSource parent = new ParentSource(); parent.setCount( 4 ); - parent.setNested( new ChildSource( "Phineas" ) ); + parent.setChild( new ChildSource( "Phineas" ) ); + parent.setNonGenericChild( new ChildSource( "Ferb" ) ); // transform - AbstractParentTarget immutableTarget = AbstractTargetMapper.INSTANCE.toImmutable( parent ); - AbstractParentTarget mutableTarget = AbstractTargetMapper.INSTANCE.toMutable( parent ); + Parent immutableParent = ParentMapper.INSTANCE.toImmutable( parent ); + assertThat( immutableParent.getCount() ).isEqualTo( 4 ); + assertThat( immutableParent.getChild().getName() ).isEqualTo( "Phineas" ); + assertThat( immutableParent.getNonGenericChild() ) + .isNotNull() + .isInstanceOf( ImmutableChild.class ); + assertThat( immutableParent.getNonGenericChild().getName() ).isEqualTo( "Ferb" ); + + Parent mutableParent = ParentMapper.INSTANCE.toMutable( parent ); - assertThat( mutableTarget.getCount() ).isEqualTo( 4 ); - assertThat( mutableTarget.getNested().getBar() ).isEqualTo( "Phineas" ); + assertThat( mutableParent.getCount() ).isEqualTo( 4 ); + assertThat( mutableParent.getChild().getName() ).isEqualTo( "Phineas" ); + assertThat( mutableParent.getNonGenericChild() ) + .isNotNull() + .isInstanceOf( ImmutableChild.class ); + assertThat( mutableParent.getNonGenericChild().getName() ).isEqualTo( "Ferb" ); - assertThat( immutableTarget.getCount() ).isEqualTo( 4 ); - assertThat( immutableTarget.getNested().getBar() ).isEqualTo( "Phineas" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java similarity index 93% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java index 0d8e5c2905..306d4b1b61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractChildTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java @@ -18,6 +18,6 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public interface AbstractChildTarget { - String getBar(); +public interface Child { + String getName(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java index 704c809d07..1884f8cef4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java @@ -19,20 +19,20 @@ package org.mapstruct.ap.test.builder.abstractGenericTarget; public class ChildSource { - private String bar; + private String name; public ChildSource() { } - public ChildSource(String bar) { - this.bar = bar; + public ChildSource(String name) { + this.name = name; } - public String getBar() { - return bar; + public String getName() { + return name; } - public void setBar(String bar) { - this.bar = bar; + public void setName(String name) { + this.name = name; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java similarity index 61% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java index 67bb62546c..becdb4fab1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChildTargetImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java @@ -18,31 +18,31 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public class ImmutableChildTargetImpl implements AbstractChildTarget { - private final String bar; +public class ImmutableChild implements Child { + private final String name; - private ImmutableChildTargetImpl(ImmutableChildTargetImpl.Builder builder) { - this.bar = builder.bar; + private ImmutableChild(ImmutableChild.Builder builder) { + this.name = builder.name; } - public static ImmutableChildTargetImpl.Builder builder() { - return new ImmutableChildTargetImpl.Builder(); + public static ImmutableChild.Builder builder() { + return new ImmutableChild.Builder(); } - public String getBar() { - return bar; + public String getName() { + return name; } public static class Builder { - private String bar; + private String name; - public ImmutableChildTargetImpl.Builder bar(String bar) { - this.bar = bar; + public ImmutableChild.Builder name(String name) { + this.name = name; return this; } - public ImmutableChildTargetImpl build() { - return new ImmutableChildTargetImpl( this ); + public ImmutableChild build() { + return new ImmutableChild( this ); } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java similarity index 58% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java index 6973943cca..392ccbf979 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParentTargetImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java @@ -18,15 +18,15 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public class ImmutableParentTargetImpl implements AbstractParentTarget { +public class ImmutableParent implements Parent { private final int count; - private final ImmutableChildTargetImpl nested; - private final AbstractChildTarget nonGenericizedNested; + private final ImmutableChild child; + private final Child nonGenericChild; - public ImmutableParentTargetImpl(Builder builder) { + public ImmutableParent(Builder builder) { this.count = builder.count; - this.nested = builder.nested; - this.nonGenericizedNested = builder.nonGenericizedNested; + this.child = builder.child; + this.nonGenericChild = builder.nonGenericChild; } public static Builder builder() { @@ -34,8 +34,8 @@ public static Builder builder() { } @Override - public AbstractChildTarget getNonGenericizedNested() { - return nonGenericizedNested; + public Child getNonGenericChild() { + return nonGenericChild; } @Override @@ -44,32 +44,32 @@ public int getCount() { } @Override - public ImmutableChildTargetImpl getNested() { - return nested; + public ImmutableChild getChild() { + return child; } public static class Builder { private int count; - private ImmutableChildTargetImpl nested; - private AbstractChildTarget nonGenericizedNested; + private ImmutableChild child; + private Child nonGenericChild; public Builder count(int count) { this.count = count; return this; } - public Builder nonGenericizedNested(AbstractChildTarget nonGenericizedNested) { - this.nonGenericizedNested = nonGenericizedNested; + public Builder nonGenericChild(Child nonGenericChild) { + this.nonGenericChild = nonGenericChild; return this; } - public Builder nested(ImmutableChildTargetImpl nested) { - this.nested = nested; + public Builder child(ImmutableChild child) { + this.child = child; return this; } - public ImmutableParentTargetImpl build() { - return new ImmutableParentTargetImpl( this ); + public ImmutableParent build() { + return new ImmutableParent( this ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java similarity index 81% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java index 136958f044..3232ce89d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChildTargetImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java @@ -18,15 +18,15 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public class MutableChildTargetImpl implements AbstractChildTarget { - private String bar; +public class MutableChild implements Child { + private String name; @Override - public String getBar() { - return null; + public String getName() { + return name; } - public void setBar(String bar) { - this.bar = bar; + public void setName(String name) { + this.name = name; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java similarity index 64% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java index 7ddead8550..c8ba05e371 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParentTargetImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java @@ -18,10 +18,10 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public class MutableParentTargetImpl implements AbstractParentTarget { +public class MutableParent implements Parent { private int count; - private ImmutableChildTargetImpl nested; - private AbstractChildTarget nonGenericizedNested; + private ImmutableChild child; + private Child nonGenericChild; @Override public int getCount() { @@ -33,20 +33,20 @@ public void setCount(int count) { } @Override - public ImmutableChildTargetImpl getNested() { - return nested; + public ImmutableChild getChild() { + return child; } - public void setNested(ImmutableChildTargetImpl nested) { - this.nested = nested; + public void setChild(ImmutableChild child) { + this.child = child; } @Override - public AbstractChildTarget getNonGenericizedNested() { - return nonGenericizedNested; + public Child getNonGenericChild() { + return nonGenericChild; } - public void setNonGenericizedNested(AbstractChildTarget nonGenericizedNested) { - this.nonGenericizedNested = nonGenericizedNested; + public void setNonGenericChild(Child nonGenericChild) { + this.nonGenericChild = nonGenericChild; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java index 5fa08e4cb8..5bc5c8d448 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractParentTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java @@ -18,10 +18,10 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -public interface AbstractParentTarget { +public interface Parent { int getCount(); - T getNested(); + T getChild(); - AbstractChildTarget getNonGenericizedNested(); + Child getNonGenericChild(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java index a1e5217aec..372f34dc01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java @@ -22,18 +22,18 @@ import org.mapstruct.factory.Mappers; @Mapper -public interface AbstractTargetMapper { +public interface ParentMapper { - AbstractTargetMapper INSTANCE = Mappers.getMapper( AbstractTargetMapper.class ); + ParentMapper INSTANCE = Mappers.getMapper( ParentMapper.class ); - ImmutableParentTargetImpl toImmutable(ParentSource parentSource); + ImmutableParent toImmutable(ParentSource parentSource); - MutableParentTargetImpl toMutable(ParentSource parentSource); + MutableParent toMutable(ParentSource parentSource); /** - * This method allows mapstruct to successfully write to {@link ImmutableParentTargetImpl#nonGenericizedNested} + * This method allows mapstruct to successfully write to {@link ImmutableParent#nonGenericChild} * by providing a concrete class to convert to. */ - ImmutableChildTargetImpl toChild(ChildSource child); + ImmutableChild toChild(ChildSource child); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java index 4470547c0c..bf0f378bbb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java @@ -20,15 +20,15 @@ public class ParentSource { private int count; - private ChildSource nested; - private ChildSource nonGenericizedNested; + private ChildSource child; + private ChildSource nonGenericChild; - public ChildSource getNonGenericizedNested() { - return nonGenericizedNested; + public ChildSource getNonGenericChild() { + return nonGenericChild; } - public void setNonGenericizedNested(ChildSource nonGenericizedNested) { - this.nonGenericizedNested = nonGenericizedNested; + public void setNonGenericChild(ChildSource nonGenericChild) { + this.nonGenericChild = nonGenericChild; } public int getCount() { @@ -39,11 +39,11 @@ public void setCount(int count) { this.count = count; } - public ChildSource getNested() { - return nested; + public ChildSource getChild() { + return child; } - public void setNested(ChildSource nested) { - this.nested = nested; + public void setChild(ChildSource child) { + this.child = child; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java similarity index 98% rename from processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java rename to processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index 5d331a4f8e..15561a43dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -39,7 +39,7 @@ @RunWith(AnnotationProcessorTestRunner.class) @WithClasses({CupboardDto.class, CupboardEntity.class, CupboardMapper.class}) @IssueKey( "1126" ) -public class ImmutableTargetTest { +public class ImmutableProductTest { @Test public void shouldHandleImmutableTarget() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java similarity index 98% rename from processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTest.java rename to processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java index c0b6217f23..4e61915d19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java @@ -31,7 +31,7 @@ @WithClasses( { Foo9Base.class, Foo9Child.class, Bar9Base.class, Bar9Child.class, Bar9Factory.class, TargetTypeFactoryTestMapper.class } ) @RunWith( AnnotationProcessorTestRunner.class ) -public class TargetTypeFactoryTest { +public class ProductTypeFactoryTest { @Test public void shouldUseFactoryTwoCreateBaseClassDueToTargetType() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java similarity index 99% rename from processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java rename to processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java index c1976d656d..012afbff9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java @@ -50,7 +50,7 @@ } ) @IssueKey("389") @RunWith(AnnotationProcessorTestRunner.class) -public class NestedTargetPropertiesTest { +public class NestedProductPropertiesTest { @Rule public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java similarity index 99% rename from processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedTargetTest.java rename to processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index cc5de42acf..b02a5d8d68 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -39,7 +39,7 @@ */ @IssueKey("35") @RunWith(AnnotationProcessorTestRunner.class) -public class UnmappedTargetTest { +public class UnmappedProductTest { @Test @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) From 6291631af7ebb97777ef1c1b3188540b76f4eeb7 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Mar 2018 13:12:14 +0100 Subject: [PATCH 0199/1006] #782 Adding negative test for @MappingTarget with immutable classes --- .../processor/MethodRetrievalProcessor.java | 5 ++++ .../mapstruct/ap/internal/util/Message.java | 1 + .../abstractBuilder/AbstractBuilderTest.java | 1 - .../AbstractImmutableProduct.java | 2 +- .../AbstractProductBuilder.java | 2 +- .../abstractBuilder/ImmutableProduct.java | 1 - .../test/builder/abstractBuilder/Product.java | 25 ------------------- .../simple/BuilderInfoTargetTest.java | 17 +++++++++++++ ...java => ErroneousSimpleBuilderMapper.java} | 5 ++-- 9 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java rename processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/{InvalidSimpleBuilderMapper.java => ErroneousSimpleBuilderMapper.java} (83%) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 19e3d538f5..6dfed43c52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -403,6 +403,11 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List { +public abstract class AbstractProductBuilder { protected String name; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java index 9745673ec6..77aeed710a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java @@ -31,7 +31,6 @@ public static ImmutableProductBuilder builder() { return new ImmutableProductBuilder(); } - @Override public Integer getPrice() { return price; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java deleted file mode 100644 index b8b8197407..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/Product.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.test.builder.abstractBuilder; - -public interface Product { - String getName(); - - Integer getPrice(); -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java index 83976f1a42..fa8c7d9c88 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -26,6 +26,9 @@ import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @WithClasses({ SimpleMutableSource.class, @@ -50,4 +53,18 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getAge() ).isEqualTo( 3 ); assertThat( targetObject.getName() ).isEqualTo( "Bob" ); } + + @WithClasses(ErroneousSimpleBuilderMapper.class) + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousSimpleBuilderMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + messageRegExp = "^Can't generate mapping method when @MappingTarget is supposed to be immutable " + + "\\(has a builder\\)\\.$") + }) + public void shouldFailCannotModifyImmutable() { + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/ErroneousSimpleBuilderMapper.java similarity index 83% rename from processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/ErroneousSimpleBuilderMapper.java index 519fb64de3..9776c0ecf9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/InvalidSimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/ErroneousSimpleBuilderMapper.java @@ -19,8 +19,9 @@ package org.mapstruct.ap.test.builder.mappingTarget.simple; import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; @Mapper -public interface InvalidSimpleBuilderMapper { - SimpleImmutableTarget toImmutable(SimpleMutableSource source); +public interface ErroneousSimpleBuilderMapper { + void toImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget target); } From 998d6fc35fbb903be1706ee018216f34ffb68bd8 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Mar 2018 15:58:16 +0100 Subject: [PATCH 0200/1006] #782 Add tests with expressions and constants --- .../simple/ErroneousSimpleBuilderMapper.java | 8 ++++- .../builder/simple/SimpleBuilderMapper.java | 9 ++++-- .../simple/SimpleImmutableBuilderTest.java | 12 ++++--- ...Target.java => SimpleImmutablePerson.java} | 32 ++++++++++++++++--- ...leSource.java => SimpleMutablePerson.java} | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{SimpleImmutableTarget.java => SimpleImmutablePerson.java} (68%) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{SimpleMutableSource.java => SimpleMutablePerson.java} (97%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java index 076a754d9e..94ac2f6bc4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java @@ -19,10 +19,16 @@ package org.mapstruct.ap.test.builder.simple; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.ReportingPolicy; @Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) public interface ErroneousSimpleBuilderMapper { - SimpleImmutableTarget toImmutable(SimpleMutableSource source); + @Mappings({ + @Mapping(target = "job", ignore = true ), + @Mapping(target = "city", ignore = true ) + }) + SimpleImmutablePerson toImmutable(SimpleMutablePerson source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java index aece401112..8ccb94c661 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java @@ -20,10 +20,15 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Mappings; @Mapper public interface SimpleBuilderMapper { - @Mapping(target = "name", source = "fullName") - SimpleImmutableTarget toImmutable(SimpleMutableSource source); + @Mappings({ + @Mapping(target = "name", source = "fullName"), + @Mapping(target = "job", constant = "programmer"), + @Mapping(target = "city", expression = "java(\"Bengalore\")") + }) + SimpleImmutablePerson toImmutable(SimpleMutablePerson source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index 197f8a4f44..a2489753ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -32,8 +32,8 @@ import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ - SimpleMutableSource.class, - SimpleImmutableTarget.class + SimpleMutablePerson.class, + SimpleImmutablePerson.class }) @RunWith(AnnotationProcessorTestRunner.class) public class SimpleImmutableBuilderTest { @@ -45,14 +45,16 @@ public class SimpleImmutableBuilderTest { @WithClasses({ SimpleBuilderMapper.class }) public void testSimpleImmutableBuilderHappyPath() { SimpleBuilderMapper mapper = Mappers.getMapper( SimpleBuilderMapper.class ); - SimpleMutableSource source = new SimpleMutableSource(); + SimpleMutablePerson source = new SimpleMutablePerson(); source.setAge( 3 ); source.setFullName( "Bob" ); - SimpleImmutableTarget targetObject = mapper.toImmutable( source ); + SimpleImmutablePerson targetObject = mapper.toImmutable( source ); assertThat( targetObject.getAge() ).isEqualTo( 3 ); assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + assertThat( targetObject.getJob() ).isEqualTo( "programmer" ); + assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" ); } @Test @@ -61,7 +63,7 @@ public void testSimpleImmutableBuilderHappyPath() { diagnostics = @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousSimpleBuilderMapper.class, - line = 27, + line = 33, messageRegExp = "Unmapped target property: \"name\"\\.")) public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java similarity index 68% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java index 8e6365a34f..3e6668d14a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java @@ -18,13 +18,17 @@ */ package org.mapstruct.ap.test.builder.simple; -public class SimpleImmutableTarget { +public class SimpleImmutablePerson { private final String name; private final int age; + private final String job; + private final String city; - SimpleImmutableTarget(Builder builder) { + SimpleImmutablePerson(Builder builder) { this.name = builder.name; this.age = builder.age; + this.job = builder.job; + this.city = builder.city; } public static Builder builder() { @@ -39,22 +43,42 @@ public String getName() { return name; } + public String getJob() { + return job; + } + + public String getCity() { + return city; + } + public static class Builder { private String name; private int age; + private String job; + private String city; public Builder age(int age) { this.age = age; return this; } - public SimpleImmutableTarget build() { - return new SimpleImmutableTarget( this ); + public SimpleImmutablePerson build() { + return new SimpleImmutablePerson( this ); } public Builder name(String name) { this.name = name; return this; } + + public Builder job(String job) { + this.job = job; + return this; + } + + public Builder city(String city) { + this.city = city; + return this; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java similarity index 97% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java index 2548ab7781..559f81d94d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutableSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java @@ -18,7 +18,7 @@ */ package org.mapstruct.ap.test.builder.simple; -public class SimpleMutableSource { +public class SimpleMutablePerson { private String fullName; private int age; From 045532fa689d3a07ee2b2cc2b09fa3af5719945a Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Mar 2018 16:31:20 +0100 Subject: [PATCH 0201/1006] #782 Add tests with nested expanding target --- .../BuilderNestedPropertyTest.java | 19 +++++------ .../ExpandingMapper.java} | 11 +++--- .../FlattenedStock.java} | 32 ++++++++--------- .../ImmutableArticle.java} | 28 +++++++-------- .../ImmutableExpandedStock.java} | 34 +++++++++---------- 5 files changed, 61 insertions(+), 63 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/{ => expanding}/BuilderNestedPropertyTest.java (77%) rename processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/{FlattenedMapper.java => expanding/ExpandingMapper.java} (74%) rename processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/{FlattenedSource.java => expanding/FlattenedStock.java} (63%) rename processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/{ImmutableTargetContainer.java => expanding/ImmutableArticle.java} (58%) rename processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/{ExpandedTarget.java => expanding/ImmutableExpandedStock.java} (62%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java similarity index 77% rename from processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java index d4117ccfa0..cad6440276 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.builder.nestedprop; +package org.mapstruct.ap.test.builder.nestedprop.expanding; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,25 +29,22 @@ * Verifies that nested property mapping works with an immutable intermediate type. */ @WithClasses({ - FlattenedSource.class, - ExpandedTarget.class, - ImmutableTargetContainer.class, - FlattenedMapper.class + FlattenedStock.class, + ImmutableExpandedStock.class, + ImmutableArticle.class, + ExpandingMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) public class BuilderNestedPropertyTest { @Test public void testNestedImmutablePropertyMapper() { - ExpandedTarget expandedTarget = FlattenedMapper.INSTANCE.writeToNestedProperty( new FlattenedSource( - "Foo", - "Bar", - 33 - ) ); + FlattenedStock stock = new FlattenedStock( "Sock", "Tie", 33 ); + ImmutableExpandedStock expandedTarget = ExpandingMapper.INSTANCE.writeToNestedProperty( stock ); assertThat( expandedTarget ).isNotNull(); assertThat( expandedTarget.getCount() ).isEqualTo( 33 ); assertThat( expandedTarget.getSecond() ).isNull(); assertThat( expandedTarget.getFirst() ).isNotNull(); - assertThat( expandedTarget.getFirst().getFoo() ).isEqualTo( "33" ); + assertThat( expandedTarget.getFirst().getDescription() ).isEqualTo( "Sock" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java index e74251e8f1..b9d855bcfb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.builder.nestedprop; +package org.mapstruct.ap.test.builder.nestedprop.expanding; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -24,13 +24,14 @@ import org.mapstruct.factory.Mappers; @Mapper -public interface FlattenedMapper { +public interface ExpandingMapper { - FlattenedMapper INSTANCE = Mappers.getMapper( FlattenedMapper.class ); + ExpandingMapper INSTANCE = Mappers.getMapper( ExpandingMapper.class ); @Mappings({ - @Mapping(target = "first.foo", source = "count"), + @Mapping(target = "articleCount", source = "count"), + @Mapping(target = "first.description", source = "article1"), @Mapping(target = "second", ignore = true) }) - ExpandedTarget writeToNestedProperty(FlattenedSource source); + ImmutableExpandedStock writeToNestedProperty(FlattenedStock source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java similarity index 63% rename from processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java index 8bd210b02f..682ab86e32 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/FlattenedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java @@ -16,38 +16,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.builder.nestedprop; +package org.mapstruct.ap.test.builder.nestedprop.expanding; import static com.google.common.base.Preconditions.checkNotNull; -public class FlattenedSource { - private String foo; - private String bar; +public class FlattenedStock { + private String article1; + private String article2; private int count; - public FlattenedSource() { + public FlattenedStock() { } - public FlattenedSource(String foo, String bar, int count) { - this.foo = checkNotNull( foo ); - this.bar = checkNotNull( bar ); + public FlattenedStock(String article1, String article2, int count) { + this.article1 = checkNotNull( article1 ); + this.article2 = checkNotNull( article2 ); this.count = count; } - public String getFoo() { - return foo; + public String getArticle1() { + return article1; } - public void setFoo(String foo) { - this.foo = foo; + public void setArticle1(String article1) { + this.article1 = article1; } - public String getBar() { - return bar; + public String getArticle2() { + return article2; } - public void setBar(String bar) { - this.bar = bar; + public void setArticle2(String article2) { + this.article2 = article2; } public int getCount() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java similarity index 58% rename from processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java index 07eb0468c6..622fbeaba0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ImmutableTargetContainer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java @@ -16,32 +16,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.builder.nestedprop; +package org.mapstruct.ap.test.builder.nestedprop.expanding; -public class ImmutableTargetContainer { - private final String foo; +public class ImmutableArticle { + private final String description; - ImmutableTargetContainer(ImmutableTargetContainer.Builder builder) { - this.foo = builder.foo; + ImmutableArticle(ImmutableArticle.Builder builder) { + this.description = builder.description; } - public static ImmutableTargetContainer.Builder builder() { - return new ImmutableTargetContainer.Builder(); + public static ImmutableArticle.Builder builder() { + return new ImmutableArticle.Builder(); } - public String getFoo() { - return foo; + public String getDescription() { + return description; } public static class Builder { - private String foo; + private String description; - public ImmutableTargetContainer build() { - return new ImmutableTargetContainer( this ); + public ImmutableArticle build() { + return new ImmutableArticle( this ); } - public ImmutableTargetContainer.Builder foo(String foo) { - this.foo = foo; + public ImmutableArticle.Builder description(String description) { + this.description = description; return this; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java similarity index 62% rename from processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java index d83d67f507..067218b4d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/ExpandedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java @@ -16,15 +16,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.ap.test.builder.nestedprop; +package org.mapstruct.ap.test.builder.nestedprop.expanding; -public class ExpandedTarget { +public class ImmutableExpandedStock { private final int count; - private final ImmutableTargetContainer first; - private final ImmutableTargetContainer second; + private final ImmutableArticle first; + private final ImmutableArticle second; - ExpandedTarget(Builder builder) { - this.count = builder.count; + ImmutableExpandedStock(Builder builder) { + this.count = builder.articleCount; this.first = builder.first; this.second = builder.second; } @@ -37,36 +37,36 @@ public int getCount() { return count; } - public ImmutableTargetContainer getFirst() { + public ImmutableArticle getFirst() { return first; } - public ImmutableTargetContainer getSecond() { + public ImmutableArticle getSecond() { return second; } public static class Builder { - private int count; - private ImmutableTargetContainer first; - private ImmutableTargetContainer second; + private int articleCount; + private ImmutableArticle first; + private ImmutableArticle second; - public Builder count(int count) { - this.count = count; + public Builder articleCount(int articleCount) { + this.articleCount = articleCount; return this; } - public Builder first(ImmutableTargetContainer first) { + public Builder first(ImmutableArticle first) { this.first = first; return this; } - public Builder second(ImmutableTargetContainer second) { + public Builder second(ImmutableArticle second) { this.second = second; return this; } - public ExpandedTarget build() { - return new ExpandedTarget( this ); + public ImmutableExpandedStock build() { + return new ImmutableExpandedStock( this ); } } } From 768a739a0984a8ade95f2b3136f7ab9809337be7 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Mar 2018 17:02:00 +0100 Subject: [PATCH 0202/1006] #782 Add tests with nested flattening target --- .../nestedprop/flattening/Article.java | 32 ++++++++ .../flattening/BuilderNestedPropertyTest.java | 59 ++++++++++++++ .../flattening/FlatteningMapper.java | 37 +++++++++ .../flattening/ImmutableFlattenedStock.java | 78 +++++++++++++++++++ .../builder/nestedprop/flattening/Stock.java | 50 ++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java new file mode 100644 index 0000000000..5f5020519c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop.flattening; + +public class Article { + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java new file mode 100644 index 0000000000..fbf1b32332 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop.flattening; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Verifies that nested property mapping works with an immutable intermediate type. + */ +@WithClasses({ + ImmutableFlattenedStock.class, + Stock.class, + Article.class, + FlatteningMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class BuilderNestedPropertyTest { + + @Test + public void testNestedImmutablePropertyMapper() { + + Stock stock = new Stock(); + Article article1 = new Article(); + article1.setDescription( "shavingfoam" ); + Article article2 = new Article(); + article2.setDescription( "soap" ); + stock.setCount( 2 ); + stock.setFirst( article1 ); + stock.setSecond( article2 ); + + ImmutableFlattenedStock flattenedTarget = FlatteningMapper.INSTANCE.writeToFlatProperty( stock ); + + assertThat( flattenedTarget ).isNotNull(); + assertThat( flattenedTarget.getArticleCount() ).isEqualTo( 2 ); + assertThat( flattenedTarget.getArticle1() ).isEqualTo( "shavingfoam" ); + assertThat( flattenedTarget.getArticle2() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java new file mode 100644 index 0000000000..75a339b53e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop.flattening; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface FlatteningMapper { + + FlatteningMapper INSTANCE = Mappers.getMapper( FlatteningMapper.class ); + + @Mappings({ + @Mapping(target = "articleCount", source = "count"), + @Mapping(target = "article1", source = "first.description"), + @Mapping(target = "article2", ignore = true) + }) + ImmutableFlattenedStock writeToFlatProperty(Stock source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java new file mode 100644 index 0000000000..461bd3e7dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java @@ -0,0 +1,78 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop.flattening; + +public class ImmutableFlattenedStock { + + private final String article1; + private final String article2; + private final int articleCount; + + public ImmutableFlattenedStock(String article1, String article2, int count) { + this.article1 = article1; + this.article2 = article2; + this.articleCount = count; + } + + public String getArticle1() { + return article1; + } + + public String getArticle2() { + return article2; + } + + public int getArticleCount() { + return articleCount; + } + + public static ImmutableFlattenedStock.Builder builder() { + return new ImmutableFlattenedStock.Builder(); + } + + public static class Builder { + + private String article1; + private String article2; + private int articleCount; + + public Builder() { + } + + public Builder setArticle1(String article1) { + this.article1 = article1; + return this; + } + + public Builder setArticle2(String article2) { + this.article2 = article2; + return this; + } + + public Builder setArticleCount(int articleCount) { + this.articleCount = articleCount; + return this; + } + + public ImmutableFlattenedStock build() { + return new ImmutableFlattenedStock( article1, article2, articleCount ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java new file mode 100644 index 0000000000..ab10144e1f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.nestedprop.flattening; + +public class Stock { + private int count; + private Article first; + private Article second; + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public Article getFirst() { + return first; + } + + public void setFirst(Article first) { + this.first = first; + } + + public Article getSecond() { + return second; + } + + public void setSecond(Article second) { + this.second = second; + } + +} From 3b9d5413f481442c7fcc9107d628cdfff41a3859 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 18 Mar 2018 17:06:13 +0100 Subject: [PATCH 0203/1006] #782 Use more desriptive names in tests --- .../test/builder/parentchild/ImmutableChild.java | 14 +++++++------- .../ap/test/builder/parentchild/MutableChild.java | 15 ++++++++------- .../parentchild/ParentChildBuilderTest.java | 2 +- .../builder/parentchild/ParentChildMapper.java | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java index 8c7e45a82c..3f95ce98cf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java @@ -20,25 +20,25 @@ public class ImmutableChild { - private final String bar; + private final String name; private ImmutableChild(Builder builder) { - this.bar = builder.bar; + this.name = builder.name; } public static Builder builder() { return new Builder(); } - public String getBar() { - return bar; + public String getName() { + return name; } public static class Builder { - private String bar; + private String name; - public ImmutableChild.Builder bar(String bar) { - this.bar = bar; + public ImmutableChild.Builder name(String name) { + this.name = name; return this; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java index 692a6414d6..a3688275d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java @@ -19,20 +19,21 @@ package org.mapstruct.ap.test.builder.parentchild; public class MutableChild { + public MutableChild() { } - public MutableChild(String foo) { - this.foo = foo; + public MutableChild(String childName) { + this.childName = childName; } - private String foo; + private String childName; - public String getFoo() { - return foo; + public String getChildName() { + return childName; } - public void setFoo(String foo) { - this.foo = foo; + public void setChildName(String childName) { + this.childName = childName; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java index 4d7d9b2cc1..671c095cc8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java @@ -61,7 +61,7 @@ private Condition hasMatchingName(final String name) { return new Condition( "Matching name" ) { @Override public boolean matches(ImmutableChild value) { - return name.equals( value.getBar() ); + return name.equals( value.getName() ); } }; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java index 2a66469a6c..479d4f5e92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java @@ -29,6 +29,6 @@ public interface ParentChildMapper { ImmutableParent toParent(MutableParent source); - @Mapping(target = "bar", source = "foo") + @Mapping(target = "name", source = "childName") ImmutableChild toChild(MutableChild source); } From 2d8af2960b8d5f4f5700d3f20d80c790d7b24007 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 4 Apr 2018 19:48:46 +0200 Subject: [PATCH 0204/1006] Add Eric to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index c1010269c6..73af174e44 100644 --- a/copyright.txt +++ b/copyright.txt @@ -10,6 +10,7 @@ Cornelius Dirmeier - https://github.com/cornzy Darren Rambaud - https://github.com/xyzst Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil +Eric Martineau - https://github.com/ericmartineau Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Gunnar Morling - https://github.com/gunnarmorling From e368b34ea48641f93ff235244f4ec1b531e4de88 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Fri, 30 Mar 2018 21:44:18 +0200 Subject: [PATCH 0205/1006] #1370 avoid errors when Joda is not on classpath --- .../internal/model/common/DateFormatValidatorFactory.java | 7 +++++++ .../main/java/org/mapstruct/ap/internal/util/Message.java | 1 + 2 files changed, 8 insertions(+) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index dddd6d6850..cee6a19874 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -154,6 +154,9 @@ public DateFormatValidationResult validate(String dateFormat) { catch ( InvocationTargetException e ) { return invalidDateFormat( dateFormat, e.getCause() ); } + catch ( ClassNotFoundException e ) { + return noJodaOnClassPath(); + } catch ( Exception e ) { return invalidDateFormat( dateFormat, e ); } @@ -185,4 +188,8 @@ private static DateFormatValidationResult validDateFormat(String dateFormat) { private static DateFormatValidationResult invalidDateFormat(String dateFormat, Throwable e) { return new DateFormatValidationResult( false, Message.GENERAL_INVALID_DATE, dateFormat, e.getMessage() ); } + + private static DateFormatValidationResult noJodaOnClassPath() { + return new DateFormatValidationResult( false, Message.GENERAL_JODA_NOT_ON_CLASSPATH ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4d7d629fb7..3a65e30cec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -95,6 +95,7 @@ public enum Message { GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ), + GENERAL_JODA_NOT_ON_CLASSPATH( "Cannot validate Joda dateformat, no Joda on classpath. Consider adding Joda to the annotation processorpath.", Diagnostic.Kind.WARNING ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible parameterless constructor." ), From db6805f100f325cf85f4e8660c87186ae3935fc5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 6 Apr 2018 23:02:55 +0200 Subject: [PATCH 0206/1006] #1418 Add support for NoOp BuilderProvider for turning off using of builders --- .../mapstruct/ap/spi/NoOpBuilderProvider.java | 36 ++++++++++ .../builder/noop/NoOpBuilderProviderTest.java | 51 ++++++++++++++ .../ap/test/builder/noop/Person.java | 66 +++++++++++++++++++ .../ap/test/builder/noop/PersonDto.java | 35 ++++++++++ .../ap/test/builder/noop/PersonMapper.java | 33 ++++++++++ 5 files changed, 221 insertions(+) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java new file mode 100644 index 0000000000..598ef1ab3f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +/** + * A NoOp {@link BuilderProvider} which returns {@code null} when searching for a builder. + * + * @author Filip Hrisafov + */ +public class NoOpBuilderProvider implements BuilderProvider { + + @Override + public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types) { + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java new file mode 100644 index 0000000000..fa72dc47c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.noop; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.NoOpBuilderProvider; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey( "1418" ) +@WithServiceImplementation(NoOpBuilderProvider.class) +@WithClasses( { + Person.class, + PersonDto.class, + PersonMapper.class +} ) +public class NoOpBuilderProviderTest { + + @Test + public void shouldNotUseBuilder() { + Person person = PersonMapper.INSTANCE.map( new PersonDto( "Filip" ) ); + + assertThat( person ).isNotNull(); + assertThat( person.getName() ).isEqualTo( "Filip" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java new file mode 100644 index 0000000000..f40e49f8a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.noop; + +/** + * @author Filip Hrisafov + */ +public class Person { + + private String name; + + public Person() { + + } + + public Person(Builder builder) { + this.name = builder.name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Builder create() { + throw new UnsupportedOperationException( "Creating builder is not supported" ); + } + + public static class Builder { + + private String name; + + public Builder() { + throw new UnsupportedOperationException( "Creating a builder is not supported" ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Person create() { + return new Person(this); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java new file mode 100644 index 0000000000..b36f62acb0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.noop; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + + private final String name; + + public PersonDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java new file mode 100644 index 0000000000..d2146690d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.noop; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person map(PersonDto dto); +} From 42d7bfe54d1d5bfaa011f5b6c1d4132be20ffbba Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Apr 2018 13:15:36 +0200 Subject: [PATCH 0207/1006] #1359 Collection target should be considered as immutable if there is no read accessor --- .../model/CollectionAssignmentBuilder.java | 2 +- .../ap/test/bugs/_1359/Issue1359Mapper.java | 34 +++++++++++ .../ap/test/bugs/_1359/Issue1359Test.java | 59 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1359/Source.java | 37 ++++++++++++ .../mapstruct/ap/test/bugs/_1359/Target.java | 33 +++++++++++ 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index e6197b8079..3443cfab72 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -125,7 +125,7 @@ public Assignment build() { Assignment result = assignment; CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); - boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE; + boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE || targetReadAccessor == null; if ( targetAccessorType == PropertyMapping.TargetWriteAccessorType.SETTER || targetAccessorType == PropertyMapping.TargetWriteAccessorType.FIELD ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java new file mode 100644 index 0000000000..a0270788d6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1359; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1359Mapper { + + Issue1359Mapper INSTANCE = Mappers.getMapper( Issue1359Mapper.class ); + + void map(@MappingTarget Target target, Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java new file mode 100644 index 0000000000..9e4d8276a9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1359; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.atIndex; + +/** + * @author Filip Hrisafov + */ +@WithClasses( { + Issue1359Mapper.class, + Source.class, + Target.class +} ) +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey( "1359" ) +public class Issue1359Test { + + @Test + public void shouldCompile() { + + Target target = new Target(); + assertThat( target ).extracting( "properties" ).contains( null, atIndex( 0 ) ); + + Set properties = new HashSet(); + properties.add( "first" ); + Source source = new Source( properties ); + Issue1359Mapper.INSTANCE.map( target, source ); + + assertThat( target ).extracting( "properties" ).contains( properties, atIndex( 0 ) ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java new file mode 100644 index 0000000000..7b4bb0d2d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1359; + +import java.util.Set; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private Set properties; + + public Source(Set properties) { + this.properties = properties; + } + + public Set getProperties() { + return properties; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java new file mode 100644 index 0000000000..196118eb59 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1359; + +import java.util.Set; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Set properties; + + public void setProperties(Set properties) { + this.properties = properties; + } +} From beea14125540e5ca22f47541d9a268aa73d3ae23 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Apr 2018 17:54:26 +0200 Subject: [PATCH 0208/1006] #1338 Always determine collection argument type when searching for adder If the Collection type is not actually generic it has no type parameters. However, it's type argument can be determined. One such list exists in protobuf (ProtocolStringList) --- .../ap/internal/model/common/Type.java | 34 ++++++------ .../ap/test/bugs/_1338/Issue1338Mapper.java | 34 ++++++++++++ .../ap/test/bugs/_1338/Issue1338Test.java | 53 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1338/Source.java | 37 +++++++++++++ .../mapstruct/ap/test/bugs/_1338/Target.java | 44 +++++++++++++++ 5 files changed, 185 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 0f88cc81a6..32f962b712 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -51,6 +51,8 @@ import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; import org.mapstruct.ap.spi.BuilderInfo; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * Represents (a reference to) the type of a bean property, parameter etc. Types are managed per generated source file. * Each type corresponds to a {@link TypeMirror}, i.e. there are different instances for e.g. {@code Set} and @@ -578,23 +580,21 @@ private Accessor getAdderForType(Type collectionProperty, String pluralPropertyN if ( collectionProperty.isCollectionType ) { // this is a collection, so this can be done always - if ( !collectionProperty.getTypeParameters().isEmpty() ) { - // there's only one type arg to a collection - TypeMirror typeArg = collectionProperty.getTypeParameters().get( 0 ).getTypeBound().getTypeMirror(); - // now, look for a method that - // 1) starts with add, - // 2) and has typeArg as one and only arg - List adderList = getAdders(); - for ( Accessor adder : adderList ) { - ExecutableElement executable = adder.getExecutable(); - if ( executable == null ) { - // it should not be null, but to be safe - continue; - } - VariableElement arg = executable.getParameters().get( 0 ); - if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { - candidates.add( adder ); - } + TypeMirror typeArg = first( collectionProperty.determineTypeArguments( Iterable.class ) ).getTypeBound() + .getTypeMirror(); + // now, look for a method that + // 1) starts with add, + // 2) and has typeArg as one and only arg + List adderList = getAdders(); + for ( Accessor adder : adderList ) { + ExecutableElement executable = adder.getExecutable(); + if ( executable == null ) { + // it should not be null, but to be safe + continue; + } + VariableElement arg = executable.getParameters().get( 0 ); + if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { + candidates.add( adder ); } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java new file mode 100644 index 0000000000..ade7b14bee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1338; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue1338Mapper { + + Issue1338Mapper INSTANCE = Mappers.getMapper( Issue1338Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java new file mode 100644 index 0000000000..7b8d5ce8d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1338; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.atIndex; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1338") +@WithClasses({ + Issue1338Mapper.class, + Source.class, + Target.class +}) +public class Issue1338Test { + + @Test + public void shouldCorrectlyUseAdder() { + Target target = Issue1338Mapper.INSTANCE.map( new Source( Arrays.asList( "first", "second" ) ) ); + + assertThat( target ) + .extracting( "properties" ) + .contains( Arrays.asList( "first", "second" ), atIndex( 0 ) ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java new file mode 100644 index 0000000000..5c8a6c84b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1338; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final List properties; + + public Source(List properties) { + this.properties = properties; + } + + public List getProperties() { + return properties; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java new file mode 100644 index 0000000000..793541cbc9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1338; + +import java.util.ArrayList; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private StringList properties = new StringList(); + + public void addProperty(String property) { + properties.add( property ); + } + + public void setProperties(StringList properties) { + throw new IllegalStateException( "Setter is there just as a marker it should not be used" ); + } + + public static class StringList extends ArrayList { + + private StringList() { + // Constructor is private so we get a compile error if we try to instantiate it + } + } +} From 18fa0a5b1ac048fe7c3572706c92b1baaadbaf96 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 8 Apr 2018 16:42:42 +0200 Subject: [PATCH 0209/1006] #1414 Pass originating mapper element to the Filer API --- .../processor/MapperRenderingProcessor.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java index c91cd08ceb..a0d90adc17 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java @@ -39,24 +39,25 @@ public class MapperRenderingProcessor implements ModelElementProcessor Date: Sun, 15 Apr 2018 02:33:00 -0400 Subject: [PATCH 0210/1006] #1383 Invalid @Mapping values should be reported on the @Mapping annotation --- .../ap/internal/model/source/Mapping.java | 40 +++++++++++++++---- .../test/defaultvalue/DefaultValueTest.java | 4 +- .../source/constants/SourceConstantsTest.java | 6 +-- .../java/JavaDefaultExpressionTest.java | 6 +-- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index d819a788d4..1f5ffb612b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -110,35 +110,59 @@ public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElem } if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) { - messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED ); return null; } else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) { - messager.printMessage( element, Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) { - messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( element, Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( element, Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( element, Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); return null; } else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( element, Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); return null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index 885230f2b9..f1b8e0e23e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -138,7 +138,7 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { diagnostics = { @Diagnostic( type = ErroneousMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 31, messageRegExp = "Constant and default value are both defined in @Mapping," + " either define a defaultValue or a constant." ), @Diagnostic(type = ErroneousMapper.class, @@ -160,7 +160,7 @@ public void errorOnDefaultValueAndConstant() throws ParseException { diagnostics = { @Diagnostic( type = ErroneousMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 31, messageRegExp = "Expression and default value are both defined in @Mapping," + " either define a defaultValue or an expression." ), @Diagnostic(type = ErroneousMapper2.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 5142bc6e0e..5105fe2896 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -103,7 +103,7 @@ public void shouldMapTargetToSourceWithoutWhining() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper1.class, kind = Kind.ERROR, - line = 43, + line = 37, messageRegExp = "Source and constant are both defined in @Mapping, either define a source or a " + "constant"), @Diagnostic(type = ErroneousMapper1.class, @@ -129,7 +129,7 @@ public void errorOnSourceAndConstant() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper3.class, kind = Kind.ERROR, - line = 43, + line = 37, messageRegExp = "Expression and constant are both defined in @Mapping, either define an expression or a " + "constant"), @@ -156,7 +156,7 @@ public void errorOnConstantAndExpression() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper4.class, kind = Kind.ERROR, - line = 43, + line = 37, messageRegExp = "Source and expression are both defined in @Mapping, either define a source or an " + "expression"), @Diagnostic(type = ErroneousMapper4.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 149438f1ad..04d1d54500 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -68,7 +68,7 @@ public void testJavaDefaultExpressionWithNoValues() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 39, + line = 35, messageRegExp = "Expression and default expression are both defined in @Mapping," + " either define an expression or a default expression." ), @@ -89,7 +89,7 @@ public void testJavaDefaultExpressionExpression() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 38, + line = 35, messageRegExp = "Constant and default expression are both defined in @Mapping," + " either define a constant or a default expression." ), @@ -110,7 +110,7 @@ public void testJavaDefaultExpressionConstant() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 38, + line = 35, messageRegExp = "Default value and default expression are both defined in @Mapping," + " either define a default value or a default expression." ), From 050e893c51461e6154dfd32cab7111a903ed5fe3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Apr 2018 09:35:33 +0200 Subject: [PATCH 0211/1006] Add David to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 73af174e44..a7d53e0d2b 100644 --- a/copyright.txt +++ b/copyright.txt @@ -7,6 +7,7 @@ Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman Cornelius Dirmeier - https://github.com/cornzy +David Feinblum - https://github.com/dvfeinblum Darren Rambaud - https://github.com/xyzst Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil From 5834368b15f0f0955fd363ee45470b385889628d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Apr 2018 10:19:58 +0200 Subject: [PATCH 0212/1006] #1431 Factory method resolution should be done on the effective type This allows using factories for builder types as well --- .../creation/MappingResolverImpl.java | 4 +- .../builder/factory/BuilderFactoryMapper.java | 40 ++++++++++++ .../factory/BuilderFactoryMapperTest.java | 55 ++++++++++++++++ .../factory/BuilderImplicitFactoryMapper.java | 38 +++++++++++ .../ap/test/builder/factory/Person.java | 63 +++++++++++++++++++ .../ap/test/builder/factory/PersonDto.java | 35 +++++++++++ 6 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index fbc3e15168..d6f5050327 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -138,7 +138,7 @@ public MethodReference getFactoryMethod(final Method mappingMethod, Type targetT mappingMethod, sourceModel, java.util.Collections. emptyList(), - targetType, + targetType.getEffectiveType(), SelectionCriteria.forFactoryMethods( selectionParameters ) ); if (matchingFactoryMethods.isEmpty()) { @@ -149,7 +149,7 @@ java.util.Collections. emptyList(), messager.printMessage( mappingMethod.getExecutable(), Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, - targetType, + targetType.getEffectiveType(), Strings.join( matchingFactoryMethods, ", " ) ); return null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java new file mode 100644 index 0000000000..e7ac6c2e99 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.factory; + +import org.mapstruct.Mapper; +import org.mapstruct.ObjectFactory; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class BuilderFactoryMapper { + + public static final BuilderFactoryMapper INSTANCE = Mappers.getMapper( BuilderFactoryMapper.class ); + + public abstract Person map(PersonDto source); + + @ObjectFactory + public Person.PersonBuilder personBuilder() { + return new Person.PersonBuilder( "Factory with @ObjectFactory" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java new file mode 100644 index 0000000000..827d3f9f87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.factory; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + BuilderFactoryMapper.class, + BuilderImplicitFactoryMapper.class, + Person.class, + PersonDto.class +}) +public class BuilderFactoryMapperTest { + + @Test + public void shouldUseBuilderFactory() { + Person person = BuilderFactoryMapper.INSTANCE.map( new PersonDto( "Filip" ) ); + + assertThat( person.getName() ).isEqualTo( "Filip" ); + assertThat( person.getSource() ).isEqualTo( "Factory with @ObjectFactory" ); + } + + @Test + public void shouldUseImplicitBuilderFactory() { + Person person = BuilderImplicitFactoryMapper.INSTANCE.map( new PersonDto( "Filip" ) ); + + assertThat( person.getName() ).isEqualTo( "Filip" ); + assertThat( person.getSource() ).isEqualTo( "Implicit Factory" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java new file mode 100644 index 0000000000..cc1feeafab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.factory; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class BuilderImplicitFactoryMapper { + + public static final BuilderImplicitFactoryMapper INSTANCE = Mappers.getMapper( BuilderImplicitFactoryMapper.class ); + + public abstract Person map(PersonDto source); + + public Person.PersonBuilder personBuilder() { + return new Person.PersonBuilder( "Implicit Factory" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java new file mode 100644 index 0000000000..f94a167546 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java @@ -0,0 +1,63 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.factory; + +/** + * @author Filip Hrisafov + */ +public class Person { + + private final String name; + private final String source; + + protected Person(PersonBuilder builder) { + this.name = builder.name; + this.source = builder.source; + } + + public String getName() { + return name; + } + + public String getSource() { + return source; + } + + public static PersonBuilder builder() { + throw new UnsupportedOperationException( "Factory should be used" ); + } + + public static class PersonBuilder { + private String name; + private final String source; + + public PersonBuilder(String source) { + this.source = source; + } + + public PersonBuilder name(String name) { + this.name = name; + return this; + } + + public Person create() { + return new Person( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java new file mode 100644 index 0000000000..797b7bf56a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.factory; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + + private String name; + + public PersonDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} From 43a9419c33002f1fd49bbeacd5c48492c4ee30f3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Apr 2018 10:31:45 +0200 Subject: [PATCH 0213/1006] #1417 Add documentation about the builder support --- .../mapstruct-reference-guide.asciidoc | 140 ++++++++++++++++++ .../extras/ImmutablesBuilderProvider.java | 7 + 2 files changed, 147 insertions(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index d5e0f84d9c..8f359969dd 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -5,6 +5,8 @@ :Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen, Filip Hrisafov and the MapStruct community :processor-dir: ../../../../processor :processor-ap-test: {processor-dir}/src/test/java/org/mapstruct/ap/test +:integration-tests-dir: ../../../../integrationtest +:immutables-builder-test: {integration-tests-dir}/src/test/resources/immutablesBuilderTest [[Preface]] == Preface @@ -310,6 +312,21 @@ In the generated method implementations all readable properties from the source The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans specification] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. ==== +[TIP] +==== +Fluent setters are also supported. +Fluent setters are setters that return the same type as the type being modified. + +E.g. + +``` +public Builder seatCount(int seatCount) { + this.seatCount = seatCount; + return this; +} +``` +==== + [TIP] ==== When using Java 8 or later, you can omit the `@Mappings` wrapper annotation and directly specify several `@Mapping` annotations on one method. @@ -594,6 +611,113 @@ You can find the complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-field-mapping[mapstruct-examples-field-mapping] project on GitHub. +[[mapping-with-builders]] +=== Using builders + +MapStruct also supports mapping of immutable types via builders. +When performing a mapping MapStruct checks if there is a builder for the type being mapped. +This is done via the `BuilderProvider` SPI. +If a Builder exists for a certain type, than that builder will be used for the mappings. + +The default implementation of the `BuilderProvider` assumes the following: + +* The type has a parameterless public static builder creation method that returns a builder. +So for example `Person` has a public static method that returns `PersonBuilder`. +* The builder type has a parameterless public method (build method) that returns the type being build +In our example `PersonBuilder` has a method returning `Person`. + +If such type is found then MapStruct will use that type to perform the mapping to (i.e. it will look for setters into that type). +To finish the mapping MapStruct generates code that will invoke the build method of the builder. + +[NOTE] +====== +The <> are also considered for the builder type. +E.g. If an object factory exists for our `PersonBuilder` than this factory would be used instead of the builder creation method. +====== + +.Person with Builder example +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Person { + + private final String name; + + protected Person(Person.Builder builder) { + this.name = builder.name; + } + + public static Person.Builder builder() { + return new Person.Builder(); + } + + public static class Builder { + + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Person create() { + return new Person( this ); + } + } +} +---- +==== + +.Person Mapper definition +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public interface PersonMapper { + + Person map(PersonDto dto); +} +---- +==== + +.Generated mapper with builder +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class PersonMapperImpl implements PersonMapper { + + public Person map(PersonDto dto) { + if (dto == null) { + return null; + } + + Person.Builder builder = Person.builder(); + + builder.name( dto.getName() ); + + return builder.create(); + } +} +---- +==== + +Supported builder frameworks: + +* https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] +* https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] +* https://immutables.github.io/[Immutables] - requires using a custom `AccessorNamingStrategy` and a custom `BuilderProvider` (see example in integration tests) +* https://github.com/google/FreeBuilder[FreeBuilder] +* It also works for custom builders (handwritten ones) if the implementation supports the defined rules for the default `BuilderProvider`. +Otherwise, you would need to write a custom `BuilderProvider` + +[TIP] +==== +In case you want to disable using builders then you can use the `NoOpBuilderProvider` by creating a `org.mapstruct.ap.spi.BuilderProvider` file in the `META-INF/services` directory with `org.mapstruct.ap.spi.NoOpBuilderProvider` as it's content. +==== + [[retrieving-mapper]] == Retrieving a mapper @@ -2671,3 +2795,19 @@ together with the file `META-INF/services/org.mapstruct.ap.spi.MappingExclusionP (e.g. `org.mapstruct.example.CustomMappingExclusionProvider`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). + + +[[custom-builder-provider]] +=== Custom Builder Provider + +MapStruct offers the possibility to override the `DefaultProvider` via the Service Provider Interface (SPI). +A nice example is to provide support for a custom builder strategy. + +.Custom Builder Provider for Immutables +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{immutables-builder-test}/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java[tag=documentation] +---- +==== diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java index 63c6ae26a6..96f1c1bd3c 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java @@ -18,6 +18,8 @@ */ package org.mapstruct.itest.immutables.extras; +// tag::documentation[] + import java.util.regex.Pattern; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -32,9 +34,12 @@ import org.mapstruct.ap.spi.DefaultBuilderProvider; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; +// end::documentation[] + /** * @author Filip Hrisafov */ +// tag::documentation[] public class ImmutablesBuilderProvider extends DefaultBuilderProvider { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); @@ -70,6 +75,7 @@ protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, return super.findBuilderInfo( immutableElement, elements, types ); } else { + // Immutables processor has not run yet. Trigger a postpone to the next round for MapStruct throw new TypeHierarchyErroneousException( typeElement ); } } @@ -95,3 +101,4 @@ private TypeElement asImmutableElement(TypeElement typeElement, Elements element return elements.getTypeElement( builderQualifiedName ); } } +// end::documentation[] From 60f27dbafc06208779171345ce655aa09305e6dc Mon Sep 17 00:00:00 2001 From: Lauri Apple Date: Tue, 31 Oct 2017 13:37:36 +0100 Subject: [PATCH 0214/1006] Update readme.md --- readme.md | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/readme.md b/readme.md index 52904f7559..4398a68e91 100644 --- a/readme.md +++ b/readme.md @@ -20,7 +20,17 @@ ## What is MapStruct? -MapStruct is a Java [annotation processor](http://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html) for the generation of type-safe and performant mappers for Java bean classes. +MapStruct is a Java [annotation processor](http://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html) for the generation of type-safe and performant mappers for Java bean classes. It saves you from writing mapping code by hand, which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior. + +Compared to mapping frameworks working at runtime, MapStruct offers the following advantages: + +* Fast execution by using plain method invocations instead of reflection +* Compile-time type safety: Only objects and attributes mapping to each other can be mapped, so there's no accidental mapping of an order entity into a customer DTO, etc. +* Self-contained code—no runtime dependencies +* Clear error-reports at build time if: + * mappings are incomplete (not all target properties are mapped) + * mappings are incorrect (cannot find a proper mapping method or type conversion) +* Mapping code is easy to debug (or edited by hand—e.g. in case of a bug in the generator) To create a mapping between two types, declare a mapper class like this: @@ -35,19 +45,7 @@ public interface CarMapper { } ``` -At compile time MapStruct will generate an implementation of this interface. The generated implementation uses plain Java method invocations for mapping between source and target objects, i.e. there is no reflection involved. By default, properties are mapped if they have the same name in source and target, but this and many other aspects can be controlled using `@Mapping` and a handful of other annotations. - -MapStruct saves you from writing mapping code by hand which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior. - -Compared to mapping frameworks working at runtime MapStruct offers the following advantages: - -* Fast execution by using plain method invocations instead of reflection -* Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc. -* Self-contained code, no runtime dependencies -* Clear error-reports at build time if - * mappings are incomplete (not all target properties are mapped) - * mappings are incorrect (cannot find a proper mapping method or type conversion) -* Mapping code is easy to debug (or edited by hand e.g. in case of a bug in the generator) +At compile time MapStruct will generate an implementation of this interface. The generated implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection is involved. By default, properties are mapped if they have the same name in source and target, but you can control this and many other aspects using `@Mapping` and a handful of other annotations. ## Requirements @@ -57,11 +55,11 @@ MapStruct requires Java 1.6 or later. MapStruct works in command line builds (plain javac, via Maven, Gradle, Ant etc.) and IDEs. -For Eclipse, there is a dedicated plug-in under development (see https://github.com/mapstruct/mapstruct-eclipse) which goes beyond what's possible with an annotation processor, providing content assist for annotation attributes, quick fixes and more. +For Eclipse, a dedicated plug-in is in development (see https://github.com/mapstruct/mapstruct-eclipse). It goes beyond what's possible with an annotation processor, providing content assist for annotation attributes, quick fixes and more. ### Maven -For Maven-based projects add the following to your POM file in order to use MapStruct (the dependencies can be obtained from Maven Central): +For Maven-based projects, add the following to your POM file in order to use MapStruct (the dependencies are available at Maven Central): ```xml ... @@ -118,19 +116,15 @@ dependencies { ... ``` -If you don't work with a dependency management tool you can obtain a distribution bundle from [SourceForge](https://sourceforge.net/projects/mapstruct/files/). +If you don't work with a dependency management tool, you can obtain a distribution bundle from [SourceForge](https://sourceforge.net/projects/mapstruct/files/). ## Documentation and getting help To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help, come and join the [mapstruct-users](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) group. -## Licensing - -MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use it except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. - ## Building from Source -MapStruct uses Maven for its build. Java 8 is required for building MapStruct from source. To build the complete project run +MapStruct uses Maven for its build. Java 8 is required for building MapStruct from source. To build the complete project, run mvn clean install @@ -150,3 +144,7 @@ from the root of the project directory. To skip the distribution module, run

      + +## Licensing + +MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. From 721e3efec25885c20a3023f3807884ee18eb1e5f Mon Sep 17 00:00:00 2001 From: Lauri Apple Date: Tue, 31 Oct 2017 13:39:32 +0100 Subject: [PATCH 0215/1006] Update readme.md --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 4398a68e91..cb1a039798 100644 --- a/readme.md +++ b/readme.md @@ -24,13 +24,13 @@ MapStruct is a Java [annotation processor](http://docs.oracle.com/javase/6/docs/ Compared to mapping frameworks working at runtime, MapStruct offers the following advantages: -* Fast execution by using plain method invocations instead of reflection -* Compile-time type safety: Only objects and attributes mapping to each other can be mapped, so there's no accidental mapping of an order entity into a customer DTO, etc. -* Self-contained code—no runtime dependencies -* Clear error-reports at build time if: +* **Fast execution** by using plain method invocations instead of reflection +* **Compile-time type safety**. Only objects and attributes mapping to each other can be mapped, so there's no accidental mapping of an order entity into a customer DTO, etc. +* **Self-contained code**—no runtime dependencies +* **Clear error reports** at build time if: * mappings are incomplete (not all target properties are mapped) * mappings are incorrect (cannot find a proper mapping method or type conversion) -* Mapping code is easy to debug (or edited by hand—e.g. in case of a bug in the generator) +* **Easily debuggable mapping code** (or editable by hand—e.g. in case of a bug in the generator) To create a mapping between two types, declare a mapper class like this: From f63903a822176b1c16ff5af5dcdd2af2e6c036bb Mon Sep 17 00:00:00 2001 From: Lauri Apple Date: Tue, 31 Oct 2017 13:40:42 +0100 Subject: [PATCH 0216/1006] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index cb1a039798..d693c6a095 100644 --- a/readme.md +++ b/readme.md @@ -14,9 +14,9 @@ * [Maven](#maven) * [Gradle](#gradle) * [Documentation and getting help](#documentation-and-getting-help) -* [Licensing](#licensing) * [Building from Source](#building-from-source) * [Links](#links) +* [Licensing](#licensing) ## What is MapStruct? From 72bf87f40913a7d1cfaeca4f289a9ebe2e1f7d83 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Thu, 19 Apr 2018 19:39:43 +0200 Subject: [PATCH 0217/1006] Remove cloudbees CI links and add travis-ci to readme --- CONTRIBUTING.md | 2 +- readme.md | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1c2c0bbafe..aaf8fd8646 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ You love MapStruct but miss a certain feature? You found a bug and want to repor * Source code: [http://github.com/mapstruct/mapstruct](http://github.com/mapstruct/mapstruct) * Issue tracker: [https://github.com/mapstruct/mapstruct/issues](https://github.com/mapstruct/mapstruct/issues) * Discussions: Join the [mapstruct-users](https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users) Google group -* CI build: [https://mapstruct.ci.cloudbees.com](https://mapstruct.ci.cloudbees.com) +* CI build: [https://travis-ci.org/mapstruct/mapstruct/](https://travis-ci.org/mapstruct/mapstruct/) MapStruct follows the _Fork & Pull_ development approach. To get started just fork the [MapStruct repository](http://github.com/mapstruct/mapstruct) to your GitHub account and create a new topic branch for each change. Once you are done with your change, submit a [pull request](https://help.github.com/articles/using-pull-requests) against the MapStruct repo. diff --git a/readme.md b/readme.md index d693c6a095..1b65d8c684 100644 --- a/readme.md +++ b/readme.md @@ -139,11 +139,7 @@ from the root of the project directory. To skip the distribution module, run * [Downloads](https://sourceforge.net/projects/mapstruct/files/) * [Issue tracker](https://github.com/mapstruct/mapstruct/issues) * [User group](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) -* [CI build](https://mapstruct.ci.cloudbees.com/) - -
      - -
      +* [CI build](https://travis-ci.org/mapstruct/mapstruct/) ## Licensing From 4f5db83de7e45f4453a73b2f1da63eb53db38f4c Mon Sep 17 00:00:00 2001 From: sjaakd Date: Mon, 19 Mar 2018 15:06:56 +0100 Subject: [PATCH 0218/1006] #1392 add option to default ignoreAll mappings in a bean mapping method --- .../main/java/org/mapstruct/BeanMapping.java | 10 +++ .../mapstruct-reference-guide.asciidoc | 10 ++- .../ap/internal/model/source/BeanMapping.java | 26 +++++- .../ap/internal/model/source/Mapping.java | 19 ++++ .../internal/model/source/MappingOptions.java | 22 ++++- .../processor/MapperCreationProcessor.java | 5 ++ .../ap/test/ignore/AnimalMapper.java | 6 +- .../ap/test/ignore/IgnorePropertyTest.java | 16 ++++ .../test/ignore/expand/ExpandedToolbox.java | 55 ++++++++++++ .../test/ignore/expand/FlattenedToolBox.java | 73 +++++++++++++++ .../ap/test/ignore/expand/Hammer.java | 46 ++++++++++ .../ignore/expand/IgnorePropertyTest.java | 64 +++++++++++++ .../ap/test/ignore/expand/ToolBoxMapper.java | 39 ++++++++ .../ap/test/ignore/expand/Wrench.java | 46 ++++++++++ .../ap/test/ignore/inherit/BaseEntity.java | 57 ++++++++++++ .../ap/test/ignore/inherit/HammerDto.java | 36 ++++++++ .../ap/test/ignore/inherit/HammerEntity.java | 35 ++++++++ .../ignore/inherit/IgnorePropertyTest.java | 90 +++++++++++++++++++ .../ap/test/ignore/inherit/ToolDto.java | 37 ++++++++ .../ap/test/ignore/inherit/ToolEntity.java | 37 ++++++++ .../ap/test/ignore/inherit/ToolMapper.java | 53 +++++++++++ .../ap/test/ignore/inherit/WorkBenchDto.java | 46 ++++++++++ .../test/ignore/inherit/WorkBenchEntity.java | 46 ++++++++++ 23 files changed, 865 insertions(+), 9 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index 50df1ae392..76eac373f5 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -73,4 +73,14 @@ * @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapping. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + + /** + * Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No + * warning will be issued on missing target properties. + * + * @return The ignore strategy (default false). + * + * @since 1.3 + */ + boolean ignoreByDefault() default false; } diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 8f359969dd..122d597347 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -305,13 +305,19 @@ public interface CarMapper { The `@Mapper` annotation causes the MapStruct code generator to create an implementation of the `CarMapper` interface during build-time. -In the generated method implementations all readable properties from the source type (e.g. `Car`) will be copied into the corresponding property in the target type (e.g. `CarDto`). If a property has a different name in the target entity, its name can be specified via the `@Mapping` annotation. +In the generated method implementations all readable properties from the source type (e.g. `Car`) will be copied into the corresponding property in the target type (e.g. `CarDto`): + +* When a property has the same name as its target entity counterpart, it will be mapped implicitly. +* When a property has a different name in the target entity, its name can be specified via the `@Mapping` annotation. [TIP] ==== The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans specification] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. ==== - +[TIP] +==== +By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. +==== [TIP] ==== Fluent setters are also supported. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index dccc14f7d7..55610f995c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -38,6 +38,17 @@ public class BeanMapping { private final SelectionParameters selectionParameters; private final NullValueMappingStrategyPrism nullValueMappingStrategy; private final ReportingPolicyPrism reportingPolicy; + private final boolean ignoreByDefault; + + /** + * creates a mapping for inheritance. Will set ignoreByDefault to false. + * + * @param map + * @return + */ + public static BeanMapping forInheritance( BeanMapping map ) { + return new BeanMapping( map.selectionParameters, map.nullValueMappingStrategy, map.reportingPolicy, false ); + } public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, FormattingMessager messager, Types typeUtils) { @@ -53,8 +64,9 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ? null : NullValueMappingStrategyPrism.valueOf( beanMapping.nullValueMappingStrategy() ); + boolean ignoreByDefault = beanMapping.ignoreByDefault(); if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() - && ( nullValueMappingStrategy == null ) ) { + && ( nullValueMappingStrategy == null ) && !ignoreByDefault ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); } @@ -67,7 +79,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ); //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? - return new BeanMapping( cmp, nullValueMappingStrategy, null ); + return new BeanMapping( cmp, nullValueMappingStrategy, null, ignoreByDefault ); } /** @@ -77,14 +89,15 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem * @return bean mapping that needs to be used for Mappings */ public static BeanMapping forForgedMethods() { - return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE ); + return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false ); } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, - ReportingPolicyPrism reportingPolicy) { + ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; this.reportingPolicy = reportingPolicy; + this.ignoreByDefault = ignoreByDefault; } public SelectionParameters getSelectionParameters() { @@ -98,4 +111,9 @@ public NullValueMappingStrategyPrism getNullValueMappingStrategy() { public ReportingPolicyPrism getReportingPolicy() { return reportingPolicy; } + + public boolean isignoreByDefault() { + return ignoreByDefault; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 1f5ffb612b..fb840d659c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -211,6 +211,25 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa ); } + public static Mapping forIgnore( String targetName) { + return new Mapping( + null, + null, + null, + null, + targetName, + null, + true, + null, + null, + null, + null, + null, + null, + new ArrayList() + ); + } + @SuppressWarnings("checkstyle:parameternumber") private Mapping( String sourceName, String constant, String javaExpression, String defaultJavaExpression, String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index c09ff785a3..8471210d12 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -21,6 +21,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -30,7 +31,9 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.accessor.Accessor; /** * Encapsulates all options specifiable on a mapping method @@ -234,7 +237,7 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S if ( getBeanMapping() == null ) { if ( inherited.getBeanMapping() != null ) { - setBeanMapping( inherited.getBeanMapping() ); + setBeanMapping( BeanMapping.forInheritance( inherited.getBeanMapping() ) ); } } @@ -290,8 +293,23 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S setMappings( newMappings ); } + } - markAsFullyInitialized(); + public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, FormattingMessager messager, + TypeFactory typeFactory ) { + CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); + Map writeAccessors = method.getResultType().getPropertyWriteAccessors( cms ); + List mappedPropertyNames = new ArrayList(); + for ( String targetMappingName : mappings.keySet() ) { + mappedPropertyNames.add( targetMappingName.split( "\\." )[0] ); + } + for ( String targetPropertyName : writeAccessors.keySet() ) { + if ( !mappedPropertyNames.contains( targetPropertyName ) ) { + Mapping mapping = Mapping.forIgnore( targetPropertyName ); + mapping.init( method, messager, typeFactory ); + mappings.put( targetPropertyName, Arrays.asList( mapping ) ); + } + } } private void filterNestedTargetIgnores( Map> mappings) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index ec56229fc5..caed18144d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -495,6 +495,11 @@ else if ( applicableReversePrototypeMethods.size() > 1 ) { } } + // @BeanMapping( ignoreByDefault = true ) + if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isignoreByDefault() ) { + mappingOptions.applyIgnoreAll( mappingOptions, method, messager, typeFactory ); + } + mappingOptions.markAsFullyInitialized(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java index 97b6b79ce5..e4b2809884 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.ignore; +import org.mapstruct.BeanMapping; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -37,6 +38,9 @@ public interface AnimalMapper { }) AnimalDto animalToDto(Animal animal); - @InheritInverseConfiguration + @BeanMapping( ignoreByDefault = true ) + AnimalDto animalToDtoIgnoreAll(Animal animal); + + @InheritInverseConfiguration( name = "animalToDto" ) Animal animalDtoToAnimal(AnimalDto animalDto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 170fe31136..c81111b9ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -56,6 +56,22 @@ public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { assertThat( animalDto.publicColor ).isNull(); } + @Test + @IssueKey("1392") + public void shouldIgnoreAllTargetPropertiesWithNoUnmappedTargetWarnings() { + Animal animal = new Animal( "Bruno", 100, 23, "black" ); + + AnimalDto animalDto = AnimalMapper.INSTANCE.animalToDtoIgnoreAll( animal ); + + assertThat( animalDto ).isNotNull(); + assertThat( animalDto.getName() ).isNull(); + assertThat( animalDto.getSize() ).isNull(); + assertThat( animalDto.getAge() ).isNull(); + assertThat( animalDto.publicAge ).isNull(); + assertThat( animalDto.getColor() ).isNull(); + assertThat( animalDto.publicColor ).isNull(); + } + @Test @IssueKey("337") public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java new file mode 100644 index 0000000000..ca0b6c53d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +/** + * + * @author Sjaak Derksen + */ +public class ExpandedToolbox { + + private String brand; + private Hammer hammer; + private Wrench wrench; + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public Hammer getHammer() { + return hammer; + } + + public void setHammer(Hammer hammer) { + this.hammer = hammer; + } + + public Wrench getWrench() { + return wrench; + } + + public void setWrench(Wrench wrench) { + this.wrench = wrench; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java new file mode 100644 index 0000000000..a340d57139 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java @@ -0,0 +1,73 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +/** + * + * @author Sjaak Derksen + */ +public class FlattenedToolBox { + + private String brand; + private String hammerDescription; + private Integer hammerSize; + private Boolean wrenchIsBahco; + private String wrenchDescription; + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getHammerDescription() { + return hammerDescription; + } + + public void setHammerDescription(String hammerDescription) { + this.hammerDescription = hammerDescription; + } + + public Integer getHammerSize() { + return hammerSize; + } + + public void setHammerSize(Integer hammerSize) { + this.hammerSize = hammerSize; + } + + public Boolean getWrenchIsBahco() { + return wrenchIsBahco; + } + + public void setWrenchIsBahco(Boolean wrenchIsBahco) { + this.wrenchIsBahco = wrenchIsBahco; + } + + public String getWrenchDescription() { + return wrenchDescription; + } + + public void setWrenchDescription(String wrenchDescription) { + this.wrenchDescription = wrenchDescription; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java new file mode 100644 index 0000000000..760ebe31b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +/** + * + * @author Sjaak Derksen + */ +public class Hammer { + + private Integer size; + private String description; + + public Integer getSize() { + return size; + } + + public void setSize(Integer size) { + this.size = size; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java new file mode 100644 index 0000000000..30cd86a787 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java @@ -0,0 +1,64 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Test for ignoring properties during the mapping. + * + * @author Sjaak Derksen + */ +@WithClasses({ + ExpandedToolbox.class, + Hammer.class, + Wrench.class, + FlattenedToolBox.class, + ToolBoxMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class IgnorePropertyTest { + + @Test + @IssueKey("1392") + public void shouldIgnoreAll() { + FlattenedToolBox toolboxSource = new FlattenedToolBox(); + toolboxSource.setBrand( "Stanley" ); + toolboxSource.setHammerDescription( "heavy" ); + toolboxSource.setHammerSize( 5 ); + toolboxSource.setWrenchIsBahco( Boolean.TRUE ); + toolboxSource.setWrenchDescription( "generic use" ); + + ExpandedToolbox toolboxTarget = ToolBoxMapper.INSTANCE.expand( toolboxSource ); + + assertThat( toolboxTarget ).isNotNull(); + assertThat( toolboxTarget.getBrand() ).isNull(); + assertThat( toolboxTarget.getHammer() ).isNotNull(); + assertThat( toolboxTarget.getHammer().getDescription() ).isEqualTo( "heavy" ); + assertThat( toolboxTarget.getHammer().getSize() ).isNull(); + assertThat( toolboxTarget.getWrench() ).isNull(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java new file mode 100644 index 0000000000..b16e89f351 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ToolBoxMapper { + + ToolBoxMapper INSTANCE = Mappers.getMapper( ToolBoxMapper.class ); + + @BeanMapping(ignoreByDefault = true) + @Mapping( target = "hammer.description", source = "hammerDescription" ) + ExpandedToolbox expand( FlattenedToolBox toolbox ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java new file mode 100644 index 0000000000..d40d0295e9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.expand; + +/** + * + * @author Sjaak Derksen + */ +public class Wrench { + + boolean bahco; + String description; + + public boolean isBahco() { + return bahco; + } + + public void setBahco(boolean bahco) { + this.bahco = bahco; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java new file mode 100644 index 0000000000..ddda507356 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java @@ -0,0 +1,57 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +import java.util.Date; + +/** + * + * @author Sjaak Derksen + */ +public class BaseEntity { + + private Long key; + private Date creationDate; + private Date modificationDate; + + public Long getKey() { + return key; + } + + public void setKey(Long key) { + this.key = key; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public Date getModificationDate() { + return modificationDate; + } + + public void setModificationDate(Date modificationDate) { + this.modificationDate = modificationDate; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java new file mode 100644 index 0000000000..6f23727465 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class HammerDto extends ToolDto { + + private Integer toolSize; + + public Integer getToolSize() { + return toolSize; + } + + public void setToolSize(Integer toolSize) { + this.toolSize = toolSize; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java new file mode 100644 index 0000000000..19f6143699 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class HammerEntity extends ToolEntity { + private Integer size; + + public Integer getSize() { + return size; + } + + public void setSize(Integer size) { + this.size = size; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java new file mode 100644 index 0000000000..d9ef3b377e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java @@ -0,0 +1,90 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +import java.util.Date; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * Test for ignoring properties during the mapping. + * + * @author Sjaak Derksen + */ +@WithClasses({ + HammerDto.class, + HammerEntity.class, + ToolEntity.class, + BaseEntity.class, + ToolDto.class, + WorkBenchDto.class, + WorkBenchEntity.class, + ToolMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class IgnorePropertyTest { + + @Test + @IssueKey("1392") + /** + * Should not issue warnings on unmapped target properties + */ + public void shouldIgnoreAllExeptOveriddenInherited() { + HammerDto hammer = new HammerDto(); + hammer.setToolType( "smash" ); + hammer.setToolSize( 5 ); + + HammerEntity toolTarget = ToolMapper.INSTANCE.mapHammer( hammer ); + + assertThat( toolTarget ).isNotNull(); + assertThat( toolTarget.getSize() ).isNull(); + assertThat( toolTarget.getType() ).isEqualTo( "smash" ); + assertThat( toolTarget.getKey() ).isNull(); + assertThat( toolTarget.getCreationDate() ).isNull(); + assertThat( toolTarget.getModificationDate() ).isNull(); + + } + + @Test + @IssueKey("1392") + public void shouldIgnoreBase() { + + WorkBenchDto workBenchDto = new WorkBenchDto(); + workBenchDto.setArticleName( "MyBench" ); + workBenchDto.setArticleDescription( "Beautiful" ); + workBenchDto.setCreationDate( new Date() ); + workBenchDto.setModificationDate( new Date() ); + + WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBench( workBenchDto ); + + assertThat( benchTarget ).isNotNull(); + assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" ); + assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" ); + assertThat( benchTarget.getKey() ).isNull(); + assertThat( benchTarget.getModificationDate() ).isNull(); + assertThat( benchTarget.getCreationDate() ).isNull(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java new file mode 100644 index 0000000000..335cbdcc2c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class ToolDto { + + private String toolType; + + public String getToolType() { + return toolType; + } + + public void setToolType(String toolType) { + this.toolType = toolType; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java new file mode 100644 index 0000000000..94f664ce18 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class ToolEntity extends BaseEntity { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java new file mode 100644 index 0000000000..7d582b384c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ToolMapper { + + ToolMapper INSTANCE = Mappers.getMapper( ToolMapper.class ); + + // + @InheritConfiguration( name = "mapTool" ) + @BeanMapping( ignoreByDefault = true ) + HammerEntity mapHammer(HammerDto source); + + @Mapping( target = "type", source = "toolType" ) + @InheritConfiguration( name = "mapBase" ) + ToolEntity mapTool(ToolDto source); + + // demonstrates that all the businss stuff is mapped (implicit-by-name and defined) + @InheritConfiguration( name = "mapBase" ) + @Mapping(target = "description", source = "articleDescription") + WorkBenchEntity mapBench(WorkBenchDto source); + + // ignore all the base properties by default + @BeanMapping( ignoreByDefault = true ) + BaseEntity mapBase(Object o); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java new file mode 100644 index 0000000000..ffee3a8e6f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class WorkBenchDto extends BaseEntity { + + private String articleName; + private String articleDescription; + + public String getArticleName() { + return articleName; + } + + public void setArticleName(String articleName) { + this.articleName = articleName; + } + + public String getArticleDescription() { + return articleDescription; + } + + public void setArticleDescription(String articleDescription) { + this.articleDescription = articleDescription; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java new file mode 100644 index 0000000000..d5dbb37579 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.ignore.inherit; + +/** + * + * @author Sjaak Derksen + */ +public class WorkBenchEntity extends BaseEntity { + + private String articleName; + private String description; + + public String getArticleName() { + return articleName; + } + + public void setArticleName(String articleName) { + this.articleName = articleName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + +} From 5540efc482f28b0a3c758702aa7bb4a6f0d14e42 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sat, 21 Apr 2018 18:59:29 +0200 Subject: [PATCH 0219/1006] #1425 Added findType to VirtualMappingMethod and use it in all builtin templates Together with the includeModel directive this will ensure that the type will be written to the file as a FQN if required, otherwise as a simple name. --- .../tests/FullFeatureCompilationTest.java | 1 + .../internal/model/VirtualMappingMethod.java | 23 ++++++++ .../CalendarToXmlGregorianCalendar.ftl | 8 +-- .../builtin/CalendarToZonedDateTime.ftl | 4 +- .../builtin/DateToXmlGregorianCalendar.ftl | 8 +-- .../model/source/builtin/JaxbElemToValue.ftl | 2 +- .../JodaDateTimeToXmlGregorianCalendar.ftl | 6 +-- ...odaLocalDateTimeToXmlGregorianCalendar.ftl | 8 +-- .../JodaLocalDateToXmlGregorianCalendar.ftl | 8 +-- .../JodaLocalTimeToXmlGregorianCalendar.ftl | 8 +-- .../LocalDateToXmlGregorianCalendar.ftl | 8 +-- .../builtin/StringToXmlGregorianCalendar.ftl | 14 ++--- .../XmlGregorianCalendarToCalendar.ftl | 4 +- .../builtin/XmlGregorianCalendarToDate.ftl | 2 +- .../XmlGregorianCalendarToJodaDateTime.ftl | 48 ++++++++--------- .../XmlGregorianCalendarToJodaLocalDate.ftl | 10 ++-- ...mlGregorianCalendarToJodaLocalDateTime.ftl | 24 ++++----- .../XmlGregorianCalendarToJodaLocalTime.ftl | 18 +++---- .../XmlGregorianCalendarToLocalDate.ftl | 4 +- .../builtin/XmlGregorianCalendarToString.ftl | 6 +-- .../builtin/ZonedDateTimeToCalendar.ftl | 4 +- .../ap/test/bugs/_1425/Issue1425Mapper.java | 39 ++++++++++++++ .../ap/test/bugs/_1425/Issue1425Test.java | 52 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1425/Source.java | 37 +++++++++++++ .../mapstruct/ap/test/bugs/_1425/Target.java | 37 +++++++++++++ 25 files changed, 286 insertions(+), 97 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java index f53b673d90..46dc4ce6bd 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java @@ -73,6 +73,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorType proces case ECLIPSE_JDT_JAVA_6: case ORACLE_JAVA_7: case ECLIPSE_JDT_JAVA_7: + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1425/*.java" ); additionalExcludes.add( "**/java8*/**/*.java" ); break; case ORACLE_JAVA_9: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java index dda42376b4..dbaec580e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java @@ -56,6 +56,29 @@ public Set getImportTypes() { return importTypes; } + /** + * Finds a {@link Type} by a given name. The {@code name} will be compared to the fully-qualified and also simple + * names of the {@code importTypes}. + * + * @param name Fully-qualified or simple name of the type. + * + * @return Found type, never null. + * + * @throws IllegalArgumentException In case no {@link Type} was found for given name. + */ + public Type findType(String name) { + for ( Type type : importTypes ) { + if ( type.getFullyQualifiedName().contentEquals( name ) ) { + return type; + } + if ( type.getName().contentEquals( name ) ) { + return type; + } + } + + throw new IllegalArgumentException( "No type for given name '" + name + "' found in 'importTypes'." ); + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl index b716b46f2c..2e74ffa071 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl @@ -19,17 +19,17 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( Calendar cal ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Calendar")/> cal ) { if ( cal == null ) { return null; } try { - GregorianCalendar gcal = new GregorianCalendar(); + <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>(); gcal.setTimeInMillis( cal.getTimeInMillis() ); - return DatatypeFactory.newInstance().newXMLGregorianCalendar( gcal ); + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( gcal ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl index 8ca07603a3..03815fac7c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl @@ -19,10 +19,10 @@ limitations under the License. --> -private ZonedDateTime ${name}(Calendar cal) { +private <@includeModel object=findType("ZonedDateTime")/> ${name}(<@includeModel object=findType("Calendar")/> cal) { if ( cal == null ) { return null; } - return ZonedDateTime.ofInstant( cal.toInstant(), cal.getTimeZone().toZoneId() ); + return <@includeModel object=findType("ZonedDateTime")/>.ofInstant( cal.toInstant(), cal.getTimeZone().toZoneId() ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl index 6442c12ec7..3ed932884d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl @@ -19,17 +19,17 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( Date date ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Date")/> date ) { if ( date == null ) { return null; } try { - GregorianCalendar c = new GregorianCalendar(); + <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); c.setTime( date ); - return DatatypeFactory.newInstance().newXMLGregorianCalendar( c ); + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl index af314d442f..bc7da073b9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl @@ -19,7 +19,7 @@ limitations under the License. --> -private T ${name}( JAXBElement element ) { +private T ${name}( <@includeModel object=findType("JAXBElement") raw=true/> element ) { if ( element == null ) { return null; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl index 386ea8b8fb..65677e7313 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl @@ -19,13 +19,13 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( DateTime dt ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("DateTime")/> dt ) { if ( dt == null ) { return null; } try { - return DatatypeFactory.newInstance().newXMLGregorianCalendar( + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), @@ -35,7 +35,7 @@ private XMLGregorianCalendar ${name}( DateTime dt ) { dt.getMillisOfSecond(), dt.getZone().getOffset( null ) / 60000 ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl index 04c5c98108..3e177214e8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl @@ -19,13 +19,13 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( LocalDateTime dt ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDateTime")/> dt ) { if ( dt == null ) { return null; } try { - return DatatypeFactory.newInstance().newXMLGregorianCalendar( + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), @@ -33,9 +33,9 @@ private XMLGregorianCalendar ${name}( LocalDateTime dt ) { dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(), - DatatypeConstants.FIELD_UNDEFINED ); + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl index f3244626e3..5b77e2314b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl @@ -19,19 +19,19 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( LocalDate dt ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDate")/> dt ) { if ( dt == null ) { return null; } try { - return DatatypeFactory.newInstance().newXMLGregorianCalendarDate( + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), - DatatypeConstants.FIELD_UNDEFINED ); + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl index c518fb8524..2add1e79c2 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl @@ -19,20 +19,20 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( LocalTime dt ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalTime")/> dt ) { if ( dt == null ) { return null; } try { - return DatatypeFactory.newInstance().newXMLGregorianCalendarTime( + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarTime( dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(), - DatatypeConstants.FIELD_UNDEFINED ); + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl index 6103838c80..e1139fed23 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl @@ -19,20 +19,20 @@ limitations under the License. --> -private static XMLGregorianCalendar ${name}( java.time.LocalDate localDate ) { +private static <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) { if ( localDate == null ) { return null; } try { - return DatatypeFactory.newInstance().newXMLGregorianCalendarDate( + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth(), - DatatypeConstants.FIELD_UNDEFINED + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl index 0cac9015ce..0e8db79d13 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl @@ -19,26 +19,26 @@ limitations under the License. --> -private XMLGregorianCalendar ${name}( String date, String dateFormat ) { +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String date, String dateFormat ) { if ( date == null ) { return null; } try { if ( dateFormat != null ) { - DateFormat df = new SimpleDateFormat( dateFormat ); - GregorianCalendar c = new GregorianCalendar(); + <@includeModel object=findType("DateFormat")/> df = new <@includeModel object=findType("SimpleDateFormat")/>( dateFormat ); + <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); c.setTime( df.parse( date ) ); - return DatatypeFactory.newInstance().newXMLGregorianCalendar( c ); + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c ); } else { - return DatatypeFactory.newInstance().newXMLGregorianCalendar( date ); + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( date ); } } - catch ( DatatypeConfigurationException ex ) { + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { throw new RuntimeException( ex ); } - catch ( ParseException ex ) { + catch ( <@includeModel object=findType("ParseException")/> ex ) { throw new RuntimeException( ex ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl index 782ba83d7e..2021d776df 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl @@ -19,12 +19,12 @@ limitations under the License. --> -private Calendar ${name}( XMLGregorianCalendar xcal ) { +private <@includeModel object=findType("Calendar")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - Calendar cal = Calendar.getInstance(); + <@includeModel object=findType("Calendar")/> cal = <@includeModel object=findType("Calendar")/>.getInstance(); cal.setTimeInMillis( xcal.toGregorianCalendar().getTimeInMillis() ); return cal; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl index a62cf38cdf..88fe71b486 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl @@ -19,7 +19,7 @@ limitations under the License. --> -private static Date ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("java.util.Date")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl index 80cdf46610..1e4799dc89 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl @@ -19,33 +19,33 @@ limitations under the License. --> -private static DateTime ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("DateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - if ( xcal.getYear() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMonth() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getDay() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getHour() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMinute() != DatatypeConstants.FIELD_UNDEFINED + if ( xcal.getYear() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMonth() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getDay() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getHour() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMinute() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { - if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMillisecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED ) { - return new DateTime( xcal.getYear(), + if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMillisecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getTimezone() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), xcal.getMinute(), xcal.getSecond(), xcal.getMillisecond(), - DateTimeZone.forOffsetMillis( xcal.getTimezone() * 60000 ) + <@includeModel object=findType("DateTimeZone")/>.forOffsetMillis( xcal.getTimezone() * 60000 ) ); } - else if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMillisecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new DateTime( xcal.getYear(), + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMillisecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), @@ -54,19 +54,19 @@ private static DateTime ${name}( XMLGregorianCalendar xcal ) { xcal.getMillisecond() ); } - else if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED ) { - return new DateTime( xcal.getYear(), + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getTimezone() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), xcal.getMinute(), xcal.getSecond(), - DateTimeZone.forOffsetMillis( xcal.getTimezone() * 60000 ) + <@includeModel object=findType("DateTimeZone")/>.forOffsetMillis( xcal.getTimezone() * 60000 ) ); } - else if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new DateTime( xcal.getYear(), + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), @@ -74,17 +74,17 @@ private static DateTime ${name}( XMLGregorianCalendar xcal ) { xcal.getSecond() ); } - else if ( xcal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED ) { - return new DateTime( xcal.getYear(), + else if ( xcal.getTimezone() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), xcal.getMinute(), - DateTimeZone.forOffsetMillis( xcal.getTimezone() * 60000 ) + <@includeModel object=findType("DateTimeZone")/>.forOffsetMillis( xcal.getTimezone() * 60000 ) ); } else { - return new DateTime( xcal.getYear(), + return new <@includeModel object=findType("DateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl index 24ec1391d7..e51d87a13e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl @@ -19,15 +19,15 @@ limitations under the License. --> -private static LocalDate ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("org.joda.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - if ( xcal.getYear() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMonth() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getDay() != DatatypeConstants.FIELD_UNDEFINED ) { - return new LocalDate( xcal.getYear(), xcal.getMonth(), xcal.getDay() ); + if ( xcal.getYear() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMonth() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getDay() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("org.joda.time.LocalDate")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay() ); } return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl index a57e607baa..edcf3e3a33 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl @@ -19,20 +19,20 @@ limitations under the License. --> -private static LocalDateTime ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("org.joda.time.LocalDateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - if ( xcal.getYear() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMonth() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getDay() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getHour() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMinute() != DatatypeConstants.FIELD_UNDEFINED + if ( xcal.getYear() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMonth() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getDay() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getHour() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMinute() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { - if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMillisecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new LocalDateTime( xcal.getYear(), + if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMillisecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("org.joda.time.LocalDateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), @@ -41,8 +41,8 @@ private static LocalDateTime ${name}( XMLGregorianCalendar xcal ) { xcal.getMillisecond() ); } - else if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new LocalDateTime( xcal.getYear(), + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("org.joda.time.LocalDateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), @@ -51,7 +51,7 @@ private static LocalDateTime ${name}( XMLGregorianCalendar xcal ) { ); } else { - return new LocalDateTime( xcal.getYear(), + return new <@includeModel object=findType("org.joda.time.LocalDateTime")/>( xcal.getYear(), xcal.getMonth(), xcal.getDay(), xcal.getHour(), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl index 9d0c2af94d..1396324452 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl @@ -19,30 +19,30 @@ limitations under the License. --> -private static LocalTime ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("org.joda.time.LocalTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - if ( xcal.getHour() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMinute() != DatatypeConstants.FIELD_UNDEFINED ) { - if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED - && xcal.getMillisecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new LocalTime( xcal.getHour(), + if ( xcal.getHour() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMinute() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMillisecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("org.joda.time.LocalTime")/>( xcal.getHour(), xcal.getMinute(), xcal.getSecond(), xcal.getMillisecond() ); } - else if ( xcal.getSecond() != DatatypeConstants.FIELD_UNDEFINED ) { - return new LocalTime( + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return new <@includeModel object=findType("org.joda.time.LocalTime")/>( xcal.getHour(), xcal.getMinute(), xcal.getSecond() ); } else { - return new LocalTime( xcal.getHour(), + return new <@includeModel object=findType("org.joda.time.LocalTime")/>( xcal.getHour(), xcal.getMinute() ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl index 2a53fcd6eb..fc69fdd5b3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl @@ -19,10 +19,10 @@ limitations under the License. --> -private static java.time.LocalDate ${name}( XMLGregorianCalendar xcal ) { +private static <@includeModel object=findType("java.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; } - return java.time.LocalDate.of( xcal.getYear(), xcal.getMonth(), xcal.getDay() ); + return <@includeModel object=findType("java.time.LocalDate")/>.of( xcal.getYear(), xcal.getMonth(), xcal.getDay() ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl index 63437c8b6a..5a705aa74a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl @@ -19,7 +19,7 @@ limitations under the License. --> -private String ${name}( XMLGregorianCalendar xcal, String dateFormat ) { +private String ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal, String dateFormat ) { if ( xcal == null ) { return null; } @@ -28,8 +28,8 @@ private String ${name}( XMLGregorianCalendar xcal, String dateFormat ) { return xcal.toString(); } else { - Date d = xcal.toGregorianCalendar().getTime(); - SimpleDateFormat sdf = new SimpleDateFormat( dateFormat ); + <@includeModel object=findType("java.util.Date")/> d = xcal.toGregorianCalendar().getTime(); + <@includeModel object=findType("SimpleDateFormat")/> sdf = new <@includeModel object=findType("SimpleDateFormat")/>( dateFormat ); return sdf.format( d ); } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl index 88c943e5fc..47a951a29c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl @@ -19,12 +19,12 @@ limitations under the License. --> -private Calendar ${name}(ZonedDateTime dateTime) { +private <@includeModel object=findType("Calendar")/> ${name}(<@includeModel object=findType("ZonedDateTime")/> dateTime) { if ( dateTime == null ) { return null; } - Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( dateTime.getZone() ) ); + <@includeModel object=findType("Calendar")/> instance = <@includeModel object=findType("Calendar")/>.getInstance( TimeZone.getTimeZone( dateTime.getZone() ) ); instance.setTimeInMillis( dateTime.toInstant().toEpochMilli() ); return instance; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java new file mode 100644 index 0000000000..f61f8c4a7c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1425; + +import java.time.LocalDate; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper +public abstract class Issue1425Mapper { + + public static final Issue1425Mapper INSTANCE = Mappers.getMapper( Issue1425Mapper.class ); + + public abstract Target map(Source source); + + LocalDate now() { + return LocalDate.now(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java new file mode 100644 index 0000000000..15ee02797d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1425; + +import org.joda.time.LocalDate; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Christian Bandowski + */ +@WithClasses({ + Issue1425Mapper.class, + Source.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1425") +public class Issue1425Test { + + @Test + public void shouldTestMappingLocalDates() { + Source source = new Source(); + source.setValue( LocalDate.parse( "2018-04-18" ) ); + + Target target = Issue1425Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "2018-04-18" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java new file mode 100644 index 0000000000..2c97acc5fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1425; + +import org.joda.time.LocalDate; + +/** + * @author Christian Bandowski + */ +public class Source { + + private LocalDate value; + + public LocalDate getValue() { + return value; + } + + public void setValue(LocalDate value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java new file mode 100644 index 0000000000..da1d0394ae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1425; + +import java.time.LocalDate; + +/** + * @author Christian Bandowski + */ +public class Target { + + private LocalDate value; + + public LocalDate getValue() { + return value; + } + + public void setValue(LocalDate value) { + this.value = value; + } +} From 2f44bab9c98d83061d02b345dd68807f0229928d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 21 Apr 2018 19:07:59 +0200 Subject: [PATCH 0220/1006] Add Christian to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index a7d53e0d2b..e83d9d683d 100644 --- a/copyright.txt +++ b/copyright.txt @@ -3,6 +3,7 @@ Alexandr Shalugin - https://github.com/shalugin Andreas Gudian - https://github.com/agudian +Christian Bandowski - https://github.com/chris922 Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman From 47ffb041064bfa0aa382fd6f3322ddff5a07bdac Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Apr 2018 16:33:14 +0200 Subject: [PATCH 0221/1006] #1436 Add since tag to new API elements --- core-jdk8/src/main/java/org/mapstruct/Mapping.java | 2 ++ core/src/main/java/org/mapstruct/Mapping.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java index 4358729e50..f8a611abcb 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java @@ -156,6 +156,8 @@ * * @return An expression specifying a defaultValue for the designated target property if the designated source * property is null + * + * @since 1.3 */ String defaultExpression() default ""; diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index ebe545de60..849e8bd871 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -154,6 +154,8 @@ * * @return An expression specifying a defaultValue for the designated target property if the designated source * property is null + * + * @since 1.3 */ String defaultExpression() default ""; From 4a05c8d5f14a287242bfd5ec67ed75b86e141862 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 24 Apr 2018 21:36:48 +0200 Subject: [PATCH 0222/1006] #1433 Support for lifecycle methods for builders When doing mappings with builder the effective type should be considered for lifecycle callback methods --- .../model/LifecycleCallbackFactory.java | 8 +- .../ap/internal/model/BeanMappingMethod.ftl | 10 ++- .../BuilderLifecycleCallbacksTest.java | 67 ++++++++++++++++ .../ap/test/builder/lifecycle/Item.java | 52 ++++++++++++ .../ap/test/builder/lifecycle/ItemDto.java | 35 ++++++++ .../builder/lifecycle/MappingContext.java | 79 +++++++++++++++++++ .../ap/test/builder/lifecycle/Order.java | 62 +++++++++++++++ .../ap/test/builder/lifecycle/OrderDto.java | 46 +++++++++++ .../test/builder/lifecycle/OrderMapper.java | 36 +++++++++ 9 files changed, 391 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java index b5f31160ee..6cad83b86d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java @@ -106,11 +106,17 @@ private static List collectLifecycleCallbackMe MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory() ); + Type targetType = method.getResultType(); + + if ( !method.isUpdateMethod() ) { + targetType = targetType.getEffectiveType(); + } + List> matchingMethods = selectors.getMatchingMethods( method, callbackMethods, Collections. emptyList(), - method.getResultType(), + targetType, SelectionCriteria.forLifecycleMethods( selectionParameters ) ); return toLifecycleCallbackMethodRefs( diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 81e475deb0..6bba770a78 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -21,8 +21,12 @@ --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { + <#assign targetType = resultType /> + <#if !existingInstanceMapping> + <#assign targetType = resultType.effectiveType /> + <#list beforeMappingReferencesWithoutMappingTarget as callback> - <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + <@includeModel object=callback targetBeanName=resultName targetType=targetType/> <#if !callback_has_next> @@ -38,7 +42,7 @@ <#list beforeMappingReferencesWithMappingTarget as callback> - <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + <@includeModel object=callback targetBeanName=resultName targetType=targetType/> <#if !callback_has_next> @@ -74,7 +78,7 @@ <#if callback_index = 0> - <@includeModel object=callback targetBeanName=resultName targetType=resultType/> + <@includeModel object=callback targetBeanName=resultName targetType=targetType/> <#if returnType.name != "void"> diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java new file mode 100644 index 0000000000..9ef7b2469e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java @@ -0,0 +1,67 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey( "1433" ) +@WithClasses( { + Item.class, + ItemDto.class, + MappingContext.class, + Order.class, + OrderDto.class, + OrderMapper.class +} ) +public class BuilderLifecycleCallbacksTest { + + @Test + public void lifecycleMethodsShouldBeInvoked() { + OrderDto source = new OrderDto(); + source.setCreator( "Filip" ); + ItemDto item1 = new ItemDto(); + item1.setName( "Laptop" ); + ItemDto item2 = new ItemDto(); + item2.setName( "Keyboard" ); + source.setItems( Arrays.asList( item1, item2 ) ); + MappingContext context = new MappingContext(); + + OrderMapper.INSTANCE.map( source, context ); + + assertThat( context.getInvokedMethods() ) + .contains( + "beforeWithBuilderTargetType", + "beforeWithBuilderTarget", + "afterWithBuilderTargetType", + "afterWithBuilderTarget" + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java new file mode 100644 index 0000000000..636a71b0ec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +/** + * @author Filip Hrisafov + */ +public class Item { + + private final String name; + + Item(Builder builder) { + this.name = builder.name; + } + + public String getName() { + return name; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Item create() { + return new Item( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java new file mode 100644 index 0000000000..a14d93265a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +/** + * @author Filip Hrisafov + */ +public class ItemDto { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java new file mode 100644 index 0000000000..5b4f6487f0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java @@ -0,0 +1,79 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetType; + +/** + * @author Filip Hrisafov + */ +public class MappingContext { + + private final List invokedMethods = new ArrayList(); + + @BeforeMapping + public void beforeWithTargetType(OrderDto source, @TargetType Class orderClass) { + invokedMethods.add( "beforeWithTargetType" ); + } + + @BeforeMapping + public void beforeWithBuilderTargetType(OrderDto source, @TargetType Class builderClass) { + invokedMethods.add( "beforeWithBuilderTargetType" ); + } + + @BeforeMapping + public void beforeWithTarget(OrderDto source, @MappingTarget Order order) { + invokedMethods.add( "beforeWithTarget" ); + } + + @BeforeMapping + public void beforeWithBuilderTarget(OrderDto source, @MappingTarget Order.Builder orderBuilder) { + invokedMethods.add( "beforeWithBuilderTarget" ); + } + + @AfterMapping + public void afterWithTargetType(OrderDto source, @TargetType Class orderClass) { + invokedMethods.add( "afterWithTargetType" ); + } + + @AfterMapping + public void afterWithBuilderTargetType(OrderDto source, @TargetType Class builderClass) { + invokedMethods.add( "afterWithBuilderTargetType" ); + } + + @AfterMapping + public void afterWithTarget(OrderDto source, @MappingTarget Order order) { + invokedMethods.add( "afterWithTarget" ); + } + + @AfterMapping + public void afterWithBuilderTarget(OrderDto source, @MappingTarget Order.Builder orderBuilder) { + invokedMethods.add( "afterWithBuilderTarget" ); + } + + public List getInvokedMethods() { + return invokedMethods; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java new file mode 100644 index 0000000000..b3d1d3621d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java @@ -0,0 +1,62 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Order { + + private final List items; + private final String creator; + + public Order(Builder builder) { + this.items = new ArrayList( builder.items ); + this.creator = builder.creator; + } + + public List getItems() { + return items; + } + + public String getCreator() { + return creator; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private List items = new ArrayList(); + private String creator; + + public Builder items(List items) { + this.items = items; + return this; + } + + public Order create() { + return new Order( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java new file mode 100644 index 0000000000..958a668c07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class OrderDto { + + private List items; + private String creator; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java new file mode 100644 index 0000000000..ccfcb42908 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.lifecycle; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OrderMapper { + + OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); + + Order map(OrderDto source, @Context MappingContext context); + + Item map(ItemDto source, @Context MappingContext context); +} From 2fe7f6be2b33ddd2a7de5ae207847478887d6b8f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 24 Apr 2018 21:39:28 +0200 Subject: [PATCH 0223/1006] #1387 Improve error message when unknown source parameter is used in Mapping --- .../model/source/SourceReference.java | 16 +++++++++- .../mapstruct/ap/internal/util/Message.java | 2 +- .../mapstruct/ap/internal/util/Strings.java | 8 +++-- .../ErroneousSourceTargetMapper2.java | 30 +++++++++++++++++++ .../SeveralSourceParametersTest.java | 22 ++++++++++++++ 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 60353dc94b..dba8266831 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -32,6 +32,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.Extractor; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -132,7 +133,20 @@ public SourceReference build() { String sourceParameterName = segments[0]; parameter = method.getSourceParameter( sourceParameterName ); if ( parameter == null ) { - reportMappingError( Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, sourceParameterName ); + reportMappingError( + Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, + sourceParameterName, + Strings.join( + method.getSourceParameters(), + ", ", + new Extractor() { + @Override + public String apply(Parameter parameter) { + return parameter.getName(); + } + } + ) + ); isValid = false; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 3a65e30cec..fb1bdfcb95 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -59,7 +59,7 @@ public enum Message { PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Default value and default expression are both defined in @Mapping, either define a default value or a default expression." ), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), - PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no parameter named \"%s\"." ), + PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no source parameter named \"%s\". Method source parameters are: \"%s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s). Did you mean \"%s\"?" ), PROPERTYMAPPING_NO_PRESENCE_CHECKER_FOR_SOURCE_TYPE( "Using custom source value presence checking strategy, but no presence checker found for %s in source type." ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index a4a000cccd..a14e4d8ada 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -98,10 +98,14 @@ public static String decapitalize(String string) { } public static String join(Iterable iterable, String separator) { + return join( iterable, separator, null ); + } + + public static String join(Iterable iterable, String separator, Extractor extractor) { StringBuilder sb = new StringBuilder(); boolean isFirst = true; - for ( Object object : iterable ) { + for ( T object : iterable ) { if ( !isFirst ) { sb.append( separator ); } @@ -109,7 +113,7 @@ public static String join(Iterable iterable, String separator) { isFirst = false; } - sb.append( object ); + sb.append( extractor == null ? object : extractor.apply( object ) ); } return sb.toString(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java new file mode 100644 index 0000000000..0bf5ed2520 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java @@ -0,0 +1,30 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.severalsources; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ErroneousSourceTargetMapper2 { + + @Mapping( target = "houseNumber", source = "houseNo") + DeliveryAddress addressAndAddressToDeliveryAddress(Address address, Person person); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java index f0e66c880e..dcb0aaaef2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java @@ -168,4 +168,26 @@ public void shouldMapSeveralSourceAttributesAndParameters() { }) public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { } + + @Test + @WithClasses({ + ErroneousSourceTargetMapper2.class, + Address.class, + Person.class, + DeliveryAddress.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousSourceTargetMapper2.class, + kind = Kind.ERROR, + line = 28, + messageRegExp = "Method has no source parameter named \"houseNo\"\\." + + " Method source parameters are: \"address, person\"\\." + ) + } + ) + public void shouldFailWhenSourcePropertyDoesNotMatchAnyOfTheSourceParameters() { + } } From 35f5400e0038cf5eca276de5504ef63ccb38d8dd Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sun, 1 Apr 2018 15:15:42 +0200 Subject: [PATCH 0224/1006] #1401 improvements by direct assigning constants --- .../mapstruct-reference-guide.asciidoc | 3 +- .../ap/internal/model/BeanMappingMethod.java | 3 +- .../ap/internal/model/PropertyMapping.java | 17 +- .../ap/internal/model/common/Type.java | 20 +- .../ap/internal/model/common/TypeFactory.java | 53 ++- .../creation/MappingResolverImpl.java | 12 + .../ap/internal/util/NativeTypes.java | 333 +++++++++++++++++ .../DateFormatValidatorFactoryTest.java | 2 + .../common/DefaultConversionContextTest.java | 2 + .../constants/ConstantOptimizingTest.java | 342 ++++++++++++++++++ .../source/constants/ErroneousMapper1.java | 2 +- .../source/constants/ErroneousMapper3.java | 2 +- .../source/constants/ErroneousMapper4.java | 2 +- .../source/constants/ErroneousMapper5.java | 2 +- .../source/constants/ErroneousMapper6.java | 46 +++ .../source/constants/SourceConstantsTest.java | 24 +- .../source/constants/SourceTargetMapper.java | 2 +- 17 files changed, 850 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 122d597347..39b393f7c0 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1918,7 +1918,8 @@ This chapter describes several advanced options which allow to fine-tune the beh [[default-values-and-constants]] === Default values and constants -Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values and are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. +Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values. When the target type is a primitive or a boxed type, the String value is taken literal. Bit / octal / decimal / hex patterns are allowed in such case as long as they are a valid literal. +In all other cases, constant or default values are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. A mapping with a constant must not include a reference to a source property. The following example shows some mappings using default values and constants: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 7eaf9f6599..506b4bf4eb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -496,13 +496,14 @@ else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKe propertyMapping = new ConstantMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) - .constantExpression( "\"" + mapping.getConstant() + "\"" ) + .constantExpression( mapping.getConstant() ) .targetProperty( targetProperty ) .targetPropertyName( mapping.getTargetName() ) .formattingParameters( mapping.getFormattingParameters() ) .selectionParameters( mapping.getSelectionParameters() ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) + .mirror( mapping.getMirror() ) .build(); handledTargets.add( mapping.getTargetName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 9f10ab2b40..3ed0abaf63 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; @@ -116,6 +117,7 @@ private static class MappingBuilderBase> extends protected List dependsOn; protected Set existingVariableNames; + protected AnnotationMirror mirror; MappingBuilderBase(Class selfType) { super( selfType ); @@ -146,6 +148,11 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { return (T) this; } + T mirror(AnnotationMirror mirror) { + this.mirror = mirror; + return (T) this; + } + private Type determineTargetType() { // This is a bean mapping method, so we know the result is a declared type DeclaredType resultType = (DeclaredType) method.getResultType().getEffectiveType().getTypeMirror(); @@ -359,7 +366,7 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { && ( !rhs.getSourceType().isPrimitive() || rhs.getSourcePresenceCheckerReference() != null) ) { // cannot check on null source if source is primitive unless it has a presence checker PropertyMapping build = new ConstantMappingBuilder() - .constantExpression( '"' + defaultValue + '"' ) + .constantExpression( defaultValue ) .formattingParameters( formattingParameters ) .selectionParameters( selectionParameters ) .dependsOn( dependsOn ) @@ -749,7 +756,12 @@ public ConstantMappingBuilder selectionParameters(SelectionParameters selectionP public PropertyMapping build() { // source String sourceErrorMessagePart = "constant '" + constantExpression + "'"; - Type sourceType = ctx.getTypeFactory().getType( String.class ); + + Type sourceType = ctx.getTypeFactory().getTypeForConstant( targetType, constantExpression ); + if ( String.class.getCanonicalName().equals( sourceType.getFullyQualifiedName() ) ) { + // convert to string + constantExpression = "\"" + constantExpression + "\""; + } Assignment assignment = null; if ( !targetType.isEnumType() ) { @@ -808,6 +820,7 @@ public PropertyMapping build() { else { ctx.getMessager().printMessage( method.getExecutable(), + mirror, Message.CONSTANTMAPPING_MAPPING_NOT_FOUND, sourceType, constantExpression, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 32f962b712..12f3f379ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -89,6 +89,8 @@ public class Type extends ModelElement implements Comparable { private final boolean isImported; private final boolean isVoid; private final boolean isStream; + private final boolean isBoxed; + private final boolean isOriginatedFromConstant; private final List enumConstants; @@ -111,7 +113,8 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, BuilderInfo builderInfo, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, - boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported) { + boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported, + boolean isBoxed, boolean isOriginatedFromConstant ) { this.typeUtils = typeUtils; this.elementUtils = elementUtils; @@ -135,6 +138,8 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.isStream = isStreamType; this.isImported = isImported; this.isVoid = typeMirror.getKind() == TypeKind.VOID; + this.isBoxed = isBoxed; + this.isOriginatedFromConstant = isOriginatedFromConstant; if ( isEnumType ) { enumConstants = new ArrayList(); @@ -384,7 +389,9 @@ public Type erasure() { isCollectionType, isMapType, isStream, - isImported + isImported, + isBoxed, + isOriginatedFromConstant ); } @@ -913,4 +920,13 @@ public List determineTypeArguments(Class superclass) { return null; } + + public boolean isBoxed() { + return isBoxed; + } + + public boolean hasOriginatedFromConstant() { + return isOriginatedFromConstant; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 8780596829..dc06e1f12b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -64,6 +64,7 @@ import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultBuilderProvider; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; +import org.mapstruct.ap.internal.util.NativeTypes; import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity; @@ -131,6 +132,10 @@ public Type getType(Class type) { } public Type getType(String canonicalName) { + return getType( canonicalName, false ); + } + + private Type getType(String canonicalName, boolean isOriginatedFromConstant) { TypeElement typeElement = elementUtils.getTypeElement( canonicalName ); if ( typeElement == null ) { @@ -139,7 +144,31 @@ public Type getType(String canonicalName) { ); } - return getType( typeElement ); + return getType( typeElement, isOriginatedFromConstant ); + } + + public Type getTypeForConstant(Type targetType, String literal) { + Type result = null; + if ( targetType.isPrimitive() ) { + TypeKind kind = targetType.getTypeMirror().getKind(); + boolean assignable = NativeTypes.isStringAssignable( kind, true, literal ); + if ( assignable ) { + result = getType( targetType.getTypeMirror(), true ); + } + } + else { + TypeKind boxedTypeKind = NativeTypes.getWrapperKind( targetType.getFullyQualifiedName() ); + if ( boxedTypeKind != null ) { + boolean assignable = NativeTypes.isStringAssignable( boxedTypeKind, false, literal ); + if ( assignable ) { + result = getType( targetType.getTypeMirror(), true ); + } + } + } + if ( result == null ) { + result = getType( String.class.getCanonicalName(), true ); + } + return result; } /** @@ -165,7 +194,15 @@ public Type getType(TypeElement typeElement) { return getType( typeElement.asType() ); } + private Type getType(TypeElement typeElement, boolean originatedFromConstant) { + return getType( typeElement.asType(), originatedFromConstant ); + } + public Type getType(TypeMirror mirror) { + return getType( mirror, false ); + } + + private Type getType(TypeMirror mirror, boolean originatedFromConstant) { if ( !canBeProcessed( mirror ) ) { throw new TypeHierarchyErroneousException( mirror ); } @@ -186,6 +223,7 @@ public Type getType(TypeMirror mirror) { TypeElement typeElement; Type componentType; boolean isImported; + boolean isBoxed = false; if ( mirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) mirror; @@ -207,6 +245,7 @@ public Type getType(TypeMirror mirror) { componentType = null; isImported = isImported( name, qualifiedName ); + isBoxed = NativeTypes.isWrapped( qualifiedName ); } else if ( mirror.getKind() == TypeKind.ARRAY ) { TypeMirror componentTypeMirror = getComponentType( mirror ); @@ -267,7 +306,9 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { isCollectionType, isMapType, isStreamType, - isImported + isImported, + isBoxed, + originatedFromConstant ); } @@ -315,8 +356,8 @@ public ExecutableType getMethodType(DeclaredType includingType, ExecutableElemen } /** - * Get the Type for given method as part of usedMapper. Possibly parameterized types in method declaration - * will be evaluated to concrete types then. + * Get the Type for given method as part of usedMapper. Possibly parameterized types in method declaration will be + * evaluated to concrete types then. * * @param includingType the type on which's scope the method type shall be evaluated * @param method the method @@ -479,7 +520,9 @@ private ImplementationType getImplementationType(TypeMirror mirror) { implementationType.isCollectionType(), implementationType.isMapType(), implementationType.isStreamType(), - isImported( implementationType.getName(), implementationType.getFullyQualifiedName() ) + isImported( implementationType.getName(), implementationType.getFullyQualifiedName() ), + implementationType.isBoxed(), + implementationType.hasOriginatedFromConstant() ); return implementation.createNew( replacement ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index d6f5050327..81b346e0c8 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -253,6 +253,18 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { return simpleAssignment; } + // At this point the SourceType will either + // 1. be a String + // 2. or when its a primitive / wrapped type and analysis successful equal to its TargetType. But in that + // case it should have been direct assignable. + // In case of 1. and the target type is still a wrapped or primitive type we must assume that the check + // in NativeType is not successful. We don't want to go through type conversion, double mappings etc. + // with something that we already know to be wrong. + if ( sourceType.hasOriginatedFromConstant() && ( targetType.isPrimitive() || targetType.isBoxed() ) ) { + // TODO: convey some error message + return null; + } + // then type conversion Assignment conversion = resolveViaConversion( sourceType, targetType ); if ( conversion != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index d73bacd73c..db61bb7f33 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -25,6 +25,8 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.regex.Pattern; +import javax.lang.model.type.TypeKind; /** * Provides functionality around the Java primitive data types and their wrapper @@ -37,6 +39,195 @@ public class NativeTypes { private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES; private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPES; private static final Set> NUMBER_TYPES = new HashSet>(); + private static final Map WRAPPER_NAME_TO_PRIMITIVE_TYPES; + + private static final Pattern PTRN_HEX = Pattern.compile( "^0[x|X].*" ); + private static final Pattern PTRN_OCT = Pattern.compile( "^0_*[0-7].*" ); + private static final Pattern PTRN_BIN = Pattern.compile( "^0[b|B].*" ); + private static final Pattern PTRN_FLOAT_DEC_ZERO = Pattern.compile( "^[^eE]*[1-9].*[eE]?.*" ); + private static final Pattern PTRN_FLOAT_HEX_ZERO = Pattern.compile( "^[^pP]*[1-9a-fA-F].*[pP]?.*" ); + + private static final Pattern PTRN_SIGN = Pattern.compile( "^[\\+|-]" ); + + private static final Pattern PTRN_LONG = Pattern.compile( "[l|L]$" ); + private static final Pattern PTRN_FLOAT = Pattern.compile( "[f|F]$" ); + private static final Pattern PTRN_DOUBLE = Pattern.compile( "[d|D]$" ); + + private static final Pattern PTRN_FAULTY_UNDERSCORE_INT = Pattern.compile( "^_|_$|-_|_-|\\+_|_\\+" ); + private static final Pattern PTRN_FAULTY_UNDERSCORE_FLOAT = Pattern.compile( "^_|_$|-_|_-|\\+_|_\\+|\\._|_\\." ); + private static final Pattern PTRN_FAULTY_DEC_UNDERSCORE_FLOAT = Pattern.compile( "_e|_E|e_|E_" ); + private static final Pattern PTRN_FAULTY_HEX_UNDERSCORE_FLOAT = Pattern.compile( "_p|_P|p_|P_" ); + + private static final Map VALIDATORS = initValidators(); + + private interface NumberFormatValidator { + + boolean validate(boolean isPrimitive, String s); + } + + private abstract static class NumberRepresentation { + + int radix; + String val; + boolean isIntegralType; + boolean isLong; + boolean isFloat; + boolean isPrimitive; + + NumberRepresentation(String in, boolean isIntegralType, boolean isLong, boolean isFloat, boolean isPrimitive) { + this.isLong = isLong; + this.isFloat = isFloat; + this.isIntegralType = isIntegralType; + this.isPrimitive = isPrimitive; + + String valWithoutSign; + boolean isNegative = in.startsWith( "-" ); + boolean hasSign = PTRN_SIGN.matcher( in ).find(); + if ( hasSign ) { + valWithoutSign = in.substring( 1 ); + } + else { + valWithoutSign = in; + } + if ( PTRN_HEX.matcher( valWithoutSign ).matches() ) { + // hex + radix = 16; + val = (isNegative ? "-" : "") + valWithoutSign.substring( 2 ); + } + else if ( PTRN_BIN.matcher( valWithoutSign ).matches() ) { + // binary + radix = 2; + val = (isNegative ? "-" : "") + valWithoutSign.substring( 2 ); + } + else if ( PTRN_OCT.matcher( valWithoutSign ).matches() ) { + // octal + radix = 8; + val = (isNegative ? "-" : "") + valWithoutSign.substring( 1 ); + } + else { + // decimal + radix = 10; + val = (isNegative ? "-" : "") + valWithoutSign; + } + } + + abstract boolean parse(String val, int radix); + + boolean validate() { + try { + strip(); + return parse( val, radix ); + } + catch ( NumberFormatException ex ) { + return false; + } + } + + void strip() { + if ( isIntegralType ) { + removeAndValidateIntegerLiteralSuffix(); + removeAndValidateIntegerLiteralUnderscore(); + } + else { + removeAndValidateFloatingPointLiteralSuffix(); + removeAndValidateFloatingPointLiteralUnderscore(); + } + } + + /** + * remove java7+ underscores from the input + */ + void removeAndValidateIntegerLiteralUnderscore() { + if ( PTRN_FAULTY_UNDERSCORE_INT.matcher( val ).find() ) { + throw new NumberFormatException("Improperly placed underscores"); + } + else { + val = val.replace( "_", "" ); + } + } + + /** + * remove java7+ underscores from the input + */ + void removeAndValidateFloatingPointLiteralUnderscore() { + boolean isHex = radix == 16; + if ( PTRN_FAULTY_UNDERSCORE_FLOAT.matcher( val ).find() + || !isHex && PTRN_FAULTY_DEC_UNDERSCORE_FLOAT.matcher( val ).find() + || isHex && PTRN_FAULTY_HEX_UNDERSCORE_FLOAT.matcher( val ).find() ) { + throw new NumberFormatException("Improperly placed underscores"); + } + else { + val = val.replace( "_", "" ); + } + } + + /** + * + */ + void removeAndValidateIntegerLiteralSuffix() { + boolean endsWithLSuffix = PTRN_LONG.matcher( val ).find(); + // error handling + if (endsWithLSuffix && !isLong) { + throw new NumberFormatException("L/l not allowed for non-long types"); + } + if (!isPrimitive && !endsWithLSuffix && isLong) { + throw new NumberFormatException("L/l mandatory for boxed long"); + } + // remove suffix + if ( endsWithLSuffix ) { + val = val.substring( 0, val.length() - 1 ); + } + + } + + /** + * Double suffix forbidden for float. + * + * @param isFloat + */ + void removeAndValidateFloatingPointLiteralSuffix() { + boolean endsWithLSuffix = PTRN_LONG.matcher( val ).find(); + boolean endsWithFSuffix = PTRN_FLOAT.matcher( val ).find(); + boolean endsWithDSuffix = PTRN_DOUBLE.matcher( val ).find(); + // error handling + if ( isFloat && endsWithDSuffix ) { + throw new NumberFormatException("Assiging double to a float"); + } + // remove suffix + if ( endsWithLSuffix || endsWithFSuffix || endsWithDSuffix ) { + val = val.substring( 0, val.length() - 1 ); + } + } + + boolean floatHasBecomeZero(float parsed) { + if ( parsed == 0f ) { + return floatHasBecomeZero(); + } + else { + return false; + } + } + + boolean doubleHasBecomeZero(double parsed) { + if ( parsed == 0d ) { + return floatHasBecomeZero(); + } + else { + return false; + } + } + + private boolean floatHasBecomeZero() { + if ( radix == 10 ) { + // decimal, should be at least some number before exponent (eE) unequal to 0. + return PTRN_FLOAT_DEC_ZERO.matcher( val ).matches(); + } + else { + // hex, should be at least some number before exponent (pP) unequal to 0. + return PTRN_FLOAT_HEX_ZERO.matcher( val ).matches(); + } + } + } private NativeTypes() { } @@ -80,6 +271,19 @@ private NativeTypes() { NUMBER_TYPES.add( Double.class ); NUMBER_TYPES.add( BigInteger.class ); NUMBER_TYPES.add( BigDecimal.class ); + + Map tmp2 = new HashMap(); + tmp2.put( Boolean.class.getName(), TypeKind.BOOLEAN ); + tmp2.put( Byte.class.getName(), TypeKind.BYTE ); + tmp2.put( Character.class.getName(), TypeKind.CHAR ); + tmp2.put( Double.class.getName(), TypeKind.DOUBLE ); + tmp2.put( Float.class.getName(), TypeKind.FLOAT ); + tmp2.put( Integer.class.getName(), TypeKind.INT ); + tmp2.put( Long.class.getName(), TypeKind.LONG ); + tmp2.put( Short.class.getName(), TypeKind.SHORT ); + + WRAPPER_NAME_TO_PRIMITIVE_TYPES = Collections.unmodifiableMap( tmp2 ); + } public static Class getWrapperType(Class clazz) { @@ -98,6 +302,14 @@ public static Class getPrimitiveType(Class clazz) { return WRAPPER_TO_PRIMITIVE_TYPES.get( clazz ); } + public static boolean isWrapped(String fullyQualifiedName) { + return WRAPPER_NAME_TO_PRIMITIVE_TYPES.containsKey( fullyQualifiedName ); + } + + public static TypeKind getWrapperKind(String fullyQualifiedName) { + return WRAPPER_NAME_TO_PRIMITIVE_TYPES.get( fullyQualifiedName ); + } + public static boolean isNumber(Class clazz) { if ( clazz == null ) { return false; @@ -106,4 +318,125 @@ public static boolean isNumber(Class clazz) { return NUMBER_TYPES.contains( clazz ); } } + + public static boolean isStringAssignable(TypeKind kind, boolean isPrimitive, String in) { + NumberFormatValidator validator = VALIDATORS.get( kind ); + return validator != null && validator.validate( isPrimitive, in ); + } + + private static Map initValidators() { + Map result = new HashMap(); + result.put( TypeKind.BOOLEAN, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + return "true".equals( s ) || "false".equals( s ); + } + } ); + result.put( TypeKind.CHAR, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + return s.length() == 3 && s.startsWith( "'" ) && s.endsWith( "'" ); + } + } ); + result.put( TypeKind.BYTE, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + + @Override + boolean parse(String val, int radix) { + Byte.parseByte( val, radix ); + return true; + } + }; + return br.validate(); + } + } ); + result.put( TypeKind.DOUBLE, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + NumberRepresentation br = new NumberRepresentation( s, false, false, false, isPrimitive ) { + + @Override + boolean parse(String val, int radix) { + Double d = Double.parseDouble( radix == 16 ? "0x" + val : val ); + return !d.isInfinite() && !doubleHasBecomeZero( d ); + } + }; + return br.validate(); + } + } ); + result.put( TypeKind.FLOAT, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + + NumberRepresentation br = new NumberRepresentation( s, false, false, true, isPrimitive ) { + @Override + boolean parse(String val, int radix) { + Float f = Float.parseFloat( radix == 16 ? "0x" + val : val ); + return !f.isInfinite() && !floatHasBecomeZero( f ); + } + }; + return br.validate(); + } + } ); + result.put( TypeKind.INT, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + + @Override + boolean parse(String val, int radix) { + if ( radix == 10 ) { + // when decimal: treat like signed + Integer.parseInt( val, radix ); + return true; + } + else { + // when binary, octal or hex: treat like unsigned + return new BigInteger( val, radix ).bitLength() <= 32; + } + } + }; + return br.validate(); + } + } ); + result.put( TypeKind.LONG, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + NumberRepresentation br = new NumberRepresentation( s, true, true, false, isPrimitive ) { + + @Override + boolean parse(String val, int radix) { + if ( radix == 10 ) { + // when decimal: treat like signed + Long.parseLong( val, radix ); + return true; + } + else { + // when binary, octal or hex: treat like unsigned + return new BigInteger( val, radix ).bitLength() <= 64; + } + } + }; + return br.validate(); + } + } ); + result.put( TypeKind.SHORT, new NumberFormatValidator() { + @Override + public boolean validate(boolean isPrimitive, String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + + @Override + boolean parse(String val, int radix) { + Short.parseShort( val, radix ); + return true; + } + }; + return br.validate(); + } + } ); + return result; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index e74b9574e6..7afafc0d6b 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -183,6 +183,8 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + false, + false, false ); } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 5770868197..73796af0fb 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -134,6 +134,8 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + false, + false, false ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java new file mode 100644 index 0000000000..d703d6096a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java @@ -0,0 +1,342 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.constants; + +import javax.lang.model.type.TypeKind; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mapstruct.ap.internal.util.NativeTypes.isStringAssignable; + +/** + * + * @author Sjaak Derksen + */ +public class ConstantOptimizingTest { + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testUnderscorePlacement1() { + assertThat( isStringAssignable( TypeKind.LONG, true, "1234_5678_9012_3456L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "999_99_9999L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.14_15F" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0xFF_EC_DE_5EL" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0xCAFE_BABEL" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0x7fff_ffff_ffff_ffffL" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BYTE, true, "0b0010_0101" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0b11010010_01101001_10010100_10010010L" ) ).isTrue(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * You can place underscores only between digits; you cannot place underscores in the following places: + *
        + *
      1. At the beginning or end of a number
      2. + *
      3. Adjacent to a decimal point in a floating point literal
      4. + *
      5. Prior to an F or L suffix
      6. + *
      7. In positions where a string of digits is expected
      8. + *
      + * The following examples demonstrate valid and invalid underscore placements (which are highlighted) in numeric + * literals: + */ + @Test + public void testUnderscorePlacement2() { + + // Invalid: cannot put underscores + // adjacent to a decimal point + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3_.1415F" ) ).isFalse(); + + // Invalid: cannot put underscores + // adjacent to a decimal point + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3._1415F" ) ).isFalse(); + + // Invalid: cannot put underscores + // prior to an L suffix + assertThat( isStringAssignable( TypeKind.LONG, true, "999_99_9999_L" ) ).isFalse(); + + // OK (decimal literal) + assertThat( isStringAssignable( TypeKind.INT, true, "5_2" ) ).isTrue(); + + // Invalid: cannot put underscores + // At the end of a literal + assertThat( isStringAssignable( TypeKind.INT, true, "52_" ) ).isFalse(); + + // OK (decimal literal) + assertThat( isStringAssignable( TypeKind.INT, true, "5_______2" ) ).isTrue(); + + // Invalid: cannot put underscores + // in the 0x radix prefix + assertThat( isStringAssignable( TypeKind.INT, true, "0_x52" ) ).isFalse(); + + // Invalid: cannot put underscores + // at the beginning of a number + assertThat( isStringAssignable( TypeKind.INT, true, "0x_52" ) ).isFalse(); + + // OK (hexadecimal literal) + assertThat( isStringAssignable( TypeKind.INT, true, "0x5_2" ) ).isTrue(); + + // Invalid: cannot put underscores + // at the end of a number + assertThat( isStringAssignable( TypeKind.INT, true, "0x52_" ) ).isFalse(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testIntegerLiteralFromJLS() { + + // largest positive int: dec / octal / int / binary + assertThat( isStringAssignable( TypeKind.INT, true, "2147483647" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0x7fff_ffff" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0177_7777_7777" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0b0111_1111_1111_1111_1111_1111_1111_1111" ) ).isTrue(); + + // most negative int: dec / octal / int / binary + // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can disssapear (java8) + // and the function will be true to what the compiler shows. + assertThat( isStringAssignable( TypeKind.INT, true, "-2147483648" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0x8000_0000" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0200_0000_0000" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0b1000_0000_0000_0000_0000_0000_0000_0000" ) ).isTrue(); + + // -1 representation int: dec / octal / int / binary + assertThat( isStringAssignable( TypeKind.INT, true, "-1" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0xffff_ffff" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0377_7777_7777" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0b1111_1111_1111_1111_1111_1111_1111_1111" ) ).isTrue(); + + // largest positive long: dec / octal / int / binary + assertThat( isStringAssignable( TypeKind.LONG, true, "9223372036854775807L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0x7fff_ffff_ffff_ffffL" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "07_7777_7777_7777_7777_7777L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" + + "1111_1111_1111_1111_1111_1111L" ) ).isTrue(); + // most negative long: dec / octal / int / binary + assertThat( isStringAssignable( TypeKind.LONG, true, "-9223372036854775808L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0x8000_0000_0000_0000L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "010_0000_0000_0000_0000_0000L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_" + + "0000_0000_0000_0000_0000L" ) ).isTrue(); + // -1 representation long: dec / octal / int / binary + assertThat( isStringAssignable( TypeKind.LONG, true, "-1L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0xffff_ffff_ffff_ffffL" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "017_7777_7777_7777_7777_7777L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" + + "1111_1111_1111_1111_1111L" ) ).isTrue(); + + // some examples of ints + assertThat( isStringAssignable( TypeKind.INT, true, "0" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "2" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0372" ) ).isTrue(); + //assertThat( isStringAssignable( TypeKind.INT, true, "0xDada_Cafe" ) ).isTrue(); java8 + assertThat( isStringAssignable( TypeKind.INT, true, "1996" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "0x00_FF__00_FF" ) ).isTrue(); + + // some examples of longs + assertThat( isStringAssignable( TypeKind.LONG, true, "0777l" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0x100000000L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "2_147_483_648L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0xC0B0L" ) ).isTrue(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testFloatingPoingLiteralFromJLS() { + + // The largest positive finite literal of type float is 3.4028235e38f. + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e38f" ) ).isTrue(); + // The smallest positive finite non-zero literal of type float is 1.40e-45f. + assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-45f" ) ).isTrue(); + // The largest positive finite literal of type double is 1.7976931348623157e308. + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623157e308" ) ).isTrue(); + // The smallest positive finite non-zero literal of type double is 4.9e-324 + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-324" ) ).isTrue(); + + // some floats + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.1e1F" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "2.f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, ".3f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "0f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.14f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "6.022137e+23f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "-3.14f" ) ).isTrue(); + + // some doubles + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e1" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e+1" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "2." ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, ".3" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0.0" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "3.14" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "-3.14" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e-9D" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e137" ) ).isTrue(); + + // too large (infinitve) + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e38f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623157e308" ) ).isTrue(); + + // too large (infinitve) + assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e39f" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623159e308" ) ).isFalse(); + + // small + assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-45f" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "0x1.0p-149" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-324" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001P-1062d" ) ).isTrue(); + + // too small + assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-46f" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "0x1.0p-150" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-325" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001p-1063d" ) ).isFalse(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testBooleanLiteralFromJLS() { + assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "true" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "false" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "FALSE" ) ).isFalse(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testCharLiteralFromJLS() { + + assertThat( isStringAssignable( TypeKind.CHAR, true, "'a'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'%'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\t'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\\'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\''" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\u03a9'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\uFFFF'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'\177'" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'Ω'" ) ).isTrue(); + + } + + @Test + public void testShortAndByte() { + assertThat( isStringAssignable( TypeKind.SHORT, true, "0xFE" ) ).isTrue(); + + // some examples of ints + assertThat( isStringAssignable( TypeKind.BYTE, true, "0" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BYTE, true, "2" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BYTE, true, "127" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.BYTE, true, "-128" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.SHORT, true, "1996" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.SHORT, true, "-1996" ) ).isTrue(); + } + + @Test + public void testMiscellaneousErroneousPatterns() { + assertThat( isStringAssignable( TypeKind.INT, true, "1F" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "1D" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.INT, true, "_1" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.INT, true, "1_" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.INT, true, "0x_1" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.INT, true, "0_x1" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e_-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9_e-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4._9e-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4_.9e-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "_4.9e-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E-3_" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E_-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E-_3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E+-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E+_3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9_E-3" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001_P-10d" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001P_-10d" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001_p-10d" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001p_-10d" ) ).isFalse(); + } + + @Test + public void testNegatives() { + assertThat( isStringAssignable( TypeKind.INT, true, "-0xffaa" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "-0377_7777" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.INT, true, "-0b1111_1111" ) ).isTrue(); + } + + @Test + public void testFaultyChar() { + assertThat( isStringAssignable( TypeKind.CHAR, true, "''" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'a" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'aa" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "a'" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "aa'" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "'" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.CHAR, true, "a" ) ).isFalse(); + } + + @Test + public void testFloatWithLongLiteral() { + assertThat( isStringAssignable( TypeKind.FLOAT, true, "156L" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.FLOAT, true, "156l" ) ).isTrue(); + } + + @Test + public void testLongPrimitivesAndNonRequiredLongSuffix() { + assertThat( isStringAssignable( TypeKind.LONG, true, "156" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "156l" ) ).isTrue(); + assertThat( isStringAssignable( TypeKind.LONG, true, "156L" ) ).isTrue(); + } + + @Test + public void testIntPrimitiveWithLongSuffix() { + assertThat( isStringAssignable( TypeKind.INT, true, "156l" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.INT, true, "156L" ) ).isFalse(); + } + + @Test + public void testTooBigIntegersAndBigLongs() { + assertThat( isStringAssignable( TypeKind.INT, true, "0xFFFF_FFFF_FFFF" ) ).isFalse(); + assertThat( isStringAssignable( TypeKind.LONG, true, "0xFFFF_FFFF_FFFF_FFFF_FFFF" ) ).isFalse(); + } + + @Test + public void testNonSupportedPrimitiveType() { + assertThat( isStringAssignable( TypeKind.VOID, true, "0xFFFF_FFFF_FFFF" ) ).isFalse(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java index 482af96664..87d9c07de8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java @@ -35,7 +35,7 @@ public interface ErroneousMapper1 { @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), @Mapping(source = "test", target = "integerConstant", constant = "14"), - @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), @Mapping(target = "country", constant = "THE_NETHERLANDS") diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java index b7eb7c0bbc..71049fba45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java @@ -35,7 +35,7 @@ public interface ErroneousMapper3 { @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), @Mapping(target = "integerConstant", expression = "java('test')", constant = "14"), - @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), @Mapping(target = "country", constant = "THE_NETHERLANDS") diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java index 458b58e5c6..533f02def0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java @@ -35,7 +35,7 @@ public interface ErroneousMapper4 { @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), @Mapping(source = "test", target = "integerConstant", expression = "java('test')"), - @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), @Mapping(target = "country", constant = "THE_NETHERLANDS") diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java index d2a947218d..e65c9b58d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java @@ -35,7 +35,7 @@ public interface ErroneousMapper5 { @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), @Mapping(target = "integerConstant", constant = "14"), - @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), @Mapping(target = "country", constant = "DENMARK") diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java new file mode 100644 index 0000000000..0cd149ee13 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java @@ -0,0 +1,46 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.constants; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper(uses = StringListMapper.class) +public interface ErroneousMapper6 { + + ErroneousMapper6 INSTANCE = Mappers.getMapper( ErroneousMapper6.class ); + + @Mappings({ + @Mapping(target = "stringConstant", constant = "stringConstant"), + @Mapping(target = "emptyStringConstant", constant = ""), + @Mapping(target = "integerConstant", constant = "14"), + @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), + @Mapping(target = "nameConstants", constant = "jack-jill-tom"), + @Mapping(target = "country", constant = "THE_NETHERLANDS") + }) + Target sourceToTarget(Source s); + + Source targetToSource(Target t); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 5105fe2896..be4a046d94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -209,7 +209,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc + "constants.CountryEnum for property \"country\".$"), @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, - line = 43, + line = 41, messageRegExp = "^Can't map \"java.lang.String \"DENMARK\"\" to \"org.mapstruct.ap.test.source." + "constants.CountryEnum country\".$") } @@ -217,6 +217,28 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc public void errorOnNonExistingEnumConstant() throws ParseException { } + @Test + @IssueKey("1401") + @WithClasses({ + Source.class, + Target.class, + CountryEnum.class, + ErroneousMapper6.class, + StringListMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapper6.class, + kind = Kind.ERROR, + line = 38, + messageRegExp = "^.*Can't map \"java.lang.String \"3001\"\" to \"java.lang.Long " + + "longWrapperConstant\".*$") + } + ) + public void cannotMapIntConstantToLong() throws ParseException { + } + private Date getDate(String format, String date) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat( format ); Date result = dateFormat.parse( date ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java index 1005b01dd6..5721b17353 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java @@ -35,7 +35,7 @@ public interface SourceTargetMapper { @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), @Mapping(target = "integerConstant", constant = "14"), - @Mapping(target = "longWrapperConstant", constant = "3001"), + @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), @Mapping(target = "country", constant = "THE_NETHERLANDS") From 7e7fcfbb940405912c77ef6ff8fe5c8e999c9a62 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 25 Apr 2018 20:45:02 +0200 Subject: [PATCH 0225/1006] #1317 Add support for ignoring unmapped source properties This property has only effect on the unmapped source properties report --- .../main/java/org/mapstruct/BeanMapping.java | 14 ++++++ .../ap/internal/model/BeanMappingMethod.java | 9 ++++ .../ap/internal/model/source/BeanMapping.java | 29 ++++++++++-- .../ignore/IgnoreUnmappedSourceMapper.java | 41 +++++++++++++++++ .../IgnoreUnmappedSourcePropertiesTest.java | 43 ++++++++++++++++++ .../ap/test/source/ignore/Person.java | 44 +++++++++++++++++++ .../ap/test/source/ignore/PersonDto.java | 44 +++++++++++++++++++ 7 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index 76eac373f5..10d0e70f78 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -83,4 +83,18 @@ * @since 1.3 */ boolean ignoreByDefault() default false; + + /** + * Unmapped source properties to be ignored. This could be used when {@link ReportingPolicy#WARN} + * or {@link ReportingPolicy#ERROR} is used for {@link Mapper#unmappedSourcePolicy()} or + * {@link MapperConfig#unmappedSourcePolicy()}. Listed properties will be ignored when composing the unmapped + * source properties report. + *

      + * NOTE: This does not support ignoring nested source properties + * + * @return The source properties that should be ignored when performing a report + * + * @since 1.3 + */ + String[] ignoreUnmappedSourceProperties() default {}; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 506b4bf4eb..4886e475e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -45,6 +45,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; +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.model.source.Mapping; @@ -133,6 +134,14 @@ private Builder setupMethodWithMapping(Method sourceMethod) { } } existingVariableNames.addAll( method.getParameterNames() ); + + BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); + if ( beanMapping != null ) { + for ( String ignoreUnmapped : beanMapping.getIgnoreUnmappedSourceProperties() ) { + unprocessedSourceProperties.remove( ignoreUnmapped ); + } + } + return this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index 55610f995c..e3580de65e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.Collections; +import java.util.List; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; @@ -39,6 +41,7 @@ public class BeanMapping { private final NullValueMappingStrategyPrism nullValueMappingStrategy; private final ReportingPolicyPrism reportingPolicy; private final boolean ignoreByDefault; + private final List ignoreUnmappedSourceProperties; /** * creates a mapping for inheritance. Will set ignoreByDefault to false. @@ -47,7 +50,13 @@ public class BeanMapping { * @return */ public static BeanMapping forInheritance( BeanMapping map ) { - return new BeanMapping( map.selectionParameters, map.nullValueMappingStrategy, map.reportingPolicy, false ); + return new BeanMapping( + map.selectionParameters, + map.nullValueMappingStrategy, + map.reportingPolicy, + false, + map.ignoreUnmappedSourceProperties + ); } public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, @@ -66,6 +75,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem boolean ignoreByDefault = beanMapping.ignoreByDefault(); if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() + && beanMapping.ignoreUnmappedSourceProperties().isEmpty() && ( nullValueMappingStrategy == null ) && !ignoreByDefault ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); @@ -79,7 +89,13 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ); //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? - return new BeanMapping( cmp, nullValueMappingStrategy, null, ignoreByDefault ); + return new BeanMapping( + cmp, + nullValueMappingStrategy, + null, + ignoreByDefault, + beanMapping.ignoreUnmappedSourceProperties() + ); } /** @@ -89,15 +105,17 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem * @return bean mapping that needs to be used for Mappings */ public static BeanMapping forForgedMethods() { - return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false ); + return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false, Collections.emptyList() ); } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, - ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault) { + ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, + List ignoreUnmappedSourceProperties) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; this.reportingPolicy = reportingPolicy; this.ignoreByDefault = ignoreByDefault; + this.ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties; } public SelectionParameters getSelectionParameters() { @@ -116,4 +134,7 @@ public boolean isignoreByDefault() { return ignoreByDefault; } + public List getIgnoreUnmappedSourceProperties() { + return ignoreUnmappedSourceProperties; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java new file mode 100644 index 0000000000..d6ad432ff5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.ignore; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * @author Filip Hrisafov + */ +@Mapper( + unmappedTargetPolicy = ReportingPolicy.IGNORE, + unmappedSourcePolicy = ReportingPolicy.ERROR +) +public interface IgnoreUnmappedSourceMapper { + + @BeanMapping( + ignoreUnmappedSourceProperties = { + "name", + "surname" + } + ) + PersonDto map(Person person); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java new file mode 100644 index 0000000000..2a76a47ead --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.ignore; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + IgnoreUnmappedSourceMapper.class, + Person.class, + PersonDto.class +}) +@RunWith( AnnotationProcessorTestRunner.class ) +@IssueKey("1317") +public class IgnoreUnmappedSourcePropertiesTest { + + @Test + public void shouldNotReportErrorOnIgnoredUnmappedSourceProperties() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java new file mode 100644 index 0000000000..8bd43eff17 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.ignore; + +/** + * @author Filip Hrisafov + */ +public class Person { + + private String name; + private String surname; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java new file mode 100644 index 0000000000..97faec6525 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.ignore; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + + private String firstName; + private String lastName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} From cf19a6b637e2570580b32a94b357e0f31559c1de Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 28 Apr 2018 09:09:44 +0200 Subject: [PATCH 0226/1006] #1423 Updating types that have a builder should be allowed It is possible that a type has both a builder and accessors. In such case doing an update to this type should be allowed --- .../ap/internal/model/BeanMappingMethod.java | 13 +++- .../ap/internal/model/PropertyMapping.java | 6 +- .../model/source/TargetReference.java | 22 +++++- .../processor/MethodRetrievalProcessor.java | 5 -- .../mapstruct/ap/internal/util/Message.java | 1 - .../simple/BuilderInfoTargetTest.java | 55 +++++++++---- .../simple/ErroneousSimpleBuilderMapper.java | 27 ------- .../mappingTarget/simple/MutableTarget.java | 78 +++++++++++++++++++ .../simple/SimpleBuilderMapper.java | 9 +++ 9 files changed, 162 insertions(+), 54 deletions(-) delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/ErroneousSimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/MutableTarget.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4886e475e9..059a1c7baf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -115,8 +115,12 @@ private Builder setupMethodWithMapping(Method sourceMethod) { this.method = sourceMethod; this.methodMappings = sourceMethod.getMappingOptions().getMappings(); CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); - Map accessors = method.getResultType() - .getEffectiveType() + Type mappingType = method.getResultType(); + if ( !method.isUpdateMethod() ) { + mappingType = mappingType.getEffectiveType(); + } + + Map accessors = mappingType .getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); @@ -885,7 +889,10 @@ public Set getImportTypes() { types.addAll( propertyMapping.getImportTypes() ); } - types.add( getResultType().getEffectiveType() ); + if ( !isExistingInstanceMapping() ) { + types.addAll( getResultType().getEffectiveType().getImportTypes() ); + } + return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 3ed0abaf63..cb48c23d52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -155,7 +155,11 @@ T mirror(AnnotationMirror mirror) { private Type determineTargetType() { // This is a bean mapping method, so we know the result is a declared type - DeclaredType resultType = (DeclaredType) method.getResultType().getEffectiveType().getTypeMirror(); + Type mappingType = method.getResultType(); + if ( !method.isUpdateMethod() ) { + mappingType = mappingType.getEffectiveType(); + } + DeclaredType resultType = (DeclaredType) mappingType.getTypeMirror(); switch ( targetWriteAccessorType ) { case ADDER: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index fc9da48695..5b48d54ccc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -153,7 +153,7 @@ public TargetReference build() { boolean foundEntryMatch; Type resultType = method.getResultType(); - resultType = resultType.getEffectiveType(); + resultType = typeBasedOnMethod( resultType ); // there can be 4 situations // 1. Return type @@ -191,7 +191,7 @@ private List getTargetEntries(Type type, String[] entryNames) { // last entry for ( int i = 0; i < entryNames.length; i++ ) { - Type mappingType = nextType.getEffectiveType(); + Type mappingType = typeBasedOnMethod( nextType ); Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); boolean isLast = i == entryNames.length - 1; @@ -237,13 +237,13 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t if ( Executables.isGetterMethod( toUse ) || Executables.isFieldAccessor( toUse ) ) { nextType = typeFactory.getReturnType( - (DeclaredType) initial.getEffectiveType().getTypeMirror(), + (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), toUse ); } else { nextType = typeFactory.getSingleParameter( - (DeclaredType) initial.getEffectiveType().getTypeMirror(), + (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), toUse ).getType(); } @@ -264,6 +264,20 @@ else if ( targetWriteAccessor == null ) { } } + /** + * When we are in an update method, i.e. source parameter with {@code @MappingTarget} then the type should + * be itself, otherwise, we always get the effective type. The reason is that when doing updates we always + * search for setters and getters within the updating type. + */ + private Type typeBasedOnMethod(Type type) { + if ( method.isUpdateMethod() ) { + return type; + } + else { + return type.getEffectiveType(); + } + } + /** * A write accessor is not valid if it is {@code null} and it is not last. i.e. for nested target mappings * there must be a write accessor for all entries except the last one. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 6dfed43c52..19e3d538f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -403,11 +403,6 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List Date: Sat, 28 Apr 2018 10:17:52 +0200 Subject: [PATCH 0227/1006] #1452 support BeanMapping#ignoreByDefault for builders --- .../internal/model/source/MappingOptions.java | 7 +- .../ap/test/builder/ignore/BaseDto.java | 35 ++++++++ .../ap/test/builder/ignore/BaseEntity.java | 52 ++++++++++++ .../builder/ignore/BuilderIgnoringMapper.java | 43 ++++++++++ .../ignore/BuilderIgnoringMappingConfig.java | 32 +++++++ .../builder/ignore/BuilderIgnoringTest.java | 85 +++++++++++++++++++ .../ap/test/builder/ignore/Person.java | 66 ++++++++++++++ .../ap/test/builder/ignore/PersonDto.java | 44 ++++++++++ 8 files changed, 363 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 8471210d12..2b4c1b518c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -30,6 +30,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -298,7 +299,11 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, FormattingMessager messager, TypeFactory typeFactory ) { CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); - Map writeAccessors = method.getResultType().getPropertyWriteAccessors( cms ); + Type writeType = method.getResultType(); + if ( !method.isUpdateMethod() ) { + writeType = writeType.getEffectiveType(); + } + Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); List mappedPropertyNames = new ArrayList(); for ( String targetMappingName : mappings.keySet() ) { mappedPropertyNames.add( targetMappingName.split( "\\." )[0] ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java new file mode 100644 index 0000000000..50b6d35e59 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +/** + * @author Filip Hrisafov + */ +public class BaseDto { + + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java new file mode 100644 index 0000000000..24ee73188a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java @@ -0,0 +1,52 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +/** + * @author Filip Hrisafov + */ +public class BaseEntity { + + private final Long id; + + public BaseEntity(Builder builder) { + this.id = builder.id; + } + + public Long getId() { + return id; + } + + public static Builder baseBuilder() { + return new Builder(); + } + + public static class Builder { + private Long id; + + public Builder id(Long id) { + this.id = id; + return this; + } + + public BaseEntity createBase() { + return new BaseEntity( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java new file mode 100644 index 0000000000..e3c8dbd81d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = BuilderIgnoringMappingConfig.class) +public interface BuilderIgnoringMapper { + + BuilderIgnoringMapper INSTANCE = Mappers.getMapper( BuilderIgnoringMapper.class ); + + @InheritConfiguration(name = "mapBase") + Person mapWithIgnoringBase(PersonDto source); + + @BeanMapping(ignoreByDefault = true) + @Mapping(target = "name", source = "name") + Person mapOnlyWithExplicit(PersonDto source); + + Person mapAll(PersonDto source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java new file mode 100644 index 0000000000..67a699e536 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +import org.mapstruct.BeanMapping; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig +public interface BuilderIgnoringMappingConfig { + + @BeanMapping(ignoreByDefault = true) + BaseEntity mapBase(BaseDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java new file mode 100644 index 0000000000..0538aeda21 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java @@ -0,0 +1,85 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1452") +@WithClasses({ + BaseDto.class, + BaseEntity.class, + BuilderIgnoringMapper.class, + BuilderIgnoringMappingConfig.class, + Person.class, + PersonDto.class +}) +public class BuilderIgnoringTest { + + @Test + public void shouldIgnoreBase() { + PersonDto source = new PersonDto(); + source.setId( 100L ); + source.setName( "John" ); + source.setLastName( "Doe" ); + + Person target = BuilderIgnoringMapper.INSTANCE.mapWithIgnoringBase( source ); + + assertThat( target.getId() ).isNull(); + assertThat( target.getName() ).isEqualTo( "John" ); + assertThat( target.getLastName() ).isEqualTo( "Doe" ); + } + + @Test + public void shouldMapOnlyExplicit() { + PersonDto source = new PersonDto(); + source.setId( 100L ); + source.setName( "John" ); + source.setLastName( "Doe" ); + + Person target = BuilderIgnoringMapper.INSTANCE.mapOnlyWithExplicit( source ); + + assertThat( target.getId() ).isNull(); + assertThat( target.getName() ).isEqualTo( "John" ); + assertThat( target.getLastName() ).isNull(); + } + + @Test + public void shouldMapAll() { + PersonDto source = new PersonDto(); + source.setId( 100L ); + source.setName( "John" ); + source.setLastName( "Doe" ); + + Person target = BuilderIgnoringMapper.INSTANCE.mapAll( source ); + + assertThat( target.getId() ).isEqualTo( 100L ); + assertThat( target.getName() ).isEqualTo( "John" ); + assertThat( target.getLastName() ).isEqualTo( "Doe" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java new file mode 100644 index 0000000000..0fafbae7c7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java @@ -0,0 +1,66 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +/** + * @author Filip Hrisafov + */ +public class Person extends BaseEntity { + + private final String name; + private final String lastName; + + public Person(Builder builder) { + super( builder ); + this.name = builder.name; + this.lastName = builder.lastName; + } + + public String getName() { + return name; + } + + public String getLastName() { + return lastName; + } + + public static Builder builder() { + return new Builder(); + + } + + public static class Builder extends BaseEntity.Builder { + private String name; + private String lastName; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder lastName(String lastName) { + this.lastName = lastName; + return this; + } + + public Person create() { + return new Person( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java new file mode 100644 index 0000000000..b3b137f9f9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java @@ -0,0 +1,44 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.ignore; + +/** + * @author Filip Hrisafov + */ +public class PersonDto extends BaseDto { + + private String name; + private String lastName; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} From ffb720dc29b62e26afda8b82ee5d8b7812278cd3 Mon Sep 17 00:00:00 2001 From: sjaakd Date: Sat, 28 Apr 2018 12:35:13 +0200 Subject: [PATCH 0228/1006] #1459 javadoc on constant assigment --- .../src/main/java/org/mapstruct/Mapping.java | 56 +++++++++++++++-- core/src/main/java/org/mapstruct/Mapping.java | 62 +++++++++++++++++-- 2 files changed, 106 insertions(+), 12 deletions(-) diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java index f8a611abcb..4064b7d86c 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java @@ -94,9 +94,31 @@ String numberFormat() default ""; /** - * A constant {@link String} based on which the specified target property is to be set. If the designated target - * property is not of type {@code String}, the value will be converted by applying a matching conversion method or - * built-in conversion. + * A constant {@link String} based on which the specified target property is to be set. + *

      + * When the designated target property is of type: + *

      + *
        + *
      1. primitive or boxed (e.g. {@code java.lang.Long}). + *

        + * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. + *

        + *
          + *
        • + * If possible, MapStruct assigns as literal. + *
        • + *
        • + * If not possible, MapStruct will try to apply a user defined mapping method. + *
        • + *
        + *
      2. + *
      3. other + *

        + * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, + * type conversion method or built-in conversion. + *

        + *

      4. + *
      *

      * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, * {@link #defaultExpression()} or {@link #expression()}. @@ -214,9 +236,31 @@ String[] dependsOn() default { }; /** - * In case the source property is {@code null}, the provided default {@link String} value is set. If the designated - * target property is not of type {@code String}, the value will be converted by applying a matching conversion - * method or built-in conversion. + * In case the source property is {@code null}, the provided default {@link String} value is set. + *

      + * When the designated target property is of type: + *

      + *
        + *
      1. primitive or boxed (e.g. {@code java.lang.Long}). + *

        + * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. + *

        + *
          + *
        • + * If possible, MapStruct assigns as literal. + *
        • + *
        • + * If not possible, MapStruct will try to apply a user defined mapping method. + *
        • + *
        + *
      2. + *
      3. other + *

        + * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, + * type conversion method or built-in conversion. + *

        + *

      4. + *
      *

      * This attribute can not be used together with {@link #constant()}, {@link #expression()} * or {@link #defaultExpression()}. diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 849e8bd871..86e1810e25 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -92,9 +92,34 @@ String numberFormat() default ""; /** - * A constant {@link String} based on which the specified target property is to be set. If the designated target - * property is not of type {@code String}, the value will be converted by applying a matching conversion method or - * built-in conversion. + * A constant {@link String} based on which the specified target property is to be set. + *

      + * When the designated target property is of type: + *

      + *
        + *
      1. primitive or boxed (e.g. {@code java.lang.Long}). + *

        + * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. + *

        + *
          + *
        • + * If possible, MapStruct assigns as literal. + *
        • + *
        • + * If not possible, MapStruct will try to apply a user defined mapping method. + *
        • + *
        + *

        + * Please note that grouping underscores and binary literals are not supported in Java 6 + *

        + *
      2. + *
      3. other + *

        + * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, + * type conversion method or built-in conversion. + *

        + *

      4. + *
      *

      * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, * {@link #defaultExpression()} or {@link #expression()}. @@ -213,9 +238,34 @@ String[] dependsOn() default { }; /** - * In case the source property is {@code null}, the provided default {@link String} value is set. If the designated - * target property is not of type {@code String}, the value will be converted by applying a matching conversion - * method or built-in conversion. + * In case the source property is {@code null}, the provided default {@link String} value is set. + *

      + * When the designated target property is of type: + *

      + *
        + *
      1. primitive or boxed (e.g. {@code java.lang.Long}). + *

        + * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. + *

        + *
          + *
        • + * If possible, MapStruct assigns as literal. + *
        • + *
        • + * If not possible, MapStruct will try to apply a user defined mapping method. + *
        • + *
        + *

        + * Please note that grouping underscores and binary literals are not supported in Java 6 + *

        + *
      2. + *
      3. other + *

        + * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, + * type conversion method or built-in conversion. + *

        + *

      4. + *
      *

      * This attribute can not be used together with {@link #constant()}, {@link #expression()} * or {@link #defaultExpression()}. From d92b439a60a914c53098d5868c4c4ef1e63c538b Mon Sep 17 00:00:00 2001 From: sjaakd Date: Fri, 27 Apr 2018 22:12:39 +0200 Subject: [PATCH 0229/1006] #1462 define constants as JLS literal types, enforce long L suffix --- .../ap/internal/model/common/Type.java | 8 + .../ap/internal/model/common/TypeFactory.java | 26 +- .../creation/MappingResolverImpl.java | 4 +- .../ap/internal/util/NativeTypes.java | 128 ++++-- .../ap/internal/util/NativeTypesTest.java | 374 +++++++++++++++++- .../constants/ConstantOptimizingTest.java | 342 ---------------- .../constants/NumericConstantsTest.java | 63 +++ .../test/source/constants/NumericMapper.java | 51 +++ .../test/source/constants/NumericTarget.java | 137 +++++++ .../source/constants/SourceConstantsTest.java | 2 +- .../source/constants/NumericMapperImpl.java | 53 +++ 11 files changed, 792 insertions(+), 396 deletions(-) delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 12f3f379ff..1ae66dbe79 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -925,6 +925,14 @@ public boolean isBoxed() { return isBoxed; } + /** + * All primitive types and their corresponding boxed types are considered native. + * @return true when native. + */ + public boolean isNative() { + return isBoxed() || isPrimitive(); + } + public boolean hasOriginatedFromConstant() { return isOriginatedFromConstant; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index dc06e1f12b..d540cfcb24 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -149,23 +149,21 @@ private Type getType(String canonicalName, boolean isOriginatedFromConstant) { public Type getTypeForConstant(Type targetType, String literal) { Type result = null; - if ( targetType.isPrimitive() ) { - TypeKind kind = targetType.getTypeMirror().getKind(); - boolean assignable = NativeTypes.isStringAssignable( kind, true, literal ); - if ( assignable ) { - result = getType( targetType.getTypeMirror(), true ); + TypeMirror baseForLiteral = null; + if ( targetType.isNative() ) { + TypeKind kind; + if ( targetType.isBoxed() ) { + kind = NativeTypes.getWrapperKind( targetType.getFullyQualifiedName() ); } - } - else { - TypeKind boxedTypeKind = NativeTypes.getWrapperKind( targetType.getFullyQualifiedName() ); - if ( boxedTypeKind != null ) { - boolean assignable = NativeTypes.isStringAssignable( boxedTypeKind, false, literal ); - if ( assignable ) { - result = getType( targetType.getTypeMirror(), true ); - } + else { + kind = targetType.getTypeMirror().getKind(); } + baseForLiteral = NativeTypes.getLiteral( kind, literal, typeUtils ); } - if ( result == null ) { + if ( baseForLiteral != null ) { + result = getType( baseForLiteral, true ); + } + else { result = getType( String.class.getCanonicalName(), true ); } return result; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 81b346e0c8..07624b21ad 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -260,7 +260,9 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { // In case of 1. and the target type is still a wrapped or primitive type we must assume that the check // in NativeType is not successful. We don't want to go through type conversion, double mappings etc. // with something that we already know to be wrong. - if ( sourceType.hasOriginatedFromConstant() && ( targetType.isPrimitive() || targetType.isBoxed() ) ) { + if ( sourceType.hasOriginatedFromConstant() + && "java.lang.String".equals( sourceType.getFullyQualifiedName( ) ) + && targetType.isNative() ) { // TODO: convey some error message return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index db61bb7f33..48336b2a1b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -21,16 +21,19 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; /** * Provides functionality around the Java primitive data types and their wrapper - * types. + * types. They are considered native. * * @author Gunnar Morling */ @@ -58,11 +61,14 @@ public class NativeTypes { private static final Pattern PTRN_FAULTY_DEC_UNDERSCORE_FLOAT = Pattern.compile( "_e|_E|e_|E_" ); private static final Pattern PTRN_FAULTY_HEX_UNDERSCORE_FLOAT = Pattern.compile( "_p|_P|p_|P_" ); - private static final Map VALIDATORS = initValidators(); + private static final Map ANALYZERS = initAnalyzers(); - private interface NumberFormatValidator { + private interface LiteralAnalyzer { + + boolean validate( String s); + + TypeMirror getLiteral( Types types ); - boolean validate(boolean isPrimitive, String s); } private abstract static class NumberRepresentation { @@ -72,13 +78,11 @@ private abstract static class NumberRepresentation { boolean isIntegralType; boolean isLong; boolean isFloat; - boolean isPrimitive; - NumberRepresentation(String in, boolean isIntegralType, boolean isLong, boolean isFloat, boolean isPrimitive) { + NumberRepresentation(String in, boolean isIntegralType, boolean isLong, boolean isFloat) { this.isLong = isLong; this.isFloat = isFloat; this.isIntegralType = isIntegralType; - this.isPrimitive = isPrimitive; String valWithoutSign; boolean isNegative = in.startsWith( "-" ); @@ -170,8 +174,8 @@ void removeAndValidateIntegerLiteralSuffix() { if (endsWithLSuffix && !isLong) { throw new NumberFormatException("L/l not allowed for non-long types"); } - if (!isPrimitive && !endsWithLSuffix && isLong) { - throw new NumberFormatException("L/l mandatory for boxed long"); + if ( !endsWithLSuffix && isLong) { + throw new NumberFormatException("L/l mandatory long"); } // remove suffix if ( endsWithLSuffix ) { @@ -319,29 +323,51 @@ public static boolean isNumber(Class clazz) { } } - public static boolean isStringAssignable(TypeKind kind, boolean isPrimitive, String in) { - NumberFormatValidator validator = VALIDATORS.get( kind ); - return validator != null && validator.validate( isPrimitive, in ); + /** + * + * @param kind typeKind + * @param literal literal + * @param utils type util for constructing literal type + * @return literal type when the literal is a proper literal for the provided kind. + */ + public static TypeMirror getLiteral(TypeKind kind, String literal, Types utils ) { + LiteralAnalyzer analyzer = ANALYZERS.get( kind ); + TypeMirror result = null; + if ( analyzer != null && analyzer.validate( literal ) ) { + result = analyzer.getLiteral( utils ); + } + return result; } - private static Map initValidators() { - Map result = new HashMap(); - result.put( TypeKind.BOOLEAN, new NumberFormatValidator() { + @SuppressWarnings( "checkstyle:MethodLength" ) + private static Map initAnalyzers() { + Map result = new EnumMap(TypeKind.class); + result.put( TypeKind.BOOLEAN, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { + public boolean validate( String s) { return "true".equals( s ) || "false".equals( s ); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.BOOLEAN ); + } } ); - result.put( TypeKind.CHAR, new NumberFormatValidator() { + result.put( TypeKind.CHAR, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { + public boolean validate( String s) { return s.length() == 3 && s.startsWith( "'" ) && s.endsWith( "'" ); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.CHAR ); + } } ); - result.put( TypeKind.BYTE, new NumberFormatValidator() { + result.put( TypeKind.BYTE, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { - NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + public boolean validate( String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false ) { @Override boolean parse(String val, int radix) { @@ -351,11 +377,16 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.INT ); + } } ); - result.put( TypeKind.DOUBLE, new NumberFormatValidator() { + result.put( TypeKind.DOUBLE, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { - NumberRepresentation br = new NumberRepresentation( s, false, false, false, isPrimitive ) { + public boolean validate( String s) { + NumberRepresentation br = new NumberRepresentation( s, false, false, false ) { @Override boolean parse(String val, int radix) { @@ -365,12 +396,17 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.FLOAT ); + } } ); - result.put( TypeKind.FLOAT, new NumberFormatValidator() { + result.put( TypeKind.FLOAT, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { + public boolean validate( String s) { - NumberRepresentation br = new NumberRepresentation( s, false, false, true, isPrimitive ) { + NumberRepresentation br = new NumberRepresentation( s, false, false, true ) { @Override boolean parse(String val, int radix) { Float f = Float.parseFloat( radix == 16 ? "0x" + val : val ); @@ -379,11 +415,16 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.FLOAT ); + } } ); - result.put( TypeKind.INT, new NumberFormatValidator() { + result.put( TypeKind.INT, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { - NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + public boolean validate( String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false ) { @Override boolean parse(String val, int radix) { @@ -400,11 +441,16 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.INT ); + } } ); - result.put( TypeKind.LONG, new NumberFormatValidator() { + result.put( TypeKind.LONG, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { - NumberRepresentation br = new NumberRepresentation( s, true, true, false, isPrimitive ) { + public boolean validate(String s) { + NumberRepresentation br = new NumberRepresentation( s, true, true, false ) { @Override boolean parse(String val, int radix) { @@ -421,11 +467,16 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.INT ); + } } ); - result.put( TypeKind.SHORT, new NumberFormatValidator() { + result.put( TypeKind.SHORT, new LiteralAnalyzer() { @Override - public boolean validate(boolean isPrimitive, String s) { - NumberRepresentation br = new NumberRepresentation( s, true, false, false, isPrimitive ) { + public boolean validate( String s) { + NumberRepresentation br = new NumberRepresentation( s, true, false, false ) { @Override boolean parse(String val, int radix) { @@ -435,6 +486,11 @@ boolean parse(String val, int radix) { }; return br.validate(); } + + @Override + public TypeMirror getLiteral(Types types) { + return types.getPrimitiveType( TypeKind.INT ); + } } ); return result; } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java index 257fce4a1f..98c31be696 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java @@ -18,13 +18,28 @@ */ package org.mapstruct.ap.internal.util; +import static org.assertj.core.api.Assertions.assertThat; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import static org.mapstruct.ap.internal.util.NativeTypes.getLiteral; + +import java.lang.annotation.Annotation; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import org.junit.Test; import java.math.BigDecimal; import java.math.BigInteger; +import java.util.List; +import javax.lang.model.element.AnnotationMirror; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import javax.lang.model.type.PrimitiveType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Types; +import javax.lang.model.type.TypeVisitor; /** * @author Ciaran Liedeman @@ -44,4 +59,359 @@ public void testIsNumber() throws Exception { assertTrue( NativeTypes.isNumber( BigDecimal.class ) ); assertTrue( NativeTypes.isNumber( BigInteger.class ) ); } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testUnderscorePlacement1() { + assertThat( getLiteral( TypeKind.LONG, "1234_5678_9012_3456L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "999_99_9999L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "3.14_15F", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0xFF_EC_DE_5EL", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0xCAFE_BABEL", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0x7fff_ffff_ffff_ffffL", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BYTE, "0b0010_0101", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0b11010010_01101001_10010100_10010010L", types() ) ).isNotNull(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * You can place underscores only between digits; you cannot place underscores in the following places: + *

        + *
      1. At the beginning or end of a number
      2. + *
      3. Adjacent to a decimal point in a floating point literal
      4. + *
      5. Prior to an F or L suffix
      6. + *
      7. In positions where a string of digits is expected
      8. + *
      + * The following examples demonstrate valid and invalid underscore placements (which are highlighted) in numeric + * literals: + */ + @Test + public void testUnderscorePlacement2() { + + // Invalid: cannot put underscores + // adjacent to a decimal point + assertThat( getLiteral( TypeKind.FLOAT, "3_.1415F", types() ) ).isNull(); + + // Invalid: cannot put underscores + // adjacent to a decimal point + assertThat( getLiteral( TypeKind.FLOAT, "3._1415F", types() ) ).isNull(); + + // Invalid: cannot put underscores + // prior to an L suffix + assertThat( getLiteral( TypeKind.LONG, "999_99_9999_L", types() ) ).isNull(); + + // OK (decimal literal) + assertThat( getLiteral( TypeKind.INT, "5_2", types() ) ).isNotNull(); + + // Invalid: cannot put underscores + // At the end of a literal + assertThat( getLiteral( TypeKind.INT, "52_", types() ) ).isNull(); + + // OK (decimal literal) + assertThat( getLiteral( TypeKind.INT, "5_______2", types() ) ).isNotNull(); + + // Invalid: cannot put underscores + // in the 0x radix prefix + assertThat( getLiteral( TypeKind.INT, "0_x52", types() ) ).isNull(); + + // Invalid: cannot put underscores + // at the beginning of a number + assertThat( getLiteral( TypeKind.INT, "0x_52", types() ) ).isNull(); + + // OK (hexadecimal literal) + assertThat( getLiteral( TypeKind.INT, "0x5_2", types() ) ).isNotNull(); + + // Invalid: cannot put underscores + // at the end of a number + assertThat( getLiteral( TypeKind.INT, "0x52_", types() ) ).isNull(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testIntegerLiteralFromJLS() { + + // largest positive int: dec / octal / int / binary + assertThat( getLiteral( TypeKind.INT, "2147483647", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "2147483647", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0x7fff_ffff", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0177_7777_7777", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0b0111_1111_1111_1111_1111_1111_1111_1111", types() ) ).isNotNull(); + + // most negative int: dec / octal / int / binary + // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can disssapear (java8) + // and the function will be true to what the compiler shows. + assertThat( getLiteral( TypeKind.INT, "-2147483648", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0x8000_0000", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0200_0000_0000", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0b1000_0000_0000_0000_0000_0000_0000_0000", types() ) ).isNotNull(); + + // -1 representation int: dec / octal / int / binary + assertThat( getLiteral( TypeKind.INT, "-1", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0xffff_ffff", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0377_7777_7777", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0b1111_1111_1111_1111_1111_1111_1111_1111", types() ) ).isNotNull(); + + // largest positive long: dec / octal / int / binary + assertThat( getLiteral( TypeKind.LONG, "9223372036854775807L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0x7fff_ffff_ffff_ffffL", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "07_7777_7777_7777_7777_7777L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" + + "1111_1111_1111_1111_1111_1111L", types() ) ).isNotNull(); + // most negative long: dec / octal / int / binary + assertThat( getLiteral( TypeKind.LONG, "-9223372036854775808L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0x8000_0000_0000_0000L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "010_0000_0000_0000_0000_0000L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_" + + "0000_0000_0000_0000_0000L", types() ) ).isNotNull(); + // -1 representation long: dec / octal / int / binary + assertThat( getLiteral( TypeKind.LONG, "-1L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0xffff_ffff_ffff_ffffL", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "017_7777_7777_7777_7777_7777L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" + + "1111_1111_1111_1111_1111L", types() ) ).isNotNull(); + + // some examples of ints + assertThat( getLiteral( TypeKind.INT, "0", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "2", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0372", types() ) ).isNotNull(); + //assertThat( getLiteral( TypeKind.INT, "0xDada_Cafe", types() ) ).isNotNull(); java8 + assertThat( getLiteral( TypeKind.INT, "1996", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "0x00_FF__00_FF", types() ) ).isNotNull(); + + // some examples of longs + assertThat( getLiteral( TypeKind.LONG, "0777l", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0x100000000L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "2_147_483_648L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "0xC0B0L", types() ) ).isNotNull(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testFloatingPoingLiteralFromJLS() { + + // The largest positive finite literal of type float is 3.4028235e38f. + assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e38f", types() ) ).isNotNull(); + // The smallest positive finite non-zero literal of type float is 1.40e-45f. + assertThat( getLiteral( TypeKind.FLOAT, "1.40e-45f", types() ) ).isNotNull(); + // The largest positive finite literal of type double is 1.7976931348623157e308. + assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623157e308", types() ) ).isNotNull(); + // The smallest positive finite non-zero literal of type double is 4.9e-324 + assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-324", types() ) ).isNotNull(); + + // some floats + assertThat( getLiteral( TypeKind.FLOAT, "3.1e1F", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "2.f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, ".3f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "0f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "3.14f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "6.022137e+23f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "-3.14f", types() ) ).isNotNull(); + + // some doubles + assertThat( getLiteral( TypeKind.DOUBLE, "1e1", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "1e+1", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "2.", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, ".3", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0.0", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "3.14", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "-3.14", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "1e-9D", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "1e137", types() ) ).isNotNull(); + + // too large (infinitve) + assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e38f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623157e308", types() ) ).isNotNull(); + + // too large (infinitve) + assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e39f", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623159e308", types() ) ).isNull(); + + // small + assertThat( getLiteral( TypeKind.FLOAT, "1.40e-45f", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "0x1.0p-149", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-324", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001P-1062d", types() ) ).isNotNull(); + + // too small + assertThat( getLiteral( TypeKind.FLOAT, "1.40e-46f", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.FLOAT, "0x1.0p-150", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-325", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001p-1063d", types() ) ).isNull(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testBooleanLiteralFromJLS() { + assertThat( getLiteral( TypeKind.BOOLEAN, "true", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BOOLEAN, "false", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BOOLEAN, "FALSE", types() ) ).isNull(); + } + + /** + * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html + * + * The following example shows other ways you can use the underscore in numeric literals: + */ + @Test + public void testCharLiteralFromJLS() { + + assertThat( getLiteral( TypeKind.CHAR, "'a'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'%'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\t'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\\'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\''", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\u03a9'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\uFFFF'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'\177'", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.CHAR, "'Ω'", types() ) ).isNotNull(); + + } + + @Test + public void testShortAndByte() { + assertThat( getLiteral( TypeKind.SHORT, "0xFE", types() ) ).isNotNull(); + + // some examples of ints + assertThat( getLiteral( TypeKind.BYTE, "0", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BYTE, "2", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BYTE, "127", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.BYTE, "-128", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.SHORT, "1996", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.SHORT, "-1996", types() ) ).isNotNull(); + } + + @Test + public void testMiscellaneousErroneousPatterns() { + assertThat( getLiteral( TypeKind.INT, "1F", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.FLOAT, "1D", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.INT, "_1", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.INT, "1_", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.INT, "0x_1", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.INT, "0_x1", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9e_-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9_e-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4._9e-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4_.9e-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "_4.9e-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9E-3_", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9E_-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9E-_3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9E+-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9E+_3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "4.9_E-3", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001_P-10d", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001P_-10d", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001_p-10d", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001p_-10d", types() ) ).isNull(); + } + + @Test + public void testNegatives() { + assertThat( getLiteral( TypeKind.INT, "-0xffaa", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "-0377_7777", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.INT, "-0b1111_1111", types() ) ).isNotNull(); + } + + @Test + public void testFaultyChar() { + assertThat( getLiteral( TypeKind.CHAR, "''", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "'a", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "'aa", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "a'", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "aa'", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "'", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.CHAR, "a", types() ) ).isNull(); + } + + @Test + public void testFloatWithLongLiteral() { + assertThat( getLiteral( TypeKind.FLOAT, "156L", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.FLOAT, "156l", types() ) ).isNotNull(); + } + + @Test + public void testLongPrimitivesWithLongSuffix() { + assertThat( getLiteral( TypeKind.LONG, "156l", types() ) ).isNotNull(); + assertThat( getLiteral( TypeKind.LONG, "156L", types() ) ).isNotNull(); + } + + @Test + public void testIntPrimitiveWithLongSuffix() { + assertThat( getLiteral( TypeKind.INT, "156l", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.INT, "156L", types() ) ).isNull(); + } + + @Test + public void testTooBigIntegersAndBigLongs() { + assertThat( getLiteral( TypeKind.INT, "0xFFFF_FFFF_FFFF", types() ) ).isNull(); + assertThat( getLiteral( TypeKind.LONG, "0xFFFF_FFFF_FFFF_FFFF_FFFF", types() ) ).isNull(); + } + + @Test + public void testNonSupportedPrimitiveType() { + assertThat( getLiteral( TypeKind.VOID, "0xFFFF_FFFF_FFFF", types() ) ).isNull(); + } + + private static Types types() { + + InvocationHandler handler = new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if ( "getPrimitiveType".equals( method.getName() ) ) { + return new MyTypeMirror(); + } + else { + return null; + } + } + }; + + return (Types) Proxy.newProxyInstance( Types.class.getClassLoader(), new Class[]{Types.class}, handler ); + } + + private static class MyTypeMirror implements PrimitiveType { + + @Override + public TypeKind getKind() { + return TypeKind.VOID; + } + + @Override + public R accept(TypeVisitor v, P p) { + return null; + } + + @Override + public List getAnnotationMirrors() { + return null; + } + + @Override + public A getAnnotation(Class annotationType) { + return null; + } + + @Override + public A[] getAnnotationsByType(Class annotationType) { + return null; + } + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java deleted file mode 100644 index d703d6096a..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantOptimizingTest.java +++ /dev/null @@ -1,342 +0,0 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mapstruct.ap.test.source.constants; - -import javax.lang.model.type.TypeKind; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mapstruct.ap.internal.util.NativeTypes.isStringAssignable; - -/** - * - * @author Sjaak Derksen - */ -public class ConstantOptimizingTest { - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * The following example shows other ways you can use the underscore in numeric literals: - */ - @Test - public void testUnderscorePlacement1() { - assertThat( isStringAssignable( TypeKind.LONG, true, "1234_5678_9012_3456L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "999_99_9999L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.14_15F" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0xFF_EC_DE_5EL" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0xCAFE_BABEL" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0x7fff_ffff_ffff_ffffL" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BYTE, true, "0b0010_0101" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0b11010010_01101001_10010100_10010010L" ) ).isTrue(); - } - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * You can place underscores only between digits; you cannot place underscores in the following places: - *
        - *
      1. At the beginning or end of a number
      2. - *
      3. Adjacent to a decimal point in a floating point literal
      4. - *
      5. Prior to an F or L suffix
      6. - *
      7. In positions where a string of digits is expected
      8. - *
      - * The following examples demonstrate valid and invalid underscore placements (which are highlighted) in numeric - * literals: - */ - @Test - public void testUnderscorePlacement2() { - - // Invalid: cannot put underscores - // adjacent to a decimal point - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3_.1415F" ) ).isFalse(); - - // Invalid: cannot put underscores - // adjacent to a decimal point - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3._1415F" ) ).isFalse(); - - // Invalid: cannot put underscores - // prior to an L suffix - assertThat( isStringAssignable( TypeKind.LONG, true, "999_99_9999_L" ) ).isFalse(); - - // OK (decimal literal) - assertThat( isStringAssignable( TypeKind.INT, true, "5_2" ) ).isTrue(); - - // Invalid: cannot put underscores - // At the end of a literal - assertThat( isStringAssignable( TypeKind.INT, true, "52_" ) ).isFalse(); - - // OK (decimal literal) - assertThat( isStringAssignable( TypeKind.INT, true, "5_______2" ) ).isTrue(); - - // Invalid: cannot put underscores - // in the 0x radix prefix - assertThat( isStringAssignable( TypeKind.INT, true, "0_x52" ) ).isFalse(); - - // Invalid: cannot put underscores - // at the beginning of a number - assertThat( isStringAssignable( TypeKind.INT, true, "0x_52" ) ).isFalse(); - - // OK (hexadecimal literal) - assertThat( isStringAssignable( TypeKind.INT, true, "0x5_2" ) ).isTrue(); - - // Invalid: cannot put underscores - // at the end of a number - assertThat( isStringAssignable( TypeKind.INT, true, "0x52_" ) ).isFalse(); - } - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * The following example shows other ways you can use the underscore in numeric literals: - */ - @Test - public void testIntegerLiteralFromJLS() { - - // largest positive int: dec / octal / int / binary - assertThat( isStringAssignable( TypeKind.INT, true, "2147483647" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0x7fff_ffff" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0177_7777_7777" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0b0111_1111_1111_1111_1111_1111_1111_1111" ) ).isTrue(); - - // most negative int: dec / octal / int / binary - // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can disssapear (java8) - // and the function will be true to what the compiler shows. - assertThat( isStringAssignable( TypeKind.INT, true, "-2147483648" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0x8000_0000" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0200_0000_0000" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0b1000_0000_0000_0000_0000_0000_0000_0000" ) ).isTrue(); - - // -1 representation int: dec / octal / int / binary - assertThat( isStringAssignable( TypeKind.INT, true, "-1" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0xffff_ffff" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0377_7777_7777" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0b1111_1111_1111_1111_1111_1111_1111_1111" ) ).isTrue(); - - // largest positive long: dec / octal / int / binary - assertThat( isStringAssignable( TypeKind.LONG, true, "9223372036854775807L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0x7fff_ffff_ffff_ffffL" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "07_7777_7777_7777_7777_7777L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" - + "1111_1111_1111_1111_1111_1111L" ) ).isTrue(); - // most negative long: dec / octal / int / binary - assertThat( isStringAssignable( TypeKind.LONG, true, "-9223372036854775808L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0x8000_0000_0000_0000L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "010_0000_0000_0000_0000_0000L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_" - + "0000_0000_0000_0000_0000L" ) ).isTrue(); - // -1 representation long: dec / octal / int / binary - assertThat( isStringAssignable( TypeKind.LONG, true, "-1L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0xffff_ffff_ffff_ffffL" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "017_7777_7777_7777_7777_7777L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_" - + "1111_1111_1111_1111_1111L" ) ).isTrue(); - - // some examples of ints - assertThat( isStringAssignable( TypeKind.INT, true, "0" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "2" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0372" ) ).isTrue(); - //assertThat( isStringAssignable( TypeKind.INT, true, "0xDada_Cafe" ) ).isTrue(); java8 - assertThat( isStringAssignable( TypeKind.INT, true, "1996" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "0x00_FF__00_FF" ) ).isTrue(); - - // some examples of longs - assertThat( isStringAssignable( TypeKind.LONG, true, "0777l" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0x100000000L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "2_147_483_648L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0xC0B0L" ) ).isTrue(); - } - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * The following example shows other ways you can use the underscore in numeric literals: - */ - @Test - public void testFloatingPoingLiteralFromJLS() { - - // The largest positive finite literal of type float is 3.4028235e38f. - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e38f" ) ).isTrue(); - // The smallest positive finite non-zero literal of type float is 1.40e-45f. - assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-45f" ) ).isTrue(); - // The largest positive finite literal of type double is 1.7976931348623157e308. - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623157e308" ) ).isTrue(); - // The smallest positive finite non-zero literal of type double is 4.9e-324 - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-324" ) ).isTrue(); - - // some floats - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.1e1F" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "2.f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, ".3f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "0f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.14f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "6.022137e+23f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "-3.14f" ) ).isTrue(); - - // some doubles - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e1" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e+1" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "2." ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, ".3" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0.0" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "3.14" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "-3.14" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e-9D" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1e137" ) ).isTrue(); - - // too large (infinitve) - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e38f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623157e308" ) ).isTrue(); - - // too large (infinitve) - assertThat( isStringAssignable( TypeKind.FLOAT, true, "3.4028235e39f" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "1.7976931348623159e308" ) ).isFalse(); - - // small - assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-45f" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "0x1.0p-149" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-324" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001P-1062d" ) ).isTrue(); - - // too small - assertThat( isStringAssignable( TypeKind.FLOAT, true, "1.40e-46f" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "0x1.0p-150" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e-325" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001p-1063d" ) ).isFalse(); - } - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * The following example shows other ways you can use the underscore in numeric literals: - */ - @Test - public void testBooleanLiteralFromJLS() { - assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "true" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "false" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BOOLEAN, true, "FALSE" ) ).isFalse(); - } - - /** - * checkout https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html - * - * The following example shows other ways you can use the underscore in numeric literals: - */ - @Test - public void testCharLiteralFromJLS() { - - assertThat( isStringAssignable( TypeKind.CHAR, true, "'a'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'%'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\t'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\\'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\''" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\u03a9'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\uFFFF'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'\177'" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'Ω'" ) ).isTrue(); - - } - - @Test - public void testShortAndByte() { - assertThat( isStringAssignable( TypeKind.SHORT, true, "0xFE" ) ).isTrue(); - - // some examples of ints - assertThat( isStringAssignable( TypeKind.BYTE, true, "0" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BYTE, true, "2" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BYTE, true, "127" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.BYTE, true, "-128" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.SHORT, true, "1996" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.SHORT, true, "-1996" ) ).isTrue(); - } - - @Test - public void testMiscellaneousErroneousPatterns() { - assertThat( isStringAssignable( TypeKind.INT, true, "1F" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "1D" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.INT, true, "_1" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.INT, true, "1_" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.INT, true, "0x_1" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.INT, true, "0_x1" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9e_-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9_e-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4._9e-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4_.9e-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "_4.9e-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E-3_" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E_-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E-_3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E+-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9E+_3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "4.9_E-3" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001_P-10d" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001P_-10d" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001_p-10d" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.DOUBLE, true, "0x0.001p_-10d" ) ).isFalse(); - } - - @Test - public void testNegatives() { - assertThat( isStringAssignable( TypeKind.INT, true, "-0xffaa" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "-0377_7777" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.INT, true, "-0b1111_1111" ) ).isTrue(); - } - - @Test - public void testFaultyChar() { - assertThat( isStringAssignable( TypeKind.CHAR, true, "''" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'a" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'aa" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "a'" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "aa'" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "'" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.CHAR, true, "a" ) ).isFalse(); - } - - @Test - public void testFloatWithLongLiteral() { - assertThat( isStringAssignable( TypeKind.FLOAT, true, "156L" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.FLOAT, true, "156l" ) ).isTrue(); - } - - @Test - public void testLongPrimitivesAndNonRequiredLongSuffix() { - assertThat( isStringAssignable( TypeKind.LONG, true, "156" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "156l" ) ).isTrue(); - assertThat( isStringAssignable( TypeKind.LONG, true, "156L" ) ).isTrue(); - } - - @Test - public void testIntPrimitiveWithLongSuffix() { - assertThat( isStringAssignable( TypeKind.INT, true, "156l" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.INT, true, "156L" ) ).isFalse(); - } - - @Test - public void testTooBigIntegersAndBigLongs() { - assertThat( isStringAssignable( TypeKind.INT, true, "0xFFFF_FFFF_FFFF" ) ).isFalse(); - assertThat( isStringAssignable( TypeKind.LONG, true, "0xFFFF_FFFF_FFFF_FFFF_FFFF" ) ).isFalse(); - } - - @Test - public void testNonSupportedPrimitiveType() { - assertThat( isStringAssignable( TypeKind.VOID, true, "0xFFFF_FFFF_FFFF" ) ).isFalse(); - } - -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java new file mode 100644 index 0000000000..9d474c20f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java @@ -0,0 +1,63 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.constants; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * + * @author Sjaak Derksen + */ +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( { + NumericMapper.class, + NumericTarget.class +} ) +public class NumericConstantsTest { + + @Rule + public final GeneratedSource generatedSrc = new GeneratedSource().addComparisonToFixtureFor( NumericMapper.class ); + + @Test + public void testNumericConstants() { + + NumericTarget target = NumericMapper.INSTANCE.mapFromConstants( "dummy" ); + + assertThat( target ).isNotNull(); + assertThat( target.getByteValue() ).isEqualTo( (byte) 20 ); + assertThat( target.getByteBoxed() ).isEqualTo( (byte) -128 ); + assertThat( target.getShortValue() ).isEqualTo( (short) 1996 ); + assertThat( target.getShortBoxed() ).isEqualTo( (short) -1996 ); + assertThat( target.getIntValue() ).isEqualTo( -03777777 ); + assertThat( target.getIntBoxed() ).isEqualTo( 15 ); + assertThat( target.getLongValue() ).isEqualTo( 0x7fffffffffffffffL ); + assertThat( target.getLongBoxed() ).isEqualTo( 0xCAFEBABEL ); + assertThat( target.getFloatValue() ).isEqualTo( 1.40e-45f ); + assertThat( target.getFloatBoxed() ).isEqualTo( 3.4028235e38f ); + assertThat( target.getDoubleValue() ).isEqualTo( 1e137 ); + assertThat( target.getDoubleBoxed() ).isEqualTo( 0x0.001P-1062d ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java new file mode 100644 index 0000000000..4c555a3046 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java @@ -0,0 +1,51 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.test.source.constants; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface NumericMapper { + + NumericMapper INSTANCE = Mappers.getMapper( NumericMapper.class ); + + @Mappings({ + @Mapping(target = "byteValue", constant = "20"), + @Mapping(target = "byteBoxed", constant = "-128"), + @Mapping(target = "shortValue", constant = "1996"), + @Mapping(target = "shortBoxed", constant = "-1996"), + @Mapping(target = "intValue", constant = "-03777777"), + @Mapping(target = "intBoxed", constant = "15"), + @Mapping(target = "longValue", constant = "0x7fffffffffffffffL"), + @Mapping(target = "longBoxed", constant = "0xCAFEBABEL"), + @Mapping(target = "floatValue", constant = "1.40e-45f"), + @Mapping(target = "floatBoxed", constant = "3.4028235e38f"), + @Mapping(target = "doubleValue", constant = "1e137"), + @Mapping(target = "doubleBoxed", constant = "0x0.001P-1062d"), + }) + NumericTarget mapFromConstants( String dummy ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java new file mode 100644 index 0000000000..768dfd7526 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java @@ -0,0 +1,137 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.test.source.constants; + +/** + * + * @author Sjaak Derksen + */ +public class NumericTarget { + + private byte byteValue; + private Byte byteBoxed; + private short shortValue; + private Short shortBoxed; + private int intValue; + private Integer intBoxed; + private long longValue; + private Long longBoxed; + private float floatValue; + private Float floatBoxed; + private double doubleValue; + private Double doubleBoxed; + + public byte getByteValue() { + return byteValue; + } + + public void setByteValue(byte byteValue) { + this.byteValue = byteValue; + } + + public Byte getByteBoxed() { + return byteBoxed; + } + + public void setByteBoxed(Byte byteBoxed) { + this.byteBoxed = byteBoxed; + } + + public short getShortValue() { + return shortValue; + } + + public void setShortValue(short shortValue) { + this.shortValue = shortValue; + } + + public Short getShortBoxed() { + return shortBoxed; + } + + public void setShortBoxed(Short shortBoxed) { + this.shortBoxed = shortBoxed; + } + + public int getIntValue() { + return intValue; + } + + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + public Integer getIntBoxed() { + return intBoxed; + } + + public void setIntBoxed(Integer intBoxed) { + this.intBoxed = intBoxed; + } + + public long getLongValue() { + return longValue; + } + + public void setLongValue(long longValue) { + this.longValue = longValue; + } + + public Long getLongBoxed() { + return longBoxed; + } + + public void setLongBoxed(Long longBoxed) { + this.longBoxed = longBoxed; + } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } + + public Float getFloatBoxed() { + return floatBoxed; + } + + public void setFloatBoxed(Float floatBoxed) { + this.floatBoxed = floatBoxed; + } + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + public Double getDoubleBoxed() { + return doubleBoxed; + } + + public void setDoubleBoxed(Double doubleBoxed) { + this.doubleBoxed = doubleBoxed; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index be4a046d94..1157925f46 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -217,7 +217,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc public void errorOnNonExistingEnumConstant() throws ParseException { } - @Test + @Test @IssueKey("1401") @WithClasses({ Source.class, diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java new file mode 100644 index 0000000000..c8aef1b48f --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.source.constants; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2018-04-28T11:42:09+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)" +) +public class NumericMapperImpl implements NumericMapper { + + @Override + public NumericTarget mapFromConstants(String dummy) { + if ( dummy == null ) { + return null; + } + + NumericTarget numericTarget = new NumericTarget(); + + numericTarget.setByteBoxed( (byte) -128 ); + numericTarget.setDoubleBoxed( (double) 0x0.001P-1062d ); + numericTarget.setIntValue( -03777777 ); + numericTarget.setLongBoxed( (long) 0xCAFEBABEL ); + numericTarget.setFloatBoxed( 3.4028235e38f ); + numericTarget.setFloatValue( 1.40e-45f ); + numericTarget.setIntBoxed( 15 ); + numericTarget.setDoubleValue( 1e137 ); + numericTarget.setLongValue( 0x7fffffffffffffffL ); + numericTarget.setShortBoxed( (short) -1996 ); + numericTarget.setShortValue( (short) 1996 ); + numericTarget.setByteValue( (byte) 20 ); + + return numericTarget; + } +} From 720854913a26b57ad235c0d9a9e574933e5fa73d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Apr 2018 08:27:57 +0200 Subject: [PATCH 0230/1006] Disable running the annotation processing in the module defining it --- .../resources/namingStrategyTest/strategy/pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml b/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml index a61ae95eca..40885abf15 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml +++ b/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml @@ -40,4 +40,17 @@ provided + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -proc:none + + + + + From 8a247060263fabbf1c271d1c1462acb8a3645efc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Apr 2018 09:59:20 +0200 Subject: [PATCH 0231/1006] Extract methods that use the AccessorNamingStrategy into class instance methods This helps towards #1415, where we need to use strategy based on presence / absence of Immutables --- .../internal/model/MappingBuilderContext.java | 8 ++ .../ap/internal/model/PropertyMapping.java | 17 +-- .../ap/internal/model/common/Type.java | 40 +++--- .../ap/internal/model/common/TypeFactory.java | 2 + .../ap/internal/model/source/Mapping.java | 17 ++- .../internal/model/source/MappingOptions.java | 11 +- .../internal/model/source/SourceMethod.java | 9 +- .../model/source/TargetReference.java | 11 +- .../DefaultModelElementProcessorContext.java | 8 ++ .../processor/MapperCreationProcessor.java | 38 ++++- .../processor/MethodRetrievalProcessor.java | 5 + .../processor/ModelElementProcessor.java | 3 + .../ap/internal/util/AccessorNamingUtils.java | 132 ++++++++++++++++++ .../util/AnnotationProcessorContext.java | 6 + .../ap/internal/util/Executables.java | 92 +----------- .../mapstruct/ap/internal/util/Filters.java | 17 +-- .../DateFormatValidatorFactoryTest.java | 1 + .../common/DefaultConversionContextTest.java | 1 + 18 files changed, 278 insertions(+), 140 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 77bca9fcf8..b8449d975d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -38,6 +38,7 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; import org.mapstruct.ap.spi.MappingExclusionProvider; @@ -125,6 +126,7 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, String tar private final Elements elementUtils; private final Types typeUtils; private final FormattingMessager messager; + private final AccessorNamingUtils accessorNaming; private final Options options; private final TypeElement mapperTypeElement; private final List sourceModel; @@ -138,6 +140,7 @@ public MappingBuilderContext(TypeFactory typeFactory, Elements elementUtils, Types typeUtils, FormattingMessager messager, + AccessorNamingUtils accessorNaming, Options options, MappingResolver mappingResolver, TypeElement mapper, @@ -147,6 +150,7 @@ public MappingBuilderContext(TypeFactory typeFactory, this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; + this.accessorNaming = accessorNaming; this.options = options; this.mappingResolver = mappingResolver; this.mapperTypeElement = mapper; @@ -195,6 +199,10 @@ public FormattingMessager getMessager() { return messager; } + public AccessorNamingUtils getAccessorNaming() { + return accessorNaming; + } + public Options getOptions() { return options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index cb48c23d52..14f1d1153d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -50,6 +50,7 @@ import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; @@ -86,14 +87,14 @@ public enum TargetWriteAccessorType { SETTER, ADDER; - public static TargetWriteAccessorType of(Accessor accessor) { - if ( Executables.isSetterMethod( accessor ) ) { + public static TargetWriteAccessorType of(AccessorNamingUtils accessorNaming, Accessor accessor) { + if ( accessorNaming.isSetterMethod( accessor ) ) { return TargetWriteAccessorType.SETTER; } - else if ( Executables.isAdderMethod( accessor ) ) { + else if ( accessorNaming.isAdderMethod( accessor ) ) { return TargetWriteAccessorType.ADDER; } - else if ( Executables.isGetterMethod( accessor ) ) { + else if ( accessorNaming.isGetterMethod( accessor ) ) { return TargetWriteAccessorType.GETTER; } else { @@ -131,7 +132,7 @@ public T targetProperty(PropertyEntry targetProp) { this.targetReadAccessor = targetProp.getReadAccessor(); this.targetWriteAccessor = targetProp.getWriteAccessor(); this.targetType = targetProp.getType(); - this.targetWriteAccessorType = TargetWriteAccessorType.of( targetWriteAccessor ); + this.targetWriteAccessorType = TargetWriteAccessorType.of( ctx.getAccessorNaming(), targetWriteAccessor ); return (T) this; } @@ -142,7 +143,7 @@ public T targetReadAccessor(Accessor targetReadAccessor) { public T targetWriteAccessor(Accessor targetWriteAccessor) { this.targetWriteAccessor = targetWriteAccessor; - this.targetWriteAccessorType = TargetWriteAccessorType.of( targetWriteAccessor ); + this.targetWriteAccessorType = TargetWriteAccessorType.of( ctx.getAccessorNaming(), targetWriteAccessor ); this.targetType = determineTargetType(); return (T) this; @@ -785,7 +786,7 @@ public PropertyMapping build() { if ( assignment != null ) { - if ( Executables.isSetterMethod( targetWriteAccessor ) || + if ( ctx.getAccessorNaming().isSetterMethod( targetWriteAccessor ) || Executables.isFieldAccessor( targetWriteAccessor ) ) { // target accessor is setter, so decorate assignment as setter @@ -883,7 +884,7 @@ public JavaExpressionMappingBuilder javaExpression(String javaExpression) { public PropertyMapping build() { Assignment assignment = new SourceRHS( javaExpression, null, existingVariableNames, "" ); - if ( Executables.isSetterMethod( targetWriteAccessor ) || + if ( ctx.getAccessorNaming().isSetterMethod( targetWriteAccessor ) || Executables.isFieldAccessor( targetWriteAccessor ) ) { // setter, so wrap in setter assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 1ae66dbe79..0b27f771ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -44,6 +44,7 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.Filters; import org.mapstruct.ap.internal.util.Nouns; @@ -68,6 +69,7 @@ public class Type extends ModelElement implements Comparable { private final Types typeUtils; private final Elements elementUtils; private final TypeFactory typeFactory; + private final AccessorNamingUtils accessorNaming; private final TypeMirror typeMirror; private final TypeElement typeElement; @@ -108,6 +110,7 @@ public class Type extends ModelElement implements Comparable { //CHECKSTYLE:OFF public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, + AccessorNamingUtils accessorNaming, TypeMirror typeMirror, TypeElement typeElement, List typeParameters, ImplementationType implementationType, Type componentType, BuilderInfo builderInfo, @@ -119,6 +122,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.typeUtils = typeUtils; this.elementUtils = elementUtils; this.typeFactory = typeFactory; + this.accessorNaming = accessorNaming; this.typeMirror = typeMirror; this.typeElement = typeElement; @@ -374,6 +378,7 @@ public Type erasure() { typeUtils, elementUtils, typeFactory, + accessorNaming, typeUtils.erasure( typeMirror ), typeElement, typeParameters, @@ -421,26 +426,26 @@ public boolean isAssignableTo(Type other) { */ public Map getPropertyReadAccessors() { if ( readAccessors == null ) { - List getterList = Filters.getterMethodsIn( getAllAccessors() ); + List getterList = Filters.getterMethodsIn( accessorNaming, getAllAccessors() ); Map modifiableGetters = new LinkedHashMap(); for ( Accessor getter : getterList ) { - String propertyName = Executables.getPropertyName( getter ); + String propertyName = accessorNaming.getPropertyName( getter ); if ( modifiableGetters.containsKey( propertyName ) ) { // In the DefaultAccessorNamingStrategy, this can only be the case for Booleans: isFoo() and // getFoo(); The latter is preferred. if ( !getter.getSimpleName().toString().startsWith( "is" ) ) { - modifiableGetters.put( Executables.getPropertyName( getter ), getter ); + modifiableGetters.put( accessorNaming.getPropertyName( getter ), getter ); } } else { - modifiableGetters.put( Executables.getPropertyName( getter ), getter ); + modifiableGetters.put( accessorNaming.getPropertyName( getter ), getter ); } } List fieldsList = Filters.fieldsIn( getAllAccessors() ); for ( Accessor field : fieldsList ) { - String propertyName = Executables.getPropertyName( field ); + String propertyName = accessorNaming.getPropertyName( field ); if ( !modifiableGetters.containsKey( propertyName ) ) { // If there was no getter or is method for booleans, then resort to the field. // If a field was already added do not add it again. @@ -459,11 +464,14 @@ public Map getPropertyReadAccessors() { */ public Map getPropertyPresenceCheckers() { if ( presenceCheckers == null ) { - List checkerList = Filters.presenceCheckMethodsIn( getAllAccessors() ); + List checkerList = Filters.presenceCheckMethodsIn( + accessorNaming, + getAllAccessors() + ); Map modifiableCheckers = new LinkedHashMap(); for ( ExecutableElementAccessor checker : checkerList ) { - modifiableCheckers.put( Executables.getPropertyName( checker ), checker ); + modifiableCheckers.put( accessorNaming.getPropertyName( checker ), checker ); } presenceCheckers = Collections.unmodifiableMap( modifiableCheckers ); } @@ -491,7 +499,7 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg Map result = new LinkedHashMap(); for ( Accessor candidate : candidates ) { - String targetPropertyName = Executables.getPropertyName( candidate ); + String targetPropertyName = accessorNaming.getPropertyName( candidate ); Accessor readAccessor = getPropertyReadAccessors().get( targetPropertyName ); @@ -507,12 +515,12 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg // first check if there's a setter method. Accessor adderMethod = null; - if ( Executables.isSetterMethod( candidate ) + if ( accessorNaming.isSetterMethod( candidate ) // ok, the current accessor is a setter. So now the strategy determines what to use && cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED ) { adderMethod = getAdderForType( targetType, targetPropertyName ); } - else if ( Executables.isGetterMethod( candidate ) ) { + else if ( accessorNaming.isGetterMethod( candidate ) ) { // the current accessor is a getter (no setter available). But still, an add method is according // to the above strategy (SETTER_PREFERRED || ADDER_PREFERRED) preferred over the getter. adderMethod = getAdderForType( targetType, targetPropertyName ); @@ -550,7 +558,7 @@ private Type determineTargetType(Accessor candidate) { if ( parameter != null ) { return parameter.getType(); } - else if ( Executables.isGetterMethod( candidate ) || Executables.isFieldAccessor( candidate ) ) { + else if ( accessorNaming.isGetterMethod( candidate ) || Executables.isFieldAccessor( candidate ) ) { return typeFactory.getReturnType( (DeclaredType) typeMirror, candidate ); } return null; @@ -613,7 +621,7 @@ else if ( candidates.size() == 1 ) { } else { for ( Accessor candidate : candidates ) { - String elementName = Executables.getElementNameForAdder( candidate ); + String elementName = accessorNaming.getElementNameForAdder( candidate ); if ( elementName != null && elementName.equals( Nouns.singularize( pluralPropertyName ) ) ) { return candidate; } @@ -630,7 +638,7 @@ else if ( candidates.size() == 1 ) { */ private List getSetters() { if ( setters == null ) { - setters = Collections.unmodifiableList( Filters.setterMethodsIn( getAllAccessors() ) ); + setters = Collections.unmodifiableList( Filters.setterMethodsIn( accessorNaming, getAllAccessors() ) ); } return setters; } @@ -645,7 +653,7 @@ private List getSetters() { */ private List getAdders() { if ( adders == null ) { - adders = Collections.unmodifiableList( Filters.adderMethodsIn( getAllAccessors() ) ); + adders = Collections.unmodifiableList( Filters.adderMethodsIn( accessorNaming, getAllAccessors() ) ); } return adders; } @@ -691,10 +699,10 @@ else if ( Executables.isFieldAccessor( readAccessor ) && private boolean correspondingSetterMethodExists(Accessor getterMethod, List setterMethods) { - String getterPropertyName = Executables.getPropertyName( getterMethod ); + String getterPropertyName = accessorNaming.getPropertyName( getterMethod ); for ( Accessor setterMethod : setterMethods ) { - String setterPropertyName = Executables.getPropertyName( setterMethod ); + String setterPropertyName = accessorNaming.getPropertyName( setterMethod ); if ( getterPropertyName.equals( setterPropertyName ) ) { return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index d540cfcb24..8b87f92efd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -289,6 +289,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { return new Type( typeUtils, elementUtils, this, + roundContext.getAnnotationProcessorContext().getAccessorNaming(), mirror, typeElement, getTypeParameters( mirror, false ), @@ -500,6 +501,7 @@ private ImplementationType getImplementationType(TypeMirror mirror) { typeUtils, elementUtils, this, + roundContext.getAnnotationProcessorContext().getAccessorNaming(), typeUtils.getDeclaredType( implementationType.getTypeElement(), declaredType.getTypeArguments().toArray( new TypeMirror[] { } ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index fb840d659c..7f695b386c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -39,6 +39,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -333,8 +334,9 @@ private static boolean isEnumType(TypeMirror mirror) { ( (DeclaredType) mirror ).asElement().getKind() == ElementKind.ENUM; } - public void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory) { - init( method, messager, typeFactory, false, null ); + public void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, + AccessorNamingUtils accessorNaming) { + init( method, messager, typeFactory, accessorNaming, false, null ); } /** @@ -343,11 +345,13 @@ public void init(SourceMethod method, FormattingMessager messager, TypeFactory t * @param method the source method that the mapping belongs to * @param messager the messager that can be used for outputting messages * @param typeFactory the type factory + * @param accessorNaming the accessor naming utils * @param isReverse whether the init is for a reverse mapping * @param reverseSourceParameter the source parameter from the revers mapping */ - private void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, boolean isReverse, - Parameter reverseSourceParameter) { + private void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, + AccessorNamingUtils accessorNaming, boolean isReverse, + Parameter reverseSourceParameter) { if ( !method.isEnumMapping() ) { sourceReference = new SourceReference.BuilderFromMapping() @@ -363,6 +367,7 @@ private void init(SourceMethod method, FormattingMessager messager, TypeFactory .method( method ) .messager( messager ) .typeFactory( typeFactory ) + .accessorNaming( accessorNaming ) .reverseSourceParameter( reverseSourceParameter ) .build(); } @@ -473,7 +478,8 @@ public List getDependsOn() { return dependsOn; } - public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory) { + public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, + AccessorNamingUtils accessorNaming) { // mapping can only be reversed if the source was not a constant nor an expression nor a nested property // and the mapping is not a 'target-source-ignore' mapping @@ -502,6 +508,7 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac method, messager, typeFactory, + accessorNaming, true, sourceReference != null ? sourceReference.getParameter() : null ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 2b4c1b518c..62cb0dd3df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -33,6 +33,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -220,9 +221,11 @@ public void markAsFullyInitialized() { * @param method the source method * @param messager the messager * @param typeFactory the type factory + * @param accessorNaming the accessor naming utils */ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, SourceMethod method, - FormattingMessager messager, TypeFactory typeFactory) { + FormattingMessager messager, TypeFactory typeFactory, + AccessorNamingUtils accessorNaming) { if ( null != inherited ) { if ( getIterableMapping() == null ) { if ( inherited.getIterableMapping() != null ) { @@ -270,7 +273,7 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S for ( List lmappings : inherited.getMappings().values() ) { for ( Mapping mapping : lmappings ) { if ( isInverse ) { - mapping = mapping.reverse( method, messager, typeFactory ); + mapping = mapping.reverse( method, messager, typeFactory, accessorNaming ); } if ( mapping != null ) { @@ -297,7 +300,7 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S } public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, FormattingMessager messager, - TypeFactory typeFactory ) { + TypeFactory typeFactory, AccessorNamingUtils accessorNaming) { CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); Type writeType = method.getResultType(); if ( !method.isUpdateMethod() ) { @@ -311,7 +314,7 @@ public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, Format for ( String targetPropertyName : writeAccessors.keySet() ) { if ( !mappedPropertyNames.contains( targetPropertyName ) ) { Mapping mapping = Mapping.forIgnore( targetPropertyName ); - mapping.init( method, messager, typeFactory ); + mapping.init( method, messager, typeFactory, accessorNaming ); mappings.put( targetPropertyName, Arrays.asList( mapping ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index e678a43723..4cf01354d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -36,6 +36,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.ObjectFactoryPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -99,6 +100,7 @@ public static class Builder { private BeanMapping beanMapping = null; private Types typeUtils; private TypeFactory typeFactory = null; + private AccessorNamingUtils accessorNaming = null; private FormattingMessager messager = null; private MapperConfiguration mapperConfig = null; private List prototypeMethods = Collections.emptyList(); @@ -165,6 +167,11 @@ public Builder setTypeFactory(TypeFactory typeFactory) { return this; } + public Builder setAccessorNaming(AccessorNamingUtils accessorNaming) { + this.accessorNaming = accessorNaming; + return this; + } + public Builder setMessager(FormattingMessager messager) { this.messager = messager; return this; @@ -200,7 +207,7 @@ public SourceMethod build() { if ( mappings != null ) { for ( Map.Entry> entry : mappings.entrySet() ) { for ( Mapping mapping : entry.getValue() ) { - mapping.init( sourceMethod, messager, typeFactory ); + mapping.init( sourceMethod, messager, typeFactory, accessorNaming ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 5b48d54ccc..327b7a290c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -30,6 +30,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -74,6 +75,7 @@ public static class BuilderFromTargetMapping { private SourceMethod method; private FormattingMessager messager; private TypeFactory typeFactory; + private AccessorNamingUtils accessorNaming; private boolean isReverse; /** * Needed when we are building from reverse mapping. It is needed, so we can remove the first level if it is @@ -119,6 +121,11 @@ public BuilderFromTargetMapping typeFactory(TypeFactory typeFactory) { return this; } + public BuilderFromTargetMapping accessorNaming(AccessorNamingUtils accessorNaming) { + this.accessorNaming = accessorNaming; + return this; + } + public BuilderFromTargetMapping isReverse(boolean isReverse) { this.isReverse = isReverse; return this; @@ -204,7 +211,7 @@ private List getTargetEntries(Type type, String[] entryNames) { break; } - if ( isLast || ( Executables.isSetterMethod( targetWriteAccessor ) + if ( isLast || ( accessorNaming.isSetterMethod( targetWriteAccessor ) || Executables.isFieldAccessor( targetWriteAccessor ) ) ) { // only intermediate nested properties when they are a true setter or field accessor // the last may be other readAccessor (setter / getter / adder). @@ -234,7 +241,7 @@ private List getTargetEntries(Type type, String[] entryNames) { private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor targetReadAccessor) { Type nextType; Accessor toUse = targetWriteAccessor != null ? targetWriteAccessor : targetReadAccessor; - if ( Executables.isGetterMethod( toUse ) || + if ( accessorNaming.isGetterMethod( toUse ) || Executables.isFieldAccessor( toUse ) ) { nextType = typeFactory.getReturnType( (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 1715849b31..07e0e1a908 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.RoundContext; @@ -50,12 +51,14 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final TypeFactory typeFactory; private final VersionInformation versionInformation; private final Types delegatingTypes; + private final AccessorNamingUtils accessorNaming; public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options, RoundContext roundContext) { this.processingEnvironment = processingEnvironment; this.messager = new DelegatingMessager( processingEnvironment.getMessager() ); + this.accessorNaming = roundContext.getAnnotationProcessorContext().getAccessorNaming(); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); this.delegatingTypes = new TypesDecorator( processingEnvironment, versionInformation ); this.typeFactory = new TypeFactory( @@ -91,6 +94,11 @@ public FormattingMessager getMessager() { return messager; } + @Override + public AccessorNamingUtils getAccessorNaming() { + return accessorNaming; + } + @Override public Options getOptions() { return options; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index caed18144d..d5900a422d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -62,6 +62,7 @@ import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; @@ -85,6 +86,7 @@ public class MapperCreationProcessor implements ModelElementProcessor mapperReferences = initReferencedMappers( mapperTypeElement, mapperConfig ); @@ -104,6 +107,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L elementUtils, typeUtils, messager, + accessorNaming, options, new MappingResolverImpl( messager, @@ -448,10 +452,24 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp // apply defined (@InheritConfiguration, @InheritInverseConfiguration) mappings if ( forwardMappingOptions != null ) { - mappingOptions.applyInheritedOptions( forwardMappingOptions, false, method, messager, typeFactory ); + mappingOptions.applyInheritedOptions( + forwardMappingOptions, + false, + method, + messager, + typeFactory, + accessorNaming + ); } if ( inverseMappingOptions != null ) { - mappingOptions.applyInheritedOptions( inverseMappingOptions, true, method, messager, typeFactory ); + mappingOptions.applyInheritedOptions( + inverseMappingOptions, + true, + method, + messager, + typeFactory, + accessorNaming + ); } // apply auto inherited options @@ -466,7 +484,9 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp false, method, messager, - typeFactory ); + typeFactory, + accessorNaming + ); } else if ( applicablePrototypeMethods.size() > 1 ) { messager.printMessage( @@ -484,7 +504,9 @@ else if ( applicablePrototypeMethods.size() > 1 ) { true, method, messager, - typeFactory ); + typeFactory, + accessorNaming + ); } else if ( applicableReversePrototypeMethods.size() > 1 ) { messager.printMessage( @@ -497,7 +519,13 @@ else if ( applicableReversePrototypeMethods.size() > 1 ) { // @BeanMapping( ignoreByDefault = true ) if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isignoreByDefault() ) { - mappingOptions.applyIgnoreAll( mappingOptions, method, messager, typeFactory ); + mappingOptions.applyIgnoreAll( + mappingOptions, + method, + messager, + typeFactory, + accessorNaming + ); } mappingOptions.markAsFullyInitialized(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 19e3d538f5..8d2b4e8be9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -55,6 +55,7 @@ import org.mapstruct.ap.internal.prism.ObjectFactoryPrism; import org.mapstruct.ap.internal.prism.ValueMappingPrism; import org.mapstruct.ap.internal.prism.ValueMappingsPrism; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -73,6 +74,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor process(ProcessorContext context, TypeElement mapperTypeElement, Void sourceModel) { this.messager = context.getMessager(); this.typeFactory = context.getTypeFactory(); + this.accessorNaming = context.getAccessorNaming(); this.typeUtils = context.getTypeUtils(); this.elementUtils = context.getElementUtils(); @@ -265,6 +268,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setTypeUtils( typeUtils ) .setMessager( messager ) .setTypeFactory( typeFactory ) + .setAccessorNaming( accessorNaming ) .setMapperConfiguration( mapperConfig ) .setPrototypeMethods( prototypeMethods ) .setContextProvidedMethods( contextProvidedMethods ) @@ -322,6 +326,7 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType .setExceptionTypes( exceptionTypes ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) + .setAccessorNaming( accessorNaming ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index 94f8741055..43a857bf37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -26,6 +26,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.version.VersionInformation; @@ -61,6 +62,8 @@ public interface ProcessorContext { FormattingMessager getMessager(); + AccessorNamingUtils getAccessorNaming(); + Options getOptions(); VersionInformation getVersionInformation(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java new file mode 100644 index 0000000000..536498d717 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -0,0 +1,132 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.SimpleElementVisitor6; +import javax.lang.model.util.SimpleTypeVisitor6; + +import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; +import org.mapstruct.ap.spi.MethodType; + +import static org.mapstruct.ap.internal.util.Executables.isPublic; + +/** + * Utils for working with the {@link AccessorNamingStrategy}. + * + * @author Filip Hrisafov + */ +public final class AccessorNamingUtils { + + private final AccessorNamingStrategy accessorNamingStrategy; + + public AccessorNamingUtils() { + accessorNamingStrategy = Services.get( + AccessorNamingStrategy.class, new DefaultAccessorNamingStrategy() + ); + } + + public boolean isGetterMethod(Accessor method) { + ExecutableElement executable = method.getExecutable(); + return executable != null && isPublic( method ) && + executable.getParameters().isEmpty() && + accessorNamingStrategy.getMethodType( executable ) == MethodType.GETTER; + } + + public boolean isPresenceCheckMethod(Accessor method) { + if ( !( method instanceof ExecutableElementAccessor ) ) { + return false; + } + ExecutableElement executable = method.getExecutable(); + return executable != null + && isPublic( method ) + && executable.getParameters().isEmpty() + && ( executable.getReturnType().getKind() == TypeKind.BOOLEAN || + "java.lang.Boolean".equals( getQualifiedName( executable.getReturnType() ) ) ) + && accessorNamingStrategy.getMethodType( executable ) == MethodType.PRESENCE_CHECKER; + } + + public boolean isSetterMethod(Accessor method) { + ExecutableElement executable = method.getExecutable(); + return executable != null + && isPublic( method ) + && executable.getParameters().size() == 1 + && accessorNamingStrategy.getMethodType( executable ) == MethodType.SETTER; + } + + public boolean isAdderMethod(Accessor method) { + ExecutableElement executable = method.getExecutable(); + return executable != null + && isPublic( method ) + && executable.getParameters().size() == 1 + && accessorNamingStrategy.getMethodType( executable ) == MethodType.ADDER; + } + + public String getPropertyName(Accessor accessor) { + ExecutableElement executable = accessor.getExecutable(); + return executable != null ? accessorNamingStrategy.getPropertyName( executable ) : + accessor.getSimpleName().toString(); + } + + /** + * @param adderMethod the adder method + * + * @return the 'element name' to which an adder method applies. If. e.g. an adder method is named + * {@code addChild(Child v)}, the element name would be 'Child'. + */ + public String getElementNameForAdder(Accessor adderMethod) { + ExecutableElement executable = adderMethod.getExecutable(); + return executable != null ? accessorNamingStrategy.getElementName( executable ) : null; + } + + private static String getQualifiedName(TypeMirror type) { + DeclaredType declaredType = type.accept( + new SimpleTypeVisitor6() { + @Override + public DeclaredType visitDeclared(DeclaredType t, Void p) { + return t; + } + }, + null + ); + + if ( declaredType == null ) { + return null; + } + + TypeElement typeElement = declaredType.asElement().accept( + new SimpleElementVisitor6() { + @Override + public TypeElement visitType(TypeElement e, Void p) { + return e; + } + }, + null + ); + + return typeElement != null ? typeElement.getQualifiedName().toString() : null; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 2474c1558f..22044e9799 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -33,10 +33,12 @@ public class AnnotationProcessorContext { private List astModifyingAnnotationProcessors; + private AccessorNamingUtils accessorNaming; public AnnotationProcessorContext() { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors() ); + this.accessorNaming = new AccessorNamingUtils(); } private static List findAstModifyingAnnotationProcessors() { @@ -56,4 +58,8 @@ private static List findAstModifyingAnnotationP public List getAstModifyingAnnotationProcessors() { return astModifyingAnnotationProcessors; } + + public AccessorNamingUtils getAccessorNaming() { + return accessorNaming; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index f70b5fcffc..e4e14c39b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -36,17 +36,12 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; -import javax.lang.model.util.SimpleElementVisitor6; -import javax.lang.model.util.SimpleTypeVisitor6; import org.mapstruct.ap.internal.prism.AfterMappingPrism; import org.mapstruct.ap.internal.prism.BeforeMappingPrism; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; import org.mapstruct.ap.internal.util.accessor.VariableElementAccessor; -import org.mapstruct.ap.spi.AccessorNamingStrategy; -import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; -import org.mapstruct.ap.spi.MethodType; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** @@ -69,20 +64,9 @@ public class Executables { DEFAULT_METHOD = method; } - private static final AccessorNamingStrategy ACCESSOR_NAMING_STRATEGY = Services.get( - AccessorNamingStrategy.class, new DefaultAccessorNamingStrategy() - ); - private Executables() { } - public static boolean isGetterMethod(Accessor method) { - ExecutableElement executable = method.getExecutable(); - return executable != null && isPublic( method ) && - executable.getParameters().isEmpty() && - ACCESSOR_NAMING_STRATEGY.getMethodType( executable ) == MethodType.GETTER; - } - /** * An {@link Accessor} is a field accessor, if it doesn't have an executable element, is public and it is not * static. @@ -96,36 +80,7 @@ public static boolean isFieldAccessor(Accessor accessor) { return executable == null && isPublic( accessor ) && isNotStatic( accessor ); } - public static boolean isPresenceCheckMethod(Accessor method) { - if ( !( method instanceof ExecutableElementAccessor ) ) { - return false; - } - ExecutableElement executable = method.getExecutable(); - return executable != null - && isPublic( method ) - && executable.getParameters().isEmpty() - && ( executable.getReturnType().getKind() == TypeKind.BOOLEAN || - "java.lang.Boolean".equals( getQualifiedName( executable.getReturnType() ) ) ) - && ACCESSOR_NAMING_STRATEGY.getMethodType( executable ) == MethodType.PRESENCE_CHECKER; - } - - public static boolean isSetterMethod(Accessor method) { - ExecutableElement executable = method.getExecutable(); - return executable != null - && isPublic( method ) - && executable.getParameters().size() == 1 - && ACCESSOR_NAMING_STRATEGY.getMethodType( executable ) == MethodType.SETTER; - } - - public static boolean isAdderMethod(Accessor method) { - ExecutableElement executable = method.getExecutable(); - return executable != null - && isPublic( method ) - && executable.getParameters().size() == 1 - && ACCESSOR_NAMING_STRATEGY.getMethodType( executable ) == MethodType.ADDER; - } - - private static boolean isPublic(Accessor method) { + static boolean isPublic(Accessor method) { return method.getModifiers().contains( Modifier.PUBLIC ); } @@ -137,12 +92,6 @@ public static boolean isFinal(Accessor accessor) { return accessor != null && accessor.getModifiers().contains( Modifier.FINAL ); } - public static String getPropertyName(Accessor accessor) { - ExecutableElement executable = accessor.getExecutable(); - return executable != null ? ACCESSOR_NAMING_STRATEGY.getPropertyName( executable ) : - accessor.getSimpleName().toString(); - } - public static boolean isDefaultMethod(ExecutableElement method) { try { return DEFAULT_METHOD != null && Boolean.TRUE.equals( DEFAULT_METHOD.invoke( method ) ); @@ -155,16 +104,6 @@ public static boolean isDefaultMethod(ExecutableElement method) { } } - /** - * @param adderMethod the adder method - * @return the 'element name' to which an adder method applies. If. e.g. an adder method is named - * {@code addChild(Child v)}, the element name would be 'Child'. - */ - public static String getElementNameForAdder(Accessor adderMethod) { - ExecutableElement executable = adderMethod.getExecutable(); - return executable != null ? ACCESSOR_NAMING_STRATEGY.getElementName( executable ) : null; - } - /** * @param mirror the type mirror * @@ -356,33 +295,4 @@ public static boolean isAfterMappingMethod(ExecutableElement executableElement) public static boolean isBeforeMappingMethod(ExecutableElement executableElement) { return BeforeMappingPrism.getInstanceOn( executableElement ) != null; } - - private static String getQualifiedName(TypeMirror type) { - DeclaredType declaredType = type.accept( - new SimpleTypeVisitor6() { - @Override - public DeclaredType visitDeclared(DeclaredType t, Void p) { - return t; - } - }, - null - ); - - if ( declaredType == null ) { - return null; - } - - TypeElement typeElement = declaredType.asElement().accept( - new SimpleElementVisitor6() { - @Override - public TypeElement visitType(TypeElement e, Void p) { - return e; - } - }, - null - ); - - return typeElement != null ? typeElement.getQualifiedName().toString() : null; - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index d26342244c..b50711edf0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -36,11 +36,11 @@ public class Filters { private Filters() { } - public static List getterMethodsIn(List elements) { + public static List getterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { List getterMethods = new LinkedList(); for ( Accessor method : elements ) { - if ( Executables.isGetterMethod( method ) ) { + if ( accessorNaming.isGetterMethod( method ) ) { getterMethods.add( method ); } } @@ -60,11 +60,12 @@ public static List fieldsIn(List accessors) { return fieldAccessors; } - public static List presenceCheckMethodsIn(List elements) { + public static List presenceCheckMethodsIn(AccessorNamingUtils accessorNaming, + List elements) { List presenceCheckMethods = new LinkedList(); for ( Accessor method : elements ) { - if ( Executables.isPresenceCheckMethod( method ) ) { + if ( accessorNaming.isPresenceCheckMethod( method ) ) { presenceCheckMethods.add( (ExecutableElementAccessor) method ); } } @@ -72,22 +73,22 @@ public static List presenceCheckMethodsIn(List setterMethodsIn(List elements) { + public static List setterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { List setterMethods = new LinkedList(); for ( Accessor method : elements ) { - if ( Executables.isSetterMethod( method ) ) { + if ( accessorNaming.isSetterMethod( method ) ) { setterMethods.add( method ); } } return setterMethods; } - public static List adderMethodsIn(List elements) { + public static List adderMethodsIn(AccessorNamingUtils accessorNaming, List elements) { List adderMethods = new LinkedList(); for ( Accessor method : elements ) { - if ( Executables.isAdderMethod( method ) ) { + if ( accessorNaming.isAdderMethod( method ) ) { adderMethods.add( method ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 7afafc0d6b..7b9330ab4f 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -168,6 +168,7 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, + null, voidTypeMirror, null, null, diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 73796af0fb..da16066e35 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -119,6 +119,7 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, + null, voidTypeMirror, null, null, From 7306c525293da10f638ee7937cce56e2b74e2d72 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Apr 2018 10:06:07 +0200 Subject: [PATCH 0232/1006] #1415 Use Immutables AccesorNamingStrategy and BuilderProvider when immutables are present This allows out of the box support for Immutables by picking the right default strategy when immutables are present --- .../mapstruct-reference-guide.asciidoc | 8 ++-- ...rg.mapstruct.ap.spi.AccessorNamingStrategy | 18 --------- .../org.mapstruct.ap.spi.BuilderProvider | 18 --------- .../org/mapstruct/ap/MappingProcessor.java | 2 +- .../ap/internal/model/common/TypeFactory.java | 12 ++---- .../ap/internal/util/AccessorNamingUtils.java | 7 +--- .../util/AnnotationProcessorContext.java | 39 ++++++++++++++++++- .../ap/internal/util/ImmutablesConstants.java | 33 ++++++++++++++++ .../ImmutablesAccessorNamingStrategy.java | 8 ++-- .../ap/spi}/ImmutablesBuilderProvider.java | 22 +++++------ .../mapstruct/ap/spi/NoOpBuilderProvider.java | 6 +++ 11 files changed, 100 insertions(+), 73 deletions(-) delete mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy delete mode 100644 integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java rename {integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras => processor/src/main/java/org/mapstruct/ap/spi}/ImmutablesAccessorNamingStrategy.java (81%) rename {integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras => processor/src/main/java/org/mapstruct/ap/spi}/ImmutablesBuilderProvider.java (85%) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 39b393f7c0..316600a833 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -5,8 +5,8 @@ :Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen, Filip Hrisafov and the MapStruct community :processor-dir: ../../../../processor :processor-ap-test: {processor-dir}/src/test/java/org/mapstruct/ap/test +:processor-ap-main: {processor-dir}/src/main/java/org/mapstruct/ap :integration-tests-dir: ../../../../integrationtest -:immutables-builder-test: {integration-tests-dir}/src/test/resources/immutablesBuilderTest [[Preface]] == Preface @@ -714,7 +714,7 @@ Supported builder frameworks: * https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] * https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] -* https://immutables.github.io/[Immutables] - requires using a custom `AccessorNamingStrategy` and a custom `BuilderProvider` (see example in integration tests) +* https://immutables.github.io/[Immutables] - When Immutables are present on the annotation processor path then the `ImmutablesAccessorNamingStrategy` and `ImmutablesBuilderProvider` would be used by default * https://github.com/google/FreeBuilder[FreeBuilder] * It also works for custom builders (handwritten ones) if the implementation supports the defined rules for the default `BuilderProvider`. Otherwise, you would need to write a custom `BuilderProvider` @@ -2810,11 +2810,11 @@ This JAR file needs to be added to the annotation processor classpath MapStruct offers the possibility to override the `DefaultProvider` via the Service Provider Interface (SPI). A nice example is to provide support for a custom builder strategy. -.Custom Builder Provider for Immutables +.Custom Builder Provider which disables Builder support ==== [source, java, linenums] [subs="verbatim,attributes"] ---- -include::{immutables-builder-test}/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java[tag=documentation] +include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] ---- ==== diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy deleted file mode 100644 index a908131ba1..0000000000 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -org.mapstruct.itest.immutables.extras.ImmutablesAccessorNamingStrategy diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider deleted file mode 100644 index 2ab5dab768..0000000000 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/resources/META-INF/services/org.mapstruct.ap.spi.BuilderProvider +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -org.mapstruct.itest.immutables.extras.ImmutablesBuilderProvider diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index a5bcc66139..ec0db40415 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -127,7 +127,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { super.init( processingEnv ); options = createOptions(); - annotationProcessorContext = new AnnotationProcessorContext(); + annotationProcessorContext = new AnnotationProcessorContext( processingEnv.getElementUtils() ); } private Options createOptions() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 8b87f92efd..b496f36ec6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -57,12 +57,9 @@ import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.RoundContext; -import org.mapstruct.ap.internal.util.Services; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderInfo; -import org.mapstruct.ap.spi.BuilderProvider; -import org.mapstruct.ap.spi.DefaultBuilderProvider; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; import org.mapstruct.ap.internal.util.NativeTypes; @@ -77,11 +74,6 @@ */ public class TypeFactory { - private static final BuilderProvider BUILDER_PROVIDER = Services.get( - BuilderProvider.class, - new DefaultBuilderProvider() - ); - private final Elements elementUtils; private final Types typeUtils; private final RoundContext roundContext; @@ -531,7 +523,9 @@ private ImplementationType getImplementationType(TypeMirror mirror) { } private BuilderInfo findBuilder(TypeMirror type) { - return BUILDER_PROVIDER.findBuilderInfo( type, elementUtils, typeUtils ); + return roundContext.getAnnotationProcessorContext() + .getBuilderProvider() + .findBuilderInfo( type, elementUtils, typeUtils ); } private TypeMirror getComponentType(TypeMirror mirror) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java index 536498d717..247776c547 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -29,7 +29,6 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; import org.mapstruct.ap.spi.AccessorNamingStrategy; -import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.MethodType; import static org.mapstruct.ap.internal.util.Executables.isPublic; @@ -43,10 +42,8 @@ public final class AccessorNamingUtils { private final AccessorNamingStrategy accessorNamingStrategy; - public AccessorNamingUtils() { - accessorNamingStrategy = Services.get( - AccessorNamingStrategy.class, new DefaultAccessorNamingStrategy() - ); + public AccessorNamingUtils(AccessorNamingStrategy accessorNamingStrategy) { + this.accessorNamingStrategy = accessorNamingStrategy; } public boolean isGetterMethod(Accessor method) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 22044e9799..02e95707e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -23,7 +23,16 @@ import java.util.List; import java.util.ServiceLoader; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; + +import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; +import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; /** * Keeps contextual data in the scope of the entire annotation processor ("application scope"). @@ -33,12 +42,30 @@ public class AnnotationProcessorContext { private List astModifyingAnnotationProcessors; + + private final BuilderProvider builderProvider; + private final AccessorNamingStrategy accessorNamingStrategy; + private AccessorNamingUtils accessorNaming; - public AnnotationProcessorContext() { + public AnnotationProcessorContext(Elements elementUtils) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors() ); - this.accessorNaming = new AccessorNamingUtils(); + + AccessorNamingStrategy defaultAccessorNamingStrategy; + BuilderProvider defaultBuilderProvider; + TypeElement immutableElement = elementUtils.getTypeElement( ImmutablesConstants.IMMUTABLE_FQN ); + if ( immutableElement == null ) { + defaultAccessorNamingStrategy = new DefaultAccessorNamingStrategy(); + defaultBuilderProvider = new DefaultBuilderProvider(); + } + else { + defaultAccessorNamingStrategy = new ImmutablesAccessorNamingStrategy(); + defaultBuilderProvider = new ImmutablesBuilderProvider(); + } + this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); + this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); + this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); } private static List findAstModifyingAnnotationProcessors() { @@ -62,4 +89,12 @@ public List getAstModifyingAnnotationProcessors public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } + + public AccessorNamingStrategy getAccessorNamingStrategy() { + return accessorNamingStrategy; + } + + public BuilderProvider getBuilderProvider() { + return builderProvider; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java new file mode 100644 index 0000000000..164888beb8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.util; + +/** + * Helper for holding Immutables FQN. + * + * @author Filip Hrisafov + */ +public class ImmutablesConstants { + + public static final String IMMUTABLE_FQN = "org.immutables.value.Value.Immutable"; + + private ImmutablesConstants() { + + } +} diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java similarity index 81% rename from integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java rename to processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index 56fef54689..5604220920 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -16,13 +16,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.itest.immutables.extras; +package org.mapstruct.ap.spi; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; - /** + * Accesor naming strategy for Immutables. + * The generated Immutables also have a from that works as a copy. Our default strategy considers this method + * as a setter with a name {@code from}. Therefore we are ignoring it. + * * @author Filip Hrisafov */ public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrategy { diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java similarity index 85% rename from integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java rename to processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index 96f1c1bd3c..b02d4a9016 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/extras/src/main/java/org/mapstruct/itest/immutables/extras/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -16,9 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.mapstruct.itest.immutables.extras; - -// tag::documentation[] +package org.mapstruct.ap.spi; import java.util.regex.Pattern; import javax.lang.model.element.AnnotationMirror; @@ -30,19 +28,18 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.spi.BuilderInfo; -import org.mapstruct.ap.spi.DefaultBuilderProvider; -import org.mapstruct.ap.spi.TypeHierarchyErroneousException; - -// end::documentation[] - /** + * Builder provider for Immutables. A custom provider is needed because Immutables creates an implementation of an + * interface and that implementation has the builder. This implementation would try to find the type created by + * Immutables and would look for the builder in it. Only types annotated with the + * {@code org.immutables.value.Value.Immutable} are considered for this discovery. + * * @author Filip Hrisafov */ -// tag::documentation[] public class ImmutablesBuilderProvider extends DefaultBuilderProvider { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + private static final String IMMUTABLE_FQN = "org.immutables.value.Value.Immutable"; @Override protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { @@ -50,7 +47,7 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { return null; } - TypeElement immutableAnnotation = elements.getTypeElement( "org.immutables.value.Value.Immutable" ); + TypeElement immutableAnnotation = elements.getTypeElement( IMMUTABLE_FQN ); if ( immutableAnnotation != null ) { BuilderInfo info = findBuilderInfoForImmutables( typeElement, @@ -83,7 +80,7 @@ protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, return null; } - private TypeElement asImmutableElement(TypeElement typeElement, Elements elements) { + protected TypeElement asImmutableElement(TypeElement typeElement, Elements elements) { Element enclosingElement = typeElement.getEnclosingElement(); StringBuilder builderQualifiedName = new StringBuilder( typeElement.getQualifiedName().length() + 17 ); if ( enclosingElement.getKind() == ElementKind.PACKAGE ) { @@ -101,4 +98,3 @@ private TypeElement asImmutableElement(TypeElement typeElement, Elements element return elements.getTypeElement( builderQualifiedName ); } } -// end::documentation[] diff --git a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java index 598ef1ab3f..b4c3cbe37f 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java @@ -18,15 +18,20 @@ */ package org.mapstruct.ap.spi; +// tag::documentation[] + import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; +// end::documentation[] + /** * A NoOp {@link BuilderProvider} which returns {@code null} when searching for a builder. * * @author Filip Hrisafov */ +// tag::documentation[] public class NoOpBuilderProvider implements BuilderProvider { @Override @@ -34,3 +39,4 @@ public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types typ return null; } } +// end::documentation[] From adde6826a637fb2f54fd4400d2765172858678a5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Apr 2018 16:28:00 +0200 Subject: [PATCH 0233/1006] #1449 Adders should not be considered as builder setter methods --- .../ap/spi/DefaultAccessorNamingStrategy.java | 1 + .../builder/simple/SimpleBuilderMapper.java | 3 ++- .../simple/SimpleImmutableBuilderTest.java | 4 ++++ .../builder/simple/SimpleImmutablePerson.java | 19 +++++++++++++++++++ .../builder/simple/SimpleMutablePerson.java | 11 +++++++++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 0744f75821..72b910d1e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -102,6 +102,7 @@ public boolean isSetterMethod(ExecutableElement method) { protected boolean isBuilderSetter(ExecutableElement method) { return method.getParameters().size() == 1 && !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && + !isAdderMethod( method ) && //TODO The Types need to be compared with Types#isSameType(TypeMirror, TypeMirror) method.getReturnType().toString().equals( method.getEnclosingElement().asType().toString() ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java index 8ccb94c661..3b430b8246 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java @@ -18,11 +18,12 @@ */ package org.mapstruct.ap.test.builder.simple; +import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; -@Mapper +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) public interface SimpleBuilderMapper { @Mappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index a2489753ea..3bf9120f91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.test.builder.simple; +import java.util.Arrays; + import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,6 +50,7 @@ public void testSimpleImmutableBuilderHappyPath() { SimpleMutablePerson source = new SimpleMutablePerson(); source.setAge( 3 ); source.setFullName( "Bob" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); SimpleImmutablePerson targetObject = mapper.toImmutable( source ); @@ -55,6 +58,7 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getName() ).isEqualTo( "Bob" ); assertThat( targetObject.getJob() ).isEqualTo( "programmer" ); assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" ); + assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java index 3e6668d14a..a4c98f8e0c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java @@ -18,17 +18,22 @@ */ package org.mapstruct.ap.test.builder.simple; +import java.util.ArrayList; +import java.util.List; + public class SimpleImmutablePerson { private final String name; private final int age; private final String job; private final String city; + private final List children; SimpleImmutablePerson(Builder builder) { this.name = builder.name; this.age = builder.age; this.job = builder.job; this.city = builder.city; + this.children = new ArrayList( builder.children ); } public static Builder builder() { @@ -51,11 +56,16 @@ public String getCity() { return city; } + public List getChildren() { + return children; + } + public static class Builder { private String name; private int age; private String job; private String city; + private List children = new ArrayList(); public Builder age(int age) { this.age = age; @@ -80,5 +90,14 @@ public Builder city(String city) { this.city = city; return this; } + + public List getChildren() { + throw new UnsupportedOperationException( "This is just a marker method" ); + } + + public Builder addChild(String child) { + this.children.add( child ); + return this; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java index 559f81d94d..2e608b32f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java @@ -18,9 +18,12 @@ */ package org.mapstruct.ap.test.builder.simple; +import java.util.List; + public class SimpleMutablePerson { private String fullName; private int age; + private List children; public int getAge() { return age; @@ -37,4 +40,12 @@ public String getFullName() { public void setFullName(String fullName) { this.fullName = fullName; } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } } From 84bf019fdfbf115ea03d4186f86989eb7072c043 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 28 Apr 2018 09:10:56 +0200 Subject: [PATCH 0234/1006] More detailed check for adder in builde --- .../ap/spi/DefaultAccessorNamingStrategy.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 72b910d1e6..a5ee1a2755 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -102,11 +102,24 @@ public boolean isSetterMethod(ExecutableElement method) { protected boolean isBuilderSetter(ExecutableElement method) { return method.getParameters().size() == 1 && !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && - !isAdderMethod( method ) && + !isAdderWithUpperCase4thCharacter( method ) && //TODO The Types need to be compared with Types#isSameType(TypeMirror, TypeMirror) method.getReturnType().toString().equals( method.getEnclosingElement().asType().toString() ); } + /** + * Checks that the method is an adder with an upper case 4th character. The reason for this is that methods such + * as {@code address(String address)} are considered as setter and {@code addName(String name)} too. We need to + * make sure that {@code addName} is considered as an adder and {@code address} is considered as a setter. + * + * @param method the method that needs to be checked + * + * @return {@code true} if the method is an adder with an upper case 4h character, {@code false} otherwise + */ + private boolean isAdderWithUpperCase4thCharacter(ExecutableElement method) { + return isAdderMethod( method ) && Character.isUpperCase( method.getSimpleName().toString().charAt( 3 ) ); + } + /** * Returns {@code true} when the {@link ExecutableElement} is an adder method. An adder method starts with 'add'. * The remainder of the name is supposed to reflect the singular property name (as opposed to plural) of From b6905d5168ce81089608cfaa244547f74e473ee8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 28 Apr 2018 10:05:49 +0200 Subject: [PATCH 0235/1006] Make sure we have a conflicting test with adder --- .../builder/simple/ErroneousSimpleBuilderMapper.java | 1 + .../builder/simple/SimpleImmutableBuilderTest.java | 4 +++- .../test/builder/simple/SimpleImmutablePerson.java | 12 ++++++++++++ .../ap/test/builder/simple/SimpleMutablePerson.java | 9 +++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java index 94ac2f6bc4..f5812aaa85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java @@ -27,6 +27,7 @@ public interface ErroneousSimpleBuilderMapper { @Mappings({ + @Mapping(target = "address", ignore = true ), @Mapping(target = "job", ignore = true ), @Mapping(target = "city", ignore = true ) }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index 3bf9120f91..5afa4e6682 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -51,6 +51,7 @@ public void testSimpleImmutableBuilderHappyPath() { source.setAge( 3 ); source.setFullName( "Bob" ); source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + source.setAddress( "Plaza 1" ); SimpleImmutablePerson targetObject = mapper.toImmutable( source ); @@ -58,6 +59,7 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getName() ).isEqualTo( "Bob" ); assertThat( targetObject.getJob() ).isEqualTo( "programmer" ); assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" ); + assertThat( targetObject.getAddress() ).isEqualTo( "Plaza 1" ); assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" ); } @@ -67,7 +69,7 @@ public void testSimpleImmutableBuilderHappyPath() { diagnostics = @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousSimpleBuilderMapper.class, - line = 33, + line = 34, messageRegExp = "Unmapped target property: \"name\"\\.")) public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java index a4c98f8e0c..0d9a92b745 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java @@ -26,6 +26,7 @@ public class SimpleImmutablePerson { private final int age; private final String job; private final String city; + private final String address; private final List children; SimpleImmutablePerson(Builder builder) { @@ -33,6 +34,7 @@ public class SimpleImmutablePerson { this.age = builder.age; this.job = builder.job; this.city = builder.city; + this.address = builder.address; this.children = new ArrayList( builder.children ); } @@ -56,6 +58,10 @@ public String getCity() { return city; } + public String getAddress() { + return address; + } + public List getChildren() { return children; } @@ -65,6 +71,7 @@ public static class Builder { private int age; private String job; private String city; + private String address; private List children = new ArrayList(); public Builder age(int age) { @@ -91,6 +98,11 @@ public Builder city(String city) { return this; } + public Builder address(String address) { + this.address = address; + return this; + } + public List getChildren() { throw new UnsupportedOperationException( "This is just a marker method" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java index 2e608b32f8..52b6c49ee2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java @@ -23,6 +23,7 @@ public class SimpleMutablePerson { private String fullName; private int age; + private String address; private List children; public int getAge() { @@ -41,6 +42,14 @@ public void setFullName(String fullName) { this.fullName = fullName; } + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + public List getChildren() { return children; } From 7a3f6d973e442bc811a39cdbe67021fa129af9ab Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 3 May 2018 23:15:23 +0200 Subject: [PATCH 0236/1006] #1473 Make sure that the SPIs are lazy initialized in the AnnotationProcessorContext --- .../util/AnnotationProcessorContext.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 02e95707e6..418b83f679 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -43,14 +43,30 @@ public class AnnotationProcessorContext { private List astModifyingAnnotationProcessors; - private final BuilderProvider builderProvider; - private final AccessorNamingStrategy accessorNamingStrategy; + private BuilderProvider builderProvider; + private AccessorNamingStrategy accessorNamingStrategy; + private boolean initialized; private AccessorNamingUtils accessorNaming; + private Elements elementUtils; public AnnotationProcessorContext(Elements elementUtils) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors() ); + this.elementUtils = elementUtils; + } + + /** + * Method for initializing the context with the SPIs. The reason why we do this is due to the fact that + * when custom SPI implementations are done and users don't set {@code proc:none} then our processor + * would be triggered. And this context will always get initialized and the SPI won't be found. However, + * if this is lazily evaluated it won't be a problem, as in the SPI implementation module there won't be any + * processing done. + */ + private void initialize() { + if ( initialized ) { + return; + } AccessorNamingStrategy defaultAccessorNamingStrategy; BuilderProvider defaultBuilderProvider; @@ -66,6 +82,7 @@ public AnnotationProcessorContext(Elements elementUtils) { this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); + this.initialized = true; } private static List findAstModifyingAnnotationProcessors() { @@ -87,14 +104,17 @@ public List getAstModifyingAnnotationProcessors } public AccessorNamingUtils getAccessorNaming() { + initialize(); return accessorNaming; } public AccessorNamingStrategy getAccessorNamingStrategy() { + initialize(); return accessorNamingStrategy; } public BuilderProvider getBuilderProvider() { + initialize(); return builderProvider; } } From bf31ec72de38bd5b59f357525e40e665192723ae Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 4 May 2018 08:09:37 +0200 Subject: [PATCH 0237/1006] #1338 Using an adder with non generic source collection should work --- .../ap/internal/model/assignment/AdderWrapper.java | 11 ++++++++++- .../ap/internal/model/common/SourceRHS.java | 5 ++++- .../ap/internal/model/assignment/AdderWrapper.ftl | 2 +- .../ap/test/bugs/_1338/Issue1338Mapper.java | 2 ++ .../ap/test/bugs/_1338/Issue1338Test.java | 8 +++++++- .../org/mapstruct/ap/test/bugs/_1338/Source.java | 14 +++++++++++--- .../org/mapstruct/ap/test/bugs/_1338/Target.java | 4 ++++ 7 files changed, 39 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 3c7e03505c..d7e9322d4c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -19,6 +19,7 @@ package org.mapstruct.ap.internal.model.assignment; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -27,6 +28,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Nouns; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * Wraps the assignment in a target setter. * @@ -35,6 +38,7 @@ public class AdderWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; + private final Type adderType; public AdderWrapper( Assignment rhs, List thrownTypesToExclude, @@ -44,6 +48,7 @@ public AdderWrapper( Assignment rhs, this.thrownTypesToExclude = thrownTypesToExclude; String desiredName = Nouns.singularize( targetPropertyName ); rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); + adderType = first( getSourceType().determineTypeArguments( Collection.class ) ); } @Override @@ -60,11 +65,15 @@ public List getThrownTypes() { return result; } + public Type getAdderType() { + return adderType; + } + @Override public Set getImportTypes() { Set imported = new HashSet(); imported.addAll( super.getImportTypes() ); - imported.add( getSourceType().getTypeParameters().get( 0 ).getTypeBound() ); + imported.add( adderType.getTypeBound() ); return imported; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index 90493453b2..61de3548c1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -18,12 +18,15 @@ */ package org.mapstruct.ap.internal.model.common; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * SourceRHS Assignment. Right Hand Side (RHS), source part of the assignment. * @@ -135,7 +138,7 @@ public String getSourceErrorMessagePart() { */ public Type getSourceTypeForMatching() { return useElementAsSourceTypeForMatching && sourceType.isCollectionType() ? - sourceType.getTypeParameters().get( 0 ) : sourceType; + first( sourceType.determineTypeArguments( Collection.class ) ) : sourceType; } /** diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index c039f459cb..190c95fa14 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -22,7 +22,7 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> if ( ${sourceReference} != null ) { - for ( <@includeModel object=sourceType.typeParameters[0].typeBound/> ${sourceLocalVarName} : ${sourceReference} ) { + for ( <@includeModel object=adderType.typeBound/> ${sourceLocalVarName} : ${sourceReference} ) { ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java index ade7b14bee..b4b6b7022f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java @@ -31,4 +31,6 @@ public interface Issue1338Mapper { Issue1338Mapper INSTANCE = Mappers.getMapper( Issue1338Mapper.class ); Target map(Source source); + + Source map(Target target); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java index 7b8d5ce8d0..08a4b3ccd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java @@ -43,11 +43,17 @@ public class Issue1338Test { @Test public void shouldCorrectlyUseAdder() { - Target target = Issue1338Mapper.INSTANCE.map( new Source( Arrays.asList( "first", "second" ) ) ); + Source source = new Source(); + source.setProperties( Arrays.asList( "first", "second" ) ); + Target target = Issue1338Mapper.INSTANCE.map( source ); assertThat( target ) .extracting( "properties" ) .contains( Arrays.asList( "first", "second" ), atIndex( 0 ) ); + Source mapped = Issue1338Mapper.INSTANCE.map( target ); + + assertThat( mapped.getProperties() ) + .containsExactly( "first", "second" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java index 5c8a6c84b9..1700fd62d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.test.bugs._1338; +import java.util.ArrayList; import java.util.List; /** @@ -25,13 +26,20 @@ */ public class Source { - private final List properties; + private List properties; - public Source(List properties) { - this.properties = properties; + public void addProperty(String property) { + if ( properties == null ) { + properties = new ArrayList(); + } + properties.add( property ); } public List getProperties() { return properties; } + + public void setProperties(List properties) { + this.properties = properties; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java index 793541cbc9..0ee75087f0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java @@ -35,6 +35,10 @@ public void setProperties(StringList properties) { throw new IllegalStateException( "Setter is there just as a marker it should not be used" ); } + public StringList getProperties() { + return properties; + } + public static class StringList extends ArrayList { private StringList() { From b2919079188938c02750fe0d9e3734c9213a6585 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sat, 5 May 2018 20:42:37 +0200 Subject: [PATCH 0238/1006] #1460 Ensures the FQN will be used for SimpleConversion if required * Added getReferenceName() to Type which returns simple or fully-qualified-name * Use getReferenceName() in all SimpleConversions * Added testcase that is not working without these changes * Added ConversionUtils with a lot of helper methods to create the "reference names" used in SimpleConversions --- .../AbstractJavaTimeToStringConversion.java | 27 +- .../AbstractJodaTypeToStringConversion.java | 18 +- .../AbstractNumberToStringConversion.java | 2 - .../BigDecimalToBigIntegerConversion.java | 9 +- .../BigDecimalToPrimitiveConversion.java | 7 +- .../BigDecimalToStringConversion.java | 10 +- .../BigDecimalToWrapperConversion.java | 7 +- .../BigIntegerToPrimitiveConversion.java | 7 +- .../BigIntegerToStringConversion.java | 14 +- .../BigIntegerToWrapperConversion.java | 7 +- .../internal/conversion/ConversionUtils.java | 243 ++++++++++++++++++ .../CurrencyToStringConversion.java | 8 +- .../conversion/DateToSqlDateConversion.java | 14 +- .../conversion/DateToSqlTimeConversion.java | 4 +- .../DateToSqlTimestampConversion.java | 4 +- .../conversion/DateToStringConversion.java | 11 +- .../conversion/EnumStringConversion.java | 11 +- .../JavaLocalDateTimeToDateConversion.java | 39 ++- .../JavaLocalDateToDateConversion.java | 37 ++- .../JavaZonedDateTimeToDateConversion.java | 33 ++- .../JodaDateTimeToCalendarConversion.java | 9 +- .../conversion/JodaTimeToDateConversion.java | 2 +- .../PrimitiveToStringConversion.java | 34 ++- .../conversion/WrapperToStringConversion.java | 34 ++- .../ap/internal/model/common/Type.java | 10 +- .../ap/internal/util/JavaTimeConstants.java | 4 + .../ap/internal/model/common/Type.ftl | 2 +- .../ap/test/bugs/_1460/Issue1460Mapper.java | 53 ++++ .../ap/test/bugs/_1460/Issue1460Test.java | 67 +++++ .../mapstruct/ap/test/bugs/_1460/Source.java | 53 ++++ .../mapstruct/ap/test/bugs/_1460/Target.java | 57 ++++ .../_1460/java8/Issue1460JavaTimeMapper.java | 38 +++ .../_1460/java8/Issue1460JavaTimeTest.java | 55 ++++ .../ap/test/bugs/_1460/java8/Source.java | 32 +++ .../ap/test/bugs/_1460/java8/Target.java | 34 +++ 35 files changed, 923 insertions(+), 73 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java index 9f3ce654f5..093e1511f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java @@ -52,10 +52,12 @@ protected String getToExpression(ConversionContext conversionContext) { private String dateTimeFormatter(ConversionContext conversionContext) { if ( !Strings.isEmpty( conversionContext.getDateFormat() ) ) { - return "DateTimeFormatter.ofPattern( \"" + conversionContext.getDateFormat() + "\" )"; + return ConversionUtils.dateTimeFormatter( conversionContext ) + + ".ofPattern( \"" + conversionContext.getDateFormat() + + "\" )"; } else { - return "DateTimeFormatter." + defaultFormatterSuffix(); + return ConversionUtils.dateTimeFormatter( conversionContext ) + "." + defaultFormatterSuffix(); } } @@ -64,7 +66,7 @@ private String dateTimeFormatter(ConversionContext conversionContext) { @Override protected String getFromExpression(ConversionContext conversionContext) { // See http://docs.oracle.com/javase/tutorial/datetime/iso/format.html for how to parse Dates - return new StringBuilder().append( conversionContext.getTargetType().getFullyQualifiedName() ) + return new StringBuilder().append( conversionContext.getTargetType().getReferenceName() ) .append( ".parse( " ) .append( parametersListForParsing( conversionContext ) ) .append( " )" ).toString(); @@ -74,9 +76,8 @@ private String parametersListForParsing(ConversionContext conversionContext) { // See http://docs.oracle.com/javase/tutorial/datetime/iso/format.html for how to format Dates StringBuilder parameterBuilder = new StringBuilder( "" ); if ( !Strings.isEmpty( conversionContext.getDateFormat() ) ) { - parameterBuilder.append( ", DateTimeFormatter.ofPattern( \"" ) - .append( conversionContext.getDateFormat() ) - .append( "\" )" ); + parameterBuilder.append( ", " ); + parameterBuilder.append( dateTimeFormatter( conversionContext ) ); } return parameterBuilder.toString(); } @@ -84,14 +85,20 @@ private String parametersListForParsing(ConversionContext conversionContext) { @Override protected Set getToConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) + conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) ); } @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { - return Collections.asSet( - conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) - ); + if ( !Strings.isEmpty( conversionContext.getDateFormat() ) ) { + return Collections.asSet( + conversionContext.getTargetType(), + conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) + ); + } + + return Collections.asSet( conversionContext.getTargetType() ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java index c9c80a0486..e6c9b855fa 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Collections; import java.util.Locale; import java.util.Set; @@ -28,6 +26,10 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.dateTimeFormat; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; + /** * Base class for conversions between Joda-Time types and String. * @@ -78,7 +80,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon } private String conversionString(ConversionContext conversionContext, String method) { - StringBuilder conversionString = new StringBuilder( "DateTimeFormat" ); + StringBuilder conversionString = new StringBuilder( dateTimeFormat( conversionContext ) ); conversionString.append( dateFormatPattern( conversionContext ) ); conversionString.append( "." ); conversionString.append( method ); @@ -92,7 +94,7 @@ private String dateFormatPattern(ConversionContext conversionContext) { String dateFormat = conversionContext.getDateFormat(); if ( dateFormat == null ) { - conversionString.append( defaultDateFormatPattern() ); + conversionString.append( defaultDateFormatPattern( conversionContext ) ); } else { @@ -105,8 +107,12 @@ private String dateFormatPattern(ConversionContext conversionContext) { return conversionString.toString(); } - private String defaultDateFormatPattern() { - return " DateTimeFormat.patternForStyle( \"" + formatStyle() + "\", Locale.getDefault() )"; + private String defaultDateFormatPattern(ConversionContext conversionContext) { + return " " + + dateTimeFormat( conversionContext ) + + ".patternForStyle( \"" + formatStyle() + "\", " + + locale( conversionContext ) + + ".getDefault() )"; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java index 1ddd0f5aee..43f8af8416 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java @@ -40,7 +40,6 @@ public abstract class AbstractNumberToStringConversion extends SimpleConversion private final boolean sourceTypeNumberSubclass; public AbstractNumberToStringConversion(boolean sourceTypeNumberSubclass) { - this.sourceTypeNumberSubclass = sourceTypeNumberSubclass; } @@ -77,5 +76,4 @@ protected List getFromConversionExceptionTypes(ConversionContext conversio return super.getFromConversionExceptionTypes( conversionContext ); } } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java index 8e819b5983..080c6e0887 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigDecimal; import java.math.BigInteger; import java.util.Set; @@ -27,6 +25,9 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; + /** * Conversion between {@link BigDecimal} and {@link BigInteger}. * @@ -41,7 +42,9 @@ public String getToExpression(ConversionContext conversionContext) { @Override public String getFromExpression(ConversionContext conversionContext) { - return "new BigDecimal( )"; + return "new " + + bigDecimal( conversionContext ) + + "( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java index 811813c595..851070c540 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java @@ -18,14 +18,15 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigDecimal; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; + /** * Conversion between {@link BigDecimal} and native number types. * @@ -50,7 +51,7 @@ public String getToExpression(ConversionContext conversionContext) { @Override public String getFromExpression(ConversionContext conversionContext) { - return "BigDecimal.valueOf( )"; + return bigDecimal( conversionContext ) + ".valueOf( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index 2e19ee8aa6..d423dc8662 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -29,6 +27,9 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; + /** * Conversion between {@link BigDecimal} and {@link String}. * @@ -57,13 +58,13 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { StringBuilder sb = new StringBuilder(); - sb.append( "(BigDecimal) " ); + sb.append( "(" + bigDecimal( conversionContext ) + ") " ); appendDecimalFormatter( sb, conversionContext ); sb.append( ".parse( )" ); return sb.toString(); } else { - return "new BigDecimal( )"; + return "new " + bigDecimal( conversionContext ) + "( )"; } } @@ -91,5 +92,4 @@ private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversi sb.append( " )" ); } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java index 860961e6f4..0068a27d2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigDecimal; import java.util.Set; @@ -27,6 +25,9 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; + /** * Conversion between {@link BigDecimal} and wrappers of native number types. * @@ -51,7 +52,7 @@ public String getToExpression(ConversionContext conversionContext) { @Override public String getFromExpression(ConversionContext conversionContext) { - return "BigDecimal.valueOf( )"; + return bigDecimal( conversionContext ) + ".valueOf( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java index 5021204b24..464f983825 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java @@ -18,14 +18,15 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigInteger; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; + /** * Conversion between {@link BigInteger} and native number types. * @@ -54,7 +55,7 @@ public String getFromExpression(ConversionContext conversionContext) { if ( targetType == float.class || targetType == double.class ) { castString = "(long) "; } - return "BigInteger.valueOf( " + castString + " )"; + return bigInteger( conversionContext ) + ".valueOf( " + castString + " )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index 6b99b0fd19..034d191227 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -18,8 +18,7 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - +import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.List; @@ -29,6 +28,10 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; + /** * Conversion between {@link BigInteger} and {@link String}. * @@ -57,22 +60,21 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { StringBuilder sb = new StringBuilder(); - sb.append( "( (BigDecimal) " ); + sb.append( "( (" + bigDecimal( conversionContext ) + ") " ); appendDecimalFormatter( sb, conversionContext ); sb.append( ".parse( )" ); sb.append( " ).toBigInteger()" ); return sb.toString(); } else { - return "new BigInteger( )"; + return "new " + bigInteger( conversionContext ) + "( )"; } } @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { - // no imports are required when decimal format is used. - return super.getFromConversionImportTypes( conversionContext ); + return asSet( conversionContext.getTypeFactory().getType( BigDecimal.class ) ); } else { return asSet( conversionContext.getTypeFactory().getType( BigInteger.class ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java index 168a83f262..5ec50cf246 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.math.BigInteger; import java.util.Set; @@ -27,6 +25,9 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; + /** * Conversion between {@link BigInteger} and wrappers of native number types. * @@ -56,7 +57,7 @@ public String getFromExpression(ConversionContext conversionContext) { toLongValueStr = ".longValue()"; } - return "BigInteger.valueOf( " + toLongValueStr + " )"; + return bigInteger( conversionContext ) + ".valueOf( " + toLongValueStr + " )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java new file mode 100644 index 0000000000..f295fa80bc --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -0,0 +1,243 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.conversion; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Time; +import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Currency; +import java.util.Locale; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.util.JavaTimeConstants; +import org.mapstruct.ap.internal.util.JodaTimeConstants; + +/** + * Methods mainly used in {@link org.mapstruct.ap.internal.conversion.SimpleConversion SimpleConversion} classes, e. g. + * to get the correct String representation of various types that could be used in generated sources. + * + * @author Christian Bandowski + */ +public final class ConversionUtils { + private ConversionUtils() { + } + + /** + * Name for the given {@code canonicalName}. + * + * @param conversionContext Conversion context + * @param canonicalName Canonical name of the type + * + * @return Name or fully-qualified name. + */ + private static String typeReferenceName(ConversionContext conversionContext, String canonicalName) { + return conversionContext.getTypeFactory().getType( canonicalName ).getReferenceName(); + } + + /** + * Name for the given {@code canonicalName}. + * + * @param conversionContext Conversion context + * @param type Type + * + * @return Name or fully-qualified name. + */ + private static String typeReferenceName(ConversionContext conversionContext, Class type) { + return conversionContext.getTypeFactory().getType( type ).getReferenceName(); + } + + /** + * Name for {@link java.math.BigDecimal}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String bigDecimal(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, BigDecimal.class ); + } + + /** + * Name for {@link java.math.BigInteger}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String bigInteger(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, BigInteger.class ); + } + + /** + * Name for {@link java.util.Locale}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String locale(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, Locale.class ); + } + + /** + * Name for {@link java.util.Currency}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String currency(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, Currency.class ); + } + + /** + * Name for {@link java.sql.Date}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String sqlDate(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, java.sql.Date.class ); + } + + /** + * Name for {@link java.sql.Time}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String time(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, Time.class ); + } + + /** + * Name for {@link java.sql.Timestamp}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String timestamp(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, Timestamp.class ); + } + + /** + * Name for {@link java.text.DecimalFormat}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String decimalFormat(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, DecimalFormat.class ); + } + + /** + * Name for {@link java.text.SimpleDateFormat}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String simpleDateFormat(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, SimpleDateFormat.class ); + } + + /** + * Name for {@link java.util.Date}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String date(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, java.util.Date.class ); + } + + /** + * Name for {@link java.time.ZoneOffset}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String zoneOffset(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JavaTimeConstants.ZONE_OFFSET_FQN ); + } + + /** + * Name for {@link java.time.ZoneId}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String zoneId(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JavaTimeConstants.ZONE_ID_FQN ); + } + + /** + * Name for {@link java.time.LocalDateTime}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String localDateTime(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JavaTimeConstants.LOCAL_DATE_TIME_FQN ); + } + + /** + * Name for {@link java.time.ZonedDateTime}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String zonedDateTime(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JavaTimeConstants.ZONED_DATE_TIME_FQN ); + } + + /** + * Name for {@link java.time.format.DateTimeFormatter}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String dateTimeFormatter(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JavaTimeConstants.DATE_TIME_FORMATTER_FQN ); + } + + /** + * Name for {@code org.joda.time.format.DateTimeFormat}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String dateTimeFormat(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, JodaTimeConstants.DATE_TIME_FORMAT_FQN ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java index 536c684048..7675370a2e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java @@ -18,12 +18,14 @@ */ package org.mapstruct.ap.internal.conversion; +import java.util.Currency; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Collections; -import java.util.Currency; -import java.util.Set; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.currency; /** * @author Darren Rambaud @@ -36,7 +38,7 @@ protected String getToExpression(final ConversionContext conversionContext) { @Override protected String getFromExpression(final ConversionContext conversionContext) { - return "Currency.getInstance( )"; + return currency( conversionContext ) + ".getInstance( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java index 335913a4a7..5e9d3bc6b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java @@ -18,7 +18,14 @@ */ package org.mapstruct.ap.internal.conversion; +import java.sql.Date; +import java.util.Collections; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.sqlDate; /** * Conversion between {@link java.util.Date} and {@link java.sql.Date}. @@ -29,7 +36,12 @@ public class DateToSqlDateConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "new java.sql.Date( .getTime() )"; + return "new " + sqlDate( conversionContext ) + "( .getTime() )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.singleton( conversionContext.getTypeFactory().getType( Date.class ) ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java index 7ab06ee6f1..9407131728 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java @@ -25,6 +25,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Collections; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.time; + /** * Conversion between {@link java.util.Date} and {@link java.sql.Time}. * @@ -34,7 +36,7 @@ public class DateToSqlTimeConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "new Time( .getTime() )"; + return "new " + time( conversionContext ) + "( .getTime() )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java index 84b3175e00..7086b2fc07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java @@ -25,6 +25,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Collections; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.timestamp; + /** * Conversion between {@link java.util.Date} and {@link java.sql.Timestamp}. * @@ -34,7 +36,7 @@ public class DateToSqlTimestampConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "new Timestamp( .getTime() )"; + return "new " + timestamp( conversionContext ) + "( .getTime() )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index f16a50095b..624c7ab4f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -18,9 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static java.util.Arrays.asList; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collections; @@ -33,6 +30,10 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static java.util.Arrays.asList; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.simpleDateFormat; + /** * Conversion between {@link String} and {@link Date}. * @@ -62,7 +63,9 @@ public List getRequiredHelperMethods(ConversionContext conversionC } private String getConversionExpression(ConversionContext conversionContext, String method) { - StringBuilder conversionString = new StringBuilder( "new SimpleDateFormat(" ); + StringBuilder conversionString = new StringBuilder( "new " ); + conversionString.append( simpleDateFormat( conversionContext ) ); + conversionString.append( '(' ); if ( conversionContext.getDateFormat() != null ) { conversionString.append( " \"" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java index 0eb7ffd991..50447ad699 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java @@ -18,13 +18,13 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * Conversion between {@link String} and {@link Enum} types. * @@ -39,11 +39,14 @@ public String getToExpression(ConversionContext conversionContext) { @Override public String getFromExpression(ConversionContext conversionContext) { - return "Enum.valueOf( " + conversionContext.getTargetType().getName() + ".class, )"; + return "Enum.valueOf( " + conversionContext.getTargetType().getReferenceName() + + ".class, )"; } @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { - return asSet( conversionContext.getTargetType() ); + return asSet( + conversionContext.getTargetType() + ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java index 077589a430..ada1efa1ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java @@ -18,7 +18,20 @@ */ package org.mapstruct.ap.internal.conversion; +import java.util.Date; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.localDateTime; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneId; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.LOCAL_DATE_TIME_FQN; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** * SimpleConversion for mapping {@link java.time.LocalDateTime} to @@ -28,11 +41,33 @@ public class JavaLocalDateTimeToDateConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "java.util.Date.from( .toInstant( java.time.ZoneOffset.UTC ) )"; + return date( conversionContext ) + + ".from( .toInstant( " + + zoneOffset( conversionContext ) + + ".UTC ) )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( Date.class ), + conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + ); } @Override protected String getFromExpression(ConversionContext conversionContext) { - return "java.time.LocalDateTime.ofInstant( .toInstant(), java.time.ZoneId.of( \"UTC\" ) )"; + return localDateTime( conversionContext ) + + ".ofInstant( .toInstant(), " + + zoneId( conversionContext ) + + ".of( \"UTC\" ) )"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( LOCAL_DATE_TIME_FQN ), + conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java index 3abbaeff26..03616b86a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java @@ -18,7 +18,19 @@ */ package org.mapstruct.ap.internal.conversion; +import java.util.Date; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.localDateTime; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.LOCAL_DATE_TIME_FQN; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** * SimpleConversion for mapping {@link java.time.LocalDate} to @@ -28,12 +40,33 @@ public class JavaLocalDateToDateConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "java.util.Date.from( .atStartOfDay( java.time.ZoneOffset.UTC ).toInstant() )"; + return date( conversionContext ) + + ".from( .atStartOfDay( " + + zoneOffset( conversionContext ) + + ".UTC ).toInstant() )"; + } + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( Date.class ), + conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + ); } @Override protected String getFromExpression(ConversionContext conversionContext) { - return "java.time.LocalDateTime.ofInstant( .toInstant(), java.time.ZoneOffset.UTC ).toLocalDate()"; + return localDateTime( conversionContext ) + + ".ofInstant( .toInstant(), " + + zoneOffset( conversionContext ) + + ".UTC ).toLocalDate()"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( LOCAL_DATE_TIME_FQN ), + conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java index 7445ff8702..dee492b847 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java @@ -18,7 +18,18 @@ */ package org.mapstruct.ap.internal.conversion; +import java.util.Date; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneId; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zonedDateTime; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONED_DATE_TIME_FQN; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; /** * SimpleConversion for mapping {@link java.time.ZonedDateTime} to @@ -29,11 +40,29 @@ public class JavaZonedDateTimeToDateConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return "java.util.Date.from( .toInstant() )"; + return date( conversionContext ) + ".from( .toInstant() )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( Date.class ) + ); } @Override protected String getFromExpression(ConversionContext conversionContext) { - return "java.time.ZonedDateTime.ofInstant( .toInstant(), java.time.ZoneId.systemDefault() )"; + return zonedDateTime( conversionContext ) + + ".ofInstant( .toInstant(), " + + zoneId( conversionContext ) + + ".systemDefault() )"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( ZONED_DATE_TIME_FQN ), + conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java index e3b5e52f74..230d2e8ce7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java @@ -18,8 +18,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Calendar; import java.util.Locale; import java.util.Set; @@ -27,6 +25,9 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; + /** * Conversion between {@code DateTime} and {@link Calendar}. * @@ -36,7 +37,7 @@ public class JodaDateTimeToCalendarConversion extends SimpleConversion { @Override protected String getToExpression(ConversionContext conversionContext) { - return ".toCalendar( Locale.getDefault() )"; + return ".toCalendar( " + locale( conversionContext ) + ".getDefault() )"; } @Override @@ -46,7 +47,7 @@ protected Set getToConversionImportTypes(ConversionContext conversionConte @Override protected String getFromExpression(ConversionContext conversionContext) { - return "new " + conversionContext.getTargetType().getName() + "( )"; + return "new " + conversionContext.getTargetType().getReferenceName() + "( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java index 4617e3d6a6..7979099aad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java @@ -45,7 +45,7 @@ protected String getToExpression(ConversionContext conversionContext) { @Override protected String getFromExpression(ConversionContext conversionContext) { - return "new " + conversionContext.getTargetType().getName() + "( )"; + return "new " + conversionContext.getTargetType().getReferenceName() + "( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java index cec648d1ad..52cb7ac171 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java @@ -18,10 +18,17 @@ */ package org.mapstruct.ap.internal.conversion; +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormat; + /** * Conversion between primitive types such as {@code byte} or {@code long} and * {@link String}. @@ -56,6 +63,17 @@ public String getToExpression(ConversionContext conversionContext) { } } + @Override + public Set getToConversionImportTypes(ConversionContext conversionContext) { + if ( requiresDecimalFormat( conversionContext ) ) { + return Collections.singleton( + conversionContext.getTypeFactory().getType( DecimalFormat.class ) + ); + } + + return Collections.emptySet(); + } + @Override public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { @@ -72,8 +90,22 @@ public String getFromExpression(ConversionContext conversionContext) { } } + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + if ( requiresDecimalFormat( conversionContext ) ) { + return Collections.singleton( + conversionContext.getTypeFactory().getType( DecimalFormat.class ) + ); + } + + return Collections.emptySet(); + } + private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { - sb.append( "new DecimalFormat( " ); + sb.append( "new " ); + sb.append( decimalFormat( conversionContext ) ); + sb.append( "( " ); + if ( conversionContext.getNumberFormat() != null ) { sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java index cc53db7994..32ca05572f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java @@ -18,10 +18,17 @@ */ package org.mapstruct.ap.internal.conversion; +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.Set; + import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormat; + /** * Conversion between wrapper types such as {@link Integer} and {@link String}. * @@ -55,6 +62,17 @@ public String getToExpression(ConversionContext conversionContext) { } } + @Override + public Set getToConversionImportTypes(ConversionContext conversionContext) { + if ( requiresDecimalFormat( conversionContext ) ) { + return Collections.singleton( + conversionContext.getTypeFactory().getType( DecimalFormat.class ) + ); + } + + return Collections.emptySet(); + } + @Override public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { @@ -71,8 +89,22 @@ public String getFromExpression(ConversionContext conversionContext) { } } + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + if ( requiresDecimalFormat( conversionContext ) ) { + return Collections.singleton( + conversionContext.getTypeFactory().getType( DecimalFormat.class ) + ); + } + + return Collections.emptySet(); + } + private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { - sb.append( "new DecimalFormat( " ); + sb.append( "new " ); + sb.append( decimalFormat( conversionContext ) ); + sb.append( "( " ); + if ( conversionContext.getNumberFormat() != null ) { sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 0b27f771ef..e33b2cf853 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -181,6 +180,15 @@ public String getName() { return name; } + /** + * String that could be used in generated code to reference to this {@link Type}. + * + * @return Just the name if this {@link Type} will be imported, otherwise the fully-qualified name. + */ + public String getReferenceName() { + return isImported ? name : qualifiedName; + } + public List getTypeParameters() { return typeParameters; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java index f44233581a..a83c52a6f8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java @@ -24,9 +24,13 @@ public final class JavaTimeConstants { public static final String ZONED_DATE_TIME_FQN = "java.time.ZonedDateTime"; + public static final String ZONE_OFFSET_FQN = "java.time.ZoneOffset"; + public static final String ZONE_ID_FQN = "java.time.ZoneId"; + public static final String LOCAL_DATE_TIME_FQN = "java.time.LocalDateTime"; public static final String LOCAL_DATE_FQN = "java.time.LocalDate"; public static final String LOCAL_TIME_FQN = "java.time.LocalTime"; + public static final String DATE_TIME_FORMATTER_FQN = "java.time.format.DateTimeFormatter"; private JavaTimeConstants() { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 15fbc47d84..75348519c1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -26,6 +26,6 @@ <#elseif wildCardSuperBound> ? super <@includeModel object=typeBound /> <#else> - <#if imported>${name}<#else>${fullyQualifiedName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > + ${referenceName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java new file mode 100644 index 0000000000..7f099a499f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper +public abstract class Issue1460Mapper { + + public static final Issue1460Mapper INSTANCE = Mappers.getMapper( Issue1460Mapper.class ); + + public abstract Target map(Source source); + + public abstract String forceUsageOfIssue1460Enum(Issue1460Enum source); + + public abstract String forceUsageOfLocale(Locale source); + + public abstract String forceUsageOfLocalDate(LocalDate source); + + public abstract String forceUsageOfDateTime(DateTime source); + + public static class Issue1460Enum { + } + + public static class Locale { + } + + public static class LocalDate { + } + + public static class DateTime { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java new file mode 100644 index 0000000000..18ff7c5340 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java @@ -0,0 +1,67 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460; + +import java.util.Date; +import java.util.Locale; + +import org.joda.time.DateTime; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Christian Bandowski + */ +@WithClasses({ + Issue1460Mapper.class, + Source.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1460") +public class Issue1460Test { + + @Test + public void shouldTestMappingLocalDates() { + long dateInMs = 1524693600000L; + String dateAsString = "2018-04-26"; + String dateTimeAsString = dateAsString + "T00:00:00+00:00"; + + Source source = new Source(); + source.setStringToEnum( "OK" ); + source.setDateToJodaDateTime( new Date( dateInMs ) ); + source.setJodaDateTimeToCalendar( DateTime.parse( dateTimeAsString ) ); + + Target target = Issue1460Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringToEnum() ).isEqualTo( Target.Issue1460Enum.OK ); + assertThat( target.getDateToJodaDateTime() ).isEqualTo( + new DateTime( new Date( dateInMs ) ) + ); + assertThat( target.getJodaDateTimeToCalendar().getTimeInMillis() ).isEqualTo( + DateTime.parse( dateTimeAsString ).toCalendar( Locale.getDefault() ).getTimeInMillis() + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java new file mode 100644 index 0000000000..2ac3f93026 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460; + +import java.util.Date; + +import org.joda.time.DateTime; + +public class Source { + private String stringToEnum; + private DateTime jodaDateTimeToCalendar; + private Date dateToJodaDateTime; + + public String getStringToEnum() { + return stringToEnum; + } + + public void setStringToEnum(String stringToEnum) { + this.stringToEnum = stringToEnum; + } + + public DateTime getJodaDateTimeToCalendar() { + return jodaDateTimeToCalendar; + } + + public void setJodaDateTimeToCalendar(DateTime jodaDateTimeToCalendar) { + this.jodaDateTimeToCalendar = jodaDateTimeToCalendar; + } + + public Date getDateToJodaDateTime() { + return dateToJodaDateTime; + } + + public void setDateToJodaDateTime(Date dateToJodaDateTime) { + this.dateToJodaDateTime = dateToJodaDateTime; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java new file mode 100644 index 0000000000..dcb20fa6be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java @@ -0,0 +1,57 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460; + +import java.util.Calendar; + +import org.joda.time.DateTime; + +public class Target { + public enum Issue1460Enum { + OK, KO; + } + + private Issue1460Enum stringToEnum; + private Calendar jodaDateTimeToCalendar; + private DateTime dateToJodaDateTime; + + public Issue1460Enum getStringToEnum() { + return stringToEnum; + } + + public void setStringToEnum(Issue1460Enum stringToEnum) { + this.stringToEnum = stringToEnum; + } + + public Calendar getJodaDateTimeToCalendar() { + return jodaDateTimeToCalendar; + } + + public void setJodaDateTimeToCalendar(Calendar jodaDateTimeToCalendar) { + this.jodaDateTimeToCalendar = jodaDateTimeToCalendar; + } + + public DateTime getDateToJodaDateTime() { + return dateToJodaDateTime; + } + + public void setDateToJodaDateTime(DateTime dateToJodaDateTime) { + this.dateToJodaDateTime = dateToJodaDateTime; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java new file mode 100644 index 0000000000..a1da8a805b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java @@ -0,0 +1,38 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper +public abstract class Issue1460JavaTimeMapper { + + public static final Issue1460JavaTimeMapper INSTANCE = Mappers.getMapper( Issue1460JavaTimeMapper.class ); + + public abstract Target map(Source source); + + public abstract String forceUsageOfLocalDate(LocalDate source); + + public static class LocalDate { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java new file mode 100644 index 0000000000..f0ffd86768 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java @@ -0,0 +1,55 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460.java8; + +import java.time.LocalDate; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Christian Bandowski + */ +@WithClasses({ + Issue1460JavaTimeMapper.class, + Source.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1460") +public class Issue1460JavaTimeTest { + + @Test + public void shouldTestMappingLocalDates() { + String dateAsString = "2018-04-26"; + + Source source = new Source(); + source.setStringToJavaLocalDate( dateAsString ); + + Target target = Issue1460JavaTimeMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStringToJavaLocalDate() ).isEqualTo( LocalDate.parse( dateAsString ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java new file mode 100644 index 0000000000..6515c6fa82 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460.java8; + +public class Source { + private String stringToJavaLocalDate; + + public String getStringToJavaLocalDate() { + return stringToJavaLocalDate; + } + + public void setStringToJavaLocalDate(String stringToJavaLocalDate) { + this.stringToJavaLocalDate = stringToJavaLocalDate; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java new file mode 100644 index 0000000000..f7cf79ebb6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1460.java8; + +import java.time.LocalDate; + +public class Target { + private LocalDate stringToJavaLocalDate; + + public LocalDate getStringToJavaLocalDate() { + return stringToJavaLocalDate; + } + + public void setStringToJavaLocalDate(LocalDate stringToJavaLocalDate) { + this.stringToJavaLocalDate = stringToJavaLocalDate; + } + +} From 9e299a2ba1c4dc7993ac31cbe1bc48632ad22566 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sat, 5 May 2018 22:19:27 +0200 Subject: [PATCH 0239/1006] Use constants instead of strings in ValueMapping javadoc --- core-jdk8/src/main/java/org/mapstruct/ValueMapping.java | 6 +++--- core/src/main/java/org/mapstruct/ValueMapping.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java b/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java index 1c762d4456..5808cd5f89 100644 --- a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java @@ -65,9 +65,9 @@ * *
        * 
      - * @ValueMapping( source = "<NULL>", target = "DEFAULT" ),
      - * @ValueMapping( source = "STANDARD", target = "<NULL>" ),
      - * @ValueMapping( source = "<ANY_REMAINING>", target = "SPECIAL" )
      + * @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      + * @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      + * @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
        * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
        * 
        * Mapping result:
      diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java
      index fd24a0b6f5..59bc10f3d5 100644
      --- a/core/src/main/java/org/mapstruct/ValueMapping.java
      +++ b/core/src/main/java/org/mapstruct/ValueMapping.java
      @@ -67,9 +67,9 @@
        * 
        * 
        * @ValueMappings({
      - *    @ValueMapping( source = "<NULL>", target = "DEFAULT" ),
      - *    @ValueMapping( source = "STANDARD", target = "<NULL>" ),
      - *    @ValueMapping( source = "<ANY_REMAINING>", target = "SPECIAL" )
      + *    @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      + *    @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      + *    @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
        * })
        * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
        * 
      
      From 45cc87849b550f33830498769c81f6e489f2d945 Mon Sep 17 00:00:00 2001
      From: sjaakd 
      Date: Sun, 29 Apr 2018 13:41:51 +0200
      Subject: [PATCH 0240/1006] #1458 reporting error detail from literal
       assignment
      
      ---
       .../ap/internal/model/PropertyMapping.java    |  31 +-
       .../ap/internal/model/common/Type.java        |  22 +-
       .../ap/internal/model/common/TypeFactory.java |  47 +-
       .../creation/MappingResolverImpl.java         |   2 +-
       .../mapstruct/ap/internal/util/Message.java   |   1 +
       .../ap/internal/util/NativeTypes.java         | 431 +++++++++---------
       .../DateFormatValidatorFactoryTest.java       |   1 -
       .../common/DefaultConversionContextTest.java  |   1 -
       .../ap/internal/util/NativeTypesTest.java     | 360 +++++++--------
       ...umericMapper.java => ConstantsMapper.java} |  11 +-
       ...umericTarget.java => ConstantsTarget.java} |  47 +-
       .../test/source/constants/ConstantsTest.java  | 116 +++++
       .../constants/ErroneousConstantMapper.java    |  48 ++
       .../constants/NumericConstantsTest.java       |  63 ---
       ...pperImpl.java => ConstantsMapperImpl.java} |  37 +-
       15 files changed, 666 insertions(+), 552 deletions(-)
       rename processor/src/test/java/org/mapstruct/ap/test/source/constants/{NumericMapper.java => ConstantsMapper.java} (79%)
       rename processor/src/test/java/org/mapstruct/ap/test/source/constants/{NumericTarget.java => ConstantsTarget.java} (74%)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java
       delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java
       rename processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/{NumericMapperImpl.java => ConstantsMapperImpl.java} (51%)
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      index 14f1d1153d..690cd09a19 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      @@ -62,6 +62,7 @@
       import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS;
       import static org.mapstruct.ap.internal.util.Collections.first;
       import static org.mapstruct.ap.internal.util.Collections.last;
      +import org.mapstruct.ap.internal.util.NativeTypes;
       
       /**
        * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to
      @@ -761,12 +762,22 @@ public ConstantMappingBuilder selectionParameters(SelectionParameters selectionP
               public PropertyMapping build() {
                   // source
                   String sourceErrorMessagePart = "constant '" + constantExpression + "'";
      +            String errorMessageDetails = null;
       
      -            Type sourceType = ctx.getTypeFactory().getTypeForConstant( targetType, constantExpression );
      -            if ( String.class.getCanonicalName().equals( sourceType.getFullyQualifiedName() ) ) {
      -                // convert to string
      +            Class baseForLiteral = null;
      +            try {
      +                baseForLiteral = NativeTypes.getLiteral( targetType.getFullyQualifiedName(), constantExpression );
      +            }
      +            catch ( IllegalArgumentException ex ) {
      +                errorMessageDetails = ex.getMessage();
      +            }
      +
      +            //  the constant is not a primitive literal, assume it to be a String
      +            if ( baseForLiteral == null ) {
                       constantExpression = "\"" + constantExpression + "\"";
      +                baseForLiteral = String.class;
                   }
      +            Type sourceType = ctx.getTypeFactory().getTypeForLiteral( baseForLiteral );
       
                   Assignment assignment = null;
                   if ( !targetType.isEnumType() ) {
      @@ -822,7 +833,7 @@ public PropertyMapping build() {
                                                                              );
                       }
                   }
      -            else {
      +            else if ( errorMessageDetails == null ) {
                       ctx.getMessager().printMessage(
                           method.getExecutable(),
                           mirror,
      @@ -833,6 +844,18 @@ public PropertyMapping build() {
                           targetPropertyName
                       );
                   }
      +            else {
      +                ctx.getMessager().printMessage(
      +                    method.getExecutable(),
      +                    mirror,
      +                    Message.CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS,
      +                    sourceType,
      +                    constantExpression,
      +                    targetType,
      +                    targetPropertyName,
      +                    errorMessageDetails
      +                );
      +            }
       
                   return new PropertyMapping(
                       targetPropertyName,
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      index e33b2cf853..c95c842e89 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      @@ -52,6 +52,7 @@
       import org.mapstruct.ap.spi.BuilderInfo;
       
       import static org.mapstruct.ap.internal.util.Collections.first;
      +import org.mapstruct.ap.internal.util.NativeTypes;
       
       /**
        * Represents (a reference to) the type of a bean property, parameter etc. Types are managed per generated source file.
      @@ -90,8 +91,7 @@ public class Type extends ModelElement implements Comparable {
           private final boolean isImported;
           private final boolean isVoid;
           private final boolean isStream;
      -    private final boolean isBoxed;
      -    private final boolean isOriginatedFromConstant;
      +    private final boolean isLiteral;
       
           private final List enumConstants;
       
      @@ -116,7 +116,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory,
                       String packageName, String name, String qualifiedName,
                       boolean isInterface, boolean isEnumType, boolean isIterableType,
                       boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported,
      -                boolean isBoxed, boolean isOriginatedFromConstant ) {
      +                boolean isLiteral ) {
       
               this.typeUtils = typeUtils;
               this.elementUtils = elementUtils;
      @@ -141,8 +141,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory,
               this.isStream = isStreamType;
               this.isImported = isImported;
               this.isVoid = typeMirror.getKind() == TypeKind.VOID;
      -        this.isBoxed = isBoxed;
      -        this.isOriginatedFromConstant = isOriginatedFromConstant;
      +        this.isLiteral = isLiteral;
       
               if ( isEnumType ) {
                   enumConstants = new ArrayList();
      @@ -403,8 +402,7 @@ public Type erasure() {
                   isMapType,
                   isStream,
                   isImported,
      -            isBoxed,
      -            isOriginatedFromConstant
      +            isLiteral
               );
           }
       
      @@ -937,20 +935,16 @@ public List determineTypeArguments(Class superclass) {
               return null;
           }
       
      -    public boolean isBoxed() {
      -        return isBoxed;
      -    }
      -
           /**
            * All primitive types and their corresponding boxed types are considered native.
            * @return true when native.
            */
           public boolean isNative() {
      -        return isBoxed() || isPrimitive();
      +        return NativeTypes.isNative( qualifiedName );
           }
       
      -    public boolean hasOriginatedFromConstant() {
      -        return isOriginatedFromConstant;
      +    public boolean isLiteral() {
      +        return isLiteral;
           }
       
       }
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
      index b496f36ec6..476898fd74 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java
      @@ -61,7 +61,6 @@
       import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
       import org.mapstruct.ap.spi.BuilderInfo;
       import org.mapstruct.ap.spi.TypeHierarchyErroneousException;
      -import org.mapstruct.ap.internal.util.NativeTypes;
       
       import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor;
       import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity;
      @@ -119,6 +118,11 @@ public TypeFactory(Elements elementUtils, Types typeUtils, RoundContext roundCon
               );
           }
       
      +    public Type getTypeForLiteral(Class type) {
      +        return type.isPrimitive() ? getType( getPrimitiveType( type ), true )
      +            : getType( type.getCanonicalName(), true );
      +    }
      +
           public Type getType(Class type) {
               return type.isPrimitive() ? getType( getPrimitiveType( type ) ) : getType( type.getCanonicalName() );
           }
      @@ -127,7 +131,7 @@ public Type getType(String canonicalName) {
               return getType( canonicalName, false );
           }
       
      -    private Type getType(String canonicalName, boolean isOriginatedFromConstant) {
      +    private Type getType(String canonicalName, boolean isLiteral) {
               TypeElement typeElement = elementUtils.getTypeElement( canonicalName );
       
               if ( typeElement == null ) {
      @@ -136,30 +140,9 @@ private Type getType(String canonicalName, boolean isOriginatedFromConstant) {
                   );
               }
       
      -        return getType( typeElement, isOriginatedFromConstant );
      +        return getType( typeElement, isLiteral );
           }
       
      -    public Type getTypeForConstant(Type targetType, String literal) {
      -        Type result = null;
      -        TypeMirror baseForLiteral = null;
      -        if ( targetType.isNative() ) {
      -            TypeKind kind;
      -            if ( targetType.isBoxed() ) {
      -                kind = NativeTypes.getWrapperKind( targetType.getFullyQualifiedName() );
      -            }
      -            else {
      -                kind = targetType.getTypeMirror().getKind();
      -            }
      -            baseForLiteral = NativeTypes.getLiteral( kind, literal, typeUtils );
      -        }
      -        if ( baseForLiteral != null ) {
      -            result = getType( baseForLiteral, true );
      -        }
      -        else {
      -            result = getType( String.class.getCanonicalName(), true );
      -        }
      -        return result;
      -    }
       
           /**
            * Determines if the type with the given full qualified name is part of the classpath
      @@ -181,18 +164,18 @@ public Type getWrappedType(Type type ) {
           }
       
           public Type getType(TypeElement typeElement) {
      -        return getType( typeElement.asType() );
      +        return getType( typeElement.asType(), false );
           }
       
      -    private Type getType(TypeElement typeElement, boolean originatedFromConstant) {
      -        return getType( typeElement.asType(), originatedFromConstant );
      +    private Type getType(TypeElement typeElement, boolean isLiteral) {
      +        return getType( typeElement.asType(), isLiteral );
           }
       
           public Type getType(TypeMirror mirror) {
               return getType( mirror, false );
           }
       
      -    private Type getType(TypeMirror mirror, boolean originatedFromConstant) {
      +    private Type getType(TypeMirror mirror, boolean isLiteral) {
               if ( !canBeProcessed( mirror ) ) {
                   throw new TypeHierarchyErroneousException( mirror );
               }
      @@ -213,7 +196,6 @@ private Type getType(TypeMirror mirror, boolean originatedFromConstant) {
               TypeElement typeElement;
               Type componentType;
               boolean isImported;
      -        boolean isBoxed = false;
       
               if ( mirror.getKind() == TypeKind.DECLARED ) {
                   DeclaredType declaredType = (DeclaredType) mirror;
      @@ -235,7 +217,6 @@ private Type getType(TypeMirror mirror, boolean originatedFromConstant) {
       
                   componentType = null;
                   isImported = isImported( name, qualifiedName );
      -            isBoxed = NativeTypes.isWrapped( qualifiedName );
               }
               else if ( mirror.getKind() == TypeKind.ARRAY ) {
                   TypeMirror componentTypeMirror = getComponentType( mirror );
      @@ -298,8 +279,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) {
                   isMapType,
                   isStreamType,
                   isImported,
      -            isBoxed,
      -            originatedFromConstant
      +            isLiteral
               );
           }
       
      @@ -513,8 +493,7 @@ private ImplementationType getImplementationType(TypeMirror mirror) {
                       implementationType.isMapType(),
                       implementationType.isStreamType(),
                       isImported( implementationType.getName(), implementationType.getFullyQualifiedName() ),
      -                implementationType.isBoxed(),
      -                implementationType.hasOriginatedFromConstant()
      +                implementationType.isLiteral()
                   );
                   return implementation.createNew( replacement );
               }
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
      index 07624b21ad..e50dce92a6 100755
      --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java
      @@ -260,7 +260,7 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) {
                   // In case of 1. and the target type is still a wrapped or primitive type we must assume that the check
                   // in NativeType is not successful. We don't want to go through type conversion, double mappings etc.
                   // with something that we already know to be wrong.
      -            if ( sourceType.hasOriginatedFromConstant()
      +            if ( sourceType.isLiteral()
                       && "java.lang.String".equals( sourceType.getFullyQualifiedName( ) )
                       && targetType.isNative() ) {
                       // TODO: convey some error message
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      index bc5f8dfc0d..0bb6b788fd 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      @@ -68,6 +68,7 @@ public enum Message {
           PROPERTYMAPPING_WHITESPACE_TRIMMED( "The property named \"%s\" has whitespaces, using trimmed property \"%s\" instead.", Diagnostic.Kind.WARNING ),
       
           CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ),
      +    CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS( "Can't map \"%s %s\" to \"%s %s\". Reason: %s." ),
           CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ),
           CONSTANTMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s for property \"%s\"." ),
       
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      index 48336b2a1b..85c56060dd 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      @@ -21,19 +21,14 @@
       import java.math.BigDecimal;
       import java.math.BigInteger;
       import java.util.Collections;
      -import java.util.EnumMap;
       import java.util.HashMap;
       import java.util.HashSet;
       import java.util.Map;
       import java.util.Set;
       import java.util.regex.Pattern;
      -import javax.lang.model.type.TypeKind;
      -import javax.lang.model.type.TypeMirror;
      -import javax.lang.model.util.Types;
       
       /**
      - * Provides functionality around the Java primitive data types and their wrapper
      - * types. They are considered native.
      + * Provides functionality around the Java primitive data types and their wrapper types. They are considered native.
        *
        * @author Gunnar Morling
        */
      @@ -42,7 +37,7 @@ public class NativeTypes {
           private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES;
           private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPES;
           private static final Set> NUMBER_TYPES = new HashSet>();
      -    private static final Map WRAPPER_NAME_TO_PRIMITIVE_TYPES;
      +    private static final Map ANALYZERS;
       
           private static final Pattern PTRN_HEX = Pattern.compile( "^0[x|X].*" );
           private static final Pattern PTRN_OCT = Pattern.compile( "^0_*[0-7].*" );
      @@ -61,13 +56,11 @@ public class NativeTypes {
           private static final Pattern PTRN_FAULTY_DEC_UNDERSCORE_FLOAT = Pattern.compile( "_e|_E|e_|E_" );
           private static final Pattern PTRN_FAULTY_HEX_UNDERSCORE_FLOAT = Pattern.compile( "_p|_P|p_|P_" );
       
      -    private static final Map ANALYZERS = initAnalyzers();
      -
           private interface LiteralAnalyzer {
       
      -        boolean validate( String s);
      +        void validate(String s);
       
      -        TypeMirror getLiteral( Types types );
      +        Class getLiteral();
       
           }
       
      @@ -115,16 +108,11 @@ else if ( PTRN_OCT.matcher( valWithoutSign ).matches() ) {
                   }
               }
       
      -        abstract boolean parse(String val, int radix);
      +        abstract void parse(String val, int radix);
       
      -        boolean validate() {
      -            try {
      -                strip();
      -                return parse( val, radix );
      -            }
      -            catch ( NumberFormatException ex ) {
      -                return false;
      -            }
      +        void validate() {
      +            strip();
      +            parse( val, radix );
               }
       
               void strip() {
      @@ -143,7 +131,7 @@ void strip() {
                */
               void removeAndValidateIntegerLiteralUnderscore() {
                   if ( PTRN_FAULTY_UNDERSCORE_INT.matcher( val ).find() ) {
      -                throw new NumberFormatException("Improperly placed underscores");
      +                throw new NumberFormatException( "improperly placed underscores" );
                   }
                   else {
                       val = val.replace( "_", "" );
      @@ -158,7 +146,7 @@ void removeAndValidateFloatingPointLiteralUnderscore() {
                   if ( PTRN_FAULTY_UNDERSCORE_FLOAT.matcher( val ).find()
                       || !isHex && PTRN_FAULTY_DEC_UNDERSCORE_FLOAT.matcher( val ).find()
                       || isHex && PTRN_FAULTY_HEX_UNDERSCORE_FLOAT.matcher( val ).find() ) {
      -                throw new NumberFormatException("Improperly placed underscores");
      +                throw new NumberFormatException( "improperly placed underscores" );
                   }
                   else {
                       val = val.replace( "_", "" );
      @@ -171,11 +159,11 @@ void removeAndValidateFloatingPointLiteralUnderscore() {
               void removeAndValidateIntegerLiteralSuffix() {
                   boolean endsWithLSuffix = PTRN_LONG.matcher( val ).find();
                   // error handling
      -            if (endsWithLSuffix && !isLong) {
      -                throw new NumberFormatException("L/l not allowed for non-long types");
      +            if ( endsWithLSuffix && !isLong ) {
      +                throw new NumberFormatException( "L/l not allowed for non-long types" );
                   }
      -            if ( !endsWithLSuffix && isLong)  {
      -                throw new NumberFormatException("L/l mandatory long");
      +            if ( !endsWithLSuffix && isLong ) {
      +                throw new NumberFormatException( "L/l mandatory for long types" );
                   }
                   // remove suffix
                   if ( endsWithLSuffix ) {
      @@ -195,7 +183,7 @@ void removeAndValidateFloatingPointLiteralSuffix() {
                   boolean endsWithDSuffix = PTRN_DOUBLE.matcher( val ).find();
                   // error handling
                   if ( isFloat && endsWithDSuffix ) {
      -                throw new NumberFormatException("Assiging double to a float");
      +                throw new NumberFormatException( "Assiging double to a float" );
                   }
                   // remove suffix
                   if ( endsWithLSuffix || endsWithFSuffix || endsWithDSuffix ) {
      @@ -233,6 +221,181 @@ private boolean floatHasBecomeZero() {
               }
           }
       
      +   private static class BooleanAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            if ( !( "true".equals( s ) || "false".equals( s ) ) ) {
      +                throw new IllegalArgumentException("only 'true' or 'false' are supported");
      +            }
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return boolean.class;
      +        }
      +    }
      +
      +    private static class CharAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            if ( !(s.length() == 3 && s.startsWith( "'" ) && s.endsWith( "'" )) ) {
      +                throw new NumberFormatException( "invalid character literal" );
      +            }
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return char.class;
      +        }
      +    }
      +
      +    private static class ByteAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      +
      +                @Override
      +                void parse(String val, int radix) {
      +                    Byte.parseByte( val, radix );
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return int.class;
      +        }
      +    }
      +
      +    private static class DoubleAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            NumberRepresentation br = new NumberRepresentation( s, false, false, false ) {
      +
      +                @Override
      +                void parse(String val, int radix) {
      +                    Double d = Double.parseDouble( radix == 16 ? "0x" + val : val );
      +                    if ( doubleHasBecomeZero( d  ) ) {
      +                        throw new NumberFormatException( "floating point number too small" );
      +                    }
      +                    if ( d.isInfinite() ) {
      +                        throw new NumberFormatException( "infinitive is not allowed" );
      +                    }
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return float.class;
      +        }
      +
      +    }
      +
      +    private static class FloatAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +
      +            NumberRepresentation br = new NumberRepresentation( s, false, false, true ) {
      +                @Override
      +                void parse(String val, int radix) {
      +                    Float f = Float.parseFloat( radix == 16 ? "0x" + val : val );
      +                    if ( doubleHasBecomeZero( f  ) ) {
      +                        throw new NumberFormatException( "floating point number too small" );
      +                    }
      +                    if ( f.isInfinite() ) {
      +                        throw new NumberFormatException( "infinitive is not allowed" );
      +                    }
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return float.class;
      +        }
      +    }
      +
      +    private static class IntAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      +
      +                @Override
      +                void parse(String val, int radix) {
      +                    if ( radix == 10 ) {
      +                        // when decimal: treat like signed
      +                        Integer.parseInt( val, radix );
      +                    }
      +                    else if ( new BigInteger( val, radix ).bitLength() > 32 ) {
      +                        throw new NumberFormatException( "integer number too large" );
      +                    }
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return int.class;
      +        }
      +    }
      +
      +    private static class LongAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            NumberRepresentation br = new NumberRepresentation( s, true, true, false ) {
      +
      +                @Override
      +                void parse(String val, int radix) {
      +                    if ( radix == 10 ) {
      +                        // when decimal: treat like signed
      +                        Long.parseLong( val, radix );
      +                    }
      +                    else if ( new BigInteger( val, radix ).bitLength() > 64 ) {
      +                        throw new NumberFormatException( "integer number too large" );
      +                    }
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return int.class;
      +        }
      +    }
      +
      +    private static class ShortAnalyzer implements LiteralAnalyzer {
      +
      +        @Override
      +        public void validate(String s) {
      +            NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      +
      +                @Override
      +                void parse(String val, int radix) {
      +                    Short.parseShort( val, radix );
      +                }
      +            };
      +            br.validate();
      +        }
      +
      +        @Override
      +        public Class getLiteral() {
      +            return int.class;
      +        }
      +    }
      +
           private NativeTypes() {
           }
       
      @@ -276,17 +439,25 @@ private NativeTypes() {
               NUMBER_TYPES.add( BigInteger.class );
               NUMBER_TYPES.add( BigDecimal.class );
       
      -        Map tmp2 = new HashMap();
      -        tmp2.put( Boolean.class.getName(), TypeKind.BOOLEAN );
      -        tmp2.put( Byte.class.getName(), TypeKind.BYTE );
      -        tmp2.put( Character.class.getName(), TypeKind.CHAR );
      -        tmp2.put( Double.class.getName(), TypeKind.DOUBLE );
      -        tmp2.put( Float.class.getName(), TypeKind.FLOAT );
      -        tmp2.put( Integer.class.getName(), TypeKind.INT );
      -        tmp2.put( Long.class.getName(), TypeKind.LONG );
      -        tmp2.put( Short.class.getName(), TypeKind.SHORT );
      -
      -        WRAPPER_NAME_TO_PRIMITIVE_TYPES = Collections.unmodifiableMap( tmp2 );
      +        Map tmp2 = new HashMap();
      +        tmp2.put( boolean.class.getCanonicalName(), new BooleanAnalyzer() );
      +        tmp2.put( Boolean.class.getCanonicalName(), new BooleanAnalyzer() );
      +        tmp2.put( char.class.getCanonicalName(), new CharAnalyzer() );
      +        tmp2.put( Character.class.getCanonicalName(), new CharAnalyzer() );
      +        tmp2.put( byte.class.getCanonicalName(), new ByteAnalyzer() );
      +        tmp2.put( Byte.class.getCanonicalName(), new ByteAnalyzer() );
      +        tmp2.put( double.class.getCanonicalName(), new DoubleAnalyzer() );
      +        tmp2.put( Double.class.getCanonicalName(), new DoubleAnalyzer() );
      +        tmp2.put( float.class.getCanonicalName(), new FloatAnalyzer() );
      +        tmp2.put( Float.class.getCanonicalName(), new FloatAnalyzer() );
      +        tmp2.put( int.class.getCanonicalName(), new IntAnalyzer() );
      +        tmp2.put( Integer.class.getCanonicalName(), new IntAnalyzer() );
      +        tmp2.put( long.class.getCanonicalName(), new LongAnalyzer() );
      +        tmp2.put( Long.class.getCanonicalName(), new LongAnalyzer() );
      +        tmp2.put( short.class.getCanonicalName(), new ShortAnalyzer() );
      +        tmp2.put( Short.class.getCanonicalName(), new ShortAnalyzer() );
      +
      +        ANALYZERS = Collections.unmodifiableMap( tmp2 );
       
           }
       
      @@ -306,12 +477,8 @@ public static Class getPrimitiveType(Class clazz) {
               return WRAPPER_TO_PRIMITIVE_TYPES.get( clazz );
           }
       
      -    public static boolean isWrapped(String fullyQualifiedName) {
      -        return WRAPPER_NAME_TO_PRIMITIVE_TYPES.containsKey( fullyQualifiedName );
      -    }
      -
      -    public static TypeKind getWrapperKind(String fullyQualifiedName) {
      -        return WRAPPER_NAME_TO_PRIMITIVE_TYPES.get( fullyQualifiedName );
      +    public static boolean isNative(String fullyQualifiedName) {
      +        return ANALYZERS.containsKey( fullyQualifiedName );
           }
       
           public static boolean isNumber(Class clazz) {
      @@ -325,174 +492,18 @@ public static boolean isNumber(Class clazz) {
       
           /**
            *
      -     * @param kind typeKind
      -     * @param literal literal
      -     * @param utils type util for constructing literal type
      -     * @return literal type when the literal is a proper literal for the provided kind.
      +     * @param className FQN of the literal native class
      +     * @param literal literal to verify
      +     * @return literal class when the literal is a proper literal for the provided kind.
      +     * @throws IllegalArgumentException when the literal does not match to the provided native type className
            */
      -    public static TypeMirror getLiteral(TypeKind kind, String literal, Types utils ) {
      -        LiteralAnalyzer analyzer = ANALYZERS.get( kind );
      -        TypeMirror result = null;
      -        if ( analyzer != null && analyzer.validate( literal ) ) {
      -            result = analyzer.getLiteral( utils );
      +    public static Class getLiteral(String className, String literal) {
      +        LiteralAnalyzer analyzer = ANALYZERS.get( className );
      +        Class result = null;
      +        if ( analyzer != null ) {
      +            analyzer.validate( literal );
      +            result = analyzer.getLiteral();
               }
               return result;
           }
      -
      -    @SuppressWarnings( "checkstyle:MethodLength" )
      -    private static Map initAnalyzers() {
      -        Map result = new EnumMap(TypeKind.class);
      -        result.put( TypeKind.BOOLEAN, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                return "true".equals( s ) || "false".equals( s );
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.BOOLEAN );
      -            }
      -        } );
      -        result.put( TypeKind.CHAR, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                return s.length() == 3 && s.startsWith( "'" ) && s.endsWith( "'" );
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.CHAR );
      -            }
      -        } );
      -        result.put( TypeKind.BYTE, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      -
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        Byte.parseByte( val, radix );
      -                        return true;
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.INT );
      -            }
      -        } );
      -        result.put( TypeKind.DOUBLE, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                NumberRepresentation br = new NumberRepresentation( s, false, false, false ) {
      -
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        Double d = Double.parseDouble( radix == 16 ? "0x" + val : val );
      -                        return !d.isInfinite() && !doubleHasBecomeZero( d );
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.FLOAT );
      -            }
      -        } );
      -        result.put( TypeKind.FLOAT, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -
      -                NumberRepresentation br = new NumberRepresentation( s, false, false, true ) {
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        Float f = Float.parseFloat( radix == 16 ? "0x" + val : val );
      -                        return !f.isInfinite() && !floatHasBecomeZero( f );
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.FLOAT );
      -            }
      -        } );
      -        result.put( TypeKind.INT, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      -
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        if ( radix == 10 ) {
      -                            // when decimal: treat like signed
      -                            Integer.parseInt( val, radix );
      -                            return true;
      -                        }
      -                        else {
      -                            // when binary, octal or hex: treat like unsigned
      -                            return new BigInteger( val, radix ).bitLength() <= 32;
      -                        }
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.INT );
      -            }
      -        } );
      -        result.put( TypeKind.LONG, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate(String s) {
      -                NumberRepresentation br = new NumberRepresentation( s, true, true, false ) {
      -
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        if ( radix == 10 ) {
      -                            // when decimal: treat like signed
      -                            Long.parseLong( val, radix );
      -                            return true;
      -                        }
      -                        else {
      -                            // when binary, octal or hex: treat like unsigned
      -                            return new BigInteger( val, radix ).bitLength() <= 64;
      -                        }
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.INT );
      -            }
      -        } );
      -        result.put( TypeKind.SHORT, new LiteralAnalyzer() {
      -            @Override
      -            public boolean validate( String s) {
      -                NumberRepresentation br = new NumberRepresentation( s, true, false, false ) {
      -
      -                    @Override
      -                    boolean parse(String val, int radix) {
      -                        Short.parseShort( val, radix );
      -                        return true;
      -                    }
      -                };
      -                return br.validate();
      -            }
      -
      -            @Override
      -            public TypeMirror getLiteral(Types types) {
      -                return types.getPrimitiveType( TypeKind.INT );
      -            }
      -        } );
      -        return result;
      -    }
      -
       }
      diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java
      index 7b9330ab4f..47ded40dab 100755
      --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java
      +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java
      @@ -185,7 +185,6 @@ private Type typeWithFQN(String fullQualifiedName) {
                               false,
                               false,
                               false,
      -                        false,
                               false );
           }
       
      diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java
      index da16066e35..742e4391d5 100755
      --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java
      +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java
      @@ -136,7 +136,6 @@ private Type typeWithFQN(String fullQualifiedName) {
                               false,
                               false,
                               false,
      -                        false,
                               false );
           }
       
      diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java
      index 98c31be696..2555209259 100644
      --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java
      +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java
      @@ -19,27 +19,12 @@
       package org.mapstruct.ap.internal.util;
       
       import static org.assertj.core.api.Assertions.assertThat;
      -
       import static org.junit.Assert.assertFalse;
       import static org.junit.Assert.assertTrue;
       
      -import static org.mapstruct.ap.internal.util.NativeTypes.getLiteral;
      -
      -import java.lang.annotation.Annotation;
      -import java.lang.reflect.InvocationHandler;
      -import java.lang.reflect.Method;
      -import java.lang.reflect.Proxy;
      -import org.junit.Test;
      -
       import java.math.BigDecimal;
       import java.math.BigInteger;
      -import java.util.List;
      -import javax.lang.model.element.AnnotationMirror;
      -
      -import javax.lang.model.type.PrimitiveType;
      -import javax.lang.model.type.TypeKind;
      -import javax.lang.model.util.Types;
      -import javax.lang.model.type.TypeVisitor;
      +import org.junit.Test;
       
       /**
        * @author Ciaran Liedeman
      @@ -67,14 +52,15 @@ public void testIsNumber() throws Exception {
            */
           @Test
           public void testUnderscorePlacement1() {
      -        assertThat( getLiteral( TypeKind.LONG, "1234_5678_9012_3456L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "999_99_9999L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.14_15F", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0xFF_EC_DE_5EL", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0xCAFE_BABEL", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0x7fff_ffff_ffff_ffffL", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BYTE, "0b0010_0101", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0b11010010_01101001_10010100_10010010L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "1234_5678_9012_3456L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "999_99_9999L" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.14_15F" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0xFF_EC_DE_5EL" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0xCAFE_BABEL" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0x7fff_ffff_ffff_ffffL" ) ).isNotNull();
      +        assertThat( getLiteral( byte.class.getCanonicalName(), "0b0010_0101" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0b11010010_01101001_10010100_10010010L" ) )
      +            .isNotNull();
           }
       
           /**
      @@ -95,40 +81,40 @@ public void testUnderscorePlacement2() {
       
               // Invalid: cannot put underscores
               // adjacent to a decimal point
      -        assertThat( getLiteral( TypeKind.FLOAT, "3_.1415F", types() ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3_.1415F" ) ).isNull();
       
               // Invalid: cannot put underscores
               // adjacent to a decimal point
      -        assertThat( getLiteral( TypeKind.FLOAT, "3._1415F", types() ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3._1415F" ) ).isNull();
       
               // Invalid: cannot put underscores
               // prior to an L suffix
      -        assertThat( getLiteral( TypeKind.LONG, "999_99_9999_L", types() ) ).isNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "999_99_9999_L" ) ).isNull();
       
               // OK (decimal literal)
      -        assertThat( getLiteral( TypeKind.INT, "5_2", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "5_2" ) ).isNotNull();
       
               // Invalid: cannot put underscores
               // At the end of a literal
      -        assertThat( getLiteral( TypeKind.INT, "52_", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "52_" ) ).isNull();
       
               // OK (decimal literal)
      -        assertThat( getLiteral( TypeKind.INT, "5_______2", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "5_______2" ) ).isNotNull();
       
               // Invalid: cannot put underscores
               // in the 0x radix prefix
      -        assertThat( getLiteral( TypeKind.INT, "0_x52", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0_x52" ) ).isNull();
       
               // Invalid: cannot put underscores
               // at the beginning of a number
      -        assertThat( getLiteral( TypeKind.INT, "0x_52", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x_52" ) ).isNull();
       
               // OK (hexadecimal literal)
      -        assertThat( getLiteral( TypeKind.INT, "0x5_2", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x5_2" ) ).isNotNull();
       
               // Invalid: cannot put underscores
               // at the end of a number
      -        assertThat( getLiteral( TypeKind.INT, "0x52_", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x52_" ) ).isNull();
           }
       
           /**
      @@ -140,58 +126,61 @@ public void testUnderscorePlacement2() {
           public void testIntegerLiteralFromJLS() {
       
               // largest positive int: dec / octal / int / binary
      -        assertThat( getLiteral( TypeKind.INT, "2147483647", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "2147483647", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0x7fff_ffff", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0177_7777_7777", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0b0111_1111_1111_1111_1111_1111_1111_1111", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "2147483647" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "2147483647" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x7fff_ffff" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0177_7777_7777" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0b0111_1111_1111_1111_1111_1111_1111_1111" ) )
      +            .isNotNull();
       
               // most negative int: dec / octal / int / binary
               // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can disssapear (java8)
               // and the function will be true to what the compiler shows.
      -        assertThat( getLiteral( TypeKind.INT, "-2147483648", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0x8000_0000", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0200_0000_0000", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0b1000_0000_0000_0000_0000_0000_0000_0000", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "-2147483648" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x8000_0000" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0200_0000_0000" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0b1000_0000_0000_0000_0000_0000_0000_0000" ) )
      +            .isNotNull();
       
               // -1 representation int: dec / octal / int / binary
      -        assertThat( getLiteral( TypeKind.INT, "-1", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0xffff_ffff", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0377_7777_7777", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0b1111_1111_1111_1111_1111_1111_1111_1111", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "-1" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0xffff_ffff" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0377_7777_7777" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0b1111_1111_1111_1111_1111_1111_1111_1111" ) )
      +            .isNotNull();
       
               // largest positive long: dec / octal / int / binary
      -        assertThat( getLiteral( TypeKind.LONG, "9223372036854775807L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0x7fff_ffff_ffff_ffffL", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "07_7777_7777_7777_7777_7777L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_"
      -            + "1111_1111_1111_1111_1111_1111L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "9223372036854775807L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0x7fff_ffff_ffff_ffffL" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "07_7777_7777_7777_7777_7777L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_"
      +            + "1111_1111_1111_1111_1111_1111L" ) ).isNotNull();
               // most negative long: dec / octal / int / binary
      -        assertThat( getLiteral( TypeKind.LONG, "-9223372036854775808L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0x8000_0000_0000_0000L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "010_0000_0000_0000_0000_0000L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_"
      -            + "0000_0000_0000_0000_0000L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "-9223372036854775808L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0x8000_0000_0000_0000L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "010_0000_0000_0000_0000_0000L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_"
      +            + "0000_0000_0000_0000_0000_0000L" ) ).isNotNull();
               // -1 representation long: dec / octal / int / binary
      -        assertThat( getLiteral( TypeKind.LONG, "-1L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0xffff_ffff_ffff_ffffL", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "017_7777_7777_7777_7777_7777L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_"
      -            + "1111_1111_1111_1111_1111L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "-1L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0xffff_ffff_ffff_ffffL" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "017_7777_7777_7777_7777_7777L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_"
      +            + "1111_1111_1111_1111_1111_1111L" ) ).isNotNull();
       
               // some examples of ints
      -        assertThat( getLiteral( TypeKind.INT, "0", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "2", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0372", types() ) ).isNotNull();
      -        //assertThat( getLiteral( TypeKind.INT, "0xDada_Cafe", types() ) ).isNotNull(); java8
      -        assertThat( getLiteral( TypeKind.INT, "1996", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "0x00_FF__00_FF", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "2" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0372" ) ).isNotNull();
      +        //assertThat( getLiteral( int.class.getCanonicalName(), "0xDada_Cafe" ) ).isNotNull(); java8
      +        assertThat( getLiteral( int.class.getCanonicalName(), "1996" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x00_FF__00_FF" ) ).isNotNull();
       
               // some examples of longs
      -        assertThat( getLiteral( TypeKind.LONG, "0777l", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0x100000000L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "2_147_483_648L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0xC0B0L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0777l" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0x100000000L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "2_147_483_648L" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0xC0B0L" ) ).isNotNull();
           }
       
           /**
      @@ -203,53 +192,53 @@ public void testIntegerLiteralFromJLS() {
           public void testFloatingPoingLiteralFromJLS() {
       
               // The largest positive finite literal of type float is 3.4028235e38f.
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e38f", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.4028235e38f" ) ).isNotNull();
               // The smallest positive finite non-zero literal of type float is 1.40e-45f.
      -        assertThat( getLiteral( TypeKind.FLOAT, "1.40e-45f", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "1.40e-45f" ) ).isNotNull();
               // The largest positive finite literal of type double is 1.7976931348623157e308.
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623157e308", types() ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1.7976931348623157e308" ) ).isNotNull();
               // The smallest positive finite non-zero literal of type double is 4.9e-324
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-324", types() ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9e-324" ) ).isNotNull();
       
               // some floats
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.1e1F", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "2.f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, ".3f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "0f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.14f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "6.022137e+23f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "-3.14f", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.1e1F" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "2.f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), ".3f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "0f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.14f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "6.022137e+23f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "-3.14f" ) ).isNotNull();
       
               // some doubles
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1e1", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1e+1", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "2.", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, ".3", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0.0", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "3.14", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "-3.14", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1e-9D", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1e137", types() ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1e1" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1e+1" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "2." ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), ".3" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0.0" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "3.14" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "-3.14" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1e-9D" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1e137" ) ).isNotNull();
       
               // too large (infinitve)
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e38f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623157e308", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.4028235e38f" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1.7976931348623157e308" ) ).isNotNull();
       
               // too large (infinitve)
      -        assertThat( getLiteral( TypeKind.FLOAT, "3.4028235e39f", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "1.7976931348623159e308", types() ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "3.4028235e39f" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "1.7976931348623159e308" ) ).isNull();
       
               // small
      -        assertThat( getLiteral( TypeKind.FLOAT, "1.40e-45f", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "0x1.0p-149", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-324", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001P-1062d", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "1.40e-45f" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "0x1.0p-149" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9e-324" ) ).isNotNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001P-1062d" ) ).isNotNull();
       
               // too small
      -        assertThat( getLiteral( TypeKind.FLOAT, "1.40e-46f", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "0x1.0p-150", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9e-325", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001p-1063d", types() ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "1.40e-46f" ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "0x1.0p-150" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9e-325" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001p-1063d" ) ).isNull();
           }
       
           /**
      @@ -259,9 +248,9 @@ public void testFloatingPoingLiteralFromJLS() {
            */
           @Test
           public void testBooleanLiteralFromJLS() {
      -        assertThat( getLiteral( TypeKind.BOOLEAN, "true", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BOOLEAN, "false", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BOOLEAN, "FALSE", types() ) ).isNull();
      +        assertThat( getLiteral( boolean.class.getCanonicalName(), "true" ) ).isNotNull();
      +        assertThat( getLiteral( boolean.class.getCanonicalName(), "false" ) ).isNotNull();
      +        assertThat( getLiteral( boolean.class.getCanonicalName(), "FALSE" ) ).isNull();
           }
       
           /**
      @@ -272,146 +261,109 @@ public void testBooleanLiteralFromJLS() {
           @Test
           public void testCharLiteralFromJLS() {
       
      -        assertThat( getLiteral( TypeKind.CHAR, "'a'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'%'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\t'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\\'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\''", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\u03a9'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\uFFFF'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'\177'", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'Ω'", types() ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'a'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'%'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\t'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\\'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\''" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\u03a9'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\uFFFF'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'\177'" ) ).isNotNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'Ω'" ) ).isNotNull();
       
           }
       
           @Test
           public void testShortAndByte() {
      -        assertThat( getLiteral( TypeKind.SHORT, "0xFE", types() ) ).isNotNull();
      +        assertThat( getLiteral( short.class.getCanonicalName(), "0xFE" ) ).isNotNull();
       
               // some examples of ints
      -        assertThat( getLiteral( TypeKind.BYTE, "0", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BYTE, "2", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BYTE, "127", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.BYTE, "-128", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.SHORT, "1996", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.SHORT, "-1996", types() ) ).isNotNull();
      +        assertThat( getLiteral( byte.class.getCanonicalName(), "0" ) ).isNotNull();
      +        assertThat( getLiteral( byte.class.getCanonicalName(), "2" ) ).isNotNull();
      +        assertThat( getLiteral( byte.class.getCanonicalName(), "127" ) ).isNotNull();
      +        assertThat( getLiteral( byte.class.getCanonicalName(), "-128" ) ).isNotNull();
      +        assertThat( getLiteral( short.class.getCanonicalName(), "1996" ) ).isNotNull();
      +        assertThat( getLiteral( short.class.getCanonicalName(), "-1996" ) ).isNotNull();
           }
       
           @Test
           public void testMiscellaneousErroneousPatterns() {
      -        assertThat( getLiteral( TypeKind.INT, "1F", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "1D", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.INT, "_1", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.INT, "1_", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.INT, "0x_1", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.INT, "0_x1", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9e_-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9_e-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4._9e-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4_.9e-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "_4.9e-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9E-3_", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9E_-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9E-_3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9E+-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9E+_3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "4.9_E-3", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001_P-10d", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001P_-10d", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001_p-10d", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.DOUBLE, "0x0.001p_-10d", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "1F" ) ).isNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "1D" ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "_1" ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "1_" ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0x_1" ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0_x1" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9e_-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9_e-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4._9e-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4_.9e-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "_4.9e-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9E-3_" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9E_-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9E-_3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9E+-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9E+_3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "4.9_E-3" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001_P-10d" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001P_-10d" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001_p-10d" ) ).isNull();
      +        assertThat( getLiteral( double.class.getCanonicalName(), "0x0.001p_-10d" ) ).isNull();
           }
       
           @Test
           public void testNegatives() {
      -        assertThat( getLiteral( TypeKind.INT, "-0xffaa", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "-0377_7777", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.INT, "-0b1111_1111", types() ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "-0xffaa" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "-0377_7777" ) ).isNotNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "-0b1111_1111" ) ).isNotNull();
           }
       
           @Test
           public void testFaultyChar() {
      -        assertThat( getLiteral( TypeKind.CHAR, "''", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'a", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'aa", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "a'", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "aa'", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "'", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.CHAR, "a", types() ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "''" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'a" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'aa" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "a'" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "aa'" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "'" ) ).isNull();
      +        assertThat( getLiteral( char.class.getCanonicalName(), "a" ) ).isNull();
           }
       
           @Test
           public void testFloatWithLongLiteral() {
      -        assertThat( getLiteral( TypeKind.FLOAT, "156L", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.FLOAT, "156l", types() ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "156L" ) ).isNotNull();
      +        assertThat( getLiteral( float.class.getCanonicalName(), "156l" ) ).isNotNull();
           }
       
           @Test
           public void testLongPrimitivesWithLongSuffix() {
      -        assertThat( getLiteral( TypeKind.LONG, "156l", types() ) ).isNotNull();
      -        assertThat( getLiteral( TypeKind.LONG, "156L", types() ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "156l" ) ).isNotNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "156L" ) ).isNotNull();
           }
       
           @Test
           public void testIntPrimitiveWithLongSuffix() {
      -        assertThat( getLiteral( TypeKind.INT, "156l", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.INT, "156L", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "156l" ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "156L" ) ).isNull();
           }
       
           @Test
           public void testTooBigIntegersAndBigLongs() {
      -        assertThat( getLiteral( TypeKind.INT, "0xFFFF_FFFF_FFFF", types() ) ).isNull();
      -        assertThat( getLiteral( TypeKind.LONG, "0xFFFF_FFFF_FFFF_FFFF_FFFF", types() ) ).isNull();
      +        assertThat( getLiteral( int.class.getCanonicalName(), "0xFFFF_FFFF_FFFF" ) ).isNull();
      +        assertThat( getLiteral( long.class.getCanonicalName(), "0xFFFF_FFFF_FFFF_FFFF_FFFF" ) ).isNull();
           }
       
           @Test
           public void testNonSupportedPrimitiveType() {
      -        assertThat( getLiteral( TypeKind.VOID, "0xFFFF_FFFF_FFFF", types() ) ).isNull();
      -    }
      -
      -    private static Types types() {
      -
      -        InvocationHandler handler = new InvocationHandler() {
      -            @Override
      -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      -                if ( "getPrimitiveType".equals( method.getName() ) ) {
      -                    return new MyTypeMirror();
      -                }
      -                else {
      -                    return null;
      -                }
      -            }
      -        };
      -
      -        return (Types) Proxy.newProxyInstance( Types.class.getClassLoader(),  new Class[]{Types.class}, handler );
      +        assertThat( getLiteral( void.class.getCanonicalName(), "0xFFFF_FFFF_FFFF" ) ).isNull();
           }
       
      -    private static class MyTypeMirror implements PrimitiveType {
      -
      -        @Override
      -        public TypeKind getKind() {
      -            return TypeKind.VOID;
      -        }
      -
      -        @Override
      -        public  R accept(TypeVisitor v, P p) {
      -            return null;
      -        }
      -
      -        @Override
      -        public List getAnnotationMirrors() {
      -            return null;
      -        }
      -
      -        @Override
      -        public  A getAnnotation(Class annotationType) {
      -            return null;
      +    private static Class getLiteral(String className, String literal) {
      +        try {
      +            return NativeTypes.getLiteral( className, literal );
               }
      -
      -        @Override
      -        public  A[] getAnnotationsByType(Class annotationType) {
      +        catch ( IllegalArgumentException ex ) {
                   return null;
               }
      -
           }
       }
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java
      similarity index 79%
      rename from processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java
      rename to processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java
      index 4c555a3046..fceb72449b 100644
      --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericMapper.java
      +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java
      @@ -29,11 +29,15 @@
        * @author Sjaak Derksen
        */
       @Mapper
      -public interface NumericMapper {
      +public interface ConstantsMapper {
       
      -    NumericMapper INSTANCE = Mappers.getMapper( NumericMapper.class );
      +    ConstantsMapper INSTANCE = Mappers.getMapper( ConstantsMapper.class );
       
           @Mappings({
      +        @Mapping(target = "booleanValue", constant = "true"),
      +        @Mapping(target = "booleanBoxed", constant = "false"),
      +        @Mapping(target = "charValue", constant = "'b'"),
      +        @Mapping(target = "charBoxed", constant = "'a'"),
               @Mapping(target = "byteValue", constant = "20"),
               @Mapping(target = "byteBoxed", constant = "-128"),
               @Mapping(target = "shortValue", constant = "1996"),
      @@ -46,6 +50,7 @@ public interface NumericMapper {
               @Mapping(target = "floatBoxed", constant = "3.4028235e38f"),
               @Mapping(target = "doubleValue", constant = "1e137"),
               @Mapping(target = "doubleBoxed", constant = "0x0.001P-1062d"),
      +        @Mapping(target = "doubleBoxedZero", constant = "0.0")
           })
      -    NumericTarget mapFromConstants( String dummy );
      +    ConstantsTarget mapFromConstants( String dummy );
       }
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java
      similarity index 74%
      rename from processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java
      rename to processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java
      index 768dfd7526..494e45b74f 100644
      --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericTarget.java
      +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java
      @@ -23,8 +23,12 @@
        *
        * @author Sjaak Derksen
        */
      -public class NumericTarget {
      +public class ConstantsTarget {
       
      +    private boolean booleanValue;
      +    private Boolean booleanBoxed;
      +    private char charValue;
      +    private Character charBoxed;
           private byte byteValue;
           private Byte byteBoxed;
           private short shortValue;
      @@ -37,6 +41,39 @@ public class NumericTarget {
           private Float floatBoxed;
           private double doubleValue;
           private Double doubleBoxed;
      +    private Double doubleBoxedZero;
      +
      +    public boolean isBooleanValue() {
      +        return booleanValue;
      +    }
      +
      +    public void setBooleanValue(boolean booleanValue) {
      +        this.booleanValue = booleanValue;
      +    }
      +
      +    public Boolean getBooleanBoxed() {
      +        return booleanBoxed;
      +    }
      +
      +    public void setBooleanBoxed(Boolean booleanBoxed) {
      +        this.booleanBoxed = booleanBoxed;
      +    }
      +
      +    public char getCharValue() {
      +        return charValue;
      +    }
      +
      +    public void setCharValue(char charValue) {
      +        this.charValue = charValue;
      +    }
      +
      +    public Character getCharBoxed() {
      +        return charBoxed;
      +    }
      +
      +    public void setCharBoxed(Character charBoxed) {
      +        this.charBoxed = charBoxed;
      +    }
       
           public byte getByteValue() {
               return byteValue;
      @@ -134,4 +171,12 @@ public void setDoubleBoxed(Double doubleBoxed) {
               this.doubleBoxed = doubleBoxed;
           }
       
      +    public Double getDoubleBoxedZero() {
      +        return doubleBoxedZero;
      +    }
      +
      +    public void setDoubleBoxedZero(Double doubleBoxedZero) {
      +        this.doubleBoxedZero = doubleBoxedZero;
      +    }
      +
       }
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java
      new file mode 100644
      index 0000000000..0611e7fbd4
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java
      @@ -0,0 +1,116 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.source.constants;
      +
      +import static org.assertj.core.api.Assertions.assertThat;
      +
      +import org.junit.Rule;
      +import org.junit.Test;
      +import org.junit.runner.RunWith;
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.WithClasses;
      +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
      +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
      +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
      +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
      +import org.mapstruct.ap.testutil.runner.GeneratedSource;
      +
      +/**
      + *
      + * @author Sjaak Derksen
      + */
      +@RunWith( AnnotationProcessorTestRunner.class )
      +@WithClasses( {
      +    ConstantsMapper.class,
      +    ConstantsTarget.class
      +} )
      +public class ConstantsTest {
      +
      +    @Rule
      +    public final GeneratedSource generatedSrc =
      +        new GeneratedSource().addComparisonToFixtureFor( ConstantsMapper.class );
      +
      +    @Test
      +    public void testNumericConstants() {
      +
      +        ConstantsTarget target = ConstantsMapper.INSTANCE.mapFromConstants( "dummy" );
      +
      +        assertThat( target ).isNotNull();
      +        assertThat( target.isBooleanValue() ).isEqualTo( true );
      +        assertThat( target.getBooleanBoxed() ).isEqualTo( false );
      +        assertThat( target.getCharValue() ).isEqualTo( 'b' );
      +        assertThat( target.getCharBoxed() ).isEqualTo( 'a' );
      +        assertThat( target.getByteValue() ).isEqualTo( (byte) 20 );
      +        assertThat( target.getByteBoxed() ).isEqualTo( (byte) -128 );
      +        assertThat( target.getShortValue() ).isEqualTo( (short) 1996 );
      +        assertThat( target.getShortBoxed() ).isEqualTo( (short) -1996 );
      +        assertThat( target.getIntValue() ).isEqualTo( -03777777 );
      +        assertThat( target.getIntBoxed() ).isEqualTo( 15 );
      +        assertThat( target.getLongValue() ).isEqualTo( 0x7fffffffffffffffL );
      +        assertThat( target.getLongBoxed() ).isEqualTo( 0xCAFEBABEL );
      +        assertThat( target.getFloatValue() ).isEqualTo( 1.40e-45f );
      +        assertThat( target.getFloatBoxed() ).isEqualTo( 3.4028235e38f );
      +        assertThat( target.getDoubleValue() ).isEqualTo( 1e137 );
      +        assertThat( target.getDoubleBoxed() ).isEqualTo( 0x0.001P-1062d );
      +        assertThat( target.getDoubleBoxedZero() ).isEqualTo( 0.0 );
      +    }
      +
      +    @Test
      +    @IssueKey("1458")
      +    @WithClasses({
      +        ConstantsTarget.class,
      +        ErroneousConstantMapper.class
      +    })
      +    @ExpectedCompilationOutcome(
      +        value = CompilationResult.FAILED,
      +        diagnostics = {
      +            @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 39,
      +                messageRegExp = "^.*only 'true' or 'false' are supported\\.$"),
      +            @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 40,
      +                messageRegExp = "^.*invalid character literal\\.$"),
      +            @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 41,
      +                messageRegExp = "^.*Value out of range. Value:\"200\" Radix:10\\.$"),
      +           @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 42,
      +                messageRegExp = "^.*integer number too large.$"),
      +           @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 43,
      +                messageRegExp = "^.*L/l mandatory for long types.$"),
      +           @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 44,
      +                messageRegExp = "^.*improperly placed underscores.$"),
      +          @Diagnostic(type = ErroneousConstantMapper.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 45,
      +                messageRegExp = "^.*floating point number too small.$")
      +        }
      +    )
      +    public void miscellaneousDetailMessages() {
      +    }
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java
      new file mode 100644
      index 0000000000..674fcda0e4
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java
      @@ -0,0 +1,48 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +
      +package org.mapstruct.ap.test.source.constants;
      +
      +import org.mapstruct.BeanMapping;
      +import org.mapstruct.Mapper;
      +import org.mapstruct.Mapping;
      +import org.mapstruct.Mappings;
      +import org.mapstruct.factory.Mappers;
      +
      +/**
      + *
      + * @author Sjaak Derksen
      + */
      +@Mapper
      +public interface ErroneousConstantMapper {
      +
      +    ErroneousConstantMapper INSTANCE = Mappers.getMapper( ErroneousConstantMapper.class );
      +
      +    @BeanMapping( ignoreByDefault = true )
      +    @Mappings({
      +        @Mapping(target = "booleanValue", constant = "zz"),
      +        @Mapping(target = "charValue", constant = "'ba'"),
      +        @Mapping(target = "byteValue", constant = "200"),
      +        @Mapping(target = "intValue", constant = "0xFFFF_FFFF_FFFF"),
      +        @Mapping(target = "longValue", constant = "1"),
      +        @Mapping(target = "floatValue", constant = "1.40e-_45f"),
      +        @Mapping(target = "doubleValue", constant = "1e-137000")
      +    })
      +    ConstantsTarget mapFromConstants( String dummy );
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java
      deleted file mode 100644
      index 9d474c20f5..0000000000
      --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/NumericConstantsTest.java
      +++ /dev/null
      @@ -1,63 +0,0 @@
      -/**
      - *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      - *  and/or other contributors as indicated by the @authors tag. See the
      - *  copyright.txt file in the distribution for a full listing of all
      - *  contributors.
      - *
      - *  Licensed under the Apache License, Version 2.0 (the "License");
      - *  you may not use this file except in compliance with the License.
      - *  You may obtain a copy of the License at
      - *
      - *      http://www.apache.org/licenses/LICENSE-2.0
      - *
      - *  Unless required by applicable law or agreed to in writing, software
      - *  distributed under the License is distributed on an "AS IS" BASIS,
      - *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      - *  See the License for the specific language governing permissions and
      - *  limitations under the License.
      - */
      -package org.mapstruct.ap.test.source.constants;
      -
      -import static org.assertj.core.api.Assertions.assertThat;
      -import org.junit.Rule;
      -import org.junit.Test;
      -import org.junit.runner.RunWith;
      -import org.mapstruct.ap.testutil.WithClasses;
      -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
      -import org.mapstruct.ap.testutil.runner.GeneratedSource;
      -
      -/**
      - *
      - * @author Sjaak Derksen
      - */
      -@RunWith( AnnotationProcessorTestRunner.class )
      -@WithClasses( {
      -    NumericMapper.class,
      -    NumericTarget.class
      -} )
      -public class NumericConstantsTest {
      -
      -    @Rule
      -    public final GeneratedSource generatedSrc = new GeneratedSource().addComparisonToFixtureFor( NumericMapper.class );
      -
      -    @Test
      -    public void testNumericConstants() {
      -
      -        NumericTarget target = NumericMapper.INSTANCE.mapFromConstants( "dummy" );
      -
      -        assertThat( target ).isNotNull();
      -        assertThat( target.getByteValue() ).isEqualTo( (byte) 20 );
      -        assertThat( target.getByteBoxed() ).isEqualTo( (byte) -128 );
      -        assertThat( target.getShortValue() ).isEqualTo( (short) 1996 );
      -        assertThat( target.getShortBoxed() ).isEqualTo( (short) -1996 );
      -        assertThat( target.getIntValue() ).isEqualTo( -03777777 );
      -        assertThat( target.getIntBoxed() ).isEqualTo( 15 );
      -        assertThat( target.getLongValue() ).isEqualTo( 0x7fffffffffffffffL );
      -        assertThat( target.getLongBoxed() ).isEqualTo( 0xCAFEBABEL );
      -        assertThat( target.getFloatValue() ).isEqualTo( 1.40e-45f );
      -        assertThat( target.getFloatBoxed() ).isEqualTo( 3.4028235e38f );
      -        assertThat( target.getDoubleValue() ).isEqualTo( 1e137 );
      -        assertThat( target.getDoubleBoxed() ).isEqualTo( 0x0.001P-1062d );
      -    }
      -
      -}
      diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      similarity index 51%
      rename from processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java
      rename to processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      index c8aef1b48f..ba4f7fc6cd 100644
      --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/NumericMapperImpl.java
      +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      @@ -25,29 +25,34 @@
           date = "2018-04-28T11:42:09+0200",
           comments = "version: , compiler: javac, environment: Java 1.8.0_131 (Oracle Corporation)"
       )
      -public class NumericMapperImpl implements NumericMapper {
      +public class ConstantsMapperImpl implements ConstantsMapper {
       
           @Override
      -    public NumericTarget mapFromConstants(String dummy) {
      +    public ConstantsTarget mapFromConstants(String dummy) {
               if ( dummy == null ) {
                   return null;
               }
       
      -        NumericTarget numericTarget = new NumericTarget();
      +        ConstantsTarget constantsTarget = new ConstantsTarget();
       
      -        numericTarget.setByteBoxed( (byte) -128 );
      -        numericTarget.setDoubleBoxed( (double) 0x0.001P-1062d );
      -        numericTarget.setIntValue( -03777777 );
      -        numericTarget.setLongBoxed( (long) 0xCAFEBABEL );
      -        numericTarget.setFloatBoxed( 3.4028235e38f );
      -        numericTarget.setFloatValue( 1.40e-45f );
      -        numericTarget.setIntBoxed( 15 );
      -        numericTarget.setDoubleValue( 1e137 );
      -        numericTarget.setLongValue( 0x7fffffffffffffffL );
      -        numericTarget.setShortBoxed( (short) -1996 );
      -        numericTarget.setShortValue( (short) 1996 );
      -        numericTarget.setByteValue( (byte) 20 );
      +        constantsTarget.setByteBoxed( (byte) -128 );
      +        constantsTarget.setDoubleBoxed( (double) 0x0.001P-1062d );
      +        constantsTarget.setBooleanBoxed( false );
      +        constantsTarget.setCharValue( 'b' );
      +        constantsTarget.setIntValue( -03777777 );
      +        constantsTarget.setLongBoxed( (long) 0xCAFEBABEL );
      +        constantsTarget.setFloatBoxed( 3.4028235e38f );
      +        constantsTarget.setFloatValue( 1.40e-45f );
      +        constantsTarget.setIntBoxed( 15 );
      +        constantsTarget.setDoubleValue( 1e137 );
      +        constantsTarget.setLongValue( 0x7fffffffffffffffL );
      +        constantsTarget.setDoubleBoxedZero( (double) 0.0 );
      +        constantsTarget.setShortBoxed( (short) -1996 );
      +        constantsTarget.setCharBoxed( 'a' );
      +        constantsTarget.setBooleanValue( true );
      +        constantsTarget.setShortValue( (short) 1996 );
      +        constantsTarget.setByteValue( (byte) 20 );
       
      -        return numericTarget;
      +        return constantsTarget;
           }
       }
      
      From 771debee88644d616377a2f278626dfdba4f213f Mon Sep 17 00:00:00 2001
      From: Filip Hrisafov 
      Date: Sun, 6 May 2018 22:03:16 +0200
      Subject: [PATCH 0241/1006] #1453 Make sure that we always forge iterable / map
       mapping methods without bounds
      
      When generating collection / map mapping methods make sure that the method result type is without bounds
      ---
       .../ap/internal/model/PropertyMapping.java    |   2 +
       .../ap/internal/model/common/Type.java        |  41 +++++
       .../mapstruct/ap/test/bugs/_1453/Auction.java |  62 +++++++
       .../ap/test/bugs/_1453/AuctionDto.java        |  66 ++++++++
       .../ap/test/bugs/_1453/Issue1453Mapper.java   |  44 +++++
       .../ap/test/bugs/_1453/Issue1453Test.java     |  82 ++++++++++
       .../mapstruct/ap/test/bugs/_1453/Payment.java |  35 ++++
       .../ap/test/bugs/_1453/PaymentDto.java        |  35 ++++
       .../test/bugs/_1453/Issue1453MapperImpl.java  | 152 ++++++++++++++++++
       9 files changed, 519 insertions(+)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java
       create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      index 690cd09a19..4b0300e784 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java
      @@ -598,6 +598,7 @@ private Assignment forgeIterableMapping(Type sourceType, Type targetType, Source
               private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source,
                   ExecutableElement element, ContainerMappingMethodBuilder builder) {
       
      +            targetType = targetType.withoutBounds();
                   ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "[]" );
       
                   ContainerMappingMethod iterableMappingMethod = builder
      @@ -634,6 +635,7 @@ private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, Sourc
               private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source,
                                                  ExecutableElement element) {
       
      +            targetType = targetType.withoutBounds();
                   ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "{}" );
       
                   MapMappingMethod.Builder builder = new MapMappingMethod.Builder();
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      index c95c842e89..a1724f0e25 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      @@ -406,6 +406,47 @@ public Type erasure() {
               );
           }
       
      +    public Type withoutBounds() {
      +        if ( typeParameters.isEmpty() ) {
      +            return this;
      +        }
      +
      +        List bounds = new ArrayList( typeParameters.size() );
      +        List mirrors = new ArrayList( typeParameters.size() );
      +        for ( Type typeParameter : typeParameters ) {
      +            bounds.add( typeParameter.getTypeBound() );
      +            mirrors.add( typeParameter.getTypeBound().getTypeMirror() );
      +        }
      +
      +        DeclaredType declaredType = typeUtils.getDeclaredType(
      +            typeElement,
      +            mirrors.toArray( new TypeMirror[] {} )
      +        );
      +        return new Type(
      +            typeUtils,
      +            elementUtils,
      +            typeFactory,
      +            accessorNaming,
      +            declaredType,
      +            (TypeElement) declaredType.asElement(),
      +            bounds,
      +            implementationType,
      +            componentType,
      +            builderType == null ? null : builderType.asBuilderInfo(),
      +            packageName,
      +            name,
      +            qualifiedName,
      +            isInterface,
      +            isEnumType,
      +            isIterableType,
      +            isCollectionType,
      +            isMapType,
      +            isStream,
      +            isImported,
      +            isLiteral
      +        );
      +    }
      +
           /**
            * Whether this type is assignable to the given other type.
            *
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java
      new file mode 100644
      index 0000000000..60f32b6500
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java
      @@ -0,0 +1,62 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +import java.util.List;
      +import java.util.Map;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +public class Auction {
      +
      +    private final List payments;
      +    private final List otherPayments;
      +    private Map mapPayments;
      +    private Map mapSuperPayments;
      +
      +    public Auction(List payments, List otherPayments) {
      +        this.payments = payments;
      +        this.otherPayments = otherPayments;
      +    }
      +
      +    public List getPayments() {
      +        return payments;
      +    }
      +
      +    public List getOtherPayments() {
      +        return otherPayments;
      +    }
      +
      +    public Map getMapPayments() {
      +        return mapPayments;
      +    }
      +
      +    public void setMapPayments(Map mapPayments) {
      +        this.mapPayments = mapPayments;
      +    }
      +
      +    public Map getMapSuperPayments() {
      +        return mapSuperPayments;
      +    }
      +
      +    public void setMapSuperPayments(Map mapSuperPayments) {
      +        this.mapSuperPayments = mapSuperPayments;
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java
      new file mode 100644
      index 0000000000..c3a68bba09
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java
      @@ -0,0 +1,66 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +import java.util.ArrayList;
      +import java.util.HashMap;
      +import java.util.List;
      +import java.util.Map;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +public class AuctionDto {
      +    private List payments;
      +    private List otherPayments;
      +    private Map mapPayments;
      +    private Map mapSuperPayments;
      +
      +    List takePayments() {
      +        return payments;
      +    }
      +
      +    public void setPayments(List payments) {
      +        this.payments = payments == null ? null : new ArrayList( payments );
      +    }
      +
      +    List takeOtherPayments() {
      +        return otherPayments;
      +    }
      +
      +    public void setOtherPayments(List otherPayments) {
      +        this.otherPayments = otherPayments;
      +    }
      +
      +    public Map getMapPayments() {
      +        return mapPayments;
      +    }
      +
      +    public void setMapPayments(Map mapPayments) {
      +        this.mapPayments = mapPayments == null ? null : new HashMap( mapPayments );
      +    }
      +
      +    public Map getMapSuperPayments() {
      +        return mapSuperPayments;
      +    }
      +
      +    public void setMapSuperPayments(Map mapSuperPayments) {
      +        this.mapSuperPayments = mapSuperPayments;
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java
      new file mode 100644
      index 0000000000..fa3e0b4c54
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java
      @@ -0,0 +1,44 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +import java.util.List;
      +import java.util.Map;
      +
      +import org.mapstruct.Mapper;
      +import org.mapstruct.factory.Mappers;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +@Mapper
      +public interface Issue1453Mapper {
      +
      +    Issue1453Mapper INSTANCE = Mappers.getMapper( Issue1453Mapper.class );
      +
      +    AuctionDto map(Auction auction);
      +
      +    List mapExtend(List auctions);
      +
      +    List mapSuper(List auctions);
      +
      +    Map mapExtend(Map auctions);
      +
      +    Map mapSuper(Map auctions);
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java
      new file mode 100644
      index 0000000000..47ece0437f
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java
      @@ -0,0 +1,82 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +import java.util.Arrays;
      +
      +import org.junit.Rule;
      +import org.junit.Test;
      +import org.junit.runner.RunWith;
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.WithClasses;
      +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
      +import org.mapstruct.ap.testutil.runner.GeneratedSource;
      +
      +import static org.assertj.core.api.Assertions.assertThat;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +@IssueKey("1453")
      +@RunWith(AnnotationProcessorTestRunner.class)
      +@WithClasses({
      +    Auction.class,
      +    AuctionDto.class,
      +    Issue1453Mapper.class,
      +    Payment.class,
      +    PaymentDto.class
      +})
      +public class Issue1453Test {
      +
      +    @Rule
      +    public GeneratedSource source = new GeneratedSource().addComparisonToFixtureFor( Issue1453Mapper.class );
      +
      +    @Test
      +    public void shouldGenerateCorrectCode() {
      +
      +        AuctionDto target = Issue1453Mapper.INSTANCE.map( new Auction(
      +            Arrays.asList( new Payment( 100L ), new Payment( 500L ) ),
      +            Arrays.asList( new Payment( 200L ), new Payment( 600L ) )
      +        ) );
      +
      +        PaymentDto first = new PaymentDto();
      +        first.setPrice( 100L );
      +        PaymentDto second = new PaymentDto();
      +        second.setPrice( 500L );
      +
      +        assertThat( target.takePayments() )
      +            .usingFieldByFieldElementComparator()
      +            .containsExactly(
      +                first,
      +                second
      +            );
      +
      +        PaymentDto firstOther = new PaymentDto();
      +        firstOther.setPrice( 200L );
      +        PaymentDto secondOther = new PaymentDto();
      +        secondOther.setPrice( 600L );
      +
      +        assertThat( target.takeOtherPayments() )
      +            .usingFieldByFieldElementComparator()
      +            .containsExactly(
      +                firstOther,
      +                secondOther
      +            );
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java
      new file mode 100644
      index 0000000000..e3ec1a7f03
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java
      @@ -0,0 +1,35 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +public class Payment {
      +
      +    private final Long price;
      +
      +    public Payment(Long price) {
      +        this.price = price;
      +    }
      +
      +    public Long getPrice() {
      +        return price;
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java
      new file mode 100644
      index 0000000000..0763b24416
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java
      @@ -0,0 +1,35 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +public class PaymentDto {
      +
      +    private Long price;
      +
      +    public Long getPrice() {
      +        return price;
      +    }
      +
      +    public void setPrice(Long price) {
      +        this.price = price;
      +    }
      +}
      diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java
      new file mode 100644
      index 0000000000..38faf777bf
      --- /dev/null
      +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java
      @@ -0,0 +1,152 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1453;
      +
      +import java.util.ArrayList;
      +import java.util.HashMap;
      +import java.util.List;
      +import java.util.Map;
      +import javax.annotation.Generated;
      +
      +@Generated(
      +    value = "org.mapstruct.ap.MappingProcessor",
      +    date = "2018-05-04T23:25:01+0200",
      +    comments = "version: , compiler: javac, environment: Java 1.8.0_161 (Oracle Corporation)"
      +)
      +public class Issue1453MapperImpl implements Issue1453Mapper {
      +
      +    @Override
      +    public AuctionDto map(Auction auction) {
      +        if ( auction == null ) {
      +            return null;
      +        }
      +
      +        AuctionDto auctionDto = new AuctionDto();
      +
      +        auctionDto.setPayments( paymentListToPaymentDtoList( auction.getPayments() ) );
      +        auctionDto.setOtherPayments( paymentListToPaymentDtoList( auction.getOtherPayments() ) );
      +        auctionDto.setMapPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapPayments() ) );
      +        auctionDto.setMapSuperPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapSuperPayments() ) );
      +
      +        return auctionDto;
      +    }
      +
      +    @Override
      +    public List mapExtend(List auctions) {
      +        if ( auctions == null ) {
      +            return null;
      +        }
      +
      +        List list = new ArrayList( auctions.size() );
      +        for ( Auction auction : auctions ) {
      +            list.add( map( auction ) );
      +        }
      +
      +        return list;
      +    }
      +
      +    @Override
      +    public List mapSuper(List auctions) {
      +        if ( auctions == null ) {
      +            return null;
      +        }
      +
      +        List list = new ArrayList( auctions.size() );
      +        for ( Auction auction : auctions ) {
      +            list.add( map( auction ) );
      +        }
      +
      +        return list;
      +    }
      +
      +    @Override
      +    public Map mapExtend(Map auctions) {
      +        if ( auctions == null ) {
      +            return null;
      +        }
      +
      +        Map map = new HashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) );
      +
      +        for ( java.util.Map.Entry entry : auctions.entrySet() ) {
      +            AuctionDto key = map( entry.getKey() );
      +            AuctionDto value = map( entry.getValue() );
      +            map.put( key, value );
      +        }
      +
      +        return map;
      +    }
      +
      +    @Override
      +    public Map mapSuper(Map auctions) {
      +        if ( auctions == null ) {
      +            return null;
      +        }
      +
      +        Map map = new HashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) );
      +
      +        for ( java.util.Map.Entry entry : auctions.entrySet() ) {
      +            AuctionDto key = map( entry.getKey() );
      +            AuctionDto value = map( entry.getValue() );
      +            map.put( key, value );
      +        }
      +
      +        return map;
      +    }
      +
      +    protected PaymentDto paymentToPaymentDto(Payment payment) {
      +        if ( payment == null ) {
      +            return null;
      +        }
      +
      +        PaymentDto paymentDto = new PaymentDto();
      +
      +        paymentDto.setPrice( payment.getPrice() );
      +
      +        return paymentDto;
      +    }
      +
      +    protected List paymentListToPaymentDtoList(List list) {
      +        if ( list == null ) {
      +            return null;
      +        }
      +
      +        List list1 = new ArrayList( list.size() );
      +        for ( Payment payment : list ) {
      +            list1.add( paymentToPaymentDto( payment ) );
      +        }
      +
      +        return list1;
      +    }
      +
      +    protected Map paymentPaymentMapToPaymentDtoPaymentDtoMap(Map map) {
      +        if ( map == null ) {
      +            return null;
      +        }
      +
      +        Map map1 = new HashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) );
      +
      +        for ( java.util.Map.Entry entry : map.entrySet() ) {
      +            PaymentDto key = paymentToPaymentDto( entry.getKey() );
      +            PaymentDto value = paymentToPaymentDto( entry.getValue() );
      +            map1.put( key, value );
      +        }
      +
      +        return map1;
      +    }
      +}
      
      From 6fbc4cf25306821f5e7862c77795f2d2993811c2 Mon Sep 17 00:00:00 2001
      From: sjaakd 
      Date: Mon, 7 May 2018 20:59:06 +0200
      Subject: [PATCH 0242/1006] #1180 non existing (nested) property in shared
       config
      
      ---
       .../model/source/SourceReference.java         |  2 +-
       .../bugs/_1180/ErroneousIssue1180Mapper.java  | 33 ++++++++++++
       .../ap/test/bugs/_1180/Issue1180Test.java     | 53 +++++++++++++++++++
       .../ap/test/bugs/_1180/SharedConfig.java      | 37 +++++++++++++
       .../mapstruct/ap/test/bugs/_1180/Source.java  | 36 +++++++++++++
       .../mapstruct/ap/test/bugs/_1180/Target.java  | 36 +++++++++++++
       6 files changed, 196 insertions(+), 1 deletion(-)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java
      index dba8266831..cfad298162 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java
      @@ -355,7 +355,7 @@ public List getElementNames() {
           public SourceReference copyForInheritanceTo(SourceMethod method) {
               List replacementParamCandidates = new ArrayList();
               for ( Parameter sourceParam : method.getSourceParameters() ) {
      -            if ( sourceParam.getType().isAssignableTo( parameter.getType() ) ) {
      +            if ( parameter != null && sourceParam.getType().isAssignableTo( parameter.getType() ) ) {
                       replacementParamCandidates.add( sourceParam );
                   }
               }
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java
      new file mode 100644
      index 0000000000..be815188c8
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java
      @@ -0,0 +1,33 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1180;
      +
      +import org.mapstruct.InheritConfiguration;
      +import org.mapstruct.Mapper;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +@Mapper( config = SharedConfig.class )
      +public abstract class ErroneousIssue1180Mapper {
      +
      +    @InheritConfiguration
      +    public abstract Target map(Source source);
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java
      new file mode 100644
      index 0000000000..3953d6950d
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java
      @@ -0,0 +1,53 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1180;
      +
      +import org.junit.Test;
      +import org.junit.runner.RunWith;
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.WithClasses;
      +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
      +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
      +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
      +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
      +
      +/**
      + * @author Sjaak Derksen
      + */
      +@WithClasses( {
      +    Source.class,
      +    Target.class,
      +    SharedConfig.class,
      +    ErroneousIssue1180Mapper.class
      +} )
      +@RunWith(AnnotationProcessorTestRunner.class)
      +@IssueKey( "1180" )
      +public class Issue1180Test {
      +
      +    @Test
      +    @ExpectedCompilationOutcome(value = CompilationResult.FAILED,
      +        diagnostics = {
      +            @Diagnostic(type = SharedConfig.class,
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 33,
      +                messageRegExp = "No property named \"sourceProperty\\.nonExistant\" exists.*")
      +        })
      +    public void shouldCompileButNotGiveNullPointer() {
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java
      new file mode 100644
      index 0000000000..a0dc7f6291
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java
      @@ -0,0 +1,37 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1180;
      +
      +import org.mapstruct.MapperConfig;
      +import org.mapstruct.Mapping;
      +import org.mapstruct.Mappings;
      +
      +/**
      + *
      + * @author Sjaak Derksen
      + */
      +@MapperConfig
      +public interface SharedConfig {
      +
      +    @Mappings({
      +        @Mapping(target = "targetProperty", source = "sourceProperty.nonExistant")
      +    })
      +    Target map(Source source);
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java
      new file mode 100644
      index 0000000000..f8d57efb9e
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java
      @@ -0,0 +1,36 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1180;
      +
      +/**
      + * @author Sjaak Derksen
      + */
      +public class Source {
      +
      +    private String sourceProperty;
      +
      +    public String getSourceProperty() {
      +        return sourceProperty;
      +    }
      +
      +    public void setSourceProperty(String sourceProperty) {
      +        this.sourceProperty = sourceProperty;
      +    }
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java
      new file mode 100644
      index 0000000000..8948548f49
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java
      @@ -0,0 +1,36 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._1180;
      +
      +/**
      + * @author Sjaak Derksen
      + */
      +public class Target {
      +
      +    private String targetProperty;
      +
      +    public String getTargetProperty() {
      +        return targetProperty;
      +    }
      +
      +    public void setTargetProperty(String targetProperty) {
      +        this.targetProperty = targetProperty;
      +    }
      +
      +}
      
      From eeddc17de4178ef7aedbf07f7862aed79790033b Mon Sep 17 00:00:00 2001
      From: Christian Bandowski 
      Date: Wed, 9 May 2018 22:28:17 +0200
      Subject: [PATCH 0243/1006] #537 add unit test
      
      ---
       .../ap/test/bugs/_537/Issue537Mapper.java     | 32 ++++++++++++
       .../test/bugs/_537/Issue537MapperConfig.java  | 29 +++++++++++
       .../ap/test/bugs/_537/Issue537Test.java       | 50 +++++++++++++++++++
       .../ap/test/bugs/_537/ReferenceMapper.java    | 28 +++++++++++
       .../mapstruct/ap/test/bugs/_537/Source.java   | 41 +++++++++++++++
       .../mapstruct/ap/test/bugs/_537/Target.java   | 41 +++++++++++++++
       6 files changed, 221 insertions(+)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java
      
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java
      new file mode 100644
      index 0000000000..67a88ba368
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java
      @@ -0,0 +1,32 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +import org.mapstruct.Mapper;
      +import org.mapstruct.factory.Mappers;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +@Mapper(uses = ReferenceMapper.class, config = Issue537MapperConfig.class)
      +public interface Issue537Mapper {
      +    Issue537Mapper INSTANCE = Mappers.getMapper( Issue537Mapper.class );
      +
      +    Target mapDto(Source source);
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java
      new file mode 100644
      index 0000000000..21c81318e2
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java
      @@ -0,0 +1,29 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +import org.mapstruct.MapperConfig;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +@MapperConfig(uses = ReferenceMapper.class)
      +public interface Issue537MapperConfig {
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java
      new file mode 100644
      index 0000000000..22d9d39135
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java
      @@ -0,0 +1,50 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +import org.junit.Test;
      +import org.junit.runner.RunWith;
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.WithClasses;
      +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
      +
      +import static org.assertj.core.api.Assertions.assertThat;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +@RunWith(AnnotationProcessorTestRunner.class)
      +@IssueKey("537")
      +@WithClasses({
      +    Issue537Mapper.class,
      +    Issue537MapperConfig.class,
      +    ReferenceMapper.class,
      +    Source.class,
      +    Target.class
      +})
      +public class Issue537Test {
      +
      +    @Test
      +    public void testThatReferencedMapperWillBeUsed() {
      +        Target target = Issue537Mapper.INSTANCE.mapDto( new Source( "abc" ) );
      +
      +        assertThat( target ).isNotNull();
      +        assertThat( target.getValue() ).isEqualTo( 3 );
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java
      new file mode 100644
      index 0000000000..db3b91f924
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java
      @@ -0,0 +1,28 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +public class ReferenceMapper {
      +    public Integer stringLength(String source) {
      +        return source == null ? null : source.length();
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java
      new file mode 100644
      index 0000000000..753c6a47c4
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java
      @@ -0,0 +1,41 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +public class Source {
      +    private String value;
      +
      +    public Source() {
      +    }
      +
      +    public Source(String value) {
      +        this.value = value;
      +    }
      +
      +    public String getValue() {
      +        return value;
      +    }
      +
      +    public void setValue(String value) {
      +        this.value = value;
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java
      new file mode 100644
      index 0000000000..afe1fb35b5
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java
      @@ -0,0 +1,41 @@
      +/**
      + *  Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/)
      + *  and/or other contributors as indicated by the @authors tag. See the
      + *  copyright.txt file in the distribution for a full listing of all
      + *  contributors.
      + *
      + *  Licensed under the Apache License, Version 2.0 (the "License");
      + *  you may not use this file except in compliance with the License.
      + *  You may obtain a copy of the License at
      + *
      + *      http://www.apache.org/licenses/LICENSE-2.0
      + *
      + *  Unless required by applicable law or agreed to in writing, software
      + *  distributed under the License is distributed on an "AS IS" BASIS,
      + *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      + *  See the License for the specific language governing permissions and
      + *  limitations under the License.
      + */
      +package org.mapstruct.ap.test.bugs._537;
      +
      +/**
      + * @author Christian Bandowski
      + */
      +public class Target {
      +    private Integer value;
      +
      +    public Target() {
      +    }
      +
      +    public Target(Integer value) {
      +        this.value = value;
      +    }
      +
      +    public Integer getValue() {
      +        return value;
      +    }
      +
      +    public void setValue(Integer value) {
      +        this.value = value;
      +    }
      +}
      
      From db851701ef742ee4c6e3354c838dbe2d184c62a5 Mon Sep 17 00:00:00 2001
      From: Christian Bandowski 
      Date: Thu, 17 May 2018 21:39:38 +0200
      Subject: [PATCH 0244/1006] #1454 add more tests for builder lifecycle methods
      
      ---
       .../BuilderLifecycleCallbacksTest.java          |  5 ++++-
       .../test/builder/lifecycle/MappingContext.java  | 17 +++++++++++++++++
       2 files changed, 21 insertions(+), 1 deletion(-)
      
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java
      index 9ef7b2469e..890c96da29 100644
      --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java
      +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java
      @@ -58,10 +58,13 @@ public void lifecycleMethodsShouldBeInvoked() {
       
               assertThat( context.getInvokedMethods() )
                   .contains(
      +                "beforeWithoutParameters",
                       "beforeWithBuilderTargetType",
                       "beforeWithBuilderTarget",
      +                "afterWithoutParameters",
                       "afterWithBuilderTargetType",
      -                "afterWithBuilderTarget"
      +                "afterWithBuilderTarget",
      +                "afterWithBuilderTargetReturningTarget"
                   );
           }
       }
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java
      index 5b4f6487f0..157b5bbce8 100644
      --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java
      +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java
      @@ -33,6 +33,11 @@ public class MappingContext {
       
           private final List invokedMethods = new ArrayList();
       
      +    @BeforeMapping
      +    public void beforeWithoutParameters() {
      +        invokedMethods.add( "beforeWithoutParameters" );
      +    }
      +
           @BeforeMapping
           public void beforeWithTargetType(OrderDto source, @TargetType Class orderClass) {
               invokedMethods.add( "beforeWithTargetType" );
      @@ -53,6 +58,11 @@ public void beforeWithBuilderTarget(OrderDto source, @MappingTarget Order.Builde
               invokedMethods.add( "beforeWithBuilderTarget" );
           }
       
      +    @AfterMapping
      +    public void afterWithoutParameters() {
      +        invokedMethods.add( "afterWithoutParameters" );
      +    }
      +
           @AfterMapping
           public void afterWithTargetType(OrderDto source, @TargetType Class orderClass) {
               invokedMethods.add( "afterWithTargetType" );
      @@ -73,6 +83,13 @@ public void afterWithBuilderTarget(OrderDto source, @MappingTarget Order.Builder
               invokedMethods.add( "afterWithBuilderTarget" );
           }
       
      +    @AfterMapping
      +    public Order afterWithBuilderTargetReturningTarget(@MappingTarget Order.Builder orderBuilder) {
      +        invokedMethods.add( "afterWithBuilderTargetReturningTarget" );
      +
      +        return orderBuilder.create();
      +    }
      +
           public List getInvokedMethods() {
               return invokedMethods;
           }
      
      From e67c849c175d9efcc1fe32fe93075fadaf000cbe Mon Sep 17 00:00:00 2001
      From: sjaakd 
      Date: Tue, 22 May 2018 22:41:53 +0200
      Subject: [PATCH 0245/1006] #1398 allowing `@ObjectFactory` methods on context
      
      ---
       .../src/main/java/org/mapstruct/Context.java  |  53 +++++-
       .../java/org/mapstruct/ObjectFactory.java     |  15 +-
       .../mapstruct-reference-guide.asciidoc        |   2 +
       .../ap/internal/model/BeanMappingMethod.java  |   9 +-
       .../model/CollectionAssignmentBuilder.java    |   4 +-
       .../model/ContainerMappingMethodBuilder.java  |   6 +-
       .../ap/internal/model/EnumMappingMethod.java  |   4 +-
       ...tory.java => LifecycleMethodResolver.java} |  27 +--
       .../ap/internal/model/MapMappingMethod.java   |  11 +-
       .../ap/internal/model/MapperReference.java    |  13 ++
       .../internal/model/MappingBuilderContext.java |  12 --
       .../model/ObjectFactoryMethodResolver.java    | 161 ++++++++++++++++++
       .../ap/internal/model/PropertyMapping.java    |  20 +--
       .../ap/internal/model/ValueMappingMethod.java |   4 +-
       .../internal/model/source/SourceMethod.java   |  14 +-
       .../processor/MethodRetrievalProcessor.java   |  12 +-
       .../creation/MappingResolverImpl.java         |  61 -------
       .../objectfactory/ContextObjectFactory.java   |  33 ++++
       .../ContextWithObjectFactoryMapper.java       |  36 ++++
       .../ContextWithObjectFactoryTest.java         |  53 ++++++
       .../ap/test/context/objectfactory/Valve.java  |  42 +++++
       .../test/context/objectfactory/ValveDto.java  |  37 ++++
       22 files changed, 489 insertions(+), 140 deletions(-)
       rename processor/src/main/java/org/mapstruct/ap/internal/model/{LifecycleCallbackFactory.java => LifecycleMethodResolver.java} (90%)
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java
      
      diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core-common/src/main/java/org/mapstruct/Context.java
      index 7432e66ad1..e1fc0c979a 100644
      --- a/core-common/src/main/java/org/mapstruct/Context.java
      +++ b/core-common/src/main/java/org/mapstruct/Context.java
      @@ -32,8 +32,9 @@
        * {@code @}{@link BeforeMapping}/{@code @}{@link AfterMapping} methods, which are called on the provided context
        * parameter value if applicable.
        * 

      - * Note: no {@code null} checks are performed before calling before/after mapping methods on context - * parameters. The caller needs to make sure that no {@code null} are passed in that case. + * Note: no {@code null} checks are performed before calling before/after mapping methods or object + * factory methods on {@code @}{@link Context} annotated parameters. The caller needs to make sure that no {@code null} + * are passed in that case. *

      * For generated code to call a method that is declared with {@code @Context} parameters, the declaration of the mapping * method being generated needs to contain at least those (or assignable) {@code @Context} parameters as well. MapStruct @@ -135,7 +136,55 @@ * } * *

      + *

      + * Example 3: Using {@code @Context} parameters for creating an entity object by calling an + * {@code @}{@link ObjectFactory} methods: + * + *

      + * 
      + * // type of the context parameter
      + * public class ContextObjectFactory {
      + *     @PersistenceContext(unitName = "my-unit")
      + *     private EntityManager em;
      + *
      + *     @ObjectFactory
      + *     public Valve create( String id ) {
      + *        Query query = em.createNamedQuery("Valve.findById");
      + *        query.setParameter("id", id);
      + *        Valve result = query.getSingleResult();
      + *        if ( result != null ) {
      + *            result = new Valve( id );
      + *        }
      + *        return result;
      + *     }
      + *
      + * }
      + *
      + * @Mapper
      + * public interface ContextWithObjectFactoryMapper {
      + *     Valve map(ValveDto dto, @Context ContextObjectFactory factory);
      + * }
        *
      + *
      + * // generates:
      + *
      + * public class ContextWithObjectFactoryMapperImpl implements ContextWithObjectFactoryMapper {
      + *
      + *   @Override
      + *   public Valve map(ValveDto dto, ContextObjectFactory factory) {
      + *       if ( dto == null ) {
      + *           return null;
      + *       }
      + *
      + *       Valve valve = factory.create();
      + *
      + *       valve.setOneWay( dto.isOneWay() );
      + *
      + *       return valve;
      + *   }
      + * }
      + * 
      + * 
      * @author Andreas Gudian * @since 1.2 */ diff --git a/core-common/src/main/java/org/mapstruct/ObjectFactory.java b/core-common/src/main/java/org/mapstruct/ObjectFactory.java index 7319900b66..60c0acff02 100644 --- a/core-common/src/main/java/org/mapstruct/ObjectFactory.java +++ b/core-common/src/main/java/org/mapstruct/ObjectFactory.java @@ -29,14 +29,15 @@ * By default beans are created during the mapping process with the default constructor. If a factory method with a * return type that is assignable to the required object type is present, then the factory method is used instead. *

      - * Factory methods can be defined without parameters, with an {@code @}{@link TargetType} parameter, a {@code @} - * {@link Context} parameter, or with the mapping source parameter. If any of those parameters are defined, then - * the mapping method that is supposed to use the factory method needs to be declared with an assignable result type, - * assignable context parameter, and/or assignable source types. + * Factory methods can be defined without parameters, with an {@code @}{@link TargetType} parameter, a + * {@code @}{@link Context} parameter, or with the mapping source parameter. If any of those parameters are defined, + * then the mapping method that is supposed to use the factory method needs to be declared with an assignable result + * type, assignable context parameter, and/or assignable source types. *

      - * Note: the usage of this annotation is optional if no source parameters are part of the - * signature, i.e. it is declared without parameters or only with {@code @}{@link TargetType} and/or {@code @} - * {@link Context}. + * Note: the usage of this annotation is optional when used in the {@link Mapper#uses()} + * if no source parameters are part of the signature, i.e. it is declared without parameters or only with + * {@code @}{@link TargetType} and/or {@code @}{@link Context}. It is however mandatory when used inside + * an {@code @}{@link Context} annotated class. *

      * Example: Using a factory method for entities to check whether the entity already exists in the * EntityManager and then returns the managed instance: diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 316600a833..58cf8ca3ad 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1119,6 +1119,8 @@ public class CarMapperImpl implements CarMapper { Additional _context_ or _state_ information can be passed through generated mapping methods to custom methods with `@Context` parameters. Such parameters are passed to other mapping methods, `@ObjectFactory` methods (see <>) or `@BeforeMapping` / `@AfterMapping` methods (see <>) when applicable and can thus be used in custom code. +`@Context` parameters are searched for `@ObjectFactory` methods, which are called on the provided context parameter value if applicable. + `@Context` parameters are also searched for `@BeforeMapping` / `@AfterMapping` methods, which are called on the provided context parameter value if applicable. *Note:* no `null` checks are performed before calling before/after mapping methods on context parameters. The caller needs to make sure that `null` is not passed in that case. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 059a1c7baf..95a14e180a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -190,10 +190,11 @@ public BeanMappingMethod build() { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( + factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, method.getResultType(), - selectionParameters + selectionParameters, + ctx ); } @@ -246,14 +247,14 @@ else if ( !method.isUpdateMethod() && sortPropertyMappingsByDependencies(); - List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( + List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariableNames ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); + LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); if (factoryMethod != null && method instanceof ForgedMethod ) { ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 3443cfab72..7973b5c8d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -141,8 +141,8 @@ public Assignment build() { ); } - Assignment factoryMethod = ctx.getMappingResolver() - .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( sourceRHS ) ); + Assignment factoryMethod = ObjectFactoryMethodResolver + .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( sourceRHS ), ctx ); result = new UpdateWrapper( result, method.getThrownTypes(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 7225947204..5a3d5dde16 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -138,19 +138,19 @@ else if ( method instanceof ForgedMethod ) { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); + factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, method.getResultType(), null, ctx ); } Set existingVariables = new HashSet( method.getParameterNames() ); existingVariables.add( loopVariableName ); - List beforeMappingMethods = LifecycleCallbackFactory.beforeMappingMethods( + List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); - List afterMappingMethods = LifecycleCallbackFactory.afterMappingMethods( + List afterMappingMethods = LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index f91e6231c8..ee4b663c21 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -104,9 +104,9 @@ enumConstant, first( mappedConstants ).getTargetName() Set existingVariables = new HashSet( method.getParameterNames() ); List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); + LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); + LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); return new EnumMappingMethod( method, enumMappings, beforeMappingMethods, afterMappingMethods ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java similarity index 90% rename from processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 6cad83b86d..6c763e9c83 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -38,9 +38,9 @@ * * @author Andreas Gudian */ -public final class LifecycleCallbackFactory { +public final class LifecycleMethodResolver { - private LifecycleCallbackFactory() { + private LifecycleMethodResolver() { } /** @@ -54,8 +54,7 @@ public static List beforeMappingMethods(Method SelectionParameters selectionParameters, MappingBuilderContext ctx, Set existingVariableNames) { - return collectLifecycleCallbackMethods( - method, + return collectLifecycleCallbackMethods( method, selectionParameters, filterBeforeMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, @@ -73,8 +72,7 @@ public static List afterMappingMethods(Method SelectionParameters selectionParameters, MappingBuilderContext ctx, Set existingVariableNames) { - return collectLifecycleCallbackMethods( - method, + return collectLifecycleCallbackMethods( method, selectionParameters, filterAfterMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, @@ -93,7 +91,9 @@ private static List getAllAvailableMethods(Method method, List availableMethods = new ArrayList( methodsProvidedByParams.size() + sourceModelMethods.size() ); - availableMethods.addAll( methodsProvidedByParams ); + for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { + availableMethods.add( methodProvidedByParams ); + } availableMethods.addAll( sourceModelMethods ); return availableMethods; @@ -144,7 +144,7 @@ private static List toLifecycleCallbackMethodR existingVariableNames ) ); } else { - MapperReference mapperReference = findMapperReference( + MapperReference mapperReference = MapperReference.findMapperReference( ctx.getMapperReferences(), candidate.getMethod() ); @@ -158,17 +158,6 @@ private static List toLifecycleCallbackMethodR return result; } - private static MapperReference findMapperReference(List mapperReferences, SourceMethod method) { - for ( MapperReference ref : mapperReferences ) { - if ( ref.getType().equals( method.getDeclaringMapper() ) ) { - ref.setUsed( ref.isUsed() || !method.isStatic() ); - ref.setTypeRequiresImport( true ); - return ref; - } - } - return null; - } - private static List filterBeforeMappingMethods(List methods) { List result = new ArrayList(); for ( SourceMethod method : methods ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 1f02b7756c..2c7fb453fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -18,6 +18,8 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -36,8 +38,6 @@ import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Strings; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one {@code Map} type to another. Keys and * values are mapped either by a {@link TypeConversion} or another mapping method if required. @@ -191,7 +191,8 @@ public MapMappingMethod build() { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ctx.getMappingResolver().getFactoryMethod( method, method.getResultType(), null ); + factoryMethod = ObjectFactoryMethodResolver + .getFactoryMethod( method, method.getResultType(), null, ctx ); } keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); @@ -199,9 +200,9 @@ public MapMappingMethod build() { Set existingVariables = new HashSet( method.getParameterNames() ); List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, null, ctx, existingVariables ); + LifecycleMethodResolver.beforeMappingMethods( method, null, ctx, existingVariables ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, null, ctx, existingVariables ); + LifecycleMethodResolver.afterMappingMethods( method, null, ctx, existingVariables ); return new MapMappingMethod( method, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java index d8a60211ce..5fedcf285c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java @@ -18,7 +18,9 @@ */ package org.mapstruct.ap.internal.model; +import java.util.List; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.SourceMethod; /** * A reference to another mapper class, which itself may be generated or hand-written. @@ -34,4 +36,15 @@ public MapperReference(Type type, String variableName) { public MapperReference(Type type, String variableName, boolean isUsed) { super( type, variableName, isUsed ); } + + public static MapperReference findMapperReference(List mapperReferences, SourceMethod method) { + for ( MapperReference ref : mapperReferences ) { + if ( ref.getType().equals( method.getDeclaringMapper() ) ) { + ref.setUsed( ref.isUsed() || !method.isStatic() ); + ref.setTypeRequiresImport( true ); + return ref; + } + } + return null; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index b8449d975d..fafce28fc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -107,18 +107,6 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, String tar SelectionParameters selectionParameters, SourceRHS sourceRHS, boolean preferUpdateMethods); - /** - * returns a no arg factory method - * - * @param mappingMethod target mapping method - * @param target return type to match - * @param selectionParameters parameters used in the selection process - * - * @return a method reference to the factory method, or null if no suitable, or ambiguous method found - * - */ - MethodReference getFactoryMethod(Method mappingMethod, Type target, SelectionParameters selectionParameters); - Set getUsedVirtualMappings(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java new file mode 100644 index 0000000000..8f779aed23 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -0,0 +1,161 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import static org.mapstruct.ap.internal.util.Collections.first; + +import java.util.ArrayList; +import java.util.List; + +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; + +import org.mapstruct.ap.internal.model.common.BuilderType; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; +import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.Strings; + +/** + * + * @author Sjaak Derksen + */ +public class ObjectFactoryMethodResolver { + + private ObjectFactoryMethodResolver() { + } + + /** + * returns a no arg factory method + * + * @param method target mapping method + * @param targetType return type to match + * @param selectionParameters parameters used in the selection process + * @param ctx + * + * @return a method reference to the factory method, or null if no suitable, or ambiguous method found + * + */ + public static MethodReference getFactoryMethod( Method method, + Type targetType, + SelectionParameters selectionParameters, + MappingBuilderContext ctx) { + + MethodSelectors selectors = + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory() ); + + List> matchingFactoryMethods = + selectors.getMatchingMethods( + method, + getAllAvailableMethods( method, ctx.getSourceModel() ), + java.util.Collections. emptyList(), + targetType.getEffectiveType(), + SelectionCriteria.forFactoryMethods( selectionParameters ) ); + + if (matchingFactoryMethods.isEmpty()) { + return findBuilderFactoryMethod( targetType ); + } + + if ( matchingFactoryMethods.size() > 1 ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, + targetType.getEffectiveType(), + Strings.join( matchingFactoryMethods, ", " ) ); + + return null; + } + + SelectedMethod matchingFactoryMethod = first( matchingFactoryMethods ); + + Parameter providingParameter = + method.getContextProvidedMethods().getParameterForProvidedMethod( matchingFactoryMethod.getMethod() ); + + if ( providingParameter != null ) { + return MethodReference.forParameterProvidedMethod( + matchingFactoryMethod.getMethod(), + providingParameter, + matchingFactoryMethod.getParameterBindings() ); + } + else { + MapperReference ref = MapperReference.findMapperReference( + ctx.getMapperReferences(), + matchingFactoryMethod.getMethod() ); + + return MethodReference.forMapperReference( + matchingFactoryMethod.getMethod(), + ref, + matchingFactoryMethod.getParameterBindings() ); + } + } + + private static MethodReference findBuilderFactoryMethod(Type targetType) { + BuilderType builder = targetType.getBuilderType(); + if ( builder == null ) { + return null; + } + + ExecutableElement builderCreationMethod = builder.getBuilderCreationMethod(); + if ( builderCreationMethod.getKind() == ElementKind.CONSTRUCTOR ) { + // If the builder creation method is a constructor it would be handled properly down the line + return null; + } + + if ( !builder.getBuildingType().isAssignableTo( targetType ) ) { + //TODO print error message + return null; + } + + return MethodReference.forStaticBuilder( + builderCreationMethod.getSimpleName().toString(), + builder.getOwningType() + ); + } + + private static List getAllAvailableMethods(Method method, List sourceModelMethods) { + ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods(); + if ( contextProvidedMethods.isEmpty() ) { + return sourceModelMethods; + } + + List methodsProvidedByParams = contextProvidedMethods + .getAllProvidedMethodsInParameterOrder( method.getContextParameters() ); + + List availableMethods = + new ArrayList( methodsProvidedByParams.size() + sourceModelMethods.size() ); + + for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { + // add only methods from context that do have the @ObjectFactory annotation + if ( methodProvidedByParams.hasObjectFactoryAnnotation() ) { + availableMethods.add( methodProvidedByParams ); + } + } + availableMethods.addAll( sourceModelMethods ); + + return availableMethods; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 4b0300e784..8440cb72d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -18,13 +18,18 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; -import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; @@ -54,16 +59,11 @@ import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; -import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; -import org.mapstruct.ap.internal.util.NativeTypes; - /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to * {@code int Target#bar}. Name and type of source and target property can differ. If they have different types, the @@ -433,8 +433,8 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { boolean mapNullToDefault = method.getMapperConfiguration(). getNullValueMappingStrategy() == NullValueMappingStrategyPrism.RETURN_DEFAULT; - Assignment factory = ctx.getMappingResolver() - .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ) ); + Assignment factory = ObjectFactoryMethodResolver + .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ), ctx ); return new UpdateWrapper( rhs, method.getThrownTypes(), factory, isFieldAssignment(), targetType, !rhs.isSourceReferenceParameter(), mapNullToDefault ); } @@ -816,7 +816,7 @@ public PropertyMapping build() { getNullValueMappingStrategy() == NullValueMappingStrategyPrism.RETURN_DEFAULT; Assignment factoryMethod = - ctx.getMappingResolver().getFactoryMethod( method, targetType, null ); + ObjectFactoryMethodResolver.getFactoryMethod( method, targetType, null, ctx ); assignment = new UpdateWrapper( assignment, method.getThrownTypes(), factoryMethod, isFieldAssignment(), targetType, false, mapNullToDefault ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index c1568a2f07..6c9a057b31 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -122,9 +122,9 @@ public ValueMappingMethod build( ) { SelectionParameters selectionParameters = getSelectionParameters( method, ctx.getTypeUtils() ); Set existingVariables = new HashSet( method.getParameterNames() ); List beforeMappingMethods = - LifecycleCallbackFactory.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); + LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = - LifecycleCallbackFactory.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); + LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); // finally return a mapping return new ValueMappingMethod( method, mappingEntries, nullTarget, defaultTarget, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 4cf01354d0..a83029db2b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -79,12 +79,12 @@ public class SourceMethod implements Method { private List applicablePrototypeMethods; private List applicableReversePrototypeMethods; - private Boolean isBeanMapping; private Boolean isEnumMapping; private Boolean isValueMapping; private Boolean isIterableMapping; private Boolean isMapMapping; private Boolean isStreamMapping; + private final boolean hasObjectFactoryAnnotation; public static class Builder { @@ -231,7 +231,8 @@ private SourceMethod(Builder builder, MappingOptions mappingOptions) { this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); - this.isObjectFactory = determineIfIsObjectFactory( executable ); + this.hasObjectFactoryAnnotation = ObjectFactoryPrism.getInstanceOn( executable ) != null; + this.isObjectFactory = determineIfIsObjectFactory(); this.typeUtils = builder.typeUtils; this.typeFactory = builder.typeFactory; @@ -240,13 +241,12 @@ private SourceMethod(Builder builder, MappingOptions mappingOptions) { this.mapperToImplement = builder.definingType; } - private boolean determineIfIsObjectFactory(ExecutableElement executable) { - boolean hasFactoryAnnotation = ObjectFactoryPrism.getInstanceOn( executable ) != null; + private boolean determineIfIsObjectFactory() { boolean hasNoSourceParameters = getSourceParameters().isEmpty(); boolean hasNoMappingTargetParam = getMappingTargetParameter() == null; return !isLifecycleCallbackMethod() && !returnType.isVoid() && hasNoMappingTargetParam - && ( hasFactoryAnnotation || hasNoSourceParameters ); + && ( hasObjectFactoryAnnotation || hasNoSourceParameters ); } @Override @@ -606,4 +606,8 @@ public boolean isAbstract() { public boolean isUpdateMethod() { return getMappingTargetParameter() != null; } + + public boolean hasObjectFactoryAnnotation() { + return hasObjectFactoryAnnotation; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 8d2b4e8be9..04eb86a13d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -245,7 +245,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, } ParameterProvidedMethods contextProvidedMethods = - retrieveLifecycleMethodsFromContext( contextParameters, mapperToImplement, mapperConfig ); + retrieveContextProvidedMethods( contextParameters, mapperToImplement, mapperConfig ); return new SourceMethod.Builder() .setExecutable( method ) @@ -275,7 +275,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .build(); } - private ParameterProvidedMethods retrieveLifecycleMethodsFromContext( + private ParameterProvidedMethods retrieveContextProvidedMethods( List contextParameters, TypeElement mapperToImplement, MapperConfiguration mapperConfig) { ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder(); @@ -289,14 +289,14 @@ private ParameterProvidedMethods retrieveLifecycleMethodsFromContext( mapperConfig, Collections. emptyList() ); - List lifecycleMethods = new ArrayList( contextParamMethods.size() ); + List contextProvidedMethods = new ArrayList( contextParamMethods.size() ); for ( SourceMethod sourceMethod : contextParamMethods ) { - if ( sourceMethod.isLifecycleCallbackMethod() ) { - lifecycleMethods.add( sourceMethod ); + if ( sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() ) { + contextProvidedMethods.add( sourceMethod ); } } - builder.addMethodsForParameter( contextParam, lifecycleMethods ); + builder.addMethodsForParameter( contextParam, contextProvidedMethods ); } return builder.build(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index e50dce92a6..04a8dace0b 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Set; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; @@ -45,7 +44,6 @@ import org.mapstruct.ap.internal.model.MethodReference; import org.mapstruct.ap.internal.model.VirtualMappingMethod; import org.mapstruct.ap.internal.model.common.Assignment; -import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -129,65 +127,6 @@ public Set getUsedVirtualMappings() { return usedVirtualMappings; } - @Override - public MethodReference getFactoryMethod(final Method mappingMethod, Type targetType, - SelectionParameters selectionParameters) { - - List> matchingFactoryMethods = - methodSelectors.getMatchingMethods( - mappingMethod, - sourceModel, - java.util.Collections. emptyList(), - targetType.getEffectiveType(), - SelectionCriteria.forFactoryMethods( selectionParameters ) ); - - if (matchingFactoryMethods.isEmpty()) { - return findBuilderFactoryMethod( targetType ); - } - - if ( matchingFactoryMethods.size() > 1 ) { - messager.printMessage( - mappingMethod.getExecutable(), - Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, - targetType.getEffectiveType(), - Strings.join( matchingFactoryMethods, ", " ) ); - - return null; - } - - SelectedMethod matchingFactoryMethod = first( matchingFactoryMethods ); - - MapperReference ref = findMapperReference( matchingFactoryMethod.getMethod() ); - - return MethodReference.forMapperReference( - matchingFactoryMethod.getMethod(), - ref, - matchingFactoryMethod.getParameterBindings() ); - } - - private MethodReference findBuilderFactoryMethod(Type targetType) { - BuilderType builder = targetType.getBuilderType(); - if ( builder == null ) { - return null; - } - - ExecutableElement builderCreationMethod = builder.getBuilderCreationMethod(); - if ( builderCreationMethod.getKind() == ElementKind.CONSTRUCTOR ) { - // If the builder creation method is a constructor it would be handled properly down the line - return null; - } - - if ( !builder.getBuildingType().isAssignableTo( targetType ) ) { - //TODO print error message - return null; - } - - return MethodReference.forStaticBuilder( - builderCreationMethod.getSimpleName().toString(), - builder.getOwningType() - ); - } - private MapperReference findMapperReference(Method method) { for ( MapperReference ref : mapperReferences ) { if ( ref.getType().equals( method.getDeclaringMapper() ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java new file mode 100644 index 0000000000..2ef29aa363 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.objectfactory; + +import org.mapstruct.ObjectFactory; + +/** + * @author Andreas Gudian + */ +public class ContextObjectFactory { + + @ObjectFactory + public Valve create() { + return new Valve("123id"); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java new file mode 100644 index 0000000000..febf62e0e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.objectfactory; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper +public interface ContextWithObjectFactoryMapper { + + ContextWithObjectFactoryMapper INSTANCE = Mappers.getMapper( ContextWithObjectFactoryMapper.class ); + + Valve map(ValveDto dto, @Context ContextObjectFactory factory); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java new file mode 100644 index 0000000000..15da66770d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.objectfactory; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * + * @author Sjaak Derksen + */ +@IssueKey( "1398" ) +@WithClasses({ + Valve.class, + ValveDto.class, + ContextObjectFactory.class, + ContextWithObjectFactoryMapper.class}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ContextWithObjectFactoryTest { + + @Test + public void testFactoryCalled( ) { + ValveDto dto = new ValveDto(); + dto.setOneWay( true ); + + Valve result = ContextWithObjectFactoryMapper.INSTANCE.map( dto, new ContextObjectFactory() ); + + assertThat( result ).isNotNull(); + assertThat( result.isOneWay() ).isTrue(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java new file mode 100644 index 0000000000..4a04bdd816 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.objectfactory; + +/** + * + * @author Sjaak Derksen + */ +public class Valve { + + private boolean oneWay; + private final String id; + + public Valve(String id) { + this.id = id; + } + + public boolean isOneWay() { + return oneWay; + } + + public void setOneWay(boolean oneWay) { + this.oneWay = oneWay; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java new file mode 100644 index 0000000000..1a4a96e342 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.context.objectfactory; + +/** + * + * @author Sjaak Derksen + */ +public class ValveDto { + + private boolean oneWay; + + public boolean isOneWay() { + return oneWay; + } + + public void setOneWay(boolean oneWay) { + this.oneWay = oneWay; + } + +} From 3a4fcb5bcb23985040d2f7e6f984efb2a2aa967a Mon Sep 17 00:00:00 2001 From: sjaakd Date: Thu, 24 May 2018 22:51:51 +0200 Subject: [PATCH 0246/1006] #1398 allowing `@ObjectFactory` methods on context, fixing javadoc --- core-common/src/main/java/org/mapstruct/Context.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core-common/src/main/java/org/mapstruct/Context.java index e1fc0c979a..7d5d922cb3 100644 --- a/core-common/src/main/java/org/mapstruct/Context.java +++ b/core-common/src/main/java/org/mapstruct/Context.java @@ -162,21 +162,20 @@ * * @Mapper * public interface ContextWithObjectFactoryMapper { - * Valve map(ValveDto dto, @Context ContextObjectFactory factory); + * Valve map(ValveDto dto, @Context ContextObjectFactory factory, String id); * } * * * // generates: - * * public class ContextWithObjectFactoryMapperImpl implements ContextWithObjectFactoryMapper { * * @Override - * public Valve map(ValveDto dto, ContextObjectFactory factory) { + * public Valve map(ValveDto dto, ContextObjectFactory factory, String id) { * if ( dto == null ) { * return null; * } * - * Valve valve = factory.create(); + * Valve valve = factory.create( id ); * * valve.setOneWay( dto.isOneWay() ); * From f4ed077aeb4d6bd6896e5a128646a89601a85f26 Mon Sep 17 00:00:00 2001 From: cvanburen Date: Tue, 5 Jun 2018 11:57:47 -0700 Subject: [PATCH 0247/1006] Documentation update, section 3, fixing typos --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 58cf8ca3ad..c39addf905 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -366,7 +366,7 @@ public class CarMapperImpl implements CarMapper { if ( car.getCategory() != null ) { carDto.setCategory( car.getCategory().toString() ); } - carDto.setEngine( engineTtoEngineDto( car.getEngine() ) ); + carDto.setEngine( engineToEngineDto( car.getEngine() ) ); return carDto; } @@ -408,7 +408,7 @@ MapStruct takes all public properties of the source and target types into accoun [[adding-custom-methods]] === Adding custom methods to mappers -In some cases it can be required to manually implement a specific mapping from one type to another which can't be generated by MapStruct. One way for this is to implement such method on another class which then is used by mappers generated by MapStruct (see <>). +In some cases it can be required to manually implement a specific mapping from one type to another which can't be generated by MapStruct. One way to handle this is to implement the custom method on another class which then is used by mappers generated by MapStruct (see <>). Alternatively, when using Java 8 or later, you can implement custom methods directly in a mapper interface as default methods. The generated code will invoke the default methods if the argument and return types match. @@ -434,7 +434,7 @@ public interface CarMapper { The class generated by MapStruct implements the method `carToCarDto()`. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute. -A mapper could also be defined in form of an abstract class instead of an interface and implement custom methods directly in this mapper class. In this case MapStruct will generate an extension of the abstract class with implementations of all abstract methods. An advantage of this approach over declaring default methods is that additional fields could be declared in the mapper class. +A mapper could also be defined in the form of an abstract class instead of an interface and implement the custom methods directly in the mapper class. In this case MapStruct will generate an extension of the abstract class with implementations of all abstract methods. An advantage of this approach over declaring default methods is that additional fields could be declared in the mapper class. The previous example where the mapping from `Person` to `PersonDto` requires some special logic could then be defined like this: From 508de6733ec2a08585b2b770abb99b7502c7b708 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Fri, 15 Jun 2018 22:26:15 +0200 Subject: [PATCH 0248/1006] #1523 dont lose timezone mapping Calendar to XMLGregorianCalendar --- .../source/builtin/BuiltInMappingMethods.java | 1 + .../ZonedDateTimeToXmlGregorianCalendar.java | 70 +++++++++++++++ .../CalendarToXmlGregorianCalendar.ftl | 2 +- .../ZonedDateTimeToXmlGregorianCalendar.ftl | 33 +++++++ .../bugs/_1523/java8/Issue1523Mapper.java | 34 ++++++++ .../test/bugs/_1523/java8/Issue1523Test.java | 86 +++++++++++++++++++ .../ap/test/bugs/_1523/java8/Source.java | 43 ++++++++++ .../ap/test/bugs/_1523/java8/Target.java | 42 +++++++++ 8 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 9675bf386a..58bd170034 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -55,6 +55,7 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { if ( isJava8TimeAvailable( typeFactory ) ) { builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); + builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) ); if ( isXmlGregorianCalendarPresent ) { builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java new file mode 100644 index 0000000000..a06e78da7e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java @@ -0,0 +1,70 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import java.time.ZonedDateTime; +import java.util.GregorianCalendar; +import java.util.Set; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * @author Christian Bandowski + */ +public class ZonedDateTimeToXmlGregorianCalendar extends BuiltInMethod { + + private final Parameter parameter; + private final Type returnType; + private final Set importTypes; + + public ZonedDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { + this.parameter = new Parameter( "zdt ", typeFactory.getType( ZonedDateTime.class ) ); + this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); + + this.importTypes = asSet( + returnType, + parameter.getType(), + typeFactory.getType( DatatypeFactory.class ), + typeFactory.getType( GregorianCalendar.class ), + typeFactory.getType( DatatypeConfigurationException.class ) + ); + } + + @Override + public Set getImportTypes() { + return importTypes; + } + + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public Type getReturnType() { + return returnType; + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl index 2e74ffa071..4220268ea3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl @@ -25,7 +25,7 @@ private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@incl } try { - <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>(); + <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>( cal.getTimeZone() ); gcal.setTimeInMillis( cal.getTimeInMillis() ); return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( gcal ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl new file mode 100644 index 0000000000..116d5d3525 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl @@ -0,0 +1,33 @@ +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> +<#-- + + Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + and/or other contributors as indicated by the @authors tag. See the + copyright.txt file in the distribution for a full listing of all + contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("ZonedDateTime")/> zdt ) { + if ( zdt == null ) { + return null; + } + + try { + return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( <@includeModel object=findType("GregorianCalendar")/>.from( zdt ) ); + } + catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { + throw new RuntimeException( ex ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java new file mode 100644 index 0000000000..eb54dc6c0c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1523.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper +public abstract class Issue1523Mapper { + + public static final Issue1523Mapper INSTANCE = Mappers.getMapper( Issue1523Mapper.class ); + + public abstract Target map(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java new file mode 100644 index 0000000000..0ebde15c2a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java @@ -0,0 +1,86 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1523.java8; + +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.TimeZone; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * This test will evaluate if the conversion from {@code Calendar} to {@code XMLGregorianCalendar} works in case the + * default timezone was not used. Additionally a direct conversion between {@code ZonedDateTime} to + * {@code XMLGregorianCalendar} was added for this issue to improve readability / performance. This will be tested as + * well. + * + * @author Christian Bandowski + */ +@WithClasses({ + Issue1523Mapper.class, + Source.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1523") +public class Issue1523Test { + + private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getDefault(); + + @BeforeClass + public static void before() { + // we want to test that the timezone will correctly be used in mapped XMLGregorianCalendar and not the + // default one, so we must ensure that we use a different timezone than the default one -> set the default + // one explicitly to UTC + TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); + } + + @AfterClass + public static void after() { + // revert the changed default TZ + TimeZone.setDefault( DEFAULT_TIMEZONE ); + } + + @Test + public void testThatCorrectTimeZoneWillBeUsedInTarget() { + Source source = new Source(); + // default one was explicitly set to UTC, thus +01:00 is a different one + source.setValue( ZonedDateTime.parse( "2018-06-15T00:00:00+01:00" ) ); + Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT+01:00" ) ); + cal.set( 2018, 02, 15, 00, 00, 00 ); + source.setValue2( cal ); + + Target target = Issue1523Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNotNull(); + assertThat( target.getValue2() ).isNotNull(); + // +01:00 -> offset is 60 min + assertThat( target.getValue().getTimezone() ).isEqualTo( 60 ); + assertThat( target.getValue2().getTimezone() ).isEqualTo( 60 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java new file mode 100644 index 0000000000..5ccb45d9cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1523.java8; + +import java.time.ZonedDateTime; +import java.util.Calendar; + +public class Source { + private ZonedDateTime value; + private Calendar value2; + + public ZonedDateTime getValue() { + return value; + } + + public void setValue(ZonedDateTime value) { + this.value = value; + } + + public Calendar getValue2() { + return value2; + } + + public void setValue2(Calendar value2) { + this.value2 = value2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java new file mode 100644 index 0000000000..009c4ca62f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java @@ -0,0 +1,42 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1523.java8; + +import javax.xml.datatype.XMLGregorianCalendar; + +public class Target { + private XMLGregorianCalendar value; + private XMLGregorianCalendar value2; + + public XMLGregorianCalendar getValue() { + return value; + } + + public void setValue(XMLGregorianCalendar value) { + this.value = value; + } + + public XMLGregorianCalendar getValue2() { + return value2; + } + + public void setValue2(XMLGregorianCalendar value2) { + this.value2 = value2; + } +} From fc5f937a713f7f19de4147aa92ed09f5ba9ec503 Mon Sep 17 00:00:00 2001 From: tomoya-yokota Date: Sun, 1 Jul 2018 15:25:39 +0900 Subject: [PATCH 0249/1006] Fix Method name typo --- .../org/mapstruct/ap/internal/model/BeanMappingMethod.java | 2 +- .../org/mapstruct/ap/internal/model/EnumMappingMethod.java | 2 +- .../ap/internal/processor/MapperCreationProcessor.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 95a14e180a..02d2358cf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -101,7 +101,7 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { return this; } - public Builder souceMethod(SourceMethod sourceMethod) { + public Builder sourceMethod(SourceMethod sourceMethod) { singleMapping = new SourceMethodSingleMapping( sourceMethod ); return setupMethodWithMapping( sourceMethod ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index ee4b663c21..fc0a896606 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -58,7 +58,7 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { return this; } - public Builder souceMethod(SourceMethod sourceMethod) { + public Builder sourceMethod(SourceMethod sourceMethod) { this.method = sourceMethod; return this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index d5900a422d..37a3cd2775 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -340,7 +340,7 @@ else if ( method.isEnumMapping() ) { EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder(); MappingMethod enumMappingMethod = builder .mappingContext( mappingContext ) - .souceMethod( method ) + .sourceMethod( method ) .build(); if ( enumMappingMethod != null ) { @@ -371,7 +371,7 @@ else if ( method.isStreamMapping() ) { BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) - .souceMethod( method ) + .sourceMethod( method ) .nullValueMappingStrategy( nullValueMappingStrategy ) .selectionParameters( selectionParameters ) .build(); From b03ca8b7a9327a35a3bd3e89317b621458b220f7 Mon Sep 17 00:00:00 2001 From: sngrekov Date: Mon, 2 Jul 2018 00:27:47 +0300 Subject: [PATCH 0250/1006] Add sample of @Mapping annotation to @InheritInverseConfiguration --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index c39addf905..0647880e11 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2235,7 +2235,7 @@ In case of bi-directional mappings, e.g. from entity to DTO and from DTO to enti Use the annotation `@InheritInverseConfiguration` to indicate that a method shall inherit the inverse configuration of the corresponding reverse method. -.Inverse mapping method inheriting its configuration +.Inverse mapping method inheriting its configuration and ignoring some of them ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -2247,6 +2247,7 @@ public interface CarMapper { CarDto carToDto(Car car); @InheritInverseConfiguration + @Mapping(target = "numberOfSeats", ignore = true) Car carDtoToCar(CarDto carDto); } ---- From e2c8559a6294906bcbd24d3f7d5d01f04bf7f5c2 Mon Sep 17 00:00:00 2001 From: tomoya-yokota Date: Mon, 11 Jun 2018 20:12:04 +0900 Subject: [PATCH 0251/1006] Update document on gradle-apt-plugin --- .../asciidoc/mapstruct-reference-guide.asciidoc | 14 +++++++++++--- readme.md | 11 +++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 0647880e11..c79eb6efd0 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -123,13 +123,21 @@ Add the following to your Gradle build file in order to enable MapStruct: ... plugins { ... - id 'net.ltgt.apt' version '0.8' + id 'net.ltgt.apt' version '0.15' } + +// You can integrate with your IDEs. +// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides +apply plugin: 'net.ltgt.apt-idea' +apply plugin: 'net.ltgt.apt-eclipse' + dependencies { ... - compile 'org.mapstruct:mapstruct-jdk8:{mapstructVersion}' + compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}" - apt 'org.mapstruct:mapstruct-processor:{mapstructVersion}' + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + // If you are using mapstruct in test code + testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" } ... ---- diff --git a/readme.md b/readme.md index 1b65d8c684..9e5d354e5a 100644 --- a/readme.md +++ b/readme.md @@ -105,13 +105,20 @@ For Gradle, you need something along the following lines: ```groovy plugins { ... - id 'net.ltgt.apt' version '0.8' + id 'net.ltgt.apt' version '0.15' } + +// You can integrate with your IDEs. +// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides +apply plugin: 'net.ltgt.apt-idea' +apply plugin: 'net.ltgt.apt-eclipse' + dependencies { ... compile 'org.mapstruct:mapstruct:1.2.0.Final' // OR use this with Java 8 and beyond: org.mapstruct:mapstruct-jdk8:... - apt 'org.mapstruct:mapstruct-processor:1.2.0.Final' + annotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final' // if you are using mapstruct in test code } ... ``` From 81f82a54a5d1e233ea7fb15237c61aca5fd8e237 Mon Sep 17 00:00:00 2001 From: tomoya-yokota Date: Thu, 28 Jun 2018 19:52:33 +0900 Subject: [PATCH 0252/1006] Document of sample code is broken. --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index c79eb6efd0..0efe2c8da9 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2017,10 +2017,10 @@ The same warnings and restrictions apply to default expressions that apply to ex The example below demonstrates how two source properties can be mapped to one target: .Mapping method using a default expression -=== +==== [source, java, linenums] [subs="verbatim,attributes"] ---- +---- imports java.util.UUID; @Mapper( imports = UUID.class ) @@ -2031,8 +2031,8 @@ public interface SourceTargetMapper { @Mapping(target="id", source="sourceId", defaultExpression = "java( UUID.randomUUID().toString() )") Target sourceToTarget(Source s); } ---- -=== +---- +==== The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation ((see <>). From c9bc1df132e3498eca7bcd92fd91e260bcc195db Mon Sep 17 00:00:00 2001 From: Gervais Blaise Date: Thu, 12 Jul 2018 22:12:09 +0200 Subject: [PATCH 0253/1006] Allow package-private mapper Use and make the default constructor accessible to create the mapper instance. fixes #1365 --- .../java/org/mapstruct/factory/Mappers.java | 22 +++++++++++++----- .../org/mapstruct/factory/MappersTest.java | 5 ++++ .../factory/PackagePrivateMapper.java | 23 +++++++++++++++++++ .../factory/PackagePrivateMapperImpl.java | 22 ++++++++++++++++++ 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java create mode 100644 core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java diff --git a/core-common/src/main/java/org/mapstruct/factory/Mappers.java b/core-common/src/main/java/org/mapstruct/factory/Mappers.java index e740040237..44ab7ae4fb 100644 --- a/core-common/src/main/java/org/mapstruct/factory/Mappers.java +++ b/core-common/src/main/java/org/mapstruct/factory/Mappers.java @@ -18,6 +18,8 @@ */ package org.mapstruct.factory; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; @@ -78,10 +80,13 @@ public static T getMapper(Class clazz) { catch ( ClassNotFoundException e ) { throw new RuntimeException( e ); } + catch ( NoSuchMethodException e) { + throw new RuntimeException( e ); + } } - private static T getMapper( - Class mapperType, Iterable classLoaders) throws ClassNotFoundException { + private static T getMapper(Class mapperType, Iterable classLoaders) + throws ClassNotFoundException, NoSuchMethodException { for ( ClassLoader classLoader : classLoaders ) { T mapper = doGetMapper( mapperType, classLoader ); @@ -93,11 +98,13 @@ private static T getMapper( throw new ClassNotFoundException("Cannot find implementation for " + mapperType.getName() ); } - private static T doGetMapper(Class clazz, ClassLoader classLoader) { + private static T doGetMapper(Class clazz, ClassLoader classLoader) throws NoSuchMethodException { try { - @SuppressWarnings("unchecked") - T mapper = (T) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ).newInstance(); - return mapper; + @SuppressWarnings( "unchecked" ) + Class implementation = (Class) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ); + Constructor constructor = implementation.getDeclaredConstructor(); + constructor.setAccessible( true ); + return constructor.newInstance(); } catch (ClassNotFoundException e) { ServiceLoader loader = ServiceLoader.load( clazz, classLoader ); @@ -118,5 +125,8 @@ private static T doGetMapper(Class clazz, ClassLoader classLoader) { catch (IllegalAccessException e) { throw new RuntimeException( e ); } + catch (InvocationTargetException e) { + throw new RuntimeException( e ); + } } } diff --git a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java index 990907fe0a..1a0da2626b 100644 --- a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java +++ b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java @@ -47,4 +47,9 @@ public void findsNestedMapperImpl() throws Exception { assertThat( Mappers.getMapper( SomeClass.Foo.class ) ).isNotNull(); assertThat( Mappers.getMapper( SomeClass.NestedClass.Foo.class ) ).isNotNull(); } + + @Test + public void shouldReturnPackagePrivateImplementationInstance() { + assertThat( Mappers.getMapper( PackagePrivateMapper.class ) ).isNotNull(); + } } diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java new file mode 100644 index 0000000000..7d5e4738af --- /dev/null +++ b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java @@ -0,0 +1,23 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.factory; + +interface PackagePrivateMapper { + +} diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java new file mode 100644 index 0000000000..dd8ee89319 --- /dev/null +++ b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java @@ -0,0 +1,22 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.factory; + +class PackagePrivateMapperImpl implements PackagePrivateMapper { +} From 62ffa3fa43a7c995f22f2d7dfe5f24c0dc5cecc9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 12 Jul 2018 22:14:56 +0200 Subject: [PATCH 0254/1006] Add Gervais to the copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index e83d9d683d..eddc353b64 100644 --- a/copyright.txt +++ b/copyright.txt @@ -15,6 +15,7 @@ Dmytro Polovinkin - https://github.com/navpil Eric Martineau - https://github.com/ericmartineau Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr +Gervais Blaise - https://github.com/gervaisb Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla Jeff Smyth - https://github.com/smythie86 From ef270caecbebfa035ea642eb64ce1952d2fea653 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 12 Jul 2018 23:16:53 +0200 Subject: [PATCH 0255/1006] #1479 Add support for Builders with multiple build methods (#1498) * Add new @Builder annotation for defining a build method * When there are multiple build methods look for a method named `build` and if found use it * If @Builder is defined than look for a build method with the defined method * When a type has multiple builder creation methods throw an exception and don't use the builder Defaulting to a method named `build` will make sure that a correct method is selected for: * FreeBuilder - it has two methods: `build` and `buildPartial` * Protobuf - it has three methods: `getDefaultInstanceForType`, `build` and `buildPartial` --- .../main/java/org/mapstruct/BeanMapping.java | 19 ++ .../src/main/java/org/mapstruct/Builder.java | 45 +++++ .../src/main/java/org/mapstruct/Mapper.java | 22 ++- .../main/java/org/mapstruct/MapperConfig.java | 24 ++- .../mapstruct-reference-guide.asciidoc | 6 + .../ap/internal/model/BeanMappingMethod.java | 2 +- .../model/BuilderFinisherMethodResolver.java | 101 ++++++++++ .../ap/internal/model/common/BuilderType.java | 25 +-- .../ap/internal/model/common/TypeFactory.java | 35 +++- .../ap/internal/model/source/BeanMapping.java | 25 ++- .../ap/internal/prism/PrismGenerator.java | 2 + .../DefaultModelElementProcessorContext.java | 1 + .../ap/internal/util/MapperConfiguration.java | 13 ++ .../mapstruct/ap/internal/util/Message.java | 4 + .../org/mapstruct/ap/spi/BuilderInfo.java | 32 ++-- .../org/mapstruct/ap/spi/BuilderProvider.java | 2 + .../ap/spi/DefaultBuilderProvider.java | 58 ++++-- ...ThanOneBuilderCreationMethodException.java | 49 +++++ .../multiple/BuilderConfigDefinedMapper.java | 39 ++++ .../multiple/BuilderDefinedMapper.java | 39 ++++ .../builder/multiple/BuilderMapperConfig.java | 29 +++ .../multiple/DefaultBuildMethodMapper.java | 33 ++++ ...ErroneousMoreThanOneBuildMethodMapper.java | 36 ++++ ...dMethodWithMapperDefinedMappingMapper.java | 32 ++++ .../multiple/MultipleBuilderMapperTest.java | 174 ++++++++++++++++++ .../ap/test/builder/multiple/Source.java | 35 ++++ .../ap/test/builder/multiple/Task.java | 84 +++++++++ .../TooManyBuilderCreationMethodsMapper.java | 34 ++++ .../test/builder/multiple/build/Process.java | 84 +++++++++ .../test/builder/multiple/builder/Case.java | 83 +++++++++ 30 files changed, 1109 insertions(+), 58 deletions(-) create mode 100644 core-common/src/main/java/org/mapstruct/Builder.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index 10d0e70f78..03a0ee10f2 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -97,4 +97,23 @@ * @since 1.3 */ String[] ignoreUnmappedSourceProperties() default {}; + + /** + * The information that should be used for the builder mappings. This can be used to define custom build methods + * for the builder strategy that one uses. + * + * If no builder is defined the builder given via {@link MapperConfig#builder()} or {@link Mapper#builder()} + * will be applied. + *

      + * NOTE: In case no builder is defined here, in {@link Mapper} or {@link MapperConfig} and there is a single + * build method, then that method would be used. + *

      + * If the builder is defined and there is a single method that does not match the name of the finisher than + * a compile error will occurs + * + * @return the builder information for the method level + * + * @since 1.3 + */ + Builder builder() default @Builder; } diff --git a/core-common/src/main/java/org/mapstruct/Builder.java b/core-common/src/main/java/org/mapstruct/Builder.java new file mode 100644 index 0000000000..68d7eb9fce --- /dev/null +++ b/core-common/src/main/java/org/mapstruct/Builder.java @@ -0,0 +1,45 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.util.Experimental; + +/** + * Configuration of builders, e.g. the name of the final build method. + * + * @author Filip Hrisafov + * + * @since 1.3 + */ +@Retention(RetentionPolicy.CLASS) +@Target({}) +@Experimental +public @interface Builder { + + /** + * The name of the build method that needs to be invoked on the builder to create the type being build + * + * @return the method that needs to tbe invoked on the builder + */ + String buildMethod() default "build"; +} diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index 17bb1115c2..a4a19ba500 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -18,8 +18,6 @@ */ package org.mapstruct; -import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -27,6 +25,8 @@ import org.mapstruct.factory.Mappers; +import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; + /** * Marks an interface or abstract class as a mapper and activates the generation of a implementation of that type via * MapStruct. @@ -200,4 +200,22 @@ */ boolean disableSubMappingMethodsGeneration() default false; + /** + * The information that should be used for the builder mappings. This can be used to define custom build methods + * for the builder strategy that one uses. + * + * If no builder is defined the builder given via {@link MapperConfig#builder()} will be applied. + * + *

      + * NOTE: In case no builder is defined here, in {@link BeanMapping} or {@link MapperConfig} and there is a single + * build method, then that method would be used. + *

      + * If the builder is defined and there is a single method that does not match the name of the finisher than + * a compile error will occurs + * + * @return the builder information + * + * @since 1.3 + */ + Builder builder() default @Builder; } diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index e9bbec0aaf..45a95a1bf3 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -18,8 +18,6 @@ */ package org.mapstruct; -import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -27,6 +25,8 @@ import org.mapstruct.factory.Mappers; +import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; + /** * Marks a class or interface as configuration source for generated mappers. This allows to share common configurations * between several mapper classes. @@ -186,4 +186,24 @@ MappingInheritanceStrategy mappingInheritanceStrategy() * @since 1.2 */ boolean disableSubMappingMethodsGeneration() default false; + + /** + * The information that should be used for the builder mappings. This can be used to define custom build methods + * for the builder strategy that one uses. + * + *

      + * Can be overridden by {@link MapperConfig#builder()}. + * + *

      + * NOTE: In case no builder is defined here, in {@link BeanMapping} or {@link Mapper} and there is a single + * build method, then that method would be used. + *

      + * If the builder is defined and there is a single method that does not match the name of the finisher than + * a compile error will occurs + * + * @return the builder information + * + * @since 1.3 + */ + Builder builder() default @Builder; } diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 0efe2c8da9..1a2d481dcb 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -639,6 +639,12 @@ The default implementation of the `BuilderProvider` assumes the following: So for example `Person` has a public static method that returns `PersonBuilder`. * The builder type has a parameterless public method (build method) that returns the type being build In our example `PersonBuilder` has a method returning `Person`. +* In case there are multiple build methods, MapStruct will look for a method called `build` if such methods exists +than this would be used, otherwise a compilation error would be created. +* A specific build method can be defined by using `@Builder` within: `@BeanMapping`, `@Mapper` or `@MapperConfig` +* In case there are multiple builder creation methods that satisfy the above conditions then a `MoreThanOneBuilderCreationMethodException` +will be thrown from the `DefaultBuilderProvider` SPI. +In case of a `MoreThanOneBuilderCreationMethodException` MapStruct will write a warning in the compilation and not use any builder. If such type is found then MapStruct will use that type to perform the mapping to (i.e. it will look for setters into that type). To finish the mapping MapStruct generates code that will invoke the build method of the builder. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 02d2358cf4..090ac070b1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -287,7 +287,7 @@ private MethodReference getFinalizerMethod(Type resultType) { return null; } - return MethodReference.forMethodCall( builderType.getBuildMethod() ); + return BuilderFinisherMethodResolver.getBuilderFinisherMethod( method, builderType, ctx ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java new file mode 100644 index 0000000000..0948c7d112 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -0,0 +1,101 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.internal.model; + +import java.util.Collection; +import javax.lang.model.element.ExecutableElement; + +import org.mapstruct.ap.internal.model.common.BuilderType; +import org.mapstruct.ap.internal.model.source.BeanMapping; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.prism.BuilderPrism; +import org.mapstruct.ap.internal.util.MapperConfiguration; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.Strings; + +import static org.mapstruct.ap.internal.util.Collections.first; + +/** + * @author Filip Hrisafov + */ +public class BuilderFinisherMethodResolver { + + private static final String DEFAULT_BUILD_METHOD_NAME = "build"; + + private BuilderFinisherMethodResolver() { + } + + public static MethodReference getBuilderFinisherMethod(Method method, BuilderType builderType, + MappingBuilderContext ctx) { + Collection buildMethods = builderType.getBuildMethods(); + if ( buildMethods.isEmpty() ) { + //If we reach this method this should never happen + return null; + } + + BuilderPrism builderMapping = builderMappingPrism( method, ctx ); + if ( builderMapping == null && buildMethods.size() == 1 ) { + return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() ); + } + else { + String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME; + if ( builderMapping != null ) { + buildMethodPattern = builderMapping.buildMethod(); + } + for ( ExecutableElement buildMethod : buildMethods ) { + String methodName = buildMethod.getSimpleName().toString(); + if ( methodName.matches( buildMethodPattern ) ) { + return MethodReference.forMethodCall( methodName ); + } + } + + if ( builderMapping == null ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT, + buildMethodPattern, + builderType.getBuilder(), + builderType.getBuildingType(), + Strings.join( buildMethods, ", " ) + ); + } + else { + ctx.getMessager().printMessage( + method.getExecutable(), + builderMapping.mirror, + Message.BUILDER_NO_BUILD_METHOD_FOUND, + buildMethodPattern, + builderType.getBuilder(), + builderType.getBuildingType(), + Strings.join( buildMethods, ", " ) + ); + } + } + + return null; + } + + private static BuilderPrism builderMappingPrism(Method method, MappingBuilderContext ctx) { + BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); + if ( beanMapping != null && beanMapping.getBuilder() != null ) { + return beanMapping.getBuilder(); + } + return MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ).getBuilderPrism(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 25ed3beae0..1cfba42f2c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.internal.model.common; +import java.util.Collection; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; @@ -33,20 +34,20 @@ public class BuilderType { private final Type owningType; private final Type buildingType; private final ExecutableElement builderCreationMethod; - private final ExecutableElement buildMethod; + private final Collection buildMethods; private BuilderType( Type builder, Type owningType, Type buildingType, ExecutableElement builderCreationMethod, - ExecutableElement buildMethod + Collection buildMethods ) { this.builder = builder; this.owningType = owningType; this.buildingType = buildingType; this.builderCreationMethod = builderCreationMethod; - this.buildMethod = buildMethod; + this.buildMethods = buildMethods; } /** @@ -87,18 +88,17 @@ public ExecutableElement getBuilderCreationMethod() { } /** - * The name of the method that needs to be invoked on the builder to create the type being built. - * - * @return the name of the method that needs to be invoked on the type that is being built + * The build methods that can be invoked to create the type being built. + * @return the build methods that can be invoked to create the type being built */ - public String getBuildMethod() { - return buildMethod.getSimpleName().toString(); + public Collection getBuildMethods() { + return buildMethods; } public BuilderInfo asBuilderInfo() { return new BuilderInfo.Builder() .builderCreationMethod( this.builderCreationMethod ) - .buildMethod( this.buildMethod ) + .buildMethod( this.buildMethods ) .build(); } @@ -107,11 +107,6 @@ public static BuilderType create(BuilderInfo builderInfo, Type typeToBuild, Type if ( builderInfo == null ) { return null; } - ExecutableElement buildMethod = builderInfo.getBuildMethod(); - if ( !typeUtils.isAssignable( buildMethod.getReturnType(), typeToBuild.getTypeMirror() ) ) { - //TODO throw error - throw new IllegalArgumentException( "Build return type is not assignable" ); - } Type builder = typeFactory.getType( builderInfo.getBuilderCreationMethod().getReturnType() ); ExecutableElement builderCreationMethod = builderInfo.getBuilderCreationMethod(); @@ -133,7 +128,7 @@ else if ( typeUtils.isSameType( builder.getTypeMirror(), builderCreationOwner ) owner, typeToBuild, builderCreationMethod, - buildMethod + builderInfo.getBuildMethods() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 476898fd74..13e38cc5c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -55,11 +55,16 @@ import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.internal.util.Extractor; +import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.JavaStreamConstants; +import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.RoundContext; +import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.MoreThanOneBuilderCreationMethodException; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; @@ -73,8 +78,17 @@ */ public class TypeFactory { + private static final Extractor BUILDER_INFO_CREATION_METHOD_EXTRACTOR = + new Extractor() { + @Override + public String apply(BuilderInfo builderInfo) { + return builderInfo.getBuilderCreationMethod().toString(); + } + }; + private final Elements elementUtils; private final Types typeUtils; + private final FormattingMessager messager; private final RoundContext roundContext; private final TypeMirror iterableType; @@ -85,9 +99,10 @@ public class TypeFactory { private final Map implementationTypes = new HashMap(); private final Map importedQualifiedTypesBySimpleName = new HashMap(); - public TypeFactory(Elements elementUtils, Types typeUtils, RoundContext roundContext) { + public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; + this.messager = messager; this.roundContext = roundContext; iterableType = typeUtils.erasure( elementUtils.getTypeElement( Iterable.class.getCanonicalName() ).asType() ); @@ -502,9 +517,21 @@ private ImplementationType getImplementationType(TypeMirror mirror) { } private BuilderInfo findBuilder(TypeMirror type) { - return roundContext.getAnnotationProcessorContext() - .getBuilderProvider() - .findBuilderInfo( type, elementUtils, typeUtils ); + try { + return roundContext.getAnnotationProcessorContext() + .getBuilderProvider() + .findBuilderInfo( type, elementUtils, typeUtils ); + } + catch ( MoreThanOneBuilderCreationMethodException ex ) { + messager.printMessage( + typeUtils.asElement( type ), + Message.BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD, + type, + Strings.join( ex.getBuilderInfo(), ", ", BUILDER_INFO_CREATION_METHOD_EXTRACTOR ) + ); + } + + return null; } private TypeMirror getComponentType(TypeMirror mirror) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index e3580de65e..a181c3a995 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -25,6 +25,7 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.prism.BeanMappingPrism; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -42,6 +43,7 @@ public class BeanMapping { private final ReportingPolicyPrism reportingPolicy; private final boolean ignoreByDefault; private final List ignoreUnmappedSourceProperties; + private final BuilderPrism builder; /** * creates a mapping for inheritance. Will set ignoreByDefault to false. @@ -55,7 +57,8 @@ public static BeanMapping forInheritance( BeanMapping map ) { map.nullValueMappingStrategy, map.reportingPolicy, false, - map.ignoreUnmappedSourceProperties + map.ignoreUnmappedSourceProperties, + map.builder ); } @@ -74,9 +77,15 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem : NullValueMappingStrategyPrism.valueOf( beanMapping.nullValueMappingStrategy() ); boolean ignoreByDefault = beanMapping.ignoreByDefault(); + BuilderPrism builderMapping = null; + if ( beanMapping.values.builder() != null ) { + builderMapping = beanMapping.builder(); + } + if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() && beanMapping.ignoreUnmappedSourceProperties().isEmpty() - && ( nullValueMappingStrategy == null ) && !ignoreByDefault ) { + && ( nullValueMappingStrategy == null ) && !ignoreByDefault + && builderMapping == null ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); } @@ -94,7 +103,8 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem nullValueMappingStrategy, null, ignoreByDefault, - beanMapping.ignoreUnmappedSourceProperties() + beanMapping.ignoreUnmappedSourceProperties(), + builderMapping ); } @@ -105,17 +115,18 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem * @return bean mapping that needs to be used for Mappings */ public static BeanMapping forForgedMethods() { - return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false, Collections.emptyList() ); + return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false, Collections.emptyList(), null ); } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, - List ignoreUnmappedSourceProperties) { + List ignoreUnmappedSourceProperties, BuilderPrism builder) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; this.reportingPolicy = reportingPolicy; this.ignoreByDefault = ignoreByDefault; this.ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties; + this.builder = builder; } public SelectionParameters getSelectionParameters() { @@ -137,4 +148,8 @@ public boolean isignoreByDefault() { public List getIgnoreUnmappedSourceProperties() { return ignoreUnmappedSourceProperties; } + + public BuilderPrism getBuilder() { + return builder; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java index c07d5c3714..5b2a6fb7dc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java @@ -24,6 +24,7 @@ import org.mapstruct.AfterMapping; import org.mapstruct.BeanMapping; import org.mapstruct.BeforeMapping; +import org.mapstruct.Builder; import org.mapstruct.Context; import org.mapstruct.DecoratedWith; import org.mapstruct.InheritConfiguration; @@ -71,6 +72,7 @@ @GeneratePrism(value = ValueMapping.class, publicAccess = true), @GeneratePrism(value = ValueMappings.class, publicAccess = true), @GeneratePrism(value = Context.class, publicAccess = true), + @GeneratePrism(value = Builder.class, publicAccess = true), // external types @GeneratePrism(value = XmlElementDecl.class, publicAccess = true), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 07e0e1a908..70ef02e45f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -64,6 +64,7 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir this.typeFactory = new TypeFactory( processingEnvironment.getElementUtils(), delegatingTypes, + messager, roundContext ); this.options = options; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 4576015383..d7bb90260b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -28,6 +28,7 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; import org.mapstruct.ap.internal.prism.MapperConfigPrism; @@ -238,6 +239,18 @@ public boolean isDisableSubMappingMethodsGeneration() { return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation } + public BuilderPrism getBuilderPrism() { + if ( mapperPrism.values.builder() != null ) { + return mapperPrism.builder(); + } + else if ( mapperConfigPrism != null && mapperConfigPrism.values.builder() != null ) { + return mapperConfigPrism.builder(); + } + else { + return null; + } + } + public DeclaredType config() { return config; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 0bb6b788fd..de257c2e6e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -100,6 +100,10 @@ public enum Message { GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible parameterless constructor." ), + BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), + BUILDER_NO_BUILD_METHOD_FOUND("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\".", Diagnostic.Kind.ERROR ), + BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\". Consider to add @Builder in order to select the correct build method.", Diagnostic.Kind.ERROR ), + RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), RETRIEVAL_VOID_MAPPING_METHOD( "Can't generate mapping method with return type void." ), diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java index 9e6157688d..2be9c01fb0 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.spi; +import java.util.Collection; import javax.lang.model.element.ExecutableElement; /** @@ -28,11 +29,11 @@ public class BuilderInfo { private final ExecutableElement builderCreationMethod; - private final ExecutableElement buildMethod; + private final Collection buildMethods; - private BuilderInfo(ExecutableElement builderCreationMethod, ExecutableElement buildMethod) { + private BuilderInfo(ExecutableElement builderCreationMethod, Collection buildMethods) { this.builderCreationMethod = builderCreationMethod; - this.buildMethod = buildMethod; + this.buildMethods = buildMethods; } /** @@ -50,18 +51,18 @@ public ExecutableElement getBuilderCreationMethod() { } /** - * The method that can be used to build the type being built. - * This should be a {@code public} method within the builder itself + * The methods that can be used to build the type being built. + * This should be {@code public} methods within the builder itself * * @return the build method for the type */ - public ExecutableElement getBuildMethod() { - return buildMethod; + public Collection getBuildMethods() { + return buildMethods; } public static class Builder { private ExecutableElement builderCreationMethod; - private ExecutableElement buildMethod; + private Collection buildMethods; /** * @see BuilderInfo#getBuilderCreationMethod() @@ -72,10 +73,10 @@ public Builder builderCreationMethod(ExecutableElement method) { } /** - * @see BuilderInfo#getBuildMethod() + * @see BuilderInfo#getBuildMethods() */ - public Builder buildMethod(ExecutableElement method) { - this.buildMethod = method; + public Builder buildMethod(Collection methods) { + this.buildMethods = methods; return this; } @@ -87,10 +88,13 @@ public BuilderInfo build() { if ( builderCreationMethod == null ) { throw new IllegalArgumentException( "Builder creation method is mandatory" ); } - else if ( buildMethod == null ) { - throw new IllegalArgumentException( "Build method is mandatory" ); + else if ( buildMethods == null ) { + throw new IllegalArgumentException( "Build methods are mandatory" ); } - return new BuilderInfo( builderCreationMethod, buildMethod ); + else if ( buildMethods.isEmpty() ) { + throw new IllegalArgumentException( "Build methods must not be empty" ); + } + return new BuilderInfo( builderCreationMethod, buildMethods ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index 96c3375433..fb48fcce6b 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -40,6 +40,8 @@ public interface BuilderProvider { * * @throws TypeHierarchyErroneousException if the type that needs to be visited is not ready yet, this signals the * MapStruct processor to postpone the generation of the mappers to the next round + * @throws MoreThanOneBuilderCreationMethodException if {@code type} has more than one method that can create the + * builder */ BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 75b83f55ad..365efa02f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -18,6 +18,9 @@ */ package org.mapstruct.ap.spi; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.regex.Pattern; import javax.lang.model.element.ExecutableElement; @@ -141,17 +144,22 @@ public TypeElement visitType(TypeElement e, Void p) { *

      * The default implementation iterates over all the methods in {@code typeElement} and uses * {@link DefaultBuilderProvider#isPossibleBuilderCreationMethod(ExecutableElement, TypeElement, Types)} and - * {@link DefaultBuilderProvider#findBuildMethod(TypeElement, TypeElement, Types)} to create the + * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement, Types)} to create the * {@link BuilderInfo}. *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the * {@code typeElement} should be ignored. + *

      + * In case there are multiple {@link BuilderInfo} then a {@link MoreThanOneBuilderCreationMethodException} is + * thrown. * * @param typeElement the type element for which a builder searched * @param elements the util elements that can be used for operating on the type element * @param types the util types that can be used for operation on {@link TypeMirror}(s) * * @return the {@link BuilderInfo} or {@code null} if no builder was found for the type + * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement, Types)} + * @throws MoreThanOneBuilderCreationMethodException if there are multiple builder creation methods */ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { if ( shouldIgnore( typeElement ) ) { @@ -159,18 +167,28 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements } List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); + List builderInfo = new ArrayList(); for ( ExecutableElement method : methods ) { if ( isPossibleBuilderCreationMethod( method, typeElement, types ) ) { TypeElement builderElement = getTypeElement( method.getReturnType() ); - ExecutableElement buildMethod = findBuildMethod( builderElement, typeElement, types ); - if ( buildMethod != null ) { - return new BuilderInfo.Builder() + Collection buildMethods = findBuildMethods( builderElement, typeElement, types ); + if ( !buildMethods.isEmpty() ) { + builderInfo.add( new BuilderInfo.Builder() .builderCreationMethod( method ) - .buildMethod( buildMethod ) - .build(); + .buildMethod( buildMethods ) + .build() + ); } } } + + if ( builderInfo.size() == 1 ) { + return builderInfo.get( 0 ); + } + else if ( builderInfo.size() > 1 ) { + throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), builderInfo ); + } + return findBuilderInfo( typeElement.getSuperclass(), elements, types ); } @@ -207,30 +225,40 @@ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, Type *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the * {@code builderElement} should be ignored, i.e. not checked for build elements. - * + *

      + * If there are multiple methods that satisfy + * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement, Types)} and one of those methods + * is names {@code build} that that method would be considered as a build method. * @param builderElement the element for the builder * @param typeElement the element for the type that is being built * @param types the util types tat can be used for operations on {@link TypeMirror}(s) * * @return the build method for the {@code typeElement} if it exists, or {@code null} if it does not + * {@code build} */ - protected ExecutableElement findBuildMethod(TypeElement builderElement, TypeElement typeElement, Types types) { + protected Collection findBuildMethods(TypeElement builderElement, TypeElement typeElement, + Types types) { if ( shouldIgnore( builderElement ) ) { - return null; + return Collections.emptyList(); } List builderMethods = ElementFilter.methodsIn( builderElement.getEnclosedElements() ); + List buildMethods = new ArrayList(); for ( ExecutableElement buildMethod : builderMethods ) { if ( isBuildMethod( buildMethod, typeElement, types ) ) { - return buildMethod; + buildMethods.add( buildMethod ); } } - return findBuildMethod( - getTypeElement( builderElement.getSuperclass() ), - typeElement, - types - ); + if ( buildMethods.isEmpty() ) { + return findBuildMethods( + getTypeElement( builderElement.getSuperclass() ), + typeElement, + types + ); + } + + return buildMethods; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java b/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java new file mode 100644 index 0000000000..8d1038aa04 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java @@ -0,0 +1,49 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.spi; + +import java.util.List; +import javax.lang.model.type.TypeMirror; + +/** + * Indicates that a type has too many builder creation methods. + * This exception can be used to signal the MapStruct processor that more than one builder creation method was found. + * + * @author Filip Hrisafov + */ +public class MoreThanOneBuilderCreationMethodException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + private final TypeMirror type; + private final List builderCreationMethods; + + public MoreThanOneBuilderCreationMethodException(TypeMirror type, List builderCreationMethods) { + this.type = type; + this.builderCreationMethods = builderCreationMethods; + } + + public TypeMirror getType() { + return type; + } + + public List getBuilderInfo() { + return builderCreationMethods; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java new file mode 100644 index 0000000000..79eb4de38e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builder.multiple.build.Process; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = BuilderMapperConfig.class) +public interface BuilderConfigDefinedMapper { + + BuilderConfigDefinedMapper INSTANCE = Mappers.getMapper( BuilderConfigDefinedMapper.class ); + + Process map(Source source); + + @BeanMapping(builder = @Builder(buildMethod = "wrongCreate")) + Process wrongMap(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java new file mode 100644 index 0000000000..85e497ce25 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java @@ -0,0 +1,39 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builder.multiple.build.Process; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(builder = @Builder(buildMethod = "create")) +public interface BuilderDefinedMapper { + + BuilderDefinedMapper INSTANCE = Mappers.getMapper( BuilderDefinedMapper.class ); + + Process map(Source source); + + @BeanMapping(builder = @Builder(buildMethod = "wrongCreate")) + Process wrongMap(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java new file mode 100644 index 0000000000..90f69a1497 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java @@ -0,0 +1,29 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.Builder; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(builder = @Builder(buildMethod = "create")) +public interface BuilderMapperConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java new file mode 100644 index 0000000000..ce39c7e367 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface DefaultBuildMethodMapper { + + DefaultBuildMethodMapper INSTANCE = Mappers.getMapper( DefaultBuildMethodMapper.class ); + + Task map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java new file mode 100644 index 0000000000..dedad6f2d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builder.multiple.build.Process; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousMoreThanOneBuildMethodMapper { + + Process map(Source source); + + @BeanMapping(builder = @Builder(buildMethod = "missingBuild")) + Process map2(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java new file mode 100644 index 0000000000..a7ff63573d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java @@ -0,0 +1,32 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builder.multiple.build.Process; + +/** + * @author Filip Hrisafov + */ +@Mapper(builder = @Builder(buildMethod = "mapperBuild")) +public interface ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper { + + Process map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java new file mode 100644 index 0000000000..12bd0dd635 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -0,0 +1,174 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.builder.multiple.build.Process; +import org.mapstruct.ap.test.builder.multiple.builder.Case; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1479") +@WithClasses({ + Process.class, + Case.class, + Task.class, + Source.class +}) +public class MultipleBuilderMapperTest { + + @WithClasses({ + ErroneousMoreThanOneBuildMethodMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMoreThanOneBuildMethodMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 32, + messageRegExp = "No build method \"build\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + + "for \".*\\.multiple\\.build\\.Process\"\\. " + + "Found methods: " + + "\".*wrongCreate\\(\\) ?, " + + ".*create\\(\\) ?\"\\. " + + "Consider to add @Builder in order to select the correct build method." + ), + @Diagnostic( + type = ErroneousMoreThanOneBuildMethodMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + messageRegExp = "No build method \"missingBuild\" found " + + "in \".*\\.multiple\\.build\\.Process\\.Builder\" " + + "for \".*\\.multiple\\.build\\.Process\"\\. " + + "Found methods: " + + "\".*wrongCreate\\(\\) ?, " + + ".*create\\(\\) ?\"\\." + ) + }) + @Test + public void moreThanOneBuildMethod() { + } + + @WithClasses({ + ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 31, + messageRegExp = + "No build method \"mapperBuild\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + + "for \".*\\.multiple\\.build\\.Process\"\\. " + + "Found methods: " + + "\".*wrongCreate\\(\\) ?, " + + ".*create\\(\\) ?\"\\." + ) + }) + @Test + public void moreThanOneBuildMethodDefinedOnMapper() { + } + + @WithClasses({ + BuilderDefinedMapper.class + }) + @Test + public void builderMappingDefined() { + Process map = BuilderDefinedMapper.INSTANCE.map( new Source( "map" ) ); + Process wrongMap = BuilderDefinedMapper.INSTANCE.wrongMap( new Source( "wrongMap" ) ); + + assertThat( map.getBuildMethod() ).isEqualTo( "create" ); + assertThat( wrongMap.getBuildMethod() ).isEqualTo( "wrongCreate" ); + } + + @WithClasses({ + BuilderMapperConfig.class, + BuilderConfigDefinedMapper.class + }) + @Test + public void builderMappingMapperConfigDefined() { + Process map = BuilderConfigDefinedMapper.INSTANCE.map( new Source( "map" ) ); + Process wrongMap = BuilderConfigDefinedMapper.INSTANCE.wrongMap( new Source( "wrongMap" ) ); + + assertThat( map.getBuildMethod() ).isEqualTo( "create" ); + assertThat( wrongMap.getBuildMethod() ).isEqualTo( "wrongCreate" ); + } + + @WithClasses({ + TooManyBuilderCreationMethodsMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + // We have 2 diagnostics, as we don't do caching of the types, so a type is processed multiple types + diagnostics = { + @Diagnostic( + type = Case.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 24, + messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + + "Found methods: " + + "\".*wrongBuilder\\(\\) ?, " + + ".*builder\\(\\) ?\"\\. " + + "Builder will not be used\\. Consider implementing a custom BuilderProvider SPI\\." + ), + @Diagnostic( + type = Case.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 24, + messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + + "Found methods: " + + "\".*wrongBuilder\\(\\) ?, " + + ".*builder\\(\\) ?\"\\. " + + "Builder will not be used\\. Consider implementing a custom BuilderProvider SPI\\." + ) + }) + @Test + public void tooManyBuilderCreationMethods() { + Case caseTarget = TooManyBuilderCreationMethodsMapper.INSTANCE.map( new Source( "test" ) ); + + assertThat( caseTarget ).isNotNull(); + assertThat( caseTarget.getName() ).isEqualTo( "test" ); + assertThat( caseTarget.getBuilderCreationMethod() ).isNull(); + assertThat( caseTarget.getBuildMethod() ).isEqualTo( "constructor" ); + } + + @WithClasses( { + DefaultBuildMethodMapper.class + } ) + @Test + public void defaultBuildMethod() { + Task task = DefaultBuildMethodMapper.INSTANCE.map( new Source( "test" ) ); + + assertThat( task ).isNotNull(); + assertThat( task.getName() ).isEqualTo( "test" ); + assertThat( task.getBuilderCreationMethod() ).isEqualTo( "builder" ); + assertThat( task.getBuildMethod() ).isEqualTo( "build" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java new file mode 100644 index 0000000000..93c0ab59f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String name; + + public Source(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java new file mode 100644 index 0000000000..234fe6e851 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java @@ -0,0 +1,84 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +/** + * @author Filip Hrisafov + */ +public class Task { + + private final String builderCreationMethod; + private final String buildMethod; + private String name; + + public Task() { + this.builderCreationMethod = null; + this.buildMethod = "constructor"; + } + + public Task(Builder builder, String buildMethod) { + this.builderCreationMethod = builder.builderCreationMethod; + this.buildMethod = buildMethod; + this.name = builder.name; + } + + public String getBuilderCreationMethod() { + return builderCreationMethod; + } + + public String getBuildMethod() { + return buildMethod; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static Builder builder() { + return new Builder( "builder" ); + } + + public static class Builder { + + private String name; + private String builderCreationMethod; + + protected Builder(String builderCreationMethod) { + this.builderCreationMethod = builderCreationMethod; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Task wrongCreate() { + return new Task( this, "wrongCreate" ); + } + + public Task build() { + return new Task( this, "build" ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java new file mode 100644 index 0000000000..1b935eb2ef --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java @@ -0,0 +1,34 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builder.multiple.builder.Case; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface TooManyBuilderCreationMethodsMapper { + + TooManyBuilderCreationMethodsMapper INSTANCE = Mappers.getMapper( TooManyBuilderCreationMethodsMapper.class ); + + Case map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java new file mode 100644 index 0000000000..939249f531 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java @@ -0,0 +1,84 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple.build; + +/** + * @author Filip Hrisafov + */ +public class Process { + + private final String builderCreationMethod; + private final String buildMethod; + private String name; + + public Process() { + this.builderCreationMethod = null; + this.buildMethod = "constructor"; + } + + public Process(Builder builder, String buildMethod) { + this.builderCreationMethod = builder.builderCreationMethod; + this.buildMethod = buildMethod; + this.name = builder.name; + } + + public String getBuilderCreationMethod() { + return builderCreationMethod; + } + + public String getBuildMethod() { + return buildMethod; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static Builder builder() { + return new Builder( "builder" ); + } + + public static class Builder { + + private String name; + private String builderCreationMethod; + + protected Builder(String builderCreationMethod) { + this.builderCreationMethod = builderCreationMethod; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Process wrongCreate() { + return new Process( this, "wrongCreate" ); + } + + public Process create() { + return new Process( this, "create" ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java new file mode 100644 index 0000000000..a4251abd5f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java @@ -0,0 +1,83 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.builder.multiple.builder; + +/** + * @author Filip Hrisafov + */ +public class Case { + + private final String builderCreationMethod; + private final String buildMethod; + private String name; + + public Case() { + this.builderCreationMethod = null; + this.buildMethod = "constructor"; + } + + public Case(Builder builder, String buildMethod) { + this.builderCreationMethod = builder.builderCreationMethod; + this.buildMethod = buildMethod; + this.name = builder.name; + } + + public String getBuilderCreationMethod() { + return builderCreationMethod; + } + + public String getBuildMethod() { + return buildMethod; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static Builder wrongBuilder() { + return new Builder( "wrongBuilder" ); + } + + public static Builder builder() { + return new Builder( "builder" ); + } + + public static class Builder { + + private String name; + private String builderCreationMethod; + + protected Builder(String builderCreationMethod) { + this.builderCreationMethod = builderCreationMethod; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Case create() { + return new Case( this, "create" ); + } + } +} From 616aaa986d473baedc8849a156616e7431673a43 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 12 Jul 2018 23:30:37 +0200 Subject: [PATCH 0256/1006] #1479 Fix typos in the Javadoc --- core-common/src/main/java/org/mapstruct/Builder.java | 2 +- core-common/src/main/java/org/mapstruct/Mapper.java | 4 ++-- core-common/src/main/java/org/mapstruct/MapperConfig.java | 4 ++-- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core-common/src/main/java/org/mapstruct/Builder.java b/core-common/src/main/java/org/mapstruct/Builder.java index 68d7eb9fce..5f37028d8e 100644 --- a/core-common/src/main/java/org/mapstruct/Builder.java +++ b/core-common/src/main/java/org/mapstruct/Builder.java @@ -37,7 +37,7 @@ public @interface Builder { /** - * The name of the build method that needs to be invoked on the builder to create the type being build + * The name of the build method that needs to be invoked on the builder to create the type to be build * * @return the method that needs to tbe invoked on the builder */ diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index a4a19ba500..011c83a1f6 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -210,8 +210,8 @@ * NOTE: In case no builder is defined here, in {@link BeanMapping} or {@link MapperConfig} and there is a single * build method, then that method would be used. *

      - * If the builder is defined and there is a single method that does not match the name of the finisher than - * a compile error will occurs + * If the builder is defined and there is a single method that does not match the name of the build method then + * a compile error will occur * * @return the builder information * diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index 45a95a1bf3..857320b3aa 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -198,8 +198,8 @@ MappingInheritanceStrategy mappingInheritanceStrategy() * NOTE: In case no builder is defined here, in {@link BeanMapping} or {@link Mapper} and there is a single * build method, then that method would be used. *

      - * If the builder is defined and there is a single method that does not match the name of the finisher than - * a compile error will occurs + * If the builder is defined and there is a single method that does not match the name of the build method then + * a compile error will occur * * @return the builder information * diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 1a2d481dcb..1620564d1c 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -639,8 +639,8 @@ The default implementation of the `BuilderProvider` assumes the following: So for example `Person` has a public static method that returns `PersonBuilder`. * The builder type has a parameterless public method (build method) that returns the type being build In our example `PersonBuilder` has a method returning `Person`. -* In case there are multiple build methods, MapStruct will look for a method called `build` if such methods exists -than this would be used, otherwise a compilation error would be created. +* In case there are multiple build methods, MapStruct will look for a method called `build`, if such method exists +then this would be used, otherwise a compilation error would be created. * A specific build method can be defined by using `@Builder` within: `@BeanMapping`, `@Mapper` or `@MapperConfig` * In case there are multiple builder creation methods that satisfy the above conditions then a `MoreThanOneBuilderCreationMethodException` will be thrown from the `DefaultBuilderProvider` SPI. From 58a2aa94bb8138d0bf04f85f1784ffecc3ddf07c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 14 Jul 2018 16:27:10 +0200 Subject: [PATCH 0257/1006] #1482 allowing generic self references in types when matching --- .../ap/internal/model/MethodReference.java | 9 +++ .../internal/model/source/MethodMatcher.java | 28 ++++--- .../ap/internal/model/MethodReference.ftl | 2 +- .../ap/test/bugs/_1482/BigDecimalWrapper.java | 35 +++++++++ .../ap/test/bugs/_1482/Issue1482Test.java | 75 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1482/Source.java | 41 ++++++++++ .../mapstruct/ap/test/bugs/_1482/Source2.java | 43 +++++++++++ .../ap/test/bugs/_1482/SourceEnum.java | 35 +++++++++ .../test/bugs/_1482/SourceTargetMapper.java | 40 ++++++++++ .../mapstruct/ap/test/bugs/_1482/Target.java | 43 +++++++++++ .../test/bugs/_1482/TargetSourceMapper.java | 50 +++++++++++++ .../ap/test/bugs/_1482/ValueWrapper.java | 23 ++++++ 12 files changed, 413 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 003c196ab0..be5c6ba801 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -276,6 +276,15 @@ public List getParameterBindings() { return parameterBindings; } + public Type inferTypeWhenEnum( Type type ) { + if ( "java.lang.Enum".equals( type.getFullyQualifiedName() ) ) { + return type.getTypeParameters().get( 0 ); + } + else { + return type; + } + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 91cc151064..74925d0c82 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -263,14 +263,22 @@ public Boolean visitDeclared(DeclaredType t, TypeMirror p) { // (type args are checked later). if ( p.getKind() == TypeKind.DECLARED ) { DeclaredType t1 = (DeclaredType) p; - if ( assignabilityMatches( t, t1 ) - && t.getTypeArguments().size() == t1.getTypeArguments().size() ) { - for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { - if ( !visit( t.getTypeArguments().get( i ), t1.getTypeArguments().get( i ) ) ) { - return Boolean.FALSE; + if ( rawAssignabilityMatches( t, t1 ) ) { + if ( t.getTypeArguments().size() == t1.getTypeArguments().size() ) { + // compare type var side by side + for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { + if ( !visit( t.getTypeArguments().get( i ), t1.getTypeArguments().get( i ) ) ) { + return Boolean.FALSE; + } } + return Boolean.TRUE; + } + else { + // return true (e.g. matching Enumeration with an enumeration E) + // but do not try to line up raw type arguments with types that do have arguments. + return assignability == Assignability.VISITED_ASSIGNABLE_TO ? + !t1.getTypeArguments().isEmpty() : !t.getTypeArguments().isEmpty(); } - return Boolean.TRUE; } else { return Boolean.FALSE; @@ -284,12 +292,12 @@ else if ( p.getKind() == TypeKind.WILDCARD ) { } } - private boolean assignabilityMatches(DeclaredType visited, DeclaredType param) { + private boolean rawAssignabilityMatches(DeclaredType t1, DeclaredType t2) { if ( assignability == Assignability.VISITED_ASSIGNABLE_TO ) { - return typeUtils.isAssignable( toRawType( visited ), toRawType( param ) ); + return typeUtils.isAssignable( toRawType( t1 ), toRawType( t2 ) ); } else { - return typeUtils.isAssignable( toRawType( param ), toRawType( visited ) ); + return typeUtils.isAssignable( toRawType( t2 ), toRawType( t1 ) ); } } @@ -302,7 +310,7 @@ public Boolean visitTypeVariable(TypeVariable t, TypeMirror p) { if ( genericTypesMap.containsKey( t ) ) { // when already found, the same mapping should apply TypeMirror p1 = genericTypesMap.get( t ); - return typeUtils.isSameType( p, p1 ); + return typeUtils.isSubtype( p, p1 ); } else { // check if types are in bound diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 8f4a31ddc6..06c599c1c4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -48,7 +48,7 @@ <#list parameterBindings as param> <#if param.targetType> <#-- a class is passed on for casting, see @TargetType --> - <@includeModel object=ext.targetType raw=true/>.class<#t> + <@includeModel object=inferTypeWhenEnum( ext.targetType ) raw=true/>.class<#t> <#elseif param.mappingTarget> ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> <#elseif param.mappingContext> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java new file mode 100644 index 0000000000..b68d22acdb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import java.math.BigDecimal; + +public class BigDecimalWrapper implements ValueWrapper { + + private final BigDecimal value; + + public BigDecimalWrapper(BigDecimal value) { + this.value = value; + } + + @Override + public BigDecimal getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java new file mode 100644 index 0000000000..48d72e4b0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java @@ -0,0 +1,75 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import java.math.BigDecimal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Source.class, + Source2.class, + Target.class, + SourceEnum.class, + SourceTargetMapper.class, + TargetSourceMapper.class, + BigDecimalWrapper.class, + ValueWrapper.class +}) +@IssueKey(value = "1482") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1482Test { + + @Test + public void testForward() { + + Source source = new Source(); + source.setTest( SourceEnum.VAL1 ); + source.setWrapper( new BigDecimalWrapper( new BigDecimal( 5 ) ) ); + + Target target = SourceTargetMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getTest() ).isEqualTo( "value1" ); + assertThat( target.getBigDecimal() ).isEqualTo( new BigDecimal( 5 ) ); + + } + + @Test + public void testReverse() { + + Target target = new Target(); + target.setBigDecimal( new BigDecimal( 5 ) ); + target.setTest( "VAL1" ); + + Source2 source2 = TargetSourceMapper.INSTANCE.map( target ); + + assertThat( source2 ).isNotNull(); + assertThat( source2.getTest() ).isEqualTo( SourceEnum.VAL1 ); + assertThat( source2.getWrapper().getValue() ).isEqualTo( new BigDecimal( 5 ) ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java new file mode 100644 index 0000000000..82087751b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java @@ -0,0 +1,41 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +public class Source { + + private SourceEnum test; + private BigDecimalWrapper wrapper; + + public SourceEnum getTest() { + return test; + } + + public void setTest(SourceEnum test) { + this.test = test; + } + + public BigDecimalWrapper getWrapper() { + return wrapper; + } + + public void setWrapper(BigDecimalWrapper wrapper) { + this.wrapper = wrapper; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java new file mode 100644 index 0000000000..3423132cea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import java.math.BigDecimal; + +public class Source2 { + + private Enum test; + private ValueWrapper wrapper; + + public Enum getTest() { + return test; + } + + public void setTest(Enum test) { + this.test = test; + } + + public ValueWrapper getWrapper() { + return wrapper; + } + + public void setWrapper(ValueWrapper wrapper) { + this.wrapper = wrapper; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java new file mode 100644 index 0000000000..58d0652494 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java @@ -0,0 +1,35 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +public enum SourceEnum { + + VAL1( "value1" ), + VAL2( "value2" ); + + private final String val; + + SourceEnum(String val) { + this.val = val; + } + + public String toString() { + return val; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java new file mode 100644 index 0000000000..194587b155 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java @@ -0,0 +1,40 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class SourceTargetMapper { + + public static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping( target = "bigDecimal", source = "wrapper" ) + abstract Target map(Source source); + + protected String map(Enum e) { + return e.toString(); + } + + protected T map(ValueWrapper in) { + return in.getValue(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java new file mode 100644 index 0000000000..bb4d7a75c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java @@ -0,0 +1,43 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import java.math.BigDecimal; + +public class Target { + + private String test; + private BigDecimal bigDecimal; + + public String getTest() { + return test; + } + + public void setTest(String test) { + this.test = test; + } + + public BigDecimal getBigDecimal() { + return bigDecimal; + } + + public void setBigDecimal(BigDecimal bigDecimal) { + this.bigDecimal = bigDecimal; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java new file mode 100644 index 0000000000..3ad2af79d1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java @@ -0,0 +1,50 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class TargetSourceMapper { + + public static final TargetSourceMapper INSTANCE = Mappers.getMapper( TargetSourceMapper.class ); + + @Mapping(target = "wrapper", source = "bigDecimal") + abstract Source2 map(Target target); + + protected > Enum map(String in, @TargetType Classclz ) { + if ( clz.isAssignableFrom( SourceEnum.class )) { + return (Enum) SourceEnum.valueOf( in ); + } + return null; + } + + protected ValueWrapper map(T in) { + if ( in instanceof BigDecimal ) { + return (ValueWrapper) new BigDecimalWrapper( (BigDecimal) in ); + + } + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java new file mode 100644 index 0000000000..2ae62cee57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java @@ -0,0 +1,23 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1482; + +public interface ValueWrapper { + T getValue(); +} From 347a436cda422df04d6dcbcbe2e5f9f0c9321736 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Jul 2018 10:56:06 +0200 Subject: [PATCH 0258/1006] #1382 Change module for java.annotation.Generated in the documentation closes #1382 --- .../main/asciidoc/mapstruct-reference-guide.asciidoc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 1620564d1c..df25b40388 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -271,16 +271,22 @@ If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, === Using MapStruct on Java 9 -MapStruct can be used with Java 9, but as that Java version has not been finalized yet, support for it is experimental. +MapStruct can be used with Java 9 (JPMS), support for it is experimental. A core theme of Java 9 is the modularization of the JDK. One effect of this is that a specific module needs to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. -To allow usage of the `@Generated` annotation the module _java.annotations.common_ must be enabled. When using Maven, this can be done like this: +To allow usage of the `@Generated` annotation the module _java.xml.ws.annotation_ must be enabled. When using Maven, this can be done like this: - export MAVEN_OPTS="--add-modules java.annotations.common" + export MAVEN_OPTS="--add-modules java.xml.ws.annotation" If the `@Generated` annotation is not available, MapStruct will detect this situation and not add it to generated mappers. +[NOTE] +===== +In Java 9 `java.annotation.processing.Generated` was added, which is considered as a general purpose annotation for any code generators +and is part of the `java.compiler` module. Support for it is planned within https://github.com/mapstruct/mapstruct/issues/1551[#1551] +===== + [[defining-mapper]] == Defining a mapper From b35126e60948a69b82c37266d58c752cbeb1fcf7 Mon Sep 17 00:00:00 2001 From: MapStruct Team Date: Sat, 14 Jul 2018 15:44:26 +0200 Subject: [PATCH 0259/1006] #1411 Update copyright header on all files * Use new shorter copyright header without a year * Use SLASHSTAR_STYLE for Java files --- LICENSE.txt | 17 ++------------- build-config/pom.xml | 17 ++------------- core-common/pom.xml | 17 ++------------- .../main/java/org/mapstruct/AfterMapping.java | 19 +++-------------- .../main/java/org/mapstruct/BeanMapping.java | 19 +++-------------- .../java/org/mapstruct/BeforeMapping.java | 19 +++-------------- .../src/main/java/org/mapstruct/Builder.java | 19 +++-------------- .../mapstruct/CollectionMappingStrategy.java | 19 +++-------------- .../src/main/java/org/mapstruct/Context.java | 21 ++++--------------- .../java/org/mapstruct/DecoratedWith.java | 21 ++++--------------- .../org/mapstruct/InheritConfiguration.java | 19 +++-------------- .../InheritInverseConfiguration.java | 19 +++-------------- .../java/org/mapstruct/InjectionStrategy.java | 19 +++-------------- .../java/org/mapstruct/IterableMapping.java | 19 +++-------------- .../main/java/org/mapstruct/MapMapping.java | 19 +++-------------- .../src/main/java/org/mapstruct/Mapper.java | 19 +++-------------- .../main/java/org/mapstruct/MapperConfig.java | 19 +++-------------- .../java/org/mapstruct/MappingConstants.java | 19 +++-------------- .../mapstruct/MappingInheritanceStrategy.java | 19 +++-------------- .../java/org/mapstruct/MappingTarget.java | 19 +++-------------- .../src/main/java/org/mapstruct/Named.java | 19 +++-------------- .../org/mapstruct/NullValueCheckStrategy.java | 19 +++-------------- .../mapstruct/NullValueMappingStrategy.java | 19 +++-------------- .../java/org/mapstruct/ObjectFactory.java | 19 +++-------------- .../main/java/org/mapstruct/Qualifier.java | 19 +++-------------- .../java/org/mapstruct/ReportingPolicy.java | 19 +++-------------- .../main/java/org/mapstruct/TargetType.java | 19 +++-------------- .../java/org/mapstruct/factory/Mappers.java | 19 +++-------------- .../org/mapstruct/factory/package-info.java | 19 +++-------------- .../main/java/org/mapstruct/package-info.java | 19 +++-------------- .../java/org/mapstruct/util/Experimental.java | 19 +++-------------- .../org/mapstruct/factory/MappersTest.java | 19 +++-------------- .../factory/PackagePrivateMapper.java | 19 +++-------------- .../factory/PackagePrivateMapperImpl.java | 19 +++-------------- .../java/org/mapstruct/test/model/Foo.java | 19 +++-------------- .../org/mapstruct/test/model/FooImpl.java | 19 +++-------------- .../test/model/SomeClass$FooImpl.java | 19 +++-------------- .../model/SomeClass$NestedClass$FooImpl.java | 19 +++-------------- .../org/mapstruct/test/model/SomeClass.java | 19 +++-------------- core-jdk8/pom.xml | 17 ++------------- .../src/main/java/org/mapstruct/Mapping.java | 19 +++-------------- .../src/main/java/org/mapstruct/Mappings.java | 19 +++-------------- .../main/java/org/mapstruct/ValueMapping.java | 19 +++-------------- .../java/org/mapstruct/ValueMappings.java | 19 +++-------------- core/pom.xml | 17 ++------------- core/src/main/java/org/mapstruct/Mapping.java | 19 +++-------------- .../src/main/java/org/mapstruct/Mappings.java | 19 +++-------------- .../main/java/org/mapstruct/ValueMapping.java | 19 +++-------------- .../java/org/mapstruct/ValueMappings.java | 19 +++-------------- distribution/pom.xml | 19 +++-------------- distribution/src/main/assembly/dist.xml | 17 ++------------- documentation/pom.xml | 17 ++------------- etc/license.txt | 17 ++------------- integrationtest/pom.xml | 17 ++------------- .../itest/tests/AutoValueBuilderTest.java | 19 +++-------------- .../org/mapstruct/itest/tests/CdiTest.java | 19 +++-------------- .../itest/tests/ExternalBeanJarTest.java | 19 +++-------------- .../itest/tests/FreeBuilderBuilderTest.java | 19 +++-------------- .../tests/FullFeatureCompilationTest.java | 19 +++-------------- .../itest/tests/ImmutablesBuilderTest.java | 19 +++-------------- .../org/mapstruct/itest/tests/Java8Test.java | 19 +++-------------- .../org/mapstruct/itest/tests/JaxbTest.java | 19 +++-------------- .../org/mapstruct/itest/tests/Jsr330Test.java | 19 +++-------------- .../itest/tests/LombokBuilderTest.java | 19 +++-------------- .../itest/tests/NamingStrategyTest.java | 19 +++-------------- .../org/mapstruct/itest/tests/SimpleTest.java | 19 +++-------------- .../org/mapstruct/itest/tests/SpringTest.java | 19 +++-------------- .../itest/tests/SuperTypeGenerationTest.java | 19 +++-------------- .../itest/tests/TargetTypeGenerationTest.java | 19 +++-------------- .../itest/testutil/runner/ProcessorSuite.java | 19 +++-------------- .../testutil/runner/ProcessorSuiteRunner.java | 19 +++-------------- .../itest/testutil/runner/Toolchain.java | 19 +++-------------- .../itest/testutil/runner/xml/Toolchains.java | 19 +++-------------- .../resources/autoValueBuilderTest/pom.xml | 17 ++------------- .../mapstruct/itest/auto/value/Address.java | 19 +++-------------- .../itest/auto/value/AddressDto.java | 19 +++-------------- .../mapstruct/itest/auto/value/Person.java | 19 +++-------------- .../mapstruct/itest/auto/value/PersonDto.java | 19 +++-------------- .../itest/auto/value/PersonMapper.java | 19 +++-------------- .../itest/auto/value/AutoValueMapperTest.java | 19 +++-------------- .../src/test/resources/cdiTest/pom.xml | 17 ++------------- .../cdi/DecoratedSourceTargetMapper.java | 19 +++-------------- .../java/org/mapstruct/itest/cdi/Source.java | 19 +++-------------- .../itest/cdi/SourceTargetMapper.java | 19 +++-------------- .../cdi/SourceTargetMapperDecorator.java | 19 +++-------------- .../java/org/mapstruct/itest/cdi/Target.java | 19 +++-------------- .../mapstruct/itest/cdi/other/DateMapper.java | 19 +++-------------- .../itest/cdi/CdiBasedMapperTest.java | 19 +++-------------- .../resources/externalbeanjar/beanjar/pom.xml | 17 ++------------- .../itest/externalbeanjar/Source.java | 19 +++-------------- .../itest/externalbeanjar/Target.java | 19 +++-------------- .../resources/externalbeanjar/mapper/pom.xml | 17 ++------------- .../externalbeanjar/Issue1121Mapper.java | 19 +++-------------- .../itest/externalbeanjar/ConversionTest.java | 19 +++-------------- .../test/resources/externalbeanjar/pom.xml | 17 ++------------- .../resources/freeBuilderBuilderTest/pom.xml | 17 ++------------- .../mapstruct/itest/freebuilder/Address.java | 19 +++-------------- .../itest/freebuilder/AddressDto.java | 19 +++-------------- .../mapstruct/itest/freebuilder/Person.java | 19 +++-------------- .../itest/freebuilder/PersonDto.java | 19 +++-------------- .../itest/freebuilder/PersonMapper.java | 19 +++-------------- .../freebuilder/FreeBuilderMapperTest.java | 19 +++-------------- .../test/resources/fullFeatureTest/pom.xml | 17 ++------------- .../mapstruct/itest/simple/AnimalTest.java | 19 +++-------------- .../immutablesBuilderTest/extras/pom.xml | 7 +++++++ .../immutablesBuilderTest/mapper/pom.xml | 7 +++++++ .../mapstruct/itest/immutables/Address.java | 19 +++-------------- .../itest/immutables/AddressDto.java | 19 +++-------------- .../mapstruct/itest/immutables/Person.java | 19 +++-------------- .../mapstruct/itest/immutables/PersonDto.java | 19 +++-------------- .../itest/immutables/PersonMapper.java | 19 +++-------------- .../immutables/ImmutablesMapperTest.java | 19 +++-------------- .../resources/immutablesBuilderTest/pom.xml | 17 ++------------- .../src/test/resources/java8Test/pom.xml | 17 ++------------- .../mapstruct/ap/test/bugs/_603/Source.java | 19 +++-------------- .../ap/test/bugs/_603/SourceTargetMapper.java | 19 +++-------------- .../_603/SourceTargetMapperDecorator.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_603/Target.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_636/Bar.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_636/Foo.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_636/Source.java | 19 +++-------------- .../bugs/_636/SourceTargetBaseMapper.java | 19 +++-------------- .../ap/test/bugs/_636/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_636/Target.java | 19 +++-------------- .../mapstruct/itest/java8/Java8Mapper.java | 19 +++-------------- .../org/mapstruct/itest/java8/Source.java | 19 +++-------------- .../org/mapstruct/itest/java8/Target.java | 19 +++-------------- .../ap/test/bugs/_603/Issue603Test.java | 19 +++-------------- .../ap/test/bugs/_636/Issue636Test.java | 19 +++-------------- .../itest/java8/Java8MapperTest.java | 19 +++-------------- .../src/test/resources/jaxbTest/pom.xml | 17 ++------------- .../org/mapstruct/itest/jaxb/JaxbMapper.java | 19 +++-------------- .../mapstruct/itest/jaxb/OrderDetailsDto.java | 19 +++-------------- .../org/mapstruct/itest/jaxb/OrderDto.java | 19 +++-------------- .../mapstruct/itest/jaxb/OrderStatusDto.java | 19 +++-------------- .../itest/jaxb/ShippingAddressDto.java | 19 +++-------------- .../itest/jaxb/SourceTargetMapper.java | 19 +++-------------- .../org/mapstruct/itest/jaxb/SubTypeDto.java | 19 +++-------------- .../mapstruct/itest/jaxb/SuperTypeDto.java | 19 +++-------------- .../src/main/resources/binding/binding.xjb | 19 +++-------------- .../src/main/resources/schema/test1.xsd | 17 ++------------- .../src/main/resources/schema/test2.xsd | 17 ++------------- .../src/main/resources/schema/underscores.xsd | 17 ++------------- .../itest/jaxb/JaxbBasedMapperTest.java | 19 +++-------------- .../src/test/resources/jsr330Test/pom.xml | 17 ++------------- .../jsr330/DecoratedSourceTargetMapper.java | 19 +++-------------- .../SecondDecoratedSourceTargetMapper.java | 19 +++-------------- .../SecondSourceTargetMapperDecorator.java | 19 +++-------------- .../org/mapstruct/itest/jsr330/Source.java | 19 +++-------------- .../itest/jsr330/SourceTargetMapper.java | 19 +++-------------- .../jsr330/SourceTargetMapperDecorator.java | 19 +++-------------- .../org/mapstruct/itest/jsr330/Target.java | 19 +++-------------- .../itest/jsr330/other/DateMapper.java | 19 +++-------------- .../itest/jsr330/Jsr330BasedMapperTest.java | 19 +++-------------- .../test/resources/lombokBuilderTest/pom.xml | 17 ++------------- .../org/mapstruct/itest/lombok/Address.java | 19 +++-------------- .../mapstruct/itest/lombok/AddressDto.java | 19 +++-------------- .../org/mapstruct/itest/lombok/Person.java | 19 +++-------------- .../org/mapstruct/itest/lombok/PersonDto.java | 19 +++-------------- .../itest/lombok/LombokMapperTest.java | 19 +++-------------- .../mapstruct/itest/lombok/PersonMapper.java | 19 +++-------------- .../test/resources/namingStrategyTest/pom.xml | 17 ++------------- .../namingStrategyTest/strategy/pom.xml | 17 ++------------- .../naming/CustomAccessorNamingStrategy.java | 19 +++-------------- .../namingStrategyTest/usage/pom.xml | 17 ++------------- .../mapstruct/itest/naming/GolfPlayer.java | 19 +++-------------- .../mapstruct/itest/naming/GolfPlayerDto.java | 19 +++-------------- .../itest/naming/GolfPlayerMapper.java | 19 +++-------------- .../mapstruct/itest/naming/NamingTest.java | 19 +++-------------- integrationtest/src/test/resources/pom.xml | 17 ++------------- .../src/test/resources/simpleTest/pom.xml | 17 ++------------- .../org/mapstruct/itest/simple/BaseType.java | 19 +++-------------- .../itest/simple/ReferencedCustomMapper.java | 19 +++-------------- .../mapstruct/itest/simple/SomeOtherType.java | 19 +++-------------- .../org/mapstruct/itest/simple/SomeType.java | 19 +++-------------- .../org/mapstruct/itest/simple/Source.java | 19 +++-------------- .../simple/SourceTargetAbstractMapper.java | 19 +++-------------- .../itest/simple/SourceTargetMapper.java | 19 +++-------------- .../org/mapstruct/itest/simple/Target.java | 19 +++-------------- .../itest/simple/YetAnotherType.java | 19 +++-------------- .../itest/simple/ConversionTest.java | 19 +++-------------- .../src/test/resources/springTest/pom.xml | 17 ++------------- .../spring/DecoratedSourceTargetMapper.java | 19 +++-------------- .../SecondDecoratedSourceTargetMapper.java | 19 +++-------------- .../SecondSourceTargetMapperDecorator.java | 19 +++-------------- .../org/mapstruct/itest/spring/Source.java | 19 +++-------------- .../itest/spring/SourceTargetMapper.java | 19 +++-------------- .../spring/SourceTargetMapperDecorator.java | 19 +++-------------- .../org/mapstruct/itest/spring/Target.java | 19 +++-------------- .../itest/spring/other/DateMapper.java | 19 +++-------------- .../itest/spring/SpringBasedMapperTest.java | 19 +++-------------- .../superTypeGenerationTest/generator/pom.xml | 7 +++++++ .../BaseGenerationProcessor.java | 19 +++-------------- .../itest/supertypegeneration/GenBase.java | 19 +++-------------- .../javax.annotation.processing.Processor | 17 ++------------- .../resources/superTypeGenerationTest/pom.xml | 17 ++------------- .../superTypeGenerationTest/usage/pom.xml | 7 +++++++ .../usage/AnotherOrderMapper.java | 19 +++-------------- .../supertypegeneration/usage/Order.java | 19 +++-------------- .../supertypegeneration/usage/OrderDto.java | 19 +++-------------- .../usage/OrderMapper.java | 19 +++-------------- .../usage/GeneratedBasesTest.java | 19 +++-------------- .../generator/pom.xml | 7 +++++++ .../DtoGenerationProcessor.java | 19 +++-------------- .../javax.annotation.processing.Processor | 17 ++------------- .../targetTypeGenerationTest/pom.xml | 17 ++------------- .../targetTypeGenerationTest/usage/pom.xml | 7 +++++++ .../targettypegeneration/usage/Order.java | 19 +++-------------- .../usage/OrderMapper.java | 19 +++-------------- .../usage/GeneratedTargetTypeTest.java | 19 +++-------------- parent/pom.xml | 20 +++++------------- pom.xml | 18 +++------------- processor/pom.xml | 17 ++------------- .../org/mapstruct/ap/MappingProcessor.java | 19 +++-------------- .../AbstractJavaTimeToStringConversion.java | 19 +++-------------- .../AbstractJodaTypeToStringConversion.java | 19 +++-------------- .../AbstractNumberToStringConversion.java | 19 +++-------------- .../BigDecimalToBigIntegerConversion.java | 19 +++-------------- .../BigDecimalToPrimitiveConversion.java | 19 +++-------------- .../BigDecimalToStringConversion.java | 19 +++-------------- .../BigDecimalToWrapperConversion.java | 19 +++-------------- .../BigIntegerToPrimitiveConversion.java | 19 +++-------------- .../BigIntegerToStringConversion.java | 19 +++-------------- .../BigIntegerToWrapperConversion.java | 19 +++-------------- .../conversion/CharToStringConversion.java | 19 +++-------------- .../CharWrapperToStringConversion.java | 19 +++-------------- .../conversion/ConversionProvider.java | 19 +++-------------- .../internal/conversion/ConversionUtils.java | 19 +++-------------- .../ap/internal/conversion/Conversions.java | 19 +++-------------- .../conversion/CreateDecimalFormat.java | 19 +++-------------- .../CurrencyToStringConversion.java | 19 +++-------------- .../conversion/DateToSqlDateConversion.java | 19 +++-------------- .../conversion/DateToSqlTimeConversion.java | 19 +++-------------- .../DateToSqlTimestampConversion.java | 19 +++-------------- .../conversion/DateToStringConversion.java | 19 +++-------------- .../conversion/EnumStringConversion.java | 19 +++-------------- .../JavaLocalDateTimeToDateConversion.java | 19 +++-------------- .../JavaLocalDateTimeToStringConversion.java | 19 +++-------------- .../JavaLocalDateToDateConversion.java | 19 +++-------------- .../JavaLocalDateToStringConversion.java | 19 +++-------------- .../JavaLocalTimeToStringConversion.java | 19 +++-------------- .../JavaZonedDateTimeToDateConversion.java | 19 +++-------------- .../JavaZonedDateTimeToStringConversion.java | 19 +++-------------- .../JodaDateTimeToCalendarConversion.java | 19 +++-------------- .../JodaDateTimeToStringConversion.java | 19 +++-------------- .../JodaLocalDateTimeToStringConversion.java | 19 +++-------------- .../JodaLocalDateToStringConversion.java | 19 +++-------------- .../JodaLocalTimeToStringConversion.java | 19 +++-------------- .../conversion/JodaTimeToDateConversion.java | 19 +++-------------- .../PrimitiveToPrimitiveConversion.java | 19 +++-------------- .../PrimitiveToStringConversion.java | 19 +++-------------- .../PrimitiveToWrapperConversion.java | 19 +++-------------- .../conversion/ReverseConversion.java | 19 +++-------------- .../internal/conversion/SimpleConversion.java | 19 +++-------------- .../conversion/WrapperToStringConversion.java | 19 +++-------------- .../WrapperToWrapperConversion.java | 19 +++-------------- .../ap/internal/conversion/package-info.java | 19 +++-------------- .../internal/model/AbstractBaseBuilder.java | 19 +++-------------- .../model/AbstractMappingMethodBuilder.java | 20 +++--------------- .../internal/model/AnnotatedConstructor.java | 19 +++-------------- .../ap/internal/model/Annotation.java | 19 +++-------------- .../model/AnnotationMapperReference.java | 19 +++-------------- .../ap/internal/model/BeanMappingMethod.java | 19 +++-------------- .../model/BuilderFinisherMethodResolver.java | 19 +++-------------- .../model/CollectionAssignmentBuilder.java | 19 +++-------------- .../ap/internal/model/Constructor.java | 19 +++-------------- .../model/ContainerMappingMethod.java | 19 +++-------------- .../model/ContainerMappingMethodBuilder.java | 19 +++-------------- .../ap/internal/model/Decorator.java | 19 +++-------------- .../internal/model/DecoratorConstructor.java | 19 +++-------------- .../model/DefaultMapperReference.java | 19 +++-------------- .../DefaultMappingExclusionProvider.java | 19 +++-------------- .../ap/internal/model/DelegatingMethod.java | 19 +++-------------- .../ap/internal/model/EnumMappingMethod.java | 19 +++-------------- .../mapstruct/ap/internal/model/Field.java | 19 +++-------------- .../ap/internal/model/GeneratedType.java | 19 +++-------------- .../ap/internal/model/HelperMethod.java | 19 +++-------------- .../ap/internal/model/IterableCreation.java | 19 +++-------------- .../internal/model/IterableMappingMethod.java | 19 +++-------------- .../LifecycleCallbackMethodReference.java | 19 +++-------------- .../model/LifecycleMethodResolver.java | 19 +++-------------- .../ap/internal/model/MapMappingMethod.java | 19 +++-------------- .../mapstruct/ap/internal/model/Mapper.java | 19 +++-------------- .../ap/internal/model/MapperReference.java | 19 +++-------------- .../internal/model/MappingBuilderContext.java | 19 +++-------------- .../ap/internal/model/MappingMethod.java | 19 +++-------------- .../ap/internal/model/MethodReference.java | 19 +++-------------- .../model/NestedPropertyMappingMethod.java | 19 +++-------------- .../NestedTargetPropertyMappingHolder.java | 19 +++-------------- .../model/NormalTypeMappingMethod.java | 19 +++-------------- .../model/ObjectFactoryMethodResolver.java | 19 +++-------------- .../ap/internal/model/PropertyMapping.java | 19 +++-------------- .../ap/internal/model/ServicesEntry.java | 19 +++-------------- .../internal/model/StreamMappingMethod.java | 19 +++-------------- .../ap/internal/model/TypeConversion.java | 19 +++-------------- .../ap/internal/model/ValueMappingMethod.java | 19 +++-------------- .../internal/model/VirtualMappingMethod.java | 19 +++-------------- .../model/assignment/AdderWrapper.java | 19 +++-------------- .../model/assignment/ArrayCopyWrapper.java | 19 +++-------------- .../model/assignment/AssignmentWrapper.java | 19 +++-------------- .../model/assignment/EnumConstantWrapper.java | 19 +++-------------- ...nceSetterWrapperForCollectionsAndMaps.java | 19 +++-------------- .../GetterWrapperForCollectionsAndMaps.java | 19 +++-------------- .../assignment/Java8FunctionWrapper.java | 19 +++-------------- .../model/assignment/LocalVarWrapper.java | 19 +++-------------- .../model/assignment/SetterWrapper.java | 19 +++-------------- .../SetterWrapperForCollectionsAndMaps.java | 19 +++-------------- ...perForCollectionsAndMapsWithNullCheck.java | 19 +++-------------- .../model/assignment/UpdateWrapper.java | 19 +++-------------- .../WrapperForCollectionsAndMaps.java | 19 +++-------------- .../model/assignment/package-info.java | 19 +++-------------- .../internal/model/common/Accessibility.java | 19 +++-------------- .../ap/internal/model/common/Assignment.java | 19 +++-------------- .../ap/internal/model/common/BuilderType.java | 19 +++-------------- .../model/common/ConversionContext.java | 19 +++-------------- .../common/DateFormatValidationResult.java | 19 +++-------------- .../model/common/DateFormatValidator.java | 19 +++-------------- .../common/DateFormatValidatorFactory.java | 19 +++-------------- .../common/DefaultConversionContext.java | 19 +++-------------- .../model/common/FormattingParameters.java | 19 +++-------------- .../model/common/ImplementationType.java | 19 +++-------------- .../internal/model/common/ModelElement.java | 19 +++-------------- .../ap/internal/model/common/Parameter.java | 19 +++-------------- .../model/common/ParameterBinding.java | 19 +++-------------- .../ap/internal/model/common/SourceRHS.java | 19 +++-------------- .../ap/internal/model/common/Type.java | 19 +++-------------- .../ap/internal/model/common/TypeFactory.java | 19 +++-------------- .../internal/model/common/package-info.java | 19 +++-------------- .../model/dependency/GraphAnalyzer.java | 19 +++-------------- .../ap/internal/model/dependency/Node.java | 19 +++-------------- .../ap/internal/model/package-info.java | 19 +++-------------- .../ap/internal/model/source/BeanMapping.java | 19 +++-------------- .../ap/internal/model/source/EnumMapping.java | 19 +++-------------- .../internal/model/source/ForgedMethod.java | 19 +++-------------- .../model/source/ForgedMethodHistory.java | 19 +++-------------- .../model/source/IterableMapping.java | 19 +++-------------- .../ap/internal/model/source/MapMapping.java | 19 +++-------------- .../ap/internal/model/source/Mapping.java | 19 +++-------------- .../model/source/MappingMethodUtils.java | 19 +++-------------- .../internal/model/source/MappingOptions.java | 19 +++-------------- .../ap/internal/model/source/Method.java | 19 +++-------------- .../internal/model/source/MethodMatcher.java | 19 +++-------------- .../source/ParameterProvidedMethods.java | 19 +++-------------- .../internal/model/source/PropertyEntry.java | 19 +++-------------- .../model/source/SelectionParameters.java | 19 +++-------------- .../internal/model/source/SourceMethod.java | 19 +++-------------- .../model/source/SourceReference.java | 19 +++-------------- .../model/source/TargetReference.java | 19 +++-------------- .../internal/model/source/ValueMapping.java | 19 +++-------------- .../source/builtin/BuiltInMappingMethods.java | 19 +++-------------- .../model/source/builtin/BuiltInMethod.java | 19 +++-------------- .../CalendarToXmlGregorianCalendar.java | 19 +++-------------- .../builtin/CalendarToZonedDateTime.java | 19 +++-------------- .../builtin/DateToXmlGregorianCalendar.java | 19 +++-------------- .../model/source/builtin/JaxbElemToValue.java | 19 +++-------------- .../JodaDateTimeToXmlGregorianCalendar.java | 19 +++-------------- ...daLocalDateTimeToXmlGregorianCalendar.java | 19 +++-------------- .../JodaLocalDateToXmlGregorianCalendar.java | 19 +++-------------- .../JodaLocalTimeToXmlGregorianCalendar.java | 19 +++-------------- .../LocalDateToXmlGregorianCalendar.java | 19 +++-------------- .../builtin/StringToXmlGregorianCalendar.java | 19 +++-------------- .../XmlGregorianCalendarToCalendar.java | 19 +++-------------- .../builtin/XmlGregorianCalendarToDate.java | 19 +++-------------- .../XmlGregorianCalendarToJodaDateTime.java | 19 +++-------------- .../XmlGregorianCalendarToJodaLocalDate.java | 19 +++-------------- ...lGregorianCalendarToJodaLocalDateTime.java | 19 +++-------------- .../XmlGregorianCalendarToJodaLocalTime.java | 19 +++-------------- .../XmlGregorianCalendarToLocalDate.java | 19 +++-------------- .../builtin/XmlGregorianCalendarToString.java | 19 +++-------------- .../builtin/ZonedDateTimeToCalendar.java | 19 +++-------------- .../ZonedDateTimeToXmlGregorianCalendar.java | 19 +++-------------- .../model/source/builtin/package-info.java | 19 +++-------------- .../internal/model/source/package-info.java | 19 +++-------------- .../selector/CreateOrUpdateSelector.java | 19 +++-------------- .../selector/FactoryParameterSelector.java | 19 +++-------------- .../source/selector/InheritanceSelector.java | 19 +++-------------- .../source/selector/MethodFamilySelector.java | 19 +++-------------- .../model/source/selector/MethodSelector.java | 19 +++-------------- .../source/selector/MethodSelectors.java | 19 +++-------------- .../source/selector/QualifierSelector.java | 19 +++-------------- .../model/source/selector/SelectedMethod.java | 19 +++-------------- .../source/selector/SelectionCriteria.java | 19 +++-------------- .../source/selector/TargetTypeSelector.java | 19 +++-------------- .../model/source/selector/TypeSelector.java | 19 +++-------------- .../selector/XmlElementDeclSelector.java | 19 +++-------------- .../model/source/selector/package-info.java | 19 +++-------------- .../mapstruct/ap/internal/option/Options.java | 19 +++-------------- .../ap/internal/option/package-info.java | 19 +++-------------- .../prism/CollectionMappingStrategyPrism.java | 19 +++-------------- .../prism/InjectionStrategyPrism.java | 19 +++-------------- .../internal/prism/MappingConstantsPrism.java | 19 +++-------------- .../MappingInheritanceStrategyPrism.java | 19 +++-------------- .../prism/NullValueCheckStrategyPrism.java | 19 +++-------------- .../prism/NullValueMappingStrategyPrism.java | 19 +++-------------- .../ap/internal/prism/PrismGenerator.java | 19 +++-------------- .../internal/prism/ReportingPolicyPrism.java | 19 +++-------------- .../ap/internal/prism/package-info.java | 19 +++-------------- ...nnotationBasedComponentModelProcessor.java | 19 +++-------------- .../processor/CdiComponentProcessor.java | 19 +++-------------- .../DefaultModelElementProcessorContext.java | 19 +++-------------- .../processor/DefaultVersionInformation.java | 19 +++-------------- .../processor/Jsr330ComponentProcessor.java | 19 +++-------------- .../processor/MapperCreationProcessor.java | 19 +++-------------- .../processor/MapperRenderingProcessor.java | 19 +++-------------- .../processor/MapperServiceProcessor.java | 19 +++-------------- .../processor/MethodRetrievalProcessor.java | 19 +++-------------- .../processor/ModelElementProcessor.java | 19 +++-------------- .../processor/SpringComponentProcessor.java | 19 +++-------------- .../creation/MappingResolverImpl.java | 19 +++-------------- .../processor/creation/package-info.java | 19 +++-------------- .../ap/internal/processor/package-info.java | 19 +++-------------- .../ap/internal/util/AccessorNamingUtils.java | 19 +++-------------- .../util/AnnotationProcessingException.java | 19 +++-------------- .../util/AnnotationProcessorContext.java | 19 +++-------------- .../ap/internal/util/ClassUtils.java | 19 +++-------------- .../ap/internal/util/Collections.java | 19 +++-------------- .../ap/internal/util/Executables.java | 19 +++-------------- .../mapstruct/ap/internal/util/Extractor.java | 19 +++-------------- .../mapstruct/ap/internal/util/Filters.java | 19 +++-------------- .../ap/internal/util/FormattingMessager.java | 19 +++-------------- .../ap/internal/util/ImmutablesConstants.java | 19 +++-------------- .../ap/internal/util/JavaStreamConstants.java | 19 +++-------------- .../ap/internal/util/JavaTimeConstants.java | 19 +++-------------- .../ap/internal/util/JaxbConstants.java | 19 +++-------------- .../ap/internal/util/JodaTimeConstants.java | 19 +++-------------- .../ap/internal/util/MapperConfiguration.java | 19 +++-------------- .../mapstruct/ap/internal/util/Message.java | 19 +++-------------- .../ap/internal/util/NativeTypes.java | 19 +++-------------- .../org/mapstruct/ap/internal/util/Nouns.java | 19 +++-------------- .../ap/internal/util/RoundContext.java | 19 +++-------------- .../mapstruct/ap/internal/util/Services.java | 19 +++-------------- .../mapstruct/ap/internal/util/Strings.java | 19 +++-------------- .../ap/internal/util/ValueProvider.java | 19 +++-------------- .../ap/internal/util/XmlConstants.java | 19 +++-------------- .../util/accessor/AbstractAccessor.java | 19 +++-------------- .../ap/internal/util/accessor/Accessor.java | 19 +++-------------- .../accessor/ExecutableElementAccessor.java | 19 +++-------------- .../accessor/VariableElementAccessor.java | 19 +++-------------- .../ap/internal/util/package-info.java | 19 +++-------------- .../EclipseAsMemberOfWorkaround.java | 19 +++-------------- .../workarounds/EclipseClassLoaderBridge.java | 19 +++-------------- .../SpecificCompilerWorkarounds.java | 19 +++-------------- .../util/workarounds/TypesDecorator.java | 19 +++-------------- .../internal/version/VersionInformation.java | 19 +++-------------- .../ap/internal/version/package-info.java | 19 +++-------------- .../writer/FreeMarkerModelElementWriter.java | 19 +++-------------- .../internal/writer/FreeMarkerWritable.java | 19 +++-------------- .../writer/IndentationCorrectingWriter.java | 19 +++-------------- .../writer/ModelIncludeDirective.java | 19 +++-------------- .../ap/internal/writer/ModelWriter.java | 19 +++-------------- .../ap/internal/writer/Writable.java | 19 +++-------------- .../ap/internal/writer/package-info.java | 19 +++-------------- .../java/org/mapstruct/ap/package-info.java | 19 +++-------------- .../ap/spi/AccessorNamingStrategy.java | 19 +++-------------- .../spi/AstModifyingAnnotationProcessor.java | 19 +++-------------- .../org/mapstruct/ap/spi/BuilderInfo.java | 19 +++-------------- .../org/mapstruct/ap/spi/BuilderProvider.java | 19 +++-------------- .../ap/spi/DefaultAccessorNamingStrategy.java | 19 +++-------------- .../ap/spi/DefaultBuilderProvider.java | 19 +++-------------- .../spi/ImmutablesAccessorNamingStrategy.java | 19 +++-------------- .../ap/spi/ImmutablesBuilderProvider.java | 19 +++-------------- .../ap/spi/MappingExclusionProvider.java | 19 +++-------------- .../java/org/mapstruct/ap/spi/MethodType.java | 19 +++-------------- ...ThanOneBuilderCreationMethodException.java | 19 +++-------------- .../mapstruct/ap/spi/NoOpBuilderProvider.java | 19 +++-------------- .../spi/TypeHierarchyErroneousException.java | 19 +++-------------- .../org/mapstruct/ap/spi/package-info.java | 19 +++-------------- .../javax.annotation.processing.Processor | 17 ++------------- ...p.internal.processor.ModelElementProcessor | 17 ++------------- .../conversion/CreateDecimalFormat.ftl | 18 ++-------------- .../internal/model/AnnotatedConstructor.ftl | 19 ++--------------- .../ap/internal/model/Annotation.ftl | 18 ++-------------- .../model/AnnotationMapperReference.ftl | 18 ++-------------- .../ap/internal/model/BeanMappingMethod.ftl | 18 ++-------------- .../ap/internal/model/ConversionMethod.ftl | 17 ++------------- .../internal/model/DecoratorConstructor.ftl | 18 ++-------------- .../internal/model/DefaultMapperReference.ftl | 18 ++-------------- .../ap/internal/model/DelegatingMethod.ftl | 18 ++-------------- .../ap/internal/model/EnumMappingMethod.ftl | 18 ++-------------- .../org/mapstruct/ap/internal/model/Field.ftl | 18 ++-------------- .../ap/internal/model/GeneratedType.ftl | 18 ++-------------- .../ap/internal/model/IterableCreation.ftl | 18 ++-------------- .../internal/model/IterableMappingMethod.ftl | 18 ++-------------- .../LifecycleCallbackMethodReference.ftl | 18 ++-------------- .../ap/internal/model/MapMappingMethod.ftl | 18 ++-------------- .../ap/internal/model/MethodReference.ftl | 18 ++-------------- .../model/NestedPropertyMappingMethod.ftl | 18 ++-------------- .../ap/internal/model/PropertyMapping.ftl | 18 ++-------------- .../ap/internal/model/ServicesEntry.ftl | 18 ++-------------- .../ap/internal/model/StreamMappingMethod.ftl | 18 ++-------------- .../ap/internal/model/TypeConversion.ftl | 18 ++-------------- .../ap/internal/model/ValueMappingMethod.ftl | 18 ++-------------- .../model/assignment/AdderWrapper.ftl | 18 ++-------------- .../model/assignment/ArrayCopyWrapper.ftl | 18 ++-------------- .../model/assignment/EnumConstantWrapper.ftl | 18 ++-------------- ...anceSetterWrapperForCollectionsAndMaps.ftl | 18 ++-------------- .../GetterWrapperForCollectionsAndMaps.ftl | 18 ++-------------- .../model/assignment/Java8FunctionWrapper.ftl | 18 ++-------------- .../model/assignment/LocalVarWrapper.ftl | 18 ++-------------- .../model/assignment/SetterWrapper.ftl | 18 ++-------------- .../SetterWrapperForCollectionsAndMaps.ftl | 18 ++-------------- ...pperForCollectionsAndMapsWithNullCheck.ftl | 18 ++-------------- .../model/assignment/UpdateWrapper.ftl | 18 ++-------------- .../ap/internal/model/common/Parameter.ftl | 18 ++-------------- .../ap/internal/model/common/SourceRHS.ftl | 18 ++-------------- .../ap/internal/model/common/Type.ftl | 19 ++--------------- .../ap/internal/model/macro/CommonMacros.ftl | 17 ++------------- .../CalendarToXmlGregorianCalendar.ftl | 18 ++-------------- .../builtin/CalendarToZonedDateTime.ftl | 18 ++-------------- .../builtin/DateToXmlGregorianCalendar.ftl | 18 ++-------------- .../model/source/builtin/JaxbElemToValue.ftl | 18 ++-------------- .../JodaDateTimeToXmlGregorianCalendar.ftl | 18 ++-------------- ...odaLocalDateTimeToXmlGregorianCalendar.ftl | 18 ++-------------- .../JodaLocalDateToXmlGregorianCalendar.ftl | 18 ++-------------- .../JodaLocalTimeToXmlGregorianCalendar.ftl | 18 ++-------------- .../LocalDateToXmlGregorianCalendar.ftl | 18 ++-------------- .../builtin/StringToXmlGregorianCalendar.ftl | 18 ++-------------- .../XmlGregorianCalendarToCalendar.ftl | 18 ++-------------- .../builtin/XmlGregorianCalendarToDate.ftl | 18 ++-------------- .../XmlGregorianCalendarToJodaDateTime.ftl | 18 ++-------------- .../XmlGregorianCalendarToJodaLocalDate.ftl | 18 ++-------------- ...mlGregorianCalendarToJodaLocalDateTime.ftl | 18 ++-------------- .../XmlGregorianCalendarToJodaLocalTime.ftl | 18 ++-------------- .../XmlGregorianCalendarToLocalDate.ftl | 18 ++-------------- .../builtin/XmlGregorianCalendarToString.ftl | 18 ++-------------- .../builtin/ZonedDateTimeToCalendar.ftl | 18 ++-------------- .../ZonedDateTimeToXmlGregorianCalendar.ftl | 18 ++-------------- .../DateFormatValidatorFactoryTest.java | 19 +++-------------- .../common/DefaultConversionContextTest.java | 19 +++-------------- .../model/common/TypeFactoryTest.java | 19 +++-------------- .../model/source/SelectionParametersTest.java | 19 +++-------------- .../ap/internal/util/NativeTypesTest.java | 19 +++-------------- .../ap/internal/util/StringsTest.java | 19 +++-------------- .../org/mapstruct/ap/test/NoProperties.java | 19 +++-------------- .../org/mapstruct/ap/test/WithProperties.java | 19 +++-------------- .../abstractclass/AbstractBaseMapper.java | 19 +++-------------- .../test/abstractclass/AbstractClassTest.java | 19 +++-------------- .../ap/test/abstractclass/AbstractDto.java | 19 +++-------------- .../AbstractReferencedMapper.java | 19 +++-------------- .../ap/test/abstractclass/AlsoHasId.java | 19 +++-------------- .../abstractclass/BaseMapperInterface.java | 19 +++-------------- .../ap/test/abstractclass/HasId.java | 19 +++-------------- .../ap/test/abstractclass/Identifiable.java | 19 +++-------------- .../ap/test/abstractclass/Measurable.java | 19 +++-------------- .../test/abstractclass/ReferencedMapper.java | 19 +++-------------- .../ReferencedMapperInterface.java | 19 +++-------------- .../ap/test/abstractclass/Source.java | 19 +++-------------- .../abstractclass/SourceTargetMapper.java | 19 +++-------------- .../ap/test/abstractclass/Target.java | 19 +++-------------- .../generics/AbstractAnimal.java | 19 +++-------------- .../abstractclass/generics/AbstractHuman.java | 19 +++-------------- .../abstractclass/generics/AnimalKey.java | 19 +++-------------- .../ap/test/abstractclass/generics/Child.java | 19 +++-------------- .../test/abstractclass/generics/Elephant.java | 19 +++-------------- .../generics/GenericIdentifiable.java | 19 +++-------------- .../generics/GenericsHierarchyMapper.java | 19 +++-------------- .../generics/GenericsHierarchyTest.java | 19 +++-------------- .../test/abstractclass/generics/IAnimal.java | 19 +++-------------- .../abstractclass/generics/Identifiable.java | 19 +++-------------- .../ap/test/abstractclass/generics/Key.java | 19 +++-------------- .../generics/KeyOfAllBeings.java | 19 +++-------------- .../test/abstractclass/generics/Target.java | 19 +++-------------- .../test/accessibility/AccessibilityTest.java | 19 +++-------------- .../DefaultSourceTargetMapperAbstr.java | 19 +++-------------- .../DefaultSourceTargetMapperIfc.java | 19 +++-------------- .../ap/test/accessibility/Source.java | 19 +++-------------- .../ap/test/accessibility/Target.java | 19 +++-------------- .../AbstractSourceTargetMapperPrivate.java | 19 +++-------------- .../AbstractSourceTargetMapperProtected.java | 19 +++-------------- .../ReferencedAccessibilityTest.java | 19 +++-------------- .../ReferencedMapperDefaultSame.java | 19 +++-------------- .../referenced/ReferencedMapperPrivate.java | 19 +++-------------- .../referenced/ReferencedMapperProtected.java | 19 +++-------------- .../referenced/ReferencedSource.java | 19 +++-------------- .../referenced/ReferencedTarget.java | 19 +++-------------- .../test/accessibility/referenced/Source.java | 19 +++-------------- .../SourceTargetMapperDefaultOther.java | 19 +++-------------- .../SourceTargetMapperDefaultSame.java | 19 +++-------------- .../referenced/SourceTargetMapperPrivate.java | 19 +++-------------- .../SourceTargetMapperProtected.java | 19 +++-------------- .../SourceTargetmapperPrivateBase.java | 19 +++-------------- .../SourceTargetmapperProtectedBase.java | 19 +++-------------- .../test/accessibility/referenced/Target.java | 19 +++-------------- .../a/ReferencedMapperDefaultOther.java | 19 +++-------------- .../ap/test/array/ArrayMappingTest.java | 19 +++-------------- .../ap/test/array/ScienceMapper.java | 19 +++-------------- .../ap/test/array/_target/ScientistDto.java | 19 +++-------------- .../ap/test/array/source/Scientist.java | 19 +++-------------- .../ap/test/bool/BooleanMappingTest.java | 19 +++-------------- .../org/mapstruct/ap/test/bool/Person.java | 19 +++-------------- .../org/mapstruct/ap/test/bool/PersonDto.java | 19 +++-------------- .../mapstruct/ap/test/bool/PersonMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/bool/YesNo.java | 19 +++-------------- .../mapstruct/ap/test/bool/YesNoMapper.java | 19 +++-------------- .../ap/test/bugs/_1005/AbstractEntity.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1005/HasKey.java | 19 +++-------------- .../ap/test/bugs/_1005/HasPrimaryKey.java | 19 +++-------------- ...1005ErroneousAbstractResultTypeMapper.java | 19 +++-------------- ...1005ErroneousAbstractReturnTypeMapper.java | 19 +++-------------- ...005ErroneousInterfaceResultTypeMapper.java | 19 +++-------------- ...005ErroneousInterfaceReturnTypeMapper.java | 19 +++-------------- .../ap/test/bugs/_1005/Issue1005Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1005/Order.java | 19 +++-------------- .../ap/test/bugs/_1005/OrderDto.java | 19 +++-------------- .../bugs/_1029/ErroneousIssue1029Mapper.java | 19 +++-------------- .../ap/test/bugs/_1029/Issue1029Test.java | 19 +++-------------- .../ap/test/bugs/_1061/Issue1061Test.java | 19 +++-------------- .../test/bugs/_1061/SourceTargetMapper.java | 19 +++-------------- .../ap/test/bugs/_1111/Issue1111Mapper.java | 19 +++-------------- .../ap/test/bugs/_1111/Issue1111Test.java | 19 +++-------------- .../ap/test/bugs/_1124/Issue1124Mapper.java | 19 +++-------------- .../ap/test/bugs/_1124/Issue1124Test.java | 19 +++-------------- .../ap/test/bugs/_1130/Issue1130Mapper.java | 19 +++-------------- .../ap/test/bugs/_1130/Issue1130Test.java | 19 +++-------------- .../ap/test/bugs/_1131/Issue1131Mapper.java | 19 +++-------------- .../_1131/Issue1131MapperWithContext.java | 19 +++-------------- .../ap/test/bugs/_1131/Issue1131Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1131/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1131/Target.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1148/Entity.java | 19 +++-------------- .../ap/test/bugs/_1148/Issue1148Mapper.java | 19 +++-------------- .../ap/test/bugs/_1148/Issue1148Test.java | 19 +++-------------- .../bugs/_1153/ErroneousIssue1153Mapper.java | 19 +++-------------- .../ap/test/bugs/_1153/Issue1153Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1155/Entity.java | 19 +++-------------- .../ap/test/bugs/_1155/Issue1155Mapper.java | 19 +++-------------- .../ap/test/bugs/_1155/Issue1155Test.java | 19 +++-------------- .../ap/test/bugs/_1164/GenericHolder.java | 19 +++-------------- .../ap/test/bugs/_1164/Issue1164Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1164/Source.java | 19 +++-------------- .../test/bugs/_1164/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1164/Target.java | 19 +++-------------- .../bugs/_1170/AdderSourceTargetMapper.java | 19 +++-------------- .../ap/test/bugs/_1170/AdderTest.java | 19 +++-------------- .../ap/test/bugs/_1170/PetMapper.java | 19 +++-------------- .../ap/test/bugs/_1170/_target/Target.java | 19 +++-------------- .../ap/test/bugs/_1170/source/Source.java | 19 +++-------------- .../bugs/_1180/ErroneousIssue1180Mapper.java | 19 +++-------------- .../ap/test/bugs/_1180/Issue1180Test.java | 19 +++-------------- .../ap/test/bugs/_1180/SharedConfig.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1180/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1180/Target.java | 19 +++-------------- .../ap/test/bugs/_1215/Issue1215Test.java | 19 +++-------------- .../ap/test/bugs/_1215/dto/EntityDTO.java | 19 +++-------------- .../ap/test/bugs/_1215/entity/AnotherTag.java | 19 +++-------------- .../ap/test/bugs/_1215/entity/Entity.java | 19 +++-------------- .../ap/test/bugs/_1215/entity/Tag.java | 19 +++-------------- .../bugs/_1215/mapper/Issue1215Mapper.java | 19 +++-------------- .../ap/test/bugs/_1227/Issue1227Mapper.java | 19 +++-------------- .../ap/test/bugs/_1227/Issue1227Test.java | 19 +++-------------- .../ap/test/bugs/_1227/ThreadDto.java | 19 +++-------------- ...roneousIssue1242MapperMultipleSources.java | 19 +++-------------- .../ap/test/bugs/_1242/Issue1242Mapper.java | 19 +++-------------- .../ap/test/bugs/_1242/Issue1242Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1242/SourceA.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1242/SourceB.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1242/TargetA.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1242/TargetB.java | 19 +++-------------- .../ap/test/bugs/_1242/TargetFactories.java | 19 +++-------------- .../ap/test/bugs/_1244/Issue1244Test.java | 19 +++-------------- .../ap/test/bugs/_1244/SizeMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1247/DtoIn.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1247/DtoOut.java | 19 +++-------------- .../ap/test/bugs/_1247/InternalData.java | 19 +++-------------- .../ap/test/bugs/_1247/InternalDto.java | 19 +++-------------- .../ap/test/bugs/_1247/Issue1247Mapper.java | 19 +++-------------- .../ap/test/bugs/_1247/Issue1247Test.java | 19 +++-------------- .../ap/test/bugs/_1247/OtherDtoOut.java | 19 +++-------------- .../ap/test/bugs/_1247/OtherInternalData.java | 19 +++-------------- .../ap/test/bugs/_1247/OtherInternalDto.java | 19 +++-------------- .../ap/test/bugs/_1255/AbstractA.java | 19 +++-------------- .../ap/test/bugs/_1255/Issue1255Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1255/SomeA.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1255/SomeB.java | 19 +++-------------- .../ap/test/bugs/_1255/SomeMapper.java | 19 +++-------------- .../ap/test/bugs/_1255/SomeMapperConfig.java | 19 +++-------------- .../ap/test/bugs/_1269/Issue1269Test.java | 19 +++-------------- .../ap/test/bugs/_1269/dto/VehicleDto.java | 19 +++-------------- .../test/bugs/_1269/dto/VehicleImageDto.java | 19 +++-------------- .../test/bugs/_1269/dto/VehicleInfoDto.java | 19 +++-------------- .../test/bugs/_1269/mapper/VehicleMapper.java | 19 +++-------------- .../ap/test/bugs/_1269/model/Vehicle.java | 19 +++-------------- .../test/bugs/_1269/model/VehicleImage.java | 19 +++-------------- .../bugs/_1269/model/VehicleTypeInfo.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_1273/Dto.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1273/Entity.java | 19 +++-------------- .../bugs/_1273/EntityMapperReturnDefault.java | 19 +++-------------- .../bugs/_1273/EntityMapperReturnNull.java | 19 +++-------------- .../ap/test/bugs/_1273/Issue1273Test.java | 19 +++-------------- ...eTargetHasNoSuitableConstructorMapper.java | 19 +++-------------- ...sTargetHasNoSuitableConstructorMapper.java | 19 +++-------------- .../ap/test/bugs/_1283/Issue1283Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1283/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1283/Target.java | 19 +++-------------- .../ap/test/bugs/_1320/Issue1320Mapper.java | 19 +++-------------- .../ap/test/bugs/_1320/Issue1320Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1320/Target.java | 19 +++-------------- .../ap/test/bugs/_1338/Issue1338Mapper.java | 19 +++-------------- .../ap/test/bugs/_1338/Issue1338Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1338/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1338/Target.java | 19 +++-------------- .../ap/test/bugs/_1339/Callback.java | 19 +++-------------- .../ap/test/bugs/_1339/Issue1339Mapper.java | 19 +++-------------- .../ap/test/bugs/_1339/Issue1339Test.java | 19 +++-------------- .../ap/test/bugs/_1340/Issue1340Mapper.java | 19 +++-------------- .../ap/test/bugs/_1340/Issue1340Test.java | 19 +++-------------- .../ap/test/bugs/_1345/Issue1345Mapper.java | 19 +++-------------- .../ap/test/bugs/_1345/Issue1345Test.java | 19 +++-------------- .../ap/test/bugs/_1353/Issue1353Mapper.java | 19 +++-------------- .../ap/test/bugs/_1353/Issue1353Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1353/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1353/Target.java | 19 +++-------------- .../ap/test/bugs/_1359/Issue1359Mapper.java | 19 +++-------------- .../ap/test/bugs/_1359/Issue1359Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1359/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1359/Target.java | 19 +++-------------- .../ap/test/bugs/_1375/Issue1375Mapper.java | 19 +++-------------- .../ap/test/bugs/_1375/Issue1375Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1375/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1375/Target.java | 19 +++-------------- .../ap/test/bugs/_1395/Issue1395Mapper.java | 19 +++-------------- .../ap/test/bugs/_1395/Issue1395Test.java | 19 +++-------------- .../ap/test/bugs/_1395/NotUsedService.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1395/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1395/Target.java | 19 +++-------------- .../ap/test/bugs/_1425/Issue1425Mapper.java | 19 +++-------------- .../ap/test/bugs/_1425/Issue1425Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1425/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1425/Target.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1453/Auction.java | 19 +++-------------- .../ap/test/bugs/_1453/AuctionDto.java | 19 +++-------------- .../ap/test/bugs/_1453/Issue1453Mapper.java | 19 +++-------------- .../ap/test/bugs/_1453/Issue1453Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1453/Payment.java | 19 +++-------------- .../ap/test/bugs/_1453/PaymentDto.java | 19 +++-------------- .../ap/test/bugs/_1460/Issue1460Mapper.java | 19 +++-------------- .../ap/test/bugs/_1460/Issue1460Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1460/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1460/Target.java | 19 +++-------------- .../_1460/java8/Issue1460JavaTimeMapper.java | 19 +++-------------- .../_1460/java8/Issue1460JavaTimeTest.java | 19 +++-------------- .../ap/test/bugs/_1460/java8/Source.java | 19 +++-------------- .../ap/test/bugs/_1460/java8/Target.java | 19 +++-------------- .../ap/test/bugs/_1482/BigDecimalWrapper.java | 19 +++-------------- .../ap/test/bugs/_1482/Issue1482Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1482/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1482/Source2.java | 19 +++-------------- .../ap/test/bugs/_1482/SourceEnum.java | 19 +++-------------- .../test/bugs/_1482/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_1482/Target.java | 19 +++-------------- .../test/bugs/_1482/TargetSourceMapper.java | 19 +++-------------- .../ap/test/bugs/_1482/ValueWrapper.java | 19 +++-------------- .../bugs/_1523/java8/Issue1523Mapper.java | 19 +++-------------- .../test/bugs/_1523/java8/Issue1523Test.java | 19 +++-------------- .../ap/test/bugs/_1523/java8/Source.java | 19 +++-------------- .../ap/test/bugs/_1523/java8/Target.java | 19 +++-------------- .../ap/test/bugs/_289/Issue289Mapper.java | 19 +++-------------- .../ap/test/bugs/_289/Issue289Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_289/Source.java | 19 +++-------------- .../ap/test/bugs/_289/SourceElement.java | 19 +++-------------- .../ap/test/bugs/_289/TargetElement.java | 19 +++-------------- .../ap/test/bugs/_289/TargetWithSetter.java | 19 +++-------------- .../test/bugs/_289/TargetWithoutSetter.java | 19 +++-------------- .../ap/test/bugs/_306/Issue306Mapper.java | 19 +++-------------- .../ap/test/bugs/_306/Issue306Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_306/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_306/Target.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_373/Branch.java | 19 +++-------------- .../ap/test/bugs/_373/BranchLocation.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_373/Country.java | 19 +++-------------- .../ap/test/bugs/_373/Issue373Mapper.java | 19 +++-------------- .../ap/test/bugs/_373/Issue373Test.java | 19 +++-------------- .../ap/test/bugs/_373/ResultDto.java | 19 +++-------------- .../ap/test/bugs/_374/Issue374Mapper.java | 19 +++-------------- .../ap/test/bugs/_374/Issue374Test.java | 19 +++-------------- .../ap/test/bugs/_374/Issue374VoidMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_374/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_374/Target.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_375/Case.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_375/Int.java | 19 +++-------------- .../ap/test/bugs/_375/Issue375Mapper.java | 19 +++-------------- .../ap/test/bugs/_375/Issue375Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_375/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_375/Target.java | 19 +++-------------- .../SameClassNameInDifferentPackageTest.java | 19 +++-------------- .../SameNameForSourceAndTargetCarsMapper.java | 19 +++-------------- .../ap/test/bugs/_394/_target/AnotherCar.java | 19 +++-------------- .../ap/test/bugs/_394/_target/Cars.java | 19 +++-------------- .../ap/test/bugs/_394/source/AnotherCar.java | 19 +++-------------- .../ap/test/bugs/_394/source/Cars.java | 19 +++-------------- .../ap/test/bugs/_405/EntityFactory.java | 19 +++-------------- .../ap/test/bugs/_405/Issue405Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_405/People.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_405/Person.java | 19 +++-------------- .../ap/test/bugs/_405/PersonMapper.java | 19 +++-------------- .../ap/test/bugs/_513/Issue513Mapper.java | 19 +++-------------- .../ap/test/bugs/_513/Issue513Test.java | 19 +++-------------- .../ap/test/bugs/_513/MappingException.java | 19 +++-------------- .../test/bugs/_513/MappingKeyException.java | 19 +++-------------- .../test/bugs/_513/MappingValueException.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_513/Source.java | 19 +++-------------- .../ap/test/bugs/_513/SourceElement.java | 19 +++-------------- .../ap/test/bugs/_513/SourceKey.java | 19 +++-------------- .../ap/test/bugs/_513/SourceValue.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_513/Target.java | 19 +++-------------- .../ap/test/bugs/_513/TargetElement.java | 19 +++-------------- .../ap/test/bugs/_513/TargetKey.java | 19 +++-------------- .../ap/test/bugs/_513/TargetValue.java | 19 +++-------------- .../ap/test/bugs/_515/Issue515Mapper.java | 19 +++-------------- .../ap/test/bugs/_515/Issue515Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_515/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_515/Target.java | 19 +++-------------- .../ap/test/bugs/_516/Issue516Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_516/Source.java | 19 +++-------------- .../ap/test/bugs/_516/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_516/Target.java | 19 +++-------------- .../ap/test/bugs/_537/Issue537Mapper.java | 19 +++-------------- .../test/bugs/_537/Issue537MapperConfig.java | 19 +++-------------- .../ap/test/bugs/_537/Issue537Test.java | 19 +++-------------- .../ap/test/bugs/_537/ReferenceMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_537/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_537/Target.java | 19 +++-------------- .../ap/test/bugs/_543/Issue543Mapper.java | 19 +++-------------- .../ap/test/bugs/_543/Issue543Test.java | 19 +++-------------- .../ap/test/bugs/_543/SourceUtil.java | 19 +++-------------- .../ap/test/bugs/_543/dto/Source.java | 19 +++-------------- .../ap/test/bugs/_543/dto/Target.java | 19 +++-------------- .../ap/test/bugs/_577/Issue577Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_577/Source.java | 19 +++-------------- .../ap/test/bugs/_577/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_577/Target.java | 19 +++-------------- .../ap/test/bugs/_581/Issue581Test.java | 19 +++-------------- .../ap/test/bugs/_581/SourceTargetMapper.java | 19 +++-------------- .../ap/test/bugs/_581/_target/Car.java | 19 +++-------------- .../ap/test/bugs/_581/source/Car.java | 19 +++-------------- .../_590/ErroneousSourceTargetMapper.java | 19 +++-------------- .../ap/test/bugs/_590/Issue590Test.java | 19 +++-------------- .../ap/test/bugs/_611/Issue611Test.java | 19 +++-------------- .../ap/test/bugs/_611/SomeClass.java | 19 +++-------------- .../ap/test/bugs/_611/SomeOtherClass.java | 19 +++-------------- .../ap/test/bugs/_625/Issue625Test.java | 19 +++-------------- .../ap/test/bugs/_625/ObjectFactory.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_625/Source.java | 19 +++-------------- .../ap/test/bugs/_625/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_625/Target.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_631/Base1.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_631/Base2.java | 19 +++-------------- .../_631/ErroneousSourceTargetMapper.java | 19 +++-------------- .../ap/test/bugs/_631/Issue631Test.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_634/Bar.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_634/Foo.java | 19 +++-------------- .../test/bugs/_634/GenericContainerTest.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_634/Source.java | 19 +++-------------- .../ap/test/bugs/_634/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_634/Target.java | 19 +++-------------- .../ap/test/bugs/_775/IterableContainer.java | 19 +++-------------- .../IterableWithBoundedElementTypeTest.java | 19 +++-------------- .../ap/test/bugs/_775/ListContainer.java | 19 +++-------------- .../_775/MapperWithCustomListMapping.java | 19 +++-------------- .../_775/MapperWithForgedIterableMapping.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_843/Commit.java | 19 +++-------------- .../ap/test/bugs/_843/GitlabTag.java | 19 +++-------------- .../ap/test/bugs/_843/Issue843Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_843/TagInfo.java | 19 +++-------------- .../ap/test/bugs/_843/TagMapper.java | 19 +++-------------- .../ap/test/bugs/_846/Mapper846.java | 19 +++-------------- .../ap/test/bugs/_846/UpdateTest.java | 19 +++-------------- .../ap/test/bugs/_849/Issue849Mapper.java | 19 +++-------------- .../ap/test/bugs/_849/Issue849Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_849/Source.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_849/Target.java | 19 +++-------------- .../ap/test/bugs/_855/OrderDemoMapper.java | 19 +++-------------- .../ap/test/bugs/_855/OrderedSource.java | 19 +++-------------- .../ap/test/bugs/_855/OrderedTarget.java | 19 +++-------------- .../ap/test/bugs/_855/OrderingBug855Test.java | 19 +++-------------- .../ap/test/bugs/_865/Issue865Test.java | 19 +++-------------- .../ap/test/bugs/_865/ProjCoreUserEntity.java | 19 +++-------------- .../ap/test/bugs/_865/ProjMemberDto.java | 19 +++-------------- .../ap/test/bugs/_865/ProjectDto.java | 19 +++-------------- .../ap/test/bugs/_865/ProjectEntity.java | 19 +++-------------- .../bugs/_865/ProjectEntityWithoutSetter.java | 19 +++-------------- .../ap/test/bugs/_865/ProjectMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_880/Config.java | 19 +++-------------- .../DefaultsToProcessorOptionsMapper.java | 19 +++-------------- .../ap/test/bugs/_880/Issue880Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_880/Poodle.java | 19 +++-------------- .../_880/UsesConfigFromAnnotationMapper.java | 19 +++-------------- .../ap/test/bugs/_891/BuggyMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_891/Dest.java | 19 +++-------------- .../ap/test/bugs/_891/Issue891Test.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_891/Src.java | 19 +++-------------- .../ap/test/bugs/_891/SrcNested.java | 19 +++-------------- .../ap/test/bugs/_892/Issue892Mapper.java | 19 +++-------------- .../ap/test/bugs/_892/Issue892Test.java | 19 +++-------------- .../ap/test/bugs/_895/Issue895Test.java | 19 +++-------------- .../ap/test/bugs/_895/MultiArrayMapper.java | 19 +++-------------- .../ap/test/bugs/_909/Issue909Test.java | 19 +++-------------- .../ap/test/bugs/_909/ValuesMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_913/Domain.java | 19 +++-------------- .../_913/DomainDtoWithNcvsAlwaysMapper.java | 19 +++-------------- .../_913/DomainDtoWithNvmsDefaultMapper.java | 19 +++-------------- .../_913/DomainDtoWithNvmsNullMapper.java | 19 +++-------------- .../DomainDtoWithPresenceCheckMapper.java | 19 +++-------------- .../test/bugs/_913/DomainWithoutSetter.java | 19 +++-------------- ...WithoutSetterDtoWithNvmsDefaultMapper.java | 19 +++-------------- ...ainWithoutSetterDtoWithNvmsNullMapper.java | 19 +++-------------- ...thoutSetterDtoWithPresenceCheckMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/bugs/_913/Dto.java | 19 +++-------------- .../test/bugs/_913/DtoWithPresenceCheck.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_913/Helper.java | 19 +++-------------- ...ssue913GetterMapperForCollectionsTest.java | 19 +++-------------- ...ssue913SetterMapperForCollectionsTest.java | 19 +++-------------- .../ap/test/bugs/_931/Issue931Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_931/Nested.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_931/Source.java | 19 +++-------------- .../ap/test/bugs/_931/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_931/Target.java | 19 +++-------------- .../ap/test/bugs/_955/CarMapper.java | 19 +++-------------- .../ap/test/bugs/_955/CustomMapper.java | 19 +++-------------- .../ap/test/bugs/_955/Issue955Test.java | 19 +++-------------- .../mapstruct/ap/test/bugs/_955/dto/Car.java | 19 +++-------------- .../ap/test/bugs/_955/dto/Person.java | 19 +++-------------- .../ap/test/bugs/_955/dto/SuperCar.java | 19 +++-------------- .../ap/test/bugs/_971/CollectionSource.java | 19 +++-------------- .../ap/test/bugs/_971/CollectionTarget.java | 19 +++-------------- .../bugs/_971/Issue971CollectionMapper.java | 19 +++-------------- .../ap/test/bugs/_971/Issue971MapMapper.java | 19 +++-------------- .../ap/test/bugs/_971/Issue971Test.java | 19 +++-------------- .../ap/test/bugs/_971/MapSource.java | 19 +++-------------- .../ap/test/bugs/_971/MapTarget.java | 19 +++-------------- .../abstractBuilder/AbstractBuilderTest.java | 19 +++-------------- .../AbstractImmutableProduct.java | 19 +++-------------- .../AbstractProductBuilder.java | 19 +++-------------- .../abstractBuilder/ImmutableProduct.java | 19 +++-------------- .../builder/abstractBuilder/ProductDto.java | 19 +++-------------- .../abstractBuilder/ProductMapper.java | 19 +++-------------- .../AbstractGenericTargetBuilderTest.java | 19 +++-------------- .../builder/abstractGenericTarget/Child.java | 19 +++-------------- .../abstractGenericTarget/ChildSource.java | 19 +++-------------- .../abstractGenericTarget/ImmutableChild.java | 19 +++-------------- .../ImmutableParent.java | 19 +++-------------- .../abstractGenericTarget/MutableChild.java | 19 +++-------------- .../abstractGenericTarget/MutableParent.java | 19 +++-------------- .../builder/abstractGenericTarget/Parent.java | 19 +++-------------- .../abstractGenericTarget/ParentMapper.java | 19 +++-------------- .../abstractGenericTarget/ParentSource.java | 19 +++-------------- .../builder/factory/BuilderFactoryMapper.java | 19 +++-------------- .../factory/BuilderFactoryMapperTest.java | 19 +++-------------- .../factory/BuilderImplicitFactoryMapper.java | 19 +++-------------- .../ap/test/builder/factory/Person.java | 19 +++-------------- .../ap/test/builder/factory/PersonDto.java | 19 +++-------------- .../ap/test/builder/ignore/BaseDto.java | 19 +++-------------- .../ap/test/builder/ignore/BaseEntity.java | 19 +++-------------- .../builder/ignore/BuilderIgnoringMapper.java | 19 +++-------------- .../ignore/BuilderIgnoringMappingConfig.java | 19 +++-------------- .../builder/ignore/BuilderIgnoringTest.java | 19 +++-------------- .../ap/test/builder/ignore/Person.java | 19 +++-------------- .../ap/test/builder/ignore/PersonDto.java | 19 +++-------------- .../BuilderLifecycleCallbacksTest.java | 19 +++-------------- .../ap/test/builder/lifecycle/Item.java | 19 +++-------------- .../ap/test/builder/lifecycle/ItemDto.java | 19 +++-------------- .../builder/lifecycle/MappingContext.java | 19 +++-------------- .../ap/test/builder/lifecycle/Order.java | 19 +++-------------- .../ap/test/builder/lifecycle/OrderDto.java | 19 +++-------------- .../test/builder/lifecycle/OrderMapper.java | 19 +++-------------- .../simple/BuilderInfoTargetTest.java | 19 +++-------------- .../mappingTarget/simple/MutableTarget.java | 19 +++-------------- .../simple/SimpleBuilderMapper.java | 19 +++-------------- .../simple/SimpleImmutableTarget.java | 19 +++-------------- .../simple/SimpleMutableSource.java | 19 +++-------------- .../multiple/BuilderConfigDefinedMapper.java | 19 +++-------------- .../multiple/BuilderDefinedMapper.java | 19 +++-------------- .../builder/multiple/BuilderMapperConfig.java | 19 +++-------------- .../multiple/DefaultBuildMethodMapper.java | 19 +++-------------- ...ErroneousMoreThanOneBuildMethodMapper.java | 19 +++-------------- ...dMethodWithMapperDefinedMappingMapper.java | 19 +++-------------- .../multiple/MultipleBuilderMapperTest.java | 19 +++-------------- .../ap/test/builder/multiple/Source.java | 19 +++-------------- .../ap/test/builder/multiple/Task.java | 19 +++-------------- .../TooManyBuilderCreationMethodsMapper.java | 19 +++-------------- .../test/builder/multiple/build/Process.java | 19 +++-------------- .../test/builder/multiple/builder/Case.java | 19 +++-------------- .../expanding/BuilderNestedPropertyTest.java | 19 +++-------------- .../nestedprop/expanding/ExpandingMapper.java | 19 +++-------------- .../nestedprop/expanding/FlattenedStock.java | 19 +++-------------- .../expanding/ImmutableArticle.java | 19 +++-------------- .../expanding/ImmutableExpandedStock.java | 19 +++-------------- .../nestedprop/flattening/Article.java | 19 +++-------------- .../flattening/BuilderNestedPropertyTest.java | 19 +++-------------- .../flattening/FlatteningMapper.java | 19 +++-------------- .../flattening/ImmutableFlattenedStock.java | 19 +++-------------- .../builder/nestedprop/flattening/Stock.java | 19 +++-------------- .../builder/noop/NoOpBuilderProviderTest.java | 19 +++-------------- .../ap/test/builder/noop/Person.java | 19 +++-------------- .../ap/test/builder/noop/PersonDto.java | 19 +++-------------- .../ap/test/builder/noop/PersonMapper.java | 19 +++-------------- .../builder/parentchild/ImmutableChild.java | 19 +++-------------- .../builder/parentchild/ImmutableParent.java | 19 +++-------------- .../builder/parentchild/MutableChild.java | 19 +++-------------- .../builder/parentchild/MutableParent.java | 19 +++-------------- .../parentchild/ParentChildBuilderTest.java | 19 +++-------------- .../parentchild/ParentChildMapper.java | 19 +++-------------- .../simple/ErroneousSimpleBuilderMapper.java | 19 +++-------------- .../builder/simple/SimpleBuilderMapper.java | 19 +++-------------- .../simple/SimpleImmutableBuilderTest.java | 19 +++-------------- .../builder/simple/SimpleImmutablePerson.java | 19 +++-------------- .../builder/simple/SimpleMutablePerson.java | 19 +++-------------- .../ap/test/builtin/BuiltInTest.java | 19 +++-------------- .../test/builtin/_target/IterableTarget.java | 19 +++-------------- .../ap/test/builtin/_target/MapTarget.java | 19 +++-------------- .../test/builtin/bean/CalendarProperty.java | 19 +++-------------- .../ap/test/builtin/bean/DateProperty.java | 19 +++-------------- .../builtin/bean/JaxbElementListProperty.java | 19 +++-------------- .../builtin/bean/JaxbElementProperty.java | 19 +++-------------- .../test/builtin/bean/StringListProperty.java | 19 +++-------------- .../ap/test/builtin/bean/StringProperty.java | 19 +++-------------- .../bean/XmlGregorianCalendarProperty.java | 19 +++-------------- .../java8time/bean/ZonedDateTimeProperty.java | 19 +++-------------- .../mapper/CalendarToZonedDateTimeMapper.java | 19 +++-------------- .../mapper/ZonedDateTimeToCalendarMapper.java | 19 +++-------------- .../test/builtin/jodatime/JodaTimeTest.java | 19 +++-------------- .../builtin/jodatime/bean/DateTimeBean.java | 19 +++-------------- .../builtin/jodatime/bean/LocalDateBean.java | 19 +++-------------- .../jodatime/bean/LocalDateTimeBean.java | 19 +++-------------- .../builtin/jodatime/bean/LocalTimeBean.java | 19 +++-------------- .../bean/XmlGregorianCalendarBean.java | 19 +++-------------- .../DateTimeToXmlGregorianCalendar.java | 19 +++-------------- .../LocalDateTimeToXmlGregorianCalendar.java | 19 +++-------------- .../LocalDateToXmlGregorianCalendar.java | 19 +++-------------- .../LocalTimeToXmlGregorianCalendar.java | 19 +++-------------- .../XmlGregorianCalendarToDateTime.java | 19 +++-------------- .../XmlGregorianCalendarToLocalDate.java | 19 +++-------------- .../XmlGregorianCalendarToLocalDateTime.java | 19 +++-------------- .../XmlGregorianCalendarToLocalTime.java | 19 +++-------------- .../builtin/mapper/CalendarToDateMapper.java | 19 +++-------------- .../mapper/CalendarToStringMapper.java | 19 +++-------------- .../mapper/CalendarToXmlGregCalMapper.java | 19 +++-------------- .../builtin/mapper/DateToCalendarMapper.java | 19 +++-------------- .../mapper/DateToXmlGregCalMapper.java | 19 +++-------------- .../mapper/IterableSourceTargetMapper.java | 19 +++-------------- .../test/builtin/mapper/JaxbListMapper.java | 19 +++-------------- .../ap/test/builtin/mapper/JaxbMapper.java | 19 +++-------------- .../builtin/mapper/MapSourceTargetMapper.java | 19 +++-------------- .../mapper/StringToCalendarMapper.java | 19 +++-------------- .../mapper/StringToXmlGregCalMapper.java | 19 +++-------------- .../mapper/XmlGregCalToCalendarMapper.java | 19 +++-------------- .../mapper/XmlGregCalToDateMapper.java | 19 +++-------------- .../mapper/XmlGregCalToStringMapper.java | 19 +++-------------- .../test/builtin/source/IterableSource.java | 19 +++-------------- .../ap/test/builtin/source/MapSource.java | 19 +++-------------- .../ap/test/callbacks/BaseMapper.java | 19 +++-------------- .../ap/test/callbacks/CallbackMethodTest.java | 19 +++-------------- .../callbacks/ClassContainingCallbacks.java | 19 +++-------------- .../ap/test/callbacks/Invocation.java | 19 +++-------------- .../ap/test/callbacks/Qualified.java | 19 +++-------------- .../mapstruct/ap/test/callbacks/Source.java | 19 +++-------------- .../ap/test/callbacks/SourceEnum.java | 19 +++-------------- .../SourceTargetCollectionMapper.java | 19 +++-------------- .../ap/test/callbacks/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/callbacks/Target.java | 19 +++-------------- .../ap/test/callbacks/TargetEnum.java | 19 +++-------------- .../callbacks/ongeneratedmethods/Address.java | 19 +++-------------- .../ongeneratedmethods/AddressDto.java | 19 +++-------------- .../callbacks/ongeneratedmethods/Company.java | 19 +++-------------- .../ongeneratedmethods/CompanyDto.java | 19 +++-------------- .../ongeneratedmethods/CompanyMapper.java | 19 +++-------------- .../CompanyMapperPostProcessing.java | 19 +++-------------- .../ongeneratedmethods/Employee.java | 19 +++-------------- .../ongeneratedmethods/EmployeeDto.java | 19 +++-------------- .../MappingResultPostprocessorTest.java | 19 +++-------------- .../test/callbacks/returning/Attribute.java | 19 +++-------------- .../callbacks/returning/AttributeDto.java | 19 +++-------------- .../CallbacksWithReturnValuesTest.java | 19 +++-------------- .../ap/test/callbacks/returning/Node.java | 19 +++-------------- .../ap/test/callbacks/returning/NodeDto.java | 19 +++-------------- .../returning/NodeMapperContext.java | 19 +++-------------- .../returning/NodeMapperDefault.java | 19 +++-------------- .../returning/NodeMapperWithContext.java | 19 +++-------------- .../ap/test/callbacks/returning/Number.java | 19 +++-------------- .../returning/NumberMapperContext.java | 19 +++-------------- .../returning/NumberMapperDefault.java | 19 +++-------------- .../returning/NumberMapperWithContext.java | 19 +++-------------- .../CallbackMethodTypeMatchingTest.java | 19 +++-------------- .../callbacks/typematching/CarMapper.java | 19 +++-------------- .../collection/CollectionMappingTest.java | 19 +++-------------- .../mapstruct/ap/test/collection/Colour.java | 19 +++-------------- .../mapstruct/ap/test/collection/Source.java | 19 +++-------------- .../test/collection/SourceTargetMapper.java | 19 +++-------------- .../ap/test/collection/StringHolder.java | 19 +++-------------- .../collection/StringHolderArrayList.java | 19 +++-------------- .../collection/StringHolderToLongMap.java | 19 +++-------------- .../mapstruct/ap/test/collection/Target.java | 19 +++-------------- .../ap/test/collection/TestList.java | 19 +++-------------- .../mapstruct/ap/test/collection/TestMap.java | 19 +++-------------- .../ap/test/collection/adder/AdderTest.java | 19 +++-------------- .../test/collection/adder/CatException.java | 19 +++-------------- .../test/collection/adder/DogException.java | 19 +++-------------- .../ap/test/collection/adder/PetMapper.java | 19 +++-------------- .../adder/Source2Target2Mapper.java | 19 +++-------------- .../collection/adder/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperStrategyDefault.java | 19 +++-------------- ...ceTargetMapperStrategySetterPreferred.java | 19 +++-------------- .../ap/test/collection/adder/TeethMapper.java | 19 +++-------------- .../adder/_target/AdderUsageObserver.java | 19 +++-------------- .../collection/adder/_target/IndoorPet.java | 19 +++-------------- .../collection/adder/_target/OutdoorPet.java | 19 +++-------------- .../ap/test/collection/adder/_target/Pet.java | 19 +++-------------- .../test/collection/adder/_target/Target.java | 19 +++-------------- .../collection/adder/_target/Target2.java | 19 +++-------------- .../collection/adder/_target/TargetDali.java | 19 +++-------------- .../collection/adder/_target/TargetHuman.java | 19 +++-------------- .../adder/_target/TargetOnlyGetter.java | 19 +++-------------- .../adder/_target/TargetViaTargetType.java | 19 +++-------------- .../adder/_target/TargetWithoutSetter.java | 19 +++-------------- .../ap/test/collection/adder/source/Foo.java | 19 +++-------------- .../adder/source/SingleElementSource.java | 19 +++-------------- .../test/collection/adder/source/Source.java | 19 +++-------------- .../test/collection/adder/source/Source2.java | 19 +++-------------- .../collection/adder/source/SourceTeeth.java | 19 +++-------------- .../DefaultCollectionImplementationTest.java | 19 +++-------------- .../NoSetterCollectionMappingTest.java | 19 +++-------------- .../defaultimplementation/NoSetterMapper.java | 19 +++-------------- .../defaultimplementation/NoSetterSource.java | 19 +++-------------- .../defaultimplementation/NoSetterTarget.java | 19 +++-------------- .../defaultimplementation/Source.java | 19 +++-------------- .../defaultimplementation/SourceFoo.java | 19 +++-------------- .../SourceTargetMapper.java | 19 +++-------------- .../defaultimplementation/Target.java | 19 +++-------------- .../defaultimplementation/TargetFoo.java | 19 +++-------------- .../EmptyItererableMappingMapper.java | 19 +++-------------- .../erroneous/EmptyMapMappingMapper.java | 19 +++-------------- .../ErroneousCollectionMappingTest.java | 19 +++-------------- ...oneousCollectionNoElementMappingFound.java | 19 +++-------------- ...tionNoElementMappingFoundDisabledAuto.java | 19 +++-------------- .../ErroneousCollectionNoKeyMappingFound.java | 19 +++-------------- ...llectionNoKeyMappingFoundDisabledAuto.java | 19 +++-------------- ...rroneousCollectionNoValueMappingFound.java | 19 +++-------------- ...ectionNoValueMappingFoundDisabledAuto.java | 19 +++-------------- ...oneousCollectionToNonCollectionMapper.java | 19 +++-------------- ...usCollectionToPrimitivePropertyMapper.java | 19 +++-------------- .../ap/test/collection/erroneous/Source.java | 19 +++-------------- .../ap/test/collection/erroneous/Target.java | 19 +++-------------- .../ap/test/collection/forged/Bar.java | 19 +++-------------- .../collection/forged/CollectionMapper.java | 19 +++-------------- ...onMapperNullValueMappingReturnDefault.java | 19 +++-------------- .../forged/CollectionMappingTest.java | 19 +++-------------- ...roneousCollectionNonMappableMapMapper.java | 19 +++-------------- ...roneousCollectionNonMappableSetMapper.java | 19 +++-------------- .../forged/ErroneousNonMappableMapSource.java | 19 +++-------------- .../forged/ErroneousNonMappableMapTarget.java | 19 +++-------------- .../forged/ErroneousNonMappableSetSource.java | 19 +++-------------- .../forged/ErroneousNonMappableSetTarget.java | 19 +++-------------- .../ap/test/collection/forged/Foo.java | 19 +++-------------- .../ap/test/collection/forged/Source.java | 19 +++-------------- .../ap/test/collection/forged/Target.java | 19 +++-------------- .../immutabletarget/CupboardDto.java | 19 +++-------------- .../immutabletarget/CupboardEntity.java | 19 +++-------------- .../CupboardEntityOnlyGetter.java | 19 +++-------------- .../immutabletarget/CupboardMapper.java | 19 +++-------------- .../ErroneousCupboardMapper.java | 19 +++-------------- .../immutabletarget/ImmutableProductTest.java | 19 +++-------------- .../IterableToNonIterableMappingTest.java | 19 +++-------------- .../iterabletononiterable/Source.java | 19 +++-------------- .../SourceTargetMapper.java | 19 +++-------------- .../StringListMapper.java | 19 +++-------------- .../iterabletononiterable/Target.java | 19 +++-------------- .../collection/map/CustomNumberMapper.java | 19 +++-------------- .../test/collection/map/MapMappingTest.java | 19 +++-------------- .../ap/test/collection/map/Source.java | 19 +++-------------- .../collection/map/SourceTargetMapper.java | 19 +++-------------- .../ap/test/collection/map/Target.java | 19 +++-------------- .../collection/map/other/ImportedType.java | 19 +++-------------- .../test/collection/wildcard/BeanMapper.java | 19 +++-------------- .../test/collection/wildcard/CunningPlan.java | 19 +++-------------- ...neousIterableExtendsBoundTargetMapper.java | 19 +++-------------- ...roneousIterableSuperBoundSourceMapper.java | 19 +++-------------- ...ousIterableTypeVarBoundMapperOnMapper.java | 19 +++-------------- ...ousIterableTypeVarBoundMapperOnMethod.java | 19 +++-------------- .../wildcard/ExtendsBoundSource.java | 19 +++-------------- .../ExtendsBoundSourceTargetMapper.java | 19 +++-------------- .../ap/test/collection/wildcard/GoodIdea.java | 19 +++-------------- .../ap/test/collection/wildcard/Idea.java | 19 +++-------------- .../ap/test/collection/wildcard/Plan.java | 19 +++-------------- .../ap/test/collection/wildcard/Source.java | 19 +++-------------- .../SourceSuperBoundTargetMapper.java | 19 +++-------------- .../collection/wildcard/SuperBoundTarget.java | 19 +++-------------- .../ap/test/collection/wildcard/Target.java | 19 +++-------------- .../collection/wildcard/WildCardTest.java | 19 +++-------------- .../mapstruct/ap/test/complex/CarMapper.java | 19 +++-------------- .../ap/test/complex/CarMapperTest.java | 19 +++-------------- .../ap/test/complex/_target/CarDto.java | 19 +++-------------- .../ap/test/complex/_target/PersonDto.java | 19 +++-------------- .../ap/test/complex/other/DateMapper.java | 19 +++-------------- .../mapstruct/ap/test/complex/source/Car.java | 19 +++-------------- .../ap/test/complex/source/Category.java | 19 +++-------------- .../ap/test/complex/source/Person.java | 19 +++-------------- .../AutomappingNodeMapperWithContext.java | 19 +++-------------- ...ngNodeMapperWithSelfContainingContext.java | 19 +++-------------- .../ContextParameterErroneousTest.java | 19 +++-------------- .../ap/test/context/ContextParameterTest.java | 19 +++-------------- .../ap/test/context/CycleContext.java | 19 +++-------------- .../context/CycleContextLifecycleMethods.java | 19 +++-------------- .../ap/test/context/FactoryContext.java | 19 +++-------------- .../test/context/FactoryContextMethods.java | 19 +++-------------- .../org/mapstruct/ap/test/context/Node.java | 19 +++-------------- .../mapstruct/ap/test/context/NodeDto.java | 19 +++-------------- .../test/context/NodeMapperWithContext.java | 19 +++-------------- .../context/SelfContainingCycleContext.java | 19 +++-------------- ...usNodeMapperWithNonUniqueContextTypes.java | 19 +++-------------- .../objectfactory/ContextObjectFactory.java | 19 +++-------------- .../ContextWithObjectFactoryMapper.java | 19 +++-------------- .../ContextWithObjectFactoryTest.java | 19 +++-------------- .../ap/test/context/objectfactory/Valve.java | 19 +++-------------- .../test/context/objectfactory/ValveDto.java | 19 +++-------------- .../ap/test/conversion/ConversionTest.java | 19 +++-------------- .../mapstruct/ap/test/conversion/Source.java | 19 +++-------------- .../test/conversion/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/conversion/Target.java | 19 +++-------------- .../bignumbers/BigDecimalMapper.java | 19 +++-------------- .../bignumbers/BigDecimalSource.java | 19 +++-------------- .../bignumbers/BigDecimalTarget.java | 19 +++-------------- .../bignumbers/BigIntegerMapper.java | 19 +++-------------- .../bignumbers/BigIntegerSource.java | 19 +++-------------- .../bignumbers/BigIntegerTarget.java | 19 +++-------------- .../bignumbers/BigNumbersConversionTest.java | 19 +++-------------- .../currency/CurrencyConversionTest.java | 19 +++-------------- .../conversion/currency/CurrencyMapper.java | 19 +++-------------- .../conversion/currency/CurrencySource.java | 19 +++-------------- .../conversion/currency/CurrencyTarget.java | 19 +++-------------- .../conversion/date/DateConversionTest.java | 19 +++-------------- .../ap/test/conversion/date/Source.java | 19 +++-------------- .../conversion/date/SourceTargetMapper.java | 19 +++-------------- .../ap/test/conversion/date/Target.java | 19 +++-------------- .../erroneous/ErroneousFormatMapper.java | 19 +++-------------- .../erroneous/InvalidDateFormatTest.java | 19 +++-------------- .../ap/test/conversion/erroneous/Source.java | 19 +++-------------- .../ap/test/conversion/erroneous/Target.java | 19 +++-------------- .../java8time/Java8TimeConversionTest.java | 19 +++-------------- ...eToXMLGregorianCalendarConversionTest.java | 19 +++-------------- .../ap/test/conversion/java8time/Source.java | 19 +++-------------- .../java8time/SourceTargetMapper.java | 19 +++-------------- .../ap/test/conversion/java8time/Target.java | 19 +++-------------- .../Source.java | 19 +++-------------- .../SourceTargetMapper.java | 19 +++-------------- .../Target.java | 19 +++-------------- .../jodatime/JodaConversionTest.java | 19 +++-------------- .../ap/test/conversion/jodatime/Source.java | 19 +++-------------- .../jodatime/SourceTargetMapper.java | 19 +++-------------- .../jodatime/SourceWithStringDate.java | 19 +++-------------- .../jodatime/StringToLocalDateMapper.java | 19 +++-------------- .../ap/test/conversion/jodatime/Target.java | 19 +++-------------- .../jodatime/TargetWithLocalDate.java | 19 +++-------------- .../nativetypes/BooleanConversionTest.java | 19 +++-------------- .../conversion/nativetypes/BooleanMapper.java | 19 +++-------------- .../conversion/nativetypes/BooleanSource.java | 19 +++-------------- .../conversion/nativetypes/BooleanTarget.java | 19 +++-------------- .../conversion/nativetypes/ByteSource.java | 19 +++-------------- .../conversion/nativetypes/ByteTarget.java | 19 +++-------------- .../nativetypes/ByteWrapperSource.java | 19 +++-------------- .../nativetypes/ByteWrapperTarget.java | 19 +++-------------- .../nativetypes/CharConversionTest.java | 19 +++-------------- .../conversion/nativetypes/CharMapper.java | 19 +++-------------- .../conversion/nativetypes/CharSource.java | 19 +++-------------- .../conversion/nativetypes/CharTarget.java | 19 +++-------------- .../conversion/nativetypes/DoubleSource.java | 19 +++-------------- .../conversion/nativetypes/DoubleTarget.java | 19 +++-------------- .../nativetypes/DoubleWrapperSource.java | 19 +++-------------- .../nativetypes/DoubleWrapperTarget.java | 19 +++-------------- .../conversion/nativetypes/FloatSource.java | 19 +++-------------- .../conversion/nativetypes/FloatTarget.java | 19 +++-------------- .../nativetypes/FloatWrapperSource.java | 19 +++-------------- .../nativetypes/FloatWrapperTarget.java | 19 +++-------------- .../conversion/nativetypes/IntSource.java | 19 +++-------------- .../conversion/nativetypes/IntTarget.java | 19 +++-------------- .../nativetypes/IntWrapperSource.java | 19 +++-------------- .../nativetypes/IntWrapperTarget.java | 19 +++-------------- .../conversion/nativetypes/LongSource.java | 19 +++-------------- .../conversion/nativetypes/LongTarget.java | 19 +++-------------- .../nativetypes/LongWrapperSource.java | 19 +++-------------- .../nativetypes/LongWrapperTarget.java | 19 +++-------------- .../nativetypes/NumberConversionTest.java | 19 +++-------------- .../conversion/nativetypes/ShortSource.java | 19 +++-------------- .../conversion/nativetypes/ShortTarget.java | 19 +++-------------- .../nativetypes/ShortWrapperSource.java | 19 +++-------------- .../nativetypes/ShortWrapperTarget.java | 19 +++-------------- .../nativetypes/SourceTargetMapper.java | 19 +++-------------- .../numbers/NumberFormatConversionTest.java | 19 +++-------------- .../ap/test/conversion/numbers/Source.java | 19 +++-------------- .../numbers/SourceTargetMapper.java | 19 +++-------------- .../ap/test/conversion/numbers/Target.java | 19 +++-------------- .../conversion/precedence/ConversionTest.java | 19 +++-------------- .../precedence/IntegerStringMapper.java | 19 +++-------------- .../ap/test/conversion/precedence/Source.java | 19 +++-------------- .../precedence/SourceTargetMapper.java | 19 +++-------------- .../ap/test/conversion/precedence/Target.java | 19 +++-------------- .../ap/test/conversion/string/Source.java | 19 +++-------------- .../conversion/string/SourceTargetMapper.java | 19 +++-------------- .../string/StringConversionTest.java | 19 +++-------------- .../ap/test/conversion/string/Target.java | 19 +++-------------- .../mapstruct/ap/test/decorator/Address.java | 19 +++-------------- .../ap/test/decorator/AddressDto.java | 19 +++-------------- .../test/decorator/AnotherPersonMapper.java | 19 +++-------------- .../AnotherPersonMapperDecorator.java | 19 +++-------------- .../ap/test/decorator/DecoratorTest.java | 19 +++-------------- .../mapstruct/ap/test/decorator/Employer.java | 19 +++-------------- .../ap/test/decorator/EmployerDto.java | 19 +++-------------- .../ap/test/decorator/EmployerMapper.java | 19 +++-------------- .../test/decorator/ErroneousPersonMapper.java | 19 +++-------------- .../ErroneousPersonMapperDecorator.java | 19 +++-------------- .../mapstruct/ap/test/decorator/Person.java | 19 +++-------------- .../mapstruct/ap/test/decorator/Person2.java | 19 +++-------------- .../ap/test/decorator/Person2Mapper.java | 19 +++-------------- .../decorator/Person2MapperDecorator.java | 19 +++-------------- .../ap/test/decorator/PersonDto.java | 19 +++-------------- .../ap/test/decorator/PersonDto2.java | 19 +++-------------- .../ap/test/decorator/PersonMapper.java | 19 +++-------------- .../test/decorator/PersonMapperDecorator.java | 19 +++-------------- .../ap/test/decorator/SportsClub.java | 19 +++-------------- .../ap/test/decorator/SportsClubDto.java | 19 +++-------------- .../decorator/YetAnotherPersonMapper.java | 19 +++-------------- .../YetAnotherPersonMapperDecorator.java | 19 +++-------------- .../decorator/jsr330/Jsr330DecoratorTest.java | 19 +++-------------- .../test/decorator/jsr330/PersonMapper.java | 19 +++-------------- .../jsr330/PersonMapperDecorator.java | 19 +++-------------- .../spring/constructor/PersonMapper.java | 19 +++-------------- .../constructor/PersonMapperDecorator.java | 19 +++-------------- .../constructor/SpringDecoratorTest.java | 19 +++-------------- .../decorator/spring/field/PersonMapper.java | 19 +++-------------- .../spring/field/PersonMapperDecorator.java | 19 +++-------------- .../spring/field/SpringDecoratorTest.java | 19 +++-------------- .../ap/test/defaultvalue/CountryDts.java | 19 +++-------------- .../ap/test/defaultvalue/CountryEntity.java | 19 +++-------------- .../ap/test/defaultvalue/CountryMapper.java | 19 +++-------------- .../test/defaultvalue/DefaultValueTest.java | 19 +++-------------- .../ap/test/defaultvalue/ErroneousMapper.java | 19 +++-------------- .../test/defaultvalue/ErroneousMapper2.java | 19 +++-------------- .../ap/test/defaultvalue/Region.java | 19 +++-------------- .../ap/test/defaultvalue/other/Continent.java | 19 +++-------------- .../mapstruct/ap/test/dependency/Address.java | 19 +++-------------- .../ap/test/dependency/AddressDto.java | 19 +++-------------- .../ap/test/dependency/AddressMapper.java | 19 +++-------------- ...eousAddressMapperWithCyclicDependency.java | 19 +++-------------- ...sMapperWithUnknownPropertyInDependsOn.java | 19 +++-------------- .../ap/test/dependency/GraphAnalyzerTest.java | 19 +++-------------- .../ap/test/dependency/OrderingTest.java | 19 +++-------------- .../mapstruct/ap/test/dependency/Person.java | 19 +++-------------- .../ap/test/dependency/PersonDto.java | 19 +++-------------- .../AbstractDestinationClassNameMapper.java | 19 +++-------------- .../AbstractDestinationPackageNameMapper.java | 19 +++-------------- .../DestinationClassNameMapper.java | 19 +++-------------- .../DestinationClassNameMapperConfig.java | 19 +++-------------- .../DestinationClassNameMapperDecorated.java | 19 +++-------------- .../DestinationClassNameMapperDecorator.java | 19 +++-------------- .../DestinationClassNameMapperWithConfig.java | 19 +++-------------- ...tionClassNameMapperWithConfigOverride.java | 19 +++-------------- .../destination/DestinationClassNameTest.java | 19 +++-------------- .../DestinationClassNameWithJsr330Mapper.java | 19 +++-------------- .../DestinationPackageNameMapper.java | 19 +++-------------- .../DestinationPackageNameMapperConfig.java | 19 +++-------------- ...DestinationPackageNameMapperDecorated.java | 19 +++-------------- ...DestinationPackageNameMapperDecorator.java | 19 +++-------------- ...estinationPackageNameMapperWithConfig.java | 19 +++-------------- ...onPackageNameMapperWithConfigOverride.java | 19 +++-------------- ...estinationPackageNameMapperWithSuffix.java | 19 +++-------------- .../DestinationPackageNameTest.java | 19 +++-------------- .../ap/test/enums/EnumMappingTest.java | 19 +++-------------- ...usOrderMapperMappingSameConstantTwice.java | 19 +++-------------- ...ppingConstantWithoutMatchInTargetType.java | 19 +++-------------- ...sOrderMapperUsingUnknownEnumConstants.java | 19 +++-------------- .../ap/test/enums/ExternalOrderType.java | 19 +++-------------- .../org/mapstruct/ap/test/enums/OrderDto.java | 19 +++-------------- .../mapstruct/ap/test/enums/OrderEntity.java | 19 +++-------------- .../mapstruct/ap/test/enums/OrderMapper.java | 19 +++-------------- .../mapstruct/ap/test/enums/OrderType.java | 19 +++-------------- .../AmbiguousAnnotatedFactoryTest.java | 19 +++-------------- .../AmbiguousBarFactory.java | 19 +++-------------- .../ambiguousannotatedfactorymethod/Bar.java | 19 +++-------------- .../ambiguousannotatedfactorymethod/Foo.java | 19 +++-------------- .../Source.java | 19 +++-------------- .../SourceTargetMapperAndBarFactory.java | 19 +++-------------- .../Target.java | 19 +++-------------- .../erroneous/ambiguousfactorymethod/Bar.java | 19 +++-------------- .../ambiguousfactorymethod/FactoryTest.java | 19 +++-------------- .../erroneous/ambiguousfactorymethod/Foo.java | 19 +++-------------- .../ambiguousfactorymethod/Source.java | 19 +++-------------- .../SourceTargetMapperAndBarFactory.java | 19 +++-------------- .../ambiguousfactorymethod/Target.java | 19 +++-------------- .../ambiguousfactorymethod/a/BarFactory.java | 19 +++-------------- .../AnnotationNotFoundTest.java | 19 +++-------------- .../annotationnotfound/ErroneousMapper.java | 19 +++-------------- .../NotFoundAnnotation.java | 19 +++-------------- .../erroneous/annotationnotfound/Source.java | 19 +++-------------- .../erroneous/annotationnotfound/Target.java | 19 +++-------------- .../attributereference/AnotherTarget.java | 19 +++-------------- .../attributereference/DummySource.java | 19 +++-------------- .../attributereference/ErroneousMapper.java | 19 +++-------------- .../attributereference/ErroneousMapper1.java | 19 +++-------------- .../attributereference/ErroneousMapper2.java | 19 +++-------------- .../ErroneousMappingsTest.java | 19 +++-------------- .../erroneous/attributereference/Source.java | 19 +++-------------- .../erroneous/attributereference/Target.java | 19 +++-------------- .../MapperWithMalformedExpression.java | 19 +++-------------- .../MisbalancedBracesTest.java | 19 +++-------------- .../erroneous/misbalancedbraces/Source.java | 19 +++-------------- .../erroneous/misbalancedbraces/Target.java | 19 +++-------------- .../typemismatch/ErroneousMapper.java | 19 +++-------------- .../typemismatch/ErroneousMappingsTest.java | 19 +++-------------- .../test/erroneous/typemismatch/Source.java | 19 +++-------------- .../test/erroneous/typemismatch/Target.java | 19 +++-------------- .../ap/test/exceptions/ExceptionTest.java | 19 +++-------------- .../exceptions/ExceptionTestDecorator.java | 19 +++-------------- .../test/exceptions/ExceptionTestMapper.java | 19 +++-------------- .../mapstruct/ap/test/exceptions/Source.java | 19 +++-------------- .../test/exceptions/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/exceptions/Target.java | 19 +++-------------- .../ap/test/exceptions/TestException2.java | 19 +++-------------- .../exceptions/imports/TestException1.java | 19 +++-------------- .../exceptions/imports/TestExceptionBase.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Bar1.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Bar2.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Bar3.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Bar4.java | 19 +++-------------- .../ap/test/factories/CustomList.java | 19 +++-------------- .../ap/test/factories/CustomListImpl.java | 19 +++-------------- .../ap/test/factories/CustomMap.java | 19 +++-------------- .../ap/test/factories/CustomMapImpl.java | 19 +++-------------- .../ap/test/factories/FactoryCreatable.java | 19 +++-------------- .../ap/test/factories/FactoryTest.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Foo1.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Foo2.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Foo3.java | 19 +++-------------- .../org/mapstruct/ap/test/factories/Foo4.java | 19 +++-------------- .../ap/test/factories/GenericFactory.java | 19 +++-------------- .../mapstruct/ap/test/factories/Source.java | 19 +++-------------- .../SourceTargetMapperAndBar2Factory.java | 19 +++-------------- .../SourceTargetMapperWithGenericFactory.java | 19 +++-------------- .../mapstruct/ap/test/factories/Target.java | 19 +++-------------- .../ap/test/factories/a/BarFactory.java | 19 +++-------------- .../ap/test/factories/assignment/Bar5.java | 19 +++-------------- .../factories/assignment/Bar5Factory.java | 19 +++-------------- .../ap/test/factories/assignment/Bar6.java | 19 +++-------------- .../factories/assignment/Bar6Factory.java | 19 +++-------------- .../ap/test/factories/assignment/Bar7.java | 19 +++-------------- .../factories/assignment/Bar7Factory.java | 19 +++-------------- .../ap/test/factories/assignment/Foo5A.java | 19 +++-------------- .../ap/test/factories/assignment/Foo5B.java | 19 +++-------------- .../ap/test/factories/assignment/Foo6A.java | 19 +++-------------- .../ap/test/factories/assignment/Foo6B.java | 19 +++-------------- .../ap/test/factories/assignment/Foo7A.java | 19 +++-------------- .../ap/test/factories/assignment/Foo7B.java | 19 +++-------------- .../ParameterAssigmentFactoryTest.java | 19 +++-------------- .../ParameterAssignmentFactoryTestMapper.java | 19 +++-------------- .../ap/test/factories/b/BarFactory.java | 19 +++-------------- .../ap/test/factories/c/BarFactory.java | 19 +++-------------- .../ap/test/factories/qualified/Bar10.java | 19 +++-------------- .../factories/qualified/Bar10Factory.java | 19 +++-------------- .../ap/test/factories/qualified/Foo10.java | 19 +++-------------- .../qualified/QualifiedFactoryTest.java | 19 +++-------------- .../qualified/QualifiedFactoryTestMapper.java | 19 +++-------------- .../factories/qualified/TestQualifier.java | 19 +++-------------- .../test/factories/targettype/Bar9Base.java | 19 +++-------------- .../test/factories/targettype/Bar9Child.java | 19 +++-------------- .../factories/targettype/Bar9Factory.java | 19 +++-------------- .../test/factories/targettype/Foo9Base.java | 19 +++-------------- .../test/factories/targettype/Foo9Child.java | 19 +++-------------- .../targettype/ProductTypeFactoryTest.java | 19 +++-------------- .../TargetTypeFactoryTestMapper.java | 19 +++-------------- .../ap/test/fields/FieldsMappingTest.java | 19 +++-------------- .../org/mapstruct/ap/test/fields/Source.java | 19 +++-------------- .../ap/test/fields/SourceTargetMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/fields/Target.java | 19 +++-------------- .../ap/test/generics/AbstractIdHoldingTo.java | 19 +++-------------- .../ap/test/generics/AbstractTo.java | 19 +++-------------- .../ap/test/generics/GenericsTest.java | 19 +++-------------- .../mapstruct/ap/test/generics/Source.java | 19 +++-------------- .../ap/test/generics/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/generics/TargetTo.java | 19 +++-------------- .../generics/genericsupertype/MapperBase.java | 19 +++-------------- .../MapperWithGenericSuperClassTest.java | 19 +++-------------- .../genericsupertype/SearchResult.java | 19 +++-------------- .../generics/genericsupertype/Vessel.java | 19 +++-------------- .../generics/genericsupertype/VesselDto.java | 19 +++-------------- .../VesselSearchResultMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/ignore/Animal.java | 19 +++-------------- .../mapstruct/ap/test/ignore/AnimalDto.java | 19 +++-------------- .../ap/test/ignore/AnimalMapper.java | 19 +++-------------- ...roneousTargetHasNoWriteAccessorMapper.java | 19 +++-------------- .../ap/test/ignore/IgnorePropertyTest.java | 19 +++-------------- .../mapstruct/ap/test/ignore/Preditor.java | 19 +++-------------- .../mapstruct/ap/test/ignore/PreditorDto.java | 19 +++-------------- .../test/ignore/expand/ExpandedToolbox.java | 19 +++-------------- .../test/ignore/expand/FlattenedToolBox.java | 19 +++-------------- .../ap/test/ignore/expand/Hammer.java | 19 +++-------------- .../ignore/expand/IgnorePropertyTest.java | 19 +++-------------- .../ap/test/ignore/expand/ToolBoxMapper.java | 19 +++-------------- .../ap/test/ignore/expand/Wrench.java | 19 +++-------------- .../ap/test/ignore/inherit/BaseEntity.java | 19 +++-------------- .../ap/test/ignore/inherit/HammerDto.java | 19 +++-------------- .../ap/test/ignore/inherit/HammerEntity.java | 19 +++-------------- .../ignore/inherit/IgnorePropertyTest.java | 19 +++-------------- .../ap/test/ignore/inherit/ToolDto.java | 19 +++-------------- .../ap/test/ignore/inherit/ToolEntity.java | 19 +++-------------- .../ap/test/ignore/inherit/ToolMapper.java | 19 +++-------------- .../ap/test/ignore/inherit/WorkBenchDto.java | 19 +++-------------- .../test/ignore/inherit/WorkBenchEntity.java | 19 +++-------------- .../imports/ConflictingTypesNamesTest.java | 19 +++-------------- .../test/imports/InnerClassesImportsTest.java | 19 +++-------------- .../org/mapstruct/ap/test/imports/List.java | 19 +++-------------- .../org/mapstruct/ap/test/imports/Map.java | 19 +++-------------- .../org/mapstruct/ap/test/imports/Named.java | 19 +++-------------- .../ap/test/imports/ParseException.java | 19 +++-------------- .../imports/SecondSourceTargetMapper.java | 19 +++-------------- .../ap/test/imports/SourceTargetMapper.java | 19 +++-------------- .../ap/test/imports/decorator/Actor.java | 19 +++-------------- .../ap/test/imports/decorator/ActorDto.java | 19 +++-------------- .../test/imports/decorator/ActorMapper.java | 19 +++-------------- .../DecoratorInAnotherPackageTest.java | 19 +++-------------- .../decorator/other/ActorMapperDecorator.java | 19 +++-------------- .../mapstruct/ap/test/imports/from/Foo.java | 19 +++-------------- .../ap/test/imports/from/FooWrapper.java | 19 +++-------------- .../test/imports/innerclasses/BeanFacade.java | 19 +++-------------- .../innerclasses/BeanWithInnerEnum.java | 19 +++-------------- .../innerclasses/BeanWithInnerEnumMapper.java | 19 +++-------------- .../innerclasses/InnerClassMapper.java | 19 +++-------------- .../innerclasses/SourceWithInnerClass.java | 19 +++-------------- .../innerclasses/TargetWithInnerClass.java | 19 +++-------------- .../imports/referenced/GenericMapper.java | 19 +++-------------- .../referenced/NotImportedDatatype.java | 19 +++-------------- .../ap/test/imports/referenced/Source.java | 19 +++-------------- .../ap/test/imports/referenced/Target.java | 19 +++-------------- ...ontainsCollectionWithExtendsBoundTest.java | 19 +++-------------- .../SpaceshipMapper.java | 19 +++-------------- .../astronautmapper/AstronautMapper.java | 19 +++-------------- .../dto/AstronautDto.java | 19 +++-------------- .../dto/SpaceshipDto.java | 19 +++-------------- .../entity/Astronaut.java | 19 +++-------------- .../entity/Spaceship.java | 19 +++-------------- .../org/mapstruct/ap/test/imports/to/Foo.java | 19 +++-------------- .../ap/test/imports/to/FooWrapper.java | 19 +++-------------- .../ap/test/inheritance/InheritanceTest.java | 19 +++-------------- .../ap/test/inheritance/SourceBase.java | 19 +++-------------- .../ap/test/inheritance/SourceExt.java | 19 +++-------------- .../test/inheritance/SourceTargetMapper.java | 19 +++-------------- .../ap/test/inheritance/TargetBase.java | 19 +++-------------- .../ap/test/inheritance/TargetExt.java | 19 +++-------------- .../attribute/AttributeInheritanceTest.java | 19 +++-------------- .../ErroneousTargetSourceMapper.java | 19 +++-------------- .../ap/test/inheritance/attribute/Source.java | 19 +++-------------- .../attribute/SourceTargetMapper.java | 19 +++-------------- .../ap/test/inheritance/attribute/Target.java | 19 +++-------------- .../complex/AdditionalFooSource.java | 19 +++-------------- .../complex/AdditionalMappingHelper.java | 19 +++-------------- .../complex/ComplexInheritanceTest.java | 19 +++-------------- ...sSourceCompositeTargetCompositeMapper.java | 19 +++-------------- .../test/inheritance/complex/Reference.java | 19 +++-------------- .../test/inheritance/complex/SourceBase.java | 19 +++-------------- .../complex/SourceBaseMappingHelper.java | 19 +++-------------- .../inheritance/complex/SourceComposite.java | 19 +++-------------- .../SourceCompositeTargetCompositeMapper.java | 19 +++-------------- .../test/inheritance/complex/SourceExt.java | 19 +++-------------- .../test/inheritance/complex/SourceExt2.java | 19 +++-------------- ...eSourceCompositeTargetCompositeMapper.java | 19 +++-------------- .../inheritance/complex/TargetComposite.java | 19 +++-------------- .../inheritedmappingmethod/BoundMappable.java | 19 +++-------------- .../inheritedmappingmethod/CarMapper.java | 19 +++-------------- .../inheritedmappingmethod/FastCarMapper.java | 19 +++-------------- .../InheritedMappingMethodTest.java | 19 +++-------------- .../UnboundMappable.java | 19 +++-------------- .../_target/CarDto.java | 19 +++-------------- .../_target/FastCarDto.java | 19 +++-------------- .../inheritedmappingmethod/source/Car.java | 19 +++-------------- .../source/FastCar.java | 19 +++-------------- .../AutoInheritedAllConfig.java | 19 +++-------------- .../AutoInheritedConfig.java | 19 +++-------------- .../AutoInheritedDriverConfig.java | 19 +++-------------- .../AutoInheritedReverseConfig.java | 19 +++-------------- .../inheritfromconfig/BaseVehicleDto.java | 19 +++-------------- .../inheritfromconfig/BaseVehicleEntity.java | 19 +++-------------- .../ap/test/inheritfromconfig/CarDto.java | 19 +++-------------- .../ap/test/inheritfromconfig/CarEntity.java | 19 +++-------------- .../CarMapperAllWithAutoInheritance.java | 19 +++-------------- .../CarMapperReverseWithAutoInheritance.java | 19 +++-------------- ...rMapperReverseWithExplicitInheritance.java | 19 +++-------------- .../CarMapperWithAutoInheritance.java | 19 +++-------------- .../CarMapperWithExplicitInheritance.java | 19 +++-------------- .../CarWithDriverEntity.java | 19 +++-------------- ...arWithDriverMapperWithAutoInheritance.java | 19 +++-------------- .../ap/test/inheritfromconfig/DriverDto.java | 19 +++-------------- .../inheritfromconfig/Erroneous1Config.java | 19 +++-------------- .../inheritfromconfig/Erroneous1Mapper.java | 19 +++-------------- .../inheritfromconfig/Erroneous2Mapper.java | 19 +++-------------- .../inheritfromconfig/Erroneous3Config.java | 19 +++-------------- .../inheritfromconfig/Erroneous3Mapper.java | 19 +++-------------- .../ErroneousMapperAutoInheritance.java | 19 +++-------------- ...neousMapperReverseWithAutoInheritance.java | 19 +++-------------- .../InheritFromConfigTest.java | 19 +++-------------- .../inheritfromconfig/NotToBeUsedMapper.java | 19 +++-------------- .../inheritfromconfig/multiple/BaseDto.java | 19 +++-------------- .../multiple/BaseEntity.java | 19 +++-------------- .../inheritfromconfig/multiple/Car2Dto.java | 19 +++-------------- .../multiple/Car2Entity.java | 19 +++-------------- .../inheritfromconfig/multiple/CarDto.java | 19 +++-------------- .../inheritfromconfig/multiple/CarEntity.java | 19 +++-------------- .../inheritfromconfig/multiple/CarMapper.java | 19 +++-------------- .../multiple/CarMapper2.java | 19 +++-------------- .../multiple/CarMapperTest.java | 19 +++-------------- .../multiple/EntityToDtoMappingConfig.java | 19 +++-------------- .../constructor/ConstructorJsr330Config.java | 19 +++-------------- .../CustomerJsr330ConstructorMapper.java | 19 +++-------------- .../GenderJsr330ConstructorMapper.java | 19 +++-------------- .../Jsr330ConstructorMapperTest.java | 19 +++-------------- .../field/CustomerJsr330FieldMapper.java | 19 +++-------------- .../jsr330/field/FieldJsr330Config.java | 19 +++-------------- .../jsr330/field/GenderJsr330FieldMapper.java | 19 +++-------------- .../jsr330/field/Jsr330FieldMapperTest.java | 19 +++-------------- .../injectionstrategy/shared/CustomerDto.java | 19 +++-------------- .../shared/CustomerEntity.java | 19 +++-------------- .../test/injectionstrategy/shared/Gender.java | 19 +++-------------- .../injectionstrategy/shared/GenderDto.java | 19 +++-------------- .../_default/CustomerSpringDefaultMapper.java | 19 +++-------------- .../_default/GenderSpringDefaultMapper.java | 19 +++-------------- .../_default/SpringDefaultMapperTest.java | 19 +++-------------- .../constructor/ConstructorSpringConfig.java | 19 +++-------------- .../CustomerSpringConstructorMapper.java | 19 +++-------------- .../GenderSpringConstructorMapper.java | 19 +++-------------- .../SpringConstructorMapperTest.java | 19 +++-------------- .../field/CustomerSpringFieldMapper.java | 19 +++-------------- .../spring/field/FieldSpringConfig.java | 19 +++-------------- .../spring/field/GenderSpringFieldMapper.java | 19 +++-------------- .../spring/field/SpringFieldMapperTest.java | 19 +++-------------- .../mapstruct/ap/test/java8stream/Colour.java | 19 +++-------------- .../mapstruct/ap/test/java8stream/Source.java | 19 +++-------------- .../test/java8stream/SourceTargetMapper.java | 19 +++-------------- .../test/java8stream/StreamMappingTest.java | 19 +++-------------- .../ap/test/java8stream/StringHolder.java | 19 +++-------------- .../java8stream/StringHolderArrayList.java | 19 +++-------------- .../mapstruct/ap/test/java8stream/Target.java | 19 +++-------------- .../ap/test/java8stream/TestList.java | 19 +++-------------- .../java8stream/base/MyCustomException.java | 19 +++-------------- .../ap/test/java8stream/base/Source.java | 19 +++-------------- .../test/java8stream/base/SourceElement.java | 19 +++-------------- .../test/java8stream/base/StreamMapper.java | 19 +++-------------- .../ap/test/java8stream/base/StreamsTest.java | 19 +++-------------- .../ap/test/java8stream/base/Target.java | 19 +++-------------- .../test/java8stream/base/TargetElement.java | 19 +++-------------- .../java8stream/context/StreamContext.java | 19 +++-------------- .../context/StreamWithContextMapper.java | 19 +++-------------- .../context/StreamWithContextTest.java | 19 +++-------------- .../DefaultStreamImplementationTest.java | 19 +++-------------- .../defaultimplementation/NoSetterMapper.java | 19 +++-------------- .../defaultimplementation/NoSetterSource.java | 19 +++-------------- .../NoSetterStreamMappingTest.java | 19 +++-------------- .../defaultimplementation/NoSetterTarget.java | 19 +++-------------- .../defaultimplementation/Source.java | 19 +++-------------- .../defaultimplementation/SourceFoo.java | 19 +++-------------- .../SourceTargetMapper.java | 19 +++-------------- .../defaultimplementation/Target.java | 19 +++-------------- .../defaultimplementation/TargetFoo.java | 19 +++-------------- .../erroneous/EmptyStreamMappingMapper.java | 19 +++-------------- ...eousListToStreamNoElementMappingFound.java | 19 +++-------------- ...reamNoElementMappingFoundDisabledAuto.java | 19 +++-------------- .../erroneous/ErroneousStreamMappingTest.java | 19 +++-------------- ...eousStreamToListNoElementMappingFound.java | 19 +++-------------- ...ListNoElementMappingFoundDisabledAuto.java | 19 +++-------------- .../ErroneousStreamToNonStreamMapper.java | 19 +++-------------- ...oneousStreamToPrimitivePropertyMapper.java | 19 +++-------------- ...usStreamToStreamNoElementMappingFound.java | 19 +++-------------- ...reamNoElementMappingFoundDisabledAuto.java | 19 +++-------------- .../ap/test/java8stream/erroneous/Source.java | 19 +++-------------- .../ap/test/java8stream/erroneous/Target.java | 19 +++-------------- .../ap/test/java8stream/forged/Bar.java | 19 +++-------------- .../ErroneousNonMappableStreamSource.java | 19 +++-------------- .../ErroneousNonMappableStreamTarget.java | 19 +++-------------- ...rroneousStreamNonMappableStreamMapper.java | 19 +++-------------- .../ap/test/java8stream/forged/Foo.java | 19 +++-------------- .../forged/ForgedStreamMappingTest.java | 19 +++-------------- .../ap/test/java8stream/forged/Source.java | 19 +++-------------- .../test/java8stream/forged/StreamMapper.java | 19 +++-------------- ...amMapperNullValueMappingReturnDefault.java | 19 +++-------------- .../ap/test/java8stream/forged/Target.java | 19 +++-------------- .../streamtononiterable/Source.java | 19 +++-------------- .../SourceTargetMapper.java | 19 +++-------------- .../StreamToNonIterableMappingTest.java | 19 +++-------------- .../streamtononiterable/StringListMapper.java | 19 +++-------------- .../streamtononiterable/Target.java | 19 +++-------------- ...neousIterableExtendsBoundTargetMapper.java | 19 +++-------------- ...roneousIterableSuperBoundSourceMapper.java | 19 +++-------------- ...ousIterableTypeVarBoundMapperOnMapper.java | 19 +++-------------- ...ousIterableTypeVarBoundMapperOnMethod.java | 19 +++-------------- .../wildcard/ExtendsBoundSource.java | 19 +++-------------- .../ExtendsBoundSourceTargetMapper.java | 19 +++-------------- .../ap/test/java8stream/wildcard/Idea.java | 19 +++-------------- .../ap/test/java8stream/wildcard/Plan.java | 19 +++-------------- .../ap/test/java8stream/wildcard/Source.java | 19 +++-------------- .../SourceSuperBoundTargetMapper.java | 19 +++-------------- .../wildcard/SuperBoundTarget.java | 19 +++-------------- .../ap/test/java8stream/wildcard/Target.java | 19 +++-------------- .../java8stream/wildcard/WildCardTest.java | 19 +++-------------- .../ap/test/mapperconfig/BarDto.java | 19 +++-------------- .../ap/test/mapperconfig/BarEntity.java | 19 +++-------------- .../ap/test/mapperconfig/CentralConfig.java | 19 +++-------------- .../ap/test/mapperconfig/ConfigTest.java | 19 +++-------------- .../mapperconfig/CustomMapperViaMapper.java | 19 +++-------------- .../CustomMapperViaMapperConfig.java | 19 +++-------------- .../ap/test/mapperconfig/FooDto.java | 19 +++-------------- .../ap/test/mapperconfig/FooEntity.java | 19 +++-------------- .../ap/test/mapperconfig/Source.java | 19 +++-------------- .../test/mapperconfig/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperErroneous.java | 19 +++-------------- .../mapperconfig/SourceTargetMapperWarn.java | 19 +++-------------- .../ap/test/mapperconfig/Target.java | 19 +++-------------- .../ap/test/mapperconfig/TargetNoFoo.java | 19 +++-------------- .../ap/test/namesuggestion/ColorRgb.java | 19 +++-------------- .../ap/test/namesuggestion/ColorRgbDto.java | 19 +++-------------- .../ap/test/namesuggestion/Garage.java | 19 +++-------------- .../ap/test/namesuggestion/GarageDto.java | 19 +++-------------- .../ap/test/namesuggestion/Person.java | 19 +++-------------- .../ap/test/namesuggestion/PersonDto.java | 19 +++-------------- .../SuggestMostSimilarNameTest.java | 19 +++-------------- .../erroneous/PersonAgeMapper.java | 19 +++-------------- .../PersonGarageWrongSourceMapper.java | 19 +++-------------- .../PersonGarageWrongTargetMapper.java | 19 +++-------------- .../erroneous/PersonNameMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/naming/Break.java | 19 +++-------------- .../org/mapstruct/ap/test/naming/Source.java | 19 +++-------------- .../ap/test/naming/SourceTargetMapper.java | 19 +++-------------- .../ap/test/naming/VariableNamingTest.java | 19 +++-------------- .../org/mapstruct/ap/test/naming/While.java | 19 +++-------------- .../spi/CustomAccessorNamingStrategy.java | 19 +++-------------- .../naming/spi/CustomNamingStrategyTest.java | 19 +++-------------- .../ap/test/naming/spi/GolfPlayer.java | 19 +++-------------- .../ap/test/naming/spi/GolfPlayerDto.java | 19 +++-------------- .../ap/test/naming/spi/GolfPlayerMapper.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/Car.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/CarDto.java | 19 +++-------------- .../ap/test/nestedbeans/DisableConfig.java | 19 +++-------------- ...DisablingNestedSimpleBeansMappingTest.java | 19 +++-------------- .../nestedbeans/DottedErrorMessageTest.java | 19 +++-------------- .../ErroneousDisabledHouseMapper.java | 19 +++-------------- ...ErroneousDisabledViaConfigHouseMapper.java | 19 +++-------------- .../ap/test/nestedbeans/ExternalRoofType.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/House.java | 19 +++-------------- .../ap/test/nestedbeans/HouseDto.java | 19 +++-------------- .../MultipleForgedMethodsTest.java | 19 +++-------------- .../NestedSimpleBeansMappingTest.java | 19 +++-------------- .../ap/test/nestedbeans/RecursionTest.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/Roof.java | 19 +++-------------- .../ap/test/nestedbeans/RoofDto.java | 19 +++-------------- .../ap/test/nestedbeans/RoofType.java | 19 +++-------------- .../ap/test/nestedbeans/TestData.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/User.java | 19 +++-------------- .../ap/test/nestedbeans/UserDto.java | 19 +++-------------- .../nestedbeans/UserDtoMapperClassic.java | 19 +++-------------- .../test/nestedbeans/UserDtoMapperSmart.java | 19 +++-------------- .../nestedbeans/UserDtoUpdateMapperSmart.java | 19 +++-------------- .../mapstruct/ap/test/nestedbeans/Wheel.java | 19 +++-------------- .../ap/test/nestedbeans/WheelDto.java | 19 +++-------------- .../nestedbeans/exceptions/EntityFactory.java | 19 +++-------------- .../exceptions/MappingException.java | 19 +++-------------- .../NestedMappingsWithExceptionTest.java | 19 +++-------------- .../nestedbeans/exceptions/ProjectMapper.java | 19 +++-------------- .../exceptions/_target/DeveloperDto.java | 19 +++-------------- .../exceptions/_target/ProjectDto.java | 19 +++-------------- .../exceptions/source/Developer.java | 19 +++-------------- .../exceptions/source/Project.java | 19 +++-------------- .../ErroneousJavaInternalMapper.java | 19 +++-------------- .../exclusions/ErroneousJavaInternalTest.java | 19 +++-------------- .../test/nestedbeans/exclusions/Source.java | 19 +++-------------- .../test/nestedbeans/exclusions/Target.java | 19 +++-------------- .../CustomMappingExclusionProvider.java | 19 +++-------------- .../ErroneousCustomExclusionMapper.java | 19 +++-------------- .../custom/ErroneousCustomExclusionTest.java | 19 +++-------------- .../nestedbeans/exclusions/custom/Source.java | 19 +++-------------- .../nestedbeans/exclusions/custom/Target.java | 19 +++-------------- .../nestedbeans/maps/AntonymsDictionary.java | 19 +++-------------- .../maps/AntonymsDictionaryDto.java | 19 +++-------------- .../test/nestedbeans/maps/AutoMapMapper.java | 19 +++-------------- .../ap/test/nestedbeans/maps/Word.java | 19 +++-------------- .../ap/test/nestedbeans/maps/WordDto.java | 19 +++-------------- .../mixed/AutomappingAndNestedTest.java | 19 +++-------------- .../nestedbeans/mixed/FishTankMapper.java | 19 +++-------------- .../mixed/FishTankMapperConstant.java | 19 +++-------------- .../mixed/FishTankMapperExpression.java | 19 +++-------------- .../mixed/FishTankMapperWithDocument.java | 19 +++-------------- .../nestedbeans/mixed/_target/FishDto.java | 19 +++-------------- .../mixed/_target/FishTankDto.java | 19 +++-------------- .../FishTankWithNestedDocumentDto.java | 19 +++-------------- .../mixed/_target/MaterialDto.java | 19 +++-------------- .../mixed/_target/MaterialTypeDto.java | 19 +++-------------- .../mixed/_target/OrnamentDto.java | 19 +++-------------- .../mixed/_target/WaterPlantDto.java | 19 +++-------------- .../mixed/_target/WaterQualityDto.java | 19 +++-------------- .../_target/WaterQualityOrganisationDto.java | 19 +++-------------- .../mixed/_target/WaterQualityReportDto.java | 19 +++-------------- .../_target/WaterQualityWithDocumentDto.java | 19 +++-------------- .../test/nestedbeans/mixed/source/Fish.java | 19 +++-------------- .../nestedbeans/mixed/source/FishTank.java | 19 +++-------------- .../nestedbeans/mixed/source/Interior.java | 19 +++-------------- .../mixed/source/MaterialType.java | 19 +++-------------- .../nestedbeans/mixed/source/Ornament.java | 19 +++-------------- .../nestedbeans/mixed/source/WaterPlant.java | 19 +++-------------- .../mixed/source/WaterQuality.java | 19 +++-------------- .../mixed/source/WaterQualityReport.java | 19 +++-------------- .../multiplecollections/Garage.java | 19 +++-------------- .../multiplecollections/GarageDto.java | 19 +++-------------- .../MultipleListMapper.java | 19 +++-------------- .../ap/test/nestedbeans/other/CarDto.java | 19 +++-------------- .../ap/test/nestedbeans/other/HouseDto.java | 19 +++-------------- .../ap/test/nestedbeans/other/RoofDto.java | 19 +++-------------- .../ap/test/nestedbeans/other/UserDto.java | 19 +++-------------- .../ap/test/nestedbeans/other/WheelDto.java | 19 +++-------------- .../recursive/RecursionMapper.java | 19 +++-------------- .../recursive/TreeRecursionMapper.java | 19 +++-------------- .../BaseCollectionElementPropertyMapper.java | 19 +++-------------- .../unmappable/BaseDeepListMapper.java | 19 +++-------------- .../unmappable/BaseDeepMapKeyMapper.java | 19 +++-------------- .../unmappable/BaseDeepMapValueMapper.java | 19 +++-------------- .../unmappable/BaseDeepNestingMapper.java | 19 +++-------------- .../unmappable/BaseValuePropertyMapper.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Car.java | 19 +++-------------- .../test/nestedbeans/unmappable/CarDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Cat.java | 19 +++-------------- .../test/nestedbeans/unmappable/CatDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Color.java | 19 +++-------------- .../test/nestedbeans/unmappable/ColorDto.java | 19 +++-------------- .../test/nestedbeans/unmappable/Computer.java | 19 +++-------------- .../nestedbeans/unmappable/ComputerDto.java | 19 +++-------------- .../nestedbeans/unmappable/Dictionary.java | 19 +++-------------- .../nestedbeans/unmappable/DictionaryDto.java | 19 +++-------------- .../unmappable/ExternalRoofType.java | 19 +++-------------- .../nestedbeans/unmappable/ForeignWord.java | 19 +++-------------- .../unmappable/ForeignWordDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/House.java | 19 +++-------------- .../test/nestedbeans/unmappable/HouseDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Info.java | 19 +++-------------- .../test/nestedbeans/unmappable/InfoDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Roof.java | 19 +++-------------- .../test/nestedbeans/unmappable/RoofDto.java | 19 +++-------------- .../test/nestedbeans/unmappable/RoofType.java | 19 +++-------------- .../unmappable/RoofTypeMapper.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/User.java | 19 +++-------------- .../test/nestedbeans/unmappable/UserDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Wheel.java | 19 +++-------------- .../test/nestedbeans/unmappable/WheelDto.java | 19 +++-------------- .../ap/test/nestedbeans/unmappable/Word.java | 19 +++-------------- .../test/nestedbeans/unmappable/WordDto.java | 19 +++-------------- ...ppableCollectionElementPropertyMapper.java | 19 +++-------------- .../erroneous/UnmappableDeepListMapper.java | 19 +++-------------- .../erroneous/UnmappableDeepMapKeyMapper.java | 19 +++-------------- .../UnmappableDeepMapValueMapper.java | 19 +++-------------- .../UnmappableDeepNestingMapper.java | 19 +++-------------- .../erroneous/UnmappableEnumMapper.java | 19 +++-------------- .../UnmappableValuePropertyMapper.java | 19 +++-------------- ...IgnoreCollectionElementPropertyMapper.java | 19 +++-------------- .../UnmappableIgnoreDeepListMapper.java | 19 +++-------------- .../UnmappableIgnoreDeepMapKeyMapper.java | 19 +++-------------- .../UnmappableIgnoreDeepMapValueMapper.java | 19 +++-------------- .../UnmappableIgnoreDeepNestingMapper.java | 19 +++-------------- .../UnmappableIgnoreValuePropertyMapper.java | 19 +++-------------- ...leWarnCollectionElementPropertyMapper.java | 19 +++-------------- .../warn/UnmappableWarnDeepListMapper.java | 19 +++-------------- .../warn/UnmappableWarnDeepMapKeyMapper.java | 19 +++-------------- .../UnmappableWarnDeepMapValueMapper.java | 19 +++-------------- .../warn/UnmappableWarnDeepNestingMapper.java | 19 +++-------------- .../UnmappableWarnValuePropertyMapper.java | 19 +++-------------- .../NestedMappingMethodInvocationTest.java | 19 +++-------------- .../test/nestedmethodcall/ObjectFactory.java | 19 +++-------------- .../nestedmethodcall/OrderDetailsDto.java | 19 +++-------------- .../nestedmethodcall/OrderDetailsType.java | 19 +++-------------- .../ap/test/nestedmethodcall/OrderDto.java | 19 +++-------------- .../ap/test/nestedmethodcall/OrderType.java | 19 +++-------------- .../OrderTypeToOrderDtoMapper.java | 19 +++-------------- .../ap/test/nestedmethodcall/SourceType.java | 19 +++-------------- .../SourceTypeTargetDtoMapper.java | 19 +++-------------- .../ap/test/nestedmethodcall/TargetDto.java | 19 +++-------------- .../nestedproperties/simple/SimpleMapper.java | 19 +++-------------- .../simple/SimpleNestedPropertiesTest.java | 19 +++-------------- .../simple/_target/TargetObject.java | 19 +++-------------- .../simple/source/SourceProps.java | 19 +++-------------- .../simple/source/SourceRoot.java | 19 +++-------------- .../test/nestedsource/exceptions/Bucket.java | 19 +++-------------- .../exceptions/NestedExceptionTest.java | 19 +++-------------- .../nestedsource/exceptions/NoSuchUser.java | 19 +++-------------- .../nestedsource/exceptions/Resource.java | 19 +++-------------- .../nestedsource/exceptions/ResourceDto.java | 19 +++-------------- .../exceptions/ResourceMapper.java | 19 +++-------------- .../ap/test/nestedsource/exceptions/User.java | 19 +++-------------- .../test/nestedsource/parameter/FontDto.java | 19 +++-------------- .../nestedsource/parameter/LetterDto.java | 19 +++-------------- .../nestedsource/parameter/LetterEntity.java | 19 +++-------------- .../nestedsource/parameter/LetterMapper.java | 19 +++-------------- .../parameter/NormalizingTest.java | 19 +++-------------- .../ArtistToChartEntry.java | 19 +++-------------- .../ArtistToChartEntryAdder.java | 19 +++-------------- .../ArtistToChartEntryComposedReverse.java | 19 +++-------------- .../ArtistToChartEntryConfig.java | 19 +++-------------- .../ArtistToChartEntryErroneous.java | 19 +++-------------- .../ArtistToChartEntryGetter.java | 19 +++-------------- .../ArtistToChartEntryReverse.java | 19 +++-------------- .../ArtistToChartEntryUpdateReverse.java | 19 +++-------------- .../ArtistToChartEntryWithConfigReverse.java | 19 +++-------------- .../ArtistToChartEntryWithFactoryReverse.java | 19 +++-------------- .../ArtistToChartEntryWithIgnoresReverse.java | 19 +++-------------- .../ArtistToChartEntryWithMappingReverse.java | 19 +++-------------- .../NestedSourcePropertiesTest.java | 19 +++-------------- .../ReversingNestedSourcePropertiesTest.java | 19 +++-------------- .../_target/AdderUsageObserver.java | 19 +++-------------- .../_target/BaseChartEntry.java | 19 +++-------------- .../_target/ChartEntry.java | 19 +++-------------- .../_target/ChartEntryComposed.java | 19 +++-------------- .../_target/ChartEntryLabel.java | 19 +++-------------- .../_target/ChartEntryWithBase.java | 19 +++-------------- .../_target/ChartEntryWithMapping.java | 19 +++-------------- .../_target/ChartPositions.java | 19 +++-------------- .../nestedsourceproperties/source/Artist.java | 19 +++-------------- .../nestedsourceproperties/source/Chart.java | 19 +++-------------- .../nestedsourceproperties/source/Label.java | 19 +++-------------- .../nestedsourceproperties/source/Song.java | 19 +++-------------- .../source/SourceDtoFactory.java | 19 +++-------------- .../nestedsourceproperties/source/Studio.java | 19 +++-------------- .../ChartEntryToArtist.java | 19 +++-------------- .../ChartEntryToArtistUpdate.java | 19 +++-------------- .../NestedProductPropertiesTest.java | 19 +++-------------- .../ap/test/nonvoidsetter/Actor.java | 19 +++-------------- .../ap/test/nonvoidsetter/ActorDto.java | 19 +++-------------- .../ap/test/nonvoidsetter/ActorMapper.java | 19 +++-------------- .../nonvoidsetter/NonVoidSettersTest.java | 19 +++-------------- .../ap/test/nullcheck/CustomMapper.java | 19 +++-------------- .../ap/test/nullcheck/MyBigIntWrapper.java | 19 +++-------------- .../ap/test/nullcheck/MyLongWrapper.java | 19 +++-------------- .../ap/test/nullcheck/NullCheckTest.java | 19 +++-------------- .../ap/test/nullcheck/NullObject.java | 19 +++-------------- .../ap/test/nullcheck/NullObjectMapper.java | 19 +++-------------- .../mapstruct/ap/test/nullcheck/Source.java | 19 +++-------------- .../ap/test/nullcheck/SourceTargetMapper.java | 19 +++-------------- .../mapstruct/ap/test/nullcheck/Target.java | 19 +++-------------- .../ap/test/nullvaluemapping/CarMapper.java | 19 +++-------------- .../CarMapperSettingOnConfig.java | 19 +++-------------- .../CarMapperSettingOnMapper.java | 19 +++-------------- .../test/nullvaluemapping/CentralConfig.java | 19 +++-------------- .../NullValueMappingTest.java | 19 +++-------------- .../test/nullvaluemapping/_target/CarDto.java | 19 +++-------------- .../_target/DriverAndCarDto.java | 19 +++-------------- .../ap/test/nullvaluemapping/source/Car.java | 19 +++-------------- .../test/nullvaluemapping/source/Driver.java | 19 +++-------------- .../mapstruct/ap/test/oneway/OnewayTest.java | 19 +++-------------- .../org/mapstruct/ap/test/oneway/Source.java | 19 +++-------------- .../ap/test/oneway/SourceTargetMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/oneway/Target.java | 19 +++-------------- .../mapstruct/ap/test/prism/ConstantTest.java | 19 +++-------------- .../ap/test/prism/EnumPrismsTest.java | 19 +++-------------- .../org/mapstruct/ap/test/references/Bar.java | 19 +++-------------- .../ap/test/references/BaseType.java | 19 +++-------------- .../org/mapstruct/ap/test/references/Foo.java | 19 +++-------------- .../ap/test/references/FooMapper.java | 19 +++-------------- .../ap/test/references/GenericWrapper.java | 19 +++-------------- .../references/ReferencedCustomMapper.java | 19 +++-------------- .../test/references/ReferencedMapperTest.java | 19 +++-------------- .../ap/test/references/SomeOtherType.java | 19 +++-------------- .../ap/test/references/SomeType.java | 19 +++-------------- .../mapstruct/ap/test/references/Source.java | 19 +++-------------- .../test/references/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperWithPrimitives.java | 19 +++-------------- .../test/references/SourceWithWrappers.java | 19 +++-------------- .../mapstruct/ap/test/references/Target.java | 19 +++-------------- .../test/references/TargetWithPrimitives.java | 19 +++-------------- .../samename/Jsr330SourceTargetMapper.java | 19 +++-------------- ...ferencedMappersWithSameSimpleNameTest.java | 19 +++-------------- .../samename/SourceTargetMapper.java | 19 +++-------------- .../samename/a/AnotherSourceTargetMapper.java | 19 +++-------------- .../references/samename/a/CustomMapper.java | 19 +++-------------- .../references/samename/b/CustomMapper.java | 19 +++-------------- .../references/samename/model/Source.java | 19 +++-------------- .../references/samename/model/Target.java | 19 +++-------------- .../ap/test/references/statics/Beer.java | 19 +++-------------- .../ap/test/references/statics/BeerDto.java | 19 +++-------------- .../test/references/statics/BeerMapper.java | 19 +++-------------- .../statics/BeerMapperWithNonUsedMapper.java | 19 +++-------------- .../ap/test/references/statics/Category.java | 19 +++-------------- .../test/references/statics/CustomMapper.java | 19 +++-------------- .../test/references/statics/StaticsTest.java | 19 +++-------------- .../statics/nonused/NonUsedMapper.java | 19 +++-------------- .../InheritInverseConfigurationTest.java | 19 +++-------------- .../org/mapstruct/ap/test/reverse/Source.java | 19 +++-------------- .../ap/test/reverse/SourceTargetMapper.java | 19 +++-------------- .../org/mapstruct/ap/test/reverse/Target.java | 19 +++-------------- .../SourceTargetMapperAmbiguous1.java | 19 +++-------------- .../SourceTargetMapperAmbiguous2.java | 19 +++-------------- .../SourceTargetMapperAmbiguous3.java | 19 +++-------------- .../SourceTargetMapperNonMatchingName.java | 19 +++-------------- .../test/selection/generics/ArrayWrapper.java | 19 +++-------------- .../selection/generics/ConversionTest.java | 19 +++-------------- .../selection/generics/ErroneousSource1.java | 19 +++-------------- .../selection/generics/ErroneousSource2.java | 19 +++-------------- .../selection/generics/ErroneousSource3.java | 19 +++-------------- .../selection/generics/ErroneousSource4.java | 19 +++-------------- .../selection/generics/ErroneousSource5.java | 19 +++-------------- .../selection/generics/ErroneousSource6.java | 19 +++-------------- .../ErroneousSourceTargetMapper1.java | 19 +++-------------- .../ErroneousSourceTargetMapper2.java | 19 +++-------------- .../ErroneousSourceTargetMapper3.java | 19 +++-------------- .../ErroneousSourceTargetMapper4.java | 19 +++-------------- .../ErroneousSourceTargetMapper5.java | 19 +++-------------- .../ErroneousSourceTargetMapper6.java | 19 +++-------------- .../selection/generics/ErroneousTarget1.java | 19 +++-------------- .../selection/generics/ErroneousTarget2.java | 19 +++-------------- .../selection/generics/ErroneousTarget3.java | 19 +++-------------- .../selection/generics/ErroneousTarget4.java | 19 +++-------------- .../selection/generics/ErroneousTarget5.java | 19 +++-------------- .../selection/generics/ErroneousTarget6.java | 19 +++-------------- .../selection/generics/GenericTypeMapper.java | 19 +++-------------- .../ap/test/selection/generics/Source.java | 19 +++-------------- .../generics/SourceTargetMapper.java | 19 +++-------------- .../ap/test/selection/generics/Target.java | 19 +++-------------- .../test/selection/generics/TwoArgHolder.java | 19 +++-------------- .../selection/generics/TwoArgWrapper.java | 19 +++-------------- .../ap/test/selection/generics/TypeA.java | 19 +++-------------- .../ap/test/selection/generics/TypeB.java | 19 +++-------------- .../ap/test/selection/generics/TypeC.java | 19 +++-------------- .../selection/generics/UpperBoundWrapper.java | 19 +++-------------- .../generics/WildCardExtendsMBWrapper.java | 19 +++-------------- .../generics/WildCardExtendsWrapper.java | 19 +++-------------- .../generics/WildCardSuperWrapper.java | 19 +++-------------- .../ap/test/selection/generics/Wrapper.java | 19 +++-------------- .../jaxb/JaxbFactoryMethodSelectionTest.java | 19 +++-------------- .../ap/test/selection/jaxb/OrderDto.java | 19 +++-------------- .../ap/test/selection/jaxb/OrderMapper.java | 19 +++-------------- .../jaxb/OrderShippingDetailsDto.java | 19 +++-------------- .../jaxb/UnderscoreSelectionTest.java | 19 +++-------------- .../selection/jaxb/test1/ObjectFactory.java | 19 +++-------------- .../test/selection/jaxb/test1/OrderType.java | 19 +++-------------- .../selection/jaxb/test2/ObjectFactory.java | 19 +++-------------- .../jaxb/test2/OrderShippingDetailsType.java | 19 +++-------------- .../jaxb/underscores/ObjectFactory.java | 19 +++-------------- .../selection/jaxb/underscores/SubType.java | 19 +++-------------- .../selection/jaxb/underscores/SuperType.java | 19 +++-------------- .../jaxb/underscores/UnderscoreMapper.java | 19 +++-------------- .../jaxb/underscores/UnderscoreType.java | 19 +++-------------- .../ap/test/selection/primitives/MyLong.java | 19 +++-------------- .../selection/primitives/PrimitiveMapper.java | 19 +++-------------- .../PrimitiveVsWrappedSelectionTest.java | 19 +++-------------- .../ap/test/selection/primitives/Source.java | 19 +++-------------- .../primitives/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperPrimitive.java | 19 +++-------------- .../primitives/SourceTargetMapperWrapped.java | 19 +++-------------- .../ap/test/selection/primitives/Target.java | 19 +++-------------- .../selection/primitives/WrappedMapper.java | 19 +++-------------- .../selection/qualifier/ErroneousMapper.java | 19 +++-------------- .../ErroneousMovieFactoryMapper.java | 19 +++-------------- .../test/selection/qualifier/FactMapper.java | 19 +++-------------- .../selection/qualifier/KeyWordMapper.java | 19 +++-------------- .../qualifier/MapperWithoutQualifiedBy.java | 19 +++-------------- .../qualifier/MovieFactoryMapper.java | 19 +++-------------- .../test/selection/qualifier/MovieMapper.java | 19 +++-------------- .../selection/qualifier/QualifierTest.java | 19 +++-------------- .../annotation/CreateGermanRelease.java | 19 +++-------------- .../qualifier/annotation/EnglishToGerman.java | 19 +++-------------- .../annotation/NonQualifierAnnotated.java | 19 +++-------------- .../qualifier/annotation/TitleTranslator.java | 19 +++-------------- .../qualifier/bean/AbstractEntry.java | 19 +++-------------- .../qualifier/bean/GermanRelease.java | 19 +++-------------- .../qualifier/bean/OriginalRelease.java | 19 +++-------------- .../qualifier/bean/ReleaseFactory.java | 19 +++-------------- .../qualifier/handwritten/Facts.java | 19 +++-------------- .../qualifier/handwritten/PlotWords.java | 19 +++-------------- .../qualifier/handwritten/Reverse.java | 19 +++-------------- .../handwritten/SomeOtherMapper.java | 19 +++-------------- .../qualifier/handwritten/Titles.java | 19 +++-------------- .../handwritten/YetAnotherMapper.java | 19 +++-------------- .../qualifier/hybrid/HybridTest.java | 19 +++-------------- .../qualifier/hybrid/ReleaseMapper.java | 19 +++-------------- .../qualifier/hybrid/SourceRelease.java | 19 +++-------------- .../qualifier/hybrid/TargetRelease.java | 19 +++-------------- .../selection/qualifier/iterable/CityDto.java | 19 +++-------------- .../qualifier/iterable/CityEntity.java | 19 +++-------------- .../iterable/IterableAndQualifiersTest.java | 19 +++-------------- .../qualifier/iterable/RiverDto.java | 19 +++-------------- .../qualifier/iterable/RiverEntity.java | 19 +++-------------- .../qualifier/iterable/TopologyDto.java | 19 +++-------------- .../qualifier/iterable/TopologyEntity.java | 19 +++-------------- .../iterable/TopologyFeatureDto.java | 19 +++-------------- .../iterable/TopologyFeatureEntity.java | 19 +++-------------- .../qualifier/iterable/TopologyMapper.java | 19 +++-------------- .../qualifier/named/ErroneousMapper.java | 19 +++-------------- .../selection/qualifier/named/FactMapper.java | 19 +++-------------- .../qualifier/named/KeyWordMapper.java | 19 +++-------------- .../qualifier/named/MovieFactoryMapper.java | 19 +++-------------- .../qualifier/named/MovieMapper.java | 19 +++-------------- .../selection/qualifier/named/NamedTest.java | 19 +++-------------- .../ap/test/selection/resulttype/Apple.java | 19 +++-------------- .../test/selection/resulttype/AppleDto.java | 19 +++-------------- .../selection/resulttype/AppleFactory.java | 19 +++-------------- .../selection/resulttype/AppleFamily.java | 19 +++-------------- .../selection/resulttype/AppleFamilyDto.java | 19 +++-------------- .../ap/test/selection/resulttype/Banana.java | 19 +++-------------- .../test/selection/resulttype/BananaDto.java | 19 +++-------------- .../resulttype/ConflictingFruitFactory.java | 19 +++-------------- .../resulttype/ErroneousFruitMapper.java | 19 +++-------------- .../resulttype/ErroneousFruitMapper2.java | 19 +++-------------- ...ousResultTypeNoEmptyConstructorMapper.java | 19 +++-------------- .../ap/test/selection/resulttype/Fruit.java | 19 +++-------------- .../test/selection/resulttype/FruitDto.java | 19 +++-------------- .../resulttype/FruitFamilyMapper.java | 19 +++-------------- .../selection/resulttype/GoldenDelicious.java | 19 +++-------------- .../resulttype/GoldenDeliciousDto.java | 19 +++-------------- .../resulttype/InheritanceSelectionTest.java | 19 +++-------------- .../ap/test/selection/resulttype/IsFruit.java | 19 +++-------------- ...tructingFruitInterfaceErroneousMapper.java | 19 +++-------------- ...tTypeConstructingFruitInterfaceMapper.java | 19 +++-------------- .../ResultTypeConstructingFruitMapper.java | 19 +++-------------- .../ResultTypeSelectingFruitMapper.java | 19 +++-------------- .../ap/test/severalsources/Address.java | 19 +++-------------- .../test/severalsources/DeliveryAddress.java | 19 +++-------------- .../ErroneousSourceTargetMapper.java | 19 +++-------------- .../ErroneousSourceTargetMapper2.java | 19 +++-------------- .../ap/test/severalsources/Person.java | 19 +++-------------- .../test/severalsources/ReferencedMapper.java | 19 +++-------------- .../SeveralSourceParametersTest.java | 19 +++-------------- .../severalsources/SourceTargetMapper.java | 19 +++-------------- .../ap/test/severaltargets/Source.java | 19 +++-------------- .../SourcePropertyMapSeveralTimesTest.java | 19 +++-------------- .../severaltargets/SourceTargetMapper.java | 19 +++-------------- .../ap/test/severaltargets/Target.java | 19 +++-------------- .../ap/test/severaltargets/TimeAndFormat.java | 19 +++-------------- .../severaltargets/TimeAndFormatMapper.java | 19 +++-------------- .../source/constants/ConstantsMapper.java | 20 +++--------------- .../source/constants/ConstantsTarget.java | 20 +++--------------- .../test/source/constants/ConstantsTest.java | 19 +++-------------- .../ap/test/source/constants/CountryEnum.java | 19 +++-------------- .../constants/ErroneousConstantMapper.java | 20 +++--------------- .../source/constants/ErroneousMapper1.java | 19 +++-------------- .../source/constants/ErroneousMapper2.java | 19 +++-------------- .../source/constants/ErroneousMapper3.java | 19 +++-------------- .../source/constants/ErroneousMapper4.java | 19 +++-------------- .../source/constants/ErroneousMapper5.java | 19 +++-------------- .../source/constants/ErroneousMapper6.java | 19 +++-------------- .../ap/test/source/constants/Source.java | 19 +++-------------- .../ap/test/source/constants/Source1.java | 19 +++-------------- .../ap/test/source/constants/Source2.java | 19 +++-------------- .../source/constants/SourceConstantsTest.java | 19 +++-------------- .../source/constants/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperSeveralSources.java | 19 +++-------------- .../source/constants/StringListMapper.java | 19 +++-------------- .../ap/test/source/constants/Target.java | 19 +++-------------- .../ap/test/source/constants/Target2.java | 19 +++-------------- ...oneousDefaultExpressionConstantMapper.java | 19 +++-------------- ...usDefaultExpressionDefaultValueMapper.java | 19 +++-------------- ...eousDefaultExpressionExpressionMapper.java | 19 +++-------------- .../ErroneousDefaultExpressionMapper.java | 19 +++-------------- .../java/JavaDefaultExpressionTest.java | 19 +++-------------- .../defaultExpressions/java/Source.java | 19 +++-------------- .../java/SourceTargetMapper.java | 19 +++-------------- .../defaultExpressions/java/Target.java | 19 +++-------------- .../java/BooleanWorkAroundMapper.java | 19 +++-------------- .../expressions/java/JavaExpressionTest.java | 19 +++-------------- .../test/source/expressions/java/Source.java | 19 +++-------------- .../test/source/expressions/java/Source2.java | 19 +++-------------- .../java/SourceBooleanWorkAround.java | 19 +++-------------- .../source/expressions/java/SourceList.java | 19 +++-------------- .../java/SourceTargetListMapper.java | 19 +++-------------- .../expressions/java/SourceTargetMapper.java | 19 +++-------------- .../SourceTargetMapperSeveralSources.java | 19 +++-------------- .../test/source/expressions/java/Target.java | 19 +++-------------- .../java/TargetBooleanWorkAround.java | 19 +++-------------- .../source/expressions/java/TargetList.java | 19 +++-------------- .../java/mapper/TimeAndFormat.java | 19 +++-------------- .../ignore/IgnoreUnmappedSourceMapper.java | 19 +++-------------- .../IgnoreUnmappedSourcePropertiesTest.java | 19 +++-------------- .../ap/test/source/ignore/Person.java | 19 +++-------------- .../ap/test/source/ignore/PersonDto.java | 19 +++-------------- .../PresenceCheckTest.java | 19 +++-------------- .../RockFestivalMapper.java | 19 +++-------------- .../RockFestivalMapperConfig.java | 19 +++-------------- .../RockFestivalMapperOveridingConfig.java | 19 +++-------------- .../RockFestivalMapperWithConfig.java | 19 +++-------------- .../RockFestivalSource.java | 19 +++-------------- .../RockFestivalTarget.java | 19 +++-------------- .../source/nullvaluecheckstrategy/Stage.java | 19 +++-------------- .../source/presencecheck/spi/GoalKeeper.java | 19 +++-------------- .../presencecheck/spi/PresenceCheckTest.java | 19 +++-------------- .../presencecheck/spi/SoccerTeamMapper.java | 19 +++-------------- .../presencecheck/spi/SoccerTeamSource.java | 19 +++-------------- .../presencecheck/spi/SoccerTeamTarget.java | 19 +++-------------- .../test/source/presencecheck/spi/Source.java | 19 +++-------------- .../presencecheck/spi/SourceTargetMapper.java | 19 +++-------------- .../test/source/presencecheck/spi/Target.java | 19 +++-------------- .../template/InheritConfigurationTest.java | 19 +++-------------- .../ap/test/template/NestedSource.java | 19 +++-------------- .../mapstruct/ap/test/template/Source.java | 19 +++-------------- .../template/SourceTargetMapperMultiple.java | 19 +++-------------- .../SourceTargetMapperSeveralArgs.java | 19 +++-------------- .../template/SourceTargetMapperSingle.java | 19 +++-------------- .../mapstruct/ap/test/template/Target.java | 19 +++-------------- .../SourceTargetMapperAmbiguous1.java | 19 +++-------------- .../SourceTargetMapperAmbiguous2.java | 19 +++-------------- .../SourceTargetMapperAmbiguous3.java | 19 +++-------------- .../SourceTargetMapperNonMatchingName.java | 19 +++-------------- .../ap/test/unmappedsource/Config.java | 19 +++-------------- .../ErroneousStrictSourceTargetMapper.java | 19 +++-------------- .../unmappedsource/SourceTargetMapper.java | 19 +++-------------- .../unmappedsource/UnmappedSourceTest.java | 19 +++-------------- .../UsesConfigFromAnnotationMapper.java | 19 +++-------------- .../ErroneousStrictSourceTargetMapper.java | 19 +++-------------- .../ap/test/unmappedtarget/Source.java | 19 +++-------------- .../unmappedtarget/SourceTargetMapper.java | 19 +++-------------- .../ap/test/unmappedtarget/Target.java | 19 +++-------------- .../unmappedtarget/UnmappedProductTest.java | 19 +++-------------- .../ap/test/updatemethods/BossDto.java | 19 +++-------------- .../ap/test/updatemethods/BossEntity.java | 19 +++-------------- .../ap/test/updatemethods/CompanyDto.java | 19 +++-------------- .../ap/test/updatemethods/CompanyEntity.java | 19 +++-------------- .../ap/test/updatemethods/CompanyMapper.java | 19 +++-------------- .../ap/test/updatemethods/CompanyMapper1.java | 19 +++-------------- .../ConstructableDepartmentEntity.java | 19 +++-------------- .../ap/test/updatemethods/DepartmentDto.java | 19 +++-------------- .../test/updatemethods/DepartmentEntity.java | 19 +++-------------- .../DepartmentEntityFactory.java | 19 +++-------------- .../updatemethods/DepartmentInBetween.java | 19 +++-------------- .../ap/test/updatemethods/EmployeeDto.java | 19 +++-------------- .../ap/test/updatemethods/EmployeeEntity.java | 19 +++-------------- .../ErroneousOrganizationMapper1.java | 19 +++-------------- .../ErroneousOrganizationMapper2.java | 19 +++-------------- .../test/updatemethods/OrganizationDto.java | 19 +++-------------- .../updatemethods/OrganizationEntity.java | 19 +++-------------- .../updatemethods/OrganizationMapper.java | 19 +++-------------- .../updatemethods/OrganizationTypeEntity.java | 19 +++-------------- .../OrganizationTypeNrEntity.java | 19 +++-------------- ...rganizationWithoutCompanyGetterEntity.java | 19 +++-------------- .../OrganizationWithoutTypeGetterEntity.java | 19 +++-------------- .../ap/test/updatemethods/SecretaryDto.java | 19 +++-------------- .../test/updatemethods/SecretaryEntity.java | 19 +++-------------- .../updatemethods/UnmappableCompanyDto.java | 19 +++-------------- .../UnmappableDepartmentDto.java | 19 +++-------------- .../test/updatemethods/UpdateMethodsTest.java | 19 +++-------------- .../selection/DepartmentMapper.java | 19 +++-------------- .../selection/ExternalHandWrittenMapper.java | 19 +++-------------- .../selection/ExternalMapper.java | 19 +++-------------- .../selection/ExternalSelectionTest.java | 19 +++-------------- .../selection/OrganizationMapper1.java | 19 +++-------------- .../selection/OrganizationMapper2.java | 19 +++-------------- .../selection/OrganizationMapper3.java | 19 +++-------------- .../ap/test/value/DefaultOrderMapper.java | 19 +++-------------- .../ap/test/value/EnumToEnumMappingTest.java | 19 +++-------------- .../ErroneousOrderMapperDuplicateANY.java | 19 +++-------------- ...usOrderMapperMappingSameConstantTwice.java | 19 +++-------------- ...ppingConstantWithoutMatchInTargetType.java | 19 +++-------------- ...sOrderMapperUsingUnknownEnumConstants.java | 19 +++-------------- .../ap/test/value/ExternalOrderType.java | 19 +++-------------- .../org/mapstruct/ap/test/value/OrderDto.java | 19 +++-------------- .../mapstruct/ap/test/value/OrderEntity.java | 19 +++-------------- .../mapstruct/ap/test/value/OrderMapper.java | 19 +++-------------- .../mapstruct/ap/test/value/OrderType.java | 19 +++-------------- .../ap/test/value/SpecialOrderMapper.java | 19 +++-------------- .../ap/test/versioninfo/SimpleMapper.java | 19 +++-------------- .../ap/test/versioninfo/VersionInfoTest.java | 19 +++-------------- .../org/mapstruct/ap/testutil/IssueKey.java | 19 +++-------------- .../mapstruct/ap/testutil/WithClasses.java | 19 +++-------------- .../testutil/WithServiceImplementation.java | 19 +++-------------- .../testutil/WithServiceImplementations.java | 19 +++-------------- .../testutil/assertions/JavaFileAssert.java | 21 ++++--------------- .../annotation/CompilationResult.java | 19 +++-------------- .../compilation/annotation/Diagnostic.java | 19 +++-------------- .../annotation/DisableCheckstyle.java | 19 +++-------------- .../ExpectedCompilationOutcome.java | 19 +++-------------- .../annotation/ProcessorOption.java | 19 +++-------------- .../annotation/ProcessorOptions.java | 19 +++-------------- .../model/CompilationOutcomeDescriptor.java | 19 +++-------------- .../model/DiagnosticDescriptor.java | 19 +++-------------- .../runner/AnnotationProcessorTestRunner.java | 19 +++-------------- .../ap/testutil/runner/CompilationCache.java | 19 +++-------------- .../testutil/runner/CompilationRequest.java | 19 +++-------------- .../ap/testutil/runner/Compiler.java | 19 +++-------------- .../testutil/runner/CompilingStatement.java | 19 +++-------------- .../runner/EclipseCompilingStatement.java | 19 +++-------------- .../runner/FilteringParentClassLoader.java | 19 +++-------------- .../ap/testutil/runner/GeneratedSource.java | 19 +++-------------- .../InnerAnnotationProcessorRunner.java | 19 +++-------------- .../runner/JdkCompilingStatement.java | 19 +++-------------- .../runner/ModifiableURLClassLoader.java | 19 +++-------------- .../testutil/runner/ReplacableTestClass.java | 19 +++-------------- .../testutil/runner/WithSingleCompiler.java | 19 +++-------------- ...AbstractSourceTargetMapperPrivateImpl.java | 19 +++-------------- .../SourceTargetMapperDefaultOtherImpl.java | 19 +++-------------- .../SourceTargetMapperPrivateImpl.java | 19 +++-------------- .../ap/test/array/ScienceMapperImpl.java | 19 +++-------------- .../test/bugs/_1453/Issue1453MapperImpl.java | 19 +++-------------- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 19 +++-------------- .../DomainDtoWithNvmsDefaultMapperImpl.java | 19 +++-------------- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 19 +++-------------- .../DomainDtoWithPresenceCheckMapperImpl.java | 19 +++-------------- .../adder/Source2Target2MapperImpl.java | 19 +++-------------- .../adder/SourceTargetMapperImpl.java | 19 +++-------------- ...SourceTargetMapperStrategyDefaultImpl.java | 19 +++-------------- ...rgetMapperStrategySetterPreferredImpl.java | 19 +++-------------- .../SourceTargetMapperImpl.java | 19 +++-------------- .../string/SourceTargetMapperImpl.java | 19 +++-------------- .../nestedbeans/UserDtoMapperClassicImpl.java | 19 +++-------------- .../nestedbeans/UserDtoMapperSmartImpl.java | 19 +++-------------- .../UserDtoUpdateMapperSmartImpl.java | 19 +++-------------- .../mixed/FishTankMapperConstantImpl.java | 19 +++-------------- .../mixed/FishTankMapperExpressionImpl.java | 19 +++-------------- .../nestedbeans/mixed/FishTankMapperImpl.java | 19 +++-------------- .../mixed/FishTankMapperWithDocumentImpl.java | 19 +++-------------- .../ArtistToChartEntryImpl.java | 19 +++-------------- .../ChartEntryToArtistImpl.java | 19 +++-------------- .../ChartEntryToArtistUpdateImpl.java | 19 +++-------------- .../source/constants/ConstantsMapperImpl.java | 19 +++-------------- .../updatemethods/CompanyMapper1Impl.java | 19 +++-------------- .../test/updatemethods/CompanyMapperImpl.java | 19 +++-------------- .../updatemethods/OrganizationMapperImpl.java | 19 +++-------------- .../selection/DepartmentMapperImpl.java | 19 +++-------------- .../selection/ExternalMapperImpl.java | 19 +++-------------- .../selection/OrganizationMapper1Impl.java | 19 +++-------------- .../selection/OrganizationMapper2Impl.java | 19 +++-------------- .../selection/OrganizationMapper3Impl.java | 19 +++-------------- .../ap/test/value/DefaultOrderMapperImpl.java | 19 +++-------------- .../ap/test/value/OrderMapperImpl.java | 19 +++-------------- .../ap/test/value/SpecialOrderMapperImpl.java | 19 +++-------------- 2318 files changed, 6888 insertions(+), 36960 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index f052b4665d..8332d4c444 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,19 +1,6 @@ - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - MapStruct is licensed under the Apache License, Version 2.0 (the - "License"); you may not use this software except in compliance with the - License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + MapStruct is licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 ------------------------------------------------------------------------ diff --git a/build-config/pom.xml b/build-config/pom.xml index 930f5ded4e..462fe5c4db 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -1,22 +1,9 @@ diff --git a/core-common/pom.xml b/core-common/pom.xml index b1d066a4bf..0583071238 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -1,22 +1,9 @@ diff --git a/core-common/src/main/java/org/mapstruct/AfterMapping.java b/core-common/src/main/java/org/mapstruct/AfterMapping.java index f6d8350ea5..a76eebdcba 100644 --- a/core-common/src/main/java/org/mapstruct/AfterMapping.java +++ b/core-common/src/main/java/org/mapstruct/AfterMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index 03a0ee10f2..582814e7a5 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/BeforeMapping.java b/core-common/src/main/java/org/mapstruct/BeforeMapping.java index 626e918ed8..0e296e71a7 100644 --- a/core-common/src/main/java/org/mapstruct/BeforeMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeforeMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/Builder.java b/core-common/src/main/java/org/mapstruct/Builder.java index 5f37028d8e..ec26ab37ab 100644 --- a/core-common/src/main/java/org/mapstruct/Builder.java +++ b/core-common/src/main/java/org/mapstruct/Builder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java b/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java index 556e8aab01..afaba97370 100644 --- a/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java +++ b/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core-common/src/main/java/org/mapstruct/Context.java index 7d5d922cb3..58f606a038 100644 --- a/core-common/src/main/java/org/mapstruct/Context.java +++ b/core-common/src/main/java/org/mapstruct/Context.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/DecoratedWith.java b/core-common/src/main/java/org/mapstruct/DecoratedWith.java index 632f63b749..e2734a699c 100644 --- a/core-common/src/main/java/org/mapstruct/DecoratedWith.java +++ b/core-common/src/main/java/org/mapstruct/DecoratedWith.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/InheritConfiguration.java b/core-common/src/main/java/org/mapstruct/InheritConfiguration.java index cdbae1d57a..d39ded7b0d 100644 --- a/core-common/src/main/java/org/mapstruct/InheritConfiguration.java +++ b/core-common/src/main/java/org/mapstruct/InheritConfiguration.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java index 5ec1c21a74..d1bede3f05 100644 --- a/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java +++ b/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/InjectionStrategy.java b/core-common/src/main/java/org/mapstruct/InjectionStrategy.java index 75728d139f..84baa8afa9 100644 --- a/core-common/src/main/java/org/mapstruct/InjectionStrategy.java +++ b/core-common/src/main/java/org/mapstruct/InjectionStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/IterableMapping.java b/core-common/src/main/java/org/mapstruct/IterableMapping.java index efc26ce3a2..0e81e66126 100644 --- a/core-common/src/main/java/org/mapstruct/IterableMapping.java +++ b/core-common/src/main/java/org/mapstruct/IterableMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/MapMapping.java b/core-common/src/main/java/org/mapstruct/MapMapping.java index d3c68ec535..41616882be 100644 --- a/core-common/src/main/java/org/mapstruct/MapMapping.java +++ b/core-common/src/main/java/org/mapstruct/MapMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index 011c83a1f6..fa9863244e 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index 857320b3aa..f0589c0ae5 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/MappingConstants.java b/core-common/src/main/java/org/mapstruct/MappingConstants.java index c4f7dbbf20..f679d1157f 100644 --- a/core-common/src/main/java/org/mapstruct/MappingConstants.java +++ b/core-common/src/main/java/org/mapstruct/MappingConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java b/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java index 03f5ee0e77..ff57b45841 100644 --- a/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java +++ b/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/MappingTarget.java b/core-common/src/main/java/org/mapstruct/MappingTarget.java index f99c79885d..fc140f120a 100644 --- a/core-common/src/main/java/org/mapstruct/MappingTarget.java +++ b/core-common/src/main/java/org/mapstruct/MappingTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/Named.java b/core-common/src/main/java/org/mapstruct/Named.java index 3a8a27a681..0b6e8b53a9 100644 --- a/core-common/src/main/java/org/mapstruct/Named.java +++ b/core-common/src/main/java/org/mapstruct/Named.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java index c6c0dbfd5d..8f31a35f7c 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java b/core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java index 4dd77dbb3a..519a28bd81 100644 --- a/core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java +++ b/core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/ObjectFactory.java b/core-common/src/main/java/org/mapstruct/ObjectFactory.java index 60c0acff02..dc0e92de8d 100644 --- a/core-common/src/main/java/org/mapstruct/ObjectFactory.java +++ b/core-common/src/main/java/org/mapstruct/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/Qualifier.java b/core-common/src/main/java/org/mapstruct/Qualifier.java index 0581da2da4..c21390e8ca 100644 --- a/core-common/src/main/java/org/mapstruct/Qualifier.java +++ b/core-common/src/main/java/org/mapstruct/Qualifier.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/ReportingPolicy.java b/core-common/src/main/java/org/mapstruct/ReportingPolicy.java index 35c77d4bc7..78b510aac7 100644 --- a/core-common/src/main/java/org/mapstruct/ReportingPolicy.java +++ b/core-common/src/main/java/org/mapstruct/ReportingPolicy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/TargetType.java b/core-common/src/main/java/org/mapstruct/TargetType.java index dec252c01b..e4064f248a 100644 --- a/core-common/src/main/java/org/mapstruct/TargetType.java +++ b/core-common/src/main/java/org/mapstruct/TargetType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-common/src/main/java/org/mapstruct/factory/Mappers.java b/core-common/src/main/java/org/mapstruct/factory/Mappers.java index 44ab7ae4fb..85c673b127 100644 --- a/core-common/src/main/java/org/mapstruct/factory/Mappers.java +++ b/core-common/src/main/java/org/mapstruct/factory/Mappers.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.factory; diff --git a/core-common/src/main/java/org/mapstruct/factory/package-info.java b/core-common/src/main/java/org/mapstruct/factory/package-info.java index 4ce3e2ec0f..532857a401 100644 --- a/core-common/src/main/java/org/mapstruct/factory/package-info.java +++ b/core-common/src/main/java/org/mapstruct/factory/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/core-common/src/main/java/org/mapstruct/package-info.java b/core-common/src/main/java/org/mapstruct/package-info.java index 8ef7ea9fce..02f2b31a42 100644 --- a/core-common/src/main/java/org/mapstruct/package-info.java +++ b/core-common/src/main/java/org/mapstruct/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/core-common/src/main/java/org/mapstruct/util/Experimental.java b/core-common/src/main/java/org/mapstruct/util/Experimental.java index 58cedeb932..a945a87d7c 100644 --- a/core-common/src/main/java/org/mapstruct/util/Experimental.java +++ b/core-common/src/main/java/org/mapstruct/util/Experimental.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.util; diff --git a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java index 1a0da2626b..507eb08d0e 100644 --- a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java +++ b/core-common/src/test/java/org/mapstruct/factory/MappersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.factory; diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java index 7d5e4738af..4fbc97f26d 100644 --- a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java +++ b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.factory; diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java index dd8ee89319..2aca92abef 100644 --- a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java +++ b/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.factory; diff --git a/core-common/src/test/java/org/mapstruct/test/model/Foo.java b/core-common/src/test/java/org/mapstruct/test/model/Foo.java index 1f25db3703..4ee788efcf 100644 --- a/core-common/src/test/java/org/mapstruct/test/model/Foo.java +++ b/core-common/src/test/java/org/mapstruct/test/model/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.test.model; diff --git a/core-common/src/test/java/org/mapstruct/test/model/FooImpl.java b/core-common/src/test/java/org/mapstruct/test/model/FooImpl.java index ff486c4452..0d90dabebc 100644 --- a/core-common/src/test/java/org/mapstruct/test/model/FooImpl.java +++ b/core-common/src/test/java/org/mapstruct/test/model/FooImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.test.model; diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java index 0e2e0dd181..a9e03641fe 100644 --- a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.test.model; diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java index 27b1fec379..53331de181 100644 --- a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.test.model; diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java b/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java index f8fc1437e0..d25841145c 100644 --- a/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java +++ b/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.test.model; diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 89ffba54da..456766be07 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -1,22 +1,9 @@ diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java index 4064b7d86c..703c2bd372 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-jdk8/src/main/java/org/mapstruct/Mappings.java b/core-jdk8/src/main/java/org/mapstruct/Mappings.java index 9bc3b1f7fa..1e9dd96707 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mappings.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mappings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java b/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java index 5808cd5f89..26ed661dce 100644 --- a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java b/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java index 5c720e834d..f2450a2fd6 100644 --- a/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java +++ b/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core/pom.xml b/core/pom.xml index 1f4a7a65df..f6b037f6e4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,22 +1,9 @@ diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 86e1810e25..d98eb3b8de 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core/src/main/java/org/mapstruct/Mappings.java b/core/src/main/java/org/mapstruct/Mappings.java index 9bc3b1f7fa..1e9dd96707 100644 --- a/core/src/main/java/org/mapstruct/Mappings.java +++ b/core/src/main/java/org/mapstruct/Mappings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index 59bc10f3d5..f677fb1038 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/core/src/main/java/org/mapstruct/ValueMappings.java b/core/src/main/java/org/mapstruct/ValueMappings.java index 5c720e834d..f2450a2fd6 100644 --- a/core/src/main/java/org/mapstruct/ValueMappings.java +++ b/core/src/main/java/org/mapstruct/ValueMappings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct; diff --git a/distribution/pom.xml b/distribution/pom.xml index e155e87b15..b586a4ba2f 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -1,22 +1,9 @@ @@ -106,7 +93,7 @@ MapStruct ${project.version} MapStruct ${project.version} - Gunnar Morling; All rights reserved. Released under the Apache Software License 2.0.]]> + MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.]]> diff --git a/distribution/src/main/assembly/dist.xml b/distribution/src/main/assembly/dist.xml index 88aed5eeb2..6dee9eeda0 100644 --- a/distribution/src/main/assembly/dist.xml +++ b/distribution/src/main/assembly/dist.xml @@ -1,22 +1,9 @@ diff --git a/documentation/pom.xml b/documentation/pom.xml index 4802c6149f..3ce539793e 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -1,22 +1,9 @@ diff --git a/etc/license.txt b/etc/license.txt index 2cc3d75aa3..66af6edf79 100644 --- a/etc/license.txt +++ b/etc/license.txt @@ -1,16 +1,3 @@ - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. +Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 2e377915cd..820ba733f8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java index 3d69d052f9..823a530c09 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java index bea73ef70e..216d2afdfa 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java index 87010b9e85..bcfb0c399c 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java index 78b5465c83..250f4ce856 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java index 46dc4ce6bd..76d5bd0a08 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java index 2bc395486e..b6f6970d38 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java index dd52db731f..ce0b191f65 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java index b72e5b1146..840f5d9337 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java index dd82752f4a..65cd76f0d3 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java index a86a1b805c..ff5ef418b1 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java index 39690d5b01..55d06a3f14 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java index 46389767f8..bbcd7a529d 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java index eccbceac4e..1eca9383a2 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java index 264f7e4fb0..b39f8e93d9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java index 04b9155c52..2cbd78f0f2 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.tests; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java index 62ad61f936..96f3aa00d9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.testutil.runner; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java index 4e287b8005..92f02abf70 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.testutil.runner; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java index 05e6d8e6b9..83b7f7f666 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.testutil.runner; diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java index bee02f692c..4f9b0c7e60 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.testutil.runner.xml; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml b/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml index 3d37a1d024..383ab4efbe 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/autoValueBuilderTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java index ff0da32ecb..97eb723193 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java index fe3d6d9ee7..35eed1cb11 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java index af46d576ec..4f71c55c4a 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java index 13f8d084df..f3e2ecede5 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java index 2e585c545c..9e916c8ad7 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/main/java/org/mapstruct/itest/auto/value/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java index 93f5d58958..8f640780f3 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.auto.value; diff --git a/integrationtest/src/test/resources/cdiTest/pom.xml b/integrationtest/src/test/resources/cdiTest/pom.xml index 0df46e0e11..30d35a421e 100644 --- a/integrationtest/src/test/resources/cdiTest/pom.xml +++ b/integrationtest/src/test/resources/cdiTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java index 55b95159b9..1787fd3c90 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Source.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Source.java index 7c0940cded..ea2910015a 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Source.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java index 0b0c6f92cf..3a46a20889 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapperDecorator.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapperDecorator.java index 96bc09dc4a..8dd673a2e2 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Target.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Target.java index 94c1727030..857ab8aaf2 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Target.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/other/DateMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/other/DateMapper.java index bb09803b84..a9c4706bd8 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/other/DateMapper.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/other/DateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi.other; diff --git a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java index b86ab2d040..702ab6d255 100644 --- a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java +++ b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.cdi; diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml b/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml index 58eb8735a3..28ea208e1a 100644 --- a/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java index 36b01ab954..0e6e956efa 100644 --- a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.externalbeanjar; diff --git a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java index da78a4e03f..26c42e5869 100644 --- a/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java +++ b/integrationtest/src/test/resources/externalbeanjar/beanjar/src/main/java/org/mapstruct/itest/externalbeanjar/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.externalbeanjar; diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml b/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml index e45abc0302..aa5546f587 100644 --- a/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java b/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java index 45d861bde6..028941e24d 100644 --- a/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/src/main/java/org/mapstruct/itest/externalbeanjar/Issue1121Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /* * To change this license header, choose License Headers in Project Properties. diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java index 9177041631..8a18e9e4fc 100644 --- a/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/externalbeanjar/pom.xml b/integrationtest/src/test/resources/externalbeanjar/pom.xml index 9fe0dff28b..ef3bf4da93 100644 --- a/integrationtest/src/test/resources/externalbeanjar/pom.xml +++ b/integrationtest/src/test/resources/externalbeanjar/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml b/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml index 0b02094fb7..9e8c501ec3 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java index 0cc549a778..1b6878fb8c 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java index 948efa42e3..053840b441 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java index 81538dcf60..b4d544d67a 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java index e9b2c52e30..3b4a17e591 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java index 934a805848..2b732271a3 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/main/java/org/mapstruct/itest/freebuilder/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java index 0aacabd7a9..5047451798 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.freebuilder; diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 7625371c21..7a1654c45c 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java index 26147bdf7b..a180b4df52 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java +++ b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml index c7f6a13f92..5141f2998b 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml +++ b/integrationtest/src/test/resources/immutablesBuilderTest/extras/pom.xml @@ -1,4 +1,11 @@ + diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml index cbe79c972e..10c481b66e 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/pom.xml @@ -1,4 +1,11 @@ + diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java index 2e96845e6f..ce9c033ad0 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java index 7accf8559b..0f24e182f5 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java index 2951023942..dfbfc47b74 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java index 99027926bb..44a6b7b9e3 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java index b52821fe6f..6023833ec8 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/main/java/org/mapstruct/itest/immutables/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java index 9b526f1a54..421954fc90 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.immutables; diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml index 19a738894d..51542adbcb 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/immutablesBuilderTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/java8Test/pom.xml b/integrationtest/src/test/resources/java8Test/pom.xml index f9367676c7..face2f4564 100644 --- a/integrationtest/src/test/resources/java8Test/pom.xml +++ b/integrationtest/src/test/resources/java8Test/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Source.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Source.java index b27a00f778..76925c4430 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Source.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._603; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapper.java index 9f19f94b79..129c459816 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._603; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapperDecorator.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapperDecorator.java index a9d9c2898e..7d47b1f836 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/SourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._603; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Target.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Target.java index 2e7b68a2bd..d1511d7fdb 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Target.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_603/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._603; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Bar.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Bar.java index 2a94d20c04..54a360f7e3 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Bar.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Foo.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Foo.java index c4aed965ec..80c01d4fd6 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Foo.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Source.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Source.java index 322bb9ba02..e7a44792e9 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Source.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetBaseMapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetBaseMapper.java index 314e4c2377..407a4c3b52 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetBaseMapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetBaseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java index 4705a58910..e0e2f791a7 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Target.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Target.java index 9046c7e155..5a45d57d1f 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Target.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java index 6ffb9b0c11..4acd23d08e 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.java8; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Source.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Source.java index 64ac073f27..4f25c4a89b 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Source.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.java8; diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Target.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Target.java index f219cb7fe0..d738aa37ac 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Target.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.java8; diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java index 84072f85b3..c732b96f22 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._603; diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java index 584f0e42c4..99b7a515eb 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._636; diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java index d1f3b74668..556dd2f1e4 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.java8; diff --git a/integrationtest/src/test/resources/jaxbTest/pom.xml b/integrationtest/src/test/resources/jaxbTest/pom.xml index 2f6be7fe29..49f6c28cef 100644 --- a/integrationtest/src/test/resources/jaxbTest/pom.xml +++ b/integrationtest/src/test/resources/jaxbTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java index f9c45a442a..137f234c26 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java index 4305d49366..cdec6dc19d 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondSourceTargetMapperDecorator.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondSourceTargetMapperDecorator.java index fa8b8388e2..d41db89dd5 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondSourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondSourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Source.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Source.java index 91f8ac8f55..6edf1e5133 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Source.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java index d3c9078cdb..c5ba3670fb 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapperDecorator.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapperDecorator.java index 6fd5bd83a6..e7f3423e4b 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Target.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Target.java index 8411101d9e..b3efb96456 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Target.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/other/DateMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/other/DateMapper.java index 0b8e440a4c..817ab2aa53 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/other/DateMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/other/DateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330.other; diff --git a/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java b/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java index c48fe16718..26a9863576 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java +++ b/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.jsr330; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml index e96551d6da..92ece809fe 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java index e367a8e086..248587a308 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java index 871fd58237..36c71607b6 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java index 92a97ec686..faefc5aa1b 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java index 90443f548d..f5607d8b74 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java index 36188efc42..4a58bb72be 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java index 120396af0b..a7185d5011 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.lombok; diff --git a/integrationtest/src/test/resources/namingStrategyTest/pom.xml b/integrationtest/src/test/resources/namingStrategyTest/pom.xml index 55df5f7163..c337167b53 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/pom.xml +++ b/integrationtest/src/test/resources/namingStrategyTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml b/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml index 40885abf15..6045742e36 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml +++ b/integrationtest/src/test/resources/namingStrategyTest/strategy/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java b/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java index 1e3e31b258..3126a08a91 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java +++ b/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.naming; diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/pom.xml b/integrationtest/src/test/resources/namingStrategyTest/usage/pom.xml index 637d1810e5..319cefd218 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/pom.xml +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayer.java b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayer.java index 0a5d4fb939..0536f5ee01 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayer.java +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.naming; diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerDto.java b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerDto.java index c049269827..62e9893ce2 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerDto.java +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.naming; diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerMapper.java b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerMapper.java index 49363e3475..07dcf00b76 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerMapper.java +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/src/main/java/org/mapstruct/itest/naming/GolfPlayerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.naming; diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java b/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java index 42d752d455..d3a45db26b 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.naming; diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index 55a52e5a18..d2ed9acdca 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/BaseType.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/BaseType.java index 3c0c0671f2..1613106a38 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/BaseType.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/BaseType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/ReferencedCustomMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/ReferencedCustomMapper.java index 4eb1887d61..85d551f091 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/ReferencedCustomMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/ReferencedCustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeOtherType.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeOtherType.java index 252372e105..cfa55535d9 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeOtherType.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeOtherType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeType.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeType.java index b43354a7b7..2bf7d3454a 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeType.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SomeType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java index d4fdd01386..48093144cb 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java index 51d4254047..c5a222a6ca 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java index 5db7a10eef..3de0b84722 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java index 4bd4aab266..f49e09ae32 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/YetAnotherType.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/YetAnotherType.java index 786b154cae..c79d55aef7 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/YetAnotherType.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/YetAnotherType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java b/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java index a2aff58a7a..2b6a0bc93b 100644 --- a/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java +++ b/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.simple; diff --git a/integrationtest/src/test/resources/springTest/pom.xml b/integrationtest/src/test/resources/springTest/pom.xml index 2ff4606245..3c1fb54552 100644 --- a/integrationtest/src/test/resources/springTest/pom.xml +++ b/integrationtest/src/test/resources/springTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java index 7bd273c01a..f1bbf87d3a 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java index 4261603ebf..88e2906300 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondSourceTargetMapperDecorator.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondSourceTargetMapperDecorator.java index 3ee87d5dbb..3d710102e3 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondSourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondSourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Source.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Source.java index ba7f2922ba..b1d1a2850f 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Source.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java index 8b150fb6f7..06e4be4d22 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapperDecorator.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapperDecorator.java index e32a69d14c..cb487f52cc 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapperDecorator.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Target.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Target.java index 2eec511ee3..762c778001 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Target.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/other/DateMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/other/DateMapper.java index 1ccd989480..bb9685e6cb 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/other/DateMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/other/DateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring.other; diff --git a/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java b/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java index b102383bf1..a5b3bb0e65 100644 --- a/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java +++ b/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.spring; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml index 9e72814831..234a321b1c 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml @@ -1,3 +1,10 @@ + 4.0.0 diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/BaseGenerationProcessor.java b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/BaseGenerationProcessor.java index b5b98791ac..01693d7f0e 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/BaseGenerationProcessor.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/BaseGenerationProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/GenBase.java b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/GenBase.java index ac796f1a42..b5bada8d14 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/GenBase.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/supertypegeneration/GenBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor index dd8828a3b4..ac02411c1c 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,17 +1,4 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. +# Copyright MapStruct Authors. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 org.mapstruct.itest.supertypegeneration.BaseGenerationProcessor \ No newline at end of file diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/pom.xml index 45c830997d..e522d12b5b 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml index 3f2d54ec6c..8cdd33fec6 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml @@ -1,3 +1,10 @@ + 4.0.0 diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/AnotherOrderMapper.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/AnotherOrderMapper.java index dcf27ff555..09abaf5615 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/AnotherOrderMapper.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/AnotherOrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration.usage; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/Order.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/Order.java index d1161c7155..ae2315bb19 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/Order.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/Order.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration.usage; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderDto.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderDto.java index 43e1068333..f70224b753 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderDto.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration.usage; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderMapper.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderMapper.java index 5c018e3e29..b3d6325d74 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderMapper.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/supertypegeneration/usage/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration.usage; diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java index b5fbdfc172..4a012283d3 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.supertypegeneration.usage; diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml index 589af8215b..60f50ac616 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml @@ -1,3 +1,10 @@ + 4.0.0 diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java index e4d27a885d..87dd299bfe 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/targettypegeneration/DtoGenerationProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.targettypegeneration; diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 1bd0775000..732c6b2124 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,17 +1,4 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. +# Copyright MapStruct Authors. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 org.mapstruct.itest.targettypegeneration.DtoGenerationProcessor diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml index 5f77262044..ba19d31a71 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/pom.xml @@ -1,22 +1,9 @@ diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml index 520576dad5..5aa83327cb 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -1,3 +1,10 @@ + 4.0.0 diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java index c6a4961124..9c5114675f 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/Order.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.targettypegeneration.usage; diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java index cb842c60f9..45f8c223f9 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/targettypegeneration/usage/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.targettypegeneration.usage; diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java index 724754958d..d9e3f8d789 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.itest.targettypegeneration.usage; diff --git a/parent/pom.xml b/parent/pom.xml index a088ddd778..126e09bb15 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1,22 +1,9 @@ @@ -612,6 +599,9 @@ **/*.asciidoc **/binding.xjb + + SLASHSTAR_STYLE + diff --git a/pom.xml b/pom.xml index d920177b63..e24bfdd30a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,22 +1,9 @@ @@ -56,6 +43,7 @@

      etc/license.txt
      XML_STYLE + SLASHSTAR_STYLE diff --git a/processor/pom.xml b/processor/pom.xml index da0b426d0c..f71ede86b5 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -1,22 +1,9 @@ diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index ec0db40415..05f52d3af4 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java index 093e1511f4..f3dfdf46db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java index e6c9b855fa..7f83078318 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJodaTypeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java index 43f8af8416..99649a9a37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractNumberToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java index 080c6e0887..83e8782432 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java index 851070c540..2605416f33 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index d423dc8662..391df2fa68 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java index 0068a27d2a..843f34c389 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java index 464f983825..5306c4fc5b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index 034d191227..56f167829f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java index 5ec50cf246..c71ad26c2e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharToStringConversion.java index 0b0e66f778..fa6434b582 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharWrapperToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharWrapperToStringConversion.java index 17564f6613..5dd6d6bf73 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharWrapperToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CharWrapperToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java index 574f73dcae..0f7df0ac5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index f295fa80bc..b2210ec106 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 239c060b3d..e59998a54a 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java index d881a9fc1f..9fe0c5b332 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java index 7675370a2e..99797f898c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java index 5e9d3bc6b8..bc2aae7305 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlDateConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java index 9407131728..ef892273e3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimeConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java index 7086b2fc07..cba40e7c5e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToSqlTimestampConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index 624c7ab4f4..ac71273c03 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java index 50447ad699..7f904dbe41 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java index ada1efa1ee..579e45fd9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToStringConversion.java index b837e7a0ca..7de296ac6a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java index 03616b86a1..d34d03c40f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToStringConversion.java index be797a90ef..2cc415337b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalTimeToStringConversion.java index b59c62f9e1..f7ca411455 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java index dee492b847..fb2f7f4026 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToStringConversion.java index c7c87bc9be..96fd4115bb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java index 230d2e8ce7..f32f6e369c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToStringConversion.java index e6b1eccba5..6980bf79fc 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateTimeToStringConversion.java index e731ce425b..4a2804eba0 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateToStringConversion.java index b146f0d504..7201a6c65a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalDateToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalTimeToStringConversion.java index 2cea799474..2305f840f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaLocalTimeToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java index 7979099aad..fecd079e3b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java index 7f8632488d..ebe2fefeaf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java index 52cb7ac171..fcc7241290 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java index 36a1d4ff74..373302df7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java index 3c914591e8..30fe24fa34 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java index a69cbfbca7..e904c27753 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java index 32ca05572f..300c901216 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java index c4c9d1a8eb..2a36bcdc79 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.conversion; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/package-info.java index 407b6355fd..b1002b6a8d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 9a2ec6b4ad..8f3f7f52d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 597ad093b8..88f6d6a127 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -1,22 +1,8 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/* + * Copyright MapStruct Authors. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ - package org.mapstruct.ap.internal.model; import org.mapstruct.ap.internal.model.common.Assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java index 7a12cf61db..aaf4d152dd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java index dddef0a3a2..efc3fa0730 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java index 88d8dbe294..9deaff561f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 090ac070b1..ab820eceb7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index 0948c7d112..78375d8e33 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 7973b5c8d4..e832bba4ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java index 0f07dd528a..a352a36063 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Constructor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 1bb72088a7..c80eb593d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 5a3d5dde16..c4b96c0348 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index ae67c4ff29..5b5dae8714 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DecoratorConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DecoratorConstructor.java index 89ff477ea1..3bdfd66435 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DecoratorConstructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DecoratorConstructor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java index c012a1ddad..e1fc85eb40 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java index 66656e6ea2..c5a97cf860 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMappingExclusionProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DelegatingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DelegatingMethod.java index 0bc6260511..4d5b8efe17 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DelegatingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DelegatingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index fc0a896606..8fb346db2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index 654aa47ddd..1ce3753a21 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 592620997e..352e651758 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 8121f7def7..7711c15cfb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java index a1afac6f71..522b3476a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index d9f2b41cab..5310fa382d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java index 252655e741..cb3d892de3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 6c763e9c83..edafa5d393 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 2c7fb453fc..e46e1194d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index efe8e49d01..89b3c36ef7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java index 5fedcf285c..d3bfc7f17e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapperReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index fafce28fc5..3efa16ada0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 0f80ddd11c..3a4a9c1306 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index be5c6ba801..b92dc77a2c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 973761f7c7..fbe9076a6b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 7dd3ca680a..7f7b875413 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index 0743987b40..4687a626d1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 8f779aed23..8ac7e7c459 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 8440cb72d0..fc996c0527 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java index d91ca0e5cf..727518dad8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 6e2d067b86..912a1e0fef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index 19c6a6f9eb..e0d9ea46cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 6c9a057b31..e60b4db0d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java index dbaec580e7..2787839026 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index d7e9322d4c..b4b27f34af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index 2dfc5b6cd8..1c15b7d312 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 6bcdb93ff8..0ab210ebfa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java index 80d9e403c4..867a2a9b78 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index 2326b144b5..01875b7e60 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 2d0c2429a3..1b465ce0f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java index 6d4a00e5f0..b5aa620674 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java index 8b28b331fa..3b645240ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index 97ccc25f00..b09f123bb1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java index 98b298f567..9f84aeeff8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index dca19ec1c2..f38e90b71c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index 17f6bd4fc9..489f4063aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index 44411a4448..60dcc7a421 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.assignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/package-info.java index aff525bd1c..9a68f1f632 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** * Meta-model of assignments. There are currently three types of assignment: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Accessibility.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Accessibility.java index 959c41212c..39baf29a56 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Accessibility.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Accessibility.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index a25fab69c4..a7c6960a81 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 1cfba42f2c..94f406b1f9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java index 17cfe9c7db..c2aa73f307 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java index 4409d50eab..c4cc6c5c23 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidator.java index 9c2b4dee67..a502601fcb 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index cee6a19874..774d186261 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java index d1af4e85ef..572c483314 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java index 57428684fb..e21f5d74fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java index 15fb300b99..45b73c492f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java index 4d2e77b1c0..26d1067489 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ModelElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 98fb5dab56..cfc9a9f50f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 9cfdfcaeca..d10d2bf090 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index 61de3548c1..fc73ab4a64 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index a1724f0e25..d3f4e2aee0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 13e38cc5c8..9b795e136c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/package-info.java index 82cda989a4..32be1929a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java index 9b8bf28575..261e09c233 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.dependency; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java index 0cc35e6308..cda8e847e0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.dependency; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/package-info.java index 9f172edf79..06e132833c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index a181c3a995..5fdb28e277 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java index 62e681245b..2c13344d20 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 97523a2a60..363be4d412 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java index 754866bafa..65c9408573 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java index 8e96790a22..0f000ec74c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java index adeac692c7..5bbc704d30 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 7f695b386c..64051d4081 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java index d38451785a..a471e1c6af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 62cb0dd3df..b7f589d16a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 9f93205a12..46810e0d4d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 74925d0c82..ad6c91cf92 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java index 79a0aa8d40..63bb5c3285 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java index 4e189015c4..03bfe25c65 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index de95e77b3b..0600b01565 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index a83029db2b..1c4b2e2108 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index cfad298162..76ab08b754 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 327b7a290c..1d302043c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java index 31ccbdfb12..7ad385be66 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 58bd170034..35de0efb96 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 60c939c691..4b1c4eeec2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java index 6aed447a07..fc35f9a36b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java index 08614f3fea..88c10f8ae8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java index 9979fcf65f..a293abe8d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 49a386b8dc..09baa8b684 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java index 3e707d13c5..90a41ab9e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java index 79d008b0bf..32e5c7c55a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java index b66bea8dc6..ef04de5289 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java index 2b4188864c..771a2febb4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java index 7a5e48820d..4c18617252 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java index 1f7f1a0b5e..d8a660afb3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java index 87f0087b1c..3c8706fef7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java index be1cf7c0f3..49693748fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java index 72d80867b1..3c79036ac2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java index 76ddfa47aa..8828f2578d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java index 440da1ea1a..2e3a075268 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java index 7ee55ea2c3..ba294978a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java index 48bd25992f..d339b88cbc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java index befbed87b9..97b80b987a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java index a99cf5c571..43d8b08f71 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java index a06e78da7e..6c64929888 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.builtin; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/package-info.java index e74466ff39..040ed91f4a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java index 456649b219..ab27029099 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index 6ac3371de2..d50300ab74 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java index 8571f51831..b405c37f56 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index b077b20527..a63319d3b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index ff85bc062a..e4f05c350a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java index 351c71b35d..587a37a7fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 1495b3e6e0..69358dafd8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 5a32375697..4fe296befc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java index 00eac7e302..bc0696d2b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 9856dd9281..9b35a2ca5a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index 7824a0acac..ceed20ee07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index ce977f5664..6ab9e97097 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index ad35d691b4..3660950311 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source.selector; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/package-info.java index 7563231eaf..60bfa41d1e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 03adaa3544..77001c4815 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.option; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/option/package-info.java index 0de96a97b6..87bb426eaf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java index a68fa477b5..457607d7c7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java index 18860bc37e..839bc26f9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java index bc2ccd7b03..959f571bba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java index 5a18f80832..7ea4ce8bbc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java index f392c3415e..6783d34af0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java index d7e33ff8ef..b0f11bcc7c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java index 5b2a6fb7dc..f40cedd20a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java index 9067ff0780..8c06231447 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.prism; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java index 69aad2bb11..4c5a19a855 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 40ef3c9c5d..db42a7158e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java index cb41987785..a5e3458681 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 70ef02e45f..6454d7c20c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java index 8a1cd33513..589299bb3b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java index 7f6623ef52..4f7b46d643 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 37a3cd2775..40b7c3a3d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java index a0d90adc17..a827a60736 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperRenderingProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java index 03ea857d51..a2b7cf747e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 04eb86a13d..d2694907fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index 43a857bf37..74f0528d6e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index 1bf96cd4f5..521689d044 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 04a8dace0b..0866656de9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.processor.creation; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/package-info.java index 794fec7503..d8ab59ad5a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/package-info.java index 90503dafd8..b0aa0d0a16 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java index 247776c547..3f80ab34e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessingException.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessingException.java index 481c840a03..29c73d2691 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessingException.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessingException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 418b83f679..1bc369c2f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java index 95d5bfbe99..889b729318 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java index 05715d9fab..5b47d1178b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index e4e14c39b8..0c845037a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java index ec70657afd..7d6a87e8a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Extractor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index b50711edf0..1037d541ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java index 5de057365e..cd778162a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java index 164888beb8..4e670d17d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ImmutablesConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaStreamConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaStreamConstants.java index b532bcf564..f23e89435a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaStreamConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaStreamConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java index a83c52a6f8..8f119241bd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java index c7c9e6c55c..f8f01cd18c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JodaTimeConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JodaTimeConstants.java index 0e889cff4f..5300f1bf91 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JodaTimeConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JodaTimeConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index d7bb90260b..40670a63c1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index de257c2e6e..155ea39a5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index 85c56060dd..3d3c37441e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Nouns.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Nouns.java index 1db29bb06a..ccd7a1e863 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Nouns.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Nouns.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java index c06a335440..ad43298e82 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java index f70ce2a56b..2d37c46db8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index a14e4d8ada..bb923a5970 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java index 19b28293ac..28c706bef0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java index 5a341d8815..8216e83121 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java index fd1ad4830d..b5b671c2dd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.accessor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index 4e43d3e79c..9fb0969807 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.accessor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java index d4ef7f0cfe..356313f52f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.accessor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java index 6464f90793..fc8d54933e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.accessor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/util/package-info.java index 72f81a43ec..5dbc4e0853 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java index 1307219b34..0d61c96acc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.workarounds; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java index 0deab8d99a..d7dee52fb4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.workarounds; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java index eb3ae9503c..69b45c1ca7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.workarounds; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java index d4d0641c05..097ab52631 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util.workarounds; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java index 923158d07b..020792e860 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.version; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/version/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/version/package-info.java index 867f6cae78..114194190b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/version/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/version/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerModelElementWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerModelElementWriter.java index ea8a6d29e9..6ed6fe24e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerModelElementWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerModelElementWriter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerWritable.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerWritable.java index 090846476d..e8aa8fcf3a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerWritable.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/FreeMarkerWritable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java index 0ff950dc1b..79d164ddb3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java index 975f98e0e5..6b8b340f53 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java index fe9abe28c0..0fe78ce227 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/Writable.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/Writable.java index 2ef3539f06..42724b43c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/Writable.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/Writable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.writer; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/package-info.java index dc8cfcae46..36b72bc30b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/package-info.java b/processor/src/main/java/org/mapstruct/ap/package-info.java index a2a8c67a8c..037310099c 100644 --- a/processor/src/main/java/org/mapstruct/ap/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java index 9e6ed49d39..0afc22695a 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java index aa263ab12d..8ac41395bf 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java index 2be9c01fb0..1e55bef95c 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index fb48fcce6b..6140d7a3aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index a5ee1a2755..118ad2ba9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 365efa02f5..4869bd3679 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index 5604220920..98d34407d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index b02d4a9016..531b92f57a 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java index 98d329643f..afd7e69511 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MethodType.java b/processor/src/main/java/org/mapstruct/ap/spi/MethodType.java index f61c3b86a5..d2b93e615e 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MethodType.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MethodType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java b/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java index 8d1038aa04..a869dd9fd6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MoreThanOneBuilderCreationMethodException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java index b4c3cbe37f..e38e86d916 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java index c79ff31d01..aa9abc46a2 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/TypeHierarchyErroneousException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.spi; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/package-info.java b/processor/src/main/java/org/mapstruct/ap/spi/package-info.java index b738b851cd..ca4ed5db3b 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/package-info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ /** *

      diff --git a/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor index 6ed0dfd63f..c472c18f91 100644 --- a/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1,18 +1,5 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. +# Copyright MapStruct Authors. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 org.mapstruct.ap.MappingProcessor diff --git a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor index 61296cedec..7b27e54faf 100644 --- a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor +++ b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor @@ -1,19 +1,6 @@ -# Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) -# and/or other contributors as indicated by the @authors tag. See the -# copyright.txt file in the distribution for a full listing of all -# contributors. +# Copyright MapStruct Authors. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 org.mapstruct.ap.internal.processor.CdiComponentProcessor org.mapstruct.ap.internal.processor.Jsr330ComponentProcessor diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl index 4c8894abf4..ce0f605f11 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private DecimalFormat ${name}( String numberFormat ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl index 78c3a76c4a..bf5fa4a203 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl @@ -1,25 +1,10 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotatedConstructor" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> - <#if publicEmptyConstructor> public ${name}() { } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index 2be168662c..66458d3b85 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> @<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property>${property}<#if property_has_next>, ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl index ac42d221e3..4391960efd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotationMapperReference" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if includeAnnotationsOnField> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 6bba770a78..f5d5c9dbc7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.BeanMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if overridden>@Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ConversionMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ConversionMethod.ftl index f62ee1bf27..14d0e4883d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ConversionMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ConversionMethod.ftl @@ -1,21 +1,8 @@ <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> ${name}<#if ext.input??>( ${ext.input} )<#else>() \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl index 46dee8b6ef..e592a1d14a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DecoratorConstructor" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> public ${name}() { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl index 034a5ff812..3adf750613 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>(); \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl index bdbc8f3829..5c467772e9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DelegatingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> @Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl index 628d760fc6..0caa97fa2e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.EnumMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> @Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl index a21e77fecd..ddaa403add 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Field" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private final <@includeModel object=type/> ${variableName}; \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 0656686b4f..16942480ff 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.GeneratedType" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if hasPackageName()> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl index 5c3f95c49c..02af542549 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableCreation" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 3e404ede61..10a4fd367c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if overridden>@Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl index e34de1733b..3eef87a305 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.LifecycleCallbackMethodReference" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index ed6d903006..471c3dbe9c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if overridden>@Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 06c599c1c4..4dc538e296 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReference" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 337c6d5564..97f8c0ea2b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index 86a623e177..4f0632ed54 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.PropertyMapping" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@includeModel object=assignment diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl index 1963e84eb2..9d61e93106 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ServicesEntry" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> ${implementationPackage}.${implementationName} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index f8877a02e5..bb1ad1628f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.StreamMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if overridden>@Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl index b9469b048a..1dc7ec63b4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.TypeConversion" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 9163417f2c..bc3a63cdeb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if overridden>@Override diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index 190c95fa14..6e124ef6fd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.AdderWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl index d1b43febb8..3dd22a2cb0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl index 03f8f385d9..94a8682a00 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> ${ext.targetType.name}.${assignment} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index 9a50ebbdf2..ab254e4b51 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index 69f9fd6748..c4ab06e7a8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl index 1cb9729d0c..927372a93c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl index 00bed2a9e3..52d6efb672 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.LocalVarWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if (thrownTypes?size == 0) > diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index 6df7b17148..201e7bc70f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index 9d413fd4d5..726c73cb37 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index 102966164d..3e0395c9ea 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import "../macro/CommonMacros.ftl" as lib> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 44f37eec2b..305cb23c97 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.UpdateWrapper" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#import '../macro/CommonMacros.ftl' as lib > diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl index ab33a5100a..9174624297 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Parameter" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@includeModel object=type/> ${name} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl index 1e22080cff..9594a665b9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 75348519c1..426dd6e16d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -1,23 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> - <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 + Copyright MapStruct Authors. - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 094102039c..7f4d3bb862 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -1,21 +1,8 @@ <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> <#-- diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl index 4220268ea3..c462710bd0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Calendar")/> cal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl index 03815fac7c..f203fce790 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("ZonedDateTime")/> ${name}(<@includeModel object=findType("Calendar")/> cal) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl index 3ed932884d..fa7f5985b0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Date")/> date ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl index bc7da073b9..913e8d4d3d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private T ${name}( <@includeModel object=findType("JAXBElement") raw=true/> element ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl index 65677e7313..63f12392cc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("DateTime")/> dt ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl index 3e177214e8..7fa0f17e02 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDateTime")/> dt ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl index 5b77e2314b..5a41f31b82 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDate")/> dt ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl index 2add1e79c2..cee4edd7b0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalTime")/> dt ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl index e1139fed23..93e10b1eeb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl index 0e8db79d13..660526ac7c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String date, String dateFormat ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl index 2021d776df..a8b3ba2bde 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("Calendar")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl index 88fe71b486..bd3841c225 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("java.util.Date")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl index 1e4799dc89..555d6b273f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("DateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl index e51d87a13e..c5adac02ac 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("org.joda.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl index edcf3e3a33..ae640c6b81 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("org.joda.time.LocalDateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl index 1396324452..c8115f29c2 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("org.joda.time.LocalTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl index fc69fdd5b3..a526c6b99b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private static <@includeModel object=findType("java.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl index 5a705aa74a..f75ce8b48f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private String ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal, String dateFormat ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl index 47a951a29c..3c57b7923e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("Calendar")/> ${name}(<@includeModel object=findType("ZonedDateTime")/> dateTime) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl index 116d5d3525..a49558f7d7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl @@ -1,22 +1,8 @@ -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.VirtualMappingMethod" --> <#-- - Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - and/or other contributors as indicated by the @authors tag. See the - copyright.txt file in the distribution for a full listing of all - contributors. + Copyright MapStruct Authors. - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("ZonedDateTime")/> zdt ) { diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 47ded40dab..6e1463dea7 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 742e4391d5..cdbef06bdc 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java index 213bcb4f93..7b6fd64109 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.common; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java index b5ff2a7f44..7eb34135a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.model.source; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java index 2555209259..36f92af6bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 3959d6ac17..575288ec97 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.internal.util; diff --git a/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java b/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java index 4a2c74081e..20efe22568 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java +++ b/processor/src/test/java/org/mapstruct/ap/test/NoProperties.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test; diff --git a/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java b/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java index 5d879dbdcc..2a13360e24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java +++ b/processor/src/test/java/org/mapstruct/ap/test/WithProperties.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractBaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractBaseMapper.java index 955fb2d93f..87eb21b8ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractBaseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractBaseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java index 77441c2082..42df0b4fea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractDto.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractDto.java index b674d184d9..46af734731 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java index 3b50357486..1fa135af21 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AlsoHasId.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AlsoHasId.java index cc0c58c054..1cb76008c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AlsoHasId.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AlsoHasId.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/BaseMapperInterface.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/BaseMapperInterface.java index 17881cfb53..0c9e1ef445 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/BaseMapperInterface.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/BaseMapperInterface.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/HasId.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/HasId.java index a29ad24337..d611b229ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/HasId.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/HasId.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Identifiable.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Identifiable.java index be8c65e356..57561049de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Identifiable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Identifiable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Measurable.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Measurable.java index 1d0775f00b..b8351b036f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Measurable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Measurable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java index ed69807454..d3099f2cb0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java index 089932d170..a257135e0e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java index 655704f78d..ed8df1f079 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/SourceTargetMapper.java index 547f34566b..0f8227b3f0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Target.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Target.java index 6c91111a08..fef4406ebc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractAnimal.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractAnimal.java index 7d3d2fa12a..6a82bcc727 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractAnimal.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractAnimal.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractHuman.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractHuman.java index a3965992bd..2e38329f1a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractHuman.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AbstractHuman.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AnimalKey.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AnimalKey.java index 9fe80557e8..ee95bb8884 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AnimalKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/AnimalKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Child.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Child.java index 0ce601b65f..f1f9034def 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Child.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Child.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Elephant.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Elephant.java index 60de8084f9..9d0b37723a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Elephant.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Elephant.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericIdentifiable.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericIdentifiable.java index a7e73bb716..a4107ce86e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericIdentifiable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericIdentifiable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyMapper.java index c7ede0e588..d002b1304b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java index 2d404d4d93..d79f544541 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/IAnimal.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/IAnimal.java index 2f585887a4..6b96c829d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/IAnimal.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/IAnimal.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Identifiable.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Identifiable.java index 0b2c359b4a..4f3d7ca4a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Identifiable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Identifiable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Key.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Key.java index e43a551fc7..56e014d199 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Key.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Key.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/KeyOfAllBeings.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/KeyOfAllBeings.java index 75781ed94c..ab320ded50 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/KeyOfAllBeings.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/KeyOfAllBeings.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Target.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Target.java index 5dcf73c9c7..357e88a081 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.abstractclass.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java index f8145fab75..0ee789750c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperAbstr.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperAbstr.java index 32bdd73554..d7f7ba46ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperAbstr.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperAbstr.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java index fa983c4fb3..84e9aebbbc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/Source.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/Source.java index 7d07a1691c..ab30881998 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/Target.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/Target.java index a5d198127a..253115abb0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java index bb5261ddf6..fa612bd956 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java index ce2bb9d5d7..2ae40488f2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 7f4bea7fa5..1516e37693 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java index 499259f954..f572eee0a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperDefaultSame.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java index 108af0ac2b..58e1336ca8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperPrivate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java index d8a6931eba..389486ce4a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedMapperProtected.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedSource.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedSource.java index b0a75cf82d..e26969551e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java index da13c64fb4..1dbfe510d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Source.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Source.java index 10a0f548dd..0b833a14ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java index e075d088d1..4ada977bc8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java index 56cc9aed08..36127e1af6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java index 9a7c080776..1ec1aa6c5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java index 6abd596936..f8ac1b4d28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java index 9264ac6a12..94f9b2668f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java index 4435e81b5d..263d74bee6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Target.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Target.java index ab2e74a024..50604a8075 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java index 03ce8901b1..81dcc306f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced.a; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index d908b3102b..221bc361a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.array; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ScienceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/array/ScienceMapper.java index 89dbb34021..b0dac0ea98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ScienceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ScienceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.array; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/_target/ScientistDto.java b/processor/src/test/java/org/mapstruct/ap/test/array/_target/ScientistDto.java index 5ff88fbafe..2fe85a14ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/_target/ScientistDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/_target/ScientistDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.array._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/source/Scientist.java b/processor/src/test/java/org/mapstruct/ap/test/array/source/Scientist.java index 3e88df977e..ac2f01f1d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/source/Scientist.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/source/Scientist.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.array.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java index 01dff441a0..6ca327cce4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/Person.java b/processor/src/test/java/org/mapstruct/ap/test/bool/Person.java index 939b776bb7..6b20598ea4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/bool/PersonDto.java index 07c10c29aa..6240df6860 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bool/PersonMapper.java index f064f38534..04f806b11f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/YesNo.java b/processor/src/test/java/org/mapstruct/ap/test/bool/YesNo.java index 8a087961ff..7bbdb67cd4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/YesNo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/YesNo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/YesNoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bool/YesNoMapper.java index 79616caf19..5cc1a4c78f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/YesNoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/YesNoMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bool; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java index 7bd16b45a4..88eaeffbb3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/AbstractEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java index 6f130710d7..e8c9b71ef9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java index f507ba52cf..a027a51cbd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/HasPrimaryKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java index fa8658189d..b44b4e1476 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractResultTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java index 48a6069a89..a71a4d1417 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousAbstractReturnTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java index 0c61c60163..b84821dc86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceResultTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java index 01007b6579..525dc8ee94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005ErroneousInterfaceReturnTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index 2aac9adfe1..1e39739e25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java index 8086328965..e9722e13ce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Order.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java index 7dcdb85fd7..5108bd07de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1005; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java index b9ccfdc463..65cc635043 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/ErroneousIssue1029Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1029; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index 93832bb68e..02deaf3d37 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1029; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java index 22d681d8ff..09c9d066d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1061; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java index ff677f581e..88bc5328ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1061; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java index 8a81d91ed4..a5a624e684 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1111; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java index a908491e7c..623be34f04 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1111; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java index 940d78cfee..fce8ffcd6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1124; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java index ef2ddc9143..1516c66496 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1124; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java index 0746671992..042d5a2f8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1130; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java index fd0027b42d..2024a83933 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1130; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java index 5059ffe6ce..46fd66f433 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1131; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java index c75a967756..4939e316e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1131; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java index 3f1d167769..de3a38366e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1131; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java index fef5f8d435..38c5e28490 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1131; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java index d97617950d..a0a6337bc0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1131; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java index 6ed4f1e48b..2db0196cf5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1148; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java index f4ae218ca1..fa997becf0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1148; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java index 5997b93d66..2dc4749b9a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1148; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java index 67f87bcf9f..71c8998a79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/ErroneousIssue1153Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1153; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index e28eeb59b3..22811d1abf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1153; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java index 62a2394350..08617d6462 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1155; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java index 5db16bd460..cb2fd3453c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1155; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java index 730c81b7e8..a3295fe4df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1155; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java index 7d5dd28d6b..6ebf510872 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/GenericHolder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1164; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java index fd2990b1b7..7fa5a343ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1164; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java index e59304c77d..7f72633739 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1164; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java index 9761dfa015..41d62c30de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1164; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java index c80a8ecc22..103a699a1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1164; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java index a966299759..e882421e9d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1170; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java index 90b19f92e0..9e1e3ea5a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1170; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java index 847ec04245..f76cd4e91b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1170; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java index 4e57ce7ff5..95e0414f2a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1170._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java index 07c5d671bc..4226c92455 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1170.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java index be815188c8..1f22d34578 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1180; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java index 3953d6950d..121353a909 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1180; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java index a0dc7f6291..3afa895967 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1180; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java index f8d57efb9e..5f21a327f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1180; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java index 8948548f49..5619562567 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1180; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java index 1e4255eb0a..c18a858d47 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java index 364dda4b12..68267dd30e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/dto/EntityDTO.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java index 16f454567b..0938b1a783 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/AnotherTag.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215.entity; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java index e6e9a170f8..37ae4e1038 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215.entity; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java index b5962fee1d..04729f35b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/entity/Tag.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215.entity; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java index da517a25bd..979b6f51c4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/mapper/Issue1215Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1215.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java index 443cf12f1e..e34174f27b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1227; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java index cf9231a71e..e4612e9d87 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1227; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java index f503f3c112..ff14066a72 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/ThreadDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1227; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java index 3732aca923..7259d343b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java index 45e7547fdd..0491b5ffe0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index bf548e0108..4edeab667b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java index 874732508a..5afee73549 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceA.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java index caf301c803..53a16640db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/SourceB.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java index a100c51a70..1b861c8029 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetA.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java index f6b690073b..ab4f639697 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java index b4476bcd2d..bdec6b5ed8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetFactories.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1242; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java index 42b8076f17..ebb27fc202 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1244; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java index 8de1c6874c..0e647360e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/SizeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1244; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java index 5012d60b85..69a19454e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoIn.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java index 1a5cefc57f..667a5e02ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/DtoOut.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java index aafdc6838d..2c9684584f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalData.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java index 6e3ec8a5af..a69385dd6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/InternalDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java index ba3086631c..5e216a334f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java index beaef236cf..884fb7fdb2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java index 36439f0ceb..80660b0bf1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherDtoOut.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java index f06bacde4f..3773029266 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalData.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java index 91fe5d7eaf..25411c207c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/OtherInternalDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1247; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java index 0b9c107ca8..edb36b1d38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/AbstractA.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java index 924e8533bc..a459099000 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java index a9e030f7dc..cea619e6fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeA.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java index 1820b96764..9f6019fdee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeB.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java index 0fb3137c05..b1350d991c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java index dfe711f50e..145de5b95c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/SomeMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1255; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java index 9329eddabb..7f44ea012b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java index 046972b5f3..bc6842cfef 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java index 50de755f7b..3e0b0b8414 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleImageDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java index 55f6ef7ddc..48255fcb25 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/dto/VehicleInfoDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java index 9db3fdfb0a..eba04c130b 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/mapper/VehicleMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java index ba19f8d16c..9b02435a16 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/Vehicle.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.model; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java index f9ff4fed44..19ac16c8ad 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleImage.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.model; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java index dc803dc520..7310e63c3d 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/model/VehicleTypeInfo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1269.model; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java index b38fcaec61..d91aaa8279 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1273; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java index f93a3578f2..ece26b3bdd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1273; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java index 38e2a1f5ac..3f0d1e003f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1273; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java index bd9c284b22..331de18d13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnNull.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1273; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java index f50e9c2c9c..e12edd50a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1273; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java index db16b4c166..fd109d0dc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousInverseTargetHasNoSuitableConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1283; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java index fac5677d87..259285993c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/ErroneousTargetHasNoSuitableConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1283; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index 951976d53f..d70827ae80 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1283; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java index a55fa332c0..a34c8d4a53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1283; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java index 2285de7015..02a26968f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1283; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java index f7e09e6d00..b20ef4a72d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1320; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java index 563ffbfd2f..2b6b918bb3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1320; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java index b848d25f38..3fb27141eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1320; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java index b4b6b7022f..faff474e00 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1338; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java index 08a4b3ccd8..8274b748ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1338; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java index 1700fd62d0..4717001147 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1338; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java index 0ee75087f0..a06a52c16a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1338; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java index 5724322c01..f7f42079be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Callback.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1339; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java index d11d41f4b9..d3463e712b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1339; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java index 63dcc1f100..5846860098 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1339; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java index 72cd7b2997..2b511956f2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1340; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java index b303beb4d9..d4fdac257d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1340; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java index 5b8733b951..7699a8f7e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1345; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java index 0397fdc89d..c5ad1c3030 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1345; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java index f94551460d..e22bd946a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1353; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java index ad074548ee..d07b0532ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1353; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java index d216236bf2..1a6c62db39 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1353; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java index 3197f092d7..15ece1eb3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1353; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java index a0270788d6..6b4e1257b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1359; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java index 9e4d8276a9..d81554b8eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1359; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java index 7b4bb0d2d0..7646bad7c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1359; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java index 196118eb59..9aa853ffff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1359; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java index 3890db403d..5fb62711db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java index 85e70dd0dc..d08d8d3d36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java index 4d6b7bfa07..55b7de30eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java index 3cb4996cdf..a7c160aaa5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java index 96ba139cb8..559e39512e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1395; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java index b1333a4a09..21d2f5015b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1395; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java index 95f39909c2..765764ef2b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1395; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java index f79943b2ef..1b676c2b62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1395; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java index 1eb6c41522..2c7b22fd4d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1395; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java index f61f8c4a7c..2e500aa285 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1425; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java index 15ee02797d..25a148e474 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1425; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java index 2c97acc5fa..1a739197d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1425; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java index da1d0394ae..57d96dad49 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1425; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java index 60f32b6500..11f44281d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Auction.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java index c3a68bba09..ef92bc8272 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java index fa3e0b4c54..d6ba8b9917 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java index 47ece0437f..9ba0a41cf3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java index e3ec1a7f03..f03461e10f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Payment.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java index 0763b24416..68963c7353 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/PaymentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java index 7f099a499f..90ed83d28a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java index 18ff7c5340..b436899147 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java index 2ac3f93026..c97909aeec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java index dcb20fa6be..e680f7d29c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java index a1da8a805b..216cda21fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java index f0ffd86768..ff3ea2d1c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java index 6515c6fa82..76b5124d2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java index f7cf79ebb6..1a7554b54f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1460.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java index b68d22acdb..d62464c11a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/BigDecimalWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java index 48d72e4b0a..74f6923734 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java index 82087751b7..78c98c8af7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java index 3423132cea..3ef01c76bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Source2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java index 58d0652494..d421b17ef1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceEnum.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java index 194587b155..01a50311ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java index bb4d7a75c9..3c3ede8016 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java index 3ad2af79d1..d589927a19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java index 2ae62cee57..09f331c5ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/ValueWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1482; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java index eb54dc6c0c..044e714e65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1523.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java index 0ebde15c2a..b922dcc14f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1523.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java index 5ccb45d9cd..1075599c54 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1523.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java index 009c4ca62f..7492d58b99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1523.java8; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Mapper.java index 95dad2c3b1..29e6305187 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java index 67c4dd868e..fb9d16112a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Source.java index b9f2c3c2c5..76365a6354 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/SourceElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/SourceElement.java index 5ba6026f4a..453933e940 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/SourceElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/SourceElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetElement.java index ee719e4e64..3131fffdf0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithSetter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithSetter.java index 1355786fe3..6c9cdc7fd5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithSetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithoutSetter.java index c25d6509dc..b3fb312c82 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/TargetWithoutSetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._289; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Mapper.java index 4669f7677e..9d0b9a2574 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._306; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java index d775baa747..712e563ca8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._306; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Source.java index 8b3c6f6485..741e54fe3b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._306; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Target.java index 14092b3699..50196032b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._306; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Branch.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Branch.java index 5177c46687..2f3165b32f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Branch.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Branch.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/BranchLocation.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/BranchLocation.java index 43efd95a0a..b5d83e015e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/BranchLocation.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/BranchLocation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Country.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Country.java index 912c1a3e02..9d6b827626 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Country.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Country.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Mapper.java index 66999ad905..ac64cd7db1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java index bcafe22503..d860591fff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/ResultDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/ResultDto.java index a37839371e..d3799efbed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/ResultDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/ResultDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._373; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Mapper.java index db3c985181..b12bbd5e07 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._374; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java index 82d27b5b93..63ed283f17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._374; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374VoidMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374VoidMapper.java index bff99efe6a..6fa27a806c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374VoidMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374VoidMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._374; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Source.java index e57c3737f0..349fd4a1e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._374; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Target.java index cdd53f038f..ab87548921 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._374; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Case.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Case.java index 025fdc5a90..2eb9e1aaa5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Case.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Case.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Int.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Int.java index 324cd4d8a6..0006257cfa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Int.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Int.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Mapper.java index 2e790f30ca..acc76e04c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java index 723d74b6a5..e02c56a1d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java index f02aefb4d6..6f9b154033 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Target.java index c6d3abe850..80a86f2cb2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._375; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java index 9a0311961f..ac9dbf93c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java index 2364b17ca3..8cca546200 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/AnotherCar.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/AnotherCar.java index 9003a7d43f..bd99d6f524 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/AnotherCar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/AnotherCar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/Cars.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/Cars.java index 233701beea..185e52e046 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/Cars.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/_target/Cars.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/AnotherCar.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/AnotherCar.java index 0b0e2ecf70..0d050196e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/AnotherCar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/AnotherCar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/Cars.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/Cars.java index 6a22c6a37a..68bac36095 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/Cars.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/source/Cars.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._394.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/EntityFactory.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/EntityFactory.java index a86dd77590..77811f4ad9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/EntityFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/EntityFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._405; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java index 0eecf73222..75f6e6952e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._405; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/People.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/People.java index d59d86f6ec..87e7ab8818 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/People.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/People.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._405; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Person.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Person.java index 7883db38b9..36c119cd41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._405; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java index a1ebaf0e8b..b9e15b1da9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._405; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Mapper.java index 09df5cb258..32cf02e3af 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java index 545c1e3df9..90bbcec3c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingException.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingException.java index 2bf8c94730..289e86abbd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingKeyException.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingKeyException.java index af409b1d49..668667fb07 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingKeyException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingKeyException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingValueException.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingValueException.java index 0f536f647d..9bf51c2fdd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingValueException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/MappingValueException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Source.java index 963f63e755..1e85ffe808 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceElement.java index 520261e0d6..329b502361 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceKey.java index 40e691e207..9490e95d61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceValue.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceValue.java index 84c38938c9..fbdde5a474 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceValue.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/SourceValue.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Target.java index ed289ef7ae..7356849403 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java index 5dd5b081d9..dc794a62f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java index e06194dfd5..e697afc20a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java index dbfb005017..d999de75a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._513; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Mapper.java index a753c3720d..5baaa475d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._515; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java index 26e90117a8..e322963db7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._515; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Source.java index bf269841bc..c21d940f63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._515; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Target.java index ef6379de41..bfb27f7276 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._515; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java index 862151774b..5b64aca1dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._516; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Source.java index 7507117635..593522d4a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._516; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/SourceTargetMapper.java index 2e5c58cdd1..a55f793ffa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._516; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java index 76b42f4539..8bb32e38c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._516; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java index 67a88ba368..3651d41ba6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java index 21c81318e2..14a60f7b36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537MapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java index 22d9d39135..ce5fb5dcbb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java index db3b91f924..86f9554c86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/ReferenceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java index 753c6a47c4..dd1040dafb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java index afe1fb35b5..4a95e4aeed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._537; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java index 798870ced7..1a22879c38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._543; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java index 2626dd4934..0773f7d271 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._543; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java index 7c5808fb87..ef0e7879e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/SourceUtil.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._543; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java index 1c6148d5f0..2a996f1fe9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._543.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java index 25a423db9b..c868716db6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/dto/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._543.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java index 74191a4a22..9b6672a539 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._577; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Source.java index c5aec85321..80dd1d6408 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._577; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/SourceTargetMapper.java index 784151666a..7b4987c996 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._577; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Target.java index b59022e87a..7646439a66 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._577; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java index f557a7a797..cf50b344e1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._581; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/SourceTargetMapper.java index 02234dc553..4619412738 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._581; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/_target/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/_target/Car.java index 9ac3649ae7..cf472286b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/_target/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/_target/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._581._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/source/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/source/Car.java index cef6c41d1a..b5289a3492 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/source/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/source/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._581.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/ErroneousSourceTargetMapper.java index 8300bf971a..0991468293 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/ErroneousSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/ErroneousSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._590; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java index ef7091bc69..28f06b2acb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._590; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java index f8e96ec75d..1a503a74b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._611; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java index ea9bd23f9f..0d41128711 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._611; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java index aa0c560027..e50187a82a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._611; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java index f52dac5d29..32fc27d56c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._625; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/ObjectFactory.java index a4fdbca8bb..3cdf4a03df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._625; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Source.java index 64fd2df40b..94a811a0f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._625; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/SourceTargetMapper.java index af4650cab8..e11cb05411 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._625; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Target.java index bfa7af20da..2340f7e09e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._625; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base1.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base1.java index cfaf8fecd9..eccc9fb612 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._631; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base2.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base2.java index 7b9fd40a62..3e01907520 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Base2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._631; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/ErroneousSourceTargetMapper.java index 5f2a91314b..30e4688b8c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/ErroneousSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/ErroneousSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._631; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java index 2dac1dd640..00edd36804 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._631; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Bar.java index 4e4b84e5a4..c731414aa6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Foo.java index ebb28d7533..10ba1b423e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java index 551982b558..a9ae5167fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Source.java index 895effb2c2..e5d3ae101b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/SourceTargetMapper.java index f465934d45..54bb1a2651 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Target.java index a368b2e673..5c3a1cb892 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._634; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableContainer.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableContainer.java index 472e340747..ed2d0df612 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableContainer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableContainer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._775; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java index 0e4e26f7ac..9b6c6d40f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._775; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/ListContainer.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/ListContainer.java index df520075e3..df4229bfe2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/ListContainer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/ListContainer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._775; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java index 1c6cdc8249..39e8a5772a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._775; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithForgedIterableMapping.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithForgedIterableMapping.java index 473f5b93da..c659bf596c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithForgedIterableMapping.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithForgedIterableMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._775; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java index b47f65f49f..b0d74bae26 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._843; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java index 922a94e08b..ff298ad8a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._843; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java index c8d4c48a28..1540df73d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._843; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagInfo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagInfo.java index 5870853ca9..55af1beb9d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagInfo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagInfo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._843; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagMapper.java index 5e6d20b1c9..334ac52ef0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/TagMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._843; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java index 1747c94be3..f52f226ef1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._846; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java index 63aa45a874..9bac413c0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._846; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java index 0b08571599..a54a3cb3bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._849; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java index 224b0306d7..313913286e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._849; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java index 064ffe5b14..f96483aa24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._849; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java index 0618b10bb1..b89eac46e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._849; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java index 5f0062aaf7..f968509d65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderDemoMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._855; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedSource.java index f96ca6ef08..6cc57147a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._855; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedTarget.java index 4f35b13ca6..af9f7c3c3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderedTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._855; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java index 2729eca1cd..eaeba688d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._855; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java index 8871f6dc1f..d0be73f9c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjCoreUserEntity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjCoreUserEntity.java index d1865e6873..ee6495f568 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjCoreUserEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjCoreUserEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjMemberDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjMemberDto.java index 0f97e62f3a..ada4fdc40d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjMemberDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjMemberDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectDto.java index de288c29ca..1bd35bae76 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntity.java index e57b95acf9..dd01abe045 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntityWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntityWithoutSetter.java index 691fdcc432..8e4ae71129 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntityWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectEntityWithoutSetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectMapper.java index ffa699adb8..b23db3d35d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/ProjectMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._865; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java index cf50a0a392..32f58384b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._880; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java index d1555374ca..c54da3f7cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._880; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index b3db6c142e..9ad1352e20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._880; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java index 5974d6d4df..e822db1cfe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._880; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java index 72e7d57847..ed4267cf12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._880; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java index 1d39b11be6..ebc654bf16 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._891; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Dest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Dest.java index 281c065ef8..f0a8c64936 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Dest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Dest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._891; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java index 78ab232aeb..a520a055d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._891; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Src.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Src.java index 3e65efab4f..f461aba664 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Src.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Src.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._891; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/SrcNested.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/SrcNested.java index c638f9d263..5557030822 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/SrcNested.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/SrcNested.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._891; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Mapper.java index f53762ecf8..84b6d12a15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._892; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java index 3bdb375eeb..6291a56233 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._892; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java index 1cafeaa3d9..9de76b43d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._895; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/MultiArrayMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/MultiArrayMapper.java index 4acc5b6e7a..7d01485e38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/MultiArrayMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/MultiArrayMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._895; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java index 4cbe2531f0..da74677ee2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._909; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java index 2061e8d51f..fb4cede674 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/ValuesMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._909; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java index 022a937c95..2eb2e85030 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java index 4ce109c9f0..f7a995a351 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java index e926b2c920..7fef9d8b92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java index c7a6a3d8ad..4d6fd9eff9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java index 1675a74058..ddb0a60cea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java index dc761eb277..df821ca182 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsDefaultMapper.java index de537096d1..74564f7859 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsDefaultMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsNullMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsNullMapper.java index d6f595163d..90916555ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsNullMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithNvmsNullMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithPresenceCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithPresenceCheckMapper.java index a5758ab8c1..b3ed59852c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithPresenceCheckMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetterDtoWithPresenceCheckMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java index cbc01b8243..dd152beccc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java index a4a6103e4d..3d55e1ec21 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Helper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Helper.java index 1e60807a28..91c8db655f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Helper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Helper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java index 96ec3968f4..c9c3182edc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index 2665883464..29ad1e5bfa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java index 1c333021d6..8fc0e0cbcf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._931; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Nested.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Nested.java index e66ecfcf60..a31265cd14 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Nested.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Nested.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._931; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Source.java index 92a48be775..e3faec32aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._931; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/SourceTargetMapper.java index 755edd1ba5..c418b778e3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._931; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Target.java index f23dcfca8a..6f1f4b8661 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._931; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CarMapper.java index afd7784b36..6855f47957 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CustomMapper.java index eeaccfa343..b4688f6258 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/CustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java index e049c250b8..8178668900 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Car.java index 4226f4e397..5aa4f1e2b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Person.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Person.java index 673d36c448..82adc0cd97 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/SuperCar.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/SuperCar.java index f7920850bb..43cbfc3651 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/SuperCar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/dto/SuperCar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._955.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionSource.java index 6041810e9f..23873fabf9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionTarget.java index a6b225315b..26652b15fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/CollectionTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971CollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971CollectionMapper.java index b8f6e70661..d34d6e3dac 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971CollectionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971CollectionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971MapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971MapMapper.java index f53ed7ccde..d96e5f008e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971MapMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971MapMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java index 7bd6afe0b8..236f1641c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapSource.java index 5eeaca1685..c56973f23c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapTarget.java index b59ff7f988..43f8abf689 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/MapTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._971; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java index a71461fe6b..8ff3bf9fad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java index f1b7291427..f8b9421ebc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractImmutableProduct.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java index 8d47ba3cf5..41ed9d43e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractProductBuilder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java index 77aeed710a..d3b710cddc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ImmutableProduct.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java index 30b4c9d8a9..0e3eaaae6b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java index 937935a377..877c18746d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/ProductMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractBuilder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java index cf3913c179..8ff58c5af3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java index 306d4b1b61..a136448b18 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Child.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java index 1884f8cef4..6a23998adf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ChildSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java index becdb4fab1..23dc617408 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableChild.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java index 392ccbf979..f0877844a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ImmutableParent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java index 3232ce89d1..e43417d753 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableChild.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java index c8ba05e371..8ad97dbb62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/MutableParent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java index 5bc5c8d448..8d3f548973 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/Parent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java index 372f34dc01..0fa5f5633f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java index bf0f378bbb..56e6da533f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/ParentSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.abstractGenericTarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java index e7ac6c2e99..2846e17795 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.factory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java index 827d3f9f87..57641a6dc1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.factory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java index cc1feeafab..916b3cac32 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderImplicitFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.factory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java index f94a167546..f371c1566c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.factory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java index 797b7bf56a..ac326e524a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.factory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java index 50b6d35e59..3ababeec92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java index 24ee73188a..7835305be5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BaseEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java index e3c8dbd81d..58848b0b8d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java index 67a699e536..1cd9be99b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringMappingConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java index 0538aeda21..d179a17ff7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java index 0fafbae7c7..7ab599bdf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java index b3b137f9f9..31d3ac08f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java index 890c96da29..706a08eea1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java index 636a71b0ec..19da018e85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Item.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java index a14d93265a..664d99c966 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/ItemDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java index 157b5bbce8..96b9b30db6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java index b3d1d3621d..5342a5e444 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java index 958a668c07..5da6578a74 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java index ccfcb42908..12dab91ce2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.lifecycle; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java index 3a0d6fa5dc..e44912ff99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.mappingTarget.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/MutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/MutableTarget.java index 374d12f429..02668f5fff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/MutableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/MutableTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.mappingTarget.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java index b79d626ff3..9f7187c634 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.mappingTarget.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java index 50b62be8f7..cc7b103dc0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.mappingTarget.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java index 4b23a79938..9befd215a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleMutableSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.mappingTarget.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java index 79eb4de38e..3a2d6a2c60 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderConfigDefinedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java index 85e497ce25..2cccbc0afb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderDefinedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java index 90f69a1497..2bd52af4b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/BuilderMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java index ce39c7e367..8e66255d59 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/DefaultBuildMethodMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java index dedad6f2d4..1c591f8e48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java index a7ff63573d..34194e5025 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java index 12bd0dd635..6bf212d299 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java index 93c0ab59f4..04701b8472 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java index 234fe6e851..67317d2edd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/Task.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java index 1b935eb2ef..a5d7b6d38c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/TooManyBuilderCreationMethodsMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java index 939249f531..8e30310c6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/build/Process.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple.build; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java index a4251abd5f..d1d9805462 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/builder/Case.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.multiple.builder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java index cad6440276..45073dd906 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.expanding; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java index b9d855bcfb..9b2196da07 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ExpandingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.expanding; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java index 682ab86e32..70cbbb7f84 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.expanding; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java index 622fbeaba0..2d86e74d0d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableArticle.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.expanding; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java index 067218b4d1..2bfc65f0b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/ImmutableExpandedStock.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.expanding; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java index 5f5020519c..c24cb55b5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Article.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.flattening; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java index fbf1b32332..a25e224472 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.flattening; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java index 75a339b53e..b3b4123e83 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/FlatteningMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.flattening; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java index 461bd3e7dc..bc941fc290 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/ImmutableFlattenedStock.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.flattening; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java index ab10144e1f..56845d1163 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/Stock.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.nestedprop.flattening; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java index fa72dc47c5..6334be7ff0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.noop; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java index f40e49f8a4..02e371f773 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.noop; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java index b36f62acb0..f739803330 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.noop; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java index d2146690d9..1aa0072dc3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.noop; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java index 3f95ce98cf..e4d067c704 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableChild.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java index 88d9967c02..b77860532b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ImmutableParent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java index a3688275d3..e1e2b7c71f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableChild.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java index b0b975b35a..ef91baef48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/MutableParent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java index 671c095cc8..f1a3b4d617 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java index 479d4f5e92..179c9f947c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.parentchild; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java index f5812aaa85..305ae77e80 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java index 3b430b8246..0b0e961b30 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index 5afa4e6682..f35cee8f9b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java index 0d9a92b745..daa3dfad0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java index 52b6c49ee2..34fd71ad92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleMutablePerson.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builder.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 62e6267072..42e6919663 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/IterableTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/IterableTarget.java index b3467c0245..bf43900e6b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/IterableTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/IterableTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/MapTarget.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/MapTarget.java index 4c33ce465a..b280ddc61d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/MapTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/_target/MapTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/CalendarProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/CalendarProperty.java index 90bd0f2299..8ff72ea59c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/CalendarProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/CalendarProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DateProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DateProperty.java index 912ca6f98c..8ace868dad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DateProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DateProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementListProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementListProperty.java index 321b32b493..dd2d2ec41f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementListProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementListProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementProperty.java index 3c0c616c6f..c981ab613c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JaxbElementProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringListProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringListProperty.java index effcfea81b..4cc073ccd0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringListProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringListProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringProperty.java index b7063cfd93..218ce61553 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/StringProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarProperty.java index bb165acb6e..c15a62eb9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/bean/ZonedDateTimeProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/bean/ZonedDateTimeProperty.java index ee391ff135..467f553077 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/bean/ZonedDateTimeProperty.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/bean/ZonedDateTimeProperty.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.java8time.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/CalendarToZonedDateTimeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/CalendarToZonedDateTimeMapper.java index ec2be5bf15..8c860ce319 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/CalendarToZonedDateTimeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/CalendarToZonedDateTimeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.java8time.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/ZonedDateTimeToCalendarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/ZonedDateTimeToCalendarMapper.java index b1281c111f..5034a05db4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/ZonedDateTimeToCalendarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/java8time/mapper/ZonedDateTimeToCalendarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.java8time.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java index 6d4cc75928..9f1e6cef20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/DateTimeBean.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/DateTimeBean.java index 22f08dac33..e250aa12df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/DateTimeBean.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/DateTimeBean.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateBean.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateBean.java index 60d553e397..3306964076 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateBean.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateBean.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateTimeBean.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateTimeBean.java index dadebd9d73..d7e968848d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateTimeBean.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalDateTimeBean.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalTimeBean.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalTimeBean.java index f59ab320e6..fd74f507b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalTimeBean.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/LocalTimeBean.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/XmlGregorianCalendarBean.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/XmlGregorianCalendarBean.java index e87731e3ec..7ba0fd4aed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/XmlGregorianCalendarBean.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/bean/XmlGregorianCalendarBean.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/DateTimeToXmlGregorianCalendar.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/DateTimeToXmlGregorianCalendar.java index 459c394c2f..d56a7b5019 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/DateTimeToXmlGregorianCalendar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/DateTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateTimeToXmlGregorianCalendar.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateTimeToXmlGregorianCalendar.java index c88ab55231..e36808d608 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateToXmlGregorianCalendar.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateToXmlGregorianCalendar.java index 1eabb75bda..d9a3b2ce19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalDateToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalTimeToXmlGregorianCalendar.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalTimeToXmlGregorianCalendar.java index 2180efc095..74b5ffda71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalTimeToXmlGregorianCalendar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/LocalTimeToXmlGregorianCalendar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToDateTime.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToDateTime.java index b9b0d8a9a1..a173faacf1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToDateTime.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToDateTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDate.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDate.java index d956606100..4fa3f31d49 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDateTime.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDateTime.java index 99ef408481..b5807dfe81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDateTime.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalDateTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalTime.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalTime.java index 17ec485b4a..28d082469f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalTime.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/mapper/XmlGregorianCalendarToLocalTime.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.jodatime.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToDateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToDateMapper.java index be052a305a..a0abde8a87 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToDateMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToDateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java index 81626f8b52..da21e10e0e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToStringMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToXmlGregCalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToXmlGregCalMapper.java index 17e72ee193..445507a8bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToXmlGregCalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/CalendarToXmlGregCalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToCalendarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToCalendarMapper.java index 32794e0d64..fcc04131f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToCalendarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToCalendarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToXmlGregCalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToXmlGregCalMapper.java index 26d4a264c2..9136959ad6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToXmlGregCalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/DateToXmlGregCalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/IterableSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/IterableSourceTargetMapper.java index 05b228cd0e..5e5e669a38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/IterableSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/IterableSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbListMapper.java index e4ebcddb3b..c34d956a2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java index b97689c637..ae49b8d178 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/MapSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/MapSourceTargetMapper.java index e7e2f14632..8d0524332f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/MapSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/MapSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java index 385cebd2e5..31e782976e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToCalendarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java index 3880f96b6b..a216b0b262 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/StringToXmlGregCalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToCalendarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToCalendarMapper.java index e36b273ff3..29835c39b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToCalendarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToCalendarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToDateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToDateMapper.java index b942602dfa..8b6eca9512 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToDateMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToDateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java index df6e94cccd..69d1ddc961 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/XmlGregCalToStringMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/source/IterableSource.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/source/IterableSource.java index 824d238a2a..da21ed6cd5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/source/IterableSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/source/IterableSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/source/MapSource.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/source/MapSource.java index f77cb7471b..c05ed16625 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/source/MapSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/source/MapSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.builtin.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java index cf37085c5a..11e5e515f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java index 5a72f807fa..91a84655fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java index 5c37663fae..762247045d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java index 9a560294fa..e408852a0c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Qualified.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Qualified.java index f80a554c7a..1a0f48f4b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Qualified.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Qualified.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java index 90f7893ef9..7194ecc2a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceEnum.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceEnum.java index 25b636cd5e..93e393246a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceEnum.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceEnum.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetCollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetCollectionMapper.java index c8f62b5405..2d6996b484 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetCollectionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetCollectionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetMapper.java index a7824fb7a7..725bbe5c03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java index a92f0af080..90edbe462f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/TargetEnum.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/TargetEnum.java index 65242cbfc6..016be4363f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/TargetEnum.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/TargetEnum.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Address.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Address.java index d56f7cf729..503e57ae25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/AddressDto.java index 635ea83aa4..4d6a16182c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/AddressDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Company.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Company.java index 88a77ecd38..182568a730 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Company.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Company.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyDto.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyDto.java index 69a7ac6a58..3227a04970 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapper.java index d0c848b092..4296f07791 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java index e202d8b461..dd18e48aa6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Employee.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Employee.java index 9a685565fc..95a31a47a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Employee.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/Employee.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/EmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/EmployeeDto.java index 8f41b760e6..55ceeb40ce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/EmployeeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/EmployeeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java index de84c16f29..19feaefda2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Attribute.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Attribute.java index 1fbd761ddb..54d7434a3c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Attribute.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Attribute.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java index 4d7e3f1b11..7bb178ae85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/AttributeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index c10c4c3d36..bea89fa7f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java index e3ef456549..c939ec7d3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java index d5ef75a37a..36f7a2e3b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java index e1f82f5552..def62dab8d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java index f3dfe15a07..f633a63d11 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java index 8830bea521..456eb1134b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperWithContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Number.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Number.java index ad7c0bda1d..9edd87025b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Number.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Number.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java index ddadffa7ad..7ce3510775 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperDefault.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperDefault.java index 13919341f9..d21e67fdb8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperWithContext.java index 819162e88a..2a1f48e726 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperWithContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.returning; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java index 22ea4d620a..e92dec0105 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.typematching; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CarMapper.java index ba5170570e..2d3105531c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.callbacks.typematching; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java index 8dfa001b4a..8f752ec497 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/Colour.java b/processor/src/test/java/org/mapstruct/ap/test/collection/Colour.java index 15da46b18c..b9cb1870f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/Colour.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/Colour.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/Source.java index d00ed3e986..0ceb45af7d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java index fd192d07bf..d716918d78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java index 5e1f823c10..36cb8f38db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderArrayList.java b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderArrayList.java index 56de9408e3..6b3b4fd4b6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderArrayList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderArrayList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderToLongMap.java b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderToLongMap.java index 2334e4feba..9705f2b12f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderToLongMap.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolderToLongMap.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java index 3b16a91b3d..e4e445962f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/TestList.java b/processor/src/test/java/org/mapstruct/ap/test/collection/TestList.java index b06da0d389..68741e5b84 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/TestList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/TestList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/TestMap.java b/processor/src/test/java/org/mapstruct/ap/test/collection/TestMap.java index a9d3c74aee..6ff922fc1e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/TestMap.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/TestMap.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index 6f434d2db6..cb2a93b1a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/CatException.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/CatException.java index 26e8dc605f..970f7d7368 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/CatException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/CatException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/DogException.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/DogException.java index 3e91e3d020..e28c2749c5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/DogException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/DogException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java index 837a4baad1..9cb74c7dc9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/Source2Target2Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/Source2Target2Mapper.java index 9b3a301119..a0be9730fe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/Source2Target2Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/Source2Target2Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java index 10b5167456..5e3017c19a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefault.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefault.java index 08670928f6..4a824fa768 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferred.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferred.java index 97b0551d0a..93a5a7e531 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferred.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferred.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/TeethMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/TeethMapper.java index 89d36d03cd..06e416828b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/TeethMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/TeethMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/AdderUsageObserver.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/AdderUsageObserver.java index 71c15d6325..c579b8e40a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/AdderUsageObserver.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/AdderUsageObserver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/IndoorPet.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/IndoorPet.java index 17c077c12e..954ced0938 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/IndoorPet.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/IndoorPet.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/OutdoorPet.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/OutdoorPet.java index 296f540489..8cb2475e6e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/OutdoorPet.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/OutdoorPet.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Pet.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Pet.java index 8920b71dcf..145f2b85ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Pet.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Pet.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java index 7d87d1b7ec..022d593650 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java index 946e7f4982..850c6ee94d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java index 5f45e150f4..3d437b3ab7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java index f2ff11f0f0..8117abf2b4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java index 5a8dc634c4..1e21e819ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java index ec5fabad8b..0840e0115e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java index 695765c0bf..69613854d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Foo.java index 00be6cfbe0..6395243177 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java index a9cf9f5fd0..91e277a209 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source.java index c70f549b1e..862ea96fc3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source2.java index 356d8ea38e..93369bde2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/Source2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceTeeth.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceTeeth.java index e5d02df58f..3abe3afc2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceTeeth.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceTeeth.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java index ce6a0a245c..b5de8abaab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java index 5326ccbd6c..914a5e3f01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterMapper.java index 58eb9db200..0c7302d657 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterSource.java index f17d6f5efd..6bb1d429b4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java index c266f7f413..562966dfd1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Source.java index 96236406f5..990681492a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceFoo.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceFoo.java index e2d7671b47..697c27fe45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceFoo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java index 724c9f647f..1143a311ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java index 1293637a30..8a5cc6200c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java index 9b2b909200..da76cc4134 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyItererableMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyItererableMappingMapper.java index 94513ebe9b..cc93860cbd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyItererableMappingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyItererableMappingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyMapMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyMapMappingMapper.java index 62e5a949d4..14ba978fcc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyMapMappingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/EmptyMapMappingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 5f76775943..cf0aa78a39 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java index 2b153913c2..e3659574ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java index 43a159f5bb..aa249cd205 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoElementMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java index 8891b2da92..346124d59f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java index c0cd8fcb71..ae966e4f5d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoKeyMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java index 9bfd418f31..35caf8f60a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java index 365c62a757..220ae0a50c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionNoValueMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToNonCollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToNonCollectionMapper.java index 40f23f1ac4..bbd56a3dd4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToNonCollectionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToNonCollectionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java index e753492dad..50a0a4fc0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionToPrimitivePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java index 7813dfaf82..24a9ce883b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java index 64c8ff77dd..046e92734c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Bar.java index 930058c792..5dfb58c504 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapper.java index 19331f3485..39b9d6ce57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapperNullValueMappingReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapperNullValueMappingReturnDefault.java index 726dec3278..130f281fdb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapperNullValueMappingReturnDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMapperNullValueMappingReturnDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 629f74efc1..d157b3f02a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableMapMapper.java index 76e021f129..bb77390281 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableMapMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableMapMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableSetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableSetMapper.java index 43acb68aeb..94fbed368a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableSetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousCollectionNonMappableSetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapSource.java index dd0cf1c490..c00c64f253 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapTarget.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapTarget.java index 648e819b5c..cae62b65a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableMapTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetSource.java index e85c57322a..8a736cda11 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetTarget.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetTarget.java index 7a5d307fcd..701c829112 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/ErroneousNonMappableSetTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Foo.java index aa29236f3d..eb4485ab17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Source.java index 450d51bdfd..e98dcc37b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Target.java index 6448efa13e..4a291e5584 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java index 10fdda78b7..917ed483ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java index 3579215535..87e9661780 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java index 1552ccc89e..bbf3a6d24e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java index de536286c9..b00f4441c5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java index 4f59ca7020..028ac4d765 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index 15561a43dd..e83c7a7056 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.immutabletarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java index d20c814f7a..b852a0a4d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.iterabletononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Source.java index 34ca2264f9..4a757d814f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.iterabletononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/SourceTargetMapper.java index 714f203339..7395192ac3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.iterabletononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java index d89e0fe1c6..1cbe6e128d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.iterabletononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Target.java index 2d46d4a0db..07cf6a0f85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.iterabletononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/CustomNumberMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/CustomNumberMapper.java index ec6a26e3c5..5fa4de9860 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/CustomNumberMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/CustomNumberMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index c705a7ae46..45ccbb911e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java index af7fc266e7..997e4a8be9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java index 94cca06a61..1f996b836e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java index 282fb27411..db1eee8976 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java index 4197c678db..91986ca5c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/other/ImportedType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.map.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java index d759020eb4..146c876871 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/CunningPlan.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/CunningPlan.java index 63aaadcae7..154112f642 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/CunningPlan.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/CunningPlan.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableExtendsBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableExtendsBoundTargetMapper.java index c45e27aa22..236d24d77b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableExtendsBoundTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableExtendsBoundTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableSuperBoundSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableSuperBoundSourceMapper.java index d22110cb5e..aa29529df9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableSuperBoundSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableSuperBoundSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java index c27fe0f904..fbe16cb8e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java index b7f42bdfa0..d725358997 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSource.java index 8dad91cd14..8181344d2b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSourceTargetMapper.java index 3df1a5df1c..059a474490 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/ExtendsBoundSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/GoodIdea.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/GoodIdea.java index edfdd743e6..d919f99e08 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/GoodIdea.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/GoodIdea.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java index c09ae57a60..fc9b89b571 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java index 74724a854b..29fcfc2f3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Source.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Source.java index 6c8e701f6c..1542c7ce96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SourceSuperBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SourceSuperBoundTargetMapper.java index e80bded7b7..181543ba28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SourceSuperBoundTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SourceSuperBoundTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SuperBoundTarget.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SuperBoundTarget.java index 367872e5c3..7b09752394 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SuperBoundTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/SuperBoundTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Target.java index c1240d06ea..86b4f001e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index cf6758ece9..692723bcc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java index 453dc657d1..20309ccae4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java index aea64ae581..0b964d6974 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/_target/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/complex/_target/CarDto.java index 30f5166ea2..8878398be7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/_target/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/_target/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/_target/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/complex/_target/PersonDto.java index d544b0f0bf..cfe527a9c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/_target/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/_target/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/other/DateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/complex/other/DateMapper.java index 3df1a8f2bd..3417d5be5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/other/DateMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/other/DateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Car.java b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Car.java index 67317837bf..bfdc4d2c87 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Category.java b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Category.java index d5af180698..ca589cf2dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Category.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Category.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Person.java b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Person.java index 9c3e200112..33dfcc50ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/source/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/source/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.complex.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java index a0afc9af5f..21a93fab82 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java index af3ffc396f..1e59c275c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/AutomappingNodeMapperWithSelfContainingContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java index 89a226eb22..72cc8270c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java index b84fa21ec3..8fc6e436e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java index 713817eb8f..48a82df57d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java index ffb2a970f4..edca0142d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContextLifecycleMethods.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java index df6b07ddce..28194513bd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java index 6eb9ddbd4a..87908f1238 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/FactoryContextMethods.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/Node.java b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java index 07b9237042..15a8effacb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/Node.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java b/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java index 2bfb2978cd..0d117aa487 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/NodeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java index 374363f9b4..8ebdb5c64a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/NodeMapperWithContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java index 7f062d5c7d..298b95aa2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java b/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java index 98ddb2e08f..210f7fc968 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/erroneous/ErroneousNodeMapperWithNonUniqueContextTypes.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java index 2ef29aa363..af0e8b5145 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.objectfactory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java index febf62e0e1..b82d07f042 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.objectfactory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java index 15da66770d..08ca1ce1b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.objectfactory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java index 4a04bdd816..887c4b3ec9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/Valve.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.objectfactory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java index 1a4a96e342..10c148f484 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ValveDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.context.objectfactory; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java index 521be1f50e..400026254a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/Source.java index 7c6858900c..78cb134897 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java index 683f583427..ae5a4e9ce0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/Target.java index 23de76c88a..8056ab6aa3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalMapper.java index ff92d16334..30bd6ba9ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalSource.java index 8413063ee4..d52cb69f41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalTarget.java index 5a187c4266..18843a25dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerMapper.java index 3692ca2221..1663df8f51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerSource.java index cbbe012b4b..34821583cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerTarget.java index ed33131c64..4204715d3b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java index eef41167b9..95adb3e050 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.bignumbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java index 190ce76234..80e0f9ffb0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.currency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java index 8c0b916d1c..eae0e41bcd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.currency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java index b9b2b0149f..a7a9408b98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencySource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.currency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java index dcf29ba691..384decb106 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.currency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 8441510fdd..ee643032b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Source.java index eb20d26b82..619ddfb117 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java index 75f4d0a52b..2ef6a7bd96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Target.java index 263b12d46a..745c599bd0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java index 7f059125d0..bee6db6345 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/ErroneousFormatMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java index 09c4ad2c3e..5a6bfd2730 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java index 8614d1d6d2..4018fc1258 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java index a6a71b8fdd..abaf46db7b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index 7e7574d1ba..1bf73e9042 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java index 9a76dd0aaf..2e5c7b63e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java index e2ea78bde0..5ca0d29fb8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java index e8ff00c4d3..37fc7d6cbe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java index 68c8430b82..c74f870f41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java index 151888a225..23fc7a5ed4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/SourceTargetMapper.java index 3e9046b739..5c8598241a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Target.java index 5e35b98e43..6b9fd2bc78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 1d9ab3cea0..60dca06ce1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Source.java index 1a2ababef7..5c23318479 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java index ff6546ad3d..d1c2723c5c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceWithStringDate.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceWithStringDate.java index 46ef4e1413..ba209d3db4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceWithStringDate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/SourceWithStringDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/StringToLocalDateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/StringToLocalDateMapper.java index 7e55dfb045..52dfd76aca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/StringToLocalDateMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/StringToLocalDateMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Target.java index a654f48baf..ef12f646cf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/TargetWithLocalDate.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/TargetWithLocalDate.java index 8efa3c9ff7..93c4607cab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/TargetWithLocalDate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/TargetWithLocalDate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.jodatime; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java index 2572c99340..9e10dbf959 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanMapper.java index 80615d8443..6765df6ace 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanSource.java index 5832578788..e5b6f0aad0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanTarget.java index 95a091af28..c9a1019c0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteSource.java index c762912138..2f647027ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteTarget.java index b9006d8b3b..3ec43ebf2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperSource.java index 8a8292c64b..e7dbe2c06b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperTarget.java index 010c2c6a74..643ec19871 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java index 80cafea743..f2cc7e3417 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharMapper.java index fdf7d48bcc..fabdb78392 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharSource.java index 9593524f7c..450c2c467c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharTarget.java index c74cef64ab..324d43a0ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleSource.java index 90ce2f320a..f061bae18b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleTarget.java index 88e875472c..62bcb28716 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperSource.java index 3565ec000f..74c9267db7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperTarget.java index 56a5ebd8bf..c3584f7083 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatSource.java index 33e1398201..0a3ca13a3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatTarget.java index de2e5f2eac..f2c7dfe837 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperSource.java index 78698d328a..1033aa317e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperTarget.java index 8b4ab38f33..d9e3deef65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntSource.java index d804202ba0..de2143fe6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntTarget.java index 2b8b9fe2fc..1e0c4a558d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperSource.java index b22fcd3717..8912a8f592 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperTarget.java index f7a568fff7..3b8d6a0044 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongSource.java index d7e5b100ae..710bc58172 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongTarget.java index 1252467848..7d1f35b23d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperSource.java index 093667e589..9c876f7c1e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperTarget.java index d5844e042a..8a6218fa5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java index 2579bfc550..b0dedb61c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortSource.java index 1ba02c15e7..cf88274634 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortTarget.java index e820c6fe9d..bd5635d07a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperSource.java index c72f3a7947..9a52592df9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperTarget.java index a1dc1367a7..4093f3988c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/SourceTargetMapper.java index eb2acff75f..8e4f51b9c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.nativetypes; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index 6ef67611a2..ed358ff6b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.numbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Source.java index d9989bcd7d..96f9a704b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.numbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java index e283e3c60f..537452fca2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.numbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Target.java index 876b2bf8e6..948dcb15b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.numbers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java index 36261ed1d3..5a3a968c1e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.precedence; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/IntegerStringMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/IntegerStringMapper.java index af368b487a..b56498ef0d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/IntegerStringMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/IntegerStringMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.precedence; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Source.java index b6590a300a..85cc46cb5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.precedence; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/SourceTargetMapper.java index fec8f56dd4..e618c13154 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.precedence; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Target.java index 8baa2f17d9..33d3ef2044 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.precedence; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java index 0306c5a2ba..ae9f226351 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.string; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java index e68a1be212..770c702f69 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.string; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java index 8d621e6c7d..8b7fe0f058 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.string; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java index 75b56deccc..db6c3553c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.string; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Address.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Address.java index af01a27e5c..fe46600813 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/AddressDto.java index 92f4d01e60..bc1c576582 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/AddressDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapper.java index 9a7d2c44b3..960250a0d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapperDecorator.java index 45def49fa2..0967bcf70f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnotherPersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java index cf51db200c..df013d5335 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Employer.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Employer.java index a53dbd9b44..aef87b819e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Employer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Employer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerDto.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerDto.java index 99bfe1f03f..3dca441eca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerMapper.java index ea6368c7a0..697526d76c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/EmployerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapper.java index 38756603e4..1019951b9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapperDecorator.java index c82e3f6c09..54eb009527 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/ErroneousPersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person.java index b3dc9348dc..b9773e0043 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2.java index 56eb026fcf..d08694b118 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2Mapper.java index 4f9a06e8d3..544f5be4ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2MapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2MapperDecorator.java index bd4528a2bb..fa7cc12ac9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2MapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/Person2MapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto.java index 5f7a414532..4036686828 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto2.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto2.java index de9eacebb8..4b1438e2b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonDto2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapper.java index ca809547d5..66ddbcd4f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapperDecorator.java index 4d7a7ad54b..f3c3ca151f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/PersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClub.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClub.java index a437f46502..13b7259855 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClub.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClub.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClubDto.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClubDto.java index 43f441e7e9..818454f74e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClubDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/SportsClubDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapper.java index a42c016b0b..fa41843773 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapperDecorator.java index e577c65d45..a22ce77827 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/YetAnotherPersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index 4089b05743..2e95f3d2ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.jsr330; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java index 9a2e90ae89..b37557bae1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.jsr330; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapperDecorator.java index cb557348d9..98d39cc0c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.jsr330; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java index 7dd675c9bd..e1e57eb6f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java index 0f7c0e726e..6c406e334d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java index dd3aefcfbf..2ed238490a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java index 3fdbd0dd6e..fc03b6ce1a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java index c9069cf9e1..315e1d0f26 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java index e95fa9a6f9..2890a4a9e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.decorator.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryDts.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryDts.java index 11c5810496..8caa4bd27a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryDts.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryDts.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryEntity.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryEntity.java index ec09a9fbbe..e11810aa78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapper.java index 3f3b9ba7bf..820e05b2c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index f1b8e0e23e..e02e00b556 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper.java index 9e68889648..5b218b3324 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper2.java index 144bf4ab7a..3f4ef62875 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/Region.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/Region.java index 806fb93a0b..25e6bd0d50 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/Region.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/Region.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue; diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/other/Continent.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/other/Continent.java index 582e2e2feb..c96ed95b3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/other/Continent.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/other/Continent.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.defaultvalue.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/Address.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/Address.java index 795b79cd19..142ce54995 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressDto.java index 79a2d117d1..6572fec403 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressMapper.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressMapper.java index 659e09b89c..0c384a7dd1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/AddressMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithCyclicDependency.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithCyclicDependency.java index 5d90ef2f05..fa08faa683 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithCyclicDependency.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithCyclicDependency.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithUnknownPropertyInDependsOn.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithUnknownPropertyInDependsOn.java index aae69336a1..edeb57a001 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithUnknownPropertyInDependsOn.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/ErroneousAddressMapperWithUnknownPropertyInDependsOn.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java index 1f1919ca83..9a6a0a0515 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index 9c3fdff9a1..9ba8a1fecd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/Person.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/Person.java index c2fc9fc9a8..99a0724329 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/PersonDto.java index 4b9c420153..0f3219080f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.dependency; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java index 73861decc9..9498b832f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java index f2d59f3219..b59d5cd21b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java index 2848dbbef2..a331096a63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperConfig.java index 7c3bc5ccf1..d0d00154b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java index 494c876cbf..ef44767379 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java index cd4ef10b9f..216786da24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java index d0fba5a6cd..d76392d11d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java index 15bdad4d20..b218fff158 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java index 6b80061046..a109ae0fc0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java index 40f4ce43ea..48d5547ff2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java index 942d890898..8c4740e323 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperConfig.java index 3be6e29fc0..9bb64eddbf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java index 3b48aa4a92..1dd371b48a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java index 92263df6a8..4f6dd3242b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java index 9e24c6ddfd..fbe69ce43e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java index e55bc764c8..b53dcaae42 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java index d38afd83bc..2a221e5f5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java index b94c8326c0..d789a7024e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.destination; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java index 632c171017..d7bb8ceddf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java index 5c0f514b36..d63ca71fae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java index a8e6c999b7..d086e91819 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java index a4520b5e14..79747b2ae9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java index 2388a05f90..827b668354 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java index 97c9359713..e9ee6429d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java index bc9136ec97..3d1a6b1dba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java index c6a3e5e7e8..4c65db6a1a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java index e1f3625d05..da519d8e28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.enums; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 24c25d8858..aa9d800b28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java index 80c67f79c3..cb1c30a2d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Bar.java index ab2a15b6d2..ebbd3be29e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java index 2560d84321..796dd0fae7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java index 5b5aafdf63..8fdd2ad52e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/SourceTargetMapperAndBarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/SourceTargetMapperAndBarFactory.java index b55ac6e603..4b7e67d71b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/SourceTargetMapperAndBarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/SourceTargetMapperAndBarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java index 708972fd42..71b5880add 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Bar.java index 654630bf1f..50bef91496 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index c35ed41a03..bd09018c32 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java index 914570ac0d..2373a6549f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java index df6ffab916..ea0c9a247e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/SourceTargetMapperAndBarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/SourceTargetMapperAndBarFactory.java index 9c308a8a29..0e4e5a6fd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/SourceTargetMapperAndBarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/SourceTargetMapperAndBarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java index 0d240301cd..2342d880eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java index b849f80516..35cb5c4462 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java index 4b55a0bd28..787aad515c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.annotationnotfound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/ErroneousMapper.java index 081a3e94c8..d9314cf8f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.annotationnotfound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/NotFoundAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/NotFoundAnnotation.java index c1bc59b1c3..d1f476c8a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/NotFoundAnnotation.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/NotFoundAnnotation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.annotationnotfound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Source.java index ae57f63e5f..ee23f10709 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.annotationnotfound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Target.java index 81a5267eaf..393d061ea8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.annotationnotfound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/AnotherTarget.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/AnotherTarget.java index d7ca42c866..86c862d59f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/AnotherTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/AnotherTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/DummySource.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/DummySource.java index 6f1d88988c..4a668f918f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/DummySource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/DummySource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java index 57484a6e22..fdb665552e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java index ce7bbeeae9..ce9134cc9a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper2.java index 698a7509d3..0dea78c6f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index cc3ea1fb40..4245d65f6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Source.java index 1b1d13ebf0..9aedfa24ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Target.java index e0804545b2..2ce74b5f9b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.attributereference; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java index 7fb159871f..83b1dbbbb7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MapperWithMalformedExpression.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.misbalancedbraces; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java index 97353ad811..bc270d446e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.misbalancedbraces; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java index be8bcbbac0..f7f58ac980 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.misbalancedbraces; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java index d7fc738177..f68b211c59 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.misbalancedbraces; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMapper.java index 48facfab40..c57c3a1262 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.typemismatch; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index 1b3e9cee6e..4b04b427e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.typemismatch; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Source.java index 28fb0ec0e8..9a0148c772 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.typemismatch; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Target.java index ae70028e4f..5d967b5790 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.erroneous.typemismatch; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java index fdd3d45253..6e6d8b4e03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestDecorator.java index 76935d5c60..8c8b328c97 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java index 9c285713f6..c856c0d3bf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/Source.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/Source.java index d0c71df15b..52a96d54ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/SourceTargetMapper.java index 58a851d329..0e5bb43f02 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/Target.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/Target.java index d56a25b5e1..ff6cd1aa25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/TestException2.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/TestException2.java index 1b9ff31b96..2e41f8d193 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/TestException2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/TestException2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestException1.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestException1.java index b3a1d6b9d0..6129110307 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestException1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestException1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestExceptionBase.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestExceptionBase.java index bdf4a9450f..b55e297452 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestExceptionBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/imports/TestExceptionBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.exceptions.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar1.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar1.java index 0463ce50a8..517a55c81f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar2.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar2.java index 64164a5bca..4859d595c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar3.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar3.java index e493f9da38..6b7eebf6e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar4.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar4.java index fc3e7cc22f..05b4c695af 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Bar4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Bar4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomList.java b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomList.java index 9ecb0eb64b..805937a450 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomListImpl.java b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomListImpl.java index 156fa870cd..887c25416f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomListImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomListImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMap.java b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMap.java index 748c721a83..1dcb8d2951 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMap.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMap.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMapImpl.java b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMapImpl.java index 54d716c77d..a9e3cd84b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMapImpl.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/CustomMapImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryCreatable.java b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryCreatable.java index 6a28e077b7..b5b77f93d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryCreatable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryCreatable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java index 327bc16ad3..e00f88198d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo1.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo1.java index 817e65bb92..ce75e17d7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo2.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo2.java index d46d7088b6..37c9d44a00 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo3.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo3.java index 7955f89d75..7430e8bd66 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo4.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo4.java index ba741b9e54..87433ad408 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Foo4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Foo4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/GenericFactory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/GenericFactory.java index 601ed9da77..b0822e683c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/GenericFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/GenericFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Source.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Source.java index a3b527e6f1..06db859fea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java index 80da7faa8e..2e33bf3ff8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperWithGenericFactory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperWithGenericFactory.java index aeeca0f3b8..5367453157 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperWithGenericFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperWithGenericFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/Target.java b/processor/src/test/java/org/mapstruct/ap/test/factories/Target.java index e5cfea36f3..46724cd07a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/a/BarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/a/BarFactory.java index cdc877735d..39665a432c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/a/BarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/a/BarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.a; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5.java index 3d06954967..6f75afd991 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5Factory.java index 68e3df1c9d..704e99bc33 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar5Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6.java index 7cd6c93d33..dfce7ab2e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6Factory.java index f3b035168c..9695af8461 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar6Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7.java index d1e69b2db6..37602cd0aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7Factory.java index 055676692c..fa90aa2a07 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Bar7Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5A.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5A.java index bd7de6cd39..cf8f337279 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5A.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5A.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5B.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5B.java index c78bf18a1b..8c860277f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5B.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo5B.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6A.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6A.java index a87fff17fb..cb4dd30f9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6A.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6A.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6B.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6B.java index eff9a25a7d..783a7ec5ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6B.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo6B.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7A.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7A.java index 928967e70d..56d3707680 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7A.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7A.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7B.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7B.java index 6e0d620aa4..1670a587c5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7B.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/Foo7B.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java index ea7a4aeb68..5ea82a5096 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssignmentFactoryTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssignmentFactoryTestMapper.java index e45198f47a..d6d0bc2791 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssignmentFactoryTestMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssignmentFactoryTestMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/b/BarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/b/BarFactory.java index 2584db5229..0b05a663be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/b/BarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/b/BarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.b; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/c/BarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/c/BarFactory.java index 9793b5a53e..bf7facbbd5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/c/BarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/c/BarFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.c; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10.java index f3f0074e9b..0fdae17e62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10Factory.java index 271d28d2b8..bd18fed865 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Bar10Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Foo10.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Foo10.java index 5067ddfc29..e78332cdb4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Foo10.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/Foo10.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java index 93d117ce0f..226c2ca8b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTestMapper.java index d697f84798..467a14d800 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTestMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTestMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/TestQualifier.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/TestQualifier.java index 6d5a9bd0cd..704c8c73fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/TestQualifier.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/TestQualifier.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.qualified; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Base.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Base.java index 229f1782ec..7ee28ba3d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Base.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Base.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Child.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Child.java index 4d397dfa96..f5e814d094 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Child.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Child.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Factory.java index e25b9e98b2..631d0d6f09 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Bar9Factory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Base.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Base.java index ceacf3ae79..d2ac9a1c29 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Base.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Base.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Child.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Child.java index cd540eaf07..d848ee6ca1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Child.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/Foo9Child.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java index 4e61915d19..0d39e433c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTestMapper.java index f549e47779..5f37342ada 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTestMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/TargetTypeFactoryTestMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.factories.targettype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java index df6fccd51f..5780e35132 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.fields; diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java b/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java index e9dbfc134f..1592b9e849 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.fields; diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java index 2f819681cf..a872c25feb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.fields; diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/Target.java b/processor/src/test/java/org/mapstruct/ap/test/fields/Target.java index 871799a4de..51ef1f6c0d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.fields; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractIdHoldingTo.java b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractIdHoldingTo.java index 16d3a59177..3c5e582f20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractIdHoldingTo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractIdHoldingTo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java index 6fd9d24b23..5d7f0ba82f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java index 8bf6213de5..3f1ca3a818 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/Source.java b/processor/src/test/java/org/mapstruct/ap/test/generics/Source.java index 398a4e65e7..9d3b8eb50f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/generics/SourceTargetMapper.java index 9c888551fe..02a29b7993 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java b/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java index 0ee83d724b..799dc2509e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperBase.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperBase.java index 13e4bfa795..3c0f065b89 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java index 68a720a785..9d53fa0f94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/SearchResult.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/SearchResult.java index 90c1722cd3..3c1874a5fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/SearchResult.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/SearchResult.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/Vessel.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/Vessel.java index d23cd631c4..0359c5e73b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/Vessel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/Vessel.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselDto.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselDto.java index cd41e588aa..0a42fb07a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselSearchResultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselSearchResultMapper.java index 12af7b12de..e291d389c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselSearchResultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/VesselSearchResultMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.generics.genericsupertype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/Animal.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/Animal.java index a7c43578a6..43cafaf348 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/Animal.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/Animal.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalDto.java index 39ab114b27..74e828f641 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java index e4b2809884..3569be375a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/AnimalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java index eec8c64ded..41097f9ee0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/ErroneousTargetHasNoWriteAccessorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index c81111b9ba..dcc92d6899 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java index 6a7deeb3eb..b474d842c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/Preditor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java index e20d6f9f12..541c40051f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/PreditorDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java index ca0b6c53d7..485404fa17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ExpandedToolbox.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java index a340d57139..90f210bfc3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/FlattenedToolBox.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java index 760ebe31b7..3514224503 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Hammer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java index 30cd86a787..f3dc994a6e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java index b16e89f351..aa8144269c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/ToolBoxMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java index d40d0295e9..8abbdc2a67 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/Wrench.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.expand; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java index ddda507356..1314079470 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/BaseEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java index 6f23727465..fab5c26a82 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java index 19f6143699..585c66f002 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/HammerEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java index d9ef3b377e..d0f829fa4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java index 335cbdcc2c..e6eec3a224 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java index 94f664ce18..707f00182c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java index 7d582b384c..f2126a3136 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java index ffee3a8e6f..488a6766ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java index d5dbb37579..0c18779ea5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/WorkBenchEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.ignore.inherit; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java index f6d42a48ad..0fda48c63d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java index 03a7bbf392..95dbbd3ee8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/List.java b/processor/src/test/java/org/mapstruct/ap/test/imports/List.java index d3c1d6a81f..5f49859d8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/List.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/List.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/Map.java b/processor/src/test/java/org/mapstruct/ap/test/imports/Map.java index db480861e2..f33ce0ac83 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/Map.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/Map.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/Named.java b/processor/src/test/java/org/mapstruct/ap/test/imports/Named.java index c15b7c5710..fd519c7072 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/Named.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/Named.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/ParseException.java b/processor/src/test/java/org/mapstruct/ap/test/imports/ParseException.java index d58aaaddb1..2686ef0833 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/ParseException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/ParseException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SecondSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SecondSourceTargetMapper.java index fbbe98eb55..084322002e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/SecondSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SecondSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java index b894ceee29..8e5e7b0de2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/Actor.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/Actor.java index 0104cd6b61..c84cbe8ab3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/Actor.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/Actor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorDto.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorDto.java index 58159769cb..75d810ce6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorMapper.java index ef639c9712..2a00059c22 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/ActorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java index 9ce1f124f3..13f373278f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/other/ActorMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/other/ActorMapperDecorator.java index 1512c21433..dd23661977 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/other/ActorMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/other/ActorMapperDecorator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.decorator.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java index a8fe60f092..475d98a115 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/from/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.from; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/from/FooWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/from/FooWrapper.java index 82c34ed1ec..4cf849c65a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/from/FooWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/from/FooWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.from; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanFacade.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanFacade.java index c88e3114b3..ef584b7f27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanFacade.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanFacade.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnum.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnum.java index 39cb43ca49..4be9d9ce5a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnum.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnum.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapper.java index 6390948b74..a3fbf0363b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapper.java index 141614e343..8bf5e408e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/SourceWithInnerClass.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/SourceWithInnerClass.java index 108217f71f..fb40268fdc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/SourceWithInnerClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/SourceWithInnerClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/TargetWithInnerClass.java b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/TargetWithInnerClass.java index 86e61fe040..b47bbc80da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/TargetWithInnerClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/innerclasses/TargetWithInnerClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.innerclasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/GenericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/GenericMapper.java index 30e7cd181c..d4e59a72c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/GenericMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/GenericMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/NotImportedDatatype.java b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/NotImportedDatatype.java index ca4f3210cf..ae8ff4f1f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/NotImportedDatatype.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/NotImportedDatatype.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Source.java b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Source.java index 4b437d1d81..3c70fe3b2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Target.java b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Target.java index 8e413dc38e..4503d3b49e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/referenced/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.referenced; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java index d4b0761ce4..069e23a58f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SpaceshipMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SpaceshipMapper.java index 1f39d86332..3191b37558 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SpaceshipMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SpaceshipMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/astronautmapper/AstronautMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/astronautmapper/AstronautMapper.java index 28328c2065..5316280e43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/astronautmapper/AstronautMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/astronautmapper/AstronautMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound.astronautmapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/AstronautDto.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/AstronautDto.java index 528194da54..0cb2731997 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/AstronautDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/AstronautDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/SpaceshipDto.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/SpaceshipDto.java index 372e491ca7..2b21b2b165 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/SpaceshipDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/dto/SpaceshipDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound.dto; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Astronaut.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Astronaut.java index 3fc48833af..ab73285975 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Astronaut.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Astronaut.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound.entity; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Spaceship.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Spaceship.java index f4ec1073f1..d1f95b08ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Spaceship.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/entity/Spaceship.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.sourcewithextendsbound.entity; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java index fd95b22430..2d45dccaab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/to/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.to; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/to/FooWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/to/FooWrapper.java index b685d81977..8fd5b15213 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/to/FooWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/to/FooWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.imports.to; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java index 3935f86279..b13629d06c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceBase.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceBase.java index 5d16ed8ad3..135334b453 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceExt.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceExt.java index 71e661ac5d..61ad6b8083 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceExt.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceExt.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceTargetMapper.java index 2a93bc072c..938b2bd4df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetBase.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetBase.java index fa5966d89c..c0a24f22f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetExt.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetExt.java index f8fb8f824e..4ac8906f28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetExt.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/TargetExt.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java index 9f2c4ab803..ce30a10b2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.attribute; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/ErroneousTargetSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/ErroneousTargetSourceMapper.java index ed5579c20f..89a27d9564 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/ErroneousTargetSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/ErroneousTargetSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.attribute; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Source.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Source.java index 9a167027d1..06a024b326 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.attribute; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/SourceTargetMapper.java index 5ffe93bb66..e9c787ab22 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.attribute; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Target.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Target.java index 68499c1d87..bbe6f7fc7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.attribute; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalFooSource.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalFooSource.java index da772b3b07..2414ba4f75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalFooSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalFooSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalMappingHelper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalMappingHelper.java index 2db8507f78..d12c19a9b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalMappingHelper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/AdditionalMappingHelper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index 544dc35ce4..c2eac938d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ErroneousSourceCompositeTargetCompositeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ErroneousSourceCompositeTargetCompositeMapper.java index 2864c3464d..696b96ef53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ErroneousSourceCompositeTargetCompositeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ErroneousSourceCompositeTargetCompositeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/Reference.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/Reference.java index 81a1d3e731..bd6e3aaa74 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/Reference.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/Reference.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBase.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBase.java index cc7124fd02..d9e446e859 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java index baa2270e4e..e73c708915 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceComposite.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceComposite.java index 2578d3b909..0bce391871 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceComposite.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceComposite.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceCompositeTargetCompositeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceCompositeTargetCompositeMapper.java index e4156a6464..8cddb58e8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceCompositeTargetCompositeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceCompositeTargetCompositeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt.java index b5a423d0b2..1cb41b1092 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt2.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt2.java index 094343fb5e..fcc648543d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceExt2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/StandaloneSourceCompositeTargetCompositeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/StandaloneSourceCompositeTargetCompositeMapper.java index 36855a9a75..db8212e8be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/StandaloneSourceCompositeTargetCompositeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/StandaloneSourceCompositeTargetCompositeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/TargetComposite.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/TargetComposite.java index d14946801d..99f92e3a1e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/TargetComposite.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/TargetComposite.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritance.complex; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/BoundMappable.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/BoundMappable.java index b378a84bf4..486d3469f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/BoundMappable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/BoundMappable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/CarMapper.java index 1c3411dbeb..48d1c46f88 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/FastCarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/FastCarMapper.java index a8917a1014..e16fbbde1c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/FastCarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/FastCarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java index 7530d1f574..874acfc81d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/UnboundMappable.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/UnboundMappable.java index 9719d9ec4a..67d7893320 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/UnboundMappable.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/UnboundMappable.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/CarDto.java index 9df484d42a..31434e7453 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/FastCarDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/FastCarDto.java index d25a34eb95..347624410e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/FastCarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/_target/FastCarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/Car.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/Car.java index 570d1af031..290f034c4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/FastCar.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/FastCar.java index 2c463962de..a10f6009ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/FastCar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/source/FastCar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritedmappingmethod.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java index c9ab6eddc6..56f3a3f649 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedAllConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedConfig.java index 84f29d9abd..f78366ee30 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedDriverConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedDriverConfig.java index 3608617f9b..631252c8f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedDriverConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedDriverConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java index 5be48cc9e0..55004c9fe2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/AutoInheritedReverseConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleDto.java index a246315036..8433efa910 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleEntity.java index 1dac6cc6f5..cf06c80e9d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/BaseVehicleEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarDto.java index a017026e0e..36323025b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarEntity.java index 2715a9db57..bcb191e99d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java index 12eed022d4..b52034bf1d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperAllWithAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java index 041f4e172b..cffe1c6caf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java index 0dec597902..fc084c32f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperReverseWithExplicitInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithAutoInheritance.java index 25c1ef96c5..3ef9cafa05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java index 0cced4dd12..27fdf14171 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarMapperWithExplicitInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverEntity.java index defabd2de9..13b14c5904 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverMapperWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverMapperWithAutoInheritance.java index 2302edfcd7..2e08a46dad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverMapperWithAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/CarWithDriverMapperWithAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/DriverDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/DriverDto.java index e8c7c9bad8..9cb059b38e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/DriverDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/DriverDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Config.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Config.java index 4374688099..46afe99dec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Mapper.java index 4502e57b17..bbe21398a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous1Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous2Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous2Mapper.java index 936d710569..06683fd5fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous2Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous2Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java index ad53c8510e..ac1a7a6a8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java index 34fae8634e..b50369af7f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/Erroneous3Mapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java index 8e7dccfb13..7457bda9f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java index 7a32767a4f..3a5bcfe98e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/ErroneousMapperReverseWithAutoInheritance.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index 2cd07e7d0b..dd064e82a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java index eb2f75c297..8ced44989d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/NotToBeUsedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java index 699ac21370..5937b77654 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java index 7a5a2cc3bf..a66a25b16f 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/BaseEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java index c8e6f71634..f478452a88 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Dto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java index 8a5ab0ca52..0d3213977d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/Car2Entity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java index a0eb1a8a22..027d7529ac 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java index 30e1c42758..ec4e00c18f 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java index 511b3c96c2..63333f2824 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java index 97b7db5b6a..f1d6f1437f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java index 3aded6b9ec..3e765d9b18 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java index e764396f4a..60671f8bf6 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/EntityToDtoMappingConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.inheritfromconfig.multiple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java index d83d38f081..3bfc7d23ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java index 2193fe58cb..001cb9f736 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java index fa813ce841..8ad1836555 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/GenderJsr330ConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java index 3f85a13535..d76b077a3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java index 55dba208dd..5c53a91c0f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java index 2dab52dc57..33b5bbe8dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java index b72ec8078c..67ffaf8306 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/GenderJsr330FieldMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java index ac42d731af..551821df05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.jsr330.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java index 398b890899..6aef16322b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.shared; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java index 862e7156a8..6cb99983a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.shared; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java index 5d923ab921..04c104218e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/Gender.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.shared; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java index 567aac964b..66c514c608 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/GenderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.shared; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java index 8c9b38ecb9..34b06fc788 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring._default; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java index 18085d4072..106b93519e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring._default; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java index e07db6a465..c695214937 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring._default; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java index 33f941afe9..f4b46e35c3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java index d5812bb8ba..9a9ab0119a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java index bc2667deed..42dfa0f9d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/GenderSpringConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java index 1b0dba77e8..41335e1e6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.constructor; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java index d0a685825b..449cc5e435 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java index f712d14788..d44a54c935 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java index 655a640a8a..49bf3ee017 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/GenderSpringFieldMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java index 37ac7ff989..12cb9577dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.injectionstrategy.spring.field; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java index 023baa52e1..e1f89276e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Colour.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java index 98f37575c0..da1198d3ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java index c2e3c5b39e..8dc5c93484 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java index da4b162019..4fa628502e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java index 153c848fc8..c82e1d0142 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java index ccf8ed0299..3e98b0d569 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolderArrayList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java index 29b338aa6d..2d63c3f166 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java index 53617cddf0..fcdf4a5e8a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/TestList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java index 7e2a71fbe6..b0ebbfc60c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/MyCustomException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java index a0deb021bb..3440d6f9e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java index a0a95aecaa..0a7bc6ac16 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/SourceElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java index 0b4b05e0f3..edd6b87d19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java index b66f603267..5f6f74d1b6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java index babaf78a6f..6314c28bf2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java index 4c0f647070..ed2e0877d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/TargetElement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.base; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java index 834abec16b..3b74c7c61a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamContext.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java index a98758a9e7..8a99db72dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java index 78b705c890..9800ef75df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.context; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java index 21c4c997f4..441d3d3a35 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java index 392f84c4ca..3c9a21b672 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java index 336a6572b8..0dd0bf6175 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java index 2966005cf7..03617607dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java index 4de11a1d0e..39c7c17cbc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java index 33134f4c38..64e7424afc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java index 9533f6cc29..7b1185d314 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceFoo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java index c42f4997eb..77d24916f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java index 98c366e427..5168c6b043 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java index 6e9f29ed53..0a4061e712 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.defaultimplementation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java index c74bb9403d..e47447dac4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/EmptyStreamMappingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java index 31189594f5..d739fdb23b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java index 157146ee92..a146f634d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousListToStreamNoElementMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index 7122e730e4..233830b80a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java index 8fd1b67e13..68a3d46b76 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java index a3c1c7e65c..ad025fc30d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToListNoElementMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java index a1607d9c7b..99679de6b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToNonStreamMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java index 73ca458ee6..0a00518423 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToPrimitivePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java index ac5d28a7a0..92da773868 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFound.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java index 56efd7e330..82df9117ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java index d85c7ea7d5..09af31f3ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java index ae5ae0b709..54cc350d36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java index 15e24a728b..9aca654647 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java index da2d603a7e..d6c4c4a7b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java index 50d5c1bbdc..696fab515a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousNonMappableStreamTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java index e36f78376b..ed5c9e494d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ErroneousStreamNonMappableStreamMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java index fb80ee460a..d4465cd126 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index 16f8379429..524bfa956a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java index 47ec385886..5c08dad04a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java index 61692c16e3..881f7f6f34 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java index 13a0757c0f..f277ff0829 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/StreamMapperNullValueMappingReturnDefault.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java index 02bee8ea84..407b34977c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.forged; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java index a4136a8ee9..d3e594da74 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.streamtononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java index f83d2a03cd..5653cf0065 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.streamtononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java index f877b5536e..2e93d1a378 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.streamtononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java index f8bbc79ec2..d1b6e959f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.streamtononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java index a0593d4b68..a2380f0ba5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.streamtononiterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java index 77d368a9e8..5eb7c4a6e1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableExtendsBoundTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java index 24340bf49f..1058269929 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableSuperBoundSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java index fb1008a709..add2dfbfff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java index d32637dcfc..ff684af6fb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ErroneousIterableTypeVarBoundMapperOnMethod.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java index 9235fb726c..8a7f6e2aa2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java index e5c9e6d9e0..d896e65b49 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/ExtendsBoundSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java index e3e42c0984..bb8434fd63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java index 15b28ff2f4..8c55ebc273 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java index 02f08a9e1c..4aea62255b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java index 6704dbfa99..f33027b2e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SourceSuperBoundTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java index 7d30efceab..5ab829f602 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/SuperBoundTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java index b657985bd8..b70ab2eeb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java index 67db736ac8..db9197fcc0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.java8stream.wildcard; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarDto.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarDto.java index 02f74b0591..84354e3eab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarEntity.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarEntity.java index fda7dba5d3..b522563801 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/BarEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CentralConfig.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CentralConfig.java index a23e0ccac4..81dc9a452a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CentralConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CentralConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java index 84decf0c90..c481f9f1c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapper.java index baebee1cb6..756c06b787 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapperConfig.java index 69e31bb336..f8749e93c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/CustomMapperViaMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooDto.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooDto.java index 3313512e74..6d31877923 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooEntity.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooEntity.java index ca38b6d6b2..f8a454f7d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/FooEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Source.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Source.java index b85d54b529..b20d04c9c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapper.java index 681f8a5fe6..e392c6b14a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperErroneous.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperErroneous.java index f10fe115f6..881eea9b1c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperErroneous.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperErroneous.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperWarn.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperWarn.java index e2acefc1f8..0003b703ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperWarn.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/SourceTargetMapperWarn.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Target.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Target.java index ecea6ef40f..ba85076a98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/TargetNoFoo.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/TargetNoFoo.java index c5d79becda..a75d735215 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/TargetNoFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/TargetNoFoo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.mapperconfig; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java index 9fa53911ed..03cdb1aa0f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgb.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java index 55d5b05c63..c5070a3563 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/ColorRgbDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java index 67c713be16..6ea1be3b06 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Garage.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java index 37543eb12a..d94c3ef7b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/GarageDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java index e80adb708f..6341e0002b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java index 13a804a9f1..a6febf074c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index 0b81d07020..60a38740f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java index e40058c6f0..70c1b13c83 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java index 40c5dc8f56..ed8e6ec901 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java index d462f54c16..8a7805237a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java index a6dab48610..11bd389a5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.namesuggestion.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/Break.java b/processor/src/test/java/org/mapstruct/ap/test/naming/Break.java index 003eefbc84..c9335aa4b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/Break.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/Break.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/Source.java b/processor/src/test/java/org/mapstruct/ap/test/naming/Source.java index 241edcee46..0fe5629a1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/naming/SourceTargetMapper.java index 99c32d7bae..d1d702e2ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java index df69782e14..2014e11bf6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/While.java b/processor/src/test/java/org/mapstruct/ap/test/naming/While.java index 02f4a5e029..b91bed5e24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/While.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/While.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java index 763d638f49..eb99c43707 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java index f450a9ebb5..d443d952ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayer.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayer.java index 22ed2953de..fa0af60de9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerDto.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerDto.java index 0b8c6a87b9..bd9c4ecf8c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerMapper.java index d4c97fd80c..bcfd923240 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/GolfPlayerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.naming.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java index 5390171055..25f1d88749 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java index eb3cf1d6eb..5bc377c2e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java index 8c49d6090e..5a346c672d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisableConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index 2452936082..4b2de8f141 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index 4fbf16812e..371566a598 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java index d5617b70f5..5780d83252 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledHouseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java index ff5ceabf3b..cbaf3cbe18 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ErroneousDisabledViaConfigHouseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java index 9f86ca22c6..adfd4a26b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/ExternalRoofType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java index dd4bb6b71a..ada8a2b6e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java index 8007534228..1d92eb7e4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java index 33d0b855e2..655b49a310 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 3ce4fe9804..847fd100ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java index 97eb5b0661..90f5553278 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java index e3c98cbb65..6e94c50e60 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Roof.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java index c999cd10bb..eb5702f0c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java index 91abcb366f..7d2b999a95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java index 3335e367ec..02620920f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/TestData.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java index 6b50b65f31..48eb94d61b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java index a36b08ca09..105c84e74b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java index d461d90d83..584c83a527 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassic.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java index 90e5322cc1..8019a7cb36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmart.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java index adc1a43adf..cee32323ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmart.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java index d97458ce4b..00c84f6e2b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Wheel.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java index c5494fb591..63d0c58a3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/WheelDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java index 7302445e51..1276cbfc39 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java index 7e72786ff7..233c434342 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/MappingException.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java index acb1353453..509ca1e146 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java index 58ce299738..a2b836dc6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/ProjectMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java index c813bca133..2fd0b03d4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/DeveloperDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java index 9cd1386ca6..b8fc7e0e3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/_target/ProjectDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java index 6c453480e0..6f0318e028 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Developer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java index 8b5e0771ef..e302a79c96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/source/Project.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exceptions.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java index 842199c466..111aca1099 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index b367dbf57f..ef89bea847 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java index adeaba1266..3d29ff35ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java index 3691541eda..63deed8b4b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java index ad3461ff58..5c344c714f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java index 51497f05bb..a09ce4da3e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java index 3196bef2e9..a515d52f7b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java index 969334da42..6cdc3e2752 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java index e6d4b1ef22..16910601f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java index 78a27df9ee..bec3c420cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.maps; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java index 89df76bc7a..33ccfbc1cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.maps; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java index e1f2a33c2c..2184589a01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AutoMapMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.maps; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java index f503700f63..2d25012703 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.maps; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java index a74eef2136..57a99fd519 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.maps; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java index 11522e05f4..3c381cfb4a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java index ab806c0999..a730eaa541 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java index 955d7e7043..1d1145b82f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstant.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java index b76abb957f..02011d8799 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpression.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java index d5571afea5..beeb233cd9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocument.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java index a7fffe1ec5..6da67eeef1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java index 04693823c7..f3338f49a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java index 0fddf165b6..7e107908f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/FishTankWithNestedDocumentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java index 8932b88595..19f9cb2a94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java index a9d46ff27d..4e5166214d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/MaterialTypeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java index 6c8153873f..f5523470f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/OrnamentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java index e527e6ec7e..56e9af5e08 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterPlantDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java index 84f7dc229f..c4eb78d6ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java index e8833d35de..16c5811621 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityOrganisationDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java index d5456a3090..56a107775c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityReportDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java index 35c86b243c..8fab7dc5d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/_target/WaterQualityWithDocumentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java index 51250f42a0..3d6032be3c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Fish.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java index 2cfc48bb97..218df4aa57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/FishTank.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java index ae84726637..4b5971b6c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Interior.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java index 8f83fdb16d..f81b226276 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/MaterialType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java index 80cc128f3c..ded7fac05f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/Ornament.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java index 52799646c5..d083634591 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterPlant.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java index 77a0e454e6..4262cf8167 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQuality.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java index 76dbd7cbfc..4ee0fc65f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/source/WaterQualityReport.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java index f40fdae5cb..c2497e9787 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.multiplecollections; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java index f66d9f46e9..190a06d280 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.multiplecollections; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java index e7c9dba4fe..84e7bd6414 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/MultipleListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.multiplecollections; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java index 40678c5f96..682eac481b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java index fd927131af..29ed80a8a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java index 1101df7c82..5382c09a5c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java index 3ede3acbaa..df614fc1ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java index feb4de4eac..0b42cc4123 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/WheelDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.other; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java index 1ab1fe0f46..5f6cbf53d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/RecursionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.recursive; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java index 6914fd0e36..17c647e39f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/recursive/TreeRecursionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.recursive; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseCollectionElementPropertyMapper.java index 142a28ac15..193eba415e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseCollectionElementPropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseCollectionElementPropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepListMapper.java index 096c96c165..e37250890d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapKeyMapper.java index 0bddbb41b9..dc862ec3fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapKeyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapKeyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapValueMapper.java index bdf2c79c9d..0bd19d06ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepMapValueMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepNestingMapper.java index bb461612ae..7ce151a30a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepNestingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseDeepNestingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseValuePropertyMapper.java index e78fa0a0f2..c6b2d529c5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseValuePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/BaseValuePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Car.java index d1ce244bbf..b69ffd46de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CarDto.java index a4b118b849..bcff46314b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Cat.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Cat.java index 17bd0533a8..b880717dea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Cat.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Cat.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CatDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CatDto.java index 2c80ed1a9b..8eb016705f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CatDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/CatDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Color.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Color.java index 75ecd4dc11..0e01f1285f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Color.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Color.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ColorDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ColorDto.java index 64f28c0d24..09f6cb64d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ColorDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ColorDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Computer.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Computer.java index 8985bade34..873e3be348 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Computer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Computer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ComputerDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ComputerDto.java index c48e47c836..30537f1168 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ComputerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ComputerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Dictionary.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Dictionary.java index 1ef1e59456..b13b12e19f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Dictionary.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Dictionary.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/DictionaryDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/DictionaryDto.java index 7874537183..04cbcbb958 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/DictionaryDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/DictionaryDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ExternalRoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ExternalRoofType.java index 61e42d9ca8..01788a1c33 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ExternalRoofType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ExternalRoofType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWord.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWord.java index 436fd65b41..a0fb7b1c81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWord.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWord.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWordDto.java index 0c22988694..165089b619 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWordDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ForeignWordDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/House.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/House.java index 05f58a9b85..d14ac4e616 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/House.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/House.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/HouseDto.java index 76623d419b..cbe011b2c3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/HouseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/HouseDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Info.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Info.java index d78d41b9fa..b7c03e9dff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Info.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Info.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/InfoDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/InfoDto.java index e8e1c0ba02..1d816efde4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/InfoDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/InfoDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Roof.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Roof.java index 8670355d6a..15592d174a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Roof.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Roof.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofDto.java index 8a4ac2837d..cfa2229b15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofType.java index 69c75e7b5b..b7271b6d96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofTypeMapper.java index 97af82875b..28d245efc9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/RoofTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/User.java index a183cbfef2..3f0009a5dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/User.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/UserDto.java index 7c6977fe7c..427b0dd8b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/UserDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Wheel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Wheel.java index d704d5d102..b8f836441b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Wheel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Wheel.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WheelDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WheelDto.java index 60aa9620f0..b26d7951be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WheelDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WheelDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Word.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Word.java index 97e4288da0..d2fb22fd4b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Word.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/Word.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WordDto.java index 1a0c439ff2..e532753ce3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WordDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/WordDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableCollectionElementPropertyMapper.java index 8c29fc2968..493442cae0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableCollectionElementPropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableCollectionElementPropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepListMapper.java index b62360a62d..275d043cfb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapKeyMapper.java index 7c5cf9a00e..c26fbb7df6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapKeyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapKeyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapValueMapper.java index 8d73d33563..4c9c8d9f93 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepMapValueMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepNestingMapper.java index bd9b8f0ed2..00b0401ee5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepNestingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableDeepNestingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableEnumMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableEnumMapper.java index 86a1753e47..1733c9af0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableEnumMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableEnumMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableValuePropertyMapper.java index 57d2fe510d..dd657c8569 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableValuePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableValuePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreCollectionElementPropertyMapper.java index 3d7b19401d..06311e41dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreCollectionElementPropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreCollectionElementPropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepListMapper.java index 746777bc25..df80002650 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapKeyMapper.java index 8dc34f372b..51d2366afc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapKeyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapKeyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapValueMapper.java index 5255246fe6..a8566def9e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepMapValueMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepNestingMapper.java index 4ba701427e..eb4b374cde 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepNestingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreDeepNestingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreValuePropertyMapper.java index 000c0a271a..5b51ac7499 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreValuePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/ignore/UnmappableIgnoreValuePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnCollectionElementPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnCollectionElementPropertyMapper.java index 69ad7272fc..64610a61f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnCollectionElementPropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnCollectionElementPropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepListMapper.java index 429aee3b37..6ca1ce71da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapKeyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapKeyMapper.java index b98f994d6e..a010ac05ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapKeyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapKeyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapValueMapper.java index f594336ef2..53e60c6687 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepMapValueMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepNestingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepNestingMapper.java index cc71221f08..50d0b366b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepNestingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnDeepNestingMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnValuePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnValuePropertyMapper.java index 42a79040a1..f2877b215b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnValuePropertyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableWarnValuePropertyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.unmappable.warn; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 93ba0a6f74..f16732beb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java index 8d06287e3f..05fd3e7c63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsDto.java index 961cbe3a8a..4ad888b8bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsType.java index fab5b13543..534166656f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDetailsType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDto.java index 2ada9268fc..8a4d63fc0f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderType.java index e28417f401..5925685f65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderTypeToOrderDtoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderTypeToOrderDtoMapper.java index cda6faf010..9cd162e9bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderTypeToOrderDtoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/OrderTypeToOrderDtoMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceType.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceType.java index 457819d919..cdf69bd156 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java index aa1f0827bf..87371f004f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/TargetDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/TargetDto.java index 826d136110..636c44967a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/TargetDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/TargetDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedmethodcall; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleMapper.java index e0a2f19dc8..0639399434 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedproperties.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java index de9aa7e9e5..98faca0cca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedproperties.simple; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/_target/TargetObject.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/_target/TargetObject.java index b2936a1bbb..283faf4e71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/_target/TargetObject.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/_target/TargetObject.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedproperties.simple._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceProps.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceProps.java index 05d07160c1..dabfe62616 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceProps.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceProps.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedproperties.simple.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceRoot.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceRoot.java index b570b326e4..5464a81795 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceRoot.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/source/SourceRoot.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedproperties.simple.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java index d541723c27..b9f1b6d369 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Bucket.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java index 06b481eac2..09f47ccebb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java index 0a8044639a..f1f684d794 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NoSuchUser.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java index 255e05e103..821f3e2d05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/Resource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java index 00c720aa75..7eba6bb696 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java index 0b8b706cae..b1dcd8cd04 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java index 0f7724b81c..9c14fd3557 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/User.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.exceptions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/FontDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/FontDto.java index e7f7be1855..3c48b98a1c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/FontDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/FontDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.parameter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterDto.java index 0f5f88f184..3d5bd4e5af 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.parameter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterEntity.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterEntity.java index b17ebc9ea9..139b9e0a3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.parameter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterMapper.java index 273f7208f0..6815299421 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/LetterMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.parameter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java index 0cd9258a89..696d983dc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsource.parameter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntry.java index 5fb685d5c9..e1d1c865bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntry.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryAdder.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryAdder.java index 4b1679886b..7d8f284446 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryAdder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryAdder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryComposedReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryComposedReverse.java index 673c032799..3cfaa6c0d9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryComposedReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryComposedReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java index c4c1c6613f..bbb1608133 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java index c01772f1fa..5ed5ee57d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryGetter.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryGetter.java index fce09b5f6c..6f5b5382ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryGetter.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryReverse.java index 752fcb4b46..b6ce2d786f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryUpdateReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryUpdateReverse.java index 6c977c38e3..836e6a3699 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryUpdateReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryUpdateReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java index bd934dc10c..8f9754777f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithConfigReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithFactoryReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithFactoryReverse.java index 7bf2885867..f1862c53b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithFactoryReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithFactoryReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithIgnoresReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithIgnoresReverse.java index a067490993..c782f3d8b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithIgnoresReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithIgnoresReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithMappingReverse.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithMappingReverse.java index 74f5f2709b..bc8e798634 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithMappingReverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryWithMappingReverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 8edf24f685..ae5d45e40e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java index 2b67d531ac..db27970b51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java index 0e458f10b0..96de5cd1d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/BaseChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/BaseChartEntry.java index 80c5b0f811..25376dd6fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/BaseChartEntry.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/BaseChartEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntry.java index 3015a3df35..c9bf625ef0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntry.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryComposed.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryComposed.java index a17d969b14..45f8a4cf42 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryComposed.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryComposed.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java index b881b77e21..bd13f1fcb1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithBase.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithBase.java index 9e39b89a4c..3c09111865 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithBase.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithMapping.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithMapping.java index 2663411230..4873b3f9a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithMapping.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryWithMapping.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java index 51d6bacd3a..936c45dea5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Artist.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Artist.java index 62a87eedb1..f1d6281e46 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Artist.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Artist.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Chart.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Chart.java index 778721a5b7..4fd5b86048 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Chart.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Chart.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Label.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Label.java index e3bc4bb234..23e467dc36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Label.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Label.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java index 8b5de5e9d4..f3c2856260 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/SourceDtoFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/SourceDtoFactory.java index 47f2874cc7..503f174820 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/SourceDtoFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/SourceDtoFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Studio.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Studio.java index 334a47276b..61adfa53aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Studio.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Studio.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java index 966deb68ca..515679a0da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedtargetproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java index 3d5859ffb7..1121e45828 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedtargetproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java index 012afbff9c..44a73abd4b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedtargetproperties; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/Actor.java b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/Actor.java index 8faebcc39a..ed9cdb6453 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/Actor.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/Actor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nonvoidsetter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorDto.java b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorDto.java index d9bd21560a..e5d99c88f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nonvoidsetter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorMapper.java index de9ba1c9c5..1b77ff849a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/ActorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nonvoidsetter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java index 3e8a92f30e..6745f52c02 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nonvoidsetter; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/CustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/CustomMapper.java index 31f31d8287..0c2bace6bd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/CustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/CustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyBigIntWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyBigIntWrapper.java index 70eb0a6387..be6531ff61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyBigIntWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyBigIntWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java index f1f5ac6acc..d070c64941 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java index 33d5f8fd67..290a34f733 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObject.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObject.java index 93b571bcd9..80c1b56a75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObject.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObject.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObjectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObjectMapper.java index 37778e82e5..8bb4b9ed38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObjectMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullObjectMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Source.java index 02092f1009..a1bcc5a5c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/SourceTargetMapper.java index e2457b35eb..c5f64f611a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Target.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Target.java index 34777eb28d..aa35d20622 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullcheck; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java index c6f8ae5182..f40e4fbb45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java index bdfacf29b3..f8f15a3e77 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java index 32e56d8cba..c3f7d5f2c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralConfig.java index a876ce66a6..5a39f55f51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java index bc825f001e..e316f20866 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/CarDto.java index aa18e39301..dca67b4d5e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/CarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/DriverAndCarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/DriverAndCarDto.java index c2def9d265..10af703211 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/DriverAndCarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/_target/DriverAndCarDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping._target; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Car.java index 70d63a7b01..f0ca97b7a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Car.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Driver.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Driver.java index 93afa27ae6..89322fd4a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Driver.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/source/Driver.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nullvaluemapping.source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java index 316c1511fd..7794b406d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.oneway; diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/Source.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/Source.java index 96651cad7f..9a34fe5d81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.oneway; diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java index 6846bc0a49..efc62ee6ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.oneway; diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/Target.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/Target.java index c3e3ca2a38..9514596f03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.oneway; diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java index 9e0d6ac18b..2f439cfe75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.prism; diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java index be2ccb41dd..388516380c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.prism; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java index 45546ab13e..ad8eebb3fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Bar.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/BaseType.java b/processor/src/test/java/org/mapstruct/ap/test/references/BaseType.java index 9f4a33fdd5..13e691a29f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/BaseType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/BaseType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java index d6cdc1fd44..af9ed0aff8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Foo.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java index d92de459af..10007f9ff6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/FooMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/GenericWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/GenericWrapper.java index 2dd2a902a0..80a90e0910 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/GenericWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/GenericWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java index f3a2182b10..d27146fb18 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java index 4b23d7f067..381a521e16 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java b/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java index 44ca11e0a0..449b5b49af 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java b/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java index 00db06ea7e..08360a5a4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Source.java b/processor/src/test/java/org/mapstruct/ap/test/references/Source.java index 6575f7bdce..d90b89fcb9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java index 08f458b583..8f068ccf92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapperWithPrimitives.java b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapperWithPrimitives.java index c6729fe54d..8f14570b2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapperWithPrimitives.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SourceTargetMapperWithPrimitives.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SourceWithWrappers.java b/processor/src/test/java/org/mapstruct/ap/test/references/SourceWithWrappers.java index 553895f8e9..6c7201184d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SourceWithWrappers.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SourceWithWrappers.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Target.java b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java index 8a6f46c7c8..53feca7fc2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/TargetWithPrimitives.java b/processor/src/test/java/org/mapstruct/ap/test/references/TargetWithPrimitives.java index b33d3614f6..ae1c29f101 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/TargetWithPrimitives.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/TargetWithPrimitives.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java index fad06eca58..6d613b0f91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java index 6da6c4ef5e..3623be1937 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SourceTargetMapper.java index c03687de44..2d7e254f68 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/AnotherSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/AnotherSourceTargetMapper.java index 7b29e8f75a..b5dd71c51e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/AnotherSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/AnotherSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename.a; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/CustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/CustomMapper.java index 188f0c11a9..5afc8254f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/CustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/a/CustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename.a; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/b/CustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/b/CustomMapper.java index d80199c765..fe040d47f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/b/CustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/b/CustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename.b; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Source.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Source.java index 980e92a025..4e42a7085b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename.model; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Target.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Target.java index b8c6d6c815..058d537eb1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/model/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.samename.model; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/Beer.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/Beer.java index 2cc147ff19..71ab1bde2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/Beer.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/Beer.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerDto.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerDto.java index 93898d0efc..80b116199a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapper.java index 1218187300..c106942e2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapperWithNonUsedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapperWithNonUsedMapper.java index f8e650f93e..8d4c2f4345 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapperWithNonUsedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/BeerMapperWithNonUsedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/Category.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/Category.java index 4dd4bd4aa8..503e8b928b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/Category.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/Category.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/CustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/CustomMapper.java index 9c74259a2a..f8b42455f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/CustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/CustomMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java index 83af6346c3..645f3fc2c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/nonused/NonUsedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/nonused/NonUsedMapper.java index 9127b9bd06..f3743a3188 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/nonused/NonUsedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/nonused/NonUsedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.references.statics.nonused; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java index 2d53e43cfb..81f3b53900 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/Source.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/Source.java index 0e7c977c0d..060b08bcd1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java index 186668302e..79d0ed43ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/Target.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/Target.java index a81ef25657..0fd0c48062 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java index 6a5dff8b2d..de2da07ece 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java index bff873d108..25a1939b67 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java index 849586ac02..e12505b42d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java index 0becc63838..970b24a721 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.reverse.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ArrayWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ArrayWrapper.java index 4682117b70..bb75241a3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ArrayWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ArrayWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 17ec7e7d04..e5f17afa9e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource1.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource1.java index 6b65f83471..0fbcc059d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource2.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource2.java index 019fbb2bab..d1a257d599 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource3.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource3.java index 290c5c8049..b1b69f98f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource4.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource4.java index b428a44ef4..02ba71a420 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource5.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource5.java index 57ed04d404..ae9b27932b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource5.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java index 92662c8b7b..5022cdd678 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSource6.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper1.java index 58be8650eb..148aa1328a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper2.java index dc8ff8fa9b..db4f6a61a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper3.java index 7b8cd033be..703631ecf3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper4.java index d155c8644e..4b17a9cbd7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper5.java index 04aa1c0fb3..7afb8708bd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper5.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java index 0fe789dda1..731b743b82 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget1.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget1.java index fdec46ca9c..ac77349ffc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget2.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget2.java index c2273ca816..0dc4219140 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget3.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget3.java index 9c61858333..2d89628a7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget4.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget4.java index f6937474d9..3f38249445 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget5.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget5.java index 7083d2b3d2..2dd8746319 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget5.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java index b2ff03d7d7..3c9aee0676 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousTarget6.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java index 8435c5e0f8..33b93473b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java index 07446a4372..ce99476501 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/SourceTargetMapper.java index c3bacec08a..e583d3f57f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java index 597fda2a7c..85d672ca94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgHolder.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgHolder.java index 9d1602f734..968a5ab697 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgHolder.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgWrapper.java index 7394adba6b..172eb23634 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TwoArgWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeA.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeA.java index f1d6bb14ec..aa6cb2ee48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeA.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeA.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeB.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeB.java index 4cf973c1f7..793164bf77 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeB.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeB.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeC.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeC.java index 29aec2169b..87b7a04ba1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeC.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/TypeC.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/UpperBoundWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/UpperBoundWrapper.java index 4ebf84197b..b244ed0111 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/UpperBoundWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/UpperBoundWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsMBWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsMBWrapper.java index b40f57efeb..028d1621c4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsMBWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsMBWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsWrapper.java index c256b53901..2f24b501e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardExtendsWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardSuperWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardSuperWrapper.java index a889fa96be..2c1d307fb2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardSuperWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/WildCardSuperWrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Wrapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Wrapper.java index 4e50d67e73..30ed2a1781 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Wrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Wrapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.generics; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java index 947d3c6245..02eabb31b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java index b3a8d3599d..3f82688784 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java index d32f1098aa..cd20a48b47 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderShippingDetailsDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderShippingDetailsDto.java index 368406d676..d3a9e3940c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderShippingDetailsDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/OrderShippingDetailsDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java index 831358071f..3dce6c35fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java index 0bced56d4e..32ffd23da8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.test1; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java index 1cb84378bb..35e273e751 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/OrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.test1; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java index 001317b11d..4457166d17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.test2; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/OrderShippingDetailsType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/OrderShippingDetailsType.java index c86fd9a237..4ae8a9b368 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/OrderShippingDetailsType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/OrderShippingDetailsType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.test2; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java index c308169a91..8314422ea8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.underscores; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SubType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SubType.java index 65e17768cb..6e2660ed3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SubType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SubType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.underscores; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SuperType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SuperType.java index 00a76f7865..1bc8cfcc58 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SuperType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/SuperType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.underscores; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreMapper.java index 63fe14a17b..9860363f87 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.underscores; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreType.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreType.java index 648bdea211..243bc0d02d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/UnderscoreType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.jaxb.underscores; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/MyLong.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/MyLong.java index 461d86bc51..56d2416d57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/MyLong.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/MyLong.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java index 2ba445737e..4ab200f9f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java index 68a85ca018..7832a89c9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Source.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Source.java index 458dc8f393..4f5e3974b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapper.java index d56923fc77..707a226764 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperPrimitive.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperPrimitive.java index f5cecc2681..736fca2b5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperPrimitive.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperPrimitive.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperWrapped.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperWrapped.java index 60b1e6e1f6..50551e88fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperWrapped.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/SourceTargetMapperWrapped.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Target.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Target.java index 0ea526a924..73a2b02c74 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/WrappedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/WrappedMapper.java index 089aa8113e..973f37478f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/WrappedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/WrappedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.primitives; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java index d3fa6b3120..895de1ccb3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMovieFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMovieFactoryMapper.java index f7d6b78952..f0e1ac461d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMovieFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/ErroneousMovieFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/FactMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/FactMapper.java index 07a56d9d6e..6c89efe118 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/FactMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/FactMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/KeyWordMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/KeyWordMapper.java index 70b5ecdca1..72b46b02ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/KeyWordMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/KeyWordMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MapperWithoutQualifiedBy.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MapperWithoutQualifiedBy.java index 24f45fa04e..36f8e46cd3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MapperWithoutQualifiedBy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MapperWithoutQualifiedBy.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieFactoryMapper.java index fd5812cfe2..bbd8ae648c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java index 3f4096877e..4777f4c582 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/MovieMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index f6b1a10e78..7e9e9a64f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/CreateGermanRelease.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/CreateGermanRelease.java index d1af40bdde..fdf4bcaff6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/CreateGermanRelease.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/CreateGermanRelease.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/EnglishToGerman.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/EnglishToGerman.java index 29e6ab1f67..39c6da7f5e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/EnglishToGerman.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/EnglishToGerman.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/NonQualifierAnnotated.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/NonQualifierAnnotated.java index d50254d055..969a1a7dd2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/NonQualifierAnnotated.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/NonQualifierAnnotated.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/TitleTranslator.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/TitleTranslator.java index 8b94aec479..68cd77dce4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/TitleTranslator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/annotation/TitleTranslator.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/AbstractEntry.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/AbstractEntry.java index 0fd99fd33c..ace9c5e322 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/AbstractEntry.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/AbstractEntry.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/GermanRelease.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/GermanRelease.java index ba1319c149..a214dc3378 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/GermanRelease.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/GermanRelease.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/OriginalRelease.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/OriginalRelease.java index c24419b914..ce34043ed5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/OriginalRelease.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/OriginalRelease.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/ReleaseFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/ReleaseFactory.java index 6b52a122c3..86b37ebffb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/ReleaseFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/bean/ReleaseFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.bean; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Facts.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Facts.java index ad3356a289..be74df61d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Facts.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Facts.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java index 10d85f9917..a2b1f14e4d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Reverse.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Reverse.java index e3bec7d64a..7d6a8efea6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Reverse.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Reverse.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/SomeOtherMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/SomeOtherMapper.java index 0176db8f2d..b23c48f98c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/SomeOtherMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/SomeOtherMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Titles.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Titles.java index 25ed456f80..62988e0848 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Titles.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/Titles.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/YetAnotherMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/YetAnotherMapper.java index 365b05c402..d73bf13a4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/YetAnotherMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/YetAnotherMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.handwritten; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java index c1b329c908..fc9c48d3a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.hybrid; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/ReleaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/ReleaseMapper.java index ba5983fb75..aeb25718c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/ReleaseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/ReleaseMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.hybrid; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/SourceRelease.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/SourceRelease.java index 0c86791840..e756cdbc85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/SourceRelease.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/SourceRelease.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.hybrid; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/TargetRelease.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/TargetRelease.java index 68a0839e02..91d544c8b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/TargetRelease.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/TargetRelease.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.hybrid; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityDto.java index 62b7c1f523..0930646650 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityEntity.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityEntity.java index 1fa768e7d0..1a879c7e93 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/CityEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java index 96efeac94c..3155d43bee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverDto.java index 894d82da0a..2b19cd1772 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverEntity.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverEntity.java index 6875a1b594..6da8c0d164 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/RiverEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyDto.java index 1b619c7558..6b7430aca4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyEntity.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyEntity.java index 03b082802c..e747586135 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureDto.java index 81c3b2ea96..e7436ce492 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureEntity.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureEntity.java index 797b03a0bf..3a90c06d64 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyFeatureEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java index 60a185f1ec..e1c8190b7f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.iterable; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/ErroneousMapper.java index 6b770f7ff3..b825b77b10 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/ErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/FactMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/FactMapper.java index 45e9ebfed1..e55e5dab81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/FactMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/FactMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/KeyWordMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/KeyWordMapper.java index f8d8afbbf4..4a564159bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/KeyWordMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/KeyWordMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieFactoryMapper.java index 1505bf809f..aae0643d5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieFactoryMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieMapper.java index a5eb2670d2..d6a4995db0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/MovieMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java index 021bbee685..eb9c62e53f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.qualifier.named; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java index 53cf22a652..31f4672fa4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Apple.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleDto.java index f1c3561a63..c787196891 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFactory.java index fffb9d0738..94d8cb10ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamily.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamily.java index dba677a639..4684f26ece 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamily.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamily.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamilyDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamilyDto.java index 5521ffc3e9..8dd0bd2495 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamilyDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/AppleFamilyDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Banana.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Banana.java index 7fbb34ba39..2f85757110 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Banana.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Banana.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/BananaDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/BananaDto.java index 1cf01a5490..e210707d45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/BananaDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/BananaDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ConflictingFruitFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ConflictingFruitFactory.java index 10e1c0a6bf..219eee1095 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ConflictingFruitFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ConflictingFruitFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper.java index d985795346..b40ec3f95b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper2.java index 85cf4167b0..4ecc550ed2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousFruitMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java index 8752c88baf..0e8cb1138d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Fruit.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Fruit.java index 13c08b0b77..94e73744c4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Fruit.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Fruit.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitDto.java index 74c5183278..39b3537b48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamilyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamilyMapper.java index dd0ce9ece8..563950dc5a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamilyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamilyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDelicious.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDelicious.java index 58f405c424..307f3c65ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDelicious.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDelicious.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDeliciousDto.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDeliciousDto.java index 865f764f6e..756f7dad31 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDeliciousDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/GoldenDeliciousDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 23a77954c9..cdfc4024fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java index 093d62194a..2dc5eddbfe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/IsFruit.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java index c8a9d7d676..06541c3b42 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceErroneousMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java index 4230e0aa8c..e1db7775d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitInterfaceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitMapper.java index 60ed62a1a4..be4540222e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeConstructingFruitMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeSelectingFruitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeSelectingFruitMapper.java index 21e695c747..2816b3d92b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeSelectingFruitMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeSelectingFruitMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.selection.resulttype; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java index e0ab3af0b8..db66dc8b6c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java index 806343dbb5..7e06b76bb4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java index f52c5a7e02..60649f2714 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java index 0bf5ed2520..d4f9a25850 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java index ef8d3be998..fab70df8a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java index 215c7e38ef..0cd2cf20c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java index dcb0aaaef2..95d8095f41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java index 1f4e04400b..80a498d078 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severalsources; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java index 90e6aff9ea..b3b4810fe8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java index 0de9c5539f..79b7363f31 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java index e821697f83..9d075ee4cf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java index d734bee59c..1a66774dea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java index 20b5f4eedf..2884d82c7f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java index e06c394269..219f84d57a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.severaltargets; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java index fceb72449b..fd4371c082 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsMapper.java @@ -1,22 +1,8 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/* + * Copyright MapStruct Authors. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ - package org.mapstruct.ap.test.source.constants; import org.mapstruct.Mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java index 494e45b74f..1278033a73 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTarget.java @@ -1,22 +1,8 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/* + * Copyright MapStruct Authors. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ - package org.mapstruct.ap.test.source.constants; /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java index 0611e7fbd4..7742f3c30f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/CountryEnum.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/CountryEnum.java index 7e32a56369..7d9bd79e7b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/CountryEnum.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/CountryEnum.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java index 674fcda0e4..320618710c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousConstantMapper.java @@ -1,22 +1,8 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at +/* + * Copyright MapStruct Authors. * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ - package org.mapstruct.ap.test.source.constants; import org.mapstruct.BeanMapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java index 87d9c07de8..6d1990bd0d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper2.java index b8409e6eca..c8f10bef2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java index 71049fba45..1c9224c998 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java index 533f02def0..3ff8bd1b88 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java index e65c9b58d2..da45ffd1be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper5.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java index 0cd149ee13..9725f1e2a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper6.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source.java index 79d3ecadd0..d1345b1cb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java index 0f0511042d..e9797fdecf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java index c5b84418a2..eb5cc07a2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 1157925f46..b1929f4ea3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java index 5721b17353..db35112c11 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java index a8aef84b4b..6e9a63e6d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/StringListMapper.java index 5193d239cb..91cdbceeeb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/StringListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/StringListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java index 99e0c1954f..98ca13eb0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java index 38b06ad378..e64b3f7e7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java index 1b64cf01cc..c2f92e0b0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionConstantMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java index 0687c99377..97133a3945 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionDefaultValueMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java index 211a0a0f70..36fb06293e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionExpressionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java index dd896b8685..01f9687db9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/ErroneousDefaultExpressionMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 04d1d54500..660c00dd89 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java index a186e52c28..00e1ebb30c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java index 03481c84aa..82784a999a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java index 1679f5db1e..c214b3a975 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.defaultExpressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/BooleanWorkAroundMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/BooleanWorkAroundMapper.java index 743e7d1f5a..9b0852703d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/BooleanWorkAroundMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/BooleanWorkAroundMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index dc66b15afc..51988717c4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source.java index be0d5d33e5..d098376036 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source2.java index 0a2fdfc942..9012089ece 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Source2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceBooleanWorkAround.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceBooleanWorkAround.java index 979ca36fc3..bd3caf9bfa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceBooleanWorkAround.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceBooleanWorkAround.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceList.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceList.java index 69ce4e59fb..bb28dc7173 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetListMapper.java index 09711a91c5..2312d59f6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetListMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java index 18410ccdd1..0e462ab3b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java index 4ae237faaf..5c57b154a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Target.java index ee91e090fc..1b9beeb119 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetBooleanWorkAround.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetBooleanWorkAround.java index 66885d2aa1..46f85ee75b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetBooleanWorkAround.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetBooleanWorkAround.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java index a1602a73cb..f45f284be9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/mapper/TimeAndFormat.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/mapper/TimeAndFormat.java index f3ea3e9005..cab18c87ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/mapper/TimeAndFormat.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/mapper/TimeAndFormat.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.expressions.java.mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java index d6ad432ff5..3ac235de6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourceMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java index 2a76a47ead..f8b6b7306a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java index 8bd43eff17..81037aa21f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/Person.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java index 97faec6525..632858ee13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/PersonDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.ignore; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java index 326e175424..eaa9e85159 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapper.java index 1fea91ef09..5aaa3fd479 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperConfig.java index 319b97fa1b..e85c18c106 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperOveridingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperOveridingConfig.java index c959506c83..95cc6f60f2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperOveridingConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperOveridingConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperWithConfig.java index e55a0bc8d7..b0d79cbadc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperWithConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalMapperWithConfig.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalSource.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalSource.java index 5271e56f6b..8bc17a304f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalTarget.java index 235969241e..1ee5792e20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/RockFestivalTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/Stage.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/Stage.java index 3cad4bc8bd..3a13f0aa1c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/Stage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/Stage.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/GoalKeeper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/GoalKeeper.java index c0ac6e14e6..cb6c228105 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/GoalKeeper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/GoalKeeper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java index 6403830d70..8758ea8e9d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapper.java index fb91882846..93675884ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java index b6746f9761..d2462acf0e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java index 5dc6d671dc..42f9624baf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Source.java index 73f949d4ed..0c95f00b9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SourceTargetMapper.java index b5e5ad88c0..944eda3d8e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Target.java index f42179b4d9..ba98251faf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.presencecheck.spi; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java index e01669d043..c97efe4282 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/NestedSource.java b/processor/src/test/java/org/mapstruct/ap/test/template/NestedSource.java index b7ad02de17..98ae993b66 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/NestedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/NestedSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/Source.java b/processor/src/test/java/org/mapstruct/ap/test/template/Source.java index 171e8f78cc..a5013e5acb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperMultiple.java b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperMultiple.java index 15a573bef0..5153deee7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperMultiple.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperMultiple.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSeveralArgs.java b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSeveralArgs.java index fec83a961a..7740500dfb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSeveralArgs.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSeveralArgs.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSingle.java b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSingle.java index 7f90618f2f..fcd7758667 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSingle.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/SourceTargetMapperSingle.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/Target.java b/processor/src/test/java/org/mapstruct/ap/test/template/Target.java index b840be70c0..3d8c63faf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous1.java b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous1.java index f3ae08af15..3d0008be3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous2.java b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous2.java index 30c5c32139..31f60c0b50 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous3.java b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous3.java index 7025eccc57..4035d46d61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperAmbiguous3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperNonMatchingName.java b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperNonMatchingName.java index 2aecc59268..05db6914da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperNonMatchingName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/erroneous/SourceTargetMapperNonMatchingName.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.template.erroneous; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/Config.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/Config.java index db95dfe0bf..013b0462ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/Config.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedsource; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/ErroneousStrictSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/ErroneousStrictSourceTargetMapper.java index 9f8e590eca..7f928f858b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/ErroneousStrictSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/ErroneousStrictSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedsource; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapper.java index 702908fb60..f5c33042dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedsource; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 37f4c8c5f8..0f7e526dbf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedsource; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UsesConfigFromAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UsesConfigFromAnnotationMapper.java index de530ddfe8..cb552bc4fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UsesConfigFromAnnotationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UsesConfigFromAnnotationMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedsource; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousStrictSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousStrictSourceTargetMapper.java index 8e369f2621..c656547e15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousStrictSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousStrictSourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedtarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Source.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Source.java index 5561d15aca..3c88795398 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Source.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedtarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/SourceTargetMapper.java index 5893ba460b..a6bf940cd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/SourceTargetMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedtarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Target.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Target.java index 842d7b3d95..28f559a5f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/Target.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedtarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index b02a5d8d68..e1714f92f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.unmappedtarget; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossDto.java index d16b198dda..1b2c6bea03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossEntity.java index c5823acf66..31de681149 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/BossEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyDto.java index 0c1f9460d7..8034832d34 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyEntity.java index d1c698742f..f33dd93a2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper.java index 49f67cc623..0fed406f4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper1.java index 2c2b6cae67..cfe68c6632 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/CompanyMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ConstructableDepartmentEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ConstructableDepartmentEntity.java index 4c3ec45c11..25cde7f003 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ConstructableDepartmentEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ConstructableDepartmentEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentDto.java index 513c302df2..1ebc662f94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntity.java index 4fede2cea8..ac2f7275f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntityFactory.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntityFactory.java index d07212fd7c..16b7efa699 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntityFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentEntityFactory.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentInBetween.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentInBetween.java index b18be12d0b..2dc1a6594f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentInBetween.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/DepartmentInBetween.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeDto.java index ce2ee99a72..04acfd423c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeEntity.java index 2c32d3997d..94cae28af4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/EmployeeEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java index 6b357d68ae..126e6801f0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java index 8019506507..81eecea982 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationDto.java index 6d1c13e8de..0b7f8a3284 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationEntity.java index 0e0a1bc5f0..b193b1dea0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java index 0529fab830..d2b71b439e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeEntity.java index 7c6c1f03b4..d464a9fa8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeNrEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeNrEntity.java index 31245240e9..8179d06134 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeNrEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationTypeNrEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutCompanyGetterEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutCompanyGetterEntity.java index ba7bef9da3..728ce3a5a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutCompanyGetterEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutCompanyGetterEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutTypeGetterEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutTypeGetterEntity.java index 3c1a1b54d2..de5ce6fcfd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutTypeGetterEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationWithoutTypeGetterEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryDto.java index 93a98f879b..14f8b48095 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryEntity.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryEntity.java index 4fd8a3fab0..c5d41edcae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/SecretaryEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java index c6215325e3..9a55fe3e7d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableCompanyDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java index 457b17a669..dfb05ffdc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UnmappableDepartmentDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index 46df3377eb..cfa72e190a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapper.java index d8994ea71d..06fe23be0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalHandWrittenMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalHandWrittenMapper.java index 7d6c5c21d6..8e11106958 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalHandWrittenMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalHandWrittenMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalMapper.java index a343ad3148..5579456923 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java index 8b9db6f060..f82fd1c33a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1.java index 11293c9b69..e096520783 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2.java index ecdf9e2f29..7cf0a9ce2a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3.java index 38a4de57a9..6204bd5802 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/DefaultOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/DefaultOrderMapper.java index 4ac99029dc..6228e4b619 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/DefaultOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/DefaultOrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java index 96ecef590f..b881532df1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperDuplicateANY.java b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperDuplicateANY.java index 968364e78e..72989be31a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperDuplicateANY.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperDuplicateANY.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperMappingSameConstantTwice.java b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperMappingSameConstantTwice.java index 504bbdc3db..62c6bc3341 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperMappingSameConstantTwice.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperMappingSameConstantTwice.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java index c4bdd5d7e7..d39d579098 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperUsingUnknownEnumConstants.java b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperUsingUnknownEnumConstants.java index 33108cfb23..49569f1fa3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperUsingUnknownEnumConstants.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/ErroneousOrderMapperUsingUnknownEnumConstants.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/ExternalOrderType.java b/processor/src/test/java/org/mapstruct/ap/test/value/ExternalOrderType.java index b5567936dc..d678e35b92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/ExternalOrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/ExternalOrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/value/OrderDto.java index 22aecea6de..d0eb104a5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/OrderDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/OrderDto.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/OrderEntity.java b/processor/src/test/java/org/mapstruct/ap/test/value/OrderEntity.java index 1b105c8297..62a5f41489 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/OrderEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/OrderEntity.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/OrderMapper.java index a3f148ae65..82996f73d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/OrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/value/OrderType.java index f4ae9aa2ba..a1b6ac4f0f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/OrderType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/OrderType.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java index 26fca87004..29767c1a6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/SpecialOrderMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java index 98c735faf3..3bcea83364 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.versioninfo; diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java index 6eecbc4ea6..67c716468c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.versioninfo; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/IssueKey.java b/processor/src/test/java/org/mapstruct/ap/testutil/IssueKey.java index 2fe1f95e0a..651db60965 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/IssueKey.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/IssueKey.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithClasses.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithClasses.java index 71dc1ac714..4b50f17082 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/WithClasses.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithClasses.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java index b94e6d9376..2397667eb6 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementations.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementations.java index c79c5fa48e..dc76150763 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementations.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementations.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 7d832d3c8a..8e8b4d0f72 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.assertions; @@ -46,7 +33,7 @@ */ public class JavaFileAssert extends FileAssert { - private static final String FIRST_LINE_LICENSE_REGEX = ".*Copyright 2012-\\d{4} Gunnar Morling.*"; + private static final String FIRST_LINE_LICENSE_REGEX = ".*Copyright MapStruct Authors.*"; private static final String GENERATED_DATE_REGEX = "\\s+date = " + "\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{4}\","; private static final String GENERATED_COMMENTS_REGEX = "\\s+comments = \"version: , compiler: .*, environment: " + diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/CompilationResult.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/CompilationResult.java index 5d1ebe2ecd..81db2dbb0b 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/CompilationResult.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/CompilationResult.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java index 3fe2b9ec59..c129302515 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java index ee21d45886..3e3f927c63 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/DisableCheckstyle.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedCompilationOutcome.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedCompilationOutcome.java index e08968d2f1..0efaa6482a 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedCompilationOutcome.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedCompilationOutcome.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java index c0902943a0..e378c891f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOption.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOptions.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOptions.java index 3a376f1a7d..616db429e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOptions.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ProcessorOptions.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.annotation; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java index b4f494ab22..cfe201f5d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.model; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index 96222950e3..b406ae7eae 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.compilation.model; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java index dd6da4da38..02f986d540 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationCache.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationCache.java index a16a0cd136..2c5ce87250 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationCache.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationCache.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index c3681e73c8..46a112da2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java index bc6c22c383..4e11318be7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 95b4a91e4f..215ab1c70c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java index 53182f9780..a0617322ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java index d4d2a5dbe7..a38bc079da 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index ca96cef614..233a460bc4 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java index ec05766e7f..9b9dc868b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java index b71bd5ba05..119ad42674 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java index 3dd8567907..afb7969630 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java index da30f07390..7141b78146 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java index 69e65d327a..dc930f370a 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/* + * Copyright MapStruct Authors. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.testutil.runner; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivateImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivateImpl.java index dbcb1474db..5420ad747b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivateImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivateImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOtherImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOtherImpl.java index 366bbc3c13..9040846b6d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOtherImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOtherImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateImpl.java index a19adfdac2..8eae843b92 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.accessibility.referenced; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java index b2769fa890..066901bc45 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.array; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java index 38faf777bf..00e01f6f17 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._1453; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index 22427cba8b..3e45e345e2 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 5c8692f803..137282b101 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index 21cadd539e..b1b8b0963d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index 37dc9ceab3..085e89d5bb 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.bugs._913; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java index c544ebc684..ed8170c2c6 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/Source2Target2MapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java index de1df9f68c..823fbb1908 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java index 4cf29185e0..18c451533c 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategyDefaultImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java index dd65113eb6..9625f48926 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperStrategySetterPreferredImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.adder; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java index 7b39e52bc4..6310026170 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.collection.defaultimplementation; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java index 48b137da0e..7317a6ba60 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.conversion.string; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java index 00517eb4a8..4954a9163b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperClassicImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java index 12bcc738e7..e29d0bccf7 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoMapperSmartImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java index 28594ec1a3..c503c8a2ba 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java index 14449cd99b..6683e81bbc 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java index ed43e60741..4fae53be79 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperExpressionImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index b2bd752066..570fae4a76 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java index 141bf8bbc2..913b76155d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperWithDocumentImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedbeans.mixed; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java index ca3a27297e..81d3e29748 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedsourceproperties; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index acd8332331..3c30a5ac86 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedtargetproperties; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java index 990bf30c93..38f73d64fc 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.nestedtargetproperties; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java index ba4f7fc6cd..8963b800ae 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.source.constants; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java index 352b0a10e9..121dbea3ec 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java index d2dafaee7c..789d830f6c 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java index 0214fc8aa5..79779841ba 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/OrganizationMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java index 7a28bb7a9a..338d6e9b57 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java index a926291d1d..43a5170e3b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/ExternalMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java index 1073c4acd7..7e53df87c4 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java index 24ee2ab4af..b46593ecda 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper2Impl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java index ef2e589059..11c3bd0df6 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.updatemethods.selection; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java index 270f31168c..3818038de2 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/DefaultOrderMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java index 8fc0647061..dbcd2cb012 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/OrderMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java index 489af7dfc1..8ff732ae2a 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/SpecialOrderMapperImpl.java @@ -1,20 +1,7 @@ -/** - * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) - * and/or other contributors as indicated by the @authors tag. See the - * copyright.txt file in the distribution for a full listing of all - * contributors. +/* + * Copyright MapStruct Authors. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ package org.mapstruct.ap.test.value; From 12bfff8f46c00b22c384f9441d2928b2e588406d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Jul 2018 16:14:58 +0200 Subject: [PATCH 0260/1006] #1411 Fix expected line in Diagnostic after reducing the test files copyright headers --- .../ReferencedAccessibilityTest.java | 6 ++--- .../ap/test/bugs/_1005/Issue1005Test.java | 8 +++--- .../ap/test/bugs/_1029/Issue1029Test.java | 6 ++--- .../ap/test/bugs/_1153/Issue1153Test.java | 6 ++--- .../ap/test/bugs/_1180/Issue1180Test.java | 2 +- .../ap/test/bugs/_1242/Issue1242Test.java | 4 +-- .../ap/test/bugs/_1283/Issue1283Test.java | 4 +-- .../ap/test/bugs/_1353/Issue1353Test.java | 4 +-- .../ap/test/bugs/_631/Issue631Test.java | 4 +-- .../ap/test/bugs/_880/Issue880Test.java | 2 +- .../multiple/MultipleBuilderMapperTest.java | 10 +++---- .../simple/SimpleImmutableBuilderTest.java | 2 +- .../ErroneousCollectionMappingTest.java | 22 ++++++++-------- .../forged/CollectionMappingTest.java | 6 ++--- .../immutabletarget/ImmutableProductTest.java | 2 +- .../collection/wildcard/WildCardTest.java | 8 +++--- .../ContextParameterErroneousTest.java | 2 +- .../erroneous/InvalidDateFormatTest.java | 24 ++++++++--------- .../ap/test/decorator/DecoratorTest.java | 2 +- .../test/defaultvalue/DefaultValueTest.java | 8 +++--- .../ap/test/dependency/OrderingTest.java | 4 +-- .../ap/test/enums/EnumMappingTest.java | 18 ++++++------- .../AmbiguousAnnotatedFactoryTest.java | 4 +-- .../ambiguousfactorymethod/FactoryTest.java | 4 +-- .../AnnotationNotFoundTest.java | 2 +- .../ErroneousMappingsTest.java | 14 +++++----- .../typemismatch/ErroneousMappingsTest.java | 10 +++---- .../ap/test/ignore/IgnorePropertyTest.java | 2 +- .../attribute/AttributeInheritanceTest.java | 2 +- .../complex/ComplexInheritanceTest.java | 2 +- .../InheritFromConfigTest.java | 18 ++++++------- .../erroneous/ErroneousStreamMappingTest.java | 24 ++++++++--------- .../forged/ForgedStreamMappingTest.java | 2 +- .../java8stream/wildcard/WildCardTest.java | 8 +++--- .../ap/test/mapperconfig/ConfigTest.java | 4 +-- .../SuggestMostSimilarNameTest.java | 12 ++++----- ...DisablingNestedSimpleBeansMappingTest.java | 4 +-- .../nestedbeans/DottedErrorMessageTest.java | 26 +++++++++---------- .../exclusions/ErroneousJavaInternalTest.java | 8 +++--- .../custom/ErroneousCustomExclusionTest.java | 2 +- .../NestedSourcePropertiesTest.java | 2 +- .../InheritInverseConfigurationTest.java | 16 ++++++------ .../selection/generics/ConversionTest.java | 14 +++++----- .../selection/qualifier/QualifierTest.java | 6 ++--- .../resulttype/InheritanceSelectionTest.java | 10 +++---- .../SeveralSourceParametersTest.java | 8 +++--- .../test/source/constants/ConstantsTest.java | 14 +++++----- .../source/constants/SourceConstantsTest.java | 18 ++++++------- .../java/JavaDefaultExpressionTest.java | 14 +++++----- .../template/InheritConfigurationTest.java | 16 ++++++------ .../unmappedsource/UnmappedSourceTest.java | 8 +++--- .../unmappedtarget/UnmappedProductTest.java | 12 ++++----- .../test/updatemethods/UpdateMethodsTest.java | 8 +++--- .../ap/test/value/EnumToEnumMappingTest.java | 10 +++---- 54 files changed, 229 insertions(+), 229 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 1516e37693..eb36ad9664 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -37,7 +37,7 @@ public class ReferencedAccessibilityTest { diagnostics = { @Diagnostic(type = SourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 35, + line = 22, messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") @@ -65,7 +65,7 @@ public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() throw diagnostics = { @Diagnostic(type = SourceTargetMapperDefaultOther.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 37, + line = 24, messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") @@ -88,7 +88,7 @@ public void shouldBeAbleToAccessProtectedMethodInBase() throws Exception { } diagnostics = { @Diagnostic(type = AbstractSourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 36, + line = 23, messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index 1e39739e25..b54479a8e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -34,7 +34,7 @@ public class Issue1005Test { diagnostics = { @Diagnostic(type = Issue1005ErroneousAbstractResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 30, + line = 17, messageRegExp = "The result type .*\\.AbstractEntity may not be an abstract class nor interface.") }) public void shouldFailDueToAbstractResultType() throws Exception { @@ -46,7 +46,7 @@ public void shouldFailDueToAbstractResultType() throws Exception { diagnostics = { @Diagnostic(type = Issue1005ErroneousAbstractReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "The return type .*\\.AbstractEntity is an abstract class or interface. Provide a non" + " abstract / non interface result type or a factory method.") }) @@ -59,7 +59,7 @@ public void shouldFailDueToAbstractReturnType() throws Exception { diagnostics = { @Diagnostic(type = Issue1005ErroneousInterfaceResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 30, + line = 17, messageRegExp = "The result type .*\\.HasPrimaryKey may not be an abstract class nor interface.") }) public void shouldFailDueToInterfaceResultType() throws Exception { @@ -71,7 +71,7 @@ public void shouldFailDueToInterfaceResultType() throws Exception { diagnostics = { @Diagnostic(type = Issue1005ErroneousInterfaceReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "The return type .*\\.HasKey is an abstract class or interface. Provide a non " + "abstract / non interface result type or a factory method.") }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index 02deaf3d37..86c55597d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -28,11 +28,11 @@ public class Issue1029Test { @Test @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(kind = Kind.WARNING, line = 39, type = ErroneousIssue1029Mapper.class, + @Diagnostic(kind = Kind.WARNING, line = 26, type = ErroneousIssue1029Mapper.class, messageRegExp = "Unmapped target properties: \"knownProp, lastUpdated, computedMapping\"\\."), - @Diagnostic(kind = Kind.WARNING, line = 50, type = ErroneousIssue1029Mapper.class, + @Diagnostic(kind = Kind.WARNING, line = 37, type = ErroneousIssue1029Mapper.class, messageRegExp = "Unmapped target property: \"lastUpdated\"\\."), - @Diagnostic(kind = Kind.ERROR, line = 55, type = ErroneousIssue1029Mapper.class, + @Diagnostic(kind = Kind.ERROR, line = 42, type = ErroneousIssue1029Mapper.class, messageRegExp = "Unknown property \"unknownProp\" in result type " + "org.mapstruct.ap.test.bugs._1029.ErroneousIssue1029Mapper.Deck\\. Did you mean \"knownProp\"?") }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index 22811d1abf..3ed3e20db1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -26,17 +26,17 @@ public class Issue1153Test { diagnostics = { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Property \"readOnly\" has no write accessor in " + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Property \"nestedTarget.readOnly\" has no write accessor in " + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 36, + line = 23, messageRegExp = "Unknown property \"nestedTarget2.writable2\" in result type " + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\. " + "Did you mean \"nestedTarget2\\.writable\"") diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java index 121353a909..80910e55aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java @@ -32,7 +32,7 @@ public class Issue1180Test { diagnostics = { @Diagnostic(type = SharedConfig.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "No property named \"sourceProperty\\.nonExistant\" exists.*") }) public void shouldCompileButNotGiveNullPointer() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 4edeab667b..94a7e3bbae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -57,7 +57,7 @@ public void factoryMethodWithSourceParamIsChosen() { diagnostics = { @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Ambiguous factory methods found for creating .*TargetB:" + " .*TargetB anotherTargetBCreator\\(.*SourceB source\\)," + " .*TargetB .*TargetFactories\\.createTargetB\\(.*SourceB source," @@ -66,7 +66,7 @@ public void factoryMethodWithSourceParamIsChosen() { + " .*TargetB .*TargetFactories\\.createTargetB\\(\\)."), @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = ".*TargetB does not have an accessible parameterless constructor\\.") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index d70827ae80..9e33e2f079 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -32,7 +32,7 @@ public class Issue1283Test { diagnostics = { @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35L, + line = 22L, messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" ) } @@ -47,7 +47,7 @@ public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { diagnostics = { @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 31L, + line = 18L, messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" ) } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java index d07b0532ff..da89288013 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java @@ -34,13 +34,13 @@ public class Issue1353Test { diagnostics = { @Diagnostic (type = Issue1353Mapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 35, + line = 22, messageRegExp = "The property named \" source.string1\" has whitespaces," + " using trimmed property \"source.string1\" instead." ), @Diagnostic (type = Issue1353Mapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 35, + line = 22, messageRegExp = "The property named \"string2 \" has whitespaces," + " using trimmed property \"string2\" instead." ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java index 00edd36804..5050c76ea0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java @@ -29,11 +29,11 @@ public class Issue631Test { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Can't generate mapping method for a generic type variable target."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Can't generate mapping method for a generic type variable source.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index 9ad1352e20..6ff17597c3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -40,7 +40,7 @@ public class Issue880Test { @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic(kind = Kind.WARNING, - type = UsesConfigFromAnnotationMapper.class, line = 29, + type = UsesConfigFromAnnotationMapper.class, line = 16, messageRegExp = "Unmapped target property: \"core\"\\.")) public void compilationSucceedsAndAppliesCorrectComponentModel() { generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java index 6bf212d299..2d0fe0f78a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -39,7 +39,7 @@ public class MultipleBuilderMapperTest { @Diagnostic( type = ErroneousMoreThanOneBuildMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = "No build method \"build\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + "for \".*\\.multiple\\.build\\.Process\"\\. " + "Found methods: " + @@ -50,7 +50,7 @@ public class MultipleBuilderMapperTest { @Diagnostic( type = ErroneousMoreThanOneBuildMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, + line = 21, messageRegExp = "No build method \"missingBuild\" found " + "in \".*\\.multiple\\.build\\.Process\\.Builder\" " + "for \".*\\.multiple\\.build\\.Process\"\\. " + @@ -71,7 +71,7 @@ public void moreThanOneBuildMethod() { @Diagnostic( type = ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 31, + line = 18, messageRegExp = "No build method \"mapperBuild\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + "for \".*\\.multiple\\.build\\.Process\"\\. " + @@ -118,7 +118,7 @@ public void builderMappingMapperConfigDefined() { @Diagnostic( type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 24, + line = 11, messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + "Found methods: " + "\".*wrongBuilder\\(\\) ?, " + @@ -128,7 +128,7 @@ public void builderMappingMapperConfigDefined() { @Diagnostic( type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 24, + line = 11, messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + "Found methods: " + "\".*wrongBuilder\\(\\) ?, " + diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index f35cee8f9b..a7e579b290 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -56,7 +56,7 @@ public void testSimpleImmutableBuilderHappyPath() { diagnostics = @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousSimpleBuilderMapper.class, - line = 34, + line = 21, messageRegExp = "Unmapped target property: \"name\"\\.")) public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index cf0aa78a39..8a1a138c4d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -34,11 +34,11 @@ public class ErroneousCollectionMappingTest { diagnostics = { @Diagnostic(type = ErroneousCollectionToNonCollectionMapper.class, kind = Kind.ERROR, - line = 28, + line = 15, messageRegExp = "Can't generate mapping method from iterable type to non-iterable type"), @Diagnostic(type = ErroneousCollectionToNonCollectionMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't generate mapping method from non-iterable type to iterable type") } ) @@ -53,7 +53,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection( diagnostics = { @Diagnostic(type = ErroneousCollectionToPrimitivePropertyMapper.class, kind = Kind.ERROR, - line = 26, + line = 13, messageRegExp = "Can't map property \"java.util.List strings\" to \"int strings\". " + "Consider to declare/implement a mapping method: \"int map\\(java.util.List" + " value\\)\"") @@ -70,7 +70,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { diagnostics = { @Diagnostic(type = EmptyItererableMappingMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them.") } @@ -86,7 +86,7 @@ public void shouldFailOnEmptyIterableAnnotation() { diagnostics = { @Diagnostic(type = EmptyMapMappingMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "'nullValueMappingStrategy', 'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', " + "'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, " + "define at least one of them.") @@ -103,7 +103,7 @@ public void shouldFailOnEmptyMapAnnotation() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Can't map Collection element \".*WithProperties withProperties\" to \".*NoProperties" + " noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + ".*WithProperties value\\)") @@ -120,7 +120,7 @@ public void shouldFailOnNoElementMappingFound() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Can't map collection element \".*AttributedString\" to \".*String \". " + "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") @@ -137,7 +137,7 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Can't map Map key \".*WithProperties withProperties\" to \".*NoProperties " + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + ".*WithProperties value\\)") @@ -154,7 +154,7 @@ public void shouldFailOnNoKeyMappingFound() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoKeyMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Can't map map key \".*AttributedString\" to \".*String \". " + "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") } @@ -170,7 +170,7 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Can't map Map value \".*WithProperties withProperties\" to \".*NoProperties " + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + ".*WithProperties value\\)") @@ -187,7 +187,7 @@ public void shouldFailOnNoValueMappingFound() { diagnostics = { @Diagnostic(type = ErroneousCollectionNoValueMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Can't map map value \".*AttributedString\" to \".*String \". " + "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index d157b3f02a..0c4480b3b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -86,7 +86,7 @@ public void shouldForgeNewMapMappingMethod() { diagnostics = { @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't map Collection element \".* nonMappableSet\" to \".* nonMappableSet\". " + "Consider to declare/implement a mapping method: .*."), } @@ -106,12 +106,12 @@ public void shouldGenerateNonMappleMethodForSetMapping() { diagnostics = { @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't map Map key \".* nonMappableMap\\{:key\\}\" to \".* nonMappableMap\\{:key\\}\". " + "Consider to declare/implement a mapping method: .*."), @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't map Map value \".* nonMappableMap\\{:value\\}\" to \".* " + "nonMappableMap\\{:value\\}\". Consider to declare/implement a mapping method: .*."), } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index e83c7a7056..f196a1ed98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -52,7 +52,7 @@ public void shouldHandleImmutableTarget() { diagnostics = { @Diagnostic(type = ErroneousCupboardMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "No write accessor found for property \"content\" in target type.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index 692723bcc6..3e6da19cb8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -86,7 +86,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { diagnostics = { @Diagnostic( type = ErroneousIterableSuperBoundSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't generate mapping method for a wildcard super bound source." ) } ) @@ -100,7 +100,7 @@ public void shouldFailOnSuperBoundSource() { diagnostics = { @Diagnostic( type = ErroneousIterableExtendsBoundTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't generate mapping method for a wildcard extends bound result." ) } ) @@ -114,7 +114,7 @@ public void shouldFailOnExtendsBoundTarget() { diagnostics = { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMethod.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't generate mapping method for a generic type variable target." ) } ) @@ -128,7 +128,7 @@ public void shouldFailOnTypeVarSource() { diagnostics = { @Diagnostic( type = ErroneousIterableTypeVarBoundMapperOnMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't generate mapping method for a generic type variable source." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java index 72cc8270c0..db72521e9a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -39,7 +39,7 @@ public class ContextParameterErroneousTest { @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = @Diagnostic( kind = Kind.ERROR, - line = 33, + line = 20, type = ErroneousNodeMapperWithNonUniqueContextTypes.class, messageRegExp = "The types of @Context parameters must be unique")) public void reportsNonUniqueContextParamType() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java index 5a6bfd2730..669b4cfdad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -32,51 +32,51 @@ public class InvalidDateFormatTest { diagnostics = { @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 39, + line = 26, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 40, + line = 27, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 41, + line = 28, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 42, + line = 29, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 43, + line = 30, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 44, + line = 31, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 45, + line = 32, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 46, + line = 33, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 50, + line = 37, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 53, + line = 40, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 56, + line = 43, messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"") }) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java index df013d5335..08e71f8369 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java @@ -181,7 +181,7 @@ public void shouldApplyCustomMappers() { diagnostics = { @Diagnostic(type = ErroneousPersonMapper.class, kind = Kind.ERROR, - line = 27, + line = 14, messageRegExp = "Specified decorator type is no subtype of the annotated mapper type") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index e02e00b556..9107b4eb2a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -125,12 +125,12 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { diagnostics = { @Diagnostic( type = ErroneousMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 31, + line = 18, messageRegExp = "Constant and default value are both defined in @Mapping," + " either define a defaultValue or a constant." ), @Diagnostic(type = ErroneousMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") } ) @@ -147,12 +147,12 @@ public void errorOnDefaultValueAndConstant() throws ParseException { diagnostics = { @Diagnostic( type = ErroneousMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 31, + line = 18, messageRegExp = "Expression and default value are both defined in @Mapping," + " either define a defaultValue or an expression." ), @Diagnostic(type = ErroneousMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index 9ba8a1fecd..fd091d21a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -62,7 +62,7 @@ public void shouldApplySeveralDependenciesConfiguredForOneProperty() { diagnostics = { @Diagnostic(type = ErroneousAddressMapperWithCyclicDependency.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Cycle\\(s\\) between properties given via dependsOn\\(\\): firstName -> lastName -> " + "middleName -> firstName" ) @@ -79,7 +79,7 @@ public void shouldReportErrorIfDependenciesContainCycle() { diagnostics = { @Diagnostic(type = ErroneousAddressMapperWithUnknownPropertyInDependsOn.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = "\"doesnotexist\" is no property of the method return type" ) } diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java index d7bb8ceddf..552fad686e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java @@ -35,7 +35,7 @@ public class EnumMappingTest { diagnostics = { @Diagnostic(type = OrderMapper.class, kind = Kind.WARNING, - line = 41, + line = 28, messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " + "MapStruct\\. Please use @ValueMapping instead!") } @@ -55,7 +55,7 @@ public void shouldGenerateEnumMappingMethod() { diagnostics = { @Diagnostic(type = OrderMapper.class, kind = Kind.WARNING, - line = 41, + line = 28, messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " + "MapStruct\\. Please use @ValueMapping instead!") } @@ -78,7 +78,7 @@ public void shouldConsiderConstantMappings() { diagnostics = { @Diagnostic(type = OrderMapper.class, kind = Kind.WARNING, - line = 41, + line = 28, messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " + "MapStruct\\. Please use @ValueMapping instead!") } @@ -100,12 +100,12 @@ public void shouldInvokeEnumMappingMethodForPropertyMapping() { @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, kind = Kind.ERROR, - line = 42, + line = 29, messageRegExp = "One enum constant must not be mapped to more than one target constant, but " + "constant EXTRA is mapped to SPECIAL, DEFAULT\\."), @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, kind = Kind.WARNING, - line = 42, + line = 29, messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " + "MapStruct\\. Please use @ValueMapping instead!") } @@ -120,16 +120,16 @@ public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { diagnostics = { @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.WARNING, - line = 40, + line = 27, messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " + "MapStruct\\. Please use @ValueMapping instead!"), @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Constant FOO doesn't exist in enum type org.mapstruct.ap.test.enums.OrderType\\."), @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Constant BAR doesn't exist in enum type org.mapstruct.ap.test.enums." + "ExternalOrderType\\.") } @@ -144,7 +144,7 @@ public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { diagnostics = { @Diagnostic(type = ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class, kind = Kind.ERROR, - line = 34, + line = 21, messageRegExp = "The following constants from the source enum have no corresponding constant in the " + "target enum and must be be mapped via adding additional mappings: EXTRA, STANDARD, NORMAL") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index aa9d800b28..64191955cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -29,7 +29,7 @@ public class AmbiguousAnnotatedFactoryTest { diagnostics = { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Ambiguous factory methods found for creating " + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar: " + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar " @@ -39,7 +39,7 @@ public class AmbiguousAnnotatedFactoryTest { + "ambiguousannotatedfactorymethod.Foo foo\\)."), @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = ".*\\.ambiguousannotatedfactorymethod.Bar does not have an accessible parameterless " + "constructor\\.") diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index bd09018c32..e54602b01a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -33,14 +33,14 @@ public class FactoryTest { diagnostics = { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Ambiguous factory methods found for creating " + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar: " + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar createBar\\(\\), " + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar .*BarFactory.createBar\\(\\)."), @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = ".*\\.ambiguousfactorymethod\\.Bar does not have an accessible parameterless " + "constructor\\.") diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java index 787aad515c..50d5b7c82b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java @@ -32,7 +32,7 @@ public class AnnotationNotFoundTest { diagnostics = { @Diagnostic( type = ErroneousMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "NotFoundAnnotation") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index 4245d65f6d..8031a7880d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -33,26 +33,26 @@ public class ErroneousMappingsTest { diagnostics = { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)\\. " + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)\\. " + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 31, + line = 18, messageRegExp = "Unknown property \"bar\" in result type " + "org.mapstruct.ap.test.erroneous.attributereference.Target. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Target property \"foo\" must not be mapped more than once"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.WARNING, - line = 35, + line = 22, messageRegExp = "Unmapped target property: \"bar\"") } ) @@ -66,7 +66,7 @@ public void shouldFailToGenerateMappings() { diagnostics = { @Diagnostic(type = ErroneousMapper1.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "The type of parameter \"source\" has no property named \"foobar\"") } ) @@ -80,7 +80,7 @@ public void shouldFailToGenerateMappingsErrorOnMandatoryParameterName() { diagnostics = { @Diagnostic(type = ErroneousMapper2.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Target property \"foo\" must not be mapped more than once" ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index 4b04b427e2..4462bdffa9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -32,25 +32,25 @@ public class ErroneousMappingsTest { diagnostics = { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 27, + line = 14, messageRegExp = "Can't map property \"boolean foo\" to \"int foo\". Consider to declare/implement a " + "mapping method: \"int map\\(boolean value\\)\"."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"int foo\" to \"boolean foo\". Consider to declare/implement a " + "mapping method: \"boolean map\\(int value\\)\"."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 31, + line = 18, messageRegExp = "Can't generate mapping method with primitive return type\\."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't generate mapping method with primitive parameter type\\."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Can't generate mapping method that has a parameter annotated with @TargetType\\.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index dcc92d6899..3b2496327d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -81,7 +81,7 @@ public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore( diagnostics = { @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Property \"hasClaws\" has no write accessor in " + "org.mapstruct.ap.test.ignore.PreditorDto\\.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java index ce30a10b2d..839d0987f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java @@ -43,7 +43,7 @@ public void shouldMapAttributeFromSuperType() { diagnostics = @Diagnostic( type = ErroneousTargetSourceMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"java.lang.CharSequence foo\" to \"java.lang.String foo\"" )) public void shouldReportErrorDueToUnmappableAttribute() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index c2eac938d1..6168ecdf24 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -68,7 +68,7 @@ public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { diagnostics = @Diagnostic( kind = Kind.ERROR, type = ErroneousSourceCompositeTargetCompositeMapper.class, - line = 32, + line = 19, messageRegExp = "Ambiguous mapping methods found for mapping property " + "\"org.mapstruct.ap.test.inheritance.complex.SourceExt prop1\" to .*Reference: " diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index dd064e82a2..29c01c0a6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -202,25 +202,25 @@ public void autoInheritedFromMultipleSources() { diagnostics = { @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" + " to select one of them explicitly:" + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.WARNING, - line = 36, + line = 23, messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.ERROR, - line = 42, + line = 29, messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" + " to select one of them explicitly:" + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.WARNING, - line = 42, + line = 29, messageRegExp = "Unmapped target property: \"primaryKey\"\\.") } ) @@ -235,7 +235,7 @@ public void erroneous1MultiplePrototypeMethodsMatch() { diagnostics = { @Diagnostic(type = Erroneous2Mapper.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Cycle detected while evaluating inherited configurations. Inheritance path:" + " .*CarEntity toCarEntity1\\(.*CarDto carDto\\)" + " -> .*CarEntity toCarEntity2\\(.*CarDto carDto\\)" @@ -255,7 +255,7 @@ public void erroneous2InheritanceCycle() { diagnostics = { @Diagnostic(type = ErroneousMapperAutoInheritance.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\.") } ) @@ -269,7 +269,7 @@ public void erroneousWrongReverseConfigInherited() { } diagnostics = { @Diagnostic(type = ErroneousMapperReverseWithAutoInheritance.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = "Unmapped target property: \"id\"\\.") } ) @@ -283,12 +283,12 @@ public void erroneousWrongConfigInherited() { } diagnostics = { @Diagnostic(type = Erroneous3Mapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "More than one configuration prototype method is applicable. " + "Use @InheritInverseConfiguration.*"), @Diagnostic(type = Erroneous3Mapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Unmapped target property: \"id\"\\.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index 233830b80a..e195b037e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -41,11 +41,11 @@ public class ErroneousStreamMappingTest { diagnostics = { @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, - line = 28, + line = 15, messageRegExp = "Can't generate mapping method from iterable type to non-iterable type"), @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't generate mapping method from non-iterable type to iterable type") } ) @@ -59,7 +59,7 @@ public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterabl diagnostics = { @Diagnostic(type = ErroneousStreamToPrimitivePropertyMapper.class, kind = Kind.ERROR, - line = 26, + line = 13, messageRegExp = "Can't map property \"java.util.stream.Stream strings\" to \"int strings\". " + @@ -78,17 +78,17 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { diagnostics = { @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them."), @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, - line = 39, + line = 26, messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them."), @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, - line = 42, + line = 29, messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them.") } @@ -103,7 +103,7 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { diagnostics = { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties " + "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + ".*WithProperties value\\)") @@ -120,7 +120,7 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { diagnostics = { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + "declare/implement a mapping method: \".*String map(.*AttributedString value)") } @@ -135,7 +135,7 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() diagnostics = { @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties noProperties\"." + " Consider to declare/implement a mapping method: \".*NoProperties map\\(.*WithProperties " + @@ -153,7 +153,7 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { diagnostics = { @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + "declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") } @@ -168,7 +168,7 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { diagnostics = { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to .*NoProperties noProperties\"." + " Consider to declare/implement a mapping method: \".*NoProperties map(.*WithProperties value)") @@ -185,7 +185,7 @@ public void shouldFailOnNoElementMappingFoundForStreamToList() { diagnostics = { @Diagnostic(type = ErroneousStreamToListNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Can't map stream element \".*AttributedString\" to .*String \". Consider to " + "declare/implement a mapping method: \".*String map(.*AttributedString value)") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index 524bfa956a..3737584a8b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -69,7 +69,7 @@ public void shouldForgeNewIterableMappingMethod() { diagnostics = { @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't map Stream element \".* nonMappableStream\" to \".* nonMappableStream\". " + "Consider to declare/implement a mapping method: .*."), } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java index db9197fcc0..a24a9d8b5d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java @@ -70,7 +70,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { diagnostics = { @Diagnostic(type = ErroneousIterableSuperBoundSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, + line = 21, messageRegExp = "Can't generate mapping method for a wildcard super bound source.") } ) @@ -84,7 +84,7 @@ public void shouldFailOnSuperBoundSource() { diagnostics = { @Diagnostic(type = ErroneousIterableExtendsBoundTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, + line = 21, messageRegExp = "Can't generate mapping method for a wildcard extends bound result.") } ) @@ -98,7 +98,7 @@ public void shouldFailOnExtendsBoundTarget() { diagnostics = { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMethod.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, + line = 21, messageRegExp = "Can't generate mapping method for a generic type variable target.") } ) @@ -112,7 +112,7 @@ public void shouldFailOnTypeVarSource() { diagnostics = { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, + line = 21, messageRegExp = "Can't generate mapping method for a generic type variable source.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java index c481f9f1c2..cd7e56a93e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java @@ -57,7 +57,7 @@ public void shouldUseCustomMapperViaMapperConfigForFooToDto() { @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = SourceTargetMapperWarn.class, - kind = javax.tools.Diagnostic.Kind.WARNING, line = 37, + kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, messageRegExp = "Unmapped target property: \"noFoo\"") }) public void shouldUseWARNViaMapper() { @@ -68,7 +68,7 @@ public void shouldUseWARNViaMapper() { @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = SourceTargetMapperErroneous.class, - kind = javax.tools.Diagnostic.Kind.ERROR, line = 33, + kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, messageRegExp = "Unmapped target property: \"noFoo\"") }) public void shouldUseERRORViaMapperConfig() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index 60a38740f9..1c4c23bb91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -32,7 +32,7 @@ public class SuggestMostSimilarNameTest { diagnostics = { @Diagnostic(type = PersonAgeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = ".*Did you mean \"age\"\\?") } ) @@ -48,7 +48,7 @@ public void testAgeSuggestion() { diagnostics = { @Diagnostic(type = PersonNameMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = ".*Did you mean \"fullName\"\\?") } ) @@ -64,11 +64,11 @@ public void testNameSuggestion() { diagnostics = { @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Unknown property \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Unknown property \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") } ) @@ -84,11 +84,11 @@ public void testGarageTargetSuggestion() { diagnostics = { @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 32, + line = 19, messageRegExp = "No property named \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "No property named \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index 4b2de8f141..3236429fce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -32,7 +32,7 @@ public class DisablingNestedSimpleBeansMappingTest { diagnostics = { @Diagnostic(type = ErroneousDisabledHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." ) @@ -49,7 +49,7 @@ public void shouldUseDisabledMethodGenerationOnMapper() throws Exception { diagnostics = { @Diagnostic(type = ErroneousDisabledViaConfigHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index 371566a598..1d684ec502 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -99,7 +99,7 @@ public class DottedErrorMessageTest { diagnostics = { @Diagnostic(type = BaseDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"rgb\"\\. Mapping from " + PROPERTY + " \".*Color house\\.roof\\.color\" to \".*ColorDto house\\.roof\\.color\"\\.") } @@ -116,7 +116,7 @@ public void testDeepNestedBeans() { diagnostics = { @Diagnostic(type = BaseDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"left\"\\. Mapping from " + COLLECTION_ELEMENT + " \".*Wheel car\\.wheels\" to \".*WheelDto car\\.wheels\"\\.") } @@ -133,7 +133,7 @@ public void testIterables() { diagnostics = { @Diagnostic(type = BaseDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_KEY + " \".*Word dictionary\\.wordMap\\{:key\\}\" to \".*WordDto dictionary\\.wordMap\\{:key\\}\"\\.") } @@ -150,7 +150,7 @@ public void testMapKeys() { diagnostics = { @Diagnostic(type = BaseDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_VALUE + " \".*ForeignWord dictionary\\.wordMap\\{:value\\}\" " + "to \".*ForeignWordDto dictionary\\.wordMap\\{:value\\}\"\\.") @@ -168,7 +168,7 @@ public void testMapValues() { diagnostics = { @Diagnostic(type = BaseCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + " \".*Info computers\\[\\].info\" to \".*InfoDto computers\\[\\].info\"\\.") } @@ -185,7 +185,7 @@ public void testCollectionElementProperty() { diagnostics = { @Diagnostic(type = BaseValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + " \".*Info catNameMap\\{:value\\}.info\" to \".*InfoDto catNameMap\\{:value\\}.info\"\\.") } @@ -202,7 +202,7 @@ public void testMapValueProperty() { diagnostics = { @Diagnostic(type = UnmappableEnumMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 38, + line = 25, messageRegExp = "The following constants from the property \".*RoofType house\\.roof\\.type\" enum " + "have no corresponding constant in the \".*ExternalRoofType house\\.roof\\.type\" enum and must " + "be be mapped via adding additional mappings: NORMAL\\." @@ -226,33 +226,33 @@ public void testMapEnumProperty() { diagnostics = { @Diagnostic(type = BaseDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"rgb\"\\. Mapping from " + PROPERTY + " \".*Color house\\.roof\\.color\" to \".*ColorDto house\\.roof\\.color\"\\."), @Diagnostic(type = BaseDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"left\"\\. Mapping from " + COLLECTION_ELEMENT + " \".*Wheel car\\.wheels\" to \".*WheelDto car\\.wheels\"\\."), @Diagnostic(type = BaseDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_KEY + " \".*Word dictionary\\.wordMap\\{:key\\}\" to \".*WordDto dictionary\\.wordMap\\{:key\\}\"\\."), @Diagnostic(type = BaseDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_VALUE + " \".*ForeignWord dictionary\\.wordMap\\{:value\\}\" " + "to \".*ForeignWordDto dictionary\\.wordMap\\{:value\\}\"\\."), @Diagnostic(type = BaseCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + " \".*Info computers\\[\\].info\" to \".*InfoDto computers\\[\\].info\"\\."), @Diagnostic(type = BaseValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 23, + line = 10, messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + " \".*Info catNameMap\\{:value\\}.info\" to \".*InfoDto catNameMap\\{:value\\}.info\"\\.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index ef89bea847..cd05ad64be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -30,24 +30,24 @@ public class ErroneousJavaInternalTest { diagnostics = { @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*MyType date\" to \"java\\.util\\.Date date\"\\. Consider to " + "declare/implement a mapping method: \"java\\.util\\.Date map\\(.*MyType value\\)\"\\."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*MyType calendar\" to \"java\\.util\\.GregorianCalendar " + "calendar\"\\. Consider to declare/implement a mapping method: \"java\\.util\\.GregorianCalendar " + "map\\(.*MyType value\\)\"\\."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*List<.*MyType> types\" to \".*List<.*String> types\"\\" + ". Consider to declare/implement a mapping method: \".*List<.*String> map\\(.*List<.*MyType> " + "value\\)\"\\."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*List<.*MyType> nestedMyType\\.deepNestedType\\.types\" to \"" + ".*List<.*String> nestedMyType\\.deepNestedType\\.types\"\\. Consider to declare/implement a " + "mapping method: \".*List<.*String> map\\(.*List<.*MyType> value\\)\"\\.") diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java index a515d52f7b..b34a8d451c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -32,7 +32,7 @@ public class ErroneousCustomExclusionTest { diagnostics = { @Diagnostic(type = ErroneousCustomExclusionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Can't map property \".*NestedSource nested\" to \".*NestedTarget nested\"\\. " + "Consider to declare/implement a mapping method: \".*NestedTarget map\\(.*NestedSource value\\)" + "\"\\.") diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index ae5d45e40e..6fab4df190 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -170,7 +170,7 @@ public void shouldUseGetAsTargetAccessor() { diagnostics = { @Diagnostic( type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 47, + line = 34, messageRegExp = "java.lang.Integer does not have an accessible parameterless constructor." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java index 81f3b53900..fa7b4015cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java @@ -60,12 +60,12 @@ public void shouldInheritInverseConfigurationMultipleCandidates() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.ERROR, - line = 51, + line = 38, messageRegExp = "Several matching inverse methods exist: forward\\(\\), " + "forwardNotToReverse\\(\\). Specify a name explicitly."), @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.WARNING, - line = 56, + line = 43, messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") } ) @@ -79,12 +79,12 @@ public void shouldRaiseAmbiguousReverseMethodError() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.ERROR, - line = 51, + line = 38, messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given " + "name: \"blah\"."), @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.WARNING, - line = 56, + line = 43, messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") } ) @@ -98,12 +98,12 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.ERROR, - line = 52, + line = 39, messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward\\(.+\\), " + ".*forward\\(.+\\)"), @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.WARNING, - line = 57, + line = 44, messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") } ) @@ -117,12 +117,12 @@ public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { diagnostics = { @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.ERROR, - line = 44, + line = 31, messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: " + "\"forward\"."), @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.WARNING, - line = 49, + line = 36, messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index e5f17afa9e..3d4df45bd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -84,7 +84,7 @@ public void shouldApplyGenericTypeMapper() { @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper1.class, - kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, + kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.UpperBoundWrapper" + " fooUpperBoundFailure\" to " + "\"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"") @@ -98,7 +98,7 @@ public void shouldFailOnUpperBound() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper" + " fooWildCardExtendsTypeAFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardExtendsTypeAFailure\"") @@ -112,7 +112,7 @@ public void shouldFailOnWildCardBound() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics." + "WildCardExtendsMBWrapper " + "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " @@ -127,7 +127,7 @@ public void shouldFailOnWildCardMultipleBounds() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + " fooWildCardSuperTypeAFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardSuperTypeAFailure\"") @@ -141,7 +141,7 @@ public void shouldFailOnSuperBounds1() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + " fooWildCardSuperTypeCFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeC fooWildCardSuperTypeCFailure\"") @@ -160,14 +160,14 @@ public void shouldFailOnSuperBounds2() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Can't map property \".*NoProperties " + "foo\\.wrapped\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA " + "foo\\.wrapped\""), @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 29, + line = 16, messageRegExp = ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " + "accessible parameterless constructor\\.") diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 7e9e9a64f7..7454b36f86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -100,7 +100,7 @@ public void shouldMatchClassAndMethod() { diagnostics = { @Diagnostic( type = ErroneousMapper.class, kind = Kind.ERROR, - line = 42, + line = 29, messageRegExp = "Ambiguous mapping methods found for mapping property " + "\"java.lang.String title\" to java.lang.String.*" ) } @@ -173,12 +173,12 @@ public void testFactorySelectionWithQualifier() { diagnostics = { @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in " + "@BeanMapping, define at least one of them."), @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "The return type .*\\.AbstractEntry is an abstract class or interface. Provide a non " + "abstract / non interface result type or a factory method.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index cdfc4024fa..ed9f813489 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -44,13 +44,13 @@ public class InheritanceSelectionTest { diagnostics = { @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = "Ambiguous factory methods found for creating .*Fruit: " + ".*Apple .*ConflictingFruitFactory\\.createApple\\(\\), " + ".*Banana .*ConflictingFruitFactory\\.createBanana\\(\\)\\."), @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = ".*Fruit does not have an accessible parameterless constructor\\.") } ) @@ -65,7 +65,7 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() diagnostics = { @Diagnostic(type = ErroneousResultTypeNoEmptyConstructorMapper.class, kind = Kind.ERROR, - line = 31, + line = 18, messageRegExp = ".*\\.resulttype\\.Banana does not have an accessible parameterless constructor\\.") } ) @@ -111,7 +111,7 @@ public void testResultTypeBasedConstructionOfResultForInterface() { diagnostics = { @Diagnostic(type = ResultTypeConstructingFruitInterfaceErroneousMapper.class, kind = Kind.ERROR, - line = 36, + line = 23, messageRegExp = "The return type .*\\.IsFruit is an abstract class or interface. Provide a non " + "abstract / non interface result type or a factory method." ) @@ -128,7 +128,7 @@ public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { diagnostics = { @Diagnostic(type = ErroneousFruitMapper2.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = ".*\\.Banana not assignable to: .*\\.Apple.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java index 95d8095f41..4ac88be38f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java @@ -142,15 +142,15 @@ public void shouldMapSeveralSourceAttributesAndParameters() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Several possible source properties for target property \"street\"."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Several possible source properties for target property \"zipCode\"."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Several possible source properties for target property \"description\".") }) public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { @@ -169,7 +169,7 @@ public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { @Diagnostic( type = ErroneousSourceTargetMapper2.class, kind = Kind.ERROR, - line = 28, + line = 15, messageRegExp = "Method has no source parameter named \"houseNo\"\\." + " Method source parameters are: \"address, person\"\\." ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java index 7742f3c30f..7182b62740 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java @@ -69,31 +69,31 @@ public void testNumericConstants() { diagnostics = { @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 39, + line = 25, messageRegExp = "^.*only 'true' or 'false' are supported\\.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 40, + line = 26, messageRegExp = "^.*invalid character literal\\.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 41, + line = 27, messageRegExp = "^.*Value out of range. Value:\"200\" Radix:10\\.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 42, + line = 28, messageRegExp = "^.*integer number too large.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 43, + line = 29, messageRegExp = "^.*L/l mandatory for long types.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 44, + line = 30, messageRegExp = "^.*improperly placed underscores.$"), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 45, + line = 31, messageRegExp = "^.*floating point number too small.$") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index b1929f4ea3..b03b42b3e5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -90,12 +90,12 @@ public void shouldMapTargetToSourceWithoutWhining() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper1.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Source and constant are both defined in @Mapping, either define a source or a " + "constant"), @Diagnostic(type = ErroneousMapper1.class, kind = Kind.WARNING, - line = 43, + line = 30, messageRegExp = "Unmapped target property: \"integerConstant\"") } ) @@ -116,13 +116,13 @@ public void errorOnSourceAndConstant() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper3.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Expression and constant are both defined in @Mapping, either define an expression or a " + "constant"), @Diagnostic(type = ErroneousMapper3.class, kind = Kind.WARNING, - line = 43, + line = 30, messageRegExp = "Unmapped target property: \"integerConstant\"") } ) @@ -143,12 +143,12 @@ public void errorOnConstantAndExpression() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper4.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Source and expression are both defined in @Mapping, either define a source or an " + "expression"), @Diagnostic(type = ErroneousMapper4.class, kind = Kind.WARNING, - line = 43, + line = 30, messageRegExp = "Unmapped target property: \"integerConstant\"") } ) @@ -191,12 +191,12 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc diagnostics = { @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, - line = 43, + line = 30, messageRegExp = "^Constant \"DENMARK\" doesn't exist in enum type org.mapstruct.ap.test.source." + "constants.CountryEnum for property \"country\".$"), @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, - line = 41, + line = 28, messageRegExp = "^Can't map \"java.lang.String \"DENMARK\"\" to \"org.mapstruct.ap.test.source." + "constants.CountryEnum country\".$") } @@ -218,7 +218,7 @@ public void errorOnNonExistingEnumConstant() throws ParseException { diagnostics = { @Diagnostic(type = ErroneousMapper6.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "^.*Can't map \"java.lang.String \"3001\"\" to \"java.lang.Long " + "longWrapperConstant\".*$") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 660c00dd89..09343d597b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -55,13 +55,13 @@ public void testJavaDefaultExpressionWithNoValues() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Expression and default expression are both defined in @Mapping," + " either define an expression or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 39, + line = 26, messageRegExp = "Unmapped target property: \"sourceId\"" ) } @@ -76,13 +76,13 @@ public void testJavaDefaultExpressionExpression() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Constant and default expression are both defined in @Mapping," + " either define a constant or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 38, + line = 25, messageRegExp = "Unmapped target property: \"sourceId\"" ) } @@ -97,13 +97,13 @@ public void testJavaDefaultExpressionConstant() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Default value and default expression are both defined in @Mapping," + " either define a default value or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 38, + line = 25, messageRegExp = "Unmapped target property: \"sourceId\"" ) } @@ -118,7 +118,7 @@ public void testJavaDefaultExpressionDefaultValue() { diagnostics = { @Diagnostic(type = ErroneousDefaultExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Value for default expression must be given in the form \"java\\(\\)\"" ) } diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java index c97efe4282..1b5c9c9cc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java @@ -121,12 +121,12 @@ public void shouldInheritConfigurationSeveralArgs() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.ERROR, - line = 56, + line = 43, messageRegExp = "Several matching methods exist: forwardCreate\\(\\), " + "forwardCreate1\\(\\). Specify a name explicitly."), @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.WARNING, - line = 57, + line = 44, messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + "expressionProp, nestedResultProp\"") } @@ -141,12 +141,12 @@ public void shouldRaiseAmbiguousReverseMethodError() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.ERROR, - line = 56, + line = 43, messageRegExp = "None of the candidates forwardCreate\\(\\), forwardCreate1\\(\\) matches given " + "name: \"blah\"."), @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.WARNING, - line = 57, + line = 44, messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + "expressionProp, nestedResultProp\"") } @@ -161,12 +161,12 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { diagnostics = { @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.ERROR, - line = 56, + line = 43, messageRegExp = "Given name \"forwardCreate\" matches several candidate methods: " + ".*forwardCreate.*, .*forwardCreate.*"), @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.WARNING, - line = 57, + line = 44, messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + "expressionProp, nestedResultProp\"") } ) @@ -180,12 +180,12 @@ public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { diagnostics = { @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.ERROR, - line = 47, + line = 34, messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: " + "\"forwardCreate\"."), @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.WARNING, - line = 48, + line = 35, messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + "expressionProp, nestedResultProp\"") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 0f7e526dbf..999064237d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -34,11 +34,11 @@ public class UnmappedSourceTest { diagnostics = { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, - line = 33, + line = 20, messageRegExp = "Unmapped source property: \"qux\""), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, - line = 35, + line = 22, messageRegExp = "Unmapped source property: \"bar\"") } ) @@ -60,11 +60,11 @@ public void shouldLeaveUnmappedSourcePropertyUnset() { diagnostics = { @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, - line = 33, + line = 20, messageRegExp = "Unmapped source property: \"qux\""), @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, - line = 35, + line = 22, messageRegExp = "Unmapped source property: \"bar\"") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index e1714f92f4..b027202d96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -35,11 +35,11 @@ public class UnmappedProductTest { diagnostics = { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, - line = 29, + line = 16, messageRegExp = "Unmapped target property: \"bar\""), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, - line = 31, + line = 18, messageRegExp = "Unmapped target property: \"qux\"") } ) @@ -61,11 +61,11 @@ public void shouldLeaveUnmappedTargetPropertyUnset() { diagnostics = { @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, - line = 30, + line = 17, messageRegExp = "Unmapped target property: \"bar\""), @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, - line = 32, + line = 19, messageRegExp = "Unmapped target property: \"qux\"") } ) @@ -80,11 +80,11 @@ public void shouldRaiseErrorDueToUnsetTargetProperty() { diagnostics = { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.ERROR, - line = 29, + line = 16, messageRegExp = "Unmapped target property: \"bar\""), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.ERROR, - line = 31, + line = 18, messageRegExp = "Unmapped target property: \"qux\"") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index cfa72e190a..91db277198 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -154,7 +154,7 @@ public void testPreferUpdateMethodEncapsulatingCreateMethod() { diagnostics = { @Diagnostic(type = ErroneousOrganizationMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 37, + line = 24, messageRegExp = "No read accessor found for property \"company\" in target type.") } ) @@ -170,11 +170,11 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } diagnostics = { @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 37, + line = 24, messageRegExp = "No read accessor found for property \"type\" in target type."), @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 48, + line = 35, messageRegExp = ".*\\.updatemethods\\.DepartmentEntity does not have an accessible parameterless " + "constructor\\.") @@ -194,7 +194,7 @@ public void testShouldFailOnConstantMappingNoPropertyGetter() { } diagnostics = { @Diagnostic(type = CompanyMapper1.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 36, + line = 23, messageRegExp = "Unmapped target property: \"employees\"\\. Mapping from property \"" + ".*UnmappableDepartmentDto department\" to \".*DepartmentEntity department.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java index b881532df1..2403977d09 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java @@ -214,7 +214,7 @@ public void shouldMapAnyRemainingToNullCorrectly() throws Exception { diagnostics = { @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Source value mapping: \"EXTRA\" cannot be mapped more than once\\.") } ) @@ -228,11 +228,11 @@ public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { diagnostics = { @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, - line = 37, + line = 24, messageRegExp = "Constant FOO doesn't exist in enum type org.mapstruct.ap.test.value.OrderType\\."), @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, - line = 38, + line = 25, messageRegExp = "Constant BAR doesn't exist in enum type org.mapstruct.ap.test.value." + "ExternalOrderType\\.") } @@ -247,7 +247,7 @@ public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { diagnostics = { @Diagnostic(type = ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class, kind = Kind.ERROR, - line = 34, + line = 21, messageRegExp = "The following constants from the source enum have no corresponding constant in the " + "target enum and must be be mapped via adding additional mappings: EXTRA, STANDARD, NORMAL") } @@ -262,7 +262,7 @@ public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeI diagnostics = { @Diagnostic(type = ErroneousOrderMapperDuplicateANY.class, kind = Kind.ERROR, - line = 39, + line = 26, messageRegExp = "Source = \"\" or \"\" can only be used once\\." ) } ) From c189aa7bb53572db30391cd92cab82a4ef0590ad Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Jul 2018 19:51:44 +0200 Subject: [PATCH 0261/1006] [maven-release-plugin] prepare release 1.3.0.Beta1 --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 462fe5c4db..e31593c7aa 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index 0583071238..801bdc9a26 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 456766be07..c467be0b2e 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index f6b037f6e4..cede7136e4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b586a4ba2f..4c23961273 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 3ce539793e..7b07d429fa 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 820ba733f8..981a9cf786 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 126e09bb15..8475328cb0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 pom MapStruct Parent @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Beta1 diff --git a/pom.xml b/pom.xml index e24bfdd30a..d937cadd3f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 parent/pom.xml @@ -55,7 +55,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Beta1 diff --git a/processor/pom.xml b/processor/pom.xml index f71ede86b5..4ad6a19d1b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta1 ../parent/pom.xml From e29c25e5cb26318b42e99bcb30676bf875d06b3f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Jul 2018 19:51:45 +0200 Subject: [PATCH 0262/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-common/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index e31593c7aa..462fe5c4db 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core-common/pom.xml b/core-common/pom.xml index 801bdc9a26..0583071238 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c467be0b2e..456766be07 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index cede7136e4..f6b037f6e4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4c23961273..b586a4ba2f 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 7b07d429fa..3ce539793e 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 981a9cf786..820ba733f8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8475328cb0..126e09bb15 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT pom MapStruct Parent @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Beta1 + HEAD diff --git a/pom.xml b/pom.xml index d937cadd3f..e24bfdd30a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT parent/pom.xml @@ -55,7 +55,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Beta1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 4ad6a19d1b..f71ede86b5 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta1 + 1.3.0-SNAPSHOT ../parent/pom.xml From 0fa964038cda4806ca0a83657ef640fc21b4a9c5 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sun, 15 Jul 2018 20:53:13 +0200 Subject: [PATCH 0263/1006] #1499 Add Protobuf builder integration test * Don't run the ProtobufBuilderTest with the processor_plugin_java8 and eclipse_jdt_java_8 (processor plugin runs before the proto java classes are created and the eclipse plugin has some bug) * Include *.proto for license checks --- .../itest/tests/ProtobufBuilderTest.java | 28 ++++++++ .../resources/protobufBuilderTest/pom.xml | 69 +++++++++++++++++++ .../mapstruct/itest/protobuf/AddressDto.java | 27 ++++++++ .../mapstruct/itest/protobuf/PersonDto.java | 45 ++++++++++++ .../itest/protobuf/PersonMapper.java | 19 +++++ .../src/main/proto/Person.proto | 21 ++++++ .../itest/protobuf/ProtobufMapperTest.java | 44 ++++++++++++ parent/pom.xml | 8 ++- 8 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/pom.xml create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/AddressDto.java create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonDto.java create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonMapper.java create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/src/main/proto/Person.proto create mode 100644 integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java new file mode 100644 index 0000000000..7e52bed06a --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.tests; + +import org.junit.runner.RunWith; +import org.mapstruct.itest.testutil.runner.ProcessorSuite; +import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; + +/** + * ECLIPSE_JDT_JAVA_8 is not working with Protobuf. Use all other available processor types. + * + * @author Christian Bandowski + */ +@RunWith(ProcessorSuiteRunner.class) +@ProcessorSuite(baseDir = "protobufBuilderTest", + processorTypes = { + ProcessorSuite.ProcessorType.ORACLE_JAVA_6, + ProcessorSuite.ProcessorType.ORACLE_JAVA_7, + ProcessorSuite.ProcessorType.ORACLE_JAVA_8, + ProcessorSuite.ProcessorType.ORACLE_JAVA_9, + ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_6, + ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_7 + }) +public class ProtobufBuilderTest { +} diff --git a/integrationtest/src/test/resources/protobufBuilderTest/pom.xml b/integrationtest/src/test/resources/protobufBuilderTest/pom.xml new file mode 100644 index 0000000000..ecbbf1d6d8 --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + protobufIntegrationTest + jar + + + 1.6.0 + 0.5.1 + + + + + com.google.protobuf + protobuf-java + provided + + + + + + + kr.motd.maven + os-maven-plugin + ${os.mavenplugin.version} + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + ${protobuf.mavenplugin.version} + + + generate-sources + + compile + compile-custom + + + com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + + grpc-java + io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} + + + + + + + + diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/AddressDto.java b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/AddressDto.java new file mode 100644 index 0000000000..0956722de8 --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/AddressDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.protobuf; + +public class AddressDto { + + private String addressLine; + + public AddressDto() { + + } + + public AddressDto(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } + + public void setAddressLine(String addressLine) { + this.addressLine = addressLine; + } +} diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonDto.java b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonDto.java new file mode 100644 index 0000000000..61ee37b391 --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonDto.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.protobuf; + +public class PersonDto { + private String name; + private int age; + private AddressDto address; + + public PersonDto() { + } + + public PersonDto(String name, int age, AddressDto address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public AddressDto getAddress() { + return address; + } + + public void setAddress(AddressDto address) { + this.address = address; + } +} diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonMapper.java b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonMapper.java new file mode 100644 index 0000000000..b5cdc8575a --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/main/java/org/mapstruct/itest/protobuf/PersonMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.protobuf; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) // protobuf has a lot of strange additional setters/getters +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + PersonProtos.Person fromDto(PersonDto personDto); + PersonDto toDto(PersonProtos.Person personDto); +} diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/main/proto/Person.proto b/integrationtest/src/test/resources/protobufBuilderTest/src/main/proto/Person.proto new file mode 100644 index 0000000000..209c2220b8 --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/main/proto/Person.proto @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +syntax = "proto3"; + +package itest.protobuf; + +option java_package = "org.mapstruct.itest.protobuf"; +option java_outer_classname = "PersonProtos"; + +message Person { + string name = 1; + int32 age = 2; + Address address = 3; + + message Address { + string addressLine = 1; + } +} \ No newline at end of file diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java b/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java new file mode 100644 index 0000000000..ae3740848f --- /dev/null +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.protobuf; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Protobuf Builder Mapper implementations + * + * @author Christian Bandowski + */ +public class ProtobufMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( PersonProtos.Person.newBuilder() + .setAge( 33 ) + .setName( "Bob" ) + .setAddress( PersonProtos.Person.Address.newBuilder() + .setAddressLine( "Wild Drive" ) + .build() ) + .build() ); + + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + PersonProtos.Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 126e09bb15..332ab2ff23 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -196,6 +196,11 @@ auto-value 1.5 + + com.google.protobuf + protobuf-java + 3.6.0 + org.inferred freebuilder @@ -576,7 +581,7 @@

      ${basedir}/../etc/license.txt
      true - .idea/** + **/.idea/** **/build-config/checkstyle.xml **/build-config/import-control.xml copyright.txt @@ -601,6 +606,7 @@ SLASHSTAR_STYLE + SLASHSTAR_STYLE From 6b89539ff6ed5019fc6a15283ec8bcf718807c96 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Tue, 24 Jul 2018 18:19:42 +0200 Subject: [PATCH 0264/1006] #1541 Fix NPE when using varargs in mapping methods --- .../ap/internal/model/BeanMappingMethod.java | 9 +- .../ap/internal/model/common/Parameter.java | 23 ++- .../ap/internal/model/common/TypeFactory.java | 9 +- .../processor/MethodRetrievalProcessor.java | 7 +- .../ap/internal/model/common/Parameter.ftl | 2 +- .../ap/internal/model/common/Type.ftl | 2 +- .../DateFormatValidatorFactoryTest.java | 2 +- .../common/DefaultConversionContextTest.java | 2 +- .../ap/test/bugs/_1541/Issue1541Mapper.java | 85 ++++++++++ .../ap/test/bugs/_1541/Issue1541Test.java | 148 ++++++++++++++++++ .../mapstruct/ap/test/bugs/_1541/Target.java | 74 +++++++++ 11 files changed, 342 insertions(+), 21 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index ab820eceb7..05f4e9b1cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -20,7 +18,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; - import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; @@ -53,6 +50,8 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally * configured by one or more {@link PropertyMapping}s. @@ -116,7 +115,7 @@ private Builder setupMethodWithMapping(Method sourceMethod) { for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); - if ( sourceParameter.getType().isPrimitive() ) { + if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() ) { continue; } Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); @@ -558,7 +557,7 @@ private void applyPropertyNameBasedMapping() { Type sourceType = sourceParameter.getType(); - if ( sourceType.isPrimitive() ) { + if ( sourceType.isPrimitive() || sourceType.isArrayType() ) { continue; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index cfc9a9f50f..ed65185f60 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; - import javax.lang.model.element.VariableElement; import org.mapstruct.ap.internal.prism.ContextPrism; @@ -30,17 +29,21 @@ public class Parameter extends ModelElement { private final boolean targetType; private final boolean mappingContext; - private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext) { + private final boolean varArgs; + + private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext, + boolean varArgs) { this.name = name; this.originalName = name; this.type = type; this.mappingTarget = mappingTarget; this.targetType = targetType; this.mappingContext = mappingContext; + this.varArgs = varArgs; } public Parameter(String name, Type type) { - this( name, type, false, false, false ); + this( name, type, false, false, false, false ); } public String getName() { @@ -80,6 +83,10 @@ public boolean isMappingContext() { return mappingContext; } + public boolean isVarArgs() { + return varArgs; + } + @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; @@ -105,13 +112,15 @@ public boolean equals(Object o) { } - public static Parameter forElementAndType(VariableElement element, Type parameterType) { + public static Parameter forElementAndType(VariableElement element, Type parameterType, boolean isVarArgs) { return new Parameter( element.getSimpleName().toString(), parameterType, MappingTargetPrism.getInstanceOn( element ) != null, TargetTypePrism.getInstanceOn( element ) != null, - ContextPrism.getInstanceOn( element ) != null ); + ContextPrism.getInstanceOn( element ) != null, + isVarArgs + ); } public static Parameter forForgedMappingTarget(Type parameterType) { @@ -120,7 +129,9 @@ public static Parameter forForgedMappingTarget(Type parameterType) { parameterType, true, false, - false); + false, + false + ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 9b795e136c..e2733cb6f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentSkipListMap; - import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -377,7 +376,13 @@ public List getParameters(ExecutableType methodType, ExecutableElemen VariableElement parameter = varIt.next(); TypeMirror parameterType = typesIt.next(); - result.add( Parameter.forElementAndType( parameter, getType( parameterType ) ) ); + Type type = getType( parameterType ); + + // if the method has varargs and this is the last parameter + // we know that this parameter should be used as varargs + boolean isVarArgs = !varIt.hasNext() && method.isVarArgs(); + + result.add( Parameter.forElementAndType( parameter, type, isVarArgs ) ); } return result; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index d2694907fa..f74f8880f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.processor; -import static org.mapstruct.ap.internal.util.Executables.getAllEnclosedExecutableElements; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -14,7 +12,6 @@ import java.util.List; import java.util.Map; import java.util.Set; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; @@ -49,6 +46,8 @@ import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; +import static org.mapstruct.ap.internal.util.Executables.getAllEnclosedExecutableElements; + /** * A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s * representing all the mapping methods of the given bean mapper type as well as @@ -267,7 +266,7 @@ private ParameterProvidedMethods retrieveContextProvidedMethods( ParameterProvidedMethods.Builder builder = ParameterProvidedMethods.builder(); for ( Parameter contextParam : contextParameters ) { - if ( contextParam.getType().isPrimitive() ) { + if ( contextParam.getType().isPrimitive() || contextParam.getType().isArrayType() ) { continue; } List contextParamMethods = retrieveMethods( diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl index 9174624297..821712188c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl @@ -5,4 +5,4 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> -<@includeModel object=type/> ${name} \ No newline at end of file +<@includeModel object=type asVarArgs=varArgs/> ${name} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 426dd6e16d..1cb4fa6290 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -11,6 +11,6 @@ <#elseif wildCardSuperBound> ? super <@includeModel object=typeBound /> <#else> - ${referenceName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > + <#if ext.asVarArgs!false>${referenceName?remove_ending("[]")}...<#else>${referenceName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 6e1463dea7..68fee3bc85 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -172,7 +172,7 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, - false ); + false); } } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index cdbef06bdc..40f7357e94 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -123,7 +123,7 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, - false ); + false); } private static class StatefulMessagerMock implements FormattingMessager { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Mapper.java new file mode 100644 index 0000000000..caafee8d3f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Mapper.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1541; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeanMapping; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.Named; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) // IGNORE to keep this test-mapper small and clean +public abstract class Issue1541Mapper { + + public static final Issue1541Mapper INSTANCE = Mappers.getMapper( Issue1541Mapper.class ); + + public abstract Target mapWithVarArgs(String code, String... parameters); + + public abstract Target mapWithArray(String code, String[] parameters); + + @Mapping(target = "parameters2", source = "parameters") + public abstract Target mapWithReassigningVarArgs(String code, String... parameters); + + public abstract Target mapWithArrayAndVarArgs(String code, String[] parameters, String... parameters2); + + @Mappings({ + @Mapping(target = "parameters", ignore = true) + }) + @BeanMapping(qualifiedByName = "afterMappingParametersAsArray") + public abstract Target mapParametersAsArrayInAfterMapping(String code, String... parameters); + + @AfterMapping + @Named( "afterMappingParametersAsArray" ) + protected void afterMappingParametersAsArray(@MappingTarget Target target, String[] parameters) { + target.setAfterMappingWithArrayCalled( true ); + target.setParameters( parameters ); + } + + @Mappings({ + @Mapping(target = "parameters", ignore = true) + }) + @BeanMapping(qualifiedByName = "afterMappingParametersAsVarArgs") + public abstract Target mapParametersAsVarArgsInAfterMapping(String code, String... parameters); + + @AfterMapping + @Named( "afterMappingParametersAsVarArgs" ) + protected void afterMappingParametersAsVarArgs(@MappingTarget Target target, String... parameters) { + target.setAfterMappingWithVarArgsCalled( true ); + target.setParameters( parameters ); + } + + @Mapping(target = "parameters2", ignore = true) + @BeanMapping(qualifiedByName = "afterMappingContextAsVarArgsUsingVarArgs") + public abstract Target mapContextWithVarArgsInAfterMappingWithVarArgs(String code, String[] parameters, + @Context String... context); + + @AfterMapping + @Named( "afterMappingContextAsVarArgsUsingVarArgs" ) + protected void afterMappingContextAsVarArgsUsingVarArgs(@MappingTarget Target target, @Context String... context) { + target.setAfterMappingContextWithVarArgsAsVarArgsCalled( true ); + target.setParameters2( context ); + } + + @Mapping(target = "parameters2", ignore = true) + @BeanMapping(qualifiedByName = "afterMappingContextAsVarArgsUsingArray") + public abstract Target mapContextWithVarArgsInAfterMappingWithArray(String code, String[] parameters, + @Context String... context); + + @AfterMapping + @Named( "afterMappingContextAsVarArgsUsingArray" ) + protected void afterMappingContextAsVarArgsUsingArray(@MappingTarget Target target, @Context String[] context) { + target.setAfterMappingContextWithVarArgsAsArrayCalled( true ); + target.setParameters2( context ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java new file mode 100644 index 0000000000..92a7f99ca7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java @@ -0,0 +1,148 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1541; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * + * @author Christian Bandowski + */ +@WithClasses({ + Issue1541Mapper.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1541") +public class Issue1541Test { + + @Test + public void testMappingWithVarArgs() { + Target target = Issue1541Mapper.INSTANCE.mapWithVarArgs( "code", "1", "2" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testMappingWithArray() { + Target target = Issue1541Mapper.INSTANCE.mapWithArray( "code", new String[] { "1", "2" } ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).isNull(); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testMappingWithVarArgsReassignment() { + Target target = Issue1541Mapper.INSTANCE.mapWithReassigningVarArgs( "code", "1", "2" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).isNull(); + assertThat( target.getParameters2() ).contains( "1", "2" ); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testMappingWithArrayAndVarArgs() { + Target target = Issue1541Mapper.INSTANCE.mapWithArrayAndVarArgs( "code", new String[] { "1", "2" }, "3", "4" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).contains( "3", "4" ); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testVarArgsInAfterMappingAsArray() { + Target target = Issue1541Mapper.INSTANCE.mapParametersAsArrayInAfterMapping( "code", "1", "2" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).isNull(); + assertThat( target.isAfterMappingWithArrayCalled() ).isTrue(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testVarArgsInAfterMappingAsVarArgs() { + Target target = Issue1541Mapper.INSTANCE.mapParametersAsVarArgsInAfterMapping( "code", "1", "2" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).isNull(); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isTrue(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testVarArgsInContextWithVarArgsAfterMapping() { + Target target = Issue1541Mapper.INSTANCE.mapContextWithVarArgsInAfterMappingWithVarArgs( + "code", + new String[] { "1", "2" }, + "3", + "4" + ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).contains( "3", "4" ); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isTrue(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); + } + + @Test + public void testVarArgsInContextWithArrayAfterMapping() { + Target target = Issue1541Mapper.INSTANCE.mapContextWithVarArgsInAfterMappingWithArray( + "code", + new String[] { "1", "2" }, + "3", + "4" + ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "code" ); + assertThat( target.getParameters() ).contains( "1", "2" ); + assertThat( target.getParameters2() ).contains( "3", "4" ); + assertThat( target.isAfterMappingWithArrayCalled() ).isFalse(); + assertThat( target.isAfterMappingWithVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsVarArgsCalled() ).isFalse(); + assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isTrue(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Target.java new file mode 100644 index 0000000000..b57c7a476f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Target.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1541; + +public class Target { + private String code; + private String[] parameters; + private String[] parameters2; + + private boolean afterMappingWithVarArgsCalled = false; + private boolean afterMappingWithArrayCalled = false; + private boolean afterMappingContextWithVarArgsAsVarArgsCalled = false; + private boolean afterMappingContextWithVarArgsAsArrayCalled = false; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String[] getParameters() { + return parameters; + } + + public void setParameters(String[] parameters) { + this.parameters = parameters; + } + + public String[] getParameters2() { + return parameters2; + } + + public void setParameters2(String[] parameters2) { + this.parameters2 = parameters2; + } + + public boolean isAfterMappingWithVarArgsCalled() { + return afterMappingWithVarArgsCalled; + } + + public void setAfterMappingWithVarArgsCalled(boolean afterMappingWithVarArgsCalled) { + this.afterMappingWithVarArgsCalled = afterMappingWithVarArgsCalled; + } + + public boolean isAfterMappingWithArrayCalled() { + return afterMappingWithArrayCalled; + } + + public void setAfterMappingWithArrayCalled(boolean afterMappingWithArrayCalled) { + this.afterMappingWithArrayCalled = afterMappingWithArrayCalled; + } + + public boolean isAfterMappingContextWithVarArgsAsVarArgsCalled() { + return afterMappingContextWithVarArgsAsVarArgsCalled; + } + + public void setAfterMappingContextWithVarArgsAsVarArgsCalled( + boolean afterMappingContextWithVarArgsAsVarArgsCalled) { + this.afterMappingContextWithVarArgsAsVarArgsCalled = afterMappingContextWithVarArgsAsVarArgsCalled; + } + + public boolean isAfterMappingContextWithVarArgsAsArrayCalled() { + return afterMappingContextWithVarArgsAsArrayCalled; + } + + public void setAfterMappingContextWithVarArgsAsArrayCalled(boolean afterMappingContextWithVarArgsAsArrayCalled) { + this.afterMappingContextWithVarArgsAsArrayCalled = afterMappingContextWithVarArgsAsArrayCalled; + } +} From 08067b7f172e0d1fd4ea6e9365acd170fdbe9795 Mon Sep 17 00:00:00 2001 From: Saheb Preet Singh Date: Sun, 12 Aug 2018 01:49:21 +0530 Subject: [PATCH 0265/1006] #1524 replaced java.beans.Introspector with a custom IntrospectorUtils class to avoid java.desktop module --- .../mapstruct-reference-guide.asciidoc | 2 +- .../naming/CustomAccessorNamingStrategy.java | 8 ++-- .../ap/spi/DefaultAccessorNamingStrategy.java | 10 ++-- .../ap/spi/util/IntrospectorUtils.java | 47 +++++++++++++++++++ .../mapstruct/ap/spi/util/package-info.java | 7 +++ .../ap/spi/util/IntrospectorUtilsTest.java | 28 +++++++++++ .../spi/CustomAccessorNamingStrategy.java | 8 ++-- 7 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java create mode 100644 processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index df25b40388..2d2327e578 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2757,7 +2757,7 @@ public class CustomAccessorNamingStrategy extends DefaultAccessorNamingStrategy @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); + return IntrospectorUtils.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); } } ---- diff --git a/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java b/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java index 3126a08a91..eb9d07a246 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java +++ b/integrationtest/src/test/resources/namingStrategyTest/strategy/src/main/java/org/mapstruct/itest/naming/CustomAccessorNamingStrategy.java @@ -5,13 +5,12 @@ */ package org.mapstruct.itest.naming; -import java.beans.Introspector; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; +import org.mapstruct.ap.spi.util.IntrospectorUtils; /** * A custom {@link AccessorNamingStrategy} recognizing getters in the form of {@code property()} and setters in the @@ -42,13 +41,14 @@ public boolean isAdderMethod(ExecutableElement method) { @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); + return IntrospectorUtils.decapitalize( + methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); } @Override public String getElementName(ExecutableElement adderMethod) { String methodName = adderMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.substring( 3 ) ); + return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 118ad2ba9b..8f82c8f896 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.spi; -import java.beans.Introspector; import java.util.regex.Pattern; import javax.lang.model.element.ExecutableElement; @@ -16,6 +15,7 @@ import javax.lang.model.util.SimpleElementVisitor6; import javax.lang.model.util.SimpleTypeVisitor6; +import org.mapstruct.ap.spi.util.IntrospectorUtils; /** * The default JavaBeans-compliant implementation of the {@link AccessorNamingStrategy} service provider interface. @@ -157,12 +157,12 @@ public boolean isPresenceCheckMethod(ExecutableElement method) { public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); if ( methodName.startsWith( "is" ) || methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { - return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); + return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); } else if ( isBuilderSetter( getterOrSetterMethod ) ) { return methodName; } - return Introspector.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); + return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); } /** @@ -177,10 +177,10 @@ else if ( isBuilderSetter( getterOrSetterMethod ) ) { @Override public String getElementName(ExecutableElement adderMethod) { String methodName = adderMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.substring( 3 ) ); + return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); } - /** + /** * Helper method, to obtain the fully qualified name of a type. * * @param type input type diff --git a/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java b/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java new file mode 100644 index 0000000000..fccc22b38b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi.util; + +/** + * Utilities for tools to learn about the properties, events, and methods supported by a target Java Bean. + * It is mainly needed to avoid using {@link java.beans.Introspector} class which is part of java.desktop module + * from java 9, thus avoiding pulling a module ( of around 10 MB ) for using a single class. + * + * @author Saheb Preet Singh + */ +public class IntrospectorUtils { + + private IntrospectorUtils() { + } + + /** + * Utility method to take a string and convert it to normal Java variable + * name capitalization. This normally means converting the first + * character from upper case to lower case, but in the (unusual) special + * case when there is more than one character and both the first and + * second characters are upper case, we leave it alone. + *

      + * Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays + * as "URL". + * + * @param name The string to be decapitalized. + * + * @return The decapitalized version of the string. + */ + public static String decapitalize(String name) { + if ( name == null || name.length() == 0 ) { + return name; + } + if ( name.length() > 1 && Character.isUpperCase( name.charAt( 1 ) ) && + Character.isUpperCase( name.charAt( 0 ) ) ) { + return name; + } + char[] chars = name.toCharArray(); + chars[0] = Character.toLowerCase( chars[0] ); + return new String( chars ); + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java b/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java new file mode 100644 index 0000000000..7b8f374cf7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java @@ -0,0 +1,7 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.spi.util; diff --git a/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java new file mode 100644 index 0000000000..02c171e63e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi.util; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +/** + * @author Saheb Preet Singh + */ +public class IntrospectorUtilsTest { + + @Test + public void testDecapitalize() throws Exception { + assertThat( IntrospectorUtils.decapitalize( null ) ).isNull(); + assertThat( IntrospectorUtils.decapitalize( "" ) ).isEqualTo( "" ); + assertThat( IntrospectorUtils.decapitalize( "URL" ) ).isEqualTo( "URL" ); + assertThat( IntrospectorUtils.decapitalize( "FooBar" ) ).isEqualTo( "fooBar" ); + assertThat( IntrospectorUtils.decapitalize( "PArtialCapitalized" ) ).isEqualTo( "PArtialCapitalized" ); + assertThat( IntrospectorUtils.decapitalize( "notCapitalized" ) ).isEqualTo( "notCapitalized" ); + assertThat( IntrospectorUtils.decapitalize( "a" ) ).isEqualTo( "a" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java index eb99c43707..d8c4ddd8c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomAccessorNamingStrategy.java @@ -5,11 +5,10 @@ */ package org.mapstruct.ap.test.naming.spi; -import java.beans.Introspector; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; +import org.mapstruct.ap.spi.util.IntrospectorUtils; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; @@ -42,13 +41,14 @@ public boolean isAdderMethod(ExecutableElement method) { @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); + return IntrospectorUtils.decapitalize( + methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); } @Override public String getElementName(ExecutableElement adderMethod) { String methodName = adderMethod.getSimpleName().toString(); - return Introspector.decapitalize( methodName.substring( 3 ) ); + return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); } } From 0d3ec9042db1fed6c2b55ec21cc91eb4989276b9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 Aug 2018 22:21:56 +0200 Subject: [PATCH 0266/1006] Add Saheb to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index eddc353b64..c66607498e 100644 --- a/copyright.txt +++ b/copyright.txt @@ -31,6 +31,7 @@ Peter Larson - https://github.com/pjlarson Remko Plantenga - https://github.com/sonata82 Remo Meier - https://github.com/remmeier Richard Lea - https://github.com/chigix +Saheb Preet Singh - https://github.com/sahebpreet Samuel Wright - https://github.com/samwright Sebastian Hasait - https://github.com/shasait Sean Huang - https://github.com/seanjob From e056311c1a48d3b9de15d0fbd3a6dd57ba847739 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 13 Aug 2018 21:21:04 +0200 Subject: [PATCH 0267/1006] #1569 Make sure that converting Java 8 LocalDate to Date generates correct code * ZoneOffset instead of ZoneId needs to be imported when performing a conversion from LocalDate to Date --- .../JavaLocalDateToDateConversion.java | 3 +- .../bugs/_1569/java8/Issue1569Mapper.java | 20 +++++++++ .../test/bugs/_1569/java8/Issue1569Test.java | 43 +++++++++++++++++++ .../ap/test/bugs/_1569/java8/Source.java | 24 +++++++++++ .../ap/test/bugs/_1569/java8/Target.java | 24 +++++++++++ 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java index d34d03c40f..9d4f3a0c57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java @@ -16,7 +16,6 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.localDateTime; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; import static org.mapstruct.ap.internal.util.JavaTimeConstants.LOCAL_DATE_TIME_FQN; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** @@ -53,7 +52,7 @@ protected String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( conversionContext.getTypeFactory().getType( LOCAL_DATE_TIME_FQN ), - conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Mapper.java new file mode 100644 index 0000000000..b97d0f75fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1569.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1569Mapper { + + Issue1569Mapper INSTANCE = Mappers.getMapper( Issue1569Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java new file mode 100644 index 0000000000..079e792705 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1569.java8; + +import java.time.LocalDate; +import java.time.Month; +import java.time.ZoneOffset; +import java.util.Date; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue1569Mapper.class, + Source.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1569") +public class Issue1569Test { + + @Test + public void shouldGenerateCorrectMapping() { + Source source = new Source(); + Date date = Date.from( LocalDate.of( 2018, Month.AUGUST, 5 ).atTime( 20, 30 ).toInstant( ZoneOffset.UTC ) ); + source.setPromotionDate( date ); + + Target target = Issue1569Mapper.INSTANCE.map( source ); + + assertThat( target.getPromotionDate() ).isEqualTo( LocalDate.of( 2018, Month.AUGUST, 5 ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Source.java new file mode 100644 index 0000000000..1be37556b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Source.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1569.java8; + +import java.util.Date; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private Date promotionDate; + + public Date getPromotionDate() { + return promotionDate; + } + + public void setPromotionDate(Date promotionDate) { + this.promotionDate = promotionDate; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Target.java new file mode 100644 index 0000000000..d523517577 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Target.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1569.java8; + +import java.time.LocalDate; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private LocalDate promotionDate; + + public LocalDate getPromotionDate() { + return promotionDate; + } + + public void setPromotionDate(LocalDate promotionDate) { + this.promotionDate = promotionDate; + } +} From 5c2e0494789ab40a68d3cdfa218a195de24ce922 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 14 Aug 2018 06:56:59 +0200 Subject: [PATCH 0268/1006] #1558 Annotations `ElementType.TYPE_USE` not handled correctly --- .../ap/internal/model/common/TypeFactory.java | 10 +++ .../ap/internal/util/NativeTypes.java | 24 +++++ .../ap/test/bugs/_1558/java8/Car.java | 81 +++++++++++++++++ .../ap/test/bugs/_1558/java8/Car2.java | 89 +++++++++++++++++++ .../ap/test/bugs/_1558/java8/CarMapper.java | 17 ++++ .../test/bugs/_1558/java8/Issue1558Test.java | 34 +++++++ .../ap/test/bugs/_1558/java8/NotNull.java | 22 +++++ 7 files changed, 277 insertions(+) create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car2.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/NotNull.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index e2733cb6f4..24922910b6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -45,6 +45,7 @@ import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -238,6 +239,15 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { qualifiedName = componentTypeElement.getQualifiedName().toString() + arraySuffix; isImported = isImported( name, qualifiedName ); } + else if (componentTypeMirror.getKind().isPrimitive()) { + // When the component type is primitive and is annotated with ElementType.TYPE_USE then + // the typeMirror#toString returns (@CustomAnnotation :: byte) for the javac compiler + name = NativeTypes.getName( componentTypeMirror.getKind() ) + builder.toString(); + packageName = null; + // for primitive types only name (e.g. byte, short..) required as qualified name + qualifiedName = name; + isImported = false; + } else { name = mirror.toString(); packageName = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index 3d3c37441e..bd12135226 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -8,11 +8,13 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.util.Collections; +import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import javax.lang.model.type.TypeKind; /** * Provides functionality around the Java primitive data types and their wrapper types. They are considered native. @@ -24,6 +26,7 @@ public class NativeTypes { private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES; private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPES; private static final Set> NUMBER_TYPES = new HashSet>(); + private static final Map TYPE_KIND_NAME = new EnumMap( TypeKind.class ); private static final Map ANALYZERS; private static final Pattern PTRN_HEX = Pattern.compile( "^0[x|X].*" ); @@ -446,6 +449,15 @@ private NativeTypes() { ANALYZERS = Collections.unmodifiableMap( tmp2 ); + TYPE_KIND_NAME.put( TypeKind.BOOLEAN, "boolean" ); + TYPE_KIND_NAME.put( TypeKind.BYTE, "byte" ); + TYPE_KIND_NAME.put( TypeKind.SHORT, "short" ); + TYPE_KIND_NAME.put( TypeKind.INT, "int" ); + TYPE_KIND_NAME.put( TypeKind.LONG, "long" ); + TYPE_KIND_NAME.put( TypeKind.CHAR, "char" ); + TYPE_KIND_NAME.put( TypeKind.FLOAT, "float" ); + TYPE_KIND_NAME.put( TypeKind.DOUBLE, "double" ); + } public static Class getWrapperType(Class clazz) { @@ -493,4 +505,16 @@ public static Class getLiteral(String className, String literal) { } return result; } + + /** + * The name that should be used for the {@code typeKind}. + * Should be used in order to get the name of a primitive type + * + * @param typeKind the type kind + * + * @return the name that should be used for the {@code typeKind} + */ + public static String getName(TypeKind typeKind) { + return TYPE_KIND_NAME.get( typeKind ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car.java new file mode 100755 index 0000000000..d18c49246a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car.java @@ -0,0 +1,81 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1558.java8; + +public class Car { + private boolean[] booleanData; + private byte[] data; + private short[] shortData; + private int[] intData; + private long[] longData; + private char[] charData; + private float[] floatData; + private double[] doubleData; + + public boolean[] getBooleanData() { + return booleanData; + } + + public void setBooleanData(boolean[] booleanData) { + this.booleanData = booleanData; + } + + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + public short[] getShortData() { + return shortData; + } + + public void setShortData(short[] shortData) { + this.shortData = shortData; + } + + public int[] getIntData() { + return intData; + } + + public void setIntData(int[] intData) { + this.intData = intData; + } + + public long[] getLongData() { + return longData; + } + + public void setLongData(long[] longData) { + this.longData = longData; + } + + public char[] getCharData() { + return charData; + } + + public void setCharData(char[] charData) { + this.charData = charData; + } + + public float[] getFloatData() { + return floatData; + } + + public void setFloatData(float[] floatData) { + this.floatData = floatData; + } + + public double[] getDoubleData() { + return doubleData; + } + + public void setDoubleData(double[] doubleData) { + this.doubleData = doubleData; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car2.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car2.java new file mode 100755 index 0000000000..337c5dd774 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Car2.java @@ -0,0 +1,89 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1558.java8; + +public class Car2 { + private boolean[] booleanData; + private byte[] data; + private short[] shortData; + private int[] intData; + private long[] longData; + private char[] charData; + private float[] floatData; + private double[] doubleData; + + @NotNull + public boolean[] getBooleanData() { + return booleanData; + } + + public void setBooleanData(boolean[] booleanData) { + this.booleanData = booleanData; + } + + @NotNull + public byte[] getData() { + return data; + } + + public void setData(byte[] data) { + this.data = data; + } + + @NotNull + public short[] getShortData() { + return shortData; + } + + public void setShortData(short[] shortData) { + this.shortData = shortData; + } + + @NotNull + public int[] getIntData() { + return intData; + } + + public void setIntData(int[] intData) { + this.intData = intData; + } + + @NotNull + public long[] getLongData() { + return longData; + } + + public void setLongData(long[] longData) { + this.longData = longData; + } + + @NotNull + public char[] getCharData() { + return charData; + } + + public void setCharData(char[] charData) { + this.charData = charData; + } + + @NotNull + public float[] getFloatData() { + return floatData; + } + + public void setFloatData(float[] floatData) { + this.floatData = floatData; + } + + @NotNull + public double[] getDoubleData() { + return doubleData; + } + + public void setDoubleData(double[] doubleData) { + this.doubleData = doubleData; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/CarMapper.java new file mode 100755 index 0000000000..2bd71d0c62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/CarMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1558.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + Car toCar(Car2 car2); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java new file mode 100644 index 0000000000..9840716429 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1558.java8; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ + NotNull.class, + CarMapper.class, + Car.class, + Car2.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1558") +public class Issue1558Test { + + @Test + public void testShouldCompile() { + Car2 car = new Car2(); + Car target = CarMapper.INSTANCE.toCar( car ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/NotNull.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/NotNull.java new file mode 100644 index 0000000000..cf059a7c14 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/NotNull.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1558.java8; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ + ElementType.METHOD, + ElementType.TYPE_USE +}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface NotNull { + +} From 10f855fa9ec3fd8290cbb2536b352e2f1997d3c4 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 14 Aug 2018 23:53:41 +0200 Subject: [PATCH 0269/1006] #1532 using fields and constructor fragments optimizing DataTypeFactory usage --- .../model/AbstractMappingMethodBuilder.java | 2 +- .../internal/model/AnnotatedConstructor.java | 54 ++++++++++-- .../model/ContainerMappingMethod.java | 4 +- .../model/ContainerMappingMethodBuilder.java | 2 +- .../ap/internal/model/Decorator.java | 2 +- .../model/DefaultMapperReference.java | 2 +- .../mapstruct/ap/internal/model/Field.java | 10 +++ .../ap/internal/model/GeneratedType.java | 8 +- .../LifecycleCallbackMethodReference.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 6 +- .../mapstruct/ap/internal/model/Mapper.java | 34 +++++--- .../internal/model/MappingBuilderContext.java | 8 +- .../ap/internal/model/MappingMethod.java | 6 +- .../model/NestedPropertyMappingMethod.java | 2 +- .../internal/model/NoArgumentConstructor.java | 42 +++++++++ .../ap/internal/model/PropertyMapping.java | 6 +- .../model/SupportingConstructorFragment.java | 85 +++++++++++++++++++ .../ap/internal/model/SupportingField.java | 76 +++++++++++++++++ ...thod.java => SupportingMappingMethod.java} | 66 +++++++++++++- .../ap/internal/model/common/SourceRHS.java | 2 +- .../internal/model/source/ForgedMethod.java | 2 +- .../AbstractToXmlGregorianCalendar.java | 57 +++++++++++++ .../builtin/BuiltInConstructorFragment.java | 12 +++ .../source/builtin/BuiltInFieldReference.java | 27 ++++++ .../model/source/builtin/BuiltInMethod.java | 14 ++- .../CalendarToXmlGregorianCalendar.java | 27 ++---- .../builtin/CalendarToZonedDateTime.java | 4 +- .../builtin/DateToXmlGregorianCalendar.java | 27 ++---- .../model/source/builtin/FinalField.java | 35 ++++++++ .../model/source/builtin/JaxbElemToValue.java | 5 +- .../JodaDateTimeToXmlGregorianCalendar.java | 32 ++----- ...daLocalDateTimeToXmlGregorianCalendar.java | 32 ++----- .../JodaLocalDateToXmlGregorianCalendar.java | 32 ++----- .../JodaLocalTimeToXmlGregorianCalendar.java | 32 ++----- .../LocalDateToXmlGregorianCalendar.java | 30 +++---- ...NewDatatypeFactoryConstructorFragment.java | 12 +++ .../builtin/StringToXmlGregorianCalendar.java | 27 ++---- .../XmlGregorianCalendarToCalendar.java | 5 +- .../builtin/XmlGregorianCalendarToDate.java | 5 +- .../XmlGregorianCalendarToJodaDateTime.java | 4 +- .../XmlGregorianCalendarToJodaLocalDate.java | 4 +- ...lGregorianCalendarToJodaLocalDateTime.java | 4 +- .../XmlGregorianCalendarToJodaLocalTime.java | 4 +- .../XmlGregorianCalendarToLocalDate.java | 5 +- .../builtin/XmlGregorianCalendarToString.java | 5 +- .../builtin/ZonedDateTimeToCalendar.java | 4 +- .../ZonedDateTimeToXmlGregorianCalendar.java | 21 ++--- ...nnotationBasedComponentModelProcessor.java | 43 +++++++--- .../processor/MapperCreationProcessor.java | 23 ++++- .../creation/MappingResolverImpl.java | 41 +++++---- .../mapstruct/ap/internal/util/Strings.java | 6 +- .../internal/model/AnnotatedConstructor.ftl | 12 ++- .../ap/internal/model/Annotation.ftl | 1 + .../model/AnnotationMapperReference.ftl | 1 + .../ap/internal/model/BeanMappingMethod.ftl | 1 + .../internal/model/DecoratorConstructor.ftl | 1 + .../internal/model/DefaultMapperReference.ftl | 1 + .../ap/internal/model/DelegatingMethod.ftl | 1 + .../ap/internal/model/EnumMappingMethod.ftl | 1 + .../org/mapstruct/ap/internal/model/Field.ftl | 1 + .../ap/internal/model/GeneratedType.ftl | 1 + .../ap/internal/model/IterableCreation.ftl | 1 + .../internal/model/IterableMappingMethod.ftl | 1 + .../LifecycleCallbackMethodReference.ftl | 1 + .../ap/internal/model/MapMappingMethod.ftl | 1 + .../ap/internal/model/MethodReference.ftl | 1 + .../model/NestedPropertyMappingMethod.ftl | 1 + .../internal/model/NoArgumentConstructor.ftl | 13 +++ .../ap/internal/model/PropertyMapping.ftl | 1 + .../ap/internal/model/ServicesEntry.ftl | 1 + .../ap/internal/model/StreamMappingMethod.ftl | 1 + .../ap/internal/model/TypeConversion.ftl | 1 + .../ap/internal/model/ValueMappingMethod.ftl | 1 + .../model/assignment/AdderWrapper.ftl | 1 + .../model/assignment/ArrayCopyWrapper.ftl | 1 + .../model/assignment/EnumConstantWrapper.ftl | 1 + ...anceSetterWrapperForCollectionsAndMaps.ftl | 1 + .../GetterWrapperForCollectionsAndMaps.ftl | 1 + .../model/assignment/Java8FunctionWrapper.ftl | 1 + .../model/assignment/LocalVarWrapper.ftl | 1 + .../model/assignment/SetterWrapper.ftl | 1 + .../SetterWrapperForCollectionsAndMaps.ftl | 1 + ...pperForCollectionsAndMapsWithNullCheck.ftl | 1 + .../model/assignment/UpdateWrapper.ftl | 1 + .../ap/internal/model/common/Parameter.ftl | 1 + .../ap/internal/model/common/SourceRHS.ftl | 1 + .../ap/internal/model/common/Type.ftl | 1 + .../CalendarToXmlGregorianCalendar.ftl | 12 +-- .../builtin/CalendarToZonedDateTime.ftl | 1 + .../builtin/DateToXmlGregorianCalendar.ftl | 12 +-- .../model/source/builtin/FinalField.ftl | 9 ++ .../model/source/builtin/JaxbElemToValue.ftl | 1 + .../JodaDateTimeToXmlGregorianCalendar.ftl | 25 +++--- ...odaLocalDateTimeToXmlGregorianCalendar.ftl | 24 +++--- .../JodaLocalDateToXmlGregorianCalendar.ftl | 16 ++-- .../JodaLocalTimeToXmlGregorianCalendar.ftl | 19 ++--- .../LocalDateToXmlGregorianCalendar.ftl | 19 ++--- .../NewDatatypeFactoryConstructorFragment.ftl | 14 +++ .../builtin/StringToXmlGregorianCalendar.ftl | 8 +- .../XmlGregorianCalendarToCalendar.ftl | 1 + .../builtin/XmlGregorianCalendarToDate.ftl | 1 + .../XmlGregorianCalendarToJodaDateTime.ftl | 1 + .../XmlGregorianCalendarToJodaLocalDate.ftl | 1 + ...mlGregorianCalendarToJodaLocalDateTime.ftl | 1 + .../XmlGregorianCalendarToJodaLocalTime.ftl | 1 + .../XmlGregorianCalendarToLocalDate.ftl | 1 + .../builtin/XmlGregorianCalendarToString.ftl | 1 + .../builtin/ZonedDateTimeToCalendar.ftl | 1 + .../ZonedDateTimeToXmlGregorianCalendar.ftl | 8 +- .../ap/internal/util/StringsTest.java | 26 +++--- .../ap/test/builtin/DatatypeFactoryTest.java | 69 +++++++++++++++ .../ap/test/builtin/bean/DatatypeFactory.java | 13 +++ ...mlGregorianCalendarFactorizedProperty.java | 26 ++++++ .../builtin/mapper/ToXmlGregCalMapper.java | 24 ++++++ .../shared/CustomerRecordDto.java | 33 +++++++ .../shared/CustomerRecordEntity.java | 33 +++++++ ...CustomerRecordSpringConstructorMapper.java | 23 +++++ .../SpringConstructorMapperTest.java | 49 +++++++++-- 118 files changed, 1116 insertions(+), 416 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/NoArgumentConstructor.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java rename processor/src/main/java/org/mapstruct/ap/internal/model/{VirtualMappingMethod.java => SupportingMappingMethod.java} (50%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/NoArgumentConstructor.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DatatypeFactory.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarFactorizedProperty.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ToXmlGregCalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 88f6d6a127..04c64d6066 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -37,7 +37,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { } String name = getName( sourceType, targetType ); - name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); ForgedMethodHistory history = null; if ( method instanceof ForgedMethod ) { history = ( (ForgedMethod) method ).getHistory(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java index aaf4d152dd..d9feb2b1d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -19,17 +20,52 @@ */ public class AnnotatedConstructor extends ModelElement implements Constructor { - private final String name; + private String name; private final List mapperReferences; private final List annotations; - private final boolean publicEmptyConstructor; + private final NoArgumentConstructor noArgumentConstructor; + private final Set fragments; - public AnnotatedConstructor(String name, List mapperReferences, - List annotations, boolean publicEmptyConstructor) { + public static AnnotatedConstructor forComponentModels(String name, + List mapperReferences, + List annotations, + Constructor constructor, + boolean includeNoArgConstructor) { + + NoArgumentConstructor noArgumentConstructor = null; + if ( constructor instanceof NoArgumentConstructor ) { + noArgumentConstructor = (NoArgumentConstructor) constructor; + } + NoArgumentConstructor noArgConstructorToInBecluded = null; + Set fragmentsToBeIncluded = Collections.emptySet(); + if ( includeNoArgConstructor ) { + if ( noArgumentConstructor != null ) { + noArgConstructorToInBecluded = noArgumentConstructor; + } + else { + noArgConstructorToInBecluded = new NoArgumentConstructor( name, fragmentsToBeIncluded ); + } + } + else if ( noArgumentConstructor != null ) { + fragmentsToBeIncluded = noArgumentConstructor.getFragments(); + } + return new AnnotatedConstructor( + name, + mapperReferences, + annotations, + noArgConstructorToInBecluded, + fragmentsToBeIncluded + ); + } + + private AnnotatedConstructor(String name, List mapperReferences, + List annotations, NoArgumentConstructor noArgumentConstructor, + Set fragments) { this.name = name; this.mapperReferences = mapperReferences; this.annotations = annotations; - this.publicEmptyConstructor = publicEmptyConstructor; + this.noArgumentConstructor = noArgumentConstructor; + this.fragments = fragments; } @Override @@ -60,7 +96,11 @@ public List getAnnotations() { return annotations; } - public boolean isPublicEmptyConstructor() { - return publicEmptyConstructor; + public NoArgumentConstructor getNoArgumentConstructor() { + return noArgumentConstructor; + } + + public Set getFragments() { + return fragments; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index c80eb593d5..13759f5c12 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -41,8 +41,8 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { this.elementAssignment = parameterAssignment; this.loopVariableName = loopVariableName; this.selectionParameters = selectionParameters; - this.index1Name = Strings.getSaveVariableName( "i", existingVariables ); - this.index2Name = Strings.getSaveVariableName( "j", existingVariables ); + this.index1Name = Strings.getSafeVariableName( "i", existingVariables ); + this.index2Name = Strings.getSafeVariableName( "j", existingVariables ); } public Parameter getSourceParameter() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index c4b96c0348..5cd610c20d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -73,7 +73,7 @@ public final M build() { Type targetElementType = getElementType( resultType ); String loopVariableName = - Strings.getSaveVariableName( sourceElementType.getName(), method.getParameterNames() ); + Strings.getSafeVariableName( sourceElementType.getName(), method.getParameterNames() ); SourceRHS sourceRHS = new SourceRHS( loopVariableName, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index 5b5dae8714..ad88c0e387 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -133,7 +133,7 @@ public Decorator build() { @SuppressWarnings( "checkstyle:parameternumber" ) private Decorator(TypeFactory typeFactory, String packageName, String name, Type decoratorType, String interfacePackage, String interfaceName, List methods, - List fields, Options options, VersionInformation versionInformation, + List fields, Options options, VersionInformation versionInformation, Accessibility accessibility, SortedSet extraImports, DecoratorConstructor decoratorConstructor) { super( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java index e1fc85eb40..924648368a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java @@ -37,7 +37,7 @@ public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedM importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) ); } - String variableName = Strings.getSaveVariableName( + String variableName = Strings.getSafeVariableName( type.getName(), otherMapperReferences ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index 1ce3753a21..a47c44f6dc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -5,7 +5,9 @@ */ package org.mapstruct.ap.internal.model; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; @@ -115,4 +117,12 @@ public boolean equals(Object obj) { (other.variableName != null) : !this.variableName.equals( other.variableName ) ); } + public static List getFieldNames(Set fields) { + List names = new ArrayList( fields.size() ); + for ( Field field : fields ) { + names.add( field.getVariableName() ); + } + return names; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 352e651758..75703dcfa4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -44,7 +44,7 @@ public abstract class GeneratedType extends ModelElement { private final boolean suppressGeneratorVersionComment; private final VersionInformation versionInformation; private final Accessibility accessibility; - private List fields; + private List fields; private Constructor constructor; /** @@ -56,7 +56,7 @@ public abstract class GeneratedType extends ModelElement { // CHECKSTYLE:OFF protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName, String interfacePackage, String interfaceName, List methods, - List fields, Options options, VersionInformation versionInformation, + List fields, Options options, VersionInformation versionInformation, Accessibility accessibility, SortedSet extraImportedTypes, Constructor constructor) { this.packageName = packageName; this.name = name; @@ -123,11 +123,11 @@ public List getMethods() { return methods; } - public List getFields() { + public List getFields() { return fields; } - public void setFields(List fields) { + public void setFields(List fields) { this.fields = fields; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java index cb3d892de3..10fb2d9c77 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.java @@ -42,7 +42,7 @@ private LifecycleCallbackMethodReference(SelectedMethod lifecycleM this.methodResultType = containingMethod.getResultType(); if ( hasReturnType() ) { - this.targetVariableName = Strings.getSaveVariableName( "target", existingVariableNames ); + this.targetVariableName = Strings.getSafeVariableName( "target", existingVariableNames ); existingVariableNames.add( this.targetVariableName ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index e46e1194d0..e4075757da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -266,21 +266,21 @@ public Set getImportTypes() { } public String getKeyVariableName() { - return Strings.getSaveVariableName( + return Strings.getSafeVariableName( "key", getParameterNames() ); } public String getValueVariableName() { - return Strings.getSaveVariableName( + return Strings.getSafeVariableName( "value", getParameterNames() ); } public String getEntryVariableName() { - return Strings.getSaveVariableName( + return Strings.getSafeVariableName( "entry", getParameterNames() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index 89b3c36ef7..e4b89b4c0b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.List; +import java.util.Set; import java.util.SortedSet; import javax.lang.model.element.Element; @@ -34,15 +35,14 @@ public class Mapper extends GeneratedType { private final boolean customPackage; private final boolean customImplName; - private final List referencedMappers; private Decorator decorator; @SuppressWarnings( "checkstyle:parameternumber" ) private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName, String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName, List methods, Options options, VersionInformation versionInformation, - Accessibility accessibility, List referencedMappers, Decorator decorator, - SortedSet extraImportedTypes) { + Accessibility accessibility, List fields, Constructor constructor, + Decorator decorator, SortedSet extraImportedTypes ) { super( typeFactory, @@ -52,17 +52,16 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, String interfacePackage, interfaceName, methods, - referencedMappers, + fields, options, versionInformation, accessibility, extraImportedTypes, - null + constructor ); this.customPackage = customPackage; this.customImplName = customImplName; - this.referencedMappers = referencedMappers; this.decorator = decorator; } @@ -71,7 +70,8 @@ public static class Builder { private TypeFactory typeFactory; private TypeElement element; private List mappingMethods; - private List mapperReferences; + private List fields; + private Set fragments; private SortedSet extraImportedTypes; private Elements elementUtils; @@ -93,8 +93,13 @@ public Builder mappingMethods(List mappingMethods) { return this; } - public Builder mapperReferences(List mapperReferences) { - this.mapperReferences = mapperReferences; + public Builder fields(List fields) { + this.fields = fields; + return this; + } + + public Builder constructorFragments(Set fragments) { + this.fragments = fragments; return this; } @@ -146,7 +151,10 @@ public Mapper build() { String elementPackage = elementUtils.getPackageOf( element ).getQualifiedName().toString(); String packageName = implPackage.replace( PACKAGE_NAME_PLACEHOLDER, elementPackage ); - + Constructor constructor = null; + if ( !fragments.isEmpty() ) { + constructor = new NoArgumentConstructor( implementationName, fragments ); + } return new Mapper( typeFactory, packageName, @@ -160,15 +168,13 @@ public Mapper build() { options, versionInformation, Accessibility.fromModifiers( element.getModifiers() ), - mapperReferences, + fields, + constructor, decorator, extraImportedTypes ); } - } - public List getReferencedMappers() { - return referencedMappers; } public Decorator getDecorator() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 3efa16ada0..48ee36be0d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -37,7 +37,7 @@ *

        *
      • Input for the building process, such as the source model (mapping methods found) and mapper references.
      • *
      • Required factory, utility, reporting methods for building the mappings.
      • - *
      • Means to harbor results produced by the builders, such as forged- and virtual mapping methods that should be + *
      • Means to harbor results produced by the builders, such as forged- and supported mapping methods that should be * generated in a later stage.
      • *
      * @@ -94,7 +94,7 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, String tar SelectionParameters selectionParameters, SourceRHS sourceRHS, boolean preferUpdateMethods); - Set getUsedVirtualMappings(); + Set getUsedSupportedMappings(); } private final TypeFactory typeFactory; @@ -209,8 +209,8 @@ public MappingMethod getExistingMappingMethod(MappingMethod newMappingMethod) { return existingMappingMethod; } - public Set getUsedVirtualMappings() { - return mappingResolver.getUsedVirtualMappings(); + public Set getUsedSupportedMappings() { + return mappingResolver.getUsedSupportedMappings(); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 3a4a9c1306..0a23001d0f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -5,7 +5,7 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Strings.getSaveVariableName; +import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName; import static org.mapstruct.ap.internal.util.Strings.join; import java.util.ArrayList; @@ -91,12 +91,12 @@ private String initResultName(Collection existingVarNames) { return targetParameter.getName(); } else if ( getResultType().isArrayType() ) { - String name = getSaveVariableName( getResultType().getComponentType().getName() + "Tmp", existingVarNames ); + String name = getSafeVariableName( getResultType().getComponentType().getName() + "Tmp", existingVarNames ); existingVarNames.add( name ); return name; } else { - String name = getSaveVariableName( getResultType().getName(), existingVarNames ); + String name = getSafeVariableName( getResultType().getName(), existingVarNames ); existingVarNames.add( name ); return name; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index fbe9076a6b..f77218431a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -58,7 +58,7 @@ public NestedPropertyMappingMethod build() { final List thrownTypes = new ArrayList(); List safePropertyEntries = new ArrayList(); for ( PropertyEntry propertyEntry : propertyEntries ) { - String safeName = Strings.getSaveVariableName( propertyEntry.getName(), existingVariableNames ); + String safeName = Strings.getSafeVariableName( propertyEntry.getName(), existingVariableNames ); safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); existingVariableNames.add( safeName ); thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NoArgumentConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NoArgumentConstructor.java new file mode 100644 index 0000000000..1101c15891 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NoArgumentConstructor.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.Collections; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * Represents a constructor that is used for constructor injection. + * + * @author Sjaak Derksen + */ +public class NoArgumentConstructor extends ModelElement implements Constructor { + + private final String name; + private final Set fragments; + + public NoArgumentConstructor(String name, Set fragments) { + this.name = name; + this.fragments = fragments; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + @Override + public String getName() { + return name; + } + + public Set getFragments() { + return fragments; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index fc996c0527..7c632f1f8e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -511,7 +511,7 @@ else if ( propertyEntries.size() == 1 ) { // forge a method from the parameter type to the last entry type. String forgedName = Strings.joinAndCamelize( sourceReference.getElementNames() ); - forgedName = Strings.getSaveVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() ); + forgedName = Strings.getSafeVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() ); ForgedMethod methodRef = new ForgedMethod( forgedName, sourceReference.getParameter().getType(), @@ -601,7 +601,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element, String suffix) { String name = getName( sourceType, targetType ); - name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); @@ -647,7 +647,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { } String name = getName( sourceType, targetType ); - name = Strings.getSaveVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); List parameters = new ArrayList( method.getContextParameters() ); Type returnType; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java new file mode 100644 index 0000000000..14a13ca735 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.Collections; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.builtin.BuiltInConstructorFragment; + +/** + * A mapper instance field, initialized as null + * + * @author Sjaak Derksen + */ +public class SupportingConstructorFragment extends ModelElement { + + private final String templateName; + private final SupportingMappingMethod definingMethod; + + public SupportingConstructorFragment(SupportingMappingMethod definingMethod, + BuiltInConstructorFragment constructorFragment) { + this.templateName = getTemplateNameForClass( constructorFragment.getClass() ); + this.definingMethod = definingMethod; + } + + @Override + public String getTemplateName() { + return templateName; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + public SupportingMappingMethod getDefiningMethod() { + return definingMethod; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + SupportingConstructorFragment other = (SupportingConstructorFragment) obj; + if ( templateName == null ) { + if ( other.templateName != null ) { + return false; + } + } + else if ( !templateName.equals( other.templateName ) ) { + return false; + } + return true; + } + + public static void addAllFragmentsIn(Set supportingMappingMethods, + Set targets) { + for ( SupportingMappingMethod supportingMappingMethod : supportingMappingMethods ) { + SupportingConstructorFragment fragment = supportingMappingMethod.getSupportingConstructorFragment(); + if ( fragment != null ) { + targets.add( supportingMappingMethod.getSupportingConstructorFragment() ); + } + } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java new file mode 100644 index 0000000000..e9d0d1e3ca --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.Set; + +import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference; + +/** + * supports the + * + * @author Sjaak Derksen + */ +public class SupportingField extends Field { + + private final String templateName; + private final SupportingMappingMethod definingMethod; + + public SupportingField(SupportingMappingMethod definingMethod, BuiltInFieldReference fieldReference, String name) { + super( fieldReference.getType(), name, true ); + this.templateName = getTemplateNameForClass( fieldReference.getClass() ); + this.definingMethod = definingMethod; + } + + @Override + public String getTemplateName() { + return templateName; + } + + public SupportingMappingMethod getDefiningMethod() { + return definingMethod; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() ); + return result; + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + SupportingField other = (SupportingField) obj; + if ( templateName == null ) { + if ( other.templateName != null ) { + return false; + } + } + else if ( !templateName.equals( other.templateName ) ) { + return false; + } + return true; + } + + public static void addAllFieldsIn(Set supportingMappingMethods, Set targets) { + for ( SupportingMappingMethod supportingMappingMethod : supportingMappingMethods ) { + Field field = supportingMappingMethod.getSupportingField(); + if ( field != null ) { + targets.add( supportingMappingMethod.getSupportingField() ); + } + } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java similarity index 50% rename from processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java index 2787839026..8827bc5d35 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/VirtualMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java @@ -8,29 +8,79 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; +import org.mapstruct.ap.internal.model.source.builtin.NewDatatypeFactoryConstructorFragment; +import org.mapstruct.ap.internal.util.Strings; /** * A mapping method which is not based on an actual method declared in the original mapper interface but is added as * private method to map a certain source/target type combination. Based on a {@link BuiltInMethod}. * + * Specific templates all point to this class, for instance: + * {@link org.mapstruct.ap.internal.model.source.builtin.XmlGregorianCalendarToCalendar}, + * but also used fields and constructor elements, e.g. + * {@link org.mapstruct.ap.internal.model.source.builtin.FinalField} and + * {@link NewDatatypeFactoryConstructorFragment} + * * @author Gunnar Morling */ -public class VirtualMappingMethod extends MappingMethod { +public class SupportingMappingMethod extends MappingMethod { private final String templateName; private final Set importTypes; + private final Field supportingField; + private final SupportingConstructorFragment supportingConstructorFragment; - public VirtualMappingMethod(BuiltInMethod method) { + public SupportingMappingMethod(BuiltInMethod method, Set existingFields) { super( method ); this.importTypes = method.getImportTypes(); this.templateName = getTemplateNameForClass( method.getClass() ); + if ( method.getFieldReference() != null ) { + this.supportingField = getSafeField( method.getFieldReference(), existingFields ); + } + else { + this.supportingField = null; + } + if ( method.getConstructorFragment() != null ) { + this.supportingConstructorFragment = new SupportingConstructorFragment( + this, + method.getConstructorFragment() + ); + } + else { + this.supportingConstructorFragment = null; + } + } + + private Field getSafeField(BuiltInFieldReference ref, Set existingFields) { + Field result = null; + String name = ref.getVariableName(); + for ( Field existingField : existingFields ) { + if ( existingField.getType().equals( ref.getType() ) ) { + // field type already exist, use that one + return existingField; + } + } + for ( Field existingField : existingFields ) { + if ( existingField.getVariableName().equals( ref.getVariableName() ) ) { + // field with name exist, however its a wrong type + name = Strings.getSafeVariableName( name, Field.getFieldNames( existingFields ) ); + } + } + if ( result == null ) { + result = new SupportingField( this, ref, name ); + } + + return result; } - public VirtualMappingMethod(HelperMethod method) { + public SupportingMappingMethod(HelperMethod method) { super( method ); this.importTypes = method.getImportTypes(); this.templateName = getTemplateNameForClass( method.getClass() ); + this.supportingField = null; + this.supportingConstructorFragment = null; } @Override @@ -66,6 +116,14 @@ public Type findType(String name) { throw new IllegalArgumentException( "No type for given name '" + name + "' found in 'importTypes'." ); } + public Field getSupportingField() { + return supportingField; + } + + public SupportingConstructorFragment getSupportingConstructorFragment() { + return supportingConstructorFragment; + } + @Override public int hashCode() { final int prime = 31; @@ -85,7 +143,7 @@ public boolean equals(Object obj) { if ( getClass() != obj.getClass() ) { return false; } - VirtualMappingMethod other = (VirtualMappingMethod) obj; + SupportingMappingMethod other = (SupportingMappingMethod) obj; if ( templateName == null ) { if ( other.templateName != null ) { return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index fc73ab4a64..dd36fb2cc0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -69,7 +69,7 @@ public Type getSourceType() { @Override public String createLocalVarName(String desiredName) { - String result = Strings.getSaveVariableName( desiredName, existingVariableNames ); + String result = Strings.getSafeVariableName( desiredName, existingVariableNames ); existingVariableNames.add( result ); return result; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 363be4d412..19544de10c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -87,7 +87,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, MappingOptions mappingOptions, boolean forgedNameBased) { String sourceParamName = Strings.decapitalize( sourceType.getName() ); - String sourceParamSafeName = Strings.getSaveVariableName( sourceParamName ); + String sourceParamSafeName = Strings.getSafeVariableName( sourceParamName ); this.parameters = new ArrayList( 1 + additionalParameters.size() ); Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java new file mode 100644 index 0000000000..691d93d0f3 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import java.util.Set; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.Strings; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * @author Sjaak Derksen + */ +public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod { + + private final Type returnType; + private final Set importTypes; + private final Type dataTypeFactoryType; + + public AbstractToXmlGregorianCalendar(TypeFactory typeFactory) { + this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); + this.dataTypeFactoryType = typeFactory.getType( DatatypeFactory.class ); + this.importTypes = asSet( + returnType, + dataTypeFactoryType, + typeFactory.getType( DatatypeConfigurationException.class ) + ); + } + + @Override + public Set getImportTypes() { + return importTypes; + } + + @Override + public Type getReturnType() { + return returnType; + } + + @Override + public BuiltInFieldReference getFieldReference() { + return new FinalField( dataTypeFactoryType, Strings.decapitalize( DatatypeFactory.class.getSimpleName() ) ); + } + + @Override + public BuiltInConstructorFragment getConstructorFragment() { + return new NewDatatypeFactoryConstructorFragment( ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java new file mode 100644 index 0000000000..ae8dbcc7cd --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +/** + * ConstructorFragments are 'code snippets' added to the constructor to initialize fields used by {@link BuiltInMethod} + */ +public interface BuiltInConstructorFragment { +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java new file mode 100644 index 0000000000..0eb15f289b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import org.mapstruct.ap.internal.model.common.Type; + +/** + * reference used by BuiltInMethod to create an additional field in the mapper. + */ +public interface BuiltInFieldReference { + + /** + * + * @return variable name of the field + */ + String getVariableName(); + + /** + * + * @return type of the field + */ + Type getType(); + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 4b1c4eeec2..8716b235e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -5,14 +5,11 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.conversion.SimpleConversion; @@ -26,6 +23,8 @@ import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in * methods are used in cases where a {@link SimpleConversion} doesn't suffice, e.g. as several lines of source code or a @@ -275,4 +274,13 @@ public boolean isUpdateMethod() { public MappingOptions getMappingOptions() { return MappingOptions.empty(); } + + public BuiltInFieldReference getFieldReference() { + return null; + } + + public BuiltInConstructorFragment getConstructorFragment() { + return null; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java index fc35f9a36b..c8cd89169b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java @@ -5,45 +5,38 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class CalendarToXmlGregorianCalendar extends BuiltInMethod { +public class CalendarToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public CalendarToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); this.parameter = new Parameter( "cal ", typeFactory.getType( Calendar.class ) ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( GregorianCalendar.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( GregorianCalendar.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( this.importTypes ); + return result; } @Override @@ -51,8 +44,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java index 88c10f8ae8..478f03ee4b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Set; @@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JavaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}. *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java index a293abe8d4..036edd83a2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java @@ -5,45 +5,38 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Date; import java.util.GregorianCalendar; import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class DateToXmlGregorianCalendar extends BuiltInMethod { +public class DateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public DateToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); this.parameter = new Parameter( "date", typeFactory.getType( Date.class ) ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( GregorianCalendar.class ), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( GregorianCalendar.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( this.importTypes ); + return result; } @Override @@ -51,8 +44,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java new file mode 100644 index 0000000000..5ce4167117 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import org.mapstruct.ap.internal.model.common.Type; + +/** + * A mapper instance field, initialized as null + * + * @author Sjaak Derksen + */ +public class FinalField implements BuiltInFieldReference { + + private final Type type; + private String variableName; + + public FinalField(Type type, String variableName) { + this.type = type; + this.variableName = variableName; + } + + @Override + public String getVariableName() { + return variableName; + } + + @Override + public Type getType() { + return type; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 09baa8b684..1ae3efe3c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -5,16 +5,15 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; - import javax.xml.bind.JAXBElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java index 90a41ab9e6..d0b06300c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java @@ -5,14 +5,8 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -21,30 +15,20 @@ /** * @author Sjaak Derksen */ -public class JodaDateTimeToXmlGregorianCalendar extends BuiltInMethod { +public class JodaDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; - private final Set importTypes; public JodaDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( - "dt", - typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN ) - ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - - this.importTypes = asSet( - returnType, - parameter.getType(), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) - ); + super( typeFactory ); + this.parameter = new Parameter("dt", typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.add( parameter.getType() ); + return result; } @Override @@ -52,8 +36,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java index 32e5c7c55a..fa87bff2db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java @@ -5,48 +5,38 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; - -import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class JodaLocalDateTimeToXmlGregorianCalendar extends BuiltInMethod { +public class JodaLocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public JodaLocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( - "dt", - typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ) - ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - + super( typeFactory ); + this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ) ); this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( DatatypeConstants.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override @@ -54,8 +44,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java index ef04de5289..e958ca952e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java @@ -5,48 +5,38 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; - -import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class JodaLocalDateToXmlGregorianCalendar extends BuiltInMethod { +public class JodaLocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public JodaLocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( - "dt", - typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ) - ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - + super( typeFactory ); + this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ) ); this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( DatatypeConstants.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override @@ -54,8 +44,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java index 771a2febb4..e9daac39c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java @@ -5,48 +5,38 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; - -import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class JodaLocalTimeToXmlGregorianCalendar extends BuiltInMethod { +public class JodaLocalTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public JodaLocalTimeToXmlGregorianCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( - "dt", - typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ) - ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - + super( typeFactory ); + this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ) ); this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( DatatypeConstants.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override @@ -54,8 +44,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java index 4c18617252..96c8a8a31b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java @@ -5,53 +5,43 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.time.LocalDate; import java.util.Set; - -import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Gunnar Morling */ -public class LocalDateToXmlGregorianCalendar extends BuiltInMethod { +public class LocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public LocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); this.parameter = new Parameter( "localDate", typeFactory.getType( LocalDate.class ) ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ), typeFactory.getType( DatatypeConstants.class ) ); } @Override - public Parameter getParameter() { - return parameter; + public Set getImportTypes() { + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override - public Type getReturnType() { - return returnType; + public Parameter getParameter() { + return parameter; } - @Override - public Set getImportTypes() { - return importTypes; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java new file mode 100644 index 0000000000..a302b59375 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +public class NewDatatypeFactoryConstructorFragment implements BuiltInConstructorFragment { + + public NewDatatypeFactoryConstructorFragment() { + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java index d8a660afb3..9f0d2ad207 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java @@ -5,49 +5,43 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ -public class StringToXmlGregorianCalendar extends BuiltInMethod { +public class StringToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public StringToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); this.parameter = new Parameter( "date", typeFactory.getType( String.class ) ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); this.importTypes = asSet( - returnType, typeFactory.getType( GregorianCalendar.class ), typeFactory.getType( SimpleDateFormat.class ), typeFactory.getType( DateFormat.class ), - typeFactory.getType( ParseException.class ), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( ParseException.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override @@ -55,11 +49,6 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } - @Override public String getContextParameter(ConversionContext conversionContext) { return conversionContext.getDateFormat() != null ? "\"" + conversionContext.getDateFormat() + "\"" : "null"; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java index 3c8706fef7..f4d8ceee9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java @@ -5,17 +5,16 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Calendar; import java.util.Set; - import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java index 49693748fd..7f270be5f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java @@ -5,17 +5,16 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Date; import java.util.Set; - import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java index 3c79036ac2..ab2db49e8a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.XMLGregorianCalendar; @@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java index 8828f2578d..d26cde0215 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.XMLGregorianCalendar; @@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java index 2e3a075268..700c19c211 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.XMLGregorianCalendar; @@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java index ba294978a5..b3eae20314 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.XMLGregorianCalendar; @@ -16,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java index d339b88cbc..1da6951b9a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java @@ -5,17 +5,16 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.time.LocalDate; import java.util.Set; - import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Gunnar Morling */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java index 97b80b987a..73ac51fa2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java @@ -5,12 +5,9 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; - import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.ConversionContext; @@ -18,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java index 43d8b08f71..7e7a0751d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Set; @@ -17,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JavaTimeConstants; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * {@link BuiltInMethod} for mapping between {@link Calendar} and {@link ZonedDateTime}. *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java index 6c64929888..27a39cd2b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java @@ -8,9 +8,6 @@ import java.time.ZonedDateTime; import java.util.GregorianCalendar; import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -21,28 +18,26 @@ /** * @author Christian Bandowski */ -public class ZonedDateTimeToXmlGregorianCalendar extends BuiltInMethod { +public class ZonedDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { private final Parameter parameter; - private final Type returnType; private final Set importTypes; public ZonedDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); this.parameter = new Parameter( "zdt ", typeFactory.getType( ZonedDateTime.class ) ); - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); this.importTypes = asSet( - returnType, parameter.getType(), - typeFactory.getType( DatatypeFactory.class ), - typeFactory.getType( GregorianCalendar.class ), - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( GregorianCalendar.class ) ); } @Override public Set getImportTypes() { - return importTypes; + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; } @Override @@ -50,8 +45,4 @@ public Parameter getParameter() { return parameter; } - @Override - public Type getReturnType() { - return returnType; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index db42a7158e..5cd44e27ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -63,12 +63,15 @@ else if ( mapper.getDecorator() != null ) { } List annotations = getMapperReferenceAnnotations(); - ListIterator iterator = mapper.getReferencedMappers().listIterator(); + ListIterator iterator = mapper.getFields().listIterator(); while ( iterator.hasNext() ) { - MapperReference reference = iterator.next(); - iterator.remove(); - iterator.add( replacementMapperReference( reference, annotations, injectionStrategy ) ); + + Field reference = iterator.next(); + if ( reference instanceof MapperReference ) { + iterator.remove(); + iterator.add( replacementMapperReference( reference, annotations, injectionStrategy ) ); + } } if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) { @@ -97,8 +100,18 @@ protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionSt decorator.setFields( replacement ); } + private List toMapperReferences(List fields) { + List mapperReferences = new ArrayList( ); + for ( Field field : fields ) { + if ( field instanceof MapperReference ) { + mapperReferences.add( (MapperReference) field ); + } + } + return mapperReferences; + } + private void buildConstructors(Mapper mapper) { - if ( !mapper.getReferencedMappers().isEmpty() ) { + if ( !toMapperReferences( mapper.getFields() ).isEmpty() ) { AnnotatedConstructor annotatedConstructor = buildAnnotatedConstructorForMapper( mapper ); if ( !annotatedConstructor.getMapperReferences().isEmpty() ) { @@ -117,10 +130,11 @@ private void buildConstructors(Mapper mapper) { } private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { + List mapperReferences = toMapperReferences( mapper.getFields() ); List mapperReferencesForConstructor = - new ArrayList( mapper.getReferencedMappers().size() ); + new ArrayList( mapperReferences.size() ); - for ( MapperReference mapperReference : mapper.getReferencedMappers() ) { + for ( MapperReference mapperReference : mapperReferences ) { if ( mapperReference.isUsed() ) { mapperReferencesForConstructor.add( (AnnotationMapperReference) mapperReference ); } @@ -130,11 +144,13 @@ private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); - return new AnnotatedConstructor( + return AnnotatedConstructor.forComponentModels( mapper.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, - additionalPublicEmptyConstructor() ); + mapper.getConstructor(), + additionalPublicEmptyConstructor() + ); } private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) { @@ -151,13 +167,16 @@ private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator dec removeDuplicateAnnotations( mapperReferencesForConstructor, mapperReferenceAnnotations ); - return new AnnotatedConstructor( + return AnnotatedConstructor.forComponentModels( decorator.getName(), mapperReferencesForConstructor, mapperReferenceAnnotations, - additionalPublicEmptyConstructor() ); + decorator.getConstructor(), + additionalPublicEmptyConstructor() + ); } + /** * Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it * does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject @@ -204,7 +223,7 @@ protected List getDelegatorReferenceAnnotations(Mapper mapper) { * @param injectionStrategyPrism strategy for injection * @return the mapper reference replacing the original one */ - protected MapperReference replacementMapperReference(Field originalReference, List annotations, + protected Field replacementMapperReference(Field originalReference, List annotations, InjectionStrategyPrism injectionStrategyPrism) { boolean finalField = injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 40b7c3a3d7..abc9828632 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -7,8 +7,10 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import javax.lang.model.element.ExecutableElement; @@ -26,6 +28,7 @@ import org.mapstruct.ap.internal.model.DefaultMapperReference; import org.mapstruct.ap.internal.model.DelegatingMethod; import org.mapstruct.ap.internal.model.EnumMappingMethod; +import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.IterableMappingMethod; import org.mapstruct.ap.internal.model.MapMappingMethod; import org.mapstruct.ap.internal.model.Mapper; @@ -33,6 +36,7 @@ import org.mapstruct.ap.internal.model.MappingBuilderContext; import org.mapstruct.ap.internal.model.MappingMethod; import org.mapstruct.ap.internal.model.StreamMappingMethod; +import org.mapstruct.ap.internal.model.SupportingConstructorFragment; import org.mapstruct.ap.internal.model.ValueMappingMethod; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -56,6 +60,8 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; +import static org.mapstruct.ap.internal.model.SupportingConstructorFragment.addAllFragmentsIn; +import static org.mapstruct.ap.internal.model.SupportingField.addAllFieldsIn; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.join; @@ -139,15 +145,26 @@ private List initReferencedMappers(TypeElement element, MapperC } private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, List methods) { - List mapperReferences = mappingContext.getMapperReferences(); + List mappingMethods = getMappingMethods( mapperConfig, methods ); - mappingMethods.addAll( mappingContext.getUsedVirtualMappings() ); + mappingMethods.addAll( mappingContext.getUsedSupportedMappings() ); mappingMethods.addAll( mappingContext.getMappingsToGenerate() ); + // handle fields + List fields = new ArrayList( mappingContext.getMapperReferences() ); + Set supportingFieldSet = new LinkedHashSet( ); + addAllFieldsIn( mappingContext.getUsedSupportedMappings(), supportingFieldSet ); + fields.addAll( supportingFieldSet ); + + // handle constructorfragments + Set constructorFragments = new LinkedHashSet(); + addAllFragmentsIn( mappingContext.getUsedSupportedMappings(), constructorFragments ); + Mapper mapper = new Mapper.Builder() .element( element ) .mappingMethods( mappingMethods ) - .mapperReferences( mapperReferences ) + .fields( fields ) + .constructorFragments( constructorFragments ) .options( options ) .versionInformation( versionInformation ) .decorator( getDecorator( element, methods, mapperConfig.implementationName(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 0866656de9..9c6f51bf14 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -25,11 +25,13 @@ import org.mapstruct.ap.internal.conversion.ConversionProvider; import org.mapstruct.ap.internal.conversion.Conversions; +import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver; import org.mapstruct.ap.internal.model.MethodReference; -import org.mapstruct.ap.internal.model.VirtualMappingMethod; +import org.mapstruct.ap.internal.model.SupportingField; +import org.mapstruct.ap.internal.model.SupportingMappingMethod; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; @@ -73,7 +75,7 @@ public class MappingResolverImpl implements MappingResolver { * Private methods which are not present in the original mapper interface and are added to map certain property * types. */ - private final Set usedVirtualMappings = new HashSet(); + private final Set usedSupportedMappings = new HashSet(); public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, TypeFactory typeFactory, List sourceModel, @@ -110,8 +112,8 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, Str } @Override - public Set getUsedVirtualMappings() { - return usedVirtualMappings; + public Set getUsedSupportedMappings() { + return usedSupportedMappings; } private MapperReference findMapperReference(Method method) { @@ -134,10 +136,10 @@ private class ResolvingAttempt { private final boolean savedPreferUpdateMapping; private final FormattingParameters formattingParameters; - // resolving via 2 steps creates the possibillity of wrong matches, first builtin method matches, - // second doesn't. In that case, the first builtin method should not lead to a virtual method + // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches, + // second doesn't. In that case, the first builtin method should not lead to a supported method // so this set must be cleared. - private final Set virtualMethodCandidates; + private final Set supportingMethodCandidates; private ResolvingAttempt(List sourceModel, Method mappingMethod, FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria) { @@ -147,7 +149,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; - this.virtualMethodCandidates = new HashSet(); + this.supportingMethodCandidates = new HashSet(); this.selectionCriteria = criteria; this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); } @@ -204,21 +206,21 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); if ( builtInMethod != null ) { builtInMethod.setAssignment( sourceRHS ); - usedVirtualMappings.addAll( virtualMethodCandidates ); + usedSupportedMappings.addAll( supportingMethodCandidates ); return builtInMethod; } // 2 step method, first: method(method(source)) referencedMethod = resolveViaMethodAndMethod( sourceType, targetType ); if ( referencedMethod != null ) { - usedVirtualMappings.addAll( virtualMethodCandidates ); + usedSupportedMappings.addAll( supportingMethodCandidates ); return referencedMethod; } // 2 step method, then: method(conversion(source)) referencedMethod = resolveViaConversionAndMethod( sourceType, targetType ); if ( referencedMethod != null ) { - usedVirtualMappings.addAll( virtualMethodCandidates ); + usedSupportedMappings.addAll( supportingMethodCandidates ); return referencedMethod; } @@ -228,7 +230,7 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { // 2 step method, finally: conversion(method(source)) conversion = resolveViaMethodAndConversion( sourceType, targetType ); if ( conversion != null ) { - usedVirtualMappings.addAll( virtualMethodCandidates ); + usedSupportedMappings.addAll( supportingMethodCandidates ); return conversion; } @@ -252,7 +254,7 @@ private Assignment resolveViaConversion(Type sourceType, Type targetType) { // add helper methods required in conversion for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) { - usedVirtualMappings.add( new VirtualMappingMethod( helperMethod ) ); + usedSupportedMappings.add( new SupportingMappingMethod( helperMethod ) ); } return conversionProvider.to( ctx ); } @@ -282,7 +284,12 @@ private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType ); if ( matchingBuiltInMethod != null ) { - virtualMethodCandidates.add( new VirtualMappingMethod( matchingBuiltInMethod.getMethod() ) ); + + Set allUsedFields = new HashSet( mapperReferences ); + SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); + SupportingMappingMethod supportingMappingMethod = + new SupportingMappingMethod( matchingBuiltInMethod.getMethod(), allUsedFields ); + supportingMethodCandidates.add( supportingMappingMethod ); ConversionContext ctx = new DefaultConversionContext( typeFactory, messager, @@ -337,7 +344,7 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { } else { // both should match; - virtualMethodCandidates.clear(); + supportingMethodCandidates.clear(); methodRefY = null; } } @@ -374,7 +381,7 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp } else { // both should match - virtualMethodCandidates.clear(); + supportingMethodCandidates.clear(); methodRefY = null; } } @@ -417,7 +424,7 @@ private Assignment resolveViaMethodAndConversion(Type sourceType, Type targetTyp } else { // both should match; - virtualMethodCandidates.clear(); + supportingMethodCandidates.clear(); conversionYRef = null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index bb923a5970..546e55f8ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -127,8 +127,8 @@ public static boolean isEmpty(String string) { return string == null || string.isEmpty(); } - public static String getSaveVariableName(String name, String... existingVariableNames) { - return getSaveVariableName( name, Arrays.asList( existingVariableNames ) ); + public static String getSafeVariableName(String name, String... existingVariableNames) { + return getSafeVariableName( name, Arrays.asList( existingVariableNames ) ); } /** @@ -141,7 +141,7 @@ public static String getSaveVariableName(String name, String... existingVariable * @return a variable name based on the given original name, not conflicting with any of the given other names or * any Java keyword; starting with a lower-case letter */ - public static String getSaveVariableName(String name, Collection existingVariableNames) { + public static String getSafeVariableName(String name, Collection existingVariableNames) { name = decapitalize( sanitizeIdentifierName( name ) ); name = joinAndCamelize( extractParts( name ) ); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl index bf5fa4a203..e3ddd51bd7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedConstructor.ftl @@ -1,20 +1,24 @@ -<#-- + <#-- Copyright MapStruct Authors. Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> -<#if publicEmptyConstructor> -public ${name}() { -} + <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotatedConstructor" --> + <#if noArgumentConstructor??> + <@includeModel object=noArgumentConstructor/> <#list annotations as annotation> <#nt><@includeModel object=annotation/> public ${name}(<#list mapperReferences as mapperReference><#list mapperReference.annotations as annotation><@includeModel object=annotation/> <@includeModel object=mapperReference.type/> ${mapperReference.variableName}<#if mapperReference_has_next>, ) { + <#if noArgumentConstructor?? && !noArgumentConstructor.fragments.empty>this(); <#list mapperReferences as mapperReference> this.${mapperReference.variableName} = ${mapperReference.variableName}; + <#list fragments as fragment> + <#nt><@includeModel object=fragment/> + } \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index 66458d3b85..4391bcb975 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> @<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property>${property}<#if property_has_next>, ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl index 4391960efd..616c4900e6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotationMapperReference.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotationMapperReference" --> <#if includeAnnotationsOnField> <#list annotations as annotation> <#nt><@includeModel object=annotation/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index f5d5c9dbc7..2d702efe2d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.BeanMappingMethod" --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#assign targetType = resultType /> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl index e592a1d14a..9c9f397c29 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DecoratorConstructor.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DecoratorConstructor" --> public ${name}() { this( new ${delegateName}() ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl index 3adf750613..e4eeddb4b5 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" --> private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>(); \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl index 5c467772e9..f27c242de1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DelegatingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DelegatingMethod" --> @Override public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) <@throws/> { <#if returnType.name != "void">return delegate.${name}( <#list parameters as param>${param.name}<#if param_has_next>, ); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl index 0caa97fa2e..3d0c9e074b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/EnumMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.EnumMappingMethod" --> @Override public <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl index ddaa403add..af4cb01f63 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Field.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Field" --> private final <@includeModel object=type/> ${variableName}; \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 16942480ff..3bdae0582a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.GeneratedType" --> <#if hasPackageName()> package ${packageName}; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl index 02af542549..86634ef13a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableCreation" --> <@compress single_line=true> <#if factoryMethod??> <@includeModel object=factoryMethod targetType=resultType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 10a4fd367c..3af75079b9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableMappingMethod" --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl index 3eef87a305..310eda210d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/LifecycleCallbackMethodReference.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.LifecycleCallbackMethodReference" --> <@compress single_line=true> <#if hasReturnType()> <@includeModel object=methodResultType /> ${targetVariableName} = diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 471c3dbe9c..1c6e6bad35 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 4dc538e296..30a830bc57 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReference" --> <@compress single_line=true> <#-- method is either internal to the mapper class, or external (via uses) declaringMapper!=null --> <#if declaringMapper??> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 97f8c0ea2b..ae4f65a81c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" --> <#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { if ( ${sourceParameter.name} == null ) { return ${returnType.null}; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NoArgumentConstructor.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NoArgumentConstructor.ftl new file mode 100644 index 0000000000..e0ae1454b7 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NoArgumentConstructor.ftl @@ -0,0 +1,13 @@ + <#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> + <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NoArgumentConstructor" --> +public ${name}() { + <#list fragments as fragment> + <#nt><@includeModel object=fragment/> + + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index 4f0632ed54..20e6f1734c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.PropertyMapping" --> <@includeModel object=assignment targetBeanName=ext.targetBeanName existingInstanceMapping=ext.existingInstanceMapping diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl index 9d61e93106..facbb5f8b7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ServicesEntry.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ServicesEntry" --> ${implementationPackage}.${implementationName} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index bb1ad1628f..3eab477941 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.StreamMappingMethod" --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable--> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl index 1dc7ec63b4..370fe7c978 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.TypeConversion" --> <@compress single_line=true> ${openExpression}<@_assignment/>${closeExpression} <#macro _assignment> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index bc3a63cdeb..5fa1c0a118 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" --> <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index 6e124ef6fd..c75942de97 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.AdderWrapper" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> if ( ${sourceReference} != null ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl index 3dd22a2cb0..edb0d3cad3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> <@lib.sourceLocalVarAssignment/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl index 94a8682a00..7364f7922e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper" --> ${ext.targetType.name}.${assignment} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index ab254e4b51..17eb9de511 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index c4ab06e7a8..4ef55f3b40 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing /> != null ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl index 927372a93c..2795dac7bc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper" --> <#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference} <#if (thrownTypes?size == 0) > <#compress> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl index 52d6efb672..53e987e476 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.LocalVarWrapper" --> <#if (thrownTypes?size == 0) > <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/> ${ext.targetWriteAccessorName} = <@_assignment/>; <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index 201e7bc70f..613e8f6abd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapper" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> <@lib.sourceLocalVarAssignment/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index 726c73cb37..122c76bc62 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index 3e0395c9ea..6e38d7fbf5 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 305cb23c97..833120b01d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.UpdateWrapper" --> <#import '../macro/CommonMacros.ftl' as lib > <@lib.handleExceptions> <#if includeSourceNullCheck> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl index 821712188c..41afd0a42e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Parameter.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Parameter" --> <@includeModel object=type asVarArgs=varArgs/> ${name} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl index 9594a665b9..7cab67b529 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl @@ -5,4 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" --> <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 1cb4fa6290..d6b2d6850c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> <@compress single_line=true> <#if wildCardExtendsBound> ? extends <@includeModel object=typeBound /> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl index c462710bd0..38cf1ad852 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.ftl @@ -5,17 +5,13 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Calendar")/> cal ) { if ( cal == null ) { return null; } - try { - <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>( cal.getTimeZone() ); - gcal.setTimeInMillis( cal.getTimeInMillis() ); - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( gcal ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + <@includeModel object=findType("GregorianCalendar")/> gcal = new <@includeModel object=findType("GregorianCalendar")/>( cal.getTimeZone() ); + gcal.setTimeInMillis( cal.getTimeInMillis() ); + return ${supportingField.variableName}.newXMLGregorianCalendar( gcal ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl index f203fce790..e97a1fc69f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("ZonedDateTime")/> ${name}(<@includeModel object=findType("Calendar")/> cal) { if ( cal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl index fa7f5985b0..7488bc9886 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.ftl @@ -5,17 +5,13 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("Date")/> date ) { if ( date == null ) { return null; } - try { - <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); - c.setTime( date ); - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); + c.setTime( date ); + return ${supportingField.variableName}.newXMLGregorianCalendar( c ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl new file mode 100644 index 0000000000..3d04bc3aec --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingField" --> +private final <@includeModel object=type/> ${variableName}; \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl index 913e8d4d3d..078be41af8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private T ${name}( <@includeModel object=findType("JAXBElement") raw=true/> element ) { if ( element == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl index 63f12392cc..aceec1f83e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.ftl @@ -5,23 +5,18 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("DateTime")/> dt ) { if ( dt == null ) { return null; } - - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( - dt.getYear(), - dt.getMonthOfYear(), - dt.getDayOfMonth(), - dt.getHourOfDay(), - dt.getMinuteOfHour(), - dt.getSecondOfMinute(), - dt.getMillisOfSecond(), - dt.getZone().getOffset( null ) / 60000 ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendar( + dt.getYear(), + dt.getMonthOfYear(), + dt.getDayOfMonth(), + dt.getHourOfDay(), + dt.getMinuteOfHour(), + dt.getSecondOfMinute(), + dt.getMillisOfSecond(), + dt.getZone().getOffset( null ) / 60000 ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl index 7fa0f17e02..19a9ce0a20 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.ftl @@ -5,23 +5,19 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDateTime")/> dt ) { if ( dt == null ) { return null; } - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( - dt.getYear(), - dt.getMonthOfYear(), - dt.getDayOfMonth(), - dt.getHourOfDay(), - dt.getMinuteOfHour(), - dt.getSecondOfMinute(), - dt.getMillisOfSecond(), - <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendar( + dt.getYear(), + dt.getMonthOfYear(), + dt.getDayOfMonth(), + dt.getHourOfDay(), + dt.getMinuteOfHour(), + dt.getSecondOfMinute(), + dt.getMillisOfSecond(), + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl index 5a41f31b82..4b9b855fbd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.ftl @@ -5,19 +5,15 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalDate")/> dt ) { if ( dt == null ) { return null; } - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( - dt.getYear(), - dt.getMonthOfYear(), - dt.getDayOfMonth(), - <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendarDate( + dt.getYear(), + dt.getMonthOfYear(), + dt.getDayOfMonth(), + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl index cee4edd7b0..43a8e67a92 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.ftl @@ -5,20 +5,17 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("org.joda.time.LocalTime")/> dt ) { if ( dt == null ) { return null; } - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarTime( - dt.getHourOfDay(), - dt.getMinuteOfHour(), - dt.getSecondOfMinute(), - dt.getMillisOfSecond(), - <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendarTime( + dt.getHourOfDay(), + dt.getMinuteOfHour(), + dt.getSecondOfMinute(), + dt.getMillisOfSecond(), + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl index 93e10b1eeb..469bbf7508 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.ftl @@ -5,20 +5,15 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> -private static <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) { +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDate")/> localDate ) { if ( localDate == null ) { return null; } - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendarDate( - localDate.getYear(), - localDate.getMonthValue(), - localDate.getDayOfMonth(), - <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED - ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendarDate( + localDate.getYear(), + localDate.getMonthValue(), + localDate.getDayOfMonth(), + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.ftl new file mode 100644 index 0000000000..1dcbbe34be --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.ftl @@ -0,0 +1,14 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingConstructorFragment" --> +try { + ${definingMethod.supportingField.variableName} = <@includeModel object=definingMethod.supportingField.type/>.newInstance(); +} +catch ( <@includeModel object=definingMethod.findType("DatatypeConfigurationException")/> ex ) { + throw new RuntimeException( ex ); +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl index 660526ac7c..00c178b142 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String date, String dateFormat ) { if ( date == null ) { return null; @@ -15,15 +16,12 @@ private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( String <@includeModel object=findType("DateFormat")/> df = new <@includeModel object=findType("SimpleDateFormat")/>( dateFormat ); <@includeModel object=findType("GregorianCalendar")/> c = new <@includeModel object=findType("GregorianCalendar")/>(); c.setTime( df.parse( date ) ); - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( c ); + return ${supportingField.variableName}.newXMLGregorianCalendar( c ); } else { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( date ); + return ${supportingField.variableName}.newXMLGregorianCalendar( date ); } } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } catch ( <@includeModel object=findType("ParseException")/> ex ) { throw new RuntimeException( ex ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl index a8b3ba2bde..cfc4ed2adf 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("Calendar")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl index bd3841c225..f4ebaab9ca 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("java.util.Date")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl index 555d6b273f..15fa82bc51 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("DateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl index c5adac02ac..3067f5dd65 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("org.joda.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl index ae640c6b81..6ace975194 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("org.joda.time.LocalDateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl index c8115f29c2..392401b3f9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("org.joda.time.LocalTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl index a526c6b99b..81141a41fb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private static <@includeModel object=findType("java.time.LocalDate")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl index f75ce8b48f..99c0237eec 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private String ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal, String dateFormat ) { if ( xcal == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl index 3c57b7923e..6a96241e34 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.ftl @@ -5,6 +5,7 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("Calendar")/> ${name}(<@includeModel object=findType("ZonedDateTime")/> dateTime) { if ( dateTime == null ) { return null; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl index a49558f7d7..b187daa957 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.ftl @@ -5,15 +5,11 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("ZonedDateTime")/> zdt ) { if ( zdt == null ) { return null; } - try { - return <@includeModel object=findType("DatatypeFactory")/>.newInstance().newXMLGregorianCalendar( <@includeModel object=findType("GregorianCalendar")/>.from( zdt ) ); - } - catch ( <@includeModel object=findType("DatatypeConfigurationException")/> ex ) { - throw new RuntimeException( ex ); - } + return ${supportingField.variableName}.newXMLGregorianCalendar( <@includeModel object=findType("GregorianCalendar")/>.from( zdt ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 575288ec97..b21db49a3e 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -76,27 +76,27 @@ public void testIsEmpty() throws Exception { @Test public void testGetSaveVariableNameWithArrayExistingVariables() throws Exception { - assertThat( Strings.getSaveVariableName( "int[]" ) ).isEqualTo( "intArray" ); - assertThat( Strings.getSaveVariableName( "Extends" ) ).isEqualTo( "extends1" ); - assertThat( Strings.getSaveVariableName( "class" ) ).isEqualTo( "class1" ); - assertThat( Strings.getSaveVariableName( "Class" ) ).isEqualTo( "class1" ); - assertThat( Strings.getSaveVariableName( "Case" ) ).isEqualTo( "case1" ); - assertThat( Strings.getSaveVariableName( "Synchronized" ) ).isEqualTo( "synchronized1" ); - assertThat( Strings.getSaveVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); + assertThat( Strings.getSafeVariableName( "int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.getSafeVariableName( "Extends" ) ).isEqualTo( "extends1" ); + assertThat( Strings.getSafeVariableName( "class" ) ).isEqualTo( "class1" ); + assertThat( Strings.getSafeVariableName( "Class" ) ).isEqualTo( "class1" ); + assertThat( Strings.getSafeVariableName( "Case" ) ).isEqualTo( "case1" ); + assertThat( Strings.getSafeVariableName( "Synchronized" ) ).isEqualTo( "synchronized1" ); + assertThat( Strings.getSafeVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); } @Test public void testGetSaveVariableNameVariablesEndingOnNumberVariables() throws Exception { - assertThat( Strings.getSaveVariableName( "prop1", "prop1" ) ).isEqualTo( "prop1_1" ); - assertThat( Strings.getSaveVariableName( "prop1", "prop1", "prop1_1" ) ).isEqualTo( "prop1_2" ); + assertThat( Strings.getSafeVariableName( "prop1", "prop1" ) ).isEqualTo( "prop1_1" ); + assertThat( Strings.getSafeVariableName( "prop1", "prop1", "prop1_1" ) ).isEqualTo( "prop1_2" ); } @Test public void testGetSaveVariableNameWithCollection() throws Exception { - assertThat( Strings.getSaveVariableName( "int[]", new ArrayList() ) ).isEqualTo( "intArray" ); - assertThat( Strings.getSaveVariableName( "Extends", new ArrayList() ) ).isEqualTo( "extends1" ); - assertThat( Strings.getSaveVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); - assertThat( Strings.getSaveVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) + assertThat( Strings.getSafeVariableName( "int[]", new ArrayList() ) ).isEqualTo( "intArray" ); + assertThat( Strings.getSafeVariableName( "Extends", new ArrayList() ) ).isEqualTo( "extends1" ); + assertThat( Strings.getSafeVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); + assertThat( Strings.getSafeVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) .isEqualTo( "propFont1" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java new file mode 100644 index 0000000000..fe52452c73 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.builtin.bean.CalendarProperty; +import org.mapstruct.ap.test.builtin.bean.DatatypeFactory; +import org.mapstruct.ap.test.builtin.bean.DateProperty; +import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarFactorizedProperty; +import org.mapstruct.ap.test.builtin.mapper.ToXmlGregCalMapper; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses( { + DatatypeFactory.class, + XmlGregorianCalendarFactorizedProperty.class, + ToXmlGregCalMapper.class, + CalendarProperty.class, + DateProperty.class + +} ) +@RunWith(AnnotationProcessorTestRunner.class) +public class DatatypeFactoryTest { + + @Test + public void testNoConflictsWithOwnDatatypeFactory() throws ParseException { + + DateProperty source1 = new DateProperty(); + source1.setProp( createDate( "31-08-1982 10:20:56" ) ); + + CalendarProperty source2 = new CalendarProperty(); + source2.setProp( createCalendar( "02.03.1999" ) ); + + XmlGregorianCalendarFactorizedProperty target1 = ToXmlGregCalMapper.INSTANCE.map( source1 ); + assertThat( target1 ).isNotNull(); + assertThat( target1.getProp() ).isNotNull(); + assertThat( target1.getProp().toString() ).isEqualTo( "1982-08-31T10:20:56.000+02:00" ); + + XmlGregorianCalendarFactorizedProperty target2 = ToXmlGregCalMapper.INSTANCE.map( source2 ); + assertThat( target2 ).isNotNull(); + assertThat( target2.getProp() ).isNotNull(); + assertThat( target2.getProp().toString() ).isEqualTo( "1999-03-02T00:00:00.000+01:00" ); + + } + + private Date createDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); + return sdf.parse( date ); + } + + private Calendar createCalendar(String cal) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd.MM.yyyy" ); + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTime( sdf.parse( cal ) ); + return gcal; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DatatypeFactory.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DatatypeFactory.java new file mode 100644 index 0000000000..648905677c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/DatatypeFactory.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +public class DatatypeFactory { + + public XmlGregorianCalendarFactorizedProperty create() { + return new XmlGregorianCalendarFactorizedProperty( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarFactorizedProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarFactorizedProperty.java new file mode 100644 index 0000000000..afbea20a79 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/XmlGregorianCalendarFactorizedProperty.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +import javax.xml.datatype.XMLGregorianCalendar; + +public class XmlGregorianCalendarFactorizedProperty { + + private XMLGregorianCalendar prop; + private String control; + + XmlGregorianCalendarFactorizedProperty( String in ) { + this.control = in; + } + + public XMLGregorianCalendar getProp() { + return prop; + } + + public void setProp( XMLGregorianCalendar prop ) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ToXmlGregCalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ToXmlGregCalMapper.java new file mode 100644 index 0000000000..9ab5dc366a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/ToXmlGregCalMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.CalendarProperty; +import org.mapstruct.ap.test.builtin.bean.DatatypeFactory; +import org.mapstruct.ap.test.builtin.bean.DateProperty; +import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarFactorizedProperty; +import org.mapstruct.factory.Mappers; + +@Mapper( uses = DatatypeFactory.class ) +public interface ToXmlGregCalMapper { + + ToXmlGregCalMapper INSTANCE = Mappers.getMapper( ToXmlGregCalMapper.class ); + + XmlGregorianCalendarFactorizedProperty map(CalendarProperty source); + + XmlGregorianCalendarFactorizedProperty map(DateProperty source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordDto.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordDto.java new file mode 100644 index 0000000000..9160b7c768 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordDto.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +import javax.xml.datatype.XMLGregorianCalendar; + +/** + * @author Sjaak Derksen + */ +public class CustomerRecordDto { + + private XMLGregorianCalendar registrationDate; + private CustomerDto customer; + + public XMLGregorianCalendar getRegistrationDate() { + return registrationDate; + } + + public void setRegistrationDate(XMLGregorianCalendar registrationDate) { + this.registrationDate = registrationDate; + } + + public CustomerDto getCustomer() { + return customer; + } + + public void setCustomer(CustomerDto customer) { + this.customer = customer; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordEntity.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordEntity.java new file mode 100644 index 0000000000..0f115fc323 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/shared/CustomerRecordEntity.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.shared; + +import java.util.Date; + +/** + * @author Sjaak Derksen + */ +public class CustomerRecordEntity { + + private Date registrationDate; + private CustomerEntity customer; + + public Date getRegistrationDate() { + return registrationDate; + } + + public void setRegistrationDate(Date registrationDate) { + this.registrationDate = registrationDate; + } + + public CustomerEntity getCustomer() { + return customer; + } + + public void setCustomer(CustomerEntity customer) { + this.customer = customer; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java new file mode 100644 index 0000000000..a7f9e8a8b2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; + +/** + * @author Kevin Grüneberg + */ +@Mapper(componentModel = "spring", + uses = { CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class }, + injectionStrategy = InjectionStrategy.CONSTRUCTOR, + disableSubMappingMethodsGeneration = true) +public interface CustomerRecordSpringConstructorMapper { + + CustomerRecordDto asTarget(CustomerRecordEntity customerRecordEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java index 41335e1e6f..267ad8dd33 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -5,13 +5,22 @@ */ package org.mapstruct.ap.test.injectionstrategy.spring.constructor; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; @@ -33,10 +42,13 @@ * @author Kevin Grüneberg */ @WithClasses( { + CustomerRecordDto.class, + CustomerRecordEntity.class, CustomerDto.class, CustomerEntity.class, Gender.class, GenderDto.class, + CustomerRecordSpringConstructorMapper.class, CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class, ConstructorSpringConfig.class @@ -47,13 +59,26 @@ @Configuration public class SpringConstructorMapperTest { + private static TimeZone originalTimeZone; + @Rule public final GeneratedSource generatedSource = new GeneratedSource(); @Autowired - private CustomerSpringConstructorMapper customerMapper; + private CustomerRecordSpringConstructorMapper customerRecordMapper; private ConfigurableApplicationContext context; + @BeforeClass + public static void setDefaultTimeZoneToCet() { + originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); + } + + @AfterClass + public static void restoreOriginalTimeZone() { + TimeZone.setDefault( originalTimeZone ); + } + @Before public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); @@ -68,19 +93,25 @@ public void springDown() { } @Test - public void shouldConvertToTarget() { + public void shouldConvertToTarget() throws Exception { // given CustomerEntity customerEntity = new CustomerEntity(); customerEntity.setName( "Samuel" ); customerEntity.setGender( Gender.MALE ); + CustomerRecordEntity customerRecordEntity = new CustomerRecordEntity(); + customerRecordEntity.setCustomer( customerEntity ); + customerRecordEntity.setRegistrationDate( createDate( "31-08-1982 10:20:56" ) ); // when - CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + CustomerRecordDto customerRecordDto = customerRecordMapper.asTarget( customerRecordEntity ); // then - assertThat( customerDto ).isNotNull(); - assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); - assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + assertThat( customerRecordDto ).isNotNull(); + assertThat( customerRecordDto.getCustomer() ).isNotNull(); + assertThat( customerRecordDto.getCustomer().getName() ).isEqualTo( "Samuel" ); + assertThat( customerRecordDto.getCustomer().getGender() ).isEqualTo( GenderDto.M ); + assertThat( customerRecordDto.getRegistrationDate() ).isNotNull(); + assertThat( customerRecordDto.getRegistrationDate().toString() ).isEqualTo( "1982-08-31T10:20:56.000+02:00" ); } @Test @@ -91,4 +122,10 @@ public void shouldHaveConstructorInjection() { .contains( "@Autowired" + lineSeparator() + " public CustomerSpringConstructorMapperImpl(GenderSpringConstructorMapper" ); } + + private Date createDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); + return sdf.parse( date ); + } + } From 04576de1d1689aac439c092164c1fef7175e57c3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Aug 2018 19:58:02 +0200 Subject: [PATCH 0270/1006] #1552 Stop processing source parameters for unprocessed defined properties when a mapping is found --- .../ap/internal/model/BeanMappingMethod.java | 2 + .../ap/test/bugs/_1552/Issue1552Mapper.java | 32 +++++++++++++ .../ap/test/bugs/_1552/Issue1552Test.java | 46 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1552/Target.java | 43 +++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 05f4e9b1cf..a44f1a90a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -318,6 +318,8 @@ private void handleUnprocessedDefinedTargets() { unprocessedSourceProperties.remove( propertyName ); iterator.remove(); propertyMappings.add( propertyMapping ); + // If we found a mapping for the unprocessed property then stop + break; } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java new file mode 100644 index 0000000000..ca97c0f0b4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Mapper.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1552; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1552Mapper { + + Issue1552Mapper INSTANCE = Mappers.getMapper( Issue1552Mapper.class ); + + @Mappings({ + @Mapping(target = "first.value", constant = "constant"), + @Mapping(target = "second.value", source = "sourceTwo") + }) + Target twoArgsWithConstant(String sourceOne, String sourceTwo); + + @Mappings({ + @Mapping(target = "first.value", expression = "java(\"expression\")"), + @Mapping(target = "second.value", source = "sourceTwo") + }) + Target twoArgsWithExpression(String sourceOne, String sourceTwo); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java new file mode 100644 index 0000000000..c06a00bb05 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1552; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue1552Mapper.class, + Target.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1552") +public class Issue1552Test { + + @Test + public void shouldCompile() { + Target target = Issue1552Mapper.INSTANCE.twoArgsWithConstant( "first", "second" ); + + assertThat( target ).isNotNull(); + assertThat( target.getFirst() ).isNotNull(); + assertThat( target.getFirst().getValue() ).isEqualTo( "constant" ); + assertThat( target.getSecond() ).isNotNull(); + assertThat( target.getSecond().getValue() ).isEqualTo( "second" ); + + + target = Issue1552Mapper.INSTANCE.twoArgsWithExpression( "third", "fourth" ); + + assertThat( target ).isNotNull(); + assertThat( target.getFirst() ).isNotNull(); + assertThat( target.getFirst().getValue() ).isEqualTo( "expression" ); + assertThat( target.getSecond() ).isNotNull(); + assertThat( target.getSecond().getValue() ).isEqualTo( "fourth" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java new file mode 100644 index 0000000000..93c80ebd1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Target.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1552; + +/** + * @author Filip Hrisafov + */ +public class Target { + private Inner first; + private Inner second; + + public Inner getFirst() { + return first; + } + + public void setFirst(Inner first) { + this.first = first; + } + + public Inner getSecond() { + return second; + } + + public void setSecond(Inner second) { + this.second = second; + } + + public static class Inner { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} From ded8d88c73c18323eae421e92c14949dccbd78be Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Aug 2018 21:58:22 +0200 Subject: [PATCH 0271/1006] #1578 Rename isBuilderSetter to isFluentSetter in the DefaultAccessorNamingStrategy --- .../org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java | 6 +++--- .../mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 8f82c8f896..908963f5da 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -83,10 +83,10 @@ public boolean isGetterMethod(ExecutableElement method) { public boolean isSetterMethod(ExecutableElement method) { String methodName = method.getSimpleName().toString(); - return methodName.startsWith( "set" ) && methodName.length() > 3 || isBuilderSetter( method ); + return methodName.startsWith( "set" ) && methodName.length() > 3 || isFluentSetter( method ); } - protected boolean isBuilderSetter(ExecutableElement method) { + protected boolean isFluentSetter(ExecutableElement method) { return method.getParameters().size() == 1 && !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && !isAdderWithUpperCase4thCharacter( method ) && @@ -159,7 +159,7 @@ public String getPropertyName(ExecutableElement getterOrSetterMethod) { if ( methodName.startsWith( "is" ) || methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); } - else if ( isBuilderSetter( getterOrSetterMethod ) ) { + else if ( isFluentSetter( getterOrSetterMethod ) ) { return methodName; } return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index 98d34407d6..cc1d66895d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -17,7 +17,7 @@ public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrategy { @Override - protected boolean isBuilderSetter(ExecutableElement method) { - return super.isBuilderSetter( method ) && !method.getSimpleName().toString().equals( "from" ); + protected boolean isFluentSetter(ExecutableElement method) { + return super.isFluentSetter( method ) && !method.getSimpleName().toString().equals( "from" ); } } From bd2c206f7f7fb8eadb62b368694c1e4cea4aff6c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Wed, 29 Aug 2018 21:11:22 +0200 Subject: [PATCH 0272/1006] #1590 ArrayList missing as import for NVMS.RETURN_DEFAULT (#1598) --- ...perForCollectionsAndMapsWithNullCheck.java | 3 ++ .../mapstruct/ap/test/bugs/_1590/Book.java | 9 ++++ .../ap/test/bugs/_1590/BookMapper.java | 21 ++++++++++ .../ap/test/bugs/_1590/BookShelf.java | 20 +++++++++ .../ap/test/bugs/_1590/BookShelfMapper.java | 21 ++++++++++ .../ap/test/bugs/_1590/Issue1590Test.java | 41 +++++++++++++++++++ 6 files changed, 115 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelf.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelfMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index f38e90b71c..9d87952434 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -63,6 +63,9 @@ public Set getImportTypes() { if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) { imported.addAll( getNullCheckLocalVarType().getImportTypes() ); } + if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) { + imported.add( targetType.getImplementationType() ); + } return imported; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java new file mode 100644 index 0000000000..53355ee603 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1590; + +public class Book { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookMapper.java new file mode 100644 index 0000000000..31acd1885a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1590; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BookMapper { + + BookMapper INSTANCE = Mappers.getMapper( BookMapper.class ); + + Book map(Book book); + + List map(List books); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelf.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelf.java new file mode 100644 index 0000000000..056b409d4d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelf.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1590; + +import java.util.List; + +public class BookShelf { + private List books; + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelfMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelfMapper.java new file mode 100644 index 0000000000..46f53f6469 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/BookShelfMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1590; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = BookMapper.class, + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) +public interface BookShelfMapper { + + BookShelfMapper INSTANCE = Mappers.getMapper( BookShelfMapper.class ); + + BookShelf map(BookShelf bookShelf); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java new file mode 100644 index 0000000000..30613d1a27 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1590; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ + BookMapper.class, + BookShelfMapper.class, + Book.class, + BookShelf.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1590") +public class Issue1590Test { + + @Test + public void shouldTestMappingLocalDates() { + BookShelf source = new BookShelf(); + source.setBooks( Arrays.asList( new Book() ) ); + + BookShelf target = BookShelfMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getBooks() ).isNotNull(); + } +} From 3da85bc1787c9001a8118d3b60c4f469fcfb6f7e Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 2 Sep 2018 22:19:21 +0200 Subject: [PATCH 0273/1006] #1596 Missing builder type import (#1602) --- .../org/mapstruct/ap/internal/model/BeanMappingMethod.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a44f1a90a4..f29c876c45 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -882,6 +882,9 @@ public Set getImportTypes() { types.addAll( getResultType().getEffectiveType().getImportTypes() ); } + if ( getResultType().getBuilderType() != null ) { + types.add( getResultType().getBuilderType().getOwningType() ); + } return types; } From 13aa94742183fc5eedb3c991b55336d1b63a68dc Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Wed, 12 Sep 2018 16:26:09 +0200 Subject: [PATCH 0274/1006] #1569 Reproducer missing Immubable buildertype import (#1605) --- .../tests/FullFeatureCompilationTest.java | 3 + .../test/resources/fullFeatureTest/pom.xml | 2 + .../bugs/_1596/Issue1569BuilderProvider.java | 39 ++++ .../ap/test/bugs/_1596/Issue1596Test.java | 53 +++++ .../ap/test/bugs/_1596/ItemMapper.java | 20 ++ .../test/bugs/_1596/domain/ImmutableItem.java | 162 ++++++++++++++++ .../ap/test/bugs/_1596/domain/Item.java | 10 + .../test/bugs/_1596/dto/ImmutableItemDTO.java | 182 ++++++++++++++++++ .../ap/test/bugs/_1596/dto/ItemDTO.java | 10 + 9 files changed, 481 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/ItemMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/ImmutableItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/Item.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ImmutableItemDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ItemDTO.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java index 76d5bd0a08..ba73357dc9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java @@ -53,6 +53,9 @@ public static final class CompilationExclusionCliEnhancer implements CommandLine public Collection getAdditionalCommandLineArguments(ProcessorType processorType) { List additionalExcludes = new ArrayList<>(); + // SPI not working correctly here.. (not picked up) + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" ); + switch ( processorType ) { case ORACLE_JAVA_6: additionalExcludes.add( "org/mapstruct/ap/test/abstractclass/generics/*.java" ); diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 7a1654c45c..9a7b85426f 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -24,6 +24,7 @@ x x x + x @@ -43,6 +44,7 @@ ${additionalExclude1} ${additionalExclude2} ${additionalExclude3} + ${additionalExclude4} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java new file mode 100644 index 0000000000..c3df534431 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596; + +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; + +public class Issue1569BuilderProvider extends ImmutablesBuilderProvider implements BuilderProvider { + + @Override + protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + Name name = typeElement.getQualifiedName(); + if ( name.toString().endsWith( ".Item" ) ) { + BuilderInfo info = findBuilderInfoForImmutables( typeElement, elements, types ); + if ( info != null ) { + return info; + } + } + + return super.findBuilderInfo( typeElement, elements, types ); + } + + protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, Elements elements, Types types) { + TypeElement immutableElement = asImmutableElement( typeElement, elements ); + if ( immutableElement != null ) { + return super.findBuilderInfo( immutableElement, elements, types ); + } + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java new file mode 100644 index 0000000000..f92648b219 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.test.bugs._1596.domain.ImmutableItem; +import org.mapstruct.ap.test.bugs._1596.domain.Item; +import org.mapstruct.ap.test.bugs._1596.dto.ImmutableItemDTO; +import org.mapstruct.ap.test.bugs._1596.dto.ItemDTO; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.WithServiceImplementations; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ + ItemMapper.class, + Item.class, + ImmutableItem.class, + ItemDTO.class, + ImmutableItemDTO.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1596") +@WithServiceImplementations( { + @WithServiceImplementation( provides = BuilderProvider.class, value = Issue1569BuilderProvider.class), + @WithServiceImplementation( provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) +}) +public class Issue1596Test { + + @Test + public void shouldIncludeBuildeType() { + + ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); + + Item target = ItemMapper.INSTANCE.map( item ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/ItemMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/ItemMapper.java new file mode 100644 index 0000000000..00f647148b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/ItemMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596; + +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._1596.domain.Item; +import org.mapstruct.ap.test.bugs._1596.dto.ItemDTO; +import org.mapstruct.factory.Mappers; + +@Mapper( builder = @Builder) +public abstract class ItemMapper { + + public static final ItemMapper INSTANCE = Mappers.getMapper( ItemMapper.class ); + + public abstract Item map(ItemDTO itemDTO); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/ImmutableItem.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/ImmutableItem.java new file mode 100644 index 0000000000..f0ea474287 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/ImmutableItem.java @@ -0,0 +1,162 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596.domain; + +import java.util.ArrayList; +import java.util.List; + +/** + * Immutable implementation of {@link Item}. + *

      + * Use the builder to create immutable instances: + * {@code ImmutableItem.builder()}. + */ +@SuppressWarnings({"all"}) +public final class ImmutableItem extends Item { + private final String id; + + private ImmutableItem(String id) { + this.id = id; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * Copy the current immutable object by setting a value for the {@link Item#getId() id} attribute. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * @param value A new value for id + * @return A modified copy of the {@code this} object + */ + public final ImmutableItem withId(String value) { + if (this.id == value) return this; + return new ImmutableItem(value); + } + + /** + * This instance is equal to all instances of {@code ImmutableItem} that have equal attribute values. + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if (this == another) return true; + return another instanceof ImmutableItem + && equalTo((ImmutableItem) another); + } + + private boolean equalTo(ImmutableItem another) { + return id.equals(another.id); + } + + /** + * Computes a hash code from attributes: {@code id}. + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += (h << 5) + id.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code Item} with attribute values. + * @return A string representation of the value + */ + @Override + public String toString() { + return "Item{" + + "id=" + id + + "}"; + } + + /** + * Creates an immutable copy of a {@link Item} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * @param instance The instance to copy + * @return A copied immutable Item instance + */ + public static ImmutableItem copyOf(Item instance) { + if (instance instanceof ImmutableItem) { + return (ImmutableItem) instance; + } + return ImmutableItem.builder() + .from(instance) + .build(); + } + + /** + * Creates a builder for {@link ImmutableItem ImmutableItem}. + * @return A new ImmutableItem builder + */ + public static ImmutableItem.Builder builder() { + return new ImmutableItem.Builder(); + } + + /** + * Builds instances of type {@link ImmutableItem ImmutableItem}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static final class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + + private Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code Item} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * @param instance The instance from which to copy values + * @return {@code this} builder for use in a chained invocation + */ + public final Builder from(Item instance) { + id(instance.getId()); + return this; + } + + /** + * Initializes the value for the {@link Item#getId() id} attribute. + * @param id The value for id + * @return {@code this} builder for use in a chained invocation + */ + public final Builder id(String id) { + this.id = id; + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Builds a new {@link ImmutableItem ImmutableItem}. + * @return An immutable instance of Item + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItem build() { + if (initBits != 0) { + throw new IllegalStateException(formatRequiredAttributesMessage()); + } + return new ImmutableItem(id); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList(); + if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); + return "Cannot build Item, some of required attributes are not set " + attributes; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/Item.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/Item.java new file mode 100644 index 0000000000..6c5be03818 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/domain/Item.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596.domain; + +public abstract class Item { + public abstract String getId(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ImmutableItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ImmutableItemDTO.java new file mode 100644 index 0000000000..4d84af3479 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ImmutableItemDTO.java @@ -0,0 +1,182 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596.dto; + +import java.util.ArrayList; +import java.util.List; + +/** + * Immutable implementation of {@link ItemDTO}. + *

      + * Use the builder to create immutable instances: + * {@code ImmutableItemDTO.builder()}. + */ +@SuppressWarnings({ "all" }) +public final class ImmutableItemDTO extends ItemDTO { + private final String id; + + private ImmutableItemDTO(String id) { + this.id = id; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * Copy the current immutable object by setting a value for the {@link ItemDTO#getId() id} attribute. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * + * @param value A new value for id + * + * @return A modified copy of the {@code this} object + */ + public final ImmutableItemDTO withId(String value) { + if ( this.id == value ) { + return this; + } + return new ImmutableItemDTO( value ); + } + + /** + * This instance is equal to all instances of {@code ImmutableItemDTO} that have equal attribute values. + * + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if ( this == another ) { + return true; + } + return another instanceof ImmutableItemDTO + && equalTo( (ImmutableItemDTO) another ); + } + + private boolean equalTo(ImmutableItemDTO another) { + return id.equals( another.id ); + } + + /** + * Computes a hash code from attributes: {@code id}. + * + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += ( h << 5 ) + id.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code ItemDTO} with attribute values. + * + * @return A string representation of the value + */ + @Override + public String toString() { + return "ItemDTO{" + + "id=" + id + + "}"; + } + + /** + * Creates an immutable copy of a {@link ItemDTO} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * + * @param instance The instance to copy + * + * @return A copied immutable ItemDTO instance + */ + public static ImmutableItemDTO copyOf(ItemDTO instance) { + if ( instance instanceof ImmutableItemDTO ) { + return (ImmutableItemDTO) instance; + } + return ImmutableItemDTO.builder() + .from( instance ) + .build(); + } + + /** + * Creates a builder for {@link ImmutableItemDTO ImmutableItemDTO}. + * + * @return A new ImmutableItemDTO builder + */ + public static ImmutableItemDTO.Builder builder() { + return new ImmutableItemDTO.Builder(); + } + + /** + * Builds instances of type {@link ImmutableItemDTO ImmutableItemDTO}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static final class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + + private Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code ItemDTO} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * + * @param instance The instance from which to copy values + * + * @return {@code this} builder for use in a chained invocation + */ + public final Builder from(ItemDTO instance) { + id( instance.getId() ); + return this; + } + + /** + * Initializes the value for the {@link ItemDTO#getId() id} attribute. + * + * @param id The value for id + * + * @return {@code this} builder for use in a chained invocation + */ + public final Builder id(String id) { + this.id = id; + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Builds a new {@link ImmutableItemDTO ImmutableItemDTO}. + * + * @return An immutable instance of ItemDTO + * + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItemDTO build() { + if ( initBits != 0 ) { + throw new IllegalStateException( formatRequiredAttributesMessage() ); + } + return new ImmutableItemDTO( id ); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList(); + if ( ( initBits & INIT_BIT_ID ) != 0 ) { + attributes.add( "id" ); + } + return "Cannot build ItemDTO, some of required attributes are not set " + attributes; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ItemDTO.java new file mode 100644 index 0000000000..9cbed4ae54 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/dto/ItemDTO.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1596.dto; + +public abstract class ItemDTO { + public abstract String getId(); +} From 5a4990c47410df958db84dd9bb333c1d967b1fad Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 22 Sep 2018 14:06:53 +0200 Subject: [PATCH 0275/1006] #1456 apply source presence tracking recursively (in nested source) --- copyright.txt | 1 + .../ap/internal/model/PropertyMapping.java | 14 ++++++ .../spi/PresenceCheckNestedObjectsTest.java | 50 +++++++++++++++++++ .../source/presencecheck/spi/Referee.java | 18 +++++++ .../spi/SoccerTeamMapperNestedObjects.java | 27 ++++++++++ .../presencecheck/spi/SoccerTeamSource.java | 18 +++++++ .../SoccerTeamTargetWithPresenceCheck.java | 50 +++++++++++++++++++ 7 files changed, 178 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Referee.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapperNestedObjects.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTargetWithPresenceCheck.java diff --git a/copyright.txt b/copyright.txt index c66607498e..8b6317dc76 100644 --- a/copyright.txt +++ b/copyright.txt @@ -7,6 +7,7 @@ Christian Bandowski - https://github.com/chris922 Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman +Cindy Wang - https://github.com/birdfriend Cornelius Dirmeier - https://github.com/cornzy David Feinblum - https://github.com/dvfeinblum Darren Rambaud - https://github.com/xyzst diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 7c632f1f8e..09627b5c49 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -563,6 +563,20 @@ private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { if ( propertyEntry.getPresenceChecker() != null ) { sourcePresenceChecker = sourceParam.getName() + "." + propertyEntry.getPresenceChecker().getSimpleName() + "()"; + + String variableName = sourceParam.getName() + "." + + propertyEntry.getReadAccessor().getSimpleName() + "()"; + for (int i = 1; i < sourceReference.getPropertyEntries().size(); i++) { + PropertyEntry entry = sourceReference.getPropertyEntries().get( i ); + if (entry.getPresenceChecker() != null && entry.getReadAccessor() != null) { + sourcePresenceChecker += " && " + variableName + " != null && " + + variableName + "." + entry.getPresenceChecker().getSimpleName() + "()"; + variableName = variableName + "." + entry.getReadAccessor().getSimpleName() + "()"; + } + else { + break; + } + } } } return sourcePresenceChecker; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java new file mode 100644 index 0000000000..1f39810831 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertFalse; + +/** + * Test for correct handling of source presence checks for nested objects. + * + * @author Cindy Wang + */ +@WithClasses({ + SoccerTeamMapperNestedObjects.class, + SoccerTeamSource.class, + GoalKeeper.class, + SoccerTeamTargetWithPresenceCheck.class, + Referee.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class PresenceCheckNestedObjectsTest { + + @Test + public void testNestedWithSourcesAbsentOnNestingLevel() { + + SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); + GoalKeeper goalKeeper = new GoalKeeper(); + goalKeeper.setHasName( false ); + goalKeeper.setName( "shouldNotBeUsed" ); + soccerTeamSource.setGoalKeeper( goalKeeper ); + soccerTeamSource.setHasRefereeName( false ); + soccerTeamSource.setRefereeName( "shouldNotBeUsed" ); + + SoccerTeamTargetWithPresenceCheck target = SoccerTeamMapperNestedObjects.INSTANCE.mapNested( soccerTeamSource ); + + assertThat( target.getGoalKeeperName() ).isNull(); + assertFalse( target.hasGoalKeeperName() ); + assertThat( target.getReferee() ).isNotNull(); + assertThat( target.getReferee().getName() ).isNull(); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Referee.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Referee.java new file mode 100644 index 0000000000..d108486894 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/Referee.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +public class Referee { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapperNestedObjects.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapperNestedObjects.java new file mode 100644 index 0000000000..f804d957dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamMapperNestedObjects.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Cindy Wang + */ +@Mapper +public interface SoccerTeamMapperNestedObjects { + SoccerTeamMapperNestedObjects INSTANCE = Mappers.getMapper( SoccerTeamMapperNestedObjects.class ); + + @Mappings({ + @Mapping(target = "players", ignore = true), + @Mapping(target = "goalKeeperName", source = "goalKeeper.name"), + @Mapping(target = "referee.name", source = "refereeName") + }) + SoccerTeamTargetWithPresenceCheck mapNested( SoccerTeamSource in ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java index d2462acf0e..35ecdb8fe6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamSource.java @@ -18,6 +18,9 @@ public class SoccerTeamSource { private GoalKeeper goalKeeper; private boolean hasGoalKeeper = true; + private String refereeName; + private boolean hasRefereeName; + public boolean hasPlayers() { return hasPlayers; } @@ -50,4 +53,19 @@ public void setHasGoalKeeper(boolean hasGoalKeeper) { this.hasGoalKeeper = hasGoalKeeper; } + public String getRefereeName() { + return refereeName; + } + + public void setRefereeName(String refereeName) { + this.refereeName = refereeName; + } + + public boolean hasRefereeName() { + return hasRefereeName; + } + + public void setHasRefereeName(boolean hasRefereeName) { + this.hasRefereeName = hasRefereeName; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTargetWithPresenceCheck.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTargetWithPresenceCheck.java new file mode 100644 index 0000000000..1e005904e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTargetWithPresenceCheck.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import java.util.List; + +/** + * @author Cindy Wang + */ +public class SoccerTeamTargetWithPresenceCheck { + + private List players; + private String goalKeeperName; + private Referee referee; + + private boolean hasPlayers = false; + private boolean hasGoalKeeperName = false; + + public List getPlayers() { + return players; + } + + public String getGoalKeeperName() { + return goalKeeperName; + } + + public void setGoalKeeperName(String goalKeeperName) { + this.goalKeeperName = goalKeeperName; + hasGoalKeeperName = true; + } + + public boolean hasPlayers() { + return hasPlayers; + } + + public boolean hasGoalKeeperName() { + return hasGoalKeeperName; + } + + public Referee getReferee() { + return referee; + } + + public void setReferee(Referee referee) { + this.referee = referee; + } +} From 30c2dadec7b84895498db7f99308f169f2f516e4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 24 Sep 2018 22:23:34 +0200 Subject: [PATCH 0276/1006] #1561 add support for adders in combination with streams - Extended Type#getAlternativeTargetAccessors to recognize stream read accessors for which no corresponding setter exists (there is only an add method) - Extended SourceRHS#getSourceTypeForMatching to return the correct source type for streams too - Add StreamAdderWrapper to map Stream -> Adder - Extended PropertyMapping$PropertyMappingBuilder#assignToPlainViaAdder to return StreamAdderWrapper if source type is stream --- .../ap/internal/model/PropertyMapping.java | 5 + .../model/assignment/StreamAdderWrapper.java | 67 ++++++++++++++ .../ap/internal/model/common/SourceRHS.java | 12 ++- .../ap/internal/model/common/Type.java | 92 ++++++++++++------- .../model/assignment/StreamAdderWrapper.ftl | 14 +++ .../bugs/_1561/java8/Issue1561Mapper.java | 24 +++++ .../test/bugs/_1561/java8/Issue1561Test.java | 45 +++++++++ .../ap/test/bugs/_1561/java8/Source.java | 25 +++++ .../ap/test/bugs/_1561/java8/Target.java | 26 ++++++ 9 files changed, 277 insertions(+), 33 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 09627b5c49..54da3723c3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -25,6 +25,7 @@ import org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; +import org.mapstruct.ap.internal.model.assignment.StreamAdderWrapper; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -438,6 +439,10 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { if ( result.getSourceType().isCollectionType() ) { result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName ); } + else if ( result.getSourceType().isStreamType() ) { + result = new StreamAdderWrapper( + result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName ); + } else { // Possibly adding null to a target collection. So should be surrounded by an null check. result = new SetterWrapper( result, method.getThrownTypes(), ALWAYS, isFieldAssignment(), targetType ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java new file mode 100644 index 0000000000..6c38f05a24 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.assignment; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Nouns; + +import static org.mapstruct.ap.internal.util.Collections.first; + +/** + * Wraps the assignment in a target setter. + * + * @author Sebastian Haberey + */ +public class StreamAdderWrapper extends AssignmentWrapper { + + private final List thrownTypesToExclude; + private final Type adderType; + + public StreamAdderWrapper(Assignment rhs, + List thrownTypesToExclude, + boolean fieldAssignment, + String targetPropertyName ) { + super( rhs, fieldAssignment ); + this.thrownTypesToExclude = thrownTypesToExclude; + String desiredName = Nouns.singularize( targetPropertyName ); + rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); + adderType = first( getSourceType().determineTypeArguments( Stream.class ) ); + } + + @Override + public List getThrownTypes() { + List parentThrownTypes = super.getThrownTypes(); + List result = new ArrayList( parentThrownTypes ); + for ( Type thrownTypeToExclude : thrownTypesToExclude ) { + for ( Type parentExceptionType : parentThrownTypes ) { + if ( parentExceptionType.isAssignableTo( thrownTypeToExclude ) ) { + result.remove( parentExceptionType ); + } + } + } + return result; + } + + public Type getAdderType() { + return adderType; + } + + @Override + public Set getImportTypes() { + Set imported = new HashSet(); + imported.addAll( super.getImportTypes() ); + imported.add( adderType.getTypeBound() ); + return imported; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index dd36fb2cc0..fddf0a4b19 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.stream.Stream; import org.mapstruct.ap.internal.util.Strings; @@ -124,8 +125,15 @@ public String getSourceErrorMessagePart() { * @return the source type to be used in the matching process. */ public Type getSourceTypeForMatching() { - return useElementAsSourceTypeForMatching && sourceType.isCollectionType() ? - first( sourceType.determineTypeArguments( Collection.class ) ) : sourceType; + if ( useElementAsSourceTypeForMatching ) { + if ( sourceType.isCollectionType() ) { + return first( sourceType.determineTypeArguments( Collection.class ) ); + } + else if ( sourceType.isStreamType() ) { + return first( sourceType.determineTypeArguments( Stream.class ) ); + } + } + return sourceType; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index d3f4e2aee0..997277ab55 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Stream; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -33,6 +34,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.Filters; +import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.Nouns; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; @@ -625,46 +627,67 @@ private List getAllAccessors() { */ private Accessor getAdderForType(Type collectionProperty, String pluralPropertyName) { - List candidates = new ArrayList(); - if ( collectionProperty.isCollectionType ) { - - // this is a collection, so this can be done always - TypeMirror typeArg = first( collectionProperty.determineTypeArguments( Iterable.class ) ).getTypeBound() - .getTypeMirror(); - // now, look for a method that - // 1) starts with add, - // 2) and has typeArg as one and only arg - List adderList = getAdders(); - for ( Accessor adder : adderList ) { - ExecutableElement executable = adder.getExecutable(); - if ( executable == null ) { - // it should not be null, but to be safe - continue; - } - VariableElement arg = executable.getParameters().get( 0 ); - if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { - candidates.add( adder ); - } - } + List candidates; + + if ( collectionProperty.isCollectionType() ) { + candidates = getAccessorCandidates( collectionProperty, Iterable.class ); } + else if ( collectionProperty.isStreamType() ) { + candidates = getAccessorCandidates( collectionProperty, Stream.class ); + } + else { + return null; + } + if ( candidates.isEmpty() ) { return null; } - else if ( candidates.size() == 1 ) { + + if ( candidates.size() == 1 ) { return candidates.get( 0 ); } - else { - for ( Accessor candidate : candidates ) { - String elementName = accessorNaming.getElementNameForAdder( candidate ); - if ( elementName != null && elementName.equals( Nouns.singularize( pluralPropertyName ) ) ) { - return candidate; - } + + for ( Accessor candidate : candidates ) { + String elementName = accessorNaming.getElementNameForAdder( candidate ); + if ( elementName != null && elementName.equals( Nouns.singularize( pluralPropertyName ) ) ) { + return candidate; } } return null; } + /** + * Returns all accessor candidates that start with "add" and have exactly one argument + * whose type matches the collection or stream property's type argument. + * + * @param property the collection or stream property + * @param superclass the superclass to use for type argument lookup + * + * @return accessor candidates + */ + private List getAccessorCandidates(Type property, Class superclass) { + TypeMirror typeArg = first( property.determineTypeArguments( superclass ) ).getTypeBound() + .getTypeMirror(); + // now, look for a method that + // 1) starts with add, + // 2) and has typeArg as one and only arg + List adderList = getAdders(); + List candidateList = new ArrayList(); + for ( Accessor adder : adderList ) { + ExecutableElement executable = adder.getExecutable(); + if ( executable == null ) { + // it should not be null, but to be safe + continue; + } + VariableElement arg = executable.getParameters().get( 0 ); + if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { + candidateList.add( adder ); + } + } + return candidateList; + } + /** * getSetters * @@ -716,7 +739,7 @@ private List getAlternativeTargetAccessors() { // an accessor could substitute the setter in that case and act as setter. // (assuming it is initialized) for ( Accessor readAccessor : readAccessors ) { - if ( isCollectionOrMap( readAccessor ) && + if ( isCollectionOrMapOrStream( readAccessor ) && !correspondingSetterMethodExists( readAccessor, setterMethods ) ) { result.add( readAccessor ); } @@ -745,14 +768,21 @@ private boolean correspondingSetterMethodExists(Accessor getterMethod, return false; } - private boolean isCollectionOrMap(Accessor getterMethod) { - return isCollection( getterMethod.getAccessedType() ) || isMap( getterMethod.getAccessedType() ); + private boolean isCollectionOrMapOrStream(Accessor getterMethod) { + return isCollection( getterMethod.getAccessedType() ) || isMap( getterMethod.getAccessedType() ) || + isStream( getterMethod.getAccessedType() ); } private boolean isCollection(TypeMirror candidate) { return isSubType( candidate, Collection.class ); } + private boolean isStream(TypeMirror candidate) { + TypeElement streamTypeElement = elementUtils.getTypeElement( JavaStreamConstants.STREAM_FQN ); + TypeMirror streamType = streamTypeElement == null ? null : typeUtils.erasure( streamTypeElement.asType() ); + return streamType != null && typeUtils.isSubtype( candidate, streamType ); + } + private boolean isMap(TypeMirror candidate) { return isSubType( candidate, Map.class ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl new file mode 100644 index 0000000000..1a308844c1 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl @@ -0,0 +1,14 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.StreamAdderWrapper" --> +<#import "../macro/CommonMacros.ftl" as lib> +<@lib.handleExceptions> + if ( ${sourceReference} != null ) { + ${sourceReference}.forEach( ${ext.targetBeanName}::${ext.targetWriteAccessorName} ); + } + \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java new file mode 100644 index 0000000000..b50015337d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561.java8; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sebastian Haberey + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue1561Mapper { + + Issue1561Mapper + INSTANCE = Mappers.getMapper( Issue1561Mapper.class ); + + Target map(Source source); + + Source map(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java new file mode 100644 index 0000000000..d15a53f48c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561.java8; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sebastian Haberey + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1561") +@WithClasses({ + Issue1561Mapper.class, + Source.class, + Target.class +}) +public class Issue1561Test { + + @Test + public void shouldCorrectlyUseAdder() { + + Source source = new Source(); + source.addProperty( "first" ); + source.addProperty( "second" ); + + Target target = Issue1561Mapper.INSTANCE.map( source ); + + assertThat( target.getProperties() ) + .containsExactly( "first", "second" ); + + Source mapped = Issue1561Mapper.INSTANCE.map( target ); + + assertThat( mapped.getProperties() ) + .containsExactly( "first", "second" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java new file mode 100644 index 0000000000..5f52689ce2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561.java8; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Sebastian Haberey + */ +public class Source { + + private List properties = new ArrayList(); + + public List getProperties() { + return properties; + } + + public void addProperty(String property) { + properties.add( property ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java new file mode 100644 index 0000000000..1a46477dd3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561.java8; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +/** + * @author Sebastian Haberey + */ +public class Target { + + private List properties = new ArrayList(); + + public Stream getProperties() { + return properties.stream(); + } + + public void addProperty(String property) { + properties.add( property ); + } +} From dcddba68533a3b6c8ce102d8346b3b2e1452b0e1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 24 Sep 2018 22:26:43 +0200 Subject: [PATCH 0277/1006] Add Sebastian to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 8b6317dc76..a36ca3cf69 100644 --- a/copyright.txt +++ b/copyright.txt @@ -34,6 +34,7 @@ Remo Meier - https://github.com/remmeier Richard Lea - https://github.com/chigix Saheb Preet Singh - https://github.com/sahebpreet Samuel Wright - https://github.com/samwright +Sebastian Haberey - https://github.com/sebastianhaberey Sebastian Hasait - https://github.com/shasait Sean Huang - https://github.com/seanjob Sjaak Derksen - https://github.com/sjaakd From 459f57e8058800847d8c8ebaa4f26d024ecd517d Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Mon, 24 Sep 2018 23:35:35 +0200 Subject: [PATCH 0278/1006] #1571 apply nullvaluecheck strategy on all relevant levels --- .../main/java/org/mapstruct/BeanMapping.java | 11 +++ .../src/main/java/org/mapstruct/Mapper.java | 2 +- .../main/java/org/mapstruct/MapperConfig.java | 2 +- .../src/main/java/org/mapstruct/Mapping.java | 12 +++ core/src/main/java/org/mapstruct/Mapping.java | 12 +++ .../ap/internal/model/BeanMappingMethod.java | 26 +++--- .../model/CollectionAssignmentBuilder.java | 11 ++- .../ap/internal/model/PropertyMapping.java | 29 ++++-- .../ap/internal/model/source/BeanMapping.java | 29 +++++- .../ap/internal/model/source/Mapping.java | 29 +++++- .../prism/NullValueCheckStrategyPrism.java | 2 +- .../processor/MapperCreationProcessor.java | 8 -- .../ap/internal/util/MapperConfiguration.java | 12 ++- .../ap/test/nullcheck/strategy/HouseDto.java | 28 ++++++ .../test/nullcheck/strategy/HouseEntity.java | 41 ++++++++ .../test/nullcheck/strategy/HouseMapper.java | 28 ++++++ .../nullcheck/strategy/HouseMapperConfig.java | 15 +++ .../strategy/HouseMapperWithConfig.java | 28 ++++++ .../strategy/NullValueCheckTest.java | 93 +++++++++++++++++++ 19 files changed, 373 insertions(+), 45 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperWithConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core-common/src/main/java/org/mapstruct/BeanMapping.java index 582814e7a5..2492477a27 100644 --- a/core-common/src/main/java/org/mapstruct/BeanMapping.java +++ b/core-common/src/main/java/org/mapstruct/BeanMapping.java @@ -11,6 +11,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; + /** * Configures the mapping between two bean types. *

      @@ -61,6 +63,15 @@ */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * Determines when to include a null check on the source property value of a bean mapping. + * + * Can be overridden by the one on {@link MapperConfig}, {@link Mapper} or {@link Mapping}. + * + * @return strategy how to do null checking + */ + NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + /** * Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No * warning will be issued on missing target properties. diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core-common/src/main/java/org/mapstruct/Mapper.java index fa9863244e..c86485e94f 100644 --- a/core-common/src/main/java/org/mapstruct/Mapper.java +++ b/core-common/src/main/java/org/mapstruct/Mapper.java @@ -153,7 +153,7 @@ /** * Determines when to include a null check on the source property value of a bean mapping. * - * Can be overridden by the one on {@link MapperConfig} or {@link Mapping}. + * Can be overridden by the one on {@link MapperConfig}, {@link BeanMapping} or {@link Mapping}. * * @return strategy how to do null checking */ diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core-common/src/main/java/org/mapstruct/MapperConfig.java index f0589c0ae5..cbcd151157 100644 --- a/core-common/src/main/java/org/mapstruct/MapperConfig.java +++ b/core-common/src/main/java/org/mapstruct/MapperConfig.java @@ -138,7 +138,7 @@ MappingInheritanceStrategy mappingInheritanceStrategy() /** * Determines when to include a null check on the source property value of a bean mapping. * - * Can be overridden by the one on {@link Mapper} or {@link Mapping}. + * Can be overridden by the one on {@link Mapper}, {@link BeanMapping} or {@link Mapping}. * * @return strategy how to do null checking */ diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java index 703c2bd372..a5d86dc905 100644 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ b/core-jdk8/src/main/java/org/mapstruct/Mapping.java @@ -15,6 +15,8 @@ import java.text.DecimalFormat; import java.util.Date; +import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; + /** * Configures the mapping of one bean attribute or enum constant. *

      @@ -255,4 +257,14 @@ * @return Default value to set in case the source property is {@code null}. */ String defaultValue() default ""; + + /** + * Determines when to include a null check on the source property value of a bean mapping. + * + * Can be overridden by the one on {@link MapperConfig}, {@link Mapper} or {@link BeanMapping}. + * + * @return strategy how to do null checking + */ + NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + } diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index d98eb3b8de..edf7d55ec6 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -14,6 +14,8 @@ import java.text.DecimalFormat; import java.util.Date; +import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; + /** * Configures the mapping of one bean attribute or enum constant. *

      @@ -260,4 +262,14 @@ * @return Default value to set in case the source property is {@code null}. */ String defaultValue() default ""; + + /** + * Determines when to include a null check on the source property value of a bean mapping. + * + * Can be overridden by the one on {@link MapperConfig}, {@link Mapper} or {@link BeanMapping}. + * + * @return strategy how to do null checking + */ + NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index f29c876c45..16546f4010 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -75,8 +75,6 @@ public static class Builder { private Set targetProperties; private final List propertyMappings = new ArrayList(); private final Set unprocessedSourceParameters = new HashSet(); - private NullValueMappingStrategyPrism nullValueMappingStrategy; - private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet(); private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; @@ -135,16 +133,6 @@ private Builder setupMethodWithMapping(Method sourceMethod) { return this; } - public Builder selectionParameters(SelectionParameters selectionParameters) { - this.selectionParameters = selectionParameters; - return this; - } - - public Builder nullValueMappingStrategy(NullValueMappingStrategyPrism nullValueMappingStrategy) { - this.nullValueMappingStrategy = nullValueMappingStrategy; - return this; - } - public BeanMappingMethod build() { // map properties with mapping boolean mappingErrorOccured = handleDefinedMappings(); @@ -168,12 +156,20 @@ public BeanMappingMethod build() { reportErrorForUnmappedTargetPropertiesIfRequired(); reportErrorForUnmappedSourcePropertiesIfRequired(); + // get bean mapping (when specified as annotation ) + BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); + BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); + // mapNullToDefault + NullValueMappingStrategyPrism nullValueMappingStrategy = + beanMapping != null ? beanMapping.getNullValueMappingStrategy() : null; boolean mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); - BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); + // selectionParameters + SelectionParameters selectionParameters = beanMapping != null ? beanMapping.getSelectionParameters() : null; + // check if there's a factory method for the result type MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( @@ -481,6 +477,7 @@ else if ( mapping.getSourceName() != null ) { .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) .defaultJavaExpression( mapping.getDefaultJavaExpression() ) + .nullValueCheckStrategyPrism( mapping.getNullValueCheckStrategy() ) .build(); handledTargets.add( propertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); @@ -597,6 +594,8 @@ private void applyPropertyNameBasedMapping() { .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetPropertyName, false ) ) + .nullValueCheckStrategyPrism( mapping != null ? mapping.getNullValueCheckStrategy() + : null ) .build(); unprocessedSourceParameters.remove( sourceParameter ); @@ -660,6 +659,7 @@ private void applyParameterNameBasedMapping() { .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetProperty.getKey(), false ) ) + .nullValueCheckStrategyPrism( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .build(); propertyMappings.add( propertyMapping ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index e832bba4ef..7649c373f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -57,6 +57,7 @@ public class CollectionAssignmentBuilder { private PropertyMapping.TargetWriteAccessorType targetAccessorType; private Assignment assignment; private SourceRHS sourceRHS; + private NullValueCheckStrategyPrism nullValueCheckStrategy; public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) { this.ctx = ctx; @@ -108,6 +109,11 @@ public CollectionAssignmentBuilder rightHandSide(SourceRHS sourceRHS) { return this; } + public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyPrism nullValueCheckStrategy ) { + this.nullValueCheckStrategy = nullValueCheckStrategy; + return this; + } + public Assignment build() { Assignment result = assignment; @@ -146,14 +152,14 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { result, method.getThrownTypes(), targetType, - method.getMapperConfiguration().getNullValueCheckStrategy(), + nullValueCheckStrategy, ctx.getTypeFactory(), PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), mapNullToDefault() ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || - method.getMapperConfiguration().getNullValueCheckStrategy() == NullValueCheckStrategyPrism.ALWAYS ) { + nullValueCheckStrategy == NullValueCheckStrategyPrism.ALWAYS ) { result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, @@ -199,4 +205,5 @@ private boolean mapNullToDefault() { return method.getMapperConfiguration().getNullValueMappingStrategy() == NullValueMappingStrategyPrism.RETURN_DEFAULT; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 54da3723c3..25db635761 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -5,17 +5,11 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.DeclaredType; @@ -33,6 +27,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; 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.model.source.MappingOptions; @@ -52,6 +47,11 @@ import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; + /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to * {@code int Target#bar}. Name and type of source and target property can differ. If they have different types, the @@ -197,6 +197,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase ignoreUnmappedSourceProperties; @@ -42,6 +44,7 @@ public static BeanMapping forInheritance( BeanMapping map ) { return new BeanMapping( map.selectionParameters, map.nullValueMappingStrategy, + map.nullValueCheckStrategy, map.reportingPolicy, false, map.ignoreUnmappedSourceProperties, @@ -63,6 +66,11 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ? null : NullValueMappingStrategyPrism.valueOf( beanMapping.nullValueMappingStrategy() ); + NullValueCheckStrategyPrism nullValueCheckStrategy = + null == beanMapping.values.nullValueCheckStrategy() + ? null + : NullValueCheckStrategyPrism.valueOf( beanMapping.nullValueCheckStrategy() ); + boolean ignoreByDefault = beanMapping.ignoreByDefault(); BuilderPrism builderMapping = null; if ( beanMapping.values.builder() != null ) { @@ -71,7 +79,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() && beanMapping.ignoreUnmappedSourceProperties().isEmpty() - && ( nullValueMappingStrategy == null ) && !ignoreByDefault + && ( nullValueMappingStrategy == null ) && ( nullValueCheckStrategy == null ) && !ignoreByDefault && builderMapping == null ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); @@ -88,6 +96,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem return new BeanMapping( cmp, nullValueMappingStrategy, + nullValueCheckStrategy, null, ignoreByDefault, beanMapping.ignoreUnmappedSourceProperties(), @@ -102,14 +111,24 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem * @return bean mapping that needs to be used for Mappings */ public static BeanMapping forForgedMethods() { - return new BeanMapping( null, null, ReportingPolicyPrism.IGNORE, false, Collections.emptyList(), null ); + return new BeanMapping( + null, + null, + null, + ReportingPolicyPrism.IGNORE, + false, + Collections.emptyList(), + null + ); } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, + NullValueCheckStrategyPrism nvcs, ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, - List ignoreUnmappedSourceProperties, BuilderPrism builder) { + List ignoreUnmappedSourceProperties, BuilderPrism builder) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; + this.nullValueCheckStrategy = nvcs; this.reportingPolicy = reportingPolicy; this.ignoreByDefault = ignoreByDefault; this.ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties; @@ -124,6 +143,10 @@ public NullValueMappingStrategyPrism getNullValueMappingStrategy() { return nullValueMappingStrategy; } + public NullValueCheckStrategyPrism getNullValueCheckStrategy() { + return nullValueCheckStrategy; + } + public ReportingPolicyPrism getReportingPolicy() { return reportingPolicy; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 64051d4081..8c669f8b45 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -26,6 +26,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; +import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -56,6 +57,7 @@ public class Mapping { private final AnnotationValue sourceAnnotationValue; private final AnnotationValue targetAnnotationValue; private final AnnotationValue dependsOnAnnotationValue; + private final NullValueCheckStrategyPrism nullValueCheckStrategy; private SourceReference sourceReference; private TargetReference targetReference; @@ -181,6 +183,11 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa typeUtils ); + NullValueCheckStrategyPrism nullValueCheckStrategy = + null == mappingPrism.values.nullValueCheckStrategy() + ? null + : NullValueCheckStrategyPrism.valueOf( mappingPrism.nullValueCheckStrategy() ); + return new Mapping( source, constant, @@ -195,7 +202,8 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa formattingParam, selectionParams, mappingPrism.values.dependsOn(), - dependsOn + dependsOn, + nullValueCheckStrategy ); } @@ -214,7 +222,8 @@ public static Mapping forIgnore( String targetName) { null, null, null, - new ArrayList() + new ArrayList(), + null ); } @@ -223,7 +232,8 @@ private Mapping( String sourceName, String constant, String javaExpression, Stri String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror, AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue, FormattingParameters formattingParameters, SelectionParameters selectionParameters, - AnnotationValue dependsOnAnnotationValue, List dependsOn ) { + AnnotationValue dependsOnAnnotationValue, List dependsOn, + NullValueCheckStrategyPrism nullValueCheckStrategy ) { this.sourceName = sourceName; this.constant = constant; this.javaExpression = javaExpression; @@ -238,6 +248,7 @@ private Mapping( String sourceName, String constant, String javaExpression, Stri this.selectionParameters = selectionParameters; this.dependsOnAnnotationValue = dependsOnAnnotationValue; this.dependsOn = dependsOn; + this.nullValueCheckStrategy = nullValueCheckStrategy; } private Mapping( Mapping mapping, TargetReference targetReference ) { @@ -257,6 +268,7 @@ private Mapping( Mapping mapping, TargetReference targetReference ) { this.dependsOn = mapping.dependsOn; this.sourceReference = mapping.sourceReference; this.targetReference = targetReference; + this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; } private Mapping( Mapping mapping, SourceReference sourceReference ) { @@ -276,6 +288,7 @@ private Mapping( Mapping mapping, SourceReference sourceReference ) { this.dependsOn = mapping.dependsOn; this.sourceReference = sourceReference; this.targetReference = mapping.targetReference; + this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; } private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, @@ -441,6 +454,10 @@ public TargetReference getTargetReference() { return targetReference; } + public NullValueCheckStrategyPrism getNullValueCheckStrategy() { + return nullValueCheckStrategy; + } + public Mapping popTargetReference() { if ( targetReference != null ) { TargetReference newTargetReference = targetReference.pop(); @@ -488,7 +505,8 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac formattingParameters, selectionParameters, dependsOnAnnotationValue, - Collections.emptyList() + Collections.emptyList(), + nullValueCheckStrategy ); reverse.init( @@ -529,7 +547,8 @@ public Mapping copyForInheritanceTo(SourceMethod method) { formattingParameters, selectionParameters, dependsOnAnnotationValue, - dependsOn + dependsOn, + nullValueCheckStrategy ); if ( sourceReference != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java index 6783d34af0..555231f987 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java @@ -7,7 +7,7 @@ /** - * Prism for the enum {@link org.mapstruct.SourceValuePresenceCheckStrategy} + * Prism for the enum {@link org.mapstruct.NullValueCheckStrategy} * * @author Sean Huang */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index abc9828632..3ccd45873f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -365,19 +365,11 @@ else if ( method.isStreamMapping() ) { } else { - NullValueMappingStrategyPrism nullValueMappingStrategy = null; - SelectionParameters selectionParameters = null; - if ( mappingOptions.getBeanMapping() != null ) { - nullValueMappingStrategy = mappingOptions.getBeanMapping().getNullValueMappingStrategy(); - selectionParameters = mappingOptions.getBeanMapping().getSelectionParameters(); - } BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) .sourceMethod( method ) - .nullValueMappingStrategy( nullValueMappingStrategy ) - .selectionParameters( selectionParameters ) .build(); if ( beanMappingMethod != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 40670a63c1..4ffc31016e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -8,7 +8,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.type.DeclaredType; @@ -148,8 +147,15 @@ public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() { } } - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy() == null ) { + public NullValueCheckStrategyPrism getNullValueCheckStrategy(NullValueCheckStrategyPrism beanPrism, + NullValueCheckStrategyPrism mappingPrism) { + if ( mappingPrism != null ) { + return mappingPrism; + } + else if ( beanPrism != null ) { + return beanPrism; + } + else if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy() == null ) { return NullValueCheckStrategyPrism.valueOf( mapperConfigPrism.nullValueCheckStrategy() ); } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseDto.java new file mode 100644 index 0000000000..141c893373 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseDto.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +public class HouseDto { + + private String owner; + private Integer number; + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseEntity.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseEntity.java new file mode 100644 index 0000000000..943a5c3f5a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseEntity.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +public class HouseEntity { + + private String owner; + private boolean ownerSet = false; + + private Integer number; + private boolean numberSet = false; + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + ownerSet = true; + this.owner = owner; + } + + public boolean ownerSet() { + return ownerSet; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + numberSet = true; + this.number = number; + } + + public boolean numberSet() { + return numberSet; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapper.java new file mode 100644 index 0000000000..860fbc6579 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface HouseMapper { + + HouseMapper INSTANCE = Mappers.getMapper( HouseMapper.class ); + + HouseEntity mapWithNvcsOnMapper(HouseDto in); + + @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION) + HouseEntity mapWithNvcsOnBean(HouseDto in); + + @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION) + @Mapping(target = "number", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) + HouseEntity mapWithNvcsOnMapping(HouseDto in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperConfig.java new file mode 100644 index 0000000000..24753bb8dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperConfig.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +import org.mapstruct.MapperConfig; +import org.mapstruct.NullValueCheckStrategy; + +@MapperConfig( + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS +) +public interface HouseMapperConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperWithConfig.java new file mode 100644 index 0000000000..ceb703fdfe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/HouseMapperWithConfig.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(config = HouseMapperConfig.class) +public interface HouseMapperWithConfig { + + HouseMapperWithConfig INSTANCE = Mappers.getMapper( HouseMapperWithConfig.class ); + + HouseEntity mapWithNvcsOnMapper(HouseDto in); + + @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION) + HouseEntity mapWithNvcsOnBean(HouseDto in); + + @BeanMapping(nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION) + @Mapping(target = "number", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) + HouseEntity mapWithNvcsOnMapping(HouseDto in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java new file mode 100644 index 0000000000..957b3e7b1a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java @@ -0,0 +1,93 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullcheck.strategy; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("1571") +@WithClasses({ + HouseDto.class, + HouseEntity.class, + HouseMapper.class, + HouseMapperConfig.class, + HouseMapperWithConfig.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class NullValueCheckTest { + + @Test + public void testDefinedOnMapper() { + + HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnMapper( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isFalse(); + assertThat( entity.numberSet() ).isFalse(); + + } + + @Test + public void testDefinedOnBean() { + + HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnBean( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isTrue(); + assertThat( entity.numberSet() ).isTrue(); + + } + + @Test + public void testDefinedOnMapping() { + + HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnMapping( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isTrue(); + assertThat( entity.numberSet() ).isFalse(); + + } + + @Test + public void testDefinedOnConfig() { + + HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnMapper( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isFalse(); + assertThat( entity.numberSet() ).isFalse(); + + } + + @Test + public void testDefinedOnConfigAndBean() { + + HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnBean( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isTrue(); + assertThat( entity.numberSet() ).isTrue(); + + } + + @Test + public void testDefinedOnConfigAndMapping() { + + HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnMapping( new HouseDto() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.ownerSet() ).isTrue(); + assertThat( entity.numberSet() ).isFalse(); + + } + +} From 4f539d2a084f80744134598b423f50b2cf8f4975 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Wed, 26 Sep 2018 20:48:54 +0200 Subject: [PATCH 0279/1006] #1616 Adding an issue template to streamline answers --- ISSUE_TEMPLATE.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 0000000000..ecaf441514 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,9 @@ +- [ ] Is this an issue (and hence not a question)? + +If this is a question how to use MapStruct there are several resources available. +- Our reference- and API [documentation](http://mapstruct.org/documentation/reference-guide/). +- Our [examples](https://github.com/mapstruct/mapstruct-examples) repository (contributions always welcome) +- Our [FAQ](http://mapstruct.org/faq/) +- [StackOverflow](https://stackoverflow.com), tag MapStruct +- [Gitter](https://gitter.im/mapstruct/mapstruct-users) (you usually get fast feedback) +- Our [google group](https://groups.google.com/forum/#!forum/mapstruct-users) \ No newline at end of file From 6b3cbaae9e1625f147212a9c726ae13fa1bd1239 Mon Sep 17 00:00:00 2001 From: neoXfire Date: Fri, 12 Oct 2018 21:10:25 +0200 Subject: [PATCH 0280/1006] #1595 Support for conversion between java.time.Instant and java.util.Date (#1622) --- .../ap/internal/conversion/Conversions.java | 1 + .../JavaInstantToDateConversion.java | 37 +++++++++++++++++++ .../ap/internal/util/JavaTimeConstants.java | 2 + .../java8time/Java8TimeConversionTest.java | 17 +++++++++ .../ap/test/conversion/java8time/Source.java | 11 ++++++ .../ap/test/conversion/java8time/Target.java | 10 +++++ 6 files changed, 78 insertions(+) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaInstantToDateConversion.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index e59998a54a..dd8c13cc77 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -222,6 +222,7 @@ private void registerJava8TimeConversions() { register( JavaTimeConstants.ZONED_DATE_TIME_FQN, Date.class, new JavaZonedDateTimeToDateConversion() ); register( JavaTimeConstants.LOCAL_DATE_TIME_FQN, Date.class, new JavaLocalDateTimeToDateConversion() ); register( JavaTimeConstants.LOCAL_DATE_FQN, Date.class, new JavaLocalDateToDateConversion() ); + register( JavaTimeConstants.INSTANT, Date.class, new JavaInstantToDateConversion() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaInstantToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaInstantToDateConversion.java new file mode 100644 index 0000000000..fab4778061 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaInstantToDateConversion.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import java.util.Date; +import java.util.Set; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; + +/** + * SimpleConversion for mapping {@link java.time.Instant} to + * {@link Date} and vice versa. + */ +public class JavaInstantToDateConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return date( conversionContext ) + ".from( )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( conversionContext.getTypeFactory().getType( Date.class ) ); + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return ".toInstant()"; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java index 8f119241bd..60053064b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java @@ -20,6 +20,8 @@ public final class JavaTimeConstants { public static final String DATE_TIME_FORMATTER_FQN = "java.time.format.DateTimeFormatter"; + public static final String INSTANT = "java.time.Instant"; + private JavaTimeConstants() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index 1bf73e9042..d04ae629a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -7,12 +7,14 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Calendar; +import java.util.Date; import java.util.TimeZone; import org.junit.Test; @@ -229,6 +231,21 @@ public void testZonedDateTimeToDateMapping() { assertThat( source.getForDateConversionWithZonedDateTime() ).isEqualTo( dateTime ); } + @Test + public void testInstantToDateMapping() { + Instant instant = Instant.ofEpochMilli( 1539366615000L ); + + Source source = new Source(); + source.setForDateConversionWithInstant( instant ); + Target target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + Date date = target.getForDateConversionWithInstant(); + assertThat( date ).isNotNull(); + assertThat( date.getTime() ).isEqualTo( 1539366615000L ); + + source = SourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForDateConversionWithInstant() ).isEqualTo( instant ); + } + @Test public void testLocalDateTimeToDateMapping() { TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java index 5ca0d29fb8..97a8f5b62a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.conversion.java8time; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -31,6 +32,8 @@ public class Source { private LocalDate forDateConversionWithLocalDate; + private Instant forDateConversionWithInstant; + public ZonedDateTime getZonedDateTime() { return zonedDateTime; } @@ -94,4 +97,12 @@ public LocalDate getForDateConversionWithLocalDate() { public void setForDateConversionWithLocalDate(LocalDate forDateConversionWithLocalDate) { this.forDateConversionWithLocalDate = forDateConversionWithLocalDate; } + + public Instant getForDateConversionWithInstant() { + return forDateConversionWithInstant; + } + + public void setForDateConversionWithInstant(Instant forDateConversionWithInstant) { + this.forDateConversionWithInstant = forDateConversionWithInstant; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java index c74f870f41..aca6aa22a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java @@ -29,6 +29,8 @@ public class Target { private Date forDateConversionWithLocalDate; + private Date forDateConversionWithInstant; + public String getZonedDateTime() { return zonedDateTime; } @@ -92,4 +94,12 @@ public Date getForDateConversionWithLocalDate() { public void setForDateConversionWithLocalDate(Date forDateConversionWithLocalDate) { this.forDateConversionWithLocalDate = forDateConversionWithLocalDate; } + + public Date getForDateConversionWithInstant() { + return forDateConversionWithInstant; + } + + public void setForDateConversionWithInstant(Date forDateConversionWithInstant) { + this.forDateConversionWithInstant = forDateConversionWithInstant; + } } From ef82ebfbcaa652792fccb70d72861806ce0bf4c6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 13 Oct 2018 08:17:20 +0200 Subject: [PATCH 0281/1006] #1595 Update reference guide with implicit conversion between java.time.Instant and java.util.Date --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 2d2327e578..00a71c553d 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -957,6 +957,8 @@ public interface CarMapper { * Between `java.time.LocalDate` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. +* Between `java.time.Instant` from Java 8 Date-Time package and `java.util.Date`. + * Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Calendar`. * Between `java.sql.Date` and `java.util.Date` From fa1ab4b781f39ccbb845a1d4994103e6609a8db9 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 13 Oct 2018 08:46:16 +0200 Subject: [PATCH 0282/1006] Update copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index a36ca3cf69..c15d26b5bc 100644 --- a/copyright.txt +++ b/copyright.txt @@ -16,6 +16,7 @@ Dmytro Polovinkin - https://github.com/navpil Eric Martineau - https://github.com/ericmartineau Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr +Florian Tavares - https://github.com/neoXfire Gervais Blaise - https://github.com/gervaisb Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla From f17ddcfb1874bb271b4b7b921a4e416467e977e5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 13 Oct 2018 08:54:09 +0200 Subject: [PATCH 0283/1006] #1608 Make sure that property names for fluent setters starting with is are handled properly (#1620) --- .../ap/spi/DefaultAccessorNamingStrategy.java | 4 +- .../mapstruct/ap/test/bugs/_1608/Book.java | 32 ++++++++++ .../mapstruct/ap/test/bugs/_1608/BookDto.java | 61 +++++++++++++++++++ .../ap/test/bugs/_1608/Issue1608Mapper.java | 20 ++++++ .../ap/test/bugs/_1608/Issue1608Test.java | 39 ++++++++++++ 5 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Book.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/BookDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 908963f5da..ab0d604a69 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -156,8 +156,8 @@ public boolean isPresenceCheckMethod(ExecutableElement method) { @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); - if ( methodName.startsWith( "is" ) || methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { - return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); + if ( methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { + return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); } else if ( isFluentSetter( getterOrSetterMethod ) ) { return methodName; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Book.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Book.java new file mode 100644 index 0000000000..0bfeb08e1b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Book.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1608; + +/** + * @author Filip Hrisafov + */ +public class Book { + + private String isbn; + + private int issueYear; + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public int getIssueYear() { + return issueYear; + } + + public void setIssueYear(int issueYear) { + this.issueYear = issueYear; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/BookDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/BookDto.java new file mode 100644 index 0000000000..7244cc1c6a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/BookDto.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1608; + +/** + * @author Filip Hrisafov + */ +public class BookDto { + + private final String isbn; + private final int issueYear; + + public BookDto(String isbn, int issueYear) { + this.isbn = isbn; + this.issueYear = issueYear; + } + + public String getIsbn() { + return isbn; + } + + public int getIssueYear() { + return issueYear; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String isbn; + + private int issueYear; + + public String getIsbn() { + return isbn; + } + + public Builder isbn(String isbn) { + this.isbn = isbn; + return this; + } + + public int getIssueYear() { + return issueYear; + } + + public Builder setIssueYear(int issueYear) { + this.issueYear = issueYear; + return this; + } + + public BookDto build() { + return new BookDto( isbn, issueYear ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Mapper.java new file mode 100644 index 0000000000..f36f9739f9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1608; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1608Mapper { + + Issue1608Mapper INSTANCE = Mappers.getMapper( Issue1608Mapper.class ); + + BookDto map(Book source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java new file mode 100644 index 0000000000..44abfd69fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1608; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1608") +@WithClasses({ + Issue1608Mapper.class, + Book.class, + BookDto.class +}) +public class Issue1608Test { + + @Test + public void shouldCorrectlyUseFluentSettersStartingWithIs() { + + Book book = new Book(); + book.setIsbn( "978-3-16-148410-0" ); + book.setIssueYear( 2018 ); + BookDto bookDto = Issue1608Mapper.INSTANCE.map( book ); + + assertThat( bookDto.getIsbn() ).isEqualTo( "978-3-16-148410-0" ); + assertThat( bookDto.getIssueYear() ).isEqualTo( 2018 ); + } +} From 0e0fd313e560dd17097f730f7d759d95d84eb1ee Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 12 Oct 2018 23:57:24 +0200 Subject: [PATCH 0284/1006] #1594 Add test case to show that it has been fixed --- .../ap/test/bugs/_1594/Issue1594Mapper.java | 84 +++++++++++++++++++ .../ap/test/bugs/_1594/Issue1594Test.java | 41 +++++++++ 2 files changed, 125 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Mapper.java new file mode 100644 index 0000000000..fbb99ed529 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Mapper.java @@ -0,0 +1,84 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1594; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1594Mapper { + + Issue1594Mapper INSTANCE = Mappers.getMapper( Issue1594Mapper.class ); + + @Mappings({ + @Mapping(target = "address.country.oid", expression = "java(dto.getFullAddress().split( \"-\" )[0])"), + @Mapping(target = "address.city.oid", expression = "java(dto.getFullAddress().split( \"-\" )[1])"), + }) + Client toClient(Dto dto); + + class Client { + private Address address; + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + } + + class Address { + + private Id country; + private Id city; + + public Id getCountry() { + return country; + } + + public void setCountry(Id country) { + this.country = country; + } + + public Id getCity() { + return city; + } + + public void setCity(Id city) { + this.city = city; + } + } + + class Id { + private String oid; + + public String getOid() { + return oid; + } + + public void setOid(String oid) { + this.oid = oid; + } + } + + class Dto { + private String fullAddress; + + public String getFullAddress() { + return fullAddress; + } + + public void setFullAddress(String fullAddress) { + this.fullAddress = fullAddress; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java new file mode 100644 index 0000000000..b498884b29 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1594; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1594") +@WithClasses({ + Issue1594Mapper.class +}) +public class Issue1594Test { + + @Test + public void shouldGenerateCorrectMapping() { + Issue1594Mapper.Dto dto = new Issue1594Mapper.Dto(); + dto.setFullAddress( "Switzerland-Zurich" ); + + Issue1594Mapper.Client client = Issue1594Mapper.INSTANCE.toClient( dto ); + + assertThat( client ).isNotNull(); + assertThat( client.getAddress() ).isNotNull(); + assertThat( client.getAddress().getCountry() ).isNotNull(); + assertThat( client.getAddress().getCountry().getOid() ).isEqualTo( "Switzerland" ); + assertThat( client.getAddress().getCity() ).isNotNull(); + assertThat( client.getAddress().getCity().getOid() ).isEqualTo( "Zurich" ); + + } +} From 6d5243dc2fbee57599a1aacfec2646288ba323f4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 13 Oct 2018 10:24:22 +0200 Subject: [PATCH 0285/1006] #1551 Use javax.annotation.processing.Generated if it is available and source version is at least RELEASE_9 --- .../mapstruct-reference-guide.asciidoc | 4 ++-- .../ap/internal/model/GeneratedType.java | 10 ++++++++-- .../processor/DefaultVersionInformation.java | 19 +++++++++++++++++-- .../internal/version/VersionInformation.java | 2 ++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 00a71c553d..a06b722493 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -283,8 +283,8 @@ If the `@Generated` annotation is not available, MapStruct will detect this situ [NOTE] ===== -In Java 9 `java.annotation.processing.Generated` was added, which is considered as a general purpose annotation for any code generators -and is part of the `java.compiler` module. Support for it is planned within https://github.com/mapstruct/mapstruct/issues/1551[#1551] +In Java 9 `java.annotation.processing.Generated` was added (part of the `java.compiler` module), +if this annotation is available then it will be used. ===== [[defining-mapper]] diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 75703dcfa4..5404d0d950 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -74,12 +74,18 @@ protected GeneratedType(TypeFactory typeFactory, String packageName, String name this.versionInformation = versionInformation; this.accessibility = accessibility; - this.generatedTypeAvailable = typeFactory.isTypeAvailable( "javax.annotation.Generated" ); - if ( generatedTypeAvailable ) { + if ( versionInformation.isSourceVersionAtLeast9() && + typeFactory.isTypeAvailable( "javax.annotation.processing.Generated" ) ) { + this.generatedType = typeFactory.getType( "javax.annotation.processing.Generated" ); + this.generatedTypeAvailable = true; + } + else if ( typeFactory.isTypeAvailable( "javax.annotation.Generated" ) ) { this.generatedType = typeFactory.getType( "javax.annotation.Generated" ); + this.generatedTypeAvailable = true; } else { this.generatedType = null; + this.generatedTypeAvailable = false; } this.constructor = constructor; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java index 589299bb3b..60e5f112d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java @@ -11,6 +11,7 @@ import java.util.jar.Manifest; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.SourceVersion; import org.mapstruct.ap.internal.version.VersionInformation; @@ -37,15 +38,19 @@ public class DefaultVersionInformation implements VersionInformation { private final String runtimeVersion; private final String runtimeVendor; private final String compiler; + private final boolean sourceVersionAtLeast9; private final boolean eclipseJDT; private final boolean javac; - DefaultVersionInformation(String runtimeVersion, String runtimeVendor, String compiler) { + DefaultVersionInformation(String runtimeVersion, String runtimeVendor, String compiler, + SourceVersion sourceVersion) { this.runtimeVersion = runtimeVersion; this.runtimeVendor = runtimeVendor; this.compiler = compiler; this.eclipseJDT = compiler.startsWith( COMPILER_NAME_ECLIPSE_JDT ); this.javac = compiler.startsWith( COMPILER_NAME_JAVAC ); + // If the difference between the source version and RELEASE_6 is more that 2 than we are at least on 9 + this.sourceVersionAtLeast9 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 2; } @Override @@ -68,6 +73,11 @@ public String getCompiler() { return this.compiler; } + @Override + public boolean isSourceVersionAtLeast9() { + return sourceVersionAtLeast9; + } + @Override public boolean isEclipseJDTCompiler() { return eclipseJDT; @@ -84,7 +94,12 @@ static DefaultVersionInformation fromProcessingEnvironment(ProcessingEnvironment String compiler = getCompiler( processingEnv ); - return new DefaultVersionInformation( runtimeVersion, runtimeVendor, compiler ); + return new DefaultVersionInformation( + runtimeVersion, + runtimeVendor, + compiler, + processingEnv.getSourceVersion() + ); } private static String getCompiler(ProcessingEnvironment processingEnv) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java index 020792e860..94e3520ad0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java @@ -19,6 +19,8 @@ public interface VersionInformation { String getCompiler(); + boolean isSourceVersionAtLeast9(); + boolean isEclipseJDTCompiler(); boolean isJavacCompiler(); From 9f8c0749d1f465221ac7ca856085619081e6219c Mon Sep 17 00:00:00 2001 From: Sivaraman Viswanathan Date: Mon, 15 Oct 2018 12:41:53 -0700 Subject: [PATCH 0286/1006] #1591 Add support for mapping java.time.LocalDate to java.sql.Date --- .../ap/internal/conversion/Conversions.java | 6 +-- .../JavaLocalDateToSqlDateConversion.java | 53 +++++++++++++++++++ .../java8time/Java8TimeConversionTest.java | 24 +++++++++ .../ap/test/conversion/java8time/Source.java | 10 ++++ .../ap/test/conversion/java8time/Target.java | 10 ++++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index dd8c13cc77..70e04146a3 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.conversion.ReverseConversion.reverse; - import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Time; @@ -16,7 +14,6 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; - import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.model.common.Type; @@ -24,6 +21,8 @@ import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import static org.mapstruct.ap.internal.conversion.ReverseConversion.reverse; + /** * Holds built-in {@link ConversionProvider}s such as from {@code int} to {@code String}. * @@ -222,6 +221,7 @@ private void registerJava8TimeConversions() { register( JavaTimeConstants.ZONED_DATE_TIME_FQN, Date.class, new JavaZonedDateTimeToDateConversion() ); register( JavaTimeConstants.LOCAL_DATE_TIME_FQN, Date.class, new JavaLocalDateTimeToDateConversion() ); register( JavaTimeConstants.LOCAL_DATE_FQN, Date.class, new JavaLocalDateToDateConversion() ); + register( JavaTimeConstants.LOCAL_DATE_FQN, java.sql.Date.class, new JavaLocalDateToSqlDateConversion() ); register( JavaTimeConstants.INSTANT, Date.class, new JavaInstantToDateConversion() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java new file mode 100644 index 0000000000..29663cbcf2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.sql.Date; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.sqlDate; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; +import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; + +/** + * SimpleConversion for mapping {@link java.time.LocalDate} to + * {@link Date} and vice versa. + */ +public class JavaLocalDateToSqlDateConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return "new " + sqlDate( conversionContext ) + "( " + + ".atStartOfDay( " + + zoneOffset( conversionContext ) + + ".UTC ).toInstant().toEpochMilli() )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( Date.class ), + conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + ); + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return ".toLocalDate()"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index d04ae629a5..271a8d9589 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -295,4 +295,28 @@ public void testLocalDateToDateMapping() { assertThat( source.getForDateConversionWithLocalDate() ).isEqualTo( localDate ); } + + @Test + public void testLocalDateToSqlDateMapping() { + TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); + + Source source = new Source(); + LocalDate localDate = LocalDate.of( 2016, 3, 1 ); + source.setForSqlDateConversionWithLocalDate( localDate ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + + assertThat( target.getForSqlDateConversionWithLocalDate() ).isNotNull(); + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); + instance.setTimeInMillis( target.getForSqlDateConversionWithLocalDate().getTime() ); + + assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( localDate.getYear() ); + assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( localDate.getMonthValue() - 1 ); + assertThat( instance.get( Calendar.DATE ) ).isEqualTo( localDate.getDayOfMonth() ); + + source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForSqlDateConversionWithLocalDate() ).isEqualTo( localDate ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java index 97a8f5b62a..8862971701 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java @@ -32,6 +32,8 @@ public class Source { private LocalDate forDateConversionWithLocalDate; + private LocalDate forSqlDateConversionWithLocalDate; + private Instant forDateConversionWithInstant; public ZonedDateTime getZonedDateTime() { @@ -98,6 +100,14 @@ public void setForDateConversionWithLocalDate(LocalDate forDateConversionWithLoc this.forDateConversionWithLocalDate = forDateConversionWithLocalDate; } + public LocalDate getForSqlDateConversionWithLocalDate() { + return forSqlDateConversionWithLocalDate; + } + + public void setForSqlDateConversionWithLocalDate(LocalDate forSqlDateConversionWithLocalDate) { + this.forSqlDateConversionWithLocalDate = forSqlDateConversionWithLocalDate; + } + public Instant getForDateConversionWithInstant() { return forDateConversionWithInstant; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java index aca6aa22a8..eac1603d4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java @@ -29,6 +29,8 @@ public class Target { private Date forDateConversionWithLocalDate; + private java.sql.Date forSqlDateConversionWithLocalDate; + private Date forDateConversionWithInstant; public String getZonedDateTime() { @@ -95,6 +97,14 @@ public void setForDateConversionWithLocalDate(Date forDateConversionWithLocalDat this.forDateConversionWithLocalDate = forDateConversionWithLocalDate; } + public java.sql.Date getForSqlDateConversionWithLocalDate() { + return forSqlDateConversionWithLocalDate; + } + + public void setForSqlDateConversionWithLocalDate(java.sql.Date forSqlDateConversionWithLocalDate) { + this.forSqlDateConversionWithLocalDate = forSqlDateConversionWithLocalDate; + } + public Date getForDateConversionWithInstant() { return forDateConversionWithInstant; } From 20bff96e99ce4a89be199e6bb909ddef5d2f5c9e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 15 Oct 2018 21:46:23 +0200 Subject: [PATCH 0287/1006] #1591 Update reference guide with implicit conversion between java.time.LocaDate and java.sql.Date --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index a06b722493..0f66e90d13 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -955,7 +955,7 @@ public interface CarMapper { * Between `java.time.LocalDateTime` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. -* Between `java.time.LocalDate` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. +* Between `java.time.LocalDate` from Java 8 Date-Time package and `java.util.Date` / `java.sql.Date` where timezone UTC is used as the timezone. * Between `java.time.Instant` from Java 8 Date-Time package and `java.util.Date`. From d81d3e46a4b19191fff808c3b963001c6fe41a47 Mon Sep 17 00:00:00 2001 From: Florian Tavares Date: Mon, 15 Oct 2018 22:16:33 +0200 Subject: [PATCH 0288/1006] #1301 Use Java 8 as baseline for MapStruct * Move classes from mapstruct-common into mapstruct * Use Java 8 @Repeatable for @Mappings and @ValueMappings in the mapstruct module * Add relocation for mapstruct-jdk8 to mapstruct * Use of 1.8 source and target versions from parent POM * Update documentation to match * Update versions of some maven plugin crashing build on Java 8 * Drop JDK 6 & 7 support in integration tests * Remove mapstruct-common module (it was never deployed to Central) --- core-common/pom.xml | 58 ---- core-jdk8/pom.xml | 147 +--------- .../src/main/java/org/mapstruct/Mapping.java | 270 ------------------ .../src/main/java/org/mapstruct/Mappings.java | 28 -- .../main/java/org/mapstruct/ValueMapping.java | 113 -------- .../java/org/mapstruct/ValueMappings.java | 24 -- core/pom.xml | 38 --- .../main/java/org/mapstruct/AfterMapping.java | 0 .../main/java/org/mapstruct/BeanMapping.java | 0 .../java/org/mapstruct/BeforeMapping.java | 0 .../src/main/java/org/mapstruct/Builder.java | 0 .../mapstruct/CollectionMappingStrategy.java | 0 .../src/main/java/org/mapstruct/Context.java | 0 .../java/org/mapstruct/DecoratedWith.java | 0 .../org/mapstruct/InheritConfiguration.java | 0 .../InheritInverseConfiguration.java | 0 .../java/org/mapstruct/InjectionStrategy.java | 0 .../java/org/mapstruct/IterableMapping.java | 0 .../main/java/org/mapstruct/MapMapping.java | 0 .../src/main/java/org/mapstruct/Mapper.java | 0 .../main/java/org/mapstruct/MapperConfig.java | 0 core/src/main/java/org/mapstruct/Mapping.java | 13 +- .../java/org/mapstruct/MappingConstants.java | 0 .../mapstruct/MappingInheritanceStrategy.java | 0 .../java/org/mapstruct/MappingTarget.java | 0 .../src/main/java/org/mapstruct/Named.java | 0 .../org/mapstruct/NullValueCheckStrategy.java | 0 .../mapstruct/NullValueMappingStrategy.java | 0 .../java/org/mapstruct/ObjectFactory.java | 0 .../main/java/org/mapstruct/Qualifier.java | 0 .../java/org/mapstruct/ReportingPolicy.java | 0 .../main/java/org/mapstruct/TargetType.java | 0 .../main/java/org/mapstruct/ValueMapping.java | 19 +- .../java/org/mapstruct/factory/Mappers.java | 0 .../org/mapstruct/factory/package-info.java | 0 .../main/java/org/mapstruct/package-info.java | 0 .../java/org/mapstruct/util/Experimental.java | 0 .../org/mapstruct/factory/MappersTest.java | 0 .../factory/PackagePrivateMapper.java | 0 .../factory/PackagePrivateMapperImpl.java | 0 .../java/org/mapstruct/test/model/Foo.java | 0 .../org/mapstruct/test/model/FooImpl.java | 0 .../test/model/SomeClass$FooImpl.java | 0 .../model/SomeClass$NestedClass$FooImpl.java | 0 .../org/mapstruct/test/model/SomeClass.java | 0 distribution/pom.xml | 5 - distribution/src/main/assembly/dist.xml | 1 - .../mapstruct-reference-guide.asciidoc | 14 +- etc/toolchains-cloudbees-jenkins.xml | 23 -- etc/toolchains-example.xml | 22 -- etc/toolchains-travis-jenkins.xml | 23 +- integrationtest/pom.xml | 8 - .../tests/FullFeatureCompilationTest.java | 13 - .../itest/tests/LombokBuilderTest.java | 2 - .../itest/tests/ProtobufBuilderTest.java | 4 - .../itest/testutil/runner/ProcessorSuite.java | 31 +- .../testutil/runner/ProcessorSuiteRunner.java | 8 +- .../superTypeGenerationTest/generator/pom.xml | 2 - .../superTypeGenerationTest/usage/pom.xml | 2 - .../generator/pom.xml | 2 - .../targetTypeGenerationTest/usage/pom.xml | 2 - parent/pom.xml | 17 +- pom.xml | 1 - 63 files changed, 36 insertions(+), 854 deletions(-) delete mode 100644 core-common/pom.xml delete mode 100644 core-jdk8/src/main/java/org/mapstruct/Mapping.java delete mode 100644 core-jdk8/src/main/java/org/mapstruct/Mappings.java delete mode 100644 core-jdk8/src/main/java/org/mapstruct/ValueMapping.java delete mode 100644 core-jdk8/src/main/java/org/mapstruct/ValueMappings.java rename {core-common => core}/src/main/java/org/mapstruct/AfterMapping.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/BeanMapping.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/BeforeMapping.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/Builder.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/CollectionMappingStrategy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/Context.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/DecoratedWith.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/InheritConfiguration.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/InheritInverseConfiguration.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/InjectionStrategy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/IterableMapping.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/MapMapping.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/Mapper.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/MapperConfig.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/MappingConstants.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/MappingInheritanceStrategy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/MappingTarget.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/Named.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/NullValueCheckStrategy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/NullValueMappingStrategy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/ObjectFactory.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/Qualifier.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/ReportingPolicy.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/TargetType.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/factory/Mappers.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/factory/package-info.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/package-info.java (100%) rename {core-common => core}/src/main/java/org/mapstruct/util/Experimental.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/factory/MappersTest.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/test/model/Foo.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/test/model/FooImpl.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java (100%) rename {core-common => core}/src/test/java/org/mapstruct/test/model/SomeClass.java (100%) diff --git a/core-common/pom.xml b/core-common/pom.xml deleted file mode 100644 index 0583071238..0000000000 --- a/core-common/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - 4.0.0 - - - org.mapstruct - mapstruct-parent - 1.3.0-SNAPSHOT - ../parent/pom.xml - - - mapstruct-common - jar - MapStruct Core Common - - - true - true - - - - - junit - junit - test - - - org.assertj - assertj-core - test - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - check-style - verify - - checkstyle - - - - - - - diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 456766be07..48f50c7b60 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -17,146 +17,13 @@ mapstruct-jdk8 - jar MapStruct Core JDK 8 - MapStruct annotations to be used with JDK 8 and later + Deprecated MapStruct artifact containing annotations to be used with JDK 8 and later - + Relocated to mapstruct + + + mapstruct + + - - copied-common-sources - - - - - ${project.groupId} - mapstruct-common - true - - - junit - junit - test - - - org.assertj - assertj-core - test - - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - check-style - verify - - checkstyle - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - verify - - jar - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-copied-common-sources - generate-sources - - add-source - - - - ${project.build.directory}/${common.sources.dir} - - - - - - - org.apache.maven.plugins - maven-resources-plugin - - - copy-resources - process-resources - - copy-resources - - - ${project.build.directory}/${common.sources.dir} - - - ${basedir}/../core-common/src/main/java - false - - - - - - copy-mapstruct-license - prepare-package - - copy-resources - - - ${project.build.directory}/classes/META-INF - - - ${basedir}/.. - false - LICENSE.txt - - - - - - - - org.apache.felix - maven-bundle-plugin - - - org.mapstruct - - - - - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - com.github.siom79.japicmp - japicmp-maven-plugin - - - diff --git a/core-jdk8/src/main/java/org/mapstruct/Mapping.java b/core-jdk8/src/main/java/org/mapstruct/Mapping.java deleted file mode 100644 index a5d86dc905..0000000000 --- a/core-jdk8/src/main/java/org/mapstruct/Mapping.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct; - -import java.lang.annotation.Annotation; -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.text.SimpleDateFormat; -import java.text.DecimalFormat; -import java.util.Date; - -import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; - -/** - * Configures the mapping of one bean attribute or enum constant. - *

      - * The name of the mapped attribute or constant is to be specified via {@link #target()}. For mapped bean attributes it - * is assumed by default that the attribute has the same name in the source bean. Alternatively, one of - * {@link #source()}, {@link #expression()} or {@link #constant()} can be specified to define the property source. - *

      - * In addition, the attributes {@link #dateFormat()} and {@link #qualifiedBy()} may be used to further define the - * mapping. - * - *

      - * IMPORTANT NOTE: the enum mapping capability is deprecated and replaced by {@link ValueMapping} it - * will be removed in subsequent versions. - * - * @author Gunnar Morling - */ -@Repeatable(Mappings.class) -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface Mapping { - - /** - * The target name of the configured property as defined by the JavaBeans specification. The same target property - * must not be mapped more than once. - *

      - * If used to map an enum constant, the name of the constant member is to be given. In this case, several values - * from the source enum may be mapped to the same value of the target enum. - * - * @return The target name of the configured property or enum constant - */ - String target(); - - /** - * The source to use for this mapping. This can either be: - *

        - *
      1. The source name of the configured property as defined by the JavaBeans specification. - *

        - * This may either be a simple property name (e.g. "address") or a dot-separated property path (e.g. "address.city" - * or "address.city.name"). In case the annotated method has several source parameters, the property name must - * qualified with the parameter name, e.g. "addressParam.city".

      2. - *
      3. When no matching property is found, MapStruct looks for a matching parameter name instead.
      4. - *
      5. When used to map an enum constant, the name of the constant member is to be given.
      6. - *
      - * This attribute can not be used together with {@link #constant()} or {@link #expression()}. - * - * @return The source name of the configured property or enum constant. - */ - String source() default ""; - - /** - * A format string as processable by {@link SimpleDateFormat} if the attribute is mapped from {@code String} to - * {@link Date} or vice-versa. Will be ignored for all other attribute types and when mapping enum constants. - * - * @return A date format string as processable by {@link SimpleDateFormat}. - */ - String dateFormat() default ""; - - /** - * A format string as processable by {@link DecimalFormat} if the annotated method maps from a - * {@link Number} to a {@link String} or vice-versa. Will be ignored for all other element types. - * - * @return A decimal format string as processable by {@link DecimalFormat}. - */ - String numberFormat() default ""; - - /** - * A constant {@link String} based on which the specified target property is to be set. - *

      - * When the designated target property is of type: - *

      - *
        - *
      1. primitive or boxed (e.g. {@code java.lang.Long}). - *

        - * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. - *

        - *
          - *
        • - * If possible, MapStruct assigns as literal. - *
        • - *
        • - * If not possible, MapStruct will try to apply a user defined mapping method. - *
        • - *
        - *
      2. - *
      3. other - *

        - * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, - * type conversion method or built-in conversion. - *

        - *

      4. - *
      - *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, - * {@link #defaultExpression()} or {@link #expression()}. - * - * @return A constant {@code String} constant specifying the value for the designated target property - */ - String constant() default ""; - - /** - * An expression {@link String} based on which the specified target property is to be set. - *

      - * Currently, Java is the only supported "expression language" and expressions must be given in form of Java - * expressions using the following format: {@code java()}. For instance the mapping: - *

      
      -     * @Mapping(
      -     *     target = "someProp",
      -     *     expression = "java(new TimeAndFormat( s.getTime(), s.getFormat() ))"
      -     * )
      -     * 
      - *

      - * will cause the following target property assignment to be generated: - *

      - * {@code targetBean.setSomeProp( new TimeAndFormat( s.getTime(), s.getFormat() ) )}. - *

      - * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be - * imported via {@link Mapper#imports()}. - *

      - * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, - * {@link #defaultExpression()} or {@link #constant()}. - * - * @return An expression specifying the value for the designated target property - */ - String expression() default ""; - - /** - * A defaultExpression {@link String} based on which the specified target property is to be set - * if and only if the specified source property is null. - *

      - * Currently, Java is the only supported "expression language" and expressions must be given in form of Java - * expressions using the following format: {@code java()}. For instance the mapping: - *

      
      -     * @Mapping(
      -     *     target = "someProp",
      -     *     defaultExpression = "java(new TimeAndFormat( s.getTime(), s.getFormat() ))"
      -     * )
      -     * 
      - *

      - * will cause the following target property assignment to be generated: - *

      - * {@code targetBean.setSomeProp( new TimeAndFormat( s.getTime(), s.getFormat() ) )}. - *

      - * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be - * imported via {@link Mapper#imports()}. - *

      - * This attribute can not be used together with {@link #expression()}, {@link #defaultValue()} - * or {@link #constant()}. - * - * @return An expression specifying a defaultValue for the designated target property if the designated source - * property is null - * - * @since 1.3 - */ - String defaultExpression() default ""; - - /** - * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not. - * This can be useful when certain attributes should not be propagated from source or target or when properties in - * the target object are populated using a decorator and thus would be reported as unmapped target property by - * default. - * - * @return {@code true} if the given property should be ignored, {@code false} otherwise - */ - boolean ignore() default false; - - /** - * A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple - * mapping methods (hand written or generated) qualify and thus would result in an 'Ambiguous mapping methods found' - * error. A qualifier is a custom annotation and can be placed on a hand written mapper class or a method. - * - * @return the qualifiers - */ - Class[] qualifiedBy() default { }; - - /** - * String-based form of qualifiers; When looking for a suitable mapping method for a given property, MapStruct will - * only consider those methods carrying directly or indirectly (i.e. on the class-level) a {@link Named} annotation - * for each of the specified qualifier names. - *

      - * Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and - * are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large - * number of qualifiers as no custom annotation types are needed. - * - * @return One or more qualifier name(s) - * @see #qualifiedBy() - * @see Named - */ - String[] qualifiedByName() default { }; - - /** - * Specifies the result type of the mapping method to be used in case multiple mapping methods qualify. - * - * @return the resultType to select - */ - Class resultType() default void.class; - - /** - * One or more properties of the result type on which the mapped property depends. The generated method - * implementation will invoke the setters of the result type ordered so that the given dependency relationship(s) - * are satisfied. Useful in case one property setter depends on the state of another property of the result type. - *

      - * An error will be raised in case a cycle in the dependency relationships is detected. - * - * @return the dependencies of the mapped property - */ - String[] dependsOn() default { }; - - /** - * In case the source property is {@code null}, the provided default {@link String} value is set. - *

      - * When the designated target property is of type: - *

      - *
        - *
      1. primitive or boxed (e.g. {@code java.lang.Long}). - *

        - * MapStruct checks whether the primitive can be assigned as valid literal to the primitive or boxed type. - *

        - *
          - *
        • - * If possible, MapStruct assigns as literal. - *
        • - *
        • - * If not possible, MapStruct will try to apply a user defined mapping method. - *
        • - *
        - *
      2. - *
      3. other - *

        - * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, - * type conversion method or built-in conversion. - *

        - *

      4. - *
      - *

      - * This attribute can not be used together with {@link #constant()}, {@link #expression()} - * or {@link #defaultExpression()}. - * - * @return Default value to set in case the source property is {@code null}. - */ - String defaultValue() default ""; - - /** - * Determines when to include a null check on the source property value of a bean mapping. - * - * Can be overridden by the one on {@link MapperConfig}, {@link Mapper} or {@link BeanMapping}. - * - * @return strategy how to do null checking - */ - NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; - -} diff --git a/core-jdk8/src/main/java/org/mapstruct/Mappings.java b/core-jdk8/src/main/java/org/mapstruct/Mappings.java deleted file mode 100644 index 1e9dd96707..0000000000 --- a/core-jdk8/src/main/java/org/mapstruct/Mappings.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Configures the mappings of several bean attributes. - * - * @author Gunnar Morling - */ -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface Mappings { - - /** - * The configuration of the bean attributes. - * - * @return The configuration of the bean attributes. - */ - Mapping[] value(); -} diff --git a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java b/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java deleted file mode 100644 index 26ed661dce..0000000000 --- a/core-jdk8/src/main/java/org/mapstruct/ValueMapping.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Configures the mapping of source constant value to target constant value. - *

      - * Supported mappings are - *

        - *
      1. Enumeration to Enumeration
      2. - *
      - *

      - * Example 1: - * - *

      - * 
      - * public enum OrderType { RETAIL, B2B, EXTRA, STANDARD, NORMAL }
      - *
      - * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
      - *
      - * @ValueMapping(source = "EXTRA", target = "SPECIAL"),
      - * @ValueMapping(source = "STANDARD", target = "DEFAULT"),
      - * @ValueMapping(source = "NORMAL", target = "DEFAULT")
      - * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
      - * 
      - * Mapping result:
      - * +---------------------+----------------------------+
      - * | OrderType           | ExternalOrderType          |
      - * +---------------------+----------------------------+
      - * | null                | null                       |
      - * | OrderType.EXTRA     | ExternalOrderType.SPECIAL  |
      - * | OrderType.STANDARD  | ExternalOrderType.DEFAULT  |
      - * | OrderType.NORMAL    | ExternalOrderType.DEFAULT  |
      - * | OrderType.RETAIL    | ExternalOrderType.RETAIL   |
      - * | OrderType.B2B       | ExternalOrderType.B2B      |
      - * +---------------------+----------------------------+
      - * 
      - * - * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found an - * {@link java.lang.IllegalStateException} will be thrown. - *

      - * Example 2: - * - *

      - * 
      - * @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      - * @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      - * @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
      - * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
      - * 
      - * Mapping result:
      - * +---------------------+----------------------------+
      - * | OrderType           | ExternalOrderType          |
      - * +---------------------+----------------------------+
      - * | null                | ExternalOrderType.DEFAULT  |
      - * | OrderType.STANDARD  | null                       |
      - * | OrderType.RETAIL    | ExternalOrderType.RETAIL   |
      - * | OrderType.B2B       | ExternalOrderType.B2B      |
      - * | OrderType.NORMAL    | ExternalOrderType.SPECIAL  |
      - * | OrderType.EXTRA     | ExternalOrderType.SPECIAL  |
      - * +---------------------+----------------------------+
      - * 
      - * - * @author Sjaak Derksen - */ -@Repeatable(ValueMappings.class) -@Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) -public @interface ValueMapping { - /** - * The source value constant to use for this mapping. - * - *

      - * Valid values: - *

        - *
      1. enum constant name
      2. - *
      3. {@link MappingConstants#NULL}
      4. - *
      5. {@link MappingConstants#ANY_REMAINING}
      6. - *
      7. {@link MappingConstants#ANY_UNMAPPED}
      8. - *
      - *

      - * NOTE:When using <ANY_REMAINING>, MapStruct will perform the normal name based mapping, in which - * source is mapped to target based on enum identifier equality. Using <ANY_UNMAPPED> will not apply name - * based mapping. - * - * @return The source value. - */ - String source(); - - /** - * The target value constant to use for this mapping. - * - *

      - * Valid values: - *

        - *
      1. enum constant name
      2. - *
      3. {@link MappingConstants#NULL}
      4. - *
      - * - * @return The target value. - */ - String target(); - -} diff --git a/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java b/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java deleted file mode 100644 index f2450a2fd6..0000000000 --- a/core-jdk8/src/main/java/org/mapstruct/ValueMappings.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Constructs a set of value (constant) mappings. - * - * @author Sjaak Derksen - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.CLASS) -public @interface ValueMappings { - - ValueMapping[] value(); - -} diff --git a/core/pom.xml b/core/pom.xml index f6b037f6e4..b566ffe059 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -20,10 +20,6 @@ jar MapStruct Core - - copied-common-sources - - ${project.groupId} @@ -70,44 +66,10 @@
      - - org.codehaus.mojo - build-helper-maven-plugin - - - add-copied-common-sources - generate-sources - - add-source - - - - ${project.build.directory}/${common.sources.dir} - - - - - org.apache.maven.plugins maven-resources-plugin - - copy-resources - process-resources - - copy-resources - - - ${project.build.directory}/${common.sources.dir} - - - ${basedir}/../core-common/src/main/java - false - - - - copy-mapstruct-license prepare-package diff --git a/core-common/src/main/java/org/mapstruct/AfterMapping.java b/core/src/main/java/org/mapstruct/AfterMapping.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/AfterMapping.java rename to core/src/main/java/org/mapstruct/AfterMapping.java diff --git a/core-common/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/BeanMapping.java rename to core/src/main/java/org/mapstruct/BeanMapping.java diff --git a/core-common/src/main/java/org/mapstruct/BeforeMapping.java b/core/src/main/java/org/mapstruct/BeforeMapping.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/BeforeMapping.java rename to core/src/main/java/org/mapstruct/BeforeMapping.java diff --git a/core-common/src/main/java/org/mapstruct/Builder.java b/core/src/main/java/org/mapstruct/Builder.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/Builder.java rename to core/src/main/java/org/mapstruct/Builder.java diff --git a/core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java b/core/src/main/java/org/mapstruct/CollectionMappingStrategy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/CollectionMappingStrategy.java rename to core/src/main/java/org/mapstruct/CollectionMappingStrategy.java diff --git a/core-common/src/main/java/org/mapstruct/Context.java b/core/src/main/java/org/mapstruct/Context.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/Context.java rename to core/src/main/java/org/mapstruct/Context.java diff --git a/core-common/src/main/java/org/mapstruct/DecoratedWith.java b/core/src/main/java/org/mapstruct/DecoratedWith.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/DecoratedWith.java rename to core/src/main/java/org/mapstruct/DecoratedWith.java diff --git a/core-common/src/main/java/org/mapstruct/InheritConfiguration.java b/core/src/main/java/org/mapstruct/InheritConfiguration.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/InheritConfiguration.java rename to core/src/main/java/org/mapstruct/InheritConfiguration.java diff --git a/core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/InheritInverseConfiguration.java rename to core/src/main/java/org/mapstruct/InheritInverseConfiguration.java diff --git a/core-common/src/main/java/org/mapstruct/InjectionStrategy.java b/core/src/main/java/org/mapstruct/InjectionStrategy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/InjectionStrategy.java rename to core/src/main/java/org/mapstruct/InjectionStrategy.java diff --git a/core-common/src/main/java/org/mapstruct/IterableMapping.java b/core/src/main/java/org/mapstruct/IterableMapping.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/IterableMapping.java rename to core/src/main/java/org/mapstruct/IterableMapping.java diff --git a/core-common/src/main/java/org/mapstruct/MapMapping.java b/core/src/main/java/org/mapstruct/MapMapping.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/MapMapping.java rename to core/src/main/java/org/mapstruct/MapMapping.java diff --git a/core-common/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/Mapper.java rename to core/src/main/java/org/mapstruct/Mapper.java diff --git a/core-common/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/MapperConfig.java rename to core/src/main/java/org/mapstruct/MapperConfig.java diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index edf7d55ec6..b6a4dc87e0 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -7,15 +7,15 @@ import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.text.SimpleDateFormat; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.Date; import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; - /** * Configures the mapping of one bean attribute or enum constant. *

      @@ -32,6 +32,8 @@ * * @author Gunnar Morling */ + +@Repeatable(Mappings.class) @Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Mapping { @@ -98,9 +100,6 @@ * If not possible, MapStruct will try to apply a user defined mapping method. * * - *

      - * Please note that grouping underscores and binary literals are not supported in Java 6 - *

      * *
    5. other *

      @@ -207,7 +206,6 @@ */ String[] qualifiedByName() default { }; - /** * Specifies the result type of the mapping method to be used in case multiple mapping methods qualify. * @@ -244,9 +242,6 @@ * If not possible, MapStruct will try to apply a user defined mapping method. *

    6. * - *

      - * Please note that grouping underscores and binary literals are not supported in Java 6 - *

      * *
    7. other *

      diff --git a/core-common/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/MappingConstants.java rename to core/src/main/java/org/mapstruct/MappingConstants.java diff --git a/core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java b/core/src/main/java/org/mapstruct/MappingInheritanceStrategy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/MappingInheritanceStrategy.java rename to core/src/main/java/org/mapstruct/MappingInheritanceStrategy.java diff --git a/core-common/src/main/java/org/mapstruct/MappingTarget.java b/core/src/main/java/org/mapstruct/MappingTarget.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/MappingTarget.java rename to core/src/main/java/org/mapstruct/MappingTarget.java diff --git a/core-common/src/main/java/org/mapstruct/Named.java b/core/src/main/java/org/mapstruct/Named.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/Named.java rename to core/src/main/java/org/mapstruct/Named.java diff --git a/core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/NullValueCheckStrategy.java rename to core/src/main/java/org/mapstruct/NullValueCheckStrategy.java diff --git a/core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValueMappingStrategy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/NullValueMappingStrategy.java rename to core/src/main/java/org/mapstruct/NullValueMappingStrategy.java diff --git a/core-common/src/main/java/org/mapstruct/ObjectFactory.java b/core/src/main/java/org/mapstruct/ObjectFactory.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/ObjectFactory.java rename to core/src/main/java/org/mapstruct/ObjectFactory.java diff --git a/core-common/src/main/java/org/mapstruct/Qualifier.java b/core/src/main/java/org/mapstruct/Qualifier.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/Qualifier.java rename to core/src/main/java/org/mapstruct/Qualifier.java diff --git a/core-common/src/main/java/org/mapstruct/ReportingPolicy.java b/core/src/main/java/org/mapstruct/ReportingPolicy.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/ReportingPolicy.java rename to core/src/main/java/org/mapstruct/ReportingPolicy.java diff --git a/core-common/src/main/java/org/mapstruct/TargetType.java b/core/src/main/java/org/mapstruct/TargetType.java similarity index 100% rename from core-common/src/main/java/org/mapstruct/TargetType.java rename to core/src/main/java/org/mapstruct/TargetType.java diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index f677fb1038..26ed661dce 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -6,6 +6,7 @@ package org.mapstruct; import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -26,11 +27,9 @@ * * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT } * - * @ValueMappings({ - * @ValueMapping(source = "EXTRA", target = "SPECIAL"), - * @ValueMapping(source = "STANDARD", target = "DEFAULT"), - * @ValueMapping(source = "NORMAL", target = "DEFAULT") - * }) + * @ValueMapping(source = "EXTRA", target = "SPECIAL"), + * @ValueMapping(source = "STANDARD", target = "DEFAULT"), + * @ValueMapping(source = "NORMAL", target = "DEFAULT") * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); * * Mapping result: @@ -53,11 +52,9 @@ * *

        * 
      - * @ValueMappings({
      - *    @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      - *    @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      - *    @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
      - * })
      + * @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      + * @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      + * @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
        * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
        * 
        * Mapping result:
      @@ -75,10 +72,10 @@
        *
        * @author Sjaak Derksen
        */
      +@Repeatable(ValueMappings.class)
       @Retention(RetentionPolicy.CLASS)
       @Target(ElementType.METHOD)
       public @interface ValueMapping {
      -
           /**
            * The source value constant to use for this mapping.
            *
      diff --git a/core-common/src/main/java/org/mapstruct/factory/Mappers.java b/core/src/main/java/org/mapstruct/factory/Mappers.java
      similarity index 100%
      rename from core-common/src/main/java/org/mapstruct/factory/Mappers.java
      rename to core/src/main/java/org/mapstruct/factory/Mappers.java
      diff --git a/core-common/src/main/java/org/mapstruct/factory/package-info.java b/core/src/main/java/org/mapstruct/factory/package-info.java
      similarity index 100%
      rename from core-common/src/main/java/org/mapstruct/factory/package-info.java
      rename to core/src/main/java/org/mapstruct/factory/package-info.java
      diff --git a/core-common/src/main/java/org/mapstruct/package-info.java b/core/src/main/java/org/mapstruct/package-info.java
      similarity index 100%
      rename from core-common/src/main/java/org/mapstruct/package-info.java
      rename to core/src/main/java/org/mapstruct/package-info.java
      diff --git a/core-common/src/main/java/org/mapstruct/util/Experimental.java b/core/src/main/java/org/mapstruct/util/Experimental.java
      similarity index 100%
      rename from core-common/src/main/java/org/mapstruct/util/Experimental.java
      rename to core/src/main/java/org/mapstruct/util/Experimental.java
      diff --git a/core-common/src/test/java/org/mapstruct/factory/MappersTest.java b/core/src/test/java/org/mapstruct/factory/MappersTest.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/factory/MappersTest.java
      rename to core/src/test/java/org/mapstruct/factory/MappersTest.java
      diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java b/core/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java
      rename to core/src/test/java/org/mapstruct/factory/PackagePrivateMapper.java
      diff --git a/core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java b/core/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java
      rename to core/src/test/java/org/mapstruct/factory/PackagePrivateMapperImpl.java
      diff --git a/core-common/src/test/java/org/mapstruct/test/model/Foo.java b/core/src/test/java/org/mapstruct/test/model/Foo.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/test/model/Foo.java
      rename to core/src/test/java/org/mapstruct/test/model/Foo.java
      diff --git a/core-common/src/test/java/org/mapstruct/test/model/FooImpl.java b/core/src/test/java/org/mapstruct/test/model/FooImpl.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/test/model/FooImpl.java
      rename to core/src/test/java/org/mapstruct/test/model/FooImpl.java
      diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java b/core/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java
      rename to core/src/test/java/org/mapstruct/test/model/SomeClass$FooImpl.java
      diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java b/core/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java
      rename to core/src/test/java/org/mapstruct/test/model/SomeClass$NestedClass$FooImpl.java
      diff --git a/core-common/src/test/java/org/mapstruct/test/model/SomeClass.java b/core/src/test/java/org/mapstruct/test/model/SomeClass.java
      similarity index 100%
      rename from core-common/src/test/java/org/mapstruct/test/model/SomeClass.java
      rename to core/src/test/java/org/mapstruct/test/model/SomeClass.java
      diff --git a/distribution/pom.xml b/distribution/pom.xml
      index b586a4ba2f..4645262fd4 100644
      --- a/distribution/pom.xml
      +++ b/distribution/pom.xml
      @@ -25,10 +25,6 @@
                   org.mapstruct
                   mapstruct
               
      -        
      -            org.mapstruct
      -            mapstruct-jdk8
      -        
               
                   org.mapstruct
                   mapstruct-processor
      @@ -82,7 +78,6 @@
                       maven-javadoc-plugin
                       
                           
      -                        ${basedir}/../core-common/src/main/java;
                               ${basedir}/../core/src/main/java;
                               ${basedir}/../processor/src/main/java
                           
      diff --git a/distribution/src/main/assembly/dist.xml b/distribution/src/main/assembly/dist.xml
      index 6dee9eeda0..f519e5fc9c 100644
      --- a/distribution/src/main/assembly/dist.xml
      +++ b/distribution/src/main/assembly/dist.xml
      @@ -19,7 +19,6 @@
                   lib
                   
                       org.mapstruct:mapstruct
      -                org.mapstruct:mapstruct-jdk8
                       org.mapstruct:mapstruct-processor
                   
               
      diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc
      index 0f66e90d13..56f6291753 100644
      --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc
      +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc
      @@ -44,7 +44,7 @@ MapStruct is a Java annotation processor based on http://www.jcp.org/en/jsr/deta
       
       It comprises the following artifacts:
       
      -* _org.mapstruct:mapstruct_: contains the required annotations such as `@Mapping`; On Java 8 or later, use _org.mapstruct:mapstruct-jdk8_ instead which takes advantage of language improvements introduced in Java 8
      +* _org.mapstruct:mapstruct_: contains the required annotations such as `@Mapping`
       * _org.mapstruct:mapstruct-processor_: contains the annotation processor which generates mapper implementations
       
       === Apache Maven
      @@ -64,7 +64,7 @@ For Maven based projects add the following to your POM file in order to use MapS
       
           
               org.mapstruct
      -        mapstruct-jdk8
      +        mapstruct
               ${org.mapstruct.version}
           
       
      @@ -107,7 +107,7 @@ If the processor is not kicking in, check that the configuration of annotation p
       To do so, go to "Preferences" -> "Maven" -> "Annotation Processing" and select "Automatically configure JDT APT".
       Alternatively, specify the following in the `properties` section of your POM file: `jdt_apt`.
       
      -Also make sure that your project is using Java 1.6 or later (project properties -> "Java Compiler" -> "Compile Compliance Level").
      +Also make sure that your project is using Java 1.8 or later (project properties -> "Java Compiler" -> "Compile Compliance Level").
       It will not work with older versions.
       ====
       
      @@ -133,7 +133,7 @@ apply plugin: 'net.ltgt.apt-eclipse'
       
       dependencies {
           ...
      -    compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}"
      +    compile "org.mapstruct:mapstruct:${mapstructVersion}"
       
           annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
           // If you are using mapstruct in test code
      @@ -159,7 +159,7 @@ Add the `javac` task configured as follows to your _build.xml_ file in order to
       
      +    classpath="path/to/mapstruct-{mapstructVersion}.jar">
           
           
       
      @@ -347,10 +347,6 @@ public Builder seatCount(int seatCount) {
       ```
       ====
       
      -[TIP]
      -====
      -When using Java 8 or later, you can omit the `@Mappings` wrapper annotation and directly specify several `@Mapping` annotations on one method.
      -====
       
       To get a better understanding of what MapStruct does have a look at the following implementation of the `carToCarDto()` method as generated by MapStruct:
       
      diff --git a/etc/toolchains-cloudbees-jenkins.xml b/etc/toolchains-cloudbees-jenkins.xml
      index e6ce86e063..cf7f0262f3 100644
      --- a/etc/toolchains-cloudbees-jenkins.xml
      +++ b/etc/toolchains-cloudbees-jenkins.xml
      @@ -1,27 +1,5 @@
       
       
      -    
      -        jdk
      -        
      -            1.6
      -            oracle
      -            jdk1.6
      -        
      -        
      -            /opt/jdk/jdk1.6.latest
      -        
      -    
      -    
      -        jdk
      -        
      -            1.7
      -            oracle
      -            jdk1.7
      -        
      -        
      -            /opt/jdk/jdk1.7.latest
      -        
      -    
           
               jdk
               
      @@ -33,5 +11,4 @@
                   /opt/jdk/jdk8.latest
               
           
      -    
       
      diff --git a/etc/toolchains-example.xml b/etc/toolchains-example.xml
      index 08cee8b241..628487ce08 100644
      --- a/etc/toolchains-example.xml
      +++ b/etc/toolchains-example.xml
      @@ -1,27 +1,5 @@
       
       
      -    
      -        jdk
      -        
      -            1.6.0_45
      -            oracle
      -            jdk1.6
      -        
      -        
      -            C:\Program Files\Java\jdk1.6.0_45
      -        
      -    
      -    
      -        jdk
      -        
      -            1.7.0_51
      -            oracle
      -            jdk1.7
      -        
      -        
      -            C:\Program Files\Java\jdk1.7.0_51
      -        
      -    
           
               jdk
               
      diff --git a/etc/toolchains-travis-jenkins.xml b/etc/toolchains-travis-jenkins.xml
      index 75ac0de574..0668c72b97 100644
      --- a/etc/toolchains-travis-jenkins.xml
      +++ b/etc/toolchains-travis-jenkins.xml
      @@ -1,27 +1,6 @@
       
       
      -    
      -        jdk
      -        
      -            1.6
      -            oracle
      -            jdk1.6
      -        
      -        
      -            /usr/lib/jvm/java-6-openjdk-amd64/
      -        
      -    
      -    
      -        jdk
      -        
      -            1.7
      -            oracle
      -            jdk1.7
      -        
      -        
      -            /usr/lib/jvm/java-7-openjdk-amd64/
      -        
      -    
      +
           
               jdk
               
      diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml
      index 820ba733f8..18082e0a03 100644
      --- a/integrationtest/pom.xml
      +++ b/integrationtest/pom.xml
      @@ -59,14 +59,6 @@
                           \
                       
                   
      -            
      -                org.apache.maven.plugins
      -                maven-compiler-plugin
      -                
      -                    1.8
      -                    1.8
      -                
      -            
                   
                       org.apache.maven.plugins
                       maven-surefire-plugin
      diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java
      index ba73357dc9..fe3836e306 100644
      --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java
      +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java
      @@ -34,12 +34,8 @@
           baseDir = "fullFeatureTest",
           commandLineEnhancer = CompilationExclusionCliEnhancer.class,
           processorTypes = {
      -        ProcessorType.ORACLE_JAVA_6,
      -        ProcessorType.ORACLE_JAVA_7,
               ProcessorType.ORACLE_JAVA_8,
               ProcessorType.ORACLE_JAVA_9,
      -        ProcessorType.ECLIPSE_JDT_JAVA_6,
      -        ProcessorType.ECLIPSE_JDT_JAVA_7,
               ProcessorType.ECLIPSE_JDT_JAVA_8
       })
       public class FullFeatureCompilationTest {
      @@ -57,15 +53,6 @@ public Collection getAdditionalCommandLineArguments(ProcessorType proces
                   additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" );
       
                   switch ( processorType ) {
      -                case ORACLE_JAVA_6:
      -                    additionalExcludes.add( "org/mapstruct/ap/test/abstractclass/generics/*.java" );
      -                    additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1170/*.java" );
      -                case ECLIPSE_JDT_JAVA_6:
      -                case ORACLE_JAVA_7:
      -                case ECLIPSE_JDT_JAVA_7:
      -                    additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1425/*.java" );
      -                    additionalExcludes.add( "**/java8*/**/*.java" );
      -                    break;
                       case ORACLE_JAVA_9:
                           // TODO find out why this fails:
                           additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" );
      diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java
      index ff5ef418b1..7199cb1f34 100644
      --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java
      +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java
      @@ -15,8 +15,6 @@
       @RunWith( ProcessorSuiteRunner.class )
       @ProcessorSuite( baseDir = "lombokBuilderTest",
           processorTypes = {
      -        ProcessorSuite.ProcessorType.ORACLE_JAVA_6,
      -        ProcessorSuite.ProcessorType.ORACLE_JAVA_7,
               ProcessorSuite.ProcessorType.ORACLE_JAVA_8,
               ProcessorSuite.ProcessorType.ORACLE_JAVA_9,
           }
      diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java
      index 7e52bed06a..cf648ca3c8 100644
      --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java
      +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java
      @@ -17,12 +17,8 @@
       @RunWith(ProcessorSuiteRunner.class)
       @ProcessorSuite(baseDir = "protobufBuilderTest",
           processorTypes = {
      -        ProcessorSuite.ProcessorType.ORACLE_JAVA_6,
      -        ProcessorSuite.ProcessorType.ORACLE_JAVA_7,
               ProcessorSuite.ProcessorType.ORACLE_JAVA_8,
               ProcessorSuite.ProcessorType.ORACLE_JAVA_9,
      -        ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_6,
      -        ProcessorSuite.ProcessorType.ECLIPSE_JDT_JAVA_7
           })
       public class ProtobufBuilderTest {
       }
      diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java
      index 96f3aa00d9..916d513954 100644
      --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java
      +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java
      @@ -5,6 +5,8 @@
        */
       package org.mapstruct.itest.testutil.runner;
       
      +import org.apache.maven.it.Verifier;
      +
       import java.lang.annotation.Documented;
       import java.lang.annotation.ElementType;
       import java.lang.annotation.Retention;
      @@ -12,8 +14,6 @@
       import java.lang.annotation.Target;
       import java.util.Collection;
       
      -import org.apache.maven.it.Verifier;
      -
       /**
        * Declares the content of the integration test.
        * 

      @@ -39,15 +39,6 @@ * @author Andreas Gudian */ enum ProcessorType { - /** - * Use an Oracle JDK 1.6 (or 1.6.x) via toolchain support to perform the processing - */ - ORACLE_JAVA_6( new Toolchain( "oracle", "1.6", "1.7" ), "javac", "1.6" ), - - /** - * Use an Oracle JDK 1.7 (or 1.7.x) via toolchain support to perform the processing - */ - ORACLE_JAVA_7( new Toolchain( "oracle", "1.7", "1.8" ), "javac", "1.7" ), /** * Use the same JDK that runs the mvn build to perform the processing @@ -59,18 +50,6 @@ enum ProcessorType { */ ORACLE_JAVA_9( new Toolchain( "oracle", "9", "10" ), "javac", "1.9" ), - /** - * Use the eclipse compiler with 1.6 source/target level from tycho-compiler-jdt to perform the build and - * processing - */ - ECLIPSE_JDT_JAVA_6( null, "jdt", "1.6" ), - - /** - * Use the eclipse compiler with 1.7 source/target level from tycho-compiler-jdt to perform the build and - * processing - */ - ECLIPSE_JDT_JAVA_7( null, "jdt", "1.7" ), - /** * Use the eclipse compiler with 1.8 source/target level from tycho-compiler-jdt to perform the build and * processing @@ -86,14 +65,12 @@ enum ProcessorType { /** * Use all processing variants, but without the maven-procesor-plugin */ - ALL_WITHOUT_PROCESSOR_PLUGIN(ORACLE_JAVA_6, ORACLE_JAVA_7, ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_6, - ECLIPSE_JDT_JAVA_7, ECLIPSE_JDT_JAVA_8), + ALL_WITHOUT_PROCESSOR_PLUGIN( ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_8), /** * Use all available processing variants */ - ALL( ORACLE_JAVA_6, ORACLE_JAVA_7, ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_6, ECLIPSE_JDT_JAVA_7, - ECLIPSE_JDT_JAVA_8, PROCESSOR_PLUGIN_JAVA_8 ), + ALL( ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_8, PROCESSOR_PLUGIN_JAVA_8 ), /** * Use all JDK8 compatible processing variants diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java index 92f02abf70..c2d20e0568 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java @@ -200,13 +200,7 @@ private void doExecute(ProcessorTestCase child, Description description) throws verifier.addCliOption( "-Dcompiler-source-target-version=" + child.processor.getSourceTargetVersion() ); - if ( "1.8".equals( child.processor.getSourceTargetVersion() ) - || "1.9".equals( child.processor.getSourceTargetVersion() ) ) { - verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct-jdk8" ); - } - else { - verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct" ); - } + verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct" ); if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) { originalOut.print( "Processor Integration Test: " ); diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml index 234a321b1c..1b84638ef2 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml @@ -34,8 +34,6 @@ maven-compiler-plugin 3.1 - 1.6 - 1.6 -proc:none diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml index 8cdd33fec6..07e89a9808 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml @@ -41,8 +41,6 @@ maven-compiler-plugin 3.1 - 1.6 - 1.6 -XprintProcessorInfo -XprintRounds diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml index 60f50ac616..bf0d704851 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml @@ -34,8 +34,6 @@ maven-compiler-plugin 3.1 - 1.6 - 1.6 -proc:none diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml index 5aa83327cb..8b0852ff07 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -41,8 +41,6 @@ maven-compiler-plugin 3.1 - 1.6 - 1.6 -XprintProcessorInfo -XprintRounds diff --git a/parent/pom.xml b/parent/pom.xml index 332ab2ff23..5bdd07ce70 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -242,11 +242,6 @@ mapstruct ${project.version} - - ${project.groupId} - mapstruct-jdk8 - ${project.version} - ${project.groupId} mapstruct-processor @@ -320,10 +315,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 + 3.8.0 - 1.6 - 1.6 + 1.8 + 1.8 -proc:none @@ -440,7 +435,7 @@ org.apache.maven.plugins maven-shade-plugin - 2.3 + 3.2.0 com.mycila.maven-license-plugin @@ -460,12 +455,12 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.9 + 1.16 org.ow2.asm asm-all - 5.0.2 + 5.2 diff --git a/pom.xml b/pom.xml index e24bfdd30a..2786ef835f 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,6 @@ parent build-config - core-common core core-jdk8 processor From 71e9bd3699d1a295bf51abb7d685a093cfc1aa6f Mon Sep 17 00:00:00 2001 From: Florian Tavares Date: Fri, 19 Oct 2018 21:36:07 +0200 Subject: [PATCH 0289/1006] #1301 code improvements / adaptations after language-level upgrade --- core/pom.xml | 5 -- .../java/org/mapstruct/factory/Mappers.java | 15 ++---- parent/pom.xml | 5 -- .../org/mapstruct/ap/MappingProcessor.java | 8 ++-- .../BigDecimalToStringConversion.java | 2 +- .../BigIntegerToStringConversion.java | 2 +- .../ap/internal/conversion/Conversions.java | 2 +- .../internal/model/AnnotatedConstructor.java | 2 +- .../model/AnnotationMapperReference.java | 2 +- .../ap/internal/model/BeanMappingMethod.java | 28 +++++------ .../model/ContainerMappingMethodBuilder.java | 4 +- .../ap/internal/model/EnumMappingMethod.java | 8 ++-- .../mapstruct/ap/internal/model/Field.java | 2 +- .../ap/internal/model/GeneratedType.java | 6 +-- .../ap/internal/model/HelperMethod.java | 2 +- .../ap/internal/model/IterableCreation.java | 2 +- .../model/LifecycleMethodResolver.java | 8 ++-- .../ap/internal/model/MapMappingMethod.java | 6 +-- .../internal/model/MappingBuilderContext.java | 6 +-- .../ap/internal/model/MappingMethod.java | 12 ++--- .../ap/internal/model/MethodReference.java | 6 +-- .../model/NestedPropertyMappingMethod.java | 6 +-- .../NestedTargetPropertyMappingHolder.java | 46 +++++++++---------- .../model/ObjectFactoryMethodResolver.java | 2 +- .../ap/internal/model/PropertyMapping.java | 2 +- .../internal/model/StreamMappingMethod.java | 2 +- .../ap/internal/model/TypeConversion.java | 2 +- .../ap/internal/model/ValueMappingMethod.java | 12 ++--- .../model/assignment/AdderWrapper.java | 4 +- .../model/assignment/ArrayCopyWrapper.java | 2 +- .../model/assignment/EnumConstantWrapper.java | 2 +- .../GetterWrapperForCollectionsAndMaps.java | 2 +- .../assignment/Java8FunctionWrapper.java | 2 +- .../model/assignment/LocalVarWrapper.java | 4 +- .../model/assignment/SetterWrapper.java | 2 +- ...perForCollectionsAndMapsWithNullCheck.java | 2 +- .../model/assignment/StreamAdderWrapper.java | 4 +- .../model/assignment/UpdateWrapper.java | 4 +- .../WrapperForCollectionsAndMaps.java | 2 +- .../ap/internal/model/common/Parameter.java | 4 +- .../model/common/ParameterBinding.java | 2 +- .../ap/internal/model/common/Type.java | 23 +++++----- .../ap/internal/model/common/TypeFactory.java | 16 +++---- .../model/dependency/GraphAnalyzer.java | 8 ++-- .../ap/internal/model/dependency/Node.java | 2 +- .../internal/model/source/ForgedMethod.java | 8 ++-- .../ap/internal/model/source/Mapping.java | 4 +- .../internal/model/source/MappingOptions.java | 12 ++--- .../internal/model/source/MethodMatcher.java | 2 +- .../source/ParameterProvidedMethods.java | 6 +-- .../internal/model/source/SourceMethod.java | 10 ++-- .../model/source/SourceReference.java | 14 +++--- .../model/source/TargetReference.java | 8 ++-- .../source/builtin/BuiltInMappingMethods.java | 2 +- .../model/source/builtin/BuiltInMethod.java | 2 +- .../selector/CreateOrUpdateSelector.java | 4 +- .../selector/FactoryParameterSelector.java | 2 +- .../source/selector/InheritanceSelector.java | 2 +- .../source/selector/MethodFamilySelector.java | 2 +- .../source/selector/MethodSelectors.java | 4 +- .../source/selector/QualifierSelector.java | 10 ++-- .../source/selector/SelectionCriteria.java | 4 +- .../source/selector/TargetTypeSelector.java | 2 +- .../model/source/selector/TypeSelector.java | 18 ++++---- .../selector/XmlElementDeclSelector.java | 6 +-- ...nnotationBasedComponentModelProcessor.java | 12 ++--- .../processor/MapperCreationProcessor.java | 32 ++++++------- .../processor/MethodRetrievalProcessor.java | 14 +++--- .../processor/SpringComponentProcessor.java | 2 +- .../creation/MappingResolverImpl.java | 16 +++---- .../util/AnnotationProcessorContext.java | 2 +- .../ap/internal/util/Collections.java | 42 ++++------------- .../ap/internal/util/Executables.java | 13 ++---- .../mapstruct/ap/internal/util/Filters.java | 10 ++-- .../ap/internal/util/MapperConfiguration.java | 2 +- .../ap/internal/util/NativeTypes.java | 10 ++-- .../ap/internal/util/RoundContext.java | 2 +- .../mapstruct/ap/internal/util/Strings.java | 2 +- .../EclipseAsMemberOfWorkaround.java | 4 +- .../writer/ModelIncludeDirective.java | 10 +--- .../ap/internal/writer/ModelWriter.java | 4 +- .../ap/spi/DefaultBuilderProvider.java | 4 +- 82 files changed, 270 insertions(+), 323 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b566ffe059..fe993959b8 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -21,11 +21,6 @@ MapStruct Core - - ${project.groupId} - mapstruct-common - true - junit junit diff --git a/core/src/main/java/org/mapstruct/factory/Mappers.java b/core/src/main/java/org/mapstruct/factory/Mappers.java index 85c673b127..ac479d3646 100644 --- a/core/src/main/java/org/mapstruct/factory/Mappers.java +++ b/core/src/main/java/org/mapstruct/factory/Mappers.java @@ -53,7 +53,7 @@ private Mappers() { */ public static T getMapper(Class clazz) { try { - List classLoaders = new ArrayList( 3 ); + List classLoaders = new ArrayList<>( 3 ); classLoaders.add( clazz.getClassLoader() ); if ( Thread.currentThread().getContextClassLoader() != null ) { @@ -64,10 +64,7 @@ public static T getMapper(Class clazz) { return getMapper( clazz, classLoaders ); } - catch ( ClassNotFoundException e ) { - throw new RuntimeException( e ); - } - catch ( NoSuchMethodException e) { + catch ( ClassNotFoundException | NoSuchMethodException e ) { throw new RuntimeException( e ); } } @@ -106,13 +103,7 @@ private static T doGetMapper(Class clazz, ClassLoader classLoader) throws return null; } - catch (InstantiationException e) { - throw new RuntimeException( e ); - } - catch (IllegalAccessException e) { - throw new RuntimeException( e ); - } - catch (InvocationTargetException e) { + catch ( InstantiationException | InvocationTargetException | IllegalAccessException e) { throw new RuntimeException( e ); } } diff --git a/parent/pom.xml b/parent/pom.xml index 5bdd07ce70..0ac7060b03 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -232,11 +232,6 @@ - - ${project.groupId} - mapstruct-common - ${project.version} - ${project.groupId} mapstruct diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 05f52d3af4..c277ba5c3a 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -107,7 +107,7 @@ public class MappingProcessor extends AbstractProcessor { * generated by other processors), this mapper will not be generated; That's fine, the compiler will raise an error * due to the inconsistent Java types used as source or target anyways. */ - private Set deferredMappers = new HashSet(); + private Set deferredMappers = new HashSet<>(); @Override public synchronized void init(ProcessingEnvironment processingEnv) { @@ -157,7 +157,7 @@ public boolean process(final Set annotations, final Round * erroneous source/target type elements). */ private Set getAndResetDeferredMappers() { - Set deferred = new HashSet( deferredMappers.size() ); + Set deferred = new HashSet<>( deferredMappers.size() ); for (TypeElement element : deferredMappers ) { deferred.add( processingEnv.getElementUtils().getTypeElement( element.getQualifiedName() ) ); @@ -169,7 +169,7 @@ private Set getAndResetDeferredMappers() { private Set getMappers(final Set annotations, final RoundEnvironment roundEnvironment) { - Set mapperTypes = new HashSet(); + Set mapperTypes = new HashSet<>(); for ( TypeElement annotation : annotations ) { //Indicates that the annotation's type isn't on the class path of the compiled @@ -283,7 +283,7 @@ private R process(ProcessorContext context, ModelElementProcessor p MappingProcessor.class.getClassLoader() ) .iterator(); - List> processors = new ArrayList>(); + List> processors = new ArrayList<>(); while ( processorIterator.hasNext() ) { processors.add( processorIterator.next() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index 391df2fa68..d696cf5bb5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -62,7 +62,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList<>(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index 56f167829f..9cb1cf41cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -70,7 +70,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - List helpers = new ArrayList(); + List helpers = new ArrayList<>(); if ( conversionContext.getNumberFormat() != null ) { helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 70e04146a3..3bf9ccade8 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -30,7 +30,7 @@ */ public class Conversions { - private final Map conversions = new HashMap(); + private final Map conversions = new HashMap<>(); private final Type enumType; private final Type stringType; private final TypeFactory typeFactory; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java index d9feb2b1d4..1c38b1062b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java @@ -70,7 +70,7 @@ private AnnotatedConstructor(String name, List mapper @Override public Set getImportTypes() { - Set types = new HashSet(); + Set types = new HashSet<>(); for ( MapperReference mapperReference : mapperReferences ) { types.addAll( mapperReference.getImportTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java index 9deaff561f..4cb78ea4f8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotationMapperReference.java @@ -42,7 +42,7 @@ public List getAnnotations() { @Override public Set getImportTypes() { - Set types = new HashSet(); + Set types = new HashSet<>(); types.add( getType() ); for ( Annotation annotation : annotations ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 16546f4010..1dff9c196a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -73,12 +73,12 @@ public static class Builder { private Map unprocessedTargetProperties; private Map unprocessedSourceProperties; private Set targetProperties; - private final List propertyMappings = new ArrayList(); - private final Set unprocessedSourceParameters = new HashSet(); - private final Set existingVariableNames = new HashSet(); + private final List propertyMappings = new ArrayList<>(); + private final Set unprocessedSourceParameters = new HashSet<>(); + private final Set existingVariableNames = new HashSet<>(); private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; - private final Map> unprocessedDefinedTargets = new HashMap>(); + private final Map> unprocessedDefinedTargets = new HashMap<>(); public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -108,8 +108,8 @@ private Builder setupMethodWithMapping(Method sourceMethod) { .getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); - this.unprocessedTargetProperties = new LinkedHashMap( accessors ); - this.unprocessedSourceProperties = new LinkedHashMap(); + this.unprocessedTargetProperties = new LinkedHashMap<>( accessors ); + this.unprocessedSourceProperties = new LinkedHashMap<>(); for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); @@ -335,7 +335,7 @@ private void sortPropertyMappingsByDependencies() { final GraphAnalyzer graphAnalyzer = graphAnalyzerBuilder.build(); if ( !graphAnalyzer.getCycles().isEmpty() ) { - Set cycles = new HashSet(); + Set cycles = new HashSet<>(); for ( List cycle : graphAnalyzer.getCycles() ) { cycles.add( Strings.join( cycle, " -> " ) ); } @@ -371,7 +371,7 @@ public int compare(PropertyMapping o1, PropertyMapping o2) { private boolean handleDefinedMappings() { boolean errorOccurred = false; - Set handledTargets = new HashSet(); + Set handledTargets = new HashSet<>(); // first we have to handle nested target mappings if ( method.getMappingOptions().hasNestedTargetReferences() ) { @@ -676,7 +676,7 @@ private MappingOptions extractAdditionalOptions(String targetProperty, boolean r MappingOptions additionalOptions = null; if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { - Map> mappings = new HashMap>(); + Map> mappings = new HashMap<>(); for ( Mapping mapping : unprocessedDefinedTargets.get( targetProperty ) ) { mappings.put( mapping.getTargetName(), Collections.singletonList( mapping ) ); } @@ -828,10 +828,10 @@ private BeanMappingMethod(Method method, // intialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. - this.mappingsByParameter = new HashMap>(); - this.constantMappings = new ArrayList( propertyMappings ); + this.mappingsByParameter = new HashMap<>(); + this.constantMappings = new ArrayList<>( propertyMappings ); for ( Parameter sourceParameter : getSourceParameters() ) { - ArrayList mappingsOfParameter = new ArrayList(); + ArrayList mappingsOfParameter = new ArrayList<>(); mappingsByParameter.put( sourceParameter.getName(), mappingsOfParameter ); for ( PropertyMapping mapping : propertyMappings ) { if ( sourceParameter.getName().equals( mapping.getSourceBeanName() ) ) { @@ -890,7 +890,7 @@ public Set getImportTypes() { } public List getSourceParametersExcludingPrimitives() { - List sourceParameters = new ArrayList(); + List sourceParameters = new ArrayList<>(); for ( Parameter sourceParam : getSourceParameters() ) { if ( !sourceParam.getType().isPrimitive() ) { sourceParameters.add( sourceParam ); @@ -901,7 +901,7 @@ public List getSourceParametersExcludingPrimitives() { } public List getSourcePrimitiveParameters() { - List sourceParameters = new ArrayList(); + List sourceParameters = new ArrayList<>(); for ( Parameter sourceParam : getSourceParameters() ) { if ( sourceParam.getType().isPrimitive() ) { sourceParameters.add( sourceParam ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 5cd610c20d..efe6d5401b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -78,7 +78,7 @@ public final M build() { SourceRHS sourceRHS = new SourceRHS( loopVariableName, sourceElementType, - new HashSet(), + new HashSet<>(), errorMessagePart ); Assignment assignment = ctx.getMappingResolver().getTargetAssignment( @@ -128,7 +128,7 @@ else if ( method instanceof ForgedMethod ) { factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, method.getResultType(), null, ctx ); } - Set existingVariables = new HashSet( method.getParameterNames() ); + Set existingVariables = new HashSet<>( method.getParameterNames() ); existingVariables.add( loopVariableName ); List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java index 8fb346db2a..53d2e5ec29 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java @@ -57,7 +57,7 @@ public EnumMappingMethod build() { return null; } - List enumMappings = new ArrayList(); + List enumMappings = new ArrayList<>(); List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); @@ -75,7 +75,7 @@ enumConstant, first( mappedConstants ).getTargetName() ); } else { - List targetConstants = new ArrayList( mappedConstants.size() ); + List targetConstants = new ArrayList<>( mappedConstants.size() ); for ( Mapping mapping : mappedConstants ) { targetConstants.add( mapping.getTargetName() ); } @@ -89,7 +89,7 @@ enumConstant, first( mappedConstants ).getTargetName() SelectionParameters selectionParameters = getSelecionParameters( method, ctx.getTypeUtils() ); - Set existingVariables = new HashSet( method.getParameterNames() ); + Set existingVariables = new HashSet<>( method.getParameterNames() ); List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = @@ -163,7 +163,7 @@ private boolean reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConsta List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); List targetEnumConstants = method.getReturnType().getEnumConstants(); - List unmappedSourceEnumConstants = new ArrayList(); + List unmappedSourceEnumConstants = new ArrayList<>(); for ( String sourceEnumConstant : sourceEnumConstants ) { if ( !targetEnumConstants.contains( sourceEnumConstant ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index a47c44f6dc..2f2df4b1fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -118,7 +118,7 @@ public boolean equals(Object obj) { } public static List getFieldNames(Set fields) { - List names = new ArrayList( fields.size() ); + List names = new ArrayList<>( fields.size() ); for ( Field field : fields ) { names.add( field.getVariableName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 5404d0d950..92f10c5293 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -65,7 +65,7 @@ protected GeneratedType(TypeFactory typeFactory, String packageName, String name this.interfaceName = interfaceName; this.extraImportedTypes = extraImportedTypes; - this.annotations = new ArrayList(); + this.annotations = new ArrayList<>(); this.methods = methods; this.fields = fields; @@ -163,7 +163,7 @@ public void setConstructor(Constructor constructor) { @Override public SortedSet getImportTypes() { - SortedSet importedTypes = new TreeSet(); + SortedSet importedTypes = new TreeSet<>(); addIfImportRequired( importedTypes, generatedType ); for ( MappingMethod mappingMethod : methods ) { @@ -198,7 +198,7 @@ public SortedSet getImportTypes() { } public SortedSet getImportTypeNames() { - SortedSet importTypeNames = new TreeSet(); + SortedSet importTypeNames = new TreeSet<>(); for ( Type type : getImportTypes() ) { importTypeNames.add( type.getImportName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 7711c15cfb..72e062cca8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -205,7 +205,7 @@ public Type getResultType() { @Override public List getParameterNames() { - List parameterNames = new ArrayList( getParameters().size() ); + List parameterNames = new ArrayList<>( getParameters().size() ); for ( Parameter parameter : getParameters() ) { parameterNames.add( parameter.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java index 522b3476a1..75dbe53fbd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -65,7 +65,7 @@ public boolean isLoadFactorAdjustment() { @Override public Set getImportTypes() { - Set types = new HashSet(); + Set types = new HashSet<>(); if ( factoryMethod == null && resultType.getImplementationType() != null ) { types.addAll( resultType.getImplementationType().getImportTypes() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index edafa5d393..de7ebe13fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -76,7 +76,7 @@ private static List getAllAvailableMethods(Method method, List availableMethods = - new ArrayList( methodsProvidedByParams.size() + sourceModelMethods.size() ); + new ArrayList<>( methodsProvidedByParams.size() + sourceModelMethods.size() ); for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { availableMethods.add( methodProvidedByParams ); @@ -118,7 +118,7 @@ private static List toLifecycleCallbackMethodR MappingBuilderContext ctx, Set existingVariableNames) { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( SelectedMethod candidate : candidates ) { Parameter providingParameter = method.getContextProvidedMethods().getParameterForProvidedMethod( candidate.getMethod() ); @@ -146,7 +146,7 @@ private static List toLifecycleCallbackMethodR } private static List filterBeforeMappingMethods(List methods) { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( SourceMethod method : methods ) { if ( method.isBeforeMappingMethod() ) { result.add( method ); @@ -157,7 +157,7 @@ private static List filterBeforeMappingMethods(List } private static List filterAfterMappingMethods(List methods) { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( SourceMethod method : methods ) { if ( method.isAfterMappingMethod() ) { result.add( method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index e4075757da..b429d96f27 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -84,7 +84,7 @@ public MapMappingMethod build() { Type keySourceType = sourceTypeParams.get( 0 ).getTypeBound(); Type keyTargetType = resultTypeParams.get( 0 ).getTypeBound(); - SourceRHS keySourceRHS = new SourceRHS( "entry.getKey()", keySourceType, new HashSet(), "map key" ); + SourceRHS keySourceRHS = new SourceRHS( "entry.getKey()", keySourceType, new HashSet<>(), "map key" ); Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method, keyTargetType, @@ -124,7 +124,7 @@ public MapMappingMethod build() { Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound(); Type valueTargetType = resultTypeParams.get( 1 ).getTypeBound(); - SourceRHS valueSourceRHS = new SourceRHS( "entry.getValue()", valueSourceType, new HashSet(), + SourceRHS valueSourceRHS = new SourceRHS( "entry.getValue()", valueSourceType, new HashSet<>(), "map value" ); Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method, @@ -185,7 +185,7 @@ public MapMappingMethod build() { keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes(), valueTargetType, false ); - Set existingVariables = new HashSet( method.getParameterNames() ); + Set existingVariables = new HashSet<>( method.getParameterNames() ); List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( method, null, ctx, existingVariables ); List afterMappingMethods = diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 48ee36be0d..5832554809 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -107,9 +107,9 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, String tar private final List sourceModel; private final List mapperReferences; private final MappingResolver mappingResolver; - private final List mappingsToGenerate = new ArrayList(); + private final List mappingsToGenerate = new ArrayList<>(); private final Map forgedMethodsUnderCreation = - new HashMap( ); + new HashMap<>(); public MappingBuilderContext(TypeFactory typeFactory, Elements elementUtils, @@ -191,7 +191,7 @@ public List getMappingsToGenerate() { } public List getNamesOfMappingsToGenerate() { - List nameList = new ArrayList(); + List nameList = new ArrayList<>(); for ( MappingMethod method : mappingsToGenerate ) { nameList.add( method.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 0a23001d0f..4691c9cdf7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -73,16 +73,16 @@ protected MappingMethod(Method method, List parameters, Collection parameters) { - this( method, parameters, new ArrayList( method.getParameterNames() ), null, null ); + this( method, parameters, new ArrayList<>( method.getParameterNames() ), null, null ); } protected MappingMethod(Method method) { - this( method, new ArrayList( method.getParameterNames() ), null, null ); + this( method, new ArrayList<>( method.getParameterNames() ), null, null ); } protected MappingMethod(Method method, List beforeMappingReferences, List afterMappingReferences) { - this( method, new ArrayList( method.getParameterNames() ), beforeMappingReferences, + this( method, new ArrayList<>( method.getParameterNames() ), beforeMappingReferences, afterMappingReferences ); } @@ -140,7 +140,7 @@ public boolean isStatic() { @Override public Set getImportTypes() { - Set types = new HashSet(); + Set types = new HashSet<>(); for ( Parameter param : parameters ) { types.addAll( param.getType().getImportTypes() ); @@ -156,7 +156,7 @@ public Set getImportTypes() { } protected List getParameterNames() { - List parameterNames = new ArrayList( parameters.size() ); + List parameterNames = new ArrayList<>( parameters.size() ); for ( Parameter parameter : parameters ) { parameterNames.add( parameter.getName() ); @@ -181,7 +181,7 @@ private List filterMappingTarget(List result = - new ArrayList( methods.size() ); + new ArrayList<>( methods.size() ); for ( LifecycleCallbackMethodReference method : methods ) { if ( mustHaveMappingTargetParameter == method.hasMappingTargetParameter() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index b92dc77a2c..207b4c153b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -72,7 +72,7 @@ protected MethodReference(Method method, MapperReference declaringMapper, Parame this.providingParameter = providingParameter; this.parameterBindings = parameterBindings; this.contextParam = null; - Set imported = new HashSet(); + Set imported = new HashSet<>(); for ( Type type : method.getThrownTypes() ) { imported.addAll( type.getImportTypes() ); @@ -211,7 +211,7 @@ public Type getDefiningType() { @Override public Set getImportTypes() { - Set imported = new HashSet( importTypes ); + Set imported = new HashSet<>( importTypes ); if ( assignment != null ) { imported.addAll( assignment.getImportTypes() ); } @@ -223,7 +223,7 @@ public Set getImportTypes() { @Override public List getThrownTypes() { - List exceptions = new ArrayList(); + List exceptions = new ArrayList<>(); exceptions.addAll( thrownTypes ); if ( assignment != null ) { exceptions.addAll( assignment.getThrownTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index f77218431a..c004baebb7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -51,12 +51,12 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { } public NestedPropertyMappingMethod build() { - List existingVariableNames = new ArrayList(); + List existingVariableNames = new ArrayList<>(); for ( Parameter parameter : method.getSourceParameters() ) { existingVariableNames.add( parameter.getName() ); } - final List thrownTypes = new ArrayList(); - List safePropertyEntries = new ArrayList(); + final List thrownTypes = new ArrayList<>(); + List safePropertyEntries = new ArrayList<>(); for ( PropertyEntry propertyEntry : propertyEntries ) { String safeName = Strings.getSafeVariableName( propertyEntry.getName(), existingVariableNames ); safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 7f7b875413..2cf9b258e4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -125,15 +125,15 @@ public Builder existingVariableNames(Set existingVariableNames) { } public NestedTargetPropertyMappingHolder build() { - List processedSourceParameters = new ArrayList(); - handledTargets = new HashSet(); - propertyMappings = new ArrayList(); + List processedSourceParameters = new ArrayList<>(); + handledTargets = new HashSet<>(); + propertyMappings = new ArrayList<>(); // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); Map> unprocessedDefinedTarget - = new LinkedHashMap>(); + = new LinkedHashMap<>(); for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { PropertyEntry targetProperty = entryByTP.getKey(); @@ -275,7 +275,7 @@ private void handleSourceParameterMappings(List sourceParameterMappings if ( !sourceParameterMappings.isEmpty() ) { // The source parameter mappings have no mappings, the source name is actually the parameter itself MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( - new HashMap>(), + new HashMap<>(), false, true ); @@ -349,9 +349,9 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp Map> mappings = mappingOptions.getMappings(); // group all mappings based on the top level name before popping Map> mappingsKeyedByProperty - = new LinkedHashMap>(); + = new LinkedHashMap<>(); Map> singleTargetReferences - = new LinkedHashMap>(); + = new LinkedHashMap<>(); boolean errorOccurred = false; for ( List mapping : mappings.values() ) { Mapping firstMapping = first( mapping ); @@ -365,13 +365,13 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp if ( newMapping != null ) { // group properties on current name. if ( !mappingsKeyedByProperty.containsKey( property ) ) { - mappingsKeyedByProperty.put( property, new ArrayList() ); + mappingsKeyedByProperty.put( property, new ArrayList<>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } else { if ( !singleTargetReferences.containsKey( property ) ) { - singleTargetReferences.put( property, new ArrayList() ); + singleTargetReferences.put( property, new ArrayList<>() ); } singleTargetReferences.get( property ).add( firstMapping ); } @@ -466,13 +466,13 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp private GroupedBySourceParameters groupBySourceParameter(List mappings, List singleTargetReferences) { - Map> mappingsKeyedByParameter = new LinkedHashMap>(); - List appliesToAll = new ArrayList(); + Map> mappingsKeyedByParameter = new LinkedHashMap<>(); + List appliesToAll = new ArrayList<>(); for ( Mapping mapping : mappings ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { Parameter parameter = mapping.getSourceReference().getParameter(); if ( !mappingsKeyedByParameter.containsKey( parameter ) ) { - mappingsKeyedByParameter.put( parameter, new ArrayList() ); + mappingsKeyedByParameter.put( parameter, new ArrayList<>() ); } mappingsKeyedByParameter.get( parameter ).add( mapping ); } @@ -492,7 +492,7 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, } List notProcessAppliesToAll = - mappingsKeyedByParameter.isEmpty() ? appliesToAll : new ArrayList(); + mappingsKeyedByParameter.isEmpty() ? appliesToAll : new ArrayList<>(); return new GroupedBySourceParameters( mappingsKeyedByParameter, notProcessAppliesToAll ); } @@ -530,12 +530,12 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry> entryByParam, List singleTargetReferences) { List mappings = entryByParam.getValue(); - List nonNested = new ArrayList(); - List appliesToAll = new ArrayList(); - List sourceParameterMappings = new ArrayList(); + List nonNested = new ArrayList<>(); + List appliesToAll = new ArrayList<>(); + List sourceParameterMappings = new ArrayList<>(); // group all mappings based on the top level name before popping Map> mappingsKeyedByProperty - = new LinkedHashMap>(); + = new LinkedHashMap<>(); for ( Mapping mapping : mappings ) { Mapping newMapping = mapping.popSourceReference(); @@ -543,7 +543,7 @@ private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry() ); + mappingsKeyedByProperty.put( property, new ArrayList<>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } @@ -579,7 +579,7 @@ else if ( mapping.getSourceReference() == null ) { entry.getValue().addAll( appliesToAll ); } - List notProcessedAppliesToAll = new ArrayList(); + List notProcessedAppliesToAll = new ArrayList<>(); // If the applied to all were not added to all properties because they were empty, and the non-nested // one are not empty, add them to the non-nested ones if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { @@ -619,7 +619,7 @@ private List extractSingleTargetReferencesToUseAndPopulateSourceParamet Parameter sourceParameter) { List singleTargetReferencesToUse = null; if ( singleTargetReferences != null ) { - singleTargetReferencesToUse = new ArrayList( singleTargetReferences.size() ); + singleTargetReferencesToUse = new ArrayList<>( singleTargetReferences.size() ); for ( Mapping mapping : singleTargetReferences ) { if ( mapping.getSourceReference() == null || !mapping.getSourceReference().isValid() || !sourceParameter.equals( mapping.getSourceReference().getParameter() ) ) { @@ -643,10 +643,10 @@ private List extractSingleTargetReferencesToUseAndPopulateSourceParamet } private Map> groupByTargetName(List mappingList) { - Map> result = new LinkedHashMap>(); + Map> result = new LinkedHashMap<>(); for ( Mapping mapping : mappingList ) { if ( !result.containsKey( mapping.getTargetName() ) ) { - result.put( mapping.getTargetName(), new ArrayList() ); + result.put( mapping.getTargetName(), new ArrayList<>() ); } result.get( mapping.getTargetName() ).add( mapping ); } @@ -688,7 +688,7 @@ private void populateWithSingleTargetReferences(Map> map, if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { K key = keyExtractor.apply( mapping.getSourceReference() ); if ( key != null && !map.containsKey( key ) ) { - map.put( key, new ArrayList() ); + map.put( key, new ArrayList<>() ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 8ac7e7c459..8fda20a35e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -132,7 +132,7 @@ private static List getAllAvailableMethods(Method method, List availableMethods = - new ArrayList( methodsProvidedByParams.size() + sourceModelMethods.size() ); + new ArrayList<>( methodsProvidedByParams.size() + sourceModelMethods.size() ); for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { // add only methods from context that do have the @ObjectFactory annotation diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 25db635761..10cfbeb88b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -681,7 +681,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { String name = getName( sourceType, targetType ); name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); - List parameters = new ArrayList( method.getContextParameters() ); + List parameters = new ArrayList<>( method.getContextParameters() ); Type returnType; // there's only one case for forging a method with mapping options: nested target properties. // They should forge an update method only if we set the forceUpdateMethod. This is set to true, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 912a1e0fef..552040d8ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -53,7 +53,7 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Collection List beforeMappingMethods, List afterMappingMethods, SelectionParameters selectionParameters) { - Set helperImports = new HashSet(); + Set helperImports = new HashSet<>(); if ( method.getResultType().isIterableType() ) { helperImports.add( ctx.getTypeFactory().getType( Collectors.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index e0d9ea46cf..60e0957f23 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -37,7 +37,7 @@ public class TypeConversion extends ModelElement implements Assignment { public TypeConversion( Set importTypes, List exceptionTypes, String expression ) { - this.importTypes = new HashSet( importTypes ); + this.importTypes = new HashSet<>( importTypes ); this.importTypes.addAll( exceptionTypes ); this.thrownTypes = exceptionTypes; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index e60b4db0d5..c05d9bdb2b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -44,7 +44,7 @@ public static class Builder { private Method method; private MappingBuilderContext ctx; - private final List trueValueMappings = new ArrayList(); + private final List trueValueMappings = new ArrayList<>(); private ValueMapping defaultTargetValue = null; private ValueMapping nullTargetValue = null; private boolean applyNamebasedMappings = true; @@ -81,7 +81,7 @@ else if ( MappingConstantsPrism.NULL.equals( valueMapping.getSource() ) ) { public ValueMappingMethod build( ) { // initialize all relevant parameters - List mappingEntries = new ArrayList(); + List mappingEntries = new ArrayList<>(); String nullTarget = null; String defaultTarget = null; boolean throwIllegalArgumentException = false; @@ -107,7 +107,7 @@ public ValueMappingMethod build( ) { // do before / after lifecycle mappings SelectionParameters selectionParameters = getSelectionParameters( method, ctx.getTypeUtils() ); - Set existingVariables = new HashSet( method.getParameterNames() ); + Set existingVariables = new HashSet<>( method.getParameterNames() ); List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = @@ -120,9 +120,9 @@ public ValueMappingMethod build( ) { private List enumToEnumMapping(Method method) { - List mappings = new ArrayList(); + List mappings = new ArrayList<>(); List unmappedSourceConstants - = new ArrayList( first( method.getSourceParameters() ).getType().getEnumConstants() ); + = new ArrayList<>( first( method.getSourceParameters() ).getType().getEnumConstants() ); if ( !reportErrorIfMappedEnumConstantsDontExist( method ) ) { @@ -143,7 +143,7 @@ private List enumToEnumMapping(Method method) { // get all target constants List targetConstants = method.getReturnType().getEnumConstants(); - for ( String sourceConstant : new ArrayList( unmappedSourceConstants ) ) { + for ( String sourceConstant : new ArrayList<>( unmappedSourceConstants ) ) { if ( targetConstants.contains( sourceConstant ) ) { mappings.add( new MappingEntry( sourceConstant, sourceConstant ) ); unmappedSourceConstants.remove( sourceConstant ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index b4b27f34af..73dba6234a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -41,7 +41,7 @@ public AdderWrapper( Assignment rhs, @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentExceptionType : parentThrownTypes ) { if ( parentExceptionType.isAssignableTo( thrownTypeToExclude ) ) { @@ -58,7 +58,7 @@ public Type getAdderType() { @Override public Set getImportTypes() { - Set imported = new HashSet(); + Set imported = new HashSet<>(); imported.addAll( super.getImportTypes() ); imported.add( adderType.getTypeBound() ); return imported; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index 1c15b7d312..74549bd2e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -34,7 +34,7 @@ public ArrayCopyWrapper(Assignment rhs, @Override public Set getImportTypes() { - Set imported = new HashSet(); + Set imported = new HashSet<>(); imported.addAll( getAssignment().getImportTypes() ); imported.add( arraysType ); imported.add( targetType ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java index 867a2a9b78..a334312007 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java @@ -26,7 +26,7 @@ public EnumConstantWrapper(Assignment decoratedAssignment, Type enumType ) { @Override public Set getImportTypes() { - Set imported = new HashSet( getAssignment().getImportTypes() ); + Set imported = new HashSet<>( getAssignment().getImportTypes() ); imported.add( enumType ); return imported; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 1b465ce0f6..40e195dcd0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -48,7 +48,7 @@ public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, @Override public Set getImportTypes() { - Set imported = new HashSet( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); if ( getSourcePresenceCheckerReference() == null ) { imported.addAll( getNullCheckLocalVarType().getImportTypes() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java index b5aa620674..e629ae35f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.java @@ -31,7 +31,7 @@ public Java8FunctionWrapper(Assignment decoratedAssignment, Type functionType) { @Override public Set getImportTypes() { - Set imported = new HashSet( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); if ( isDirectAssignment() && functionType != null ) { imported.add( functionType ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java index 3b645240ce..1287ab6cd6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.java @@ -33,7 +33,7 @@ public LocalVarWrapper(Assignment decoratedAssignment, List thrownTypesToE @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentThrownType : parentThrownTypes ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) { @@ -46,7 +46,7 @@ public List getThrownTypes() { @Override public Set getImportTypes() { - Set imported = new HashSet( getAssignment().getImportTypes() ); + Set imported = new HashSet<>( getAssignment().getImportTypes() ); imported.add( targetType ); imported.addAll( targetType.getTypeParameters() ); return imported; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index b09f123bb1..b4653dbb2e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -44,7 +44,7 @@ public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fi @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentThrownType : parentThrownTypes ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index 9d87952434..7746a7bedd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -47,7 +47,7 @@ public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssig @Override public Set getImportTypes() { - Set imported = new HashSet( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); if ( isDirectAssignment() ) { if ( targetType.getImplementationType() != null ) { imported.addAll( targetType.getImplementationType().getImportTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java index 6c38f05a24..7aabbd249b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java @@ -41,7 +41,7 @@ public StreamAdderWrapper(Assignment rhs, @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentExceptionType : parentThrownTypes ) { if ( parentExceptionType.isAssignableTo( thrownTypeToExclude ) ) { @@ -58,7 +58,7 @@ public Type getAdderType() { @Override public Set getImportTypes() { - Set imported = new HashSet(); + Set imported = new HashSet<>(); imported.addAll( super.getImportTypes() ); imported.add( adderType.getTypeBound() ); return imported; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index 489f4063aa..4de30e32ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -58,7 +58,7 @@ private static Type determineImplType(Assignment factoryMethod, Type targetType) @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentThrownType : parentThrownTypes ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) { @@ -71,7 +71,7 @@ public List getThrownTypes() { @Override public Set getImportTypes() { - Set imported = new HashSet(); + Set imported = new HashSet<>(); imported.addAll( super.getImportTypes() ); if ( factoryMethod != null ) { imported.addAll( factoryMethod.getImportTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index 60dcc7a421..e0dbaf3893 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -43,7 +43,7 @@ public WrapperForCollectionsAndMaps(Assignment rhs, @Override public List getThrownTypes() { List parentThrownTypes = super.getThrownTypes(); - List result = new ArrayList( parentThrownTypes ); + List result = new ArrayList<>( parentThrownTypes ); for ( Type thrownTypeToExclude : thrownTypesToExclude ) { for ( Type parentThrownType : parentThrownTypes ) { if ( parentThrownType.isAssignableTo( thrownTypeToExclude ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index ed65185f60..e4dea46a4f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -139,7 +139,7 @@ public static Parameter forForgedMappingTarget(Type parameterType) { * @return the parameters from the given list that are considered 'source parameters' */ public static List getSourceParameters(List parameters) { - List sourceParameters = new ArrayList( parameters.size() ); + List sourceParameters = new ArrayList<>( parameters.size() ); for ( Parameter parameter : parameters ) { if ( !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext() ) { @@ -155,7 +155,7 @@ public static List getSourceParameters(List parameters) { * @return the parameters from the given list that are marked as 'mapping context parameters' */ public static List getContextParameters(List parameters) { - List contextParameters = new ArrayList( parameters.size() ); + List contextParameters = new ArrayList<>( parameters.size() ); for ( Parameter parameter : parameters ) { if ( parameter.isMappingContext() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index d10d2bf090..5f807578e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -104,7 +104,7 @@ public static ParameterBinding fromParameter(Parameter parameter) { } public static List fromParameters(List parameters) { - List result = new ArrayList( parameters.size() ); + List result = new ArrayList<>( parameters.size() ); for ( Parameter param : parameters ) { result.add( fromParameter( param ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 997277ab55..60852b49b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -133,7 +133,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.isLiteral = isLiteral; if ( isEnumType ) { - enumConstants = new ArrayList(); + enumConstants = new ArrayList<>(); for ( Element element : typeElement.getEnclosedElements() ) { // #162: The check for visibility shouldn't be required, but the Eclipse compiler implementation @@ -319,7 +319,7 @@ public String getImportName() { @Override public Set getImportTypes() { - Set result = new HashSet(); + Set result = new HashSet<>(); if ( getTypeMirror().getKind() == TypeKind.DECLARED ) { result.add( this ); @@ -400,8 +400,8 @@ public Type withoutBounds() { return this; } - List bounds = new ArrayList( typeParameters.size() ); - List mirrors = new ArrayList( typeParameters.size() ); + List bounds = new ArrayList<>( typeParameters.size() ); + List mirrors = new ArrayList<>( typeParameters.size() ); for ( Type typeParameter : typeParameters ) { bounds.add( typeParameter.getTypeBound() ); mirrors.add( typeParameter.getTypeBound().getTypeMirror() ); @@ -463,7 +463,7 @@ public boolean isAssignableTo(Type other) { public Map getPropertyReadAccessors() { if ( readAccessors == null ) { List getterList = Filters.getterMethodsIn( accessorNaming, getAllAccessors() ); - Map modifiableGetters = new LinkedHashMap(); + Map modifiableGetters = new LinkedHashMap<>(); for ( Accessor getter : getterList ) { String propertyName = accessorNaming.getPropertyName( getter ); if ( modifiableGetters.containsKey( propertyName ) ) { @@ -504,8 +504,7 @@ public Map getPropertyPresenceCheckers() { accessorNaming, getAllAccessors() ); - Map modifiableCheckers = new LinkedHashMap(); + Map modifiableCheckers = new LinkedHashMap<>(); for ( ExecutableElementAccessor checker : checkerList ) { modifiableCheckers.put( accessorNaming.getPropertyName( checker ), checker ); } @@ -529,10 +528,10 @@ public Map getPropertyPresenceCheckers() { */ public Map getPropertyWriteAccessors( CollectionMappingStrategyPrism cmStrategy ) { // collect all candidate target accessors - List candidates = new ArrayList( getSetters() ); + List candidates = new ArrayList<>( getSetters() ); candidates.addAll( getAlternativeTargetAccessors() ); - Map result = new LinkedHashMap(); + Map result = new LinkedHashMap<>(); for ( Accessor candidate : candidates ) { String targetPropertyName = accessorNaming.getPropertyName( candidate ); @@ -673,7 +672,7 @@ private List getAccessorCandidates(Type property, Class superclass) // 1) starts with add, // 2) and has typeArg as one and only arg List adderList = getAdders(); - List candidateList = new ArrayList(); + List candidateList = new ArrayList<>(); for ( Accessor adder : adderList ) { ExecutableElement executable = adder.getExecutable(); if ( executable == null ) { @@ -728,10 +727,10 @@ private List getAlternativeTargetAccessors() { if ( alternativeTargetAccessors == null ) { - List result = new ArrayList(); + List result = new ArrayList<>(); List setterMethods = getSetters(); List readAccessors = - new ArrayList( getPropertyReadAccessors().values() ); + new ArrayList<>( getPropertyReadAccessors().values() ); // All the fields are also alternative accessors readAccessors.addAll( Filters.fieldsIn( getAllAccessors() ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 24922910b6..981bd19577 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -83,8 +83,8 @@ public String apply(BuilderInfo builderInfo) { private final TypeMirror mapType; private final TypeMirror streamType; - private final Map implementationTypes = new HashMap(); - private final Map importedQualifiedTypesBySimpleName = new HashMap(); + private final Map implementationTypes = new HashMap<>(); + private final Map importedQualifiedTypesBySimpleName = new HashMap<>(); public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext) { this.elementUtils = elementUtils; @@ -369,7 +369,7 @@ public List getParameters(DeclaredType includingType, Accessor access ExecutableElement method = accessor.getExecutable(); TypeMirror methodType = getMethodType( includingType, accessor.getElement() ); if ( method == null || methodType.getKind() != TypeKind.EXECUTABLE ) { - return new ArrayList(); + return new ArrayList<>(); } return getParameters( (ExecutableType) methodType, method ); } @@ -377,7 +377,7 @@ public List getParameters(DeclaredType includingType, Accessor access public List getParameters(ExecutableType methodType, ExecutableElement method) { List parameterTypes = methodType.getParameterTypes(); List parameters = method.getParameters(); - List result = new ArrayList( parameters.size() ); + List result = new ArrayList<>( parameters.size() ); Iterator varIt = parameters.iterator(); Iterator typesIt = parameterTypes.iterator(); @@ -425,19 +425,19 @@ public List getThrownTypes(ExecutableType method) { public List getThrownTypes(Accessor accessor) { if (accessor.getExecutable() == null) { - return new ArrayList(); + return new ArrayList<>(); } return extractTypes( accessor.getExecutable().getThrownTypes() ); } private List extractTypes(List typeMirrors) { - Set types = new HashSet( typeMirrors.size() ); + Set types = new HashSet<>( typeMirrors.size() ); for ( TypeMirror typeMirror : typeMirrors ) { types.add( getType( typeMirror ) ); } - return new ArrayList( types ); + return new ArrayList<>( types ); } private List getTypeParameters(TypeMirror mirror, boolean isImplementationType) { @@ -446,7 +446,7 @@ private List getTypeParameters(TypeMirror mirror, boolean isImplementation } DeclaredType declaredType = (DeclaredType) mirror; - List typeParameters = new ArrayList( declaredType.getTypeArguments().size() ); + List typeParameters = new ArrayList<>( declaredType.getTypeArguments().size() ); for ( TypeMirror typeParameter : declaredType.getTypeArguments() ) { if ( isImplementationType ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java index 261e09c233..19e6374d55 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java @@ -28,8 +28,8 @@ public class GraphAnalyzer { private GraphAnalyzer(Map nodes) { this.nodes = nodes; - cycles = new HashSet>(); - currentPath = new Stack(); + cycles = new HashSet<>(); + currentPath = new Stack<>(); } public static GraphAnalyzerBuilder builder() { @@ -94,7 +94,7 @@ private void depthFirstSearch(Node node) { } private List getCurrentCycle(Node start) { - List cycle = new ArrayList(); + List cycle = new ArrayList<>(); boolean inCycle = false; for ( Node n : currentPath ) { @@ -112,7 +112,7 @@ private List getCurrentCycle(Node start) { public static class GraphAnalyzerBuilder { - private final Map nodes = new LinkedHashMap(); + private final Map nodes = new LinkedHashMap<>(); public GraphAnalyzerBuilder withNode(String name, List descendants) { Node node = getNode( name ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java index cda8e847e0..445b01692c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java @@ -26,7 +26,7 @@ class Node { Node(String name) { this.name = name; - descendants = new ArrayList(); + descendants = new ArrayList<>(); } public String getName() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 19544de10c..4aeb2b5d59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -89,7 +89,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSafeVariableName( sourceParamName ); - this.parameters = new ArrayList( 1 + additionalParameters.size() ); + this.parameters = new ArrayList<>( 1 + additionalParameters.size() ); Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); this.parameters.add( sourceParameter ); this.parameters.addAll( additionalParameters ); @@ -99,7 +99,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu this.contextProvidedMethods = parameterProvidedMethods; this.returnType = returnType; - this.thrownTypes = new ArrayList(); + this.thrownTypes = new ArrayList<>(); this.name = Strings.sanitizeIdentifierName( name ); this.mapperConfiguration = mapperConfiguration; this.positionHintElement = positionHintElement; @@ -117,7 +117,7 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu public ForgedMethod(String name, ForgedMethod forgedMethod) { this.parameters = forgedMethod.parameters; this.returnType = forgedMethod.returnType; - this.thrownTypes = new ArrayList(); + this.thrownTypes = new ArrayList<>(); this.mapperConfiguration = forgedMethod.mapperConfiguration; this.positionHintElement = forgedMethod.positionHintElement; this.history = forgedMethod.history; @@ -236,7 +236,7 @@ public Type getResultType() { @Override public List getParameterNames() { - List parameterNames = new ArrayList(); + List parameterNames = new ArrayList<>(); for ( Parameter parameter : getParameters() ) { parameterNames.add( parameter.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 8c669f8b45..aed9855b59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -64,14 +64,14 @@ public class Mapping { public static Map> fromMappingsPrism(MappingsPrism mappingsAnnotation, ExecutableElement method, FormattingMessager messager, Types typeUtils) { - Map> mappings = new HashMap>(); + Map> mappings = new HashMap<>(); for ( MappingPrism mappingPrism : mappingsAnnotation.value() ) { Mapping mapping = fromMappingPrism( mappingPrism, method, messager, typeUtils ); if ( mapping != null ) { List mappingsOfProperty = mappings.get( mappingPrism.target() ); if ( mappingsOfProperty == null ) { - mappingsOfProperty = new ArrayList(); + mappingsOfProperty = new ArrayList<>(); mappings.put( mappingPrism.target(), mappingsOfProperty ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index b7f589d16a..3d5bf302e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -129,7 +129,7 @@ public boolean hasNestedTargetReferences() { */ public List collectNestedDependsOn() { - List nestedDependsOn = new ArrayList(); + List nestedDependsOn = new ArrayList<>(); for ( List mappingList : mappings.values() ) { for ( Mapping mapping : mappingList ) { nestedDependsOn.addAll( mapping.getDependsOn() ); @@ -255,7 +255,7 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S } - Map> newMappings = new HashMap>(); + Map> newMappings = new HashMap<>(); for ( List lmappings : inherited.getMappings().values() ) { for ( Mapping mapping : lmappings ) { @@ -266,7 +266,7 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S if ( mapping != null ) { List mappingsOfProperty = newMappings.get( mapping.getTargetName() ); if ( mappingsOfProperty == null ) { - mappingsOfProperty = new ArrayList(); + mappingsOfProperty = new ArrayList<>(); newMappings.put( mapping.getTargetName(), mappingsOfProperty ); } @@ -294,7 +294,7 @@ public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, Format writeType = writeType.getEffectiveType(); } Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); - List mappedPropertyNames = new ArrayList(); + List mappedPropertyNames = new ArrayList<>(); for ( String targetMappingName : mappings.keySet() ) { mappedPropertyNames.add( targetMappingName.split( "\\." )[0] ); } @@ -310,7 +310,7 @@ public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, Format private void filterNestedTargetIgnores( Map> mappings) { // collect all properties to ignore, and safe their target name ( == same name as first ref target property) - Set ignored = new HashSet(); + Set ignored = new HashSet<>(); for ( Map.Entry> mappingEntry : mappings.entrySet() ) { Mapping mapping = first( mappingEntry.getValue() ); // list only used for deprecated enums mapping if ( mapping.isIgnored() && mapping.getTargetReference().isValid() ) { @@ -319,7 +319,7 @@ private void filterNestedTargetIgnores( Map> mappings) { } // collect all entries to remove (avoid concurrent modification) - Set toBeRemoved = new HashSet(); + Set toBeRemoved = new HashSet<>(); for ( Map.Entry> mappingEntry : mappings.entrySet() ) { Mapping mapping = first( mappingEntry.getValue() ); // list only used for deprecated enums mapping TargetReference targetReference = mapping.getTargetReference(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index ad6c91cf92..20bec62bf9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -73,7 +73,7 @@ public class MethodMatcher { boolean matches(List sourceTypes, Type resultType) { // check & collect generic types. - Map genericTypesMap = new HashMap(); + Map genericTypesMap = new HashMap<>(); if ( candidateMethod.getParameters().size() == sourceTypes.size() ) { int i = 0; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java index 63bb5c3285..28817bc43f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ParameterProvidedMethods.java @@ -30,7 +30,7 @@ public class ParameterProvidedMethods { private ParameterProvidedMethods(Map> parameterToProvidedMethods) { this.parameterToProvidedMethods = parameterToProvidedMethods; - this.methodToProvidingParameter = new IdentityHashMap(); + this.methodToProvidingParameter = new IdentityHashMap<>(); for ( Entry> entry : parameterToProvidedMethods.entrySet() ) { for ( SourceMethod method : entry.getValue() ) { methodToProvidingParameter.put( method, entry.getKey() ); @@ -44,7 +44,7 @@ private ParameterProvidedMethods(Map> parameterToP * methods of each parameter ordered based on their definition in that parameter's type. */ public List getAllProvidedMethodsInParameterOrder(List orderedParameters) { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( Parameter parameter : orderedParameters ) { List methods = parameterToProvidedMethods.get( parameter ); @@ -82,7 +82,7 @@ public static ParameterProvidedMethods empty() { public static class Builder { private Map> contextProvidedMethods = - new HashMap>(); + new HashMap<>(); private Builder() { } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 1c4b2e2108..efe38231d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -274,7 +274,7 @@ public ParameterProvidedMethods getContextProvidedMethods() { @Override public List getParameterNames() { if ( parameterNames == null ) { - List names = new ArrayList( parameters.size() ); + List names = new ArrayList<>( parameters.size() ); for ( Parameter parameter : parameters ) { names.add( parameter.getName() ); @@ -419,7 +419,7 @@ public String toString() { * @return list of mappings */ public List getMappingBySourcePropertyName(String sourcePropertyName) { - List mappingsOfSourceProperty = new ArrayList(); + List mappingsOfSourceProperty = new ArrayList<>(); for ( List mappingOfProperty : mappingOptions.getMappings().values() ) { for ( Mapping mapping : mappingOfProperty ) { @@ -456,7 +456,7 @@ public Parameter getSourceParameter(String sourceParameterName) { public List getApplicablePrototypeMethods() { if ( applicablePrototypeMethods == null ) { - applicablePrototypeMethods = new ArrayList(); + applicablePrototypeMethods = new ArrayList<>(); for ( SourceMethod prototype : prototypeMethods ) { if ( canInheritFrom( prototype ) ) { @@ -470,7 +470,7 @@ public List getApplicablePrototypeMethods() { public List getApplicableReversePrototypeMethods() { if ( applicableReversePrototypeMethods == null ) { - applicableReversePrototypeMethods = new ArrayList(); + applicableReversePrototypeMethods = new ArrayList<>(); for ( SourceMethod prototype : prototypeMethods ) { if ( reverses( prototype ) ) { @@ -484,7 +484,7 @@ public List getApplicableReversePrototypeMethods() { private static boolean allParametersAreAssignable(List fromParams, List toParams) { if ( fromParams.size() == toParams.size() ) { - Set unaccountedToParams = new HashSet( toParams ); + Set unaccountedToParams = new HashSet<>( toParams ); for ( Parameter fromParam : fromParams ) { // each fromParam needs at least one match, and all toParam need to be accounted for at the end diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 76ab08b754..79d0a8b134 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -111,7 +111,7 @@ public SourceReference build() { String[] segments = sourceNameTrimmed.split( "\\." ); Parameter parameter = null; - List entries = new ArrayList(); + List entries = new ArrayList<>(); if ( method.getSourceParameters().size() > 1 ) { @@ -188,7 +188,7 @@ public String apply(Parameter parameter) { sourcePropertyNames[notFoundPropertyIndex], sourceType.getPropertyReadAccessors().keySet() ); - List elements = new ArrayList( + List elements = new ArrayList<>( Arrays.asList( sourcePropertyNames ).subList( 0, notFoundPropertyIndex ) ); elements.add( mostSimilarWord ); @@ -204,7 +204,7 @@ public String apply(Parameter parameter) { } private List getSourceEntries(Type type, String[] entryNames) { - List sourceEntries = new ArrayList(); + List sourceEntries = new ArrayList<>(); Type newType = type; for ( String entryName : entryNames ) { boolean matchFound = false; @@ -275,7 +275,7 @@ public BuilderFromProperty sourceParameter(Parameter sourceParameter) { } public SourceReference build() { - List sourcePropertyEntries = new ArrayList(); + List sourcePropertyEntries = new ArrayList<>(); if ( readAccessor != null ) { sourcePropertyEntries.add( forSourceReference( name, readAccessor, presenceChecker, type ) ); } @@ -325,7 +325,7 @@ public boolean isValid() { } public List getElementNames() { - List sourceName = new ArrayList(); + List sourceName = new ArrayList<>(); sourceName.add( parameter.getName() ); for ( PropertyEntry propertyEntry : propertyEntries ) { sourceName.add( propertyEntry.getName() ); @@ -340,7 +340,7 @@ public List getElementNames() { * @return the copy */ public SourceReference copyForInheritanceTo(SourceMethod method) { - List replacementParamCandidates = new ArrayList(); + List replacementParamCandidates = new ArrayList<>(); for ( Parameter sourceParam : method.getSourceParameters() ) { if ( parameter != null && sourceParam.getType().isAssignableTo( parameter.getType() ) ) { replacementParamCandidates.add( sourceParam ); @@ -358,7 +358,7 @@ public SourceReference copyForInheritanceTo(SourceMethod method) { public SourceReference pop() { if ( propertyEntries.size() > 1 ) { List newPropertyEntries = - new ArrayList( propertyEntries.subList( 1, propertyEntries.size() ) ); + new ArrayList<>( propertyEntries.subList( 1, propertyEntries.size() ) ); return new SourceReference( parameter, newPropertyEntries, isValid ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 1d302043c0..0edfb362d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -178,7 +178,7 @@ private List getTargetEntries(Type type, String[] entryNames) { // initialize CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); - List targetEntries = new ArrayList(); + List targetEntries = new ArrayList<>(); Type nextType = type; // iterate, establish for each entry the target write accessors. Other than setter is only allowed for @@ -349,7 +349,7 @@ public boolean isValid() { } public List getElementNames() { - List elementNames = new ArrayList(); + List elementNames = new ArrayList<>(); if ( parameter != null ) { // only relevant for source properties elementNames.add( parameter.getName() ); @@ -362,7 +362,7 @@ public List getElementNames() { public TargetReference pop() { if ( propertyEntries.size() > 1 ) { - List newPropertyEntries = new ArrayList( propertyEntries.size() - 1 ); + List newPropertyEntries = new ArrayList<>( propertyEntries.size() - 1 ); for ( PropertyEntry propertyEntry : propertyEntries ) { PropertyEntry newPropertyEntry = propertyEntry.pop(); if ( newPropertyEntry != null ) { @@ -433,7 +433,7 @@ public void report() { Set readAccessors = nextType.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( entryNames[index], readAccessors ); - List elements = new ArrayList( Arrays.asList( entryNames ).subList( 0, index ) ); + List elements = new ArrayList<>( Arrays.asList( entryNames ).subList( 0, index ) ); elements.add( mostSimilarProperty ); printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 35de0efb96..908b8284f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -25,7 +25,7 @@ public class BuiltInMappingMethods { public BuiltInMappingMethods(TypeFactory typeFactory) { boolean isXmlGregorianCalendarPresent = isXmlGregorianCalendarAvailable( typeFactory ); - builtInMethods = new ArrayList( 20 ); + builtInMethods = new ArrayList<>( 20 ); if ( isXmlGregorianCalendarPresent ) { builtInMethods.add( new DateToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new XmlGregorianCalendarToDate( typeFactory ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 8716b235e7..024f63229e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -222,7 +222,7 @@ public Type getResultType() { @Override public List getParameterNames() { - List parameterNames = new ArrayList( getParameters().size() ); + List parameterNames = new ArrayList<>( getParameters().size() ); for ( Parameter parameter : getParameters() ) { parameterNames.add( parameter.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index d50300ab74..166b7396ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -38,8 +38,8 @@ public List> getMatchingMethods(Method mapp return methods; } - List> createCandidates = new ArrayList>(); - List> updateCandidates = new ArrayList>(); + List> createCandidates = new ArrayList<>(); + List> updateCandidates = new ArrayList<>(); for ( SelectedMethod method : methods ) { boolean isCreateCandidate = method.getMethod().getMappingTargetParameter() == null; if ( isCreateCandidate ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java index b405c37f56..4e52731225 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java @@ -30,7 +30,7 @@ public List> getMatchingMethods(Method mapp return methods; } - List> sourceParamFactoryMethods = new ArrayList>( methods.size() ); + List> sourceParamFactoryMethods = new ArrayList<>( methods.size() ); for ( SelectedMethod candidate : methods ) { if ( !candidate.getMethod().getSourceParameters().isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index a63319d3b2..3866857bbe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -34,7 +34,7 @@ public List> getMatchingMethods(Method mapp Type singleSourceType = first( sourceTypes ); - List> candidatesWithBestMatchingSourceType = new ArrayList>(); + List> candidatesWithBestMatchingSourceType = new ArrayList<>(); int bestMatchingSourceTypeDistance = Integer.MAX_VALUE; // find the methods with the minimum distance regarding getParameter getParameter type diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index e4f05c350a..c4a029da90 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -25,7 +25,7 @@ public List> getMatchingMethods(Method mapp List sourceTypes, Type targetType, SelectionCriteria criteria) { - List> result = new ArrayList>( methods.size() ); + List> result = new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { if ( method.getMethod().isObjectFactory() == criteria.isObjectFactoryRequired() && method.getMethod().isLifecycleCallbackMethod() == criteria.isLifecycleCallbackRequired() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 69358dafd8..d5f2042931 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -52,9 +52,9 @@ public List> getMatchingMethods(Method mapp List sourceTypes, Type targetType, SelectionCriteria criteria) { - List> candidates = new ArrayList>( methods.size() ); + List> candidates = new ArrayList<>( methods.size() ); for ( T method : methods ) { - candidates.add( new SelectedMethod( method ) ); + candidates.add( new SelectedMethod<>( method ) ); } for ( MethodSelector selector : selectors ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 4fe296befc..cabe123004 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -58,12 +58,12 @@ public List> getMatchingMethods(Method mapp int numberOfQualifiersToMatch = 0; // Define some local collections and make sure that they are defined. - List qualifierTypes = new ArrayList(); + List qualifierTypes = new ArrayList<>(); if ( criteria.getQualifiers() != null ) { qualifierTypes.addAll( criteria.getQualifiers() ); numberOfQualifiersToMatch += criteria.getQualifiers().size(); } - List qualfiedByNames = new ArrayList(); + List qualfiedByNames = new ArrayList<>(); if ( criteria.getQualifiedByNames() != null ) { qualfiedByNames.addAll( criteria.getQualifiedByNames() ); numberOfQualifiersToMatch += criteria.getQualifiedByNames().size(); @@ -77,7 +77,7 @@ public List> getMatchingMethods(Method mapp // Check there are qualfiers for this mapping: Mapping#qualifier or Mapping#qualfiedByName if ( qualifierTypes.isEmpty() ) { // When no qualifiers, disqualify all methods marked with a qualifier by removing them from the candidates - List> nonQualiferAnnotatedMethods = new ArrayList>( methods.size() ); + List> nonQualiferAnnotatedMethods = new ArrayList<>( methods.size() ); for ( SelectedMethod candidate : methods ) { if ( candidate.getMethod() instanceof SourceMethod ) { @@ -95,7 +95,7 @@ public List> getMatchingMethods(Method mapp } else { // Check all methods marked with qualfier (or methods in Mappers marked wiht a qualfier) for matches. - List> matches = new ArrayList>( methods.size() ); + List> matches = new ArrayList<>( methods.size() ); for ( SelectedMethod candidate : methods ) { if ( !( candidate.getMethod() instanceof SourceMethod ) ) { @@ -150,7 +150,7 @@ public List> getMatchingMethods(Method mapp private Set getQualifierAnnotationMirrors( Method candidate ) { // retrieve annotations - Set qualiferAnnotations = new HashSet(); + Set qualiferAnnotations = new HashSet<>(); // first from the method itself SourceMethod candidateSM = (SourceMethod) candidate; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 9b35a2ca5a..132358ec34 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -20,8 +20,8 @@ */ public class SelectionCriteria { - private final List qualifiers = new ArrayList(); - private final List qualifiedByNames = new ArrayList(); + private final List qualifiers = new ArrayList<>(); + private final List qualifiedByNames = new ArrayList<>(); private final String targetPropertyName; private final TypeMirror qualifyingResultType; private final SourceRHS sourceRHS; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index ceed20ee07..3b97b70323 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -41,7 +41,7 @@ public List> getMatchingMethods(Method mapp if ( qualifyingTypeMirror != null && !criteria.isLifecycleCallbackRequired() ) { List> candidatesWithQualifyingTargetType = - new ArrayList>( methods.size() ); + new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { TypeMirror resultTypeMirror = method.getMethod().getResultType().getTypeElement().asType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 6ab9e97097..178e4a3ff4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -42,7 +42,7 @@ public List> getMatchingMethods(Method mapp return methods; } - List> result = new ArrayList>(); + List> result = new ArrayList<>(); List availableBindings; if ( sourceTypes.isEmpty() ) { @@ -75,7 +75,7 @@ public List> getMatchingMethods(Method mapp private List getAvailableParameterBindingsFromMethod(Method method, Type targetType, SourceRHS sourceRHS) { - List availableParams = new ArrayList( method.getParameters().size() + 3 ); + List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); addMappingTargetAndTargetTypeBindings( availableParams, targetType ); if ( sourceRHS != null ) { @@ -92,7 +92,7 @@ private List getAvailableParameterBindingsFromMethod(Method me private List getAvailableParameterBindingsFromSourceTypes(List sourceTypes, Type targetType, Method mappingMethod) { - List availableParams = new ArrayList( sourceTypes.size() + 2 ); + List availableParams = new ArrayList<>( sourceTypes.size() + 2 ); addMappingTargetAndTargetTypeBindings( availableParams, targetType ); @@ -139,8 +139,8 @@ private static List> getCandidateParameterBindingPermutat return null; } - List> bindingPermutations = new ArrayList>( 1 ); - bindingPermutations.add( new ArrayList( methodParameters.size() ) ); + List> bindingPermutations = new ArrayList<>( 1 ); + bindingPermutations.add( new ArrayList<>( methodParameters.size() ) ); for ( Parameter methodParam : methodParameters ) { List candidateBindings = @@ -159,12 +159,12 @@ private static List> getCandidateParameterBindingPermutat } else { List> newVariants = - new ArrayList>( bindingPermutations.size() * candidateBindings.size() ); + new ArrayList<>( bindingPermutations.size() * candidateBindings.size() ); for ( List variant : bindingPermutations ) { // create a copy of each variant for each binding for ( ParameterBinding binding : candidateBindings ) { List extendedVariant = - new ArrayList( methodParameters.size() ); + new ArrayList<>( methodParameters.size() ); extendedVariant.addAll( variant ); extendedVariant.add( binding ); @@ -186,7 +186,7 @@ private static List> getCandidateParameterBindingPermutat */ private static List findCandidateBindingsForParameter(List candidateParameters, Parameter parameter) { - List result = new ArrayList( candidateParameters.size() ); + List result = new ArrayList<>( candidateParameters.size() ); for ( ParameterBinding candidate : candidateParameters ) { if ( parameter.isTargetType() == candidate.isTargetType() @@ -200,7 +200,7 @@ private static List findCandidateBindingsForParameter(List extractTypes(List parameters) { - List result = new ArrayList( parameters.size() ); + List result = new ArrayList<>( parameters.size() ); for ( ParameterBinding param : parameters ) { result.add( param.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 3660950311..ec93bf239b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -50,9 +50,9 @@ public List> getMatchingMethods(Method mapp List sourceTypes, Type targetType, SelectionCriteria criteria) { - List> nameMatches = new ArrayList>(); - List> scopeMatches = new ArrayList>(); - List> nameAndScopeMatches = new ArrayList>(); + List> nameMatches = new ArrayList<>(); + List> scopeMatches = new ArrayList<>(); + List> nameAndScopeMatches = new ArrayList<>(); XmlElementRefInfo xmlElementRefInfo = findXmlElementRef( mappingMethod.getResultType(), criteria.getTargetPropertyName() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 5cd44e27ca..a4d9704369 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -91,7 +91,7 @@ protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionSt decorator.removeConstructor(); List annotations = getDelegatorReferenceAnnotations( mapper ); - List replacement = new ArrayList(); + List replacement = new ArrayList<>(); if ( !decorator.getMethods().isEmpty() ) { for ( Field field : decorator.getFields() ) { replacement.add( replacementMapperReference( field, annotations, injectionStrategy ) ); @@ -101,7 +101,7 @@ protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionSt } private List toMapperReferences(List fields) { - List mapperReferences = new ArrayList( ); + List mapperReferences = new ArrayList<>(); for ( Field field : fields ) { if ( field instanceof MapperReference ) { mapperReferences.add( (MapperReference) field ); @@ -132,7 +132,7 @@ private void buildConstructors(Mapper mapper) { private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { List mapperReferences = toMapperReferences( mapper.getFields() ); List mapperReferencesForConstructor = - new ArrayList( mapperReferences.size() ); + new ArrayList<>( mapperReferences.size() ); for ( MapperReference mapperReference : mapperReferences ) { if ( mapperReference.isUsed() ) { @@ -155,7 +155,7 @@ private AnnotatedConstructor buildAnnotatedConstructorForMapper(Mapper mapper) { private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator decorator) { List mapperReferencesForConstructor = - new ArrayList( decorator.getFields().size() ); + new ArrayList<>( decorator.getFields().size() ); for ( Field field : decorator.getFields() ) { if ( field instanceof AnnotationMapperReference ) { @@ -189,7 +189,7 @@ private void removeDuplicateAnnotations(List annotati List mapperReferenceAnnotations) { ListIterator mapperReferenceIterator = annotationMapperReferences.listIterator(); - Set mapperReferenceAnnotationsTypes = new HashSet(); + Set mapperReferenceAnnotationsTypes = new HashSet<>(); for ( Annotation annotation : mapperReferenceAnnotations ) { mapperReferenceAnnotationsTypes.add( annotation.getType() ); } @@ -198,7 +198,7 @@ private void removeDuplicateAnnotations(List annotati AnnotationMapperReference annotationMapperReference = mapperReferenceIterator.next(); mapperReferenceIterator.remove(); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); for ( Annotation annotation : annotationMapperReference.getAnnotations() ) { if ( !mapperReferenceAnnotationsTypes.contains( annotation.getType() ) ) { qualifiers.add( annotation ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 3ccd45873f..b55422cf77 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -107,7 +107,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L elementUtils, typeUtils, typeFactory, - new ArrayList( sourceModel ), + new ArrayList<>( sourceModel ), mapperReferences ), mapperTypeElement, @@ -126,8 +126,8 @@ public int getPriority() { } private List initReferencedMappers(TypeElement element, MapperConfiguration mapperConfig) { - List result = new LinkedList(); - List variableNames = new LinkedList(); + List result = new LinkedList<>(); + List variableNames = new LinkedList<>(); for ( TypeMirror usedMapper : mapperConfig.uses() ) { DefaultMapperReference mapperReference = DefaultMapperReference.getInstance( @@ -151,13 +151,13 @@ private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, mappingMethods.addAll( mappingContext.getMappingsToGenerate() ); // handle fields - List fields = new ArrayList( mappingContext.getMapperReferences() ); - Set supportingFieldSet = new LinkedHashSet( ); + List fields = new ArrayList<>( mappingContext.getMapperReferences() ); + Set supportingFieldSet = new LinkedHashSet<>(); addAllFieldsIn( mappingContext.getUsedSupportedMappings(), supportingFieldSet ); fields.addAll( supportingFieldSet ); // handle constructorfragments - Set constructorFragments = new LinkedHashSet(); + Set constructorFragments = new LinkedHashSet<>(); addAllFragmentsIn( mappingContext.getUsedSupportedMappings(), constructorFragments ); Mapper mapper = new Mapper.Builder() @@ -198,7 +198,7 @@ private Decorator getDecorator(TypeElement element, List methods, messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_NO_SUBTYPE ); } - List mappingMethods = new ArrayList( methods.size() ); + List mappingMethods = new ArrayList<>( methods.size() ); for ( SourceMethod mappingMethod : methods ) { boolean implementationRequired = true; @@ -254,7 +254,7 @@ else if ( constructor.getParameters().size() == 1 ) { } private SortedSet getExtraImports(TypeElement element) { - SortedSet extraImports = new TreeSet(); + SortedSet extraImports = new TreeSet<>(); MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn( element ); @@ -272,14 +272,14 @@ private SortedSet getExtraImports(TypeElement element) { } private List getMappingMethods(MapperConfiguration mapperConfig, List methods) { - List mappingMethods = new ArrayList(); + List mappingMethods = new ArrayList<>(); for ( SourceMethod method : methods ) { if ( !method.overridesMethod() ) { continue; } - mergeInheritedOptions( method, mapperConfig, methods, new ArrayList() ); + mergeInheritedOptions( method, mapperConfig, methods, new ArrayList<>() ); MappingOptions mappingOptions = method.getMappingOptions(); @@ -551,7 +551,7 @@ private MappingOptions getInverseMappingOptions(List rawMethods, S if ( reversePrism != null ) { // method is configured as being reverse method, collect candidates - List candidates = new ArrayList(); + List candidates = new ArrayList<>(); for ( SourceMethod oneMethod : rawMethods ) { if ( method.reverses( oneMethod ) ) { candidates.add( oneMethod ); @@ -574,7 +574,7 @@ else if ( candidates.get( 0 ).getName().equals( name ) ) { else if ( candidates.size() > 1 ) { // ambiguity: find a matching method that matches configuredBy - List nameFilteredcandidates = new ArrayList(); + List nameFilteredcandidates = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { if ( candidate.getName().equals( name ) ) { nameFilteredcandidates.add( candidate ); @@ -627,7 +627,7 @@ private MappingOptions getTemplateMappingOptions(List rawMethods, if ( forwardPrism != null ) { - List candidates = new ArrayList(); + List candidates = new ArrayList<>(); for ( SourceMethod oneMethod : rawMethods ) { // method must be similar but not equal if ( method.canInheritFrom( oneMethod ) && !( oneMethod.equals( method ) ) ) { @@ -652,7 +652,7 @@ else if ( sourceMethod.getName().equals( name ) ) { else if ( candidates.size() > 1 ) { // ambiguity: find a matching method that matches configuredBy - List nameFilteredcandidates = new ArrayList(); + List nameFilteredcandidates = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { if ( candidate.getName().equals( name ) ) { nameFilteredcandidates.add( candidate ); @@ -677,7 +677,7 @@ else if ( nameFilteredcandidates.size() > 1 ) { private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, InheritInverseConfigurationPrism reversePrism) { - List candidateNames = new ArrayList(); + List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { candidateNames.add( candidate.getName() ); } @@ -728,7 +728,7 @@ private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMe private void reportErrorWhenAmbigousMapping(List candidates, SourceMethod method, InheritConfigurationPrism prism) { - List candidateNames = new ArrayList(); + List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { candidateNames.add( candidate.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index f74f8880f4..75f49d4214 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -97,7 +97,7 @@ private List retrievePrototypeMethods(TypeElement mapperTypeElemen } TypeElement typeElement = asTypeElement( mapperConfig.config() ); - List methods = new ArrayList(); + List methods = new ArrayList<>(); for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, typeElement ) ) { ExecutableType methodType = typeFactory.getMethodType( mapperConfig.config(), executable ); @@ -137,7 +137,7 @@ private List retrievePrototypeMethods(TypeElement mapperTypeElemen */ private List retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement, MapperConfiguration mapperConfig, List prototypeMethods) { - List methods = new ArrayList(); + List methods = new ArrayList<>(); for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, usedMapper ) ) { SourceMethod method = getMethod( @@ -275,7 +275,7 @@ private ParameterProvidedMethods retrieveContextProvidedMethods( mapperConfig, Collections. emptyList() ); - List contextProvidedMethods = new ArrayList( contextParamMethods.size() ); + List contextProvidedMethods = new ArrayList<>( contextParamMethods.size() ); for ( SourceMethod sourceMethod : contextParamMethods ) { if ( sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() ) { contextProvidedMethods.add( sourceMethod ); @@ -413,7 +413,7 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List contextParameterTypes = new HashSet(); + Set contextParameterTypes = new HashSet<>(); for ( Parameter contextParameter : contextParameters ) { if ( !contextParameterTypes.add( contextParameter.getType() ) ) { messager.printMessage( method, Message.RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE ); @@ -498,14 +498,14 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List> getMappings(ExecutableElement method) { - Map> mappings = new HashMap>(); + Map> mappings = new HashMap<>(); MappingPrism mappingAnnotation = MappingPrism.getInstanceOn( method ); MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( method ); if ( mappingAnnotation != null ) { if ( !mappings.containsKey( mappingAnnotation.target() ) ) { - mappings.put( mappingAnnotation.target(), new ArrayList() ); + mappings.put( mappingAnnotation.target(), new ArrayList<>() ); } Mapping mapping = Mapping.fromMappingPrism( mappingAnnotation, method, messager, typeUtils ); if ( mapping != null ) { @@ -529,7 +529,7 @@ private Map> getMappings(ExecutableElement method) { * @return The mappings for the given method, keyed by target property name */ private List getValueMappings(ExecutableElement method) { - List valueMappings = new ArrayList(); + List valueMappings = new ArrayList<>(); ValueMappingPrism mappingAnnotation = ValueMappingPrism.getInstanceOn( method ); ValueMappingsPrism mappingsAnnotation = ValueMappingsPrism.getInstanceOn( method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index 521689d044..7780501a78 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -29,7 +29,7 @@ protected String getComponentModelIdentifier() { @Override protected List getTypeAnnotations(Mapper mapper) { - List typeAnnotations = new ArrayList(); + List typeAnnotations = new ArrayList<>(); typeAnnotations.add( component() ); if ( mapper.getDecorator() != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 9c6f51bf14..0ab2f32fa3 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -75,7 +75,7 @@ public class MappingResolverImpl implements MappingResolver { * Private methods which are not present in the original mapper interface and are added to map certain property * types. */ - private final Set usedSupportedMappings = new HashSet(); + private final Set usedSupportedMappings = new HashSet<>(); public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, TypeFactory typeFactory, List sourceModel, @@ -149,13 +149,13 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; - this.supportingMethodCandidates = new HashSet(); + this.supportingMethodCandidates = new HashSet<>(); this.selectionCriteria = criteria; this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); } private List filterPossibleCandidateMethods(List candidateMethods) { - List result = new ArrayList( candidateMethods.size() ); + List result = new ArrayList<>( candidateMethods.size() ); for ( T candidate : candidateMethods ) { if ( isCandidateForMapping( candidate ) ) { result.add( candidate ); @@ -285,7 +285,7 @@ private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { if ( matchingBuiltInMethod != null ) { - Set allUsedFields = new HashSet( mapperReferences ); + Set allUsedFields = new HashSet<>( mapperReferences ); SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); SupportingMappingMethod supportingMappingMethod = new SupportingMappingMethod( matchingBuiltInMethod.getMethod(), allUsedFields ); @@ -317,7 +317,7 @@ private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { */ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { - List methodYCandidates = new ArrayList( methods ); + List methodYCandidates = new ArrayList<>( methods ); methodYCandidates.addAll( builtInMethods.getBuiltInMethods() ); Assignment methodRefY = null; @@ -362,7 +362,7 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { */ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetType) { - List methodYCandidates = new ArrayList( methods ); + List methodYCandidates = new ArrayList<>( methods ); methodYCandidates.addAll( builtInMethods.getBuiltInMethods() ); Assignment methodRefY = null; @@ -399,7 +399,7 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp */ private Assignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { - List methodXCandidates = new ArrayList( methods ); + List methodXCandidates = new ArrayList<>( methods ); methodXCandidates.addAll( builtInMethods.getBuiltInMethods() ); Assignment conversionYRef = null; @@ -557,7 +557,7 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { // handled in SpecificCompilerWorkarounds... DeclaredType p = (DeclaredType) parameterType; - List typeArguments = new ArrayList( p.getTypeArguments().size() ); + List typeArguments = new ArrayList<>( p.getTypeArguments().size() ); for ( TypeMirror tArg : p.getTypeArguments() ) { typeArguments.add( typeFactory.getTypeBound( tArg ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 1bc369c2f1..c38a1c11ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -73,7 +73,7 @@ private void initialize() { } private static List findAstModifyingAnnotationProcessors() { - List processors = new ArrayList(); + List processors = new ArrayList<>(); ServiceLoader loader = ServiceLoader.load( AstModifyingAnnotationProcessor.class, AnnotationProcessorContext.class.getClassLoader() diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java index 5b47d1178b..7f2d5cd8db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.util; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -22,36 +21,23 @@ public class Collections { private Collections() { } + @SafeVarargs public static Set asSet(T... elements) { - Set set = new HashSet(); - - for ( T element : elements ) { - set.add( element ); - } - + Set set = new HashSet<>( elements.length ); + java.util.Collections.addAll( set, elements ); return set; } - public static List newArrayList(T... elements) { - List list = new ArrayList(); - - list.addAll( Arrays.asList( elements ) ); - - return list; - } - + @SafeVarargs public static Set asSet(Collection collection, T... elements) { - Set set = new HashSet( collection ); - - for ( T element : elements ) { - set.add( element ); - } - + Set set = new HashSet<>( collection.size() + elements.length ); + java.util.Collections.addAll( set, elements ); return set; } + @SafeVarargs public static Set asSet(Collection collection, Collection... elements) { - Set set = new HashSet( collection ); + Set set = new HashSet<>( collection ); for ( Collection element : elements ) { set.addAll( element ); @@ -69,7 +55,7 @@ public static T last(List list) { } public static List join(List a, List b) { - List result = new ArrayList( a.size() + b.size() ); + List result = new ArrayList<>( a.size() + b.size() ); result.addAll( a ); result.addAll( b ); @@ -77,14 +63,4 @@ public static List join(List a, List b) { return result; } - public static boolean hasNonNullElements(Iterable elements) { - if ( elements != null ) { - for ( E e : elements ) { - if ( e != null ) { - return true; - } - } - } - return false; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 0c845037a3..2e754ff9d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -83,10 +83,7 @@ public static boolean isDefaultMethod(ExecutableElement method) { try { return DEFAULT_METHOD != null && Boolean.TRUE.equals( DEFAULT_METHOD.invoke( method ) ); } - catch ( IllegalAccessException e ) { - return false; - } - catch ( InvocationTargetException e ) { + catch ( IllegalAccessException | InvocationTargetException e ) { return false; } } @@ -111,7 +108,7 @@ private static TypeElement asTypeElement(TypeMirror mirror) { * @return the executable elements usable in the type */ public static List getAllEnclosedExecutableElements(Elements elementUtils, TypeElement element) { - List executables = new ArrayList(); + List executables = new ArrayList<>(); for ( Accessor accessor : getAllEnclosedAccessors( elementUtils, element ) ) { if ( accessor.getExecutable() != null ) { executables.add( accessor.getExecutable() ); @@ -131,7 +128,7 @@ public static List getAllEnclosedExecutableElements(Elements * @return the executable elements usable in the type */ public static List getAllEnclosedAccessors(Elements elementUtils, TypeElement element) { - List enclosedElements = new ArrayList(); + List enclosedElements = new ArrayList<>(); element = replaceTypeElementIfNecessary( elementUtils, element ); addEnclosedElementsInHierarchy( elementUtils, enclosedElements, element, element ); @@ -179,7 +176,7 @@ private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyCollected, List methodsToAdd, TypeElement parentType) { - List safeToAdd = new ArrayList( methodsToAdd.size() ); + List safeToAdd = new ArrayList<>( methodsToAdd.size() ); for ( ExecutableElement toAdd : methodsToAdd ) { if ( isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { @@ -191,7 +188,7 @@ && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { } private static void addFields(List alreadyCollected, List variablesToAdd) { - List safeToAdd = new ArrayList( variablesToAdd.size() ); + List safeToAdd = new ArrayList<>( variablesToAdd.size() ); for ( VariableElement toAdd : variablesToAdd ) { safeToAdd.add( new VariableElementAccessor( toAdd ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 1037d541ca..2b784785a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -24,7 +24,7 @@ private Filters() { } public static List getterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { - List getterMethods = new LinkedList(); + List getterMethods = new LinkedList<>(); for ( Accessor method : elements ) { if ( accessorNaming.isGetterMethod( method ) ) { @@ -36,7 +36,7 @@ public static List getterMethodsIn(AccessorNamingUtils accessorNaming, } public static List fieldsIn(List accessors) { - List fieldAccessors = new LinkedList(); + List fieldAccessors = new LinkedList<>(); for ( Accessor accessor : accessors ) { if ( Executables.isFieldAccessor( accessor ) ) { @@ -49,7 +49,7 @@ public static List fieldsIn(List accessors) { public static List presenceCheckMethodsIn(AccessorNamingUtils accessorNaming, List elements) { - List presenceCheckMethods = new LinkedList(); + List presenceCheckMethods = new LinkedList<>(); for ( Accessor method : elements ) { if ( accessorNaming.isPresenceCheckMethod( method ) ) { @@ -61,7 +61,7 @@ public static List presenceCheckMethodsIn(AccessorNam } public static List setterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { - List setterMethods = new LinkedList(); + List setterMethods = new LinkedList<>(); for ( Accessor method : elements ) { if ( accessorNaming.isSetterMethod( method ) ) { @@ -72,7 +72,7 @@ public static List setterMethodsIn(AccessorNamingUtils accessorNaming, } public static List adderMethodsIn(AccessorNamingUtils accessorNaming, List elements) { - List adderMethods = new LinkedList(); + List adderMethods = new LinkedList<>(); for ( Accessor method : elements ) { if ( accessorNaming.isAdderMethod( method ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 4ffc31016e..d92d0c17e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -78,7 +78,7 @@ public String implementationPackage() { } public Set uses() { - Set uses = new LinkedHashSet(); + Set uses = new LinkedHashSet<>(); for ( TypeMirror usedMapperType : mapperPrism.uses() ) { // TODO #737 Only declared type make sense here; Validate and raise graceful error; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index bd12135226..f453dee51a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -25,8 +25,8 @@ public class NativeTypes { private static final Map, Class> WRAPPER_TO_PRIMITIVE_TYPES; private static final Map, Class> PRIMITIVE_TO_WRAPPER_TYPES; - private static final Set> NUMBER_TYPES = new HashSet>(); - private static final Map TYPE_KIND_NAME = new EnumMap( TypeKind.class ); + private static final Set> NUMBER_TYPES = new HashSet<>(); + private static final Map TYPE_KIND_NAME = new EnumMap<>( TypeKind.class ); private static final Map ANALYZERS; private static final Pattern PTRN_HEX = Pattern.compile( "^0[x|X].*" ); @@ -390,7 +390,7 @@ private NativeTypes() { } static { - Map, Class> tmp = new HashMap, Class>(); + Map, Class> tmp = new HashMap<>(); tmp.put( Byte.class, byte.class ); tmp.put( Short.class, short.class ); tmp.put( Integer.class, int.class ); @@ -402,7 +402,7 @@ private NativeTypes() { WRAPPER_TO_PRIMITIVE_TYPES = Collections.unmodifiableMap( tmp ); - tmp = new HashMap, Class>(); + tmp = new HashMap<>(); tmp.put( byte.class, Byte.class ); tmp.put( short.class, Short.class ); tmp.put( int.class, Integer.class ); @@ -429,7 +429,7 @@ private NativeTypes() { NUMBER_TYPES.add( BigInteger.class ); NUMBER_TYPES.add( BigDecimal.class ); - Map tmp2 = new HashMap(); + Map tmp2 = new HashMap<>(); tmp2.put( boolean.class.getCanonicalName(), new BooleanAnalyzer() ); tmp2.put( Boolean.class.getCanonicalName(), new BooleanAnalyzer() ); tmp2.put( char.class.getCanonicalName(), new CharAnalyzer() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java index ad43298e82..78e61fbf29 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -24,7 +24,7 @@ public class RoundContext { public RoundContext(AnnotationProcessorContext annotationProcessorContext) { this.annotationProcessorContext = annotationProcessorContext; - this.clearedTypes = new HashSet(); + this.clearedTypes = new HashSet<>(); } public AnnotationProcessorContext getAnnotationProcessorContext() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 546e55f8ec..7fbca6dc44 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -145,7 +145,7 @@ public static String getSafeVariableName(String name, Collection existin name = decapitalize( sanitizeIdentifierName( name ) ); name = joinAndCamelize( extractParts( name ) ); - Set conflictingNames = new HashSet( KEYWORDS ); + Set conflictingNames = new HashSet<>( KEYWORDS ); conflictingNames.addAll( existingVariableNames ); if ( !conflictingNames.contains( name ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java index 0d61c96acc..54aebe03be 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java @@ -64,12 +64,12 @@ static TypeMirror asMemberOf(ProcessingEnvironment environment, DeclaredType con } // if nothing was found, traverse the interfaces and collect all candidate methods that match - List candidatesFromInterfaces = new ArrayList(); + List candidatesFromInterfaces = new ArrayList<>(); collectFromInterfaces( methodBinding, referenceBinding, - new HashSet(), + new HashSet<>(), candidatesFromInterfaces ); // there can be multiple matches for the same method name from adjacent interface hierarchies. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java index 6b8b340f53..b58fb79205 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelIncludeDirective.java @@ -48,15 +48,9 @@ public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, T modelElement.write( context, env.getOut() ); } } - catch ( TemplateException te ) { + catch ( TemplateException | RuntimeException | IOException te ) { throw te; } - catch ( IOException ioe ) { - throw ioe; - } - catch ( RuntimeException re ) { - throw re; - } catch ( Exception e ) { throw new RuntimeException( e ); } @@ -97,7 +91,7 @@ private DefaultModelElementWriterContext createContext(Map params) { Map ext = new HashMap( params ); ext.remove( "object" ); - Map, Object> values = new HashMap, Object>(); + Map, Object> values = new HashMap<>(); values.put( Configuration.class, configuration ); values.put( Map.class, ext ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java index 0fe78ce227..cb2e2a911f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java @@ -65,7 +65,7 @@ public void writeModel(FileObject sourceFile, Writable model) { try { BufferedWriter writer = new BufferedWriter( new IndentationCorrectingWriter( sourceFile.openWriter() ) ); - Map, Object> values = new HashMap, Object>(); + Map, Object> values = new HashMap<>(); values.put( Configuration.class, CONFIGURATION ); model.write( new DefaultModelElementWriterContext( values ), writer ); @@ -128,7 +128,7 @@ static class DefaultModelElementWriterContext implements Context { private final Map, Object> values; DefaultModelElementWriterContext(Map, Object> values) { - this.values = new HashMap, Object>( values ); + this.values = new HashMap<>( values ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 4869bd3679..23e6db3505 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -154,7 +154,7 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements } List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); - List builderInfo = new ArrayList(); + List builderInfo = new ArrayList<>(); for ( ExecutableElement method : methods ) { if ( isPossibleBuilderCreationMethod( method, typeElement, types ) ) { TypeElement builderElement = getTypeElement( method.getReturnType() ); @@ -230,7 +230,7 @@ protected Collection findBuildMethods(TypeElement builderElem } List builderMethods = ElementFilter.methodsIn( builderElement.getEnclosedElements() ); - List buildMethods = new ArrayList(); + List buildMethods = new ArrayList<>(); for ( ExecutableElement buildMethod : builderMethods ) { if ( isBuildMethod( buildMethod, typeElement, types ) ) { buildMethods.add( buildMethod ); From a09d9807739b72a9a61bdc7ed03781b8b5447cb2 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 20 Oct 2018 11:21:13 +0100 Subject: [PATCH 0290/1006] #1593 additional testcase to test multiple source arguments icw @MappingConfig (#1630) --- .../manysourcearguments}/Address.java | 2 +- .../manysourcearguments}/DeliveryAddress.java | 2 +- .../ErroneousSourceTargetMapper.java | 2 +- .../ErroneousSourceTargetMapper2.java | 2 +- .../ManySourceArgumentsTest.java} | 27 +++++++++++++++++-- .../manysourcearguments}/Person.java | 2 +- .../ReferencedMapper.java | 2 +- .../SourceTargetConfig.java | 18 +++++++++++++ .../SourceTargetMapper.java | 2 +- .../SourceTargetMapperWithConfig.java | 20 ++++++++++++++ .../manytargetproperties}/Source.java | 2 +- .../SourceTargetMapper.java | 2 +- .../SourceToManyTargetPropertiesTest.java} | 4 +-- .../manytargetproperties}/Target.java | 2 +- .../manytargetproperties}/TimeAndFormat.java | 2 +- .../TimeAndFormatMapper.java | 2 +- 16 files changed, 77 insertions(+), 16 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/Address.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/DeliveryAddress.java (97%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/ErroneousSourceTargetMapper.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/ErroneousSourceTargetMapper2.java (89%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources/SeveralSourceParametersTest.java => source/manysourcearguments/ManySourceArgumentsTest.java} (87%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/Person.java (95%) rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/ReferencedMapper.java (92%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java rename processor/src/test/java/org/mapstruct/ap/test/{severalsources => source/manysourcearguments}/SourceTargetMapper.java (95%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapperWithConfig.java rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets => source/manytargetproperties}/Source.java (91%) rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets => source/manytargetproperties}/SourceTargetMapper.java (93%) rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets/SourcePropertyMapSeveralTimesTest.java => source/manytargetproperties/SourceToManyTargetPropertiesTest.java} (95%) rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets => source/manytargetproperties}/Target.java (93%) rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets => source/manytargetproperties}/TimeAndFormat.java (90%) rename processor/src/test/java/org/mapstruct/ap/test/{severaltargets => source/manytargetproperties}/TimeAndFormatMapper.java (88%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Address.java similarity index 95% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Address.java index db66dc8b6c..ec8e63052a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Address.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; public class Address { diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/DeliveryAddress.java similarity index 97% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/DeliveryAddress.java index 7e06b76bb4..a5e04c5d58 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/DeliveryAddress.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/DeliveryAddress.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; public class DeliveryAddress { diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper.java index 60649f2714..2b96b4b1ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper2.java similarity index 89% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper2.java index d4f9a25850..5d71d120a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ErroneousSourceTargetMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ErroneousSourceTargetMapper2.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java index 4ac88be38f..2f56517e06 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SeveralSourceParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +28,7 @@ */ @IssueKey("31") @RunWith(AnnotationProcessorTestRunner.class) -public class SeveralSourceParametersTest { +public class ManySourceArgumentsTest { @Before public void reset() { @@ -134,6 +134,29 @@ public void shouldMapSeveralSourceAttributesAndParameters() { assertThat( deliveryAddress.getStreet() ).isEqualTo( "Main street" ); } + @IssueKey( "1593" ) + @Test + @WithClasses( { + Person.class, + Address.class, + DeliveryAddress.class, + SourceTargetMapperWithConfig.class, + SourceTargetConfig.class } ) + public void shouldUseConfig() { + Person person = new Person( "Bob", "Garner", 181, "An actor" ); + Address address = new Address( "Main street", 12345, 42, "His address" ); + + DeliveryAddress deliveryAddress = SourceTargetMapperWithConfig.INSTANCE + .personAndAddressToDeliveryAddress( person, address ); + + assertThat( deliveryAddress ).isNotNull(); + assertThat( deliveryAddress.getLastName() ).isEqualTo( "Garner" ); + assertThat( deliveryAddress.getZipCode() ).isEqualTo( 12345 ); + assertThat( deliveryAddress.getHouseNumber() ).isEqualTo( 42 ); + assertThat( deliveryAddress.getDescription() ).isEqualTo( "An actor" ); + + } + @Test @WithClasses({ ErroneousSourceTargetMapper.class, Address.class, DeliveryAddress.class }) @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "IGNORE") diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Person.java similarity index 95% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Person.java index fab70df8a9..bfe3dc65de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/Person.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/Person.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; public class Person { diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ReferencedMapper.java similarity index 92% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ReferencedMapper.java index 0cd2cf20c8..005ef3f4ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/ReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ReferencedMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; import org.mapstruct.BeforeMapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java new file mode 100644 index 0000000000..b64186e6bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.manysourcearguments; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; + +@MapperConfig +public interface SourceTargetConfig { + + @Mapping(source = "address.houseNo", target = "houseNumber") + @Mapping(source = "person.description", target = "description") + DeliveryAddress personAndAddressToDeliveryAddress(Person person, Address address); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java similarity index 95% rename from processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java index 80a498d078..f9289dc99d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severalsources/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severalsources; +package org.mapstruct.ap.test.source.manysourcearguments; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapperWithConfig.java new file mode 100644 index 0000000000..5b31fe02fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapperWithConfig.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.manysourcearguments; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper( config = SourceTargetConfig.class ) +public interface SourceTargetMapperWithConfig { + + SourceTargetMapperWithConfig INSTANCE = Mappers.getMapper( SourceTargetMapperWithConfig.class ); + + @InheritConfiguration + DeliveryAddress personAndAddressToDeliveryAddress(Person person, Address address); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Source.java similarity index 91% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Source.java index b3b4810fe8..f83199c0d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Source.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; /** * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java similarity index 93% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java index 9d075ee4cf..06084b4e6e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java similarity index 95% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java index 79b7363f31..2da3dc8723 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/SourcePropertyMapSeveralTimesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +27,7 @@ TimeAndFormatMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) -public class SourcePropertyMapSeveralTimesTest { +public class SourceToManyTargetPropertiesTest { @Test @IssueKey("94") diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Target.java similarity index 93% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Target.java index 1a66774dea..cb755f9948 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/Target.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; import java.util.Date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormat.java similarity index 90% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormat.java index 2884d82c7f..3c6d5806ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormat.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormat.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; import java.util.Date; diff --git a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormatMapper.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormatMapper.java index 219f84d57a..4ea9f92961 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/severaltargets/TimeAndFormatMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/TimeAndFormatMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.severaltargets; +package org.mapstruct.ap.test.source.manytargetproperties; import java.util.Date; From cfe0f6250c5e6ab3095df943e324911cf25bd581 Mon Sep 17 00:00:00 2001 From: dgruntz Date: Thu, 25 Oct 2018 19:26:39 +0200 Subject: [PATCH 0291/1006] Renames MAPPER field to INSTANCE (#1632) --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 56f6291753..50804de705 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -583,7 +583,7 @@ public class CustomerDto { @Mapper public interface CustomerMapper { - CustomerMapper MAPPER = Mappers.getMapper( CustomerMapper.class ); + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); @Mapping(source = "customerName", target = "name") Customer toCustomer(CustomerDto customerDto); From 288813fc3c56f4c144c6f4d56811430f7b31bc70 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 25 Oct 2018 22:14:26 +0100 Subject: [PATCH 0292/1006] #1306 Add new NullValuePropertyMappingStrategy which leaves @MappingTarget untouched (#1618) --- .../main/java/org/mapstruct/BeanMapping.java | 14 +- core/src/main/java/org/mapstruct/Mapper.java | 17 +- .../main/java/org/mapstruct/MapperConfig.java | 14 +- core/src/main/java/org/mapstruct/Mapping.java | 15 ++ .../java/org/mapstruct/MappingConstants.java | 7 +- .../org/mapstruct/NullValueCheckStrategy.java | 2 +- .../NullValuePropertyMappingStrategy.java | 37 +++ .../mapstruct-reference-guide.asciidoc | 16 +- .../ap/internal/model/BeanMappingMethod.java | 12 +- .../model/CollectionAssignmentBuilder.java | 32 +-- .../ap/internal/model/PropertyMapping.java | 68 ++++-- ...nceSetterWrapperForCollectionsAndMaps.java | 40 +++- ...perForCollectionsAndMapsWithNullCheck.java | 12 +- .../model/assignment/UpdateWrapper.java | 14 +- .../ap/internal/model/source/BeanMapping.java | 21 +- .../ap/internal/model/source/Mapping.java | 219 ++++++++++++------ .../internal/prism/MappingConstantsPrism.java | 1 - ...NullValuePropertyMappingStrategyPrism.java | 19 ++ .../ap/internal/util/MapperConfiguration.java | 20 ++ .../mapstruct/ap/internal/util/Message.java | 7 +- ...anceSetterWrapperForCollectionsAndMaps.ftl | 2 +- ...pperForCollectionsAndMapsWithNullCheck.ftl | 4 - .../model/assignment/UpdateWrapper.ftl | 2 + .../org/mapstruct/ap/test/bugs/_1273/Dto.java | 3 +- .../bugs/_1273/EntityMapperReturnDefault.java | 12 +- .../_913/DomainDtoWithNcvsAlwaysMapper.java | 13 ++ .../_913/DomainDtoWithNvmsDefaultMapper.java | 6 +- .../_913/DomainDtoWithNvmsNullMapper.java | 13 ++ .../DomainDtoWithPresenceCheckMapper.java | 13 ++ .../nullvaluepropertymapping/Address.java | 19 ++ .../nullvaluepropertymapping/AddressDTO.java | 19 ++ .../nullvaluepropertymapping/Customer.java | 30 +++ .../nullvaluepropertymapping/CustomerDTO.java | 30 +++ .../CustomerDefaultMapper.java | 26 +++ .../CustomerMapper.java | 26 +++ ...ustomerNvpmsOnBeanMappingMethodMapper.java | 28 +++ .../CustomerNvpmsOnConfigMapper.java | 24 ++ .../CustomerNvpmsOnMapperMapper.java | 24 ++ .../CustomerNvpmsPropertyMappingMapper.java | 28 +++ .../ErroneousCustomerMapper1.java | 28 +++ .../ErroneousCustomerMapper2.java | 28 +++ .../ErroneousCustomerMapper3.java | 28 +++ .../ErroneousCustomerMapper4.java | 28 +++ .../ErroneousCustomerMapper5.java | 28 +++ .../nullvaluepropertymapping/HomeDTO.java | 19 ++ .../NullValuePropertyMappingTest.java | 203 ++++++++++++++++ .../nullvaluepropertymapping/NvpmsConfig.java | 13 ++ .../nullvaluepropertymapping/UserDTO.java | 30 +++ .../selection/qualifier/QualifierTest.java | 4 +- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 14 +- .../DomainDtoWithNvmsDefaultMapperImpl.java | 6 - .../_913/DomainDtoWithNvmsNullMapperImpl.java | 8 +- .../DomainDtoWithPresenceCheckMapperImpl.java | 8 +- 53 files changed, 1160 insertions(+), 194 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Address.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/AddressDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Customer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/HomeDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NvpmsConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/UserDTO.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index 2492477a27..b510b442d2 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -54,7 +54,7 @@ String[] qualifiedByName() default { }; /** - * The strategy to be applied when {@code null} is passed as source value to this bean mapping. If no + * The strategy to be applied when {@code null} is passed as source bean argument value to this bean mapping. If no * strategy is configured, the strategy given via {@link MapperConfig#nullValueMappingStrategy()} or * {@link Mapper#nullValueMappingStrategy()} will be applied, using {@link NullValueMappingStrategy#RETURN_NULL} * by default. @@ -63,6 +63,18 @@ */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is + * configured, the strategy given via {@link MapperConfig#nullValuePropertyMappingStrategy()} or + * {@link Mapper#nullValuePropertyMappingStrategy()} will be applied, + * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. + * + * @return The strategy to be applied when {@code null} is passed as source property value or the source property + * is not present. + */ + NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() + default NullValuePropertyMappingStrategy.SET_TO_NULL; + /** * Determines when to include a null check on the source property value of a bean mapping. * diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index c86485e94f..7c3f8f9e5e 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -129,14 +129,25 @@ CollectionMappingStrategy collectionMappingStrategy() default CollectionMappingStrategy.ACCESSOR_ONLY; /** - * The strategy to be applied when {@code null} is passed as source value to the methods of this mapper. If no - * strategy is configured, the strategy given via {@link MapperConfig#nullValueMappingStrategy()} will be applied, - * using {@link NullValueMappingStrategy#RETURN_NULL} by default. + * The strategy to be applied when {@code null} is passed as source argument value to the methods of this mapper. + * If no strategy is configured, the strategy given via {@link MapperConfig#nullValueMappingStrategy()} will be + * applied, using {@link NullValueMappingStrategy#RETURN_NULL} by default. * * @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapper. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is + * configured, the strategy given via {@link MapperConfig#nullValuePropertyMappingStrategy()} will be applied, + * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. + * + * @return The strategy to be applied when {@code null} is passed as source property value or the source property + * is not present. + */ + NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default + NullValuePropertyMappingStrategy.SET_TO_NULL; + /** * The strategy to use for applying method-level configuration annotations of prototype methods in the interface * specified with {@link #config()}. Annotations that can be inherited are for example {@link Mapping}, diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index cbcd151157..85991f527f 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -115,13 +115,23 @@ CollectionMappingStrategy collectionMappingStrategy() default CollectionMappingStrategy.ACCESSOR_ONLY; /** - * The strategy to be applied when {@code null} is passed as source value to mapping methods. If no strategy is - * configured, {@link NullValueMappingStrategy#RETURN_NULL} will be used by default. + * The strategy to be applied when {@code null} is passed as source argument value to mapping methods. If no + * strategy is configured, {@link NullValueMappingStrategy#RETURN_NULL} will be used by default. * * @return The strategy to be applied when {@code null} is passed as source value to mapping methods. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is + * configured, {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. + * + * @return The strategy to be applied when {@code null} is passed as source property value or the source property + * is not present. + */ + NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default + NullValuePropertyMappingStrategy.SET_TO_NULL; + /** * The strategy to use for applying method-level configuration annotations of prototype methods in the interface * annotated with this annotation. Annotations that can be inherited are for example {@link Mapping}, diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index b6a4dc87e0..66f4f825e9 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -242,6 +242,7 @@ * If not possible, MapStruct will try to apply a user defined mapping method. *

    8. * + *

      * *

    9. other *

      @@ -267,4 +268,18 @@ */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; + /** + * The strategy to be applied when the source property is {@code null} or not present. If no strategy is configured, + * the strategy given via {@link MapperConfig#nullValuePropertyMappingStrategy()}, + * {@link BeanMapping#nullValuePropertyMappingStrategy()} or + * {@link Mapper#nullValuePropertyMappingStrategy()} will be applied. + * + * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. + * + * @return The strategy to be applied when {@code null} is passed as source property value or the source property + * is not present. + */ + NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() + default NullValuePropertyMappingStrategy.SET_TO_NULL; + } diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index f679d1157f..8b0da9a72e 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -16,17 +16,18 @@ private MappingConstants() { } /** - * Represents a {@code null} source or target. + * In an {@link ValueMapping} this represents a {@code null} source or target. */ public static final String NULL = ""; /** - * Represents any source that is not already mapped by either a defined mapping or by means of name based mapping. + * In an {@link ValueMapping} this represents any source that is not already mapped by either a defined mapping or + * by means of name based mapping. */ public static final String ANY_REMAINING = ""; /** - * Represents any source that is not already mapped by a defined mapping. + * In an {@link ValueMapping} this represents any source that is not already mapped by a defined mapping. */ public static final String ANY_UNMAPPED = ""; diff --git a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java index 8f31a35f7c..8d5b53c005 100644 --- a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -33,6 +33,6 @@ public enum NullValueCheckStrategy { /** * This option always includes a null check. */ - ALWAYS, + ALWAYS; } diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java new file mode 100644 index 0000000000..41ee737d09 --- /dev/null +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +/** + * Strategy for dealing with {@code null} or not present properties in the source bean. The + * {@link NullValuePropertyMappingStrategy} can be defined on {@link MapperConfig}, {@link Mapper}, {@link BeanMapping} + * and {@link Mapping}. + * Precedence is arranged in the reverse order. So {@link Mapping} will override {@link BeanMapping}, will + * overide {@link Mapper} + * + * The enum only applies to update method: methods that update a pre-existing target (annotated with + * {@code @}{@link MappingTarget}). + * + * @author Sjaak Derksen + */ +public enum NullValuePropertyMappingStrategy { + + /** + * If a source bean property equals {@code null} the target bean property will be set explicitly to {@code null}. + */ + SET_TO_NULL, + + /** + * If a source bean property equals {@code null} the target bean property will be set to its default value. + */ + SET_TO_DEFAULT, + + /** + * If a source bean property equals {@code null} the target bean property will be ignored and retain its + * existing value. + */ + IGNORE; +} diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 50804de705..bf2e384bf5 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2107,6 +2107,20 @@ However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETU The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`. +[[mapping-result-for-null-properties]] +=== Controlling mapping result for 'null' properties in bean mappings (update mapping methods only). + +MapStruct offers control over the property to set in an `@MappingTarget` annotated target bean when the source property equals `null` or the presence check method yields absent. + +By default the source property will be set to null. However: + +1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values (`Object`, `ArrayList`, `HashMap`). + +2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. + +The strategy works in a hierarchical fashion. Setting `Mapping#nullValuePropertyMappingStrategy` on mapping level will override `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. + + [[checking-source-property-for-null-arguments]] === Controlling checking result for 'null' properties in bean mapping @@ -2122,7 +2136,7 @@ First calling a mapping method on the source property is not protected by a null The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. -The strategy works in a hierarchical fashion. `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. +The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. [[source-presence-check]] === Source presence checking diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1dff9c196a..0cd484122c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -477,7 +477,8 @@ else if ( mapping.getSourceName() != null ) { .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) .defaultJavaExpression( mapping.getDefaultJavaExpression() ) - .nullValueCheckStrategyPrism( mapping.getNullValueCheckStrategy() ) + .nullValueCheckStrategy( mapping.getNullValueCheckStrategy() ) + .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); handledTargets.add( propertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); @@ -594,8 +595,9 @@ private void applyPropertyNameBasedMapping() { .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetPropertyName, false ) ) - .nullValueCheckStrategyPrism( mapping != null ? mapping.getNullValueCheckStrategy() - : null ) + .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) + .nullValuePropertyMappingStrategy( mapping != null ? + mapping.getNullValuePropertyMappingStrategy() : null ) .build(); unprocessedSourceParameters.remove( sourceParameter ); @@ -659,7 +661,9 @@ private void applyParameterNameBasedMapping() { .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetProperty.getKey(), false ) ) - .nullValueCheckStrategyPrism( mapping != null ? mapping.getNullValueCheckStrategy() : null ) + .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) + .nullValuePropertyMappingStrategy( mapping != null ? + mapping.getNullValuePropertyMappingStrategy() : null ) .build(); propertyMappings.add( propertyMapping ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 7649c373f1..dcef911e89 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -17,7 +17,7 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -57,7 +57,8 @@ public class CollectionAssignmentBuilder { private PropertyMapping.TargetWriteAccessorType targetAccessorType; private Assignment assignment; private SourceRHS sourceRHS; - private NullValueCheckStrategyPrism nullValueCheckStrategy; + private NullValueCheckStrategyPrism nvcs; + private NullValuePropertyMappingStrategyPrism nvpms; public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) { this.ctx = ctx; @@ -109,8 +110,13 @@ public CollectionAssignmentBuilder rightHandSide(SourceRHS sourceRHS) { return this; } - public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyPrism nullValueCheckStrategy ) { - this.nullValueCheckStrategy = nullValueCheckStrategy; + public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyPrism nvcs ) { + this.nvcs = nvcs; + return this; + } + + public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePropertyMappingStrategyPrism nvpms ) { + this.nvpms = nvpms; return this; } @@ -143,7 +149,7 @@ public Assignment build() { PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), targetType, true, - mapNullToDefault() + nvpms ); } else if ( method.isUpdateMethod() && !targetImmutable ) { @@ -152,22 +158,21 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { result, method.getThrownTypes(), targetType, - nullValueCheckStrategy, + nvcs, + nvpms, ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), - mapNullToDefault() + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || - nullValueCheckStrategy == NullValueCheckStrategyPrism.ALWAYS ) { + nvcs == NullValueCheckStrategyPrism.ALWAYS ) { result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, method.getThrownTypes(), targetType, ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), - mapNullToDefault() + PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) ); } else { @@ -201,9 +206,4 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || return result; } - private boolean mapNullToDefault() { - return method.getMapperConfiguration().getNullValueMappingStrategy() - == NullValueMappingStrategyPrism.RETURN_DEFAULT; - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 10cfbeb88b..c8c0b00cdc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -38,6 +38,7 @@ import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -197,7 +198,9 @@ public static class PropertyMappingBuilder extends MappingBuilderBase thrownTypesToExclude, Type targetType, - NullValueCheckStrategyPrism nvms, + NullValueCheckStrategyPrism nvcs, + NullValuePropertyMappingStrategyPrism nvpms, TypeFactory typeFactory, - boolean fieldAssignment, - boolean mapNullToDefault) { + boolean fieldAssignment) { super( decoratedAssignment, thrownTypesToExclude, targetType, typeFactory, - fieldAssignment, - mapNullToDefault + fieldAssignment ); - this.includeSourceNullCheck = ALWAYS == nvms; + this.mapNullToDefault = SET_TO_DEFAULT == nvpms; + this.targetType = targetType; + this.includeElseBranch = ALWAYS != nvcs && IGNORE != nvpms; } - public boolean isIncludeSourceNullCheck() { - return includeSourceNullCheck; + @Override + public Set getImportTypes() { + Set imported = new HashSet( super.getImportTypes() ); + if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) { + imported.add( targetType.getImplementationType() ); + } + return imported; } + + public boolean isIncludeElseBranch() { + return includeElseBranch; + } + + public boolean isMapNullToDefault() { + return mapNullToDefault; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index 7746a7bedd..5e3f4d63fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -26,14 +26,12 @@ public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForC private final Type targetType; private final TypeFactory typeFactory; - private final boolean mapNullToDefault; public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssignment, List thrownTypesToExclude, Type targetType, TypeFactory typeFactory, - boolean fieldAssignment, - boolean mapNullToDefault) { + boolean fieldAssignment) { super( decoratedAssignment, thrownTypesToExclude, @@ -42,7 +40,6 @@ public SetterWrapperForCollectionsAndMapsWithNullCheck(Assignment decoratedAssig ); this.targetType = targetType; this.typeFactory = typeFactory; - this.mapNullToDefault = mapNullToDefault; } @Override @@ -63,9 +60,6 @@ public Set getImportTypes() { if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) { imported.addAll( getNullCheckLocalVarType().getImportTypes() ); } - if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) { - imported.add( targetType.getImplementationType() ); - } return imported; } @@ -77,8 +71,4 @@ public boolean isEnumSet() { return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); } - public boolean isMapNullToDefault() { - return mapNullToDefault; - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index 4de30e32ed..8176f6a8fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -12,6 +12,10 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; + +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; /** * Wraps the assignment in a target setter. @@ -24,6 +28,7 @@ public class UpdateWrapper extends AssignmentWrapper { private final Assignment factoryMethod; private final Type targetImplementationType; private final boolean includeSourceNullCheck; + private final boolean includeExplicitNullWhenSourceIsNull; private final boolean mapNullToDefault; public UpdateWrapper( Assignment decoratedAssignment, @@ -32,13 +37,14 @@ public UpdateWrapper( Assignment decoratedAssignment, boolean fieldAssignment, Type targetType, boolean includeSourceNullCheck, - boolean mapNullToDefault ) { + NullValuePropertyMappingStrategyPrism nvpms) { super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; this.targetImplementationType = determineImplType( factoryMethod, targetType ); this.includeSourceNullCheck = includeSourceNullCheck; - this.mapNullToDefault = mapNullToDefault; + this.mapNullToDefault = nvpms == SET_TO_DEFAULT; + this.includeExplicitNullWhenSourceIsNull = nvpms == SET_TO_NULL; } private static Type determineImplType(Assignment factoryMethod, Type targetType) { @@ -91,6 +97,10 @@ public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } + public boolean isIncludeExplicitNullWhenSourceIsNull() { + return includeExplicitNullWhenSourceIsNull; + } + public boolean isMapNullToDefault() { return mapNullToDefault; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index ce91d9acd1..f2dc9527d1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -33,6 +34,7 @@ public class BeanMapping { private final boolean ignoreByDefault; private final List ignoreUnmappedSourceProperties; private final BuilderPrism builder; + private final NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy; /** * creates a mapping for inheritance. Will set ignoreByDefault to false. @@ -44,6 +46,7 @@ public static BeanMapping forInheritance( BeanMapping map ) { return new BeanMapping( map.selectionParameters, map.nullValueMappingStrategy, + map.nullValuePropertyMappingStrategy, map.nullValueCheckStrategy, map.reportingPolicy, false, @@ -66,6 +69,11 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ? null : NullValueMappingStrategyPrism.valueOf( beanMapping.nullValueMappingStrategy() ); + NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy = + null == beanMapping.values.nullValuePropertyMappingStrategy() + ? null + : NullValuePropertyMappingStrategyPrism.valueOf( beanMapping.nullValuePropertyMappingStrategy() ); + NullValueCheckStrategyPrism nullValueCheckStrategy = null == beanMapping.values.nullValueCheckStrategy() ? null @@ -79,8 +87,8 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() && beanMapping.ignoreUnmappedSourceProperties().isEmpty() - && ( nullValueMappingStrategy == null ) && ( nullValueCheckStrategy == null ) && !ignoreByDefault - && builderMapping == null ) { + && ( nullValueMappingStrategy == null ) && ( nullValuePropertyMappingStrategy == null ) + && ( nullValueCheckStrategy == null ) && !ignoreByDefault && builderMapping == null ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); } @@ -96,6 +104,7 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem return new BeanMapping( cmp, nullValueMappingStrategy, + nullValuePropertyMappingStrategy, nullValueCheckStrategy, null, ignoreByDefault, @@ -115,6 +124,7 @@ public static BeanMapping forForgedMethods() { null, null, null, + null, ReportingPolicyPrism.IGNORE, false, Collections.emptyList(), @@ -123,11 +133,12 @@ public static BeanMapping forForgedMethods() { } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, - NullValueCheckStrategyPrism nvcs, + NullValuePropertyMappingStrategyPrism nvpms, NullValueCheckStrategyPrism nvcs, ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, List ignoreUnmappedSourceProperties, BuilderPrism builder) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; + this.nullValuePropertyMappingStrategy = nvpms; this.nullValueCheckStrategy = nvcs; this.reportingPolicy = reportingPolicy; this.ignoreByDefault = ignoreByDefault; @@ -143,6 +154,10 @@ public NullValueMappingStrategyPrism getNullValueMappingStrategy() { return nullValueMappingStrategy; } + public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { + return nullValuePropertyMappingStrategy; + } + public NullValueCheckStrategyPrism getNullValueCheckStrategy() { return nullValueCheckStrategy; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index aed9855b59..f9bd4d4a30 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -27,6 +27,7 @@ import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -58,6 +59,7 @@ public class Mapping { private final AnnotationValue targetAnnotationValue; private final AnnotationValue dependsOnAnnotationValue; private final NullValueCheckStrategyPrism nullValueCheckStrategy; + private final NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy; private SourceReference sourceReference; private TargetReference targetReference; @@ -89,70 +91,7 @@ public static Map> fromMappingsPrism(MappingsPrism mapping public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElement element, FormattingMessager messager, Types typeUtils) { - if ( mappingPrism.target().isEmpty() ) { - messager.printMessage( - element, - mappingPrism.mirror, - mappingPrism.values.target(), - Message.PROPERTYMAPPING_EMPTY_TARGET - ); - return null; - } - - if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED ); - return null; - } - else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); - return null; - } - else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED ); + if (!isConsistent( mappingPrism, element, messager ) ) { return null; } @@ -168,7 +107,6 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa List dependsOn = mappingPrism.dependsOn() != null ? mappingPrism.dependsOn() : Collections.emptyList(); - FormattingParameters formattingParam = new FormattingParameters( dateFormat, numberFormat, @@ -188,6 +126,11 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa ? null : NullValueCheckStrategyPrism.valueOf( mappingPrism.nullValueCheckStrategy() ); + NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy = + null == mappingPrism.values.nullValuePropertyMappingStrategy() + ? null + : NullValuePropertyMappingStrategyPrism.valueOf( mappingPrism.nullValuePropertyMappingStrategy() ); + return new Mapping( source, constant, @@ -203,7 +146,8 @@ else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defa selectionParams, mappingPrism.values.dependsOn(), dependsOn, - nullValueCheckStrategy + nullValueCheckStrategy, + nullValuePropertyMappingStrategy ); } @@ -223,17 +167,144 @@ public static Mapping forIgnore( String targetName) { null, null, new ArrayList(), + null, null ); } + private static boolean isConsistent(MappingPrism mappingPrism, ExecutableElement element, + FormattingMessager messager) { + + if ( mappingPrism.target().isEmpty() ) { + messager.printMessage( + element, + mappingPrism.mirror, + mappingPrism.values.target(), + Message.PROPERTYMAPPING_EMPTY_TARGET + ); + return false; + } + + if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED + ); + return false; + } + else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED + ); + return false; + } + else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null + && mappingPrism.values.defaultValue() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS + ); + return false; + } + else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null + && mappingPrism.values.constant() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS + ); + return false; + } + else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null + && mappingPrism.values.expression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS + ); + return false; + } + else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null + && mappingPrism.values.defaultExpression() != null ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS + ); + return false; + } + else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null + && mappingPrism.ignore() != null && mappingPrism.ignore() ) { + messager.printMessage( + element, + mappingPrism.mirror, + Message.PROPERTYMAPPING_IGNORE_AND_NVPMS + ); + return false; + } + return true; + } + @SuppressWarnings("checkstyle:parameternumber") private Mapping( String sourceName, String constant, String javaExpression, String defaultJavaExpression, String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror, AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue, FormattingParameters formattingParameters, SelectionParameters selectionParameters, AnnotationValue dependsOnAnnotationValue, List dependsOn, - NullValueCheckStrategyPrism nullValueCheckStrategy ) { + NullValueCheckStrategyPrism nullValueCheckStrategy, + NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy ) { this.sourceName = sourceName; this.constant = constant; this.javaExpression = javaExpression; @@ -249,6 +320,7 @@ private Mapping( String sourceName, String constant, String javaExpression, Stri this.dependsOnAnnotationValue = dependsOnAnnotationValue; this.dependsOn = dependsOn; this.nullValueCheckStrategy = nullValueCheckStrategy; + this.nullValuePropertyMappingStrategy = nullValuePropertyMappingStrategy; } private Mapping( Mapping mapping, TargetReference targetReference ) { @@ -269,6 +341,7 @@ private Mapping( Mapping mapping, TargetReference targetReference ) { this.sourceReference = mapping.sourceReference; this.targetReference = targetReference; this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; + this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; } private Mapping( Mapping mapping, SourceReference sourceReference ) { @@ -289,6 +362,7 @@ private Mapping( Mapping mapping, SourceReference sourceReference ) { this.sourceReference = sourceReference; this.targetReference = mapping.targetReference; this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; + this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; } private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, @@ -458,6 +532,10 @@ public NullValueCheckStrategyPrism getNullValueCheckStrategy() { return nullValueCheckStrategy; } + public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { + return nullValuePropertyMappingStrategy; + } + public Mapping popTargetReference() { if ( targetReference != null ) { TargetReference newTargetReference = targetReference.pop(); @@ -506,7 +584,8 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac selectionParameters, dependsOnAnnotationValue, Collections.emptyList(), - nullValueCheckStrategy + nullValueCheckStrategy, + nullValuePropertyMappingStrategy ); reverse.init( @@ -548,7 +627,8 @@ public Mapping copyForInheritanceTo(SourceMethod method) { selectionParameters, dependsOnAnnotationValue, dependsOn, - nullValueCheckStrategy + nullValueCheckStrategy, + nullValuePropertyMappingStrategy ); if ( sourceReference != null ) { @@ -568,5 +648,6 @@ public String toString() { "\n targetName='" + targetName + "\'," + "\n}"; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java index 959f571bba..c03bac6a7e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java @@ -20,5 +20,4 @@ private MappingConstantsPrism() { public static final String ANY_REMAINING = ""; public static final String ANY_UNMAPPED = ""; - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java new file mode 100644 index 0000000000..bc0cdae9e7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.prism; + + +/** + * Prism for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy} + * + * @author Sjaak Derksen + */ +public enum NullValuePropertyMappingStrategyPrism { + + SET_TO_NULL, + SET_TO_DEFAULT, + IGNORE; +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index d92d0c17e6..49b0aded8d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -22,6 +22,7 @@ import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; /** @@ -163,6 +164,25 @@ else if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy } } + public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy( + NullValuePropertyMappingStrategyPrism beanPrism, + NullValuePropertyMappingStrategyPrism mappingPrism) { + if ( mappingPrism != null ) { + return mappingPrism; + } + else if ( beanPrism != null ) { + return beanPrism; + } + else if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy() == null ) { + return NullValuePropertyMappingStrategyPrism.valueOf( + mapperConfigPrism.nullValuePropertyMappingStrategy() + ); + } + else { + return NullValuePropertyMappingStrategyPrism.valueOf( mapperPrism.nullValuePropertyMappingStrategy() ); + } + } + public InjectionStrategyPrism getInjectionStrategy() { if ( mapperConfigPrism != null && mapperPrism.values.injectionStrategy() == null ) { return InjectionStrategyPrism.valueOf( mapperConfigPrism.injectionStrategy() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 155ea39a5f..445c0b3b0f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -15,7 +15,7 @@ public enum Message { // CHECKSTYLE:OFF - BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), + BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in result type %s. Did you mean \"%s\"?" ), @@ -44,6 +44,11 @@ public enum Message { PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Expression and default expression are both defined in @Mapping, either define an expression or a default expression." ), PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Constant and default expression are both defined in @Mapping, either define a constant or a default expression." ), PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Default value and default expression are both defined in @Mapping, either define a default value or a default expression." ), + PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS( "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultValue or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS( "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define an expression or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS( "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a constant or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS( "DefaultExpression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_IGNORE_AND_NVPMS( "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, either define ignore or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no source parameter named \"%s\". Method source parameters are: \"%s\"." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index 17eb9de511..cee722e2d3 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -14,7 +14,7 @@ ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); - <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !includeSourceNullCheck>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && includeElseBranch>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index 6e38d7fbf5..c26557af94 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -10,10 +10,6 @@ <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> <@callTargetWriteAccessor/> - <#if !ext.defaultValueAssignment??>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; - } - <#-- assigns the target via the regular target write accessor (usually the setter) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 833120b01d..9dfbc08586 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -13,9 +13,11 @@ <@assignToExistingTarget/> <@lib.handleAssignment/>; } + <#if mapNullToDefault || includeExplicitNullWhenSourceIsNull> else { ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; } + <#else> <@assignToExistingTarget/> <@lib.handleAssignment/>; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java index d91aaa8279..9c912c2210 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Dto.java @@ -5,12 +5,11 @@ */ package org.mapstruct.ap.test.bugs._1273; -import java.util.ArrayList; import java.util.List; public class Dto { - List longs = new ArrayList(); + List longs; public List getLongs() { return longs; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java index 3f0d1e003f..0b31e1d734 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/EntityMapperReturnDefault.java @@ -5,12 +5,20 @@ */ package org.mapstruct.ap.test.bugs._1273; +import java.util.ArrayList; + import org.mapstruct.Mapper; -import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ObjectFactory; -@Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT ) +@Mapper public interface EntityMapperReturnDefault { Dto asTarget(Entity entity); + @ObjectFactory + default Dto createDto() { + Dto result = new Dto(); + result.setLongs( new ArrayList<>( ) ); + return result; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java index f7a995a351..11be515838 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapper.java @@ -5,12 +5,15 @@ */ package org.mapstruct.ap.test.bugs._913; +import org.mapstruct.BeanMapping; import org.mapstruct.InheritConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; +import org.mapstruct.Named; import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.ObjectFactory; import org.mapstruct.factory.Mappers; /** @@ -22,6 +25,7 @@ public interface DomainDtoWithNcvsAlwaysMapper { DomainDtoWithNcvsAlwaysMapper INSTANCE = Mappers.getMapper( DomainDtoWithNcvsAlwaysMapper.class ); + @BeanMapping( qualifiedByName = "DomainObjectFactory" ) @Mappings({ @Mapping(target = "strings", source = "strings"), @Mapping(target = "longs", source = "strings"), @@ -36,4 +40,13 @@ public interface DomainDtoWithNcvsAlwaysMapper { @InheritConfiguration( name = "create" ) Domain updateWithReturn(DtoWithPresenceCheck source, @MappingTarget Domain target); + + @ObjectFactory + @Named( "DomainObjectFactory" ) + default Domain createNullDomain() { + Domain domain = new Domain(); + domain.setLongs( null ); + domain.setStrings( null ); + return domain; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java index 7fef9d8b92..7cd3cfedef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapper.java @@ -11,13 +11,17 @@ import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; import org.mapstruct.factory.Mappers; /** * * @author Sjaak Derksen */ -@Mapper( nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, uses = Helper.class ) +@Mapper( + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT, + uses = Helper.class ) public interface DomainDtoWithNvmsDefaultMapper { DomainDtoWithNvmsDefaultMapper INSTANCE = Mappers.getMapper( DomainDtoWithNvmsDefaultMapper.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java index 4d6fd9eff9..d288b666f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapper.java @@ -5,11 +5,14 @@ */ package org.mapstruct.ap.test.bugs._913; +import org.mapstruct.BeanMapping; import org.mapstruct.InheritConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; +import org.mapstruct.Named; +import org.mapstruct.ObjectFactory; import org.mapstruct.factory.Mappers; /** @@ -22,6 +25,7 @@ public interface DomainDtoWithNvmsNullMapper { DomainDtoWithNvmsNullMapper INSTANCE = Mappers.getMapper( DomainDtoWithNvmsNullMapper.class ); + @BeanMapping( qualifiedByName = "DomainObjectFactory" ) @Mappings({ @Mapping(target = "strings", source = "strings"), @Mapping(target = "longs", source = "strings"), @@ -36,4 +40,13 @@ public interface DomainDtoWithNvmsNullMapper { @InheritConfiguration( name = "create" ) Domain updateWithReturn(Dto source, @MappingTarget Domain target); + + @ObjectFactory + @Named( "DomainObjectFactory" ) + default Domain createNullDomain() { + Domain domain = new Domain(); + domain.setLongs( null ); + domain.setStrings( null ); + return domain; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java index ddb0a60cea..83b8539a41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapper.java @@ -5,11 +5,14 @@ */ package org.mapstruct.ap.test.bugs._913; +import org.mapstruct.BeanMapping; import org.mapstruct.InheritConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; +import org.mapstruct.Named; +import org.mapstruct.ObjectFactory; import org.mapstruct.factory.Mappers; /** @@ -22,6 +25,7 @@ public interface DomainDtoWithPresenceCheckMapper { DomainDtoWithPresenceCheckMapper INSTANCE = Mappers.getMapper( DomainDtoWithPresenceCheckMapper.class ); + @BeanMapping( qualifiedByName = "DomainObjectFactory" ) @Mappings({ @Mapping(target = "strings", source = "strings"), @Mapping(target = "longs", source = "strings"), @@ -36,4 +40,13 @@ public interface DomainDtoWithPresenceCheckMapper { @InheritConfiguration( name = "create" ) Domain updateWithReturn(DtoWithPresenceCheck source, @MappingTarget Domain target); + + @ObjectFactory + @Named( "DomainObjectFactory" ) + default Domain createNullDomain() { + Domain domain = new Domain(); + domain.setLongs( null ); + domain.setStrings( null ); + return domain; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Address.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Address.java new file mode 100644 index 0000000000..86c76f4d50 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Address.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +public class Address { + + private Integer houseNumber; + + public Integer getHouseNumber() { + return houseNumber; + } + + public void setHouseNumber(Integer houseNumber) { + this.houseNumber = houseNumber; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/AddressDTO.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/AddressDTO.java new file mode 100644 index 0000000000..3fca3b046f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/AddressDTO.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +public class AddressDTO { + + private Integer houseNo; + + public Integer getHouseNo() { + return houseNo; + } + + public void setHouseNo(Integer houseNo) { + this.houseNo = houseNo; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Customer.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Customer.java new file mode 100644 index 0000000000..ac750aeb5a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/Customer.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import java.util.List; + +public class Customer { + + private Address address; + private List details; + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public List getDetails() { + return details; + } + + public void setDetails(List details) { + this.details = details; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDTO.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDTO.java new file mode 100644 index 0000000000..b2475cd4c7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDTO.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import java.util.List; + +public class CustomerDTO { + + private AddressDTO address; + private List details; + + public AddressDTO getAddress() { + return address; + } + + public void setAddress(AddressDTO address) { + this.address = address; + } + + public List getDetails() { + return details; + } + + public void setDetails(List details) { + this.details = details; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java new file mode 100644 index 0000000000..019327ede9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) +public interface CustomerDefaultMapper { + + CustomerDefaultMapper INSTANCE = Mappers.getMapper( CustomerDefaultMapper.class ); + + @Mapping(source = "address", target = "homeDTO.addressDTO") + void mapCustomer(Customer customer, @MappingTarget UserDTO userDTO); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java new file mode 100644 index 0000000000..56b930c51a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(source = "address", target = "homeDTO.addressDTO") + void mapCustomer(Customer customer, @MappingTarget UserDTO userDTO); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java new file mode 100644 index 0000000000..7801084639 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CustomerNvpmsOnBeanMappingMethodMapper { + + CustomerNvpmsOnBeanMappingMethodMapper INSTANCE = Mappers.getMapper( CustomerNvpmsOnBeanMappingMethodMapper.class ); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java new file mode 100644 index 0000000000..941b7d2b43 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper(config = NvpmsConfig.class) +public interface CustomerNvpmsOnConfigMapper { + + CustomerNvpmsOnConfigMapper INSTANCE = Mappers.getMapper( CustomerNvpmsOnConfigMapper.class ); + + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java new file mode 100644 index 0000000000..592a687c6e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface CustomerNvpmsOnMapperMapper { + + CustomerNvpmsOnMapperMapper INSTANCE = Mappers.getMapper( CustomerNvpmsOnMapperMapper.class ); + + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java new file mode 100644 index 0000000000..28eaf8f337 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface CustomerNvpmsPropertyMappingMapper { + + CustomerNvpmsPropertyMappingMapper INSTANCE = Mappers.getMapper( CustomerNvpmsPropertyMappingMapper.class ); + + @Mapping( target = "address", nullValuePropertyMappingStrategy = IGNORE) + @Mapping( target = "details", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java new file mode 100644 index 0000000000..3c2dd51344 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface ErroneousCustomerMapper1 { + + ErroneousCustomerMapper1 INSTANCE = Mappers.getMapper( ErroneousCustomerMapper1.class ); + + @Mapping(target = "details", defaultValue = "test", nullValuePropertyMappingStrategy = IGNORE) + @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java new file mode 100644 index 0000000000..4b7f2bec75 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface ErroneousCustomerMapper2 { + + ErroneousCustomerMapper2 INSTANCE = Mappers.getMapper( ErroneousCustomerMapper2.class ); + + @Mapping(target = "details", expression = "java(getTest())", nullValuePropertyMappingStrategy = IGNORE) + @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java new file mode 100644 index 0000000000..755b468539 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface ErroneousCustomerMapper3 { + + ErroneousCustomerMapper3 INSTANCE = Mappers.getMapper( ErroneousCustomerMapper3.class ); + + @Mapping(target = "details", defaultExpression = "java(getTest())", nullValuePropertyMappingStrategy = IGNORE) + @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java new file mode 100644 index 0000000000..88fe1a7cbf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface ErroneousCustomerMapper4 { + + ErroneousCustomerMapper4 INSTANCE = Mappers.getMapper( ErroneousCustomerMapper4.class ); + + @Mapping(target = "details", constant = "test", nullValuePropertyMappingStrategy = IGNORE) + @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java new file mode 100644 index 0000000000..05ed1c1fe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +import static org.mapstruct.NullValuePropertyMappingStrategy.IGNORE; + +@Mapper +public interface ErroneousCustomerMapper5 { + + ErroneousCustomerMapper5 INSTANCE = Mappers.getMapper( ErroneousCustomerMapper5.class ); + + @Mapping(target = "details", ignore = true, nullValuePropertyMappingStrategy = IGNORE) + @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) + void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); + + @Mapping(source = "houseNumber", target = "houseNo") + void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/HomeDTO.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/HomeDTO.java new file mode 100644 index 0000000000..ad283e5efd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/HomeDTO.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +public class HomeDTO { + + private AddressDTO addressDTO; + + public AddressDTO getAddressDTO() { + return addressDTO; + } + + public void setAddressDTO(AddressDTO addressDTO) { + this.addressDTO = addressDTO; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java new file mode 100644 index 0000000000..63bb6f92e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -0,0 +1,203 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import java.util.Arrays; +import java.util.function.BiConsumer; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@IssueKey("1306") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Address.class, + Customer.class, + CustomerDTO.class, + AddressDTO.class, + HomeDTO.class, + UserDTO.class +}) +public class NullValuePropertyMappingTest { + + @Test + @WithClasses(CustomerMapper.class) + public void testStrategyAppliedOnForgedMethod() { + + Customer customer = new Customer(); + customer.setAddress( null ); + + UserDTO userDTO = new UserDTO(); + userDTO.setHomeDTO( new HomeDTO() ); + userDTO.getHomeDTO().setAddressDTO( new AddressDTO() ); + userDTO.getHomeDTO().getAddressDTO().setHouseNo( 5 ); + userDTO.setDetails( Arrays.asList( "green hair" ) ); + + CustomerMapper.INSTANCE.mapCustomer( customer, userDTO ); + + assertThat( userDTO.getHomeDTO() ).isNotNull(); + assertThat( userDTO.getHomeDTO().getAddressDTO() ).isNotNull(); + assertThat( userDTO.getHomeDTO().getAddressDTO().getHouseNo() ).isEqualTo( 5 ); + assertThat( userDTO.getDetails() ).isNotNull(); + assertThat( userDTO.getDetails() ).containsExactly( "green hair" ); + } + + @Test + @WithClasses({ NvpmsConfig.class, CustomerNvpmsOnConfigMapper.class }) + public void testHierarchyIgnoreOnConfig() { + testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnConfigMapper.INSTANCE.map( s, t ) ); + } + + @Test + @WithClasses(CustomerNvpmsOnMapperMapper.class) + public void testHierarchyIgnoreOnMapping() { + testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnMapperMapper.INSTANCE.map( s, t ) ); + } + + @Test + @WithClasses(CustomerNvpmsOnBeanMappingMethodMapper.class) + public void testHierarchyIgnoreOnBeanMappingMethod() { + testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnBeanMappingMethodMapper.INSTANCE.map( s, t ) ); + } + + @Test + @WithClasses(CustomerNvpmsPropertyMappingMapper.class) + public void testHierarchyIgnoreOnPropertyMappingMehtod() { + testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsPropertyMappingMapper.INSTANCE.map( s, t ) ); + } + + @Test + @WithClasses(CustomerDefaultMapper.class) + public void testStrategyDefaultAppliedOnForgedMethod() { + + Customer customer = new Customer(); + customer.setAddress( null ); + + UserDTO userDTO = new UserDTO(); + userDTO.setHomeDTO( new HomeDTO() ); + userDTO.getHomeDTO().setAddressDTO( new AddressDTO() ); + userDTO.getHomeDTO().getAddressDTO().setHouseNo( 5 ); + userDTO.setDetails( Arrays.asList( "green hair" ) ); + + CustomerDefaultMapper.INSTANCE.mapCustomer( customer, userDTO ); + + assertThat( userDTO.getHomeDTO() ).isNotNull(); + assertThat( userDTO.getHomeDTO().getAddressDTO() ).isNotNull(); + assertThat( userDTO.getHomeDTO().getAddressDTO().getHouseNo() ).isNull(); + assertThat( userDTO.getDetails() ).isNotNull(); + assertThat( userDTO.getDetails() ).isEmpty(); + } + + @Test + @Ignore // test gives different results for JDK and JDT + @WithClasses(ErroneousCustomerMapper1.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomerMapper1.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + messageRegExp = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + "either define a defaultValue or an nullValuePropertyMappingStrategy.") + } + ) + public void testBothDefaultValueAndNvpmsDefined() { + } + + @Test + @Ignore // test gives different results for JDK and JDT + @WithClasses(ErroneousCustomerMapper2.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomerMapper2.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + messageRegExp = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + "either define an expression or an nullValuePropertyMappingStrategy.") + } + ) + public void testBothExpressionAndNvpmsDefined() { + } + + @Test + @Ignore // test gives different results for JDK and JDT + @WithClasses(ErroneousCustomerMapper3.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomerMapper3.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + messageRegExp = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " + + "@Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy.") + } + ) + public void testBothDefaultExpressionAndNvpmsDefined() { + } + + @Test + @Ignore // test gives different results for JDK and JDT + @WithClasses(ErroneousCustomerMapper4.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomerMapper4.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + messageRegExp = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + "either define a constant or an nullValuePropertyMappingStrategy.") + } + ) + public void testBothConstantAndNvpmsDefined() { + } + + @Test + @Ignore // test gives different results for JDK and JDT + @WithClasses(ErroneousCustomerMapper5.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousCustomerMapper5.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + messageRegExp = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + "either define ignore or an nullValuePropertyMappingStrategy.") + } + ) + public void testBothIgnoreAndNvpmsDefined() { + } + + private void testConfig(BiConsumer customerMapper) { + + Customer customer = new Customer(); + customer.setAddress( null ); + + CustomerDTO customerDto = new CustomerDTO(); + customerDto.setAddress( new AddressDTO() ); + customerDto.getAddress().setHouseNo( 5 ); + customerDto.setDetails( Arrays.asList( "green hair" ) ); + + customerMapper.accept( customer, customerDto ); + + assertThat( customerDto.getAddress() ).isNotNull(); + assertThat( customerDto.getAddress().getHouseNo() ).isEqualTo( 5 ); + assertThat( customerDto.getDetails() ).isNotNull(); + assertThat( customerDto.getDetails() ).containsExactly( "green hair" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NvpmsConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NvpmsConfig.java new file mode 100644 index 0000000000..bf89b1e98f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NvpmsConfig.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import org.mapstruct.MapperConfig; +import org.mapstruct.NullValuePropertyMappingStrategy; + +@MapperConfig( nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE ) +public interface NvpmsConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/UserDTO.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/UserDTO.java new file mode 100644 index 0000000000..9dc9af6efb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/UserDTO.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping; + +import java.util.List; + +public class UserDTO { + + private HomeDTO homeDTO; + private List details; + + public HomeDTO getHomeDTO() { + return homeDTO; + } + + public void setHomeDTO(HomeDTO homeDTO) { + this.homeDTO = homeDTO; + } + + public List getDetails() { + return details; + } + + public void setDetails(List details) { + this.details = details; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 7454b36f86..570922b6cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -174,8 +174,8 @@ public void testFactorySelectionWithQualifier() { @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, line = 24, - messageRegExp = "'nullValueMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in " + - "@BeanMapping, define at least one of them."), + messageRegExp = "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and " + + "'qualifiedBy' are undefined in @BeanMapping, define at least one of them."), @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, line = 24, diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index 3e45e345e2..bd1575a207 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -26,27 +26,18 @@ public Domain create(DtoWithPresenceCheck source) { return null; } - Domain domain = new Domain(); + Domain domain = createNullDomain(); if ( source.hasStringsInitialized() ) { domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } - else { - domain.setLongsInitialized( null ); - } if ( source.hasStrings() ) { domain.setLongs( stringListToLongSet( source.getStrings() ) ); } - else { - domain.setLongs( null ); - } if ( source.hasStrings() ) { List list = source.getStrings(); domain.setStrings( new HashSet( list ) ); } - else { - domain.setStrings( null ); - } if ( source.hasStringsWithDefault() ) { List list1 = source.getStringsWithDefault(); domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -58,9 +49,6 @@ public Domain create(DtoWithPresenceCheck source) { List list2 = source.getStringsInitialized(); domain.setStringsInitialized( new HashSet( list2 ) ); } - else { - domain.setStringsInitialized( null ); - } return domain; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 137282b101..3ed50cb865 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -32,9 +32,6 @@ public Domain create(Dto source) { if ( list != null ) { domain.setStrings( new HashSet( list ) ); } - else { - domain.setStrings( new HashSet() ); - } List list1 = source.getStringsWithDefault(); if ( list1 != null ) { domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -46,9 +43,6 @@ public Domain create(Dto source) { if ( list2 != null ) { domain.setStringsInitialized( new HashSet( list2 ) ); } - else { - domain.setStringsInitialized( new HashSet() ); - } } return domain; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index b1b8b0963d..34867626a6 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -26,7 +26,7 @@ public Domain create(Dto source) { return null; } - Domain domain = new Domain(); + Domain domain = createNullDomain(); domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); domain.setLongs( stringListToLongSet( source.getStrings() ) ); @@ -34,9 +34,6 @@ public Domain create(Dto source) { if ( list != null ) { domain.setStrings( new HashSet( list ) ); } - else { - domain.setStrings( null ); - } List list1 = source.getStringsWithDefault(); if ( list1 != null ) { domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -48,9 +45,6 @@ public Domain create(Dto source) { if ( list2 != null ) { domain.setStringsInitialized( new HashSet( list2 ) ); } - else { - domain.setStringsInitialized( null ); - } return domain; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index 085e89d5bb..c44a9bc360 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -26,7 +26,7 @@ public Domain create(DtoWithPresenceCheck source) { return null; } - Domain domain = new Domain(); + Domain domain = createNullDomain(); domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); domain.setLongs( stringListToLongSet( source.getStrings() ) ); @@ -34,9 +34,6 @@ public Domain create(DtoWithPresenceCheck source) { List list = source.getStrings(); domain.setStrings( new HashSet( list ) ); } - else { - domain.setStrings( null ); - } if ( source.hasStringsWithDefault() ) { List list1 = source.getStringsWithDefault(); domain.setStringsWithDefault( new ArrayList( list1 ) ); @@ -48,9 +45,6 @@ public Domain create(DtoWithPresenceCheck source) { List list2 = source.getStringsInitialized(); domain.setStringsInitialized( new HashSet( list2 ) ); } - else { - domain.setStringsInitialized( null ); - } return domain; } From 2acbe0f5e8f59786b669cab60691d3ef3ca21389 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Oct 2018 08:01:44 +0100 Subject: [PATCH 0293/1006] #1633 Add support for an alternative line in the diagnostics report * This should be used as a last resort when the compilers report the diagnostic on a wrong line * The NullValuePropertyMappingTest uses repeatable annotations that reports errors on wrong lines in javac JDK-8042710 --- .../NullValuePropertyMappingTest.java | 11 +++++------ .../testutil/compilation/annotation/Diagnostic.java | 10 ++++++++++ .../compilation/model/DiagnosticDescriptor.java | 11 +++++++++++ .../ap/testutil/runner/CompilingStatement.java | 5 ++++- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index 63bb6f92e1..30920b9ae1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.function.BiConsumer; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -104,7 +103,6 @@ public void testStrategyDefaultAppliedOnForgedMethod() { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper1.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -112,6 +110,7 @@ public void testStrategyDefaultAppliedOnForgedMethod() { @Diagnostic(type = ErroneousCustomerMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a defaultValue or an nullValuePropertyMappingStrategy.") } @@ -120,7 +119,6 @@ public void testBothDefaultValueAndNvpmsDefined() { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper2.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -128,6 +126,7 @@ public void testBothDefaultValueAndNvpmsDefined() { @Diagnostic(type = ErroneousCustomerMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define an expression or an nullValuePropertyMappingStrategy.") } @@ -136,7 +135,6 @@ public void testBothExpressionAndNvpmsDefined() { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper3.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -144,6 +142,7 @@ public void testBothExpressionAndNvpmsDefined() { @Diagnostic(type = ErroneousCustomerMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " + "@Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy.") } @@ -152,7 +151,6 @@ public void testBothDefaultExpressionAndNvpmsDefined() { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper4.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -160,6 +158,7 @@ public void testBothDefaultExpressionAndNvpmsDefined() { @Diagnostic(type = ErroneousCustomerMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a constant or an nullValuePropertyMappingStrategy.") } @@ -168,7 +167,6 @@ public void testBothConstantAndNvpmsDefined() { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper5.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -176,6 +174,7 @@ public void testBothConstantAndNvpmsDefined() { @Diagnostic(type = ErroneousCustomerMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define ignore or an nullValuePropertyMappingStrategy.") } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java index c129302515..b2016f1c2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java @@ -35,6 +35,16 @@ */ long line() default -1; + /** + * In case compilers report diagnostics on different lines this can be used as the alternative expected line number + * of the diagnostic. + *

      + * This should be used as a last resort when the compilers report the diagnostic on a wrong line. + * + * @return The alternative line number of the diagnostic. + */ + long alternativeLine() default -1; + /** * A regular expression matching the expected message of the diagnostic. * Wild-cards matching any character (".*") will be added to the beginning diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index b406ae7eae..f023610642 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -26,12 +26,18 @@ public class DiagnosticDescriptor { private final String sourceFileName; private final Kind kind; private final Long line; + private final Long alternativeLine; private final String message; private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message) { + this( sourceFileName, kind, line, null, message ); + } + + private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long alternativeLine, String message) { this.sourceFileName = sourceFileName; this.kind = kind; this.line = line; + this.alternativeLine = alternativeLine; this.message = message; } @@ -43,6 +49,7 @@ public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) { soureFileName, diagnostic.kind(), diagnostic.line() != -1 ? diagnostic.line() : null, + diagnostic.alternativeLine() != -1 ? diagnostic.alternativeLine() : null, diagnostic.messageRegExp() ); } @@ -135,6 +142,10 @@ public Long getLine() { return line; } + public Long getAlternativeLine() { + return alternativeLine; + } + public String getMessage() { return message; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 215ab1c70c..73693e4cb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -269,7 +269,10 @@ private void assertDiagnostics(List actualDiagnostics, if ( expected.getSourceFileName() != null ) { assertThat( actual.getSourceFileName() ).isEqualTo( expected.getSourceFileName() ); } - if ( expected.getLine() != null ) { + if ( expected.getLine() != null && expected.getAlternativeLine() != null ) { + assertThat( actual.getLine() ).isIn( expected.getLine(), expected.getAlternativeLine() ); + } + else if ( expected.getLine() != null ) { assertThat( actual.getLine() ).isEqualTo( expected.getLine() ); } assertThat( actual.getKind() ).isEqualTo( expected.getKind() ); From de13634ccec4abe225e1b656611c47ceeb2ac7bb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Oct 2018 14:55:41 +0100 Subject: [PATCH 0294/1006] #1478 Use source property name for the adder iterator --- .../ap/internal/model/BeanMappingMethod.java | 1 + .../ap/internal/model/PropertyMapping.java | 11 ++++-- .../model/assignment/AdderWrapper.java | 4 +-- .../ap/test/collection/adder/AdderTest.java | 18 ++++++++++ ...ceTargetMapperWithDifferentProperties.java | 26 ++++++++++++++ .../adder/_target/TargetWithAnimals.java | 29 +++++++++++++++ .../adder/source/SourceWithPets.java | 24 +++++++++++++ ...rgetMapperWithDifferentPropertiesImpl.java | 35 +++++++++++++++++++ 8 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentProperties.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceWithPets.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentPropertiesImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0cd484122c..d7f1c30843 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -470,6 +470,7 @@ else if ( mapping.getSourceName() != null ) { .sourceMethod( method ) .targetProperty( targetProperty ) .targetPropertyName( mapping.getTargetName() ) + .sourcePropertyName( mapping.getSourceName() ) .sourceReference( sourceRef ) .selectionParameters( mapping.getSelectionParameters() ) .formattingParameters( mapping.getFormattingParameters() ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index c8c0b00cdc..cbfe5aa68c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -105,6 +105,7 @@ private static class MappingBuilderBase> extends protected Type targetType; protected Accessor targetReadAccessor; protected String targetPropertyName; + protected String sourcePropertyName; protected List dependsOn; protected Set existingVariableNames; @@ -171,6 +172,11 @@ public T targetPropertyName(String targetPropertyName) { return (T) this; } + public T sourcePropertyName(String sourcePropertyName) { + this.sourcePropertyName = sourcePropertyName; + return (T) this; + } + public T dependsOn(List dependsOn) { this.dependsOn = dependsOn; return (T) this; @@ -468,12 +474,13 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { Assignment result = rightHandSide; + String adderIteratorName = sourcePropertyName == null ? targetPropertyName : sourcePropertyName; if ( result.getSourceType().isCollectionType() ) { - result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName ); + result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), adderIteratorName ); } else if ( result.getSourceType().isStreamType() ) { result = new StreamAdderWrapper( - result, method.getThrownTypes(), isFieldAssignment(), targetPropertyName ); + result, method.getThrownTypes(), isFieldAssignment(), adderIteratorName ); } else { // Possibly adding null to a target collection. So should be surrounded by an null check. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 73dba6234a..0cb2a23024 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -30,10 +30,10 @@ public class AdderWrapper extends AssignmentWrapper { public AdderWrapper( Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment, - String targetPropertyName ) { + String adderIteratorName ) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; - String desiredName = Nouns.singularize( targetPropertyName ); + String desiredName = Nouns.singularize( adderIteratorName ); rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); adderType = first( getSourceType().determineTypeArguments( Collection.class ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index cb2a93b1a5..1507f56399 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -25,12 +25,14 @@ import org.mapstruct.ap.test.collection.adder._target.TargetHuman; import org.mapstruct.ap.test.collection.adder._target.TargetOnlyGetter; import org.mapstruct.ap.test.collection.adder._target.TargetViaTargetType; +import org.mapstruct.ap.test.collection.adder._target.TargetWithAnimals; import org.mapstruct.ap.test.collection.adder._target.TargetWithoutSetter; import org.mapstruct.ap.test.collection.adder.source.Foo; import org.mapstruct.ap.test.collection.adder.source.SingleElementSource; import org.mapstruct.ap.test.collection.adder.source.Source; import org.mapstruct.ap.test.collection.adder.source.Source2; import org.mapstruct.ap.test.collection.adder.source.SourceTeeth; +import org.mapstruct.ap.test.collection.adder.source.SourceWithPets; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @@ -42,15 +44,18 @@ @WithClasses({ Source.class, SourceTeeth.class, + SourceWithPets.class, Target.class, TargetDali.class, TargetHuman.class, TargetOnlyGetter.class, TargetViaTargetType.class, TargetWithoutSetter.class, + TargetWithAnimals.class, SourceTargetMapper.class, SourceTargetMapperStrategyDefault.class, SourceTargetMapperStrategySetterPreferred.class, + SourceTargetMapperWithDifferentProperties.class, SingleElementSource.class, PetMapper.class, TeethMapper.class, @@ -255,4 +260,17 @@ public void testMissingImport() throws DogException { assertThat( target ).isNotNull(); assertThat( target.getAttributes().size() ).isEqualTo( 1 ); } + + @IssueKey("1478") + @Test + public void useIterationNameFromSource() { + generatedSource.addComparisonToFixtureFor( SourceTargetMapperWithDifferentProperties.class ); + + SourceWithPets source = new SourceWithPets(); + source.setPets( Arrays.asList( "dog", "cat" ) ); + + TargetWithAnimals target = SourceTargetMapperWithDifferentProperties.INSTANCE.map( source ); + + assertThat( target.getAnimals() ).containsExactly( "dog", "cat" ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentProperties.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentProperties.java new file mode 100644 index 0000000000..b0460c2650 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentProperties.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.adder; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.collection.adder._target.TargetWithAnimals; +import org.mapstruct.ap.test.collection.adder.source.SourceWithPets; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface SourceTargetMapperWithDifferentProperties { + + SourceTargetMapperWithDifferentProperties INSTANCE = + Mappers.getMapper( SourceTargetMapperWithDifferentProperties.class ); + + @Mapping(target = "animals", source = "pets") + TargetWithAnimals map(SourceWithPets source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java new file mode 100644 index 0000000000..5005251235 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.adder._target; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class TargetWithAnimals { + + private List animals = new ArrayList(); + + public List getAnimals() { + return animals; + } + + public void setAnimals(List animals) { + this.animals = animals; + } + + public void addAnimal(String animal) { + animals.add( animal ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceWithPets.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceWithPets.java new file mode 100644 index 0000000000..bbb0006532 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SourceWithPets.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.adder.source; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class SourceWithPets { + + private List pets; + + public List getPets() { + return pets; + } + + public void setPets(List pets) { + this.pets = pets; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentPropertiesImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentPropertiesImpl.java new file mode 100644 index 0000000000..3a3f60b32d --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperWithDifferentPropertiesImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.adder; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.collection.adder._target.TargetWithAnimals; +import org.mapstruct.ap.test.collection.adder.source.SourceWithPets; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2018-10-13T10:43:55+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_161 (Oracle Corporation)" +) +public class SourceTargetMapperWithDifferentPropertiesImpl implements SourceTargetMapperWithDifferentProperties { + + @Override + public TargetWithAnimals map(SourceWithPets source) { + if ( source == null ) { + return null; + } + + TargetWithAnimals targetWithAnimals = new TargetWithAnimals(); + + if ( source.getPets() != null ) { + for ( String pet : source.getPets() ) { + targetWithAnimals.addAnimal( pet ); + } + } + + return targetWithAnimals; + } +} From ec413118d6fb21f0eeafab6d9c61daa95825c50f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Oct 2018 21:39:35 +0100 Subject: [PATCH 0295/1006] Update build with latest dependencies and Java 8 baseline: (#1636) * Do not use maven-processor-plugin and use the maven-compiler-plugin annotationProcessors instead * Update NoPackageCyclesRule and exclude tests * Update checkstyle to 8.14 and remove FIleContentsHolder module and move SuppressionCommentFilter to the TreeWalker * Update assertj to 3.11.1 and replace usage of RuntimeIOException (from AssertJ) with UncheckedIOException (from java 8) * Add how to import MapStruct into IntelliJ and Eclipse into the readme --- .../resources/build-config/checkstyle.xml | 4 +- parent/pom.xml | 71 ++++++++----------- processor/pom.xml | 52 ++------------ .../testutil/assertions/JavaFileAssert.java | 4 +- readme.md | 14 ++++ 5 files changed, 51 insertions(+), 94 deletions(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 1f371acd2b..9051361d18 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -62,8 +62,6 @@ - - @@ -202,9 +200,9 @@ + - diff --git a/parent/pom.xml b/parent/pom.xml index 0ac7060b03..7ac85a46fe 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -22,15 +22,18 @@ UTF-8 1.0.0 - 1.2 - 2.19.1 - 3.0.0-M1 + 3.0.0-M2 + 2.22.1 + 3.0.1 4.0.3.RELEASE 0.26.0 - 7.2 + 8.14 1 - 3.7.0 + 3.11.1 + + + jdt_apt @@ -268,12 +271,12 @@ org.apache.maven.plugins maven-assembly-plugin - 2.4 + 3.1.0 org.apache.maven.plugins maven-checkstyle-plugin - 2.17 + 3.0.0 build-config/checkstyle.xml true @@ -305,7 +308,7 @@ org.apache.maven.plugins maven-clean-plugin - 2.5 + 3.1.0 org.apache.maven.plugins @@ -314,18 +317,17 @@ 1.8 1.8 - -proc:none org.apache.maven.plugins maven-dependency-plugin - 2.8 + 3.1.1 org.apache.maven.plugins maven-deploy-plugin - 2.8.2 + 3.0.0-M1 true @@ -343,14 +345,14 @@ de.andrena.tools.nopackagecycles no-package-cycles-enforcer-rule - 1.0.5 + 1.0.9 org.apache.felix maven-bundle-plugin - 3.0.1 + 4.0.0 bundle-manifest @@ -364,12 +366,12 @@ org.apache.maven.plugins maven-install-plugin - 2.5.2 + 3.0.0-M1 org.apache.maven.plugins maven-jar-plugin - 3.0.2 + 3.1.0 org.apache.maven.plugins @@ -398,7 +400,7 @@ org.apache.maven.plugins maven-resources-plugin - 2.6 + 3.1.0 org.apache.maven.plugins @@ -408,7 +410,7 @@ org.apache.maven.plugins maven-site-plugin - 3.6 + 3.7.1 org.apache.maven.plugins @@ -419,13 +421,6 @@ -Xms1024m -Xmx3072m - - - org.apache.maven.surefire - surefire-junit47 - ${org.apache.maven.plugins.surefire.version} - - org.apache.maven.plugins @@ -437,25 +432,15 @@ maven-license-plugin 1.10.b1 - - org.bsc.maven - maven-processor-plugin - 2.2.4 - - - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - org.codehaus.mojo animal-sniffer-maven-plugin - 1.16 + 1.17 org.ow2.asm - asm-all - 5.2 + asm + 6.2.1 @@ -513,12 +498,12 @@ org.jacoco jacoco-maven-plugin - 0.7.9 + 0.8.2 org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - 0.9.0 + 0.14.0 org.codehaus.mojo @@ -528,7 +513,7 @@ de.thetaphi forbiddenapis - 2.3 + 2.6 ${project.basedir}/../etc/forbidden-apis.txt @@ -538,7 +523,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.10.0 + 0.13.0 verify @@ -660,7 +645,9 @@ test-compile - + + false + diff --git a/processor/pom.xml b/processor/pom.xml index f71ede86b5..eb307ffa6d 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -21,7 +21,6 @@ MapStruct Processor - ${project.build.directory}/generated-sources/prims @@ -221,54 +220,13 @@ - org.bsc.maven - maven-processor-plugin + org.apache.maven.plugins + maven-compiler-plugin - ${prism.directory} - - net.java.dev.hickory.prism.internal.PrismGenerator - - + + net.java.dev.hickory.prism.internal.PrismGenerator + - - - process - generate-sources - - process - - - - - - com.jolira - hickory - ${com.jolira.hickory.version} - - - org.eclipse.tycho - tycho-compiler-jdt - ${org.eclipse.tycho.compiler-jdt.version} - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-source - generate-sources - - add-source - - - - ${prism.directory} - - - - org.apache.maven.plugins diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 8e8b4d0f72..9b374273f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Iterator; @@ -17,7 +18,6 @@ import org.assertj.core.api.AbstractCharSequenceAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.FileAssert; -import org.assertj.core.api.exception.RuntimeIOException; import org.assertj.core.error.ShouldHaveSameContent; import org.assertj.core.internal.Diff; import org.assertj.core.internal.Failures; @@ -111,7 +111,7 @@ public void hasSameMapperContent(File expected) { } } catch ( IOException e ) { - throw new RuntimeIOException( format( + throw new UncheckedIOException( format( "Unable to compare contents of files:<%s> and:<%s>", actual, expected diff --git a/readme.md b/readme.md index 9e5d354e5a..8260bcb2f4 100644 --- a/readme.md +++ b/readme.md @@ -138,6 +138,20 @@ MapStruct uses Maven for its build. Java 8 is required for building MapStruct fr from the root of the project directory. To skip the distribution module, run mvn clean install -DskipDistribution=true + +## Importing into IDE + +MapStruct uses the hickory annotation processor to generate mapping prisms for it's own annotations. +Therefore for seamless integration within an IDE annotation processing needs to be enabled. + +### IntelliJ + +Make sure that you have at least IntelliJ 2018.2.x (needed since support for `annotationProcessors` from the `maven-compiler-plugin` is from that version). +Enable annotation processing in IntelliJ (Build, Execution, Deployment -> Compiler -> Annotation Processors) + +### Eclipse + +Make sure that you have the [m2e_apt](https://marketplace.eclipse.org/content/m2e-apt) plugin installed. ## Links From e69647f75628f0024feb327cdcf44a06cfc58649 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Fri, 2 Nov 2018 07:56:51 +0000 Subject: [PATCH 0296/1006] #5 controlling lossy conversions (also solving #1504 partially and #1458) --- core/src/main/java/org/mapstruct/Mapper.java | 11 ++ .../main/java/org/mapstruct/MapperConfig.java | 10 ++ .../mapstruct-reference-guide.asciidoc | 2 +- .../BigDecimalToBigIntegerConversion.java | 1 + .../BigDecimalToPrimitiveConversion.java | 7 +- .../BigDecimalToWrapperConversion.java | 7 +- .../BigIntegerToPrimitiveConversion.java | 7 +- .../BigIntegerToWrapperConversion.java | 7 +- .../conversion/ConversionProvider.java | 1 + .../conversion/DateToStringConversion.java | 1 + .../PrimitiveToPrimitiveConversion.java | 5 +- .../PrimitiveToWrapperConversion.java | 8 +- .../internal/conversion/SimpleConversion.java | 1 + .../WrapperToWrapperConversion.java | 8 +- .../internal/model/AbstractBaseBuilder.java | 26 +++ .../ap/internal/model/BeanMappingMethod.java | 11 +- .../model/ContainerMappingMethodBuilder.java | 12 +- .../ap/internal/model/MapMappingMethod.java | 7 +- .../internal/model/MappingBuilderContext.java | 3 +- .../ap/internal/model/MethodReference.java | 1 + .../ap/internal/model/PropertyMapping.java | 19 ++- .../ap/internal/model/TypeConversion.java | 6 +- .../model/assignment/AssignmentWrapper.java | 1 + .../ap/internal/model/common/Assignment.java | 2 +- .../common/DateFormatValidationResult.java | 2 +- .../common/DefaultConversionContext.java | 2 +- .../source/selector/QualifierSelector.java | 2 +- .../DefaultModelElementProcessorContext.java | 13 +- .../creation/MappingResolverImpl.java | 101 ++++++++--- .../ap/internal/util/Executables.java | 2 +- .../ap/internal/util/FormattingMessager.java | 6 +- .../ap/internal/util/MapperConfiguration.java | 13 ++ .../mapstruct/ap/internal/util/Message.java | 3 + .../ap/internal/util/NativeTypes.java | 32 +++- .../conversion/lossy/CutleryInventoryDto.java | 47 ++++++ .../lossy/CutleryInventoryEntity.java | 47 ++++++ .../lossy/CutleryInventoryMapper.java | 18 ++ .../lossy/ErroneousKitchenDrawerMapper1.java | 27 +++ .../lossy/ErroneousKitchenDrawerMapper3.java | 27 +++ .../lossy/ErroneousKitchenDrawerMapper4.java | 27 +++ .../lossy/ErroneousKitchenDrawerMapper5.java | 27 +++ .../lossy/KitchenDrawerMapper2.java | 27 +++ .../lossy/KitchenDrawerMapper6.java | 27 +++ .../ap/test/conversion/lossy/ListMapper.java | 22 +++ .../conversion/lossy/LossyConversionTest.java | 159 ++++++++++++++++++ .../ap/test/conversion/lossy/MapMapper.java | 20 +++ .../lossy/OversizedKitchenDrawerDto.java | 73 ++++++++ .../lossy/RegularKitchenDrawerEntity.java | 69 ++++++++ .../conversion/lossy/VerySpecialNumber.java | 14 ++ .../lossy/VerySpecialNumberMapper.java | 23 +++ .../propertymapping/ErroneousMapper1.java | 18 ++ .../propertymapping/ErroneousMapper2.java | 18 ++ .../propertymapping/ErroneousMapper3.java | 18 ++ .../propertymapping/ErroneousMapper4.java | 18 ++ .../ErroneousPropertyMappingTest.java | 66 ++++++++ .../erroneous/propertymapping/Source.java | 28 +++ .../erroneous/propertymapping/Target.java | 38 +++++ .../propertymapping/UnmappableClass.java | 9 + .../source/constants/SourceConstantsTest.java | 2 +- .../test/updatemethods/UpdateMethodsTest.java | 2 +- 60 files changed, 1118 insertions(+), 93 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper1.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper3.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper4.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper5.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper6.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/MapMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumber.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper1.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper3.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper4.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/UnmappableClass.java diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 7c3f8f9e5e..64e22ab741 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -62,6 +62,17 @@ */ ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.WARN; + /** + * How lossy (narrowing) conversion, for instance long to integer should be + * reported. The method overrides an typeConversionPolicy set in a central + * configuration set by {@link #config() } + * + * @since 1.3 + * + * @return The reporting policy for unmapped target properties. + */ + ReportingPolicy typeConversionPolicy() default ReportingPolicy.IGNORE; + /** * Specifies the component model to which the generated mapper should * adhere. Supported values are diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 85991f527f..cd58d70dbd 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -62,6 +62,16 @@ */ ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.WARN; + /** + * How lossy (narrowing) conversion, for instance: long to integer should be + * reported. + * + * @since 1.3 + * + * @return The reporting policy for type conversion. + */ + ReportingPolicy typeConversionPolicy() default ReportingPolicy.IGNORE; + /** * Specifies the component model to which the generated mapper should * adhere. Supported values are diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index bf2e384bf5..9bdc041e34 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -875,7 +875,7 @@ Currently the following conversions are applied automatically: [WARNING] ==== -Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. There https://github.com/mapstruct/mapstruct/issues/5[will be] an option for raising a warning in such cases in a future MapStruct version. +Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. The `Mapper` and `MapperConfig` annotations have a method `typeConversionPolicy` to control warnings / errors. Due to backward compatibility reasons the default value is 'ReportingPolicy.IGNORE`. ==== * Between all Java primitive types (including their wrappers) and `String`, e.g. between `int` and `String` or `Boolean` and `String`. A format string as understood by `java.text.DecimalFormat` can be specified. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java index 83e8782432..9e4d61b46e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToBigIntegerConversion.java @@ -38,4 +38,5 @@ public String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return asSet( conversionContext.getTypeFactory().getType( BigDecimal.class ) ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java index 2605416f33..ff50b910cd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToPrimitiveConversion.java @@ -11,8 +11,8 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; -import static org.mapstruct.ap.internal.util.Collections.asSet; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigDecimal} and native number types. @@ -24,10 +24,6 @@ public class BigDecimalToPrimitiveConversion extends SimpleConversion { private final Class targetType; public BigDecimalToPrimitiveConversion(Class targetType) { - if ( !targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is no primitive type." ); - } - this.targetType = targetType; } @@ -45,4 +41,5 @@ public String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return asSet( conversionContext.getTypeFactory().getType( BigDecimal.class ) ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java index 843f34c389..ef5a3175e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToWrapperConversion.java @@ -12,8 +12,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; -import static org.mapstruct.ap.internal.util.Collections.asSet; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigDecimal} and wrappers of native number types. @@ -25,10 +25,6 @@ public class BigDecimalToWrapperConversion extends SimpleConversion { private final Class targetType; public BigDecimalToWrapperConversion(Class targetType) { - if ( targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is a primitive type." ); - } - this.targetType = NativeTypes.getPrimitiveType( targetType ); } @@ -46,4 +42,5 @@ public String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return asSet( conversionContext.getTypeFactory().getType( BigDecimal.class ) ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java index 5306c4fc5b..75c3647bad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToPrimitiveConversion.java @@ -11,8 +11,8 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; -import static org.mapstruct.ap.internal.util.Collections.asSet; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigInteger} and native number types. @@ -24,10 +24,6 @@ public class BigIntegerToPrimitiveConversion extends SimpleConversion { private final Class targetType; public BigIntegerToPrimitiveConversion(Class targetType) { - if ( !targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is no primitive type." ); - } - this.targetType = targetType; } @@ -49,4 +45,5 @@ public String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return asSet( conversionContext.getTypeFactory().getType( BigInteger.class ) ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java index c71ad26c2e..b3aa5dc6f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToWrapperConversion.java @@ -12,8 +12,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.NativeTypes; -import static org.mapstruct.ap.internal.util.Collections.asSet; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigInteger} and wrappers of native number types. @@ -25,10 +25,6 @@ public class BigIntegerToWrapperConversion extends SimpleConversion { private final Class targetType; public BigIntegerToWrapperConversion(Class targetType) { - if ( targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is a primitive type." ); - } - this.targetType = NativeTypes.getPrimitiveType( targetType ); } @@ -51,4 +47,5 @@ public String getFromExpression(ConversionContext conversionContext) { protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return asSet( conversionContext.getTypeFactory().getType( BigInteger.class ) ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java index 0f7df0ac5f..2ff73d3485 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java @@ -48,4 +48,5 @@ public interface ConversionProvider { * @return any helper methods when required. */ List getRequiredHelperMethods(ConversionContext conversionContext); + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index ac71273c03..eff3731c85 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -66,4 +66,5 @@ private String getConversionExpression(ConversionContext conversionContext, Stri return conversionString.toString(); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java index ebe2fefeaf..34f787b191 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToPrimitiveConversion.java @@ -17,10 +17,6 @@ public class PrimitiveToPrimitiveConversion extends SimpleConversion { private final Class sourceType; public PrimitiveToPrimitiveConversion(Class sourceType) { - if ( !sourceType.isPrimitive() ) { - throw new IllegalArgumentException( sourceType + " is no primitive type." ); - } - this.sourceType = sourceType; } @@ -33,4 +29,5 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { return "(" + sourceType + ") "; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java index 373302df7a..dc1bde1d05 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToWrapperConversion.java @@ -20,13 +20,6 @@ public class PrimitiveToWrapperConversion extends SimpleConversion { private final Class targetType; public PrimitiveToWrapperConversion(Class sourceType, Class targetType) { - if ( !sourceType.isPrimitive() ) { - throw new IllegalArgumentException( sourceType + " is no primitive type." ); - } - if ( targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is no wrapper type." ); - } - this.sourceType = sourceType; this.targetType = NativeTypes.getPrimitiveType( targetType ); } @@ -45,4 +38,5 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { return "." + sourceType.getName() + "Value()"; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java index e904c27753..c143085bbc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java @@ -97,4 +97,5 @@ protected List getToConversionExceptionTypes(ConversionContext conversionC protected List getFromConversionExceptionTypes(ConversionContext conversionContext) { return Collections.emptyList(); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java index 2a36bcdc79..a16ac87274 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToWrapperConversion.java @@ -19,13 +19,6 @@ public class WrapperToWrapperConversion extends SimpleConversion { private final Class targetType; public WrapperToWrapperConversion(Class sourceType, Class targetType) { - if ( sourceType.isPrimitive() ) { - throw new IllegalArgumentException( sourceType + " is no wrapper type." ); - } - if ( targetType.isPrimitive() ) { - throw new IllegalArgumentException( targetType + " is no wrapper type." ); - } - this.sourceType = NativeTypes.getPrimitiveType( sourceType ); this.targetType = NativeTypes.getPrimitiveType( targetType ); } @@ -49,4 +42,5 @@ public String getFromExpression(ConversionContext conversionContext) { return "." + sourceType.getName() + "Value()"; } } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 8f3f7f52d7..8d8750b9fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model; +import javax.lang.model.element.AnnotationMirror; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.SourceRHS; @@ -139,9 +140,34 @@ private Assignment createAssignment(SourceRHS source, ForgedMethod methodRef) { * @param targetPropertyName the name of the target property */ void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, Type sourceType, Type targetType, + String targetPropertyName) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + sourceErrorMessagePart, + targetType, + targetPropertyName, + targetType, + sourceType + ); + } + + /** + * Reports that a mapping could not be created. + * + * @param method the method that should be mapped + * @param posHint hint which @Mapping is the culprit + * @param sourceErrorMessagePart the error message part for the source + * @param sourceType the source type of the mapping + * @param targetType the type of the target mapping + * @param targetPropertyName the name of the target property + */ + void reportCannotCreateMapping(Method method, AnnotationMirror posHint, String sourceErrorMessagePart, + Type sourceType, Type targetType, String targetPropertyName) { ctx.getMessager().printMessage( method.getExecutable(), + posHint, Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, sourceErrorMessagePart, targetType, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d7f1c30843..a257dc2cee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -18,6 +20,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; + import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; @@ -50,8 +53,6 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally * configured by one or more {@link PropertyMapping}s. @@ -75,6 +76,8 @@ public static class Builder { private Set targetProperties; private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); + private NullValueMappingStrategyPrism nullValueMappingStrategy; + private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet<>(); private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; @@ -478,6 +481,7 @@ else if ( mapping.getSourceName() != null ) { .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) .defaultJavaExpression( mapping.getDefaultJavaExpression() ) + .mirror( mapping.getMirror() ) .nullValueCheckStrategy( mapping.getNullValueCheckStrategy() ) .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); @@ -522,6 +526,7 @@ else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.cont .targetProperty( targetProperty ) .targetPropertyName( mapping.getTargetName() ) .dependsOn( mapping.getDependsOn() ) + .mirror( mapping.getMirror() ) .build(); handledTargets.add( mapping.getTargetName() ); } @@ -599,6 +604,7 @@ private void applyPropertyNameBasedMapping() { .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? mapping.getNullValuePropertyMappingStrategy() : null ) + .mirror( mapping != null ? mapping.getMirror() : null ) .build(); unprocessedSourceParameters.remove( sourceParameter ); @@ -665,6 +671,7 @@ private void applyParameterNameBasedMapping() { .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? mapping.getNullValuePropertyMappingStrategy() : null ) + .mirror( mapping != null ? mapping.getMirror() : null ) .build(); propertyMappings.add( propertyMapping ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index efe6d5401b..c265d9daa0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -88,7 +88,8 @@ public final M build() { formattingParameters, selectionParameters, sourceRHS, - false + false, + null ); if ( assignment == null ) { @@ -110,11 +111,12 @@ public final M build() { ); } } - else if ( method instanceof ForgedMethod ) { - ForgedMethod forgedMethod = (ForgedMethod) method; - forgedMethod.addThrownTypes( assignment.getThrownTypes() ); + else { + if ( method instanceof ForgedMethod ) { + ForgedMethod forgedMethod = (ForgedMethod) method; + forgedMethod.addThrownTypes( assignment.getThrownTypes() ); + } } - assignment = getWrapper( assignment, method ); // mapNullToDefault diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index b429d96f27..42dc4ace94 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -92,7 +92,8 @@ public MapMappingMethod build() { keyFormattingParameters, keySelectionParameters, keySourceRHS, - false + false, + null ); if ( keyAssignment == null ) { @@ -133,7 +134,8 @@ public MapMappingMethod build() { valueFormattingParameters, valueSelectionParameters, valueSourceRHS, - false + false, + null ); if ( method instanceof ForgedMethod ) { @@ -182,6 +184,7 @@ public MapMappingMethod build() { .getFactoryMethod( method, method.getResultType(), null, ctx ); } + keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes(), valueTargetType, false ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 5832554809..3ce85d1272 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -11,6 +11,7 @@ import java.util.Map; import java.util.Set; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; @@ -92,7 +93,7 @@ public interface MappingResolver { Assignment getTargetAssignment(Method mappingMethod, Type targetType, String targetPropertyName, FormattingParameters formattingParameters, SelectionParameters selectionParameters, SourceRHS sourceRHS, - boolean preferUpdateMethods); + boolean preferUpdateMethods, AnnotationMirror mirror); Set getUsedSupportedMappings(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 207b4c153b..03dd68dd57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -337,4 +337,5 @@ public static MethodReference forStaticBuilder(String builderCreationMethod, Typ public static MethodReference forMethodCall(String methodName) { return new MethodReference( methodName, null, false ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index cbfe5aa68c..478cd76ae8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -109,7 +109,7 @@ private static class MappingBuilderBase> extends protected List dependsOn; protected Set existingVariableNames; - protected AnnotationMirror mirror; + protected AnnotationMirror positionHint; MappingBuilderBase(Class selfType) { super( selfType ); @@ -141,7 +141,7 @@ public T targetWriteAccessor(Accessor targetWriteAccessor) { } T mirror(AnnotationMirror mirror) { - this.mirror = mirror; + this.positionHint = mirror; return (T) this; } @@ -314,7 +314,8 @@ public PropertyMapping build() { formattingParameters, selectionParameters, rightHandSide, - preferUpdateMethods + preferUpdateMethods, + positionHint ); } @@ -374,6 +375,7 @@ private void reportCannotCreateMapping() { ForgedMethodHistory history = getForgedMethodHistory( rightHandSide ); reportCannotCreateMapping( method, + positionHint, history.createSourcePropertyErrorMessage(), history.getSourceType(), history.getTargetType(), @@ -383,6 +385,7 @@ private void reportCannotCreateMapping() { else { reportCannotCreateMapping( method, + positionHint, rightHandSide.getSourceErrorMessagePart(), rightHandSide.getSourceType(), targetType, @@ -449,6 +452,7 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( method.getExecutable(), + positionHint, Message.PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, targetPropertyName ); @@ -837,7 +841,8 @@ public PropertyMapping build() { formattingParameters, selectionParameters, new SourceRHS( constantExpression, sourceType, existingVariableNames, sourceErrorMessagePart ), - method.getMappingTargetParameter() != null + method.getMappingTargetParameter() != null, + positionHint ); } else { @@ -854,6 +859,7 @@ public PropertyMapping build() { if ( targetReadAccessor == null ) { ctx.getMessager().printMessage( method.getExecutable(), + positionHint, Message.CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE, targetPropertyName ); @@ -888,7 +894,7 @@ public PropertyMapping build() { else if ( errorMessageDetails == null ) { ctx.getMessager().printMessage( method.getExecutable(), - mirror, + positionHint, Message.CONSTANTMAPPING_MAPPING_NOT_FOUND, sourceType, constantExpression, @@ -899,7 +905,7 @@ else if ( errorMessageDetails == null ) { else { ctx.getMessager().printMessage( method.getExecutable(), - mirror, + positionHint, Message.CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS, sourceType, constantExpression, @@ -932,6 +938,7 @@ private Assignment getEnumAssignment() { else { ctx.getMessager().printMessage( method.getExecutable(), + positionHint, Message.CONSTANTMAPPING_NON_EXISTING_CONSTANT, constantExpression, targetType, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index 60e0957f23..cdca4a6edd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -35,8 +35,8 @@ public class TypeConversion extends ModelElement implements Assignment { private Assignment assignment; public TypeConversion( Set importTypes, - List exceptionTypes, - String expression ) { + List exceptionTypes, + String expression ) { this.importTypes = new HashSet<>( importTypes ); this.importTypes.addAll( exceptionTypes ); this.thrownTypes = exceptionTypes; @@ -128,6 +128,6 @@ public Assignment.AssignmentType getType() { @Override public boolean isCallingUpdateMethod() { - return false; + return false; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 0ab210ebfa..321e1f3ece 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -103,4 +103,5 @@ public String createLocalVarName( String desiredName ) { public boolean isFieldAssignment() { return fieldAssignment; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index a7c6960a81..cc14e035de 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -59,7 +59,7 @@ public boolean isConverted() { * * @return exceptions thrown */ - List getThrownTypes(); + List getThrownTypes(); /** * An assignment in itself can wrap another assignment. E.g.: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java index c4cc6c5c23..a005b17a6d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidationResult.java @@ -43,7 +43,7 @@ public boolean isValid() { * * @param messager the messager to print the error message to * @param element the element that had the error - * @param annotation the mirror of the annotation that had an error + * @param annotation the positionHint of the annotation that had an error * @param value the value of the annotation that had an error */ public void printErrorMessage(FormattingMessager messager, Element element, AnnotationMirror annotation, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java index 572c483314..f5a9fcc761 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java @@ -24,7 +24,7 @@ public class DefaultConversionContext implements ConversionContext { private final TypeFactory typeFactory; public DefaultConversionContext(TypeFactory typeFactory, FormattingMessager messager, Type sourceType, - Type targetType, FormattingParameters formattingParameters) { + Type targetType, FormattingParameters formattingParameters) { this.typeFactory = typeFactory; this.messager = messager; this.sourceType = sourceType; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index cabe123004..803e6a08d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -111,7 +111,7 @@ public List> getMatchingMethods(Method mapp for ( AnnotationMirror qualifierAnnotationMirror : qualifierAnnotationMirrors ) { for ( TypeMirror qualifierType : qualifierTypes ) { - // get the type of the annotation mirror. + // get the type of the annotation positionHint. DeclaredType qualifierAnnotationType = qualifierAnnotationMirror.getAnnotationType(); if ( typeUtils.isSameType( qualifierType, qualifierAnnotationType ) ) { // Match! we have an annotation which has the @Qualifer marker ( could be @Named as well ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 6454d7c20c..b178861dd4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -131,10 +131,15 @@ public void printMessage(Element e, Message msg, Object... args) { @Override public void printMessage(Element e, AnnotationMirror a, Message msg, Object... args) { - String message = String.format( msg.getDescription(), args ); - delegate.printMessage( msg.getDiagnosticKind(), message, e, a ); - if ( msg.getDiagnosticKind() == Kind.ERROR ) { - isErroneous = true; + if ( a == null ) { + printMessage( e, msg, args ); + } + else { + String message = String.format( msg.getDescription(), args ); + delegate.printMessage( msg.getDiagnosticKind(), message, e, a ); + if ( msg.getDiagnosticKind() == Kind.ERROR ) { + isErroneous = true; + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 0ab2f32fa3..c96dd6c6f5 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -5,14 +5,11 @@ */ package org.mapstruct.ap.internal.processor.creation; -import static java.util.Collections.singletonList; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; - +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; @@ -46,11 +43,16 @@ import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; +import static java.util.Collections.singletonList; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * The one and only implementation of {@link MappingResolver}. The class has been split into an interface an * implementation for the sake of avoiding package dependencies. Specifically, this implementation refers to classes @@ -95,7 +97,7 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T @Override public Assignment getTargetAssignment(Method mappingMethod, Type targetType, String targetPropertyName, FormattingParameters formattingParameters, SelectionParameters selectionParameters, SourceRHS sourceRHS, - boolean preferUpdateMapping) { + boolean preferUpdateMapping, AnnotationMirror positionHint) { SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, targetPropertyName, preferUpdateMapping ); @@ -105,7 +107,8 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, Str mappingMethod, formattingParameters, sourceRHS, - criteria + criteria, + positionHint ); return attempt.getTargetAssignment( sourceRHS.getSourceTypeForMatching(), targetType ); @@ -135,6 +138,7 @@ private class ResolvingAttempt { private final SourceRHS sourceRHS; private final boolean savedPreferUpdateMapping; private final FormattingParameters formattingParameters; + private final AnnotationMirror positionHint; // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches, // second doesn't. In that case, the first builtin method should not lead to a supported method @@ -142,7 +146,9 @@ private class ResolvingAttempt { private final Set supportingMethodCandidates; private ResolvingAttempt(List sourceModel, Method mappingMethod, - FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria) { + FormattingParameters formattingParameters, SourceRHS sourceRHS, + SelectionCriteria criteria, + AnnotationMirror positionHint) { this.mappingMethod = mappingMethod; this.methods = filterPossibleCandidateMethods( sourceModel ); @@ -152,6 +158,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, this.supportingMethodCandidates = new HashSet<>(); this.selectionCriteria = criteria; this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); + this.positionHint = positionHint; } private List filterPossibleCandidateMethods(List candidateMethods) { @@ -196,10 +203,11 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { } // then type conversion - Assignment conversion = resolveViaConversion( sourceType, targetType ); + ConversionAssignment conversion = resolveViaConversion( sourceType, targetType ); if ( conversion != null ) { - conversion.setAssignment( sourceRHS ); - return conversion; + conversion.reportMessageWhenNarrowing( messager, this ); + conversion.getAssignment().setAssignment( sourceRHS ); + return conversion.getAssignment(); } // check for a built-in method @@ -231,14 +239,15 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { conversion = resolveViaMethodAndConversion( sourceType, targetType ); if ( conversion != null ) { usedSupportedMappings.addAll( supportingMethodCandidates ); - return conversion; + return conversion.getAssignment(); } // if nothing works, alas, the result is null return null; } - private Assignment resolveViaConversion(Type sourceType, Type targetType) { + private ConversionAssignment resolveViaConversion(Type sourceType, Type targetType) { + ConversionProvider conversionProvider = conversions.getConversion( sourceType, targetType ); if ( conversionProvider == null ) { @@ -256,9 +265,16 @@ private Assignment resolveViaConversion(Type sourceType, Type targetType) { for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) { usedSupportedMappings.add( new SupportingMappingMethod( helperMethod ) ); } - return conversionProvider.to( ctx ); + + Assignment conversion = conversionProvider.to( ctx ); + if ( conversion != null ) { + return new ConversionAssignment( sourceType, targetType, conversionProvider.to( ctx ) ); + } + return null; } + + /** * Returns a reference to a method mapping the given source type to the given target type, if such a method * exists. @@ -372,11 +388,12 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(), targetType, true ); if ( methodRefY != null ) { - Assignment conversionXRef = - resolveViaConversion( sourceType, methodYCandidate.getSourceParameters().get( 0 ).getType() ); + Type targetTypeX = methodYCandidate.getSourceParameters().get( 0 ).getType(); + ConversionAssignment conversionXRef = resolveViaConversion( sourceType, targetTypeX ); if ( conversionXRef != null ) { - methodRefY.setAssignment( conversionXRef ); - conversionXRef.setAssignment( sourceRHS ); + methodRefY.setAssignment( conversionXRef.getAssignment() ); + conversionXRef.getAssignment().setAssignment( sourceRHS ); + conversionXRef.reportMessageWhenNarrowing( messager, this ); break; } else { @@ -397,12 +414,12 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp * * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) */ - private Assignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { + private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { List methodXCandidates = new ArrayList<>( methods ); methodXCandidates.addAll( builtInMethods.getBuiltInMethods() ); - Assignment conversionYRef = null; + ConversionAssignment conversionYRef = null; // search the other way around for ( Method methodXCandidate : methodXCandidates ) { @@ -418,8 +435,9 @@ private Assignment resolveViaMethodAndConversion(Type sourceType, Type targetTyp if ( methodRefX != null ) { conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType ); if ( conversionYRef != null ) { - conversionYRef.setAssignment( methodRefX ); + conversionYRef.getAssignment().setAssignment( methodRefX ); methodRefX.setAssignment( sourceRHS ); + conversionYRef.reportMessageWhenNarrowing( messager, this ); break; } else { @@ -575,4 +593,47 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { return false; } } + + private static class ConversionAssignment { + + private final Type sourceType; + private final Type targetType; + private final Assignment assignment; + + ConversionAssignment(Type sourceType, Type targetType, Assignment assignment) { + this.sourceType = sourceType; + this.targetType = targetType; + this.assignment = assignment; + } + + Assignment getAssignment() { + return assignment; + } + + void reportMessageWhenNarrowing(FormattingMessager messager, ResolvingAttempt attempt) { + + if ( NativeTypes.isNarrowing( sourceType.getFullyQualifiedName(), targetType.getFullyQualifiedName() ) ) { + ReportingPolicyPrism policy = attempt.mappingMethod.getMapperConfiguration().typeConversionPolicy(); + if ( policy == ReportingPolicyPrism.WARN ) { + report( messager, attempt, Message.CONVERSION_LOSSY_WARNING ); + } + else if ( policy == ReportingPolicyPrism.ERROR ) { + report( messager, attempt, Message.CONVERSION_LOSSY_ERROR ); + } + } + } + + private void report(FormattingMessager messager, ResolvingAttempt attempt, Message message) { + + messager.printMessage( + attempt.mappingMethod.getExecutable(), + attempt.positionHint, + message, + attempt.sourceRHS.getSourceErrorMessagePart(), + sourceType.toString(), + targetType.toString() + ); + } + + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 2e754ff9d9..6d085ea760 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -89,7 +89,7 @@ public static boolean isDefaultMethod(ExecutableElement method) { } /** - * @param mirror the type mirror + * @param mirror the type positionHint * * @return the corresponding type element */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java index cd778162a1..b3f9bd7240 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java @@ -39,10 +39,10 @@ public interface FormattingMessager { /** * Prints a message of the specified kind at the location of the - * annotation mirror of the annotated element. + * annotation positionHint of the annotated element. * * @param e the annotated element - * @param a the annotation to use as a position hint + * @param a the annotation to use as a position hint (can be null) * @param msg the message * @param args Arguments referenced by the format specifiers in the format string. If there are more arguments * than format specifiers, the extra arguments are ignored @@ -52,7 +52,7 @@ public interface FormattingMessager { /** * Prints a message of the specified kind at the location of the - * annotation value inside the annotation mirror of the annotated + * annotation value inside the annotation positionHint of the annotated * element. * * @param e the annotated element diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 49b0aded8d..1545e115ab 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -130,6 +130,19 @@ public ReportingPolicyPrism unmappedSourcePolicy() { return ReportingPolicyPrism.valueOf( mapperPrism.unmappedSourcePolicy() ); } + public ReportingPolicyPrism typeConversionPolicy() { + if ( mapperPrism.values.typeConversionPolicy() != null ) { + return ReportingPolicyPrism.valueOf( mapperPrism.typeConversionPolicy() ); + } + + if ( mapperConfigPrism != null && mapperConfigPrism.values.typeConversionPolicy() != null ) { + return ReportingPolicyPrism.valueOf( mapperConfigPrism.typeConversionPolicy() ); + } + + // fall back to default defined in the annotation + return ReportingPolicyPrism.valueOf( mapperPrism.typeConversionPolicy() ); + } + public CollectionMappingStrategyPrism getCollectionMappingStrategy() { if ( mapperConfigPrism != null && mapperPrism.values.collectionMappingStrategy() == null ) { return CollectionMappingStrategyPrism.valueOf( mapperConfigPrism.collectionMappingStrategy() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 445c0b3b0f..a718a994de 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -59,6 +59,9 @@ public enum Message { PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_WHITESPACE_TRIMMED( "The property named \"%s\" has whitespaces, using trimmed property \"%s\" instead.", Diagnostic.Kind.WARNING ), + CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ), + CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ), + CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ), CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS( "Can't map \"%s %s\" to \"%s %s\". Reason: %s." ), CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index f453dee51a..769f7b83f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -29,6 +29,8 @@ public class NativeTypes { private static final Map TYPE_KIND_NAME = new EnumMap<>( TypeKind.class ); private static final Map ANALYZERS; + private static final Map NARROWING_LUT; + private static final Pattern PTRN_HEX = Pattern.compile( "^0[x|X].*" ); private static final Pattern PTRN_OCT = Pattern.compile( "^0_*[0-7].*" ); private static final Pattern PTRN_BIN = Pattern.compile( "^0[b|B].*" ); @@ -165,7 +167,6 @@ void removeAndValidateIntegerLiteralSuffix() { /** * Double suffix forbidden for float. * - * @param isFloat */ void removeAndValidateFloatingPointLiteralSuffix() { boolean endsWithLSuffix = PTRN_LONG.matcher( val ).find(); @@ -458,6 +459,22 @@ private NativeTypes() { TYPE_KIND_NAME.put( TypeKind.FLOAT, "float" ); TYPE_KIND_NAME.put( TypeKind.DOUBLE, "double" ); + Map tmp3 = new HashMap<>( ); + tmp3.put( byte.class.getName(), 1 ); + tmp3.put( Byte.class.getName(), 1 ); + tmp3.put( short.class.getName(), 2 ); + tmp3.put( Short.class.getName(), 2 ); + tmp3.put( int.class.getName(), 3 ); + tmp3.put( Integer.class.getName(), 3 ); + tmp3.put( long.class.getName(), 4 ); + tmp3.put( Long.class.getName(), 4 ); + tmp3.put( float.class.getName(), 5 ); + tmp3.put( Float.class.getName(), 5 ); + tmp3.put( double.class.getName(), 6 ); + tmp3.put( Double.class.getName(), 6 ); + tmp3.put( BigInteger.class.getName(), 50 ); + tmp3.put( BigDecimal.class.getName(), 51 ); + NARROWING_LUT = Collections.unmodifiableMap( tmp3 ); } public static Class getWrapperType(Class clazz) { @@ -517,4 +534,17 @@ public static Class getLiteral(String className, String literal) { public static String getName(TypeKind typeKind) { return TYPE_KIND_NAME.get( typeKind ); } + + public static boolean isNarrowing( String sourceFQN, String targetFQN ) { + + boolean isNarrowing = false; + + Integer sourcePosition = NARROWING_LUT.get( sourceFQN ); + Integer targetPosition = NARROWING_LUT.get( targetFQN ); + + if ( sourcePosition != null && targetPosition != null ) { + isNarrowing = ( targetPosition - sourcePosition < 0 ); + } + return isNarrowing; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java new file mode 100644 index 0000000000..5a96d6deb2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +public class CutleryInventoryDto { + + private short numberOfKnifes; + private int numberOfForks; + private byte numberOfSpoons; + + private float approximateKnifeLength; + + public short getNumberOfKnifes() { + return numberOfKnifes; + } + + public void setNumberOfKnifes(short numberOfKnifes) { + this.numberOfKnifes = numberOfKnifes; + } + + public int getNumberOfForks() { + return numberOfForks; + } + + public void setNumberOfForks(int numberOfForks) { + this.numberOfForks = numberOfForks; + } + + public byte getNumberOfSpoons() { + return numberOfSpoons; + } + + public void setNumberOfSpoons(byte numberOfSpoons) { + this.numberOfSpoons = numberOfSpoons; + } + + public float getApproximateKnifeLength() { + return approximateKnifeLength; + } + + public void setApproximateKnifeLength(float approximateKnifeLength) { + this.approximateKnifeLength = approximateKnifeLength; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java new file mode 100644 index 0000000000..9575ed99dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +public class CutleryInventoryEntity { + + private int numberOfKnifes; + private Long numberOfForks; + private short numberOfSpoons; + + private double approximateKnifeLength; + + public int getNumberOfKnifes() { + return numberOfKnifes; + } + + public void setNumberOfKnifes(int numberOfKnifes) { + this.numberOfKnifes = numberOfKnifes; + } + + public Long getNumberOfForks() { + return numberOfForks; + } + + public void setNumberOfForks(Long numberOfForks) { + this.numberOfForks = numberOfForks; + } + + public short getNumberOfSpoons() { + return numberOfSpoons; + } + + public void setNumberOfSpoons(short numberOfSpoons) { + this.numberOfSpoons = numberOfSpoons; + } + + public double getApproximateKnifeLength() { + return approximateKnifeLength; + } + + public void setApproximateKnifeLength(double approximateKnifeLength) { + this.approximateKnifeLength = approximateKnifeLength; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryMapper.java new file mode 100644 index 0000000000..258f696d5b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface CutleryInventoryMapper { + + CutleryInventoryMapper INSTANCE = Mappers.getMapper( CutleryInventoryMapper.class ); + + CutleryInventoryEntity map( CutleryInventoryDto in ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper1.java new file mode 100644 index 0000000000..b96745c3cc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper1.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerMapper1 { + + ErroneousKitchenDrawerMapper1 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerMapper1.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfForks", source = "numberOfForks" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper3.java new file mode 100644 index 0000000000..1b270dc395 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper3.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR, uses = VerySpecialNumberMapper.class ) +public interface ErroneousKitchenDrawerMapper3 { + + ErroneousKitchenDrawerMapper3 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerMapper3.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfSpoons", source = "numberOfSpoons" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper4.java new file mode 100644 index 0000000000..fc02081182 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper4.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerMapper4 { + + ErroneousKitchenDrawerMapper4 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerMapper4.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "depth", source = "depth" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper5.java new file mode 100644 index 0000000000..ef86586060 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper5.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerMapper5 { + + ErroneousKitchenDrawerMapper5 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerMapper5.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "length", source = "length" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper2.java new file mode 100644 index 0000000000..2ececec67b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper2.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.WARN ) +public interface KitchenDrawerMapper2 { + + KitchenDrawerMapper2 INSTANCE = Mappers.getMapper( KitchenDrawerMapper2.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfKnifes", source = "numberOfKnifes" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper6.java new file mode 100644 index 0000000000..8932858109 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerMapper6.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.WARN, uses = VerySpecialNumberMapper.class ) +public interface KitchenDrawerMapper6 { + + KitchenDrawerMapper6 INSTANCE = Mappers.getMapper( KitchenDrawerMapper6.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "height", source = "height" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ListMapper.java new file mode 100644 index 0000000000..3d7f36c026 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ListMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.List; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.WARN ) +public interface ListMapper { + + List map(List in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java new file mode 100644 index 0000000000..de1921ea5d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -0,0 +1,159 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.withinPercentage; + +/** + * Tests the conversion between Joda-Time types and String/Date/Calendar. + * + * @author Sjaak Derksen + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + OversizedKitchenDrawerDto.class, + RegularKitchenDrawerEntity.class, + VerySpecialNumber.class, + VerySpecialNumberMapper.class, + CutleryInventoryMapper.class, + CutleryInventoryDto.class, + CutleryInventoryEntity.class +}) +@IssueKey("5") +public class LossyConversionTest { + + @Test + public void testNoErrorCase() { + + CutleryInventoryDto dto = new CutleryInventoryDto(); + dto.setNumberOfForks( 5 ); + dto.setNumberOfKnifes( (short) 7 ); + dto.setNumberOfSpoons( (byte) 3 ); + dto.setApproximateKnifeLength( 3.7f ); + + CutleryInventoryEntity entity = CutleryInventoryMapper.INSTANCE.map( dto ); + assertThat( entity.getNumberOfForks() ).isEqualTo( 5L ); + assertThat( entity.getNumberOfKnifes() ).isEqualTo( 7 ); + assertThat( entity.getNumberOfSpoons() ).isEqualTo( (short) 3 ); + assertThat( entity.getApproximateKnifeLength() ).isCloseTo( 3.7d, withinPercentage( 0.0001d ) ); + } + + @Test + @WithClasses(ErroneousKitchenDrawerMapper1.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerMapper1.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + messageRegExp = "Can't map property \"long numberOfForks\". It has a possibly lossy conversion from " + + "long to int.") + }) + public void testConversionFromlongToint() { + } + + @Test + @WithClasses(KitchenDrawerMapper2.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = KitchenDrawerMapper2.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 24, + messageRegExp = "property \"java.math.BigInteger numberOfKnifes\" has a possibly lossy conversion " + + "from java.math.BigInteger to java.lang.Integer.") + }) + public void testConversionFromBigIntegerToInteger() { + } + + @Test + @WithClasses(ErroneousKitchenDrawerMapper3.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerMapper3.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + messageRegExp = "org.mapstruct.ap.test.conversion.lossy.VerySpecialNumber numberOfSpoons\". It has " + + "a possibly lossy conversion from java.math.BigInteger to java.lang.Long") + }) + public void test2StepConversionFromBigIntegerToLong() { + } + + @Test + @WithClasses(ErroneousKitchenDrawerMapper4.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerMapper4.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + messageRegExp = "Can't map property \"java.lang.Double depth\". It has a possibly lossy conversion " + + "from java.lang.Double to float.") + }) + public void testConversionFromDoubleTofloat() { + } + + @Test + @WithClasses(ErroneousKitchenDrawerMapper5.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerMapper5.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + messageRegExp = "\"java.math.BigDecimal length\". It has a possibly lossy conversion from " + + "java.math.BigDecimal to java.lang.Float.") + }) + public void testConversionFromBigDecimalToFloat() { + } + + @Test + @WithClasses(KitchenDrawerMapper6.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = KitchenDrawerMapper6.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 24, + messageRegExp = "property \"double height\" has a possibly lossy conversion from double to float.") + }) + public void test2StepConversionFromdoubleTofloat() { + } + + @Test + @WithClasses(ListMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = ListMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + messageRegExp = "collection element has a possibly lossy conversion from java.math.BigDecimal to " + + "java.math.BigInteger") + }) + public void testListElementConversion() { + } + + @Test + @WithClasses(MapMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = MapMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 19, + messageRegExp = "map key has a possibly lossy conversion from java.lang.Long to java.lang.Integer."), + @Diagnostic(type = MapMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 19, + messageRegExp = "map value has a possibly lossy conversion from java.lang.Double to java.lang.Float.") + }) + public void testMapElementConversion() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/MapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/MapMapper.java new file mode 100644 index 0000000000..22cec92e3e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/MapMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import java.util.Map; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * + * @author Sjaak Derksen + */ +@Mapper( typeConversionPolicy = ReportingPolicy.WARN ) +public interface MapMapper { + + Map map(Map in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java new file mode 100644 index 0000000000..110bb2f07c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java @@ -0,0 +1,73 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * + * @author Sjaak Derksen + */ +public class OversizedKitchenDrawerDto { + + /* yes, its a big drawer */ + private long numberOfForks; + private BigInteger numberOfKnifes; + private VerySpecialNumber numberOfSpoons; + private Double depth; + private BigDecimal length; + private double height; + + public long getNumberOfForks() { + return numberOfForks; + } + + public void setNumberOfForks(long numberOfForks) { + this.numberOfForks = numberOfForks; + } + + public BigInteger getNumberOfKnifes() { + return numberOfKnifes; + } + + public void setNumberOfKnifes(BigInteger numberOfKnifes) { + this.numberOfKnifes = numberOfKnifes; + } + + public VerySpecialNumber getNumberOfSpoons() { + return numberOfSpoons; + } + + public void setNumberOfSpoons(VerySpecialNumber numberOfSpoons) { + this.numberOfSpoons = numberOfSpoons; + } + + public Double getDepth() { + return depth; + } + + public void setDepth(Double depth) { + this.depth = depth; + } + + public BigDecimal getLength() { + return length; + } + + public void setLength(BigDecimal length) { + this.length = length; + } + + public double getHeight() { + return height; + } + + public void setHeight(double height) { + this.height = height; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java new file mode 100644 index 0000000000..d49a89052d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +/** + * + * @author Sjaak Derksen + */ +public class RegularKitchenDrawerEntity { + + private int numberOfForks; + private Integer numberOfKnifes; + private Long numberOfSpoons; + private float depth; + private Float length; + private VerySpecialNumber height; + + public int getNumberOfForks() { + return numberOfForks; + } + + public void setNumberOfForks(int numberOfForks) { + this.numberOfForks = numberOfForks; + } + + public Integer getNumberOfKnifes() { + return numberOfKnifes; + } + + public void setNumberOfKnifes(Integer numberOfKnifes) { + this.numberOfKnifes = numberOfKnifes; + } + + public Long getNumberOfSpoons() { + return numberOfSpoons; + } + + public void setNumberOfSpoons(Long numberOfSpoons) { + this.numberOfSpoons = numberOfSpoons; + } + + public float getDepth() { + return depth; + } + + public void setDepth(float depth) { + this.depth = depth; + } + + public Float getLength() { + return length; + } + + public void setLength(Float length) { + this.length = length; + } + + public VerySpecialNumber getHeight() { + return height; + } + + public void setHeight(VerySpecialNumber height) { + this.height = height; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumber.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumber.java new file mode 100644 index 0000000000..3f4be13d1f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumber.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +/** + * + * @author Sjaak Derksen + */ +public class VerySpecialNumber { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java new file mode 100644 index 0000000000..29531bea0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import java.math.BigInteger; + +/** + * + * @author Sjaak Derksen + */ +public class VerySpecialNumberMapper { + + VerySpecialNumber fromFLoat( float f ) { + return new VerySpecialNumber(); + } + + BigInteger toBigInteger( VerySpecialNumber v ) { + return new BigInteger( "10" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper1.java new file mode 100644 index 0000000000..1e4bc62c29 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper1.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousMapper1 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "property", source = "source" ) + Target map( Source source ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper2.java new file mode 100644 index 0000000000..34802a0c73 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper2.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousMapper2 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "nameBasedSource" ) + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper3.java new file mode 100644 index 0000000000..b8d04aa5bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper3.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousMapper3 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "constant", constant = "constant" ) + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper4.java new file mode 100644 index 0000000000..7e9f1ee85a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousMapper4.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousMapper4 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "property", source = "source" ) + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java new file mode 100644 index 0000000000..ed2e9e2108 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@IssueKey("1504") +@WithClasses( { Source.class, Target.class, UnmappableClass.class } ) +@RunWith(AnnotationProcessorTestRunner.class) +public class ErroneousPropertyMappingTest { + + @Test + @WithClasses( ErroneousMapper1.class ) + @IssueKey("1504") + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + messageRegExp = ".*Consider to declare/implement a mapping method.*") } + ) + public void testUnmappableSourceProperty() { } + + @Test + @WithClasses( ErroneousMapper2.class ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + messageRegExp = ".*Consider to declare/implement a mapping method.*") } + ) + public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { } + + @Test + @WithClasses( ErroneousMapper3.class ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + messageRegExp = "Can't map.*constant.*" ) } + ) + public void testUnmappableConstantAssignment() { } + + @Test + @WithClasses( ErroneousMapper4.class ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + messageRegExp = ".*Consider to declare/implement a mapping method.*") } + ) + public void testUnmappableParameterAssignment() { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Source.java new file mode 100644 index 0000000000..10d43623e5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Source.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +public class Source { + + private UnmappableClass source; + private UnmappableClass nameBasedSource; + + public UnmappableClass getSource() { + return source; + } + + public void setSource(UnmappableClass source) { + this.source = source; + } + + public UnmappableClass getNameBasedSource() { + return nameBasedSource; + } + + public void setNameBasedSource(UnmappableClass nameBasedSource) { + this.nameBasedSource = nameBasedSource; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Target.java new file mode 100644 index 0000000000..c811a30019 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/Target.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +public class Target { + + private String property; + private String nameBasedSource; + private UnmappableClass constant; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + + public String getNameBasedSource() { + return nameBasedSource; + } + + public void setNameBasedSource(String nameBasedSource) { + this.nameBasedSource = nameBasedSource; + } + + public UnmappableClass getConstant() { + return constant; + } + + public void setConstant(UnmappableClass constant) { + this.constant = constant; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/UnmappableClass.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/UnmappableClass.java new file mode 100644 index 0000000000..6f1a796777 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/UnmappableClass.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.propertymapping; + +public class UnmappableClass { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index b03b42b3e5..c1c6d8d58f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -191,7 +191,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc diagnostics = { @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, - line = 30, + line = 28, messageRegExp = "^Constant \"DENMARK\" doesn't exist in enum type org.mapstruct.ap.test.source." + "constants.CountryEnum for property \"country\".$"), @Diagnostic(type = ErroneousMapper5.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index 91db277198..d2038a9c5c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -170,7 +170,7 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } diagnostics = { @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 24, + line = 23, messageRegExp = "No read accessor found for property \"type\" in target type."), @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, From 6f19d5615500d66193f34244381db1e31b6856d9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Oct 2018 15:22:25 +0100 Subject: [PATCH 0297/1006] #1566, #1253 Add support for initializing the AccessorNamingStrategy with Elements and Types and use Types for determining fluent setters * This allows using generic builders --- .../org/mapstruct/ap/MappingProcessor.java | 5 ++- .../util/AnnotationProcessorContext.java | 19 +++++++- .../ap/spi/AccessorNamingStrategy.java | 9 ++++ .../ap/spi/DefaultAccessorNamingStrategy.java | 14 +++++- .../spi/MapStructProcessingEnvironment.java | 37 +++++++++++++++ .../ap/test/bugs/_1566/AbstractBuilder.java | 19 ++++++++ .../ap/test/bugs/_1566/Issue1566Mapper.java | 20 +++++++++ .../ap/test/bugs/_1566/Issue1566Test.java | 41 +++++++++++++++++ .../mapstruct/ap/test/bugs/_1566/Source.java | 31 +++++++++++++ .../mapstruct/ap/test/bugs/_1566/Target.java | 45 +++++++++++++++++++ 10 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/AbstractBuilder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index c277ba5c3a..83841db525 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -114,7 +114,10 @@ public synchronized void init(ProcessingEnvironment processingEnv) { super.init( processingEnv ); options = createOptions(); - annotationProcessorContext = new AnnotationProcessorContext( processingEnv.getElementUtils() ); + annotationProcessorContext = new AnnotationProcessorContext( + processingEnv.getElementUtils(), + processingEnv.getTypeUtils() + ); } private Options createOptions() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index c38a1c11ee..b6bcc85b48 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -12,6 +12,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; @@ -20,13 +21,14 @@ import org.mapstruct.ap.spi.DefaultBuilderProvider; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesBuilderProvider; +import org.mapstruct.ap.spi.MapStructProcessingEnvironment; /** * Keeps contextual data in the scope of the entire annotation processor ("application scope"). * * @author Gunnar Morling */ -public class AnnotationProcessorContext { +public class AnnotationProcessorContext implements MapStructProcessingEnvironment { private List astModifyingAnnotationProcessors; @@ -36,11 +38,13 @@ public class AnnotationProcessorContext { private AccessorNamingUtils accessorNaming; private Elements elementUtils; + private Types typeUtils; - public AnnotationProcessorContext(Elements elementUtils) { + public AnnotationProcessorContext(Elements elementUtils, Types typeUtils) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors() ); this.elementUtils = elementUtils; + this.typeUtils = typeUtils; } /** @@ -67,6 +71,7 @@ private void initialize() { defaultBuilderProvider = new ImmutablesBuilderProvider(); } this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); + this.accessorNamingStrategy.init( this ); this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); this.initialized = true; @@ -86,6 +91,16 @@ private static List findAstModifyingAnnotationP return processors; } + @Override + public Elements getElementUtils() { + return elementUtils; + } + + @Override + public Types getTypeUtils() { + return typeUtils; + } + public List getAstModifyingAnnotationProcessors() { return astModifyingAnnotationProcessors; } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java index 0afc22695a..e4dd2cfe27 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java @@ -15,6 +15,15 @@ */ public interface AccessorNamingStrategy { + /** + * Initializes the accessor naming strategy with the MapStruct processing environment. + * + * @param processingEnvironment environment for facilities + */ + default void init(MapStructProcessingEnvironment processingEnvironment) { + + } + /** * Returns the type of the given method. * diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index ab0d604a69..6a8c9baafb 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -12,8 +12,10 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; import javax.lang.model.util.SimpleElementVisitor6; import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.Types; import org.mapstruct.ap.spi.util.IntrospectorUtils; @@ -26,6 +28,15 @@ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + protected Elements elementUtils; + protected Types typeUtils; + + @Override + public void init(MapStructProcessingEnvironment processingEnvironment) { + this.elementUtils = processingEnvironment.getElementUtils(); + this.typeUtils = processingEnvironment.getTypeUtils(); + } + @Override public MethodType getMethodType(ExecutableElement method) { if ( isGetterMethod( method ) ) { @@ -90,8 +101,7 @@ protected boolean isFluentSetter(ExecutableElement method) { return method.getParameters().size() == 1 && !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && !isAdderWithUpperCase4thCharacter( method ) && - //TODO The Types need to be compared with Types#isSameType(TypeMirror, TypeMirror) - method.getReturnType().toString().equals( method.getEnclosingElement().asType().toString() ); + typeUtils.isAssignable( method.getReturnType(), method.getEnclosingElement().asType() ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java new file mode 100644 index 0000000000..97fd42148b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +/** + * MapStruct will provide the implementations of its SPIs with on object implementing this interface so they can use + * facilities provided by it. It is a subset of {@link javax.annotation.processing.ProcessingEnvironment + * ProcessingEnvironment}. + * + * @author Filip Hrisafov + * @see javax.annotation.processing.ProcessingEnvironment + */ +public interface MapStructProcessingEnvironment { + + /** + * Returns an implementation of some utility methods for + * operating on elements + * + * @return element utilities + */ + Elements getElementUtils(); + + /** + * Returns an implementation of some utility methods for + * operating on types. + * + * @return type utilities + */ + Types getTypeUtils(); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/AbstractBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/AbstractBuilder.java new file mode 100644 index 0000000000..d97fccf9be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/AbstractBuilder.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1566; + +/** + * @author Filip Hrisafov + */ +public abstract class AbstractBuilder> { + String id; + + @SuppressWarnings("unchecked") + public T id(final String id) { + this.id = id; + return (T) this; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Mapper.java new file mode 100644 index 0000000000..2ed6ed6d75 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1566; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1566Mapper { + + Issue1566Mapper INSTANCE = Mappers.getMapper( Issue1566Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java new file mode 100644 index 0000000000..667f90d1ca --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1566; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + AbstractBuilder.class, + Issue1566Mapper.class, + Source.class, + Target.class +}) +@IssueKey("1566") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1566Test { + + @Test + public void genericMapperIsCorrectlyUsed() { + Source source = new Source(); + source.setId( "id-123" ); + source.setName( "Source" ); + + Target target = Issue1566Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( "id-123" ); + assertThat( target.getName() ).isEqualTo( "Source" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Source.java new file mode 100644 index 0000000000..73f3820d00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Source.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1566; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String id; + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Target.java new file mode 100644 index 0000000000..64a336af3c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Target.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1566; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String id; + private final String name; + + private Target(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractBuilder { + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Target build() { + return new Target( id, name ); + } + } +} From 104ebf88da8c6145b790905f0c1db66a3cd35a6b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Oct 2018 17:33:28 +0100 Subject: [PATCH 0298/1006] Add a FreeBuilder specific AccessNamingStrategy The builder created by FreeBuilder have different fluent methods created. When using FreeBuilder one needs to use the JavaBean convention for the getters (as otherwise MapStruct won't recognize them), this leads to FreeBuilder creating fluent setters that start with set (so we can safely ignore all other fluent setters) --- .../util/AnnotationProcessorContext.java | 15 ++++---- .../internal/util/FreeBuilderConstants.java | 20 +++++++++++ .../FreeBuilderAccessorNamingStrategy.java | 35 +++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/FreeBuilderConstants.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index b6bcc85b48..d46ca6f02f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.ServiceLoader; -import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; @@ -19,6 +18,7 @@ import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.FreeBuilderAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesBuilderProvider; import org.mapstruct.ap.spi.MapStructProcessingEnvironment; @@ -61,14 +61,17 @@ private void initialize() { AccessorNamingStrategy defaultAccessorNamingStrategy; BuilderProvider defaultBuilderProvider; - TypeElement immutableElement = elementUtils.getTypeElement( ImmutablesConstants.IMMUTABLE_FQN ); - if ( immutableElement == null ) { - defaultAccessorNamingStrategy = new DefaultAccessorNamingStrategy(); + if ( elementUtils.getTypeElement( ImmutablesConstants.IMMUTABLE_FQN ) != null ) { + defaultAccessorNamingStrategy = new ImmutablesAccessorNamingStrategy(); + defaultBuilderProvider = new ImmutablesBuilderProvider(); + } + else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) != null ) { + defaultAccessorNamingStrategy = new FreeBuilderAccessorNamingStrategy(); defaultBuilderProvider = new DefaultBuilderProvider(); } else { - defaultAccessorNamingStrategy = new ImmutablesAccessorNamingStrategy(); - defaultBuilderProvider = new ImmutablesBuilderProvider(); + defaultAccessorNamingStrategy = new DefaultAccessorNamingStrategy(); + defaultBuilderProvider = new DefaultBuilderProvider(); } this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); this.accessorNamingStrategy.init( this ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/FreeBuilderConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/FreeBuilderConstants.java new file mode 100644 index 0000000000..e7ae4d63d4 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/FreeBuilderConstants.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +/** + * Helper for holding FreeBuilder FQN. + * + * @author Filip Hrisafov + */ +public class FreeBuilderConstants { + + public static final String FREE_BUILDER_FQN = "org.inferred.freebuilder.FreeBuilder"; + + private FreeBuilderConstants() { + + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java new file mode 100644 index 0000000000..f2d3c3402d --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.element.ExecutableElement; + +/** + * Accessor naming strategy for FreeBuilder. + * FreeBuilder adds a lot of other methods that can be considered as fluent setters. Such as: + *

        + *
      • {@code from(Target)}
      • + *
      • {@code mapXXX(UnaryOperator)}
      • + *
      • {@code mutateXXX(Consumer)}
      • + *
      • {@code mergeFrom(Target)}
      • + *
      • {@code mergeFrom(Target.Builder)}
      • + *
      + *

      + * When the JavaBean convention is not used with FreeBuilder then the getters are non standard and MapStruct + * won't recognize them. Therefore one needs to use the JavaBean convention in which the fluent setters + * start with {@code set}. + * + * @author Filip Hrisafov + */ +public class FreeBuilderAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + @Override + protected boolean isFluentSetter(ExecutableElement method) { + // When using FreeBuilder one needs to use the JavaBean convention, which means that all setters will start + // with set + return false; + } +} From a0ae8750a15caa0192b868df149062537b786bd6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 1 Nov 2018 23:56:15 +0100 Subject: [PATCH 0299/1006] Adapt japicmp-maven-plugin to not consider adding a new default method to an interface as incompatible According to https://docs.oracle.com/javase/specs/jls/se8/html/jls-13.html#jls-13.5.3 Adding an abstract (default) method to an interface does not break compatibility with pre-existing binaries. --- parent/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/parent/pom.xml b/parent/pom.xml index 7ac85a46fe..a30051d958 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -541,6 +541,14 @@ \d+\.\d+\.\d+\.Final true + + + METHOD_NEW_DEFAULT + true + false + MINOR + + From 60611d94cf40c8cfe9bdb2df80f43dc6b6ad85ff Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 3 Nov 2018 09:03:22 +0100 Subject: [PATCH 0300/1006] Add more info for the FreeBuilder support in the documentation * Add the usage of the FreeBuilderAccessorNamingStrategy when FreeBuilder is present * And the fact that the JavaBean convention should be followed when using FreeBuilder --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 9bdc041e34..be998a3b84 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -731,7 +731,8 @@ Supported builder frameworks: * https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] * https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] * https://immutables.github.io/[Immutables] - When Immutables are present on the annotation processor path then the `ImmutablesAccessorNamingStrategy` and `ImmutablesBuilderProvider` would be used by default -* https://github.com/google/FreeBuilder[FreeBuilder] +* https://github.com/google/FreeBuilder[FreeBuilder] - When FreeBuilder is present on the annotation processor path then the `FreeBuilderAccessorNamingStrategy` would be used by default. +When using FreeBuilder then the JavaBean convention should be followed, otherwise MapStruct won't recognize the fluent getters. * It also works for custom builders (handwritten ones) if the implementation supports the defined rules for the default `BuilderProvider`. Otherwise, you would need to write a custom `BuilderProvider` From 12667969217db3b05a56c4bdcd5967a2996793f0 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 3 Nov 2018 08:57:42 +0000 Subject: [PATCH 0301/1006] #1504 adding position hints for ambiguous mapping methods (#1639) --- .../ap/internal/processor/creation/MappingResolverImpl.java | 5 ++--- .../mapstruct/ap/test/selection/qualifier/QualifierTest.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index c96dd6c6f5..fa0128a020 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -198,7 +198,6 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { if ( sourceType.isLiteral() && "java.lang.String".equals( sourceType.getFullyQualifiedName( ) ) && targetType.isNative() ) { - // TODO: convey some error message return null; } @@ -273,8 +272,6 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy return null; } - - /** * Returns a reference to a method mapping the given source type to the given target type, if such a method * exists. @@ -485,6 +482,7 @@ private SelectedMethod getBestMatch(List methods, Type if ( sourceRHS.getSourceErrorMessagePart() != null ) { messager.printMessage( mappingMethod.getExecutable(), + positionHint, Message.GENERAL_AMBIGIOUS_MAPPING_METHOD, sourceRHS.getSourceErrorMessagePart(), returnType, @@ -493,6 +491,7 @@ private SelectedMethod getBestMatch(List methods, Type } else { messager.printMessage( mappingMethod.getExecutable(), + positionHint, Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, returnType, Strings.join( candidates, ", " ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 570922b6cc..6d20d1a45b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -100,7 +100,7 @@ public void shouldMatchClassAndMethod() { diagnostics = { @Diagnostic( type = ErroneousMapper.class, kind = Kind.ERROR, - line = 29, + line = 28, messageRegExp = "Ambiguous mapping methods found for mapping property " + "\"java.lang.String title\" to java.lang.String.*" ) } From 3ff4ebd60a82ab5b969befe25df945629153114b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 3 Nov 2018 11:36:33 +0100 Subject: [PATCH 0302/1006] #1640 Add init method with MapStructProcessingEnvironment to the BuilderProvider for initializing the Elements and Types --- .../ap/internal/model/common/TypeFactory.java | 2 +- .../util/AnnotationProcessorContext.java | 1 + .../org/mapstruct/ap/spi/BuilderProvider.java | 16 ++++-- .../ap/spi/DefaultBuilderProvider.java | 56 +++++++++---------- .../ap/spi/ImmutablesBuilderProvider.java | 26 ++++----- .../mapstruct/ap/spi/NoOpBuilderProvider.java | 4 +- .../bugs/_1596/Issue1569BuilderProvider.java | 14 ++--- 7 files changed, 57 insertions(+), 62 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 981bd19577..6f46f073e0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -522,7 +522,7 @@ private BuilderInfo findBuilder(TypeMirror type) { try { return roundContext.getAnnotationProcessorContext() .getBuilderProvider() - .findBuilderInfo( type, elementUtils, typeUtils ); + .findBuilderInfo( type ); } catch ( MoreThanOneBuilderCreationMethodException ex ) { messager.printMessage( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index d46ca6f02f..ed70cd9f9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -76,6 +76,7 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); this.accessorNamingStrategy.init( this ); this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); + this.builderProvider.init( this ); this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); this.initialized = true; } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index 6140d7a3aa..c755c63f2f 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -6,8 +6,6 @@ package org.mapstruct.ap.spi; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; /** * A service provider interface that is used to detect types that require a builder for mapping. This interface could @@ -16,13 +14,19 @@ */ public interface BuilderProvider { + /** + * Initializes the builder provider with the MapStruct processing environment. + * + * @param processingEnvironment environment for facilities + */ + default void init(MapStructProcessingEnvironment processingEnvironment) { + + } + /** * Find the builder information, if any, for the {@code type}. * * @param type the type for which a builder should be found - * @param elements the util elements that can be used for operations on program elements - * @param types the util types that can be used for operations on {@link TypeMirror}(s) - * * @return the builder info for the {@code type} if it exists, or {@code null} if there is no builder * * @throws TypeHierarchyErroneousException if the type that needs to be visited is not ready yet, this signals the @@ -30,5 +34,5 @@ public interface BuilderProvider { * @throws MoreThanOneBuilderCreationMethodException if {@code type} has more than one method that can create the * builder */ - BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types); + BuilderInfo findBuilderInfo(TypeMirror type); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 23e6db3505..9921ad2f05 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -77,14 +77,23 @@ public class DefaultBuilderProvider implements BuilderProvider { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + protected Elements elementUtils; + protected Types typeUtils; + + @Override + public void init(MapStructProcessingEnvironment processingEnvironment) { + this.elementUtils = processingEnvironment.getElementUtils(); + this.typeUtils = processingEnvironment.getTypeUtils(); + } + @Override - public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types) { + public BuilderInfo findBuilderInfo(TypeMirror type) { TypeElement typeElement = getTypeElement( type ); if ( typeElement == null ) { return null; } - return findBuilderInfo( typeElement, elements, types ); + return findBuilderInfo( typeElement ); } /** @@ -130,8 +139,8 @@ public TypeElement visitType(TypeElement e, Void p) { * Find the {@link BuilderInfo} for the given {@code typeElement}. *

      * The default implementation iterates over all the methods in {@code typeElement} and uses - * {@link DefaultBuilderProvider#isPossibleBuilderCreationMethod(ExecutableElement, TypeElement, Types)} and - * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement, Types)} to create the + * {@link DefaultBuilderProvider#isPossibleBuilderCreationMethod(ExecutableElement, TypeElement)} and + * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement)} to create the * {@link BuilderInfo}. *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the @@ -141,14 +150,11 @@ public TypeElement visitType(TypeElement e, Void p) { * thrown. * * @param typeElement the type element for which a builder searched - * @param elements the util elements that can be used for operating on the type element - * @param types the util types that can be used for operation on {@link TypeMirror}(s) - * * @return the {@link BuilderInfo} or {@code null} if no builder was found for the type - * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement, Types)} + * {@link DefaultBuilderProvider#findBuildMethods(TypeElement, TypeElement)} * @throws MoreThanOneBuilderCreationMethodException if there are multiple builder creation methods */ - protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + protected BuilderInfo findBuilderInfo(TypeElement typeElement) { if ( shouldIgnore( typeElement ) ) { return null; } @@ -156,9 +162,9 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); List builderInfo = new ArrayList<>(); for ( ExecutableElement method : methods ) { - if ( isPossibleBuilderCreationMethod( method, typeElement, types ) ) { + if ( isPossibleBuilderCreationMethod( method, typeElement ) ) { TypeElement builderElement = getTypeElement( method.getReturnType() ); - Collection buildMethods = findBuildMethods( builderElement, typeElement, types ); + Collection buildMethods = findBuildMethods( builderElement, typeElement ); if ( !buildMethods.isEmpty() ) { builderInfo.add( new BuilderInfo.Builder() .builderCreationMethod( method ) @@ -176,7 +182,7 @@ else if ( builderInfo.size() > 1 ) { throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), builderInfo ); } - return findBuilderInfo( typeElement.getSuperclass(), elements, types ); + return findBuilderInfo( typeElement.getSuperclass() ); } /** @@ -192,39 +198,34 @@ else if ( builderInfo.size() > 1 ) { * * @param method The method that needs to be checked * @param typeElement the enclosing element of the method, i.e. the type in which the method is located in - * @param types the util types that can be used for operations on {@link TypeMirror}(s) - * * @return {@code true} if the {@code method} is a possible builder creation method, {@code false} otherwise */ - protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, TypeElement typeElement, Types types) { + protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, TypeElement typeElement) { return method.getParameters().isEmpty() && method.getModifiers().contains( Modifier.PUBLIC ) && method.getModifiers().contains( Modifier.STATIC ) - && !types.isSameType( method.getReturnType(), typeElement.asType() ); + && !typeUtils.isSameType( method.getReturnType(), typeElement.asType() ); } /** * Searches for a build method for {@code typeElement} within the {@code builderElement}. *

      * The default implementation iterates over each method in {@code builderElement} and uses - * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement, Types)} to check if the method is a + * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement)} to check if the method is a * build method for {@code typeElement}. *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the * {@code builderElement} should be ignored, i.e. not checked for build elements. *

      * If there are multiple methods that satisfy - * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement, Types)} and one of those methods + * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement)} and one of those methods * is names {@code build} that that method would be considered as a build method. * @param builderElement the element for the builder * @param typeElement the element for the type that is being built - * @param types the util types tat can be used for operations on {@link TypeMirror}(s) - * * @return the build method for the {@code typeElement} if it exists, or {@code null} if it does not * {@code build} */ - protected Collection findBuildMethods(TypeElement builderElement, TypeElement typeElement, - Types types) { + protected Collection findBuildMethods(TypeElement builderElement, TypeElement typeElement) { if ( shouldIgnore( builderElement ) ) { return Collections.emptyList(); } @@ -232,7 +233,7 @@ protected Collection findBuildMethods(TypeElement builderElem List builderMethods = ElementFilter.methodsIn( builderElement.getEnclosedElements() ); List buildMethods = new ArrayList<>(); for ( ExecutableElement buildMethod : builderMethods ) { - if ( isBuildMethod( buildMethod, typeElement, types ) ) { + if ( isBuildMethod( buildMethod, typeElement ) ) { buildMethods.add( buildMethod ); } } @@ -240,8 +241,7 @@ protected Collection findBuildMethods(TypeElement builderElem if ( buildMethods.isEmpty() ) { return findBuildMethods( getTypeElement( builderElement.getSuperclass() ), - typeElement, - types + typeElement ); } @@ -260,15 +260,13 @@ protected Collection findBuildMethods(TypeElement builderElem * * @param buildMethod the method that should be checked * @param typeElement the type element that needs to be built - * @param types the util types that can be used for operations on {@link TypeMirror}(s) - * * @return {@code true} if the {@code buildMethod} is a build method for {@code typeElement}, {@code false} * otherwise */ - protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement, Types types) { + protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement) { return buildMethod.getParameters().isEmpty() && buildMethod.getModifiers().contains( Modifier.PUBLIC ) - && types.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); + && typeUtils.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index 531b92f57a..0da8b03161 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -12,8 +12,6 @@ import javax.lang.model.element.Name; import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; /** * Builder provider for Immutables. A custom provider is needed because Immutables creates an implementation of an @@ -29,34 +27,32 @@ public class ImmutablesBuilderProvider extends DefaultBuilderProvider { private static final String IMMUTABLE_FQN = "org.immutables.value.Value.Immutable"; @Override - protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + protected BuilderInfo findBuilderInfo(TypeElement typeElement) { Name name = typeElement.getQualifiedName(); if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { return null; } - TypeElement immutableAnnotation = elements.getTypeElement( IMMUTABLE_FQN ); + TypeElement immutableAnnotation = elementUtils.getTypeElement( IMMUTABLE_FQN ); if ( immutableAnnotation != null ) { BuilderInfo info = findBuilderInfoForImmutables( typeElement, - immutableAnnotation, - elements, - types + immutableAnnotation ); if ( info != null ) { return info; } } - return super.findBuilderInfo( typeElement, elements, types ); + return super.findBuilderInfo( typeElement ); } protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, - TypeElement immutableAnnotation, Elements elements, Types types) { - for ( AnnotationMirror annotationMirror : elements.getAllAnnotationMirrors( typeElement ) ) { - if ( types.isSameType( annotationMirror.getAnnotationType(), immutableAnnotation.asType() ) ) { - TypeElement immutableElement = asImmutableElement( typeElement, elements ); + TypeElement immutableAnnotation) { + for ( AnnotationMirror annotationMirror : elementUtils.getAllAnnotationMirrors( typeElement ) ) { + if ( typeUtils.isSameType( annotationMirror.getAnnotationType(), immutableAnnotation.asType() ) ) { + TypeElement immutableElement = asImmutableElement( typeElement ); if ( immutableElement != null ) { - return super.findBuilderInfo( immutableElement, elements, types ); + return super.findBuilderInfo( immutableElement ); } else { // Immutables processor has not run yet. Trigger a postpone to the next round for MapStruct @@ -67,7 +63,7 @@ protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, return null; } - protected TypeElement asImmutableElement(TypeElement typeElement, Elements elements) { + protected TypeElement asImmutableElement(TypeElement typeElement) { Element enclosingElement = typeElement.getEnclosingElement(); StringBuilder builderQualifiedName = new StringBuilder( typeElement.getQualifiedName().length() + 17 ); if ( enclosingElement.getKind() == ElementKind.PACKAGE ) { @@ -82,6 +78,6 @@ protected TypeElement asImmutableElement(TypeElement typeElement, Elements eleme } builderQualifiedName.append( "Immutable" ).append( typeElement.getSimpleName() ); - return elements.getTypeElement( builderQualifiedName ); + return elementUtils.getTypeElement( builderQualifiedName ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java index e38e86d916..fae086ab18 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java @@ -8,8 +8,6 @@ // tag::documentation[] import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; // end::documentation[] @@ -22,7 +20,7 @@ public class NoOpBuilderProvider implements BuilderProvider { @Override - public BuilderInfo findBuilderInfo(TypeMirror type, Elements elements, Types types) { + public BuilderInfo findBuilderInfo(TypeMirror type) { return null; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java index c3df534431..92676f9ae0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1569BuilderProvider.java @@ -7,8 +7,6 @@ import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; import org.mapstruct.ap.spi.BuilderInfo; import org.mapstruct.ap.spi.BuilderProvider; @@ -17,22 +15,22 @@ public class Issue1569BuilderProvider extends ImmutablesBuilderProvider implements BuilderProvider { @Override - protected BuilderInfo findBuilderInfo(TypeElement typeElement, Elements elements, Types types) { + protected BuilderInfo findBuilderInfo(TypeElement typeElement) { Name name = typeElement.getQualifiedName(); if ( name.toString().endsWith( ".Item" ) ) { - BuilderInfo info = findBuilderInfoForImmutables( typeElement, elements, types ); + BuilderInfo info = findBuilderInfoForImmutables( typeElement ); if ( info != null ) { return info; } } - return super.findBuilderInfo( typeElement, elements, types ); + return super.findBuilderInfo( typeElement ); } - protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, Elements elements, Types types) { - TypeElement immutableElement = asImmutableElement( typeElement, elements ); + protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement) { + TypeElement immutableElement = asImmutableElement( typeElement ); if ( immutableElement != null ) { - return super.findBuilderInfo( immutableElement, elements, types ); + return super.findBuilderInfo( immutableElement ); } return null; } From cf668bea77d5d48f34d32c229823a04dbd01f21d Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 6 Nov 2018 07:36:09 +0000 Subject: [PATCH 0303/1006] #1576 Delay determining whether a Type needs to be imported & java.time cleanup (#1642) --- parent/pom.xml | 2 +- .../org/mapstruct/ap/MappingProcessor.java | 17 +++- .../AbstractJavaTimeToStringConversion.java | 8 +- .../internal/conversion/ConversionUtils.java | 20 ++-- .../ap/internal/conversion/Conversions.java | 31 +++--- .../conversion/EnumStringConversion.java | 2 +- .../JavaLocalDateTimeToDateConversion.java | 12 +-- .../JavaLocalDateToDateConversion.java | 10 +- .../JavaLocalDateToSqlDateConversion.java | 6 +- .../JavaZonedDateTimeToDateConversion.java | 8 +- .../JodaDateTimeToCalendarConversion.java | 2 +- .../conversion/JodaTimeToDateConversion.java | 2 +- .../ap/internal/model/GeneratedType.java | 2 +- .../common/DateFormatValidatorFactory.java | 14 ++- .../ap/internal/model/common/Type.java | 94 ++++++++++++++++--- .../ap/internal/model/common/TypeFactory.java | 66 +++---------- .../source/builtin/BuiltInMappingMethods.java | 20 ++-- .../builtin/CalendarToZonedDateTime.java | 3 +- .../builtin/ZonedDateTimeToCalendar.java | 3 +- .../DefaultModelElementProcessorContext.java | 6 +- .../ap/internal/util/JavaTimeConstants.java | 27 ------ .../ap/internal/model/common/Type.ftl | 2 +- .../DateFormatValidatorFactoryTest.java | 16 +++- .../common/DefaultConversionContextTest.java | 9 +- .../model/common/TypeFactoryTest.java | 50 ---------- .../bugs/_1576/java8/Issue1576Mapper.java | 17 ++++ .../test/bugs/_1576/java8/Issue1576Test.java | 32 +++++++ .../ap/test/bugs/_1576/java8/Source.java | 57 +++++++++++ .../ap/test/bugs/_1576/java8/Target.java | 61 ++++++++++++ .../bugs/_1576/java8/Issue1576MapperImpl.java | 48 ++++++++++ 30 files changed, 417 insertions(+), 230 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Target.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576MapperImpl.java diff --git a/parent/pom.xml b/parent/pom.xml index a30051d958..fdfb0dd478 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -613,7 +613,7 @@ org.codehaus.mojo.signature - java16 + java18 1.0 diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 83841db525..dc565e13b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -13,9 +13,10 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; import java.util.Set; - +import java.util.stream.Collectors; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.Processor; @@ -25,6 +26,7 @@ import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; +import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.lang.model.util.ElementKindVisitor6; import javax.tools.Diagnostic.Kind; @@ -41,6 +43,8 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; +import static javax.lang.model.element.ElementKind.CLASS; + /** * A JSR 269 annotation {@link Processor} which generates the implementations for mapper interfaces (interfaces * annotated with {@code @Mapper}). @@ -209,8 +213,9 @@ private void processMapperElements(Set mapperElements, RoundContext // note that this assumes that a new source file is created for each mapper which must not // necessarily be the case, e.g. in case of several mapper interfaces declared as inner types // of one outer interface + List tst = mapperElement.getEnclosedElements(); ProcessorContext context = new DefaultModelElementProcessorContext( - processingEnv, options, roundContext + processingEnv, options, roundContext, getDeclaredTypesNotToBeImported( mapperElement ) ); processMapperTypeElement( context, mapperElement ); @@ -225,6 +230,14 @@ private void processMapperElements(Set mapperElements, RoundContext } } + private Map getDeclaredTypesNotToBeImported(TypeElement element) { + return element.getEnclosedElements().stream() + .filter( e -> CLASS.equals( e.getKind() ) ) + .map( Element::getSimpleName ) + .map( Name::toString ) + .collect( Collectors.toMap( k -> k, v -> element.getQualifiedName().toString() + "." + v ) ); + } + private void handleUncaughtError(Element element, Throwable thrown) { StringWriter sw = new StringWriter(); thrown.printStackTrace( new PrintWriter( sw ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java index f3dfdf46db..e903c00e59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java @@ -5,12 +5,12 @@ */ package org.mapstruct.ap.internal.conversion; +import java.time.format.DateTimeFormatter; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Collections; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.Strings; /** @@ -53,7 +53,7 @@ private String dateTimeFormatter(ConversionContext conversionContext) { @Override protected String getFromExpression(ConversionContext conversionContext) { // See http://docs.oracle.com/javase/tutorial/datetime/iso/format.html for how to parse Dates - return new StringBuilder().append( conversionContext.getTargetType().getReferenceName() ) + return new StringBuilder().append( conversionContext.getTargetType().createReferenceName() ) .append( ".parse( " ) .append( parametersListForParsing( conversionContext ) ) .append( " )" ).toString(); @@ -72,7 +72,7 @@ private String parametersListForParsing(ConversionContext conversionContext) { @Override protected Set getToConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) + conversionContext.getTypeFactory().getType( DateTimeFormatter.class ) ); } @@ -81,7 +81,7 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon if ( !Strings.isEmpty( conversionContext.getDateFormat() ) ) { return Collections.asSet( conversionContext.getTargetType(), - conversionContext.getTypeFactory().getType( JavaTimeConstants.DATE_TIME_FORMATTER_FQN ) + conversionContext.getTypeFactory().getType( DateTimeFormatter.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index b2210ec106..8d2557b334 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -11,11 +11,15 @@ import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Currency; import java.util.Locale; import org.mapstruct.ap.internal.model.common.ConversionContext; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; /** @@ -37,7 +41,7 @@ private ConversionUtils() { * @return Name or fully-qualified name. */ private static String typeReferenceName(ConversionContext conversionContext, String canonicalName) { - return conversionContext.getTypeFactory().getType( canonicalName ).getReferenceName(); + return conversionContext.getTypeFactory().getType( canonicalName ).createReferenceName(); } /** @@ -49,7 +53,7 @@ private static String typeReferenceName(ConversionContext conversionContext, Str * @return Name or fully-qualified name. */ private static String typeReferenceName(ConversionContext conversionContext, Class type) { - return conversionContext.getTypeFactory().getType( type ).getReferenceName(); + return conversionContext.getTypeFactory().getType( type ).createReferenceName(); } /** @@ -170,7 +174,7 @@ public static String date(ConversionContext conversionContext) { * @return Name or fully-qualified name. */ public static String zoneOffset(ConversionContext conversionContext) { - return typeReferenceName( conversionContext, JavaTimeConstants.ZONE_OFFSET_FQN ); + return typeReferenceName( conversionContext, ZoneOffset.class ); } /** @@ -181,7 +185,7 @@ public static String zoneOffset(ConversionContext conversionContext) { * @return Name or fully-qualified name. */ public static String zoneId(ConversionContext conversionContext) { - return typeReferenceName( conversionContext, JavaTimeConstants.ZONE_ID_FQN ); + return typeReferenceName( conversionContext, ZoneId.class ); } /** @@ -192,7 +196,7 @@ public static String zoneId(ConversionContext conversionContext) { * @return Name or fully-qualified name. */ public static String localDateTime(ConversionContext conversionContext) { - return typeReferenceName( conversionContext, JavaTimeConstants.LOCAL_DATE_TIME_FQN ); + return typeReferenceName( conversionContext, LocalDateTime.class ); } /** @@ -203,7 +207,7 @@ public static String localDateTime(ConversionContext conversionContext) { * @return Name or fully-qualified name. */ public static String zonedDateTime(ConversionContext conversionContext) { - return typeReferenceName( conversionContext, JavaTimeConstants.ZONED_DATE_TIME_FQN ); + return typeReferenceName( conversionContext, ZonedDateTime.class ); } /** @@ -214,7 +218,7 @@ public static String zonedDateTime(ConversionContext conversionContext) { * @return Name or fully-qualified name. */ public static String dateTimeFormatter(ConversionContext conversionContext) { - return typeReferenceName( conversionContext, JavaTimeConstants.DATE_TIME_FORMATTER_FQN ); + return typeReferenceName( conversionContext, DateTimeFormatter.class ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 3bf9ccade8..6f4db9316f 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -9,6 +9,11 @@ import java.math.BigInteger; import java.sql.Time; import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Currency; import java.util.Date; @@ -18,7 +23,6 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; import static org.mapstruct.ap.internal.conversion.ReverseConversion.reverse; @@ -207,22 +211,19 @@ private void registerJodaConversions() { } private void registerJava8TimeConversions() { - if ( !isJava8TimeAvailable() ) { - return; - } // Java 8 time to String - register( JavaTimeConstants.ZONED_DATE_TIME_FQN, String.class, new JavaZonedDateTimeToStringConversion() ); - register( JavaTimeConstants.LOCAL_DATE_FQN, String.class, new JavaLocalDateToStringConversion() ); - register( JavaTimeConstants.LOCAL_DATE_TIME_FQN, String.class, new JavaLocalDateTimeToStringConversion() ); - register( JavaTimeConstants.LOCAL_TIME_FQN, String.class, new JavaLocalTimeToStringConversion() ); + register( ZonedDateTime.class, String.class, new JavaZonedDateTimeToStringConversion() ); + register( LocalDate.class, String.class, new JavaLocalDateToStringConversion() ); + register( LocalDateTime.class, String.class, new JavaLocalDateTimeToStringConversion() ); + register( LocalTime.class, String.class, new JavaLocalTimeToStringConversion() ); // Java 8 to Date - register( JavaTimeConstants.ZONED_DATE_TIME_FQN, Date.class, new JavaZonedDateTimeToDateConversion() ); - register( JavaTimeConstants.LOCAL_DATE_TIME_FQN, Date.class, new JavaLocalDateTimeToDateConversion() ); - register( JavaTimeConstants.LOCAL_DATE_FQN, Date.class, new JavaLocalDateToDateConversion() ); - register( JavaTimeConstants.LOCAL_DATE_FQN, java.sql.Date.class, new JavaLocalDateToSqlDateConversion() ); - register( JavaTimeConstants.INSTANT, Date.class, new JavaInstantToDateConversion() ); + register( ZonedDateTime.class, Date.class, new JavaZonedDateTimeToDateConversion() ); + register( LocalDateTime.class, Date.class, new JavaLocalDateTimeToDateConversion() ); + register( LocalDate.class, Date.class, new JavaLocalDateToDateConversion() ); + register( LocalDate.class, java.sql.Date.class, new JavaLocalDateToSqlDateConversion() ); + register( Instant.class, Date.class, new JavaInstantToDateConversion() ); } @@ -230,10 +231,6 @@ private boolean isJodaTimeAvailable() { return typeFactory.isTypeAvailable( JodaTimeConstants.DATE_TIME_FQN ); } - private boolean isJava8TimeAvailable() { - return typeFactory.isTypeAvailable( JavaTimeConstants.ZONED_DATE_TIME_FQN ); - } - private void registerNativeTypeConversion(Class sourceType, Class targetType) { if ( sourceType.isPrimitive() && targetType.isPrimitive() ) { register( sourceType, targetType, new PrimitiveToPrimitiveConversion( sourceType ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java index 7f904dbe41..d06cad93b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumStringConversion.java @@ -26,7 +26,7 @@ public String getToExpression(ConversionContext conversionContext) { @Override public String getFromExpression(ConversionContext conversionContext) { - return "Enum.valueOf( " + conversionContext.getTargetType().getReferenceName() + return "Enum.valueOf( " + conversionContext.getTargetType().createReferenceName() + ".class, )"; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java index 579e45fd9b..489fc39eb4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToDateConversion.java @@ -5,6 +5,9 @@ */ package org.mapstruct.ap.internal.conversion; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.util.Date; import java.util.Set; @@ -16,9 +19,6 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.localDateTime; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneId; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.LOCAL_DATE_TIME_FQN; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** * SimpleConversion for mapping {@link java.time.LocalDateTime} to @@ -38,7 +38,7 @@ protected String getToExpression(ConversionContext conversionContext) { protected Set getToConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( conversionContext.getTypeFactory().getType( Date.class ), - conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + conversionContext.getTypeFactory().getType( ZoneOffset.class ) ); } @@ -53,8 +53,8 @@ protected String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( LOCAL_DATE_TIME_FQN ), - conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + conversionContext.getTypeFactory().getType( LocalDateTime.class ), + conversionContext.getTypeFactory().getType( ZoneId.class ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java index 9d4f3a0c57..b28bc50785 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToDateConversion.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.internal.conversion; +import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.Date; import java.util.Set; @@ -15,8 +17,6 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; import static org.mapstruct.ap.internal.conversion.ConversionUtils.localDateTime; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.LOCAL_DATE_TIME_FQN; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** * SimpleConversion for mapping {@link java.time.LocalDate} to @@ -36,7 +36,7 @@ protected String getToExpression(ConversionContext conversionContext) { protected Set getToConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( conversionContext.getTypeFactory().getType( Date.class ), - conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + conversionContext.getTypeFactory().getType( ZoneOffset.class ) ); } @@ -51,8 +51,8 @@ protected String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( LOCAL_DATE_TIME_FQN ), - conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + conversionContext.getTypeFactory().getType( LocalDateTime.class ), + conversionContext.getTypeFactory().getType( ZoneOffset.class ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java index 29663cbcf2..cfc6ca31d3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateToSqlDateConversion.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.conversion; import java.sql.Date; +import java.time.ZoneOffset; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; @@ -14,7 +15,6 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.sqlDate; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneOffset; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_OFFSET_FQN; /** * SimpleConversion for mapping {@link java.time.LocalDate} to @@ -34,7 +34,7 @@ protected String getToExpression(ConversionContext conversionContext) { protected Set getToConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( conversionContext.getTypeFactory().getType( Date.class ), - conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + conversionContext.getTypeFactory().getType( ZoneOffset.class ) ); } @@ -46,7 +46,7 @@ protected String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( ZONE_OFFSET_FQN ) + conversionContext.getTypeFactory().getType( ZoneOffset.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java index fb2f7f4026..cc88d72e4e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaZonedDateTimeToDateConversion.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.internal.conversion; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.Date; import java.util.Set; @@ -15,8 +17,6 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.date; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zoneId; import static org.mapstruct.ap.internal.conversion.ConversionUtils.zonedDateTime; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONED_DATE_TIME_FQN; -import static org.mapstruct.ap.internal.util.JavaTimeConstants.ZONE_ID_FQN; /** * SimpleConversion for mapping {@link java.time.ZonedDateTime} to @@ -48,8 +48,8 @@ protected String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { return Collections.asSet( - conversionContext.getTypeFactory().getType( ZONED_DATE_TIME_FQN ), - conversionContext.getTypeFactory().getType( ZONE_ID_FQN ) + conversionContext.getTypeFactory().getType( ZonedDateTime.class ), + conversionContext.getTypeFactory().getType( ZoneId.class ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java index f32f6e369c..f9c70ff8ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaDateTimeToCalendarConversion.java @@ -34,7 +34,7 @@ protected Set getToConversionImportTypes(ConversionContext conversionConte @Override protected String getFromExpression(ConversionContext conversionContext) { - return "new " + conversionContext.getTargetType().getReferenceName() + "( )"; + return "new " + conversionContext.getTargetType().createReferenceName() + "( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java index fecd079e3b..0e47085bc8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JodaTimeToDateConversion.java @@ -32,7 +32,7 @@ protected String getToExpression(ConversionContext conversionContext) { @Override protected String getFromExpression(ConversionContext conversionContext) { - return "new " + conversionContext.getTargetType().getReferenceName() + "( )"; + return "new " + conversionContext.getTargetType().createReferenceName() + "( )"; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 92f10c5293..de16a5ce07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -224,7 +224,7 @@ protected void addIfImportRequired(Collection collection, Type typeToAdd) } private boolean needsImportDeclaration(Type typeToAdd) { - if ( !typeToAdd.isImported() ) { + if ( !typeToAdd.isToBeImported() ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index 774d186261..8e8c328f20 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -8,8 +8,11 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.XmlConstants; @@ -89,10 +92,11 @@ private static boolean isJava8DateTimeSupposed(Type sourceType, Type targetType) return typesEqualsOneOf( sourceType, targetType, - JavaTimeConstants.LOCAL_DATE_FQN, - JavaTimeConstants.LOCAL_TIME_FQN, - JavaTimeConstants.LOCAL_DATE_TIME_FQN, - JavaTimeConstants.ZONED_DATE_TIME_FQN ); + LocalDate.class.getCanonicalName(), + LocalTime.class.getCanonicalName(), + LocalDateTime.class.getCanonicalName(), + ZonedDateTime.class.getCanonicalName() + ); } private static boolean isJavaUtilDateSupposed(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 60852b49b4..7fa56b5640 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -77,13 +77,16 @@ public class Type extends ModelElement implements Comparable { private final boolean isIterableType; private final boolean isCollectionType; private final boolean isMapType; - private final boolean isImported; private final boolean isVoid; private final boolean isStream; private final boolean isLiteral; private final List enumConstants; + private final Map toBeImportedTypes; + private final Map notToBeImportedTypes; + private Boolean isToBeImported; + private Map readAccessors = null; private Map presenceCheckers = null; @@ -104,7 +107,10 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, BuilderInfo builderInfo, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, - boolean isCollectionType, boolean isMapType, boolean isStreamType, boolean isImported, + boolean isCollectionType, boolean isMapType, boolean isStreamType, + Map toBeImportedTypes, + Map notToBeImportedTypes, + Boolean isToBeImported, boolean isLiteral ) { this.typeUtils = typeUtils; @@ -128,7 +134,6 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.isCollectionType = isCollectionType; this.isMapType = isMapType; this.isStream = isStreamType; - this.isImported = isImported; this.isVoid = typeMirror.getKind() == TypeKind.VOID; this.isLiteral = isLiteral; @@ -148,6 +153,9 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, enumConstants = Collections.emptyList(); } + this.isToBeImported = isToBeImported; + this.toBeImportedTypes = toBeImportedTypes; + this.notToBeImportedTypes = notToBeImportedTypes; this.builderType = BuilderType.create( builderInfo, this, this.typeFactory, this.typeUtils ); } //CHECKSTYLE:ON @@ -169,12 +177,18 @@ public String getName() { } /** - * String that could be used in generated code to reference to this {@link Type}. + * Returns a String that could be used in generated code to reference to this {@link Type}.
      + *

      + * The first time a name is referred-to it will be marked as to be imported. For instance + * {@code LocalDateTime} can be one of {@code java.time.LocalDateTime} and {@code org.joda.LocalDateTime}) + *

      + * If the {@code java.time} variant is referred to first, the {@code java.time.LocalDateTime} will be imported + * and the {@code org.joda} variant will be referred to with its FQN. * * @return Just the name if this {@link Type} will be imported, otherwise the fully-qualified name. */ - public String getReferenceName() { - return isImported ? name : qualifiedName; + public String createReferenceName() { + return isToBeImported() ? name : ( shouldUseSimpleName() ? name : qualifiedName ); } public List getTypeParameters() { @@ -314,7 +328,7 @@ public String getFullyQualifiedName() { * @return The name of this type as to be used within import statements. */ public String getImportName() { - return isArrayType() ? TypeFactory.trimSimpleClassName( qualifiedName ) : qualifiedName; + return isArrayType() ? trimSimpleClassName( qualifiedName ) : qualifiedName; } @Override @@ -341,14 +355,38 @@ public Set getImportTypes() { } /** - * Whether this type is imported by means of an import statement in the currently generated source file (meaning it - * can be referenced in the generated source using its simple name) or not (meaning it has to be referenced using - * the fully-qualified name). + * Whether this type is to be imported by means of an import statement in the currently generated source file + * (it can be referenced in the generated source using its simple name) or not (referenced using the FQN). * * @return {@code true} if the type is imported, {@code false} otherwise. */ - public boolean isImported() { - return isImported; + public boolean isToBeImported() { + if ( isToBeImported == null ) { + String trimmedName = trimSimpleClassName( name ); + if ( notToBeImportedTypes.containsKey( trimmedName ) ) { + isToBeImported = false; + return isToBeImported; + } + String trimmedQualifiedName = trimSimpleClassName( qualifiedName ); + String importedType = toBeImportedTypes.get( trimmedName ); + + isToBeImported = false; + if ( importedType != null ) { + if ( importedType.equals( trimmedQualifiedName ) ) { + isToBeImported = true; + } + } + else { + toBeImportedTypes.put( trimmedName, trimmedQualifiedName ); + isToBeImported = true; + } + } + return isToBeImported; + } + + private boolean shouldUseSimpleName() { + String fqn = notToBeImportedTypes.get( name ); + return this.qualifiedName.equals( fqn ); } /** @@ -390,7 +428,9 @@ public Type erasure() { isCollectionType, isMapType, isStream, - isImported, + toBeImportedTypes, + notToBeImportedTypes, + isToBeImported, isLiteral ); } @@ -431,7 +471,9 @@ public Type withoutBounds() { isCollectionType, isMapType, isStream, - isImported, + toBeImportedTypes, + notToBeImportedTypes, + isToBeImported, isLiteral ); } @@ -1004,4 +1046,28 @@ public boolean isLiteral() { return isLiteral; } + /** + * It strips all the {@code []} from the {@code className}. + * + * E.g. + *

      +     *     trimSimpleClassName("String[][][]") -> "String"
      +     *     trimSimpleClassName("String[]") -> "String"
      +     * 
      + * + * @param className that needs to be trimmed + * + * @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null} + */ + private String trimSimpleClassName(String className) { + if ( className == null ) { + return null; + } + String trimmedClassName = className; + while ( trimmedClassName.endsWith( "[]" ) ) { + trimmedClassName = trimmedClassName.substring( 0, trimmedClassName.length() - 2 ); + } + return trimmedClassName; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 6f46f073e0..567053986e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -84,13 +84,16 @@ public String apply(BuilderInfo builderInfo) { private final TypeMirror streamType; private final Map implementationTypes = new HashMap<>(); - private final Map importedQualifiedTypesBySimpleName = new HashMap<>(); + private final Map toBeImportedTypes = new HashMap<>(); + private final Map notToBeImportedTypes; - public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext) { + public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext, + Map notToBeImportedTypes) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; this.roundContext = roundContext; + this.notToBeImportedTypes = notToBeImportedTypes; iterableType = typeUtils.erasure( elementUtils.getTypeElement( Iterable.class.getCanonicalName() ).asType() ); collectionType = @@ -197,7 +200,7 @@ private Type getType(TypeMirror mirror, boolean isLiteral) { String qualifiedName; TypeElement typeElement; Type componentType; - boolean isImported; + Boolean toBeImported = null; if ( mirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) mirror; @@ -218,7 +221,6 @@ private Type getType(TypeMirror mirror, boolean isLiteral) { } componentType = null; - isImported = isImported( name, qualifiedName ); } else if ( mirror.getKind() == TypeKind.ARRAY ) { TypeMirror componentTypeMirror = getComponentType( mirror ); @@ -237,7 +239,6 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { name = componentTypeElement.getSimpleName().toString() + arraySuffix; packageName = elementUtils.getPackageOf( componentTypeElement ).getQualifiedName().toString(); qualifiedName = componentTypeElement.getQualifiedName().toString() + arraySuffix; - isImported = isImported( name, qualifiedName ); } else if (componentTypeMirror.getKind().isPrimitive()) { // When the component type is primitive and is annotated with ElementType.TYPE_USE then @@ -246,13 +247,13 @@ else if (componentTypeMirror.getKind().isPrimitive()) { packageName = null; // for primitive types only name (e.g. byte, short..) required as qualified name qualifiedName = name; - isImported = false; + toBeImported = false; } else { name = mirror.toString(); packageName = null; qualifiedName = name; - isImported = false; + toBeImported = false; } isEnumType = false; @@ -268,7 +269,7 @@ else if (componentTypeMirror.getKind().isPrimitive()) { qualifiedName = name; typeElement = null; componentType = null; - isImported = false; + toBeImported = false; } return new Type( @@ -289,7 +290,9 @@ else if (componentTypeMirror.getKind().isPrimitive()) { isCollectionType, isMapType, isStreamType, - isImported, + toBeImportedTypes, + notToBeImportedTypes, + toBeImported, isLiteral ); } @@ -509,7 +512,9 @@ private ImplementationType getImplementationType(TypeMirror mirror) { implementationType.isCollectionType(), implementationType.isMapType(), implementationType.isStreamType(), - isImported( implementationType.getName(), implementationType.getFullyQualifiedName() ), + toBeImportedTypes, + notToBeImportedTypes, + null, implementationType.isLiteral() ); return implementation.createNew( replacement ); @@ -545,24 +550,6 @@ private TypeMirror getComponentType(TypeMirror mirror) { return arrayType.getComponentType(); } - private boolean isImported(String name, String qualifiedName) { - String trimmedName = TypeFactory.trimSimpleClassName( name ); - String trimmedQualifiedName = TypeFactory.trimSimpleClassName( qualifiedName ); - String importedType = importedQualifiedTypesBySimpleName.get( trimmedName ); - - boolean imported = false; - if ( importedType != null ) { - if ( importedType.equals( trimmedQualifiedName ) ) { - imported = true; - } - } - else { - importedQualifiedTypesBySimpleName.put( trimmedName, trimmedQualifiedName ); - imported = true; - } - return imported; - } - /** * Converts any collection type, e.g. {@code List} to {@code Collection} and any map type, e.g. * {@code HashMap} to {@code Map}. @@ -643,29 +630,6 @@ else if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { return typeMirror; } - /** - * It strips the all the {@code []} from the {@code className}. - * - * E.g. - *
      -     *     trimSimpleClassName("String[][][]") -> "String"
      -     *     trimSimpleClassName("String[]") -> "String"
      -     * 
      - * - * @param className that needs to be trimmed - * - * @return the trimmed {@code className}, or {@code null} if the {@code className} was {@code null} - */ - static String trimSimpleClassName(String className) { - if ( className == null ) { - return null; - } - String trimmedClassName = className; - while ( trimmedClassName.endsWith( "[]" ) ) { - trimmedClassName = trimmedClassName.substring( 0, trimmedClassName.length() - 2 ); - } - return trimmedClassName; - } /** * Whether the given type is ready to be processed or not. It can be processed if it is not of kind diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 908b8284f5..5332651ab0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -9,7 +9,6 @@ import java.util.List; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JaxbConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.internal.util.XmlConstants; @@ -33,21 +32,18 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { builtInMethods.add( new XmlGregorianCalendarToString( typeFactory ) ); builtInMethods.add( new CalendarToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new XmlGregorianCalendarToCalendar( typeFactory ) ); + builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) ); } if ( isJaxbAvailable( typeFactory ) ) { builtInMethods.add( new JaxbElemToValue( typeFactory ) ); } - - if ( isJava8TimeAvailable( typeFactory ) ) { - builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); - builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) ); - builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) ); - if ( isXmlGregorianCalendarPresent ) { - builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); - builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); - } + builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); + builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) ); + if ( isXmlGregorianCalendarPresent ) { + builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); + builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); } if ( isJodaTimeAvailable( typeFactory ) && isXmlGregorianCalendarPresent ) { @@ -66,10 +62,6 @@ private static boolean isJaxbAvailable(TypeFactory typeFactory) { return JaxbConstants.isJaxbElementPresent() && typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); } - private static boolean isJava8TimeAvailable(TypeFactory typeFactory) { - return typeFactory.isTypeAvailable( JavaTimeConstants.ZONED_DATE_TIME_FQN ); - } - private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) { return XmlConstants.isXmlGregorianCalendarPresent() && typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java index 478f03ee4b..729b65e5e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToZonedDateTime.java @@ -12,7 +12,6 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +27,7 @@ public class CalendarToZonedDateTime extends BuiltInMethod { private final Set importedTypes; CalendarToZonedDateTime(TypeFactory typeFactory) { - this.returnType = typeFactory.getType( JavaTimeConstants.ZONED_DATE_TIME_FQN ); + this.returnType = typeFactory.getType( ZonedDateTime.class ); this.parameter = new Parameter( "cal", typeFactory.getType( Calendar.class ) ); this.importedTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java index 7e7a0751d6..5a6c447908 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToCalendar.java @@ -13,7 +13,6 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -29,7 +28,7 @@ public class ZonedDateTimeToCalendar extends BuiltInMethod { ZonedDateTimeToCalendar(TypeFactory typeFactory) { this.returnType = typeFactory.getType( Calendar.class ); - this.parameter = new Parameter( "dateTime", typeFactory.getType( JavaTimeConstants.ZONED_DATE_TIME_FQN ) ); + this.parameter = new Parameter( "dateTime", typeFactory.getType( ZonedDateTime.class ) ); this.importedTypes = asSet( returnType, parameter.getType(), typeFactory.getType( TimeZone.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index b178861dd4..5168dccc1b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.processor; +import java.util.Map; import javax.annotation.processing.Filer; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; @@ -41,7 +42,7 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final AccessorNamingUtils accessorNaming; public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options, - RoundContext roundContext) { + RoundContext roundContext, Map notToBeImported) { this.processingEnvironment = processingEnvironment; this.messager = new DelegatingMessager( processingEnvironment.getMessager() ); @@ -52,7 +53,8 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir processingEnvironment.getElementUtils(), delegatingTypes, messager, - roundContext + roundContext, + notToBeImported ); this.options = options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java deleted file mode 100644 index 60053064b0..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaTimeConstants.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util; - -/** - * Helper holding Java time full qualified class names for conversion registration - */ -public final class JavaTimeConstants { - - public static final String ZONED_DATE_TIME_FQN = "java.time.ZonedDateTime"; - public static final String ZONE_OFFSET_FQN = "java.time.ZoneOffset"; - public static final String ZONE_ID_FQN = "java.time.ZoneId"; - - public static final String LOCAL_DATE_TIME_FQN = "java.time.LocalDateTime"; - public static final String LOCAL_DATE_FQN = "java.time.LocalDate"; - public static final String LOCAL_TIME_FQN = "java.time.LocalTime"; - - public static final String DATE_TIME_FORMATTER_FQN = "java.time.format.DateTimeFormatter"; - - public static final String INSTANT = "java.time.Instant"; - - private JavaTimeConstants() { - } -} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index d6b2d6850c..89b2279a6d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -12,6 +12,6 @@ <#elseif wildCardSuperBound> ? super <@includeModel object=typeBound /> <#else> - <#if ext.asVarArgs!false>${referenceName?remove_ending("[]")}...<#else>${referenceName}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > + <#if ext.asVarArgs!false>${createReferenceName()?remove_ending("[]")}...<#else>${createReferenceName()}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 68fee3bc85..064aabfd85 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -8,6 +8,11 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.annotation.Annotation; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; +import java.util.HashMap; import java.util.List; import javax.lang.model.element.AnnotationMirror; @@ -16,7 +21,6 @@ import javax.lang.model.type.TypeVisitor; import org.junit.Test; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.testutil.IssueKey; @@ -113,25 +117,25 @@ public void testJavaTimeValidator() { Type targetType = typeWithFQN( JAVA_LANG_STRING ); - Type sourceType = typeWithFQN( JavaTimeConstants.ZONED_DATE_TIME_FQN ); + Type sourceType = typeWithFQN( ZonedDateTime.class.getCanonicalName() ); assertInvalidDateFormat( sourceType, targetType ); assertInvalidDateFormat( targetType, sourceType ); assertValidDateFormat( sourceType, targetType ); assertValidDateFormat( targetType, sourceType ); - sourceType = typeWithFQN( JavaTimeConstants.LOCAL_DATE_FQN ); + sourceType = typeWithFQN( LocalDate.class.getCanonicalName() ); assertInvalidDateFormat( sourceType, targetType ); assertInvalidDateFormat( targetType, sourceType ); assertValidDateFormat( sourceType, targetType ); assertValidDateFormat( targetType, sourceType ); - sourceType = typeWithFQN( JavaTimeConstants.LOCAL_DATE_TIME_FQN ); + sourceType = typeWithFQN( LocalDateTime.class.getCanonicalName() ); assertInvalidDateFormat( sourceType, targetType ); assertInvalidDateFormat( targetType, sourceType ); assertValidDateFormat( sourceType, targetType ); assertValidDateFormat( targetType, sourceType ); - sourceType = typeWithFQN( JavaTimeConstants.LOCAL_TIME_FQN ); + sourceType = typeWithFQN( LocalTime.class.getCanonicalName() ); assertInvalidDateFormat( sourceType, targetType ); assertInvalidDateFormat( targetType, sourceType ); assertValidDateFormat( sourceType, targetType ); @@ -171,6 +175,8 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + new HashMap<>( ), + new HashMap<>( ), false, false); } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 40f7357e94..6b40de3133 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -8,6 +8,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.annotation.Annotation; +import java.time.ZonedDateTime; +import java.util.HashMap; import java.util.List; import javax.lang.model.element.AnnotationMirror; @@ -20,7 +22,6 @@ import org.junit.Test; import org.mapstruct.ap.internal.util.FormattingMessager; -import org.mapstruct.ap.internal.util.JavaTimeConstants; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.testutil.IssueKey; @@ -62,7 +63,7 @@ public R accept(TypeVisitor v, P p) { @Test public void testInvalidDateFormatValidation() { - Type type = typeWithFQN( JavaTimeConstants.ZONED_DATE_TIME_FQN ); + Type type = typeWithFQN( ZonedDateTime.class.getCanonicalName() ); StatefulMessagerMock statefulMessagerMock = new StatefulMessagerMock(); new DefaultConversionContext( null, @@ -76,7 +77,7 @@ public void testInvalidDateFormatValidation() { @Test public void testNullDateFormatValidation() { - Type type = typeWithFQN( JavaTimeConstants.ZONED_DATE_TIME_FQN ); + Type type = typeWithFQN( ZonedDateTime.class.getCanonicalName() ); StatefulMessagerMock statefulMessagerMock = new StatefulMessagerMock(); new DefaultConversionContext( null, @@ -122,6 +123,8 @@ private Type typeWithFQN(String fullQualifiedName) { false, false, false, + new HashMap<>( ), + new HashMap<>( ), false, false); } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java deleted file mode 100644 index 7b6fd64109..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/TypeFactoryTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.model.common; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; - -public class TypeFactoryTest { - - @Test - public void shouldReturnNullIfNoClassNameIsProvided() { - String result = TypeFactory.trimSimpleClassName( null ); - - assertThat( result ).isNull(); - } - - @Test - public void shouldNotModifyClassNameIfNotAnArray() { - String className = "SimpleClass"; - - String result = TypeFactory.trimSimpleClassName( className ); - - assertThat( result ).isEqualTo( className ); - } - - @Test - public void shouldTrimOneDimensionalArray() { - String result = TypeFactory.trimSimpleClassName( "SimpleClass[]" ); - - assertThat( result ).isEqualTo( "SimpleClass" ); - } - - @Test - public void shouldTrimTwoDimensionalArray() { - String result = TypeFactory.trimSimpleClassName( "SimpleClass[][]" ); - - assertThat( result ).isEqualTo( "SimpleClass" ); - } - - @Test - public void shouldTrimMultiDimensionalArray() { - String result = TypeFactory.trimSimpleClassName( "SimpleClass[][][][][]" ); - - assertThat( result ).isEqualTo( "SimpleClass" ); - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Mapper.java new file mode 100644 index 0000000000..a1c5a82a3b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Mapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1576.java8; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue1576Mapper { + + Issue1576Mapper INSTANCE = Mappers.getMapper( Issue1576Mapper.class ); + + Target map( Source source ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java new file mode 100644 index 0000000000..4b367a15a9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1576.java8; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +@IssueKey("1576") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses( { Issue1576Mapper.class, Source.class, Target.class }) +public class Issue1576Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + Issue1576Mapper.class + ); + + @Test + public void testLocalDateTimeIsImported() { + + Issue1576Mapper.INSTANCE.map( new Source() ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Source.java new file mode 100644 index 0000000000..c23bb0359f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Source.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1576.java8; + +import java.util.Date; + +public class Source { + + private Date localDateTime; + private Date localDate; + private String localTime; + private Date zonedDateTime; + private Date instant; + + public Date getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(Date localDateTime) { + this.localDateTime = localDateTime; + } + + public Date getLocalDate() { + return localDate; + } + + public void setLocalDate(Date localDate) { + this.localDate = localDate; + } + + public String getLocalTime() { + return localTime; + } + + public void setLocalTime(String localTime) { + this.localTime = localTime; + } + + public Date getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(Date zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } + + public Date getInstant() { + return instant; + } + + public void setInstant(Date instant) { + this.instant = instant; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Target.java new file mode 100644 index 0000000000..e43ecf0737 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Target.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1576.java8; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; + +public class Target { + + private LocalDateTime localDateTime; + private LocalDate localDate; + private LocalTime localTime; + private ZonedDateTime zonedDateTime; + private Instant instant; + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public void setLocalDate(LocalDate localDate) { + this.localDate = localDate; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public void setLocalTime(LocalTime localTime) { + this.localTime = localTime; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(ZonedDateTime zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } + + public Instant getInstant() { + return instant; + } + + public void setInstant(Instant instant) { + this.instant = instant; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576MapperImpl.java new file mode 100644 index 0000000000..f15d1b6830 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576MapperImpl.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1576.java8; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2018-11-05T21:40:12+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class Issue1576MapperImpl implements Issue1576Mapper { + + @Override + public Target map(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( LocalDateTime.ofInstant( source.getLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( LocalDateTime.ofInstant( source.getLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( LocalTime.parse( source.getLocalTime() ) ); + } + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( ZonedDateTime.ofInstant( source.getZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( source.getInstant() != null ) { + target.setInstant( source.getInstant().toInstant() ); + } + + return target; + } +} From 3f2c1cee55871096bacf9ae8709910eb73921367 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Nov 2018 09:19:05 +0100 Subject: [PATCH 0304/1006] [maven-release-plugin] prepare release 1.3.0.Beta2 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 462fe5c4db..8011dc3b66 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 48f50c7b60..c13354f9b2 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index fe993959b8..23a965cc0c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4645262fd4..cde934274e 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 3ce539793e..0a92feb336 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 18082e0a03..81deb6a92e 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index fdfb0dd478..493df2c260 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 pom MapStruct Parent @@ -57,7 +57,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Beta2 diff --git a/pom.xml b/pom.xml index 2786ef835f..6f39579f1b 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Beta2 diff --git a/processor/pom.xml b/processor/pom.xml index eb307ffa6d..dbae2d3fcd 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Beta2 ../parent/pom.xml From ced7f3b024d9a93c921d55071b075ad34f196b5a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Nov 2018 09:19:06 +0100 Subject: [PATCH 0305/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 8011dc3b66..462fe5c4db 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c13354f9b2..48f50c7b60 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 23a965cc0c..fe993959b8 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index cde934274e..4645262fd4 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a92feb336..3ce539793e 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 81deb6a92e..18082e0a03 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 493df2c260..fdfb0dd478 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT pom MapStruct Parent @@ -57,7 +57,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Beta2 + HEAD diff --git a/pom.xml b/pom.xml index 6f39579f1b..2786ef835f 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Beta2 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index dbae2d3fcd..eb307ffa6d 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Beta2 + 1.3.0-SNAPSHOT ../parent/pom.xml From 2977c2e614b241510950caf08d373a4a22e1edae Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Nov 2018 13:57:42 +0100 Subject: [PATCH 0306/1006] #1645 Use Repeatable Mapping annotation in the reference documentation --- .../controlling-nested-bean-mappings.asciidoc | 28 ++++++------- .../mapstruct-reference-guide.asciidoc | 40 ++++++++----------- 2 files changed, 29 insertions(+), 39 deletions(-) diff --git a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc index 18e9f54998..a3e6cdb82e 100644 --- a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc +++ b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc @@ -21,13 +21,11 @@ This tells MapStruct to deviate from looking for a name `kind` at this level and @Mapper public interface FishTankMapper { - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", ignore = true), - @Mapping(target = "ornament", source = "interior.ornament"), - @Mapping(target = "material.materialType", source = "material"), - @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", ignore = true) + @Mapping(target = "ornament", source = "interior.ornament") + @Mapping(target = "material.materialType", source = "material") + @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") FishTankDto map( FishTank source ); } ---- @@ -57,15 +55,13 @@ Such is demonstrated in the next example: @Mapper public interface FishTankMapperWithDocument { - @Mappings({ - @Mapping(target = "fish.kind", source = "fish.type"), - @Mapping(target = "fish.name", expression = "java(\"Jaws\")"), - @Mapping(target = "plant", ignore = true ), - @Mapping(target = "ornament", ignore = true ), - @Mapping(target = "material", ignore = true), - @Mapping(target = "quality.document", source = "quality.report"), - @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) - }) + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", expression = "java(\"Jaws\")") + @Mapping(target = "plant", ignore = true ) + @Mapping(target = "ornament", ignore = true ) + @Mapping(target = "material", ignore = true) + @Mapping(target = "quality.document", source = "quality.report") + @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) FishTankWithNestedDocumentDto map( FishTank source ); } diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index be998a3b84..44c757b11c 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -305,10 +305,8 @@ To create a mapper simply define a Java interface with the required mapping meth @Mapper public interface CarMapper { - @Mappings({ - @Mapping(source = "make", target = "manufacturer"), - @Mapping(source = "numberOfSeats", target = "seatCount") - }) + @Mapping(source = "make", target = "manufacturer") + @Mapping(source = "numberOfSeats", target = "seatCount") CarDto carToCarDto(Car car); @Mapping(source = "name", target = "fullName") @@ -432,7 +430,8 @@ As an example let's assume the mapping from `Person` to `PersonDto` requires som @Mapper public interface CarMapper { - @Mappings({...}) + @Mapping(...) + ... CarDto carToCarDto(Car car); default PersonDto personToPersonDto(Person person) { @@ -456,7 +455,8 @@ The previous example where the mapping from `Person` to `PersonDto` requires som @Mapper public abstract class CarMapper { - @Mappings(...) + @Mapping(...) + ... public abstract CarDto carToCarDto(Car car); public PersonDto personToPersonDto(Person person) { @@ -481,10 +481,8 @@ MapStruct also supports mapping methods with several source parameters. This is @Mapper public interface AddressMapper { - @Mappings({ - @Mapping(source = "person.description", target = "description"), - @Mapping(source = "address.houseNo", target = "houseNumber") - }) + @Mapping(source = "person.description", target = "description") + @Mapping(source = "address.houseNo", target = "houseNumber") DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address); } ---- @@ -514,10 +512,8 @@ MapStruct also offers the possibility to directly refer to a source parameter. @Mapper public interface AddressMapper { - @Mappings({ - @Mapping(source = "person.description", target = "description"), - @Mapping(source = "hn", target = "houseNumber") - }) + @Mapping(source = "person.description", target = "description") + @Mapping(source = "hn", target = "houseNumber") DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn); } ---- @@ -1954,15 +1950,13 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mappings( { - @Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined"), - @Mapping(target = "longProperty", source = "longProp", defaultValue = "-1"), - @Mapping(target = "stringConstant", constant = "Constant Value"), - @Mapping(target = "integerConstant", constant = "14"), - @Mapping(target = "longWrapperConstant", constant = "3001"), - @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), - @Mapping(target = "stringListConstants", constant = "jack-jill-tom") - } ) + @Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined") + @Mapping(target = "longProperty", source = "longProp", defaultValue = "-1") + @Mapping(target = "stringConstant", constant = "Constant Value") + @Mapping(target = "integerConstant", constant = "14") + @Mapping(target = "longWrapperConstant", constant = "3001") + @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014") + @Mapping(target = "stringListConstants", constant = "jack-jill-tom") Target sourceToTarget(Source s); } ---- From b651ad34b54d157bfa5121a7849cd09284df0720 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 18 Nov 2018 08:44:57 +0100 Subject: [PATCH 0307/1006] #1649 Improvement: builder for Mapper/Decorator/GeneratedType --- .../ap/internal/model/Decorator.java | 48 ++------ .../ap/internal/model/GeneratedType.java | 48 ++++++++ .../mapstruct/ap/internal/model/Mapper.java | 111 ++++++------------ .../processor/MapperCreationProcessor.java | 2 +- 4 files changed, 96 insertions(+), 113 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index ad88c0e387..ce034837e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -11,7 +11,6 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Type; @@ -27,28 +26,17 @@ */ public class Decorator extends GeneratedType { - public static class Builder { + public static class Builder extends GeneratedTypeBuilder { - private Elements elementUtils; - private TypeFactory typeFactory; private TypeElement mapperElement; private DecoratedWithPrism decoratorPrism; - private List methods; - private Options options; - private VersionInformation versionInformation; + private boolean hasDelegateConstructor; private String implName; private String implPackage; - private SortedSet extraImportedTypes; - public Builder elementUtils(Elements elementUtils) { - this.elementUtils = elementUtils; - return this; - } - - public Builder typeFactory(TypeFactory typeFactory) { - this.typeFactory = typeFactory; - return this; + public Builder() { + super( Builder.class ); } public Builder mapperElement(TypeElement mapperElement) { @@ -61,21 +49,6 @@ public Builder decoratorPrism(DecoratedWithPrism decoratorPrism) { return this; } - public Builder methods(List methods) { - this.methods = methods; - return this; - } - - public Builder options(Options options) { - this.options = options; - return this; - } - - public Builder versionInformation(VersionInformation versionInformation) { - this.versionInformation = versionInformation; - return this; - } - public Builder hasDelegateConstructor(boolean hasDelegateConstructor) { this.hasDelegateConstructor = hasDelegateConstructor; return this; @@ -91,20 +64,15 @@ public Builder implPackage(String implPackage) { return this; } - public Builder extraImports(SortedSet extraImportedTypes) { - this.extraImportedTypes = extraImportedTypes; - return this; - } - public Decorator build() { String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER, - Mapper.getFlatName( mapperElement ) ); + Mapper.getFlatName( mapperElement ) ); Type decoratorType = typeFactory.getType( decoratorPrism.value() ); DecoratorConstructor decoratorConstructor = new DecoratorConstructor( - implementationName, - implementationName + "_", - hasDelegateConstructor ); + implementationName, + implementationName + "_", + hasDelegateConstructor ); String elementPackage = elementUtils.getPackageOf( mapperElement ).getQualifiedName().toString(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index de16a5ce07..81ccc779a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -12,6 +12,7 @@ import java.util.TreeSet; import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.ModelElement; @@ -30,6 +31,53 @@ public abstract class GeneratedType extends ModelElement { private static final String JAVA_LANG_PACKAGE = "java.lang"; + protected abstract static class GeneratedTypeBuilder { + + private T myself; + protected TypeFactory typeFactory; + protected Elements elementUtils; + protected Options options; + protected VersionInformation versionInformation; + protected SortedSet extraImportedTypes; + + protected List methods; + + GeneratedTypeBuilder(Class selfType) { + myself = selfType.cast( this ); + } + + public T elementUtils(Elements elementUtils) { + this.elementUtils = elementUtils; + return myself; + } + + public T typeFactory(TypeFactory typeFactory) { + this.typeFactory = typeFactory; + return myself; + } + + public T options(Options options) { + this.options = options; + return myself; + } + + public T versionInformation(VersionInformation versionInformation) { + this.versionInformation = versionInformation; + return myself; + } + + public T extraImports(SortedSet extraImportedTypes) { + this.extraImportedTypes = extraImportedTypes; + return myself; + } + + public T methods(List methods) { + this.methods = methods; + return myself; + } + + } + private final String packageName; private final String name; private final String superClassName; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index e4b89b4c0b..0ebd1f0ffd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -12,7 +12,6 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Type; @@ -33,63 +32,24 @@ public class Mapper extends GeneratedType { static final String DEFAULT_IMPLEMENTATION_CLASS = CLASS_NAME_PLACEHOLDER + "Impl"; static final String DEFAULT_IMPLEMENTATION_PACKAGE = PACKAGE_NAME_PLACEHOLDER; - private final boolean customPackage; - private final boolean customImplName; - private Decorator decorator; - - @SuppressWarnings( "checkstyle:parameternumber" ) - private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName, - String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName, - List methods, Options options, VersionInformation versionInformation, - Accessibility accessibility, List fields, Constructor constructor, - Decorator decorator, SortedSet extraImportedTypes ) { - - super( - typeFactory, - packageName, - name, - superClassName, - interfacePackage, - interfaceName, - methods, - fields, - options, - versionInformation, - accessibility, - extraImportedTypes, - constructor - ); - this.customPackage = customPackage; - this.customImplName = customImplName; - - this.decorator = decorator; - } - - public static class Builder { + public static class Builder extends GeneratedTypeBuilder { - private TypeFactory typeFactory; private TypeElement element; - private List mappingMethods; private List fields; private Set fragments; - private SortedSet extraImportedTypes; - private Elements elementUtils; - private Options options; - private VersionInformation versionInformation; private Decorator decorator; private String implName; private boolean customName; private String implPackage; private boolean customPackage; - public Builder element(TypeElement element) { - this.element = element; - return this; + public Builder() { + super( Builder.class ); } - public Builder mappingMethods(List mappingMethods) { - this.mappingMethods = mappingMethods; + public Builder element(TypeElement element) { + this.element = element; return this; } @@ -103,36 +63,11 @@ public Builder constructorFragments(Set fragment return this; } - public Builder options(Options options) { - this.options = options; - return this; - } - - public Builder versionInformation(VersionInformation versionInformation) { - this.versionInformation = versionInformation; - return this; - } - - public Builder typeFactory(TypeFactory typeFactory) { - this.typeFactory = typeFactory; - return this; - } - - public Builder elementUtils(Elements elementUtils) { - this.elementUtils = elementUtils; - return this; - } - public Builder decorator(Decorator decorator) { this.decorator = decorator; return this; } - public Builder extraImports(SortedSet extraImportedTypes) { - this.extraImportedTypes = extraImportedTypes; - return this; - } - public Builder implName(String implName) { this.implName = implName; this.customName = !DEFAULT_IMPLEMENTATION_CLASS.equals( this.implName ); @@ -147,7 +82,7 @@ public Builder implPackage(String implPackage) { public Mapper build() { String implementationName = implName.replace( CLASS_NAME_PLACEHOLDER, getFlatName( element ) ) + - ( decorator == null ? "" : "_" ); + ( decorator == null ? "" : "_" ); String elementPackage = elementUtils.getPackageOf( element ).getQualifiedName().toString(); String packageName = implPackage.replace( PACKAGE_NAME_PLACEHOLDER, elementPackage ); @@ -164,7 +99,7 @@ public Mapper build() { element.getKind() == ElementKind.INTERFACE ? element.getSimpleName().toString() : null, customPackage, customName, - mappingMethods, + methods, options, versionInformation, Accessibility.fromModifiers( element.getModifiers() ), @@ -177,6 +112,38 @@ public Mapper build() { } + private final boolean customPackage; + private final boolean customImplName; + private Decorator decorator; + + @SuppressWarnings( "checkstyle:parameternumber" ) + private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName, + String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName, + List methods, Options options, VersionInformation versionInformation, + Accessibility accessibility, List fields, Constructor constructor, + Decorator decorator, SortedSet extraImportedTypes ) { + + super( + typeFactory, + packageName, + name, + superClassName, + interfacePackage, + interfaceName, + methods, + fields, + options, + versionInformation, + accessibility, + extraImportedTypes, + constructor + ); + this.customPackage = customPackage; + this.customImplName = customImplName; + + this.decorator = decorator; + } + public Decorator getDecorator() { return decorator; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index b55422cf77..974822216f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -162,7 +162,7 @@ private Mapper getMapper(TypeElement element, MapperConfiguration mapperConfig, Mapper mapper = new Mapper.Builder() .element( element ) - .mappingMethods( mappingMethods ) + .methods( mappingMethods ) .fields( fields ) .constructorFragments( constructorFragments ) .options( options ) From a3ba57c372a9913398f4fda4de6949abaf196c78 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Nov 2018 10:11:11 +0100 Subject: [PATCH 0308/1006] #1648 Source properties defined in Mapping should not be reported as unmapped --- .../ap/internal/model/BeanMappingMethod.java | 1 + .../ap/test/bugs/_1648/Issue1648Mapper.java | 23 ++++++++++++ .../ap/test/bugs/_1648/Issue1648Test.java | 37 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1648/Source.java | 22 +++++++++++ .../mapstruct/ap/test/bugs/_1648/Target.java | 22 +++++++++++ 5 files changed, 105 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a257dc2cee..abd488e03a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -486,6 +486,7 @@ else if ( mapping.getSourceName() != null ) { .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); handledTargets.add( propertyName ); + unprocessedSourceProperties.remove( mapping.getSourceName() ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java new file mode 100644 index 0000000000..713de86997 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Mapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1648; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue1648Mapper { + + Issue1648Mapper INSTANCE = Mappers.getMapper( Issue1648Mapper.class ); + + @Mapping(target = "targetValue", source = "sourceValue") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java new file mode 100644 index 0000000000..03ba02d4b0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1648; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1648") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1648Mapper.class, + Source.class, + Target.class, +}) +public class Issue1648Test { + + @Test + public void shouldCorrectlyMarkSourceAsUsed() { + Source source = new Source(); + source.setSourceValue( "value" ); + + Target target = Issue1648Mapper.INSTANCE.map( source ); + + assertThat( target.getTargetValue() ).isEqualTo( "value" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java new file mode 100644 index 0000000000..5d9f207bf0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1648; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String sourceValue; + + public String getSourceValue() { + return sourceValue; + } + + public void setSourceValue(String sourceValue) { + this.sourceValue = sourceValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java new file mode 100644 index 0000000000..0225e9540f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1648; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String targetValue; + + public String getTargetValue() { + return targetValue; + } + + public void setTargetValue(String targetValue) { + this.targetValue = targetValue; + } +} From 9a43b210d39bc590d8c9237d13c5c9016199b6b4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Nov 2018 02:07:31 +0100 Subject: [PATCH 0309/1006] Add since tag to new API elements --- core/src/main/java/org/mapstruct/BeanMapping.java | 2 ++ core/src/main/java/org/mapstruct/Mapper.java | 2 ++ core/src/main/java/org/mapstruct/MapperConfig.java | 2 ++ core/src/main/java/org/mapstruct/Mapping.java | 4 ++++ .../java/org/mapstruct/NullValuePropertyMappingStrategy.java | 1 + .../java/org/mapstruct/ap/spi/AccessorNamingStrategy.java | 2 ++ processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java | 2 ++ .../src/main/java/org/mapstruct/ap/spi/BuilderProvider.java | 2 ++ .../org/mapstruct/ap/spi/MapStructProcessingEnvironment.java | 2 ++ 9 files changed, 19 insertions(+) diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index b510b442d2..6b062dac99 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -69,6 +69,8 @@ * {@link Mapper#nullValuePropertyMappingStrategy()} will be applied, * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. * + * @since 1.3 + * * @return The strategy to be applied when {@code null} is passed as source property value or the source property * is not present. */ diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 64e22ab741..69e70e859e 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -153,6 +153,8 @@ * configured, the strategy given via {@link MapperConfig#nullValuePropertyMappingStrategy()} will be applied, * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. * + * @since 1.3 + * * @return The strategy to be applied when {@code null} is passed as source property value or the source property * is not present. */ diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index cd58d70dbd..e042d40116 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -136,6 +136,8 @@ * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is * configured, {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. * + * @since 1.3 + * * @return The strategy to be applied when {@code null} is passed as source property value or the source property * is not present. */ diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 66f4f825e9..01ffcd17a1 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -264,6 +264,8 @@ * * Can be overridden by the one on {@link MapperConfig}, {@link Mapper} or {@link BeanMapping}. * + * @since 1.3 + * * @return strategy how to do null checking */ NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION; @@ -276,6 +278,8 @@ * * {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. * + * @since 1.3 + * * @return The strategy to be applied when {@code null} is passed as source property value or the source property * is not present. */ diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index 41ee737d09..c9182938f8 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -16,6 +16,7 @@ * {@code @}{@link MappingTarget}). * * @author Sjaak Derksen + * @since 1.3 */ public enum NullValuePropertyMappingStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java index e4dd2cfe27..c9d0734753 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java @@ -19,6 +19,8 @@ public interface AccessorNamingStrategy { * Initializes the accessor naming strategy with the MapStruct processing environment. * * @param processingEnvironment environment for facilities + * + * @since 1.3 */ default void init(MapStructProcessingEnvironment processingEnvironment) { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java index 1e55bef95c..0f95567481 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -12,6 +12,8 @@ * Holder for the builder information. * * @author Filip Hrisafov + * + * @since 1.3 */ public class BuilderInfo { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java index c755c63f2f..419c85a39d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderProvider.java @@ -11,6 +11,8 @@ * A service provider interface that is used to detect types that require a builder for mapping. This interface could * support automatic detection of builders for projects like Lombok, Immutables, AutoValue, etc. * @author Filip Hrisafov + * + * @since 1.3 */ public interface BuilderProvider { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java index 97fd42148b..0471108a51 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java @@ -15,6 +15,8 @@ * * @author Filip Hrisafov * @see javax.annotation.processing.ProcessingEnvironment + * + * @since 1.3 */ public interface MapStructProcessingEnvironment { From d1fe65dbad0d3abb84756d1eace8a7251f69b9e0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 1 Dec 2018 18:20:31 +0100 Subject: [PATCH 0310/1006] #1660 Consider only public not static accessor methods as possible getter, setter, presence check and / or adder methods --- .../ap/internal/util/AccessorNamingUtils.java | 10 ++-- .../ap/internal/util/Executables.java | 4 ++ .../ap/test/bugs/_1660/Issue1660Mapper.java | 21 ++++++++ .../ap/test/bugs/_1660/Issue1660Test.java | 38 ++++++++++++++ .../mapstruct/ap/test/bugs/_1660/Source.java | 30 ++++++++++++ .../mapstruct/ap/test/bugs/_1660/Target.java | 49 +++++++++++++++++++ 6 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java index 3f80ab34e7..3d0d11686b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -18,7 +18,7 @@ import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.MethodType; -import static org.mapstruct.ap.internal.util.Executables.isPublic; +import static org.mapstruct.ap.internal.util.Executables.isPublicNotStatic; /** * Utils for working with the {@link AccessorNamingStrategy}. @@ -35,7 +35,7 @@ public AccessorNamingUtils(AccessorNamingStrategy accessorNamingStrategy) { public boolean isGetterMethod(Accessor method) { ExecutableElement executable = method.getExecutable(); - return executable != null && isPublic( method ) && + return executable != null && isPublicNotStatic( method ) && executable.getParameters().isEmpty() && accessorNamingStrategy.getMethodType( executable ) == MethodType.GETTER; } @@ -46,7 +46,7 @@ public boolean isPresenceCheckMethod(Accessor method) { } ExecutableElement executable = method.getExecutable(); return executable != null - && isPublic( method ) + && isPublicNotStatic( method ) && executable.getParameters().isEmpty() && ( executable.getReturnType().getKind() == TypeKind.BOOLEAN || "java.lang.Boolean".equals( getQualifiedName( executable.getReturnType() ) ) ) @@ -56,7 +56,7 @@ && isPublic( method ) public boolean isSetterMethod(Accessor method) { ExecutableElement executable = method.getExecutable(); return executable != null - && isPublic( method ) + && isPublicNotStatic( method ) && executable.getParameters().size() == 1 && accessorNamingStrategy.getMethodType( executable ) == MethodType.SETTER; } @@ -64,7 +64,7 @@ && isPublic( method ) public boolean isAdderMethod(Accessor method) { ExecutableElement executable = method.getExecutable(); return executable != null - && isPublic( method ) + && isPublicNotStatic( method ) && executable.getParameters().size() == 1 && accessorNamingStrategy.getMethodType( executable ) == MethodType.ADDER; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 6d085ea760..6c16b6a8a0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -67,6 +67,10 @@ public static boolean isFieldAccessor(Accessor accessor) { return executable == null && isPublic( accessor ) && isNotStatic( accessor ); } + static boolean isPublicNotStatic(Accessor accessor) { + return isPublic( accessor ) && isNotStatic( accessor ); + } + static boolean isPublic(Accessor method) { return method.getModifiers().contains( Modifier.PUBLIC ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Mapper.java new file mode 100644 index 0000000000..512455970c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Mapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1660; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue1660Mapper { + + Issue1660Mapper INSTANCE = Mappers.getMapper( Issue1660Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java new file mode 100644 index 0000000000..838f705c20 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1660; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1660") +@WithClasses({ + Issue1660Mapper.class, + Source.class, + Target.class, +}) +public class Issue1660Test { + + @Test + public void shouldNotUseStaticMethods() { + Source source = new Source(); + source.setValue( "source" ); + Target target = Issue1660Mapper.INSTANCE.map( source ); + + assertThat( target.getValue() ).isEqualTo( "source" ); + assertThat( Target.getStaticValue() ).isEqualTo( "targetStatic" ); + assertThat( Target.getOtherStaticValues() ).containsExactly( "targetOtherStatic" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Source.java new file mode 100644 index 0000000000..bd324f2f14 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Source.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1660; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public static String getStaticValue() { + return "sourceStatic"; + } + + public String getOtherStaticValue() { + return "sourceOtherStatic"; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Target.java new file mode 100644 index 0000000000..2e2e3cd27d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Target.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1660; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private static String staticValue = "targetStatic"; + private static List otherStaticValues = new ArrayList<>( Collections.singletonList( "targetOtherStatic" ) ); + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public static String getStaticValue() { + return staticValue; + } + + public static void setStaticValue(String staticValue) { + Target.staticValue = staticValue; + } + + public static List getOtherStaticValues() { + return otherStaticValues; + } + + public static void addOtherStaticValue(String otherStaticValue) { + Target.otherStaticValues.add( otherStaticValue ); + } + + public static void setOtherStaticValues(List otherStaticValues) { + Target.otherStaticValues = otherStaticValues; + } +} From 780fd739286be8f12626c0a1eb508c366146b59d Mon Sep 17 00:00:00 2001 From: Taras Mychaskiw Date: Sat, 8 Dec 2018 14:25:42 -0500 Subject: [PATCH 0311/1006] #1656 Support for mapping between String and java.time Duration, Period, Instant --- .../mapstruct-reference-guide.asciidoc | 2 + .../ap/internal/conversion/Conversions.java | 9 +- .../StaticParseToStringConversion.java | 36 ++++ .../java8time/Java8TimeConversionTest.java | 159 ++++++++++++++++-- .../ap/test/conversion/java8time/Source.java | 32 ++++ .../ap/test/conversion/java8time/Target.java | 30 ++++ 6 files changed, 248 insertions(+), 20 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 44c757b11c..d371e310b7 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -944,6 +944,8 @@ public interface CarMapper { * Between `java.time.ZonedDateTime`, `java.time.LocalDateTime`, `java.time.LocalDate`, `java.time.LocalTime` from Java 8 Date-Time package and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). +* Between `java.time.Instant`, `java.time.Duration`, `java.time.Period` from Java 8 Date-Time package and `String` using the `parse` method in each class to map from `String` and using `toString` to map into `String`. + * Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Date` where, when mapping a `ZonedDateTime` from a given `Date`, the system default timezone is used. * Between `java.time.LocalDateTime` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 6f4db9316f..9f0ad97485 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -9,10 +9,12 @@ import java.math.BigInteger; import java.sql.Time; import java.sql.Timestamp; +import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.Period; import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Currency; @@ -171,8 +173,8 @@ public Conversions(Elements elementUtils, TypeFactory typeFactory) { registerToStringConversion( Boolean.class ); register( char.class, String.class, new CharToStringConversion() ); register( Character.class, String.class, new CharWrapperToStringConversion() ); - register( BigInteger.class, String.class, new BigIntegerToStringConversion( ) ); - register( BigDecimal.class, String.class, new BigDecimalToStringConversion( ) ); + register( BigInteger.class, String.class, new BigIntegerToStringConversion() ); + register( BigDecimal.class, String.class, new BigDecimalToStringConversion() ); registerJodaConversions(); @@ -217,6 +219,9 @@ private void registerJava8TimeConversions() { register( LocalDate.class, String.class, new JavaLocalDateToStringConversion() ); register( LocalDateTime.class, String.class, new JavaLocalDateTimeToStringConversion() ); register( LocalTime.class, String.class, new JavaLocalTimeToStringConversion() ); + register( Instant.class, String.class, new StaticParseToStringConversion() ); + register( Period.class, String.class, new StaticParseToStringConversion() ); + register( Duration.class, String.class, new StaticParseToStringConversion() ); // Java 8 to Date register( ZonedDateTime.class, Date.class, new JavaZonedDateTimeToDateConversion() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java new file mode 100644 index 0000000000..15d7b4bcc9 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +/** + * Handles conversion between a target type T and {@link String}, + * where {@code T#parse(String)} and {@code T#toString} are inverse operations. + * The {@link ConversionContext#getTargetType()} is used as the from target type T. + */ +public class StaticParseToStringConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toString()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return conversionContext.getTargetType().createReferenceName() + ".parse( )"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( conversionContext.getTargetType() ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index 271a8d9589..573e300bfc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -5,12 +5,12 @@ */ package org.mapstruct.ap.test.conversion.java8time; -import static org.assertj.core.api.Assertions.assertThat; - +import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.Period; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.Calendar; @@ -23,6 +23,8 @@ import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for conversions to/from Java 8 date and time types. */ @@ -99,7 +101,7 @@ public void testStringToDateTime() { Target target = new Target(); target.setZonedDateTime( dateTimeAsString ); ZonedDateTime sourceDateTime = - ZonedDateTime.of( java.time.LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); + ZonedDateTime.of( java.time.LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); Source src = SourceTargetMapper.INSTANCE.targetToSourceDateTimeMapped( target ); assertThat( src ).isNotNull(); @@ -112,7 +114,7 @@ public void testStringToLocalDateTime() { Target target = new Target(); target.setLocalDateTime( dateTimeAsString ); LocalDateTime sourceDateTime = - LocalDateTime.of( 2014, 1, 1, 0, 0, 0 ); + LocalDateTime.of( 2014, 1, 1, 0, 0, 0 ); Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateTimeMapped( target ); assertThat( src ).isNotNull(); @@ -125,7 +127,7 @@ public void testStringToLocalDate() { Target target = new Target(); target.setLocalDate( dateTimeAsString ); LocalDate sourceDate = - LocalDate.of( 2014, 1, 1 ); + LocalDate.of( 2014, 1, 1 ); Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalDateMapped( target ); assertThat( src ).isNotNull(); @@ -138,7 +140,7 @@ public void testStringToLocalTime() { Target target = new Target(); target.setLocalTime( dateTimeAsString ); LocalTime sourceTime = - LocalTime.of( 0, 0 ); + LocalTime.of( 0, 0 ); Source src = SourceTargetMapper.INSTANCE.targetToSourceLocalTimeMapped( target ); assertThat( src ).isNotNull(); @@ -169,13 +171,14 @@ public void testTargetToSourceMappingForStrings() { Source src = SourceTargetMapper.INSTANCE.targetToSource( target ); assertThat( src.getZonedDateTime() ).isEqualTo( - ZonedDateTime.of( - java.time.LocalDateTime.of( - 2014, - 1, - 1, - 0, - 0 ), ZoneId.of( "UTC" ) ) ); + ZonedDateTime.of( + java.time.LocalDateTime.of( + 2014, + 1, + 1, + 0, + 0 + ), ZoneId.of( "UTC" ) ) ); assertThat( src.getLocalDateTime() ).isEqualTo( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ); assertThat( src.getLocalDate() ).isEqualTo( LocalDate.of( 2014, 1, 1 ) ); assertThat( src.getLocalTime() ).isEqualTo( LocalTime.of( 0, 0 ) ); @@ -186,17 +189,17 @@ public void testCalendarMapping() { Source source = new Source(); ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); source.setForCalendarConversion( - dateTime ); + dateTime ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); assertThat( target.getForCalendarConversion() ).isNotNull(); assertThat( target.getForCalendarConversion().getTimeZone() ).isEqualTo( - TimeZone.getTimeZone( - "UTC" ) ); + TimeZone.getTimeZone( + "UTC" ) ); assertThat( target.getForCalendarConversion().get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() ); assertThat( target.getForCalendarConversion().get( Calendar.MONTH ) ).isEqualTo( - dateTime.getMonthValue() - 1 ); + dateTime.getMonthValue() - 1 ); assertThat( target.getForCalendarConversion().get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() ); assertThat( target.getForCalendarConversion().get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() ); assertThat( target.getForCalendarConversion().get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() ); @@ -212,7 +215,7 @@ public void testZonedDateTimeToDateMapping() { Source source = new Source(); ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); source.setForDateConversionWithZonedDateTime( - dateTime ); + dateTime ); Target target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); assertThat( target.getForDateConversionWithZonedDateTime() ).isNotNull(); @@ -319,4 +322,124 @@ public void testLocalDateToSqlDateMapping() { assertThat( source.getForSqlDateConversionWithLocalDate() ).isEqualTo( localDate ); } + + @Test + public void testInstantToStringMapping() { + Source source = new Source(); + source.setForInstantConversionWithString( Instant.ofEpochSecond( 42L ) ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForInstantConversionWithString(); + assertThat( periodString ).isEqualTo( "1970-01-01T00:00:42Z" ); + } + + @Test + public void testInstantToStringNullMapping() { + Source source = new Source(); + source.setForInstantConversionWithString( null ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForInstantConversionWithString(); + assertThat( periodString ).isNull(); + } + + @Test + public void testStringToInstantMapping() { + Target target = new Target(); + target.setForInstantConversionWithString( "1970-01-01T00:00:00.000Z" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Instant instant = source.getForInstantConversionWithString(); + assertThat( instant ).isEqualTo( Instant.EPOCH ); + } + + @Test + public void testStringToInstantNullMapping() { + Target target = new Target(); + target.setForInstantConversionWithString( null ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Instant instant = source.getForInstantConversionWithString(); + assertThat( instant ).isNull(); + } + + @Test + public void testPeriodToStringMapping() { + Source source = new Source(); + source.setForPeriodConversionWithString( Period.ofDays( 42 ) ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForPeriodConversionWithString(); + assertThat( periodString ).isEqualTo( "P42D" ); + } + + @Test + public void testPeriodToStringNullMapping() { + Source source = new Source(); + source.setForPeriodConversionWithString( null ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForPeriodConversionWithString(); + assertThat( periodString ).isNull(); + } + + @Test + public void testStringToPeriodMapping() { + Target target = new Target(); + target.setForPeriodConversionWithString( "P1Y2M3D" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Period period = source.getForPeriodConversionWithString(); + assertThat( period ).isEqualTo( Period.of( 1, 2, 3 ) ); + } + + @Test + public void testStringToPeriodNullMapping() { + Target target = new Target(); + target.setForPeriodConversionWithString( null ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Period period = source.getForPeriodConversionWithString(); + assertThat( period ).isNull(); + } + + @Test + public void testDurationToStringMapping() { + Source source = new Source(); + source.setForDurationConversionWithString( Duration.ofMinutes( 42L ) ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String durationString = target.getForDurationConversionWithString(); + assertThat( durationString ).isEqualTo( "PT42M" ); + } + + @Test + public void testDurationToStringNullMapping() { + Source source = new Source(); + source.setForDurationConversionWithString( null ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + String durationString = target.getForDurationConversionWithString(); + assertThat( durationString ).isNull(); + } + + @Test + public void testStringToDurationMapping() { + Target target = new Target(); + target.setForDurationConversionWithString( "PT20.345S" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Duration duration = source.getForDurationConversionWithString(); + assertThat( duration ).isEqualTo( Duration.ofSeconds( 20L, 345000000L ) ); + } + + @Test + public void testStringToDurationNullMapping() { + Target target = new Target(); + target.setForDurationConversionWithString( null ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + Duration duration = source.getForDurationConversionWithString(); + assertThat( duration ).isNull(); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java index 8862971701..91298617cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java @@ -5,10 +5,12 @@ */ package org.mapstruct.ap.test.conversion.java8time; +import java.time.Duration; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.Period; import java.time.ZonedDateTime; /** @@ -36,6 +38,12 @@ public class Source { private Instant forDateConversionWithInstant; + private Instant forInstantConversionWithString; + + private Period forPeriodConversionWithString; + + private Duration forDurationConversionWithString; + public ZonedDateTime getZonedDateTime() { return zonedDateTime; } @@ -115,4 +123,28 @@ public Instant getForDateConversionWithInstant() { public void setForDateConversionWithInstant(Instant forDateConversionWithInstant) { this.forDateConversionWithInstant = forDateConversionWithInstant; } + + public Instant getForInstantConversionWithString() { + return forInstantConversionWithString; + } + + public void setForInstantConversionWithString(Instant forInstantConversionWithString) { + this.forInstantConversionWithString = forInstantConversionWithString; + } + + public Period getForPeriodConversionWithString() { + return forPeriodConversionWithString; + } + + public void setForPeriodConversionWithString(Period forPeriodConversionWithString) { + this.forPeriodConversionWithString = forPeriodConversionWithString; + } + + public Duration getForDurationConversionWithString() { + return forDurationConversionWithString; + } + + public void setForDurationConversionWithString(Duration forDurationConversionWithString) { + this.forDurationConversionWithString = forDurationConversionWithString; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java index eac1603d4c..188a6d0e20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java @@ -33,6 +33,12 @@ public class Target { private Date forDateConversionWithInstant; + private String forInstantConversionWithString; + + private String forPeriodConversionWithString; + + private String forDurationConversionWithString; + public String getZonedDateTime() { return zonedDateTime; } @@ -112,4 +118,28 @@ public Date getForDateConversionWithInstant() { public void setForDateConversionWithInstant(Date forDateConversionWithInstant) { this.forDateConversionWithInstant = forDateConversionWithInstant; } + + public String getForInstantConversionWithString() { + return forInstantConversionWithString; + } + + public void setForInstantConversionWithString(String forInstantConversionWithString) { + this.forInstantConversionWithString = forInstantConversionWithString; + } + + public String getForPeriodConversionWithString() { + return forPeriodConversionWithString; + } + + public void setForPeriodConversionWithString(String forPeriodConversionWithString) { + this.forPeriodConversionWithString = forPeriodConversionWithString; + } + + public String getForDurationConversionWithString() { + return forDurationConversionWithString; + } + + public void setForDurationConversionWithString(String forDurationConversionWithString) { + this.forDurationConversionWithString = forDurationConversionWithString; + } } From e2915c864e8e032273f063d555bdfca985654ae5 Mon Sep 17 00:00:00 2001 From: Arne Seime Date: Tue, 11 Dec 2018 18:33:50 +0100 Subject: [PATCH 0312/1006] #1665 Box any primitives before attempting type comparison for adder accessors --- .../ap/internal/model/common/Type.java | 12 +++++- .../ap/test/bugs/_1665/Issue1665Mapper.java | 21 +++++++++ .../ap/test/bugs/_1665/Issue1665Test.java | 43 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1665/Source.java | 24 +++++++++++ .../mapstruct/ap/test/bugs/_1665/Target.java | 25 +++++++++++ 5 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 7fa56b5640..8097b15e61 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -23,6 +23,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.type.WildcardType; @@ -722,13 +723,22 @@ private List getAccessorCandidates(Type property, Class superclass) continue; } VariableElement arg = executable.getParameters().get( 0 ); - if ( typeUtils.isSameType( arg.asType(), typeArg ) ) { + if ( typeUtils.isSameType( boxed( arg.asType() ), boxed( typeArg ) ) ) { candidateList.add( adder ); } } return candidateList; } + private TypeMirror boxed(TypeMirror possiblePrimitive) { + if ( possiblePrimitive.getKind().isPrimitive() ) { + return typeUtils.boxedClass( (PrimitiveType) possiblePrimitive ).asType(); + } + else { + return possiblePrimitive; + } + } + /** * getSetters * diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Mapper.java new file mode 100644 index 0000000000..1087ba4c1d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Mapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1665; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Arne Seime + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue1665Mapper { + + Issue1665Mapper INSTANCE = Mappers.getMapper( Issue1665Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java new file mode 100644 index 0000000000..4690d5d5a2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1665; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Arne Seime + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1665") +@WithClasses({ + Issue1665Mapper.class, + Source.class, + Target.class, +}) +public class Issue1665Test { + + @Test + public void shouldBoxIntPrimitive() { + Source source = new Source(); + List values = new ArrayList<>(); + values.add( 10 ); + source.setValue( values ); + + Target target = Issue1665Mapper.INSTANCE.map( source ); + + assertThat( target.getValue().size() ).isEqualTo( source.getValue().size() ); + assertThat( target.getValue().get( 0 ) ).isEqualTo( source.getValue().get( 0 ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Source.java new file mode 100644 index 0000000000..f89ed4436d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Source.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1665; + +import java.util.List; + +/** + * @author Arne Seime + */ +public class Source { + + private List value; + + public List getValue() { + return value; + } + + public void setValue(List value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Target.java new file mode 100644 index 0000000000..7c2cf5620d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Target.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1665; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Arne Seime + */ +public class Target { + + private List value = new ArrayList<>(); + + public void addValue(int v) { + value.add( v ); + } + + public List getValue() { + return value; + } +} From 8edc6f82aa53cd1398944518034759ffd2af08c0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 11 Dec 2018 18:36:09 +0100 Subject: [PATCH 0313/1006] Add Arne to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index c15d26b5bc..99f73d1965 100644 --- a/copyright.txt +++ b/copyright.txt @@ -3,6 +3,7 @@ Alexandr Shalugin - https://github.com/shalugin Andreas Gudian - https://github.com/agudian +Arne Seime - https://github.com/seime Christian Bandowski - https://github.com/chris922 Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools From 743361ca45ab9eb26592b6b220c01d142e1d832f Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 20 Dec 2018 21:12:37 +0100 Subject: [PATCH 0314/1006] #1650 cannot find symbol nested mapping mappingtarget (#1671) * #1650 reproducer * #1650 fix cannot-find-symbol * #1650 reproducer, extended --- .../model/assignment/UpdateWrapper.ftl | 3 +- .../org/mapstruct/ap/test/bugs/_1650/A.java | 18 ++++++++ .../mapstruct/ap/test/bugs/_1650/AMapper.java | 27 +++++++++++ .../mapstruct/ap/test/bugs/_1650/APrime.java | 19 ++++++++ .../org/mapstruct/ap/test/bugs/_1650/B.java | 18 ++++++++ .../org/mapstruct/ap/test/bugs/_1650/C.java | 9 ++++ .../mapstruct/ap/test/bugs/_1650/CPrime.java | 9 ++++ .../ap/test/bugs/_1650/Issue1650Test.java | 45 +++++++++++++++++++ 8 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/A.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/APrime.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/B.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 9dfbc08586..bdcb438d08 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -9,7 +9,8 @@ <#import '../macro/CommonMacros.ftl' as lib > <@lib.handleExceptions> <#if includeSourceNullCheck> - if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else>${sourceReference} != null ) { + <@lib.sourceLocalVarAssignment/> + if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { <@assignToExistingTarget/> <@lib.handleAssignment/>; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/A.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/A.java new file mode 100644 index 0000000000..692f72282a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/A.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +public class A { + private B b; + + public B getB() { + return b; + } + + public void setB(B b) { + this.b = b; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java new file mode 100644 index 0000000000..860c3b21e3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface AMapper { + + AMapper INSTANCE = Mappers.getMapper( AMapper.class ); + + @Mapping(source = "b.c", target = "cPrime") + APrime toAPrime(A a, @MappingTarget APrime mappingTarget); + + CPrime toCPrime(C c, @MappingTarget CPrime mappingTarget); + + @Mapping(source = "b.c", target = "cPrime") + APrime toAPrime(A a); + + CPrime toCPrime(C c); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/APrime.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/APrime.java new file mode 100644 index 0000000000..625816f179 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/APrime.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +public class APrime { + + private CPrime cPrime; + + public CPrime getcPrime() { + return cPrime; + } + + public void setcPrime(CPrime cPrime) { + this.cPrime = cPrime; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/B.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/B.java new file mode 100644 index 0000000000..924858c8d3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/B.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +public class B { + private C c; + + public C getC() { + return c; + } + + public void setC(C c) { + this.c = c; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java new file mode 100644 index 0000000000..705f2e2d69 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +public class C { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java new file mode 100644 index 0000000000..24e4376f88 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +public class CPrime { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java new file mode 100644 index 0000000000..9dd6f2dba6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1650; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("1650") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + AMapper.class, + A.class, + B.class, + C.class, + APrime.class, + CPrime.class +}) +public class Issue1650Test { + + @Test + public void shouldCompile() { + + A a = new A(); + a.setB( new B() ); + a.getB().setC( new C() ); + + APrime aPrime = new APrime(); + + // update mapping + AMapper.INSTANCE.toAPrime( a, aPrime ); + assertThat( aPrime.getcPrime() ).isNotNull(); + + // create mapping + APrime aPrime1 = AMapper.INSTANCE.toAPrime( a ); + assertThat( aPrime1.getcPrime() ).isNotNull(); + } +} From 0e33ad4bbcfd7f8628f63221db4faa7415ac4384 Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sat, 22 Dec 2018 15:19:39 +0100 Subject: [PATCH 0315/1006] #1657 Add Mappers.getMapperClass for getting the class of a Mapper --- .../java/org/mapstruct/factory/Mappers.java | 94 +++++++++++++++---- .../org/mapstruct/factory/MappersTest.java | 21 ++++- 2 files changed, 96 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/mapstruct/factory/Mappers.java b/core/src/main/java/org/mapstruct/factory/Mappers.java index ac479d3646..05b616fe9a 100644 --- a/core/src/main/java/org/mapstruct/factory/Mappers.java +++ b/core/src/main/java/org/mapstruct/factory/Mappers.java @@ -53,14 +53,7 @@ private Mappers() { */ public static T getMapper(Class clazz) { try { - List classLoaders = new ArrayList<>( 3 ); - classLoaders.add( clazz.getClassLoader() ); - - if ( Thread.currentThread().getContextClassLoader() != null ) { - classLoaders.add( Thread.currentThread().getContextClassLoader() ); - } - - classLoaders.add( Mappers.class.getClassLoader() ); + List classLoaders = collectClassLoaders( clazz.getClassLoader() ); return getMapper( clazz, classLoaders ); } @@ -88,23 +81,88 @@ private static T doGetMapper(Class clazz, ClassLoader classLoader) throws Class implementation = (Class) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ); Constructor constructor = implementation.getDeclaredConstructor(); constructor.setAccessible( true ); + return constructor.newInstance(); } catch (ClassNotFoundException e) { - ServiceLoader loader = ServiceLoader.load( clazz, classLoader ); - - if ( loader != null ) { - for ( T mapper : loader ) { - if ( mapper != null ) { - return mapper; - } - } + return getMapperFromServiceLoader( clazz, classLoader ); + } + catch ( InstantiationException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException( e ); + } + } + + /** + * Returns the class of the implementation for the given mapper type. + * + * @param clazz The type of the mapper to return. + * @param The type of the mapper to create. + * + * @return A class of the implementation for the given mapper type. + * + * @since 1.3 + */ + public static Class getMapperClass(Class clazz) { + try { + List classLoaders = collectClassLoaders( clazz.getClassLoader() ); + + return getMapperClass( clazz, classLoaders ); + } + catch ( ClassNotFoundException e ) { + throw new RuntimeException( e ); + } + } + + private static Class getMapperClass(Class mapperType, Iterable classLoaders) + throws ClassNotFoundException { + + for ( ClassLoader classLoader : classLoaders ) { + Class mapperClass = doGetMapperClass( mapperType, classLoader ); + if ( mapperClass != null ) { + return mapperClass; + } + } + + throw new ClassNotFoundException( "Cannot find implementation for " + mapperType.getName() ); + } + + @SuppressWarnings("unchecked") + private static Class doGetMapperClass(Class clazz, ClassLoader classLoader) { + try { + return (Class) classLoader.loadClass( clazz.getName() + IMPLEMENTATION_SUFFIX ); + } + catch ( ClassNotFoundException e ) { + T mapper = getMapperFromServiceLoader( clazz, classLoader ); + if ( mapper != null ) { + return (Class) mapper.getClass(); } return null; } - catch ( InstantiationException | InvocationTargetException | IllegalAccessException e) { - throw new RuntimeException( e ); + } + + private static T getMapperFromServiceLoader(Class clazz, ClassLoader classLoader) { + ServiceLoader loader = ServiceLoader.load( clazz, classLoader ); + + for ( T mapper : loader ) { + if ( mapper != null ) { + return mapper; + } + } + + return null; + } + + private static List collectClassLoaders(ClassLoader classLoader) { + List classLoaders = new ArrayList<>( 3 ); + classLoaders.add( classLoader ); + + if ( Thread.currentThread().getContextClassLoader() != null ) { + classLoaders.add( Thread.currentThread().getContextClassLoader() ); } + + classLoaders.add( Mappers.class.getClassLoader() ); + + return classLoaders; } } diff --git a/core/src/test/java/org/mapstruct/factory/MappersTest.java b/core/src/test/java/org/mapstruct/factory/MappersTest.java index 507eb08d0e..60371cada8 100644 --- a/core/src/test/java/org/mapstruct/factory/MappersTest.java +++ b/core/src/test/java/org/mapstruct/factory/MappersTest.java @@ -25,18 +25,37 @@ public void shouldReturnImplementationInstance() { assertThat( mapper ).isNotNull(); } + @Test + public void shouldReturnImplementationClass() { + + Class mapperClass = Mappers.getMapperClass( Foo.class ); + assertThat( mapperClass ).isNotNull(); + assertThat( mapperClass ).isNotExactlyInstanceOf( Foo.class ); + } + /** * Checks if an implementation of a nested mapper can be found. This is a special case since * it is named */ @Test - public void findsNestedMapperImpl() throws Exception { + public void findsNestedMapperImpl() { assertThat( Mappers.getMapper( SomeClass.Foo.class ) ).isNotNull(); assertThat( Mappers.getMapper( SomeClass.NestedClass.Foo.class ) ).isNotNull(); } + @Test + public void findsNestedMapperImplClass() { + assertThat( Mappers.getMapperClass( SomeClass.Foo.class ) ).isNotNull(); + assertThat( Mappers.getMapperClass( SomeClass.NestedClass.Foo.class ) ).isNotNull(); + } + @Test public void shouldReturnPackagePrivateImplementationInstance() { assertThat( Mappers.getMapper( PackagePrivateMapper.class ) ).isNotNull(); } + + @Test + public void shouldReturnPackagePrivateImplementationClass() { + assertThat( Mappers.getMapperClass( PackagePrivateMapper.class ) ).isNotNull(); + } } From b46682f95b43397dae089906b2c0dfc3859f33ce Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 20 Jan 2019 15:28:55 +0100 Subject: [PATCH 0316/1006] Go back to using 3.0.0-M1 of the maven-enforcer-plugin Once https://issues.apache.org/jira/browse/MENFORCER-306 is fixed we can upgrade the plugin again --- parent/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index fdfb0dd478..a4e60cc472 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -22,7 +22,8 @@ UTF-8 1.0.0 - 3.0.0-M2 + + 3.0.0-M1 2.22.1 3.0.1 4.0.3.RELEASE From 73a1ab1e8a1a3d73e7a516030b72834558d13a15 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 20 Jan 2019 17:05:52 +0100 Subject: [PATCH 0317/1006] #1681 Do not call finaliser method on return when @MappingTarget is not a builder --- .../ap/internal/model/BeanMappingMethod.java | 35 +++++++----- .../ap/test/bugs/_1681/Issue1681Mapper.java | 25 +++++++++ .../ap/test/bugs/_1681/Issue1681Test.java | 53 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1681/Source.java | 22 ++++++++ .../mapstruct/ap/test/bugs/_1681/Target.java | 48 +++++++++++++++++ 5 files changed, 171 insertions(+), 12 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index abd488e03a..4e05ad5d60 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -27,7 +27,6 @@ import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; -import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; @@ -245,8 +244,11 @@ else if ( !method.isUpdateMethod() && ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); } - MethodReference finalizeMethod = getFinalizerMethod( - resultType == null ? method.getReturnType() : resultType ); + MethodReference finalizeMethod = null; + + if ( shouldCallFinalizerMethod( resultType == null ? method.getResultType() : resultType ) ) { + finalizeMethod = getFinalizerMethod(); + } return new BeanMappingMethod( method, @@ -261,18 +263,27 @@ else if ( !method.isUpdateMethod() && ); } - private MethodReference getFinalizerMethod(Type resultType) { - if ( method.getReturnType().isVoid() || - resultType.getEffectiveType().isAssignableTo( resultType ) ) { - return null; + private boolean shouldCallFinalizerMethod(Type resultType) { + Type returnType = method.getReturnType(); + if ( returnType.isVoid() ) { + return false; } - BuilderType builderType = resultType.getBuilderType(); - if ( builderType == null ) { - // If the mapping type is assignable to the result type this should never happen - return null; + Type mappingType = method.isUpdateMethod() ? resultType : resultType.getEffectiveType(); + if ( mappingType.isAssignableTo( returnType ) ) { + // If the mapping type can be assigned to the return type then we + // don't need a finalizer method + return false; } - return BuilderFinisherMethodResolver.getBuilderFinisherMethod( method, builderType, ctx ); + return returnType.getBuilderType() != null; + } + + private MethodReference getFinalizerMethod() { + return BuilderFinisherMethodResolver.getBuilderFinisherMethod( + method, + method.getReturnType().getBuilderType(), + ctx + ); } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Mapper.java new file mode 100644 index 0000000000..a8fcc2ec79 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Mapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1681; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1681Mapper { + + Issue1681Mapper INSTANCE = Mappers.getMapper( Issue1681Mapper.class ); + + Target update(@MappingTarget Target target, Source source); + + @Mapping(target = "builderValue", source = "value") + Target update(@MappingTarget Target.Builder targetBuilder, Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java new file mode 100644 index 0000000000..812400be04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1681; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1681") +@WithClasses({ + Issue1681Mapper.class, + Source.class, + Target.class +}) +public class Issue1681Test { + + @Test + public void shouldCompile() { + Target target = new Target( "before" ); + Source source = new Source(); + source.setValue( "after" ); + + Target updatedTarget = Issue1681Mapper.INSTANCE.update( target, source ); + + assertThat( updatedTarget ).isSameAs( target ); + assertThat( updatedTarget.getValue() ).isEqualTo( "after" ); + } + + @Test + public void shouldCompileWithBuilder() { + Target.Builder targetBuilder = Target.builder(); + targetBuilder.builderValue( "before" ); + Source source = new Source(); + source.setValue( "after" ); + + Target updatedTarget = Issue1681Mapper.INSTANCE.update( targetBuilder, source ); + + assertThat( updatedTarget ).isNotNull(); + assertThat( updatedTarget.getValue() ).isEqualTo( "after" ); + assertThat( targetBuilder.getBuilderValue() ).isEqualTo( "after" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Source.java new file mode 100644 index 0000000000..384dbcca1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1681; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Target.java new file mode 100644 index 0000000000..5a392e1968 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Target.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1681; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String builderValue; + + public String getBuilderValue() { + return builderValue; + } + + public Builder builderValue(String builderValue) { + this.builderValue = builderValue; + return this; + } + + public Target build() { + return new Target( builderValue ); + } + } +} From abd1cfb6a18cf13a055f2ea9d4c6fc6118129779 Mon Sep 17 00:00:00 2001 From: Andres Jose Sebastian Rincon Gonzalez Date: Tue, 22 Jan 2019 16:49:30 -0500 Subject: [PATCH 0318/1006] #1695 update gradle installation --- .../mapstruct-reference-guide.asciidoc | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index d371e310b7..782e47a313 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -115,7 +115,7 @@ It will not work with older versions. Add the following to your Gradle build file in order to enable MapStruct: -.Gradle configuration +.Gradle configuration (3.4 and later) ==== [source, groovy, linenums] [subs="verbatim,attributes"] @@ -123,7 +123,7 @@ Add the following to your Gradle build file in order to enable MapStruct: ... plugins { ... - id 'net.ltgt.apt' version '0.15' + id 'net.ltgt.apt' version '0.20' } // You can integrate with your IDEs. @@ -133,9 +133,36 @@ apply plugin: 'net.ltgt.apt-eclipse' dependencies { ... - compile "org.mapstruct:mapstruct:${mapstructVersion}" + implementation "org.mapstruct:mapstruct:${mapstructVersion}" + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + // If you are using mapstruct in test code + testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" +} +... +---- +==== +.Gradle (3.3 and older) +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- +... +plugins { + ... + id 'net.ltgt.apt' version '0.20' +} + +// You can integrate with your IDEs. +// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides +apply plugin: 'net.ltgt.apt-idea' +apply plugin: 'net.ltgt.apt-eclipse' + +dependencies { + ... + compile "org.mapstruct:mapstruct:${mapstructVersion}" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + // If you are using mapstruct in test code testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" } From 57caee250f0e4ee0ac50083d7e993a3c011eb3be Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 27 Jan 2019 21:09:44 +0100 Subject: [PATCH 0319/1006] #1685 completing nullvaluepropertymappingstrategy (#1697) --- .../org/mapstruct/NullValueCheckStrategy.java | 5 + .../NullValuePropertyMappingStrategy.java | 10 +- .../mapstruct-reference-guide.asciidoc | 17 +- .../model/CollectionAssignmentBuilder.java | 6 +- .../ap/internal/model/PropertyMapping.java | 50 +++- .../model/assignment/ArrayCopyWrapper.java | 16 +- .../model/assignment/SetterWrapper.java | 62 +++-- .../model/assignment/UpdateWrapper.java | 23 +- .../model/assignment/UpdateWrapper.ftl | 4 +- .../ap/internal/model/macro/CommonMacros.ftl | 14 +- .../ap/test/bugs/_1685/ContactDataDTO.java | 56 ++++ .../ap/test/bugs/_1685/Issue1685Test.java | 117 +++++++++ .../mapstruct/ap/test/bugs/_1685/User.java | 68 +++++ .../mapstruct/ap/test/bugs/_1685/UserDTO.java | 27 ++ .../ap/test/bugs/_1685/UserMapper.java | 44 ++++ .../NestedSimpleBeansMappingTest.java | 2 +- .../ChartEntryToArtistUpdate.java | 6 +- .../CustomerDefaultMapper.java | 2 +- .../ap/test/bugs/_1685/UserMapperImpl.java | 241 ++++++++++++++++++ .../UserDtoUpdateMapperSmartImpl.java | 12 + .../nestedbeans/mixed/FishTankMapperImpl.java | 20 +- .../ArtistToChartEntryImpl.java | 30 +-- .../ChartEntryToArtistImpl.java | 25 +- 23 files changed, 739 insertions(+), 118 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/ContactDataDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/User.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java index 8d5b53c005..446b879d92 100644 --- a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -10,6 +10,11 @@ * * Note: This strategy is not in effect when the a specific source presence check method is defined * in the service provider interface (SPI). + *

      + * Note: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder + * as target accessor see {@link CollectionMappingStrategy}, MapStruct will always generate a source property null + * check, regardless the value of the {@link NullValueCheckStrategy} to avoid addition of {@code null} to the target + * collection or map. * * @author Sean Huang */ diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index c9182938f8..6db84814ce 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -12,9 +12,15 @@ * Precedence is arranged in the reverse order. So {@link Mapping} will override {@link BeanMapping}, will * overide {@link Mapper} * - * The enum only applies to update method: methods that update a pre-existing target (annotated with + * The enum only applies to update methods: methods that update a pre-existing target (annotated with * {@code @}{@link MappingTarget}). * + *

      + * Note: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder + * as target accessor see {@link CollectionMappingStrategy}, MapStruct will always generate a source property + * null check, regardless the value of the {@link NullValuePropertyMappingStrategy} to avoid addition of {@code null} + * to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. + * * @author Sjaak Derksen * @since 1.3 */ @@ -27,6 +33,8 @@ public enum NullValuePropertyMappingStrategy { /** * If a source bean property equals {@code null} the target bean property will be set to its default value. + * Make sure that a {@link Mapping#defaultValue()} is defined if no empty constructor is available on + * the default value. */ SET_TO_DEFAULT, diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 782e47a313..3c1ea56490 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2138,12 +2138,22 @@ MapStruct offers control over the property to set in an `@MappingTarget` annotat By default the source property will be set to null. However: -1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values (`Object`, `ArrayList`, `HashMap`). +1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. For `List` MapStruct generates an `ArrayList`, for `Map` mapstruct generates a `HashMap`. 2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. The strategy works in a hierarchical fashion. Setting `Mapping#nullValuePropertyMappingStrategy` on mapping level will override `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. +[NOTE] +==== +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property +null check, regardless the value of the `NullValuePropertyMappingStrategy` to avoid addition of `null` to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. +==== + +[TIP] +==== +`NullValuePropertyMappingStrategy` also applies when the presense checker returns `not present`. +==== [[checking-source-property-for-null-arguments]] === Controlling checking result for 'null' properties in bean mapping @@ -2171,6 +2181,11 @@ Some frameworks generate bean properties that have a source presence checker. Of The source presence checker name can be changed in the MapStruct service provider interface (SPI). It can also be deactivated in this way. ==== +[NOTE] +==== +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property +null check, regardless the value of the `NullValueheckStrategy` to avoid addition of `null` to the target collection or map. +==== [[exceptions]] === Exceptions diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index dcef911e89..ad9defb9d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -21,6 +21,9 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; + /** * A builder that is used for creating an assignment to a collection. * @@ -149,7 +152,8 @@ public Assignment build() { PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), targetType, true, - nvpms + nvpms == SET_TO_NULL && !targetType.isPrimitive(), + nvpms == SET_TO_DEFAULT ); } else if ( method.isUpdateMethod() && !targetImmutable ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 478cd76ae8..e44c4d9a30 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -49,7 +49,8 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; @@ -285,10 +286,12 @@ public PropertyMapping build() { // null value mapping strategy this.nvms = mapperConfiguration.getNullValueMappingStrategy(); - // null value property mapping strategy (determine true value based on hierarchy) - NullValuePropertyMappingStrategyPrism nvpmsBean = - beanMapping != null ? beanMapping.getNullValuePropertyMappingStrategy() : null; - this.nvpms = mapperConfiguration.getNullValuePropertyMappingStrategy( nvpmsBean, nvpms ); + // for update methods: determine null value property mapping strategy (determine value based on hierarchy) + if ( method.isUpdateMethod() ) { + NullValuePropertyMappingStrategyPrism nvpmsBean = + beanMapping != null ? beanMapping.getNullValuePropertyMappingStrategy() : null; + this.nvpms = mapperConfiguration.getNullValuePropertyMappingStrategy( nvpmsBean, nvpms ); + } // handle source this.rightHandSide = getSourceRHS( sourceReference ); @@ -463,14 +466,28 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { return new UpdateWrapper( rhs, method.getThrownTypes(), - factory, isFieldAssignment(), + factory, + isFieldAssignment(), targetType, !rhs.isSourceReferenceParameter(), - nvpms + nvpms == SET_TO_NULL && !targetType.isPrimitive(), + nvpms == SET_TO_DEFAULT ); } else { - return new SetterWrapper( rhs, method.getThrownTypes(), nvcs, isFieldAssignment(), targetType ); + boolean includeSourceNullCheck = SetterWrapper.doSourceNullCheck( rhs, nvcs, nvpms, targetType ); + if ( !includeSourceNullCheck ) { + // solution for #834 introduced a local var and null check for nested properties always. + // however, a local var is not needed if there's no need to check for null. + rhs.setSourceLocalVarName( null ); + } + return new SetterWrapper( + rhs, + method.getThrownTypes(), + isFieldAssignment(), + includeSourceNullCheck, + includeSourceNullCheck && nvpms == SET_TO_NULL && !targetType.isPrimitive(), + nvpms == SET_TO_DEFAULT ); } } @@ -488,7 +505,14 @@ else if ( result.getSourceType().isStreamType() ) { } else { // Possibly adding null to a target collection. So should be surrounded by an null check. - result = new SetterWrapper( result, method.getThrownTypes(), ALWAYS, isFieldAssignment(), targetType ); + // TODO: what triggers this else branch? Should nvcs, nvpms be applied? + result = new SetterWrapper( result, + method.getThrownTypes(), + isFieldAssignment(), + true, + nvpms == SET_TO_NULL && !targetType.isPrimitive(), + nvpms == SET_TO_DEFAULT + ); } return result; } @@ -517,8 +541,9 @@ private Assignment assignToArray(Type targetType, Assignment rightHandSide) { targetPropertyName, arrayType, targetType, - isFieldAssignment() - ); + isFieldAssignment(), + nvpms == SET_TO_NULL && !targetType.isPrimitive(), + nvpms == SET_TO_DEFAULT ); return assignment; } @@ -875,7 +900,8 @@ public PropertyMapping build() { isFieldAssignment(), targetType, false, - null ); + false, + false ); } else { assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index 74549bd2e8..4f70e4ec75 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -20,16 +20,22 @@ public class ArrayCopyWrapper extends AssignmentWrapper { private final Type arraysType; private final Type targetType; + private final boolean setExplicitlyToNull; + private final boolean setExplicitlyToDefault; public ArrayCopyWrapper(Assignment rhs, String targetPropertyName, Type arraysType, Type targetType, - boolean fieldAssignment) { + boolean fieldAssignment, + boolean setExplicitlyToNull, + boolean setExplicitlyToDefault) { super( rhs, fieldAssignment ); this.arraysType = arraysType; this.targetType = targetType; rhs.setSourceLocalVarName( rhs.createLocalVarName( targetPropertyName ) ); + this.setExplicitlyToDefault = setExplicitlyToDefault; + this.setExplicitlyToNull = setExplicitlyToNull; } @Override @@ -44,4 +50,12 @@ public Set getImportTypes() { public boolean isIncludeSourceNullCheck() { return true; } + + public boolean isSetExplicitlyToNull() { + return setExplicitlyToNull; + } + + public boolean isSetExplicitlyToDefault() { + return setExplicitlyToDefault; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index b4653dbb2e..3d8de9fd57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -11,8 +11,11 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; +import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.IGNORE; +import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; /** * Wraps the assignment in a target setter. @@ -23,22 +26,29 @@ public class SetterWrapper extends AssignmentWrapper { private final List thrownTypesToExclude; private final boolean includeSourceNullCheck; + private final boolean setExplicitlyToNull; + private final boolean setExplicitlyToDefault; public SetterWrapper(Assignment rhs, List thrownTypesToExclude, - NullValueCheckStrategyPrism nvms, boolean fieldAssignment, - Type targetType) { + boolean includeSourceNullCheck, + boolean setExplicitlyToNull, + boolean setExplicitlyToDefault) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; - this.includeSourceNullCheck = includeSourceNullCheck( rhs, nvms, targetType ); + this.includeSourceNullCheck = includeSourceNullCheck; + this.setExplicitlyToDefault = setExplicitlyToDefault; + this.setExplicitlyToNull = setExplicitlyToNull; } public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment ) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.includeSourceNullCheck = false; + this.setExplicitlyToNull = false; + this.setExplicitlyToDefault = false; } @Override @@ -55,30 +65,40 @@ public List getThrownTypes() { return result; } + public boolean isSetExplicitlyToNull() { + return setExplicitlyToNull; + } + + public boolean isSetExplicitlyToDefault() { + return setExplicitlyToDefault; + } + public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } - /** - * Wraps the assignment in a target setter. include a null check when - * - * - Not if source is the parameter iso property, because the null check is than handled by the bean mapping - * - Not when source is primitive, you can't null check a primitive - * - The source property is fed to a conversion somehow before its assigned to the target - * - The user decided to ALLWAYS include a null check - * - When there's a source local variable name defined (e.g. nested source properties) - * - TODO: The last one I forgot..? - * - * @param rhs the source righthand side - * @param nvms null value check strategy - * @param targetType the target type - * - * @return include a null check - */ - private boolean includeSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvms, Type targetType) { + /** + * Wraps the assignment in a target setter. include a null check when + * + * - Not if source is the parameter iso property, because the null check is than handled by the bean mapping + * - Not when source is primitive, you can't null check a primitive + * - The source property is fed to a conversion somehow before its assigned to the target + * - The user decided to ALLWAYS include a null check + * + * @param rhs the source righthand side + * @param nvcs null value check strategy + * @param nvpms null value property mapping strategy + * @param targetType the target type + * + * @return include a null check + */ + public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvcs, + NullValuePropertyMappingStrategyPrism nvpms, Type targetType) { return !rhs.isSourceReferenceParameter() && !rhs.getSourceType().isPrimitive() - && (ALWAYS == nvms || rhs.getType().isConverted() || rhs.getSourceLocalVarName() != null + && (ALWAYS == nvcs + || SET_TO_DEFAULT == nvpms || IGNORE == nvpms + || rhs.getType().isConverted() || (rhs.getType().isDirect() && targetType.isPrimitive())); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index 8176f6a8fc..dede031456 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -12,10 +12,6 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; - -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; /** * Wraps the assignment in a target setter. @@ -28,8 +24,8 @@ public class UpdateWrapper extends AssignmentWrapper { private final Assignment factoryMethod; private final Type targetImplementationType; private final boolean includeSourceNullCheck; - private final boolean includeExplicitNullWhenSourceIsNull; - private final boolean mapNullToDefault; + private final boolean setExplicitlyToNull; + private final boolean setExplicitlyToDefault; public UpdateWrapper( Assignment decoratedAssignment, List thrownTypesToExclude, @@ -37,14 +33,15 @@ public UpdateWrapper( Assignment decoratedAssignment, boolean fieldAssignment, Type targetType, boolean includeSourceNullCheck, - NullValuePropertyMappingStrategyPrism nvpms) { + boolean setExplicitlyToNull, + boolean setExplicitlyToDefault ) { super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; this.targetImplementationType = determineImplType( factoryMethod, targetType ); this.includeSourceNullCheck = includeSourceNullCheck; - this.mapNullToDefault = nvpms == SET_TO_DEFAULT; - this.includeExplicitNullWhenSourceIsNull = nvpms == SET_TO_NULL; + this.setExplicitlyToDefault = setExplicitlyToDefault; + this.setExplicitlyToNull = setExplicitlyToNull; } private static Type determineImplType(Assignment factoryMethod, Type targetType) { @@ -97,11 +94,11 @@ public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } - public boolean isIncludeExplicitNullWhenSourceIsNull() { - return includeExplicitNullWhenSourceIsNull; + public boolean isSetExplicitlyToNull() { + return setExplicitlyToNull; } - public boolean isMapNullToDefault() { - return mapNullToDefault; + public boolean isSetExplicitlyToDefault() { + return setExplicitlyToDefault; } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index bdcb438d08..58416fc63b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -14,9 +14,9 @@ <@assignToExistingTarget/> <@lib.handleAssignment/>; } - <#if mapNullToDefault || includeExplicitNullWhenSourceIsNull> + <#if setExplicitlyToDefault || setExplicitlyToNull> else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; } <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 7f4d3bb862..8fe5c44fa6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -30,12 +30,18 @@ <#-- local macro related to handleSourceReferenceNullCheck + note: the <#elseif setExplicitlyToDefault || setExplicitlyToNull> is only relevant for update mappings + the default value takes precedence --> <#macro elseDefaultAssignment> <#if ext.defaultValueAssignment?? > else { <@handeDefaultAssigment/> } + <#elseif setExplicitlyToDefault || setExplicitlyToNull> + else { + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; + } <#-- @@ -142,7 +148,7 @@ Performs a default assignment with a default value. <#if factoryMethod??> <@includeModel object=factoryMethod targetType=ext.targetType/> <#else> - new <@constructTargetObject/>() + <@constructTargetObject/> <#-- @@ -152,9 +158,11 @@ Performs a default assignment with a default value. --> <#macro constructTargetObject><@compress single_line=true> <#if ext.targetType.implementationType??> - <@includeModel object=ext.targetType.implementationType/> + new <@includeModel object=ext.targetType.implementationType/>() + <#elseif ext.targetType.arrayType> + new <@includeModel object=ext.targetType.componentType/>[0] <#else> - <@includeModel object=ext.targetType/> + new <@includeModel object=ext.targetType/>() <#-- diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/ContactDataDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/ContactDataDTO.java new file mode 100644 index 0000000000..1d3fe69dfa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/ContactDataDTO.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +import java.util.List; + +public class ContactDataDTO { + private String email; + private String phone; + private String address; + private List preferences; + private String[] settings; + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getPreferences() { + return preferences; + } + + public void setPreferences(List preferences) { + this.preferences = preferences; + } + + public String[] getSettings() { + return settings; + } + + public void setSettings(String[] settings) { + this.settings = settings; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java new file mode 100644 index 0000000000..5bff62f4c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java @@ -0,0 +1,117 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1685") +@WithClasses({ + User.class, + UserDTO.class, + UserMapper.class, + ContactDataDTO.class +}) +public class Issue1685Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + UserMapper.class + ); + + @Test + public void testSetToNullWhenNVPMSSetToNull() { + + User target = new User(); + target.setAddress( "address" ); + target.setEmail( "email" ); + target.setName( "name" ); + target.setPhone( 12345 ); + target.addPreference( "preference" ); + target.setSettings( new String[]{ "test" } ); + + UserDTO source = new UserDTO(); + source.setContactDataDTO( new ContactDataDTO() ); + source.getContactDataDTO().setAddress( "newAddress" ); + source.getContactDataDTO().setEmail( null ); + source.getContactDataDTO().setPhone( null ); + source.setName( null ); + + UserMapper.INSTANCE.updateUserFromUserDTO( source, target ); + + assertThat( target.getAddress() ).isEqualTo( "newAddress" ); + assertThat( target.getEmail() ).isNull(); + assertThat( target.getPhone() ).isNull(); + assertThat( target.getName() ).isNull(); + assertThat( target.getPreferences() ).containsOnly( "preference" ); + assertThat( target.getSettings() ).isNull(); + } + + @Test + public void testIgnoreWhenNVPMSIgnore() { + + User target = new User(); + target.setAddress( "address" ); + target.setEmail( "email" ); + target.setName( "name" ); + target.setPhone( 12345 ); + target.addPreference( "preference" ); + target.setSettings( new String[]{ "test" } ); + + UserDTO source = new UserDTO(); + source.setContactDataDTO( new ContactDataDTO() ); + source.getContactDataDTO().setAddress( "newAddress" ); + source.getContactDataDTO().setEmail( null ); + source.getContactDataDTO().setPhone( null ); + source.setName( null ); + + UserMapper.INSTANCE.updateUserFromUserAndIgnoreDTO( source, target ); + + assertThat( target.getAddress() ).isEqualTo( "newAddress" ); + assertThat( target.getEmail() ).isEqualTo( "email" ); + assertThat( target.getPhone() ).isEqualTo( 12345 ); + assertThat( target.getName() ).isEqualTo( "name" ); + assertThat( target.getPreferences() ).containsOnly( "preference" ); + assertThat( target.getSettings() ).containsExactly( "test" ); + } + + @Test + public void testSetToDefaultWhenNVPMSSetToDefault() { + + User target = new User(); + target.setAddress( "address" ); + target.setEmail( "email" ); + target.setName( "name" ); + target.setPhone( 12345 ); + target.addPreference( "preference" ); + target.setSettings( new String[]{ "test" } ); + + UserDTO source = new UserDTO(); + source.setContactDataDTO( new ContactDataDTO() ); + source.getContactDataDTO().setAddress( "newAddress" ); + source.getContactDataDTO().setEmail( null ); + source.getContactDataDTO().setPhone( null ); + source.setName( null ); + + UserMapper.INSTANCE.updateUserFromUserAndDefaultDTO( source, target ); + + assertThat( target.getAddress() ).isEqualTo( "newAddress" ); + assertThat( target.getEmail() ).isEqualTo( "" ); + assertThat( target.getPhone() ).isEqualTo( 0 ); + assertThat( target.getName() ).isEqualTo( "" ); + assertThat( target.getPreferences() ).containsOnly( "preference" ); + assertThat( target.getSettings() ).isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/User.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/User.java new file mode 100644 index 0000000000..3216465fc4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/User.java @@ -0,0 +1,68 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +import java.util.ArrayList; +import java.util.List; + +public class User { + private String name; + private String email; + private Integer phone; + private String address; + private List preferences = new ArrayList<>( ); + private String[] settings; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Integer getPhone() { + return phone; + } + + public void setPhone(Integer phone) { + this.phone = phone; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public void addPreference(String preference) { + preferences.add( preference ); + } + + public List getPreferences() { + return preferences; + } + + public String[] getSettings() { + return settings; + } + + public void setSettings(String[] settings) { + this.settings = settings; + } +} + + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserDTO.java new file mode 100644 index 0000000000..0ea035ee87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserDTO.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +public class UserDTO { + private String name; + private ContactDataDTO contactDataDTO; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ContactDataDTO getContactDataDTO() { + return contactDataDTO; + } + + public void setContactDataDTO(ContactDataDTO contactDataDTO) { + this.contactDataDTO = contactDataDTO; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java new file mode 100644 index 0000000000..10ed334c0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +import org.mapstruct.BeanMapping; +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper( collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED ) +public interface UserMapper { + + UserMapper INSTANCE = Mappers.getMapper( UserMapper.class ); + + @Mappings({ + @Mapping(source = "email", target = "contactDataDTO.email"), + @Mapping(source = "phone", target = "contactDataDTO.phone"), + @Mapping(source = "address", target = "contactDataDTO.address"), + @Mapping(source = "preferences", target = "contactDataDTO.preferences"), + @Mapping(source = "settings", target = "contactDataDTO.settings") + }) + UserDTO userToUserDTO(User user); + + @InheritInverseConfiguration + void updateUserFromUserDTO(UserDTO userDTO, @MappingTarget User user); + + @InheritInverseConfiguration + @BeanMapping( nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE ) + void updateUserFromUserAndIgnoreDTO(UserDTO userDTO, @MappingTarget User user); + + @InheritInverseConfiguration + @BeanMapping( nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT ) + @Mapping( target = "phone", source = "contactDataDTO.phone", defaultValue = "0" ) + void updateUserFromUserAndDefaultDTO(UserDTO userDTO, @MappingTarget User user); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 847fd100ff..08c5e2ec17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -98,7 +98,7 @@ public void shouldMapUpdateNestedBeans() { // result assertThat( smartMapping.getName() ).isEqualTo( user.getName() ); assertThat( smartMapping.getCar().getYear() ).isEqualTo( user.getCar().getYear() ); - assertThat( smartMapping.getCar().getName() ).isEqualTo( "Toyota" ); + assertThat( smartMapping.getCar().getName() ).isNull(); assertThat( user.getCar().getName() ).isNull(); assertWheels( smartMapping.getCar().getWheels(), user.getCar().getWheels() ); assertCar( smartMapping.getSecondCar(), user.getSecondCar() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java index 1121e45828..a65bfde8db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java @@ -14,6 +14,7 @@ import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; import org.mapstruct.factory.Mappers; @@ -21,7 +22,10 @@ /** * @author Sjaak Derksen */ -@Mapper( nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS ) +@Mapper( + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE +) public abstract class ChartEntryToArtistUpdate { public static final ChartEntryToArtistUpdate MAPPER = Mappers.getMapper( ChartEntryToArtistUpdate.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java index 019327ede9..362a129991 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java @@ -19,7 +19,7 @@ public interface CustomerDefaultMapper { @Mapping(source = "address", target = "homeDTO.addressDTO") void mapCustomer(Customer customer, @MappingTarget UserDTO userDTO); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(source = "houseNumber", target = "houseNo", defaultValue = "0") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java new file mode 100644 index 0000000000..9c62462f53 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java @@ -0,0 +1,241 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1685; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2019-01-27T12:40:32+0100", + comments = "version: , compiler: Eclipse JDT (Batch) 1.2.100.v20160418-1457, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class UserMapperImpl implements UserMapper { + + @Override + public UserDTO userToUserDTO(User user) { + if ( user == null ) { + return null; + } + + UserDTO userDTO = new UserDTO(); + + userDTO.setContactDataDTO( userToContactDataDTO( user ) ); + userDTO.setName( user.getName() ); + + return userDTO; + } + + @Override + public void updateUserFromUserDTO(UserDTO userDTO, User user) { + if ( userDTO == null ) { + return; + } + + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + } + else { + user.setSettings( null ); + } + if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { + for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + user.addPreference( contactDataDTOPreference ); + } + } + user.setAddress( userDTOContactDataDTOAddress( userDTO ) ); + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); + } + else { + user.setPhone( null ); + } + user.setEmail( userDTOContactDataDTOEmail( userDTO ) ); + user.setName( userDTO.getName() ); + } + + @Override + public void updateUserFromUserAndIgnoreDTO(UserDTO userDTO, User user) { + if ( userDTO == null ) { + return; + } + + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + } + if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { + for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + user.addPreference( contactDataDTOPreference ); + } + } + String address = userDTOContactDataDTOAddress( userDTO ); + if ( address != null ) { + user.setAddress( address ); + } + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); + } + String email = userDTOContactDataDTOEmail( userDTO ); + if ( email != null ) { + user.setEmail( email ); + } + if ( userDTO.getName() != null ) { + user.setName( userDTO.getName() ); + } + } + + @Override + public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { + if ( userDTO == null ) { + return; + } + + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + } + else { + user.setSettings( new String[0] ); + } + if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { + for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + user.addPreference( contactDataDTOPreference ); + } + } + String address = userDTOContactDataDTOAddress( userDTO ); + if ( address != null ) { + user.setAddress( address ); + } + else { + user.setAddress( new String() ); + } + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); + } + else { + user.setPhone( 0 ); + } + String email = userDTOContactDataDTOEmail( userDTO ); + if ( email != null ) { + user.setEmail( email ); + } + else { + user.setEmail( new String() ); + } + if ( userDTO.getName() != null ) { + user.setName( userDTO.getName() ); + } + else { + user.setName( new String() ); + } + } + + protected ContactDataDTO userToContactDataDTO(User user) { + if ( user == null ) { + return null; + } + + ContactDataDTO contactDataDTO = new ContactDataDTO(); + + if ( user.getPhone() != null ) { + contactDataDTO.setPhone( String.valueOf( user.getPhone() ) ); + } + String[] settings = user.getSettings(); + if ( settings != null ) { + contactDataDTO.setSettings( Arrays.copyOf( settings, settings.length ) ); + } + List list = user.getPreferences(); + if ( list != null ) { + contactDataDTO.setPreferences( new ArrayList( list ) ); + } + contactDataDTO.setAddress( user.getAddress() ); + contactDataDTO.setEmail( user.getEmail() ); + + return contactDataDTO; + } + + private String[] userDTOContactDataDTOSettings(UserDTO userDTO) { + if ( userDTO == null ) { + return null; + } + ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); + if ( contactDataDTO == null ) { + return null; + } + String[] settings = contactDataDTO.getSettings(); + if ( settings == null ) { + return null; + } + return settings; + } + + private List userDTOContactDataDTOPreferences(UserDTO userDTO) { + if ( userDTO == null ) { + return null; + } + ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); + if ( contactDataDTO == null ) { + return null; + } + List preferences = contactDataDTO.getPreferences(); + if ( preferences == null ) { + return null; + } + return preferences; + } + + private String userDTOContactDataDTOAddress(UserDTO userDTO) { + if ( userDTO == null ) { + return null; + } + ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); + if ( contactDataDTO == null ) { + return null; + } + String address = contactDataDTO.getAddress(); + if ( address == null ) { + return null; + } + return address; + } + + private String userDTOContactDataDTOPhone(UserDTO userDTO) { + if ( userDTO == null ) { + return null; + } + ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); + if ( contactDataDTO == null ) { + return null; + } + String phone = contactDataDTO.getPhone(); + if ( phone == null ) { + return null; + } + return phone; + } + + private String userDTOContactDataDTOEmail(UserDTO userDTO) { + if ( userDTO == null ) { + return null; + } + ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); + if ( contactDataDTO == null ) { + return null; + } + String email = contactDataDTO.getEmail(); + if ( email == null ) { + return null; + } + return email; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java index c503c8a2ba..548d236e57 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/UserDtoUpdateMapperSmartImpl.java @@ -25,6 +25,9 @@ public void userToUserDto(UserDto userDto, User user) { if ( user.getName() != null ) { userDto.setName( user.getName() ); } + else { + userDto.setName( null ); + } if ( user.getCar() != null ) { if ( userDto.getCar() == null ) { userDto.setCar( new CarDto() ); @@ -88,6 +91,9 @@ protected void carToCarDto(Car car, CarDto mappingTarget) { if ( car.getName() != null ) { mappingTarget.setName( car.getName() ); } + else { + mappingTarget.setName( null ); + } mappingTarget.setYear( car.getYear() ); if ( mappingTarget.getWheels() != null ) { List list = wheelListToWheelDtoList( car.getWheels() ); @@ -133,6 +139,9 @@ protected void roofToRoofDto(Roof roof, RoofDto mappingTarget) { if ( roof.getType() != null ) { mappingTarget.setType( roofTypeToExternalRoofType( roof.getType() ) ); } + else { + mappingTarget.setType( null ); + } } protected void houseToHouseDto(House house, HouseDto mappingTarget) { @@ -143,6 +152,9 @@ protected void houseToHouseDto(House house, HouseDto mappingTarget) { if ( house.getName() != null ) { mappingTarget.setName( house.getName() ); } + else { + mappingTarget.setName( null ); + } mappingTarget.setYear( house.getYear() ); if ( house.getRoof() != null ) { if ( mappingTarget.getRoof() == null ) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 570fae4a76..5716b231e1 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -42,10 +42,7 @@ public FishTankDto map(FishTank source) { fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); - Ornament ornament = sourceInteriorOrnament( source ); - if ( ornament != null ) { - fishTankDto.setOrnament( ornamentToOrnamentDto( ornament ) ); - } + fishTankDto.setOrnament( ornamentToOrnamentDto( sourceInteriorOrnament( source ) ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); @@ -63,10 +60,7 @@ public FishTankDto mapAsWell(FishTank source) { fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setMaterial( fishTankToMaterialDto1( source ) ); fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); - Ornament ornament = sourceInteriorOrnament( source ); - if ( ornament != null ) { - fishTankDto.setOrnament( ornamentToOrnamentDto( ornament ) ); - } + fishTankDto.setOrnament( ornamentToOrnamentDto( sourceInteriorOrnament( source ) ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); @@ -84,10 +78,7 @@ public FishTank map(FishTankDto source) { fishTank.setFish( fishDtoToFish( source.getFish() ) ); fishTank.setQuality( waterQualityDtoToWaterQuality( source.getQuality() ) ); fishTank.setInterior( fishTankDtoToInterior( source ) ); - MaterialTypeDto materialType = sourceMaterialMaterialType( source ); - if ( materialType != null ) { - fishTank.setMaterial( materialTypeDtoToMaterialType( materialType ) ); - } + fishTank.setMaterial( materialTypeDtoToMaterialType( sourceMaterialMaterialType( source ) ) ); fishTank.setPlant( waterPlantDtoToWaterPlant( source.getPlant() ) ); fishTank.setName( source.getName() ); @@ -264,10 +255,7 @@ protected WaterQualityReport waterQualityReportDtoToWaterQualityReport(WaterQual WaterQualityReport waterQualityReport = new WaterQualityReport(); - String name = waterQualityReportDtoOrganisationName( waterQualityReportDto ); - if ( name != null ) { - waterQualityReport.setOrganisationName( name ); - } + waterQualityReport.setOrganisationName( waterQualityReportDtoOrganisationName( waterQualityReportDto ) ); waterQualityReport.setVerdict( waterQualityReportDto.getVerdict() ); return waterQualityReport; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java index 81d3e29748..48d276f00b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -33,18 +33,9 @@ public ChartEntry map(Chart chart, Song song, Integer position) { } if ( song != null ) { chartEntry.setSongTitle( song.getTitle() ); - String city = songArtistLabelStudioCity( song ); - if ( city != null ) { - chartEntry.setCity( city ); - } - String name = songArtistLabelStudioName( song ); - if ( name != null ) { - chartEntry.setRecordedAt( name ); - } - String name1 = songArtistName( song ); - if ( name1 != null ) { - chartEntry.setArtistName( name1 ); - } + chartEntry.setCity( songArtistLabelStudioCity( song ) ); + chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); + chartEntry.setArtistName( songArtistName( song ) ); } if ( position != null ) { chartEntry.setPosition( position ); @@ -62,18 +53,9 @@ public ChartEntry map(Song song) { ChartEntry chartEntry = new ChartEntry(); chartEntry.setSongTitle( song.getTitle() ); - String city = songArtistLabelStudioCity( song ); - if ( city != null ) { - chartEntry.setCity( city ); - } - String name = songArtistLabelStudioName( song ); - if ( name != null ) { - chartEntry.setRecordedAt( name ); - } - String name1 = songArtistName( song ); - if ( name1 != null ) { - chartEntry.setArtistName( name1 ); - } + chartEntry.setCity( songArtistLabelStudioCity( song ) ); + chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); + chartEntry.setArtistName( songArtistName( song ) ); return chartEntry; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index 3c30a5ac86..f01afb4286 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -68,27 +68,12 @@ public ChartEntry map(Chart chart) { ChartEntry chartEntry = new ChartEntry(); - String title = chartSongTitle( chart ); - if ( title != null ) { - chartEntry.setSongTitle( title ); - } + chartEntry.setSongTitle( chartSongTitle( chart ) ); chartEntry.setChartName( chart.getName() ); - String city = chartSongArtistLabelStudioCity( chart ); - if ( city != null ) { - chartEntry.setCity( city ); - } - String name = chartSongArtistLabelStudioName( chart ); - if ( name != null ) { - chartEntry.setRecordedAt( name ); - } - String name1 = chartSongArtistName( chart ); - if ( name1 != null ) { - chartEntry.setArtistName( name1 ); - } - List positions = chartSongPositions( chart ); - if ( positions != null ) { - chartEntry.setPosition( mapPosition( positions ) ); - } + chartEntry.setCity( chartSongArtistLabelStudioCity( chart ) ); + chartEntry.setRecordedAt( chartSongArtistLabelStudioName( chart ) ); + chartEntry.setArtistName( chartSongArtistName( chart ) ); + chartEntry.setPosition( mapPosition( chartSongPositions( chart ) ) ); return chartEntry; } From 884ca2507a0fca94349b8f494fd29efeebf89b3b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 27 Jan 2019 21:21:25 +0100 Subject: [PATCH 0320/1006] Mark the Immutables BuilderProvider and AccessorNamingStrategy and the FreeBuilderAccessorNamingStrategy as Experimental (#1692) --- .../mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java | 3 +++ .../org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java | 3 +++ .../java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java | 3 +++ 3 files changed, 9 insertions(+) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java index f2d3c3402d..5b269b4b06 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java @@ -7,6 +7,8 @@ import javax.lang.model.element.ExecutableElement; +import org.mapstruct.util.Experimental; + /** * Accessor naming strategy for FreeBuilder. * FreeBuilder adds a lot of other methods that can be considered as fluent setters. Such as: @@ -24,6 +26,7 @@ * * @author Filip Hrisafov */ +@Experimental("The FreeBuilder accessor naming strategy might change in a subsequent release") public class FreeBuilderAccessorNamingStrategy extends DefaultAccessorNamingStrategy { @Override diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index cc1d66895d..abe777a1c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -7,6 +7,8 @@ import javax.lang.model.element.ExecutableElement; +import org.mapstruct.util.Experimental; + /** * Accesor naming strategy for Immutables. * The generated Immutables also have a from that works as a copy. Our default strategy considers this method @@ -14,6 +16,7 @@ * * @author Filip Hrisafov */ +@Experimental("The Immutables accessor naming strategy might change in a subsequent release") public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrategy { @Override diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index 0da8b03161..16ad797a92 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -13,6 +13,8 @@ import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; +import org.mapstruct.util.Experimental; + /** * Builder provider for Immutables. A custom provider is needed because Immutables creates an implementation of an * interface and that implementation has the builder. This implementation would try to find the type created by @@ -21,6 +23,7 @@ * * @author Filip Hrisafov */ +@Experimental("The Immutables builder provider might change in a subsequent release") public class ImmutablesBuilderProvider extends DefaultBuilderProvider { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); From 0981959ff053186c24cbb88f106a670c9ad21f9c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Mon, 28 Jan 2019 22:47:37 +0100 Subject: [PATCH 0321/1006] #1699 add sensible defaults to NullValuePropertyMapping.SET_TO_DEFAULT (#1702) --- .../NullValuePropertyMappingStrategy.java | 11 +++++++++++ .../asciidoc/mapstruct-reference-guide.asciidoc | 10 +++++++--- .../mapstruct/ap/internal/model/common/Type.java | 16 ++++++++++++++++ .../ap/internal/model/macro/CommonMacros.ftl | 2 ++ .../mapstruct/ap/test/bugs/_1685/UserMapper.java | 1 - .../ap/test/bugs/_1685/UserMapperImpl.java | 10 +++++----- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index 6db84814ce..9e06e723b6 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -33,6 +33,17 @@ public enum NullValuePropertyMappingStrategy { /** * If a source bean property equals {@code null} the target bean property will be set to its default value. + *

      + * This means: + *

        + *
      1. For {@code List} MapStruct generates an {@code ArrayList}
      2. + *
      3. For {@code Map} a {@code HashMap}
      4. + *
      5. For arrays an empty array
      6. + *
      7. For {@code String} {@code ""}
      8. + *
      9. for primitive / boxed types a representation of {@code 0} or {@code false}
      10. + *
      11. For all other objects an new instance is created, requiring an empty constructor.
      12. + *
      + *

      * Make sure that a {@link Mapping#defaultValue()} is defined if no empty constructor is available on * the default value. */ diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 3c1ea56490..46a996353f 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2134,11 +2134,15 @@ The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` [[mapping-result-for-null-properties]] === Controlling mapping result for 'null' properties in bean mappings (update mapping methods only). -MapStruct offers control over the property to set in an `@MappingTarget` annotated target bean when the source property equals `null` or the presence check method yields absent. +MapStruct offers control over the property to set in an `@MappingTarget` annotated target bean when the source property equals `null` or the presence check method results in 'absent'. -By default the source property will be set to null. However: +By default the target property will be set to null. -1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. For `List` MapStruct generates an `ArrayList`, for `Map` mapstruct generates a `HashMap`. +However: + +1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. +For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. +For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. 2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 8097b15e61..5992a687bd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -934,6 +934,22 @@ public String getNull() { throw new UnsupportedOperationException( getName() ); } + public String getSensibleDefault() { + if ( isPrimitive() ) { + return getNull(); + } + else if ( "String".equals( getName() ) ) { + return "\"\""; + } + else { + if ( isNative() ) { + // must be boxed, since primitive is already checked + return typeFactory.getType( typeUtils.unboxedType( typeMirror ) ).getNull(); + } + } + return null; + } + @Override public int hashCode() { // javadoc typemirror: "Types should be compared using the utility methods in Types. There is no guarantee diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 8fe5c44fa6..96ecd953b9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -161,6 +161,8 @@ Performs a default assignment with a default value. new <@includeModel object=ext.targetType.implementationType/>() <#elseif ext.targetType.arrayType> new <@includeModel object=ext.targetType.componentType/>[0] + <#elseif ext.targetType.sensibleDefault??> + ${ext.targetType.sensibleDefault} <#else> new <@includeModel object=ext.targetType/>() diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java index 10ed334c0a..38800dc757 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java @@ -38,7 +38,6 @@ public interface UserMapper { @InheritInverseConfiguration @BeanMapping( nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT ) - @Mapping( target = "phone", source = "contactDataDTO.phone", defaultValue = "0" ) void updateUserFromUserAndDefaultDTO(UserDTO userDTO, @MappingTarget User user); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java index 9c62462f53..811fca4a52 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java @@ -12,8 +12,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2019-01-27T12:40:32+0100", - comments = "version: , compiler: Eclipse JDT (Batch) 1.2.100.v20160418-1457, environment: Java 1.8.0_181 (Oracle Corporation)" + date = "2019-01-28T21:17:39+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" ) public class UserMapperImpl implements UserMapper { @@ -116,7 +116,7 @@ public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { user.setAddress( address ); } else { - user.setAddress( new String() ); + user.setAddress( "" ); } String phone = userDTOContactDataDTOPhone( userDTO ); if ( phone != null ) { @@ -130,13 +130,13 @@ public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { user.setEmail( email ); } else { - user.setEmail( new String() ); + user.setEmail( "" ); } if ( userDTO.getName() != null ) { user.setName( userDTO.getName() ); } else { - user.setName( new String() ); + user.setName( "" ); } } From 07c7a29adc8631ece782d319d1b17609bdd066eb Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 29 Jan 2019 20:02:23 +0100 Subject: [PATCH 0322/1006] #1700 Optimizing code for adders and stream adders (#1701) --- .../ap/internal/model/MethodReference.java | 14 +++- .../ap/internal/model/PropertyMapping.java | 2 +- .../ap/internal/model/TypeConversion.java | 14 +++- .../model/assignment/AdderWrapper.java | 18 ++++- .../model/assignment/ArrayCopyWrapper.java | 2 +- .../model/assignment/AssignmentWrapper.java | 14 +++- .../model/assignment/StreamAdderWrapper.java | 14 +++- .../WrapperForCollectionsAndMaps.java | 2 +- .../ap/internal/model/common/Assignment.java | 19 ++++- .../ap/internal/model/common/SourceRHS.java | 11 ++- .../model/assignment/AdderWrapper.ftl | 7 +- .../model/assignment/StreamAdderWrapper.ftl | 7 +- .../ap/internal/model/common/SourceRHS.ftl | 2 +- .../_1561/{java8 => }/Issue1561Mapper.java | 6 +- .../bugs/_1561/{java8 => }/Issue1561Test.java | 18 +++-- .../{java8/Target.java => NestedTarget.java} | 4 +- .../test/bugs/_1561/{java8 => }/Source.java | 2 +- .../mapstruct/ap/test/bugs/_1561/Target.java | 19 +++++ .../test/bugs/_1561/Issue1561MapperImpl.java | 77 +++++++++++++++++++ .../ap/test/bugs/_1685/UserMapperImpl.java | 19 +++-- 20 files changed, 233 insertions(+), 38 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/{java8 => }/Issue1561Mapper.java (71%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/{java8 => }/Issue1561Test.java (65%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/{java8/Target.java => NestedTarget.java} (87%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/{java8 => }/Source.java (91%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Target.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 03dd68dd57..7ef9766609 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -169,8 +169,8 @@ public Type getSourceType() { } @Override - public String createLocalVarName( String desiredName ) { - return assignment.createLocalVarName( desiredName ); + public String createUniqueVarName(String desiredName ) { + return assignment.createUniqueVarName( desiredName ); } @Override @@ -183,6 +183,16 @@ public void setSourceLocalVarName(String sourceLocalVarName) { assignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceLoopVarName() { + return assignment.getSourceLoopVarName(); + } + + @Override + public void setSourceLoopVarName(String sourceLoopVarName) { + assignment.setSourceLoopVarName( sourceLoopVarName ); + } + @Override public String getSourceParameterName() { return assignment.getSourceParameterName(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index e44c4d9a30..5dffad9d88 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -621,7 +621,7 @@ Collections. emptyList(), // create a local variable to which forged method can be assigned. String desiredName = last( sourceReference.getPropertyEntries() ).getName(); - sourceRhs.setSourceLocalVarName( sourceRhs.createLocalVarName( desiredName ) ); + sourceRhs.setSourceLocalVarName( sourceRhs.createUniqueVarName( desiredName ) ); return sourceRhs; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index cdca4a6edd..d0481cdc2d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -89,8 +89,8 @@ public Type getSourceType() { } @Override - public String createLocalVarName( String desiredName ) { - return assignment.createLocalVarName( desiredName ); + public String createUniqueVarName(String desiredName ) { + return assignment.createUniqueVarName( desiredName ); } @Override @@ -103,6 +103,16 @@ public void setSourceLocalVarName(String sourceLocalVarName) { assignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceLoopVarName() { + return assignment.getSourceLoopVarName(); + } + + @Override + public void setSourceLoopVarName(String sourceLoopVarName) { + assignment.setSourceLoopVarName( sourceLoopVarName ); + } + @Override public String getSourceParameterName() { return assignment.getSourceParameterName(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 0cb2a23024..71b5f10a9e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -33,8 +33,12 @@ public AdderWrapper( Assignment rhs, String adderIteratorName ) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; + // a method local var has been added earlier. + + + // localVar is iteratorVariable String desiredName = Nouns.singularize( adderIteratorName ); - rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); + rhs.setSourceLoopVarName( rhs.createUniqueVarName( desiredName ) ); adderType = first( getSourceType().determineTypeArguments( Collection.class ) ); } @@ -56,6 +60,18 @@ public Type getAdderType() { return adderType; } + public boolean isIncludeSourceNullCheck() { + return true; + } + + public boolean isSetExplicitlyToNull() { + return false; + } + + public boolean isSetExplicitlyToDefault() { + return false; + } + @Override public Set getImportTypes() { Set imported = new HashSet<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index 4f70e4ec75..db2c7be5ac 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -33,7 +33,7 @@ public ArrayCopyWrapper(Assignment rhs, super( rhs, fieldAssignment ); this.arraysType = arraysType; this.targetType = targetType; - rhs.setSourceLocalVarName( rhs.createLocalVarName( targetPropertyName ) ); + rhs.setSourceLocalVarName( rhs.createUniqueVarName( targetPropertyName ) ); this.setExplicitlyToDefault = setExplicitlyToDefault; this.setExplicitlyToNull = setExplicitlyToNull; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 321e1f3ece..551d20d72b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -76,6 +76,16 @@ public void setSourceLocalVarName(String sourceLocalVarName) { decoratedAssignment.setSourceLocalVarName( sourceLocalVarName ); } + @Override + public String getSourceLoopVarName() { + return decoratedAssignment.getSourceLoopVarName(); + } + + @Override + public void setSourceLoopVarName(String sourceLoopVarName) { + decoratedAssignment.setSourceLoopVarName( sourceLoopVarName ); + } + @Override public String getSourceParameterName() { return decoratedAssignment.getSourceParameterName(); @@ -92,8 +102,8 @@ public boolean isCallingUpdateMethod() { } @Override - public String createLocalVarName( String desiredName ) { - return decoratedAssignment.createLocalVarName( desiredName ); + public String createUniqueVarName(String desiredName ) { + return decoratedAssignment.createUniqueVarName( desiredName ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java index 7aabbd249b..1deff95a2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java @@ -34,7 +34,7 @@ public StreamAdderWrapper(Assignment rhs, super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; String desiredName = Nouns.singularize( targetPropertyName ); - rhs.setSourceLocalVarName( rhs.createLocalVarName( desiredName ) ); + rhs.setSourceLocalVarName( rhs.createUniqueVarName( desiredName ) ); adderType = first( getSourceType().determineTypeArguments( Stream.class ) ); } @@ -56,6 +56,18 @@ public Type getAdderType() { return adderType; } + public boolean isIncludeSourceNullCheck() { + return true; + } + + public boolean isSetExplicitlyToNull() { + return false; + } + + public boolean isSetExplicitlyToDefault() { + return false; + } + @Override public Set getImportTypes() { Set imported = new HashSet<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java index e0dbaf3893..e8b1f88457 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/WrapperForCollectionsAndMaps.java @@ -37,7 +37,7 @@ public WrapperForCollectionsAndMaps(Assignment rhs, else { this.nullCheckLocalVarType = targetType; } - this.nullCheckLocalVarName = rhs.createLocalVarName( nullCheckLocalVarType.getName() ); + this.nullCheckLocalVarName = rhs.createUniqueVarName( nullCheckLocalVarType.getName() ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index cc14e035de..3cd32c82ea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -106,7 +106,7 @@ public boolean isConverted() { * * @return the desired name, made unique in the scope of the bean mapping. */ - String createLocalVarName( String desiredName ); + String createUniqueVarName(String desiredName ); /** * See {@link #setSourceLocalVarName(java.lang.String) } @@ -131,6 +131,23 @@ public boolean isConverted() { */ void setSourceLocalVarName(String sourceLocalVarName); + /** + * See {@link #getSourceLoopVarName()} (java.lang.String) } + * + * @return loop variable (can be null if not set) + */ + String getSourceLoopVarName(); + + /** + * Replaces the sourceLocalVar or sourceReference at the call site in the assignment in the template with this + * sourceLoopVarName. + * The sourceLocalVar can subsequently be used for e.g. null checking. + * + * @param sourceLoopVarName loop variable + */ + void setSourceLoopVarName(String sourceLoopVarName); + + /** * Returns whether the type of assignment * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index fddf0a4b19..5dc5d91832 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -27,6 +27,7 @@ public class SourceRHS extends ModelElement implements Assignment { private final String sourceReference; private final Type sourceType; private String sourceLocalVarName; + private String sourceLoopVarName; private final Set existingVariableNames; private final String sourceErrorMessagePart; private final String sourcePresenceCheckerReference; @@ -69,7 +70,7 @@ public Type getSourceType() { } @Override - public String createLocalVarName(String desiredName) { + public String createUniqueVarName(String desiredName) { String result = Strings.getSafeVariableName( desiredName, existingVariableNames ); existingVariableNames.add( result ); return result; @@ -85,6 +86,14 @@ public void setSourceLocalVarName(String sourceLocalVarName) { this.sourceLocalVarName = sourceLocalVarName; } + public String getSourceLoopVarName() { + return sourceLoopVarName; + } + + public void setSourceLoopVarName(String sourceLoopVarName) { + this.sourceLoopVarName = sourceLoopVarName; + } + @Override public Set getImportTypes() { return Collections.emptySet(); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index c75942de97..361fedaa58 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -8,9 +8,10 @@ <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.AdderWrapper" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> - if ( ${sourceReference} != null ) { - for ( <@includeModel object=adderType.typeBound/> ${sourceLocalVarName} : ${sourceReference} ) { + <@lib.sourceLocalVarAssignment/> + <@lib.handleSourceReferenceNullCheck> + for ( <@includeModel object=adderType.typeBound/> ${sourceLoopVarName} : <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} ) { ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; } - } + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl index 1a308844c1..6e7683e05f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.ftl @@ -8,7 +8,8 @@ <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.StreamAdderWrapper" --> <#import "../macro/CommonMacros.ftl" as lib> <@lib.handleExceptions> - if ( ${sourceReference} != null ) { - ${sourceReference}.forEach( ${ext.targetBeanName}::${ext.targetWriteAccessorName} ); - } + <@lib.sourceLocalVarAssignment/> + <@lib.handleSourceReferenceNullCheck> + <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}.forEach( ${ext.targetBeanName}::${ext.targetWriteAccessorName} ); + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl index 7cab67b529..0b60bd39ae 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" --> -<#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file +<#if sourceLoopVarName??>${sourceLoopVarName}<#elseif sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Mapper.java similarity index 71% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Mapper.java index b50015337d..95065f5dfb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Mapper.java @@ -3,10 +3,12 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1561.java8; +package org.mapstruct.ap.test.bugs._1561; import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; /** @@ -18,7 +20,9 @@ public interface Issue1561Mapper { Issue1561Mapper INSTANCE = Mappers.getMapper( Issue1561Mapper.class ); + @Mapping( target = "nestedTarget.properties", source = "properties") Target map(Source source); + @InheritInverseConfiguration Source map(Target target); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java similarity index 65% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java index d15a53f48c..4b8e5704ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Issue1561Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java @@ -3,13 +3,15 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1561.java8; +package org.mapstruct.ap.test.bugs._1561; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +23,16 @@ @WithClasses({ Issue1561Mapper.class, Source.class, - Target.class + Target.class, + NestedTarget.class }) public class Issue1561Test { + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + Issue1561Mapper.class + ); + @Test public void shouldCorrectlyUseAdder() { @@ -34,12 +42,10 @@ public void shouldCorrectlyUseAdder() { Target target = Issue1561Mapper.INSTANCE.map( source ); - assertThat( target.getProperties() ) - .containsExactly( "first", "second" ); + assertThat( target.getNestedTarget().getProperties() ).containsExactly( "first", "second" ); Source mapped = Issue1561Mapper.INSTANCE.map( target ); - assertThat( mapped.getProperties() ) - .containsExactly( "first", "second" ); + assertThat( mapped.getProperties() ).containsExactly( "first", "second" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java index 1a46477dd3..a2f1040527 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1561.java8; +package org.mapstruct.ap.test.bugs._1561; import java.util.ArrayList; import java.util.List; @@ -12,7 +12,7 @@ /** * @author Sebastian Haberey */ -public class Target { +public class NestedTarget { private List properties = new ArrayList(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Source.java similarity index 91% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Source.java index 5f52689ce2..23195b81de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/java8/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Source.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1561.java8; +package org.mapstruct.ap.test.bugs._1561; import java.util.ArrayList; import java.util.List; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Target.java new file mode 100644 index 0000000000..29c4f28b0c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Target.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561; + +public class Target { + + private NestedTarget nestedTarget; + + public NestedTarget getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(NestedTarget nestedTarget) { + this.nestedTarget = nestedTarget; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java new file mode 100644 index 0000000000..dde54d65b7 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1561; + +import java.util.stream.Stream; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2019-01-29T19:40:52+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class Issue1561MapperImpl implements Issue1561Mapper { + + @Override + public Target map(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setNestedTarget( sourceToNestedTarget( source ) ); + + return target; + } + + @Override + public Source map(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + Stream nestedTargetProperty = targetNestedTargetProperties( target ); + if ( nestedTargetProperty != null ) { + nestedTargetProperty.forEach( source::addProperty ); + } + + return source; + } + + protected NestedTarget sourceToNestedTarget(Source source) { + if ( source == null ) { + return null; + } + + NestedTarget nestedTarget = new NestedTarget(); + + if ( source.getProperties() != null ) { + for ( String property : source.getProperties() ) { + nestedTarget.addProperty( property ); + } + } + + return nestedTarget; + } + + private Stream targetNestedTargetProperties(Target target) { + if ( target == null ) { + return null; + } + NestedTarget nestedTarget = target.getNestedTarget(); + if ( nestedTarget == null ) { + return null; + } + Stream properties = nestedTarget.getProperties(); + if ( properties == null ) { + return null; + } + return properties; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java index 811fca4a52..fcf8bc2a34 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java @@ -12,8 +12,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2019-01-28T21:17:39+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" + date = "2019-01-27T12:40:32+0100", + comments = "version: , compiler: Eclipse JDT (Batch) 1.2.100.v20160418-1457, environment: Java 1.8.0_181 (Oracle Corporation)" ) public class UserMapperImpl implements UserMapper { @@ -44,8 +44,9 @@ public void updateUserFromUserDTO(UserDTO userDTO, User user) { else { user.setSettings( null ); } - if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { - for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + List preferences = userDTOContactDataDTOPreferences( userDTO ); + if ( preferences != null ) { + for ( String contactDataDTOPreference : preferences ) { user.addPreference( contactDataDTOPreference ); } } @@ -71,8 +72,9 @@ public void updateUserFromUserAndIgnoreDTO(UserDTO userDTO, User user) { if ( settings1 != null ) { user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); } - if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { - for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + List preferences = userDTOContactDataDTOPreferences( userDTO ); + if ( preferences != null ) { + for ( String contactDataDTOPreference : preferences ) { user.addPreference( contactDataDTOPreference ); } } @@ -106,8 +108,9 @@ public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { else { user.setSettings( new String[0] ); } - if ( userDTOContactDataDTOPreferences( userDTO ) != null ) { - for ( String contactDataDTOPreference : userDTOContactDataDTOPreferences( userDTO ) ) { + List preferences = userDTOContactDataDTOPreferences( userDTO ); + if ( preferences != null ) { + for ( String contactDataDTOPreference : preferences ) { user.addPreference( contactDataDTOPreference ); } } From 2ea5dcf4008682fafa8698c5e703db0f687810bf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Feb 2019 21:38:24 +0100 Subject: [PATCH 0323/1006] Add Andres and Taras to copyright.txt --- copyright.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/copyright.txt b/copyright.txt index 99f73d1965..11a9035c9c 100644 --- a/copyright.txt +++ b/copyright.txt @@ -3,6 +3,7 @@ Alexandr Shalugin - https://github.com/shalugin Andreas Gudian - https://github.com/agudian +Andres Jose Sebastian Rincon Gonzalez - https://github.com/stianrincon Arne Seime - https://github.com/seime Christian Bandowski - https://github.com/chris922 Christian Schuster - https://github.com/chschu @@ -41,6 +42,7 @@ Sebastian Hasait - https://github.com/shasait Sean Huang - https://github.com/seanjob Sjaak Derksen - https://github.com/sjaakd Stefan May - https://github.com/osthus-sm +Taras Mychaskiw - https://github.com/twentylemon Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld From eca743310365b24ddc79085c35e1c0901f58361c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Feb 2019 09:09:17 +0100 Subject: [PATCH 0324/1006] #1694 Avoid circular dependency between model and conversion packages Remove import of SimpleConversion used in the javadoc of the BuiltIntMethod Fixes #1694 --- .../ap/internal/model/source/builtin/BuiltInMethod.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 024f63229e..783ea43a5b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -12,7 +12,6 @@ import java.util.Set; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.conversion.SimpleConversion; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; @@ -27,7 +26,7 @@ /** * Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in - * methods are used in cases where a {@link SimpleConversion} doesn't suffice, e.g. as several lines of source code or a + * methods are used in cases where a simple conversation doesn't suffice, e.g. as several lines of source code or a * try/catch block are required. * * @author Sjaak Derksen From 3c079e412aabb7afb1f11b946e6c85dd874c9777 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 10 Feb 2019 10:31:51 +0100 Subject: [PATCH 0325/1006] #1707 fix for not defining local variable in stream-iterable mapping (#1708) --- .../ap/internal/model/StreamMappingMethod.ftl | 10 +-- .../ap/test/bugs/_1707/Converter.java | 89 +++++++++++++++++++ .../ap/test/bugs/_1707/Issue1707Test.java | 32 +++++++ .../ap/test/bugs/_1707/ConverterImpl.java | 67 ++++++++++++++ 4 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Converter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index 3eab477941..f9a7309b5d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -48,11 +48,11 @@ } - <#-- A variable needs to be defined if there are before mappings and this is not exisitingInstanceMapping --> - <#assign needVarDefine = beforeMappingReferencesWithMappingTarget?has_content && !existingInstanceMapping /> + <#-- A variable needs to be defined if there are before or after mappings and this is not exisitingInstanceMapping --> + <#assign needVarDefine = (beforeMappingReferencesWithMappingTarget?has_content || afterMappingReferences?has_content) && !existingInstanceMapping /> <#if resultType.arrayType> - <#if !existingInstanceMapping && needVarDefine> + <#if needVarDefine> <#assign needVarDefine = false /> <#-- We create a null array which later will be directly assigned from the stream--> ${resultElementType}[] ${resultName} = null; @@ -67,7 +67,7 @@ <#else> <#-- Streams are immutable so we can't update them --> - <#if !existingInstanceMapping && needVarDefine> + <#if needVarDefine> <#assign needVarDefine = false /> <@iterableLocalVarDef/> ${resultName} = Stream.empty(); @@ -180,5 +180,5 @@ <#macro returnLocalVarDefOrUpdate> - <#if canReturnImmediatelly><#if returnType.name != "void">return <#elseif !needVarDefine><@iterableLocalVarDef/> ${resultName} = <#else>${resultName} = <#nested /> + <#if canReturnImmediatelly><#if returnType.name != "void">return <#elseif needVarDefine><@iterableLocalVarDef/> ${resultName} = <#else>${resultName} = <#nested /> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Converter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Converter.java new file mode 100644 index 0000000000..45659b9d6f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Converter.java @@ -0,0 +1,89 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1707; + +import java.util.Set; +import java.util.stream.Stream; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; + +@Mapper +public abstract class Converter { + + public abstract Set convert(Stream source); + + public abstract Target[] convertArray(Stream source); + + @Mapping( target = "custom", ignore = true ) + public abstract Target convert(Source source); + + @AfterMapping + public void addCustomValue(@MappingTarget Set targetList) { + targetList.forEach( t -> t.custom = true ); + } + + @AfterMapping + public void addCustomValue(@MappingTarget Target[] targetArray) { + for ( Target target : targetArray ) { + target.custom = true; + } + } + + public static final class Source { + private String text; + private int number; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + } + + public static class Target { + private String text; + private int number; + private boolean custom; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public boolean isCustom() { + return custom; + } + + public void setCustom(boolean custom) { + this.custom = custom; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java new file mode 100644 index 0000000000..5d2083312b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1707; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1707") +@WithClasses({ + Converter.class +}) +public class Issue1707Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + Converter.class + ); + + @Test + public void codeShouldBeGeneratedCorrectly() { + + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java new file mode 100644 index 0000000000..898b134188 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1707; + +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2019-02-10T09:58:11+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class ConverterImpl extends Converter { + + @Override + public Set convert(Stream source) { + if ( source == null ) { + return null; + } + + Set set = new HashSet(); + + set.addAll( source.map( source1 -> convert( source1 ) ) + .collect( Collectors.toCollection( HashSet::new ) ) + ); + + addCustomValue( set ); + + return set; + } + + @Override + public org.mapstruct.ap.test.bugs._1707.Converter.Target[] convertArray(Stream source) { + if ( source == null ) { + return null; + } + + org.mapstruct.ap.test.bugs._1707.Converter.Target[] targetTmp = null; + + targetTmp = source.map( source1 -> convert( source1 ) ) + .toArray( Target[]::new ); + + addCustomValue( targetTmp ); + + return targetTmp; + } + + @Override + public Target convert(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setText( source.getText() ); + target.setNumber( source.getNumber() ); + + return target; + } +} From 97620827031a234e0bce2b5bddacf9e77e285290 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Feb 2019 11:43:19 +0100 Subject: [PATCH 0326/1006] Use Java 8 Javadoc links --- distribution/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index 4645262fd4..c012ac81d5 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -82,7 +82,7 @@ ${basedir}/../processor/src/main/java - http://docs.oracle.com/javase/7/docs/api/ + https://docs.oracle.com/javase/8/docs/api/ MapStruct Packages MapStruct ${project.version} From 984423dfee29b15624141873680f27b31690f383 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Feb 2019 11:48:19 +0100 Subject: [PATCH 0327/1006] [maven-release-plugin] prepare release 1.3.0.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 462fe5c4db..15b985e9d0 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 48f50c7b60..c6869612c6 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index fe993959b8..8cb0d53e10 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index c012ac81d5..5d146521f2 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 3ce539793e..855a844f87 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 18082e0a03..1c86029870 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index a4e60cc472..4dcbfe7392 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final pom MapStruct Parent @@ -58,7 +58,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Final diff --git a/pom.xml b/pom.xml index 2786ef835f..fa3f71929d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.3.0.Final diff --git a/processor/pom.xml b/processor/pom.xml index eb307ffa6d..53d7d71bb5 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0-SNAPSHOT + 1.3.0.Final ../parent/pom.xml From a28f2cb9cf340056e6fe5e75be280921117e0f01 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Feb 2019 11:48:20 +0100 Subject: [PATCH 0328/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 15b985e9d0..6c908377c8 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c6869612c6..63311b5950 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8cb0d53e10..c74e0b8bb1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 5d146521f2..b404ed3cee 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 855a844f87..90c3e0b64e 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 1c86029870..135f7991f3 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 4dcbfe7392..dc28d04adb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT pom MapStruct Parent @@ -58,7 +58,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Final + HEAD diff --git a/pom.xml b/pom.xml index fa3f71929d..f9c649c168 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.3.0.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 53d7d71bb5..52d8e7efb9 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.3.0.Final + 1.4.0-SNAPSHOT ../parent/pom.xml From d282261ddf9b0c7fced7b336e41db98d8bab3202 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Feb 2019 12:28:04 +0100 Subject: [PATCH 0329/1006] Update latest release badge and update readme with 1.3.0.Final --- readme.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index 8260bcb2f4..d4c1e0d053 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.2.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.3.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -64,13 +64,13 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.2.0.Final + 1.3.0.Final ... org.mapstruct - mapstruct + mapstruct ${org.mapstruct.version} @@ -82,8 +82,8 @@ For Maven-based projects, add the following to your POM file in order to use Map maven-compiler-plugin 3.5.1 - 1.6 - 1.6 + 1.8 + 1.8 org.mapstruct @@ -115,10 +115,10 @@ apply plugin: 'net.ltgt.apt-eclipse' dependencies { ... - compile 'org.mapstruct:mapstruct:1.2.0.Final' // OR use this with Java 8 and beyond: org.mapstruct:mapstruct-jdk8:... + compile 'org.mapstruct:mapstruct:1.3.0.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final' // if you are using mapstruct in test code } ... ``` From 160549a788b5ff607ce4d855602b6b6e8d4c3576 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 10 Feb 2019 22:08:38 +0100 Subject: [PATCH 0330/1006] #1142 update documentation (#1710) * #1142 update documentation * #1142 comment --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 46a996353f..79ce0dc097 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -568,7 +568,7 @@ public interface CarMapper { The generated code of the `updateCarFromDto()` method will update the passed `Car` instance with the properties from the given `CarDto` object. There may be only one parameter marked as mapping target. Instead of `void` you may also set the method's return type to the type of the target parameter, which will cause the generated implementation to update the passed mapping target and return it as well. This allows for fluent invocations of mapping methods. -Collection- or map-typed properties of the target bean to be updated will be cleared and then populated with the values from the corresponding source collection or map. +For `CollectionMappingStrategy.ACCESSOR_ONLY` Collection- or map-typed properties of the target bean to be updated will be cleared and then populated with the values from the corresponding source collection or map. Otherwise, For `CollectionMappingStrategy.ADDER_PREFERRED` or `CollectionMappingStrategy.TARGET_IMMUTABLE` the target will not be cleared and the values will be populated immediately. [[direct-field-mappings]] === Mappings with direct field access From 23608477b7d21f184a7e9d19f38b00cf873ff97c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 12 Feb 2019 10:17:50 +0100 Subject: [PATCH 0331/1006] #1698 Skip "java.lang.Object" as intermediate result in 2 step mappings (#1712) --- .../creation/MappingResolverImpl.java | 16 ++- .../test/bugs/_1698/Erroneous1698Mapper.java | 111 ++++++++++++++++++ .../ap/test/bugs/_1698/Issue1698Test.java | 32 +++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Erroneous1698Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index fa0128a020..b45235420f 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -342,6 +342,12 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { // sourceMethod or builtIn that fits the signature B to C. Only then there is a match. If we have a match // a nested method call can be called. so C = methodY( methodX (A) ) for ( Method methodYCandidate : methodYCandidates ) { + if ( Object.class.getName() + .equals( methodYCandidate.getSourceParameters().get( 0 ).getType().getName() ) ) { + // java.lang.Object as intermediate result + continue; + } + methodRefY = resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(), targetType, true ); @@ -381,6 +387,12 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp Assignment methodRefY = null; for ( Method methodYCandidate : methodYCandidates ) { + if ( Object.class.getName() + .equals( methodYCandidate.getSourceParameters().get( 0 ).getType().getName() ) ) { + // java.lang.Object as intermediate result + continue; + } + methodRefY = resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(), targetType, true ); @@ -420,7 +432,9 @@ private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type // search the other way around for ( Method methodXCandidate : methodXCandidates ) { - if ( methodXCandidate.getMappingTargetParameter() != null ) { + if ( methodXCandidate.isUpdateMethod() || + Object.class.getName().equals( methodXCandidate.getReturnType().getFullyQualifiedName() ) ) { + // skip update methods || java.lang.Object as intermediate result continue; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Erroneous1698Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Erroneous1698Mapper.java new file mode 100644 index 0000000000..d158239778 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Erroneous1698Mapper.java @@ -0,0 +1,111 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1698; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Erroneous1698Mapper { + + Erroneous1698Mapper INSTANCE = Mappers.getMapper( Erroneous1698Mapper.class ); + + Target map(Source source); + + @Mapping(target = "value", source = "source") + Cat mapToCat(String source); + + @Mapping(target = "value", source = "source") + Dog mapToDog(String source); + + class Source { + + private String cat; + private String dog; + private String rabbit; + + public String getCat() { + return cat; + } + + public void setCat(String cat) { + this.cat = cat; + } + + public String getDog() { + return dog; + } + + public void setDog(String dog) { + this.dog = dog; + } + + public String getRabbit() { + return rabbit; + } + + public void setRabbit(String rabbit) { + this.rabbit = rabbit; + } + } + + class Target { + + private Cat cat; + private Dog dog; + private Rabbit rabbit; + + public Cat getCat() { + return cat; + } + + public void setCat(Cat cat) { + this.cat = cat; + } + + public Dog getDog() { + return dog; + } + + public void setDog(Dog dog) { + this.dog = dog; + } + + public Rabbit getRabbit() { + return rabbit; + } + + public void setRabbit(Rabbit rabbit) { + this.rabbit = rabbit; + } + } + + class Animal { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Cat extends Animal { + + } + + class Dog extends Animal { + + } + + class Rabbit extends Animal { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java new file mode 100644 index 0000000000..77f480346a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1698; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1698") +@WithClasses(Erroneous1698Mapper.class) +public class Issue1698Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Erroneous1698Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + messageRegExp = "Can't map property.*") + }) + + public void testErrorMessage() { + } +} From 60208b67afe86584dc878091fa0ec582625adaba Mon Sep 17 00:00:00 2001 From: Thibault Duperron Date: Wed, 13 Feb 2019 21:08:23 +0100 Subject: [PATCH 0332/1006] #1435 add import to MapperConfig --- .../main/java/org/mapstruct/MapperConfig.java | 10 ++++++ .../ap/internal/util/MapperConfiguration.java | 8 ++++- .../mapstruct/ap/test/bugs/_1435/Config.java | 19 +++++++++++ .../ap/test/bugs/_1435/InObject.java | 19 +++++++++++ .../ap/test/bugs/_1435/Issue1435Mapper.java | 17 ++++++++++ .../ap/test/bugs/_1435/Issue1435Test.java | 33 +++++++++++++++++++ .../ap/test/bugs/_1435/OutObject.java | 19 +++++++++++ 7 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/InObject.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/OutObject.java diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index e042d40116..079388cc42 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -44,6 +44,16 @@ */ Class[] uses() default { }; + /** + * Additional types for which an import statement is to be added to the generated mapper implementation class. + * This allows to refer to those types from within mapping expressions given via {@link Mapping#expression()}, + * {@link Mapping#defaultExpression()} or using + * their simple name rather than their fully-qualified name. + * + * @return classes to add in the imports of the generated implementation. + */ + Class[] imports() default { }; + /** * How unmapped properties of the source type of a mapping should be * reported. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 1545e115ab..cb812b53b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.util; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -97,7 +98,12 @@ public Set uses() { } public List imports() { - return mapperPrism.imports(); + List imports = new ArrayList<>(); + imports.addAll( mapperPrism.imports() ); + if ( mapperConfigPrism != null ) { + imports.addAll( mapperConfigPrism.imports() ); + } + return imports; } public ReportingPolicyPrism unmappedTargetPolicy(Options options) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Config.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Config.java new file mode 100644 index 0000000000..911cbf1f9d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Config.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1435; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; + +import java.util.Objects; + +@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG, imports = Objects.class) +public interface Config { + @Mapping(expression = "java( Objects.equals( source.getName(), \"Rainbow Dash\" ) )", target = "rainbowDash") + OutObject map(InObject source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/InObject.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/InObject.java new file mode 100644 index 0000000000..27b6fa2742 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/InObject.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1435; + +public class InObject { + + private final String name; + + public InObject(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Mapper.java new file mode 100644 index 0000000000..c98eba2ed2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Mapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1435; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper(config = Config.class) +public interface Issue1435Mapper { + + Issue1435Mapper INSTANCE = Mappers.getMapper( Issue1435Mapper.class ); + + OutObject map(InObject source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java new file mode 100644 index 0000000000..ade951f2b1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1435; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1435") +@WithClasses({ + Config.class, + Issue1435Mapper.class, + InObject.class, + OutObject.class, +}) +public class Issue1435Test { + @Test + public void mustNotSetListToNull() { + InObject source = new InObject( "Rainbow Dash" ); + + OutObject result = Issue1435Mapper.INSTANCE.map( source ); + + assertThat( result.isRainbowDash() ).isTrue(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/OutObject.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/OutObject.java new file mode 100644 index 0000000000..b3a16f2250 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/OutObject.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1435; + +public class OutObject { + + private boolean isRainbowDash; + + public boolean isRainbowDash() { + return isRainbowDash; + } + + public void setRainbowDash(boolean rainbowDash) { + isRainbowDash = rainbowDash; + } +} From 635cdbf4eaf18c728d9d403c72153a1a81d28ee7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 14 Feb 2019 22:27:43 +0100 Subject: [PATCH 0333/1006] Add Thibault to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 11a9035c9c..6757936ad1 100644 --- a/copyright.txt +++ b/copyright.txt @@ -43,6 +43,7 @@ Sean Huang - https://github.com/seanjob Sjaak Derksen - https://github.com/sjaakd Stefan May - https://github.com/osthus-sm Taras Mychaskiw - https://github.com/twentylemon +Thibault Duperron - https://github.com/Zomzog Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld From 002a8b0562aa7857928a8783f70b52c691555520 Mon Sep 17 00:00:00 2001 From: Xavier RENE-CORAIL Date: Wed, 21 Nov 2018 13:12:52 +0100 Subject: [PATCH 0334/1006] Add LGTM.com code quality badges --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index d4c1e0d053..bd180d7d6a 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,8 @@ [![Build Status](https://img.shields.io/travis/mapstruct/mapstruct.svg)](https://travis-ci.org/mapstruct/mapstruct) [![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct) [![Gitter](https://img.shields.io/gitter/room/mapstruct/mapstruct.svg)](https://gitter.im/mapstruct/mapstruct-users) +[![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/context:java) +[![Total Alerts](https://img.shields.io/lgtm/alerts/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/alerts) * [What is MapStruct?](#what-is-mapstruct) * [Requirements](#requirements) From 51bd43fc1bead66f424c9b1ce204481996d00a5d Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Mon, 25 Feb 2019 19:47:53 +0100 Subject: [PATCH 0335/1006] #1719 strange error message for selecting collection update methods (#1724) --- .../ap/internal/model/PropertyMapping.java | 11 ++- .../ap/test/bugs/_1719/Issue1719Mapper.java | 22 ++++++ .../ap/test/bugs/_1719/Issue1719Test.java | 57 +++++++++++++++ .../mapstruct/ap/test/bugs/_1719/Source.java | 23 ++++++ .../ap/test/bugs/_1719/SourceElement.java | 52 ++++++++++++++ .../mapstruct/ap/test/bugs/_1719/Target.java | 35 ++++++++++ .../ap/test/bugs/_1719/TargetElement.java | 70 +++++++++++++++++++ 7 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/SourceElement.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/TargetElement.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 5dffad9d88..2291504039 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -724,7 +724,13 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s } private Assignment forgeMapping(SourceRHS sourceRHS) { - Type sourceType = sourceRHS.getSourceType(); + Type sourceType; + if ( targetWriteAccessorType == TargetWriteAccessorType.ADDER ) { + sourceType = sourceRHS.getSourceTypeForMatching(); + } + else { + sourceType = sourceRHS.getSourceType(); + } if ( forgedNamedBased && !canGenerateAutoSubMappingBetween( sourceType, targetType ) ) { return null; } @@ -744,7 +750,8 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { // They should forge an update method only if we set the forceUpdateMethod. This is set to true, // because we are forging a Mapping for a method with multiple source parameters. // If the target type is enum, then we can't create an update method - if ( !targetType.isEnumType() && ( method.isUpdateMethod() || forceUpdateMethod ) ) { + if ( !targetType.isEnumType() && ( method.isUpdateMethod() || forceUpdateMethod ) + && targetWriteAccessorType != TargetWriteAccessorType.ADDER) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Mapper.java new file mode 100644 index 0000000000..f4ac6978f6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue1719Mapper { + + Issue1719Mapper INSTANCE = Mappers.getMapper( Issue1719Mapper.class ); + + @Mapping(target = "targetElements", source = "sourceElements") + void map(Source source, @MappingTarget Target target); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java new file mode 100644 index 0000000000..e34c790322 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1719") +@WithClasses({ + Source.class, + SourceElement.class, + Target.class, + TargetElement.class +}) +public class Issue1719Test { + + /** + * For adder methods MapStuct cannot generate an update method. MapStruct would cannot know how to remove objects + * from the child-parent relation. It cannot even assume that the the collection can be cleared at forehand. + * Therefore the only sensible choice is for MapStruct to create a create method for the target elements. + */ + @Test + @WithClasses(Issue1719Mapper.class) + public void testShouldGiveNoErrorMessage() { + Source source = new Source(); + source.getSourceElements().add( new SourceElement( 1, "jim" ) ); + source.getSourceElements().add( new SourceElement( 2, "alice" ) ); + + Target target = new Target(); + TargetElement bob = new TargetElement( 1, "bob" ); + target.addTargetElement( bob ); + TargetElement louise = new TargetElement( 3, "louise" ); + target.addTargetElement( louise ); + + Issue1719Mapper.INSTANCE.map( source, target ); + + assertThat( target.getTargetElements() ).hasSize( 3 ); + assertThat( target.getTargetElements() ) + .extracting( TargetElement::getId, TargetElement::getName ) + .containsOnly( + tuple( 1, "bob" ), + tuple( 2, "alice" ), + tuple( 3, "louise" ) + ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Source.java new file mode 100644 index 0000000000..f3e6b1ea20 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Source.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import java.util.HashSet; +import java.util.Set; + +public class Source { + + private Set sourceElements = new HashSet<>(); + + public Set getSourceElements() { + return sourceElements; + } + + public void setSourceElements(Set sourceElements) { + this.sourceElements = sourceElements; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/SourceElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/SourceElement.java new file mode 100644 index 0000000000..fbfe00e829 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/SourceElement.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import java.util.Objects; + +public class SourceElement { + + private int id; + private String name; + + public SourceElement(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SourceElement that = (SourceElement) o; + return id == that.id; + } + + @Override + public int hashCode() { + return Objects.hash( id ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Target.java new file mode 100644 index 0000000000..9d14a9a143 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Target.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import java.util.HashSet; +import java.util.Set; + +public class Target { + + private Set targetElements = new HashSet<>(); + + public Set getTargetElements() { + return targetElements; + } + + public void setTargetElements(Set targetElements) { + this.targetElements = targetElements; + } + + public TargetElement addTargetElement(TargetElement element) { + element.updateTarget( this ); + getTargetElements().add( element ); + return element; + } + + public TargetElement removeTargetElement(TargetElement element) { + element.updateTarget( null ); + getTargetElements().remove( element ); + return element; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/TargetElement.java new file mode 100644 index 0000000000..92d1970af2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/TargetElement.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1719; + +import java.util.Objects; + +public class TargetElement { + + private int id; + private String name; + private Target target; + + public TargetElement() { + } + + public TargetElement(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Target getTarget() { + return target; + } + + /** + * intentionally not a setter, to not further complicate this test case. + * + * @param target + */ + public void updateTarget(Target target) { + this.target = target; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + TargetElement that = (TargetElement) o; + return id == that.id; + } + + @Override + public int hashCode() { + return Objects.hash( id ); + } + +} From 6c1108d5bb8cf84dad84ff401c1911ff095452e7 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Mon, 25 Feb 2019 20:56:28 +0100 Subject: [PATCH 0336/1006] #1698 Skip "java.lang.Object" as intermediate result additional unit test (#1737) --- .../creation/MappingResolverImpl.java | 10 ++- .../ap/test/builtin/BuiltInTest.java | 70 +++++++++++++------ .../test/builtin/bean/BigDecimalProperty.java | 25 +++++++ .../ap/test/builtin/bean/SomeType.java | 9 +++ .../test/builtin/bean/SomeTypeProperty.java | 23 ++++++ .../ap/test/builtin/mapper/JaxbMapper.java | 11 +++ 6 files changed, 126 insertions(+), 22 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/BigDecimalProperty.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeTypeProperty.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index b45235420f..9938beff16 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -378,6 +378,10 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { *

    10. there is a method from B to C, methodY
    11. * * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) + * + * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt + * is done to find a matching type conversion. */ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetType) { @@ -421,7 +425,11 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp *
    12. there is a conversion from A to B, conversionX
    13. *
    14. there is a method from B to C, methodY
    15. * - * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) + * then this method tries to resolve this combination and make a mapping conversionY( methodX ( parameter ) ) + * + * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from source type to 'B'. If a match is found, an attempt + * is done to find a matching type conversion. */ private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 42e6919663..d5e2de5b64 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -5,8 +5,7 @@ */ package org.mapstruct.ap.test.builtin; -import static org.assertj.core.api.Assertions.assertThat; - +import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.ZoneId; @@ -19,7 +18,6 @@ import java.util.HashMap; import java.util.List; import java.util.TimeZone; - import javax.xml.bind.JAXBElement; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; @@ -34,10 +32,13 @@ import org.junit.runners.MethodSorters; import org.mapstruct.ap.test.builtin._target.IterableTarget; import org.mapstruct.ap.test.builtin._target.MapTarget; +import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; import org.mapstruct.ap.test.builtin.bean.CalendarProperty; import org.mapstruct.ap.test.builtin.bean.DateProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementListProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty; +import org.mapstruct.ap.test.builtin.bean.SomeType; +import org.mapstruct.ap.test.builtin.bean.SomeTypeProperty; import org.mapstruct.ap.test.builtin.bean.StringListProperty; import org.mapstruct.ap.test.builtin.bean.StringProperty; import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty; @@ -64,6 +65,8 @@ import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for the generation of built-in mapping methods. * @@ -78,24 +81,11 @@ JaxbElementProperty.class, StringListProperty.class, StringProperty.class, + BigDecimalProperty.class, + SomeTypeProperty.class, + SomeType.class, XmlGregorianCalendarProperty.class, ZonedDateTimeProperty.class, - CalendarToZonedDateTimeMapper.class, - ZonedDateTimeToCalendarMapper.class, - CalendarToDateMapper.class, - CalendarToStringMapper.class, - CalendarToXmlGregCalMapper.class, - DateToCalendarMapper.class, - DateToXmlGregCalMapper.class, - IterableSourceTargetMapper.class, - JaxbListMapper.class, - JaxbMapper.class, - MapSourceTargetMapper.class, - StringToCalendarMapper.class, - StringToXmlGregCalMapper.class, - XmlGregCalToCalendarMapper.class, - XmlGregCalToDateMapper.class, - XmlGregCalToStringMapper.class, IterableSource.class, MapSource.class }) @@ -117,8 +107,8 @@ public static void restoreOriginalTimeZone() { } @Test - public void shouldApplyBuiltInOnJAXBElement() throws ParseException, DatatypeConfigurationException { - + @WithClasses( JaxbMapper.class ) + public void shouldApplyBuiltInOnJAXBElement() { JaxbElementProperty source = new JaxbElementProperty(); source.setProp( createJaxb( "TEST" ) ); source.publicProp = createJaxb( "PUBLIC TEST" ); @@ -130,6 +120,30 @@ public void shouldApplyBuiltInOnJAXBElement() throws ParseException, DatatypeCon } @Test + @WithClasses( JaxbMapper.class ) + @IssueKey( "1698" ) + public void shouldApplyBuiltInOnJAXBElementExtra() { + JaxbElementProperty source = new JaxbElementProperty(); + source.setProp( createJaxb( "5" ) ); + source.publicProp = createJaxb( "5" ); + + BigDecimalProperty target = JaxbMapper.INSTANCE.mapBD( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( new BigDecimal( "5" ) ); + assertThat( target.publicProp ).isEqualTo( new BigDecimal( "5" ) ); + + JaxbElementProperty source2 = new JaxbElementProperty(); + source2.setProp( createJaxb( "5" ) ); + source2.publicProp = createJaxb( "5" ); + + SomeTypeProperty target2 = JaxbMapper.INSTANCE.mapSomeType( source2 ); + assertThat( target2 ).isNotNull(); + assertThat( target2.publicProp ).isNotNull(); + assertThat( target2.getProp() ).isNotNull(); + } + + @Test + @WithClasses( JaxbListMapper.class ) @IssueKey( "141" ) public void shouldApplyBuiltInOnJAXBElementList() throws ParseException, DatatypeConfigurationException { @@ -144,6 +158,7 @@ public void shouldApplyBuiltInOnJAXBElementList() throws ParseException, Datatyp } @Test + @WithClasses( DateToXmlGregCalMapper.class ) public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException, DatatypeConfigurationException { DateProperty source = new DateProperty(); @@ -159,6 +174,7 @@ public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException, Dataty } @Test + @WithClasses( XmlGregCalToDateMapper.class ) public void shouldApplyBuiltInOnXmlGregCalToDate() throws ParseException, DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); @@ -175,6 +191,7 @@ public void shouldApplyBuiltInOnXmlGregCalToDate() throws ParseException, Dataty } @Test + @WithClasses( StringToXmlGregCalMapper.class ) public void shouldApplyBuiltInStringToXmlGregCal() throws ParseException, DatatypeConfigurationException { StringProperty source = new StringProperty(); @@ -209,6 +226,7 @@ public void shouldApplyBuiltInStringToXmlGregCal() throws ParseException, Dataty } @Test + @WithClasses( XmlGregCalToStringMapper.class ) public void shouldApplyBuiltInXmlGregCalToString() throws ParseException, DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); @@ -235,6 +253,7 @@ public void shouldApplyBuiltInXmlGregCalToString() throws ParseException, Dataty } @Test + @WithClasses( CalendarToXmlGregCalMapper.class ) public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException, DatatypeConfigurationException { CalendarProperty source = new CalendarProperty(); @@ -250,6 +269,7 @@ public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException, Da } @Test + @WithClasses( XmlGregCalToCalendarMapper.class ) public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws ParseException, DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); @@ -267,6 +287,7 @@ public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws ParseException, Da } @Test + @WithClasses( CalendarToDateMapper.class ) public void shouldApplyBuiltInOnCalendarToDate() throws ParseException, DatatypeConfigurationException { CalendarProperty source = new CalendarProperty(); @@ -282,6 +303,7 @@ public void shouldApplyBuiltInOnCalendarToDate() throws ParseException, Datatype } @Test + @WithClasses( DateToCalendarMapper.class ) public void shouldApplyBuiltInOnDateToCalendar() throws ParseException, DatatypeConfigurationException { DateProperty source = new DateProperty(); @@ -298,6 +320,7 @@ public void shouldApplyBuiltInOnDateToCalendar() throws ParseException, Datatype } @Test + @WithClasses( CalendarToStringMapper.class ) public void shouldApplyBuiltInOnCalendarToString() throws ParseException, DatatypeConfigurationException { CalendarProperty source = new CalendarProperty(); @@ -313,6 +336,7 @@ public void shouldApplyBuiltInOnCalendarToString() throws ParseException, Dataty } @Test + @WithClasses( StringToCalendarMapper.class ) public void shouldApplyBuiltInOnStringToCalendar() throws ParseException, DatatypeConfigurationException { StringProperty source = new StringProperty(); @@ -329,6 +353,7 @@ public void shouldApplyBuiltInOnStringToCalendar() throws ParseException, Dataty } @Test + @WithClasses( IterableSourceTargetMapper.class ) public void shouldApplyBuiltInOnIterable() throws ParseException, DatatypeConfigurationException { IterableSource source = new IterableSource(); @@ -342,6 +367,7 @@ public void shouldApplyBuiltInOnIterable() throws ParseException, DatatypeConfig } @Test + @WithClasses( MapSourceTargetMapper.class ) public void shouldApplyBuiltInOnMap() throws ParseException, DatatypeConfigurationException { MapSource source = new MapSource(); @@ -357,6 +383,7 @@ public void shouldApplyBuiltInOnMap() throws ParseException, DatatypeConfigurati } @Test + @WithClasses( CalendarToZonedDateTimeMapper.class ) public void shouldApplyBuiltInOnCalendarToZonedDateTime() throws ParseException { assertThat( CalendarToZonedDateTimeMapper.INSTANCE.map( null ) ).isNull(); @@ -373,6 +400,7 @@ public void shouldApplyBuiltInOnCalendarToZonedDateTime() throws ParseException } @Test + @WithClasses( ZonedDateTimeToCalendarMapper.class ) public void shouldApplyBuiltInOnZonedDateTimeToCalendar() throws ParseException { assertThat( ZonedDateTimeToCalendarMapper.INSTANCE.map( null ) ).isNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/BigDecimalProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/BigDecimalProperty.java new file mode 100644 index 0000000000..85e92f7c4d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/BigDecimalProperty.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +import java.math.BigDecimal; + +public class BigDecimalProperty { + + // CHECKSTYLE:OFF + public BigDecimal publicProp; + // CHECKSTYLE:ON + + private BigDecimal prop; + + public BigDecimal getProp() { + return prop; + } + + public void setProp( BigDecimal prop ) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeType.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeType.java new file mode 100644 index 0000000000..9ba2a38166 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeType.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +public class SomeType { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeTypeProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeTypeProperty.java new file mode 100644 index 0000000000..fa40da83a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/SomeTypeProperty.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +public class SomeTypeProperty { + + // CHECKSTYLE:OFF + public SomeType publicProp; + // CHECKSTYLE:ON + + private SomeType prop; + + public SomeType getProp() { + return prop; + } + + public void setProp( SomeType prop ) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java index ae49b8d178..5b407e19d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JaxbMapper.java @@ -6,6 +6,9 @@ package org.mapstruct.ap.test.builtin.mapper; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; +import org.mapstruct.ap.test.builtin.bean.SomeType; +import org.mapstruct.ap.test.builtin.bean.SomeTypeProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty; import org.mapstruct.ap.test.builtin.bean.StringProperty; import org.mapstruct.factory.Mappers; @@ -16,4 +19,12 @@ public interface JaxbMapper { JaxbMapper INSTANCE = Mappers.getMapper( JaxbMapper.class ); StringProperty map(JaxbElementProperty source); + + BigDecimalProperty mapBD(JaxbElementProperty source); + + SomeTypeProperty mapSomeType(JaxbElementProperty source); + + default SomeType map( String in ) { + return new SomeType(); + } } From 98d86cee84ac6715d23528a74495daa70198c5cf Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 9 Mar 2019 18:36:33 +0100 Subject: [PATCH 0337/1006] #1745 refactoring source reference (#1746) --- .../model/source/SourceReference.java | 214 +++++++++++------- 1 file changed, 133 insertions(+), 81 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 79d0a8b134..30b80c8b2f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -86,16 +86,11 @@ public BuilderFromMapping typeFactory(TypeFactory typeFactory) { public SourceReference build() { - String sourceName = mapping.getSourceName(); - if ( sourceName == null ) { return null; } - boolean isValid = true; - boolean foundEntryMatch; - String sourceNameTrimmed = sourceName.trim(); if ( !sourceName.equals( sourceNameTrimmed ) ) { messager.printMessage( @@ -107,103 +102,160 @@ public SourceReference build() { sourceNameTrimmed ); } - String[] sourcePropertyNames = new String[0]; - String[] segments = sourceNameTrimmed.split( "\\." ); - Parameter parameter = null; - List entries = new ArrayList<>(); + String[] segments = sourceNameTrimmed.split( "\\." ); + // start with an invalid source reference + SourceReference result = new SourceReference( null, new ArrayList<>( ), false ); if ( method.getSourceParameters().size() > 1 ) { - - // parameterName is mandatory for multiple source parameters - if ( segments.length > 0 ) { - String sourceParameterName = segments[0]; - parameter = method.getSourceParameter( sourceParameterName ); - if ( parameter == null ) { - reportMappingError( - Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, - sourceParameterName, - Strings.join( - method.getSourceParameters(), - ", ", - new Extractor() { - @Override - public String apply(Parameter parameter) { - return parameter.getName(); - } - } - ) - ); - isValid = false; - } + Parameter parameter = fetchMatchingParameterFromFirstSegment( segments ); + if ( parameter != null ) { + result = buildFromMultipleSourceParameters( segments, parameter ); } - if ( segments.length > 1 && parameter != null ) { - sourcePropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); + } + else { + Parameter parameter = method.getSourceParameters().get( 0 ); + result = buildFromSingleSourceParameters( segments, parameter ); + } + return result; + + } + + /** + * When there is only one source parameters, the first segment name of the property may, or may not match + * the parameter name to avoid ambiguity + * + * consider: {@code Target map( Source1 source1 )} + * entries in an @Mapping#source can be "source1.propx" or just "propx" to be valid + * + * @param segments the segments of @Mapping#source + * @param parameter the one and only parameter + * @return the source reference + */ + private SourceReference buildFromSingleSourceParameters(String[] segments, Parameter parameter) { + + boolean foundEntryMatch; + + String[] propertyNames = segments; + List entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + foundEntryMatch = ( entries.size() == propertyNames.length ); + + if ( !foundEntryMatch ) { + //Lets see if the expression contains the parameterName, so parameterName.propName1.propName2 + if ( parameter.getName().equals( segments[0] ) ) { + propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); + entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + foundEntryMatch = ( entries.size() == propertyNames.length ); } else { - // its only a parameter, no property - foundEntryMatch = true; + // segment[0] cannot be attributed to the parameter name. + parameter = null; } + } + if ( !foundEntryMatch ) { + reportErrorOnNoMatch( parameter, propertyNames, entries ); } - else { - // parameter name is not mandatory for single source parameter - sourcePropertyNames = segments; - parameter = method.getSourceParameters().get( 0 ); - entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); - - if ( !foundEntryMatch ) { - //Lets see if the expression contains the parameterName, so parameterName.propName1.propName2 - if ( parameter.getName().equals( segments[0] ) ) { - sourcePropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - entries = getSourceEntries( parameter.getType(), sourcePropertyNames ); - foundEntryMatch = ( entries.size() == sourcePropertyNames.length ); - } - else { - // segment[0] cannot be attributed to the parameter name. - parameter = null; - } - } + return new SourceReference( parameter, entries, foundEntryMatch ); + } + + /** + * When there are more than one source parameters, the first segment name of the property + * needs to match the parameter name to avoid ambiguity + * + * @param segments the segments of @Mapping#source + * @param parameter the relevant source parameter + * @return the source reference + */ + private SourceReference buildFromMultipleSourceParameters(String[] segments, Parameter parameter) { + + boolean foundEntryMatch; + + String[] propertyNames = new String[0]; + List entries = new ArrayList<>(); + + if ( segments.length > 1 && parameter != null ) { + propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); + entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + foundEntryMatch = ( entries.size() == propertyNames.length ); + } + else { + // its only a parameter, no property + foundEntryMatch = true; } if ( !foundEntryMatch ) { + reportErrorOnNoMatch( parameter, propertyNames, entries ); + } - if ( parameter != null ) { - reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(), - Strings.join( Arrays.asList( sourcePropertyNames ), "." ) - ); - } - else { - int notFoundPropertyIndex = 0; - Type sourceType = method.getParameters().get( 0 ).getType(); - if ( !entries.isEmpty() ) { - notFoundPropertyIndex = entries.size(); - sourceType = last( entries ).getType(); - } - String mostSimilarWord = Strings.getMostSimilarWord( - sourcePropertyNames[notFoundPropertyIndex], - sourceType.getPropertyReadAccessors().keySet() - ); - List elements = new ArrayList<>( - Arrays.asList( sourcePropertyNames ).subList( 0, notFoundPropertyIndex ) - ); - elements.add( mostSimilarWord ); + return new SourceReference( parameter, entries, foundEntryMatch ); + } + + /** + * When there are more than one source parameters, the first segment name of the propery + * needs to match the parameter name to avoid ambiguity + * + * consider: {@code Target map( Source1 source1, Source2 source2 )} + * entries in an @Mapping#source need to be "source1.propx" or "source2.propy.propz" to be valid + * + * @param segments the segments of @Mapping#source + * @return parameter that matches with first segment of @Mapping#source + */ + private Parameter fetchMatchingParameterFromFirstSegment(String[] segments ) { + Parameter parameter = null; + if ( segments.length > 0 ) { + String parameterName = segments[0]; + parameter = method.getSourceParameter( parameterName ); + if ( parameter == null ) { reportMappingError( - Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), - Strings.join( elements, "." ) + Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, + parameterName, + Strings.join( + method.getSourceParameters(), + ", ", + new Extractor() { + @Override + public String apply(Parameter parameter) { + return parameter.getName(); + } + } + ) ); } - isValid = false; } + return parameter; + } - return new SourceReference( parameter, entries, isValid ); + private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, List entries) { + if ( parameter != null ) { + reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(), + Strings.join( Arrays.asList( propertyNames ), "." ) + ); + } + else { + int notFoundPropertyIndex = 0; + Type sourceType = method.getParameters().get( 0 ).getType(); + if ( !entries.isEmpty() ) { + notFoundPropertyIndex = entries.size(); + sourceType = last( entries ).getType(); + } + String mostSimilarWord = Strings.getMostSimilarWord( + propertyNames[notFoundPropertyIndex], + sourceType.getPropertyReadAccessors().keySet() + ); + List elements = new ArrayList<>( + Arrays.asList( propertyNames ).subList( 0, notFoundPropertyIndex ) + ); + elements.add( mostSimilarWord ); + reportMappingError( + Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), + Strings.join( elements, "." ) + ); + } } - private List getSourceEntries(Type type, String[] entryNames) { + private List matchWithSourceAccessorTypes(Type type, String[] entryNames) { List sourceEntries = new ArrayList<>(); Type newType = type; for ( String entryName : entryNames ) { From ae3758674ab7b18663887a082b02a95aa9f7a939 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Thu, 3 Jan 2019 10:53:30 +0100 Subject: [PATCH 0338/1006] #1675 Making MapStruct compileable with OpenJDK 11 --- integrationtest/pom.xml | 17 +++++++++++++++++ processor/pom.xml | 16 ++++++++++++++++ .../StaticParseToStringConversion.java | 4 ++-- .../test/abstractclass/AbstractClassTest.java | 3 ++- .../abstractclass/AbstractReferencedMapper.java | 3 +-- .../mapstruct/ap/test/abstractclass/Holder.java | 15 +++++++++++++++ .../ap/test/abstractclass/ReferencedMapper.java | 3 +-- .../ReferencedMapperInterface.java | 3 +-- .../mapstruct/ap/test/abstractclass/Source.java | 2 -- .../mapstruct/ap/test/bugs/_1170/AdderTest.java | 12 ++++++------ .../IterableWithBoundedElementTypeTest.java | 7 +++++-- 11 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/abstractclass/Holder.java diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 135f7991f3..257c32730a 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -86,4 +86,21 @@
      + + + + jdk-11-or-newer + + [11 + + + + javax.xml.bind + jaxb-api + 2.3.1 + provided + + + +
      diff --git a/processor/pom.xml b/processor/pom.xml index 52d8e7efb9..538237e7d6 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -304,4 +304,20 @@ + + + jdk-11-or-newer + + [11 + + + + javax.xml.bind + jaxb-api + 2.3.1 + provided + + + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java index 15d7b4bcc9..df3a70ac34 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StaticParseToStringConversion.java @@ -12,9 +12,9 @@ import org.mapstruct.ap.internal.util.Collections; /** - * Handles conversion between a target type T and {@link String}, + * Handles conversion between a target type {@code T} and {@link String}, * where {@code T#parse(String)} and {@code T#toString} are inverse operations. - * The {@link ConversionContext#getTargetType()} is used as the from target type T. + * The {@link ConversionContext#getTargetType()} is used as the from target type {@code T}. */ public class StaticParseToStringConversion extends SimpleConversion { diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java index 42df0b4fea..f510fd32e9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java @@ -28,7 +28,8 @@ Identifiable.class, HasId.class, AlsoHasId.class, - Measurable.class + Measurable.class, + Holder.class }) @RunWith(AnnotationProcessorTestRunner.class) public class AbstractClassTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java index 1fa135af21..0bde73c975 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java @@ -5,12 +5,11 @@ */ package org.mapstruct.ap.test.abstractclass; -import javax.xml.ws.Holder; - /** * @author Andreas Gudian */ public abstract class AbstractReferencedMapper implements ReferencedMapperInterface { + @Override public int holderToInt(Holder holder) { return 41; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Holder.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Holder.java new file mode 100644 index 0000000000..e05e062464 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Holder.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.abstractclass; + +/** + * @author Gunnar Morling + */ +public class Holder { + + public Holder(String string) { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java index d3099f2cb0..c2a01d3f8e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapper.java @@ -5,12 +5,11 @@ */ package org.mapstruct.ap.test.abstractclass; -import javax.xml.ws.Holder; - /** * @author Andreas Gudian */ public class ReferencedMapper extends AbstractReferencedMapper { + @Override public int holderToInt(Holder holder) { return 42; diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java index a257135e0e..5d4e3d8661 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/ReferencedMapperInterface.java @@ -5,11 +5,10 @@ */ package org.mapstruct.ap.test.abstractclass; -import javax.xml.ws.Holder; - /** * @author Andreas Gudian */ public interface ReferencedMapperInterface { + int holderToInt(Holder holder); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java index ed8df1f079..f13efc9785 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java @@ -7,8 +7,6 @@ import java.util.Calendar; -import javax.xml.ws.Holder; - public class Source extends AbstractDto implements HasId, AlsoHasId { //CHECKSTYLE:OFF diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java index 9e1e3ea5a9..b68884e0e3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java @@ -9,6 +9,7 @@ import java.util.Arrays; +import org.assertj.core.api.ListAssert; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._1170._target.Target; @@ -44,8 +45,8 @@ public void testWildcardAdder() { assertThat( target ).isNotNull(); assertThat( target.getWithoutWildcards() ).containsExactly( 2L ); assertThat( target.getWildcardInSources() ).containsExactly( 2L ); - assertThat( target.getWildcardInTargets() ).containsExactly( 2L ); - assertThat( target.getWildcardInBoths() ).containsExactly( 2L ); + ( (ListAssert) assertThat( target.getWildcardInTargets() ) ).containsExactly( 2L ); + ( (ListAssert) assertThat( target.getWildcardInBoths() ) ).containsExactly( 2L ); assertThat( target.getWildcardAdderToSetters() ).containsExactly( 2L ); } @@ -63,10 +64,9 @@ public void testWildcardAdderTargetToSource() { assertThat( source ).isNotNull(); assertThat( source.getWithoutWildcards() ).containsExactly( "mouse" ); - assertThat( source.getWildcardInSources() ).containsExactly( "mouse" ); + ( (ListAssert) assertThat( source.getWildcardInSources() ) ).containsExactly( "mouse" ); assertThat( source.getWildcardInTargets() ).containsExactly( "mouse" ); - assertThat( source.getWildcardInBoths() ).containsExactly( "mouse" ); - assertThat( source.getWildcardAdderToSetters() ).containsExactly( "mouse" ); + ( (ListAssert) assertThat( source.getWildcardInBoths() ) ).containsExactly( "mouse" ); + ( (ListAssert) assertThat( source.getWildcardAdderToSetters() ) ).containsExactly( "mouse" ); } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java index 9b6c6d40f7..af3d5b4245 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java @@ -9,6 +9,7 @@ import java.util.Arrays; +import org.assertj.core.api.IterableAssert; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -42,7 +43,8 @@ public void createsForgedMethodForIterableLowerBoundInteger() { source.setValues( Arrays.asList( "42", "47" ) ); IterableContainer result = MapperWithForgedIterableMapping.INSTANCE.toContainerWithIterable( source ); - assertThat( result.getValues() ).contains( Integer.valueOf( 42 ), Integer.valueOf( 47 ) ); + ( (IterableAssert) assertThat( result.getValues() ) ) + .contains( Integer.valueOf( 42 ), Integer.valueOf( 47 ) ); } @Test @@ -52,6 +54,7 @@ public void usesListIntegerMethodForIterableLowerBoundInteger() { source.setValues( Arrays.asList( "42", "47" ) ); IterableContainer result = MapperWithCustomListMapping.INSTANCE.toContainerWithIterable( source ); - assertThat( result.getValues() ).contains( Integer.valueOf( 66 ), Integer.valueOf( 71 ) ); + ( (IterableAssert) assertThat( result.getValues() ) ) + .contains( Integer.valueOf( 66 ), Integer.valueOf( 71 ) ); } } From 643cc85e5018f783f9d0f00e2f8bdcaf52cf98aa Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 19:37:27 +0100 Subject: [PATCH 0339/1006] #1675 Tests should run properly in Java 11 * Add Travis CI build matrix to run build on OpenJDK 11 and EA * Add regex for the Java 11 Generated annotation in order for the JavaFileAssert to work properly * Do not use eclipse compiler if running on Java 9+ * Add JDK11 util compiler that reports all errors (also when multiple on same line) * Whitelist jaxb-api to the test compilation classpath * Add specific ignores for running some tests with Java 11 (See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+) --- .travis.yml | 17 ++++++++- .../conversion/date/DateConversionTest.java | 37 +++++++++++++++++++ .../jodatime/JodaConversionTest.java | 33 +++++++++++++++++ .../testutil/assertions/JavaFileAssert.java | 5 ++- .../runner/AnnotationProcessorTestRunner.java | 19 ++++++++++ .../ap/testutil/runner/Compiler.java | 2 +- .../testutil/runner/CompilingStatement.java | 1 + .../testutil/runner/DisabledOnCompiler.java | 26 +++++++++++++ .../ap/testutil/runner/EnabledOnCompiler.java | 26 +++++++++++++ .../InnerAnnotationProcessorRunner.java | 22 +++++++++++ .../runner/Jdk11CompilingStatement.java | 37 +++++++++++++++++++ 11 files changed, 221 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java diff --git a/.travis.yml b/.travis.yml index 8ce15e93ce..f9e1963f90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,24 @@ language: java -jdk: - - oraclejdk8 install: true script: mvn clean install -DprocessorIntegrationTest.toolchainsFile=etc/toolchains-travis-jenkins.xml -B -V after_success: - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" +matrix: + include: + - jdk: oraclejdk8 + - jdk: openjdk11 + # Only run the processor and its dependencies + # The integration tests are using the maven toolchain and that is not yet ready for Java 11 + # There is an issue with the documentation so skip it + script: mvn -B -V clean install -pl processor -am + # Only run the processor and its dependencies + # The integration tests are using the maven toolchain and that is not yet ready for Java EA + # There is an issue with the documentation so skip it + - jdk: openjdk-ea + script: mvn -B -V clean install -pl processor -am + allow_failures: + - jdk: openjdk-ea deploy: provider: script script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true deploy" diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index ee643032b1..680303b334 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -22,6 +22,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; +import org.mapstruct.ap.testutil.runner.EnabledOnCompiler; /** * Tests application of format strings for conversions between strings and dates. @@ -43,6 +46,8 @@ public void setDefaultLocale() { } @Test + @DisabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversions() { Source source = new Source(); source.setDate( new GregorianCalendar( 2013, 6, 6 ).getTime() ); @@ -56,6 +61,23 @@ public void shouldApplyDateFormatForConversions() { } @Test + @EnabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionsJdk11() { + Source source = new Source(); + source.setDate( new GregorianCalendar( 2013, 6, 6 ).getTime() ); + source.setAnotherDate( new GregorianCalendar( 2013, 1, 14 ).getTime() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getDate() ).isEqualTo( "06.07.2013" ); + assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); + } + + @Test + @DisabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMapping() { Target target = new Target(); target.setDate( "06.07.2013" ); @@ -68,6 +90,21 @@ public void shouldApplyDateFormatForConversionInReverseMapping() { assertThat( source.getAnotherDate() ).isEqualTo( new GregorianCalendar( 2013, 1, 14, 8, 30 ).getTime() ); } + @Test + @EnabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { + Target target = new Target(); + target.setDate( "06.07.2013" ); + target.setAnotherDate( "14.02.13, 8:30" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, 6, 6 ).getTime() ); + assertThat( source.getAnotherDate() ).isEqualTo( new GregorianCalendar( 2013, 1, 14, 8, 30 ).getTime() ); + } + @Test public void shouldApplyStringConversionForIterableMethod() { List dates = Arrays.asList( diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 60dca06ce1..30c96395b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -22,6 +22,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; +import org.mapstruct.ap.testutil.runner.EnabledOnCompiler; /** * Tests the conversion between Joda-Time types and String/Date/Calendar. @@ -75,6 +78,8 @@ public void testLocalTimeToString() { } @Test + @DisabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStrings() { Source src = new Source(); src.setLocalTime( new LocalTime( 0, 0 ) ); @@ -100,6 +105,34 @@ public void testSourceToTargetMappingForStrings() { assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); } + @Test + @EnabledOnCompiler(Compiler.JDK11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void testSourceToTargetMappingForStringsJdk11() { + Source src = new Source(); + src.setLocalTime( new LocalTime( 0, 0 ) ); + src.setLocalDate( new LocalDate( 2014, 1, 1 ) ); + src.setLocalDateTime( new LocalDateTime( 2014, 1, 1, 0, 0 ) ); + src.setDateTime( new DateTime( 2014, 1, 1, 0, 0, 0, DateTimeZone.UTC ) ); + + // with given format + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); + assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); + assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); + assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); + + // and now with default mappings + target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( src ); + assertThat( target ).isNotNull(); + assertThat( target.getDateTime() ).isEqualTo( "1. Januar 2014 um 00:00:00 UTC" ); + assertThat( target.getLocalDateTime() ).isEqualTo( "1. Januar 2014 um 00:00:00" ); + assertThat( target.getLocalDate() ).isEqualTo( "1. Januar 2014" ); + assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); + } + @Test public void testStringToDateTime() { String dateTimeAsString = "01.01.2014 00:00 UTC"; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 9b374273f1..62325ac8f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -38,6 +38,8 @@ public class JavaFileAssert extends FileAssert { "\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{4}\","; private static final String GENERATED_COMMENTS_REGEX = "\\s+comments = \"version: , compiler: .*, environment: " + ".*\""; + private static final String IMPORT_GENERATED_ANNOTATION_REGEX = "import javax\\.annotation\\.(processing\\.)?" + + "Generated;"; private Diff diff = new Diff(); @@ -135,7 +137,8 @@ private boolean ignoreDelta(Delta delta) { else if ( delta.getType() == Delta.TYPE.CHANGE ) { List lines = delta.getOriginal().getLines(); if ( lines.size() == 1 ) { - return lines.get( 0 ).matches( GENERATED_DATE_REGEX ); + return lines.get( 0 ).matches( GENERATED_DATE_REGEX ) || + lines.get( 0 ).matches( IMPORT_GENERATED_ANNOTATION_REGEX ); } else if ( lines.size() == 2 ) { return lines.get( 0 ).matches( GENERATED_DATE_REGEX ) && diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java index 02f986d540..2688f9f7df 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java @@ -37,6 +37,19 @@ * @author Andreas Gudian */ public class AnnotationProcessorTestRunner extends ParentRunner { + + private static final boolean IS_AT_LEAST_JAVA_9 = isIsAtLeastJava9(); + + private static boolean isIsAtLeastJava9() { + try { + Runtime.class.getMethod( "version" ); + return true; + } + catch ( NoSuchMethodException e ) { + return false; + } + } + private final List runners; /** @@ -57,6 +70,12 @@ private List createRunners(Class klass) throws Exception { if (singleCompiler != null) { return Arrays. asList( new InnerAnnotationProcessorRunner( klass, singleCompiler.value() ) ); } + else if ( IS_AT_LEAST_JAVA_9 ) { + // Current tycho-compiler-jdt (0.26.0) is not compatible with Java 11 + // Updating to latest version 1.3.0 fails some tests + // Once https://github.com/mapstruct/mapstruct/pull/1587 is resolved we can remove this line + return Arrays.asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK11 ) ); + } return Arrays. asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK ), diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java index 4e11318be7..d59a7ed0dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java @@ -10,5 +10,5 @@ * */ public enum Compiler { - JDK, ECLIPSE; + JDK, JDK11, ECLIPSE; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 73693e4cb5..f6ddcbd2bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -128,6 +128,7 @@ private static List buildTestCompilationClasspath() { "javax.inject", "spring-beans", "spring-context", + "jaxb-api", "joda-time" }; return filterBootClassPath( whitelist ); diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java new file mode 100644 index 0000000000..41bcdb1000 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This should be used with care. + * This is similar to the JUnit 5 DisabledOnJre (once we have JUnit 5 we can replace this one) + * + * @author Filip Hrisafov + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface DisabledOnCompiler { + /** + * @return The compiler to use. + */ + Compiler value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java new file mode 100644 index 0000000000..e297bd2c65 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This should be used with care. + * This is similar to the JUnit 5 EnabledOnJre (once we have JUnit 5 we can replace this one) + * + * @author Filip Hrisafov + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface EnabledOnCompiler { + /** + * @return The compiler to use. + */ + Compiler value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java index 9b9dc868b8..4850a48704 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java @@ -60,6 +60,25 @@ private static void replaceContextClassLoader(Class klass) { Thread.currentThread().setContextClassLoader( testClassLoader ); } + @Override + protected boolean isIgnored(FrameworkMethod child) { + return super.isIgnored( child ) || isIgnoredForCompiler( child ); + } + + protected boolean isIgnoredForCompiler(FrameworkMethod child) { + EnabledOnCompiler enabledOnCompiler = child.getAnnotation( EnabledOnCompiler.class ); + if ( enabledOnCompiler != null ) { + return enabledOnCompiler.value() != compiler; + } + + DisabledOnCompiler disabledOnCompiler = child.getAnnotation( DisabledOnCompiler.class ); + if ( disabledOnCompiler != null ) { + return disabledOnCompiler.value() == compiler; + } + + return false; + } + @Override protected TestClass createTestClass(final Class testClass) { replacableTestClass = new ReplacableTestClass( testClass ); @@ -98,6 +117,9 @@ private CompilingStatement createCompilingStatement(FrameworkMethod method) { if ( compiler == Compiler.JDK ) { return new JdkCompilingStatement( method, compilationCache ); } + else if ( compiler == Compiler.JDK11 ) { + return new Jdk11CompilingStatement( method, compilationCache ); + } else { return new EclipseCompilingStatement( method, compilationCache ); } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java new file mode 100644 index 0000000000..30f12aead7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import java.util.List; + +import org.junit.runners.model.FrameworkMethod; +import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; + +/** + * Statement that uses the JDK compiler to compile. + * + * @author Filip Hrisafov + */ +class Jdk11CompilingStatement extends JdkCompilingStatement { + + Jdk11CompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { + super( method, compilationCache ); + } + + + /** + * The JDK 11 compiler reports all ERROR diagnostics properly. Also when there are multiple per line. + */ + @Override + protected List filterExpectedDiagnostics(List expectedDiagnostics) { + return expectedDiagnostics; + } + + @Override + protected String getPathSuffix() { + return "_jdk"; + } +} From 92bed791445eab22acc0aa20205defd2d63ad147 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 20:05:41 +0100 Subject: [PATCH 0340/1006] Fix .travis.yml --- .travis.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f9e1963f90..8bafb838f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,19 +6,19 @@ after_success: matrix: include: - - jdk: oraclejdk8 - - jdk: openjdk11 - # Only run the processor and its dependencies - # The integration tests are using the maven toolchain and that is not yet ready for Java 11 - # There is an issue with the documentation so skip it - script: mvn -B -V clean install -pl processor -am - # Only run the processor and its dependencies - # The integration tests are using the maven toolchain and that is not yet ready for Java EA - # There is an issue with the documentation so skip it + - jdk: oraclejdk8 + - jdk: openjdk11 + # Only run the processor and its dependencies + # The integration tests are using the maven toolchain and that is not yet ready for Java 11 + # There is an issue with the documentation so skip it + script: mvn -B -V clean install -pl processor -am + # Only run the processor and its dependencies + # The integration tests are using the maven toolchain and that is not yet ready for Java EA + # There is an issue with the documentation so skip it + - jdk: openjdk-ea + script: mvn -B -V clean install -pl processor -am + allow_failures: - jdk: openjdk-ea - script: mvn -B -V clean install -pl processor -am - allow_failures: - - jdk: openjdk-ea deploy: provider: script script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true deploy" From 3e6ea0ef8ff3cc163196032bf185f751d2f9b46b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 20:19:28 +0100 Subject: [PATCH 0341/1006] Update Javadoc and set source to 8 for proper compilation on Java 11 See https://bugs.openjdk.java.net/browse/JDK-8212233 for more information --- parent/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index dc28d04adb..0fe73c1ce5 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ 3.0.0-M1 2.22.1 - 3.0.1 + 3.1.0 4.0.3.RELEASE 0.26.0 8.14 @@ -381,6 +381,7 @@ true org.mapstruct.ap.internal.prism;org.mapstruct.itest.jaxb.xsd.* + 8 From 5e96dc8085f6af41a564e9d18807ec356c76a0cb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 20:36:21 +0100 Subject: [PATCH 0342/1006] Deploy coverage reports only on JDK 8 + deploy snapshots only from JDK 8 build --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8bafb838f5..3db2872ac4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,12 @@ language: java install: true script: mvn clean install -DprocessorIntegrationTest.toolchainsFile=etc/toolchains-travis-jenkins.xml -B -V -after_success: - - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" matrix: include: - jdk: oraclejdk8 + after_success: + - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" - jdk: openjdk11 # Only run the processor and its dependencies # The integration tests are using the maven toolchain and that is not yet ready for Java 11 @@ -25,6 +25,7 @@ deploy: skip_cleanup: true on: branch: master + jdk: oraclejdk8 sudo: required cache: From b9b9b60a38d0a03959ed6791cc5cc6a4f1620bbc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 21:35:16 +0100 Subject: [PATCH 0343/1006] Travis CI deploy snapshots only from the mapstruct/mapstruct repo + skip build of distribution when deploying --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3db2872ac4..3d8c755ea8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,9 +21,10 @@ matrix: - jdk: openjdk-ea deploy: provider: script - script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true deploy" + script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true -DskipDistribution=true deploy" skip_cleanup: true on: + repo: mapstruct/mapstruct branch: master jdk: oraclejdk8 From 07590cc0d1b8f1625708399b0db10f5f8f15ed03 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Mar 2019 21:50:57 +0100 Subject: [PATCH 0344/1006] Add Open JDK 12 to the Travis CI matrix --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3d8c755ea8..c9058ee97b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,11 @@ matrix: # The integration tests are using the maven toolchain and that is not yet ready for Java 11 # There is an issue with the documentation so skip it script: mvn -B -V clean install -pl processor -am + - jdk: openjdk12 + # Only run the processor and its dependencies + # The integration tests are using the maven toolchain and that is not yet ready for Java 11 + # There is an issue with the documentation so skip it + script: mvn -B -V clean install -pl processor -am # Only run the processor and its dependencies # The integration tests are using the maven toolchain and that is not yet ready for Java EA # There is an issue with the documentation so skip it From 4f2f546ffc3e47203fe75c356c9212ed6d027ff8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Mar 2019 13:36:11 +0100 Subject: [PATCH 0345/1006] Update plugins to latest versions --- parent/pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 0fe73c1ce5..53e01718c8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -24,7 +24,7 @@ 1.0.0 3.0.0-M1 - 2.22.1 + 3.0.0-M3 3.1.0 4.0.3.RELEASE 0.26.0 @@ -272,7 +272,7 @@ org.apache.maven.plugins maven-assembly-plugin - 3.1.0 + 3.1.1 org.apache.maven.plugins @@ -372,7 +372,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.1.0 + 3.1.1 org.apache.maven.plugins @@ -500,7 +500,7 @@ org.jacoco jacoco-maven-plugin - 0.8.2 + 0.8.3 org.jvnet.jaxb2.maven2 @@ -525,7 +525,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.13.0 + 0.13.1 verify From bc010a52dcb7bbb444968f7c737458007eb67dd3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 10 Mar 2019 13:55:32 +0100 Subject: [PATCH 0346/1006] #1738: Use typeBound for the return type of the nested property mapping method and for the definition of the properties within the method --- .../model/NestedPropertyMappingMethod.ftl | 4 +- .../ap/test/bugs/_1738/Issue1738Mapper.java | 22 +++++++++++ .../ap/test/bugs/_1738/Issue1738Test.java | 39 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1738/Source.java | 35 +++++++++++++++++ .../mapstruct/ap/test/bugs/_1738/Target.java | 22 +++++++++++ 5 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Target.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index ae4f65a81c..e50e55bc34 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -6,7 +6,7 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" --> -<#lt>private <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { +<#lt>private <@includeModel object=returnType.typeBound/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { if ( ${sourceParameter.name} == null ) { return ${returnType.null}; } @@ -16,7 +16,7 @@ return ${returnType.null}; } - <@includeModel object=entry.type/> ${entry.name} = <@localVarName index=entry_index/>.${entry.accessorName}; + <@includeModel object=entry.type.typeBound/> ${entry.name} = <@localVarName index=entry_index/>.${entry.accessorName}; <#if !entry.presenceCheckerName?? > <#if !entry.type.primitive> if ( ${entry.name} == null ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Mapper.java new file mode 100644 index 0000000000..79147f2247 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1738; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1738Mapper { + + Issue1738Mapper INSTANCE = Mappers.getMapper( Issue1738Mapper.class ); + + @Mapping(target = "value", source = "nested.value") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java new file mode 100644 index 0000000000..b9d28ff27b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1738; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1738") +@WithClasses({ + Issue1738Mapper.class, + Source.class, + Target.class +}) +public class Issue1738Test { + + @Test + public void shouldGenerateCorrectSourceNestedMapping() { + Source source = new Source(); + Source.Nested nested = new Source.Nested<>(); + source.setNested( nested ); + nested.setValue( 100L ); + + Target target = Issue1738Mapper.INSTANCE.map( source ); + + assertThat( target.getValue() ).isEqualTo( 100L ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Source.java new file mode 100644 index 0000000000..7f67c6db6d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Source.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1738; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private Nested nested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + + public static class Nested { + + private T value; + + public T getValue() { + return value; + } + + public void setValue(T value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Target.java new file mode 100644 index 0000000000..931ccb85b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1738; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Number value; + + public Number getValue() { + return value; + } + + public void setValue(Number value) { + this.value = value; + } +} From b53741d9608c1a3faccc46c8ee32b54cfdc5d724 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 17 Mar 2019 16:45:22 +0100 Subject: [PATCH 0347/1006] #37 Rudimentary logging in mapstruct (#1741) * #37 Rudimentary logging in mapstruct * #37 Rudimentary logging in mapstruct changed order * #37 rework * #37 documentation * #37 comments * #37 docmentation revisited * #37 review comments * #37 unit test * #37 unit test fixing empty mapper * #37 rework comments christian * #37 adding deferred mapper logging * #37 adding unit test for deferred mapper logging * #37 processing comments Filip --- .../mapstruct-reference-guide.asciidoc | 12 +- .../org/mapstruct/ap/MappingProcessor.java | 18 ++- .../model/ContainerMappingMethodBuilder.java | 7 + .../ap/internal/model/MapMappingMethod.java | 14 +- .../ap/internal/model/MethodReference.java | 13 ++ .../ap/internal/model/PropertyMapping.java | 9 ++ .../ap/internal/model/TypeConversion.java | 6 + .../mapstruct/ap/internal/option/Options.java | 8 +- .../DefaultModelElementProcessorContext.java | 16 ++- .../processor/MapperCreationProcessor.java | 9 +- .../processor/MethodRetrievalProcessor.java | 6 + .../util/AnnotationProcessorContext.java | 27 +++- .../ap/internal/util/FormattingMessager.java | 8 ++ .../mapstruct/ap/internal/util/Message.java | 19 ++- .../accessor/ExecutableElementAccessor.java | 5 + .../accessor/VariableElementAccessor.java | 5 + .../writer/IndentationCorrectingWriter.java | 2 +- .../ap/spi/DefaultBuilderProvider.java | 1 + .../FreeBuilderAccessorNamingStrategy.java | 1 + .../spi/ImmutablesAccessorNamingStrategy.java | 1 + .../ap/spi/ImmutablesBuilderProvider.java | 1 + .../mapstruct/ap/spi/NoOpBuilderProvider.java | 1 + .../common/DefaultConversionContextTest.java | 5 + ...AstModifyingAnnotationProcessorSaysNo.java | 18 +++ .../ap/test/verbose/CreateBeanMapping.java | 67 +++++++++ .../test/verbose/CreateIterableMapping.java | 45 ++++++ .../ap/test/verbose/CreateMapMapping.java | 69 +++++++++ .../ap/test/verbose/SelectBeanMapping.java | 69 +++++++++ .../test/verbose/SelectIterableMapping.java | 31 ++++ .../ap/test/verbose/SelectMapMapping.java | 40 ++++++ .../ap/test/verbose/SelectStreamMapping.java | 31 ++++ .../ap/test/verbose/ValueMapping.java | 22 +++ .../ap/test/verbose/VerboseTest.java | 134 ++++++++++++++++++ .../testutil/WithServiceImplementation.java | 2 + .../compilation/annotation/ExpectedNote.java | 41 ++++++ .../model/CompilationOutcomeDescriptor.java | 43 ++++-- .../testutil/runner/CompilingStatement.java | 33 ++++- 37 files changed, 813 insertions(+), 26 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/AstModifyingAnnotationProcessorSaysNo.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/CreateBeanMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/CreateIterableMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/SelectBeanMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/SelectIterableMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/SelectMapMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/SelectStreamMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/ValueMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 79ce0dc097..c985a90ec4 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -223,6 +223,8 @@ When invoking javac directly, these options are passed to the compiler in the fo ${org.mapstruct.version} + + true -Amapstruct.suppressGeneratorTimestamp=true @@ -230,6 +232,9 @@ When invoking javac directly, these options are passed to the compiler in the fo -Amapstruct.suppressGeneratorVersionInfoComment=true + + -Amapstruct.verbose=true + @@ -246,7 +251,8 @@ When invoking javac directly, these options are passed to the compiler in the fo compileJava { options.compilerArgs = [ '-Amapstruct.suppressGeneratorTimestamp=true', - '-Amapstruct.suppressGeneratorVersionInfoComment=true' + '-Amapstruct.suppressGeneratorVersionInfoComment=true', + '-Amapstruct.verbose=true' ] } ... @@ -265,6 +271,10 @@ suppressGeneratorTimestamp` |If set to `true`, the creation of a time stamp in the `@Generated` annotation in the generated mapper classes is suppressed. |`false` +|`mapstruct.verbose` +|If set to `true`, MapStruct in which MapStruct logs its major decisions. Note, at the moment of writing in Maven, also `showWarnings` needs to be added due to a problem in the maven-compiler-plugin configuration. +|`false` + |`mapstruct. suppressGeneratorVersionInfoComment` |If set to `true`, the creation of the `comment` attribute in the `@Generated` annotation in the generated mapper classes is suppressed. The comment contains information about the version of MapStruct and about the compiler used for the annotation processing. diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index dc565e13b8..4878f3f989 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -82,7 +82,8 @@ MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP, MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, MappingProcessor.UNMAPPED_TARGET_POLICY, - MappingProcessor.DEFAULT_COMPONENT_MODEL + MappingProcessor.DEFAULT_COMPONENT_MODEL, + MappingProcessor.VERBOSE }) public class MappingProcessor extends AbstractProcessor { @@ -97,6 +98,7 @@ public class MappingProcessor extends AbstractProcessor { protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; + protected static final String VERBOSE = "mapstruct.verbose"; private Options options; @@ -120,7 +122,9 @@ public synchronized void init(ProcessingEnvironment processingEnv) { options = createOptions(); annotationProcessorContext = new AnnotationProcessorContext( processingEnv.getElementUtils(), - processingEnv.getTypeUtils() + processingEnv.getTypeUtils(), + processingEnv.getMessager(), + options.isVerbose() ); } @@ -132,7 +136,8 @@ private Options createOptions() { Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), - Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ) + Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), + Boolean.valueOf( processingEnv.getOptions().get( VERBOSE ) ) ); } @@ -221,6 +226,11 @@ processingEnv, options, roundContext, getDeclaredTypesNotToBeImported( mapperEle processMapperTypeElement( context, mapperElement ); } catch ( TypeHierarchyErroneousException thie ) { + if ( options.isVerbose() ) { + processingEnv.getMessager().printMessage( + Kind.NOTE, "MapStruct: referred types not available (yet), deferring mapper: " + + mapperElement ); + } deferredMappers.add( mapperElement ); } catch ( Throwable t ) { @@ -242,7 +252,7 @@ private void handleUncaughtError(Element element, Throwable thrown) { StringWriter sw = new StringWriter(); thrown.printStackTrace( new PrintWriter( sw ) ); - String reportableStacktrace = sw.toString().replace( System.getProperty( "line.separator" ), " " ); + String reportableStacktrace = sw.toString().replace( System.lineSeparator( ), " " ); processingEnv.getMessager().printMessage( Kind.ERROR, "Internal error in the mapping processor: " + reportableStacktrace, element ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index c265d9daa0..72a1eb29f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -20,6 +20,7 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; /** @@ -94,6 +95,12 @@ public final M build() { if ( assignment == null ) { assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); + if ( assignment != null ) { + ctx.getMessager().note( 2, Message.ITERABLEMAPPING_CREATE_ELEMENT_NOTE, assignment ); + } + } + else { + ctx.getMessager().note( 2, Message.ITERABLEMAPPING_SELECT_ELEMENT_NOTE, assignment ); } if ( assignment == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 42dc4ace94..961fd97783 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -23,6 +23,7 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; /** @@ -98,8 +99,13 @@ public MapMappingMethod build() { if ( keyAssignment == null ) { keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); + if ( keyAssignment != null ) { + ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_KEY_NOTE, keyAssignment ); + } + } + else { + ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_KEY_NOTE, keyAssignment ); } - if ( keyAssignment == null ) { if ( method instanceof ForgedMethod ) { @@ -150,6 +156,12 @@ public MapMappingMethod build() { if ( valueAssignment == null ) { valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); + if ( valueAssignment != null ) { + ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_VALUE_NOTE, valueAssignment ); + } + } + else { + ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_VALUE_NOTE, valueAssignment ); } if ( valueAssignment == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 7ef9766609..b95ef372d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -10,6 +10,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; @@ -19,6 +20,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; +import org.mapstruct.ap.internal.util.Strings; /** * Represents a reference to another method, e.g. used to map a bean property from source to target type or to @@ -348,4 +350,15 @@ public static MethodReference forMethodCall(String methodName) { return new MethodReference( methodName, null, false ); } + @Override + public String toString() { + String mapper = declaringMapper != null ? declaringMapper.getType().getName().toString() : ""; + String argument = getAssignment() != null ? getAssignment().toString() : getSourceReference(); + String returnTypeAsString = returnType != null ? returnType.toString() : ""; + List arguments = sourceParameters.stream() + .map( p -> p.isMappingContext() || p.isMappingTarget() || p.isTargetType() ? p.getName() : argument ) + .collect( Collectors.toList() ); + + return returnTypeAsString + " " + mapper + "#" + name + "(" + Strings.join( arguments, "," ) + ")"; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 2291504039..423b5f4b4a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -295,6 +295,9 @@ public PropertyMapping build() { // handle source this.rightHandSide = getSourceRHS( sourceReference ); + + ctx.getMessager().note( 2, Message.PROPERTYMAPPING_MAPPING_NOTE, rightHandSide, targetWriteAccessor ); + rightHandSide.setUseElementAsSourceTypeForMatching( targetWriteAccessorType == TargetWriteAccessorType.ADDER ); @@ -339,6 +342,12 @@ else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) || else { assignment = forgeMapping( rightHandSide ); } + if ( assignment != null ) { + ctx.getMessager().note( 2, Message.PROPERTYMAPPING_CREATE_NOTE, assignment ); + } + } + else { + ctx.getMessager().note( 2, Message.PROPERTYMAPPING_SELECT_NOTE, assignment ); } if ( assignment != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index d0481cdc2d..3f06ce7e85 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -140,4 +140,10 @@ public Assignment.AssignmentType getType() { public boolean isCallingUpdateMethod() { return false; } + + @Override + public String toString() { + String argument = getAssignment() != null ? getAssignment().toString() : getSourceReference(); + return openExpression + argument + closeExpression; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 77001c4815..1e555e8d37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -19,15 +19,17 @@ public class Options { private final ReportingPolicyPrism unmappedTargetPolicy; private final boolean alwaysGenerateSpi; private final String defaultComponentModel; + private final boolean verbose; public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyPrism unmappedTargetPolicy, - String defaultComponentModel, boolean alwaysGenerateSpi) { + String defaultComponentModel, boolean alwaysGenerateSpi, boolean verbose) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; this.defaultComponentModel = defaultComponentModel; this.alwaysGenerateSpi = alwaysGenerateSpi; + this.verbose = verbose; } public boolean isSuppressGeneratorTimestamp() { @@ -49,4 +51,8 @@ public String getDefaultComponentModel() { public boolean isAlwaysGenerateSpi() { return alwaysGenerateSpi; } + + public boolean isVerbose() { + return verbose; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 5168dccc1b..bc7374d391 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.processor; import java.util.Map; +import java.util.stream.IntStream; import javax.annotation.processing.Filer; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; @@ -45,7 +46,7 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir RoundContext roundContext, Map notToBeImported) { this.processingEnvironment = processingEnvironment; - this.messager = new DelegatingMessager( processingEnvironment.getMessager() ); + this.messager = new DelegatingMessager( processingEnvironment.getMessager(), options.isVerbose() ); this.accessorNaming = roundContext.getAnnotationProcessorContext().getAccessorNaming(); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); this.delegatingTypes = new TypesDecorator( processingEnvironment, versionInformation ); @@ -108,9 +109,11 @@ private static final class DelegatingMessager implements FormattingMessager { private final Messager delegate; private boolean isErroneous = false; + private final boolean verbose; - DelegatingMessager(Messager delegate) { + DelegatingMessager(Messager delegate, boolean verbose) { this.delegate = delegate; + this.verbose = verbose; } @Override @@ -155,6 +158,15 @@ public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Messa } } + public void note( int level, Message msg, Object... args ) { + if ( verbose ) { + StringBuilder builder = new StringBuilder(); + IntStream.range( 0, level ).mapToObj( i -> "-" ).forEach( builder::append ); + builder.append( " MapStruct: " ).append( String.format( msg.getDescription(), args ) ); + delegate.printMessage( Kind.NOTE, builder.toString() ); + } + } + public boolean isErroneous() { return isErroneous; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 974822216f..1b31bcf4cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -38,9 +38,9 @@ import org.mapstruct.ap.internal.model.StreamMappingMethod; import org.mapstruct.ap.internal.model.SupportingConstructorFragment; import org.mapstruct.ap.internal.model.ValueMappingMethod; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -286,6 +286,7 @@ private List getMappingMethods(MapperConfiguration mapperConfig, boolean hasFactoryMethod = false; if ( method.isIterableMapping() ) { + this.messager.note( 1, Message.ITERABLEMAPPING_CREATE_NOTE, method ); IterableMappingMethod iterableMappingMethod = createWithElementMappingMethod( method, mappingOptions, @@ -313,6 +314,7 @@ else if ( method.isMapMapping() ) { nullValueMappingStrategy = mappingOptions.getMapMapping().getNullValueMappingStrategy(); } + this.messager.note( 1, Message.MAPMAPPING_CREATE_NOTE, method ); MapMappingMethod mapMappingMethod = builder .mappingContext( mappingContext ) .method( method ) @@ -328,6 +330,7 @@ else if ( method.isMapMapping() ) { } else if ( method.isValueMapping() ) { // prefer value mappings over enum mapping + this.messager.note( 1, Message.VALUEMAPPING_CREATE_NOTE, method ); ValueMappingMethod valueMappingMethod = new ValueMappingMethod.Builder() .mappingContext( mappingContext ) .method( method ) @@ -352,6 +355,7 @@ else if ( method.isEnumMapping() ) { } } else if ( method.isStreamMapping() ) { + this.messager.note( 1, Message.STREAMMAPPING_CREATE_NOTE, method ); StreamMappingMethod streamMappingMethod = createWithElementMappingMethod( method, mappingOptions, @@ -364,8 +368,7 @@ else if ( method.isStreamMapping() ) { mappingMethods.add( streamMappingMethod ); } else { - - + this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 75f49d4214..9ba8d54d54 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -72,8 +72,14 @@ public List process(ProcessorContext context, TypeElement mapperTy this.typeUtils = context.getTypeUtils(); this.elementUtils = context.getElementUtils(); + this.messager.note( 0, Message.PROCESSING_NOTE, mapperTypeElement ); + MapperConfiguration mapperConfig = MapperConfiguration.getInstanceOn( mapperTypeElement ); + if ( mapperConfig != null ) { + this.messager.note( 0, Message.CONFIG_NOTE, mapperConfig.getClass().getName() ); + } + if ( !mapperConfig.isValid() ) { throw new AnnotationProcessingException( "Couldn't retrieve @Mapper annotation", diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index ed70cd9f9b..ae8cc62fbb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -10,8 +10,10 @@ import java.util.List; import java.util.ServiceLoader; +import javax.annotation.processing.Messager; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; +import javax.tools.Diagnostic; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; @@ -39,12 +41,16 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private AccessorNamingUtils accessorNaming; private Elements elementUtils; private Types typeUtils; + private Messager messager; + private boolean verbose; - public AnnotationProcessorContext(Elements elementUtils, Types typeUtils) { + public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messager messager, boolean verbose) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors() ); this.elementUtils = elementUtils; this.typeUtils = typeUtils; + this.messager = messager; + this.verbose = verbose; } /** @@ -64,10 +70,16 @@ private void initialize() { if ( elementUtils.getTypeElement( ImmutablesConstants.IMMUTABLE_FQN ) != null ) { defaultAccessorNamingStrategy = new ImmutablesAccessorNamingStrategy(); defaultBuilderProvider = new ImmutablesBuilderProvider(); + if ( verbose ) { + messager.printMessage( Diagnostic.Kind.NOTE, "MapStruct: Immutables found on classpath" ); + } } else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) != null ) { defaultAccessorNamingStrategy = new FreeBuilderAccessorNamingStrategy(); defaultBuilderProvider = new DefaultBuilderProvider(); + if ( verbose ) { + messager.printMessage( Diagnostic.Kind.NOTE, "MapStruct: Freebuilder found on classpath" ); + } } else { defaultAccessorNamingStrategy = new DefaultAccessorNamingStrategy(); @@ -75,8 +87,21 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! } this.accessorNamingStrategy = Services.get( AccessorNamingStrategy.class, defaultAccessorNamingStrategy ); this.accessorNamingStrategy.init( this ); + if ( verbose ) { + messager.printMessage( + Diagnostic.Kind.NOTE, + "MapStruct: Using accessor naming strategy: " + + this.accessorNamingStrategy.getClass().getCanonicalName() + ); + } this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); this.builderProvider.init( this ); + if ( verbose ) { + messager.printMessage( + Diagnostic.Kind.NOTE, + "MapStruct: Using builder provider: " + this.builderProvider.getClass().getCanonicalName() + ); + } this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); this.initialized = true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java index b3f9bd7240..2e4d287d4b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java @@ -67,4 +67,12 @@ void printMessage(Element e, AnnotationValue v, Message msg, Object... args); + + /** + * Just log as plain note + * @param level nesting level + * @param log the log message + * @param args the arguments + */ + void note(int level, Message log, Object... args); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index a718a994de..2706a33791 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -15,6 +15,10 @@ public enum Message { // CHECKSTYLE:OFF + PROCESSING_NOTE( "processing: %s.", Diagnostic.Kind.NOTE ), + CONFIG_NOTE( "applying mapper configuration: %s.", Diagnostic.Kind.NOTE ), + + BEANMAPPING_CREATE_NOTE( "creating bean mapping method implementation for %s.", Diagnostic.Kind.NOTE ), BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), @@ -31,6 +35,9 @@ public enum Message { BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), + PROPERTYMAPPING_MAPPING_NOTE( "mapping property: %s to: %s.", Diagnostic.Kind.NOTE ), + PROPERTYMAPPING_CREATE_NOTE( "creating property mapping: %s.", Diagnostic.Kind.NOTE ), + PROPERTYMAPPING_SELECT_NOTE( "selecting property mapping: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "Can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), @@ -67,10 +74,19 @@ public enum Message { CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), CONSTANTMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s for property \"%s\"." ), + MAPMAPPING_CREATE_NOTE( "creating map mapping method implementation for %s.", Diagnostic.Kind.NOTE ), MAPMAPPING_KEY_MAPPING_NOT_FOUND( "No implementation can be generated for this method. Found no method nor implicit conversion for mapping source key type to target key type." ), MAPMAPPING_VALUE_MAPPING_NOT_FOUND( "No implementation can be generated for this method. Found no method nor implicit conversion for mapping source value type to target value type." ), MAPMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', 'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, define at least one of them." ), - + MAPMAPPING_SELECT_KEY_NOTE( "selecting key mapping: %s.", Diagnostic.Kind.NOTE ), + MAPMAPPING_SELECT_VALUE_NOTE( "selecting value mapping: %s.", Diagnostic.Kind.NOTE ), + MAPMAPPING_CREATE_KEY_NOTE( "creating key mapping: %s.", Diagnostic.Kind.NOTE ), + MAPMAPPING_CREATE_VALUE_NOTE( "creating value mapping: %s.", Diagnostic.Kind.NOTE ), + + STREAMMAPPING_CREATE_NOTE( "creating stream mapping method implementation for %s.", Diagnostic.Kind.NOTE ), + ITERABLEMAPPING_CREATE_NOTE( "creating iterable mapping method implementation for %s.", Diagnostic.Kind.NOTE ), + ITERABLEMAPPING_SELECT_ELEMENT_NOTE( "selecting element mapping: %s.", Diagnostic.Kind.NOTE ), + ITERABLEMAPPING_CREATE_ELEMENT_NOTE( "creating element mapping: %s.", Diagnostic.Kind.NOTE ), ITERABLEMAPPING_MAPPING_NOT_FOUND( "No implementation can be generated for this method. Found no method nor implicit conversion for mapping source element type into target element type." ), ITERABLEMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are undefined in @IterableMapping, define at least one of them." ), @@ -128,6 +144,7 @@ public enum Message { INHERITINVERSECONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH( "More than one configuration prototype method is applicable. Use @InheritInverseConfiguration to select one of them explicitly: %s." ), INHERITCONFIGURATION_CYCLE( "Cycle detected while evaluating inherited configurations. Inheritance path: %s" ), + VALUEMAPPING_CREATE_NOTE( "creating value mapping method implementation for %s.", Diagnostic.Kind.NOTE ), VALUEMAPPING_DUPLICATE_SOURCE( "Source value mapping: \"%s\" cannot be mapped more than once." ), VALUEMAPPING_ANY_AREADY_DEFINED( "Source = \"\" or \"\" can only be used once." ), VALUE_MAPPING_UNMAPPED_SOURCES( "The following constants from the %s enum have no corresponding constant in the %s enum and must be be mapped via adding additional mappings: %s." ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java index 356313f52f..effd137b04 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java @@ -28,4 +28,9 @@ public TypeMirror getAccessedType() { public ExecutableElement getExecutable() { return element; } + + @Override + public String toString() { + return element.toString(); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java index fc8d54933e..cdbdf1f09f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java @@ -29,4 +29,9 @@ public TypeMirror getAccessedType() { public ExecutableElement getExecutable() { return null; } + + @Override + public String toString() { + return element.toString(); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java index 79d164ddb3..25cea82c8c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/IndentationCorrectingWriter.java @@ -37,7 +37,7 @@ class IndentationCorrectingWriter extends Writer { * Set to true to enable output of written characters on the console. */ private static final boolean DEBUG = false; - private static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); + private static final String LINE_SEPARATOR = System.lineSeparator( ); private static final boolean IS_WINDOWS = System.getProperty( "os.name" ).startsWith( "Windows" ); private State currentState = State.START_OF_LINE; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 9921ad2f05..f5656e2e48 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -280,4 +280,5 @@ protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeE protected boolean shouldIgnore(TypeElement typeElement) { return typeElement == null || JAVA_JAVAX_PACKAGE.matcher( typeElement.getQualifiedName() ).matches(); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java index 5b269b4b06..92fef3a1be 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java @@ -35,4 +35,5 @@ protected boolean isFluentSetter(ExecutableElement method) { // with set return false; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index abe777a1c4..69c66cdd28 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -23,4 +23,5 @@ public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrat protected boolean isFluentSetter(ExecutableElement method) { return super.isFluentSetter( method ) && !method.getSimpleName().toString().equals( "from" ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index 16ad797a92..d4ccd029ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -83,4 +83,5 @@ protected TypeElement asImmutableElement(TypeElement typeElement) { builderQualifiedName.append( "Immutable" ).append( typeElement.getSimpleName() ); return elementUtils.getTypeElement( builderQualifiedName ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java index fae086ab18..a30346c4b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/NoOpBuilderProvider.java @@ -23,5 +23,6 @@ public class NoOpBuilderProvider implements BuilderProvider { public BuilderInfo findBuilderInfo(TypeMirror type) { return null; } + } // end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 6b40de3133..76ceac40df 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -153,6 +153,11 @@ public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Messa lastKindPrinted = msg.getDiagnosticKind(); } + @Override + public void note(int level, Message msg, Object... args) { + throw new UnsupportedOperationException( "Should not be called" ); + } + public Diagnostic.Kind getLastKindPrinted() { return lastKindPrinted; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/AstModifyingAnnotationProcessorSaysNo.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/AstModifyingAnnotationProcessorSaysNo.java new file mode 100644 index 0000000000..898721b9f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/AstModifyingAnnotationProcessorSaysNo.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +public class AstModifyingAnnotationProcessorSaysNo implements AstModifyingAnnotationProcessor { + + @Override + public boolean isTypeComplete(TypeMirror type) { + return false; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateBeanMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateBeanMapping.java new file mode 100644 index 0000000000..594318d9f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateBeanMapping.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CreateBeanMapping { + + CreateBeanMapping INSTANCE = Mappers.getMapper( CreateBeanMapping.class ); + + Target map(Source source); + + class Source { + private NestedSource nested; + + public NestedSource getNested() { + return nested; + } + + public void setNested(NestedSource nested) { + this.nested = nested; + } + } + + class Target { + private NestedTarget nested; + + public NestedTarget getNested() { + return nested; + } + + public void setNested(NestedTarget nested) { + this.nested = nested; + } + } + + class NestedSource { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class NestedTarget { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateIterableMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateIterableMapping.java new file mode 100644 index 0000000000..cf06fede07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateIterableMapping.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CreateIterableMapping { + + CreateIterableMapping INSTANCE = Mappers.getMapper( CreateIterableMapping.class ); + + List map(List source); + + class SourceElement { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class TargetElement { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java new file mode 100644 index 0000000000..8156256891 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CreateMapMapping { + + CreateMapMapping INSTANCE = Mappers.getMapper( CreateMapMapping.class ); + + Map map(Map source); + + // empty beans fail.. TODO check + class SourceKey { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class SourceValue { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class TargetKey { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class TargetValue { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectBeanMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectBeanMapping.java new file mode 100644 index 0000000000..4b6d73d307 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectBeanMapping.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SelectBeanMapping { + + SelectBeanMapping INSTANCE = Mappers.getMapper( SelectBeanMapping.class ); + + Target map(Source source); + + NestedTarget map(NestedSource source); + + class Source { + private NestedSource nested; + + public NestedSource getNested() { + return nested; + } + + public void setNested(NestedSource nested) { + this.nested = nested; + } + } + + class Target { + private NestedTarget nested; + + public NestedTarget getNested() { + return nested; + } + + public void setNested(NestedTarget nested) { + this.nested = nested; + } + } + + class NestedSource { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class NestedTarget { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectIterableMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectIterableMapping.java new file mode 100644 index 0000000000..fa492cc144 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectIterableMapping.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SelectIterableMapping { + + SelectIterableMapping INSTANCE = Mappers.getMapper( SelectIterableMapping.class ); + + List map(List source); + + default TargetElement map(SourceElement sourceKey) { + return null; + } + + class SourceElement { + } + + class TargetElement { + } + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectMapMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectMapMapping.java new file mode 100644 index 0000000000..7018642ce2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectMapMapping.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SelectMapMapping { + + SelectMapMapping INSTANCE = Mappers.getMapper( SelectMapMapping.class ); + + Map map(Map source); + + default TargetKey map(SourceKey sourceKey) { + return null; + } + + default TargetValue map(SourceValue sourceValue) { + return null; + } + + class SourceKey { + } + + class SourceValue { + } + + class TargetKey { + } + + class TargetValue { + } +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectStreamMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectStreamMapping.java new file mode 100644 index 0000000000..7ee44d8b00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/SelectStreamMapping.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import java.util.stream.Stream; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SelectStreamMapping { + + SelectStreamMapping INSTANCE = Mappers.getMapper( SelectStreamMapping.class ); + + Stream map(Stream source); + + default TargetElement map(SourceElement sourceKey) { + return null; + } + + class SourceElement { + } + + class TargetElement { + } + +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/ValueMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/ValueMapping.java new file mode 100644 index 0000000000..f3e07fca8f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/ValueMapping.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ValueMapping { + + ValueMapping INSTANCE = Mappers.getMapper( ValueMapping.class ); + + TargetEnum map(SourceEnum source); + + enum TargetEnum { VALUE } + + enum SourceEnum { VALUE } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java new file mode 100644 index 0000000000..99b77b1220 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java @@ -0,0 +1,134 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.verbose; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; + +@IssueKey("37") +@RunWith(AnnotationProcessorTestRunner.class) +public class VerboseTest { + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateBeanMapping.class) + @ExpectedNote("^MapStruct: Using accessor naming strategy:.*DefaultAccessorNamingStrategy.*$") + @ExpectedNote("^MapStruct: Using builder provider:.*DefaultBuilderProvider.*$") + @ExpectedNote("^ MapStruct: processing:.*.CreateBeanMapping.*$") + @ExpectedNote("^ MapStruct: applying mapper configuration:.*MapperConfiguration.*$") + public void testGeneralMessages() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @WithServiceImplementation(provides = BuilderProvider.class, value = ImmutablesBuilderProvider.class) + @WithServiceImplementation(provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateBeanMapping.class) + @ExpectedNote("^MapStruct: Using accessor naming strategy:.*ImmutablesAccessorNamingStrategy.*$") + @ExpectedNote("^MapStruct: Using builder provider:.*ImmutablesBuilderProvider.*$") + @ExpectedNote("^ MapStruct: processing:.*.CreateBeanMapping.*$") + @ExpectedNote("^ MapStruct: applying mapper configuration:.*MapperConfiguration.*$") + public void testGeneralWithOtherSPI() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @WithServiceImplementation(provides = AstModifyingAnnotationProcessor.class, + value = AstModifyingAnnotationProcessorSaysNo.class) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateBeanMapping.class) + @ExpectedNote("^MapStruct: referred types not available \\(yet\\), deferring mapper:.*CreateBeanMapping.*$") + public void testDeferred() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateBeanMapping.class) + @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: creating property mapping.*$") + public void testCreateBeanMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(SelectBeanMapping.class) + @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: selecting property mapping.*$") + public void testSelectBeanMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(ValueMapping.class) + @ExpectedNote("^- MapStruct: creating value mapping method implementation for.*$") + public void testValueMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateIterableMapping.class) + @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: creating element mapping.*$") + public void testVerboseCreateIterableMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(SelectIterableMapping.class) + @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: selecting element mapping.*$") + public void testVerboseSelectingIterableMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(SelectStreamMapping.class) + @ExpectedNote("^- MapStruct: creating stream mapping method implementation for.*$") + public void testVerboseSelectingStreamMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(CreateMapMapping.class) + @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: creating key mapping.*$") + @ExpectedNote("^-- MapStruct: creating value mapping.*$") + public void testVerboseCreateMapMapping() { + } + + @Test + @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses(SelectMapMapping.class) + @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") + @ExpectedNote("^-- MapStruct: selecting key mapping.*$") + @ExpectedNote("^-- MapStruct: selecting value mapping.*$") + public void testVerboseSelectingMapMapping() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java index 2397667eb6..16d8ad04f6 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithServiceImplementation.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.testutil; import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @@ -17,6 +18,7 @@ */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE, ElementType.METHOD }) +@Repeatable( WithServiceImplementations.class ) public @interface WithServiceImplementation { /** * @return The service implementation class that is to be made available during the annotation processing. diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java new file mode 100644 index 0000000000..1cb95f52c2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.compilation.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * An expected {@link javax.tools.Diagnostic.Kind#NOTE}. + * + * @author Sjaak Derksen + */ + +@Repeatable(ExpectedNote.ExpectedNotes.class) +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ExpectedNote { + + String value(); + + /** + * The notes in the order they are expected + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface ExpectedNotes { + + /** + * Regexp for the note to match. + * + * @return + */ + ExpectedNote[] value(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java index cfe201f5d4..22d9bcd68e 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java @@ -8,6 +8,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.tools.Diagnostic; import javax.tools.Diagnostic.Kind; @@ -17,6 +19,7 @@ import org.codehaus.plexus.compiler.CompilerResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; /** * Represents the outcome of a compilation. @@ -25,21 +28,37 @@ */ public class CompilationOutcomeDescriptor { + private static final String LINE_SEPARATOR = System.lineSeparator( ); + private CompilationResult compilationResult; private List diagnostics; + private List notes; private CompilationOutcomeDescriptor(CompilationResult compilationResult, - List diagnostics) { + List diagnostics, + List notes) { this.compilationResult = compilationResult; this.diagnostics = diagnostics; + this.notes = notes; } public static CompilationOutcomeDescriptor forExpectedCompilationResult( - ExpectedCompilationOutcome expectedCompilationResult) { + ExpectedCompilationOutcome expectedCompilationResult, ExpectedNote.ExpectedNotes expectedNotes, + ExpectedNote expectedNote) { + List notes = new ArrayList<>(); + if ( expectedNotes != null ) { + notes.addAll( Stream.of( expectedNotes.value() ) + .map( ExpectedNote::value ) + .collect( Collectors.toList() ) ); + } + if ( expectedNote != null ) { + notes.add( expectedNote.value() ); + } if ( expectedCompilationResult == null ) { return new CompilationOutcomeDescriptor( CompilationResult.SUCCEEDED, - Collections.emptyList() + Collections.emptyList(), + notes ); } else { @@ -48,8 +67,7 @@ public static CompilationOutcomeDescriptor forExpectedCompilationResult( expectedCompilationResult.diagnostics() ) { diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) ); } - - return new CompilationOutcomeDescriptor( expectedCompilationResult.value(), diagnosticDescriptors ); + return new CompilationOutcomeDescriptor( expectedCompilationResult.value(), diagnosticDescriptors, notes ); } } @@ -57,31 +75,34 @@ public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean c List> diagnostics) { CompilationResult compilationResult = compilationSuccessful ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; - + List notes = new ArrayList<>(); List diagnosticDescriptors = new ArrayList(); for ( Diagnostic diagnostic : diagnostics ) { //ignore notes created by the compiler if ( diagnostic.getKind() != Kind.NOTE ) { diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( sourceDir, diagnostic ) ); } + else { + notes.add( diagnostic.getMessage( null ) ); + } } - return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors ); + return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors, notes ); } public static CompilationOutcomeDescriptor forResult(String sourceDir, CompilerResult compilerResult) { CompilationResult compilationResult = compilerResult.isSuccess() ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; - List diagnosticDescriptors = new ArrayList(); for ( CompilerMessage message : compilerResult.getCompilerMessages() ) { if ( message.getKind() != CompilerMessage.Kind.NOTE ) { diagnosticDescriptors.add( DiagnosticDescriptor.forCompilerMessage( sourceDir, message ) ); } + // the eclipse compiler does not support NOTE (it is never actually set). } - return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors ); + return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors, Collections.emptyList() ); } public CompilationResult getCompilationResult() { @@ -92,6 +113,10 @@ public List getDiagnostics() { return diagnostics; } + public List getNotes() { + return notes; + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index f6ddcbd2bb..a292ef6a22 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; @@ -32,6 +33,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; @@ -54,7 +56,7 @@ abstract class CompilingStatement extends Statement { private static final String TARGET_COMPILATION_TESTS = "/target/compilation-tests/"; - private static final String LINE_SEPARATOR = System.getProperty( "line.separator" ); + private static final String LINE_SEPARATOR = System.lineSeparator( ); private static final DiagnosticDescriptorComparator COMPARATOR = new DiagnosticDescriptorComparator(); @@ -175,7 +177,9 @@ protected void generateMapperImplementation() throws Exception { CompilationOutcomeDescriptor expectedResult = CompilationOutcomeDescriptor.forExpectedCompilationResult( - method.getAnnotation( ExpectedCompilationOutcome.class ) + method.getAnnotation( ExpectedCompilationOutcome.class ), + method.getAnnotation( ExpectedNote.ExpectedNotes.class ), + method.getAnnotation( ExpectedNote.class ) ); if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) { @@ -192,6 +196,7 @@ protected void generateMapperImplementation() throws Exception { } assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() ); + assertNotes( actualResult.getNotes(), expectedResult.getNotes() ); if ( runCheckstyle ) { assertCheckstyleRules(); @@ -239,6 +244,30 @@ else if ( file.isFile() ) { return files; } + private void assertNotes(List actualNotes, List expectedNotes) { + List expectedNotesRemaining = new ArrayList<>( expectedNotes ); + Iterator expectedNotesIterator = expectedNotesRemaining.iterator(); + if ( expectedNotesIterator.hasNext() ) { + String expectedNoteRegexp = expectedNotesIterator.next(); + for ( String actualNote : actualNotes ) { + if ( actualNote.matches( expectedNoteRegexp ) ) { + expectedNotesIterator.remove(); + if ( expectedNotesIterator.hasNext() ) { + expectedNoteRegexp = expectedNotesIterator.next(); + } + else { + break; + } + } + } + } + + assertThat( expectedNotesRemaining ) + .describedAs( "There are unmatched notes: " + + expectedNotesRemaining.stream().collect( Collectors.joining( LINE_SEPARATOR ) ).toString() ) + .isEmpty(); + } + private void assertDiagnostics(List actualDiagnostics, List expectedDiagnostics) { From fcf96c36ebc0663ffa3db2b7a92772ae11105737 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 19 Mar 2019 09:44:27 +0100 Subject: [PATCH 0348/1006] #1756 better forged method error based on empty target bean properties (#1757) --- .../ap/internal/model/BeanMappingMethod.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 1 - .../mapstruct/ap/internal/util/Message.java | 3 +- .../ErroneousCollectionMappingTest.java | 20 +++++++------ .../forged/CollectionMappingTest.java | 14 ++++++---- .../erroneous/ErroneousStreamMappingTest.java | 28 +++++++++++-------- .../forged/ForgedStreamMappingTest.java | 5 ++-- .../selection/generics/ConversionTest.java | 20 +++++++------ .../ap/test/verbose/CreateMapMapping.java | 1 - 9 files changed, 52 insertions(+), 42 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4e05ad5d60..502e924aac 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -749,7 +749,7 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { ForgedMethodHistory history = forgedMethod.getHistory(); ctx.getMessager().printMessage( this.method.getExecutable(), - Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, + Message.PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND, history.createSourcePropertyErrorMessage(), history.getTargetType(), history.createTargetPropertyName(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 961fd97783..72a6da85f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -196,7 +196,6 @@ public MapMappingMethod build() { .getFactoryMethod( method, method.getResultType(), null, ctx ); } - keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); valueAssignment = new LocalVarWrapper( valueAssignment, method.getThrownTypes(), valueTargetType, false ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 2706a33791..a064873da9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -39,7 +39,8 @@ public enum Message { PROPERTYMAPPING_CREATE_NOTE( "creating property mapping: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_SELECT_NOTE( "selecting property mapping: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), - PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "Can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ), + PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND( "No target bean properties found: can't map %s to \"%s %s\". Consider to declare/implement a mapping method: \"%s map(%s value)\"." ), + PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND( "No target bean properties found: can't map %s to %s. Consider to implement a mapping method: \"%s map(%s value)\"." ), PROPERTYMAPPING_DUPLICATE_TARGETS( "Target property \"%s\" must not be mapped more than once." ), PROPERTYMAPPING_EMPTY_TARGET( "Target must not be empty in @Mapping." ), PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED( "Source and constant are both defined in @Mapping, either define a source or a constant." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 8a1a138c4d..feefb92b40 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -104,9 +104,9 @@ public void shouldFailOnEmptyMapAnnotation() { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "Can't map Collection element \".*WithProperties withProperties\" to \".*NoProperties" + - " noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + - ".*WithProperties value\\)") + messageRegExp = "No target bean properties found: can't map Collection element \".*WithProperties " + + "withProperties\" to \".*NoProperties noProperties\". Consider to declare/implement " + + "a mapping method: \".*NoProperties map\\(.*WithProperties value\\)") } ) public void shouldFailOnNoElementMappingFound() { @@ -138,9 +138,10 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "Can't map Map key \".*WithProperties withProperties\" to \".*NoProperties " + - "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + - ".*WithProperties value\\)") + messageRegExp = "No target bean properties found: can't map Map key \".*WithProperties " + + "withProperties\" to " + + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: " + + "\".*NoProperties map\\(.*WithProperties value\\)" ) } ) public void shouldFailOnNoKeyMappingFound() { @@ -171,9 +172,10 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "Can't map Map value \".*WithProperties withProperties\" to \".*NoProperties " + - "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + - ".*WithProperties value\\)") + messageRegExp = "No target bean properties found: can't map Map value \".*WithProperties " + + "withProperties\" to " + + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: " + + "\".*NoProperties map\\(.*WithProperties value\\)" ) } ) public void shouldFailOnNoValueMappingFound() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 0c4480b3b9..c538318fd7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -87,8 +87,8 @@ public void shouldForgeNewMapMappingMethod() { @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't map Collection element \".* nonMappableSet\" to \".* nonMappableSet\". " - + "Consider to declare/implement a mapping method: .*."), + messageRegExp = "No target bean properties found: can't map Collection element \".* nonMappableSet\" " + + "to \".* nonMappableSet\". Consider to declare/implement a mapping method: .*." ), } ) public void shouldGenerateNonMappleMethodForSetMapping() { @@ -107,13 +107,15 @@ public void shouldGenerateNonMappleMethodForSetMapping() { @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't map Map key \".* nonMappableMap\\{:key\\}\" to \".* nonMappableMap\\{:key\\}\". " - + "Consider to declare/implement a mapping method: .*."), + messageRegExp = "No target bean properties found: can't map Map key \".* nonMappableMap\\{:key\\}\" " + + "to \".* " + + "nonMappableMap\\{:key\\}\". Consider to declare/implement a mapping method: .*." ), @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't map Map value \".* nonMappableMap\\{:value\\}\" to \".* " + - "nonMappableMap\\{:value\\}\". Consider to declare/implement a mapping method: .*."), + messageRegExp = "No target bean properties found: can't map Map value \".* " + + "nonMappableMap\\{:value\\}\" to \".* nonMappableMap\\{:value\\}\". " + + "Consider to declare/implement a mapping method: .*." ), } ) public void shouldGenerateNonMappleMethodForMapMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index e195b037e0..dfa9849f0f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -104,9 +104,10 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 24, - messageRegExp = "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties " + - "noProperties\". Consider to declare/implement a mapping method: \".*NoProperties map\\(" + - ".*WithProperties value\\)") + messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " + + "withProperties\" to \".*NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \".*NoProperties " + + "map\\(.*WithProperties value\\)" ) } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { @@ -136,10 +137,11 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = - "Can't map Stream element \".*WithProperties withProperties\" to \".*NoProperties noProperties\"." + - " Consider to declare/implement a mapping method: \".*NoProperties map\\(.*WithProperties " + - "value\\)") + messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " + + "withProperties\" to \".*NoProperties noProperties\"." + + " Consider to declare/implement a mapping method: \".*NoProperties map\\(" + + ".*WithProperties " + + "value\\)" ) } ) public void shouldFailOnNoElementMappingFoundForListToStream() { @@ -154,8 +156,9 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + - "declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + messageRegExp = "Can't map stream element \".*AttributedString\" to " + + "\".*String \". Consider to declare/implement a mapping method: \".*String " + + "map\\(.*AttributedString value\\)" ) } ) public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @@ -169,9 +172,10 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = - "Can't map Stream element \".*WithProperties withProperties\" to .*NoProperties noProperties\"." + - " Consider to declare/implement a mapping method: \".*NoProperties map(.*WithProperties value)") + messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " + + "withProperties\" to .*NoProperties noProperties\"." + + " Consider to declare/implement a mapping method: \".*NoProperties map(" + + ".*WithProperties value)" ) } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index 3737584a8b..67091f5798 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -70,9 +70,8 @@ public void shouldForgeNewIterableMappingMethod() { @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't map Stream element \".* nonMappableStream\" to \".* nonMappableStream\". " - + "Consider to declare/implement a mapping method: .*."), - } + messageRegExp = "No target bean properties found: can't map Stream element \".* nonMappableStream\" " + + "to \".* nonMappableStream\". Consider to declare/implement a mapping method: .*." ) } ) public void shouldGenerateNonMappableMethodForSetMapping() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 3d4df45bd8..d46a4b6d06 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -85,9 +85,9 @@ public void shouldApplyGenericTypeMapper() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.UpperBoundWrapper" - + " fooUpperBoundFailure\" to " - + "\"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"") + messageRegExp = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection." + + "generics.UpperBoundWrapper " + + "fooUpperBoundFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"") }) public void shouldFailOnUpperBound() { } @@ -99,7 +99,8 @@ public void shouldFailOnUpperBound() { @Diagnostic(type = ErroneousSourceTargetMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper" + messageRegExp = "No target bean properties found: can't map property " + + "\"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper" + " fooWildCardExtendsTypeAFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardExtendsTypeAFailure\"") }) @@ -113,7 +114,8 @@ public void shouldFailOnWildCardBound() { @Diagnostic(type = ErroneousSourceTargetMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics." + messageRegExp = "No target bean properties found: can't map property " + + "\"org.mapstruct.ap.test.selection.generics." + "WildCardExtendsMBWrapper " + "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " + "fooWildCardExtendsMBTypeBFailure\"") @@ -128,7 +130,8 @@ public void shouldFailOnWildCardMultipleBounds() { @Diagnostic(type = ErroneousSourceTargetMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + messageRegExp = "No target bean properties found: can't map property " + + "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + " fooWildCardSuperTypeAFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardSuperTypeAFailure\"") }) @@ -142,7 +145,8 @@ public void shouldFailOnSuperBounds1() { @Diagnostic(type = ErroneousSourceTargetMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + messageRegExp = "No target bean properties found: can't map property " + + "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" + " fooWildCardSuperTypeCFailure\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeC fooWildCardSuperTypeCFailure\"") }) @@ -161,7 +165,7 @@ public void shouldFailOnSuperBounds2() { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*NoProperties " + messageRegExp = "No target bean properties found: can't map property \".*NoProperties " + "foo\\.wrapped\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA " + "foo\\.wrapped\""), diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java index 8156256891..69dc148e69 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/CreateMapMapping.java @@ -17,7 +17,6 @@ public interface CreateMapMapping { Map map(Map source); - // empty beans fail.. TODO check class SourceKey { private String name; From 63c5fc8effdd5cbf7e3aac96d5149235fd3dcba6 Mon Sep 17 00:00:00 2001 From: juliojgd Date: Wed, 20 Mar 2019 21:37:47 +0100 Subject: [PATCH 0349/1006] Fix typo in documentation (#1760) It is "then" instead "than --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index c985a90ec4..202f216a41 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -687,7 +687,7 @@ To finish the mapping MapStruct generates code that will invoke the build method [NOTE] ====== The <> are also considered for the builder type. -E.g. If an object factory exists for our `PersonBuilder` than this factory would be used instead of the builder creation method. +E.g. If an object factory exists for our `PersonBuilder` then this factory would be used instead of the builder creation method. ====== .Person with Builder example From 39481f98c529d0be992f3d29b8aba8796d3083e6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 23 Mar 2019 21:25:08 +0100 Subject: [PATCH 0350/1006] Update checkstyle to latest version and replace deprecated methods (#1764) --- parent/pom.xml | 2 +- .../ap/testutil/runner/CompilingStatement.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 53e01718c8..3b2e0e4999 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -28,7 +28,7 @@ 3.1.0 4.0.3.RELEASE 0.26.0 - 8.14 + 8.18 1 3.11.1 diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index a292ef6a22..0b2d297384 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.stream.Collectors; +import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; import org.mapstruct.ap.testutil.WithClasses; @@ -214,10 +215,18 @@ private void assertCheckstyleRules() throws Exception { new InputSource( getClass().getClassLoader().getResourceAsStream( "checkstyle-for-generated-sources.xml" ) ), new PropertiesExpander( properties ), - true ) ); + ConfigurationLoader.IgnoredModulesOptions.OMIT + ) ); ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); - checker.addListener( new DefaultLogger( ByteStreams.nullOutputStream(), true, errorStream, true ) ); + checker.addListener( + new DefaultLogger( + ByteStreams.nullOutputStream(), + AutomaticBean.OutputStreamOptions.CLOSE, + errorStream, + AutomaticBean.OutputStreamOptions.CLOSE + ) + ); int errors = checker.process( findGeneratedFiles( new File( sourceOutputDir ) ) ); if ( errors > 0 ) { From f5ee2c6729d61d128f71078e86e92a8b47a59acb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 23 Mar 2019 21:27:15 +0100 Subject: [PATCH 0351/1006] Remove use of prerequisites from parent pom.xml (#1766) --- parent/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 3b2e0e4999..db190043a8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -91,10 +91,6 @@ - - 3.0.3 - - From 6c838e6e0c55218b217ee4bc30ca7598a10ca49f Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 23 Mar 2019 22:08:18 +0100 Subject: [PATCH 0352/1006] #1714 Qualifiers should not qualfiy when no qualfier is found (#1739) --- .../model/AbstractMappingMethodBuilder.java | 2 +- .../model/ContainerMappingMethodBuilder.java | 13 ++- .../ap/internal/model/MapMappingMethod.java | 26 +++--- .../internal/model/MappingBuilderContext.java | 28 ++++--- .../ap/internal/model/PropertyMapping.java | 27 +++--- .../source/selector/QualifierSelector.java | 7 +- .../source/selector/SelectionCriteria.java | 4 + .../creation/MappingResolverImpl.java | 82 +++++++++++-------- .../ap/test/bugs/_1714/Issue1714Mapper.java | 60 ++++++++++++++ .../ap/test/bugs/_1714/Issue1714Test.java | 34 ++++++++ .../ap/test/callbacks/BaseMapper.java | 3 + .../selection/qualifier/QualifierTest.java | 17 ++-- .../qualifier/iterable/TopologyMapper.java | 11 +++ 13 files changed, 229 insertions(+), 85 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 04c64d6066..759f22ca73 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -37,7 +37,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { } String name = getName( sourceType, targetType ); - name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getReservedNames() ); ForgedMethodHistory history = null; if ( method instanceof ForgedMethod ) { history = ( (ForgedMethod) method ).getHistory(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 72a1eb29f6..a9a501a49e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -19,6 +19,7 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -82,18 +83,22 @@ public final M build() { new HashSet<>(), errorMessagePart ); + + SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, + callingContextTargetPropertyName, + false + ); + Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, targetElementType, - callingContextTargetPropertyName, formattingParameters, - selectionParameters, + criteria, sourceRHS, - false, null ); - if ( assignment == null ) { + if ( assignment == null && !criteria.hasQualfiers() ) { assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); if ( assignment != null ) { ctx.getMessager().note( 2, Message.ITERABLEMAPPING_CREATE_ELEMENT_NOTE, assignment ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 72a6da85f0..b08fea5775 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -22,10 +20,13 @@ import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one {@code Map} type to another. Keys and * values are mapped either by a {@link TypeConversion} or another mapping method if required. @@ -86,18 +87,20 @@ public MapMappingMethod build() { Type keyTargetType = resultTypeParams.get( 0 ).getTypeBound(); SourceRHS keySourceRHS = new SourceRHS( "entry.getKey()", keySourceType, new HashSet<>(), "map key" ); + + SelectionCriteria keyCriteria = + SelectionCriteria.forMappingMethods( keySelectionParameters, null, false ); + Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method, keyTargetType, - null, // there is no targetPropertyName keyFormattingParameters, - keySelectionParameters, + keyCriteria, keySourceRHS, - false, null ); - if ( keyAssignment == null ) { + if ( keyAssignment == null && !keyCriteria.hasQualfiers( ) ) { keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); if ( keyAssignment != null ) { ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_KEY_NOTE, keyAssignment ); @@ -133,14 +136,16 @@ public MapMappingMethod build() { SourceRHS valueSourceRHS = new SourceRHS( "entry.getValue()", valueSourceType, new HashSet<>(), "map value" ); + + SelectionCriteria valueCriteria = + SelectionCriteria.forMappingMethods( valueSelectionParameters, null, false ); + Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method, valueTargetType, - null, // there is no targetPropertyName valueFormattingParameters, - valueSelectionParameters, + valueCriteria, valueSourceRHS, - false, null ); @@ -154,7 +159,7 @@ public MapMappingMethod build() { } } - if ( valueAssignment == null ) { + if ( valueAssignment == null && !valueCriteria.hasQualfiers( ) ) { valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); if ( valueAssignment != null ) { ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_VALUE_NOTE, valueAssignment ); @@ -221,6 +226,7 @@ public MapMappingMethod build() { protected boolean shouldUsePropertyNamesInHistory() { return true; } + } private MapMappingMethod(Method method, Collection existingVariableNames, Assignment keyAssignment, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 3ce85d1272..bbbf69dbdc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -23,8 +24,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -76,11 +77,10 @@ public interface MappingResolver { * * @param mappingMethod target mapping method * @param targetType return type to match - * @param targetPropertyName name of the target property * @param formattingParameters used for formatting dates and numbers - * @param selectionParameters parameters used in the selection process + * @param criteria parameters criteria in the selection process * @param sourceRHS source information - * @param preferUpdateMethods selection should prefer update methods when present. + * @param positionHint the mirror for reporting problems * * @return an assignment to a method parameter, which can either be: *
        @@ -90,10 +90,10 @@ public interface MappingResolver { *
      1. null, no assignment found
      2. *
      */ - Assignment getTargetAssignment(Method mappingMethod, Type targetType, String targetPropertyName, + Assignment getTargetAssignment(Method mappingMethod, Type targetType, FormattingParameters formattingParameters, - SelectionParameters selectionParameters, SourceRHS sourceRHS, - boolean preferUpdateMethods, AnnotationMirror mirror); + SelectionCriteria criteria, SourceRHS sourceRHS, + AnnotationMirror positionHint); Set getUsedSupportedMappings(); } @@ -191,12 +191,18 @@ public List getMappingsToGenerate() { return mappingsToGenerate; } - public List getNamesOfMappingsToGenerate() { - List nameList = new ArrayList<>(); + public List getReservedNames() { + Set nameSet = new HashSet<>(); for ( MappingMethod method : mappingsToGenerate ) { - nameList.add( method.getName() ); + nameSet.add( method.getName() ); } - return nameList; + // add existing names + for ( SourceMethod method : sourceModel) { + if ( method.isAbstract() ) { + nameSet.add( method.getName() ); + } + } + return new ArrayList<>( nameSet ); } public MappingMethod getExistingMappingMethod(MappingMethod newMappingMethod) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 423b5f4b4a..2f892e6b5e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -36,6 +36,7 @@ import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; @@ -310,24 +311,27 @@ public PropertyMapping build() { preferUpdateMethods = method.getMappingTargetParameter() != null; } + SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, + targetPropertyName, + preferUpdateMethods + ); + // forge a method instead of resolving one when there are mapping options. Assignment assignment = null; if ( forgeMethodWithMappingOptions == null ) { assignment = ctx.getMappingResolver().getTargetAssignment( method, targetType, - targetPropertyName, formattingParameters, - selectionParameters, + criteria, rightHandSide, - preferUpdateMethods, positionHint ); } Type sourceType = rightHandSide.getSourceType(); // No mapping found. Try to forge a mapping - if ( assignment == null ) { + if ( assignment == null && !criteria.hasQualfiers() ) { if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) { assignment = forgeIterableMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); } @@ -595,7 +599,7 @@ else if ( propertyEntries.size() == 1 ) { // forge a method from the parameter type to the last entry type. String forgedName = Strings.joinAndCamelize( sourceReference.getElementNames() ); - forgedName = Strings.getSafeVariableName( forgedName, ctx.getNamesOfMappingsToGenerate() ); + forgedName = Strings.getSafeVariableName( forgedName, ctx.getReservedNames() ); ForgedMethod methodRef = new ForgedMethod( forgedName, sourceReference.getParameter().getType(), @@ -699,7 +703,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, ExecutableElement element, String suffix) { String name = getName( sourceType, targetType ); - name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getReservedNames() ); // copy mapper configuration from the source method, its the same mapper MapperConfiguration config = method.getMapperConfiguration(); @@ -751,7 +755,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { } String name = getName( sourceType, targetType ); - name = Strings.getSafeVariableName( name, ctx.getNamesOfMappingsToGenerate() ); + name = Strings.getSafeVariableName( name, ctx.getReservedNames() ); List parameters = new ArrayList<>( method.getContextParameters() ); Type returnType; @@ -873,16 +877,19 @@ public PropertyMapping build() { } Type sourceType = ctx.getTypeFactory().getTypeForLiteral( baseForLiteral ); + SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, + targetPropertyName, + method.getMappingTargetParameter() != null + ); + Assignment assignment = null; if ( !targetType.isEnumType() ) { assignment = ctx.getMappingResolver().getTargetAssignment( method, targetType, - targetPropertyName, formattingParameters, - selectionParameters, + criteria, new SourceRHS( constantExpression, sourceType, existingVariableNames, sourceErrorMessagePart ), - method.getMappingTargetParameter() != null, positionHint ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 803e6a08d2..5c24e423ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -138,12 +138,7 @@ public List> getMatchingMethods(Method mapp matches.add( candidate ); } } - if ( !matches.isEmpty() ) { - return matches; - } - else { - return methods; - } + return matches; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 132358ec34..c632fec6c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -90,6 +90,10 @@ public void setPreferUpdateMapping(boolean preferUpdateMapping) { this.preferUpdateMapping = preferUpdateMapping; } + public boolean hasQualfiers() { + return !qualifiedByNames.isEmpty() || !qualifiers.isEmpty(); + } + public static SelectionCriteria forMappingMethods(SelectionParameters selectionParameters, String targetPropertyName, boolean preferUpdateMapping) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 9938beff16..6218cbcd1d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -37,7 +37,6 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; @@ -95,12 +94,10 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T } @Override - public Assignment getTargetAssignment(Method mappingMethod, Type targetType, String targetPropertyName, - FormattingParameters formattingParameters, SelectionParameters selectionParameters, SourceRHS sourceRHS, - boolean preferUpdateMapping, AnnotationMirror positionHint) { - - SelectionCriteria criteria = - SelectionCriteria.forMappingMethods( selectionParameters, targetPropertyName, preferUpdateMapping ); + public Assignment getTargetAssignment(Method mappingMethod, Type targetType, + FormattingParameters formattingParameters, + SelectionCriteria criteria, SourceRHS sourceRHS, + AnnotationMirror positionHint) { ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, @@ -182,12 +179,13 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { } // then direct assignable - if ( sourceType.isAssignableTo( targetType ) || + if ( !hasQualfiers() ) { + if ( sourceType.isAssignableTo( targetType ) || isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) { - Assignment simpleAssignment = sourceRHS; - return simpleAssignment; + Assignment simpleAssignment = sourceRHS; + return simpleAssignment; + } } - // At this point the SourceType will either // 1. be a String // 2. or when its a primitive / wrapped type and analysis successful equal to its TargetType. But in that @@ -196,25 +194,29 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { // in NativeType is not successful. We don't want to go through type conversion, double mappings etc. // with something that we already know to be wrong. if ( sourceType.isLiteral() - && "java.lang.String".equals( sourceType.getFullyQualifiedName( ) ) + && "java.lang.String".equals( sourceType.getFullyQualifiedName() ) && targetType.isNative() ) { return null; } // then type conversion - ConversionAssignment conversion = resolveViaConversion( sourceType, targetType ); - if ( conversion != null ) { - conversion.reportMessageWhenNarrowing( messager, this ); - conversion.getAssignment().setAssignment( sourceRHS ); - return conversion.getAssignment(); + if ( !hasQualfiers() ) { + ConversionAssignment conversion = resolveViaConversion( sourceType, targetType ); + if ( conversion != null ) { + conversion.reportMessageWhenNarrowing( messager, this ); + conversion.getAssignment().setAssignment( sourceRHS ); + return conversion.getAssignment(); + } } // check for a built-in method - Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); - if ( builtInMethod != null ) { - builtInMethod.setAssignment( sourceRHS ); - usedSupportedMappings.addAll( supportingMethodCandidates ); - return builtInMethod; + if (!hasQualfiers() ) { + Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); + if ( builtInMethod != null ) { + builtInMethod.setAssignment( sourceRHS ); + usedSupportedMappings.addAll( supportingMethodCandidates ); + return builtInMethod; + } } // 2 step method, first: method(method(source)) @@ -235,7 +237,7 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { selectionCriteria.setPreferUpdateMapping( false ); // 2 step method, finally: conversion(method(source)) - conversion = resolveViaMethodAndConversion( sourceType, targetType ); + ConversionAssignment conversion = resolveViaMethodAndConversion( sourceType, targetType ); if ( conversion != null ) { usedSupportedMappings.addAll( supportingMethodCandidates ); return conversion.getAssignment(); @@ -245,6 +247,10 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { return null; } + private boolean hasQualfiers() { + return selectionCriteria != null && selectionCriteria.hasQualfiers(); + } + private ConversionAssignment resolveViaConversion(Type sourceType, Type targetType) { ConversionProvider conversionProvider = conversions.getConversion( sourceType, targetType ); @@ -379,9 +385,9 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { * * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) * - * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in - * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt - * is done to find a matching type conversion. + * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt + * is done to find a matching type conversion. */ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetType) { @@ -503,7 +509,8 @@ private SelectedMethod getBestMatch(List methods, Type if ( candidates.size() > 1 ) { if ( sourceRHS.getSourceErrorMessagePart() != null ) { - messager.printMessage( mappingMethod.getExecutable(), + messager.printMessage( + mappingMethod.getExecutable(), positionHint, Message.GENERAL_AMBIGIOUS_MAPPING_METHOD, sourceRHS.getSourceErrorMessagePart(), @@ -512,7 +519,8 @@ private SelectedMethod getBestMatch(List methods, Type ); } else { - messager.printMessage( mappingMethod.getExecutable(), + messager.printMessage( + mappingMethod.getExecutable(), positionHint, Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, returnType, @@ -535,7 +543,8 @@ private Assignment getMappingMethodReference(SelectedMethod method, return MethodReference.forMapperReference( method.getMethod(), mapperReference, - method.getParameterBindings() ); + method.getParameterBindings() + ); } /** @@ -546,14 +555,14 @@ private boolean isAssignableThroughCollectionCopyConstructor(Type sourceType, Ty boolean bothCollectionOrMap = false; if ( ( sourceType.isCollectionType() && targetType.isCollectionType() ) || - ( sourceType.isMapType() && targetType.isMapType() ) ) { + ( sourceType.isMapType() && targetType.isMapType() ) ) { bothCollectionOrMap = true; } if ( bothCollectionOrMap ) { return hasCompatibleCopyConstructor( - sourceType, - targetType.getImplementationType() != null ? targetType.getImplementationType() : targetType + sourceType, + targetType.getImplementationType() != null ? targetType.getImplementationType() : targetType ); } @@ -565,8 +574,9 @@ private boolean isAssignableThroughCollectionCopyConstructor(Type sourceType, Ty * * @param sourceType the source type * @param targetType the target type + * * @return {@code true} if the target type has a constructor accepting the given source type, {@code false} - * otherwise. + * otherwise. */ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { if ( targetType.isPrimitive() ) { @@ -584,7 +594,8 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { // get the constructor resolved against the type arguments of specific target type ExecutableType typedConstructor = (ExecutableType) typeUtils.asMemberOf( (DeclaredType) targetType.getTypeMirror(), - constructor ); + constructor + ); TypeMirror parameterType = Collections.first( typedConstructor.getParameterTypes() ); if ( parameterType.getKind() == TypeKind.DECLARED ) { @@ -603,7 +614,8 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { } parameterType = typeUtils.getDeclaredType( (TypeElement) p.asElement(), - typeArguments.toArray( new TypeMirror[typeArguments.size()] ) ); + typeArguments.toArray( new TypeMirror[typeArguments.size()] ) + ); } if ( typeUtils.isAssignable( sourceType.getTypeMirror(), parameterType ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java new file mode 100644 index 0000000000..0273457e8a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java @@ -0,0 +1,60 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1714; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue1714Mapper { + + Issue1714Mapper INSTANCE = Mappers.getMapper( Issue1714Mapper.class ); + + @Mapping(source = "programInstance", target = "seasonNumber", qualifiedByName = "getSeasonNumber") + OfferEntity map(OnDemand offerStatusDTO); + + @Named("getTitle") + default String mapTitle(Program programInstance) { + return "dont care"; + } + + @Named("getSeasonNumber") + default Integer mapSeasonNumber(Program programInstance) { + return 1; + } + + class OfferEntity { + + private String seasonNumber; + + public String getSeasonNumber() { + return seasonNumber; + } + + public void setSeasonNumber(String seasonNumber) { + this.seasonNumber = seasonNumber; + } + + } + + class OnDemand { + + private Program programInstance; + + public Program getProgramInstance() { + return programInstance; + } + + public void setProgramInstance(Program programInstance) { + this.programInstance = programInstance; + } + } + + class Program { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java new file mode 100644 index 0000000000..88a7848c84 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1714; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1714") +@WithClasses({ + Issue1714Mapper.class +}) +public class Issue1714Test { + + @Test + public void codeShouldBeGeneratedCorrectly() { + + Issue1714Mapper.OnDemand source = new Issue1714Mapper.OnDemand(); + source.setProgramInstance( new Issue1714Mapper.Program() ); + + Issue1714Mapper.OfferEntity result = Issue1714Mapper.INSTANCE.map( source ); + + assertThat( result.getSeasonNumber() ).isEqualTo( "1" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java index 11e5e515f3..bee462accc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java @@ -21,6 +21,9 @@ public abstract class BaseMapper { public abstract Target sourceToTarget(Source source); + @Qualified + public abstract Target sourceToTargetQualified(Source source); + private static final List INVOCATIONS = new ArrayList(); @BeforeMapping diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 6d20d1a45b..1d298f94d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -96,14 +96,15 @@ public void shouldMatchClassAndMethod() { ErroneousMapper.class } ) @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ErroneousMapper.class, - kind = Kind.ERROR, - line = 28, - messageRegExp = "Ambiguous mapping methods found for mapping property " - + "\"java.lang.String title\" to java.lang.String.*" ) - } + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapper.class, + kind = Kind.ERROR, + line = 28, + messageRegExp = + "Can't map property \"java.lang.String title\" to \"java.lang.String title\". " + + "Consider to declare/implement a mapping method: \"java.lang.String map(java.lang.String value)*") + } ) public void shouldNotProduceMatchingMethod() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java index e1c8190b7f..22e87dd084 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java @@ -9,6 +9,9 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.util.List; + +import org.mapstruct.IterableMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Qualifier; @@ -29,6 +32,14 @@ public abstract class TopologyMapper { @Mapping( target = "topologyFeatures", qualifiedBy = Cities.class ) public abstract TopologyEntity mapTopologyAsCity(TopologyDto dto); + @Rivers + @IterableMapping( qualifiedBy = Rivers.class ) + public abstract List mapTopologiesAsRiver(List in); + + @Cities + @IterableMapping( qualifiedBy = Cities.class ) + public abstract List mapTopologiesAsCities(List in); + @Rivers protected TopologyFeatureEntity mapRiver( TopologyFeatureDto dto ) { TopologyFeatureEntity topologyFeatureEntity = null; From 3790f1919a4a22907ff4a60422b2c79ef663817d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 Mar 2019 09:47:35 +0100 Subject: [PATCH 0353/1006] Make hickory an optional dependency as well (#1765) Using optional because IntelliJ is picking up hickory as a transitive dependency and runs the hickory processor in projects using mapstruct-processor. This happens only when the processor is defined in the maven-compiler annotationProcessorPaths. This is related to https://youtrack.jetbrains.com/issue/IDEA-200481. --- processor/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/processor/pom.xml b/processor/pom.xml index 538237e7d6..4f792da14a 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -36,10 +36,14 @@ + com.jolira hickory provided + true ${project.groupId} From 7e112ccc2f27f55fd73c176d37c4c3824a633c43 Mon Sep 17 00:00:00 2001 From: power721 Date: Thu, 4 Apr 2019 02:21:08 +0800 Subject: [PATCH 0354/1006] Fix typo and code error in documentation (#1779) * fix typo in documentation "Using builders" * fix generated code example in stream mapping --- documentation/src/main/asciidoc/mapping-streams.asciidoc | 4 ++-- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/mapping-streams.asciidoc b/documentation/src/main/asciidoc/mapping-streams.asciidoc index a52a569c0c..ccc3e56854 100644 --- a/documentation/src/main/asciidoc/mapping-streams.asciidoc +++ b/documentation/src/main/asciidoc/mapping-streams.asciidoc @@ -41,7 +41,7 @@ public Set integerStreamToStringSet(Stream integers) { return null; } - return integers.stream().map( integer -> String.valueOf( integer ) ) + return integers.map( integer -> String.valueOf( integer ) ) .collect( Collectors.toCollection( HashSet::new ) ); } @@ -51,7 +51,7 @@ public List carsToCarDtos(Stream cars) { return null; } - return integers.stream().map( car -> carToCarDto( car ) ) + return cars.map( car -> carToCarDto( car ) ) .collect( Collectors.toCollection( ArrayList::new ) ); } ---- diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 202f216a41..87e2934fc4 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -666,7 +666,7 @@ project on GitHub. MapStruct also supports mapping of immutable types via builders. When performing a mapping MapStruct checks if there is a builder for the type being mapped. This is done via the `BuilderProvider` SPI. -If a Builder exists for a certain type, than that builder will be used for the mappings. +If a Builder exists for a certain type, then that builder will be used for the mappings. The default implementation of the `BuilderProvider` assumes the following: From 3ca4c3fcefd02c0b7924ec5cbdfef2813de9004e Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Wed, 3 Apr 2019 20:29:10 +0200 Subject: [PATCH 0355/1006] Update Readme --- readme.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index bd180d7d6a..cbd410ab10 100644 --- a/readme.md +++ b/readme.md @@ -51,14 +51,16 @@ At compile time MapStruct will generate an implementation of this interface. The ## Requirements -MapStruct requires Java 1.6 or later. +MapStruct requires Java 1.8 or later. ## Using MapStruct -MapStruct works in command line builds (plain javac, via Maven, Gradle, Ant etc.) and IDEs. +MapStruct works in command line builds (plain javac, via Maven, Gradle, Ant, etc.) and IDEs. For Eclipse, a dedicated plug-in is in development (see https://github.com/mapstruct/mapstruct-eclipse). It goes beyond what's possible with an annotation processor, providing content assist for annotation attributes, quick fixes and more. +For IntelliJ the plug-in is available within the IntelliJ marketplace (see https://plugins.jetbrains.com/plugin/10036-mapstruct-support). + ### Maven For Maven-based projects, add the following to your POM file in order to use MapStruct (the dependencies are available at Maven Central): @@ -82,7 +84,7 @@ For Maven-based projects, add the following to your POM file in order to use Map org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.8.0 1.8 1.8 From f82522fa774c8f7e309717f5230bb01841c247ba Mon Sep 17 00:00:00 2001 From: Christian Bandowski Date: Sun, 7 Apr 2019 18:56:05 +0200 Subject: [PATCH 0356/1006] [#1457] Stricter matching for lifecycle methods / non-unique parameters (#1782) In case a lifecycle method has multiple matching parameters (e. g. same type) all parameter names must match exactly with the ones from the mapping method, otherwise the lifecycle method will not be used and a warning will be shown. --- .../model/LifecycleMethodResolver.java | 2 +- .../model/ObjectFactoryMethodResolver.java | 7 +- .../source/selector/MethodSelectors.java | 7 +- .../model/source/selector/TypeSelector.java | 146 +++++++++++++++--- .../creation/MappingResolverImpl.java | 2 +- .../mapstruct/ap/internal/util/Message.java | 2 + .../ap/test/bugs/_1457/BookMapper.java | 47 ++++++ .../_1457/DifferentOrderingBookMapper.java | 27 ++++ .../test/bugs/_1457/ErroneousBookMapper.java | 27 ++++ .../ap/test/bugs/_1457/Issue1457Test.java | 123 +++++++++++++++ .../bugs/_1457/ObjectFactoryBookMapper.java | 29 ++++ .../ap/test/bugs/_1457/SourceBook.java | 27 ++++ .../ap/test/bugs/_1457/TargetBook.java | 83 ++++++++++ 13 files changed, 497 insertions(+), 32 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/BookMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/DifferentOrderingBookMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ErroneousBookMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ObjectFactoryBookMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/SourceBook.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/TargetBook.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index de7ebe13fc..64eee60517 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -91,7 +91,7 @@ private static List collectLifecycleCallbackMe MappingBuilderContext ctx, Set existingVariableNames) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); Type targetType = method.getResultType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 8fda20a35e..17d5135b00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -5,11 +5,8 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.List; - import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -26,6 +23,8 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * * @author Sjaak Derksen @@ -52,7 +51,7 @@ public static MethodReference getFactoryMethod( Method method, MappingBuilderContext ctx) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); List> matchingFactoryMethods = selectors.getMatchingMethods( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index d5f2042931..e0f7d0328c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -8,13 +8,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; - import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.util.FormattingMessager; /** * Applies all known {@link MethodSelector}s in order. @@ -25,10 +25,11 @@ public class MethodSelectors { private final List selectors; - public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeFactory) { + public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, + FormattingMessager messager) { selectors = Arrays.asList( new MethodFamilySelector(), - new TypeSelector( typeFactory ), + new TypeSelector( typeFactory, messager ), new QualifierSelector( typeUtils, elementUtils ), new TargetTypeSelector( typeUtils, elementUtils ), new XmlElementDeclSelector( typeUtils ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 178e4a3ff4..c00a90760d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -5,10 +5,9 @@ */ package org.mapstruct.ap.internal.model.source.selector; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; @@ -17,6 +16,10 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.MethodMatcher; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; + +import static org.mapstruct.ap.internal.util.Collections.first; /** * Selects those methods from the given input set which match the given source and target types (via @@ -27,9 +30,11 @@ public class TypeSelector implements MethodSelector { private TypeFactory typeFactory; + private FormattingMessager messager; - public TypeSelector(TypeFactory typeFactory) { + public TypeSelector(TypeFactory typeFactory, FormattingMessager messager) { this.typeFactory = typeFactory; + this.messager = messager; } @Override @@ -63,7 +68,7 @@ public List> getMatchingMethods(Method mapp if ( parameterBindingPermutations != null ) { SelectedMethod matchingMethod = - getFirstMatchingParameterBinding( targetType, method, parameterBindingPermutations ); + getMatchingParameterBinding( targetType, mappingMethod, method, parameterBindingPermutations ); if ( matchingMethod != null ) { result.add( matchingMethod ); @@ -77,7 +82,6 @@ private List getAvailableParameterBindingsFromMethod(Method me SourceRHS sourceRHS) { List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); - addMappingTargetAndTargetTypeBindings( availableParams, targetType ); if ( sourceRHS != null ) { availableParams.addAll( ParameterBinding.fromParameters( method.getContextParameters() ) ); availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); @@ -86,6 +90,8 @@ private List getAvailableParameterBindingsFromMethod(Method me availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); } + addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + return availableParams; } @@ -94,8 +100,6 @@ private List getAvailableParameterBindingsFromSourceTypes(List List availableParams = new ArrayList<>( sourceTypes.size() + 2 ); - addMappingTargetAndTargetTypeBindings( availableParams, targetType ); - for ( Type sourceType : sourceTypes ) { availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); } @@ -106,24 +110,124 @@ private List getAvailableParameterBindingsFromSourceTypes(List } } + addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + return availableParams; } + /** + * Adds default parameter bindings for the mapping-target and target-type if not already available. + * + * @param availableParams Already available params, new entries will be added to this list + * @param targetType Target type + */ private void addMappingTargetAndTargetTypeBindings(List availableParams, Type targetType) { - availableParams.add( ParameterBinding.forMappingTargetBinding( targetType ) ); - availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); + boolean mappingTargetAvailable = false; + boolean targetTypeAvailable = false; + + // search available parameter bindings if mapping-target and/or target-type is available + for ( ParameterBinding pb : availableParams ) { + if ( pb.isMappingTarget() ) { + mappingTargetAvailable = true; + } + else if ( pb.isTargetType() ) { + targetTypeAvailable = true; + } + } + + if ( !mappingTargetAvailable ) { + availableParams.add( ParameterBinding.forMappingTargetBinding( targetType ) ); + } + if ( !targetTypeAvailable ) { + availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); + } + } + + private SelectedMethod getMatchingParameterBinding(Type targetType, + Method mappingMethod, SelectedMethod selectedMethodInfo, + List> parameterAssignmentVariants) { + + List> matchingParameterAssignmentVariants = new ArrayList<>( + parameterAssignmentVariants + ); + + Method selectedMethod = selectedMethodInfo.getMethod(); + + // remove all assignment variants that doesn't match the types from the method + matchingParameterAssignmentVariants.removeIf( parameterAssignments -> + !selectedMethod.matches( extractTypes( parameterAssignments ), targetType ) + ); + + if ( matchingParameterAssignmentVariants.isEmpty() ) { + // no matching variants found + return null; + } + else if ( matchingParameterAssignmentVariants.size() == 1 ) { + // we found exactly one set of variants, use this + selectedMethodInfo.setParameterBindings( first( matchingParameterAssignmentVariants ) ); + return selectedMethodInfo; + } + + // more than one variant matches, try to find one where also the parameter names are matching + // -> remove all variants where the binding var-name doesn't match the var-name of the parameter + List methodParameters = selectedMethod.getParameters(); + + matchingParameterAssignmentVariants.removeIf( parameterBindings -> + parameterBindingNotMatchesParameterVariableNames( + parameterBindings, + methodParameters + ) + ); + + + if ( matchingParameterAssignmentVariants.isEmpty() ) { + // we had some matching assignments before, but when checking the parameter names we can't find an + // appropriate one, in this case the user must chose identical parameter names for the mapping and lifecycle + // method + messager.printMessage( + selectedMethod.getExecutable(), + Message.LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS, + mappingMethod + ); + + return null; + } + + // there should never be more then one assignment left after checking the parameter names as it is not possible + // to use the same parameter name more then once + // -> we can use the first variant that is left (that should also be the only one) + selectedMethodInfo.setParameterBindings( first( matchingParameterAssignmentVariants ) ); + return selectedMethodInfo; } - private SelectedMethod getFirstMatchingParameterBinding(Type targetType, - SelectedMethod method, List> parameterAssignmentVariants) { + /** + * Checks if the given parameter-bindings have the same variable name than the given parameters.
      + * The first entry in the parameter-bindings belongs to the first entry in the parameters and so on.
      + * + * @param parameterBindings List of parameter bindings + * @param parameters List of parameters, must have the same size than the {@code parameterBindings} list + * + * @return {@code true} as soon as there is a parameter with a different variable name than the binding + */ + private boolean parameterBindingNotMatchesParameterVariableNames(List parameterBindings, + List parameters) { + if ( parameterBindings.size() != parameters.size() ) { + return true; + } + + int i = 0; + for ( ParameterBinding parameterBinding : parameterBindings ) { + Parameter parameter = parameters.get( i++ ); - for ( List parameterAssignments : parameterAssignmentVariants ) { - if ( method.getMethod().matches( extractTypes( parameterAssignments ), targetType ) ) { - method.setParameterBindings( parameterAssignments ); - return method; + // if the parameterBinding contains a parameter name we must ensure that this matches the name from the + // method parameter -> remove all variants where this is not the case + if ( parameterBinding.getVariableName() != null && + !parameter.getName().equals( parameterBinding.getVariableName() ) ) { + return true; } } - return null; + + return false; } /** @@ -200,12 +304,8 @@ private static List findCandidateBindingsForParameter(List extractTypes(List parameters) { - List result = new ArrayList<>( parameters.size() ); - - for ( ParameterBinding param : parameters ) { - result.add( param.getType() ); - } - - return result; + return parameters.stream() + .map( ParameterBinding::getType ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 6218cbcd1d..d9e8748932 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -90,7 +90,7 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T this.conversions = new Conversions( elementUtils, typeFactory ); this.builtInMethods = new BuiltInMappingMethods( typeFactory ); - this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, typeFactory ); + this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, typeFactory, messager ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index a064873da9..a7e6159bb1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -98,6 +98,8 @@ public enum Message { ENUMMAPPING_UNMAPPED_SOURCES( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: %s." ), ENUMMAPPING_DEPRECATED( "Mapping of Enums via @Mapping is going to be removed in future versions of MapStruct. Please use @ValueMapping instead!", Diagnostic.Kind.WARNING ), + LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), + DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ), DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/BookMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/BookMapper.java new file mode 100644 index 0000000000..bbef1fe3a8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/BookMapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public abstract class BookMapper { + + public static final BookMapper INSTANCE = Mappers.getMapper( BookMapper.class ); + + public abstract TargetBook mapBook(SourceBook sourceBook, String authorFirstName, String authorLastName); + + @AfterMapping + protected void fillAuthor(@MappingTarget TargetBook targetBook, String authorFirstName, String authorLastName) { + targetBook.setAuthorFirstName( authorFirstName ); + targetBook.setAuthorLastName( authorLastName ); + } + + @AfterMapping + protected void withoutAuthorNames(@MappingTarget TargetBook targetBook) { + targetBook.setAfterMappingWithoutAuthorName( true ); + } + + @AfterMapping + protected void withOnlyFirstName(@MappingTarget TargetBook targetBook, String authorFirstName) { + targetBook.setAfterMappingWithOnlyFirstName( authorFirstName ); + } + + @AfterMapping + protected void withOnlyLastName(@MappingTarget TargetBook targetBook, String authorLastName) { + targetBook.setAfterMappingWithOnlyLastName( authorLastName ); + } + + @AfterMapping + protected void withDifferentVariableName(@MappingTarget TargetBook targetBook, String author) { + targetBook.setAfterMappingWithDifferentVariableName( true ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/DifferentOrderingBookMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/DifferentOrderingBookMapper.java new file mode 100644 index 0000000000..c2ac556bab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/DifferentOrderingBookMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public abstract class DifferentOrderingBookMapper { + + public static final DifferentOrderingBookMapper INSTANCE = Mappers.getMapper( DifferentOrderingBookMapper.class ); + + public abstract TargetBook mapBook(SourceBook sourceBook, String authorFirstName, String authorLastName); + + @AfterMapping + protected void fillAuthor(String authorLastName, String authorFirstName, @MappingTarget TargetBook targetBook) { + targetBook.setAuthorLastName( authorLastName ); + targetBook.setAuthorFirstName( authorFirstName ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ErroneousBookMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ErroneousBookMapper.java new file mode 100644 index 0000000000..a7314bbbad --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ErroneousBookMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public abstract class ErroneousBookMapper { + + public static final ErroneousBookMapper INSTANCE = Mappers.getMapper( ErroneousBookMapper.class ); + + public abstract TargetBook mapBook(SourceBook sourceBook, String authorFirstName, String authorLastName); + + @AfterMapping + protected void fillAuthor(@MappingTarget TargetBook targetBook, String authorFirstN, String authorLastN) { + targetBook.setAuthorFirstName( authorFirstN ); + targetBook.setAuthorLastName( authorLastN ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java new file mode 100644 index 0000000000..6d30ce345d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java @@ -0,0 +1,123 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + SourceBook.class, + TargetBook.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1457") +public class Issue1457Test { + + private SourceBook sourceBook; + private String authorFirstName; + private String authorLastName; + + @Before + public void setup() { + sourceBook = new SourceBook(); + sourceBook.setIsbn( "3453146972" ); + sourceBook.setTitle( "Per Anhalter durch die Galaxis" ); + + authorFirstName = "Douglas"; + authorLastName = "Adams"; + } + + @Test + @WithClasses({ + BookMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = @Diagnostic( + messageRegExp = + "Lifecycle method has multiple matching parameters \\(e\\. g\\. same type\\), in this case " + + "please ensure to name the parameters in the lifecycle and mapping method identical\\. This " + + "lifecycle method will not be used for the mapping method '.*\\.TargetBook mapBook\\(" + + ".*\\.SourceBook sourceBook, .*\\.String authorFirstName, .*\\.String authorLastName\\)'\\.", + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 43 + ) + ) + public void testMapperWithMatchingParameterNames() { + TargetBook targetBook = BookMapper.INSTANCE.mapBook( sourceBook, authorFirstName, authorLastName ); + + assertTargetBookMatchesSourceBook( targetBook ); + + assertThat( targetBook.isAfterMappingWithoutAuthorName() ).isTrue(); + assertThat( targetBook.getAfterMappingWithOnlyFirstName() ).isEqualTo( authorFirstName ); + assertThat( targetBook.getAfterMappingWithOnlyLastName() ).isEqualTo( authorLastName ); + assertThat( targetBook.isAfterMappingWithDifferentVariableName() ).isFalse(); + } + + @Test + @WithClasses({ + DifferentOrderingBookMapper.class + }) + public void testMapperWithMatchingParameterNamesAndDifferentOrdering() { + TargetBook targetBook = DifferentOrderingBookMapper.INSTANCE.mapBook( + sourceBook, + authorFirstName, + authorLastName + ); + + assertTargetBookMatchesSourceBook( targetBook ); + } + + @Test + @WithClasses({ + ObjectFactoryBookMapper.class + }) + public void testMapperWithObjectFactory() { + TargetBook targetBook = ObjectFactoryBookMapper.INSTANCE.mapBook( + sourceBook, + authorFirstName, + authorLastName + ); + + assertTargetBookMatchesSourceBook( targetBook ); + } + + private void assertTargetBookMatchesSourceBook(TargetBook targetBook) { + assertThat( sourceBook.getIsbn() ).isEqualTo( targetBook.getIsbn() ); + assertThat( sourceBook.getTitle() ).isEqualTo( targetBook.getTitle() ); + assertThat( authorFirstName ).isEqualTo( targetBook.getAuthorFirstName() ); + assertThat( authorLastName ).isEqualTo( targetBook.getAuthorLastName() ); + } + + @Test + @WithClasses({ + ErroneousBookMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = @Diagnostic( + messageRegExp = + "Lifecycle method has multiple matching parameters \\(e\\. g\\. same type\\), in this case " + + "please ensure to name the parameters in the lifecycle and mapping method identical\\. This " + + "lifecycle method will not be used for the mapping method '.*\\.TargetBook mapBook\\(" + + ".*\\.SourceBook sourceBook, .*\\.String authorFirstName, .*\\.String authorLastName\\)'\\.", + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 22 + ) + ) + public void testMapperWithoutMatchingParameterNames() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ObjectFactoryBookMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ObjectFactoryBookMapper.java new file mode 100644 index 0000000000..038b44653c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/ObjectFactoryBookMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +import org.mapstruct.Mapper; +import org.mapstruct.ObjectFactory; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public abstract class ObjectFactoryBookMapper { + + public static final ObjectFactoryBookMapper INSTANCE = Mappers.getMapper( ObjectFactoryBookMapper.class ); + + public abstract TargetBook mapBook(SourceBook sourceBook, String authorFirstName, String authorLastName); + + @ObjectFactory + protected TargetBook createTargetBook(String authorFirstName, String authorLastName) { + TargetBook targetBook = new TargetBook(); + targetBook.setAuthorFirstName( authorFirstName ); + targetBook.setAuthorLastName( authorLastName ); + + return targetBook; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/SourceBook.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/SourceBook.java new file mode 100644 index 0000000000..650e51fe4c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/SourceBook.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +public class SourceBook { + private String isbn; + private String title; + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/TargetBook.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/TargetBook.java new file mode 100644 index 0000000000..1698c537f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/TargetBook.java @@ -0,0 +1,83 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1457; + +public class TargetBook { + + private String isbn; + private String title; + private String authorFirstName; + private String authorLastName; + + private boolean afterMappingWithoutAuthorName; + private String afterMappingWithOnlyFirstName; + private String afterMappingWithOnlyLastName; + private boolean afterMappingWithDifferentVariableName; + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthorFirstName() { + return authorFirstName; + } + + public void setAuthorFirstName(String authorFirstName) { + this.authorFirstName = authorFirstName; + } + + public String getAuthorLastName() { + return authorLastName; + } + + public void setAuthorLastName(String authorLastName) { + this.authorLastName = authorLastName; + } + + public boolean isAfterMappingWithoutAuthorName() { + return afterMappingWithoutAuthorName; + } + + public void setAfterMappingWithoutAuthorName(boolean afterMappingWithoutAuthorName) { + this.afterMappingWithoutAuthorName = afterMappingWithoutAuthorName; + } + + public String getAfterMappingWithOnlyFirstName() { + return afterMappingWithOnlyFirstName; + } + + public void setAfterMappingWithOnlyFirstName(String afterMappingWithOnlyFirstName) { + this.afterMappingWithOnlyFirstName = afterMappingWithOnlyFirstName; + } + + public String getAfterMappingWithOnlyLastName() { + return afterMappingWithOnlyLastName; + } + + public void setAfterMappingWithOnlyLastName(String afterMappingWithOnlyLastName) { + this.afterMappingWithOnlyLastName = afterMappingWithOnlyLastName; + } + + public boolean isAfterMappingWithDifferentVariableName() { + return afterMappingWithDifferentVariableName; + } + + public void setAfterMappingWithDifferentVariableName(boolean afterMappingWithDifferentVariableName) { + this.afterMappingWithDifferentVariableName = afterMappingWithDifferentVariableName; + } +} From da8c1d0e4b11ad80ff7a1937308ad4eee133097e Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 7 Apr 2019 21:37:36 +0200 Subject: [PATCH 0357/1006] #1772 unmapped source prop remaining when target and source entry diff (#1778) --- .../ap/internal/model/BeanMappingMethod.java | 16 +++++--- .../ap/test/bugs/_1772/Issue1772Mapper.java | 23 +++++++++++ .../ap/test/bugs/_1772/Issue1772Test.java | 39 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1772/Source.java | 35 +++++++++++++++++ .../mapstruct/ap/test/bugs/_1772/Target.java | 35 +++++++++++++++++ 5 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 502e924aac..dc4c005bb7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -396,23 +396,30 @@ private boolean handleDefinedMappings() { for ( Mapping mapping : entry.getValue() ) { TargetReference targetReference = mapping.getTargetReference(); if ( targetReference.isValid() ) { - if ( !handledTargets.contains( first( targetReference.getPropertyEntries() ).getFullName() ) ) { + String target = first( targetReference.getPropertyEntries() ).getFullName(); + if ( !handledTargets.contains( target ) ) { if ( handleDefinedMapping( mapping, handledTargets ) ) { errorOccurred = true; } } + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { + List sourceEntries = mapping.getSourceReference().getPropertyEntries(); + if ( !sourceEntries.isEmpty() ) { + String source = first( sourceEntries ).getFullName(); + unprocessedSourceProperties.remove( source ); + } + } } else { errorOccurred = true; } } } + + // remove the remaining name based properties for ( String handledTarget : handledTargets ) { - // In order to avoid: "Unknown property foo in return type" in case of duplicate - // target mappings unprocessedTargetProperties.remove( handledTarget ); unprocessedDefinedTargets.remove( handledTarget ); - unprocessedSourceProperties.remove( handledTarget ); } return errorOccurred; @@ -497,7 +504,6 @@ else if ( mapping.getSourceName() != null ) { .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); handledTargets.add( propertyName ); - unprocessedSourceProperties.remove( mapping.getSourceName() ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Mapper.java new file mode 100644 index 0000000000..867385ce25 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Mapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1772; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue1772Mapper { + + Issue1772Mapper INSTANCE = Mappers.getMapper( Issue1772Mapper.class ); + + @Mapping(target = "nestedTarget.doubleNestedTarget", source = "nestedSource.doublyNestedSourceField" ) + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java new file mode 100644 index 0000000000..b77eb34ec0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1772; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@IssueKey("1772") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1772Mapper.class, + Source.class, + Target.class, +}) +public class Issue1772Test { + + @Test + public void shouldCorrectlyMarkSourceAsUsed() { + + Source source = new Source(); + source.setNestedSource( new Source.NestedSource() ); + source.getNestedSource().setDoublyNestedSourceField( 5d ); + + Target target = Issue1772Mapper.INSTANCE.map( source ); + + assertThat( target.getNestedTarget().getDoubleNestedTarget() ).isEqualTo( 5d ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Source.java new file mode 100644 index 0000000000..076ae8a410 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Source.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1772; + +/** + * @author Sjaak Derksen + */ +public class Source { + + private NestedSource nestedSource; + + public NestedSource getNestedSource() { + return nestedSource; + } + + public void setNestedSource(NestedSource nestedSource) { + this.nestedSource = nestedSource; + } + + public static class NestedSource { + + private double doublyNestedSourceField; + + public double getDoublyNestedSourceField() { + return doublyNestedSourceField; + } + + public void setDoublyNestedSourceField(double doublyNestedSourceField) { + this.doublyNestedSourceField = doublyNestedSourceField; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Target.java new file mode 100644 index 0000000000..6ad876acd1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Target.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1772; + +/** + * @author Sjaak Derksen + */ +public class Target { + + private NestedTarget nestedTarget; + + public NestedTarget getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(NestedTarget nestedTarget) { + this.nestedTarget = nestedTarget; + } + + public static class NestedTarget { + + private double doubleNestedTarget; + + public double getDoubleNestedTarget() { + return doubleNestedTarget; + } + + public void setDoubleNestedTarget(double doubleNestedTarget) { + this.doubleNestedTarget = doubleNestedTarget; + } + } +} From 871353fccbf8ed05cfc7dee055f99eb81b0e69e0 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 7 Apr 2019 21:38:22 +0200 Subject: [PATCH 0358/1006] #1784 NullValueMappingStrategy.RETURN_DEFAULT refers wrongly to primitive types (#1785) --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 1 - 1 file changed, 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 87e2934fc4..467dc910c1 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2134,7 +2134,6 @@ MapStruct offers control over the object to create when the source argument of t However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MappingConfig`, the mapping result can be altered to return empty *default* values. This means for: * *Bean mappings*: an 'empty' target bean will be returned, with the exception of constants and expressions, they will be populated when present. -* *Primitives*: the default values for primitives will be returned, e.g. `false` for `boolean` or `0` for `int`. * *Iterables / Arrays*: an empty iterable will be returned. * *Maps*: an empty map will be returned. From 1415e327618b76eb70195a757c865fb65fd5405b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 May 2019 12:42:25 +0200 Subject: [PATCH 0359/1006] #1797 Use EnumSet.noneOf when creating a new instance of EnumSet --- .../ap/internal/model/IterableCreation.java | 16 ++++++++ .../ap/internal/model/IterableCreation.ftl | 2 + .../ap/test/bugs/_1797/Customer.java | 28 +++++++++++++ .../ap/test/bugs/_1797/CustomerDto.java | 28 +++++++++++++ .../ap/test/bugs/_1797/Issue1797Mapper.java | 20 ++++++++++ .../ap/test/bugs/_1797/Issue1797Test.java | 39 +++++++++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Customer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/CustomerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java index 75dbe53fbd..90b50baf25 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableCreation.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * Model element that can be used to create a type of {@link Iterable} or {@link java.util.Map}. If an implementation * type is used and the target type has a constructor with {@code int} as parameter and the source parameter is of @@ -69,6 +71,20 @@ public Set getImportTypes() { if ( factoryMethod == null && resultType.getImplementationType() != null ) { types.addAll( resultType.getImplementationType().getImportTypes() ); } + + if ( isEnumSet() ) { + types.add( getEnumSetElementType() ); + // The result type itself is an EnumSet + types.add( resultType ); + } return types; } + + public Type getEnumSetElementType() { + return first( getResultType().determineTypeArguments( Iterable.class ) ); + } + + public boolean isEnumSet() { + return "java.util.EnumSet".equals( resultType.getFullyQualifiedName() ); + } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl index 86634ef13a..d49397a985 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl @@ -9,6 +9,8 @@ <@compress single_line=true> <#if factoryMethod??> <@includeModel object=factoryMethod targetType=resultType/> + <#elseif enumSet> + EnumSet.noneOf( <@includeModel object=enumSetElementType raw=true/>.class ) <#else> new <#if resultType.implementationType??> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Customer.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Customer.java new file mode 100644 index 0000000000..1d7dce9aa2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Customer.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1797; + +import java.util.EnumSet; + +/** + * @author Filip Hrisafov + */ +public class Customer { + + public enum Type { + ONE, TWO + } + + private final EnumSet types; + + public Customer(EnumSet types) { + this.types = types; + } + + public EnumSet getTypes() { + return types; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/CustomerDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/CustomerDto.java new file mode 100644 index 0000000000..fd51ddc6cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/CustomerDto.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1797; + +import java.util.EnumSet; + +/** + * @author Filip Hrisafov + */ +public class CustomerDto { + + public enum Type { + ONE, TWO + } + + private EnumSet types; + + public EnumSet getTypes() { + return types; + } + + public void setTypes(EnumSet types) { + this.types = types; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Mapper.java new file mode 100644 index 0000000000..f5a0e4162a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1797; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1797Mapper { + + Issue1797Mapper INSTANCE = Mappers.getMapper( Issue1797Mapper.class ); + + CustomerDto map(Customer customer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java new file mode 100644 index 0000000000..ecb531721d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1797; + +import java.util.EnumSet; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1797") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Customer.class, + CustomerDto.class, + Issue1797Mapper.class +}) +public class Issue1797Test { + + @Test + public void shouldCorrectlyMapEnumSetToEnumSet() { + + Customer customer = new Customer( EnumSet.of( Customer.Type.ONE ) ); + + CustomerDto customerDto = Issue1797Mapper.INSTANCE.map( customer ); + + assertThat( customerDto.getTypes() ).containsExactly( CustomerDto.Type.ONE ); + } +} From 648ebceb30a1871d8d7ead78159405523457a1b2 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 16 May 2019 22:23:37 +0200 Subject: [PATCH 0360/1006] #1819 documentation clarification on obtaining Mapper (#1820) --- .../mapstruct-reference-guide.asciidoc | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 467dc910c1..85ba4c8b8b 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -778,9 +778,9 @@ In case you want to disable using builders then you can use the `NoOpBuilderProv == Retrieving a mapper [[mappers-factory]] -=== The Mappers factory +=== The Mappers factory (no dependency injection) -Mapper instances can be retrieved via the `org.mapstruct.factory.Mappers` class. Just invoke the `getMapper()` method, passing the interface type of the mapper to return: +When not using a DI framework, Mapper instances can be retrieved via the `org.mapstruct.factory.Mappers` class. Just invoke the `getMapper()` method, passing the interface type of the mapper to return: .Using the Mappers factory ==== @@ -793,7 +793,7 @@ CarMapper mapper = Mappers.getMapper( CarMapper.class ); By convention, a mapper interface should define a member called `INSTANCE` which holds a single instance of the mapper type: -.Declaring an instance of a mapper +.Declaring an instance of a mapper (interface) ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -809,6 +809,22 @@ public interface CarMapper { ---- ==== +.Declaring an instance of a mapper (abstract class) +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public abstract class CarMapper { + + public static final CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + CarDto carToCarDto(Car car); +} + +---- +==== + This pattern makes it very easy for clients to use mapper objects without repeatedly instantiating new instances: .Accessing a mapper @@ -821,12 +837,13 @@ CarDto dto = CarMapper.INSTANCE.carToCarDto( car ); ---- ==== -Note that mappers generated by MapStruct are thread-safe and thus can safely be accessed from several threads at the same time. + +Note that mappers generated by MapStruct are stateless and thread-safe and thus can safely be accessed from several threads at the same time. [[using-dependency-injection]] === Using dependency injection -If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection as well. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. +If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: From 60c159a0a1150882a7279cb90e72ecef8bad259a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 24 May 2019 23:26:25 +0200 Subject: [PATCH 0361/1006] #1751 Fix handling of possible builder creation methods with generic signature When a method has a generic signature and the builder type is generic then the method return type does not match the builder type. Therefore check only for raw types. Add extra check for void method since a void method can't be a builder creation method --- .../ap/spi/DefaultBuilderProvider.java | 9 ++++- .../mapstruct/ap/test/bugs/_1751/Holder.java | 35 ++++++++++++++++ .../ap/test/bugs/_1751/Issue1751Mapper.java | 24 +++++++++++ .../ap/test/bugs/_1751/Issue1751Test.java | 40 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1751/Source.java | 22 ++++++++++ .../mapstruct/ap/test/bugs/_1751/Target.java | 22 ++++++++++ 6 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Holder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index f5656e2e48..f89e99cd17 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -204,7 +204,14 @@ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, Type return method.getParameters().isEmpty() && method.getModifiers().contains( Modifier.PUBLIC ) && method.getModifiers().contains( Modifier.STATIC ) - && !typeUtils.isSameType( method.getReturnType(), typeElement.asType() ); + && method.getReturnType().getKind() != TypeKind.VOID + // Only compare raw elements + // Reason: if the method is a generic method ( Holder build()) and the type element is (Holder) + // then the return type of the method does not match the type of the type element + && !typeUtils.isSameType( + typeUtils.erasure( method.getReturnType() ), + typeUtils.erasure( typeElement.asType() ) + ); } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Holder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Holder.java new file mode 100644 index 0000000000..cd35297d73 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Holder.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1751; + +/** + * @author Filip Hrisafov + */ +public class Holder { + + private final T value; + + public Holder(T value) { + this.value = value; + } + + public T getValue() { + return value; + } + + // If empty is considered as a builder creation method, this method would be the build method and would + // lead to a stackoverflow + @SuppressWarnings("unused") + public Holder duplicate() { + return new Holder<>( value ); + } + + // This method should not be considered as builder creation method + @SuppressWarnings("unused") + public static Holder empty() { + return new Holder<>( null ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Mapper.java new file mode 100644 index 0000000000..62fb66dc0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Mapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1751; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1751Mapper { + + Issue1751Mapper INSTANCE = Mappers.getMapper( Issue1751Mapper.class ); + + Target map(Source source); + + default Holder mapToHolder(Source source) { + return new Holder<>( this.map( source ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java new file mode 100644 index 0000000000..5061ba598f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1751; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1772") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Holder.class, + Issue1751Mapper.class, + Source.class, + Target.class +}) +public class Issue1751Test { + + @Test + public void name() { + Source source = new Source(); + source.setValue( "some value" ); + + Holder targetHolder = Issue1751Mapper.INSTANCE.mapToHolder( source ); + + assertThat( targetHolder.getValue() ) + .extracting( Target::getValue ) + .isEqualTo( "some value" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Source.java new file mode 100644 index 0000000000..d69e688d79 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1751; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Target.java new file mode 100644 index 0000000000..a6b2ca91b5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1751; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} From 33710584d33856495992c7cab511b4a16643f53e Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Fri, 24 May 2019 23:30:16 +0200 Subject: [PATCH 0362/1006] #1742 & #1661 refactoring and making builder optional (#1811) --- core/src/main/java/org/mapstruct/Builder.java | 8 + .../mapstruct-reference-guide.asciidoc | 5 + .../internal/model/AbstractBaseBuilder.java | 4 +- .../model/AbstractMappingMethodBuilder.java | 8 +- .../ap/internal/model/BeanMappingMethod.java | 309 +++++++++++------- .../model/BuilderFinisherMethodResolver.java | 21 +- .../model/CollectionAssignmentBuilder.java | 18 +- .../model/ContainerMappingMethodBuilder.java | 2 +- .../ap/internal/model/HelperMethod.java | 1 - .../model/LifecycleMethodResolver.java | 53 ++- .../ap/internal/model/MapMappingMethod.java | 2 +- .../ap/internal/model/MethodReference.java | 5 +- .../model/ObjectFactoryMethodResolver.java | 34 +- .../ap/internal/model/PropertyMapping.java | 94 ++---- .../ap/internal/model/common/BuilderType.java | 7 - .../ap/internal/model/common/Type.java | 117 ++++--- .../ap/internal/model/common/TypeFactory.java | 51 ++- .../ap/internal/model/source/BeanMapping.java | 13 +- .../internal/model/source/ForgedMethod.java | 11 +- .../internal/model/source/MappingOptions.java | 5 +- .../ap/internal/model/source/Method.java | 10 +- .../internal/model/source/PropertyEntry.java | 26 +- .../internal/model/source/SourceMethod.java | 9 +- .../model/source/SourceReference.java | 7 +- .../model/source/TargetReference.java | 40 ++- .../processor/MapperCreationProcessor.java | 4 + .../processor/MethodRetrievalProcessor.java | 7 +- .../ap/internal/util/AccessorNamingUtils.java | 45 +-- .../ap/internal/util/Executables.java | 103 ++---- .../mapstruct/ap/internal/util/Fields.java | 106 ++++++ .../mapstruct/ap/internal/util/Filters.java | 74 +++-- .../ap/internal/util/MapperConfiguration.java | 14 +- .../ap/internal/util/ValueProvider.java | 3 +- .../util/accessor/AbstractAccessor.java | 1 + .../ap/internal/util/accessor/Accessor.java | 13 +- .../internal/util/accessor/AccessorType.java | 15 + .../accessor/ExecutableElementAccessor.java | 17 +- .../accessor/VariableElementAccessor.java | 10 +- .../ap/internal/model/BeanMappingMethod.ftl | 4 +- .../DateFormatValidatorFactoryTest.java | 1 - .../common/DefaultConversionContextTest.java | 1 - .../multiple/MultipleBuilderMapperTest.java | 11 - .../ap/test/builder/off/SimpleMapper.java | 20 ++ .../test/builder/off/SimpleMutablePerson.java | 19 ++ .../SimpleNotRealyImmutableBuilderTest.java | 42 +++ .../off/SimpleNotRealyImmutablePerson.java | 44 +++ .../selection/generics/ConversionTest.java | 28 +- 47 files changed, 912 insertions(+), 530 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMutablePerson.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutablePerson.java diff --git a/core/src/main/java/org/mapstruct/Builder.java b/core/src/main/java/org/mapstruct/Builder.java index ec26ab37ab..2f3c9b2e90 100644 --- a/core/src/main/java/org/mapstruct/Builder.java +++ b/core/src/main/java/org/mapstruct/Builder.java @@ -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; } diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 85ba4c8b8b..a08adbae54 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -684,6 +684,11 @@ In case of a `MoreThanOneBuilderCreationMethodException` MapStruct will write a If such type is found then MapStruct will use that type to perform the mapping to (i.e. it will look for setters into that type). To finish the mapping MapStruct generates code that will invoke the build method of the builder. +[NOTE] +====== +Builder detection can be switched off by means of `@Builder#disableBuilder`. MapStruct will fall back on regular getters / setters in case builders are disabled. +====== + [NOTE] ====== The <> are also considered for the builder type. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 8d8750b9fd..220176c06d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -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; @@ -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 ) ); @@ -93,6 +94,7 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod else { forgedMappingMethod = new BeanMappingMethod.Builder() .forgedMethod( forgedMethod ) + .returnTypeBuilder( builderType ) .mappingContext( ctx ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 759f22ca73..6e6b3e0e97 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -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; @@ -63,7 +64,12 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { true ); - return createForgedAssignment( sourceRHS, forgedMethod ); + return createForgedAssignment( + sourceRHS, + ctx.getTypeFactory() + .builderTypeFor( targetType, BeanMapping.builderPrismFor( method ).orElse( null ) ), + forgedMethod + ); } private String getName(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index dc4c005bb7..f8cbde9757 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -6,6 +6,9 @@ package org.mapstruct.ap.internal.model; import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; +import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; +import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; import java.text.MessageFormat; import java.util.ArrayList; @@ -27,6 +30,7 @@ import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; @@ -50,7 +54,6 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally @@ -63,20 +66,23 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; private final List constantMappings; - private final Type resultType; + private final Type returnTypeToConstruct; + private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; public static class Builder { private MappingBuilderContext ctx; private Method method; + + /* returnType to construct can have a builder */ + private BuilderType returnTypeBuilder; + private Map unprocessedTargetProperties; private Map unprocessedSourceProperties; private Set targetProperties; private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); - private NullValueMappingStrategyPrism nullValueMappingStrategy; - private SelectionParameters selectionParameters; private final Set existingVariableNames = new HashSet<>(); private Map> methodMappings; private SingleMappingByTargetPropertyNameFunction singleMapping; @@ -87,27 +93,69 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { return this; } + public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { + this.returnTypeBuilder = returnTypeBuilder; + return this; + } + public Builder sourceMethod(SourceMethod sourceMethod) { singleMapping = new SourceMethodSingleMapping( sourceMethod ); - return setupMethodWithMapping( sourceMethod ); + this.method = sourceMethod; + return this; } public Builder forgedMethod(Method method) { singleMapping = new EmptySingleMapping(); - return setupMethodWithMapping( method ); + this.method = method; + return this; } - private Builder setupMethodWithMapping(Method sourceMethod) { - this.method = sourceMethod; - this.methodMappings = sourceMethod.getMappingOptions().getMappings(); - CollectionMappingStrategyPrism cms = sourceMethod.getMapperConfiguration().getCollectionMappingStrategy(); - Type mappingType = method.getResultType(); - if ( !method.isUpdateMethod() ) { - mappingType = mappingType.getEffectiveType(); + public BeanMappingMethod build() { + + BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); + SelectionParameters selectionParameters = beanMapping != null ? beanMapping.getSelectionParameters() : null; + + /* the return type that needs to be constructed (new or factorized), so for instance: */ + /* 1) the return type of a non-update method */ + /* 2) or the implementation type that needs to be used when the return type is abstract */ + /* 3) or the builder whenever the return type is immutable */ + Type returnTypeToConstruct = null; + + /* factory or builder method to construct the returnTypeToConstruct */ + MethodReference factoryMethod = null; + + // determine which return type to construct + if ( !method.getReturnType().isVoid() ) { + Type returnTypeImpl = getReturnTypeToConstructFromSelectionParameters( selectionParameters ); + if ( returnTypeImpl != null ) { + factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + if ( factoryMethod != null || canBeConstructed( returnTypeImpl ) ) { + returnTypeToConstruct = returnTypeImpl; + } + else { + reportResultTypeFromBeanMappingNotConstructableError( returnTypeImpl ); + } + } + else { + returnTypeImpl = isBuilderRequired() ? returnTypeBuilder.getBuilder() : method.getReturnType(); + factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + if ( factoryMethod != null || canBeConstructed( returnTypeImpl ) ) { + returnTypeToConstruct = returnTypeImpl; + } + else { + reportReturnTypeNotConstructableError( returnTypeImpl ); + } + } } - Map accessors = mappingType - .getPropertyWriteAccessors( cms ); + /* the type that needs to be used in the mapping process as target */ + Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; + + this.methodMappings = this.method.getMappingOptions().getMappings(); + CollectionMappingStrategyPrism cms = this.method.getMapperConfiguration().getCollectionMappingStrategy(); + + // determine accessors + Map accessors = resultTypeToMap.getPropertyWriteAccessors( cms ); this.targetProperties = accessors.keySet(); this.unprocessedTargetProperties = new LinkedHashMap<>( accessors ); @@ -125,17 +173,13 @@ private Builder setupMethodWithMapping(Method sourceMethod) { } existingVariableNames.addAll( method.getParameterNames() ); - BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); + // get bean mapping (when specified as annotation ) if ( beanMapping != null ) { for ( String ignoreUnmapped : beanMapping.getIgnoreUnmappedSourceProperties() ) { unprocessedSourceProperties.remove( ignoreUnmapped ); } } - return this; - } - - public BeanMappingMethod build() { // map properties with mapping boolean mappingErrorOccured = handleDefinedMappings(); if ( mappingErrorOccured ) { @@ -158,87 +202,29 @@ public BeanMappingMethod build() { reportErrorForUnmappedTargetPropertiesIfRequired(); reportErrorForUnmappedSourcePropertiesIfRequired(); - // get bean mapping (when specified as annotation ) - BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); - BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); - // mapNullToDefault NullValueMappingStrategyPrism nullValueMappingStrategy = beanMapping != null ? beanMapping.getNullValueMappingStrategy() : null; boolean mapNullToDefault = method.getMapperConfiguration().isMapToDefault( nullValueMappingStrategy ); - - // selectionParameters - SelectionParameters selectionParameters = beanMapping != null ? beanMapping.getSelectionParameters() : null; - - // check if there's a factory method for the result type - MethodReference factoryMethod = null; - if ( !method.isUpdateMethod() ) { - factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( - method, - method.getResultType(), - selectionParameters, - ctx - ); - } - - // if there's no factory method, try the resultType in the @BeanMapping - Type resultType = null; - if ( factoryMethod == null ) { - if ( selectionParameters != null && selectionParameters.getResultType() != null ) { - resultType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ).getEffectiveType(); - if ( resultType.isAbstract() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - beanMappingPrism.mirror, - Message.BEANMAPPING_ABSTRACT, - resultType, - method.getResultType() - ); - } - else if ( !resultType.isAssignableTo( method.getResultType() ) ) { - ctx.getMessager().printMessage( - method.getExecutable(), - beanMappingPrism.mirror, - Message.BEANMAPPING_NOT_ASSIGNABLE, resultType, method.getResultType() - ); - } - else if ( !resultType.hasEmptyAccessibleContructor() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - beanMappingPrism.mirror, - Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - resultType - ); - } - } - else if ( !method.isUpdateMethod() && method.getReturnType().getEffectiveType().isAbstract() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - Message.GENERAL_ABSTRACT_RETURN_TYPE, - method.getReturnType().getEffectiveType() - ); - } - else if ( !method.isUpdateMethod() && - !method.getReturnType().getEffectiveType().hasEmptyAccessibleContructor() ) { - ctx.getMessager().printMessage( - method.getExecutable(), - Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - method.getReturnType().getEffectiveType() - ); - } - } - + // sort sortPropertyMappingsByDependencies(); + // before / after mappings List beforeMappingMethods = LifecycleMethodResolver.beforeMappingMethods( - method, - selectionParameters, - ctx, - existingVariableNames + method, + resultTypeToMap, + selectionParameters, + ctx, + existingVariableNames + ); + List afterMappingMethods = LifecycleMethodResolver.afterMappingMethods( + method, + resultTypeToMap, + selectionParameters, + ctx, + existingVariableNames ); - List afterMappingMethods = - LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariableNames ); if (factoryMethod != null && method instanceof ForgedMethod ) { ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); @@ -246,7 +232,7 @@ else if ( !method.isUpdateMethod() && MethodReference finalizeMethod = null; - if ( shouldCallFinalizerMethod( resultType == null ? method.getResultType() : resultType ) ) { + if ( shouldCallFinalizerMethod( returnTypeToConstruct ) ) { finalizeMethod = getFinalizerMethod(); } @@ -256,32 +242,41 @@ else if ( !method.isUpdateMethod() && propertyMappings, factoryMethod, mapNullToDefault, - resultType, + returnTypeToConstruct, + returnTypeBuilder, beforeMappingMethods, afterMappingMethods, finalizeMethod ); } - private boolean shouldCallFinalizerMethod(Type resultType) { - Type returnType = method.getReturnType(); - if ( returnType.isVoid() ) { + /** + * @return builder is required when there is a returnTypeBuilder and the mapping method is not update method. + * However, builder is also required when there is a returnTypeBuilder, the mapping target is the builder and + * builder is not assignable to the return type (so without building). + */ + private boolean isBuilderRequired() { + return returnTypeBuilder != null + && ( !method.isUpdateMethod() || !method.isMappingTargetAssignableToReturnType() ); + } + + private boolean shouldCallFinalizerMethod(Type returnTypeToConstruct ) { + if ( returnTypeToConstruct == null ) { return false; } - Type mappingType = method.isUpdateMethod() ? resultType : resultType.getEffectiveType(); - if ( mappingType.isAssignableTo( returnType ) ) { + else if ( returnTypeToConstruct.isAssignableTo( method.getReturnType() ) ) { // If the mapping type can be assigned to the return type then we // don't need a finalizer method return false; } - return returnType.getBuilderType() != null; + return returnTypeBuilder != null; } private MethodReference getFinalizerMethod() { return BuilderFinisherMethodResolver.getBuilderFinisherMethod( method, - method.getReturnType().getBuilderType(), + returnTypeBuilder, ctx ); } @@ -372,6 +367,87 @@ public int compare(PropertyMapping o1, PropertyMapping o2) { } } + private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters selectionParams) { + if ( selectionParams != null && selectionParams.getResultType() != null ) { + return ctx.getTypeFactory().getType( selectionParams.getResultType() ); + } + return null; + } + + private boolean canBeConstructed(Type typeToBeConstructed) { + return !typeToBeConstructed.isAbstract() + && typeToBeConstructed.isAssignableTo( this.method.getResultType() ) + && typeToBeConstructed.hasEmptyAccessibleContructor(); + } + + private void reportResultTypeFromBeanMappingNotConstructableError(Type resultType) { + + if ( resultType.isAbstract() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + BEANMAPPING_ABSTRACT, + resultType, + method.getResultType() + ); + } + else if ( !resultType.isAssignableTo( method.getResultType() ) ) { + ctx.getMessager().printMessage( + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + BEANMAPPING_NOT_ASSIGNABLE, + resultType, + method.getResultType() + ); + } + else if ( !resultType.hasEmptyAccessibleContructor() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + resultType + ); + } + } + + private void reportReturnTypeNotConstructableError(Type returnType) { + if ( returnType.isAbstract() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + GENERAL_ABSTRACT_RETURN_TYPE, + returnType + ); + } + else if ( !returnType.hasEmptyAccessibleContructor() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + returnType + ); + } + } + + /** + * Find a factory method for a return type or for a builder. + * @param returnTypeImpl the return type implementation to construct + * @param selectionParameters + * @return + */ + private MethodReference getFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters) { + MethodReference factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, + returnTypeImpl, + selectionParameters, + ctx + ); + if ( factoryMethod == null && returnTypeBuilder != null ) { + factoryMethod = ObjectFactoryMethodResolver.getBuilderFactoryMethod( method, returnTypeBuilder ); + } + + return factoryMethod; + } + + + /** * Iterates over all defined mapping methods ({@code @Mapping(s)}), either directly given or inherited from the * inverse mapping method. @@ -590,7 +666,7 @@ private void applyPropertyNameBasedMapping() { Accessor sourceReadAccessor = sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); - ExecutableElementAccessor sourcePresenceChecker = + Accessor sourcePresenceChecker = sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); if ( sourceReadAccessor != null ) { @@ -840,7 +916,8 @@ private BeanMappingMethod(Method method, List propertyMappings, MethodReference factoryMethod, boolean mapNullToDefault, - Type resultType, + Type returnTypeToConstruct, + BuilderType returnTypeBuilder, List beforeMappingReferences, List afterMappingReferences, MethodReference finalizerMethod) { @@ -854,6 +931,7 @@ private BeanMappingMethod(Method method, ); this.propertyMappings = propertyMappings; + this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a @@ -870,11 +948,7 @@ private BeanMappingMethod(Method method, } } } - this.resultType = resultType; - } - - public List getPropertyMappings() { - return propertyMappings; + this.returnTypeToConstruct = returnTypeToConstruct; } public List getConstantMappings() { @@ -886,14 +960,8 @@ public List propertyMappingsByParameter(Parameter parameter) { return mappingsByParameter.get( parameter.getName() ); } - @Override - public Type getResultType() { - if ( resultType == null ) { - return super.getResultType(); - } - else { - return resultType; - } + public Type getReturnTypeToConstruct() { + return returnTypeToConstruct; } public MethodReference getFinalizerMethod() { @@ -908,12 +976,11 @@ public Set getImportTypes() { types.addAll( propertyMapping.getImportTypes() ); } - if ( !isExistingInstanceMapping() ) { - types.addAll( getResultType().getEffectiveType().getImportTypes() ); + if ( returnTypeToConstruct != null ) { + types.addAll( returnTypeToConstruct.getImportTypes() ); } - - if ( getResultType().getBuilderType() != null ) { - types.add( getResultType().getBuilderType().getOwningType() ); + if ( returnTypeBuilder != null ) { + types.add( returnTypeBuilder.getOwningType() ); } return types; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index 78375d8e33..9f44085809 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -6,13 +6,13 @@ package org.mapstruct.ap.internal.model; import java.util.Collection; +import java.util.Optional; import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.source.BeanMapping; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -36,14 +36,14 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp return null; } - BuilderPrism builderMapping = builderMappingPrism( method, ctx ); - if ( builderMapping == null && buildMethods.size() == 1 ) { + Optional builderMapping = BeanMapping.builderPrismFor( method ); + if ( !builderMapping.isPresent() && buildMethods.size() == 1 ) { return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() ); } else { String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME; - if ( builderMapping != null ) { - buildMethodPattern = builderMapping.buildMethod(); + if ( builderMapping.isPresent() ) { + buildMethodPattern = builderMapping.get().buildMethod(); } for ( ExecutableElement buildMethod : buildMethods ) { String methodName = buildMethod.getSimpleName().toString(); @@ -52,7 +52,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp } } - if ( builderMapping == null ) { + if ( !builderMapping.isPresent() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT, @@ -65,7 +65,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp else { ctx.getMessager().printMessage( method.getExecutable(), - builderMapping.mirror, + builderMapping.get().mirror, Message.BUILDER_NO_BUILD_METHOD_FOUND, buildMethodPattern, builderType.getBuilder(), @@ -78,11 +78,4 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp return null; } - private static BuilderPrism builderMappingPrism(Method method, MappingBuilderContext ctx) { - BeanMapping beanMapping = method.getMappingOptions().getBeanMapping(); - if ( beanMapping != null && beanMapping.getBuilder() != null ) { - return beanMapping.getBuilder(); - } - return MapperConfiguration.getInstanceOn( ctx.getMapperTypeElement() ).getBuilderPrism(); - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index ad9defb9d2..6422a354d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -20,6 +20,7 @@ import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; @@ -57,7 +58,7 @@ public class CollectionAssignmentBuilder { private Accessor targetReadAccessor; private Type targetType; private String targetPropertyName; - private PropertyMapping.TargetWriteAccessorType targetAccessorType; + private AccessorType targetAccessorType; private Assignment assignment; private SourceRHS sourceRHS; private NullValueCheckStrategyPrism nvcs; @@ -88,7 +89,7 @@ public CollectionAssignmentBuilder targetPropertyName(String targetPropertyName) return this; } - public CollectionAssignmentBuilder targetAccessorType(PropertyMapping.TargetWriteAccessorType targetAccessorType) { + public CollectionAssignmentBuilder targetAccessorType(AccessorType targetAccessorType) { this.targetAccessorType = targetAccessorType; return this; } @@ -129,8 +130,7 @@ public Assignment build() { CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE || targetReadAccessor == null; - if ( targetAccessorType == PropertyMapping.TargetWriteAccessorType.SETTER || - targetAccessorType == PropertyMapping.TargetWriteAccessorType.FIELD ) { + if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) { if ( result.isCallingUpdateMethod() && !targetImmutable ) { @@ -149,7 +149,7 @@ public Assignment build() { result, method.getThrownTypes(), factoryMethod, - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ), + targetAccessorType == AccessorType.FIELD, targetType, true, nvpms == SET_TO_NULL && !targetType.isPrimitive(), @@ -165,7 +165,7 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { nvcs, nvpms, ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + targetAccessorType == AccessorType.FIELD ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || @@ -176,7 +176,7 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || method.getThrownTypes(), targetType, ctx.getTypeFactory(), - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + targetAccessorType == AccessorType.FIELD ); } else { @@ -185,7 +185,7 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || result, method.getThrownTypes(), targetType, - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + targetAccessorType == AccessorType.FIELD ); } } @@ -203,7 +203,7 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || result, method.getThrownTypes(), targetType, - PropertyMapping.TargetWriteAccessorType.isFieldAssignment( targetAccessorType ) + targetAccessorType == AccessorType.FIELD ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index a9a501a49e..c4dc73f611 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -139,7 +139,7 @@ public final M build() { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { - factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, method.getResultType(), null, ctx ); + factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, null, ctx ); } Set existingVariables = new HashSet<>( method.getParameterNames() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 72e062cca8..5921d15179 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -10,7 +10,6 @@ import java.util.Collections; import java.util.List; import java.util.Set; - import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.Accessibility; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 64eee60517..0448be5d44 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -32,16 +32,60 @@ private LifecycleMethodResolver() { /** * @param method the method to obtain the beforeMapping methods for + * @param alternativeTarget alternative to {@link Method#getResultType()} e.g. when target is abstract * @param selectionParameters method selectionParameters * @param ctx the builder context * @param existingVariableNames the existing variable names in the mapping method * @return all applicable {@code @BeforeMapping} methods for the given method */ public static List beforeMappingMethods(Method method, + Type alternativeTarget, SelectionParameters selectionParameters, MappingBuilderContext ctx, Set existingVariableNames) { return collectLifecycleCallbackMethods( method, + alternativeTarget, + selectionParameters, + filterBeforeMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), + ctx, + existingVariableNames ); + } + + /** + * @param method the method to obtain the afterMapping methods for + * @param alternativeTarget alternative to {@link Method#getResultType()} e.g. when target is abstract + * @param selectionParameters method selectionParameters + * @param ctx the builder context + * @param existingVariableNames list of already used variable names + * @return all applicable {@code @AfterMapping} methods for the given method + */ + public static List afterMappingMethods(Method method, + Type alternativeTarget, + SelectionParameters selectionParameters, + MappingBuilderContext ctx, + Set existingVariableNames) { + return collectLifecycleCallbackMethods( method, + alternativeTarget, + selectionParameters, + filterAfterMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), + ctx, + existingVariableNames ); + } + + + /** + * @param method the method to obtain the beforeMapping methods for + * @param selectionParameters method selectionParameters + * @param ctx the builder context + * @param existingVariableNames the existing variable names in the mapping method + * @return all applicable {@code @BeforeMapping} methods for the given method + */ + public static List beforeMappingMethods(Method method, + SelectionParameters selectionParameters, + MappingBuilderContext ctx, + Set existingVariableNames) { + return collectLifecycleCallbackMethods( method, + method.getResultType(), selectionParameters, filterBeforeMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, @@ -60,6 +104,7 @@ public static List afterMappingMethods(Method MappingBuilderContext ctx, Set existingVariableNames) { return collectLifecycleCallbackMethods( method, + method.getResultType(), selectionParameters, filterAfterMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, @@ -87,18 +132,12 @@ private static List getAllAvailableMethods(Method method, List collectLifecycleCallbackMethods( - Method method, SelectionParameters selectionParameters, List callbackMethods, + Method method, Type targetType, SelectionParameters selectionParameters, List callbackMethods, MappingBuilderContext ctx, Set existingVariableNames) { MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); - Type targetType = method.getResultType(); - - if ( !method.isUpdateMethod() ) { - targetType = targetType.getEffectiveType(); - } - List> matchingMethods = selectors.getMatchingMethods( method, callbackMethods, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index b08fea5775..81026c5ec2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -198,7 +198,7 @@ public MapMappingMethod build() { MethodReference factoryMethod = null; if ( !method.isUpdateMethod() ) { factoryMethod = ObjectFactoryMethodResolver - .getFactoryMethod( method, method.getResultType(), null, ctx ); + .getFactoryMethod( method, null, ctx ); } keyAssignment = new LocalVarWrapper( keyAssignment, method.getThrownTypes(), keyTargetType, false ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index b95ef372d7..81d75a80e4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -157,7 +157,7 @@ public void setAssignment( Assignment assignment ) { @Override public String getSourceReference() { - return assignment.getSourceReference(); + return assignment != null ? assignment.getSourceReference() : null; } @Override @@ -353,7 +353,8 @@ public static MethodReference forMethodCall(String methodName) { @Override public String toString() { String mapper = declaringMapper != null ? declaringMapper.getType().getName().toString() : ""; - String argument = getAssignment() != null ? getAssignment().toString() : getSourceReference(); + String argument = getAssignment() != null ? getAssignment().toString() : + ( getSourceReference() != null ? getSourceReference() : "" ); String returnTypeAsString = returnType != null ? returnType.toString() : ""; List arguments = sourceParameters.stream() .map( p -> p.isMappingContext() || p.isMappingTarget() || p.isTargetType() ? p.getName() : argument ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 17d5135b00..5a0f72fb50 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -38,7 +38,6 @@ private ObjectFactoryMethodResolver() { * returns a no arg factory method * * @param method target mapping method - * @param targetType return type to match * @param selectionParameters parameters used in the selection process * @param ctx * @@ -46,9 +45,29 @@ private ObjectFactoryMethodResolver() { * */ public static MethodReference getFactoryMethod( Method method, - Type targetType, SelectionParameters selectionParameters, MappingBuilderContext ctx) { + return getFactoryMethod( method, method.getResultType(), selectionParameters, ctx ); + } + + + + /** + * returns a no arg factory method + * + * @param method target mapping method + * @param alternativeTarget alternative to {@link Method#getResultType()} e.g. when target is abstract + * @param selectionParameters parameters used in the selection process + * @param ctx + * + * @return a method reference to the factory method, or null if no suitable, or ambiguous method found + * + */ + public static MethodReference getFactoryMethod( Method method, + Type alternativeTarget, + SelectionParameters selectionParameters, + MappingBuilderContext ctx) { + MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); @@ -58,18 +77,18 @@ public static MethodReference getFactoryMethod( Method method, method, getAllAvailableMethods( method, ctx.getSourceModel() ), java.util.Collections. emptyList(), - targetType.getEffectiveType(), + alternativeTarget, SelectionCriteria.forFactoryMethods( selectionParameters ) ); if (matchingFactoryMethods.isEmpty()) { - return findBuilderFactoryMethod( targetType ); + return null; } if ( matchingFactoryMethods.size() > 1 ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, - targetType.getEffectiveType(), + alternativeTarget, Strings.join( matchingFactoryMethods, ", " ) ); return null; @@ -98,8 +117,7 @@ java.util.Collections. emptyList(), } } - private static MethodReference findBuilderFactoryMethod(Type targetType) { - BuilderType builder = targetType.getBuilderType(); + public static MethodReference getBuilderFactoryMethod(Method method, BuilderType builder ) { if ( builder == null ) { return null; } @@ -110,7 +128,7 @@ private static MethodReference findBuilderFactoryMethod(Type targetType) { return null; } - if ( !builder.getBuildingType().isAssignableTo( targetType ) ) { + if ( !builder.getBuildingType().isAssignableTo( method.getReturnType() ) ) { //TODO print error message return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 2f892e6b5e..a439f69178 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -12,7 +12,6 @@ import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.DeclaredType; import org.mapstruct.ap.internal.model.assignment.AdderWrapper; import org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper; @@ -22,6 +21,7 @@ import org.mapstruct.ap.internal.model.assignment.StreamAdderWrapper; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; @@ -37,17 +37,17 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.util.AccessorNamingUtils; -import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; @@ -73,38 +73,13 @@ public class PropertyMapping extends ModelElement { private final List dependsOn; private final Assignment defaultValueAssignment; - public enum TargetWriteAccessorType { - FIELD, - GETTER, - SETTER, - ADDER; - - public static TargetWriteAccessorType of(AccessorNamingUtils accessorNaming, Accessor accessor) { - if ( accessorNaming.isSetterMethod( accessor ) ) { - return TargetWriteAccessorType.SETTER; - } - else if ( accessorNaming.isAdderMethod( accessor ) ) { - return TargetWriteAccessorType.ADDER; - } - else if ( accessorNaming.isGetterMethod( accessor ) ) { - return TargetWriteAccessorType.GETTER; - } - else { - return TargetWriteAccessorType.FIELD; - } - } - - public static boolean isFieldAssignment(TargetWriteAccessorType accessorType) { - return accessorType == FIELD; - } - } - @SuppressWarnings("unchecked") private static class MappingBuilderBase> extends AbstractBaseBuilder { protected Accessor targetWriteAccessor; - protected TargetWriteAccessorType targetWriteAccessorType; + protected AccessorType targetWriteAccessorType; protected Type targetType; + protected BuilderType targetBuilderType; protected Accessor targetReadAccessor; protected String targetPropertyName; protected String sourcePropertyName; @@ -125,7 +100,8 @@ public T targetProperty(PropertyEntry targetProp) { this.targetReadAccessor = targetProp.getReadAccessor(); this.targetWriteAccessor = targetProp.getWriteAccessor(); this.targetType = targetProp.getType(); - this.targetWriteAccessorType = TargetWriteAccessorType.of( ctx.getAccessorNaming(), targetWriteAccessor ); + this.targetBuilderType = targetProp.getBuilderType(); + this.targetWriteAccessorType = targetWriteAccessor.getAccessorType(); return (T) this; } @@ -136,9 +112,10 @@ public T targetReadAccessor(Accessor targetReadAccessor) { public T targetWriteAccessor(Accessor targetWriteAccessor) { this.targetWriteAccessor = targetWriteAccessor; - this.targetWriteAccessorType = TargetWriteAccessorType.of( ctx.getAccessorNaming(), targetWriteAccessor ); - this.targetType = determineTargetType(); - + this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + this.targetBuilderType = ctx.getTypeFactory().builderTypeFor( this.targetType, builderPrism ); + this.targetWriteAccessorType = targetWriteAccessor.getAccessorType(); return (T) this; } @@ -147,28 +124,6 @@ T mirror(AnnotationMirror mirror) { return (T) this; } - private Type determineTargetType() { - // This is a bean mapping method, so we know the result is a declared type - Type mappingType = method.getResultType(); - if ( !method.isUpdateMethod() ) { - mappingType = mappingType.getEffectiveType(); - } - DeclaredType resultType = (DeclaredType) mappingType.getTypeMirror(); - - switch ( targetWriteAccessorType ) { - case ADDER: - case SETTER: - return ctx.getTypeFactory() - .getSingleParameter( resultType, targetWriteAccessor ) - .getType(); - case GETTER: - case FIELD: - default: - return ctx.getTypeFactory() - .getReturnType( resultType, targetWriteAccessor ); - } - } - public T targetPropertyName(String targetPropertyName) { this.targetPropertyName = targetPropertyName; return (T) this; @@ -190,7 +145,7 @@ public T existingVariableNames(Set existingVariableNames) { } protected boolean isFieldAssignment() { - return targetWriteAccessorType == TargetWriteAccessorType.FIELD; + return targetWriteAccessorType == AccessorType.FIELD; } } @@ -300,11 +255,11 @@ public PropertyMapping build() { ctx.getMessager().note( 2, Message.PROPERTYMAPPING_MAPPING_NOTE, rightHandSide, targetWriteAccessor ); rightHandSide.setUseElementAsSourceTypeForMatching( - targetWriteAccessorType == TargetWriteAccessorType.ADDER ); + targetWriteAccessorType == AccessorType.ADDER ); // all the tricky cases will be excluded for the time being. boolean preferUpdateMethods; - if ( targetWriteAccessorType == TargetWriteAccessorType.ADDER ) { + if ( targetWriteAccessorType == AccessorType.ADDER ) { preferUpdateMethods = false; } else { @@ -446,13 +401,12 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { return null; } - private Assignment assignToPlain(Type targetType, TargetWriteAccessorType targetAccessorType, + private Assignment assignToPlain(Type targetType, AccessorType targetAccessorType, Assignment rightHandSide) { Assignment result; - if ( targetAccessorType == TargetWriteAccessorType.SETTER || - targetAccessorType == TargetWriteAccessorType.FIELD ) { + if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) { result = assignToPlainViaSetter( targetType, rightHandSide ); } else { @@ -530,7 +484,7 @@ else if ( result.getSourceType().isStreamType() ) { return result; } - private Assignment assignToCollection(Type targetType, TargetWriteAccessorType targetAccessorType, + private Assignment assignToCollection(Type targetType, AccessorType targetAccessorType, Assignment rhs) { return new CollectionAssignmentBuilder() .mappingBuilderContext( ctx ) @@ -738,7 +692,7 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s private Assignment forgeMapping(SourceRHS sourceRHS) { Type sourceType; - if ( targetWriteAccessorType == TargetWriteAccessorType.ADDER ) { + if ( targetWriteAccessorType == AccessorType.ADDER ) { sourceType = sourceRHS.getSourceTypeForMatching(); } else { @@ -764,7 +718,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { // because we are forging a Mapping for a method with multiple source parameters. // If the target type is enum, then we can't create an update method if ( !targetType.isEnumType() && ( method.isUpdateMethod() || forceUpdateMethod ) - && targetWriteAccessorType != TargetWriteAccessorType.ADDER) { + && targetWriteAccessorType != AccessorType.ADDER) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } @@ -783,7 +737,7 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { forgeMethodWithMappingOptions, forgedNamedBased ); - return createForgedAssignment( sourceRHS, forgedMethod ); + return createForgedAssignment( sourceRHS, targetBuilderType, forgedMethod ); } private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { @@ -899,8 +853,8 @@ public PropertyMapping build() { if ( assignment != null ) { - if ( ctx.getAccessorNaming().isSetterMethod( targetWriteAccessor ) || - Executables.isFieldAccessor( targetWriteAccessor ) ) { + if ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || + targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) { // target accessor is setter, so decorate assignment as setter if ( assignment.isCallingUpdateMethod() ) { @@ -1015,8 +969,8 @@ public JavaExpressionMappingBuilder javaExpression(String javaExpression) { public PropertyMapping build() { Assignment assignment = new SourceRHS( javaExpression, null, existingVariableNames, "" ); - if ( ctx.getAccessorNaming().isSetterMethod( targetWriteAccessor ) || - Executables.isFieldAccessor( targetWriteAccessor ) ) { + if ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || + targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) { // setter, so wrap in setter assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 94f406b1f9..bae5c161b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -82,13 +82,6 @@ public Collection getBuildMethods() { return buildMethods; } - public BuilderInfo asBuilderInfo() { - return new BuilderInfo.Builder() - .builderCreationMethod( this.builderCreationMethod ) - .buildMethod( this.buildMethods ) - .build(); - } - public static BuilderType create(BuilderInfo builderInfo, Type typeToBuild, TypeFactory typeFactory, Types typeUtils) { if ( builderInfo == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 5992a687bd..bc0170645b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -34,12 +34,12 @@ import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; +import org.mapstruct.ap.internal.util.Fields; import org.mapstruct.ap.internal.util.Filters; import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.Nouns; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; -import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.util.Collections.first; import org.mapstruct.ap.internal.util.NativeTypes; @@ -67,7 +67,6 @@ public class Type extends ModelElement implements Comparable { private final ImplementationType implementationType; private final Type componentType; - private final BuilderType builderType; private final String packageName; private final String name; @@ -89,9 +88,11 @@ public class Type extends ModelElement implements Comparable { private Boolean isToBeImported; private Map readAccessors = null; - private Map presenceCheckers = null; + private Map presenceCheckers = null; + + private List allMethods = null; + private List allFields = null; - private List allAccessors = null; private List setters = null; private List adders = null; private List alternativeTargetAccessors = null; @@ -100,12 +101,13 @@ public class Type extends ModelElement implements Comparable { private Boolean hasEmptyAccessibleContructor; + private final Filters filters; + //CHECKSTYLE:OFF public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, AccessorNamingUtils accessorNaming, TypeMirror typeMirror, TypeElement typeElement, List typeParameters, ImplementationType implementationType, Type componentType, - BuilderInfo builderInfo, String packageName, String name, String qualifiedName, boolean isInterface, boolean isEnumType, boolean isIterableType, boolean isCollectionType, boolean isMapType, boolean isStreamType, @@ -157,7 +159,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.isToBeImported = isToBeImported; this.toBeImportedTypes = toBeImportedTypes; this.notToBeImportedTypes = notToBeImportedTypes; - this.builderType = BuilderType.create( builderInfo, this, this.typeFactory, this.typeUtils ); + this.filters = new Filters( accessorNaming, typeUtils, typeMirror ); } //CHECKSTYLE:ON @@ -200,18 +202,6 @@ public Type getComponentType() { return componentType; } - public BuilderType getBuilderType() { - return builderType; - } - - /** - * The effective type that should be used when searching for getters / setters, creating new types etc - * @return the effective type for mappings - */ - public Type getEffectiveType() { - return builderType != null ? builderType.getBuilder() : this; - } - public boolean isPrimitive() { return typeMirror.getKind().isPrimitive(); } @@ -419,7 +409,6 @@ public Type erasure() { typeParameters, implementationType, componentType, - builderType == null ? null : builderType.asBuilderInfo(), packageName, name, qualifiedName, @@ -462,7 +451,6 @@ public Type withoutBounds() { bounds, implementationType, componentType, - builderType == null ? null : builderType.asBuilderInfo(), packageName, name, qualifiedName, @@ -505,30 +493,30 @@ public boolean isAssignableTo(Type other) { */ public Map getPropertyReadAccessors() { if ( readAccessors == null ) { - List getterList = Filters.getterMethodsIn( accessorNaming, getAllAccessors() ); + List getterList = filters.getterMethodsIn( getAllMethods() ); Map modifiableGetters = new LinkedHashMap<>(); for ( Accessor getter : getterList ) { - String propertyName = accessorNaming.getPropertyName( getter ); + String propertyName = getPropertyName( getter ); if ( modifiableGetters.containsKey( propertyName ) ) { // In the DefaultAccessorNamingStrategy, this can only be the case for Booleans: isFoo() and // getFoo(); The latter is preferred. if ( !getter.getSimpleName().toString().startsWith( "is" ) ) { - modifiableGetters.put( accessorNaming.getPropertyName( getter ), getter ); + modifiableGetters.put( getPropertyName( getter ), getter ); } } else { - modifiableGetters.put( accessorNaming.getPropertyName( getter ), getter ); + modifiableGetters.put( getPropertyName( getter ), getter ); } } - List fieldsList = Filters.fieldsIn( getAllAccessors() ); + List fieldsList = filters.fieldsIn( getAllFields() ); for ( Accessor field : fieldsList ) { - String propertyName = accessorNaming.getPropertyName( field ); + String propertyName = getPropertyName( field ); if ( !modifiableGetters.containsKey( propertyName ) ) { // If there was no getter or is method for booleans, then resort to the field. // If a field was already added do not add it again. - modifiableGetters.put( propertyName, field ); + modifiableGetters.put( propertyName, field ); } } readAccessors = Collections.unmodifiableMap( modifiableGetters ); @@ -541,15 +529,12 @@ public Map getPropertyReadAccessors() { * * @return an unmodifiable map of all presence checkers, indexed by property name */ - public Map getPropertyPresenceCheckers() { + public Map getPropertyPresenceCheckers() { if ( presenceCheckers == null ) { - List checkerList = Filters.presenceCheckMethodsIn( - accessorNaming, - getAllAccessors() - ); - Map modifiableCheckers = new LinkedHashMap<>(); - for ( ExecutableElementAccessor checker : checkerList ) { - modifiableCheckers.put( accessorNaming.getPropertyName( checker ), checker ); + List checkerList = filters.presenceCheckMethodsIn( getAllMethods() ); + Map modifiableCheckers = new LinkedHashMap<>(); + for ( Accessor checker : checkerList ) { + modifiableCheckers.put( getPropertyName( checker ), checker ); } presenceCheckers = Collections.unmodifiableMap( modifiableCheckers ); } @@ -577,7 +562,7 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg Map result = new LinkedHashMap<>(); for ( Accessor candidate : candidates ) { - String targetPropertyName = accessorNaming.getPropertyName( candidate ); + String targetPropertyName = getPropertyName( candidate ); Accessor readAccessor = getPropertyReadAccessors().get( targetPropertyName ); @@ -593,12 +578,12 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg // first check if there's a setter method. Accessor adderMethod = null; - if ( accessorNaming.isSetterMethod( candidate ) + if ( candidate.getAccessorType() == AccessorType.SETTER // ok, the current accessor is a setter. So now the strategy determines what to use && cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED ) { adderMethod = getAdderForType( targetType, targetPropertyName ); } - else if ( accessorNaming.isGetterMethod( candidate ) ) { + else if ( candidate.getAccessorType() == AccessorType.GETTER ) { // the current accessor is a getter (no setter available). But still, an add method is according // to the above strategy (SETTER_PREFERRED || ADDER_PREFERRED) preferred over the getter. adderMethod = getAdderForType( targetType, targetPropertyName ); @@ -608,7 +593,7 @@ else if ( accessorNaming.isGetterMethod( candidate ) ) { candidate = adderMethod; } } - else if ( Executables.isFieldAccessor( candidate ) && ( Executables.isFinal( candidate ) || + else if ( candidate.getAccessorType() == AccessorType.FIELD && ( Executables.isFinal( candidate ) || result.containsKey( targetPropertyName ) ) ) { // if the candidate is a field and a mapping already exists, then use that one, skip it. continue; @@ -636,18 +621,36 @@ private Type determineTargetType(Accessor candidate) { if ( parameter != null ) { return parameter.getType(); } - else if ( accessorNaming.isGetterMethod( candidate ) || Executables.isFieldAccessor( candidate ) ) { + else if ( candidate.getAccessorType() == AccessorType.GETTER + || candidate.getAccessorType() == AccessorType.FIELD ) { return typeFactory.getReturnType( (DeclaredType) typeMirror, candidate ); } return null; } - private List getAllAccessors() { - if ( allAccessors == null ) { - allAccessors = Executables.getAllEnclosedAccessors( elementUtils, typeElement ); + private List getAllMethods() { + if ( allMethods == null ) { + allMethods = Executables.getAllEnclosedExecutableElements( elementUtils, typeElement ); } - return allAccessors; + return allMethods; + } + + private List getAllFields() { + if ( allFields == null ) { + allFields = Fields.getAllEnclosedFields( elementUtils, typeElement ); + } + + return allFields; + } + + private String getPropertyName(Accessor accessor ) { + if ( accessor.getAccessorType() == AccessorType.FIELD ) { + return accessorNaming.getPropertyName( (VariableElement) accessor.getElement() ); + } + else { + return accessorNaming.getPropertyName( (ExecutableElement) accessor.getElement() ); + } } /** @@ -709,19 +712,14 @@ else if ( collectionProperty.isStreamType() ) { * @return accessor candidates */ private List getAccessorCandidates(Type property, Class superclass) { - TypeMirror typeArg = first( property.determineTypeArguments( superclass ) ).getTypeBound() - .getTypeMirror(); + TypeMirror typeArg = first( property.determineTypeArguments( superclass ) ).getTypeBound().getTypeMirror(); // now, look for a method that // 1) starts with add, // 2) and has typeArg as one and only arg List adderList = getAdders(); List candidateList = new ArrayList<>(); for ( Accessor adder : adderList ) { - ExecutableElement executable = adder.getExecutable(); - if ( executable == null ) { - // it should not be null, but to be safe - continue; - } + ExecutableElement executable = (ExecutableElement) adder.getElement(); VariableElement arg = executable.getParameters().get( 0 ); if ( typeUtils.isSameType( boxed( arg.asType() ), boxed( typeArg ) ) ) { candidateList.add( adder ); @@ -746,7 +744,7 @@ private TypeMirror boxed(TypeMirror possiblePrimitive) { */ private List getSetters() { if ( setters == null ) { - setters = Collections.unmodifiableList( Filters.setterMethodsIn( accessorNaming, getAllAccessors() ) ); + setters = Collections.unmodifiableList( filters.setterMethodsIn( getAllMethods() ) ); } return setters; } @@ -761,7 +759,7 @@ private List getSetters() { */ private List getAdders() { if ( adders == null ) { - adders = Collections.unmodifiableList( Filters.adderMethodsIn( accessorNaming, getAllAccessors() ) ); + adders = Collections.unmodifiableList( filters.adderMethodsIn( getAllMethods() ) ); } return adders; } @@ -781,10 +779,9 @@ private List getAlternativeTargetAccessors() { List result = new ArrayList<>(); List setterMethods = getSetters(); - List readAccessors = - new ArrayList<>( getPropertyReadAccessors().values() ); + List readAccessors = new ArrayList<>( getPropertyReadAccessors().values() ); // All the fields are also alternative accessors - readAccessors.addAll( Filters.fieldsIn( getAllAccessors() ) ); + readAccessors.addAll( filters.fieldsIn( getAllFields() ) ); // there could be a read accessor (field or method) for a list/map that is not present as setter. // an accessor could substitute the setter in that case and act as setter. @@ -794,7 +791,7 @@ private List getAlternativeTargetAccessors() { !correspondingSetterMethodExists( readAccessor, setterMethods ) ) { result.add( readAccessor ); } - else if ( Executables.isFieldAccessor( readAccessor ) && + else if ( readAccessor.getAccessorType() == AccessorType.FIELD && !correspondingSetterMethodExists( readAccessor, setterMethods ) ) { result.add( readAccessor ); } @@ -807,10 +804,10 @@ else if ( Executables.isFieldAccessor( readAccessor ) && private boolean correspondingSetterMethodExists(Accessor getterMethod, List setterMethods) { - String getterPropertyName = accessorNaming.getPropertyName( getterMethod ); + String getterPropertyName = getPropertyName( getterMethod ); for ( Accessor setterMethod : setterMethods ) { - String setterPropertyName = accessorNaming.getPropertyName( setterMethod ); + String setterPropertyName = getPropertyName( setterMethod ); if ( getterPropertyName.equals( setterPropertyName ) ) { return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 567053986e..c94986e822 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -39,6 +39,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.Extractor; @@ -49,6 +50,7 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderInfo; import org.mapstruct.ap.spi.MoreThanOneBuilderCreationMethodException; @@ -186,7 +188,6 @@ private Type getType(TypeMirror mirror, boolean isLiteral) { } ImplementationType implementationType = getImplementationType( mirror ); - BuilderInfo builderInfo = findBuilder( mirror ); boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); boolean isCollectionType = typeUtils.isSubtype( mirror, collectionType ); @@ -280,7 +281,6 @@ else if (componentTypeMirror.getKind().isPrimitive()) { getTypeParameters( mirror, false ), implementationType, componentType, - builderInfo, packageName, name, qualifiedName, @@ -354,10 +354,10 @@ public TypeMirror getMethodType(DeclaredType includingType, Element method) { } public Parameter getSingleParameter(DeclaredType includingType, Accessor method) { - ExecutableElement executable = method.getExecutable(); - if ( executable == null ) { + if ( method.getAccessorType() == AccessorType.FIELD ) { return null; } + ExecutableElement executable = (ExecutableElement) method.getElement(); List parameters = executable.getParameters(); if ( parameters.size() != 1 ) { @@ -369,7 +369,7 @@ public Parameter getSingleParameter(DeclaredType includingType, Accessor method) } public List getParameters(DeclaredType includingType, Accessor accessor) { - ExecutableElement method = accessor.getExecutable(); + ExecutableElement method = (ExecutableElement) accessor.getElement(); TypeMirror methodType = getMethodType( includingType, accessor.getElement() ); if ( method == null || methodType.getKind() != TypeKind.EXECUTABLE ) { return new ArrayList<>(); @@ -427,10 +427,10 @@ public List getThrownTypes(ExecutableType method) { } public List getThrownTypes(Accessor accessor) { - if (accessor.getExecutable() == null) { + if (accessor.getAccessorType() == AccessorType.FIELD) { return new ArrayList<>(); } - return extractTypes( accessor.getExecutable().getThrownTypes() ); + return extractTypes( ( (ExecutableElement) accessor.getElement() ).getThrownTypes() ); } private List extractTypes(List typeMirrors) { @@ -502,7 +502,6 @@ private ImplementationType getImplementationType(TypeMirror mirror) { getTypeParameters( mirror, true ), null, null, - null, implementationType.getPackageName(), implementationType.getName(), implementationType.getFullyQualifiedName(), @@ -523,19 +522,24 @@ private ImplementationType getImplementationType(TypeMirror mirror) { return null; } - private BuilderInfo findBuilder(TypeMirror type) { + private BuilderInfo findBuilder(TypeMirror type, BuilderPrism builderPrism, boolean report) { + if ( builderPrism != null && builderPrism.disableBuilder() ) { + return null; + } try { return roundContext.getAnnotationProcessorContext() .getBuilderProvider() .findBuilderInfo( type ); } catch ( MoreThanOneBuilderCreationMethodException ex ) { - messager.printMessage( - typeUtils.asElement( type ), - Message.BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD, - type, - Strings.join( ex.getBuilderInfo(), ", ", BUILDER_INFO_CREATION_METHOD_EXTRACTOR ) - ); + if ( report ) { + messager.printMessage( + typeUtils.asElement( type ), + Message.BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD, + type, + Strings.join( ex.getBuilderInfo(), ", ", BUILDER_INFO_CREATION_METHOD_EXTRACTOR ) + ); + } } return null; @@ -663,4 +667,21 @@ private boolean canBeProcessed(TypeMirror type) { return true; } + + public BuilderType builderTypeFor( Type type, BuilderPrism builderPrism ) { + if ( type != null ) { + BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, true ); + return BuilderType.create( builderInfo, type, this, this.typeUtils ); + } + return null; + } + + public Type effectiveResultTypeFor( Type type, BuilderPrism builderPrism ) { + if ( type != null ) { + BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, false ); + BuilderType builderType = BuilderType.create( builderInfo, type, this, this.typeUtils ); + return builderType != null ? builderType.getBuilder() : type; + } + return type; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index f2dc9527d1..9c05e382a7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -7,6 +7,7 @@ import java.util.Collections; import java.util.List; +import java.util.Optional; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; @@ -174,7 +175,15 @@ public List getIgnoreUnmappedSourceProperties() { return ignoreUnmappedSourceProperties; } - public BuilderPrism getBuilder() { - return builder; + /** + * derives the builder prism given the options and configuration + * @param method containing mandatory configuration and the mapping options (optionally containing a beanmapping) + * @return a BuilderPrism as optional + */ + public static Optional builderPrismFor(Method method) { + return method.getMapperConfiguration() + .getBuilderPrism( Optional.ofNullable( method.getMappingOptions().getBeanMapping() ) + .map( b -> b.builder ) + .orElse( null ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 4aeb2b5d59..0298dcbf24 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; - import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -82,11 +81,11 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu * @param mappingOptions the mapping options for this method * @param forgedNameBased forges a name based (matched) mapping method */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, - MappingOptions mappingOptions, boolean forgedNameBased) { - String sourceParamName = Strings.decapitalize( sourceType.getName() ); + public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, + ExecutableElement positionHintElement, List additionalParameters, + ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, + MappingOptions mappingOptions, boolean forgedNameBased) { + String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSafeVariableName( sourceParamName ); this.parameters = new ArrayList<>( 1 + additionalParameters.size() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 3d5bf302e1..3e6811af9e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -291,7 +291,10 @@ public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, Format CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); Type writeType = method.getResultType(); if ( !method.isUpdateMethod() ) { - writeType = writeType.getEffectiveType(); + writeType = typeFactory.effectiveResultTypeFor( + writeType, + BeanMapping.builderPrismFor( method ).orElse( null ) + ); } Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); List mappedPropertyNames = new ArrayList<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 46810e0d4d..98f27b8334 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -129,7 +129,6 @@ public interface Method { */ Type getResultType(); - /** * * @return the names of the parameters of this mapping method @@ -187,4 +186,13 @@ public interface Method { * @return the mapping options for this method */ MappingOptions getMappingOptions(); + + /** + * + * @return true when @MappingTarget annotated parameter is the same type as the return type. The method has + * to be an update method in order for this to be true. + */ + default boolean isMappingTargetAssignableToReturnType() { + return isUpdateMethod() ? getResultType().isAssignableTo( getReturnType() ) : false; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java index 03bfe25c65..1eb4bc80b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java @@ -7,11 +7,10 @@ import java.util.Arrays; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; - /** * A PropertyEntry contains information on the name, readAccessor (for source), readAccessor and writeAccessor @@ -22,8 +21,9 @@ public class PropertyEntry { private final String[] fullName; private final Accessor readAccessor; private final Accessor writeAccessor; - private final ExecutableElementAccessor presenceChecker; + private final Accessor presenceChecker; private final Type type; + private final BuilderType builderType; /** * Constructor used to create {@link TargetReference} property entries from a mapping @@ -34,12 +34,13 @@ public class PropertyEntry { * @param type */ private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor writeAccessor, - ExecutableElementAccessor presenceChecker, Type type) { + Accessor presenceChecker, Type type, BuilderType builderType) { this.fullName = fullName; this.readAccessor = readAccessor; this.writeAccessor = writeAccessor; this.presenceChecker = presenceChecker; this.type = type; + this.builderType = builderType; } /** @@ -49,11 +50,12 @@ private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor writeAc * @param readAccessor its read accessor * @param writeAccessor its write accessor * @param type type of the property + * @param builderType the builder for the type * @return the property entry for given parameters. */ public static PropertyEntry forTargetReference(String[] fullName, Accessor readAccessor, - Accessor writeAccessor, Type type) { - return new PropertyEntry( fullName, readAccessor, writeAccessor, null, type ); + Accessor writeAccessor, Type type, BuilderType builderType ) { + return new PropertyEntry( fullName, readAccessor, writeAccessor, null, type, builderType ); } /** @@ -66,8 +68,8 @@ public static PropertyEntry forTargetReference(String[] fullName, Accessor readA * @return the property entry for given parameters. */ public static PropertyEntry forSourceReference(String name, Accessor readAccessor, - ExecutableElementAccessor presenceChecker, Type type) { - return new PropertyEntry( new String[]{name}, readAccessor, null, presenceChecker, type ); + Accessor presenceChecker, Type type) { + return new PropertyEntry( new String[]{name}, readAccessor, null, presenceChecker, type, null ); } public String getName() { @@ -82,7 +84,7 @@ public Accessor getWriteAccessor() { return writeAccessor; } - public ExecutableElementAccessor getPresenceChecker() { + public Accessor getPresenceChecker() { return presenceChecker; } @@ -90,6 +92,10 @@ public Type getType() { return type; } + public BuilderType getBuilderType() { + return builderType; + } + public String getFullName() { return Strings.join( Arrays.asList( fullName ), "." ); } @@ -97,7 +103,7 @@ public String getFullName() { public PropertyEntry pop() { if ( fullName.length > 1 ) { String[] newFullName = Arrays.copyOfRange( fullName, 1, fullName.length ); - return new PropertyEntry(newFullName, readAccessor, writeAccessor, presenceChecker, type ); + return new PropertyEntry(newFullName, readAccessor, writeAccessor, presenceChecker, type, builderType ); } else { return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index efe38231d0..87302dce3c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -5,20 +5,18 @@ */ package org.mapstruct.ap.internal.model.source; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; - import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Accessibility; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -29,6 +27,8 @@ import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * Represents a mapping method with source and target type and the mappings between the properties of source and target * type. @@ -50,6 +50,7 @@ public class SourceMethod implements Method { private final Parameter targetTypeParameter; private final boolean isObjectFactory; private final Type returnType; + private final BuilderType builderType; private final Accessibility accessibility; private final List exceptionTypes; private final MapperConfiguration config; @@ -80,6 +81,7 @@ public static class Builder { private ExecutableElement executable; private List parameters; private Type returnType = null; + private BuilderType builderType = null; private List exceptionTypes; private Map> mappings; private IterableMapping iterableMapping = null; @@ -207,6 +209,7 @@ private SourceMethod(Builder builder, MappingOptions mappingOptions) { this.executable = builder.executable; this.parameters = builder.parameters; this.returnType = builder.returnType; + this.builderType = builder.builderType; this.exceptionTypes = builder.exceptionTypes; this.accessibility = Accessibility.fromModifiers( builder.executable.getModifiers() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 30b80c8b2f..cd76dfff26 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -24,7 +24,6 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; /** * This class describes the source side of a property mapping. @@ -261,7 +260,7 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent for ( String entryName : entryNames ) { boolean matchFound = false; Map sourceReadAccessors = newType.getPropertyReadAccessors(); - Map sourcePresenceCheckers = newType.getPropertyPresenceCheckers(); + Map sourcePresenceCheckers = newType.getPropertyPresenceCheckers(); for ( Map.Entry getter : sourceReadAccessors.entrySet() ) { if ( getter.getKey().equals( entryName ) ) { @@ -297,7 +296,7 @@ public static class BuilderFromProperty { private String name; private Accessor readAccessor; - private ExecutableElementAccessor presenceChecker; + private Accessor presenceChecker; private Type type; private Parameter sourceParameter; @@ -311,7 +310,7 @@ public BuilderFromProperty readAccessor(Accessor readAccessor) { return this; } - public BuilderFromProperty presenceChecker(ExecutableElementAccessor presenceChecker) { + public BuilderFromProperty presenceChecker(Accessor presenceChecker) { this.presenceChecker = presenceChecker; return this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 0edfb362d0..7c30144371 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -13,16 +13,18 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.DeclaredType; +import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.util.AccessorNamingUtils; -import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; /** * This class describes the target side of a property mapping. @@ -146,8 +148,7 @@ public TargetReference build() { Parameter parameter = method.getMappingTargetParameter(); boolean foundEntryMatch; - Type resultType = method.getResultType(); - resultType = typeBasedOnMethod( resultType ); + Type resultType = typeBasedOnMethod( method.getResultType() ); // there can be 4 situations // 1. Return type @@ -198,8 +199,8 @@ private List getTargetEntries(Type type, String[] entryNames) { break; } - if ( isLast || ( accessorNaming.isSetterMethod( targetWriteAccessor ) - || Executables.isFieldAccessor( targetWriteAccessor ) ) ) { + if ( isLast || ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || + targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) ) { // only intermediate nested properties when they are a true setter or field accessor // the last may be other readAccessor (setter / getter / adder). @@ -207,8 +208,27 @@ private List getTargetEntries(Type type, String[] entryNames) { // check if an entry alread exists, otherwise create String[] fullName = Arrays.copyOfRange( entryNames, 0, i + 1 ); - PropertyEntry propertyEntry = PropertyEntry.forTargetReference( fullName, targetReadAccessor, - targetWriteAccessor, nextType ); + BuilderType builderType; + PropertyEntry propertyEntry = null; + if ( method.isUpdateMethod() ) { + propertyEntry = PropertyEntry.forTargetReference( fullName, + targetReadAccessor, + targetWriteAccessor, + nextType, + null + ); + } + else { + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + builderType = typeFactory.builderTypeFor( nextType, builderPrism ); + propertyEntry = PropertyEntry.forTargetReference( fullName, + targetReadAccessor, + targetWriteAccessor, + nextType, + builderType + ); + + } targetEntries.add( propertyEntry ); } @@ -228,8 +248,7 @@ private List getTargetEntries(Type type, String[] entryNames) { private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor targetReadAccessor) { Type nextType; Accessor toUse = targetWriteAccessor != null ? targetWriteAccessor : targetReadAccessor; - if ( accessorNaming.isGetterMethod( toUse ) || - Executables.isFieldAccessor( toUse ) ) { + if ( toUse.getAccessorType() == AccessorType.GETTER || toUse.getAccessorType() == AccessorType.FIELD ) { nextType = typeFactory.getReturnType( (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), toUse @@ -268,7 +287,8 @@ private Type typeBasedOnMethod(Type type) { return type; } else { - return type.getEffectiveType(); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + return typeFactory.effectiveResultTypeFor( type, builderPrism ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 1b31bcf4cb..3ee6adabdb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -41,11 +41,13 @@ import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.BeanMapping; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.DecoratedWithPrism; import org.mapstruct.ap.internal.prism.InheritConfigurationPrism; import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism; @@ -369,10 +371,12 @@ else if ( method.isStreamMapping() ) { } else { this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) .sourceMethod( method ) + .returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builderPrism ) ) .build(); if ( beanMappingMethod != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 9ba8d54d54..b796945f80 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -387,8 +387,7 @@ private Type selectResultType(Type returnType, Parameter targetParameter) { private boolean checkParameterAndReturnType(ExecutableElement method, List sourceParameters, Parameter targetParameter, List contextParameters, - Type resultType, Type returnType, - boolean containsTargetTypeParameter) { + Type resultType, Type returnType, boolean containsTargetTypeParameter) { if ( sourceParameters.isEmpty() ) { messager.printMessage( method, Message.RETRIEVAL_NO_INPUT_ARGS ); return false; @@ -406,8 +405,8 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List getAllEnclosedExecutableElements(Elements elementUtils, TypeElement element) { - List executables = new ArrayList<>(); - for ( Accessor accessor : getAllEnclosedAccessors( elementUtils, element ) ) { - if ( accessor.getExecutable() != null ) { - executables.add( accessor.getExecutable() ); - } - } - return executables; - } - - /** - * Finds all executable elements/variable elements within the given type element, including executable/variable - * elements defined in super classes and implemented interfaces and including the fields in the . Methods defined - * in {@link java.lang.Object} are ignored, as well as implementations of {@link java.lang.Object#equals(Object)}. - * - * @param elementUtils element helper - * @param element the element to inspect - * - * @return the executable elements usable in the type - */ - public static List getAllEnclosedAccessors(Elements elementUtils, TypeElement element) { - List enclosedElements = new ArrayList<>(); + List enclosedElements = new ArrayList<>(); element = replaceTypeElementIfNecessary( elementUtils, element ); addEnclosedElementsInHierarchy( elementUtils, enclosedElements, element, element ); return enclosedElements; } - private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyAdded, + private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyAdded, TypeElement element, TypeElement parentType) { if ( element != parentType ) { // otherwise the element was already checked for replacement element = replaceTypeElementIfNecessary( elementUtils, element ); @@ -150,23 +112,22 @@ private static void addEnclosedElementsInHierarchy(Elements elementUtils, List
      alreadyCollected, + private static void addNotYetOverridden(Elements elementUtils, List alreadyCollected, List methodsToAdd, TypeElement parentType) { - List safeToAdd = new ArrayList<>( methodsToAdd.size() ); + List safeToAdd = new ArrayList<>( methodsToAdd.size() ); for ( ExecutableElement toAdd : methodsToAdd ) { if ( isNotObjectEquals( toAdd ) - && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { - safeToAdd.add( new ExecutableElementAccessor( toAdd ) ); + && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { + safeToAdd.add( toAdd ); } } alreadyCollected.addAll( 0, safeToAdd ); } - private static void addFields(List alreadyCollected, List variablesToAdd) { - List safeToAdd = new ArrayList<>( variablesToAdd.size() ); - for ( VariableElement toAdd : variablesToAdd ) { - safeToAdd.add( new VariableElementAccessor( toAdd ) ); - } - - alreadyCollected.addAll( 0, safeToAdd ); - } - - /** * @param executable the executable to check * @@ -209,8 +160,8 @@ private static void addFields(List alreadyCollected, List alreadyCollected, + private static boolean wasNotYetOverridden(Elements elementUtils, List alreadyCollected, ExecutableElement executable, TypeElement parentType) { - for ( ListIterator it = alreadyCollected.listIterator(); it.hasNext(); ) { - ExecutableElement executableInSubtype = it.next().getExecutable(); + for ( ListIterator it = alreadyCollected.listIterator(); it.hasNext(); ) { + ExecutableElement executableInSubtype = it.next(); if ( executableInSubtype == null ) { continue; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java new file mode 100644 index 0000000000..adf927aed0 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java @@ -0,0 +1,106 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.util.ArrayList; +import java.util.List; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; + +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; + +import static javax.lang.model.util.ElementFilter.fieldsIn; +import static org.mapstruct.ap.internal.util.workarounds.SpecificCompilerWorkarounds.replaceTypeElementIfNecessary; + +/** + * Provides functionality around {@link VariableElement}s. + * + * @author Sjaak Derksen + */ +public class Fields { + + private Fields() { + } + + public static boolean isFieldAccessor(VariableElement method) { + return isPublic( method ) && isNotStatic( method ); + } + + static boolean isPublic(VariableElement method) { + return method.getModifiers().contains( Modifier.PUBLIC ); + } + + private static boolean isNotStatic(VariableElement method) { + return !method.getModifiers().contains( Modifier.STATIC ); + } + + /** + * Finds all variable elements within the given type element, including variable + * elements defined in super classes and implemented interfaces and including the fields in the . + * + * @param elementUtils element helper + * @param element the element to inspect + * + * @return the executable elements usable in the type + */ + public static List getAllEnclosedFields(Elements elementUtils, TypeElement element) { + List enclosedElements = new ArrayList<>(); + element = replaceTypeElementIfNecessary( elementUtils, element ); + addEnclosedElementsInHierarchy( elementUtils, enclosedElements, element, element ); + + return enclosedElements; + } + + private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyAdded, + TypeElement element, TypeElement parentType) { + if ( element != parentType ) { // otherwise the element was already checked for replacement + element = replaceTypeElementIfNecessary( elementUtils, element ); + } + + if ( element.asType().getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( element ); + } + + addFields( alreadyAdded, fieldsIn( element.getEnclosedElements() ) ); + + + if ( hasNonObjectSuperclass( element ) ) { + addEnclosedElementsInHierarchy( + elementUtils, + alreadyAdded, + asTypeElement( element.getSuperclass() ), + parentType + ); + } + } + + private static void addFields(List alreadyCollected, List variablesToAdd) { + List safeToAdd = new ArrayList<>( variablesToAdd.size() ); + for ( VariableElement toAdd : variablesToAdd ) { + safeToAdd.add( toAdd ); + } + + alreadyCollected.addAll( 0, safeToAdd ); + } + + private static TypeElement asTypeElement(TypeMirror mirror) { + return (TypeElement) ( (DeclaredType) mirror ).asElement(); + } + + private static boolean hasNonObjectSuperclass(TypeElement element) { + if ( element.getSuperclass().getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( element ); + } + + return element.getSuperclass().getKind() == TypeKind.DECLARED + && !asTypeElement( element.getSuperclass() ).getQualifiedName().toString().equals( "java.lang.Object" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 2b784785a5..ec69b7131a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -7,11 +7,23 @@ import java.util.LinkedList; import java.util.List; - import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.ExecutableType; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; +import org.mapstruct.ap.internal.util.accessor.VariableElementAccessor; + +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.accessor.AccessorType.ADDER; +import static org.mapstruct.ap.internal.util.accessor.AccessorType.GETTER; +import static org.mapstruct.ap.internal.util.accessor.AccessorType.PRESENCE_CHECKER; +import static org.mapstruct.ap.internal.util.accessor.AccessorType.SETTER; /** * Filter methods for working with {@link Element} collections. @@ -20,66 +32,88 @@ */ public class Filters { - private Filters() { + private final AccessorNamingUtils accessorNaming; + private final Types typeUtils; + private final TypeMirror typeMirror; + + public Filters(AccessorNamingUtils accessorNaming, Types typeUtils, TypeMirror typeMirror) { + this.accessorNaming = accessorNaming; + this.typeUtils = typeUtils; + this.typeMirror = typeMirror; } - public static List getterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { + public List getterMethodsIn(List elements) { List getterMethods = new LinkedList<>(); - for ( Accessor method : elements ) { + for ( ExecutableElement method : elements ) { if ( accessorNaming.isGetterMethod( method ) ) { - getterMethods.add( method ); + getterMethods.add( new ExecutableElementAccessor( method, getReturnType( method ), GETTER ) ); } } return getterMethods; } - public static List fieldsIn(List accessors) { + public List fieldsIn(List accessors) { List fieldAccessors = new LinkedList<>(); - for ( Accessor accessor : accessors ) { - if ( Executables.isFieldAccessor( accessor ) ) { - fieldAccessors.add( accessor ); + for ( VariableElement accessor : accessors ) { + if ( Fields.isFieldAccessor( accessor ) ) { + fieldAccessors.add( new VariableElementAccessor( accessor ) ); } } return fieldAccessors; } - public static List presenceCheckMethodsIn(AccessorNamingUtils accessorNaming, - List elements) { - List presenceCheckMethods = new LinkedList<>(); + public List presenceCheckMethodsIn(List elements) { + List presenceCheckMethods = new LinkedList<>(); - for ( Accessor method : elements ) { + for ( ExecutableElement method : elements ) { if ( accessorNaming.isPresenceCheckMethod( method ) ) { - presenceCheckMethods.add( (ExecutableElementAccessor) method ); + presenceCheckMethods.add( new ExecutableElementAccessor( + method, + getReturnType( method ), + PRESENCE_CHECKER + ) ); } } return presenceCheckMethods; } - public static List setterMethodsIn(AccessorNamingUtils accessorNaming, List elements) { + public List setterMethodsIn(List elements) { List setterMethods = new LinkedList<>(); - for ( Accessor method : elements ) { + for ( ExecutableElement method : elements ) { if ( accessorNaming.isSetterMethod( method ) ) { - setterMethods.add( method ); + setterMethods.add( new ExecutableElementAccessor( method, getFirstParameter( method ), SETTER ) ); } } return setterMethods; } - public static List adderMethodsIn(AccessorNamingUtils accessorNaming, List elements) { + public List adderMethodsIn( List elements) { List adderMethods = new LinkedList<>(); - for ( Accessor method : elements ) { + for ( ExecutableElement method : elements ) { if ( accessorNaming.isAdderMethod( method ) ) { - adderMethods.add( method ); + adderMethods.add( new ExecutableElementAccessor( method, getFirstParameter( method ), ADDER ) ); } } return adderMethods; } + + private TypeMirror getReturnType(ExecutableElement executableElement) { + return getWithinContext( executableElement ).getReturnType(); + } + + private TypeMirror getFirstParameter(ExecutableElement executableElement) { + return first( getWithinContext( executableElement ).getParameterTypes() ); + } + + private ExecutableType getWithinContext( ExecutableElement executableElement ) { + return (ExecutableType) typeUtils.asMemberOf( (DeclaredType) typeMirror, executableElement ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index cb812b53b7..909152b6a0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -271,15 +272,18 @@ public boolean isDisableSubMappingMethodsGeneration() { return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation } - public BuilderPrism getBuilderPrism() { - if ( mapperPrism.values.builder() != null ) { - return mapperPrism.builder(); + public Optional getBuilderPrism(BuilderPrism beanMappingBuilderPrism) { + if ( beanMappingBuilderPrism != null ) { + return Optional.ofNullable( beanMappingBuilderPrism ); + } + else if ( mapperPrism.values.builder() != null ) { + return Optional.ofNullable( mapperPrism.builder() ); } else if ( mapperConfigPrism != null && mapperConfigPrism.values.builder() != null ) { - return mapperConfigPrism.builder(); + return Optional.ofNullable( mapperConfigPrism.builder() ); } else { - return null; + return Optional.empty(); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java index 28c706bef0..31a3a9c6cd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.util; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; /** * This a wrapper class which provides the value that needs to be used in the models. @@ -45,7 +46,7 @@ public static ValueProvider of(Accessor accessor) { return null; } String value = accessor.getSimpleName().toString(); - if ( accessor.getExecutable() != null ) { + if ( accessor.getAccessorType() != AccessorType.FIELD ) { value += "()"; } return new ValueProvider( value ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java index b5b671c2dd..5a16e45fa8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java @@ -38,4 +38,5 @@ public Set getModifiers() { public T getElement() { return element; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index 9fb0969807..f9dd435d5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -8,6 +8,7 @@ import java.util.Set; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.VariableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.Name; import javax.lang.model.type.TypeMirror; @@ -23,7 +24,7 @@ public interface Accessor { * This returns the type that this accessor gives as a return. * * e.g. The {@link ExecutableElement#getReturnType()} if this is a method accessor, - * or {@link javax.lang.model.element.VariableElement#asType()} for field accessors. + * or {@link VariableElement#asType()} for field accessors. * * @return the type that the accessor gives as a return */ @@ -40,12 +41,14 @@ public interface Accessor { Set getModifiers(); /** - * @return the {@link ExecutableElement}, or {@code null} if the accessor does not have one + * @return the underlying {@link Element}, {@link VariableElement} or {@link ExecutableElement} */ - ExecutableElement getExecutable(); + Element getElement(); /** - * @return the underlying {@link Element} + * The accessor type + * + * @return */ - Element getElement(); + AccessorType getAccessorType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java new file mode 100644 index 0000000000..9348de878c --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +public enum AccessorType { + + FIELD, + GETTER, + SETTER, + ADDER, + PRESENCE_CHECKER; +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java index effd137b04..af37acbce1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java @@ -15,22 +15,27 @@ */ public class ExecutableElementAccessor extends AbstractAccessor { - public ExecutableElementAccessor(ExecutableElement element) { + private final TypeMirror accessedType; + private final AccessorType accessorType; + + public ExecutableElementAccessor(ExecutableElement element, TypeMirror accessedType, AccessorType accessorType) { super( element ); + this.accessedType = accessedType; + this.accessorType = accessorType; } @Override public TypeMirror getAccessedType() { - return element.getReturnType(); + return accessedType; } @Override - public ExecutableElement getExecutable() { - return element; + public String toString() { + return element.toString(); } @Override - public String toString() { - return element.toString(); + public AccessorType getAccessorType() { + return accessorType; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java index cdbdf1f09f..8b1b01dbd6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.internal.util.accessor; -import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; @@ -26,12 +25,13 @@ public TypeMirror getAccessedType() { } @Override - public ExecutableElement getExecutable() { - return null; + public String toString() { + return element.toString(); } @Override - public String toString() { - return element.toString(); + public AccessorType getAccessorType() { + return AccessorType.FIELD; } + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 2d702efe2d..b8ffd0a179 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -10,7 +10,7 @@ <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#assign targetType = resultType /> <#if !existingInstanceMapping> - <#assign targetType = resultType.effectiveType /> + <#assign targetType = returnTypeToConstruct /> <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=targetType/> @@ -25,7 +25,7 @@ <#if !existingInstanceMapping> - <@includeModel object=resultType.effectiveType/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=resultType.effectiveType/><#else>new <@includeModel object=resultType.effectiveType/>(); + <@includeModel object=returnTypeToConstruct/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=returnTypeToConstruct/><#else>new <@includeModel object=returnTypeToConstruct/>(); <#list beforeMappingReferencesWithMappingTarget as callback> diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 064aabfd85..9552e881bd 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -167,7 +167,6 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, - null, fullQualifiedName, false, false, diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 76ceac40df..bc90a7c3c3 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -115,7 +115,6 @@ private Type typeWithFQN(String fullQualifiedName) { null, null, null, - null, fullQualifiedName, false, false, diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java index 2d0fe0f78a..ac3e0fc6f6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -113,18 +113,7 @@ public void builderMappingMapperConfigDefined() { TooManyBuilderCreationMethodsMapper.class }) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, - // We have 2 diagnostics, as we don't do caching of the types, so a type is processed multiple types diagnostics = { - @Diagnostic( - type = Case.class, - kind = javax.tools.Diagnostic.Kind.WARNING, - line = 11, - messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + - "Found methods: " + - "\".*wrongBuilder\\(\\) ?, " + - ".*builder\\(\\) ?\"\\. " + - "Builder will not be used\\. Consider implementing a custom BuilderProvider SPI\\." - ), @Diagnostic( type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMapper.java new file mode 100644 index 0000000000..94e5101720 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.off; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface SimpleMapper { + + @BeanMapping( builder = @Builder( disableBuilder = true ) ) + @Mapping(target = "name", source = "fullName") + SimpleNotRealyImmutablePerson toNotRealyImmutable(SimpleMutablePerson source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMutablePerson.java new file mode 100644 index 0000000000..d3cde44d21 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleMutablePerson.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.off; + +public class SimpleMutablePerson { + private String fullName; + + public String getFullName() { + return fullName; + } + + public void setFullName(String fullName) { + this.fullName = fullName; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java new file mode 100644 index 0000000000..a98be84d22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.off; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("1743") +@WithClasses({ + SimpleMutablePerson.class, + SimpleNotRealyImmutablePerson.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class SimpleNotRealyImmutableBuilderTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ SimpleMapper.class }) + public void testSimpleImmutableBuilderHappyPath() { + SimpleMapper mapper = Mappers.getMapper( SimpleMapper.class ); + SimpleMutablePerson source = new SimpleMutablePerson(); + source.setFullName( "Bob" ); + + SimpleNotRealyImmutablePerson targetObject = mapper.toNotRealyImmutable( source ); + + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutablePerson.java new file mode 100644 index 0000000000..4caba6b016 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutablePerson.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.off; + +public class SimpleNotRealyImmutablePerson { + + private String name; + + public static Builder builder() { + return new Builder(); + } + + public SimpleNotRealyImmutablePerson() { + } + + SimpleNotRealyImmutablePerson(Builder builder) { + this.name = builder.name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public static class Builder { + + private String name; + + public Builder name(String name) { + throw new IllegalStateException( "name should not be called on builder" ); + } + + public SimpleNotRealyImmutablePerson build() { + return new SimpleNotRealyImmutablePerson( this ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index d46a4b6d06..8f493bb6ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -160,22 +160,18 @@ public void shouldFailOnSuperBounds2() { ErroneousSourceTargetMapper6.class, NoProperties.class }) - @ExpectedCompilationOutcome(value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = ErroneousSourceTargetMapper6.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, - messageRegExp = "No target bean properties found: can't map property \".*NoProperties " - + "foo\\.wrapped\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeA " + - "foo\\.wrapped\""), - @Diagnostic(type = ErroneousSourceTargetMapper6.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, - messageRegExp = ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " + - "accessible parameterless constructor\\.") - - }) + @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { + @Diagnostic( type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, messageRegExp = + ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " + + "accessible parameterless constructor\\." ), + @Diagnostic( type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, messageRegExp = + "No target bean properties found: can't map property \".*NoProperties " + + "foo\\.wrapped\" to" + + " \"org.mapstruct.ap.test.selection.generics.TypeA " + + "foo\\.wrapped\"" ) + } ) public void shouldFailOnNonMatchingWildCards() { } } From 9c33199a667a56f89b5a4086b94b6290a430cdd5 Mon Sep 17 00:00:00 2001 From: Matt Drees Date: Sat, 25 May 2019 03:34:30 -0600 Subject: [PATCH 0363/1006] Improve terms in qualifier docs (#1814) This sentence is talking about `@Target`, not `@Retention`. Also, let's use 'type' instead of 'class' to line up with `ElementType.TYPE`. --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index a08adbae54..ba9b2119cc 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -1344,7 +1344,7 @@ public @interface GermanToEnglish { ---- ==== -Please take note of the retention `TitleTranslator` on class level, `EnglishToGerman`, `GermanToEnglish` on method level! +Please take note of the target `TitleTranslator` on type level, `EnglishToGerman`, `GermanToEnglish` on method level! Then, using the qualifiers, the mapping could look like this: From d50e41cdbb605edcb41d550e37da96733e6f1b1c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 25 May 2019 18:14:00 +0200 Subject: [PATCH 0364/1006] #1776 adding a message when no qualifiers are found (#1786) --- .../model/ContainerMappingMethodBuilder.java | 25 ++++----- .../ap/internal/model/MapMappingMethod.java | 40 ++++++-------- .../internal/model/MappingBuilderContext.java | 4 +- .../ap/internal/model/PropertyMapping.java | 55 ++++++++++--------- .../creation/MappingResolverImpl.java | 25 ++++++++- .../mapstruct/ap/internal/util/Message.java | 1 + .../selection/qualifier/QualifierTest.java | 11 +++- 7 files changed, 96 insertions(+), 65 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index c4dc73f611..f495375d60 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -89,25 +89,15 @@ public final M build() { false ); - Assignment assignment = ctx.getMappingResolver().getTargetAssignment( - method, + Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, targetElementType, formattingParameters, criteria, sourceRHS, - null + null, + () -> forge( sourceRHS, sourceElementType, targetElementType ) ); - if ( assignment == null && !criteria.hasQualfiers() ) { - assignment = forgeMapping( sourceRHS, sourceElementType, targetElementType ); - if ( assignment != null ) { - ctx.getMessager().note( 2, Message.ITERABLEMAPPING_CREATE_ELEMENT_NOTE, assignment ); - } - } - else { - ctx.getMessager().note( 2, Message.ITERABLEMAPPING_SELECT_ELEMENT_NOTE, assignment ); - } - if ( assignment == null ) { if ( method instanceof ForgedMethod ) { // leave messaging to calling property mapping @@ -124,6 +114,7 @@ public final M build() { } } else { + ctx.getMessager().note( 2, Message.ITERABLEMAPPING_SELECT_ELEMENT_NOTE, assignment ); if ( method instanceof ForgedMethod ) { ForgedMethod forgedMethod = (ForgedMethod) method; forgedMethod.addThrownTypes( assignment.getThrownTypes() ); @@ -171,6 +162,14 @@ public final M build() { ); } + private Assignment forge(SourceRHS sourceRHS, Type sourceType, Type targetType) { + Assignment assignment = super.forgeMapping( sourceRHS, sourceType, targetType ); + if ( assignment != null ) { + ctx.getMessager().note( 2, Message.ITERABLEMAPPING_CREATE_ELEMENT_NOTE, assignment ); + } + return assignment; + } + protected abstract M instantiateMappingMethod(Method method, Collection existingVariables, Assignment assignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 81026c5ec2..cc6155be96 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -97,19 +97,10 @@ public MapMappingMethod build() { keyFormattingParameters, keyCriteria, keySourceRHS, - null + null, + () -> forge( keySourceRHS, keySourceType, keyTargetType, Message.MAPMAPPING_CREATE_KEY_NOTE ) ); - if ( keyAssignment == null && !keyCriteria.hasQualfiers( ) ) { - keyAssignment = forgeMapping( keySourceRHS, keySourceType, keyTargetType ); - if ( keyAssignment != null ) { - ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_KEY_NOTE, keyAssignment ); - } - } - else { - ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_KEY_NOTE, keyAssignment ); - } - if ( keyAssignment == null ) { if ( method instanceof ForgedMethod ) { // leave messaging to calling property mapping @@ -129,6 +120,9 @@ public MapMappingMethod build() { ); } } + else { + ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_KEY_NOTE, keyAssignment ); + } // find mapping method or conversion for value Type valueSourceType = sourceTypeParams.get( 1 ).getTypeBound(); @@ -146,7 +140,8 @@ public MapMappingMethod build() { valueFormattingParameters, valueCriteria, valueSourceRHS, - null + null, + () -> forge( valueSourceRHS, valueSourceType, valueTargetType, Message.MAPMAPPING_CREATE_VALUE_NOTE ) ); if ( method instanceof ForgedMethod ) { @@ -159,16 +154,6 @@ public MapMappingMethod build() { } } - if ( valueAssignment == null && !valueCriteria.hasQualfiers( ) ) { - valueAssignment = forgeMapping( valueSourceRHS, valueSourceType, valueTargetType ); - if ( valueAssignment != null ) { - ctx.getMessager().note( 2, Message.MAPMAPPING_CREATE_VALUE_NOTE, valueAssignment ); - } - } - else { - ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_VALUE_NOTE, valueAssignment ); - } - if ( valueAssignment == null ) { if ( method instanceof ForgedMethod ) { // leave messaging to calling property mapping @@ -188,6 +173,9 @@ public MapMappingMethod build() { ); } } + else { + ctx.getMessager().note( 2, Message.MAPMAPPING_SELECT_VALUE_NOTE, valueAssignment ); + } // mapNullToDefault boolean mapNullToDefault = false; @@ -222,6 +210,14 @@ public MapMappingMethod build() { ); } + Assignment forge(SourceRHS sourceRHS, Type sourceType, Type targetType, Message message ) { + Assignment assignment = forgeMapping( sourceRHS, sourceType, targetType ); + if ( assignment != null ) { + ctx.getMessager().note( 2, message, assignment ); + } + return assignment; + } + @Override protected boolean shouldUsePropertyNamesInHistory() { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index bbbf69dbdc..dae67e927f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Supplier; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.TypeElement; @@ -93,7 +94,8 @@ public interface MappingResolver { Assignment getTargetAssignment(Method mappingMethod, Type targetType, FormattingParameters formattingParameters, SelectionCriteria criteria, SourceRHS sourceRHS, - AnnotationMirror positionHint); + AnnotationMirror positionHint, + Supplier forger); Set getUsedSupportedMappings(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index a439f69178..d298a710df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -280,36 +280,17 @@ public PropertyMapping build() { formattingParameters, criteria, rightHandSide, - positionHint + positionHint, + () -> forge( ) ); } - - Type sourceType = rightHandSide.getSourceType(); - // No mapping found. Try to forge a mapping - if ( assignment == null && !criteria.hasQualfiers() ) { - if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) { - assignment = forgeIterableMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); - } - else if ( sourceType.isMapType() && targetType.isMapType() ) { - assignment = forgeMapMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); - } - else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) || - ( sourceType.isStreamType() && targetType.isStreamType() ) || - ( sourceType.isStreamType() && targetType.isIterableType() ) ) { - assignment = forgeStreamMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); - } - else { - assignment = forgeMapping( rightHandSide ); - } - if ( assignment != null ) { - ctx.getMessager().note( 2, Message.PROPERTYMAPPING_CREATE_NOTE, assignment ); - } - } else { - ctx.getMessager().note( 2, Message.PROPERTYMAPPING_SELECT_NOTE, assignment ); + assignment = forge(); } + Type sourceType = rightHandSide.getSourceType(); if ( assignment != null ) { + ctx.getMessager().note( 2, Message.PROPERTYMAPPING_SELECT_NOTE, assignment ); if ( targetType.isCollectionOrMapType() ) { assignment = assignToCollection( targetType, targetWriteAccessorType, assignment ); } @@ -336,6 +317,29 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get ); } + private Assignment forge( ) { + Assignment assignment; + Type sourceType = rightHandSide.getSourceType(); + if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) { + assignment = forgeIterableMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); + } + else if ( sourceType.isMapType() && targetType.isMapType() ) { + assignment = forgeMapMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); + } + else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) + || ( sourceType.isStreamType() && targetType.isStreamType() ) + || ( sourceType.isStreamType() && targetType.isIterableType() ) ) { + assignment = forgeStreamMapping( sourceType, targetType, rightHandSide, method.getExecutable() ); + } + else { + assignment = forgeMapping( rightHandSide ); + } + if ( assignment != null ) { + ctx.getMessager().note( 2, Message.PROPERTYMAPPING_CREATE_NOTE, assignment ); + } + return assignment; + } + /** * Report that a mapping could not be created. */ @@ -844,7 +848,8 @@ public PropertyMapping build() { formattingParameters, criteria, new SourceRHS( constantExpression, sourceType, existingVariableNames, sourceErrorMessagePart ), - positionHint + positionHint, + () -> null ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index d9e8748932..cf3c588f0d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.function.Supplier; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; @@ -97,7 +98,8 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T public Assignment getTargetAssignment(Method mappingMethod, Type targetType, FormattingParameters formattingParameters, SelectionCriteria criteria, SourceRHS sourceRHS, - AnnotationMirror positionHint) { + AnnotationMirror positionHint, + Supplier forger) { ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, @@ -105,7 +107,8 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, formattingParameters, sourceRHS, criteria, - positionHint + positionHint, + forger ); return attempt.getTargetAssignment( sourceRHS.getSourceTypeForMatching(), targetType ); @@ -136,6 +139,7 @@ private class ResolvingAttempt { private final boolean savedPreferUpdateMapping; private final FormattingParameters formattingParameters; private final AnnotationMirror positionHint; + private final Supplier forger; // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches, // second doesn't. In that case, the first builtin method should not lead to a supported method @@ -145,7 +149,8 @@ private class ResolvingAttempt { private ResolvingAttempt(List sourceModel, Method mappingMethod, FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria, - AnnotationMirror positionHint) { + AnnotationMirror positionHint, + Supplier forger) { this.mappingMethod = mappingMethod; this.methods = filterPossibleCandidateMethods( sourceModel ); @@ -156,6 +161,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, this.selectionCriteria = criteria; this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); this.positionHint = positionHint; + this.forger = forger; } private List filterPossibleCandidateMethods(List candidateMethods) { @@ -243,6 +249,19 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { return conversion.getAssignment(); } + if ( hasQualfiers() ) { + messager.printMessage( + mappingMethod.getExecutable(), + positionHint, + Message.GENERAL_NO_QUALIFYING_METHOD, + Strings.join( selectionCriteria.getQualifiers(), ", " ), + Strings.join( selectionCriteria.getQualifiedByNames(), ", " ) + ); + } + else { + return forger.get(); + } + // if nothing works, alas, the result is null return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index a7e6159bb1..821e31db42 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -113,6 +113,7 @@ public enum Message { GENERAL_JODA_NOT_ON_CLASSPATH( "Cannot validate Joda dateformat, no Joda on classpath. Consider adding Joda to the annotation processorpath.", Diagnostic.Kind.WARNING ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible parameterless constructor." ), + GENERAL_NO_QUALIFYING_METHOD( "No qualifying method found for qualifiers: %s and / or qualifying names: %s" ), BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), BUILDER_NO_BUILD_METHOD_FOUND("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\".", Diagnostic.Kind.ERROR ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 1d298f94d1..6edbb93cf6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -98,7 +98,16 @@ public void shouldMatchClassAndMethod() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = ErroneousMapper.class, + @Diagnostic( + type = ErroneousMapper.class, + kind = Kind.ERROR, + line = 28, + messageRegExp = + "No qualifying method found for qualifiers: " + + "org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated and " + + "/ or qualifying names: .*"), + @Diagnostic( + type = ErroneousMapper.class, kind = Kind.ERROR, line = 28, messageRegExp = From 119826982ab7a8d7d5a995ca80319992acca150f Mon Sep 17 00:00:00 2001 From: Jonathan Kraska Date: Sun, 26 May 2019 11:41:44 -0400 Subject: [PATCH 0365/1006] #1826: fixed null pointer in nested property mapping when using presence checking (#1827) --- copyright.txt | 1 + .../model/NestedPropertyMappingMethod.ftl | 2 +- .../ap/test/bugs/_1826/Issue1826Mapper.java | 20 +++++++++++ .../ap/test/bugs/_1826/Issue1826Test.java | 34 +++++++++++++++++++ .../ap/test/bugs/_1826/SourceChild.java | 25 ++++++++++++++ .../ap/test/bugs/_1826/SourceParent.java | 26 ++++++++++++++ .../mapstruct/ap/test/bugs/_1826/Target.java | 19 +++++++++++ 7 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceChild.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceParent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Target.java diff --git a/copyright.txt b/copyright.txt index 6757936ad1..826b627d49 100644 --- a/copyright.txt +++ b/copyright.txt @@ -23,6 +23,7 @@ Gervais Blaise - https://github.com/gervaisb Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla Jeff Smyth - https://github.com/smythie86 +Jonathan Kraska - https://github.com/jakraska Joshua Spoerri - https://github.com/spoerri Kevin Grüneberg - https://github.com/kevcodez Michael Pardo - https://github.com/pardom diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index e50e55bc34..22dc2d8c37 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -12,7 +12,7 @@ } <#list propertyEntries as entry> <#if entry.presenceCheckerName?? > - if ( !<@localVarName index=entry_index/>.${entry.presenceCheckerName}() ) { + if ( <#if entry_index != 0><@localVarName index=entry_index/> == null || !<@localVarName index=entry_index/>.${entry.presenceCheckerName}() ) { return ${returnType.null}; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Mapper.java new file mode 100644 index 0000000000..126837cbfa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1826; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue1826Mapper { + + Issue1826Mapper INSTANCE = Mappers.getMapper( Issue1826Mapper.class ); + + @Mapping(target = "content", source = "sourceChild.content") + Target sourceAToTarget(SourceParent sourceParent); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java new file mode 100644 index 0000000000..66f6cb14f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1826; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1826") +@WithClasses({ + SourceParent.class, + SourceChild.class, + Target.class, + Issue1826Mapper.class +}) +public class Issue1826Test { + + @Test + public void testNestedPropertyMappingChecksForNull() { + SourceParent sourceParent = new SourceParent(); + sourceParent.setSourceChild( null ); + + Target result = Issue1826Mapper.INSTANCE.sourceAToTarget( sourceParent ); + assertThat( result.getContent() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceChild.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceChild.java new file mode 100644 index 0000000000..4243d444eb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceChild.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1826; + +public class SourceChild { + + private String content; + private Boolean hasContent = false; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + hasContent = true; + } + + public Boolean hasContent() { + return hasContent; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceParent.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceParent.java new file mode 100644 index 0000000000..65f737d15d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/SourceParent.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1826; + +public class SourceParent { + + private SourceChild sourceChild; + private Boolean hasSourceChild = false; + + public SourceChild getSourceChild() { + return sourceChild; + } + + public void setSourceChild(SourceChild sourceChild) { + this.sourceChild = sourceChild; + this.hasSourceChild = true; + } + + public Boolean hasSourceChild() { + return hasSourceChild; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Target.java new file mode 100644 index 0000000000..9d2ec717f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Target.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1826; + +public class Target { + + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} From 7bee12138da5f601364987d053e4fd3eeb43cbcd Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 18 Jul 2019 07:20:22 +0200 Subject: [PATCH 0366/1006] #1307 & #1845 remove deprecated enummapping & create ST - refs under bean mapping #1307 remove deprecated enum mapping #1845 create source / target references under bean mapping --- .../ap/internal/conversion/Conversions.java | 8 +- .../conversion/ReverseConversion.java | 4 +- .../ap/internal/model/BeanMappingMethod.java | 172 +++++++----- .../ap/internal/model/EnumMappingMethod.java | 201 ------------- .../NestedTargetPropertyMappingHolder.java | 160 +++++------ .../ap/internal/model/PropertyMapping.java | 14 +- .../ap/internal/model/common/Parameter.java | 52 ++-- .../model/dependency/GraphAnalyzer.java | 5 +- .../internal/model/source/ForgedMethod.java | 1 - .../ap/internal/model/source/Mapping.java | 264 +++++++++--------- .../internal/model/source/MappingOptions.java | 164 ++++------- .../internal/model/source/MethodMatcher.java | 4 +- .../internal/model/source/SourceMethod.java | 99 +++---- .../model/source/SourceReference.java | 29 +- .../model/source/TargetReference.java | 107 ++++--- .../internal/model/source/ValueMapping.java | 2 +- .../processor/MapperCreationProcessor.java | 125 +++------ .../processor/MethodRetrievalProcessor.java | 20 +- .../mapstruct/ap/internal/util/Message.java | 2 +- .../ap/test/bugs/_1180/Issue1180Test.java | 4 +- .../ap/test/enums/EnumMappingTest.java | 154 ---------- ...usOrderMapperMappingSameConstantTwice.java | 30 -- ...ppingConstantWithoutMatchInTargetType.java | 22 -- ...sOrderMapperUsingUnknownEnumConstants.java | 28 -- .../ap/test/enums/ExternalOrderType.java | 14 - .../org/mapstruct/ap/test/enums/OrderDto.java | 22 -- .../mapstruct/ap/test/enums/OrderEntity.java | 22 -- .../mapstruct/ap/test/enums/OrderMapper.java | 29 -- .../mapstruct/ap/test/enums/OrderType.java | 14 - .../attributereference/ErroneousMapper.java | 10 +- .../ErroneousMappingsTest.java | 16 +- .../NestedSourcePropertiesTest.java | 2 +- .../ap/test/bugs/_1685/UserMapperImpl.java | 130 ++++----- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 106 +++---- .../DomainDtoWithNvmsDefaultMapperImpl.java | 140 +++++----- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 140 +++++----- .../DomainDtoWithPresenceCheckMapperImpl.java | 100 +++---- .../mixed/FishTankMapperConstantImpl.java | 30 +- .../nestedbeans/mixed/FishTankMapperImpl.java | 50 ++-- .../ArtistToChartEntryImpl.java | 40 +-- .../ChartEntryToArtistImpl.java | 44 +-- .../ChartEntryToArtistUpdateImpl.java | 12 +- .../source/constants/ConstantsMapperImpl.java | 20 +- 43 files changed, 975 insertions(+), 1637 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 9f0ad97485..08185ac51d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -27,7 +27,7 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; -import static org.mapstruct.ap.internal.conversion.ReverseConversion.reverse; +import static org.mapstruct.ap.internal.conversion.ReverseConversion.inverse; /** * Holds built-in {@link ConversionProvider}s such as from {@code int} to {@code String}. @@ -244,7 +244,7 @@ else if ( sourceType.isPrimitive() && !targetType.isPrimitive() ) { register( sourceType, targetType, new PrimitiveToWrapperConversion( sourceType, targetType ) ); } else if ( !sourceType.isPrimitive() && targetType.isPrimitive() ) { - register( sourceType, targetType, reverse( new PrimitiveToWrapperConversion( targetType, sourceType ) ) ); + register( sourceType, targetType, inverse( new PrimitiveToWrapperConversion( targetType, sourceType ) ) ); } else { register( sourceType, targetType, new WrapperToWrapperConversion( sourceType, targetType ) ); @@ -283,7 +283,7 @@ private void register(Class sourceClass, Class targetClass, ConversionProv Type targetType = typeFactory.getType( targetClass ); conversions.put( new Key( sourceType, targetType ), conversion ); - conversions.put( new Key( targetType, sourceType ), reverse( conversion ) ); + conversions.put( new Key( targetType, sourceType ), inverse( conversion ) ); } private void register(String sourceTypeName, Class targetClass, ConversionProvider conversion) { @@ -291,7 +291,7 @@ private void register(String sourceTypeName, Class targetClass, ConversionPro Type targetType = typeFactory.getType( targetClass ); conversions.put( new Key( sourceType, targetType ), conversion ); - conversions.put( new Key( targetType, sourceType ), reverse( conversion ) ); + conversions.put( new Key( targetType, sourceType ), inverse( conversion ) ); } public ConversionProvider getConversion(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java index 30fe24fa34..7fd7f6bbb8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java @@ -12,7 +12,7 @@ import org.mapstruct.ap.internal.model.HelperMethod; /** - * A {@link ConversionProvider} which creates the reversed conversions for a + * * A {@link ConversionProvider} which creates the inversed conversions for a * given conversion provider. * * @author Gunnar Morling @@ -21,7 +21,7 @@ public class ReverseConversion implements ConversionProvider { private ConversionProvider conversionProvider; - public static ReverseConversion reverse(ConversionProvider conversionProvider) { + public static ReverseConversion inverse(ConversionProvider conversionProvider) { return new ReverseConversion( conversionProvider ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index f8cbde9757..a5cb32e214 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -5,11 +5,6 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; -import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; -import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; - import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; @@ -23,7 +18,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; - +import java.util.function.Consumer; +import java.util.function.Function; import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; @@ -55,6 +51,12 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.model.source.Mapping.getMappingByTargetName; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; +import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; +import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; + /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally * configured by one or more {@link PropertyMapping}s. @@ -84,9 +86,9 @@ public static class Builder { private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); - private Map> methodMappings; - private SingleMappingByTargetPropertyNameFunction singleMapping; - private final Map> unprocessedDefinedTargets = new HashMap<>(); + private Function singleMapping; + private Consumer> mappingsInitializer; + private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -99,13 +101,18 @@ public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { } public Builder sourceMethod(SourceMethod sourceMethod) { - singleMapping = new SourceMethodSingleMapping( sourceMethod ); + singleMapping = + targetName -> getMappingByTargetName( targetName, sourceMethod.getMappingOptions().getMappings() ); + mappingsInitializer = + mappings -> mappings.stream().forEach( mapping -> initReferencesForSourceMethodMapping( mapping ) ); this.method = sourceMethod; return this; } public Builder forgedMethod(Method method) { - singleMapping = new EmptySingleMapping(); + singleMapping = targetPropertyName -> null; + mappingsInitializer = + mappings -> mappings.stream().forEach( mapping -> initReferencesForForgedMethodMapping( mapping ) ); this.method = method; return this; } @@ -151,7 +158,10 @@ public BeanMappingMethod build() { /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; - this.methodMappings = this.method.getMappingOptions().getMappings(); + /* initialize mappings for this method && filter invalid inverse methods */ + mappingsInitializer.accept( method.getMappingOptions().getMappings() ); + method.getMappingOptions().getMappings().removeIf( mapping -> !isValidWhenReversed( mapping ) ); + CollectionMappingStrategyPrism cms = this.method.getMapperConfiguration().getCollectionMappingStrategy(); // determine accessors @@ -285,12 +295,12 @@ private MethodReference getFinalizerMethod() { * If there were nested defined targets that have not been handled. Then we need to process them at the end. */ private void handleUnprocessedDefinedTargets() { - Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); + Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); // For each of the unprocessed defined targets forge a mapping for each of the // method source parameters. The generated mappings are not going to use forged name based mappings. while ( iterator.hasNext() ) { - Entry> entry = iterator.next(); + Entry> entry = iterator.next(); String propertyName = entry.getKey(); if ( !unprocessedTargetProperties.containsKey( propertyName ) ) { continue; @@ -446,7 +456,68 @@ private MethodReference getFactoryMethod(Type returnTypeImpl, SelectionParameter return factoryMethod; } + /** + * Initialized the source- and target reference for a certain mapping for regular non forged methods + * + * @param mapping the mapping + */ + private void initReferencesForSourceMethodMapping(Mapping mapping ) { + + // handle source reference + SourceReference sourceReference = new SourceReference.BuilderFromMapping() + .mapping( mapping ) + .method( method ) + .messager( ctx.getMessager() ) + .typeFactory( ctx.getTypeFactory() ) + .build(); + mapping.setSourceReference( sourceReference ); + + // handle target reference + TargetReference targetReference = new TargetReference.BuilderFromTargetMapping() + .mapping( mapping ) + .method( method ) + .messager( ctx.getMessager() ) + .typeFactory( ctx.getTypeFactory() ) + .build(); + mapping.setTargetReference( targetReference ); + + } + + /** + * Initialized the source- and target reference for forged methods (e.g. when handling nesting) + * + * @param mapping the mapping + */ + private void initReferencesForForgedMethodMapping(Mapping mapping ) { + + /* a forge method has always one mandatory source parameter and no more */ + Parameter sourceParameter = first( Parameter.getSourceParameters( method.getParameters() ) ); + + SourceReference sourceReference = mapping.getSourceReference(); + if ( sourceReference != null ) { + SourceReference oldSourceReference = sourceReference; + sourceReference = new SourceReference.BuilderFromSourceReference() + .sourceParameter( sourceParameter ) + .sourceReference( oldSourceReference ) + .build(); + } + mapping.setSourceReference( sourceReference ); + + } + /** + * MapStruct filters automatically inversed invalid methods out. TODO: this is a principle we should discuss! + * @param mapping + * @return + */ + private static boolean isValidWhenReversed(Mapping mapping) { + if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { + return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() != null ? + mapping.getSourceReference().isValid() : + true ); + } + return true; + } /** * Iterates over all defined mapping methods ({@code @Mapping(s)}), either directly given or inherited from the @@ -468,28 +539,26 @@ private boolean handleDefinedMappings() { errorOccurred = handleDefinedNestedTargetMapping( handledTargets ); } - for ( Map.Entry> entry : methodMappings.entrySet() ) { - for ( Mapping mapping : entry.getValue() ) { - TargetReference targetReference = mapping.getTargetReference(); - if ( targetReference.isValid() ) { - String target = first( targetReference.getPropertyEntries() ).getFullName(); - if ( !handledTargets.contains( target ) ) { - if ( handleDefinedMapping( mapping, handledTargets ) ) { - errorOccurred = true; - } - } - if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { - List sourceEntries = mapping.getSourceReference().getPropertyEntries(); - if ( !sourceEntries.isEmpty() ) { - String source = first( sourceEntries ).getFullName(); - unprocessedSourceProperties.remove( source ); - } + for ( Mapping mapping : method.getMappingOptions().getMappings() ) { + TargetReference targetReference = mapping.getTargetReference(); + if ( targetReference.isValid() ) { + String target = first( targetReference.getPropertyEntries() ).getFullName(); + if ( !handledTargets.contains( target ) ) { + if ( handleDefinedMapping( mapping, handledTargets ) ) { + errorOccurred = true; } } - else { - errorOccurred = true; + if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { + List sourceEntries = mapping.getSourceReference().getPropertyEntries(); + if ( !sourceEntries.isEmpty() ) { + String source = first( sourceEntries ).getFullName(); + unprocessedSourceProperties.remove( source ); + } } } + else { + errorOccurred = true; + } } // remove the remaining name based properties @@ -513,7 +582,7 @@ private boolean handleDefinedNestedTargetMapping(Set handledTargets) { propertyMappings.addAll( holder.getPropertyMappings() ); handledTargets.addAll( holder.getHandledTargets() ); // Store all the unprocessed defined targets. - for ( Entry> entry : holder.getUnprocessedDefinedTarget().entrySet() ) { + for ( Entry> entry : holder.getUnprocessedDefinedTarget().entrySet() ) { if ( entry.getValue().isEmpty() ) { continue; } @@ -670,8 +739,7 @@ private void applyPropertyNameBasedMapping() { sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); if ( sourceReadAccessor != null ) { - Mapping mapping = singleMapping.getSingleMappingByTargetPropertyName( - targetProperty.getKey() ); + Mapping mapping = singleMapping.apply( targetProperty.getKey() ); DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); SourceReference sourceRef = new SourceReference.BuilderFromProperty() @@ -693,7 +761,7 @@ private void applyPropertyNameBasedMapping() { .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .defaultValue( mapping != null ? mapping.getDefaultValue() : null ) .existingVariableNames( existingVariableNames ) - .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) + .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetPropertyName, false ) ) .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? @@ -743,7 +811,7 @@ private void applyParameterNameBasedMapping() { Parameter sourceParameter = sourceParameters.next(); if ( sourceParameter.getName().equals( targetProperty.getKey() ) ) { - Mapping mapping = singleMapping.getSingleMappingByTargetPropertyName( targetProperty.getKey() ); + Mapping mapping = singleMapping.apply( targetProperty.getKey() ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) @@ -760,7 +828,7 @@ private void applyParameterNameBasedMapping() { .formattingParameters( mapping != null ? mapping.getFormattingParameters() : null ) .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .existingVariableNames( existingVariableNames ) - .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptyList() ) + .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) .forgeMethodWithMappingOptions( extractAdditionalOptions( targetProperty.getKey(), false ) ) .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? @@ -781,11 +849,7 @@ private void applyParameterNameBasedMapping() { private MappingOptions extractAdditionalOptions(String targetProperty, boolean restrictToDefinedMappings) { MappingOptions additionalOptions = null; if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { - - Map> mappings = new HashMap<>(); - for ( Mapping mapping : unprocessedDefinedTargets.get( targetProperty ) ) { - mappings.put( mapping.getTargetName(), Collections.singletonList( mapping ) ); - } + Set mappings = unprocessedDefinedTargets.get( targetProperty ); additionalOptions = MappingOptions.forMappingsOnly( mappings, restrictToDefinedMappings ); } return additionalOptions; @@ -1037,27 +1101,5 @@ private interface SingleMappingByTargetPropertyNameFunction { Mapping getSingleMappingByTargetPropertyName(String targetPropertyName); } - private static class EmptySingleMapping implements SingleMappingByTargetPropertyNameFunction { - - @Override - public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { - return null; - } - } - - private static class SourceMethodSingleMapping implements SingleMappingByTargetPropertyNameFunction { - - private final SourceMethod sourceMethod; - - private SourceMethodSingleMapping(SourceMethod sourceMethod) { - this.sourceMethod = sourceMethod; - } - - @Override - public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { - return sourceMethod.getSingleMappingByTargetPropertyName( targetPropertyName ); - } - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java deleted file mode 100644 index 53d2e5ec29..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/EnumMappingMethod.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.model; - -import static org.mapstruct.ap.internal.util.Collections.first; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; - -import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.source.EnumMapping; -import org.mapstruct.ap.internal.model.source.Mapping; -import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.prism.BeanMappingPrism; -import org.mapstruct.ap.internal.util.Message; -import org.mapstruct.ap.internal.util.Strings; - -/** - * A {@link MappingMethod} which maps one enum type to another, optionally configured by one or more - * {@link EnumMapping}s. - * - * @author Gunnar Morling - */ -public class EnumMappingMethod extends MappingMethod { - - private final List enumMappings; - - public static class Builder { - - private SourceMethod method; - private MappingBuilderContext ctx; - - public Builder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; - } - - public Builder sourceMethod(SourceMethod sourceMethod) { - this.method = sourceMethod; - return this; - } - - public EnumMappingMethod build() { - - if ( !reportErrorIfMappedEnumConstantsDontExist( method ) - || !reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConstantAreNotMapped( method ) ) { - return null; - } - - List enumMappings = new ArrayList<>(); - - List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); - - for ( String enumConstant : sourceEnumConstants ) { - List mappedConstants = method.getMappingBySourcePropertyName( enumConstant ); - - if ( mappedConstants.isEmpty() ) { - enumMappings.add( new EnumMapping( enumConstant, enumConstant ) ); - } - else if ( mappedConstants.size() == 1 ) { - enumMappings.add( - new EnumMapping( - enumConstant, first( mappedConstants ).getTargetName() - ) - ); - } - else { - List targetConstants = new ArrayList<>( mappedConstants.size() ); - for ( Mapping mapping : mappedConstants ) { - targetConstants.add( mapping.getTargetName() ); - } - ctx.getMessager().printMessage( method.getExecutable(), - Message.ENUMMAPPING_MULTIPLE_SOURCES, - enumConstant, - Strings.join( targetConstants, ", " ) - ); - } - } - - SelectionParameters selectionParameters = getSelecionParameters( method, ctx.getTypeUtils() ); - - Set existingVariables = new HashSet<>( method.getParameterNames() ); - List beforeMappingMethods = - LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); - List afterMappingMethods = - LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); - - return new EnumMappingMethod( method, enumMappings, beforeMappingMethods, afterMappingMethods ); - } - - private static SelectionParameters getSelecionParameters(SourceMethod method, Types typeUtils) { - BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); - if ( beanMappingPrism != null ) { - List qualifiers = beanMappingPrism.qualifiedBy(); - List qualifyingNames = beanMappingPrism.qualifiedByName(); - TypeMirror resultType = beanMappingPrism.resultType(); - return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); - } - return null; - } - - private boolean reportErrorIfMappedEnumConstantsDontExist(SourceMethod method) { - List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); - List targetEnumConstants = method.getReturnType().getEnumConstants(); - - boolean foundIncorrectMapping = false; - - for ( List mappedConstants : method.getMappingOptions().getMappings().values() ) { - for ( Mapping mappedConstant : mappedConstants ) { - - if ( mappedConstant.getSourceName() == null ) { - ctx.getMessager().printMessage( method.getExecutable(), - mappedConstant.getMirror(), - Message.ENUMMAPPING_UNDEFINED_SOURCE - ); - foundIncorrectMapping = true; - } - else if ( !sourceEnumConstants.contains( mappedConstant.getSourceName() ) ) { - ctx.getMessager().printMessage( method.getExecutable(), - mappedConstant.getMirror(), - mappedConstant.getSourceAnnotationValue(), - Message.ENUMMAPPING_NON_EXISTING_CONSTANT, - mappedConstant.getSourceName(), - first( method.getSourceParameters() ).getType() - ); - foundIncorrectMapping = true; - } - if ( mappedConstant.getTargetName() == null ) { - ctx.getMessager().printMessage( method.getExecutable(), - mappedConstant.getMirror(), - Message.ENUMMAPPING_UNDEFINED_TARGET - ); - foundIncorrectMapping = true; - } - else if ( !targetEnumConstants.contains( mappedConstant.getTargetName() ) ) { - ctx.getMessager().printMessage( method.getExecutable(), - mappedConstant.getMirror(), - mappedConstant.getTargetAnnotationValue(), - Message.ENUMMAPPING_NON_EXISTING_CONSTANT, - mappedConstant.getTargetName(), - method.getReturnType() - ); - foundIncorrectMapping = true; - } - } - } - - return !foundIncorrectMapping; - } - - private boolean reportErrorIfSourceEnumConstantsWithoutCorrespondingTargetConstantAreNotMapped( - SourceMethod method) { - - List sourceEnumConstants = first( method.getSourceParameters() ).getType().getEnumConstants(); - List targetEnumConstants = method.getReturnType().getEnumConstants(); - List unmappedSourceEnumConstants = new ArrayList<>(); - - for ( String sourceEnumConstant : sourceEnumConstants ) { - if ( !targetEnumConstants.contains( sourceEnumConstant ) - && method.getMappingBySourcePropertyName( sourceEnumConstant ).isEmpty() ) { - unmappedSourceEnumConstants.add( sourceEnumConstant ); - } - } - - if ( !unmappedSourceEnumConstants.isEmpty() ) { - ctx.getMessager().printMessage( method.getExecutable(), - Message.ENUMMAPPING_UNMAPPED_SOURCES, - Strings.join( unmappedSourceEnumConstants, ", " ) - ); - } - - return unmappedSourceEnumConstants.isEmpty(); - } - - } - - private EnumMappingMethod(Method method, List enumMappings, - List beforeMappingMethods, - List afterMappingMethods) { - super( method, beforeMappingMethods, afterMappingMethods ); - this.enumMappings = enumMappings; - } - - public List getEnumMappings() { - return enumMappings; - } - - public Parameter getSourceParameter() { - return first( getSourceParameters() ); - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 2cf9b258e4..87d75c0665 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -6,12 +6,13 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.source.Mapping; @@ -20,7 +21,6 @@ import org.mapstruct.ap.internal.model.source.PropertyEntry; import org.mapstruct.ap.internal.model.source.SourceReference; import org.mapstruct.ap.internal.model.source.TargetReference; -import org.mapstruct.ap.internal.util.Extractor; import static org.mapstruct.ap.internal.util.Collections.first; @@ -32,33 +32,16 @@ */ public class NestedTargetPropertyMappingHolder { - private static final Extractor SOURCE_PARAM_EXTRACTOR = new - Extractor() { - @Override - public Parameter apply(SourceReference sourceReference) { - return sourceReference.getParameter(); - } - }; - - private static final Extractor PROPERTY_EXTRACTOR = new - Extractor() { - @Override - public PropertyEntry apply(SourceReference sourceReference) { - return sourceReference.getPropertyEntries().isEmpty() ? null : - first( sourceReference.getPropertyEntries() ); - } - }; - private final List processedSourceParameters; private final Set handledTargets; private final List propertyMappings; - private final Map> unprocessedDefinedTarget; + private final Map> unprocessedDefinedTarget; private final boolean errorOccurred; public NestedTargetPropertyMappingHolder( List processedSourceParameters, Set handledTargets, List propertyMappings, - Map> unprocessedDefinedTarget, boolean errorOccurred) { + Map> unprocessedDefinedTarget, boolean errorOccurred) { this.processedSourceParameters = processedSourceParameters; this.handledTargets = handledTargets; this.propertyMappings = propertyMappings; @@ -90,7 +73,7 @@ public List getPropertyMappings() { /** * @return a map of all the unprocessed defined targets that can be applied to name forged base methods */ - public Map> getUnprocessedDefinedTarget() { + public Map> getUnprocessedDefinedTarget() { return unprocessedDefinedTarget; } @@ -132,10 +115,10 @@ public NestedTargetPropertyMappingHolder build() { // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); - Map> unprocessedDefinedTarget + Map> unprocessedDefinedTarget = new LinkedHashMap<>(); - for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { + for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { PropertyEntry targetProperty = entryByTP.getKey(); //Now we are grouping the already popped mappings by the source parameter(s) of the method GroupedBySourceParameters groupedBySourceParam = groupBySourceParameter( @@ -148,7 +131,7 @@ public NestedTargetPropertyMappingHolder build() { // All not processed mappings that should have been applied to all are part of the unprocessed // defined targets unprocessedDefinedTarget.put( targetProperty, groupedBySourceParam.notProcessedAppliesToAll ); - for ( Map.Entry> entryByParam : groupedBySourceParam + for ( Map.Entry> entryByParam : groupedBySourceParam .groupedBySourceParameter.entrySet() ) { Parameter sourceParameter = entryByParam.getKey(); @@ -164,7 +147,7 @@ public NestedTargetPropertyMappingHolder build() { // from the Mappings and not restrict on the defined mappings (allow to forge name based mapping) // if we have composite methods i.e. more then 2 parameters then we have to force a creation // of an update method in our generation - for ( Map.Entry> entryBySP : groupedSourceReferences + for ( Map.Entry> entryBySP : groupedSourceReferences .groupedBySourceReferences .entrySet() ) { PropertyEntry sourceEntry = entryBySP.getKey(); @@ -180,7 +163,7 @@ public NestedTargetPropertyMappingHolder build() { //}) // See Issue1269Test, Issue1247Test, AutomappingAndNestedTest for more info as well MappingOptions sourceMappingOptions = MappingOptions.forMappingsOnly( - groupByTargetName( entryBySP.getValue() ), + entryBySP.getValue(), multipleSourceParametersForTP, forceUpdateMethodOrNonNestedReferencesPresent ); @@ -214,7 +197,7 @@ public NestedTargetPropertyMappingHolder build() { // do update on the defined Mappings. if ( !groupedSourceReferences.nonNested.isEmpty() ) { MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( - groupByTargetName( groupedSourceReferences.nonNested ), + groupedSourceReferences.nonNested, true ); SourceReference reference = new SourceReference.BuilderFromProperty() @@ -270,12 +253,12 @@ public NestedTargetPropertyMappingHolder build() { * @param sourceParameter the source parameter that is used * @param forceUpdateMethod whether we need to force an update method */ - private void handleSourceParameterMappings(List sourceParameterMappings, PropertyEntry targetProperty, + private void handleSourceParameterMappings(Set sourceParameterMappings, PropertyEntry targetProperty, Parameter sourceParameter, boolean forceUpdateMethod) { if ( !sourceParameterMappings.isEmpty() ) { // The source parameter mappings have no mappings, the source name is actually the parameter itself MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( - new HashMap<>(), + new LinkedHashSet<>(), false, true ); @@ -346,34 +329,33 @@ private void handleSourceParameterMappings(List sourceParameterMappings * @return See above */ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOptions) { - Map> mappings = mappingOptions.getMappings(); + Set mappings = mappingOptions.getMappings(); // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty + Map> mappingsKeyedByProperty = new LinkedHashMap<>(); - Map> singleTargetReferences + Map> singleTargetReferences = new LinkedHashMap<>(); boolean errorOccurred = false; - for ( List mapping : mappings.values() ) { - Mapping firstMapping = first( mapping ); - TargetReference targetReference = firstMapping.getTargetReference(); + for ( Mapping mapping : mappings ) { + TargetReference targetReference = mapping.getTargetReference(); if ( !targetReference.isValid() ) { errorOccurred = true; continue; } PropertyEntry property = first( targetReference.getPropertyEntries() ); - Mapping newMapping = firstMapping.popTargetReference(); + Mapping newMapping = mapping.popTargetReference(); if ( newMapping != null ) { // group properties on current name. if ( !mappingsKeyedByProperty.containsKey( property ) ) { - mappingsKeyedByProperty.put( property, new ArrayList<>() ); + mappingsKeyedByProperty.put( property, new LinkedHashSet<>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } else { if ( !singleTargetReferences.containsKey( property ) ) { - singleTargetReferences.put( property, new ArrayList<>() ); + singleTargetReferences.put( property, new LinkedHashSet<>() ); } - singleTargetReferences.get( property ).add( firstMapping ); + singleTargetReferences.get( property ).add( mapping ); } } @@ -463,16 +445,16 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp * property as the {@code mappings} * @return the split mapping options. */ - private GroupedBySourceParameters groupBySourceParameter(List mappings, - List singleTargetReferences) { + private GroupedBySourceParameters groupBySourceParameter(Set mappings, + Set singleTargetReferences) { - Map> mappingsKeyedByParameter = new LinkedHashMap<>(); - List appliesToAll = new ArrayList<>(); + Map> mappingsKeyedByParameter = new LinkedHashMap<>(); + Set appliesToAll = new LinkedHashSet<>(); for ( Mapping mapping : mappings ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { Parameter parameter = mapping.getSourceReference().getParameter(); if ( !mappingsKeyedByParameter.containsKey( parameter ) ) { - mappingsKeyedByParameter.put( parameter, new ArrayList<>() ); + mappingsKeyedByParameter.put( parameter, new LinkedHashSet<>() ); } mappingsKeyedByParameter.get( parameter ).add( mapping ); } @@ -484,15 +466,15 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, populateWithSingleTargetReferences( mappingsKeyedByParameter, singleTargetReferences, - SOURCE_PARAM_EXTRACTOR + SourceReference::getParameter ); - for ( Map.Entry> entry : mappingsKeyedByParameter.entrySet() ) { + for ( Map.Entry> entry : mappingsKeyedByParameter.entrySet() ) { entry.getValue().addAll( appliesToAll ); } - List notProcessAppliesToAll = - mappingsKeyedByParameter.isEmpty() ? appliesToAll : new ArrayList<>(); + Set notProcessAppliesToAll = + mappingsKeyedByParameter.isEmpty() ? appliesToAll : new LinkedHashSet<>(); return new GroupedBySourceParameters( mappingsKeyedByParameter, notProcessAppliesToAll ); } @@ -527,14 +509,14 @@ private GroupedBySourceParameters groupBySourceParameter(List mappings, * * @return the Grouped Source References */ - private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry> entryByParam, - List singleTargetReferences) { - List mappings = entryByParam.getValue(); - List nonNested = new ArrayList<>(); - List appliesToAll = new ArrayList<>(); - List sourceParameterMappings = new ArrayList<>(); + private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry> entryByParam, + Set singleTargetReferences) { + Set mappings = entryByParam.getValue(); + Set nonNested = new LinkedHashSet<>(); + Set appliesToAll = new LinkedHashSet<>(); + Set sourceParameterMappings = new LinkedHashSet<>(); // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty + Map> mappingsKeyedByProperty = new LinkedHashMap<>(); for ( Mapping mapping : mappings ) { @@ -543,7 +525,7 @@ private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry() ); + mappingsKeyedByProperty.put( property, new LinkedHashSet<>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } @@ -561,7 +543,7 @@ else if ( mapping.getSourceReference() == null ) { // applied to everything. boolean hasNoMappings = mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty(); Parameter sourceParameter = entryByParam.getKey(); - List singleTargetReferencesToUse = + Set singleTargetReferencesToUse = extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( singleTargetReferences, sourceParameterMappings, @@ -572,14 +554,15 @@ else if ( mapping.getSourceReference() == null ) { populateWithSingleTargetReferences( mappingsKeyedByProperty, singleTargetReferencesToUse, - PROPERTY_EXTRACTOR + sourceReference -> sourceReference.getPropertyEntries().isEmpty() ? null : + first( sourceReference.getPropertyEntries() ) ); - for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { + for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { entry.getValue().addAll( appliesToAll ); } - List notProcessedAppliesToAll = new ArrayList<>(); + Set notProcessedAppliesToAll = new LinkedHashSet<>(); // If the applied to all were not added to all properties because they were empty, and the non-nested // one are not empty, add them to the non-nested ones if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { @@ -614,12 +597,12 @@ else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { * * @return a list with valid single target references */ - private List extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( - List singleTargetReferences, List sourceParameterMappings, boolean hasNoMappings, + private Set extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( + Set singleTargetReferences, Set sourceParameterMappings, boolean hasNoMappings, Parameter sourceParameter) { - List singleTargetReferencesToUse = null; + Set singleTargetReferencesToUse = null; if ( singleTargetReferences != null ) { - singleTargetReferencesToUse = new ArrayList<>( singleTargetReferences.size() ); + singleTargetReferencesToUse = new LinkedHashSet<>( singleTargetReferences.size() ); for ( Mapping mapping : singleTargetReferences ) { if ( mapping.getSourceReference() == null || !mapping.getSourceReference().isValid() || !sourceParameter.equals( mapping.getSourceReference().getParameter() ) ) { @@ -642,17 +625,6 @@ private List extractSingleTargetReferencesToUseAndPopulateSourceParamet return singleTargetReferencesToUse; } - private Map> groupByTargetName(List mappingList) { - Map> result = new LinkedHashMap<>(); - for ( Mapping mapping : mappingList ) { - if ( !result.containsKey( mapping.getTargetName() ) ) { - result.put( mapping.getTargetName(), new ArrayList<>() ); - } - result.get( mapping.getTargetName() ).add( mapping ); - } - return result; - } - private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mappingOptions, PropertyEntry targetProperty, SourceReference sourceReference, boolean forceUpdateMethod) { PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() @@ -679,8 +651,8 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mapp * @param singleTargetReferences to use * @param keyExtractor to be used to extract a key */ - private void populateWithSingleTargetReferences(Map> map, - List singleTargetReferences, Extractor keyExtractor) { + private void populateWithSingleTargetReferences(Map> map, + Set singleTargetReferences, Function keyExtractor) { if ( singleTargetReferences != null ) { //This are non nested target references only their property needs to be added as they most probably // define it @@ -688,7 +660,7 @@ private void populateWithSingleTargetReferences(Map> map, if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { K key = keyExtractor.apply( mapping.getSourceReference() ); if ( key != null && !map.containsKey( key ) ) { - map.put( key, new ArrayList<>() ); + map.put( key, new LinkedHashSet<>() ); } } } @@ -697,11 +669,11 @@ private void populateWithSingleTargetReferences(Map> map, } private static class GroupedBySourceParameters { - private final Map> groupedBySourceParameter; - private final List notProcessedAppliesToAll; + private final Map> groupedBySourceParameter; + private final Set notProcessedAppliesToAll; - private GroupedBySourceParameters(Map> groupedBySourceParameter, - List notProcessedAppliesToAll) { + private GroupedBySourceParameters(Map> groupedBySourceParameter, + Set notProcessedAppliesToAll) { this.groupedBySourceParameter = groupedBySourceParameter; this.notProcessedAppliesToAll = notProcessedAppliesToAll; } @@ -712,12 +684,12 @@ private GroupedBySourceParameters(Map> groupedBySourceP * references (target references that were not nested). */ private static class GroupedTargetReferences { - private final Map> poppedTargetReferences; - private final Map> singleTargetReferences; + private final Map> poppedTargetReferences; + private final Map> singleTargetReferences; private final boolean errorOccurred; - private GroupedTargetReferences(Map> poppedTargetReferences, - Map> singleTargetReferences, boolean errorOccurred) { + private GroupedTargetReferences(Map> poppedTargetReferences, + Map> singleTargetReferences, boolean errorOccurred) { this.poppedTargetReferences = poppedTargetReferences; this.singleTargetReferences = singleTargetReferences; this.errorOccurred = errorOccurred; @@ -759,14 +731,14 @@ private GroupedTargetReferences(Map> poppedTargetRe */ private static class GroupedSourceReferences { - private final Map> groupedBySourceReferences; - private final List nonNested; - private final List notProcessedAppliesToAll; - private final List sourceParameterMappings; + private final Map> groupedBySourceReferences; + private final Set nonNested; + private final Set notProcessedAppliesToAll; + private final Set sourceParameterMappings; - private GroupedSourceReferences(Map> groupedBySourceReferences, - List nonNested, List notProcessedAppliesToAll, - List sourceParameterMappings) { + private GroupedSourceReferences(Map> groupedBySourceReferences, + Set nonNested, Set notProcessedAppliesToAll, + Set sourceParameterMappings) { this.groupedBySourceReferences = groupedBySourceReferences; this.nonNested = nonNested; this.notProcessedAppliesToAll = notProcessedAppliesToAll; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index d298a710df..9c6bb49de8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -70,7 +70,7 @@ public class PropertyMapping extends ModelElement { private final ValueProvider targetReadAccessorProvider; private final Type targetType; private final Assignment assignment; - private final List dependsOn; + private final Set dependsOn; private final Assignment defaultValueAssignment; @SuppressWarnings("unchecked") @@ -84,7 +84,7 @@ private static class MappingBuilderBase> extends protected String targetPropertyName; protected String sourcePropertyName; - protected List dependsOn; + protected Set dependsOn; protected Set existingVariableNames; protected AnnotationMirror positionHint; @@ -134,7 +134,7 @@ public T sourcePropertyName(String sourcePropertyName) { return (T) this; } - public T dependsOn(List dependsOn) { + public T dependsOn(Set dependsOn) { this.dependsOn = dependsOn; return (T) this; } @@ -1005,7 +1005,7 @@ public PropertyMapping build() { private PropertyMapping(String name, String targetWriteAccessorName, ValueProvider targetReadAccessorProvider, Type targetType, Assignment propertyAssignment, - List dependsOn, Assignment defaultValueAssignment ) { + Set dependsOn, Assignment defaultValueAssignment ) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, targetType, propertyAssignment, dependsOn, defaultValueAssignment ); @@ -1014,7 +1014,7 @@ private PropertyMapping(String name, String targetWriteAccessorName, private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, ValueProvider targetReadAccessorProvider, Type targetType, Assignment assignment, - List dependsOn, Assignment defaultValueAssignment) { + Set dependsOn, Assignment defaultValueAssignment) { this.name = name; this.sourceBeanName = sourceBeanName; this.targetWriteAccessorName = targetWriteAccessorName; @@ -1022,7 +1022,7 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.targetType = targetType; this.assignment = assignment; - this.dependsOn = dependsOn != null ? dependsOn : Collections.emptyList(); + this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet(); this.defaultValueAssignment = defaultValueAssignment; } @@ -1070,7 +1070,7 @@ public Set getImportTypes() { ); } - public List getDependsOn() { + public Set getDependsOn() { return dependsOn; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index e4dea46a4f..f93ae8095a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.internal.model.common; -import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.lang.model.element.VariableElement; import org.mapstruct.ap.internal.prism.ContextPrism; @@ -139,15 +139,20 @@ public static Parameter forForgedMappingTarget(Type parameterType) { * @return the parameters from the given list that are considered 'source parameters' */ public static List getSourceParameters(List parameters) { - List sourceParameters = new ArrayList<>( parameters.size() ); - - for ( Parameter parameter : parameters ) { - if ( !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext() ) { - sourceParameters.add( parameter ); - } - } + return parameters.stream().filter( Parameter::isSourceParameter ).collect( Collectors.toList() ); + } - return sourceParameters; + /** + * @param parameters the parameters to scan + * @param sourceParameterName the source parameter name to match + * @return the parameters from the given list that are considered 'source parameters' + */ + public static Parameter getSourceParameter(List parameters, String sourceParameterName) { + return parameters.stream() + .filter( Parameter::isSourceParameter ) + .filter( parameter -> parameter.getName().equals( sourceParameterName ) ) + .findAny() + .orElse( null ); } /** @@ -155,34 +160,19 @@ public static List getSourceParameters(List parameters) { * @return the parameters from the given list that are marked as 'mapping context parameters' */ public static List getContextParameters(List parameters) { - List contextParameters = new ArrayList<>( parameters.size() ); - - for ( Parameter parameter : parameters ) { - if ( parameter.isMappingContext() ) { - contextParameters.add( parameter ); - } - } - - return contextParameters; + return parameters.stream().filter( Parameter::isMappingContext ).collect( Collectors.toList() ); } public static Parameter getMappingTargetParameter(List parameters) { - for ( Parameter parameter : parameters ) { - if ( parameter.isMappingTarget() ) { - return parameter; - } - } - - return null; + return parameters.stream().filter( Parameter::isMappingTarget ).findAny().orElse( null ); } public static Parameter getTargetTypeParameter(List parameters) { - for ( Parameter parameter : parameters ) { - if ( parameter.isTargetType() ) { - return parameter; - } - } + return parameters.stream().filter( Parameter::isTargetType ).findAny().orElse( null ); + } - return null; + private static boolean isSourceParameter( Parameter parameter ) { + return !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext(); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java index 19e6374d55..b9c4540d77 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -114,7 +115,7 @@ public static class GraphAnalyzerBuilder { private final Map nodes = new LinkedHashMap<>(); - public GraphAnalyzerBuilder withNode(String name, List descendants) { + public GraphAnalyzerBuilder withNode(String name, Set descendants) { Node node = getNode( name ); for ( String descendant : descendants ) { @@ -125,7 +126,7 @@ public GraphAnalyzerBuilder withNode(String name, List descendants) { } public GraphAnalyzerBuilder withNode(String name, String... descendants) { - return withNode( name, Arrays.asList( descendants ) ); + return withNode( name, new LinkedHashSet<>( Arrays.asList( descendants ) ) ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java index 0298dcbf24..7b63909a94 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java @@ -104,7 +104,6 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu this.positionHintElement = positionHintElement; this.history = history; this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions; - this.mappingOptions.initWithParameter( sourceParameter ); this.forgedNameBased = forgedNameBased; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index f9bd4d4a30..5e3de4208f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -5,30 +5,24 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.LinkedHashSet; +import java.util.Objects; +import java.util.Set; +import java.util.function.Predicate; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; -import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.MappingPrism; import org.mapstruct.ap.internal.prism.MappingsPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -52,7 +46,7 @@ public class Mapping { private final SelectionParameters selectionParameters; private final boolean isIgnored; - private final List dependsOn; + private final Set dependsOn; private final AnnotationMirror mirror; private final AnnotationValue sourceAnnotationValue; @@ -61,27 +55,59 @@ public class Mapping { private final NullValueCheckStrategyPrism nullValueCheckStrategy; private final NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy; + private final InheritContext inheritContext; private SourceReference sourceReference; private TargetReference targetReference; - public static Map> fromMappingsPrism(MappingsPrism mappingsAnnotation, - ExecutableElement method, FormattingMessager messager, Types typeUtils) { - Map> mappings = new HashMap<>(); + public static class InheritContext { + + private final boolean isReversed; + private final boolean isForwarded; + private final Method inheritedFromMethod; + + public InheritContext(boolean isReversed, boolean isForwarded, Method inheritedFromMethod) { + this.isReversed = isReversed; + this.isForwarded = isForwarded; + this.inheritedFromMethod = inheritedFromMethod; + } + + public boolean isReversed() { + return isReversed; + } + + public boolean isForwarded() { + return isForwarded; + } + + public Method getInheritedFromMethod() { + return inheritedFromMethod; + } + } + + public static Set getMappingTargetNamesBy(Predicate predicate, Set mappings) { + return mappings.stream() + .filter( predicate ) + .map( Mapping::getTargetName ) + .collect( Collectors.toCollection( LinkedHashSet::new ) ); + } + + public static Mapping getMappingByTargetName(String targetName, Set mappings) { + return mappings.stream().filter( mapping -> mapping.targetName.equals( targetName ) ).findAny().orElse( null ); + } + + public static Set fromMappingsPrism(MappingsPrism mappingsAnnotation, ExecutableElement method, + FormattingMessager messager, Types typeUtils) { + Set mappings = new LinkedHashSet<>(); for ( MappingPrism mappingPrism : mappingsAnnotation.value() ) { Mapping mapping = fromMappingPrism( mappingPrism, method, messager, typeUtils ); if ( mapping != null ) { - List mappingsOfProperty = mappings.get( mappingPrism.target() ); - if ( mappingsOfProperty == null ) { - mappingsOfProperty = new ArrayList<>(); - mappings.put( mappingPrism.target(), mappingsOfProperty ); - } - - mappingsOfProperty.add( mapping ); - - if ( mappingsOfProperty.size() > 1 && !isEnumType( method.getReturnType() ) ) { + if ( mappings.contains( mapping ) ) { messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mappingPrism.target() ); } + else { + mappings.add( mapping ); + } } } @@ -104,8 +130,9 @@ public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElem String defaultValue = mappingPrism.values.defaultValue() == null ? null : mappingPrism.defaultValue(); boolean resultTypeIsDefined = mappingPrism.values.resultType() != null; - List dependsOn = - mappingPrism.dependsOn() != null ? mappingPrism.dependsOn() : Collections.emptyList(); + Set dependsOn = mappingPrism.dependsOn() != null ? + new LinkedHashSet( mappingPrism.dependsOn() ) : + Collections.emptySet(); FormattingParameters formattingParam = new FormattingParameters( dateFormat, @@ -147,7 +174,8 @@ public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElem mappingPrism.values.dependsOn(), dependsOn, nullValueCheckStrategy, - nullValuePropertyMappingStrategy + nullValuePropertyMappingStrategy, + null ); } @@ -166,7 +194,8 @@ public static Mapping forIgnore( String targetName) { null, null, null, - new ArrayList(), + Collections.emptySet(), + null, null, null ); @@ -298,13 +327,14 @@ else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null } @SuppressWarnings("checkstyle:parameternumber") - private Mapping( String sourceName, String constant, String javaExpression, String defaultJavaExpression, - String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror, - AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue, - FormattingParameters formattingParameters, SelectionParameters selectionParameters, - AnnotationValue dependsOnAnnotationValue, List dependsOn, - NullValueCheckStrategyPrism nullValueCheckStrategy, - NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy ) { + private Mapping(String sourceName, String constant, String javaExpression, String defaultJavaExpression, + String targetName, String defaultValue, boolean isIgnored, AnnotationMirror mirror, + AnnotationValue sourceAnnotationValue, AnnotationValue targetAnnotationValue, + FormattingParameters formattingParameters, SelectionParameters selectionParameters, + AnnotationValue dependsOnAnnotationValue, Set dependsOn, + NullValueCheckStrategyPrism nullValueCheckStrategy, + NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy, + InheritContext inheritContext) { this.sourceName = sourceName; this.constant = constant; this.javaExpression = javaExpression; @@ -321,6 +351,7 @@ private Mapping( String sourceName, String constant, String javaExpression, Stri this.dependsOn = dependsOn; this.nullValueCheckStrategy = nullValueCheckStrategy; this.nullValuePropertyMappingStrategy = nullValuePropertyMappingStrategy; + this.inheritContext = inheritContext; } private Mapping( Mapping mapping, TargetReference targetReference ) { @@ -342,6 +373,7 @@ private Mapping( Mapping mapping, TargetReference targetReference ) { this.targetReference = targetReference; this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; + this.inheritContext = mapping.inheritContext; } private Mapping( Mapping mapping, SourceReference sourceReference ) { @@ -363,6 +395,7 @@ private Mapping( Mapping mapping, SourceReference sourceReference ) { this.targetReference = mapping.targetReference; this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; + this.inheritContext = mapping.inheritContext; } private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, @@ -403,64 +436,7 @@ private static String getDefaultExpression(MappingPrism mappingPrism, Executable return javaExpressionMatcher.group( 1 ).trim(); } - private static boolean isEnumType(TypeMirror mirror) { - return mirror.getKind() == TypeKind.DECLARED && - ( (DeclaredType) mirror ).asElement().getKind() == ElementKind.ENUM; - } - - public void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, - AccessorNamingUtils accessorNaming) { - init( method, messager, typeFactory, accessorNaming, false, null ); - } - - /** - * Initialize the Mapping. - * - * @param method the source method that the mapping belongs to - * @param messager the messager that can be used for outputting messages - * @param typeFactory the type factory - * @param accessorNaming the accessor naming utils - * @param isReverse whether the init is for a reverse mapping - * @param reverseSourceParameter the source parameter from the revers mapping - */ - private void init(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, - AccessorNamingUtils accessorNaming, boolean isReverse, - Parameter reverseSourceParameter) { - - if ( !method.isEnumMapping() ) { - sourceReference = new SourceReference.BuilderFromMapping() - .mapping( this ) - .method( method ) - .messager( messager ) - .typeFactory( typeFactory ) - .build(); - - targetReference = new TargetReference.BuilderFromTargetMapping() - .mapping( this ) - .isReverse( isReverse ) - .method( method ) - .messager( messager ) - .typeFactory( typeFactory ) - .accessorNaming( accessorNaming ) - .reverseSourceParameter( reverseSourceParameter ) - .build(); - } - } - - /** - * Initializes the mapping with a new source parameter. - * - * @param sourceParameter sets the source parameter that acts as a basis for this mapping - */ - public void init( Parameter sourceParameter ) { - if ( sourceReference != null ) { - SourceReference oldSourceReference = sourceReference; - sourceReference = new SourceReference.BuilderFromSourceReference() - .sourceParameter( sourceParameter ) - .sourceReference( oldSourceReference ) - .build(); - } - } + // immutable properties /** * Returns the complete source name of this mapping, either a qualified (e.g. {@code parameter1.foo}) or @@ -520,20 +496,38 @@ public AnnotationValue getDependsOnAnnotationValue() { return dependsOnAnnotationValue; } + public NullValueCheckStrategyPrism getNullValueCheckStrategy() { + return nullValueCheckStrategy; + } + + public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { + return nullValuePropertyMappingStrategy; + } + + public Set getDependsOn() { + return dependsOn; + } + + public InheritContext getInheritContext() { + return inheritContext; + } + + //// mutable properties + public SourceReference getSourceReference() { return sourceReference; } - public TargetReference getTargetReference() { - return targetReference; + public void setSourceReference(SourceReference sourceReference) { + this.sourceReference = sourceReference; } - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return nullValueCheckStrategy; + public TargetReference getTargetReference() { + return targetReference; } - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return nullValuePropertyMappingStrategy; + public void setTargetReference(TargetReference targetReference) { + this.targetReference = targetReference; } public Mapping popTargetReference() { @@ -556,20 +550,19 @@ public Mapping popSourceReference() { return null; } - public List getDependsOn() { - return dependsOn; + /** + * mapping can only be inversed if the source was not a constant nor an expression nor a nested property + * and the mapping is not a 'target-source-ignore' mapping + * + * @return true when the above applies + */ + public boolean canInverse() { + return constant == null && javaExpression == null && !( isIgnored && sourceName == null ); } - public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFactory typeFactory, - AccessorNamingUtils accessorNaming) { - - // mapping can only be reversed if the source was not a constant nor an expression nor a nested property - // and the mapping is not a 'target-source-ignore' mapping - if ( constant != null || javaExpression != null || ( isIgnored && sourceName == null ) ) { - return null; - } + public Mapping copyForInverseInheritance(SourceMethod method ) { - Mapping reverse = new Mapping( + return new Mapping( sourceName != null ? targetName : null, null, // constant null, // expression @@ -583,36 +576,21 @@ public Mapping reverse(SourceMethod method, FormattingMessager messager, TypeFac formattingParameters, selectionParameters, dependsOnAnnotationValue, - Collections.emptyList(), + Collections.emptySet(), nullValueCheckStrategy, - nullValuePropertyMappingStrategy + nullValuePropertyMappingStrategy, + new InheritContext( true, false, method ) ); - reverse.init( - method, - messager, - typeFactory, - accessorNaming, - true, - sourceReference != null ? sourceReference.getParameter() : null - ); - - // check if the reverse mapping has indeed a write accessor, otherwise the mapping cannot be reversed - if ( !reverse.targetReference.isValid() ) { - return null; - } - - return reverse; } /** - * Creates a copy of this mapping, which is adapted to the given method + * Creates a copy of this mapping * - * @param method the method to create the copy for * @return the copy */ - public Mapping copyForInheritanceTo(SourceMethod method) { - Mapping mapping = new Mapping( + public Mapping copyForForwardInheritance( SourceMethod method ) { + return new Mapping( sourceName, constant, javaExpression, @@ -628,17 +606,27 @@ public Mapping copyForInheritanceTo(SourceMethod method) { dependsOnAnnotationValue, dependsOn, nullValueCheckStrategy, - nullValuePropertyMappingStrategy + nullValuePropertyMappingStrategy, + new InheritContext( false, true, method ) ); - if ( sourceReference != null ) { - mapping.sourceReference = sourceReference.copyForInheritanceTo( method ); - } + } - // TODO... must something be done here? Andreas? - mapping.targetReference = targetReference; + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + Mapping mapping = (Mapping) o; + return targetName.equals( mapping.targetName ); + } - return mapping; + @Override + public int hashCode() { + return Objects.hash( targetName ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 3e6811af9e..81e93826a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -5,39 +5,34 @@ */ package org.mapstruct.ap.internal.model.source; -import static org.mapstruct.ap.internal.util.Collections.first; - -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; -import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.util.AccessorNamingUtils; -import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.model.source.Mapping.getMappingTargetNamesBy; + /** * Encapsulates all options specifiable on a mapping method * * @author Andreas Gudian */ public class MappingOptions { - private static final MappingOptions EMPTY = new MappingOptions( Collections.>emptyMap(), + private static final MappingOptions EMPTY = new MappingOptions( Collections.emptySet(), null, null, null, Collections.emptyList(), false ); - private Map> mappings; + private Set mappings; private IterableMapping iterableMapping; private MapMapping mapMapping; private BeanMapping beanMapping; @@ -45,7 +40,7 @@ public class MappingOptions { private boolean fullyInitialized; private final boolean restrictToDefinedMappings; - public MappingOptions(Map> mappings, IterableMapping iterableMapping, MapMapping mapMapping, + public MappingOptions(Set mappings, IterableMapping iterableMapping, MapMapping mapMapping, BeanMapping beanMapping, List valueMappings, boolean restrictToDefinedMappings ) { this.mappings = mappings; this.iterableMapping = iterableMapping; @@ -71,10 +66,8 @@ public static MappingOptions empty() { * @param restrictToDefinedMappings whether to restrict the mappings only to the defined mappings * @return MappingOptions with only regular mappings */ - public static MappingOptions forMappingsOnly(Map> mappings, - boolean restrictToDefinedMappings) { + public static MappingOptions forMappingsOnly(Set mappings, boolean restrictToDefinedMappings) { return forMappingsOnly( mappings, restrictToDefinedMappings, restrictToDefinedMappings ); - } /** @@ -85,7 +78,7 @@ public static MappingOptions forMappingsOnly(Map> mappings * @param forForgedMethods whether the mappings are for forged methods * @return MappingOptions with only regular mappings */ - public static MappingOptions forMappingsOnly(Map> mappings, + public static MappingOptions forMappingsOnly(Set mappings, boolean restrictToDefinedMappings, boolean forForgedMethods) { return new MappingOptions( mappings, @@ -102,7 +95,7 @@ public static MappingOptions forMappingsOnly(Map> mappings * @return the {@link Mapping}s configured for this method, keyed by target property name. Only for enum mapping * methods a target will be mapped by several sources. TODO. Remove the value list when 2.0 */ - public Map> getMappings() { + public Set getMappings() { return mappings; } @@ -112,46 +105,29 @@ public Map> getMappings() { * @return boolean, true if there are nested target references */ public boolean hasNestedTargetReferences() { - for ( List mappingList : mappings.values() ) { - for ( Mapping mapping : mappingList ) { - TargetReference targetReference = mapping.getTargetReference(); - if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { - return true; - } + + for ( Mapping mapping : mappings ) { + TargetReference targetReference = mapping.getTargetReference(); + if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { + return true; } + } return false; } /** - * * @return all dependencies to other properties the contained mappings are dependent on */ - public List collectNestedDependsOn() { + public Set collectNestedDependsOn() { - List nestedDependsOn = new ArrayList<>(); - for ( List mappingList : mappings.values() ) { - for ( Mapping mapping : mappingList ) { - nestedDependsOn.addAll( mapping.getDependsOn() ); - } + Set nestedDependsOn = new LinkedHashSet<>(); + for ( Mapping mapping : mappings ) { + nestedDependsOn.addAll( mapping.getDependsOn() ); } return nestedDependsOn; } - /** - * Initializes the underlying mappings with a new property. Specifically used in in combination with forged methods - * where the new parameter name needs to be established at a later moment. - * - * @param sourceParameter the new source parameter - */ - public void initWithParameter( Parameter sourceParameter ) { - for ( List mappingList : mappings.values() ) { - for ( Mapping mapping : mappingList ) { - mapping.init( sourceParameter ); - } - } - } - public IterableMapping getIterableMapping() { return iterableMapping; } @@ -168,10 +144,6 @@ public List getValueMappings() { return valueMappings; } - public void setMappings(Map> mappings) { - this.mappings = mappings; - } - public void setIterableMapping(IterableMapping iterableMapping) { this.iterableMapping = iterableMapping; } @@ -203,16 +175,12 @@ public void markAsFullyInitialized() { /** * Merges in all the mapping options configured, giving the already defined options precedence. * - * @param inherited the options to inherit, may be {@code null} + * @param templateMethod the template method with the options to inherit, may be {@code null} * @param isInverse if {@code true}, the specified options are from an inverse method * @param method the source method - * @param messager the messager - * @param typeFactory the type factory - * @param accessorNaming the accessor naming utils */ - public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, SourceMethod method, - FormattingMessager messager, TypeFactory typeFactory, - AccessorNamingUtils accessorNaming) { + public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse, SourceMethod method ) { + MappingOptions inherited = templateMethod.getMappingOptions(); if ( null != inherited ) { if ( getIterableMapping() == null ) { if ( inherited.getIterableMapping() != null ) { @@ -243,51 +211,38 @@ public void applyInheritedOptions(MappingOptions inherited, boolean isInverse, S } else { if ( inherited.getValueMappings() != null ) { - // iff there are also inherited mappings, we reverse and add them. + // iff there are also inherited mappings, we inverse and add them. for ( ValueMapping inheritedValueMapping : inherited.getValueMappings() ) { - ValueMapping valueMapping = isInverse ? inheritedValueMapping.reverse() : inheritedValueMapping; + ValueMapping valueMapping = isInverse ? inheritedValueMapping.inverse() : inheritedValueMapping; if ( valueMapping != null && !getValueMappings().contains( valueMapping ) ) { getValueMappings().add( valueMapping ); } } } - } - Map> newMappings = new HashMap<>(); - - for ( List lmappings : inherited.getMappings().values() ) { - for ( Mapping mapping : lmappings ) { - if ( isInverse ) { - mapping = mapping.reverse( method, messager, typeFactory, accessorNaming ); - } - - if ( mapping != null ) { - List mappingsOfProperty = newMappings.get( mapping.getTargetName() ); - if ( mappingsOfProperty == null ) { - mappingsOfProperty = new ArrayList<>(); - newMappings.put( mapping.getTargetName(), mappingsOfProperty ); - } - - mappingsOfProperty.add( mapping.copyForInheritanceTo( method ) ); + Set newMappings = new LinkedHashSet<>(); + for ( Mapping mapping : inherited.getMappings() ) { + if ( isInverse ) { + if ( mapping.canInverse() ) { + newMappings.add( mapping.copyForInverseInheritance( templateMethod ) ); } } + else { + newMappings.add( mapping.copyForForwardInheritance( templateMethod ) ); + } } - - // now add all of its own mappings - newMappings.putAll( getMappings() ); + // now add all (does not override duplicates and leaves original mappings) + mappings.addAll( newMappings ); // filter new mappings - filterNestedTargetIgnores( newMappings ); - - setMappings( newMappings ); + filterNestedTargetIgnores( mappings ); } } - public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, FormattingMessager messager, - TypeFactory typeFactory, AccessorNamingUtils accessorNaming) { + public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { CollectionMappingStrategyPrism cms = method.getMapperConfiguration().getCollectionMappingStrategy(); Type writeType = method.getResultType(); if ( !method.isUpdateMethod() ) { @@ -297,45 +252,34 @@ public void applyIgnoreAll(MappingOptions inherited, SourceMethod method, Format ); } Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); - List mappedPropertyNames = new ArrayList<>(); - for ( String targetMappingName : mappings.keySet() ) { - mappedPropertyNames.add( targetMappingName.split( "\\." )[0] ); - } + + + Set mappedPropertyNames = mappings.stream() + .map( m -> getPropertyEntries( m )[0] ) + .collect( Collectors.toSet() ); + for ( String targetPropertyName : writeAccessors.keySet() ) { if ( !mappedPropertyNames.contains( targetPropertyName ) ) { Mapping mapping = Mapping.forIgnore( targetPropertyName ); - mapping.init( method, messager, typeFactory, accessorNaming ); - mappings.put( targetPropertyName, Arrays.asList( mapping ) ); + mappings.add( mapping ); } } } - private void filterNestedTargetIgnores( Map> mappings) { + private void filterNestedTargetIgnores( Set mappings) { // collect all properties to ignore, and safe their target name ( == same name as first ref target property) - Set ignored = new HashSet<>(); - for ( Map.Entry> mappingEntry : mappings.entrySet() ) { - Mapping mapping = first( mappingEntry.getValue() ); // list only used for deprecated enums mapping - if ( mapping.isIgnored() && mapping.getTargetReference().isValid() ) { - ignored.add( mapping.getTargetName() ); - } - } - - // collect all entries to remove (avoid concurrent modification) - Set toBeRemoved = new HashSet<>(); - for ( Map.Entry> mappingEntry : mappings.entrySet() ) { - Mapping mapping = first( mappingEntry.getValue() ); // list only used for deprecated enums mapping - TargetReference targetReference = mapping.getTargetReference(); - if ( targetReference.isValid() - && targetReference.getPropertyEntries().size() > 1 - && ignored.contains( first( targetReference.getPropertyEntries() ).getName() ) ) { - toBeRemoved.add( mappingEntry.getKey() ); - } - } + Set ignored = getMappingTargetNamesBy( Mapping::isIgnored, mappings ); + mappings.removeIf( m -> isToBeIgnored( ignored, m ) ); + } - // finall remove all duplicates - mappings.keySet().removeAll( toBeRemoved ); + private boolean isToBeIgnored(Set ignored, Mapping mapping) { + String[] propertyEntries = getPropertyEntries( mapping ); + return propertyEntries.length > 1 && ignored.contains( propertyEntries[ 0 ] ); + } + private String[] getPropertyEntries( Mapping mapping ) { + return mapping.getTargetName().split( "\\." ); } public boolean isRestrictToDefinedMappings() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 20bec62bf9..cade509b15 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -348,7 +348,7 @@ public Boolean visitWildcard(WildcardType t, TypeMirror p) { switch ( superBound.getKind() ) { case DECLARED: // for example method: String method(? super String) - // to check super type, we can simply reverse the argument, but that would initially yield + // to check super type, we can simply inverse the argument, but that would initially yield // a result: exceptionTypes; private final MapperConfiguration config; @@ -67,7 +64,6 @@ public class SourceMethod implements Method { private List applicablePrototypeMethods; private List applicableReversePrototypeMethods; - private Boolean isEnumMapping; private Boolean isValueMapping; private Boolean isIterableMapping; private Boolean isMapMapping; @@ -83,14 +79,12 @@ public static class Builder { private Type returnType = null; private BuilderType builderType = null; private List exceptionTypes; - private Map> mappings; + private Set mappings; private IterableMapping iterableMapping = null; private MapMapping mapMapping = null; private BeanMapping beanMapping = null; private Types typeUtils; private TypeFactory typeFactory = null; - private AccessorNamingUtils accessorNaming = null; - private FormattingMessager messager = null; private MapperConfiguration mapperConfig = null; private List prototypeMethods = Collections.emptyList(); private List valueMappings; @@ -121,7 +115,7 @@ public Builder setExceptionTypes(List exceptionTypes) { return this; } - public Builder setMappings(Map> mappings) { + public Builder setMappings(Set mappings) { this.mappings = mappings; return this; } @@ -156,16 +150,6 @@ public Builder setTypeFactory(TypeFactory typeFactory) { return this; } - public Builder setAccessorNaming(AccessorNamingUtils accessorNaming) { - this.accessorNaming = accessorNaming; - return this; - } - - public Builder setMessager(FormattingMessager messager) { - this.messager = messager; - return this; - } - public Builder setMapperConfiguration(MapperConfiguration mapperConfig) { this.mapperConfig = mapperConfig; return this; @@ -188,19 +172,14 @@ public Builder setContextProvidedMethods(ParameterProvidedMethods contextProvide public SourceMethod build() { + if ( mappings == null ) { + mappings = Collections.emptySet(); + } + MappingOptions mappingOptions = new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings, false ); - SourceMethod sourceMethod = new SourceMethod( this, mappingOptions ); - - if ( mappings != null ) { - for ( Map.Entry> entry : mappings.entrySet() ) { - for ( Mapping mapping : entry.getValue() ) { - mapping.init( sourceMethod, messager, typeFactory, accessorNaming ); - } - } - } - return sourceMethod; + return new SourceMethod( this, mappingOptions ); } } @@ -209,7 +188,6 @@ private SourceMethod(Builder builder, MappingOptions mappingOptions) { this.executable = builder.executable; this.parameters = builder.parameters; this.returnType = builder.returnType; - this.builderType = builder.builderType; this.exceptionTypes = builder.exceptionTypes; this.accessibility = Accessibility.fromModifiers( builder.executable.getModifiers() ); @@ -304,12 +282,7 @@ public Accessibility getAccessibility() { return accessibility; } - public Mapping getSingleMappingByTargetPropertyName(String targetPropertyName) { - List all = mappingOptions.getMappings().get( targetPropertyName ); - return all != null ? first( all ) : null; - } - - public boolean reverses(SourceMethod method) { + public boolean inverses(SourceMethod method) { return method.getDeclaringMapper() == null && method.isAbstract() && getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 @@ -328,7 +301,7 @@ public boolean canInheritFrom(SourceMethod method) { && method.isAbstract() && isMapMapping() == method.isMapMapping() && isIterableMapping() == method.isIterableMapping() - && isEnumMapping() == method.isEnumMapping() + && isEnumMapping( this ) == isEnumMapping( method ) && getResultType().isAssignableTo( method.getResultType() ) && allParametersAreAssignable( getSourceParameters(), method.getSourceParameters() ); } @@ -376,11 +349,14 @@ && first( getSourceParameters() ).getType().isMapType() return isMapMapping; } - public boolean isEnumMapping() { - if ( isEnumMapping == null ) { - isEnumMapping = MappingMethodUtils.isEnumMapping( this ); - } - return isEnumMapping; + /** + * Enum Mapping was realized with @Mapping in stead of @ValueMapping. @Mapping is no longer + * supported. + * + * @return true when @Mapping is used in stead of @ValueMapping + */ + public boolean isRemovedEnumMapping() { + return MappingMethodUtils.isEnumMapping( this ); } /** @@ -392,7 +368,7 @@ public boolean isEnumMapping() { public boolean isValueMapping() { if ( isValueMapping == null ) { - isValueMapping = isEnumMapping() && mappingOptions.getMappings().isEmpty(); + isValueMapping = isEnumMapping( this ) && mappingOptions.getMappings().isEmpty(); } return isValueMapping; } @@ -415,6 +391,7 @@ public String toString() { return sb.toString(); } + // TODO remove? /** * Returns the {@link Mapping}s for the given source property. * @@ -424,22 +401,20 @@ public String toString() { public List getMappingBySourcePropertyName(String sourcePropertyName) { List mappingsOfSourceProperty = new ArrayList<>(); - for ( List mappingOfProperty : mappingOptions.getMappings().values() ) { - for ( Mapping mapping : mappingOfProperty ) { + for ( Mapping mapping : mappingOptions.getMappings() ) { - if ( isEnumMapping() ) { - if ( mapping.getSourceName().equals( sourcePropertyName ) ) { - mappingsOfSourceProperty.add( mapping ); - } + if ( isEnumMapping( this ) ) { + if ( mapping.getSourceName().equals( sourcePropertyName ) ) { + mappingsOfSourceProperty.add( mapping ); } - else { - List sourceEntries = mapping.getSourceReference().getPropertyEntries(); + } + else { + List sourceEntries = mapping.getSourceReference().getPropertyEntries(); - // there can only be a mapping if there's only one entry for a source property, so: param.property. - // There can be no mapping if there are more entries. So: param.property.property2 - if ( sourceEntries.size() == 1 && sourcePropertyName.equals( first( sourceEntries ).getName() ) ) { - mappingsOfSourceProperty.add( mapping ); - } + // there can only be a mapping if there's only one entry for a source property, so: param.property. + // There can be no mapping if there are more entries. So: param.property.property2 + if ( sourceEntries.size() == 1 && sourcePropertyName.equals( first( sourceEntries ).getName() ) ) { + mappingsOfSourceProperty.add( mapping ); } } } @@ -447,16 +422,6 @@ public List getMappingBySourcePropertyName(String sourcePropertyName) { return mappingsOfSourceProperty; } - public Parameter getSourceParameter(String sourceParameterName) { - for ( Parameter parameter : getSourceParameters() ) { - if ( parameter.getName().equals( sourceParameterName ) ) { - return parameter; - } - } - - return null; - } - public List getApplicablePrototypeMethods() { if ( applicablePrototypeMethods == null ) { applicablePrototypeMethods = new ArrayList<>(); @@ -476,7 +441,7 @@ public List getApplicableReversePrototypeMethods() { applicableReversePrototypeMethods = new ArrayList<>(); for ( SourceMethod prototype : prototypeMethods ) { - if ( reverses( prototype ) ) { + if ( inverses( prototype ) ) { applicableReversePrototypeMethods.add( prototype ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index cd76dfff26..4bdcf27f90 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -13,6 +13,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; @@ -59,7 +60,7 @@ public class SourceReference { public static class BuilderFromMapping { private Mapping mapping; - private SourceMethod method; + private Method method; private FormattingMessager messager; private TypeFactory typeFactory; @@ -73,7 +74,7 @@ public BuilderFromMapping mapping(Mapping mapping) { return this; } - public BuilderFromMapping method(SourceMethod method) { + public BuilderFromMapping method(Method method) { this.method = method; return this; } @@ -141,7 +142,7 @@ private SourceReference buildFromSingleSourceParameters(String[] segments, Param if ( !foundEntryMatch ) { //Lets see if the expression contains the parameterName, so parameterName.propName1.propName2 - if ( parameter.getName().equals( segments[0] ) ) { + if ( getSourceParameterFromMethodOrTemplate( segments[0] ) != null ) { propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); foundEntryMatch = ( entries.size() == propertyNames.length ); @@ -205,7 +206,7 @@ private Parameter fetchMatchingParameterFromFirstSegment(String[] segments ) { Parameter parameter = null; if ( segments.length > 0 ) { String parameterName = segments[0]; - parameter = method.getSourceParameter( parameterName ); + parameter = getSourceParameterFromMethodOrTemplate( parameterName ); if ( parameter == null ) { reportMappingError( Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, @@ -226,6 +227,26 @@ public String apply(Parameter parameter) { return parameter; } + private Parameter getSourceParameterFromMethodOrTemplate(String parameterName ) { + + Parameter result = null; + if ( mapping.getInheritContext() != null && mapping.getInheritContext().isForwarded() ) { + Method templateMethod = mapping.getInheritContext().getInheritedFromMethod(); + Parameter parameter = Parameter.getSourceParameter( templateMethod.getParameters(), parameterName ); + if ( parameter != null ) { + result = method.getSourceParameters() + .stream() + .filter( p -> p.getType().isAssignableTo( parameter.getType() ) ) + .collect( Collectors.reducing( (a, b) -> null ) ) + .orElse( null ); + } + } + else { + result = Parameter.getSourceParameter( method.getParameters(), parameterName ); + } + return result; + } + private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, List entries) { if ( parameter != null ) { reportMappingError( Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER, parameter.getName(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 7c30144371..07657406c5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -9,7 +9,6 @@ import java.util.Arrays; import java.util.List; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.DeclaredType; @@ -19,13 +18,14 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * This class describes the target side of a property mapping. *

      @@ -61,28 +61,10 @@ public class TargetReference { public static class BuilderFromTargetMapping { private Mapping mapping; - private SourceMethod method; + private Method method; private FormattingMessager messager; private TypeFactory typeFactory; - private AccessorNamingUtils accessorNaming; - private boolean isReverse; - /** - * Needed when we are building from reverse mapping. It is needed, so we can remove the first level if it is - * needed. - * E.g. If we have a mapping like: - * - * {@literal @}Mapping( target = "letterSignature", source = "dto.signature" ) - * - * - * When it is reversed it will look like: - * - * {@literal @}Mapping( target = "dto.signature", source = "letterSignature" ) - * - * - * The {@code dto} needs to be considered as a possibility for a target name only if a Target Reference for - * a reverse is created. - */ - private Parameter reverseSourceParameter; + /** * During {@link #getTargetEntries(Type, String[])} an error can occur. However, we are invoking * that multiple times because the first entry can also be the name of the parameter. Therefore we keep @@ -100,7 +82,7 @@ public BuilderFromTargetMapping mapping(Mapping mapping) { return this; } - public BuilderFromTargetMapping method(SourceMethod method) { + public BuilderFromTargetMapping method(Method method) { this.method = method; return this; } @@ -110,25 +92,11 @@ public BuilderFromTargetMapping typeFactory(TypeFactory typeFactory) { return this; } - public BuilderFromTargetMapping accessorNaming(AccessorNamingUtils accessorNaming) { - this.accessorNaming = accessorNaming; - return this; - } - - public BuilderFromTargetMapping isReverse(boolean isReverse) { - this.isReverse = isReverse; - return this; - } - - public BuilderFromTargetMapping reverseSourceParameter(Parameter reverseSourceParameter) { - this.reverseSourceParameter = reverseSourceParameter; - return this; - } - public TargetReference build() { - String targetName = mapping.getTargetName(); + boolean isInverse = mapping.getInheritContext() != null ? mapping.getInheritContext().isReversed() : false; + String targetName = mapping.getTargetName(); if ( targetName == null ) { return null; } @@ -152,20 +120,20 @@ public TargetReference build() { // there can be 4 situations // 1. Return type - // 2. A reverse target reference where the source parameter name is used in the original mapping + // 2. An inverse target reference where the source parameter name is used in the original mapping // 3. @MappingTarget, with // 4. or without parameter name. String[] targetPropertyNames = segments; List entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); if ( !foundEntryMatch && segments.length > 1 - && matchesSourceOrTargetParameter( segments[0], parameter, reverseSourceParameter, isReverse ) ) { + && matchesSourceOrTargetParameter( segments[0], parameter, isInverse ) ) { targetPropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); } - if ( !foundEntryMatch && errorMessage != null && !isReverse ) { + if ( !foundEntryMatch && errorMessage != null && !isInverse ) { // This is called only for reporting errors errorMessage.report( ); } @@ -330,23 +298,50 @@ private static boolean isWriteAccessorNotValidWhenLast(Accessor writeAccessor, A /** * Validates that the {@code segment} is the same as the {@code targetParameter} or the {@code - * reverseSourceParameter} names + * inverseSourceParameter} names * * @param segment that needs to be checked * @param targetParameter the target parameter if it exists - * @param reverseSourceParameter the reverse source parameter if it exists - * @param isReverse whether a reverse {@link TargetReference} is being built + + * @param isInverse whether a inverse {@link TargetReference} is being built * * @return {@code true} if the segment matches the name of the {@code targetParameter} or the name of the - * {@code reverseSourceParameter} when this is a reverse {@link TargetReference} is being built, {@code + * {@code inverseSourceParameter} when this is a inverse {@link TargetReference} is being built, {@code * false} otherwise */ - private static boolean matchesSourceOrTargetParameter(String segment, Parameter targetParameter, - Parameter reverseSourceParameter, boolean isReverse) { - boolean matchesTargetParameter = - targetParameter != null && targetParameter.getName().equals( segment ); - return matchesTargetParameter - || isReverse && reverseSourceParameter != null && reverseSourceParameter.getName().equals( segment ); + private boolean matchesSourceOrTargetParameter(String segment, Parameter targetParameter, boolean isInverse) { + boolean matchesTargetParameter = targetParameter != null && targetParameter.getName().equals( segment ); + return matchesTargetParameter || matchesSourceOnInverseSourceParameter( segment, isInverse ); + } + + /** + * Needed when we are building from inverse mapping. It is needed, so we can remove the first level if it is + * needed. + * E.g. If we have a mapping like: + * + * {@literal @}Mapping( target = "letterSignature", source = "dto.signature" ) + * + * When it is inversed it will look like: + * + * {@literal @}Mapping( target = "dto.signature", source = "letterSignature" ) + * + * The {@code dto} needs to be considered as a possibility for a target name only if a Target Reference for + * a inverse is created. + * + * @param segment that needs to be checked* + * @param isInverse whether a inverse {@link TargetReference} is being built + * + * @return on match when inverse and segment matches the one and only source parameter + */ + private boolean matchesSourceOnInverseSourceParameter( String segment, boolean isInverse ) { + boolean result = false; + if ( isInverse ) { + Method templateMethod = mapping.getInheritContext().getInheritedFromMethod(); + // there is only source parameter by definition when applying @InheritInverseConfiguration + Parameter inverseSourceParameter = first( templateMethod.getSourceParameters() ); + result = inverseSourceParameter.getName().equals( segment ); + } + return result; } } @@ -398,10 +393,10 @@ public TargetReference pop() { private abstract static class MappingErrorMessage { private final Mapping mapping; - private final SourceMethod method; + private final Method method; private final FormattingMessager messager; - private MappingErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager) { + private MappingErrorMessage(Mapping mapping, Method method, FormattingMessager messager) { this.mapping = mapping; this.method = method; this.messager = messager; @@ -423,7 +418,7 @@ protected void printErrorMessage(Message message, Object... args) { private static class NoWriteAccessorErrorMessage extends MappingErrorMessage { - private NoWriteAccessorErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager) { + private NoWriteAccessorErrorMessage(Mapping mapping, Method method, FormattingMessager messager) { super( mapping, method, messager ); } @@ -439,7 +434,7 @@ private static class NoPropertyErrorMessage extends MappingErrorMessage { private final int index; private final Type nextType; - private NoPropertyErrorMessage(Mapping mapping, SourceMethod method, FormattingMessager messager, + private NoPropertyErrorMessage(Mapping mapping, Method method, FormattingMessager messager, String[] entryNames, int index, Type nextType) { super( mapping, method, messager ); this.entryNames = entryNames; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java index 7ad385be66..b86583496d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java @@ -109,7 +109,7 @@ public AnnotationValue getTargetAnnotationValue() { return targetAnnotationValue; } - public ValueMapping reverse() { + public ValueMapping inverse() { ValueMapping result; if ( !MappingConstantsPrism.ANY_REMAINING.equals( source ) || !MappingConstantsPrism.ANY_UNMAPPED.equals( source ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 3ee6adabdb..783e90dff4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -27,7 +27,6 @@ import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.DefaultMapperReference; import org.mapstruct.ap.internal.model.DelegatingMethod; -import org.mapstruct.ap.internal.model.EnumMappingMethod; import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.IterableMappingMethod; import org.mapstruct.ap.internal.model.MapMappingMethod; @@ -340,21 +339,11 @@ else if ( method.isValueMapping() ) { .build(); mappingMethods.add( valueMappingMethod ); } - else if ( method.isEnumMapping() ) { - + else if ( method.isRemovedEnumMapping() ) { messager.printMessage( method.getExecutable(), - Message.ENUMMAPPING_DEPRECATED ); - - EnumMappingMethod.Builder builder = new EnumMappingMethod.Builder(); - MappingMethod enumMappingMethod = builder - .mappingContext( mappingContext ) - .sourceMethod( method ) - .build(); - - if ( enumMappingMethod != null ) { - mappingMethods.add( enumMappingMethod ); - } + Message.ENUMMAPPING_REMOVED + ); } else if ( method.isStreamMapping() ) { this.messager.note( 1, Message.STREAMMAPPING_CREATE_NOTE, method ); @@ -438,41 +427,27 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp MappingOptions mappingOptions = method.getMappingOptions(); List applicableReversePrototypeMethods = method.getApplicableReversePrototypeMethods(); - MappingOptions inverseMappingOptions = - getInverseMappingOptions( join( availableMethods, applicableReversePrototypeMethods ), + SourceMethod inverseTemplateMethod = + getInverseTemplateMethod( join( availableMethods, applicableReversePrototypeMethods ), method, initializingMethods, mapperConfig ); List applicablePrototypeMethods = method.getApplicablePrototypeMethods(); - MappingOptions forwardMappingOptions = - getTemplateMappingOptions( + SourceMethod forwardTemplateMethod = + getForwardTemplateMethod( join( availableMethods, applicablePrototypeMethods ), method, initializingMethods, mapperConfig ); // apply defined (@InheritConfiguration, @InheritInverseConfiguration) mappings - if ( forwardMappingOptions != null ) { - mappingOptions.applyInheritedOptions( - forwardMappingOptions, - false, - method, - messager, - typeFactory, - accessorNaming - ); + if ( forwardTemplateMethod != null ) { + mappingOptions.applyInheritedOptions( forwardTemplateMethod, false, method ); } - if ( inverseMappingOptions != null ) { - mappingOptions.applyInheritedOptions( - inverseMappingOptions, - true, - method, - messager, - typeFactory, - accessorNaming - ); + if ( inverseTemplateMethod != null ) { + mappingOptions.applyInheritedOptions( inverseTemplateMethod, true, method ); } // apply auto inherited options @@ -480,15 +455,12 @@ private void mergeInheritedOptions(SourceMethod method, MapperConfiguration mapp if ( inheritanceStrategy.isAutoInherit() ) { // but.. there should not be an @InheritedConfiguration - if ( forwardMappingOptions == null && inheritanceStrategy.isApplyForward() ) { + if ( forwardTemplateMethod == null && inheritanceStrategy.isApplyForward() ) { if ( applicablePrototypeMethods.size() == 1 ) { mappingOptions.applyInheritedOptions( - first( applicablePrototypeMethods ).getMappingOptions(), + first( applicablePrototypeMethods ), false, - method, - messager, - typeFactory, - accessorNaming + method ); } else if ( applicablePrototypeMethods.size() > 1 ) { @@ -500,15 +472,12 @@ else if ( applicablePrototypeMethods.size() > 1 ) { } // or no @InheritInverseConfiguration - if ( inverseMappingOptions == null && inheritanceStrategy.isApplyReverse() ) { + if ( inverseTemplateMethod == null && inheritanceStrategy.isApplyReverse() ) { if ( applicableReversePrototypeMethods.size() == 1 ) { mappingOptions.applyInheritedOptions( - first( applicableReversePrototypeMethods ).getMappingOptions(), + first( applicableReversePrototypeMethods ), true, - method, - messager, - typeFactory, - accessorNaming + method ); } else if ( applicableReversePrototypeMethods.size() > 1 ) { @@ -522,13 +491,7 @@ else if ( applicableReversePrototypeMethods.size() > 1 ) { // @BeanMapping( ignoreByDefault = true ) if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isignoreByDefault() ) { - mappingOptions.applyIgnoreAll( - mappingOptions, - method, - messager, - typeFactory, - accessorNaming - ); + mappingOptions.applyIgnoreAll( method, typeFactory ); } mappingOptions.markAsFullyInitialized(); @@ -547,25 +510,25 @@ private void reportErrorIfNoImplementationTypeIsRegisteredForInterfaceReturnType * {@code @InheritInverseConfiguration} and exactly one such configuring method can unambiguously be selected (as * per the source/target type and optionally the name given via {@code @InheritInverseConfiguration}). */ - private MappingOptions getInverseMappingOptions(List rawMethods, SourceMethod method, - List initializingMethods, - MapperConfiguration mapperConfig) { + private SourceMethod getInverseTemplateMethod(List rawMethods, SourceMethod method, + List initializingMethods, + MapperConfiguration mapperConfig) { SourceMethod resultMethod = null; - InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( + InheritInverseConfigurationPrism inversePrism = InheritInverseConfigurationPrism.getInstanceOn( method.getExecutable() ); - if ( reversePrism != null ) { + if ( inversePrism != null ) { - // method is configured as being reverse method, collect candidates + // method is configured as being inverse method, collect candidates List candidates = new ArrayList<>(); for ( SourceMethod oneMethod : rawMethods ) { - if ( method.reverses( oneMethod ) ) { + if ( method.inverses( oneMethod ) ) { candidates.add( oneMethod ); } } - String name = reversePrism.name(); + String name = inversePrism.name(); if ( candidates.size() == 1 ) { // no ambiguity: if no configuredBy is specified, or configuredBy specified and match if ( name.isEmpty() ) { @@ -575,7 +538,7 @@ else if ( candidates.get( 0 ).getName().equals( name ) ) { resultMethod = candidates.get( 0 ); } else { - reportErrorWhenNonMatchingName( candidates.get( 0 ), method, reversePrism ); + reportErrorWhenNonMatchingName( candidates.get( 0 ), method, inversePrism ); } } else if ( candidates.size() > 1 ) { @@ -592,10 +555,10 @@ else if ( candidates.size() > 1 ) { resultMethod = nameFilteredcandidates.get( 0 ); } else if ( nameFilteredcandidates.size() > 1 ) { - reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, reversePrism ); + reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inversePrism ); } else { - reportErrorWhenAmbigousReverseMapping( candidates, method, reversePrism ); + reportErrorWhenAmbigousReverseMapping( candidates, method, inversePrism ); } } } @@ -603,7 +566,7 @@ else if ( nameFilteredcandidates.size() > 1 ) { return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods ); } - private MappingOptions extractInitializedOptions(SourceMethod resultMethod, + private SourceMethod extractInitializedOptions(SourceMethod resultMethod, List rawMethods, MapperConfiguration mapperConfig, List initializingMethods) { @@ -612,7 +575,7 @@ private MappingOptions extractInitializedOptions(SourceMethod resultMethod, mergeInheritedOptions( resultMethod, mapperConfig, rawMethods, initializingMethods ); } - return resultMethod.getMappingOptions(); + return resultMethod; } return null; @@ -624,9 +587,9 @@ private MappingOptions extractInitializedOptions(SourceMethod resultMethod, * source/target type and optionally the name given via {@code @InheritConfiguration}). The method cannot be marked * forward mapping itself (hence 'other'). And neither can it contain an {@code @InheritReverseConfiguration} */ - private MappingOptions getTemplateMappingOptions(List rawMethods, SourceMethod method, - List initializingMethods, - MapperConfiguration mapperConfig) { + private SourceMethod getForwardTemplateMethod(List rawMethods, SourceMethod method, + List initializingMethods, + MapperConfiguration mapperConfig) { SourceMethod resultMethod = null; InheritConfigurationPrism forwardPrism = InheritConfigurationPrism.getInstanceOn( method.getExecutable() @@ -682,17 +645,17 @@ else if ( nameFilteredcandidates.size() > 1 ) { } private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, - InheritInverseConfigurationPrism reversePrism) { + InheritInverseConfigurationPrism inversePrism) { List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { candidateNames.add( candidate.getName() ); } - String name = reversePrism.name(); + String name = inversePrism.name(); if ( name.isEmpty() ) { messager.printMessage( method.getExecutable(), - reversePrism.mirror, + inversePrism.mirror, Message.INHERITINVERSECONFIGURATION_DUPLICATES, Strings.join( candidateNames, "(), " ) @@ -700,7 +663,7 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } else { messager.printMessage( method.getExecutable(), - reversePrism.mirror, + inversePrism.mirror, Message.INHERITINVERSECONFIGURATION_INVALID_NAME, Strings.join( candidateNames, "(), " ), name @@ -710,24 +673,24 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } private void reportErrorWhenSeveralNamesMatch(List candidates, SourceMethod method, - InheritInverseConfigurationPrism reversePrism) { + InheritInverseConfigurationPrism inversePrism) { messager.printMessage( method.getExecutable(), - reversePrism.mirror, + inversePrism.mirror, Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES, - reversePrism.name(), + inversePrism.name(), Strings.join( candidates, ", " ) ); } private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, - InheritInverseConfigurationPrism reversePrism) { + InheritInverseConfigurationPrism inversePrism) { messager.printMessage( method.getExecutable(), - reversePrism.mirror, + inversePrism.mirror, Message.INHERITINVERSECONFIGURATION_NO_NAME_MATCH, - reversePrism.name(), + inversePrism.name(), onlyCandidate.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index b796945f80..b8fabeab07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -7,10 +7,9 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; @@ -258,9 +257,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager, typeUtils ) ) .setValueMappings( getValueMappings( method ) ) .setTypeUtils( typeUtils ) - .setMessager( messager ) .setTypeFactory( typeFactory ) - .setAccessorNaming( accessorNaming ) .setMapperConfiguration( mapperConfig ) .setPrototypeMethods( prototypeMethods ) .setContextProvidedMethods( contextProvidedMethods ) @@ -318,7 +315,6 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType .setExceptionTypes( exceptionTypes ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) - .setAccessorNaming( accessorNaming ) .build(); } @@ -502,24 +498,18 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List> getMappings(ExecutableElement method) { - Map> mappings = new HashMap<>(); + private Set getMappings(ExecutableElement method) { + Set mappings = new LinkedHashSet<>( ); MappingPrism mappingAnnotation = MappingPrism.getInstanceOn( method ); MappingsPrism mappingsAnnotation = MappingsPrism.getInstanceOn( method ); if ( mappingAnnotation != null ) { - if ( !mappings.containsKey( mappingAnnotation.target() ) ) { - mappings.put( mappingAnnotation.target(), new ArrayList<>() ); - } - Mapping mapping = Mapping.fromMappingPrism( mappingAnnotation, method, messager, typeUtils ); - if ( mapping != null ) { - mappings.get( mappingAnnotation.target() ).add( mapping ); - } + mappings.add( Mapping.fromMappingPrism( mappingAnnotation, method, messager, typeUtils ) ); } if ( mappingsAnnotation != null ) { - mappings.putAll( Mapping.fromMappingsPrism( mappingsAnnotation, method, messager, typeUtils ) ); + mappings.addAll( Mapping.fromMappingsPrism( mappingsAnnotation, method, messager, typeUtils ) ); } return mappings; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 821e31db42..4ecf757d41 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -96,7 +96,7 @@ public enum Message { ENUMMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ), ENUMMAPPING_UNDEFINED_TARGET( "A target constant must be specified for mappings of an enum mapping method." ), ENUMMAPPING_UNMAPPED_SOURCES( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: %s." ), - ENUMMAPPING_DEPRECATED( "Mapping of Enums via @Mapping is going to be removed in future versions of MapStruct. Please use @ValueMapping instead!", Diagnostic.Kind.WARNING ), + ENUMMAPPING_REMOVED( "Mapping of Enums via @Mapping is removed. Please use @ValueMapping instead!" ), LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java index 80910e55aa..32de67728e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java @@ -30,9 +30,9 @@ public class Issue1180Test { @Test @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = SharedConfig.class, + @Diagnostic(type = ErroneousIssue1180Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 20, + line = 18, messageRegExp = "No property named \"sourceProperty\\.nonExistant\" exists.*") }) public void shouldCompileButNotGiveNullPointer() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java deleted file mode 100644 index 552fad686e..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/EnumMappingTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -import static org.assertj.core.api.Assertions.assertThat; - -import javax.tools.Diagnostic.Kind; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.testutil.IssueKey; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; -import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; -import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; - -/** - * Test for the generation and invocation of enum mapping methods. - * - * @author Gunnar Morling - */ -@IssueKey("128") -@WithClasses({ OrderEntity.class, OrderType.class, OrderDto.class, ExternalOrderType.class }) -@RunWith(AnnotationProcessorTestRunner.class) -public class EnumMappingTest { - - @Test - @WithClasses( OrderMapper.class ) - @ExpectedCompilationOutcome( - value = CompilationResult.SUCCEEDED, - diagnostics = { - @Diagnostic(type = OrderMapper.class, - kind = Kind.WARNING, - line = 28, - messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " - + "MapStruct\\. Please use @ValueMapping instead!") - } - ) - public void shouldGenerateEnumMappingMethod() { - ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.B2B ); - assertThat( target ).isEqualTo( ExternalOrderType.B2B ); - - target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.RETAIL ); - assertThat( target ).isEqualTo( ExternalOrderType.RETAIL ); - } - - @Test - @WithClasses(OrderMapper.class) - @ExpectedCompilationOutcome( - value = CompilationResult.SUCCEEDED, - diagnostics = { - @Diagnostic(type = OrderMapper.class, - kind = Kind.WARNING, - line = 28, - messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " - + "MapStruct\\. Please use @ValueMapping instead!") - } - ) - public void shouldConsiderConstantMappings() { - ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.EXTRA ); - assertThat( target ).isEqualTo( ExternalOrderType.SPECIAL ); - - target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.STANDARD ); - assertThat( target ).isEqualTo( ExternalOrderType.DEFAULT ); - - target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.NORMAL ); - assertThat( target ).isEqualTo( ExternalOrderType.DEFAULT ); - } - - @Test - @WithClasses( OrderMapper.class ) - @ExpectedCompilationOutcome( - value = CompilationResult.SUCCEEDED, - diagnostics = { - @Diagnostic(type = OrderMapper.class, - kind = Kind.WARNING, - line = 28, - messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " - + "MapStruct\\. Please use @ValueMapping instead!") - } - ) - public void shouldInvokeEnumMappingMethodForPropertyMapping() { - OrderEntity order = new OrderEntity(); - order.setOrderType( OrderType.EXTRA ); - - OrderDto orderDto = OrderMapper.INSTANCE.orderEntityToDto( order ); - assertThat( orderDto ).isNotNull(); - assertThat( orderDto.getOrderType() ).isEqualTo( ExternalOrderType.SPECIAL ); - } - - @Test - @WithClasses( ErroneousOrderMapperMappingSameConstantTwice.class ) - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - - @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, - kind = Kind.ERROR, - line = 29, - messageRegExp = "One enum constant must not be mapped to more than one target constant, but " + - "constant EXTRA is mapped to SPECIAL, DEFAULT\\."), - @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, - kind = Kind.WARNING, - line = 29, - messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " - + "MapStruct\\. Please use @ValueMapping instead!") - } - ) - public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { - } - - @Test - @WithClasses(ErroneousOrderMapperUsingUnknownEnumConstants.class) - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, - kind = Kind.WARNING, - line = 27, - messageRegExp = "Mapping of Enums via @Mapping is going to be removed in future versions of " - + "MapStruct\\. Please use @ValueMapping instead!"), - @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, - kind = Kind.ERROR, - line = 24, - messageRegExp = "Constant FOO doesn't exist in enum type org.mapstruct.ap.test.enums.OrderType\\."), - @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, - kind = Kind.ERROR, - line = 25, - messageRegExp = "Constant BAR doesn't exist in enum type org.mapstruct.ap.test.enums." + - "ExternalOrderType\\.") - } - ) - public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { - } - - @Test - @WithClasses(ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class) - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class, - kind = Kind.ERROR, - line = 21, - messageRegExp = "The following constants from the source enum have no corresponding constant in the " + - "target enum and must be be mapped via adding additional mappings: EXTRA, STANDARD, NORMAL") - } - ) - public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeIsNotMapped() { - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java deleted file mode 100644 index d63ca71fae..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperMappingSameConstantTwice.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -/** - * @author Gunnar Morling - */ -@Mapper -public interface ErroneousOrderMapperMappingSameConstantTwice { - - ErroneousOrderMapperMappingSameConstantTwice INSTANCE = Mappers.getMapper( - ErroneousOrderMapperMappingSameConstantTwice.class - ); - - @Mappings({ - @Mapping(source = "EXTRA", target = "SPECIAL"), - @Mapping(source = "EXTRA", target = "DEFAULT"), - @Mapping(source = "STANDARD", target = "DEFAULT"), - @Mapping(source = "NORMAL", target = "DEFAULT") - }) - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java deleted file mode 100644 index d086e91819..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -import org.mapstruct.Mapper; -import org.mapstruct.factory.Mappers; - -/** - * @author Gunnar Morling - */ -@Mapper -public interface ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType { - - ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType INSTANCE = Mappers.getMapper( - ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class - ); - - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java deleted file mode 100644 index 79747b2ae9..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ErroneousOrderMapperUsingUnknownEnumConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -/** - * @author Gunnar Morling - */ -@Mapper -public interface ErroneousOrderMapperUsingUnknownEnumConstants { - - ErroneousOrderMapperUsingUnknownEnumConstants INSTANCE = Mappers.getMapper( - ErroneousOrderMapperUsingUnknownEnumConstants.class - ); - - @Mappings({ - @Mapping(source = "FOO", target = "SPECIAL"), - @Mapping(source = "EXTRA", target = "BAR") - }) - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java deleted file mode 100644 index 827b668354..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/ExternalOrderType.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -/** - * @author Gunnar Morling - */ -public enum ExternalOrderType { - - RETAIL, B2B, SPECIAL, DEFAULT -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java deleted file mode 100644 index e9ee6429d8..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderDto.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -/** - * @author Gunnar Morling - */ -public class OrderDto { - - private ExternalOrderType orderType; - - public ExternalOrderType getOrderType() { - return orderType; - } - - public void setOrderType(ExternalOrderType orderType) { - this.orderType = orderType; - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java deleted file mode 100644 index 3d1a6b1dba..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -/** - * @author Gunnar Morling - */ -public class OrderEntity { - - private OrderType orderType; - - public OrderType getOrderType() { - return orderType; - } - - public void setOrderType(OrderType orderType) { - this.orderType = orderType; - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java deleted file mode 100644 index 4c65db6a1a..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.Mappings; -import org.mapstruct.factory.Mappers; - -/** - * @author Gunnar Morling - */ -@Mapper -public interface OrderMapper { - - OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); - - OrderDto orderEntityToDto(OrderEntity order); - - @Mappings({ - @Mapping(source = "EXTRA", target = "SPECIAL"), - @Mapping(source = "STANDARD", target = "DEFAULT"), - @Mapping(source = "NORMAL", target = "DEFAULT") - }) - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java deleted file mode 100644 index da519d8e28..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/test/enums/OrderType.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.test.enums; - -/** - * @author Gunnar Morling - */ -public enum OrderType { - - RETAIL, B2B, EXTRA, STANDARD, NORMAL -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java index fdb665552e..d7e230547a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper.java @@ -13,11 +13,15 @@ public interface ErroneousMapper { @Mappings({ - @Mapping(source = "bar", target = "foo"), - @Mapping(source = "source1.foo", target = "foo"), - @Mapping(source = "foo", target = "bar") + @Mapping(target = "foo", source = "bar"), + @Mapping(target = "foo", source = "source1.foo" ), + @Mapping(target = "bar", source = "foo") }) Target sourceToTarget(Source source); + // to test that nested is also reported correctly + @Mapping(target = "foo", source = "source1.foo" ) + Target sourceToTarget2(Source source); + AnotherTarget sourceToAnotherTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index 8031a7880d..5e30722152 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -33,13 +33,12 @@ public class ErroneousMappingsTest { diagnostics = { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 16, - messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)\\. " + - "Did you mean \"foo\"?"), + line = 20, + messageRegExp = "Target property \"foo\" must not be mapped more than once"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 17, - messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)\\. " + + line = 16, + messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)\\. " + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, @@ -48,11 +47,12 @@ public class ErroneousMappingsTest { "org.mapstruct.ap.test.erroneous.attributereference.Target. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, - line = 20, - messageRegExp = "Target property \"foo\" must not be mapped more than once"), + line = 23, + messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)\\. " + + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.WARNING, - line = 22, + line = 26, messageRegExp = "Unmapped target property: \"bar\"") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 6fab4df190..d300c1a2a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -175,6 +175,6 @@ public void shouldUseGetAsTargetAccessor() { } ) @WithClasses({ ArtistToChartEntryErroneous.class }) - public void reverseShouldRaiseErrorForEmptyContructor() { + public void inverseShouldRaiseErrorForEmptyContructor() { } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java index fcf8bc2a34..b8d3e9db4b 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java @@ -37,28 +37,28 @@ public void updateUserFromUserDTO(UserDTO userDTO, User user) { return; } - String[] settings1 = userDTOContactDataDTOSettings( userDTO ); - if ( settings1 != null ) { - user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + user.setEmail( userDTOContactDataDTOEmail( userDTO ) ); + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); } else { - user.setSettings( null ); + user.setPhone( null ); } + user.setAddress( userDTOContactDataDTOAddress( userDTO ) ); List preferences = userDTOContactDataDTOPreferences( userDTO ); if ( preferences != null ) { for ( String contactDataDTOPreference : preferences ) { user.addPreference( contactDataDTOPreference ); } } - user.setAddress( userDTOContactDataDTOAddress( userDTO ) ); - String phone = userDTOContactDataDTOPhone( userDTO ); - if ( phone != null ) { - user.setPhone( Integer.parseInt( phone ) ); + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); } else { - user.setPhone( null ); + user.setSettings( null ); } - user.setEmail( userDTOContactDataDTOEmail( userDTO ) ); user.setName( userDTO.getName() ); } @@ -68,27 +68,27 @@ public void updateUserFromUserAndIgnoreDTO(UserDTO userDTO, User user) { return; } - String[] settings1 = userDTOContactDataDTOSettings( userDTO ); - if ( settings1 != null ) { - user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + String email = userDTOContactDataDTOEmail( userDTO ); + if ( email != null ) { + user.setEmail( email ); } - List preferences = userDTOContactDataDTOPreferences( userDTO ); - if ( preferences != null ) { - for ( String contactDataDTOPreference : preferences ) { - user.addPreference( contactDataDTOPreference ); - } + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); } String address = userDTOContactDataDTOAddress( userDTO ); if ( address != null ) { user.setAddress( address ); } - String phone = userDTOContactDataDTOPhone( userDTO ); - if ( phone != null ) { - user.setPhone( Integer.parseInt( phone ) ); + List preferences = userDTOContactDataDTOPreferences( userDTO ); + if ( preferences != null ) { + for ( String contactDataDTOPreference : preferences ) { + user.addPreference( contactDataDTOPreference ); + } } - String email = userDTOContactDataDTOEmail( userDTO ); - if ( email != null ) { - user.setEmail( email ); + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); } if ( userDTO.getName() != null ) { user.setName( userDTO.getName() ); @@ -101,18 +101,19 @@ public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { return; } - String[] settings1 = userDTOContactDataDTOSettings( userDTO ); - if ( settings1 != null ) { - user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); + String email = userDTOContactDataDTOEmail( userDTO ); + if ( email != null ) { + user.setEmail( email ); } else { - user.setSettings( new String[0] ); + user.setEmail( "" ); } - List preferences = userDTOContactDataDTOPreferences( userDTO ); - if ( preferences != null ) { - for ( String contactDataDTOPreference : preferences ) { - user.addPreference( contactDataDTOPreference ); - } + String phone = userDTOContactDataDTOPhone( userDTO ); + if ( phone != null ) { + user.setPhone( Integer.parseInt( phone ) ); + } + else { + user.setPhone( 0 ); } String address = userDTOContactDataDTOAddress( userDTO ); if ( address != null ) { @@ -121,19 +122,18 @@ public void updateUserFromUserAndDefaultDTO(UserDTO userDTO, User user) { else { user.setAddress( "" ); } - String phone = userDTOContactDataDTOPhone( userDTO ); - if ( phone != null ) { - user.setPhone( Integer.parseInt( phone ) ); - } - else { - user.setPhone( 0 ); + List preferences = userDTOContactDataDTOPreferences( userDTO ); + if ( preferences != null ) { + for ( String contactDataDTOPreference : preferences ) { + user.addPreference( contactDataDTOPreference ); + } } - String email = userDTOContactDataDTOEmail( userDTO ); - if ( email != null ) { - user.setEmail( email ); + String[] settings1 = userDTOContactDataDTOSettings( userDTO ); + if ( settings1 != null ) { + user.setSettings( Arrays.copyOf( settings1, settings1.length ) ); } else { - user.setEmail( "" ); + user.setSettings( new String[0] ); } if ( userDTO.getName() != null ) { user.setName( userDTO.getName() ); @@ -150,24 +150,24 @@ protected ContactDataDTO userToContactDataDTO(User user) { ContactDataDTO contactDataDTO = new ContactDataDTO(); + contactDataDTO.setEmail( user.getEmail() ); if ( user.getPhone() != null ) { contactDataDTO.setPhone( String.valueOf( user.getPhone() ) ); } - String[] settings = user.getSettings(); - if ( settings != null ) { - contactDataDTO.setSettings( Arrays.copyOf( settings, settings.length ) ); - } + contactDataDTO.setAddress( user.getAddress() ); List list = user.getPreferences(); if ( list != null ) { contactDataDTO.setPreferences( new ArrayList( list ) ); } - contactDataDTO.setAddress( user.getAddress() ); - contactDataDTO.setEmail( user.getEmail() ); + String[] settings = user.getSettings(); + if ( settings != null ) { + contactDataDTO.setSettings( Arrays.copyOf( settings, settings.length ) ); + } return contactDataDTO; } - private String[] userDTOContactDataDTOSettings(UserDTO userDTO) { + private String userDTOContactDataDTOEmail(UserDTO userDTO) { if ( userDTO == null ) { return null; } @@ -175,14 +175,14 @@ private String[] userDTOContactDataDTOSettings(UserDTO userDTO) { if ( contactDataDTO == null ) { return null; } - String[] settings = contactDataDTO.getSettings(); - if ( settings == null ) { + String email = contactDataDTO.getEmail(); + if ( email == null ) { return null; } - return settings; + return email; } - private List userDTOContactDataDTOPreferences(UserDTO userDTO) { + private String userDTOContactDataDTOPhone(UserDTO userDTO) { if ( userDTO == null ) { return null; } @@ -190,11 +190,11 @@ private List userDTOContactDataDTOPreferences(UserDTO userDTO) { if ( contactDataDTO == null ) { return null; } - List preferences = contactDataDTO.getPreferences(); - if ( preferences == null ) { + String phone = contactDataDTO.getPhone(); + if ( phone == null ) { return null; } - return preferences; + return phone; } private String userDTOContactDataDTOAddress(UserDTO userDTO) { @@ -212,7 +212,7 @@ private String userDTOContactDataDTOAddress(UserDTO userDTO) { return address; } - private String userDTOContactDataDTOPhone(UserDTO userDTO) { + private List userDTOContactDataDTOPreferences(UserDTO userDTO) { if ( userDTO == null ) { return null; } @@ -220,14 +220,14 @@ private String userDTOContactDataDTOPhone(UserDTO userDTO) { if ( contactDataDTO == null ) { return null; } - String phone = contactDataDTO.getPhone(); - if ( phone == null ) { + List preferences = contactDataDTO.getPreferences(); + if ( preferences == null ) { return null; } - return phone; + return preferences; } - private String userDTOContactDataDTOEmail(UserDTO userDTO) { + private String[] userDTOContactDataDTOSettings(UserDTO userDTO) { if ( userDTO == null ) { return null; } @@ -235,10 +235,10 @@ private String userDTOContactDataDTOEmail(UserDTO userDTO) { if ( contactDataDTO == null ) { return null; } - String email = contactDataDTO.getEmail(); - if ( email == null ) { + String[] settings = contactDataDTO.getSettings(); + if ( settings == null ) { return null; } - return email; + return settings; } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index bd1575a207..e7e1be5b1d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -28,27 +28,27 @@ public Domain create(DtoWithPresenceCheck source) { Domain domain = createNullDomain(); - if ( source.hasStringsInitialized() ) { - domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + if ( source.hasStrings() ) { + List list = source.getStrings(); + domain.setStrings( new HashSet( list ) ); } if ( source.hasStrings() ) { domain.setLongs( stringListToLongSet( source.getStrings() ) ); } - if ( source.hasStrings() ) { - List list = source.getStrings(); - domain.setStrings( new HashSet( list ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + domain.setStringsInitialized( new HashSet( list1 ) ); + } + if ( source.hasStringsInitialized() ) { + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); } if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - domain.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); } - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - domain.setStringsInitialized( new HashSet( list2 ) ); - } return domain; } @@ -59,6 +59,18 @@ public void update(DtoWithPresenceCheck source, Domain target) { return; } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { if ( source.hasStrings() ) { target.getLongs().clear(); @@ -70,16 +82,16 @@ public void update(DtoWithPresenceCheck source, Domain target) { target.setLongs( stringListToLongSet( source.getStrings() ) ); } } - if ( target.getStrings() != null ) { - if ( source.hasStrings() ) { - target.getStrings().clear(); - target.getStrings().addAll( source.getStrings() ); + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { - if ( source.hasStrings() ) { - List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -104,25 +116,13 @@ public void update(DtoWithPresenceCheck source, Domain target) { } else { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } - if ( target.getStringsInitialized() != null ) { - if ( source.hasStringsInitialized() ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( source.getStringsInitialized() ); - } - } - else { - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list2 ) ); - } - } } @Override @@ -131,6 +131,18 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { return null; } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { if ( source.hasStrings() ) { target.getLongs().clear(); @@ -142,16 +154,16 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { target.setLongs( stringListToLongSet( source.getStrings() ) ); } } - if ( target.getStrings() != null ) { - if ( source.hasStrings() ) { - target.getStrings().clear(); - target.getStrings().addAll( source.getStrings() ); + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { - if ( source.hasStrings() ) { - List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -176,25 +188,13 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } else { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } - if ( target.getStringsInitialized() != null ) { - if ( source.hasStringsInitialized() ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( source.getStringsInitialized() ); - } - } - else { - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list2 ) ); - } - } return target; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 3ed50cb865..f0f2ea5f01 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -26,23 +26,23 @@ public Domain create(Dto source) { Domain domain = new Domain(); if ( source != null ) { - domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); - domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list = source.getStrings(); if ( list != null ) { domain.setStrings( new HashSet( list ) ); } - List list1 = source.getStringsWithDefault(); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsWithDefault( new ArrayList( list1 ) ); + domain.setStringsInitialized( new HashSet( list1 ) ); + } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + domain.setStringsWithDefault( new ArrayList( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); } - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - domain.setStringsInitialized( new HashSet( list2 ) ); - } } return domain; @@ -52,6 +52,22 @@ public Domain create(Dto source) { public void update(Dto source, Domain target) { if ( source != null ) { + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( new HashSet() ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); if ( set != null ) { @@ -68,20 +84,20 @@ public void update(Dto source, Domain target) { target.setLongs( set ); } } - if ( target.getStrings() != null ) { - List list = source.getStrings(); - if ( list != null ) { - target.getStrings().clear(); - target.getStrings().addAll( list ); + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); } else { - target.setStrings( new HashSet() ); + target.setStringsInitialized( new HashSet() ); } } else { - List list = source.getStrings(); - if ( list != null ) { - target.setStrings( new HashSet( list ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -101,38 +117,22 @@ public void update(Dto source, Domain target) { } } if ( target.getStringsWithDefault() != null ) { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( list2 ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } else { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { - target.setStringsWithDefault( new ArrayList( list1 ) ); - } - else { - target.setStringsWithDefault( helper.toList( "3" ) ); - } - } - if ( target.getStringsInitialized() != null ) { - List list2 = source.getStringsInitialized(); + List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { - target.setStringsInitialized( new HashSet() ); - } - } - else { - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - target.setStringsInitialized( new HashSet( list2 ) ); + target.setStringsWithDefault( helper.toList( "3" ) ); } } } @@ -142,6 +142,22 @@ public void update(Dto source, Domain target) { public Domain updateWithReturn(Dto source, Domain target) { if ( source != null ) { + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( new HashSet() ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); if ( set != null ) { @@ -158,20 +174,20 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongs( set ); } } - if ( target.getStrings() != null ) { - List list = source.getStrings(); - if ( list != null ) { - target.getStrings().clear(); - target.getStrings().addAll( list ); + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); } else { - target.setStrings( new HashSet() ); + target.setStringsInitialized( new HashSet() ); } } else { - List list = source.getStrings(); - if ( list != null ) { - target.setStrings( new HashSet( list ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -191,38 +207,22 @@ public Domain updateWithReturn(Dto source, Domain target) { } } if ( target.getStringsWithDefault() != null ) { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( list2 ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } else { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { - target.setStringsWithDefault( new ArrayList( list1 ) ); - } - else { - target.setStringsWithDefault( helper.toList( "3" ) ); - } - } - if ( target.getStringsInitialized() != null ) { - List list2 = source.getStringsInitialized(); + List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { - target.setStringsInitialized( new HashSet() ); - } - } - else { - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - target.setStringsInitialized( new HashSet( list2 ) ); + target.setStringsWithDefault( helper.toList( "3" ) ); } } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index 34867626a6..a07601a4df 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -28,23 +28,23 @@ public Domain create(Dto source) { Domain domain = createNullDomain(); - domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); - domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list = source.getStrings(); if ( list != null ) { domain.setStrings( new HashSet( list ) ); } - List list1 = source.getStringsWithDefault(); + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsWithDefault( new ArrayList( list1 ) ); + domain.setStringsInitialized( new HashSet( list1 ) ); + } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + domain.setStringsWithDefault( new ArrayList( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); } - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - domain.setStringsInitialized( new HashSet( list2 ) ); - } return domain; } @@ -55,6 +55,22 @@ public void update(Dto source, Domain target) { return; } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); if ( set != null ) { @@ -71,20 +87,20 @@ public void update(Dto source, Domain target) { target.setLongs( set ); } } - if ( target.getStrings() != null ) { - List list = source.getStrings(); - if ( list != null ) { - target.getStrings().clear(); - target.getStrings().addAll( list ); + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); } else { - target.setStrings( null ); + target.setStringsInitialized( null ); } } else { - List list = source.getStrings(); - if ( list != null ) { - target.setStrings( new HashSet( list ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -104,38 +120,22 @@ public void update(Dto source, Domain target) { } } if ( target.getStringsWithDefault() != null ) { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( list2 ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } else { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { - target.setStringsWithDefault( new ArrayList( list1 ) ); - } - else { - target.setStringsWithDefault( helper.toList( "3" ) ); - } - } - if ( target.getStringsInitialized() != null ) { - List list2 = source.getStringsInitialized(); + List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { - target.setStringsInitialized( null ); - } - } - else { - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - target.setStringsInitialized( new HashSet( list2 ) ); + target.setStringsWithDefault( helper.toList( "3" ) ); } } } @@ -146,6 +146,22 @@ public Domain updateWithReturn(Dto source, Domain target) { return null; } + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); if ( set != null ) { @@ -162,20 +178,20 @@ public Domain updateWithReturn(Dto source, Domain target) { target.setLongs( set ); } } - if ( target.getStrings() != null ) { - List list = source.getStrings(); - if ( list != null ) { - target.getStrings().clear(); - target.getStrings().addAll( list ); + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); } else { - target.setStrings( null ); + target.setStringsInitialized( null ); } } else { - List list = source.getStrings(); - if ( list != null ) { - target.setStrings( new HashSet( list ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -195,38 +211,22 @@ public Domain updateWithReturn(Dto source, Domain target) { } } if ( target.getStringsWithDefault() != null ) { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { target.getStringsWithDefault().clear(); - target.getStringsWithDefault().addAll( list1 ); + target.getStringsWithDefault().addAll( list2 ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } else { - List list1 = source.getStringsWithDefault(); - if ( list1 != null ) { - target.setStringsWithDefault( new ArrayList( list1 ) ); - } - else { - target.setStringsWithDefault( helper.toList( "3" ) ); - } - } - if ( target.getStringsInitialized() != null ) { - List list2 = source.getStringsInitialized(); + List list2 = source.getStringsWithDefault(); if ( list2 != null ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( list2 ); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { - target.setStringsInitialized( null ); - } - } - else { - List list2 = source.getStringsInitialized(); - if ( list2 != null ) { - target.setStringsInitialized( new HashSet( list2 ) ); + target.setStringsWithDefault( helper.toList( "3" ) ); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index c44a9bc360..6ed369c4d9 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -28,23 +28,23 @@ public Domain create(DtoWithPresenceCheck source) { Domain domain = createNullDomain(); - domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); - domain.setLongs( stringListToLongSet( source.getStrings() ) ); if ( source.hasStrings() ) { List list = source.getStrings(); domain.setStrings( new HashSet( list ) ); } + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + domain.setStringsInitialized( new HashSet( list1 ) ); + } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - domain.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list2 ) ); } else { domain.setStringsWithDefault( helper.toList( "3" ) ); } - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - domain.setStringsInitialized( new HashSet( list2 ) ); - } return domain; } @@ -55,6 +55,18 @@ public void update(DtoWithPresenceCheck source, Domain target) { return; } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { if ( source.hasStrings() ) { target.getLongs().clear(); @@ -66,16 +78,16 @@ public void update(DtoWithPresenceCheck source, Domain target) { target.setLongs( stringListToLongSet( source.getStrings() ) ); } } - if ( target.getStrings() != null ) { - if ( source.hasStrings() ) { - target.getStrings().clear(); - target.getStrings().addAll( source.getStrings() ); + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { - if ( source.hasStrings() ) { - List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -100,25 +112,13 @@ public void update(DtoWithPresenceCheck source, Domain target) { } else { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } - if ( target.getStringsInitialized() != null ) { - if ( source.hasStringsInitialized() ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( source.getStringsInitialized() ); - } - } - else { - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list2 ) ); - } - } } @Override @@ -127,6 +127,18 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { return null; } + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new HashSet( list ) ); + } + } if ( target.getLongs() != null ) { if ( source.hasStrings() ) { target.getLongs().clear(); @@ -138,16 +150,16 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { target.setLongs( stringListToLongSet( source.getStrings() ) ); } } - if ( target.getStrings() != null ) { - if ( source.hasStrings() ) { - target.getStrings().clear(); - target.getStrings().addAll( source.getStrings() ); + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); } } else { - if ( source.hasStrings() ) { - List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new HashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -172,25 +184,13 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { } else { if ( source.hasStringsWithDefault() ) { - List list1 = source.getStringsWithDefault(); - target.setStringsWithDefault( new ArrayList( list1 ) ); + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); } else { target.setStringsWithDefault( helper.toList( "3" ) ); } } - if ( target.getStringsInitialized() != null ) { - if ( source.hasStringsInitialized() ) { - target.getStringsInitialized().clear(); - target.getStringsInitialized().addAll( source.getStringsInitialized() ); - } - } - else { - if ( source.hasStringsInitialized() ) { - List list2 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list2 ) ); - } - } return target; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java index 6683e81bbc..80674f925d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperConstantImpl.java @@ -31,14 +31,28 @@ public FishTankDto map(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setMaterial( fishTankToMaterialDto( source ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); return fishTankDto; } + protected FishDto fishToFishDto(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + fishDto.setName( "Nemo" ); + + return fishDto; + } + protected MaterialTypeDto materialTypeToMaterialTypeDto(MaterialType materialType) { if ( materialType == null ) { return null; @@ -65,20 +79,6 @@ protected MaterialDto fishTankToMaterialDto(FishTank fishTank) { return materialDto; } - protected FishDto fishToFishDto(Fish fish) { - if ( fish == null ) { - return null; - } - - FishDto fishDto = new FishDto(); - - fishDto.setKind( fish.getType() ); - - fishDto.setName( "Nemo" ); - - return fishDto; - } - protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { if ( waterPlant == null ) { return null; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 5716b231e1..2b81718dba 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -76,8 +76,8 @@ public FishTank map(FishTankDto source) { FishTank fishTank = new FishTank(); fishTank.setFish( fishDtoToFish( source.getFish() ) ); - fishTank.setQuality( waterQualityDtoToWaterQuality( source.getQuality() ) ); fishTank.setInterior( fishTankDtoToInterior( source ) ); + fishTank.setQuality( waterQualityDtoToWaterQuality( source.getQuality() ) ); fishTank.setMaterial( materialTypeDtoToMaterialType( sourceMaterialMaterialType( source ) ) ); fishTank.setPlant( waterPlantDtoToWaterPlant( source.getPlant() ) ); fishTank.setName( source.getName() ); @@ -233,6 +233,30 @@ protected Fish fishDtoToFish(FishDto fishDto) { return fish; } + protected Ornament ornamentDtoToOrnament(OrnamentDto ornamentDto) { + if ( ornamentDto == null ) { + return null; + } + + Ornament ornament = new Ornament(); + + ornament.setType( ornamentDto.getType() ); + + return ornament; + } + + protected Interior fishTankDtoToInterior(FishTankDto fishTankDto) { + if ( fishTankDto == null ) { + return null; + } + + Interior interior = new Interior(); + + interior.setOrnament( ornamentDtoToOrnament( fishTankDto.getOrnament() ) ); + + return interior; + } + private String waterQualityReportDtoOrganisationName(WaterQualityReportDto waterQualityReportDto) { if ( waterQualityReportDto == null ) { return null; @@ -273,30 +297,6 @@ protected WaterQuality waterQualityDtoToWaterQuality(WaterQualityDto waterQualit return waterQuality; } - protected Ornament ornamentDtoToOrnament(OrnamentDto ornamentDto) { - if ( ornamentDto == null ) { - return null; - } - - Ornament ornament = new Ornament(); - - ornament.setType( ornamentDto.getType() ); - - return ornament; - } - - protected Interior fishTankDtoToInterior(FishTankDto fishTankDto) { - if ( fishTankDto == null ) { - return null; - } - - Interior interior = new Interior(); - - interior.setOrnament( ornamentDtoToOrnament( fishTankDto.getOrnament() ) ); - - return interior; - } - private MaterialTypeDto sourceMaterialMaterialType(FishTankDto fishTankDto) { if ( fishTankDto == null ) { return null; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java index 48d276f00b..131566ad4f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -33,9 +33,9 @@ public ChartEntry map(Chart chart, Song song, Integer position) { } if ( song != null ) { chartEntry.setSongTitle( song.getTitle() ); - chartEntry.setCity( songArtistLabelStudioCity( song ) ); - chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); chartEntry.setArtistName( songArtistName( song ) ); + chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); + chartEntry.setCity( songArtistLabelStudioCity( song ) ); } if ( position != null ) { chartEntry.setPosition( position ); @@ -53,9 +53,9 @@ public ChartEntry map(Song song) { ChartEntry chartEntry = new ChartEntry(); chartEntry.setSongTitle( song.getTitle() ); - chartEntry.setCity( songArtistLabelStudioCity( song ) ); - chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); chartEntry.setArtistName( songArtistName( song ) ); + chartEntry.setRecordedAt( songArtistLabelStudioName( song ) ); + chartEntry.setCity( songArtistLabelStudioCity( song ) ); return chartEntry; } @@ -73,7 +73,7 @@ public ChartEntry map(Chart name) { return chartEntry; } - private String songArtistLabelStudioCity(Song song) { + private String songArtistName(Song song) { if ( song == null ) { return null; } @@ -81,19 +81,11 @@ private String songArtistLabelStudioCity(Song song) { if ( artist == null ) { return null; } - Label label = artist.getLabel(); - if ( label == null ) { - return null; - } - Studio studio = label.getStudio(); - if ( studio == null ) { - return null; - } - String city = studio.getCity(); - if ( city == null ) { + String name = artist.getName(); + if ( name == null ) { return null; } - return city; + return name; } private String songArtistLabelStudioName(Song song) { @@ -119,7 +111,7 @@ private String songArtistLabelStudioName(Song song) { return name; } - private String songArtistName(Song song) { + private String songArtistLabelStudioCity(Song song) { if ( song == null ) { return null; } @@ -127,10 +119,18 @@ private String songArtistName(Song song) { if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { + Label label = artist.getLabel(); + if ( label == null ) { return null; } - return name; + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index f01afb4286..8877bd421f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -68,11 +68,11 @@ public ChartEntry map(Chart chart) { ChartEntry chartEntry = new ChartEntry(); - chartEntry.setSongTitle( chartSongTitle( chart ) ); chartEntry.setChartName( chart.getName() ); - chartEntry.setCity( chartSongArtistLabelStudioCity( chart ) ); - chartEntry.setRecordedAt( chartSongArtistLabelStudioName( chart ) ); + chartEntry.setSongTitle( chartSongTitle( chart ) ); chartEntry.setArtistName( chartSongArtistName( chart ) ); + chartEntry.setRecordedAt( chartSongArtistLabelStudioName( chart ) ); + chartEntry.setCity( chartSongArtistLabelStudioCity( chart ) ); chartEntry.setPosition( mapPosition( chartSongPositions( chart ) ) ); return chartEntry; @@ -85,8 +85,8 @@ protected Studio chartEntryToStudio(ChartEntry chartEntry) { Studio studio = new Studio(); - studio.setCity( chartEntry.getCity() ); studio.setName( chartEntry.getRecordedAt() ); + studio.setCity( chartEntry.getCity() ); return studio; } @@ -124,8 +124,8 @@ protected Song chartEntryToSong(ChartEntry chartEntry) { Song song = new Song(); song.setArtist( chartEntryToArtist( chartEntry ) ); - song.setPositions( mapPosition( chartEntry.getPosition() ) ); song.setTitle( chartEntry.getSongTitle() ); + song.setPositions( mapPosition( chartEntry.getPosition() ) ); return song; } @@ -135,8 +135,8 @@ protected void chartEntryToStudio1(ChartEntry chartEntry, Studio mappingTarget) return; } - mappingTarget.setCity( chartEntry.getCity() ); mappingTarget.setName( chartEntry.getRecordedAt() ); + mappingTarget.setCity( chartEntry.getCity() ); } protected void chartEntryToLabel1(ChartEntry chartEntry, Label mappingTarget) { @@ -212,7 +212,7 @@ private String chartSongTitle(Chart chart) { return title; } - private String chartSongArtistLabelStudioCity(Chart chart) { + private String chartSongArtistName(Chart chart) { if ( chart == null ) { return null; } @@ -224,19 +224,11 @@ private String chartSongArtistLabelStudioCity(Chart chart) { if ( artist == null ) { return null; } - Label label = artist.getLabel(); - if ( label == null ) { - return null; - } - Studio studio = label.getStudio(); - if ( studio == null ) { - return null; - } - String city = studio.getCity(); - if ( city == null ) { + String name = artist.getName(); + if ( name == null ) { return null; } - return city; + return name; } private String chartSongArtistLabelStudioName(Chart chart) { @@ -266,7 +258,7 @@ private String chartSongArtistLabelStudioName(Chart chart) { return name; } - private String chartSongArtistName(Chart chart) { + private String chartSongArtistLabelStudioCity(Chart chart) { if ( chart == null ) { return null; } @@ -278,11 +270,19 @@ private String chartSongArtistName(Chart chart) { if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { + Label label = artist.getLabel(); + if ( label == null ) { return null; } - return name; + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; } private List chartSongPositions(Chart chart) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java index 38f73d64fc..633fe9dc56 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdateImpl.java @@ -41,12 +41,12 @@ protected void chartEntryToStudio(ChartEntry chartEntry, Studio mappingTarget) { return; } - if ( chartEntry.getCity() != null ) { - mappingTarget.setCity( chartEntry.getCity() ); - } if ( chartEntry.getRecordedAt() != null ) { mappingTarget.setName( chartEntry.getRecordedAt() ); } + if ( chartEntry.getCity() != null ) { + mappingTarget.setCity( chartEntry.getCity() ); + } } protected void chartEntryToLabel(ChartEntry chartEntry, Label mappingTarget) { @@ -83,6 +83,9 @@ protected void chartEntryToSong(ChartEntry chartEntry, Song mappingTarget) { mappingTarget.setArtist( new Artist() ); } chartEntryToArtist( chartEntry, mappingTarget.getArtist() ); + if ( chartEntry.getSongTitle() != null ) { + mappingTarget.setTitle( chartEntry.getSongTitle() ); + } if ( mappingTarget.getPositions() != null ) { List list = mapPosition( chartEntry.getPosition() ); if ( list != null ) { @@ -96,8 +99,5 @@ protected void chartEntryToSong(ChartEntry chartEntry, Song mappingTarget) { mappingTarget.setPositions( list ); } } - if ( chartEntry.getSongTitle() != null ) { - mappingTarget.setTitle( chartEntry.getSongTitle() ); - } } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java index 8963b800ae..f5f37142c2 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java @@ -22,23 +22,23 @@ public ConstantsTarget mapFromConstants(String dummy) { ConstantsTarget constantsTarget = new ConstantsTarget(); - constantsTarget.setByteBoxed( (byte) -128 ); - constantsTarget.setDoubleBoxed( (double) 0x0.001P-1062d ); + constantsTarget.setBooleanValue( true ); constantsTarget.setBooleanBoxed( false ); constantsTarget.setCharValue( 'b' ); + constantsTarget.setCharBoxed( 'a' ); + constantsTarget.setByteValue( (byte) 20 ); + constantsTarget.setByteBoxed( (byte) -128 ); + constantsTarget.setShortValue( (short) 1996 ); + constantsTarget.setShortBoxed( (short) -1996 ); constantsTarget.setIntValue( -03777777 ); + constantsTarget.setIntBoxed( 15 ); + constantsTarget.setLongValue( 0x7fffffffffffffffL ); constantsTarget.setLongBoxed( (long) 0xCAFEBABEL ); - constantsTarget.setFloatBoxed( 3.4028235e38f ); constantsTarget.setFloatValue( 1.40e-45f ); - constantsTarget.setIntBoxed( 15 ); + constantsTarget.setFloatBoxed( 3.4028235e38f ); constantsTarget.setDoubleValue( 1e137 ); - constantsTarget.setLongValue( 0x7fffffffffffffffL ); + constantsTarget.setDoubleBoxed( (double) 0x0.001P-1062d ); constantsTarget.setDoubleBoxedZero( (double) 0.0 ); - constantsTarget.setShortBoxed( (short) -1996 ); - constantsTarget.setCharBoxed( 'a' ); - constantsTarget.setBooleanValue( true ); - constantsTarget.setShortValue( (short) 1996 ); - constantsTarget.setByteValue( (byte) 20 ); return constantsTarget; } From 5f2a53afe1500925cf497bad9d7e2aa2e4578f0d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Aug 2019 08:51:40 +0200 Subject: [PATCH 0367/1006] Use trusty dist for JDK 8 build, add OpenJDK13 build and remove OpenJDK12 build --- .travis.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9058ee97b..410650be31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,13 @@ matrix: - jdk: oraclejdk8 after_success: - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" + dist: trusty - jdk: openjdk11 # Only run the processor and its dependencies # The integration tests are using the maven toolchain and that is not yet ready for Java 11 # There is an issue with the documentation so skip it script: mvn -B -V clean install -pl processor -am - - jdk: openjdk12 + - jdk: openjdk13 # Only run the processor and its dependencies # The integration tests are using the maven toolchain and that is not yet ready for Java 11 # There is an issue with the documentation so skip it @@ -37,7 +38,3 @@ sudo: required cache: directories: - $HOME/.m2 -addons: - apt: - packages: - - oracle-java8-installer From e5c5550182e75b399d77573fa876fb737a3aaf07 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 10 Aug 2019 17:38:37 +0300 Subject: [PATCH 0368/1006] Fix warning addAll in org.mapstruct.ap.internal.model.assignment Fix typo in org.mapstruct.ap.internal.model.common.Type --- .../ap/internal/model/BeanMappingMethod.java | 6 +++--- .../ap/internal/model/assignment/AdderWrapper.java | 3 +-- .../internal/model/assignment/ArrayCopyWrapper.java | 3 +-- ...ngInstanceSetterWrapperForCollectionsAndMaps.java | 2 +- .../model/assignment/StreamAdderWrapper.java | 3 +-- .../ap/internal/model/assignment/UpdateWrapper.java | 3 +-- .../org/mapstruct/ap/internal/model/common/Type.java | 12 ++++++------ 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a5cb32e214..ba78f7291d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -387,7 +387,7 @@ private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters private boolean canBeConstructed(Type typeToBeConstructed) { return !typeToBeConstructed.isAbstract() && typeToBeConstructed.isAssignableTo( this.method.getResultType() ) - && typeToBeConstructed.hasEmptyAccessibleContructor(); + && typeToBeConstructed.hasEmptyAccessibleConstructor(); } private void reportResultTypeFromBeanMappingNotConstructableError(Type resultType) { @@ -410,7 +410,7 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) { method.getResultType() ); } - else if ( !resultType.hasEmptyAccessibleContructor() ) { + else if ( !resultType.hasEmptyAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, @@ -428,7 +428,7 @@ private void reportReturnTypeNotConstructableError(Type returnType) { returnType ); } - else if ( !returnType.hasEmptyAccessibleContructor() ) { + else if ( !returnType.hasEmptyAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index 71b5f10a9e..c5778628e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -74,8 +74,7 @@ public boolean isSetExplicitlyToDefault() { @Override public Set getImportTypes() { - Set imported = new HashSet<>(); - imported.addAll( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); imported.add( adderType.getTypeBound() ); return imported; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java index db2c7be5ac..6b623f7e39 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.java @@ -40,8 +40,7 @@ public ArrayCopyWrapper(Assignment rhs, @Override public Set getImportTypes() { - Set imported = new HashSet<>(); - imported.addAll( getAssignment().getImportTypes() ); + Set imported = new HashSet<>( getAssignment().getImportTypes() ); imported.add( arraysType ); imported.add( targetType ); return imported; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index d567b2d287..d07c5acef8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -60,7 +60,7 @@ public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAs @Override public Set getImportTypes() { - Set imported = new HashSet( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) { imported.add( targetType.getImplementationType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java index 1deff95a2a..21a028c79f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/StreamAdderWrapper.java @@ -70,8 +70,7 @@ public boolean isSetExplicitlyToDefault() { @Override public Set getImportTypes() { - Set imported = new HashSet<>(); - imported.addAll( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); imported.add( adderType.getTypeBound() ); return imported; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index dede031456..cf0140e8ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -74,8 +74,7 @@ public List getThrownTypes() { @Override public Set getImportTypes() { - Set imported = new HashSet<>(); - imported.addAll( super.getImportTypes() ); + Set imported = new HashSet<>( super.getImportTypes() ); if ( factoryMethod != null ) { imported.addAll( factoryMethod.getImportTypes() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index bc0170645b..9aa996e7e3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -99,7 +99,7 @@ public class Type extends ModelElement implements Comparable { private Type boundingBase = null; - private Boolean hasEmptyAccessibleContructor; + private Boolean hasEmptyAccessibleConstructor; private final Filters filters; @@ -1018,20 +1018,20 @@ public Type getTypeBound() { return boundingBase; } - public boolean hasEmptyAccessibleContructor() { + public boolean hasEmptyAccessibleConstructor() { - if ( this.hasEmptyAccessibleContructor == null ) { - hasEmptyAccessibleContructor = false; + if ( this.hasEmptyAccessibleConstructor == null ) { + hasEmptyAccessibleConstructor = false; List constructors = ElementFilter.constructorsIn( typeElement.getEnclosedElements() ); for ( ExecutableElement constructor : constructors ) { if ( !constructor.getModifiers().contains( Modifier.PRIVATE ) && constructor.getParameters().isEmpty() ) { - hasEmptyAccessibleContructor = true; + hasEmptyAccessibleConstructor = true; break; } } } - return hasEmptyAccessibleContructor; + return hasEmptyAccessibleConstructor; } /** From f02b3d1a4217ed42031e4f6fc263411861245861 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 11 Aug 2019 10:10:37 +0300 Subject: [PATCH 0369/1006] Remove unnecessary generic type in Collections.empty*, replace "for" on Stream API, replace anonymous classes on lambda --- .../org/mapstruct/ap/MappingProcessor.java | 5 +- .../conversion/DateToStringConversion.java | 3 +- .../ap/internal/model/Annotation.java | 2 +- .../ap/internal/model/BeanMappingMethod.java | 54 ++++++++----------- .../model/LifecycleMethodResolver.java | 29 ++++------ .../ap/internal/model/MethodReference.java | 3 +- .../ap/internal/model/common/TypeFactory.java | 7 +-- .../internal/model/source/MappingOptions.java | 2 +- .../model/source/SelectionParameters.java | 4 +- .../model/source/SourceReference.java | 8 +-- .../util/AnnotationProcessorContext.java | 5 +- .../mapstruct/ap/internal/util/Fields.java | 4 +- .../ap/internal/util/MapperConfiguration.java | 5 +- 13 files changed, 44 insertions(+), 87 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 4878f3f989..5f7d3394f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -341,10 +341,7 @@ private static class ProcessorComparator implements Comparator o1, ModelElementProcessor o2) { - return - o1.getPriority() < o2.getPriority() ? -1 : - o1.getPriority() == o2.getPriority() ? 0 : - 1; + return Integer.compare( o1.getPriority(), o2.getPriority() ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index eff3731c85..361ce9d9ab 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -15,7 +15,6 @@ import org.mapstruct.ap.internal.model.TypeConversion; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; -import org.mapstruct.ap.internal.model.common.Type; import static java.util.Arrays.asList; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -31,7 +30,7 @@ public class DateToStringConversion implements ConversionProvider { @Override public Assignment to(ConversionContext conversionContext) { return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ), - Collections.emptyList(), + Collections.emptyList(), getConversionExpression( conversionContext, "format" ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java index efc3fa0730..405958ccdf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java @@ -27,7 +27,7 @@ public class Annotation extends ModelElement { private List properties; public Annotation(Type type) { - this( type, Collections.emptyList() ); + this( type, Collections.emptyList() ); } public Annotation(Type type, List properties) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index ba78f7291d..d5506b6bca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -17,9 +17,11 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.function.Function; +import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; @@ -104,7 +106,7 @@ public Builder sourceMethod(SourceMethod sourceMethod) { singleMapping = targetName -> getMappingByTargetName( targetName, sourceMethod.getMappingOptions().getMappings() ); mappingsInitializer = - mappings -> mappings.stream().forEach( mapping -> initReferencesForSourceMethodMapping( mapping ) ); + mappings -> mappings.stream().forEach( this::initReferencesForSourceMethodMapping ); this.method = sourceMethod; return this; } @@ -112,7 +114,7 @@ public Builder sourceMethod(SourceMethod sourceMethod) { public Builder forgedMethod(Method method) { singleMapping = targetPropertyName -> null; mappingsInitializer = - mappings -> mappings.stream().forEach( mapping -> initReferencesForForgedMethodMapping( mapping ) ); + mappings -> mappings.stream().forEach( this::initReferencesForForgedMethodMapping ); this.method = method; return this; } @@ -177,8 +179,9 @@ public BeanMappingMethod build() { continue; } Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); - for ( String key : readAccessors.keySet() ) { - unprocessedSourceProperties.put( key, readAccessors.get( key ) ); + + for ( Entry entry : readAccessors.entrySet() ) { + unprocessedSourceProperties.put( entry.getKey(), entry.getValue() ); } } existingVariableNames.addAll( method.getParameterNames() ); @@ -191,8 +194,8 @@ public BeanMappingMethod build() { } // map properties with mapping - boolean mappingErrorOccured = handleDefinedMappings(); - if ( mappingErrorOccured ) { + boolean mappingErrorOccurred = handleDefinedMappings(); + if ( mappingErrorOccurred ) { return null; } @@ -366,13 +369,9 @@ private void sortPropertyMappingsByDependencies() { } else { Collections.sort( - propertyMappings, new Comparator() { - @Override - public int compare(PropertyMapping o1, PropertyMapping o2) { - return graphAnalyzer.getTraversalSequence( o1.getName() ) - - graphAnalyzer.getTraversalSequence( o2.getName() ); - } - } + propertyMappings, + Comparator.comparingInt( propertyMapping -> + graphAnalyzer.getTraversalSequence( propertyMapping.getName() ) ) ); } } @@ -512,9 +511,8 @@ private void initReferencesForForgedMethodMapping(Mapping mapping ) { */ private static boolean isValidWhenReversed(Mapping mapping) { if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { - return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() != null ? - mapping.getSourceReference().isValid() : - true ); + return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() == null || + mapping.getSourceReference().isValid() ); } return true; } @@ -1051,24 +1049,15 @@ public Set getImportTypes() { } public List getSourceParametersExcludingPrimitives() { - List sourceParameters = new ArrayList<>(); - for ( Parameter sourceParam : getSourceParameters() ) { - if ( !sourceParam.getType().isPrimitive() ) { - sourceParameters.add( sourceParam ); - } - } - - return sourceParameters; + return getSourceParameters().stream() + .filter( parameter -> !parameter.getType().isPrimitive() ) + .collect( Collectors.toList() ); } public List getSourcePrimitiveParameters() { - List sourceParameters = new ArrayList<>(); - for ( Parameter sourceParam : getSourceParameters() ) { - if ( sourceParam.getType().isPrimitive() ) { - sourceParameters.add( sourceParam ); - } - } - return sourceParameters; + return getSourceParameters().stream() + .filter( parameter -> parameter.getType().isPrimitive() ) + .collect( Collectors.toList() ); } @Override @@ -1092,8 +1081,7 @@ public boolean equals(Object obj) { if ( !super.equals( obj ) ) { return false; } - return propertyMappings != null ? propertyMappings.equals( that.propertyMappings ) : - that.propertyMappings == null; + return Objects.equals( propertyMappings, that.propertyMappings ); } private interface SingleMappingByTargetPropertyNameFunction { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 0448be5d44..40dbb74901 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -123,9 +124,7 @@ private static List getAllAvailableMethods(Method method, List availableMethods = new ArrayList<>( methodsProvidedByParams.size() + sourceModelMethods.size() ); - for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { - availableMethods.add( methodProvidedByParams ); - } + availableMethods.addAll( methodsProvidedByParams ); availableMethods.addAll( sourceModelMethods ); return availableMethods; @@ -141,7 +140,7 @@ private static List collectLifecycleCallbackMe List> matchingMethods = selectors.getMatchingMethods( method, callbackMethods, - Collections. emptyList(), + Collections.emptyList(), targetType, SelectionCriteria.forLifecycleMethods( selectionParameters ) ); @@ -185,24 +184,14 @@ private static List toLifecycleCallbackMethodR } private static List filterBeforeMappingMethods(List methods) { - List result = new ArrayList<>(); - for ( SourceMethod method : methods ) { - if ( method.isBeforeMappingMethod() ) { - result.add( method ); - } - } - - return result; + return methods.stream() + .filter( SourceMethod::isBeforeMappingMethod ) + .collect( Collectors.toList() ); } private static List filterAfterMappingMethods(List methods) { - List result = new ArrayList<>(); - for ( SourceMethod method : methods ) { - if ( method.isAfterMappingMethod() ) { - result.add( method ); - } - } - - return result; + return methods.stream() + .filter( SourceMethod::isAfterMappingMethod ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 81d75a80e4..69b9b81dc1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -235,8 +235,7 @@ public Set getImportTypes() { @Override public List getThrownTypes() { - List exceptions = new ArrayList<>(); - exceptions.addAll( thrownTypes ); + List exceptions = new ArrayList<>( thrownTypes ); if ( assignment != null ) { exceptions.addAll( assignment.getThrownTypes() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index c94986e822..1ec8077a88 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -68,12 +68,7 @@ public class TypeFactory { private static final Extractor BUILDER_INFO_CREATION_METHOD_EXTRACTOR = - new Extractor() { - @Override - public String apply(BuilderInfo builderInfo) { - return builderInfo.getBuilderCreationMethod().toString(); - } - }; + builderInfo -> builderInfo.getBuilderCreationMethod().toString(); private final Elements elementUtils; private final Types typeUtils; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 81e93826a6..0b8cf89f6f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -85,7 +85,7 @@ public static MappingOptions forMappingsOnly(Set mappings, null, null, forForgedMethods ? BeanMapping.forForgedMethods() : null, - Collections.emptyList(), + Collections.emptyList(), restrictToDefinedMappings ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index 0600b01565..cdbf745604 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -144,8 +144,8 @@ private boolean equals(TypeMirror mirror1, TypeMirror mirror2) { public static SelectionParameters forSourceRHS(SourceRHS sourceRHS) { return new SelectionParameters( - Collections.emptyList(), - Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), null, null, sourceRHS diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index 4bdcf27f90..8b4a28d524 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -20,7 +20,6 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.Extractor; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -214,12 +213,7 @@ private Parameter fetchMatchingParameterFromFirstSegment(String[] segments ) { Strings.join( method.getSourceParameters(), ", ", - new Extractor() { - @Override - public String apply(Parameter parameter) { - return parameter.getName(); - } - } + Parameter::getName ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index ae8cc62fbb..2b6f353d07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.util; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.ServiceLoader; @@ -113,8 +112,8 @@ private static List findAstModifyingAnnotationP AstModifyingAnnotationProcessor.class, AnnotationProcessorContext.class.getClassLoader() ); - for ( Iterator it = loader.iterator(); it.hasNext(); ) { - processors.add( it.next() ); + for ( AstModifyingAnnotationProcessor astModifyingAnnotationProcessor : loader ) { + processors.add( astModifyingAnnotationProcessor ); } return processors; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java index adf927aed0..f394f4e8f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java @@ -84,9 +84,7 @@ private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyCollected, List variablesToAdd) { List safeToAdd = new ArrayList<>( variablesToAdd.size() ); - for ( VariableElement toAdd : variablesToAdd ) { - safeToAdd.add( toAdd ); - } + safeToAdd.addAll( variablesToAdd ); alreadyCollected.addAll( 0, safeToAdd ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 909152b6a0..451e8fe7ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -99,8 +99,7 @@ public Set uses() { } public List imports() { - List imports = new ArrayList<>(); - imports.addAll( mapperPrism.imports() ); + List imports = new ArrayList<>( mapperPrism.imports() ); if ( mapperConfigPrism != null ) { imports.addAll( mapperConfigPrism.imports() ); } @@ -262,7 +261,7 @@ public String componentModel(Options options) { public boolean isDisableSubMappingMethodsGeneration() { if ( mapperPrism.disableSubMappingMethodsGeneration() ) { - return mapperPrism.disableSubMappingMethodsGeneration(); + return true; } if ( mapperConfigPrism != null && mapperConfigPrism.disableSubMappingMethodsGeneration() ) { From 716b85aa2caf0efc00d8e19f997a612d81eee3af Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 11 Aug 2019 19:14:58 +0300 Subject: [PATCH 0370/1006] Simplify conditions in org.mapstruct.ap.internal.model.source --- .../internal/model/source/MappingOptions.java | 22 +++++++------------ .../ap/internal/model/source/Method.java | 2 +- .../internal/model/source/PropertyEntry.java | 5 +---- .../model/source/TargetReference.java | 2 +- .../internal/model/source/ValueMapping.java | 6 ++--- .../selector/CreateOrUpdateSelector.java | 6 ++--- .../selector/XmlElementDeclSelector.java | 14 ++++++------ 7 files changed, 22 insertions(+), 35 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 0b8cf89f6f..228de8e10b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -29,7 +29,7 @@ public class MappingOptions { null, null, null, - Collections.emptyList(), + Collections.emptyList(), false ); private Set mappings; @@ -182,22 +182,16 @@ public void markAsFullyInitialized() { public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse, SourceMethod method ) { MappingOptions inherited = templateMethod.getMappingOptions(); if ( null != inherited ) { - if ( getIterableMapping() == null ) { - if ( inherited.getIterableMapping() != null ) { - setIterableMapping( inherited.getIterableMapping() ); - } + if ( getIterableMapping() == null && inherited.getIterableMapping() != null) { + setIterableMapping( inherited.getIterableMapping() ); } - if ( getMapMapping() == null ) { - if ( inherited.getMapMapping() != null ) { - setMapMapping( inherited.getMapMapping() ); - } + if ( getMapMapping() == null && inherited.getMapMapping() != null) { + setMapMapping( inherited.getMapMapping() ); } - if ( getBeanMapping() == null ) { - if ( inherited.getBeanMapping() != null ) { - setBeanMapping( BeanMapping.forInheritance( inherited.getBeanMapping() ) ); - } + if ( getBeanMapping() == null && inherited.getBeanMapping() != null ) { + setBeanMapping( BeanMapping.forInheritance( inherited.getBeanMapping() ) ); } if ( getValueMappings() == null ) { @@ -206,7 +200,7 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse setValueMappings( inherited.getValueMappings() ); } else { - setValueMappings( Collections.emptyList() ); + setValueMappings( Collections.emptyList() ); } } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 98f27b8334..5ed6f485d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -193,6 +193,6 @@ public interface Method { * to be an update method in order for this to be true. */ default boolean isMappingTargetAssignableToReturnType() { - return isUpdateMethod() ? getResultType().isAssignableTo( getReturnType() ) : false; + return isUpdateMethod() && getResultType().isAssignableTo( getReturnType() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java index 1eb4bc80b2..8f2a6f0bba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java @@ -129,10 +129,7 @@ public boolean equals(Object obj) { return false; } final PropertyEntry other = (PropertyEntry) obj; - if ( !Arrays.deepEquals( this.fullName, other.fullName ) ) { - return false; - } - return true; + return Arrays.deepEquals( this.fullName, other.fullName ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java index 07657406c5..4a25a0e866 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java @@ -94,7 +94,7 @@ public BuilderFromTargetMapping typeFactory(TypeFactory typeFactory) { public TargetReference build() { - boolean isInverse = mapping.getInheritContext() != null ? mapping.getInheritContext().isReversed() : false; + boolean isInverse = mapping.getInheritContext() != null && mapping.getInheritContext().isReversed(); String targetName = mapping.getTargetName(); if ( targetName == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java index b86583496d..12bb863d9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model.source; import java.util.List; +import java.util.Objects; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; @@ -142,9 +143,6 @@ public boolean equals(Object obj) { return false; } final ValueMapping other = (ValueMapping) obj; - if ( (this.source == null) ? (other.source != null) : !this.source.equals( other.source ) ) { - return false; - } - return true; + return Objects.equals( this.source, other.source ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index 166b7396ee..be729220ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -49,10 +49,8 @@ public List> getMatchingMethods(Method mapp updateCandidates.add( method ); } } - if ( criteria.isPreferUpdateMapping() ) { - if ( !updateCandidates.isEmpty() ) { - return updateCandidates; - } + if ( criteria.isPreferUpdateMapping() && !updateCandidates.isEmpty() ) { + return updateCandidates; } return createCandidates; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index ec93bf239b..4f51e91b6a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -62,14 +62,14 @@ public List> getMatchingMethods(Method mapp } SourceMethod candidateMethod = (SourceMethod) candidate.getMethod(); - XmlElementDeclPrism xmlElememtDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() ); + XmlElementDeclPrism xmlElementDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() ); - if ( xmlElememtDecl == null ) { + if ( xmlElementDecl == null ) { continue; } - String name = xmlElememtDecl.name(); - TypeMirror scope = xmlElememtDecl.scope(); + String name = xmlElementDecl.name(); + TypeMirror scope = xmlElementDecl.scope(); boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() ); boolean scopeIsSetAndMatches = @@ -88,13 +88,13 @@ else if ( scopeIsSetAndMatches ) { } } - if ( nameAndScopeMatches.size() > 0 ) { + if ( !nameAndScopeMatches.isEmpty() ) { return nameAndScopeMatches; } - else if ( scopeMatches.size() > 0 ) { + else if ( !scopeMatches.isEmpty() ) { return scopeMatches; } - else if ( nameMatches.size() > 0 ) { + else if ( !nameMatches.isEmpty() ) { return nameMatches; } else { From 66e57b0dfe291094776cce0d008f54e0df20416e Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Tue, 13 Aug 2019 18:44:49 +0200 Subject: [PATCH 0371/1006] #1862 Update @MappingTarget documentation to take builders (#1864) --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index ba9b2119cc..58cc0cfb99 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2726,6 +2726,7 @@ Within those groups, the method invocations are ordered by their location of def *Important:* the order of methods declared within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. +*Important:* when using a builder, the `@AfterMapping` annotated method must have the builder as `@MappingTarget` annotated parameter so that the method is able to modify the object going to be build. The `build` method is called when the `@AfterMapping` annotated method scope finishes. MapStruct will not call the `@AfterMapping` annotated method if the real target is used as `@MappingTarget` annotated parameter. [[using-spi]] == Using the MapStruct SPI From 281b792cf670766d7190cd2df5657db66b19bce0 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 17 Aug 2019 22:07:00 +0300 Subject: [PATCH 0372/1006] Fix minor warnings in test package bugs: remove unnecessary generic type for collections, remove unnecessary exceptions from signature test methods --- .../ap/test/bugs/_1005/Issue1005Test.java | 8 ++--- .../ap/test/bugs/_1061/Issue1061Test.java | 2 +- .../ap/test/bugs/_1131/Issue1131Mapper.java | 4 +-- .../_1131/Issue1131MapperWithContext.java | 6 ++-- .../ap/test/bugs/_1131/Issue1131Test.java | 4 +-- .../ap/test/bugs/_1148/Issue1148Test.java | 14 ++++---- .../ap/test/bugs/_1155/Issue1155Test.java | 2 +- .../test/bugs/_1164/SourceTargetMapper.java | 6 ++-- .../ap/test/bugs/_1170/PetMapper.java | 23 ++++-------- .../ap/test/bugs/_1170/_target/Target.java | 18 +++++----- .../ap/test/bugs/_1170/source/Source.java | 18 +++++----- .../ap/test/bugs/_1255/Issue1255Test.java | 4 +-- .../mapstruct/ap/test/bugs/_1273/Entity.java | 2 +- .../mapstruct/ap/test/bugs/_1338/Source.java | 2 +- .../ap/test/bugs/_1359/Issue1359Test.java | 2 +- .../ap/test/bugs/_1453/AuctionDto.java | 4 +-- .../test/bugs/_1523/java8/Issue1523Test.java | 2 +- .../ap/test/bugs/_1561/NestedTarget.java | 2 +- .../ap/test/bugs/_1596/Issue1596Test.java | 2 +- .../ap/test/bugs/_374/Issue374Test.java | 8 ++--- .../ap/test/bugs/_513/Issue513Test.java | 8 ++--- .../mapstruct/ap/test/bugs/_516/Target.java | 2 +- .../test/bugs/_634/GenericContainerTest.java | 2 +- .../IterableWithBoundedElementTypeTest.java | 4 +-- .../_775/MapperWithCustomListMapping.java | 11 +++--- .../ap/test/bugs/_849/Issue849Test.java | 3 +- .../mapstruct/ap/test/bugs/_849/Target.java | 2 +- .../ap/test/bugs/_865/Issue865Test.java | 5 +-- .../mapstruct/ap/test/bugs/_913/Domain.java | 4 +-- .../test/bugs/_913/DomainWithoutSetter.java | 10 +++--- .../org/mapstruct/ap/test/bugs/_913/Dto.java | 2 +- .../test/bugs/_913/DtoWithPresenceCheck.java | 2 +- ...ssue913SetterMapperForCollectionsTest.java | 36 +++++++++---------- 33 files changed, 106 insertions(+), 118 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index b54479a8e4..7a58d56fb2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -37,7 +37,7 @@ public class Issue1005Test { line = 17, messageRegExp = "The result type .*\\.AbstractEntity may not be an abstract class nor interface.") }) - public void shouldFailDueToAbstractResultType() throws Exception { + public void shouldFailDueToAbstractResultType() { } @WithClasses(Issue1005ErroneousAbstractReturnTypeMapper.class) @@ -50,7 +50,7 @@ public void shouldFailDueToAbstractResultType() throws Exception { messageRegExp = "The return type .*\\.AbstractEntity is an abstract class or interface. Provide a non" + " abstract / non interface result type or a factory method.") }) - public void shouldFailDueToAbstractReturnType() throws Exception { + public void shouldFailDueToAbstractReturnType() { } @WithClasses(Issue1005ErroneousInterfaceResultTypeMapper.class) @@ -62,7 +62,7 @@ public void shouldFailDueToAbstractReturnType() throws Exception { line = 17, messageRegExp = "The result type .*\\.HasPrimaryKey may not be an abstract class nor interface.") }) - public void shouldFailDueToInterfaceResultType() throws Exception { + public void shouldFailDueToInterfaceResultType() { } @WithClasses(Issue1005ErroneousInterfaceReturnTypeMapper.class) @@ -75,6 +75,6 @@ public void shouldFailDueToInterfaceResultType() throws Exception { messageRegExp = "The return type .*\\.HasKey is an abstract class or interface. Provide a non " + "abstract / non interface result type or a factory method.") }) - public void shouldFailDueToInterfaceReturnType() throws Exception { + public void shouldFailDueToInterfaceReturnType() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java index 09c9d066d2..fe0f463c4e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java @@ -20,7 +20,7 @@ public class Issue1061Test { @Test - public void shouldCompile() throws Exception { + public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java index 46fd66f433..0e82c0708b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Mapper.java @@ -20,7 +20,7 @@ public abstract class Issue1131Mapper { public static final Issue1131Mapper INSTANCE = Mappers.getMapper( Issue1131Mapper.class ); - public static final List CALLED_METHODS = new ArrayList(); + public static final List CALLED_METHODS = new ArrayList<>(); public abstract void merge(Source source, @MappingTarget Target target); @@ -40,7 +40,7 @@ protected Target.Nested createWithSource(Source source) { @ObjectFactory protected List createWithSourceList(List source) { CALLED_METHODS.add( "create(List)" ); - List result = new ArrayList(); + List result = new ArrayList<>(); result.add( new Target.Nested( "from createWithSourceList" ) ); return result; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java index 4939e316e8..3f3176b57a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131MapperWithContext.java @@ -22,7 +22,7 @@ public abstract class Issue1131MapperWithContext { public static final Issue1131MapperWithContext INSTANCE = Mappers.getMapper( Issue1131MapperWithContext.class ); public static class MappingContext { - private final List calledMethods = new ArrayList(); + private final List calledMethods = new ArrayList<>(); public Target.Nested create(Source.Nested source) { calledMethods.add( "create(Source.Nested)" ); @@ -32,10 +32,10 @@ public Target.Nested create(Source.Nested source) { public List create(List source) { calledMethods.add( "create(List)" ); if ( source == null ) { - return new ArrayList(); + return new ArrayList<>(); } else { - return new ArrayList( source.size() ); + return new ArrayList<>( source.size() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java index de3a38366e..04cfa25d44 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java @@ -34,7 +34,7 @@ public void shouldUseCreateWithSourceNested() { Source source = new Source(); source.setNested( new Source.Nested() ); source.getNested().setProperty( "something" ); - source.setMoreNested( new ArrayList() ); + source.setMoreNested( new ArrayList<>() ); Target target = new Target(); @@ -55,7 +55,7 @@ public void shouldUseContextObjectFactory() { Source source = new Source(); source.setNested( new Source.Nested() ); source.getNested().setProperty( "something" ); - source.setMoreNested( new ArrayList() ); + source.setMoreNested( new ArrayList<>() ); Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java index 2dc4749b9a..1c6ff15e53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java @@ -25,7 +25,7 @@ public class Issue1148Test { @Test - public void shouldNotUseSameMethodForDifferentMappingsNestedSource() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsNestedSource() { Entity.Dto dto = new Entity.Dto(); dto.nestedDto = new Entity.NestedDto( 30 ); dto.nestedDto2 = new Entity.NestedDto( 40 ); @@ -36,7 +36,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedSource() throws Exce } @Test - public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() { Entity.Dto dto = new Entity.Dto(); dto.recipientId = 10; dto.senderId = 20; @@ -52,7 +52,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() throws Exce } @Test - public void shouldNotUseSameMethodForDifferentMappingsSymmetric() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsSymmetric() { Entity.Dto dto = new Entity.Dto(); dto.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); dto.sameLevel2 = new Entity.ClientDto(new Entity.NestedDto( 40 )); @@ -68,7 +68,7 @@ public void shouldNotUseSameMethodForDifferentMappingsSymmetric() throws Excepti } @Test - public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() { Entity.Dto dto = new Entity.Dto(); dto.level = new Entity.ClientDto(new Entity.NestedDto( 80 )); dto.level2 = new Entity.ClientDto(new Entity.NestedDto( 90 )); @@ -82,7 +82,7 @@ public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() throws Exc } @Test - public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.nestedDto = new Entity.NestedDto( 30 ); Entity.Dto dto2 = new Entity.Dto(); @@ -94,7 +94,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() thr } @Test - public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.recipientId = 10; Entity.Dto dto2 = new Entity.Dto(); @@ -111,7 +111,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() thr } @Test - public void shouldNotUseSameMethodForDifferentMappingsSymmetricMultiple() throws Exception { + public void shouldNotUseSameMethodForDifferentMappingsSymmetricMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); Entity.Dto dto2 = new Entity.Dto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java index a3295fe4df..553323b32b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java @@ -25,7 +25,7 @@ public class Issue1155Test { @Test - public void shouldCompile() throws Exception { + public void shouldCompile() { Entity.Dto dto = new Entity.Dto(); dto.clientId = 10; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java index 41d62c30de..31cb10ba6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/SourceTargetMapper.java @@ -21,14 +21,14 @@ public abstract class SourceTargetMapper { public abstract Target map(Source source); protected List> mapLists(List> lists) { - return new ArrayList>(); + return new ArrayList<>(); } protected Map> map(Map> map) { - return new HashMap>(); + return new HashMap<>(); } protected GenericHolder> map(GenericHolder> genericHolder) { - return new GenericHolder>(); + return new GenericHolder<>(); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java index f76cd4e91b..7dd9ff50a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1170; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.mapstruct.Mapper; @@ -36,8 +36,6 @@ public class PetMapper { * @param pet * * @return - * - * @throws DogException */ public Long toPet(String pet) { return PETS_TO_TARGET.get( pet ); @@ -53,24 +51,17 @@ public String toSourcePets(Long pet) { * @param pets * * @return - * - * @throws CatException - * @throws DogException */ public List toPets(List pets) { - List result = new ArrayList(); - for ( String pet : pets ) { - result.add( toPet( pet ) ); - } - return result; + return pets.stream() + .map( this::toPet ) + .collect( Collectors.toList() ); } public List toSourcePets(List pets) { - List result = new ArrayList(); - for ( Long pet : pets ) { - result.add( PETS_TO_SOURCE.get( pet ) ); - } - return result; + return pets.stream() + .map( PETS_TO_SOURCE::get ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java index 95e0414f2a..5103fb075a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/_target/Target.java @@ -14,23 +14,23 @@ */ public class Target { - private List withoutWildcards = new ArrayList(); + private List withoutWildcards = new ArrayList<>(); - private List wildcardInSources = new ArrayList(); + private List wildcardInSources = new ArrayList<>(); - private List wildcardInTargets = new ArrayList(); + private List wildcardInTargets = new ArrayList<>(); - private List wildcardInBoths = new ArrayList(); + private List wildcardInBoths = new ArrayList<>(); - private List wildcardAdderToSetters = new ArrayList(); + private List wildcardAdderToSetters = new ArrayList<>(); - private List wildcardInSourcesAddAll = new ArrayList(); + private List wildcardInSourcesAddAll = new ArrayList<>(); - private List sameTypeWildcardInSources = new ArrayList(); + private List sameTypeWildcardInSources = new ArrayList<>(); - private List sameTypeWildcardInTargets = new ArrayList(); + private List sameTypeWildcardInTargets = new ArrayList<>(); - private List sameTypeWildcardInBoths = new ArrayList(); + private List sameTypeWildcardInBoths = new ArrayList<>(); public List getWithoutWildcards() { return withoutWildcards; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java index 4226c92455..989ef5f6b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/source/Source.java @@ -14,23 +14,23 @@ */ public class Source { - private List withoutWildcards = new ArrayList(); + private List withoutWildcards = new ArrayList<>(); - private List wildcardInSources = new ArrayList(); + private List wildcardInSources = new ArrayList<>(); - private List wildcardInTargets = new ArrayList(); + private List wildcardInTargets = new ArrayList<>(); - private List wildcardInBoths = new ArrayList(); + private List wildcardInBoths = new ArrayList<>(); - private List wildcardInSourcesAddAll = new ArrayList(); + private List wildcardInSourcesAddAll = new ArrayList<>(); - private List wildcardAdderToSetters = new ArrayList(); + private List wildcardAdderToSetters = new ArrayList<>(); - private List sameTypeWildcardInSources = new ArrayList(); + private List sameTypeWildcardInSources = new ArrayList<>(); - private List sameTypeWildcardInTargets = new ArrayList(); + private List sameTypeWildcardInTargets = new ArrayList<>(); - private List sameTypeWildcardInBoths = new ArrayList(); + private List sameTypeWildcardInBoths = new ArrayList<>(); public List getWithoutWildcards() { return withoutWildcards; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java index a459099000..4168a75b79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java @@ -27,7 +27,7 @@ public class Issue1255Test { @Test - public void shouldMapSomeBToSomeAWithoutField1() throws Exception { + public void shouldMapSomeBToSomeAWithoutField1() { SomeB someB = new SomeB(); someB.setField1( "value1" ); someB.setField2( "value2" ); @@ -41,7 +41,7 @@ public void shouldMapSomeBToSomeAWithoutField1() throws Exception { } @Test - public void shouldMapSomeAToSomeB() throws Exception { + public void shouldMapSomeAToSomeB() { SomeA someA = new SomeA(); someA.setField1( "value1" ); someA.setField2( "value2" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java index ece26b3bdd..fa1c1d47f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Entity.java @@ -10,7 +10,7 @@ public class Entity { - List longs = new ArrayList(); + List longs = new ArrayList<>(); public List getLongs() { return longs; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java index 4717001147..f5157b9690 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Source.java @@ -17,7 +17,7 @@ public class Source { public void addProperty(String property) { if ( properties == null ) { - properties = new ArrayList(); + properties = new ArrayList<>(); } properties.add( property ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java index d81554b8eb..7434afa9fd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java @@ -35,7 +35,7 @@ public void shouldCompile() { Target target = new Target(); assertThat( target ).extracting( "properties" ).contains( null, atIndex( 0 ) ); - Set properties = new HashSet(); + Set properties = new HashSet<>(); properties.add( "first" ); Source source = new Source( properties ); Issue1359Mapper.INSTANCE.map( target, source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java index ef92bc8272..5b8fd42a25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/AuctionDto.java @@ -24,7 +24,7 @@ List takePayments() { } public void setPayments(List payments) { - this.payments = payments == null ? null : new ArrayList( payments ); + this.payments = payments == null ? null : new ArrayList<>( payments ); } List takeOtherPayments() { @@ -40,7 +40,7 @@ public void setOtherPayments(List otherPayments) { } public void setMapPayments(Map mapPayments) { - this.mapPayments = mapPayments == null ? null : new HashMap( mapPayments ); + this.mapPayments = mapPayments == null ? null : new HashMap<>( mapPayments ); } public Map getMapSuperPayments() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java index b922dcc14f..d1f859db6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java @@ -58,7 +58,7 @@ public void testThatCorrectTimeZoneWillBeUsedInTarget() { // default one was explicitly set to UTC, thus +01:00 is a different one source.setValue( ZonedDateTime.parse( "2018-06-15T00:00:00+01:00" ) ); Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT+01:00" ) ); - cal.set( 2018, 02, 15, 00, 00, 00 ); + cal.set( 2018, Calendar.MARCH, 15, 00, 00, 00 ); source.setValue2( cal ); Target target = Issue1523Mapper.INSTANCE.map( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java index a2f1040527..479d91f0e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/NestedTarget.java @@ -14,7 +14,7 @@ */ public class NestedTarget { - private List properties = new ArrayList(); + private List properties = new ArrayList<>(); public Stream getProperties() { return properties.stream(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java index f92648b219..0d75feea03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java @@ -41,7 +41,7 @@ public class Issue1596Test { @Test - public void shouldIncludeBuildeType() { + public void shouldIncludeBuildType() { ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java index 63ed283f17..7c1fa96719 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java @@ -53,7 +53,7 @@ public void shouldMapExistingTargetWithConstantToDefault() { @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingIterableTargetToDefault() { - List targetList = new ArrayList(); + List targetList = new ArrayList<>(); targetList.add( "test" ); List resultList = Issue374Mapper.INSTANCE.mapIterable( null, targetList ); assertThat( resultList ).isEqualTo( targetList ); @@ -64,7 +64,7 @@ public void shouldMapExistingIterableTargetToDefault() { @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingMapTargetToDefault() { - Map targetMap = new HashMap(); + Map targetMap = new HashMap<>(); targetMap.put( 5, "test" ); Map resultMap = Issue374Mapper.INSTANCE.mapMap( null, targetMap ); assertThat( resultMap ).isEmpty(); @@ -85,7 +85,7 @@ public void shouldMapExistingTargetVoidReturnToDefault() { @WithClasses( { Issue374VoidMapper.class, Source.class, Target.class } ) public void shouldMapExistingIterableTargetVoidReturnToDefault() { - List targetList = new ArrayList(); + List targetList = new ArrayList<>(); targetList.add( "test" ); Issue374VoidMapper.INSTANCE.mapIterable( null, targetList ); assertThat( targetList ).isEmpty(); @@ -95,7 +95,7 @@ public void shouldMapExistingIterableTargetVoidReturnToDefault() { @WithClasses( { Issue374VoidMapper.class, Source.class, Target.class } ) public void shouldMapExistingMapTargetVoidReturnToDefault() { - Map targetMap = new HashMap(); + Map targetMap = new HashMap<>(); targetMap.put( 5, "test" ); Issue374VoidMapper.INSTANCE.mapMap( null, targetMap ); assertThat( targetMap ).isEmpty(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java index 90bbcec3c1..0b75d8681e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java @@ -43,7 +43,7 @@ public void shouldThrowMappingException() throws Exception { Source source = new Source(); SourceElement sourceElement = new SourceElement(); sourceElement.setValue( "test" ); - source.setCollection( Arrays.asList( new SourceElement[]{ sourceElement } ) ); + source.setCollection( Arrays.asList( sourceElement ) ); Issue513Mapper.INSTANCE.map( source ); @@ -56,7 +56,7 @@ public void shouldThrowMappingKeyException() throws Exception { SourceKey sourceKey = new SourceKey(); sourceKey.setValue( MappingKeyException.class.getSimpleName() ); SourceValue sourceValue = new SourceValue(); - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put( sourceKey, sourceValue ); source.setMap( map ); @@ -71,7 +71,7 @@ public void shouldThrowMappingValueException() throws Exception { SourceKey sourceKey = new SourceKey(); SourceValue sourceValue = new SourceValue(); sourceValue.setValue( MappingValueException.class.getSimpleName() ); - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put( sourceKey, sourceValue ); source.setMap( map ); @@ -86,7 +86,7 @@ public void shouldThrowMappingCommonException() throws Exception { SourceKey sourceKey = new SourceKey(); SourceValue sourceValue = new SourceValue(); sourceValue.setValue( MappingException.class.getSimpleName() ); - HashMap map = new HashMap(); + HashMap map = new HashMap<>(); map.put( sourceKey, sourceValue ); source.setMap( map ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java index 8bb32e38c0..1b65b0662b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Target.java @@ -26,7 +26,7 @@ public void setElements(List elements) { public void addElement(String element) { if ( elements == null ) { - elements = new ArrayList(); + elements = new ArrayList<>(); } elements.add( element ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java index a9ae5167fc..f16a9e6f6a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java @@ -33,7 +33,7 @@ public class GenericContainerTest { @IssueKey("634") public void canMapGenericSourceTypeToGenericTargetType() { List items = Arrays.asList( new Foo( "42" ), new Foo( "84" ) ); - Source source = new Source( items ); + Source source = new Source<>( items ); Target target = SourceTargetMapper.INSTANCE.mapSourceToTarget( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java index af3d5b4245..a3fe3dacd3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java @@ -44,7 +44,7 @@ public void createsForgedMethodForIterableLowerBoundInteger() { IterableContainer result = MapperWithForgedIterableMapping.INSTANCE.toContainerWithIterable( source ); ( (IterableAssert) assertThat( result.getValues() ) ) - .contains( Integer.valueOf( 42 ), Integer.valueOf( 47 ) ); + .contains( 42, 47 ); } @Test @@ -55,6 +55,6 @@ public void usesListIntegerMethodForIterableLowerBoundInteger() { IterableContainer result = MapperWithCustomListMapping.INSTANCE.toContainerWithIterable( source ); ( (IterableAssert) assertThat( result.getValues() ) ) - .contains( Integer.valueOf( 66 ), Integer.valueOf( 71 ) ); + .contains( 66, 71 ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java index 39e8a5772a..dba7dc2360 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/MapperWithCustomListMapping.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.test.bugs._775; -import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -23,11 +23,8 @@ public abstract class MapperWithCustomListMapping { public abstract IterableContainer toContainerWithIterable(ListContainer source); protected List hexListToIntList(Collection source) { - List iterable = new ArrayList( source.size() ); - for ( String string : source ) { - iterable.add( Integer.parseInt( string, 16 ) ); - } - - return iterable; + return source.stream() + .map( string -> Integer.parseInt( string, 16 ) ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java index 313913286e..5b9e33c353 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java @@ -7,7 +7,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.Serializable; import java.util.Arrays; import org.junit.Test; @@ -29,7 +28,7 @@ public class Issue849Test { public void shouldCompileWithAllImportsDeclared() { Source source = new Source(); - source.setSourceList( Arrays.asList( (Serializable) "test" ) ); + source.setSourceList( Arrays.asList( "test" ) ); Target target = Issue849Mapper.INSTANCE.mapSourceToTarget( source ); assertThat( target.getTargetList() ).containsExactly( "test" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java index b89eac46e5..8bd9e9d17b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Target.java @@ -19,7 +19,7 @@ public class Target { public List getTargetList() { if ( targetList == null ) { - targetList = new ArrayList(); + targetList = new ArrayList<>(); } return targetList; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java index d0be73f9c6..d1352cceb4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java @@ -27,7 +27,7 @@ public class Issue865Test { @Test - public void shouldGenerateNpeCheckBeforCallingAddAllWhenInUpdateMethods() { + public void shouldGenerateNpeCheckBeforeCallingAddAllWhenInUpdateMethods() { ProjectDto dto = new ProjectDto(); dto.setName( "myProject" ); @@ -41,7 +41,8 @@ public void shouldGenerateNpeCheckBeforCallingAddAllWhenInUpdateMethods() { assertThat( entity.getCoreUsers() ).isNull(); } - public void shouldGenerateNpeCheckBeforCallingAddAllWhenInUpdateMethodsAndTargetWithoutSetter() { + @Test + public void shouldGenerateNpeCheckBeforeCallingAddAllWhenInUpdateMethodsAndTargetWithoutSetter() { ProjectDto dto = new ProjectDto(); dto.setName( "myProject" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java index 2eb2e85030..500adf3066 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Domain.java @@ -14,8 +14,8 @@ * @author Sjaak Derksen */ public class Domain { - static final Set DEFAULT_STRINGS = new HashSet(); - static final Set DEFAULT_LONGS = new HashSet(); + static final Set DEFAULT_STRINGS = new HashSet<>(); + static final Set DEFAULT_LONGS = new HashSet<>(); private Set strings = DEFAULT_STRINGS; private Set longs = DEFAULT_LONGS; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java index df821ca182..a808d78737 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DomainWithoutSetter.java @@ -16,11 +16,11 @@ */ public class DomainWithoutSetter { - private final Set strings = new HashSet(); - private final Set longs = new HashSet(); - private final Set stringsInitialized = new HashSet(); - private final Set longsInitialized = new HashSet(); - private final List stringsWithDefault = new ArrayList(); + private final Set strings = new HashSet<>(); + private final Set longs = new HashSet<>(); + private final Set stringsInitialized = new HashSet<>(); + private final Set longsInitialized = new HashSet<>(); + private final List stringsWithDefault = new ArrayList<>(); public Set getStrings() { return strings; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java index dd152beccc..507180bc07 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Dto.java @@ -16,7 +16,7 @@ public class Dto { private List strings; - private List stringsInitialized = new ArrayList( Arrays.asList( "5" ) ); + private List stringsInitialized = new ArrayList<>( Arrays.asList( "5" ) ); private List stringsWithDefault; public List getStrings() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java index 3d55e1ec21..27c262da12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/DtoWithPresenceCheck.java @@ -16,7 +16,7 @@ public class DtoWithPresenceCheck { private List strings; - private List stringsInitialized = new ArrayList( Arrays.asList( "5" ) ); + private List stringsInitialized = new ArrayList<>( Arrays.asList( "5" ) ); private List stringsWithDefault; public boolean hasStrings() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index 29ad1e5bfa..8a3ce7fb64 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -76,8 +76,8 @@ public void shouldReturnNullForNvmsReturnNullForUpdate() { Dto dto = new Dto(); Domain domain = new Domain(); - domain.setLongs( new HashSet() ); - domain.setStrings( new HashSet() ); + domain.setLongs( new HashSet<>() ); + domain.setStrings( new HashSet<>() ); DomainDtoWithNvmsNullMapper.INSTANCE.update( dto, domain ); doControlAsserts( domain ); @@ -100,8 +100,8 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithNonNullTargetAndNullSo Dto dto = new Dto(); dto.setStringsInitialized( null ); Domain domain = new Domain(); - domain.setLongs( new HashSet() ); - domain.setStrings( new HashSet() ); + domain.setLongs( new HashSet<>() ); + domain.setStrings( new HashSet<>() ); DomainDtoWithNvmsNullMapper.INSTANCE.update( dto, domain ); assertThat( domain.getStringsInitialized() ).isNull(); @@ -122,8 +122,8 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { Dto dto = new Dto(); Domain domain1 = new Domain(); - domain1.setLongs( new HashSet() ); - domain1.setStrings( new HashSet() ); + domain1.setLongs( new HashSet<>() ); + domain1.setStrings( new HashSet<>() ); Domain domain2 = DomainDtoWithNvmsNullMapper.INSTANCE.updateWithReturn( dto, domain1 ); doControlAsserts( domain1, domain2 ); @@ -163,10 +163,10 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { Dto dto = new Dto(); Domain domain = new Domain(); - Set longIn = new HashSet(); + Set longIn = new HashSet<>(); longIn.add( 10L ); domain.setLongs( longIn ); - domain.setStrings( new HashSet() ); + domain.setStrings( new HashSet<>() ); DomainDtoWithNvmsDefaultMapper.INSTANCE.update( dto, domain ); doControlAsserts( domain ); @@ -189,10 +189,10 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { Dto dto = new Dto(); Domain domain1 = new Domain(); - Set longIn = new HashSet(); + Set longIn = new HashSet<>(); longIn.add( 10L ); domain1.setLongs( longIn ); - domain1.setStrings( new HashSet() ); + domain1.setStrings( new HashSet<>() ); domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithNvmsDefaultMapper.INSTANCE.updateWithReturn( dto, domain1 ); @@ -234,9 +234,9 @@ public void shouldReturnNullForUpdateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain = new Domain(); - domain.setLongs( new HashSet() ); + domain.setLongs( new HashSet<>() ); domain.getLongs().add( 10L ); - domain.setStrings( new HashSet() ); + domain.setStrings( new HashSet<>() ); domain.getStrings().add( "30" ); DomainDtoWithPresenceCheckMapper.INSTANCE.update( dto, domain ); @@ -257,9 +257,9 @@ public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain1 = new Domain(); - domain1.setLongs( new HashSet() ); + domain1.setLongs( new HashSet<>() ); domain1.getLongs().add( 10L ); - domain1.setStrings( new HashSet() ); + domain1.setStrings( new HashSet<>() ); domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithPresenceCheckMapper.INSTANCE.updateWithReturn( dto, domain1 ); @@ -300,9 +300,9 @@ public void shouldReturnNullForUpdateWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain = new Domain(); - domain.setLongs( new HashSet() ); + domain.setLongs( new HashSet<>() ); domain.getLongs().add( 10L ); - domain.setStrings( new HashSet() ); + domain.setStrings( new HashSet<>() ); domain.getStrings().add( "30" ); DomainDtoWithNcvsAlwaysMapper.INSTANCE.update( dto, domain ); @@ -323,9 +323,9 @@ public void shouldReturnNullForUpdateWithReturnWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); Domain domain1 = new Domain(); - domain1.setLongs( new HashSet() ); + domain1.setLongs( new HashSet<>() ); domain1.getLongs().add( 10L ); - domain1.setStrings( new HashSet() ); + domain1.setStrings( new HashSet<>() ); domain1.getStrings().add( "30" ); Domain domain2 = DomainDtoWithNcvsAlwaysMapper.INSTANCE.updateWithReturn( dto, domain1 ); From dc86d5df45dc2280ee1643312e58e2e8549134b2 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 17 Aug 2019 15:08:00 +0300 Subject: [PATCH 0373/1006] Fix minor warnings in test packages java8stream and nestedbeans: remove unnecessary generic types from collection, remove unnecessary throws from test methods, simplify equals in test dto --- .../test/java8stream/StreamMappingTest.java | 28 +++++++++---------- .../ap/test/java8stream/StringHolder.java | 9 ++---- .../context/StreamWithContextTest.java | 11 ++++---- .../DefaultStreamImplementationTest.java | 7 ++--- .../NoSetterStreamMappingTest.java | 6 ++-- .../defaultimplementation/NoSetterTarget.java | 2 +- .../defaultimplementation/Target.java | 2 +- .../defaultimplementation/TargetFoo.java | 9 ++---- .../StreamToNonIterableMappingTest.java | 4 +-- .../streamtononiterable/StringListMapper.java | 2 +- .../mapstruct/ap/test/nestedbeans/Car.java | 5 ++-- .../mapstruct/ap/test/nestedbeans/CarDto.java | 5 ++-- .../mapstruct/ap/test/nestedbeans/House.java | 6 ++-- .../MultipleForgedMethodsTest.java | 4 +-- .../NestedSimpleBeansMappingTest.java | 12 +++----- .../ap/test/nestedbeans/RoofDto.java | 4 ++- .../mapstruct/ap/test/nestedbeans/User.java | 8 ++++-- .../ap/test/nestedbeans/UserDto.java | 8 ++++-- .../nestedbeans/exceptions/EntityFactory.java | 5 +--- .../nestedbeans/maps/AntonymsDictionary.java | 3 +- .../ap/test/nestedbeans/maps/Word.java | 4 ++- .../ap/test/nestedbeans/maps/WordDto.java | 4 ++- .../multiplecollections/Garage.java | 5 ++-- .../multiplecollections/GarageDto.java | 5 ++-- .../ap/test/nestedbeans/other/RoofDto.java | 4 ++- .../ap/test/nestedbeans/other/UserDto.java | 8 ++++-- 26 files changed, 88 insertions(+), 82 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java index 4fa628502e..a6fa793d57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java @@ -9,9 +9,9 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.EnumSet; import java.util.HashSet; import java.util.Set; +import java.util.stream.Stream; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,7 +55,7 @@ public void shouldReverseMapNullList() { @Test public void shouldMapList() { Source source = new Source(); - source.setStringStream( Arrays.asList( "Bob", "Alice" ).stream() ); + source.setStringStream( Stream.of( "Bob", "Alice" ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -66,7 +66,7 @@ public void shouldMapList() { @Test public void shouldMapListWithoutSetter() { Source source = new Source(); - source.setStringStream2( Arrays.asList( "Bob", "Alice" ).stream() ); + source.setStringStream2( Stream.of( "Bob", "Alice" ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -88,7 +88,7 @@ public void shouldReverseMapList() { @Test public void shouldMapArrayList() { Source source = new Source(); - source.setStringArrayStream( new ArrayList( Arrays.asList( "Bob", "Alice" ) ).stream() ); + source.setStringArrayStream( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -99,7 +99,7 @@ public void shouldMapArrayList() { @Test public void shouldReverseMapArrayList() { Target target = new Target(); - target.setStringArrayList( new ArrayList( Arrays.asList( "Bob", "Alice" ) ) ); + target.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -110,7 +110,7 @@ public void shouldReverseMapArrayList() { @Test public void shouldMapSet() { Source source = new Source(); - source.setStringStreamToSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ).stream() ); + source.setStringStreamToSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -121,7 +121,7 @@ public void shouldMapSet() { @Test public void shouldReverseMapSet() { Target target = new Target(); - target.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -132,7 +132,7 @@ public void shouldReverseMapSet() { @Test public void shouldMapListToCollection() { Source source = new Source(); - source.setIntegerStream( Arrays.asList( 1, 2 ).stream() ); + source.setIntegerStream( Stream.of( 1, 2 ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -154,7 +154,7 @@ public void shouldReverseMapListToCollection() { @Test public void shouldMapIntegerSetToStringSet() { Source source = new Source(); - source.setAnotherIntegerStream( new HashSet( Arrays.asList( 1, 2 ) ).stream() ); + source.setAnotherIntegerStream( new HashSet<>( Arrays.asList( 1, 2 ) ).stream() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -165,7 +165,7 @@ public void shouldMapIntegerSetToStringSet() { @Test public void shouldReverseMapIntegerSetToStringSet() { Target target = new Target(); - target.setAnotherStringSet( new HashSet( Arrays.asList( "1", "2" ) ) ); + target.setAnotherStringSet( new HashSet<>( Arrays.asList( "1", "2" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -176,7 +176,7 @@ public void shouldReverseMapIntegerSetToStringSet() { @Test public void shouldMapSetOfEnumToStringSet() { Source source = new Source(); - source.setColours( EnumSet.of( Colour.BLUE, Colour.GREEN ).stream() ); + source.setColours( Stream.of( Colour.BLUE, Colour.GREEN ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -187,7 +187,7 @@ public void shouldMapSetOfEnumToStringSet() { @Test public void shouldReverseMapSetOfEnumToStringSet() { Target target = new Target(); - target.setColours( new HashSet( Arrays.asList( "BLUE", "GREEN" ) ) ); + target.setColours( new HashSet<>( Arrays.asList( "BLUE", "GREEN" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -198,7 +198,7 @@ public void shouldReverseMapSetOfEnumToStringSet() { @Test public void shouldMapIntegerStreamToNumberSet() { Set numbers = SourceTargetMapper.INSTANCE - .integerStreamToNumberSet( Arrays.asList( 123, 456 ).stream() ); + .integerStreamToNumberSet( Stream.of( 123, 456 ) ); assertThat( numbers ).isNotNull(); assertThat( numbers ).containsOnly( 123, 456 ); @@ -207,7 +207,7 @@ public void shouldMapIntegerStreamToNumberSet() { @Test public void shouldMapNonGenericList() { Source source = new Source(); - source.setStringStream3( new ArrayList( Arrays.asList( "Bob", "Alice" ) ).stream() ); + source.setStringStream3( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java index c82e1d0142..d1fff8cbf5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StringHolder.java @@ -41,13 +41,10 @@ public boolean equals(Object obj) { } StringHolder other = (StringHolder) obj; if ( string == null ) { - if ( other.string != null ) { - return false; - } + return other.string == null; } - else if ( !string.equals( other.string ) ) { - return false; + else { + return string.equals( other.string ); } - return true; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java index 9800ef75df..91c1a41256 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.java8stream.context; -import java.util.Arrays; import java.util.Collection; import java.util.stream.Stream; @@ -26,15 +25,15 @@ public class StreamWithContextTest { @Test - public void shouldApplyAfterMapping() throws Exception { + public void shouldApplyAfterMapping() { Stream stringStream = StreamWithContextMapper.INSTANCE.intStreamToStringStream( - Arrays.asList( 1, 2, 3, 5 ).stream() ); + Stream.of( 1, 2, 3, 5 ) ); assertThat( stringStream ).containsOnly( "1", "2" ); } @Test - public void shouldApplyBeforeMappingOnArray() throws Exception { + public void shouldApplyBeforeMappingOnArray() { Integer[] integers = new Integer[] { 1, 3 }; Stream stringStream = StreamWithContextMapper.INSTANCE.arrayToStream( integers ); @@ -42,9 +41,9 @@ public void shouldApplyBeforeMappingOnArray() throws Exception { } @Test - public void shouldApplyBeforeAndAfterMappingOnCollection() throws Exception { + public void shouldApplyBeforeAndAfterMappingOnCollection() { Collection stringsStream = StreamWithContextMapper.INSTANCE.streamToCollection( - Arrays.asList( 10, 20, 40 ).stream() ); + Stream.of( 10, 20, 40 ) ); assertThat( stringsStream ).containsOnly( "23", "10", "20", "40", "230" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java index 441d3d3a35..ae64592c0e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java @@ -8,7 +8,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -90,7 +89,7 @@ public void shouldUseDefaultImplementationForSortedSet() { @Test public void shouldUseTargetParameterForMapping() { - List target = new ArrayList(); + List target = new ArrayList<>(); SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter( target, createSourceFooStream() @@ -147,7 +146,7 @@ public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() { @Test public void shouldUseAndReturnTargetParameterForMapping() { - List target = new ArrayList(); + List target = new ArrayList<>(); Iterable result = SourceTargetMapper.INSTANCE .sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooStream(), target ); @@ -172,6 +171,6 @@ private void assertResultList(Iterable fooIterable) { } private Stream createSourceFooStream() { - return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) ).stream(); + return Stream.of( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java index 03617607dd..813b9d87e1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java @@ -7,8 +7,8 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.junit.Test; import org.junit.runner.RunWith; @@ -28,7 +28,7 @@ public class NoSetterStreamMappingTest { @Test public void compilesAndMapsCorrectly() { NoSetterSource source = new NoSetterSource(); - source.setListValues( Arrays.asList( "foo", "bar" ).stream() ); + source.setListValues( Stream.of( "foo", "bar" ) ); NoSetterTarget target = NoSetterMapper.INSTANCE.toTarget( source ); @@ -37,7 +37,7 @@ public void compilesAndMapsCorrectly() { // now test existing instances NoSetterSource source2 = new NoSetterSource(); - source2.setListValues( Arrays.asList( "baz" ).stream() ); + source2.setListValues( Stream.of( "baz" ) ); List originalCollectionInstance = target.getListValues(); NoSetterTarget target2 = NoSetterMapper.INSTANCE.toTargetWithExistingTarget( source2, target ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java index 39c7c17cbc..7992012c81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterTarget.java @@ -13,7 +13,7 @@ * */ public class NoSetterTarget { - private List listValues = new ArrayList(); + private List listValues = new ArrayList<>(); public List getListValues() { return listValues; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java index 5168c6b043..2518414731 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/Target.java @@ -14,7 +14,7 @@ public class Target { public List getFooListNoSetter() { if ( fooListNoSetter == null ) { - fooListNoSetter = new ArrayList(); + fooListNoSetter = new ArrayList<>(); } return fooListNoSetter; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java index 0a4061e712..10439fe2b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/TargetFoo.java @@ -45,14 +45,11 @@ public boolean equals(Object obj) { } TargetFoo other = (TargetFoo) obj; if ( name == null ) { - if ( other.name != null ) { - return false; - } + return other.name == null; } - else if ( !name.equals( other.name ) ) { - return false; + else { + return name.equals( other.name ); } - return true; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java index 2e93d1a378..6472ce6db3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Arrays; +import java.util.stream.Stream; import org.junit.Test; import org.junit.runner.RunWith; @@ -23,7 +23,7 @@ public class StreamToNonIterableMappingTest { @Test public void shouldMapStringStreamToStringUsingCustomMapper() { Source source = new Source(); - source.setNames( Arrays.asList( "Alice", "Bob", "Jim" ).stream() ); + source.setNames( Stream.of( "Alice", "Bob", "Jim" ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); assertThat( target ).isNotNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java index d1b6e959f8..f8da66374e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StringListMapper.java @@ -16,6 +16,6 @@ public String stringListToString(Stream strings) { } public Stream stringToStringList(String string) { - return string == null ? null : Arrays.asList( string.split( "-" ) ).stream(); + return string == null ? null : Arrays.stream( string.split( "-" ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java index 25f1d88749..f89a35d830 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/Car.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans; import java.util.List; +import java.util.Objects; public class Car { @@ -60,10 +61,10 @@ public boolean equals(Object o) { if ( year != car.year ) { return false; } - if ( name != null ? !name.equals( car.name ) : car.name != null ) { + if ( !Objects.equals( name, car.name ) ) { return false; } - return wheels != null ? wheels.equals( car.wheels ) : car.wheels == null; + return Objects.equals( wheels, car.wheels ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java index 5bc377c2e8..1eed692016 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/CarDto.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans; import java.util.List; +import java.util.Objects; public class CarDto { @@ -60,10 +61,10 @@ public boolean equals(Object o) { if ( year != carDto.year ) { return false; } - if ( name != null ? !name.equals( carDto.name ) : carDto.name != null ) { + if ( !Objects.equals( name, carDto.name ) ) { return false; } - return wheels != null ? wheels.equals( carDto.wheels ) : carDto.wheels == null; + return Objects.equals( wheels, carDto.wheels ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java index ada8a2b6e7..8badaae653 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/House.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.util.Objects; + public class House { private String name; @@ -60,10 +62,10 @@ public boolean equals(Object o) { if ( year != house.year ) { return false; } - if ( name != null ? !name.equals( house.name ) : house.name != null ) { + if ( !Objects.equals( name, house.name ) ) { return false; } - return roof != null ? roof.equals( house.roof ) : house.roof == null; + return Objects.equals( roof, house.roof ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java index 655b49a310..ecd371d3f6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java @@ -34,8 +34,8 @@ public class MultipleForgedMethodsTest { @Test public void testNestedMapsAutoMap() { - HashMap dtoAntonyms = new HashMap(); - HashMap entityAntonyms = new HashMap(); + HashMap dtoAntonyms = new HashMap<>(); + HashMap entityAntonyms = new HashMap<>(); String[] words = { "black", "good", "up", "left", "fast" }; String[] antonyms = { "white", "bad", "down", "right", "slow" }; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 08c5e2ec17..84d78cdd1c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.test.nestedbeans; import java.util.List; -import java.util.function.Function; import java.util.stream.Collectors; import org.assertj.core.groups.Tuple; @@ -45,7 +44,7 @@ public class NestedSimpleBeansMappingTest { ); @Test - public void shouldHaveAllFields() throws Exception { + public void shouldHaveAllFields() { // If this test fails that means something new was added to the structure of the User/UserDto. // Make sure that the other tests are also updated (the new field is asserted) String[] userFields = new String[] { "name", "car", "secondCar", "house" }; @@ -125,12 +124,9 @@ private static void assertCar(CarDto carDto, Car car) { } private static void assertWheels(List wheelDtos, List wheels) { - List wheelTuples = wheels.stream().map( new Function() { - @Override - public Tuple apply(Wheel wheel) { - return tuple( wheel.isFront(), wheel.isRight() ); - } - } ).collect( Collectors.toList() ); + List wheelTuples = wheels.stream() + .map( wheel -> tuple( wheel.isFront(), wheel.isRight() ) ) + .collect( Collectors.toList() ); assertThat( wheelDtos ) .extracting( "front", "right" ) .containsExactlyElementsOf( wheelTuples ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java index eb5702f0c2..5721d3f6f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RoofDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.util.Objects; + public class RoofDto { private String color; private ExternalRoofType type; @@ -48,7 +50,7 @@ public boolean equals(Object o) { return false; } - return color != null ? color.equals( roofDto.color ) : roofDto.color == null; + return Objects.equals( color, roofDto.color ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java index 48eb94d61b..11ffc5b889 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/User.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.util.Objects; + public class User { private String name; @@ -64,13 +66,13 @@ public boolean equals(Object o) { User user = (User) o; - if ( name != null ? !name.equals( user.name ) : user.name != null ) { + if ( !Objects.equals( name, user.name ) ) { return false; } - if ( car != null ? !car.equals( user.car ) : user.car != null ) { + if ( !Objects.equals( car, user.car ) ) { return false; } - return house != null ? house.equals( user.house ) : user.house == null; + return Objects.equals( house, user.house ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java index 105c84e74b..c496e23529 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/UserDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.util.Objects; + public class UserDto { private String name; @@ -64,13 +66,13 @@ public boolean equals(Object o) { UserDto userDto = (UserDto) o; - if ( name != null ? !name.equals( userDto.name ) : userDto.name != null ) { + if ( !Objects.equals( name, userDto.name ) ) { return false; } - if ( car != null ? !car.equals( userDto.car ) : userDto.car != null ) { + if ( !Objects.equals( car, userDto.car ) ) { return false; } - return house != null ? house.equals( userDto.house ) : userDto.house == null; + return Objects.equals( house, userDto.house ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java index 1276cbfc39..6e0c5fd957 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/EntityFactory.java @@ -21,10 +21,7 @@ public T createEntity(@TargetType Class entityClass) throws MappingExcept try { entity = entityClass.newInstance(); } - catch ( IllegalAccessException exception ) { - throw new MappingException( "Rare exception thrown, refer to stack trace", exception ); - } - catch ( InstantiationException exception ) { + catch ( IllegalAccessException | InstantiationException exception ) { throw new MappingException( "Rare exception thrown, refer to stack trace", exception ); } catch ( Exception exception ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java index bec3c420cd..e0fa0df8da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionary.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans.maps; import java.util.Map; +import java.util.Objects; public class AntonymsDictionary { private Map antonyms; @@ -36,7 +37,7 @@ public boolean equals(Object o) { AntonymsDictionary antonymsDictionary = (AntonymsDictionary) o; - return antonyms != null ? antonyms.equals( antonymsDictionary.antonyms ) : antonymsDictionary.antonyms == null; + return Objects.equals( antonyms, antonymsDictionary.antonyms ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java index 2d25012703..cd4b03114e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/Word.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans.maps; +import java.util.Objects; + public class Word { private String textValue; @@ -34,7 +36,7 @@ public boolean equals(Object o) { Word word = (Word) o; - return textValue != null ? textValue.equals( word.textValue ) : word.textValue == null; + return Objects.equals( textValue, word.textValue ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java index 57a99fd519..d31f025d5d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/WordDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans.maps; +import java.util.Objects; + public class WordDto { private String textValue; @@ -34,7 +36,7 @@ public boolean equals(Object o) { WordDto wordDto = (WordDto) o; - return textValue != null ? textValue.equals( wordDto.textValue ) : wordDto.textValue == null; + return Objects.equals( textValue, wordDto.textValue ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java index c2497e9787..7505aeee13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/Garage.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans.multiplecollections; import java.util.List; +import java.util.Objects; import org.mapstruct.ap.test.nestedbeans.Car; @@ -48,10 +49,10 @@ public boolean equals(Object o) { Garage garage = (Garage) o; - if ( cars != null ? !cars.equals( garage.cars ) : garage.cars != null ) { + if ( !Objects.equals( cars, garage.cars ) ) { return false; } - return usedCars != null ? usedCars.equals( garage.usedCars ) : garage.usedCars == null; + return Objects.equals( usedCars, garage.usedCars ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java index 190a06d280..970c558f64 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/multiplecollections/GarageDto.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans.multiplecollections; import java.util.List; +import java.util.Objects; import org.mapstruct.ap.test.nestedbeans.CarDto; @@ -49,10 +50,10 @@ public boolean equals(Object o) { GarageDto garageDto = (GarageDto) o; - if ( cars != null ? !cars.equals( garageDto.cars ) : garageDto.cars != null ) { + if ( !Objects.equals( cars, garageDto.cars ) ) { return false; } - return usedCars != null ? usedCars.equals( garageDto.usedCars ) : garageDto.usedCars == null; + return Objects.equals( usedCars, garageDto.usedCars ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java index 5382c09a5c..05b984b89d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/RoofDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans.other; +import java.util.Objects; + public class RoofDto { private String color; @@ -34,7 +36,7 @@ public boolean equals(Object o) { RoofDto roofDto = (RoofDto) o; - return color != null ? color.equals( roofDto.color ) : roofDto.color == null; + return Objects.equals( color, roofDto.color ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java index df614fc1ca..eb4529a212 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/UserDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans.other; +import java.util.Objects; + public class UserDto { private String name; @@ -55,13 +57,13 @@ public boolean equals(Object o) { UserDto userDto = (UserDto) o; - if ( name != null ? !name.equals( userDto.name ) : userDto.name != null ) { + if ( !Objects.equals( name, userDto.name ) ) { return false; } - if ( car != null ? !car.equals( userDto.car ) : userDto.car != null ) { + if ( !Objects.equals( car, userDto.car ) ) { return false; } - return house != null ? house.equals( userDto.house ) : userDto.house == null; + return Objects.equals( house, userDto.house ); } From 148466ae3eb4005d4a9f3f2a8d730a47aa16947a Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 17 Aug 2019 00:26:33 +0300 Subject: [PATCH 0374/1006] Fix minor warnings in package test.collection: remove unnecessary generic-type in collections, remove unnecessary exception from signature, replace months numbers on Calendar constants --- .../collection/CollectionMappingTest.java | 37 ++++++++--------- .../ap/test/collection/StringHolder.java | 9 ++-- .../mapstruct/ap/test/collection/Target.java | 4 +- .../ap/test/collection/adder/AdderTest.java | 14 +++---- .../ap/test/collection/adder/PetMapper.java | 4 +- .../test/collection/adder/_target/Target.java | 2 +- .../collection/adder/_target/TargetDali.java | 2 +- .../collection/adder/_target/TargetHuman.java | 4 +- .../adder/_target/TargetOnlyGetter.java | 2 +- .../adder/_target/TargetViaTargetType.java | 2 +- .../adder/_target/TargetWithoutSetter.java | 2 +- .../DefaultCollectionImplementationTest.java | 8 ++-- .../NoSetterCollectionMappingTest.java | 2 +- .../defaultimplementation/Target.java | 2 +- .../defaultimplementation/TargetFoo.java | 9 ++-- .../immutabletarget/ImmutableProductTest.java | 2 +- .../test/collection/map/MapMappingTest.java | 41 ++++++++++--------- .../test/collection/wildcard/BeanMapper.java | 2 +- .../collection/wildcard/WildCardTest.java | 2 +- 19 files changed, 72 insertions(+), 78 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java index 8f752ec497..d67df4a983 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java @@ -113,7 +113,7 @@ public void shouldMapListWithClearAndAddAll() { assertThat( source.getOtherStringList() ).containsExactly( "Bob", "Alice" ); // prepare a test list to monitor add all behaviour - List testList = new TestList(); + List testList = new TestList<>(); testList.addAll( target.getOtherStringList() ); TestList.setAddAllCalled( false ); target.setOtherStringList( testList ); @@ -146,7 +146,7 @@ public void shouldReverseMapListAsCopy() { @IssueKey("6") public void shouldMapArrayList() { Source source = new Source(); - source.setStringArrayList( new ArrayList( Arrays.asList( "Bob", "Alice" ) ) ); + source.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -158,7 +158,7 @@ public void shouldMapArrayList() { @IssueKey("6") public void shouldReverseMapArrayList() { Target target = new Target(); - target.setStringArrayList( new ArrayList( Arrays.asList( "Bob", "Alice" ) ) ); + target.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -170,7 +170,7 @@ public void shouldReverseMapArrayList() { @IssueKey("6") public void shouldMapSet() { Source source = new Source(); - source.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + source.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -182,7 +182,7 @@ public void shouldMapSet() { @IssueKey("6") public void shouldReverseMapSet() { Target target = new Target(); - target.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -194,7 +194,7 @@ public void shouldReverseMapSet() { @IssueKey("6") public void shouldMapSetAsCopy() { Source source = new Source(); - source.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + source.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); target.getStringSet().add( "Bill" ); @@ -206,7 +206,7 @@ public void shouldMapSetAsCopy() { @IssueKey("6") public void shouldMapHashSetAsCopy() { Source source = new Source(); - source.setStringHashSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + source.setStringHashSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); target.getStringHashSet().add( "Bill" ); @@ -218,7 +218,7 @@ public void shouldMapHashSetAsCopy() { @IssueKey("6") public void shouldReverseMapSetAsCopy() { Target target = new Target(); - target.setStringSet( new HashSet( Arrays.asList( "Bob", "Alice" ) ) ); + target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); source.getStringSet().add( "Bill" ); @@ -254,7 +254,7 @@ public void shouldReverseMapListToCollection() { @IssueKey("6") public void shouldMapIntegerSetToRawSet() { Source source = new Source(); - source.setIntegerSet( new HashSet( Arrays.asList( 1, 2 ) ) ); + source.setIntegerSet( new HashSet<>( Arrays.asList( 1, 2 ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -266,7 +266,7 @@ public void shouldMapIntegerSetToRawSet() { @IssueKey("6") public void shouldMapIntegerSetToStringSet() { Source source = new Source(); - source.setAnotherIntegerSet( new HashSet( Arrays.asList( 1, 2 ) ) ); + source.setAnotherIntegerSet( new HashSet<>( Arrays.asList( 1, 2 ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -278,7 +278,7 @@ public void shouldMapIntegerSetToStringSet() { @IssueKey("6") public void shouldReverseMapIntegerSetToStringSet() { Target target = new Target(); - target.setAnotherStringSet( new HashSet( Arrays.asList( "1", "2" ) ) ); + target.setAnotherStringSet( new HashSet<>( Arrays.asList( "1", "2" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -302,7 +302,7 @@ public void shouldMapSetOfEnumToStringSet() { @IssueKey("6") public void shouldReverseMapSetOfEnumToStringSet() { Target target = new Target(); - target.setColours( new HashSet( Arrays.asList( "BLUE", "GREEN" ) ) ); + target.setColours( new HashSet<>( Arrays.asList( "BLUE", "GREEN" ) ) ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -314,7 +314,7 @@ public void shouldReverseMapSetOfEnumToStringSet() { public void shouldMapMapAsCopy() { Source source = new Source(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put( "Bob", 123L ); map.put( "Alice", 456L ); source.setStringLongMap( map ); @@ -331,7 +331,7 @@ public void shouldMapMapAsCopy() { public void shouldMapMapWithClearAndPutAll() { Source source = new Source(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put( "Bob", 123L ); map.put( "Alice", 456L ); source.setOtherStringLongMap( map ); @@ -345,7 +345,7 @@ public void shouldMapMapWithClearAndPutAll() { source.getOtherStringLongMap().remove( "Alice" ); // prepare a test list to monitor add all behaviour - Map originalInstance = new TestMap(); + Map originalInstance = new TestMap<>(); originalInstance.putAll( target.getOtherStringLongMap() ); TestMap.setPuttAllCalled( false ); target.setOtherStringLongMap( originalInstance ); @@ -362,7 +362,7 @@ public void shouldMapMapWithClearAndPutAll() { @IssueKey("87") public void shouldMapIntegerSetToNumberSet() { Set numbers = SourceTargetMapper.INSTANCE - .integerSetToNumberSet( new HashSet( Arrays.asList( 123, 456 ) ) ); + .integerSetToNumberSet( new HashSet<>( Arrays.asList( 123, 456 ) ) ); assertThat( numbers ).isNotNull(); assertThat( numbers ).containsOnly( 123, 456 ); @@ -385,7 +385,7 @@ public void shouldEnumSetAsCopy() { @IssueKey("853") public void shouldMapNonGenericList() { Source source = new Source(); - source.setStringList3( new ArrayList( Arrays.asList( "Bob", "Alice" ) ) ); + source.setStringList3( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -406,12 +406,11 @@ public void shouldMapNonGenericList() { assertThat( mappedSource.getStringList3() ).containsExactly( "Bill", "Bob" ); } - @SuppressWarnings("unchecked") @Test @IssueKey("853") public void shouldMapNonGenericMap() { Source source = new Source(); - Map map = new HashMap(); + Map map = new HashMap<>(); map.put( "Bob", 123L ); map.put( "Alice", 456L ); source.setStringLongMapForNonGeneric( map ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java index 36cb8f38db..af3539ff9e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/StringHolder.java @@ -41,13 +41,10 @@ public boolean equals(Object obj) { } StringHolder other = (StringHolder) obj; if ( string == null ) { - if ( other.string != null ) { - return false; - } + return other.string == null; } - else if ( !string.equals( other.string ) ) { - return false; + else { + return string.equals( other.string ); } - return true; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java index e4e445962f..51a1edddab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java @@ -144,14 +144,14 @@ public void setStringLongMap(Map stringLongMap) { public List getStringListNoSetter() { if ( stringListNoSetter == null ) { - stringListNoSetter = new ArrayList(); + stringListNoSetter = new ArrayList<>(); } return stringListNoSetter; } public List getStringListNoSetter2() { if ( stringListNoSetter2 == null ) { - stringListNoSetter2 = new ArrayList(); + stringListNoSetter2 = new ArrayList<>(); } return stringListNoSetter2; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index 1507f56399..3398a99d79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -117,14 +117,14 @@ public void testAddWithExceptionNotInThrowsClause() throws DogException { @IssueKey("241") @Test - public void testAddwithExistingTarget() throws DogException { + public void testAddWithExistingTarget() { AdderUsageObserver.setUsed( false ); Source source = new Source(); source.setPets( Arrays.asList( "mouse" ) ); Target target = new Target(); - target.setPets( new ArrayList( Arrays.asList( 1L ) ) ); + target.setPets( new ArrayList<>( Arrays.asList( 1L ) ) ); SourceTargetMapper.INSTANCE.toExistingTarget( source, target ); assertThat( target ).isNotNull(); @@ -178,7 +178,7 @@ public void testShouldPreferHumanSingular() { } @Test - public void testshouldFallBackToDaliSingularInAbsenseOfHumanSingular() { + public void testShouldFallBackToDaliSingularInAbsenseOfHumanSingular() { AdderUsageObserver.setUsed( false ); SourceTeeth source = new SourceTeeth(); @@ -192,7 +192,7 @@ public void testshouldFallBackToDaliSingularInAbsenseOfHumanSingular() { } @Test - public void testAddReverse() throws DogException { + public void testAddReverse() { AdderUsageObserver.setUsed( false ); Target source = new Target(); @@ -219,7 +219,7 @@ public void testAddOnlyGetter() throws DogException { } @Test - public void testAddViaTargetType() throws DogException { + public void testAddViaTargetType() { AdderUsageObserver.setUsed( false ); Source source = new Source(); @@ -235,7 +235,7 @@ public void testAddViaTargetType() throws DogException { @IssueKey("242") @Test - public void testSingleElementSource() throws DogException { + public void testSingleElementSource() { AdderUsageObserver.setUsed( false ); SingleElementSource source = new SingleElementSource(); @@ -250,7 +250,7 @@ public void testSingleElementSource() throws DogException { @IssueKey( "310" ) @Test - public void testMissingImport() throws DogException { + public void testMissingImport() { generatedSource.addComparisonToFixtureFor( Source2Target2Mapper.class ); Source2 source = new Source2(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java index 9cb74c7dc9..c2cf92ed6c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java @@ -63,7 +63,7 @@ else if ( "dog".equals( pet ) ) { * @throws DogException */ public List toPets(List pets) throws CatException, DogException { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( String pet : pets ) { result.add( toPet( pet ) ); } @@ -82,7 +82,7 @@ public T toPet(String pet, @TargetType Class clazz) throws Ca } public List toSourcePets(List pets) throws CatException, DogException { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( Long pet : pets ) { result.add( PETS_TO_SOURCE.get( pet ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java index 022d593650..0a112ac216 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java @@ -38,7 +38,7 @@ public void addPets(Long cat) { public Long addPet(Long pet) { AdderUsageObserver.setUsed( true ); if ( pets == null ) { - pets = new ArrayList(); + pets = new ArrayList<>(); } pets.add( pet ); return pet; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java index 3d437b3ab7..30f11f3807 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetDali.java @@ -26,7 +26,7 @@ public void setTeeth(List teeth) { public void addTeeth(Integer tooth) { AdderUsageObserver.setUsed( true ); if ( teeth == null ) { - teeth = new ArrayList(); + teeth = new ArrayList<>(); } teeth.add( tooth ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java index 8117abf2b4..3a2efb9b81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetHuman.java @@ -26,14 +26,14 @@ public void setTeeth(List teeth) { public void addTooth(Integer pet) { AdderUsageObserver.setUsed( true ); if ( teeth == null ) { - teeth = new ArrayList(); + teeth = new ArrayList<>(); } teeth.add( pet ); } public void addTeeth(Integer tooth) { if ( teeth == null ) { - teeth = new ArrayList(); + teeth = new ArrayList<>(); } teeth.add( tooth ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java index 1e21e819ca..09a3bc8e43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java @@ -34,7 +34,7 @@ public void addPets(Long cat) { public void addPet(Long pet) { AdderUsageObserver.setUsed( true ); if ( pets == null ) { - pets = new ArrayList(); + pets = new ArrayList<>(); } pets.add( pet ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java index 0840e0115e..22123aa970 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetViaTargetType.java @@ -26,7 +26,7 @@ public void setPets(List pets) { public void addPet(IndoorPet pet) { AdderUsageObserver.setUsed( true ); if ( pets == null ) { - pets = new ArrayList(); + pets = new ArrayList<>(); } pets.add( pet ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java index 69613854d0..61e670c3a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithoutSetter.java @@ -22,7 +22,7 @@ public List getPets() { public void addPet(Long pet) { AdderUsageObserver.setUsed( true ); if ( pets == null ) { - pets = new ArrayList(); + pets = new ArrayList<>(); } pets.add( pet ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java index b5de8abaab..a6ba036e81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java @@ -128,7 +128,7 @@ public void shouldUseDefaultImplementationForList() { @IssueKey("6") public void shouldUseDefaultImplementationForSet() { Set target = - SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet( createSourceFooList() ) ); + SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet<>( createSourceFooList() ) ); assertResultList( target ); } @@ -145,7 +145,7 @@ public void shouldUseDefaultImplementationForSortedSet() { @Test @IssueKey("19") public void shouldUseTargetParameterForMapping() { - List target = new ArrayList(); + List target = new ArrayList<>(); SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter( target, createSourceFooList() @@ -157,7 +157,7 @@ public void shouldUseTargetParameterForMapping() { @Test @IssueKey("19") public void shouldUseAndReturnTargetParameterForMapping() { - List target = new ArrayList(); + List target = new ArrayList<>(); Iterable result = SourceTargetMapper.INSTANCE .sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooList(), target ); @@ -189,7 +189,7 @@ private void assertResultMap(Map result) { } private Map createSourceFooMap() { - Map map = new HashMap(); + Map map = new HashMap<>(); map.put( 1L, new SourceFoo( "Bob" ) ); map.put( 2L, new SourceFoo( "Alice" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java index 914a5e3f01..1d9747854b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java @@ -32,7 +32,7 @@ public class NoSetterCollectionMappingTest { public void compilesAndMapsCorrectly() { NoSetterSource source = new NoSetterSource(); source.setListValues( Arrays.asList( "foo", "bar" ) ); - HashMap mapValues = new HashMap(); + HashMap mapValues = new HashMap<>(); mapValues.put( "fooKey", "fooVal" ); mapValues.put( "barKey", "barVal" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java index 8a5cc6200c..713865da62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/Target.java @@ -14,7 +14,7 @@ public class Target { public List getFooListNoSetter() { if ( fooListNoSetter == null ) { - fooListNoSetter = new ArrayList(); + fooListNoSetter = new ArrayList<>(); } return fooListNoSetter; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java index da76cc4134..5a843b045c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/TargetFoo.java @@ -45,14 +45,11 @@ public boolean equals(Object obj) { } TargetFoo other = (TargetFoo) obj; if ( name == null ) { - if ( other.name != null ) { - return false; - } + return other.name == null; } - else if ( !name.equals( other.name ) ) { - return false; + else { + return name.equals( other.name ); } - return true; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index f196a1ed98..4c4932e2c4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -34,7 +34,7 @@ public void shouldHandleImmutableTarget() { CupboardDto in = new CupboardDto(); in.setContent( Arrays.asList( "cups", "soucers" ) ); CupboardEntity out = new CupboardEntity(); - out.setContent( Collections.emptyList() ); + out.setContent( Collections.emptyList() ); CupboardMapper.INSTANCE.map( in, out ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index 45ccbb911e..a9a17e5416 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -32,9 +33,9 @@ public class MapMappingTest { @Test public void shouldCreateMapMethodImplementation() { - Map values = new HashMap(); - values.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ); - values.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ); + Map values = new HashMap<>(); + values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); + values.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ); Map target = SourceTargetMapper.INSTANCE.longDateMapToStringStringMap( values ); @@ -60,8 +61,8 @@ public void shouldCreateReverseMapMethodImplementation() { public void shouldCreateMapMethodImplementationWithTargetParameter() { Map values = createStringStringMap(); - Map target = new HashMap(); - target.put( 66L, new GregorianCalendar( 2013, 7, 16 ).getTime() ); + Map target = new HashMap<>(); + target.put( 66L, new GregorianCalendar( 2013, Calendar.AUGUST, 16 ).getTime() ); SourceTargetMapper.INSTANCE.stringStringMapToLongDateMapUsingTargetParameter( target, values ); @@ -73,8 +74,8 @@ public void shouldCreateMapMethodImplementationWithTargetParameter() { public void shouldCreateMapMethodImplementationWithReturnedTargetParameter() { Map values = createStringStringMap(); - Map target = new HashMap(); - target.put( 66L, new GregorianCalendar( 2013, 7, 16 ).getTime() ); + Map target = new HashMap<>(); + target.put( 66L, new GregorianCalendar( 2013, Calendar.AUGUST, 16 ).getTime() ); Map returnedTarget = SourceTargetMapper.INSTANCE .stringStringMapToLongDateMapUsingTargetParameterAndReturn( values, target ); @@ -88,13 +89,13 @@ private void assertResult(Map target) { assertThat( target ).isNotNull(); assertThat( target ).hasSize( 2 ); assertThat( target ).contains( - entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ), - entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ) + entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ), + entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ) ); } private Map createStringStringMap() { - Map values = new HashMap(); + Map values = new HashMap<>(); values.put( "42", "01.01.1980" ); values.put( "121", "20.07.2013" ); return values; @@ -102,13 +103,13 @@ private Map createStringStringMap() { @Test public void shouldInvokeMapMethodImplementationForMapTypedProperty() { - Map values = new HashMap(); - values.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ); - values.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ); + Map values = new HashMap<>(); + values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); + values.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ); Source source = new Source(); source.setValues( values ); - source.setPublicValues( new HashMap( values ) ); + source.setPublicValues( new HashMap<>( values ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -135,7 +136,7 @@ public void shouldInvokeReverseMapMethodImplementationForMapTypedProperty() { Target target = new Target(); target.setValues( values ); - target.publicValues = new HashMap( values ); + target.publicValues = new HashMap<>( values ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -143,21 +144,21 @@ public void shouldInvokeReverseMapMethodImplementationForMapTypedProperty() { assertThat( source.getValues() ).isNotNull(); assertThat( source.getValues() ).hasSize( 2 ); assertThat( source.getValues() ).contains( - entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ), - entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ) + entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ), + entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ) ); assertThat( source.getPublicValues() ) .isNotNull() .hasSize( 2 ) .contains( - entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ), - entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ) + entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ), + entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ) ); } private Map createIntIntMap() { - Map values = new HashMap(); + Map values = new HashMap<>(); values.put( 42, 47 ); values.put( 121, 123 ); return values; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java index 146c876871..0fd26e11fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/BeanMapper.java @@ -29,7 +29,7 @@ BigDecimal map(JAXBElement value) { } JAXBElement map(BigDecimal value) { - return new JAXBElement( new QName( "test" ), BigDecimal.class, value ); + return new JAXBElement<>( new QName( "test" ), BigDecimal.class, value ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index 3e6da19cb8..4f5c161a20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -140,7 +140,7 @@ public void shouldFailOnTypeVarTarget() { public void shouldMapBean() { GoodIdea aGoodIdea = new GoodIdea(); - aGoodIdea.setContent( new JAXBElement( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); + aGoodIdea.setContent( new JAXBElement<>( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) ); aGoodIdea.setDescription( BigDecimal.ZERO ); CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea ); From 1ee59fd123102f479763c975ff80f7203a27d0b5 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 17 Aug 2019 00:44:29 +0300 Subject: [PATCH 0375/1006] Fix minor warnings in tests, packages internal, spi and some others packages: remove unnecessary generic-type in collections, simplify conditions, remove unnecessary exception from signature, replace months numbers on Calendar constants --- .../model/source/SelectionParametersTest.java | 32 +++++----- .../ap/internal/util/NativeTypesTest.java | 2 +- .../ap/internal/util/StringsTest.java | 24 ++++---- .../ap/spi/util/IntrospectorUtilsTest.java | 2 +- .../AbstractReferencedMapper.java | 6 +- .../ap/test/abstractclass/Source.java | 2 +- .../ap/test/array/ArrayMappingTest.java | 38 ++++++------ .../ap/test/builtin/BuiltInTest.java | 38 ++++++------ .../ap/test/callbacks/CallbackMethodTest.java | 14 ++--- .../ap/test/callbacks/Invocation.java | 9 +-- .../mapstruct/ap/test/callbacks/Source.java | 9 +-- .../mapstruct/ap/test/callbacks/Target.java | 9 +-- .../CompanyMapperPostProcessing.java | 6 +- .../MappingResultPostprocessorTest.java | 2 +- .../CallbacksWithReturnValuesTest.java | 2 +- .../ap/test/complex/CarMapperTest.java | 59 ++++++++++-------- .../org/mapstruct/ap/test/context/Node.java | 4 +- .../context/SelfContainingCycleContext.java | 2 +- .../conversion/date/DateConversionTest.java | 60 ++++++++++--------- .../nativetypes/CharConversionTest.java | 2 +- .../ap/test/decorator/DecoratorTest.java | 8 +-- .../decorator/jsr330/Jsr330DecoratorTest.java | 2 +- .../constructor/SpringDecoratorTest.java | 2 +- .../spring/field/SpringDecoratorTest.java | 2 +- 24 files changed, 167 insertions(+), 169 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java index 7eb34135a5..7f57ae75cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java @@ -174,7 +174,7 @@ public TypeMirror asMemberOf(DeclaredType containing, Element element) { public void testGetters() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); @@ -226,7 +226,7 @@ public void testHashCodeWithNullResultType() { public void testEqualsSameInstance() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); @@ -238,7 +238,7 @@ public void testEqualsSameInstance() { public void testEqualsWitNull() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); @@ -250,7 +250,7 @@ public void testEqualsWitNull() { public void testEqualsQualifiersOneNull() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); @@ -264,12 +264,12 @@ public void testEqualsQualifiersOneNull() { public void testEqualsQualifiersInDifferentOrder() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames, resultType, typeUtils ); @@ -282,12 +282,12 @@ public void testEqualsQualifiersInDifferentOrder() { public void testEqualsQualifyingNamesOneNull() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, null, resultType, typeUtils ); @@ -300,13 +300,13 @@ public void testEqualsQualifyingNamesOneNull() { public void testEqualsQualifyingNamesInDifferentOrder() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); List qualifyingNames2 = Arrays.asList( "german", "language" ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType, typeUtils ); @@ -319,13 +319,13 @@ public void testEqualsQualifyingNamesInDifferentOrder() { public void testEqualsResultTypeOneNull() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); List qualifyingNames2 = Arrays.asList( "language", "german" ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, null, typeUtils ); @@ -338,14 +338,14 @@ public void testEqualsResultTypeOneNull() { public void testAllEqual() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); List qualifyingNames2 = Arrays.asList( "language", "german" ); TypeMirror resultType2 = new TestTypeMirror( "resultType" ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType2, typeUtils ); @@ -358,14 +358,14 @@ public void testAllEqual() { public void testDifferentResultTypes() { List qualifyingNames = Arrays.asList( "language", "german" ); TypeMirror resultType = new TestTypeMirror( "resultType" ); - List qualifiers = new ArrayList(); + List qualifiers = new ArrayList<>(); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params = new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); List qualifyingNames2 = Arrays.asList( "language", "german" ); TypeMirror resultType2 = new TestTypeMirror( "otherResultType" ); - List qualifiers2 = new ArrayList(); + List qualifiers2 = new ArrayList<>(); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeType" ) ); qualifiers2.add( new TestTypeMirror( "org.mapstruct.test.SomeOtherType" ) ); SelectionParameters params2 = new SelectionParameters( qualifiers2, qualifyingNames2, resultType2, typeUtils ); diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java index 36f92af6bc..74272cbae3 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java @@ -19,7 +19,7 @@ public class NativeTypesTest { @Test - public void testIsNumber() throws Exception { + public void testIsNumber() { assertFalse( NativeTypes.isNumber( null ) ); assertFalse( NativeTypes.isNumber( Object.class ) ); assertFalse( NativeTypes.isNumber( String.class ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index b21db49a3e..ced598330d 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -34,7 +34,7 @@ public void after() { } @Test - public void testCapitalize() throws Exception { + public void testCapitalize() { assertThat( Strings.capitalize( null ) ).isNull(); assertThat( Strings.capitalize( "c" ) ).isEqualTo( "C" ); assertThat( Strings.capitalize( "capitalize" ) ).isEqualTo( "Capitalize" ); @@ -43,7 +43,7 @@ public void testCapitalize() throws Exception { } @Test - public void testDecapitalize() throws Exception { + public void testDecapitalize() { assertThat( Strings.decapitalize( null ) ).isNull(); assertThat( Strings.decapitalize( "c" ) ).isEqualTo( "c" ); assertThat( Strings.decapitalize( "capitalize" ) ).isEqualTo( "capitalize" ); @@ -52,14 +52,14 @@ public void testDecapitalize() throws Exception { } @Test - public void testJoin() throws Exception { + public void testJoin() { assertThat( Strings.join( new ArrayList(), "-" ) ).isEqualTo( "" ); assertThat( Strings.join( Arrays.asList( "Hello", "World" ), "-" ) ).isEqualTo( "Hello-World" ); assertThat( Strings.join( Arrays.asList( "Hello" ), "-" ) ).isEqualTo( "Hello" ); } @Test - public void testJoinAndCamelize() throws Exception { + public void testJoinAndCamelize() { assertThat( Strings.joinAndCamelize( new ArrayList() ) ).isEqualTo( "" ); assertThat( Strings.joinAndCamelize( Arrays.asList( "Hello", "World" ) ) ).isEqualTo( "HelloWorld" ); assertThat( Strings.joinAndCamelize( Arrays.asList( "Hello", "world" ) ) ).isEqualTo( "HelloWorld" ); @@ -67,7 +67,7 @@ public void testJoinAndCamelize() throws Exception { } @Test - public void testIsEmpty() throws Exception { + public void testIsEmpty() { assertThat( Strings.isEmpty( null ) ).isTrue(); assertThat( Strings.isEmpty( "" ) ).isTrue(); assertThat( Strings.isEmpty( " " ) ).isFalse(); @@ -75,7 +75,7 @@ public void testIsEmpty() throws Exception { } @Test - public void testGetSaveVariableNameWithArrayExistingVariables() throws Exception { + public void testGetSaveVariableNameWithArrayExistingVariables() { assertThat( Strings.getSafeVariableName( "int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.getSafeVariableName( "Extends" ) ).isEqualTo( "extends1" ); assertThat( Strings.getSafeVariableName( "class" ) ).isEqualTo( "class1" ); @@ -86,28 +86,28 @@ public void testGetSaveVariableNameWithArrayExistingVariables() throws Exception } @Test - public void testGetSaveVariableNameVariablesEndingOnNumberVariables() throws Exception { + public void testGetSaveVariableNameVariablesEndingOnNumberVariables() { assertThat( Strings.getSafeVariableName( "prop1", "prop1" ) ).isEqualTo( "prop1_1" ); assertThat( Strings.getSafeVariableName( "prop1", "prop1", "prop1_1" ) ).isEqualTo( "prop1_2" ); } @Test - public void testGetSaveVariableNameWithCollection() throws Exception { - assertThat( Strings.getSafeVariableName( "int[]", new ArrayList() ) ).isEqualTo( "intArray" ); - assertThat( Strings.getSafeVariableName( "Extends", new ArrayList() ) ).isEqualTo( "extends1" ); + public void testGetSaveVariableNameWithCollection() { + assertThat( Strings.getSafeVariableName( "int[]", new ArrayList<>() ) ).isEqualTo( "intArray" ); + assertThat( Strings.getSafeVariableName( "Extends", new ArrayList<>() ) ).isEqualTo( "extends1" ); assertThat( Strings.getSafeVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); assertThat( Strings.getSafeVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) .isEqualTo( "propFont1" ); } @Test - public void testSanitizeIdentifierName() throws Exception { + public void testSanitizeIdentifierName() { assertThat( Strings.sanitizeIdentifierName( "test" ) ).isEqualTo( "test" ); assertThat( Strings.sanitizeIdentifierName( "int[]" ) ).isEqualTo( "intArray" ); } @Test - public void findMostSimilarWord() throws Exception { + public void findMostSimilarWord() { String mostSimilarWord = Strings.getMostSimilarWord( "fulName", Arrays.asList( "fullAge", "fullName", "address", "status" ) diff --git a/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java index 02c171e63e..7114f7b9f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java @@ -15,7 +15,7 @@ public class IntrospectorUtilsTest { @Test - public void testDecapitalize() throws Exception { + public void testDecapitalize() { assertThat( IntrospectorUtils.decapitalize( null ) ).isNull(); assertThat( IntrospectorUtils.decapitalize( "" ) ).isEqualTo( "" ); assertThat( IntrospectorUtils.decapitalize( "URL" ) ).isEqualTo( "URL" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java index 0bde73c975..8fd8ab0ef4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractReferencedMapper.java @@ -16,11 +16,7 @@ public int holderToInt(Holder holder) { } public boolean objectToBoolean(Object obj) { - if ( obj instanceof String ) { - return true; - } - - return false; + return obj instanceof String; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java index f13efc9785..703bc7daf1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/Source.java @@ -15,7 +15,7 @@ public class Source extends AbstractDto implements HasId, AlsoHasId { private final int size; private final Calendar birthday; private final String notAttractingEqualsMethod = "no way"; - private final Holder manuallyConverted = new Holder( "What is the answer?" ); + private final Holder manuallyConverted = new Holder<>( "What is the answer?" ); public Source() { publicSize = 191; diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index 221bc361a8..39adff4eb7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -140,7 +140,7 @@ public void shouldMapTargetToNullWhenNullSource() { @IssueKey("534") @Test - public void shouldMapbooleanWhenReturnDefault() { + public void shouldMapBooleanWhenReturnDefault() { boolean[] existingTarget = new boolean[]{true}; boolean[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -152,7 +152,7 @@ public void shouldMapbooleanWhenReturnDefault() { } @Test - public void shouldMapshortWhenReturnDefault() { + public void shouldMapShortWhenReturnDefault() { short[] existingTarget = new short[]{ 5 }; short[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -161,7 +161,7 @@ public void shouldMapshortWhenReturnDefault() { } @Test - public void shouldMapcharWhenReturnDefault() { + public void shouldMapCharWhenReturnDefault() { char[] existingTarget = new char[]{ 'a' }; char[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -170,53 +170,53 @@ public void shouldMapcharWhenReturnDefault() { } @Test - public void shouldMapintWhenReturnDefault() { + public void shouldMapIntWhenReturnDefault() { int[] existingTarget = new int[]{ 5 }; int[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); - assertThat( target ).containsOnly( new int[] { 0 } ); - assertThat( existingTarget ).containsOnly( new int[] { 0 } ); + assertThat( target ).containsOnly( 0 ); + assertThat( existingTarget ).containsOnly( 0 ); } @Test - public void shouldMaplongWhenReturnDefault() { + public void shouldMapLongWhenReturnDefault() { long[] existingTarget = new long[]{ 5L }; long[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); - assertThat( target ).containsOnly( new long[] { 0L } ); - assertThat( existingTarget ).containsOnly( new long[] { 0L } ); + assertThat( target ).containsOnly( 0L ); + assertThat( existingTarget ).containsOnly( 0L ); } @Test - public void shouldMapfloatWhenReturnDefault() { + public void shouldMapFloatWhenReturnDefault() { float[] existingTarget = new float[]{ 3.1f }; float[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); - assertThat( target ).containsOnly( new float[] { 0.0f } ); - assertThat( existingTarget ).containsOnly( new float[] { 0.0f } ); + assertThat( target ).containsOnly( 0.0f ); + assertThat( existingTarget ).containsOnly( 0.0f ); } @Test - public void shouldMapdoubleWhenReturnDefault() { + public void shouldMapDoubleWhenReturnDefault() { double[] existingTarget = new double[]{ 5.0d }; double[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); - assertThat( target ).containsOnly( new double[] { 0.0d } ); - assertThat( existingTarget ).containsOnly( new double[] { 0.0d } ); + assertThat( target ).containsOnly( 0.0d ); + assertThat( existingTarget ).containsOnly( 0.0d ); } @Test - public void shouldVoidMapintWhenReturnNull() { + public void shouldVoidMapIntWhenReturnNull() { long[] existingTarget = new long[]{ 5L }; ScienceMapper.INSTANCE.nvmMappingVoidReturnNull( null, existingTarget ); - assertThat( existingTarget ).containsOnly( new long[] { 5L } ); + assertThat( existingTarget ).containsOnly( 5L ); } @Test - public void shouldVoidMapintWhenReturnDefault() { + public void shouldVoidMapIntWhenReturnDefault() { long[] existingTarget = new long[]{ 5L }; ScienceMapper.INSTANCE.nvmMappingVoidReturnDefault( null, existingTarget ); - assertThat( existingTarget ).containsOnly( new long[] { 0L } ); + assertThat( existingTarget ).containsOnly( 0L ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index d5e2de5b64..a16cb26ee6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -145,7 +145,7 @@ public void shouldApplyBuiltInOnJAXBElementExtra() { @Test @WithClasses( JaxbListMapper.class ) @IssueKey( "141" ) - public void shouldApplyBuiltInOnJAXBElementList() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnJAXBElementList() { JaxbElementListProperty source = new JaxbElementListProperty(); source.setProp( createJaxbList( "TEST2" ) ); @@ -159,7 +159,7 @@ public void shouldApplyBuiltInOnJAXBElementList() throws ParseException, Datatyp @Test @WithClasses( DateToXmlGregCalMapper.class ) - public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException { DateProperty source = new DateProperty(); source.setProp( createDate( "31-08-1982 10:20:56" ) ); @@ -175,7 +175,7 @@ public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException, Dataty @Test @WithClasses( XmlGregCalToDateMapper.class ) - public void shouldApplyBuiltInOnXmlGregCalToDate() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnXmlGregCalToDate() throws DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); source.setProp( createXmlCal( 1999, 3, 2, 60 ) ); @@ -192,7 +192,7 @@ public void shouldApplyBuiltInOnXmlGregCalToDate() throws ParseException, Dataty @Test @WithClasses( StringToXmlGregCalMapper.class ) - public void shouldApplyBuiltInStringToXmlGregCal() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInStringToXmlGregCal() { StringProperty source = new StringProperty(); source.setProp( "05.07.1999" ); @@ -227,7 +227,7 @@ public void shouldApplyBuiltInStringToXmlGregCal() throws ParseException, Dataty @Test @WithClasses( XmlGregCalToStringMapper.class ) - public void shouldApplyBuiltInXmlGregCalToString() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInXmlGregCalToString() throws DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); source.setProp( createXmlCal( 1999, 3, 2, 60 ) ); @@ -254,7 +254,7 @@ public void shouldApplyBuiltInXmlGregCalToString() throws ParseException, Dataty @Test @WithClasses( CalendarToXmlGregCalMapper.class ) - public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException { CalendarProperty source = new CalendarProperty(); source.setProp( createCalendar( "02.03.1999" ) ); @@ -270,7 +270,7 @@ public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException, Da @Test @WithClasses( XmlGregCalToCalendarMapper.class ) - public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws DatatypeConfigurationException { XmlGregorianCalendarProperty source = new XmlGregorianCalendarProperty(); source.setProp( createXmlCal( 1999, 3, 2, 60 ) ); @@ -288,7 +288,7 @@ public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws ParseException, Da @Test @WithClasses( CalendarToDateMapper.class ) - public void shouldApplyBuiltInOnCalendarToDate() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnCalendarToDate() throws ParseException { CalendarProperty source = new CalendarProperty(); source.setProp( createCalendar( "02.03.1999" ) ); @@ -304,7 +304,7 @@ public void shouldApplyBuiltInOnCalendarToDate() throws ParseException, Datatype @Test @WithClasses( DateToCalendarMapper.class ) - public void shouldApplyBuiltInOnDateToCalendar() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnDateToCalendar() throws ParseException { DateProperty source = new DateProperty(); source.setProp( new SimpleDateFormat( "dd.MM.yyyy" ).parse( "02.03.1999" ) ); @@ -321,7 +321,7 @@ public void shouldApplyBuiltInOnDateToCalendar() throws ParseException, Datatype @Test @WithClasses( CalendarToStringMapper.class ) - public void shouldApplyBuiltInOnCalendarToString() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnCalendarToString() throws ParseException { CalendarProperty source = new CalendarProperty(); source.setProp( createCalendar( "02.03.1999" ) ); @@ -337,7 +337,7 @@ public void shouldApplyBuiltInOnCalendarToString() throws ParseException, Dataty @Test @WithClasses( StringToCalendarMapper.class ) - public void shouldApplyBuiltInOnStringToCalendar() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnStringToCalendar() throws ParseException { StringProperty source = new StringProperty(); source.setProp( "02.03.1999" ); @@ -354,11 +354,11 @@ public void shouldApplyBuiltInOnStringToCalendar() throws ParseException, Dataty @Test @WithClasses( IterableSourceTargetMapper.class ) - public void shouldApplyBuiltInOnIterable() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnIterable() throws DatatypeConfigurationException { IterableSource source = new IterableSource(); - source.setDates( Arrays.asList( new XMLGregorianCalendar[] { createXmlCal( 1999, 3, 2, 60 ) } ) ); - source.publicDates = Arrays.asList( new XMLGregorianCalendar[] { createXmlCal( 2016, 3, 2, 60 ) } ); + source.setDates( Arrays.asList( createXmlCal( 1999, 3, 2, 60 ) ) ); + source.publicDates = Arrays.asList( createXmlCal( 2016, 3, 2, 60 ) ); IterableTarget target = IterableSourceTargetMapper.INSTANCE.sourceToTarget( source ); assertThat( target ).isNotNull(); @@ -368,12 +368,12 @@ public void shouldApplyBuiltInOnIterable() throws ParseException, DatatypeConfig @Test @WithClasses( MapSourceTargetMapper.class ) - public void shouldApplyBuiltInOnMap() throws ParseException, DatatypeConfigurationException { + public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException { MapSource source = new MapSource(); - source.setExample( new HashMap, XMLGregorianCalendar>() ); + source.setExample( new HashMap<>() ); source.getExample().put( createJaxb( "TEST" ), createXmlCal( 1999, 3, 2, 60 ) ); - source.publicExample = new HashMap, XMLGregorianCalendar>(); + source.publicExample = new HashMap<>(); source.publicExample.put( createJaxb( "TEST" ), createXmlCal( 2016, 3, 2, 60 ) ); MapTarget target = MapSourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -417,11 +417,11 @@ public void shouldApplyBuiltInOnZonedDateTimeToCalendar() throws ParseException } private JAXBElement createJaxb(String test) { - return new JAXBElement( new QName( "www.mapstruct.org", "test" ), String.class, test ); + return new JAXBElement<>( new QName( "www.mapstruct.org", "test" ), String.class, test ); } private List> createJaxbList(String test) { - List> result = new ArrayList>(); + List> result = new ArrayList<>(); result.add( createJaxb( test ) ); return result; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java index 91a84655fa..e4f363d4c3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java @@ -68,7 +68,7 @@ public void callbackMethodsForIterableMappingCalled() { @Test public void callbackMethodsForIterableMappingWithResultParamCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( - Arrays.asList( createSource() ), new ArrayList() ); + Arrays.asList( createSource() ), new ArrayList<>() ); assertIterableMappingInvocations( ClassContainingCallbacks.getInvocations() ); assertIterableMappingInvocations( BaseMapper.getInvocations() ); @@ -86,7 +86,7 @@ public void callbackMethodsForMapMappingCalled() { public void callbackMethodsForMapMappingWithResultParamCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( toMap( "foo", createSource() ), - new HashMap() ); + new HashMap<>() ); assertMapMappingInvocations( ClassContainingCallbacks.getInvocations() ); assertMapMappingInvocations( BaseMapper.getInvocations() ); @@ -173,7 +173,7 @@ private void assertMapMappingInvocations(List invocations) { } private Map toMap(String string, T value) { - Map result = new HashMap(); + Map result = new HashMap<>(); result.put( string, value ); return result; } @@ -191,7 +191,7 @@ private void assertCollectionMappingInvocations(List invocations, Ob } private List beanMappingInvocationList(Object source, Object target, Object emptyTarget) { - List invocations = new ArrayList(); + List invocations = new ArrayList<>(); invocations.addAll( allBeforeMappingMethods( source, emptyTarget, Target.class ) ); invocations.addAll( allAfterMappingMethods( source, target, Target.class ) ); @@ -200,7 +200,7 @@ private List beanMappingInvocationList(Object source, Object target, } private List allAfterMappingMethods(Object source, Object target, Class targetClass) { - return new ArrayList( Arrays.asList( + return new ArrayList<>( Arrays.asList( new Invocation( "noArgsAfterMapping" ), new Invocation( "withSourceAfterMapping", source ), new Invocation( "withSourceAsObjectAfterMapping", source ), @@ -211,7 +211,7 @@ private List allAfterMappingMethods(Object source, Object target, Cl } private List allBeforeMappingMethods(Object source, Object emptyTarget, Class targetClass) { - return new ArrayList( Arrays.asList( + return new ArrayList<>( Arrays.asList( new Invocation( "noArgsBeforeMapping" ), new Invocation( "withSourceBeforeMapping", source ), new Invocation( "withSourceAsObjectBeforeMapping", source ), @@ -226,7 +226,7 @@ private void assertQualifiedInvocations(List actual, Object source, } private List allQualifiedCallbackMethods(Object source, Object target) { - List invocations = new ArrayList(); + List invocations = new ArrayList<>(); invocations.add( new Invocation( "withSourceBeforeMappingQualified", source ) ); if ( source instanceof List || source instanceof Map ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java index e408852a0c..42d321af7c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Invocation.java @@ -62,13 +62,10 @@ else if ( !arguments.equals( other.arguments ) ) { return false; } if ( methodName == null ) { - if ( other.methodName != null ) { - return false; - } + return other.methodName == null; } - else if ( !methodName.equals( other.methodName ) ) { - return false; + else { + return methodName.equals( other.methodName ); } - return true; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java index 7194ecc2a4..69d91af39d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Source.java @@ -40,14 +40,11 @@ public boolean equals(Object obj) { } Source other = (Source) obj; if ( foo == null ) { - if ( other.foo != null ) { - return false; - } + return other.foo == null; } - else if ( !foo.equals( other.foo ) ) { - return false; + else { + return foo.equals( other.foo ); } - return true; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java index 90edbe462f..d800bfbcdc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/Target.java @@ -40,14 +40,11 @@ public boolean equals(Object obj) { } Target other = (Target) obj; if ( foo == null ) { - if ( other.foo != null ) { - return false; - } + return other.foo == null; } - else if ( !foo.equals( other.foo ) ) { - return false; + else { + return foo.equals( other.foo ); } - return true; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java index dd18e48aa6..bb7f08a836 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/CompanyMapperPostProcessing.java @@ -17,9 +17,9 @@ public class CompanyMapperPostProcessing { @AfterMapping public void toAddressDto(Address address, @MappingTarget AddressDto addressDto) { String addressLine = address.getAddressLine(); - int seperatorIndex = addressLine.indexOf( ";" ); - addressDto.setStreet( addressLine.substring( 0, seperatorIndex ) ); - String houseNumber = addressLine.substring( seperatorIndex + 1, addressLine.length() ); + int separatorIndex = addressLine.indexOf( ";" ); + addressDto.setStreet( addressLine.substring( 0, separatorIndex ) ); + String houseNumber = addressLine.substring( separatorIndex + 1 ); addressDto.setHouseNumber( Integer.parseInt( houseNumber ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java index 19feaefda2..2927108002 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java @@ -44,7 +44,7 @@ public void test() { Employee employee = new Employee(); employee.setAddress( address ); Company company = new Company(); - company.setEmployees( Arrays.asList( new Employee[] { employee } ) ); + company.setEmployees( Arrays.asList( employee ) ); // test CompanyDto companyDto = CompanyMapper.INSTANCE.toCompanyDto( company ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index bea89fa7f9..6dac09f190 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -42,7 +42,7 @@ public void updatingWithDefaultHandlingRaisesStackOverflowError() { @Test public void mappingWithContextCorrectlyResolvesCycles() { - final AtomicReference contextLevel = new AtomicReference( null ); + final AtomicReference contextLevel = new AtomicReference<>( null ); ContextListener contextListener = new ContextListener() { @Override public void methodCalled(Integer level, String method, Object source, Object target) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java index 0b964d6974..128abccf55 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; @@ -36,7 +37,7 @@ public class CarMapperTest { @Test - public void shouldProvideMapperInstance() throws Exception { + public void shouldProvideMapperInstance() { assertThat( CarMapper.INSTANCE ).isNotNull(); } @@ -46,9 +47,9 @@ public void shouldMapAttributeByName() { Car car = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList() + new ArrayList<>() ); //when @@ -65,9 +66,9 @@ public void shouldMapReferenceAttribute() { Car car = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList() + new ArrayList<>() ); //when @@ -82,7 +83,7 @@ public void shouldMapReferenceAttribute() { @Test public void shouldReverseMapReferenceAttribute() { //given - CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList() ); + CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); //when Car car = CarMapper.INSTANCE.carDtoToCar( carDto ); @@ -99,9 +100,9 @@ public void shouldMapAttributeWithCustomMapping() { Car car = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList() + new ArrayList<>() ); //when @@ -115,7 +116,7 @@ public void shouldMapAttributeWithCustomMapping() { @Test public void shouldConsiderCustomMappingForReverseMapping() { //given - CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList() ); + CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); //when Car car = CarMapper.INSTANCE.carDtoToCar( carDto ); @@ -131,9 +132,9 @@ public void shouldApplyConverter() { Car car = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList() + new ArrayList<>() ); //when @@ -147,14 +148,16 @@ public void shouldApplyConverter() { @Test public void shouldApplyConverterForReverseMapping() { //given - CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList() ); + CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); //when Car car = CarMapper.INSTANCE.carDtoToCar( carDto ); //then assertThat( car ).isNotNull(); - assertThat( car.getManufacturingDate() ).isEqualTo( new GregorianCalendar( 1980, 0, 1 ).getTime() ); + assertThat( car.getManufacturingDate() ).isEqualTo( + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() + ); } @Test @@ -163,20 +166,20 @@ public void shouldMapIterable() { Car car1 = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList() + new ArrayList<>() ); Car car2 = new Car( "Railton", 4, - new GregorianCalendar( 1934, 0, 1 ).getTime(), + new GregorianCalendar( 1934, Calendar.JANUARY, 1 ).getTime(), new Person( "Bill" ), - new ArrayList() + new ArrayList<>() ); //when - List dtos = CarMapper.INSTANCE.carsToCarDtos( new ArrayList( Arrays.asList( car1, car2 ) ) ); + List dtos = CarMapper.INSTANCE.carsToCarDtos( Arrays.asList( car1, car2 ) ); //then assertThat( dtos ).isNotNull(); @@ -196,11 +199,11 @@ public void shouldMapIterable() { @Test public void shouldReverseMapIterable() { //given - CarDto car1 = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList() ); - CarDto car2 = new CarDto( "Railton", 4, "1934", new PersonDto( "Bill" ), new ArrayList() ); + CarDto car1 = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); + CarDto car2 = new CarDto( "Railton", 4, "1934", new PersonDto( "Bill" ), new ArrayList<>() ); //when - List cars = CarMapper.INSTANCE.carDtosToCars( new ArrayList( Arrays.asList( car1, car2 ) ) ); + List cars = CarMapper.INSTANCE.carDtosToCars( Arrays.asList( car1, car2 ) ); //then assertThat( cars ).isNotNull(); @@ -208,12 +211,16 @@ public void shouldReverseMapIterable() { assertThat( cars.get( 0 ).getMake() ).isEqualTo( "Morris" ); assertThat( cars.get( 0 ).getNumberOfSeats() ).isEqualTo( 2 ); - assertThat( cars.get( 0 ).getManufacturingDate() ).isEqualTo( new GregorianCalendar( 1980, 0, 1 ).getTime() ); + assertThat( cars.get( 0 ).getManufacturingDate() ).isEqualTo( + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() + ); assertThat( cars.get( 0 ).getDriver().getName() ).isEqualTo( "Bob" ); assertThat( cars.get( 1 ).getMake() ).isEqualTo( "Railton" ); assertThat( cars.get( 1 ).getNumberOfSeats() ).isEqualTo( 4 ); - assertThat( cars.get( 1 ).getManufacturingDate() ).isEqualTo( new GregorianCalendar( 1934, 0, 1 ).getTime() ); + assertThat( cars.get( 1 ).getManufacturingDate() ).isEqualTo( + new GregorianCalendar( 1934, Calendar.JANUARY, 1 ).getTime() + ); assertThat( cars.get( 1 ).getDriver().getName() ).isEqualTo( "Bill" ); } @@ -223,9 +230,9 @@ public void shouldMapIterableAttribute() { Car car = new Car( "Morris", 2, - new GregorianCalendar( 1980, 0, 1 ).getTime(), + new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime(), new Person( "Bob" ), - new ArrayList( Arrays.asList( new Person( "Alice" ), new Person( "Bill" ) ) ) + Arrays.asList( new Person( "Alice" ), new Person( "Bill" ) ) ); //when @@ -247,7 +254,7 @@ public void shouldReverseMapIterableAttribute() { 2, "1980", new PersonDto( "Bob" ), - new ArrayList( Arrays.asList( new PersonDto( "Alice" ), new PersonDto( "Bill" ) ) ) + Arrays.asList( new PersonDto( "Alice" ), new PersonDto( "Bill" ) ) ); //when diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/Node.java b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java index 15a8effacb..b663b7b15f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/Node.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/Node.java @@ -21,8 +21,8 @@ public class Node { public Node(String name) { this.name = name; - this.children = new ArrayList(); - this.attributes = new ArrayList(); + this.children = new ArrayList<>(); + this.attributes = new ArrayList<>(); } public Node getParent() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java index 298b95aa2c..8b4a21640f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/SelfContainingCycleContext.java @@ -19,7 +19,7 @@ * @author Andreas Gudian */ public class SelfContainingCycleContext { - private Map knownInstances = new IdentityHashMap(); + private Map knownInstances = new IdentityHashMap<>(); @BeforeMapping @SuppressWarnings("unchecked") diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 680303b334..c7a3cf3311 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -50,8 +50,8 @@ public void setDefaultLocale() { // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversions() { Source source = new Source(); - source.setDate( new GregorianCalendar( 2013, 6, 6 ).getTime() ); - source.setAnotherDate( new GregorianCalendar( 2013, 1, 14 ).getTime() ); + source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -65,8 +65,8 @@ public void shouldApplyDateFormatForConversions() { // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionsJdk11() { Source source = new Source(); - source.setDate( new GregorianCalendar( 2013, 6, 6 ).getTime() ); - source.setAnotherDate( new GregorianCalendar( 2013, 1, 14 ).getTime() ); + source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -86,8 +86,10 @@ public void shouldApplyDateFormatForConversionInReverseMapping() { Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); assertThat( source ).isNotNull(); - assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, 6, 6 ).getTime() ); - assertThat( source.getAnotherDate() ).isEqualTo( new GregorianCalendar( 2013, 1, 14, 8, 30 ).getTime() ); + assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + assertThat( source.getAnotherDate() ).isEqualTo( + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() + ); } @Test @@ -101,16 +103,18 @@ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); assertThat( source ).isNotNull(); - assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, 6, 6 ).getTime() ); - assertThat( source.getAnotherDate() ).isEqualTo( new GregorianCalendar( 2013, 1, 14, 8, 30 ).getTime() ); + assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + assertThat( source.getAnotherDate() ).isEqualTo( + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() + ); } @Test public void shouldApplyStringConversionForIterableMethod() { List dates = Arrays.asList( - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() ); List stringDates = SourceTargetMapper.INSTANCE.stringListToDateList( dates ); @@ -122,9 +126,9 @@ public void shouldApplyStringConversionForIterableMethod() { @Test public void shouldApplyStringConversionForArrayMethod() { List dates = Arrays.asList( - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() ); String[] stringDates = SourceTargetMapper.INSTANCE.stringListToDateArray( dates ); @@ -141,9 +145,9 @@ public void shouldApplyStringConversionForReverseIterableMethod() { assertThat( dates ).isNotNull(); assertThat( dates ).containsExactly( - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() ); } @@ -155,18 +159,18 @@ public void shouldApplyStringConversionForReverseArrayMethod() { assertThat( dates ).isNotNull(); assertThat( dates ).containsExactly( - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() ); } @Test public void shouldApplyStringConversionForReverseArrayArrayMethod() { Date[] dates = new Date[]{ - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() }; String[] stringDates = SourceTargetMapper.INSTANCE.dateArrayToStringArray( dates ); @@ -182,15 +186,15 @@ public void shouldApplyDateConversionForReverseArrayArrayMethod() { assertThat( dates ).isNotNull(); assertThat( dates ).isEqualTo( new Date[] { - new GregorianCalendar( 2013, 6, 6 ).getTime(), - new GregorianCalendar( 2013, 1, 14 ).getTime(), - new GregorianCalendar( 2013, 3, 11 ).getTime() + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() } ); } @IssueKey("858") @Test - public void shouldApplyDateToSqlConversion() throws Exception { + public void shouldApplyDateToSqlConversion() { GregorianCalendar time = new GregorianCalendar( 2016, Calendar.AUGUST, 24, 20, 30, 30 ); GregorianCalendar sqlDate = new GregorianCalendar( 2016, Calendar.AUGUST, 23, 21, 35, 35 ); GregorianCalendar timestamp = new GregorianCalendar( 2016, Calendar.AUGUST, 22, 21, 35, 35 ); @@ -212,7 +216,7 @@ public void shouldApplyDateToSqlConversion() throws Exception { @IssueKey("858") @Test - public void shouldApplySqlToDateConversion() throws Exception { + public void shouldApplySqlToDateConversion() { Target target = new Target(); GregorianCalendar time = new GregorianCalendar( 2016, Calendar.AUGUST, 24, 20, 30, 30 ); GregorianCalendar sqlDate = new GregorianCalendar( 2016, Calendar.AUGUST, 23, 21, 35, 35 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java index f2cc7e3417..cb5192d42f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java @@ -35,7 +35,7 @@ public void shouldApplyCharConversion() { @Test public void shouldApplyReverseCharConversion() { CharTarget target = new CharTarget(); - target.setC( Character.valueOf( 'G' ) ); + target.setC( 'G' ); CharSource source = CharMapper.INSTANCE.targetToSource( target ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java index 08e71f8369..84a5657930 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java @@ -43,7 +43,7 @@ public class DecoratorTest { public void shouldInvokeDecoratorMethods() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); //when @@ -99,7 +99,7 @@ public void shouldDelegateNonDecoratedVoidMethodsToDefaultImplementation() { public void shouldApplyDecoratorWithDefaultConstructor() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); //when @@ -120,7 +120,7 @@ public void shouldApplyDecoratorWithDefaultConstructor() { public void shouldApplyDelegateToClassBasedMapper() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person2( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); @@ -150,7 +150,7 @@ public void shouldApplyDelegateToClassBasedMapper() { public void shouldApplyCustomMappers() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person2 person = new Person2( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); person.setEmployer( new Employer( "ACME" ) ); person.setSportsClub( new SportsClub( "SC Duckburg" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index 2e95f3d2ee..ba1f6012bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -78,7 +78,7 @@ public void springDown() { @Test public void shouldInvokeDecoratorMethods() { Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); PersonDto personDto = personMapper.personToPersonDto( person ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java index 2ed238490a..feffc8c52c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java @@ -66,7 +66,7 @@ public void springDown() { public void shouldInvokeDecoratorMethods() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); //when diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java index 2890a4a9e4..d882dfc6db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java @@ -66,7 +66,7 @@ public void springDown() { public void shouldInvokeDecoratorMethods() { //given Calendar birthday = Calendar.getInstance(); - birthday.set( 1928, 4, 23 ); + birthday.set( 1928, Calendar.MAY, 23 ); Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); //when From dbe761e738a54f7c70f833ce2b929cb4d4d69ae8 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 17 Aug 2019 15:53:47 +0300 Subject: [PATCH 0376/1006] Fix minor warnings in packages test and testutil: remove unnecessary generic types for collection, replace numbers months on Calendar constants, remove unnecessary exceptions from signature test methods --- .../ap/test/dependency/GraphAnalyzerTest.java | 2 +- .../destination/DestinationClassNameTest.java | 8 +-- .../DestinationPackageNameTest.java | 10 ++-- .../ap/test/exceptions/ExceptionTest.java | 12 ++--- .../ap/test/factories/FactoryTest.java | 4 +- .../ap/test/fields/FieldsMappingTest.java | 4 +- .../MapperWithGenericSuperClassTest.java | 2 +- .../complex/ComplexInheritanceTest.java | 4 +- .../complex/SourceBaseMappingHelper.java | 13 ++--- .../ap/test/naming/VariableNamingTest.java | 9 ++-- .../NestedMappingMethodInvocationTest.java | 53 ++++++++++--------- .../test/nestedmethodcall/ObjectFactory.java | 2 +- .../_target/ChartPositions.java | 2 +- .../ChartEntryToArtist.java | 4 +- .../ChartEntryToArtistUpdate.java | 2 +- .../NullValuePropertyMappingTest.java | 8 +-- .../ap/test/prism/EnumPrismsTest.java | 13 ++--- .../references/ReferencedCustomMapper.java | 2 +- .../test/references/ReferencedMapperTest.java | 4 +- .../ap/test/references/SomeOtherType.java | 9 ++-- .../ap/test/references/SomeType.java | 9 ++-- .../selection/generics/ConversionTest.java | 26 ++++----- .../selection/jaxb/test1/ObjectFactory.java | 10 ++-- .../selection/jaxb/test2/ObjectFactory.java | 6 +-- .../jaxb/underscores/ObjectFactory.java | 8 +-- .../selection/qualifier/QualifierTest.java | 4 +- .../qualifier/handwritten/PlotWords.java | 9 +--- .../iterable/IterableAndQualifiersTest.java | 4 +- .../selection/qualifier/named/NamedTest.java | 4 +- .../source/constants/SourceConstantsTest.java | 3 +- .../expressions/java/JavaExpressionTest.java | 3 +- .../source/expressions/java/TargetList.java | 2 +- .../presencecheck/spi/SoccerTeamTarget.java | 2 +- .../selection/ExternalSelectionTest.java | 2 +- .../ap/test/value/EnumToEnumMappingTest.java | 2 +- .../testutil/assertions/JavaFileAssert.java | 5 +- .../model/CompilationOutcomeDescriptor.java | 10 ++-- .../model/DiagnosticDescriptor.java | 4 +- .../runner/AnnotationProcessorTestRunner.java | 4 +- .../testutil/runner/CompilingStatement.java | 25 +++++---- .../ap/testutil/runner/GeneratedSource.java | 9 ++-- .../runner/JdkCompilingStatement.java | 6 +-- .../runner/ModifiableURLClassLoader.java | 15 +----- 43 files changed, 153 insertions(+), 186 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java index 9a6a0a0515..d9f611d6d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java @@ -165,7 +165,7 @@ public void eightNodesWithoutCycle() { } private Set asStrings(Set> cycles) { - Set asStrings = new HashSet(); + Set asStrings = new HashSet<>(); for ( List cycle : cycles ) { asStrings.add( asString( cycle ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java index a109ae0fc0..4f4454bcea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java @@ -21,7 +21,7 @@ public class DestinationClassNameTest { @Test @WithClasses({ DestinationClassNameMapper.class }) - public void shouldGenerateRightName() throws Exception { + public void shouldGenerateRightName() { DestinationClassNameMapper instance = DestinationClassNameMapper.INSTANCE; assertThat( instance.getClass().getSimpleName() ).isEqualTo( "MyDestinationClassNameMapperCustomImpl" ); } @@ -48,7 +48,7 @@ public void shouldNotGenerateSpi() throws Exception { @Test @WithClasses({ DestinationClassNameMapperConfig.class, DestinationClassNameMapperWithConfig.class }) - public void shouldGenerateRightNameWithConfig() throws Exception { + public void shouldGenerateRightNameWithConfig() { DestinationClassNameMapperWithConfig instance = DestinationClassNameMapperWithConfig.INSTANCE; assertThat( instance.getClass().getSimpleName() ) .isEqualTo( "MyDestinationClassNameMapperWithConfigConfigImpl" ); @@ -56,7 +56,7 @@ public void shouldGenerateRightNameWithConfig() throws Exception { @Test @WithClasses({ DestinationClassNameMapperConfig.class, DestinationClassNameMapperWithConfigOverride.class }) - public void shouldGenerateRightNameWithConfigOverride() throws Exception { + public void shouldGenerateRightNameWithConfigOverride() { DestinationClassNameMapperWithConfigOverride instance = DestinationClassNameMapperWithConfigOverride.INSTANCE; assertThat( instance.getClass().getSimpleName() ) .isEqualTo( "CustomDestinationClassNameMapperWithConfigOverrideMyImpl" ); @@ -64,7 +64,7 @@ public void shouldGenerateRightNameWithConfigOverride() throws Exception { @Test @WithClasses({ DestinationClassNameMapperDecorated.class, DestinationClassNameMapperDecorator.class }) - public void shouldGenerateRightNameWithDecorator() throws Exception { + public void shouldGenerateRightNameWithDecorator() { DestinationClassNameMapperDecorated instance = DestinationClassNameMapperDecorated.INSTANCE; assertThat( instance.getClass().getSimpleName() ) .isEqualTo( "MyDestinationClassNameMapperDecoratedCustomImpl" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java index d789a7024e..8f55dedc9b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java @@ -21,7 +21,7 @@ public class DestinationPackageNameTest { @Test @WithClasses({ DestinationPackageNameMapper.class }) - public void shouldGenerateInRightPackage() throws Exception { + public void shouldGenerateInRightPackage() { DestinationPackageNameMapper instance = DestinationPackageNameMapper.INSTANCE; assertThat( instance.getClass().getName() ) .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperImpl" ); @@ -29,7 +29,7 @@ public void shouldGenerateInRightPackage() throws Exception { @Test @WithClasses({ DestinationPackageNameMapperWithSuffix.class }) - public void shouldGenerateInRightPackageWithSuffix() throws Exception { + public void shouldGenerateInRightPackageWithSuffix() { DestinationPackageNameMapperWithSuffix instance = DestinationPackageNameMapperWithSuffix.INSTANCE; assertThat( instance.getClass().getName() ) .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperWithSuffixMyImpl" ); @@ -37,7 +37,7 @@ public void shouldGenerateInRightPackageWithSuffix() throws Exception { @Test @WithClasses({ DestinationPackageNameMapperConfig.class, DestinationPackageNameMapperWithConfig.class }) - public void shouldGenerateRightSuffixWithConfig() throws Exception { + public void shouldGenerateRightSuffixWithConfig() { DestinationPackageNameMapperWithConfig instance = DestinationPackageNameMapperWithConfig.INSTANCE; assertThat( instance.getClass().getName() ) .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperWithConfigImpl" ); @@ -45,7 +45,7 @@ public void shouldGenerateRightSuffixWithConfig() throws Exception { @Test @WithClasses({ DestinationPackageNameMapperConfig.class, DestinationPackageNameMapperWithConfigOverride.class }) - public void shouldGenerateRightSuffixWithConfigOverride() throws Exception { + public void shouldGenerateRightSuffixWithConfigOverride() { DestinationPackageNameMapperWithConfigOverride instance = DestinationPackageNameMapperWithConfigOverride.INSTANCE; assertThat( instance.getClass().getName() ) @@ -56,7 +56,7 @@ public void shouldGenerateRightSuffixWithConfigOverride() throws Exception { @Test @WithClasses({ DestinationPackageNameMapperDecorated.class, DestinationPackageNameMapperDecorator.class }) - public void shouldGenerateRightSuffixWithDecorator() throws Exception { + public void shouldGenerateRightSuffixWithDecorator() { DestinationPackageNameMapperDecorated instance = DestinationPackageNameMapperDecorated.INSTANCE; assertThat( instance.getClass().getName() ) .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperDecoratedImpl" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java index 6e6d8b4e03..2364381efe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java @@ -65,7 +65,7 @@ public void shouldThrowTestParseExceptionInBeanMappingDueToTypeConverion() throw @Test( expected = RuntimeException.class ) @IssueKey( "198" ) public void shouldThrowRuntimeInIterableMapping() throws TestException2 { - List source = new ArrayList(); + List source = new ArrayList<>(); source.add( 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerListToLongList( source ); @@ -74,7 +74,7 @@ public void shouldThrowRuntimeInIterableMapping() throws TestException2 { @Test( expected = TestException2.class ) @IssueKey( "198" ) public void shouldThrowTestException2InIterableMapping() throws TestException2 { - List source = new ArrayList(); + List source = new ArrayList<>(); source.add( 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerListToLongList( source ); @@ -83,7 +83,7 @@ public void shouldThrowTestException2InIterableMapping() throws TestException2 { @Test( expected = RuntimeException.class ) @IssueKey( "198" ) public void shouldThrowRuntimeInMapKeyMapping() throws TestException2 { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( 1, "test" ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerKeyMapToLongKeyMap( source ); @@ -92,7 +92,7 @@ public void shouldThrowRuntimeInMapKeyMapping() throws TestException2 { @Test( expected = TestException2.class ) @IssueKey( "198" ) public void shouldThrowTestException2InMapKeyMapping() throws TestException2 { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( 2, "test" ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerKeyMapToLongKeyMap( source ); @@ -101,7 +101,7 @@ public void shouldThrowTestException2InMapKeyMapping() throws TestException2 { @Test( expected = RuntimeException.class ) @IssueKey( "198" ) public void shouldThrowRuntimeInMapValueMapping() throws TestException2 { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( "test", 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerValueMapToLongValueMap( source ); @@ -110,7 +110,7 @@ public void shouldThrowRuntimeInMapValueMapping() throws TestException2 { @Test( expected = TestException2.class ) @IssueKey( "198" ) public void shouldThrowTestException2InMapValueMapping() throws TestException2 { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( "test", 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; sourceTargetMapper.integerValueMapToLongValueMap( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java index e00f88198d..1480c146fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java @@ -84,11 +84,11 @@ private Source createSource() { foo4.setProp( "foo4" ); source.setProp4( foo4 ); - List fooList = new ArrayList(); + List fooList = new ArrayList<>(); fooList.add( "fooListEntry" ); source.setPropList( fooList ); - Map fooMap = new HashMap(); + Map fooMap = new HashMap<>(); fooMap.put( "key", "fooValue" ); source.setPropMap( fooMap ); return source; diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java index 5780e35132..8c87e7e14d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java @@ -23,7 +23,7 @@ public class FieldsMappingTest { @Test - public void shouldMapSourceToTarget() throws Exception { + public void shouldMapSourceToTarget() { Source source = new Source(); source.normalInt = 4; source.normalList = Lists.newArrayList( 10, 11, 12 ); @@ -42,7 +42,7 @@ public void shouldMapSourceToTarget() throws Exception { } @Test - public void shouldMapTargetToSource() throws Exception { + public void shouldMapTargetToSource() { Target target = new Target(); target.finalInt = "40"; target.normalInt = "4"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java index 9d53fa0f94..30b961432c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java @@ -32,7 +32,7 @@ public void canCreateImplementationForMapperWithGenericSuperClass() { Vessel vessel = new Vessel(); vessel.setName( "Pacific Queen" ); - SearchResult vessels = new SearchResult(); + SearchResult vessels = new SearchResult<>(); vessels.setValues( Arrays.asList( vessel ) ); vessels.setSize( 1L ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index 6168ecdf24..a8e1033a2b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -108,14 +108,14 @@ private SourceBase createSourceBase(int foo) { private SourceExt createSourceExt(int foo) { SourceExt s = new SourceExt(); s.setFoo( foo ); - s.setBar( Long.valueOf( 47 ) ); + s.setBar( 47L ); return s; } private SourceExt2 createSourceExt2(int foo) { SourceExt2 s = new SourceExt2(); s.setFoo( foo ); - s.setBaz( Long.valueOf( 47 ) ); + s.setBaz( 47L ); return s; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java index e73c708915..017b98496b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/SourceBaseMappingHelper.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.test.inheritance.complex; -import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; public class SourceBaseMappingHelper { public Reference asReference(SourceBase source) { @@ -33,13 +33,8 @@ public List integerCollectionToNumberList(Collection collection if ( collection == null ) { return null; } - - List list = new ArrayList( collection.size() ); - - for ( Integer original : collection ) { - list.add( Integer.valueOf( original + 1 ) ); - } - - return list; + return collection.stream() + .map( original -> original + 1 ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java index 2014e11bf6..c70f21b2cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java @@ -9,6 +9,7 @@ import static org.assertj.core.api.Assertions.entry; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; @@ -35,11 +36,11 @@ public void shouldGenerateImplementationsOfMethodsWithProblematicVariableNmes() Source source = new Source(); source.setSomeNumber( 42 ); - source.setValues( Arrays.asList( 42L, 121L ) ); + source.setValues( Arrays.asList( 42L, 121L ) ); - Map map = new HashMap(); - map.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ); - map.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() ); + Map map = new HashMap<>(); + map.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); + map.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ); source.setMap( map ); Break target = SourceTargetMapper.INSTANCE.sourceToBreak( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index f16732beb5..11ac637f91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; +import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; @@ -70,13 +71,13 @@ public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException ObjectFactory.class, TargetDto.class } ) - public void shouldMapViaMethodAndConversion() throws DatatypeConfigurationException { + public void shouldMapViaMethodAndConversion() { SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; TargetDto target = instance.sourceToTarget( createSource() ); assertThat( target ).isNotNull(); - assertThat( target.getDate() ).isEqualTo( new GregorianCalendar( 2013, 6, 6 ).getTime() ); + assertThat( target.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); } @Test @@ -86,7 +87,7 @@ public void shouldMapViaMethodAndConversion() throws DatatypeConfigurationExcept ObjectFactory.class, TargetDto.class } ) - public void shouldMapViaConversionAndMethod() throws DatatypeConfigurationException { + public void shouldMapViaConversionAndMethod() { SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; SourceType source = instance.targetToSource( createTarget() ); @@ -97,36 +98,36 @@ public void shouldMapViaConversionAndMethod() throws DatatypeConfigurationExcept } private OrderType createOrderType() throws DatatypeConfigurationException { - List> dates = new ArrayList>(); + List> dates = new ArrayList<>(); dates.add( - new JAXBElement( - QNAME, - XMLGregorianCalendar.class, - createXmlCal( 1999, 3, 2 ) - ) + new JAXBElement<>( + QNAME, + XMLGregorianCalendar.class, + createXmlCal( 1999, 3, 2 ) + ) ); dates.add( - new JAXBElement( - QNAME, - XMLGregorianCalendar.class, - createXmlCal( 2004, 7, 28 ) - ) + new JAXBElement<>( + QNAME, + XMLGregorianCalendar.class, + createXmlCal( 2004, 7, 28 ) + ) ); - List> description = new ArrayList>(); - description.add( new JAXBElement( QNAME, String.class, "elem1" ) ); - description.add( new JAXBElement( QNAME, String.class, "elem2" ) ); + List> description = new ArrayList<>(); + description.add( new JAXBElement<>( QNAME, String.class, "elem1" ) ); + description.add( new JAXBElement<>( QNAME, String.class, "elem2" ) ); OrderType orderType = new OrderType(); - orderType.setOrderNumber( new JAXBElement( QNAME, Long.class, 5L ) ); + orderType.setOrderNumber( new JAXBElement<>( QNAME, Long.class, 5L ) ); orderType.setOrderDetails( - new JAXBElement( - QNAME, - OrderDetailsType.class, - new OrderDetailsType() - ) + new JAXBElement<>( + QNAME, + OrderDetailsType.class, + new OrderDetailsType() + ) ); - orderType.getOrderDetails().getValue().setName( new JAXBElement( QNAME, String.class, "test" ) ); + orderType.getOrderDetails().getValue().setName( new JAXBElement<>( QNAME, String.class, "test" ) ); orderType.getOrderDetails().getValue().setDescription( description ); orderType.setDates( dates ); @@ -141,13 +142,13 @@ private XMLGregorianCalendar createXmlCal( int year, int month, int day ) private SourceType createSource() { SourceType source = new SourceType(); - source.setDate( new JAXBElement( QNAME, String.class, "06.07.2013" ) ); + source.setDate( new JAXBElement<>( QNAME, String.class, "06.07.2013" ) ); return source; } private TargetDto createTarget() { TargetDto target = new TargetDto(); - target.setDate( new GregorianCalendar( 2013, 6, 6 ).getTime() ); + target.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); return target; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java index 05fd3e7c63..3d2c454255 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/ObjectFactory.java @@ -15,6 +15,6 @@ public class ObjectFactory { public JAXBElement createDate(String date) { - return new JAXBElement( new QName( "dont-care" ), String.class, "06.07.2013" ); + return new JAXBElement<>( new QName( "dont-care" ), String.class, "06.07.2013" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java index 936c45dea5..f91534fe99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartPositions.java @@ -13,7 +13,7 @@ */ public class ChartPositions { - private final List positions = new ArrayList(); + private final List positions = new ArrayList<>(); public List getPositions() { return positions; diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java index 515679a0da..db8d635d62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtist.java @@ -52,10 +52,10 @@ public abstract class ChartEntryToArtist { protected List mapPosition(Integer in) { if ( in != null ) { - return new ArrayList( Arrays.asList( in ) ); + return new ArrayList<>( Arrays.asList( in ) ); } else { - return new ArrayList(); + return new ArrayList<>(); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java index a65bfde8db..eb9191daf3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistUpdate.java @@ -46,7 +46,7 @@ protected List mapPosition(Integer in) { return Arrays.asList( in ); } else { - return Collections.emptyList(); + return Collections.emptyList(); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index 30920b9ae1..75cb93bf3e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -59,25 +59,25 @@ public void testStrategyAppliedOnForgedMethod() { @Test @WithClasses({ NvpmsConfig.class, CustomerNvpmsOnConfigMapper.class }) public void testHierarchyIgnoreOnConfig() { - testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnConfigMapper.INSTANCE.map( s, t ) ); + testConfig( CustomerNvpmsOnConfigMapper.INSTANCE::map ); } @Test @WithClasses(CustomerNvpmsOnMapperMapper.class) public void testHierarchyIgnoreOnMapping() { - testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnMapperMapper.INSTANCE.map( s, t ) ); + testConfig( CustomerNvpmsOnMapperMapper.INSTANCE::map ); } @Test @WithClasses(CustomerNvpmsOnBeanMappingMethodMapper.class) public void testHierarchyIgnoreOnBeanMappingMethod() { - testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsOnBeanMappingMethodMapper.INSTANCE.map( s, t ) ); + testConfig( CustomerNvpmsOnBeanMappingMethodMapper.INSTANCE::map ); } @Test @WithClasses(CustomerNvpmsPropertyMappingMapper.class) public void testHierarchyIgnoreOnPropertyMappingMehtod() { - testConfig( ( Customer s, CustomerDTO t ) -> CustomerNvpmsPropertyMappingMapper.INSTANCE.map( s, t ) ); + testConfig( CustomerNvpmsPropertyMappingMapper.INSTANCE::map ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java index 388516380c..3090ead472 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java @@ -7,8 +7,9 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.Test; import org.mapstruct.CollectionMappingStrategy; @@ -67,12 +68,8 @@ public void injectionStrategyPrismIsCorrect() { } private static List namesOf(Enum[] values) { - List names = new ArrayList( values.length ); - - for ( Enum e : values ) { - names.add( e.name() ); - } - - return names; + return Stream.of( values ) + .map( Enum::name ) + .collect( Collectors.toList() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java index d27146fb18..391266be08 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedCustomMapper.java @@ -27,7 +27,7 @@ else if ( clazz == SomeOtherType.class ) { return (T) new SomeOtherType( string ); } else if ( clazz == GenericWrapper.class ) { - return (T) new GenericWrapper( string ); + return (T) new GenericWrapper<>( string ); } return null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java index 381a521e16..ee34f53046 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java @@ -66,7 +66,7 @@ public void shouldUseGenericFactoryForIterable() { @Test @IssueKey( "136" ) public void shouldUseGenericFactoryForMap() { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( "foo1", "bar1" ); source.put( "foo2", "bar2" ); Map result = SourceTargetMapper.INSTANCE.fromStringMap( source ); @@ -85,7 +85,7 @@ public void shouldMapPrimitivesWithCustomMapper() { source.setProp1( new SomeType( "42" ) ); source.setProp2( new SomeType( "1701" ) ); source.setProp3( new SomeType( "true" ) ); - source.setProp4( new GenericWrapper( new SomeType( "x" ) ) ); + source.setProp4( new GenericWrapper<>( new SomeType( "x" ) ) ); TargetWithPrimitives result = SourceTargetMapperWithPrimitives.INSTANCE.sourceToTarget( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java b/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java index 449b5b49af..99f04a97d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SomeOtherType.java @@ -45,13 +45,10 @@ public boolean equals(Object obj) { } SomeOtherType other = (SomeOtherType) obj; if ( value == null ) { - if ( other.value != null ) { - return false; - } + return other.value == null; } - else if ( !value.equals( other.value ) ) { - return false; + else { + return value.equals( other.value ); } - return true; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java b/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java index 08360a5a4c..c58c24f3ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/SomeType.java @@ -45,13 +45,10 @@ public boolean equals(Object obj) { } SomeType other = (SomeType) obj; if ( value == null ) { - if ( other.value != null ) { - return false; - } + return other.value == null; } - else if ( !value.equals( other.value ) ) { - return false; + else { + return value.equals( other.value ); } - return true; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 8f493bb6ca..1adc1aba8f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -43,19 +43,19 @@ public void shouldApplyGenericTypeMapper() { // setup source Source source = new Source(); - source.setFooInteger( new Wrapper( 5 ) ); - source.setFooString( new Wrapper( "test" ) ); - source.setFooStringArray( new Wrapper( new String[] { "test1", "test2" } ) ); - source.setFooLongArray( new ArrayWrapper( new Long[] { 5L, 3L } ) ); - source.setFooTwoArgs( new TwoArgWrapper( new TwoArgHolder( 3, true ) ) ); - source.setFooNested( new Wrapper>( new Wrapper( new BigDecimal( 5 ) ) ) ); - source.setFooUpperBoundCorrect( new UpperBoundWrapper( typeB ) ); - source.setFooWildCardExtendsString( new WildCardExtendsWrapper( "test3" ) ); - source.setFooWildCardExtendsTypeCCorrect( new WildCardExtendsWrapper( typeC ) ); - source.setFooWildCardExtendsTypeBCorrect( new WildCardExtendsWrapper( typeB ) ); - source.setFooWildCardSuperString( new WildCardSuperWrapper( "test4" ) ); - source.setFooWildCardExtendsMBTypeCCorrect( new WildCardExtendsMBWrapper( typeC ) ); - source.setFooWildCardSuperTypeBCorrect( new WildCardSuperWrapper( typeB ) ); + source.setFooInteger( new Wrapper<>( 5 ) ); + source.setFooString( new Wrapper<>( "test" ) ); + source.setFooStringArray( new Wrapper<>( new String[] { "test1", "test2" } ) ); + source.setFooLongArray( new ArrayWrapper<>( new Long[] { 5L, 3L } ) ); + source.setFooTwoArgs( new TwoArgWrapper<>( new TwoArgHolder<>( 3, true ) ) ); + source.setFooNested( new Wrapper<>( new Wrapper<>( new BigDecimal( 5 ) ) ) ); + source.setFooUpperBoundCorrect( new UpperBoundWrapper<>( typeB ) ); + source.setFooWildCardExtendsString( new WildCardExtendsWrapper<>( "test3" ) ); + source.setFooWildCardExtendsTypeCCorrect( new WildCardExtendsWrapper<>( typeC ) ); + source.setFooWildCardExtendsTypeBCorrect( new WildCardExtendsWrapper<>( typeB ) ); + source.setFooWildCardSuperString( new WildCardSuperWrapper<>( "test4" ) ); + source.setFooWildCardExtendsMBTypeCCorrect( new WildCardExtendsMBWrapper<>( typeC ) ); + source.setFooWildCardSuperTypeBCorrect( new WildCardSuperWrapper<>( typeB ) ); // define wrapper Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java index 32ffd23da8..5a36880334 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test1/ObjectFactory.java @@ -35,25 +35,25 @@ public OrderType createOrderType() { @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "Order") public JAXBElement createOrder(OrderType value) { - return new JAXBElement( ORDER_QNAME, OrderType.class, null, value ); + return new JAXBElement<>( ORDER_QNAME, OrderType.class, null, value ); } @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "orderNumber1", scope = OrderType.class) public JAXBElement createOrderTypeOrderNumber1(Long value) { - return new JAXBElement( ORDER_TYPE_ORDER_NUMBER1_QNAME, Long.class, OrderType.class, value ); + return new JAXBElement<>( ORDER_TYPE_ORDER_NUMBER1_QNAME, Long.class, OrderType.class, value ); } @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "orderNumber2", scope = OrderType.class) public JAXBElement createOrderTypeOrderNumber2(Long value) { - return new JAXBElement( ORDER_TYPE_ORDER_NUMBER2_QNAME, Long.class, OrderType.class, value ); + return new JAXBElement<>( ORDER_TYPE_ORDER_NUMBER2_QNAME, Long.class, OrderType.class, value ); } @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "shippingDetails", scope = OrderType.class) public JAXBElement createOrderTypeShippingDetails(OrderShippingDetailsType value) { - return new JAXBElement( + return new JAXBElement<>( ORDER_TYPE_SHIPPING_DETAILS_QNAME, OrderShippingDetailsType.class, OrderType.class, value ); @@ -62,7 +62,7 @@ public JAXBElement createOrderTypeShippingDetails(Orde @XmlElementDecl(namespace = "http://www.mapstruct.org/itest/jaxb/xsd/test1", name = "description", scope = OrderType.class) public JAXBElement createOrderTypeDescription(String value) { - return new JAXBElement(ORDER_TYPE_DESCRIPTION_QNAME, String.class, OrderType.class, value); + return new JAXBElement<>( ORDER_TYPE_DESCRIPTION_QNAME, String.class, OrderType.class, value ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java index 4457166d17..1827512f63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/test2/ObjectFactory.java @@ -29,7 +29,7 @@ public OrderShippingDetailsType createOrderShippingDetailsType() { @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "OrderShippingDetails") public JAXBElement createOrderShippingDetails(OrderShippingDetailsType value) { - return new JAXBElement( + return new JAXBElement<>( ORDER_SHIPPING_DETAILS_QNAME, OrderShippingDetailsType.class, null, value ); @@ -38,7 +38,7 @@ public JAXBElement createOrderShippingDetails(OrderShi @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedFrom", scope = OrderShippingDetailsType.class) public JAXBElement createOrderShippingDetailsTypeOrderShippedFrom(String value) { - return new JAXBElement( + return new JAXBElement<>( ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME, String.class, OrderShippingDetailsType.class, value ); @@ -47,7 +47,7 @@ public JAXBElement createOrderShippingDetailsTypeOrderShippedFrom(String @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedTo", scope = OrderShippingDetailsType.class) public JAXBElement createOrderShippingDetailsTypeOrderShippedTo(String value) { - return new JAXBElement( + return new JAXBElement<>( ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME, String.class, OrderShippingDetailsType.class, value ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java index 8314422ea8..2412527349 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/underscores/ObjectFactory.java @@ -34,23 +34,23 @@ public SuperType createSuperType() { @XmlElementDecl( namespace = "http://www.mapstruct.org/itest/jaxb/xsd/underscores", name = "Super" ) public JAXBElement createSuper(SuperType value) { - return new JAXBElement(SUPER_QNAME, SuperType.class, null, value ); + return new JAXBElement<>( SUPER_QNAME, SuperType.class, null, value ); } @XmlElementDecl( namespace = "http://www.mapstruct.org/itest/jaxb/xsd/underscores", name = "Sub" ) public JAXBElement createSub(SubType value) { - return new JAXBElement(SUB_QNAME, SubType.class, null, value ); + return new JAXBElement<>( SUB_QNAME, SubType.class, null, value ); } @XmlElementDecl( namespace = "http://www.mapstruct.org/itest/jaxb/xsd/underscores", name = "inherited_underscore", scope = SuperType.class ) public JAXBElement createSuperTypeInheritedUnderscore(String value) { - return new JAXBElement(SUPER_TYPE_INHERITED_UNDERSCORE_QNAME, String.class, SuperType.class, value ); + return new JAXBElement<>( SUPER_TYPE_INHERITED_UNDERSCORE_QNAME, String.class, SuperType.class, value ); } @XmlElementDecl( namespace = "http://www.mapstruct.org/itest/jaxb/xsd/underscores", name = "declared_underscore", scope = SubType.class ) public JAXBElement createSubTypeDeclaredUnderscore(String value) { - return new JAXBElement(SUB_TYPE_DECLARED_UNDERSCORE_QNAME, String.class, SubType.class, value ); + return new JAXBElement<>( SUB_TYPE_DECLARED_UNDERSCORE_QNAME, String.class, SubType.class, value ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 6edbb93cf6..9ec88d431e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -68,7 +68,7 @@ public void shouldMatchClassAndMethod() { OriginalRelease foreignMovies = new OriginalRelease(); foreignMovies.setTitle( "Sixth Sense, The" ); foreignMovies.setKeyWords( Arrays.asList( "evergreen", "magnificent" ) ); - Map> facts = new HashMap>(); + Map> facts = new HashMap<>(); facts.put( "director", Arrays.asList( "M. Night Shyamalan" ) ); facts.put( "cast", Arrays.asList( "Bruce Willis", "Haley Joel Osment", "Toni Collette" ) ); facts.put( "plot keywords", Arrays.asList( "boy", "child psychologist", "I see dead people" ) ); @@ -150,7 +150,7 @@ public void testFactorySelectionWithQualifier() { OriginalRelease foreignMovies = new OriginalRelease(); foreignMovies.setTitle( "Sixth Sense, The" ); foreignMovies.setKeyWords( Arrays.asList( "evergreen", "magnificent" ) ); - Map> facts = new HashMap>(); + Map> facts = new HashMap<>(); facts.put( "director", Arrays.asList( "M. Night Shyamalan" ) ); facts.put( "cast", Arrays.asList( "Bruce Willis", "Haley Joel Osment", "Toni Collette" ) ); facts.put( "plot keywords", Arrays.asList( "boy", "child psychologist", "I see dead people" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java index a2b1f14e4d..3c635ae4e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/handwritten/PlotWords.java @@ -29,14 +29,9 @@ public class PlotWords { @EnglishToGerman @Named( "EnglishToGerman" ) public List translate( List keywords ) { - List result = new ArrayList(); + List result = new ArrayList<>(); for ( String keyword : keywords ) { - if ( EN_GER.containsKey( keyword ) ) { - result.add( EN_GER.get( keyword ) ); - } - else { - result.add( keyword ); - } + result.add( EN_GER.getOrDefault( keyword, keyword ) ); } return result; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java index 3155d43bee..db8de9496e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java @@ -39,7 +39,7 @@ public class IterableAndQualifiersTest { public void testGenerationBasedOnQualifier() { TopologyDto topologyDto1 = new TopologyDto(); - List topologyFeatures1 = new ArrayList(); + List topologyFeatures1 = new ArrayList<>(); RiverDto riverDto = new RiverDto(); riverDto.setName( "Rhine" ); riverDto.setLength( 5 ); @@ -53,7 +53,7 @@ public void testGenerationBasedOnQualifier() { assertThat( ( (RiverEntity) result1.getTopologyFeatures().get( 0 ) ).getLength() ).isEqualTo( 5 ); TopologyDto topologyDto2 = new TopologyDto(); - List topologyFeatures2 = new ArrayList(); + List topologyFeatures2 = new ArrayList<>(); CityDto cityDto = new CityDto(); cityDto.setName( "Amsterdam" ); cityDto.setPopulation( 800000 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java index eb9c62e53f..3de7b1515e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java @@ -62,7 +62,7 @@ public void shouldMatchClassAndMethod() { OriginalRelease foreignMovies = new OriginalRelease(); foreignMovies.setTitle( "Sixth Sense, The" ); foreignMovies.setKeyWords( Arrays.asList( "evergreen", "magnificent" ) ); - Map> facts = new HashMap>(); + Map> facts = new HashMap<>(); facts.put( "director", Arrays.asList( "M. Night Shyamalan" ) ); facts.put( "cast", Arrays.asList( "Bruce Willis", "Haley Joel Osment", "Toni Collette" ) ); facts.put( "plot keywords", Arrays.asList( "boy", "child psychologist", "I see dead people" ) ); @@ -96,7 +96,7 @@ public void testFactorySelectionWithQualifier() { OriginalRelease foreignMovies = new OriginalRelease(); foreignMovies.setTitle( "Sixth Sense, The" ); foreignMovies.setKeyWords( Arrays.asList( "evergreen", "magnificent" ) ); - Map> facts = new HashMap>(); + Map> facts = new HashMap<>(); facts.put( "director", Arrays.asList( "M. Night Shyamalan" ) ); facts.put( "cast", Arrays.asList( "Bruce Willis", "Haley Joel Osment", "Toni Collette" ) ); facts.put( "plot keywords", Arrays.asList( "boy", "child psychologist", "I see dead people" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index c1c6d8d58f..fa10dce5d0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -228,8 +228,7 @@ public void cannotMapIntConstantToLong() throws ParseException { private Date getDate(String format, String date) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat( format ); - Date result = dateFormat.parse( date ); - return result; + return dateFormat.parse( date ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index 51988717c4..3cec82ea9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -73,8 +73,7 @@ public void testJavaExpressionInsertionWithSeveralSources() throws ParseExceptio private Date getTime(String format, String date) throws ParseException { SimpleDateFormat dateFormat = new SimpleDateFormat( format ); - Date result = dateFormat.parse( date ); - return result; + return dateFormat.parse( date ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java index f45f284be9..6e6b98f116 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/TargetList.java @@ -14,7 +14,7 @@ */ public class TargetList { - private List list = new ArrayList(); + private List list = new ArrayList<>(); public List getList() { return list; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java index 42f9624baf..b56ed32997 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/SoccerTeamTarget.java @@ -22,7 +22,7 @@ public List getPlayers() { public void addPlayer(String player) { if ( this.players == null ) { - this.players = new ArrayList(); + this.players = new ArrayList<>(); } this.players.add( player ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java index f82fd1c33a..8c10656ae4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java @@ -111,7 +111,7 @@ public void shouldSelectGeneratedExternalMapperForIterablesAndMaps() { SecretaryDto secretaryDto = new SecretaryDto(); secretaryDto.setName( "Jim" ); departmentDto.setEmployees( Arrays.asList( employeeDto ) ); - Map secretaryToEmployee = new HashMap(); + Map secretaryToEmployee = new HashMap<>(); secretaryToEmployee.put( secretaryDto, employeeDto ); departmentDto.setSecretaryToEmployee( secretaryToEmployee ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java index 2403977d09..aa1e0ea02c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/EnumToEnumMappingTest.java @@ -186,7 +186,7 @@ public void shouldMappAllUnmappedToDefault() { @IssueKey( "1091" ) @Test - public void shouldMapAnyRemainingToNullCorrectly() throws Exception { + public void shouldMapAnyRemainingToNullCorrectly() { ExternalOrderType externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.RETAIL ); assertThat( externalOrderType ) .isNotNull() diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 62325ac8f7..b1718087b6 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.UncheckedIOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -92,9 +93,9 @@ public void containsNoImportFor(Class importedClass) { * @param expected the file that should be matched */ public void hasSameMapperContent(File expected) { - Charset charset = Charset.forName( "UTF-8" ); + Charset charset = StandardCharsets.UTF_8; try { - List> diffs = new ArrayList>( this.diff.diff( + List> diffs = new ArrayList<>( this.diff.diff( actual, charset, expected, diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java index 22d9bcd68e..02036d175e 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java @@ -28,8 +28,6 @@ */ public class CompilationOutcomeDescriptor { - private static final String LINE_SEPARATOR = System.lineSeparator( ); - private CompilationResult compilationResult; private List diagnostics; private List notes; @@ -57,12 +55,12 @@ public static CompilationOutcomeDescriptor forExpectedCompilationResult( if ( expectedCompilationResult == null ) { return new CompilationOutcomeDescriptor( CompilationResult.SUCCEEDED, - Collections.emptyList(), + Collections.emptyList(), notes ); } else { - List diagnosticDescriptors = new ArrayList(); + List diagnosticDescriptors = new ArrayList<>(); for ( org.mapstruct.ap.testutil.compilation.annotation.Diagnostic diagnostic : expectedCompilationResult.diagnostics() ) { diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) ); @@ -76,7 +74,7 @@ public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean c CompilationResult compilationResult = compilationSuccessful ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; List notes = new ArrayList<>(); - List diagnosticDescriptors = new ArrayList(); + List diagnosticDescriptors = new ArrayList<>(); for ( Diagnostic diagnostic : diagnostics ) { //ignore notes created by the compiler if ( diagnostic.getKind() != Kind.NOTE ) { @@ -93,7 +91,7 @@ public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean c public static CompilationOutcomeDescriptor forResult(String sourceDir, CompilerResult compilerResult) { CompilationResult compilationResult = compilerResult.isSuccess() ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; - List diagnosticDescriptors = new ArrayList(); + List diagnosticDescriptors = new ArrayList<>(); for ( CompilerMessage message : compilerResult.getCompilerMessages() ) { if ( message.getKind() != CompilerMessage.Kind.NOTE ) { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index f023610642..b268242c4a 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -42,11 +42,11 @@ private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long a } public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) { - String soureFileName = diagnostic.type() != void.class + String sourceFileName = diagnostic.type() != void.class ? diagnostic.type().getName().replace( ".", File.separator ) + ".java" : null; return new DiagnosticDescriptor( - soureFileName, + sourceFileName, diagnostic.kind(), diagnostic.line() != -1 ? diagnostic.line() : null, diagnostic.alternativeLine() != -1 ? diagnostic.alternativeLine() : null, diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java index 2688f9f7df..5a487e8c11 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java @@ -68,7 +68,7 @@ private List createRunners(Class klass) throws Exception { WithSingleCompiler singleCompiler = klass.getAnnotation( WithSingleCompiler.class ); if (singleCompiler != null) { - return Arrays. asList( new InnerAnnotationProcessorRunner( klass, singleCompiler.value() ) ); + return Arrays.asList( new InnerAnnotationProcessorRunner( klass, singleCompiler.value() ) ); } else if ( IS_AT_LEAST_JAVA_9 ) { // Current tycho-compiler-jdt (0.26.0) is not compatible with Java 11 @@ -77,7 +77,7 @@ else if ( IS_AT_LEAST_JAVA_9 ) { return Arrays.asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK11 ) ); } - return Arrays. asList( + return Arrays.asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK ), new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 0b2d297384..e87c22d421 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.stream.Collectors; import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import org.junit.runners.model.FrameworkMethod; @@ -102,7 +101,7 @@ String getSourceOutputDir() { return compilationCache.getLastSourceOutputDir(); } - protected void setupDirectories() throws Exception { + protected void setupDirectories() { String compilationRoot = getBasePath() + TARGET_COMPILATION_TESTS + method.getDeclaringClass().getName() @@ -154,7 +153,7 @@ protected static List filterBootClassPath(String[] whitelist) { System.getProperty( "java.class.path" ).split( File.pathSeparator ); String testClasses = "target" + File.separator + "test-classes"; - List classpath = new ArrayList(); + List classpath = new ArrayList<>(); for ( String path : bootClasspath ) { if ( !path.contains( testClasses ) && isWhitelisted( path, whitelist ) ) { classpath.add( path ); @@ -273,7 +272,7 @@ private void assertNotes(List actualNotes, List expectedNotes) { assertThat( expectedNotesRemaining ) .describedAs( "There are unmatched notes: " + - expectedNotesRemaining.stream().collect( Collectors.joining( LINE_SEPARATOR ) ).toString() ) + String.join( LINE_SEPARATOR, expectedNotesRemaining ) ) .isEmpty(); } @@ -340,7 +339,7 @@ protected List filterExpectedDiagnostics(List> getTestClasses() { - Set> testClasses = new HashSet>(); + Set> testClasses = new HashSet<>(); WithClasses withClasses = method.getAnnotation( WithClasses.class ); if ( withClasses != null ) { @@ -368,7 +367,7 @@ private Set> getTestClasses() { * for this test */ private Map, Class> getServices() { - Map, Class> services = new HashMap, Class>(); + Map, Class> services = new HashMap<>(); addServices( services, method.getAnnotation( WithServiceImplementations.class ) ); addService( services, method.getAnnotation( WithServiceImplementation.class ) ); @@ -428,7 +427,7 @@ private List getProcessorOptions() { method.getMethod().getDeclaringClass().getAnnotation( ProcessorOption.class ) ); } - List result = new ArrayList( processorOptions.size() ); + List result = new ArrayList<>( processorOptions.size() ); for ( ProcessorOption option : processorOptions ) { result.add( asOptionString( option ) ); } @@ -455,7 +454,7 @@ private String asOptionString(ProcessorOption processorOption) { } protected static Set getSourceFiles(Collection> classes) { - Set sourceFiles = new HashSet( classes.size() ); + Set sourceFiles = new HashSet<>( classes.size() ); for ( Class clazz : classes ) { sourceFiles.add( @@ -537,12 +536,12 @@ private void createOutputDirs() { private void deleteDirectory(File path) { if ( path.exists() ) { File[] files = path.listFiles(); - for ( int i = 0; i < files.length; i++ ) { - if ( files[i].isDirectory() ) { - deleteDirectory( files[i] ); + for ( File file : files ) { + if ( file.isDirectory() ) { + deleteDirectory( file ); } else { - files[i].delete(); + file.delete(); } } } @@ -587,7 +586,7 @@ public int compare(DiagnosticDescriptor o1, DiagnosticDescriptor o2) { if ( result != 0 ) { return result; } - result = Long.valueOf( o1.getLine() ).compareTo( o2.getLine() ); + result = o1.getLine().compareTo( o2.getLine() ); if ( result != 0 ) { return result; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index 233a460bc4..35e3ddb0e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -10,6 +10,7 @@ import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.rules.TestRule; @@ -39,9 +40,9 @@ public class GeneratedSource implements TestRule { * static ThreadLocal, as the {@link CompilingStatement} must inject itself statically for this rule to gain access * to the statement's information. As test execution of different classes in parallel is supported. */ - private static ThreadLocal compilingStatement = new ThreadLocal(); + private static ThreadLocal compilingStatement = new ThreadLocal<>(); - private List> fixturesFor = new ArrayList>(); + private List> fixturesFor = new ArrayList<>(); @Override public Statement apply(Statement base, Description description) { @@ -67,9 +68,7 @@ static void clearCompilingStatement() { * @return the same rule for chaining */ public GeneratedSource addComparisonToFixtureFor(Class... fixturesFor) { - for ( Class fixture : fixturesFor ) { - this.fixturesFor.add( fixture ); - } + this.fixturesFor.addAll( Arrays.asList( fixturesFor ) ); return this; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java index 119ad42674..18838ee51c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java @@ -49,7 +49,7 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe String classOutputDir, String additionalCompilerClasspath) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - DiagnosticCollector diagnostics = new DiagnosticCollector(); + DiagnosticCollector diagnostics = new DiagnosticCollector<>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager( null, null, null ); Iterable compilationUnits = @@ -97,7 +97,7 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe } private static List asFiles(List paths) { - List classpath = new ArrayList(); + List classpath = new ArrayList<>(); for ( String path : paths ) { classpath.add( new File( path ) ); } @@ -112,7 +112,7 @@ private static List asFiles(List paths) { */ @Override protected List filterExpectedDiagnostics(List expectedDiagnostics) { - List filtered = new ArrayList( expectedDiagnostics.size() ); + List filtered = new ArrayList<>( expectedDiagnostics.size() ); DiagnosticDescriptor previous = null; for ( DiagnosticDescriptor diag : expectedDiagnostics ) { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java index afb7969630..9cc41fe134 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java @@ -99,19 +99,8 @@ private static void tryRegisterAsParallelCapable() { try { ClassLoader.class.getMethod( "registerAsParallelCapable" ).invoke( null ); } - catch ( NoSuchMethodException e ) { - return; // ignore - } - catch ( SecurityException e ) { - return; // ignore - } - catch ( IllegalAccessException e ) { - return; // ignore - } - catch ( IllegalArgumentException e ) { - return; // ignore - } - catch ( InvocationTargetException e ) { + catch ( NoSuchMethodException | SecurityException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException e ) { return; // ignore } } From 59a5182dabc09d27d008b3c776751138ce5b5508 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Mon, 12 Aug 2019 22:20:53 +0300 Subject: [PATCH 0377/1006] Fix minor warnings: remove unnecessary generic type for collections, replace Charset.forName on StandartCharset --- .../testutil/runner/ProcessorSuiteRunner.java | 4 ++-- .../ap/internal/model/HelperMethod.java | 2 +- .../org/mapstruct/ap/internal/util/Strings.java | 6 +++--- .../ap/internal/writer/ModelWriter.java | 17 +++++++---------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java index c2d20e0568..cb3f601b21 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java @@ -111,7 +111,7 @@ public ProcessorSuiteRunner(Class clazz) throws InitializationError { private List initializeTestCases(ProcessorSuite suite, Constructor cliEnhancerConstructor) { - List types = new ArrayList(); + List types = new ArrayList<>(); for ( ProcessorType compiler : suite.processorTypes() ) { if ( compiler.getIncluded().length > 0 ) { @@ -190,7 +190,7 @@ private void doExecute(ProcessorTestCase child, Description description) throws verifier = new Verifier( destination.getCanonicalPath() ); } - List goals = new ArrayList( 3 ); + List goals = new ArrayList<>( 3 ); goals.add( "clean" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 5921d15179..149e713337 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -51,7 +51,7 @@ public String getName() { * @return the types used by this method for which import statements need to be generated */ public Set getImportTypes() { - return Collections.emptySet(); + return Collections.emptySet(); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 7fbca6dc44..71acee3cf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -153,12 +153,12 @@ public static String getSafeVariableName(String name, Collection existin } int c = 1; - String seperator = Character.isDigit( name.charAt( name.length() - 1 ) ) ? "_" : ""; - while ( conflictingNames.contains( name + seperator + c ) ) { + String separator = Character.isDigit( name.charAt( name.length() - 1 ) ) ? "_" : ""; + while ( conflictingNames.contains( name + separator + c ) ) { c++; } - return name + seperator + c; + return name + separator + c; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java index cb2e2a911f..2c3f762c0d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/writer/ModelWriter.java @@ -12,7 +12,7 @@ import java.io.Reader; import java.net.URL; import java.net.URLConnection; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -62,16 +62,13 @@ public class ModelWriter { } public void writeModel(FileObject sourceFile, Writable model) { - try { - BufferedWriter writer = new BufferedWriter( new IndentationCorrectingWriter( sourceFile.openWriter() ) ); - - Map, Object> values = new HashMap<>(); - values.put( Configuration.class, CONFIGURATION ); + try ( BufferedWriter writer = new BufferedWriter( new IndentationCorrectingWriter( sourceFile.openWriter() ))) { + Map, Object> values = new HashMap<>(); + values.put( Configuration.class, CONFIGURATION ); - model.write( new DefaultModelElementWriterContext( values ), writer ); + model.write( new DefaultModelElementWriterContext( values ), writer ); - writer.flush(); - writer.close(); + writer.flush(); } catch ( RuntimeException e ) { throw e; @@ -100,7 +97,7 @@ public Reader getReader(Object name, String encoding) throws IOException { InputStream is = connection.getInputStream(); - return new InputStreamReader( is, Charset.forName( "UTF-8" ) ); + return new InputStreamReader( is, StandardCharsets.UTF_8 ); } @Override From ee8f9283f2340e981d3ad99f786801329b013a89 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 11 Aug 2019 20:18:57 +0300 Subject: [PATCH 0378/1006] Simplify conditions in package org.mapstruct.ap.internal.model and classes: Conversions.java, MappingResolverImpl.java, EclipseAsMemberOfWorkaround.java --- .../ap/internal/conversion/Conversions.java | 21 +++++++------------ .../model/ContainerMappingMethod.java | 8 ++----- .../mapstruct/ap/internal/model/Field.java | 4 ++-- .../ap/internal/model/MappingMethod.java | 11 +++++----- .../model/NestedPropertyMappingMethod.java | 10 ++++----- .../NestedTargetPropertyMappingHolder.java | 3 +-- .../model/SupportingConstructorFragment.java | 10 ++++----- .../ap/internal/model/SupportingField.java | 10 ++++----- .../model/SupportingMappingMethod.java | 17 +++++---------- .../ap/internal/model/dependency/Node.java | 10 ++++----- .../creation/MappingResolverImpl.java | 7 +++---- .../EclipseAsMemberOfWorkaround.java | 2 +- 12 files changed, 44 insertions(+), 69 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 08185ac51d..6b2d5e2649 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -21,7 +21,7 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; -import javax.lang.model.util.Elements; +import java.util.Objects; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -41,7 +41,7 @@ public class Conversions { private final Type stringType; private final TypeFactory typeFactory; - public Conversions(Elements elementUtils, TypeFactory typeFactory) { + public Conversions(TypeFactory typeFactory) { this.typeFactory = typeFactory; this.enumType = typeFactory.getType( Enum.class ); @@ -341,22 +341,15 @@ public boolean equals(Object obj) { return false; } Key other = (Key) obj; - if ( sourceType == null ) { - if ( other.sourceType != null ) { - return false; - } - } - else if ( !sourceType.equals( other.sourceType ) ) { + + if ( !Objects.equals( sourceType, other.sourceType ) ) { return false; } - if ( targetType == null ) { - if ( other.targetType != null ) { - return false; - } - } - else if ( !targetType.equals( other.targetType ) ) { + + if ( !Objects.equals( targetType, other.targetType ) ) { return false; } + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 13759f5c12..382aff9737 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Assignment; @@ -117,12 +118,7 @@ public boolean equals(Object obj) { ContainerMappingMethod other = (ContainerMappingMethod) obj; - if ( this.selectionParameters != null ) { - if ( !this.selectionParameters.equals( other.selectionParameters ) ) { - return false; - } - } - else if ( other.selectionParameters != null ) { + if ( !Objects.equals( selectionParameters, other.selectionParameters ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java index 2f2df4b1fc..b1d346d82c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Field.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; @@ -113,8 +114,7 @@ public boolean equals(Object obj) { return false; } final Field other = (Field) obj; - return !( (this.variableName == null) ? - (other.variableName != null) : !this.variableName.equals( other.variableName ) ); + return Objects.equals( variableName, other.variableName ); } public static List getFieldNames(Set fields) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 4691c9cdf7..c7d329916f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -12,6 +12,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -227,15 +228,15 @@ public boolean equals(Object obj) { //Reason: Whenever we forge methods we can reuse mappings if they are the same. However, if we take the name // into consideration, they'll never be the same, because we create safe methods names. final MappingMethod other = (MappingMethod) obj; - if ( this.parameters != other.parameters && - (this.parameters == null || !this.parameters.equals( other.parameters )) ) { + + if ( !Objects.equals( parameters, other.parameters ) ) { return false; } - if ( this.returnType != other.returnType && - (this.returnType == null || !this.returnType.equals( other.returnType )) ) { + + if ( !Objects.equals( returnType, other.returnType ) ) { return false; } + return true; } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index c004baebb7..27c45a488f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; @@ -185,19 +186,18 @@ public boolean equals(Object o) { SafePropertyEntry that = (SafePropertyEntry) o; - if ( readAccessorName != null ? !readAccessorName.equals( that.readAccessorName ) : - that.readAccessorName != null ) { + if ( !Objects.equals( readAccessorName, that.readAccessorName ) ) { return false; } - if ( presenceCheckerName != null ? !presenceCheckerName.equals( that.presenceCheckerName ) : - that.presenceCheckerName != null ) { + if ( !Objects.equals( presenceCheckerName, that.presenceCheckerName ) ) { return false; } - if ( type != null ? !type.equals( that.type ) : that.type != null ) { + if ( !Objects.equals( type, that.type ) ) { return false; } + return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 87d75c0665..f074c32974 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -627,7 +627,7 @@ private Set extractSingleTargetReferencesToUseAndPopulateSourceParamete private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mappingOptions, PropertyEntry targetProperty, SourceReference sourceReference, boolean forceUpdateMethod) { - PropertyMapping propertyMapping = new PropertyMapping.PropertyMappingBuilder() + return new PropertyMapping.PropertyMappingBuilder() .mappingContext( mappingContext ) .sourceMethod( method ) .targetProperty( targetProperty ) @@ -639,7 +639,6 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mapp .forceUpdateMethod( forceUpdateMethod ) .forgedNamedBased( false ) .build(); - return propertyMapping; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java index 14a13ca735..f25bbfca9f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.Collections; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; @@ -62,14 +63,11 @@ public boolean equals(Object obj) { return false; } SupportingConstructorFragment other = (SupportingConstructorFragment) obj; - if ( templateName == null ) { - if ( other.templateName != null ) { - return false; - } - } - else if ( !templateName.equals( other.templateName ) ) { + + if ( !Objects.equals( templateName, other.templateName ) ) { return false; } + return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java index e9d0d1e3ca..a92f4c9df4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference; @@ -54,14 +55,11 @@ public boolean equals(Object obj) { return false; } SupportingField other = (SupportingField) obj; - if ( templateName == null ) { - if ( other.templateName != null ) { - return false; - } - } - else if ( !templateName.equals( other.templateName ) ) { + + if ( !Objects.equals( templateName, other.templateName ) ) { return false; } + return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java index 8827bc5d35..756330e5d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; @@ -54,7 +55,6 @@ public SupportingMappingMethod(BuiltInMethod method, Set existingFields) } private Field getSafeField(BuiltInFieldReference ref, Set existingFields) { - Field result = null; String name = ref.getVariableName(); for ( Field existingField : existingFields ) { if ( existingField.getType().equals( ref.getType() ) ) { @@ -68,11 +68,7 @@ private Field getSafeField(BuiltInFieldReference ref, Set existingFields) name = Strings.getSafeVariableName( name, Field.getFieldNames( existingFields ) ); } } - if ( result == null ) { - result = new SupportingField( this, ref, name ); - } - - return result; + return new SupportingField( this, ref, name ); } public SupportingMappingMethod(HelperMethod method) { @@ -144,14 +140,11 @@ public boolean equals(Object obj) { return false; } SupportingMappingMethod other = (SupportingMappingMethod) obj; - if ( templateName == null ) { - if ( other.templateName != null ) { - return false; - } - } - else if ( !templateName.equals( other.templateName ) ) { + + if ( !Objects.equals( templateName, other.templateName ) ) { return false; } + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java index 445b01692c..883731ac7c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/Node.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * A node of a directed graph. @@ -86,14 +87,11 @@ public boolean equals(Object obj) { return false; } Node other = (Node) obj; - if ( name == null ) { - if ( other.name != null ) { - return false; - } - } - else if ( !name.equals( other.name ) ) { + + if ( !Objects.equals( name, other.name ) ) { return false; } + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index cf3c588f0d..3a20a969de 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -89,7 +89,7 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T this.sourceModel = sourceModel; this.mapperReferences = mapperReferences; - this.conversions = new Conversions( elementUtils, typeFactory ); + this.conversions = new Conversions( typeFactory ); this.builtInMethods = new BuiltInMappingMethods( typeFactory ); this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, typeFactory, messager ); } @@ -307,7 +307,7 @@ private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean co SelectedMethod matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); if ( matchingSourceMethod != null ) { - return getMappingMethodReference( matchingSourceMethod, targetType ); + return getMappingMethodReference( matchingSourceMethod ); } if ( considerBuiltInMethods ) { @@ -555,8 +555,7 @@ private SelectedMethod getBestMatch(List methods, Type return null; } - private Assignment getMappingMethodReference(SelectedMethod method, - Type targetType) { + private Assignment getMappingMethodReference(SelectedMethod method) { MapperReference mapperReference = findMapperReference( method.getMethod() ); return MethodReference.forMapperReference( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java index 54aebe03be..739246a6c6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java @@ -84,7 +84,7 @@ static TypeMirror asMemberOf(ProcessingEnvironment environment, DeclaredType con } private static T tryCast(Object instance, Class type) { - if ( instance != null && type.isInstance( instance ) ) { + if ( type.isInstance( instance ) ) { return type.cast( instance ); } From 55048ab045ef1cf6e2d10b25ba76682a0725bac8 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 18 Aug 2019 22:09:03 +0300 Subject: [PATCH 0379/1006] Simplify consistent checks in class Mapping --- .../model/dependency/GraphAnalyzer.java | 15 +-- .../ap/internal/model/source/BeanMapping.java | 2 +- .../ap/internal/model/source/Mapping.java | 103 ++++-------------- 3 files changed, 26 insertions(+), 94 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java index b9c4540d77..06acfc24b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/dependency/GraphAnalyzer.java @@ -116,10 +116,10 @@ public static class GraphAnalyzerBuilder { private final Map nodes = new LinkedHashMap<>(); public GraphAnalyzerBuilder withNode(String name, Set descendants) { - Node node = getNode( name ); + Node node = nodes.computeIfAbsent( name, Node::new ); for ( String descendant : descendants ) { - node.addDescendant( getNode( descendant ) ); + node.addDescendant( nodes.computeIfAbsent( descendant, Node::new ) ); } return this; @@ -140,16 +140,5 @@ public GraphAnalyzer build() { graphAnalyzer.analyze(); return graphAnalyzer; } - - private Node getNode(String name) { - Node node = nodes.get( name ); - - if ( node == null ) { - node = new Node( name ); - nodes.put( name, node ); - } - - return node; - } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index 9c05e382a7..d28205ca09 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -128,7 +128,7 @@ public static BeanMapping forForgedMethods() { null, ReportingPolicyPrism.IGNORE, false, - Collections.emptyList(), + Collections.emptyList(), null ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index 5e3de4208f..c2fe0a4e26 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -132,7 +132,7 @@ public static Mapping fromMappingPrism(MappingPrism mappingPrism, ExecutableElem boolean resultTypeIsDefined = mappingPrism.values.resultType() != null; Set dependsOn = mappingPrism.dependsOn() != null ? new LinkedHashSet( mappingPrism.dependsOn() ) : - Collections.emptySet(); + Collections.emptySet(); FormattingParameters formattingParam = new FormattingParameters( dateFormat, @@ -214,116 +214,59 @@ private static boolean isConsistent(MappingPrism mappingPrism, ExecutableElement return false; } + Message message = null; if ( !mappingPrism.source().isEmpty() && mappingPrism.values.constant() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED; } else if ( !mappingPrism.source().isEmpty() && mappingPrism.values.expression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.constant() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED; } else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED; } else if ( mappingPrism.values.expression() != null && mappingPrism.values.defaultExpression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultExpression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED - ); - return false; + message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.values.defaultValue() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS - ); - return false; + message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS; } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.values.constant() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS - ); - return false; + message = Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS; } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.values.expression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS - ); - return false; + message = Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS; } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.values.defaultExpression() != null ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS - ); - return false; + message = Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS; } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.ignore() != null && mappingPrism.ignore() ) { - messager.printMessage( - element, - mappingPrism.mirror, - Message.PROPERTYMAPPING_IGNORE_AND_NVPMS - ); + message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS; + } + + if ( message == null ) { + return true; + } + else { + messager.printMessage( element, mappingPrism.mirror, message ); return false; } - return true; } @SuppressWarnings("checkstyle:parameternumber") @@ -576,7 +519,7 @@ public Mapping copyForInverseInheritance(SourceMethod method ) { formattingParameters, selectionParameters, dependsOnAnnotationValue, - Collections.emptySet(), + Collections.emptySet(), nullValueCheckStrategy, nullValuePropertyMappingStrategy, new InheritContext( true, false, method ) From 8e37159a00041104a20ba8a8eaa786b7cc9bd92d Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Thu, 22 Aug 2019 15:52:05 +0300 Subject: [PATCH 0380/1006] Fix minor warnings: remove unnecessary generic type for collections, remove unnecessary exceptions from signature, fix typos --- .../ReferencedAccessibilityTest.java | 12 ++++---- .../ap/test/builder/lifecycle/Order.java | 4 +-- .../ap/test/callbacks/returning/Node.java | 4 +-- .../returning/NodeMapperContext.java | 2 +- .../returning/NumberMapperContext.java | 7 ++--- .../test/collection/adder/_target/Target.java | 6 ++-- .../adder/_target/TargetOnlyGetter.java | 6 ++-- .../adder/_target/TargetWithAnimals.java | 2 +- .../ap/test/context/CycleContext.java | 2 +- .../currency/CurrencyConversionTest.java | 2 +- .../conversion/lossy/LossyConversionTest.java | 6 ++-- .../lossy/VerySpecialNumberMapper.java | 5 ++-- .../nativetypes/BooleanConversionTest.java | 2 +- .../nativetypes/CharConversionTest.java | 2 +- .../nativetypes/NumberConversionTest.java | 2 +- .../numbers/NumberFormatConversionTest.java | 2 +- .../test/defaultvalue/DefaultValueTest.java | 6 ++-- .../ap/test/dependency/OrderingTest.java | 2 +- .../SourceTargetMapperAndBar2Factory.java | 4 +-- .../org/mapstruct/ap/test/fields/Source.java | 2 +- .../ap/test/ignore/inherit/ToolMapper.java | 2 +- .../ap/test/java8stream/base/StreamsTest.java | 30 +++++++++---------- ...DisablingNestedSimpleBeansMappingTest.java | 4 +-- .../exclusions/ErroneousJavaInternalTest.java | 2 +- .../ap/test/nestedbeans/other/CarDto.java | 5 ++-- .../ap/test/nestedbeans/other/HouseDto.java | 6 ++-- .../NestedSourcePropertiesTest.java | 2 +- .../NullValueMappingTest.java | 2 +- .../NullValuePropertyMappingTest.java | 2 +- 29 files changed, 67 insertions(+), 68 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index eb36ad9664..424b815718 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -43,19 +43,19 @@ public class ReferencedAccessibilityTest { ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") } ) - public void shouldNotBeAbleToAccessPrivateMethodInReferenced() throws Exception { + public void shouldNotBeAbleToAccessPrivateMethodInReferenced() { generatedSource.addComparisonToFixtureFor( SourceTargetMapperPrivate.class ); } @Test @IssueKey( "206" ) @WithClasses( { SourceTargetMapperDefaultSame.class, ReferencedMapperDefaultSame.class } ) - public void shouldBeAbleToAccessDefaultMethodInReferencedInSamePackage() throws Exception { } + public void shouldBeAbleToAccessDefaultMethodInReferencedInSamePackage() { } @Test @IssueKey( "206" ) @WithClasses( { SourceTargetMapperProtected.class, ReferencedMapperProtected.class } ) - public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() throws Exception { } + public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() { } @Test @IssueKey("206") @@ -71,14 +71,14 @@ public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() throw ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") } ) - public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() throws Exception { + public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() { generatedSource.addComparisonToFixtureFor( SourceTargetMapperDefaultOther.class ); } @Test @IssueKey( "206" ) @WithClasses( { AbstractSourceTargetMapperProtected.class, SourceTargetmapperProtectedBase.class } ) - public void shouldBeAbleToAccessProtectedMethodInBase() throws Exception { } + public void shouldBeAbleToAccessProtectedMethodInBase() { } @Test @IssueKey("206") @@ -94,7 +94,7 @@ public void shouldBeAbleToAccessProtectedMethodInBase() throws Exception { } ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") } ) - public void shouldNotBeAbleToAccessPrivateMethodInBase() throws Exception { + public void shouldNotBeAbleToAccessPrivateMethodInBase() { generatedSource.addComparisonToFixtureFor( AbstractSourceTargetMapperPrivate.class ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java index 5342a5e444..54316bf774 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/Order.java @@ -17,7 +17,7 @@ public class Order { private final String creator; public Order(Builder builder) { - this.items = new ArrayList( builder.items ); + this.items = new ArrayList<>( builder.items ); this.creator = builder.creator; } @@ -34,7 +34,7 @@ public static Builder builder() { } public static class Builder { - private List items = new ArrayList(); + private List items = new ArrayList<>(); private String creator; public Builder items(List items) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java index c939ec7d3d..2ee619c61d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/Node.java @@ -25,8 +25,8 @@ public Node() { public Node(String name) { this.name = name; - this.children = new ArrayList(); - this.attributes = new ArrayList(); + this.children = new ArrayList<>(); + this.attributes = new ArrayList<>(); } public Node getParent() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java index def62dab8d..40a1a63937 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java @@ -48,7 +48,7 @@ public static void setInstance(Object source, @MappingTarget Object target) { fireMethodCalled( level, "setInstance", source, target ); if ( level == null ) { LEVEL.set( 1 ); - MAPPING.set( new IdentityHashMap() ); + MAPPING.set( new IdentityHashMap<>() ); } else { LEVEL.set( level + 1 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java index 7ce3510775..bbbe9c6bec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NumberMapperContext.java @@ -19,9 +19,9 @@ * @author Pascal Grün */ public class NumberMapperContext { - private static final Map CACHE = new HashMap(); + private static final Map CACHE = new HashMap<>(); - private static final List VISITED = new ArrayList(); + private static final List VISITED = new ArrayList<>(); private NumberMapperContext() { // Only allow static access @@ -45,8 +45,7 @@ public static void clearVisited() { @AfterMapping public static Number getInstance(Integer source, @MappingTarget Number target) { - Number cached = CACHE.get( target ); - return ( cached == null ? null : cached ); + return CACHE.get( target ); } @AfterMapping diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java index 0a112ac216..b131bd96ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target.java @@ -24,15 +24,15 @@ public void setPets(List pets) { } public void addCat(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public void addDog(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public void addPets(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public Long addPet(Long pet) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java index 09a3bc8e43..d9d593a230 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetOnlyGetter.java @@ -20,15 +20,15 @@ public List getPets() { } public void addCat(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public void addDog(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public void addPets(Long cat) { - // dummy method to test selection mechanims + // dummy method to test selection mechanism } public void addPet(Long pet) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java index 5005251235..10770922bd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/TargetWithAnimals.java @@ -13,7 +13,7 @@ */ public class TargetWithAnimals { - private List animals = new ArrayList(); + private List animals = new ArrayList<>(); public List getAnimals() { return animals; diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java index 48a82df57d..da6c87ecdf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/CycleContext.java @@ -16,7 +16,7 @@ * @author Andreas Gudian */ public class CycleContext { - private Map knownInstances = new IdentityHashMap(); + private Map knownInstances = new IdentityHashMap<>(); @SuppressWarnings("unchecked") public T getMappedInstance(Object source, Class targetType) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java index 80e0f9ffb0..092388e2e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java @@ -30,7 +30,7 @@ public class CurrencyConversionTest { public void shouldApplyCurrencyConversions() { final CurrencySource source = new CurrencySource(); source.setCurrencyA( Currency.getInstance( "USD" ) ); - Set currencies = new HashSet(); + Set currencies = new HashSet<>(); currencies.add( Currency.getInstance( "EUR" ) ); currencies.add( Currency.getInstance( "CHF" ) ); source.setUniqueCurrencies( currencies ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index de1921ea5d..a9bd35c2b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -61,7 +61,7 @@ public void testNoErrorCase() { messageRegExp = "Can't map property \"long numberOfForks\". It has a possibly lossy conversion from " + "long to int.") }) - public void testConversionFromlongToint() { + public void testConversionFromLongToInt() { } @Test @@ -100,7 +100,7 @@ public void test2StepConversionFromBigIntegerToLong() { messageRegExp = "Can't map property \"java.lang.Double depth\". It has a possibly lossy conversion " + "from java.lang.Double to float.") }) - public void testConversionFromDoubleTofloat() { + public void testConversionFromDoubleToFloat() { } @Test @@ -125,7 +125,7 @@ public void testConversionFromBigDecimalToFloat() { line = 24, messageRegExp = "property \"double height\" has a possibly lossy conversion from double to float.") }) - public void test2StepConversionFromdoubleTofloat() { + public void test2StepConversionFromDoubleToFloat() { } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java index 29531bea0b..d49a263deb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java @@ -8,16 +8,15 @@ import java.math.BigInteger; /** - * * @author Sjaak Derksen */ public class VerySpecialNumberMapper { - VerySpecialNumber fromFLoat( float f ) { + VerySpecialNumber fromFloat(float f) { return new VerySpecialNumber(); } - BigInteger toBigInteger( VerySpecialNumber v ) { + BigInteger toBigInteger(VerySpecialNumber v) { return new BigInteger( "10" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java index 9e10dbf959..0f90586007 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java @@ -49,7 +49,7 @@ public void shouldApplyReverseBooleanConversion() { @Test @IssueKey( "229" ) - public void wrapperToPrimitveIsNullSafe() { + public void wrapperToPrimitiveIsNullSafe() { BooleanTarget target = new BooleanTarget(); BooleanSource source = BooleanMapper.INSTANCE.targetToSource( target ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java index cb5192d42f..29b8b76484 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java @@ -45,7 +45,7 @@ public void shouldApplyReverseCharConversion() { @Test @IssueKey( "229" ) - public void wrapperToPrimitveIsNullSafe() { + public void wrapperToPrimitiveIsNullSafe() { CharTarget target = new CharTarget(); CharSource source = CharMapper.INSTANCE.targetToSource( target ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java index b0dedb61c1..bba6b9fc27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java @@ -441,7 +441,7 @@ public void shouldApplyDoubleWrapperConversions() { @Test @IssueKey( "229" ) - public void wrapperToPrimitveIsNullSafe() { + public void wrapperToPrimitiveIsNullSafe() { assertThat( SourceTargetMapper.INSTANCE.sourceToTarget( new ByteWrapperSource() ) ).isNotNull(); assertThat( SourceTargetMapper.INSTANCE.sourceToTarget( new DoubleWrapperSource() ) ).isNotNull(); assertThat( SourceTargetMapper.INSTANCE.sourceToTarget( new ShortWrapperSource() ) ).isNotNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index ed358ff6b8..ad2caecfd3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -133,7 +133,7 @@ public void shouldApplyStringConversionsToIterables() { @Test public void shouldApplyStringConversionsToMaps() { - Map source1 = new HashMap(); + Map source1 = new HashMap<>(); source1.put( 1.0001f, 2.01f ); Map target = SourceTargetMapper.INSTANCE.sourceToTarget( source1 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index 9107b4eb2a..e554e4a4b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -7,8 +7,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.text.ParseException; - import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.defaultvalue.other.Continent; @@ -134,7 +132,7 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") } ) - public void errorOnDefaultValueAndConstant() throws ParseException { + public void errorOnDefaultValueAndConstant() { } @Test @@ -156,7 +154,7 @@ public void errorOnDefaultValueAndConstant() throws ParseException { messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") } ) - public void errorOnDefaultValueAndExpression() throws ParseException { + public void errorOnDefaultValueAndExpression() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index fd091d21a7..3faa85f78c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -84,6 +84,6 @@ public void shouldReportErrorIfDependenciesContainCycle() { ) } ) - public void shouldReportErrorIfPropertiyGivenInDependsOnDoesNotExist() { + public void shouldReportErrorIfPropertyGivenInDependsOnDoesNotExist() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java index 2e33bf3ff8..568b9abf2a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/SourceTargetMapperAndBar2Factory.java @@ -40,10 +40,10 @@ public Bar2 createBar2() { } public CustomList createCustomList() { - return new CustomListImpl( "CUSTOMLIST" ); + return new CustomListImpl<>( "CUSTOMLIST" ); } public CustomMap createCustomMap() { - return new CustomMapImpl( "CUSTOMMAP" ); + return new CustomMapImpl<>( "CUSTOMMAP" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java b/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java index 1592b9e849..9e8137aee8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/Source.java @@ -22,7 +22,7 @@ public class Source { public Integer fieldOnlyWithGetter; // CHECKSTYLE:ON - private final List privateFinalList = new ArrayList( Arrays.asList( 3, 4, 5 ) ); + private final List privateFinalList = new ArrayList<>( Arrays.asList( 3, 4, 5 ) ); public List getPrivateFinalList() { return privateFinalList; diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java index f2126a3136..ca7da9b99c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java @@ -29,7 +29,7 @@ public interface ToolMapper { @InheritConfiguration( name = "mapBase" ) ToolEntity mapTool(ToolDto source); - // demonstrates that all the businss stuff is mapped (implicit-by-name and defined) + // demonstrates that all the business stuff is mapped (implicit-by-name and defined) @InheritConfiguration( name = "mapBase" ) @Mapping(target = "description", source = "articleDescription") WorkBenchEntity mapBench(WorkBenchDto source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java index 5f6f74d1b6..c91889e063 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java @@ -40,7 +40,7 @@ public class StreamsTest { public final GeneratedSource generatedSource = new GeneratedSource(); @Test - public void shouldNotContainFunctionIdentity() throws Exception { + public void shouldNotContainFunctionIdentity() { generatedSource.forMapper( StreamMapper.class ) .content() .as( "The Mapper implementation should not use Function.identity()" ) @@ -48,24 +48,24 @@ public void shouldNotContainFunctionIdentity() throws Exception { } @Test - public void shouldMapSourceStream() throws Exception { + public void shouldMapSourceStream() { List someInts = Arrays.asList( 1, 2, 3 ); Stream stream = someInts.stream(); Source source = new Source(); source.setStream( stream ); - source.setStringStream( Arrays.asList( "4", "5", "6", "7" ).stream() ); + source.setStringStream( Stream.of( "4", "5", "6", "7" ) ); source.setInts( Arrays.asList( 1, 2, 3 ) ); - source.setIntegerSet( Arrays.asList( 1, 1, 2, 2, 4, 4 ).stream() ); - source.setStringCollection( Arrays.asList( "1", "1", "2", "3" ).stream().distinct() ); - source.setIntegerIterable( Arrays.asList( 10, 11, 12 ).stream() ); - source.setSortedSet( Arrays.asList( 12, 11, 10 ).stream() ); - source.setNavigableSet( Arrays.asList( 12, 11, 10 ).stream() ); - source.setIntToStringStream( Arrays.asList( 10, 11, 12 ).stream() ); - source.setStringArrayStream( Arrays.asList( "4", "5", "6", "6" ).stream().limit( 2 ) ); + source.setIntegerSet( Stream.of( 1, 1, 2, 2, 4, 4 ) ); + source.setStringCollection( Stream.of( "1", "1", "2", "3" ).distinct() ); + source.setIntegerIterable( Stream.of( 10, 11, 12 ) ); + source.setSortedSet( Stream.of( 12, 11, 10 ) ); + source.setNavigableSet( Stream.of( 12, 11, 10 ) ); + source.setIntToStringStream( Stream.of( 10, 11, 12 ) ); + source.setStringArrayStream( Stream.of( "4", "5", "6", "6" ).limit( 2 ) ); SourceElement element = new SourceElement(); element.setSource( "source1" ); - source.setSourceElements( Arrays.asList( element ).stream() ); + source.setSourceElements( Stream.of( element ) ); Target target = StreamMapper.INSTANCE.map( source ); @@ -85,18 +85,18 @@ public void shouldMapSourceStream() throws Exception { } @Test - public void shouldMapTargetStream() throws Exception { + public void shouldMapTargetStream() { List someInts = Arrays.asList( 1, 2, 3 ); Stream stream = someInts.stream(); Target target = new Target(); target.setTargetStream( stream ); target.setStringStream( Arrays.asList( "4", "5", "6", "7" ) ); - target.setInts( Arrays.asList( 1, 2, 3 ).stream() ); + target.setInts( Stream.of( 1, 2, 3 ) ); target.setIntegerSet( Collections.asSet( 1, 1, 2, 2, 4, 4 ) ); target.setStringCollection( Collections.asSet( "1", "1", "2", "3" ) ); target.setIntegerIterable( Arrays.asList( 10, 11, 12 ) ); - target.setSortedSet( new TreeSet( Arrays.asList( 12, 11, 10 ) ) ); - target.setNavigableSet( new TreeSet( Arrays.asList( 12, 11, 10 ) ) ); + target.setSortedSet( new TreeSet<>( Arrays.asList( 12, 11, 10 ) ) ); + target.setNavigableSet( new TreeSet<>( Arrays.asList( 12, 11, 10 ) ) ); target.setIntToStringStream( Arrays.asList( "4", "5", "6" ) ); target.setStringArrayStream( new Integer[] { 10, 11, 12 } ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index 3236429fce..b7dd9b70ac 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -38,7 +38,7 @@ public class DisablingNestedSimpleBeansMappingTest { ) }) @Test - public void shouldUseDisabledMethodGenerationOnMapper() throws Exception { + public void shouldUseDisabledMethodGenerationOnMapper() { } @WithClasses({ @@ -55,6 +55,6 @@ public void shouldUseDisabledMethodGenerationOnMapper() throws Exception { ) }) @Test - public void shouldUseDisabledMethodGenerationOnMapperConfig() throws Exception { + public void shouldUseDisabledMethodGenerationOnMapperConfig() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index cd05ad64be..6f50266f2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -53,6 +53,6 @@ public class ErroneousJavaInternalTest { "mapping method: \".*List<.*String> map\\(.*List<.*MyType> value\\)\"\\.") }) @Test - public void shouldNotNestIntoJavaPackageObjects() throws Exception { + public void shouldNotNestIntoJavaPackageObjects() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java index 682eac481b..a7b27970ce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/CarDto.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans.other; import java.util.List; +import java.util.Objects; public class CarDto { @@ -60,10 +61,10 @@ public boolean equals(Object o) { if ( year != carDto.year ) { return false; } - if ( name != null ? !name.equals( carDto.name ) : carDto.name != null ) { + if ( !Objects.equals( name, carDto.name ) ) { return false; } - return wheels != null ? wheels.equals( carDto.wheels ) : carDto.wheels == null; + return Objects.equals( wheels, carDto.wheels ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java index 29ed80a8a2..d7b0631f41 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/other/HouseDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans.other; +import java.util.Objects; + public class HouseDto { private String name; @@ -58,10 +60,10 @@ public boolean equals(Object o) { if ( year != houseDto.year ) { return false; } - if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) { + if ( !Objects.equals( name, houseDto.name ) ) { return false; } - return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null; + return Objects.equals( roof, houseDto.roof ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index d300c1a2a1..7a1187f05d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -175,6 +175,6 @@ public void shouldUseGetAsTargetAccessor() { } ) @WithClasses({ ArtistToChartEntryErroneous.class }) - public void inverseShouldRaiseErrorForEmptyContructor() { + public void inverseShouldRaiseErrorForEmptyConstructor() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java index e316f20866..6d893f1375 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java @@ -42,7 +42,7 @@ public class NullValueMappingTest { @Test - public void shouldProvideMapperInstance() throws Exception { + public void shouldProvideMapperInstance() { assertThat( CarMapper.INSTANCE ).isNotNull(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index 75cb93bf3e..a7f8e6bb9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -76,7 +76,7 @@ public void testHierarchyIgnoreOnBeanMappingMethod() { @Test @WithClasses(CustomerNvpmsPropertyMappingMapper.class) - public void testHierarchyIgnoreOnPropertyMappingMehtod() { + public void testHierarchyIgnoreOnPropertyMappingMethod() { testConfig( CustomerNvpmsPropertyMappingMapper.INSTANCE::map ); } From ba90c95f232b144f6b73033e3371e7f8a9e65f56 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 24 Aug 2019 20:51:16 +0300 Subject: [PATCH 0381/1006] #991 Split reference guide source into an adoc file per chapter --- .../asciidoc/chapter-1-introduction.asciidoc | 16 + ...apter-10-advanced-mapping-options.asciidoc | 302 ++ ...11-reusing-mapping-configurations.asciidoc | 163 + .../chapter-12-customizing-mapping.asciidoc | 270 ++ .../chapter-13-using-mapstruct-spi.asciidoc | 200 ++ .../main/asciidoc/chapter-2-set-up.asciidoc | 286 ++ .../chapter-3-defining-a-mapper.asciidoc | 454 +++ .../chapter-4-retrieving-a-mapper.asciidoc | 129 + .../chapter-5-data-type-conversions.asciidoc | 621 ++++ .../chapter-6-mapping-collections.asciidoc | 227 ++ ...doc => chapter-7-mapping-streams.asciidoc} | 0 .../chapter-8-mapping-values.asciidoc | 143 + .../chapter-9-object-factories.asciidoc | 170 + .../controlling-nested-bean-mappings.asciidoc | 89 - .../mapstruct-reference-guide.asciidoc | 2909 +---------------- 15 files changed, 2994 insertions(+), 2985 deletions(-) create mode 100644 documentation/src/main/asciidoc/chapter-1-introduction.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-2-set-up.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc rename documentation/src/main/asciidoc/{mapping-streams.asciidoc => chapter-7-mapping-streams.asciidoc} (100%) create mode 100644 documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc create mode 100644 documentation/src/main/asciidoc/chapter-9-object-factories.asciidoc delete mode 100644 documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc diff --git a/documentation/src/main/asciidoc/chapter-1-introduction.asciidoc b/documentation/src/main/asciidoc/chapter-1-introduction.asciidoc new file mode 100644 index 0000000000..1d73a11078 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-1-introduction.asciidoc @@ -0,0 +1,16 @@ +[[introduction]] +== Introduction + +MapStruct is a Java http://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html[annotation processor] for the generation of type-safe bean mapping classes. + +All you have to do is to define a mapper interface which declares any required mapping methods. During compilation, MapStruct will generate an implementation of this interface. This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar. + +Compared to writing mapping code from hand, MapStruct saves time by generating code which is tedious and error-prone to write. Following a convention over configuration approach, MapStruct uses sensible defaults but steps out of your way when it comes to configuring or implementing special behavior. + +Compared to dynamic mapping frameworks, MapStruct offers the following advantages: + +* Fast execution by using plain method invocations instead of reflection +* Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc. +* Clear error-reports at build time, if +** mappings are incomplete (not all target properties are mapped) +** mappings are incorrect (cannot find a proper mapping method or type conversion) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc new file mode 100644 index 0000000000..a3836d048f --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -0,0 +1,302 @@ +== Advanced mapping options +This chapter describes several advanced options which allow to fine-tune the behavior of the generated mapping code as needed. + +[[default-values-and-constants]] +=== Default values and constants + +Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values. When the target type is a primitive or a boxed type, the String value is taken literal. Bit / octal / decimal / hex patterns are allowed in such case as long as they are a valid literal. +In all other cases, constant or default values are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. + +A mapping with a constant must not include a reference to a source property. The following example shows some mappings using default values and constants: + +.Mapping method with default values and constants +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses = StringListMapper.class) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined") + @Mapping(target = "longProperty", source = "longProp", defaultValue = "-1") + @Mapping(target = "stringConstant", constant = "Constant Value") + @Mapping(target = "integerConstant", constant = "14") + @Mapping(target = "longWrapperConstant", constant = "3001") + @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014") + @Mapping(target = "stringListConstants", constant = "jack-jill-tom") + Target sourceToTarget(Source s); +} +---- +==== + +If `s.getStringProp() == null`, then the target property `stringProperty` will be set to `"undefined"` instead of applying the value from `s.getStringProp()`. If `s.getLongProperty() == null`, then the target property `longProperty` will be set to `-1`. +The String `"Constant Value"` is set as is to the target property `stringConstant`. The value `"3001"` is type-converted to the `Long` (wrapper) class of target property `longWrapperConstant`. Date properties also require a date format. The constant `"jack-jill-tom"` demonstrates how the hand-written class `StringListMapper` is invoked to map the dash-separated list into a `List`. + +[[expressions]] +=== Expressions + +By means of Expressions it will be possible to include constructs from a number of languages. + +Currently only Java is supported as a language. This feature is e.g. useful to invoke constructors. The entire source object is available for usage in the expression. Care should be taken to insert only valid Java code: MapStruct will not validate the expression at generation-time, but errors will show up in the generated classes during compilation. + +The example below demonstrates how two source properties can be mapped to one target: + +.Mapping method using an expression +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target = "timeAndFormat", + expression = "java( new org.sample.TimeAndFormat( s.getTime(), s.getFormat() ) )") + Target sourceToTarget(Source s); +} +---- +==== + +The example demonstrates how the source properties `time` and `format` are composed into one target property `TimeAndFormat`. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `TimeAndFormat` class (unless it's used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining `imports` on the `@Mapper` annotation. + +.Declaring an import +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +imports org.sample.TimeAndFormat; + +@Mapper( imports = TimeAndFormat.class ) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target = "timeAndFormat", + expression = "java( new TimeAndFormat( s.getTime(), s.getFormat() ) )") + Target sourceToTarget(Source s); +} +---- +==== + +[[default-expressions]] +=== Default Expressions + +Default expressions are a combination of default values and expressions. They will only be used when the source attribute is `null`. + +The same warnings and restrictions apply to default expressions that apply to expressions. Only Java is supported, and MapStruct will not validate the expression at generation-time. + +The example below demonstrates how two source properties can be mapped to one target: + +.Mapping method using a default expression +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +imports java.util.UUID; + +@Mapper( imports = UUID.class ) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target="id", source="sourceId", defaultExpression = "java( UUID.randomUUID().toString() )") + Target sourceToTarget(Source s); +} +---- +==== + +The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation ((see <>). + +[[determining-result-type]] +=== Determining the result type + +When result types have an inheritance relation, selecting either mapping method (`@Mapping`) or a factory method (`@BeanMapping`) can become ambiguous. Suppose an Apple and a Banana, which are both specializations of Fruit. + +.Specifying the result type of a bean mapping method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper( uses = FruitFactory.class ) +public interface FruitMapper { + + @BeanMapping( resultType = Apple.class ) + Fruit map( FruitDto source ); + +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class FruitFactory { + + public Apple createApple() { + return new Apple( "Apple" ); + } + + public Banana createBanana() { + return new Banana( "Banana" ); + } +} +---- +==== + +So, which `Fruit` must be factorized in the mapping method `Fruit map(FruitDto source);`? A `Banana` or an `Apple`? Here's were the `@BeanMapping#resultType` comes in handy. It controls the factory method to select, or in absence of a factory method, the return type to create. + +[TIP] +==== +The same mechanism is present on mapping: `@Mapping#resultType` and works like you expect it would: it selects the mapping method with the desired result type when present. +==== + +[TIP] +==== +The mechanism is also present on iterable mapping and map mapping. `@IterableMapping#elementTargetType` is used to select the mapping method with the desired element in the resulting `Iterable`. For the `@MapMapping` a similar purpose is served by means of `#MapMapping#keyTargetType` and `MapMapping#valueTargetType`. +==== + +[[mapping-result-for-null-arguments]] +=== Controlling mapping result for 'null' arguments + +MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. By default `null` will be returned. + +However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MappingConfig`, the mapping result can be altered to return empty *default* values. This means for: + +* *Bean mappings*: an 'empty' target bean will be returned, with the exception of constants and expressions, they will be populated when present. +* *Iterables / Arrays*: an empty iterable will be returned. +* *Maps*: an empty map will be returned. + +The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`. + + +[[mapping-result-for-null-properties]] +=== Controlling mapping result for 'null' properties in bean mappings (update mapping methods only). + +MapStruct offers control over the property to set in an `@MappingTarget` annotated target bean when the source property equals `null` or the presence check method results in 'absent'. + +By default the target property will be set to null. + +However: + +1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. +For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. +For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. + +2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. + +The strategy works in a hierarchical fashion. Setting `Mapping#nullValuePropertyMappingStrategy` on mapping level will override `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. + +[NOTE] +==== +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property +null check, regardless the value of the `NullValuePropertyMappingStrategy` to avoid addition of `null` to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. +==== + +[TIP] +==== +`NullValuePropertyMappingStrategy` also applies when the presense checker returns `not present`. +==== + +[[checking-source-property-for-null-arguments]] +=== Controlling checking result for 'null' properties in bean mapping + +MapStruct offers control over when to generate a `null` check. By default (`nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION`) a `null` check will be generated for: + +* direct setting of source value to target value when target is primitive and source is not. +* applying type conversion and then: +.. calling the setter on the target. +.. calling another type conversion and subsequently calling the setter on the target. +.. calling a mapping method and subsequently calling the setter on the target. + +First calling a mapping method on the source property is not protected by a null check. Therefor generated mapping methods will do a null check prior to carrying out mapping on a source property. Handwritten mapping methods must take care of null value checking. They have the possibility to add 'meaning' to `null`. For instance: mapping `null` to a default value. + +The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. + +The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. + +[[source-presence-check]] +=== Source presence checking +Some frameworks generate bean properties that have a source presence checker. Often this is in the form of a method `hasXYZ`, `XYZ` being a property on the source bean in a bean mapping method. MapStruct will call this `hasXYZ` instead of performing a `null` check when it finds such `hasXYZ` method. + +[TIP] +==== +The source presence checker name can be changed in the MapStruct service provider interface (SPI). It can also be deactivated in this way. +==== + +[NOTE] +==== +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property +null check, regardless the value of the `NullValueheckStrategy` to avoid addition of `null` to the target collection or map. +==== +[[exceptions]] +=== Exceptions + +Calling applications may require handling of exceptions when calling a mapping method. These exceptions could be thrown by hand-written logic and by the generated built-in mapping methods or type-conversions of MapStruct. When the calling application requires handling of exceptions, a throws clause can be defined in the mapping method: + +.Mapper using custom method declaring checked exception +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses = HandWritten.class) +public interface CarMapper { + + CarDto carToCarDto(Car car) throws GearException; +} +---- +==== + +The hand written logic might look like this: + +.Custom mapping method declaring checked exception +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class HandWritten { + + private static final String[] GEAR = {"ONE", "TWO", "THREE", "OVERDRIVE", "REVERSE"}; + + public String toGear(Integer gear) throws GearException, FatalException { + if ( gear == null ) { + throw new FatalException("null is not a valid gear"); + } + + if ( gear < 0 && gear > GEAR.length ) { + throw new GearException("invalid gear"); + } + return GEAR[gear]; + } +} +---- +==== + +MapStruct now, wraps the `FatalException` in a `try-catch` block and rethrows an unchecked `RuntimeException`. MapStruct delegates handling of the `GearException` to the application logic because it is defined as throws clause in the `carToCarDto` method: + +.try-catch block in generated implementation +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public CarDto carToCarDto(Car car) throws GearException { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + try { + carDto.setGear( handWritten.toGear( car.getGear() ) ); + } + catch ( FatalException e ) { + throw new RuntimeException( e ); + } + + return carDto; +} +---- +==== + +Some **notes** on null checks. MapStruct does provide null checking only when required: when applying type-conversions or constructing a new type by invoking its constructor. This means that the user is responsible in hand-written code for returning valid non-null objects. Also null objects can be handed to hand-written code, since MapStruct does not want to make assumptions on the meaning assigned by the user to a null object. Hand-written code has to deal with this. \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc new file mode 100644 index 0000000000..2b47579ec8 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc @@ -0,0 +1,163 @@ +== Reusing mapping configurations + +This chapter discusses different means of reusing mapping configurations for several mapping methods: "inheritance" of configuration from other methods and sharing central configuration between multiple mapper types. + +[[mapping-configuration-inheritance]] +=== Mapping configuration inheritance + +Method-level configuration annotations such as `@Mapping`, `@BeanMapping`, `@IterableMapping`, etc., can be *inherited* from one mapping method to a *similar* method using the annotation `@InheritConfiguration`: + +.Update method inheriting its configuration +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(target = "numberOfSeats", source = "seatCount") + Car carDtoToCar(CarDto car); + + @InheritConfiguration + void carDtoIntoCar(CarDto carDto, @MappingTarget Car car); +} +---- +==== + +The example above declares a mapping method `carDtoToCar()` with a configuration to define how the property `numberOfSeats` in the type `Car` shall be mapped. The update method that performs the mapping on an existing instance of `Car` needs the same configuration to successfully map all properties. Declaring `@InheritConfiguration` on the method lets MapStruct search for inheritance candidates to apply the annotations of the method that is inherited from. + +One method *A* can inherit the configuration from another method *B* if all types of *A* (source types and result type) are assignable to the corresponding types of *B*. + +Methods that are considered for inheritance need to be defined in the current mapper, a super class/interface, or in the shared configuration interface (as described in <>). + +In case more than one method is applicable as source for the inheritance, the method name must be specified within the annotation: `@InheritConfiguration( name = "carDtoToCar" )`. + +A method can use `@InheritConfiguration` and override or amend the configuration by additionally applying `@Mapping`, `@BeanMapping`, etc. + +[NOTE] +==== +`@InheritConfiguration` cannot refer to methods in a used mapper. +==== + +[[inverse-mappings]] +=== Inverse mappings + +In case of bi-directional mappings, e.g. from entity to DTO and from DTO to entity, the mapping rules for the forward method and the reverse method are often similar and can simply be inversed by switching `source` and `target`. + +Use the annotation `@InheritInverseConfiguration` to indicate that a method shall inherit the inverse configuration of the corresponding reverse method. + +.Inverse mapping method inheriting its configuration and ignoring some of them +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(source = "numberOfSeats", target = "seatCount") + CarDto carToDto(Car car); + + @InheritInverseConfiguration + @Mapping(target = "numberOfSeats", ignore = true) + Car carDtoToCar(CarDto carDto); +} +---- +==== + +Here the `carDtoToCar()` method is the reverse mapping method for `carToDto()`. Note that any attribute mappings from `carToDto()` will be applied to the corresponding reverse mapping method as well. They are automatically reversed and copied to the method with the `@InheritInverseConfiguration` annotation. + +Specific mappings from the inversed method can (optionally) be overridden by `ignore`, `expression` or `constant` in the mapping, e.g. like this: `@Mapping(target = "numberOfSeats", ignore=true)`. + +A method *A* is considered a *reverse* method of a method *B*, if the result type of *A* is the *same* as the single source type of *B* and if the single source type of *A* is the *same* as the result type of *B*. + +Methods that are considered for inverse inheritance need to be defined in the current mapper, a super class/interface. + +If multiple methods qualify, the method from which to inherit the configuration needs to be specified using the `name` property like this: `@InheritInverseConfiguration(name = "carToDto")`. + +`@InheritConfiguration` takes, in case of conflict precedence over `@InheritInverseConfiguration`. + +Configurations are inherited transitively. So if method `C` defines a mapping `@Mapping( target = "x", ignore = true)`, `B` defines a mapping `@Mapping( target = "y", ignore = true)`, then if `A` inherits from `B` inherits from `C`, `A` will inherit mappings for both property `x` and `y`. + +Expressions and constants are excluded (silently ignored) in `@InheritInverseConfiguration`. + +Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. + +[NOTE] +==== +`@InheritConfiguration` or `@InheritInverseConfiguration` cannot refer to methods in a used mapper. +==== + +[[shared-configurations]] +=== Shared configurations + +MapStruct offers the possibility to define a shared configuration by pointing to a central interface annotated with `@MapperConfig`. For a mapper to use the shared configuration, the configuration interface needs to be defined in the `@Mapper#config` property. + +The `@MapperConfig` annotation has the same attributes as the `@Mapper` annotation. Any attributes not given via `@Mapper` will be inherited from the shared configuration. Attributes specified in `@Mapper` take precedence over the attributes specified via the referenced configuration class. List properties such as `uses` are simply combined: + +.Mapper configuration class and mapper using it +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@MapperConfig( + uses = CustomMapperViaMapperConfig.class, + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface CentralConfig { +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(config = CentralConfig.class, uses = { CustomMapperViaMapper.class } ) +// Effective configuration: +// @Mapper( +// uses = { CustomMapperViaMapper.class, CustomMapperViaMapperConfig.class }, +// unmappedTargetPolicy = ReportingPolicy.ERROR +// ) +public interface SourceTargetMapper { + ... +} + +---- +==== + +The interface holding the `@MapperConfig` annotation may also declare *prototypes* of mapping methods that can be used to inherit method-level mapping annotations from. Such prototype methods are not meant to be implemented or used as part of the mapper API. + +.Mapper configuration class with prototype methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@MapperConfig( + uses = CustomMapperViaMapperConfig.class, + unmappedTargetPolicy = ReportingPolicy.ERROR, + mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG +) +public interface CentralConfig { + + // Not intended to be generated, but to carry inheritable mapping annotations: + @Mapping(target = "primaryKey", source = "technicalKey") + BaseEntity anyDtoToEntity(BaseDto dto); +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(config = CentralConfig.class, uses = { CustomMapperViaMapper.class } ) +public interface SourceTargetMapper { + + @Mapping(target = "numberOfSeats", source = "seatCount") + // additionally inherited from CentralConfig, because Car extends BaseEntity and CarDto extends BaseDto: + // @Mapping(target = "primaryKey", source = "technicalKey") + Car toCar(CarDto car) +} +---- +==== + +The attributes `@Mapper#mappingInheritanceStrategy()` / `@MapperConfig#mappingInheritanceStrategy()` configure when the method-level mapping configuration annotations are inherited from prototype methods in the interface to methods in the mapper: + +* `EXPLICIT` (default): the configuration will only be inherited, if the target mapping method is annotated with `@InheritConfiguration` and the source and target types are assignable to the corresponding types of the prototype method, all as described in <>. +* `AUTO_INHERIT_FROM_CONFIG`: the configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritConfiguration(name = ...)` which will cause `AUTO_INHERIT_FROM_CONFIG` to be ignored. +* `AUTO_INHERIT_REVERSE_FROM_CONFIG`: the inverse configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritInverseConfiguration(name = ...)` which will cause ``AUTO_INHERIT_REVERSE_FROM_CONFIG` to be ignored. +* `AUTO_INHERIT_ALL_FROM_CONFIG`: both the configuration and the inverse configuration will be inherited automatically. The same rules apply as for `AUTO_INHERIT_FROM_CONFIG` or `AUTO_INHERIT_REVERSE_FROM_CONFIG`. \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc new file mode 100644 index 0000000000..b7b7c4b248 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc @@ -0,0 +1,270 @@ +== Customizing mappings + +Sometimes it's needed to apply custom logic before or after certain mapping methods. MapStruct provides two ways for doing so: decorators which allow for a type-safe customization of specific mapping methods and the before-mapping and after-mapping lifecycle methods which allow for a generic customization of mapping methods with given source or target types. + +[[customizing-mappers-using-decorators]] +=== Mapping customization with decorators + +In certain cases it may be required to customize a generated mapping method, e.g. to set an additional property in the target object which can't be set by a generated method implementation. MapStruct supports this requirement using decorators. + +[TIP] +When working with the component model `cdi`, use https://docs.jboss.org/cdi/spec/1.0/html/decorators.html[CDI decorators] with MapStruct mappers instead of the `@DecoratedWith` annotation described here. + +To apply a decorator to a mapper class, specify it using the `@DecoratedWith` annotation. + +.Applying a decorator +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +@DecoratedWith(PersonMapperDecorator.class) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} +---- +==== + +The decorator must be a sub-type of the decorated mapper type. You can make it an abstract class which allows to only implement those methods of the mapper interface which you want to customize. For all non-implemented methods, a simple delegation to the original mapper will be generated using the default generation routine. + +The `PersonMapperDecorator` shown below customizes the `personToPersonDto()`. It sets an additional attribute which is not present in the source type of the mapping. The `addressToAddressDto()` method is not customized. + +.Implementing a decorator +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public abstract class PersonMapperDecorator implements PersonMapper { + + private final PersonMapper delegate; + + public PersonMapperDecorator(PersonMapper delegate) { + this.delegate = delegate; + } + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setFullName( person.getFirstName() + " " + person.getLastName() ); + return dto; + } +} +---- +==== + +The example shows how you can optionally inject a delegate with the generated default implementation and use this delegate in your customized decorator methods. + +For a mapper with `componentModel = "default"`, define a constructor with a single parameter which accepts the type of the decorated mapper. + +When working with the component models `spring` or `jsr330`, this needs to be handled differently. + +[[decorators-with-spring]] +==== Decorators with the Spring component model + +When using `@DecoratedWith` on a mapper with component model `spring`, the generated implementation of the original mapper is annotated with the Spring annotation `@Qualifier("delegate")`. To autowire that bean in your decorator, add that qualifier annotation as well: + +.Spring-based decorator +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public abstract class PersonMapperDecorator implements PersonMapper { + + @Autowired + @Qualifier("delegate") + private PersonMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + + return dto; + } + } +---- +==== + +The generated class that extends the decorator is annotated with Spring's `@Primary` annotation. To autowire the decorated mapper in the application, nothing special needs to be done: + +.Using a decorated mapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Autowired +private PersonMapper personMapper; // injects the decorator, with the injected original mapper +---- +==== + +[[decorators-with-jsr-330]] +==== Decorators with the JSR 330 component model + +JSR 330 doesn't specify qualifiers and only allows to specifically name the beans. Hence, the generated implementation of the original mapper is annotated with `@Named("fully-qualified-name-of-generated-implementation")` (please note that when using a decorator, the class name of the mapper implementation ends with an underscore). To inject that bean in your decorator, add the same annotation to the delegate field (e.g. by copy/pasting it from the generated class): + +.JSR 330 based decorator +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public abstract class PersonMapperDecorator implements PersonMapper { + + @Inject + @Named("org.examples.PersonMapperImpl_") + private PersonMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + + return dto; + } +} +---- +==== + +Unlike with the other component models, the usage site must be aware if a mapper is decorated or not, as for decorated mappers, the parameterless `@Named` annotation must be added to select the decorator to be injected: + +.Using a decorated mapper with JSR 330 +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Inject +@Named +private PersonMapper personMapper; // injects the decorator, with the injected original mapper +---- +==== + +[WARNING] +==== +`@DecoratedWith` in combination with component model `jsr330` is considered experimental as of the 1.0.0.CR2 release. The way the original mapper is referenced in the decorator or the way the decorated mapper is injected in the application code might still change. +==== + +[[customizing-mappings-with-before-and-after]] +=== Mapping customization with before-mapping and after-mapping methods + +Decorators may not always fit the needs when it comes to customizing mappers. For example, if you need to perform the customization not only for a few selected methods, but for all methods that map specific super-types: in that case, you can use *callback methods* that are invoked before the mapping starts or after the mapping finished. + +Callback methods can be implemented in the abstract mapper itself, in a type reference in `Mapper#uses`, or in a type used as `@Context` parameter. + +.Mapper with @BeforeMapping and @AfterMapping hooks +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public abstract class VehicleMapper { + + @BeforeMapping + protected void flushEntity(AbstractVehicle vehicle) { + // I would call my entity manager's flush() method here to make sure my entity + // is populated with the right @Version before I let it map into the DTO + } + + @AfterMapping + protected void fillTank(AbstractVehicle vehicle, @MappingTarget AbstractVehicleDto result) { + result.fuelUp( new Fuel( vehicle.getTankCapacity(), vehicle.getFuelType() ) ); + } + + public abstract CarDto toCarDto(Car car); +} + +// Generates something like this: +public class VehicleMapperImpl extends VehicleMapper { + + public CarDto toCarDto(Car car) { + flushEntity( car ); + + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + // attributes mapping ... + + fillTank( car, carDto ); + + return carDto; + } +} +---- +==== + +If the `@BeforeMapping` / `@AfterMapping` method has parameters, the method invocation is only generated if the return type of the method (if non-`void`) is assignable to the return type of the mapping method and all parameters can be *assigned* by the source or target parameters of the mapping method: + +* A parameter annotated with `@MappingTarget` is populated with the target instance of the mapping. +* A parameter annotated with `@TargetType` is populated with the target type of the mapping. +* Parameters annotated with `@Context` are populated with the context parameters of the mapping method. +* Any other parameter is populated with a source parameter of the mapping. + +For non-`void` methods, the return value of the method invocation is returned as the result of the mapping method if it is not `null`. + +As with mapping methods, it is possible to specify type parameters for before/after-mapping methods. + +.Mapper with @AfterMapping hook that returns a non-null value +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public abstract class VehicleMapper { + + @PersistenceContext + private EntityManager entityManager; + + @AfterMapping + protected T attachEntity(@MappingTarget T entity) { + return entityManager.merge(entity); + } + + public abstract CarDto toCarDto(Car car); +} + +// Generates something like this: +public class VehicleMapperImpl extends VehicleMapper { + + public CarDto toCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + // attributes mapping ... + + CarDto target = attachEntity( carDto ); + if ( target != null ) { + return target; + } + + return carDto; + } +} +---- +==== + +All before/after-mapping methods that *can* be applied to a mapping method *will* be used. <> can be used to further control which methods may be chosen and which not. For that, the qualifier annotation needs to be applied to the before/after-method and referenced in `BeanMapping#qualifiedBy` or `IterableMapping#qualifiedBy`. + +The order of the method invocation is determined primarily by their variant: + +1. `@BeforeMapping` methods without an `@MappingTarget` parameter are called before any null-checks on source +parameters and constructing a new target bean. +2. `@BeforeMapping` methods with an `@MappingTarget` parameter are called after constructing a new target bean. +3. `@AfterMapping` methods are called at the end of the mapping method before the last `return` statement. + +Within those groups, the method invocations are ordered by their location of definition: + +1. Methods declared on `@Context` parameters, ordered by the parameter order. +2. Methods implemented in the mapper itself. +3. Methods from types referenced in `Mapper#uses()`, in the order of the type declaration in the annotation. +4. Methods declared in one type are used after methods declared in their super-type. + +*Important:* the order of methods declared within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. + +*Important:* when using a builder, the `@AfterMapping` annotated method must have the builder as `@MappingTarget` annotated parameter so that the method is able to modify the object going to be build. The `build` method is called when the `@AfterMapping` annotated method scope finishes. MapStruct will not call the `@AfterMapping` annotated method if the real target is used as `@MappingTarget` annotated parameter. \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc new file mode 100644 index 0000000000..b152570475 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -0,0 +1,200 @@ +[[using-spi]] +== Using the MapStruct SPI +=== Custom Accessor Naming Strategy + +MapStruct offers the possibility to override the `AccessorNamingStrategy` via the Service Provide Interface (SPI). A nice example is the use of the fluent API on the source object `GolfPlayer` and `GolfPlayerDto` below. + +.Source object GolfPlayer with fluent API. +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class GolfPlayer { + + private double handicap; + private String name; + + public double handicap() { + return handicap; + } + + public GolfPlayer withHandicap(double handicap) { + this.handicap = handicap; + return this; + } + + public String name() { + return name; + } + + public GolfPlayer withName(String name) { + this.name = name; + return this; + } +} +---- +==== + +.Source object GolfPlayerDto with fluent API. +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class GolfPlayerDto { + + private double handicap; + private String name; + + public double handicap() { + return handicap; + } + + public GolfPlayerDto withHandicap(double handicap) { + this.handicap = handicap; + return this; + } + + public String name() { + return name; + } + + public GolfPlayerDto withName(String name) { + this.name = name; + return this + } +} +---- +==== + +We want `GolfPlayer` to be mapped to a target object `GolfPlayerDto` similar like we 'always' do this: + +.Source object with fluent API. +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface GolfPlayerMapper { + + GolfPlayerMapper INSTANCE = Mappers.getMapper( GolfPlayerMapper.class ); + + GolfPlayerDto toDto(GolfPlayer player); + + GolfPlayer toPlayer(GolfPlayerDto player); + +} +---- +==== + +This can be achieved with implementing the SPI `org.mapstruct.ap.spi.AccessorNamingStrategy` as in the following example. Here's an implemented `org.mapstruct.ap.spi.AccessorNamingStrategy`: + +.CustomAccessorNamingStrategy +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +/** + * A custom {@link AccessorNamingStrategy} recognizing getters in the form of {@code property()} and setters in the + * form of {@code withProperty(value)}. + */ +public class CustomAccessorNamingStrategy extends DefaultAccessorNamingStrategy { + + @Override + public boolean isGetterMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + return !methodName.startsWith( "with" ) && method.getReturnType().getKind() != TypeKind.VOID; + } + + @Override + public boolean isSetterMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + return methodName.startsWith( "with" ) && methodName.length() > 4; + } + + @Override + public String getPropertyName(ExecutableElement getterOrSetterMethod) { + String methodName = getterOrSetterMethod.getSimpleName().toString(); + return IntrospectorUtils.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); + } +} +---- +==== +The `CustomAccessorNamingStrategy` makes use of the `DefaultAccessorNamingStrategy` (also available in mapstruct-processor) and relies on that class to leave most of the default behaviour unchanged. + +To use a custom SPI implementation, it must be located in a separate JAR file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). + +[TIP] +Fore more details: The example above is present in our examples repository (https://github.com/mapstruct/mapstruct-examples). + +[mapping-exclusion-provider] +=== Mapping Exclusion Provider + +MapStruct offers the possibility to override the `MappingExclusionProvider` via the Service Provider Interface (SPI). +A nice example is to not allow MapStruct to create an automatic sub-mapping for a certain type, +i.e. MapStruct will not try to generate an automatic sub-mapping method for an excluded type. + +[NOTE] +==== +The `DefaultMappingExclusionProvider` will exclude all types under the `java` or `javax` packages. +This means that MapStruct will not try to generate an automatic sub-mapping method between some custom type and some type declared in the Java class library. +==== + +.Source object +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/Source.java[tag=documentation] +---- +==== + +.Target object +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/Target.java[tag=documentation] +---- +==== + +.Mapper definition +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java[tag=documentation] +---- +==== + +We want to exclude the `NestedTarget` from the automatic sub-mapping method generation. + +.CustomMappingExclusionProvider +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java[tag=documentation] +---- +==== + +To use a custom SPI implementation, it must be located in a separate JAR file +together with the file `META-INF/services/org.mapstruct.ap.spi.MappingExclusionProvider` with the fully qualified name of your custom implementation as content +(e.g. `org.mapstruct.example.CustomMappingExclusionProvider`). +This JAR file needs to be added to the annotation processor classpath +(i.e. add it next to the place where you added the mapstruct-processor jar). + + +[[custom-builder-provider]] +=== Custom Builder Provider + +MapStruct offers the possibility to override the `DefaultProvider` via the Service Provider Interface (SPI). +A nice example is to provide support for a custom builder strategy. + +.Custom Builder Provider which disables Builder support +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] +---- +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc new file mode 100644 index 0000000000..591ff0764a --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -0,0 +1,286 @@ +[[setup]] +== Set up + +MapStruct is a Java annotation processor based on http://www.jcp.org/en/jsr/detail?id=269[JSR 269] and as such can be used within command line builds (javac, Ant, Maven etc.) as well as from within your IDE. + +It comprises the following artifacts: + +* _org.mapstruct:mapstruct_: contains the required annotations such as `@Mapping` +* _org.mapstruct:mapstruct-processor_: contains the annotation processor which generates mapper implementations + +=== Apache Maven + +For Maven based projects add the following to your POM file in order to use MapStruct: + +.Maven configuration +==== +[source, xml, linenums] +[subs="verbatim,attributes"] +---- +... + + {mapstructVersion} + +... + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + +... + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + +... +---- +==== + +[TIP] +==== +If you are working with the Eclipse IDE, make sure to have a current version of the http://www.eclipse.org/m2e/[M2E plug-in]. +When importing a Maven project configured as shown above, it will set up the MapStruct annotation processor so it runs right in the IDE, whenever you save a mapper type. +Neat, isn't it? + +To double check that everything is working as expected, go to your project's properties and select "Java Compiler" -> "Annotation Processing" -> "Factory Path". +The MapStruct processor JAR should be listed and enabled there. +Any processor options configured via the compiler plug-in (see below) should be listed under "Java Compiler" -> "Annotation Processing". + +If the processor is not kicking in, check that the configuration of annotation processors through M2E is enabled. +To do so, go to "Preferences" -> "Maven" -> "Annotation Processing" and select "Automatically configure JDT APT". +Alternatively, specify the following in the `properties` section of your POM file: `jdt_apt`. + +Also make sure that your project is using Java 1.8 or later (project properties -> "Java Compiler" -> "Compile Compliance Level"). +It will not work with older versions. +==== + +=== Gradle + +Add the following to your Gradle build file in order to enable MapStruct: + +.Gradle configuration (3.4 and later) +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- +... +plugins { + ... + id 'net.ltgt.apt' version '0.20' +} + +// You can integrate with your IDEs. +// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides +apply plugin: 'net.ltgt.apt-idea' +apply plugin: 'net.ltgt.apt-eclipse' + +dependencies { + ... + implementation "org.mapstruct:mapstruct:${mapstructVersion}" + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + + // If you are using mapstruct in test code + testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" +} +... +---- +==== +.Gradle (3.3 and older) +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- +... +plugins { + ... + id 'net.ltgt.apt' version '0.20' +} + +// You can integrate with your IDEs. +// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides +apply plugin: 'net.ltgt.apt-idea' +apply plugin: 'net.ltgt.apt-eclipse' + +dependencies { + ... + compile "org.mapstruct:mapstruct:${mapstructVersion}" + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + + // If you are using mapstruct in test code + testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" +} +... +---- +==== + +You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-gradle[mapstruct-examples] project on GitHub. + + +=== Apache Ant + +Add the `javac` task configured as follows to your _build.xml_ file in order to enable MapStruct in your Ant-based project. Adjust the paths as required for your project layout. + +.Ant configuration +==== +[source, xml, linenums] +[subs="verbatim,attributes"] +---- +... + + + + +... +---- +==== + +You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-ant[mapstruct-examples] project on GitHub. + +[[configuration-options]] +=== Configuration options + +The MapStruct code generator can be configured using _annotation processor options_. + +When invoking javac directly, these options are passed to the compiler in the form _-Akey=value_. When using MapStruct via Maven, any processor options can be passed using an `options` element within the configuration of the Maven processor plug-in like this: + +.Maven configuration +==== +[source, xml, linenums] +[subs="verbatim,attributes"] +---- +... + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + true + + + -Amapstruct.suppressGeneratorTimestamp=true + + + -Amapstruct.suppressGeneratorVersionInfoComment=true + + + -Amapstruct.verbose=true + + + + +... +---- +==== + +.Gradle configuration +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- +... +compileJava { + options.compilerArgs = [ + '-Amapstruct.suppressGeneratorTimestamp=true', + '-Amapstruct.suppressGeneratorVersionInfoComment=true', + '-Amapstruct.verbose=true' + ] +} +... +---- +==== + +The following options exist: + +.MapStruct processor options +[cols="1,2a,1"] +|=== +|Option|Purpose|Default + +|`mapstruct. +suppressGeneratorTimestamp` +|If set to `true`, the creation of a time stamp in the `@Generated` annotation in the generated mapper classes is suppressed. +|`false` + +|`mapstruct.verbose` +|If set to `true`, MapStruct in which MapStruct logs its major decisions. Note, at the moment of writing in Maven, also `showWarnings` needs to be added due to a problem in the maven-compiler-plugin configuration. +|`false` + +|`mapstruct. +suppressGeneratorVersionInfoComment` +|If set to `true`, the creation of the `comment` attribute in the `@Generated` annotation in the generated mapper classes is suppressed. The comment contains information about the version of MapStruct and about the compiler used for the annotation processing. +|`false` + +|`mapstruct.defaultComponentModel` +|The name of the component model (see <>) based on which mappers should be generated. + +Supported values are: + +* `default`: the mapper uses no component model, instances are typically retrieved via `Mappers#getMapper(Class)` +* `cdi`: the generated mapper is an application-scoped CDI bean and can be retrieved via `@Inject` +* `spring`: the generated mapper is a singleton-scoped Spring bean and can be retrieved via `@Autowired` +* `jsr330`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject`, e.g. using Spring + +If a component model is given for a specific mapper via `@Mapper#componentModel()`, the value from the annotation takes precedence. +|`default` + +|`mapstruct.unmappedTargetPolicy` +|The default reporting policy to be applied in case an attribute of the target object of a mapping method is not populated with a source value. + +Supported values are: + +* `ERROR`: any unmapped target property will cause the mapping code generation to fail +* `WARN`: any unmapped target property will cause a warning at build time +* `IGNORE`: unmapped target properties are ignored + +If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. +|`WARN` +|=== + +=== Using MapStruct on Java 9 + +MapStruct can be used with Java 9 (JPMS), support for it is experimental. + +A core theme of Java 9 is the modularization of the JDK. One effect of this is that a specific module needs to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. + +To allow usage of the `@Generated` annotation the module _java.xml.ws.annotation_ must be enabled. When using Maven, this can be done like this: + + export MAVEN_OPTS="--add-modules java.xml.ws.annotation" + +If the `@Generated` annotation is not available, MapStruct will detect this situation and not add it to generated mappers. + +[NOTE] +===== +In Java 9 `java.annotation.processing.Generated` was added (part of the `java.compiler` module), +if this annotation is available then it will be used. +===== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc new file mode 100644 index 0000000000..352bde0b4e --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -0,0 +1,454 @@ +[[defining-mapper]] +== Defining a mapper + +In this section you'll learn how to define a bean mapper with MapStruct and which options you have to do so. + +[[basic-mappings]] +=== Basic mappings + +To create a mapper simply define a Java interface with the required mapping method(s) and annotate it with the `org.mapstruct.Mapper` annotation: + +.Java interface to define a mapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(source = "make", target = "manufacturer") + @Mapping(source = "numberOfSeats", target = "seatCount") + CarDto carToCarDto(Car car); + + @Mapping(source = "name", target = "fullName") + PersonDto personToPersonDto(Person person); +} +---- +==== + +The `@Mapper` annotation causes the MapStruct code generator to create an implementation of the `CarMapper` interface during build-time. + +In the generated method implementations all readable properties from the source type (e.g. `Car`) will be copied into the corresponding property in the target type (e.g. `CarDto`): + +* When a property has the same name as its target entity counterpart, it will be mapped implicitly. +* When a property has a different name in the target entity, its name can be specified via the `@Mapping` annotation. + +[TIP] +==== +The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans specification] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. +==== +[TIP] +==== +By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. +==== +[TIP] +==== +Fluent setters are also supported. +Fluent setters are setters that return the same type as the type being modified. + +E.g. + +``` +public Builder seatCount(int seatCount) { + this.seatCount = seatCount; + return this; +} +``` +==== + + +To get a better understanding of what MapStruct does have a look at the following implementation of the `carToCarDto()` method as generated by MapStruct: + +.Code generated by MapStruct +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + if ( car.getFeatures() != null ) { + carDto.setFeatures( new ArrayList( car.getFeatures() ) ); + } + carDto.setManufacturer( car.getMake() ); + carDto.setSeatCount( car.getNumberOfSeats() ); + carDto.setDriver( personToPersonDto( car.getDriver() ) ); + carDto.setPrice( String.valueOf( car.getPrice() ) ); + if ( car.getCategory() != null ) { + carDto.setCategory( car.getCategory().toString() ); + } + carDto.setEngine( engineToEngineDto( car.getEngine() ) ); + + return carDto; + } + + @Override + public PersonDto personToPersonDto(Person person) { + //... + } + + private EngineDto engineToEngineDto(Engine engine) { + if ( engine == null ) { + return null; + } + + EngineDto engineDto = new EngineDto(); + + engineDto.setHorsePower(engine.getHorsePower()); + engineDto.setFuel(engine.getFuel()); + + return engineDto; + } +} +---- +==== + +The general philosophy of MapStruct is to generate code which looks as much as possible as if you had written it yourself from hand. In particular this means that the values are copied from source to target by plain getter/setter invocations instead of reflection or similar. + +As the example shows the generated code takes into account any name mappings specified via `@Mapping`. +If the type of a mapped attribute is different in source and target entity, +MapStruct will either apply an automatic conversion (as e.g. for the _price_ property, see also <>) +or optionally invoke / create another mapping method (as e.g. for the _driver_ / _engine_ property, see also <>). +MapStruct will only create a new mapping method if and only if the source and target property are properties of a Bean and they themselves are Beans or simple properties. +i.e. they are not `Collection` or `Map` type properties. + +Collection-typed attributes with the same element type will be copied by creating a new instance of the target collection type containing the elements from the source property. For collection-typed attributes with different element types each element will be mapped individually and added to the target collection (see <>). + +MapStruct takes all public properties of the source and target types into account. This includes properties declared on super-types. + +[[adding-custom-methods]] +=== Adding custom methods to mappers + +In some cases it can be required to manually implement a specific mapping from one type to another which can't be generated by MapStruct. One way to handle this is to implement the custom method on another class which then is used by mappers generated by MapStruct (see <>). + +Alternatively, when using Java 8 or later, you can implement custom methods directly in a mapper interface as default methods. The generated code will invoke the default methods if the argument and return types match. + +As an example let's assume the mapping from `Person` to `PersonDto` requires some special logic which can't be generated by MapStruct. You could then define the mapper from the previous example like this: + +.Mapper which defines a custom mapping with a default method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(...) + ... + CarDto carToCarDto(Car car); + + default PersonDto personToPersonDto(Person person) { + //hand-written mapping logic + } +} +---- +==== + +The class generated by MapStruct implements the method `carToCarDto()`. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute. + +A mapper could also be defined in the form of an abstract class instead of an interface and implement the custom methods directly in the mapper class. In this case MapStruct will generate an extension of the abstract class with implementations of all abstract methods. An advantage of this approach over declaring default methods is that additional fields could be declared in the mapper class. + +The previous example where the mapping from `Person` to `PersonDto` requires some special logic could then be defined like this: + +.Mapper defined by an abstract class +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public abstract class CarMapper { + + @Mapping(...) + ... + public abstract CarDto carToCarDto(Car car); + + public PersonDto personToPersonDto(Person person) { + //hand-written mapping logic + } +} +---- +==== + +MapStruct will generate a sub-class of `CarMapper` with an implementation of the `carToCarDto()` method as it is declared abstract. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute. + +[[mappings-with-several-source-parameters]] +=== Mapping methods with several source parameters + +MapStruct also supports mapping methods with several source parameters. This is useful e.g. in order to combine several entities into one data transfer object. The following shows an example: + +.Mapping method with several source parameters +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface AddressMapper { + + @Mapping(source = "person.description", target = "description") + @Mapping(source = "address.houseNo", target = "houseNumber") + DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address); +} +---- +==== + +The shown mapping method takes two source parameters and returns a combined target object. As with single-parameter mapping methods properties are mapped by name. + +In case several source objects define a property with the same name, the source parameter from which to retrieve the property must be specified using the `@Mapping` annotation as shown for the `description` property in the example. An error will be raised when such an ambiguity is not resolved. For properties which only exist once in the given source objects it is optional to specify the source parameter's name as it can be determined automatically. + +[WARNING] +==== +Specifying the parameter in which the property resides is mandatory when using the `@Mapping` annotation. +==== + +[TIP] +==== +Mapping methods with several source parameters will return `null` in case all the source parameters are `null`. Otherwise the target object will be instantiated and all properties from the provided parameters will be propagated. +==== + +MapStruct also offers the possibility to directly refer to a source parameter. + +.Mapping method directly referring to a source parameter +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface AddressMapper { + + @Mapping(source = "person.description", target = "description") + @Mapping(source = "hn", target = "houseNumber") + DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn); +} +---- +==== + +In this case the source parameter is directly mapped into the target as the example above demonstrates. The parameter `hn`, a non bean type (in this case `java.lang.Integer`) is mapped to `houseNumber`. + +[[updating-bean-instances]] +=== Updating existing bean instances + +In some cases you need mappings which don't create a new instance of the target type but instead update an existing instance of that type. This sort of mapping can be realized by adding a parameter for the target object and marking this parameter with `@MappingTarget`. The following shows an example: + +.Update method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + void updateCarFromDto(CarDto carDto, @MappingTarget Car car); +} +---- +==== + +The generated code of the `updateCarFromDto()` method will update the passed `Car` instance with the properties from the given `CarDto` object. There may be only one parameter marked as mapping target. Instead of `void` you may also set the method's return type to the type of the target parameter, which will cause the generated implementation to update the passed mapping target and return it as well. This allows for fluent invocations of mapping methods. + +For `CollectionMappingStrategy.ACCESSOR_ONLY` Collection- or map-typed properties of the target bean to be updated will be cleared and then populated with the values from the corresponding source collection or map. Otherwise, For `CollectionMappingStrategy.ADDER_PREFERRED` or `CollectionMappingStrategy.TARGET_IMMUTABLE` the target will not be cleared and the values will be populated immediately. + +[[direct-field-mappings]] +=== Mappings with direct field access + +MapStruct also supports mappings of `public` fields that have no getters/setters. MapStruct will +use the fields as read/write accessor if it cannot find suitable getter/setter methods for the property. + +A field is considered as a read accessor if it is `public` or `public final`. If a field is `static` it is not +considered as a read accessor. + +A field is considered as a write accessor only if it is `public`. If a field is `final` and/or `static` it is not +considered as a write accessor. + +Small example: + +.Example classes for mapping +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Customer { + + private Long id; + private String name; + + //getters and setter omitted for brevity +} + +public class CustomerDto { + + public Long id; + public String customerName; +} + +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(source = "customerName", target = "name") + Customer toCustomer(CustomerDto customerDto); + + @InheritInverseConfiguration + CustomerDto fromCustomer(Customer customer); +} +---- +==== + +For the configuration from above, the generated mapper looks like: + +.Generated mapper for example classes +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CustomerMapperImpl implements CustomerMapper { + + @Override + public Customer toCustomer(CustomerDto customerDto) { + // ... + customer.setId( customerDto.id ); + customer.setName( customerDto.customerName ); + // ... + } + + @Override + public CustomerDto fromCustomer(Customer customer) { + // ... + customerDto.id = customer.getId(); + customerDto.customerName = customer.getName(); + // ... + } +} +---- +==== + +You can find the complete example in the +https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-field-mapping[mapstruct-examples-field-mapping] +project on GitHub. + +[[mapping-with-builders]] +=== Using builders + +MapStruct also supports mapping of immutable types via builders. +When performing a mapping MapStruct checks if there is a builder for the type being mapped. +This is done via the `BuilderProvider` SPI. +If a Builder exists for a certain type, then that builder will be used for the mappings. + +The default implementation of the `BuilderProvider` assumes the following: + +* The type has a parameterless public static builder creation method that returns a builder. +So for example `Person` has a public static method that returns `PersonBuilder`. +* The builder type has a parameterless public method (build method) that returns the type being build +In our example `PersonBuilder` has a method returning `Person`. +* In case there are multiple build methods, MapStruct will look for a method called `build`, if such method exists +then this would be used, otherwise a compilation error would be created. +* A specific build method can be defined by using `@Builder` within: `@BeanMapping`, `@Mapper` or `@MapperConfig` +* In case there are multiple builder creation methods that satisfy the above conditions then a `MoreThanOneBuilderCreationMethodException` +will be thrown from the `DefaultBuilderProvider` SPI. +In case of a `MoreThanOneBuilderCreationMethodException` MapStruct will write a warning in the compilation and not use any builder. + +If such type is found then MapStruct will use that type to perform the mapping to (i.e. it will look for setters into that type). +To finish the mapping MapStruct generates code that will invoke the build method of the builder. + +[NOTE] +====== +Builder detection can be switched off by means of `@Builder#disableBuilder`. MapStruct will fall back on regular getters / setters in case builders are disabled. +====== + +[NOTE] +====== +The <> are also considered for the builder type. +E.g. If an object factory exists for our `PersonBuilder` then this factory would be used instead of the builder creation method. +====== + +.Person with Builder example +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Person { + + private final String name; + + protected Person(Person.Builder builder) { + this.name = builder.name; + } + + public static Person.Builder builder() { + return new Person.Builder(); + } + + public static class Builder { + + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Person create() { + return new Person( this ); + } + } +} +---- +==== + +.Person Mapper definition +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public interface PersonMapper { + + Person map(PersonDto dto); +} +---- +==== + +.Generated mapper with builder +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class PersonMapperImpl implements PersonMapper { + + public Person map(PersonDto dto) { + if (dto == null) { + return null; + } + + Person.Builder builder = Person.builder(); + + builder.name( dto.getName() ); + + return builder.create(); + } +} +---- +==== + +Supported builder frameworks: + +* https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] +* https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] +* https://immutables.github.io/[Immutables] - When Immutables are present on the annotation processor path then the `ImmutablesAccessorNamingStrategy` and `ImmutablesBuilderProvider` would be used by default +* https://github.com/google/FreeBuilder[FreeBuilder] - When FreeBuilder is present on the annotation processor path then the `FreeBuilderAccessorNamingStrategy` would be used by default. +When using FreeBuilder then the JavaBean convention should be followed, otherwise MapStruct won't recognize the fluent getters. +* It also works for custom builders (handwritten ones) if the implementation supports the defined rules for the default `BuilderProvider`. +Otherwise, you would need to write a custom `BuilderProvider` + +[TIP] +==== +In case you want to disable using builders then you can use the `NoOpBuilderProvider` by creating a `org.mapstruct.ap.spi.BuilderProvider` file in the `META-INF/services` directory with `org.mapstruct.ap.spi.NoOpBuilderProvider` as it's content. +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc new file mode 100644 index 0000000000..03c2c4b559 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc @@ -0,0 +1,129 @@ +[[retrieving-mapper]] +== Retrieving a mapper + +[[mappers-factory]] +=== The Mappers factory (no dependency injection) + +When not using a DI framework, Mapper instances can be retrieved via the `org.mapstruct.factory.Mappers` class. Just invoke the `getMapper()` method, passing the interface type of the mapper to return: + +.Using the Mappers factory +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +CarMapper mapper = Mappers.getMapper( CarMapper.class ); +---- +==== + +By convention, a mapper interface should define a member called `INSTANCE` which holds a single instance of the mapper type: + +.Declaring an instance of a mapper (interface) +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + CarDto carToCarDto(Car car); +} + +---- +==== + +.Declaring an instance of a mapper (abstract class) +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public abstract class CarMapper { + + public static final CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + CarDto carToCarDto(Car car); +} + +---- +==== + +This pattern makes it very easy for clients to use mapper objects without repeatedly instantiating new instances: + +.Accessing a mapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +Car car = ...; +CarDto dto = CarMapper.INSTANCE.carToCarDto( car ); +---- +==== + + +Note that mappers generated by MapStruct are stateless and thread-safe and thus can safely be accessed from several threads at the same time. + +[[using-dependency-injection]] +=== Using dependency injection + +If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. + +Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: + +.A mapper using the CDI component model +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(componentModel = "cdi") +public interface CarMapper { + + CarDto carToCarDto(Car car); +} + +---- +==== + +The generated mapper implementation will be marked with the `@ApplicationScoped` annotation and thus can be injected into fields, constructor arguments etc. using the `@Inject` annotation: + +.Obtaining a mapper via dependency injection +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Inject +private CarMapper mapper; +---- +==== + +A mapper which uses other mapper classes (see <>) will obtain these mappers using the configured component model. So if `CarMapper` from the previous example was using another mapper, this other mapper would have to be an injectable CDI bean as well. + +[[injection-strategy]] +=== Injection strategy + +When using <>, you can choose between field and constructor injection. +This can be done by either providing the injection strategy via `@Mapper` or `@MapperConfig` annotation. + +.Using constructor injection +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) +public interface CarMapper { + CarDto carToCarDto(Car car); +} +---- +==== + +The generated mapper will inject all classes defined in the **uses** attribute. +When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. +When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. +For now, the default injection strategy is field injection. +It is recommended to use constructor injection to simplify testing. + +[TIP] +==== +For abstract classes or decorators setter injection should be used. +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc new file mode 100644 index 0000000000..26e8c083d8 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -0,0 +1,621 @@ +[[datatype-conversions]] +== Data type conversions + +Not always a mapped attribute has the same type in the source and target objects. For instance an attribute may be of type `int` in the source bean but of type `Long` in the target bean. + +Another example are references to other objects which should be mapped to the corresponding types in the target model. E.g. the class `Car` might have a property `driver` of the type `Person` which needs to be converted into a `PersonDto` object when mapping a `Car` object. + +In this section you'll learn how MapStruct deals with such data type conversions. + +[[implicit-type-conversions]] +=== Implicit type conversions + +MapStruct takes care of type conversions automatically in many cases. If for instance an attribute is of type `int` in the source bean but of type `String` in the target bean, the generated code will transparently perform a conversion by calling `String#valueOf(int)` and `Integer#parseInt(String)`, respectively. + +Currently the following conversions are applied automatically: + +* Between all Java primitive data types and their corresponding wrapper types, e.g. between `int` and `Integer`, `boolean` and `Boolean` etc. The generated code is `null` aware, i.e. when converting a wrapper type into the corresponding primitive type a `null` check will be performed. + +* Between all Java primitive number types and the wrapper types, e.g. between `int` and `long` or `byte` and `Integer`. + +[WARNING] +==== +Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. The `Mapper` and `MapperConfig` annotations have a method `typeConversionPolicy` to control warnings / errors. Due to backward compatibility reasons the default value is 'ReportingPolicy.IGNORE`. +==== + +* Between all Java primitive types (including their wrappers) and `String`, e.g. between `int` and `String` or `Boolean` and `String`. A format string as understood by `java.text.DecimalFormat` can be specified. + +.Conversion from int to String +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(source = "price", numberFormat = "$#.00") + CarDto carToCarDto(Car car); + + @IterableMapping(numberFormat = "$#.00") + List prices(List prices); +} +---- +==== +* Between `enum` types and `String`. + +* Between big number types (`java.math.BigInteger`, `java.math.BigDecimal`) and Java primitive types (including their wrappers) as well as String. A format string as understood by `java.text.DecimalFormat` can be specified. + +.Conversion from BigDecimal to String +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(source = "power", numberFormat = "#.##E0") + CarDto carToCarDto(Car car); + +} +---- +==== + + +* Between `JAXBElement` and `T`, `List>` and `List` + +* Between `java.util.Calendar`/`java.util.Date` and JAXB's `XMLGregorianCalendar` + +* Between `java.util.Date`/`XMLGregorianCalendar` and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option as this: + +.Conversion from Date to String +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + @Mapping(source = "manufacturingDate", dateFormat = "dd.MM.yyyy") + CarDto carToCarDto(Car car); + + @IterableMapping(dateFormat = "dd.MM.yyyy") + List stringListToDateList(List dates); +} +---- +==== + +* Between Jodas `org.joda.time.DateTime`, `org.joda.time.LocalDateTime`, `org.joda.time.LocalDate`, `org.joda.time.LocalTime` and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). + +* Between Jodas `org.joda.time.DateTime` and `javax.xml.datatype.XMLGregorianCalendar`, `java.util.Calendar`. + +* Between Jodas `org.joda.time.LocalDateTime`, `org.joda.time.LocalDate` and `javax.xml.datatype.XMLGregorianCalendar`, `java.util.Date`. + +* Between `java.time.ZonedDateTime`, `java.time.LocalDateTime`, `java.time.LocalDate`, `java.time.LocalTime` from Java 8 Date-Time package and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). + +* Between `java.time.Instant`, `java.time.Duration`, `java.time.Period` from Java 8 Date-Time package and `String` using the `parse` method in each class to map from `String` and using `toString` to map into `String`. + +* Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Date` where, when mapping a `ZonedDateTime` from a given `Date`, the system default timezone is used. + +* Between `java.time.LocalDateTime` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. + +* Between `java.time.LocalDate` from Java 8 Date-Time package and `java.util.Date` / `java.sql.Date` where timezone UTC is used as the timezone. + +* Between `java.time.Instant` from Java 8 Date-Time package and `java.util.Date`. + +* Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Calendar`. + +* Between `java.sql.Date` and `java.util.Date` + +* Between `java.sql.Time` and `java.util.Date` + +* Between `java.sql.Timestamp` and `java.util.Date` + +* When converting from a `String`, omitting `Mapping#dateFormat`, it leads to usage of the default pattern and date format symbols for the default locale. An exception to this rule is `XmlGregorianCalendar` which results in parsing the `String` according to http://www.w3.org/TR/xmlschema-2/#dateTime[XML Schema 1.0 Part 2, Section 3.2.7-14.1, Lexical Representation]. + +* Between `java.util.Currency` and `String`. +** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown + +[[mapping-object-references]] +=== Mapping object references + +Typically an object has not only primitive attributes but also references other objects. E.g. the `Car` class could contain a reference to a `Person` object (representing the car's driver) which should be mapped to a `PersonDto` object referenced by the `CarDto` class. + +In this case just define a mapping method for the referenced object type as well: + +.Mapper with one mapping method using another +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarDto carToCarDto(Car car); + + PersonDto personToPersonDto(Person person); +} +---- +==== + +The generated code for the `carToCarDto()` method will invoke the `personToPersonDto()` method for mapping the `driver` attribute, while the generated implementation for `personToPersonDto()` performs the mapping of person objects. + +That way it is possible to map arbitrary deep object graphs. When mapping from entities into data transfer objects it is often useful to cut references to other entities at a certain point. To do so, implement a custom mapping method (see the next section) which e.g. maps a referenced entity to its id in the target object. + +When generating the implementation of a mapping method, MapStruct will apply the following routine for each attribute pair in the source and target object: + +* If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. +* If source and target attribute type differ, check whether there is another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. +* If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. +* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. +* If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. + +[NOTE] +==== +In order to stop MapStruct from generating automatic sub-mapping methods, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. +==== + +[NOTE] +==== +During the generation of automatic sub-mapping methods <> will not be taken into consideration, yet. +Follow issue https://github.com/mapstruct/mapstruct/issues/1086[#1086] for more information. +==== + +[[controlling-nested-bean-mappings]] +=== Controlling nested bean mappings + +As explained above, MapStruct will generate a method based on the name of the source and target property. Unfortunately, in many occasions these names do not match. + +The ‘.’ notation in an `@Mapping` source or target type can be used to control how properties should be mapped when names do not match. +There is an elaborate https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-nested-bean-mappings[example] in our examples repository to explain how this problem can be overcome. + +In the simplest scenario there’s a property on a nested level that needs to be corrected. +Take for instance a property `fish` which has an identical name in `FishTankDto` and `FishTank`. +For this property MapStruct automatically generates a mapping: `FishDto fishToFishDto(Fish fish)`. +MapStruct cannot possibly be aware of the deviating properties `kind` and `type`. +Therefore this can be addressed in a mapping rule: `@Mapping(target="fish.kind", source="fish.type")`. +This tells MapStruct to deviate from looking for a name `kind` at this level and map it to `type`. + +.Mapper controlling nested beans mappings I +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface FishTankMapper { + + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", ignore = true) + @Mapping(target = "ornament", source = "interior.ornament") + @Mapping(target = "material.materialType", source = "material") + @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") + FishTankDto map( FishTank source ); +} +---- +==== + +The same constructs can be used to ignore certain properties at a nesting level, as is demonstrated in the second `@Mapping` rule. + +MapStruct can even be used to “cherry pick” properties when source and target do not share the same nesting level (the same number of properties). +This can be done in the source – and in the target type. This is demonstrated in the next 2 rules: `@Mapping(target="ornament", source="interior.ornament")` and `@Mapping(target="material.materialType", source="material")`. + +The latter can even be done when mappings first share a common base. +For example: all properties that share the same name of `Quality` are mapped to `QualityDto`. +Likewise, all properties of `Report` are mapped to `ReportDto`, with one exception: `organisation` in `OrganisationDto` is left empty (since there is no organization at the source level). +Only the `name` is populated with the `organisationName` from `Report`. +This is demonstrated in `@Mapping(target="quality.report.organisation.name", source="quality.report.organisationName")` + +Coming back to the original example: what if `kind` and `type` would be beans themselves? +In that case MapStruct would again generate a method continuing to map. +Such is demonstrated in the next example: + + +.Mapper controlling nested beans mappings II +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface FishTankMapperWithDocument { + + @Mapping(target = "fish.kind", source = "fish.type") + @Mapping(target = "fish.name", expression = "java(\"Jaws\")") + @Mapping(target = "plant", ignore = true ) + @Mapping(target = "ornament", ignore = true ) + @Mapping(target = "material", ignore = true) + @Mapping(target = "quality.document", source = "quality.report") + @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) + FishTankWithNestedDocumentDto map( FishTank source ); + +} +---- +==== + +Note what happens in `@Mapping(target="quality.document", source="quality.report")`. +`DocumentDto` does not exist as such on the target side. It is mapped from `Report`. +MapStruct continues to generate mapping code here. That mapping itself can be guided towards another name. +This even works for constants and expression. Which is shown in the final example: `@Mapping(target="quality.document.organisation.name", constant="NoIdeaInc")`. + +MapStruct will perform a null check on each nested property in the source. + +[TIP] +==== +Instead of configuring everything via the parent method we encourage users to explicitly write their own nested methods. +This puts the configuration of the nested mapping into one place (method) where it can be reused from several methods in the upper level, +instead of re-configuring the same things on all of those upper methods. +==== + +[NOTE] +==== +In some cases the `ReportingPolicy` that is going to be used for the generated nested method would be `IGNORE`. +This means that it is possible for MapStruct not to report unmapped target properties in nested mappings. +==== + + +[[invoking-other-mappers]] +=== Invoking other mappers + +In addition to methods defined on the same mapper type MapStruct can also invoke mapping methods defined in other classes, be it mappers generated by MapStruct or hand-written mapping methods. This can be useful to structure your mapping code in several classes (e.g. with one mapper type per application module) or if you want to provide custom mapping logic which can't be generated by MapStruct. + +For instance the `Car` class might contain an attribute `manufacturingDate` while the corresponding DTO attribute is of type String. In order to map this attribute, you could implement a mapper class like this: + +.Manually implemented mapper class +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class DateMapper { + + public String asString(Date date) { + return date != null ? new SimpleDateFormat( "yyyy-MM-dd" ) + .format( date ) : null; + } + + public Date asDate(String date) { + try { + return date != null ? new SimpleDateFormat( "yyyy-MM-dd" ) + .parse( date ) : null; + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + } +} +---- +==== + +In the `@Mapper` annotation at the `CarMapper` interface reference the `DateMapper` class like this: + +.Referencing another mapper class +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses=DateMapper.class) +public class CarMapper { + + CarDto carToCarDto(Car car); +} +---- +==== + +When generating code for the implementation of the `carToCarDto()` method, MapStruct will look for a method which maps a `Date` object into a String, find it on the `DateMapper` class and generate an invocation of `asString()` for mapping the `manufacturingDate` attribute. + +Generated mappers retrieve referenced mappers using the component model configured for them. If e.g. CDI was used as component model for `CarMapper`, `DateMapper` would have to be a CDI bean as well. When using the default component model, any hand-written mapper classes to be referenced by MapStruct generated mappers must declare a public no-args constructor in order to be instantiable. + +[[passing-target-type]] +=== Passing the mapping target type to custom mappers + +When having a custom mapper hooked into the generated mapper with `@Mapper#uses()`, an additional parameter of type `Class` (or a super-type of it) can be defined in the custom mapping method in order to perform general mapping tasks for specific target object types. That attribute must be annotated with `@TargetType` for MapStruct to generate calls that pass the `Class` instance representing the corresponding property type of the target bean. + +For instance, the `CarDto` could have a property `owner` of type `Reference` that contains the primary key of a `Person` entity. You could now create a generic custom mapper that resolves any `Reference` objects to their corresponding managed JPA entity instances. + +.Mapping method expecting mapping target type as parameter +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@ApplicationScoped // CDI component model +public class ReferenceMapper { + + @PersistenceContext + private EntityManager entityManager; + + public T resolve(Reference reference, @TargetType Class entityClass) { + return reference != null ? entityManager.find( entityClass, reference.getPk() ) : null; + } + + public Reference toReference(BaseEntity entity) { + return entity != null ? new Reference( entity.getPk() ) : null; + } +} + +@Mapper(componentModel = "cdi", uses = ReferenceMapper.class ) +public interface CarMapper { + + Car carDtoToCar(CarDto carDto); +} +---- +==== + +MapStruct will then generate something like this: + +.Generated code +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +@ApplicationScoped +public class CarMapperImpl implements CarMapper { + + @Inject + private ReferenceMapper referenceMapper; + + @Override + public Car carDtoToCar(CarDto carDto) { + if ( carDto == null ) { + return null; + } + + Car car = new Car(); + + car.setOwner( referenceMapper.resolve( carDto.getOwner(), Owner.class ) ); + // ... + + return car; + } +} +---- +==== + +[[passing-context]] +=== Passing context or state objects to custom methods + +Additional _context_ or _state_ information can be passed through generated mapping methods to custom methods with `@Context` parameters. Such parameters are passed to other mapping methods, `@ObjectFactory` methods (see <>) or `@BeforeMapping` / `@AfterMapping` methods (see <>) when applicable and can thus be used in custom code. + +`@Context` parameters are searched for `@ObjectFactory` methods, which are called on the provided context parameter value if applicable. + +`@Context` parameters are also searched for `@BeforeMapping` / `@AfterMapping` methods, which are called on the provided context parameter value if applicable. + +*Note:* no `null` checks are performed before calling before/after mapping methods on context parameters. The caller needs to make sure that `null` is not passed in that case. + +For generated code to call a method that is declared with `@Context` parameters, the declaration of the mapping method being generated needs to contain at least those (or assignable) `@Context` parameters as well. The generated code will not create new instances of missing `@Context` parameters nor will it pass a literal `null` instead. + +.Using `@Context` parameters for passing data down to hand-written property mapping methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public abstract CarDto toCar(Car car, @Context Locale translationLocale); + +protected OwnerManualDto translateOwnerManual(OwnerManual ownerManual, @Context Locale locale) { + // manually implemented logic to translate the OwnerManual with the given Locale +} +---- +==== + +MapStruct will then generate something like this: + +.Generated code +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +public CarDto toCar(Car car, Locale translationLocale) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + carDto.setOwnerManual( translateOwnerManual( car.getOwnerManual(), translationLocale ); + // more generated mapping code + + return carDto; +} +---- +==== + + +[[mapping-method-resolution]] +=== Mapping method resolution + +When mapping a property from one type to another, MapStruct looks for the most specific method which maps the source type into the target type. The method may either be declared on the same mapper interface or on another mapper which is registered via `@Mapper#uses()`. The same applies for factory methods (see <>). + +The algorithm for finding a mapping or factory method resembles Java's method resolution algorithm as much as possible. In particular, methods with a more specific source type will take precedence (e.g. if there are two methods, one which maps the searched source type, and another one which maps a super-type of the same). In case more than one most-specific method is found, an error will be raised. + +[TIP] +==== +When working with JAXB, e.g. when converting a `String` to a corresponding `JAXBElement`, MapStruct will take the `scope` and `name` attributes of `@XmlElementDecl` annotations into account when looking for a mapping method. This makes sure that the created `JAXBElement` instances will have the right QNAME value. You can find a test which maps JAXB objects https://github.com/mapstruct/mapstruct/blob/{mapstructVersion}/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java[here]. +==== + +[[selection-based-on-qualifiers]] +=== Mapping method selection based on qualifiers + +In many occasions one requires mapping methods with the same method signature (apart from the name) that have different behavior. +MapStruct has a handy mechanism to deal with such situations: `@Qualifier` (`org.mapstruct.Qualifier`). +A ‘qualifier’ is a custom annotation that the user can write, ‘stick onto’ a mapping method which is included as used mapper +and can be referred to in a bean property mapping, iterable mapping or map mapping. +Multiple qualifiers can be ‘stuck onto’ a method and mapping. + +So, let's say there is a hand-written method to map titles with a `String` return type and `String` argument amongst many other referenced mappers with the same `String` return type - `String` argument signature: + +.Several mapping methods with identical source and target types +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Titles { + + public String translateTitleEG(String title) { + // some mapping logic + } + + public String translateTitleGE(String title) { + // some mapping logic + } +} +---- +==== + +And a mapper using this handwritten mapper, in which source and target have a property 'title' that should be mapped: + +.Mapper causing an ambiguous mapping method error +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper( uses = Titles.class ) +public interface MovieMapper { + + GermanRelease toGerman( OriginalRelease movies ); + +} +---- +==== + +Without the use of qualifiers, this would result in an ambiguous mapping method error, because 2 qualifying methods are found (`translateTitleEG`, `translateTitleGE`) and MapStruct would not have a hint which one to choose. + +Enter the qualifier approach: + +.Declaring a qualifier type +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.CLASS) +public @interface TitleTranslator { +} +---- +==== + +And, some qualifiers to indicate which translator to use to map from source language to target language: + +.Declaring qualifier types for mapping methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface EnglishToGerman { +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface GermanToEnglish { +} +---- +==== + +Please take note of the target `TitleTranslator` on type level, `EnglishToGerman`, `GermanToEnglish` on method level! + +Then, using the qualifiers, the mapping could look like this: + +.Mapper using qualifiers +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper( uses = Titles.class ) +public interface MovieMapper { + + @Mapping( target = "title", qualifiedBy = { TitleTranslator.class, EnglishToGerman.class } ) + GermanRelease toGerman( OriginalRelease movies ); + +} +---- +==== + +.Custom mapper qualifying the methods it provides +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@TitleTranslator +public class Titles { + + @EnglishToGerman + public String translateTitleEG(String title) { + // some mapping logic + } + + @GermanToEnglish + public String translateTitleGE(String title) { + // some mapping logic + } +} +---- +==== + +[WARNING] +==== +Please make sure the used retention policy equals retention policy `CLASS` (`@Retention(RetentionPolicy.CLASS)`). +==== + +[WARNING] +==== +A class / method annotated with a qualifier will not qualify anymore for mappings that do not have the `qualifiedBy` element. +==== + +[TIP] +==== +The same mechanism is also present on bean mappings: `@BeanMapping#qualifiedBy`: it selects the factory method marked with the indicated qualifier. +==== + +In many occasions, declaring a new annotation to aid the selection process can be too much for what you try to achieve. For those situations, MapStruct has the `@Named` annotation. This annotation is a pre-defined qualifier (annotated with `@Qualifier` itself) and can be used to name a Mapper or, more directly a mapping method by means of its value. The same example above would look like: + +.Custom mapper, annotating the methods to qualify by means of `@Named` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Named("TitleTranslator") +public class Titles { + + @Named("EnglishToGerman") + public String translateTitleEG(String title) { + // some mapping logic + } + + @Named("GermanToEnglish") + public String translateTitleGE(String title) { + // some mapping logic + } +} +---- +==== + +.Mapper using named +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper( uses = Titles.class ) +public interface MovieMapper { + + @Mapping( target = "title", qualifiedByName = { "TitleTranslator", "EnglishToGerman" } ) + GermanRelease toGerman( OriginalRelease movies ); + +} +---- +==== + +[WARNING] +==== +Although the used mechanism is the same, the user has to be a bit more careful. Refactoring the name of a defined qualifier in an IDE will neatly refactor all other occurrences as well. This is obviously not the case for changing a name. +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc new file mode 100644 index 0000000000..0713316a46 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -0,0 +1,227 @@ +[[mapping-collections]] +== Mapping collections + +The mapping of collection types (`List`, `Set` etc.) is done in the same way as mapping bean types, i.e. by defining mapping methods with the required source and target types in a mapper interface. MapStruct supports a wide range of iterable types from the http://docs.oracle.com/javase/tutorial/collections/intro/index.html[Java Collection Framework]. + +The generated code will contain a loop which iterates over the source collection, converts each element and puts it into the target collection. If a mapping method for the collection element types is found in the given mapper or the mapper it uses, this method is invoked to perform the element conversion. Alternatively, if an implicit conversion for the source and target element types exists, this conversion routine will be invoked. The following shows an example: + +.Mapper with collection mapping methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + Set integerSetToStringSet(Set integers); + + List carsToCarDtos(List cars); + + CarDto carToCarDto(Car car); +} +---- +==== + +The generated implementation of the `integerSetToStringSet` performs the conversion from `Integer` to `String` for each element, while the generated `carsToCarDtos()` method invokes the `carToCarDto()` method for each contained element as shown in the following: + +.Generated collection mapping methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +@Override +public Set integerSetToStringSet(Set integers) { + if ( integers == null ) { + return null; + } + + Set set = new HashSet(); + + for ( Integer integer : integers ) { + set.add( String.valueOf( integer ) ); + } + + return set; +} + +@Override +public List carsToCarDtos(List cars) { + if ( cars == null ) { + return null; + } + + List list = new ArrayList(); + + for ( Car car : cars ) { + list.add( carToCarDto( car ) ); + } + + return list; +} +---- +==== + +Note that MapStruct will look for a collection mapping method with matching parameter and return type, when mapping a collection-typed attribute of a bean, e.g. from `Car#passengers` (of type `List`) to `CarDto#passengers` (of type `List`). + +.Usage of collection mapping method to map a bean property +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +carDto.setPassengers( personsToPersonDtos( car.getPassengers() ) ); +... +---- +==== + +Some frameworks and libraries only expose JavaBeans getters but no setters for collection-typed properties. Types generated from an XML schema using JAXB adhere to this pattern by default. In this case the generated code for mapping such a property invokes its getter and adds all the mapped elements: + +.Usage of an adding method for collection mapping +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +carDto.getPassengers().addAll( personsToPersonDtos( car.getPassengers() ) ); +... +---- +==== + +[WARNING] +==== +It is not allowed to declare mapping methods with an iterable source and a non-iterable target or the other way around. An error will be raised when detecting this situation. +==== + +[[mapping-maps]] +=== Mapping maps + +Also map-based mapping methods are supported. The following shows an example: + +.Map mapping method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public interface SourceTargetMapper { + + @MapMapping(valueDateFormat = "dd.MM.yyyy") + Map longDateMapToStringStringMap(Map source); +} +---- +==== + +Similar to iterable mappings, the generated code will iterate through the source map, convert each value and key (either by means of an implicit conversion or by invoking another mapping method) and put them into the target map: + +.Generated implementation of map mapping method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +@Override +public Map stringStringMapToLongDateMap(Map source) { + if ( source == null ) { + return null; + } + + Map map = new HashMap(); + + for ( Map.Entry entry : source.entrySet() ) { + + Long key = Long.parseLong( entry.getKey() ); + Date value; + try { + value = new SimpleDateFormat( "dd.MM.yyyy" ).parse( entry.getValue() ); + } + catch( ParseException e ) { + throw new RuntimeException( e ); + } + + map.put( key, value ); + } + + return map; +} +---- +==== + +[[collection-mapping-strategies]] +=== Collection mapping strategies + +MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED`, `ADDER_PREFERRED` and `TARGET_IMMUTABLE`. + +In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are applied to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: + +.Collection mapping strategy options +|=== +|Option|Only target set-s Available|Only target add- Available|Both set-s / add- Available|No set-s / add- Available|Existing Target(`@TargetType`) + +|`ACCESSOR_ONLY` +|set-s +|get-s +|set-s +|get-s +|get-s + +|`SETTER_PREFERRED` +|set-s +|add- +|set-s +|get-s +|get-s + +|`ADDER_PREFERRED` +|set-s +|add- +|add- +|get-s +|get-s + +|`TARGET_IMMUTABLE` +|set-s +|exception +|set-s +|exception +|set-s +|=== + +Some background: An `adder` method is typically used in case of http://www.eclipse.org/webtools/dali/[generated (JPA) entities], to add a single element (entity) to an underlying collection. Invoking the adder establishes a parent-child relation between parent - the bean (entity) on which the adder is invoked - and its child(ren), the elements (entities) in the collection. To find the appropriate `adder`, MapStruct will try to make a match between the generic parameter type of the underlying collection and the single argument of a candidate `adder`. When there are more candidates, the plural `setter` / `getter` name is converted to singular and will be used in addition to make a match. + +The option `DEFAULT` should not be used explicitly. It is used to distinguish between an explicit user desire to override the default in a `@MapperConfig` from the implicit Mapstruct choice in a `@Mapper`. The option `DEFAULT` is synonymous to `ACCESSOR_ONLY`. + +[TIP] +==== +When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with intialized collections instead of Mapstruct creating the target entity by its constructor. +==== + +[[implementation-types-for-collection-mappings]] +=== Implementation types used for collection mappings + +When an iterable or map mapping method declares an interface type as return type, one of its implementation types will be instantiated in the generated code. The following table shows the supported interface types and their corresponding implementation types as instantiated in the generated code: + +.Collection mapping implementation types +|=== +|Interface type|Implementation type + +|`Iterable`|`ArrayList` + +|`Collection`|`ArrayList` + +|`List`|`ArrayList` + +|`Set`|`HashSet` + +|`SortedSet`|`TreeSet` + +|`NavigableSet`|`TreeSet` + +|`Map`|`HashMap` + +|`SortedMap`|`TreeMap` + +|`NavigableMap`|`TreeMap` + +|`ConcurrentMap`|`ConcurrentHashMap` +|`ConcurrentNavigableMap`|`ConcurrentSkipListMap` +|=== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/mapping-streams.asciidoc b/documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc similarity index 100% rename from documentation/src/main/asciidoc/mapping-streams.asciidoc rename to documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc new file mode 100644 index 0000000000..752c1418a1 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -0,0 +1,143 @@ +[[mapping-enum-types]] +== Mapping Values + +=== Mapping enum types + +MapStruct supports the generation of methods which map one Java enum type into another. + +By default, each constant from the source enum is mapped to a constant with the same name in the target enum type. If required, a constant from the source enum may be mapped to a constant with another name with help of the `@ValueMapping` annotation. Several constants from the source enum can be mapped to the same constant in the target type. + +The following shows an example: + +.Enum mapping method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface OrderMapper { + + OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); + + @ValueMappings({ + @ValueMapping(source = "EXTRA", target = "SPECIAL"), + @ValueMapping(source = "STANDARD", target = "DEFAULT"), + @ValueMapping(source = "NORMAL", target = "DEFAULT") + }) + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); +} +---- +==== + +.Enum mapping method result +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class OrderMapperImpl implements OrderMapper { + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType_; + + switch ( orderType ) { + case EXTRA: externalOrderType_ = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType_ = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType_ = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType_ = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType_ = ExternalOrderType.B2B; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType_; + } +} +---- +==== +By default an error will be raised by MapStruct in case a constant of the source enum type does not have a corresponding constant with the same name in the target type and also is not mapped to another constant via `@ValueMapping`. This ensures that all constants are mapped in a safe and predictable manner. The generated +mapping method will throw an IllegalStateException if for some reason an unrecognized source value occurs. + +MapStruct also has a mechanism for mapping any remaining (unspecified) mappings to a default. This can be used only once in a set of value mappings. It comes in two flavors: `` and ``. + +In case of source `` MapStruct will continue to map a source enum constant to a target enum constant with the same name. The remainder of the source enum constants will be mapped to the target specified in the `@ValueMapping` with `` source. + +MapStruct will *not* attempt such name based mapping for `` and directly apply the target specified in the `@ValueMapping` with `` source to the remainder. + +MapStruct is able to handle `null` sources and `null` targets by means of the `` keyword. + +[TIP] +==== +Constants for ``, `` and `` are available in the `MappingConstants` class. +==== + +Finally `@InheritInverseConfiguration` and `@InheritConfiguration` can be used in combination with `@ValueMappings`. + +.Enum mapping method, and +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface SpecialOrderMapper { + + SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); + + @ValueMappings({ + @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ), + @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ), + @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" ) + }) + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); +} +---- +==== + +.Enum mapping method result, and +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class SpecialOrderMapperImpl implements SpecialOrderMapper { + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return ExternalOrderType.DEFAULT; + } + + ExternalOrderType externalOrderType_; + + switch ( orderType ) { + case STANDARD: externalOrderType_ = null; + break; + case RETAIL: externalOrderType_ = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType_ = ExternalOrderType.B2B; + break; + default: externalOrderType_ = ExternalOrderType.SPECIAL; + } + + return externalOrderType_; + } +} +---- +==== + +*Note:* MapStruct would have refrained from mapping the `RETAIL` and `B2B` when `` was used instead of ``. + + +[WARNING] +==== +The mapping of enum to enum via the `@Mapping` annotation is *DEPRECATED*. It will be removed from future versions of MapStruct. Please adapt existing enum mapping methods to make use of `@ValueMapping` instead. +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-9-object-factories.asciidoc b/documentation/src/main/asciidoc/chapter-9-object-factories.asciidoc new file mode 100644 index 0000000000..1b1e94c64f --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-9-object-factories.asciidoc @@ -0,0 +1,170 @@ +[[object-factories]] +== Object factories + +By default, the generated code for mapping one bean type into another or updating a bean will call the default constructor to instantiate the target type. + +Alternatively you can plug in custom object factories which will be invoked to obtain instances of the target type. One use case for this is JAXB which creates `ObjectFactory` classes for obtaining new instances of schema types. + +To make use of custom factories register them via `@Mapper#uses()` as described in <>, or implement them directly in your mapper. When creating the target object of a bean mapping, MapStruct will look for a parameterless method, a method annotated with `@ObjectFactory`, or a method with only one `@TargetType` parameter that returns the required target type and invoke this method instead of calling the default constructor: + +.Custom object factories +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class DtoFactory { + + public CarDto createCarDto() { + return // ... custom factory logic + } +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class EntityFactory { + + public T createEntity(@TargetType Class entityClass) { + return // ... custom factory logic + } +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses= { DtoFactory.class, EntityFactory.class } ) +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + CarDto carToCarDto(Car car); + + Car carDtoToCar(CarDto carDto); +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +public class CarMapperImpl implements CarMapper { + + private final DtoFactory dtoFactory = new DtoFactory(); + + private final EntityFactory entityFactory = new EntityFactory(); + + @Override + public CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = dtoFactory.createCarDto(); + + //map properties... + + return carDto; + } + + @Override + public Car carDtoToCar(CarDto carDto) { + if ( carDto == null ) { + return null; + } + + Car car = entityFactory.createEntity( Car.class ); + + //map properties... + + return car; + } +} +---- +==== + +.Custom object factories with update methods +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(uses = { DtoFactory.class, EntityFactory.class, CarMapper.class } ) +public interface OwnerMapper { + + OwnerMapper INSTANCE = Mappers.getMapper( OwnerMapper.class ); + + void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto); + + void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner); +} +---- +[source, java, linenums] +[subs="verbatim,attributes"] +---- +//GENERATED CODE +public class OwnerMapperImpl implements OwnerMapper { + + private final DtoFactory dtoFactory = new DtoFactory(); + + private final EntityFactory entityFactory = new EntityFactory(); + + private final OwnerMapper ownerMapper = Mappers.getMapper( OwnerMapper.class ); + + @Override + public void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto) { + if ( owner == null ) { + return; + } + + if ( owner.getCar() != null ) { + if ( ownerDto.getCar() == null ) { + ownerDto.setCar( dtoFactory.createCarDto() ); + } + // update car within ownerDto + } + else { + ownerDto.setCar( null ); + } + + // updating other properties + } + + @Override + public void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner) { + if ( ownerDto == null ) { + return; + } + + if ( ownerDto.getCar() != null ) { + if ( owner.getCar() == null ) { + owner.setCar( entityFactory.createEntity( Car.class ) ); + } + // update car within owner + } + else { + owner.setCar( null ); + } + + // updating other properties + } +} +---- +==== + +In addition, annotating a factory method with `@ObjectFactory` lets you gain access to the mapping sources. +Source objects can be added as parameters in the same way as for mapping method. The `@ObjectFactory` +annotation is necessary to let MapStruct know that the given method is only a factory method. + +.Custom object factories with `@ObjectFactory` + +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class DtoFactory { + + @ObjectFactory + public CarDto createCarDto(Car car) { + return // ... custom factory logic + } +} +---- +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc b/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc deleted file mode 100644 index a3e6cdb82e..0000000000 --- a/documentation/src/main/asciidoc/controlling-nested-bean-mappings.asciidoc +++ /dev/null @@ -1,89 +0,0 @@ -[[controlling-nested-bean-mappings]] -=== Controlling nested bean mappings - -As explained above, MapStruct will generate a method based on the name of the source and target property. Unfortunately, in many occasions these names do not match. - -The ‘.’ notation in an `@Mapping` source or target type can be used to control how properties should be mapped when names do not match. -There is an elaborate https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-nested-bean-mappings[example] in our examples repository to explain how this problem can be overcome. - -In the simplest scenario there’s a property on a nested level that needs to be corrected. -Take for instance a property `fish` which has an identical name in `FishTankDto` and `FishTank`. -For this property MapStruct automatically generates a mapping: `FishDto fishToFishDto(Fish fish)`. -MapStruct cannot possibly be aware of the deviating properties `kind` and `type`. -Therefore this can be addressed in a mapping rule: `@Mapping(target="fish.kind", source="fish.type")`. -This tells MapStruct to deviate from looking for a name `kind` at this level and map it to `type`. - -.Mapper controlling nested beans mappings I -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface FishTankMapper { - - @Mapping(target = "fish.kind", source = "fish.type") - @Mapping(target = "fish.name", ignore = true) - @Mapping(target = "ornament", source = "interior.ornament") - @Mapping(target = "material.materialType", source = "material") - @Mapping(target = "quality.report.organisation.name", source = "quality.report.organisationName") - FishTankDto map( FishTank source ); -} ----- -==== - -The same constructs can be used to ignore certain properties at a nesting level, as is demonstrated in the second `@Mapping` rule. - -MapStruct can even be used to “cherry pick” properties when source and target do not share the same nesting level (the same number of properties). -This can be done in the source – and in the target type. This is demonstrated in the next 2 rules: `@Mapping(target="ornament", source="interior.ornament")` and `@Mapping(target="material.materialType", source="material")`. - -The latter can even be done when mappings first share a common base. -For example: all properties that share the same name of `Quality` are mapped to `QualityDto`. -Likewise, all properties of `Report` are mapped to `ReportDto`, with one exception: `organisation` in `OrganisationDto` is left empty (since there is no organization at the source level). -Only the `name` is populated with the `organisationName` from `Report`. -This is demonstrated in `@Mapping(target="quality.report.organisation.name", source="quality.report.organisationName")` - -Coming back to the original example: what if `kind` and `type` would be beans themselves? -In that case MapStruct would again generate a method continuing to map. -Such is demonstrated in the next example: - - -.Mapper controlling nested beans mappings II -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface FishTankMapperWithDocument { - - @Mapping(target = "fish.kind", source = "fish.type") - @Mapping(target = "fish.name", expression = "java(\"Jaws\")") - @Mapping(target = "plant", ignore = true ) - @Mapping(target = "ornament", ignore = true ) - @Mapping(target = "material", ignore = true) - @Mapping(target = "quality.document", source = "quality.report") - @Mapping(target = "quality.document.organisation.name", constant = "NoIdeaInc" ) - FishTankWithNestedDocumentDto map( FishTank source ); - -} ----- -==== - -Note what happens in `@Mapping(target="quality.document", source="quality.report")`. -`DocumentDto` does not exist as such on the target side. It is mapped from `Report`. -MapStruct continues to generate mapping code here. That mapping itself can be guided towards another name. -This even works for constants and expression. Which is shown in the final example: `@Mapping(target="quality.document.organisation.name", constant="NoIdeaInc")`. - -MapStruct will perform a null check on each nested property in the source. - -[TIP] -==== -Instead of configuring everything via the parent method we encourage users to explicitly write their own nested methods. -This puts the configuration of the nested mapping into one place (method) where it can be reused from several methods in the upper level, -instead of re-configuring the same things on all of those upper methods. -==== - -[NOTE] -==== -In some cases the `ReportingPolicy` that is going to be used for the generated nested method would be `IGNORE`. -This means that it is possible for MapStruct not to report unmapped target properties in nested mappings. -==== diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 58cc0cfb99..1aa08b17b8 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -20,2911 +20,28 @@ This work is licensed under the http://creativecommons.org/licenses/by-sa/4.0/[C :numbered: -[[introduction]] -== Introduction +include::chapter-1-introduction.asciidoc[] -MapStruct is a Java http://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html[annotation processor] for the generation of type-safe bean mapping classes. +include::chapter-2-set-up.asciidoc[] -All you have to do is to define a mapper interface which declares any required mapping methods. During compilation, MapStruct will generate an implementation of this interface. This implementation uses plain Java method invocations for mapping between source and target objects, i.e. no reflection or similar. +include::chapter-3-defining-a-mapper.asciidoc[] -Compared to writing mapping code from hand, MapStruct saves time by generating code which is tedious and error-prone to write. Following a convention over configuration approach, MapStruct uses sensible defaults but steps out of your way when it comes to configuring or implementing special behavior. +include::chapter-4-retrieving-a-mapper.asciidoc[] -Compared to dynamic mapping frameworks, MapStruct offers the following advantages: +include::chapter-5-data-type-conversions.asciidoc[] -* Fast execution by using plain method invocations instead of reflection -* Compile-time type safety: Only objects and attributes mapping to each other can be mapped, no accidental mapping of an order entity into a customer DTO etc. -* Clear error-reports at build time, if - ** mappings are incomplete (not all target properties are mapped) - ** mappings are incorrect (cannot find a proper mapping method or type conversion) +include::chapter-6-mapping-collections.asciidoc[] -[[setup]] -== Set up +include::chapter-7-mapping-streams.asciidoc[] -MapStruct is a Java annotation processor based on http://www.jcp.org/en/jsr/detail?id=269[JSR 269] and as such can be used within command line builds (javac, Ant, Maven etc.) as well as from within your IDE. +include::chapter-8-mapping-values.asciidoc[] -It comprises the following artifacts: +include::chapter-9-object-factories.asciidoc[] -* _org.mapstruct:mapstruct_: contains the required annotations such as `@Mapping` -* _org.mapstruct:mapstruct-processor_: contains the annotation processor which generates mapper implementations +include::chapter-10-advanced-mapping-options.asciidoc[] -=== Apache Maven +include::chapter-11-reusing-mapping-configurations.asciidoc[] -For Maven based projects add the following to your POM file in order to use MapStruct: +include::chapter-12-customizing-mapping.asciidoc[] -.Maven configuration -==== -[source, xml, linenums] -[subs="verbatim,attributes"] ----- -... - - {mapstructVersion} - -... - - - org.mapstruct - mapstruct - ${org.mapstruct.version} - - -... - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.8 - 1.8 - - - org.mapstruct - mapstruct-processor - ${org.mapstruct.version} - - - - - - -... ----- -==== - -[TIP] -==== -If you are working with the Eclipse IDE, make sure to have a current version of the http://www.eclipse.org/m2e/[M2E plug-in]. -When importing a Maven project configured as shown above, it will set up the MapStruct annotation processor so it runs right in the IDE, whenever you save a mapper type. -Neat, isn't it? - -To double check that everything is working as expected, go to your project's properties and select "Java Compiler" -> "Annotation Processing" -> "Factory Path". -The MapStruct processor JAR should be listed and enabled there. -Any processor options configured via the compiler plug-in (see below) should be listed under "Java Compiler" -> "Annotation Processing". - -If the processor is not kicking in, check that the configuration of annotation processors through M2E is enabled. -To do so, go to "Preferences" -> "Maven" -> "Annotation Processing" and select "Automatically configure JDT APT". -Alternatively, specify the following in the `properties` section of your POM file: `jdt_apt`. - -Also make sure that your project is using Java 1.8 or later (project properties -> "Java Compiler" -> "Compile Compliance Level"). -It will not work with older versions. -==== - -=== Gradle - -Add the following to your Gradle build file in order to enable MapStruct: - -.Gradle configuration (3.4 and later) -==== -[source, groovy, linenums] -[subs="verbatim,attributes"] ----- -... -plugins { - ... - id 'net.ltgt.apt' version '0.20' -} - -// You can integrate with your IDEs. -// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides -apply plugin: 'net.ltgt.apt-idea' -apply plugin: 'net.ltgt.apt-eclipse' - -dependencies { - ... - implementation "org.mapstruct:mapstruct:${mapstructVersion}" - annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" - - // If you are using mapstruct in test code - testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" -} -... ----- -==== -.Gradle (3.3 and older) -==== -[source, groovy, linenums] -[subs="verbatim,attributes"] ----- -... -plugins { - ... - id 'net.ltgt.apt' version '0.20' -} - -// You can integrate with your IDEs. -// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides -apply plugin: 'net.ltgt.apt-idea' -apply plugin: 'net.ltgt.apt-eclipse' - -dependencies { - ... - compile "org.mapstruct:mapstruct:${mapstructVersion}" - annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" - - // If you are using mapstruct in test code - testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" -} -... ----- -==== - -You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-gradle[mapstruct-examples] project on GitHub. - - -=== Apache Ant - -Add the `javac` task configured as follows to your _build.xml_ file in order to enable MapStruct in your Ant-based project. Adjust the paths as required for your project layout. - -.Ant configuration -==== -[source, xml, linenums] -[subs="verbatim,attributes"] ----- -... - - - - -... ----- -==== - -You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-ant[mapstruct-examples] project on GitHub. - -[[configuration-options]] -=== Configuration options - -The MapStruct code generator can be configured using _annotation processor options_. - -When invoking javac directly, these options are passed to the compiler in the form _-Akey=value_. When using MapStruct via Maven, any processor options can be passed using an `options` element within the configuration of the Maven processor plug-in like this: - -.Maven configuration -==== -[source, xml, linenums] -[subs="verbatim,attributes"] ----- -... - - org.apache.maven.plugins - maven-compiler-plugin - 3.5.1 - - 1.8 - 1.8 - - - org.mapstruct - mapstruct-processor - ${org.mapstruct.version} - - - - true - - - -Amapstruct.suppressGeneratorTimestamp=true - - - -Amapstruct.suppressGeneratorVersionInfoComment=true - - - -Amapstruct.verbose=true - - - - -... ----- -==== - -.Gradle configuration -==== -[source, groovy, linenums] -[subs="verbatim,attributes"] ----- -... -compileJava { - options.compilerArgs = [ - '-Amapstruct.suppressGeneratorTimestamp=true', - '-Amapstruct.suppressGeneratorVersionInfoComment=true', - '-Amapstruct.verbose=true' - ] -} -... ----- -==== - -The following options exist: - -.MapStruct processor options -[cols="1,2a,1"] -|=== -|Option|Purpose|Default - -|`mapstruct. -suppressGeneratorTimestamp` -|If set to `true`, the creation of a time stamp in the `@Generated` annotation in the generated mapper classes is suppressed. -|`false` - -|`mapstruct.verbose` -|If set to `true`, MapStruct in which MapStruct logs its major decisions. Note, at the moment of writing in Maven, also `showWarnings` needs to be added due to a problem in the maven-compiler-plugin configuration. -|`false` - -|`mapstruct. -suppressGeneratorVersionInfoComment` -|If set to `true`, the creation of the `comment` attribute in the `@Generated` annotation in the generated mapper classes is suppressed. The comment contains information about the version of MapStruct and about the compiler used for the annotation processing. -|`false` - -|`mapstruct.defaultComponentModel` -|The name of the component model (see <>) based on which mappers should be generated. - -Supported values are: - -* `default`: the mapper uses no component model, instances are typically retrieved via `Mappers#getMapper(Class)` -* `cdi`: the generated mapper is an application-scoped CDI bean and can be retrieved via `@Inject` -* `spring`: the generated mapper is a singleton-scoped Spring bean and can be retrieved via `@Autowired` -* `jsr330`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject`, e.g. using Spring - -If a component model is given for a specific mapper via `@Mapper#componentModel()`, the value from the annotation takes precedence. -|`default` - -|`mapstruct.unmappedTargetPolicy` -|The default reporting policy to be applied in case an attribute of the target object of a mapping method is not populated with a source value. - -Supported values are: - -* `ERROR`: any unmapped target property will cause the mapping code generation to fail -* `WARN`: any unmapped target property will cause a warning at build time -* `IGNORE`: unmapped target properties are ignored - -If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. -|`WARN` -|=== - -=== Using MapStruct on Java 9 - -MapStruct can be used with Java 9 (JPMS), support for it is experimental. - -A core theme of Java 9 is the modularization of the JDK. One effect of this is that a specific module needs to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. - -To allow usage of the `@Generated` annotation the module _java.xml.ws.annotation_ must be enabled. When using Maven, this can be done like this: - - export MAVEN_OPTS="--add-modules java.xml.ws.annotation" - -If the `@Generated` annotation is not available, MapStruct will detect this situation and not add it to generated mappers. - -[NOTE] -===== -In Java 9 `java.annotation.processing.Generated` was added (part of the `java.compiler` module), -if this annotation is available then it will be used. -===== - -[[defining-mapper]] -== Defining a mapper - -In this section you'll learn how to define a bean mapper with MapStruct and which options you have to do so. - -[[basic-mappings]] -=== Basic mappings - -To create a mapper simply define a Java interface with the required mapping method(s) and annotate it with the `org.mapstruct.Mapper` annotation: - -.Java interface to define a mapper -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(source = "make", target = "manufacturer") - @Mapping(source = "numberOfSeats", target = "seatCount") - CarDto carToCarDto(Car car); - - @Mapping(source = "name", target = "fullName") - PersonDto personToPersonDto(Person person); -} ----- -==== - -The `@Mapper` annotation causes the MapStruct code generator to create an implementation of the `CarMapper` interface during build-time. - -In the generated method implementations all readable properties from the source type (e.g. `Car`) will be copied into the corresponding property in the target type (e.g. `CarDto`): - -* When a property has the same name as its target entity counterpart, it will be mapped implicitly. -* When a property has a different name in the target entity, its name can be specified via the `@Mapping` annotation. - -[TIP] -==== -The property name as defined in the http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html[JavaBeans specification] must be specified in the `@Mapping` annotation, e.g. _seatCount_ for a property with the accessor methods `getSeatCount()` and `setSeatCount()`. -==== -[TIP] -==== -By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. -==== -[TIP] -==== -Fluent setters are also supported. -Fluent setters are setters that return the same type as the type being modified. - -E.g. - -``` -public Builder seatCount(int seatCount) { - this.seatCount = seatCount; - return this; -} -``` -==== - - -To get a better understanding of what MapStruct does have a look at the following implementation of the `carToCarDto()` method as generated by MapStruct: - -.Code generated by MapStruct -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -public class CarMapperImpl implements CarMapper { - - @Override - public CarDto carToCarDto(Car car) { - if ( car == null ) { - return null; - } - - CarDto carDto = new CarDto(); - - if ( car.getFeatures() != null ) { - carDto.setFeatures( new ArrayList( car.getFeatures() ) ); - } - carDto.setManufacturer( car.getMake() ); - carDto.setSeatCount( car.getNumberOfSeats() ); - carDto.setDriver( personToPersonDto( car.getDriver() ) ); - carDto.setPrice( String.valueOf( car.getPrice() ) ); - if ( car.getCategory() != null ) { - carDto.setCategory( car.getCategory().toString() ); - } - carDto.setEngine( engineToEngineDto( car.getEngine() ) ); - - return carDto; - } - - @Override - public PersonDto personToPersonDto(Person person) { - //... - } - - private EngineDto engineToEngineDto(Engine engine) { - if ( engine == null ) { - return null; - } - - EngineDto engineDto = new EngineDto(); - - engineDto.setHorsePower(engine.getHorsePower()); - engineDto.setFuel(engine.getFuel()); - - return engineDto; - } -} ----- -==== - -The general philosophy of MapStruct is to generate code which looks as much as possible as if you had written it yourself from hand. In particular this means that the values are copied from source to target by plain getter/setter invocations instead of reflection or similar. - -As the example shows the generated code takes into account any name mappings specified via `@Mapping`. -If the type of a mapped attribute is different in source and target entity, -MapStruct will either apply an automatic conversion (as e.g. for the _price_ property, see also <>) -or optionally invoke / create another mapping method (as e.g. for the _driver_ / _engine_ property, see also <>). -MapStruct will only create a new mapping method if and only if the source and target property are properties of a Bean and they themselves are Beans or simple properties. -i.e. they are not `Collection` or `Map` type properties. - -Collection-typed attributes with the same element type will be copied by creating a new instance of the target collection type containing the elements from the source property. For collection-typed attributes with different element types each element will be mapped individually and added to the target collection (see <>). - -MapStruct takes all public properties of the source and target types into account. This includes properties declared on super-types. - -[[adding-custom-methods]] -=== Adding custom methods to mappers - -In some cases it can be required to manually implement a specific mapping from one type to another which can't be generated by MapStruct. One way to handle this is to implement the custom method on another class which then is used by mappers generated by MapStruct (see <>). - -Alternatively, when using Java 8 or later, you can implement custom methods directly in a mapper interface as default methods. The generated code will invoke the default methods if the argument and return types match. - -As an example let's assume the mapping from `Person` to `PersonDto` requires some special logic which can't be generated by MapStruct. You could then define the mapper from the previous example like this: - -.Mapper which defines a custom mapping with a default method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(...) - ... - CarDto carToCarDto(Car car); - - default PersonDto personToPersonDto(Person person) { - //hand-written mapping logic - } -} ----- -==== - -The class generated by MapStruct implements the method `carToCarDto()`. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute. - -A mapper could also be defined in the form of an abstract class instead of an interface and implement the custom methods directly in the mapper class. In this case MapStruct will generate an extension of the abstract class with implementations of all abstract methods. An advantage of this approach over declaring default methods is that additional fields could be declared in the mapper class. - -The previous example where the mapping from `Person` to `PersonDto` requires some special logic could then be defined like this: - -.Mapper defined by an abstract class -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public abstract class CarMapper { - - @Mapping(...) - ... - public abstract CarDto carToCarDto(Car car); - - public PersonDto personToPersonDto(Person person) { - //hand-written mapping logic - } -} ----- -==== - -MapStruct will generate a sub-class of `CarMapper` with an implementation of the `carToCarDto()` method as it is declared abstract. The generated code in `carToCarDto()` will invoke the manually implemented `personToPersonDto()` method when mapping the `driver` attribute. - -[[mappings-with-several-source-parameters]] -=== Mapping methods with several source parameters - -MapStruct also supports mapping methods with several source parameters. This is useful e.g. in order to combine several entities into one data transfer object. The following shows an example: - -.Mapping method with several source parameters -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface AddressMapper { - - @Mapping(source = "person.description", target = "description") - @Mapping(source = "address.houseNo", target = "houseNumber") - DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address); -} ----- -==== - -The shown mapping method takes two source parameters and returns a combined target object. As with single-parameter mapping methods properties are mapped by name. - -In case several source objects define a property with the same name, the source parameter from which to retrieve the property must be specified using the `@Mapping` annotation as shown for the `description` property in the example. An error will be raised when such an ambiguity is not resolved. For properties which only exist once in the given source objects it is optional to specify the source parameter's name as it can be determined automatically. - -[WARNING] -==== -Specifying the parameter in which the property resides is mandatory when using the `@Mapping` annotation. -==== - -[TIP] -==== -Mapping methods with several source parameters will return `null` in case all the source parameters are `null`. Otherwise the target object will be instantiated and all properties from the provided parameters will be propagated. -==== - -MapStruct also offers the possibility to directly refer to a source parameter. - -.Mapping method directly referring to a source parameter -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface AddressMapper { - - @Mapping(source = "person.description", target = "description") - @Mapping(source = "hn", target = "houseNumber") - DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn); -} ----- -==== - -In this case the source parameter is directly mapped into the target as the example above demonstrates. The parameter `hn`, a non bean type (in this case `java.lang.Integer`) is mapped to `houseNumber`. - -[[updating-bean-instances]] -=== Updating existing bean instances - -In some cases you need mappings which don't create a new instance of the target type but instead update an existing instance of that type. This sort of mapping can be realized by adding a parameter for the target object and marking this parameter with `@MappingTarget`. The following shows an example: - -.Update method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - void updateCarFromDto(CarDto carDto, @MappingTarget Car car); -} ----- -==== - -The generated code of the `updateCarFromDto()` method will update the passed `Car` instance with the properties from the given `CarDto` object. There may be only one parameter marked as mapping target. Instead of `void` you may also set the method's return type to the type of the target parameter, which will cause the generated implementation to update the passed mapping target and return it as well. This allows for fluent invocations of mapping methods. - -For `CollectionMappingStrategy.ACCESSOR_ONLY` Collection- or map-typed properties of the target bean to be updated will be cleared and then populated with the values from the corresponding source collection or map. Otherwise, For `CollectionMappingStrategy.ADDER_PREFERRED` or `CollectionMappingStrategy.TARGET_IMMUTABLE` the target will not be cleared and the values will be populated immediately. - -[[direct-field-mappings]] -=== Mappings with direct field access - -MapStruct also supports mappings of `public` fields that have no getters/setters. MapStruct will -use the fields as read/write accessor if it cannot find suitable getter/setter methods for the property. - -A field is considered as a read accessor if it is `public` or `public final`. If a field is `static` it is not -considered as a read accessor. - -A field is considered as a write accessor only if it is `public`. If a field is `final` and/or `static` it is not -considered as a write accessor. - -Small example: - -.Example classes for mapping -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class Customer { - - private Long id; - private String name; - - //getters and setter omitted for brevity -} - -public class CustomerDto { - - public Long id; - public String customerName; -} - -@Mapper -public interface CustomerMapper { - - CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); - - @Mapping(source = "customerName", target = "name") - Customer toCustomer(CustomerDto customerDto); - - @InheritInverseConfiguration - CustomerDto fromCustomer(Customer customer); -} ----- -==== - -For the configuration from above, the generated mapper looks like: - -.Generated mapper for example classes -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -public class CustomerMapperImpl implements CustomerMapper { - - @Override - public Customer toCustomer(CustomerDto customerDto) { - // ... - customer.setId( customerDto.id ); - customer.setName( customerDto.customerName ); - // ... - } - - @Override - public CustomerDto fromCustomer(Customer customer) { - // ... - customerDto.id = customer.getId(); - customerDto.customerName = customer.getName(); - // ... - } -} ----- -==== - -You can find the complete example in the -https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-field-mapping[mapstruct-examples-field-mapping] -project on GitHub. - -[[mapping-with-builders]] -=== Using builders - -MapStruct also supports mapping of immutable types via builders. -When performing a mapping MapStruct checks if there is a builder for the type being mapped. -This is done via the `BuilderProvider` SPI. -If a Builder exists for a certain type, then that builder will be used for the mappings. - -The default implementation of the `BuilderProvider` assumes the following: - -* The type has a parameterless public static builder creation method that returns a builder. -So for example `Person` has a public static method that returns `PersonBuilder`. -* The builder type has a parameterless public method (build method) that returns the type being build -In our example `PersonBuilder` has a method returning `Person`. -* In case there are multiple build methods, MapStruct will look for a method called `build`, if such method exists -then this would be used, otherwise a compilation error would be created. -* A specific build method can be defined by using `@Builder` within: `@BeanMapping`, `@Mapper` or `@MapperConfig` -* In case there are multiple builder creation methods that satisfy the above conditions then a `MoreThanOneBuilderCreationMethodException` -will be thrown from the `DefaultBuilderProvider` SPI. -In case of a `MoreThanOneBuilderCreationMethodException` MapStruct will write a warning in the compilation and not use any builder. - -If such type is found then MapStruct will use that type to perform the mapping to (i.e. it will look for setters into that type). -To finish the mapping MapStruct generates code that will invoke the build method of the builder. - -[NOTE] -====== -Builder detection can be switched off by means of `@Builder#disableBuilder`. MapStruct will fall back on regular getters / setters in case builders are disabled. -====== - -[NOTE] -====== -The <> are also considered for the builder type. -E.g. If an object factory exists for our `PersonBuilder` then this factory would be used instead of the builder creation method. -====== - -.Person with Builder example -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class Person { - - private final String name; - - protected Person(Person.Builder builder) { - this.name = builder.name; - } - - public static Person.Builder builder() { - return new Person.Builder(); - } - - public static class Builder { - - private String name; - - public Builder name(String name) { - this.name = name; - return this; - } - - public Person create() { - return new Person( this ); - } - } -} ----- -==== - -.Person Mapper definition -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public interface PersonMapper { - - Person map(PersonDto dto); -} ----- -==== - -.Generated mapper with builder -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -public class PersonMapperImpl implements PersonMapper { - - public Person map(PersonDto dto) { - if (dto == null) { - return null; - } - - Person.Builder builder = Person.builder(); - - builder.name( dto.getName() ); - - return builder.create(); - } -} ----- -==== - -Supported builder frameworks: - -* https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] -* https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] -* https://immutables.github.io/[Immutables] - When Immutables are present on the annotation processor path then the `ImmutablesAccessorNamingStrategy` and `ImmutablesBuilderProvider` would be used by default -* https://github.com/google/FreeBuilder[FreeBuilder] - When FreeBuilder is present on the annotation processor path then the `FreeBuilderAccessorNamingStrategy` would be used by default. -When using FreeBuilder then the JavaBean convention should be followed, otherwise MapStruct won't recognize the fluent getters. -* It also works for custom builders (handwritten ones) if the implementation supports the defined rules for the default `BuilderProvider`. -Otherwise, you would need to write a custom `BuilderProvider` - -[TIP] -==== -In case you want to disable using builders then you can use the `NoOpBuilderProvider` by creating a `org.mapstruct.ap.spi.BuilderProvider` file in the `META-INF/services` directory with `org.mapstruct.ap.spi.NoOpBuilderProvider` as it's content. -==== - -[[retrieving-mapper]] -== Retrieving a mapper - -[[mappers-factory]] -=== The Mappers factory (no dependency injection) - -When not using a DI framework, Mapper instances can be retrieved via the `org.mapstruct.factory.Mappers` class. Just invoke the `getMapper()` method, passing the interface type of the mapper to return: - -.Using the Mappers factory -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -CarMapper mapper = Mappers.getMapper( CarMapper.class ); ----- -==== - -By convention, a mapper interface should define a member called `INSTANCE` which holds a single instance of the mapper type: - -.Declaring an instance of a mapper (interface) -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); - - CarDto carToCarDto(Car car); -} - ----- -==== - -.Declaring an instance of a mapper (abstract class) -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public abstract class CarMapper { - - public static final CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); - - CarDto carToCarDto(Car car); -} - ----- -==== - -This pattern makes it very easy for clients to use mapper objects without repeatedly instantiating new instances: - -.Accessing a mapper -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -Car car = ...; -CarDto dto = CarMapper.INSTANCE.carToCarDto( car ); ----- -==== - - -Note that mappers generated by MapStruct are stateless and thread-safe and thus can safely be accessed from several threads at the same time. - -[[using-dependency-injection]] -=== Using dependency injection - -If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. - -Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: - -.A mapper using the CDI component model -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(componentModel = "cdi") -public interface CarMapper { - - CarDto carToCarDto(Car car); -} - ----- -==== - -The generated mapper implementation will be marked with the `@ApplicationScoped` annotation and thus can be injected into fields, constructor arguments etc. using the `@Inject` annotation: - -.Obtaining a mapper via dependency injection -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Inject -private CarMapper mapper; ----- -==== - -A mapper which uses other mapper classes (see <>) will obtain these mappers using the configured component model. So if `CarMapper` from the previous example was using another mapper, this other mapper would have to be an injectable CDI bean as well. - -[[injection-strategy]] -=== Injection strategy - -When using <>, you can choose between field and constructor injection. -This can be done by either providing the injection strategy via `@Mapper` or `@MapperConfig` annotation. - -.Using constructor injection -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) -public interface CarMapper { - CarDto carToCarDto(Car car); -} ----- -==== - -The generated mapper will inject all classes defined in the **uses** attribute. -When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. -When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. -For now, the default injection strategy is field injection. -It is recommended to use constructor injection to simplify testing. - -[TIP] -==== -For abstract classes or decorators setter injection should be used. -==== - -[[datatype-conversions]] -== Data type conversions - -Not always a mapped attribute has the same type in the source and target objects. For instance an attribute may be of type `int` in the source bean but of type `Long` in the target bean. - -Another example are references to other objects which should be mapped to the corresponding types in the target model. E.g. the class `Car` might have a property `driver` of the type `Person` which needs to be converted into a `PersonDto` object when mapping a `Car` object. - -In this section you'll learn how MapStruct deals with such data type conversions. - -[[implicit-type-conversions]] -=== Implicit type conversions - -MapStruct takes care of type conversions automatically in many cases. If for instance an attribute is of type `int` in the source bean but of type `String` in the target bean, the generated code will transparently perform a conversion by calling `String#valueOf(int)` and `Integer#parseInt(String)`, respectively. - -Currently the following conversions are applied automatically: - -* Between all Java primitive data types and their corresponding wrapper types, e.g. between `int` and `Integer`, `boolean` and `Boolean` etc. The generated code is `null` aware, i.e. when converting a wrapper type into the corresponding primitive type a `null` check will be performed. - -* Between all Java primitive number types and the wrapper types, e.g. between `int` and `long` or `byte` and `Integer`. - -[WARNING] -==== -Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. The `Mapper` and `MapperConfig` annotations have a method `typeConversionPolicy` to control warnings / errors. Due to backward compatibility reasons the default value is 'ReportingPolicy.IGNORE`. -==== - -* Between all Java primitive types (including their wrappers) and `String`, e.g. between `int` and `String` or `Boolean` and `String`. A format string as understood by `java.text.DecimalFormat` can be specified. - -.Conversion from int to String -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(source = "price", numberFormat = "$#.00") - CarDto carToCarDto(Car car); - - @IterableMapping(numberFormat = "$#.00") - List prices(List prices); -} ----- -==== -* Between `enum` types and `String`. - -* Between big number types (`java.math.BigInteger`, `java.math.BigDecimal`) and Java primitive types (including their wrappers) as well as String. A format string as understood by `java.text.DecimalFormat` can be specified. - -.Conversion from BigDecimal to String -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(source = "power", numberFormat = "#.##E0") - CarDto carToCarDto(Car car); - -} ----- -==== - - -* Between `JAXBElement` and `T`, `List>` and `List` - -* Between `java.util.Calendar`/`java.util.Date` and JAXB's `XMLGregorianCalendar` - -* Between `java.util.Date`/`XMLGregorianCalendar` and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option as this: - -.Conversion from Date to String -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(source = "manufacturingDate", dateFormat = "dd.MM.yyyy") - CarDto carToCarDto(Car car); - - @IterableMapping(dateFormat = "dd.MM.yyyy") - List stringListToDateList(List dates); -} ----- -==== - -* Between Jodas `org.joda.time.DateTime`, `org.joda.time.LocalDateTime`, `org.joda.time.LocalDate`, `org.joda.time.LocalTime` and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). - -* Between Jodas `org.joda.time.DateTime` and `javax.xml.datatype.XMLGregorianCalendar`, `java.util.Calendar`. - -* Between Jodas `org.joda.time.LocalDateTime`, `org.joda.time.LocalDate` and `javax.xml.datatype.XMLGregorianCalendar`, `java.util.Date`. - -* Between `java.time.ZonedDateTime`, `java.time.LocalDateTime`, `java.time.LocalDate`, `java.time.LocalTime` from Java 8 Date-Time package and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). - -* Between `java.time.Instant`, `java.time.Duration`, `java.time.Period` from Java 8 Date-Time package and `String` using the `parse` method in each class to map from `String` and using `toString` to map into `String`. - -* Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Date` where, when mapping a `ZonedDateTime` from a given `Date`, the system default timezone is used. - -* Between `java.time.LocalDateTime` from Java 8 Date-Time package and `java.util.Date` where timezone UTC is used as the timezone. - -* Between `java.time.LocalDate` from Java 8 Date-Time package and `java.util.Date` / `java.sql.Date` where timezone UTC is used as the timezone. - -* Between `java.time.Instant` from Java 8 Date-Time package and `java.util.Date`. - -* Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Calendar`. - -* Between `java.sql.Date` and `java.util.Date` - -* Between `java.sql.Time` and `java.util.Date` - -* Between `java.sql.Timestamp` and `java.util.Date` - -* When converting from a `String`, omitting `Mapping#dateFormat`, it leads to usage of the default pattern and date format symbols for the default locale. An exception to this rule is `XmlGregorianCalendar` which results in parsing the `String` according to http://www.w3.org/TR/xmlschema-2/#dateTime[XML Schema 1.0 Part 2, Section 3.2.7-14.1, Lexical Representation]. - -* Between `java.util.Currency` and `String`. -** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown - -[[mapping-object-references]] -=== Mapping object references - -Typically an object has not only primitive attributes but also references other objects. E.g. the `Car` class could contain a reference to a `Person` object (representing the car's driver) which should be mapped to a `PersonDto` object referenced by the `CarDto` class. - -In this case just define a mapping method for the referenced object type as well: - -.Mapper with one mapping method using another -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - CarDto carToCarDto(Car car); - - PersonDto personToPersonDto(Person person); -} ----- -==== - -The generated code for the `carToCarDto()` method will invoke the `personToPersonDto()` method for mapping the `driver` attribute, while the generated implementation for `personToPersonDto()` performs the mapping of person objects. - -That way it is possible to map arbitrary deep object graphs. When mapping from entities into data transfer objects it is often useful to cut references to other entities at a certain point. To do so, implement a custom mapping method (see the next section) which e.g. maps a referenced entity to its id in the target object. - -When generating the implementation of a mapping method, MapStruct will apply the following routine for each attribute pair in the source and target object: - -* If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. -* If source and target attribute type differ, check whether there is another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. -* If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. -* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. -* If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. - -[NOTE] -==== -In order to stop MapStruct from generating automatic sub-mapping methods, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. -==== - -[NOTE] -==== -During the generation of automatic sub-mapping methods <> will not be taken into consideration, yet. -Follow issue https://github.com/mapstruct/mapstruct/issues/1086[#1086] for more information. -==== - -include::controlling-nested-bean-mappings.asciidoc[] - -[[invoking-other-mappers]] -=== Invoking other mappers - -In addition to methods defined on the same mapper type MapStruct can also invoke mapping methods defined in other classes, be it mappers generated by MapStruct or hand-written mapping methods. This can be useful to structure your mapping code in several classes (e.g. with one mapper type per application module) or if you want to provide custom mapping logic which can't be generated by MapStruct. - -For instance the `Car` class might contain an attribute `manufacturingDate` while the corresponding DTO attribute is of type String. In order to map this attribute, you could implement a mapper class like this: - -.Manually implemented mapper class -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class DateMapper { - - public String asString(Date date) { - return date != null ? new SimpleDateFormat( "yyyy-MM-dd" ) - .format( date ) : null; - } - - public Date asDate(String date) { - try { - return date != null ? new SimpleDateFormat( "yyyy-MM-dd" ) - .parse( date ) : null; - } - catch ( ParseException e ) { - throw new RuntimeException( e ); - } - } -} ----- -==== - -In the `@Mapper` annotation at the `CarMapper` interface reference the `DateMapper` class like this: - -.Referencing another mapper class -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(uses=DateMapper.class) -public class CarMapper { - - CarDto carToCarDto(Car car); -} ----- -==== - -When generating code for the implementation of the `carToCarDto()` method, MapStruct will look for a method which maps a `Date` object into a String, find it on the `DateMapper` class and generate an invocation of `asString()` for mapping the `manufacturingDate` attribute. - -Generated mappers retrieve referenced mappers using the component model configured for them. If e.g. CDI was used as component model for `CarMapper`, `DateMapper` would have to be a CDI bean as well. When using the default component model, any hand-written mapper classes to be referenced by MapStruct generated mappers must declare a public no-args constructor in order to be instantiable. - -[[passing-target-type]] -=== Passing the mapping target type to custom mappers - -When having a custom mapper hooked into the generated mapper with `@Mapper#uses()`, an additional parameter of type `Class` (or a super-type of it) can be defined in the custom mapping method in order to perform general mapping tasks for specific target object types. That attribute must be annotated with `@TargetType` for MapStruct to generate calls that pass the `Class` instance representing the corresponding property type of the target bean. - -For instance, the `CarDto` could have a property `owner` of type `Reference` that contains the primary key of a `Person` entity. You could now create a generic custom mapper that resolves any `Reference` objects to their corresponding managed JPA entity instances. - -.Mapping method expecting mapping target type as parameter -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@ApplicationScoped // CDI component model -public class ReferenceMapper { - - @PersistenceContext - private EntityManager entityManager; - - public T resolve(Reference reference, @TargetType Class entityClass) { - return reference != null ? entityManager.find( entityClass, reference.getPk() ) : null; - } - - public Reference toReference(BaseEntity entity) { - return entity != null ? new Reference( entity.getPk() ) : null; - } -} - -@Mapper(componentModel = "cdi", uses = ReferenceMapper.class ) -public interface CarMapper { - - Car carDtoToCar(CarDto carDto); -} ----- -==== - -MapStruct will then generate something like this: - -.Generated code -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -@ApplicationScoped -public class CarMapperImpl implements CarMapper { - - @Inject - private ReferenceMapper referenceMapper; - - @Override - public Car carDtoToCar(CarDto carDto) { - if ( carDto == null ) { - return null; - } - - Car car = new Car(); - - car.setOwner( referenceMapper.resolve( carDto.getOwner(), Owner.class ) ); - // ... - - return car; - } -} ----- -==== - -[[passing-context]] -=== Passing context or state objects to custom methods - -Additional _context_ or _state_ information can be passed through generated mapping methods to custom methods with `@Context` parameters. Such parameters are passed to other mapping methods, `@ObjectFactory` methods (see <>) or `@BeforeMapping` / `@AfterMapping` methods (see <>) when applicable and can thus be used in custom code. - -`@Context` parameters are searched for `@ObjectFactory` methods, which are called on the provided context parameter value if applicable. - -`@Context` parameters are also searched for `@BeforeMapping` / `@AfterMapping` methods, which are called on the provided context parameter value if applicable. - -*Note:* no `null` checks are performed before calling before/after mapping methods on context parameters. The caller needs to make sure that `null` is not passed in that case. - -For generated code to call a method that is declared with `@Context` parameters, the declaration of the mapping method being generated needs to contain at least those (or assignable) `@Context` parameters as well. The generated code will not create new instances of missing `@Context` parameters nor will it pass a literal `null` instead. - -.Using `@Context` parameters for passing data down to hand-written property mapping methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public abstract CarDto toCar(Car car, @Context Locale translationLocale); - -protected OwnerManualDto translateOwnerManual(OwnerManual ownerManual, @Context Locale locale) { - // manually implemented logic to translate the OwnerManual with the given Locale -} ----- -==== - -MapStruct will then generate something like this: - -.Generated code -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -public CarDto toCar(Car car, Locale translationLocale) { - if ( car == null ) { - return null; - } - - CarDto carDto = new CarDto(); - - carDto.setOwnerManual( translateOwnerManual( car.getOwnerManual(), translationLocale ); - // more generated mapping code - - return carDto; -} ----- -==== - - -[[mapping-method-resolution]] -=== Mapping method resolution - -When mapping a property from one type to another, MapStruct looks for the most specific method which maps the source type into the target type. The method may either be declared on the same mapper interface or on another mapper which is registered via `@Mapper#uses()`. The same applies for factory methods (see <>). - -The algorithm for finding a mapping or factory method resembles Java's method resolution algorithm as much as possible. In particular, methods with a more specific source type will take precedence (e.g. if there are two methods, one which maps the searched source type, and another one which maps a super-type of the same). In case more than one most-specific method is found, an error will be raised. - -[TIP] -==== -When working with JAXB, e.g. when converting a `String` to a corresponding `JAXBElement`, MapStruct will take the `scope` and `name` attributes of `@XmlElementDecl` annotations into account when looking for a mapping method. This makes sure that the created `JAXBElement` instances will have the right QNAME value. You can find a test which maps JAXB objects https://github.com/mapstruct/mapstruct/blob/{mapstructVersion}/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java[here]. -==== - -[[selection-based-on-qualifiers]] -=== Mapping method selection based on qualifiers - -In many occasions one requires mapping methods with the same method signature (apart from the name) that have different behavior. -MapStruct has a handy mechanism to deal with such situations: `@Qualifier` (`org.mapstruct.Qualifier`). -A ‘qualifier’ is a custom annotation that the user can write, ‘stick onto’ a mapping method which is included as used mapper -and can be referred to in a bean property mapping, iterable mapping or map mapping. -Multiple qualifiers can be ‘stuck onto’ a method and mapping. - -So, let's say there is a hand-written method to map titles with a `String` return type and `String` argument amongst many other referenced mappers with the same `String` return type - `String` argument signature: - -.Several mapping methods with identical source and target types -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class Titles { - - public String translateTitleEG(String title) { - // some mapping logic - } - - public String translateTitleGE(String title) { - // some mapping logic - } -} ----- -==== - -And a mapper using this handwritten mapper, in which source and target have a property 'title' that should be mapped: - -.Mapper causing an ambiguous mapping method error -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper( uses = Titles.class ) -public interface MovieMapper { - - GermanRelease toGerman( OriginalRelease movies ); - -} ----- -==== - -Without the use of qualifiers, this would result in an ambiguous mapping method error, because 2 qualifying methods are found (`translateTitleEG`, `translateTitleGE`) and MapStruct would not have a hint which one to choose. - -Enter the qualifier approach: - -.Declaring a qualifier type -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -import org.mapstruct.Qualifier; - -@Qualifier -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.CLASS) -public @interface TitleTranslator { -} ----- -==== - -And, some qualifiers to indicate which translator to use to map from source language to target language: - -.Declaring qualifier types for mapping methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -import org.mapstruct.Qualifier; - -@Qualifier -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.CLASS) -public @interface EnglishToGerman { -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -import org.mapstruct.Qualifier; - -@Qualifier -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.CLASS) -public @interface GermanToEnglish { -} ----- -==== - -Please take note of the target `TitleTranslator` on type level, `EnglishToGerman`, `GermanToEnglish` on method level! - -Then, using the qualifiers, the mapping could look like this: - -.Mapper using qualifiers -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper( uses = Titles.class ) -public interface MovieMapper { - - @Mapping( target = "title", qualifiedBy = { TitleTranslator.class, EnglishToGerman.class } ) - GermanRelease toGerman( OriginalRelease movies ); - -} ----- -==== - -.Custom mapper qualifying the methods it provides -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@TitleTranslator -public class Titles { - - @EnglishToGerman - public String translateTitleEG(String title) { - // some mapping logic - } - - @GermanToEnglish - public String translateTitleGE(String title) { - // some mapping logic - } -} ----- -==== - -[WARNING] -==== -Please make sure the used retention policy equals retention policy `CLASS` (`@Retention(RetentionPolicy.CLASS)`). -==== - -[WARNING] -==== -A class / method annotated with a qualifier will not qualify anymore for mappings that do not have the `qualifiedBy` element. -==== - -[TIP] -==== -The same mechanism is also present on bean mappings: `@BeanMapping#qualifiedBy`: it selects the factory method marked with the indicated qualifier. -==== - -In many occasions, declaring a new annotation to aid the selection process can be too much for what you try to achieve. For those situations, MapStruct has the `@Named` annotation. This annotation is a pre-defined qualifier (annotated with `@Qualifier` itself) and can be used to name a Mapper or, more directly a mapping method by means of its value. The same example above would look like: - -.Custom mapper, annotating the methods to qualify by means of `@Named` -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Named("TitleTranslator") -public class Titles { - - @Named("EnglishToGerman") - public String translateTitleEG(String title) { - // some mapping logic - } - - @Named("GermanToEnglish") - public String translateTitleGE(String title) { - // some mapping logic - } -} ----- -==== - -.Mapper using named -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper( uses = Titles.class ) -public interface MovieMapper { - - @Mapping( target = "title", qualifiedByName = { "TitleTranslator", "EnglishToGerman" } ) - GermanRelease toGerman( OriginalRelease movies ); - -} ----- -==== - -[WARNING] -==== -Although the used mechanism is the same, the user has to be a bit more careful. Refactoring the name of a defined qualifier in an IDE will neatly refactor all other occurrences as well. This is obviously not the case for changing a name. -==== - - -[[mapping-collections]] -== Mapping collections - -The mapping of collection types (`List`, `Set` etc.) is done in the same way as mapping bean types, i.e. by defining mapping methods with the required source and target types in a mapper interface. MapStruct supports a wide range of iterable types from the http://docs.oracle.com/javase/tutorial/collections/intro/index.html[Java Collection Framework]. - -The generated code will contain a loop which iterates over the source collection, converts each element and puts it into the target collection. If a mapping method for the collection element types is found in the given mapper or the mapper it uses, this method is invoked to perform the element conversion. Alternatively, if an implicit conversion for the source and target element types exists, this conversion routine will be invoked. The following shows an example: - -.Mapper with collection mapping methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - Set integerSetToStringSet(Set integers); - - List carsToCarDtos(List cars); - - CarDto carToCarDto(Car car); -} ----- -==== - -The generated implementation of the `integerSetToStringSet` performs the conversion from `Integer` to `String` for each element, while the generated `carsToCarDtos()` method invokes the `carToCarDto()` method for each contained element as shown in the following: - -.Generated collection mapping methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -@Override -public Set integerSetToStringSet(Set integers) { - if ( integers == null ) { - return null; - } - - Set set = new HashSet(); - - for ( Integer integer : integers ) { - set.add( String.valueOf( integer ) ); - } - - return set; -} - -@Override -public List carsToCarDtos(List cars) { - if ( cars == null ) { - return null; - } - - List list = new ArrayList(); - - for ( Car car : cars ) { - list.add( carToCarDto( car ) ); - } - - return list; -} ----- -==== - -Note that MapStruct will look for a collection mapping method with matching parameter and return type, when mapping a collection-typed attribute of a bean, e.g. from `Car#passengers` (of type `List`) to `CarDto#passengers` (of type `List`). - -.Usage of collection mapping method to map a bean property -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -carDto.setPassengers( personsToPersonDtos( car.getPassengers() ) ); -... ----- -==== - -Some frameworks and libraries only expose JavaBeans getters but no setters for collection-typed properties. Types generated from an XML schema using JAXB adhere to this pattern by default. In this case the generated code for mapping such a property invokes its getter and adds all the mapped elements: - -.Usage of an adding method for collection mapping -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -carDto.getPassengers().addAll( personsToPersonDtos( car.getPassengers() ) ); -... ----- -==== - -[WARNING] -==== -It is not allowed to declare mapping methods with an iterable source and a non-iterable target or the other way around. An error will be raised when detecting this situation. -==== - -[[mapping-maps]] -=== Mapping maps - -Also map-based mapping methods are supported. The following shows an example: - -.Map mapping method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public interface SourceTargetMapper { - - @MapMapping(valueDateFormat = "dd.MM.yyyy") - Map longDateMapToStringStringMap(Map source); -} ----- -==== - -Similar to iterable mappings, the generated code will iterate through the source map, convert each value and key (either by means of an implicit conversion or by invoking another mapping method) and put them into the target map: - -.Generated implementation of map mapping method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -@Override -public Map stringStringMapToLongDateMap(Map source) { - if ( source == null ) { - return null; - } - - Map map = new HashMap(); - - for ( Map.Entry entry : source.entrySet() ) { - - Long key = Long.parseLong( entry.getKey() ); - Date value; - try { - value = new SimpleDateFormat( "dd.MM.yyyy" ).parse( entry.getValue() ); - } - catch( ParseException e ) { - throw new RuntimeException( e ); - } - - map.put( key, value ); - } - - return map; -} ----- -==== - -[[collection-mapping-strategies]] -=== Collection mapping strategies - -MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED`, `ADDER_PREFERRED` and `TARGET_IMMUTABLE`. - -In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are applied to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: - -.Collection mapping strategy options -|=== -|Option|Only target set-s Available|Only target add- Available|Both set-s / add- Available|No set-s / add- Available|Existing Target(`@TargetType`) - -|`ACCESSOR_ONLY` -|set-s -|get-s -|set-s -|get-s -|get-s - -|`SETTER_PREFERRED` -|set-s -|add- -|set-s -|get-s -|get-s - -|`ADDER_PREFERRED` -|set-s -|add- -|add- -|get-s -|get-s - -|`TARGET_IMMUTABLE` -|set-s -|exception -|set-s -|exception -|set-s -|=== - -Some background: An `adder` method is typically used in case of http://www.eclipse.org/webtools/dali/[generated (JPA) entities], to add a single element (entity) to an underlying collection. Invoking the adder establishes a parent-child relation between parent - the bean (entity) on which the adder is invoked - and its child(ren), the elements (entities) in the collection. To find the appropriate `adder`, MapStruct will try to make a match between the generic parameter type of the underlying collection and the single argument of a candidate `adder`. When there are more candidates, the plural `setter` / `getter` name is converted to singular and will be used in addition to make a match. - -The option `DEFAULT` should not be used explicitly. It is used to distinguish between an explicit user desire to override the default in a `@MapperConfig` from the implicit Mapstruct choice in a `@Mapper`. The option `DEFAULT` is synonymous to `ACCESSOR_ONLY`. - -[TIP] -==== -When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with intialized collections instead of Mapstruct creating the target entity by its constructor. -==== - -[[implementation-types-for-collection-mappings]] -=== Implementation types used for collection mappings - -When an iterable or map mapping method declares an interface type as return type, one of its implementation types will be instantiated in the generated code. The following table shows the supported interface types and their corresponding implementation types as instantiated in the generated code: - -.Collection mapping implementation types -|=== -|Interface type|Implementation type - -|`Iterable`|`ArrayList` - -|`Collection`|`ArrayList` - -|`List`|`ArrayList` - -|`Set`|`HashSet` - -|`SortedSet`|`TreeSet` - -|`NavigableSet`|`TreeSet` - -|`Map`|`HashMap` - -|`SortedMap`|`TreeMap` - -|`NavigableMap`|`TreeMap` - -|`ConcurrentMap`|`ConcurrentHashMap` -|`ConcurrentNavigableMap`|`ConcurrentSkipListMap` -|=== - -include::mapping-streams.asciidoc[] - -[[mapping-enum-types]] -== Mapping Values - -=== Mapping enum types - -MapStruct supports the generation of methods which map one Java enum type into another. - -By default, each constant from the source enum is mapped to a constant with the same name in the target enum type. If required, a constant from the source enum may be mapped to a constant with another name with help of the `@ValueMapping` annotation. Several constants from the source enum can be mapped to the same constant in the target type. - -The following shows an example: - -.Enum mapping method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface OrderMapper { - - OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); - - @ValueMappings({ - @ValueMapping(source = "EXTRA", target = "SPECIAL"), - @ValueMapping(source = "STANDARD", target = "DEFAULT"), - @ValueMapping(source = "NORMAL", target = "DEFAULT") - }) - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} ----- -==== - -.Enum mapping method result -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -public class OrderMapperImpl implements OrderMapper { - - @Override - public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { - if ( orderType == null ) { - return null; - } - - ExternalOrderType externalOrderType_; - - switch ( orderType ) { - case EXTRA: externalOrderType_ = ExternalOrderType.SPECIAL; - break; - case STANDARD: externalOrderType_ = ExternalOrderType.DEFAULT; - break; - case NORMAL: externalOrderType_ = ExternalOrderType.DEFAULT; - break; - case RETAIL: externalOrderType_ = ExternalOrderType.RETAIL; - break; - case B2B: externalOrderType_ = ExternalOrderType.B2B; - break; - default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); - } - - return externalOrderType_; - } -} ----- -==== -By default an error will be raised by MapStruct in case a constant of the source enum type does not have a corresponding constant with the same name in the target type and also is not mapped to another constant via `@ValueMapping`. This ensures that all constants are mapped in a safe and predictable manner. The generated -mapping method will throw an IllegalStateException if for some reason an unrecognized source value occurs. - -MapStruct also has a mechanism for mapping any remaining (unspecified) mappings to a default. This can be used only once in a set of value mappings. It comes in two flavors: `` and ``. - -In case of source `` MapStruct will continue to map a source enum constant to a target enum constant with the same name. The remainder of the source enum constants will be mapped to the target specified in the `@ValueMapping` with `` source. - -MapStruct will *not* attempt such name based mapping for `` and directly apply the target specified in the `@ValueMapping` with `` source to the remainder. - -MapStruct is able to handle `null` sources and `null` targets by means of the `` keyword. - -[TIP] -==== -Constants for ``, `` and `` are available in the `MappingConstants` class. -==== - -Finally `@InheritInverseConfiguration` and `@InheritConfiguration` can be used in combination with `@ValueMappings`. - -.Enum mapping method, and -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface SpecialOrderMapper { - - SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); - - @ValueMappings({ - @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ), - @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ), - @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" ) - }) - ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); -} ----- -==== - -.Enum mapping method result, and -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -public class SpecialOrderMapperImpl implements SpecialOrderMapper { - - @Override - public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { - if ( orderType == null ) { - return ExternalOrderType.DEFAULT; - } - - ExternalOrderType externalOrderType_; - - switch ( orderType ) { - case STANDARD: externalOrderType_ = null; - break; - case RETAIL: externalOrderType_ = ExternalOrderType.RETAIL; - break; - case B2B: externalOrderType_ = ExternalOrderType.B2B; - break; - default: externalOrderType_ = ExternalOrderType.SPECIAL; - } - - return externalOrderType_; - } -} ----- -==== - -*Note:* MapStruct would have refrained from mapping the `RETAIL` and `B2B` when `` was used instead of ``. - - -[WARNING] -==== -The mapping of enum to enum via the `@Mapping` annotation is *DEPRECATED*. It will be removed from future versions of MapStruct. Please adapt existing enum mapping methods to make use of `@ValueMapping` instead. -==== - - -[[object-factories]] -== Object factories - -By default, the generated code for mapping one bean type into another or updating a bean will call the default constructor to instantiate the target type. - -Alternatively you can plug in custom object factories which will be invoked to obtain instances of the target type. One use case for this is JAXB which creates `ObjectFactory` classes for obtaining new instances of schema types. - -To make use of custom factories register them via `@Mapper#uses()` as described in <>, or implement them directly in your mapper. When creating the target object of a bean mapping, MapStruct will look for a parameterless method, a method annotated with `@ObjectFactory`, or a method with only one `@TargetType` parameter that returns the required target type and invoke this method instead of calling the default constructor: - -.Custom object factories -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class DtoFactory { - - public CarDto createCarDto() { - return // ... custom factory logic - } -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class EntityFactory { - - public T createEntity(@TargetType Class entityClass) { - return // ... custom factory logic - } -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(uses= { DtoFactory.class, EntityFactory.class } ) -public interface CarMapper { - - CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); - - CarDto carToCarDto(Car car); - - Car carDtoToCar(CarDto carDto); -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -public class CarMapperImpl implements CarMapper { - - private final DtoFactory dtoFactory = new DtoFactory(); - - private final EntityFactory entityFactory = new EntityFactory(); - - @Override - public CarDto carToCarDto(Car car) { - if ( car == null ) { - return null; - } - - CarDto carDto = dtoFactory.createCarDto(); - - //map properties... - - return carDto; - } - - @Override - public Car carDtoToCar(CarDto carDto) { - if ( carDto == null ) { - return null; - } - - Car car = entityFactory.createEntity( Car.class ); - - //map properties... - - return car; - } -} ----- -==== - -.Custom object factories with update methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(uses = { DtoFactory.class, EntityFactory.class, CarMapper.class } ) -public interface OwnerMapper { - - OwnerMapper INSTANCE = Mappers.getMapper( OwnerMapper.class ); - - void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto); - - void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner); -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -//GENERATED CODE -public class OwnerMapperImpl implements OwnerMapper { - - private final DtoFactory dtoFactory = new DtoFactory(); - - private final EntityFactory entityFactory = new EntityFactory(); - - private final OwnerMapper ownerMapper = Mappers.getMapper( OwnerMapper.class ); - - @Override - public void updateOwnerDto(Owner owner, @MappingTarget OwnerDto ownerDto) { - if ( owner == null ) { - return; - } - - if ( owner.getCar() != null ) { - if ( ownerDto.getCar() == null ) { - ownerDto.setCar( dtoFactory.createCarDto() ); - } - // update car within ownerDto - } - else { - ownerDto.setCar( null ); - } - - // updating other properties - } - - @Override - public void updateOwner(OwnerDto ownerDto, @MappingTarget Owner owner) { - if ( ownerDto == null ) { - return; - } - - if ( ownerDto.getCar() != null ) { - if ( owner.getCar() == null ) { - owner.setCar( entityFactory.createEntity( Car.class ) ); - } - // update car within owner - } - else { - owner.setCar( null ); - } - - // updating other properties - } -} ----- -==== - -In addition, annotating a factory method with `@ObjectFactory` lets you gain access to the mapping sources. -Source objects can be added as parameters in the same way as for mapping method. The `@ObjectFactory` -annotation is necessary to let MapStruct know that the given method is only a factory method. - -.Custom object factories with `@ObjectFactory` - -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class DtoFactory { - - @ObjectFactory - public CarDto createCarDto(Car car) { - return // ... custom factory logic - } -} ----- -==== - - -== Advanced mapping options -This chapter describes several advanced options which allow to fine-tune the behavior of the generated mapping code as needed. - -[[default-values-and-constants]] -=== Default values and constants - -Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values. When the target type is a primitive or a boxed type, the String value is taken literal. Bit / octal / decimal / hex patterns are allowed in such case as long as they are a valid literal. -In all other cases, constant or default values are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. - -A mapping with a constant must not include a reference to a source property. The following example shows some mappings using default values and constants: - -.Mapping method with default values and constants -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(uses = StringListMapper.class) -public interface SourceTargetMapper { - - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - - @Mapping(target = "stringProperty", source = "stringProp", defaultValue = "undefined") - @Mapping(target = "longProperty", source = "longProp", defaultValue = "-1") - @Mapping(target = "stringConstant", constant = "Constant Value") - @Mapping(target = "integerConstant", constant = "14") - @Mapping(target = "longWrapperConstant", constant = "3001") - @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014") - @Mapping(target = "stringListConstants", constant = "jack-jill-tom") - Target sourceToTarget(Source s); -} ----- -==== - -If `s.getStringProp() == null`, then the target property `stringProperty` will be set to `"undefined"` instead of applying the value from `s.getStringProp()`. If `s.getLongProperty() == null`, then the target property `longProperty` will be set to `-1`. -The String `"Constant Value"` is set as is to the target property `stringConstant`. The value `"3001"` is type-converted to the `Long` (wrapper) class of target property `longWrapperConstant`. Date properties also require a date format. The constant `"jack-jill-tom"` demonstrates how the hand-written class `StringListMapper` is invoked to map the dash-separated list into a `List`. - -[[expressions]] -=== Expressions - -By means of Expressions it will be possible to include constructs from a number of languages. - -Currently only Java is supported as a language. This feature is e.g. useful to invoke constructors. The entire source object is available for usage in the expression. Care should be taken to insert only valid Java code: MapStruct will not validate the expression at generation-time, but errors will show up in the generated classes during compilation. - -The example below demonstrates how two source properties can be mapped to one target: - -.Mapping method using an expression -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface SourceTargetMapper { - - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - - @Mapping(target = "timeAndFormat", - expression = "java( new org.sample.TimeAndFormat( s.getTime(), s.getFormat() ) )") - Target sourceToTarget(Source s); -} ----- -==== - -The example demonstrates how the source properties `time` and `format` are composed into one target property `TimeAndFormat`. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `TimeAndFormat` class (unless it's used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining `imports` on the `@Mapper` annotation. - -.Declaring an import -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -imports org.sample.TimeAndFormat; - -@Mapper( imports = TimeAndFormat.class ) -public interface SourceTargetMapper { - - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - - @Mapping(target = "timeAndFormat", - expression = "java( new TimeAndFormat( s.getTime(), s.getFormat() ) )") - Target sourceToTarget(Source s); -} ----- -==== - -[[default-expressions]] -=== Default Expressions - -Default expressions are a combination of default values and expressions. They will only be used when the source attribute is `null`. - -The same warnings and restrictions apply to default expressions that apply to expressions. Only Java is supported, and MapStruct will not validate the expression at generation-time. - -The example below demonstrates how two source properties can be mapped to one target: - -.Mapping method using a default expression -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -imports java.util.UUID; - -@Mapper( imports = UUID.class ) -public interface SourceTargetMapper { - - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - - @Mapping(target="id", source="sourceId", defaultExpression = "java( UUID.randomUUID().toString() )") - Target sourceToTarget(Source s); -} ----- -==== - -The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation ((see <>). - -[[determining-result-type]] -=== Determining the result type - -When result types have an inheritance relation, selecting either mapping method (`@Mapping`) or a factory method (`@BeanMapping`) can become ambiguous. Suppose an Apple and a Banana, which are both specializations of Fruit. - -.Specifying the result type of a bean mapping method -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper( uses = FruitFactory.class ) -public interface FruitMapper { - - @BeanMapping( resultType = Apple.class ) - Fruit map( FruitDto source ); - -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class FruitFactory { - - public Apple createApple() { - return new Apple( "Apple" ); - } - - public Banana createBanana() { - return new Banana( "Banana" ); - } -} ----- -==== - -So, which `Fruit` must be factorized in the mapping method `Fruit map(FruitDto source);`? A `Banana` or an `Apple`? Here's were the `@BeanMapping#resultType` comes in handy. It controls the factory method to select, or in absence of a factory method, the return type to create. - -[TIP] -==== -The same mechanism is present on mapping: `@Mapping#resultType` and works like you expect it would: it selects the mapping method with the desired result type when present. -==== - -[TIP] -==== -The mechanism is also present on iterable mapping and map mapping. `@IterableMapping#elementTargetType` is used to select the mapping method with the desired element in the resulting `Iterable`. For the `@MapMapping` a similar purpose is served by means of `#MapMapping#keyTargetType` and `MapMapping#valueTargetType`. -==== - -[[mapping-result-for-null-arguments]] -=== Controlling mapping result for 'null' arguments - -MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. By default `null` will be returned. - -However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MappingConfig`, the mapping result can be altered to return empty *default* values. This means for: - -* *Bean mappings*: an 'empty' target bean will be returned, with the exception of constants and expressions, they will be populated when present. -* *Iterables / Arrays*: an empty iterable will be returned. -* *Maps*: an empty map will be returned. - -The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`. - - -[[mapping-result-for-null-properties]] -=== Controlling mapping result for 'null' properties in bean mappings (update mapping methods only). - -MapStruct offers control over the property to set in an `@MappingTarget` annotated target bean when the source property equals `null` or the presence check method results in 'absent'. - -By default the target property will be set to null. - -However: - -1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. -For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. -For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. - -2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. - -The strategy works in a hierarchical fashion. Setting `Mapping#nullValuePropertyMappingStrategy` on mapping level will override `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. - -[NOTE] -==== -Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property -null check, regardless the value of the `NullValuePropertyMappingStrategy` to avoid addition of `null` to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. -==== - -[TIP] -==== -`NullValuePropertyMappingStrategy` also applies when the presense checker returns `not present`. -==== - -[[checking-source-property-for-null-arguments]] -=== Controlling checking result for 'null' properties in bean mapping - -MapStruct offers control over when to generate a `null` check. By default (`nullValueCheckStrategy = NullValueCheckStrategy.ON_IMPLICIT_CONVERSION`) a `null` check will be generated for: - -* direct setting of source value to target value when target is primitive and source is not. -* applying type conversion and then: -.. calling the setter on the target. -.. calling another type conversion and subsequently calling the setter on the target. -.. calling a mapping method and subsequently calling the setter on the target. - -First calling a mapping method on the source property is not protected by a null check. Therefor generated mapping methods will do a null check prior to carrying out mapping on a source property. Handwritten mapping methods must take care of null value checking. They have the possibility to add 'meaning' to `null`. For instance: mapping `null` to a default value. - -The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. - -The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. - -[[source-presence-check]] -=== Source presence checking -Some frameworks generate bean properties that have a source presence checker. Often this is in the form of a method `hasXYZ`, `XYZ` being a property on the source bean in a bean mapping method. MapStruct will call this `hasXYZ` instead of performing a `null` check when it finds such `hasXYZ` method. - -[TIP] -==== -The source presence checker name can be changed in the MapStruct service provider interface (SPI). It can also be deactivated in this way. -==== - -[NOTE] -==== -Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property -null check, regardless the value of the `NullValueheckStrategy` to avoid addition of `null` to the target collection or map. -==== -[[exceptions]] -=== Exceptions - -Calling applications may require handling of exceptions when calling a mapping method. These exceptions could be thrown by hand-written logic and by the generated built-in mapping methods or type-conversions of MapStruct. When the calling application requires handling of exceptions, a throws clause can be defined in the mapping method: - -.Mapper using custom method declaring checked exception -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(uses = HandWritten.class) -public interface CarMapper { - - CarDto carToCarDto(Car car) throws GearException; -} ----- -==== - -The hand written logic might look like this: - -.Custom mapping method declaring checked exception -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class HandWritten { - - private static final String[] GEAR = {"ONE", "TWO", "THREE", "OVERDRIVE", "REVERSE"}; - - public String toGear(Integer gear) throws GearException, FatalException { - if ( gear == null ) { - throw new FatalException("null is not a valid gear"); - } - - if ( gear < 0 && gear > GEAR.length ) { - throw new GearException("invalid gear"); - } - return GEAR[gear]; - } -} ----- -==== - -MapStruct now, wraps the `FatalException` in a `try-catch` block and rethrows an unchecked `RuntimeException`. MapStruct delegates handling of the `GearException` to the application logic because it is defined as throws clause in the `carToCarDto` method: - -.try-catch block in generated implementation -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -// GENERATED CODE -@Override -public CarDto carToCarDto(Car car) throws GearException { - if ( car == null ) { - return null; - } - - CarDto carDto = new CarDto(); - try { - carDto.setGear( handWritten.toGear( car.getGear() ) ); - } - catch ( FatalException e ) { - throw new RuntimeException( e ); - } - - return carDto; -} ----- -==== - -Some **notes** on null checks. MapStruct does provide null checking only when required: when applying type-conversions or constructing a new type by invoking its constructor. This means that the user is responsible in hand-written code for returning valid non-null objects. Also null objects can be handed to hand-written code, since MapStruct does not want to make assumptions on the meaning assigned by the user to a null object. Hand-written code has to deal with this. - -== Reusing mapping configurations - -This chapter discusses different means of reusing mapping configurations for several mapping methods: "inheritance" of configuration from other methods and sharing central configuration between multiple mapper types. - -[[mapping-configuration-inheritance]] -=== Mapping configuration inheritance - -Method-level configuration annotations such as `@Mapping`, `@BeanMapping`, `@IterableMapping`, etc., can be *inherited* from one mapping method to a *similar* method using the annotation `@InheritConfiguration`: - -.Update method inheriting its configuration -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(target = "numberOfSeats", source = "seatCount") - Car carDtoToCar(CarDto car); - - @InheritConfiguration - void carDtoIntoCar(CarDto carDto, @MappingTarget Car car); -} ----- -==== - -The example above declares a mapping method `carDtoToCar()` with a configuration to define how the property `numberOfSeats` in the type `Car` shall be mapped. The update method that performs the mapping on an existing instance of `Car` needs the same configuration to successfully map all properties. Declaring `@InheritConfiguration` on the method lets MapStruct search for inheritance candidates to apply the annotations of the method that is inherited from. - -One method *A* can inherit the configuration from another method *B* if all types of *A* (source types and result type) are assignable to the corresponding types of *B*. - -Methods that are considered for inheritance need to be defined in the current mapper, a super class/interface, or in the shared configuration interface (as described in <>). - -In case more than one method is applicable as source for the inheritance, the method name must be specified within the annotation: `@InheritConfiguration( name = "carDtoToCar" )`. - -A method can use `@InheritConfiguration` and override or amend the configuration by additionally applying `@Mapping`, `@BeanMapping`, etc. - -[NOTE] -==== -`@InheritConfiguration` cannot refer to methods in a used mapper. -==== - -[[inverse-mappings]] -=== Inverse mappings - -In case of bi-directional mappings, e.g. from entity to DTO and from DTO to entity, the mapping rules for the forward method and the reverse method are often similar and can simply be inversed by switching `source` and `target`. - -Use the annotation `@InheritInverseConfiguration` to indicate that a method shall inherit the inverse configuration of the corresponding reverse method. - -.Inverse mapping method inheriting its configuration and ignoring some of them -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface CarMapper { - - @Mapping(source = "numberOfSeats", target = "seatCount") - CarDto carToDto(Car car); - - @InheritInverseConfiguration - @Mapping(target = "numberOfSeats", ignore = true) - Car carDtoToCar(CarDto carDto); -} ----- -==== - -Here the `carDtoToCar()` method is the reverse mapping method for `carToDto()`. Note that any attribute mappings from `carToDto()` will be applied to the corresponding reverse mapping method as well. They are automatically reversed and copied to the method with the `@InheritInverseConfiguration` annotation. - -Specific mappings from the inversed method can (optionally) be overridden by `ignore`, `expression` or `constant` in the mapping, e.g. like this: `@Mapping(target = "numberOfSeats", ignore=true)`. - -A method *A* is considered a *reverse* method of a method *B*, if the result type of *A* is the *same* as the single source type of *B* and if the single source type of *A* is the *same* as the result type of *B*. - -Methods that are considered for inverse inheritance need to be defined in the current mapper, a super class/interface. - -If multiple methods qualify, the method from which to inherit the configuration needs to be specified using the `name` property like this: `@InheritInverseConfiguration(name = "carToDto")`. - -`@InheritConfiguration` takes, in case of conflict precedence over `@InheritInverseConfiguration`. - -Configurations are inherited transitively. So if method `C` defines a mapping `@Mapping( target = "x", ignore = true)`, `B` defines a mapping `@Mapping( target = "y", ignore = true)`, then if `A` inherits from `B` inherits from `C`, `A` will inherit mappings for both property `x` and `y`. - -Expressions and constants are excluded (silently ignored) in `@InheritInverseConfiguration`. - -Reverse mapping of nested source properties is experimental as of the 1.1.0.Beta2 release. Reverse mapping will take place automatically when the source property name and target property name are identical. Otherwise, `@Mapping` should specify both the target name and source name. In all cases, a suitable mapping method needs to be in place for the reverse mapping. - -[NOTE] -==== -`@InheritConfiguration` or `@InheritInverseConfiguration` cannot refer to methods in a used mapper. -==== - -[[shared-configurations]] -=== Shared configurations - -MapStruct offers the possibility to define a shared configuration by pointing to a central interface annotated with `@MapperConfig`. For a mapper to use the shared configuration, the configuration interface needs to be defined in the `@Mapper#config` property. - -The `@MapperConfig` annotation has the same attributes as the `@Mapper` annotation. Any attributes not given via `@Mapper` will be inherited from the shared configuration. Attributes specified in `@Mapper` take precedence over the attributes specified via the referenced configuration class. List properties such as `uses` are simply combined: - -.Mapper configuration class and mapper using it -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@MapperConfig( - uses = CustomMapperViaMapperConfig.class, - unmappedTargetPolicy = ReportingPolicy.ERROR -) -public interface CentralConfig { -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(config = CentralConfig.class, uses = { CustomMapperViaMapper.class } ) -// Effective configuration: -// @Mapper( -// uses = { CustomMapperViaMapper.class, CustomMapperViaMapperConfig.class }, -// unmappedTargetPolicy = ReportingPolicy.ERROR -// ) -public interface SourceTargetMapper { - ... -} - ----- -==== - -The interface holding the `@MapperConfig` annotation may also declare *prototypes* of mapping methods that can be used to inherit method-level mapping annotations from. Such prototype methods are not meant to be implemented or used as part of the mapper API. - -.Mapper configuration class with prototype methods -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@MapperConfig( - uses = CustomMapperViaMapperConfig.class, - unmappedTargetPolicy = ReportingPolicy.ERROR, - mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG -) -public interface CentralConfig { - - // Not intended to be generated, but to carry inheritable mapping annotations: - @Mapping(target = "primaryKey", source = "technicalKey") - BaseEntity anyDtoToEntity(BaseDto dto); -} ----- -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper(config = CentralConfig.class, uses = { CustomMapperViaMapper.class } ) -public interface SourceTargetMapper { - - @Mapping(target = "numberOfSeats", source = "seatCount") - // additionally inherited from CentralConfig, because Car extends BaseEntity and CarDto extends BaseDto: - // @Mapping(target = "primaryKey", source = "technicalKey") - Car toCar(CarDto car) -} ----- -==== - -The attributes `@Mapper#mappingInheritanceStrategy()` / `@MapperConfig#mappingInheritanceStrategy()` configure when the method-level mapping configuration annotations are inherited from prototype methods in the interface to methods in the mapper: - -* `EXPLICIT` (default): the configuration will only be inherited, if the target mapping method is annotated with `@InheritConfiguration` and the source and target types are assignable to the corresponding types of the prototype method, all as described in <>. -* `AUTO_INHERIT_FROM_CONFIG`: the configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritConfiguration(name = ...)` which will cause `AUTO_INHERIT_FROM_CONFIG` to be ignored. -* `AUTO_INHERIT_REVERSE_FROM_CONFIG`: the inverse configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritInverseConfiguration(name = ...)` which will cause ``AUTO_INHERIT_REVERSE_FROM_CONFIG` to be ignored. -* `AUTO_INHERIT_ALL_FROM_CONFIG`: both the configuration and the inverse configuration will be inherited automatically. The same rules apply as for `AUTO_INHERIT_FROM_CONFIG` or `AUTO_INHERIT_REVERSE_FROM_CONFIG`. - -== Customizing mappings - -Sometimes it's needed to apply custom logic before or after certain mapping methods. MapStruct provides two ways for doing so: decorators which allow for a type-safe customization of specific mapping methods and the before-mapping and after-mapping lifecycle methods which allow for a generic customization of mapping methods with given source or target types. - -[[customizing-mappers-using-decorators]] -=== Mapping customization with decorators - -In certain cases it may be required to customize a generated mapping method, e.g. to set an additional property in the target object which can't be set by a generated method implementation. MapStruct supports this requirement using decorators. - -[TIP] -When working with the component model `cdi`, use https://docs.jboss.org/cdi/spec/1.0/html/decorators.html[CDI decorators] with MapStruct mappers instead of the `@DecoratedWith` annotation described here. - -To apply a decorator to a mapper class, specify it using the `@DecoratedWith` annotation. - -.Applying a decorator -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -@DecoratedWith(PersonMapperDecorator.class) -public interface PersonMapper { - - PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); - - PersonDto personToPersonDto(Person person); - - AddressDto addressToAddressDto(Address address); -} ----- -==== - -The decorator must be a sub-type of the decorated mapper type. You can make it an abstract class which allows to only implement those methods of the mapper interface which you want to customize. For all non-implemented methods, a simple delegation to the original mapper will be generated using the default generation routine. - -The `PersonMapperDecorator` shown below customizes the `personToPersonDto()`. It sets an additional attribute which is not present in the source type of the mapping. The `addressToAddressDto()` method is not customized. - -.Implementing a decorator -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public abstract class PersonMapperDecorator implements PersonMapper { - - private final PersonMapper delegate; - - public PersonMapperDecorator(PersonMapper delegate) { - this.delegate = delegate; - } - - @Override - public PersonDto personToPersonDto(Person person) { - PersonDto dto = delegate.personToPersonDto( person ); - dto.setFullName( person.getFirstName() + " " + person.getLastName() ); - return dto; - } -} ----- -==== - -The example shows how you can optionally inject a delegate with the generated default implementation and use this delegate in your customized decorator methods. - -For a mapper with `componentModel = "default"`, define a constructor with a single parameter which accepts the type of the decorated mapper. - -When working with the component models `spring` or `jsr330`, this needs to be handled differently. - -[[decorators-with-spring]] -==== Decorators with the Spring component model - -When using `@DecoratedWith` on a mapper with component model `spring`, the generated implementation of the original mapper is annotated with the Spring annotation `@Qualifier("delegate")`. To autowire that bean in your decorator, add that qualifier annotation as well: - -.Spring-based decorator -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public abstract class PersonMapperDecorator implements PersonMapper { - - @Autowired - @Qualifier("delegate") - private PersonMapper delegate; - - @Override - public PersonDto personToPersonDto(Person person) { - PersonDto dto = delegate.personToPersonDto( person ); - dto.setName( person.getFirstName() + " " + person.getLastName() ); - - return dto; - } - } ----- -==== - -The generated class that extends the decorator is annotated with Spring's `@Primary` annotation. To autowire the decorated mapper in the application, nothing special needs to be done: - -.Using a decorated mapper -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Autowired -private PersonMapper personMapper; // injects the decorator, with the injected original mapper ----- -==== - -[[decorators-with-jsr-330]] -==== Decorators with the JSR 330 component model - -JSR 330 doesn't specify qualifiers and only allows to specifically name the beans. Hence, the generated implementation of the original mapper is annotated with `@Named("fully-qualified-name-of-generated-implementation")` (please note that when using a decorator, the class name of the mapper implementation ends with an underscore). To inject that bean in your decorator, add the same annotation to the delegate field (e.g. by copy/pasting it from the generated class): - -.JSR 330 based decorator -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public abstract class PersonMapperDecorator implements PersonMapper { - - @Inject - @Named("org.examples.PersonMapperImpl_") - private PersonMapper delegate; - - @Override - public PersonDto personToPersonDto(Person person) { - PersonDto dto = delegate.personToPersonDto( person ); - dto.setName( person.getFirstName() + " " + person.getLastName() ); - - return dto; - } -} ----- -==== - -Unlike with the other component models, the usage site must be aware if a mapper is decorated or not, as for decorated mappers, the parameterless `@Named` annotation must be added to select the decorator to be injected: - -.Using a decorated mapper with JSR 330 -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Inject -@Named -private PersonMapper personMapper; // injects the decorator, with the injected original mapper ----- -==== - -[WARNING] -==== -`@DecoratedWith` in combination with component model `jsr330` is considered experimental as of the 1.0.0.CR2 release. The way the original mapper is referenced in the decorator or the way the decorated mapper is injected in the application code might still change. -==== - -[[customizing-mappings-with-before-and-after]] -=== Mapping customization with before-mapping and after-mapping methods - -Decorators may not always fit the needs when it comes to customizing mappers. For example, if you need to perform the customization not only for a few selected methods, but for all methods that map specific super-types: in that case, you can use *callback methods* that are invoked before the mapping starts or after the mapping finished. - -Callback methods can be implemented in the abstract mapper itself, in a type reference in `Mapper#uses`, or in a type used as `@Context` parameter. - -.Mapper with @BeforeMapping and @AfterMapping hooks -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public abstract class VehicleMapper { - - @BeforeMapping - protected void flushEntity(AbstractVehicle vehicle) { - // I would call my entity manager's flush() method here to make sure my entity - // is populated with the right @Version before I let it map into the DTO - } - - @AfterMapping - protected void fillTank(AbstractVehicle vehicle, @MappingTarget AbstractVehicleDto result) { - result.fuelUp( new Fuel( vehicle.getTankCapacity(), vehicle.getFuelType() ) ); - } - - public abstract CarDto toCarDto(Car car); -} - -// Generates something like this: -public class VehicleMapperImpl extends VehicleMapper { - - public CarDto toCarDto(Car car) { - flushEntity( car ); - - if ( car == null ) { - return null; - } - - CarDto carDto = new CarDto(); - // attributes mapping ... - - fillTank( car, carDto ); - - return carDto; - } -} ----- -==== - -If the `@BeforeMapping` / `@AfterMapping` method has parameters, the method invocation is only generated if the return type of the method (if non-`void`) is assignable to the return type of the mapping method and all parameters can be *assigned* by the source or target parameters of the mapping method: - -* A parameter annotated with `@MappingTarget` is populated with the target instance of the mapping. -* A parameter annotated with `@TargetType` is populated with the target type of the mapping. -* Parameters annotated with `@Context` are populated with the context parameters of the mapping method. -* Any other parameter is populated with a source parameter of the mapping. - -For non-`void` methods, the return value of the method invocation is returned as the result of the mapping method if it is not `null`. - -As with mapping methods, it is possible to specify type parameters for before/after-mapping methods. - -.Mapper with @AfterMapping hook that returns a non-null value -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public abstract class VehicleMapper { - - @PersistenceContext - private EntityManager entityManager; - - @AfterMapping - protected T attachEntity(@MappingTarget T entity) { - return entityManager.merge(entity); - } - - public abstract CarDto toCarDto(Car car); -} - -// Generates something like this: -public class VehicleMapperImpl extends VehicleMapper { - - public CarDto toCarDto(Car car) { - if ( car == null ) { - return null; - } - - CarDto carDto = new CarDto(); - // attributes mapping ... - - CarDto target = attachEntity( carDto ); - if ( target != null ) { - return target; - } - - return carDto; - } -} ----- -==== - -All before/after-mapping methods that *can* be applied to a mapping method *will* be used. <> can be used to further control which methods may be chosen and which not. For that, the qualifier annotation needs to be applied to the before/after-method and referenced in `BeanMapping#qualifiedBy` or `IterableMapping#qualifiedBy`. - -The order of the method invocation is determined primarily by their variant: - -1. `@BeforeMapping` methods without an `@MappingTarget` parameter are called before any null-checks on source - parameters and constructing a new target bean. -2. `@BeforeMapping` methods with an `@MappingTarget` parameter are called after constructing a new target bean. -3. `@AfterMapping` methods are called at the end of the mapping method before the last `return` statement. - -Within those groups, the method invocations are ordered by their location of definition: - -1. Methods declared on `@Context` parameters, ordered by the parameter order. -2. Methods implemented in the mapper itself. -3. Methods from types referenced in `Mapper#uses()`, in the order of the type declaration in the annotation. -4. Methods declared in one type are used after methods declared in their super-type. - -*Important:* the order of methods declared within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. - -*Important:* when using a builder, the `@AfterMapping` annotated method must have the builder as `@MappingTarget` annotated parameter so that the method is able to modify the object going to be build. The `build` method is called when the `@AfterMapping` annotated method scope finishes. MapStruct will not call the `@AfterMapping` annotated method if the real target is used as `@MappingTarget` annotated parameter. - -[[using-spi]] -== Using the MapStruct SPI -=== Custom Accessor Naming Strategy - -MapStruct offers the possibility to override the `AccessorNamingStrategy` via the Service Provide Interface (SPI). A nice example is the use of the fluent API on the source object `GolfPlayer` and `GolfPlayerDto` below. - -.Source object GolfPlayer with fluent API. -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class GolfPlayer { - - private double handicap; - private String name; - - public double handicap() { - return handicap; - } - - public GolfPlayer withHandicap(double handicap) { - this.handicap = handicap; - return this; - } - - public String name() { - return name; - } - - public GolfPlayer withName(String name) { - this.name = name; - return this; - } -} ----- -==== - -.Source object GolfPlayerDto with fluent API. -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -public class GolfPlayerDto { - - private double handicap; - private String name; - - public double handicap() { - return handicap; - } - - public GolfPlayerDto withHandicap(double handicap) { - this.handicap = handicap; - return this; - } - - public String name() { - return name; - } - - public GolfPlayerDto withName(String name) { - this.name = name; - return this - } -} ----- -==== - -We want `GolfPlayer` to be mapped to a target object `GolfPlayerDto` similar like we 'always' do this: - -.Source object with fluent API. -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -@Mapper -public interface GolfPlayerMapper { - - GolfPlayerMapper INSTANCE = Mappers.getMapper( GolfPlayerMapper.class ); - - GolfPlayerDto toDto(GolfPlayer player); - - GolfPlayer toPlayer(GolfPlayerDto player); - -} ----- -==== - -This can be achieved with implementing the SPI `org.mapstruct.ap.spi.AccessorNamingStrategy` as in the following example. Here's an implemented `org.mapstruct.ap.spi.AccessorNamingStrategy`: - -.CustomAccessorNamingStrategy -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -/** - * A custom {@link AccessorNamingStrategy} recognizing getters in the form of {@code property()} and setters in the - * form of {@code withProperty(value)}. - */ -public class CustomAccessorNamingStrategy extends DefaultAccessorNamingStrategy { - - @Override - public boolean isGetterMethod(ExecutableElement method) { - String methodName = method.getSimpleName().toString(); - return !methodName.startsWith( "with" ) && method.getReturnType().getKind() != TypeKind.VOID; - } - - @Override - public boolean isSetterMethod(ExecutableElement method) { - String methodName = method.getSimpleName().toString(); - return methodName.startsWith( "with" ) && methodName.length() > 4; - } - - @Override - public String getPropertyName(ExecutableElement getterOrSetterMethod) { - String methodName = getterOrSetterMethod.getSimpleName().toString(); - return IntrospectorUtils.decapitalize( methodName.startsWith( "with" ) ? methodName.substring( 4 ) : methodName ); - } -} ----- -==== -The `CustomAccessorNamingStrategy` makes use of the `DefaultAccessorNamingStrategy` (also available in mapstruct-processor) and relies on that class to leave most of the default behaviour unchanged. - -To use a custom SPI implementation, it must be located in a separate JAR file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). - -[TIP] -Fore more details: The example above is present in our examples repository (https://github.com/mapstruct/mapstruct-examples). - -[mapping-exclusion-provider] -=== Mapping Exclusion Provider - -MapStruct offers the possibility to override the `MappingExclusionProvider` via the Service Provider Interface (SPI). -A nice example is to not allow MapStruct to create an automatic sub-mapping for a certain type, -i.e. MapStruct will not try to generate an automatic sub-mapping method for an excluded type. - -[NOTE] -==== -The `DefaultMappingExclusionProvider` will exclude all types under the `java` or `javax` packages. -This means that MapStruct will not try to generate an automatic sub-mapping method between some custom type and some type declared in the Java class library. -==== - -.Source object -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -include::{processor-ap-test}/nestedbeans/exclusions/custom/Source.java[tag=documentation] ----- -==== - -.Target object -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -include::{processor-ap-test}/nestedbeans/exclusions/custom/Target.java[tag=documentation] ----- -==== - -.Mapper definition -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -include::{processor-ap-test}/nestedbeans/exclusions/custom/ErroneousCustomExclusionMapper.java[tag=documentation] ----- -==== - -We want to exclude the `NestedTarget` from the automatic sub-mapping method generation. - -.CustomMappingExclusionProvider -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -include::{processor-ap-test}/nestedbeans/exclusions/custom/CustomMappingExclusionProvider.java[tag=documentation] ----- -==== - -To use a custom SPI implementation, it must be located in a separate JAR file -together with the file `META-INF/services/org.mapstruct.ap.spi.MappingExclusionProvider` with the fully qualified name of your custom implementation as content -(e.g. `org.mapstruct.example.CustomMappingExclusionProvider`). -This JAR file needs to be added to the annotation processor classpath -(i.e. add it next to the place where you added the mapstruct-processor jar). - - -[[custom-builder-provider]] -=== Custom Builder Provider - -MapStruct offers the possibility to override the `DefaultProvider` via the Service Provider Interface (SPI). -A nice example is to provide support for a custom builder strategy. - -.Custom Builder Provider which disables Builder support -==== -[source, java, linenums] -[subs="verbatim,attributes"] ----- -include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] ----- -==== +include::chapter-13-using-mapstruct-spi.asciidoc[] \ No newline at end of file From 6d9a50601ee84accef48882ef91b2870f4239980 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 12 Sep 2019 20:21:39 +0200 Subject: [PATCH 0382/1006] #1867 refactor make the source model only a reflection of the source (#1868) --- .../internal/model/AbstractBaseBuilder.java | 3 +- .../model/AbstractMappingMethodBuilder.java | 33 ++-- .../ap/internal/model/BeanMappingMethod.java | 170 ++++++---------- .../model/ContainerMappingMethodBuilder.java | 1 - .../model/{source => }/ForgedMethod.java | 138 ++++++++----- .../{source => }/ForgedMethodHistory.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 1 - .../internal/model/MappingBuilderContext.java | 1 - .../model/NestedPropertyMappingMethod.java | 3 +- .../NestedTargetPropertyMappingHolder.java | 185 ++++++++++-------- .../ap/internal/model/PropertyMapping.java | 86 +++----- .../ap/internal/model/ValueMappingMethod.java | 2 - .../model/beanmapping/MappingReference.java | 95 +++++++++ .../model/beanmapping/MappingReferences.java | 129 ++++++++++++ .../PropertyEntry.java | 2 +- .../SourceReference.java | 7 +- .../TargetReference.java | 5 +- .../model/beanmapping/package-info.java | 10 + .../ap/internal/model/source/BeanMapping.java | 20 -- .../ap/internal/model/source/Mapping.java | 84 +------- .../internal/model/source/MappingOptions.java | 73 +------ .../internal/model/source/SourceMethod.java | 33 +--- .../internal/model/source/package-info.java | 4 + 23 files changed, 547 insertions(+), 540 deletions(-) rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => }/ForgedMethod.java (66%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => }/ForgedMethodHistory.java (98%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => beanmapping}/PropertyEntry.java (98%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => beanmapping}/SourceReference.java (98%) rename processor/src/main/java/org/mapstruct/ap/internal/model/{source => beanmapping}/TargetReference.java (98%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/package-info.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 220176c06d..b030f41c3f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -11,7 +11,6 @@ import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.MappingMethodUtils; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.util.MapperConfiguration; @@ -108,7 +107,7 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp if ( mappingMethod == null ) { return null; } - if (methodRef.getMappingOptions().isRestrictToDefinedMappings() || + if (methodRef.getMappingReferences().isRestrictToDefinedMappings() || !ctx.getMappingsToGenerate().contains( mappingMethod )) { // If the mapping options are restricted only to the defined mappings, then use the mapping method. // See https://github.com/mapstruct/mapstruct/issues/1148 diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 6e6b3e0e97..a5da9d0532 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -9,10 +9,10 @@ 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; +import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; + /** * An abstract builder that can be reused for building {@link MappingMethod}(s). * @@ -43,26 +43,17 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { if ( method instanceof ForgedMethod ) { history = ( (ForgedMethod) method ).getHistory(); } - ForgedMethod forgedMethod = new ForgedMethod( - name, - sourceType, + + ForgedMethodHistory forgedHistory = new ForgedMethodHistory( + history, + Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), + Strings.stubPropertyName( targetType.getName() ), + sourceRHS.getSourceType(), targetType, - method.getMapperConfiguration(), - method.getExecutable(), - method.getContextParameters(), - method.getContextProvidedMethods(), - new ForgedMethodHistory( - history, - Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), - Strings.stubPropertyName( targetType.getName() ), - sourceRHS.getSourceType(), - targetType, - shouldUsePropertyNamesInHistory(), - sourceRHS.getSourceErrorMessagePart() - ), - null, - true - ); + shouldUsePropertyNamesInHistory(), + sourceRHS.getSourceErrorMessagePart() ); + + ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true ); return createForgedAssignment( sourceRHS, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d5506b6bca..8c55047ede 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -19,7 +19,6 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.function.Consumer; import java.util.function.Function; import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; @@ -34,16 +33,16 @@ import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; 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.model.source.Mapping; import org.mapstruct.ap.internal.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.beanmapping.MappingReference; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.PropertyEntry; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.model.source.SourceReference; -import org.mapstruct.ap.internal.model.source.TargetReference; +import org.mapstruct.ap.internal.model.beanmapping.SourceReference; +import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -54,6 +53,7 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import static org.mapstruct.ap.internal.model.source.Mapping.getMappingByTargetName; +import static org.mapstruct.ap.internal.model.beanmapping.MappingReferences.forSourceMethod; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; @@ -81,16 +81,16 @@ public static class Builder { /* returnType to construct can have a builder */ private BuilderType returnTypeBuilder; - private Map unprocessedTargetProperties; private Map unprocessedSourceProperties; private Set targetProperties; private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); + private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); private Function singleMapping; - private Consumer> mappingsInitializer; - private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); + + private MappingReferences mappingReferences; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -105,17 +105,25 @@ public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { public Builder sourceMethod(SourceMethod sourceMethod) { singleMapping = targetName -> getMappingByTargetName( targetName, sourceMethod.getMappingOptions().getMappings() ); - mappingsInitializer = - mappings -> mappings.stream().forEach( this::initReferencesForSourceMethodMapping ); this.method = sourceMethod; + this.mappingReferences = forSourceMethod( sourceMethod, ctx.getMessager(), ctx.getTypeFactory() ); return this; } - public Builder forgedMethod(Method method) { + public Builder forgedMethod(ForgedMethod forgedMethod) { singleMapping = targetPropertyName -> null; - mappingsInitializer = - mappings -> mappings.stream().forEach( this::initReferencesForForgedMethodMapping ); - this.method = method; + this.method = forgedMethod; + mappingReferences = forgedMethod.getMappingReferences(); + Parameter sourceParameter = first( Parameter.getSourceParameters( forgedMethod.getParameters() ) ); + for ( MappingReference mappingReference: mappingReferences.getMappingReferences() ) { + SourceReference sourceReference = mappingReference.getSourceReference(); + if ( sourceReference != null ) { + mappingReference.setSourceReference( new SourceReference.BuilderFromSourceReference() + .sourceParameter( sourceParameter ) + .sourceReference( sourceReference ) + .build() ); + } + } return this; } @@ -160,10 +168,6 @@ public BeanMappingMethod build() { /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; - /* initialize mappings for this method && filter invalid inverse methods */ - mappingsInitializer.accept( method.getMappingOptions().getMappings() ); - method.getMappingOptions().getMappings().removeIf( mapping -> !isValidWhenReversed( mapping ) ); - CollectionMappingStrategyPrism cms = this.method.getMapperConfiguration().getCollectionMappingStrategy(); // determine accessors @@ -199,7 +203,7 @@ public BeanMappingMethod build() { return null; } - if ( !method.getMappingOptions().isRestrictToDefinedMappings() ) { + if ( !mappingReferences.isRestrictToDefinedMappings() ) { // map properties without a mapping applyPropertyNameBasedMapping(); @@ -298,12 +302,12 @@ private MethodReference getFinalizerMethod() { * If there were nested defined targets that have not been handled. Then we need to process them at the end. */ private void handleUnprocessedDefinedTargets() { - Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); + Iterator>> iterator = unprocessedDefinedTargets.entrySet().iterator(); // For each of the unprocessed defined targets forge a mapping for each of the // method source parameters. The generated mappings are not going to use forged name based mappings. while ( iterator.hasNext() ) { - Entry> entry = iterator.next(); + Entry> entry = iterator.next(); String propertyName = entry.getKey(); if ( !unprocessedTargetProperties.containsKey( propertyName ) ) { continue; @@ -316,7 +320,7 @@ private void handleUnprocessedDefinedTargets() { .name( propertyName ) .build(); - MappingOptions mappingOptions = extractAdditionalOptions( propertyName, true ); + MappingReferences mappingRefs = extractMappingReferences( propertyName, true ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) @@ -325,8 +329,8 @@ private void handleUnprocessedDefinedTargets() { .targetPropertyName( propertyName ) .sourceReference( reference ) .existingVariableNames( existingVariableNames ) - .dependsOn( mappingOptions.collectNestedDependsOn() ) - .forgeMethodWithMappingOptions( mappingOptions ) + .dependsOn( mappingRefs.collectNestedDependsOn() ) + .forgeMethodWithMappingReferences( mappingRefs ) .forceUpdateMethod( forceUpdateMethod ) .forgedNamedBased( false ) .build(); @@ -455,68 +459,6 @@ private MethodReference getFactoryMethod(Type returnTypeImpl, SelectionParameter return factoryMethod; } - /** - * Initialized the source- and target reference for a certain mapping for regular non forged methods - * - * @param mapping the mapping - */ - private void initReferencesForSourceMethodMapping(Mapping mapping ) { - - // handle source reference - SourceReference sourceReference = new SourceReference.BuilderFromMapping() - .mapping( mapping ) - .method( method ) - .messager( ctx.getMessager() ) - .typeFactory( ctx.getTypeFactory() ) - .build(); - mapping.setSourceReference( sourceReference ); - - // handle target reference - TargetReference targetReference = new TargetReference.BuilderFromTargetMapping() - .mapping( mapping ) - .method( method ) - .messager( ctx.getMessager() ) - .typeFactory( ctx.getTypeFactory() ) - .build(); - mapping.setTargetReference( targetReference ); - - } - - /** - * Initialized the source- and target reference for forged methods (e.g. when handling nesting) - * - * @param mapping the mapping - */ - private void initReferencesForForgedMethodMapping(Mapping mapping ) { - - /* a forge method has always one mandatory source parameter and no more */ - Parameter sourceParameter = first( Parameter.getSourceParameters( method.getParameters() ) ); - - SourceReference sourceReference = mapping.getSourceReference(); - if ( sourceReference != null ) { - SourceReference oldSourceReference = sourceReference; - sourceReference = new SourceReference.BuilderFromSourceReference() - .sourceParameter( sourceParameter ) - .sourceReference( oldSourceReference ) - .build(); - } - mapping.setSourceReference( sourceReference ); - - } - - /** - * MapStruct filters automatically inversed invalid methods out. TODO: this is a principle we should discuss! - * @param mapping - * @return - */ - private static boolean isValidWhenReversed(Mapping mapping) { - if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { - return mapping.getTargetReference().isValid() && ( mapping.getSourceReference() == null || - mapping.getSourceReference().isValid() ); - } - return true; - } - /** * Iterates over all defined mapping methods ({@code @Mapping(s)}), either directly given or inherited from the * inverse mapping method. @@ -533,11 +475,11 @@ private boolean handleDefinedMappings() { Set handledTargets = new HashSet<>(); // first we have to handle nested target mappings - if ( method.getMappingOptions().hasNestedTargetReferences() ) { + if ( mappingReferences.hasNestedTargetReferences() ) { errorOccurred = handleDefinedNestedTargetMapping( handledTargets ); } - for ( Mapping mapping : method.getMappingOptions().getMappings() ) { + for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { TargetReference targetReference = mapping.getTargetReference(); if ( targetReference.isValid() ) { String target = first( targetReference.getPropertyEntries() ).getFullName(); @@ -573,6 +515,7 @@ private boolean handleDefinedNestedTargetMapping(Set handledTargets) { NestedTargetPropertyMappingHolder holder = new NestedTargetPropertyMappingHolder.Builder() .mappingContext( ctx ) .method( method ) + .mappingReferences( mappingReferences ) .existingVariableNames( existingVariableNames ) .build(); @@ -580,7 +523,8 @@ private boolean handleDefinedNestedTargetMapping(Set handledTargets) { propertyMappings.addAll( holder.getPropertyMappings() ); handledTargets.addAll( holder.getHandledTargets() ); // Store all the unprocessed defined targets. - for ( Entry> entry : holder.getUnprocessedDefinedTarget().entrySet() ) { + for ( Entry> entry : holder.getUnprocessedDefinedTarget() + .entrySet() ) { if ( entry.getValue().isEmpty() ) { continue; } @@ -589,15 +533,16 @@ private boolean handleDefinedNestedTargetMapping(Set handledTargets) { return holder.hasErrorOccurred(); } - private boolean handleDefinedMapping(Mapping mapping, Set handledTargets) { + private boolean handleDefinedMapping(MappingReference mappingRef, Set handledTargets) { boolean errorOccured = false; PropertyMapping propertyMapping = null; - TargetReference targetRef = mapping.getTargetReference(); + TargetReference targetRef = mappingRef.getTargetReference(); + Mapping mapping = mappingRef.getMapping(); PropertyEntry targetProperty = first( targetRef.getPropertyEntries() ); - String propertyName = targetProperty.getName(); + String targetPropertyName = targetProperty.getName(); // unknown properties given via dependsOn()? for ( String dependency : mapping.getDependsOn() ) { @@ -617,14 +562,14 @@ private boolean handleDefinedMapping(Mapping mapping, Set handledTargets // its an ignored property mapping if ( mapping.isIgnored() ) { propertyMapping = null; - handledTargets.add( mapping.getTargetName() ); + handledTargets.add( targetProperty.getName() ); } // its a plain-old property mapping else if ( mapping.getSourceName() != null ) { // determine source parameter - SourceReference sourceRef = mapping.getSourceReference(); + SourceReference sourceRef = mappingRef.getSourceReference(); if ( sourceRef.isValid() ) { // targetProperty == null can occur: we arrived here because we want as many errors @@ -633,7 +578,7 @@ else if ( mapping.getSourceName() != null ) { .mappingContext( ctx ) .sourceMethod( method ) .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) + .targetPropertyName( targetPropertyName ) .sourcePropertyName( mapping.getSourceName() ) .sourceReference( sourceRef ) .selectionParameters( mapping.getSelectionParameters() ) @@ -646,7 +591,7 @@ else if ( mapping.getSourceName() != null ) { .nullValueCheckStrategy( mapping.getNullValueCheckStrategy() ) .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) .build(); - handledTargets.add( propertyName ); + handledTargets.add( targetPropertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); } else { @@ -657,27 +602,28 @@ else if ( mapping.getSourceName() != null ) { // its a constant // if we have an unprocessed target that means that it most probably is nested and we should // not generated any mapping for it now. Eventually it will be done though - else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { + else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { propertyMapping = new ConstantMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) .constantExpression( mapping.getConstant() ) .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) + .targetPropertyName( targetPropertyName ) .formattingParameters( mapping.getFormattingParameters() ) .selectionParameters( mapping.getSelectionParameters() ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) .mirror( mapping.getMirror() ) .build(); - handledTargets.add( mapping.getTargetName() ); + handledTargets.add( targetPropertyName ); } // its an expression // if we have an unprocessed target that means that it most probably is nested and we should // not generated any mapping for it now. Eventually it will be done though - else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.containsKey( propertyName ) ) { + else if ( mapping.getJavaExpression() != null + && !unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { propertyMapping = new JavaExpressionMappingBuilder() .mappingContext( ctx ) @@ -685,11 +631,11 @@ else if ( mapping.getJavaExpression() != null && !unprocessedDefinedTargets.cont .javaExpression( mapping.getJavaExpression() ) .existingVariableNames( existingVariableNames ) .targetProperty( targetProperty ) - .targetPropertyName( mapping.getTargetName() ) + .targetPropertyName( targetPropertyName ) .dependsOn( mapping.getDependsOn() ) .mirror( mapping.getMirror() ) .build(); - handledTargets.add( mapping.getTargetName() ); + handledTargets.add( targetPropertyName ); } // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers @@ -748,6 +694,7 @@ private void applyPropertyNameBasedMapping() { .name( targetProperty.getKey() ) .build(); + MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); newPropertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) @@ -760,7 +707,7 @@ private void applyPropertyNameBasedMapping() { .defaultValue( mapping != null ? mapping.getDefaultValue() : null ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) - .forgeMethodWithMappingOptions( extractAdditionalOptions( targetPropertyName, false ) ) + .forgeMethodWithMappingReferences( mappingRefs ) .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? mapping.getNullValuePropertyMappingStrategy() : null ) @@ -816,6 +763,7 @@ private void applyParameterNameBasedMapping() { .name( targetProperty.getKey() ) .build(); + MappingReferences mappingRefs = extractMappingReferences( targetProperty.getKey(), false ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) @@ -827,7 +775,7 @@ private void applyParameterNameBasedMapping() { .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) - .forgeMethodWithMappingOptions( extractAdditionalOptions( targetProperty.getKey(), false ) ) + .forgeMethodWithMappingReferences( mappingRefs ) .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) .nullValuePropertyMappingStrategy( mapping != null ? mapping.getNullValuePropertyMappingStrategy() : null ) @@ -844,13 +792,12 @@ private void applyParameterNameBasedMapping() { } } - private MappingOptions extractAdditionalOptions(String targetProperty, boolean restrictToDefinedMappings) { - MappingOptions additionalOptions = null; + private MappingReferences extractMappingReferences(String targetProperty, boolean restrictToDefinedMappings) { if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { - Set mappings = unprocessedDefinedTargets.get( targetProperty ); - additionalOptions = MappingOptions.forMappingsOnly( mappings, restrictToDefinedMappings ); + Set mappings = unprocessedDefinedTargets.get( targetProperty ); + return new MappingReferences( mappings, restrictToDefinedMappings ); } - return additionalOptions; + return null; } private Accessor getTargetPropertyReadAccessor(String propertyName) { @@ -858,6 +805,9 @@ private Accessor getTargetPropertyReadAccessor(String propertyName) { } private ReportingPolicyPrism getUnmappedTargetPolicy() { + if ( mappingReferences.isForForgedMethods() ) { + return ReportingPolicyPrism.IGNORE; + } MappingOptions mappingOptions = method.getMappingOptions(); if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().getReportingPolicy() != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index f495375d60..f5ad077378 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -16,7 +16,6 @@ import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java similarity index 66% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index 7b63909a94..2f73c4b9ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -3,9 +3,10 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; import java.util.List; import javax.lang.model.element.ExecutableElement; @@ -13,6 +14,10 @@ import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.util.MapperConfiguration; import org.mapstruct.ap.internal.util.Strings; @@ -26,68 +31,104 @@ public class ForgedMethod implements Method { private final List parameters; private final Type returnType; private final String name; - private final ExecutableElement positionHintElement; private final List thrownTypes; - private final MapperConfiguration mapperConfiguration; private final ForgedMethodHistory history; private final List sourceParameters; private final List contextParameters; private final Parameter mappingTargetParameter; - private final MappingOptions mappingOptions; - private final ParameterProvidedMethods contextProvidedMethods; + private final MappingReferences mappingReferences; + + private final Method basedOn; private final boolean forgedNameBased; /** - * Creates a new forged method with the given name. + * Creates a new forged method with the given name for mapping a method parameter to a property. * * @param name the (unique name) for this method * @param sourceType the source type * @param returnType the return type. - * @param mapperConfiguration the mapper configuration - * @param positionHintElement element used to for reference to the position in the source file. - * @param additionalParameters additional parameters to add to the forged method - * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context - * parameters + * @param basedOn the method that (originally) triggered this nested method generation. + * @return a new forge method */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - ParameterProvidedMethods parameterProvidedMethods) { - this( + public static ForgedMethod forParameterMapping(String name, Type sourceType, Type returnType, + Method basedOn) { + return new ForgedMethod( name, sourceType, returnType, - mapperConfiguration, - positionHintElement, - additionalParameters, - parameterProvidedMethods, - null, + Collections.emptyList(), + basedOn, null, - false ); + MappingReferences.empty(), + false + ); } - /** - * Creates a new forged method with the given name. + /** + * Creates a new forged method for mapping a bean property to a property * * @param name the (unique name) for this method * @param sourceType the source type * @param returnType the return type. - * @param mapperConfiguration the mapper configuration - * @param positionHintElement element used to for reference to the position in the source file. - * @param additionalParameters additional parameters to add to the forged method - * @param parameterProvidedMethods additional factory/lifecycle methods to consider that are provided by context - * parameters + * @param parameters other parameters (including the context + @MappingTarget + * @param basedOn the method that (originally) triggered this nested method generation. * @param history a parent forged method if this is a forged method within a forged method - * @param mappingOptions the mapping options for this method + * @param mappingReferences the mapping options for this method * @param forgedNameBased forges a name based (matched) mapping method + * @return a new forge method */ - public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfiguration mapperConfiguration, - ExecutableElement positionHintElement, List additionalParameters, - ParameterProvidedMethods parameterProvidedMethods, ForgedMethodHistory history, - MappingOptions mappingOptions, boolean forgedNameBased) { - String sourceParamName = Strings.decapitalize( sourceType.getName() ); + public static ForgedMethod forPropertyMapping(String name, Type sourceType, Type returnType, + List parameters, Method basedOn, + ForgedMethodHistory history, MappingReferences mappingReferences, + boolean forgedNameBased) { + return new ForgedMethod( + name, + sourceType, + returnType, + parameters, + basedOn, + history, + mappingReferences == null ? MappingReferences.empty() : mappingReferences, + forgedNameBased + ); + } + + /** + * Creates a new forged method for mapping a collection element, map key/value or stream element + * + * @param name the (unique name) for this method + * @param sourceType the source type + * @param returnType the return type. + * @param basedOn the method that (originally) triggered this nested method generation. + * @param history a parent forged method if this is a forged method within a forged method + * @param forgedNameBased forges a name based (matched) mapping method + * + * @return a new forge method + */ + public static ForgedMethod forElementMapping(String name, Type sourceType, Type returnType, Method basedOn, + ForgedMethodHistory history, boolean forgedNameBased) { + return new ForgedMethod( + name, + sourceType, + returnType, + basedOn.getContextParameters(), + basedOn, + history, + MappingReferences.empty(), + forgedNameBased + ); + } + + private ForgedMethod(String name, Type sourceType, Type returnType, List additionalParameters, + Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences, + boolean forgedNameBased) { + + // establish name + String sourceParamName = Strings.decapitalize( sourceType.getName() ); String sourceParamSafeName = Strings.getSafeVariableName( sourceParamName ); + // establish parameters this.parameters = new ArrayList<>( 1 + additionalParameters.size() ); Parameter sourceParameter = new Parameter( sourceParamSafeName, sourceType ); this.parameters.add( sourceParameter ); @@ -95,15 +136,15 @@ public ForgedMethod(String name, Type sourceType, Type returnType, MapperConfigu this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); - this.contextProvidedMethods = parameterProvidedMethods; - this.returnType = returnType; this.thrownTypes = new ArrayList<>(); + + // based on method + this.basedOn = basedOn; + this.name = Strings.sanitizeIdentifierName( name ); - this.mapperConfiguration = mapperConfiguration; - this.positionHintElement = positionHintElement; this.history = history; - this.mappingOptions = mappingOptions == null ? MappingOptions.empty() : mappingOptions; + this.mappingReferences = mappingReferences; this.forgedNameBased = forgedNameBased; } @@ -116,15 +157,14 @@ public ForgedMethod(String name, ForgedMethod forgedMethod) { this.parameters = forgedMethod.parameters; this.returnType = forgedMethod.returnType; this.thrownTypes = new ArrayList<>(); - this.mapperConfiguration = forgedMethod.mapperConfiguration; - this.positionHintElement = forgedMethod.positionHintElement; this.history = forgedMethod.history; this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); - this.mappingOptions = forgedMethod.mappingOptions; - this.contextProvidedMethods = forgedMethod.contextProvidedMethods; + this.mappingReferences = forgedMethod.mappingReferences; + + this.basedOn = forgedMethod.basedOn; this.name = name; this.forgedNameBased = forgedMethod.forgedNameBased; @@ -182,7 +222,7 @@ public List getContextParameters() { @Override public ParameterProvidedMethods getContextProvidedMethods() { - return contextProvidedMethods; + return basedOn.getContextProvidedMethods(); } @Override @@ -248,7 +288,7 @@ public boolean overridesMethod() { @Override public ExecutableElement getExecutable() { - return positionHintElement; + return basedOn.getExecutable(); } @Override @@ -283,7 +323,7 @@ public Type getDefiningType() { @Override public MapperConfiguration getMapperConfiguration() { - return mapperConfiguration; + return basedOn.getMapperConfiguration(); } @Override @@ -303,7 +343,11 @@ public boolean isObjectFactory() { @Override public MappingOptions getMappingOptions() { - return mappingOptions; + return basedOn.getMappingOptions(); + } + + public MappingReferences getMappingReferences() { + return mappingReferences; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java similarity index 98% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java index 65c9408573..9355c62fd5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ForgedMethodHistory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Strings; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index cc6155be96..909535c7e2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -17,7 +17,6 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index dae67e927f..4fb5c8a370 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -23,7 +23,6 @@ import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.model.source.ForgedMethod; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 27c45a488f..f698f83459 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -12,8 +12,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.PropertyEntry; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index f074c32974..e9ce0b64f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -14,13 +15,14 @@ import java.util.Set; import java.util.function.Function; +import org.mapstruct.ap.internal.model.beanmapping.MappingReference; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; +import org.mapstruct.ap.internal.model.beanmapping.SourceReference; +import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.source.Mapping; -import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.PropertyEntry; -import org.mapstruct.ap.internal.model.source.SourceReference; -import org.mapstruct.ap.internal.model.source.TargetReference; import static org.mapstruct.ap.internal.util.Collections.first; @@ -35,13 +37,13 @@ public class NestedTargetPropertyMappingHolder { private final List processedSourceParameters; private final Set handledTargets; private final List propertyMappings; - private final Map> unprocessedDefinedTarget; + private final Map> unprocessedDefinedTarget; private final boolean errorOccurred; public NestedTargetPropertyMappingHolder( List processedSourceParameters, Set handledTargets, List propertyMappings, - Map> unprocessedDefinedTarget, boolean errorOccurred) { + Map> unprocessedDefinedTarget, boolean errorOccurred) { this.processedSourceParameters = processedSourceParameters; this.handledTargets = handledTargets; this.propertyMappings = propertyMappings; @@ -73,7 +75,7 @@ public List getPropertyMappings() { /** * @return a map of all the unprocessed defined targets that can be applied to name forged base methods */ - public Map> getUnprocessedDefinedTarget() { + public Map> getUnprocessedDefinedTarget() { return unprocessedDefinedTarget; } @@ -87,11 +89,17 @@ public boolean hasErrorOccurred() { public static class Builder { private Method method; + private MappingReferences mappingReferences; private MappingBuilderContext mappingContext; private Set existingVariableNames; private List propertyMappings; private Set handledTargets; + public Builder mappingReferences(MappingReferences mappingReferences) { + this.mappingReferences = mappingReferences; + return this; + } + public Builder method(Method method) { this.method = method; return this; @@ -114,11 +122,11 @@ public NestedTargetPropertyMappingHolder build() { // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. - GroupedTargetReferences groupedByTP = groupByTargetReferences( method.getMappingOptions() ); - Map> unprocessedDefinedTarget - = new LinkedHashMap<>(); + GroupedTargetReferences groupedByTP = groupByTargetReferences( ); + Map> unprocessedDefinedTarget = new LinkedHashMap<>(); - for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { + for ( Map.Entry> entryByTP : + groupedByTP.poppedTargetReferences.entrySet() ) { PropertyEntry targetProperty = entryByTP.getKey(); //Now we are grouping the already popped mappings by the source parameter(s) of the method GroupedBySourceParameters groupedBySourceParam = groupBySourceParameter( @@ -131,7 +139,7 @@ public NestedTargetPropertyMappingHolder build() { // All not processed mappings that should have been applied to all are part of the unprocessed // defined targets unprocessedDefinedTarget.put( targetProperty, groupedBySourceParam.notProcessedAppliesToAll ); - for ( Map.Entry> entryByParam : groupedBySourceParam + for ( Map.Entry> entryByParam : groupedBySourceParam .groupedBySourceParameter.entrySet() ) { Parameter sourceParameter = entryByParam.getKey(); @@ -147,7 +155,7 @@ public NestedTargetPropertyMappingHolder build() { // from the Mappings and not restrict on the defined mappings (allow to forge name based mapping) // if we have composite methods i.e. more then 2 parameters then we have to force a creation // of an update method in our generation - for ( Map.Entry> entryBySP : groupedSourceReferences + for ( Map.Entry> entryBySP : groupedSourceReferences .groupedBySourceReferences .entrySet() ) { PropertyEntry sourceEntry = entryBySP.getKey(); @@ -162,11 +170,11 @@ public NestedTargetPropertyMappingHolder build() { // @Mapping(target = "vehicleInfo.images", source = "images") //}) // See Issue1269Test, Issue1247Test, AutomappingAndNestedTest for more info as well - MappingOptions sourceMappingOptions = MappingOptions.forMappingsOnly( - entryBySP.getValue(), + MappingReferences sourceMappingRefs = new MappingReferences( entryBySP.getValue(), multipleSourceParametersForTP, forceUpdateMethodOrNonNestedReferencesPresent ); + SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) .type( sourceEntry.getType() ) @@ -179,7 +187,7 @@ public NestedTargetPropertyMappingHolder build() { // parts of the nested properties are mapped to different sources (see comment above as well) // we would force an update method PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( - sourceMappingOptions, + sourceMappingRefs, targetProperty, sourceRef, forceUpdateMethodOrNonNestedReferencesPresent @@ -196,10 +204,8 @@ public NestedTargetPropertyMappingHolder build() { // However, here we do not forge name based mappings and we only // do update on the defined Mappings. if ( !groupedSourceReferences.nonNested.isEmpty() ) { - MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( - groupedSourceReferences.nonNested, - true - ); + MappingReferences mappingReferences = + new MappingReferences( groupedSourceReferences.nonNested, true ); SourceReference reference = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) .name( targetProperty.getName() ) @@ -212,7 +218,7 @@ public NestedTargetPropertyMappingHolder build() { // an update method. The reason is that they might be for the same reference and we should // use update for it PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( - nonNestedOptions, + mappingReferences, targetProperty, reference, forceUpdateMethodForNonNested @@ -253,22 +259,19 @@ public NestedTargetPropertyMappingHolder build() { * @param sourceParameter the source parameter that is used * @param forceUpdateMethod whether we need to force an update method */ - private void handleSourceParameterMappings(Set sourceParameterMappings, PropertyEntry targetProperty, - Parameter sourceParameter, boolean forceUpdateMethod) { + private void handleSourceParameterMappings(Set sourceParameterMappings, + PropertyEntry targetProperty, Parameter sourceParameter, + boolean forceUpdateMethod) { if ( !sourceParameterMappings.isEmpty() ) { // The source parameter mappings have no mappings, the source name is actually the parameter itself - MappingOptions nonNestedOptions = MappingOptions.forMappingsOnly( - new LinkedHashSet<>(), - false, - true - ); + MappingReferences nonNestedRefs = new MappingReferences( Collections.emptySet(), false, true ); SourceReference reference = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) .name( targetProperty.getName() ) .build(); PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( - nonNestedOptions, + nonNestedRefs, targetProperty, reference, forceUpdateMethod @@ -324,26 +327,21 @@ private void handleSourceParameterMappings(Set sourceParameterMappings, * } *

      * - * @param mappingOptions that need to be used to create the {@link GroupedTargetReferences} - * * @return See above */ - private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOptions) { - Set mappings = mappingOptions.getMappings(); + private GroupedTargetReferences groupByTargetReferences( ) { // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty - = new LinkedHashMap<>(); - Map> singleTargetReferences - = new LinkedHashMap<>(); + Map> mappingsKeyedByProperty = new LinkedHashMap<>(); + Map> singleTargetReferences = new LinkedHashMap<>(); boolean errorOccurred = false; - for ( Mapping mapping : mappings ) { + for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { TargetReference targetReference = mapping.getTargetReference(); if ( !targetReference.isValid() ) { errorOccurred = true; continue; } PropertyEntry property = first( targetReference.getPropertyEntries() ); - Mapping newMapping = mapping.popTargetReference(); + MappingReference newMapping = mapping.popTargetReference(); if ( newMapping != null ) { // group properties on current name. if ( !mappingsKeyedByProperty.containsKey( property ) ) { @@ -445,12 +443,12 @@ private GroupedTargetReferences groupByTargetReferences(MappingOptions mappingOp * property as the {@code mappings} * @return the split mapping options. */ - private GroupedBySourceParameters groupBySourceParameter(Set mappings, - Set singleTargetReferences) { + private GroupedBySourceParameters groupBySourceParameter(Set mappings, + Set singleTargetReferences) { - Map> mappingsKeyedByParameter = new LinkedHashMap<>(); - Set appliesToAll = new LinkedHashSet<>(); - for ( Mapping mapping : mappings ) { + Map> mappingsKeyedByParameter = new LinkedHashMap<>(); + Set appliesToAll = new LinkedHashSet<>(); + for ( MappingReference mapping : mappings ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { Parameter parameter = mapping.getSourceReference().getParameter(); if ( !mappingsKeyedByParameter.containsKey( parameter ) ) { @@ -469,11 +467,11 @@ private GroupedBySourceParameters groupBySourceParameter(Set mappings, SourceReference::getParameter ); - for ( Map.Entry> entry : mappingsKeyedByParameter.entrySet() ) { + for ( Map.Entry> entry : mappingsKeyedByParameter.entrySet() ) { entry.getValue().addAll( appliesToAll ); } - Set notProcessAppliesToAll = + Set notProcessAppliesToAll = mappingsKeyedByParameter.isEmpty() ? appliesToAll : new LinkedHashSet<>(); return new GroupedBySourceParameters( mappingsKeyedByParameter, notProcessAppliesToAll ); @@ -509,18 +507,18 @@ private GroupedBySourceParameters groupBySourceParameter(Set mappings, * * @return the Grouped Source References */ - private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry> entryByParam, - Set singleTargetReferences) { - Set mappings = entryByParam.getValue(); - Set nonNested = new LinkedHashSet<>(); - Set appliesToAll = new LinkedHashSet<>(); - Set sourceParameterMappings = new LinkedHashSet<>(); + private GroupedSourceReferences groupByPoppedSourceReferences( + Map.Entry> entryByParam, + Set singleTargetReferences) { + Set mappings = entryByParam.getValue(); + Set nonNested = new LinkedHashSet<>(); + Set appliesToAll = new LinkedHashSet<>(); + Set sourceParameterMappings = new LinkedHashSet<>(); // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty + Map> mappingsKeyedByProperty = new LinkedHashMap<>(); - for ( Mapping mapping : mappings ) { - - Mapping newMapping = mapping.popSourceReference(); + for ( MappingReference mapping : mappings ) { + MappingReference newMapping = mapping.popSourceReference(); if ( newMapping != null ) { // group properties on current name. PropertyEntry property = first( mapping.getSourceReference().getPropertyEntries() ); @@ -543,7 +541,7 @@ else if ( mapping.getSourceReference() == null ) { // applied to everything. boolean hasNoMappings = mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty(); Parameter sourceParameter = entryByParam.getKey(); - Set singleTargetReferencesToUse = + Set singleTargetReferencesToUse = extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( singleTargetReferences, sourceParameterMappings, @@ -558,11 +556,11 @@ else if ( mapping.getSourceReference() == null ) { first( sourceReference.getPropertyEntries() ) ); - for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { + for ( Map.Entry> entry : mappingsKeyedByProperty.entrySet() ) { entry.getValue().addAll( appliesToAll ); } - Set notProcessedAppliesToAll = new LinkedHashSet<>(); + Set notProcessedAppliesToAll = new LinkedHashSet<>(); // If the applied to all were not added to all properties because they were empty, and the non-nested // one are not empty, add them to the non-nested ones if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { @@ -597,13 +595,13 @@ else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { * * @return a list with valid single target references */ - private Set extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( - Set singleTargetReferences, Set sourceParameterMappings, boolean hasNoMappings, - Parameter sourceParameter) { - Set singleTargetReferencesToUse = null; + private Set extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( + Set singleTargetReferences, Set sourceParameterMappings, + boolean hasNoMappings, Parameter sourceParameter) { + Set singleTargetReferencesToUse = null; if ( singleTargetReferences != null ) { singleTargetReferencesToUse = new LinkedHashSet<>( singleTargetReferences.size() ); - for ( Mapping mapping : singleTargetReferences ) { + for ( MappingReference mapping : singleTargetReferences ) { if ( mapping.getSourceReference() == null || !mapping.getSourceReference().isValid() || !sourceParameter.equals( mapping.getSourceReference().getParameter() ) ) { // If the mapping has no sourceReference, it is not valid or it does not have the same source @@ -625,8 +623,10 @@ private Set extractSingleTargetReferencesToUseAndPopulateSourceParamete return singleTargetReferencesToUse; } - private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mappingOptions, - PropertyEntry targetProperty, SourceReference sourceReference, boolean forceUpdateMethod) { + private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences mappingReferences, + PropertyEntry targetProperty, + SourceReference sourceReference, + boolean forceUpdateMethod) { return new PropertyMapping.PropertyMappingBuilder() .mappingContext( mappingContext ) .sourceMethod( method ) @@ -634,8 +634,8 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mapp .targetPropertyName( targetProperty.getName() ) .sourceReference( sourceReference ) .existingVariableNames( existingVariableNames ) - .dependsOn( mappingOptions.collectNestedDependsOn() ) - .forgeMethodWithMappingOptions( mappingOptions ) + .dependsOn( mappingReferences.collectNestedDependsOn() ) + .forgeMethodWithMappingReferences( mappingReferences ) .forceUpdateMethod( forceUpdateMethod ) .forgedNamedBased( false ) .build(); @@ -650,12 +650,12 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingOptions mapp * @param singleTargetReferences to use * @param keyExtractor to be used to extract a key */ - private void populateWithSingleTargetReferences(Map> map, - Set singleTargetReferences, Function keyExtractor) { + private void populateWithSingleTargetReferences(Map> map, + Set singleTargetReferences, Function keyExtractor) { if ( singleTargetReferences != null ) { //This are non nested target references only their property needs to be added as they most probably // define it - for ( Mapping mapping : singleTargetReferences ) { + for ( MappingReference mapping : singleTargetReferences ) { if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { K key = keyExtractor.apply( mapping.getSourceReference() ); if ( key != null && !map.containsKey( key ) ) { @@ -668,11 +668,11 @@ private void populateWithSingleTargetReferences(Map> map, } private static class GroupedBySourceParameters { - private final Map> groupedBySourceParameter; - private final Set notProcessedAppliesToAll; + private final Map> groupedBySourceParameter; + private final Set notProcessedAppliesToAll; - private GroupedBySourceParameters(Map> groupedBySourceParameter, - Set notProcessedAppliesToAll) { + private GroupedBySourceParameters(Map> groupedBySourceParameter, + Set notProcessedAppliesToAll) { this.groupedBySourceParameter = groupedBySourceParameter; this.notProcessedAppliesToAll = notProcessedAppliesToAll; } @@ -683,16 +683,22 @@ private GroupedBySourceParameters(Map> groupedBySourcePa * references (target references that were not nested). */ private static class GroupedTargetReferences { - private final Map> poppedTargetReferences; - private final Map> singleTargetReferences; + private final Map> poppedTargetReferences; + private final Map> singleTargetReferences; private final boolean errorOccurred; - private GroupedTargetReferences(Map> poppedTargetReferences, - Map> singleTargetReferences, boolean errorOccurred) { + private GroupedTargetReferences(Map> poppedTargetReferences, + Map> singleTargetReferences, boolean errorOccurred) { this.poppedTargetReferences = poppedTargetReferences; this.singleTargetReferences = singleTargetReferences; this.errorOccurred = errorOccurred; } + + @Override + public String toString() { + return "GroupedTargetReferences{" + "poppedTargetReferences=" + poppedTargetReferences + + ", singleTargetReferences=" + singleTargetReferences + ", errorOccurred=" + errorOccurred + '}'; + } } /** @@ -730,19 +736,26 @@ private GroupedTargetReferences(Map> poppedTargetRef */ private static class GroupedSourceReferences { - private final Map> groupedBySourceReferences; - private final Set nonNested; - private final Set notProcessedAppliesToAll; - private final Set sourceParameterMappings; + private final Map> groupedBySourceReferences; + private final Set nonNested; + private final Set notProcessedAppliesToAll; + private final Set sourceParameterMappings; - private GroupedSourceReferences(Map> groupedBySourceReferences, - Set nonNested, Set notProcessedAppliesToAll, - Set sourceParameterMappings) { + private GroupedSourceReferences(Map> groupedBySourceReferences, + Set nonNested, Set notProcessedAppliesToAll, + Set sourceParameterMappings) { this.groupedBySourceReferences = groupedBySourceReferences; this.nonNested = nonNested; this.notProcessedAppliesToAll = notProcessedAppliesToAll; this.sourceParameterMappings = sourceParameterMappings; } + + @Override + public String toString() { + return "GroupedSourceReferences{" + "groupedBySourceReferences=" + groupedBySourceReferences + + ", nonNested=" + nonNested + ", notProcessedAppliesToAll=" + notProcessedAppliesToAll + + ", sourceParameterMappings=" + sourceParameterMappings + '}'; + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 9c6bb49de8..0a11473b7d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Set; import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.assignment.AdderWrapper; import org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper; @@ -28,14 +27,11 @@ 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.model.source.MappingOptions; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; -import org.mapstruct.ap.internal.model.source.PropertyEntry; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.model.source.SourceReference; +import org.mapstruct.ap.internal.model.beanmapping.SourceReference; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; @@ -50,6 +46,9 @@ import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; +import static org.mapstruct.ap.internal.model.ForgedMethod.forParameterMapping; +import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; +import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; import static org.mapstruct.ap.internal.util.Collections.first; @@ -158,7 +157,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase emptyList(), - ParameterProvidedMethods.empty() ); + Type sourceParameterType = sourceReference.getParameter().getType(); + ForgedMethod methodRef = forParameterMapping( forgedName, sourceParameterType, sourceType, method ); NestedPropertyMappingMethod.Builder builder = new NestedPropertyMappingMethod.Builder(); NestedPropertyMappingMethod nestedPropertyMapping = builder @@ -628,25 +618,23 @@ private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { return sourcePresenceChecker; } - private Assignment forgeStreamMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + private Assignment forgeStreamMapping(Type sourceType, Type targetType, SourceRHS source) { StreamMappingMethod.Builder builder = new StreamMappingMethod.Builder(); - return forgeWithElementMapping( sourceType, targetType, source, element, builder ); + return forgeWithElementMapping( sourceType, targetType, source, builder ); } - private Assignment forgeIterableMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + private Assignment forgeIterableMapping(Type sourceType, Type targetType, SourceRHS source) { IterableMappingMethod.Builder builder = new IterableMappingMethod.Builder(); - return forgeWithElementMapping( sourceType, targetType, source, element, builder ); + return forgeWithElementMapping( sourceType, targetType, source, builder ); } private Assignment forgeWithElementMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element, ContainerMappingMethodBuilder builder) { + ContainerMappingMethodBuilder builder) { targetType = targetType.withoutBounds(); - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "[]" ); + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "[]" ); ContainerMappingMethod iterableMappingMethod = builder .mappingContext( ctx ) @@ -658,32 +646,19 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou return createForgedAssignment( source, methodRef, iterableMappingMethod ); } - private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element, String suffix) { + private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, String suffix) { String name = getName( sourceType, targetType ); name = Strings.getSafeVariableName( name, ctx.getReservedNames() ); // copy mapper configuration from the source method, its the same mapper - MapperConfiguration config = method.getMapperConfiguration(); - return new ForgedMethod( - name, - sourceType, - targetType, - config, - element, - method.getContextParameters(), - method.getContextProvidedMethods(), - getForgedMethodHistory( source, suffix ), - null, - forgedNamedBased - ); + ForgedMethodHistory forgedMethodHistory = getForgedMethodHistory( source, suffix ); + return forElementMapping( name, sourceType, targetType, method, forgedMethodHistory, forgedNamedBased ); } - private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source, - ExecutableElement element) { + private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS source) { targetType = targetType.withoutBounds(); - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, element, "{}" ); + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "{}" ); MapMappingMethod.Builder builder = new MapMappingMethod.Builder(); MapMappingMethod mapMappingMethod = builder @@ -729,16 +704,13 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { else { returnType = targetType; } - ForgedMethod forgedMethod = new ForgedMethod( - name, + ForgedMethod forgedMethod = forPropertyMapping( name, sourceType, returnType, - method.getMapperConfiguration(), - method.getExecutable(), parameters, - method.getContextProvidedMethods(), + method, getForgedMethodHistory( sourceRHS ), - forgeMethodWithMappingOptions, + forgeMethodWithMappingReferences, forgedNamedBased ); return createForgedAssignment( sourceRHS, targetBuilderType, forgedMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index c05d9bdb2b..7c05ac5813 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -16,8 +16,6 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Parameter; -import org.mapstruct.ap.internal.model.source.ForgedMethod; -import org.mapstruct.ap.internal.model.source.ForgedMethodHistory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.ValueMapping; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java new file mode 100644 index 0000000000..3e02617b19 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java @@ -0,0 +1,95 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.beanmapping; + +import java.util.Objects; + +import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.util.Strings; + +/** + * Represents the intermediate (nesting) state of the {@link Mapping} in this class. + */ +public class MappingReference { + + private Mapping mapping; + + private TargetReference targetReference; + + private SourceReference sourceReference; + + public MappingReference(Mapping mapping, TargetReference targetReference, SourceReference sourceReference) { + this.mapping = mapping; + this.targetReference = targetReference; + this.sourceReference = sourceReference; + } + + public Mapping getMapping() { + return mapping; + } + + public SourceReference getSourceReference() { + return sourceReference; + } + + public void setSourceReference(SourceReference sourceReference) { + this.sourceReference = sourceReference; + } + + public TargetReference getTargetReference() { + return targetReference; + } + + public MappingReference popTargetReference() { + if ( targetReference != null ) { + TargetReference newTargetReference = targetReference.pop(); + if (newTargetReference != null ) { + return new MappingReference(mapping, newTargetReference, sourceReference ); + } + } + return null; + } + + public MappingReference popSourceReference() { + if ( sourceReference != null ) { + SourceReference newSourceReference = sourceReference.pop(); + if (newSourceReference != null ) { + return new MappingReference(mapping, targetReference, newSourceReference ); + } + } + return null; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + MappingReference that = (MappingReference) o; + return mapping.equals( that.mapping ); + } + + @Override + public int hashCode() { + return Objects.hash( mapping ); + } + + @Override + public String toString() { + String targetRefName = Strings.join( targetReference.getElementNames(), "." ); + String sourceRefName = "null"; + if ( sourceReference != null ) { + sourceRefName = Strings.join( sourceReference.getElementNames(), "." ); + } + return "MappingReference {" + + "\n sourceRefName='" + sourceRefName + "\'," + + "\n targetRefName='" + targetRefName + "\'," + + "\n}"; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java new file mode 100644 index 0000000000..ee5e9f3676 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -0,0 +1,129 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.beanmapping; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.util.FormattingMessager; + +public class MappingReferences { + + private static final MappingReferences EMPTY = new MappingReferences( Collections.emptySet(), false ); + + private final Set mappingReferences; + private final boolean restrictToDefinedMappings; + private final boolean forForgedMethods; + + public static MappingReferences empty() { + return EMPTY; + } + + public static MappingReferences forSourceMethod(SourceMethod sourceMethod, FormattingMessager messager, + TypeFactory typeFactory) { + + Set mappings = sourceMethod.getMappingOptions().getMappings(); + + + Set references = new LinkedHashSet<>(); + for ( Mapping mapping : sourceMethod.getMappingOptions().getMappings() ) { + + // handle source reference + SourceReference sourceReference = new SourceReference.BuilderFromMapping().mapping( mapping ) + .method( sourceMethod ) + .messager( messager ) + .typeFactory( typeFactory ) + .build(); + + // handle target reference + TargetReference targetReference = new TargetReference.BuilderFromTargetMapping().mapping( mapping ) + .method( sourceMethod ) + .messager( messager ) + .typeFactory( typeFactory ) + .build(); + + // add when inverse is also valid + MappingReference mappingReference = new MappingReference( mapping, targetReference, sourceReference ); + if ( isValidWhenInversed( mappingReference ) ) { + references.add( mappingReference ); + } + } + return new MappingReferences( references, false ); + } + + public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings) { + this.mappingReferences = mappingReferences; + this.restrictToDefinedMappings = restrictToDefinedMappings; + this.forForgedMethods = restrictToDefinedMappings; + } + + public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings, + boolean forForgedMethods) { + this.mappingReferences = mappingReferences; + this.restrictToDefinedMappings = restrictToDefinedMappings; + this.forForgedMethods = forForgedMethods; + } + + public Set getMappingReferences() { + return mappingReferences; + } + + public boolean isRestrictToDefinedMappings() { + return restrictToDefinedMappings; + } + + public boolean isForForgedMethods() { + return forForgedMethods; + } + + /** + * @return all dependencies to other properties the contained mappings are dependent on + */ + public Set collectNestedDependsOn() { + + Set nestedDependsOn = new LinkedHashSet<>(); + for ( MappingReference mapping : getMappingReferences() ) { + nestedDependsOn.addAll( mapping.getMapping().getDependsOn() ); + } + return nestedDependsOn; + } + + /** + * Check there are nested target references for this mapping options. + * + * @return boolean, true if there are nested target references + */ + public boolean hasNestedTargetReferences() { + + for ( MappingReference mappingRef : mappingReferences ) { + TargetReference targetReference = mappingRef.getTargetReference(); + if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { + return true; + } + + } + return false; + } + + + /** + * MapStruct filters automatically inversed invalid methods out. TODO: this is a principle we should discuss! + * @param mappingRef + * @return + */ + private static boolean isValidWhenInversed(MappingReference mappingRef) { + Mapping mapping = mappingRef.getMapping(); + if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { + return mappingRef.getTargetReference().isValid() && ( mappingRef.getSourceReference() == null || + mappingRef.getSourceReference().isValid() ); + } + return true; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java similarity index 98% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java index 8f2a6f0bba..38335f2c55 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model.beanmapping; import java.util.Arrays; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java similarity index 98% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 8b4a28d524..97bbb228e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -3,9 +3,9 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model.beanmapping; -import static org.mapstruct.ap.internal.model.source.PropertyEntry.forSourceReference; +import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; @@ -20,6 +20,9 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java similarity index 98% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index 4a25a0e866..bce6d43ed8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source; +package org.mapstruct.ap.internal.model.beanmapping; import java.util.ArrayList; import java.util.Arrays; @@ -16,6 +16,9 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.BeanMapping; +import org.mapstruct.ap.internal.model.source.Mapping; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/package-info.java new file mode 100644 index 0000000000..e616342c6f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/package-info.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +/** + *

      + * helper classes used in {@link org.mapstruct.ap.internal.model.BeanMappingMethod} + *

      + */package org.mapstruct.ap.internal.model.beanmapping; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index d28205ca09..fd96c14c21 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.Collections; import java.util.List; import java.util.Optional; import javax.lang.model.element.ExecutableElement; @@ -114,25 +113,6 @@ public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElem ); } - /** - * This method should be used to generate BeanMappings for our internal generated Mappings. Like forged update - * methods. - * - * @return bean mapping that needs to be used for Mappings - */ - public static BeanMapping forForgedMethods() { - return new BeanMapping( - null, - null, - null, - null, - ReportingPolicyPrism.IGNORE, - false, - Collections.emptyList(), - null - ); - } - private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, NullValuePropertyMappingStrategyPrism nvpms, NullValueCheckStrategyPrism nvcs, ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index c2fe0a4e26..fabd444fc2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -25,10 +25,9 @@ import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; -import org.mapstruct.ap.internal.util.Strings; /** - * Represents a property mapping as configured via {@code @Mapping}. + * Represents a property mapping as configured via {@code @Mapping} (no intermediate state). * * @author Gunnar Morling */ @@ -56,8 +55,6 @@ public class Mapping { private final NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy; private final InheritContext inheritContext; - private SourceReference sourceReference; - private TargetReference targetReference; public static class InheritContext { @@ -297,50 +294,6 @@ private Mapping(String sourceName, String constant, String javaExpression, Strin this.inheritContext = inheritContext; } - private Mapping( Mapping mapping, TargetReference targetReference ) { - this.sourceName = mapping.sourceName; - this.constant = mapping.constant; - this.javaExpression = mapping.javaExpression; - this.defaultJavaExpression = mapping.defaultJavaExpression; - this.targetName = Strings.join( targetReference.getElementNames(), "." ); - this.defaultValue = mapping.defaultValue; - this.isIgnored = mapping.isIgnored; - this.mirror = mapping.mirror; - this.sourceAnnotationValue = mapping.sourceAnnotationValue; - this.targetAnnotationValue = mapping.targetAnnotationValue; - this.formattingParameters = mapping.formattingParameters; - this.selectionParameters = mapping.selectionParameters; - this.dependsOnAnnotationValue = mapping.dependsOnAnnotationValue; - this.dependsOn = mapping.dependsOn; - this.sourceReference = mapping.sourceReference; - this.targetReference = targetReference; - this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; - this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; - this.inheritContext = mapping.inheritContext; - } - - private Mapping( Mapping mapping, SourceReference sourceReference ) { - this.sourceName = Strings.join( sourceReference.getElementNames(), "." ); - this.constant = mapping.constant; - this.javaExpression = mapping.javaExpression; - this.defaultJavaExpression = mapping.defaultJavaExpression; - this.targetName = mapping.targetName; - this.defaultValue = mapping.defaultValue; - this.isIgnored = mapping.isIgnored; - this.mirror = mapping.mirror; - this.sourceAnnotationValue = mapping.sourceAnnotationValue; - this.targetAnnotationValue = mapping.targetAnnotationValue; - this.formattingParameters = mapping.formattingParameters; - this.selectionParameters = mapping.selectionParameters; - this.dependsOnAnnotationValue = mapping.dependsOnAnnotationValue; - this.dependsOn = mapping.dependsOn; - this.sourceReference = sourceReference; - this.targetReference = mapping.targetReference; - this.nullValueCheckStrategy = mapping.nullValueCheckStrategy; - this.nullValuePropertyMappingStrategy = mapping.nullValuePropertyMappingStrategy; - this.inheritContext = mapping.inheritContext; - } - private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, FormattingMessager messager) { if ( mappingPrism.expression().isEmpty() ) { @@ -457,41 +410,6 @@ public InheritContext getInheritContext() { //// mutable properties - public SourceReference getSourceReference() { - return sourceReference; - } - - public void setSourceReference(SourceReference sourceReference) { - this.sourceReference = sourceReference; - } - - public TargetReference getTargetReference() { - return targetReference; - } - - public void setTargetReference(TargetReference targetReference) { - this.targetReference = targetReference; - } - - public Mapping popTargetReference() { - if ( targetReference != null ) { - TargetReference newTargetReference = targetReference.pop(); - if (newTargetReference != null ) { - return new Mapping(this, newTargetReference ); - } - } - return null; - } - - public Mapping popSourceReference() { - if ( sourceReference != null ) { - SourceReference newSourceReference = sourceReference.pop(); - if (newSourceReference != null ) { - return new Mapping(this, newSourceReference ); - } - } - return null; - } /** * mapping can only be inversed if the source was not a constant nor an expression nor a nested property diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 228de8e10b..95a93b422a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -29,25 +29,23 @@ public class MappingOptions { null, null, null, - Collections.emptyList(), - false + Collections.emptyList() ); + private Set mappings; private IterableMapping iterableMapping; private MapMapping mapMapping; private BeanMapping beanMapping; private List valueMappings; private boolean fullyInitialized; - private final boolean restrictToDefinedMappings; public MappingOptions(Set mappings, IterableMapping iterableMapping, MapMapping mapMapping, - BeanMapping beanMapping, List valueMappings, boolean restrictToDefinedMappings ) { + BeanMapping beanMapping, List valueMappings ) { this.mappings = mappings; this.iterableMapping = iterableMapping; this.mapMapping = mapMapping; this.beanMapping = beanMapping; this.valueMappings = valueMappings; - this.restrictToDefinedMappings = restrictToDefinedMappings; } /** @@ -59,38 +57,6 @@ public static MappingOptions empty() { return EMPTY; } - /** - * creates mapping options with only regular mappings - * - * @param mappings regular mappings to add - * @param restrictToDefinedMappings whether to restrict the mappings only to the defined mappings - * @return MappingOptions with only regular mappings - */ - public static MappingOptions forMappingsOnly(Set mappings, boolean restrictToDefinedMappings) { - return forMappingsOnly( mappings, restrictToDefinedMappings, restrictToDefinedMappings ); - } - - /** - * creates mapping options with only regular mappings - * - * @param mappings regular mappings to add - * @param restrictToDefinedMappings whether to restrict the mappings only to the defined mappings - * @param forForgedMethods whether the mappings are for forged methods - * @return MappingOptions with only regular mappings - */ - public static MappingOptions forMappingsOnly(Set mappings, - boolean restrictToDefinedMappings, boolean forForgedMethods) { - return new MappingOptions( - mappings, - null, - null, - forForgedMethods ? BeanMapping.forForgedMethods() : null, - Collections.emptyList(), - restrictToDefinedMappings - ); - - } - /** * @return the {@link Mapping}s configured for this method, keyed by target property name. Only for enum mapping * methods a target will be mapped by several sources. TODO. Remove the value list when 2.0 @@ -99,35 +65,6 @@ public Set getMappings() { return mappings; } - /** - * Check there are nested target references for this mapping options. - * - * @return boolean, true if there are nested target references - */ - public boolean hasNestedTargetReferences() { - - for ( Mapping mapping : mappings ) { - TargetReference targetReference = mapping.getTargetReference(); - if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { - return true; - } - - } - return false; - } - - /** - * @return all dependencies to other properties the contained mappings are dependent on - */ - public Set collectNestedDependsOn() { - - Set nestedDependsOn = new LinkedHashSet<>(); - for ( Mapping mapping : mappings ) { - nestedDependsOn.addAll( mapping.getDependsOn() ); - } - return nestedDependsOn; - } - public IterableMapping getIterableMapping() { return iterableMapping; } @@ -276,8 +213,4 @@ private String[] getPropertyEntries( Mapping mapping ) { return mapping.getTargetName().split( "\\." ); } - public boolean isRestrictToDefinedMappings() { - return restrictToDefinedMappings; - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index a6a4b9fef8..9b1ef4aa0c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -177,7 +177,7 @@ public SourceMethod build() { } MappingOptions mappingOptions = - new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings, false ); + new MappingOptions( mappings, iterableMapping, mapMapping, beanMapping, valueMappings ); return new SourceMethod( this, mappingOptions ); } @@ -391,37 +391,6 @@ public String toString() { return sb.toString(); } - // TODO remove? - /** - * Returns the {@link Mapping}s for the given source property. - * - * @param sourcePropertyName the source property name - * @return list of mappings - */ - public List getMappingBySourcePropertyName(String sourcePropertyName) { - List mappingsOfSourceProperty = new ArrayList<>(); - - for ( Mapping mapping : mappingOptions.getMappings() ) { - - if ( isEnumMapping( this ) ) { - if ( mapping.getSourceName().equals( sourcePropertyName ) ) { - mappingsOfSourceProperty.add( mapping ); - } - } - else { - List sourceEntries = mapping.getSourceReference().getPropertyEntries(); - - // there can only be a mapping if there's only one entry for a source property, so: param.property. - // There can be no mapping if there are more entries. So: param.property.property2 - if ( sourceEntries.size() == 1 && sourcePropertyName.equals( first( sourceEntries ).getName() ) ) { - mappingsOfSourceProperty.add( mapping ); - } - } - } - - return mappingsOfSourceProperty; - } - public List getApplicablePrototypeMethods() { if ( applicablePrototypeMethods == null ) { applicablePrototypeMethods = new ArrayList<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java index ab27029099..f59fc2f2f3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/package-info.java @@ -7,6 +7,10 @@ *

      * Intermediary representation of mapping methods as retrieved from via the annotation processing API. The intermediary * representation is then processed into the mapper model representation. + * + * This intermediary presentation is primarily constructed in the + * {@link org.mapstruct.ap.internal.processor.MapperCreationProcessor} and used + * in the {@link org.mapstruct.ap.internal.processor.MapperCreationProcessor} *

      */ package org.mapstruct.ap.internal.model.source; From e12f9ffd7b906da4649d8c22903589f2ac3df67a Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Fri, 13 Sep 2019 19:41:06 +0200 Subject: [PATCH 0383/1006] Refactoring of BeanMapping and Source/TargetReferences (common base class) (#1903) --- .../ap/internal/model/BeanMappingMethod.java | 277 ++++++++---------- .../ap/internal/model/PropertyMapping.java | 15 +- .../model/beanmapping/AbstractReference.java | 132 +++++++++ .../model/beanmapping/MappingReference.java | 19 +- .../model/beanmapping/MappingReferences.java | 15 +- .../model/beanmapping/SourceReference.java | 83 +----- .../model/beanmapping/TargetReference.java | 45 +-- .../ap/test/dependency/OrderingTest.java | 4 +- .../SuggestMostSimilarNameTest.java | 4 +- .../PersonGarageWrongSourceMapper.java | 13 +- 10 files changed, 320 insertions(+), 287 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 8c55047ede..f5ddf3867b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -19,7 +19,6 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; -import java.util.function.Function; import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; @@ -52,7 +51,6 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import static org.mapstruct.ap.internal.model.source.Mapping.getMappingByTargetName; import static org.mapstruct.ap.internal.model.beanmapping.MappingReferences.forSourceMethod; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; @@ -88,7 +86,6 @@ public static class Builder { private final Set unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); - private Function singleMapping; private MappingReferences mappingReferences; @@ -103,15 +100,12 @@ public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { } public Builder sourceMethod(SourceMethod sourceMethod) { - singleMapping = - targetName -> getMappingByTargetName( targetName, sourceMethod.getMappingOptions().getMappings() ); this.method = sourceMethod; this.mappingReferences = forSourceMethod( sourceMethod, ctx.getMessager(), ctx.getTypeFactory() ); return this; } public Builder forgedMethod(ForgedMethod forgedMethod) { - singleMapping = targetPropertyName -> null; this.method = forgedMethod; mappingReferences = forgedMethod.getMappingReferences(); Parameter sourceParameter = first( Parameter.getSourceParameters( forgedMethod.getParameters() ) ); @@ -320,12 +314,14 @@ private void handleUnprocessedDefinedTargets() { .name( propertyName ) .build(); + Accessor targetPropertyReadAccessor = + method.getResultType().getPropertyReadAccessors().get( propertyName ); MappingReferences mappingRefs = extractMappingReferences( propertyName, true ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) .targetWriteAccessor( unprocessedTargetProperties.get( propertyName ) ) - .targetReadAccessor( getTargetPropertyReadAccessor( propertyName ) ) + .targetReadAccessor( targetPropertyReadAccessor ) .targetPropertyName( propertyName ) .sourceReference( reference ) .existingVariableNames( existingVariableNames ) @@ -480,18 +476,16 @@ private boolean handleDefinedMappings() { } for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { - TargetReference targetReference = mapping.getTargetReference(); - if ( targetReference.isValid() ) { - String target = first( targetReference.getPropertyEntries() ).getFullName(); + if ( mapping.isValid() ) { + String target = mapping.getTargetReference().getShallowestPropertyName(); if ( !handledTargets.contains( target ) ) { if ( handleDefinedMapping( mapping, handledTargets ) ) { errorOccurred = true; } } - if ( mapping.getSourceReference() != null && mapping.getSourceReference().isValid() ) { - List sourceEntries = mapping.getSourceReference().getPropertyEntries(); - if ( !sourceEntries.isEmpty() ) { - String source = first( sourceEntries ).getFullName(); + if ( mapping.getSourceReference() != null ) { + String source = mapping.getSourceReference().getShallowestPropertyName(); + if ( source != null ) { unprocessedSourceProperties.remove( source ); } } @@ -558,6 +552,11 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Set ha } } + // check if source / expression / constant are not somehow handled already + if ( unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { + return false; + } + // check the mapping options // its an ignored property mapping if ( mapping.isIgnored() ) { @@ -565,44 +564,10 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Set ha handledTargets.add( targetProperty.getName() ); } - // its a plain-old property mapping - else if ( mapping.getSourceName() != null ) { - - // determine source parameter - SourceReference sourceRef = mappingRef.getSourceReference(); - if ( sourceRef.isValid() ) { - - // targetProperty == null can occur: we arrived here because we want as many errors - // as possible before we stop analysing - propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .targetProperty( targetProperty ) - .targetPropertyName( targetPropertyName ) - .sourcePropertyName( mapping.getSourceName() ) - .sourceReference( sourceRef ) - .selectionParameters( mapping.getSelectionParameters() ) - .formattingParameters( mapping.getFormattingParameters() ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mapping.getDependsOn() ) - .defaultValue( mapping.getDefaultValue() ) - .defaultJavaExpression( mapping.getDefaultJavaExpression() ) - .mirror( mapping.getMirror() ) - .nullValueCheckStrategy( mapping.getNullValueCheckStrategy() ) - .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) - .build(); - handledTargets.add( targetPropertyName ); - unprocessedSourceParameters.remove( sourceRef.getParameter() ); - } - else { - errorOccured = true; - } - } - // its a constant // if we have an unprocessed target that means that it most probably is nested and we should // not generated any mapping for it now. Eventually it will be done though - else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { + else if ( mapping.getConstant() != null ) { propertyMapping = new ConstantMappingBuilder() .mappingContext( ctx ) @@ -622,8 +587,7 @@ else if ( mapping.getConstant() != null && !unprocessedDefinedTargets.containsKe // its an expression // if we have an unprocessed target that means that it most probably is nested and we should // not generated any mapping for it now. Eventually it will be done though - else if ( mapping.getJavaExpression() != null - && !unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { + else if ( mapping.getJavaExpression() != null ) { propertyMapping = new JavaExpressionMappingBuilder() .mappingContext( ctx ) @@ -637,7 +601,43 @@ else if ( mapping.getJavaExpression() != null .build(); handledTargets.add( targetPropertyName ); } + // its a plain-old property mapping + else { + + // determine source parameter + SourceReference sourceRef = mappingRef.getSourceReference(); + if ( sourceRef == null && method.getSourceParameters().size() == 1 ) { + sourceRef = getSourceRef( method.getSourceParameters().get( 0 ), targetPropertyName ); + } + + if ( sourceRef.isValid() ) { + // targetProperty == null can occur: we arrived here because we want as many errors + // as possible before we stop analysing + propertyMapping = new PropertyMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .targetProperty( targetProperty ) + .targetPropertyName( targetPropertyName ) + .sourcePropertyName( mapping.getSourceName() ) + .sourceReference( sourceRef ) + .selectionParameters( mapping.getSelectionParameters() ) + .formattingParameters( mapping.getFormattingParameters() ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mapping.getDependsOn() ) + .defaultValue( mapping.getDefaultValue() ) + .defaultJavaExpression( mapping.getDefaultJavaExpression() ) + .mirror( mapping.getMirror() ) + .nullValueCheckStrategy( mapping.getNullValueCheckStrategy() ) + .nullValuePropertyMappingStrategy( mapping.getNullValuePropertyMappingStrategy() ) + .build(); + handledTargets.add( targetPropertyName ); + unprocessedSourceParameters.remove( sourceRef.getParameter() ); + } + else { + errorOccured = true; + } + } // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers if ( propertyMapping != null ) { propertyMappings.add( propertyMapping ); @@ -653,91 +653,60 @@ else if ( mapping.getJavaExpression() != null * the set of remaining target properties. */ private void applyPropertyNameBasedMapping() { - - Iterator> targetPropertyEntriesIterator = - unprocessedTargetProperties.entrySet().iterator(); - - while ( targetPropertyEntriesIterator.hasNext() ) { - - Entry targetProperty = targetPropertyEntriesIterator.next(); - String targetPropertyName = targetProperty.getKey(); - - PropertyMapping propertyMapping = null; - - if ( propertyMapping == null ) { - - for ( Parameter sourceParameter : method.getSourceParameters() ) { - - Type sourceType = sourceParameter.getType(); - - if ( sourceType.isPrimitive() || sourceType.isArrayType() ) { - continue; - } - - PropertyMapping newPropertyMapping = null; - - Accessor sourceReadAccessor = - sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); - - Accessor sourcePresenceChecker = - sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); - - if ( sourceReadAccessor != null ) { - Mapping mapping = singleMapping.apply( targetProperty.getKey() ); - DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); - - SourceReference sourceRef = new SourceReference.BuilderFromProperty() - .sourceParameter( sourceParameter ) - .type( ctx.getTypeFactory().getReturnType( declaredSourceType, sourceReadAccessor ) ) - .readAccessor( sourceReadAccessor ) - .presenceChecker( sourcePresenceChecker ) - .name( targetProperty.getKey() ) - .build(); - - MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); - newPropertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .targetWriteAccessor( targetProperty.getValue() ) - .targetReadAccessor( getTargetPropertyReadAccessor( targetPropertyName ) ) - .targetPropertyName( targetPropertyName ) - .sourceReference( sourceRef ) - .formattingParameters( mapping != null ? mapping.getFormattingParameters() : null ) - .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) - .defaultValue( mapping != null ? mapping.getDefaultValue() : null ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) - .forgeMethodWithMappingReferences( mappingRefs ) - .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) - .nullValuePropertyMappingStrategy( mapping != null ? - mapping.getNullValuePropertyMappingStrategy() : null ) - .mirror( mapping != null ? mapping.getMirror() : null ) - .build(); - - unprocessedSourceParameters.remove( sourceParameter ); - } - - if ( propertyMapping != null && newPropertyMapping != null ) { - // TODO improve error message - ctx.getMessager().printMessage( - method.getExecutable(), - Message.BEANMAPPING_SEVERAL_POSSIBLE_SOURCES, - targetPropertyName - ); - break; - } - else if ( newPropertyMapping != null ) { - propertyMapping = newPropertyMapping; - } + List sourceReferences = new ArrayList<>(); + for ( String targetPropertyName : unprocessedTargetProperties.keySet() ) { + for ( Parameter sourceParameter : method.getSourceParameters() ) { + SourceReference sourceRef = getSourceRef( sourceParameter, targetPropertyName ); + if ( sourceRef != null ) { + sourceReferences.add( sourceRef ); } } + } + applyPropertyNameBasedMapping( sourceReferences ); + } + + /** + * Iterates over all target properties and all source parameters. + *

      + * When a property name match occurs, the remainder will be checked for duplicates. Matches will be removed from + * the set of remaining target properties. + */ + private void applyPropertyNameBasedMapping(List sourceReferences) { + + for ( SourceReference sourceRef : sourceReferences ) { + + String targetPropertyName = sourceRef.getDeepestPropertyName(); + Accessor targetPropertyWriteAccessor = unprocessedTargetProperties.remove( targetPropertyName ); + if ( targetPropertyWriteAccessor == null ) { + // TODO improve error message + ctx.getMessager() + .printMessage( method.getExecutable(), + Message.BEANMAPPING_SEVERAL_POSSIBLE_SOURCES, + targetPropertyName + ); + continue; + } + + Accessor targetPropertyReadAccessor = + method.getResultType().getPropertyReadAccessors().get( targetPropertyName ); + MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); + PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) + .sourceMethod( method ) + .targetWriteAccessor( targetPropertyWriteAccessor ) + .targetReadAccessor( targetPropertyReadAccessor ) + .targetPropertyName( targetPropertyName ) + .sourceReference( sourceRef ) + .existingVariableNames( existingVariableNames ) + .forgeMethodWithMappingReferences( mappingRefs ) + .build(); + + unprocessedSourceParameters.remove( sourceRef.getParameter() ); if ( propertyMapping != null ) { propertyMappings.add( propertyMapping ); - targetPropertyEntriesIterator.remove(); - unprocessedDefinedTargets.remove( targetPropertyName ); - unprocessedSourceProperties.remove( targetPropertyName ); } + unprocessedDefinedTargets.remove( targetPropertyName ); + unprocessedSourceProperties.remove( targetPropertyName ); } } @@ -756,30 +725,24 @@ private void applyParameterNameBasedMapping() { Parameter sourceParameter = sourceParameters.next(); if ( sourceParameter.getName().equals( targetProperty.getKey() ) ) { - Mapping mapping = singleMapping.apply( targetProperty.getKey() ); SourceReference sourceRef = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) .name( targetProperty.getKey() ) .build(); + Accessor targetPropertyReadAccessor = + method.getResultType().getPropertyReadAccessors().get( targetProperty.getKey() ); MappingReferences mappingRefs = extractMappingReferences( targetProperty.getKey(), false ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) .targetWriteAccessor( targetProperty.getValue() ) - .targetReadAccessor( getTargetPropertyReadAccessor( targetProperty.getKey() ) ) + .targetReadAccessor( targetPropertyReadAccessor ) .targetPropertyName( targetProperty.getKey() ) .sourceReference( sourceRef ) - .formattingParameters( mapping != null ? mapping.getFormattingParameters() : null ) - .selectionParameters( mapping != null ? mapping.getSelectionParameters() : null ) .existingVariableNames( existingVariableNames ) - .dependsOn( mapping != null ? mapping.getDependsOn() : Collections.emptySet() ) .forgeMethodWithMappingReferences( mappingRefs ) - .nullValueCheckStrategy( mapping != null ? mapping.getNullValueCheckStrategy() : null ) - .nullValuePropertyMappingStrategy( mapping != null ? - mapping.getNullValuePropertyMappingStrategy() : null ) - .mirror( mapping != null ? mapping.getMirror() : null ) .build(); propertyMappings.add( propertyMapping ); @@ -792,6 +755,33 @@ private void applyParameterNameBasedMapping() { } } + private SourceReference getSourceRef(Parameter sourceParameter, String targetPropertyName) { + + SourceReference sourceRef = null; + + if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() ) { + return sourceRef; + } + + Accessor sourceReadAccessor = + sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); + + Accessor sourcePresenceChecker = + sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); + + if ( sourceReadAccessor != null ) { + DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); + Type returnType = ctx.getTypeFactory().getReturnType( declaredSourceType, sourceReadAccessor ); + sourceRef = new SourceReference.BuilderFromProperty().sourceParameter( sourceParameter ) + .type( returnType ) + .readAccessor( sourceReadAccessor ) + .presenceChecker( sourcePresenceChecker ) + .name( targetPropertyName ) + .build(); + } + return sourceRef; + } + private MappingReferences extractMappingReferences(String targetProperty, boolean restrictToDefinedMappings) { if ( unprocessedDefinedTargets.containsKey( targetProperty ) ) { Set mappings = unprocessedDefinedTargets.get( targetProperty ); @@ -800,10 +790,6 @@ private MappingReferences extractMappingReferences(String targetProperty, boolea return null; } - private Accessor getTargetPropertyReadAccessor(String propertyName) { - return method.getResultType().getPropertyReadAccessors().get( propertyName ); - } - private ReportingPolicyPrism getUnmappedTargetPolicy() { if ( mappingReferences.isForForgedMethods() ) { return ReportingPolicyPrism.IGNORE; @@ -1034,10 +1020,5 @@ public boolean equals(Object obj) { return Objects.equals( propertyMappings, that.propertyMappings ); } - private interface SingleMappingByTargetPropertyNameFunction { - - Mapping getSingleMappingByTargetPropertyName(String targetPropertyName); - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 0a11473b7d..628d00cc4e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -51,8 +51,6 @@ import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; -import static org.mapstruct.ap.internal.util.Collections.first; -import static org.mapstruct.ap.internal.util.Collections.last; /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to @@ -519,10 +517,10 @@ private Assignment assignToArray(Type targetType, Assignment rightHandSide) { private SourceRHS getSourceRHS( SourceReference sourceReference ) { Parameter sourceParam = sourceReference.getParameter(); - List propertyEntries = sourceReference.getPropertyEntries(); + PropertyEntry propertyEntry = sourceReference.getDeepestProperty(); // parameter reference - if ( propertyEntries.isEmpty() ) { + if ( propertyEntry == null ) { return new SourceRHS( sourceParam.getName(), sourceParam.getType(), existingVariableNames, @@ -530,8 +528,7 @@ private SourceRHS getSourceRHS( SourceReference sourceReference ) { ); } // simple property - else if ( propertyEntries.size() == 1 ) { - PropertyEntry propertyEntry = propertyEntries.get( 0 ); + else if ( !sourceReference.isNested() ) { String sourceRef = sourceParam.getName() + "." + ValueProvider.of( propertyEntry.getReadAccessor() ); return new SourceRHS( sourceParam.getName(), sourceRef, @@ -543,7 +540,7 @@ else if ( propertyEntries.size() == 1 ) { } // nested property given as dot path else { - Type sourceType = last( propertyEntries ).getType(); + Type sourceType = propertyEntry.getType(); if ( sourceType.isPrimitive() && !targetType.isPrimitive() ) { // Handle null's. If the forged method needs to be mapped to an object, the forged method must be // able to return null. So in that case primitive types are mapped to their corresponding wrapped @@ -581,7 +578,7 @@ else if ( propertyEntries.size() == 1 ) { ); // create a local variable to which forged method can be assigned. - String desiredName = last( sourceReference.getPropertyEntries() ).getName(); + String desiredName = propertyEntry.getName(); sourceRhs.setSourceLocalVarName( sourceRhs.createUniqueVarName( desiredName ) ); return sourceRhs; @@ -595,7 +592,7 @@ private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { Parameter sourceParam = sourceReference.getParameter(); // TODO is first correct here?? shouldn't it be last since the remainer is checked // in the forged method? - PropertyEntry propertyEntry = first( sourceReference.getPropertyEntries() ); + PropertyEntry propertyEntry = sourceReference.getShallowestProperty(); if ( propertyEntry.getPresenceChecker() != null ) { sourcePresenceChecker = sourceParam.getName() + "." + propertyEntry.getPresenceChecker().getSimpleName() + "()"; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java new file mode 100644 index 0000000000..dcb67c903d --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java @@ -0,0 +1,132 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.beanmapping; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.util.Strings; + +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.last; + +/** + * Class acts as a common base class for {@link TargetReference} and {@link SourceReference}. + * + * @author sjaak + */ +public abstract class AbstractReference { + + private final Parameter parameter; + private final List propertyEntries; + private final boolean isValid; + + protected AbstractReference(Parameter sourceParameter, List sourcePropertyEntries, boolean isValid) { + this.parameter = sourceParameter; + this.propertyEntries = sourcePropertyEntries; + this.isValid = isValid; + } + + public Parameter getParameter() { + return parameter; + } + + public List getPropertyEntries() { + return propertyEntries; + } + + public boolean isValid() { + return isValid; + } + + public List getElementNames() { + List elementNames = new ArrayList<>(); + if ( parameter != null ) { + // only relevant for source properties + elementNames.add( parameter.getName() ); + } + for ( PropertyEntry propertyEntry : propertyEntries ) { + elementNames.add( propertyEntry.getName() ); + } + return elementNames; + } + + /** + * returns the property name on the shallowest nesting level + * @return + */ + public PropertyEntry getShallowestProperty() { + if ( propertyEntries.isEmpty() ) { + return null; + } + return first( propertyEntries ); + } + + /** + * returns the property name on the shallowest nesting level + * @return + */ + public String getShallowestPropertyName() { + if ( propertyEntries.isEmpty() ) { + return null; + } + return first( propertyEntries ).getName(); + } + + /** + * returns the property name on the deepest nesting level + * @return + */ + public PropertyEntry getDeepestProperty() { + if ( propertyEntries.isEmpty() ) { + return null; + } + return last( propertyEntries ); + } + + /** + * returns the property name on the deepest nesting level + * @return + */ + public String getDeepestPropertyName() { + if ( propertyEntries.isEmpty() ) { + return null; + } + return last( propertyEntries ).getName(); + } + + public boolean isNested() { + return propertyEntries.size() > 1; + } + + @Override + public String toString() { + + String result = ""; + if ( !isValid ) { + result = "invalid"; + } + else if ( propertyEntries.isEmpty() ) { + if ( parameter != null ) { + result = String.format( "parameter \"%s %s\"", parameter.getType(), parameter.getName() ); + } + } + else if ( propertyEntries.size() == 1 ) { + PropertyEntry propertyEntry = propertyEntries.get( 0 ); + result = String.format( "property \"%s %s\"", propertyEntry.getType(), propertyEntry.getName() ); + } + else { + PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 ); + result = String.format( + "property \"%s %s\"", + lastPropertyEntry.getType(), + Strings.join( getElementNames(), "." ) + ); + } + return result; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java index 3e02617b19..1ea5ff500e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java @@ -8,7 +8,6 @@ import java.util.Objects; import org.mapstruct.ap.internal.model.source.Mapping; -import org.mapstruct.ap.internal.util.Strings; /** * Represents the intermediate (nesting) state of the {@link Mapping} in this class. @@ -80,16 +79,24 @@ public int hashCode() { return Objects.hash( mapping ); } + public boolean isValid( ) { + boolean result = false; + if ( targetReference.isValid() ) { + result = sourceReference != null ? sourceReference.isValid() : true; + } + return result; + } + @Override public String toString() { - String targetRefName = Strings.join( targetReference.getElementNames(), "." ); - String sourceRefName = "null"; + String targetRefStr = targetReference.toString(); + String sourceRefStr = "null"; if ( sourceReference != null ) { - sourceRefName = Strings.join( sourceReference.getElementNames(), "." ); + sourceRefStr = sourceReference.toString(); } return "MappingReference {" - + "\n sourceRefName='" + sourceRefName + "\'," - + "\n targetRefName='" + targetRefName + "\'," + + "\n sourceReference='" + sourceRefStr + "\'," + + "\n targetReference='" + targetRefStr + "\'," + "\n}"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index ee5e9f3676..7cb9a142bb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -29,10 +29,9 @@ public static MappingReferences empty() { public static MappingReferences forSourceMethod(SourceMethod sourceMethod, FormattingMessager messager, TypeFactory typeFactory) { - Set mappings = sourceMethod.getMappingOptions().getMappings(); - - Set references = new LinkedHashSet<>(); + Set targetThisReferences = new LinkedHashSet<>(); + for ( Mapping mapping : sourceMethod.getMappingOptions().getMappings() ) { // handle source reference @@ -52,9 +51,15 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, Forma // add when inverse is also valid MappingReference mappingReference = new MappingReference( mapping, targetReference, sourceReference ); if ( isValidWhenInversed( mappingReference ) ) { - references.add( mappingReference ); + if ( targetReference.isTargetThis() ) { + targetThisReferences.add( mappingReference ); + } + else { + references.add( mappingReference ); + } } } + references.addAll( targetThisReferences ); return new MappingReferences( references, false ); } @@ -104,7 +109,7 @@ public boolean hasNestedTargetReferences() { for ( MappingReference mappingRef : mappingReferences ) { TargetReference targetReference = mappingRef.getTargetReference(); - if ( targetReference.isValid() && targetReference.getPropertyEntries().size() > 1 ) { + if ( targetReference.isValid() && targetReference.isNested()) { return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 97bbb228e1..5176f9b2ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.model.beanmapping; import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; -import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.last; import java.util.ArrayList; @@ -22,7 +21,6 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Mapping; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -50,11 +48,7 @@ * * @author Sjaak Derksen */ -public class SourceReference { - - private final Parameter parameter; - private final List propertyEntries; - private final boolean isValid; +public class SourceReference extends AbstractReference { /** * Builds a {@link SourceReference} from an {@code @Mappping}. @@ -371,88 +365,23 @@ public BuilderFromSourceReference sourceParameter(Parameter sourceParameter) { } public SourceReference build() { - return new SourceReference( sourceParameter, sourceReference.propertyEntries, true ); + return new SourceReference( sourceParameter, sourceReference.getPropertyEntries(), true ); } } private SourceReference(Parameter sourceParameter, List sourcePropertyEntries, boolean isValid) { - this.parameter = sourceParameter; - this.propertyEntries = sourcePropertyEntries; - this.isValid = isValid; - } - - public Parameter getParameter() { - return parameter; - } - - public List getPropertyEntries() { - return propertyEntries; - } - - public boolean isValid() { - return isValid; - } - - public List getElementNames() { - List sourceName = new ArrayList<>(); - sourceName.add( parameter.getName() ); - for ( PropertyEntry propertyEntry : propertyEntries ) { - sourceName.add( propertyEntry.getName() ); - } - return sourceName; - } - - /** - * Creates a copy of this reference, which is adapted to the given method - * - * @param method the method to create the copy for - * @return the copy - */ - public SourceReference copyForInheritanceTo(SourceMethod method) { - List replacementParamCandidates = new ArrayList<>(); - for ( Parameter sourceParam : method.getSourceParameters() ) { - if ( parameter != null && sourceParam.getType().isAssignableTo( parameter.getType() ) ) { - replacementParamCandidates.add( sourceParam ); - } - } - - Parameter replacement = parameter; - if ( replacementParamCandidates.size() == 1 ) { - replacement = first( replacementParamCandidates ); - } - - return new SourceReference( replacement, propertyEntries, isValid ); + super( sourceParameter, sourcePropertyEntries, isValid ); } public SourceReference pop() { - if ( propertyEntries.size() > 1 ) { + if ( getPropertyEntries().size() > 1 ) { List newPropertyEntries = - new ArrayList<>( propertyEntries.subList( 1, propertyEntries.size() ) ); - return new SourceReference( parameter, newPropertyEntries, isValid ); + new ArrayList<>( getPropertyEntries().subList( 1, getPropertyEntries().size() ) ); + return new SourceReference( getParameter(), newPropertyEntries, isValid() ); } else { return null; } } - @Override - public String toString() { - - if ( propertyEntries.isEmpty() ) { - return String.format( "parameter \"%s %s\"", getParameter().getType(), getParameter().getName() ); - } - else if ( propertyEntries.size() == 1 ) { - PropertyEntry propertyEntry = propertyEntries.get( 0 ); - return String.format( "property \"%s %s\"", propertyEntry.getType(), propertyEntry.getName() ); - } - else { - PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 ); - return String.format( - "property \"%s %s\"", - lastPropertyEntry.getType(), - Strings.join( getElementNames(), "." ) - ); - } - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index bce6d43ed8..b86c09dc4b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -51,12 +51,7 @@ * * @author Sjaak Derksen */ -public class TargetReference { - - private final Parameter parameter; - private final List propertyEntries; - private final boolean isValid; - +public class TargetReference extends AbstractReference { /** * Builds a {@link TargetReference} from an {@code @Mappping}. @@ -348,46 +343,24 @@ private boolean matchesSourceOnInverseSourceParameter( String segment, boolean i } } - private TargetReference(Parameter sourceParameter, List sourcePropertyEntries, boolean isValid) { - this.parameter = sourceParameter; - this.propertyEntries = sourcePropertyEntries; - this.isValid = isValid; - } - - public Parameter getParameter() { - return parameter; - } - - public List getPropertyEntries() { - return propertyEntries; - } - - public boolean isValid() { - return isValid; + private TargetReference(Parameter sourceParameter, List targetPropertyEntries, boolean isValid) { + super( sourceParameter, targetPropertyEntries, isValid ); } - public List getElementNames() { - List elementNames = new ArrayList<>(); - if ( parameter != null ) { - // only relevant for source properties - elementNames.add( parameter.getName() ); - } - for ( PropertyEntry propertyEntry : propertyEntries ) { - elementNames.add( propertyEntry.getName() ); - } - return elementNames; + public boolean isTargetThis() { + return getPropertyEntries().isEmpty(); } public TargetReference pop() { - if ( propertyEntries.size() > 1 ) { - List newPropertyEntries = new ArrayList<>( propertyEntries.size() - 1 ); - for ( PropertyEntry propertyEntry : propertyEntries ) { + if ( getPropertyEntries().size() > 1 ) { + List newPropertyEntries = new ArrayList<>( getPropertyEntries().size() - 1 ); + for ( PropertyEntry propertyEntry : getPropertyEntries() ) { PropertyEntry newPropertyEntry = propertyEntry.pop(); if ( newPropertyEntry != null ) { newPropertyEntries.add( newPropertyEntry ); } } - return new TargetReference( null, newPropertyEntries, isValid ); + return new TargetReference( null, newPropertyEntries, isValid() ); } else { return null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index 3faa85f78c..ede43320dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -63,8 +63,8 @@ public void shouldApplySeveralDependenciesConfiguredForOneProperty() { @Diagnostic(type = ErroneousAddressMapperWithCyclicDependency.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "Cycle\\(s\\) between properties given via dependsOn\\(\\): firstName -> lastName -> " - + "middleName -> firstName" + messageRegExp = "Cycle\\(s\\) between properties given via dependsOn\\(\\): lastName -> middleName -> " + + "firstName -> lastName" ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index 1c4c23bb91..dcf9451303 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -84,11 +84,11 @@ public void testGarageTargetSuggestion() { diagnostics = { @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 19, + line = 21, messageRegExp = "No property named \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 22, + line = 28, messageRegExp = "No property named \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java index ed8e6ec901..0fd3a06b0d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongSourceMapper.java @@ -7,6 +7,7 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.ap.test.namesuggestion.Person; import org.mapstruct.ap.test.namesuggestion.PersonDto; import org.mapstruct.factory.Mappers; @@ -16,10 +17,18 @@ public interface PersonGarageWrongSourceMapper { PersonGarageWrongSourceMapper MAPPER = Mappers.getMapper( PersonGarageWrongSourceMapper.class ); - @Mapping(source = "garage.colour.rgb", target = "garage.color.rgb") + @Mappings( { + @Mapping( target = "garage.color.rgb", source = "garage.colour.rgb" ), + @Mapping( target = "fullAge", source = "age" ), + @Mapping( target = "fullName", source = "name" ) + } ) Person mapPerson(PersonDto dto); - @Mapping(source = "garage.colour", target = "garage.color") + @Mappings( { + @Mapping( target = "garage.color", source = "garage.colour" ), + @Mapping( target = "fullAge", source = "age" ), + @Mapping( target = "fullName", source = "name" ) + } ) Person mapPersonGarage(PersonDto dto); } From e068564017fd1ad3b33db18df04d03d958af35f5 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 02:48:22 +0300 Subject: [PATCH 0384/1006] #724 Remove JaxbMapper from integration test (#1892) --- .../org/mapstruct/itest/jaxb/JaxbMapper.java | 40 ------------------- .../itest/jaxb/SourceTargetMapper.java | 3 +- 2 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/JaxbMapper.java diff --git a/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/JaxbMapper.java b/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/JaxbMapper.java deleted file mode 100644 index 445f5b37ce..0000000000 --- a/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/JaxbMapper.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.jaxb; - -import java.util.ArrayList; -import java.util.List; -import javax.xml.bind.JAXBElement; - -import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory; - -/** - * This class can be removed as soon as MapStruct is capable of generating List mappings. - * - * @author Sjaak Derksen - */ -public class JaxbMapper { - - private final ObjectFactory of = new ObjectFactory(); - - /** - * This method is needed, because currently MapStruct is not capable of selecting - * the proper factory method for Lists - * - * @param orderDetailsDescriptions - * - * @return - */ - List> toJaxbList(List orderDetailsDescriptions) { - - List> result = new ArrayList>(); - for ( String orderDetailDescription : orderDetailsDescriptions ) { - result.add( of.createOrderDetailsTypeDescription( orderDetailDescription ) ); - } - return result; - } - -} diff --git a/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/SourceTargetMapper.java b/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/SourceTargetMapper.java index 4fb4434a46..c0a56f8169 100644 --- a/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/jaxbTest/src/main/java/org/mapstruct/itest/jaxb/SourceTargetMapper.java @@ -20,8 +20,7 @@ @Mapper(uses = { org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory.class, org.mapstruct.itest.jaxb.xsd.test2.ObjectFactory.class, - org.mapstruct.itest.jaxb.xsd.underscores.ObjectFactory.class, - JaxbMapper.class + org.mapstruct.itest.jaxb.xsd.underscores.ObjectFactory.class }) public interface SourceTargetMapper { From f95648cef83f84f91522f039886b440d65961ba6 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 03:03:13 +0300 Subject: [PATCH 0385/1006] #1088 Refactor constructor ForgedMethod (#1888) --- .../java/org/mapstruct/ap/internal/model/ForgedMethod.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index 2f73c4b9ff..b385c127b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Objects; import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -57,7 +58,7 @@ public static ForgedMethod forParameterMapping(String name, Type sourceType, Typ name, sourceType, returnType, - Collections.emptyList(), + Collections.emptyList(), basedOn, null, MappingReferences.empty(), @@ -361,10 +362,10 @@ public boolean equals(Object o) { ForgedMethod that = (ForgedMethod) o; - if ( parameters != null ? !parameters.equals( that.parameters ) : that.parameters != null ) { + if ( !Objects.equals( parameters, that.parameters ) ) { return false; } - return returnType != null ? returnType.equals( that.returnType ) : that.returnType == null; + return Objects.equals( returnType, that.returnType ); } From 7af107c9f2707a54467d631ae33d47e6a0cd5940 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 03:24:43 +0300 Subject: [PATCH 0386/1006] #1883 Remove not used method "asCollectionOrMap" from TypeFactory (#1884) --- .../ap/internal/model/common/TypeFactory.java | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 1ec8077a88..0647834b81 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -380,7 +380,7 @@ public List getParameters(ExecutableType methodType, ExecutableElemen Iterator varIt = parameters.iterator(); Iterator typesIt = parameterTypes.iterator(); - for ( ; varIt.hasNext(); ) { + while ( varIt.hasNext() ) { VariableElement parameter = varIt.next(); TypeMirror parameterType = typesIt.next(); @@ -549,38 +549,6 @@ private TypeMirror getComponentType(TypeMirror mirror) { return arrayType.getComponentType(); } - /** - * Converts any collection type, e.g. {@code List} to {@code Collection} and any map type, e.g. - * {@code HashMap} to {@code Map}. - * - * @param collectionOrMap any collection or map type - * @return the type representing {@code Collection} or {@code Map}, if the argument type is a subtype of - * {@code Collection} or of {@code Map} respectively. - */ - public Type asCollectionOrMap(Type collectionOrMap) { - List originalParameters = collectionOrMap.getTypeParameters(); - TypeMirror[] originalParameterMirrors = new TypeMirror[originalParameters.size()]; - int i = 0; - for ( Type param : originalParameters ) { - originalParameterMirrors[i++] = param.getTypeMirror(); - } - - if ( collectionOrMap.isCollectionType() - && !"java.util.Collection".equals( collectionOrMap.getFullyQualifiedName() ) ) { - return getType( typeUtils.getDeclaredType( - elementUtils.getTypeElement( "java.util.Collection" ), - originalParameterMirrors ) ); - } - else if ( collectionOrMap.isMapType() - && !"java.util.Map".equals( collectionOrMap.getFullyQualifiedName() ) ) { - return getType( typeUtils.getDeclaredType( - elementUtils.getTypeElement( "java.util.Map" ), - originalParameterMirrors ) ); - } - - return collectionOrMap; - } - /** * creates a void return type * From 3868735da7e0a61f4511342ea2a1e38d29cc8c3c Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 03:43:27 +0300 Subject: [PATCH 0387/1006] #1897 Remove unused methods from class SourceMethod (#1898) --- .../ap/internal/model/source/SourceMethod.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 9b1ef4aa0c..32bd540f10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -15,7 +15,6 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Accessibility; -import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -77,7 +76,6 @@ public static class Builder { private ExecutableElement executable; private List parameters; private Type returnType = null; - private BuilderType builderType = null; private List exceptionTypes; private Set mappings; private IterableMapping iterableMapping = null; @@ -290,12 +288,6 @@ && first( getSourceParameters() ).getType().isAssignableTo( method.getResultType && getResultType().isAssignableTo( first( method.getSourceParameters() ).getType() ); } - public boolean isSame(SourceMethod method) { - return getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 - && equals( first( getSourceParameters() ).getType(), first( method.getSourceParameters() ).getType() ) - && equals( getResultType(), method.getResultType() ); - } - public boolean canInheritFrom(SourceMethod method) { return method.getDeclaringMapper() == null && method.isAbstract() @@ -373,10 +365,6 @@ public boolean isValueMapping() { return isValueMapping; } - private boolean equals(Object o1, Object o2) { - return (o1 == null && o2 == null) || (o1 != null) && o1.equals( o2 ); - } - @Override public String toString() { StringBuilder sb = new StringBuilder( returnType.toString() ); From 2043506179d11eab78fe3f709573a36cdff0069a Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 03:57:42 +0300 Subject: [PATCH 0388/1006] #1895 Refactor class org.mapstruct.ap.internal.util.Filters (#1896) --- .../mapstruct/ap/internal/util/Filters.java | 87 +++++++------------ 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index ec69b7131a..b673b3f162 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -7,6 +7,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.VariableElement; @@ -42,71 +43,36 @@ public Filters(AccessorNamingUtils accessorNaming, Types typeUtils, TypeMirror t this.typeMirror = typeMirror; } - public List getterMethodsIn(List elements) { - List getterMethods = new LinkedList<>(); - - for ( ExecutableElement method : elements ) { - if ( accessorNaming.isGetterMethod( method ) ) { - getterMethods.add( new ExecutableElementAccessor( method, getReturnType( method ), GETTER ) ); - } - } - - return getterMethods; - } - - public List fieldsIn(List accessors) { - List fieldAccessors = new LinkedList<>(); - - for ( VariableElement accessor : accessors ) { - if ( Fields.isFieldAccessor( accessor ) ) { - fieldAccessors.add( new VariableElementAccessor( accessor ) ); - } - } - - return fieldAccessors; + public List getterMethodsIn(List elements) { + return elements.stream() + .filter( accessorNaming::isGetterMethod ) + .map( method -> new ExecutableElementAccessor( method, getReturnType( method ), GETTER ) ) + .collect( Collectors.toCollection( LinkedList::new ) ); } - public List presenceCheckMethodsIn(List elements) { - List presenceCheckMethods = new LinkedList<>(); - - for ( ExecutableElement method : elements ) { - if ( accessorNaming.isPresenceCheckMethod( method ) ) { - presenceCheckMethods.add( new ExecutableElementAccessor( - method, - getReturnType( method ), - PRESENCE_CHECKER - ) ); - } - } - - return presenceCheckMethods; + private TypeMirror getReturnType(ExecutableElement executableElement) { + return getWithinContext( executableElement ).getReturnType(); } - public List setterMethodsIn(List elements) { - List setterMethods = new LinkedList<>(); - - for ( ExecutableElement method : elements ) { - if ( accessorNaming.isSetterMethod( method ) ) { - setterMethods.add( new ExecutableElementAccessor( method, getFirstParameter( method ), SETTER ) ); - } - } - return setterMethods; + public List fieldsIn(List accessors) { + return accessors.stream() + .filter( Fields::isFieldAccessor ) + .map( VariableElementAccessor::new ) + .collect( Collectors.toCollection( LinkedList::new ) ); } - public List adderMethodsIn( List elements) { - List adderMethods = new LinkedList<>(); - - for ( ExecutableElement method : elements ) { - if ( accessorNaming.isAdderMethod( method ) ) { - adderMethods.add( new ExecutableElementAccessor( method, getFirstParameter( method ), ADDER ) ); - } - } - - return adderMethods; + public List presenceCheckMethodsIn(List elements) { + return elements.stream() + .filter( accessorNaming::isPresenceCheckMethod ) + .map( method -> new ExecutableElementAccessor( method, getReturnType( method ), PRESENCE_CHECKER ) ) + .collect( Collectors.toCollection( LinkedList::new ) ); } - private TypeMirror getReturnType(ExecutableElement executableElement) { - return getWithinContext( executableElement ).getReturnType(); + public List setterMethodsIn(List elements) { + return elements.stream() + .filter( accessorNaming::isSetterMethod ) + .map( method -> new ExecutableElementAccessor( method, getFirstParameter( method ), SETTER ) ) + .collect( Collectors.toCollection( LinkedList::new ) ); } private TypeMirror getFirstParameter(ExecutableElement executableElement) { @@ -116,4 +82,11 @@ private TypeMirror getFirstParameter(ExecutableElement executableElement) { private ExecutableType getWithinContext( ExecutableElement executableElement ) { return (ExecutableType) typeUtils.asMemberOf( (DeclaredType) typeMirror, executableElement ); } + + public List adderMethodsIn(List elements) { + return elements.stream() + .filter( accessorNaming::isAdderMethod ) + .map( method -> new ExecutableElementAccessor( method, getFirstParameter( method ), ADDER ) ) + .collect( Collectors.toCollection( LinkedList::new ) ); + } } From c044a879694cec5536baf046cb1d9377144e82e7 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 14 Sep 2019 04:12:38 +0300 Subject: [PATCH 0389/1006] #1889 Remove unused parameters from classes TargetTypeSelector, ValueMapping, MethodRetrievalProcessor (#1890) --- .../mapstruct/ap/internal/model/source/ValueMapping.java | 5 ++--- .../internal/model/source/selector/MethodSelectors.java | 2 +- .../model/source/selector/TargetTypeSelector.java | 3 +-- .../ap/internal/processor/MethodRetrievalProcessor.java | 8 ++++---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java index 12bb863d9c..8902d9e8fb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMapping.java @@ -36,7 +36,7 @@ public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, Exec boolean anyFound = false; for ( ValueMappingPrism mappingPrism : mappingsAnnotation.value() ) { - ValueMapping mapping = fromMappingPrism( mappingPrism, method, messager ); + ValueMapping mapping = fromMappingPrism( mappingPrism ); if ( mapping != null ) { if ( !mappings.contains( mapping ) ) { @@ -68,8 +68,7 @@ public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, Exec } } - public static ValueMapping fromMappingPrism(ValueMappingPrism mappingPrism, ExecutableElement element, - FormattingMessager messager) { + public static ValueMapping fromMappingPrism( ValueMappingPrism mappingPrism ) { return new ValueMapping( mappingPrism.source(), mappingPrism.target(), mappingPrism.mirror, mappingPrism.values.source(), mappingPrism.values.target() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index e0f7d0328c..5bfbe84497 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -31,7 +31,7 @@ public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeF new MethodFamilySelector(), new TypeSelector( typeFactory, messager ), new QualifierSelector( typeUtils, elementUtils ), - new TargetTypeSelector( typeUtils, elementUtils ), + new TargetTypeSelector( typeUtils ), new XmlElementDeclSelector( typeUtils ), new InheritanceSelector(), new CreateOrUpdateSelector(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index 3b97b70323..1cbcb6927e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -9,7 +9,6 @@ import java.util.List; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.Type; @@ -27,7 +26,7 @@ public class TargetTypeSelector implements MethodSelector { private final Types typeUtils; - public TargetTypeSelector( Types typeUtils, Elements elementUtils ) { + public TargetTypeSelector( Types typeUtils ) { this.typeUtils = typeUtils; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index b8fabeab07..ffef1656d3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -200,7 +200,7 @@ private SourceMethod getMethod(TypeElement usedMapper, } // otherwise add reference to existing mapper method else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( method, parameters, returnType ) - || isValidLifecycleCallbackMethod( method, returnType ) ) { + || isValidLifecycleCallbackMethod( method ) ) { return getReferencedMethod( usedMapper, methodType, method, mapperToImplement, parameters ); } else { @@ -276,7 +276,7 @@ private ParameterProvidedMethods retrieveContextProvidedMethods( contextParam.getType().getTypeElement(), mapperToImplement, mapperConfig, - Collections. emptyList() ); + Collections.emptyList() ); List contextProvidedMethods = new ArrayList<>( contextParamMethods.size() ); for ( SourceMethod sourceMethod : contextParamMethods ) { @@ -318,7 +318,7 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType .build(); } - private boolean isValidLifecycleCallbackMethod(ExecutableElement method, Type returnType) { + private boolean isValidLifecycleCallbackMethod(ExecutableElement method) { return Executables.isLifecycleCallbackMethod( method ); } @@ -530,7 +530,7 @@ private List getValueMappings(ExecutableElement method) { ValueMappingsPrism mappingsAnnotation = ValueMappingsPrism.getInstanceOn( method ); if ( mappingAnnotation != null ) { - ValueMapping valueMapping = ValueMapping.fromMappingPrism( mappingAnnotation, method, messager ); + ValueMapping valueMapping = ValueMapping.fromMappingPrism( mappingAnnotation ); if ( valueMapping != null ) { valueMappings.add( valueMapping ); } From f3b0badcefc6f7a16aaa53260aad8701d4caffa9 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 15 Sep 2019 13:37:42 +0300 Subject: [PATCH 0390/1006] Add Andrei Arlou in copyright list (#1906) --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 826b627d49..4a851d3e74 100644 --- a/copyright.txt +++ b/copyright.txt @@ -3,6 +3,7 @@ Alexandr Shalugin - https://github.com/shalugin Andreas Gudian - https://github.com/agudian +Andrei Arlou - https://github.com/Captain1653 Andres Jose Sebastian Rincon Gonzalez - https://github.com/stianrincon Arne Seime - https://github.com/seime Christian Bandowski - https://github.com/chris922 From 7e0327767f1a375a59b76ef2458a6394d8a5786e Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 15 Sep 2019 21:43:22 +0200 Subject: [PATCH 0391/1006] #1801 Using constructor as builderCreationMethod in custom builder (#1905) --- .../tests/FullFeatureCompilationTest.java | 1 + .../ap/internal/model/BeanMappingMethod.java | 79 ++++---- .../ap/internal/model/common/BuilderType.java | 6 + .../bugs/_1801/Issue1801BuilderProvider.java | 96 +++++++++ .../ap/test/bugs/_1801/Issue1801Test.java | 53 +++++ .../ap/test/bugs/_1801/ItemMapper.java | 23 +++ .../test/bugs/_1801/domain/ImmutableItem.java | 154 +++++++++++++++ .../ap/test/bugs/_1801/domain/Item.java | 15 ++ .../test/bugs/_1801/dto/ImmutableItemDTO.java | 184 ++++++++++++++++++ .../ap/test/bugs/_1801/dto/ItemDTO.java | 13 ++ 10 files changed, 586 insertions(+), 38 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801BuilderProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/ItemMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/Item.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ImmutableItemDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ItemDTO.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java index fe3836e306..45802ff38b 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java @@ -51,6 +51,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorType proces // SPI not working correctly here.. (not picked up) additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1801/*.java" ); switch ( processorType ) { case ORACLE_JAVA_9: diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index f5ddf3867b..666dfb1aae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -140,21 +140,22 @@ public BeanMappingMethod build() { Type returnTypeImpl = getReturnTypeToConstructFromSelectionParameters( selectionParameters ); if ( returnTypeImpl != null ) { factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } - else { - reportResultTypeFromBeanMappingNotConstructableError( returnTypeImpl ); - } } - else { - returnTypeImpl = isBuilderRequired() ? returnTypeBuilder.getBuilder() : method.getReturnType(); + else if ( isBuilderRequired() ) { + returnTypeImpl = returnTypeBuilder.getBuilder(); factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } - else { - reportReturnTypeNotConstructableError( returnTypeImpl ); + } + else if ( !method.isUpdateMethod() ) { + returnTypeImpl = method.getReturnType(); + factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { + returnTypeToConstruct = returnTypeImpl; } } } @@ -383,57 +384,60 @@ private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters return null; } - private boolean canBeConstructed(Type typeToBeConstructed) { - return !typeToBeConstructed.isAbstract() - && typeToBeConstructed.isAssignableTo( this.method.getResultType() ) - && typeToBeConstructed.hasEmptyAccessibleConstructor(); - } - - private void reportResultTypeFromBeanMappingNotConstructableError(Type resultType) { + private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) { + boolean error = true; if ( resultType.isAbstract() ) { ctx.getMessager().printMessage( - method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, - BEANMAPPING_ABSTRACT, - resultType, - method.getResultType() + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + BEANMAPPING_ABSTRACT, + resultType, + method.getResultType() ); + error = false; } else if ( !resultType.isAssignableTo( method.getResultType() ) ) { ctx.getMessager().printMessage( - method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, - BEANMAPPING_NOT_ASSIGNABLE, - resultType, - method.getResultType() + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + BEANMAPPING_NOT_ASSIGNABLE, + resultType, + method.getResultType() ); + error = false; } else if ( !resultType.hasEmptyAccessibleConstructor() ) { ctx.getMessager().printMessage( - method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, - Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - resultType + method.getExecutable(), + BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + resultType ); + error = false; } + return error; } - private void reportReturnTypeNotConstructableError(Type returnType) { + private boolean canReturnTypeBeConstructed(Type returnType) { + boolean error = true; if ( returnType.isAbstract() ) { ctx.getMessager().printMessage( - method.getExecutable(), - GENERAL_ABSTRACT_RETURN_TYPE, - returnType + method.getExecutable(), + GENERAL_ABSTRACT_RETURN_TYPE, + returnType ); + error = false; } else if ( !returnType.hasEmptyAccessibleConstructor() ) { ctx.getMessager().printMessage( - method.getExecutable(), - Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - returnType + method.getExecutable(), + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + returnType ); + error = false; } + return error; } /** @@ -1021,4 +1025,3 @@ public boolean equals(Object obj) { } } - diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index bae5c161b8..1b34f4698d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model.common; import java.util.Collection; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; @@ -102,6 +103,11 @@ else if ( typeUtils.isSameType( builder.getTypeMirror(), builderCreationOwner ) owner = typeFactory.getType( builderCreationOwner ); } + // When the builderCreationMethod is constructor, its return type is Void. In this case the + // builder type should be the owner type. + if (builderInfo.getBuilderCreationMethod().getKind() == ElementKind.CONSTRUCTOR) { + builder = owner; + } return new BuilderType( builder, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801BuilderProvider.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801BuilderProvider.java new file mode 100644 index 0000000000..80766d853a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801BuilderProvider.java @@ -0,0 +1,96 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801; + +import java.util.List; +import java.util.Objects; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; + +import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; + +/** + * @author Zhizhi Deng + */ +public class Issue1801BuilderProvider extends ImmutablesBuilderProvider implements BuilderProvider { + + @Override + protected BuilderInfo findBuilderInfo(TypeElement typeElement) { + Name name = typeElement.getQualifiedName(); + if ( name.toString().endsWith( ".Item" ) ) { + BuilderInfo info = findBuilderInfoFromInnerBuilderClass( typeElement ); + if ( info != null ) { + return info; + } + } + return super.findBuilderInfo( typeElement ); + } + + /** + * Looks for inner builder class in the Immutable interface / abstract class. + * + * The inner builder class should be be declared with the following line + * + *

      +     *     public static Builder() extends ImmutableItem.Builder { }
      +     * 
      + * + * The Immutable instance should be created with the following line + * + *
      +     *     new Item.Builder().withId("123").build();
      +     * 
      + * + * @see org.mapstruct.ap.test.bugs._1801.domain.Item + * + * @param typeElement + * @return + */ + private BuilderInfo findBuilderInfoFromInnerBuilderClass(TypeElement typeElement) { + if (shouldIgnore( typeElement )) { + return null; + } + + List innerTypes = ElementFilter.typesIn( typeElement.getEnclosedElements() ); + ExecutableElement defaultConstructor = innerTypes.stream() + .filter( this::isBuilderCandidate ) + .map( this::getEmptyArgPublicConstructor ) + .filter( Objects::nonNull ) + .findAny() + .orElse( null ); + + if ( defaultConstructor != null ) { + return new BuilderInfo.Builder() + .builderCreationMethod( defaultConstructor ) + .buildMethod( findBuildMethods( (TypeElement) defaultConstructor.getEnclosingElement(), typeElement ) ) + .build(); + } + return null; + } + + private boolean isBuilderCandidate(TypeElement innerType ) { + TypeElement outerType = (TypeElement) innerType.getEnclosingElement(); + String packageName = this.elementUtils.getPackageOf( outerType ).getQualifiedName().toString(); + Name outerSimpleName = outerType.getSimpleName(); + String builderClassName = packageName + ".Immutable" + outerSimpleName + ".Builder"; + return innerType.getSimpleName().contentEquals( "Builder" ) + && getTypeElement( innerType.getSuperclass() ).getQualifiedName().contentEquals( builderClassName ) + && innerType.getModifiers().contains( Modifier.PUBLIC ); + } + + private ExecutableElement getEmptyArgPublicConstructor(TypeElement builderType) { + return ElementFilter.constructorsIn( builderType.getEnclosedElements() ).stream() + .filter( c -> c.getParameters().isEmpty() ) + .filter( c -> c.getModifiers().contains( Modifier.PUBLIC ) ) + .findAny() + .orElse( null ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java new file mode 100644 index 0000000000..e407c331f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.test.bugs._1801.domain.ImmutableItem; +import org.mapstruct.ap.test.bugs._1801.domain.Item; +import org.mapstruct.ap.test.bugs._1801.dto.ImmutableItemDTO; +import org.mapstruct.ap.test.bugs._1801.dto.ItemDTO; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.WithServiceImplementations; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Zhizhi Deng + */ +@WithClasses({ + ItemMapper.class, + Item.class, + ImmutableItem.class, + ItemDTO.class, + ImmutableItemDTO.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("1801") +@WithServiceImplementations( { + @WithServiceImplementation( provides = BuilderProvider.class, value = Issue1801BuilderProvider.class), + @WithServiceImplementation( provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) +}) +public class Issue1801Test { + + @Test + public void shouldIncludeBuildeType() { + + ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); + + Item target = ItemMapper.INSTANCE.map( item ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/ItemMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/ItemMapper.java new file mode 100644 index 0000000000..f43bf12ca2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/ItemMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801; + +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._1801.domain.Item; +import org.mapstruct.ap.test.bugs._1801.dto.ItemDTO; +import org.mapstruct.factory.Mappers; + +/** + * @author Zhizhi Deng + */ +@Mapper( builder = @Builder) +public abstract class ItemMapper { + + public static final ItemMapper INSTANCE = Mappers.getMapper( ItemMapper.class ); + + public abstract Item map(ItemDTO itemDTO); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java new file mode 100644 index 0000000000..68231f12ef --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java @@ -0,0 +1,154 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801.domain; + +import java.util.ArrayList; +import java.util.List; + +/** + * Immutable implementation of {@link Item}. + *

      + * Superclass should expose a static subclass of the Builder to create immutable instance + * {@code public static Builder extends ImmutableItem.Builder}. + * + * @author Zhizhi Deng + */ +@SuppressWarnings({"all"}) +public final class ImmutableItem extends Item { + private final String id; + + private ImmutableItem(String id) { + this.id = id; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * Copy the current immutable object by setting a value for the {@link Item#getId() id} attribute. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * @param value A new value for id + * @return A modified copy of the {@code this} object + */ + public final ImmutableItem withId(String value) { + if (this.id == value) return this; + return new ImmutableItem(value); + } + + /** + * This instance is equal to all instances of {@code ImmutableItem} that have equal attribute values. + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if (this == another) return true; + return another instanceof ImmutableItem + && equalTo((ImmutableItem) another); + } + + private boolean equalTo(ImmutableItem another) { + return id.equals(another.id); + } + + /** + * Computes a hash code from attributes: {@code id}. + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += (h << 5) + id.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code Item} with attribute values. + * @return A string representation of the value + */ + @Override + public String toString() { + return "Item{" + + "id=" + id + + "}"; + } + + /** + * Creates an immutable copy of a {@link Item} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * @param instance The instance to copy + * @return A copied immutable Item instance + */ + public static ImmutableItem copyOf(Item instance) { + if (instance instanceof ImmutableItem) { + return (ImmutableItem) instance; + } + return new Builder() + .from(instance) + .build(); + } + + /** + * Builds instances of type {@link ImmutableItem ImmutableItem}. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + + Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code Item} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * @param instance The instance from which to copy values + * @return {@code this} builder for use in a chained invocation + */ + public final Builder from(Item instance) { + id(instance.getId()); + return this; + } + + /** + * Initializes the value for the {@link Item#getId() id} attribute. + * @param id The value for id + * @return {@code this} builder for use in a chained invocation + */ + public final Builder id(String id) { + this.id = id; + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Builds a new {@link ImmutableItem ImmutableItem}. + * @return An immutable instance of Item + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItem build() { + if (initBits != 0) { + throw new IllegalStateException(formatRequiredAttributesMessage()); + } + return new ImmutableItem(id); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList(); + if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); + return "Cannot build Item, some of required attributes are not set " + attributes; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/Item.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/Item.java new file mode 100644 index 0000000000..e0f3899077 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/Item.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801.domain; + +/** + * @author Zhizhi Deng + */ +public abstract class Item { + public abstract String getId(); + + public static class Builder extends ImmutableItem.Builder { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ImmutableItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ImmutableItemDTO.java new file mode 100644 index 0000000000..bf10721aa1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ImmutableItemDTO.java @@ -0,0 +1,184 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801.dto; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +/** + * Immutable implementation of {@link ItemDTO}. + *

      + * Use the builder to create immutable instances: + * {@code ImmutableItemDTO.builder()}. + * + * @author Zhizhi Deng + */ +public final class ImmutableItemDTO extends ItemDTO { + private final String id; + + private ImmutableItemDTO(String id) { + this.id = id; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * Copy the current immutable object by setting a value for the {@link ItemDTO#getId() id} attribute. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * + * @param value A new value for id + * + * @return A modified copy of the {@code this} object + */ + public ImmutableItemDTO withId(String value) { + if ( Objects.equals( this.id, value ) ) { + return this; + } + return new ImmutableItemDTO( value ); + } + + /** + * This instance is equal to all instances of {@code ImmutableItemDTO} that have equal attribute values. + * + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if ( this == another ) { + return true; + } + return another instanceof ImmutableItemDTO + && equalTo( (ImmutableItemDTO) another ); + } + + private boolean equalTo(ImmutableItemDTO another) { + return id.equals( another.id ); + } + + /** + * Computes a hash code from attributes: {@code id}. + * + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += ( h << 5 ) + id.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code ItemDTO} with attribute values. + * + * @return A string representation of the value + */ + @Override + public String toString() { + return "ItemDTO{" + + "id=" + id + + "}"; + } + + /** + * Creates an immutable copy of a {@link ItemDTO} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * + * @param instance The instance to copy + * + * @return A copied immutable ItemDTO instance + */ + public static ImmutableItemDTO copyOf(ItemDTO instance) { + if ( instance instanceof ImmutableItemDTO ) { + return (ImmutableItemDTO) instance; + } + return ImmutableItemDTO.builder() + .from( instance ) + .build(); + } + + /** + * Creates a builder for {@link ImmutableItemDTO ImmutableItemDTO}. + * + * @return A new ImmutableItemDTO builder + */ + public static ImmutableItemDTO.Builder builder() { + return new ImmutableItemDTO.Builder(); + } + + /** + * Builds instances of type {@link ImmutableItemDTO ImmutableItemDTO}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static final class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + + private Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code ItemDTO} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * + * @param instance The instance from which to copy values + * + * @return {@code this} builder for use in a chained invocation + */ + public Builder from(ItemDTO instance) { + id( instance.getId() ); + return this; + } + + /** + * Initializes the value for the {@link ItemDTO#getId() id} attribute. + * + * @param id The value for id + * + * @return {@code this} builder for use in a chained invocation + */ + public Builder id(String id) { + this.id = id; + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Builds a new {@link ImmutableItemDTO ImmutableItemDTO}. + * + * @return An immutable instance of ItemDTO + * + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItemDTO build() { + if ( initBits != 0 ) { + throw new IllegalStateException( formatRequiredAttributesMessage() ); + } + return new ImmutableItemDTO( id ); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList<>(); + if ( ( initBits & INIT_BIT_ID ) != 0 ) { + attributes.add( "id" ); + } + return "Cannot build ItemDTO, some of required attributes are not set " + attributes; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ItemDTO.java new file mode 100644 index 0000000000..1b8866b5ea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/dto/ItemDTO.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1801.dto; + +/** + * @author Zhizhi Deng + */ +public abstract class ItemDTO { + public abstract String getId(); +} From 447bb00f8932abfff2fd3ab9ee3dcb5e57223edd Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Wed, 18 Sep 2019 07:18:05 +0300 Subject: [PATCH 0392/1006] #1773 Update documentation: componentModel=jsr330 with @DecoratedWith not longer experimental (#1907) --- core/src/main/java/org/mapstruct/DecoratedWith.java | 2 -- .../main/asciidoc/chapter-12-customizing-mapping.asciidoc | 5 ----- 2 files changed, 7 deletions(-) diff --git a/core/src/main/java/org/mapstruct/DecoratedWith.java b/core/src/main/java/org/mapstruct/DecoratedWith.java index e2734a699c..7f740a8983 100644 --- a/core/src/main/java/org/mapstruct/DecoratedWith.java +++ b/core/src/main/java/org/mapstruct/DecoratedWith.java @@ -23,8 +23,6 @@ * NOTE: This annotation is not supported for the component model {@code cdi}. Use CDI's own * {@code @Decorator} feature instead. *

      - * NOTE: The decorator feature when used with component model {@code jsr330} is considered experimental - * and it may change in future releases. *

      Examples

      *

      * For the examples below, consider the following mapper declaration: diff --git a/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc index b7b7c4b248..0c873eac09 100644 --- a/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc +++ b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc @@ -142,11 +142,6 @@ private PersonMapper personMapper; // injects the decorator, with the injected o ---- ==== -[WARNING] -==== -`@DecoratedWith` in combination with component model `jsr330` is considered experimental as of the 1.0.0.CR2 release. The way the original mapper is referenced in the decorator or the way the decorated mapper is injected in the application code might still change. -==== - [[customizing-mappings-with-before-and-after]] === Mapping customization with before-mapping and after-mapping methods From d018aed25150d886b54d41099345908c01d4cc7b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 18 Sep 2019 13:09:40 +0200 Subject: [PATCH 0393/1006] #1790 Use mapperPrism.values.nullValuePropertyMappingStrategy when retrieving NullValuePropertyMappingStrategy --- .../ap/internal/util/MapperConfiguration.java | 2 +- .../ap/test/bugs/_1790/Issue1790Config.java | 16 ++++++++ .../ap/test/bugs/_1790/Issue1790Mapper.java | 22 ++++++++++ .../ap/test/bugs/_1790/Issue1790Test.java | 40 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_1790/Source.java | 22 ++++++++++ .../mapstruct/ap/test/bugs/_1790/Target.java | 22 ++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 451e8fe7ca..96b25af2a7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -192,7 +192,7 @@ public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy else if ( beanPrism != null ) { return beanPrism; } - else if ( mapperConfigPrism != null && mapperPrism.values.nullValueCheckStrategy() == null ) { + else if ( mapperConfigPrism != null && mapperPrism.values.nullValuePropertyMappingStrategy() == null ) { return NullValuePropertyMappingStrategyPrism.valueOf( mapperConfigPrism.nullValuePropertyMappingStrategy() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Config.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Config.java new file mode 100644 index 0000000000..41fe78a0d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Config.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1790; + +import org.mapstruct.MapperConfig; +import org.mapstruct.NullValueCheckStrategy; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface Issue1790Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Mapper.java new file mode 100644 index 0000000000..72330b7356 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1790; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = Issue1790Config.class, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface Issue1790Mapper { + + Issue1790Mapper INSTANCE = Mappers.getMapper( Issue1790Mapper.class ); + + void toExistingCar(@MappingTarget Target target, Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java new file mode 100644 index 0000000000..8ea3c4c026 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1790; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1790") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1790Config.class, + Issue1790Mapper.class, + Source.class, + Target.class, +}) +public class Issue1790Test { + + @Test + public void shouldProperlyApplyNullValuePropertyMappingStrategyWhenInheriting() { + Target target = new Target(); + target.setName( "My name is set" ); + + Source source = new Source(); + + Issue1790Mapper.INSTANCE.toExistingCar( target, source ); + + assertThat( target.getName() ).isEqualTo( "My name is set" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Source.java new file mode 100644 index 0000000000..af6c94b279 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1790; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Target.java new file mode 100644 index 0000000000..facbbaf48c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1790; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} From 750ce48023e9cd0022b34e86d72f1cd5ee0d4bb7 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Wed, 18 Sep 2019 20:51:36 +0300 Subject: [PATCH 0394/1006] #1792 Annotation processor option for default injection strategy --- .../main/asciidoc/chapter-2-set-up.asciidoc | 13 ++ .../chapter-4-retrieving-a-mapper.asciidoc | 2 +- .../org/mapstruct/ap/MappingProcessor.java | 3 + .../mapstruct/ap/internal/option/Options.java | 9 +- ...nnotationBasedComponentModelProcessor.java | 2 +- .../ap/internal/util/MapperConfiguration.java | 16 ++- ...Jsr330DefaultCompileOptionFieldMapper.java | 19 +++ ...Jsr330DefaultCompileOptionFieldMapper.java | 25 ++++ ...30DefaultCompileOptionFieldMapperTest.java | 94 +++++++++++++ ...rJsr330CompileOptionConstructorMapper.java | 23 +++ ...rJsr330CompileOptionConstructorMapper.java | 25 ++++ ...330CompileOptionConstructorMapperTest.java | 95 +++++++++++++ ...dSpringCompileOptionConstructorMapper.java | 21 +++ ...rSpringCompileOptionConstructorMapper.java | 22 +++ ...rSpringCompileOptionConstructorMapper.java | 25 ++++ ...ingCompileOptionConstructorMapperTest.java | 131 ++++++++++++++++++ 16 files changed, 518 insertions(+), 7 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 591ff0764a..614be18346 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -254,6 +254,19 @@ Supported values are: If a component model is given for a specific mapper via `@Mapper#componentModel()`, the value from the annotation takes precedence. |`default` +|`mapstruct.defaultInjectionStrategy` +| The type of the injection in mapper via parameter `uses`. This is only used on annotated based component models + such as CDI, Spring and JSR 330. + +Supported values are: + +* `field`: dependencies will be injected in fields +* `constructor`: will be generated constructor. Dependencies will be injected via constructor. + +When CDI `componentModel` a default constructor will also be generated. +If a injection strategy is given for a specific mapper via `@Mapper#injectionStrategy()`, the value from the annotation takes precedence over the option. +|`field` + |`mapstruct.unmappedTargetPolicy` |The default reporting policy to be applied in case an attribute of the target object of a mapping method is not populated with a source value. diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc index 03c2c4b559..75b5b10294 100644 --- a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc @@ -120,7 +120,7 @@ public interface CarMapper { The generated mapper will inject all classes defined in the **uses** attribute. When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. -For now, the default injection strategy is field injection. +For now, the default injection strategy is field injection, but it can be configured with <>. It is recommended to use constructor injection to simplify testing. [TIP] diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 5f7d3394f0..d9686e9636 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -83,6 +83,7 @@ MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, MappingProcessor.UNMAPPED_TARGET_POLICY, MappingProcessor.DEFAULT_COMPONENT_MODEL, + MappingProcessor.DEFAULT_INJECTION_STRATEGY, MappingProcessor.VERBOSE }) public class MappingProcessor extends AbstractProcessor { @@ -97,6 +98,7 @@ public class MappingProcessor extends AbstractProcessor { "mapstruct.suppressGeneratorVersionInfoComment"; protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; + protected static final String DEFAULT_INJECTION_STRATEGY = "mapstruct.defaultInjectionStrategy"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; protected static final String VERBOSE = "mapstruct.verbose"; @@ -136,6 +138,7 @@ private Options createOptions() { Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), + processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), Boolean.valueOf( processingEnv.getOptions().get( VERBOSE ) ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 1e555e8d37..92dcbc5dc4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -19,15 +19,18 @@ public class Options { private final ReportingPolicyPrism unmappedTargetPolicy; private final boolean alwaysGenerateSpi; private final String defaultComponentModel; + private final String defaultInjectionStrategy; private final boolean verbose; public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyPrism unmappedTargetPolicy, - String defaultComponentModel, boolean alwaysGenerateSpi, boolean verbose) { + String defaultComponentModel, String defaultInjectionStrategy, + boolean alwaysGenerateSpi, boolean verbose) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; this.defaultComponentModel = defaultComponentModel; + this.defaultInjectionStrategy = defaultInjectionStrategy; this.alwaysGenerateSpi = alwaysGenerateSpi; this.verbose = verbose; } @@ -48,6 +51,10 @@ public String getDefaultComponentModel() { return defaultComponentModel; } + public String getDefaultInjectionStrategy() { + return defaultInjectionStrategy; + } + public boolean isAlwaysGenerateSpi() { return alwaysGenerateSpi; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index a4d9704369..8cd9a21c00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -45,7 +45,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, M MapperConfiguration mapperConfiguration = MapperConfiguration.getInstanceOn( mapperTypeElement ); String componentModel = mapperConfiguration.componentModel( context.getOptions() ); - InjectionStrategyPrism injectionStrategy = mapperConfiguration.getInjectionStrategy(); + InjectionStrategyPrism injectionStrategy = mapperConfiguration.getInjectionStrategy( context.getOptions() ); if ( !getComponentModelIdentifier().equalsIgnoreCase( componentModel ) ) { return mapper; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index 96b25af2a7..be4622c7ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -202,13 +202,21 @@ else if ( mapperConfigPrism != null && mapperPrism.values.nullValuePropertyMappi } } - public InjectionStrategyPrism getInjectionStrategy() { - if ( mapperConfigPrism != null && mapperPrism.values.injectionStrategy() == null ) { + public InjectionStrategyPrism getInjectionStrategy(Options options) { + if ( mapperPrism.values.injectionStrategy() != null ) { + return InjectionStrategyPrism.valueOf( mapperPrism.injectionStrategy() ); + } + + if ( mapperConfigPrism != null && mapperConfigPrism.values.injectionStrategy() != null ) { return InjectionStrategyPrism.valueOf( mapperConfigPrism.injectionStrategy() ); } - else { - return InjectionStrategyPrism.valueOf( mapperPrism.injectionStrategy() ); + + if ( options.getDefaultInjectionStrategy() != null ) { + return InjectionStrategyPrism.valueOf( options.getDefaultInjectionStrategy().toUpperCase() ); } + + // fall back to default defined in the annotation + return InjectionStrategyPrism.valueOf( mapperPrism.injectionStrategy() ); } public NullValueMappingStrategyPrism getNullValueMappingStrategy() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..9ce6b1215e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330._default; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = "jsr330", uses = GenderJsr330DefaultCompileOptionFieldMapper.class) +public interface CustomerJsr330DefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..6701ce42fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330._default; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = "jsr330") +public interface GenderJsr330DefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..61c767869a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,94 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330._default; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test field injection for component model jsr330. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Andrei Arlou + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330DefaultCompileOptionFieldMapper.class, + GenderJsr330DefaultCompileOptionFieldMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class) +@Configuration +public class Jsr330DefaultCompileOptionFieldMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Inject + @Named + private CustomerJsr330DefaultCompileOptionFieldMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerJsr330DefaultCompileOptionFieldMapper.class ) + .content() + .contains( "@Inject" + lineSeparator() + " private GenderJsr330DefaultCompileOptionFieldMapper" ) + .doesNotContain( "public CustomerJsr330DefaultCompileOptionFieldMapperImpl(" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java new file mode 100644 index 0000000000..0e89ec8943 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Andrei Arlou + */ +@Mapper( componentModel = "jsr330", + uses = GenderJsr330CompileOptionConstructorMapper.class ) +public interface CustomerJsr330CompileOptionConstructorMapper { + + @Mapping(source = "gender", target = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java new file mode 100644 index 0000000000..da3caed5be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = "jsr330") +public interface GenderJsr330CompileOptionConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java new file mode 100644 index 0000000000..dbf4a4f7ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java @@ -0,0 +1,95 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test constructor injection for component model jsr330 with compile option + * mapstruct.defaultInjectionStrategy=constructor + * + * @author Andrei Arlou + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330CompileOptionConstructorMapper.class, + GenderJsr330CompileOptionConstructorMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") +@ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class) +@Configuration +public class Jsr330CompileOptionConstructorMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerJsr330CompileOptionConstructorMapper customerMapper; + private ConfigurableApplicationContext context; + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @Test + public void shouldHaveConstructorInjectionFromCompileOption() { + generatedSource.forMapper( CustomerJsr330CompileOptionConstructorMapper.class ) + .content() + .contains( "private final GenderJsr330CompileOptionConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJsr330CompileOptionConstructorMapperImpl" + + "(GenderJsr330CompileOptionConstructorMapper" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java new file mode 100644 index 0000000000..d7debfb96c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = "spring", + uses = { CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class }, + disableSubMappingMethodsGeneration = true) +public interface CustomerRecordSpringCompileOptionConstructorMapper { + + CustomerRecordDto asTarget(CustomerRecordEntity customerRecordEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java new file mode 100644 index 0000000000..db11c1b7ad --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Andrei Arlou + */ +@Mapper( componentModel = "spring", + uses = GenderSpringCompileOptionConstructorMapper.class) +public interface CustomerSpringCompileOptionConstructorMapper { + + @Mapping( source = "gender", target = "gender" ) + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java new file mode 100644 index 0000000000..c909f1dc5c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = "spring") +public interface GenderSpringCompileOptionConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java new file mode 100644 index 0000000000..7608963a6d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java @@ -0,0 +1,131 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test constructor injection for component model spring with + * compile option mapstruct.defaultInjectStrategy=constructor + * + * @author Andrei Arlou + */ +@WithClasses( { + CustomerRecordDto.class, + CustomerRecordEntity.class, + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerRecordSpringCompileOptionConstructorMapper.class, + CustomerSpringCompileOptionConstructorMapper.class, + GenderSpringCompileOptionConstructorMapper.class +} ) +@RunWith(AnnotationProcessorTestRunner.class) +@ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") +@ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class) +@Configuration +public class SpringCompileOptionConstructorMapperTest { + + private static TimeZone originalTimeZone; + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerRecordSpringCompileOptionConstructorMapper customerRecordMapper; + private ConfigurableApplicationContext context; + + @BeforeClass + public static void setDefaultTimeZoneToCet() { + originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); + } + + @AfterClass + public static void restoreOriginalTimeZone() { + TimeZone.setDefault( originalTimeZone ); + } + + @Before + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @After + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @Test + public void shouldConvertToTarget() throws Exception { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + CustomerRecordEntity customerRecordEntity = new CustomerRecordEntity(); + customerRecordEntity.setCustomer( customerEntity ); + customerRecordEntity.setRegistrationDate( createDate( "31-08-1982 10:20:56" ) ); + + // when + CustomerRecordDto customerRecordDto = customerRecordMapper.asTarget( customerRecordEntity ); + + // then + assertThat( customerRecordDto ).isNotNull(); + assertThat( customerRecordDto.getCustomer() ).isNotNull(); + assertThat( customerRecordDto.getCustomer().getName() ).isEqualTo( "Samuel" ); + assertThat( customerRecordDto.getCustomer().getGender() ).isEqualTo( GenderDto.M ); + assertThat( customerRecordDto.getRegistrationDate() ).isNotNull(); + assertThat( customerRecordDto.getRegistrationDate().toString() ).isEqualTo( "1982-08-31T10:20:56.000+02:00" ); + } + + private Date createDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); + return sdf.parse( date ); + } + + @Test + public void shouldConstructorInjectionFromCompileOption() { + generatedSource.forMapper( CustomerSpringCompileOptionConstructorMapper.class ) + .content() + .contains( "private final GenderSpringCompileOptionConstructorMapper" ) + .contains( "@Autowired" + lineSeparator() + + " public CustomerSpringCompileOptionConstructorMapperImpl" + + "(GenderSpringCompileOptionConstructorMapper" ); + } +} From e92e3b45c6c8bc1bd4a501e6432f884e80153a29 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 21 Sep 2019 10:06:53 +0200 Subject: [PATCH 0395/1006] #1904 Create compilation error if a mapper could not be created due to a TypeHierarchyErroneousException --- .../org/mapstruct/ap/MappingProcessor.java | 56 ++++++++++++++++++- ...AstModifyingAnnotationProcessorSaysNo.java | 23 ++++++++ .../ap/test/bugs/_1904/Issue1904Mapper.java | 49 ++++++++++++++++ .../ap/test/bugs/_1904/Issue1904Test.java | 48 ++++++++++++++++ .../ap/test/verbose/VerboseTest.java | 12 ++++ 5 files changed, 185 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/AstModifyingAnnotationProcessorSaysNo.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index d9686e9636..e31b2a07b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -27,6 +27,7 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.Name; +import javax.lang.model.element.QualifiedNameable; import javax.lang.model.element.TypeElement; import javax.lang.model.util.ElementKindVisitor6; import javax.tools.Diagnostic.Kind; @@ -115,7 +116,7 @@ public class MappingProcessor extends AbstractProcessor { * generated by other processors), this mapper will not be generated; That's fine, the compiler will raise an error * due to the inconsistent Java types used as source or target anyways. */ - private Set deferredMappers = new HashSet<>(); + private Set deferredMappers = new HashSet<>(); @Override public synchronized void init(ProcessingEnvironment processingEnv) { @@ -163,6 +164,40 @@ public boolean process(final Set annotations, final Round Set mappers = getMappers( annotations, roundEnvironment ); processMapperElements( mappers, roundContext ); } + else if ( !deferredMappers.isEmpty() ) { + // If the processing is over and there are deferred mappers it means something wrong occurred and + // MapStruct didn't generate implementations for those + for ( DeferredMapper deferredMapper : deferredMappers ) { + + TypeElement deferredMapperElement = deferredMapper.deferredMapperElement; + Element erroneousElement = deferredMapper.erroneousElement; + String erroneousElementName; + + if ( erroneousElement instanceof QualifiedNameable ) { + erroneousElementName = ( (QualifiedNameable) erroneousElement ).getQualifiedName().toString(); + } + else { + erroneousElementName = erroneousElement.getSimpleName().toString(); + } + + // When running on Java 8 we need to fetch the deferredMapperElement again. + // Otherwise the reporting will not work properly + deferredMapperElement = annotationProcessorContext.getElementUtils() + .getTypeElement( deferredMapperElement.getQualifiedName() ); + + processingEnv.getMessager() + .printMessage( + Kind.ERROR, + "No implementation was created for " + deferredMapperElement.getSimpleName() + + " due to having a problem in the erroneous element " + erroneousElementName + "." + + " Hint: this often means that some other annotation processor was supposed to" + + " process the erroneous element. You can also enable MapStruct verbose mode by setting" + + " -Amapstruct.verbose=true as a compilation argument.", + deferredMapperElement + ); + } + + } return ANNOTATIONS_CLAIMED_EXCLUSIVELY; } @@ -174,7 +209,8 @@ public boolean process(final Set annotations, final Round private Set getAndResetDeferredMappers() { Set deferred = new HashSet<>( deferredMappers.size() ); - for (TypeElement element : deferredMappers ) { + for ( DeferredMapper deferredMapper : deferredMappers ) { + TypeElement element = deferredMapper.deferredMapperElement; deferred.add( processingEnv.getElementUtils().getTypeElement( element.getQualifiedName() ) ); } @@ -229,12 +265,15 @@ processingEnv, options, roundContext, getDeclaredTypesNotToBeImported( mapperEle processMapperTypeElement( context, mapperElement ); } catch ( TypeHierarchyErroneousException thie ) { + Element erroneousElement = roundContext.getAnnotationProcessorContext() + .getTypeUtils() + .asElement( thie.getType() ); if ( options.isVerbose() ) { processingEnv.getMessager().printMessage( Kind.NOTE, "MapStruct: referred types not available (yet), deferring mapper: " + mapperElement ); } - deferredMappers.add( mapperElement ); + deferredMappers.add( new DeferredMapper( mapperElement, erroneousElement ) ); } catch ( Throwable t ) { handleUncaughtError( mapperElement, t ); @@ -347,4 +386,15 @@ public int compare(ModelElementProcessor o1, ModelElementProcessor o return Integer.compare( o1.getPriority(), o2.getPriority() ); } } + + private static class DeferredMapper { + + private final TypeElement deferredMapperElement; + private final Element erroneousElement; + + private DeferredMapper(TypeElement deferredMapperElement, Element erroneousElement) { + this.deferredMapperElement = deferredMapperElement; + this.erroneousElement = erroneousElement; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/AstModifyingAnnotationProcessorSaysNo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/AstModifyingAnnotationProcessorSaysNo.java new file mode 100644 index 0000000000..74cbc7a20c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/AstModifyingAnnotationProcessorSaysNo.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1904; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * @author Filip Hrisafov + */ +public class AstModifyingAnnotationProcessorSaysNo implements AstModifyingAnnotationProcessor { + @Override + public boolean isTypeComplete(TypeMirror type) { + if ( type.toString().contains( "CarManualDto" ) ) { + return false; + } + return true; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Mapper.java new file mode 100644 index 0000000000..a4f67cb77b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Mapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1904; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1904Mapper { + + CarManualDto translateManual(CarManual manual); + + /** + * @author Filip Hrisafov + */ + class CarManual { + + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + } + + /** + * @author Filip Hrisafov + */ + class CarManualDto { + + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java new file mode 100644 index 0000000000..7c2b95bbfb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1904; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1904") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1904Mapper.class, +}) +@WithServiceImplementation( + provides = AstModifyingAnnotationProcessor.class, + value = AstModifyingAnnotationProcessorSaysNo.class +) +public class Issue1904Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic( + type = Issue1904Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 14, + messageRegExp = ".*No implementation was created for Issue1904Mapper due to having a problem in the " + + "erroneous element .*\\.CarManualDto. Hint: this often means that some other annotation processor " + + "was supposed to process the erroneous element. You can also enable MapStruct verbose mode by " + + "setting -Amapstruct.verbose=true as a compilation argument." + ) + }) + public void shouldHaveCompilationErrorIfMapperCouldNotBeCreated() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java index 99b77b1220..ba5187e74b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java @@ -16,6 +16,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @@ -57,6 +60,15 @@ public void testGeneralWithOtherSPI() { @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(CreateBeanMapping.class) @ExpectedNote("^MapStruct: referred types not available \\(yet\\), deferring mapper:.*CreateBeanMapping.*$") + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic( + type = CreateBeanMapping.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 12, + messageRegExp = ".*No implementation was created for CreateBeanMapping due to having a problem in the " + + "erroneous element .*" + ) + }) public void testDeferred() { } From fcdf852a172ad04c1dceb413c3f29a1d0273e49a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 21 Sep 2019 10:24:25 +0200 Subject: [PATCH 0396/1006] #1904 Do not include private methods when getting enclosed executable elements --- .../mapstruct/ap/internal/util/Executables.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 8c554bc1f9..4fbae2bdbd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -85,8 +85,8 @@ private static TypeElement asTypeElement(TypeMirror mirror) { /** * Finds all executable elements within the given type element, including executable elements defined in super - * classes and implemented interfaces. Methods defined in {@link java.lang.Object} are ignored, as well as - * implementations of {@link java.lang.Object#equals(Object)}. + * classes and implemented interfaces. Methods defined in {@link java.lang.Object}, + * implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored * * @param elementUtils element helper * @param element the element to inspect @@ -143,7 +143,7 @@ private static void addNotYetOverridden(Elements elementUtils, List methodsToAdd, TypeElement parentType) { List safeToAdd = new ArrayList<>( methodsToAdd.size() ); for ( ExecutableElement toAdd : methodsToAdd ) { - if ( isNotObjectEquals( toAdd ) + if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd ) && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { safeToAdd.add( toAdd ); } @@ -168,6 +168,15 @@ && asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedNam return true; } + /** + * @param executable the executable to check + * + * @return {@code true}, iff the executable does not have a private modifier + */ + private static boolean isNotPrivate(ExecutableElement executable) { + return !executable.getModifiers().contains( Modifier.PRIVATE ); + } + /** * @param elementUtils the elementUtils * @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to From f4c9313972faf8285d89ebd6850f9ba66de47b9b Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 21 Sep 2019 22:27:45 +0300 Subject: [PATCH 0397/1006] #1791 Support for conversion between java.time.LocalDateTime and javax.xml.datatype.XMLGregorianCalendar (#1894) --- .../chapter-5-data-type-conversions.asciidoc | 2 + .../source/builtin/BuiltInMappingMethods.java | 8 +- .../model/source/builtin/BuiltInMethod.java | 2 +- .../LocalDateTimeToXmlGregorianCalendar.java | 49 +++++++ .../XmlGregorianCalendarToLocalDateTime.java | 55 ++++++++ .../LocalDateTimeToXmlGregorianCalendar.ftl | 23 ++++ .../XmlGregorianCalendarToLocalDateTime.ftl | 53 ++++++++ ...eToXMLGregorianCalendarConversionTest.java | 120 ++++++++++++++++++ .../Source.java | 24 ++++ .../SourceTargetMapper.java | 25 ++++ .../Target.java | 23 ++++ 11 files changed, 379 insertions(+), 5 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Target.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 26e8c083d8..45c97b3dab 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -90,6 +90,8 @@ public interface CarMapper { * Between Jodas `org.joda.time.LocalDateTime`, `org.joda.time.LocalDate` and `javax.xml.datatype.XMLGregorianCalendar`, `java.util.Date`. +* Between `java.time.LocalDate`, `java.time.LocalDateTime` and `javax.xml.datatype.XMLGregorianCalendar`. + * Between `java.time.ZonedDateTime`, `java.time.LocalDateTime`, `java.time.LocalDate`, `java.time.LocalTime` from Java 8 Date-Time package and `String`. A format string as understood by `java.text.SimpleDateFormat` can be specified via the `dateFormat` option (see above). * Between `java.time.Instant`, `java.time.Duration`, `java.time.Period` from Java 8 Date-Time package and `String` using the `parse` method in each class to map from `String` and using `toString` to map into `String`. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 5332651ab0..4b096f8035 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -33,6 +33,10 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { builtInMethods.add( new CalendarToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new XmlGregorianCalendarToCalendar( typeFactory ) ); builtInMethods.add( new ZonedDateTimeToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); + builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new LocalDateTimeToXmlGregorianCalendar( typeFactory ) ); + builtInMethods.add( new XmlGregorianCalendarToLocalDateTime( typeFactory ) ); } if ( isJaxbAvailable( typeFactory ) ) { @@ -41,10 +45,6 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); builtInMethods.add( new CalendarToZonedDateTime( typeFactory ) ); - if ( isXmlGregorianCalendarPresent ) { - builtInMethods.add( new XmlGregorianCalendarToLocalDate( typeFactory ) ); - builtInMethods.add( new LocalDateToXmlGregorianCalendar( typeFactory ) ); - } if ( isJodaTimeAvailable( typeFactory ) && isXmlGregorianCalendarPresent ) { builtInMethods.add( new JodaDateTimeToXmlGregorianCalendar( typeFactory ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 783ea43a5b..bbfafcbfb6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -51,7 +51,7 @@ public String getName() { * @return the types used by this method for which import statements need to be generated */ public Set getImportTypes() { - return Collections.emptySet(); + return Collections.emptySet(); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java new file mode 100644 index 0000000000..8853c1aae7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoField; +import java.util.Set; + +import javax.xml.datatype.DatatypeConstants; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * @author Andrei Arlou + */ +public class LocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { + + private final Parameter parameter; + private final Set importTypes; + + public LocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { + super( typeFactory ); + this.parameter = new Parameter( "localDateTime", typeFactory.getType( LocalDateTime.class ) ); + this.importTypes = asSet( + parameter.getType(), + typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( ChronoField.class ) + ); + } + + @Override + public Set getImportTypes() { + Set result = super.getImportTypes(); + result.addAll( importTypes ); + return result; + } + + @Override + public Parameter getParameter() { + return parameter; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java new file mode 100644 index 0000000000..5d29892444 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.builtin; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.Set; + +import javax.xml.datatype.DatatypeConstants; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * @author Andrei Arlou + */ +public class XmlGregorianCalendarToLocalDateTime extends BuiltInMethod { + + private final Parameter parameter; + private final Type returnType; + private final Set importTypes; + + public XmlGregorianCalendarToLocalDateTime(TypeFactory typeFactory) { + this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.returnType = typeFactory.getType( LocalDateTime.class ); + this.importTypes = asSet( + returnType, + parameter.getType(), + typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( Duration.class ) + ); + } + + @Override + public Parameter getParameter() { + return parameter; + } + + @Override + public Type getReturnType() { + return returnType; + } + + @Override + public Set getImportTypes() { + return importTypes; + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.ftl new file mode 100644 index 0000000000..fb7706b390 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.ftl @@ -0,0 +1,23 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> +private <@includeModel object=findType("XMLGregorianCalendar")/> ${name}( <@includeModel object=findType("java.time.LocalDateTime")/> localDateTime ) { + if ( localDateTime == null ) { + return null; + } + + return ${supportingField.variableName}.newXMLGregorianCalendar( + localDateTime.getYear(), + localDateTime.getMonthValue(), + localDateTime.getDayOfMonth(), + localDateTime.getHour(), + localDateTime.getMinute(), + localDateTime.getSecond(), + localDateTime.get( ChronoField.MILLI_OF_SECOND ), + <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ); +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.ftl new file mode 100644 index 0000000000..6eef5513a4 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.ftl @@ -0,0 +1,53 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> +private static <@includeModel object=findType("java.time.LocalDateTime")/> ${name}( <@includeModel object=findType("XMLGregorianCalendar")/> xcal ) { + if ( xcal == null ) { + return null; + } + + if ( xcal.getYear() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMonth() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getDay() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getHour() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMinute() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + ) { + if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED + && xcal.getMillisecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return <@includeModel object=findType("java.time.LocalDateTime")/>.of( + xcal.getYear(), + xcal.getMonth(), + xcal.getDay(), + xcal.getHour(), + xcal.getMinute(), + xcal.getSecond(), + Duration.ofMillis( xcal.getMillisecond() ).getNano() + ); + } + else if ( xcal.getSecond() != <@includeModel object=findType("DatatypeConstants")/>.FIELD_UNDEFINED ) { + return <@includeModel object=findType("java.time.LocalDateTime")/>.of( + xcal.getYear(), + xcal.getMonth(), + xcal.getDay(), + xcal.getHour(), + xcal.getMinute(), + xcal.getSecond() + ); + } + else { + return <@includeModel object=findType("java.time.LocalDateTime")/>.of( + xcal.getYear(), + xcal.getMonth(), + xcal.getDay(), + xcal.getHour(), + xcal.getMinute() + ); + } + } + return null; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java new file mode 100644 index 0000000000..ebaa271d04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java @@ -0,0 +1,120 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import java.time.LocalDateTime; +import java.util.Calendar; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeConstants; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.SourceTargetMapper; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Source; +import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Target; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Andrei Arlou + */ +@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) +@RunWith(AnnotationProcessorTestRunner.class) +public class LocalDateTimeToXMLGregorianCalendarConversionTest { + + @Test + public void shouldNullCheckOnConversionToTarget() { + Target target = SourceTargetMapper.INSTANCE.toTarget( new Source() ); + + assertThat( target ).isNotNull(); + assertThat( target.getLocalDateTime() ).isNull(); + } + + @Test + public void shouldNullCheckOnConversionToSource() { + Source source = SourceTargetMapper.INSTANCE.toSource( new Target() ); + + assertThat( source ).isNotNull(); + assertThat( source.getXmlGregorianCalendar() ).isNull(); + } + + @Test + public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithNanoseconds() + throws DatatypeConfigurationException { + LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30, 50, 9000000 ); + Target target = new Target(); + target.setLocalDateTime( localDateTime ); + + Source source = SourceTargetMapper.INSTANCE.toSource( target ); + + XMLGregorianCalendar expectedCalendar = DatatypeFactory.newInstance() + .newXMLGregorianCalendar( 1994, Calendar.MARCH, 5, 11, 30, 50, 9, + DatatypeConstants.FIELD_UNDEFINED + ); + + assertThat( source ).isNotNull(); + assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); + } + + @Test + public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithSeconds() + throws DatatypeConfigurationException { + LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30, 50 ); + Target target = new Target(); + target.setLocalDateTime( localDateTime ); + + Source source = SourceTargetMapper.INSTANCE.toSource( target ); + + XMLGregorianCalendar expectedCalendar = DatatypeFactory.newInstance() + .newXMLGregorianCalendar( 1994, Calendar.MARCH, 5, 11, 30, 50, 0, + DatatypeConstants.FIELD_UNDEFINED + ); + + assertThat( source ).isNotNull(); + assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); + } + + @Test + public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithMinutes() + throws DatatypeConfigurationException { + LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30 ); + Target target = new Target(); + target.setLocalDateTime( localDateTime ); + + Source source = SourceTargetMapper.INSTANCE.toSource( target ); + + XMLGregorianCalendar expectedCalendar = DatatypeFactory.newInstance() + .newXMLGregorianCalendar( 1994, Calendar.MARCH, 5, 11, 30, 0, 0, + DatatypeConstants.FIELD_UNDEFINED + ); + + assertThat( source ).isNotNull(); + assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); + } + + @Test + public void shouldMapXmlGregorianCalendarToLocalDateTimeCorrectly() throws DatatypeConfigurationException { + XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance() + .newXMLGregorianCalendar( 1994, Calendar.MARCH, 5, 11, 30, 50, 500, + DatatypeConstants.FIELD_UNDEFINED + ); + + Source source = new Source(); + source.setXmlGregorianCalendar( xmlGregorianCalendar ); + + Target target = SourceTargetMapper.INSTANCE.toTarget( source ); + + LocalDateTime expectedLocalDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30, 50, 500000000 ); + + assertThat( target ).isNotNull(); + assertThat( target.getLocalDateTime() ).isEqualTo( expectedLocalDateTime ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Source.java new file mode 100644 index 0000000000..d79ad6072d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Source.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion; + +import javax.xml.datatype.XMLGregorianCalendar; + +/** + * @author Andrei Arlou + */ +public class Source { + private XMLGregorianCalendar xmlGregorianCalendar; + + public XMLGregorianCalendar getXmlGregorianCalendar() { + return xmlGregorianCalendar; + } + + public void setXmlGregorianCalendar(XMLGregorianCalendar xmlGregorianCalendar) { + this.xmlGregorianCalendar = xmlGregorianCalendar; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java new file mode 100644 index 0000000000..cc456aa0a0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Andrei Arlou + */ +@Mapper +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(source = "xmlGregorianCalendar", target = "localDateTime") + Target toTarget(Source source); + + @Mapping(source = "localDateTime", target = "xmlGregorianCalendar") + Source toSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Target.java new file mode 100644 index 0000000000..b8fc51e6d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/Target.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion; + +import java.time.LocalDateTime; + +/** + * @author Andrei Arlou + */ +public class Target { + private LocalDateTime localDateTime; + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } +} From 55fe94a93ef48464529ba2f9292239deb5d87812 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 22 Sep 2019 10:50:38 +0300 Subject: [PATCH 0398/1006] #1914 Remove unused method Type.isAnnotatedWith (#1915) --- .../ap/internal/model/common/Type.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 9aa996e7e3..c21906f68f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -14,12 +14,10 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; -import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; @@ -380,24 +378,6 @@ private boolean shouldUseSimpleName() { return this.qualifiedName.equals( fqn ); } - /** - * @param annotationTypeName the fully qualified name of the annotation type - * - * @return true, if the type is annotated with an annotation of the specified type (super-types are not inspected) - */ - public boolean isAnnotatedWith(String annotationTypeName) { - List annotationMirrors = typeElement.getAnnotationMirrors(); - - for ( AnnotationMirror mirror : annotationMirrors ) { - Name mirrorAnnotationName = ( (TypeElement) mirror.getAnnotationType().asElement() ).getQualifiedName(); - if ( mirrorAnnotationName.contentEquals( annotationTypeName ) ) { - return true; - } - } - - return false; - } - public Type erasure() { return new Type( typeUtils, From f84f6501c8826490757b8ebe7b768919a050744c Mon Sep 17 00:00:00 2001 From: dekelpilli Date: Sun, 22 Sep 2019 21:53:19 +1000 Subject: [PATCH 0399/1006] #1851 Do not allow using qualifiedBy and qualifiedByName with expression in Mapping --- core/src/main/java/org/mapstruct/Mapping.java | 2 +- .../ap/internal/model/source/Mapping.java | 4 +++ .../mapstruct/ap/internal/util/Message.java | 1 + ...ceTargetMapperExpressionAndQualifiers.java | 29 +++++++++++++++++ .../expressions/java/JavaExpressionTest.java | 32 +++++++++++++++++++ .../expressions/java/QualifierProvider.java | 17 ++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/ErroneousSourceTargetMapperExpressionAndQualifiers.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/QualifierProvider.java diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 01ffcd17a1..a12aeba707 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -136,7 +136,7 @@ * imported via {@link Mapper#imports()}. *

      * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, - * {@link #defaultExpression()} or {@link #constant()}. + * {@link #defaultExpression()}, {@link #qualifiedBy()}, {@link #qualifiedByName()} or {@link #constant()}. * * @return An expression specifying the value for the designated target property */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java index fabd444fc2..789b22126a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Mapping.java @@ -236,6 +236,10 @@ else if ( mappingPrism.values.constant() != null && mappingPrism.values.defaultE else if ( mappingPrism.values.defaultValue() != null && mappingPrism.values.defaultExpression() != null ) { message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } + else if ( mappingPrism.values.expression() != null + && ( mappingPrism.values.qualifiedByName() != null || mappingPrism.values.qualifiedBy() != null ) ) { + message = Message.PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED; + } else if ( mappingPrism.values.nullValuePropertyMappingStrategy() != null && mappingPrism.values.defaultValue() != null ) { message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4ecf757d41..83ad59fcc6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -57,6 +57,7 @@ public enum Message { PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS( "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a constant or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS( "DefaultExpression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_IGNORE_AND_NVPMS( "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, either define ignore or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED("Expression and a qualifier both defined in @Mapping, either define an expression or a qualifier."), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no source parameter named \"%s\". Method source parameters are: \"%s\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/ErroneousSourceTargetMapperExpressionAndQualifiers.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/ErroneousSourceTargetMapperExpressionAndQualifiers.java new file mode 100644 index 0000000000..189fc58b52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/ErroneousSourceTargetMapperExpressionAndQualifiers.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.expressions.java; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; + +@Mapper( uses = QualifierProvider.class, unmappedTargetPolicy = ReportingPolicy.IGNORE ) +public interface ErroneousSourceTargetMapperExpressionAndQualifiers { + + @Mappings( { + @Mapping( target = "anotherProp", expression = "java( s.getClass().getName() )", qualifiedByName = "toUpper" ), + @Mapping( target = "timeAndFormat", ignore = true ) + } ) + Target sourceToTargetWithExpressionAndNamedQualifier(Source s, @MappingTarget Target t); + + @Mappings( { + @Mapping( target = "anotherProp", expression = "java( s.getClass().getName() )", + qualifiedBy = QualifierProvider.ToUpper.class ), + @Mapping( target = "timeAndFormat", ignore = true ) + } ) + Target sourceToTargetWithExpressionAndQualifier(Source s, @MappingTarget Target t); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index 3cec82ea9f..726690ed80 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -17,6 +17,9 @@ import org.mapstruct.ap.test.source.expressions.java.mapper.TimeAndFormat; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** @@ -131,4 +134,33 @@ public void testGetterOnly() throws ParseException { assertThat( target ).isNotNull(); assertThat( target.getList() ).isEqualTo( Arrays.asList( "test2" ) ); } + + @IssueKey( "1851" ) + @Test + @WithClasses({ + Source.class, + Target.class, + QualifierProvider.class, + TimeAndFormat.class, + ErroneousSourceTargetMapperExpressionAndQualifiers.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapperExpressionAndQualifiers.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + messageRegExp = "Expression and a qualifier both defined in @Mapping," + + " either define an expression or a qualifier." + ), + @Diagnostic(type = ErroneousSourceTargetMapperExpressionAndQualifiers.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + messageRegExp = "Expression and a qualifier both defined in @Mapping," + + " either define an expression or a qualifier." + ) + } + ) + public void testExpressionAndQualifiedDoesNotCompile() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/QualifierProvider.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/QualifierProvider.java new file mode 100644 index 0000000000..a5a508b6fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/QualifierProvider.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.expressions.java; + +public class QualifierProvider { + + public @interface ToUpper { + } + + @ToUpper + public String toUpper( String string ) { + return string.toUpperCase(); + } +} From f0a00eb0d574566e0b9ed50e83fda1d6b8d7c9e0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Sep 2019 15:07:04 +0200 Subject: [PATCH 0400/1006] Add Dekel Pilli to copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 4a851d3e74..2aab0c1f80 100644 --- a/copyright.txt +++ b/copyright.txt @@ -14,6 +14,7 @@ Cindy Wang - https://github.com/birdfriend Cornelius Dirmeier - https://github.com/cornzy David Feinblum - https://github.com/dvfeinblum Darren Rambaud - https://github.com/xyzst +Dekel Pilli - https://github.com/dekelpilli Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil Eric Martineau - https://github.com/ericmartineau From 88a86696428bd3e038c7fc7850dc69cb5678c258 Mon Sep 17 00:00:00 2001 From: Dainius Figoras Date: Sun, 22 Sep 2019 17:43:32 +0200 Subject: [PATCH 0401/1006] #1406 targeting . as current object --- .../chapter-3-defining-a-mapper.asciidoc | 30 ++++++ .../ap/internal/model/BeanMappingMethod.java | 30 +++++- .../model/beanmapping/MappingReferences.java | 36 +++++-- .../model/beanmapping/PropertyEntry.java | 4 +- .../model/beanmapping/SourceReference.java | 93 +++++++++++----- .../model/beanmapping/TargetReference.java | 100 ++++++++++-------- .../mapstruct/ap/internal/util/Message.java | 1 - .../ap/test/targetthis/CustomerDTO.java | 37 +++++++ .../ap/test/targetthis/CustomerItem.java | 36 +++++++ .../mapstruct/ap/test/targetthis/ItemDTO.java | 27 +++++ .../ap/test/targetthis/NestedMapper.java | 20 ++++ .../ap/test/targetthis/OrderDTO.java | 29 +++++ .../ap/test/targetthis/OrderItem.java | 27 +++++ .../ap/test/targetthis/SimpleMapper.java | 20 ++++ .../targetthis/SimpleMapperWithIgnore.java | 20 ++++ .../targetthis/TargetThisMappingTest.java | 85 +++++++++++++++ .../runner/JdkCompilingStatement.java | 3 +- 17 files changed, 507 insertions(+), 91 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/ItemDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/NestedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapperWithIgnore.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 352bde0b4e..46513eed0b 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -232,6 +232,36 @@ public interface AddressMapper { In this case the source parameter is directly mapped into the target as the example above demonstrates. The parameter `hn`, a non bean type (in this case `java.lang.Integer`) is mapped to `houseNumber`. +[[mapping-nested-bean-properties-to-current-target]] + === Mapping nested bean properties to current target + + If you don't want explicitly name all properties from nested source bean, you can use `.` as target. + This will tell MapStruct to map every property from source bean to target object. The following shows an example: + + .Nested multi mapping method + ==== + [source, java, linenums] + [subs="verbatim,attributes"] + ---- + @Mapper + public interface CustomerMapper { + + @Mapping(source = "record", target = ".") + Customer customerDtoToCustomer(CustomerDto customerDto); + } + ---- + ==== + + The generated code will map every property from `CustomerDto.record` to `Customer` directly, without need to manually name any of them. + + Multi mapping notation can be very useful when mapping hierarchical objects to flat objects and opposite way. + + [TIP] + ==== + If you need to send your domain object using JSON, one way to do this is to convert it to single object, where every parent class is represented as separate field in JSON. + And MapStruct allows you easily convert between these 2 types. + ==== + [[updating-bean-instances]] === Updating existing bean instances diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 666dfb1aae..43fdfbc805 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -26,6 +26,11 @@ import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; +import org.mapstruct.ap.internal.model.beanmapping.MappingReference; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; +import org.mapstruct.ap.internal.model.beanmapping.SourceReference; +import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -34,14 +39,9 @@ import org.mapstruct.ap.internal.model.source.BeanMapping; import org.mapstruct.ap.internal.model.source.Mapping; import org.mapstruct.ap.internal.model.source.MappingOptions; -import org.mapstruct.ap.internal.model.beanmapping.MappingReference; -import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.model.beanmapping.SourceReference; -import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; @@ -200,6 +200,9 @@ else if ( !method.isUpdateMethod() ) { if ( !mappingReferences.isRestrictToDefinedMappings() ) { + // apply name based mapping from a source reference + applyTargetThisMapping(); + // map properties without a mapping applyPropertyNameBasedMapping(); @@ -650,6 +653,23 @@ else if ( mapping.getJavaExpression() != null ) { return errorOccured; } + /** + * When target this mapping present, iterates over unprocessed targets. + *

      + * When a target property matches its name with the (nested) source property, it is added to the list if and + * only if it is an unprocessed target property. + */ + private void applyTargetThisMapping() { + if ( mappingReferences.getTargetThis() != null ) { + List sourceRefs = mappingReferences.getTargetThis() + .getSourceReference() + .push( ctx.getTypeFactory(), ctx.getMessager(), method ).stream() + .filter( sr -> unprocessedTargetProperties.containsKey( sr.getDeepestPropertyName() ) ) + .collect( Collectors.toList() ); + applyPropertyNameBasedMapping( sourceRefs ); + } + } + /** * Iterates over all target properties and all source parameters. *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index 7cb9a142bb..1a4ede039b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -16,9 +16,10 @@ public class MappingReferences { - private static final MappingReferences EMPTY = new MappingReferences( Collections.emptySet(), false ); + private static final MappingReferences EMPTY = new MappingReferences( Collections.emptySet(), false ); private final Set mappingReferences; + private final MappingReference targetThis; private final boolean restrictToDefinedMappings; private final boolean forForgedMethods; @@ -30,7 +31,7 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, Forma TypeFactory typeFactory) { Set references = new LinkedHashSet<>(); - Set targetThisReferences = new LinkedHashSet<>(); + MappingReference targetThisReference = null; for ( Mapping mapping : sourceMethod.getMappingOptions().getMappings() ) { @@ -42,31 +43,39 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, Forma .build(); // handle target reference - TargetReference targetReference = new TargetReference.BuilderFromTargetMapping().mapping( mapping ) - .method( sourceMethod ) - .messager( messager ) - .typeFactory( typeFactory ) - .build(); + TargetReference targetReference = new TargetReference.Builder().mapping( mapping ) + .method( sourceMethod ) + .messager( messager ) + .typeFactory( typeFactory ) + .build(); // add when inverse is also valid MappingReference mappingReference = new MappingReference( mapping, targetReference, sourceReference ); if ( isValidWhenInversed( mappingReference ) ) { - if ( targetReference.isTargetThis() ) { - targetThisReferences.add( mappingReference ); + if ( ".".equals( mapping.getTargetName() ) ) { + targetThisReference = mappingReference; } else { references.add( mappingReference ); } } } - references.addAll( targetThisReferences ); - return new MappingReferences( references, false ); + return new MappingReferences( references, targetThisReference, false ); + } + + public MappingReferences(Set mappingReferences, MappingReference targetThis, + boolean restrictToDefinedMappings) { + this.mappingReferences = mappingReferences; + this.restrictToDefinedMappings = restrictToDefinedMappings; + this.forForgedMethods = restrictToDefinedMappings; + this.targetThis = targetThis; } public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings) { this.mappingReferences = mappingReferences; this.restrictToDefinedMappings = restrictToDefinedMappings; this.forForgedMethods = restrictToDefinedMappings; + this.targetThis = null; } public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings, @@ -74,6 +83,7 @@ public MappingReferences(Set mappingReferences, boolean restri this.mappingReferences = mappingReferences; this.restrictToDefinedMappings = restrictToDefinedMappings; this.forForgedMethods = forForgedMethods; + this.targetThis = null; } public Set getMappingReferences() { @@ -117,6 +127,9 @@ public boolean hasNestedTargetReferences() { return false; } + public MappingReference getTargetThis() { + return targetThis; + } /** * MapStruct filters automatically inversed invalid methods out. TODO: this is a principle we should discuss! @@ -131,4 +144,5 @@ private static boolean isValidWhenInversed(MappingReference mappingRef) { } return true; } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java index 38335f2c55..f2d087cd93 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java @@ -67,9 +67,9 @@ public static PropertyEntry forTargetReference(String[] fullName, Accessor readA * @param type type of the property * @return the property entry for given parameters. */ - public static PropertyEntry forSourceReference(String name, Accessor readAccessor, + public static PropertyEntry forSourceReference(String[] name, Accessor readAccessor, Accessor presenceChecker, Type type) { - return new PropertyEntry( new String[]{name}, readAccessor, null, presenceChecker, type, null ); + return new PropertyEntry( name, readAccessor, null, presenceChecker, type, null ); } public String getName() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 5176f9b2ec..c06d27c540 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -5,15 +5,14 @@ */ package org.mapstruct.ap.internal.model.beanmapping; -import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; -import static org.mapstruct.ap.internal.util.Collections.last; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; - +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; import javax.lang.model.type.DeclaredType; import org.mapstruct.ap.internal.model.common.Parameter; @@ -26,6 +25,9 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; +import static org.mapstruct.ap.internal.util.Collections.last; + /** * This class describes the source side of a property mapping. *

      @@ -55,18 +57,29 @@ public class SourceReference extends AbstractReference { */ public static class BuilderFromMapping { - private Mapping mapping; private Method method; - private FormattingMessager messager; + private FormattingMessager messager = null; private TypeFactory typeFactory; + private boolean isForwarded = false; + private Method templateMethod = null; + private String sourceName; + private AnnotationMirror annotationMirror; + private AnnotationValue sourceAnnotationValue; + public BuilderFromMapping messager(FormattingMessager messager) { this.messager = messager; return this; } public BuilderFromMapping mapping(Mapping mapping) { - this.mapping = mapping; + this.sourceName = mapping.getSourceName(); + this.annotationMirror = mapping.getMirror(); + this.sourceAnnotationValue = mapping.getSourceAnnotationValue(); + if ( mapping.getInheritContext() != null ) { + isForwarded = mapping.getInheritContext().isForwarded(); + templateMethod = mapping.getInheritContext().getInheritedFromMethod(); + } return this; } @@ -80,19 +93,25 @@ public BuilderFromMapping typeFactory(TypeFactory typeFactory) { return this; } + public BuilderFromMapping sourceName(String sourceName) { + this.sourceName = sourceName; + return this; + } + public SourceReference build() { - String sourceName = mapping.getSourceName(); if ( sourceName == null ) { return null; } + Objects.requireNonNull( messager ); + String sourceNameTrimmed = sourceName.trim(); if ( !sourceName.equals( sourceNameTrimmed ) ) { messager.printMessage( method.getExecutable(), - mapping.getMirror(), - mapping.getSourceAnnotationValue(), + annotationMirror, + sourceAnnotationValue, Message.PROPERTYMAPPING_WHITESPACE_TRIMMED, sourceName, sourceNameTrimmed @@ -207,11 +226,7 @@ private Parameter fetchMatchingParameterFromFirstSegment(String[] segments ) { reportMappingError( Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, parameterName, - Strings.join( - method.getSourceParameters(), - ", ", - Parameter::getName - ) + Strings.join( method.getSourceParameters(), ", ", Parameter::getName ) ); } } @@ -221,8 +236,7 @@ private Parameter fetchMatchingParameterFromFirstSegment(String[] segments ) { private Parameter getSourceParameterFromMethodOrTemplate(String parameterName ) { Parameter result = null; - if ( mapping.getInheritContext() != null && mapping.getInheritContext().isForwarded() ) { - Method templateMethod = mapping.getInheritContext().getInheritedFromMethod(); + if ( isForwarded ) { Parameter parameter = Parameter.getSourceParameter( templateMethod.getParameters(), parameterName ); if ( parameter != null ) { result = method.getSourceParameters() @@ -260,8 +274,7 @@ private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, ); elements.add( mostSimilarWord ); reportMappingError( - Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName(), - Strings.join( elements, "." ) + Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, sourceName, Strings.join( elements, "." ) ); } } @@ -269,19 +282,22 @@ private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, private List matchWithSourceAccessorTypes(Type type, String[] entryNames) { List sourceEntries = new ArrayList<>(); Type newType = type; - for ( String entryName : entryNames ) { + for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; Map sourceReadAccessors = newType.getPropertyReadAccessors(); Map sourcePresenceCheckers = newType.getPropertyPresenceCheckers(); for ( Map.Entry getter : sourceReadAccessors.entrySet() ) { - if ( getter.getKey().equals( entryName ) ) { + if ( getter.getKey().equals( entryNames[i] ) ) { newType = typeFactory.getReturnType( (DeclaredType) newType.getTypeMirror(), getter.getValue() ); - sourceEntries.add( forSourceReference( entryName, getter.getValue(), - sourcePresenceCheckers.get( entryName ), newType + sourceEntries.add( forSourceReference( + Arrays.copyOf( entryNames, i + 1 ), + getter.getValue(), + sourcePresenceCheckers.get( entryNames[i] ), + newType ) ); matchFound = true; break; @@ -295,9 +311,7 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent } private void reportMappingError(Message msg, Object... objects) { - messager.printMessage( method.getExecutable(), mapping.getMirror(), mapping.getSourceAnnotationValue(), - msg, objects - ); + messager.printMessage( method.getExecutable(), annotationMirror, sourceAnnotationValue, msg, objects ); } } @@ -340,7 +354,12 @@ public BuilderFromProperty sourceParameter(Parameter sourceParameter) { public SourceReference build() { List sourcePropertyEntries = new ArrayList<>(); if ( readAccessor != null ) { - sourcePropertyEntries.add( forSourceReference( name, readAccessor, presenceChecker, type ) ); + sourcePropertyEntries.add( forSourceReference( + new String[] { name }, + readAccessor, + presenceChecker, + type + ) ); } return new SourceReference( sourceParameter, sourcePropertyEntries, true ); } @@ -384,4 +403,24 @@ public SourceReference pop() { } } + public List push(TypeFactory typeFactory, FormattingMessager messager, Method method ) { + List result = new ArrayList<>(); + PropertyEntry deepestProperty = getDeepestProperty(); + if ( deepestProperty != null ) { + Type type = deepestProperty.getType(); + Map newDeepestReadAccessors = type.getPropertyReadAccessors(); + for ( Map.Entry newDeepestReadAccessorEntry : newDeepestReadAccessors.entrySet() ) { + String newFullName = deepestProperty.getFullName() + "." + newDeepestReadAccessorEntry.getKey(); + SourceReference sourceReference = new BuilderFromMapping() + .sourceName( newFullName ) + .method( method ) + .messager( messager ) + .typeFactory( typeFactory ) + .build(); + result.add( sourceReference ); + } + } + return result; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index b86c09dc4b..829e57258c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -8,8 +8,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.Set; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; import javax.lang.model.type.DeclaredType; import org.mapstruct.ap.internal.model.common.BuilderType; @@ -56,13 +58,20 @@ public class TargetReference extends AbstractReference { /** * Builds a {@link TargetReference} from an {@code @Mappping}. */ - public static class BuilderFromTargetMapping { + public static class Builder { - private Mapping mapping; private Method method; private FormattingMessager messager; private TypeFactory typeFactory; + // mapping parameters + private boolean isReversed = false; + private boolean isIgnored = false; + private String targetName = null; + private AnnotationMirror annotationMirror = null; + private AnnotationValue targetAnnotationValue = null; + private AnnotationValue sourceAnnotationValue = null; + private Method templateMethod = null; /** * During {@link #getTargetEntries(Type, String[])} an error can occur. However, we are invoking * that multiple times because the first entry can also be the name of the parameter. Therefore we keep @@ -70,31 +79,40 @@ public static class BuilderFromTargetMapping { */ private MappingErrorMessage errorMessage; - public BuilderFromTargetMapping messager(FormattingMessager messager) { + public Builder messager(FormattingMessager messager) { this.messager = messager; return this; } - public BuilderFromTargetMapping mapping(Mapping mapping) { - this.mapping = mapping; + public Builder mapping(Mapping mapping) { + if ( mapping.getInheritContext() != null ) { + this.isReversed = mapping.getInheritContext().isReversed(); + this.templateMethod = mapping.getInheritContext().getInheritedFromMethod(); + } + this.isIgnored = mapping.isIgnored(); + this.targetName = mapping.getTargetName(); + this.annotationMirror = mapping.getMirror(); + this.targetAnnotationValue = mapping.getTargetAnnotationValue(); + this.sourceAnnotationValue = mapping.getSourceAnnotationValue(); return this; } - public BuilderFromTargetMapping method(Method method) { - this.method = method; + public Builder typeFactory(TypeFactory typeFactory) { + this.typeFactory = typeFactory; return this; } - public BuilderFromTargetMapping typeFactory(TypeFactory typeFactory) { - this.typeFactory = typeFactory; + public Builder method(Method method) { + this.method = method; return this; } public TargetReference build() { - boolean isInverse = mapping.getInheritContext() != null && mapping.getInheritContext().isReversed(); + Objects.requireNonNull( method ); + Objects.requireNonNull( typeFactory ); + Objects.requireNonNull( messager ); - String targetName = mapping.getTargetName(); if ( targetName == null ) { return null; } @@ -103,8 +121,8 @@ public TargetReference build() { if ( !targetName.equals( targetNameTrimmed ) ) { messager.printMessage( method.getExecutable(), - mapping.getMirror(), - mapping.getTargetAnnotationValue(), + annotationMirror, + targetAnnotationValue, Message.PROPERTYMAPPING_WHITESPACE_TRIMMED, targetName, targetNameTrimmed @@ -125,13 +143,13 @@ public TargetReference build() { List entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); if ( !foundEntryMatch && segments.length > 1 - && matchesSourceOrTargetParameter( segments[0], parameter, isInverse ) ) { + && matchesSourceOrTargetParameter( segments[0], parameter, isReversed ) ) { targetPropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); entries = getTargetEntries( resultType, targetPropertyNames ); foundEntryMatch = (entries.size() == targetPropertyNames.length); } - if ( !foundEntryMatch && errorMessage != null && !isInverse ) { + if ( !foundEntryMatch && errorMessage != null && !isReversed ) { // This is called only for reporting errors errorMessage.report( ); } @@ -158,7 +176,7 @@ private List getTargetEntries(Type type, String[] entryNames) { boolean isLast = i == entryNames.length - 1; boolean isNotLast = i < entryNames.length - 1; if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast ) - || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, mapping, isLast ) ) { + || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, isIgnored, isLast ) ) { // there should always be a write accessor (except for the last when the mapping is ignored and // there is a read accessor) and there should be read accessor mandatory for all but the last setErrorMessage( targetWriteAccessor, targetReadAccessor, entryNames, i, nextType ); @@ -232,14 +250,14 @@ private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor t private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAccessor, String[] entryNames, int index, Type nextType) { if ( targetWriteAccessor == null && targetReadAccessor == null ) { - errorMessage = new NoPropertyErrorMessage( mapping, method, messager, entryNames, index, nextType ); + errorMessage = new NoPropertyErrorMessage( this, entryNames, index, nextType ); } else if ( targetWriteAccessor == null ) { - errorMessage = new NoWriteAccessorErrorMessage( mapping, method, messager ); + errorMessage = new NoWriteAccessorErrorMessage(this ); } else { //TODO there is no read accessor. What should we do here? - errorMessage = new NoPropertyErrorMessage( mapping, method, messager, entryNames, index, nextType ); + errorMessage = new NoPropertyErrorMessage( this, entryNames, index, nextType ); } } @@ -283,15 +301,15 @@ private static boolean isWriteAccessorNotValidWhenNotLast(Accessor accessor, boo * * @param writeAccessor that needs to be checked * @param readAccessor that is used - * @param mapping that is used + * @param isIgnored true when ignored * @param isLast whether or not this is the last write accessor in the entry chain * * @return {@code true} if the write accessor is not valid, {@code false} otherwise. See description for more * information */ private static boolean isWriteAccessorNotValidWhenLast(Accessor writeAccessor, Accessor readAccessor, - Mapping mapping, boolean isLast) { - return writeAccessor == null && isLast && ( readAccessor == null || !mapping.isIgnored() ); + boolean isIgnored, boolean isLast) { + return writeAccessor == null && isLast && ( readAccessor == null || !isIgnored ); } /** @@ -334,7 +352,6 @@ private boolean matchesSourceOrTargetParameter(String segment, Parameter targetP private boolean matchesSourceOnInverseSourceParameter( String segment, boolean isInverse ) { boolean result = false; if ( isInverse ) { - Method templateMethod = mapping.getInheritContext().getInheritedFromMethod(); // there is only source parameter by definition when applying @InheritInverseConfiguration Parameter inverseSourceParameter = first( templateMethod.getSourceParameters() ); result = inverseSourceParameter.getName().equals( segment ); @@ -347,10 +364,6 @@ private TargetReference(Parameter sourceParameter, List targetPro super( sourceParameter, targetPropertyEntries, isValid ); } - public boolean isTargetThis() { - return getPropertyEntries().isEmpty(); - } - public TargetReference pop() { if ( getPropertyEntries().size() > 1 ) { List newPropertyEntries = new ArrayList<>( getPropertyEntries().size() - 1 ); @@ -368,34 +381,33 @@ public TargetReference pop() { } private abstract static class MappingErrorMessage { - private final Mapping mapping; - private final Method method; - private final FormattingMessager messager; + private final Builder builder; - private MappingErrorMessage(Mapping mapping, Method method, FormattingMessager messager) { - this.mapping = mapping; - this.method = method; - this.messager = messager; + private MappingErrorMessage(Builder builder) { + this.builder = builder; } abstract void report(); protected void printErrorMessage(Message message, Object... args) { Object[] errorArgs = new Object[args.length + 2]; - errorArgs[0] = mapping.getTargetName(); - errorArgs[1] = method.getResultType(); + errorArgs[0] = builder.targetName; + errorArgs[1] = builder.method.getResultType(); System.arraycopy( args, 0, errorArgs, 2, args.length ); - AnnotationMirror annotationMirror = mapping.getMirror(); - messager.printMessage( method.getExecutable(), annotationMirror, mapping.getSourceAnnotationValue(), - message, errorArgs + AnnotationMirror annotationMirror = builder.annotationMirror; + builder.messager.printMessage( builder.method.getExecutable(), + annotationMirror, + builder.sourceAnnotationValue, + message, + errorArgs ); } } private static class NoWriteAccessorErrorMessage extends MappingErrorMessage { - private NoWriteAccessorErrorMessage(Mapping mapping, Method method, FormattingMessager messager) { - super( mapping, method, messager ); + private NoWriteAccessorErrorMessage(Builder builder) { + super( builder ); } @Override @@ -410,9 +422,9 @@ private static class NoPropertyErrorMessage extends MappingErrorMessage { private final int index; private final Type nextType; - private NoPropertyErrorMessage(Mapping mapping, Method method, FormattingMessager messager, - String[] entryNames, int index, Type nextType) { - super( mapping, method, messager ); + private NoPropertyErrorMessage(Builder builder, String[] entryNames, int index, + Type nextType) { + super( builder ); this.entryNames = entryNames; this.index = index; this.nextType = nextType; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 83ad59fcc6..0fad51905d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -154,7 +154,6 @@ public enum Message { VALUEMAPPING_ANY_AREADY_DEFINED( "Source = \"\" or \"\" can only be used once." ), VALUE_MAPPING_UNMAPPED_SOURCES( "The following constants from the %s enum have no corresponding constant in the %s enum and must be be mapped via adding additional mappings: %s." ), VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); - // CHECKSTYLE:ON private final String description; diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerDTO.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerDTO.java new file mode 100644 index 0000000000..c62bef5bb6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerDTO.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +public class CustomerDTO { + private String name; + private int level; + private ItemDTO item; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ItemDTO getItem() { + return item; + } + + public void setItem(ItemDTO item) { + this.item = item; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerItem.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerItem.java new file mode 100644 index 0000000000..8bac4dbb4b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/CustomerItem.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +public class CustomerItem { + private String id; + private int status; + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/ItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/ItemDTO.java new file mode 100644 index 0000000000..409a1caa52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/ItemDTO.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +public class ItemDTO { + private String id; + private int status; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/NestedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/NestedMapper.java new file mode 100644 index 0000000000..e989578a06 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/NestedMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface NestedMapper { + + NestedMapper INSTANCE = Mappers.getMapper( NestedMapper.class ); + + @Mapping( target = ".", source = "customer.item" ) + OrderItem map(OrderDTO order); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderDTO.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderDTO.java new file mode 100644 index 0000000000..eb701f9cde --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderDTO.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +public class OrderDTO { + + private ItemDTO item; + + private CustomerDTO customer; + + public ItemDTO getItem() { + return item; + } + + public void setItem(ItemDTO item) { + this.item = item; + } + + public void setCustomer( CustomerDTO customer ) { + this.customer = customer; + } + + public CustomerDTO getCustomer() { + return this.customer; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderItem.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderItem.java new file mode 100644 index 0000000000..f0c28a3d1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/OrderItem.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +public class OrderItem { + private String id; + private int status; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapper.java new file mode 100644 index 0000000000..46a27b3314 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SimpleMapper { + SimpleMapper INSTANCE = Mappers.getMapper( SimpleMapper.class ); + + @Mapping( target = ".", source = "item" ) + @Mapping( target = "name", ignore = true ) + CustomerItem map(CustomerDTO customer); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapperWithIgnore.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapperWithIgnore.java new file mode 100644 index 0000000000..7db8914f91 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/SimpleMapperWithIgnore.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SimpleMapperWithIgnore { + SimpleMapperWithIgnore INSTANCE = Mappers.getMapper( SimpleMapperWithIgnore.class ); + + @Mapping( target = ".", source = "item" ) + @Mapping( target = "id", ignore = true ) + CustomerItem map(CustomerDTO customer); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java new file mode 100644 index 0000000000..249a697f86 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.targetthis; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses( { + OrderDTO.class, + CustomerDTO.class, + CustomerItem.class, + CustomerItem.class, + ItemDTO.class, + OrderItem.class, + OrderDTO.class +} ) +public class TargetThisMappingTest { + + @Test + @WithClasses( SimpleMapper.class ) + public void testTargetingThis() { + CustomerDTO ce = new CustomerDTO(); + ce.setName( "customer name" ); + + ItemDTO e = new ItemDTO(); + e.setId( "item id" ); + e.setStatus( 1 ); + ce.setItem( e ); + + CustomerItem c = SimpleMapper.INSTANCE.map( ce ); + + assertThat( c ).isNotNull(); + assertThat( c.getName() ).isNull(); + assertThat( c.getId() ).isEqualTo( ce.getItem().getId() ); + assertThat( c.getStatus() ).isEqualTo( ce.getItem().getStatus() ); + } + + @Test + @WithClasses( NestedMapper.class ) + public void testTargetingThisWithNestedLevels() { + CustomerDTO customerDTO = new CustomerDTO(); + customerDTO.setName( "customer name" ); + + ItemDTO itemDTO = new ItemDTO(); + itemDTO.setId( "item id" ); + itemDTO.setStatus( 1 ); + customerDTO.setItem( itemDTO ); + + OrderDTO order = new OrderDTO(); + order.setCustomer( customerDTO ); + + OrderItem c = NestedMapper.INSTANCE.map( order ); + + assertThat( c ).isNotNull(); + assertThat( c.getId() ).isEqualTo( customerDTO.getItem().getId() ); + assertThat( c.getStatus() ).isEqualTo( customerDTO.getItem().getStatus() ); + } + + @Test + @WithClasses( SimpleMapperWithIgnore.class ) + public void testTargetingThisWithIgnore() { + CustomerDTO ce = new CustomerDTO(); + ce.setName( "customer name" ); + + ItemDTO e = new ItemDTO(); + e.setId( "item id" ); + e.setStatus( 1 ); + ce.setItem( e ); + + CustomerItem c = SimpleMapperWithIgnore.INSTANCE.map( ce ); + + assertThat( c ).isNotNull(); + assertThat( c.getName() ).isEqualTo( "customer name" ); + assertThat( c.getId() ).isNull(); + assertThat( c.getStatus() ).isEqualTo( ce.getItem().getStatus() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java index 18838ee51c..454f2c3c3c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import javax.annotation.processing.Processor; import javax.tools.Diagnostic.Kind; @@ -119,7 +120,7 @@ protected List filterExpectedDiagnostics(List Date: Sun, 22 Sep 2019 18:22:11 +0200 Subject: [PATCH 0402/1006] #1799 Fluent setters starting with set should work properly --- .../ap/spi/DefaultAccessorNamingStrategy.java | 28 +++++++--- .../ap/test/bugs/_1799/Issue1799Mapper.java | 20 +++++++ .../ap/test/bugs/_1799/Issue1799Test.java | 37 +++++++++++++ .../mapstruct/ap/test/bugs/_1799/Source.java | 30 +++++++++++ .../mapstruct/ap/test/bugs/_1799/Target.java | 54 +++++++++++++++++++ 5 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 6a8c9baafb..c3c14deb00 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -57,7 +57,8 @@ else if ( isPresenceCheckMethod( method ) ) { } /** - * Returns {@code true} when the {@link ExecutableElement} is a getter method. A method is a getter when it starts + * Returns {@code true} when the {@link ExecutableElement} is a getter method. A method is a getter when it + * has no parameters, starts * with 'get' and the return type is any type other than {@code void}, OR the getter starts with 'is' and the type * returned is a primitive or the wrapper for {@code boolean}. NOTE: the latter does strictly not comply to the bean * convention. The remainder of the name is supposed to reflect the property name. @@ -69,6 +70,10 @@ else if ( isPresenceCheckMethod( method ) ) { * @return {@code true} when the method is a getter. */ public boolean isGetterMethod(ExecutableElement method) { + if ( !method.getParameters().isEmpty() ) { + // If the method has parameters it can't be a getter + return false; + } String methodName = method.getSimpleName().toString(); boolean isNonBooleanGetterName = methodName.startsWith( "get" ) && methodName.length() > 3 && @@ -166,11 +171,22 @@ public boolean isPresenceCheckMethod(ExecutableElement method) { @Override public String getPropertyName(ExecutableElement getterOrSetterMethod) { String methodName = getterOrSetterMethod.getSimpleName().toString(); - if ( methodName.startsWith( "get" ) || methodName.startsWith( "set" ) ) { - return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); - } - else if ( isFluentSetter( getterOrSetterMethod ) ) { - return methodName; + if ( isFluentSetter( getterOrSetterMethod ) ) { + // If this is a fluent setter that starts with set and the 4th character is an uppercase one + // then we treat it as a Java Bean style method (we get the property starting from the 4th character). + // Otherwise we treat it as a fluent setter + // For example, for the following methods: + // * public Builder setSettlementDate(String settlementDate) + // * public Builder settlementDate(String settlementDate) + // We are going to extract the same property name settlementDate + if ( methodName.startsWith( "set" ) + && methodName.length() > 3 + && Character.isUpperCase( methodName.charAt( 3 ) ) ) { + return IntrospectorUtils.decapitalize( methodName.substring( 3 ) ); + } + else { + return methodName; + } } return IntrospectorUtils.decapitalize( methodName.substring( methodName.startsWith( "is" ) ? 2 : 3 ) ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Mapper.java new file mode 100644 index 0000000000..7b695dd146 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1799; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1799Mapper { + + Issue1799Mapper INSTANCE = Mappers.getMapper( Issue1799Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java new file mode 100644 index 0000000000..742c72f717 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1799; + +import java.util.Date; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue1799Mapper.class, + Source.class, + Target.class, +}) +@IssueKey("1799") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue1799Test { + + @Test + public void fluentJavaBeanStyleSettersShouldWork() { + Target target = Issue1799Mapper.INSTANCE.map( new Source( new Date( 150 ), "Switzerland" ) ); + + assertThat( target.getSettlementDate() ).isEqualTo( new Date( 150 ) ); + assertThat( target.getGetawayLocation() ).isEqualTo( "Switzerland" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Source.java new file mode 100644 index 0000000000..dc7153a2f2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Source.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1799; + +import java.util.Date; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final Date settlementDate; + private final String getawayLocation; + + public Source(Date settlementDate, String getawayLocation) { + this.settlementDate = settlementDate; + this.getawayLocation = getawayLocation; + } + + public Date getSettlementDate() { + return settlementDate; + } + + public String getGetawayLocation() { + return getawayLocation; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Target.java new file mode 100644 index 0000000000..992e3d2286 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Target.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1799; + +import java.util.Date; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final Date settlementDate; + private final String getawayLocation; + + public Target(Builder builder) { + this.settlementDate = builder.settlementDate; + this.getawayLocation = builder.getawayLocation; + } + + public Date getSettlementDate() { + return settlementDate; + } + + public String getGetawayLocation() { + return getawayLocation; + } + + public static Target.Builder builder() { + return new Builder(); + } + + public static class Builder { + + private Date settlementDate; + private String getawayLocation; + + public Builder settlementDate(Date settlementDate) { + this.settlementDate = settlementDate; + return this; + } + + public Builder getawayLocation(String getawayLocation) { + this.getawayLocation = getawayLocation; + return this; + } + + public Target build() { + return new Target( this ); + } + } +} From ade4f4d7e2ab87b2e0f113221d3fc9a6729f78cc Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 22 Sep 2019 19:25:43 +0200 Subject: [PATCH 0403/1006] #1821 nullpointer due to @BeanMapping via inheritance (#1822) --- .../ap/internal/model/BeanMappingMethod.java | 7 +- .../ap/internal/model/source/BeanMapping.java | 173 ++++++++++++------ .../ap/internal/model/source/EnumMapping.java | 36 ---- .../model/source/SelectionParameters.java | 17 ++ .../processor/MethodRetrievalProcessor.java | 9 +- .../ap/test/bugs/_1821/Issue1821Mapper.java | 32 ++++ .../ap/test/bugs/_1821/Issue1821Test.java | 24 +++ 7 files changed, 198 insertions(+), 100 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 43fdfbc805..d9103ea64c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -42,7 +42,6 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; @@ -393,7 +392,7 @@ private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) { if ( resultType.isAbstract() ) { ctx.getMessager().printMessage( method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + method.getMappingOptions().getBeanMapping().getMirror(), BEANMAPPING_ABSTRACT, resultType, method.getResultType() @@ -403,7 +402,7 @@ private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) { else if ( !resultType.isAssignableTo( method.getResultType() ) ) { ctx.getMessager().printMessage( method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + method.getMappingOptions().getBeanMapping().getMirror(), BEANMAPPING_NOT_ASSIGNABLE, resultType, method.getResultType() @@ -413,7 +412,7 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) { else if ( !resultType.hasEmptyAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), - BeanMappingPrism.getInstanceOn( method.getExecutable() ).mirror, + method.getMappingOptions().getBeanMapping().getMirror(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, resultType ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index fd96c14c21..47729dbe7b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -6,11 +6,14 @@ package org.mapstruct.ap.internal.model.source; import java.util.List; +import java.util.Objects; import java.util.Optional; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.prism.BeanMappingPrism; import org.mapstruct.ap.internal.prism.BuilderPrism; import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; @@ -36,87 +39,134 @@ public class BeanMapping { private final BuilderPrism builder; private final NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy; + private final AnnotationMirror mirror; + /** - * creates a mapping for inheritance. Will set ignoreByDefault to false. + * creates a mapping for inheritance. Will set + * - ignoreByDefault to false. + * - resultType to null * - * @param map - * @return + * @return new mapping */ - public static BeanMapping forInheritance( BeanMapping map ) { + public static BeanMapping forInheritance(BeanMapping beanMapping) { return new BeanMapping( - map.selectionParameters, - map.nullValueMappingStrategy, - map.nullValuePropertyMappingStrategy, - map.nullValueCheckStrategy, - map.reportingPolicy, + SelectionParameters.forInheritance( beanMapping.selectionParameters ), + beanMapping.nullValueMappingStrategy, + beanMapping.nullValuePropertyMappingStrategy, + beanMapping.nullValueCheckStrategy, + beanMapping.reportingPolicy, false, - map.ignoreUnmappedSourceProperties, - map.builder + beanMapping.ignoreUnmappedSourceProperties, + beanMapping.builder, + beanMapping.mirror ); } - public static BeanMapping fromPrism(BeanMappingPrism beanMapping, ExecutableElement method, - FormattingMessager messager, Types typeUtils) { - - if ( beanMapping == null ) { - return null; - } - - boolean resultTypeIsDefined = !TypeKind.VOID.equals( beanMapping.resultType().getKind() ); + public static class Builder { - NullValueMappingStrategyPrism nullValueMappingStrategy = - null == beanMapping.values.nullValueMappingStrategy() - ? null - : NullValueMappingStrategyPrism.valueOf( beanMapping.nullValueMappingStrategy() ); + private BeanMappingPrism prism; + private ExecutableElement method; + private FormattingMessager messager; + private Types typeUtils; + private TypeFactory typeFactory; - NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy = - null == beanMapping.values.nullValuePropertyMappingStrategy() - ? null - : NullValuePropertyMappingStrategyPrism.valueOf( beanMapping.nullValuePropertyMappingStrategy() ); - - NullValueCheckStrategyPrism nullValueCheckStrategy = - null == beanMapping.values.nullValueCheckStrategy() - ? null - : NullValueCheckStrategyPrism.valueOf( beanMapping.nullValueCheckStrategy() ); + public Builder beanMappingPrism(BeanMappingPrism beanMappingPrism) { + this.prism = beanMappingPrism; + return this; + } - boolean ignoreByDefault = beanMapping.ignoreByDefault(); - BuilderPrism builderMapping = null; - if ( beanMapping.values.builder() != null ) { - builderMapping = beanMapping.builder(); + public Builder method(ExecutableElement method) { + this.method = method; + return this; } - if ( !resultTypeIsDefined && beanMapping.qualifiedBy().isEmpty() && beanMapping.qualifiedByName().isEmpty() - && beanMapping.ignoreUnmappedSourceProperties().isEmpty() - && ( nullValueMappingStrategy == null ) && ( nullValuePropertyMappingStrategy == null ) - && ( nullValueCheckStrategy == null ) && !ignoreByDefault && builderMapping == null ) { + public Builder messager(FormattingMessager messager) { + this.messager = messager; + return this; + } - messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); + public Builder typeUtils(Types typeUtils) { + this.typeUtils = typeUtils; + return this; } - SelectionParameters cmp = new SelectionParameters( - beanMapping.qualifiedBy(), - beanMapping.qualifiedByName(), - resultTypeIsDefined ? beanMapping.resultType() : null, - typeUtils - ); + public Builder typeFactory(TypeFactory typeFactory) { + this.typeFactory = typeFactory; + return this; + } - //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? - return new BeanMapping( - cmp, - nullValueMappingStrategy, - nullValuePropertyMappingStrategy, - nullValueCheckStrategy, - null, - ignoreByDefault, - beanMapping.ignoreUnmappedSourceProperties(), - builderMapping - ); + public BeanMapping build() { + + if ( prism == null ) { + return null; + } + + Objects.requireNonNull( method ); + Objects.requireNonNull( messager ); + Objects.requireNonNull( method ); + Objects.requireNonNull( typeUtils ); + Objects.requireNonNull( typeFactory ); + + boolean resultTypeIsDefined = !TypeKind.VOID.equals( prism.resultType().getKind() ); + + NullValueMappingStrategyPrism nullValueMappingStrategy = + null == prism.values.nullValueMappingStrategy() + ? null + : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + + NullValuePropertyMappingStrategyPrism nullValuePropertyMappingStrategy = + null == prism.values.nullValuePropertyMappingStrategy() + ? null + : + NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + + NullValueCheckStrategyPrism nullValueCheckStrategy = + null == prism.values.nullValueCheckStrategy() + ? null + : NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + + boolean ignoreByDefault = prism.ignoreByDefault(); + BuilderPrism builderMapping = null; + if ( prism.values.builder() != null ) { + builderMapping = prism.builder(); + } + + if ( !resultTypeIsDefined && prism.qualifiedBy().isEmpty() && + prism.qualifiedByName().isEmpty() + && prism.ignoreUnmappedSourceProperties().isEmpty() + && ( nullValueMappingStrategy == null ) && ( nullValuePropertyMappingStrategy == null ) + && ( nullValueCheckStrategy == null ) && !ignoreByDefault && builderMapping == null ) { + + messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); + } + + SelectionParameters cmp = new SelectionParameters( + prism.qualifiedBy(), + prism.qualifiedByName(), + resultTypeIsDefined ? prism.resultType() : null, + typeUtils + ); + + //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? + return new BeanMapping( + cmp, + nullValueMappingStrategy, + nullValuePropertyMappingStrategy, + nullValueCheckStrategy, + null, + ignoreByDefault, + prism.ignoreUnmappedSourceProperties(), + builderMapping, + prism.mirror + ); + } } private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStrategyPrism nvms, NullValuePropertyMappingStrategyPrism nvpms, NullValueCheckStrategyPrism nvcs, ReportingPolicyPrism reportingPolicy, boolean ignoreByDefault, - List ignoreUnmappedSourceProperties, BuilderPrism builder) { + List ignoreUnmappedSourceProperties, BuilderPrism builder, + AnnotationMirror mirror) { this.selectionParameters = selectionParameters; this.nullValueMappingStrategy = nvms; this.nullValuePropertyMappingStrategy = nvpms; @@ -125,6 +175,7 @@ private BeanMapping(SelectionParameters selectionParameters, NullValueMappingStr this.ignoreByDefault = ignoreByDefault; this.ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties; this.builder = builder; + this.mirror = mirror; } public SelectionParameters getSelectionParameters() { @@ -155,6 +206,10 @@ public List getIgnoreUnmappedSourceProperties() { return ignoreUnmappedSourceProperties; } + public AnnotationMirror getMirror() { + return mirror; + } + /** * derives the builder prism given the options and configuration * @param method containing mandatory configuration and the mapping options (optionally containing a beanmapping) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java deleted file mode 100644 index 2c13344d20..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMapping.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.model.source; - -/** - * Represents the mapping between one enum constant and another. - * - * @author Gunnar Morling - */ -public class EnumMapping { - - private final String source; - private final String target; - - public EnumMapping(String source, String target) { - this.source = source; - this.target = target; - } - - /** - * @return the name of the constant in the source enum. - */ - public String getSource() { - return source; - } - - /** - * @return the name of the constant in the target enum. - */ - public String getTarget() { - return target; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index cdbf745604..34eb0a7d80 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -26,6 +26,23 @@ public class SelectionParameters { private final Types typeUtils; private final SourceRHS sourceRHS; + /** + * Returns new selection parameters + * + * ResultType is not inherited. + * + * @param selectionParameters + * @return + */ + public static SelectionParameters forInheritance(SelectionParameters selectionParameters) { + return new SelectionParameters( + selectionParameters.qualifiers, + selectionParameters.qualifyingNames, + null, + selectionParameters.typeUtils + ); + } + public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, Types typeUtils) { this( qualifiers, qualifyingNames, resultType, typeUtils, null ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index ffef1656d3..e7e2db260e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -254,7 +254,14 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setMapMapping( MapMapping.fromPrism( MapMappingPrism.getInstanceOn( method ), method, messager, typeUtils ) ) .setBeanMapping( - BeanMapping.fromPrism( BeanMappingPrism.getInstanceOn( method ), method, messager, typeUtils ) ) + new BeanMapping.Builder() + .beanMappingPrism( BeanMappingPrism.getInstanceOn( method ) ) + .messager( messager ) + .method( method ) + .typeUtils( typeUtils ) + .typeFactory( typeFactory ) + .build() + ) .setValueMappings( getValueMappings( method ) ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java new file mode 100644 index 0000000000..08eccae32e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1821; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue1821Mapper { + + Issue1821Mapper INSTANCE = Mappers.getMapper( Issue1821Mapper.class ); + + @BeanMapping( resultType = Target.class ) + Target map(Source source); + + @InheritConfiguration( name = "map" ) + ExtendedTarget mapExtended(Source source); + + class Target { + } + + class ExtendedTarget extends Target { + } + + class Source { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java new file mode 100644 index 0000000000..aa309e7fce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1821; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@IssueKey("1797") +@RunWith( AnnotationProcessorTestRunner.class) +@WithClasses( Issue1821Mapper.class ) +public class Issue1821Test { + + @Test + public void shouldNotGiveNullPtr() { + Issue1821Mapper.INSTANCE.map( new Issue1821Mapper.Source() ); + } + +} From 70de843bea86354f9c8c8c403ffbb0a1ace95859 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 22 Sep 2019 20:41:35 +0300 Subject: [PATCH 0404/1006] #1911 Change return type MapperConfiguration.getBuilderPrism from Optional to BuilderPrism (#1912) --- .../model/AbstractMappingMethodBuilder.java | 2 +- .../model/BuilderFinisherMethodResolver.java | 13 ++++++------- .../ap/internal/model/PropertyMapping.java | 7 +++---- .../internal/model/beanmapping/TargetReference.java | 4 ++-- .../ap/internal/model/source/BeanMapping.java | 4 ++-- .../ap/internal/model/source/MappingOptions.java | 2 +- .../internal/processor/MapperCreationProcessor.java | 2 +- .../ap/internal/util/MapperConfiguration.java | 11 +++++------ 8 files changed, 21 insertions(+), 24 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index a5da9d0532..69dad8e0c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -58,7 +58,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { return createForgedAssignment( sourceRHS, ctx.getTypeFactory() - .builderTypeFor( targetType, BeanMapping.builderPrismFor( method ).orElse( null ) ), + .builderTypeFor( targetType, BeanMapping.builderPrismFor( method ) ), forgedMethod ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index 9f44085809..90487d69c1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.model; import java.util.Collection; -import java.util.Optional; import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.BuilderType; @@ -36,14 +35,14 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp return null; } - Optional builderMapping = BeanMapping.builderPrismFor( method ); - if ( !builderMapping.isPresent() && buildMethods.size() == 1 ) { + BuilderPrism builderMapping = BeanMapping.builderPrismFor( method ); + if ( builderMapping == null && buildMethods.size() == 1 ) { return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() ); } else { String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME; - if ( builderMapping.isPresent() ) { - buildMethodPattern = builderMapping.get().buildMethod(); + if ( builderMapping != null ) { + buildMethodPattern = builderMapping.buildMethod(); } for ( ExecutableElement buildMethod : buildMethods ) { String methodName = buildMethod.getSimpleName().toString(); @@ -52,7 +51,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp } } - if ( !builderMapping.isPresent() ) { + if ( builderMapping == null ) { ctx.getMessager().printMessage( method.getExecutable(), Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT, @@ -65,7 +64,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp else { ctx.getMessager().printMessage( method.getExecutable(), - builderMapping.get().mirror, + builderMapping.mirror, Message.BUILDER_NO_BUILD_METHOD_FOUND, buildMethodPattern, builderType.getBuilder(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 628d00cc4e..7fc619bac1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -110,7 +110,7 @@ public T targetReadAccessor(Accessor targetReadAccessor) { public T targetWriteAccessor(Accessor targetWriteAccessor) { this.targetWriteAccessor = targetWriteAccessor; this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() ); - BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ); this.targetBuilderType = ctx.getTypeFactory().builderTypeFor( this.targetType, builderPrism ); this.targetWriteAccessorType = targetWriteAccessor.getAccessorType(); return (T) this; @@ -278,7 +278,7 @@ public PropertyMapping build() { criteria, rightHandSide, positionHint, - () -> forge( ) + this::forge ); } else { @@ -504,7 +504,7 @@ private Assignment assignToCollection(Type targetType, AccessorType targetAccess private Assignment assignToArray(Type targetType, Assignment rightHandSide) { Type arrayType = ctx.getTypeFactory().getType( Arrays.class ); - Assignment assignment = new ArrayCopyWrapper( + return new ArrayCopyWrapper( rightHandSide, targetPropertyName, arrayType, @@ -512,7 +512,6 @@ private Assignment assignToArray(Type targetType, Assignment rightHandSide) { isFieldAssignment(), nvpms == SET_TO_NULL && !targetType.isPrimitive(), nvpms == SET_TO_DEFAULT ); - return assignment; } private SourceRHS getSourceRHS( SourceReference sourceReference ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index 829e57258c..2ca8b9ca37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -203,7 +203,7 @@ private List getTargetEntries(Type type, String[] entryNames) { ); } else { - BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ); builderType = typeFactory.builderTypeFor( nextType, builderPrism ); propertyEntry = PropertyEntry.forTargetReference( fullName, targetReadAccessor, @@ -271,7 +271,7 @@ private Type typeBasedOnMethod(Type type) { return type; } else { - BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ); return typeFactory.effectiveResultTypeFor( type, builderPrism ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java index 47729dbe7b..5997956ad2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMapping.java @@ -213,9 +213,9 @@ public AnnotationMirror getMirror() { /** * derives the builder prism given the options and configuration * @param method containing mandatory configuration and the mapping options (optionally containing a beanmapping) - * @return a BuilderPrism as optional + * @return null if BuilderPrism not exist */ - public static Optional builderPrismFor(Method method) { + public static BuilderPrism builderPrismFor(Method method) { return method.getMapperConfiguration() .getBuilderPrism( Optional.ofNullable( method.getMappingOptions().getBeanMapping() ) .map( b -> b.builder ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 95a93b422a..30f4060823 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -179,7 +179,7 @@ public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { if ( !method.isUpdateMethod() ) { writeType = typeFactory.effectiveResultTypeFor( writeType, - BeanMapping.builderPrismFor( method ).orElse( null ) + BeanMapping.builderPrismFor( method ) ); } Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 783e90dff4..f5d924002f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -360,7 +360,7 @@ else if ( method.isStreamMapping() ) { } else { this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); - BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ).orElse( null ); + BuilderPrism builderPrism = BeanMapping.builderPrismFor( method ); BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = builder .mappingContext( mappingContext ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java index be4622c7ed..5eb5427581 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MapperConfiguration.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; -import java.util.Optional; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -279,18 +278,18 @@ public boolean isDisableSubMappingMethodsGeneration() { return mapperPrism.disableSubMappingMethodsGeneration(); // fall back to default defined in the annotation } - public Optional getBuilderPrism(BuilderPrism beanMappingBuilderPrism) { + public BuilderPrism getBuilderPrism(BuilderPrism beanMappingBuilderPrism) { if ( beanMappingBuilderPrism != null ) { - return Optional.ofNullable( beanMappingBuilderPrism ); + return beanMappingBuilderPrism; } else if ( mapperPrism.values.builder() != null ) { - return Optional.ofNullable( mapperPrism.builder() ); + return mapperPrism.builder(); } else if ( mapperConfigPrism != null && mapperConfigPrism.values.builder() != null ) { - return Optional.ofNullable( mapperConfigPrism.builder() ); + return mapperConfigPrism.builder(); } else { - return Optional.empty(); + return null; } } From 61f941aa804f0bbc8a5908a6e15823f1b6dc2dec Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sun, 22 Sep 2019 21:25:57 +0300 Subject: [PATCH 0405/1006] #166 Add code-examples to Javadoc of org.mapstruct.* annotations (#1876) --- .../main/java/org/mapstruct/BeanMapping.java | 32 +++++- core/src/main/java/org/mapstruct/Builder.java | 26 +++++ .../InheritInverseConfiguration.java | 35 ++++++ .../java/org/mapstruct/IterableMapping.java | 27 ++++- .../main/java/org/mapstruct/MapMapping.java | 32 +++++- core/src/main/java/org/mapstruct/Mapper.java | 52 +++++++++ .../main/java/org/mapstruct/MapperConfig.java | 30 +++++ core/src/main/java/org/mapstruct/Mapping.java | 108 ++++++++++++++++++ .../java/org/mapstruct/MappingTarget.java | 37 ++++++ .../src/main/java/org/mapstruct/Mappings.java | 26 +++++ .../main/java/org/mapstruct/Qualifier.java | 56 ++++++++- .../main/java/org/mapstruct/TargetType.java | 29 +++++ .../java/org/mapstruct/ValueMappings.java | 25 ++++ 13 files changed, 505 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index 6b062dac99..55ab05ae5e 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -18,6 +18,34 @@ *

      * Either {@link #resultType()}, {@link #qualifiedBy()} or {@link #nullValueMappingStrategy()} must be specified. *

      + *

      Example: Determining the result type

      + *
      
      + * // When result types have an inheritance relation, selecting either mapping method {@link Mapping} or factory method
      + * // {@link BeanMapping} can be become ambiguous. Parameter  {@link BeanMapping#resultType()} can be used.
      + * public class FruitFactory {
      + *     public Apple createApple() {
      + *         return new Apple();
      + *     }
      + *     public Orange createOrange() {
      + *         return new Orange();
      + *     }
      + * }
      + * @Mapper(uses = FruitFactory.class)
      + * public interface FruitMapper {
      + *     @BeanMapping(resultType = Apple.class)
      + *     Fruit toFruit(FruitDto fruitDto);
      + * }
      + * 
      + *
      
      + * // generates
      + * public class FruitMapperImpl implements FruitMapper {
      + *      @Override
      + *      public Fruit toFruit(FruitDto fruitDto) {
      + *          Apple fruit = fruitFactory.createApple();
      + *          // ...
      + *      }
      + * }
      + * 
      * * @author Sjaak Derksen */ @@ -40,9 +68,9 @@ * A qualifier is a custom annotation and can be placed on either a hand written mapper class or a method. * * @return the qualifiers - * @see BeanMapping#qualifiedByName() + * @see Qualifier */ - Class[] qualifiedBy() default { }; + Class[] qualifiedBy() default {}; /** * Similar to {@link #qualifiedBy()}, but used in combination with {@code @}{@link Named} in case no custom diff --git a/core/src/main/java/org/mapstruct/Builder.java b/core/src/main/java/org/mapstruct/Builder.java index 2f3c9b2e90..449c4ac05c 100644 --- a/core/src/main/java/org/mapstruct/Builder.java +++ b/core/src/main/java/org/mapstruct/Builder.java @@ -14,6 +14,32 @@ /** * Configuration of builders, e.g. the name of the final build method. * + *

      + * Example: Using builder + *

      + *
      
      + * // Mapper
      + * @Mapper
      + * public interface SimpleBuilderMapper {
      + *      @Mapping(target = "name", source = "fullName"),
      + *      @Mapping(target = "job", constant = "programmer"),
      + *      SimpleImmutablePerson toImmutable(SimpleMutablePerson source);
      + * }
      + * 
      + *
      
      + * // generates
      + * @Override
      + * public SimpleImmutablePerson toImmutable(SimpleMutablePerson source) {
      + *      // name method can be changed with parameter {@link #buildMethod()}
      + *      Builder simpleImmutablePerson = SimpleImmutablePerson.builder();
      + *      simpleImmutablePerson.name( source.getFullName() );
      + *      simpleImmutablePerson.age( source.getAge() );
      + *      simpleImmutablePerson.address( source.getAddress() );
      + *      simpleImmutablePerson.job( "programmer" );
      + *      // ...
      + * }
      + * 
      + * * @author Filip Hrisafov * * @since 1.3 diff --git a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java index d1bede3f05..b1eec47f34 100644 --- a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java +++ b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java @@ -22,6 +22,41 @@ * If more than one matching inverse method exists, the name of the method to inherit the configuration from must be * specified via {@link #name()} * + *

      + * Example + *

      + *
      
      + * @Mapper
      + * public interface HumanMapper {
      + *      Human toHuman(HumanDto humanDto);
      + *      @InheritInverseConfiguration
      + *      HumanDto toHumanDto(Human human);
      + * }
      + * 
      + *
      
      + * // generates
      + * public class HumanMapperImpl implements HumanMapper {
      + *      @Override
      + *      public Human toHuman(HumanDto humanDto) {
      + *          if ( humanDto == null ) {
      + *              return null;
      + *           }
      + *          Human human = new Human();
      + *          human.setName( humanDto.getName() );
      + *          return human;
      + *      }
      + *      @Override
      + *      public HumanDto toHumanDto(Human human) {
      + *          if ( human == null ) {
      + *              return null;
      + *          }
      + *          HumanDto humanDto = new HumanDto();
      + *          humanDto.setName( human.getName() );
      + *          return humanDto;
      + *      }
      + * }
      + * 
      + * * @author Sjaak Derksen */ @Target(ElementType.METHOD) diff --git a/core/src/main/java/org/mapstruct/IterableMapping.java b/core/src/main/java/org/mapstruct/IterableMapping.java index 0e81e66126..3041c4bfd0 100644 --- a/core/src/main/java/org/mapstruct/IterableMapping.java +++ b/core/src/main/java/org/mapstruct/IterableMapping.java @@ -18,9 +18,33 @@ * Configures the mapping between two iterable like types, e.g. {@code List} and {@code List}. * * - *

      Note: either @IterableMapping#dateFormat, @IterableMapping#resultType or @IterableMapping#qualifiedBy + *

      Note: either {@link #dateFormat()}, {@link #elementTargetType()} or {@link #qualifiedBy() } * must be specified

      * + *

      + * Example: Convert List<Float> to List<String> + *

      + *
      
      + * @Mapper
      + * public interface FloatToStringMapper {
      + *      @IterableMapping( numberFormat = "##.00" )
      + *      List<String> sourceToTarget(List<Float> source);
      + * }
      + * 
      + *
      
      + * // generates
      + * public class FloatToStringMapperImpl implements FloatToStringMapper {
      + *      @Override
      + *      public List<String> sourceToTarget(List<Float> source) {
      + *          List<String> list = new ArrayList<String>( source.size() );
      + *          for ( Float float1 : source ) {
      + *              list.add( new DecimalFormat( "##.00" ).format( float1 ) );
      + *          }
      + *     // ...
      + *      }
      + * }
      + * 
      + * * Supported mappings are: * *

      - * For reading annotation attributes, prisms as generated with help of the Hickory tool are used. These prisms allow a comfortable access to + * For reading annotation attributes, gems as generated with help of the Hickory tool are used. These gems allow a comfortable access to * annotations and their attributes without depending on their class objects. *

      * The creation of Java source files is done using the FreeMarker template engine. @@ -137,7 +137,7 @@ private Options createOptions() { return new Options( Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), - unmappedTargetPolicy != null ? ReportingPolicyPrism.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, + unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), @@ -236,7 +236,7 @@ private Set getMappers(final Set annotations // on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with // annotations unknown to the compiler, even though they are not declared Mappers - if ( mapperTypeElement != null && MapperPrism.getInstanceOn( mapperTypeElement ) != null ) { + if ( mapperTypeElement != null && MapperGem.instanceOn( mapperTypeElement ) != null ) { mapperTypes.add( mapperTypeElement ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/CollectionMappingStrategyGem.java similarity index 63% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/CollectionMappingStrategyGem.java index 457607d7c7..f88e21a763 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/CollectionMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/CollectionMappingStrategyGem.java @@ -3,14 +3,14 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.CollectionMappingStrategy} + * Gem for the enum {@link org.mapstruct.CollectionMappingStrategy} * * @author Andreas Gudian */ -public enum CollectionMappingStrategyPrism { +public enum CollectionMappingStrategyGem { ACCESSOR_ONLY, SETTER_PREFERRED, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java new file mode 100644 index 0000000000..6852f013e7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -0,0 +1,65 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.gem; + +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlElementRef; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeanMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Builder; +import org.mapstruct.Context; +import org.mapstruct.DecoratedWith; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.Mappings; +import org.mapstruct.Named; +import org.mapstruct.ObjectFactory; +import org.mapstruct.Qualifier; +import org.mapstruct.TargetType; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.tools.gem.GemDefinition; + +/** + * Triggers the generation of ge types using Hickory. + * + * @author Gunnar Morling + */ +@GemDefinition(Mapper.class) +@GemDefinition(Mapping.class) +@GemDefinition(Mappings.class) +@GemDefinition(IterableMapping.class) +@GemDefinition(BeanMapping.class) +@GemDefinition(MapMapping.class) +@GemDefinition(TargetType.class) +@GemDefinition(MappingTarget.class) +@GemDefinition(DecoratedWith.class) +@GemDefinition(MapperConfig.class) +@GemDefinition(InheritConfiguration.class) +@GemDefinition(InheritInverseConfiguration.class) +@GemDefinition(Qualifier.class) +@GemDefinition(Named.class) +@GemDefinition(ObjectFactory.class) +@GemDefinition(AfterMapping.class) +@GemDefinition(BeforeMapping.class) +@GemDefinition(ValueMapping.class) +@GemDefinition(ValueMappings.class) +@GemDefinition(Context.class) +@GemDefinition(Builder.class) + +// external types +@GemDefinition(XmlElementDecl.class) +@GemDefinition(XmlElementRef.class) +public class GemGenerator { +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java similarity index 60% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java index 839bc26f9c..f8ed93eeb4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/InjectionStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java @@ -3,14 +3,14 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.InjectionStrategy}. + * Gem for the enum {@link org.mapstruct.InjectionStrategy}. * * @author Kevin Grüneberg */ -public enum InjectionStrategyPrism { +public enum InjectionStrategyGem { FIELD, CONSTRUCTOR; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java similarity index 67% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index c03bac6a7e..b988ccde40 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingConstantsPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -3,16 +3,16 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.MappingConstants} + * Gem for the enum {@link org.mapstruct.MappingConstants} * * @author Sjaak Derksen */ -public final class MappingConstantsPrism { +public final class MappingConstantsGem { - private MappingConstantsPrism() { + private MappingConstantsGem() { } public static final String NULL = ""; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingInheritanceStrategyGem.java similarity index 76% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/MappingInheritanceStrategyGem.java index 7ea4ce8bbc..b07030d8fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/MappingInheritanceStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingInheritanceStrategyGem.java @@ -3,15 +3,15 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.MappingInheritanceStrategy} + * Gem for the enum {@link org.mapstruct.MappingInheritanceStrategy} * * @author Andreas Gudian */ -public enum MappingInheritanceStrategyPrism { +public enum MappingInheritanceStrategyGem { EXPLICIT( false, false, false ), AUTO_INHERIT_FROM_CONFIG( true, true, false ), @@ -22,7 +22,7 @@ public enum MappingInheritanceStrategyPrism { private final boolean applyForward; private final boolean applyReverse; - MappingInheritanceStrategyPrism(boolean isAutoInherit, boolean applyForward, boolean applyReverse) { + MappingInheritanceStrategyGem(boolean isAutoInherit, boolean applyForward, boolean applyReverse) { this.autoInherit = isAutoInherit; this.applyForward = applyForward; this.applyReverse = applyReverse; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueCheckStrategyGem.java similarity index 60% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueCheckStrategyGem.java index 555231f987..b7ab803232 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueCheckStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueCheckStrategyGem.java @@ -3,15 +3,15 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.NullValueCheckStrategy} + * Gem for the enum {@link org.mapstruct.NullValueCheckStrategy} * * @author Sean Huang */ -public enum NullValueCheckStrategyPrism { +public enum NullValueCheckStrategyGem { ON_IMPLICIT_CONVERSION, ALWAYS; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueMappingStrategyGem.java similarity index 65% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueMappingStrategyGem.java index bd5f05ff76..3d8991f820 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValueMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValueMappingStrategyGem.java @@ -3,21 +3,21 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.NullValueMappingStrategy} + * Gem for the enum {@link org.mapstruct.NullValueMappingStrategy} * * @author Sjaak Derksen */ -public enum NullValueMappingStrategyPrism { +public enum NullValueMappingStrategyGem { RETURN_NULL( false ), RETURN_DEFAULT( true ); private final boolean returnDefault; - NullValueMappingStrategyPrism(boolean returnDefault) { + NullValueMappingStrategyGem(boolean returnDefault) { this.returnDefault = returnDefault; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java similarity index 58% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java index bc0cdae9e7..77e4aa48d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/NullValuePropertyMappingStrategyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java @@ -3,15 +3,15 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; /** - * Prism for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy} + * Gem for the enum {@link org.mapstruct.NullValuePropertyMappingStrategy} * * @author Sjaak Derksen */ -public enum NullValuePropertyMappingStrategyPrism { +public enum NullValuePropertyMappingStrategyGem { SET_TO_NULL, SET_TO_DEFAULT, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/ReportingPolicyGem.java similarity index 78% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/ReportingPolicyGem.java index 8c06231447..d985c79709 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/ReportingPolicyPrism.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/ReportingPolicyGem.java @@ -3,17 +3,17 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; import javax.tools.Diagnostic; import javax.tools.Diagnostic.Kind; /** - * Prism for the enum {@link org.mapstruct.ReportingPolicy}. + * Gem for the enum {@link org.mapstruct.ReportingPolicy}. * * @author Gunnar Morling */ -public enum ReportingPolicyPrism { +public enum ReportingPolicyGem { IGNORE( null, false, false ), WARN( Kind.WARNING, true, false ), @@ -23,7 +23,7 @@ public enum ReportingPolicyPrism { private final boolean requiresReport; private final boolean failsBuild; - ReportingPolicyPrism(Diagnostic.Kind diagnosticKind, boolean requiresReport, boolean failsBuild) { + ReportingPolicyGem(Diagnostic.Kind diagnosticKind, boolean requiresReport, boolean failsBuild) { this.requiresReport = requiresReport; this.diagnosticKind = diagnosticKind; this.failsBuild = failsBuild; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/package-info.java similarity index 52% rename from processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java rename to processor/src/main/java/org/mapstruct/ap/internal/gem/package-info.java index 4c5a19a855..b5f4330e4e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/package-info.java @@ -5,7 +5,7 @@ */ /** *

      - * This package contains the generated prism types for accessing the MapStruct annotations in a comfortable way. + * This package contains the generated gem types for accessing the MapStruct annotations in a comfortable way. *

      */ -package org.mapstruct.ap.internal.prism; +package org.mapstruct.ap.internal.gem; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 8f0092578c..019f941741 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -8,7 +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.prism.BuilderPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.util.Strings; import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; @@ -54,11 +54,11 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { sourceRHS.getSourceErrorMessagePart() ); ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true ); - BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism(); + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); return createForgedAssignment( sourceRHS, - ctx.getTypeFactory().builderTypeFor( targetType, builderPrism ), + ctx.getTypeFactory().builderTypeFor( targetType, builder ), forgedMethod ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index e193b19ffa..af14d384c1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -40,8 +40,8 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -158,7 +158,7 @@ else if ( !method.isUpdateMethod() ) { /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; - CollectionMappingStrategyPrism cms = this.method.getOptions().getMapper().getCollectionMappingStrategy(); + CollectionMappingStrategyGem cms = this.method.getOptions().getMapper().getCollectionMappingStrategy(); // determine accessors Map accessors = resultTypeToMap.getPropertyWriteAccessors( cms ); @@ -823,9 +823,9 @@ private MappingReferences extractMappingReferences(String targetProperty, boolea return null; } - private ReportingPolicyPrism getUnmappedTargetPolicy() { + private ReportingPolicyGem getUnmappedTargetPolicy() { if ( mappingReferences.isForForgedMethods() ) { - return ReportingPolicyPrism.IGNORE; + return ReportingPolicyGem.IGNORE; } return method.getOptions().getMapper().unmappedTargetPolicy(); } @@ -833,7 +833,7 @@ private ReportingPolicyPrism getUnmappedTargetPolicy() { private void reportErrorForUnmappedTargetPropertiesIfRequired() { // fetch settings from element to implement - ReportingPolicyPrism unmappedTargetPolicy = getUnmappedTargetPolicy(); + ReportingPolicyGem unmappedTargetPolicy = getUnmappedTargetPolicy(); if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) { //TODO until we solve 1140 we report this error when the target properties are empty @@ -904,15 +904,15 @@ else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.require } } - private ReportingPolicyPrism getUnmappedSourcePolicy() { + private ReportingPolicyGem getUnmappedSourcePolicy() { if ( mappingReferences.isForForgedMethods() ) { - return ReportingPolicyPrism.IGNORE; + return ReportingPolicyGem.IGNORE; } return method.getOptions().getMapper().unmappedSourcePolicy(); } private void reportErrorForUnmappedSourcePropertiesIfRequired() { - ReportingPolicyPrism unmappedSourcePolicy = getUnmappedSourcePolicy(); + ReportingPolicyGem unmappedSourcePolicy = getUnmappedSourcePolicy(); if ( !unprocessedSourceProperties.isEmpty() && unmappedSourcePolicy.requiresReport() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index e1a586c522..d72e7cef9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -10,7 +10,7 @@ import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.prism.BuilderPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -34,14 +34,14 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp return null; } - BuilderPrism builderMapping = method.getOptions().getBeanMapping().getBuilderPrism(); - if ( builderMapping == null && buildMethods.size() == 1 ) { + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + if ( builder == null && buildMethods.size() == 1 ) { return MethodReference.forMethodCall( first( buildMethods ).getSimpleName().toString() ); } else { String buildMethodPattern = DEFAULT_BUILD_METHOD_NAME; - if ( builderMapping != null ) { - buildMethodPattern = builderMapping.buildMethod(); + if ( builder != null ) { + buildMethodPattern = builder.buildMethod().get(); } for ( ExecutableElement buildMethod : buildMethods ) { String methodName = buildMethod.getSimpleName().toString(); @@ -50,7 +50,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp } } - if ( builderMapping == null ) { + if ( builder == null ) { ctx.getMessager().printMessage( method.getExecutable(), Message.BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT, @@ -63,7 +63,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp else { ctx.getMessager().printMessage( method.getExecutable(), - builderMapping.mirror, + builder.mirror(), Message.BUILDER_NO_BUILD_METHOD_FOUND, buildMethodPattern, builderType.getBuilder(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 1acacad461..04331c4e14 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -15,15 +15,15 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_NULL; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL; /** * A builder that is used for creating an assignment to a collection. @@ -61,8 +61,8 @@ public class CollectionAssignmentBuilder { private AccessorType targetAccessorType; private Assignment assignment; private SourceRHS sourceRHS; - private NullValueCheckStrategyPrism nvcs; - private NullValuePropertyMappingStrategyPrism nvpms; + private NullValueCheckStrategyGem nvcs; + private NullValuePropertyMappingStrategyGem nvpms; public CollectionAssignmentBuilder mappingBuilderContext(MappingBuilderContext ctx) { this.ctx = ctx; @@ -114,12 +114,12 @@ public CollectionAssignmentBuilder rightHandSide(SourceRHS sourceRHS) { return this; } - public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyPrism nvcs ) { + public CollectionAssignmentBuilder nullValueCheckStrategy( NullValueCheckStrategyGem nvcs ) { this.nvcs = nvcs; return this; } - public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePropertyMappingStrategyPrism nvpms ) { + public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePropertyMappingStrategyGem nvpms ) { this.nvpms = nvpms; return this; } @@ -127,8 +127,8 @@ public CollectionAssignmentBuilder nullValuePropertyMappingStrategy( NullValuePr public Assignment build() { Assignment result = assignment; - CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy(); - boolean targetImmutable = cms == CollectionMappingStrategyPrism.TARGET_IMMUTABLE || targetReadAccessor == null; + CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); + boolean targetImmutable = cms == CollectionMappingStrategyGem.TARGET_IMMUTABLE || targetReadAccessor == null; if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) { @@ -169,7 +169,7 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || - nvcs == NullValueCheckStrategyPrism.ALWAYS ) { + nvcs == NullValueCheckStrategyGem.ALWAYS ) { result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index ce034837e8..ab37cb77d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.List; import java.util.SortedSet; - import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; @@ -16,7 +15,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.prism.DecoratedWithPrism; +import org.mapstruct.ap.internal.gem.DecoratedWithGem; import org.mapstruct.ap.internal.version.VersionInformation; /** @@ -29,7 +28,7 @@ public class Decorator extends GeneratedType { public static class Builder extends GeneratedTypeBuilder { private TypeElement mapperElement; - private DecoratedWithPrism decoratorPrism; + private DecoratedWithGem decorator; private boolean hasDelegateConstructor; private String implName; @@ -44,8 +43,8 @@ public Builder mapperElement(TypeElement mapperElement) { return this; } - public Builder decoratorPrism(DecoratedWithPrism decoratorPrism) { - this.decoratorPrism = decoratorPrism; + public Builder decoratedWith(DecoratedWithGem decoratedGem) { + this.decorator = decoratedGem; return this; } @@ -68,7 +67,7 @@ public Decorator build() { String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER, Mapper.getFlatName( mapperElement ) ); - Type decoratorType = typeFactory.getType( decoratorPrism.value() ); + Type decoratorType = typeFactory.getType( decorator.value().get() ); DecoratorConstructor decoratorConstructor = new DecoratorConstructor( implementationName, implementationName + "_", diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 8fd88a405a..e14382318e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -20,7 +20,7 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -42,7 +42,7 @@ public static class Builder extends AbstractMappingMethodBuilder stringToEnumMapping(Method method, Type targetType ) } private SelectionParameters getSelectionParameters(Method method, Types typeUtils) { - BeanMappingPrism beanMappingPrism = BeanMappingPrism.getInstanceOn( method.getExecutable() ); - if ( beanMappingPrism != null ) { - List qualifiers = beanMappingPrism.qualifiedBy(); - List qualifyingNames = beanMappingPrism.qualifiedByName(); - TypeMirror resultType = beanMappingPrism.resultType(); + BeanMappingGem beanMapping = BeanMappingGem.instanceOn( method.getExecutable() ); + if ( beanMapping != null ) { + List qualifiers = beanMapping.qualifiedBy().get(); + List qualifyingNames = beanMapping.qualifiedByName().get(); + TypeMirror resultType = beanMapping.resultType().get(); return new SelectionParameters( qualifiers, qualifyingNames, resultType, typeUtils ); } return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index d07c5acef8..06a2712f00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.internal.model.assignment; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.IGNORE; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; import java.util.HashSet; import java.util.List; @@ -16,8 +16,8 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; /** * This wrapper handles the situation where an assignment is done for an update method. @@ -41,8 +41,8 @@ public class ExistingInstanceSetterWrapperForCollectionsAndMaps public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List thrownTypesToExclude, Type targetType, - NullValueCheckStrategyPrism nvcs, - NullValuePropertyMappingStrategyPrism nvpms, + NullValueCheckStrategyGem nvcs, + NullValuePropertyMappingStrategyGem nvpms, TypeFactory typeFactory, boolean fieldAssignment) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index 3d8de9fd57..e9fc38741a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -10,12 +10,12 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; -import static org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism.ALWAYS; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.IGNORE; -import static org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; /** * Wraps the assignment in a target setter. @@ -92,8 +92,8 @@ public boolean isIncludeSourceNullCheck() { * * @return include a null check */ - public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyPrism nvcs, - NullValuePropertyMappingStrategyPrism nvpms, Type targetType) { + public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyGem nvcs, + NullValuePropertyMappingStrategyGem nvpms, Type targetType) { return !rhs.isSourceReferenceParameter() && !rhs.getSourceType().isPrimitive() && (ALWAYS == nvcs diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index 6041453cf8..8a2a398232 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -20,8 +20,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -161,7 +161,7 @@ && matchesSourceOrTargetParameter( segments[0], parameter, isReversed ) ) { private List getTargetEntries(Type type, String[] entryNames) { // initialize - CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy(); + CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); List targetEntries = new ArrayList<>(); Type nextType = type; @@ -202,8 +202,8 @@ private List getTargetEntries(Type type, String[] entryNames) { ); } else { - BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism(); - builderType = typeFactory.builderTypeFor( nextType, builderPrism ); + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + builderType = typeFactory.builderTypeFor( nextType, builder ); propertyEntry = PropertyEntry.forTargetReference( fullName, targetReadAccessor, targetWriteAccessor, @@ -270,8 +270,8 @@ private Type typeBasedOnMethod(Type type) { return type; } else { - BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism(); - return typeFactory.effectiveResultTypeFor( type, builderPrism ); + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + return typeFactory.effectiveResultTypeFor( type, builder ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 0f3000913b..958725c966 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -11,9 +11,9 @@ import java.util.stream.Collectors; import javax.lang.model.element.VariableElement; -import org.mapstruct.ap.internal.prism.ContextPrism; -import org.mapstruct.ap.internal.prism.MappingTargetPrism; -import org.mapstruct.ap.internal.prism.TargetTypePrism; +import org.mapstruct.ap.internal.gem.ContextGem; +import org.mapstruct.ap.internal.gem.MappingTargetGem; +import org.mapstruct.ap.internal.gem.TargetTypeGem; import org.mapstruct.ap.internal.util.Collections; /** @@ -117,9 +117,9 @@ public static Parameter forElementAndType(VariableElement element, Type paramete return new Parameter( element.getSimpleName().toString(), parameterType, - MappingTargetPrism.getInstanceOn( element ) != null, - TargetTypePrism.getInstanceOn( element ) != null, - ContextPrism.getInstanceOn( element ) != null, + MappingTargetGem.instanceOn( element ) != null, + TargetTypeGem.instanceOn( element ) != null, + ContextGem.instanceOn( element ) != null, isVarArgs ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 0a448c88ad..103325a800 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -29,7 +29,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.Fields; @@ -536,7 +536,7 @@ public Map getPropertyPresenceCheckers() { * @param cmStrategy collection mapping strategy * @return an unmodifiable map of all write accessors indexed by property name */ - public Map getPropertyWriteAccessors( CollectionMappingStrategyPrism cmStrategy ) { + public Map getPropertyWriteAccessors( CollectionMappingStrategyGem cmStrategy ) { // collect all candidate target accessors List candidates = new ArrayList<>( getSetters() ); candidates.addAll( getAlternativeTargetAccessors() ); @@ -554,15 +554,15 @@ public Map getPropertyWriteAccessors( CollectionMappingStrateg // A target access is in general a setter method on the target object. However, in case of collections, // the current target accessor can also be a getter method. // The following if block, checks if the target accessor should be overruled by an add method. - if ( cmStrategy == CollectionMappingStrategyPrism.SETTER_PREFERRED - || cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED - || cmStrategy == CollectionMappingStrategyPrism.TARGET_IMMUTABLE ) { + if ( cmStrategy == CollectionMappingStrategyGem.SETTER_PREFERRED + || cmStrategy == CollectionMappingStrategyGem.ADDER_PREFERRED + || cmStrategy == CollectionMappingStrategyGem.TARGET_IMMUTABLE ) { // first check if there's a setter method. Accessor adderMethod = null; if ( candidate.getAccessorType() == AccessorType.SETTER // ok, the current accessor is a setter. So now the strategy determines what to use - && cmStrategy == CollectionMappingStrategyPrism.ADDER_PREFERRED ) { + && cmStrategy == CollectionMappingStrategyGem.ADDER_PREFERRED ) { adderMethod = getAdderForType( targetType, targetPropertyName ); } else if ( candidate.getAccessorType() == AccessorType.GETTER ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 0647834b81..8fc7fcdc5c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -39,7 +39,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.prism.BuilderPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.Extractor; @@ -517,8 +517,8 @@ private ImplementationType getImplementationType(TypeMirror mirror) { return null; } - private BuilderInfo findBuilder(TypeMirror type, BuilderPrism builderPrism, boolean report) { - if ( builderPrism != null && builderPrism.disableBuilder() ) { + private BuilderInfo findBuilder(TypeMirror type, BuilderGem builderGem, boolean report) { + if ( builderGem != null && builderGem.disableBuilder().get() ) { return null; } try { @@ -631,17 +631,17 @@ private boolean canBeProcessed(TypeMirror type) { return true; } - public BuilderType builderTypeFor( Type type, BuilderPrism builderPrism ) { + public BuilderType builderTypeFor( Type type, BuilderGem builder ) { if ( type != null ) { - BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, true ); + BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builder, true ); return BuilderType.create( builderInfo, type, this, this.typeUtils ); } return null; } - public Type effectiveResultTypeFor( Type type, BuilderPrism builderPrism ) { + public Type effectiveResultTypeFor( Type type, BuilderGem builder ) { if ( type != null ) { - BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builderPrism, false ); + BuilderInfo builderInfo = findBuilder( type.getTypeMirror(), builder, false ); BuilderType builderType = BuilderType.create( builderInfo, type, this, this.typeUtils ); return builderType != null ? builderType.getBuilder() : type; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 44aa02c134..984044233b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -8,19 +8,20 @@ import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.BeanMappingPrism; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.BeanMappingGem; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.tools.gem.GemValue; /** * Represents an bean mapping as configured via {@code @BeanMapping}. @@ -30,7 +31,7 @@ public class BeanMappingOptions extends DelegatingOptions { private final SelectionParameters selectionParameters; - private final BeanMappingPrism prism; + private final BeanMappingGem beanMapping; /** * creates a mapping for inheritance. Will set @@ -40,17 +41,17 @@ public class BeanMappingOptions extends DelegatingOptions { public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) { BeanMappingOptions options = new BeanMappingOptions( SelectionParameters.forInheritance( beanMapping.selectionParameters ), - beanMapping.prism, + beanMapping.beanMapping, beanMapping ); return options; } - public static BeanMappingOptions getInstanceOn(BeanMappingPrism prism, MapperOptions mapperOptions, + public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, Types typeUtils, TypeFactory typeFactory ) { - if ( prism == null || !isConsistent( prism, method, messager ) ) { + if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) { BeanMappingOptions options = new BeanMappingOptions( null, null, mapperOptions ); return options; } @@ -62,28 +63,32 @@ public static BeanMappingOptions getInstanceOn(BeanMappingPrism prism, MapperOpt Objects.requireNonNull( typeFactory ); SelectionParameters selectionParameters = new SelectionParameters( - prism.qualifiedBy(), - prism.qualifiedByName(), - TypeKind.VOID != prism.resultType().getKind() ? prism.resultType() : null, + beanMapping.qualifiedBy().get(), + beanMapping.qualifiedByName().get(), + beanMapping.resultType().getValue(), typeUtils ); //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? - BeanMappingOptions options = new BeanMappingOptions( selectionParameters, prism, mapperOptions ); + BeanMappingOptions options = new BeanMappingOptions( + selectionParameters, + beanMapping, + mapperOptions + ); return options; } - private static boolean isConsistent(BeanMappingPrism prism, ExecutableElement method, + private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method, FormattingMessager messager) { - if ( TypeKind.VOID == prism.resultType().getKind() - && prism.qualifiedBy().isEmpty() - && prism.qualifiedByName().isEmpty() - && prism.ignoreUnmappedSourceProperties().isEmpty() - && null == prism.values.nullValueCheckStrategy() - && null == prism.values.nullValuePropertyMappingStrategy() - && null == prism.values.nullValueMappingStrategy() - && null == prism.values.ignoreByDefault() - && null == prism.values.builder() ) { + if ( !gem.resultType().hasValue() + && !gem.qualifiedBy().hasValue() + && !gem.qualifiedByName().hasValue() + && !gem.ignoreUnmappedSourceProperties().hasValue() + && !gem.nullValueCheckStrategy().hasValue() + && !gem.nullValuePropertyMappingStrategy().hasValue() + && !gem.nullValueMappingStrategy().hasValue() + && !gem.ignoreByDefault().hasValue() + && !gem.builder().hasValue() ) { messager.printMessage( method, Message.BEANMAPPING_NO_ELEMENTS ); return false; @@ -91,39 +96,49 @@ private static boolean isConsistent(BeanMappingPrism prism, ExecutableElement me return true; } - private BeanMappingOptions(SelectionParameters selectionParameters, BeanMappingPrism prism, + private BeanMappingOptions(SelectionParameters selectionParameters, + BeanMappingGem beanMapping, DelegatingOptions next) { super( next ); this.selectionParameters = selectionParameters; - this.prism = prism; + this.beanMapping = beanMapping; } // @Mapping, @BeanMapping @Override - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return null == prism || null == prism.values.nullValueCheckStrategy() ? - next().getNullValueCheckStrategy() - : NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + public NullValueCheckStrategyGem getNullValueCheckStrategy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValueCheckStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValueCheckStrategyGem::valueOf ) + .orElse( next().getNullValueCheckStrategy() ); } @Override - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return null == prism || null == prism.values.nullValuePropertyMappingStrategy() ? - next().getNullValuePropertyMappingStrategy() - : NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValuePropertyMappingStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValuePropertyMappingStrategyGem::valueOf ) + .orElse( next().getNullValuePropertyMappingStrategy() ); } @Override - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return null == prism || null == prism.values.nullValueMappingStrategy() ? - next().getNullValueMappingStrategy() - : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::nullValueMappingStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValueMappingStrategyGem::valueOf ) + .orElse( next().getNullValueMappingStrategy() ); } @Override - public BuilderPrism getBuilderPrism() { - return null == prism || null == prism.values.builder() ? next().getBuilderPrism() : prism.builder(); + public BuilderGem getBuilder() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::builder ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .orElse( next().getBuilder() ); } // @BeanMapping specific @@ -133,19 +148,23 @@ public SelectionParameters getSelectionParameters() { } public boolean isignoreByDefault() { - return null == prism ? false : prism.ignoreByDefault(); + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreByDefault ) + .map( GemValue::get ) + .orElse( false ); } public List getIgnoreUnmappedSourceProperties() { - return null == prism ? Collections.emptyList() : prism.ignoreUnmappedSourceProperties(); + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreUnmappedSourceProperties ) + .map( GemValue::get ) + .orElse( Collections.emptyList() ); } public AnnotationMirror getMirror() { - return null == prism ? null : prism.mirror; + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::mirror ).orElse( null ); } @Override public boolean hasAnnotation() { - return prism != null; + return beanMapping != null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 4b7fdcbc50..adbc5286bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -10,35 +10,35 @@ import javax.lang.model.type.DeclaredType; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; -import org.mapstruct.ap.internal.prism.MapperPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; +import org.mapstruct.ap.internal.gem.MapperGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; public class DefaultOptions extends DelegatingOptions { - private final MapperPrism prism; + private final MapperGem mapper; private final Options options; - DefaultOptions(MapperPrism prism, Options options) { + DefaultOptions(MapperGem mapper, Options options) { super( null ); - this.prism = prism; + this.mapper = mapper; this.options = options; } @Override public String implementationName() { - return prism.implementationName(); + return mapper.implementationName().getDefaultValue(); } @Override public String implementationPackage() { - return prism.implementationPackage(); + return mapper.implementationPackage().getDefaultValue(); } @Override @@ -52,21 +52,21 @@ public Set imports() { } @Override - public ReportingPolicyPrism unmappedTargetPolicy() { + public ReportingPolicyGem unmappedTargetPolicy() { if ( options.getUnmappedTargetPolicy() != null ) { return options.getUnmappedTargetPolicy(); } - return ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() ); + return ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().getDefaultValue() ); } @Override - public ReportingPolicyPrism unmappedSourcePolicy() { - return ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() ); + public ReportingPolicyGem unmappedSourcePolicy() { + return ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().getDefaultValue() ); } @Override - public ReportingPolicyPrism typeConversionPolicy() { - return ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() ); + public ReportingPolicyGem typeConversionPolicy() { + return ReportingPolicyGem.valueOf( mapper.typeConversionPolicy().getDefaultValue() ); } @Override @@ -74,46 +74,47 @@ public String componentModel() { if ( options.getDefaultComponentModel() != null ) { return options.getDefaultComponentModel(); } - return prism.componentModel(); + return mapper.componentModel().getDefaultValue(); } @Override - public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() { - return MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() ); + public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { + return MappingInheritanceStrategyGem.valueOf( mapper.mappingInheritanceStrategy().getDefaultValue() ); } @Override - public InjectionStrategyPrism getInjectionStrategy() { + public InjectionStrategyGem getInjectionStrategy() { if ( options.getDefaultInjectionStrategy() != null ) { - return InjectionStrategyPrism.valueOf( options.getDefaultInjectionStrategy().toUpperCase() ); + return InjectionStrategyGem.valueOf( options.getDefaultInjectionStrategy().toUpperCase() ); } - return InjectionStrategyPrism.valueOf( prism.injectionStrategy() ); + return InjectionStrategyGem.valueOf( mapper.injectionStrategy().getDefaultValue() ); } @Override public Boolean isDisableSubMappingMethodsGeneration() { - return prism.disableSubMappingMethodsGeneration(); + return mapper.disableSubMappingMethodsGeneration().getDefaultValue(); } // BeanMapping and Mapping - public CollectionMappingStrategyPrism getCollectionMappingStrategy() { - return CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() ); + public CollectionMappingStrategyGem getCollectionMappingStrategy() { + return CollectionMappingStrategyGem.valueOf( mapper.collectionMappingStrategy().getDefaultValue() ); } - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + public NullValueCheckStrategyGem getNullValueCheckStrategy() { + return NullValueCheckStrategyGem.valueOf( mapper.nullValueCheckStrategy().getDefaultValue() ); } - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { + return NullValuePropertyMappingStrategyGem.valueOf( + mapper.nullValuePropertyMappingStrategy().getDefaultValue() ); } - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().getDefaultValue() ); } - public BuilderPrism getBuilderPrism() { + public BuilderGem getBuilder() { // TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility // but assuming a default @Builder will make testcases fail. Not having a default means that you need to // specify this mandatory on @MappingConfig and @Mapper. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 1d249e7775..9062b0a031 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -12,14 +12,14 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; /** * Chain Of Responsibility Pattern. @@ -50,15 +50,15 @@ public Set imports() { return next.imports(); } - public ReportingPolicyPrism unmappedTargetPolicy() { + public ReportingPolicyGem unmappedTargetPolicy() { return next.unmappedTargetPolicy(); } - public ReportingPolicyPrism unmappedSourcePolicy() { + public ReportingPolicyGem unmappedSourcePolicy() { return next.unmappedSourcePolicy(); } - public ReportingPolicyPrism typeConversionPolicy() { + public ReportingPolicyGem typeConversionPolicy() { return next.typeConversionPolicy(); } @@ -66,11 +66,11 @@ public String componentModel() { return next.componentModel(); } - public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() { + public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { return next.getMappingInheritanceStrategy(); } - public InjectionStrategyPrism getInjectionStrategy() { + public InjectionStrategyGem getInjectionStrategy() { return next.getInjectionStrategy(); } @@ -80,24 +80,24 @@ public Boolean isDisableSubMappingMethodsGeneration() { // BeanMapping and Mapping - public CollectionMappingStrategyPrism getCollectionMappingStrategy() { + public CollectionMappingStrategyGem getCollectionMappingStrategy() { return next.getCollectionMappingStrategy(); } - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { + public NullValueCheckStrategyGem getNullValueCheckStrategy() { return next.getNullValueCheckStrategy(); } - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { return next.getNullValuePropertyMappingStrategy(); } - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { + public NullValueMappingStrategyGem getNullValueMappingStrategy() { return next.getNullValueMappingStrategy(); } - public BuilderPrism getBuilderPrism() { - return next.getBuilderPrism(); + public BuilderGem getBuilder() { + return next.getBuilder(); } DelegatingOptions next() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index 077883c311..70601a96c6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -5,16 +5,17 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; -import org.mapstruct.ap.internal.prism.IterableMappingPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.IterableMappingGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.tools.gem.GemValue; /** * Represents an iterable mapping as configured via {@code @IterableMapping}. @@ -25,44 +26,45 @@ public class IterableMappingOptions extends DelegatingOptions { private final SelectionParameters selectionParameters; private final FormattingParameters formattingParameters; - private final IterableMappingPrism prism; + private final IterableMappingGem iterableMapping; - public static IterableMappingOptions fromPrism(IterableMappingPrism prism, - MapperOptions mappperOptions, ExecutableElement method, - FormattingMessager messager, Types typeUtils) { + public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, + MapperOptions mappperOptions, ExecutableElement method, + FormattingMessager messager, Types typeUtils) { - if ( prism == null || !isConsistent( prism, method, messager ) ) { + if ( iterableMapping == null || !isConsistent( iterableMapping, method, messager ) ) { IterableMappingOptions options = new IterableMappingOptions( null, null, null, mappperOptions ); return options; } SelectionParameters selection = new SelectionParameters( - prism.qualifiedBy(), - prism.qualifiedByName(), - TypeKind.VOID != prism.elementTargetType().getKind() ? prism.elementTargetType() : null, + iterableMapping.qualifiedBy().get(), + iterableMapping.qualifiedByName().get(), + iterableMapping.elementTargetType().getValue(), typeUtils ); FormattingParameters formatting = new FormattingParameters( - prism.dateFormat(), - prism.numberFormat(), - prism.mirror, - prism.values.dateFormat(), + iterableMapping.dateFormat().get(), + iterableMapping.numberFormat().get(), + iterableMapping.mirror(), + iterableMapping.dateFormat().getAnnotationValue(), method ); - IterableMappingOptions options = new IterableMappingOptions( formatting, selection, prism, mappperOptions ); + IterableMappingOptions options = + new IterableMappingOptions( formatting, selection, iterableMapping, mappperOptions ); return options; } - private static boolean isConsistent(IterableMappingPrism prism, ExecutableElement method, + private static boolean isConsistent(IterableMappingGem gem, ExecutableElement method, FormattingMessager messager) { - if ( prism.dateFormat().isEmpty() - && prism.numberFormat().isEmpty() - && prism.qualifiedBy().isEmpty() - && prism.qualifiedByName().isEmpty() - && TypeKind.VOID == prism.elementTargetType().getKind() - && null == prism.values.nullValueMappingStrategy() ) { + if ( !gem.dateFormat().hasValue() + && !gem.numberFormat().hasValue() + && !gem.qualifiedBy().hasValue() + && !gem.qualifiedByName().hasValue() + && !gem.elementTargetType().hasValue() + && !gem.nullValueMappingStrategy().hasValue() ) { messager.printMessage( method, Message.ITERABLEMAPPING_NO_ELEMENTS ); return false; } @@ -70,11 +72,12 @@ private static boolean isConsistent(IterableMappingPrism prism, ExecutableElemen } private IterableMappingOptions(FormattingParameters formattingParameters, SelectionParameters selectionParameters, - IterableMappingPrism prism, DelegatingOptions next ) { + IterableMappingGem iterableMapping, + DelegatingOptions next) { super( next ); this.formattingParameters = formattingParameters; this.selectionParameters = selectionParameters; - this.prism = prism; + this.iterableMapping = iterableMapping; } public SelectionParameters getSelectionParameters() { @@ -86,19 +89,21 @@ public FormattingParameters getFormattingParameters() { } public AnnotationMirror getMirror() { - return null == prism ? null : prism.mirror; + return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::mirror ).orElse( null ); } @Override - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return null == prism || null == prism.values.nullValueMappingStrategy() ? - next().getNullValueMappingStrategy() - : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::nullValueMappingStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValueMappingStrategyGem::valueOf ) + .orElse( next().getNullValueMappingStrategy() ); } @Override public boolean hasAnnotation() { - return prism != null; + return iterableMapping != null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index 83d8bec5ce..3dd3927f58 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -5,16 +5,17 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeKind; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; -import org.mapstruct.ap.internal.prism.MapMappingPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.MapMappingGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.tools.gem.GemValue; /** * Represents a map mapping as configured via {@code @MapMapping}. @@ -27,44 +28,50 @@ public class MapMappingOptions extends DelegatingOptions { private final SelectionParameters valueSelectionParameters; private final FormattingParameters keyFormattingParameters; private final FormattingParameters valueFormattingParameters; - private final MapMappingPrism prism; - - public static MapMappingOptions fromPrism(MapMappingPrism prism, MapperOptions mapperOptions, - ExecutableElement method, - FormattingMessager messager, Types typeUtils) { - - if ( prism == null || !isConsistent( prism, method, messager ) ) { - MapMappingOptions options = new MapMappingOptions( null, null, null, null, null, mapperOptions ); + private final MapMappingGem mapMapping; + + public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapperOptions, + ExecutableElement method, FormattingMessager messager, Types typeUtils) { + + if ( mapMapping == null || !isConsistent( mapMapping, method, messager ) ) { + MapMappingOptions options = new MapMappingOptions( + null, + null, + null, + null, + null, + mapperOptions + ); return options; } SelectionParameters keySelection = new SelectionParameters( - prism.keyQualifiedBy(), - prism.keyQualifiedByName(), - TypeKind.VOID != prism.keyTargetType().getKind() ? prism.keyTargetType() : null, + mapMapping.keyQualifiedBy().get(), + mapMapping.keyQualifiedByName().get(), + mapMapping.keyTargetType().getValue(), typeUtils ); SelectionParameters valueSelection = new SelectionParameters( - prism.valueQualifiedBy(), - prism.valueQualifiedByName(), - TypeKind.VOID != prism.valueTargetType().getKind() ? prism.valueTargetType() : null, + mapMapping.valueQualifiedBy().get(), + mapMapping.valueQualifiedByName().get(), + mapMapping.valueTargetType().getValue(), typeUtils ); FormattingParameters keyFormatting = new FormattingParameters( - prism.keyDateFormat(), - prism.keyNumberFormat(), - prism.mirror, - prism.values.keyDateFormat(), + mapMapping.keyDateFormat().get(), + mapMapping.keyNumberFormat().get(), + mapMapping.mirror(), + mapMapping.keyDateFormat().getAnnotationValue(), method ); FormattingParameters valueFormatting = new FormattingParameters( - prism.valueDateFormat(), - prism.valueNumberFormat(), - prism.mirror, - prism.values.valueDateFormat(), + mapMapping.valueDateFormat().get(), + mapMapping.valueNumberFormat().get(), + mapMapping.mirror(), + mapMapping.valueDateFormat().getAnnotationValue(), method ); @@ -73,24 +80,25 @@ public static MapMappingOptions fromPrism(MapMappingPrism prism, MapperOptions m keySelection, valueFormatting, valueSelection, - prism, + mapMapping, mapperOptions ); return options; } - private static boolean isConsistent(MapMappingPrism prism, ExecutableElement method, FormattingMessager messager) { - if ( prism.keyDateFormat().isEmpty() - && prism.keyNumberFormat().isEmpty() - && prism.keyQualifiedBy().isEmpty() - && prism.keyQualifiedByName().isEmpty() - && prism.valueDateFormat().isEmpty() - && prism.valueNumberFormat().isEmpty() - && prism.valueQualifiedBy().isEmpty() - && prism.valueQualifiedByName().isEmpty() - && TypeKind.VOID == prism.keyTargetType().getKind() - && TypeKind.VOID == prism.valueTargetType().getKind() - && null == prism.values.nullValueMappingStrategy() ) { + private static boolean isConsistent(MapMappingGem gem, ExecutableElement method, + FormattingMessager messager) { + if ( !gem.keyDateFormat().hasValue() + && !gem.keyNumberFormat().hasValue() + && !gem.keyQualifiedBy().hasValue() + && !gem.keyQualifiedByName().hasValue() + && !gem.valueDateFormat().hasValue() + && !gem.valueNumberFormat().hasValue() + && !gem.valueQualifiedBy().hasValue() + && !gem.valueQualifiedByName().hasValue() + && !gem.keyTargetType().hasValue() + && !gem.valueTargetType().hasValue() + && !gem.nullValueMappingStrategy().hasValue() ) { messager.printMessage( method, Message.MAPMAPPING_NO_ELEMENTS ); return false; } @@ -99,13 +107,13 @@ private static boolean isConsistent(MapMappingPrism prism, ExecutableElement met private MapMappingOptions(FormattingParameters keyFormatting, SelectionParameters keySelectionParameters, FormattingParameters valueFormatting, SelectionParameters valueSelectionParameters, - MapMappingPrism prism, DelegatingOptions next ) { + MapMappingGem mapMapping, DelegatingOptions next ) { super( next ); this.keyFormattingParameters = keyFormatting; this.keySelectionParameters = keySelectionParameters; this.valueFormattingParameters = valueFormatting; this.valueSelectionParameters = valueSelectionParameters; - this.prism = prism; + this.mapMapping = mapMapping; } public FormattingParameters getKeyFormattingParameters() { @@ -125,19 +133,21 @@ public SelectionParameters getValueSelectionParameters() { } public AnnotationMirror getMirror() { - return null == prism ? null : prism.mirror; + return Optional.ofNullable( mapMapping ).map( MapMappingGem::mirror ).orElse( null ); } @Override - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return null == prism || null == prism.values.nullValueMappingStrategy() ? - next().getNullValueMappingStrategy() - : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return Optional.ofNullable( mapMapping ).map( MapMappingGem::nullValueMappingStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValueMappingStrategyGem::valueOf ) + .orElse( next().getNullValueMappingStrategy() ); } @Override public boolean hasAnnotation() { - return prism != null; + return mapMapping != null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index b83bbd2f90..5a3a0e1ade 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -8,124 +8,130 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; -import org.mapstruct.ap.internal.prism.MapperConfigPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; +import org.mapstruct.ap.internal.gem.MapperConfigGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; public class MapperConfigOptions extends DelegatingOptions { - private final MapperConfigPrism prism; + private final MapperConfigGem mapperConfig; - MapperConfigOptions(MapperConfigPrism prism, DelegatingOptions next ) { + MapperConfigOptions(MapperConfigGem mapperConfig, DelegatingOptions next ) { super( next ); - this.prism = prism; + this.mapperConfig = mapperConfig; } @Override public String implementationName() { - return null == prism.values.implementationName() ? next().implementationName() : - prism.implementationName(); + return mapperConfig.implementationName().hasValue() ? mapperConfig.implementationName().get() : + next().implementationName(); } @Override public String implementationPackage() { - return null == prism.values.implementationPackage() ? next().implementationPackage() : - prism.implementationPackage(); + return mapperConfig.implementationPackage().hasValue() ? mapperConfig.implementationPackage().get() : + next().implementationPackage(); } @Override public Set uses() { - return toDeclaredTypes( prism.uses(), next().uses() ); + return toDeclaredTypes( mapperConfig.uses().get(), next().uses() ); } @Override public Set imports() { - return toDeclaredTypes( prism.imports(), next().imports() ); + return toDeclaredTypes( mapperConfig.imports().get(), next().imports() ); } @Override - public ReportingPolicyPrism unmappedTargetPolicy() { - return null == prism.values.unmappedTargetPolicy() ? next().unmappedTargetPolicy() : - ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() ); + public ReportingPolicyGem unmappedTargetPolicy() { + return mapperConfig.unmappedTargetPolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapperConfig.unmappedTargetPolicy().get() ) : next().unmappedTargetPolicy(); + } @Override - public ReportingPolicyPrism unmappedSourcePolicy() { - return null == prism.values.unmappedSourcePolicy() ? next().unmappedSourcePolicy() : - ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() ); + public ReportingPolicyGem unmappedSourcePolicy() { + return mapperConfig.unmappedSourcePolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapperConfig.unmappedSourcePolicy().get() ) : next().unmappedSourcePolicy(); } @Override - public ReportingPolicyPrism typeConversionPolicy() { - return null == prism.values.typeConversionPolicy() ? next().typeConversionPolicy() : - ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() ); + public ReportingPolicyGem typeConversionPolicy() { + return mapperConfig.typeConversionPolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapperConfig.typeConversionPolicy().get() ) : next().typeConversionPolicy(); } @Override public String componentModel() { - return null == prism.values.componentModel() ? next().componentModel() : prism.componentModel(); + return mapperConfig.componentModel().hasValue() ? mapperConfig.componentModel().get() : next().componentModel(); } @Override - public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() { - return null == prism.values.mappingInheritanceStrategy() ? next().getMappingInheritanceStrategy() : - MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() ); + public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { + return mapperConfig.mappingInheritanceStrategy().hasValue() ? + MappingInheritanceStrategyGem.valueOf( mapperConfig.mappingInheritanceStrategy().get() ) : + next().getMappingInheritanceStrategy(); } @Override - public InjectionStrategyPrism getInjectionStrategy() { - return null == prism.values.injectionStrategy() ? next().getInjectionStrategy() : - InjectionStrategyPrism.valueOf( prism.injectionStrategy() ); + public InjectionStrategyGem getInjectionStrategy() { + return mapperConfig.injectionStrategy().hasValue() ? + InjectionStrategyGem.valueOf( mapperConfig.injectionStrategy().get() ) : + next().getInjectionStrategy(); } @Override public Boolean isDisableSubMappingMethodsGeneration() { - return null == prism.values.disableSubMappingMethodsGeneration() ? - next().isDisableSubMappingMethodsGeneration() : prism.disableSubMappingMethodsGeneration(); + return mapperConfig.disableSubMappingMethodsGeneration().hasValue() ? + mapperConfig.disableSubMappingMethodsGeneration().get() : + next().isDisableSubMappingMethodsGeneration(); } + // @Mapping, @BeanMapping + @Override - public CollectionMappingStrategyPrism getCollectionMappingStrategy() { - return null == prism.values.collectionMappingStrategy() ? - next().getCollectionMappingStrategy() - : CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() ); + public CollectionMappingStrategyGem getCollectionMappingStrategy() { + return mapperConfig.collectionMappingStrategy().hasValue() ? + CollectionMappingStrategyGem.valueOf( mapperConfig.collectionMappingStrategy().get() ) : + next().getCollectionMappingStrategy(); } @Override - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return null == prism.values.nullValueCheckStrategy() ? - next().getNullValueCheckStrategy() - : NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + public NullValueCheckStrategyGem getNullValueCheckStrategy() { + return mapperConfig.nullValueCheckStrategy().hasValue() ? + NullValueCheckStrategyGem.valueOf( mapperConfig.nullValueCheckStrategy().get() ) : + next().getNullValueCheckStrategy(); } @Override - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return null == prism.values.nullValuePropertyMappingStrategy() ? - next().getNullValuePropertyMappingStrategy() - : NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { + return mapperConfig.nullValuePropertyMappingStrategy().hasValue() ? + NullValuePropertyMappingStrategyGem.valueOf( mapperConfig.nullValuePropertyMappingStrategy().get() ) : + next().getNullValuePropertyMappingStrategy(); } @Override - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return null == prism.values.nullValueMappingStrategy() ? - next().getNullValueMappingStrategy() - : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return mapperConfig.nullValueMappingStrategy().hasValue() ? + NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueMappingStrategy().get() ) : + next().getNullValueMappingStrategy(); } @Override - public BuilderPrism getBuilderPrism() { - return null == prism.values.builder() ? next().getBuilderPrism() : prism.builder(); + public BuilderGem getBuilder() { + return mapperConfig.builder().hasValue() ? mapperConfig.builder().get() : next().getBuilder(); } @Override public boolean hasAnnotation() { - return prism != null; + return mapperConfig != null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index b1397154d1..9472694067 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -13,146 +13,150 @@ import javax.lang.model.type.TypeKind; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; -import org.mapstruct.ap.internal.prism.MapperConfigPrism; -import org.mapstruct.ap.internal.prism.MapperPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; +import org.mapstruct.ap.internal.gem.MapperConfigGem; +import org.mapstruct.ap.internal.gem.MapperGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; public class MapperOptions extends DelegatingOptions { - private final MapperPrism prism; + private final MapperGem mapper; private final DeclaredType mapperConfigType; public static MapperOptions getInstanceOn(TypeElement typeElement, Options options) { - MapperPrism prism = MapperPrism.getInstanceOn( typeElement ); + MapperGem mapper = MapperGem.instanceOn( typeElement ); MapperOptions mapperAnnotation; - DelegatingOptions defaults = new DefaultOptions( prism, options ); + DelegatingOptions defaults = new DefaultOptions( mapper, options ); DeclaredType mapperConfigType; - if ( prism.values.config() != null && prism.config().getKind() == TypeKind.DECLARED ) { - mapperConfigType = (DeclaredType) prism.config(); + if ( mapper.config().hasValue() && mapper.config().getValue().getKind() == TypeKind.DECLARED ) { + mapperConfigType = (DeclaredType) mapper.config().get(); } else { mapperConfigType = null; } if ( mapperConfigType != null ) { Element mapperConfigElement = mapperConfigType.asElement(); - MapperConfigPrism configPrism = MapperConfigPrism.getInstanceOn( mapperConfigElement ); - MapperConfigOptions mapperConfigAnnotation = new MapperConfigOptions( configPrism, defaults ); - mapperAnnotation = new MapperOptions( prism, mapperConfigType, mapperConfigAnnotation ); + MapperConfigGem mapperConfig = MapperConfigGem.instanceOn( mapperConfigElement ); + MapperConfigOptions mapperConfigAnnotation = new MapperConfigOptions( mapperConfig, defaults ); + mapperAnnotation = new MapperOptions( mapper, mapperConfigType, mapperConfigAnnotation ); } else { - mapperAnnotation = new MapperOptions( prism, null, defaults ); + mapperAnnotation = new MapperOptions( mapper, null, defaults ); } return mapperAnnotation; } - private MapperOptions(MapperPrism prism, DeclaredType mapperConfigType, DelegatingOptions next) { + private MapperOptions(MapperGem mapper, DeclaredType mapperConfigType, DelegatingOptions next) { super( next ); - this.prism = prism; + this.mapper = mapper; this.mapperConfigType = mapperConfigType; } @Override public String implementationName() { - return null == prism.values.implementationName() ? next().implementationName() : prism.implementationName(); + return mapper.implementationName().hasValue() ? mapper.implementationName().get() : next().implementationName(); } @Override public String implementationPackage() { - return null == prism.values.implementationPackage() ? next().implementationPackage() : - prism.implementationPackage(); + return mapper.implementationPackage().hasValue() ? mapper.implementationPackage().get() : + next().implementationPackage(); } @Override public Set uses() { - return toDeclaredTypes( prism.uses(), next().uses() ); + return toDeclaredTypes( mapper.uses().get(), next().uses() ); } @Override public Set imports() { - return toDeclaredTypes( prism.imports(), next().imports() ); + return toDeclaredTypes( mapper.imports().get(), next().imports() ); } @Override - public ReportingPolicyPrism unmappedTargetPolicy() { - return null == prism.values.unmappedTargetPolicy() ? next().unmappedTargetPolicy() : - ReportingPolicyPrism.valueOf( prism.unmappedTargetPolicy() ); + public ReportingPolicyGem unmappedTargetPolicy() { + return mapper.unmappedTargetPolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().get() ) : next().unmappedTargetPolicy(); + } @Override - public ReportingPolicyPrism unmappedSourcePolicy() { - return null == prism.values.unmappedSourcePolicy() ? next().unmappedSourcePolicy() : - ReportingPolicyPrism.valueOf( prism.unmappedSourcePolicy() ); + public ReportingPolicyGem unmappedSourcePolicy() { + return mapper.unmappedSourcePolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().get() ) : next().unmappedSourcePolicy(); } @Override - public ReportingPolicyPrism typeConversionPolicy() { - return null == prism.values.typeConversionPolicy() ? next().typeConversionPolicy() : - ReportingPolicyPrism.valueOf( prism.typeConversionPolicy() ); + public ReportingPolicyGem typeConversionPolicy() { + return mapper.typeConversionPolicy().hasValue() ? + ReportingPolicyGem.valueOf( mapper.typeConversionPolicy().get() ) : next().typeConversionPolicy(); } @Override public String componentModel() { - return null == prism.values.componentModel() ? next().componentModel() : prism.componentModel(); + return mapper.componentModel().hasValue() ? mapper.componentModel().get() : next().componentModel(); } @Override - public MappingInheritanceStrategyPrism getMappingInheritanceStrategy() { - return null == prism.values.mappingInheritanceStrategy() ? next().getMappingInheritanceStrategy() : - MappingInheritanceStrategyPrism.valueOf( prism.mappingInheritanceStrategy() ); + public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { + return mapper.mappingInheritanceStrategy().hasValue() ? + MappingInheritanceStrategyGem.valueOf( mapper.mappingInheritanceStrategy().get() ) : + next().getMappingInheritanceStrategy(); } @Override - public InjectionStrategyPrism getInjectionStrategy() { - return null == prism.values.injectionStrategy() ? next().getInjectionStrategy() : - InjectionStrategyPrism.valueOf( prism.injectionStrategy() ); + public InjectionStrategyGem getInjectionStrategy() { + return mapper.injectionStrategy().hasValue() ? + InjectionStrategyGem.valueOf( mapper.injectionStrategy().get() ) : + next().getInjectionStrategy(); } @Override public Boolean isDisableSubMappingMethodsGeneration() { - return null == prism.values.disableSubMappingMethodsGeneration() ? - next().isDisableSubMappingMethodsGeneration() : prism.disableSubMappingMethodsGeneration(); + return mapper.disableSubMappingMethodsGeneration().hasValue() ? + mapper.disableSubMappingMethodsGeneration().get() : + next().isDisableSubMappingMethodsGeneration(); } // @Mapping, @BeanMapping @Override - public CollectionMappingStrategyPrism getCollectionMappingStrategy() { - return null == prism.values.collectionMappingStrategy() ? - next().getCollectionMappingStrategy() - : CollectionMappingStrategyPrism.valueOf( prism.collectionMappingStrategy() ); + public CollectionMappingStrategyGem getCollectionMappingStrategy() { + return mapper.collectionMappingStrategy().hasValue() ? + CollectionMappingStrategyGem.valueOf( mapper.collectionMappingStrategy().get() ) : + next().getCollectionMappingStrategy(); } @Override - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return null == prism.values.nullValueCheckStrategy() ? - next().getNullValueCheckStrategy() - : NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + public NullValueCheckStrategyGem getNullValueCheckStrategy() { + return mapper.nullValueCheckStrategy().hasValue() ? + NullValueCheckStrategyGem.valueOf( mapper.nullValueCheckStrategy().get() ) : + next().getNullValueCheckStrategy(); } @Override - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return null == prism.values.nullValuePropertyMappingStrategy() ? - next().getNullValuePropertyMappingStrategy() - : NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { + return mapper.nullValuePropertyMappingStrategy().hasValue() ? + NullValuePropertyMappingStrategyGem.valueOf( mapper.nullValuePropertyMappingStrategy().get() ) : + next().getNullValuePropertyMappingStrategy(); } @Override - public NullValueMappingStrategyPrism getNullValueMappingStrategy() { - return null == prism.values.nullValueMappingStrategy() ? - next().getNullValueMappingStrategy() - : NullValueMappingStrategyPrism.valueOf( prism.nullValueMappingStrategy() ); + public NullValueMappingStrategyGem getNullValueMappingStrategy() { + return mapper.nullValueMappingStrategy().hasValue() ? + NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().get() ) : + next().getNullValueMappingStrategy(); } @Override - public BuilderPrism getBuilderPrism() { - return null == prism.values.builder() ? next().getBuilderPrism() : prism.builder(); + public BuilderGem getBuilder() { + return mapper.builder().hasValue() ? mapper.builder().get() : next().getBuilder(); } // @Mapper specific @@ -166,11 +170,11 @@ public boolean hasMapperConfig() { } public boolean isValid() { - return prism.isValid; + return mapper.isValid(); } public AnnotationMirror getAnnotationMirror() { - return prism.mirror; + return mapper.mirror(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 338f22db90..587dc5acf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -14,7 +14,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.accessor.Accessor; import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy; @@ -185,12 +185,12 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { - CollectionMappingStrategyPrism cms = method.getOptions().getMapper().getCollectionMappingStrategy(); + CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); Type writeType = method.getResultType(); if ( !method.isUpdateMethod() ) { writeType = typeFactory.effectiveResultTypeFor( writeType, - method.getOptions().getBeanMapping().getBuilderPrism() + method.getOptions().getBeanMapping().getBuilder() ); } Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 469398c829..1557d68920 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.function.Predicate; import java.util.regex.Matcher; @@ -19,12 +20,13 @@ import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; -import org.mapstruct.ap.internal.prism.MappingPrism; -import org.mapstruct.ap.internal.prism.MappingsPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValuePropertyMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.MappingGem; +import org.mapstruct.ap.internal.gem.MappingsGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.tools.gem.GemValue; /** * Represents a property mapping as configured via {@code @Mapping} (no intermediate state). @@ -49,7 +51,7 @@ public class MappingOptions extends DelegatingOptions { private final AnnotationValue sourceAnnotationValue; private final AnnotationValue targetAnnotationValue; - private final MappingPrism prism; + private final MappingGem mapping; private final InheritContext inheritContext; @@ -86,70 +88,70 @@ public static Set getMappingTargetNamesBy(Predicate pred .collect( Collectors.toCollection( LinkedHashSet::new ) ); } - public static void addInstances(MappingsPrism prism, ExecutableElement method, + public static void addInstances(MappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, Types typeUtils, Set mappings) { - for ( MappingPrism mappingPrism : prism.value() ) { - addInstance( mappingPrism, method, beanMappingOptions, messager, typeUtils, mappings ); + for ( MappingGem mapping : gem.value().getValue() ) { + addInstance( mapping, method, beanMappingOptions, messager, typeUtils, mappings ); } } - public static void addInstance(MappingPrism prism, ExecutableElement method, BeanMappingOptions beanMappingOptions, - FormattingMessager messager, Types typeUtils, Set mappings) { + public static void addInstance(MappingGem mapping, ExecutableElement method, + BeanMappingOptions beanMappingOptions, FormattingMessager messager, Types typeUtils, + Set mappings) { - if ( !isConsistent( prism, method, messager ) ) { + if ( !isConsistent( mapping, method, messager ) ) { return; } - String source = prism.source().isEmpty() ? null : prism.source(); - String constant = prism.values.constant() == null ? null : prism.constant(); - String expression = getExpression( prism, method, messager ); - String defaultExpression = getDefaultExpression( prism, method, messager ); - String dateFormat = prism.values.dateFormat() == null ? null : prism.dateFormat(); - String numberFormat = prism.values.numberFormat() == null ? null : prism.numberFormat(); - String defaultValue = prism.values.defaultValue() == null ? null : prism.defaultValue(); + String source = mapping.source().getValue(); + String constant = mapping.constant().getValue(); + String expression = getExpression( mapping, method, messager ); + String defaultExpression = getDefaultExpression( mapping, method, messager ); + String dateFormat = mapping.dateFormat().getValue(); + String numberFormat = mapping.numberFormat().getValue(); + String defaultValue = mapping.defaultValue().getValue(); - boolean resultTypeIsDefined = prism.values.resultType() != null; - Set dependsOn = prism.dependsOn() != null ? - new LinkedHashSet( prism.dependsOn() ) : + Set dependsOn = mapping.dependsOn().hasValue() ? + new LinkedHashSet( mapping.dependsOn().getValue() ) : Collections.emptySet(); FormattingParameters formattingParam = new FormattingParameters( dateFormat, numberFormat, - prism.mirror, - prism.values.dateFormat(), + mapping.mirror(), + mapping.dateFormat().getAnnotationValue(), method ); SelectionParameters selectionParams = new SelectionParameters( - prism.qualifiedBy(), - prism.qualifiedByName(), - resultTypeIsDefined ? prism.resultType() : null, + mapping.qualifiedBy().get(), + mapping.qualifiedByName().get(), + mapping.resultType().getValue(), typeUtils ); MappingOptions options = new MappingOptions( - prism.target(), - prism.values.target(), + mapping.target().getValue(), + mapping.target().getAnnotationValue(), source, - prism.values.source(), + mapping.source().getAnnotationValue(), constant, expression, defaultExpression, defaultValue, - prism.ignore(), + mapping.ignore().get(), formattingParam, selectionParams, dependsOn, - prism, + mapping, null, beanMappingOptions ); if ( mappings.contains( options ) ) { - messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, prism.target() ); + messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, mapping.target().get() ); } else { mappings.add( options ); @@ -176,66 +178,62 @@ public static MappingOptions forIgnore(String targetName) { ); } - private static boolean isConsistent(MappingPrism prism, ExecutableElement method, + private static boolean isConsistent(MappingGem gem, ExecutableElement method, FormattingMessager messager) { - if ( prism.target().isEmpty() ) { + if ( !gem.target().hasValue() ) { messager.printMessage( method, - prism.mirror, - prism.values.target(), + gem.mirror(), + gem.target().getAnnotationValue(), Message.PROPERTYMAPPING_EMPTY_TARGET ); return false; } Message message = null; - if ( !prism.source().isEmpty() && prism.values.constant() != null ) { + if ( gem.source().hasValue() && gem.constant().hasValue() ) { message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED; } - else if ( !prism.source().isEmpty() && prism.values.expression() != null ) { + else if ( gem.source().hasValue() && gem.expression().hasValue() ) { message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED; } - else if ( prism.values.expression() != null && prism.values.constant() != null ) { + else if (gem.expression().hasValue() && gem.constant().hasValue() ) { message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED; } - else if ( prism.values.expression() != null && prism.values.defaultValue() != null ) { + else if ( gem.expression().hasValue() && gem.defaultValue().hasValue() ) { message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED; } - else if ( prism.values.constant() != null && prism.values.defaultValue() != null ) { + else if ( gem.constant().hasValue() && gem.defaultValue().hasValue() ) { message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED; } - else if ( prism.values.expression() != null && prism.values.defaultExpression() != null ) { + else if ( gem.expression().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } - else if ( prism.values.constant() != null && prism.values.defaultExpression() != null ) { + else if ( gem.constant().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } - else if ( prism.values.defaultValue() != null && prism.values.defaultExpression() != null ) { + else if ( gem.defaultValue().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } - else if ( prism.values.expression() != null - && ( prism.values.qualifiedByName() != null || prism.values.qualifiedBy() != null ) ) { + else if ( gem.expression().hasValue() + && ( gem.qualifiedByName().hasValue() || gem.qualifiedBy().hasValue() ) ) { message = Message.PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED; } - else if ( prism.values.nullValuePropertyMappingStrategy() != null - && prism.values.defaultValue() != null ) { + else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.defaultValue().hasValue() ) { message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS; } - else if ( prism.values.nullValuePropertyMappingStrategy() != null - && prism.values.constant() != null ) { + else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.constant().hasValue() ) { message = Message.PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS; } - else if ( prism.values.nullValuePropertyMappingStrategy() != null - && prism.values.expression() != null ) { + else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.expression().hasValue() ) { message = Message.PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS; } - else if ( prism.values.nullValuePropertyMappingStrategy() != null - && prism.values.defaultExpression() != null ) { + else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS; } - else if ( prism.values.nullValuePropertyMappingStrategy() != null - && prism.ignore() != null && prism.ignore() ) { + else if ( gem.nullValuePropertyMappingStrategy().hasValue() + && gem.ignore().hasValue() && gem.ignore().getValue() ) { message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS; } @@ -243,7 +241,7 @@ else if ( prism.values.nullValuePropertyMappingStrategy() != null return true; } else { - messager.printMessage( method, prism.mirror, message ); + messager.printMessage( method, gem.mirror(), message ); return false; } } @@ -261,7 +259,7 @@ private MappingOptions(String targetName, FormattingParameters formattingParameters, SelectionParameters selectionParameters, Set dependsOn, - MappingPrism prism, + MappingGem mapping, InheritContext inheritContext, DelegatingOptions next ) { @@ -278,21 +276,23 @@ private MappingOptions(String targetName, this.formattingParameters = formattingParameters; this.selectionParameters = selectionParameters; this.dependsOn = dependsOn; - this.prism = prism; + this.mapping = mapping; this.inheritContext = inheritContext; } - private static String getExpression(MappingPrism mappingPrism, ExecutableElement element, + private static String getExpression(MappingGem mapping, ExecutableElement element, FormattingMessager messager) { - if ( mappingPrism.expression().isEmpty() ) { + if ( !mapping.expression().hasValue() ) { return null; } - Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.expression() ); + Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mapping.expression().get() ); if ( !javaExpressionMatcher.matches() ) { messager.printMessage( - element, mappingPrism.mirror, mappingPrism.values.expression(), + element, + mapping.mirror(), + mapping.expression().getAnnotationValue(), Message.PROPERTYMAPPING_INVALID_EXPRESSION ); return null; @@ -301,17 +301,19 @@ private static String getExpression(MappingPrism mappingPrism, ExecutableElement return javaExpressionMatcher.group( 1 ).trim(); } - private static String getDefaultExpression(MappingPrism mappingPrism, ExecutableElement element, + private static String getDefaultExpression(MappingGem mapping, ExecutableElement element, FormattingMessager messager) { - if ( mappingPrism.defaultExpression().isEmpty() ) { + if ( !mapping.defaultExpression().hasValue() ) { return null; } - Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mappingPrism.defaultExpression() ); + Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mapping.defaultExpression().get() ); if ( !javaExpressionMatcher.matches() ) { messager.printMessage( - element, mappingPrism.mirror, mappingPrism.values.defaultExpression(), + element, + mapping.mirror(), + mapping.defaultExpression().getAnnotationValue(), Message.PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION ); return null; @@ -371,11 +373,14 @@ public boolean isIgnored() { } public AnnotationMirror getMirror() { - return prism == null ? null : prism.mirror; + return Optional.ofNullable( mapping ).map( MappingGem::mirror ).orElse( null ); } public AnnotationValue getDependsOnAnnotationValue() { - return prism == null ? null : prism.values.dependsOn(); + return Optional.ofNullable( mapping ) + .map( MappingGem::dependsOn ) + .map( GemValue::getAnnotationValue ) + .orElse( null ); } public Set getDependsOn() { @@ -387,17 +392,21 @@ public InheritContext getInheritContext() { } @Override - public NullValueCheckStrategyPrism getNullValueCheckStrategy() { - return null == prism || null == prism.values.nullValueCheckStrategy() ? - next().getNullValueCheckStrategy() - : NullValueCheckStrategyPrism.valueOf( prism.nullValueCheckStrategy() ); + public NullValueCheckStrategyGem getNullValueCheckStrategy() { + return Optional.ofNullable( mapping ).map( MappingGem::nullValueCheckStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValueCheckStrategyGem::valueOf ) + .orElse( next().getNullValueCheckStrategy() ); } @Override - public NullValuePropertyMappingStrategyPrism getNullValuePropertyMappingStrategy() { - return null == prism || null == prism.values.nullValuePropertyMappingStrategy() ? - next().getNullValuePropertyMappingStrategy() - : NullValuePropertyMappingStrategyPrism.valueOf( prism.nullValuePropertyMappingStrategy() ); + public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() { + return Optional.ofNullable( mapping ).map( MappingGem::nullValuePropertyMappingStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( NullValuePropertyMappingStrategyGem::valueOf ) + .orElse( next().getNullValuePropertyMappingStrategy() ); } /** @@ -426,7 +435,7 @@ public MappingOptions copyForInverseInheritance(SourceMethod templateMethod, formattingParameters, selectionParameters, Collections.emptySet(), - prism, + mapping, new InheritContext( true, false, templateMethod ), beanMappingOptions ); @@ -454,7 +463,7 @@ public MappingOptions copyForForwardInheritance(SourceMethod templateMethod, formattingParameters, selectionParameters, dependsOn, - prism, + mapping, new InheritContext( false, true, templateMethod ), beanMappingOptions ); @@ -492,7 +501,7 @@ public String toString() { @Override public boolean hasAnnotation() { - return prism != null; + return mapping != null; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 92c9b94f0a..3c1a5e1789 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -18,7 +18,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.ObjectFactoryPrism; +import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.Strings; @@ -195,7 +195,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); - this.hasObjectFactoryAnnotation = ObjectFactoryPrism.getInstanceOn( executable ) != null; + this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null; this.isObjectFactory = determineIfIsObjectFactory(); this.typeUtils = builder.typeUtils; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java index 8d346af4b7..10aef4bfa8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java @@ -11,13 +11,13 @@ import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.prism.ValueMappingPrism; -import org.mapstruct.ap.internal.prism.ValueMappingsPrism; +import org.mapstruct.ap.internal.gem.ValueMappingGem; +import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; -import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_REMAINING; -import static org.mapstruct.ap.internal.prism.MappingConstantsPrism.ANY_UNMAPPED; +import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING; +import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED; /** * Represents the mapping between one value constant and another. @@ -32,12 +32,12 @@ public class ValueMappingOptions { private final AnnotationValue sourceAnnotationValue; private final AnnotationValue targetAnnotationValue; - public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, ExecutableElement method, - FormattingMessager messager, List mappings) { + public static void fromMappingsGem(ValueMappingsGem mappingsGem, ExecutableElement method, + FormattingMessager messager, List mappings) { boolean anyFound = false; - for ( ValueMappingPrism mappingPrism : mappingsAnnotation.value() ) { - ValueMappingOptions mapping = fromMappingPrism( mappingPrism ); + for ( ValueMappingGem mappingGem : mappingsGem.value().get() ) { + ValueMappingOptions mapping = fromMappingGem( mappingGem ); if ( mapping != null ) { if ( !mappings.contains( mapping ) ) { @@ -46,10 +46,10 @@ public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, Exec else { messager.printMessage( method, - mappingPrism.mirror, - mappingPrism.values.target(), + mappingGem.mirror(), + mappingGem.target().getAnnotationValue(), Message.VALUEMAPPING_DUPLICATE_SOURCE, - mappingPrism.source() + mappingGem.source().get() ); } if ( ANY_REMAINING.equals( mapping.source ) @@ -57,10 +57,10 @@ public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, Exec if ( anyFound ) { messager.printMessage( method, - mappingPrism.mirror, - mappingPrism.values.target(), + mappingGem.mirror(), + mappingGem.target().getAnnotationValue(), Message.VALUEMAPPING_ANY_AREADY_DEFINED, - mappingPrism.source() + mappingGem.source().get() ); } anyFound = true; @@ -69,10 +69,10 @@ public static void fromMappingsPrism(ValueMappingsPrism mappingsAnnotation, Exec } } - public static ValueMappingOptions fromMappingPrism(ValueMappingPrism mappingPrism ) { + public static ValueMappingOptions fromMappingGem(ValueMappingGem mapping ) { - return new ValueMappingOptions( mappingPrism.source(), mappingPrism.target(), mappingPrism.mirror, - mappingPrism.values.source(), mappingPrism.values.target() ); + return new ValueMappingOptions( mapping.source().get(), mapping.target().get(), mapping.mirror(), + mapping.source().getAnnotationValue(), mapping.target().getAnnotationValue() ); } private ValueMappingOptions(String source, String target, AnnotationMirror mirror, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 5c24e423ed..27ad9eb60d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -9,7 +9,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; - import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; @@ -19,8 +18,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.prism.NamedPrism; -import org.mapstruct.ap.internal.prism.QualifierPrism; +import org.mapstruct.ap.internal.gem.NamedGem; +import org.mapstruct.ap.internal.gem.QualifierGem; /** * This selector selects a best match based on qualifier annotations. @@ -117,8 +116,8 @@ public List> getMatchingMethods(Method mapp // Match! we have an annotation which has the @Qualifer marker ( could be @Named as well ) if ( typeUtils.isSameType( qualifierAnnotationType, namedAnnotationTypeMirror ) ) { // Match! its an @Named, so do the additional check on name. - NamedPrism namedPrism = NamedPrism.getInstance( qualifierAnnotationMirror ); - if ( namedPrism.value() != null && qualfiedByNames.contains( namedPrism.value() ) ) { + NamedGem named = NamedGem.instanceOn( qualifierAnnotationMirror ); + if ( named.value().hasValue() && qualfiedByNames.contains( named.value().get() ) ) { // Match! its an @Name and the value matches as well. Oh boy. matchingQualifierCounter++; } @@ -168,7 +167,7 @@ private Set getQualifierAnnotationMirrors( Method candidate ) private void addOnlyWhenQualifier( Set annotationSet, AnnotationMirror candidate ) { // only add the candidate annotation when the candidate itself has the annotation 'Qualifier' - if ( QualifierPrism.getInstanceOn( candidate.getAnnotationType().asElement() ) != null ) { + if ( QualifierGem.instanceOn( candidate.getAnnotationType().asElement() ) != null ) { annotationSet.add( candidate ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 4f51e91b6a..cb9d309171 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -7,18 +7,17 @@ import java.util.ArrayList; import java.util.List; - import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.gem.XmlElementRefGem; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.prism.XmlElementDeclPrism; -import org.mapstruct.ap.internal.prism.XmlElementRefPrism; +import org.mapstruct.ap.internal.gem.XmlElementDeclGem; /** * Finds the {@link javax.xml.bind.annotation.XmlElementRef} annotation on a field (of the mapping result type or its @@ -46,9 +45,9 @@ public XmlElementDeclSelector(Types typeUtils) { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, Type targetType, + SelectionCriteria criteria) { List> nameMatches = new ArrayList<>(); List> scopeMatches = new ArrayList<>(); @@ -62,14 +61,15 @@ public List> getMatchingMethods(Method mapp } SourceMethod candidateMethod = (SourceMethod) candidate.getMethod(); - XmlElementDeclPrism xmlElementDecl = XmlElementDeclPrism.getInstanceOn( candidateMethod.getExecutable() ); + XmlElementDeclGem xmlElementDecl = + XmlElementDeclGem.instanceOn( candidateMethod.getExecutable() ); if ( xmlElementDecl == null ) { continue; } - String name = xmlElementDecl.name(); - TypeMirror scope = xmlElementDecl.scope(); + String name = xmlElementDecl.name().get(); + TypeMirror scope = xmlElementDecl.scope().get(); boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() ); boolean scopeIsSetAndMatches = @@ -140,9 +140,9 @@ private XmlElementRefInfo findXmlElementRef(Type resultType, String targetProper for ( Element enclosed : currentElement.getEnclosedElements() ) { if ( enclosed.getKind().equals( ElementKind.FIELD ) && enclosed.getSimpleName().contentEquals( targetPropertyName ) ) { - XmlElementRefPrism xmlElementRef = XmlElementRefPrism.getInstanceOn( enclosed ); + XmlElementRefGem xmlElementRef = XmlElementRefGem.instanceOn( enclosed ); if ( xmlElementRef != null ) { - return new XmlElementRefInfo( xmlElementRef.name(), currentMirror ); + return new XmlElementRefInfo( xmlElementRef.name().get(), currentMirror ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 92dcbc5dc4..54b69c28b3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -5,7 +5,7 @@ */ package org.mapstruct.ap.internal.option; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; /** * The options passed to the code generator. @@ -16,14 +16,14 @@ public class Options { private final boolean suppressGeneratorTimestamp; private final boolean suppressGeneratorVersionComment; - private final ReportingPolicyPrism unmappedTargetPolicy; + private final ReportingPolicyGem unmappedTargetPolicy; private final boolean alwaysGenerateSpi; private final String defaultComponentModel; private final String defaultInjectionStrategy; private final boolean verbose; public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, - ReportingPolicyPrism unmappedTargetPolicy, + ReportingPolicyGem unmappedTargetPolicy, String defaultComponentModel, String defaultInjectionStrategy, boolean alwaysGenerateSpi, boolean verbose) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; @@ -43,7 +43,7 @@ public boolean isSuppressGeneratorVersionComment() { return suppressGeneratorVersionComment; } - public ReportingPolicyPrism getUnmappedTargetPolicy() { + public ReportingPolicyGem getUnmappedTargetPolicy() { return unmappedTargetPolicy; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java deleted file mode 100644 index f40cedd20a..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/prism/PrismGenerator.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.prism; - -import javax.xml.bind.annotation.XmlElementDecl; -import javax.xml.bind.annotation.XmlElementRef; - -import org.mapstruct.AfterMapping; -import org.mapstruct.BeanMapping; -import org.mapstruct.BeforeMapping; -import org.mapstruct.Builder; -import org.mapstruct.Context; -import org.mapstruct.DecoratedWith; -import org.mapstruct.InheritConfiguration; -import org.mapstruct.InheritInverseConfiguration; -import org.mapstruct.IterableMapping; -import org.mapstruct.MapMapping; -import org.mapstruct.Mapper; -import org.mapstruct.MapperConfig; -import org.mapstruct.Mapping; -import org.mapstruct.MappingTarget; -import org.mapstruct.Mappings; -import org.mapstruct.Named; -import org.mapstruct.ObjectFactory; -import org.mapstruct.Qualifier; -import org.mapstruct.TargetType; -import org.mapstruct.ValueMapping; -import org.mapstruct.ValueMappings; - -import net.java.dev.hickory.prism.GeneratePrism; -import net.java.dev.hickory.prism.GeneratePrisms; - -/** - * Triggers the generation of prism types using Hickory. - * - * @author Gunnar Morling - */ -@GeneratePrisms({ - @GeneratePrism(value = Mapper.class, publicAccess = true), - @GeneratePrism(value = Mapping.class, publicAccess = true), - @GeneratePrism(value = Mappings.class, publicAccess = true), - @GeneratePrism(value = IterableMapping.class, publicAccess = true), - @GeneratePrism(value = BeanMapping.class, publicAccess = true), - @GeneratePrism(value = MapMapping.class, publicAccess = true), - @GeneratePrism(value = TargetType.class, publicAccess = true), - @GeneratePrism(value = MappingTarget.class, publicAccess = true), - @GeneratePrism(value = DecoratedWith.class, publicAccess = true), - @GeneratePrism(value = MapperConfig.class, publicAccess = true), - @GeneratePrism(value = InheritConfiguration.class, publicAccess = true), - @GeneratePrism(value = InheritInverseConfiguration.class, publicAccess = true), - @GeneratePrism(value = Qualifier.class, publicAccess = true), - @GeneratePrism(value = Named.class, publicAccess = true), - @GeneratePrism(value = ObjectFactory.class, publicAccess = true), - @GeneratePrism(value = AfterMapping.class, publicAccess = true), - @GeneratePrism(value = BeforeMapping.class, publicAccess = true), - @GeneratePrism(value = ValueMapping.class, publicAccess = true), - @GeneratePrism(value = ValueMappings.class, publicAccess = true), - @GeneratePrism(value = Context.class, publicAccess = true), - @GeneratePrism(value = Builder.class, publicAccess = true), - - // external types - @GeneratePrism(value = XmlElementDecl.class, publicAccess = true), - @GeneratePrism(value = XmlElementRef.class, publicAccess = true) -}) -public class PrismGenerator { - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 6991e4c8ff..4efb8011c3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -23,7 +23,7 @@ import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; import org.mapstruct.ap.internal.model.source.MapperOptions; /** @@ -45,7 +45,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, M MapperOptions mapperAnnotation = MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ); String componentModel = mapperAnnotation.componentModel(); - InjectionStrategyPrism injectionStrategy = mapperAnnotation.getInjectionStrategy(); + InjectionStrategyGem injectionStrategy = mapperAnnotation.getInjectionStrategy(); if ( !getComponentModelIdentifier().equalsIgnoreCase( componentModel ) ) { return mapper; @@ -74,14 +74,14 @@ else if ( mapper.getDecorator() != null ) { } } - if ( injectionStrategy == InjectionStrategyPrism.CONSTRUCTOR ) { + if ( injectionStrategy == InjectionStrategyGem.CONSTRUCTOR ) { buildConstructors( mapper ); } return mapper; } - protected void adjustDecorator(Mapper mapper, InjectionStrategyPrism injectionStrategy) { + protected void adjustDecorator(Mapper mapper, InjectionStrategyGem injectionStrategy) { Decorator decorator = mapper.getDecorator(); for ( Annotation typeAnnotation : getDecoratorAnnotations() ) { @@ -220,15 +220,15 @@ protected List getDelegatorReferenceAnnotations(Mapper mapper) { /** * @param originalReference the reference to be replaced * @param annotations the list of annotations - * @param injectionStrategyPrism strategy for injection + * @param injectionStrategy strategy for injection * @return the mapper reference replacing the original one */ protected Field replacementMapperReference(Field originalReference, List annotations, - InjectionStrategyPrism injectionStrategyPrism) { + InjectionStrategyGem injectionStrategy) { boolean finalField = - injectionStrategyPrism == InjectionStrategyPrism.CONSTRUCTOR && !additionalPublicEmptyConstructor(); + injectionStrategy == InjectionStrategyGem.CONSTRUCTOR && !additionalPublicEmptyConstructor(); - boolean includeAnnotationsOnField = injectionStrategyPrism == InjectionStrategyPrism.FIELD; + boolean includeAnnotationsOnField = injectionStrategy == InjectionStrategyGem.FIELD; return new AnnotationMapperReference( originalReference.getType(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 02137a59e3..197d9fa63c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -46,13 +46,13 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.prism.BuilderPrism; -import org.mapstruct.ap.internal.prism.DecoratedWithPrism; -import org.mapstruct.ap.internal.prism.InheritConfigurationPrism; -import org.mapstruct.ap.internal.prism.InheritInverseConfigurationPrism; -import org.mapstruct.ap.internal.prism.MapperPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.DecoratedWithGem; +import org.mapstruct.ap.internal.gem.InheritConfigurationGem; +import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem; +import org.mapstruct.ap.internal.gem.MapperGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -132,7 +132,7 @@ private List initReferencedMappers(TypeElement element, MapperO for ( TypeMirror usedMapper : mapperAnnotation.uses() ) { DefaultMapperReference mapperReference = DefaultMapperReference.getInstance( typeFactory.getType( usedMapper ), - MapperPrism.getInstanceOn( typeUtils.asElement( usedMapper ) ) != null, + MapperGem.instanceOn( typeUtils.asElement( usedMapper ) ) != null, typeFactory, variableNames ); @@ -186,16 +186,16 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< private Decorator getDecorator(TypeElement element, List methods, String implName, String implPackage, SortedSet extraImports) { - DecoratedWithPrism decoratorPrism = DecoratedWithPrism.getInstanceOn( element ); + DecoratedWithGem decoratedWith = DecoratedWithGem.instanceOn( element ); - if ( decoratorPrism == null ) { + if ( decoratedWith == null ) { return null; } - TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratorPrism.value() ); + TypeElement decoratorElement = (TypeElement) typeUtils.asElement( decoratedWith.value().get() ); if ( !typeUtils.isAssignable( decoratorElement.asType(), element.asType() ) ) { - messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_NO_SUBTYPE ); + messager.printMessage( element, decoratedWith.mirror(), Message.DECORATOR_NO_SUBTYPE ); } List mappingMethods = new ArrayList<>( methods.size() ); @@ -233,14 +233,14 @@ else if ( constructor.getParameters().size() == 1 ) { } if ( !hasDelegateConstructor && !hasDefaultConstructor ) { - messager.printMessage( element, decoratorPrism.mirror, Message.DECORATOR_CONSTRUCTOR ); + messager.printMessage( element, decoratedWith.mirror(), Message.DECORATOR_CONSTRUCTOR ); } Decorator decorator = new Decorator.Builder() .elementUtils( elementUtils ) .typeFactory( typeFactory ) .mapperElement( element ) - .decoratorPrism( decoratorPrism ) + .decoratedWith( decoratedWith ) .methods( mappingMethods ) .hasDelegateConstructor( hasDelegateConstructor ) .options( options ) @@ -305,7 +305,7 @@ else if ( method.isMapMapping() ) { FormattingParameters keyFormattingParameters = null; SelectionParameters valueSelectionParameters = null; FormattingParameters valueFormattingParameters = null; - NullValueMappingStrategyPrism nullValueMappingStrategy = null; + NullValueMappingStrategyGem nullValueMappingStrategy = null; if ( mappingOptions.getMapMapping() != null ) { keySelectionParameters = mappingOptions.getMapMapping().getKeySelectionParameters(); @@ -360,12 +360,12 @@ else if ( method.isStreamMapping() ) { } else { this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); - BuilderPrism builderPrism = method.getOptions().getBeanMapping().getBuilderPrism(); - BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); - BeanMappingMethod beanMappingMethod = builder + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + BeanMappingMethod.Builder beanMappingBuilder = new BeanMappingMethod.Builder(); + BeanMappingMethod beanMappingMethod = beanMappingBuilder .mappingContext( mappingContext ) .sourceMethod( method ) - .returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builderPrism ) ) + .returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builder ) ) .build(); if ( beanMappingMethod != null ) { @@ -448,7 +448,7 @@ private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConf } // apply auto inherited options - MappingInheritanceStrategyPrism inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy(); + MappingInheritanceStrategyGem inheritanceStrategy = mapperConfig.getMappingInheritanceStrategy(); if ( inheritanceStrategy.isAutoInherit() ) { // but.. there should not be an @InheritedConfiguration @@ -511,11 +511,10 @@ private SourceMethod getInverseTemplateMethod(List rawMethods, Sou List initializingMethods, MapperOptions mapperConfig) { SourceMethod resultMethod = null; - InheritInverseConfigurationPrism inversePrism = InheritInverseConfigurationPrism.getInstanceOn( - method.getExecutable() - ); + InheritInverseConfigurationGem inverseConfiguration = + InheritInverseConfigurationGem.instanceOn( method.getExecutable() ); - if ( inversePrism != null ) { + if ( inverseConfiguration != null ) { // method is configured as being inverse method, collect candidates List candidates = new ArrayList<>(); @@ -525,7 +524,7 @@ private SourceMethod getInverseTemplateMethod(List rawMethods, Sou } } - String name = inversePrism.name(); + String name = inverseConfiguration.name().get(); if ( candidates.size() == 1 ) { // no ambiguity: if no configuredBy is specified, or configuredBy specified and match if ( name.isEmpty() ) { @@ -535,7 +534,7 @@ else if ( candidates.get( 0 ).getName().equals( name ) ) { resultMethod = candidates.get( 0 ); } else { - reportErrorWhenNonMatchingName( candidates.get( 0 ), method, inversePrism ); + reportErrorWhenNonMatchingName( candidates.get( 0 ), method, inverseConfiguration ); } } else if ( candidates.size() > 1 ) { @@ -552,10 +551,10 @@ else if ( candidates.size() > 1 ) { resultMethod = nameFilteredcandidates.get( 0 ); } else if ( nameFilteredcandidates.size() > 1 ) { - reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inversePrism ); + reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inverseConfiguration ); } else { - reportErrorWhenAmbigousReverseMapping( candidates, method, inversePrism ); + reportErrorWhenAmbigousReverseMapping( candidates, method, inverseConfiguration ); } } } @@ -588,11 +587,10 @@ private SourceMethod getForwardTemplateMethod(List rawMethods, Sou List initializingMethods, MapperOptions mapperConfig) { SourceMethod resultMethod = null; - InheritConfigurationPrism forwardPrism = InheritConfigurationPrism.getInstanceOn( - method.getExecutable() - ); + InheritConfigurationGem inheritConfiguration = + InheritConfigurationGem.instanceOn( method.getExecutable() ); - if ( forwardPrism != null ) { + if ( inheritConfiguration != null ) { List candidates = new ArrayList<>(); for ( SourceMethod oneMethod : rawMethods ) { @@ -602,7 +600,7 @@ private SourceMethod getForwardTemplateMethod(List rawMethods, Sou } } - String name = forwardPrism.name(); + String name = inheritConfiguration.name().get(); if ( candidates.size() == 1 ) { // no ambiguity: if no configuredBy is specified, or configuredBy specified and match SourceMethod sourceMethod = first( candidates ); @@ -613,7 +611,7 @@ else if ( sourceMethod.getName().equals( name ) ) { resultMethod = sourceMethod; } else { - reportErrorWhenNonMatchingName( sourceMethod, method, forwardPrism ); + reportErrorWhenNonMatchingName( sourceMethod, method, inheritConfiguration ); } } else if ( candidates.size() > 1 ) { @@ -630,10 +628,10 @@ else if ( candidates.size() > 1 ) { resultMethod = first( nameFilteredcandidates ); } else if ( nameFilteredcandidates.size() > 1 ) { - reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, forwardPrism ); + reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inheritConfiguration ); } else { - reportErrorWhenAmbigousMapping( candidates, method, forwardPrism ); + reportErrorWhenAmbigousMapping( candidates, method, inheritConfiguration ); } } } @@ -642,17 +640,17 @@ else if ( nameFilteredcandidates.size() > 1 ) { } private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, - InheritInverseConfigurationPrism inversePrism) { + InheritInverseConfigurationGem inverseGem) { List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { candidateNames.add( candidate.getName() ); } - String name = inversePrism.name(); + String name = inverseGem.name().get(); if ( name.isEmpty() ) { messager.printMessage( method.getExecutable(), - inversePrism.mirror, + inverseGem.mirror(), Message.INHERITINVERSECONFIGURATION_DUPLICATES, Strings.join( candidateNames, "(), " ) @@ -660,7 +658,7 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } else { messager.printMessage( method.getExecutable(), - inversePrism.mirror, + inverseGem.mirror(), Message.INHERITINVERSECONFIGURATION_INVALID_NAME, Strings.join( candidateNames, "(), " ), name @@ -670,40 +668,40 @@ private void reportErrorWhenAmbigousReverseMapping(List candidates } private void reportErrorWhenSeveralNamesMatch(List candidates, SourceMethod method, - InheritInverseConfigurationPrism inversePrism) { + InheritInverseConfigurationGem inverseGem) { messager.printMessage( method.getExecutable(), - inversePrism.mirror, + inverseGem.mirror(), Message.INHERITINVERSECONFIGURATION_DUPLICATE_MATCHES, - inversePrism.name(), + inverseGem.name().get(), Strings.join( candidates, ", " ) ); } private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, - InheritInverseConfigurationPrism inversePrism) { + InheritInverseConfigurationGem inverseGem) { messager.printMessage( method.getExecutable(), - inversePrism.mirror, + inverseGem.mirror(), Message.INHERITINVERSECONFIGURATION_NO_NAME_MATCH, - inversePrism.name(), + inverseGem.name().get(), onlyCandidate.getName() ); } private void reportErrorWhenAmbigousMapping(List candidates, SourceMethod method, - InheritConfigurationPrism prism) { + InheritConfigurationGem gem) { List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { candidateNames.add( candidate.getName() ); } - String name = prism.name(); + String name = gem.name().get(); if ( name.isEmpty() ) { messager.printMessage( method.getExecutable(), - prism.mirror, + gem.mirror(), Message.INHERITCONFIGURATION_DUPLICATES, Strings.join( candidateNames, "(), " ) ); @@ -711,7 +709,7 @@ private void reportErrorWhenAmbigousMapping(List candidates, Sourc else { messager.printMessage( method.getExecutable(), - prism.mirror, + gem.mirror(), Message.INHERITCONFIGURATION_INVALIDNAME, Strings.join( candidateNames, "(), " ), name @@ -720,25 +718,25 @@ private void reportErrorWhenAmbigousMapping(List candidates, Sourc } private void reportErrorWhenSeveralNamesMatch(List candidates, SourceMethod method, - InheritConfigurationPrism prism) { + InheritConfigurationGem gem) { messager.printMessage( method.getExecutable(), - prism.mirror, + gem.mirror(), Message.INHERITCONFIGURATION_DUPLICATE_MATCHES, - prism.name(), + gem.name().get(), Strings.join( candidates, ", " ) ); } private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method, - InheritConfigurationPrism prims) { + InheritConfigurationGem gem) { messager.printMessage( method.getExecutable(), - prims.mirror, + gem.mirror(), Message.INHERITCONFIGURATION_NO_NAME_MATCH, - prims.name(), + gem.name().get(), onlyCandidate.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index e1f62bf6b0..09a0cc95f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -34,14 +34,14 @@ import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.ValueMappingOptions; -import org.mapstruct.ap.internal.prism.BeanMappingPrism; -import org.mapstruct.ap.internal.prism.IterableMappingPrism; -import org.mapstruct.ap.internal.prism.MapMappingPrism; -import org.mapstruct.ap.internal.prism.MappingPrism; -import org.mapstruct.ap.internal.prism.MappingsPrism; -import org.mapstruct.ap.internal.prism.ObjectFactoryPrism; -import org.mapstruct.ap.internal.prism.ValueMappingPrism; -import org.mapstruct.ap.internal.prism.ValueMappingsPrism; +import org.mapstruct.ap.internal.gem.BeanMappingGem; +import org.mapstruct.ap.internal.gem.IterableMappingGem; +import org.mapstruct.ap.internal.gem.MapMappingGem; +import org.mapstruct.ap.internal.gem.MappingGem; +import org.mapstruct.ap.internal.gem.MappingsGem; +import org.mapstruct.ap.internal.gem.ObjectFactoryGem; +import org.mapstruct.ap.internal.gem.ValueMappingGem; +import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Executables; @@ -247,7 +247,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, retrieveContextProvidedMethods( contextParameters, mapperToImplement, mapperOptions ); BeanMappingOptions beanMappingOptions = BeanMappingOptions.getInstanceOn( - BeanMappingPrism.getInstanceOn( method ), + BeanMappingGem.instanceOn( method ), mapperOptions, method, messager, @@ -257,16 +257,16 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, Set mappingOptions = getMappings( method, method, beanMappingOptions, new LinkedHashSet<>(), new HashSet<>() ); - IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromPrism( - IterableMappingPrism.getInstanceOn( method ), + IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromGem( + IterableMappingGem.instanceOn( method ), mapperOptions, method, messager, typeUtils ); - MapMappingOptions mapMappingOptions = MapMappingOptions.fromPrism( - MapMappingPrism.getInstanceOn( method ), + MapMappingOptions mapMappingOptions = MapMappingOptions.fromGem( + MapMappingGem.instanceOn( method ), mapperOptions, method, messager, @@ -359,7 +359,7 @@ private boolean isValidFactoryMethod(ExecutableElement method, List p } private boolean hasFactoryAnnotation(ExecutableElement method) { - return ObjectFactoryPrism.getInstanceOn( method ) != null; + return ObjectFactoryGem.instanceOn( method ) != null; } private boolean isVoid(Type returnType) { @@ -514,25 +514,25 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List getMappings(ExecutableElement method, Element element, - BeanMappingOptions beanMapping, Set mappings, + BeanMappingOptions beanMapping, Set mappingOptions, Set handledElements) { for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { Element lElement = annotationMirror.getAnnotationType().asElement(); if ( isAnnotation( lElement, MAPPING_FQN ) ) { // although getInstanceOn does a search on annotation mirrors, the order is preserved - MappingPrism mappingPrism = MappingPrism.getInstanceOn( element ); - MappingOptions.addInstance( mappingPrism, method, beanMapping, messager, typeUtils, mappings ); + MappingGem mapping = MappingGem.instanceOn( element ); + MappingOptions.addInstance( mapping, method, beanMapping, messager, typeUtils, mappingOptions ); } else if ( isAnnotation( lElement, MAPPINGS_FQN ) ) { // although getInstanceOn does a search on annotation mirrors, the order is preserved - MappingsPrism mappingsPrism = MappingsPrism.getInstanceOn( element ); - MappingOptions.addInstances( mappingsPrism, method, beanMapping, messager, typeUtils, mappings ); + MappingsGem mappings = MappingsGem.instanceOn( element ); + MappingOptions.addInstances( mappings, method, beanMapping, messager, typeUtils, mappingOptions ); } else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG ) @@ -540,10 +540,10 @@ else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) ) { // recur over annotation mirrors handledElements.add( lElement ); - getMappings( method, lElement, beanMapping, mappings, handledElements ); + getMappings( method, lElement, beanMapping, mappingOptions, handledElements ); } } - return mappings; + return mappingOptions; } private boolean isAnnotationInPackage(Element element, String packageFQN ) { @@ -571,18 +571,18 @@ private boolean isAnnotation(Element element, String annotationFQN) { private List getValueMappings(ExecutableElement method) { List valueMappings = new ArrayList<>(); - ValueMappingPrism mappingAnnotation = ValueMappingPrism.getInstanceOn( method ); - ValueMappingsPrism mappingsAnnotation = ValueMappingsPrism.getInstanceOn( method ); + ValueMappingGem mappingAnnotation = ValueMappingGem.instanceOn( method ); + ValueMappingsGem mappingsAnnotation = ValueMappingsGem.instanceOn( method ); if ( mappingAnnotation != null ) { - ValueMappingOptions valueMapping = ValueMappingOptions.fromMappingPrism( mappingAnnotation ); + ValueMappingOptions valueMapping = ValueMappingOptions.fromMappingGem( mappingAnnotation ); if ( valueMapping != null ) { valueMappings.add( valueMapping ); } } if ( mappingsAnnotation != null ) { - ValueMappingOptions.fromMappingsPrism( mappingsAnnotation, method, messager, valueMappings ); + ValueMappingOptions.fromMappingsGem( mappingsAnnotation, method, messager, valueMappings ); } return valueMappings; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 8959eb3614..25de97d2b9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -43,7 +43,7 @@ import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -664,11 +664,11 @@ Assignment getAssignment() { void reportMessageWhenNarrowing(FormattingMessager messager, ResolvingAttempt attempt) { if ( NativeTypes.isNarrowing( sourceType.getFullyQualifiedName(), targetType.getFullyQualifiedName() ) ) { - ReportingPolicyPrism policy = attempt.mappingMethod.getOptions().getMapper().typeConversionPolicy(); - if ( policy == ReportingPolicyPrism.WARN ) { + ReportingPolicyGem policy = attempt.mappingMethod.getOptions().getMapper().typeConversionPolicy(); + if ( policy == ReportingPolicyGem.WARN ) { report( messager, attempt, Message.CONVERSION_LOSSY_WARNING ); } - else if ( policy == ReportingPolicyPrism.ERROR ) { + else if ( policy == ReportingPolicyGem.ERROR ) { report( messager, attempt, Message.CONVERSION_LOSSY_ERROR ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index 4fbae2bdbd..b6de4662b1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -18,8 +18,8 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; -import org.mapstruct.ap.internal.prism.AfterMappingPrism; -import org.mapstruct.ap.internal.prism.BeforeMappingPrism; +import org.mapstruct.ap.internal.gem.AfterMappingGem; +import org.mapstruct.ap.internal.gem.BeforeMappingGem; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; @@ -233,7 +233,7 @@ public static boolean isLifecycleCallbackMethod(ExecutableElement executableElem * @return {@code true}, if the executable element is a method annotated with {@code @AfterMapping} */ public static boolean isAfterMappingMethod(ExecutableElement executableElement) { - return AfterMappingPrism.getInstanceOn( executableElement ) != null; + return AfterMappingGem.instanceOn( executableElement ) != null; } /** @@ -241,6 +241,6 @@ public static boolean isAfterMappingMethod(ExecutableElement executableElement) * @return {@code true}, if the executable element is a method annotated with {@code @BeforeMapping} */ public static boolean isBeforeMappingMethod(ExecutableElement executableElement) { - return BeforeMappingPrism.getInstanceOn( executableElement ) != null; + return BeforeMappingGem.instanceOn( executableElement ) != null; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java similarity index 75% rename from processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java rename to processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index 2f439cfe75..b33f00964b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -3,13 +3,13 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.prism; +package org.mapstruct.ap.test.gem; import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; import org.mapstruct.MappingConstants; -import org.mapstruct.ap.internal.prism.MappingConstantsPrism; +import org.mapstruct.ap.internal.gem.MappingConstantsGem; /** * Test constants values @@ -20,8 +20,8 @@ public class ConstantTest { @Test public void constantsShouldBeEqual() { - assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsPrism.ANY_REMAINING ); - assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsPrism.ANY_UNMAPPED ); - assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsPrism.NULL ); + assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsGem.ANY_REMAINING ); + assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsGem.ANY_UNMAPPED ); + assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsGem.NULL ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java similarity index 52% rename from processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java rename to processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java index 3090ead472..3da35b91fb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/prism/EnumPrismsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.prism; +package org.mapstruct.ap.test.gem; import static org.assertj.core.api.Assertions.assertThat; @@ -18,53 +18,53 @@ import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ReportingPolicy; -import org.mapstruct.ap.internal.prism.CollectionMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.InjectionStrategyPrism; -import org.mapstruct.ap.internal.prism.MappingInheritanceStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueCheckStrategyPrism; -import org.mapstruct.ap.internal.prism.NullValueMappingStrategyPrism; -import org.mapstruct.ap.internal.prism.ReportingPolicyPrism; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; /** - * Test for manually created prisms on enumeration types + * Test for manually created gems on enumeration types * * @author Andreas Gudian */ -public class EnumPrismsTest { +public class EnumGemsTest { @Test - public void collectionMappingStrategyPrismIsCorrect() { + public void collectionMappingStrategyGemIsCorrect() { assertThat( namesOf( CollectionMappingStrategy.values() ) ).isEqualTo( - namesOf( CollectionMappingStrategyPrism.values() ) ); + namesOf( CollectionMappingStrategyGem.values() ) ); } @Test - public void mappingInheritanceStrategyPrismIsCorrect() { + public void mappingInheritanceStrategyGemIsCorrect() { assertThat( namesOf( MappingInheritanceStrategy.values() ) ).isEqualTo( - namesOf( MappingInheritanceStrategyPrism.values() ) ); + namesOf( MappingInheritanceStrategyGem.values() ) ); } @Test - public void nullValueCheckStrategyPrismIsCorrect() { + public void nullValueCheckStrategyGemIsCorrect() { assertThat( namesOf( NullValueCheckStrategy.values() ) ).isEqualTo( - namesOf( NullValueCheckStrategyPrism.values() ) ); + namesOf( NullValueCheckStrategyGem.values() ) ); } @Test - public void nullValueMappingStrategyPrismIsCorrect() { + public void nullValueMappingStrategyGemIsCorrect() { assertThat( namesOf( NullValueMappingStrategy.values() ) ).isEqualTo( - namesOf( NullValueMappingStrategyPrism.values() ) ); + namesOf( NullValueMappingStrategyGem.values() ) ); } @Test - public void reportingPolicyPrismIsCorrect() { + public void reportingPolicyGemIsCorrect() { assertThat( namesOf( ReportingPolicy.values() ) ).isEqualTo( - namesOf( ReportingPolicyPrism.values() ) ); + namesOf( ReportingPolicyGem.values() ) ); } @Test - public void injectionStrategyPrismIsCorrect() { + public void injectionStrategyGemIsCorrect() { assertThat( namesOf( InjectionStrategy.values() ) ).isEqualTo( - namesOf( InjectionStrategyPrism.values() ) ); + namesOf( InjectionStrategyGem.values() ) ); } private static List namesOf(Enum[] values) { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 24d3aeb9ec..ca51554f30 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -144,6 +144,7 @@ private static List buildProcessorClasspath() { "freemarker", "javax.inject", "spring-context", + "gem-api", "joda-time" }; return filterBootClassPath( whitelist ); diff --git a/readme.md b/readme.md index cbd410ab10..37376c8714 100644 --- a/readme.md +++ b/readme.md @@ -145,7 +145,7 @@ from the root of the project directory. To skip the distribution module, run ## Importing into IDE -MapStruct uses the hickory annotation processor to generate mapping prisms for it's own annotations. +MapStruct uses the gem annotation processor to generate mapping gems for it's own annotations. Therefore for seamless integration within an IDE annotation processing needs to be enabled. ### IntelliJ From 58da2d293f74309b3679b331013f6466d2d09aa8 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 2 Feb 2020 10:05:26 +0100 Subject: [PATCH 0432/1006] #695 user control over mapping means (direct, method, conversion, 2step) --- .../main/java/org/mapstruct/BeanMapping.java | 16 ++ .../java/org/mapstruct/IterableMapping.java | 18 +- .../main/java/org/mapstruct/MapMapping.java | 32 ++- core/src/main/java/org/mapstruct/Mapper.java | 15 ++ .../main/java/org/mapstruct/MapperConfig.java | 17 ++ core/src/main/java/org/mapstruct/Mapping.java | 17 ++ .../java/org/mapstruct/control/DeepClone.java | 24 +++ .../org/mapstruct/control/MappingControl.java | 150 +++++++++++++++ .../mapstruct/control/MappingControls.java | 23 +++ .../mapstruct/control/NoComplexMapping.java | 29 +++ .../chapter-5-data-type-conversions.asciidoc | 24 ++- .../ap/internal/gem/GemGenerator.java | 5 + .../ap/internal/gem/MappingControlUseGem.java | 18 ++ .../ap/internal/model/BeanMappingMethod.java | 1 + .../model/ContainerMappingMethodBuilder.java | 1 + .../ap/internal/model/MapMappingMethod.java | 15 +- .../ap/internal/model/PropertyMapping.java | 21 +- .../ap/internal/model/common/Type.java | 4 + .../model/source/BeanMappingOptions.java | 10 + .../internal/model/source/DefaultOptions.java | 6 + .../model/source/DelegatingOptions.java | 5 + .../model/source/IterableMappingOptions.java | 9 + .../model/source/MapMappingOptions.java | 17 ++ .../model/source/MapperConfigOptions.java | 8 + .../internal/model/source/MapperOptions.java | 8 + .../internal/model/source/MappingControl.java | 119 ++++++++++++ .../internal/model/source/MappingOptions.java | 12 +- .../source/selector/SelectionCriteria.java | 51 ++++- .../creation/MappingResolverImpl.java | 107 ++++++---- .../ap/test/mappingcontrol/CloningMapper.java | 19 ++ .../ap/test/mappingcontrol/ComplexMapper.java | 23 +++ .../ap/test/mappingcontrol/Config.java | 16 ++ .../test/mappingcontrol/ConversionMapper.java | 18 ++ .../ap/test/mappingcontrol/CoolBeerDTO.java | 19 ++ .../ap/test/mappingcontrol/DirectMapper.java | 20 ++ .../ErroneousComplexMapper.java | 23 +++ .../ErroneousComplexMapperWithConfig.java | 23 +++ .../ErroneousConversionMapper.java | 18 ++ .../mappingcontrol/ErroneousDirectMapper.java | 20 ++ .../mappingcontrol/ErroneousMethodMapper.java | 19 ++ .../ap/test/mappingcontrol/Fridge.java | 19 ++ .../ap/test/mappingcontrol/FridgeDTO.java | 19 ++ .../mappingcontrol/MappingControlTest.java | 182 ++++++++++++++++++ .../ap/test/mappingcontrol/MethodMapper.java | 23 +++ .../ap/test/mappingcontrol/ShelveDTO.java | 19 ++ .../ap/test/mappingcontrol/UseComplex.java | 18 ++ .../ap/test/mappingcontrol/UseDirect.java | 18 ++ 47 files changed, 1237 insertions(+), 61 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/control/DeepClone.java create mode 100644 core/src/main/java/org/mapstruct/control/MappingControl.java create mode 100644 core/src/main/java/org/mapstruct/control/MappingControls.java create mode 100644 core/src/main/java/org/mapstruct/control/NoComplexMapping.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/gem/MappingControlUseGem.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ComplexMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ConversionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CoolBeerDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/DirectMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapperWithConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousDirectMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Fridge.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/FridgeDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ShelveDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseComplex.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseDirect.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index 55ab05ae5e..329d7bd50e 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -11,6 +11,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.mapstruct.control.MappingControl; + import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; /** @@ -156,4 +158,18 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() * @since 1.3 */ Builder builder() default @Builder; + + /** + * Allows detailed control over the mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class mappingControl() default MappingControl.class; + } diff --git a/core/src/main/java/org/mapstruct/IterableMapping.java b/core/src/main/java/org/mapstruct/IterableMapping.java index 3041c4bfd0..76153127bd 100644 --- a/core/src/main/java/org/mapstruct/IterableMapping.java +++ b/core/src/main/java/org/mapstruct/IterableMapping.java @@ -10,10 +10,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.text.SimpleDateFormat; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.Date; +import org.mapstruct.control.MappingControl; + /** * Configures the mapping between two iterable like types, e.g. {@code List} and {@code List}. * @@ -121,4 +123,18 @@ * @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapping. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + + /** + * Allows detailed control over the mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class elementMappingControl() default MappingControl.class; + } diff --git a/core/src/main/java/org/mapstruct/MapMapping.java b/core/src/main/java/org/mapstruct/MapMapping.java index 4e014d9ba6..271272bb45 100644 --- a/core/src/main/java/org/mapstruct/MapMapping.java +++ b/core/src/main/java/org/mapstruct/MapMapping.java @@ -10,10 +10,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.text.SimpleDateFormat; import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.Date; +import org.mapstruct.control.MappingControl; + /** * Configures the mapping between two map types, e.g. Map<String, String> and Map<Long, Date>. * @@ -167,4 +169,32 @@ * @return The strategy to be applied when {@code null} is passed as source value to the methods of this mapping. */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + + /** + * Allows detailed control over the key mapping process. + * + * @return the mapping control + * + * @since 1.4 + + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class keyMappingControl() default MappingControl.class; + + + /** + * Allows detailed control over the value mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class valueMappingControl() default MappingControl.class; + } diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 52d12426fc..ce8eebf1cb 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -5,11 +5,13 @@ */ package org.mapstruct; +import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.mapstruct.control.MappingControl; import org.mapstruct.factory.Mappers; import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; @@ -281,4 +283,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default * @since 1.3 */ Builder builder() default @Builder; + + /** + * Allows detailed control over the mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class mappingControl() default MappingControl.class; } diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index c03217f08e..326041164f 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -5,11 +5,13 @@ */ package org.mapstruct; +import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.mapstruct.control.MappingControl; import org.mapstruct.factory.Mappers; import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; @@ -255,4 +257,19 @@ MappingInheritanceStrategy mappingInheritanceStrategy() * @since 1.3 */ Builder builder() default @Builder; + + /** + * Allows detailed control over the mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class mappingControl() default MappingControl.class; + } + diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 98a309e057..b5ce5c7a83 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -15,6 +15,8 @@ import java.text.SimpleDateFormat; import java.util.Date; +import org.mapstruct.control.MappingControl; + import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; /** @@ -394,4 +396,19 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default NullValuePropertyMappingStrategy.SET_TO_NULL; + /** + * Allows detailed control over the mapping process. + * + * @return the mapping control + * + * @since 1.4 + * + * @see org.mapstruct.control.DeepClone + * @see org.mapstruct.control.NoComplexMapping + * @see org.mapstruct.control.MappingControl + */ + Class mappingControl() default MappingControl.class; + + + } diff --git a/core/src/main/java/org/mapstruct/control/DeepClone.java b/core/src/main/java/org/mapstruct/control/DeepClone.java new file mode 100644 index 0000000000..a5264c861e --- /dev/null +++ b/core/src/main/java/org/mapstruct/control/DeepClone.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.control; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.util.Experimental; + +/** + * Clones a source type to a target type (assuming source and target are of the same type). + * + * @author Sjaak Derksen + * + * @since 1.4 + */ +@Retention(RetentionPolicy.CLASS) +@Experimental +@MappingControl( MappingControl.Use.MAPPING_METHOD ) +public @interface DeepClone { +} diff --git a/core/src/main/java/org/mapstruct/control/MappingControl.java b/core/src/main/java/org/mapstruct/control/MappingControl.java new file mode 100644 index 0000000000..975ff52e90 --- /dev/null +++ b/core/src/main/java/org/mapstruct/control/MappingControl.java @@ -0,0 +1,150 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.control; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * Controls which means of mapping are considered between the source and the target in mappings. + * + *

      + * There are several applications of MappingControl conceivable. One application, "deep cloning" is + * explained below in the example. + *

      + * + *

      + * Another application is controlling so called "complex mappings", which are not always desirable and sometimes lead to + * unexpected behaviour and prolonged compilation time. + *

      + * + *

      Example:Cloning of an object

      + *

      + * When all methods are allowed, MapStruct would make a shallow copy. It would take the ShelveDTO in + * the FridgeDTO and directly enter that as target on the target FridgeDTO. By disabling all + * other kinds of mappings apart from {@link MappingControl.Use#MAPPING_METHOD}, see {@link DeepClone} MapStruct is + * forced to generate mapping methods all through the object graph `FridgeDTO` and hence create a deep clone. + *

      + *
      
      + * public class FridgeDTO {
      + *
      + *     private ShelveDTO shelve;
      + *
      + *     public ShelveDTO getShelve() {
      + *         return shelve;
      + *     }
      + *
      + *     public void setShelve(ShelveDTO shelve) {
      + *         this.shelve = shelve;
      + *     }
      + * }
      + * 
      + *
      
      + * public class ShelveDTO {
      + *
      + *     private CoolBeerDTO coolBeer;
      + *
      + *     public CoolBeerDTO getCoolBeer() {
      + *         return coolBeer;
      + *     }
      + *
      + *     public void setCoolBeer(CoolBeerDTO coolBeer) {
      + *         this.coolBeer = coolBeer;
      + *     }
      + * }
      + * 
      + *
      
      + * public class CoolBeerDTO {
      + *
      + *     private String beerCount;
      + *
      + *     public String getBeerCount() {
      + *         return beerCount;
      + *     }
      + *
      + *     public void setBeerCount(String beerCount) {
      + *         this.beerCount = beerCount;
      + *     }
      + * }
      + * 
      + * + *
      
      + * @Mapper(mappingControl = DeepClone.class)
      + * public interface CloningMapper {
      + *
      + *     CloningMapper INSTANCE = Mappers.getMapper( CloningMapper.class );
      + *
      + *     FridgeDTO clone(FridgeDTO in);
      + *
      + * }
      + * 
      + * + * @author Sjaak Derksen + */ +@Retention(RetentionPolicy.CLASS) +@Repeatable(MappingControls.class) +@Target( ElementType.ANNOTATION_TYPE ) +@MappingControl( MappingControl.Use.DIRECT ) +@MappingControl( MappingControl.Use.BUILT_IN_CONVERSION ) +@MappingControl( MappingControl.Use.MAPPING_METHOD ) +@MappingControl( MappingControl.Use.COMPLEX_MAPPING ) +public @interface MappingControl { + + Use value(); + + enum Use { + + /** + * Controls the mapping, allows for type conversion from source type to target type + *

      + * Type conversions are typically supported directly in Java. The "toString()" is such an example, + * which allows for mapping for instance a {@link java.lang.Number} type to a {@link java.lang.String}. + *

      + * Please refer to the MapStruct guide for more info. + * + * @since 1.4 + */ + BUILT_IN_CONVERSION, + + /** + * Controls the mapping from source to target type, allows mapping by calling: + *

        + *
      1. A type conversion, passed into a mapping method
      2. + *
      3. A mapping method, passed into a type conversion
      4. + *
      5. A mapping method passed into another mapping method
      6. + *
      + * + * @since 1.4 + */ + COMPLEX_MAPPING, + /** + * Controls the mapping, allows for a direct mapping from source type to target type. + *

      + * This means if source type and target type are of the same type, MapStruct will not perform + * any mappings anymore and assign the target to the source direct. + *

      + * An exception are types from the package {@link java}, which will be mapped always directly. + * + * @since 1.4 + */ + DIRECT, + + /** + * Controls the mapping, allows for Direct Mapping from source type to target type. + *

      + * The mapping method can be either a custom referred mapping method, or a MapStruct built in + * mapping method. + * + * @since 1.4 + */ + MAPPING_METHOD + } + +} diff --git a/core/src/main/java/org/mapstruct/control/MappingControls.java b/core/src/main/java/org/mapstruct/control/MappingControls.java new file mode 100644 index 0000000000..d3b4fe1556 --- /dev/null +++ b/core/src/main/java/org/mapstruct/control/MappingControls.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.control; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Allows multiple {@link MappingControl} on a class declaration. + * + * @author Sjaak Derksen + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.ANNOTATION_TYPE) +public @interface MappingControls { + + MappingControl[] value(); +} diff --git a/core/src/main/java/org/mapstruct/control/NoComplexMapping.java b/core/src/main/java/org/mapstruct/control/NoComplexMapping.java new file mode 100644 index 0000000000..5894f602a5 --- /dev/null +++ b/core/src/main/java/org/mapstruct/control/NoComplexMapping.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.control; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.util.Experimental; + +/** + * Disables complex mappings, mappings that require 2 mapping means (method, built-in conversion) to constitute + * a mapping from source to target. + * + * @see MappingControl.Use#COMPLEX_MAPPING + * + * @author Sjaak Derksen + * + * @since 1.4 + */ +@Retention(RetentionPolicy.CLASS) +@Experimental +@MappingControl( MappingControl.Use.DIRECT ) +@MappingControl( MappingControl.Use.BUILT_IN_CONVERSION ) +@MappingControl( MappingControl.Use.MAPPING_METHOD ) +public @interface NoComplexMapping { +} diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 2a446dee5e..7a22aad559 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -145,15 +145,27 @@ That way it is possible to map arbitrary deep object graphs. When mapping from e When generating the implementation of a mapping method, MapStruct will apply the following routine for each attribute pair in the source and target object: -* If source and target attribute have the same type, the value will be simply copied from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. -* If source and target attribute type differ, check whether there is another mapping method which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. -* If no such method exists MapStruct will look whether a built-in conversion for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. -* If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. -* If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. +. If source and target attribute have the same type, the value will be simply copied *direct* from source to target. If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target attribute. +. If source and target attribute type differ, check whether there is another *mapping method* which has the type of the source attribute as parameter type and the type of the target attribute as return type. If such a method exists it will be invoked in the generated mapping implementation. +. If no such method exists MapStruct will look whether a *built-in conversion* for the source and target type of the attribute exists. If this is the case, the generated mapping code will apply this conversion. +. If no such method exists MapStruct will apply *complex* conversions: +.. mapping method, the result mapped by mapping method, like this: `target = method1( method2( source ) )` +.. built-in conversion, the result mapped by mapping method, like this: `target = method( conversion( source ) )` +.. mapping method, the result mapped by build-in conversion, like this: `target = conversion( method( source ) )` +. If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. +. If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. + +A mapping control (`MappingControl`) can be defined on all levels (`@MappingConfig`, `@Mapper`, `@BeanMapping`, `@Mapping`), the latter taking precedence over the former. For example: `@Mapper( mappingControl = NoComplexMapping.class )` takes precedence over `@MapperConfig( mappingControl = DeepClone.class )`. `@IterableMapping` and `@MapMapping` work similar as `@Mapping`. MappingControl is experimental from MapStruct 1.4. +`MappingControl` has an enum that corresponds to the first 4 options above: `MappingControl.Use#DIRECT`, `MappingControl.Use#MAPPING_METHOD`, `MappingControl.Use#BUILT_IN_CONVERSION` and `MappingControl.Use#COMPLEX_MAPPING` the presence of which allows the user to switch *on* a option. The absence of an enum switches *off* a mapping option. Default they are all present enabling all mapping options. [NOTE] ==== -In order to stop MapStruct from generating automatic sub-mapping methods, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. +In order to stop MapStruct from generating automatic sub-mapping methods as in 5. above, one can use `@Mapper( disableSubMappingMethodsGeneration = true )`. +==== + +[TIP] +==== +The user has full control over the mapping by means of meta annotations. Some handy ones have been defined such as `@DeepClone` which only allows direct mappings. The result: if source and target type are the same, MapStruct will make a deep clone of the source. Sub-mappings-methods have to be allowed (default option). ==== [NOTE] diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 6852f013e7..b4d7758a10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -29,6 +29,8 @@ import org.mapstruct.TargetType; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; +import org.mapstruct.control.MappingControl; +import org.mapstruct.control.MappingControls; import org.mapstruct.tools.gem.GemDefinition; /** @@ -58,6 +60,9 @@ @GemDefinition(Context.class) @GemDefinition(Builder.class) +@GemDefinition(MappingControl.class) +@GemDefinition(MappingControls.class) + // external types @GemDefinition(XmlElementDecl.class) @GemDefinition(XmlElementRef.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingControlUseGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingControlUseGem.java new file mode 100644 index 0000000000..94c8350ef8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingControlUseGem.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.gem; + +/** + * + * @author Sjaak + */ +public enum MappingControlUseGem { + + BUILT_IN_CONVERSION, + COMPLEX_MAPPING, + DIRECT, + MAPPING_METHOD +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index af14d384c1..1fcf8e4ce2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -577,6 +577,7 @@ else if ( mapping.getConstant() != null ) { .targetPropertyName( targetPropertyName ) .formattingParameters( mapping.getFormattingParameters() ) .selectionParameters( mapping.getSelectionParameters() ) + .options( mapping ) .existingVariableNames( existingVariableNames ) .dependsOn( mapping.getDependsOn() ) .mirror( mapping.getMirror() ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index e669e69aad..67c03fd3de 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -77,6 +77,7 @@ public final M build() { ); SelectionCriteria criteria = SelectionCriteria.forMappingMethods( selectionParameters, + method.getOptions().getIterableMapping().getMappingControl( ctx.getElementUtils() ), callingContextTargetPropertyName, false ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index e14382318e..0fbe6f9c00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -87,8 +87,12 @@ public MapMappingMethod build() { SourceRHS keySourceRHS = new SourceRHS( "entry.getKey()", keySourceType, new HashSet<>(), "map key" ); - SelectionCriteria keyCriteria = - SelectionCriteria.forMappingMethods( keySelectionParameters, null, false ); + SelectionCriteria keyCriteria = SelectionCriteria.forMappingMethods( + keySelectionParameters, + method.getOptions().getMapMapping().getKeyMappingControl( ctx.getElementUtils() ), + null, + false + ); Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method, @@ -130,8 +134,11 @@ public MapMappingMethod build() { SourceRHS valueSourceRHS = new SourceRHS( "entry.getValue()", valueSourceType, new HashSet<>(), "map value" ); - SelectionCriteria valueCriteria = - SelectionCriteria.forMappingMethods( valueSelectionParameters, null, false ); + SelectionCriteria valueCriteria = SelectionCriteria.forMappingMethods( + valueSelectionParameters, + method.getOptions().getMapMapping().getValueMappingControl( ctx.getElementUtils() ), + null, + false ); Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 7b806f57ef..06de2aa397 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -31,6 +31,8 @@ import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.DelegatingOptions; +import org.mapstruct.ap.internal.model.source.MappingControl; +import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; @@ -154,6 +156,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase MappingControl.fromTypeMirror( mc, elementUtils ) ) + .orElse( next().getMappingControl( elementUtils ) ); + } + // @BeanMapping specific public SelectionParameters getSelectionParameters() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index adbc5286bc..77911be2e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.Set; import javax.lang.model.type.DeclaredType; +import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -121,6 +122,11 @@ public BuilderGem getBuilder() { return null; } + @Override + public MappingControl getMappingControl(Elements elementUtils) { + return MappingControl.fromTypeMirror( mapper.mappingControl().getDefaultValue(), elementUtils ); + } + @Override public boolean hasAnnotation() { return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 9062b0a031..b9dc068d07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -11,6 +11,7 @@ import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -100,6 +101,10 @@ public BuilderGem getBuilder() { return next.getBuilder(); } + public MappingControl getMappingControl(Elements elementUtils) { + return next.getMappingControl( elementUtils ); + } + DelegatingOptions next() { return next; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index 70601a96c6..73ae1907cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -8,6 +8,7 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -101,6 +102,14 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } + public MappingControl getElementMappingControl(Elements elementUtils) { + return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::elementMappingControl ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( mc -> MappingControl.fromTypeMirror( mc, elementUtils ) ) + .orElse( next().getMappingControl( elementUtils ) ); + } + @Override public boolean hasAnnotation() { return iterableMapping != null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index 3dd3927f58..96ff577f48 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -8,6 +8,7 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -145,6 +146,22 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } + public MappingControl getKeyMappingControl(Elements elementUtils) { + return Optional.ofNullable( mapMapping ).map( MapMappingGem::keyMappingControl ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( mc -> MappingControl.fromTypeMirror( mc, elementUtils ) ) + .orElse( next().getMappingControl( elementUtils ) ); + } + + public MappingControl getValueMappingControl(Elements elementUtils) { + return Optional.ofNullable( mapMapping ).map( MapMappingGem::valueMappingControl ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( mc -> MappingControl.fromTypeMirror( mc, elementUtils ) ) + .orElse( next().getMappingControl( elementUtils ) ); + } + @Override public boolean hasAnnotation() { return mapMapping != null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index 5a3a0e1ade..ef25fda053 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -7,6 +7,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; +import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -129,6 +130,13 @@ public BuilderGem getBuilder() { return mapperConfig.builder().hasValue() ? mapperConfig.builder().get() : next().getBuilder(); } + @Override + public MappingControl getMappingControl(Elements elementUtils) { + return mapperConfig.mappingControl().hasValue() ? + MappingControl.fromTypeMirror( mapperConfig.mappingControl().getValue(), elementUtils ) : + next().getMappingControl( elementUtils ); + } + @Override public boolean hasAnnotation() { return mapperConfig != null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 9472694067..19b7d8f0b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -11,6 +11,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; +import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -159,6 +160,13 @@ public BuilderGem getBuilder() { return mapper.builder().hasValue() ? mapper.builder().get() : next().getBuilder(); } + @Override + public MappingControl getMappingControl(Elements elementUtils) { + return mapper.mappingControl().hasValue() ? + MappingControl.fromTypeMirror( mapper.mappingControl().getValue(), elementUtils ) : + next().getMappingControl( elementUtils ); + } + // @Mapper specific public DeclaredType mapperConfigType() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java new file mode 100644 index 0000000000..fc896bb52e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java @@ -0,0 +1,119 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.HashSet; +import java.util.Set; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; + +import org.mapstruct.ap.internal.gem.MappingControlGem; +import org.mapstruct.ap.internal.gem.MappingControlUseGem; +import org.mapstruct.ap.internal.gem.MappingControlsGem; + +public class MappingControl { + + private static final String JAVA_LANG_ANNOTATION_PGK = "java.lang.annotation"; + private static final String ORG_MAPSTRUCT_PKG = "org.mapstruct"; + private static final String MAPPING_CONTROL_FQN = "org.mapstruct.control.MappingControl"; + private static final String MAPPING_CONTROLS_FQN = "org.mapstruct.control.MappingControls"; + + private boolean allowDirect = false; + private boolean allowTypeConversion = false; + private boolean allowMappingMethod = false; + private boolean allow2Steps = false; + + public static MappingControl fromTypeMirror(TypeMirror mirror, Elements elementUtils) { + MappingControl mappingControl = new MappingControl(); + if ( TypeKind.DECLARED == mirror.getKind() ) { + resolveControls( mappingControl, ( (DeclaredType) mirror ).asElement(), new HashSet<>(), elementUtils ); + } + return mappingControl; + } + + private MappingControl() { + } + + public boolean allowDirect() { + return allowDirect; + } + + public boolean allowTypeConversion() { + return allowTypeConversion; + } + + public boolean allowMappingMethod() { + return allowMappingMethod; + } + + public boolean allowBy2Steps() { + return allow2Steps; + } + + private static void resolveControls(MappingControl control, Element element, Set handledElements, + Elements elementUtils) { + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + Element lElement = annotationMirror.getAnnotationType().asElement(); + if ( isAnnotation( lElement, MAPPING_CONTROL_FQN ) ) { + determineMappingControl( control, MappingControlGem.instanceOn( element ) ); + } + else if ( isAnnotation( lElement, MAPPING_CONTROLS_FQN ) ) { + MappingControlsGem.instanceOn( element ) + .value() + .get() + .forEach( m -> determineMappingControl( control, m ) ); + } + else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK, elementUtils ) + && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG, elementUtils ) + && !handledElements.contains( lElement ) + ) { + // recur over annotation mirrors + handledElements.add( lElement ); + resolveControls( control, lElement, handledElements, elementUtils ); + } + } + } + + private static void determineMappingControl(MappingControl in, MappingControlGem gem) { + MappingControlUseGem use = MappingControlUseGem.valueOf( gem.value().get() ); + switch ( use ) { + case DIRECT: + in.allowDirect = true; + break; + case MAPPING_METHOD: + in.allowMappingMethod = true; + break; + case BUILT_IN_CONVERSION: + in.allowTypeConversion = true; + break; + case COMPLEX_MAPPING: + in.allow2Steps = true; + break; + default: + } + } + + private static boolean isAnnotationInPackage(Element element, String packageFQN, Elements elementUtils) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); + } + return false; + } + + private static boolean isAnnotation(Element element, String annotationFQN) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return annotationFQN.equals( ( (TypeElement) element ).getQualifiedName().toString() ); + } + return false; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 1557d68920..ed88e5107a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -17,13 +17,14 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.util.Elements; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.gem.MappingGem; import org.mapstruct.ap.internal.gem.MappingsGem; import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.tools.gem.GemValue; @@ -409,6 +410,15 @@ public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() .orElse( next().getNullValuePropertyMappingStrategy() ); } + @Override + public MappingControl getMappingControl(Elements elementUtils) { + return Optional.ofNullable( mapping ).map( MappingGem::mappingControl ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( mc -> MappingControl.fromTypeMirror( mc, elementUtils ) ) + .orElse( next().getMappingControl( elementUtils ) ); + } + /** * mapping can only be inversed if the source was not a constant nor an expression nor a nested property * and the mapping is not a 'target-source-ignore' mapping diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index c632fec6c4..23c67b230e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -11,6 +11,7 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.common.SourceRHS; +import org.mapstruct.ap.internal.model.source.MappingControl; import org.mapstruct.ap.internal.model.source.SelectionParameters; /** @@ -28,9 +29,13 @@ public class SelectionCriteria { private boolean preferUpdateMapping; private final boolean objectFactoryRequired; private final boolean lifecycleCallbackRequired; + private final boolean allowDirect; + private final boolean allowConversion; + private final boolean allowMappingMethod; + private final boolean allow2Steps; - public SelectionCriteria(SelectionParameters selectionParameters, String targetPropertyName, - boolean preferUpdateMapping, boolean objectFactoryRequired, + public SelectionCriteria(SelectionParameters selectionParameters, MappingControl mappingControl, + String targetPropertyName, boolean preferUpdateMapping, boolean objectFactoryRequired, boolean lifecycleCallbackRequired) { if ( selectionParameters != null ) { qualifiers.addAll( selectionParameters.getQualifiers() ); @@ -42,6 +47,18 @@ public SelectionCriteria(SelectionParameters selectionParameters, String targetP this.qualifyingResultType = null; sourceRHS = null; } + if ( mappingControl != null ) { + this.allowDirect = mappingControl.allowDirect(); + this.allowConversion = mappingControl.allowTypeConversion(); + this.allowMappingMethod = mappingControl.allowMappingMethod(); + this.allow2Steps = mappingControl.allowBy2Steps(); + } + else { + this.allowDirect = true; + this.allowConversion = true; + this.allowMappingMethod = true; + this.allow2Steps = true; + } this.targetPropertyName = targetPropertyName; this.preferUpdateMapping = preferUpdateMapping; this.objectFactoryRequired = objectFactoryRequired; @@ -94,17 +111,41 @@ public boolean hasQualfiers() { return !qualifiedByNames.isEmpty() || !qualifiers.isEmpty(); } + public boolean isAllowDirect() { + return allowDirect; + } + + public boolean isAllowConversion() { + return allowConversion; + } + + public boolean isAllowMappingMethod() { + return allowMappingMethod; + } + + public boolean isAllow2Steps() { + return allow2Steps; + } + public static SelectionCriteria forMappingMethods(SelectionParameters selectionParameters, + MappingControl mappingControl, String targetPropertyName, boolean preferUpdateMapping) { - return new SelectionCriteria( selectionParameters, targetPropertyName, preferUpdateMapping, false, false ); + return new SelectionCriteria( + selectionParameters, + mappingControl, + targetPropertyName, + preferUpdateMapping, + false, + false + ); } public static SelectionCriteria forFactoryMethods(SelectionParameters selectionParameters) { - return new SelectionCriteria( selectionParameters, null, false, true, false ); + return new SelectionCriteria( selectionParameters, null, null, false, true, false ); } public static SelectionCriteria forLifecycleMethods(SelectionParameters selectionParameters) { - return new SelectionCriteria( selectionParameters, null, false, false, true ); + return new SelectionCriteria( selectionParameters, null, null, false, false, true ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 25de97d2b9..39d661f528 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -177,16 +177,20 @@ private List filterPossibleCandidateMethods(List candid private Assignment getTargetAssignment(Type sourceType, Type targetType) { + Assignment referencedMethod; + // first simple mapping method - Assignment referencedMethod = resolveViaMethod( sourceType, targetType, false ); - if ( referencedMethod != null ) { - referencedMethod.setAssignment( sourceRHS ); - return referencedMethod; + if ( allowMappingMethod() ) { + referencedMethod = resolveViaMethod( sourceType, targetType, false ); + if ( referencedMethod != null ) { + referencedMethod.setAssignment( sourceRHS ); + return referencedMethod; + } } // then direct assignable if ( !hasQualfiers() ) { - if ( sourceType.isAssignableTo( targetType ) || + if ( ( sourceType.isAssignableTo( targetType ) && allowDirect( sourceType, targetType ) ) || isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) { Assignment simpleAssignment = sourceRHS; return simpleAssignment; @@ -206,47 +210,51 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { } // then type conversion - if ( !hasQualfiers() ) { - ConversionAssignment conversion = resolveViaConversion( sourceType, targetType ); - if ( conversion != null ) { - conversion.reportMessageWhenNarrowing( messager, this ); - conversion.getAssignment().setAssignment( sourceRHS ); - return conversion.getAssignment(); + if ( allowConversion() ) { + if ( !hasQualfiers() ) { + ConversionAssignment conversion = resolveViaConversion( sourceType, targetType ); + if ( conversion != null ) { + conversion.reportMessageWhenNarrowing( messager, this ); + conversion.getAssignment().setAssignment( sourceRHS ); + return conversion.getAssignment(); + } } - } - // check for a built-in method - if (!hasQualfiers() ) { - Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); - if ( builtInMethod != null ) { - builtInMethod.setAssignment( sourceRHS ); - usedSupportedMappings.addAll( supportingMethodCandidates ); - return builtInMethod; + // check for a built-in method + if ( !hasQualfiers() ) { + Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); + if ( builtInMethod != null ) { + builtInMethod.setAssignment( sourceRHS ); + usedSupportedMappings.addAll( supportingMethodCandidates ); + return builtInMethod; + } } } - // 2 step method, first: method(method(source)) - referencedMethod = resolveViaMethodAndMethod( sourceType, targetType ); - if ( referencedMethod != null ) { - usedSupportedMappings.addAll( supportingMethodCandidates ); - return referencedMethod; - } + if ( allow2Steps() ) { + // 2 step method, first: method(method(source)) + referencedMethod = resolveViaMethodAndMethod( sourceType, targetType ); + if ( referencedMethod != null ) { + usedSupportedMappings.addAll( supportingMethodCandidates ); + return referencedMethod; + } - // 2 step method, then: method(conversion(source)) - referencedMethod = resolveViaConversionAndMethod( sourceType, targetType ); - if ( referencedMethod != null ) { - usedSupportedMappings.addAll( supportingMethodCandidates ); - return referencedMethod; - } + // 2 step method, then: method(conversion(source)) + referencedMethod = resolveViaConversionAndMethod( sourceType, targetType ); + if ( referencedMethod != null ) { + usedSupportedMappings.addAll( supportingMethodCandidates ); + return referencedMethod; + } - // stop here when looking for update methods. - selectionCriteria.setPreferUpdateMapping( false ); + // stop here when looking for update methods. + selectionCriteria.setPreferUpdateMapping( false ); - // 2 step method, finally: conversion(method(source)) - ConversionAssignment conversion = resolveViaMethodAndConversion( sourceType, targetType ); - if ( conversion != null ) { - usedSupportedMappings.addAll( supportingMethodCandidates ); - return conversion.getAssignment(); + // 2 step method, finally: conversion(method(source)) + ConversionAssignment conversion = resolveViaMethodAndConversion( sourceType, targetType ); + if ( conversion != null ) { + usedSupportedMappings.addAll( supportingMethodCandidates ); + return conversion.getAssignment(); + } } if ( hasQualfiers() ) { @@ -258,7 +266,8 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { Strings.join( selectionCriteria.getQualifiedByNames(), ", " ) ); } - else { + else if ( allowMappingMethod() ) { + // only forge if we would allow mapping method return forger.get(); } @@ -270,6 +279,26 @@ private boolean hasQualfiers() { return selectionCriteria != null && selectionCriteria.hasQualfiers(); } + private boolean allowDirect( Type sourceType, Type targetType ) { + if ( sourceType.isPrimitive() || targetType.isPrimitive() + || sourceType.isJavaLangType() || targetType.isJavaLangType() ) { + return true; + } + return selectionCriteria != null && selectionCriteria.isAllowDirect(); + } + + private boolean allowConversion() { + return selectionCriteria != null && selectionCriteria.isAllowConversion(); + } + + private boolean allowMappingMethod() { + return selectionCriteria != null && selectionCriteria.isAllowMappingMethod(); + } + + private boolean allow2Steps() { + return selectionCriteria != null && selectionCriteria.isAllow2Steps(); + } + private ConversionAssignment resolveViaConversion(Type sourceType, Type targetType) { ConversionProvider conversionProvider = conversions.getConversion( sourceType, targetType ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningMapper.java new file mode 100644 index 0000000000..c1ff968d2c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = DeepClone.class) +public interface CloningMapper { + + CloningMapper INSTANCE = Mappers.getMapper( CloningMapper.class ); + + FridgeDTO clone(FridgeDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ComplexMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ComplexMapper.java new file mode 100644 index 0000000000..768e6117a5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ComplexMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ComplexMapper { + + ComplexMapper INSTANCE = Mappers.getMapper( ComplexMapper.class ); + + @Mapping(target = "beerCount", source = "shelve") + Fridge map(FridgeDTO in); + + default String toBeerCount(ShelveDTO in) { + return in.getCoolBeer().getBeerCount(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Config.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Config.java new file mode 100644 index 0000000000..b37c8e4f25 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Config.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.MapperConfig; +import org.mapstruct.control.NoComplexMapping; + +/** + * @author Sjaak Derksen + */ +@MapperConfig( mappingControl = NoComplexMapping.class ) +public interface Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ConversionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ConversionMapper.java new file mode 100644 index 0000000000..d4e1c3249d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ConversionMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ConversionMapper { + + ConversionMapper INSTANCE = Mappers.getMapper( ConversionMapper.class ); + + Fridge map(CoolBeerDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CoolBeerDTO.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CoolBeerDTO.java new file mode 100644 index 0000000000..1505d3f291 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CoolBeerDTO.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +public class CoolBeerDTO { + + private String beerCount; + + public String getBeerCount() { + return beerCount; + } + + public void setBeerCount(String beerCount) { + this.beerCount = beerCount; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/DirectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/DirectMapper.java new file mode 100644 index 0000000000..1529c15eb1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/DirectMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DirectMapper { + + DirectMapper INSTANCE = Mappers.getMapper( DirectMapper.class ); + + @Mapping(target = "shelve", source = "shelve") + FridgeDTO map(FridgeDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapper.java new file mode 100644 index 0000000000..71eaf227ae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = UseDirect.class) +public interface ErroneousComplexMapper { + + ErroneousComplexMapper INSTANCE = Mappers.getMapper( ErroneousComplexMapper.class ); + + @Mapping(target = "beerCount", source = "shelve") + Fridge map(FridgeDTO in); + + default String toBeerCount(ShelveDTO in) { + return in.getCoolBeer().getBeerCount(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapperWithConfig.java new file mode 100644 index 0000000000..ecb9c58837 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousComplexMapperWithConfig.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper(config = Config.class) +public interface ErroneousComplexMapperWithConfig { + + ErroneousComplexMapperWithConfig INSTANCE = Mappers.getMapper( ErroneousComplexMapperWithConfig.class ); + + @Mapping(target = "beerCount", source = "shelve") + Fridge map(FridgeDTO in); + + default String toBeerCount(ShelveDTO in) { + return in.getCoolBeer().getBeerCount(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionMapper.java new file mode 100644 index 0000000000..a7f09e40e2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = UseDirect.class) +public interface ErroneousConversionMapper { + + ErroneousConversionMapper INSTANCE = Mappers.getMapper( ErroneousConversionMapper.class ); + + Fridge map(CoolBeerDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousDirectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousDirectMapper.java new file mode 100644 index 0000000000..672c9bd7c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousDirectMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = UseComplex.class) +public interface ErroneousDirectMapper { + + ErroneousDirectMapper INSTANCE = Mappers.getMapper( ErroneousDirectMapper.class ); + + @Mapping(target = "shelve", source = "shelve") + FridgeDTO map(FridgeDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodMapper.java new file mode 100644 index 0000000000..276c37a6e7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = UseDirect.class) +public interface ErroneousMethodMapper { + + ErroneousMethodMapper INSTANCE = Mappers.getMapper( ErroneousMethodMapper.class ); + + @Mapping(target = "beerCount", source = "shelve") + Fridge map(FridgeDTO in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Fridge.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Fridge.java new file mode 100644 index 0000000000..52d0f0e376 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/Fridge.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +public class Fridge { + + private int beerCount; + + public int getBeerCount() { + return beerCount; + } + + public void setBeerCount(int beerCount) { + this.beerCount = beerCount; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/FridgeDTO.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/FridgeDTO.java new file mode 100644 index 0000000000..0951278619 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/FridgeDTO.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +public class FridgeDTO { + + private ShelveDTO shelve; + + public ShelveDTO getShelve() { + return shelve; + } + + public void setShelve(ShelveDTO shelve) { + this.shelve = shelve; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java new file mode 100644 index 0000000000..90f0957e68 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -0,0 +1,182 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@IssueKey("695") +@WithClasses({ + CoolBeerDTO.class, + ShelveDTO.class, + Fridge.class, + FridgeDTO.class, + UseDirect.class, + UseComplex.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class MappingControlTest { + + /** + * Baseline Test, normal, direct allowed + */ + @Test + @WithClasses(DirectMapper.class) + public void directSelectionAllowed() { + + FridgeDTO in = createFridgeDTO(); + FridgeDTO out = DirectMapper.INSTANCE.map( in ); + + assertThat( out ).isNotNull(); + assertThat( out.getShelve() ).isNotNull(); + assertThat( out.getShelve() ).isSameAs( in.getShelve() ); + } + + /** + * Test the deep cloning annotation + */ + @Test + @WithClasses(CloningMapper.class) + public void testDeepCloning() { + + FridgeDTO in = createFridgeDTO(); + FridgeDTO out = CloningMapper.INSTANCE.clone( in ); + + assertThat( out ).isNotNull(); + assertThat( out.getShelve() ).isNotNull(); + assertThat( out.getShelve() ).isNotSameAs( in.getShelve() ); + assertThat( out.getShelve().getCoolBeer() ).isNotSameAs( in.getShelve().getCoolBeer() ); + assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" ); + } + + /** + * This is a nice test. MapStruct looks for a way to map ShelveDto to ShelveDto. + *

      + * MapStruct gets too creative when we allow complex (2 step mappings) to convert if we also allow + * it to forge methods (which is contradiction with the fact that we do not allow methods on this mapper) + */ + @Test + @WithClasses(ErroneousDirectMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousDirectMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \".*\\.ShelveDTO shelve\".*" + ) + }) + public void directSelectionNotAllowed() { + } + + /** + * Baseline Test, normal, method allowed + */ + @Test + @WithClasses(MethodMapper.class) + public void methodSelectionAllowed() { + Fridge fridge = MethodMapper.INSTANCE.map( createFridgeDTO() ); + + assertThat( fridge ).isNotNull(); + assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); + } + + @Test + @WithClasses(ErroneousMethodMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMethodMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + ) + }) + public void methodSelectionNotAllowed() { + } + + /** + * Baseline Test, normal, conversion allowed + */ + @Test + @WithClasses(ConversionMapper.class) + public void conversionSelectionAllowed() { + Fridge fridge = ConversionMapper.INSTANCE.map( createFridgeDTO().getShelve().getCoolBeer() ); + + assertThat( fridge ).isNotNull(); + assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); + } + + @Test + @WithClasses(ErroneousConversionMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousConversionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + messageRegExp = "Can't map property \".*\\.String beerCount\" to \"int beerCount\".*" + ) + }) + public void conversionSelectionNotAllowed() { + } + + /** + * Baseline Test, normal, complex mapping allowed + */ + @Test + @WithClasses(ComplexMapper.class) + public void complexSelectionAllowed() { + Fridge fridge = ComplexMapper.INSTANCE.map( createFridgeDTO() ); + + assertThat( fridge ).isNotNull(); + assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); + } + + @Test + @WithClasses(ErroneousComplexMapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousComplexMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + ) + }) + public void complexSelectionNotAllowed() { + } + + @Test + @WithClasses({ Config.class, ErroneousComplexMapperWithConfig.class }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousComplexMapperWithConfig.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + ) + }) + public void complexSelectionNotAllowedWithConfig() { + } + + private FridgeDTO createFridgeDTO() { + FridgeDTO fridgeDTO = new FridgeDTO(); + ShelveDTO shelveDTO = new ShelveDTO(); + CoolBeerDTO coolBeerDTO = new CoolBeerDTO(); + fridgeDTO.setShelve( shelveDTO ); + shelveDTO.setCoolBeer( coolBeerDTO ); + coolBeerDTO.setBeerCount( "5" ); + return fridgeDTO; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MethodMapper.java new file mode 100644 index 0000000000..54e4515c52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MethodMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface MethodMapper { + + MethodMapper INSTANCE = Mappers.getMapper( MethodMapper.class ); + + @Mapping(target = "beerCount", source = "shelve") + Fridge map(FridgeDTO in); + + default int map(ShelveDTO in) { + return Integer.valueOf( in.getCoolBeer().getBeerCount() ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ShelveDTO.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ShelveDTO.java new file mode 100644 index 0000000000..0ddfeb7a2a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ShelveDTO.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +public class ShelveDTO { + + private CoolBeerDTO coolBeer; + + public CoolBeerDTO getCoolBeer() { + return coolBeer; + } + + public void setCoolBeer(CoolBeerDTO coolBeer) { + this.coolBeer = coolBeer; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseComplex.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseComplex.java new file mode 100644 index 0000000000..2424d95300 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseComplex.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.control.MappingControl; +import org.mapstruct.util.Experimental; + +@Retention(RetentionPolicy.CLASS) +@Experimental +@MappingControl( MappingControl.Use.COMPLEX_MAPPING ) +public @interface UseComplex { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseDirect.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseDirect.java new file mode 100644 index 0000000000..00151d71ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/UseDirect.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.control.MappingControl; +import org.mapstruct.util.Experimental; + +@Retention(RetentionPolicy.CLASS) +@Experimental +@MappingControl( MappingControl.Use.DIRECT ) +public @interface UseDirect { +} From 95ceba1a1e123bd23c11fc9f103899205ff3f45d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Feb 2020 00:48:45 +0100 Subject: [PATCH 0433/1006] #2016 Update Checkstyle to 8.29 Adapt checkstyle configuration with new changes: * Move cacheFile to Checker module * Move LineLength to Checker module * Use SuppressWithPlainTextCommentFilter --- .gitignore | 1 + .../src/main/resources/build-config/checkstyle.xml | 14 +++++++++----- parent/pom.xml | 4 ++-- .../ap/internal/conversion/SimpleConversion.java | 1 - .../mapstruct/ap/internal/model/HelperMethod.java | 2 -- .../ap/internal/model/LifecycleMethodResolver.java | 1 - .../model/ObjectFactoryMethodResolver.java | 2 -- .../ap/internal/model/common/TypeFactory.java | 2 -- .../AnnotationBasedComponentModelProcessor.java | 1 - .../ap/spi/DefaultAccessorNamingStrategy.java | 1 - .../referenced/a/ReferencedMapperDefaultOther.java | 1 - .../mapstruct/ap/test/bugs/_1170/PetMapper.java | 1 - .../org/mapstruct/ap/test/bugs/_375/Source.java | 1 - .../mapstruct/ap/test/bugs/_513/TargetElement.java | 1 - .../org/mapstruct/ap/test/bugs/_513/TargetKey.java | 1 - .../mapstruct/ap/test/bugs/_513/TargetValue.java | 1 - .../Issue913GetterMapperForCollectionsTest.java | 2 -- .../ap/test/collection/adder/PetMapper.java | 1 - .../adder/source/SingleElementSource.java | 1 - .../Source.java | 1 - .../AmbiguousBarFactory.java | 1 - .../ambiguousannotatedfactorymethod/Foo.java | 1 - .../ambiguousannotatedfactorymethod/Source.java | 1 - .../ambiguousannotatedfactorymethod/Target.java | 1 - .../test/erroneous/ambiguousfactorymethod/Foo.java | 1 - .../erroneous/ambiguousfactorymethod/Source.java | 1 - .../erroneous/ambiguousfactorymethod/Target.java | 1 - .../ambiguousfactorymethod/a/BarFactory.java | 1 - .../org/mapstruct/ap/test/generics/AbstractTo.java | 1 - .../org/mapstruct/ap/test/generics/TargetTo.java | 1 - .../_target/AdderUsageObserver.java | 1 - .../_target/ChartEntryLabel.java | 1 - .../test/nestedsourceproperties/source/Song.java | 1 - .../mapstruct/ap/test/nullcheck/MyLongWrapper.java | 1 - .../org/mapstruct/ap/test/references/Target.java | 1 - .../test/selection/primitives/PrimitiveMapper.java | 1 - .../ap/test/source/constants/Source1.java | 1 - .../ap/test/source/constants/Source2.java | 1 - .../ap/test/source/constants/Target2.java | 1 - .../org/mapstruct/ap/test/template/Source.java | 1 - .../org/mapstruct/ap/test/template/Target.java | 1 - .../ap/testutil/runner/GeneratedSource.java | 1 - .../resources/checkstyle-for-generated-sources.xml | 4 ++-- 43 files changed, 14 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 4fc554ede8..0363e0707e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ test-output # Misc. .DS_Store +checkstyle.cache diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 9051361d18..213a0d21f5 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -15,6 +15,8 @@ --> + + @@ -60,8 +69,6 @@ - - @@ -115,9 +122,6 @@ - - - diff --git a/parent/pom.xml b/parent/pom.xml index 1960db3089..523a715112 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -28,7 +28,7 @@ 3.1.0 4.0.3.RELEASE 0.26.0 - 8.18 + 8.29 1 3.11.1 @@ -278,7 +278,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.0.0 + 3.1.0 build-config/checkstyle.xml true diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java index c143085bbc..f0e0ccd880 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/SimpleConversion.java @@ -45,7 +45,6 @@ public List getRequiredHelperMethods(ConversionContext conversionC return Collections.emptyList(); } - /** * Returns the conversion string from source to target. The placeholder {@code } can be used to represent a * reference to the source value. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 697d01a736..fcf8068ed6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -177,8 +177,6 @@ public boolean doTypeVarsMatch(Type parameter, Type returnType) { return true; } - - /** * There's currently only one parameter foreseen instead of a list of parameter * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 40dbb74901..61610badf8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -73,7 +73,6 @@ public static List afterMappingMethods(Method existingVariableNames ); } - /** * @param method the method to obtain the beforeMapping methods for * @param selectionParameters method selectionParameters diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index b64dd88884..f4b39ab1a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -50,8 +50,6 @@ public static MethodReference getFactoryMethod( Method method, return getFactoryMethod( method, method.getResultType(), selectionParameters, ctx ); } - - /** * returns a no arg factory method * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 8fc7fcdc5c..822ba0dd6d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -145,7 +145,6 @@ private Type getType(String canonicalName, boolean isLiteral) { return getType( typeElement, isLiteral ); } - /** * Determines if the type with the given full qualified name is part of the classpath * @@ -597,7 +596,6 @@ else if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { return typeMirror; } - /** * Whether the given type is ready to be processed or not. It can be processed if it is not of kind * {@link TypeKind#ERROR} and all {@link AstModifyingAnnotationProcessor}s (if any) indicated that they've fully diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 4efb8011c3..d68936f545 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -176,7 +176,6 @@ private AnnotatedConstructor buildAnnotatedConstructorForDecorator(Decorator dec ); } - /** * Removes duplicate constructor parameter annotations. If an annotation is already present on the constructor, it * does not have be defined on the constructor parameter, too. For example, for CDI, the javax.inject.Inject diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index c3c14deb00..82ecb4e17b 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -86,7 +86,6 @@ public boolean isGetterMethod(ExecutableElement method) { return isNonBooleanGetterName || ( isBooleanGetterName && returnTypeIsBoolean ); } - /** * Returns {@code true} when the {@link ExecutableElement} is a setter method. A setter starts with 'set'. The * remainder of the name is supposed to reflect the property name. diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java index 81dcc306f1..7d3ab7014f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/a/ReferencedMapperDefaultOther.java @@ -8,7 +8,6 @@ import org.mapstruct.ap.test.accessibility.referenced.ReferencedSource; import org.mapstruct.ap.test.accessibility.referenced.ReferencedTarget; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java index 7dd9ff50a8..96b7e8b72f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/PetMapper.java @@ -29,7 +29,6 @@ public class PetMapper { .put( 3L, "cat" ) .put( 4L, "dog" ).build(); - /** * method to be used when using an adder * diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java index 6f9b154033..2418fb7fdf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Source.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.bugs._375; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java index dc794a62f3..532c44052b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetElement.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.bugs._513; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java index e697afc20a..aef8b8ece1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetKey.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.bugs._513; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java index d999de75a1..beda1c1389 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/TargetValue.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.bugs._513; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java index c9c3182edc..e63d91b5e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java @@ -198,8 +198,6 @@ public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { assertThat( domain2.getLongs() ).isEmpty(); } - - /** * These assert check if non-null and default mapping is working as expected. * diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java index c2cf92ed6c..ef80c4b6c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/PetMapper.java @@ -31,7 +31,6 @@ public class PetMapper { .put( 3L, "cat" ) .put( 4L, "dog" ).build(); - /** * method to be used when using an adder * diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java index 91e277a209..01ab35a91d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/source/SingleElementSource.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.collection.adder.source; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java index 23fc7a5ed4..081fc1edb9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetoxmlgregoriancalendarconversion/Source.java @@ -7,7 +7,6 @@ import javax.xml.datatype.XMLGregorianCalendar; - /** * @author Andreas Gudian */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java index cb1c30a2d6..2c6c070402 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousBarFactory.java @@ -7,7 +7,6 @@ import org.mapstruct.ObjectFactory; - /** * @author Remo Meier */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java index 796dd0fae7..679efa8358 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Foo.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; - /** * @author Remo Meier */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java index 8fdd2ad52e..0a4e64dc54 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Source.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; - /** * @author Remo Meier */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java index 71b5880add..f15dc0e8d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/Target.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; - /** * @author Remo Meier */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java index 2373a6549f..7d13089921 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Foo.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java index ea0c9a247e..2aabe7e06d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Source.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java index 2342d880eb..025ae810f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/Target.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java index 35cb5c4462..b0e2a46e48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/a/BarFactory.java @@ -7,7 +7,6 @@ import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java index 5d7f0ba82f..c0f4c423ef 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/AbstractTo.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.generics; - /** * @author Andreas Gudian */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java b/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java index 799dc2509e..cac761f14b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/TargetTo.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.generics; - /** * @author Andreas Gudian * diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java index 96de5cd1d0..e7cae29460 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/AdderUsageObserver.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.nestedsourceproperties._target; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java index bd13f1fcb1..77d2e68655 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/_target/ChartEntryLabel.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.nestedsourceproperties._target; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java index f3c2856260..f1ebe50745 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/source/Song.java @@ -7,7 +7,6 @@ import java.util.List; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java index d070c64941..2836f7b3dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/MyLongWrapper.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.nullcheck; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/Target.java b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java index 53feca7fc2..78fd2df3a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/Target.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.references; - /** * @author Andreas Gudian * diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java index 4ab200f9f9..aaee7eafee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveMapper.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.selection.primitives; - /** * @author Sjaak Derksen * diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java index e9797fdecf..00f9d9fc45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source1.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.source.constants; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java index eb5cc07a2e..aaad0dd735 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Source2.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.source.constants; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java index e64b3f7e7e..56a1570cbf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target2.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.source.constants; - /** * * @author Sjaak Derksen diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/Source.java b/processor/src/test/java/org/mapstruct/ap/test/template/Source.java index a5013e5acb..b330d98c21 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/Source.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.template; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/Target.java b/processor/src/test/java/org/mapstruct/ap/test/template/Target.java index 3d8c63faf4..5ef24faafd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/Target.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.test.template; - /** * @author Sjaak Derksen */ diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index 35e3ddb0e7..f5a98bfee7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -57,7 +57,6 @@ static void clearCompilingStatement() { GeneratedSource.compilingStatement.remove(); } - /** * Adds more mappers that need to be compared. * diff --git a/processor/src/test/resources/checkstyle-for-generated-sources.xml b/processor/src/test/resources/checkstyle-for-generated-sources.xml index eecb42111a..295fbeeffa 100644 --- a/processor/src/test/resources/checkstyle-for-generated-sources.xml +++ b/processor/src/test/resources/checkstyle-for-generated-sources.xml @@ -7,6 +7,8 @@ + + - - junit - junit - test - org.assertj assertj-core @@ -73,6 +68,17 @@ 2.6 test + + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-engine + test + + diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java deleted file mode 100644 index 823a530c09..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/AutoValueBuilderTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Filip Hrisafov - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite(baseDir = "autoValueBuilderTest", - processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) -public class AutoValueBuilderTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java deleted file mode 100644 index 216d2afdfa..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/CdiTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "cdiTest", processorTypes = ProcessorType.ALL ) -public class CdiTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java deleted file mode 100644 index bcfb0c399c..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ExternalBeanJarTest.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * - * See: https://github.com/mapstruct/mapstruct/issues/1121 - * - * @author Sjaak Derksen - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite(baseDir = "externalbeanjar", processorTypes = ProcessorSuite.ProcessorType.ORACLE_JAVA_8) -public class ExternalBeanJarTest { - -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java deleted file mode 100644 index 250f4ce856..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FreeBuilderBuilderTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Filip Hrisafov - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "freeBuilderBuilderTest", - processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) -public class FreeBuilderBuilderTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java new file mode 100644 index 0000000000..c8bac6208c --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.tests; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.junit.jupiter.api.condition.JRE; +import org.mapstruct.itest.testutil.extension.ProcessorTest; + +/** + * Adds explicit exclusions of test mappers that are known or expected to not work with specific compilers. + * + * @author Andreas Gudian + */ +public final class FullFeatureCompilationExclusionCliEnhancer implements ProcessorTest.CommandLineEnhancer { + @Override + public Collection getAdditionalCommandLineArguments(ProcessorTest.ProcessorType processorType, + JRE currentJreVersion) { + List additionalExcludes = new ArrayList<>(); + + // SPI not working correctly here.. (not picked up) + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1801/*.java" ); + + switch ( currentJreVersion ) { + case JAVA_9: + // TODO find out why this fails: + additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); + break; + default: + } + + Collection result = new ArrayList( additionalExcludes.size() ); + for ( int i = 0; i < additionalExcludes.size(); i++ ) { + result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) ); + } + + return result; + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java deleted file mode 100644 index 45802ff38b..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.tests.FullFeatureCompilationTest.CompilationExclusionCliEnhancer; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.CommandLineEnhancer; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * Integration test that compiles all test mappers in the processor-module, excluding all classes that contain one of - * the following in their path/file name: - *

        - *
      • {@code /erronerous/}
      • - *
      • {@code *Erroneous*}
      • - *
      • {@code *Test.java}
      • - *
      • {@code /testutil/}
      • - *
      • possibly more, depending on the processor type - see {@link CompilationExclusionCliEnhancer}
      • - *
      - * - * @author Andreas Gudian - */ -@RunWith(ProcessorSuiteRunner.class) -@ProcessorSuite( - baseDir = "fullFeatureTest", - commandLineEnhancer = CompilationExclusionCliEnhancer.class, - processorTypes = { - ProcessorType.ORACLE_JAVA_8, - ProcessorType.ORACLE_JAVA_9, - ProcessorType.ECLIPSE_JDT_JAVA_8 -}) -public class FullFeatureCompilationTest { - /** - * Adds explicit exclusions of test mappers that are known or expected to not work with specific compilers. - * - * @author Andreas Gudian - */ - public static final class CompilationExclusionCliEnhancer implements CommandLineEnhancer { - @Override - public Collection getAdditionalCommandLineArguments(ProcessorType processorType) { - List additionalExcludes = new ArrayList<>(); - - // SPI not working correctly here.. (not picked up) - additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" ); - additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1801/*.java" ); - - switch ( processorType ) { - case ORACLE_JAVA_9: - // TODO find out why this fails: - additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); - break; - default: - } - - Collection result = new ArrayList( additionalExcludes.size() ); - for ( int i = 0; i < additionalExcludes.size(); i++ ) { - result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) ); - } - - return result; - } - } -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java index bb0c0f4ce6..0162582468 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java @@ -5,12 +5,6 @@ */ package org.mapstruct.itest.tests; -import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; -import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - import java.io.File; import java.io.IOException; import java.nio.charset.Charset; @@ -24,40 +18,40 @@ import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.condition.DisabledForJreRange; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runners.Parameterized.Parameters; +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; +import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE; +import static org.hamcrest.core.StringContains.containsString; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + /** *

      This is supposed to be run from the mapstruct root project folder. * Otherwise, use -Dmapstruct_root=path_to_project. */ -@RunWith( Parameterized.class ) +@DisabledForJreRange(min = JRE.JAVA_11) public class GradleIncrementalCompilationTest { private static Path rootPath; private static String projectDir = "integrationtest/src/test/resources/gradleIncrementalCompilationTest"; private static String compileTaskName = "compileJava"; - @Rule - public final TemporaryFolder testBuildDir = new TemporaryFolder(); - @Rule - public final TemporaryFolder testProjectDir = new TemporaryFolder(); + @TempDir + File testBuildDir; + @TempDir + File testProjectDir; - private String gradleVersion; private GradleRunner runner; private File sourceDirectory; private List compileArgs; // Gradle compile task arguments - public GradleIncrementalCompilationTest(String gradleVersion) { - this.gradleVersion = gradleVersion; - } - - @Parameters( name = "Gradle {0}" ) + @Parameters(name = "Gradle {0}") public static List gradleVersions() { return Arrays.asList( "5.0", "6.0" ); } @@ -81,49 +75,62 @@ private void assertRecompiled(BuildResult result, int recompiledCount) { assertCompileOutcome( result, recompiledCount > 0 ? SUCCESS : UP_TO_DATE ); assertThat( result.getOutput(), - containsString( String.format( "Incremental compilation of %d classes completed", recompiledCount ) ) ); + containsString( String.format( "Incremental compilation of %d classes completed", recompiledCount ) ) + ); } private List buildCompileArgs() { // Make Gradle use the temporary build folder by overriding the buildDir property - String buildDirPropertyArg = "-PbuildDir=" + testBuildDir.getRoot().getAbsolutePath(); + String buildDirPropertyArg = "-PbuildDir=" + testBuildDir.getAbsolutePath(); // Inject the path to the folder containing the mapstruct-processor JAR String jarDirectoryArg = "-PmapstructRootPath=" + rootPath.toString(); return Arrays.asList( compileTaskName, buildDirPropertyArg, jarDirectoryArg ); } - @BeforeClass + @BeforeAll public static void setupClass() throws Exception { rootPath = Paths.get( System.getProperty( "mapstruct_root", "." ) ).toAbsolutePath(); } - @Before - public void setup() throws IOException { + public void setup(String gradleVersion) throws IOException { + if ( !testBuildDir.exists() ) { + testBuildDir.mkdirs(); + } + + if ( !testProjectDir.exists() ) { + testProjectDir.mkdirs(); + } // Copy test project files to the temp dir Path gradleProjectPath = rootPath.resolve( projectDir ); - FileUtils.copyDirectory( gradleProjectPath.toFile(), testProjectDir.getRoot() ); + FileUtils.copyDirectory( gradleProjectPath.toFile(), testProjectDir ); compileArgs = buildCompileArgs(); - sourceDirectory = new File( testProjectDir.getRoot(), "src/main/java" ); - runner = GradleRunner.create().withGradleVersion( gradleVersion ).withProjectDir( testProjectDir.getRoot() ); + sourceDirectory = new File( testProjectDir, "src/main/java" ); + runner = GradleRunner.create().withGradleVersion( gradleVersion ).withProjectDir( testProjectDir ); } - @Test - public void testBuildSucceeds() throws IOException { + @ParameterizedTest + @MethodSource("gradleVersions") + public void testBuildSucceeds(String gradleVersion) throws IOException { + setup( gradleVersion ); // Make sure the test build setup actually compiles BuildResult buildResult = getRunner().build(); assertCompileOutcome( buildResult, SUCCESS ); } - @Test - public void testUpToDate() throws IOException { + @ParameterizedTest + @MethodSource("gradleVersions") + public void testUpToDate(String gradleVersion) throws IOException { + setup( gradleVersion ); getRunner().build(); BuildResult secondBuildResult = getRunner().build(); assertCompileOutcome( secondBuildResult, UP_TO_DATE ); } - @Test - public void testChangeConstant() throws IOException { + @ParameterizedTest + @MethodSource("gradleVersions") + public void testChangeConstant(String gradleVersion) throws IOException { + setup( gradleVersion ); getRunner().build(); // Change return value in class Target File targetFile = new File( sourceDirectory, "org/mapstruct/itest/gradle/model/Target.java" ); @@ -134,8 +141,10 @@ public void testChangeConstant() throws IOException { assertRecompiled( secondBuildResult, 3 ); } - @Test - public void testChangeTargetField() throws IOException { + @ParameterizedTest + @MethodSource("gradleVersions") + public void testChangeTargetField(String gradleVersion) throws IOException { + setup( gradleVersion ); getRunner().build(); // Change target field in mapper interface File mapperFile = new File( sourceDirectory, "org/mapstruct/itest/gradle/lib/TestMapper.java" ); @@ -146,8 +155,10 @@ public void testChangeTargetField() throws IOException { assertRecompiled( secondBuildResult, 2 ); } - @Test - public void testChangeUnrelatedFile() throws IOException { + @ParameterizedTest + @MethodSource("gradleVersions") + public void testChangeUnrelatedFile(String gradleVersion) throws IOException { + setup( gradleVersion ); getRunner().build(); File unrelatedFile = new File( sourceDirectory, "org/mapstruct/itest/gradle/lib/UnrelatedComponent.java" ); replaceInFile( unrelatedFile, "true", "false" ); diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java deleted file mode 100644 index b6f6970d38..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ImmutablesBuilderTest.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Filip Hrisafov - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "immutablesBuilderTest", - processorTypes = ProcessorSuite.ProcessorType.ALL_WITHOUT_PROCESSOR_PLUGIN) -public class ImmutablesBuilderTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java deleted file mode 100644 index ce0b191f65..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/Java8Test.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "java8Test", processorTypes = ProcessorType.ALL_JAVA_8 ) -public class Java8Test { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java deleted file mode 100644 index 840f5d9337..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/JaxbTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "jaxbTest", processorTypes = ProcessorType.ALL ) -public class JaxbTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java deleted file mode 100644 index 65cd76f0d3..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/Jsr330Test.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "jsr330Test", processorTypes = ProcessorType.ALL ) -public class Jsr330Test { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java deleted file mode 100644 index 7199cb1f34..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/LombokBuilderTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Eric Martineau - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "lombokBuilderTest", - processorTypes = { - ProcessorSuite.ProcessorType.ORACLE_JAVA_8, - ProcessorSuite.ProcessorType.ORACLE_JAVA_9, - } -) -public class LombokBuilderTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java new file mode 100644 index 0000000000..16298179a0 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -0,0 +1,124 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.tests; + +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.mapstruct.itest.testutil.extension.ProcessorTest; + +/** + * @author Filip Hrisafov + */ +@Execution( ExecutionMode.CONCURRENT ) +public class MavenIntegrationTest { + + @ProcessorTest(baseDir = "autoValueBuilderTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC, + ProcessorTest.ProcessorType.ECLIPSE_JDT + }) + void autoValueBuilderTest() { + } + + @ProcessorTest(baseDir = "cdiTest") + void cdiTest() { + } + + /** + * See: https://github.com/mapstruct/mapstruct/issues/1121 + */ + @ProcessorTest(baseDir = "externalbeanjar", processorTypes = ProcessorTest.ProcessorType.JAVAC) + void externalBeanJarTest() { + } + + @ProcessorTest(baseDir = "freeBuilderBuilderTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC, + ProcessorTest.ProcessorType.ECLIPSE_JDT + }) + void freeBuilderBuilderTest() { + } + + /** + * Integration test that compiles all test mappers in the processor-module, excluding all classes that contain + * one of + * the following in their path/file name: + *

        + *
      • {@code /erronerous/}
      • + *
      • {@code *Erroneous*}
      • + *
      • {@code *Test.java}
      • + *
      • {@code /testutil/}
      • + *
      • possibly more, depending on the processor type - see {@link FullFeatureCompilationExclusionCliEnhancer}
      • + *
      + */ + @ProcessorTest(baseDir = "fullFeatureTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC, + ProcessorTest.ProcessorType.ECLIPSE_JDT + }, commandLineEnhancer = FullFeatureCompilationExclusionCliEnhancer.class) + void fullFeatureTest() { + } + + @ProcessorTest(baseDir = "immutablesBuilderTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC, + ProcessorTest.ProcessorType.ECLIPSE_JDT + }) + void immutablesBuilderTest() { + } + + @ProcessorTest(baseDir = "java8Test") + void java8Test() { + } + + @ProcessorTest(baseDir = "jaxbTest") + void jaxbTest() { + } + + @ProcessorTest(baseDir = "jsr330Test") + void jsr330Test() { + } + + @ProcessorTest(baseDir = "lombokBuilderTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + void lombokBuilderTest() { + } + + @ProcessorTest(baseDir = "namingStrategyTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + void namingStrategyTest() { + } + + /** + * ECLIPSE_JDT is not working with Protobuf. Use all other available processor types. + */ + @ProcessorTest(baseDir = "protobufBuilderTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + void protobufBuilderTest() { + } + + @ProcessorTest(baseDir = "simpleTest") + void simpleTest() { + } + + @ProcessorTest(baseDir = "springTest") + void springTest() { + } + + /** + * Tests usage of MapStruct with another processor that generates supertypes of mapping source/target types. + */ + @ProcessorTest(baseDir = "superTypeGenerationTest", processorTypes = ProcessorTest.ProcessorType.JAVAC) + void superTypeGenerationTest() { + } + + /** + * Tests usage of MapStruct with another processor that generates the target type of a mapping method. + */ + @ProcessorTest(baseDir = "targetTypeGenerationTest", processorTypes = ProcessorTest.ProcessorType.JAVAC) + void targetTypeGenerationTest() { + } + +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java deleted file mode 100644 index 55d06a3f14..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/NamingStrategyTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite(baseDir = "namingStrategyTest", processorTypes = ProcessorType.ORACLE_JAVA_8) -public class NamingStrategyTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java deleted file mode 100644 index cf648ca3c8..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/ProtobufBuilderTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * ECLIPSE_JDT_JAVA_8 is not working with Protobuf. Use all other available processor types. - * - * @author Christian Bandowski - */ -@RunWith(ProcessorSuiteRunner.class) -@ProcessorSuite(baseDir = "protobufBuilderTest", - processorTypes = { - ProcessorSuite.ProcessorType.ORACLE_JAVA_8, - ProcessorSuite.ProcessorType.ORACLE_JAVA_9, - }) -public class ProtobufBuilderTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java deleted file mode 100644 index bbcd7a529d..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SimpleTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "simpleTest", processorTypes = ProcessorType.ALL ) -public class SimpleTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java deleted file mode 100644 index 1eca9383a2..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SpringTest.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * @author Andreas Gudian - * - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite( baseDir = "springTest", processorTypes = ProcessorType.ALL ) -public class SpringTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java deleted file mode 100644 index b39f8e93d9..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/SuperTypeGenerationTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * Tests usage of MapStruct with another processor that generates supertypes of mapping source/target types. - * - * @author Gunnar Morling - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite(baseDir = "superTypeGenerationTest", processorTypes = ProcessorType.ORACLE_JAVA_8) -public class SuperTypeGenerationTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java deleted file mode 100644 index 2cbd78f0f2..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/TargetTypeGenerationTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.tests; - -import org.junit.runner.RunWith; -import org.mapstruct.itest.testutil.runner.ProcessorSuite; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner; - -/** - * Tests usage of MapStruct with another processor that generates the target type of a mapping method. - * - * @author Gunnar Morling - */ -@RunWith( ProcessorSuiteRunner.class ) -@ProcessorSuite(baseDir = "targetTypeGenerationTest", processorTypes = ProcessorType.ORACLE_JAVA_8) -public class TargetTypeGenerationTest { -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorEnabledOnJreCondition.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorEnabledOnJreCondition.java new file mode 100644 index 0000000000..a651e55f93 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorEnabledOnJreCondition.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +import static org.mapstruct.itest.testutil.extension.ProcessorTestTemplateInvocationContext.CURRENT_VERSION; + +/** + * @author Filip Hrisafov + */ +public class ProcessorEnabledOnJreCondition implements ExecutionCondition { + + static final ConditionEvaluationResult ENABLED_ON_CURRENT_JRE = + ConditionEvaluationResult.enabled( "Enabled on JRE version: " + System.getProperty( "java.version" ) ); + + static final ConditionEvaluationResult DISABLED_ON_CURRENT_JRE = + ConditionEvaluationResult.disabled( "Disabled on JRE version: " + System.getProperty( "java.version" ) ); + + public ProcessorEnabledOnJreCondition(ProcessorTest.ProcessorType processorType) { + this.processorType = processorType; + } + + protected final ProcessorTest.ProcessorType processorType; + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + // If the max JRE is greater or equal to the current version the test is enabled + return processorType.maxJre().compareTo( CURRENT_VERSION ) >= 0 ? ENABLED_ON_CURRENT_JRE : + DISABLED_ON_CURRENT_JRE; + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java new file mode 100644 index 0000000000..4cf0738eb1 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -0,0 +1,207 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.apache.maven.it.Verifier; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.InvocationInterceptor; +import org.junit.jupiter.api.extension.ReflectiveInvocationContext; +import org.junit.platform.commons.util.ReflectionUtils; + +import static org.apache.maven.it.util.ResourceExtractor.extractResourceToDestination; +import static org.apache.maven.shared.utils.io.FileUtils.copyURLToFile; +import static org.apache.maven.shared.utils.io.FileUtils.deleteDirectory; +import static org.mapstruct.itest.testutil.extension.ProcessorTestTemplateInvocationContext.CURRENT_VERSION; + +/** + * @author Filip Hrisafov + * @author Andreas Gudian + */ +public class ProcessorInvocationInterceptor implements InvocationInterceptor { + + /** + * System property to enable remote debugging of the processor execution in the integration test + */ + public static final String SYS_PROP_DEBUG = "processorIntegrationTest.debug"; + + private final ProcessorTestContext processorTestContext; + + public ProcessorInvocationInterceptor(ProcessorTestContext processorTestContext) { + this.processorTestContext = processorTestContext; + } + + @Override + public void interceptTestTemplateMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, ExtensionContext extensionContext) throws Throwable { + try { + doExecute( extensionContext ); + invocation.proceed(); + } + catch ( Exception e ) { + invocation.skip(); + throw e; + } + } + + private void doExecute(ExtensionContext extensionContext) throws Exception { + File destination = extractTest( extensionContext ); + PrintStream originalOut = System.out; + + final Verifier verifier; + if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) { + // the compiler is executed within the Maven JVM. So make + // sure we fork a new JVM for that, and let that new JVM use the command 'mvnDebug' instead of 'mvn' + verifier = new Verifier( destination.getCanonicalPath(), null, true, true ); + verifier.setDebugJvm( true ); + } + else { + verifier = new Verifier( destination.getCanonicalPath() ); + } + + List goals = new ArrayList<>( 3 ); + + goals.add( "clean" ); + + try { + configureProcessor( verifier ); + + verifier.addCliOption( "-Dcompiler-source-target-version=" + sourceTargetVersion() ); + + if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) { + originalOut.print( "Processor Integration Test: " ); + originalOut.println( "Listening for transport dt_socket at address: 8000 (in some seconds)" ); + } + + goals.add( "test" ); + + addAdditionalCliArguments( verifier ); + + originalOut.println( extensionContext.getRequiredTestClass().getSimpleName() + "." + + extensionContext.getRequiredTestMethod().getName() + " executing " + + processorTestContext.getProcessor().name().toLowerCase() ); + + verifier.executeGoals( goals ); + verifier.verifyErrorFreeLog(); + } + finally { + verifier.resetStreams(); + } + } + + private void addAdditionalCliArguments(Verifier verifier) + throws Exception { + Class cliEnhancerClass = + processorTestContext.getCliEnhancerClass(); + + Constructor cliEnhancerConstructor = null; + if ( cliEnhancerClass != ProcessorTest.CommandLineEnhancer.class ) { + try { + cliEnhancerConstructor = cliEnhancerClass.getConstructor(); + ProcessorTest.CommandLineEnhancer enhancer = cliEnhancerConstructor.newInstance(); + Collection additionalArgs = enhancer.getAdditionalCommandLineArguments( + processorTestContext.getProcessor(), CURRENT_VERSION ); + + for ( String arg : additionalArgs ) { + verifier.addCliOption( arg ); + } + + } + catch ( NoSuchMethodException e ) { + throw new RuntimeException( cliEnhancerClass + " does not have a default constructor." ); + } + catch ( SecurityException e ) { + throw new RuntimeException( e ); + } + } + } + + private void configureProcessor(Verifier verifier) { + String compilerId = processorTestContext.getProcessor().getCompilerId(); + if ( compilerId != null ) { + verifier.addCliOption( "-Pgenerate-via-compiler-plugin" ); + verifier.addCliOption( "-Dcompiler-id=" + compilerId ); + } + else { + verifier.addCliOption( "-Pgenerate-via-processor-plugin" ); + } + } + + private File extractTest(ExtensionContext extensionContext) throws IOException { + String tmpDir = getTmpDir(); + + String tempDirName = extensionContext.getRequiredTestClass().getPackage().getName() + "." + + extensionContext.getRequiredTestMethod().getName(); + File tempDirBase = new File( tmpDir, tempDirName ).getCanonicalFile(); + + if ( !tempDirBase.exists() ) { + tempDirBase.mkdirs(); + } + + File parentPom = new File( tempDirBase, "pom.xml" ); + copyURLToFile( getClass().getResource( "/pom.xml" ), parentPom ); + + ProcessorTest.ProcessorType processorType = processorTestContext.getProcessor(); + File tempDir = new File( tempDirBase, processorType.name().toLowerCase() ); + deleteDirectory( tempDir ); + + return extractResourceToDestination( getClass(), "/" + processorTestContext.getBaseDir(), tempDir, true ); + } + + private String getTmpDir() { + if ( CURRENT_VERSION == JRE.JAVA_8 ) { + // On Java 8 the tmp dir is always + // no matter we run from the aggregator or not + return "target/tmp"; + } + + // On Java 11+ we need to do it base on the location relative + String tmpDir; + if ( Files.exists( Paths.get( "integrationtest" ) ) ) { + // If it exists then we are running from the main aggregator + tmpDir = "integrationtest/target/tmp"; + } + else { + tmpDir = "target/tmp"; + } + return tmpDir; + } + + private String sourceTargetVersion() { + if ( CURRENT_VERSION == JRE.JAVA_8 ) { + return "1.8"; + } + else if ( CURRENT_VERSION == JRE.OTHER ) { + try { + // java.lang.Runtime.version() is a static method available on Java 9+ + // that returns an instance of java.lang.Runtime.Version which has the + // following method: public int major() + Method versionMethod = null; + versionMethod = Runtime.class.getMethod( "version" ); + Object version = ReflectionUtils.invokeMethod( versionMethod, null ); + Method majorMethod = version.getClass().getMethod( "major" ); + return String.valueOf( (int) ReflectionUtils.invokeMethod( majorMethod, version ) ); + } + catch ( NoSuchMethodException e ) { + throw new RuntimeException( "Failed to get Java Version" ); + } + } + else { + return CURRENT_VERSION.name().substring( 5 ); + } + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java new file mode 100644 index 0000000000..1db77ae6b2 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java @@ -0,0 +1,109 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Collection; + +import org.apache.maven.it.Verifier; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Declares the content of the integration test. + *

      + * {@link #baseDir()} must be a path in the classpath that contains the maven module to run as integration test. The + * integration test module should contain at least one test class. The integration test passes, if + * {@code mvn clean test} finishes successfully. + *

      + * {@link #processorTypes()} configures the variants to execute the integration tests with. See + * {@link ProcessorType}. + * + * @author Filip Hrisafov + */ +@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@TestTemplate +@ExtendWith(ProcessorTestTemplateInvocationContextProvider.class) +public @interface ProcessorTest { + + /** + * Describes the type of the processing variant(s) to use when executing the integration test. + * + * @author Filip Hrisafov + */ + enum ProcessorType { + + JAVAC( "javac" ), + + ECLIPSE_JDT( "jdt", JRE.JAVA_8 ), + + PROCESSOR_PLUGIN( null, JRE.JAVA_8 ); + + private final String compilerId; + private final JRE max; + + ProcessorType(String compilerId) { + this( compilerId, JRE.OTHER ); + } + + ProcessorType(String compilerId, JRE max) { + this.compilerId = compilerId; + this.max = max; + } + + public String getCompilerId() { + return compilerId; + } + + public JRE maxJre() { + return max; + } + } + + /** + * Can be configured to provide additional command line arguments for the invoked Maven process, depending on the + * {@link ProcessorType} the test is executed for. + * + * @author Andreas Gudian + */ + interface CommandLineEnhancer { + /** + * @param processorType the processor type for which the test is executed. + * @param currentJreVersion the current JRE version + * + * @return additional command line arguments to be passed to the Maven {@link Verifier}. + */ + Collection getAdditionalCommandLineArguments(ProcessorType processorType, + JRE currentJreVersion); + } + + + /** + * @return a path in the classpath that contains the maven module to run as integration test: {@code mvn clean test} + */ + String baseDir(); + + /** + * @return the variants to execute the integration tests with. See {@link ProcessorType}. + */ + ProcessorType[] processorTypes() default { + ProcessorType.JAVAC, + ProcessorType.ECLIPSE_JDT, + ProcessorType.PROCESSOR_PLUGIN + }; + + /** + * @return the {@link CommandLineEnhancer} implementation. Must have a default constructor. + */ + Class commandLineEnhancer() default CommandLineEnhancer.class; +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java new file mode 100644 index 0000000000..be1e4647c7 --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +/** + * @author Filip Hrisafov + */ +public class ProcessorTestContext { + + private final String baseDir; + private final ProcessorTest.ProcessorType processor; + private final Class cliEnhancerClass; + + public ProcessorTestContext(String baseDir, + ProcessorTest.ProcessorType processor, + Class cliEnhancerClass) { + this.baseDir = baseDir; + this.processor = processor; + this.cliEnhancerClass = cliEnhancerClass; + } + + public String getBaseDir() { + return baseDir; + } + + public ProcessorTest.ProcessorType getProcessor() { + return processor; + } + + public Class getCliEnhancerClass() { + return cliEnhancerClass; + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContext.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContext.java new file mode 100644 index 0000000000..47e692988d --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContext.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; + +/** + * @author Filip Hrisafov + */ +public class ProcessorTestTemplateInvocationContext implements TestTemplateInvocationContext { + + static final JRE CURRENT_VERSION; + + static { + JRE currentVersion = JRE.OTHER; + for ( JRE jre : JRE.values() ) { + if ( jre.isCurrentVersion() ) { + currentVersion = jre; + break; + } + } + + CURRENT_VERSION = currentVersion; + } + + private final ProcessorTestContext processorTestContext; + + public ProcessorTestTemplateInvocationContext(ProcessorTestContext processorTestContext) { + this.processorTestContext = processorTestContext; + } + + @Override + public String getDisplayName(int invocationIndex) { + return processorTestContext.getProcessor().name().toLowerCase(); + } + + @Override + public List getAdditionalExtensions() { + List extensions = new ArrayList<>(); + extensions.add( new ProcessorEnabledOnJreCondition( processorTestContext.getProcessor() ) ); + extensions.add( new ProcessorInvocationInterceptor( processorTestContext ) ); + return extensions; + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java new file mode 100644 index 0000000000..b7a4f331cf --- /dev/null +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.testutil.extension; + +import java.lang.reflect.Method; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.junit.platform.commons.support.AnnotationSupport; + +/** + * @author Filip Hrisafov + */ +public class ProcessorTestTemplateInvocationContextProvider implements TestTemplateInvocationContextProvider { + @Override + public boolean supportsTestTemplate(ExtensionContext context) { + return AnnotationSupport.isAnnotated( context.getTestMethod(), ProcessorTest.class ); + } + + @Override + public Stream provideTestTemplateInvocationContexts(ExtensionContext context) { + + Method testMethod = context.getRequiredTestMethod(); + ProcessorTest processorTest = AnnotationSupport.findAnnotation( testMethod, ProcessorTest.class ) + .orElseThrow( () -> new RuntimeException( "Failed to get ProcessorTest on " + testMethod ) ); + + + return Stream.of( processorTest.processorTypes() ) + .map( processorType -> new ProcessorTestTemplateInvocationContext( new ProcessorTestContext( + processorTest.baseDir(), + processorType, + processorTest.commandLineEnhancer() + ) ) ); + } +} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java deleted file mode 100644 index 916d513954..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuite.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.testutil.runner; - -import org.apache.maven.it.Verifier; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.Collection; - -/** - * Declares the content of the integration test. - *

      - * {@link #baseDir()} must be a path in the classpath that contains the maven module to run as integration test. The - * integration test module should contain at least one test class. The integration test passes, if - * {@code mvn clean test} finishes successfully. - *

      - * {@link #processorTypes()} configures the variants to execute the integration tests with. See {@link ProcessorType}. - * - * @author Andreas Gudian - */ -@Retention( RetentionPolicy.RUNTIME ) -@Documented -@Target( ElementType.TYPE ) -public @interface ProcessorSuite { - /** - * Describes the type of the processing variant(s) to use when executing the integration test. - *

      - * Types that require toolchains, will - * need the toolchains.xml file to be either installed in ~/m2, or alternatively passed to the mvn process using - * {@code mvn -DprocessorIntegrationTest.toolchainsFile=/path/to/toolchains.xml ...} - * - * @author Andreas Gudian - */ - enum ProcessorType { - - /** - * Use the same JDK that runs the mvn build to perform the processing - */ - ORACLE_JAVA_8( null, "javac", "1.8" ), - - /** - * Use an Oracle JDK 1.9 (or 1.9.x) via toolchain support to perform the processing - */ - ORACLE_JAVA_9( new Toolchain( "oracle", "9", "10" ), "javac", "1.9" ), - - /** - * Use the eclipse compiler with 1.8 source/target level from tycho-compiler-jdt to perform the build and - * processing - */ - ECLIPSE_JDT_JAVA_8( null, "jdt", "1.8" ), - - /** - * Use the maven-processor-plugin with 1.8 source/target level with the same JDK that runs the mvn build to - * perform the processing - */ - PROCESSOR_PLUGIN_JAVA_8( null, null, "1.8" ), - - /** - * Use all processing variants, but without the maven-procesor-plugin - */ - ALL_WITHOUT_PROCESSOR_PLUGIN( ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_8), - - /** - * Use all available processing variants - */ - ALL( ORACLE_JAVA_8, ORACLE_JAVA_9, ECLIPSE_JDT_JAVA_8, PROCESSOR_PLUGIN_JAVA_8 ), - - /** - * Use all JDK8 compatible processing variants - */ - ALL_JAVA_8( ORACLE_JAVA_8, ECLIPSE_JDT_JAVA_8, PROCESSOR_PLUGIN_JAVA_8 ); - - private ProcessorType[] included = { }; - - private Toolchain toolchain; - private String compilerId; - private String sourceTargetVersion; - - ProcessorType(Toolchain toolchain, String compilerId, String sourceTargetVersion) { - this.toolchain = toolchain; - this.compilerId = compilerId; - this.sourceTargetVersion = sourceTargetVersion; - } - - ProcessorType(ProcessorType... included) { - this.included = included; - } - - /** - * @return the processor types that are grouped by this type - */ - public ProcessorType[] getIncluded() { - return included; - } - - /** - * @return the toolchain - */ - public Toolchain getToolchain() { - return toolchain; - } - - /** - * @return the compilerId - */ - public String getCompilerId() { - return compilerId; - } - - /** - * @return the sourceTargetVersion - */ - public String getSourceTargetVersion() { - return sourceTargetVersion; - } - } - - /** - * Can be configured to provide additional command line arguments for the invoked Maven process, depending on the - * {@link ProcessorType} the test is executed for. - * - * @author Andreas Gudian - */ - interface CommandLineEnhancer { - /** - * @param processorType the processor type for which the test is executed. - * @return additional command line arguments to be passed to the Maven {@link Verifier}. - */ - Collection getAdditionalCommandLineArguments(ProcessorType processorType); - } - - /** - * @return a path in the classpath that contains the maven module to run as integration test: {@code mvn clean test} - */ - String baseDir(); - - /** - * @return the variants to execute the integration tests with. See {@link ProcessorType}. - */ - ProcessorType[] processorTypes() default { ProcessorType.ALL }; - - /** - * @return the {@link CommandLineEnhancer} implementation. Must have a default constructor. - */ - Class commandLineEnhancer() default CommandLineEnhancer.class; -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java deleted file mode 100644 index cb3f601b21..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/ProcessorSuiteRunner.java +++ /dev/null @@ -1,354 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.testutil.runner; - -import static org.apache.maven.it.util.ResourceExtractor.extractResourceToDestination; -import static org.apache.maven.shared.utils.io.FileUtils.copyURLToFile; -import static org.apache.maven.shared.utils.io.FileUtils.deleteDirectory; - -import java.io.File; -import java.io.IOException; -import java.io.PrintStream; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - -import org.apache.maven.it.Verifier; -import org.junit.internal.AssumptionViolatedException; -import org.junit.internal.runners.model.EachTestNotifier; -import org.junit.runner.Description; -import org.junit.runner.notification.RunNotifier; -import org.junit.runner.notification.StoppedByUserException; -import org.junit.runners.ParentRunner; -import org.junit.runners.model.InitializationError; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.CommandLineEnhancer; -import org.mapstruct.itest.testutil.runner.ProcessorSuite.ProcessorType; -import org.mapstruct.itest.testutil.runner.ProcessorSuiteRunner.ProcessorTestCase; -import org.mapstruct.itest.testutil.runner.xml.Toolchains; -import org.mapstruct.itest.testutil.runner.xml.Toolchains.ProviderDescription; - -/** - * Runner for processor integration tests. Requires the annotation {@link ProcessorSuite} on the test class. - * - * @author Andreas Gudian - */ -public class ProcessorSuiteRunner extends ParentRunner { - - /** - * System property for specifying the location of the toolchains.xml file - */ - public static final String SYS_PROP_TOOLCHAINS_FILE = "processorIntegrationTest.toolchainsFile"; - - /** - * System property to enable remote debugging of the processor execution in the integration test - */ - public static final String SYS_PROP_DEBUG = "processorIntegrationTest.debug"; - - private static final File TOOLCHAINS_FILE = getToolchainsFile(); - - private static final Collection ENABLED_PROCESSOR_TYPES = detectSupportedTypes( TOOLCHAINS_FILE ); - - public static final class ProcessorTestCase { - private final String baseDir; - private final ProcessorType processor; - private final boolean ignored; - private final Constructor cliEnhancerConstructor; - - public ProcessorTestCase(String baseDir, ProcessorType processor, - Constructor cliEnhancerConstructor) { - this.baseDir = baseDir; - this.processor = processor; - this.cliEnhancerConstructor = cliEnhancerConstructor; - this.ignored = !ENABLED_PROCESSOR_TYPES.contains( processor ); - } - } - - private final List methods; - - /** - * @param clazz the test class - * @throws InitializationError in case the initialization fails - */ - public ProcessorSuiteRunner(Class clazz) throws InitializationError { - super( clazz ); - - ProcessorSuite suite = clazz.getAnnotation( ProcessorSuite.class ); - - if ( null == suite ) { - throw new InitializationError( "The test class must be annotated with " + ProcessorSuite.class.getName() ); - } - - if ( suite.processorTypes().length == 0 ) { - throw new InitializationError( "ProcessorSuite#processorTypes must not be empty" ); - } - - Constructor cliEnhancerConstructor = null; - if ( suite.commandLineEnhancer() != CommandLineEnhancer.class ) { - try { - cliEnhancerConstructor = suite.commandLineEnhancer().getConstructor(); - } - catch ( NoSuchMethodException e ) { - throw new InitializationError( - suite.commandLineEnhancer().getName() + " does not have a default constructor." ); - } - catch ( SecurityException e ) { - throw new InitializationError( e ); - } - } - - methods = initializeTestCases( suite, cliEnhancerConstructor ); - } - - private List initializeTestCases(ProcessorSuite suite, - Constructor cliEnhancerConstructor) { - List types = new ArrayList<>(); - - for ( ProcessorType compiler : suite.processorTypes() ) { - if ( compiler.getIncluded().length > 0 ) { - types.addAll( Arrays.asList( compiler.getIncluded() ) ); - } - else { - types.add( compiler ); - } - } - - List result = new ArrayList( types.size() ); - - for ( ProcessorType type : types ) { - result.add( new ProcessorTestCase( suite.baseDir(), type, cliEnhancerConstructor ) ); - } - - return result; - } - - @Override - protected List getChildren() { - return methods; - } - - @Override - protected Description describeChild(ProcessorTestCase child) { - return Description.createTestDescription( getTestClass().getJavaClass(), child.processor.name().toLowerCase() ); - } - - @Override - protected void runChild(ProcessorTestCase child, RunNotifier notifier) { - Description description = describeChild( child ); - EachTestNotifier testNotifier = new EachTestNotifier( notifier, description ); - - if ( child.ignored ) { - testNotifier.fireTestIgnored(); - } - else { - try { - testNotifier.fireTestStarted(); - doExecute( child, description ); - } - catch ( AssumptionViolatedException e ) { - testNotifier.fireTestIgnored(); - } - catch ( StoppedByUserException e ) { - throw e; - } - catch ( Throwable e ) { - testNotifier.addFailure( e ); - } - finally { - testNotifier.fireTestFinished(); - } - } - } - - private void doExecute(ProcessorTestCase child, Description description) throws Exception { - File destination = extractTest( child, description ); - PrintStream originalOut = System.out; - - final Verifier verifier; - if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) { - if ( child.processor.getToolchain() == null ) { - // when not using toolchains for a test, then the compiler is executed within the Maven JVM. So make - // sure we fork a new JVM for that, and let that new JVM use the command 'mvnDebug' instead of 'mvn' - verifier = new Verifier( destination.getCanonicalPath(), null, true, true ); - verifier.setDebugJvm( true ); - } - else { - verifier = new Verifier( destination.getCanonicalPath() ); - verifier.addCliOption( "-Pdebug-forked-javac" ); - } - } - else { - verifier = new Verifier( destination.getCanonicalPath() ); - } - - List goals = new ArrayList<>( 3 ); - - goals.add( "clean" ); - - try { - configureToolchains( child, verifier, goals, originalOut ); - configureProcessor( child, verifier ); - - verifier.addCliOption( "-Dcompiler-source-target-version=" + child.processor.getSourceTargetVersion() ); - - verifier.addCliOption( "-Dmapstruct-artifact-id=mapstruct" ); - - if ( Boolean.getBoolean( SYS_PROP_DEBUG ) ) { - originalOut.print( "Processor Integration Test: " ); - originalOut.println( "Listening for transport dt_socket at address: 8000 (in some seconds)" ); - } - - goals.add( "test" ); - - addAdditionalCliArguments( child, verifier ); - - originalOut.println( "executing " + child.processor.name().toLowerCase() ); - - verifier.executeGoals( goals ); - verifier.verifyErrorFreeLog(); - } - finally { - verifier.resetStreams(); - } - } - - private void addAdditionalCliArguments(ProcessorTestCase child, final Verifier verifier) throws Exception { - if ( child.cliEnhancerConstructor != null ) { - CommandLineEnhancer enhancer = child.cliEnhancerConstructor.newInstance(); - Collection additionalArgs = enhancer.getAdditionalCommandLineArguments( child.processor ); - - if ( additionalArgs != null ) { - for ( String arg : additionalArgs ) { - verifier.addCliOption( arg ); - } - } - } - } - - private void configureProcessor(ProcessorTestCase child, Verifier verifier) { - if ( child.processor.getCompilerId() != null ) { - verifier.addCliOption( "-Pgenerate-via-compiler-plugin" ); - verifier.addCliOption( "-Dcompiler-id=" + child.processor.getCompilerId() ); - } - else { - verifier.addCliOption( "-Pgenerate-via-processor-plugin" ); - } - } - - private void configureToolchains(ProcessorTestCase child, Verifier verifier, List goals, - PrintStream originalOut) { - if ( child.processor.getToolchain() != null ) { - verifier.addCliOption( "--toolchains" ); - verifier.addCliOption( TOOLCHAINS_FILE.getPath().replace( '\\', '/' ) ); - - Toolchain toolchain = child.processor.getToolchain(); - - verifier.addCliOption( "-Dtoolchain-jdk-vendor=" + toolchain.getVendor() ); - verifier.addCliOption( "-Dtoolchain-jdk-version=" + toolchain.getVersionRangeString() ); - - goals.add( "toolchains:toolchain" ); - } - } - - private File extractTest(ProcessorTestCase child, Description description) throws IOException { - File tempDirBase = new File( "target/tmp", description.getClassName() ).getCanonicalFile(); - - if ( !tempDirBase.exists() ) { - tempDirBase.mkdirs(); - } - - File parentPom = new File( tempDirBase, "pom.xml" ); - copyURLToFile( getClass().getResource( "/pom.xml" ), parentPom ); - - File tempDir = new File( tempDirBase, description.getMethodName() ); - deleteDirectory( tempDir ); - - return extractResourceToDestination( getClass(), "/" + child.baseDir, tempDir, true ); - } - - private static File getToolchainsFile() { - String specifiedToolchainsFile = System.getProperty( SYS_PROP_TOOLCHAINS_FILE ); - if ( null != specifiedToolchainsFile ) { - try { - File canonical = new File( specifiedToolchainsFile ).getCanonicalFile(); - if ( canonical.exists() ) { - return canonical; - } - - // check the path relative to the parent directory (allows specifying a path relative to the top-level - // aggregator module) - canonical = new File( "..", specifiedToolchainsFile ).getCanonicalFile(); - if ( canonical.exists() ) { - return canonical; - } - } - catch ( IOException e ) { - return null; - } - } - - // use default location - String defaultPath = System.getProperty( "user.home" ) + System.getProperty( "file.separator" ) + ".m2"; - return new File( defaultPath, "toolchains.xml" ); - } - - private static Collection detectSupportedTypes(File toolchainsFile) { - Toolchains toolchains; - try { - if ( toolchainsFile.exists() ) { - Unmarshaller unmarshaller = JAXBContext.newInstance( Toolchains.class ).createUnmarshaller(); - toolchains = (Toolchains) unmarshaller.unmarshal( toolchainsFile ); - } - else { - toolchains = null; - } - } - catch ( JAXBException e ) { - toolchains = null; - } - - Collection supported = new HashSet<>(); - for ( ProcessorType type : ProcessorType.values() ) { - if ( isSupported( type, toolchains ) ) { - supported.add( type ); - } - } - - return supported; - } - - private static boolean isSupported(ProcessorType type, Toolchains toolchains) { - if ( type.getToolchain() == null ) { - return true; - } - - if ( toolchains == null ) { - return false; - } - - Toolchain required = type.getToolchain(); - - for ( Toolchains.Toolchain tc : toolchains.getToolchains() ) { - if ( "jdk".equals( tc.getType() ) ) { - ProviderDescription desc = tc.getProviderDescription(); - if ( desc != null - && required.getVendor().equals( desc.getVendor() ) - && desc.getVersion() != null - && desc.getVersion().startsWith( required.getVersionMinInclusive() ) ) { - return true; - } - } - } - - return false; - } -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java deleted file mode 100644 index 83b7f7f666..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/Toolchain.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.testutil.runner; - -/** - * Describes a required entry in the Maven toolchains.xml file. - * - * @author Andreas Gudian - */ -class Toolchain { - private final String vendor; - private final String versionMinInclusive; - private final String versionMaxExclusive; - - Toolchain(String vendor, String versionMinInclusive, String versionMaxExclusive) { - this.vendor = vendor; - this.versionMinInclusive = versionMinInclusive; - this.versionMaxExclusive = versionMaxExclusive; - } - - String getVendor() { - return vendor; - } - - String getVersionMinInclusive() { - return versionMinInclusive; - } - - /** - * @return the version range string to be used in the Maven execution to select the toolchain - */ - String getVersionRangeString() { - return "[" + versionMinInclusive + "," + versionMaxExclusive + ")"; - } -} diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java deleted file mode 100644 index 4f9b0c7e60..0000000000 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/runner/xml/Toolchains.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.itest.testutil.runner.xml; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * JAXB representation of some of the parts in the Maven toolchains.xml file. - * - * @author Andreas Gudian - */ -@XmlRootElement -public class Toolchains { - @XmlElement(name = "toolchain") - private List toolchains = new ArrayList<>(); - - public List getToolchains() { - return toolchains; - } - - @Override - public String toString() { - return "Toolchains [toolchains=" + toolchains + "]"; - } - - public static class Toolchain { - @XmlElement - private String type; - - @XmlElement(name = "provides") - private ProviderDescription providerDescription; - - public String getType() { - return type; - } - - public ProviderDescription getProviderDescription() { - return providerDescription; - } - - @Override - public String toString() { - return "Toolchain [type=" + type + ", providerDescription=" + providerDescription + "]"; - } - } - - public static class ProviderDescription { - @XmlElement - private String version; - - @XmlElement - private String vendor; - - public String getVersion() { - return version; - } - - public String getVendor() { - return vendor; - } - - @Override - public String toString() { - return "ProviderDescription [version=" + version + ", vendor=" + vendor + "]"; - } - } -} diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 9a7b85426f..ebf4590d30 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -76,4 +76,25 @@ joda-time + + + + jdk-11-or-newer + + [11 + + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.2 + + + org.glassfish.jaxb + jaxb-runtime + 2.3.2 + + + + diff --git a/integrationtest/src/test/resources/jaxbTest/pom.xml b/integrationtest/src/test/resources/jaxbTest/pom.xml index 49f6c28cef..8b3e4c7921 100644 --- a/integrationtest/src/test/resources/jaxbTest/pom.xml +++ b/integrationtest/src/test/resources/jaxbTest/pom.xml @@ -50,4 +50,26 @@ + + + + jdk-11-or-newer + + [11 + + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.2 + + + org.glassfish.jaxb + jaxb-runtime + 2.3.2 + + + + + diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index d2ed9acdca..b386ce6e27 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -24,9 +24,6 @@ ${mapstruct.version} - mapstruct - - @@ -137,7 +134,7 @@ ${project.groupId} - \${mapstruct-artifact-id} + mapstruct ${mapstruct.version} provided @@ -165,19 +162,6 @@ \${compiler-source-target-version} - - org.apache.maven.plugins - maven-toolchains-plugin - 1.0 - - - - \${toolchain-jdk-version} - \${toolchain-jdk-vendor} - - - - org.apache.maven.plugins maven-enforcer-plugin diff --git a/parent/pom.xml b/parent/pom.xml index 523a715112..3103f1c1ce 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -29,6 +29,7 @@ 4.0.3.RELEASE 0.26.0 8.29 + 5.6.0 1 3.11.1 @@ -129,6 +130,14 @@ ${com.puppycrawl.tools.checkstyle.version} + + org.junit + junit-bom + ${org.junit.jupiter.version} + pom + import + + javax.enterprise @@ -189,7 +198,7 @@ org.projectlombok lombok - 1.16.18 + 1.18.10 org.immutables @@ -573,12 +582,12 @@ copyright.txt **/LICENSE.txt **/mapstruct.xml - **/toolchains-*.xml **/travis-settings.xml **/eclipse-formatter-config.xml **/forbidden-apis.txt **/checkstyle-for-generated-sources.xml **/nb-configuration.xml + **/junit-platform.properties maven-settings.xml readme.md CONTRIBUTING.md From f382903bc689a7e7e043fc72a9ec9d4686f69db1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 4 Feb 2020 13:05:53 +0100 Subject: [PATCH 0435/1006] Add proper attribution for the code for generating the sourceTargetVersion for other JRE --- .../testutil/extension/ProcessorInvocationInterceptor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 4cf0738eb1..0861f690cb 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -187,6 +187,9 @@ private String sourceTargetVersion() { } else if ( CURRENT_VERSION == JRE.OTHER ) { try { + // Extracting the major version is done with code from + // org.junit.jupiter.api.condition.JRE when determing the current version + // java.lang.Runtime.version() is a static method available on Java 9+ // that returns an instance of java.lang.Runtime.Version which has the // following method: public int major() From c64e03468e51b0e55a1bc2f6ee965445e9dffb07 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 7 Feb 2020 17:35:51 +0100 Subject: [PATCH 0436/1006] Fix Checkstyle error --- .../testutil/extension/ProcessorInvocationInterceptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 0861f690cb..f6f9186ba6 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -187,8 +187,8 @@ private String sourceTargetVersion() { } else if ( CURRENT_VERSION == JRE.OTHER ) { try { - // Extracting the major version is done with code from - // org.junit.jupiter.api.condition.JRE when determing the current version + // Extracting the major version is done with code from + // org.junit.jupiter.api.condition.JRE when determining the current version // java.lang.Runtime.version() is a static method available on Java 9+ // that returns an instance of java.lang.Runtime.Version which has the From 015468b46122d9f0c2e3b43d51a280a255e36a37 Mon Sep 17 00:00:00 2001 From: Robin Clarke Date: Thu, 6 Feb 2020 10:27:57 +0000 Subject: [PATCH 0437/1006] Updated versions on readme.md to 1.3.1.Final --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 37376c8714..3c002f9a85 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.3.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.3.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.3.0.Final + 1.3.1.Final ... @@ -119,10 +119,10 @@ apply plugin: 'net.ltgt.apt-eclipse' dependencies { ... - compile 'org.mapstruct:mapstruct:1.3.0.Final' + compile 'org.mapstruct:mapstruct:1.3.1.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.0.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' // if you are using mapstruct in test code } ... ``` From a6b3cc364a7824a4584fdd690c82c6695447dd79 Mon Sep 17 00:00:00 2001 From: "Tim J. Baumann" Date: Mon, 3 Feb 2020 22:56:42 +0100 Subject: [PATCH 0438/1006] Fix Javadoc of resolveViaMethodAndConversion and fix some smaller Javadoc typos. --- .../processor/creation/MappingResolverImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 39d661f528..47e3e57f62 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -433,7 +433,7 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { * * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) * - * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in + * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt * is done to find a matching type conversion. */ @@ -476,13 +476,13 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp /** * Suppose mapping required from A to C and: *

        - *
      • there is a conversion from A to B, conversionX
      • - *
      • there is a method from B to C, methodY
      • + *
      • there is a method from A to B, methodX
      • + *
      • there is a conversion from B to C, conversionY
      • *
      * then this method tries to resolve this combination and make a mapping conversionY( methodX ( parameter ) ) * - * In stead of directly using a built in method candidate all the return types as 'B' of all available built-in - * methods are used to resolve a mapping (assignment) from source type to 'B'. If a match is found, an attempt + * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from source type to 'B'. If a match is found, an attempt * is done to find a matching type conversion. */ private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { From 273487f152f0299a2633f0b2970e28c58c6c50cb Mon Sep 17 00:00:00 2001 From: "Sean C. Sullivan" Date: Mon, 17 Feb 2020 15:07:00 -0800 Subject: [PATCH 0439/1006] maven-compiler-plugin 3.8.1 --- documentation/src/main/asciidoc/chapter-2-set-up.asciidoc | 2 +- parent/pom.xml | 2 +- readme.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 16183b0001..fb954ac58f 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -35,7 +35,7 @@ For Maven based projects add the following to your POM file in order to use MapS org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.8.1 1.8 1.8 diff --git a/parent/pom.xml b/parent/pom.xml index 3103f1c1ce..9b920c2122 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -324,7 +324,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 1.8 1.8 diff --git a/readme.md b/readme.md index 3c002f9a85..f8247297e2 100644 --- a/readme.md +++ b/readme.md @@ -84,7 +84,7 @@ For Maven-based projects, add the following to your POM file in order to use Map org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.8.1 1.8 1.8 From f5771c4177c203fbc6276def5380f5fcec17f9fe Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Feb 2020 17:51:10 +0100 Subject: [PATCH 0440/1006] #2014 Add support for mapping from Java 14 records --- .travis.yml | 3 + .../itest/tests/MavenIntegrationTest.java | 9 ++ .../src/test/resources/recordsTest/pom.xml | 102 ++++++++++++++++++ .../mapstruct/itest/records/CustomerDto.java | 13 +++ .../itest/records/CustomerEntity.java | 31 ++++++ .../itest/records/CustomerMapper.java | 23 ++++ .../mapstruct/itest/records/RecordsTest.java | 25 +++++ parent/pom.xml | 2 +- .../ap/internal/model/common/Type.java | 5 + .../mapstruct/ap/internal/util/Filters.java | 52 +++++++++ 10 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/resources/recordsTest/pom.xml create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerDto.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerEntity.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java diff --git a/.travis.yml b/.travis.yml index 6a370d1b46..b86d33d312 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,9 @@ matrix: - jdk: openjdk13 # There is an issue with the documentation so skip it script: mvn -B -V clean install -DskipDistribution=true + - jdk: openjdk14 + # There is an issue with the documentation so skip it + script: mvn -B -V clean install -DskipDistribution=true # There is an issue with the documentation so skip it - jdk: openjdk-ea script: mvn -B -V clean install -DskipDistribution=true diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 16298179a0..e579f031f0 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -5,6 +5,8 @@ */ package org.mapstruct.itest.tests; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.mapstruct.itest.testutil.extension.ProcessorTest; @@ -99,6 +101,13 @@ void namingStrategyTest() { void protobufBuilderTest() { } + @ProcessorTest(baseDir = "recordsTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + @EnabledForJreRange(min = JRE.JAVA_14) + void recordsTest() { + } + @ProcessorTest(baseDir = "simpleTest") void simpleTest() { } diff --git a/integrationtest/src/test/resources/recordsTest/pom.xml b/integrationtest/src/test/resources/recordsTest/pom.xml new file mode 100644 index 0000000000..c74469a7ba --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/pom.xml @@ -0,0 +1,102 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + recordsTest + jar + + + + generate-via-compiler-plugin + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + \${compiler-id} + --enable-preview + + + + org.eclipse.tycho + tycho-compiler-jdt + ${org.eclipse.tycho.compiler-jdt.version} + + + + + + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + provided + + + + + debug-forked-javac + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + true + + --enable-preview + -J-Xdebug + -J-Xnoagent + -J-Djava.compiler=NONE + -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + --enable-preview + + + + + + diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerDto.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerDto.java new file mode 100644 index 0000000000..69b2547bc3 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerDto.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public record CustomerDto(String name, String email) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerEntity.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerEntity.java new file mode 100644 index 0000000000..1663bbac5a --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java new file mode 100644 index 0000000000..0e8a0d2567 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromRecord(CustomerDto record); + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java new file mode 100644 index 0000000000..5a7a62f780 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.records.CustomerDto; +import org.mapstruct.itest.records.CustomerEntity; +import org.mapstruct.itest.records.CustomerMapper; + +public class RecordsTest { + + @Test + public void shouldMapRecord() { + CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 9b920c2122..83a59bf2cd 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -510,7 +510,7 @@ org.jacoco jacoco-maven-plugin - 0.8.3 + 0.8.5 org.jvnet.jaxb2.maven2 diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index fe9d5e7e97..6f3a7b79c3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -498,6 +498,11 @@ public Map getPropertyReadAccessors() { } } + Map recordAccessors = filters.recordsIn( typeElement ); + for ( Map.Entry recordEntry : recordAccessors.entrySet() ) { + modifiableGetters.putIfAbsent( recordEntry.getKey(), recordEntry.getValue() ); + } + List fieldsList = filters.fieldsIn( getAllFields() ); for ( Accessor field : fieldsList ) { String propertyName = getPropertyName( field ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index b673b3f162..6981a1ebb5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -5,11 +5,16 @@ */ package org.mapstruct.ap.internal.util; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; @@ -30,9 +35,29 @@ * Filter methods for working with {@link Element} collections. * * @author Gunnar Morling + * @author Filip Hrisafov */ public class Filters { + private static final Method RECORD_COMPONENTS_METHOD; + private static final Method RECORD_COMPONENT_ACCESSOR_METHOD; + + static { + Method recordComponentsMethod; + Method recordComponentAccessorMethod; + try { + recordComponentsMethod = TypeElement.class.getMethod( "getRecordComponents" ); + recordComponentAccessorMethod = Class.forName( "javax.lang.model.element.RecordComponentElement" ) + .getMethod( "getAccessor" ); + } + catch ( NoSuchMethodException | ClassNotFoundException e ) { + recordComponentsMethod = null; + recordComponentAccessorMethod = null; + } + RECORD_COMPONENTS_METHOD = recordComponentsMethod; + RECORD_COMPONENT_ACCESSOR_METHOD = recordComponentAccessorMethod; + } + private final AccessorNamingUtils accessorNaming; private final Types typeUtils; private final TypeMirror typeMirror; @@ -50,6 +75,33 @@ public List getterMethodsIn(List elements) { .collect( Collectors.toCollection( LinkedList::new ) ); } + public Map recordsIn(TypeElement typeElement) { + if ( RECORD_COMPONENTS_METHOD == null || RECORD_COMPONENT_ACCESSOR_METHOD == null ) { + return java.util.Collections.emptyMap(); + } + try { + @SuppressWarnings("unchecked") + List recordComponents = (List) RECORD_COMPONENTS_METHOD.invoke( typeElement ); + Map recordAccessors = new LinkedHashMap<>(); + for ( Element recordComponent : recordComponents ) { + ExecutableElement recordExecutableElement = + (ExecutableElement) RECORD_COMPONENT_ACCESSOR_METHOD.invoke( recordComponent ); + recordAccessors.put( + recordComponent.getSimpleName().toString(), + new ExecutableElementAccessor( recordExecutableElement, + getReturnType( recordExecutableElement ), + GETTER + ) + ); + } + + return recordAccessors; + } + catch ( IllegalAccessException | InvocationTargetException e ) { + return java.util.Collections.emptyMap(); + } + } + private TypeMirror getReturnType(ExecutableElement executableElement) { return getWithinContext( executableElement ).getReturnType(); } From b9f86fe6ac05a3a11e6c05dece8cc08da9c50094 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Feb 2020 17:10:00 +0100 Subject: [PATCH 0441/1006] #2018 Add test case with properties with underscore verifying that it is working as expected --- .../ap/test/bugs/_2018/Issue2018Mapper.java | 22 +++++++++++ .../ap/test/bugs/_2018/Issue2018Test.java | 38 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2018/Source.java | 22 +++++++++++ .../mapstruct/ap/test/bugs/_2018/Target.java | 22 +++++++++++ 4 files changed, 104 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Mapper.java new file mode 100644 index 0000000000..b75450ce25 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2018; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2018Mapper { + + Issue2018Mapper INSTANCE = Mappers.getMapper( Issue2018Mapper.class ); + + @Mapping(target = "some_value", source = "someValue") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java new file mode 100644 index 0000000000..21893e0676 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2018; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2018") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2018Mapper.class, + Source.class, + Target.class +}) +public class Issue2018Test { + + @Test + public void shouldGenerateCorrectCode() { + Source source = new Source(); + source.setSomeValue( "value" ); + + Target target = Issue2018Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getSome_value() ).isEqualTo( "value" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Source.java new file mode 100644 index 0000000000..767952da1a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2018; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private String someValue; + + public String getSomeValue() { + return someValue; + } + + public void setSomeValue(String someValue) { + this.someValue = someValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java new file mode 100644 index 0000000000..582acfbebb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2018; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String some_value; + + public String getSome_value() { + return some_value; + } + + public void setSome_value(String some_value) { + this.some_value = some_value; + } +} From fe91c6d523f02d999195b04bed4dff0ae2366401 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Feb 2020 19:06:46 +0100 Subject: [PATCH 0442/1006] Disable Checkstyle for Target for #2018 test --- .../src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java index 582acfbebb..1d8c1ae3b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Target.java @@ -10,6 +10,7 @@ */ public class Target { + // CHECKSTYLE:OFF private String some_value; public String getSome_value() { @@ -19,4 +20,5 @@ public String getSome_value() { public void setSome_value(String some_value) { this.some_value = some_value; } + // CHECKSTYLE:ON } From 551c104295139f30e39c2e605364b42695f567d6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Feb 2020 20:24:57 +0100 Subject: [PATCH 0443/1006] #2019 Setup GitHub Actions Add Maven Wrapper for using in GitHub Actions Remove Travis --- .github/workflows/main.yml | 66 ++++ .mvn/wrapper/MavenWrapperDownloader.java | 117 +++++++ .mvn/wrapper/maven-wrapper.jar | Bin 0 -> 50710 bytes .mvn/wrapper/maven-wrapper.properties | 2 + .travis.yml | 37 --- CONTRIBUTING.md | 2 +- etc/{travis-settings.xml => ci-settings.xml} | 0 mvnw | 310 +++++++++++++++++++ mvnw.cmd | 182 +++++++++++ parent/pom.xml | 9 +- readme.md | 4 +- 11 files changed, 685 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .mvn/wrapper/MavenWrapperDownloader.java create mode 100644 .mvn/wrapper/maven-wrapper.jar create mode 100644 .mvn/wrapper/maven-wrapper.properties delete mode 100644 .travis.yml rename etc/{travis-settings.xml => ci-settings.xml} (100%) create mode 100755 mvnw create mode 100644 mvnw.cmd diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..5596cadad9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,66 @@ +name: CI + +on: [push, pull_request] + +env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + +jobs: + test_jdk: + strategy: + fail-fast: false + matrix: + java: [11, 12, 13, 14-ea, 15-ea] + name: 'Linux JDK ${{ matrix.java }}' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v2 + - name: 'Set up JDK' + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: 'Test' + run: ./mvnw -V -B --no-transfer-progress install -DskipDistribution=true + linux: + name: 'Linux JDK 8' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v2 + - name: 'Set up JDK 8' + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: 'Test' + run: ./mvnw -V -B --no-transfer-progress install + - name: 'Generate coverage report' + run: ./mvnw jacoco:report + - name: 'Upload coverage to Codecov' + uses: codecov/codecov-action@v1 + - name: 'Publish Snapshots' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'mapstruct/mapstruct' + run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy + windows: + name: 'Windows' + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: 'Set up JDK 8' + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: 'Test' + run: ./mvnw -V -B --no-transfer-progress install + mac: + name: 'Mac OS' + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: 'Set up JDK 8' + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: 'Test' + run: ./mvnw -V -B --no-transfer-progress install diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000000..b901097f2d --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054 GIT binary patch literal 50710 zcmbTd1CVCTmM+|7+wQV$+qP}n>auOywyU~q+qUhh+uxis_~*a##hm*_WW?9E7Pb7N%LRFiwbEGCJ0XP=%-6oeT$XZcYgtzC2~q zk(K08IQL8oTl}>>+hE5YRgXTB@fZ4TH9>7=79e`%%tw*SQUa9~$xKD5rS!;ZG@ocK zQdcH}JX?W|0_Afv?y`-NgLum62B&WSD$-w;O6G0Sm;SMX65z)l%m1e-g8Q$QTI;(Q z+x$xth4KFvH@Bs6(zn!iF#nenk^Y^ce;XIItAoCsow38eq?Y-Auh!1in#Rt-_D>H^ z=EjbclGGGa6VnaMGmMLj`x3NcwA43Jb(0gzl;RUIRAUDcR1~99l2SAPkVhoRMMtN} zXvC<tOmX83grD8GSo_Lo?%lNfhD#EBgPo z*nf@ppMC#B!T)Ae0RG$mlJWmGl7CkuU~B8-==5i;rS;8i6rJ=PoQxf446XDX9g|c> zU64ePyMlsI^V5Jq5A+BPe#e73+kpc_r1tv#B)~EZ;7^67F0*QiYfrk0uVW;Qb=NsG zN>gsuCwvb?s-KQIppEaeXtEMdc9dy6Dfduz-tMTms+i01{eD9JE&h?Kht*$eOl#&L zJdM_-vXs(V#$Ed;5wyNWJdPNh+Z$+;$|%qR(t`4W@kDhd*{(7-33BOS6L$UPDeE_53j${QfKN-0v-HG z(QfyvFNbwPK%^!eIo4ac1;b>c0vyf9}Xby@YY!lkz-UvNp zwj#Gg|4B~?n?G^{;(W;|{SNoJbHTMpQJ*Wq5b{l9c8(%?Kd^1?H1om1de0Da9M;Q=n zUfn{f87iVb^>Exl*nZ0hs(Yt>&V9$Pg`zX`AI%`+0SWQ4Zc(8lUDcTluS z5a_KerZWe}a-MF9#Cd^fi!y3%@RFmg&~YnYZ6<=L`UJ0v={zr)>$A;x#MCHZy1st7 ztT+N07NR+vOwSV2pvWuN1%lO!K#Pj0Fr>Q~R40{bwdL%u9i`DSM4RdtEH#cW)6}+I-eE< z&tZs+(Ogu(H_;$a$!7w`MH0r%h&@KM+<>gJL@O~2K2?VrSYUBbhCn#yy?P)uF3qWU z0o09mIik+kvzV6w>vEZy@&Mr)SgxPzUiDA&%07m17udz9usD82afQEps3$pe!7fUf z0eiidkJ)m3qhOjVHC_M(RYCBO%CZKZXFb8}s0-+}@CIn&EF(rRWUX2g^yZCvl0bI} zbP;1S)iXnRC&}5-Tl(hASKqdSnO?ASGJ*MIhOXIblmEudj(M|W!+I3eDc}7t`^mtg z)PKlaXe(OH+q-)qcQ8a@!llRrpGI8DsjhoKvw9T;TEH&?s=LH0w$EzI>%u;oD@x83 zJL7+ncjI9nn!TlS_KYu5vn%f*@qa5F;| zEFxY&B?g=IVlaF3XNm_03PA)=3|{n-UCgJoTr;|;1AU9|kPE_if8!Zvb}0q$5okF$ zHaJdmO&gg!9oN|M{!qGE=tb|3pVQ8PbL$}e;NgXz<6ZEggI}wO@aBP**2Wo=yN#ZC z4G$m^yaM9g=|&!^ft8jOLuzc3Psca*;7`;gnHm}tS0%f4{|VGEwu45KptfNmwxlE~ z^=r30gi@?cOm8kAz!EylA4G~7kbEiRlRIzwrb~{_2(x^$-?|#e6Bi_**(vyr_~9Of z!n>Gqf+Qwiu!xhi9f53=PM3`3tNF}pCOiPU|H4;pzjcsqbwg*{{kyrTxk<;mx~(;; z1NMrpaQ`57yn34>Jo3b|HROE(UNcQash!0p2-!Cz;{IRv#Vp5!3o$P8!%SgV~k&Hnqhp`5eLjTcy93cK!3Hm-$`@yGnaE=?;*2uSpiZTs_dDd51U%i z{|Zd9ou-;laGS_x=O}a+ zB||za<795A?_~Q=r=coQ+ZK@@ zId~hWQL<%)fI_WDIX#=(WNl!Dm$a&ROfLTd&B$vatq!M-2Jcs;N2vps$b6P1(N}=oI3<3luMTmC|0*{ zm1w8bt7vgX($!0@V0A}XIK)w!AzUn7vH=pZEp0RU0p?}ch2XC-7r#LK&vyc2=-#Q2 z^L%8)JbbcZ%g0Du;|8=q8B>X=mIQirpE=&Ox{TiuNDnOPd-FLI^KfEF729!!0x#Es z@>3ursjFSpu%C-8WL^Zw!7a0O-#cnf`HjI+AjVCFitK}GXO`ME&on|^=~Zc}^LBp9 zj=-vlN;Uc;IDjtK38l7}5xxQF&sRtfn4^TNtnzXv4M{r&ek*(eNbIu!u$>Ed%` z5x7+&)2P&4>0J`N&ZP8$vcR+@FS0126s6+Jx_{{`3ZrIMwaJo6jdrRwE$>IU_JTZ} z(||hyyQ)4Z1@wSlT94(-QKqkAatMmkT7pCycEB1U8KQbFX&?%|4$yyxCtm3=W`$4fiG0WU3yI@c zx{wfmkZAYE_5M%4{J-ygbpH|(|GD$2f$3o_Vti#&zfSGZMQ5_f3xt6~+{RX=$H8at z?GFG1Tmp}}lmm-R->ve*Iv+XJ@58p|1_jRvfEgz$XozU8#iJS})UM6VNI!3RUU!{5 zXB(+Eqd-E;cHQ>)`h0(HO_zLmzR3Tu-UGp;08YntWwMY-9i^w_u#wR?JxR2bky5j9 z3Sl-dQQU$xrO0xa&>vsiK`QN<$Yd%YXXM7*WOhnRdSFt5$aJux8QceC?lA0_if|s> ze{ad*opH_kb%M&~(~&UcX0nFGq^MqjxW?HJIP462v9XG>j(5Gat_)#SiNfahq2Mz2 zU`4uV8m$S~o9(W>mu*=h%Gs(Wz+%>h;R9Sg)jZ$q8vT1HxX3iQnh6&2rJ1u|j>^Qf`A76K%_ubL`Zu?h4`b=IyL>1!=*%!_K)=XC z6d}4R5L+sI50Q4P3upXQ3Z!~1ZXLlh!^UNcK6#QpYt-YC=^H=EPg3)z*wXo*024Q4b2sBCG4I# zlTFFY=kQ>xvR+LsuDUAk)q%5pEcqr(O_|^spjhtpb1#aC& zghXzGkGDC_XDa%t(X`E+kvKQ4zrQ*uuQoj>7@@ykWvF332)RO?%AA&Fsn&MNzmFa$ zWk&&^=NNjxLjrli_8ESU)}U|N{%j&TQmvY~lk!~Jh}*=^INA~&QB9em!in_X%Rl1&Kd~Z(u z9mra#<@vZQlOY+JYUwCrgoea4C8^(xv4ceCXcejq84TQ#sF~IU2V}LKc~Xlr_P=ry zl&Hh0exdCbVd^NPCqNNlxM3vA13EI8XvZ1H9#bT7y*U8Y{H8nwGpOR!e!!}*g;mJ#}T{ekSb}5zIPmye*If(}}_=PcuAW#yidAa^9-`<8Gr0 z)Fz=NiZ{)HAvw{Pl5uu)?)&i&Us$Cx4gE}cIJ}B4Xz~-q7)R_%owbP!z_V2=Aq%Rj z{V;7#kV1dNT9-6R+H}}(ED*_!F=~uz>&nR3gb^Ce%+0s#u|vWl<~JD3MvS0T9thdF zioIG3c#Sdsv;LdtRv3ml7%o$6LTVL>(H`^@TNg`2KPIk*8-IB}X!MT0`hN9Ddf7yN z?J=GxPL!uJ7lqwowsl?iRrh@#5C$%E&h~Z>XQcvFC*5%0RN-Opq|=IwX(dq(*sjs+ zqy99+v~m|6T#zR*e1AVxZ8djd5>eIeCi(b8sUk)OGjAsKSOg^-ugwl2WSL@d#?mdl zib0v*{u-?cq}dDGyZ%$XRY=UkQwt2oGu`zQneZh$=^! zj;!pCBWQNtvAcwcWIBM2y9!*W|8LmQy$H~5BEx)78J`4Z0(FJO2P^!YyQU{*Al+fs z){!4JvT1iLrJ8aU3k0t|P}{RN)_^v%$$r;+p0DY7N8CXzmS*HB*=?qaaF9D@#_$SN zSz{moAK<*RH->%r7xX~9gVW$l7?b|_SYI)gcjf0VAUJ%FcQP(TpBs; zg$25D!Ry_`8xpS_OJdeo$qh#7U+cepZ??TII7_%AXsT$B z=e)Bx#v%J0j``00Zk5hsvv6%T^*xGNx%KN-=pocSoqE5_R)OK%-Pbu^1MNzfds)mL zxz^F4lDKV9D&lEY;I+A)ui{TznB*CE$=9(wgE{m}`^<--OzV-5V4X2w9j(_!+jpTr zJvD*y6;39&T+==$F&tsRKM_lqa1HC}aGL0o`%c9mO=fts?36@8MGm7Vi{Y z^<7m$(EtdSr#22<(rm_(l_(`j!*Pu~Y>>xc>I9M#DJYDJNHO&4=HM%YLIp?;iR&$m z#_$ZWYLfGLt5FJZhr3jpYb`*%9S!zCG6ivNHYzNHcI%khtgHBliM^Ou}ZVD7ehU9 zS+W@AV=?Ro!=%AJ>Kcy9aU3%VX3|XM_K0A+ZaknKDyIS3S-Hw1C7&BSW5)sqj5Ye_ z4OSW7Yu-;bCyYKHFUk}<*<(@TH?YZPHr~~Iy%9@GR2Yd}J2!N9K&CN7Eq{Ka!jdu; zQNB*Y;i(7)OxZK%IHGt#Rt?z`I|A{q_BmoF!f^G}XVeTbe1Wnzh%1g>j}>DqFf;Rp zz7>xIs12@Ke0gr+4-!pmFP84vCIaTjqFNg{V`5}Rdt~xE^I;Bxp4)|cs8=f)1YwHz zqI`G~s2~qqDV+h02b`PQpUE#^^Aq8l%y2|ByQeXSADg5*qMprEAE3WFg0Q39`O+i1 z!J@iV!`Y~C$wJ!5Z+j5$i<1`+@)tBG$JL=!*uk=2k;T<@{|s1$YL079FvK%mPhyHV zP8^KGZnp`(hVMZ;s=n~3r2y;LTwcJwoBW-(ndU-$03{RD zh+Qn$ja_Z^OuMf3Ub|JTY74s&Am*(n{J3~@#OJNYuEVVJd9*H%)oFoRBkySGm`hx! zT3tG|+aAkXcx-2Apy)h^BkOyFTWQVeZ%e2@;*0DtlG9I3Et=PKaPt&K zw?WI7S;P)TWED7aSH$3hL@Qde?H#tzo^<(o_sv_2ci<7M?F$|oCFWc?7@KBj-;N$P zB;q!8@bW-WJY9do&y|6~mEruZAVe$!?{)N9rZZxD-|oltkhW9~nR8bLBGXw<632!l z*TYQn^NnUy%Ds}$f^=yQ+BM-a5X4^GHF=%PDrRfm_uqC zh{sKwIu|O0&jWb27;wzg4w5uA@TO_j(1X?8E>5Zfma|Ly7Bklq|s z9)H`zoAGY3n-+&JPrT!>u^qg9Evx4y@GI4$n-Uk_5wttU1_t?6><>}cZ-U+&+~JE) zPlDbO_j;MoxdLzMd~Ew|1o^a5q_1R*JZ=#XXMzg?6Zy!^hop}qoLQlJ{(%!KYt`MK z8umEN@Z4w!2=q_oe=;QttPCQy3Nm4F@x>@v4sz_jo{4m*0r%J(w1cSo;D_hQtJs7W z><$QrmG^+<$4{d2bgGo&3-FV}avg9zI|Rr(k{wTyl3!M1q+a zD9W{pCd%il*j&Ft z5H$nENf>>k$;SONGW`qo6`&qKs*T z2^RS)pXk9b@(_Fw1bkb)-oqK|v}r$L!W&aXA>IpcdNZ_vWE#XO8X`#Yp1+?RshVcd zknG%rPd*4ECEI0wD#@d+3NbHKxl}n^Sgkx==Iu%}HvNliOqVBqG?P2va zQ;kRJ$J6j;+wP9cS za#m;#GUT!qAV%+rdWolk+)6kkz4@Yh5LXP+LSvo9_T+MmiaP-eq6_k;)i6_@WSJ zlT@wK$zqHu<83U2V*yJ|XJU4farT#pAA&@qu)(PO^8PxEmPD4;Txpio+2)#!9 z>&=i7*#tc0`?!==vk>s7V+PL#S1;PwSY?NIXN2=Gu89x(cToFm))7L;< z+bhAbVD*bD=}iU`+PU+SBobTQ%S!=VL!>q$rfWsaaV}Smz>lO9JXT#`CcH_mRCSf4%YQAw`$^yY z3Y*^Nzk_g$xn7a_NO(2Eb*I=^;4f!Ra#Oo~LLjlcjke*k*o$~U#0ZXOQ5@HQ&T46l z7504MUgZkz2gNP1QFN8Y?nSEnEai^Rgyvl}xZfMUV6QrJcXp;jKGqB=D*tj{8(_pV zqyB*DK$2lgYGejmJUW)*s_Cv65sFf&pb(Yz8oWgDtQ0~k^0-wdF|tj}MOXaN@ydF8 zNr={U?=;&Z?wr^VC+`)S2xl}QFagy;$mG=TUs7Vi2wws5zEke4hTa2)>O0U?$WYsZ z<8bN2bB_N4AWd%+kncgknZ&}bM~eDtj#C5uRkp21hWW5gxWvc6b*4+dn<{c?w9Rmf zIVZKsPl{W2vQAlYO3yh}-{Os=YBnL8?uN5(RqfQ=-1cOiUnJu>KcLA*tQK3FU`_bM zM^T28w;nAj5EdAXFi&Kk1Nnl2)D!M{@+D-}bIEe+Lc4{s;YJc-{F#``iS2uk;2!Zp zF9#myUmO!wCeJIoi^A+T^e~20c+c2C}XltaR!|U-HfDA=^xF97ev}$l6#oY z&-&T{egB)&aV$3_aVA51XGiU07$s9vubh_kQG?F$FycvS6|IO!6q zq^>9|3U^*!X_C~SxX&pqUkUjz%!j=VlXDo$!2VLH!rKj@61mDpSr~7B2yy{>X~_nc zRI+7g2V&k zd**H++P9dg!-AOs3;GM`(g<+GRV$+&DdMVpUxY9I1@uK28$az=6oaa+PutlO9?6#? zf-OsgT>^@8KK>ggkUQRPPgC7zjKFR5spqQb3ojCHzj^(UH~v+!y*`Smv)VpVoPwa6 zWG18WJaPKMi*F6Zdk*kU^`i~NNTfn3BkJniC`yN98L-Awd)Z&mY? zprBW$!qL-OL7h@O#kvYnLsfff@kDIegt~?{-*5A7JrA;#TmTe?jICJqhub-G@e??D zqiV#g{)M!kW1-4SDel7TO{;@*h2=_76g3NUD@|c*WO#>MfYq6_YVUP+&8e4|%4T`w zXzhmVNziAHazWO2qXcaOu@R1MrPP{t)`N)}-1&~mq=ZH=w=;-E$IOk=y$dOls{6sRR`I5>|X zpq~XYW4sd;J^6OwOf**J>a7u$S>WTFPRkjY;BfVgQst)u4aMLR1|6%)CB^18XCz+r ztkYQ}G43j~Q&1em(_EkMv0|WEiKu;z2zhb(L%$F&xWwzOmk;VLBYAZ8lOCziNoPw1 zv2BOyXA`A8z^WH!nXhKXM`t0;6D*-uGds3TYGrm8SPnJJOQ^fJU#}@aIy@MYWz**H zvkp?7I5PE{$$|~{-ZaFxr6ZolP^nL##mHOErB^AqJqn^hFA=)HWj!m3WDaHW$C)i^ z9@6G$SzB=>jbe>4kqr#sF7#K}W*Cg-5y6kun3u&0L7BpXF9=#7IN8FOjWrWwUBZiU zT_se3ih-GBKx+Uw0N|CwP3D@-C=5(9T#BH@M`F2!Goiqx+Js5xC92|Sy0%WWWp={$(am!#l~f^W_oz78HX<0X#7 zp)p1u~M*o9W@O8P{0Qkg@Wa# z2{Heb&oX^CQSZWSFBXKOfE|tsAm#^U-WkDnU;IowZ`Ok4!mwHwH=s|AqZ^YD4!5!@ zPxJj+Bd-q6w_YG`z_+r;S86zwXb+EO&qogOq8h-Ect5(M2+>(O7n7)^dP*ws_3U6v zVsh)sk^@*c>)3EML|0<-YROho{lz@Nd4;R9gL{9|64xVL`n!m$-Jjrx?-Bacp!=^5 z1^T^eB{_)Y<9)y{-4Rz@9_>;_7h;5D+@QcbF4Wv7hu)s0&==&6u)33 zHRj+&Woq-vDvjwJCYES@$C4{$?f$Ibi4G()UeN11rgjF+^;YE^5nYprYoJNoudNj= zm1pXSeG64dcWHObUetodRn1Fw|1nI$D9z}dVEYT0lQnsf_E1x2vBLql7NrHH!n&Sq z6lc*mvU=WS6=v9Lrl}&zRiu_6u;6g%_DU{9b+R z#YHqX7`m9eydf?KlKu6Sb%j$%_jmydig`B*TN`cZL-g!R)iE?+Q5oOqBFKhx z%MW>BC^(F_JuG(ayE(MT{S3eI{cKiwOtPwLc0XO*{*|(JOx;uQOfq@lp_^cZo=FZj z4#}@e@dJ>Bn%2`2_WPeSN7si^{U#H=7N4o%Dq3NdGybrZgEU$oSm$hC)uNDC_M9xc zGzwh5Sg?mpBIE8lT2XsqTt3j3?We8}3bzLBTQd639vyg^$0#1epq8snlDJP2(BF)K zSx30RM+{f+b$g{9usIL8H!hCO117Xgv}ttPJm9wVRjPk;ePH@zxv%j9k5`TzdXLeT zFgFX`V7cYIcBls5WN0Pf6SMBN+;CrQ(|EsFd*xtwr#$R{Z9FP`OWtyNsq#mCgZ7+P z^Yn$haBJ)r96{ZJd8vlMl?IBxrgh=fdq_NF!1{jARCVz>jNdC)H^wfy?R94#MPdUjcYX>#wEx+LB#P-#4S-%YH>t-j+w zOFTI8gX$ard6fAh&g=u&56%3^-6E2tpk*wx3HSCQ+t7+*iOs zPk5ysqE}i*cQocFvA68xHfL|iX(C4h*67@3|5Qwle(8wT&!&{8*{f%0(5gH+m>$tq zp;AqrP7?XTEooYG1Dzfxc>W%*CyL16q|fQ0_jp%%Bk^k!i#Nbi(N9&T>#M{gez_Ws zYK=l}adalV(nH}I_!hNeb;tQFk3BHX7N}}R8%pek^E`X}%ou=cx8InPU1EE0|Hen- zyw8MoJqB5=)Z%JXlrdTXAE)eqLAdVE-=>wGHrkRet}>3Yu^lt$Kzu%$3#(ioY}@Gu zjk3BZuQH&~7H+C*uX^4}F*|P89JX;Hg2U!pt>rDi(n(Qe-c}tzb0#6_ItoR0->LSt zR~UT<-|@TO%O`M+_e_J4wx7^)5_%%u+J=yF_S#2Xd?C;Ss3N7KY^#-vx+|;bJX&8r zD?|MetfhdC;^2WG`7MCgs>TKKN=^=!x&Q~BzmQio_^l~LboTNT=I zC5pme^P@ER``p$2md9>4!K#vV-Fc1an7pl>_|&>aqP}+zqR?+~Z;f2^`a+-!Te%V? z;H2SbF>jP^GE(R1@%C==XQ@J=G9lKX+Z<@5}PO(EYkJh=GCv#)Nj{DkWJM2}F&oAZ6xu8&g7pn1ps2U5srwQ7CAK zN&*~@t{`31lUf`O;2w^)M3B@o)_mbRu{-`PrfNpF!R^q>yTR&ETS7^-b2*{-tZAZz zw@q5x9B5V8Qd7dZ!Ai$9hk%Q!wqbE1F1c96&zwBBaRW}(^axoPpN^4Aw}&a5dMe+*Gomky_l^54*rzXro$ z>LL)U5Ry>~FJi=*{JDc)_**c)-&faPz`6v`YU3HQa}pLtb5K)u%K+BOqXP0)rj5Au$zB zW1?vr?mDv7Fsxtsr+S6ucp2l#(4dnr9sD*v+@*>g#M4b|U?~s93>Pg{{a5|rm2xfI z`>E}?9S@|IoUX{Q1zjm5YJT|3S>&09D}|2~BiMo=z4YEjXlWh)V&qs;*C{`UMxp$9 zX)QB?G$fPD6z5_pNs>Jeh{^&U^)Wbr?2D6-q?)`*1k@!UvwQgl8eG$r+)NnFoT)L6 zg7lEh+E6J17krfYJCSjWzm67hEth24pomhz71|Qodn#oAILN)*Vwu2qpJirG)4Wnv}9GWOFrQg%Je+gNrPl8mw7ykE8{ z=|B4+uwC&bpp%eFcRU6{mxRV32VeH8XxX>v$du<$(DfinaaWxP<+Y97Z#n#U~V zVEu-GoPD=9$}P;xv+S~Ob#mmi$JQmE;Iz4(){y*9pFyW-jjgdk#oG$fl4o9E8bo|L zWjo4l%n51@Kz-n%zeSCD`uB?T%FVk+KBI}=ve zvlcS#wt`U6wrJo}6I6Rwb=1GzZfwE=I&Ne@p7*pH84XShXYJRgvK)UjQL%R9Zbm(m zxzTQsLTON$WO7vM)*vl%Pc0JH7WhP;$z@j=y#avW4X8iqy6mEYr@-}PW?H)xfP6fQ z&tI$F{NNct4rRMSHhaelo<5kTYq+(?pY)Ieh8*sa83EQfMrFupMM@nfEV@EmdHUv9 z35uzIrIuo4#WnF^_jcpC@uNNaYTQ~uZWOE6P@LFT^1@$o&q+9Qr8YR+ObBkpP9=F+$s5+B!mX2~T zAuQ6RenX?O{IlLMl1%)OK{S7oL}X%;!XUxU~xJN8xk z`xywS*naF(J#?vOpB(K=o~lE;m$zhgPWDB@=p#dQIW>xe_p1OLoWInJRKbEuoncf; zmS1!u-ycc1qWnDg5Nk2D)BY%jmOwCLC+Ny>`f&UxFowIsHnOXfR^S;&F(KXd{ODlm z$6#1ccqt-HIH9)|@fHnrKudu!6B$_R{fbCIkSIb#aUN|3RM>zuO>dpMbROZ`^hvS@ z$FU-;e4W}!ubzKrU@R*dW*($tFZ>}dd*4_mv)#O>X{U@zSzQt*83l9mI zI$8O<5AIDx`wo0}f2fsPC_l>ONx_`E7kdXu{YIZbp1$(^oBAH({T~&oQ&1{X951QW zmhHUxd)t%GQ9#ak5fTjk-cahWC;>^Rg7(`TVlvy0W@Y!Jc%QL3Ozu# zDPIqBCy&T2PWBj+d-JA-pxZlM=9ja2ce|3B(^VCF+a*MMp`(rH>Rt6W1$;r{n1(VK zLs>UtkT43LR2G$AOYHVailiqk7naz2yZGLo*xQs!T9VN5Q>eE(w zw$4&)&6xIV$IO^>1N-jrEUg>O8G4^@y+-hQv6@OmF@gy^nL_n1P1-Rtyy$Bl;|VcV zF=p*&41-qI5gG9UhKmmnjs932!6hceXa#-qfK;3d*a{)BrwNFeKU|ge?N!;zk+kB! zMD_uHJR#%b54c2tr~uGPLTRLg$`fupo}cRJeTwK;~}A>(Acy4k-Xk&Aa1&eWYS1ULWUj@fhBiWY$pdfy+F z@G{OG{*v*mYtH3OdUjwEr6%_ZPZ3P{@rfbNPQG!BZ7lRyC^xlMpWH`@YRar`tr}d> z#wz87t?#2FsH-jM6m{U=gp6WPrZ%*w0bFm(T#7m#v^;f%Z!kCeB5oiF`W33W5Srdt zdU?YeOdPG@98H7NpI{(uN{FJdu14r(URPH^F6tOpXuhU7T9a{3G3_#Ldfx_nT(Hec zo<1dyhsVsTw;ZkVcJ_0-h-T3G1W@q)_Q30LNv)W?FbMH+XJ* zy=$@39Op|kZv`Rt>X`zg&at(?PO^I=X8d9&myFEx#S`dYTg1W+iE?vt#b47QwoHI9 zNP+|3WjtXo{u}VG(lLUaW0&@yD|O?4TS4dfJI`HC-^q;M(b3r2;7|FONXphw-%7~* z&;2!X17|05+kZOpQ3~3!Nb>O94b&ZSs%p)TK)n3m=4eiblVtSx@KNFgBY_xV6ts;NF;GcGxMP8OKV^h6LmSb2E#Qnw ze!6Mnz7>lE9u{AgQ~8u2zM8CYD5US8dMDX-5iMlgpE9m*s+Lh~A#P1er*rF}GHV3h z=`STo?kIXw8I<`W0^*@mB1$}pj60R{aJ7>C2m=oghKyxMbFNq#EVLgP0cH3q7H z%0?L93-z6|+jiN|@v>ix?tRBU(v-4RV`}cQH*fp|)vd3)8i9hJ3hkuh^8dz{F5-~_ zUUr1T3cP%cCaTooM8dj|4*M=e6flH0&8ve32Q)0dyisl))XkZ7Wg~N}6y`+Qi2l+e zUd#F!nJp{#KIjbQdI`%oZ`?h=5G^kZ_uN`<(`3;a!~EMsWV|j-o>c?x#;zR2ktiB! z);5rrHl?GPtr6-o!tYd|uK;Vbsp4P{v_4??=^a>>U4_aUXPWQ$FPLE4PK$T^3Gkf$ zHo&9$U&G`d(Os6xt1r?sg14n)G8HNyWa^q8#nf0lbr4A-Fi;q6t-`pAx1T*$eKM*$ z|CX|gDrk#&1}>5H+`EjV$9Bm)Njw&7-ZR{1!CJTaXuP!$Pcg69`{w5BRHysB$(tWUes@@6aM69kb|Lx$%BRY^-o6bjH#0!7b;5~{6J+jKxU!Kmi# zndh@+?}WKSRY2gZ?Q`{(Uj|kb1%VWmRryOH0T)f3cKtG4oIF=F7RaRnH0Rc_&372={_3lRNsr95%ZO{IX{p@YJ^EI%+gvvKes5cY+PE@unghjdY5#9A!G z70u6}?zmd?v+{`vCu-53_v5@z)X{oPC@P)iA3jK$`r zSA2a7&!^zmUiZ82R2=1cumBQwOJUPz5Ay`RLfY(EiwKkrx%@YN^^XuET;tE zmr-6~I7j!R!KrHu5CWGSChO6deaLWa*9LLJbcAJsFd%Dy>a!>J`N)Z&oiU4OEP-!Ti^_!p}O?7`}i7Lsf$-gBkuY*`Zb z7=!nTT;5z$_5$=J=Ko+Cp|Q0J=%oFr>hBgnL3!tvFoLNhf#D0O=X^h+x08iB;@8pXdRHxX}6R4k@i6%vmsQwu^5z zk1ip`#^N)^#Lg#HOW3sPI33xqFB4#bOPVnY%d6prwxf;Y-w9{ky4{O6&94Ra8VN@K zb-lY;&`HtxW@sF!doT5T$2&lIvJpbKGMuDAFM#!QPXW87>}=Q4J3JeXlwHys?!1^#37q_k?N@+u&Ns20pEoBeZC*np;i;M{2C0Z4_br2gsh6eL z#8`#sn41+$iD?^GL%5?cbRcaa-Nx0vE(D=*WY%rXy3B%gNz0l?#noGJGP728RMY#q z=2&aJf@DcR?QbMmN)ItUe+VM_U!ryqA@1VVt$^*xYt~-qvW!J4Tp<-3>jT=7Zow5M z8mSKp0v4b%a8bxFr>3MwZHSWD73D@+$5?nZAqGM#>H@`)mIeC#->B)P8T$zh-Pxnc z8)~Zx?TWF4(YfKuF3WN_ckpCe5;x4V4AA3(i$pm|78{%!q?|~*eH0f=?j6i)n~Hso zmTo>vqEtB)`%hP55INf7HM@taH)v`Fw40Ayc*R!T?O{ziUpYmP)AH`euTK!zg9*6Z z!>M=$3pd0!&TzU=hc_@@^Yd3eUQpX4-33}b{?~5t5lgW=ldJ@dUAH%`l5US1y_`40 zs(X`Qk}vvMDYYq+@Rm+~IyCX;iD~pMgq^KY)T*aBz@DYEB={PxA>)mI6tM*sx-DmGQHEaHwRrAmNjO!ZLHO4b;;5mf@zzlPhkP($JeZGE7 z?^XN}Gf_feGoG~BjUgVa*)O`>lX=$BSR2)uD<9 z>o^|nb1^oVDhQbfW>>!;8-7<}nL6L^V*4pB=>wwW+RXAeRvKED(n1;R`A6v$6gy0I(;Vf?!4;&sgn7F%LpM}6PQ?0%2Z@b{It<(G1CZ|>913E0nR2r^Pa*Bp z@tFGi*CQ~@Yc-?{cwu1 zsilf=k^+Qs>&WZG(3WDixisHpR>`+ihiRwkL(3T|=xsoNP*@XX3BU8hr57l3k;pni zI``=3Nl4xh4oDj<%>Q1zYXHr%Xg_xrK3Nq?vKX3|^Hb(Bj+lONTz>4yhU-UdXt2>j z<>S4NB&!iE+ao{0Tx^N*^|EZU;0kJkx@zh}S^P{ieQjGl468CbC`SWnwLRYYiStXm zOxt~Rb3D{dz=nHMcY)#r^kF8|q8KZHVb9FCX2m^X*(|L9FZg!5a7((!J8%MjT$#Fs)M1Pb zq6hBGp%O1A+&%2>l0mpaIzbo&jc^!oN^3zxap3V2dNj3x<=TwZ&0eKX5PIso9j1;e zwUg+C&}FJ`k(M|%%}p=6RPUq4sT3-Y;k-<68ciZ~_j|bt>&9ZLHNVrp#+pk}XvM{8 z`?k}o-!if>hVlCP9j%&WI2V`5SW)BCeR5>MQhF)po=p~AYN%cNa_BbV6EEh_kk^@a zD>4&>uCGCUmyA-c)%DIcF4R6!>?6T~Mj_m{Hpq`*(wj>foHL;;%;?(((YOxGt)Bhx zuS+K{{CUsaC++%}S6~CJ=|vr(iIs-je)e9uJEU8ZJAz)w166q)R^2XI?@E2vUQ!R% zn@dxS!JcOimXkWJBz8Y?2JKQr>`~SmE2F2SL38$SyR1^yqj8_mkBp)o$@+3BQ~Mid z9U$XVqxX3P=XCKj0*W>}L0~Em`(vG<>srF8+*kPrw z20{z(=^w+ybdGe~Oo_i|hYJ@kZl*(9sHw#Chi&OIc?w`nBODp?ia$uF%Hs(X>xm?j zqZQ`Ybf@g#wli`!-al~3GWiE$K+LCe=Ndi!#CVjzUZ z!sD2O*;d28zkl))m)YN7HDi^z5IuNo3^w(zy8 zszJG#mp#Cj)Q@E@r-=NP2FVxxEAeOI2e=|KshybNB6HgE^(r>HD{*}S}mO>LuRGJT{*tfTzw_#+er-0${}%YPe@CMJ1Ng#j#)i)SnY@ss3gL;g zg2D~#Kpdfu#G;q1qz_TwSz1VJT(b3zby$Vk&;Y#1(A)|xj`_?i5YQ;TR%jice5E;0 zYHg;`zS5{S*9xI6o^j>rE8Ua*XhIw{_-*&@(R|C(am8__>+Ws&Q^ymy*X4~hR2b5r zm^p3sw}yv=tdyncy_Ui7{BQS732et~Z_@{-IhHDXAV`(Wlay<#hb>%H%WDi+K$862nA@BDtM#UCKMu+kM`!JHyWSi?&)A7_ z3{cyNG%a~nnH_!+;g&JxEMAmh-Z}rC!o7>OVzW&PoMyTA_g{hqXG)SLraA^OP**<7 zjWbr7z!o2n3hnx7A=2O=WL;`@9N{vQIM@&|G-ljrPvIuJHYtss0Er0fT5cMXNUf1B z7FAwBDixt0X7C3S)mPe5g`YtME23wAnbU)+AtV}z+e8G;0BP=bI;?(#|Ep!vVfDbK zvx+|CKF>yt0hWQ3drchU#XBU+HiuG*V^snFAPUp-5<#R&BUAzoB!aZ+e*KIxa26V}s6?nBK(U-7REa573wg-jqCg>H8~>O{ z*C0JL-?X-k_y%hpUFL?I>0WV{oV`Nb)nZbJG01R~AG>flIJf)3O*oB2i8~;!P?Wo_ z0|QEB*fifiL6E6%>tlAYHm2cjTFE@*<);#>689Z6S#BySQ@VTMhf9vYQyLeDg1*F} zjq>i1*x>5|CGKN{l9br3kB0EHY|k4{%^t7-uhjd#NVipUZa=EUuE5kS1_~qYX?>hJ z$}!jc9$O$>J&wnu0SgfYods^z?J4X;X7c77Me0kS-dO_VUQ39T(Kv(Y#s}Qqz-0AH z^?WRL(4RzpkD+T5FG_0NyPq-a-B7A5LHOCqwObRJi&oRi(<;OuIN7SV5PeHU$<@Zh zPozEV`dYmu0Z&Tqd>t>8JVde9#Pt+l95iHe$4Xwfy1AhI zDM4XJ;bBTTvRFtW>E+GzkN)9k!hA5z;xUOL2 zq4}zn-DP{qc^i|Y%rvi|^5k-*8;JZ~9a;>-+q_EOX+p1Wz;>i7c}M6Nv`^NY&{J-> z`(mzDJDM}QPu5i44**2Qbo(XzZ-ZDu%6vm8w@DUarqXj41VqP~ zs&4Y8F^Waik3y1fQo`bVUH;b=!^QrWb)3Gl=QVKr+6sxc=ygauUG|cm?|X=;Q)kQ8 zM(xrICifa2p``I7>g2R~?a{hmw@{!NS5`VhH8+;cV(F>B94M*S;5#O`YzZH1Z%yD? zZ61w(M`#aS-*~Fj;x|J!KM|^o;MI#Xkh0ULJcA?o4u~f%Z^16ViA27FxU5GM*rKq( z7cS~MrZ=f>_OWx8j#-Q3%!aEU2hVuTu(7`TQk-Bi6*!<}0WQi;_FpO;fhpL4`DcWp zGOw9vx0N~6#}lz(r+dxIGZM3ah-8qrqMmeRh%{z@dbUD2w15*_4P?I~UZr^anP}DB zU9CCrNiy9I3~d#&!$DX9e?A});BjBtQ7oGAyoI$8YQrkLBIH@2;lt4E^)|d6Jwj}z z&2_E}Y;H#6I4<10d_&P0{4|EUacwFHauvrjAnAm6yeR#}f}Rk27CN)vhgRqEyPMMS7zvunj2?`f;%?alsJ+-K+IzjJx>h8 zu~m_y$!J5RWAh|C<6+uiCNsOKu)E72M3xKK(a9Okw3e_*O&}7llNV!=P87VM2DkAk zci!YXS2&=P0}Hx|wwSc9JP%m8dMJA*q&VFB0yMI@5vWoAGraygwn){R+Cj6B1a2Px z5)u(K5{+;z2n*_XD!+Auv#LJEM)(~Hx{$Yb^ldQmcYF2zNH1V30*)CN_|1$v2|`LnFUT$%-tO0Eg|c5$BB~yDfzS zcOXJ$wpzVK0MfTjBJ0b$r#_OvAJ3WRt+YOLlJPYMx~qp>^$$$h#bc|`g0pF-Ao43? z>*A+8lx>}L{p(Tni2Vvk)dtzg$hUKjSjXRagj)$h#8=KV>5s)J4vGtRn5kP|AXIz! zPgbbVxW{2o4s-UM;c#We8P&mPN|DW7_uLF!a|^0S=wr6Esx9Z$2|c1?GaupU6$tb| zY_KU`(_29O_%k(;>^|6*pZURH3`@%EuKS;Ns z1lujmf;r{qAN&Q0&m{wJSZ8MeE7RM5+Sq;ul_ z`+ADrd_Um+G37js6tKsArNB}n{p*zTUxQr>3@wA;{EUbjNjlNd6$Mx zg0|MyU)v`sa~tEY5$en7^PkC=S<2@!nEdG6L=h(vT__0F=S8Y&eM=hal#7eM(o^Lu z2?^;05&|CNliYrq6gUv;|i!(W{0N)LWd*@{2q*u)}u*> z7MQgk6t9OqqXMln?zoMAJcc zMKaof_Up})q#DzdF?w^%tTI7STI^@8=Wk#enR*)&%8yje>+tKvUYbW8UAPg55xb70 zEn5&Ba~NmOJlgI#iS8W3-@N%>V!#z-ZRwfPO1)dQdQkaHsiqG|~we2ALqG7Ruup(DqSOft2RFg_X%3w?6VqvV1uzX_@F(diNVp z4{I|}35=11u$;?|JFBEE*gb;T`dy+8gWJ9~pNsecrO`t#V9jW-6mnfO@ff9od}b(3s4>p0i30gbGIv~1@a^F2kl7YO;DxmF3? zWi-RoXhzRJV0&XE@ACc?+@6?)LQ2XNm4KfalMtsc%4!Fn0rl zpHTrHwR>t>7W?t!Yc{*-^xN%9P0cs0kr=`?bQ5T*oOo&VRRu+1chM!qj%2I!@+1XF z4GWJ=7ix9;Wa@xoZ0RP`NCWw0*8247Y4jIZ>GEW7zuoCFXl6xIvz$ezsWgKdVMBH> z{o!A7f;R-@eK9Vj7R40xx)T<2$?F2E<>Jy3F;;=Yt}WE59J!1WN367 zA^6pu_zLoZIf*x031CcwotS{L8bJE(<_F%j_KJ2P_IusaZXwN$&^t716W{M6X2r_~ zaiMwdISX7Y&Qi&Uh0upS3TyEIXNDICQlT5fHXC`aji-c{U(J@qh-mWl-uMN|T&435 z5)a1dvB|oe%b2mefc=Vpm0C%IUYYh7HI*;3UdgNIz}R##(#{(_>82|zB0L*1i4B5j-xi9O4x10rs_J6*gdRBX=@VJ+==sWb&_Qc6tSOowM{BX@(zawtjl zdU!F4OYw2@Tk1L^%~JCwb|e#3CC>srRHQ*(N%!7$Mu_sKh@|*XtR>)BmWw!;8-mq7 zBBnbjwx8Kyv|hd*`5}84flTHR1Y@@uqjG`UG+jN_YK&RYTt7DVwfEDXDW4U+iO{>K zw1hr{_XE*S*K9TzzUlJH2rh^hUm2v7_XjwTuYap|>zeEDY$HOq3X4Tz^X}E9z)x4F zs+T?Ed+Hj<#jY-`Va~fT2C$=qFT-5q$@p9~0{G&eeL~tiIAHXA!f6C(rAlS^)&k<- zXU|ZVs}XQ>s5iONo~t!XXZgtaP$Iau;JT%h)>}v54yut~pykaNye4axEK#5@?TSsQ zE;Jvf9I$GVb|S`7$pG)4vgo9NXsKr?u=F!GnA%VS2z$@Z(!MR9?EPcAqi5ft)Iz6sNl`%kj+_H-X`R<>BFrBW=fSlD|{`D%@Rcbu2?%>t7i34k?Ujb)2@J-`j#4 zLK<69qcUuniIan-$A1+fR=?@+thwDIXtF1Tks@Br-xY zfB+zblrR(ke`U;6U~-;p1Kg8Lh6v~LjW@9l2P6s+?$2!ZRPX`(ZkRGe7~q(4&gEi<$ch`5kQ?*1=GSqkeV z{SA1EaW_A!t{@^UY2D^YO0(H@+kFVzZaAh0_`A`f(}G~EP~?B|%gtxu&g%^x{EYSz zk+T;_c@d;+n@$<>V%P=nk36?L!}?*=vK4>nJSm+1%a}9UlmTJTrfX4{Lb7smNQn@T zw9p2%(Zjl^bWGo1;DuMHN(djsEm)P8mEC2sL@KyPjwD@d%QnZ$ zMJ3cnn!_!iP{MzWk%PI&D?m?C(y2d|2VChluN^yHya(b`h>~GkI1y;}O_E57zOs!{ zt2C@M$^PR2U#(dZmA-sNreB@z-yb0Bf7j*yONhZG=onhx>t4)RB`r6&TP$n zgmN*)eCqvgriBO-abHQ8ECN0bw?z5Bxpx z=jF@?zFdVn?@gD5egM4o$m`}lV(CWrOKKq(sv*`mNcHcvw&Xryfw<{ch{O&qc#WCTXX6=#{MV@q#iHYba!OUY+MGeNTjP%Fj!WgM&`&RlI^=AWTOqy-o zHo9YFt!gQ*p7{Fl86>#-JLZo(b^O`LdFK~OsZBRR@6P?ad^Ujbqm_j^XycM4ZHFyg ziUbIFW#2tj`65~#2V!4z7DM8Z;fG0|APaQ{a2VNYpNotB7eZ5kp+tPDz&Lqs0j%Y4tA*URpcfi z_M(FD=fRGdqf430j}1z`O0I=;tLu81bwJXdYiN7_&a-?ly|-j*+=--XGvCq#32Gh(=|qj5F?kmihk{%M&$}udW5)DHK zF_>}5R8&&API}o0osZJRL3n~>76nUZ&L&iy^s>PMnNcYZ|9*1$v-bzbT3rpWsJ+y{ zPrg>5Zlery96Um?lc6L|)}&{992{_$J&=4%nRp9BAC6!IB=A&=tF>r8S*O-=!G(_( zwXbX_rGZgeiK*&n5E;f=k{ktyA1(;x_kiMEt0*gpp_4&(twlS2e5C?NoD{n>X2AT# zY@Zp?#!b1zNq96MQqeO*M1MMBin5v#RH52&Xd~DO6-BZLnA6xO1$sou(YJ1Dlc{WF zVa%2DyYm`V#81jP@70IJ;DX@y*iUt$MLm)ByAD$eUuji|5{ptFYq(q)mE(5bOpxjM z^Q`AHWq44SG3`_LxC9fwR)XRVIp=B%<(-lOC3jI#bb@dK(*vjom!=t|#<@dZql%>O z15y^{4tQoeW9Lu%G&V$90x6F)xN6y_oIn;!Q zs)8jT$;&;u%Y>=T3hg34A-+Y*na=|glcStr5D;&5*t5*DmD~x;zQAV5{}Ya`?RRGa zT*t9@$a~!co;pD^!J5bo?lDOWFx%)Y=-fJ+PDGc0>;=q=s?P4aHForSB+)v0WY2JH z?*`O;RHum6j%#LG)Vu#ciO#+jRC3!>T(9fr+XE7T2B7Z|0nR5jw@WG)kDDzTJ=o4~ zUpeyt7}_nd`t}j9BKqryOha{34erm)RmST)_9Aw)@ zHbiyg5n&E{_CQR@h<}34d7WM{s{%5wdty1l+KX8*?+-YkNK2Be*6&jc>@{Fd;Ps|| z26LqdI3#9le?;}risDq$K5G3yoqK}C^@-8z^wj%tdgw-6@F#Ju{Sg7+y)L?)U$ez> zoOaP$UFZ?y5BiFycir*pnaAaY+|%1%8&|(@VB)zweR%?IidwJyK5J!STzw&2RFx zZV@qeaCB01Hu#U9|1#=Msc8Pgz5P*4Lrp!Q+~(G!OiNR{qa7|r^H?FC6gVhkk3y7=uW#Sh;&>78bZ}aK*C#NH$9rX@M3f{nckYI+5QG?Aj1DM)@~z_ zw!UAD@gedTlePB*%4+55naJ8ak_;))#S;4ji!LOqY5VRI){GMwHR~}6t4g>5C_#U# ztYC!tjKjrKvRy=GAsJVK++~$|+s!w9z3H4G^mACv=EErXNSmH7qN}%PKcN|8%9=i)qS5+$L zu&ya~HW%RMVJi4T^pv?>mw*Gf<)-7gf#Qj|e#w2|v4#t!%Jk{&xlf;$_?jW*n!Pyx zkG$<18kiLOAUPuFfyu-EfWX%4jYnjBYc~~*9JEz6oa)_R|8wjZA|RNrAp%}14L7fW zi7A5Wym*K+V8pkqqO-X#3ft{0qs?KVt^)?kS>AicmeO&q+~J~ zp0YJ_P~_a8j= zsAs~G=8F=M{4GZL{|B__UorX@MRNQLn?*_gym4aW(~+i13knnk1P=khoC-ViMZk+x zLW(l}oAg1H`dU+Fv**;qw|ANDSRs>cGqL!Yw^`; zv;{E&8CNJcc)GHzTYM}f&NPw<6j{C3gaeelU#y!M)w-utYEHOCCJo|Vgp7K6C_$14 zqIrLUB0bsgz^D%V%fbo2f9#yb#CntTX?55Xy|Kps&Xek*4_r=KDZ z+`TQuv|$l}MWLzA5Ay6Cvsa^7xvwXpy?`w(6vx4XJ zWuf1bVSb#U8{xlY4+wlZ$9jjPk)X_;NFMqdgq>m&W=!KtP+6NL57`AMljW+es zzqjUjgz;V*kktJI?!NOg^s_)ph45>4UDA!Vo0hn>KZ+h-3=?Y3*R=#!fOX zP$Y~+14$f66ix?UWB_6r#fMcC^~X4R-<&OD1CSDNuX~y^YwJ>sW0j`T<2+3F9>cLo z#!j57$ll2K9(%$4>eA7(>FJX5e)pR5&EZK!IMQzOfik#FU*o*LGz~7u(8}XzIQRy- z!U7AlMTIe|DgQFmc%cHy_9^{o`eD%ja_L>ckU6$O4*U**o5uR7`FzqkU8k4gxtI=o z^P^oGFPm5jwZMI{;nH}$?p@uV8FT4r=|#GziKXK07bHJLtK}X%I0TON$uj(iJ`SY^ zc$b2CoxCQ>7LH@nxcdW&_C#fMYBtTxcg46dL{vf%EFCZ~eErMvZq&Z%Lhumnkn^4A zsx$ay(FnN7kYah}tZ@0?-0Niroa~13`?hVi6`ndno`G+E8;$<6^gsE-K3)TxyoJ4M zb6pj5=I8^FD5H@`^V#Qb2^0cx7wUz&cruA5g>6>qR5)O^t1(-qqP&1g=qvY#s&{bx zq8Hc%LsbK1*%n|Y=FfojpE;w~)G0-X4i*K3{o|J7`krhIOd*c*$y{WIKz2n2*EXEH zT{oml3Th5k*vkswuFXdGDlcLj15Nec5pFfZ*0?XHaF_lVuiB%Pv&p7z)%38}%$Gup zVTa~C8=cw%6BKn_|4E?bPNW4PT7}jZQLhDJhvf4z;~L)506IE0 zX!tWXX(QOQPRj-p80QG79t8T2^az4Zp2hOHziQlvT!|H)jv{Ixodabzv6lBj)6WRB z{)Kg@$~~(7$-az?lw$4@L%I&DI0Lo)PEJJziWP33a3azb?jyXt1v0N>2kxwA6b%l> zZqRpAo)Npi&loWbjFWtEV)783BbeIAhqyuc+~>i7aQ8shIXt)bjCWT6$~ro^>99G} z2XfmT0(|l!)XJb^E!#3z4oEGIsL(xd; zYX1`1I(cG|u#4R4T&C|m*9KB1`UzKvho5R@1eYtUL9B72{i(ir&ls8g!pD ztR|25xGaF!4z5M+U@@lQf(12?xGy`!|3E}7pI$k`jOIFjiDr{tqf0va&3pOn6Pu)% z@xtG2zjYuJXrV)DUrIF*y<1O1<$#54kZ#2;=X51J^F#0nZ0(;S$OZDt_U2bx{RZ=Q zMMdd$fH|!s{ zXq#l;{`xfV`gp&C>A`WrQU?d{!Ey5(1u*VLJt>i27aZ-^&2IIk=zP5p+{$q(K?2(b z8?9h)kvj9SF!Dr zoyF}?V|9;6abHxWk2cEvGs$-}Pg}D+ZzgkaN&$Snp%;5m%zh1E#?Wac-}x?BYlGN#U#Mek*}kek#I9XaHt?mz3*fDrRTQ#&#~xyeqJk1QJ~E$7qsw6 z?sV;|?*=-{M<1+hXoj?@-$y+(^BJ1H~wQ9G8C0#^aEAyhDduNX@haoa=PuPp zYsGv8UBfQaRHgBgLjmP^eh>fLMeh{8ic)?xz?#3kX-D#Z{;W#cd_`9OMFIaJg-=t`_3*!YDgtNQ2+QUEAJB9M{~AvT$H`E)IKmCR21H532+ata8_i_MR@ z2Xj<3w<`isF~Ah$W{|9;51ub*f4#9ziKrOR&jM{x7I_7()O@`F*5o$KtZ?fxU~g`t zUovNEVKYn$U~VX8eR)qb`7;D8pn*Pp$(otYTqL)5KH$lUS-jf}PGBjy$weoceAcPp z&5ZYB$r&P$MN{0H0AxCe4Qmd3T%M*5d4i%#!nmBCN-WU-4m4Tjxn-%j3HagwTxCZ9 z)j5vO-C7%s%D!&UfO>bi2oXiCw<-w{vVTK^rVbv#W=WjdADJy8$khnU!`ZWCIU`># zyjc^1W~pcu>@lDZ{zr6gv%)2X4n27~Ve+cQqcND%0?IFSP4sH#yIaXXYAq^z3|cg` z`I3$m%jra>e2W-=DiD@84T!cb%||k)nPmEE09NC%@PS_OLhkrX*U!cgD*;;&gIaA(DyVT4QD+q_xu z>r`tg{hiGY&DvD-)B*h+YEd+Zn)WylQl}<4>(_NlsKXCRV;a)Rcw!wtelM2_rWX`j zTh5A|i6=2BA(iMCnj_fob@*eA;V?oa4Z1kRBGaU07O70fb6-qmA$Hg$ps@^ka1=RO zTbE_2#)1bndC3VuK@e!Sftxq4=Uux}fDxXE#Q5_x=E1h>T5`DPHz zbH<_OjWx$wy7=%0!mo*qH*7N4tySm+R0~(rbus`7;+wGh;C0O%x~fEMkt!eV>U$`i z5>Q(o z=t$gPjgGh0&I7KY#k50V7DJRX<%^X z>6+ebc9efB3@eE2Tr){;?_w`vhgF>`-GDY(YkR{9RH(MiCnyRtd!LxXJ75z+?2 zGi@m^+2hKJ5sB1@Xi@s_@p_Kwbc<*LQ_`mr^Y%j}(sV_$`J(?_FWP)4NW*BIL~sR>t6 zM;qTJZ~GoY36&{h-Pf}L#y2UtR}>ZaI%A6VkU>vG4~}9^i$5WP2Tj?Cc}5oQxe2=q z8BeLa$hwCg_psjZyC2+?yX4*hJ58Wu^w9}}7X*+i5Rjqu5^@GzXiw#SUir1G1`jY% zOL=GE_ENYxhcyUrEt9XlMNP6kx6h&%6^u3@zB8KUCAa18T(R2J`%JjWZ z!{7cXaEW+Qu*iJPu+m>QqW}Lo$4Z+!I)0JNzZ&_M%=|B1yejFRM04bGAvu{=lNPd+ zJRI^DRQ(?FcVUD+bgEcAi@o(msqys9RTCG#)TjI!9~3-dc`>gW;HSJuQvH~d`MQs86R$|SKXHh zqS9Qy)u;T`>>a!$LuaE2keJV%;8g)tr&Nnc;EkvA-RanHXsy)D@XN0a>h}z2j81R; zsUNJf&g&rKpuD0WD@=dDrPHdBoK42WoBU|nMo17o(5^;M|dB4?|FsAGVrSyWcI`+FVw^vTVC`y}f(BwJl zrw3Sp151^9=}B})6@H*i4-dIN_o^br+BkcLa^H56|^2XsT0dESw2 zMX>(KqNl=x2K5=zIKg}2JpGAZu{I_IO}0$EQ5P{4zol**PCt3F4`GX}2@vr8#Y)~J zKb)gJeHcFnR@4SSh%b;c%J`l=W*40UPjF#q{<}ywv-=vHRFmDjv)NtmC zQx9qm)d%0zH&qG7AFa3VAU1S^(n8VFTC~Hb+HjYMjX8r#&_0MzlNR*mnLH5hi}`@{ zK$8qiDDvS_(L9_2vHgzEQ${DYSE;DqB!g*jhJghE&=LTnbgl&Xepo<*uRtV{2wDHN z)l;Kg$TA>Y|K8Lc&LjWGj<+bp4Hiye_@BfU(y#nF{fpR&|Ltbye?e^j0}8JC4#xi% zv29ZR%8%hk=3ZDvO-@1u8KmQ@6p%E|dlHuy#H1&MiC<*$YdLkHmR#F3ae;bKd;@*i z2_VfELG=B}JMLCO-6UQy^>RDE%K4b>c%9ki`f~Z2Qu8hO7C#t%Aeg8E%+}6P7Twtg z-)dj(w}_zFK&86KR@q9MHicUAucLVshUdmz_2@32(V`y3`&Kf8Q2I)+!n0mR=rrDU zXvv^$ho;yh*kNqJ#r1}b0|i|xRUF6;lhx$M*uG3SNLUTC@|htC z-=fsw^F%$qqz4%QdjBrS+ov}Qv!z00E+JWas>p?z@=t!WWU3K*?Z(0meTuTOC7OTx zU|kFLE0bLZ+WGcL$u4E}5dB0g`h|uwv3=H6f+{5z9oLv-=Q45+n~V4WwgO=CabjM% zBAN+RjM65(-}>Q2V#i1Na@a0`08g&y;W#@sBiX6Tpy8r}*+{RnyGUT`?XeHSqo#|J z^ww~c;ou|iyzpErDtlVU=`8N7JSu>4M z_pr9=tX0edVn9B}YFO2y(88j#S{w%E8vVOpAboK*27a7e4Ekjt0)hIX99*1oE;vex z7#%jhY=bPijA=Ce@9rRO(Vl_vnd00!^TAc<+wVvRM9{;hP*rqEL_(RzfK$er_^SN; z)1a8vo8~Dr5?;0X0J62Cusw$A*c^Sx1)dom`-)Pl7hsW4i(r*^Mw`z5K>!2ixB_mu z*Ddqjh}zceRFdmuX1akM1$3>G=#~|y?eYv(e-`Qy?bRHIq=fMaN~fB zUa6I8Rt=)jnplP>yuS+P&PxeWpJ#1$F`iqRl|jF$WL_aZFZl@kLo&d$VJtu&w?Q0O zzuXK>6gmygq(yXJy0C1SL}T8AplK|AGNUOhzlGeK_oo|haD@)5PxF}rV+5`-w{Aag zus45t=FU*{LguJ11Sr-28EZkq;!mJO7AQGih1L4rEyUmp>B!%X0YemsrV3QFvlgt* z5kwlPzaiJ+kZ^PMd-RRbl(Y?F*m`4*UIhIuf#8q>H_M=fM*L_Op-<_r zBZagV=4B|EW+KTja?srADTZXCd3Yv%^Chfpi)cg{ED${SI>InNpRj5!euKv?=Xn92 zsS&FH(*w`qLIy$doc>RE&A5R?u zzkl1sxX|{*fLpXvIW>9d<$ePROttn3oc6R!sN{&Y+>Jr@yeQN$sFR z;w6A<2-0%UA?c8Qf;sX7>>uKRBv3Ni)E9pI{uVzX|6Bb0U)`lhLE3hK58ivfRs1}d zNjlGK0hdq0qjV@q1qI%ZFMLgcpWSY~mB^LK)4GZ^h_@H+3?dAe_a~k*;9P_d7%NEFP6+ zgV(oGr*?W(ql?6SQ~`lUsjLb%MbfC4V$)1E0Y_b|OIYxz4?O|!kRb?BGrgiH5+(>s zoqM}v*;OBfg-D1l`M6T6{K`LG+0dJ1)!??G5g(2*vlNkm%Q(MPABT$r13q?|+kL4- zf)Mi5r$sn;u41aK(K#!m+goyd$c!KPl~-&-({j#D4^7hQkV3W|&>l_b!}!z?4($OA z5IrkfuT#F&S1(`?modY&I40%gtroig{YMvF{K{>5u^I51k8RriGd${z)=5k2tG zM|&Bp5kDTfb#vfuTTd?)a=>bX=lokw^y9+2LS?kwHQIWI~pYgy7 zb?A-RKVm_vM5!9?C%qYdfRAw& zAU7`up~%g=p@}pg#b7E)BFYx3g%(J36Nw(Dij!b>cMl@CSNbrW!DBDbTD4OXk!G4x zi}JBKc8HBYx$J~31PXH+4^x|UxK~(<@I;^3pWN$E=sYma@JP|8YL`L(zI6Y#c%Q{6 z*APf`DU$S4pr#_!60BH$FGViP14iJmbrzSrOkR;f3YZa{#E7Wpd@^4E-zH8EgPc-# zKWFPvh%WbqU_%ZEt`=Q?odKHc7@SUmY{GK`?40VuL~o)bS|is$Hn=<=KGHOsEC5tB zFb|q}gGlL97NUf$G$>^1b^3E18PZ~Pm9kX%*ftnolljiEt@2#F2R5ah$zbXd%V_Ev zyDd{1o_uuoBga$fB@Fw!V5F3jIr=a-ykqrK?WWZ#a(bglI_-8pq74RK*KfQ z0~Dzus7_l;pMJYf>Bk`)`S8gF!To-BdMnVw5M-pyu+aCiC5dwNH|6fgRsIKZcF&)g zr}1|?VOp}I3)IR@m1&HX1~#wsS!4iYqES zK}4J{Ei>;e3>LB#Oly>EZkW14^@YmpbgxCDi#0RgdM${&wxR+LiX}B+iRioOB0(pDKpVEI;ND?wNx>%e|m{RsqR_{(nmQ z3ZS}@t!p4a(BKx_-CYwrcyJ5u1TO9bcXti$8sy>xcLKqKCc#~UOZYD{llKTSFEjJ~ zyNWt>tLU}*>^`TvPxtP%F`ZJQw@W0^>x;!^@?k_)9#bF$j0)S3;mH-IR5y82l|%=F z2lR8zhP?XNP-ucZZ6A+o$xOyF!w;RaLHGh57GZ|TCXhJqY~GCh)aXEV$1O&$c}La1 zjuJxkY9SM4av^Hb;i7efiYaMwI%jGy`3NdY)+mcJhF(3XEiSlU3c|jMBi|;m-c?~T z+x0_@;SxcoY=(6xNgO$bBt~Pj8`-<1S|;Bsjrzw3@zSjt^JC3X3*$HI79i~!$RmTz zsblZsLYs7L$|=1CB$8qS!tXrWs!F@BVuh?kN(PvE5Av-*r^iYu+L^j^m9JG^#=m>@ z=1soa)H*w6KzoR$B8mBCXoU;f5^bVuwQ3~2LKg!yxomG1#XPmn(?YH@E~_ED+W6mxs%x{%Z<$pW`~ON1~2XjP5v(0{C{+6Dm$00tsd3w=f=ZENy zOgb-=f}|Hb*LQ$YdWg<(u7x3`PKF)B7ZfZ6;1FrNM63 z?O6tE%EiU@6%rVuwIQjvGtOofZBGZT1Sh(xLIYt9c4VI8`!=UJd2BfLjdRI#SbVAX ziT(f*RI^T!IL5Ac>ql7uduF#nuCRJ1)2bdvAyMxp-5^Ww5p#X{rb5)(X|fEhDHHW{ zw(Lfc$g;+Q`B0AiPGtmK%*aWfQQ$d!*U<|-@n2HZvCWSiw^I>#vh+LyC;aaVWGbmkENr z&kl*8o^_FW$T?rDYLO1Pyi%>@&kJKQoH2E0F`HjcN}Zlnx1ddoDA>G4Xu_jyp6vuT zPvC}pT&Owx+qB`zUeR|4G;OH(<<^_bzkjln0k40t`PQxc$7h(T8Ya~X+9gDc8Z9{Z z&y0RAU}#_kQGrM;__MK9vwIwK^aoqFhk~dK!ARf1zJqHMxF2?7-8|~yoO@_~Ed;_wvT%Vs{9RK$6uUQ|&@#6vyBsFK9eZW1Ft#D2)VpQRwpR(;x^ zdoTgMqfF9iBl%{`QDv7B0~8{8`8k`C4@cbZAXBu00v#kYl!#_Wug{)2PwD5cNp?K^ z9+|d-4z|gZ!L{57>!Ogfbzchm>J1)Y%?NThxIS8frAw@z>Zb9v%3_3~F@<=LG%r*U zaTov}{{^z~SeX!qgSYow`_5)ij*QtGp4lvF`aIGQ>@3ZTkDmsl#@^5*NGjOuu82}o zzLF~Q9SW+mP=>88%eSA1W4_W7-Q>rdq^?t=m6}^tDPaBRGFLg%ak93W!kOp#EO{6& zP%}Iff5HZQ9VW$~+9r=|Quj#z*=YwcnssS~9|ub2>v|u1JXP47vZ1&L1O%Z1DsOrDfSIMHU{VT>&>H=9}G3i@2rP+rx@eU@uE8rJNec zij~#FmuEBj03F1~ct@C@$>y)zB+tVyjV3*n`mtAhIM0$58vM9jOQC}JJOem|EpwqeMuYPxu3sv}oMS?S#o6GGK@8PN59)m&K4Dc&X% z(;XL_kKeYkafzS3Wn5DD>Yiw{LACy_#jY4op(>9q>>-*9@C0M+=b#bknAWZ37^(Ij zq>H%<@>o4a#6NydoF{_M4i4zB_KG)#PSye9bk0Ou8h%1Dtl7Q_y#7*n%g)?m>xF~( zjqvOwC;*qvN_3(*a+w2|ao0D?@okOvg8JskUw(l7n`0fncglavwKd?~l_ryKJ^Ky! zKCHkIC-o7%fFvPa$)YNh022lakMar^dgL=t#@XLyNHHw!b?%WlM)R@^!)I!smZL@k zBi=6wE5)2v&!UNV(&)oOYW(6Qa!nUjDKKBf-~Da=#^HE4(@mWk)LPvhyN3i4goB$3K8iV7uh zsv+a?#c4&NWeK(3AH;ETrMOIFgu{_@%XRwCZ;L=^8Ts)hix4Pf3yJRQ<8xb^CkdmC z?c_gB)XmRsk`9ch#tx4*hO=#qS7={~Vb4*tTf<5P%*-XMfUUYkI9T1cEF;ObfxxI-yNuA=I$dCtz3ey znVkctYD*`fUuZ(57+^B*R=Q}~{1z#2!ca?)+YsRQb+lt^LmEvZt_`=j^wqig+wz@n@ z`LIMQJT3bxMzuKg8EGBU+Q-6cs5(@5W?N>JpZL{$9VF)veF`L5%DSYTNQEypW%6$u zm_~}T{HeHj1bAlKl8ii92l9~$dm=UM21kLemA&b$;^!wB7#IKWGnF$TVq!!lBlG4 z{?Rjz?P(uvid+|i$VH?`-C&Gcb3{(~Vpg`w+O);Wk1|Mrjxrht0GfRUnZqz2MhrXa zqgVC9nemD5)H$to=~hp)c=l9?#~Z_7i~=U-`FZxb-|TR9@YCxx;Zjo-WpMNOn2)z) zFPGGVl%3N$f`gp$gPnWC+f4(rmts%fidpo^BJx72zAd7|*Xi{2VXmbOm)1`w^tm9% znM=0Fg4bDxH5PxPEm{P3#A(mxqlM7SIARP?|2&+c7qmU8kP&iApzL|F>Dz)Ixp_`O zP%xrP1M6@oYhgo$ZWwrAsYLa4 z|I;DAvJxno9HkQrhLPQk-8}=De{9U3U%)dJ$955?_AOms!9gia%)0E$Mp}$+0er@< zq7J&_SzvShM?e%V?_zUu{niL@gt5UFOjFJUJ}L?$f%eU%jUSoujr{^O=?=^{19`ON zlRIy8Uo_nqcPa6@yyz`CM?pMJ^^SN^Fqtt`GQ8Q#W4kE7`V9^LT}j#pMChl!j#g#J zr-=CCaV%xyFeQ9SK+mG(cTwW*)xa(eK;_Z(jy)woZp~> zA(4}-&VH+TEeLzPTqw&FOoK(ZjD~m{KW05fiGLe@E3Z2`rLukIDahE*`u!ubU)9`o zn^-lyht#E#-dt~S>}4y$-mSbR8{T@}22cn^refuQ08NjLOv?JiEWjyOnzk<^R5%gO zhUH_B{oz~u#IYwVnUg8?3P*#DqD8#X;%q%HY**=I>>-S|!X*-!x1{^l#OnR56O>iD zc;i;KS+t$koh)E3)w0OjWJl_aW2;xF=9D9Kr>)(5}4FqUbk# zI#$N8o0w;IChL49m9CJTzoC!|u{Ljd%ECgBOf$}&jA^$(V#P#~)`&g`H8E{uv52pp zwto`xUL-L&WTAVREEm$0g_gYPL(^vHq(*t1WCH_6alhkeW&GCZ3hL)|{O-jiFOBrF z!EW=Jej|dqQitT6!B-7&io2K)WIm~Q)v@yq%U|VpV+I?{y0@Yd%n8~-NuuM*pM~KA z85YB};IS~M(c<}4Hxx>qRK0cdl&e?t253N%vefkgds>Ubn8X}j6Vpgs>a#nFq$osY z1ZRwLqFv=+BTb=i%D2Wv>_yE0z}+niZ4?rE|*a3d7^kndWGwnFqt+iZ(7+aln<}jzbAQ(#Z2SS}3S$%Bd}^ zc9ghB%O)Z_mTZMRC&H#)I#fiLuIkGa^`4e~9oM5zKPx?zjkC&Xy0~r{;S?FS%c7w< zWbMpzc(xSw?9tGxG~_l}Acq}zjt5ClaB7-!vzqnlrX;}$#+PyQ9oU)_DfePh2E1<7 ztok6g6K^k^DuHR*iJ?jw?bs_whk|bx`dxu^nC6#e{1*m~z1eq7m}Cf$*^Eua(oi_I zAL+3opNhJteu&mWQ@kQWPucmiP)4|nFG`b2tpC;h{-PI@`+h?9v=9mn|0R-n8#t=+Z*FD(c5 zjj79Jxkgck*DV=wpFgRZuwr%}KTm+dx?RT@aUHJdaX-ODh~gByS?WGx&czAkvkg;x zrf92l8$Or_zOwJVwh>5rB`Q5_5}ef6DjS*$x30nZbuO3dijS*wvNEqTY5p1_A0gWr znH<(Qvb!os14|R)n2Ost>jS2;d1zyLHu`Svm|&dZD+PpP{Bh>U&`Md;gRl64q;>{8MJJM$?UNUd`aC>BiLe>*{ zJY15->yW+<3rLgYeTruFDtk1ovU<$(_y7#HgUq>)r0{^}Xbth}V#6?%5jeFYt;SG^ z3qF)=uWRU;Jj)Q}cpY8-H+l_n$2$6{ZR?&*IGr{>ek!69ZH0ZoJ*Ji+ezzlJ^%qL3 zO5a`6gwFw(moEzqxh=yJ9M1FTn!eo&qD#y5AZXErHs%22?A+JmS&GIolml!)rZTnUDM3YgzYfT#;OXn)`PWv3Ta z!-i|-Wojv*k&bC}_JJDjiAK(Ba|YZgUI{f}TdEOFT2+}nPmttytw7j%@bQZDV1vvj z^rp{gRkCDmYJHGrE1~e~AE!-&6B6`7UxVQuvRrfdFkGX8H~SNP_X4EodVd;lXd^>eV1jN+Tt4}Rsn)R0LxBz0c=NXU|pUe!MQQFkGBWbR3&(jLm z%RSLc#p}5_dO{GD=DEFr=Fc% z85CBF>*t!6ugI?soX(*JNxBp+-DdZ4X0LldiK}+WWGvXV(C(Ht|!3$psR=&c*HIM=BmX;pRIpz@Ale{9dhGe(U2|Giv;# zOc|;?p67J=Q(kamB*aus=|XP|m{jN^6@V*Bpm?ye56Njh#vyJqE=DweC;?Rv7faX~ zde03n^I~0B2vUmr;w^X37tVxUK?4}ifsSH5_kpKZIzpYu0;Kv}SBGfI2AKNp+VN#z`nI{UNDRbo-wqa4NEls zICRJpu)??cj^*WcZ^MAv+;bDbh~gpN$1Cor<{Y2oyIDws^JsfW^5AL$azE(T0p&pP z1Mv~6Q44R&RHoH95&OuGx2srIr<@zYJTOMKiVs;Bx3py89I87LOb@%mr`0)#;7_~Z zzcZj8?w=)>%5@HoCHE_&hnu(n_yQ-L(~VjpjjkbT7e)Dk5??fApg(d>vwLRJ-x{um z*Nt?DqTSxh_MIyogY!vf1mU1`Gld-&L)*43f6dilz`Q@HEz;+>MDDYv9u!s;WXeao zUq=TaL$P*IFgJzrGc>j1dDOd zed+=ZBo?w4mr$2)Ya}?vedDopomhW1`#P<%YOJ_j=WwClX0xJH-f@s?^tmzs_j7t!k zK@j^zS0Q|mM4tVP5Ram$VbS6|YDY&y?Q1r1joe9dj08#CM{RSMTU}(RCh`hp_Rkl- zGd|Cv~G@F{DLhCizAm9AN!^{rNs8hu!G@8RpnGx7e`-+K$ffN<0qjR zGq^$dj_Tv!n*?zOSyk5skI7JVKJ)3jysnjIu-@VSzQiP8r6MzudCU=~?v-U8yzo^7 zGf~SUTvEp+S*!X9uX!sq=o}lH;r{pzk~M*VA(uyQ`3C8!{C;)&6)95fv(cK!%Cuz$ z_Zal57H6kPN>25KNiI6z6F)jzEkh#%OqU#-__Xzy)KyH};81#N6OfX$$IXWzOn`Q& z4f$Z1t>)8&8PcYfEwY5UadU1yg+U*(1m2ZlHoC-!2?gB!!fLhmTl))D@dhvkx#+Yj z1O=LV{(T%{^IeCuFK>%QR!VZ4GnO5tK8a+thWE zg4VytZrwcS?7^ zuZfhYnB8dwd%VLO?DK7pV5Wi<(`~DYqOXn8#jUIL^)12*Dbhk4GmL_E2`WX&iT16o zk(t|hok(Y|v-wzn?4x34T)|+SfZP>fiq!><*%vnxGN~ypST-FtC+@TPv*vYv@iU!_ z@2gf|PrgQ?Ktf*9^CnJ(x*CtZVB8!OBfg0%!wL;Z8(tYYre0vcnPGlyCc$V(Ipl*P z_(J!a=o@vp^%Efme!K74(Ke7A>Y}|sxV+JL^aYa{~m%5#$$+R1? zGaQhZTTX!#s#=Xtpegqero$RNt&`4xn3g$)=y*;=N=Qai)}~`xtxI_N*#MMCIq#HFifT zz(-*m;pVH&+4bixL&Bbg)W5FN^bH87pAHp)zPkWNMfTFqS=l~AC$3FX3kQUSh_C?-ZftyClgM)o_D7cX$RGlEYblux0jv5 zTr|i-I3@ZPCGheCl~BGhImF)K4!9@?pC(gi3ozX=a!|r1)LFxy_8c&wY0<^{2cm|P zv6Y`QktY*;I)IUd5y3ne1CqpVanlY45z8hf4&$EUBnucDj16pDa4&GI&TArYhf*xh zdj>*%APH8(h~c>o@l#%T>R$e>rwVx_WUB|~V`p^JHsg*y12lzj&zF}w6W09HwB2yb z%Q~`es&(;7#*DUC_w-Dmt7|$*?TA_m;zB+-u{2;Bg{O}nV7G_@7~<)Bv8fH^G$XG8$(&{A zwXJK5LRK%M34(t$&NI~MHT{UQ9qN-V_yn|%PqC81EIiSzmMM=2zb`mIwiP_b)x+2M z7Gd`83h79j#SItpQ}luuf2uOU`my_rY5T{6P#BNlb%h%<#MZb=m@y5aW;#o1^2Z)SWo+b`y0gV^iRcZtz5!-05vF z7wNo=hc6h4hc&s@uL^jqRvD6thVYtbErDK9k!;+a0xoE0WL7zLixjn5;$fXvT=O3I zT6jI&^A7k6R{&5#lVjz#8%_RiAa2{di{`kx79K+j72$H(!ass|B%@l%KeeKchYLe_ z>!(JC2fxsv>XVen+Y42GeYPxMWqm`6F$(E<6^s|g(slNk!lL*6v^W2>f6hh^mE$s= z3D$)}{V5(Qm&A6bp%2Q}*GZ5Qrf}n7*Hr51?bJOyA-?B4vg6y_EX<*-e20h{=0Mxs zbuQGZ$fLyO5v$nQ&^kuH+mNq9O#MWSfThtH|0q1i!NrWj^S}_P;Q1OkYLW6U^?_7G zx2wg?CULj7))QU(n{$0JE%1t2dWrMi2g-Os{v|8^wK{@qlj%+1b^?NI z$}l2tjp0g>K3O+p%yK<9!XqmQ?E9>z&(|^Pi~aSRwI5x$jaA62GFz9%fmO3t3a>cq zK8Xbv=5Ps~4mKN5+Eqw12(!PEyedFXv~VLxMB~HwT1Vfo51pQ#D8e$e4pFZ{&RC2P z5gTIzl{3!&(tor^BwZfR8j4k{7Rq#`riKXP2O-Bh66#WWK2w=z;iD9GLl+3 zpHIaI4#lQ&S-xBK8PiQ%dwOh?%BO~DCo06pN7<^dnZCN@NzY{_Z1>rrB0U|nC&+!2 z2y!oBcTd2;@lzyk(B=TkyZ)zy0deK05*Q0zk+o$@nun`VI1Er7pjq>8V zNmlW{p7S^Btgb(TA}jL(uR>`0w8gHP^T~Sh5Tkip^spk4SBAhC{TZU}_Z)UJw-}zm zPq{KBm!k)?P{`-(9?LFt&YN4s%SIZ-9lJ!Ws~B%exHOeVFk3~}HewnnH(d)qkLQ_d z6h>O)pEE{vbOVw}E+jdYC^wM+AAhaI(YAibUc@B#_mDss0Ji&BK{WG`4 zOk>vSNq(Bq2IB@s>>Rxm6Wv?h;ZXkpb1l8u|+_qXWdC*jjcPCixq;!%BVPSp#hP zqo`%cNf&YoQXHC$D=D45RiT|5ngPlh?0T~?lUf*O)){K@*Kbh?3RW1j9-T?%lDk@y z4+~?wKI%Y!-=O|_IuKz|=)F;V7ps=5@g)RrE;;tvM$gUhG>jHcw2Hr@fS+k^Zr~>G z^JvPrZc}_&d_kEsqAEMTMJw!!CBw)u&ZVzmq+ZworuaE&TT>$pYsd9|g9O^0orAe8 z221?Va!l1|Y5X1Y?{G7rt1sX#qFA^?RLG^VjoxPf63;AS=_mVDfGJKg73L zsGdnTUD40y(>S##2l|W2Cy!H(@@5KBa(#gs`vlz}Y~$ot5VsqPQ{{YtjYFvIumZzt zA{CcxZLJR|4#{j7k~Tu*jkwz8QA|5G1$Cl895R`Zyp;irp1{KN){kB30O8P1W5;@bG znvX74roeMmQlUi=v9Y%(wl$ZC#9tKNFpvi3!C}f1m6Ct|l2g%psc{TJp)@yu)*e2> z((p0Fg*8gJ!|3WZke9;Z{8}&NRkv7iP=#_y-F}x^y?2m%-D_aj^)f04%mneyjo_;) z6qc_Zu$q37d~X``*eP~Q>I2gg%rrV8v=kDfpp$=%Vj}hF)^dsSWygoN(A$g*E=Do6FX?&(@F#7pbiJ`;c0c@Ul zDqW_90Wm#5f2L<(Lf3)3TeXtI7nhYwRm(F;*r_G6K@OPW4H(Y3O5SjUzBC}u3d|eQ8*8d@?;zUPE+i#QNMn=r(ap?2SH@vo*m z3HJ%XuG_S6;QbWy-l%qU;8x;>z>4pMW7>R}J%QLf%@1BY(4f_1iixd-6GlO7Vp*yU zp{VU^3?s?90i=!#>H`lxT!q8rk>W_$2~kbpz7eV{3wR|8E=8**5?qn8#n`*(bt1xRQrdGxyx2y%B$qmw#>ZV$c7%cO#%JM1lY$Y0q?Yuo> ze9KdJoiM)RH*SB%^;TAdX-zEjA7@%y=!0=Zg%iWK7jVI9b&Dk}0$Af&08KHo+ zOwDhFvA(E|ER%a^cdh@^wLUlmIv6?_3=BvX8jKk92L=Y}7Jf5OGMfh` zBdR1wFCi-i5@`9km{isRb0O%TX+f~)KNaEz{rXQa89`YIF;EN&gN)cigu6mNh>?Cm zAO&Im2flv6D{jwm+y<%WsPe4!89n~KN|7}Cb{Z;XweER73r}Qp2 zz}WP4j}U0&(uD&9yGy6`!+_v-S(yG*iytsTR#x_Rc>=6u^vnRDnf1gP{#2>`ffrAC% zTZ5WQ@hAK;P;>kX{D)mIXe4%a5p=LO1xXH@8T?mz7Q@d)$3pL{{B!2{-v70L*o1AO+|n5beiw~ zk@(>m?T3{2k2c;NWc^`4@P&Z?BjxXJ@;x1qhn)9Mn*IFdt_J-dIqx5#d`NfyfX~m( zIS~5)MfZ2Uy?_4W`47i}u0ZgPh<{D|w_d#;D}Q&U$Q-G}xM1A@1f{#%A$jh6Qp&0hQ<0bPOM z-{1Wm&p%%#eb_?x7i;bol EfAhh=DF6Tf literal 0 HcmV?d00001 diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..642d572ce9 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b86d33d312..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ -language: java -install: true -script: mvn clean install -B -V - -matrix: - include: - - jdk: oraclejdk8 - after_success: - - mvn jacoco:report && bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" - dist: trusty - - jdk: openjdk11 - # There is an issue with the documentation so skip it - script: mvn -B -V clean install -DskipDistribution=true - - jdk: openjdk13 - # There is an issue with the documentation so skip it - script: mvn -B -V clean install -DskipDistribution=true - - jdk: openjdk14 - # There is an issue with the documentation so skip it - script: mvn -B -V clean install -DskipDistribution=true - # There is an issue with the documentation so skip it - - jdk: openjdk-ea - script: mvn -B -V clean install -DskipDistribution=true - allow_failures: - - jdk: openjdk-ea -deploy: - provider: script - script: "test ${TRAVIS_TEST_RESULT} -eq 0 && mvn -s etc/travis-settings.xml -DskipTests=true -DskipDistribution=true deploy" - skip_cleanup: true - on: - repo: mapstruct/mapstruct - branch: master - jdk: oraclejdk8 - -sudo: required -cache: - directories: - - $HOME/.m2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aaf8fd8646..6064004d73 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ You love MapStruct but miss a certain feature? You found a bug and want to repor * Source code: [http://github.com/mapstruct/mapstruct](http://github.com/mapstruct/mapstruct) * Issue tracker: [https://github.com/mapstruct/mapstruct/issues](https://github.com/mapstruct/mapstruct/issues) * Discussions: Join the [mapstruct-users](https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users) Google group -* CI build: [https://travis-ci.org/mapstruct/mapstruct/](https://travis-ci.org/mapstruct/mapstruct/) +* CI build: [https://github.com/mapstruct/mapstruct/actions/](https://github.com/mapstruct/mapstruct/actions) MapStruct follows the _Fork & Pull_ development approach. To get started just fork the [MapStruct repository](http://github.com/mapstruct/mapstruct) to your GitHub account and create a new topic branch for each change. Once you are done with your change, submit a [pull request](https://help.github.com/articles/using-pull-requests) against the MapStruct repo. diff --git a/etc/travis-settings.xml b/etc/ci-settings.xml similarity index 100% rename from etc/travis-settings.xml rename to etc/ci-settings.xml diff --git a/mvnw b/mvnw new file mode 100755 index 0000000000..41c0f0c23d --- /dev/null +++ b/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000000..86115719e5 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/parent/pom.xml b/parent/pom.xml index 83a59bf2cd..9bc07c5cda 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -81,8 +81,8 @@ - Travis CI - https://travis-ci.org/mapstruct/mapstruct + Github Actions + https://github.com/mapstruct/mapstruct/actions @@ -430,7 +430,6 @@ ${org.apache.maven.plugins.surefire.version} ${forkCount} - -Xms1024m -Xmx3072m @@ -577,12 +576,13 @@ true **/.idea/** + **/.mvn/** **/build-config/checkstyle.xml **/build-config/import-control.xml copyright.txt **/LICENSE.txt **/mapstruct.xml - **/travis-settings.xml + **/ci-settings.xml **/eclipse-formatter-config.xml **/forbidden-apis.txt **/checkstyle-for-generated-sources.xml @@ -596,6 +596,7 @@ .factorypath .checkstyle *.yml + mvnw* **/*.asciidoc **/binding.xjb diff --git a/readme.md b/readme.md index f8247297e2..5daba3f777 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) -[![Build Status](https://img.shields.io/travis/mapstruct/mapstruct.svg)](https://travis-ci.org/mapstruct/mapstruct) +[![Build Status](https://github.com/mapstruct/mapstruct/workflows/CI/badge.svg?branch=master)](https://github.com/mapstruct/mapstruct/actions?query=branch%3Amaster+workflow%3ACI) [![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct) [![Gitter](https://img.shields.io/gitter/room/mapstruct/mapstruct.svg)](https://gitter.im/mapstruct/mapstruct-users) [![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/context:java) @@ -164,7 +164,7 @@ Make sure that you have the [m2e_apt](https://marketplace.eclipse.org/content/m2 * [Downloads](https://sourceforge.net/projects/mapstruct/files/) * [Issue tracker](https://github.com/mapstruct/mapstruct/issues) * [User group](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) -* [CI build](https://travis-ci.org/mapstruct/mapstruct/) +* [CI build](https://github.com/mapstruct/mapstruct/actions/) ## Licensing From 63c2edd3334fa1fde7106ea9dc38cbf1b2896510 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Feb 2020 08:34:09 +0100 Subject: [PATCH 0444/1006] Reset locale and time zone in every test --- .../ap/test/builtin/DatatypeFactoryTest.java | 16 ++++++++++++++++ .../test/conversion/date/DateConversionTest.java | 9 +++++++++ .../java8time/Java8TimeConversionTest.java | 14 ++++++++++++++ .../conversion/jodatime/JodaConversionTest.java | 9 +++++++++ .../numbers/NumberFormatConversionTest.java | 9 +++++++++ .../NestedMappingMethodInvocationTest.java | 9 +++++++++ 6 files changed, 66 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java index fe52452c73..17d7980ff8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java @@ -10,7 +10,10 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.TimeZone; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.builtin.bean.CalendarProperty; @@ -34,6 +37,19 @@ @RunWith(AnnotationProcessorTestRunner.class) public class DatatypeFactoryTest { + private TimeZone originalTimeZone; + + @Before + public void setUp() { + originalTimeZone = TimeZone.getDefault(); + TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); + } + + @After + public void tearDown() { + TimeZone.setDefault( originalTimeZone ); + } + @Test public void testNoConflictsWithOwnDatatypeFactory() throws ParseException { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index c7a3cf3311..43ed5b3301 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Locale; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,11 +41,19 @@ @RunWith(AnnotationProcessorTestRunner.class) public class DateConversionTest { + private Locale originalLocale; + @Before public void setDefaultLocale() { + originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } + @After + public void tearDown() { + Locale.setDefault( originalLocale ); + } + @Test @DisabledOnCompiler(Compiler.JDK11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index 573e300bfc..25ed958867 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -17,6 +17,8 @@ import java.util.Date; import java.util.TimeZone; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -33,6 +35,18 @@ @IssueKey("121") public class Java8TimeConversionTest { + private TimeZone originalTimeZone; + + @Before + public void setUp() { + originalTimeZone = TimeZone.getDefault(); + } + + @After + public void tearDown() { + TimeZone.setDefault( originalTimeZone ); + } + @Test public void testDateTimeToString() { Source src = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 30c96395b7..db61b85bc8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -16,6 +16,7 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,11 +37,19 @@ @IssueKey("75") public class JodaConversionTest { + private Locale originalLocale; + @Before public void setDefaultLocale() { + originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } + @After + public void tearDown() { + Locale.setDefault( originalLocale ); + } + @Test public void testDateTimeToString() { Source src = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index ad2caecfd3..9b92182f6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.conversion.numbers; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,11 +31,19 @@ @RunWith(AnnotationProcessorTestRunner.class) public class NumberFormatConversionTest { + private Locale originalLocale; + @Before public void setDefaultLocale() { + originalLocale = Locale.getDefault(); Locale.setDefault( Locale.ENGLISH ); } + @After + public void tearDown() { + Locale.setDefault( originalLocale ); + } + @Test public void shouldApplyStringConversions() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 11ac637f91..3738f56282 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -20,6 +20,7 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,11 +39,19 @@ public class NestedMappingMethodInvocationTest { public static final QName QNAME = new QName( "dont-care" ); + private Locale originalLocale; + @Before public void setDefaultLocale() { + originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } + @After + public void tearDown() { + Locale.setDefault( originalLocale ); + } + @Test @WithClasses( { OrderTypeToOrderDtoMapper.class, From f8a3924005d41a4a05872db8822b48a39cade864 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 7 Mar 2020 00:29:59 +0100 Subject: [PATCH 0445/1006] Use fix version for maven-processor-plugin Using the latest (4.0-beta1) does not work on Java 8 since it is compiled with Java 9 --- integrationtest/src/test/resources/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index b386ce6e27..e209daf234 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -75,6 +75,7 @@ org.bsc.maven maven-processor-plugin + 3.3.3 process From bbd68baf648ba870df11e2c931dfc6de9de310fd Mon Sep 17 00:00:00 2001 From: Pawel Radzinski Date: Mon, 30 Mar 2020 21:11:07 +0200 Subject: [PATCH 0446/1006] Update chapter-10-advanced-mapping-options.asciidoc (#2050) Correct some typos and punctuation here and there. --- .../chapter-10-advanced-mapping-options.asciidoc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index a3836d048f..13205caa9b 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -4,7 +4,7 @@ This chapter describes several advanced options which allow to fine-tune the beh [[default-values-and-constants]] === Default values and constants -Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values. When the target type is a primitive or a boxed type, the String value is taken literal. Bit / octal / decimal / hex patterns are allowed in such case as long as they are a valid literal. +Default values can be specified to set a predefined value to a target property if the corresponding source property is `null`. Constants can be specified to set such a predefined value in any case. Default values and constants are specified as String values. When the target type is a primitive or a boxed type, the String value is taken literal. Bit / octal / decimal / hex patterns are allowed in such a case as long as they are a valid literal. In all other cases, constant or default values are subject to type conversion either via built-in conversions or the invocation of other mapping methods in order to match the type required by the target property. A mapping with a constant must not include a reference to a source property. The following example shows some mappings using default values and constants: @@ -108,7 +108,7 @@ public interface SourceTargetMapper { ---- ==== -The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation ((see <>). +The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation (see <>). [[determining-result-type]] === Determining the result type @@ -189,8 +189,8 @@ The strategy works in a hierarchical fashion. Setting `Mapping#nullValueProperty [NOTE] ==== -Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property -null check, regardless the value of the `NullValuePropertyMappingStrategy` to avoid addition of `null` to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor (see `CollectionMappingStrategy`), MapStruct will always generate a source property +null check, regardless of the value of the `NullValuePropertyMappingStrategy`, to avoid addition of `null` to the target collection or map. Since the target is assumed to be initialised this strategy will not be applied. ==== [TIP] @@ -209,7 +209,7 @@ MapStruct offers control over when to generate a `null` check. By default (`null .. calling another type conversion and subsequently calling the setter on the target. .. calling a mapping method and subsequently calling the setter on the target. -First calling a mapping method on the source property is not protected by a null check. Therefor generated mapping methods will do a null check prior to carrying out mapping on a source property. Handwritten mapping methods must take care of null value checking. They have the possibility to add 'meaning' to `null`. For instance: mapping `null` to a default value. +First calling a mapping method on the source property is not protected by a null check. Therefore generated mapping methods will do a null check prior to carrying out mapping on a source property. Handwritten mapping methods must take care of null value checking. They have the possibility to add 'meaning' to `null`. For instance: mapping `null` to a default value. The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. @@ -227,7 +227,7 @@ The source presence checker name can be changed in the MapStruct service provide [NOTE] ==== Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property -null check, regardless the value of the `NullValueheckStrategy` to avoid addition of `null` to the target collection or map. +null check, regardless the value of the `NullValueCheckStrategy` to avoid addition of `null` to the target collection or map. ==== [[exceptions]] === Exceptions @@ -299,4 +299,4 @@ public CarDto carToCarDto(Car car) throws GearException { ---- ==== -Some **notes** on null checks. MapStruct does provide null checking only when required: when applying type-conversions or constructing a new type by invoking its constructor. This means that the user is responsible in hand-written code for returning valid non-null objects. Also null objects can be handed to hand-written code, since MapStruct does not want to make assumptions on the meaning assigned by the user to a null object. Hand-written code has to deal with this. \ No newline at end of file +Some **notes** on null checks. MapStruct does provide null checking only when required: when applying type-conversions or constructing a new type by invoking its constructor. This means that the user is responsible in hand-written code for returning valid non-null objects. Also null objects can be handed to hand-written code, since MapStruct does not want to make assumptions on the meaning assigned by the user to a null object. Hand-written code has to deal with this. From b7d5e557c1d5d327d7df0bb50dec37427bd7fda0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Apr 2020 09:29:00 +0200 Subject: [PATCH 0447/1006] Checkstyle max line length should be 120 --- build-config/src/main/resources/build-config/checkstyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 213a0d21f5..5ae53dc46f 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -32,7 +32,7 @@ - + From 4f76208c62971e7eca45dab831a379dd342214a4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 7 Mar 2020 18:16:38 +0100 Subject: [PATCH 0448/1006] #2021 Generate compilable code when Decorator is nested within the Mapper We need to treat the import of the decoratorType specially when it is nested. Calling addIfImportRequired is not the most correct approach since it would lead to checking if the type is to be imported and that would be false since the Decorator is a nested class within the Mapper. However, when generating the Decorator this is not needed, because the Decorator is a top level class itself In a nutshell creating the Decorator should have its own ProcessorContext, but it doesn't --- .../ap/internal/model/Decorator.java | 17 ++++++++++- .../ap/test/bugs/_2021/Issue2021Mapper.java | 22 +++++++++++++++ .../ap/test/bugs/_2021/Issue2021Test.java | 28 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index ab37cb77d5..e61a25a475 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -125,7 +125,22 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type @Override public SortedSet getImportTypes() { SortedSet importTypes = super.getImportTypes(); - addIfImportRequired( importTypes, decoratorType ); + // DecoratorType needs special handling in case it is nested + // calling addIfImportRequired is not the most correct approach since it would + // lead to checking if the type is to be imported and that would be false + // since the Decorator is a nested class within the Mapper. + // However, when generating the Decorator this is not needed, + // because the Decorator is a top level class itself + // In a nutshell creating the Decorator should have its own ProcessorContext, but it doesn't + if ( decoratorType.getPackageName().equalsIgnoreCase( getPackageName() ) ) { + if ( decoratorType.getTypeElement() != null && + decoratorType.getTypeElement().getNestingKind().isNested() ) { + importTypes.add( decoratorType ); + } + } + else { + importTypes.add( decoratorType ); + } return importTypes; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Mapper.java new file mode 100644 index 0000000000..4627f22323 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2021; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +@DecoratedWith(Issue2021Mapper.Decorator.class) +public interface Issue2021Mapper { + + abstract class Decorator implements Issue2021Mapper { + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java new file mode 100644 index 0000000000..f111799d53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2021; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2021") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2021Mapper.class +}) +public class Issue2021Test { + + @Test + public void shouldCompile() { + + } +} From 853ff7f74f0aebcd3b9e49f55d1778e088d7bb70 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Apr 2020 15:14:35 +0200 Subject: [PATCH 0449/1006] #2060: MapStruct should work properly on the module path --- .../itest/tests/MavenIntegrationTest.java | 6 ++++ .../src/test/resources/moduleInfoTest/pom.xml | 24 ++++++++++++++ .../src/main/java/module-info.java | 9 ++++++ .../mapstruct/itest/modules/CustomerDto.java | 31 +++++++++++++++++++ .../itest/modules/CustomerEntity.java | 31 +++++++++++++++++++ .../itest/modules/CustomerMapper.java | 23 ++++++++++++++ .../mapstruct/itest/modules/ModulesTest.java | 28 +++++++++++++++++ .../ap/internal/conversion/Conversions.java | 20 +++++++++--- 8 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 integrationtest/src/test/resources/moduleInfoTest/pom.xml create mode 100644 integrationtest/src/test/resources/moduleInfoTest/src/main/java/module-info.java create mode 100644 integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerDto.java create mode 100644 integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerEntity.java create mode 100644 integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerMapper.java create mode 100644 integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index e579f031f0..e7e26d9e1c 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -130,4 +130,10 @@ void superTypeGenerationTest() { void targetTypeGenerationTest() { } + @ProcessorTest(baseDir = "moduleInfoTest") + @EnabledForJreRange(min = JRE.JAVA_11) + void moduleInfoTest() { + + } + } diff --git a/integrationtest/src/test/resources/moduleInfoTest/pom.xml b/integrationtest/src/test/resources/moduleInfoTest/pom.xml new file mode 100644 index 0000000000..4561a1b69e --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + modulesTest + jar + + diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/main/java/module-info.java b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/module-info.java new file mode 100644 index 0000000000..07b4a62b06 --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/module-info.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +module test.mapstruct { + requires org.mapstruct; + exports org.mapstruct.itest.modules; +} diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerDto.java b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerDto.java new file mode 100644 index 0000000000..30ebb32968 --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerDto.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.modules; + +/** + * @author Filip Hrisafov + */ +public class CustomerDto { + + private String name; + private String email; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerEntity.java b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerEntity.java new file mode 100644 index 0000000000..a52a887f08 --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.modules; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerMapper.java b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerMapper.java new file mode 100644 index 0000000000..119bffaae8 --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/src/main/java/org/mapstruct/itest/modules/CustomerMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.modules; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromDto(CustomerDto record); + +} diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java b/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java new file mode 100644 index 0000000000..805662c806 --- /dev/null +++ b/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.modules; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.modules.CustomerDto; +import org.mapstruct.itest.modules.CustomerEntity; +import org.mapstruct.itest.modules.CustomerMapper; + +public class ModulesTest { + + @Test + public void shouldMapRecord() { + CustomerDto dto = new CustomerDto(); + dto.setName( "Kermit" ); + dto.setEmail( "kermit@test.com" ); + CustomerEntity customer = CustomerMapper.INSTANCE.fromDto( dto ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 6b2d5e2649..ad5fe85db3 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -184,9 +184,8 @@ public Conversions(TypeFactory typeFactory) { register( Enum.class, String.class, new EnumStringConversion() ); register( Date.class, String.class, new DateToStringConversion() ); register( BigDecimal.class, BigInteger.class, new BigDecimalToBigIntegerConversion() ); - register( Date.class, Time.class, new DateToSqlTimeConversion() ); - register( Date.class, java.sql.Date.class, new DateToSqlDateConversion() ); - register( Date.class, Timestamp.class, new DateToSqlTimestampConversion() ); + + registerJavaTimeSqlConversions(); // java.util.Currency <~> String register( Currency.class, String.class, new CurrencyToStringConversion() ); @@ -227,15 +226,28 @@ private void registerJava8TimeConversions() { register( ZonedDateTime.class, Date.class, new JavaZonedDateTimeToDateConversion() ); register( LocalDateTime.class, Date.class, new JavaLocalDateTimeToDateConversion() ); register( LocalDate.class, Date.class, new JavaLocalDateToDateConversion() ); - register( LocalDate.class, java.sql.Date.class, new JavaLocalDateToSqlDateConversion() ); register( Instant.class, Date.class, new JavaInstantToDateConversion() ); } + private void registerJavaTimeSqlConversions() { + if ( isJavaSqlAvailable() ) { + register( LocalDate.class, java.sql.Date.class, new JavaLocalDateToSqlDateConversion() ); + + register( Date.class, Time.class, new DateToSqlTimeConversion() ); + register( Date.class, java.sql.Date.class, new DateToSqlDateConversion() ); + register( Date.class, Timestamp.class, new DateToSqlTimestampConversion() ); + } + } + private boolean isJodaTimeAvailable() { return typeFactory.isTypeAvailable( JodaTimeConstants.DATE_TIME_FQN ); } + private boolean isJavaSqlAvailable() { + return typeFactory.isTypeAvailable( "java.sql.Date" ); + } + private void registerNativeTypeConversion(Class sourceType, Class targetType) { if ( sourceType.isPrimitive() && targetType.isPrimitive() ) { register( sourceType, targetType, new PrimitiveToPrimitiveConversion( sourceType ) ); From c410379f837d2cd45ebfaec58754e6f040b4ff2f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Apr 2020 16:46:20 +0200 Subject: [PATCH 0450/1006] #1553: Update tycho-compiler-jdt to latest 1.6.0 version Disable one test in GenericsHierarchyTest for Eclipse on Java 8 due to a bug in the Tycho compiler. Disable freeBuilder integration test for Eclipse since there are some problems in the second round of annotation processing (no ModelElementProcessor(s) are found) --- .../itest/tests/MavenIntegrationTest.java | 3 +- parent/pom.xml | 19 ++++++- .../generics/GenericsHierarchyTest.java | 9 +++ .../conversion/date/DateConversionTest.java | 20 +++++-- .../jodatime/JodaConversionTest.java | 10 +++- .../ap/test/verbose/VerboseTest.java | 55 +++++++++++++++---- .../runner/AnnotationProcessorTestRunner.java | 5 +- .../ap/testutil/runner/Compiler.java | 2 +- .../testutil/runner/DisabledOnCompiler.java | 2 +- .../runner/EclipseCompilingStatement.java | 18 +++++- .../ap/testutil/runner/EnabledOnCompiler.java | 2 +- .../InnerAnnotationProcessorRunner.java | 12 +++- 12 files changed, 127 insertions(+), 30 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index e7e26d9e1c..97da699cbe 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -36,8 +36,7 @@ void externalBeanJarTest() { } @ProcessorTest(baseDir = "freeBuilderBuilderTest", processorTypes = { - ProcessorTest.ProcessorType.JAVAC, - ProcessorTest.ProcessorType.ECLIPSE_JDT + ProcessorTest.ProcessorType.JAVAC }) void freeBuilderBuilderTest() { } diff --git a/parent/pom.xml b/parent/pom.xml index 9bc07c5cda..37551e2ed2 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -27,7 +27,7 @@ 3.0.0-M3 3.1.0 4.0.3.RELEASE - 0.26.0 + 1.6.0 8.29 5.6.0 @@ -237,13 +237,28 @@ org.codehaus.plexus plexus-container-default - 1.6 + 1.7.1 + + + org.codehaus.plexus + plexus-component-annotations + 1.7.1 + + + org.codehaus.plexus + plexus-classworlds + 2.5.1 org.codehaus.plexus plexus-utils 3.0.20 + + commons-io + commons-io + 2.5 + diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java index d79f544541..282a8e8efb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; /** * @author Andreas Gudian @@ -34,6 +36,13 @@ public class GenericsHierarchyTest { @Test + // Disabled due to a bug in the Eclipse compiler (https://bugs.eclipse.org/bugs/show_bug.cgi?id=540101) + // See https://github.com/mapstruct/mapstruct/issues/1553 and https://github.com/mapstruct/mapstruct/pull/1587 + // for more information + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) public void determinesAnimalKeyGetter() { AbstractAnimal source = new Elephant(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 43ed5b3301..2d98b73bc9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -55,7 +55,10 @@ public void tearDown() { } @Test - @DisabledOnCompiler(Compiler.JDK11) + @DisabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversions() { Source source = new Source(); @@ -70,7 +73,10 @@ public void shouldApplyDateFormatForConversions() { } @Test - @EnabledOnCompiler(Compiler.JDK11) + @EnabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionsJdk11() { Source source = new Source(); @@ -85,7 +91,10 @@ public void shouldApplyDateFormatForConversionsJdk11() { } @Test - @DisabledOnCompiler(Compiler.JDK11) + @DisabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMapping() { Target target = new Target(); @@ -102,7 +111,10 @@ public void shouldApplyDateFormatForConversionInReverseMapping() { } @Test - @EnabledOnCompiler(Compiler.JDK11) + @EnabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index db61b85bc8..9f61c222db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -87,7 +87,10 @@ public void testLocalTimeToString() { } @Test - @DisabledOnCompiler(Compiler.JDK11) + @DisabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStrings() { Source src = new Source(); @@ -115,7 +118,10 @@ public void testSourceToTargetMappingForStrings() { } @Test - @EnabledOnCompiler(Compiler.JDK11) + @EnabledOnCompiler({ + Compiler.JDK11, + Compiler.ECLIPSE11 + }) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStringsJdk11() { Source src = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java index 0d8003f91f..c042e3d073 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java @@ -30,7 +30,10 @@ public class VerboseTest { @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses({ CreateBeanMapping.class, CreateBeanMappingConfig.class }) @ExpectedNote("^MapStruct: Using accessor naming strategy:.*DefaultAccessorNamingStrategy.*$") @@ -41,7 +44,10 @@ public void testGeneralMessages() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @WithServiceImplementation(provides = BuilderProvider.class, value = ImmutablesBuilderProvider.class) @WithServiceImplementation(provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) @ProcessorOption(name = "mapstruct.verbose", value = "true") @@ -54,7 +60,10 @@ public void testGeneralWithOtherSPI() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @WithServiceImplementation(provides = AstModifyingAnnotationProcessor.class, value = AstModifyingAnnotationProcessorSaysNo.class) @ProcessorOption(name = "mapstruct.verbose", value = "true") @@ -73,7 +82,10 @@ public void testDeferred() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses({ CreateBeanMapping.class, CreateBeanMappingConfig.class }) @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") @@ -82,7 +94,10 @@ public void testCreateBeanMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectBeanMapping.class) @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") @@ -91,7 +106,10 @@ public void testSelectBeanMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(ValueMapping.class) @ExpectedNote("^- MapStruct: creating value mapping method implementation for.*$") @@ -99,7 +117,10 @@ public void testValueMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(CreateIterableMapping.class) @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") @@ -108,7 +129,10 @@ public void testVerboseCreateIterableMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectIterableMapping.class) @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") @@ -117,7 +141,10 @@ public void testVerboseSelectingIterableMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectStreamMapping.class) @ExpectedNote("^- MapStruct: creating stream mapping method implementation for.*$") @@ -125,7 +152,10 @@ public void testVerboseSelectingStreamMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(CreateMapMapping.class) @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") @@ -135,7 +165,10 @@ public void testVerboseCreateMapMapping() { } @Test - @DisabledOnCompiler( Compiler.ECLIPSE ) + @DisabledOnCompiler( { + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + } ) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectMapMapping.class) @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java index 6ddccf0eb7..2891121afb 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java @@ -74,7 +74,10 @@ else if ( IS_AT_LEAST_JAVA_9 ) { // Current tycho-compiler-jdt (0.26.0) is not compatible with Java 11 // Updating to latest version 1.3.0 fails some tests // Once https://github.com/mapstruct/mapstruct/pull/1587 is resolved we can remove this line - return Arrays.asList( new InnerAnnotationProcessorRunner( klass, Compiler.JDK11 ) ); + return Arrays.asList( + new InnerAnnotationProcessorRunner( klass, Compiler.JDK11 ), + new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE11 ) + ); } return Arrays.asList( diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java index d59a7ed0dc..4b24bb091b 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java @@ -10,5 +10,5 @@ * */ public enum Compiler { - JDK, JDK11, ECLIPSE; + JDK, JDK11, ECLIPSE, ECLIPSE11; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java index 41bcdb1000..6fdfa37268 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java @@ -22,5 +22,5 @@ /** * @return The compiler to use. */ - Compiler value(); + Compiler[] value(); } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java index a0617322ec..4dac535389 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java @@ -9,6 +9,8 @@ import java.util.List; import java.util.Set; +import javax.lang.model.SourceVersion; + import org.codehaus.plexus.compiler.CompilerConfiguration; import org.codehaus.plexus.compiler.CompilerException; import org.codehaus.plexus.compiler.CompilerResult; @@ -108,9 +110,10 @@ public CompilationOutcomeDescriptor compileInOtherClassloader(CompilationRequest config.setGeneratedSourcesDirectory( new File( sourceOutputDir ) ); config.setAnnotationProcessors( new String[] { MappingProcessor.class.getName() } ); config.setSourceFiles( sourceFiles ); + String version = getSourceVersion(); config.setShowWarnings( false ); - config.setSourceVersion( "1.8" ); - config.setTargetVersion( "1.8" ); + config.setSourceVersion( version ); + config.setTargetVersion( version ); for ( String option : compilationRequest.getProcessorOptions() ) { config.addCompilerCustomArgument( option, null ); @@ -128,13 +131,22 @@ public CompilationOutcomeDescriptor compileInOtherClassloader(CompilationRequest sourceDir, compilerResult ); } + + private static String getSourceVersion() { + SourceVersion latest = SourceVersion.latest(); + if ( latest == SourceVersion.RELEASE_8 ) { + return "1.8"; + } + return "11"; + } + } private static List buildEclipseCompilerClasspath() { String[] whitelist = new String[] { "tycho-compiler", - "org.eclipse.jdt.", + "ecj", "plexus-compiler-api", "plexus-component-annotations" }; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java index e297bd2c65..7c6d79e0fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java @@ -22,5 +22,5 @@ /** * @return The compiler to use. */ - Compiler value(); + Compiler[] value(); } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java index 4850a48704..50ab9c6eb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java @@ -68,12 +68,20 @@ protected boolean isIgnored(FrameworkMethod child) { protected boolean isIgnoredForCompiler(FrameworkMethod child) { EnabledOnCompiler enabledOnCompiler = child.getAnnotation( EnabledOnCompiler.class ); if ( enabledOnCompiler != null ) { - return enabledOnCompiler.value() != compiler; + for ( Compiler value : enabledOnCompiler.value() ) { + if ( value != compiler ) { + return true; + } + } } DisabledOnCompiler disabledOnCompiler = child.getAnnotation( DisabledOnCompiler.class ); if ( disabledOnCompiler != null ) { - return disabledOnCompiler.value() == compiler; + for ( Compiler value : disabledOnCompiler.value() ) { + if ( value == compiler ) { + return true; + } + } } return false; From a845197b0bab66608bdfbeee49bea77ad8c06582 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 10 Apr 2020 10:04:51 +0200 Subject: [PATCH 0451/1006] #2056: Handle null TypeMirror in uses and import gracefully Due to a bug in javac (JDK-8229535) for an annotation with Class values, instead of returning a TypeMirror with TypeKind#ERROR the compiler returns the string "". Eclipse doesn't have this problem currently. --- .../itest/tests/MavenIntegrationTest.java | 21 +++++++ .../usesTypeGenerationTest/generator/pom.xml | 43 +++++++++++++ .../UsesTypeGenerationProcessor.java | 60 +++++++++++++++++++ .../javax.annotation.processing.Processor | 4 ++ .../resources/usesTypeGenerationTest/pom.xml | 27 +++++++++ .../usesTypeGenerationTest/usage/pom.xml | 52 ++++++++++++++++ .../itest/usestypegeneration/usage/Order.java | 22 +++++++ .../usestypegeneration/usage/OrderDto.java | 22 +++++++ .../usestypegeneration/usage/OrderMapper.java | 20 +++++++ .../usage/GeneratedUsesTypeTest.java | 27 +++++++++ parent/pom.xml | 2 +- .../org/mapstruct/ap/MappingProcessor.java | 9 ++- .../model/source/DelegatingOptions.java | 17 ++++-- 13 files changed, 318 insertions(+), 8 deletions(-) create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/usestypegeneration/UsesTypeGenerationProcessor.java create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/pom.xml create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/Order.java create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderDto.java create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderMapper.java create mode 100644 integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 97da699cbe..13cd774754 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -135,4 +135,25 @@ void moduleInfoTest() { } + /** + * Tests usage of MapStruct with another processor that generates the uses type of a mapper. + */ + @ProcessorTest(baseDir = "usesTypeGenerationTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + void usesTypeGenerationTest() { + } + + /** + * Tests usage of MapStruct with another processor that generates the uses type of a mapper. + */ + @ProcessorTest(baseDir = "usesTypeGenerationTest", processorTypes = { + ProcessorTest.ProcessorType.ECLIPSE_JDT + }) + @EnabledForJreRange(min = JRE.JAVA_11) + // For some reason the second run with eclipse does not load the ModelElementProcessor(s) on java 8, + // therefore we run this only on Java 11 + void usesTypeGenerationTestEclipse() { + } + } diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml new file mode 100644 index 0000000000..6ac3a01297 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + org.mapstruct.itest + itest-usestypegeneration-aggregator + 1.0.0 + ../pom.xml + + + itest-usestypegeneration-generator + jar + + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -proc:none + + + + + + diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/usestypegeneration/UsesTypeGenerationProcessor.java b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/usestypegeneration/UsesTypeGenerationProcessor.java new file mode 100644 index 0000000000..2c17279ff8 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/java/org/mapstruct/itest/usestypegeneration/UsesTypeGenerationProcessor.java @@ -0,0 +1,60 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.usestypegeneration; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; + +/** + * Generate conversion uses. + * + * @author Filip Hrisafov + * + */ +@SupportedAnnotationTypes("*") +public class UsesTypeGenerationProcessor extends AbstractProcessor { + + private boolean hasRun = false; + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if ( !hasRun ) { + try { + JavaFileObject dto = processingEnv.getFiler().createSourceFile( "org.mapstruct.itest.usestypegeneration.usage.StringUtils" ); + Writer writer = dto.openWriter(); + + writer.append( "package org.mapstruct.itest.usestypegeneration.usage;" ); + writer.append( "\n" ); + writer.append( "public class StringUtils {" ); + writer.append( "\n" ); + writer.append( " public static String upperCase(String string) {" ); + writer.append( "\n" ); + writer.append( " return string == null ? null : string.toUpperCase();" ); + writer.append( "\n" ); + writer.append( " }" ); + writer.append( "\n" ); + writer.append( "}" ); + + writer.flush(); + writer.close(); + } + catch (IOException e) { + throw new RuntimeException( e ); + } + + hasRun = true; + } + + return false; + } +} diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000000..57be8919b5 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,4 @@ +# Copyright MapStruct Authors. +# +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 +org.mapstruct.itest.usestypegeneration.UsesTypeGenerationProcessor diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/pom.xml new file mode 100644 index 0000000000..7c0d555eaa --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + org.mapstruct.itest + itest-usestypegeneration-aggregator + pom + + + generator + usage + + diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml new file mode 100644 index 0000000000..e8b8d7bf07 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + + org.mapstruct.itest + itest-usestypegeneration-aggregator + 1.0.0 + ../pom.xml + + + itest-usestypegeneration-usage + jar + + + + junit + junit + 4.12 + test + + + org.mapstruct.itest + itest-usestypegeneration-generator + 1.0.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -XprintProcessorInfo + -XprintRounds + + -proc:none + + + + + diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/Order.java b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/Order.java new file mode 100644 index 0000000000..4d5a102aed --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/Order.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.usestypegeneration.usage; + +/** + * @author Filip Hrisafov + */ +public class Order { + + private String item; + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } +} diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderDto.java b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderDto.java new file mode 100644 index 0000000000..69951da5b2 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.usestypegeneration.usage; + +/** + * @author Filip Hrisafov + */ +public class OrderDto { + + private String item; + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } +} diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderMapper.java b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderMapper.java new file mode 100644 index 0000000000..8b33ab17d9 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/main/java/org/mapstruct/itest/usestypegeneration/usage/OrderMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.usestypegeneration.usage; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = StringUtils.class) +public interface OrderMapper { + + OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); + + OrderDto orderToDto(Order order); +} diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java new file mode 100644 index 0000000000..e715e66620 --- /dev/null +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.usestypegeneration.usage; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration test for using MapStruct with another annotation processor that generates the other mappers for uses + * + * @author Filip Hrisafov + */ +public class GeneratedUsesTypeTest { + + @Test + public void considersPropertiesOnGeneratedSourceAndTargetTypes() { + Order order = new Order(); + order.setItem( "my item" ); + + OrderDto dto = OrderMapper.INSTANCE.orderToDto( order ); + assertThat( dto.getItem() ).isEqualTo( "MY ITEM" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 37551e2ed2..3efe0ad8fb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -21,7 +21,7 @@ UTF-8 - 1.0.0.Alpha1 + 1.0.0.Alpha2 3.0.0-M1 3.0.0-M3 diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 546f06256f..e7e52be695 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -29,6 +29,7 @@ import javax.lang.model.element.Name; import javax.lang.model.element.QualifiedNameable; import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementKindVisitor6; import javax.tools.Diagnostic.Kind; @@ -177,7 +178,8 @@ else if ( !deferredMappers.isEmpty() ) { erroneousElementName = ( (QualifiedNameable) erroneousElement ).getQualifiedName().toString(); } else { - erroneousElementName = erroneousElement.getSimpleName().toString(); + erroneousElementName = + erroneousElement != null ? erroneousElement.getSimpleName().toString() : null; } // When running on Java 8 we need to fetch the deferredMapperElement again. @@ -265,9 +267,10 @@ processingEnv, options, roundContext, getDeclaredTypesNotToBeImported( mapperEle processMapperTypeElement( context, mapperElement ); } catch ( TypeHierarchyErroneousException thie ) { - Element erroneousElement = roundContext.getAnnotationProcessorContext() + TypeMirror erroneousType = thie.getType(); + Element erroneousElement = erroneousType != null ? roundContext.getAnnotationProcessorContext() .getTypeUtils() - .asElement( thie.getType() ); + .asElement( erroneousType ) : null; if ( options.isVerbose() ) { processingEnv.getMessager().printMessage( Kind.NOTE, "MapStruct: referred types not available (yet), deferring mapper: " diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index b9dc068d07..8bc6ab982b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -8,7 +8,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; @@ -21,6 +20,7 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** * Chain Of Responsibility Pattern. @@ -110,9 +110,18 @@ DelegatingOptions next() { } protected Set toDeclaredTypes(List in, Set next) { - Set result = in.stream() - .map( DeclaredType.class::cast ) - .collect( Collectors.toCollection( LinkedHashSet::new ) ); + Set result = new LinkedHashSet<>(); + for ( TypeMirror typeMirror : in ) { + if ( typeMirror == null ) { + // When a class used in uses or imports is created by another annotation processor + // then javac will not return correct TypeMirror with TypeKind#ERROR, but rather a string "" + // the gem tools would return a null TypeMirror in that case. + // Therefore throw TypeHierarchyErroneousException so we can postpone the generation of the mapper + throw new TypeHierarchyErroneousException( typeMirror ); + } + + result.add( (DeclaredType) typeMirror ); + } result.addAll( next ); return result; } From 6797afb647cbadb265cb518ca3569f90fdc1aae9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Apr 2020 01:06:03 +0200 Subject: [PATCH 0452/1006] Use exact message for Diagnostic test messages assertions --- .../model/BuilderFinisherMethodResolver.java | 19 ++- .../ap/internal/model/common/TypeFactory.java | 14 ++- .../ReferencedAccessibilityTest.java | 18 +-- .../ap/test/bugs/_1005/Issue1005Test.java | 16 ++- .../ap/test/bugs/_1029/Issue1029Test.java | 8 +- .../ap/test/bugs/_1153/Issue1153Test.java | 14 +-- .../ap/test/bugs/_1242/Issue1242Test.java | 17 +-- .../ap/test/bugs/_1283/Issue1283Test.java | 6 +- .../ap/test/bugs/_1353/Issue1353Test.java | 4 +- .../ap/test/bugs/_1457/Issue1457Test.java | 23 ++-- .../ap/test/bugs/_1698/Issue1698Test.java | 4 +- .../ap/test/bugs/_1904/Issue1904Test.java | 9 +- .../ap/test/bugs/_590/Issue590Test.java | 10 +- .../ap/test/bugs/_631/Issue631Test.java | 4 +- .../ap/test/bugs/_880/Issue880Test.java | 2 +- .../multiple/MultipleBuilderMapperTest.java | 36 ++---- .../simple/SimpleImmutableBuilderTest.java | 2 +- .../ErroneousCollectionMappingTest.java | 51 ++++---- .../forged/CollectionMappingTest.java | 23 ++-- .../immutabletarget/ImmutableProductTest.java | 2 +- .../collection/wildcard/WildCardTest.java | 8 +- .../ContextParameterErroneousTest.java | 2 +- .../erroneous/InvalidDateFormatTest.java | 24 ++-- .../conversion/lossy/LossyConversionTest.java | 22 ++-- .../ap/test/decorator/DecoratorTest.java | 2 +- .../test/defaultvalue/DefaultValueTest.java | 118 +++++++++--------- .../ap/test/dependency/OrderingTest.java | 6 +- .../AmbiguousAnnotatedFactoryTest.java | 18 +-- .../ambiguousfactorymethod/FactoryTest.java | 12 +- .../ErroneousMappingsTest.java | 14 +-- .../ErroneousPropertyMappingTest.java | 44 ++++--- .../typemismatch/ErroneousMappingsTest.java | 16 +-- .../ap/test/ignore/IgnorePropertyTest.java | 4 +- .../attribute/AttributeInheritanceTest.java | 3 +- .../complex/ComplexInheritanceTest.java | 12 +- .../InheritFromConfigTest.java | 54 ++++---- .../erroneous/ErroneousStreamMappingTest.java | 57 ++++----- .../forged/ForgedStreamMappingTest.java | 7 +- .../java8stream/wildcard/WildCardTest.java | 8 +- .../ap/test/mapperconfig/ConfigTest.java | 4 +- .../mappingcontrol/MappingControlTest.java | 20 ++- .../SuggestMostSimilarNameTest.java | 17 ++- ...DisablingNestedSimpleBeansMappingTest.java | 10 +- .../nestedbeans/DottedErrorMessageTest.java | 110 ++++++++-------- .../exclusions/ErroneousJavaInternalTest.java | 27 ++-- .../custom/ErroneousCustomExclusionTest.java | 8 +- .../NestedSourcePropertiesTest.java | 2 +- .../NullValuePropertyMappingTest.java | 10 +- .../InheritInverseConfigurationTest.java | 27 ++-- .../selection/generics/ConversionTest.java | 75 ++++++----- .../selection/qualifier/QualifierTest.java | 30 ++--- .../resulttype/InheritanceSelectionTest.java | 26 ++-- .../test/source/constants/ConstantsTest.java | 33 +++-- .../source/constants/SourceConstantsTest.java | 30 ++--- .../java/JavaDefaultExpressionTest.java | 14 +-- .../expressions/java/JavaExpressionTest.java | 4 +- .../ManySourceArgumentsTest.java | 10 +- .../targetthis/TargetThisMappingTest.java | 4 +- .../template/InheritConfigurationTest.java | 34 ++--- .../unmappedsource/UnmappedSourceTest.java | 8 +- .../unmappedtarget/UnmappedProductTest.java | 12 +- .../test/updatemethods/UpdateMethodsTest.java | 24 ++-- .../enum2enum/EnumToEnumMappingTest.java | 14 +-- .../enum2string/EnumToStringMappingTest.java | 4 +- .../string2enum/StringToEnumMappingTest.java | 4 +- .../ap/test/verbose/VerboseTest.java | 10 +- .../compilation/annotation/Diagnostic.java | 8 ++ .../model/DiagnosticDescriptor.java | 21 +++- .../testutil/runner/CompilingStatement.java | 28 +++-- 69 files changed, 753 insertions(+), 588 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index d72e7cef9c..9b7912f752 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -7,10 +7,12 @@ import java.util.Collection; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.VariableElement; import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.util.Extractor; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -23,6 +25,19 @@ public class BuilderFinisherMethodResolver { private static final String DEFAULT_BUILD_METHOD_NAME = "build"; + private static final Extractor EXECUTABLE_ELEMENT_NAME_EXTRACTOR = + executableElement -> { + StringBuilder sb = new StringBuilder( executableElement.getSimpleName() ); + + sb.append( '(' ); + for ( VariableElement parameter : executableElement.getParameters() ) { + sb.append( parameter ); + } + + sb.append( ')' ); + return sb.toString(); + }; + private BuilderFinisherMethodResolver() { } @@ -57,7 +72,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp buildMethodPattern, builderType.getBuilder(), builderType.getBuildingType(), - Strings.join( buildMethods, ", " ) + Strings.join( buildMethods, ", ", EXECUTABLE_ELEMENT_NAME_EXTRACTOR ) ); } else { @@ -68,7 +83,7 @@ public static MethodReference getBuilderFinisherMethod(Method method, BuilderTyp buildMethodPattern, builderType.getBuilder(), builderType.getBuildingType(), - Strings.join( buildMethods, ", " ) + Strings.join( buildMethods, ", ", EXECUTABLE_ELEMENT_NAME_EXTRACTOR ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 822ba0dd6d..594c2c7f70 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -68,7 +68,19 @@ public class TypeFactory { private static final Extractor BUILDER_INFO_CREATION_METHOD_EXTRACTOR = - builderInfo -> builderInfo.getBuilderCreationMethod().toString(); + builderInfo -> { + ExecutableElement builderCreationMethod = builderInfo.getBuilderCreationMethod(); + + StringBuilder sb = new StringBuilder( builderCreationMethod.getSimpleName() ); + + sb.append( '(' ); + for ( VariableElement parameter : builderCreationMethod.getParameters() ) { + sb.append( parameter ); + } + + sb.append( ')' ); + return sb.toString(); + }; private final Elements elementUtils; private final Types typeUtils; diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 424b815718..3819545090 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -38,9 +38,9 @@ public class ReferencedAccessibilityTest { @Diagnostic(type = SourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 22, - messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + - ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + - ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") + message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + + ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + + ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessPrivateMethodInReferenced() { @@ -66,9 +66,9 @@ public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() { } @Diagnostic(type = SourceTargetMapperDefaultOther.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + - ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + - ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") + message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + + ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + + ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() { @@ -89,9 +89,9 @@ public void shouldBeAbleToAccessProtectedMethodInBase() { } @Diagnostic(type = AbstractSourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 23, - messageRegExp = "Unmapped target property: \"bar\"\\. Mapping from property \"org\\.mapstruct\\.ap\\" + - ".test\\.accessibility\\.referenced\\.ReferencedSource referencedSource\" to \"org\\.mapstruct\\" + - ".ap\\.test\\.accessibility\\.referenced\\.ReferencedTarget referencedTarget\"") + message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + + ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + + ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessPrivateMethodInBase() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index 7a58d56fb2..7f97d2db51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -35,7 +35,8 @@ public class Issue1005Test { @Diagnostic(type = Issue1005ErroneousAbstractResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "The result type .*\\.AbstractEntity may not be an abstract class nor interface.") + message = "The result type org.mapstruct.ap.test.bugs._1005.AbstractEntity may not be an " + + "abstract class nor interface.") }) public void shouldFailDueToAbstractResultType() { } @@ -47,8 +48,9 @@ public void shouldFailDueToAbstractResultType() { @Diagnostic(type = Issue1005ErroneousAbstractReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "The return type .*\\.AbstractEntity is an abstract class or interface. Provide a non" + - " abstract / non interface result type or a factory method.") + message = + "The return type org.mapstruct.ap.test.bugs._1005.AbstractEntity is an abstract class or " + + "interface. Provide a non abstract / non interface result type or a factory method.") }) public void shouldFailDueToAbstractReturnType() { } @@ -60,7 +62,8 @@ public void shouldFailDueToAbstractReturnType() { @Diagnostic(type = Issue1005ErroneousInterfaceResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "The result type .*\\.HasPrimaryKey may not be an abstract class nor interface.") + message = "The result type org.mapstruct.ap.test.bugs._1005.HasPrimaryKey may not be an " + + "abstract class nor interface.") }) public void shouldFailDueToInterfaceResultType() { } @@ -72,8 +75,9 @@ public void shouldFailDueToInterfaceResultType() { @Diagnostic(type = Issue1005ErroneousInterfaceReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "The return type .*\\.HasKey is an abstract class or interface. Provide a non " + - "abstract / non interface result type or a factory method.") + message = + "The return type org.mapstruct.ap.test.bugs._1005.HasKey is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method.") }) public void shouldFailDueToInterfaceReturnType() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index 86c55597d5..afebcbef43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -29,12 +29,12 @@ public class Issue1029Test { @Test @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = Kind.WARNING, line = 26, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unmapped target properties: \"knownProp, lastUpdated, computedMapping\"\\."), + message = "Unmapped target properties: \"knownProp, lastUpdated, computedMapping\"."), @Diagnostic(kind = Kind.WARNING, line = 37, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unmapped target property: \"lastUpdated\"\\."), + message = "Unmapped target property: \"lastUpdated\"."), @Diagnostic(kind = Kind.ERROR, line = 42, type = ErroneousIssue1029Mapper.class, - messageRegExp = "Unknown property \"unknownProp\" in result type " + - "org.mapstruct.ap.test.bugs._1029.ErroneousIssue1029Mapper.Deck\\. Did you mean \"knownProp\"?") + message = "Unknown property \"unknownProp\" in result type " + + "org.mapstruct.ap.test.bugs._1029.ErroneousIssue1029Mapper.Deck. Did you mean \"knownProp\"?") }) public void reportsProperWarningsAndError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index 3ed3e20db1..f4142fe641 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -27,19 +27,19 @@ public class Issue1153Test { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = "Property \"readOnly\" has no write accessor in " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), + message = "Property \"readOnly\" has no write accessor in " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Property \"nestedTarget.readOnly\" has no write accessor in " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\."), + message = "Property \"nestedTarget.readOnly\" has no write accessor in " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, - messageRegExp = "Unknown property \"nestedTarget2.writable2\" in result type " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target\\. " + - "Did you mean \"nestedTarget2\\.writable\"") + message = "Unknown property \"nestedTarget2.writable2\" in result type " + + "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target. " + + "Did you mean \"nestedTarget2.writable\"?") }) @Test public void shouldReportErrorsCorrectly() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 94a7e3bbae..6cf0ba401f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -58,16 +58,19 @@ public void factoryMethodWithSourceParamIsChosen() { @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Ambiguous factory methods found for creating .*TargetB:" - + " .*TargetB anotherTargetBCreator\\(.*SourceB source\\)," - + " .*TargetB .*TargetFactories\\.createTargetB\\(.*SourceB source," - + " @TargetType .*Class<.*TargetB> clazz\\)," - + " .*TargetB .*TargetFactories\\.createTargetB\\(@TargetType java.lang.Class<.*TargetB> clazz\\)," - + " .*TargetB .*TargetFactories\\.createTargetB\\(\\)."), + message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.bugs._1242.TargetB: org" + + ".mapstruct.ap.test.bugs._1242.TargetB anotherTargetBCreator(org.mapstruct.ap.test.bugs._1242" + + ".SourceB source), org.mapstruct.ap.test.bugs._1242.TargetB org.mapstruct.ap.test.bugs._1242" + + ".TargetFactories.createTargetB(org.mapstruct.ap.test.bugs._1242.SourceB source, @TargetType java" + + ".lang.Class clazz), org.mapstruct.ap.test.bugs._1242" + + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB(@TargetType java.lang" + + ".Class clazz), org.mapstruct.ap.test.bugs._1242" + + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB()."), @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = ".*TargetB does not have an accessible parameterless constructor\\.") + message = "org.mapstruct.ap.test.bugs._1242.TargetB does not have an accessible parameterless " + + "constructor.") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index 9e33e2f079..4d875017f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -33,7 +33,8 @@ public class Issue1283Test { @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22L, - messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" + message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible parameterless " + + "constructor." ) } ) @@ -48,7 +49,8 @@ public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 18L, - messageRegExp = ".*\\._1283\\.Source does not have an accessible parameterless constructor" + message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible parameterless " + + "constructor." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java index da89288013..953ecf8d17 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java @@ -35,13 +35,13 @@ public class Issue1353Test { @Diagnostic (type = Issue1353Mapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 22, - messageRegExp = "The property named \" source.string1\" has whitespaces," + message = "The property named \" source.string1\" has whitespaces," + " using trimmed property \"source.string1\" instead." ), @Diagnostic (type = Issue1353Mapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 22, - messageRegExp = "The property named \"string2 \" has whitespaces," + message = "The property named \"string2 \" has whitespaces," + " using trimmed property \"string2\" instead." ) } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java index 6d30ce345d..910a1e7280 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java @@ -46,11 +46,12 @@ public void setup() { @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic( - messageRegExp = - "Lifecycle method has multiple matching parameters \\(e\\. g\\. same type\\), in this case " + - "please ensure to name the parameters in the lifecycle and mapping method identical\\. This " + - "lifecycle method will not be used for the mapping method '.*\\.TargetBook mapBook\\(" + - ".*\\.SourceBook sourceBook, .*\\.String authorFirstName, .*\\.String authorLastName\\)'\\.", + message = + "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to " + + "name the parameters in the lifecycle and mapping method identical. This lifecycle method will " + + "not be used for the mapping method 'org.mapstruct.ap.test.bugs._1457.TargetBook mapBook(org" + + ".mapstruct.ap.test.bugs._1457.SourceBook sourceBook, java.lang.String authorFirstName, java.lang" + + ".String authorLastName)'.", kind = javax.tools.Diagnostic.Kind.WARNING, line = 43 ) @@ -108,16 +109,16 @@ private void assertTargetBookMatchesSourceBook(TargetBook targetBook) { @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic( - messageRegExp = - "Lifecycle method has multiple matching parameters \\(e\\. g\\. same type\\), in this case " + - "please ensure to name the parameters in the lifecycle and mapping method identical\\. This " + - "lifecycle method will not be used for the mapping method '.*\\.TargetBook mapBook\\(" + - ".*\\.SourceBook sourceBook, .*\\.String authorFirstName, .*\\.String authorLastName\\)'\\.", + message = + "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to " + + "name the parameters in the lifecycle and mapping method identical. This lifecycle method will " + + "not be used for the mapping method 'org.mapstruct.ap.test.bugs._1457.TargetBook mapBook(org" + + ".mapstruct.ap.test.bugs._1457.SourceBook sourceBook, java.lang.String authorFirstName, java.lang" + + ".String authorLastName)'.", kind = javax.tools.Diagnostic.Kind.WARNING, line = 22 ) ) public void testMapperWithoutMatchingParameterNames() { - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java index 77f480346a..47ab19f1dd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java @@ -24,7 +24,9 @@ public class Issue1698Test { diagnostics = { @Diagnostic(type = Erroneous1698Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - messageRegExp = "Can't map property.*") + message = "Can't map property \"java.lang.String rabbit\" to \"org.mapstruct.ap.test.bugs._1698" + + ".Erroneous1698Mapper.Rabbit rabbit\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.bugs._1698.Erroneous1698Mapper.Rabbit map(java.lang.String value)\".") }) public void testErrorMessage() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java index 7c2b95bbfb..b6e0b03cf7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java @@ -36,13 +36,12 @@ public class Issue1904Test { type = Issue1904Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 14, - messageRegExp = ".*No implementation was created for Issue1904Mapper due to having a problem in the " + - "erroneous element .*\\.CarManualDto. Hint: this often means that some other annotation processor " + - "was supposed to process the erroneous element. You can also enable MapStruct verbose mode by " + - "setting -Amapstruct.verbose=true as a compilation argument." + message = "No implementation was created for Issue1904Mapper due to having a problem in the erroneous " + + "element org.mapstruct.ap.test.bugs._1904.Issue1904Mapper.CarManualDto. Hint: this often means that " + + "some other annotation processor was supposed to process the erroneous element. You can also enable " + + "MapStruct verbose mode by setting -Amapstruct.verbose=true as a compilation argument." ) }) public void shouldHaveCompilationErrorIfMapperCouldNotBeCreated() { - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java index 28f06b2acb..e716d70a34 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java @@ -24,9 +24,13 @@ public class Issue590Test { @Test @ExpectedCompilationOutcome(value = CompilationResult.FAILED, - diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, - kind = Kind.ERROR, - messageRegExp = "Can't map property \"java\\.lang\\.String prop\" to \"[^ ]+ prop\"") }) + diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapper.class, + kind = Kind.ERROR, + message = "Can't map property \"java.lang.String prop\" to \"java.util.logging.XMLFormatter " + + "prop\". Consider to declare/implement a mapping method: \"java.util.logging.XMLFormatter map" + + "(java.lang.String value)\".") + }) public void showsCantMapPropertyError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java index 5050c76ea0..5d582d1c1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java @@ -30,11 +30,11 @@ public class Issue631Test { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "Can't generate mapping method for a generic type variable target."), + message = "Can't generate mapping method for a generic type variable target."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 24, - messageRegExp = "Can't generate mapping method for a generic type variable source.") + message = "Can't generate mapping method for a generic type variable source.") } ) @WithClasses({ErroneousSourceTargetMapper.class, Base1.class, Base2.class}) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index 6ff17597c3..2a80961bc5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -41,7 +41,7 @@ public class Issue880Test { value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic(kind = Kind.WARNING, type = UsesConfigFromAnnotationMapper.class, line = 16, - messageRegExp = "Unmapped target property: \"core\"\\.")) + message = "Unmapped target property: \"core\".")) public void compilationSucceedsAndAppliesCorrectComponentModel() { generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java index ac3e0fc6f6..21b9566c4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -40,23 +40,17 @@ public class MultipleBuilderMapperTest { type = ErroneousMoreThanOneBuildMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = "No build method \"build\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + - "for \".*\\.multiple\\.build\\.Process\"\\. " + - "Found methods: " + - "\".*wrongCreate\\(\\) ?, " + - ".*create\\(\\) ?\"\\. " + - "Consider to add @Builder in order to select the correct build method." + message = "No build method \"build\" found in \"org.mapstruct.ap.test.builder.multiple.build.Process" + + ".Builder\" for \"org.mapstruct.ap.test.builder.multiple.build.Process\". Found methods: " + + "\"wrongCreate(), create()\". Consider to add @Builder in order to select the correct build method." ), @Diagnostic( type = ErroneousMoreThanOneBuildMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "No build method \"missingBuild\" found " + - "in \".*\\.multiple\\.build\\.Process\\.Builder\" " + - "for \".*\\.multiple\\.build\\.Process\"\\. " + - "Found methods: " + - "\".*wrongCreate\\(\\) ?, " + - ".*create\\(\\) ?\"\\." + message = "No build method \"missingBuild\" found in \"org.mapstruct.ap.test.builder.multiple.build" + + ".Process.Builder\" for \"org.mapstruct.ap.test.builder.multiple.build.Process\". Found methods: " + + "\"wrongCreate(), create()\"." ) }) @Test @@ -72,12 +66,10 @@ public void moreThanOneBuildMethod() { type = ErroneousMoreThanOneBuildMethodWithMapperDefinedMappingMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 18, - messageRegExp = - "No build method \"mapperBuild\" found in \".*\\.multiple\\.build\\.Process\\.Builder\" " + - "for \".*\\.multiple\\.build\\.Process\"\\. " + - "Found methods: " + - "\".*wrongCreate\\(\\) ?, " + - ".*create\\(\\) ?\"\\." + message = + "No build method \"mapperBuild\" found in \"org.mapstruct.ap.test.builder.multiple.build.Process" + + ".Builder\" for \"org.mapstruct.ap.test.builder.multiple.build.Process\". Found methods: " + + "\"wrongCreate(), create()\"." ) }) @Test @@ -118,11 +110,9 @@ public void builderMappingMapperConfigDefined() { type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 11, - messageRegExp = "More than one builder creation method for \".*\\.multiple\\.builder.Case\"\\. " + - "Found methods: " + - "\".*wrongBuilder\\(\\) ?, " + - ".*builder\\(\\) ?\"\\. " + - "Builder will not be used\\. Consider implementing a custom BuilderProvider SPI\\." + message = "More than one builder creation method for \"org.mapstruct.ap.test.builder.multiple.builder" + + ".Case\". Found methods: \"wrongBuilder(), builder()\". Builder will not be used. Consider " + + "implementing a custom BuilderProvider SPI." ) }) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index a7e579b290..3bc4e91ed8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -57,7 +57,7 @@ public void testSimpleImmutableBuilderHappyPath() { kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousSimpleBuilderMapper.class, line = 21, - messageRegExp = "Unmapped target property: \"name\"\\.")) + message = "Unmapped target property: \"name\".")) public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index feefb92b40..0aaf28d318 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -35,11 +35,11 @@ public class ErroneousCollectionMappingTest { @Diagnostic(type = ErroneousCollectionToNonCollectionMapper.class, kind = Kind.ERROR, line = 15, - messageRegExp = "Can't generate mapping method from iterable type to non-iterable type"), + message = "Can't generate mapping method from iterable type to non-iterable type."), @Diagnostic(type = ErroneousCollectionToNonCollectionMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't generate mapping method from non-iterable type to iterable type") + message = "Can't generate mapping method from non-iterable type to iterable type.") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection() { @@ -54,9 +54,9 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection( @Diagnostic(type = ErroneousCollectionToPrimitivePropertyMapper.class, kind = Kind.ERROR, line = 13, - messageRegExp = "Can't map property \"java.util.List strings\" to \"int strings\". " - + "Consider to declare/implement a mapping method: \"int map\\(java.util.List" - + " value\\)\"") + message = "Can't map property \"java.util.List strings\" to \"int strings\". " + + "Consider to declare/implement a mapping method: \"int map(java.util.List" + + " value)\".") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @@ -71,7 +71,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @Diagnostic(type = EmptyItererableMappingMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + message = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them.") } ) @@ -87,7 +87,7 @@ public void shouldFailOnEmptyIterableAnnotation() { @Diagnostic(type = EmptyMapMappingMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "'nullValueMappingStrategy', 'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', " + message = "'nullValueMappingStrategy', 'keyDateFormat', 'keyQualifiedBy', 'keyTargetType', " + "'valueDateFormat', 'valueQualfiedBy' and 'valueTargetType' are all undefined in @MapMapping, " + "define at least one of them.") } @@ -104,9 +104,10 @@ public void shouldFailOnEmptyMapAnnotation() { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "No target bean properties found: can't map Collection element \".*WithProperties " - + "withProperties\" to \".*NoProperties noProperties\". Consider to declare/implement " - + "a mapping method: \".*NoProperties map\\(.*WithProperties value\\)") + message = "No target bean properties found: can't map Collection element \"org.mapstruct.ap.test" + + ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + + ".mapstruct.ap.test.WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFound() { @@ -121,9 +122,9 @@ public void shouldFailOnNoElementMappingFound() { @Diagnostic(type = ErroneousCollectionNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - messageRegExp = - "Can't map collection element \".*AttributedString\" to \".*String \". " + - "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + message = "Can't map collection element \"java.text.AttributedString\" to \"java.lang.String \". " + + "Consider to declare/implement a mapping method: \"java.lang.String map(java.text" + + ".AttributedString value)\".") } ) public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @@ -138,10 +139,10 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "No target bean properties found: can't map Map key \".*WithProperties " - + "withProperties\" to " - + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: " - + "\".*NoProperties map\\(.*WithProperties value\\)" ) + message = "No target bean properties found: can't map Map key \"org.mapstruct.ap.test.WithProperties " + + "withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". Consider to " + + "declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org.mapstruct.ap" + + ".test.WithProperties value)\".") } ) public void shouldFailOnNoKeyMappingFound() { @@ -156,8 +157,8 @@ public void shouldFailOnNoKeyMappingFound() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - messageRegExp = "Can't map map key \".*AttributedString\" to \".*String \". " + - "Consider to declare/implement a mapping method: \".*String map\\(.*AttributedString value\\)") + message = "Can't map map key \"java.text.AttributedString\" to \"java.lang.String \". Consider to " + + "declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)\".") } ) public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @@ -172,10 +173,10 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "No target bean properties found: can't map Map value \".*WithProperties " - + "withProperties\" to " - + "\".*NoProperties noProperties\". Consider to declare/implement a mapping method: " - + "\".*NoProperties map\\(.*WithProperties value\\)" ) + message = "No target bean properties found: can't map Map value \"org.mapstruct.ap.test" + + ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + + ".mapstruct.ap.test.WithProperties value)\".") } ) public void shouldFailOnNoValueMappingFound() { @@ -190,8 +191,8 @@ public void shouldFailOnNoValueMappingFound() { @Diagnostic(type = ErroneousCollectionNoValueMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - messageRegExp = "Can't map map value \".*AttributedString\" to \".*String \". " + - "Consider to declare/implement a mapping method: \".*String map(.*AttributedString value)") + message = "Can't map map value \"java.text.AttributedString\" to \"java.lang.String \". Consider to " + + "declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)\".") } ) public void shouldFailOnNoValueMappingFoundWithDisabledAuto() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index c538318fd7..50c2ffcb96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -75,7 +75,8 @@ public void shouldForgeNewMapMappingMethod() { } @Test - @WithClasses({ ErroneousCollectionNonMappableSetMapper.class, + @WithClasses({ + ErroneousCollectionNonMappableSetMapper.class, ErroneousNonMappableSetSource.class, ErroneousNonMappableSetTarget.class, Foo.class, @@ -87,8 +88,10 @@ public void shouldForgeNewMapMappingMethod() { @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "No target bean properties found: can't map Collection element \".* nonMappableSet\" " - + "to \".* nonMappableSet\". Consider to declare/implement a mapping method: .*." ), + message = "No target bean properties found: can't map Collection element \"org.mapstruct.ap" + + ".test.collection.forged.Foo nonMappableSet\" to \"org.mapstruct.ap.test.collection.forged.Bar " + + "nonMappableSet\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + + ".collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), } ) public void shouldGenerateNonMappleMethodForSetMapping() { @@ -107,15 +110,17 @@ public void shouldGenerateNonMappleMethodForSetMapping() { @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "No target bean properties found: can't map Map key \".* nonMappableMap\\{:key\\}\" " - + "to \".* " - + "nonMappableMap\\{:key\\}\". Consider to declare/implement a mapping method: .*." ), + message = "No target bean properties found: can't map Map key \"org.mapstruct.ap.test" + + ".collection.forged.Foo nonMappableMap{:key}\" to \"org.mapstruct.ap.test.collection.forged.Bar " + + "nonMappableMap{:key}\". Consider to declare/implement a mapping method: \"org.mapstruct.ap" + + ".test.collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "No target bean properties found: can't map Map value \".* " - + "nonMappableMap\\{:value\\}\" to \".* nonMappableMap\\{:value\\}\". " - + "Consider to declare/implement a mapping method: .*." ), + message = "No target bean properties found: can't map Map value \"org.mapstruct.ap.test" + + ".collection.forged.Foo nonMappableMap{:value}\" to \"org.mapstruct.ap.test.collection.forged.Bar" + + " nonMappableMap{:value}\". Consider to declare/implement a mapping method: \"org.mapstruct.ap" + + ".test.collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), } ) public void shouldGenerateNonMappleMethodForMapMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index 4c4932e2c4..85dff16393 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -53,7 +53,7 @@ public void shouldHandleImmutableTarget() { @Diagnostic(type = ErroneousCupboardMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "No write accessor found for property \"content\" in target type.") + message = "No write accessor found for property \"content\" in target type.") } ) public void testShouldFailOnPropertyMappingNoPropertySetterOnlyGetter() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index 4f5c161a20..aa09cdbc4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -87,7 +87,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { @Diagnostic( type = ErroneousIterableSuperBoundSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Can't generate mapping method for a wildcard super bound source." ) + message = "Can't generate mapping method for a wildcard super bound source." ) } ) public void shouldFailOnSuperBoundSource() { @@ -101,7 +101,7 @@ public void shouldFailOnSuperBoundSource() { @Diagnostic( type = ErroneousIterableExtendsBoundTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Can't generate mapping method for a wildcard extends bound result." ) + message = "Can't generate mapping method for a wildcard extends bound result." ) } ) public void shouldFailOnExtendsBoundTarget() { @@ -115,7 +115,7 @@ public void shouldFailOnExtendsBoundTarget() { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMethod.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Can't generate mapping method for a generic type variable target." ) + message = "Can't generate mapping method for a generic type variable target." ) } ) public void shouldFailOnTypeVarSource() { @@ -129,7 +129,7 @@ public void shouldFailOnTypeVarSource() { @Diagnostic( type = ErroneousIterableTypeVarBoundMapperOnMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Can't generate mapping method for a generic type variable source." ) + message = "Can't generate mapping method for a generic type variable source." ) } ) public void shouldFailOnTypeVarTarget() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java index db72521e9a..2569973372 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -41,7 +41,7 @@ public class ContextParameterErroneousTest { kind = Kind.ERROR, line = 20, type = ErroneousNodeMapperWithNonUniqueContextTypes.class, - messageRegExp = "The types of @Context parameters must be unique")) + message = "The types of @Context parameters must be unique.")) public void reportsNonUniqueContextParamType() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java index 669b4cfdad..8f630df22c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -33,51 +33,51 @@ public class InvalidDateFormatTest { @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 25, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 26, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + message = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 27, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + message = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 28, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + message = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"\\."), + message = "Given date format \"qwertz\" is invalid. Message: \"Unknown pattern letter: r\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 30, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 31, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 32, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 33, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern component: q\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 37, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 40, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\""), + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"."), @Diagnostic(type = ErroneousFormatMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 43, - messageRegExp = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\"") + message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\".") }) @Test public void shouldFailWithInvalidDateFormats() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index a9bd35c2b5..ae61da8e19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -58,7 +58,7 @@ public void testNoErrorCase() { @Diagnostic(type = ErroneousKitchenDrawerMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "Can't map property \"long numberOfForks\". It has a possibly lossy conversion from " + message = "Can't map property \"long numberOfForks\". It has a possibly lossy conversion from " + "long to int.") }) public void testConversionFromLongToInt() { @@ -71,7 +71,7 @@ public void testConversionFromLongToInt() { @Diagnostic(type = KitchenDrawerMapper2.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - messageRegExp = "property \"java.math.BigInteger numberOfKnifes\" has a possibly lossy conversion " + message = "property \"java.math.BigInteger numberOfKnifes\" has a possibly lossy conversion " + "from java.math.BigInteger to java.lang.Integer.") }) public void testConversionFromBigIntegerToInteger() { @@ -84,8 +84,8 @@ public void testConversionFromBigIntegerToInteger() { @Diagnostic(type = ErroneousKitchenDrawerMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "org.mapstruct.ap.test.conversion.lossy.VerySpecialNumber numberOfSpoons\". It has " - + "a possibly lossy conversion from java.math.BigInteger to java.lang.Long") + message = "Can't map property \"org.mapstruct.ap.test.conversion.lossy.VerySpecialNumber " + + "numberOfSpoons\". It has a possibly lossy conversion from java.math.BigInteger to java.lang.Long.") }) public void test2StepConversionFromBigIntegerToLong() { } @@ -97,7 +97,7 @@ public void test2StepConversionFromBigIntegerToLong() { @Diagnostic(type = ErroneousKitchenDrawerMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "Can't map property \"java.lang.Double depth\". It has a possibly lossy conversion " + message = "Can't map property \"java.lang.Double depth\". It has a possibly lossy conversion " + "from java.lang.Double to float.") }) public void testConversionFromDoubleToFloat() { @@ -110,7 +110,7 @@ public void testConversionFromDoubleToFloat() { @Diagnostic(type = ErroneousKitchenDrawerMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "\"java.math.BigDecimal length\". It has a possibly lossy conversion from " + message = "Can't map property \"java.math.BigDecimal length\". It has a possibly lossy conversion from " + "java.math.BigDecimal to java.lang.Float.") }) public void testConversionFromBigDecimalToFloat() { @@ -123,7 +123,7 @@ public void testConversionFromBigDecimalToFloat() { @Diagnostic(type = KitchenDrawerMapper6.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - messageRegExp = "property \"double height\" has a possibly lossy conversion from double to float.") + message = "property \"double height\" has a possibly lossy conversion from double to float.") }) public void test2StepConversionFromDoubleToFloat() { } @@ -135,8 +135,8 @@ public void test2StepConversionFromDoubleToFloat() { @Diagnostic(type = ListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 21, - messageRegExp = "collection element has a possibly lossy conversion from java.math.BigDecimal to " - + "java.math.BigInteger") + message = "collection element has a possibly lossy conversion from java.math.BigDecimal to " + + "java.math.BigInteger.") }) public void testListElementConversion() { } @@ -148,11 +148,11 @@ public void testListElementConversion() { @Diagnostic(type = MapMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 19, - messageRegExp = "map key has a possibly lossy conversion from java.lang.Long to java.lang.Integer."), + message = "map key has a possibly lossy conversion from java.lang.Long to java.lang.Integer."), @Diagnostic(type = MapMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 19, - messageRegExp = "map value has a possibly lossy conversion from java.lang.Double to java.lang.Float.") + message = "map value has a possibly lossy conversion from java.lang.Double to java.lang.Float.") }) public void testMapElementConversion() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java index 84a5657930..59d59eb987 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java @@ -182,7 +182,7 @@ public void shouldApplyCustomMappers() { @Diagnostic(type = ErroneousPersonMapper.class, kind = Kind.ERROR, line = 14, - messageRegExp = "Specified decorator type is no subtype of the annotated mapper type") + message = "Specified decorator type is no subtype of the annotated mapper type.") } ) public void shouldRaiseErrorInCaseWrongDecoratorTypeIsGiven() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index e554e4a4b2..f2054b90b9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.defaultvalue; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.defaultvalue.other.Continent; @@ -17,19 +15,21 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@IssueKey( "600" ) -@RunWith( AnnotationProcessorTestRunner.class ) -@WithClasses( { - CountryEntity.class, - CountryDts.class, - Continent.class -} ) +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("600") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CountryEntity.class, + CountryDts.class, + Continent.class +}) public class DefaultValueTest { @Test - @WithClasses( { - Region.class, - CountryMapper.class - } ) + @WithClasses({ + Region.class, + CountryMapper.class + }) /** * Checks: *
        @@ -56,10 +56,10 @@ public void shouldDefaultValueAndUseConstantExpression() { } @Test - @WithClasses( { - Region.class, - CountryMapper.class - } ) + @WithClasses({ + Region.class, + CountryMapper.class + }) public void shouldIgnoreDefaultValue() { CountryEntity countryEntity = new CountryEntity(); countryEntity.setCode( "US" ); @@ -77,10 +77,10 @@ public void shouldIgnoreDefaultValue() { } @Test - @WithClasses( { - Region.class, - CountryMapper.class - } ) + @WithClasses({ + Region.class, + CountryMapper.class + }) public void shouldHandleUpdateMethodsFromDtsToEntity() { CountryEntity countryEntity = new CountryEntity(); CountryDts countryDts = new CountryDts(); @@ -95,10 +95,10 @@ public void shouldHandleUpdateMethodsFromDtsToEntity() { } @Test - @WithClasses( { - Region.class, - CountryMapper.class - } ) + @WithClasses({ + Region.class, + CountryMapper.class + }) public void shouldHandleUpdateMethodsFromEntityToEntity() { CountryEntity source = new CountryEntity(); CountryEntity target = new CountryEntity(); @@ -114,45 +114,49 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { } @Test - @WithClasses( { - ErroneousMapper.class, - Region.class, - } ) + @WithClasses({ + ErroneousMapper.class, + Region.class, + }) @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ErroneousMapper.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 18, - messageRegExp = "Constant and default value are both defined in @Mapping," - + " either define a defaultValue or a constant." ), - @Diagnostic(type = ErroneousMapper.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 20, - messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") - } + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + message = "Constant and default value are both defined in @Mapping, either define a defaultValue or a" + + " constant."), + @Diagnostic(type = ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Can't map property \"org.mapstruct.ap.test.defaultvalue.Region region\" to \"java.lang" + + ".String region\". Consider to declare/implement a mapping method: \"java.lang.String map(org" + + ".mapstruct.ap.test.defaultvalue.Region value)\".") + } ) public void errorOnDefaultValueAndConstant() { } @Test - @WithClasses( { - ErroneousMapper2.class, - Region.class, - } ) + @WithClasses({ + ErroneousMapper2.class, + Region.class, + }) @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ErroneousMapper2.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 18, - messageRegExp = "Expression and default value are both defined in @Mapping," - + " either define a defaultValue or an expression." ), - @Diagnostic(type = ErroneousMapper2.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 20, - messageRegExp = "Can't map property \".*Region region\" to \".*String region\"\\. Consider") - } + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapper2.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + message = "Expression and default value are both defined in @Mapping, either define a defaultValue or" + + " an expression."), + @Diagnostic(type = ErroneousMapper2.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Can't map property \"org.mapstruct.ap.test.defaultvalue.Region region\" to \"java.lang" + + ".String region\". Consider to declare/implement a mapping method: \"java.lang.String map(org" + + ".mapstruct.ap.test.defaultvalue.Region value)\".") + } ) public void errorOnDefaultValueAndExpression() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index ede43320dc..0a2ed604cf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -63,8 +63,8 @@ public void shouldApplySeveralDependenciesConfiguredForOneProperty() { @Diagnostic(type = ErroneousAddressMapperWithCyclicDependency.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "Cycle\\(s\\) between properties given via dependsOn\\(\\): lastName -> middleName -> " - + "firstName -> lastName" + message = "Cycle(s) between properties given via dependsOn(): lastName -> middleName -> " + + "firstName -> lastName." ) } ) @@ -80,7 +80,7 @@ public void shouldReportErrorIfDependenciesContainCycle() { @Diagnostic(type = ErroneousAddressMapperWithUnknownPropertyInDependsOn.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = "\"doesnotexist\" is no property of the method return type" + message = "\"doesnotexist\" is no property of the method return type." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 64191955cb..561b53effd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -30,18 +30,18 @@ public class AmbiguousAnnotatedFactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Ambiguous factory methods found for creating " - + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar: " - + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar " - + "createBar\\(org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Foo foo\\), " - + "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar " - + ".*AmbiguousBarFactory.createBar\\(org.mapstruct.ap.test.erroneous." - + "ambiguousannotatedfactorymethod.Foo foo\\)."), + message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.Bar: org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.Bar createBar(org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.Foo foo), org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.Bar org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.AmbiguousBarFactory.createBar(org.mapstruct.ap.test.erroneous" + + ".ambiguousannotatedfactorymethod.Foo foo)."), @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = ".*\\.ambiguousannotatedfactorymethod.Bar does not have an accessible parameterless " + - "constructor\\.") + message = "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar does not have an " + + "accessible parameterless constructor.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index e54602b01a..82886eb038 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -34,15 +34,15 @@ public class FactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Ambiguous factory methods found for creating " - + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar: " - + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar createBar\\(\\), " - + "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar .*BarFactory.createBar\\(\\)."), + message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + + ".ambiguousfactorymethod.Bar: org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar " + + "createBar(), org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar org.mapstruct.ap.test" + + ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar()."), @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = ".*\\.ambiguousfactorymethod\\.Bar does not have an accessible parameterless " - + "constructor\\.") + message = "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar does not have an accessible " + + "parameterless constructor.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index 5e30722152..f95614132c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -34,26 +34,26 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Target property \"foo\" must not be mapped more than once"), + message = "Target property \"foo\" must not be mapped more than once."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "No property named \"bar\" exists in source parameter\\(s\\)\\. " + + message = "No property named \"bar\" exists in source parameter(s). " + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 18, - messageRegExp = "Unknown property \"bar\" in result type " + + message = "Unknown property \"bar\" in result type " + "org.mapstruct.ap.test.erroneous.attributereference.Target. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = "No property named \"source1.foo\" exists in source parameter\\(s\\)\\. " + + message = "No property named \"source1.foo\" exists in source parameter(s). " + "Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.WARNING, line = 26, - messageRegExp = "Unmapped target property: \"bar\"") + message = "Unmapped target property: \"bar\".") } ) public void shouldFailToGenerateMappings() { @@ -67,7 +67,7 @@ public void shouldFailToGenerateMappings() { @Diagnostic(type = ErroneousMapper1.class, kind = Kind.ERROR, line = 16, - messageRegExp = "The type of parameter \"source\" has no property named \"foobar\"") + message = "The type of parameter \"source\" has no property named \"foobar\".") } ) public void shouldFailToGenerateMappingsErrorOnMandatoryParameterName() { @@ -81,7 +81,7 @@ public void shouldFailToGenerateMappingsErrorOnMandatoryParameterName() { @Diagnostic(type = ErroneousMapper2.class, kind = Kind.ERROR, line = 19, - messageRegExp = "Target property \"foo\" must not be mapped more than once" ) + message = "Target property \"foo\" must not be mapped more than once." ) } ) public void shouldFailToGenerateMappingsErrorOnDuplicateTarget() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java index ed2e9e2108..db97dc133a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java @@ -15,52 +15,68 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("1504") -@WithClasses( { Source.class, Target.class, UnmappableClass.class } ) +@WithClasses({ Source.class, Target.class, UnmappableClass.class }) @RunWith(AnnotationProcessorTestRunner.class) public class ErroneousPropertyMappingTest { @Test - @WithClasses( ErroneousMapper1.class ) + @WithClasses(ErroneousMapper1.class) @IssueKey("1504") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, - messageRegExp = ".*Consider to declare/implement a mapping method.*") } + line = 16, + message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + + "source\" to \"java.lang.String property\". Consider to declare/implement a mapping method: " + + "\"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass value)\".") + } ) - public void testUnmappableSourceProperty() { } + public void testUnmappableSourceProperty() { + } @Test - @WithClasses( ErroneousMapper2.class ) + @WithClasses(ErroneousMapper2.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = ".*Consider to declare/implement a mapping method.*") } + message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + + "nameBasedSource\" to \"java.lang.String nameBasedSource\". Consider to declare/implement a " + + "mapping method: \"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping" + + ".UnmappableClass value)\".") + } ) - public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { } + public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { + } @Test - @WithClasses( ErroneousMapper3.class ) + @WithClasses(ErroneousMapper3.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map.*constant.*" ) } + message = "Can't map \"java.lang.String \"constant\"\" to \"org.mapstruct.ap.test.erroneous" + + ".propertymapping.UnmappableClass constant\".") + } ) - public void testUnmappableConstantAssignment() { } + public void testUnmappableConstantAssignment() { + } @Test - @WithClasses( ErroneousMapper4.class ) + @WithClasses(ErroneousMapper4.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = ".*Consider to declare/implement a mapping method.*") } + message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + + "source\" to \"java.lang.String property\". Consider to declare/implement a mapping method: " + + "\"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass value)\".") + } ) - public void testUnmappableParameterAssignment() { } + public void testUnmappableParameterAssignment() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index 4462bdffa9..2a1b2bae28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -33,26 +33,26 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 14, - messageRegExp = "Can't map property \"boolean foo\" to \"int foo\". Consider to declare/implement a " - + "mapping method: \"int map\\(boolean value\\)\"."), + message = "Can't map property \"boolean foo\" to \"int foo\". Consider to declare/implement a " + + "mapping method: \"int map(boolean value)\"."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"int foo\" to \"boolean foo\". Consider to declare/implement a " - + "mapping method: \"boolean map\\(int value\\)\"."), + message = "Can't map property \"int foo\" to \"boolean foo\". Consider to declare/implement a " + + "mapping method: \"boolean map(int value)\"."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 18, - messageRegExp = "Can't generate mapping method with primitive return type\\."), + message = "Can't generate mapping method with primitive return type."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Can't generate mapping method with primitive parameter type\\."), + message = "Can't generate mapping method with primitive parameter type."), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = - "Can't generate mapping method that has a parameter annotated with @TargetType\\.") + message = + "Can't generate mapping method that has a parameter annotated with @TargetType.") } ) public void shouldFailToGenerateMappings() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 3b2496327d..e1549ef4a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -82,8 +82,8 @@ public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore( @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "Property \"hasClaws\" has no write accessor in " + - "org.mapstruct.ap.test.ignore.PreditorDto\\.") + message = "Property \"hasClaws\" has no write accessor in " + + "org.mapstruct.ap.test.ignore.PreditorDto.") } ) public void shouldGiveErrorOnMappingForReadOnlyProp() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java index 839d0987f7..e290aed450 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java @@ -44,7 +44,8 @@ public void shouldMapAttributeFromSuperType() { type = ErroneousTargetSourceMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Can't map property \"java.lang.CharSequence foo\" to \"java.lang.String foo\"" + message = "Can't map property \"java.lang.CharSequence foo\" to \"java.lang.String foo\". Consider to " + + "declare/implement a mapping method: \"java.lang.String map(java.lang.CharSequence value)\"." )) public void shouldReportErrorDueToUnmappableAttribute() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index a8e1033a2b..dc37b5f79c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -69,11 +69,13 @@ public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { kind = Kind.ERROR, type = ErroneousSourceCompositeTargetCompositeMapper.class, line = 19, - messageRegExp = - "Ambiguous mapping methods found for mapping property " - + "\"org.mapstruct.ap.test.inheritance.complex.SourceExt prop1\" to .*Reference: " - + ".*Reference .*AdditionalMappingHelper\\.asReference\\(.*SourceBase source\\), " - + ".*Reference .*AdditionalMappingHelper\\.asReference\\(.*AdditionalFooSource source\\)")) + message = "Ambiguous mapping methods found for mapping property \"org.mapstruct.ap.test.inheritance" + + ".complex.SourceExt prop1\" to org.mapstruct.ap.test.inheritance.complex.Reference: org.mapstruct.ap" + + ".test.inheritance.complex.Reference org.mapstruct.ap.test.inheritance.complex" + + ".AdditionalMappingHelper.asReference(org.mapstruct.ap.test.inheritance.complex.SourceBase source), " + + "org.mapstruct.ap.test.inheritance.complex.Reference org.mapstruct.ap.test.inheritance.complex" + + ".AdditionalMappingHelper.asReference(org.mapstruct.ap.test.inheritance.complex.AdditionalFooSource " + + "source).")) public void ambiguousMappingMethodsReportError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index 29c01c0a6d..8ab3583aa9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -203,29 +203,28 @@ public void autoInheritedFromMultipleSources() { @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" - + " to select one of them explicitly:" - + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," - + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), + message = "More than one configuration prototype method is applicable. Use @InheritConfiguration to " + + "select one of them explicitly: org.mapstruct.ap.test.inheritfromconfig.BaseVehicleEntity " + + "baseDtoToEntity(org.mapstruct.ap.test.inheritfromconfig.BaseVehicleDto dto), org.mapstruct.ap" + + ".test.inheritfromconfig.BaseVehicleEntity anythingToEntity(java.lang.Object anyting)."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.WARNING, line = 23, - messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\."), + message = "Unmapped target properties: \"primaryKey, auditTrail\"."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.ERROR, line = 29, - messageRegExp = "More than one configuration prototype method is applicable. Use @InheritConfiguration" - + " to select one of them explicitly:" - + " .*BaseVehicleEntity baseDtoToEntity\\(.*BaseVehicleDto dto\\)," - + " .*BaseVehicleEntity anythingToEntity\\(java.lang.Object anyting\\)\\."), + message = "More than one configuration prototype method is applicable. Use @InheritConfiguration to " + + "select one of them explicitly: org.mapstruct.ap.test.inheritfromconfig.BaseVehicleEntity " + + "baseDtoToEntity(org.mapstruct.ap.test.inheritfromconfig.BaseVehicleDto dto), org.mapstruct.ap" + + ".test.inheritfromconfig.BaseVehicleEntity anythingToEntity(java.lang.Object anyting)."), @Diagnostic(type = Erroneous1Mapper.class, kind = Kind.WARNING, line = 29, - messageRegExp = "Unmapped target property: \"primaryKey\"\\.") + message = "Unmapped target property: \"primaryKey\".") } ) public void erroneous1MultiplePrototypeMethodsMatch() { - } @Test @@ -236,15 +235,16 @@ public void erroneous1MultiplePrototypeMethodsMatch() { @Diagnostic(type = Erroneous2Mapper.class, kind = Kind.ERROR, line = 25, - messageRegExp = "Cycle detected while evaluating inherited configurations. Inheritance path:" - + " .*CarEntity toCarEntity1\\(.*CarDto carDto\\)" - + " -> .*CarEntity toCarEntity2\\(.*CarDto carDto\\)" - + " -> void toCarEntity3\\(.*CarDto carDto, @MappingTarget .*CarEntity entity\\)" - + " -> .*CarEntity toCarEntity1\\(.*CarDto carDto\\)") + message = "Cycle detected while evaluating inherited configurations. Inheritance path: org.mapstruct" + + ".ap.test.inheritfromconfig.CarEntity toCarEntity1(org.mapstruct.ap.test.inheritfromconfig.CarDto" + + " carDto) -> org.mapstruct.ap.test.inheritfromconfig.CarEntity toCarEntity2(org.mapstruct.ap.test" + + ".inheritfromconfig.CarDto carDto) -> void toCarEntity3(org.mapstruct.ap.test.inheritfromconfig" + + ".CarDto carDto, @MappingTarget org.mapstruct.ap.test.inheritfromconfig.CarEntity entity) -> org" + + ".mapstruct.ap.test.inheritfromconfig.CarEntity toCarEntity1(org.mapstruct.ap.test" + + ".inheritfromconfig.CarDto carDto)") } ) public void erroneous2InheritanceCycle() { - } @Test @@ -256,7 +256,7 @@ public void erroneous2InheritanceCycle() { @Diagnostic(type = ErroneousMapperAutoInheritance.class, kind = Kind.ERROR, line = 22, - messageRegExp = "Unmapped target properties: \"primaryKey, auditTrail\"\\.") + message = "Unmapped target properties: \"primaryKey, auditTrail\".") } ) public void erroneousWrongReverseConfigInherited() { } @@ -270,28 +270,32 @@ public void erroneousWrongReverseConfigInherited() { } @Diagnostic(type = ErroneousMapperReverseWithAutoInheritance.class, kind = Kind.ERROR, line = 23, - messageRegExp = "Unmapped target property: \"id\"\\.") + message = "Unmapped target property: \"id\".") } ) public void erroneousWrongConfigInherited() { } @Test - @IssueKey( "1255" ) - @WithClasses({ Erroneous3Mapper.class, Erroneous3Config.class } ) + @IssueKey("1255") + @WithClasses({ Erroneous3Mapper.class, Erroneous3Config.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Erroneous3Mapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "More than one configuration prototype method is applicable. " - + "Use @InheritInverseConfiguration.*"), + message = "More than one configuration prototype method is applicable. Use " + + "@InheritInverseConfiguration to select one of them explicitly: org.mapstruct.ap.test" + + ".inheritfromconfig.BaseVehicleEntity baseDtoToEntity(org.mapstruct.ap.test.inheritfromconfig" + + ".BaseVehicleDto dto), org.mapstruct.ap.test.inheritfromconfig.BaseVehicleEntity baseDtoToEntity2" + + "(org.mapstruct.ap.test.inheritfromconfig.BaseVehicleDto dto)."), @Diagnostic(type = Erroneous3Mapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "Unmapped target property: \"id\"\\.") + message = "Unmapped target property: \"id\".") } ) - public void erroneousDuplicateReverse() { } + public void erroneousDuplicateReverse() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index dfa9849f0f..4cc6ce3e66 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -42,11 +42,11 @@ public class ErroneousStreamMappingTest { @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, line = 15, - messageRegExp = "Can't generate mapping method from iterable type to non-iterable type"), + message = "Can't generate mapping method from iterable type to non-iterable type."), @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Can't generate mapping method from non-iterable type to iterable type") + message = "Can't generate mapping method from non-iterable type to iterable type.") } ) public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterable() { @@ -60,12 +60,12 @@ public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterabl @Diagnostic(type = ErroneousStreamToPrimitivePropertyMapper.class, kind = Kind.ERROR, line = 13, - messageRegExp = + message = "Can't map property \"java.util.stream.Stream strings\" to \"int strings\". " + - "Consider to declare/implement a mapping method: \"int map\\(java.util.stream.Stream" - + " value\\)\"") + + " value)\".") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @@ -79,17 +79,17 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + message = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them."), @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, line = 26, - messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + message = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them."), @Diagnostic(type = EmptyStreamMappingMapper.class, kind = Kind.ERROR, line = 29, - messageRegExp = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + message = "'nullValueMappingStrategy','dateformat', 'qualifiedBy' and 'elementTargetType' are " + "undefined in @IterableMapping, define at least one of them.") } ) @@ -104,10 +104,10 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 24, - messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " - + "withProperties\" to \".*NoProperties noProperties\". " - + "Consider to declare/implement a mapping method: \".*NoProperties " - + "map\\(.*WithProperties value\\)" ) + message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + + ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + + ".mapstruct.ap.test.WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { @@ -122,8 +122,9 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - messageRegExp = "Can't map stream element \".*AttributedString\" to \".*String \". Consider to " + - "declare/implement a mapping method: \".*String map(.*AttributedString value)") + message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + + " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + + "\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() { @@ -137,11 +138,10 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " - + "withProperties\" to \".*NoProperties noProperties\"." - + " Consider to declare/implement a mapping method: \".*NoProperties map\\(" - + ".*WithProperties " - + "value\\)" ) + message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + + ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + + ".mapstruct.ap.test.WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForListToStream() { @@ -156,9 +156,9 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Can't map stream element \".*AttributedString\" to " - + "\".*String \". Consider to declare/implement a mapping method: \".*String " - + "map\\(.*AttributedString value\\)" ) + message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + + " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + + "\".") } ) public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @@ -172,10 +172,10 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - messageRegExp = "No target bean properties found: can't map Stream element \".*WithProperties " - + "withProperties\" to .*NoProperties noProperties\"." - + " Consider to declare/implement a mapping method: \".*NoProperties map(" - + ".*WithProperties value)" ) + message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + + ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + + ".mapstruct.ap.test.WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { @@ -190,8 +190,9 @@ public void shouldFailOnNoElementMappingFoundForStreamToList() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Can't map stream element \".*AttributedString\" to .*String \". Consider to " + - "declare/implement a mapping method: \".*String map(.*AttributedString value)") + message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + + " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + + "\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToListWithDisabledAuto() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index 67091f5798..a996974cb7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -70,8 +70,11 @@ public void shouldForgeNewIterableMappingMethod() { @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "No target bean properties found: can't map Stream element \".* nonMappableStream\" " - + "to \".* nonMappableStream\". Consider to declare/implement a mapping method: .*." ) } + message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + + ".java8stream.forged.Foo nonMappableStream\" to \"org.mapstruct.ap.test.java8stream.forged.Bar " + + "nonMappableStream\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + + ".java8stream.forged.Bar map(org.mapstruct.ap.test.java8stream.forged.Foo value)\".") + } ) public void shouldGenerateNonMappableMethodForSetMapping() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java index a24a9d8b5d..acf89c5b93 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java @@ -71,7 +71,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { @Diagnostic(type = ErroneousIterableSuperBoundSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "Can't generate mapping method for a wildcard super bound source.") + message = "Can't generate mapping method for a wildcard super bound source.") } ) public void shouldFailOnSuperBoundSource() { @@ -85,7 +85,7 @@ public void shouldFailOnSuperBoundSource() { @Diagnostic(type = ErroneousIterableExtendsBoundTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "Can't generate mapping method for a wildcard extends bound result.") + message = "Can't generate mapping method for a wildcard extends bound result.") } ) public void shouldFailOnExtendsBoundTarget() { @@ -99,7 +99,7 @@ public void shouldFailOnExtendsBoundTarget() { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMethod.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "Can't generate mapping method for a generic type variable target.") + message = "Can't generate mapping method for a generic type variable target.") } ) public void shouldFailOnTypeVarSource() { @@ -113,7 +113,7 @@ public void shouldFailOnTypeVarSource() { @Diagnostic(type = ErroneousIterableTypeVarBoundMapperOnMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "Can't generate mapping method for a generic type variable source.") + message = "Can't generate mapping method for a generic type variable source.") } ) public void shouldFailOnTypeVarTarget() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java index cd7e56a93e..d128e6f77e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java @@ -58,7 +58,7 @@ public void shouldUseCustomMapperViaMapperConfigForFooToDto() { diagnostics = { @Diagnostic(type = SourceTargetMapperWarn.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - messageRegExp = "Unmapped target property: \"noFoo\"") + message = "Unmapped target property: \"noFoo\".") }) public void shouldUseWARNViaMapper() { } @@ -69,7 +69,7 @@ public void shouldUseWARNViaMapper() { diagnostics = { @Diagnostic(type = SourceTargetMapperErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - messageRegExp = "Unmapped target property: \"noFoo\"") + message = "Unmapped target property: \"noFoo\".") }) public void shouldUseERRORViaMapperConfig() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index 90f0957e68..a1a1fd6079 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -76,7 +76,10 @@ public void testDeepCloning() { @Diagnostic(type = ErroneousDirectMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \".*\\.ShelveDTO shelve\".*" + message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"org" + + ".mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\". Consider to declare/implement a mapping " + + "method: \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO map(org.mapstruct.ap.test" + + ".mappingcontrol.ShelveDTO value)\"." ) }) public void directSelectionNotAllowed() { @@ -101,7 +104,9 @@ public void methodSelectionAllowed() { @Diagnostic(type = ErroneousMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + + "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + + ".mappingcontrol.ShelveDTO value)\"." ) }) public void methodSelectionNotAllowed() { @@ -126,7 +131,8 @@ public void conversionSelectionAllowed() { @Diagnostic(type = ErroneousConversionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*\\.String beerCount\" to \"int beerCount\".*" + message = "Can't map property \"java.lang.String beerCount\" to \"int beerCount\". Consider to " + + "declare/implement a mapping method: \"int map(java.lang.String value)\"." ) }) public void conversionSelectionNotAllowed() { @@ -151,7 +157,9 @@ public void complexSelectionAllowed() { @Diagnostic(type = ErroneousComplexMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + + "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + + ".mappingcontrol.ShelveDTO value)\"." ) }) public void complexSelectionNotAllowed() { @@ -164,7 +172,9 @@ public void complexSelectionNotAllowed() { @Diagnostic(type = ErroneousComplexMapperWithConfig.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "Can't map property \".*\\.ShelveDTO shelve\" to \"int beerCount\".*" + message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + + "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + + ".mappingcontrol.ShelveDTO value)\"." ) }) public void complexSelectionNotAllowedWithConfig() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index dcf9451303..9908ea8e4a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -33,7 +33,7 @@ public class SuggestMostSimilarNameTest { @Diagnostic(type = PersonAgeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = ".*Did you mean \"age\"\\?") + message = "No property named \"agee\" exists in source parameter(s). Did you mean \"age\"?") } ) public void testAgeSuggestion() { @@ -49,7 +49,8 @@ public void testAgeSuggestion() { @Diagnostic(type = PersonNameMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = ".*Did you mean \"fullName\"\\?") + message = "Unknown property \"fulName\" in result type org.mapstruct.ap.test.namesuggestion.Person. " + + "Did you mean \"fullName\"?") } ) public void testNameSuggestion() { @@ -65,11 +66,13 @@ public void testNameSuggestion() { @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - messageRegExp = "Unknown property \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), + message = "Unknown property \"garage.colour.rgb\" in result type org.mapstruct.ap.test.namesuggestion" + + ".Person. Did you mean \"garage.color\"?"), @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Unknown property \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") + message = "Unknown property \"garage.colour\" in result type org.mapstruct.ap.test.namesuggestion" + + ".Person. Did you mean \"garage.color\"?") } ) public void testGarageTargetSuggestion() { @@ -85,11 +88,13 @@ public void testGarageTargetSuggestion() { @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 21, - messageRegExp = "No property named \"garage\\.colour\\.rgb\".*Did you mean \"garage\\.color\"\\?"), + message = "No property named \"garage.colour.rgb\" exists in source parameter(s). Did you mean " + + "\"garage.color\"?"), @Diagnostic(type = PersonGarageWrongSourceMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 28, - messageRegExp = "No property named \"garage\\.colour\".*Did you mean \"garage\\.color\"\\?") + message = "No property named \"garage.colour\" exists in source parameter(s). Did you mean \"garage" + + ".color\"?") } ) public void testGarageSourceSuggestion() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index b7dd9b70ac..434ad225a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -33,8 +33,9 @@ public class DisablingNestedSimpleBeansMappingTest { @Diagnostic(type = ErroneousDisabledHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + - "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." + message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.Roof roof\" to \"org.mapstruct.ap" + + ".test.nestedbeans.RoofDto roof\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.nestedbeans.RoofDto map(org.mapstruct.ap.test.nestedbeans.Roof value)\"." ) }) @Test @@ -50,8 +51,9 @@ public void shouldUseDisabledMethodGenerationOnMapper() { @Diagnostic(type = ErroneousDisabledViaConfigHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*\\.Roof roof\" to \".*\\.RoofDto roof\"\\. Consider to " + - "declare/implement a mapping method: \".*\\.RoofDto map\\(.*\\.Roof value\\)\"\\." + message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.Roof roof\" to \"org.mapstruct.ap" + + ".test.nestedbeans.RoofDto roof\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.nestedbeans.RoofDto map(org.mapstruct.ap.test.nestedbeans.Roof value)\"." ) }) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index 1d684ec502..b1f58967ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.test.nestedbeans; import org.junit.Test; - import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseCollectionElementPropertyMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseDeepListMapper; @@ -14,21 +13,38 @@ import org.mapstruct.ap.test.nestedbeans.unmappable.BaseDeepMapValueMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseDeepNestingMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseValuePropertyMapper; +import org.mapstruct.ap.test.nestedbeans.unmappable.Car; +import org.mapstruct.ap.test.nestedbeans.unmappable.CarDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.Cat; +import org.mapstruct.ap.test.nestedbeans.unmappable.CatDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.Color; +import org.mapstruct.ap.test.nestedbeans.unmappable.ColorDto; import org.mapstruct.ap.test.nestedbeans.unmappable.Computer; import org.mapstruct.ap.test.nestedbeans.unmappable.ComputerDto; import org.mapstruct.ap.test.nestedbeans.unmappable.Dictionary; import org.mapstruct.ap.test.nestedbeans.unmappable.DictionaryDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.ExternalRoofType; import org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWord; import org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWordDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.Cat; -import org.mapstruct.ap.test.nestedbeans.unmappable.CatDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.House; +import org.mapstruct.ap.test.nestedbeans.unmappable.HouseDto; import org.mapstruct.ap.test.nestedbeans.unmappable.Info; import org.mapstruct.ap.test.nestedbeans.unmappable.InfoDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.Roof; +import org.mapstruct.ap.test.nestedbeans.unmappable.RoofDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.RoofType; import org.mapstruct.ap.test.nestedbeans.unmappable.RoofTypeMapper; +import org.mapstruct.ap.test.nestedbeans.unmappable.User; +import org.mapstruct.ap.test.nestedbeans.unmappable.UserDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.Wheel; +import org.mapstruct.ap.test.nestedbeans.unmappable.WheelDto; +import org.mapstruct.ap.test.nestedbeans.unmappable.Word; +import org.mapstruct.ap.test.nestedbeans.unmappable.WordDto; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableCollectionElementPropertyMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableDeepListMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableDeepMapKeyMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableDeepMapValueMapper; +import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableDeepNestingMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableEnumMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableValuePropertyMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.ignore.UnmappableIgnoreCollectionElementPropertyMapper; @@ -43,23 +59,6 @@ import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnDeepMapValueMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnDeepNestingMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnValuePropertyMapper; -import org.mapstruct.ap.test.nestedbeans.unmappable.UserDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.User; -import org.mapstruct.ap.test.nestedbeans.unmappable.WheelDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.Wheel; -import org.mapstruct.ap.test.nestedbeans.unmappable.Car; -import org.mapstruct.ap.test.nestedbeans.unmappable.CarDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.ExternalRoofType; -import org.mapstruct.ap.test.nestedbeans.unmappable.House; -import org.mapstruct.ap.test.nestedbeans.unmappable.HouseDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.Color; -import org.mapstruct.ap.test.nestedbeans.unmappable.ColorDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.Roof; -import org.mapstruct.ap.test.nestedbeans.unmappable.RoofType; -import org.mapstruct.ap.test.nestedbeans.unmappable.RoofDto; -import org.mapstruct.ap.test.nestedbeans.unmappable.erroneous.UnmappableDeepNestingMapper; -import org.mapstruct.ap.test.nestedbeans.unmappable.Word; -import org.mapstruct.ap.test.nestedbeans.unmappable.WordDto; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; @@ -100,8 +99,9 @@ public class DottedErrorMessageTest { @Diagnostic(type = BaseDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"rgb\"\\. Mapping from " + PROPERTY + - " \".*Color house\\.roof\\.color\" to \".*ColorDto house\\.roof\\.color\"\\.") + message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Color house.roof.color\" to \"org.mapstruct.ap" + + ".test.nestedbeans.unmappable.ColorDto house.roof.color\".") } ) public void testDeepNestedBeans() { @@ -117,8 +117,9 @@ public void testDeepNestedBeans() { @Diagnostic(type = BaseDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"left\"\\. Mapping from " + COLLECTION_ELEMENT + - " \".*Wheel car\\.wheels\" to \".*WheelDto car\\.wheels\"\\.") + message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Wheel car.wheels\" to \"org.mapstruct.ap.test" + + ".nestedbeans.unmappable.WheelDto car.wheels\".") } ) public void testIterables() { @@ -134,8 +135,9 @@ public void testIterables() { @Diagnostic(type = BaseDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_KEY + - " \".*Word dictionary\\.wordMap\\{:key\\}\" to \".*WordDto dictionary\\.wordMap\\{:key\\}\"\\.") + message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Word dictionary.wordMap{:key}\" to \"org" + + ".mapstruct.ap.test.nestedbeans.unmappable.WordDto dictionary.wordMap{:key}\".") } ) public void testMapKeys() { @@ -151,9 +153,9 @@ public void testMapKeys() { @Diagnostic(type = BaseDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_VALUE + - " \".*ForeignWord dictionary\\.wordMap\\{:value\\}\" " + - "to \".*ForeignWordDto dictionary\\.wordMap\\{:value\\}\"\\.") + message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWord dictionary.wordMap{:value}\" " + + "to \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWordDto dictionary.wordMap{:value}\".") } ) public void testMapValues() { @@ -169,8 +171,9 @@ public void testMapValues() { @Diagnostic(type = BaseCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + - " \".*Info computers\\[\\].info\" to \".*InfoDto computers\\[\\].info\"\\.") + message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info computers[].info\" to \"org.mapstruct.ap" + + ".test.nestedbeans.unmappable.InfoDto computers[].info\".") } ) public void testCollectionElementProperty() { @@ -186,8 +189,9 @@ public void testCollectionElementProperty() { @Diagnostic(type = BaseValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, - messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + - " \".*Info catNameMap\\{:value\\}.info\" to \".*InfoDto catNameMap\\{:value\\}.info\"\\.") + message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info catNameMap{:value}.info\" to \"org" + + ".mapstruct.ap.test.nestedbeans.unmappable.InfoDto catNameMap{:value}.info\".") } ) public void testMapValueProperty() { @@ -203,9 +207,12 @@ public void testMapValueProperty() { @Diagnostic(type = UnmappableEnumMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 25, - messageRegExp = "The following constants from the property \".*RoofType house\\.roof\\.type\" enum " + - "have no corresponding constant in the \".*ExternalRoofType house\\.roof\\.type\" enum and must " + - "be be mapped via adding additional mappings: NORMAL\\." + message = + "The following constants from the property \"org.mapstruct.ap.test.nestedbeans.unmappable" + + ".RoofType house.roof.type\" enum " + + "have no corresponding constant in the \"org.mapstruct.ap.test.nestedbeans.unmappable" + + ".ExternalRoofType house.roof.type\" enum and must " + + "be be mapped via adding additional mappings: NORMAL." ) } ) @@ -227,34 +234,39 @@ public void testMapEnumProperty() { @Diagnostic(type = BaseDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"rgb\"\\. Mapping from " + PROPERTY + - " \".*Color house\\.roof\\.color\" to \".*ColorDto house\\.roof\\.color\"\\."), + message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Color house.roof.color\" to \"org.mapstruct.ap" + + ".test.nestedbeans.unmappable.ColorDto house.roof.color\"."), @Diagnostic(type = BaseDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"left\"\\. Mapping from " + COLLECTION_ELEMENT + - " \".*Wheel car\\.wheels\" to \".*WheelDto car\\.wheels\"\\."), + message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Wheel car.wheels\" to \"org.mapstruct.ap.test" + + ".nestedbeans.unmappable.WheelDto car.wheels\"."), @Diagnostic(type = BaseDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_KEY + - " \".*Word dictionary\\.wordMap\\{:key\\}\" to \".*WordDto dictionary\\.wordMap\\{:key\\}\"\\."), + message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Word dictionary.wordMap{:key}\" to \"org" + + ".mapstruct.ap.test.nestedbeans.unmappable.WordDto dictionary.wordMap{:key}\"."), @Diagnostic(type = BaseDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"pronunciation\"\\. Mapping from " + MAP_VALUE + - " \".*ForeignWord dictionary\\.wordMap\\{:value\\}\" " + - "to \".*ForeignWordDto dictionary\\.wordMap\\{:value\\}\"\\."), + message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWord dictionary.wordMap{:value}\" " + + "to \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWordDto dictionary.wordMap{:value}\"."), @Diagnostic(type = BaseCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + - " \".*Info computers\\[\\].info\" to \".*InfoDto computers\\[\\].info\"\\."), + message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info computers[].info\" to \"org.mapstruct.ap" + + ".test.nestedbeans.unmappable.InfoDto computers[].info\"."), @Diagnostic(type = BaseValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, - messageRegExp = "Unmapped target property: \"color\"\\. Mapping from " + PROPERTY + - " \".*Info catNameMap\\{:value\\}.info\" to \".*InfoDto catNameMap\\{:value\\}.info\"\\.") + message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + + " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info catNameMap{:value}.info\" to \"org" + + ".mapstruct.ap.test.nestedbeans.unmappable.InfoDto catNameMap{:value}.info\".") } ) public void testWarnUnmappedTargetProperties() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index 6f50266f2f..267dfb438c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -31,26 +31,31 @@ public class ErroneousJavaInternalTest { @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*MyType date\" to \"java\\.util\\.Date date\"\\. Consider to " + - "declare/implement a mapping method: \"java\\.util\\.Date map\\(.*MyType value\\)\"\\."), + message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType date\" to " + + "\"java.util.Date date\". Consider to declare/implement a mapping method: \"java.util.Date map" + + "(org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*MyType calendar\" to \"java\\.util\\.GregorianCalendar " + - "calendar\"\\. Consider to declare/implement a mapping method: \"java\\.util\\.GregorianCalendar " + - "map\\(.*MyType value\\)\"\\."), + message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType calendar\"" + + " to \"java.util.GregorianCalendar calendar\". Consider to declare/implement a mapping method: " + + "\"java.util.GregorianCalendar map(org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType " + + "value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*List<.*MyType> types\" to \".*List<.*String> types\"\\" + - ". Consider to declare/implement a mapping method: \".*List<.*String> map\\(.*List<.*MyType> " + - "value\\)\"\\."), + message = "Can't map property \"java.util.List types\" to \"java.util.List types\". Consider to declare/implement a " + + "mapping method: \"java.util.List map(java.util.List value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "Can't map property \".*List<.*MyType> nestedMyType\\.deepNestedType\\.types\" to \"" + - ".*List<.*String> nestedMyType\\.deepNestedType\\.types\"\\. Consider to declare/implement a " + - "mapping method: \".*List<.*String> map\\(.*List<.*MyType> value\\)\"\\.") + message = "Can't map property \"java.util.List nestedMyType.deepNestedType.types\" to \"java.util.List nestedMyType" + + ".deepNestedType.types\". Consider to declare/implement a mapping method: \"java.util.List map(java.util.List " + + "value)\".") }) @Test public void shouldNotNestIntoJavaPackageObjects() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java index b34a8d451c..1eccfdb4d7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -33,9 +33,11 @@ public class ErroneousCustomExclusionTest { @Diagnostic(type = ErroneousCustomExclusionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - messageRegExp = "Can't map property \".*NestedSource nested\" to \".*NestedTarget nested\"\\. " + - "Consider to declare/implement a mapping method: \".*NestedTarget map\\(.*NestedSource value\\)" + - "\"\\.") + message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.custom.Source" + + ".NestedSource nested\" to \"org.mapstruct.ap.test.nestedbeans.exclusions.custom.Target" + + ".NestedTarget nested\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + + ".nestedbeans.exclusions.custom.Target.NestedTarget map(org.mapstruct.ap.test.nestedbeans" + + ".exclusions.custom.Source.NestedSource value)\".") } ) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 7a1187f05d..1d61b6e69a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -171,7 +171,7 @@ public void shouldUseGetAsTargetAccessor() { @Diagnostic( type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 34, - messageRegExp = "java.lang.Integer does not have an accessible parameterless constructor." ) + message = "java.lang.Integer does not have an accessible parameterless constructor." ) } ) @WithClasses({ ArtistToChartEntryErroneous.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index a7f8e6bb9c..014c2c8220 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -111,7 +111,7 @@ public void testStrategyDefaultAppliedOnForgedMethod() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 - messageRegExp = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + message = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a defaultValue or an nullValuePropertyMappingStrategy.") } ) @@ -127,7 +127,7 @@ public void testBothDefaultValueAndNvpmsDefined() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 - messageRegExp = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + message = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define an expression or an nullValuePropertyMappingStrategy.") } ) @@ -143,7 +143,7 @@ public void testBothExpressionAndNvpmsDefined() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 - messageRegExp = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " + + message = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " + "@Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy.") } ) @@ -159,7 +159,7 @@ public void testBothDefaultExpressionAndNvpmsDefined() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 - messageRegExp = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + message = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a constant or an nullValuePropertyMappingStrategy.") } ) @@ -175,7 +175,7 @@ public void testBothConstantAndNvpmsDefined() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 - messageRegExp = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " + + message = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define ignore or an nullValuePropertyMappingStrategy.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java index fa7b4015cb..2e1598f8aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.reverse; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; import org.junit.Test; @@ -22,6 +20,8 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Sjaak Derksen */ @@ -61,12 +61,12 @@ public void shouldInheritInverseConfigurationMultipleCandidates() { @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.ERROR, line = 38, - messageRegExp = "Several matching inverse methods exist: forward\\(\\), " - + "forwardNotToReverse\\(\\). Specify a name explicitly."), + message = "Several matching inverse methods exist: forward(), " + + "forwardNotToReverse(). Specify a name explicitly."), @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.WARNING, line = 43, - messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") + message = "Unmapped target properties: \"stringPropX, integerPropX\".") } ) public void shouldRaiseAmbiguousReverseMethodError() { @@ -80,12 +80,12 @@ public void shouldRaiseAmbiguousReverseMethodError() { @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.ERROR, line = 38, - messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given " + message = "None of the candidates forward(), forwardNotToReverse() matches given " + "name: \"blah\"."), @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.WARNING, line = 43, - messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") + message = "Unmapped target properties: \"stringPropX, integerPropX\".") } ) public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { @@ -99,12 +99,14 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.ERROR, line = 39, - messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward\\(.+\\), " - + ".*forward\\(.+\\)"), + message = "Given name \"forward\" matches several candidate methods: org.mapstruct.ap.test.reverse" + + ".Target forward(org.mapstruct.ap.test.reverse.Source source), org.mapstruct.ap.test.reverse" + + ".Target forward(org.mapstruct.ap.test.reverse.Source source, @MappingTarget org.mapstruct.ap" + + ".test.reverse.Target target)."), @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.WARNING, line = 44, - messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") + message = "Unmapped target properties: \"stringPropX, integerPropX\".") } ) public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { @@ -118,12 +120,11 @@ public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.ERROR, line = 31, - messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: " - + "\"forward\"."), + message = "Given name \"blah\" does not match the only candidate. Did you mean: \"forward\"."), @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.WARNING, line = 36, - messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"") + message = "Unmapped target properties: \"stringPropX, integerPropX\".") } ) public void shouldAdviseOnSpecifyingCorrectName() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 1adc1aba8f..12ba5f111c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -85,9 +85,12 @@ public void shouldApplyGenericTypeMapper() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection." - + "generics.UpperBoundWrapper " - + "fooUpperBoundFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA fooUpperBoundFailure\"") + message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + + ".generics.UpperBoundWrapper " + + "fooUpperBoundFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + + "fooUpperBoundFailure\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + + ".selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics.UpperBoundWrapper value)\".") }) public void shouldFailOnUpperBound() { } @@ -99,10 +102,12 @@ public void shouldFailOnUpperBound() { @Diagnostic(type = ErroneousSourceTargetMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "No target bean properties found: can't map property " - + "\"org.mapstruct.ap.test.selection.generics.WildCardExtendsWrapper" - + " fooWildCardExtendsTypeAFailure\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardExtendsTypeAFailure\"") + message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + + ".generics.WildCardExtendsWrapper " + + "fooWildCardExtendsTypeAFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + + "fooWildCardExtendsTypeAFailure\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics" + + ".WildCardExtendsWrapper value)\".") }) public void shouldFailOnWildCardBound() { } @@ -114,11 +119,12 @@ public void shouldFailOnWildCardBound() { @Diagnostic(type = ErroneousSourceTargetMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "No target bean properties found: can't map property " - + "\"org.mapstruct.ap.test.selection.generics." - + "WildCardExtendsMBWrapper " - + "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " - + "fooWildCardExtendsMBTypeBFailure\"") + message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + + ".generics.WildCardExtendsMBWrapper " + + "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " + + "fooWildCardExtendsMBTypeBFailure\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.selection.generics.TypeB map(org.mapstruct.ap.test.selection.generics" + + ".WildCardExtendsMBWrapper value)\".") }) public void shouldFailOnWildCardMultipleBounds() { } @@ -130,10 +136,12 @@ public void shouldFailOnWildCardMultipleBounds() { @Diagnostic(type = ErroneousSourceTargetMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "No target bean properties found: can't map property " - + "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" - + " fooWildCardSuperTypeAFailure\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeA fooWildCardSuperTypeAFailure\"") + message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + + ".generics.WildCardSuperWrapper " + + "fooWildCardSuperTypeAFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + + "fooWildCardSuperTypeAFailure\". Consider to declare/implement a mapping method: \"org.mapstruct" + + ".ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics" + + ".WildCardSuperWrapper value)\".") }) public void shouldFailOnSuperBounds1() { } @@ -145,10 +153,12 @@ public void shouldFailOnSuperBounds1() { @Diagnostic(type = ErroneousSourceTargetMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - messageRegExp = "No target bean properties found: can't map property " - + "\"org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper" - + " fooWildCardSuperTypeCFailure\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeC fooWildCardSuperTypeCFailure\"") + message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + + ".generics.WildCardSuperWrapper " + + "fooWildCardSuperTypeCFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeC " + + "fooWildCardSuperTypeCFailure\". Consider to declare/implement a mapping method: \"org.mapstruct" + + ".ap.test.selection.generics.TypeC map(org.mapstruct.ap.test.selection.generics" + + ".WildCardSuperWrapper value)\".") }) public void shouldFailOnSuperBounds2() { } @@ -160,18 +170,19 @@ public void shouldFailOnSuperBounds2() { ErroneousSourceTargetMapper6.class, NoProperties.class }) - @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic( type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, messageRegExp = - ".*\\.generics\\.WildCardSuperWrapper<.*\\.generics\\.TypeA> does not have an " - + "accessible parameterless constructor\\." ), - @Diagnostic( type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, messageRegExp = - "No target bean properties found: can't map property \".*NoProperties " - + "foo\\.wrapped\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeA " - + "foo\\.wrapped\"" ) - } ) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, message = "org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper does not have an accessible parameterless constructor."), + @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, message = + "No target bean properties found: can't map property \"org.mapstruct.ap.test.NoProperties " + + "foo.wrapped\" to" + + " \"org.mapstruct.ap.test.selection.generics.TypeA " + + "foo.wrapped\". Consider to declare/implement a mapping method: \"org" + + ".mapstruct.ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.NoProperties " + + "value)\".") + }) public void shouldFailOnNonMatchingWildCards() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 9ec88d431e..912affa1a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -91,10 +91,10 @@ public void shouldMatchClassAndMethod() { } @Test - @WithClasses( { + @WithClasses({ YetAnotherMapper.class, ErroneousMapper.class - } ) + }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -102,17 +102,16 @@ public void shouldMatchClassAndMethod() { type = ErroneousMapper.class, kind = Kind.ERROR, line = 28, - messageRegExp = - "No qualifying method found for qualifiers: " - + "org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated and " - + "/ or qualifying names: .*"), + message = + "No qualifying method found for qualifiers: org.mapstruct.ap.test.selection.qualifier.annotation" + + ".NonQualifierAnnotated and / or qualifying names: "), @Diagnostic( type = ErroneousMapper.class, kind = Kind.ERROR, line = 28, - messageRegExp = - "Can't map property \"java.lang.String title\" to \"java.lang.String title\". " - + "Consider to declare/implement a mapping method: \"java.lang.String map(java.lang.String value)*") + message = + "Can't map property \"java.lang.String title\" to \"java.lang.String title\". Consider to " + + "declare/implement a mapping method: \"java.lang.String map(java.lang.String value)\".") } ) public void shouldNotProduceMatchingMethod() { @@ -174,23 +173,24 @@ public void testFactorySelectionWithQualifier() { } @Test - @IssueKey( "342") - @WithClasses( { + @IssueKey("342") + @WithClasses({ ErroneousMovieFactoryMapper.class - } ) + }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, line = 24, - messageRegExp = "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and " + + message = "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and " + "'qualifiedBy' are undefined in @BeanMapping, define at least one of them."), @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, line = 24, - messageRegExp = "The return type .*\\.AbstractEntry is an abstract class or interface. Provide a non " + - "abstract / non interface result type or a factory method.") + message = "The return type org.mapstruct.ap.test.selection.qualifier.bean.AbstractEntry is an " + + "abstract class or interface. Provide a non abstract / non interface result type or a factory " + + "method.") } ) public void testEmptyBeanMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index ed9f813489..efdea3c0eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -38,20 +38,22 @@ public class InheritanceSelectionTest { @Test - @WithClasses( { ConflictingFruitFactory.class, ErroneousFruitMapper.class, Banana.class } ) + @WithClasses({ ConflictingFruitFactory.class, ErroneousFruitMapper.class, Banana.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = "Ambiguous factory methods found for creating .*Fruit: " - + ".*Apple .*ConflictingFruitFactory\\.createApple\\(\\), " - + ".*Banana .*ConflictingFruitFactory\\.createBanana\\(\\)\\."), + message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.selection.resulttype" + + ".Fruit: org.mapstruct.ap.test.selection.resulttype.Apple org.mapstruct.ap.test.selection" + + ".resulttype.ConflictingFruitFactory.createApple(), org.mapstruct.ap.test.selection.resulttype" + + ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana()."), @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = ".*Fruit does not have an accessible parameterless constructor\\.") + message = "org.mapstruct.ap.test.selection.resulttype.Fruit does not have an accessible parameterless" + + " constructor.") } ) public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() { @@ -59,14 +61,15 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() @IssueKey("1283") @Test - @WithClasses( { ErroneousResultTypeNoEmptyConstructorMapper.class, Banana.class } ) + @WithClasses({ ErroneousResultTypeNoEmptyConstructorMapper.class, Banana.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousResultTypeNoEmptyConstructorMapper.class, kind = Kind.ERROR, line = 18, - messageRegExp = ".*\\.resulttype\\.Banana does not have an accessible parameterless constructor\\.") + message = "org.mapstruct.ap.test.selection.resulttype.Banana does not have an accessible " + + "parameterless constructor.") } ) public void testResultTypeHasNoSuitableEmptyConstructor() { @@ -112,8 +115,8 @@ public void testResultTypeBasedConstructionOfResultForInterface() { @Diagnostic(type = ResultTypeConstructingFruitInterfaceErroneousMapper.class, kind = Kind.ERROR, line = 23, - messageRegExp = "The return type .*\\.IsFruit is an abstract class or interface. Provide a non " + - "abstract / non interface result type or a factory method." + message = "The return type org.mapstruct.ap.test.selection.resulttype.IsFruit is an abstract class or" + + " interface. Provide a non abstract / non interface result type or a factory method." ) } ) @@ -129,11 +132,12 @@ public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { @Diagnostic(type = ErroneousFruitMapper2.class, kind = Kind.ERROR, line = 22, - messageRegExp = ".*\\.Banana not assignable to: .*\\.Apple.") + message = "org.mapstruct.ap.test.selection.resulttype.Banana not assignable to: org.mapstruct.ap.test" + + ".selection.resulttype.Apple.") } ) @IssueKey("434") - @WithClasses( { ErroneousFruitMapper2.class, Banana.class } ) + @WithClasses({ ErroneousFruitMapper2.class, Banana.class }) public void testResultTypeBasedConstructionOfResultNonAssignable() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java index 7182b62740..98a6970598 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.source.constants; -import static org.assertj.core.api.Assertions.assertThat; - import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,6 +16,8 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * * @author Sjaak Derksen @@ -70,31 +70,38 @@ public void testNumericConstants() { @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 25, - messageRegExp = "^.*only 'true' or 'false' are supported\\.$"), + message = "Can't map \"java.lang.String \"zz\"\" to \"boolean booleanValue\". Reason: only 'true' or " + + "'false' are supported."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 26, - messageRegExp = "^.*invalid character literal\\.$"), + message = "Can't map \"java.lang.String \"'ba'\"\" to \"char charValue\". Reason: invalid character " + + "literal."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 27, - messageRegExp = "^.*Value out of range. Value:\"200\" Radix:10\\.$"), - @Diagnostic(type = ErroneousConstantMapper.class, + message = "Can't map \"java.lang.String \"200\"\" to \"byte byteValue\". Reason: Value out of range. " + + "Value:\"200\" Radix:10."), + @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 28, - messageRegExp = "^.*integer number too large.$"), - @Diagnostic(type = ErroneousConstantMapper.class, + message = "Can't map \"java.lang.String \"0xFFFF_FFFF_FFFF\"\" to \"int intValue\". Reason: integer " + + "number too large."), + @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, - messageRegExp = "^.*L/l mandatory for long types.$"), - @Diagnostic(type = ErroneousConstantMapper.class, + message = "Can't map \"java.lang.String \"1\"\" to \"long longValue\". Reason: L/l mandatory for long" + + " types."), + @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 30, - messageRegExp = "^.*improperly placed underscores.$"), - @Diagnostic(type = ErroneousConstantMapper.class, + message = "Can't map \"java.lang.String \"1.40e-_45f\"\" to \"float floatValue\". Reason: improperly " + + "placed underscores."), + @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 31, - messageRegExp = "^.*floating point number too small.$") + message = "Can't map \"java.lang.String \"1e-137000\"\" to \"double doubleValue\". Reason: floating " + + "point number too small.") } ) public void miscellaneousDetailMessages() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index fa10dce5d0..7e7bc2d69e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -91,12 +91,12 @@ public void shouldMapTargetToSourceWithoutWhining() throws ParseException { @Diagnostic(type = ErroneousMapper1.class, kind = Kind.ERROR, line = 24, - messageRegExp = "Source and constant are both defined in @Mapping, either define a source or a " - + "constant"), + message = "Source and constant are both defined in @Mapping, either define a source or a " + + "constant."), @Diagnostic(type = ErroneousMapper1.class, kind = Kind.WARNING, line = 30, - messageRegExp = "Unmapped target property: \"integerConstant\"") + message = "Unmapped target property: \"integerConstant\".") } ) public void errorOnSourceAndConstant() throws ParseException { @@ -117,13 +117,13 @@ public void errorOnSourceAndConstant() throws ParseException { @Diagnostic(type = ErroneousMapper3.class, kind = Kind.ERROR, line = 24, - messageRegExp = + message = "Expression and constant are both defined in @Mapping, either define an expression or a " - + "constant"), + + "constant."), @Diagnostic(type = ErroneousMapper3.class, kind = Kind.WARNING, line = 30, - messageRegExp = "Unmapped target property: \"integerConstant\"") + message = "Unmapped target property: \"integerConstant\".") } ) public void errorOnConstantAndExpression() throws ParseException { @@ -144,12 +144,12 @@ public void errorOnConstantAndExpression() throws ParseException { @Diagnostic(type = ErroneousMapper4.class, kind = Kind.ERROR, line = 24, - messageRegExp = "Source and expression are both defined in @Mapping, either define a source or an " - + "expression"), + message = "Source and expression are both defined in @Mapping, either define a source or an " + + "expression."), @Diagnostic(type = ErroneousMapper4.class, kind = Kind.WARNING, line = 30, - messageRegExp = "Unmapped target property: \"integerConstant\"") + message = "Unmapped target property: \"integerConstant\".") } ) public void errorOnSourceAndExpression() throws ParseException { @@ -192,13 +192,13 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, line = 28, - messageRegExp = "^Constant \"DENMARK\" doesn't exist in enum type org.mapstruct.ap.test.source." - + "constants.CountryEnum for property \"country\".$"), + message = "Constant \"DENMARK\" doesn't exist in enum type org.mapstruct.ap.test.source." + + "constants.CountryEnum for property \"country\"."), @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, line = 28, - messageRegExp = "^Can't map \"java.lang.String \"DENMARK\"\" to \"org.mapstruct.ap.test.source." - + "constants.CountryEnum country\".$") + message = "Can't map \"java.lang.String \"DENMARK\"\" to \"org.mapstruct.ap.test.source." + + "constants.CountryEnum country\".") } ) public void errorOnNonExistingEnumConstant() throws ParseException { @@ -219,8 +219,8 @@ public void errorOnNonExistingEnumConstant() throws ParseException { @Diagnostic(type = ErroneousMapper6.class, kind = Kind.ERROR, line = 25, - messageRegExp = "^.*Can't map \"java.lang.String \"3001\"\" to \"java.lang.Long " - + "longWrapperConstant\".*$") + message = "Can't map \"java.lang.String \"3001\"\" to \"java.lang.Long " + + "longWrapperConstant\". Reason: L/l mandatory for long types.") } ) public void cannotMapIntConstantToLong() throws ParseException { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 09343d597b..24b2ee3538 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -56,13 +56,13 @@ public void testJavaDefaultExpressionWithNoValues() { @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Expression and default expression are both defined in @Mapping," + message = "Expression and default expression are both defined in @Mapping," + " either define an expression or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 26, - messageRegExp = "Unmapped target property: \"sourceId\"" + message = "Unmapped target property: \"sourceId\"." ) } ) @@ -77,13 +77,13 @@ public void testJavaDefaultExpressionExpression() { @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Constant and default expression are both defined in @Mapping," + message = "Constant and default expression are both defined in @Mapping," + " either define a constant or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionConstantMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 25, - messageRegExp = "Unmapped target property: \"sourceId\"" + message = "Unmapped target property: \"sourceId\"." ) } ) @@ -98,13 +98,13 @@ public void testJavaDefaultExpressionConstant() { @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Default value and default expression are both defined in @Mapping," + message = "Default value and default expression are both defined in @Mapping," + " either define a default value or a default expression." ), @Diagnostic(type = ErroneousDefaultExpressionDefaultValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 25, - messageRegExp = "Unmapped target property: \"sourceId\"" + message = "Unmapped target property: \"sourceId\"." ) } ) @@ -119,7 +119,7 @@ public void testJavaDefaultExpressionDefaultValue() { @Diagnostic(type = ErroneousDefaultExpressionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "Value for default expression must be given in the form \"java\\(\\)\"" + message = "Value for default expression must be given in the form \"java()\"." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index 726690ed80..68d19376de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -150,13 +150,13 @@ public void testGetterOnly() throws ParseException { @Diagnostic(type = ErroneousSourceTargetMapperExpressionAndQualifiers.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 18, - messageRegExp = "Expression and a qualifier both defined in @Mapping," + + message = "Expression and a qualifier both defined in @Mapping," + " either define an expression or a qualifier." ), @Diagnostic(type = ErroneousSourceTargetMapperExpressionAndQualifiers.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "Expression and a qualifier both defined in @Mapping," + + message = "Expression and a qualifier both defined in @Mapping," + " either define an expression or a qualifier." ) } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java index 2f56517e06..549397def7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java @@ -166,15 +166,15 @@ public void shouldUseConfig() { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Several possible source properties for target property \"street\"."), + message = "Several possible source properties for target property \"street\"."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Several possible source properties for target property \"zipCode\"."), + message = "Several possible source properties for target property \"zipCode\"."), @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Several possible source properties for target property \"description\".") + message = "Several possible source properties for target property \"description\".") }) public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { } @@ -193,8 +193,8 @@ public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { type = ErroneousSourceTargetMapper2.class, kind = Kind.ERROR, line = 15, - messageRegExp = "Method has no source parameter named \"houseNo\"\\." + - " Method source parameters are: \"address, person\"\\." + message = "Method has no source parameter named \"houseNo\"." + + " Method source parameters are: \"address, person\"." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java index dea128b27f..6ef6c29532 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java @@ -97,11 +97,11 @@ public void testTargetingThisWithIgnore() { @Diagnostic(type = ErroneousNestedMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "^Several possible source properties for target property \"id\"\\.$"), + message = "Several possible source properties for target property \"id\"."), @Diagnostic(type = ErroneousNestedMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - messageRegExp = "^Several possible source properties for target property \"status\"\\.$") + message = "Several possible source properties for target property \"status\".") } ) public void testNestedDuplicates() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java index 1b5c9c9cc6..f5eda7024d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java @@ -122,13 +122,13 @@ public void shouldInheritConfigurationSeveralArgs() { @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.ERROR, line = 43, - messageRegExp = "Several matching methods exist: forwardCreate\\(\\), " - + "forwardCreate1\\(\\). Specify a name explicitly."), + message = "Several matching methods exist: forwardCreate(), " + + "forwardCreate1(). Specify a name explicitly."), @Diagnostic(type = SourceTargetMapperAmbiguous1.class, kind = Kind.WARNING, line = 44, - messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " - + "expressionProp, nestedResultProp\"") + message = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\".") } ) public void shouldRaiseAmbiguousReverseMethodError() { @@ -142,13 +142,13 @@ public void shouldRaiseAmbiguousReverseMethodError() { @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.ERROR, line = 43, - messageRegExp = "None of the candidates forwardCreate\\(\\), forwardCreate1\\(\\) matches given " + message = "None of the candidates forwardCreate(), forwardCreate1() matches given " + "name: \"blah\"."), @Diagnostic(type = SourceTargetMapperAmbiguous2.class, kind = Kind.WARNING, line = 44, - messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " - + "expressionProp, nestedResultProp\"") + message = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " + + "expressionProp, nestedResultProp\".") } ) public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { @@ -162,13 +162,16 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.ERROR, line = 43, - messageRegExp = "Given name \"forwardCreate\" matches several candidate methods: " - + ".*forwardCreate.*, .*forwardCreate.*"), + message = "Given name \"forwardCreate\" matches several candidate methods: org.mapstruct.ap.test" + + ".template.Target forwardCreate(org.mapstruct.ap.test.template.Source source), void forwardCreate" + + "(org.mapstruct.ap.test.template.Source source, @MappingTarget org.mapstruct.ap.test.template" + + ".Target target)."), @Diagnostic(type = SourceTargetMapperAmbiguous3.class, kind = Kind.WARNING, line = 44, - messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " - + "expressionProp, nestedResultProp\"") } + message = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, expressionProp, " + + "nestedResultProp\".") + } ) public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { } @@ -181,13 +184,12 @@ public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { @Diagnostic(type = SourceTargetMapperNonMatchingName.class, kind = Kind.ERROR, line = 34, - messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: " - + "\"forwardCreate\"."), + message = "Given name \"blah\" does not match the only candidate. Did you mean: \"forwardCreate\"."), @Diagnostic(type = SourceTargetMapperNonMatchingName.class, - kind = Kind.WARNING, + kind = Kind.WARNING, line = 35, - messageRegExp = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, " - + "expressionProp, nestedResultProp\"") + message = "Unmapped target properties: \"stringPropY, integerPropY, constantProp, expressionProp, " + + "nestedResultProp\".") } ) public void shouldAdviseOnSpecifyingCorrectName() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 999064237d..0adcb9e0ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -35,11 +35,11 @@ public class UnmappedSourceTest { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 20, - messageRegExp = "Unmapped source property: \"qux\""), + message = "Unmapped source property: \"qux\"."), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 22, - messageRegExp = "Unmapped source property: \"bar\"") + message = "Unmapped source property: \"bar\".") } ) public void shouldLeaveUnmappedSourcePropertyUnset() { @@ -61,11 +61,11 @@ public void shouldLeaveUnmappedSourcePropertyUnset() { @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, line = 20, - messageRegExp = "Unmapped source property: \"qux\""), + message = "Unmapped source property: \"qux\"."), @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, line = 22, - messageRegExp = "Unmapped source property: \"bar\"") + message = "Unmapped source property: \"bar\".") } ) public void shouldRaiseErrorDueToUnsetSourceProperty() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index b027202d96..4a31fb93ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -36,11 +36,11 @@ public class UnmappedProductTest { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 16, - messageRegExp = "Unmapped target property: \"bar\""), + message = "Unmapped target property: \"bar\"."), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 18, - messageRegExp = "Unmapped target property: \"qux\"") + message = "Unmapped target property: \"qux\".") } ) public void shouldLeaveUnmappedTargetPropertyUnset() { @@ -62,11 +62,11 @@ public void shouldLeaveUnmappedTargetPropertyUnset() { @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, line = 17, - messageRegExp = "Unmapped target property: \"bar\""), + message = "Unmapped target property: \"bar\"."), @Diagnostic(type = ErroneousStrictSourceTargetMapper.class, kind = Kind.ERROR, line = 19, - messageRegExp = "Unmapped target property: \"qux\"") + message = "Unmapped target property: \"qux\".") } ) public void shouldRaiseErrorDueToUnsetTargetProperty() { @@ -81,11 +81,11 @@ public void shouldRaiseErrorDueToUnsetTargetProperty() { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.ERROR, line = 16, - messageRegExp = "Unmapped target property: \"bar\""), + message = "Unmapped target property: \"bar\"."), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.ERROR, line = 18, - messageRegExp = "Unmapped target property: \"qux\"") + message = "Unmapped target property: \"qux\".") } ) public void shouldRaiseErrorDueToUnsetTargetPropertyWithPolicySetViaProcessorOption() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index d2038a9c5c..f04ddf338d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -155,48 +155,50 @@ public void testPreferUpdateMethodEncapsulatingCreateMethod() { @Diagnostic(type = ErroneousOrganizationMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - messageRegExp = "No read accessor found for property \"company\" in target type.") + message = "No read accessor found for property \"company\" in target type.") } ) public void testShouldFailOnPropertyMappingNoPropertyGetter() { } @Test - @WithClasses( { + @WithClasses({ ErroneousOrganizationMapper2.class, OrganizationWithoutTypeGetterEntity.class - } ) + }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, - messageRegExp = "No read accessor found for property \"type\" in target type."), + message = "No read accessor found for property \"type\" in target type."), @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35, - messageRegExp = ".*\\.updatemethods\\.DepartmentEntity does not have an accessible parameterless " + - "constructor\\.") + message = "org.mapstruct.ap.test.updatemethods.DepartmentEntity does not have an accessible " + + "parameterless constructor.") }) - public void testShouldFailOnConstantMappingNoPropertyGetter() { } + public void testShouldFailOnConstantMappingNoPropertyGetter() { + } @Test - @WithClasses( { + @WithClasses({ CompanyMapper1.class, DepartmentInBetween.class, UnmappableCompanyDto.class, UnmappableDepartmentDto.class - } ) + }) @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = CompanyMapper1.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 23, - messageRegExp = "Unmapped target property: \"employees\"\\. Mapping from property \"" + - ".*UnmappableDepartmentDto department\" to \".*DepartmentEntity department.") + message = "Unmapped target property: \"employees\". Mapping from property \"org.mapstruct.ap.test" + + ".updatemethods.UnmappableDepartmentDto department\" to \"org.mapstruct.ap.test.updatemethods" + + ".DepartmentEntity department\".") } ) public void testShouldNotUseTwoNestedUpdateMethods() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java index 51f867947a..43b621f8cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java @@ -217,7 +217,7 @@ public void shouldMapAnyRemainingToNullCorrectly() { @Diagnostic(type = ErroneousOrderMapperMappingSameConstantTwice.class, kind = Kind.ERROR, line = 27, - messageRegExp = "Source value mapping: \"EXTRA\" cannot be mapped more than once\\.") + message = "Source value mapping: \"EXTRA\" cannot be mapped more than once.") } ) public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { @@ -231,12 +231,12 @@ public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, line = 26, - messageRegExp = "Constant FOO doesn't exist in enum type org.mapstruct.ap.test.value.OrderType\\."), + message = "Constant FOO doesn't exist in enum type org.mapstruct.ap.test.value.OrderType."), @Diagnostic(type = ErroneousOrderMapperUsingUnknownEnumConstants.class, kind = Kind.ERROR, line = 27, - messageRegExp = "Constant BAR doesn't exist in enum type org.mapstruct.ap.test.value." + - "ExternalOrderType\\.") + message = "Constant BAR doesn't exist in enum type org.mapstruct.ap.test.value." + + "ExternalOrderType.") } ) public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { @@ -250,8 +250,8 @@ public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { @Diagnostic(type = ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class, kind = Kind.ERROR, line = 23, - messageRegExp = "The following constants from the source enum have no corresponding constant in the " + - "target enum and must be be mapped via adding additional mappings: EXTRA, STANDARD, NORMAL") + message = "The following constants from the source enum have no corresponding constant in the " + + "target enum and must be be mapped via adding additional mappings: EXTRA, STANDARD, NORMAL.") } ) public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeIsNotMapped() { @@ -265,7 +265,7 @@ public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeI @Diagnostic(type = ErroneousOrderMapperDuplicateANY.class, kind = Kind.ERROR, line = 28, - messageRegExp = "Source = \"\" or \"\" can only be used once\\." ) + message = "Source = \"\" or \"\" can only be used once." ) } ) public void shouldRaiseErrorIfMappingsContainDuplicateANY() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java index 2f1be53125..145721b83d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java @@ -50,8 +50,8 @@ public void testRemainingAndNull() { @Diagnostic(type = ErroneousOrderMapperUsingAnyRemaining.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 26, - messageRegExp = "\"\" can only be used on targets of type enum and not for " + - "java\\.lang\\.String\\.") + message = "Source = \"\" can only be used on targets of type enum and not for " + + "java.lang.String.") } ) public void shouldRaiseErrorWhenUsingAnyRemaining() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java index 552766d240..7bf06ab860 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java @@ -49,8 +49,8 @@ public void testRemainingAndNull() { @Diagnostic(type = ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 28, - messageRegExp = "Source = \"\" or \"\" is advisable for mapping of " + - "type String to an enum type" ) + message = "Source = \"\" or \"\" is advisable for mapping of " + + "type String to an enum type." ) } ) public void shouldRaiseErrorWhenUsingAnyRemaining() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java index c042e3d073..fd17eed070 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java @@ -60,10 +60,10 @@ public void testGeneralWithOtherSPI() { } @Test - @DisabledOnCompiler( { + @DisabledOnCompiler({ Compiler.ECLIPSE, Compiler.ECLIPSE11 - } ) + }) @WithServiceImplementation(provides = AstModifyingAnnotationProcessor.class, value = AstModifyingAnnotationProcessorSaysNo.class) @ProcessorOption(name = "mapstruct.verbose", value = "true") @@ -74,8 +74,10 @@ public void testGeneralWithOtherSPI() { type = CreateBeanMapping.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 12, - messageRegExp = ".*No implementation was created for CreateBeanMapping due to having a problem in the " + - "erroneous element .*" + message = "No implementation was created for CreateBeanMapping due to having a problem in the erroneous " + + "element java.util.ArrayList. Hint: this often means that some other annotation processor was " + + "supposed to process the erroneous element. You can also enable MapStruct verbose mode by setting " + + "-Amapstruct.verbose=true as a compilation argument." ) }) public void testDeferred() { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java index b2016f1c2d..982c3e42e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java @@ -45,6 +45,14 @@ */ long alternativeLine() default -1; + /** + * A message matching the exact expected message of the diagnostic. + * + * @return A message matching the exact expected message of the + * diagnostic. + */ + String message() default ""; + /** * A regular expression matching the expected message of the diagnostic. * Wild-cards matching any character (".*") will be added to the beginning diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index 5a87bf0a09..94dda74708 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -29,17 +29,20 @@ public class DiagnosticDescriptor { private final Long line; private final Long alternativeLine; private final String message; + private final String messageRegex; - private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message) { - this( sourceFileName, kind, line, null, message ); + private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message, String messageRegex) { + this( sourceFileName, kind, line, null, message, messageRegex ); } - private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long alternativeLine, String message) { + private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long alternativeLine, String message, + String messageRegex) { this.sourceFileName = sourceFileName; this.kind = kind; this.line = line; this.alternativeLine = alternativeLine; this.message = message; + this.messageRegex = messageRegex; } public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) { @@ -51,6 +54,7 @@ public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) { diagnostic.kind(), diagnostic.line() != -1 ? diagnostic.line() : null, diagnostic.alternativeLine() != -1 ? diagnostic.alternativeLine() : null, + diagnostic.message(), diagnostic.messageRegExp() ); } @@ -61,7 +65,8 @@ public static DiagnosticDescriptor forDiagnostic(String sourceDir, getSourceName( sourceDir, diagnostic ), diagnostic.getKind(), diagnostic.getLineNumber(), - diagnostic.getMessage( null ) + diagnostic.getMessage( null ), + null ); } @@ -73,7 +78,9 @@ public static DiagnosticDescriptor forCompilerMessage(String sourceDir, Compiler removeSourceDirPrefix( sourceDir, compilerMessage.getFile() ), toJavaxKind( compilerMessage.getKind() ), Long.valueOf( compilerMessage.getStartLine() ), - message ); + message, + null + ); } private static Kind toJavaxKind(CompilerMessage.Kind kind) { @@ -151,6 +158,10 @@ public String getMessage() { return message; } + public String getMessageRegex() { + return messageRegex; + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index ca51554f30..e735db715d 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -311,14 +311,26 @@ else if ( expected.getLine() != null ) { assertThat( actual.getLine() ).isEqualTo( expected.getLine() ); } assertThat( actual.getKind() ).isEqualTo( expected.getKind() ); - assertThat( actual.getMessage() ).describedAs( - String.format( - "Unexpected message for diagnostic %s:%s %s", - actual.getSourceFileName(), - actual.getLine(), - actual.getKind() - ) - ).matches( "(?ms).*" + expected.getMessage() + ".*" ); + if ( expected.getMessage() != null && !expected.getMessage().isEmpty() ) { + assertThat( actual.getMessage() ).describedAs( + String.format( + "Unexpected message for diagnostic %s:%s %s", + actual.getSourceFileName(), + actual.getLine(), + actual.getKind() + ) + ).isEqualTo( expected.getMessage() ); + } + else { + assertThat( actual.getMessage() ).describedAs( + String.format( + "Unexpected message for diagnostic %s:%s %s", + actual.getSourceFileName(), + actual.getLine(), + actual.getKind() + ) + ).matches( "(?ms).*" + expected.getMessage() + ".*" ); + } } } From 1bbc4e1ca852d2fe414cf7813c0de1ac6dab71f3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Apr 2020 12:26:07 +0200 Subject: [PATCH 0453/1006] Use expected.getMessageRegex when no message for the Diagnostic descriptor has been defined --- .../org/mapstruct/ap/testutil/runner/CompilingStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index e735db715d..e8c09bec98 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -329,7 +329,7 @@ else if ( expected.getLine() != null ) { actual.getLine(), actual.getKind() ) - ).matches( "(?ms).*" + expected.getMessage() + ".*" ); + ).matches( "(?ms).*" + expected.getMessageRegex() + ".*" ); } } } From c58f80cc5f403a1d177411c6c633fa4faaaa9d83 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Apr 2020 13:27:31 +0200 Subject: [PATCH 0454/1006] #2069 Refactor target reference to report errors during bean mapping instead of creation of the target reference With this we can more easily go in the direction of using constructor to map into target beans. --- .../resources/build-config/checkstyle.xml | 4 +- .../ap/internal/model/BeanMappingMethod.java | 227 ++++++++--- .../internal/model/MappingBuilderContext.java | 4 + .../NestedTargetPropertyMappingHolder.java | 107 +++-- .../ap/internal/model/PropertyMapping.java | 34 +- .../model/beanmapping/MappingReference.java | 6 +- .../model/beanmapping/MappingReferences.java | 14 +- .../model/beanmapping/PropertyEntry.java | 48 +-- .../model/beanmapping/TargetReference.java | 381 +++++------------- .../internal/model/source/MappingOptions.java | 12 + .../DefaultModelElementProcessorContext.java | 1 + .../processor/MapperCreationProcessor.java | 6 +- .../ap/internal/util/FormattingMessager.java | 2 + .../mapstruct/ap/internal/util/Message.java | 2 + .../common/DefaultConversionContextTest.java | 4 + .../ap/test/bugs/_1153/Issue1153Test.java | 10 +- .../SuggestMostSimilarNameTest.java | 16 +- .../selection/generics/ConversionTest.java | 5 +- .../ErroneousSourceTargetMapper6.java | 8 + 19 files changed, 436 insertions(+), 455 deletions(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 5ae53dc46f..945015d5cd 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -122,7 +122,9 @@ - + + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1fcf8e4ce2..5cb2192aae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -22,12 +22,13 @@ import javax.lang.model.type.DeclaredType; import javax.tools.Diagnostic; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.JavaExpressionMappingBuilder; import org.mapstruct.ap.internal.model.PropertyMapping.PropertyMappingBuilder; import org.mapstruct.ap.internal.model.beanmapping.MappingReference; import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; -import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.model.beanmapping.SourceReference; import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.model.common.BuilderType; @@ -40,8 +41,6 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; -import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -96,7 +95,6 @@ public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { public Builder sourceMethod(SourceMethod sourceMethod) { this.method = sourceMethod; - this.mappingReferences = forSourceMethod( sourceMethod, ctx.getMessager(), ctx.getTypeFactory() ); return this; } @@ -131,6 +129,7 @@ public BeanMappingMethod build() { MethodReference factoryMethod = null; // determine which return type to construct + boolean cannotConstructReturnType = false; if ( !method.getReturnType().isVoid() ) { Type returnTypeImpl = getReturnTypeToConstructFromSelectionParameters( selectionParameters ); if ( returnTypeImpl != null ) { @@ -138,6 +137,9 @@ public BeanMappingMethod build() { if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } + else { + cannotConstructReturnType = true; + } } else if ( isBuilderRequired() ) { returnTypeImpl = returnTypeBuilder.getBuilder(); @@ -145,6 +147,9 @@ else if ( isBuilderRequired() ) { if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } + else { + cannotConstructReturnType = true; + } } else if ( !method.isUpdateMethod() ) { returnTypeImpl = method.getReturnType(); @@ -152,9 +157,17 @@ else if ( !method.isUpdateMethod() ) { if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } + else { + cannotConstructReturnType = true; + } } } + if ( cannotConstructReturnType ) { + // If the return type cannot be constructed then no need to try to create mappings + return null; + } + /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; @@ -187,8 +200,10 @@ else if ( !method.isUpdateMethod() ) { } } + initializeMappingReferencesIfNeeded( resultTypeToMap ); + // map properties with mapping - boolean mappingErrorOccurred = handleDefinedMappings(); + boolean mappingErrorOccurred = handleDefinedMappings( resultTypeToMap ); if ( mappingErrorOccurred ) { return null; } @@ -261,6 +276,20 @@ else if ( !method.isUpdateMethod() ) { ); } + private void initializeMappingReferencesIfNeeded(Type resultTypeToMap) { + if ( mappingReferences == null && method instanceof SourceMethod ) { + Set readAndWriteTargetProperties = new HashSet<>( unprocessedTargetProperties.keySet() ); + readAndWriteTargetProperties.addAll( resultTypeToMap.getPropertyReadAccessors().keySet() ); + mappingReferences = forSourceMethod( + (SourceMethod) method, + resultTypeToMap, + readAndWriteTargetProperties, + ctx.getMessager(), + ctx.getTypeFactory() + ); + } + } + /** * @return builder is required when there is a returnTypeBuilder and the mapping method is not update method. * However, builder is also required when there is a returnTypeBuilder, the mapping target is the builder and @@ -320,9 +349,11 @@ private void handleUnprocessedDefinedTargets() { PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) - .targetWriteAccessor( unprocessedTargetProperties.get( propertyName ) ) - .targetReadAccessor( targetPropertyReadAccessor ) - .targetPropertyName( propertyName ) + .target( + propertyName, + targetPropertyReadAccessor, + unprocessedTargetProperties.get( propertyName ) + ) .sourceReference( reference ) .existingVariableNames( existingVariableNames ) .dependsOn( mappingRefs.collectNestedDependsOn() ) @@ -464,22 +495,24 @@ private MethodReference getFactoryMethod(Type returnTypeImpl, SelectionParameter *

        * It is furthermore checked whether the given mappings are correct. When an error occurs, the method continues * in search of more problems. + * + * @param resultTypeToMap the type in which the defined target properties are defined */ - private boolean handleDefinedMappings() { + private boolean handleDefinedMappings(Type resultTypeToMap) { boolean errorOccurred = false; Set handledTargets = new HashSet<>(); // first we have to handle nested target mappings if ( mappingReferences.hasNestedTargetReferences() ) { - errorOccurred = handleDefinedNestedTargetMapping( handledTargets ); + errorOccurred = handleDefinedNestedTargetMapping( handledTargets, resultTypeToMap ); } for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { if ( mapping.isValid() ) { String target = mapping.getTargetReference().getShallowestPropertyName(); if ( !handledTargets.contains( target ) ) { - if ( handleDefinedMapping( mapping, handledTargets ) ) { + if ( handleDefinedMapping( mapping, resultTypeToMap, handledTargets ) ) { errorOccurred = true; } } @@ -504,11 +537,13 @@ private boolean handleDefinedMappings() { return errorOccurred; } - private boolean handleDefinedNestedTargetMapping(Set handledTargets) { + private boolean handleDefinedNestedTargetMapping(Set handledTargets, Type resultTypeToMap) { NestedTargetPropertyMappingHolder holder = new NestedTargetPropertyMappingHolder.Builder() .mappingContext( ctx ) .method( method ) + .targetPropertiesWriteAccessors( unprocessedTargetProperties ) + .targetPropertyType( resultTypeToMap ) .mappingReferences( mappingReferences ) .existingVariableNames( existingVariableNames ) .build(); @@ -517,26 +552,24 @@ private boolean handleDefinedNestedTargetMapping(Set handledTargets) { propertyMappings.addAll( holder.getPropertyMappings() ); handledTargets.addAll( holder.getHandledTargets() ); // Store all the unprocessed defined targets. - for ( Entry> entry : holder.getUnprocessedDefinedTarget() + for ( Entry> entry : holder.getUnprocessedDefinedTarget() .entrySet() ) { if ( entry.getValue().isEmpty() ) { continue; } - unprocessedDefinedTargets.put( entry.getKey().getName(), entry.getValue() ); + unprocessedDefinedTargets.put( entry.getKey(), entry.getValue() ); } return holder.hasErrorOccurred(); } - private boolean handleDefinedMapping(MappingReference mappingRef, Set handledTargets) { - + private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTypeToMap, + Set handledTargets) { boolean errorOccured = false; PropertyMapping propertyMapping = null; TargetReference targetRef = mappingRef.getTargetReference(); MappingOptions mapping = mappingRef.getMapping(); - PropertyEntry targetProperty = first( targetRef.getPropertyEntries() ); - String targetPropertyName = targetProperty.getName(); // unknown properties given via dependsOn()? for ( String dependency : mapping.getDependsOn() ) { @@ -552,16 +585,95 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Set ha } } + String targetPropertyName = first( targetRef.getPropertyEntries() ); + // check if source / expression / constant are not somehow handled already if ( unprocessedDefinedTargets.containsKey( targetPropertyName ) ) { return false; } + Accessor targetWriteAccessor = unprocessedTargetProperties.get( targetPropertyName ); + Accessor targetReadAccessor = resultTypeToMap.getPropertyReadAccessors().get( targetPropertyName ); + + if ( targetWriteAccessor == null ) { + if ( targetReadAccessor == null ) { + Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); + String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); + + Message msg; + Object[] args; + + if ( targetRef.getPathProperties().isEmpty() ) { + msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; + args = new Object[] { + targetPropertyName, + resultTypeToMap, + mostSimilarProperty + }; + } + else { + List pathProperties = new ArrayList<>( targetRef.getPathProperties() ); + pathProperties.add( mostSimilarProperty ); + msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE; + args = new Object[] { + targetPropertyName, + resultTypeToMap, + mapping.getTargetName(), + Strings.join( pathProperties, "." ) + }; + } + + ctx.getMessager() + .printMessage( + mapping.getElement(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + msg, + args + ); + return true; + } + else if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { + // read only reversed mappings are implicitly ignored + return false; + } + else if ( !mapping.isIgnored() ) { + // report an error for read only mappings + Message msg; + Object[] args; + + if ( Objects.equals( targetPropertyName, mapping.getTargetName() ) ) { + msg = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE; + args = new Object[] { + mapping.getTargetName(), + resultTypeToMap + }; + } + else { + msg = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_TYPE; + args = new Object[] { + targetPropertyName, + resultTypeToMap, + mapping.getTargetName() + }; + } + ctx.getMessager() + .printMessage( + mapping.getElement(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + msg, + args + ); + return true; + } + } + // check the mapping options // its an ignored property mapping if ( mapping.isIgnored() ) { propertyMapping = null; - handledTargets.add( targetProperty.getName() ); + handledTargets.add( targetPropertyName ); } // its a constant @@ -573,8 +685,7 @@ else if ( mapping.getConstant() != null ) { .mappingContext( ctx ) .sourceMethod( method ) .constantExpression( mapping.getConstant() ) - .targetProperty( targetProperty ) - .targetPropertyName( targetPropertyName ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .formattingParameters( mapping.getFormattingParameters() ) .selectionParameters( mapping.getSelectionParameters() ) .options( mapping ) @@ -595,8 +706,7 @@ else if ( mapping.getJavaExpression() != null ) { .sourceMethod( method ) .javaExpression( mapping.getJavaExpression() ) .existingVariableNames( existingVariableNames ) - .targetProperty( targetProperty ) - .targetPropertyName( targetPropertyName ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .dependsOn( mapping.getDependsOn() ) .mirror( mapping.getMirror() ) .build(); @@ -618,8 +728,7 @@ else if ( mapping.getJavaExpression() != null ) { propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) - .targetProperty( targetProperty ) - .targetPropertyName( targetPropertyName ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .sourcePropertyName( mapping.getSourceName() ) .sourceReference( sourceRef ) .selectionParameters( mapping.getSelectionParameters() ) @@ -723,15 +832,13 @@ private void applyPropertyNameBasedMapping(List sourceReference method.getResultType().getPropertyReadAccessors().get( targetPropertyName ); MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) - .sourceMethod( method ) - .targetWriteAccessor( targetPropertyWriteAccessor ) - .targetReadAccessor( targetPropertyReadAccessor ) - .targetPropertyName( targetPropertyName ) - .sourceReference( sourceRef ) - .existingVariableNames( existingVariableNames ) - .forgeMethodWithMappingReferences( mappingRefs ) - .options( method.getOptions().getBeanMapping() ) - .build(); + .sourceMethod( method ) + .target( targetPropertyName, targetPropertyReadAccessor, targetPropertyWriteAccessor ) + .sourceReference( sourceRef ) + .existingVariableNames( existingVariableNames ) + .forgeMethodWithMappingReferences( mappingRefs ) + .options( method.getOptions().getBeanMapping() ) + .build(); unprocessedSourceParameters.remove( sourceRef.getParameter() ); @@ -770,9 +877,7 @@ private void applyParameterNameBasedMapping() { PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) .sourceMethod( method ) - .targetWriteAccessor( targetProperty.getValue() ) - .targetReadAccessor( targetPropertyReadAccessor ) - .targetPropertyName( targetProperty.getKey() ) + .target( targetProperty.getKey(), targetPropertyReadAccessor, targetProperty.getValue() ) .sourceReference( sourceRef ) .existingVariableNames( existingVariableNames ) .forgeMethodWithMappingReferences( mappingRefs ) @@ -866,17 +971,25 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { } else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { - Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? - Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; - Object[] args = new Object[] { - MessageFormat.format( - "{0,choice,1#property|1 processedSourceParameters; private final Set handledTargets; private final List propertyMappings; - private final Map> unprocessedDefinedTarget; + private final Map> unprocessedDefinedTarget; private final boolean errorOccurred; public NestedTargetPropertyMappingHolder( List processedSourceParameters, Set handledTargets, List propertyMappings, - Map> unprocessedDefinedTarget, boolean errorOccurred) { + Map> unprocessedDefinedTarget, boolean errorOccurred) { this.processedSourceParameters = processedSourceParameters; this.handledTargets = handledTargets; this.propertyMappings = propertyMappings; @@ -75,7 +79,7 @@ public List getPropertyMappings() { /** * @return a map of all the unprocessed defined targets that can be applied to name forged base methods */ - public Map> getUnprocessedDefinedTarget() { + public Map> getUnprocessedDefinedTarget() { return unprocessedDefinedTarget; } @@ -94,6 +98,9 @@ public static class Builder { private Set existingVariableNames; private List propertyMappings; private Set handledTargets; + private Map targetPropertiesWriteAccessors; + private Type targetType; + private boolean errorOccurred; public Builder mappingReferences(MappingReferences mappingReferences) { this.mappingReferences = mappingReferences; @@ -115,6 +122,16 @@ public Builder existingVariableNames(Set existingVariableNames) { return this; } + public Builder targetPropertiesWriteAccessors(Map targetPropertiesWriteAccessors) { + this.targetPropertiesWriteAccessors = targetPropertiesWriteAccessors; + return this; + } + + public Builder targetPropertyType(Type targetType) { + this.targetType = targetType; + return this; + } + public NestedTargetPropertyMappingHolder build() { List processedSourceParameters = new ArrayList<>(); handledTargets = new HashSet<>(); @@ -123,11 +140,11 @@ public NestedTargetPropertyMappingHolder build() { // first we group by the first property in the target properties and for each of those // properties we get the new mappings as if the first property did not exist. GroupedTargetReferences groupedByTP = groupByTargetReferences( ); - Map> unprocessedDefinedTarget = new LinkedHashMap<>(); + Map> unprocessedDefinedTarget = new LinkedHashMap<>(); - for ( Map.Entry> entryByTP : + for ( Map.Entry> entryByTP : groupedByTP.poppedTargetReferences.entrySet() ) { - PropertyEntry targetProperty = entryByTP.getKey(); + String targetProperty = entryByTP.getKey(); //Now we are grouping the already popped mappings by the source parameter(s) of the method GroupedBySourceParameters groupedBySourceParam = groupBySourceParameter( entryByTP.getValue(), @@ -188,7 +205,7 @@ public NestedTargetPropertyMappingHolder build() { .type( sourceEntry.getType() ) .readAccessor( sourceEntry.getReadAccessor() ) .presenceChecker( sourceEntry.getPresenceChecker() ) - .name( targetProperty.getName() ) + .name( targetProperty ) .build(); // If we have multiple source parameters that are mapped to the target reference, or @@ -205,7 +222,7 @@ public NestedTargetPropertyMappingHolder build() { propertyMappings.add( propertyMapping ); } - handledTargets.add( entryByTP.getKey().getName() ); + handledTargets.add( entryByTP.getKey() ); } // For the nonNested mappings (assymetric) Mappings we also forge mappings @@ -216,7 +233,7 @@ public NestedTargetPropertyMappingHolder build() { new MappingReferences( groupedSourceReferences.nonNested, true ); SourceReference reference = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) - .name( targetProperty.getName() ) + .name( targetProperty ) .build(); boolean forceUpdateMethodForNonNested = @@ -236,7 +253,7 @@ public NestedTargetPropertyMappingHolder build() { propertyMappings.add( propertyMapping ); } - handledTargets.add( entryByTP.getKey().getName() ); + handledTargets.add( entryByTP.getKey() ); } handleSourceParameterMappings( @@ -255,7 +272,7 @@ public NestedTargetPropertyMappingHolder build() { handledTargets, propertyMappings, unprocessedDefinedTarget, - groupedByTP.errorOccurred + errorOccurred ); } @@ -268,7 +285,7 @@ public NestedTargetPropertyMappingHolder build() { * @param forceUpdateMethod whether we need to force an update method */ private void handleSourceParameterMappings(Set sourceParameterMappings, - PropertyEntry targetProperty, Parameter sourceParameter, + String targetProperty, Parameter sourceParameter, boolean forceUpdateMethod) { if ( !sourceParameterMappings.isEmpty() ) { // The source parameter mappings have no mappings, the source name is actually the parameter itself @@ -276,7 +293,7 @@ private void handleSourceParameterMappings(Set sourceParameter new MappingReferences( Collections.emptySet(), false, true ); SourceReference reference = new SourceReference.BuilderFromProperty() .sourceParameter( sourceParameter ) - .name( targetProperty.getName() ) + .name( targetProperty ) .build(); PropertyMapping propertyMapping = createPropertyMappingForNestedTarget( @@ -290,7 +307,7 @@ private void handleSourceParameterMappings(Set sourceParameter propertyMappings.add( propertyMapping ); } - handledTargets.add( targetProperty.getName() ); + handledTargets.add( targetProperty ); } } @@ -340,16 +357,11 @@ private void handleSourceParameterMappings(Set sourceParameter */ private GroupedTargetReferences groupByTargetReferences( ) { // group all mappings based on the top level name before popping - Map> mappingsKeyedByProperty = new LinkedHashMap<>(); - Map> singleTargetReferences = new LinkedHashMap<>(); - boolean errorOccurred = false; + Map> mappingsKeyedByProperty = new LinkedHashMap<>(); + Map> singleTargetReferences = new LinkedHashMap<>(); for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { TargetReference targetReference = mapping.getTargetReference(); - if ( !targetReference.isValid() ) { - errorOccurred = true; - continue; - } - PropertyEntry property = first( targetReference.getPropertyEntries() ); + String property = first( targetReference.getPropertyEntries() ); MappingReference newMapping = mapping.popTargetReference(); if ( newMapping != null ) { // group properties on current name. @@ -362,7 +374,7 @@ private GroupedTargetReferences groupByTargetReferences( ) { } } - return new GroupedTargetReferences( mappingsKeyedByProperty, singleTargetReferences, errorOccurred ); + return new GroupedTargetReferences( mappingsKeyedByProperty, singleTargetReferences ); } /** @@ -625,14 +637,45 @@ private Set extractSingleTargetReferencesToUseAndPopulateSourc } private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences mappingReferences, - PropertyEntry targetProperty, + String targetPropertyName, SourceReference sourceReference, boolean forceUpdateMethod) { + + Accessor targetWriteAccessor = targetPropertiesWriteAccessors.get( targetPropertyName ); + Accessor targetReadAccessor = targetType.getPropertyReadAccessors().get( targetPropertyName ); + if ( targetWriteAccessor == null ) { + Set readAccessors = targetType.getPropertyReadAccessors().keySet(); + String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); + + for ( MappingReference mappingReference : mappingReferences.getMappingReferences() ) { + MappingOptions mapping = mappingReference.getMapping(); + List pathProperties = new ArrayList<>( mappingReference.getTargetReference() + .getPathProperties() ); + if ( !pathProperties.isEmpty() ) { + pathProperties.set( pathProperties.size() - 1, mostSimilarProperty ); + } + + mappingContext.getMessager() + .printMessage( + mapping.getElement(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE, + targetPropertyName, + targetType, + mapping.getTargetName(), + Strings.join( pathProperties, "." ) + ); + } + + errorOccurred = true; + return null; + } + return new PropertyMapping.PropertyMappingBuilder() .mappingContext( mappingContext ) .sourceMethod( method ) - .targetProperty( targetProperty ) - .targetPropertyName( targetProperty.getName() ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .sourceReference( sourceReference ) .existingVariableNames( existingVariableNames ) .dependsOn( mappingReferences.collectNestedDependsOn() ) @@ -685,21 +728,19 @@ private GroupedBySourceParameters(Map> groupedB * references (target references that were not nested). */ private static class GroupedTargetReferences { - private final Map> poppedTargetReferences; - private final Map> singleTargetReferences; - private final boolean errorOccurred; + private final Map> poppedTargetReferences; + private final Map> singleTargetReferences; - private GroupedTargetReferences(Map> poppedTargetReferences, - Map> singleTargetReferences, boolean errorOccurred) { + private GroupedTargetReferences(Map> poppedTargetReferences, + Map> singleTargetReferences) { this.poppedTargetReferences = poppedTargetReferences; this.singleTargetReferences = singleTargetReferences; - this.errorOccurred = errorOccurred; } @Override public String toString() { return "GroupedTargetReferences{" + "poppedTargetReferences=" + poppedTargetReferences - + ", singleTargetReferences=" + singleTargetReferences + ", errorOccurred=" + errorOccurred + '}'; + + ", singleTargetReferences=" + singleTargetReferences + "}"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 06de2aa397..24facce722 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -94,21 +94,9 @@ public T sourceMethod(Method sourceMethod) { return super.method( sourceMethod ); } - public T targetProperty(PropertyEntry targetProp) { - this.targetReadAccessor = targetProp.getReadAccessor(); - this.targetWriteAccessor = targetProp.getWriteAccessor(); - this.targetType = targetProp.getType(); - this.targetBuilderType = targetProp.getBuilderType(); - this.targetWriteAccessorType = targetWriteAccessor.getAccessorType(); - return (T) this; - } - - public T targetReadAccessor(Accessor targetReadAccessor) { + public T target(String targetPropertyName, Accessor targetReadAccessor, Accessor targetWriteAccessor) { + this.targetPropertyName = targetPropertyName; this.targetReadAccessor = targetReadAccessor; - return (T) this; - } - - public T targetWriteAccessor(Accessor targetWriteAccessor) { this.targetWriteAccessor = targetWriteAccessor; this.targetType = ctx.getTypeFactory().getType( targetWriteAccessor.getAccessedType() ); BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); @@ -122,11 +110,6 @@ T mirror(AnnotationMirror mirror) { return (T) this; } - public T targetPropertyName(String targetPropertyName) { - this.targetPropertyName = targetPropertyName; - return (T) this; - } - public T sourcePropertyName(String sourcePropertyName) { this.sourcePropertyName = sourcePropertyName; return (T) this; @@ -326,6 +309,11 @@ else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) * Report that a mapping could not be created. */ private void reportCannotCreateMapping() { + if ( forgeMethodWithMappingReferences != null && ctx.isErroneous() ) { + // If we arrived here, there is an error it means that we couldn't forge a mapping method + // so skip the cannot create mapping + return; + } if ( method instanceof ForgedMethod && ( (ForgedMethod) method ).getHistory() != null ) { // The history that is part of the ForgedMethod misses the information from the current right hand // side. Therefore we need to extract the most relevant history and use that in the error reporting. @@ -363,9 +351,7 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { .existingVariableNames( existingVariableNames ) .mappingContext( ctx ) .sourceMethod( method ) - .targetPropertyName( targetPropertyName ) - .targetReadAccessor( targetReadAccessor ) - .targetWriteAccessor( targetWriteAccessor ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .build(); return build.getAssignment(); } @@ -378,9 +364,7 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { .existingVariableNames( existingVariableNames ) .mappingContext( ctx ) .sourceMethod( method ) - .targetPropertyName( targetPropertyName ) - .targetReadAccessor( targetReadAccessor ) - .targetWriteAccessor( targetWriteAccessor ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .build(); return build.getAssignment(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java index 2675e29007..e2501ea952 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java @@ -80,11 +80,7 @@ public int hashCode() { } public boolean isValid( ) { - boolean result = false; - if ( targetReference.isValid() ) { - result = sourceReference != null ? sourceReference.isValid() : true; - } - return result; + return sourceReference == null || sourceReference.isValid(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index 63af65f2e2..06f0ed06c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.SourceMethod; @@ -29,8 +30,11 @@ public static MappingReferences empty() { return EMPTY; } - public static MappingReferences forSourceMethod(SourceMethod sourceMethod, FormattingMessager messager, - TypeFactory typeFactory) { + public static MappingReferences forSourceMethod(SourceMethod sourceMethod, + Type targetType, + Set targetProperties, + FormattingMessager messager, + TypeFactory typeFactory) { Set references = new LinkedHashSet<>(); List targetThisReferences = new ArrayList<>( ); @@ -49,6 +53,8 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, Forma .method( sourceMethod ) .messager( messager ) .typeFactory( typeFactory ) + .targetProperties( targetProperties ) + .targetType( targetType ) .build(); // add when inverse is also valid @@ -121,7 +127,7 @@ public boolean hasNestedTargetReferences() { for ( MappingReference mappingRef : mappingReferences ) { TargetReference targetReference = mappingRef.getTargetReference(); - if ( targetReference.isValid() && targetReference.isNested()) { + if ( targetReference.isNested()) { return true; } @@ -141,7 +147,7 @@ public List getTargetThisReferences() { private static boolean isValidWhenInversed(MappingReference mappingRef) { MappingOptions mapping = mappingRef.getMapping(); if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { - return mappingRef.getTargetReference().isValid() && ( mappingRef.getSourceReference() == null || + return ( mappingRef.getSourceReference() == null || mappingRef.getSourceReference().isValid() ); } return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java index f2d087cd93..8ac5e46671 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java @@ -7,55 +7,33 @@ import java.util.Arrays; -import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; /** - * A PropertyEntry contains information on the name, readAccessor (for source), readAccessor and writeAccessor - * (for targets) and return type of a property. + * A PropertyEntry contains information on the name, readAccessor and presenceCheck (for source) + * and return type of a property. */ public class PropertyEntry { private final String[] fullName; private final Accessor readAccessor; - private final Accessor writeAccessor; private final Accessor presenceChecker; private final Type type; - private final BuilderType builderType; /** * Constructor used to create {@link TargetReference} property entries from a mapping * * @param fullName * @param readAccessor - * @param writeAccessor * @param type */ - private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor writeAccessor, - Accessor presenceChecker, Type type, BuilderType builderType) { + private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor presenceChecker, Type type) { this.fullName = fullName; this.readAccessor = readAccessor; - this.writeAccessor = writeAccessor; this.presenceChecker = presenceChecker; this.type = type; - this.builderType = builderType; - } - - /** - * Constructor used to create {@link TargetReference} property entries - * - * @param fullName name of the property (dot separated) - * @param readAccessor its read accessor - * @param writeAccessor its write accessor - * @param type type of the property - * @param builderType the builder for the type - * @return the property entry for given parameters. - */ - public static PropertyEntry forTargetReference(String[] fullName, Accessor readAccessor, - Accessor writeAccessor, Type type, BuilderType builderType ) { - return new PropertyEntry( fullName, readAccessor, writeAccessor, null, type, builderType ); } /** @@ -69,7 +47,7 @@ public static PropertyEntry forTargetReference(String[] fullName, Accessor readA */ public static PropertyEntry forSourceReference(String[] name, Accessor readAccessor, Accessor presenceChecker, Type type) { - return new PropertyEntry( name, readAccessor, null, presenceChecker, type, null ); + return new PropertyEntry( name, readAccessor, presenceChecker, type ); } public String getName() { @@ -80,10 +58,6 @@ public Accessor getReadAccessor() { return readAccessor; } - public Accessor getWriteAccessor() { - return writeAccessor; - } - public Accessor getPresenceChecker() { return presenceChecker; } @@ -92,24 +66,10 @@ public Type getType() { return type; } - public BuilderType getBuilderType() { - return builderType; - } - public String getFullName() { return Strings.join( Arrays.asList( fullName ), "." ); } - public PropertyEntry pop() { - if ( fullName.length > 1 ) { - String[] newFullName = Arrays.copyOfRange( fullName, 1, fullName.length ); - return new PropertyEntry(newFullName, readAccessor, writeAccessor, presenceChecker, type, builderType ); - } - else { - return null; - } - } - @Override public int hashCode() { int hash = 7; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index 8a2a398232..fee97f840d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -7,26 +7,21 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; -import javax.lang.model.type.DeclaredType; -import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.gem.BuilderGem; -import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; -import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.util.Collections.first; @@ -48,11 +43,77 @@ *

      • {@code propertyEntries[1]} will describe {@code propB}
      • *
      * - * After building, {@link #isValid()} will return true when when no problems are detected during building. - * * @author Sjaak Derksen */ -public class TargetReference extends AbstractReference { +public class TargetReference { + + private final List pathProperties; + private final Parameter parameter; + private final List propertyEntries; + + public TargetReference(Parameter parameter, List propertyEntries) { + this( parameter, propertyEntries, Collections.emptyList() ); + } + + public TargetReference(Parameter parameter, List propertyEntries, List pathProperties) { + this.pathProperties = pathProperties; + this.parameter = parameter; + this.propertyEntries = propertyEntries; + } + + public List getPathProperties() { + return pathProperties; + } + + public List getPropertyEntries() { + return propertyEntries; + } + + public List getElementNames() { + List elementNames = new ArrayList<>(); + if ( parameter != null ) { + // only relevant for source properties + elementNames.add( parameter.getName() ); + } + elementNames.addAll( propertyEntries ); + return elementNames; + } + + /** + * returns the property name on the shallowest nesting level + */ + public String getShallowestPropertyName() { + if ( propertyEntries.isEmpty() ) { + return null; + } + return first( propertyEntries ); + } + + public boolean isNested() { + return propertyEntries.size() > 1; + } + + @Override + public String toString() { + + String result = ""; + if ( propertyEntries.isEmpty() ) { + if ( parameter != null ) { + result = String.format( "parameter \"%s %s\"", parameter.getType(), parameter.getName() ); + } + } + else if ( propertyEntries.size() == 1 ) { + String propertyEntry = propertyEntries.get( 0 ); + result = String.format( "property \"%s\"", propertyEntry ); + } + else { + result = String.format( + "property \"%s\"", + Strings.join( getElementNames(), "." ) + ); + } + return result; + } /** * Builds a {@link TargetReference} from an {@code @Mappping}. @@ -62,21 +123,15 @@ public static class Builder { private Method method; private FormattingMessager messager; private TypeFactory typeFactory; + private Set targetProperties; + private Type targetType; // mapping parameters - private boolean isReversed = false; - private boolean isIgnored = false; private String targetName = null; + private MappingOptions mapping; private AnnotationMirror annotationMirror = null; private AnnotationValue targetAnnotationValue = null; private AnnotationValue sourceAnnotationValue = null; - private Method templateMethod = null; - /** - * During {@link #getTargetEntries(Type, String[])} an error can occur. However, we are invoking - * that multiple times because the first entry can also be the name of the parameter. Therefore we keep - * the error message until the end when we can report it. - */ - private MappingErrorMessage errorMessage; public Builder messager(FormattingMessager messager) { this.messager = messager; @@ -84,11 +139,7 @@ public Builder messager(FormattingMessager messager) { } public Builder mapping(MappingOptions mapping) { - if ( mapping.getInheritContext() != null ) { - this.isReversed = mapping.getInheritContext().isReversed(); - this.templateMethod = mapping.getInheritContext().getTemplateMethod(); - } - this.isIgnored = mapping.isIgnored(); + this.mapping = mapping; this.targetName = mapping.getTargetName(); this.annotationMirror = mapping.getMirror(); this.targetAnnotationValue = mapping.getTargetAnnotationValue(); @@ -106,11 +157,22 @@ public Builder method(Method method) { return this; } + public Builder targetProperties(Set targetProperties) { + this.targetProperties = targetProperties; + return this; + } + + public Builder targetType(Type targetType) { + this.targetType = targetType; + return this; + } + public TargetReference build() { Objects.requireNonNull( method ); Objects.requireNonNull( typeFactory ); Objects.requireNonNull( messager ); + Objects.requireNonNull( targetType ); if ( targetName == null ) { return null; @@ -130,185 +192,27 @@ public TargetReference build() { String[] segments = targetNameTrimmed.split( "\\." ); Parameter parameter = method.getMappingTargetParameter(); - boolean foundEntryMatch; - Type resultType = typeBasedOnMethod( method.getResultType() ); - // there can be 4 situations // 1. Return type // 2. An inverse target reference where the source parameter name is used in the original mapping // 3. @MappingTarget, with // 4. or without parameter name. String[] targetPropertyNames = segments; - List entries = getTargetEntries( resultType, targetPropertyNames ); - foundEntryMatch = (entries.size() == targetPropertyNames.length); - if ( !foundEntryMatch && segments.length > 1 - && matchesSourceOrTargetParameter( segments[0], parameter, isReversed ) ) { - targetPropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - entries = getTargetEntries( resultType, targetPropertyNames ); - foundEntryMatch = (entries.size() == targetPropertyNames.length); - } - - if ( !foundEntryMatch && errorMessage != null && !isReversed ) { - // This is called only for reporting errors - errorMessage.report( ); - } - - // foundEntryMatch = isValid, errors are handled here, and the BeanMapping uses that to ignore - // the creation of mapping for invalid TargetReferences - return new TargetReference( parameter, entries, foundEntryMatch ); - } - - private List getTargetEntries(Type type, String[] entryNames) { - - // initialize - CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); - List targetEntries = new ArrayList<>(); - Type nextType = type; - - // iterate, establish for each entry the target write accessors. Other than setter is only allowed for - // last entry - for ( int i = 0; i < entryNames.length; i++ ) { - - Type mappingType = typeBasedOnMethod( nextType ); - Accessor targetReadAccessor = mappingType.getPropertyReadAccessors().get( entryNames[i] ); - Accessor targetWriteAccessor = mappingType.getPropertyWriteAccessors( cms ).get( entryNames[i] ); - boolean isLast = i == entryNames.length - 1; - boolean isNotLast = i < entryNames.length - 1; - if ( isWriteAccessorNotValidWhenNotLast( targetWriteAccessor, isNotLast ) - || isWriteAccessorNotValidWhenLast( targetWriteAccessor, targetReadAccessor, isIgnored, isLast ) ) { - // there should always be a write accessor (except for the last when the mapping is ignored and - // there is a read accessor) and there should be read accessor mandatory for all but the last - setErrorMessage( targetWriteAccessor, targetReadAccessor, entryNames, i, nextType ); - break; - } - - if ( isLast || ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || - targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) ) { - // only intermediate nested properties when they are a true setter or field accessor - // the last may be other readAccessor (setter / getter / adder). - - nextType = findNextType( nextType, targetWriteAccessor, targetReadAccessor ); - - // check if an entry alread exists, otherwise create - String[] fullName = Arrays.copyOfRange( entryNames, 0, i + 1 ); - BuilderType builderType; - PropertyEntry propertyEntry = null; - if ( method.isUpdateMethod() ) { - propertyEntry = PropertyEntry.forTargetReference( fullName, - targetReadAccessor, - targetWriteAccessor, - nextType, - null - ); - } - else { - BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); - builderType = typeFactory.builderTypeFor( nextType, builder ); - propertyEntry = PropertyEntry.forTargetReference( fullName, - targetReadAccessor, - targetWriteAccessor, - nextType, - builderType - ); - + if ( segments.length > 1 ) { + String firstTargetProperty = targetPropertyNames[0]; + // If the first target property is not within the defined target properties, then check if it matches + // the source or target parameter + if ( !targetProperties.contains( firstTargetProperty ) ) { + if ( matchesSourceOrTargetParameter( firstTargetProperty, parameter ) ) { + targetPropertyNames = Arrays.copyOfRange( segments, 1, segments.length ); } - targetEntries.add( propertyEntry ); } - } - return targetEntries; - } - /** - * Finds the next type based on the initial type. - * - * @param initial for which a next type should be found - * @param targetWriteAccessor the write accessor - * @param targetReadAccessor the read accessor - * @return the next type that should be used for finding a property entry - */ - private Type findNextType(Type initial, Accessor targetWriteAccessor, Accessor targetReadAccessor) { - Type nextType; - Accessor toUse = targetWriteAccessor != null ? targetWriteAccessor : targetReadAccessor; - if ( toUse.getAccessorType() == AccessorType.GETTER || toUse.getAccessorType() == AccessorType.FIELD ) { - nextType = typeFactory.getReturnType( - (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), - toUse - ); - } - else { - nextType = typeFactory.getSingleParameter( - (DeclaredType) typeBasedOnMethod( initial ).getTypeMirror(), - toUse - ).getType(); - } - return nextType; - } - - private void setErrorMessage(Accessor targetWriteAccessor, Accessor targetReadAccessor, String[] entryNames, - int index, Type nextType) { - if ( targetWriteAccessor == null && targetReadAccessor == null ) { - errorMessage = new NoPropertyErrorMessage( this, entryNames, index, nextType ); - } - else if ( targetWriteAccessor == null ) { - errorMessage = new NoWriteAccessorErrorMessage(this ); - } - else { - //TODO there is no read accessor. What should we do here? - errorMessage = new NoPropertyErrorMessage( this, entryNames, index, nextType ); - } - } - - /** - * When we are in an update method, i.e. source parameter with {@code @MappingTarget} then the type should - * be itself, otherwise, we always get the effective type. The reason is that when doing updates we always - * search for setters and getters within the updating type. - */ - private Type typeBasedOnMethod(Type type) { - if ( method.isUpdateMethod() ) { - return type; - } - else { - BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); - return typeFactory.effectiveResultTypeFor( type, builder ); - } - } + List entries = new ArrayList<>( Arrays.asList( targetPropertyNames ) ); - /** - * A write accessor is not valid if it is {@code null} and it is not last. i.e. for nested target mappings - * there must be a write accessor for all entries except the last one. - * - * @param accessor that needs to be checked - * @param isNotLast whether or not this is the last write accessor in the entry chain - * - * @return {@code true} if the accessor is not valid, {@code false} otherwise - */ - private static boolean isWriteAccessorNotValidWhenNotLast(Accessor accessor, boolean isNotLast) { - return accessor == null && isNotLast; - } - - /** - * For a last accessor to be valid, a read accessor should exist and the mapping should be ignored. All other - * cases represent an invalid write accessor. This method will evaluate to {@code true} if the following is - * {@code true}: - *
        - *
      • {@code writeAccessor} is {@code null}
      • - *
      • It is for the last entry
      • - *
      • A read accessor does not exist, or the mapping is not ignored
      • - *
      - * - * @param writeAccessor that needs to be checked - * @param readAccessor that is used - * @param isIgnored true when ignored - * @param isLast whether or not this is the last write accessor in the entry chain - * - * @return {@code true} if the write accessor is not valid, {@code false} otherwise. See description for more - * information - */ - private static boolean isWriteAccessorNotValidWhenLast(Accessor writeAccessor, Accessor readAccessor, - boolean isIgnored, boolean isLast) { - return writeAccessor == null && isLast && ( readAccessor == null || !isIgnored ); + return new TargetReference( parameter, entries ); } /** @@ -317,16 +221,14 @@ private static boolean isWriteAccessorNotValidWhenLast(Accessor writeAccessor, A * * @param segment that needs to be checked * @param targetParameter the target parameter if it exists - - * @param isInverse whether a inverse {@link TargetReference} is being built * * @return {@code true} if the segment matches the name of the {@code targetParameter} or the name of the * {@code inverseSourceParameter} when this is a inverse {@link TargetReference} is being built, {@code * false} otherwise */ - private boolean matchesSourceOrTargetParameter(String segment, Parameter targetParameter, boolean isInverse) { + private boolean matchesSourceOrTargetParameter(String segment, Parameter targetParameter) { boolean matchesTargetParameter = targetParameter != null && targetParameter.getName().equals( segment ); - return matchesTargetParameter || matchesSourceOnInverseSourceParameter( segment, isInverse ); + return matchesTargetParameter || matchesSourceOnInverseSourceParameter( segment ); } /** @@ -344,13 +246,16 @@ private boolean matchesSourceOrTargetParameter(String segment, Parameter targetP * a inverse is created. * * @param segment that needs to be checked* - * @param isInverse whether a inverse {@link TargetReference} is being built * * @return on match when inverse and segment matches the one and only source parameter */ - private boolean matchesSourceOnInverseSourceParameter( String segment, boolean isInverse ) { + private boolean matchesSourceOnInverseSourceParameter(String segment) { + boolean result = false; - if ( isInverse ) { + MappingOptions.InheritContext inheritContext = mapping.getInheritContext(); + if ( inheritContext != null && inheritContext.isReversed() ) { + + Method templateMethod = inheritContext.getTemplateMethod(); // there is only source parameter by definition when applying @InheritInverseConfiguration Parameter inverseSourceParameter = first( templateMethod.getSourceParameters() ); result = inverseSourceParameter.getName().equals( segment ); @@ -359,87 +264,19 @@ private boolean matchesSourceOnInverseSourceParameter( String segment, boolean i } } - private TargetReference(Parameter sourceParameter, List targetPropertyEntries, boolean isValid) { - super( sourceParameter, targetPropertyEntries, isValid ); - } - public TargetReference pop() { if ( getPropertyEntries().size() > 1 ) { - List newPropertyEntries = new ArrayList<>( getPropertyEntries().size() - 1 ); - for ( PropertyEntry propertyEntry : getPropertyEntries() ) { - PropertyEntry newPropertyEntry = propertyEntry.pop(); - if ( newPropertyEntry != null ) { - newPropertyEntries.add( newPropertyEntry ); - } - } - return new TargetReference( null, newPropertyEntries, isValid() ); + List newPathProperties = new ArrayList<>( this.pathProperties ); + newPathProperties.add( getPropertyEntries().get( 0 ) ); + return new TargetReference( + null, + getPropertyEntries().subList( 1, getPropertyEntries().size() ), + newPathProperties + ); } else { return null; } } - private abstract static class MappingErrorMessage { - private final Builder builder; - - private MappingErrorMessage(Builder builder) { - this.builder = builder; - } - - abstract void report(); - - protected void printErrorMessage(Message message, Object... args) { - Object[] errorArgs = new Object[args.length + 2]; - errorArgs[0] = builder.targetName; - errorArgs[1] = builder.method.getResultType(); - System.arraycopy( args, 0, errorArgs, 2, args.length ); - AnnotationMirror annotationMirror = builder.annotationMirror; - builder.messager.printMessage( builder.method.getExecutable(), - annotationMirror, - builder.sourceAnnotationValue, - message, - errorArgs - ); - } - } - - private static class NoWriteAccessorErrorMessage extends MappingErrorMessage { - - private NoWriteAccessorErrorMessage(Builder builder) { - super( builder ); - } - - @Override - public void report() { - printErrorMessage( Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE ); - } - } - - private static class NoPropertyErrorMessage extends MappingErrorMessage { - - private final String[] entryNames; - private final int index; - private final Type nextType; - - private NoPropertyErrorMessage(Builder builder, String[] entryNames, int index, - Type nextType) { - super( builder ); - this.entryNames = entryNames; - this.index = index; - this.nextType = nextType; - } - - @Override - public void report() { - - Set readAccessors = nextType.getPropertyReadAccessors().keySet(); - String mostSimilarProperty = Strings.getMostSimilarWord( entryNames[index], readAccessors ); - - List elements = new ArrayList<>( Arrays.asList( entryNames ).subList( 0, index ) ); - elements.add( mostSimilarProperty ); - - printErrorMessage( Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE, Strings.join( elements, "." ) ); - } - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index ed88e5107a..b826295f75 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -16,6 +16,7 @@ import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.util.Elements; import javax.lang.model.util.Types; @@ -50,6 +51,7 @@ public class MappingOptions extends DelegatingOptions { private final boolean isIgnored; private final Set dependsOn; + private final Element element; private final AnnotationValue sourceAnnotationValue; private final AnnotationValue targetAnnotationValue; private final MappingGem mapping; @@ -135,6 +137,7 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, MappingOptions options = new MappingOptions( mapping.target().getValue(), + method, mapping.target().getAnnotationValue(), source, mapping.source().getAnnotationValue(), @@ -169,6 +172,7 @@ public static MappingOptions forIgnore(String targetName) { null, null, null, + null, true, null, null, @@ -249,6 +253,7 @@ else if ( gem.nullValuePropertyMappingStrategy().hasValue() @SuppressWarnings("checkstyle:parameternumber") private MappingOptions(String targetName, + Element element, AnnotationValue targetAnnotationValue, String sourceName, AnnotationValue sourceAnnotationValue, @@ -266,6 +271,7 @@ private MappingOptions(String targetName, ) { super( next ); this.targetName = targetName; + this.element = element; this.targetAnnotationValue = targetAnnotationValue; this.sourceName = sourceName; this.sourceAnnotationValue = sourceAnnotationValue; @@ -377,6 +383,10 @@ public AnnotationMirror getMirror() { return Optional.ofNullable( mapping ).map( MappingGem::mirror ).orElse( null ); } + public Element getElement() { + return element; + } + public AnnotationValue getDependsOnAnnotationValue() { return Optional.ofNullable( mapping ) .map( MappingGem::dependsOn ) @@ -434,6 +444,7 @@ public MappingOptions copyForInverseInheritance(SourceMethod templateMethod, MappingOptions mappingOptions = new MappingOptions( sourceName != null ? sourceName : targetName, + templateMethod.getExecutable(), targetAnnotationValue, sourceName != null ? targetName : null, sourceAnnotationValue, @@ -462,6 +473,7 @@ public MappingOptions copyForForwardInheritance(SourceMethod templateMethod, BeanMappingOptions beanMappingOptions ) { MappingOptions mappingOptions = new MappingOptions( targetName, + templateMethod.getExecutable(), targetAnnotationValue, sourceName, sourceAnnotationValue, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index bc7374d391..a9f9eff4a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -167,6 +167,7 @@ public void note( int level, Message msg, Object... args ) { } } + @Override public boolean isErroneous() { return isErroneous; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 197d9fa63c..7746dd6778 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -368,10 +368,10 @@ else if ( method.isStreamMapping() ) { .returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builder ) ) .build(); + // We can consider that the bean mapping method can always be constructed. If there is a problem + // it would have been reported in its build + hasFactoryMethod = true; if ( beanMappingMethod != null ) { - // We can consider that the bean mapping method can always be constructed. If there is a problem - // it would have been reported in its build - hasFactoryMethod = true; mappingMethods.add( beanMappingMethod ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java index 2e4d287d4b..6f3b1dc7a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/FormattingMessager.java @@ -75,4 +75,6 @@ void printMessage(Element e, * @param args the arguments */ void note(int level, Message log, Object... args); + + boolean isErroneous(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index df47f5bba8..e4b199adfb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -23,7 +23,9 @@ public enum Message { BEANMAPPING_NOT_ASSIGNABLE( "%s not assignable to: %s." ), BEANMAPPING_ABSTRACT( "The result type %s may not be an abstract class nor interface." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE( "Unknown property \"%s\" in result type %s. Did you mean \"%s\"?" ), + BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE( "Unknown property \"%s\" in type %s for target name \"%s\". Did you mean \"%s\"?" ), BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE( "Property \"%s\" has no write accessor in %s." ), + BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_TYPE( "Property \"%s\" has no write accessor in %s for target name \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_SOURCES( "Several possible source properties for target property \"%s\"." ), BEANMAPPING_SEVERAL_POSSIBLE_TARGET_ACCESSORS( "Found several matching getters for property \"%s\"." ), BEANMAPPING_UNMAPPED_TARGETS_WARNING( "Unmapped target %s.", Diagnostic.Kind.WARNING ), diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index bc90a7c3c3..2b65030625 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -161,5 +161,9 @@ public Diagnostic.Kind getLastKindPrinted() { return lastKindPrinted; } + @Override + public boolean isErroneous() { + return false; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index f4142fe641..bc3e59922f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -32,14 +32,14 @@ public class Issue1153Test { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - message = "Property \"nestedTarget.readOnly\" has no write accessor in " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target."), + message = "Property \"readOnly\" has no write accessor in org.mapstruct.ap.test.bugs._1153" + + ".ErroneousIssue1153Mapper.Target.NestedTarget for target name \"nestedTarget.readOnly\"."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, - message = "Unknown property \"nestedTarget2.writable2\" in result type " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target. " + - "Did you mean \"nestedTarget2.writable\"?") + message = "Unknown property \"writable2\" in type org.mapstruct.ap.test.bugs._1153" + + ".ErroneousIssue1153Mapper.Target.NestedTarget for target name \"nestedTarget2.writable2\". Did " + + "you mean \"nestedTarget2.writable\"?") }) @Test public void shouldReportErrorsCorrectly() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index 9908ea8e4a..94b2fa16a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -66,13 +66,21 @@ public void testNameSuggestion() { @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - message = "Unknown property \"garage.colour.rgb\" in result type org.mapstruct.ap.test.namesuggestion" + - ".Person. Did you mean \"garage.color\"?"), + message = "Unknown property \"colour\" in type org.mapstruct.ap.test.namesuggestion.Garage for target" + + " name \"garage.colour.rgb\". Did you mean \"garage.color\"?"), + @Diagnostic(type = PersonGarageWrongTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 20, + messageRegExp = "Unmapped target properties: \"fullName, fullAge\"\\."), @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - message = "Unknown property \"garage.colour\" in result type org.mapstruct.ap.test.namesuggestion" + - ".Person. Did you mean \"garage.color\"?") + message = "Unknown property \"colour\" in type org.mapstruct.ap.test.namesuggestion.Garage for" + + " target name \"garage.colour\". Did you mean \"garage.color\"?"), + @Diagnostic(type = PersonGarageWrongTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 23, + messageRegExp = "Unmapped target properties: \"fullName, fullAge\"\\."), } ) public void testGarageTargetSuggestion() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 12ba5f111c..b508787cc7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -172,10 +172,7 @@ public void shouldFailOnSuperBounds2() { }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, message = "org.mapstruct.ap.test.selection.generics.WildCardSuperWrapper does not have an accessible parameterless constructor."), - @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, message = + line = 17, message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.NoProperties " + "foo.wrapped\" to" + " \"org.mapstruct.ap.test.selection.generics.TypeA " diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java index 731b743b82..210cc3692a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ErroneousSourceTargetMapper6.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.selection.generics; import org.mapstruct.Mapper; +import org.mapstruct.ObjectFactory; import org.mapstruct.factory.Mappers; @Mapper( uses = GenericTypeMapper.class ) @@ -14,4 +15,11 @@ public interface ErroneousSourceTargetMapper6 { ErroneousSourceTargetMapper6 INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper6.class ); ErroneousTarget6 sourceToTarget(ErroneousSource6 source); + + // We are testing that we can't create the nested + // not whether or not we can instantiate the WildCardSuperWrapper + @ObjectFactory + default WildCardSuperWrapper createWildCardSuperWrapper() { + return new WildCardSuperWrapper<>( null ); + } } From 3bffe9698333d5bdd364f28fe3c805f5664554f9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Apr 2020 20:19:43 +0200 Subject: [PATCH 0455/1006] #1159: Do not fail loading AnnotationProcessorContext if loading AstModifyingAnnotationProcessor fails --- .../itest/tests/MavenIntegrationTest.java | 7 ++ .../generator/pom.xml | 50 ++++++++++++ .../AstModifyingProcessorSaysYes.java | 21 +++++ .../FaultyAstModifyingProcessor.java | 25 ++++++ .../FaultyStaticAstModifyingProcessor.java | 27 +++++++ ...uct.ap.spi.AstModifyingAnnotationProcessor | 7 ++ .../pom.xml | 27 +++++++ .../usage/pom.xml | 52 +++++++++++++ .../usage/Order.java | 22 ++++++ .../usage/OrderDto.java | 22 ++++++ .../usage/OrderMapper.java | 20 +++++ .../usage/FaultyAstModifyingTestTest.java | 27 +++++++ .../util/AnnotationProcessorContext.java | 77 ++++++++++++++++++- ...FaultyAstModifyingAnnotationProcessor.java | 25 ++++++ .../ap/test/bugs/_1159/Issue1159Mapper.java | 52 +++++++++++++ .../ap/test/bugs/_1159/Issue1159Test.java | 60 +++++++++++++++ 16 files changed, 517 insertions(+), 4 deletions(-) create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/AstModifyingProcessorSaysYes.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyAstModifyingProcessor.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyStaticAstModifyingProcessor.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/pom.xml create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/Order.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderDto.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderMapper.java create mode 100644 integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/FaultyAstModifyingAnnotationProcessor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 13cd774754..0789e3051d 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -156,4 +156,11 @@ void usesTypeGenerationTest() { void usesTypeGenerationTestEclipse() { } + /** + * Tests usage of MapStruct with faulty provider of AstModifyingAnnotationProcessor. + */ + @ProcessorTest(baseDir = "faultyAstModifyingAnnotationProcessorTest") + void faultyAstModifyingProcessor() { + } + } diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml new file mode 100644 index 0000000000..08390085dd --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + + org.mapstruct.itest + itest-faultyAstModifyingProcessor-aggregator + 1.0.0 + ../pom.xml + + + itest-faultyAstModifyingProcessor-generator + jar + + + + org.mapstruct + mapstruct-processor + ${mapstruct.version} + provided + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -proc:none + + + + + + + diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/AstModifyingProcessorSaysYes.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/AstModifyingProcessorSaysYes.java new file mode 100644 index 0000000000..e4a5fe5ead --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/AstModifyingProcessorSaysYes.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * @author Filip Hrisafov + */ +public class AstModifyingProcessorSaysYes implements AstModifyingAnnotationProcessor { + + @Override + public boolean isTypeComplete(TypeMirror type) { + return true; + } +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyAstModifyingProcessor.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyAstModifyingProcessor.java new file mode 100644 index 0000000000..ba1be9b2cc --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyAstModifyingProcessor.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * @author Filip Hrisafov + */ +public class FaultyAstModifyingProcessor implements AstModifyingAnnotationProcessor { + + public FaultyAstModifyingProcessor() { + throw new RuntimeException( "Failed to create processor" ); + } + + @Override + public boolean isTypeComplete(TypeMirror type) { + return true; + } +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyStaticAstModifyingProcessor.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyStaticAstModifyingProcessor.java new file mode 100644 index 0000000000..5f16165014 --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/FaultyStaticAstModifyingProcessor.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * @author Filip Hrisafov + */ +public class FaultyStaticAstModifyingProcessor implements AstModifyingAnnotationProcessor { + + static { + if ( true ) { + throw new RuntimeException( "Failed to initialize class" ); + } + } + + @Override + public boolean isTypeComplete(TypeMirror type) { + return true; + } +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor new file mode 100644 index 0000000000..3bc4f6138c --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/src/main/resources/META-INF/services/org.mapstruct.ap.spi.AstModifyingAnnotationProcessor @@ -0,0 +1,7 @@ +# Copyright MapStruct Authors. +# +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 +org.mapstruct.itest.faultyAstModifyingProcessor.UnknownAstModifyingProcessor +org.mapstruct.itest.faultyAstModifyingProcessor.AstModifyingProcessorSaysYes +org.mapstruct.itest.faultyAstModifyingProcessor.FaultyAstModifyingProcessor +org.mapstruct.itest.faultyAstModifyingProcessor.FaultyStaticAstModifyingProcessor diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/pom.xml new file mode 100644 index 0000000000..dae561252e --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/pom.xml @@ -0,0 +1,27 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + org.mapstruct.itest + itest-faultyAstModifyingProcessor-aggregator + pom + + + generator + usage + + diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml new file mode 100644 index 0000000000..cc0d0e4f98 --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + + org.mapstruct.itest + itest-faultyAstModifyingProcessor-aggregator + 1.0.0 + ../pom.xml + + + itest-faultyAstModifyingProcessor-usage + jar + + + + junit + junit + 4.12 + test + + + org.mapstruct.itest + itest-faultyAstModifyingProcessor-generator + 1.0.0 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + -XprintProcessorInfo + -XprintRounds + + -proc:none + + + + + diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/Order.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/Order.java new file mode 100644 index 0000000000..1d7cd6380b --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/Order.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor.usage; + +/** + * @author Filip Hrisafov + */ +public class Order { + + private String item; + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderDto.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderDto.java new file mode 100644 index 0000000000..afc64606b1 --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor.usage; + +/** + * @author Filip Hrisafov + */ +public class OrderDto { + + private String item; + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderMapper.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderMapper.java new file mode 100644 index 0000000000..75e52eb474 --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/main/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/OrderMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor.usage; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OrderMapper { + + OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); + + OrderDto orderToDto(Order order); +} diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java new file mode 100644 index 0000000000..06bfa3c533 --- /dev/null +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.faultyAstModifyingProcessor.usage; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration test for using MapStruct with a faulty AstModifyingProcessor (i.e. when the processor cannot be loaded) + * + * @author Filip Hrisafov + */ +public class FaultyAstModifyingTestTest { + + @Test + public void testMapping() { + Order order = new Order(); + order.setItem( "my item" ); + + OrderDto dto = OrderMapper.INSTANCE.orderToDto( order ); + assertThat( dto.getItem() ).isEqualTo( "my item" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 2b6f353d07..8fdc6201e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -5,7 +5,10 @@ */ package org.mapstruct.ap.internal.util; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.ServiceLoader; @@ -45,7 +48,7 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messager messager, boolean verbose) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( - findAstModifyingAnnotationProcessors() ); + findAstModifyingAnnotationProcessors( messager ) ); this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; @@ -105,20 +108,86 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! this.initialized = true; } - private static List findAstModifyingAnnotationProcessors() { + private static List findAstModifyingAnnotationProcessors(Messager messager) { List processors = new ArrayList<>(); ServiceLoader loader = ServiceLoader.load( AstModifyingAnnotationProcessor.class, AnnotationProcessorContext.class.getClassLoader() ); - for ( AstModifyingAnnotationProcessor astModifyingAnnotationProcessor : loader ) { - processors.add( astModifyingAnnotationProcessor ); + // Lombok packages an AstModifyingAnnotationProcessor as part of their jar + // this leads to problems within Eclipse when lombok is used as an agent + // Therefore we are wrapping this into an iterator that can handle exceptions by ignoring + // the faulty processor + Iterator loaderIterator = new FaultyDelegatingIterator( + messager, + loader.iterator() + ); + + while ( loaderIterator.hasNext() ) { + AstModifyingAnnotationProcessor processor = loaderIterator.next(); + if ( processor != null ) { + processors.add( processor ); + } } return processors; } + private static class FaultyDelegatingIterator implements Iterator { + + private final Messager messager; + private final Iterator delegate; + + private FaultyDelegatingIterator(Messager messager, + Iterator delegate) { + this.messager = messager; + this.delegate = delegate; + } + + @Override + public boolean hasNext() { + // Check the delegate maximum of 5 times + // before returning false + int failures = 5; + while ( failures > 0 ) { + try { + return delegate.hasNext(); + } + catch ( Throwable t ) { + failures--; + logFailure( t ); + } + } + + return false; + } + + @Override + public AstModifyingAnnotationProcessor next() { + try { + return delegate.next(); + } + catch ( Throwable t ) { + logFailure( t ); + return null; + } + } + + private void logFailure(Throwable t) { + StringWriter sw = new StringWriter(); + t.printStackTrace( new PrintWriter( sw ) ); + + String reportableStacktrace = sw.toString().replace( System.lineSeparator(), " " ); + + messager.printMessage( + Diagnostic.Kind.WARNING, + "Failed to read AstModifyingAnnotationProcessor. Reading next processor. Reason: " + + reportableStacktrace + ); + } + } + @Override public Elements getElementUtils() { return elementUtils; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/FaultyAstModifyingAnnotationProcessor.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/FaultyAstModifyingAnnotationProcessor.java new file mode 100644 index 0000000000..99d88e9883 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/FaultyAstModifyingAnnotationProcessor.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1159; + +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; + +/** + * @author Filip Hrisafov + */ +public class FaultyAstModifyingAnnotationProcessor implements AstModifyingAnnotationProcessor { + + public FaultyAstModifyingAnnotationProcessor() { + throw new RuntimeException( "Faulty AstModifyingAnnotationProcessor should not be instantiated" ); + } + + @Override + public boolean isTypeComplete(TypeMirror type) { + return false; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Mapper.java new file mode 100644 index 0000000000..ab1441c142 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Mapper.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1159; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue1159Mapper { + + Issue1159Mapper INSTANCE = Mappers.getMapper( Issue1159Mapper.class ); + + CarManualDto translateManual(CarManual manual); + + /** + * @author Filip Hrisafov + */ + class CarManual { + + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + } + + /** + * @author Filip Hrisafov + */ + class CarManualDto { + + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java new file mode 100644 index 0000000000..b93cd6d069 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java @@ -0,0 +1,60 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1159; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("1159") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue1159Mapper.class, +}) +@WithServiceImplementation( + provides = AstModifyingAnnotationProcessor.class, + value = FaultyAstModifyingAnnotationProcessor.class +) +public class Issue1159Test { + + @Test + // The warning is not present in the Eclipse compilation for some reason + @DisabledOnCompiler({ + Compiler.ECLIPSE, + Compiler.ECLIPSE11 + }) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + messageRegExp = "Failed to read AstModifyingAnnotationProcessor. Reading next processor. Reason:.*" + + "Faulty AstModifyingAnnotationProcessor should not be instantiated" + ) + }) + public void shouldIgnoreFaultyAstModifyingProcessor() { + + Issue1159Mapper.CarManual manual = new Issue1159Mapper.CarManual(); + manual.setContent( "test" ); + + Issue1159Mapper.CarManualDto manualDto = Issue1159Mapper.INSTANCE.translateManual( manual ); + + assertThat( manualDto ).isNotNull(); + assertThat( manualDto.getContent() ).isEqualTo( "test" ); + } +} From 7c62aec28195950ac6feafd4b2345a8c06ecf6c8 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 25 Apr 2020 17:01:22 +0200 Subject: [PATCH 0456/1006] #2077 nullpointer due to no-getter source (#2078) --- .../ap/internal/model/BeanMappingMethod.java | 49 ++++++++++--------- .../bugs/_2077/Issue2077ErroneousMapper.java | 37 ++++++++++++++ .../ap/test/bugs/_2077/Issue2077Test.java | 39 +++++++++++++++ 3 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 5cb2192aae..53a271858b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -721,30 +721,33 @@ else if ( mapping.getJavaExpression() != null ) { sourceRef = getSourceRef( method.getSourceParameters().get( 0 ), targetPropertyName ); } - if ( sourceRef.isValid() ) { + if ( sourceRef != null ) { + // sourceRef == null is not considered an error here + if ( sourceRef.isValid() ) { - // targetProperty == null can occur: we arrived here because we want as many errors - // as possible before we stop analysing - propertyMapping = new PropertyMappingBuilder() - .mappingContext( ctx ) - .sourceMethod( method ) - .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) - .sourcePropertyName( mapping.getSourceName() ) - .sourceReference( sourceRef ) - .selectionParameters( mapping.getSelectionParameters() ) - .formattingParameters( mapping.getFormattingParameters() ) - .existingVariableNames( existingVariableNames ) - .dependsOn( mapping.getDependsOn() ) - .defaultValue( mapping.getDefaultValue() ) - .defaultJavaExpression( mapping.getDefaultJavaExpression() ) - .mirror( mapping.getMirror() ) - .options( mapping ) - .build(); - handledTargets.add( targetPropertyName ); - unprocessedSourceParameters.remove( sourceRef.getParameter() ); - } - else { - errorOccured = true; + // targetProperty == null can occur: we arrived here because we want as many errors + // as possible before we stop analysing + propertyMapping = new PropertyMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) + .sourcePropertyName( mapping.getSourceName() ) + .sourceReference( sourceRef ) + .selectionParameters( mapping.getSelectionParameters() ) + .formattingParameters( mapping.getFormattingParameters() ) + .existingVariableNames( existingVariableNames ) + .dependsOn( mapping.getDependsOn() ) + .defaultValue( mapping.getDefaultValue() ) + .defaultJavaExpression( mapping.getDefaultJavaExpression() ) + .mirror( mapping.getMirror() ) + .options( mapping ) + .build(); + handledTargets.add( targetPropertyName ); + unprocessedSourceParameters.remove( sourceRef.getParameter() ); + } + else { + errorOccured = true; + } } } // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java new file mode 100644 index 0000000000..ecbff63802 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2077; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( unmappedTargetPolicy = ReportingPolicy.ERROR ) +public interface Issue2077ErroneousMapper { + + Issue2077ErroneousMapper INSTANCE = Mappers.getMapper( Issue2077ErroneousMapper.class ); + + @Mapping(target = "s1", defaultValue = "xyz" ) + Target map(String source); + + class Target { + + private String s1; + + public String getS1() { + return s1; + } + + public void setS1(String s1) { + this.s1 = s1; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java new file mode 100644 index 0000000000..d8c3a1e5d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2077; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static javax.tools.Diagnostic.Kind.ERROR; + +/** + * @author Sjaak Derksen + */ +@IssueKey("2077") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2077Test { + + @Test + @WithClasses(Issue2077ErroneousMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue2077ErroneousMapper.class, + kind = ERROR, + line = 22, + message = "Unmapped target property: \"s1\".") + } + ) + public void shouldNotCompile() { + } +} From d6ff5204d743795816fa4a343b2ebff8c2b7c15c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 13 Apr 2020 20:14:11 +0200 Subject: [PATCH 0457/1006] Accessor#getSimpleName should return a String --- .../ap/internal/model/NestedPropertyMappingMethod.java | 2 +- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 6 +++--- .../java/org/mapstruct/ap/internal/model/common/Type.java | 2 +- .../java/org/mapstruct/ap/internal/util/ValueProvider.java | 2 +- .../ap/internal/util/accessor/AbstractAccessor.java | 5 ++--- .../org/mapstruct/ap/internal/util/accessor/Accessor.java | 2 +- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index f698f83459..f5616d1278 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -150,7 +150,7 @@ public SafePropertyEntry(PropertyEntry entry, String safeName) { this.safeName = safeName; this.readAccessorName = ValueProvider.of( entry.getReadAccessor() ).getValue(); if ( entry.getPresenceChecker() != null ) { - this.presenceCheckerName = entry.getPresenceChecker().getSimpleName().toString(); + this.presenceCheckerName = entry.getPresenceChecker().getSimpleName(); } else { this.presenceCheckerName = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 24facce722..1558fc7f8a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -273,7 +273,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get return new PropertyMapping( targetPropertyName, rightHandSide.getSourceParameterName(), - targetWriteAccessor.getSimpleName().toString(), + targetWriteAccessor.getSimpleName(), ValueProvider.of( targetReadAccessor ), targetType, assignment, @@ -869,7 +869,7 @@ else if ( errorMessageDetails == null ) { return new PropertyMapping( targetPropertyName, - targetWriteAccessor.getSimpleName().toString(), + targetWriteAccessor.getSimpleName(), ValueProvider.of( targetReadAccessor ), targetType, assignment, @@ -934,7 +934,7 @@ public PropertyMapping build() { return new PropertyMapping( targetPropertyName, - targetWriteAccessor.getSimpleName().toString(), + targetWriteAccessor.getSimpleName(), ValueProvider.of( targetReadAccessor ), targetType, assignment, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6f3a7b79c3..52a076270b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -488,7 +488,7 @@ public Map getPropertyReadAccessors() { if ( modifiableGetters.containsKey( propertyName ) ) { // In the DefaultAccessorNamingStrategy, this can only be the case for Booleans: isFoo() and // getFoo(); The latter is preferred. - if ( !getter.getSimpleName().toString().startsWith( "is" ) ) { + if ( !getter.getSimpleName().startsWith( "is" ) ) { modifiableGetters.put( propertyName, getter ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java index 31a3a9c6cd..0f64c2b375 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java @@ -45,7 +45,7 @@ public static ValueProvider of(Accessor accessor) { if ( accessor == null ) { return null; } - String value = accessor.getSimpleName().toString(); + String value = accessor.getSimpleName(); if ( accessor.getAccessorType() != AccessorType.FIELD ) { value += "()"; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java index 5a16e45fa8..04c4c99992 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java @@ -9,7 +9,6 @@ import javax.lang.model.element.Element; import javax.lang.model.element.Modifier; -import javax.lang.model.element.Name; /** * This is an abstract implementation of an {@link Accessor} that provides the common implementation. @@ -25,8 +24,8 @@ abstract class AbstractAccessor implements Accessor { } @Override - public Name getSimpleName() { - return element.getSimpleName(); + public String getSimpleName() { + return element.getSimpleName().toString(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index f9dd435d5f..917d1a216b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -33,7 +33,7 @@ public interface Accessor { /** * @return the simple name of the accessor */ - Name getSimpleName(); + String getSimpleName(); /** * @return the set of modifiers that the accessor has From 2b2299a730f9b8f6ee48cef3b8c84d7e7604039c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 26 Apr 2020 12:08:57 +0200 Subject: [PATCH 0458/1006] #73 Add support for using constructor arguments when instantiating mapping targets By default the constructor argument names are used to extract the target properties. If a constructor is annotated with an annotation named `@ConstructorProperties` (from any package) then it would be used to extract the target properties. If a mapping target has a parameterless empty constructor it would be used to instantiate the target. When there are multiple constructors then an annotation named `@Default` (from any package) can be used to mark a constructor that should be used by default when instantiating the target. Supports mapping into Java 14 Records and Kotlin data classes out of the box --- .../resources/build-config/checkstyle.xml | 3 - .../chapter-3-defining-a-mapper.asciidoc | 77 ++++ .../chapter-5-data-type-conversions.asciidoc | 6 + .../itest/tests/MavenIntegrationTest.java | 8 + .../ProcessorInvocationInterceptor.java | 3 + .../testutil/extension/ProcessorTest.java | 3 + .../extension/ProcessorTestContext.java | 9 +- ...TestTemplateInvocationContextProvider.java | 3 +- .../src/test/resources/kotlinDataTest/pom.xml | 102 +++++ .../itest/kotlin/data/CustomerEntity.java | 31 ++ .../itest/kotlin/data/CustomerMapper.java | 27 ++ .../itest/kotlin/data/CustomerDto.kt | 10 + .../itest/kotlin/data/KotlinDataTest.java | 38 ++ .../itest/records/CustomerMapper.java | 4 + .../mapstruct/itest/records/RecordsTest.java | 13 + .../ap/internal/model/BeanMappingMethod.java | 387 ++++++++++++++++-- .../model/CollectionAssignmentBuilder.java | 14 +- .../ap/internal/model/MethodReference.java | 43 ++ .../model/NormalTypeMappingMethod.java | 3 + .../model/ObjectFactoryMethodResolver.java | 37 +- .../ap/internal/model/PropertyMapping.java | 39 +- .../ap/internal/model/common/Parameter.java | 23 +- .../model/common/ParameterBinding.java | 11 + .../ap/internal/model/common/Type.java | 41 +- .../ap/internal/model/common/TypeFactory.java | 13 +- .../ap/internal/util/AccessorNamingUtils.java | 5 - .../mapstruct/ap/internal/util/Filters.java | 25 +- .../mapstruct/ap/internal/util/Message.java | 4 +- .../ap/internal/util/ValueProvider.java | 3 +- .../ap/internal/util/accessor/Accessor.java | 3 +- .../internal/util/accessor/AccessorType.java | 5 + ...ccessor.java => FieldElementAccessor.java} | 4 +- .../accessor/ParameterElementAccessor.java | 46 +++ .../ap/internal/model/BeanMappingMethod.ftl | 57 ++- .../ap/internal/model/MethodReference.ftl | 2 + .../model/assignment/AdderWrapper.ftl | 2 +- .../model/assignment/ArrayCopyWrapper.ftl | 2 +- .../model/assignment/SetterWrapper.ftl | 2 +- .../SetterWrapperForCollectionsAndMaps.ftl | 2 +- ...pperForCollectionsAndMapsWithNullCheck.ftl | 6 +- .../ap/internal/model/macro/CommonMacros.ftl | 2 +- .../ap/test/bugs/_1242/Issue1242Test.java | 7 +- .../ap/test/bugs/_1283/Issue1283Test.java | 6 +- .../mapstruct/ap/test/bugs/_1283/Source.java | 2 +- .../constructor/ConstructorProperties.java | 23 ++ .../ap/test/constructor/Default.java | 21 + .../mapstruct/ap/test/constructor/Person.java | 55 +++ .../ap/test/constructor/PersonDto.java | 69 ++++ .../PersonWithConstructorProperties.java | 58 +++ .../SimpleConstructorPropertiesMapper.java | 30 ++ .../SimpleConstructorPropertiesTest.java | 90 ++++ ...PersonWithDefaultAnnotatedConstructor.java | 35 ++ ...mpleDefaultAnnotatedConstructorMapper.java | 29 ++ ...SimpleDefaultAnnotatedConstructorTest.java | 80 ++++ .../ErroneousAmbiguousConstructorsMapper.java | 33 ++ .../ErroneousConstructorPropertiesMapper.java | 31 ++ .../erroneous/ErroneousConstructorTest.java | 59 +++ .../ConstructorMixedWithSettersMapper.java | 21 + .../ConstructorMixedWithSettersTest.java | 48 +++ .../test/constructor/mixed/PersonMixed.java | 67 +++ .../nestedsource/ArtistToChartEntry.java | 54 +++ .../ArtistToChartEntryComposedReverse.java | 49 +++ .../ArtistToChartEntryConfig.java | 28 ++ .../ArtistToChartEntryReverse.java | 38 ++ .../ArtistToChartEntryWithConfigReverse.java | 37 ++ .../ArtistToChartEntryWithFactoryReverse.java | 39 ++ .../ArtistToChartEntryWithIgnoresReverse.java | 41 ++ .../ArtistToChartEntryWithMappingReverse.java | 59 +++ ...NestedSourcePropertiesConstructorTest.java | 132 ++++++ ...NestedSourcePropertiesConstructorTest.java | 222 ++++++++++ .../_target/AdderUsageObserver.java | 26 ++ .../nestedsource/_target/BaseChartEntry.java | 34 ++ .../nestedsource/_target/ChartEntry.java | 54 +++ .../_target/ChartEntryComposed.java | 58 +++ .../nestedsource/_target/ChartEntryLabel.java | 34 ++ .../_target/ChartEntryWithBase.java | 36 ++ .../_target/ChartEntryWithMapping.java | 54 +++ .../nestedsource/_target/ChartPositions.java | 25 ++ .../nestedsource/source/Artist.java | 29 ++ .../nestedsource/source/Chart.java | 35 ++ .../nestedsource/source/Label.java | 29 ++ .../constructor/nestedsource/source/Song.java | 37 ++ .../nestedsource/source/Studio.java | 29 ++ .../nestedtarget/ChartEntryToArtist.java | 59 +++ ...estedProductPropertiesConstructorTest.java | 98 +++++ .../simple/SimpleConstructorMapper.java | 31 ++ .../simple/SimpleConstructorTest.java | 89 ++++ .../ap/test/constructor/unmapped/Order.java | 30 ++ .../test/constructor/unmapped/OrderDto.java | 22 + .../unmapped/UnmappedConstructorMapper.java | 20 + .../unmapped/UnmappedConstructorTest.java | 45 ++ .../AmbiguousAnnotatedFactoryTest.java | 7 +- .../ambiguousfactorymethod/FactoryTest.java | 7 +- .../ArtistToChartEntryErroneous.java | 17 +- .../NestedSourcePropertiesTest.java | 19 +- .../ap/test/selection/resulttype/Citrus.java | 21 + ...ultTypeNoAccessibleConstructorMapper.java} | 9 +- .../resulttype/InheritanceSelectionTest.java | 73 +++- ...uctorConstructingFruitInterfaceMapper.java | 23 ++ ...ithConstructorConstructingFruitMapper.java | 24 ++ .../ErroneousOrganizationMapper2.java | 7 + .../test/updatemethods/UpdateMethodsTest.java | 4 +- .../testutil/runner/CompilingStatement.java | 6 +- .../nestedsource/ArtistToChartEntryImpl.java | 170 ++++++++ .../nestedtarget/ChartEntryToArtistImpl.java | 236 +++++++++++ 105 files changed, 3905 insertions(+), 173 deletions(-) create mode 100644 integrationtest/src/test/resources/kotlinDataTest/pom.xml create mode 100644 integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerEntity.java create mode 100644 integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerMapper.java create mode 100644 integrationtest/src/test/resources/kotlinDataTest/src/main/kotlin/org/mapstruct/itest/kotlin/data/CustomerDto.kt create mode 100644 integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java rename processor/src/main/java/org/mapstruct/ap/internal/util/accessor/{VariableElementAccessor.java => FieldElementAccessor.java} (83%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/ConstructorProperties.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/Default.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/PersonDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/PersonWithConstructorProperties.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/PersonWithDefaultAnnotatedConstructor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousAmbiguousConstructorsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorPropertiesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/PersonMixed.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntry.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryComposedReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithConfigReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithFactoryReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithIgnoresReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithMappingReverse.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/AdderUsageObserver.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/BaseChartEntry.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntry.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryComposed.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryLabel.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithBase.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartPositions.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Artist.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Chart.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Label.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Song.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Studio.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtist.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/Order.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/OrderDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Citrus.java rename processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/{ErroneousResultTypeNoEmptyConstructorMapper.java => ErroneousResultTypeNoAccessibleConstructorMapper.java} (71%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitInterfaceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitMapper.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 945015d5cd..a4591c39de 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -122,9 +122,6 @@ - - - diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 5255ac6f1b..ad5d8111f7 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -528,3 +528,80 @@ Otherwise, you would need to write a custom `BuilderProvider` ==== In case you want to disable using builders then you can use the `NoOpBuilderProvider` by creating a `org.mapstruct.ap.spi.BuilderProvider` file in the `META-INF/services` directory with `org.mapstruct.ap.spi.NoOpBuilderProvider` as it's content. ==== + +[[mapping-with-constructors]] +=== Using Constructors + +MapStruct supports using constructors for mapping target types. +When doing a mapping MapStruct checks if there is a builder for the type being mapped. +If there is no builder, then MapStruct looks for a single accessible constructor. +When there are multiple constructors then the following is done to pick the one which should be used: + +* If a parameterless constructor exists then it would be used to construct the object, and the other constructors will be ignored +* If there are multiple constructors then the one annotated with annotation named `@Default` (from any package) will be used + +When using a constructor then the names of the parameters of the constructor will be used and matched to the target properties. +When the constructor has an annotation named `@ConstructorProperties` (from any package) then this annotation will be used to get the names of the parameters. + +[NOTE] +==== +When an object factory method or a method annotated with `@ObjectFactory` exists, it will take precedence over any constructor defined in the target. +The target object constructor will not be used in that case. +==== + + +.Person with constructor parameters +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Person { + + private final String name; + private final String surname; + + public Person(String name, String surname) { + this.name = name; + this.surname = surname; + } +} +---- +==== + +.Person With Constructor Mapper definition +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public interface PersonMapper { + + Person map(PersonDto dto); +} +---- +==== + +.Generated mapper with constructor +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class PersonMapperImpl implements PersonMapper { + + public Person map(PersonDto dto) { + if (dto == null) { + return null; + } + + String name; + String surname; + name = dto.getName(); + surname = dto.getSurname(); + + Person person = new Person( name, surname ); + + return person; + } +} +---- +==== diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 7a22aad559..725c69bad0 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -174,6 +174,12 @@ During the generation of automatic sub-mapping methods <> Follow issue https://github.com/mapstruct/mapstruct/issues/1086[#1086] for more information. ==== +[NOTE] +==== +Constructor properties of the target object are also considered as target properties. +You can read more about that in <> +==== + [[controlling-nested-bean-mappings]] === Controlling nested bean mappings diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 0789e3051d..76a72b4b7f 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -107,6 +107,14 @@ void protobufBuilderTest() { void recordsTest() { } + @ProcessorTest(baseDir = "kotlinDataTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }, forkJvm = true) + // We have to fork the jvm because there is an NPE in com.intellij.openapi.util.SystemInfo.getRtVersion + // and the kotlin-maven-plugin uses that. See also https://youtrack.jetbrains.com/issue/IDEA-238907 + void kotlinDataTest() { + } + @ProcessorTest(baseDir = "simpleTest") void simpleTest() { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index f6f9186ba6..839bf86f18 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -71,6 +71,9 @@ private void doExecute(ExtensionContext extensionContext) throws Exception { } else { verifier = new Verifier( destination.getCanonicalPath() ); + if ( processorTestContext.isForkJvm() ) { + verifier.setForkJvm( true ); + } } List goals = new ArrayList<>( 3 ); diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java index 1db77ae6b2..eb8553960c 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java @@ -106,4 +106,7 @@ ProcessorType[] processorTypes() default { * @return the {@link CommandLineEnhancer} implementation. Must have a default constructor. */ Class commandLineEnhancer() default CommandLineEnhancer.class; + + boolean forkJvm() default false; + } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java index be1e4647c7..feb5c7dc02 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestContext.java @@ -13,13 +13,16 @@ public class ProcessorTestContext { private final String baseDir; private final ProcessorTest.ProcessorType processor; private final Class cliEnhancerClass; + private final boolean forkJvm; public ProcessorTestContext(String baseDir, ProcessorTest.ProcessorType processor, - Class cliEnhancerClass) { + Class cliEnhancerClass, + boolean forkJvm) { this.baseDir = baseDir; this.processor = processor; this.cliEnhancerClass = cliEnhancerClass; + this.forkJvm = forkJvm; } public String getBaseDir() { @@ -33,4 +36,8 @@ public ProcessorTest.ProcessorType getProcessor() { public Class getCliEnhancerClass() { return cliEnhancerClass; } + + public boolean isForkJvm() { + return forkJvm; + } } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java index b7a4f331cf..5ceb44804d 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTestTemplateInvocationContextProvider.java @@ -34,7 +34,8 @@ public Stream provideTestTemplateInvocationContex .map( processorType -> new ProcessorTestTemplateInvocationContext( new ProcessorTestContext( processorTest.baseDir(), processorType, - processorTest.commandLineEnhancer() + processorTest.commandLineEnhancer(), + processorTest.forkJvm() ) ) ); } } diff --git a/integrationtest/src/test/resources/kotlinDataTest/pom.xml b/integrationtest/src/test/resources/kotlinDataTest/pom.xml new file mode 100644 index 0000000000..8a43a04194 --- /dev/null +++ b/integrationtest/src/test/resources/kotlinDataTest/pom.xml @@ -0,0 +1,102 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + kotlinDataTest + jar + + + 1.3.70 + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + generate-via-compiler-plugin + + false + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + + \${project.basedir}/src/main/kotlin + \${project.basedir}/src/main/java + + + + + test-compile + test-compile + + + \${project.basedir}/src/test/kotlin + \${project.basedir}/src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + compile + + + java-test-compile + test-compile + testCompile + + + + + + + + + diff --git a/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerEntity.java b/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerEntity.java new file mode 100644 index 0000000000..e992eb0e60 --- /dev/null +++ b/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.kotlin.data; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerMapper.java b/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerMapper.java new file mode 100644 index 0000000000..b2157252db --- /dev/null +++ b/integrationtest/src/test/resources/kotlinDataTest/src/main/java/org/mapstruct/itest/kotlin/data/CustomerMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.kotlin.data; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromRecord(CustomerDto record); + + @InheritInverseConfiguration + CustomerDto toRecord(CustomerEntity entity); + +} diff --git a/integrationtest/src/test/resources/kotlinDataTest/src/main/kotlin/org/mapstruct/itest/kotlin/data/CustomerDto.kt b/integrationtest/src/test/resources/kotlinDataTest/src/main/kotlin/org/mapstruct/itest/kotlin/data/CustomerDto.kt new file mode 100644 index 0000000000..820a8b56c3 --- /dev/null +++ b/integrationtest/src/test/resources/kotlinDataTest/src/main/kotlin/org/mapstruct/itest/kotlin/data/CustomerDto.kt @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.kotlin.data; + +data class CustomerDto(var name: String?, var email: String?) { + +} diff --git a/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java b/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java new file mode 100644 index 0000000000..513f080a8b --- /dev/null +++ b/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.kotlin.data; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.kotlin.data.CustomerDto; +import org.mapstruct.itest.kotlin.data.CustomerEntity; +import org.mapstruct.itest.kotlin.data.CustomerMapper; + +public class KotlinDataTest { + + @Test + public void shouldMapData() { + CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } + + @Test + public void shouldMapIntoData() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Kermit" ); + entity.setMail( "kermit@test.com" ); + + CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getEmail() ).isEqualTo( "kermit@test.com" ); + } +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java index 0e8a0d2567..a3c7037f03 100644 --- a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java @@ -5,6 +5,7 @@ */ package org.mapstruct.itest.records; +import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @@ -20,4 +21,7 @@ public interface CustomerMapper { @Mapping(target = "mail", source = "email") CustomerEntity fromRecord(CustomerDto record); + @InheritInverseConfiguration + CustomerDto toRecord(CustomerEntity entity); + } diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index 5a7a62f780..824a763fc7 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -22,4 +22,17 @@ public void shouldMapRecord() { assertThat( customer.getName() ).isEqualTo( "Kermit" ); assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); } + + @Test + public void shouldMapIntoRecord() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Kermit" ); + entity.setMail( "kermit@test.com" ); + + CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity ); + + assertThat( customer ).isNotNull(); + assertThat( customer.name() ).isEqualTo( "Kermit" ); + assertThat( customer.email() ).isEqualTo( "kermit@test.com" ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 53a271858b..ea4f3fbdee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -8,18 +8,26 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; import javax.lang.model.type.DeclaredType; +import javax.lang.model.util.ElementFilter; import javax.tools.Diagnostic; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -33,6 +41,7 @@ import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.model.common.BuilderType; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; @@ -41,15 +50,20 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; +import org.mapstruct.ap.internal.util.accessor.ParameterElementAccessor; import static org.mapstruct.ap.internal.model.beanmapping.MappingReferences.forSourceMethod; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; +import static org.mapstruct.ap.internal.util.Message.GENERAL_AMBIGIOUS_CONSTRUCTORS; +import static org.mapstruct.ap.internal.util.Message.GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS; /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally @@ -61,7 +75,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; + private final Map> constructorMappingsByParameter; private final List constantMappings; + private final List constructorConstantMappings; private final Type returnTypeToConstruct; private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; @@ -73,6 +89,7 @@ public static class Builder { /* returnType to construct can have a builder */ private BuilderType returnTypeBuilder; + private Map unprocessedConstructorProperties; private Map unprocessedTargetProperties; private Map unprocessedSourceProperties; private Set targetProperties; @@ -82,6 +99,8 @@ public static class Builder { private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); private MappingReferences mappingReferences; + private MethodReference factoryMethod; + private boolean hasFactoryMethod; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -125,15 +144,12 @@ public BeanMappingMethod build() { /* 3) or the builder whenever the return type is immutable */ Type returnTypeToConstruct = null; - /* factory or builder method to construct the returnTypeToConstruct */ - MethodReference factoryMethod = null; - // determine which return type to construct boolean cannotConstructReturnType = false; if ( !method.getReturnType().isVoid() ) { Type returnTypeImpl = getReturnTypeToConstructFromSelectionParameters( selectionParameters ); if ( returnTypeImpl != null ) { - factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + initializeFactoryMethod( returnTypeImpl, selectionParameters ); if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } @@ -143,7 +159,7 @@ public BeanMappingMethod build() { } else if ( isBuilderRequired() ) { returnTypeImpl = returnTypeBuilder.getBuilder(); - factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + initializeFactoryMethod( returnTypeImpl, selectionParameters ); if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } @@ -153,7 +169,7 @@ else if ( isBuilderRequired() ) { } else if ( !method.isUpdateMethod() ) { returnTypeImpl = method.getReturnType(); - factoryMethod = getFactoryMethod( returnTypeImpl, selectionParameters ); + initializeFactoryMethod( returnTypeImpl, selectionParameters ); if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } @@ -171,13 +187,39 @@ else if ( !method.isUpdateMethod() ) { /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; + existingVariableNames.addAll( method.getParameterNames() ); + CollectionMappingStrategyGem cms = this.method.getOptions().getMapper().getCollectionMappingStrategy(); // determine accessors Map accessors = resultTypeToMap.getPropertyWriteAccessors( cms ); - this.targetProperties = accessors.keySet(); + this.targetProperties = new LinkedHashSet<>( accessors.keySet() ); this.unprocessedTargetProperties = new LinkedHashMap<>( accessors ); + + if ( !method.isUpdateMethod() && !hasFactoryMethod ) { + ConstructorAccessor constructorAccessor = getConstructorAccessor( resultTypeToMap ); + if ( constructorAccessor != null ) { + + this.unprocessedConstructorProperties = constructorAccessor.constructorAccessors; + + factoryMethod = MethodReference.forConstructorInvocation( + resultTypeToMap, + constructorAccessor.parameterBindings + ); + + } + else { + this.unprocessedConstructorProperties = new LinkedHashMap<>(); + } + + this.targetProperties.addAll( this.unprocessedConstructorProperties.keySet() ); + this.unprocessedTargetProperties.putAll( this.unprocessedConstructorProperties ); + } + else { + unprocessedConstructorProperties = new LinkedHashMap<>(); + } + this.unprocessedSourceProperties = new LinkedHashMap<>(); for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); @@ -191,7 +233,6 @@ else if ( !method.isUpdateMethod() ) { unprocessedSourceProperties.put( entry.getKey(), entry.getValue() ); } } - existingVariableNames.addAll( method.getParameterNames() ); // get bean mapping (when specified as annotation ) if ( beanMapping != null ) { @@ -223,6 +264,9 @@ else if ( !method.isUpdateMethod() ) { // Process the unprocessed defined targets handleUnprocessedDefinedTargets(); + // Initialize unprocessed constructor properties + handleUnmappedConstructorProperties(); + // report errors on unmapped properties reportErrorForUnmappedTargetPropertiesIfRequired(); reportErrorForUnmappedSourcePropertiesIfRequired(); @@ -364,6 +408,7 @@ private void handleUnprocessedDefinedTargets() { if ( propertyMapping != null ) { unprocessedTargetProperties.remove( propertyName ); + unprocessedConstructorProperties.remove( propertyName ); unprocessedSourceProperties.remove( propertyName ); iterator.remove(); propertyMappings.add( propertyMapping ); @@ -374,6 +419,28 @@ private void handleUnprocessedDefinedTargets() { } } + private void handleUnmappedConstructorProperties() { + for ( Entry entry : unprocessedConstructorProperties.entrySet() ) { + Accessor accessor = entry.getValue(); + Type accessedType = ctx.getTypeFactory() + .getType( accessor.getAccessedType() ); + String targetPropertyName = entry.getKey(); + + propertyMappings.add( new JavaExpressionMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .javaExpression( accessedType.getNull() ) + .existingVariableNames( existingVariableNames ) + .target( targetPropertyName, null, accessor ) + .dependsOn( Collections.emptySet() ) + .mirror( null ) + .build() + ); + } + + unprocessedConstructorProperties.clear(); + } + /** * Sources the given mappings as per the dependency relationships given via {@code dependsOn()}. If a cycle is * detected, an error is reported. @@ -434,7 +501,7 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) { ); error = false; } - else if ( !resultType.hasEmptyAccessibleConstructor() ) { + else if ( !resultType.hasAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), method.getOptions().getBeanMapping().getMirror(), @@ -456,7 +523,7 @@ private boolean canReturnTypeBeConstructed(Type returnType) { ); error = false; } - else if ( !returnType.hasEmptyAccessibleConstructor() ) { + else if ( !returnType.hasAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, @@ -470,20 +537,225 @@ else if ( !returnType.hasEmptyAccessibleConstructor() ) { /** * Find a factory method for a return type or for a builder. * @param returnTypeImpl the return type implementation to construct - * @param selectionParameters + * @param @selectionParameters * @return */ - private MethodReference getFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters) { - MethodReference factoryMethod = ObjectFactoryMethodResolver.getFactoryMethod( method, - returnTypeImpl, - selectionParameters, - ctx + private void initializeFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters) { + List> matchingFactoryMethods = + ObjectFactoryMethodResolver.getMatchingFactoryMethods( + method, + returnTypeImpl, + selectionParameters, + ctx + ); + + if ( matchingFactoryMethods.isEmpty() ) { + if ( factoryMethod == null && returnTypeBuilder != null ) { + factoryMethod = ObjectFactoryMethodResolver.getBuilderFactoryMethod( method, returnTypeBuilder ); + hasFactoryMethod = factoryMethod != null; + } + } + else if ( matchingFactoryMethods.size() == 1 ) { + factoryMethod = ObjectFactoryMethodResolver.getFactoryMethodReference( + method, + first( matchingFactoryMethods ), + ctx + ); + hasFactoryMethod = true; + } + else { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, + returnTypeImpl, + Strings.join( matchingFactoryMethods, ", " ) + ); + hasFactoryMethod = true; + } + } + + private ConstructorAccessor getConstructorAccessor(Type type) { + + if ( type.isRecord() ) { + // If the type is a record then just get the record components and use then + List recordComponents = type.getRecordComponents(); + List parameterBindings = new ArrayList<>( recordComponents.size() ); + Map constructorAccessors = new LinkedHashMap<>(); + for ( Element recordComponent : recordComponents ) { + String parameterName = recordComponent.getSimpleName().toString(); + Accessor accessor = createConstructorAccessor( recordComponent, parameterName ); + constructorAccessors.put( + parameterName, + accessor + ); + + parameterBindings.add( ParameterBinding.fromTypeAndName( + ctx.getTypeFactory().getType( recordComponent.asType() ), + accessor.getSimpleName() + ) ); + } + return new ConstructorAccessor( parameterBindings, constructorAccessors ); + } + + List constructors = ElementFilter.constructorsIn( type.getTypeElement() + .getEnclosedElements() ); + + ExecutableElement defaultConstructor = null; + List accessibleConstructors = new ArrayList<>( constructors.size() ); + + for ( ExecutableElement constructor : constructors ) { + if ( constructor.getModifiers().contains( Modifier.PRIVATE ) ) { + continue; + } + + if ( constructor.getParameters().isEmpty() ) { + defaultConstructor = constructor; + } + else { + accessibleConstructors.add( constructor ); + } + } + + if ( defaultConstructor != null ) { + return null; + } + + if ( accessibleConstructors.isEmpty() ) { + return null; + } + + ExecutableElement constructor = null; + if ( accessibleConstructors.size() > 1 ) { + + for ( ExecutableElement accessibleConstructor : accessibleConstructors ) { + for ( AnnotationMirror annotationMirror : accessibleConstructor.getAnnotationMirrors() ) { + if ( annotationMirror.getAnnotationType() + .asElement() + .getSimpleName() + .contentEquals( "Default" ) ) { + constructor = accessibleConstructor; + break; + } + } + } + + if ( constructor == null ) { + ctx.getMessager().printMessage( + method.getExecutable(), + GENERAL_AMBIGIOUS_CONSTRUCTORS, + type, + Strings.join( constructors, ", " ) + ); + return null; + } + } + else { + constructor = accessibleConstructors.get( 0 ); + } + + List constructorParameters = ctx.getTypeFactory() + .getParameters( (DeclaredType) type.getTypeMirror(), constructor ); + + + List constructorProperties = null; + for ( AnnotationMirror annotationMirror : constructor.getAnnotationMirrors() ) { + if ( annotationMirror.getAnnotationType() + .asElement() + .getSimpleName() + .contentEquals( "ConstructorProperties" ) ) { + for ( Entry entry : annotationMirror + .getElementValues() + .entrySet() ) { + if ( entry.getKey().getSimpleName().contentEquals( "value" ) ) { + constructorProperties = getArrayValues( entry.getValue() ); + break; + } + } + break; + } + } + + if ( constructorProperties == null ) { + Map constructorAccessors = new LinkedHashMap<>(); + List parameterBindings = new ArrayList<>( constructorParameters.size() ); + for ( Parameter constructorParameter : constructorParameters ) { + String parameterName = constructorParameter.getName(); + Element parameterElement = constructorParameter.getElement(); + Accessor constructorAccessor = createConstructorAccessor( parameterElement, parameterName ); + constructorAccessors.put( + parameterName, + constructorAccessor + ); + parameterBindings.add( ParameterBinding.fromTypeAndName( + constructorParameter.getType(), + constructorAccessor.getSimpleName() + ) ); + } + + return new ConstructorAccessor( parameterBindings, constructorAccessors ); + } + else if ( constructorProperties.size() != constructorParameters.size() ) { + ctx.getMessager().printMessage( + method.getExecutable(), + GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS, + type + ); + return null; + } + else { + Map constructorAccessors = new LinkedHashMap<>(); + List parameterBindings = new ArrayList<>( constructorProperties.size() ); + for ( int i = 0; i < constructorProperties.size(); i++ ) { + String parameterName = constructorProperties.get( i ); + Parameter constructorParameter = constructorParameters.get( i ); + Element parameterElement = constructorParameter.getElement(); + Accessor constructorAccessor = createConstructorAccessor( parameterElement, parameterName ); + constructorAccessors.put( + parameterName, + constructorAccessor + ); + parameterBindings.add( ParameterBinding.fromTypeAndName( + constructorParameter.getType(), + constructorAccessor.getSimpleName() + ) ); + } + + return new ConstructorAccessor( parameterBindings, constructorAccessors ); + } + } + + private Accessor createConstructorAccessor(Element element, String parameterName) { + String safeParameterName = Strings.getSafeVariableName( + parameterName, + existingVariableNames ); - if ( factoryMethod == null && returnTypeBuilder != null ) { - factoryMethod = ObjectFactoryMethodResolver.getBuilderFactoryMethod( method, returnTypeBuilder ); + existingVariableNames.add( safeParameterName ); + return new ParameterElementAccessor( element, safeParameterName ); + } + + private List getArrayValues(AnnotationValue av) { + + if ( av.getValue() instanceof List ) { + List result = new ArrayList<>(); + for ( AnnotationValue v : getValueAsList( av ) ) { + Object value = v.getValue(); + if ( value instanceof String ) { + result.add( (String) value ); + } + else { + return null; + } + } + return result; + } + else { + return null; } + } - return factoryMethod; + @SuppressWarnings("unchecked") + private List getValueAsList(AnnotationValue av) { + return (List) av.getValue(); } /** @@ -531,6 +803,7 @@ private boolean handleDefinedMappings(Type resultTypeToMap) { // remove the remaining name based properties for ( String handledTarget : handledTargets ) { unprocessedTargetProperties.remove( handledTarget ); + unprocessedConstructorProperties.remove( handledTarget ); unprocessedDefinedTargets.remove( handledTarget ); } @@ -672,7 +945,22 @@ else if ( !mapping.isIgnored() ) { // check the mapping options // its an ignored property mapping if ( mapping.isIgnored() ) { - propertyMapping = null; + if ( targetWriteAccessor != null && targetWriteAccessor.getAccessorType() == AccessorType.PARAMETER ) { + // Even though the property is ignored this is a constructor parameter. + // Therefore we have to initialize it + Type accessedType = ctx.getTypeFactory() + .getType( targetWriteAccessor.getAccessedType() ); + + propertyMapping = new JavaExpressionMappingBuilder() + .mappingContext( ctx ) + .sourceMethod( method ) + .javaExpression( accessedType.getNull() ) + .existingVariableNames( existingVariableNames ) + .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) + .dependsOn( mapping.getDependsOn() ) + .mirror( mapping.getMirror() ) + .build(); + } handledTargets.add( targetPropertyName ); } @@ -821,6 +1109,7 @@ private void applyPropertyNameBasedMapping(List sourceReference String targetPropertyName = sourceRef.getDeepestPropertyName(); Accessor targetPropertyWriteAccessor = unprocessedTargetProperties.remove( targetPropertyName ); + unprocessedConstructorProperties.remove( targetPropertyName ); if ( targetPropertyWriteAccessor == null ) { // TODO improve error message ctx.getMessager() @@ -1056,6 +1345,18 @@ private void reportErrorForUnmappedSourcePropertiesIfRequired() { } } + private static class ConstructorAccessor { + private final List parameterBindings; + private final Map constructorAccessors; + + private ConstructorAccessor( + List parameterBindings, + Map constructorAccessors) { + this.parameterBindings = parameterBindings; + this.constructorAccessors = constructorAccessors; + } + } + private BeanMappingMethod(Method method, Collection existingVariableNames, List propertyMappings, @@ -1082,15 +1383,30 @@ private BeanMappingMethod(Method method, // intialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. this.mappingsByParameter = new HashMap<>(); - this.constantMappings = new ArrayList<>( propertyMappings ); - for ( Parameter sourceParameter : getSourceParameters() ) { - ArrayList mappingsOfParameter = new ArrayList<>(); - mappingsByParameter.put( sourceParameter.getName(), mappingsOfParameter ); - for ( PropertyMapping mapping : propertyMappings ) { - if ( sourceParameter.getName().equals( mapping.getSourceBeanName() ) ) { - mappingsOfParameter.add( mapping ); - constantMappings.remove( mapping ); + this.constantMappings = new ArrayList<>( propertyMappings.size() ); + this.constructorMappingsByParameter = new LinkedHashMap<>(); + this.constructorConstantMappings = new ArrayList<>(); + Set sourceParameterNames = getSourceParameters().stream() + .map( Parameter::getName ) + .collect( Collectors.toSet() ); + for ( PropertyMapping mapping : propertyMappings ) { + if ( mapping.isConstructorMapping() ) { + if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { + constructorMappingsByParameter.computeIfAbsent( + mapping.getSourceBeanName(), + key -> new ArrayList<>() + ).add( mapping ); } + else { + constructorConstantMappings.add( mapping ); + } + } + else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { + mappingsByParameter.computeIfAbsent( mapping.getSourceBeanName(), key -> new ArrayList<>() ) + .add( mapping ); + } + else { + constantMappings.add( mapping ); } } this.returnTypeToConstruct = returnTypeToConstruct; @@ -1100,15 +1416,28 @@ public List getConstantMappings() { return constantMappings; } + public List getConstructorConstantMappings() { + return constructorConstantMappings; + } + public List propertyMappingsByParameter(Parameter parameter) { // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value - return mappingsByParameter.get( parameter.getName() ); + return mappingsByParameter.getOrDefault( parameter.getName(), Collections.emptyList() ); + } + + public List constructorPropertyMappingsByParameter(Parameter parameter) { + // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value + return constructorMappingsByParameter.getOrDefault( parameter.getName(), Collections.emptyList() ); } public Type getReturnTypeToConstruct() { return returnTypeToConstruct; } + public boolean hasConstructorMappings() { + return !constructorMappingsByParameter.isEmpty() || !constructorConstantMappings.isEmpty(); + } + public MethodReference getFinalizerMethod() { return finalizerMethod; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 04331c4e14..7ab9814e23 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -130,7 +130,7 @@ public Assignment build() { CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); boolean targetImmutable = cms == CollectionMappingStrategyGem.TARGET_IMMUTABLE || targetReadAccessor == null; - if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) { + if ( targetAccessorType == AccessorType.SETTER || targetAccessorType.isFieldAssignment() ) { if ( result.isCallingUpdateMethod() && !targetImmutable ) { @@ -149,7 +149,7 @@ public Assignment build() { result, method.getThrownTypes(), factoryMethod, - targetAccessorType == AccessorType.FIELD, + targetAccessorType.isFieldAssignment(), targetType, true, nvpms == SET_TO_NULL && !targetType.isPrimitive(), @@ -165,7 +165,7 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { nvcs, nvpms, ctx.getTypeFactory(), - targetAccessorType == AccessorType.FIELD + targetAccessorType.isFieldAssignment() ); } else if ( result.getType() == Assignment.AssignmentType.DIRECT || @@ -176,16 +176,18 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || method.getThrownTypes(), targetType, ctx.getTypeFactory(), - targetAccessorType == AccessorType.FIELD + targetAccessorType.isFieldAssignment() ); } else { + //TODO init default value + // target accessor is setter, so wrap the setter in setter map/ collection handling result = new SetterWrapperForCollectionsAndMaps( result, method.getThrownTypes(), targetType, - targetAccessorType == AccessorType.FIELD + targetAccessorType.isFieldAssignment() ); } } @@ -203,7 +205,7 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || result, method.getThrownTypes(), targetType, - targetAccessorType == AccessorType.FIELD + targetAccessorType.isFieldAssignment() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index dc2bf52182..58c4ba890a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; import java.util.Set; @@ -57,6 +58,7 @@ public class MethodReference extends ModelElement implements Assignment { private final List parameterBindings; private final Parameter providingParameter; private final boolean isStatic; + private final boolean isConstructor; /** * Creates a new reference to the given method. @@ -91,6 +93,7 @@ protected MethodReference(Method method, MapperReference declaringMapper, Parame this.definingType = method.getDefiningType(); this.isStatic = method.isStatic(); this.name = method.getName(); + this.isConstructor = false; } private MethodReference(BuiltInMethod method, ConversionContext contextParam) { @@ -106,6 +109,7 @@ private MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.parameterBindings = ParameterBinding.fromParameters( method.getParameters() ); this.isStatic = method.isStatic(); this.name = method.getName(); + this.isConstructor = false; } private MethodReference(String name, Type definingType, boolean isStatic) { @@ -121,6 +125,37 @@ private MethodReference(String name, Type definingType, boolean isStatic) { this.parameterBindings = Collections.emptyList(); this.providingParameter = null; this.isStatic = isStatic; + this.isConstructor = false; + } + + private MethodReference(Type definingType, List parameterBindings) { + this.name = null; + this.definingType = definingType; + this.sourceParameters = Collections.emptyList(); + this.returnType = null; + this.declaringMapper = null; + this.thrownTypes = Collections.emptyList(); + this.isUpdateMethod = false; + this.contextParam = null; + this.parameterBindings = parameterBindings; + this.providingParameter = null; + this.isStatic = false; + this.isConstructor = true; + + if ( parameterBindings.isEmpty() ) { + this.importTypes = Collections.emptySet(); + } + else { + Set imported = new LinkedHashSet<>(); + + for ( ParameterBinding binding : parameterBindings ) { + imported.add( binding.getType() ); + } + + imported.add( definingType ); + + this.importTypes = Collections.unmodifiableSet( imported ); + } } public MapperReference getDeclaringMapper() { @@ -271,6 +306,10 @@ public boolean isStatic() { return isStatic; } + public boolean isConstructor() { + return isConstructor; + } + public List getParameterBindings() { return parameterBindings; } @@ -341,6 +380,10 @@ public static MethodReference forMethodCall(String methodName) { return new MethodReference( methodName, null, false ); } + public static MethodReference forConstructorInvocation(Type type, List parameterBindings) { + return new MethodReference( type, parameterBindings ); + } + @Override public String toString() { String mapper = declaringMapper != null ? declaringMapper.getType().getName() : ""; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index 4687a626d1..fcd8d70d52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -42,6 +42,9 @@ public Set getImportTypes() { types.addAll( getReturnType().getImplementationType().getImportTypes() ); } } + else if ( factoryMethod != null ) { + types.addAll( factoryMethod.getImportTypes() ); + } return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index f4b39ab1a6..34d2944276 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -67,16 +67,12 @@ public static MethodReference getFactoryMethod( Method method, MappingBuilderContext ctx) { - MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); - - List> matchingFactoryMethods = - selectors.getMatchingMethods( - method, - getAllAvailableMethods( method, ctx.getSourceModel() ), - java.util.Collections.emptyList(), - alternativeTarget, - SelectionCriteria.forFactoryMethods( selectionParameters ) ); + List> matchingFactoryMethods = getMatchingFactoryMethods( + method, + alternativeTarget, + selectionParameters, + ctx + ); if (matchingFactoryMethods.isEmpty()) { return null; @@ -94,6 +90,11 @@ public static MethodReference getFactoryMethod( Method method, SelectedMethod matchingFactoryMethod = first( matchingFactoryMethods ); + return getFactoryMethodReference( method, matchingFactoryMethod, ctx ); + } + + public static MethodReference getFactoryMethodReference(Method method, + SelectedMethod matchingFactoryMethod, MappingBuilderContext ctx) { Parameter providingParameter = method.getContextProvidedMethods().getParameterForProvidedMethod( matchingFactoryMethod.getMethod() ); @@ -115,6 +116,22 @@ public static MethodReference getFactoryMethod( Method method, } } + public static List> getMatchingFactoryMethods( Method method, + Type alternativeTarget, + SelectionParameters selectionParameters, + MappingBuilderContext ctx) { + + MethodSelectors selectors = + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); + + return selectors.getMatchingMethods( + method, + getAllAvailableMethods( method, ctx.getSourceModel() ), + java.util.Collections.emptyList(), + alternativeTarget, + SelectionCriteria.forFactoryMethods( selectionParameters ) ); + } + public static MethodReference getBuilderFactoryMethod(Method method, BuilderType builder ) { if ( builder == null ) { return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 1558fc7f8a..571c3530f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -70,6 +70,7 @@ public class PropertyMapping extends ModelElement { private final Assignment assignment; private final Set dependsOn; private final Assignment defaultValueAssignment; + private final boolean constructorMapping; @SuppressWarnings("unchecked") private static class MappingBuilderBase> extends AbstractBaseBuilder { @@ -126,7 +127,7 @@ public T existingVariableNames(Set existingVariableNames) { } protected boolean isFieldAssignment() { - return targetWriteAccessorType == AccessorType.FIELD; + return targetWriteAccessorType.isFieldAssignment(); } } @@ -278,7 +279,8 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get targetType, assignment, dependsOn, - getDefaultValueAssignment( assignment ) + getDefaultValueAssignment( assignment ), + targetWriteAccessorType == AccessorType.PARAMETER ); } @@ -376,7 +378,7 @@ private Assignment assignToPlain(Type targetType, AccessorType targetAccessorTyp Assignment result; - if ( targetAccessorType == AccessorType.SETTER || targetAccessorType == AccessorType.FIELD ) { + if ( targetAccessorType == AccessorType.SETTER || targetAccessorType.isFieldAssignment() ) { result = assignToPlainViaSetter( targetType, rightHandSide ); } else { @@ -473,6 +475,7 @@ private Assignment assignToCollection(Type targetType, AccessorType targetAccess private Assignment assignToArray(Type targetType, Assignment rightHandSide) { Type arrayType = ctx.getTypeFactory().getType( Arrays.class ); + //TODO init default value return new ArrayCopyWrapper( rightHandSide, targetPropertyName, @@ -803,7 +806,7 @@ public PropertyMapping build() { if ( assignment != null ) { if ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || - targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) { + targetWriteAccessor.getAccessorType().isFieldAssignment() ) { // target accessor is setter, so decorate assignment as setter if ( assignment.isCallingUpdateMethod() ) { @@ -874,7 +877,8 @@ else if ( errorMessageDetails == null ) { targetType, assignment, dependsOn, - null + null, + targetWriteAccessorType == AccessorType.PARAMETER ); } @@ -919,7 +923,7 @@ public PropertyMapping build() { Assignment assignment = new SourceRHS( javaExpression, null, existingVariableNames, "" ); if ( targetWriteAccessor.getAccessorType() == AccessorType.SETTER || - targetWriteAccessor.getAccessorType() == AccessorType.FIELD ) { + targetWriteAccessor.getAccessorType().isFieldAssignment() ) { // setter, so wrap in setter assignment = new SetterWrapper( assignment, method.getThrownTypes(), isFieldAssignment() ); } @@ -939,7 +943,8 @@ public PropertyMapping build() { targetType, assignment, dependsOn, - null + null, + targetWriteAccessorType == AccessorType.PARAMETER ); } @@ -947,18 +952,19 @@ public PropertyMapping build() { // Constructor for creating mappings of constant expressions. private PropertyMapping(String name, String targetWriteAccessorName, - ValueProvider targetReadAccessorProvider, - Type targetType, Assignment propertyAssignment, - Set dependsOn, Assignment defaultValueAssignment ) { + ValueProvider targetReadAccessorProvider, + Type targetType, Assignment propertyAssignment, + Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, - targetType, propertyAssignment, dependsOn, defaultValueAssignment + targetType, propertyAssignment, dependsOn, defaultValueAssignment, + constructorMapping ); } private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, - ValueProvider targetReadAccessorProvider, Type targetType, - Assignment assignment, - Set dependsOn, Assignment defaultValueAssignment) { + ValueProvider targetReadAccessorProvider, Type targetType, + Assignment assignment, + Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { this.name = name; this.sourceBeanName = sourceBeanName; this.targetWriteAccessorName = targetWriteAccessorName; @@ -968,6 +974,7 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.assignment = assignment; this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet(); this.defaultValueAssignment = defaultValueAssignment; + this.constructorMapping = constructorMapping; } /** @@ -1001,6 +1008,10 @@ public Assignment getDefaultValueAssignment() { return defaultValueAssignment; } + public boolean isConstructorMapping() { + return constructorMapping; + } + @Override public Set getImportTypes() { if ( defaultValueAssignment == null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 958725c966..2fd2b69eeb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -9,6 +9,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import javax.lang.model.element.Element; import javax.lang.model.element.VariableElement; import org.mapstruct.ap.internal.gem.ContextGem; @@ -23,6 +24,7 @@ */ public class Parameter extends ModelElement { + private final Element element; private final String name; private final String originalName; private final Type type; @@ -32,8 +34,20 @@ public class Parameter extends ModelElement { private final boolean varArgs; + private Parameter(Element element, Type type, boolean varArgs) { + this.element = element; + this.name = element.getSimpleName().toString(); + this.originalName = name; + this.type = type; + this.mappingTarget = MappingTargetGem.instanceOn( element ) != null; + this.targetType = TargetTypeGem.instanceOn( element ) != null; + this.mappingContext = ContextGem.instanceOn( element ) != null; + this.varArgs = varArgs; + } + private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext, boolean varArgs) { + this.element = null; this.name = name; this.originalName = name; this.type = type; @@ -47,6 +61,10 @@ public Parameter(String name, Type type) { this( name, type, false, false, false, false ); } + public Element getElement() { + return element; + } + public String getName() { return name; } @@ -115,11 +133,8 @@ public boolean equals(Object o) { public static Parameter forElementAndType(VariableElement element, Type parameterType, boolean isVarArgs) { return new Parameter( - element.getSimpleName().toString(), + element, parameterType, - MappingTargetGem.instanceOn( element ) != null, - TargetTypeGem.instanceOn( element ) != null, - ContextGem.instanceOn( element ) != null, isVarArgs ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 5f807578e8..36e4d3e864 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -111,6 +111,17 @@ public static List fromParameters(List parameters) return result; } + public static ParameterBinding fromTypeAndName(Type parameterType, String parameterName) { + return new ParameterBinding( + parameterType, + parameterName, + false, + false, + false, + null + ); + } + /** * @param classTypeOf the type representing {@code Class} for the target type {@code X} * @return a parameter binding representing a target type parameter diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 52a076270b..0974fe3477 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -90,14 +90,16 @@ public class Type extends ModelElement implements Comparable { private List allMethods = null; private List allFields = null; + private List recordComponents = null; private List setters = null; private List adders = null; private List alternativeTargetAccessors = null; + private Map constructorAccessors = null; private Type boundingBase = null; - private Boolean hasEmptyAccessibleConstructor; + private Boolean hasAccessibleConstructor; private final Filters filters; @@ -290,6 +292,10 @@ public boolean isJavaLangType() { return packageName != null && packageName.startsWith( "java." ); } + public boolean isRecord() { + return typeElement.getKind().name().equals( "RECORD" ); + } + /** * Whether this type is a sub-type of {@link java.util.stream.Stream}. * @@ -498,7 +504,7 @@ public Map getPropertyReadAccessors() { } } - Map recordAccessors = filters.recordsIn( typeElement ); + Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); for ( Map.Entry recordEntry : recordAccessors.entrySet() ) { modifiableGetters.putIfAbsent( recordEntry.getKey(), recordEntry.getValue() ); } @@ -600,6 +606,14 @@ else if ( candidate.getAccessorType() == AccessorType.FIELD && ( Executables.is return result; } + public List getRecordComponents() { + if ( recordComponents == null ) { + recordComponents = filters.recordComponentsIn( typeElement ); + } + + return recordComponents; + } + private Type determinePreferredType(Accessor readAccessor) { if ( readAccessor != null ) { return typeFactory.getReturnType( (DeclaredType) typeMirror, readAccessor ); @@ -613,7 +627,7 @@ private Type determineTargetType(Accessor candidate) { return parameter.getType(); } else if ( candidate.getAccessorType() == AccessorType.GETTER - || candidate.getAccessorType() == AccessorType.FIELD ) { + || candidate.getAccessorType().isFieldAssignment() ) { return typeFactory.getReturnType( (DeclaredType) typeMirror, candidate ); } return null; @@ -636,11 +650,12 @@ private List getAllFields() { } private String getPropertyName(Accessor accessor ) { - if ( accessor.getAccessorType() == AccessorType.FIELD ) { - return accessorNaming.getPropertyName( (VariableElement) accessor.getElement() ); + Element accessorElement = accessor.getElement(); + if ( accessorElement instanceof ExecutableElement ) { + return accessorNaming.getPropertyName( (ExecutableElement) accessorElement ); } else { - return accessorNaming.getPropertyName( (ExecutableElement) accessor.getElement() ); + return accessor.getSimpleName(); } } @@ -1009,20 +1024,18 @@ public Type getTypeBound() { return boundingBase; } - public boolean hasEmptyAccessibleConstructor() { - - if ( this.hasEmptyAccessibleConstructor == null ) { - hasEmptyAccessibleConstructor = false; + public boolean hasAccessibleConstructor() { + if ( hasAccessibleConstructor == null ) { + hasAccessibleConstructor = false; List constructors = ElementFilter.constructorsIn( typeElement.getEnclosedElements() ); for ( ExecutableElement constructor : constructors ) { - if ( !constructor.getModifiers().contains( Modifier.PRIVATE ) - && constructor.getParameters().isEmpty() ) { - hasEmptyAccessibleConstructor = true; + if ( !constructor.getModifiers().contains( Modifier.PRIVATE ) ) { + hasAccessibleConstructor = true; break; } } } - return hasEmptyAccessibleConstructor; + return hasAccessibleConstructor; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 594c2c7f70..a74c02fd7d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -50,7 +50,6 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.AccessorType; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderInfo; import org.mapstruct.ap.spi.MoreThanOneBuilderCreationMethodException; @@ -360,7 +359,7 @@ public TypeMirror getMethodType(DeclaredType includingType, Element method) { } public Parameter getSingleParameter(DeclaredType includingType, Accessor method) { - if ( method.getAccessorType() == AccessorType.FIELD ) { + if ( method.getAccessorType().isFieldAssignment() ) { return null; } ExecutableElement executable = (ExecutableElement) method.getElement(); @@ -376,11 +375,15 @@ public Parameter getSingleParameter(DeclaredType includingType, Accessor method) public List getParameters(DeclaredType includingType, Accessor accessor) { ExecutableElement method = (ExecutableElement) accessor.getElement(); - TypeMirror methodType = getMethodType( includingType, accessor.getElement() ); + return getParameters( includingType, method ); + } + + public List getParameters(DeclaredType includingType, ExecutableElement method) { + ExecutableType methodType = getMethodType( includingType, method ); if ( method == null || methodType.getKind() != TypeKind.EXECUTABLE ) { return new ArrayList<>(); } - return getParameters( (ExecutableType) methodType, method ); + return getParameters( methodType, method ); } public List getParameters(ExecutableType methodType, ExecutableElement method) { @@ -433,7 +436,7 @@ public List getThrownTypes(ExecutableType method) { } public List getThrownTypes(Accessor accessor) { - if (accessor.getAccessorType() == AccessorType.FIELD) { + if (accessor.getAccessorType().isFieldAssignment()) { return new ArrayList<>(); } return extractTypes( ( (ExecutableElement) accessor.getElement() ).getThrownTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java index f060385a04..0f17946f72 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -7,7 +7,6 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; -import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -68,10 +67,6 @@ public String getPropertyName(ExecutableElement executable) { return accessorNamingStrategy.getPropertyName( executable ); } - public String getPropertyName(VariableElement variable) { - return variable.getSimpleName().toString(); - } - /** * @param adderMethod the adder method * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 6981a1ebb5..f4d52d7095 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -7,6 +7,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -23,7 +24,7 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; -import org.mapstruct.ap.internal.util.accessor.VariableElementAccessor; +import org.mapstruct.ap.internal.util.accessor.FieldElementAccessor; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.accessor.AccessorType.ADDER; @@ -75,13 +76,25 @@ public List getterMethodsIn(List elements) { .collect( Collectors.toCollection( LinkedList::new ) ); } - public Map recordsIn(TypeElement typeElement) { - if ( RECORD_COMPONENTS_METHOD == null || RECORD_COMPONENT_ACCESSOR_METHOD == null ) { + @SuppressWarnings("unchecked") + public List recordComponentsIn(TypeElement typeElement) { + if ( RECORD_COMPONENTS_METHOD == null ) { + return java.util.Collections.emptyList(); + } + + try { + return (List) RECORD_COMPONENTS_METHOD.invoke( typeElement ); + } + catch ( IllegalAccessException | InvocationTargetException e ) { + return java.util.Collections.emptyList(); + } + } + + public Map recordAccessorsIn(Collection recordComponents) { + if ( RECORD_COMPONENT_ACCESSOR_METHOD == null ) { return java.util.Collections.emptyMap(); } try { - @SuppressWarnings("unchecked") - List recordComponents = (List) RECORD_COMPONENTS_METHOD.invoke( typeElement ); Map recordAccessors = new LinkedHashMap<>(); for ( Element recordComponent : recordComponents ) { ExecutableElement recordExecutableElement = @@ -109,7 +122,7 @@ private TypeMirror getReturnType(ExecutableElement executableElement) { public List fieldsIn(List accessors) { return accessors.stream() .filter( Fields::isFieldAccessor ) - .map( VariableElementAccessor::new ) + .map( FieldElementAccessor::new ) .collect( Collectors.toCollection( LinkedList::new ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index e4b199adfb..d2cb9857ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -110,12 +110,14 @@ public enum Message { GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), GENERAL_AMBIGIOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s." ), GENERAL_AMBIGIOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s." ), + GENERAL_AMBIGIOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), + GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), GENERAL_INVALID_DATE( "Given date format \"%s\" is invalid. Message: \"%s\"." ), GENERAL_JODA_NOT_ON_CLASSPATH( "Cannot validate Joda dateformat, no Joda on classpath. Consider adding Joda to the annotation processorpath.", Diagnostic.Kind.WARNING ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), - GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible parameterless constructor." ), + GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible constructor." ), GENERAL_NO_QUALIFYING_METHOD( "No qualifying method found for qualifiers: %s and / or qualifying names: %s" ), BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java index 0f64c2b375..bbd73943db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.util; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.AccessorType; /** * This a wrapper class which provides the value that needs to be used in the models. @@ -46,7 +45,7 @@ public static ValueProvider of(Accessor accessor) { return null; } String value = accessor.getSimpleName(); - if ( accessor.getAccessorType() != AccessorType.FIELD ) { + if ( !accessor.getAccessorType().isFieldAssignment() ) { value += "()"; } return new ValueProvider( value ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index 917d1a216b..314302a14e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -8,9 +8,8 @@ import java.util.Set; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.element.VariableElement; import javax.lang.model.element.Modifier; -import javax.lang.model.element.Name; +import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java index 9348de878c..23448a9e98 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java @@ -7,9 +7,14 @@ public enum AccessorType { + PARAMETER, FIELD, GETTER, SETTER, ADDER, PRESENCE_CHECKER; + + public boolean isFieldAssignment() { + return this == FIELD || this == PARAMETER; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java similarity index 83% rename from processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java rename to processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java index 8b1b01dbd6..5174900532 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/VariableElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java @@ -13,9 +13,9 @@ * * @author Filip Hrisafov */ -public class VariableElementAccessor extends AbstractAccessor { +public class FieldElementAccessor extends AbstractAccessor { - public VariableElementAccessor(VariableElement element) { + public FieldElementAccessor(VariableElement element) { super( element ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java new file mode 100644 index 0000000000..e1877cb0bb --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import javax.lang.model.element.Element; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; + +/** + * An {@link Accessor} that wraps a {@link VariableElement}. + * + * @author Filip Hrisafov + */ +public class ParameterElementAccessor extends AbstractAccessor { + + protected final String name; + + public ParameterElementAccessor(Element element, String name) { + super( element ); + this.name = name; + } + + @Override + public String getSimpleName() { + return name != null ? name : super.getSimpleName(); + } + + @Override + public TypeMirror getAccessedType() { + return element.asType(); + } + + @Override + public String toString() { + return element.toString(); + } + + @Override + public AccessorType getAccessorType() { + return AccessorType.PARAMETER; + } + +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index b8ffd0a179..45825b4fd6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -25,7 +25,62 @@ <#if !existingInstanceMapping> - <@includeModel object=returnTypeToConstruct/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=returnTypeToConstruct/><#else>new <@includeModel object=returnTypeToConstruct/>(); + <#if hasConstructorMappings()> + <#if (sourceParameters?size > 1)> + <#list sourceParametersExcludingPrimitives as sourceParam> + <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> + <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + + if ( ${sourceParam.name} != null ) { + <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> + <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> + + } + else { + <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> + ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; + + } + + + <#list sourcePrimitiveParameters as sourceParam> + <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> + <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> + + + + <#else> + <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + + <#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) { + <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> + <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> + + <#if mapNullToDefault> + } + else { + <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> + ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; + + } + + + <#list constructorConstantMappings as constantMapping> + + <@compress single_line=true> + <@includeModel object=constantMapping.targetType /> <@includeModel object=constantMapping existingInstanceMapping=existingInstanceMapping/> + + + + + <@includeModel object=returnTypeToConstruct/> ${resultName} = <@includeModel object=factoryMethod targetType=returnTypeToConstruct/>; + <#else > + <@includeModel object=returnTypeToConstruct/> ${resultName} = <#if factoryMethod??><@includeModel object=factoryMethod targetType=returnTypeToConstruct/><#else>new <@includeModel object=returnTypeToConstruct/>(); + <#list beforeMappingReferencesWithMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 30a830bc57..d0ee7bef3b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -16,6 +16,8 @@ <#-- method is referenced java8 static method in the mapper to implement (interface) --> <#elseif static> <@includeModel object=definingType/>.<@methodCall/> + <#elseif constructor> + new <@includeModel object=definingType/><#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() <#else> <@methodCall/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl index 361fedaa58..9160a62d9e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/AdderWrapper.ftl @@ -11,7 +11,7 @@ <@lib.sourceLocalVarAssignment/> <@lib.handleSourceReferenceNullCheck> for ( <@includeModel object=adderType.typeBound/> ${sourceLoopVarName} : <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} ) { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; } \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl index edb0d3cad3..2ce8736f96 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ArrayCopyWrapper.ftl @@ -10,6 +10,6 @@ <@lib.handleExceptions> <@lib.sourceLocalVarAssignment/> <@lib.handleSourceReferenceNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>Arrays.copyOf( ${sourceLocalVarName}, ${sourceLocalVarName}.length ); + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>Arrays.copyOf( ${sourceLocalVarName}, ${sourceLocalVarName}.length ); \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl index 613e8f6abd..c8f18b1c7f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapper.ftl @@ -10,6 +10,6 @@ <@lib.handleExceptions> <@lib.sourceLocalVarAssignment/> <@lib.handleSourceReferenceNullCheck> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl index 122c76bc62..beb6bb1f3a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMaps.ftl @@ -9,5 +9,5 @@ <#import "../macro/CommonMacros.ftl" as lib> <@lib.sourceLocalVarAssignment/> <@lib.handleExceptions> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.handleAssignment/>; \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index c26557af94..92e2e9d09d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -16,8 +16,12 @@ --> <#macro callTargetWriteAccessor> <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !ext.targetBeanName?has_content>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> + ${ext.targetWriteAccessorName}<@lib.handleWrite>null; + } + <#-- wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 96ecd953b9..de456ca773 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -40,7 +40,7 @@ } <#elseif setExplicitlyToDefault || setExplicitlyToNull> else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 6cf0ba401f..0cf59e7267 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -65,12 +65,7 @@ public void factoryMethodWithSourceParamIsChosen() { ".lang.Class clazz), org.mapstruct.ap.test.bugs._1242" + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB(@TargetType java.lang" + ".Class clazz), org.mapstruct.ap.test.bugs._1242" + - ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB()."), - @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 20, - message = "org.mapstruct.ap.test.bugs._1242.TargetB does not have an accessible parameterless " + - "constructor.") + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB().") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index 4d875017f8..b4ce1447f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -33,8 +33,7 @@ public class Issue1283Test { @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22L, - message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible parameterless " + - "constructor." + message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible constructor." ) } ) @@ -49,8 +48,7 @@ public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 18L, - message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible parameterless " + - "constructor." + message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible constructor." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java index a34c8d4a53..227296ad25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Source.java @@ -12,7 +12,7 @@ public class Source { private String source; - public Source(String source) { + private Source(String source) { this.source = source; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/ConstructorProperties.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/ConstructorProperties.java new file mode 100644 index 0000000000..affbded7ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/ConstructorProperties.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Filip Hrisafov + */ +@Documented +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.SOURCE) +public @interface ConstructorProperties { + + String[] value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/Default.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/Default.java new file mode 100644 index 0000000000..96b30c02ea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/Default.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Filip Hrisafov + */ +@Documented +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.SOURCE) +public @interface Default { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/Person.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/Person.java new file mode 100644 index 0000000000..8fc9e7ce30 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/Person.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Person { + + private final String name; + private final int age; + private final String job; + private final String city; + private final String address; + private final List children; + + public Person(String name, int age, String job, String city, String address, + List children) { + this.name = name; + this.age = age; + this.job = job; + this.city = city; + this.address = address; + this.children = children; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public String getJob() { + return job; + } + + public String getCity() { + return city; + } + + public String getAddress() { + return address; + } + + public List getChildren() { + return children; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/PersonDto.java new file mode 100644 index 0000000000..0b2cba09cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/PersonDto.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + + private String name; + private int age; + private String job; + private String city; + private String address; + private List children; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getJob() { + return job; + } + + public void setJob(String job) { + this.job = job; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/PersonWithConstructorProperties.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/PersonWithConstructorProperties.java new file mode 100644 index 0000000000..8419442cf1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/PersonWithConstructorProperties.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.constructorproperties; + +import java.util.List; + +import org.mapstruct.ap.test.constructor.ConstructorProperties; + +/** + * @author Filip Hrisafov + */ +public class PersonWithConstructorProperties { + + private final String name; + private final int age; + private final String job; + private final String city; + private final String address; + private final List children; + + @ConstructorProperties({"name", "age", "job", "city", "address", "children"}) + public PersonWithConstructorProperties(String var1, int var2, String var3, String var4, String var5, + List var6) { + this.name = var1; + this.age = var2; + this.job = var3; + this.city = var4; + this.address = var5; + this.children = var6; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public String getJob() { + return job; + } + + public String getCity() { + return city; + } + + public String getAddress() { + return address; + } + + public List getChildren() { + return children; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesMapper.java new file mode 100644 index 0000000000..3d32d8b31c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.constructorproperties; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleConstructorPropertiesMapper { + + SimpleConstructorPropertiesMapper INSTANCE = Mappers.getMapper( SimpleConstructorPropertiesMapper.class ); + + PersonWithConstructorProperties map(PersonDto dto); + + @Mapping(target = "age", constant = "25") + @Mapping(target = "job", constant = "Software Developer") + PersonWithConstructorProperties mapWithConstants(PersonDto dto); + + @Mapping(target = "age", expression = "java(25 - 5)") + @Mapping(target = "job", expression = "java(\"Software Developer\".toLowerCase())") + PersonWithConstructorProperties mapWithExpression(PersonDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java new file mode 100644 index 0000000000..b58d55f1ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java @@ -0,0 +1,90 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.constructorproperties; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.ConstructorProperties; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + ConstructorProperties.class, + PersonWithConstructorProperties.class, + PersonDto.class, + SimpleConstructorPropertiesMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class SimpleConstructorPropertiesTest { + + @Test + public void mapDefault() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.INSTANCE.map( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + assertThat( target.getJob() ).isEqualTo( "Software Engineer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } + + @Test + public void mapWithConstants() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.INSTANCE.mapWithConstants( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 25 ); + assertThat( target.getJob() ).isEqualTo( "Software Developer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } + + @Test + public void mapWithExpressions() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithConstructorProperties target = SimpleConstructorPropertiesMapper.INSTANCE.mapWithExpression( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 20 ); + assertThat( target.getJob() ).isEqualTo( "software developer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/PersonWithDefaultAnnotatedConstructor.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/PersonWithDefaultAnnotatedConstructor.java new file mode 100644 index 0000000000..190ab818ea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/PersonWithDefaultAnnotatedConstructor.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.defaultannotated; + +import org.mapstruct.ap.test.constructor.Default; + +/** + * @author Filip Hrisafov + */ +public class PersonWithDefaultAnnotatedConstructor { + + private final String name; + private final int age; + + public PersonWithDefaultAnnotatedConstructor(String name) { + this( name, -1 ); + } + + @Default + public PersonWithDefaultAnnotatedConstructor(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorMapper.java new file mode 100644 index 0000000000..6934c34fe4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.defaultannotated; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleDefaultAnnotatedConstructorMapper { + + SimpleDefaultAnnotatedConstructorMapper INSTANCE = + Mappers.getMapper( SimpleDefaultAnnotatedConstructorMapper.class ); + + PersonWithDefaultAnnotatedConstructor map(PersonDto dto); + + @Mapping(target = "age", constant = "25") + PersonWithDefaultAnnotatedConstructor mapWithConstants(PersonDto dto); + + @Mapping(target = "age", expression = "java(25 - 5)") + PersonWithDefaultAnnotatedConstructor mapWithExpression(PersonDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java new file mode 100644 index 0000000000..ac447d7878 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.defaultannotated; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.Default; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Default.class, + PersonWithDefaultAnnotatedConstructor.class, + PersonDto.class, + SimpleDefaultAnnotatedConstructorMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class SimpleDefaultAnnotatedConstructorTest { + + @Test + public void mapDefault() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithDefaultAnnotatedConstructor target = SimpleDefaultAnnotatedConstructorMapper.INSTANCE.map( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + } + + @Test + public void mapWithConstants() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithDefaultAnnotatedConstructor target = + SimpleDefaultAnnotatedConstructorMapper.INSTANCE.mapWithConstants( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 25 ); + } + + @Test + public void mapWithExpressions() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonWithDefaultAnnotatedConstructor target = + SimpleDefaultAnnotatedConstructorMapper.INSTANCE.mapWithExpression( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 20 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousAmbiguousConstructorsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousAmbiguousConstructorsMapper.java new file mode 100644 index 0000000000..afa37ea77b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousAmbiguousConstructorsMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.PersonDto; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousAmbiguousConstructorsMapper { + + PersonWithMultipleConstructors map(PersonDto dto); + + class PersonWithMultipleConstructors { + + private final String name; + private final int age; + + public PersonWithMultipleConstructors(String name) { + this( name, -1 ); + } + + public PersonWithMultipleConstructors(String name, int age) { + this.name = name; + this.age = age; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorPropertiesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorPropertiesMapper.java new file mode 100644 index 0000000000..705421724e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorPropertiesMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.erroneous; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.test.constructor.ConstructorProperties; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousConstructorPropertiesMapper { + + PersonWithIncorrectConstructorProperties map(PersonDto dto); + + class PersonWithIncorrectConstructorProperties { + + private final String name; + private final int age; + + @ConstructorProperties({ "name" }) + public PersonWithIncorrectConstructorProperties(String name, int age) { + this.name = name; + this.age = age; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java new file mode 100644 index 0000000000..eac6188ab6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.erroneous; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.ConstructorProperties; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class ErroneousConstructorTest { + + @Test + @WithClasses({ + ErroneousAmbiguousConstructorsMapper.class, + PersonDto.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic( + type = ErroneousAmbiguousConstructorsMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "Ambiguous constructors found for creating org.mapstruct.ap.test.constructor.erroneous" + + ".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors. Either declare parameterless " + + "constructor or annotate the default constructor with an annotation named @Default." + ) + }) + public void shouldUseMultipleConstructors() { + } + + @Test + @WithClasses({ + ConstructorProperties.class, + ErroneousConstructorPropertiesMapper.class, + PersonDto.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic( + type = ErroneousConstructorPropertiesMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + message = "Incorrect @ConstructorProperties for org.mapstruct.ap.test.constructor.erroneous" + + ".ErroneousConstructorPropertiesMapper.PersonWithIncorrectConstructorProperties. The size of the " + + "@ConstructorProperties does not match the number of constructor parameters") + }) + public void shouldNotCompileIfConstructorPropertiesDoesNotMatch() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersMapper.java new file mode 100644 index 0000000000..02a6d9af64 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.mixed; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConstructorMixedWithSettersMapper { + + ConstructorMixedWithSettersMapper INSTANCE = Mappers.getMapper( ConstructorMixedWithSettersMapper.class ); + + PersonMixed map(PersonDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java new file mode 100644 index 0000000000..2c24e33cb5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.mixed; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + PersonMixed.class, + PersonDto.class, + ConstructorMixedWithSettersMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ConstructorMixedWithSettersTest { + + @Test + public void mapDefault() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + PersonMixed target = ConstructorMixedWithSettersMapper.INSTANCE.map( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + assertThat( target.getJob() ).isEqualTo( "Software Engineer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/PersonMixed.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/PersonMixed.java new file mode 100644 index 0000000000..deb79e84fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/PersonMixed.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.mixed; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class PersonMixed { + + private final String name; + private final int age; + private final String job; + private String city; + private String address; + private List children; + + public PersonMixed(String name, int age, String job) { + this.name = name; + this.age = age; + this.job = job; + } + + public String getName() { + return name; + } + + public void setName(String name) { + throw new RuntimeException( "Method is here only to verify that MapStruct won't use it" ); + } + + public int getAge() { + return age; + } + + public String getJob() { + return job; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntry.java new file mode 100644 index 0000000000..02a82ba8d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntry.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ArtistToChartEntry { + + ArtistToChartEntry MAPPER = Mappers.getMapper( ArtistToChartEntry.class ); + + @Mappings({ + @Mapping(target = "chartName", source = "chart.name"), + @Mapping(target = "songTitle", source = "song.title"), + @Mapping(target = "artistName", source = "song.artist.name"), + @Mapping(target = "recordedAt", source = "song.artist.label.studio.name"), + @Mapping(target = "city", source = "song.artist.label.studio.city"), + @Mapping(target = "position", source = "position") + }) + ChartEntry map(Chart chart, Song song, Integer position); + + @Mappings({ + @Mapping(target = "chartName", ignore = true), + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true) + }) + ChartEntry map(Song song); + + @Mappings({ + @Mapping(target = "chartName", source = "name"), + @Mapping(target = "songTitle", ignore = true), + @Mapping(target = "artistName", ignore = true), + @Mapping(target = "recordedAt", ignore = true), + @Mapping(target = "city", ignore = true), + @Mapping(target = "position", ignore = true) + }) + ChartEntry map(Chart name); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryComposedReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryComposedReverse.java new file mode 100644 index 0000000000..7fd9fbdb54 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryComposedReverse.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryComposed; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryLabel; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ArtistToChartEntryComposedReverse { + + public static final ArtistToChartEntryComposedReverse MAPPER = + Mappers.getMapper( ArtistToChartEntryComposedReverse.class ); + + @Mappings({ + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "label", source = "artist.label"), + @Mapping(target = "position", ignore = true), + @Mapping(target = "chartName", ignore = true ) + }) + abstract ChartEntryComposed mapForward(Song song); + + @Mappings({ + @Mapping(target = "name", source = "name"), + @Mapping(target = "recordedAt", source = "studio.name"), + @Mapping(target = "city", source = "studio.city") + }) + abstract ChartEntryLabel mapForward(Label label); + + @InheritInverseConfiguration + @Mapping(target = "positions", ignore = true) + abstract Song mapReverse(ChartEntryComposed ce); + + @InheritInverseConfiguration + abstract Label mapReverse(ChartEntryLabel label); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryConfig.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryConfig.java new file mode 100644 index 0000000000..c1d0d05228 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryConfig.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; + +/** + * + * @author Sjaak Derksen + */ +@MapperConfig( unmappedTargetPolicy = ReportingPolicy.ERROR ) +public interface ArtistToChartEntryConfig { + + @Mappings({ + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "chartName", ignore = true ) + }) + BaseChartEntry mapForwardConfig( Song song ); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryReverse.java new file mode 100644 index 0000000000..193d4ea6ec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryReverse.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ArtistToChartEntryReverse { + + public static final ArtistToChartEntryReverse MAPPER = Mappers.getMapper( ArtistToChartEntryReverse.class ); + + @Mappings({ + + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true), + @Mapping(target = "chartName", ignore = true ) + }) + abstract ChartEntry mapForward(Song song); + + @InheritInverseConfiguration + @Mapping(target = "positions", ignore = true) + abstract Song mapReverse(ChartEntry ce); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithConfigReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithConfigReverse.java new file mode 100644 index 0000000000..7c21104a6b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithConfigReverse.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithBase; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( config = ArtistToChartEntryConfig.class ) +public abstract class ArtistToChartEntryWithConfigReverse { + + public static final ArtistToChartEntryWithConfigReverse MAPPER = + Mappers.getMapper( ArtistToChartEntryWithConfigReverse.class ); + + @InheritConfiguration + @Mappings({ + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true) + }) + abstract ChartEntryWithBase mapForward(Song song); + + @InheritInverseConfiguration( name = "mapForward" ) + @Mapping(target = "positions", ignore = true) + abstract Song mapReverse(ChartEntryWithBase ce); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithFactoryReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithFactoryReverse.java new file mode 100644 index 0000000000..6583838673 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithFactoryReverse.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ArtistToChartEntryWithFactoryReverse { + + public static final ArtistToChartEntryWithFactoryReverse MAPPER + = Mappers.getMapper( ArtistToChartEntryWithFactoryReverse.class ); + + @Mappings({ + + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true), + @Mapping(target = "chartName", ignore = true) + }) + abstract ChartEntry mapForward(Song song); + + @InheritInverseConfiguration + @Mapping(target = "positions", ignore = true) + abstract Song mapReverse(ChartEntry ce); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithIgnoresReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithIgnoresReverse.java new file mode 100644 index 0000000000..4d1d35fbe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithIgnoresReverse.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ArtistToChartEntryWithIgnoresReverse { + + public static final ArtistToChartEntryWithIgnoresReverse MAPPER = + Mappers.getMapper( ArtistToChartEntryWithIgnoresReverse.class ); + + @Mappings({ + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistName", source = "artist.name"), + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true), + @Mapping(target = "chartName", ignore = true) + }) + abstract ChartEntry mapForward(Song song); + + @InheritInverseConfiguration + @Mappings({ + @Mapping(target = "positions", ignore = true), + @Mapping(target = "artist", ignore = true) + }) + abstract Song mapReverse(ChartEntry ce); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithMappingReverse.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithMappingReverse.java new file mode 100644 index 0000000000..b6b4cac803 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryWithMappingReverse.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithMapping; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ArtistToChartEntryWithMappingReverse { + + public static final ArtistToChartEntryWithMappingReverse MAPPER = + Mappers.getMapper( ArtistToChartEntryWithMappingReverse.class ); + + @Mappings({ + @Mapping(target = "songTitle", source = "title"), + @Mapping(target = "artistId", source = "artist.name"), + @Mapping(target = "recordedAt", source = "artist.label.studio.name"), + @Mapping(target = "city", source = "artist.label.studio.city"), + @Mapping(target = "position", ignore = true), + @Mapping(target = "chartName", ignore = true) + }) + abstract ChartEntryWithMapping mapForward(Song song); + + @InheritInverseConfiguration + @Mapping(target = "positions", ignore = true) + abstract Song mapReverse(ChartEntryWithMapping ce); + + int mapArtistToArtistId(String in) { + + if ( "The Beatles".equals( in ) ) { + return 1; + } + else { + return -1; + } + } + + String mapArtistIdToArtist(int in) { + + if ( in == 1 ) { + return "The Beatles"; + } + else { + return "Unknown"; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java new file mode 100644 index 0000000000..4fe43506ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java @@ -0,0 +1,132 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import java.util.Collections; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) +@IssueKey("73") +@RunWith(AnnotationProcessorTestRunner.class) +public class NestedSourcePropertiesConstructorTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ ArtistToChartEntry.class }) + public void shouldGenerateImplementationForPropertyNamesOnly() { + generatedSource.addComparisonToFixtureFor( ArtistToChartEntry.class ); + + Studio studio = new Studio( "Abbey Road", "London" ); + + Label label = new Label( "EMY", studio ); + + Artist artist = new Artist( "The Beatles", label ); + + Song song = new Song( artist, "A Hard Day's Night", Collections.emptyList() ); + + ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map( song ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + } + + @Test + @WithClasses({ ArtistToChartEntry.class }) + public void shouldGenerateImplementationForMultipleParam() { + + Studio studio = new Studio( "Abbey Road", "London" ); + + Label label = new Label( "EMY", studio ); + + Artist artist = new Artist( "The Beatles", label ); + + Song song = new Song( artist, "A Hard Day's Night", Collections.emptyList() ); + + Chart chart = new Chart( "record-sales", "Billboard", null ); + + ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map( chart, song, 1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isEqualTo( "Billboard" ); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 1 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + chartEntry = ArtistToChartEntry.MAPPER.map( null, song, 10 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 10 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + chartEntry = ArtistToChartEntry.MAPPER.map( chart, null, 5 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isNull(); + assertThat( chartEntry.getChartName() ).isEqualTo( "Billboard" ); + assertThat( chartEntry.getCity() ).isNull(); + assertThat( chartEntry.getPosition() ).isEqualTo( 5 ); + assertThat( chartEntry.getRecordedAt() ).isNull(); + assertThat( chartEntry.getSongTitle() ).isNull(); + + chartEntry = ArtistToChartEntry.MAPPER.map( chart, song, null ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isEqualTo( "Billboard" ); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + } + + @Test + @WithClasses({ ArtistToChartEntry.class }) + public void shouldPickPropertyNameOverParameterName() { + + Chart chart = new Chart( "record-sales", "Billboard", null ); + + ChartEntry chartEntry = ArtistToChartEntry.MAPPER.map( chart ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isNull(); + assertThat( chartEntry.getChartName() ).isEqualTo( "Billboard" ); + assertThat( chartEntry.getCity() ).isNull(); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isNull(); + assertThat( chartEntry.getSongTitle() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java new file mode 100644 index 0000000000..231a4fcad7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java @@ -0,0 +1,222 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryComposed; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryLabel; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithBase; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryWithMapping; +import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("73") +@WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) +@RunWith(AnnotationProcessorTestRunner.class) +public class ReversingNestedSourcePropertiesConstructorTest { + + @Test + @WithClasses({ ArtistToChartEntryReverse.class }) + public void shouldGenerateNestedReverse() { + + Song song1 = prepareSong(); + + ChartEntry chartEntry = ArtistToChartEntryReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNotNull(); + assertThat( song2.getArtist().getName() ).isEqualTo( "The Beatles" ); + assertThat( song2.getArtist().getLabel() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getName() ).isNull(); + assertThat( song2.getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getStudio().getCity() ).isEqualTo( "London" ); + assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); + } + + @Test + @WithClasses({ ArtistToChartEntryWithIgnoresReverse.class }) + public void shouldIgnoreEverytingBelowArtist() { + + Song song1 = prepareSong(); + + ChartEntry chartEntry = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryWithIgnoresReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNull(); + } + + @Test + @WithClasses({ ArtistToChartEntryWithFactoryReverse.class }) + public void shouldGenerateNestedReverseWithFactory() { + + Song song1 = prepareSong(); + + ChartEntry chartEntry = ArtistToChartEntryWithFactoryReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryWithFactoryReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNotNull(); + assertThat( song2.getArtist().getName() ).isEqualTo( "The Beatles" ); + assertThat( song2.getArtist().getLabel() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getName() ).isNull(); + assertThat( song2.getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getStudio().getCity() ).isEqualTo( "London" ); + assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); + + } + + @Test + @WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class }) + public void shouldGenerateNestedComposedReverse() { + + Song song1 = prepareSong(); + + ChartEntryComposed chartEntry = ArtistToChartEntryComposedReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getLabel().getName() ).isEqualTo( "EMY" ); + assertThat( chartEntry.getLabel().getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getLabel().getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryComposedReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNotNull(); + assertThat( song2.getArtist().getName() ).isEqualTo( "The Beatles" ); + assertThat( song2.getArtist().getLabel() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getName() ).isEqualTo( "EMY" ); + assertThat( song2.getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getStudio().getCity() ).isEqualTo( "London" ); + assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); + } + + @Test + @WithClasses({ ArtistToChartEntryWithMappingReverse.class, ChartEntryWithMapping.class }) + public void shouldGenerateNestedWithMappingReverse() { + + Song song1 = prepareSong(); + + ChartEntryWithMapping chartEntry = ArtistToChartEntryWithMappingReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistId() ).isEqualTo( 1 ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryWithMappingReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNotNull(); + assertThat( song2.getArtist().getName() ).isEqualTo( "The Beatles" ); + assertThat( song2.getArtist().getLabel() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getName() ).isNull(); + assertThat( song2.getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getStudio().getCity() ).isEqualTo( "London" ); + assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); + } + + @Test + @WithClasses({ + ArtistToChartEntryWithConfigReverse.class, + ArtistToChartEntryConfig.class, + BaseChartEntry.class, + ChartEntryWithBase.class + }) + public void shouldGenerateNestedWithConfigReverse() { + + Song song1 = prepareSong(); + + ChartEntryWithBase chartEntry = ArtistToChartEntryWithConfigReverse.MAPPER.mapForward( song1 ); + + assertThat( chartEntry ).isNotNull(); + assertThat( chartEntry.getArtistName() ).isEqualTo( "The Beatles" ); + assertThat( chartEntry.getChartName() ).isNull(); + assertThat( chartEntry.getCity() ).isEqualTo( "London" ); + assertThat( chartEntry.getPosition() ).isEqualTo( 0 ); + assertThat( chartEntry.getRecordedAt() ).isEqualTo( "Abbey Road" ); + assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); + + // and now in reverse + Song song2 = ArtistToChartEntryWithConfigReverse.MAPPER.mapReverse( chartEntry ); + + assertThat( song2 ).isNotNull(); + assertThat( song2.getArtist() ).isNotNull(); + assertThat( song2.getArtist().getName() ).isEqualTo( "The Beatles" ); + assertThat( song2.getArtist().getLabel() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getName() ).isNull(); + assertThat( song2.getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( song2.getArtist().getLabel().getStudio().getCity() ).isEqualTo( "London" ); + assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); + } + + private Song prepareSong() { + Studio studio = new Studio( "Abbey Road", "London" ); + + Label label = new Label( "EMY", studio ); + + Artist artist = new Artist( "The Beatles", label ); + + return new Song( artist, "A Hard Day's Night", Collections.emptyList() ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/AdderUsageObserver.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/AdderUsageObserver.java new file mode 100644 index 0000000000..ff21870b75 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/AdderUsageObserver.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Sjaak Derksen + */ +public class AdderUsageObserver { + + private AdderUsageObserver() { + } + + private static boolean used = false; + + public static boolean isUsed() { + return used; + } + + public static void setUsed(boolean used) { + AdderUsageObserver.used = used; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/BaseChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/BaseChartEntry.java new file mode 100644 index 0000000000..7b82c77b32 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/BaseChartEntry.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class BaseChartEntry { + + private final String chartName; + private final String songTitle; + private final String artistName; + + public BaseChartEntry(String chartName, String songTitle, String artistName) { + this.chartName = chartName; + this.songTitle = songTitle; + this.artistName = artistName; + } + + public String getChartName() { + return chartName; + } + + public String getSongTitle() { + return songTitle; + } + + public String getArtistName() { + return artistName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntry.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntry.java new file mode 100644 index 0000000000..36d7e95601 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntry.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class ChartEntry { + + private final String chartName; + private final String songTitle; + private final String artistName; + private final String recordedAt; + private final String city; + private final int position; + + public ChartEntry(String chartName, String songTitle, String artistName, String recordedAt, String city, + int position) { + this.chartName = chartName; + this.songTitle = songTitle; + this.artistName = artistName; + this.recordedAt = recordedAt; + this.city = city; + this.position = position; + } + + public String getChartName() { + return chartName; + } + + public String getSongTitle() { + return songTitle; + } + + public String getArtistName() { + return artistName; + } + + public String getRecordedAt() { + return recordedAt; + } + + public String getCity() { + return city; + } + + public int getPosition() { + return position; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryComposed.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryComposed.java new file mode 100644 index 0000000000..2543c70686 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryComposed.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class ChartEntryComposed { + + private String chartName; + private String songTitle; + private String artistName; + private ChartEntryLabel label; + private int position; + + public String getChartName() { + return chartName; + } + + public void setChartName(String chartName) { + this.chartName = chartName; + } + + public String getSongTitle() { + return songTitle; + } + + public void setSongTitle(String songTitle) { + this.songTitle = songTitle; + } + + public String getArtistName() { + return artistName; + } + + public void setArtistName(String artistName) { + this.artistName = artistName; + } + + public ChartEntryLabel getLabel() { + return label; + } + + public void setLabel(ChartEntryLabel label) { + this.label = label; + } + + public int getPosition() { + return position; + } + + public void setPosition(int position) { + this.position = position; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryLabel.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryLabel.java new file mode 100644 index 0000000000..b639b97b35 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryLabel.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class ChartEntryLabel { + + private final String name; + private final String city; + private final String recordedAt; + + public ChartEntryLabel(String name, String city, String recordedAt) { + this.name = name; + this.city = city; + this.recordedAt = recordedAt; + } + + public String getName() { + return name; + } + + public String getCity() { + return city; + } + + public String getRecordedAt() { + return recordedAt; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithBase.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithBase.java new file mode 100644 index 0000000000..4855080fb3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithBase.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class ChartEntryWithBase extends BaseChartEntry { + + private final String recordedAt; + private final String city; + private final int position; + + public ChartEntryWithBase(String chartName, String songTitle, String artistName, String recordedAt, + String city, int position) { + super( chartName, songTitle, artistName ); + this.recordedAt = recordedAt; + this.city = city; + this.position = position; + } + + public String getRecordedAt() { + return recordedAt; + } + + public String getCity() { + return city; + } + + public int getPosition() { + return position; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithMapping.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithMapping.java new file mode 100644 index 0000000000..f7ba366e17 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartEntryWithMapping.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +/** + * @author Filip Hrisafov + */ +public class ChartEntryWithMapping { + + private final String chartName; + private final String songTitle; + private final int artistId; + private final String recordedAt; + private final String city; + private final int position; + + public ChartEntryWithMapping(String chartName, String songTitle, int artistId, String recordedAt, + String city, int position) { + this.chartName = chartName; + this.songTitle = songTitle; + this.artistId = artistId; + this.recordedAt = recordedAt; + this.city = city; + this.position = position; + } + + public String getChartName() { + return chartName; + } + + public String getSongTitle() { + return songTitle; + } + + public int getArtistId() { + return artistId; + } + + public String getRecordedAt() { + return recordedAt; + } + + public String getCity() { + return city; + } + + public int getPosition() { + return position; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartPositions.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartPositions.java new file mode 100644 index 0000000000..a14e04ac76 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/_target/ChartPositions.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource._target; + +import java.util.Collections; +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class ChartPositions { + + private final List positions; + + public ChartPositions(List positions) { + this.positions = positions; + } + + public List getPositions() { + return Collections.unmodifiableList( positions ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Artist.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Artist.java new file mode 100644 index 0000000000..def4ac697f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Artist.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource.source; + +/** + * @author Filip Hrisafov + */ +public class Artist { + + private final String name; + private final Label label; + + public Artist(String name, Label label) { + this.name = name; + this.label = label; + } + + public String getName() { + return name; + } + + public Label getLabel() { + return label; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Chart.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Chart.java new file mode 100644 index 0000000000..064129fc06 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Chart.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource.source; + +/** + * @author Filip Hrisafov + */ +public class Chart { + + private final String type; + private final String name; + private final Song song; + + public Chart(String type, String name, Song song) { + this.type = type; + this.name = name; + this.song = song; + } + + public String getType() { + return type; + } + + public String getName() { + return name; + } + + public Song getSong() { + return song; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Label.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Label.java new file mode 100644 index 0000000000..6c2a15bbfb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Label.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource.source; + +/** + * @author Filip Hrisafov + */ +public class Label { + + private final String name; + private final Studio studio; + + public Label(String name, Studio studio) { + this.name = name; + this.studio = studio; + } + + public String getName() { + return name; + } + + public Studio getStudio() { + return studio; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Song.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Song.java new file mode 100644 index 0000000000..ac6ce20104 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Song.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource.source; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Song { + + private final Artist artist; + private final String title; + private final List positions; + + public Song(Artist artist, String title, List positions) { + this.artist = artist; + this.title = title; + this.positions = positions; + } + + public Artist getArtist() { + return artist; + } + + public String getTitle() { + return title; + } + + public List getPositions() { + return positions; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Studio.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Studio.java new file mode 100644 index 0000000000..db7bfd7389 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/source/Studio.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource.source; + +/** + * @author Filip Hrisafov + */ +public class Studio { + + private final String name; + private final String city; + + public Studio(String name, String city) { + this.name = name; + this.city = city; + } + + public String getName() { + return name; + } + + public String getCity() { + return city; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtist.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtist.java new file mode 100644 index 0000000000..9c1946fa26 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtist.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedtarget; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public abstract class ChartEntryToArtist { + + public static final ChartEntryToArtist MAPPER = Mappers.getMapper( ChartEntryToArtist.class ); + + @Mappings({ + @Mapping(target = "type", ignore = true), + @Mapping(target = "name", source = "chartName"), + @Mapping(target = "song.title", source = "songTitle"), + @Mapping(target = "song.artist.name", source = "artistName"), + @Mapping(target = "song.artist.label.studio.name", source = "recordedAt"), + @Mapping(target = "song.artist.label.studio.city", source = "city"), + @Mapping(target = "song.positions", source = "position") + }) + public abstract Chart map(ChartEntry chartEntry); + + @InheritInverseConfiguration + public abstract ChartEntry map(Chart chart); + + protected List mapPosition(Integer in) { + if ( in != null ) { + return new ArrayList<>( Arrays.asList( in ) ); + } + else { + return new ArrayList<>(); + } + } + + protected Integer mapPosition(List in) { + if ( in != null && !in.isEmpty() ) { + return in.get( 0 ); + } + else { + return null; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java new file mode 100644 index 0000000000..78d113a8c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java @@ -0,0 +1,98 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedtarget; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@WithClasses({ + Song.class, + Artist.class, + Chart.class, + Label.class, + Studio.class, + ChartEntry.class, + ChartEntryToArtist.class, +}) +@IssueKey("73") +@RunWith(AnnotationProcessorTestRunner.class) +public class NestedProductPropertiesConstructorTest { + + @Rule + public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + ChartEntryToArtist.class + ); + + @Test + public void shouldMapNestedTarget() { + + ChartEntry chartEntry = new ChartEntry( + "US Billboard Hot Rock Songs", + "Purple Rain", + "Prince", + "Live, First Avenue, Minneapolis", + "Minneapolis", + 1 + ); + + Chart result = ChartEntryToArtist.MAPPER.map( chartEntry ); + + assertThat( result.getName() ).isEqualTo( "US Billboard Hot Rock Songs" ); + assertThat( result.getSong() ).isNotNull(); + assertThat( result.getSong().getArtist() ).isNotNull(); + assertThat( result.getSong().getTitle() ).isEqualTo( "Purple Rain" ); + assertThat( result.getSong().getArtist().getName() ).isEqualTo( "Prince" ); + assertThat( result.getSong().getArtist().getLabel() ).isNotNull(); + assertThat( result.getSong().getArtist().getLabel().getStudio() ).isNotNull(); + assertThat( result.getSong().getArtist().getLabel().getStudio().getName() ) + .isEqualTo( "Live, First Avenue, Minneapolis" ); + assertThat( result.getSong().getArtist().getLabel().getStudio().getCity() ) + .isEqualTo( "Minneapolis" ); + assertThat( result.getSong().getPositions() ).hasSize( 1 ); + assertThat( result.getSong().getPositions().get( 0 ) ).isEqualTo( 1 ); + + } + + @Test + public void shouldReverseNestedTarget() { + + ChartEntry chartEntry = new ChartEntry( + "US Billboard Hot Rock Songs", + "Purple Rain", + "Prince", + "Live, First Avenue, Minneapolis", + "Minneapolis", + 1 + ); + + Chart chart = ChartEntryToArtist.MAPPER.map( chartEntry ); + ChartEntry result = ChartEntryToArtist.MAPPER.map( chart ); + + assertThat( result ).isNotNull(); + assertThat( result.getArtistName() ).isEqualTo( "Prince" ); + assertThat( result.getChartName() ).isEqualTo( "US Billboard Hot Rock Songs" ); + assertThat( result.getCity() ).isEqualTo( "Minneapolis" ); + assertThat( result.getPosition() ).isEqualTo( 1 ); + assertThat( result.getRecordedAt() ).isEqualTo( "Live, First Avenue, Minneapolis" ); + assertThat( result.getSongTitle() ).isEqualTo( "Purple Rain" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorMapper.java new file mode 100644 index 0000000000..2e162d2f23 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.simple; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.constructor.Person; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleConstructorMapper { + + SimpleConstructorMapper INSTANCE = Mappers.getMapper( SimpleConstructorMapper.class ); + + Person map(PersonDto dto); + + @Mapping(target = "age", constant = "25") + @Mapping(target = "job", constant = "Software Developer") + Person mapWithConstants(PersonDto dto); + + @Mapping(target = "age", expression = "java(25 - 5)") + @Mapping(target = "job", expression = "java(\"Software Developer\".toLowerCase())") + Person mapWithExpression(PersonDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java new file mode 100644 index 0000000000..e24abb84b1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java @@ -0,0 +1,89 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.simple; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.Person; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Person.class, + PersonDto.class, + SimpleConstructorMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class SimpleConstructorTest { + + @Test + public void mapDefault() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + Person target = SimpleConstructorMapper.INSTANCE.map( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + assertThat( target.getJob() ).isEqualTo( "Software Engineer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } + + @Test + public void mapWithConstants() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + Person target = SimpleConstructorMapper.INSTANCE.mapWithConstants( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 25 ); + assertThat( target.getJob() ).isEqualTo( "Software Developer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } + + @Test + public void mapWithExpressions() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + source.setJob( "Software Engineer" ); + source.setCity( "Zurich" ); + source.setAddress( "Plaza 1" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + + Person target = SimpleConstructorMapper.INSTANCE.mapWithExpression( source ); + + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 20 ); + assertThat( target.getJob() ).isEqualTo( "software developer" ); + assertThat( target.getCity() ).isEqualTo( "Zurich" ); + assertThat( target.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/Order.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/Order.java new file mode 100644 index 0000000000..18fe9b1015 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/Order.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.unmapped; + +import java.util.Date; + +/** + * @author Filip Hrisafov + */ +public class Order { + + private final String name; + private final Date time; + + public Order(String name, Date time) { + this.name = name; + this.time = time; + } + + public String getName() { + return name; + } + + public Date getTime() { + return time; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/OrderDto.java new file mode 100644 index 0000000000..259cf8973d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/OrderDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.unmapped; + +/** + * @author Filip Hrisafov + */ +public class OrderDto { + + private final String name; + + public OrderDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorMapper.java new file mode 100644 index 0000000000..8fcede06f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.unmapped; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface UnmappedConstructorMapper { + + UnmappedConstructorMapper INSTANCE = Mappers.getMapper( UnmappedConstructorMapper.class ); + + Order map(OrderDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java new file mode 100644 index 0000000000..7a7f859041 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.unmapped; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Order.class, + OrderDto.class, + UnmappedConstructorMapper.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class UnmappedConstructorTest { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = UnmappedConstructorMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 19, + message = "Unmapped target property: \"time\".") + }) + public void shouldGenerateCompilableCodeForUnmappedConstructorProperties() { + OrderDto source = new OrderDto( "truck" ); + + Order target = UnmappedConstructorMapper.INSTANCE.map( source ); + + assertThat( target.getName() ).isEqualTo( "truck" ); + assertThat( target.getTime() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 561b53effd..94993e4a66 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -36,12 +36,7 @@ public class AmbiguousAnnotatedFactoryTest { ".ambiguousannotatedfactorymethod.Foo foo), org.mapstruct.ap.test.erroneous" + ".ambiguousannotatedfactorymethod.Bar org.mapstruct.ap.test.erroneous" + ".ambiguousannotatedfactorymethod.AmbiguousBarFactory.createBar(org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Foo foo)."), - @Diagnostic(type = SourceTargetMapperAndBarFactory.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 22, - message = "org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod.Bar does not have an " + - "accessible parameterless constructor.") + ".ambiguousannotatedfactorymethod.Foo foo).") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index 82886eb038..e4e9ff81cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -37,12 +37,7 @@ public class FactoryTest { message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + ".ambiguousfactorymethod.Bar: org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar " + "createBar(), org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar org.mapstruct.ap.test" + - ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar()."), - @Diagnostic(type = SourceTargetMapperAndBarFactory.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 22, - message = "org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar does not have an accessible " + - "parameterless constructor.") + ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar().") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java index 5ed5ee57d0..5f8be28763 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryErroneous.java @@ -28,9 +28,22 @@ public interface ArtistToChartEntryErroneous { @Mapping(target = "city", ignore = true), @Mapping(target = "position", source = "position") } ) - ChartEntry forward(Integer position); + ChartEntry forward(ChartPosition position); @InheritInverseConfiguration - Integer reverse(ChartEntry position); + ChartPosition reverse(ChartEntry position); + + class ChartPosition { + + private final int position; + + private ChartPosition(int position) { + this.position = position; + } + + public int getPosition() { + return position; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 1d61b6e69a..f9d5b11eed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -164,17 +164,18 @@ public void shouldUseGetAsTargetAccessor() { } @Test - @IssueKey( "838" ) + @IssueKey("838") @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic( type = ArtistToChartEntryErroneous.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 34, - message = "java.lang.Integer does not have an accessible parameterless constructor." ) - } + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ArtistToChartEntryErroneous.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 34, + message = "org.mapstruct.ap.test.nestedsourceproperties.ArtistToChartEntryErroneous.ChartPosition " + + "does not have an accessible constructor.") + } ) @WithClasses({ ArtistToChartEntryErroneous.class }) - public void inverseShouldRaiseErrorForEmptyConstructor() { + public void inverseShouldRaiseErrorForNotAccessibleConstructor() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Citrus.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Citrus.java new file mode 100644 index 0000000000..5dd69a83f9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/Citrus.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +/** + * @author Filip Hrisafov + */ +public class Citrus extends Fruit implements IsFruit { + + public Citrus(String type) { + super( type ); + } + + @Override + public void setType(String type) { + throw new RuntimeException( "Not allowed to change citrus type" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoAccessibleConstructorMapper.java similarity index 71% rename from processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoAccessibleConstructorMapper.java index 0e8cb1138d..40612fcf3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoEmptyConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousResultTypeNoAccessibleConstructorMapper.java @@ -13,9 +13,16 @@ * @author Filip Hrisafov */ @Mapper -public interface ErroneousResultTypeNoEmptyConstructorMapper { +public interface ErroneousResultTypeNoAccessibleConstructorMapper { @BeanMapping(resultType = Banana.class) @Mapping(target = "type", ignore = true) Fruit map(FruitDto source); + + class Banana extends Fruit { + + private Banana(String type) { + super( type ); + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index efdea3c0eb..5cd415e56e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -21,9 +21,9 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** - * * @author Sjaak Derksen */ @IssueKey("385") @@ -48,12 +48,7 @@ public class InheritanceSelectionTest { message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.selection.resulttype" + ".Fruit: org.mapstruct.ap.test.selection.resulttype.Apple org.mapstruct.ap.test.selection" + ".resulttype.ConflictingFruitFactory.createApple(), org.mapstruct.ap.test.selection.resulttype" + - ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana()."), - @Diagnostic(type = ErroneousFruitMapper.class, - kind = Kind.ERROR, - line = 23, - message = "org.mapstruct.ap.test.selection.resulttype.Fruit does not have an accessible parameterless" + - " constructor.") + ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana().") } ) public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() { @@ -61,22 +56,22 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() @IssueKey("1283") @Test - @WithClasses({ ErroneousResultTypeNoEmptyConstructorMapper.class, Banana.class }) + @WithClasses({ ErroneousResultTypeNoAccessibleConstructorMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = ErroneousResultTypeNoEmptyConstructorMapper.class, + @Diagnostic(type = ErroneousResultTypeNoAccessibleConstructorMapper.class, kind = Kind.ERROR, line = 18, - message = "org.mapstruct.ap.test.selection.resulttype.Banana does not have an accessible " + - "parameterless constructor.") + message = "org.mapstruct.ap.test.selection.resulttype" + + ".ErroneousResultTypeNoAccessibleConstructorMapper.Banana does not have an accessible constructor.") } ) - public void testResultTypeHasNoSuitableEmptyConstructor() { + public void testResultTypeHasNoSuitableAccessibleConstructor() { } @Test - @WithClasses( { ConflictingFruitFactory.class, ResultTypeSelectingFruitMapper.class, Banana.class } ) + @WithClasses({ ConflictingFruitFactory.class, ResultTypeSelectingFruitMapper.class, Banana.class }) public void testResultTypeBasedFactoryMethodSelection() { FruitDto fruitDto = new FruitDto( null ); @@ -88,7 +83,7 @@ public void testResultTypeBasedFactoryMethodSelection() { @Test @IssueKey("434") - @WithClasses( { ResultTypeConstructingFruitMapper.class } ) + @WithClasses({ ResultTypeConstructingFruitMapper.class }) public void testResultTypeBasedConstructionOfResult() { FruitDto fruitDto = new FruitDto( null ); @@ -99,7 +94,7 @@ public void testResultTypeBasedConstructionOfResult() { @Test @IssueKey("657") - @WithClasses( { ResultTypeConstructingFruitInterfaceMapper.class } ) + @WithClasses({ ResultTypeConstructingFruitInterfaceMapper.class }) public void testResultTypeBasedConstructionOfResultForInterface() { FruitDto fruitDto = new FruitDto( null ); @@ -143,7 +138,7 @@ public void testResultTypeBasedConstructionOfResultNonAssignable() { @Test @IssueKey("433") - @WithClasses( { + @WithClasses({ FruitFamilyMapper.class, GoldenDeliciousDto.class, GoldenDelicious.class, @@ -151,11 +146,11 @@ public void testResultTypeBasedConstructionOfResultNonAssignable() { AppleFamilyDto.class, AppleFactory.class, Banana.class - } ) + }) public void testShouldSelectResultTypeInCaseOfAmbiguity() { AppleFamilyDto appleFamilyDto = new AppleFamilyDto(); - appleFamilyDto.setApple( new AppleDto("AppleDto") ); + appleFamilyDto.setApple( new AppleDto( "AppleDto" ) ); AppleFamily result = FruitFamilyMapper.INSTANCE.map( appleFamilyDto ); assertThat( result ).isNotNull(); @@ -167,7 +162,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguity() { @Test @IssueKey("433") - @WithClasses( { + @WithClasses({ FruitFamilyMapper.class, GoldenDeliciousDto.class, GoldenDelicious.class, @@ -175,7 +170,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguity() { AppleFamilyDto.class, AppleFactory.class, Banana.class - } ) + }) public void testShouldSelectResultTypeInCaseOfAmbiguityForIterable() { List source = Arrays.asList( new AppleDto( "AppleDto" ) ); @@ -189,7 +184,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForIterable() { @Test @IssueKey("433") - @WithClasses( { + @WithClasses({ FruitFamilyMapper.class, GoldenDeliciousDto.class, GoldenDelicious.class, @@ -197,7 +192,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForIterable() { AppleFamilyDto.class, AppleFactory.class, Banana.class - } ) + }) public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() { Map source = new HashMap(); @@ -214,4 +209,38 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() { assertThat( entry.getValue().getType() ).isEqualTo( "AppleDto" ); } + + @Test + @IssueKey("73") + @WithClasses({ + Citrus.class, + ResultTypeWithConstructorConstructingFruitInterfaceMapper.class + }) + public void testShouldUseConstructorFromResultTypeForInterface() { + FruitDto orange = new FruitDto( "orange" ); + IsFruit citrus = ResultTypeWithConstructorConstructingFruitInterfaceMapper.INSTANCE.map( orange ); + + assertThat( citrus ).isInstanceOf( Citrus.class ); + assertThat( citrus.getType() ).isEqualTo( "orange" ); + assertThatThrownBy( () -> citrus.setType( "lemon" ) ) + .hasMessage( "Not allowed to change citrus type" ); + assertThat( citrus.getType() ).isEqualTo( "orange" ); + } + + @Test + @IssueKey("73") + @WithClasses({ + Citrus.class, + ResultTypeWithConstructorConstructingFruitInterfaceMapper.class + }) + public void testShouldUseConstructorFromResultType() { + FruitDto lemon = new FruitDto( "lemon" ); + IsFruit citrus = ResultTypeWithConstructorConstructingFruitInterfaceMapper.INSTANCE.map( lemon ); + + assertThat( citrus ).isInstanceOf( Citrus.class ); + assertThat( citrus.getType() ).isEqualTo( "lemon" ); + assertThatThrownBy( () -> citrus.setType( "orange" ) ) + .hasMessage( "Not allowed to change citrus type" ); + assertThat( citrus.getType() ).isEqualTo( "lemon" ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitInterfaceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitInterfaceMapper.java new file mode 100644 index 0000000000..b1670772e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitInterfaceMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ResultTypeWithConstructorConstructingFruitInterfaceMapper { + + ResultTypeWithConstructorConstructingFruitInterfaceMapper INSTANCE = Mappers.getMapper( + ResultTypeWithConstructorConstructingFruitInterfaceMapper.class ); + + @BeanMapping(resultType = Citrus.class) + IsFruit map(FruitDto source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitMapper.java new file mode 100644 index 0000000000..7448cbb7ac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ResultTypeWithConstructorConstructingFruitMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ResultTypeWithConstructorConstructingFruitMapper { + + ResultTypeWithConstructorConstructingFruitMapper INSTANCE = Mappers.getMapper( + ResultTypeWithConstructorConstructingFruitMapper.class ); + + @BeanMapping(resultType = Citrus.class) + Fruit map(FruitDto source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java index 81eecea982..f57e4c95a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java @@ -34,4 +34,11 @@ public interface ErroneousOrganizationMapper2 { }) DepartmentEntity toDepartmentEntity(DepartmentDto dto); + class DepartmentEntity extends org.mapstruct.ap.test.updatemethods.DepartmentEntity { + + private DepartmentEntity() { + super( null ); + } + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index f04ddf338d..1b93d04a53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -175,8 +175,8 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35, - message = "org.mapstruct.ap.test.updatemethods.DepartmentEntity does not have an accessible " + - "parameterless constructor.") + message = "org.mapstruct.ap.test.updatemethods.ErroneousOrganizationMapper2.DepartmentEntity does not" + + " have an accessible constructor.") }) public void testShouldFailOnConstantMappingNoPropertyGetter() { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index e8c09bec98..59916e9818 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -308,9 +308,11 @@ private void assertDiagnostics(List actualDiagnostics, assertThat( actual.getLine() ).isIn( expected.getLine(), expected.getAlternativeLine() ); } else if ( expected.getLine() != null ) { - assertThat( actual.getLine() ).isEqualTo( expected.getLine() ); + assertThat( actual.getLine() ).as( actual.getMessage() ).isEqualTo( expected.getLine() ); } - assertThat( actual.getKind() ).isEqualTo( expected.getKind() ); + assertThat( actual.getKind() ) + .as( actual.getMessage() ) + .isEqualTo( expected.getKind() ); if ( expected.getMessage() != null && !expected.getMessage().isEmpty() ) { assertThat( actual.getMessage() ).describedAs( String.format( diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java new file mode 100644 index 0000000000..bd8c81a5db --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java @@ -0,0 +1,170 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedsource; + +import javax.annotation.processing.Generated; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-04-19T11:28:54+0200", + comments = "version: , compiler: javac, environment: Java 14.0.1 (Oracle Corporation)" +) +public class ArtistToChartEntryImpl implements ArtistToChartEntry { + + @Override + public ChartEntry map(Chart chart, Song song, Integer position) { + if ( chart == null && song == null && position == null ) { + return null; + } + + String chartName; + if ( chart != null ) { + chartName = chart.getName(); + } + else { + chartName = null; + } + String songTitle; + String artistName; + String recordedAt; + String city; + if ( song != null ) { + songTitle = song.getTitle(); + artistName = songArtistName( song ); + recordedAt = songArtistLabelStudioName( song ); + city = songArtistLabelStudioCity( song ); + } + else { + songTitle = null; + artistName = null; + recordedAt = null; + city = null; + } + int position1; + if ( position != null ) { + position1 = position; + } + else { + position1 = 0; + } + + ChartEntry chartEntry = new ChartEntry( chartName, songTitle, artistName, recordedAt, city, position1 ); + + return chartEntry; + } + + @Override + public ChartEntry map(Song song) { + if ( song == null ) { + return null; + } + + String songTitle; + String artistName; + String recordedAt; + String city; + + songTitle = song.getTitle(); + artistName = songArtistName( song ); + recordedAt = songArtistLabelStudioName( song ); + city = songArtistLabelStudioCity( song ); + + String chartName = null; + int position = 0; + + ChartEntry chartEntry = new ChartEntry( chartName, songTitle, artistName, recordedAt, city, position ); + + return chartEntry; + } + + @Override + public ChartEntry map(Chart name) { + if ( name == null ) { + return null; + } + + String chartName; + + chartName = name.getName(); + + String songTitle = null; + String artistName = null; + String recordedAt = null; + String city = null; + int position = 0; + + ChartEntry chartEntry = new ChartEntry( chartName, songTitle, artistName, recordedAt, city, position ); + + return chartEntry; + } + + private String songArtistName(Song song) { + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + String name = artist.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String songArtistLabelStudioName(Song song) { + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String name = studio.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String songArtistLabelStudioCity(Song song) { + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java new file mode 100644 index 0000000000..f5deb649be --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java @@ -0,0 +1,236 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.nestedtarget; + +import java.util.List; +import javax.annotation.processing.Generated; +import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; +import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; +import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; +import org.mapstruct.ap.test.constructor.nestedsource.source.Label; +import org.mapstruct.ap.test.constructor.nestedsource.source.Song; +import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-04-19T14:54:28+0200", + comments = "version: , compiler: javac, environment: Java 14.0.1 (Oracle Corporation)" +) +public class ChartEntryToArtistImpl extends ChartEntryToArtist { + + @Override + public Chart map(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Song song; + String name; + + song = chartEntryToSong( chartEntry ); + name = chartEntry.getChartName(); + + String type = null; + + Chart chart = new Chart( type, name, song ); + + return chart; + } + + @Override + public ChartEntry map(Chart chart) { + if ( chart == null ) { + return null; + } + + String chartName; + String songTitle; + String artistName; + String recordedAt; + String city; + int position; + + chartName = chart.getName(); + songTitle = chartSongTitle( chart ); + artistName = chartSongArtistName( chart ); + recordedAt = chartSongArtistLabelStudioName( chart ); + city = chartSongArtistLabelStudioCity( chart ); + position = mapPosition( chartSongPositions( chart ) ); + + ChartEntry chartEntry = new ChartEntry( chartName, songTitle, artistName, recordedAt, city, position ); + + return chartEntry; + } + + protected Studio chartEntryToStudio(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + String name; + String city; + + name = chartEntry.getRecordedAt(); + city = chartEntry.getCity(); + + Studio studio = new Studio( name, city ); + + return studio; + } + + protected Label chartEntryToLabel(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Studio studio; + + studio = chartEntryToStudio( chartEntry ); + + String name = null; + + Label label = new Label( name, studio ); + + return label; + } + + protected Artist chartEntryToArtist(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Label label; + String name; + + label = chartEntryToLabel( chartEntry ); + name = chartEntry.getArtistName(); + + Artist artist = new Artist( name, label ); + + return artist; + } + + protected Song chartEntryToSong(ChartEntry chartEntry) { + if ( chartEntry == null ) { + return null; + } + + Artist artist; + String title; + List positions; + + artist = chartEntryToArtist( chartEntry ); + title = chartEntry.getSongTitle(); + positions = mapPosition( chartEntry.getPosition() ); + + Song song = new Song( artist, title, positions ); + + return song; + } + + private String chartSongTitle(Chart chart) { + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + String title = song.getTitle(); + if ( title == null ) { + return null; + } + return title; + } + + private String chartSongArtistName(Chart chart) { + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + String name = artist.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String chartSongArtistLabelStudioName(Chart chart) { + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String name = studio.getName(); + if ( name == null ) { + return null; + } + return name; + } + + private String chartSongArtistLabelStudioCity(Chart chart) { + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + Artist artist = song.getArtist(); + if ( artist == null ) { + return null; + } + Label label = artist.getLabel(); + if ( label == null ) { + return null; + } + Studio studio = label.getStudio(); + if ( studio == null ) { + return null; + } + String city = studio.getCity(); + if ( city == null ) { + return null; + } + return city; + } + + private List chartSongPositions(Chart chart) { + if ( chart == null ) { + return null; + } + Song song = chart.getSong(); + if ( song == null ) { + return null; + } + List positions = song.getPositions(); + if ( positions == null ) { + return null; + } + return positions; + } +} From 42e0ec395b2cb7b4042dce75aad52476e90ece6d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 May 2020 12:17:36 +0200 Subject: [PATCH 0459/1006] Add dedicated action for Java EA builds and update main CI to use only 11, 13 and 14 --- .github/workflows/java-ea.yml | 21 +++++++++++++++++++++ .github/workflows/main.yml | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/java-ea.yml diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml new file mode 100644 index 0000000000..c20151eccd --- /dev/null +++ b/.github/workflows/java-ea.yml @@ -0,0 +1,21 @@ +name: Java EA + +on: [push] + +jobs: + test_jdk_ea: + strategy: + fail-fast: false + matrix: + java: [15-ea] + name: 'Linux JDK ${{ matrix.java }}' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v2 + - name: 'Set up JDK' + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: 'Test' + run: ./mvnw -V -B --no-transfer-progress install -DskipDistribution=true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5596cadad9..d1f65d18f2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - java: [11, 12, 13, 14-ea, 15-ea] + java: [11, 13, 14] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: From f7c1182ae6a14f6cb716b4af01dd0cdf1bad4d46 Mon Sep 17 00:00:00 2001 From: Gunnar Morling Date: Sun, 17 May 2020 13:27:32 +0200 Subject: [PATCH 0460/1006] Updating my developer URL --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 3efe0ad8fb..5da1dfcbc3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -51,7 +51,7 @@ gunnarmorling Gunnar Morling gunnar@mapstruct.org - http://www.gunnarmorling.de/ + https://www.morling.dev/ From 73a79cf0095e7fbbe11fa85fe24c26e2f73bb889 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 May 2020 12:08:00 +0200 Subject: [PATCH 0461/1006] #1857 Use flatten-maven-plugin to remove test dependencies from released pom For some reason when using annotationProcessorPaths IntelliJ includes the provided and test scoped dependencies on the annotation processor paths. With this change there would be no test dependencies that IntelliJ can add. --- .gitignore | 1 + parent/pom.xml | 34 ++++++++++++++++++++++++++++++++++ processor/pom.xml | 16 ++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/.gitignore b/.gitignore index 0363e0707e..a33f0014ee 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ test-output # Misc. .DS_Store checkstyle.cache +.flattened-pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 5da1dfcbc3..3e78dcfb84 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -578,6 +578,11 @@
      + + org.codehaus.mojo + flatten-maven-plugin + 1.2.2 + @@ -614,6 +619,7 @@ mvnw* **/*.asciidoc **/binding.xjb + **/*.flattened-pom.xml SLASHSTAR_STYLE @@ -702,6 +708,34 @@
      + + org.codehaus.mojo + flatten-maven-plugin + + + + flatten + package + + flatten + + + true + ossrh + + expand + + + + + flatten-clean + clean + + clean + + + + diff --git a/processor/pom.xml b/processor/pom.xml index dfe9bdbe69..c047301268 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -209,6 +209,21 @@
      + + + org.codehaus.mojo + flatten-maven-plugin + + + + flatten + package + + flatten + + + + org.apache.maven.plugins maven-dependency-plugin @@ -334,6 +349,7 @@ jaxb-api 2.3.1 provided + true From b5fe96c9da4504693db73782b88ecb4fff65c0bc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 May 2020 18:46:33 +0200 Subject: [PATCH 0462/1006] Add myself as developer --- parent/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/parent/pom.xml b/parent/pom.xml index 3e78dcfb84..b26cf8683d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -53,6 +53,11 @@ gunnar@mapstruct.org https://www.morling.dev/ + + filiphr + Filip Hrisafov + https://github.com/filiphr/ + From 7b5a54971f9b9695a88b9d95dd9eadec42da5a19 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 18 May 2020 07:17:30 +0200 Subject: [PATCH 0463/1006] Add EnumTransformationStrategy SPI (#2089) Add a new custom EnumTransformationStrategy SPI which can be used for providing custom way of name based mapping for enums. Add 4 out of the box transformation strategies: * prefix - add a prefix to the name based enum mapping * stripPrefix - remove a prefix from the name based enum mapping * suffix - add a suffix to the name based enum mapping * stripSuffix - remove a suffix from the name based enum mapping This can be achieved by using the new `EnumMapping` e.g. Add suffix `_TYPE` to all enums: `@EnumMapping(nameTransformationStrategy = "suffix", configuration = "_TYPE")` With this it would be possible to achieve what is needed in #796, #1220, #1789. --- .../main/java/org/mapstruct/EnumMapping.java | 123 ++++++++++++++++++ .../java/org/mapstruct/MappingConstants.java | 30 +++++ .../chapter-13-using-mapstruct-spi.asciidoc | 16 +++ .../chapter-8-mapping-values.asciidoc | 103 +++++++++++++++ .../ap/internal/gem/GemGenerator.java | 2 + .../ap/internal/gem/MappingConstantsGem.java | 8 ++ .../internal/model/AbstractBaseBuilder.java | 1 + .../internal/model/MappingBuilderContext.java | 10 ++ .../ap/internal/model/ValueMappingMethod.java | 111 ++++++++++++++-- .../model/source/EnumMappingOptions.java | 99 ++++++++++++++ .../model/source/MappingMethodOptions.java | 23 ++++ .../internal/model/source/SourceMethod.java | 17 ++- .../DefaultModelElementProcessorContext.java | 8 ++ .../processor/MapperCreationProcessor.java | 7 +- .../processor/MethodRetrievalProcessor.java | 13 ++ .../processor/ModelElementProcessor.java | 4 + .../util/AnnotationProcessorContext.java | 31 +++++ .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/spi/EnumTransformationStrategy.java | 44 +++++++ .../spi/PrefixEnumTransformationStrategy.java | 22 ++++ ...StripPrefixEnumTransformationStrategy.java | 25 ++++ ...StripSuffixEnumTransformationStrategy.java | 25 ++++ .../spi/SuffixEnumTransformationStrategy.java | 22 ++++ ...apstruct.ap.spi.EnumTransformationStrategy | 8 ++ .../mapstruct/ap/test/gem/ConstantTest.java | 6 + .../test/value/enum2string/OrderMapper.java | 2 + .../CheeseEnumToStringPrefixMapper.java | 34 +++++ .../CheeseEnumToStringSuffixMapper.java | 36 +++++ .../CheesePrefixMapper.java | 33 +++++ .../CheeseSuffixMapper.java | 36 +++++ .../value/nametransformation/CheeseType.java | 15 +++ .../CheeseTypeCustomSuffix.java | 15 +++ .../CheeseTypePrefixed.java | 16 +++ .../CheeseTypeSuffixed.java | 16 +++ .../CustomEnumTransformationStrategy.java | 30 +++++ .../EnumNameTransformationStrategyTest.java | 115 ++++++++++++++++ .../ErroneousNameTransformStrategyMapper.java | 22 ++++ 37 files changed, 1115 insertions(+), 14 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/EnumMapping.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java create mode 100644 processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringPrefixMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringSuffixMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheesePrefixMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseSuffixMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CustomEnumTransformationStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousNameTransformStrategyMapper.java diff --git a/core/src/main/java/org/mapstruct/EnumMapping.java b/core/src/main/java/org/mapstruct/EnumMapping.java new file mode 100644 index 0000000000..c184448aad --- /dev/null +++ b/core/src/main/java/org/mapstruct/EnumMapping.java @@ -0,0 +1,123 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configured the mapping between two value types. + *

      Example: Using a suffix for enums

      + *
      
      + * public enum CheeseType {
      + *     BRIE,
      + *     ROQUEFORT
      + * }
      + *
      + * public enum CheeseTypeSuffixed {
      + *     BRIE_TYPE,
      + *     ROQUEFORT_TYPE
      + * }
      + *
      + * @Mapper
      + * public interface CheeseMapper {
      + *
      + *     @EnumMapping(nameTransformationStrategy = "suffix", configuration = "_TYPE")
      + *     CheeseTypeSuffixed map(Cheese cheese);
      + *
      + *     @InheritInverseConfiguration
      + *     Cheese map(CheeseTypeSuffixed cheese);
      + *
      + * }
      + * 
      + *
      
      + * // generates
      + * public class CheeseMapperImpl implements CheeseMapper {
      + *
      + *     @Override
      + *     public CheeseTypeSuffixed map(Cheese cheese) {
      + *         if ( cheese == null ) {
      + *             return null;
      + *         }
      + *
      + *         CheeseTypeSuffixed cheeseTypeSuffixed;
      + *
      + *         switch ( cheese ) {
      + *             case BRIE:
      + *                 cheeseTypeSuffixed = CheeseTypeSuffixed.BRIE_TYPE;
      + *                 break;
      + *             case ROQUEFORT:
      + *                 cheeseTypeSuffixed = CheeseTypeSuffixed.ROQUEFORT_TYPE;
      + *                 break;
      + *             default:
      + *                 throw new IllegalArgumentException( "Unexpected enum constant: " + cheese );
      + *         }
      + *
      + *         return cheeseTypeSuffixed;
      + *     }
      + *
      + *     @Override
      + *     public Cheese map(CheeseTypeSuffixed cheese) {
      + *         if ( cheese == null ) {
      + *             return null;
      + *         }
      + *
      + *         CheeseType cheeseType;
      + *
      + *         switch ( cheese ) {
      + *             case BRIE_TYPE:
      + *                 cheeseType = CheeseType.BRIE;
      + *                 break;
      + *             case ROQUEFORT_TYPE:
      + *                 cheeseType = CheeseType.ROQUEFORT;
      + *                 break;
      + *             default:
      + *                 throw new IllegalArgumentException( "Unexpected enum constant: " + cheese );
      + *         }
      + *
      + *         return cheeseType;
      + *     }
      + * }
      + * 
      + * + * @author Filip Hrisafov + * @since 1.4 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface EnumMapping { + + /** + * Specifies the name transformation strategy that should be used for implicit mapping between enums. + * Known strategies are: + *
        + *
      • {@link MappingConstants#SUFFIX_TRANSFORMATION} - applies the given {@link #configuration()} as a + * suffix to the source enum
      • + *
      • {@link MappingConstants#STRIP_SUFFIX_TRANSFORMATION} - strips the the given {@link #configuration()} + * from the end of the source enum
      • + *
      • {@link MappingConstants#PREFIX_TRANSFORMATION} - applies the given {@link #configuration()} as a + * prefix to the source enum
      • + *
      • {@link MappingConstants#STRIP_PREFIX_TRANSFORMATION} - strips the given {@link #configuration()} from + * the start of the source enum
      • + *
      + * + * It is possible to use custom name transformation strategies by implementing the {@code + * EnumTransformationStrategy} SPI. + * + * @return the name transformation strategy + */ + String nameTransformationStrategy(); + + /** + * The configuration that should be passed on the appropriate name transformation strategy. + * e.g. a suffix that should be applied to the source enum when doing name based mapping. + * + * @return the configuration to use + */ + String configuration(); +} diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index af52d58f26..2c5757038f 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -36,4 +36,34 @@ private MappingConstants() { */ public static final String ANY_UNMAPPED = ""; + /** + * In an {@link EnumMapping} this represent the enum transformation strategy that adds a suffix to the source enum. + * + * @since 1.4 + */ + public static final String SUFFIX_TRANSFORMATION = "suffix"; + + /** + * In an {@link EnumMapping} this represent the enum transformation strategy that strips a suffix from the source + * enum. + * + * @since 1.4 + */ + public static final String STRIP_SUFFIX_TRANSFORMATION = "stripSuffix"; + + /** + * In an {@link EnumMapping} this represent the enum transformation strategy that adds a prefix to the source enum. + * + * @since 1.4 + */ + public static final String PREFIX_TRANSFORMATION = "prefix"; + + /** + * In an {@link EnumMapping} this represent the enum transformation strategy that strips a prefix from the source + * enum. + * + * @since 1.4 + */ + public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; + } diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index b152570475..ddf8327f79 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -197,4 +197,20 @@ A nice example is to provide support for a custom builder strategy. ---- include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] ---- +==== + + +[[custom-enum-transformation-strategy]] +=== Custom Enum Transformation Strategy + +MapStruct offers the possibility to other transformations strategies by implementing `EnumTransformationStrategy` via the Service Provider Interface (SPI). +A nice example is to provide support for a custom transformation strategy. + +.Custom Enum Transformation Strategy which lower-cases the value and applies a suffix +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/value/nametransformation/CustomEnumTransformationStrategy.java[tag=documentation] +---- ==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index 7bfd6afa45..000fd06523 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -159,3 +159,106 @@ MapStruct supports enum to a String mapping along the same lines as is described 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Similarity: `` will create a mapping for each target enum constant and proceed to the switch/default clause value. 4. Difference: A switch/default value needs to be provided to have a determined outcome (enum has a limited set of values, `String` has unlimited options). Failing to specify `` or ` will result in a warning. + +=== Custom name transformation + +When no `@ValueMapping`(s) are defined then each constant from the source enum is mapped to a constant with the same name in the target enum type. +However, there are cases where the source enum needs to be transformed before doing the mapping. +E.g. a suffix needs to be applied to map from the source into the target enum. + +.Enum types +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public enum CheeseType { + + BRIE, + ROQUEFORT +} + +public enum CheeseTypeSuffixed { + + BRIE_TYPE, + ROQUEFORT_TYPE +} +---- +==== + +.Enum mapping method with custom name transformation strategy +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CheeseMapper { + + CheeseMapper INSTANCE = Mappers.getMapper( CheeseMapper.class ); + + @EnumMapping(nameTransformationStrategy = "suffix", configuration = "_TYPE") + CheeseTypeSuffixed map(CheeseType cheese); + + @InheritInverseConfiguration + CheeseType map(CheeseTypeSuffix cheese); +} +---- +==== + +.Enum mapping method with custom name transformation strategy result +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CheeseSuffixMapperImpl implements CheeseSuffixMapper { + + @Override + public CheeseTypeSuffixed map(CheeseType cheese) { + if ( cheese == null ) { + return null; + } + + CheeseTypeSuffixed cheeseTypeSuffixed; + + switch ( cheese ) { + case BRIE: cheeseTypeSuffixed = CheeseTypeSuffixed.BRIE_TYPE; + break; + case ROQUEFORT: cheeseTypeSuffixed = CheeseTypeSuffixed.ROQUEFORT_TYPE; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return cheeseTypeSuffixed; + } + + @Override + public CheeseType map(CheeseTypeSuffixed cheese) { + if ( cheese == null ) { + return null; + } + + CheeseType cheeseType; + + switch ( cheese ) { + case BRIE_TYPE: cheeseType = CheeseType.BRIE; + break; + case ROQUEFORT_TYPE: cheeseType = CheeseType.ROQUEFORT; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return cheeseType; + } +} +---- +==== + +MapStruct provides the following out of the box enum name transformation strategies: + +* _suffix_ - Applies a suffix on the source enum +* _stripSuffix_ - Strips a suffix from the source enum +* _prefix_ - Applies a prefix on the source enum +* _stripPrefix_ - Strips a prefix from the source enum + +It is also possible to register custom strategies. +For more information on how to do that have a look at <> diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index b4d7758a10..524ea995d3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -14,6 +14,7 @@ import org.mapstruct.Builder; import org.mapstruct.Context; import org.mapstruct.DecoratedWith; +import org.mapstruct.EnumMapping; import org.mapstruct.InheritConfiguration; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.IterableMapping; @@ -43,6 +44,7 @@ @GemDefinition(Mappings.class) @GemDefinition(IterableMapping.class) @GemDefinition(BeanMapping.class) +@GemDefinition(EnumMapping.class) @GemDefinition(MapMapping.class) @GemDefinition(TargetType.class) @GemDefinition(MappingTarget.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index b988ccde40..685f5a543c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -20,4 +20,12 @@ private MappingConstantsGem() { public static final String ANY_REMAINING = ""; public static final String ANY_UNMAPPED = ""; + + public static final String SUFFIX_TRANSFORMATION = "suffix"; + + public static final String STRIP_SUFFIX_TRANSFORMATION = "stripSuffix"; + + public static final String PREFIX_TRANSFORMATION = "prefix"; + + public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 7bf720de71..f2e657f8ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -86,6 +86,7 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, forgedMappingMethod = new ValueMappingMethod.Builder() .method( forgedMethod ) .valueMappings( forgedMethod.getOptions().getValueMappings() ) + .enumMapping( forgedMethod.getOptions().getEnumMappingOptions() ) .mappingContext( ctx ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 2a752b11be..e8d649783c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -30,6 +30,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; +import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.MappingExclusionProvider; /** @@ -104,6 +105,7 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, private final Types typeUtils; private final FormattingMessager messager; private final AccessorNamingUtils accessorNaming; + private final Map enumTransformationStrategies; private final Options options; private final TypeElement mapperTypeElement; private final List sourceModel; @@ -113,11 +115,13 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, private final Map forgedMethodsUnderCreation = new HashMap<>(); + //CHECKSTYLE:OFF public MappingBuilderContext(TypeFactory typeFactory, Elements elementUtils, Types typeUtils, FormattingMessager messager, AccessorNamingUtils accessorNaming, + Map enumTransformationStrategies, Options options, MappingResolver mappingResolver, TypeElement mapper, @@ -128,12 +132,14 @@ public MappingBuilderContext(TypeFactory typeFactory, this.typeUtils = typeUtils; this.messager = messager; this.accessorNaming = accessorNaming; + this.enumTransformationStrategies = enumTransformationStrategies; this.options = options; this.mappingResolver = mappingResolver; this.mapperTypeElement = mapper; this.sourceModel = sourceModel; this.mapperReferences = mapperReferences; } + //CHECKSTYLE:ON /** * Returns a map which is used to track which forged methods are under creation. @@ -180,6 +186,10 @@ public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } + public Map getEnumTransformationStrategies() { + return enumTransformationStrategies; + } + public Options getOptions() { return options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 700cf4cd23..218c754e3d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -7,19 +7,23 @@ import java.util.ArrayList; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.EnumMappingOptions; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.ValueMappingOptions; -import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.spi.EnumTransformationStrategy; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED; @@ -45,6 +49,8 @@ public static class Builder { private Method method; private MappingBuilderContext ctx; private ValueMappings valueMappings; + private EnumMappingOptions enumMapping; + private EnumTransformationStrategyInvoker enumTransformationInvoker; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -61,7 +67,18 @@ public Builder valueMappings(List valueMappings) { return this; } - public ValueMappingMethod build( ) { + public Builder enumMapping(EnumMappingOptions enumMapping) { + this.enumMapping = enumMapping; + return this; + } + + public ValueMappingMethod build() { + + if ( !enumMapping.isValid() ) { + return null; + } + + initializeEnumTransformationStrategy(); // initialize all relevant parameters List mappingEntries = new ArrayList<>(); @@ -99,6 +116,23 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { ); } + private void initializeEnumTransformationStrategy() { + if ( !enumMapping.hasAnnotation() ) { + enumTransformationInvoker = EnumTransformationStrategyInvoker.DEFAULT; + } + else { + Map enumTransformationStrategies = + ctx.getEnumTransformationStrategies(); + + String nameTransformationStrategy = enumMapping.getNameTransformationStrategy(); + if ( enumTransformationStrategies.containsKey( nameTransformationStrategy ) ) { + enumTransformationInvoker = new EnumTransformationStrategyInvoker( enumTransformationStrategies.get( + nameTransformationStrategy ), enumMapping.getNameTransformationConfiguration() ); + } + } + + } + private List enumToEnumMapping(Method method, Type sourceType, Type targetType ) { List mappings = new ArrayList<>(); @@ -120,11 +154,36 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ // add mappings based on name if ( !valueMappings.hasMapAnyUnmapped ) { - // get all target constants - List targetConstants = method.getReturnType().getEnumConstants(); + // We store the target constants in a map in order to support inherited inverse mapping + // When using a nameTransformationStrategy the transformation should be done on the target enum + // instead of the source enum + Map targetConstants = new LinkedHashMap<>(); + + boolean enumMappingInverse = enumMapping.isInverse(); + for ( String targetEnumConstant : method.getReturnType().getEnumConstants() ) { + if ( enumMappingInverse ) { + // If the mapping is inverse we have to change the target enum constant + targetConstants.put( + enumTransformationInvoker.transform( targetEnumConstant ), + targetEnumConstant + ); + } + else { + targetConstants.put( targetEnumConstant, targetEnumConstant ); + } + } + for ( String sourceConstant : new ArrayList<>( unmappedSourceConstants ) ) { - if ( targetConstants.contains( sourceConstant ) ) { - mappings.add( new MappingEntry( sourceConstant, sourceConstant ) ); + String targetConstant; + if ( !enumMappingInverse ) { + targetConstant = enumTransformationInvoker.transform( sourceConstant ); + } + else { + targetConstant = sourceConstant; + } + + if ( targetConstants.containsKey( targetConstant ) ) { + mappings.add( new MappingEntry( sourceConstant, targetConstants.get( targetConstant ) ) ); unmappedSourceConstants.remove( sourceConstant ); } } @@ -175,7 +234,8 @@ private List enumToStringMapping(Method method, Type sourceType ) // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { - mappings.add( new MappingEntry( sourceConstant, sourceConstant ) ); + String targetConstant = enumTransformationInvoker.transform( sourceConstant ); + mappings.add( new MappingEntry( sourceConstant, targetConstant ) ); } } return mappings; @@ -204,7 +264,8 @@ private List stringToEnumMapping(Method method, Type targetType ) // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { - mappings.add( new MappingEntry( sourceConstant, sourceConstant ) ); + String stringConstant = enumTransformationInvoker.transform( sourceConstant ); + mappings.add( new MappingEntry( stringConstant, sourceConstant ) ); } } return mappings; @@ -229,7 +290,8 @@ private boolean reportErrorIfMappedSourceEnumConstantsDontExist(Method method, T for ( ValueMappingOptions mappedConstant : valueMappings.regularValueMappings ) { if ( !sourceEnumConstants.contains( mappedConstant.getSource() ) ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), mappedConstant.getMirror(), mappedConstant.getSourceAnnotationValue(), Message.VALUEMAPPING_NON_EXISTING_CONSTANT, @@ -279,7 +341,8 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T for ( ValueMappingOptions mappedConstant : valueMappings.regularValueMappings ) { if ( !NULL.equals( mappedConstant.getTarget() ) && !targetEnumConstants.contains( mappedConstant.getTarget() ) ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), mappedConstant.getMirror(), mappedConstant.getTargetAnnotationValue(), Message.VALUEMAPPING_NON_EXISTING_CONSTANT, @@ -292,7 +355,8 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T if ( valueMappings.defaultTarget != null && !NULL.equals( valueMappings.defaultTarget.getTarget() ) && !targetEnumConstants.contains( valueMappings.defaultTarget.getTarget() ) ) { - ctx.getMessager().printMessage( method.getExecutable(), + ctx.getMessager().printMessage( + method.getExecutable(), valueMappings.defaultTarget.getMirror(), valueMappings.defaultTarget.getTargetAnnotationValue(), Message.VALUEMAPPING_NON_EXISTING_CONSTANT, @@ -318,6 +382,31 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T } } + private static class EnumTransformationStrategyInvoker { + + private static final EnumTransformationStrategyInvoker DEFAULT = new EnumTransformationStrategyInvoker( + null, + null + ); + + private final EnumTransformationStrategy transformationStrategy; + private final String configuration; + + private EnumTransformationStrategyInvoker( + EnumTransformationStrategy transformationStrategy, String configuration) { + this.transformationStrategy = transformationStrategy; + this.configuration = configuration; + } + + private String transform(String source) { + if ( transformationStrategy == null ) { + return source; + } + + return transformationStrategy.transform( source, configuration ); + } + } + private static class ValueMappings { List regularValueMappings = new ArrayList<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java new file mode 100644 index 0000000000..576474e680 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java @@ -0,0 +1,99 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.Map; +import javax.lang.model.element.ExecutableElement; + +import org.mapstruct.ap.internal.gem.EnumMappingGem; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.spi.EnumTransformationStrategy; + +import static org.mapstruct.ap.internal.util.Message.ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY; + +/** + * @author Filip Hrisafov + */ +public class EnumMappingOptions extends DelegatingOptions { + + private final EnumMappingGem enumMapping; + private final boolean inverse; + private final boolean valid; + + private EnumMappingOptions(EnumMappingGem enumMapping, boolean inverse, boolean valid, DelegatingOptions next) { + super( next ); + this.enumMapping = enumMapping; + this.inverse = inverse; + this.valid = valid; + } + + @Override + public boolean hasAnnotation() { + return enumMapping != null; + } + + public boolean isValid() { + return valid; + } + + public String getNameTransformationStrategy() { + return enumMapping.nameTransformationStrategy().get(); + } + + public String getNameTransformationConfiguration() { + return enumMapping.configuration().get(); + } + + public boolean isInverse() { + return inverse; + } + + public EnumMappingOptions inverse() { + return new EnumMappingOptions( enumMapping, true, valid, next() ); + } + + public static EnumMappingOptions getInstanceOn(ExecutableElement method, MapperOptions mapperOptions, + Map enumTransformationStrategies, FormattingMessager messager) { + + EnumMappingGem enumMapping = EnumMappingGem.instanceOn( method ); + if ( enumMapping == null ) { + return new EnumMappingOptions( null, false, true, mapperOptions ); + } + else if ( !isConsistent( enumMapping, method, enumTransformationStrategies, messager ) ) { + return new EnumMappingOptions( null, false, false, mapperOptions ); + } + + return new EnumMappingOptions( + enumMapping, + false, + true, + mapperOptions + ); + } + + private static boolean isConsistent(EnumMappingGem gem, ExecutableElement method, + Map enumTransformationStrategies, FormattingMessager messager) { + + String strategy = gem.nameTransformationStrategy().getValue(); + + if ( !enumTransformationStrategies.containsKey( strategy ) ) { + String registeredStrategies = Strings.join( enumTransformationStrategies.keySet(), ", " ); + messager.printMessage( + method, + gem.mirror(), + gem.nameTransformationStrategy().getAnnotationValue(), + ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY, + strategy, + registeredStrategies + ); + + return false; + } + + return true; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 587dc5acf4..6c5cc1d04b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -31,6 +31,7 @@ public class MappingMethodOptions { null, null, null, + null, Collections.emptyList() ); @@ -39,18 +40,21 @@ public class MappingMethodOptions { private IterableMappingOptions iterableMapping; private MapMappingOptions mapMapping; private BeanMappingOptions beanMapping; + private EnumMappingOptions enumMappingOptions; private List valueMappings; private boolean fullyInitialized; public MappingMethodOptions(MapperOptions mapper, Set mappings, IterableMappingOptions iterableMapping, MapMappingOptions mapMapping, BeanMappingOptions beanMapping, + EnumMappingOptions enumMappingOptions, List valueMappings) { this.mapper = mapper; this.mappings = mappings; this.iterableMapping = iterableMapping; this.mapMapping = mapMapping; this.beanMapping = beanMapping; + this.enumMappingOptions = enumMappingOptions; this.valueMappings = valueMappings; } @@ -83,6 +87,10 @@ public BeanMappingOptions getBeanMapping() { return beanMapping; } + public EnumMappingOptions getEnumMappingOptions() { + return enumMappingOptions; + } + public List getValueMappings() { return valueMappings; } @@ -99,6 +107,10 @@ public void setBeanMapping(BeanMappingOptions beanMapping) { this.beanMapping = beanMapping; } + public void setEnumMappingOptions(EnumMappingOptions enumMappingOptions) { + this.enumMappingOptions = enumMappingOptions; + } + public void setValueMappings(List valueMappings) { this.valueMappings = valueMappings; } @@ -141,6 +153,17 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse setBeanMapping( BeanMappingOptions.forInheritance( templateOptions.getBeanMapping( ) ) ); } + if ( !getEnumMappingOptions().hasAnnotation() && templateOptions.getEnumMappingOptions().hasAnnotation() ) { + EnumMappingOptions newEnumMappingOptions; + if ( isInverse ) { + newEnumMappingOptions = templateOptions.getEnumMappingOptions().inverse(); + } + else { + newEnumMappingOptions = templateOptions.getEnumMappingOptions(); + } + setEnumMappingOptions( newEnumMappingOptions ); + } + if ( getValueMappings() == null ) { if ( templateOptions.getValueMappings() != null ) { // there were no mappings, so the inherited mappings are the new ones diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 3c1a5e1789..3551db8c51 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -84,6 +84,7 @@ public static class Builder { private MapperOptions mapper = null; private List prototypeMethods = Collections.emptyList(); private List valueMappings; + private EnumMappingOptions enumMappingOptions; private ParameterProvidedMethods contextProvidedMethods; public Builder setDeclaringMapper(Type declaringMapper) { @@ -136,6 +137,11 @@ public Builder setValueMappingOptionss(List valueMappings) return this; } + public Builder setEnumMappingOptions(EnumMappingOptions enumMappingOptions) { + this.enumMappingOptions = enumMappingOptions; + return this; + } + public Builder setTypeUtils(Types typeUtils) { this.typeUtils = typeUtils; return this; @@ -172,8 +178,15 @@ public SourceMethod build() { mappings = Collections.emptySet(); } - MappingMethodOptions mappingMethodOptions = - new MappingMethodOptions( mapper, mappings, iterableMapping, mapMapping, beanMapping, valueMappings ); + MappingMethodOptions mappingMethodOptions = new MappingMethodOptions( + mapper, + mappings, + iterableMapping, + mapMapping, + beanMapping, + enumMappingOptions, + valueMappings + ); return new SourceMethod( this, mappingMethodOptions ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index a9f9eff4a4..adb48d0877 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -26,6 +26,7 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.workarounds.TypesDecorator; import org.mapstruct.ap.internal.version.VersionInformation; +import org.mapstruct.ap.spi.EnumTransformationStrategy; /** * Default implementation of the processor context. @@ -41,6 +42,7 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final VersionInformation versionInformation; private final Types delegatingTypes; private final AccessorNamingUtils accessorNaming; + private final RoundContext roundContext; public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options, RoundContext roundContext, Map notToBeImported) { @@ -50,6 +52,7 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir this.accessorNaming = roundContext.getAnnotationProcessorContext().getAccessorNaming(); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); this.delegatingTypes = new TypesDecorator( processingEnvironment, versionInformation ); + this.roundContext = roundContext; this.typeFactory = new TypeFactory( processingEnvironment.getElementUtils(), delegatingTypes, @@ -90,6 +93,11 @@ public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } + @Override + public Map getEnumTransformationStrategies() { + return roundContext.getAnnotationProcessorContext().getEnumTransformationStrategies(); + } + @Override public Options getOptions() { return options; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 7746dd6778..6882fba642 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -101,6 +101,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L typeUtils, messager, accessorNaming, + context.getEnumTransformationStrategies(), options, new MappingResolverImpl( messager, @@ -336,8 +337,12 @@ else if ( method.isValueMapping() ) { .mappingContext( mappingContext ) .method( method ) .valueMappings( mappingOptions.getValueMappings() ) + .enumMapping( mappingOptions.getEnumMappingOptions() ) .build(); - mappingMethods.add( valueMappingMethod ); + + if ( valueMappingMethod != null ) { + mappingMethods.add( valueMappingMethod ); + } } else if ( method.isRemovedEnumMapping() ) { messager.printMessage( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 09a0cc95f2..b11c157b66 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -10,6 +10,7 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; @@ -27,6 +28,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.BeanMappingOptions; +import org.mapstruct.ap.internal.model.source.EnumMappingOptions; import org.mapstruct.ap.internal.model.source.IterableMappingOptions; import org.mapstruct.ap.internal.model.source.MapMappingOptions; import org.mapstruct.ap.internal.model.source.MapperOptions; @@ -47,6 +49,7 @@ import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.spi.EnumTransformationStrategy; import static org.mapstruct.ap.internal.util.Executables.getAllEnclosedExecutableElements; @@ -68,6 +71,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor enumTransformationStrategies; private Types typeUtils; private Elements elementUtils; @@ -78,6 +82,7 @@ public List process(ProcessorContext context, TypeElement mapperTy this.accessorNaming = context.getAccessorNaming(); this.typeUtils = context.getTypeUtils(); this.elementUtils = context.getElementUtils(); + this.enumTransformationStrategies = context.getEnumTransformationStrategies(); this.messager.note( 0, Message.PROCESSING_NOTE, mapperTypeElement ); @@ -273,6 +278,13 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, typeUtils ); + EnumMappingOptions enumMappingOptions = EnumMappingOptions.getInstanceOn( + method, + mapperOptions, + enumTransformationStrategies, + messager + ); + return new SourceMethod.Builder() .setExecutable( method ) .setParameters( parameters ) @@ -284,6 +296,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setIterableMappingOptions( iterableMappingOptions ) .setMapMappingOptions( mapMappingOptions ) .setValueMappingOptionss( getValueMappings( method ) ) + .setEnumMappingOptions( enumMappingOptions ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) .setPrototypeMethods( prototypeMethods ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index 74f0528d6e..4912037cd0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.processor; +import java.util.Map; import javax.annotation.processing.Filer; import javax.lang.model.element.TypeElement; import javax.lang.model.util.Elements; @@ -16,6 +17,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.version.VersionInformation; +import org.mapstruct.ap.spi.EnumTransformationStrategy; /** * A processor which performs one task of the mapper generation, e.g. retrieving @@ -51,6 +53,8 @@ public interface ProcessorContext { AccessorNamingUtils getAccessorNaming(); + Map getEnumTransformationStrategies(); + Options getOptions(); VersionInformation getVersionInformation(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 8fdc6201e1..28db59abbe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -9,7 +9,9 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; import javax.annotation.processing.Messager; @@ -22,6 +24,7 @@ import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.FreeBuilderAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesBuilderProvider; @@ -39,6 +42,7 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private BuilderProvider builderProvider; private AccessorNamingStrategy accessorNamingStrategy; private boolean initialized; + private Map enumTransformationStrategies; private AccessorNamingUtils accessorNaming; private Elements elementUtils; @@ -105,6 +109,28 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! ); } this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); + + + this.enumTransformationStrategies = new LinkedHashMap<>(); + ServiceLoader transformationStrategiesLoader = ServiceLoader.load( + EnumTransformationStrategy.class, + AnnotationProcessorContext.class.getClassLoader() + ); + + for ( EnumTransformationStrategy transformationStrategy : transformationStrategiesLoader ) { + String transformationStrategyName = transformationStrategy.getStrategyName(); + if ( enumTransformationStrategies.containsKey( transformationStrategyName ) ) { + throw new IllegalStateException( + "Multiple EnumTransformationStrategies are using the same ma,e. Found: " + + enumTransformationStrategies.get( transformationStrategyName ) + " and " + + transformationStrategy + " for name " + transformationStrategyName ); + } + + transformationStrategy.init( this ); + enumTransformationStrategies.put( transformationStrategyName, transformationStrategy ); + } + + this.initialized = true; } @@ -216,4 +242,9 @@ public BuilderProvider getBuilderProvider() { initialize(); return builderProvider; } + + public Map getEnumTransformationStrategies() { + initialize(); + return enumTransformationStrategies; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index d2cb9857ef..a26166a7ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -100,6 +100,7 @@ public enum Message { ENUMMAPPING_UNDEFINED_TARGET( "A target constant must be specified for mappings of an enum mapping method." ), ENUMMAPPING_UNMAPPED_SOURCES( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: %s." ), ENUMMAPPING_REMOVED( "Mapping of Enums via @Mapping is removed. Please use @ValueMapping instead!" ), + ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY( "There is no registered EnumTransformationStrategy for '%s'. Registered strategies are: %s." ), LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java new file mode 100644 index 0000000000..2c498fc3a8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import org.mapstruct.util.Experimental; + +/** + * A service provider interface for transforming name based value mappings. + * + * @author Filip Hrisafov + * @since 1.4 + */ +@Experimental("This SPI can have it's signature changed in subsequent releases") +public interface EnumTransformationStrategy { + + /** + * Initializes the enum transformation strategy with the MapStruct processing environment. + * + * @param processingEnvironment environment for facilities + */ + default void init(MapStructProcessingEnvironment processingEnvironment) { + + } + + /** + * The name of the strategy. + * + * @return the name of the strategy, never {@code null} + */ + String getStrategyName(); + + /** + * Transform the given value by using the given {@code configuration}. + * + * @param value the value that should be transformed + * @param configuration the configuration that should be used for the transformation + * + * @return the transformed value after applying the configuration + */ + String transform(String value, String configuration); +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java new file mode 100644 index 0000000000..eaa7b75512 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +/** + * @author Filip Hrisafov + */ +public class PrefixEnumTransformationStrategy implements EnumTransformationStrategy { + + @Override + public String getStrategyName() { + return "prefix"; + } + + @Override + public String transform(String value, String configuration) { + return configuration + value; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java new file mode 100644 index 0000000000..d7f03c9b7b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +/** + * @author Filip Hrisafov + */ +public class StripPrefixEnumTransformationStrategy implements EnumTransformationStrategy { + + @Override + public String getStrategyName() { + return "stripPrefix"; + } + + @Override + public String transform(String value, String configuration) { + if ( value.startsWith( configuration ) ) { + return value.substring( configuration.length() ); + } + return value; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java new file mode 100644 index 0000000000..223837924e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +/** + * @author Filip Hrisafov + */ +public class StripSuffixEnumTransformationStrategy implements EnumTransformationStrategy { + + @Override + public String getStrategyName() { + return "stripSuffix"; + } + + @Override + public String transform(String value, String configuration) { + if ( value.endsWith( configuration ) ) { + return value.substring( 0, value.length() - configuration.length() ); + } + return value; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java new file mode 100644 index 0000000000..29a109fadf --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +/** + * @author Filip Hrisafov + */ +public class SuffixEnumTransformationStrategy implements EnumTransformationStrategy { + + @Override + public String getStrategyName() { + return "suffix"; + } + + @Override + public String transform(String value, String configuration) { + return value + configuration; + } +} diff --git a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy new file mode 100644 index 0000000000..1f52733ad9 --- /dev/null +++ b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy @@ -0,0 +1,8 @@ +# Copyright MapStruct Authors. +# +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +org.mapstruct.ap.spi.PrefixEnumTransformationStrategy +org.mapstruct.ap.spi.StripPrefixEnumTransformationStrategy +org.mapstruct.ap.spi.StripSuffixEnumTransformationStrategy +org.mapstruct.ap.spi.SuffixEnumTransformationStrategy diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index b33f00964b..a2a6afefde 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -23,5 +23,11 @@ public void constantsShouldBeEqual() { assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsGem.ANY_REMAINING ); assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsGem.ANY_UNMAPPED ); assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsGem.NULL ); + assertThat( MappingConstants.SUFFIX_TRANSFORMATION ).isEqualTo( MappingConstantsGem.SUFFIX_TRANSFORMATION ); + assertThat( MappingConstants.STRIP_SUFFIX_TRANSFORMATION ) + .isEqualTo( MappingConstantsGem.STRIP_SUFFIX_TRANSFORMATION ); + assertThat( MappingConstants.PREFIX_TRANSFORMATION ).isEqualTo( MappingConstantsGem.PREFIX_TRANSFORMATION ); + assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION ) + .isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/OrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/OrderMapper.java index 35d9f57f90..d7e6f1062c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/OrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/OrderMapper.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.value.enum2string; +import org.mapstruct.EnumMapping; import org.mapstruct.Mapper; import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; @@ -27,6 +28,7 @@ public interface OrderMapper { }) String mapNormal(OrderType orderType); + @EnumMapping(nameTransformationStrategy = "prefix", configuration = "PREFIX_") @ValueMappings({ @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ), @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringPrefixMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringPrefixMapper.java new file mode 100644 index 0000000000..aa6d220711 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringPrefixMapper.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CheeseEnumToStringPrefixMapper { + + CheeseEnumToStringPrefixMapper INSTANCE = Mappers.getMapper( CheeseEnumToStringPrefixMapper.class ); + + @EnumMapping(nameTransformationStrategy = MappingConstants.PREFIX_TRANSFORMATION, configuration = "SWISS_") + String map(CheeseType cheese); + + @InheritInverseConfiguration + @EnumMapping(nameTransformationStrategy = MappingConstants.PREFIX_TRANSFORMATION, configuration = "FRENCH_") + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + CheeseType map(String cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.STRIP_PREFIX_TRANSFORMATION, configuration = "SWISS_") + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + CheeseTypePrefixed mapStripPrefix(String cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringSuffixMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringSuffixMapper.java new file mode 100644 index 0000000000..a6be3ae2d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseEnumToStringSuffixMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CheeseEnumToStringSuffixMapper { + + CheeseEnumToStringSuffixMapper INSTANCE = Mappers.getMapper( CheeseEnumToStringSuffixMapper.class ); + + @EnumMapping(nameTransformationStrategy = MappingConstants.SUFFIX_TRANSFORMATION, configuration = "_CHEESE_TYPE") + String map(CheeseType cheese); + + @InheritInverseConfiguration + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + CheeseType map(String cheese); + + @EnumMapping( + nameTransformationStrategy = MappingConstants.STRIP_SUFFIX_TRANSFORMATION, + configuration = "_CHEESE_TYPE" + ) + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + CheeseTypeSuffixed mapStripSuffix(String cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheesePrefixMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheesePrefixMapper.java new file mode 100644 index 0000000000..7cb441bb08 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheesePrefixMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CheesePrefixMapper { + + CheesePrefixMapper INSTANCE = Mappers.getMapper( CheesePrefixMapper.class ); + + @EnumMapping(nameTransformationStrategy = MappingConstants.PREFIX_TRANSFORMATION, configuration = "SWISS_") + CheeseTypePrefixed map(CheeseType cheese); + + @InheritInverseConfiguration + @ValueMapping(source = "DEFAULT", target = MappingConstants.NULL) + CheeseType mapInheritInverse(CheeseTypePrefixed cheese); + + @ValueMapping(source = "DEFAULT", target = MappingConstants.NULL) + @EnumMapping(nameTransformationStrategy = MappingConstants.STRIP_PREFIX_TRANSFORMATION, configuration = "SWISS_") + CheeseType mapStripPrefix(CheeseTypePrefixed cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseSuffixMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseSuffixMapper.java new file mode 100644 index 0000000000..b50ed0acba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseSuffixMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CheeseSuffixMapper { + + CheeseSuffixMapper INSTANCE = Mappers.getMapper( CheeseSuffixMapper.class ); + + @EnumMapping(nameTransformationStrategy = MappingConstants.SUFFIX_TRANSFORMATION, configuration = "_CHEESE_TYPE") + CheeseTypeSuffixed map(CheeseType cheese); + + @InheritInverseConfiguration + @ValueMapping(source = "DEFAULT", target = MappingConstants.NULL) + CheeseType mapInheritInverse(CheeseTypeSuffixed cheese); + + @EnumMapping( + nameTransformationStrategy = MappingConstants.STRIP_SUFFIX_TRANSFORMATION, + configuration = "_CHEESE_TYPE" + ) + @ValueMapping(source = "DEFAULT", target = MappingConstants.NULL) + CheeseType mapStripSuffix(CheeseTypeSuffixed cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java new file mode 100644 index 0000000000..d7a1d2e288 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author Filip Hrisafov + */ +public enum CheeseType { + + BRIE, + ROQUEFORT +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java new file mode 100644 index 0000000000..b7eccd3d42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author Filip Hrisafov + */ +public enum CheeseTypeCustomSuffix { + + brie_TYPE, + roquefort_TYPE, +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java new file mode 100644 index 0000000000..5f5b989c7b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author Filip Hrisafov + */ +public enum CheeseTypePrefixed { + + DEFAULT, + SWISS_BRIE, + SWISS_ROQUEFORT, +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java new file mode 100644 index 0000000000..b2b264b78b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author Filip Hrisafov + */ +public enum CheeseTypeSuffixed { + + DEFAULT, + BRIE_CHEESE_TYPE, + ROQUEFORT_CHEESE_TYPE, +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CustomEnumTransformationStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CustomEnumTransformationStrategy.java new file mode 100644 index 0000000000..f7cfe44375 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CustomEnumTransformationStrategy.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +// tag::documentation[] + +import org.mapstruct.ap.spi.EnumTransformationStrategy; + +// end::documentation[] + +/** + * @author Filip Hrisafov + */ +// tag::documentation[] +public class CustomEnumTransformationStrategy implements EnumTransformationStrategy { + + @Override + public String getStrategyName() { + return "custom"; + } + + @Override + public String transform(String value, String configuration) { + return value.toLowerCase() + configuration; + } +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java new file mode 100644 index 0000000000..d5de5e872f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java @@ -0,0 +1,115 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CheeseType.class, + CheeseTypeSuffixed.class, + CheeseTypePrefixed.class, + CheeseTypeCustomSuffix.class, +}) +public class EnumNameTransformationStrategyTest { + + @Test + @WithClasses({ + CheeseSuffixMapper.class + }) + public void shouldApplySuffixAndStripSuffixOnEnumToEnumMapping() { + CheeseSuffixMapper mapper = CheeseSuffixMapper.INSTANCE; + + assertThat( mapper.map( CheeseType.BRIE ) ) + .isEqualTo( CheeseTypeSuffixed.BRIE_CHEESE_TYPE ); + assertThat( mapper.mapInheritInverse( CheeseTypeSuffixed.BRIE_CHEESE_TYPE ) ) + .isEqualTo( CheeseType.BRIE ); + assertThat( mapper.mapStripSuffix( CheeseTypeSuffixed.BRIE_CHEESE_TYPE ) ) + .isEqualTo( CheeseType.BRIE ); + } + + @Test + @WithClasses({ + CheesePrefixMapper.class + }) + public void shouldApplyPrefixAndStripPrefixOnEnumToEnumMapping() { + CheesePrefixMapper mapper = CheesePrefixMapper.INSTANCE; + + assertThat( mapper.map( CheeseType.BRIE ) ) + .isEqualTo( CheeseTypePrefixed.SWISS_BRIE ); + assertThat( mapper.mapInheritInverse( CheeseTypePrefixed.SWISS_BRIE ) ) + .isEqualTo( CheeseType.BRIE ); + assertThat( mapper.mapStripPrefix( CheeseTypePrefixed.SWISS_BRIE ) ) + .isEqualTo( CheeseType.BRIE ); + } + + @Test + @WithClasses({ + CheeseEnumToStringSuffixMapper.class + }) + public void shouldApplySuffixAndStripSuffixOnEnumToStringMapping() { + CheeseEnumToStringSuffixMapper mapper = CheeseEnumToStringSuffixMapper.INSTANCE; + + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( "BRIE_CHEESE_TYPE" ); + assertThat( mapper.map( "BRIE_CHEESE_TYPE" ) ).isEqualTo( CheeseType.BRIE ); + assertThat( mapper.mapStripSuffix( "BRIE" ) ).isEqualTo( CheeseTypeSuffixed.BRIE_CHEESE_TYPE ); + assertThat( mapper.mapStripSuffix( "DEFAULT" ) ).isEqualTo( CheeseTypeSuffixed.DEFAULT ); + } + + @Test + @WithClasses({ + CheeseEnumToStringPrefixMapper.class + }) + public void shouldApplyPrefixAndStripPrefixOnEnumToStringMapping() { + CheeseEnumToStringPrefixMapper mapper = CheeseEnumToStringPrefixMapper.INSTANCE; + + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( "SWISS_BRIE" ); + assertThat( mapper.map( "FRENCH_BRIE" ) ).isEqualTo( CheeseType.BRIE ); + assertThat( mapper.mapStripPrefix( "BRIE" ) ).isEqualTo( CheeseTypePrefixed.SWISS_BRIE ); + assertThat( mapper.mapStripPrefix( "DEFAULT" ) ).isEqualTo( CheeseTypePrefixed.DEFAULT ); + } + + @Test + @WithClasses({ + ErroneousNameTransformStrategyMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousNameTransformStrategyMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "There is no registered EnumTransformationStrategy for 'custom'. Registered strategies are:" + + " prefix, stripPrefix, stripSuffix, suffix." + ) + } + ) + public void shouldGiveCompileErrorWhenUsingUnknownNameTransformStrategy() { + } + + @Test + @WithClasses({ + ErroneousNameTransformStrategyMapper.class + }) + @WithServiceImplementation(CustomEnumTransformationStrategy.class) + public void shouldUseCustomEnumTransformationStrategy() { + assertThat( ErroneousNameTransformStrategyMapper.INSTANCE.map( CheeseType.BRIE ) ) + .isEqualTo( CheeseTypeCustomSuffix.brie_TYPE ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousNameTransformStrategyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousNameTransformStrategyMapper.java new file mode 100644 index 0000000000..cb59089b38 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousNameTransformStrategyMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousNameTransformStrategyMapper { + + ErroneousNameTransformStrategyMapper INSTANCE = Mappers.getMapper( ErroneousNameTransformStrategyMapper.class ); + + @EnumMapping(nameTransformationStrategy = "custom", configuration = "_TYPE") + CheeseTypeCustomSuffix map(CheeseType cheese); +} From c23592a7fe30bf4b4a779caadfeb9edd4578c82c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 25 May 2020 21:31:29 +0200 Subject: [PATCH 0464/1006] Add EnumNamingStrategy SPI (#2100) Add a new EnumNamingStrategy SPI which can be used for customising the way enums are matched by name. It is similar to the AccessorNamingStrategy such that it allows implementors to provide a custom way of defining a property. Related to #796, #1220, #1789 and #1667 --- .../chapter-13-using-mapstruct-spi.asciidoc | 146 ++++++++++++++++++ .../internal/model/MappingBuilderContext.java | 8 + .../ap/internal/model/ValueMappingMethod.java | 77 ++++++--- .../DefaultModelElementProcessorContext.java | 6 + .../processor/MapperCreationProcessor.java | 1 + .../processor/ModelElementProcessor.java | 3 + .../util/AnnotationProcessorContext.java | 17 ++ .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/spi/DefaultEnumNamingStrategy.java | 35 +++++ .../mapstruct/ap/spi/EnumNamingStrategy.java | 48 ++++++ .../ap/test/value/spi/CheeseType.java | 15 ++ .../ap/test/value/spi/CustomCheeseMapper.java | 34 ++++ .../ap/test/value/spi/CustomCheeseType.java | 17 ++ .../ap/test/value/spi/CustomEnumMarker.java | 12 ++ .../value/spi/CustomEnumNamingStrategy.java | 54 +++++++ .../spi/CustomEnumNamingStrategyTest.java | 123 +++++++++++++++ .../CustomErroneousEnumNamingStrategy.java | 54 +++++++ ...CustomErroneousEnumNamingStrategyTest.java | 102 ++++++++++++ .../spi/OverridesCustomCheeseMapper.java | 45 ++++++ .../value/spi/CustomCheeseMapperImpl.java | 138 +++++++++++++++++ 20 files changed, 918 insertions(+), 18 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CheeseType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMarker.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/OverridesCustomCheeseMapper.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index ddf8327f79..bc9cf7646c 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -199,6 +199,152 @@ include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] ---- ==== +[[custom-enum-naming-strategy]] +=== Custom Enum Naming Strategy + +MapStruct offers the possibility to override the `EnumNamingStrategy` via the Service Provider Interface (SPI). +This can be used when you have certain enums that follow some conventions within your organization. +For example all enums which implement an interface named `CustomEnumMarker` are prefixed with `CUSTOM_` +and the default value for them when mapping from `null` is `UNSPECIFIED` + +.Normal Enum +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public enum CheeseType { + BRIE, + ROQUEFORT; +} +---- +==== + +.Custom marker enum +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public enum CustomCheeseType implements CustomEnumMarker { + + UNSPECIFIED, + CUSTOM_BRIE, + CUSTOM_ROQUEFORT; +} +---- +==== + +We want `CheeseType` and `CustomCheeseType` to be mapped without the need to manually define the value mappings: + +.Custom enum mapping +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CheeseTypeMapper { + + CheeseType map(CustomCheeseType cheese); + + CustomCheeseType map(CheeseType cheese); +} +---- +==== + +This can be achieved with implementing the SPI `org.mapstruct.ap.spi.EnumNamingStrategy` as in the following example. +Here’s an implemented `org.mapstruct.ap.spi.EnumNamingStrategy`: + +.Custom enum naming strategy +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class CustomEnumNamingStrategy extends DefaultEnumNamingStrategy { + + @Override + public String getDefaultNullEnumConstant(TypeElement enumType) { + if ( isCustomEnum( enumType ) ) { + return "UNSPECIFIED"; + } + + return super.getDefaultNullEnumConstant( enumType ); + } + + @Override + public String getEnumConstant(TypeElement enumType, String enumConstant) { + if ( isCustomEnum( enumType ) ) { + return getCustomEnumConstant( enumConstant ); + } + return super.getEnumConstant( enumType, enumConstant ); + } + protected String getCustomEnumConstant(String enumConstant) { + if ( "UNSPECIFIED".equals( enumConstant ) ) { + return MappingConstantsGem.NULL; + } + return enumConstant.replace( "CUSTOM_", "" ); + } + protected boolean isCustomEnum(TypeElement enumType) { + for ( TypeMirror enumTypeInterface : enumType.getInterfaces() ) { + if ( typeUtils.asElement( enumTypeInterface ).getSimpleName().contentEquals( "CustomEnumMarker" ) ) { + return true; + } + } + return false; + } +} +---- +==== + +The generated code then for the `CheeseMapper` looks like: + +.Generated CheeseTypeMapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class CheeseTypeMapperImpl implements CheeseTypeMapper { + + @Override + public CheeseType map(CustomCheeseType cheese) { + if ( cheese == null ) { + return null; + } + + CheeseType cheeseType; + + switch ( cheese ) { + case UNRECOGNIZED: cheeseType = null; + break; + case CUSTOM_BRIE: cheeseType = CheeseType.BRIE; + break; + case CUSTOM_ROQUEFORT: cheeseType = CheeseType.ROQUEFORT; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return cheeseType; + } + + @Override + public CustomCheeseType map(CheeseType cheese) { + if ( cheese == null ) { + return CustomCheeseType.UNSPECIFIED; + } + + CustomCheeseType customCheeseType; + + switch ( cheese ) { + case BRIE: customCheeseType = CustomCheeseType.CUSTOM_BRIE; + break; + case ROQUEFORT: customCheeseType = CustomCheeseType.CUSTOM_ROQUEFORT; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return customCheeseType; + } +} +---- +==== [[custom-enum-transformation-strategy]] === Custom Enum Transformation Strategy diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index e8d649783c..53317aefa0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -30,6 +30,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; +import org.mapstruct.ap.spi.EnumNamingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.MappingExclusionProvider; @@ -105,6 +106,7 @@ Assignment getTargetAssignment(Method mappingMethod, Type targetType, private final Types typeUtils; private final FormattingMessager messager; private final AccessorNamingUtils accessorNaming; + private final EnumNamingStrategy enumNamingStrategy; private final Map enumTransformationStrategies; private final Options options; private final TypeElement mapperTypeElement; @@ -121,6 +123,7 @@ public MappingBuilderContext(TypeFactory typeFactory, Types typeUtils, FormattingMessager messager, AccessorNamingUtils accessorNaming, + EnumNamingStrategy enumNamingStrategy, Map enumTransformationStrategies, Options options, MappingResolver mappingResolver, @@ -132,6 +135,7 @@ public MappingBuilderContext(TypeFactory typeFactory, this.typeUtils = typeUtils; this.messager = messager; this.accessorNaming = accessorNaming; + this.enumNamingStrategy = enumNamingStrategy; this.enumTransformationStrategies = enumTransformationStrategies; this.options = options; this.mappingResolver = mappingResolver; @@ -186,6 +190,10 @@ public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } + public EnumNamingStrategy getEnumNamingStrategy() { + return enumNamingStrategy; + } + public Map getEnumTransformationStrategies() { return enumTransformationStrategies; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 218c754e3d..adfa5779e8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -8,9 +8,11 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; @@ -86,6 +88,12 @@ public ValueMappingMethod build() { Type sourceType = first( method.getSourceParameters() ).getType(); Type targetType = method.getResultType(); + if ( targetType.isEnumType() && valueMappings.nullTarget == null ) { + // If null target is not set it means that the user has not explicitly defined a mapping for null + valueMappings.nullValueTarget = ctx.getEnumNamingStrategy() + .getDefaultNullEnumConstant( targetType.getTypeElement() ); + } + // enum-to-enum if ( sourceType.isEnumType() && targetType.isEnumType() ) { mappingEntries.addAll( enumToEnumMapping( method, sourceType, targetType ) ); @@ -145,9 +153,7 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ // Start to fill the mappings with the defined value mappings for ( ValueMappingOptions valueMapping : valueMappings.regularValueMappings ) { - String target = - NULL.equals( valueMapping.getTarget() ) ? null : valueMapping.getTarget(); - mappings.add( new MappingEntry( valueMapping.getSource(), target ) ); + mappings.add( new MappingEntry( valueMapping.getSource(), valueMapping.getTarget() ) ); unmappedSourceConstants.remove( valueMapping.getSource() ); } @@ -160,32 +166,40 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ Map targetConstants = new LinkedHashMap<>(); boolean enumMappingInverse = enumMapping.isInverse(); + TypeElement targetTypeElement = method.getReturnType().getTypeElement(); for ( String targetEnumConstant : method.getReturnType().getEnumConstants() ) { + String targetNameEnum = getEnumConstant( targetTypeElement, targetEnumConstant ); if ( enumMappingInverse ) { // If the mapping is inverse we have to change the target enum constant targetConstants.put( - enumTransformationInvoker.transform( targetEnumConstant ), + enumTransformationInvoker.transform( targetNameEnum ), targetEnumConstant ); } else { - targetConstants.put( targetEnumConstant, targetEnumConstant ); + targetConstants.put( targetNameEnum, targetEnumConstant ); } } + TypeElement sourceTypeElement = sourceType.getTypeElement(); for ( String sourceConstant : new ArrayList<>( unmappedSourceConstants ) ) { + String sourceNameConstant = getEnumConstant( sourceTypeElement, sourceConstant ); String targetConstant; if ( !enumMappingInverse ) { - targetConstant = enumTransformationInvoker.transform( sourceConstant ); + targetConstant = enumTransformationInvoker.transform( sourceNameConstant ); } else { - targetConstant = sourceConstant; + targetConstant = sourceNameConstant; } if ( targetConstants.containsKey( targetConstant ) ) { mappings.add( new MappingEntry( sourceConstant, targetConstants.get( targetConstant ) ) ); unmappedSourceConstants.remove( sourceConstant ); } + else if ( NULL.equals( targetConstant ) ) { + mappings.add( new MappingEntry( sourceConstant, null ) ); + unmappedSourceConstants.remove( sourceConstant ); + } } if ( valueMappings.defaultTarget == null && !unmappedSourceConstants.isEmpty() ) { @@ -223,18 +237,18 @@ private List enumToStringMapping(Method method, Type sourceType ) // Start to fill the mappings with the defined valuemappings for ( ValueMappingOptions valueMapping : valueMappings.regularValueMappings ) { - String target = - NULL.equals( valueMapping.getTarget() ) ? null : valueMapping.getTarget(); - mappings.add( new MappingEntry( valueMapping.getSource(), target ) ); + mappings.add( new MappingEntry( valueMapping.getSource(), valueMapping.getTarget() ) ); unmappedSourceConstants.remove( valueMapping.getSource() ); } // add mappings based on name if ( !valueMappings.hasMapAnyUnmapped ) { + TypeElement sourceTypeElement = sourceType.getTypeElement(); // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { - String targetConstant = enumTransformationInvoker.transform( sourceConstant ); + String sourceNameConstant = getEnumConstant( sourceTypeElement, sourceConstant ); + String targetConstant = enumTransformationInvoker.transform( sourceNameConstant ); mappings.add( new MappingEntry( sourceConstant, targetConstant ) ); } } @@ -250,27 +264,35 @@ private List stringToEnumMapping(Method method, Type targetType ) if ( sourceErrorOccurred || mandatoryMissing ) { return mappings; } + Set mappedSources = new LinkedHashSet<>(); // Start to fill the mappings with the defined valuemappings for ( ValueMappingOptions valueMapping : valueMappings.regularValueMappings ) { - String target = - NULL.equals( valueMapping.getTarget() ) ? null : valueMapping.getTarget(); - mappings.add( new MappingEntry( valueMapping.getSource(), target ) ); + mappedSources.add( valueMapping.getSource() ); + mappings.add( new MappingEntry( valueMapping.getSource(), valueMapping.getTarget() ) ); unmappedSourceConstants.remove( valueMapping.getSource() ); } // add mappings based on name if ( !valueMappings.hasMapAnyUnmapped ) { - + mappedSources.add( NULL ); + TypeElement targetTypeElement = targetType.getTypeElement(); // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { - String stringConstant = enumTransformationInvoker.transform( sourceConstant ); - mappings.add( new MappingEntry( stringConstant, sourceConstant ) ); + String sourceNameConstant = getEnumConstant( targetTypeElement, sourceConstant ); + String stringConstant = enumTransformationInvoker.transform( sourceNameConstant ); + if ( !mappedSources.contains( stringConstant ) ) { + mappings.add( new MappingEntry( stringConstant, sourceConstant ) ); + } } } return mappings; } + private String getEnumConstant(TypeElement typeElement, String enumConstant) { + return ctx.getEnumNamingStrategy().getEnumConstant( typeElement, enumConstant ); + } + private SelectionParameters getSelectionParameters(Method method, Types typeUtils) { BeanMappingGem beanMapping = BeanMappingGem.instanceOn( method.getExecutable() ); if ( beanMapping != null ) { @@ -377,6 +399,18 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T ); foundIncorrectMapping = true; } + else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != null + && !targetEnumConstants.contains( valueMappings.nullValueTarget ) ) { + // if there is no nullTarget, but nullValueTarget has a value it means that there was an SPI + // which returned an enum for the target enum + ctx.getMessager().printMessage( + method.getExecutable(), + Message.VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI, + valueMappings.nullValueTarget, + method.getReturnType(), + ctx.getEnumNamingStrategy() + ); + } return !foundIncorrectMapping; } @@ -417,6 +451,7 @@ private static class ValueMappings { boolean hasMapAnyUnmapped = false; boolean hasMapAnyRemaining = false; boolean hasDefaultValue = false; + boolean hasNullValue = false; ValueMappings(List valueMappings) { @@ -436,6 +471,7 @@ else if ( ANY_UNMAPPED.equals( valueMapping.getSource() ) ) { else if ( NULL.equals( valueMapping.getSource() ) ) { nullTarget = valueMapping; nullValueTarget = getValue( nullTarget ); + hasNullValue = true; } else { regularValueMappings.add( valueMapping ); @@ -489,7 +525,12 @@ public static class MappingEntry { MappingEntry( String source, String target ) { this.source = source; - this.target = target; + if ( !NULL.equals( target ) ) { + this.target = target; + } + else { + this.target = null; + } } public String getSource() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index adb48d0877..3b5cb1b036 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -26,6 +26,7 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.workarounds.TypesDecorator; import org.mapstruct.ap.internal.version.VersionInformation; +import org.mapstruct.ap.spi.EnumNamingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; /** @@ -98,6 +99,11 @@ public Map getEnumTransformationStrategies() return roundContext.getAnnotationProcessorContext().getEnumTransformationStrategies(); } + @Override + public EnumNamingStrategy getEnumNamingStrategy() { + return roundContext.getAnnotationProcessorContext().getEnumNamingStrategy(); + } + @Override public Options getOptions() { return options; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 6882fba642..c22377f984 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -101,6 +101,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L typeUtils, messager, accessorNaming, + context.getEnumNamingStrategy(), context.getEnumTransformationStrategies(), options, new MappingResolverImpl( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index 4912037cd0..0689af54a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -17,6 +17,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.version.VersionInformation; +import org.mapstruct.ap.spi.EnumNamingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; /** @@ -55,6 +56,8 @@ public interface ProcessorContext { Map getEnumTransformationStrategies(); + EnumNamingStrategy getEnumNamingStrategy(); + Options getOptions(); VersionInformation getVersionInformation(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 28db59abbe..4b70bd60ad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -24,6 +24,8 @@ import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultBuilderProvider; +import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; +import org.mapstruct.ap.spi.EnumNamingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.FreeBuilderAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; @@ -41,6 +43,7 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private BuilderProvider builderProvider; private AccessorNamingStrategy accessorNamingStrategy; + private EnumNamingStrategy enumNamingStrategy; private boolean initialized; private Map enumTransformationStrategies; @@ -110,6 +113,15 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! } this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); + this.enumNamingStrategy = Services.get( EnumNamingStrategy.class, new DefaultEnumNamingStrategy() ); + this.enumNamingStrategy.init( this ); + if ( verbose ) { + messager.printMessage( + Diagnostic.Kind.NOTE, + "MapStruct: Using enum naming strategy: " + + this.enumNamingStrategy.getClass().getCanonicalName() + ); + } this.enumTransformationStrategies = new LinkedHashMap<>(); ServiceLoader transformationStrategiesLoader = ServiceLoader.load( @@ -238,6 +250,11 @@ public AccessorNamingStrategy getAccessorNamingStrategy() { return accessorNamingStrategy; } + public EnumNamingStrategy getEnumNamingStrategy() { + initialize(); + return enumNamingStrategy; + } + public BuilderProvider getBuilderProvider() { initialize(); return builderProvider; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index a26166a7ed..4c46c09917 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -158,6 +158,7 @@ public enum Message { VALUEMAPPING_UNMAPPED_SOURCES( "The following constants from the %s enum have no corresponding constant in the %s enum and must be be mapped via adding additional mappings: %s." ), VALUEMAPPING_ANY_REMAINING_FOR_NON_ENUM( "Source = \"\" can only be used on targets of type enum and not for %s." ), VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING( "Source = \"\" or \"\" is advisable for mapping of type String to an enum type.", Diagnostic.Kind.WARNING ), + VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI( "Constant %s doesn't exist in enum type %s. Constant was returned from EnumNamingStrategy: %s"), VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); // CHECKSTYLE:ON diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java new file mode 100644 index 0000000000..526d0a24f2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +/** + * @author Filip Hrisafov + */ +public class DefaultEnumNamingStrategy implements EnumNamingStrategy { + + protected Elements elementUtils; + protected Types typeUtils; + + @Override + public void init(MapStructProcessingEnvironment processingEnvironment) { + this.elementUtils = processingEnvironment.getElementUtils(); + this.typeUtils = processingEnvironment.getTypeUtils(); + } + + @Override + public String getDefaultNullEnumConstant(TypeElement enumType) { + return null; + } + + @Override + public String getEnumConstant(TypeElement enumType, String enumConstant) { + return enumConstant; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java new file mode 100644 index 0000000000..c135cc9ab2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import javax.lang.model.element.TypeElement; + +import org.mapstruct.util.Experimental; + +/** + * A service provider interface for the mapping between different enum constants + * + * @author Arne Seime + */ +@Experimental("This SPI can have it's signature changed in subsequent releases") +public interface EnumNamingStrategy { + + /** + * Initializes the enum value mapping strategy + * + * @param processingEnvironment environment for facilities + */ + default void init(MapStructProcessingEnvironment processingEnvironment) { + + } + + /** + * Return the default enum constant to use if the source is null. + * + * @param enumType the enum + * @return enum value or null if there is no designated enum constant + */ + String getDefaultNullEnumConstant(TypeElement enumType); + + /** + * Map the enum constant to the value use for matching. + * In case you want this enum constant to match to null return {@link org.mapstruct.MappingConstants#NULL} + * + * @param enumType the enum this constant belongs to + * @param enumConstant constant to transform + * + * @return the transformed constant - or the original value from the parameter if no transformation is needed. + * never return null + */ + String getEnumConstant(TypeElement enumType, String enumConstant); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CheeseType.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CheeseType.java new file mode 100644 index 0000000000..71bde4415a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CheeseType.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +/** + * @author Filip Hrisafov + */ +public enum CheeseType { + + BRIE, + ROQUEFORT +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java new file mode 100644 index 0000000000..6524f67c36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomCheeseMapper { + + CustomCheeseMapper INSTANCE = Mappers.getMapper( CustomCheeseMapper.class ); + + CheeseType map(CustomCheeseType cheese); + + CustomCheeseType map(CheeseType cheese); + + String mapToString(CustomCheeseType cheeseType); + + String mapToString(CheeseType cheeseType); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "CUSTOM_BRIE") + CustomCheeseType mapStringToCustom(String cheese); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "BRIE") + CheeseType mapStringToCheese(String cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseType.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseType.java new file mode 100644 index 0000000000..384df9b3d1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseType.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +/** + * @author Filip Hrisafov + */ +public enum CustomCheeseType implements CustomEnumMarker { + + UNSPECIFIED, + CUSTOM_BRIE, + CUSTOM_ROQUEFORT, + UNRECOGNIZED, +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMarker.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMarker.java new file mode 100644 index 0000000000..b12715e25f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMarker.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +/** + * @author Filip Hrisafov + */ +public interface CustomEnumMarker { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java new file mode 100644 index 0000000000..f84ebaf7b3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; +import org.mapstruct.ap.spi.EnumNamingStrategy; + +/** + * @author Filip Hrisafov + */ +public class CustomEnumNamingStrategy extends DefaultEnumNamingStrategy implements EnumNamingStrategy { + + @Override + public String getDefaultNullEnumConstant(TypeElement enumType) { + if ( isCustomEnum( enumType ) ) { + return "UNSPECIFIED"; + } + + return super.getDefaultNullEnumConstant( enumType ); + } + + @Override + public String getEnumConstant(TypeElement enumType, String enumConstant) { + if ( isCustomEnum( enumType ) ) { + return getCustomEnumConstant( enumConstant ); + } + return super.getEnumConstant( enumType, enumConstant ); + } + + protected String getCustomEnumConstant(String enumConstant) { + if ( "UNRECOGNIZED".equals( enumConstant ) || "UNSPECIFIED".equals( enumConstant ) ) { + return MappingConstantsGem.NULL; + } + + return enumConstant.replace( "CUSTOM_", "" ); + } + + protected boolean isCustomEnum(TypeElement enumType) { + for ( TypeMirror enumTypeInterface : enumType.getInterfaces() ) { + if ( typeUtils.asElement( enumTypeInterface ).getSimpleName().contentEquals( "CustomEnumMarker" ) ) { + return true; + } + } + + return false; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java new file mode 100644 index 0000000000..47a0a5d64e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java @@ -0,0 +1,123 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CheeseType.class, + CustomCheeseType.class, + CustomEnumMarker.class, +}) +@WithServiceImplementation(CustomEnumNamingStrategy.class) +public class CustomEnumNamingStrategyTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ + CustomCheeseMapper.class + }) + public void shouldApplyCustomEnumNamingStrategy() { + generatedSource.addComparisonToFixtureFor( CustomCheeseMapper.class ); + CustomCheeseMapper mapper = CustomCheeseMapper.INSTANCE; + + // CheeseType -> CustomCheeseType + assertThat( mapper.map( (CheeseType) null ) ).isEqualTo( CustomCheeseType.UNSPECIFIED ); + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + assertThat( mapper.map( CheeseType.ROQUEFORT ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + + // CustomCheeseType -> CheeseType + assertThat( mapper.map( (CustomCheeseType) null ) ).isNull(); + assertThat( mapper.map( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.map( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( CheeseType.BRIE ); + assertThat( mapper.map( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // CheeseType -> String + assertThat( mapper.mapToString( (CheeseType) null ) ).isNull(); + assertThat( mapper.mapToString( CheeseType.BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CheeseType.ROQUEFORT ) ).isEqualTo( "ROQUEFORT" ); + + // CustomCheeseType -> String + assertThat( mapper.mapToString( (CustomCheeseType) null ) ).isNull(); + assertThat( mapper.mapToString( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( "ROQUEFORT" ); + assertThat( mapper.mapToString( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // String - > CheeseType + assertThat( mapper.mapStringToCheese( null ) ).isNull(); + assertThat( mapper.mapStringToCheese( "BRIE" ) ).isEqualTo( CheeseType.BRIE ); + assertThat( mapper.mapStringToCheese( "ROQUEFORT" ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "UNKNOWN" ) ).isEqualTo( CheeseType.BRIE ); + + // CustomCheeseType -> String + assertThat( mapper.mapStringToCustom( null ) ).isEqualTo( CustomCheeseType.UNSPECIFIED ); + assertThat( mapper.mapStringToCustom( "UNRECOGNIZED" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + assertThat( mapper.mapStringToCustom( "BRIE" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + assertThat( mapper.mapStringToCustom( "ROQUEFORT" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + } + + @Test + @WithClasses({ + OverridesCustomCheeseMapper.class + }) + public void shouldApplyDefinedMappingsInsteadOfCustomEnumNamingStrategy() { + OverridesCustomCheeseMapper mapper = OverridesCustomCheeseMapper.INSTANCE; + + // CheeseType -> CustomCheeseType + assertThat( mapper.map( (CheeseType) null ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.map( CheeseType.ROQUEFORT ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + + // CustomCheeseType -> CheeseType + assertThat( mapper.map( (CustomCheeseType) null ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.map( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // CheeseType -> String + assertThat( mapper.mapToString( (CheeseType) null ) ).isNull(); + assertThat( mapper.mapToString( CheeseType.BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CheeseType.ROQUEFORT ) ).isEqualTo( "BRIE" ); + + // CustomCheeseType -> String + assertThat( mapper.mapToString( (CustomCheeseType) null ) ).isEqualTo( "ROQUEFORT" ); + assertThat( mapper.mapToString( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // String - > CheeseType + assertThat( mapper.mapStringToCheese( null ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "BRIE" ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "ROQUEFORT" ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "UNKNOWN" ) ).isEqualTo( CheeseType.BRIE ); + + // CustomCheeseType -> String + assertThat( mapper.mapStringToCustom( null ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "UNRECOGNIZED" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + assertThat( mapper.mapStringToCustom( "BRIE" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "ROQUEFORT" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java new file mode 100644 index 0000000000..671ad45c04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; +import org.mapstruct.ap.spi.EnumNamingStrategy; + +/** + * @author Filip Hrisafov + */ +public class CustomErroneousEnumNamingStrategy extends DefaultEnumNamingStrategy implements EnumNamingStrategy { + + @Override + public String getDefaultNullEnumConstant(TypeElement enumType) { + if ( isCustomEnum( enumType ) ) { + return "INCORRECT"; + } + + return super.getDefaultNullEnumConstant( enumType ); + } + + @Override + public String getEnumConstant(TypeElement enumType, String enumConstant) { + if ( isCustomEnum( enumType ) ) { + return getCustomEnumConstant( enumConstant ); + } + return super.getEnumConstant( enumType, enumConstant ); + } + + protected String getCustomEnumConstant(String enumConstant) { + if ( "UNRECOGNIZED".equals( enumConstant ) || "UNSPECIFIED".equals( enumConstant ) ) { + return MappingConstantsGem.NULL; + } + + return enumConstant.replace( "CUSTOM_", "" ); + } + + protected boolean isCustomEnum(TypeElement enumType) { + for ( TypeMirror enumTypeInterface : enumType.getInterfaces() ) { + if ( typeUtils.asElement( enumTypeInterface ).getSimpleName().contentEquals( "CustomEnumMarker" ) ) { + return true; + } + } + + return false; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java new file mode 100644 index 0000000000..82d6be4c26 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java @@ -0,0 +1,102 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CheeseType.class, + CustomCheeseType.class, + CustomEnumMarker.class, +}) +@WithServiceImplementation(CustomErroneousEnumNamingStrategy.class) +public class CustomErroneousEnumNamingStrategyTest { + + @Test + @WithClasses({ + CustomCheeseMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = CustomCheeseMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 23, + messageRegExp = "Constant INCORRECT doesn't exist in enum type " + + "org\\.mapstruct\\.ap\\.test\\.value\\.spi\\.CustomCheeseType." + + " Constant was returned from EnumNamingStrategy: .*CustomErroneousEnumNamingStrategy@.*" + ), + @Diagnostic( + type = CustomCheeseMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 30, + messageRegExp = "Constant INCORRECT doesn't exist in enum type " + + "org\\.mapstruct\\.ap\\.test\\.value\\.spi\\.CustomCheeseType." + + " Constant was returned from EnumNamingStrategy: .*CustomErroneousEnumNamingStrategy@.*" + ) + } + ) + public void shouldThrowCompileErrorWhenDefaultEnumDoesNotExist() { + } + + @Test + @WithClasses({ + OverridesCustomCheeseMapper.class + }) + public void shouldApplyDefinedMappingsInsteadOfCustomEnumNamingStrategy() { + OverridesCustomCheeseMapper mapper = OverridesCustomCheeseMapper.INSTANCE; + + // CheeseType -> CustomCheeseType + assertThat( mapper.map( (CheeseType) null ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.map( CheeseType.ROQUEFORT ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + + // CustomCheeseType -> CheeseType + assertThat( mapper.map( (CustomCheeseType) null ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.map( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.map( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // CheeseType -> String + assertThat( mapper.mapToString( (CheeseType) null ) ).isNull(); + assertThat( mapper.mapToString( CheeseType.BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CheeseType.ROQUEFORT ) ).isEqualTo( "BRIE" ); + + // CustomCheeseType -> String + assertThat( mapper.mapToString( (CustomCheeseType) null ) ).isEqualTo( "ROQUEFORT" ); + assertThat( mapper.mapToString( CustomCheeseType.UNSPECIFIED ) ).isNull(); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_BRIE ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CustomCheeseType.CUSTOM_ROQUEFORT ) ).isEqualTo( "BRIE" ); + assertThat( mapper.mapToString( CustomCheeseType.UNRECOGNIZED ) ).isNull(); + + // String - > CheeseType + assertThat( mapper.mapStringToCheese( null ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "BRIE" ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "ROQUEFORT" ) ).isEqualTo( CheeseType.ROQUEFORT ); + assertThat( mapper.mapStringToCheese( "UNKNOWN" ) ).isEqualTo( CheeseType.BRIE ); + + // CustomCheeseType -> String + assertThat( mapper.mapStringToCustom( null ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "UNRECOGNIZED" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + assertThat( mapper.mapStringToCustom( "BRIE" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "ROQUEFORT" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); + assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/OverridesCustomCheeseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/OverridesCustomCheeseMapper.java new file mode 100644 index 0000000000..ae40d2d98d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/OverridesCustomCheeseMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OverridesCustomCheeseMapper { + + OverridesCustomCheeseMapper INSTANCE = Mappers.getMapper( OverridesCustomCheeseMapper.class ); + + @ValueMapping(source = "CUSTOM_BRIE", target = "ROQUEFORT") + @ValueMapping(source = MappingConstants.NULL, target = "ROQUEFORT") + CheeseType map(CustomCheeseType cheese); + + @ValueMapping(source = "BRIE", target = "CUSTOM_ROQUEFORT") + @ValueMapping(source = MappingConstants.NULL, target = "CUSTOM_ROQUEFORT") + CustomCheeseType map(CheeseType cheese); + + @ValueMapping(source = "CUSTOM_ROQUEFORT", target = "BRIE") + @ValueMapping(source = MappingConstants.NULL, target = "ROQUEFORT") + String mapToString(CustomCheeseType cheeseType); + + @ValueMapping(source = "ROQUEFORT", target = "BRIE") + String mapToString(CheeseType cheeseType); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "CUSTOM_BRIE") + @ValueMapping(source = "BRIE", target = "CUSTOM_ROQUEFORT") + @ValueMapping(source = MappingConstants.NULL, target = "CUSTOM_ROQUEFORT") + CustomCheeseType mapStringToCustom(String cheese); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "BRIE") + @ValueMapping(source = "BRIE", target = "ROQUEFORT") + @ValueMapping(source = MappingConstants.NULL, target = "ROQUEFORT") + CheeseType mapStringToCheese(String cheese); +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java new file mode 100644 index 0000000000..9798c41597 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java @@ -0,0 +1,138 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-05-16T12:53:12+0200", + comments = "version: , compiler: javac, environment: Java 14.0.1 (Oracle Corporation)" +) +public class CustomCheeseMapperImpl implements CustomCheeseMapper { + + @Override + public CheeseType map(CustomCheeseType cheese) { + if ( cheese == null ) { + return null; + } + + CheeseType cheeseType; + + switch ( cheese ) { + case UNSPECIFIED: cheeseType = null; + break; + case CUSTOM_BRIE: cheeseType = CheeseType.BRIE; + break; + case CUSTOM_ROQUEFORT: cheeseType = CheeseType.ROQUEFORT; + break; + case UNRECOGNIZED: cheeseType = null; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return cheeseType; + } + + @Override + public CustomCheeseType map(CheeseType cheese) { + if ( cheese == null ) { + return CustomCheeseType.UNSPECIFIED; + } + + CustomCheeseType customCheeseType; + + switch ( cheese ) { + case BRIE: customCheeseType = CustomCheeseType.CUSTOM_BRIE; + break; + case ROQUEFORT: customCheeseType = CustomCheeseType.CUSTOM_ROQUEFORT; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + } + + return customCheeseType; + } + + @Override + public String mapToString(CustomCheeseType cheeseType) { + if ( cheeseType == null ) { + return null; + } + + String string; + + switch ( cheeseType ) { + case UNSPECIFIED: string = null; + break; + case CUSTOM_BRIE: string = "BRIE"; + break; + case CUSTOM_ROQUEFORT: string = "ROQUEFORT"; + break; + case UNRECOGNIZED: string = null; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheeseType ); + } + + return string; + } + + @Override + public String mapToString(CheeseType cheeseType) { + if ( cheeseType == null ) { + return null; + } + + String string; + + switch ( cheeseType ) { + case BRIE: string = "BRIE"; + break; + case ROQUEFORT: string = "ROQUEFORT"; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheeseType ); + } + + return string; + } + + @Override + public CustomCheeseType mapStringToCustom(String cheese) { + if ( cheese == null ) { + return CustomCheeseType.UNSPECIFIED; + } + + CustomCheeseType customCheeseType; + + switch ( cheese ) { + case "BRIE": customCheeseType = CustomCheeseType.CUSTOM_BRIE; + break; + case "ROQUEFORT": customCheeseType = CustomCheeseType.CUSTOM_ROQUEFORT; + break; + default: customCheeseType = CustomCheeseType.CUSTOM_BRIE; + } + + return customCheeseType; + } + + @Override + public CheeseType mapStringToCheese(String cheese) { + if ( cheese == null ) { + return null; + } + + CheeseType cheeseType; + + switch ( cheese ) { + case "BRIE": cheeseType = CheeseType.BRIE; + break; + case "ROQUEFORT": cheeseType = CheeseType.ROQUEFORT; + break; + default: cheeseType = CheeseType.BRIE; + } + + return cheeseType; + } +} From 850a55cd5dd02687f0c800738a604d5d724084af Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 May 2020 12:01:14 +0200 Subject: [PATCH 0465/1006] #695 Check for direct assignment for iterable, stream or map types should be done on their type parameters instead of the types themselves --- .../creation/MappingResolverImpl.java | 40 ++++++++++++-- .../mappingcontrol/CloningListMapper.java | 19 +++++++ .../ap/test/mappingcontrol/CustomerDto.java | 52 ++++++++++++++++++ .../mappingcontrol/MappingControlTest.java | 53 +++++++++++++++++++ .../ap/test/mappingcontrol/OrderItemDto.java | 31 +++++++++++ .../test/mappingcontrol/OrderItemKeyDto.java | 22 ++++++++ 6 files changed, 212 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CustomerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemKeyDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 47e3e57f62..2875cef67a 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -190,8 +190,9 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { // then direct assignable if ( !hasQualfiers() ) { - if ( ( sourceType.isAssignableTo( targetType ) && allowDirect( sourceType, targetType ) ) || - isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) { + if ( ( sourceType.isAssignableTo( targetType ) || + isAssignableThroughCollectionCopyConstructor( sourceType, targetType ) ) + && allowDirect( sourceType, targetType ) ) { Assignment simpleAssignment = sourceRHS; return simpleAssignment; } @@ -280,11 +281,40 @@ private boolean hasQualfiers() { } private boolean allowDirect( Type sourceType, Type targetType ) { - if ( sourceType.isPrimitive() || targetType.isPrimitive() - || sourceType.isJavaLangType() || targetType.isJavaLangType() ) { + if ( selectionCriteria != null && selectionCriteria.isAllowDirect() ) { return true; } - return selectionCriteria != null && selectionCriteria.isAllowDirect(); + + return allowDirect( sourceType ) || allowDirect( targetType ); + } + + private boolean allowDirect(Type type) { + if ( type.isPrimitive() ) { + return true; + } + + if ( type.isArrayType() ) { + return type.isJavaLangType(); + } + + if ( type.isIterableOrStreamType() ) { + List typeParameters = type.getTypeParameters(); + // For iterable or stream direct mapping is enabled when: + // - The type is raw (no type parameters) + // - The type parameter is allowed + return typeParameters.isEmpty() || allowDirect( Collections.first( typeParameters ) ); + } + + if ( type.isMapType() ) { + List typeParameters = type.getTypeParameters(); + // For map type direct mapping is enabled when: + // - The type os raw (no type parameters + // - The key and value are direct assignable + return typeParameters.isEmpty() || + ( allowDirect( typeParameters.get( 0 ) ) && allowDirect( typeParameters.get( 1 ) ) ); + } + + return type.isJavaLangType(); } private boolean allowConversion() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningListMapper.java new file mode 100644 index 0000000000..5a74527d36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningListMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = DeepClone.class) +public interface CloningListMapper { + + CloningListMapper INSTANCE = Mappers.getMapper( CloningListMapper.class ); + + CustomerDto clone(CustomerDto in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CustomerDto.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CustomerDto.java new file mode 100644 index 0000000000..810d53f41e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CustomerDto.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.util.List; +import java.util.Map; + +/** + * @author Sjaak Derksen + */ +public class CustomerDto { + + private Long id; + private String customerName; + private List orders; + private Map stock; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public List getOrders() { + return orders; + } + + public void setOrders(List orders) { + this.orders = orders; + } + + public Map getStock() { + return stock; + } + + public void setStock(Map stock) { + this.stock = stock; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index a1a1fd6079..5807931ce1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -5,6 +5,11 @@ */ package org.mapstruct.ap.test.mappingcontrol; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -15,6 +20,7 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; /** * @author Sjaak Derksen @@ -25,6 +31,9 @@ ShelveDTO.class, Fridge.class, FridgeDTO.class, + CustomerDto.class, + OrderItemDto.class, + OrderItemKeyDto.class, UseDirect.class, UseComplex.class }) @@ -63,6 +72,49 @@ public void testDeepCloning() { assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" ); } + /** + * Test the deep cloning annotation with lists + */ + @Test + @WithClasses(CloningListMapper.class) + public void testDeepCloningListsAndMaps() { + + CustomerDto in = new CustomerDto(); + in.setId( 10L ); + in.setCustomerName( "Jaques" ); + OrderItemDto order1 = new OrderItemDto(); + order1.setName( "Table" ); + order1.setQuantity( 2L ); + in.setOrders( new ArrayList<>( Collections.singleton( order1 ) ) ); + OrderItemKeyDto key = new OrderItemKeyDto(); + key.setStockNumber( 5 ); + Map stock = new HashMap<>(); + stock.put( key, order1 ); + in.setStock( stock ); + + CustomerDto out = CloningListMapper.INSTANCE.clone( in ); + + assertThat( out.getId() ).isEqualTo( 10 ); + assertThat( out.getCustomerName() ).isEqualTo( "Jaques" ); + assertThat( out.getOrders() ) + .extracting( "name", "quantity" ) + .containsExactly( tuple( "Table", 2L ) ); + assertThat( out.getStock() ).isNotNull(); + assertThat( out.getStock() ).hasSize( 1 ); + + Map.Entry entry = out.getStock().entrySet().iterator().next(); + assertThat( entry.getKey().getStockNumber() ).isEqualTo( 5 ); + assertThat( entry.getValue().getName() ).isEqualTo( "Table" ); + assertThat( entry.getValue().getQuantity() ).isEqualTo( 2L ); + + // check mapper really created new objects + assertThat( out ).isNotSameAs( in ); + assertThat( out.getOrders().get( 0 ) ).isNotSameAs( order1 ); + assertThat( entry.getKey() ).isNotSameAs( key ); + assertThat( entry.getValue() ).isNotSameAs( order1 ); + assertThat( entry.getValue() ).isNotSameAs( out.getOrders().get( 0 ) ); + } + /** * This is a nice test. MapStruct looks for a way to map ShelveDto to ShelveDto. *

      @@ -95,6 +147,7 @@ public void methodSelectionAllowed() { assertThat( fridge ).isNotNull(); assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); + assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemDto.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemDto.java new file mode 100644 index 0000000000..dbaad654d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemDto.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +/** + * @author Sjaak Derksen + */ +public class OrderItemDto { + + private String name; + private Long quantity; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Long getQuantity() { + return quantity; + } + + public void setQuantity(Long quantity) { + this.quantity = quantity; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemKeyDto.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemKeyDto.java new file mode 100644 index 0000000000..6154f4450b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/OrderItemKeyDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +/** + * @author Sjaak Derksen + */ +public class OrderItemKeyDto { + + private long stockNumber; + + public long getStockNumber() { + return stockNumber; + } + + public void setStockNumber(long stockNumber) { + this.stockNumber = stockNumber; + } +} From fc5e1ffe6b4eae155d6e6ad3f806f04f0dfc249a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 May 2020 15:34:54 +0200 Subject: [PATCH 0466/1006] Upgrade to latest 1.6.2 asciidoc and fix incorrect closing documentation tag --- documentation/pom.xml | 8 ++++---- .../ap/test/nestedbeans/exclusions/custom/Source.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/pom.xml b/documentation/pom.xml index 90c3e0b64e..ceb3cb1db6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -21,9 +21,9 @@ MapStruct Documentation - 1.5.0-alpha.11 - 1.5.4 - 1.7.21 + 1.5.3 + 1.6.2 + 9.2.6.0 @@ -33,7 +33,7 @@ org.asciidoctor asciidoctor-maven-plugin - 1.5.3 + 1.6.0 org.asciidoctor diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java index 6cdc3e2752..cf5581c726 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/Source.java @@ -39,4 +39,4 @@ public void setNested(NestedSource nested) { } // tag::documentation[] } -// tag::documentation[] +// end::documentation[] From 72ce5f3bd201d542278f586bc725c6bcc493ae61 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 1 Jun 2020 13:42:32 +0200 Subject: [PATCH 0467/1006] [maven-release-plugin] prepare release 1.4.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c908377c8..0ee850799b 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 63311b5950..54bd288072 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c74e0b8bb1..241ea0ce4e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b404ed3cee..4abb86aa0d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ceb3cb1db6..07b8c23969 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a643bab4b8..c1444a63c1 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b26cf8683d..e151af0d8a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta1 diff --git a/pom.xml b/pom.xml index f9c649c168..f511147688 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta1 diff --git a/processor/pom.xml b/processor/pom.xml index c047301268..afe315d258 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta1 ../parent/pom.xml From d87d75a7a88f1f7fa45312ad54a66772ad4cdec1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 1 Jun 2020 13:42:32 +0200 Subject: [PATCH 0468/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0ee850799b..6c908377c8 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 54bd288072..63311b5950 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 241ea0ce4e..c74e0b8bb1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4abb86aa0d..b404ed3cee 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 07b8c23969..ceb3cb1db6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index c1444a63c1..a643bab4b8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e151af0d8a..b26cf8683d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta1 + HEAD diff --git a/pom.xml b/pom.xml index f511147688..f9c649c168 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index afe315d258..c047301268 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta1 + 1.4.0-SNAPSHOT ../parent/pom.xml From da37d401520ee32889f706cf06308a9ac95338e2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 7 Jun 2020 16:45:32 +0200 Subject: [PATCH 0469/1006] #2109 Generate correct array assignment for constructor parameter mapping --- .../ap/internal/model/BeanMappingMethod.ftl | 16 +----- ...pperForCollectionsAndMapsWithNullCheck.ftl | 4 -- .../ap/test/bugs/_2109/Issue2109Mapper.java | 24 ++++++++ .../ap/test/bugs/_2109/Issue2109Test.java | 55 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2109/Source.java | 28 ++++++++++ .../mapstruct/ap/test/bugs/_2109/Target.java | 28 ++++++++++ .../nestedsource/ArtistToChartEntryImpl.java | 34 ++++-------- .../nestedtarget/ChartEntryToArtistImpl.java | 32 +++++------ 8 files changed, 165 insertions(+), 56 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Target.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 45825b4fd6..c58f9e7581 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -30,31 +30,26 @@ <#list sourceParametersExcludingPrimitives as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> - <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; if ( ${sourceParam.name} != null ) { <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> } - else { - <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> - ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; - - } <#list sourcePrimitiveParameters as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> - <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> <#else> <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> - <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName}; + <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; <#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) { <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> @@ -62,11 +57,6 @@ <#if mapNullToDefault> } - else { - <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> - ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; - - } <#list constructorConstantMappings as constantMapping> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl index 92e2e9d09d..3d6172b49d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.ftl @@ -18,10 +18,6 @@ <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; - <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && !ext.targetBeanName?has_content>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetWriteAccessorName}<@lib.handleWrite>null; - } - <#-- wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Mapper.java new file mode 100644 index 0000000000..7542c2c0cf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Mapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2109; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2109Mapper { + + Issue2109Mapper INSTANCE = Mappers.getMapper( Issue2109Mapper.class ); + + Target map(Source source); + + @Mapping(target = "data", defaultExpression = "java(new byte[0])") + Target mapWithEmptyData(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java new file mode 100644 index 0000000000..6ee44acb97 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2109; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2109") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2109Mapper.class, + Source.class, + Target.class, +}) +public class Issue2109Test { + + @Test + public void shouldCorrectlyMapArrayInConstructorMapping() { + Target target = Issue2109Mapper.INSTANCE.map( new Source( 100L, new byte[] { 100, 120, 40, 40 } ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( 100L ); + assertThat( target.getData() ).containsExactly( 100, 120, 40, 40 ); + + target = Issue2109Mapper.INSTANCE.map( new Source( 50L, null ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( 50L ); + assertThat( target.getData() ).isNull(); + + target = Issue2109Mapper.INSTANCE.mapWithEmptyData( new Source( 100L, new byte[] { 100, 120, 40, 40 } ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( 100L ); + assertThat( target.getData() ).containsExactly( 100, 120, 40, 40 ); + + target = Issue2109Mapper.INSTANCE.mapWithEmptyData( new Source( 50L, null ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( 50L ); + assertThat( target.getData() ).isEmpty(); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Source.java new file mode 100644 index 0000000000..a0aba8ce8b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Source.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2109; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final Long id; + private final byte[] data; + + public Source(Long id, byte[] data) { + this.id = id; + this.data = data; + } + + public Long getId() { + return id; + } + + public byte[] getData() { + return data; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Target.java new file mode 100644 index 0000000000..2e44bc21b6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Target.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2109; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final Long id; + private final byte[] data; + + public Target(Long id, byte[] data) { + this.id = id; + this.data = data; + } + + public Long getId() { + return id; + } + + public byte[] getData() { + return data; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java index bd8c81a5db..09f96b4b3a 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java @@ -26,36 +26,24 @@ public ChartEntry map(Chart chart, Song song, Integer position) { return null; } - String chartName; + String chartName = null; if ( chart != null ) { chartName = chart.getName(); } - else { - chartName = null; - } - String songTitle; - String artistName; - String recordedAt; - String city; + String songTitle = null; + String artistName = null; + String recordedAt = null; + String city = null; if ( song != null ) { songTitle = song.getTitle(); artistName = songArtistName( song ); recordedAt = songArtistLabelStudioName( song ); city = songArtistLabelStudioCity( song ); } - else { - songTitle = null; - artistName = null; - recordedAt = null; - city = null; - } - int position1; + int position1 = 0; if ( position != null ) { position1 = position; } - else { - position1 = 0; - } ChartEntry chartEntry = new ChartEntry( chartName, songTitle, artistName, recordedAt, city, position1 ); @@ -68,10 +56,10 @@ public ChartEntry map(Song song) { return null; } - String songTitle; - String artistName; - String recordedAt; - String city; + String songTitle = null; + String artistName = null; + String recordedAt = null; + String city = null; songTitle = song.getTitle(); artistName = songArtistName( song ); @@ -92,7 +80,7 @@ public ChartEntry map(Chart name) { return null; } - String chartName; + String chartName = null; chartName = name.getName(); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java index f5deb649be..0413ef5b79 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java @@ -27,8 +27,8 @@ public Chart map(ChartEntry chartEntry) { return null; } - Song song; - String name; + Song song = null; + String name = null; song = chartEntryToSong( chartEntry ); name = chartEntry.getChartName(); @@ -46,12 +46,12 @@ public ChartEntry map(Chart chart) { return null; } - String chartName; - String songTitle; - String artistName; - String recordedAt; - String city; - int position; + String chartName = null; + String songTitle = null; + String artistName = null; + String recordedAt = null; + String city = null; + int position = 0; chartName = chart.getName(); songTitle = chartSongTitle( chart ); @@ -70,8 +70,8 @@ protected Studio chartEntryToStudio(ChartEntry chartEntry) { return null; } - String name; - String city; + String name = null; + String city = null; name = chartEntry.getRecordedAt(); city = chartEntry.getCity(); @@ -86,7 +86,7 @@ protected Label chartEntryToLabel(ChartEntry chartEntry) { return null; } - Studio studio; + Studio studio = null; studio = chartEntryToStudio( chartEntry ); @@ -102,8 +102,8 @@ protected Artist chartEntryToArtist(ChartEntry chartEntry) { return null; } - Label label; - String name; + Label label = null; + String name = null; label = chartEntryToLabel( chartEntry ); name = chartEntry.getArtistName(); @@ -118,9 +118,9 @@ protected Song chartEntryToSong(ChartEntry chartEntry) { return null; } - Artist artist; - String title; - List positions; + Artist artist = null; + String title = null; + List positions = null; artist = chartEntryToArtist( chartEntry ); title = chartEntry.getSongTitle(); From 29b82e772ce3cfe5dd330359d2b2a034def46a76 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 14 Jun 2020 21:04:31 +0200 Subject: [PATCH 0470/1006] #2111 extra tests (#2119) --- .../ap/test/bugs/_2111/Issue2111Mapper.java | 45 +++++++++++++++++++ .../ap/test/bugs/_2111/Issue2111Test.java | 26 +++++++++++ 2 files changed, 71 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Mapper.java new file mode 100644 index 0000000000..9bf63385fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Mapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2111; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +import static java.util.Collections.singletonList; + +@Mapper +public interface Issue2111Mapper { + + @Mapping(target = "strs", source = "ex", qualifiedByName = "wrap") + DTO map(UseExample from); + + @Named("wrap") + default String mapExample(Example ex) { + return ex.name; + } + + @Named("wrap") + default List wrapInList(T t) { + return singletonList( t ); + } + + //CHECKSTYLE:OFF + class Example { + public String name; + } + + class UseExample { + public Example ex; + } + + class DTO { + public List strs; + } + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java new file mode 100644 index 0000000000..0d6b9ef771 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2111; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + */ +@IssueKey("2111") +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( Issue2111Mapper.class ) +public class Issue2111Test { + + @Test + public void shouldCompile() { + + } +} From ef3cbc1b36fa0ae0b9518a0dc525b93fe1484797 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Jun 2020 23:12:02 +0200 Subject: [PATCH 0471/1006] #2121 Add extra test case --- .../ap/test/bugs/_2121/Issue2121Mapper.java | 51 +++++++++++++++++++ .../ap/test/bugs/_2121/Issue2121Test.java | 36 +++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Mapper.java new file mode 100644 index 0000000000..f61300c0ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Mapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2121; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2121Mapper { + + Issue2121Mapper INSTANCE = Mappers.getMapper( Issue2121Mapper.class ); + + Target map(Source source); + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + + private final SourceEnum value; + + public Source(SourceEnum value) { + this.value = value; + } + + public SourceEnum getValue() { + return value; + } + } + + enum SourceEnum { + VALUE1, + VALUE2 + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java new file mode 100644 index 0000000000..3d6f6dfca1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2121; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2121") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(Issue2121Mapper.class) +public class Issue2121Test { + + @Test + public void shouldCompile() { + Issue2121Mapper mapper = Issue2121Mapper.INSTANCE; + + Issue2121Mapper.Target target = mapper.map( new Issue2121Mapper.Source( Issue2121Mapper.SourceEnum.VALUE1 ) ); + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "VALUE1" ); + + target = mapper.map( new Issue2121Mapper.Source( null ) ); + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + } +} From bdc58b96025cc5d1e89278ee2b12c3a841c5d156 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Jun 2020 23:24:56 +0200 Subject: [PATCH 0472/1006] #2124 Add extra test case --- .../ap/test/bugs/_2124/CommitComment.java | 22 +++++++++++ .../ap/test/bugs/_2124/Issue2124Mapper.java | 28 ++++++++++++++ .../ap/test/bugs/_2124/Issue2124Test.java | 38 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/CommitComment.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/CommitComment.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/CommitComment.java new file mode 100644 index 0000000000..9067f82c3d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/CommitComment.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2124; + +/** + * @author Filip Hrisafov + */ +public class CommitComment { + + private final Integer issueId; + + public CommitComment(Integer issueId) { + this.issueId = issueId; + } + + public Integer getIssueId() { + return issueId; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Mapper.java new file mode 100644 index 0000000000..af6250c7f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Mapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2124; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2124Mapper { + + Issue2124Mapper INSTANCE = Mappers.getMapper( Issue2124Mapper.class ); + + @Mapping(target = "issueId", source = "comment.issueId", qualifiedByName = "mapped") + CommitComment clone(CommitComment comment, String otherSource); + + @Named("mapped") + default Integer mapIssueNumber(int issueNumber) { + return issueNumber * 2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java new file mode 100644 index 0000000000..5671c78877 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2124; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2124") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CommitComment.class, + Issue2124Mapper.class +}) +public class Issue2124Test { + + @Test + public void shouldCompile() { + + CommitComment clone = Issue2124Mapper.INSTANCE.clone( new CommitComment( 100 ), null ); + assertThat( clone ).isNotNull(); + assertThat( clone.getIssueId() ).isEqualTo( 200 ); + + clone = Issue2124Mapper.INSTANCE.clone( new CommitComment( null ), null ); + assertThat( clone ).isNotNull(); + assertThat( clone.getIssueId() ).isNull(); + } +} From 92b4316abd483528c7282dc34a08e04015d13ed8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Jun 2020 23:47:02 +0200 Subject: [PATCH 0473/1006] #2117 Add extra test case --- .../ap/test/bugs/_2117/Issue2117Mapper.java | 30 ++++++++++++++++ .../ap/test/bugs/_2117/Issue2117Test.java | 36 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Mapper.java new file mode 100644 index 0000000000..06dd72fafd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Mapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2117; + +import java.nio.file.AccessMode; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2117Mapper { + + Issue2117Mapper INSTANCE = Mappers.getMapper( Issue2117Mapper.class ); + + @Mapping(target = "accessMode", source = "accessMode") + Target toTarget(AccessMode accessMode, String otherSource); + + class Target { + // CHECKSTYLE:OFF + public AccessMode accessMode; + // CHECKSTYLE ON + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java new file mode 100644 index 0000000000..fd51fd9384 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2117; + +import java.nio.file.AccessMode; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2117") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2117Mapper.class +}) +public class Issue2117Test { + + @Test + public void shouldCompile() { + + Issue2117Mapper.Target target = Issue2117Mapper.INSTANCE.toTarget( AccessMode.READ, null ); + + assertThat( target ).isNotNull(); + assertThat( target.accessMode ).isEqualTo( AccessMode.READ ); + } +} From 13df6a21bc9931347460201d13d77f6f6df5a30d Mon Sep 17 00:00:00 2001 From: SahinSarkar Date: Sat, 20 Jun 2020 17:20:33 +0530 Subject: [PATCH 0474/1006] Fixed typo in documentation --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 13205caa9b..28d6e9d1e0 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -195,7 +195,7 @@ null check, regardless of the value of the `NullValuePropertyMappingStrategy`, t [TIP] ==== -`NullValuePropertyMappingStrategy` also applies when the presense checker returns `not present`. +`NullValuePropertyMappingStrategy` also applies when the presence checker returns `not present`. ==== [[checking-source-property-for-null-arguments]] From 082704cc551c0b533c77e3a88681b086ec831a0f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Jul 2020 17:27:32 +0200 Subject: [PATCH 0475/1006] #2131 Add extra test case --- .../ap/test/bugs/_2131/Issue2131Mapper.java | 45 +++++++++++++++++++ .../ap/test/bugs/_2131/Issue2131Test.java | 37 +++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Mapper.java new file mode 100644 index 0000000000..a0e0b1df7f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Mapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2131; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface Issue2131Mapper { + + Issue2131Mapper INSTANCE = Mappers.getMapper( Issue2131Mapper.class ); + + TestDto map(TestModel source); + + class TestModel { + private final String name; + + public TestModel(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class TestDto { + private String name; + + public TestDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java new file mode 100644 index 0000000000..80cde5c5bf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2131; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2131") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(Issue2131Mapper.class) +public class Issue2131Test { + + @Test + public void shouldCompile() { + Issue2131Mapper mapper = Issue2131Mapper.INSTANCE; + + Issue2131Mapper.TestDto target = mapper.map( new Issue2131Mapper.TestModel( "test" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "test" ); + + target = mapper.map( new Issue2131Mapper.TestModel( null ) ); + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isNull(); + } +} From 81a88bdb6cc10d0f4c2977ed9f48d3d28aac7fc4 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 4 Jul 2020 18:20:09 +0200 Subject: [PATCH 0476/1006] #2133 @BeanMapping#resultType should not be applied to forged methods (#2134) * #2133 reproducer * #2133 solution --- .../ap/internal/model/BeanMappingMethod.java | 5 +- .../ap/test/bugs/_2133/Issue2133Mapper.java | 75 +++++++++++++++++++ .../ap/test/bugs/_2133/Issue2133Test.java | 23 ++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index ea4f3fbdee..1be610842a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -472,7 +472,10 @@ private void sortPropertyMappingsByDependencies() { } private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters selectionParams) { - if ( selectionParams != null && selectionParams.getResultType() != null ) { + // resultType only applies to method that actually has @BeanMapping annotation, never to forged methods + if ( !( method instanceof ForgedMethod ) + && selectionParams != null + && selectionParams.getResultType() != null ) { return ctx.getTypeFactory().getType( selectionParams.getResultType() ); } return null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Mapper.java new file mode 100644 index 0000000000..484620c0c4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Mapper.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2133; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2133Mapper { + + Issue2133Mapper INSTANCE = Mappers.getMapper( Issue2133Mapper.class ); + + @BeanMapping(resultType = Target.class) + AbstractTarget map(Source source); + + class Source { + + private EmbeddedDto embedded; + + public EmbeddedDto getEmbedded() { + return embedded; + } + + public void setEmbedded(EmbeddedDto embedded) { + this.embedded = embedded; + } + } + + class Target extends AbstractTarget { + } + + abstract class AbstractTarget { + + private EmbeddedEntity embedded; + + public EmbeddedEntity getEmbedded() { + return embedded; + } + + public void setEmbedded(EmbeddedEntity embedded) { + this.embedded = embedded; + } + } + + class EmbeddedDto { + + private String s1; + + public String getS1() { + return s1; + } + + public void setS1(String s1) { + this.s1 = s1; + } + } + + class EmbeddedEntity { + + private String s1; + + public String getS1() { + return s1; + } + + public void setS1(String s1) { + this.s1 = s1; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java new file mode 100644 index 0000000000..8a8e8eebbe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2133; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@IssueKey("2133") +@WithClasses( Issue2133Mapper.class ) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2133Test { + + @Test + public void shouldCompile() { + } + +} From 971abc48c7ed176a0977be8e41903da2b21d6e9c Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 4 Jul 2020 18:49:33 +0200 Subject: [PATCH 0477/1006] #2122 fix for 2 step mapping and generics (#2129) --- .../ap/internal/model/common/Type.java | 53 ++++++++ .../creation/MappingResolverImpl.java | 118 +++++++++--------- .../_2122/Issue2122Method2MethodMapper.java | 103 +++++++++++++++ .../Issue2122Method2TypeConversionMapper.java | 54 ++++++++ .../ap/test/bugs/_2122/Issue2122Test.java | 80 ++++++++++++ .../Issue2122TypeConversion2MethodMapper.java | 54 ++++++++ 6 files changed, 406 insertions(+), 56 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2MethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2TypeConversionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122TypeConversion2MethodMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 0974fe3477..ea27153cca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -24,9 +24,11 @@ import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; +import javax.lang.model.util.SimpleTypeVisitor8; import javax.lang.model.util.Types; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -1073,6 +1075,57 @@ public boolean isLiteral() { return isLiteral; } + /** + * Steps through the declaredType in order to find a match for this typevar Type. It allignes with + * the provided parameterized type where this typeVar type is used. + * + * @param declaredType the type + * @param parameterizedType the parameterized type + * + * @return the matching declared type. + */ + public Type resolveTypeVarToType(Type declaredType, Type parameterizedType) { + if ( isTypeVar() ) { + TypeVarMatcher typeVarMatcher = new TypeVarMatcher( typeUtils, this ); + return typeVarMatcher.visit( parameterizedType.getTypeMirror(), declaredType ); + } + return this; + } + + private static class TypeVarMatcher extends SimpleTypeVisitor8 { + + private TypeVariable typeVarToMatch; + private Types types; + + TypeVarMatcher( Types types, Type typeVarToMatch ) { + super( null ); + this.typeVarToMatch = (TypeVariable) typeVarToMatch.getTypeMirror(); + this.types = types; + } + + @Override + public Type visitTypeVariable(TypeVariable t, Type parameterized) { + if ( types.isSameType( t, typeVarToMatch ) ) { + return parameterized; + } + return super.visitTypeVariable( t, parameterized ); + } + + @Override + public Type visitDeclared(DeclaredType t, Type parameterized) { + if ( types.isAssignable( types.erasure( t ), types.erasure( parameterized.getTypeMirror() ) ) ) { + // if same type, we can cast en assume number of type args are also the same + for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { + Type result = visit( t.getTypeArguments().get( i ), parameterized.getTypeParameters().get( i ) ); + if ( result != null ) { + return result; + } + } + } + return super.visitDeclared( t, parameterized ); + } + } + /** * It strips all the {@code []} from the {@code className}. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 2875cef67a..a42ea3826b 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -23,6 +23,7 @@ import org.mapstruct.ap.internal.conversion.ConversionProvider; import org.mapstruct.ap.internal.conversion.Conversions; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.MapperReference; @@ -43,7 +44,6 @@ import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; -import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; @@ -426,29 +426,31 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { // sourceMethod or builtIn that fits the signature B to C. Only then there is a match. If we have a match // a nested method call can be called. so C = methodY( methodX (A) ) for ( Method methodYCandidate : methodYCandidates ) { - if ( Object.class.getName() - .equals( methodYCandidate.getSourceParameters().get( 0 ).getType().getName() ) ) { + Type ySourceType = methodYCandidate.getSourceParameters().get( 0 ).getType(); + if ( Object.class.getName().equals( ySourceType.getName() ) ) { // java.lang.Object as intermediate result continue; } - methodRefY = - resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(), targetType, true ); - - if ( methodRefY != null ) { - selectionCriteria.setPreferUpdateMapping( false ); - Assignment methodRefX = - resolveViaMethod( sourceType, methodYCandidate.getSourceParameters().get( 0 ).getType(), true ); - selectionCriteria.setPreferUpdateMapping( savedPreferUpdateMapping ); - if ( methodRefX != null ) { - methodRefY.setAssignment( methodRefX ); - methodRefX.setAssignment( sourceRHS ); - break; - } - else { - // both should match; - supportingMethodCandidates.clear(); - methodRefY = null; + ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); + + if ( ySourceType != null ) { + methodRefY = resolveViaMethod( ySourceType, targetType, true ); + if ( methodRefY != null ) { + + selectionCriteria.setPreferUpdateMapping( false ); + Assignment methodRefX = resolveViaMethod( sourceType, ySourceType, true ); + selectionCriteria.setPreferUpdateMapping( savedPreferUpdateMapping ); + if ( methodRefX != null ) { + methodRefY.setAssignment( methodRefX ); + methodRefX.setAssignment( sourceRHS ); + break; + } + else { + // both should match; + supportingMethodCandidates.clear(); + methodRefY = null; + } } } } @@ -475,28 +477,30 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp Assignment methodRefY = null; for ( Method methodYCandidate : methodYCandidates ) { - if ( Object.class.getName() - .equals( methodYCandidate.getSourceParameters().get( 0 ).getType().getName() ) ) { + Type ySourceType = methodYCandidate.getSourceParameters().get( 0 ).getType(); + if ( Object.class.getName().equals( ySourceType.getName() ) ) { // java.lang.Object as intermediate result continue; } - methodRefY = - resolveViaMethod( methodYCandidate.getSourceParameters().get( 0 ).getType(), targetType, true ); - - if ( methodRefY != null ) { - Type targetTypeX = methodYCandidate.getSourceParameters().get( 0 ).getType(); - ConversionAssignment conversionXRef = resolveViaConversion( sourceType, targetTypeX ); - if ( conversionXRef != null ) { - methodRefY.setAssignment( conversionXRef.getAssignment() ); - conversionXRef.getAssignment().setAssignment( sourceRHS ); - conversionXRef.reportMessageWhenNarrowing( messager, this ); - break; - } - else { - // both should match - supportingMethodCandidates.clear(); - methodRefY = null; + ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); + + if ( ySourceType != null ) { + methodRefY = resolveViaMethod( ySourceType, targetType, true ); + if ( methodRefY != null ) { + Type targetTypeX = methodYCandidate.getSourceParameters().get( 0 ).getType(); + ConversionAssignment conversionXRef = resolveViaConversion( sourceType, targetTypeX ); + if ( conversionXRef != null ) { + methodRefY.setAssignment( conversionXRef.getAssignment() ); + conversionXRef.getAssignment().setAssignment( sourceRHS ); + conversionXRef.reportMessageWhenNarrowing( messager, this ); + break; + } + else { + // both should match + supportingMethodCandidates.clear(); + methodRefY = null; + } } } } @@ -524,29 +528,31 @@ private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type // search the other way around for ( Method methodXCandidate : methodXCandidates ) { + Type xTargetType = methodXCandidate.getReturnType(); if ( methodXCandidate.isUpdateMethod() || - Object.class.getName().equals( methodXCandidate.getReturnType().getFullyQualifiedName() ) ) { + Object.class.getName().equals( xTargetType.getFullyQualifiedName() ) ) { // skip update methods || java.lang.Object as intermediate result continue; } - Assignment methodRefX = resolveViaMethod( - sourceType, - methodXCandidate.getReturnType(), - true - ); - if ( methodRefX != null ) { - conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType ); - if ( conversionYRef != null ) { - conversionYRef.getAssignment().setAssignment( methodRefX ); - methodRefX.setAssignment( sourceRHS ); - conversionYRef.reportMessageWhenNarrowing( messager, this ); - break; - } - else { - // both should match; - supportingMethodCandidates.clear(); - conversionYRef = null; + xTargetType = + xTargetType.resolveTypeVarToType( sourceType, methodXCandidate.getParameters().get( 0 ).getType() ); + + if ( xTargetType != null ) { + Assignment methodRefX = resolveViaMethod( sourceType, xTargetType, true ); + if ( methodRefX != null ) { + conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType ); + if ( conversionYRef != null ) { + conversionYRef.getAssignment().setAssignment( methodRefX ); + methodRefX.setAssignment( sourceRHS ); + conversionYRef.reportMessageWhenNarrowing( messager, this ); + break; + } + else { + // both should match; + supportingMethodCandidates.clear(); + conversionYRef = null; + } } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2MethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2MethodMapper.java new file mode 100644 index 0000000000..033a314af2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2MethodMapper.java @@ -0,0 +1,103 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2122; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Bandowski + */ +@Mapper +public interface Issue2122Method2MethodMapper { + + Issue2122Method2MethodMapper INSTANCE = Mappers.getMapper( Issue2122Method2MethodMapper.class ); + + @Mapping(target = "embeddedTarget", source = "value") + @Mapping(target = "embeddedMapTarget", source = "value") + @Mapping(target = "embeddedListListTarget", source = "value") + Target toTarget(Source source); + + EmbeddedTarget toEmbeddedTarget(String value); + + default List singleEntry(T entry) { + return Collections.singletonList( entry ); + } + + default List> singleNestedListEntry(T entry) { + return Collections.singletonList( Collections.singletonList( entry ) ); + } + + default HashMap singleEntryMap(T entry) { + HashMap result = new HashMap<>( ); + result.put( "test", entry ); + return result; + } + + class Source { + String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Target { + List embeddedTarget; + + Map embeddedMapTarget; + + List> embeddedListListTarget; + + public List getEmbeddedTarget() { + return embeddedTarget; + } + + public void setEmbeddedTarget(List embeddedTarget) { + this.embeddedTarget = embeddedTarget; + } + + public Map getEmbeddedMapTarget() { + return embeddedMapTarget; + } + + public void setEmbeddedMapTarget( Map embeddedMapTarget) { + this.embeddedMapTarget = embeddedMapTarget; + } + + public List> getEmbeddedListListTarget() { + return embeddedListListTarget; + } + + public void setEmbeddedListListTarget( + List> embeddedListListTarget) { + this.embeddedListListTarget = embeddedListListTarget; + } + } + + class EmbeddedTarget { + String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2TypeConversionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2TypeConversionMapper.java new file mode 100644 index 0000000000..43d40aa772 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Method2TypeConversionMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2122; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface Issue2122Method2TypeConversionMapper { + + Issue2122Method2TypeConversionMapper INSTANCE = Mappers.getMapper( Issue2122Method2TypeConversionMapper.class ); + + @Mapping(target = "value", source = "strings") + Target toTarget(Source source); + + default T toFirstElement(List entry) { + return entry.get( 0 ); + } + + class Source { + List strings; + + public List getStrings() { + return strings; + } + + public void setStrings(List strings) { + this.strings = strings; + } + } + + class Target { + Integer value; + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java new file mode 100644 index 0000000000..0d42a8f125 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2122; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Christian Bandowski + */ +@IssueKey("2122") +@RunWith(AnnotationProcessorTestRunner.class) + +public class Issue2122Test { + + @Test + @WithClasses( Issue2122Method2MethodMapper.class ) + public void shouldMapMethod2Method() { + Issue2122Method2MethodMapper.Source source = new Issue2122Method2MethodMapper.Source(); + source.setValue( "value" ); + + Issue2122Method2MethodMapper.Target target = Issue2122Method2MethodMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getEmbeddedTarget() ).isNotNull(); + assertThat( target.getEmbeddedTarget() ).hasSize( 1 ) + .element( 0 ) + .extracting( Issue2122Method2MethodMapper.EmbeddedTarget::getValue ).isEqualTo( "value" ); + assertThat( target.getEmbeddedMapTarget() ).isNotNull(); + assertThat( target.getEmbeddedMapTarget() ).hasSize( 1 ); + assertThat( target.getEmbeddedMapTarget().get( "test" ) ) + .extracting( Issue2122Method2MethodMapper.EmbeddedTarget::getValue ).isEqualTo( "value" ); + assertThat( target.getEmbeddedListListTarget() ).isNotNull(); + assertThat( target.getEmbeddedListListTarget() ).hasSize( 1 ); + assertThat( target.getEmbeddedListListTarget().get( 0 ) ).hasSize( 1 ) + .element( 0 ) + .extracting( Issue2122Method2MethodMapper.EmbeddedTarget::getValue ).isEqualTo( "value" ); + } + + @Test + @WithClasses( Issue2122TypeConversion2MethodMapper.class ) + public void shouldMapTypeConversion2Method() { + Issue2122TypeConversion2MethodMapper.Source source = new Issue2122TypeConversion2MethodMapper.Source(); + source.setValue( 5 ); + + Issue2122TypeConversion2MethodMapper.Target target = + Issue2122TypeConversion2MethodMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getStrings() ).isNotNull(); + assertThat( target.getStrings() ).hasSize( 1 ) + .element( 0 ) + .isEqualTo( "5" ); + } + + @Test + @WithClasses( Issue2122Method2TypeConversionMapper.class ) + public void shouldMapMethod2TypeConversion() { + Issue2122Method2TypeConversionMapper.Source source = new Issue2122Method2TypeConversionMapper.Source(); + source.setStrings( Collections.singletonList( "5" ) ); + + Issue2122Method2TypeConversionMapper.Target target = + Issue2122Method2TypeConversionMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( 5 ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122TypeConversion2MethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122TypeConversion2MethodMapper.java new file mode 100644 index 0000000000..2555f53dee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122TypeConversion2MethodMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2122; + +import java.util.Collections; +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface Issue2122TypeConversion2MethodMapper { + + Issue2122TypeConversion2MethodMapper INSTANCE = Mappers.getMapper( Issue2122TypeConversion2MethodMapper.class ); + + @Mapping(target = "strings", source = "value") + Target toTarget(Source source); + + default List singleEntry(T entry) { + return Collections.singletonList( entry ); + } + + class Source { + Integer value; + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + } + + class Target { + List strings; + + public List getStrings() { + return strings; + } + + public void setStrings(List strings) { + this.strings = strings; + } + } + +} From 1ce282362cba827d985bcb18a720708b5336c2e3 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 4 Jul 2020 21:50:20 +0200 Subject: [PATCH 0478/1006] #2101 inherited properties need to be analysed against redefined properties when inheriting mappings (#2103) --- .../model/source/MappingMethodOptions.java | 51 ++++++++++++-- .../processor/MapperCreationProcessor.java | 16 ++--- .../bugs/_2101/Issue2101AdditionalMapper.java | 45 +++++++++++++ .../ap/test/bugs/_2101/Issue2101Mapper.java | 49 ++++++++++++++ .../ap/test/bugs/_2101/Issue2101Test.java | 67 +++++++++++++++++++ 5 files changed, 212 insertions(+), 16 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101AdditionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 6c5cc1d04b..4a06acdd4b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -6,15 +6,16 @@ package org.mapstruct.ap.internal.model.source; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.accessor.Accessor; import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy; @@ -136,9 +137,8 @@ public void markAsFullyInitialized() { * * @param templateMethod the template method with the options to inherit, may be {@code null} * @param isInverse if {@code true}, the specified options are from an inverse method - * @param method the source method */ - public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse, SourceMethod method ) { + public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse) { MappingMethodOptions templateOptions = templateMethod.getOptions(); if ( null != templateOptions ) { if ( !getIterableMapping().hasAnnotation() && templateOptions.getIterableMapping().hasAnnotation() ) { @@ -200,13 +200,56 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } // now add all (does not override duplicates and leaves original mappings) - mappings.addAll( newMappings ); + addAllNonRedefined( newMappings ); // filter new mappings filterNestedTargetIgnores( mappings ); } } + private void addAllNonRedefined(Set inheritedMappings) { + Set redefinedSources = new HashSet<>(); + Set redefinedTargets = new HashSet<>(); + for ( MappingOptions redefinedMappings : mappings ) { + if ( redefinedMappings.getSourceName() != null ) { + redefinedSources.add( redefinedMappings.getSourceName() ); + } + if ( redefinedMappings.getTargetName() != null ) { + redefinedTargets.add( redefinedMappings.getTargetName() ); + } + } + for ( MappingOptions inheritedMapping : inheritedMappings ) { + if ( inheritedMapping.isIgnored() + || ( !isRedefined( redefinedSources, inheritedMapping.getSourceName() ) + && !isRedefined( redefinedTargets, inheritedMapping.getTargetName() ) ) + ) { + mappings.add( inheritedMapping ); + } + } + } + + private boolean isRedefined(Set redefinedNames, String inheritedName ) { + for ( String redefinedName : redefinedNames ) { + if ( elementsAreContainedIn( redefinedName, inheritedName ) ) { + return true; + } + } + return false; + } + + private boolean elementsAreContainedIn( String redefinedName, String inheritedName ) { + if ( redefinedName.startsWith( inheritedName ) ) { + // it is possible to redefine an exact matching source name, because the same source can be mapped to + // multiple targets. It is not possible for target, but caught by the Set and equals methoded in + // MappingOptions + if ( redefinedName.length() > inheritedName.length() ) { + // redefined.lenght() > inherited.length(), first following character should be separator + return '.' == redefinedName.charAt( inheritedName.length() ); + } + } + return false; + } + public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); Type writeType = method.getResultType(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index c22377f984..e480eaf7a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -447,10 +447,10 @@ private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConf // apply defined (@InheritConfiguration, @InheritInverseConfiguration) mappings if ( forwardTemplateMethod != null ) { - mappingOptions.applyInheritedOptions( forwardTemplateMethod, false, method ); + mappingOptions.applyInheritedOptions( forwardTemplateMethod, false ); } if ( inverseTemplateMethod != null ) { - mappingOptions.applyInheritedOptions( inverseTemplateMethod, true, method ); + mappingOptions.applyInheritedOptions( inverseTemplateMethod, true ); } // apply auto inherited options @@ -460,11 +460,7 @@ private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConf // but.. there should not be an @InheritedConfiguration if ( forwardTemplateMethod == null && inheritanceStrategy.isApplyForward() ) { if ( applicablePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( - first( applicablePrototypeMethods ), - false, - method - ); + mappingOptions.applyInheritedOptions( first( applicablePrototypeMethods ), false ); } else if ( applicablePrototypeMethods.size() > 1 ) { messager.printMessage( @@ -477,11 +473,7 @@ else if ( applicablePrototypeMethods.size() > 1 ) { // or no @InheritInverseConfiguration if ( inverseTemplateMethod == null && inheritanceStrategy.isApplyReverse() ) { if ( applicableReversePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( - first( applicableReversePrototypeMethods ), - true, - method - ); + mappingOptions.applyInheritedOptions( first( applicableReversePrototypeMethods ), true ); } else if ( applicableReversePrototypeMethods.size() > 1 ) { messager.printMessage( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101AdditionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101AdditionalMapper.java new file mode 100644 index 0000000000..ea745d6bc1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101AdditionalMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2101; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2101AdditionalMapper { + + Issue2101AdditionalMapper INSTANCE = Mappers.getMapper( Issue2101AdditionalMapper.class ); + + @Mapping(target = "value1", source = "value.nestedValue1") + @Mapping(target = "value2", source = "value.nestedValue2") + @Mapping(target = "value3", source = "valueThrowOffPath") + Target map1(Source source); + + @InheritConfiguration + @Mapping(target = "value2", source = "value.nestedValue1") + @Mapping(target = "value3", constant = "test") + Target map2(Source source); + + //CHECKSTYLE:OFF + class Source { + public String valueThrowOffPath; + public NestedSource value; + } + + class Target { + public String value1; + public String value2; + public String value3; + } + + class NestedSource { + public String nestedValue1; + public String nestedValue2; + } + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Mapper.java new file mode 100644 index 0000000000..5a1f01fa72 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Mapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2101; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2101Mapper { + + Issue2101Mapper INSTANCE = Mappers.getMapper( Issue2101Mapper.class ); + + @Mapping(target = "value1", source = "codeValue1") + @Mapping(target = "value2", source = "codeValue2") + Source map(Target target); + + @InheritInverseConfiguration + @Mapping(target = "codeValue1.code", constant = "c1") + @Mapping(target = "codeValue1.value", source = "value1") + @Mapping(target = "codeValue2.code", constant = "c2") + @Mapping(target = "codeValue2.value", source = "value2") + Target map(Source source); + + default String mapFrom( CodeValuePair cv ) { + return cv.code; + } + + //CHECKSTYLE:OFF + class Source { + public String value1; + public String value2; + } + + class Target { + public CodeValuePair codeValue1; + public CodeValuePair codeValue2; + } + + class CodeValuePair { + public String code; + public String value; + } + //CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java new file mode 100644 index 0000000000..36c2c32134 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2101; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2101") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2101Test { + + @Test + @WithClasses(Issue2101Mapper.class) + public void shouldMap() { + + Issue2101Mapper.Source source = new Issue2101Mapper.Source(); + source.value1 = "v1"; + source.value2 = "v2"; + + Issue2101Mapper.Target target = Issue2101Mapper.INSTANCE.map( source ); + + assertThat( target.codeValue1.code ).isEqualTo( "c1" ); + assertThat( target.codeValue1.value ).isEqualTo( "v1" ); + assertThat( target.codeValue2.code ).isEqualTo( "c2" ); + assertThat( target.codeValue2.value ).isEqualTo( "v2" ); + + } + + @Test + @WithClasses(Issue2101AdditionalMapper.class) + public void shouldMapSomeAdditionalTests1() { + Issue2101AdditionalMapper.Source source = new Issue2101AdditionalMapper.Source(); + source.value = new Issue2101AdditionalMapper.NestedSource(); + source.value.nestedValue1 = "value1"; + source.value.nestedValue2 = "value2"; + source.valueThrowOffPath = "value3"; + + Issue2101AdditionalMapper.Target target = Issue2101AdditionalMapper.INSTANCE.map1( source ); + assertThat( target.value1 ).isEqualTo( "value1" ); + assertThat( target.value2 ).isEqualTo( "value2" ); + assertThat( target.value3 ).isEqualTo( "value3" ); + } + + @Test + @WithClasses(Issue2101AdditionalMapper.class) + public void shouldMapSomeAdditionalTests2() { + Issue2101AdditionalMapper.Source source = new Issue2101AdditionalMapper.Source(); + source.value = new Issue2101AdditionalMapper.NestedSource(); + source.value.nestedValue1 = "value1"; + source.value.nestedValue2 = "value2"; + source.valueThrowOffPath = "value3"; + + Issue2101AdditionalMapper.Target target = Issue2101AdditionalMapper.INSTANCE.map2( source ); + assertThat( target.value1 ).isEqualTo( "value1" ); + assertThat( target.value2 ).isEqualTo( "value1" ); + assertThat( target.value3 ).isEqualTo( "test" ); + + } +} From 12ac3486096bf8b4e7a1e14137f560f03c8083ed Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 4 Jul 2020 22:06:30 +0200 Subject: [PATCH 0479/1006] #2136 performance improvement 2 step mappings (#2138) --- .../creation/MappingResolverImpl.java | 68 +++++++++++++------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index a42ea3826b..67eebbb30b 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -39,6 +39,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; @@ -376,32 +377,56 @@ private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean co return null; } + /** + * Applies matching to given method only + * + * @param sourceType the source type + * @param targetType the target type + * @param method the method to match + * @return an assignment if a match, given the criteria could be found. When the method is a + * buildIn method, all the bookkeeping is applied. + */ + private Assignment applyMatching(Type sourceType, Type targetType, Method method) { + + if ( method instanceof SourceMethod ) { + SelectedMethod selectedMethod = + getBestMatch( java.util.Collections.singletonList( method ), sourceType, targetType ); + return selectedMethod != null ? getMappingMethodReference( selectedMethod ) : null; + } + else if ( method instanceof BuiltInMethod ) { + return resolveViaBuiltInMethod( sourceType, targetType ); + } + return null; + } + private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { SelectedMethod matchingBuiltInMethod = getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType ); if ( matchingBuiltInMethod != null ) { - - Set allUsedFields = new HashSet<>( mapperReferences ); - SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); - SupportingMappingMethod supportingMappingMethod = - new SupportingMappingMethod( matchingBuiltInMethod.getMethod(), allUsedFields ); - supportingMethodCandidates.add( supportingMappingMethod ); - ConversionContext ctx = new DefaultConversionContext( - typeFactory, - messager, - sourceType, - targetType, - formattingParameters - ); - Assignment methodReference = MethodReference.forBuiltInMethod( matchingBuiltInMethod.getMethod(), ctx ); - methodReference.setAssignment( sourceRHS ); - return methodReference; + return createFromBuiltInMethod( matchingBuiltInMethod.getMethod() ); } return null; } + private Assignment createFromBuiltInMethod(BuiltInMethod method) { + Set allUsedFields = new HashSet<>( mapperReferences ); + SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); + SupportingMappingMethod supportingMappingMethod = new SupportingMappingMethod( method, allUsedFields ); + supportingMethodCandidates.add( supportingMappingMethod ); + ConversionContext ctx = new DefaultConversionContext( + typeFactory, + messager, + method.getSourceParameters().get( 0 ).getType(), + method.getResultType(), + formattingParameters + ); + Assignment methodReference = MethodReference.forBuiltInMethod( method, ctx ); + methodReference.setAssignment( sourceRHS ); + return methodReference; + } + /** * Suppose mapping required from A to C and: *

        @@ -435,7 +460,7 @@ private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); if ( ySourceType != null ) { - methodRefY = resolveViaMethod( ySourceType, targetType, true ); + methodRefY = applyMatching( ySourceType, targetType, methodYCandidate ); if ( methodRefY != null ) { selectionCriteria.setPreferUpdateMapping( false ); @@ -486,10 +511,9 @@ private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetTyp ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); if ( ySourceType != null ) { - methodRefY = resolveViaMethod( ySourceType, targetType, true ); + methodRefY = applyMatching( ySourceType, targetType, methodYCandidate ); if ( methodRefY != null ) { - Type targetTypeX = methodYCandidate.getSourceParameters().get( 0 ).getType(); - ConversionAssignment conversionXRef = resolveViaConversion( sourceType, targetTypeX ); + ConversionAssignment conversionXRef = resolveViaConversion( sourceType, ySourceType ); if ( conversionXRef != null ) { methodRefY.setAssignment( conversionXRef.getAssignment() ); conversionXRef.getAssignment().setAssignment( sourceRHS ); @@ -539,9 +563,9 @@ private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type xTargetType.resolveTypeVarToType( sourceType, methodXCandidate.getParameters().get( 0 ).getType() ); if ( xTargetType != null ) { - Assignment methodRefX = resolveViaMethod( sourceType, xTargetType, true ); + Assignment methodRefX = applyMatching( sourceType, xTargetType, methodXCandidate ); if ( methodRefX != null ) { - conversionYRef = resolveViaConversion( methodXCandidate.getReturnType(), targetType ); + conversionYRef = resolveViaConversion( xTargetType, targetType ); if ( conversionYRef != null ) { conversionYRef.getAssignment().setAssignment( methodRefX ); methodRefX.setAssignment( sourceRHS ); From fc4f65ddb67ccdfdfc112f969e6507b8bd700895 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jul 2020 23:11:41 +0200 Subject: [PATCH 0480/1006] [maven-release-plugin] prepare release 1.4.0.Beta2 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c908377c8..b2289c2213 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 63311b5950..762d94f36f 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c74e0b8bb1..5060618d5a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b404ed3cee..87d025ac2c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ceb3cb1db6..80ff15c786 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a643bab4b8..c33feee073 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b26cf8683d..978d3f5476 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta2 diff --git a/pom.xml b/pom.xml index f9c649c168..14893a3d9d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta2 diff --git a/processor/pom.xml b/processor/pom.xml index c047301268..680f2564cb 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta2 ../parent/pom.xml From 2fede3583d109cb2f6827ebbcb8c9cfaf0463f51 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jul 2020 23:11:41 +0200 Subject: [PATCH 0481/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index b2289c2213..6c908377c8 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 762d94f36f..63311b5950 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 5060618d5a..c74e0b8bb1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 87d025ac2c..b404ed3cee 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 80ff15c786..ceb3cb1db6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index c33feee073..a643bab4b8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 978d3f5476..b26cf8683d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta2 + HEAD diff --git a/pom.xml b/pom.xml index 14893a3d9d..f9c649c168 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta2 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 680f2564cb..c047301268 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta2 + 1.4.0-SNAPSHOT ../parent/pom.xml From c0d88f86bf4d3de7f2f13a1c8e013d4473039142 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 5 Jul 2020 14:41:08 +0200 Subject: [PATCH 0482/1006] #2139 reproducer (#2140) * #2139 reproducer * #2139 solution * #2139 license --- .../model/source/MappingMethodOptions.java | 4 +- .../ap/test/bugs/_2101/Issue2101Test.java | 16 ++++++++ .../_2101/Issue2102IgnoreAllButMapper.java | 38 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2102IgnoreAllButMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 4a06acdd4b..e0007949a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -238,10 +238,10 @@ private boolean isRedefined(Set redefinedNames, String inheritedName ) { } private boolean elementsAreContainedIn( String redefinedName, String inheritedName ) { - if ( redefinedName.startsWith( inheritedName ) ) { + if ( inheritedName != null && redefinedName.startsWith( inheritedName ) ) { // it is possible to redefine an exact matching source name, because the same source can be mapped to // multiple targets. It is not possible for target, but caught by the Set and equals methoded in - // MappingOptions + // MappingOptions. SourceName == null also could hint at redefinition if ( redefinedName.length() > inheritedName.length() ) { // redefined.lenght() > inherited.length(), first following character should be separator return '.' == redefinedName.charAt( inheritedName.length() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java index 36c2c32134..9148184b25 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java @@ -64,4 +64,20 @@ public void shouldMapSomeAdditionalTests2() { assertThat( target.value3 ).isEqualTo( "test" ); } + + @Test + @WithClasses(Issue2102IgnoreAllButMapper.class) + public void shouldApplyIgnoreAllButTemplateOfMethod1() { + + Issue2102IgnoreAllButMapper.Source source = new Issue2102IgnoreAllButMapper.Source(); + source.value1 = "value1"; + source.value2 = "value2"; + + Issue2102IgnoreAllButMapper.Target target = Issue2102IgnoreAllButMapper.INSTANCE.map1( source ); + assertThat( target.value1 ).isEqualTo( "value1" ); + + target = Issue2102IgnoreAllButMapper.INSTANCE.map2( source ); + assertThat( target.value1 ).isEqualTo( "value2" ); + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2102IgnoreAllButMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2102IgnoreAllButMapper.java new file mode 100644 index 0000000000..9634ed310b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2102IgnoreAllButMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2101; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2102IgnoreAllButMapper { + + Issue2102IgnoreAllButMapper INSTANCE = Mappers.getMapper( Issue2102IgnoreAllButMapper.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping(target = "value1") // but do map value1 + Target map1(Source source); + + @InheritConfiguration + @Mapping(target = "value1", source = "value2" ) + Target map2(Source source); + + //CHECKSTYLE:OFF + class Source { + public String value1; + public String value2; + } + + class Target { + public String value1; + } + //CHECKSTYLE:ON + +} From 74f281fa3e7359bcac4f86c3221ae5c392013a67 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 5 Jul 2020 22:22:01 +0200 Subject: [PATCH 0483/1006] #2135 improved messages for not able to select qualified method (#2141) * #2135 improved messages for not able to select qualified method --- .../creation/MappingResolverImpl.java | 52 +++++++++-- .../mapstruct/ap/internal/util/Message.java | 7 +- .../ap/internal/util/MessageConstants.java | 15 ++++ .../selection/qualifier/QualifierTest.java | 4 +- ...eousMessageByAnnotationAndNamedMapper.java | 54 +++++++++++ .../ErroneousMessageByAnnotationMapper.java | 45 ++++++++++ .../errors/ErroneousMessageByNamedMapper.java | 45 ++++++++++ .../qualifier/errors/QualfierMessageTest.java | 90 +++++++++++++++++++ 8 files changed, 302 insertions(+), 10 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationAndNamedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 67eebbb30b..5427ddefa9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -10,8 +10,11 @@ import java.util.List; import java.util.Set; import java.util.function.Supplier; +import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Name; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; @@ -48,6 +51,7 @@ import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.MessageConstants; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; @@ -260,13 +264,7 @@ && allowDirect( sourceType, targetType ) ) { } if ( hasQualfiers() ) { - messager.printMessage( - mappingMethod.getExecutable(), - positionHint, - Message.GENERAL_NO_QUALIFYING_METHOD, - Strings.join( selectionCriteria.getQualifiers(), ", " ), - Strings.join( selectionCriteria.getQualifiedByNames(), ", " ) - ); + printQualifierMessage( selectionCriteria ); } else if ( allowMappingMethod() ) { // only forge if we would allow mapping method @@ -281,6 +279,46 @@ private boolean hasQualfiers() { return selectionCriteria != null && selectionCriteria.hasQualfiers(); } + private void printQualifierMessage(SelectionCriteria selectionCriteria ) { + + List annotations = selectionCriteria.getQualifiers().stream() + .filter( DeclaredType.class::isInstance ) + .map( DeclaredType.class::cast ) + .map( DeclaredType::asElement ) + .map( Element::getSimpleName ) + .map( Name::toString ) + .map( a -> "@" + a ) + .collect( Collectors.toList() ); + List names = selectionCriteria.getQualifiedByNames(); + + if ( !annotations.isEmpty() && !names.isEmpty() ) { + messager.printMessage( + mappingMethod.getExecutable(), + positionHint, + Message.GENERAL_NO_QUALIFYING_METHOD_COMBINED, + Strings.join( names, MessageConstants.AND ), + Strings.join( annotations, MessageConstants.AND ) + ); + } + else if ( !annotations.isEmpty() ) { + messager.printMessage( + mappingMethod.getExecutable(), + positionHint, + Message.GENERAL_NO_QUALIFYING_METHOD_ANNOTATION, + Strings.join( annotations, MessageConstants.AND ) + ); + } + else { + messager.printMessage( + mappingMethod.getExecutable(), + positionHint, + Message.GENERAL_NO_QUALIFYING_METHOD_NAMED, + Strings.join( names, MessageConstants.AND ) + ); + } + + } + private boolean allowDirect( Type sourceType, Type targetType ) { if ( selectionCriteria != null && selectionCriteria.isAllowDirect() ) { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4c46c09917..ae66d38776 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -7,6 +7,8 @@ import javax.tools.Diagnostic; +import static org.mapstruct.ap.internal.util.MessageConstants.FAQ_QUALIFIER_URL; + /** * A message used in warnings/errors raised by the annotation processor. * @@ -119,7 +121,9 @@ public enum Message { GENERAL_JODA_NOT_ON_CLASSPATH( "Cannot validate Joda dateformat, no Joda on classpath. Consider adding Joda to the annotation processorpath.", Diagnostic.Kind.WARNING ), GENERAL_NOT_ALL_FORGED_CREATED( "Internal Error in creation of Forged Methods, it was expected all Forged Methods to finished with creation, but %s did not" ), GENERAL_NO_SUITABLE_CONSTRUCTOR( "%s does not have an accessible constructor." ), - GENERAL_NO_QUALIFYING_METHOD( "No qualifying method found for qualifiers: %s and / or qualifying names: %s" ), + GENERAL_NO_QUALIFYING_METHOD_ANNOTATION( "Qualifier error. No method found annotated with: [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), + GENERAL_NO_QUALIFYING_METHOD_NAMED( "Qualifier error. No method found annotated with @Named#value: [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), + GENERAL_NO_QUALIFYING_METHOD_COMBINED( "Qualifier error. No method found annotated with @Named#value: [ %s ], annotated with [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), BUILDER_NO_BUILD_METHOD_FOUND("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\".", Diagnostic.Kind.ERROR ), @@ -162,6 +166,7 @@ public enum Message { VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); // CHECKSTYLE:ON + private final String description; private final Diagnostic.Kind kind; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java new file mode 100644 index 0000000000..d3dabdb2d8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +public final class MessageConstants { + + public static final String AND = " and "; + public static final String FAQ_QUALIFIER_URL = "https://mapstruct.org/faq/#qualifier"; + + private MessageConstants() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 912affa1a3..37ecfb1be6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -103,8 +103,8 @@ public void shouldMatchClassAndMethod() { kind = Kind.ERROR, line = 28, message = - "No qualifying method found for qualifiers: org.mapstruct.ap.test.selection.qualifier.annotation" + - ".NonQualifierAnnotated and / or qualifying names: "), + "Qualifier error. No method found annotated with: [ @NonQualifierAnnotated ]. " + + "See https://mapstruct.org/faq/#qualifier for more info."), @Diagnostic( type = ErroneousMapper.class, kind = Kind.ERROR, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationAndNamedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationAndNamedMapper.java new file mode 100644 index 0000000000..acf9674fe2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationAndNamedMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.errors; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Qualifier; + +@Mapper +public interface ErroneousMessageByAnnotationAndNamedMapper { + + @Mapping(target = "nested", source = "value", qualifiedBy = { + SelectMe1.class, + SelectMe2.class + }, qualifiedByName = { "selectMe1", "selectMe2" }) + Target map(Source source); + + default Nested map(String in) { + return null; + } + + // CHECKSTYLE:OFF + class Source { + public String value; + } + + class Target { + public Nested nested; + } + + class Nested { + public String value; + } + // CHECKSTYLE ON + + @Qualifier + @java.lang.annotation.Target(ElementType.METHOD) + @Retention(RetentionPolicy.CLASS) + public @interface SelectMe1 { + } + + @Qualifier + @java.lang.annotation.Target(ElementType.METHOD) + @Retention(RetentionPolicy.CLASS) + public @interface SelectMe2 { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationMapper.java new file mode 100644 index 0000000000..d5aa391f15 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByAnnotationMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.errors; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Qualifier; + +@Mapper +public interface ErroneousMessageByAnnotationMapper { + + @Mapping(target = "nested", source = "value", qualifiedBy = SelectMe.class) + Target map(Source source); + + default Nested map(String in) { + return null; + } + + // CHECKSTYLE:OFF + class Source { + public String value; + } + + class Target { + public Nested nested; + } + + class Nested { + public String value; + } + // CHECKSTYLE ON + + @Qualifier + @java.lang.annotation.Target(ElementType.METHOD) + @Retention(RetentionPolicy.CLASS) + public @interface SelectMe { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedMapper.java new file mode 100644 index 0000000000..44f0a57760 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.errors; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Qualifier; + +@Mapper +public interface ErroneousMessageByNamedMapper { + + @Mapping(target = "nested", source = "value", qualifiedByName = "SelectMe") + Target map(Source source); + + default Nested map(String in) { + return null; + } + + // CHECKSTYLE:OFF + class Source { + public String value; + } + + class Target { + public Nested nested; + } + + class Nested { + public String value; + } + // CHECKSTYLE ON + + @Qualifier + @java.lang.annotation.Target(ElementType.METHOD) + @Retention(RetentionPolicy.CLASS) + public @interface SelectMe { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java new file mode 100644 index 0000000000..4c8edc64dd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java @@ -0,0 +1,90 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.errors; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static javax.tools.Diagnostic.Kind.ERROR; + +@IssueKey("2135") +@RunWith(AnnotationProcessorTestRunner.class) +public class QualfierMessageTest { + + @Test + @WithClasses(ErroneousMessageByAnnotationMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMessageByAnnotationMapper.class, + kind = ERROR, + line = 19, + message = "Qualifier error. No method found annotated with: [ @SelectMe ]. " + + "See https://mapstruct.org/faq/#qualifier for more info."), + @Diagnostic( + type = ErroneousMessageByAnnotationMapper.class, + kind = ERROR, + line = 19, + messageRegExp = "Can't map property.*") + + } + ) + public void testNoQualifyingMethodByAnnotationFound() { + } + + @Test + @WithClasses(ErroneousMessageByNamedMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMessageByNamedMapper.class, + kind = ERROR, + line = 19, + message = "Qualifier error. No method found annotated with @Named#value: [ SelectMe ]. " + + "See https://mapstruct.org/faq/#qualifier for more info."), + @Diagnostic( + type = ErroneousMessageByNamedMapper.class, + kind = ERROR, + line = 19, + messageRegExp = "Can't map property.*") + + } + ) + public void testNoQualifyingMethodByNamedFound() { + } + + @Test + @WithClasses(ErroneousMessageByAnnotationAndNamedMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMessageByAnnotationAndNamedMapper.class, + kind = ERROR, + line = 19, + message = + "Qualifier error. No method found annotated with @Named#value: [ selectMe1 and selectMe2 ], " + + "annotated with [ @SelectMe1 and @SelectMe2 ]. " + + "See https://mapstruct.org/faq/#qualifier for more info."), + @Diagnostic( + type = ErroneousMessageByAnnotationAndNamedMapper.class, + kind = ERROR, + line = 19, + messageRegExp = "Can't map property.*") + + } + ) + public void testNoQualifyingMethodByAnnotationAndNamedFound() { + } +} From 2a849dca12c6547a56de6cd68d49bad1ca53390a Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Thu, 16 Jul 2020 13:49:49 +0200 Subject: [PATCH 0484/1006] #2145 fixing 2 step mapping methods (refactoring) (#2146) --- .../ap/internal/model/common/Type.java | 18 + .../ap/internal/model/source/Method.java | 14 + .../internal/model/source/SourceMethod.java | 12 +- .../model/source/builtin/BuiltInMethod.java | 20 +- .../model/source/builtin/JaxbElemToValue.java | 10 +- .../model/source/selector/SelectedMethod.java | 18 + .../selector/XmlElementDeclSelector.java | 2 +- .../creation/MappingResolverImpl.java | 749 +++++++++++------- .../ap/internal/util/Collections.java | 13 + .../mapstruct/ap/internal/util/Message.java | 4 + .../ap/test/bugs/_2145/Issue2145Mapper.java | 85 ++ .../ap/test/bugs/_2145/Issue2145Test.java | 34 + .../twosteperror/ErroneousMapperCM.java | 56 ++ .../twosteperror/ErroneousMapperMC.java | 52 ++ .../twosteperror/ErroneousMapperMM.java | 74 ++ .../twosteperror/TwoStepMappingTest.java | 79 ++ 16 files changed, 946 insertions(+), 294 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperCM.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMM.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ea27153cca..a829fa61a2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -482,6 +482,24 @@ public boolean isAssignableTo(Type other) { return typeUtils.isAssignable( typeMirrorToMatch, other.typeMirror ); } + /** + * Whether this type is raw assignable to the given other type. We can't make a verdict on typevars, + * they need to be resolved first. + * + * @param other The other type. + * + * @return {@code true} if and only if this type is assignable to the given other type. + */ + public boolean isRawAssignableTo(Type other) { + if ( isTypeVar() || other.isTypeVar() ) { + return true; + } + if ( equals( other ) ) { + return true; + } + return typeUtils.isAssignable( typeUtils.erasure( typeMirror ), typeUtils.erasure( other.typeMirror ) ); + } + /** * getPropertyReadAccessors * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 3930dc76b1..39d827d975 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -187,4 +187,18 @@ public interface Method { default boolean isMappingTargetAssignableToReturnType() { return isUpdateMethod() && getResultType().isAssignableTo( getReturnType() ); } + + /** + * @return the first source type, intended for mapping methods from single source to target + */ + default Type getMappingSourceType() { + return getSourceParameters().get( 0 ).getType(); + } + + /** + * @return the short name for error messages + */ + default String shortName() { + return getResultType().getName() + ":" + getName() + "(" + getMappingSourceType().getName() + ")"; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 3551db8c51..9ed432d3ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -294,7 +294,7 @@ public boolean inverses(SourceMethod method) { return method.getDeclaringMapper() == null && method.isAbstract() && getSourceParameters().size() == 1 && method.getSourceParameters().size() == 1 - && first( getSourceParameters() ).getType().isAssignableTo( method.getResultType() ) + && getMappingSourceType().isAssignableTo( method.getResultType() ) && getResultType().isAssignableTo( first( method.getSourceParameters() ).getType() ); } @@ -326,7 +326,7 @@ public Parameter getTargetTypeParameter() { public boolean isIterableMapping() { if ( isIterableMapping == null ) { isIterableMapping = getSourceParameters().size() == 1 - && first( getSourceParameters() ).getType().isIterableType() + && getMappingSourceType().isIterableType() && getResultType().isIterableType(); } return isIterableMapping; @@ -335,9 +335,9 @@ && first( getSourceParameters() ).getType().isIterableType() public boolean isStreamMapping() { if ( isStreamMapping == null ) { isStreamMapping = getSourceParameters().size() == 1 - && ( first( getSourceParameters() ).getType().isIterableType() && getResultType().isStreamType() - || first( getSourceParameters() ).getType().isStreamType() && getResultType().isIterableType() - || first( getSourceParameters() ).getType().isStreamType() && getResultType().isStreamType() ); + && ( getMappingSourceType().isIterableType() && getResultType().isStreamType() + || getMappingSourceType().isStreamType() && getResultType().isIterableType() + || getMappingSourceType().isStreamType() && getResultType().isStreamType() ); } return isStreamMapping; } @@ -345,7 +345,7 @@ public boolean isStreamMapping() { public boolean isMapMapping() { if ( isMapMapping == null ) { isMapMapping = getSourceParameters().size() == 1 - && first( getSourceParameters() ).getType().isMapType() + && getMappingSourceType().isMapType() && getResultType().isMapType(); } return isMapMapping; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 0621a68db7..360eb56bac 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -67,21 +67,13 @@ public boolean matches(List sourceTypes, Type targetType) { Type sourceType = first( sourceTypes ); - if ( getReturnType().isAssignableTo( targetType.erasure() ) - && sourceType.erasure().isAssignableTo( getParameter().getType() ) ) { - return doTypeVarsMatch( sourceType, targetType ); - } - if ( getReturnType().getFullyQualifiedName().equals( "java.lang.Object" ) - && sourceType.erasure().isAssignableTo( getParameter().getType() ) ) { - // return type could be a type parameter T - return doTypeVarsMatch( sourceType, targetType ); - } - if ( getReturnType().isAssignableTo( targetType.erasure() ) - && getParameter().getType().getFullyQualifiedName().equals( "java.lang.Object" ) ) { - // parameter type could be a type parameter T - return doTypeVarsMatch( sourceType, targetType ); + Type returnType = getReturnType().resolveTypeVarToType( sourceType, getParameter().getType() ); + if ( returnType == null ) { + return false; } - return false; + + return returnType.isAssignableTo( targetType ) + && sourceType.erasure().isAssignableTo( getParameter().getType() ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 1ae3efe3c9..4d116266fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -5,15 +5,16 @@ */ package org.mapstruct.ap.internal.model.source.builtin; +import static org.mapstruct.ap.internal.util.Collections.asSet; + import java.util.Set; + import javax.xml.bind.JAXBElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import static org.mapstruct.ap.internal.util.Collections.asSet; - /** * @author Sjaak Derksen */ @@ -24,8 +25,9 @@ public class JaxbElemToValue extends BuiltInMethod { private final Set importTypes; public JaxbElemToValue(TypeFactory typeFactory) { - this.parameter = new Parameter( "element", typeFactory.getType( JAXBElement.class ) ); - this.returnType = typeFactory.getType( Object.class ); + Type type = typeFactory.getType( JAXBElement.class ); + this.parameter = new Parameter( "element", type ); + this.returnType = type.getTypeParameters().get( 0 ); this.importTypes = asSet( parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java index bc0696d2b2..7acb1af210 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model.source.selector; import java.util.List; +import java.util.Objects; import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.source.Method; @@ -39,4 +40,21 @@ public void setParameterBindings(List parameterBindings) { public String toString() { return method.toString(); } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SelectedMethod that = (SelectedMethod) o; + return method.equals( that.method ); + } + + @Override + public int hashCode() { + return Objects.hash( method ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index cb9d309171..c3c394aefd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -69,7 +69,7 @@ public List> getMatchingMethods(Method mapp } String name = xmlElementDecl.name().get(); - TypeMirror scope = xmlElementDecl.scope().get(); + TypeMirror scope = xmlElementDecl.scope().getValue(); boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() ); boolean scopeIsSetAndMatches = diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 5427ddefa9..5edd792944 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -5,12 +5,23 @@ */ package org.mapstruct.ap.internal.processor.creation; +import static java.util.Collections.singletonList; +import static org.mapstruct.ap.internal.util.Collections.first; +import static org.mapstruct.ap.internal.util.Collections.firstKey; +import static org.mapstruct.ap.internal.util.Collections.firstValue; + import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; + import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; @@ -42,7 +53,6 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMappingMethods; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; @@ -55,9 +65,6 @@ import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; -import static java.util.Collections.singletonList; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * The one and only implementation of {@link MappingResolver}. The class has been split into an interface an * implementation for the sake of avoiding package dependencies. Specifically, this implementation refers to classes @@ -78,6 +85,8 @@ public class MappingResolverImpl implements MappingResolver { private final BuiltInMappingMethods builtInMethods; private final MethodSelectors methodSelectors; + private static final String JL_OBJECT_NAME = Object.class.getName(); + /** * Private methods which are not present in the original mapper interface and are added to map certain property * types. @@ -113,7 +122,9 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, sourceRHS, criteria, positionHint, - forger + forger, + builtInMethods.getBuiltInMethods(), + messager ); return attempt.getTargetAssignment( sourceRHS.getSourceTypeForMatching(), targetType ); @@ -141,10 +152,11 @@ private class ResolvingAttempt { private final List methods; private final SelectionCriteria selectionCriteria; private final SourceRHS sourceRHS; - private final boolean savedPreferUpdateMapping; private final FormattingParameters formattingParameters; private final AnnotationMirror positionHint; private final Supplier forger; + private final List builtIns; + private final FormattingMessager messager; // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches, // second doesn't. In that case, the first builtin method should not lead to a supported method @@ -155,7 +167,9 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria, AnnotationMirror positionHint, - Supplier forger) { + Supplier forger, + List builtIns, + FormattingMessager messager) { this.mappingMethod = mappingMethod; this.methods = filterPossibleCandidateMethods( sourceModel ); @@ -164,9 +178,10 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, this.sourceRHS = sourceRHS; this.supportingMethodCandidates = new HashSet<>(); this.selectionCriteria = criteria; - this.savedPreferUpdateMapping = criteria.isPreferUpdateMapping(); this.positionHint = positionHint; this.forger = forger; + this.builtIns = builtIns; + this.messager = messager; } private List filterPossibleCandidateMethods(List candidateMethods) { @@ -182,14 +197,16 @@ private List filterPossibleCandidateMethods(List candid private Assignment getTargetAssignment(Type sourceType, Type targetType) { - Assignment referencedMethod; + Assignment assignment; // first simple mapping method if ( allowMappingMethod() ) { - referencedMethod = resolveViaMethod( sourceType, targetType, false ); - if ( referencedMethod != null ) { - referencedMethod.setAssignment( sourceRHS ); - return referencedMethod; + List> matches = getBestMatch( methods, sourceType, targetType ); + reportErrorWhenAmbigious( matches, targetType ); + if ( !matches.isEmpty() ) { + assignment = toMethodRef( first( matches ) ); + assignment.setAssignment( sourceRHS ); + return assignment; } } @@ -228,38 +245,40 @@ && allowDirect( sourceType, targetType ) ) { // check for a built-in method if ( !hasQualfiers() ) { - Assignment builtInMethod = resolveViaBuiltInMethod( sourceType, targetType ); - if ( builtInMethod != null ) { - builtInMethod.setAssignment( sourceRHS ); + List> matches = getBestMatch( builtIns, sourceType, targetType ); + reportErrorWhenAmbigious( matches, targetType ); + if ( !matches.isEmpty() ) { + assignment = toBuildInRef( first( matches ) ); + assignment.setAssignment( sourceRHS ); usedSupportedMappings.addAll( supportingMethodCandidates ); - return builtInMethod; + return assignment; } } } if ( allow2Steps() ) { // 2 step method, first: method(method(source)) - referencedMethod = resolveViaMethodAndMethod( sourceType, targetType ); - if ( referencedMethod != null ) { + assignment = MethodMethod.getBestMatch( this, sourceType, targetType ); + if ( assignment != null ) { usedSupportedMappings.addAll( supportingMethodCandidates ); - return referencedMethod; + return assignment; } // 2 step method, then: method(conversion(source)) - referencedMethod = resolveViaConversionAndMethod( sourceType, targetType ); - if ( referencedMethod != null ) { + assignment = ConversionMethod.getBestMatch( this, sourceType, targetType ); + if ( assignment != null ) { usedSupportedMappings.addAll( supportingMethodCandidates ); - return referencedMethod; + return assignment; } // stop here when looking for update methods. selectionCriteria.setPreferUpdateMapping( false ); // 2 step method, finally: conversion(method(source)) - ConversionAssignment conversion = resolveViaMethodAndConversion( sourceType, targetType ); - if ( conversion != null ) { + assignment = MethodConversion.getBestMatch( this, sourceType, targetType ); + if ( assignment != null ) { usedSupportedMappings.addAll( supportingMethodCandidates ); - return conversion.getAssignment(); + return assignment; } } @@ -395,232 +414,6 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy return null; } - /** - * Returns a reference to a method mapping the given source type to the given target type, if such a method - * exists. - */ - private Assignment resolveViaMethod(Type sourceType, Type targetType, boolean considerBuiltInMethods) { - - // first try to find a matching source method - SelectedMethod matchingSourceMethod = getBestMatch( methods, sourceType, targetType ); - - if ( matchingSourceMethod != null ) { - return getMappingMethodReference( matchingSourceMethod ); - } - - if ( considerBuiltInMethods ) { - return resolveViaBuiltInMethod( sourceType, targetType ); - } - - return null; - } - - /** - * Applies matching to given method only - * - * @param sourceType the source type - * @param targetType the target type - * @param method the method to match - * @return an assignment if a match, given the criteria could be found. When the method is a - * buildIn method, all the bookkeeping is applied. - */ - private Assignment applyMatching(Type sourceType, Type targetType, Method method) { - - if ( method instanceof SourceMethod ) { - SelectedMethod selectedMethod = - getBestMatch( java.util.Collections.singletonList( method ), sourceType, targetType ); - return selectedMethod != null ? getMappingMethodReference( selectedMethod ) : null; - } - else if ( method instanceof BuiltInMethod ) { - return resolveViaBuiltInMethod( sourceType, targetType ); - } - return null; - } - - private Assignment resolveViaBuiltInMethod(Type sourceType, Type targetType) { - SelectedMethod matchingBuiltInMethod = - getBestMatch( builtInMethods.getBuiltInMethods(), sourceType, targetType ); - - if ( matchingBuiltInMethod != null ) { - return createFromBuiltInMethod( matchingBuiltInMethod.getMethod() ); - } - - return null; - } - - private Assignment createFromBuiltInMethod(BuiltInMethod method) { - Set allUsedFields = new HashSet<>( mapperReferences ); - SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); - SupportingMappingMethod supportingMappingMethod = new SupportingMappingMethod( method, allUsedFields ); - supportingMethodCandidates.add( supportingMappingMethod ); - ConversionContext ctx = new DefaultConversionContext( - typeFactory, - messager, - method.getSourceParameters().get( 0 ).getType(), - method.getResultType(), - formattingParameters - ); - Assignment methodReference = MethodReference.forBuiltInMethod( method, ctx ); - methodReference.setAssignment( sourceRHS ); - return methodReference; - } - - /** - * Suppose mapping required from A to C and: - *
          - *
        • no direct referenced mapping method either built-in or referenced is available from A to C
        • - *
        • no conversion is available
        • - *
        • there is a method from A to B, methodX
        • - *
        • there is a method from B to C, methodY
        • - *
        - * then this method tries to resolve this combination and make a mapping methodY( methodX ( parameter ) ) - */ - private Assignment resolveViaMethodAndMethod(Type sourceType, Type targetType) { - - List methodYCandidates = new ArrayList<>( methods ); - methodYCandidates.addAll( builtInMethods.getBuiltInMethods() ); - - Assignment methodRefY = null; - - // Iterate over all source methods. Check if the return type matches with the parameter that we need. - // so assume we need a method from A to C we look for a methodX from A to B (all methods in the - // list form such a candidate). - // For each of the candidates, we need to look if there's a methodY, either - // sourceMethod or builtIn that fits the signature B to C. Only then there is a match. If we have a match - // a nested method call can be called. so C = methodY( methodX (A) ) - for ( Method methodYCandidate : methodYCandidates ) { - Type ySourceType = methodYCandidate.getSourceParameters().get( 0 ).getType(); - if ( Object.class.getName().equals( ySourceType.getName() ) ) { - // java.lang.Object as intermediate result - continue; - } - - ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); - - if ( ySourceType != null ) { - methodRefY = applyMatching( ySourceType, targetType, methodYCandidate ); - if ( methodRefY != null ) { - - selectionCriteria.setPreferUpdateMapping( false ); - Assignment methodRefX = resolveViaMethod( sourceType, ySourceType, true ); - selectionCriteria.setPreferUpdateMapping( savedPreferUpdateMapping ); - if ( methodRefX != null ) { - methodRefY.setAssignment( methodRefX ); - methodRefX.setAssignment( sourceRHS ); - break; - } - else { - // both should match; - supportingMethodCandidates.clear(); - methodRefY = null; - } - } - } - } - return methodRefY; - } - - /** - * Suppose mapping required from A to C and: - *
          - *
        • there is a conversion from A to B, conversionX
        • - *
        • there is a method from B to C, methodY
        • - *
        - * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) - * - * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in - * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt - * is done to find a matching type conversion. - */ - private Assignment resolveViaConversionAndMethod(Type sourceType, Type targetType) { - - List methodYCandidates = new ArrayList<>( methods ); - methodYCandidates.addAll( builtInMethods.getBuiltInMethods() ); - - Assignment methodRefY = null; - - for ( Method methodYCandidate : methodYCandidates ) { - Type ySourceType = methodYCandidate.getSourceParameters().get( 0 ).getType(); - if ( Object.class.getName().equals( ySourceType.getName() ) ) { - // java.lang.Object as intermediate result - continue; - } - - ySourceType = ySourceType.resolveTypeVarToType( targetType, methodYCandidate.getResultType() ); - - if ( ySourceType != null ) { - methodRefY = applyMatching( ySourceType, targetType, methodYCandidate ); - if ( methodRefY != null ) { - ConversionAssignment conversionXRef = resolveViaConversion( sourceType, ySourceType ); - if ( conversionXRef != null ) { - methodRefY.setAssignment( conversionXRef.getAssignment() ); - conversionXRef.getAssignment().setAssignment( sourceRHS ); - conversionXRef.reportMessageWhenNarrowing( messager, this ); - break; - } - else { - // both should match - supportingMethodCandidates.clear(); - methodRefY = null; - } - } - } - } - return methodRefY; - } - - /** - * Suppose mapping required from A to C and: - *
          - *
        • there is a method from A to B, methodX
        • - *
        • there is a conversion from B to C, conversionY
        • - *
        - * then this method tries to resolve this combination and make a mapping conversionY( methodX ( parameter ) ) - * - * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in - * methods are used to resolve a mapping (assignment) from source type to 'B'. If a match is found, an attempt - * is done to find a matching type conversion. - */ - private ConversionAssignment resolveViaMethodAndConversion(Type sourceType, Type targetType) { - - List methodXCandidates = new ArrayList<>( methods ); - methodXCandidates.addAll( builtInMethods.getBuiltInMethods() ); - - ConversionAssignment conversionYRef = null; - - // search the other way around - for ( Method methodXCandidate : methodXCandidates ) { - Type xTargetType = methodXCandidate.getReturnType(); - if ( methodXCandidate.isUpdateMethod() || - Object.class.getName().equals( xTargetType.getFullyQualifiedName() ) ) { - // skip update methods || java.lang.Object as intermediate result - continue; - } - - xTargetType = - xTargetType.resolveTypeVarToType( sourceType, methodXCandidate.getParameters().get( 0 ).getType() ); - - if ( xTargetType != null ) { - Assignment methodRefX = applyMatching( sourceType, xTargetType, methodXCandidate ); - if ( methodRefX != null ) { - conversionYRef = resolveViaConversion( xTargetType, targetType ); - if ( conversionYRef != null ) { - conversionYRef.getAssignment().setAssignment( methodRefX ); - methodRefX.setAssignment( sourceRHS ); - conversionYRef.reportMessageWhenNarrowing( messager, this ); - break; - } - else { - // both should match; - supportingMethodCandidates.clear(); - conversionYRef = null; - } - } - } - } - return conversionYRef; - } - private boolean isCandidateForMapping(Method methodCandidate) { return isCreateMethodForMapping( methodCandidate ) || isUpdateMethodForMapping( methodCandidate ); } @@ -640,15 +433,17 @@ private boolean isUpdateMethodForMapping(Method methodCandidate) { && !methodCandidate.isLifecycleCallbackMethod(); } - private SelectedMethod getBestMatch(List methods, Type sourceType, Type returnType) { - - List> candidates = methodSelectors.getMatchingMethods( + private List> getBestMatch(List methods, Type source, Type target) { + return methodSelectors.getMatchingMethods( mappingMethod, methods, - singletonList( sourceType ), - returnType, + singletonList( source ), + target, selectionCriteria ); + } + + private void reportErrorWhenAmbigious(List> candidates, Type target) { // raise an error if more than one mapping method is suitable to map the given source type // into the target type @@ -660,7 +455,7 @@ private SelectedMethod getBestMatch(List methods, Type positionHint, Message.GENERAL_AMBIGIOUS_MAPPING_METHOD, sourceRHS.getSourceErrorMessagePart(), - returnType, + target, Strings.join( candidates, ", " ) ); } @@ -669,29 +464,41 @@ private SelectedMethod getBestMatch(List methods, Type mappingMethod.getExecutable(), positionHint, Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, - returnType, + target, Strings.join( candidates, ", " ) ); } } - - if ( !candidates.isEmpty() ) { - return first( candidates ); - } - - return null; } - private Assignment getMappingMethodReference(SelectedMethod method) { - MapperReference mapperReference = findMapperReference( method.getMethod() ); + private Assignment toMethodRef(SelectedMethod selectedMethod) { + MapperReference mapperReference = findMapperReference( selectedMethod.getMethod() ); return MethodReference.forMapperReference( - method.getMethod(), + selectedMethod.getMethod(), mapperReference, - method.getParameterBindings() + selectedMethod.getParameterBindings() ); } + private Assignment toBuildInRef(SelectedMethod selectedMethod) { + BuiltInMethod method = selectedMethod.getMethod(); + Set allUsedFields = new HashSet<>( mapperReferences ); + SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); + SupportingMappingMethod supportingMappingMethod = new SupportingMappingMethod( method, allUsedFields ); + supportingMethodCandidates.add( supportingMappingMethod ); + ConversionContext ctx = new DefaultConversionContext( + typeFactory, + messager, + method.getMappingSourceType(), + method.getResultType(), + formattingParameters + ); + Assignment methodReference = MethodReference.forBuiltInMethod( method, ctx ); + methodReference.setAssignment( sourceRHS ); + return methodReference; + } + /** * Whether the given source and target type are both a collection type or both a map type and the source value * can be propagated via a copy constructor. @@ -770,6 +577,7 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { return false; } + } private static class ConversionAssignment { @@ -813,5 +621,408 @@ private void report(FormattingMessager messager, ResolvingAttempt attempt, Messa ); } + String shortName() { + return sourceType.getName() + "-->" + targetType.getName(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + ConversionAssignment that = (ConversionAssignment) o; + return sourceType.equals( that.sourceType ) && targetType.equals( that.targetType ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceType, targetType ); + } + } + + /** + * Suppose mapping required from A to C and: + *
          + *
        • no direct referenced mapping method either built-in or referenced is available from A to C
        • + *
        • no conversion is available
        • + *
        • there is a method from A to B, methodX
        • + *
        • there is a method from B to C, methodY
        • + *
        + * then this method tries to resolve this combination and make a mapping methodY( methodX ( parameter ) ) + * + * NOTE method X cannot be an update method + */ + private static class MethodMethod { + + private final ResolvingAttempt attempt; + private final List xMethods; + private final List yMethods; + private final Function, Assignment> xCreate; + private final Function, Assignment> yCreate; + + // results + private boolean hasResult = false; + private Assignment result = null; + + static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targetType) { + MethodMethod mmAttempt = + new MethodMethod<>( att, att.methods, att.methods, att::toMethodRef, att::toMethodRef ) + .getBestMatch( sourceType, targetType ); + if ( mmAttempt.hasResult ) { + return mmAttempt.result; + } + MethodMethod mbAttempt = + new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + if ( mbAttempt.hasResult ) { + return mbAttempt.result; + } + MethodMethod bmAttempt = + new MethodMethod<>( att, att.builtIns, att.methods, att::toBuildInRef, att::toMethodRef ) + .getBestMatch( sourceType, targetType ); + if ( bmAttempt.hasResult ) { + return bmAttempt.result; + } + MethodMethod bbAttempt = + new MethodMethod<>( att, att.builtIns, att.builtIns, att::toBuildInRef, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + return bbAttempt.result; + } + + MethodMethod(ResolvingAttempt attempt, List xMethods, List yMethods, + Function, Assignment> xCreate, + Function, Assignment> yCreate) { + this.attempt = attempt; + this.xMethods = xMethods; + this.yMethods = yMethods; + this.xCreate = xCreate; + this.yCreate = yCreate; + } + + private MethodMethod getBestMatch(Type sourceType, Type targetType) { + + Set yCandidates = new HashSet<>(); + Map, List>> xCandidates = new LinkedHashMap<>(); + Map, Type> typesInTheMiddle = new LinkedHashMap<>(); + + // Iterate over all source methods. Check if the return type matches with the parameter that we need. + // so assume we need a method from A to C we look for a methodX from A to B (all methods in the + // list form such a candidate). + // For each of the candidates, we need to look if there's a methodY, either + // sourceMethod or builtIn that fits the signature B to C. Only then there is a match. If we have a match + // a nested method call can be called. so C = methodY( methodX (A) ) + attempt.selectionCriteria.setPreferUpdateMapping( false ); + for ( T2 yCandidate : yMethods ) { + Type ySourceType = yCandidate.getMappingSourceType(); + ySourceType = ySourceType.resolveTypeVarToType( targetType, yCandidate.getResultType() ); + Type yTargetType = yCandidate.getResultType(); + if ( ySourceType == null + || !yTargetType.isRawAssignableTo( targetType ) + || JL_OBJECT_NAME.equals( ySourceType.getFullyQualifiedName() ) ) { + // java.lang.Object as intermediate result + continue; + } + List> xMatches = attempt.getBestMatch( xMethods, sourceType, ySourceType ); + if ( !xMatches.isEmpty() ) { + xMatches.stream().forEach( x -> xCandidates.put( x, new ArrayList<>() ) ); + final Type typeInTheMiddle = ySourceType; + xMatches.stream().forEach( x -> typesInTheMiddle.put( x, typeInTheMiddle ) ); + yCandidates.add( yCandidate ); + } + } + attempt.selectionCriteria.setPreferUpdateMapping( true ); + + // collect all results + List yCandidatesList = new ArrayList<>( yCandidates ); + Iterator, List>>> i = xCandidates.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry, List>> entry = i.next(); + Type typeInTheMiddle = typesInTheMiddle.get( entry.getKey() ); + entry.getValue().addAll( attempt.getBestMatch( yCandidatesList, typeInTheMiddle, targetType ) ); + if ( entry.getValue().isEmpty() ) { + i.remove(); + } + } + + // no results left + if ( xCandidates.isEmpty() ) { + return this; + } + hasResult = true; + + // get result, there should be one entry left with only one value + if ( xCandidates.size() == 1 && firstValue( xCandidates ).size() == 1 ) { + Assignment methodRefY = yCreate.apply( first( firstValue( xCandidates ) ) ); + Assignment methodRefX = xCreate.apply( firstKey( xCandidates ) ); + methodRefY.setAssignment( methodRefX ); + methodRefX.setAssignment( attempt.sourceRHS ); + result = methodRefY; + } + else { + reportAmbigiousError( xCandidates, targetType ); + } + return this; + + } + + void reportAmbigiousError(Map, List>> xCandidates, Type target) { + StringBuilder result = new StringBuilder(); + xCandidates.entrySet() + .stream() + .forEach( e -> result.append( "method(s)Y: " ) + .append( e.getValue() + .stream() + .map( v -> v.getMethod().shortName() ) + .collect( Collectors.joining( ", " ) ) ) + .append( ", methodX: " ) + .append( e.getKey().getMethod().shortName() ) + .append( "; " ) ); + attempt.messager.printMessage( + attempt.mappingMethod.getExecutable(), + attempt.positionHint, + Message.GENERAL_AMBIGIOUS_MAPPING_METHODY_METHODX, + attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), + target.getName(), + result.toString() ); + } + } + + /** + * Suppose mapping required from A to C and: + *
          + *
        • there is a conversion from A to B, conversionX
        • + *
        • there is a method from B to C, methodY
        • + *
        + * then this method tries to resolve this combination and make a mapping methodY( conversionX ( parameter ) ) + * + * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from result type to 'B'. If a match is found, an attempt + * is done to find a matching type conversion. + */ + private static class ConversionMethod { + + private final ResolvingAttempt attempt; + private final List methods; + private final Function, Assignment> create; + + // results + private boolean hasResult = false; + private Assignment result = null; + + static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targetType) { + ConversionMethod mAttempt = new ConversionMethod<>( att, att.methods, att::toMethodRef ) + .getBestMatch( sourceType, targetType ); + if ( mAttempt.hasResult ) { + return mAttempt.result; + } + ConversionMethod bAttempt = + new ConversionMethod<>( att, att.builtIns, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + return bAttempt.result; + } + + ConversionMethod(ResolvingAttempt attempt, List methods, Function, Assignment> create) { + this.attempt = attempt; + this.methods = methods; + this.create = create; + } + + private ConversionMethod getBestMatch(Type sourceType, Type targetType) { + + List yCandidates = new ArrayList<>(); + Map>> xRefCandidates = new LinkedHashMap<>(); + + for ( T yCandidate : methods ) { + Type ySourceType = yCandidate.getMappingSourceType(); + ySourceType = ySourceType.resolveTypeVarToType( targetType, yCandidate.getResultType() ); + Type yTargetType = yCandidate.getResultType(); + if ( ySourceType == null + || !yTargetType.isRawAssignableTo( targetType ) + || JL_OBJECT_NAME.equals( ySourceType.getFullyQualifiedName() ) ) { + // java.lang.Object as intermediate result + continue; + } + ConversionAssignment xRefCandidate = attempt.resolveViaConversion( sourceType, ySourceType ); + if ( xRefCandidate != null ) { + xRefCandidates.put( xRefCandidate, new ArrayList<>() ); + yCandidates.add( yCandidate ); + } + } + + // collect all results + Iterator>>> i = xRefCandidates.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry>> entry = i.next(); + entry.getValue().addAll( attempt.getBestMatch( yCandidates, entry.getKey().targetType, targetType ) ); + if ( entry.getValue().isEmpty() ) { + i.remove(); + } + } + + // no results left + if ( xRefCandidates.isEmpty() ) { + return this; + } + hasResult = true; + + // get result, there should be one entry left with only one value + if ( xRefCandidates.size() == 1 && firstValue( xRefCandidates ).size() == 1 ) { + Assignment methodRefY = create.apply( first( firstValue( xRefCandidates ) ) ); + ConversionAssignment conversionRefX = firstKey( xRefCandidates ); + conversionRefX.reportMessageWhenNarrowing( attempt.messager, attempt ); + methodRefY.setAssignment( conversionRefX.assignment ); + conversionRefX.assignment.setAssignment( attempt.sourceRHS ); + result = methodRefY; + } + else { + reportAmbigiousError( xRefCandidates, targetType ); + } + return this; + + } + + void reportAmbigiousError(Map>> xRefCandidates, Type target) { + StringBuilder result = new StringBuilder(); + xRefCandidates.entrySet() + .stream() + .forEach( e -> result.append( "method(s)Y: " ) + .append( e.getValue() + .stream() + .map( v -> v.getMethod().shortName() ) + .collect( Collectors.joining( ", " ) ) ) + .append( ", conversionX: " ) + .append( e.getKey().shortName() ) + .append( "; " ) ); + attempt.messager.printMessage( + attempt.mappingMethod.getExecutable(), + attempt.positionHint, + Message.GENERAL_AMBIGIOUS_MAPPING_METHODY_CONVERSIONX, + attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), + target.getName(), + result.toString() ); + } } + + /** + * Suppose mapping required from A to C and: + *
          + *
        • there is a method from A to B, methodX
        • + *
        • there is a conversion from B to C, conversionY
        • + *
        + * then this method tries to resolve this combination and make a mapping conversionY( methodX ( parameter ) ) + * + * Instead of directly using a built in method candidate, all the return types as 'B' of all available built-in + * methods are used to resolve a mapping (assignment) from source type to 'B'. If a match is found, an attempt + * is done to find a matching type conversion. + * + * NOTE methodX cannot be an update method + */ + private static class MethodConversion { + + private final ResolvingAttempt attempt; + private final List methods; + private final Function, Assignment> create; + + // results + private boolean hasResult = false; + private Assignment result = null; + + static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targetType) { + MethodConversion mAttempt = new MethodConversion<>( att, att.methods, att::toMethodRef ) + .getBestMatch( sourceType, targetType ); + if ( mAttempt.hasResult ) { + return mAttempt.result; + } + MethodConversion bAttempt = new MethodConversion<>( att, att.builtIns, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + return bAttempt.result; + } + + MethodConversion(ResolvingAttempt attempt, List methods, Function, Assignment> create) { + this.attempt = attempt; + this.methods = methods; + this.create = create; + } + + private MethodConversion getBestMatch(Type sourceType, Type targetType) { + + List xCandidates = new ArrayList<>(); + Map>> yRefCandidates = new LinkedHashMap<>(); + + // search through methods, and select egible candidates + for ( T xCandidate : methods ) { + Type xTargetType = xCandidate.getReturnType(); + Type xSourceType = xCandidate.getMappingSourceType(); + xTargetType = xTargetType.resolveTypeVarToType( sourceType, xSourceType ); + if ( xTargetType == null + || xCandidate.isUpdateMethod() + || !sourceType.isRawAssignableTo( xSourceType ) + || JL_OBJECT_NAME.equals( xTargetType.getFullyQualifiedName() ) ) { + // skip update methods || java.lang.Object as intermediate result + continue; + } + ConversionAssignment yRefCandidate = attempt.resolveViaConversion( xTargetType, targetType ); + if ( yRefCandidate != null ) { + yRefCandidates.put( yRefCandidate, new ArrayList<>() ); + xCandidates.add( xCandidate ); + } + } + + // collect all results + Iterator>>> i = yRefCandidates.entrySet().iterator(); + while ( i.hasNext() ) { + Map.Entry>> entry = i.next(); + entry.getValue().addAll( attempt.getBestMatch( xCandidates, sourceType, entry.getKey().sourceType ) ); + if ( entry.getValue().isEmpty() ) { + i.remove(); + } + } + + // no results left + if ( yRefCandidates.isEmpty() ) { + return this; + } + hasResult = true; + + // get result, there should be one entry left with only one value + if ( yRefCandidates.size() == 1 && firstValue( yRefCandidates ).size() == 1 ) { + Assignment methodRefX = create.apply( first( firstValue( yRefCandidates ) ) ); + ConversionAssignment conversionRefY = firstKey( yRefCandidates ); + conversionRefY.reportMessageWhenNarrowing( attempt.messager, attempt ); + methodRefX.setAssignment( attempt.sourceRHS ); + conversionRefY.assignment.setAssignment( methodRefX ); + result = conversionRefY.assignment; + } + else { + reportAmbigiousError( yRefCandidates, targetType ); + } + return this; + + } + + void reportAmbigiousError(Map>> yRefCandidates, Type target) { + StringBuilder result = new StringBuilder(); + yRefCandidates.entrySet() + .stream() + .forEach( e -> result.append( "conversionY: " ) + .append( e.getKey().shortName() ) + .append( ", method(s)X: " ) + .append( e.getValue() + .stream() + .map( v -> v.getMethod().shortName() ) + .collect( Collectors.joining( ", " ) ) ) + .append( "; " ) ); + attempt.messager.printMessage( + attempt.mappingMethod.getExecutable(), + attempt.positionHint, + Message.GENERAL_AMBIGIOUS_MAPPING_CONVERSIONY_METHODX, + attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), + target.getName(), + result.toString() ); + } + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java index 7f2d5cd8db..365efc56ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Collections.java @@ -9,6 +9,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -63,4 +64,16 @@ public static List join(List a, List b) { return result; } + public static Map.Entry first(Map map) { + return map.entrySet().iterator().next(); + } + + public static V firstValue(Map map) { + return first( map ).getValue(); + } + + public static K firstKey(Map map) { + return first( map ).getKey(); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index ae66d38776..d10faf64b9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -125,6 +125,10 @@ public enum Message { GENERAL_NO_QUALIFYING_METHOD_NAMED( "Qualifier error. No method found annotated with @Named#value: [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), GENERAL_NO_QUALIFYING_METHOD_COMBINED( "Qualifier error. No method found annotated with @Named#value: [ %s ], annotated with [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), + GENERAL_AMBIGIOUS_MAPPING_METHODY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( methodX ( parameter ) ): %s." ), + GENERAL_AMBIGIOUS_MAPPING_CONVERSIONY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found conversionY( methodX ( parameter ) ): %s." ), + GENERAL_AMBIGIOUS_MAPPING_METHODY_CONVERSIONX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( conversionX ( parameter ) ): %s." ), + BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), BUILDER_NO_BUILD_METHOD_FOUND("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\".", Diagnostic.Kind.ERROR ), BUILDER_NO_BUILD_METHOD_FOUND_DEFAULT("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\". Consider to add @Builder in order to select the correct build method.", Diagnostic.Kind.ERROR ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Mapper.java new file mode 100644 index 0000000000..1b8969664d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Mapper.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2145; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.namespace.QName; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper( uses = Issue2145Mapper.ObjectFactory.class ) +public interface Issue2145Mapper { + + Issue2145Mapper INSTANCE = Mappers.getMapper( Issue2145Mapper.class ); + + @Mapping(target = "nested", source = "value") + Target map(Source source); + + default Nested map(String in) { + Nested nested = new Nested(); + nested.setValue( in ); + return nested; + } + + class Target { + + private JAXBElement nested; + + public JAXBElement getNested() { + return nested; + } + + public void setNested(JAXBElement nested) { + this.nested = nested; + } + } + + class Nested { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class ObjectFactory { + + private static final QName Q_NAME = new QName( "http://www.test.com/test", "" ); + private static final QName Q_NAME_NESTED = new QName( "http://www.test.com/test", "nested" ); + + @XmlElementDecl(namespace = "http://www.test.com/test", name = "Nested") + public JAXBElement createNested(Nested value) { + return new JAXBElement( Q_NAME, Nested.class, null, value ); + } + + @XmlElementDecl(namespace = "http://www.test.com/test", name = "nested", scope = Nested.class) + public JAXBElement createNestedInNestedTarget(Nested value) { + return new JAXBElement( Q_NAME_NESTED, Nested.class, Target.class, value ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java new file mode 100644 index 0000000000..02ad2ba901 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2145; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2145") +@WithClasses(Issue2145Mapper.class) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2145Test { + + @Test + public void test() { + Issue2145Mapper.Source source = new Issue2145Mapper.Source(); + source.setValue( "test" ); + + Issue2145Mapper.Target target = Issue2145Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getNested() ).isNotNull(); + assertThat( target.getNested().getScope() ).isEqualTo( Issue2145Mapper.Target.class ); + assertThat( target.getNested().getValue() ).isNotNull(); + assertThat( target.getNested().getValue().getValue() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperCM.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperCM.java new file mode 100644 index 0000000000..6910057682 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperCM.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.twosteperror; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousMapperCM { + + ErroneousMapperCM INSTANCE = Mappers.getMapper( ErroneousMapperCM.class ); + + Target map(Source s); + + default TargetType methodY1(String s) { + return new TargetType( s ); + } + + default TargetType methodY2(Double d) { + return new TargetType( d.toString() ); + } + + // CHECKSTYLE:OFF + class Target { + public TargetType t1; + } + + class Source { + public BigDecimal t1; + } + + class TargetType { + public String t1; + + public TargetType(String test) { + this.t1 = test; + } + } + + class TypeInTheMiddleA { + + TypeInTheMiddleA(String t1) { + this.test = t1; + } + + public String test; + } + + // CHECKSTYLE:ON + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java new file mode 100644 index 0000000000..4b7dcf90a3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.twosteperror; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousMapperMC { + + ErroneousMapperMC INSTANCE = Mappers.getMapper( ErroneousMapperMC.class ); + + Target map(Source s); + + default BigDecimal methodX1(SourceType s) { + return new BigDecimal( s.t1 ); + } + + default Double methodX2(SourceType s) { + return new Double( s.t1 ); + } + + // CHECKSTYLE:OFF + class Target { + public String t1; + } + + class Source { + public SourceType t1; + } + + class SourceType { + public String t1; + } + + class TargetType { + public String t1; + + public TargetType(String test) { + this.t1 = test; + } + } + + + // CHECKSTYLE:ON + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMM.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMM.java new file mode 100644 index 0000000000..2f0e25c647 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMM.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.twosteperror; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousMapperMM { + + ErroneousMapperMM INSTANCE = Mappers.getMapper( ErroneousMapperMM.class ); + + Target map( Source s ); + + default TargetType methodY1(TypeInTheMiddleA s) { + return new TargetType( s.test ); + } + + default TypeInTheMiddleA methodX1(SourceType s) { + return new TypeInTheMiddleA( s.t1 ); + } + + default TargetType methodY2(TypeInTheMiddleB s) { + return new TargetType( s.test ); + } + + default TypeInTheMiddleB methodX2(SourceType s) { + return new TypeInTheMiddleB( s.t1 ); + } + + // CHECKSTYLE:OFF + class Target { + public TargetType t1; + } + + class Source { + public SourceType t1; + } + + class SourceType { + public String t1; + } + + class TargetType { + public String t1; + + public TargetType(String test) { + this.t1 = test; + } + } + + class TypeInTheMiddleA { + + TypeInTheMiddleA(String t1) { + this.test = t1; + } + + public String test; + } + + class TypeInTheMiddleB { + + TypeInTheMiddleB(String t1) { + this.test = t1; + } + + public String test; + } + // CHECKSTYLE:ON + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java new file mode 100644 index 0000000000..e22150fe36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java @@ -0,0 +1,79 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.twosteperror; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@RunWith( AnnotationProcessorTestRunner.class ) +public class TwoStepMappingTest { + + @Test + @WithClasses( ErroneousMapperMM.class ) + @ExpectedCompilationOutcome( value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperMM.class, + line = 16, + message = "Ambiguous 2step methods found, mapping SourceType s to TargetType. " + + "Found methodY( methodX ( parameter ) ): " + + "method(s)Y: TargetType:methodY1(TypeInTheMiddleA), methodX: TypeInTheMiddleA:methodX1(SourceType); " + + "method(s)Y: TargetType:methodY2(TypeInTheMiddleB), methodX: TypeInTheMiddleB:methodX2(SourceType); ." + ) ) + public void methodAndMethodTest() { + } + + @Test + @WithClasses( ErroneousMapperCM.class ) + @ExpectedCompilationOutcome( value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperCM.class, + line = 18, + message = "Ambiguous 2step methods found, mapping BigDecimal s to TargetType. " + + "Found methodY( conversionX ( parameter ) ): " + + "method(s)Y: TargetType:methodY1(String), conversionX: BigDecimal-->String; " + + "method(s)Y: TargetType:methodY2(Double), conversionX: BigDecimal-->Double; ." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperCM.class, + line = 18, + messageRegExp = "Can't map property.*" + ) + } ) + public void conversionAndMethodTest() { + } + + @Test + @WithClasses( ErroneousMapperMC.class ) + @ExpectedCompilationOutcome( value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperMC.class, + line = 18, + message = "Ambiguous 2step methods found, mapping SourceType s to String. " + + "Found conversionY( methodX ( parameter ) ): " + + "conversionY: BigDecimal-->String, method(s)X: BigDecimal:methodX1(SourceType); " + + "conversionY: Double-->String, method(s)X: Double:methodX2(SourceType); ." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperMC.class, + line = 18, + messageRegExp = "Can't map property.*" + ) + } ) + public void methodAndConversionTest() { + } +} From 6aa39ff4283b8fff5373bd292d69e1cb1da5cf0f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 17 Jul 2020 22:10:26 +0200 Subject: [PATCH 0485/1006] #2142: Strip leading underscore when sanitizing identifier name --- .../ap/internal/model/ForgedMethod.java | 3 +- .../mapstruct/ap/internal/util/Strings.java | 19 +++++++- .../ap/internal/util/StringsTest.java | 10 ++++ .../ap/test/bugs/_2142/Issue2142Mapper.java | 46 +++++++++++++++++++ .../ap/test/bugs/_2142/Issue2142Test.java | 34 ++++++++++++++ .../test/bugs/_2142/Issue2142MapperImpl.java | 31 +++++++++++++ 6 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2142/Issue2142MapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index e7a64e9138..ce1d8c024d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -125,8 +125,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List( 1 + additionalParameters.size() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 71acee3cf4..07049c17ad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -73,6 +73,8 @@ public class Strings { "while" ); + private static final char UNDERSCORE = '_'; + private Strings() { } @@ -166,7 +168,22 @@ public static String getSafeVariableName(String name, Collection existin * @return the identifier without any characters that are not allowed as part of a Java identifier. */ public static String sanitizeIdentifierName(String identifier) { - return identifier.replace( "[]", "Array" ); + if ( identifier != null && identifier.length() > 0 ) { + + int firstNonUnderScoreIndex = 0; + while ( firstNonUnderScoreIndex < identifier.length() && + identifier.charAt( firstNonUnderScoreIndex ) == UNDERSCORE ) { + firstNonUnderScoreIndex++; + } + + if ( firstNonUnderScoreIndex < identifier.length()) { + // If it is not consisted of only underscores + return identifier.substring( firstNonUnderScoreIndex ).replace( "[]", "Array" ); + } + + return identifier.replace( "[]", "Array" ); + } + return identifier; } /** diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index ced598330d..e0eb961d10 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -83,6 +83,8 @@ public void testGetSaveVariableNameWithArrayExistingVariables() { assertThat( Strings.getSafeVariableName( "Case" ) ).isEqualTo( "case1" ); assertThat( Strings.getSafeVariableName( "Synchronized" ) ).isEqualTo( "synchronized1" ); assertThat( Strings.getSafeVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); + assertThat( Strings.getSafeVariableName( "_Test" ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "__Test" ) ).isEqualTo( "test" ); } @Test @@ -98,12 +100,20 @@ public void testGetSaveVariableNameWithCollection() { assertThat( Strings.getSafeVariableName( "prop", Arrays.asList( "prop", "prop1" ) ) ).isEqualTo( "prop2" ); assertThat( Strings.getSafeVariableName( "prop.font", Arrays.asList( "propFont", "propFont_" ) ) ) .isEqualTo( "propFont1" ); + assertThat( Strings.getSafeVariableName( "_Test", new ArrayList<>() ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "__Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); + assertThat( Strings.getSafeVariableName( "___", new ArrayList<>() ) ).isEqualTo( "___" ); } @Test public void testSanitizeIdentifierName() { assertThat( Strings.sanitizeIdentifierName( "test" ) ).isEqualTo( "test" ); assertThat( Strings.sanitizeIdentifierName( "int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.sanitizeIdentifierName( "_Test" ) ).isEqualTo( "Test" ); + assertThat( Strings.sanitizeIdentifierName( "_int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.sanitizeIdentifierName( "__int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.sanitizeIdentifierName( "test_" ) ).isEqualTo( "test_" ); + assertThat( Strings.sanitizeIdentifierName( "___" ) ).isEqualTo( "___" ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Mapper.java new file mode 100644 index 0000000000..198976b37e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Mapper.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2142; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2142Mapper { + + Issue2142Mapper INSTANCE = Mappers.getMapper( Issue2142Mapper.class ); + + _Target map(Source source); + + // CHECKSTYLE:OFF + class _Target { + // CHECKSTYLE:ON + private final String value; + + public _Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java new file mode 100644 index 0000000000..8cfff232e5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2142; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2142") +@WithClasses(Issue2142Mapper.class) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2142Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( Issue2142Mapper.class ); + + @Test + public void underscorePrefixShouldBeStrippedFromGeneratedLocalVariables() { + Issue2142Mapper._Target target = Issue2142Mapper.INSTANCE.map( new Issue2142Mapper.Source( "value1" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "value1" ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2142/Issue2142MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2142/Issue2142MapperImpl.java new file mode 100644 index 0000000000..8a6d7d1b70 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2142/Issue2142MapperImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2142; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2019-02-10T09:58:11+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class Issue2142MapperImpl implements Issue2142Mapper { + + @Override + public _Target map(Source source) { + if ( source == null ) { + return null; + } + + String value = null; + + value = source.getValue(); + + _Target target = new _Target( value ); + + return target; + } +} From cb432fa61b76a8f81bac05ab120b342a007e8536 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jul 2020 18:53:32 +0200 Subject: [PATCH 0486/1006] #2150 Change the rules for how a constructor for mapping is picked New rules: 1. Constructor annotated with @Default (from any package) has highest precedence 2. If there is a single public constructor then it would be used to construct the object 3. If a parameterless constructor exists then it would be used to construct the object, and the other constructors will be ignored --- .../chapter-3-defining-a-mapper.asciidoc | 48 +++++++++- .../ap/internal/model/BeanMappingMethod.java | 88 +++++++++++++------ .../visibility/ConstructorVisibilityTest.java | 79 +++++++++++++++++ .../SimpleWithPublicConstructorMapper.java | 48 ++++++++++ ...sConstructorAndDefaultAnnotatedMapper.java | 51 +++++++++++ ...hPublicParameterlessConstructorMapper.java | 49 +++++++++++ 6 files changed, 334 insertions(+), 29 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorMapper.java diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index ad5d8111f7..7d2dd052f6 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -537,8 +537,52 @@ When doing a mapping MapStruct checks if there is a builder for the type being m If there is no builder, then MapStruct looks for a single accessible constructor. When there are multiple constructors then the following is done to pick the one which should be used: -* If a parameterless constructor exists then it would be used to construct the object, and the other constructors will be ignored -* If there are multiple constructors then the one annotated with annotation named `@Default` (from any package) will be used +* If a constructor is annotated with an annotation named `@Default` (from any package) it will be used. +* If a single public constructor exists then it will be used to construct the object, and the other non public constructors will be ignored. +* If a parameterless constructor exists then it will be used to construct the object, and the other constructors will be ignored. +* If there are multiple eligible constructors then there will be a compilation error due to ambigious constructors. In order to break the ambiquity an annotation named `@Default` (from any package) can used. + +.Deciding which constructor to use +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Vehicle { + + protected Vehicle() { } + + // MapStruct will use this constructor, because it is a single public constructor + public Vehicle(String color) { } +} + +public class Car { + + // MapStruct will use this constructor, because it is a parameterless empty constructor + public Car() { } + + public Car(String make, String color) { } +} + +public class Truck { + + public Truck() { } + + // MapStruct will use this constructor, because it is annotated with @Default + @Default + public Truck(String make, String color) { } +} + +public class Van { + + // There will be a compilation error when using this class because MapStruct cannot pick a constructor + + public Van(String make) { } + + public Van(String make, String color) { } + +} +---- +==== When using a constructor then the names of the parameters of the constructor will be used and matched to the target properties. When the constructor has an annotation named `@ConstructorProperties` (from any package) then this annotation will be used to get the names of the parameters. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1be610842a..dc5d6ac41e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -603,23 +603,57 @@ private ConstructorAccessor getConstructorAccessor(Type type) { List constructors = ElementFilter.constructorsIn( type.getTypeElement() .getEnclosedElements() ); - ExecutableElement defaultConstructor = null; + // The rules for picking a constructor are the following: + // 1. Constructor annotated with @Default (from any package) has highest precedence + // 2. If there is a single public constructor then it would be used to construct the object + // 3. If a parameterless constructor exists then it would be used to construct the object, and the other + // constructors will be ignored + ExecutableElement defaultAnnotatedConstructor = null; + ExecutableElement parameterLessConstructor = null; List accessibleConstructors = new ArrayList<>( constructors.size() ); + List publicConstructors = new ArrayList<>( ); for ( ExecutableElement constructor : constructors ) { if ( constructor.getModifiers().contains( Modifier.PRIVATE ) ) { continue; } + if ( hasDefaultAnnotationFromAnyPackage( constructor ) ) { + // We found a constructor annotated with @Default everything else is irrelevant + defaultAnnotatedConstructor = constructor; + break; + } + if ( constructor.getParameters().isEmpty() ) { - defaultConstructor = constructor; + parameterLessConstructor = constructor; } else { accessibleConstructors.add( constructor ); } + + if ( constructor.getModifiers().contains( Modifier.PUBLIC ) ) { + publicConstructors.add( constructor ); + } + } + + if ( defaultAnnotatedConstructor != null ) { + // If a default annotated constructor exists it will be used, it has highest precedence + return getConstructorAccessor( type, defaultAnnotatedConstructor ); + } + + if ( publicConstructors.size() == 1 ) { + // If there is a single public constructor then use that one + ExecutableElement publicConstructor = publicConstructors.get( 0 ); + if ( publicConstructor.getParameters().isEmpty() ) { + // The public parameterless constructor + return null; + } + + return getConstructorAccessor( type, publicConstructor ); } - if ( defaultConstructor != null ) { + if ( parameterLessConstructor != null ) { + // If there is a constructor without parameters use it return null; } @@ -627,39 +661,26 @@ private ConstructorAccessor getConstructorAccessor(Type type) { return null; } - ExecutableElement constructor = null; if ( accessibleConstructors.size() > 1 ) { - for ( ExecutableElement accessibleConstructor : accessibleConstructors ) { - for ( AnnotationMirror annotationMirror : accessibleConstructor.getAnnotationMirrors() ) { - if ( annotationMirror.getAnnotationType() - .asElement() - .getSimpleName() - .contentEquals( "Default" ) ) { - constructor = accessibleConstructor; - break; - } - } - } - - if ( constructor == null ) { - ctx.getMessager().printMessage( - method.getExecutable(), - GENERAL_AMBIGIOUS_CONSTRUCTORS, - type, - Strings.join( constructors, ", " ) - ); - return null; - } + ctx.getMessager().printMessage( + method.getExecutable(), + GENERAL_AMBIGIOUS_CONSTRUCTORS, + type, + Strings.join( constructors, ", " ) + ); + return null; } else { - constructor = accessibleConstructors.get( 0 ); + return getConstructorAccessor( type, accessibleConstructors.get( 0 ) ); } + } + + private ConstructorAccessor getConstructorAccessor(Type type, ExecutableElement constructor) { List constructorParameters = ctx.getTypeFactory() .getParameters( (DeclaredType) type.getTypeMirror(), constructor ); - List constructorProperties = null; for ( AnnotationMirror annotationMirror : constructor.getAnnotationMirrors() ) { if ( annotationMirror.getAnnotationType() @@ -736,6 +757,19 @@ private Accessor createConstructorAccessor(Element element, String parameterName return new ParameterElementAccessor( element, safeParameterName ); } + private boolean hasDefaultAnnotationFromAnyPackage(Element element) { + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + if ( annotationMirror.getAnnotationType() + .asElement() + .getSimpleName() + .contentEquals( "Default" ) ) { + return true; + } + } + + return false; + } + private List getArrayValues(AnnotationValue av) { if ( av.getValue() instanceof List ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java new file mode 100644 index 0000000000..b40dcbf17c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java @@ -0,0 +1,79 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.visibility; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.Default; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2150") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + PersonDto.class, + Default.class, +}) +public class ConstructorVisibilityTest { + + @Test + @WithClasses({ + SimpleWithPublicConstructorMapper.class + }) + public void shouldUseSinglePublicConstructorAlways() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + + SimpleWithPublicConstructorMapper.Person target = + SimpleWithPublicConstructorMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + } + + @Test + @WithClasses({ + SimpleWithPublicParameterlessConstructorMapper.class + }) + public void shouldUsePublicParameterConstructorIfPresent() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + + SimpleWithPublicParameterlessConstructorMapper.Person target = + SimpleWithPublicParameterlessConstructorMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "From Constructor" ); + assertThat( target.getAge() ).isEqualTo( -1 ); + } + + @Test + @WithClasses({ + SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.class + }) + public void shouldUseDefaultAnnotatedConstructorAlways() { + PersonDto source = new PersonDto(); + source.setName( "Bob" ); + source.setAge( 30 ); + + SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.Person target = + SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "Bob" ); + assertThat( target.getAge() ).isEqualTo( 30 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicConstructorMapper.java new file mode 100644 index 0000000000..ce0a98aa34 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicConstructorMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.visibility; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleWithPublicConstructorMapper { + + SimpleWithPublicConstructorMapper INSTANCE = Mappers.getMapper( SimpleWithPublicConstructorMapper.class ); + + Person map(PersonDto dto); + + class Person { + + private final String name; + private final int age; + + protected Person() { + this( "From Constructor", -1 ); + } + + protected Person(String name) { + this( name, -1 ); + } + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.java new file mode 100644 index 0000000000..923821681a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.visibility; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.Default; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper { + + SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper INSTANCE = Mappers.getMapper( + SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.class ); + + Person map(PersonDto dto); + + class Person { + + private final String name; + private final int age; + + protected Person() { + this( "From Constructor", -1 ); + } + + protected Person(String name) { + this( name, -1 ); + } + + @Default + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorMapper.java new file mode 100644 index 0000000000..c0ba14bc42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/SimpleWithPublicParameterlessConstructorMapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.visibility; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleWithPublicParameterlessConstructorMapper { + + SimpleWithPublicParameterlessConstructorMapper INSTANCE = Mappers.getMapper( + SimpleWithPublicParameterlessConstructorMapper.class ); + + Person map(PersonDto dto); + + class Person { + + private final String name; + private final int age; + + public Person() { + this( "From Constructor", -1 ); + } + + protected Person(String name) { + this( name, -1 ); + } + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + } +} From 36349c49e9e545c2d9f55bfc02e457fe1a596433 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 19 Jul 2020 15:40:30 +0200 Subject: [PATCH 0487/1006] #2156 ambiguous mapping message: location and limit # candidates (#2162) --- .../model/AbstractMappingMethodBuilder.java | 11 ++- .../ap/internal/model/BeanMappingMethod.java | 6 +- .../model/ContainerMappingMethodBuilder.java | 1 + .../ap/internal/model/MapMappingMethod.java | 2 + .../internal/model/MappingBuilderContext.java | 3 +- .../model/ObjectFactoryMethodResolver.java | 2 +- .../ap/internal/model/PropertyMapping.java | 2 + .../creation/MappingResolverImpl.java | 82 ++++++++++++------- .../mapstruct/ap/internal/util/Message.java | 13 +-- .../ap/internal/util/MessageConstants.java | 1 + .../ap/test/bugs/_1242/Issue1242Test.java | 3 +- .../AmbiguousAnnotatedFactoryTest.java | 3 +- .../ambiguousfactorymethod/FactoryTest.java | 4 +- .../ambiguousmapping/AmbigiousMapperTest.java | 67 +++++++++++++++ .../ErroneousWithAmbiguousMethodsMapper.java | 52 ++++++++++++ ...ithMoreThanFiveAmbiguousMethodsMapper.java | 74 +++++++++++++++++ .../complex/ComplexInheritanceTest.java | 13 ++- .../resulttype/InheritanceSelectionTest.java | 4 +- 18 files changed, 287 insertions(+), 56 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 019f941741..91b8427630 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -27,6 +27,8 @@ public AbstractMappingMethodBuilder(Class selfType) { public abstract M build(); + private ForgedMethodHistory description; + /** * @return {@code true} if property names should be used for the creation of the {@link ForgedMethodHistory}. */ @@ -44,7 +46,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { history = ( (ForgedMethod) method ).getHistory(); } - ForgedMethodHistory forgedHistory = new ForgedMethodHistory( + description = new ForgedMethodHistory( history, Strings.stubPropertyName( sourceRHS.getSourceType().getName() ), Strings.stubPropertyName( targetType.getName() ), @@ -53,7 +55,7 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { shouldUsePropertyNamesInHistory(), sourceRHS.getSourceErrorMessagePart() ); - ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, forgedHistory, true ); + ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, description, true ); BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); return createForgedAssignment( @@ -77,4 +79,9 @@ private String getName(Type type) { builder.append( type.getIdentification() ); return builder.toString(); } + + public ForgedMethodHistory getDescription() { + return description; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index dc5d6ac41e..a82ee1a091 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -62,7 +62,7 @@ import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_ABSTRACT; import static org.mapstruct.ap.internal.util.Message.BEANMAPPING_NOT_ASSIGNABLE; import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; -import static org.mapstruct.ap.internal.util.Message.GENERAL_AMBIGIOUS_CONSTRUCTORS; +import static org.mapstruct.ap.internal.util.Message.GENERAL_AMBIGUOUS_CONSTRUCTORS; import static org.mapstruct.ap.internal.util.Message.GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS; /** @@ -569,7 +569,7 @@ else if ( matchingFactoryMethods.size() == 1 ) { else { ctx.getMessager().printMessage( method.getExecutable(), - Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, + Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, returnTypeImpl, Strings.join( matchingFactoryMethods, ", " ) ); @@ -665,7 +665,7 @@ private ConstructorAccessor getConstructorAccessor(Type type) { ctx.getMessager().printMessage( method.getExecutable(), - GENERAL_AMBIGIOUS_CONSTRUCTORS, + GENERAL_AMBIGUOUS_CONSTRUCTORS, type, Strings.join( constructors, ", " ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 67c03fd3de..79113ce61a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -83,6 +83,7 @@ public final M build() { ); Assignment assignment = ctx.getMappingResolver().getTargetAssignment( method, + getDescription(), targetElementType, formattingParameters, criteria, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 0fbe6f9c00..415f9b6c33 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -96,6 +96,7 @@ public MapMappingMethod build() { Assignment keyAssignment = ctx.getMappingResolver().getTargetAssignment( method, + getDescription(), keyTargetType, keyFormattingParameters, keyCriteria, @@ -142,6 +143,7 @@ public MapMappingMethod build() { Assignment valueAssignment = ctx.getMappingResolver().getTargetAssignment( method, + getDescription(), valueTargetType, valueFormattingParameters, valueCriteria, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 53317aefa0..f5c5887d54 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -78,6 +78,7 @@ public interface MappingResolver { * returns a parameter assignment * * @param mappingMethod target mapping method + * @param description * @param targetType return type to match * @param formattingParameters used for formatting dates and numbers * @param criteria parameters criteria in the selection process @@ -92,7 +93,7 @@ public interface MappingResolver { *
      • null, no assignment found
      • *
    */ - Assignment getTargetAssignment(Method mappingMethod, Type targetType, + Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory description, Type targetType, FormattingParameters formattingParameters, SelectionCriteria criteria, SourceRHS sourceRHS, AnnotationMirror positionHint, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 34d2944276..34fba406ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -81,7 +81,7 @@ public static MethodReference getFactoryMethod( Method method, if ( matchingFactoryMethods.size() > 1 ) { ctx.getMessager().printMessage( method.getExecutable(), - Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, + Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, alternativeTarget, Strings.join( matchingFactoryMethods, ", " ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 571c3530f1..4e0050e561 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -242,6 +242,7 @@ public PropertyMapping build() { if ( forgeMethodWithMappingReferences == null ) { assignment = ctx.getMappingResolver().getTargetAssignment( method, + getForgedMethodHistory( rightHandSide ), targetType, formattingParameters, criteria, @@ -791,6 +792,7 @@ public PropertyMapping build() { if ( !targetType.isEnumType() ) { assignment = ctx.getMappingResolver().getTargetAssignment( method, + null, // TODO description for constant targetType, formattingParameters, criteria, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 5edd792944..8fa20f079d 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -39,6 +39,7 @@ import org.mapstruct.ap.internal.conversion.Conversions; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.Field; +import org.mapstruct.ap.internal.model.ForgedMethodHistory; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.MappingBuilderContext.MappingResolver; @@ -74,6 +75,8 @@ */ public class MappingResolverImpl implements MappingResolver { + private static final int MAX_REPORTING_AMBIGUOUS = 5; + private final FormattingMessager messager; private final Types typeUtils; private final TypeFactory typeFactory; @@ -109,7 +112,7 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T } @Override - public Assignment getTargetAssignment(Method mappingMethod, Type targetType, + public Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory description, Type targetType, FormattingParameters formattingParameters, SelectionCriteria criteria, SourceRHS sourceRHS, AnnotationMirror positionHint, @@ -118,6 +121,7 @@ public Assignment getTargetAssignment(Method mappingMethod, Type targetType, ResolvingAttempt attempt = new ResolvingAttempt( sourceModel, mappingMethod, + description, formattingParameters, sourceRHS, criteria, @@ -149,6 +153,7 @@ private MapperReference findMapperReference(Method method) { private class ResolvingAttempt { private final Method mappingMethod; + private final ForgedMethodHistory description; private final List methods; private final SelectionCriteria selectionCriteria; private final SourceRHS sourceRHS; @@ -163,7 +168,7 @@ private class ResolvingAttempt { // so this set must be cleared. private final Set supportingMethodCandidates; - private ResolvingAttempt(List sourceModel, Method mappingMethod, + private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedMethodHistory description, FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria, AnnotationMirror positionHint, @@ -172,6 +177,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, FormattingMessager messager) { this.mappingMethod = mappingMethod; + this.description = description; this.methods = filterPossibleCandidateMethods( sourceModel ); this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; @@ -202,7 +208,7 @@ private Assignment getTargetAssignment(Type sourceType, Type targetType) { // first simple mapping method if ( allowMappingMethod() ) { List> matches = getBestMatch( methods, sourceType, targetType ); - reportErrorWhenAmbigious( matches, targetType ); + reportErrorWhenAmbiguous( matches, targetType ); if ( !matches.isEmpty() ) { assignment = toMethodRef( first( matches ) ); assignment.setAssignment( sourceRHS ); @@ -246,7 +252,7 @@ && allowDirect( sourceType, targetType ) ) { // check for a built-in method if ( !hasQualfiers() ) { List> matches = getBestMatch( builtIns, sourceType, targetType ); - reportErrorWhenAmbigious( matches, targetType ); + reportErrorWhenAmbiguous( matches, targetType ); if ( !matches.isEmpty() ) { assignment = toBuildInRef( first( matches ) ); assignment.setAssignment( sourceRHS ); @@ -443,29 +449,37 @@ private List> getBestMatch(List methods, ); } - private void reportErrorWhenAmbigious(List> candidates, Type target) { + private void reportErrorWhenAmbiguous(List> candidates, Type target) { // raise an error if more than one mapping method is suitable to map the given source type // into the target type if ( candidates.size() > 1 ) { + String descriptionStr = ""; + if ( description != null ) { + descriptionStr = description.createSourcePropertyErrorMessage(); + } + else { + descriptionStr = sourceRHS.getSourceErrorMessagePart(); + } + if ( sourceRHS.getSourceErrorMessagePart() != null ) { messager.printMessage( mappingMethod.getExecutable(), positionHint, - Message.GENERAL_AMBIGIOUS_MAPPING_METHOD, - sourceRHS.getSourceErrorMessagePart(), + Message.GENERAL_AMBIGUOUS_MAPPING_METHOD, + descriptionStr, target, - Strings.join( candidates, ", " ) + join( candidates ) ); } else { messager.printMessage( mappingMethod.getExecutable(), positionHint, - Message.GENERAL_AMBIGIOUS_FACTORY_METHOD, + Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, target, - Strings.join( candidates, ", " ) + join( candidates ) ); } } @@ -578,6 +592,18 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { return false; } + private String join( List> candidates ) { + + String candidateStr = candidates.stream() + .limit( MAX_REPORTING_AMBIGUOUS ) + .map( m -> m.getMethod().shortName() ) + .collect( Collectors.joining( ", " ) ); + + if ( candidates.size() > MAX_REPORTING_AMBIGUOUS ) { + candidateStr += String.format( "... and %s more", candidates.size() - MAX_REPORTING_AMBIGUOUS ); + } + return candidateStr; + } } private static class ConversionAssignment { @@ -762,28 +788,26 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType) { result = methodRefY; } else { - reportAmbigiousError( xCandidates, targetType ); + reportAmbiguousError( xCandidates, targetType ); } return this; } - void reportAmbigiousError(Map, List>> xCandidates, Type target) { + void reportAmbiguousError(Map, List>> xCandidates, Type target) { StringBuilder result = new StringBuilder(); xCandidates.entrySet() .stream() + .limit( MAX_REPORTING_AMBIGUOUS ) .forEach( e -> result.append( "method(s)Y: " ) - .append( e.getValue() - .stream() - .map( v -> v.getMethod().shortName() ) - .collect( Collectors.joining( ", " ) ) ) + .append( attempt.join( e.getValue() ) ) .append( ", methodX: " ) .append( e.getKey().getMethod().shortName() ) .append( "; " ) ); attempt.messager.printMessage( attempt.mappingMethod.getExecutable(), attempt.positionHint, - Message.GENERAL_AMBIGIOUS_MAPPING_METHODY_METHODX, + Message.GENERAL_AMBIGUOUS_MAPPING_METHODY_METHODX, attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), target.getName(), result.toString() ); @@ -878,28 +902,26 @@ private ConversionMethod getBestMatch(Type sourceType, Type targetType) { result = methodRefY; } else { - reportAmbigiousError( xRefCandidates, targetType ); + reportAmbiguousError( xRefCandidates, targetType ); } return this; } - void reportAmbigiousError(Map>> xRefCandidates, Type target) { + void reportAmbiguousError(Map>> xRefCandidates, Type target) { StringBuilder result = new StringBuilder(); xRefCandidates.entrySet() .stream() + .limit( MAX_REPORTING_AMBIGUOUS ) .forEach( e -> result.append( "method(s)Y: " ) - .append( e.getValue() - .stream() - .map( v -> v.getMethod().shortName() ) - .collect( Collectors.joining( ", " ) ) ) + .append( attempt.join( e.getValue() ) ) .append( ", conversionX: " ) .append( e.getKey().shortName() ) .append( "; " ) ); attempt.messager.printMessage( attempt.mappingMethod.getExecutable(), attempt.positionHint, - Message.GENERAL_AMBIGIOUS_MAPPING_METHODY_CONVERSIONX, + Message.GENERAL_AMBIGUOUS_MAPPING_METHODY_CONVERSIONX, attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), target.getName(), result.toString() ); @@ -997,28 +1019,26 @@ private MethodConversion getBestMatch(Type sourceType, Type targetType) { result = conversionRefY.assignment; } else { - reportAmbigiousError( yRefCandidates, targetType ); + reportAmbiguousError( yRefCandidates, targetType ); } return this; } - void reportAmbigiousError(Map>> yRefCandidates, Type target) { + void reportAmbiguousError(Map>> yRefCandidates, Type target) { StringBuilder result = new StringBuilder(); yRefCandidates.entrySet() .stream() + .limit( MAX_REPORTING_AMBIGUOUS ) .forEach( e -> result.append( "conversionY: " ) .append( e.getKey().shortName() ) .append( ", method(s)X: " ) - .append( e.getValue() - .stream() - .map( v -> v.getMethod().shortName() ) - .collect( Collectors.joining( ", " ) ) ) + .append( attempt.join( e.getValue() ) ) .append( "; " ) ); attempt.messager.printMessage( attempt.mappingMethod.getExecutable(), attempt.positionHint, - Message.GENERAL_AMBIGIOUS_MAPPING_CONVERSIONY_METHODX, + Message.GENERAL_AMBIGUOUS_MAPPING_CONVERSIONY_METHODX, attempt.sourceRHS.getSourceType().getName() + " " + attempt.sourceRHS.getSourceParameterName(), target.getName(), result.toString() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index d10faf64b9..e2a476ec9a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -7,6 +7,7 @@ import javax.tools.Diagnostic; +import static org.mapstruct.ap.internal.util.MessageConstants.FAQ_AMBIGUOUS_URL; import static org.mapstruct.ap.internal.util.MessageConstants.FAQ_QUALIFIER_URL; /** @@ -111,9 +112,9 @@ public enum Message { GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ), GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), - GENERAL_AMBIGIOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s." ), - GENERAL_AMBIGIOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s." ), - GENERAL_AMBIGIOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), + GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), + GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), + GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), @@ -125,9 +126,9 @@ public enum Message { GENERAL_NO_QUALIFYING_METHOD_NAMED( "Qualifier error. No method found annotated with @Named#value: [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), GENERAL_NO_QUALIFYING_METHOD_COMBINED( "Qualifier error. No method found annotated with @Named#value: [ %s ], annotated with [ %s ]. See " + FAQ_QUALIFIER_URL + " for more info." ), - GENERAL_AMBIGIOUS_MAPPING_METHODY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( methodX ( parameter ) ): %s." ), - GENERAL_AMBIGIOUS_MAPPING_CONVERSIONY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found conversionY( methodX ( parameter ) ): %s." ), - GENERAL_AMBIGIOUS_MAPPING_METHODY_CONVERSIONX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( conversionX ( parameter ) ): %s." ), + GENERAL_AMBIGUOUS_MAPPING_METHODY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( methodX ( parameter ) ): %s." ), + GENERAL_AMBIGUOUS_MAPPING_CONVERSIONY_METHODX( "Ambiguous 2step methods found, mapping %s to %s. Found conversionY( methodX ( parameter ) ): %s." ), + GENERAL_AMBIGUOUS_MAPPING_METHODY_CONVERSIONX( "Ambiguous 2step methods found, mapping %s to %s. Found methodY( conversionX ( parameter ) ): %s." ), BUILDER_MORE_THAN_ONE_BUILDER_CREATION_METHOD( "More than one builder creation method for \"%s\". Found methods: \"%s\". Builder will not be used. Consider implementing a custom BuilderProvider SPI.", Diagnostic.Kind.WARNING ), BUILDER_NO_BUILD_METHOD_FOUND("No build method \"%s\" found in \"%s\" for \"%s\". Found methods: \"%s\".", Diagnostic.Kind.ERROR ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java index d3dabdb2d8..6b4603af19 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MessageConstants.java @@ -9,6 +9,7 @@ public final class MessageConstants { public static final String AND = " and "; public static final String FAQ_QUALIFIER_URL = "https://mapstruct.org/faq/#qualifier"; + public static final String FAQ_AMBIGUOUS_URL = "https://mapstruct.org/faq/#ambiguous"; private MessageConstants() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 0cf59e7267..80e1038127 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -65,7 +65,8 @@ public void factoryMethodWithSourceParamIsChosen() { ".lang.Class clazz), org.mapstruct.ap.test.bugs._1242" + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB(@TargetType java.lang" + ".Class clazz), org.mapstruct.ap.test.bugs._1242" + - ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB().") + ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB()." + + " See https://mapstruct.org/faq/#ambiguous for more info." ) }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 94993e4a66..24cdbe3a53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -36,7 +36,8 @@ public class AmbiguousAnnotatedFactoryTest { ".ambiguousannotatedfactorymethod.Foo foo), org.mapstruct.ap.test.erroneous" + ".ambiguousannotatedfactorymethod.Bar org.mapstruct.ap.test.erroneous" + ".ambiguousannotatedfactorymethod.AmbiguousBarFactory.createBar(org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Foo foo).") + ".ambiguousannotatedfactorymethod.Foo foo)." + + " See https://mapstruct.org/faq/#ambiguous for more info.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index e4e9ff81cb..682c46d036 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -37,8 +37,8 @@ public class FactoryTest { message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + ".ambiguousfactorymethod.Bar: org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar " + "createBar(), org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar org.mapstruct.ap.test" + - ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar().") - + ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar()." + + " See https://mapstruct.org/faq/#ambiguous for more info.") } ) public void shouldUseTwoFactoryMethods() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java new file mode 100644 index 0000000000..a04373b13f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.ambiguousmapping; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@IssueKey("2156") +@RunWith(AnnotationProcessorTestRunner.class) +public class AmbigiousMapperTest { + + @Test + @WithClasses( ErroneousWithAmbiguousMethodsMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousWithAmbiguousMethodsMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + message = "Ambiguous mapping methods found for mapping property " + + "\"org.mapstruct.ap.test.erroneous.ambiguousmapping." + + "ErroneousWithAmbiguousMethodsMapper.LeafDTO branch.leaf\" to " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping." + + "ErroneousWithAmbiguousMethodsMapper.LeafEntity: " + + "LeafEntity:map1(LeafDTO), LeafEntity:map2(LeafDTO). " + + "See https://mapstruct.org/faq/#ambiguous for more info.") + } + ) + + public void testErrorMessageForAmbiguous() { + } + + @Test + @WithClasses( ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "Ambiguous mapping methods found for mapping property " + + "\"org.mapstruct.ap.test.erroneous.ambiguousmapping." + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO branch.leaf\" to " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping." + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity: " + + "LeafEntity:map1(LeafDTO), " + + "LeafEntity:map2(LeafDTO), " + + "LeafEntity:map3(LeafDTO), " + + "LeafEntity:map4(LeafDTO), " + + "LeafEntity:map5(LeafDTO)" + + "... and 1 more. " + + "See https://mapstruct.org/faq/#ambiguous for more info.") + } + ) + public void testErrorMessageForManyAmbiguous() { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java new file mode 100644 index 0000000000..7ebce015d1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.ambiguousmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousWithAmbiguousMethodsMapper { + + ErroneousWithAmbiguousMethodsMapper INSTANCE = Mappers.getMapper( ErroneousWithAmbiguousMethodsMapper.class ); + + TrunkEntity map(TrunkDTO dto); + + default LeafEntity map1(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + default LeafEntity map2(LeafDTO dto) { + return new LeafEntity(); + } + + // CHECKSTYLE:OFF + class TrunkDTO { + public BranchDTO branch; + } + + class BranchDTO { + public LeafDTO leaf; + } + + class LeafDTO { + public int numberOfVeigns; + } + + class TrunkEntity { + public BranchEntity branch; + } + + class BranchEntity { + public LeafEntity leaf; + } + + class LeafEntity { + public int numberOfVeigns; + } + // CHECKSTYLE ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java new file mode 100644 index 0000000000..1e050cea71 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.ambiguousmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousWithMoreThanFiveAmbiguousMethodsMapper { + + ErroneousWithMoreThanFiveAmbiguousMethodsMapper + INSTANCE = Mappers.getMapper( ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class ); + + TrunkEntity map(TrunkDTO dto); + + default LeafEntity map1(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + default LeafEntity map2(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + default LeafEntity map3(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + default LeafEntity map4(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + + default LeafEntity map5(LeafDTO dto) { + return new LeafEntity(); + } + + // duplicated method, triggering ambigious mapping method + default LeafEntity map6(LeafDTO dto) { + return new LeafEntity(); + } + + // CHECKSTYLE:OFF + class TrunkDTO { + public BranchDTO branch; + } + + class BranchDTO { + public LeafDTO leaf; + } + + class LeafDTO { + public int numberOfVeigns; + } + + class TrunkEntity { + public BranchEntity branch; + } + + class BranchEntity { + public LeafEntity leaf; + } + + class LeafEntity { + public int numberOfVeigns; + } + // CHECKSTYLE ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index dc37b5f79c..7c2459b118 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -69,13 +69,12 @@ public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { kind = Kind.ERROR, type = ErroneousSourceCompositeTargetCompositeMapper.class, line = 19, - message = "Ambiguous mapping methods found for mapping property \"org.mapstruct.ap.test.inheritance" + - ".complex.SourceExt prop1\" to org.mapstruct.ap.test.inheritance.complex.Reference: org.mapstruct.ap" + - ".test.inheritance.complex.Reference org.mapstruct.ap.test.inheritance.complex" + - ".AdditionalMappingHelper.asReference(org.mapstruct.ap.test.inheritance.complex.SourceBase source), " + - "org.mapstruct.ap.test.inheritance.complex.Reference org.mapstruct.ap.test.inheritance.complex" + - ".AdditionalMappingHelper.asReference(org.mapstruct.ap.test.inheritance.complex.AdditionalFooSource " + - "source).")) + message = "Ambiguous mapping methods found for mapping property " + + "\"org.mapstruct.ap.test.inheritance.complex.SourceExt prop1\" " + + "to org.mapstruct.ap.test.inheritance.complex.Reference: " + + "Reference:asReference(SourceBase), Reference:asReference(AdditionalFooSource). " + + "See https://mapstruct.org/faq/#ambiguous for more info.") + ) public void ambiguousMappingMethodsReportError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 5cd415e56e..9db58ec201 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -48,7 +48,9 @@ public class InheritanceSelectionTest { message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.selection.resulttype" + ".Fruit: org.mapstruct.ap.test.selection.resulttype.Apple org.mapstruct.ap.test.selection" + ".resulttype.ConflictingFruitFactory.createApple(), org.mapstruct.ap.test.selection.resulttype" + - ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana().") + ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana()." + + " See https://mapstruct.org/faq/#ambiguous for more info." + ) } ) public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() { From 28017e2b0ca99793b1bf8da933ec0811b75c3635 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Jul 2020 15:01:49 +0200 Subject: [PATCH 0488/1006] Add test case for demonstrating how the ignoreByDefault can be overridden from the base configuration --- .../ignore/inherit/IgnorePropertyTest.java | 22 ++++++++++++++++++- .../ap/test/ignore/inherit/ToolMapper.java | 11 +++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java index 7dce466b41..ef0cf6fc68 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java @@ -56,7 +56,7 @@ public void shouldIgnoreAllExeptOveriddenInherited() { @Test @IssueKey("1933") - public void shouldIgnoreBase() { + public void shouldInheritIgnoreByDefaultFromBase() { WorkBenchDto workBenchDto = new WorkBenchDto(); workBenchDto.setArticleName( "MyBench" ); @@ -74,4 +74,24 @@ public void shouldIgnoreBase() { assertThat( benchTarget.getCreationDate() ).isNull(); } + @Test + @IssueKey("1933") + public void shouldOnlyIgnoreBase() { + + WorkBenchDto workBenchDto = new WorkBenchDto(); + workBenchDto.setArticleName( "MyBench" ); + workBenchDto.setArticleDescription( "Beautiful" ); + workBenchDto.setCreationDate( new Date() ); + workBenchDto.setModificationDate( new Date() ); + + WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBenchWithImplicit( workBenchDto ); + + assertThat( benchTarget ).isNotNull(); + assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" ); + assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" ); + assertThat( benchTarget.getKey() ).isNull(); + assertThat( benchTarget.getModificationDate() ).isNull(); + assertThat( benchTarget.getCreationDate() ).isNull(); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java index ca7da9b99c..10c3a513f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/ToolMapper.java @@ -29,12 +29,21 @@ public interface ToolMapper { @InheritConfiguration( name = "mapBase" ) ToolEntity mapTool(ToolDto source); - // demonstrates that all the business stuff is mapped (implicit-by-name and defined) + // demonstrates that all the business stuff is mapped only defined because BeanMapping#ignoreByDefault @InheritConfiguration( name = "mapBase" ) @Mapping(target = "description", source = "articleDescription") WorkBenchEntity mapBench(WorkBenchDto source); + // demonstrates that all the business stuff is mapped (implicit-by-name and defined) + @BeanMapping( ignoreByDefault = false ) // needed to override the one from the BeanMapping mapBase + @InheritConfiguration( name = "mapBase" ) + @Mapping(target = "description", source = "articleDescription") + WorkBenchEntity mapBenchWithImplicit(WorkBenchDto source); + // ignore all the base properties by default @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "key", ignore = true) + @Mapping( target = "modificationDate", ignore = true) + @Mapping( target = "creationDate", ignore = true) BaseEntity mapBase(Object o); } From 0495cb7fa77271193cc4e0e774080256cb185b73 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Jul 2020 15:26:48 +0200 Subject: [PATCH 0489/1006] #2149 Do not allow using BeanMapping(ignoreByDefault = true) in combination with Mapping(target = ".") This fixes an ArrayIndexOutOfBoundsException when they were used together --- .../model/source/MappingMethodOptions.java | 41 +++++++-- .../processor/MapperCreationProcessor.java | 2 +- .../mapstruct/ap/internal/util/Message.java | 1 + .../test/bugs/_2149/Erroneous2149Mapper.java | 84 +++++++++++++++++++ .../ap/test/bugs/_2149/Issue2149Test.java | 47 +++++++++++ 5 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Erroneous2149Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index e0007949a9..b7fd7f00d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -11,11 +11,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy; @@ -250,7 +251,8 @@ private boolean elementsAreContainedIn( String redefinedName, String inheritedNa return false; } - public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { + public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory, + FormattingMessager messager) { CollectionMappingStrategyGem cms = method.getOptions().getMapper().getCollectionMappingStrategy(); Type writeType = method.getResultType(); if ( !method.isUpdateMethod() ) { @@ -262,15 +264,27 @@ public void applyIgnoreAll(SourceMethod method, TypeFactory typeFactory ) { Map writeAccessors = writeType.getPropertyWriteAccessors( cms ); - Set mappedPropertyNames = mappings.stream() - .map( m -> getPropertyEntries( m )[0] ) - .collect( Collectors.toSet() ); + for ( MappingOptions mapping : mappings ) { + String mappedTargetProperty = getFirstTargetPropertyName( mapping ); + if ( !".".equals( mappedTargetProperty ) ) { + // Remove the mapped target property from the write accessors + writeAccessors.remove( mappedTargetProperty ); + } + else { + messager.printMessage( + method.getExecutable(), + getBeanMapping().getMirror(), + Message.BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS + ); + // Nothing more to do if this is reached + return; + } + } + // The writeAccessors now contains only the accessors that should be ignored for ( String targetPropertyName : writeAccessors.keySet() ) { - if ( !mappedPropertyNames.contains( targetPropertyName ) ) { - MappingOptions mapping = MappingOptions.forIgnore( targetPropertyName ); - mappings.add( mapping ); - } + MappingOptions mapping = MappingOptions.forIgnore( targetPropertyName ); + mappings.add( mapping ); } } @@ -290,4 +304,13 @@ private String[] getPropertyEntries( MappingOptions mapping ) { return mapping.getTargetName().split( "\\." ); } + private String getFirstTargetPropertyName(MappingOptions mapping) { + String targetName = mapping.getTargetName(); + if ( ".".equals( targetName ) ) { + return targetName; + } + + return getPropertyEntries( mapping )[0]; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index e480eaf7a1..25f25c3c3f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -486,7 +486,7 @@ else if ( applicableReversePrototypeMethods.size() > 1 ) { // @BeanMapping( ignoreByDefault = true ) if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isignoreByDefault() ) { - mappingOptions.applyIgnoreAll( method, typeFactory ); + mappingOptions.applyIgnoreAll( method, typeFactory, mappingContext.getMessager() ); } mappingOptions.markAsFullyInitialized(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index e2a476ec9a..2005127fec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -39,6 +39,7 @@ public enum Message { BEANMAPPING_UNMAPPED_SOURCES_ERROR( "Unmapped source %s." ), BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), + BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS( "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not allowed. You'll need to explicitly ignore the target properties that should be ignored instead." ), PROPERTYMAPPING_MAPPING_NOTE( "mapping property: %s to: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_CREATE_NOTE( "creating property mapping: %s.", Diagnostic.Kind.NOTE ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Erroneous2149Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Erroneous2149Mapper.java new file mode 100644 index 0000000000..2b8d73cec2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Erroneous2149Mapper.java @@ -0,0 +1,84 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2149; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Erroneous2149Mapper { + + @BeanMapping(ignoreByDefault = true) + @Mapping(target = ".", source = "name") + Target map(Source source); + + class Target { + + private String firstName; + private String age; + private String address; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getAge() { + return age; + } + + public void setAge(String age) { + this.age = age; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + } + + class Source { + + private final String age; + private final Name name; + + public Source(String age, Name name) { + this.age = age; + this.name = name; + } + + public String getAge() { + return age; + } + + public Name getName() { + return name; + } + } + + class Name { + + private final String firstName; + + public Name(String firstName) { + this.firstName = firstName; + } + + public String getFirstName() { + return firstName; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java new file mode 100644 index 0000000000..80cfbcc7db --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2149; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2149") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Erroneous2149Mapper.class +}) +public class Issue2149Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = Erroneous2149Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + message = "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not " + + "allowed. You'll need to explicitly ignore the target properties that should be ignored instead." + ), + @Diagnostic( + type = Erroneous2149Mapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 20, + message = "Unmapped target property: \"address\"." + ) + } + ) + public void shouldGiveCompileErrorWhenBeanMappingIgnoreByDefaultIsCombinedWithMappingTargetThis() { + } +} From 1d223284c24ee5d701d58623919fd77a5dbbd696 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Jul 2020 18:10:12 +0200 Subject: [PATCH 0490/1006] [maven-release-plugin] prepare release 1.4.0.Beta3 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c908377c8..f6a8aee847 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 63311b5950..a8c0e2d591 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c74e0b8bb1..c3aa7a3555 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b404ed3cee..256024d196 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ceb3cb1db6..8481a58e2b 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a643bab4b8..54d72ec87a 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b26cf8683d..d7d6634276 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta3 diff --git a/pom.xml b/pom.xml index f9c649c168..7b1f68e50e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Beta3 diff --git a/processor/pom.xml b/processor/pom.xml index c047301268..4ef6a0c581 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Beta3 ../parent/pom.xml From ef4bfc9aad701558e0e31797040c4cd33c31d4d4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 19 Jul 2020 18:10:13 +0200 Subject: [PATCH 0491/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index f6a8aee847..6c908377c8 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index a8c0e2d591..63311b5950 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c3aa7a3555..c74e0b8bb1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 256024d196..b404ed3cee 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8481a58e2b..ceb3cb1db6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 54d72ec87a..a643bab4b8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index d7d6634276..b26cf8683d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta3 + HEAD diff --git a/pom.xml b/pom.xml index 7b1f68e50e..f9c649c168 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Beta3 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 4ef6a0c581..c047301268 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Beta3 + 1.4.0-SNAPSHOT ../parent/pom.xml From 2e2c20fed7502c2cb86d20ede130dfa499813a48 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Fri, 24 Jul 2020 23:19:47 +0200 Subject: [PATCH 0492/1006] #2161 use short names instead of FQN's in error messages (#2166) --- .../conversion/CreateDecimalFormat.java | 5 ++ .../internal/model/AbstractBaseBuilder.java | 12 ++-- .../ap/internal/model/BeanMappingMethod.java | 55 ++++++++-------- .../model/ContainerMappingMethodBuilder.java | 3 +- .../ap/internal/model/ForgedMethod.java | 7 ++ .../internal/model/ForgedMethodHistory.java | 2 +- .../ap/internal/model/MapMappingMethod.java | 11 +--- .../NestedTargetPropertyMappingHolder.java | 2 +- .../model/ObjectFactoryMethodResolver.java | 10 ++- .../ap/internal/model/PropertyMapping.java | 8 +-- .../ap/internal/model/ValueMappingMethod.java | 2 +- .../model/beanmapping/AbstractReference.java | 6 +- .../ap/internal/model/common/Parameter.java | 10 ++- .../ap/internal/model/common/Type.java | 34 +++++++++- .../ap/internal/model/common/TypeFactory.java | 12 +++- .../ap/internal/model/source/Method.java | 6 +- .../internal/model/source/SourceMethod.java | 25 +++++++ .../model/source/builtin/BuiltInMethod.java | 6 ++ .../DefaultModelElementProcessorContext.java | 3 +- .../processor/MapperCreationProcessor.java | 4 +- .../processor/MethodRetrievalProcessor.java | 5 ++ .../creation/MappingResolverImpl.java | 41 +++++++----- .../mapstruct/ap/internal/util/Message.java | 4 +- .../DateFormatValidatorFactoryTest.java | 3 +- .../common/DefaultConversionContextTest.java | 3 +- .../ReferencedAccessibilityTest.java | 15 ++--- .../ap/test/bugs/_1005/Issue1005Test.java | 16 ++--- .../ap/test/bugs/_1029/Issue1029Test.java | 4 +- .../ap/test/bugs/_1153/Issue1153Test.java | 13 ++-- .../ap/test/bugs/_1242/Issue1242Test.java | 15 ++--- .../ap/test/bugs/_1283/Issue1283Test.java | 4 +- .../ap/test/bugs/_1698/Issue1698Test.java | 5 +- .../ap/test/bugs/_590/Issue590Test.java | 5 +- .../ErroneousCollectionMappingTest.java | 39 +++++------ .../forged/CollectionMappingTest.java | 21 +++--- .../conversion/lossy/LossyConversionTest.java | 23 ++++--- .../test/defaultvalue/DefaultValueTest.java | 10 ++- .../AmbiguousAnnotatedFactoryTest.java | 10 +-- .../ambiguousfactorymethod/FactoryTest.java | 7 +- .../ambiguousmapping/AmbigiousMapperTest.java | 66 +++++++++++++------ .../ErroneousMappingsTest.java | 3 +- .../ErroneousPropertyMappingTest.java | 19 ++---- .../ap/test/ignore/IgnorePropertyTest.java | 3 +- .../attribute/AttributeInheritanceTest.java | 4 +- .../complex/ComplexInheritanceTest.java | 9 ++- .../erroneous/ErroneousStreamMappingTest.java | 44 +++++-------- .../forged/ForgedStreamMappingTest.java | 7 +- .../mappingcontrol/MappingControlTest.java | 25 +++---- .../SuggestMostSimilarNameTest.java | 11 ++-- ...DisablingNestedSimpleBeansMappingTest.java | 10 ++- .../nestedbeans/DottedErrorMessageTest.java | 42 ++++-------- .../exclusions/ErroneousJavaInternalTest.java | 26 +++----- .../custom/ErroneousCustomExclusionTest.java | 7 +- .../NestedSourcePropertiesTest.java | 3 +- .../selection/generics/ConversionTest.java | 62 +++++++---------- .../selection/qualifier/QualifierTest.java | 10 ++- .../resulttype/InheritanceSelectionTest.java | 20 +++--- .../twosteperror/TwoStepMappingTest.java | 32 ++++----- .../test/source/constants/ConstantsTest.java | 23 +++---- .../source/constants/SourceConstantsTest.java | 9 +-- .../test/updatemethods/UpdateMethodsTest.java | 8 +-- 61 files changed, 465 insertions(+), 444 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java index 9005907d09..77c59445ab 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java @@ -55,4 +55,9 @@ public Type getReturnType() { public MappingMethodOptions getOptions() { return MappingMethodOptions.empty(); } + + @Override + public String describe() { + return null; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index f2e657f8ef..ba13854667 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -146,10 +146,10 @@ void reportCannotCreateMapping(Method method, String sourceErrorMessagePart, Typ method.getExecutable(), Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, sourceErrorMessagePart, - targetType, + targetType.describe(), targetPropertyName, - targetType, - sourceType + targetType.describe(), + sourceType.describe() ); } @@ -171,10 +171,10 @@ void reportCannotCreateMapping(Method method, AnnotationMirror posHint, String s posHint, Message.PROPERTYMAPPING_MAPPING_NOT_FOUND, sourceErrorMessagePart, - targetType, + targetType.describe(), targetPropertyName, - targetType, - sourceType + targetType.describe(), + sourceType.describe() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a82ee1a091..3d86a59299 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -489,8 +489,8 @@ private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) { method.getExecutable(), method.getOptions().getBeanMapping().getMirror(), BEANMAPPING_ABSTRACT, - resultType, - method.getResultType() + resultType.describe(), + method.getResultType().describe() ); error = false; } @@ -499,8 +499,8 @@ else if ( !resultType.isAssignableTo( method.getResultType() ) ) { method.getExecutable(), method.getOptions().getBeanMapping().getMirror(), BEANMAPPING_NOT_ASSIGNABLE, - resultType, - method.getResultType() + resultType.describe(), + method.getResultType().describe() ); error = false; } @@ -509,7 +509,7 @@ else if ( !resultType.hasAccessibleConstructor() ) { method.getExecutable(), method.getOptions().getBeanMapping().getMirror(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - resultType + resultType.describe() ); error = false; } @@ -522,7 +522,7 @@ private boolean canReturnTypeBeConstructed(Type returnType) { ctx.getMessager().printMessage( method.getExecutable(), GENERAL_ABSTRACT_RETURN_TYPE, - returnType + returnType.describe() ); error = false; } @@ -530,7 +530,7 @@ else if ( !returnType.hasAccessibleConstructor() ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, - returnType + returnType.describe() ); error = false; } @@ -570,8 +570,11 @@ else if ( matchingFactoryMethods.size() == 1 ) { ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, - returnTypeImpl, - Strings.join( matchingFactoryMethods, ", " ) + returnTypeImpl.describe(), + matchingFactoryMethods.stream() + .map( SelectedMethod::getMethod ) + .map( Method::describe ) + .collect( Collectors.joining( ", " ) ) ); hasFactoryMethod = true; } @@ -911,13 +914,13 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); Message msg; - Object[] args; + String[] args; if ( targetRef.getPathProperties().isEmpty() ) { msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; - args = new Object[] { + args = new String[] { targetPropertyName, - resultTypeToMap, + resultTypeToMap.describe(), mostSimilarProperty }; } @@ -925,9 +928,9 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp List pathProperties = new ArrayList<>( targetRef.getPathProperties() ); pathProperties.add( mostSimilarProperty ); msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE; - args = new Object[] { + args = new String[] { targetPropertyName, - resultTypeToMap, + resultTypeToMap.describe(), mapping.getTargetName(), Strings.join( pathProperties, "." ) }; @@ -956,14 +959,14 @@ else if ( !mapping.isIgnored() ) { msg = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_RESULTTYPE; args = new Object[] { mapping.getTargetName(), - resultTypeToMap + resultTypeToMap.describe() }; } else { msg = Message.BEANMAPPING_PROPERTY_HAS_NO_WRITE_ACCESSOR_IN_TYPE; args = new Object[] { targetPropertyName, - resultTypeToMap, + resultTypeToMap.describe(), mapping.getTargetName() }; } @@ -1279,10 +1282,10 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { ctx.getMessager().printMessage( this.method.getExecutable(), Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, - sourceType, - targetType, - targetType, - sourceType + sourceType.describe(), + targetType.describe(), + targetType.describe(), + sourceType.describe() ); } else { @@ -1291,10 +1294,10 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { this.method.getExecutable(), Message.PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND, history.createSourcePropertyErrorMessage(), - history.getTargetType(), + history.getTargetType().describe(), history.createTargetPropertyName(), - history.getTargetType(), - history.getSourceType() + history.getTargetType().describe(), + history.getSourceType().describe() ); } } @@ -1321,14 +1324,14 @@ else if ( !ctx.isErroneous() ) { Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_FORGED_TARGETS_WARNING; - String sourceErrorMessage = method.getParameters().get( 0 ).getType().toString(); - String targetErrorMessage = method.getReturnType().toString(); + String sourceErrorMessage = method.getParameters().get( 0 ).getType().describe(); + String targetErrorMessage = method.getReturnType().describe(); if ( ( (ForgedMethod) method ).getHistory() != null ) { ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory(); sourceErrorMessage = history.createSourcePropertyErrorMessage(); targetErrorMessage = MessageFormat.format( "\"{0} {1}\"", - history.getTargetType(), + history.getTargetType().describe(), history.createTargetPropertyName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index 79113ce61a..b9bbf6d094 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -100,7 +100,8 @@ public final M build() { else { reportCannotCreateMapping( method, - String.format( "%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), sourceRHS.getSourceType() ), + String.format( "%s \"%s\"", sourceRHS.getSourceErrorMessagePart(), + sourceRHS.getSourceType().describe() ), sourceRHS.getSourceType(), targetElementType, "" diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index ce1d8c024d..e02107881b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -340,6 +340,13 @@ public MappingMethodOptions getOptions() { return basedOn.getOptions(); } + @Override + public String describe() { + // the name of the forged method is never fully qualified, so no need to distinguish + // between verbose or not. The type knows whether it should log verbose + return getResultType().describe() + ":" + getName() + "(" + getMappingSourceType().describe() + ")"; + } + public MappingReferences getMappingReferences() { return mappingReferences; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java index 9355c62fd5..3463413705 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethodHistory.java @@ -43,7 +43,7 @@ public Type getSourceType() { } public String createSourcePropertyErrorMessage() { - return conditionallyCapitalizedElementType() + " \"" + getSourceType() + " " + + return conditionallyCapitalizedElementType() + " \"" + getSourceType().describe() + " " + stripBrackets( getDottedSourceElement() ) + "\""; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 415f9b6c33..a8b68b435f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -20,7 +20,6 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; -import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; @@ -42,7 +41,6 @@ public static class Builder extends AbstractMappingMethodBuilder sourceTypeParams = @@ -116,7 +109,7 @@ public MapMappingMethod build() { String.format( "%s \"%s\"", keySourceRHS.getSourceErrorMessagePart(), - keySourceRHS.getSourceType() + keySourceRHS.getSourceType().describe() ), keySourceRHS.getSourceType(), keyTargetType, @@ -173,7 +166,7 @@ public MapMappingMethod build() { String.format( "%s \"%s\"", valueSourceRHS.getSourceErrorMessagePart(), - valueSourceRHS.getSourceType() + valueSourceRHS.getSourceType().describe() ), valueSourceRHS.getSourceType(), valueTargetType, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index d46019899f..254ba62871 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -662,7 +662,7 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences m mapping.getTargetAnnotationValue(), Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE, targetPropertyName, - targetType, + targetType.describe(), mapping.getTargetName(), Strings.join( pathProperties, "." ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 34fba406ef..d320bb49da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -21,7 +22,6 @@ import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Message; -import org.mapstruct.ap.internal.util.Strings; import static org.mapstruct.ap.internal.util.Collections.first; @@ -82,8 +82,12 @@ public static MethodReference getFactoryMethod( Method method, ctx.getMessager().printMessage( method.getExecutable(), Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, - alternativeTarget, - Strings.join( matchingFactoryMethods, ", " ) ); + alternativeTarget.describe(), + matchingFactoryMethods.stream() + .map( SelectedMethod::getMethod ) + .map( Method::describe ) + .collect( Collectors.joining( ", " ) ) + ); return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 4e0050e561..240343ad9b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -853,9 +853,8 @@ else if ( errorMessageDetails == null ) { method.getExecutable(), positionHint, Message.CONSTANTMAPPING_MAPPING_NOT_FOUND, - sourceType, constantExpression, - targetType, + targetType.describe(), targetPropertyName ); } @@ -864,9 +863,8 @@ else if ( errorMessageDetails == null ) { method.getExecutable(), positionHint, Message.CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS, - sourceType, constantExpression, - targetType, + targetType.describe(), targetPropertyName, errorMessageDetails ); @@ -899,7 +897,7 @@ private Assignment getEnumAssignment() { positionHint, Message.CONSTANTMAPPING_NON_EXISTING_CONSTANT, constantExpression, - targetType, + targetType.describe(), targetPropertyName ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index adfa5779e8..72f8153c5e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -209,7 +209,7 @@ else if ( NULL.equals( targetConstant ) ) { ForgedMethodHistory history = ( (ForgedMethod) method ).getHistory(); sourceErrorMessage = history.createSourcePropertyErrorMessage(); targetErrorMessage = - "\"" + history.getTargetType().toString() + " " + history.createTargetPropertyName() + "\""; + "\"" + history.getTargetType().describe() + " " + history.createTargetPropertyName() + "\""; } // all sources should now be matched, there's no default to fall back to, so if sources remain, // we have an issue. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java index dcb67c903d..4db93505e3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java @@ -112,18 +112,18 @@ public String toString() { } else if ( propertyEntries.isEmpty() ) { if ( parameter != null ) { - result = String.format( "parameter \"%s %s\"", parameter.getType(), parameter.getName() ); + result = String.format( "parameter \"%s %s\"", parameter.getType().describe(), parameter.getName() ); } } else if ( propertyEntries.size() == 1 ) { PropertyEntry propertyEntry = propertyEntries.get( 0 ); - result = String.format( "property \"%s %s\"", propertyEntry.getType(), propertyEntry.getName() ); + result = String.format( "property \"%s %s\"", propertyEntry.getType().describe(), propertyEntry.getName() ); } else { PropertyEntry lastPropertyEntry = propertyEntries.get( propertyEntries.size() - 1 ); result = String.format( "property \"%s %s\"", - lastPropertyEntry.getType(), + lastPropertyEntry.getType().describe(), Strings.join( getElementNames(), "." ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 2fd2b69eeb..dc62018be5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -83,10 +83,18 @@ public boolean isMappingTarget() { @Override public String toString() { + return String.format( format(), type ); + } + + public String describe() { + return String.format( format(), type.describe() ); + } + + private String format() { return ( mappingTarget ? "@MappingTarget " : "" ) + ( targetType ? "@TargetType " : "" ) + ( mappingContext ? "@Context " : "" ) - + type.toString() + " " + name; + + "%s " + name; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index a829fa61a2..b2b12b8a25 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -81,6 +82,8 @@ public class Type extends ModelElement implements Comparable { private final boolean isStream; private final boolean isLiteral; + private final boolean loggingVerbose; + private final List enumConstants; private final Map toBeImportedTypes; @@ -116,7 +119,7 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, Map toBeImportedTypes, Map notToBeImportedTypes, Boolean isToBeImported, - boolean isLiteral ) { + boolean isLiteral, boolean loggingVerbose) { this.typeUtils = typeUtils; this.elementUtils = elementUtils; @@ -162,6 +165,8 @@ public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, this.toBeImportedTypes = toBeImportedTypes; this.notToBeImportedTypes = notToBeImportedTypes; this.filters = new Filters( accessorNaming, typeUtils, typeMirror ); + + this.loggingVerbose = loggingVerbose; } //CHECKSTYLE:ON @@ -417,7 +422,8 @@ public Type erasure() { toBeImportedTypes, notToBeImportedTypes, isToBeImported, - isLiteral + isLiteral, + loggingVerbose ); } @@ -459,7 +465,8 @@ public Type withoutBounds() { toBeImportedTypes, notToBeImportedTypes, isToBeImported, - isLiteral + isLiteral, + loggingVerbose ); } @@ -1011,6 +1018,27 @@ public String toString() { return typeMirror.toString(); } + /** + * @return a string representation of the type for use in messages + */ + public String describe() { + if ( loggingVerbose ) { + return toString(); + } + else { + // name allows for inner classes + String name = getFullyQualifiedName().replaceFirst( "^" + getPackageName() + ".", "" ); + List typeParams = getTypeParameters(); + if ( typeParams.isEmpty() ) { + return name; + } + else { + String params = typeParams.stream().map( Type::describe ).collect( Collectors.joining( "," ) ); + return String.format( "%s<%s>", name, params ); + } + } + } + /** * * @return an identification that can be used as part in a forged method name. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index a74c02fd7d..9cfe18c176 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -95,8 +95,10 @@ public class TypeFactory { private final Map toBeImportedTypes = new HashMap<>(); private final Map notToBeImportedTypes; + private final boolean loggingVerbose; + public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext, - Map notToBeImportedTypes) { + Map notToBeImportedTypes, boolean loggingVerbose) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; @@ -129,6 +131,8 @@ public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager me ConcurrentNavigableMap.class.getName(), withDefaultConstructor( getType( ConcurrentSkipListMap.class ) ) ); + + this.loggingVerbose = loggingVerbose; } public Type getTypeForLiteral(Class type) { @@ -298,7 +302,8 @@ else if (componentTypeMirror.getKind().isPrimitive()) { toBeImportedTypes, notToBeImportedTypes, toBeImported, - isLiteral + isLiteral, + loggingVerbose ); } @@ -523,7 +528,8 @@ private ImplementationType getImplementationType(TypeMirror mirror) { toBeImportedTypes, notToBeImportedTypes, null, - implementationType.isLiteral() + implementationType.isLiteral(), + loggingVerbose ); return implementation.createNew( replacement ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 39d827d975..2039aa86aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -196,9 +196,7 @@ default Type getMappingSourceType() { } /** - * @return the short name for error messages + * @return the short name for error messages when verbose, full name when not */ - default String shortName() { - return getResultType().getName() + ":" + getName() + "(" + getMappingSourceType().getName() + ")"; - } + String describe(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 9ed432d3ec..98cffb4c35 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -10,6 +10,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.util.Types; @@ -67,6 +68,8 @@ public class SourceMethod implements Method { private Boolean isStreamMapping; private final boolean hasObjectFactoryAnnotation; + private final boolean verboseLogging; + public static class Builder { private Type declaringMapper = null; @@ -86,6 +89,7 @@ public static class Builder { private List valueMappings; private EnumMappingOptions enumMappingOptions; private ParameterProvidedMethods contextProvidedMethods; + private boolean verboseLogging; public Builder setDeclaringMapper(Type declaringMapper) { this.declaringMapper = declaringMapper; @@ -172,6 +176,11 @@ public Builder setContextProvidedMethods(ParameterProvidedMethods contextProvide return this; } + public Builder setVerboseLogging(boolean verboseLogging) { + this.verboseLogging = verboseLogging; + return this; + } + public SourceMethod build() { if ( mappings == null ) { @@ -215,6 +224,8 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.typeFactory = builder.typeFactory; this.prototypeMethods = builder.prototypeMethods; this.mapperToImplement = builder.definingType; + + this.verboseLogging = builder.verboseLogging; } private boolean determineIfIsObjectFactory() { @@ -521,4 +532,18 @@ public boolean isUpdateMethod() { public boolean hasObjectFactoryAnnotation() { return hasObjectFactoryAnnotation; } + + @Override + public String describe() { + if ( verboseLogging ) { + return toString(); + } + else { + String mapper = declaringMapper != null ? declaringMapper.getName() + "." : ""; + String sourceTypes = getParameters().stream() + .map( Parameter::describe ) + .collect( Collectors.joining( ", " ) ); + return getResultType().describe() + " " + mapper + getName() + "(" + sourceTypes + ")"; + } + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 360eb56bac..7854534ed6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -268,4 +268,10 @@ public BuiltInConstructorFragment getConstructorFragment() { return null; } + @Override + public String describe() { + // the name of the builtin method is never fully qualified, so no need to distinguish + // between verbose or not. The type knows whether it should log verbose + return getResultType().describe() + ":" + getName() + "(" + getMappingSourceType().describe() + ")"; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 3b5cb1b036..f8f7eee5bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -59,7 +59,8 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir delegatingTypes, messager, roundContext, - notToBeImported + notToBeImported, + options.isVerbose() ); this.options = options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 25f25c3c3f..adb0b8f24f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -110,7 +110,8 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L typeUtils, typeFactory, new ArrayList<>( sourceModel ), - mapperReferences + mapperReferences, + options.isVerbose() ), mapperTypeElement, //sourceModel is passed only to fetch the after/before mapping methods in lifecycleCallbackFactory; @@ -325,7 +326,6 @@ else if ( method.isMapMapping() ) { .keySelectionParameters( keySelectionParameters ) .valueFormattingParameters( valueFormattingParameters ) .valueSelectionParameters( valueSelectionParameters ) - .nullValueMappingStrategy( nullValueMappingStrategy ) .build(); hasFactoryMethod = mapMappingMethod.getFactoryMethod() != null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index b11c157b66..672d905ee0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -44,6 +44,7 @@ import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.gem.ValueMappingGem; import org.mapstruct.ap.internal.gem.ValueMappingsGem; +import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Executables; @@ -74,6 +75,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor enumTransformationStrategies; private Types typeUtils; private Elements elementUtils; + private Options options; @Override public List process(ProcessorContext context, TypeElement mapperTypeElement, Void sourceModel) { @@ -83,6 +85,7 @@ public List process(ProcessorContext context, TypeElement mapperTy this.typeUtils = context.getTypeUtils(); this.elementUtils = context.getElementUtils(); this.enumTransformationStrategies = context.getEnumTransformationStrategies(); + this.options = context.getOptions(); this.messager.note( 0, Message.PROCESSING_NOTE, mapperTypeElement ); @@ -301,6 +304,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setTypeFactory( typeFactory ) .setPrototypeMethods( prototypeMethods ) .setContextProvidedMethods( contextProvidedMethods ) + .setVerboseLogging( options.isVerbose() ) .build(); } @@ -355,6 +359,7 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType .setExceptionTypes( exceptionTypes ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) + .setVerboseLogging( options.isVerbose() ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 8fa20f079d..fe7635f7f6 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -75,7 +75,7 @@ */ public class MappingResolverImpl implements MappingResolver { - private static final int MAX_REPORTING_AMBIGUOUS = 5; + private static final int LIMIT_REPORTING_AMBIGUOUS = 5; private final FormattingMessager messager; private final Types typeUtils; @@ -88,6 +88,8 @@ public class MappingResolverImpl implements MappingResolver { private final BuiltInMappingMethods builtInMethods; private final MethodSelectors methodSelectors; + private final boolean verboseLogging; + private static final String JL_OBJECT_NAME = Object.class.getName(); /** @@ -98,7 +100,7 @@ public class MappingResolverImpl implements MappingResolver { public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, TypeFactory typeFactory, List sourceModel, - List mapperReferences) { + List mapperReferences, boolean verboseLogging) { this.messager = messager; this.typeUtils = typeUtils; this.typeFactory = typeFactory; @@ -109,6 +111,8 @@ public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, T this.conversions = new Conversions( typeFactory ); this.builtInMethods = new BuiltInMappingMethods( typeFactory ); this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, typeFactory, messager ); + + this.verboseLogging = verboseLogging; } @Override @@ -128,7 +132,8 @@ public Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory positionHint, forger, builtInMethods.getBuiltInMethods(), - messager + messager, + verboseLogging ); return attempt.getTargetAssignment( sourceRHS.getSourceTypeForMatching(), targetType ); @@ -162,19 +167,21 @@ private class ResolvingAttempt { private final Supplier forger; private final List builtIns; private final FormattingMessager messager; + private final int reportingLimitAmbiguous; // resolving via 2 steps creates the possibility of wrong matches, first builtin method matches, // second doesn't. In that case, the first builtin method should not lead to a supported method // so this set must be cleared. private final Set supportingMethodCandidates; + // CHECKSTYLE:OFF private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedMethodHistory description, FormattingParameters formattingParameters, SourceRHS sourceRHS, SelectionCriteria criteria, AnnotationMirror positionHint, Supplier forger, List builtIns, - FormattingMessager messager) { + FormattingMessager messager, boolean verboseLogging) { this.mappingMethod = mappingMethod; this.description = description; @@ -188,7 +195,9 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM this.forger = forger; this.builtIns = builtIns; this.messager = messager; + this.reportingLimitAmbiguous = verboseLogging ? Integer.MAX_VALUE : LIMIT_REPORTING_AMBIGUOUS; } + // CHECKSTYLE:ON private List filterPossibleCandidateMethods(List candidateMethods) { List result = new ArrayList<>( candidateMethods.size() ); @@ -469,7 +478,7 @@ private void reportErrorWhenAmbiguous(List> positionHint, Message.GENERAL_AMBIGUOUS_MAPPING_METHOD, descriptionStr, - target, + target.describe(), join( candidates ) ); } @@ -478,7 +487,7 @@ private void reportErrorWhenAmbiguous(List> mappingMethod.getExecutable(), positionHint, Message.GENERAL_AMBIGUOUS_FACTORY_METHOD, - target, + target.describe(), join( candidates ) ); } @@ -595,12 +604,12 @@ private boolean hasCompatibleCopyConstructor(Type sourceType, Type targetType) { private String join( List> candidates ) { String candidateStr = candidates.stream() - .limit( MAX_REPORTING_AMBIGUOUS ) - .map( m -> m.getMethod().shortName() ) + .limit( reportingLimitAmbiguous ) + .map( m -> m.getMethod().describe() ) .collect( Collectors.joining( ", " ) ); - if ( candidates.size() > MAX_REPORTING_AMBIGUOUS ) { - candidateStr += String.format( "... and %s more", candidates.size() - MAX_REPORTING_AMBIGUOUS ); + if ( candidates.size() > reportingLimitAmbiguous ) { + candidateStr += String.format( "... and %s more", candidates.size() - reportingLimitAmbiguous ); } return candidateStr; } @@ -642,8 +651,8 @@ private void report(FormattingMessager messager, ResolvingAttempt attempt, Messa attempt.positionHint, message, attempt.sourceRHS.getSourceErrorMessagePart(), - sourceType.toString(), - targetType.toString() + sourceType.describe(), + targetType.describe() ); } @@ -798,11 +807,11 @@ void reportAmbiguousError(Map, List>> xCan StringBuilder result = new StringBuilder(); xCandidates.entrySet() .stream() - .limit( MAX_REPORTING_AMBIGUOUS ) + .limit( attempt.reportingLimitAmbiguous ) .forEach( e -> result.append( "method(s)Y: " ) .append( attempt.join( e.getValue() ) ) .append( ", methodX: " ) - .append( e.getKey().getMethod().shortName() ) + .append( e.getKey().getMethod().describe() ) .append( "; " ) ); attempt.messager.printMessage( attempt.mappingMethod.getExecutable(), @@ -912,7 +921,7 @@ void reportAmbiguousError(Map>> xRe StringBuilder result = new StringBuilder(); xRefCandidates.entrySet() .stream() - .limit( MAX_REPORTING_AMBIGUOUS ) + .limit( attempt.reportingLimitAmbiguous ) .forEach( e -> result.append( "method(s)Y: " ) .append( attempt.join( e.getValue() ) ) .append( ", conversionX: " ) @@ -1029,7 +1038,7 @@ void reportAmbiguousError(Map>> yRe StringBuilder result = new StringBuilder(); yRefCandidates.entrySet() .stream() - .limit( MAX_REPORTING_AMBIGUOUS ) + .limit( attempt.reportingLimitAmbiguous ) .forEach( e -> result.append( "conversionY: " ) .append( e.getKey().shortName() ) .append( ", method(s)X: " ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 2005127fec..67cd1aba06 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -77,8 +77,8 @@ public enum Message { CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ), CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ), - CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map \"%s %s\" to \"%s %s\"." ), - CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS( "Can't map \"%s %s\" to \"%s %s\". Reason: %s." ), + CONSTANTMAPPING_MAPPING_NOT_FOUND( "Can't map %s to \"%s %s\"." ), + CONSTANTMAPPING_MAPPING_NOT_FOUND_WITH_DETAILS( "Can't map %s to \"%s %s\". Reason: %s." ), CONSTANTMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), CONSTANTMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s for property \"%s\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 9552e881bd..7bbc80e51b 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -177,7 +177,8 @@ private Type typeWithFQN(String fullQualifiedName) { new HashMap<>( ), new HashMap<>( ), false, - false); + false, false + ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index 2b65030625..f8cceee9c0 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -125,7 +125,8 @@ private Type typeWithFQN(String fullQualifiedName) { new HashMap<>( ), new HashMap<>( ), false, - false); + false, false + ); } private static class StatefulMessagerMock implements FormattingMessager { diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 3819545090..44aeb033fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -38,9 +38,8 @@ public class ReferencedAccessibilityTest { @Diagnostic(type = SourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 22, - message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + - ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + - ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") + message = "Unmapped target property: \"bar\". Mapping from property " + + "\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessPrivateMethodInReferenced() { @@ -66,9 +65,8 @@ public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() { } @Diagnostic(type = SourceTargetMapperDefaultOther.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + - ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + - ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") + message = "Unmapped target property: \"bar\". Mapping " + + "from property \"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() { @@ -89,9 +87,8 @@ public void shouldBeAbleToAccessProtectedMethodInBase() { } @Diagnostic(type = AbstractSourceTargetMapperPrivate.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 23, - message = "Unmapped target property: \"bar\". Mapping from property \"org.mapstruct.ap" + - ".test.accessibility.referenced.ReferencedSource referencedSource\" to \"org.mapstruct" + - ".ap.test.accessibility.referenced.ReferencedTarget referencedTarget\".") + message = "Unmapped target property: \"bar\". Mapping from property " + + "\"ReferencedSource referencedSource\" to \"ReferencedTarget referencedTarget\".") } ) public void shouldNotBeAbleToAccessPrivateMethodInBase() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index 7f97d2db51..95509dc0ce 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -35,8 +35,7 @@ public class Issue1005Test { @Diagnostic(type = Issue1005ErroneousAbstractResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "The result type org.mapstruct.ap.test.bugs._1005.AbstractEntity may not be an " + - "abstract class nor interface.") + message = "The result type AbstractEntity may not be an abstract class nor interface.") }) public void shouldFailDueToAbstractResultType() { } @@ -48,9 +47,8 @@ public void shouldFailDueToAbstractResultType() { @Diagnostic(type = Issue1005ErroneousAbstractReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = - "The return type org.mapstruct.ap.test.bugs._1005.AbstractEntity is an abstract class or " + - "interface. Provide a non abstract / non interface result type or a factory method.") + message = "The return type AbstractEntity is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method.") }) public void shouldFailDueToAbstractReturnType() { } @@ -62,8 +60,7 @@ public void shouldFailDueToAbstractReturnType() { @Diagnostic(type = Issue1005ErroneousInterfaceResultTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "The result type org.mapstruct.ap.test.bugs._1005.HasPrimaryKey may not be an " + - "abstract class nor interface.") + message = "The result type HasPrimaryKey may not be an abstract class nor interface.") }) public void shouldFailDueToInterfaceResultType() { } @@ -75,9 +72,8 @@ public void shouldFailDueToInterfaceResultType() { @Diagnostic(type = Issue1005ErroneousInterfaceReturnTypeMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = - "The return type org.mapstruct.ap.test.bugs._1005.HasKey is an abstract class or interface. " + - "Provide a non abstract / non interface result type or a factory method.") + message = "The return type HasKey is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method.") }) public void shouldFailDueToInterfaceReturnType() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index afebcbef43..037ac64069 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -33,8 +33,8 @@ public class Issue1029Test { @Diagnostic(kind = Kind.WARNING, line = 37, type = ErroneousIssue1029Mapper.class, message = "Unmapped target property: \"lastUpdated\"."), @Diagnostic(kind = Kind.ERROR, line = 42, type = ErroneousIssue1029Mapper.class, - message = "Unknown property \"unknownProp\" in result type " + - "org.mapstruct.ap.test.bugs._1029.ErroneousIssue1029Mapper.Deck. Did you mean \"knownProp\"?") + message = "Unknown property \"unknownProp\" in result type ErroneousIssue1029Mapper.Deck. " + + "Did you mean \"knownProp\"?") }) public void reportsProperWarningsAndError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index bc3e59922f..015268b53e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -27,19 +27,18 @@ public class Issue1153Test { @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - message = "Property \"readOnly\" has no write accessor in " + - "org.mapstruct.ap.test.bugs._1153.ErroneousIssue1153Mapper.Target."), + message = "Property \"readOnly\" has no write accessor in ErroneousIssue1153Mapper.Target."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - message = "Property \"readOnly\" has no write accessor in org.mapstruct.ap.test.bugs._1153" + - ".ErroneousIssue1153Mapper.Target.NestedTarget for target name \"nestedTarget.readOnly\"."), + message = + "Property \"readOnly\" has no write accessor in ErroneousIssue1153Mapper.Target.NestedTarget " + + "for target name \"nestedTarget.readOnly\"."), @Diagnostic(type = ErroneousIssue1153Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, - message = "Unknown property \"writable2\" in type org.mapstruct.ap.test.bugs._1153" + - ".ErroneousIssue1153Mapper.Target.NestedTarget for target name \"nestedTarget2.writable2\". Did " + - "you mean \"nestedTarget2.writable\"?") + message = "Unknown property \"writable2\" in type ErroneousIssue1153Mapper.Target.NestedTarget " + + "for target name \"nestedTarget2.writable2\". Did you mean \"nestedTarget2.writable\"?") }) @Test public void shouldReportErrorsCorrectly() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index 80e1038127..c7e9c42f95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -58,15 +58,12 @@ public void factoryMethodWithSourceParamIsChosen() { @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.bugs._1242.TargetB: org" + - ".mapstruct.ap.test.bugs._1242.TargetB anotherTargetBCreator(org.mapstruct.ap.test.bugs._1242" + - ".SourceB source), org.mapstruct.ap.test.bugs._1242.TargetB org.mapstruct.ap.test.bugs._1242" + - ".TargetFactories.createTargetB(org.mapstruct.ap.test.bugs._1242.SourceB source, @TargetType java" + - ".lang.Class clazz), org.mapstruct.ap.test.bugs._1242" + - ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB(@TargetType java.lang" + - ".Class clazz), org.mapstruct.ap.test.bugs._1242" + - ".TargetB org.mapstruct.ap.test.bugs._1242.TargetFactories.createTargetB()." + - " See https://mapstruct.org/faq/#ambiguous for more info." ) + message = "Ambiguous factory methods found for creating TargetB: " + + "TargetB anotherTargetBCreator(SourceB source), " + + "TargetB TargetFactories.createTargetB(SourceB source, @TargetType Class clazz), " + + "TargetB TargetFactories.createTargetB(@TargetType Class clazz), " + + "TargetB TargetFactories.createTargetB(). " + + "See https://mapstruct.org/faq/#ambiguous for more info.") }) public void ambiguousMethodErrorForTwoFactoryMethodsWithSourceParam() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index b4ce1447f8..0d4fef255a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -33,7 +33,7 @@ public class Issue1283Test { @Diagnostic(type = ErroneousInverseTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22L, - message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible constructor." + message = "Source does not have an accessible constructor." ) } ) @@ -48,7 +48,7 @@ public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { @Diagnostic(type = ErroneousTargetHasNoSuitableConstructorMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 18L, - message = "org.mapstruct.ap.test.bugs._1283.Source does not have an accessible constructor." + message = "Source does not have an accessible constructor." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java index 47ab19f1dd..a7a3b58e75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java @@ -24,9 +24,8 @@ public class Issue1698Test { diagnostics = { @Diagnostic(type = Erroneous1698Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - message = "Can't map property \"java.lang.String rabbit\" to \"org.mapstruct.ap.test.bugs._1698" + - ".Erroneous1698Mapper.Rabbit rabbit\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.bugs._1698.Erroneous1698Mapper.Rabbit map(java.lang.String value)\".") + message = "Can't map property \"String rabbit\" to \"Erroneous1698Mapper.Rabbit rabbit\". " + + "Consider to declare/implement a mapping method: \"Erroneous1698Mapper.Rabbit map(String value)\".") }) public void testErrorMessage() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java index e716d70a34..60c3910c0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java @@ -27,9 +27,8 @@ public class Issue590Test { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - message = "Can't map property \"java.lang.String prop\" to \"java.util.logging.XMLFormatter " + - "prop\". Consider to declare/implement a mapping method: \"java.util.logging.XMLFormatter map" + - "(java.lang.String value)\".") + message = "Can't map property \"String prop\" to \"XMLFormatter prop\". " + + "Consider to declare/implement a mapping method: \"XMLFormatter map(String value)\".") }) public void showsCantMapPropertyError() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index 0aaf28d318..9e7293919d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -54,9 +54,8 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollection( @Diagnostic(type = ErroneousCollectionToPrimitivePropertyMapper.class, kind = Kind.ERROR, line = 13, - message = "Can't map property \"java.util.List strings\" to \"int strings\". " - + "Consider to declare/implement a mapping method: \"int map(java.util.List" - + " value)\".") + message = "Can't map property \"List strings\" to \"int strings\". " + + "Consider to declare/implement a mapping method: \"int map(List value)\".") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @@ -104,10 +103,9 @@ public void shouldFailOnEmptyMapAnnotation() { @Diagnostic(type = ErroneousCollectionNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - message = "No target bean properties found: can't map Collection element \"org.mapstruct.ap.test" + - ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + - "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + - ".mapstruct.ap.test.WithProperties value)\".") + message = "No target bean properties found: can't map Collection element " + + "\"WithProperties withProperties\" to \"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFound() { @@ -122,9 +120,8 @@ public void shouldFailOnNoElementMappingFound() { @Diagnostic(type = ErroneousCollectionNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - message = "Can't map collection element \"java.text.AttributedString\" to \"java.lang.String \". " + - "Consider to declare/implement a mapping method: \"java.lang.String map(java.text" + - ".AttributedString value)\".") + message = "Can't map collection element \"AttributedString\" to \"String \". " + + "Consider to declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @@ -139,10 +136,9 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFound.class, kind = Kind.ERROR, line = 25, - message = "No target bean properties found: can't map Map key \"org.mapstruct.ap.test.WithProperties " + - "withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". Consider to " + - "declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org.mapstruct.ap" + - ".test.WithProperties value)\".") + message = "No target bean properties found: can't map Map key \"WithProperties withProperties\" to " + + "\"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoKeyMappingFound() { @@ -157,8 +153,8 @@ public void shouldFailOnNoKeyMappingFound() { @Diagnostic(type = ErroneousCollectionNoKeyMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - message = "Can't map map key \"java.text.AttributedString\" to \"java.lang.String \". Consider to " + - "declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)\".") + message = "Can't map map key \"AttributedString\" to \"String \". Consider to " + + "declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @@ -173,10 +169,9 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { @Diagnostic(type = ErroneousCollectionNoValueMappingFound.class, kind = Kind.ERROR, line = 25, - message = "No target bean properties found: can't map Map value \"org.mapstruct.ap.test" + - ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + - "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + - ".mapstruct.ap.test.WithProperties value)\".") + message = "No target bean properties found: can't map Map value \"WithProperties withProperties\" " + + "to \"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoValueMappingFound() { @@ -191,8 +186,8 @@ public void shouldFailOnNoValueMappingFound() { @Diagnostic(type = ErroneousCollectionNoValueMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - message = "Can't map map value \"java.text.AttributedString\" to \"java.lang.String \". Consider to " + - "declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)\".") + message = "Can't map map value \"AttributedString\" to \"String \". " + + "Consider to declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoValueMappingFoundWithDisabledAuto() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 50c2ffcb96..9fe6fec56a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -88,10 +88,9 @@ public void shouldForgeNewMapMappingMethod() { @Diagnostic(type = ErroneousCollectionNonMappableSetMapper.class, kind = Kind.ERROR, line = 17, - message = "No target bean properties found: can't map Collection element \"org.mapstruct.ap" + - ".test.collection.forged.Foo nonMappableSet\" to \"org.mapstruct.ap.test.collection.forged.Bar " + - "nonMappableSet\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + - ".collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), + message = "No target bean properties found: " + + "can't map Collection element \"Foo nonMappableSet\" to \"Bar nonMappableSet\". " + + "Consider to declare/implement a mapping method: \"Bar map(Foo value)\"."), } ) public void shouldGenerateNonMappleMethodForSetMapping() { @@ -110,17 +109,15 @@ public void shouldGenerateNonMappleMethodForSetMapping() { @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - message = "No target bean properties found: can't map Map key \"org.mapstruct.ap.test" + - ".collection.forged.Foo nonMappableMap{:key}\" to \"org.mapstruct.ap.test.collection.forged.Bar " + - "nonMappableMap{:key}\". Consider to declare/implement a mapping method: \"org.mapstruct.ap" + - ".test.collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), + message = "No target bean properties found: " + + "can't map Map key \"Foo nonMappableMap{:key}\" to \"Bar nonMappableMap{:key}\". " + + "Consider to declare/implement a mapping method: \"Bar map(Foo value)\"."), @Diagnostic(type = ErroneousCollectionNonMappableMapMapper.class, kind = Kind.ERROR, line = 17, - message = "No target bean properties found: can't map Map value \"org.mapstruct.ap.test" + - ".collection.forged.Foo nonMappableMap{:value}\" to \"org.mapstruct.ap.test.collection.forged.Bar" + - " nonMappableMap{:value}\". Consider to declare/implement a mapping method: \"org.mapstruct.ap" + - ".test.collection.forged.Bar map(org.mapstruct.ap.test.collection.forged.Foo value)\"."), + message = "No target bean properties found: " + + "can't map Map value \"Foo nonMappableMap{:value}\" to \"Bar nonMappableMap{:value}\". " + + "Consider to declare/implement a mapping method: \"Bar map(Foo value)\"."), } ) public void shouldGenerateNonMappleMethodForMapMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index ae61da8e19..1e5d275f43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -71,8 +71,8 @@ public void testConversionFromLongToInt() { @Diagnostic(type = KitchenDrawerMapper2.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 24, - message = "property \"java.math.BigInteger numberOfKnifes\" has a possibly lossy conversion " - + "from java.math.BigInteger to java.lang.Integer.") + message = "property \"BigInteger numberOfKnifes\" has a possibly lossy conversion " + + "from BigInteger to Integer.") }) public void testConversionFromBigIntegerToInteger() { } @@ -84,8 +84,8 @@ public void testConversionFromBigIntegerToInteger() { @Diagnostic(type = ErroneousKitchenDrawerMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - message = "Can't map property \"org.mapstruct.ap.test.conversion.lossy.VerySpecialNumber " + - "numberOfSpoons\". It has a possibly lossy conversion from java.math.BigInteger to java.lang.Long.") + message = "Can't map property \"VerySpecialNumber numberOfSpoons\". " + + "It has a possibly lossy conversion from BigInteger to Long.") }) public void test2StepConversionFromBigIntegerToLong() { } @@ -97,8 +97,8 @@ public void test2StepConversionFromBigIntegerToLong() { @Diagnostic(type = ErroneousKitchenDrawerMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - message = "Can't map property \"java.lang.Double depth\". It has a possibly lossy conversion " - + "from java.lang.Double to float.") + message = + "Can't map property \"Double depth\". It has a possibly lossy conversion from Double to float.") }) public void testConversionFromDoubleToFloat() { } @@ -110,8 +110,8 @@ public void testConversionFromDoubleToFloat() { @Diagnostic(type = ErroneousKitchenDrawerMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 24, - message = "Can't map property \"java.math.BigDecimal length\". It has a possibly lossy conversion from " - + "java.math.BigDecimal to java.lang.Float.") + message = + "Can't map property \"BigDecimal length\". It has a possibly lossy conversion from BigDecimal to Float.") }) public void testConversionFromBigDecimalToFloat() { } @@ -135,8 +135,7 @@ public void test2StepConversionFromDoubleToFloat() { @Diagnostic(type = ListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 21, - message = "collection element has a possibly lossy conversion from java.math.BigDecimal to " - + "java.math.BigInteger.") + message = "collection element has a possibly lossy conversion from BigDecimal to BigInteger.") }) public void testListElementConversion() { } @@ -148,11 +147,11 @@ public void testListElementConversion() { @Diagnostic(type = MapMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 19, - message = "map key has a possibly lossy conversion from java.lang.Long to java.lang.Integer."), + message = "map key has a possibly lossy conversion from Long to Integer."), @Diagnostic(type = MapMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 19, - message = "map value has a possibly lossy conversion from java.lang.Double to java.lang.Float.") + message = "map value has a possibly lossy conversion from Double to Float.") }) public void testMapElementConversion() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index f2054b90b9..ff7bf00722 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -129,9 +129,8 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { @Diagnostic(type = ErroneousMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - message = "Can't map property \"org.mapstruct.ap.test.defaultvalue.Region region\" to \"java.lang" + - ".String region\". Consider to declare/implement a mapping method: \"java.lang.String map(org" + - ".mapstruct.ap.test.defaultvalue.Region value)\".") + message = "Can't map property \"Region region\" to \"String region\". " + + "Consider to declare/implement a mapping method: \"String map(Region value)\".") } ) public void errorOnDefaultValueAndConstant() { @@ -153,9 +152,8 @@ public void errorOnDefaultValueAndConstant() { @Diagnostic(type = ErroneousMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, - message = "Can't map property \"org.mapstruct.ap.test.defaultvalue.Region region\" to \"java.lang" + - ".String region\". Consider to declare/implement a mapping method: \"java.lang.String map(org" + - ".mapstruct.ap.test.defaultvalue.Region value)\".") + message = "Can't map property \"Region region\" to \"String region\". " + + "Consider to declare/implement a mapping method: \"String map(Region value)\".") } ) public void errorOnDefaultValueAndExpression() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 24cdbe3a53..3887cd4a46 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -30,13 +30,9 @@ public class AmbiguousAnnotatedFactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Bar: org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Bar createBar(org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Foo foo), org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Bar org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.AmbiguousBarFactory.createBar(org.mapstruct.ap.test.erroneous" + - ".ambiguousannotatedfactorymethod.Foo foo)." + + message = "Ambiguous factory methods found for creating Bar: " + + "Bar createBar(Foo foo), " + + "Bar AmbiguousBarFactory.createBar(Foo foo)." + " See https://mapstruct.org/faq/#ambiguous for more info.") } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index 682c46d036..dbce2ab5b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -34,10 +34,9 @@ public class FactoryTest { @Diagnostic(type = SourceTargetMapperAndBarFactory.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.erroneous" + - ".ambiguousfactorymethod.Bar: org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar " + - "createBar(), org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.Bar org.mapstruct.ap.test" + - ".erroneous.ambiguousfactorymethod.a.BarFactory.createBar()." + + message = "Ambiguous factory methods found for creating Bar: " + + "Bar createBar(), " + + "Bar BarFactory.createBar()." + " See https://mapstruct.org/faq/#ambiguous for more info.") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java index a04373b13f..c13f1edd2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java @@ -12,6 +12,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("2156") @@ -26,16 +27,14 @@ public class AmbigiousMapperTest { @Diagnostic(type = ErroneousWithAmbiguousMethodsMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Ambiguous mapping methods found for mapping property " - + "\"org.mapstruct.ap.test.erroneous.ambiguousmapping." - + "ErroneousWithAmbiguousMethodsMapper.LeafDTO branch.leaf\" to " - + "org.mapstruct.ap.test.erroneous.ambiguousmapping." - + "ErroneousWithAmbiguousMethodsMapper.LeafEntity: " - + "LeafEntity:map1(LeafDTO), LeafEntity:map2(LeafDTO). " - + "See https://mapstruct.org/faq/#ambiguous for more info.") + message = + "Ambiguous mapping methods found for mapping property " + + "\"ErroneousWithAmbiguousMethodsMapper.LeafDTO branch.leaf\" to ErroneousWithAmbiguousMethodsMapper.LeafEntity: " + + "ErroneousWithAmbiguousMethodsMapper.LeafEntity map1(ErroneousWithAmbiguousMethodsMapper.LeafDTO dto), " + + "ErroneousWithAmbiguousMethodsMapper.LeafEntity map2(ErroneousWithAmbiguousMethodsMapper.LeafDTO dto). " + + "See https://mapstruct.org/faq/#ambiguous for more info." ) } ) - public void testErrorMessageForAmbiguous() { } @@ -47,21 +46,48 @@ public void testErrorMessageForAmbiguous() { @Diagnostic(type = ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Ambiguous mapping methods found for mapping property " - + "\"org.mapstruct.ap.test.erroneous.ambiguousmapping." - + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO branch.leaf\" to " - + "org.mapstruct.ap.test.erroneous.ambiguousmapping." - + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity: " - + "LeafEntity:map1(LeafDTO), " - + "LeafEntity:map2(LeafDTO), " - + "LeafEntity:map3(LeafDTO), " - + "LeafEntity:map4(LeafDTO), " - + "LeafEntity:map5(LeafDTO)" - + "... and 1 more. " - + "See https://mapstruct.org/faq/#ambiguous for more info.") + message = + // CHECKSTYLE:OFF + "Ambiguous mapping methods found for mapping property \"ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO branch.leaf\" to " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity: " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map1(ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map2(ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map3(ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map4(ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map5(ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto)" + + "... and 1 more. See https://mapstruct.org/faq/#ambiguous for more info." + // CHECKSTYLE:ON + ) } ) public void testErrorMessageForManyAmbiguous() { } + @Test + @ProcessorOption(name = "mapstruct.verbose", value = "true") + @WithClasses( ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = + // CHECKSTYLE:OFF + "Ambiguous mapping methods found for mapping property \"org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO branch.leaf\" " + + "to org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity: " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map1(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map2(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map3(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map4(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map5(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto), " + + "org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafEntity map6(org.mapstruct.ap.test.erroneous.ambiguousmapping.ErroneousWithMoreThanFiveAmbiguousMethodsMapper.LeafDTO dto). " + + "See https://mapstruct.org/faq/#ambiguous for more info." + // CHECKSTYLE:ON + ) + } + ) + public void testErrorMessageForManyAmbiguousVerbose() { + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index f95614132c..bc36e2af42 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -43,8 +43,7 @@ public class ErroneousMappingsTest { @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 18, - message = "Unknown property \"bar\" in result type " + - "org.mapstruct.ap.test.erroneous.attributereference.Target. Did you mean \"foo\"?"), + message = "Unknown property \"bar\" in result type Target. Did you mean \"foo\"?"), @Diagnostic(type = ErroneousMapper.class, kind = Kind.ERROR, line = 23, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java index db97dc133a..627478d1c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java @@ -27,9 +27,8 @@ public class ErroneousPropertyMappingTest { diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + - "source\" to \"java.lang.String property\". Consider to declare/implement a mapping method: " + - "\"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass value)\".") + message = "Can't map property \"UnmappableClass source\" to \"String property\". " + + "Consider to declare/implement a mapping method: \"String map(UnmappableClass value)\".") } ) public void testUnmappableSourceProperty() { @@ -42,10 +41,8 @@ public void testUnmappableSourceProperty() { diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + - "nameBasedSource\" to \"java.lang.String nameBasedSource\". Consider to declare/implement a " + - "mapping method: \"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping" + - ".UnmappableClass value)\".") + message = "Can't map property \"UnmappableClass nameBasedSource\" to \"String nameBasedSource\"." + + " Consider to declare/implement a mapping method: \"String map(UnmappableClass value)\".") } ) public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { @@ -58,8 +55,7 @@ public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map \"java.lang.String \"constant\"\" to \"org.mapstruct.ap.test.erroneous" + - ".propertymapping.UnmappableClass constant\".") + message = "Can't map \"constant\" to \"UnmappableClass constant\".") } ) public void testUnmappableConstantAssignment() { @@ -72,9 +68,8 @@ public void testUnmappableConstantAssignment() { diagnostics = { @Diagnostic(kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass " + - "source\" to \"java.lang.String property\". Consider to declare/implement a mapping method: " + - "\"java.lang.String map(org.mapstruct.ap.test.erroneous.propertymapping.UnmappableClass value)\".") + message = "Can't map property \"UnmappableClass source\" to \"String property\". " + + "Consider to declare/implement a mapping method: \"String map(UnmappableClass value)\".") } ) public void testUnmappableParameterAssignment() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index e1549ef4a8..417a0aa26a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -82,8 +82,7 @@ public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore( @Diagnostic(type = ErroneousTargetHasNoWriteAccessorMapper.class, kind = Kind.ERROR, line = 22, - message = "Property \"hasClaws\" has no write accessor in " + - "org.mapstruct.ap.test.ignore.PreditorDto.") + message = "Property \"hasClaws\" has no write accessor in PreditorDto.") } ) public void shouldGiveErrorOnMappingForReadOnlyProp() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java index e290aed450..f00319dcf7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java @@ -44,8 +44,8 @@ public void shouldMapAttributeFromSuperType() { type = ErroneousTargetSourceMapper.class, kind = Kind.ERROR, line = 16, - message = "Can't map property \"java.lang.CharSequence foo\" to \"java.lang.String foo\". Consider to " + - "declare/implement a mapping method: \"java.lang.String map(java.lang.CharSequence value)\"." + message = "Can't map property \"CharSequence foo\" to \"String foo\". " + + "Consider to declare/implement a mapping method: \"String map(CharSequence value)\"." )) public void shouldReportErrorDueToUnmappableAttribute() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index 7c2459b118..d67734423e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -69,11 +69,10 @@ public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { kind = Kind.ERROR, type = ErroneousSourceCompositeTargetCompositeMapper.class, line = 19, - message = "Ambiguous mapping methods found for mapping property " - + "\"org.mapstruct.ap.test.inheritance.complex.SourceExt prop1\" " - + "to org.mapstruct.ap.test.inheritance.complex.Reference: " - + "Reference:asReference(SourceBase), Reference:asReference(AdditionalFooSource). " - + "See https://mapstruct.org/faq/#ambiguous for more info.") + message = "Ambiguous mapping methods found for mapping property \"SourceExt prop1\" to Reference: " + + "Reference AdditionalMappingHelper.asReference(SourceBase source), " + + "Reference AdditionalMappingHelper.asReference(AdditionalFooSource source). " + + "See https://mapstruct.org/faq/#ambiguous for more info.") ) public void ambiguousMappingMethodsReportError() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index 4cc6ce3e66..e82ed945a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -60,12 +60,8 @@ public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterabl @Diagnostic(type = ErroneousStreamToPrimitivePropertyMapper.class, kind = Kind.ERROR, line = 13, - message = - "Can't map property \"java.util.stream.Stream strings\" to \"int strings\". " - + - "Consider to declare/implement a mapping method: \"int map(java.util.stream.Stream" - + " value)\".") + message = "Can't map property \"Stream strings\" to \"int strings\". " + + "Consider to declare/implement a mapping method: \"int map(Stream value)\".") } ) public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { @@ -104,10 +100,9 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 24, - message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + - ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + - "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + - ".mapstruct.ap.test.WithProperties value)\".") + message = "No target bean properties found: " + + "can't map Stream element \"WithProperties withProperties\" to \"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToStream() { @@ -122,9 +117,8 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { @Diagnostic(type = ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 19, - message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + - " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + - "\".") + message = "Can't map stream element \"AttributedString\" to \"String \". " + + "Consider to declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() { @@ -138,10 +132,9 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() @Diagnostic(type = ErroneousListToStreamNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + - ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + - "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + - ".mapstruct.ap.test.WithProperties value)\".") + message = "No target bean properties found: " + + "can't map Stream element \"WithProperties withProperties\" to \"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForListToStream() { @@ -156,9 +149,8 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { @Diagnostic(type = ErroneousListToStreamNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 20, - message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + - " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + - "\".") + message = "Can't map stream element \"AttributedString\" to \"String \". " + + "Consider to declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @@ -172,10 +164,9 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFound.class, kind = Kind.ERROR, line = 25, - message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + - ".WithProperties withProperties\" to \"org.mapstruct.ap.test.NoProperties noProperties\". " + - "Consider to declare/implement a mapping method: \"org.mapstruct.ap.test.NoProperties map(org" + - ".mapstruct.ap.test.WithProperties value)\".") + message = "No target bean properties found: " + + "can't map Stream element \"WithProperties withProperties\" to \"NoProperties noProperties\". " + + "Consider to declare/implement a mapping method: \"NoProperties map(WithProperties value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToList() { @@ -190,9 +181,8 @@ public void shouldFailOnNoElementMappingFoundForStreamToList() { @Diagnostic(type = ErroneousStreamToListNoElementMappingFoundDisabledAuto.class, kind = Kind.ERROR, line = 20, - message = "Can't map stream element \"java.text.AttributedString\" to \"java.lang.String \". Consider" + - " to declare/implement a mapping method: \"java.lang.String map(java.text.AttributedString value)" + - "\".") + message = "Can't map stream element \"AttributedString\" to \"String \". " + + "Consider to declare/implement a mapping method: \"String map(AttributedString value)\".") } ) public void shouldFailOnNoElementMappingFoundForStreamToListWithDisabledAuto() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index a996974cb7..bcd35e5b5e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -70,10 +70,9 @@ public void shouldForgeNewIterableMappingMethod() { @Diagnostic(type = ErroneousStreamNonMappableStreamMapper.class, kind = Kind.ERROR, line = 17, - message = "No target bean properties found: can't map Stream element \"org.mapstruct.ap.test" + - ".java8stream.forged.Foo nonMappableStream\" to \"org.mapstruct.ap.test.java8stream.forged.Bar " + - "nonMappableStream\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + - ".java8stream.forged.Bar map(org.mapstruct.ap.test.java8stream.forged.Foo value)\".") + message = "No target bean properties found: " + + "can't map Stream element \"Foo nonMappableStream\" to \"Bar nonMappableStream\". " + + "Consider to declare/implement a mapping method: \"Bar map(Foo value)\".") } ) public void shouldGenerateNonMappableMethodForSetMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index 5807931ce1..5324f3f2cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -128,10 +128,8 @@ public void testDeepCloningListsAndMaps() { @Diagnostic(type = ErroneousDirectMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"org" + - ".mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\". Consider to declare/implement a mapping " + - "method: \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO map(org.mapstruct.ap.test" + - ".mappingcontrol.ShelveDTO value)\"." + message = "Can't map property \"ShelveDTO shelve\" to \"ShelveDTO shelve\". " + + "Consider to declare/implement a mapping method: \"ShelveDTO map(ShelveDTO value)\"." ) }) public void directSelectionNotAllowed() { @@ -157,9 +155,8 @@ public void methodSelectionAllowed() { @Diagnostic(type = ErroneousMethodMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + - "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + - ".mappingcontrol.ShelveDTO value)\"." + message = "Can't map property \"ShelveDTO shelve\" to \"int beerCount\". " + + "Consider to declare/implement a mapping method: \"int map(ShelveDTO value)\"." ) }) public void methodSelectionNotAllowed() { @@ -184,8 +181,8 @@ public void conversionSelectionAllowed() { @Diagnostic(type = ErroneousConversionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"java.lang.String beerCount\" to \"int beerCount\". Consider to " + - "declare/implement a mapping method: \"int map(java.lang.String value)\"." + message = "Can't map property \"String beerCount\" to \"int beerCount\". " + + "Consider to declare/implement a mapping method: \"int map(String value)\"." ) }) public void conversionSelectionNotAllowed() { @@ -210,9 +207,8 @@ public void complexSelectionAllowed() { @Diagnostic(type = ErroneousComplexMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + - "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + - ".mappingcontrol.ShelveDTO value)\"." + message = "Can't map property \"ShelveDTO shelve\" to \"int beerCount\". " + + "Consider to declare/implement a mapping method: \"int map(ShelveDTO value)\"." ) }) public void complexSelectionNotAllowed() { @@ -225,9 +221,8 @@ public void complexSelectionNotAllowed() { @Diagnostic(type = ErroneousComplexMapperWithConfig.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Can't map property \"org.mapstruct.ap.test.mappingcontrol.ShelveDTO shelve\" to \"int " + - "beerCount\". Consider to declare/implement a mapping method: \"int map(org.mapstruct.ap.test" + - ".mappingcontrol.ShelveDTO value)\"." + message = "Can't map property \"ShelveDTO shelve\" to \"int beerCount\". " + + "Consider to declare/implement a mapping method: \"int map(ShelveDTO value)\"." ) }) public void complexSelectionNotAllowedWithConfig() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index 94b2fa16a4..f9ad0b435b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -49,8 +49,7 @@ public void testAgeSuggestion() { @Diagnostic(type = PersonNameMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - message = "Unknown property \"fulName\" in result type org.mapstruct.ap.test.namesuggestion.Person. " + - "Did you mean \"fullName\"?") + message = "Unknown property \"fulName\" in result type Person. Did you mean \"fullName\"?") } ) public void testNameSuggestion() { @@ -66,8 +65,8 @@ public void testNameSuggestion() { @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, - message = "Unknown property \"colour\" in type org.mapstruct.ap.test.namesuggestion.Garage for target" + - " name \"garage.colour.rgb\". Did you mean \"garage.color\"?"), + message = "Unknown property \"colour\" in type Garage for target name \"garage.colour.rgb\". " + + "Did you mean \"garage.color\"?"), @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 20, @@ -75,8 +74,8 @@ public void testNameSuggestion() { @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 22, - message = "Unknown property \"colour\" in type org.mapstruct.ap.test.namesuggestion.Garage for" + - " target name \"garage.colour\". Did you mean \"garage.color\"?"), + message = "Unknown property \"colour\" in type Garage for target name \"garage.colour\". " + + "Did you mean \"garage.color\"?"), @Diagnostic(type = PersonGarageWrongTargetMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 23, diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index 434ad225a6..bc9bded0cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -33,9 +33,8 @@ public class DisablingNestedSimpleBeansMappingTest { @Diagnostic(type = ErroneousDisabledHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.Roof roof\" to \"org.mapstruct.ap" + - ".test.nestedbeans.RoofDto roof\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.nestedbeans.RoofDto map(org.mapstruct.ap.test.nestedbeans.Roof value)\"." + message = "Can't map property \"Roof roof\" to \"RoofDto roof\". " + + "Consider to declare/implement a mapping method: \"RoofDto map(Roof value)\"." ) }) @Test @@ -51,9 +50,8 @@ public void shouldUseDisabledMethodGenerationOnMapper() { @Diagnostic(type = ErroneousDisabledViaConfigHouseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.Roof roof\" to \"org.mapstruct.ap" + - ".test.nestedbeans.RoofDto roof\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.nestedbeans.RoofDto map(org.mapstruct.ap.test.nestedbeans.Roof value)\"." + message = "Can't map property \"Roof roof\" to \"RoofDto roof\". " + + "Consider to declare/implement a mapping method: \"RoofDto map(Roof value)\"." ) }) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index b1f58967ff..3117f17fc9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -100,8 +100,7 @@ public class DottedErrorMessageTest { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Color house.roof.color\" to \"org.mapstruct.ap" + - ".test.nestedbeans.unmappable.ColorDto house.roof.color\".") + " \"Color house.roof.color\" to \"ColorDto house.roof.color\".") } ) public void testDeepNestedBeans() { @@ -118,8 +117,7 @@ public void testDeepNestedBeans() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Wheel car.wheels\" to \"org.mapstruct.ap.test" + - ".nestedbeans.unmappable.WheelDto car.wheels\".") + " \"Wheel car.wheels\" to \"WheelDto car.wheels\".") } ) public void testIterables() { @@ -136,8 +134,7 @@ public void testIterables() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Word dictionary.wordMap{:key}\" to \"org" + - ".mapstruct.ap.test.nestedbeans.unmappable.WordDto dictionary.wordMap{:key}\".") + " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\".") } ) public void testMapKeys() { @@ -154,8 +151,7 @@ public void testMapKeys() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWord dictionary.wordMap{:value}\" " + - "to \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWordDto dictionary.wordMap{:value}\".") + " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\".") } ) public void testMapValues() { @@ -172,8 +168,7 @@ public void testMapValues() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info computers[].info\" to \"org.mapstruct.ap" + - ".test.nestedbeans.unmappable.InfoDto computers[].info\".") + " \"Info computers[].info\" to \"InfoDto computers[].info\".") } ) public void testCollectionElementProperty() { @@ -190,8 +185,7 @@ public void testCollectionElementProperty() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 10, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info catNameMap{:value}.info\" to \"org" + - ".mapstruct.ap.test.nestedbeans.unmappable.InfoDto catNameMap{:value}.info\".") + " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\".") } ) public void testMapValueProperty() { @@ -208,10 +202,8 @@ public void testMapValueProperty() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 25, message = - "The following constants from the property \"org.mapstruct.ap.test.nestedbeans.unmappable" + - ".RoofType house.roof.type\" enum " + - "have no corresponding constant in the \"org.mapstruct.ap.test.nestedbeans.unmappable" + - ".ExternalRoofType house.roof.type\" enum and must " + + "The following constants from the property \"RoofType house.roof.type\" enum " + + "have no corresponding constant in the \"ExternalRoofType house.roof.type\" enum and must " + "be be mapped via adding additional mappings: NORMAL." ) } @@ -235,38 +227,32 @@ public void testMapEnumProperty() { kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Color house.roof.color\" to \"org.mapstruct.ap" + - ".test.nestedbeans.unmappable.ColorDto house.roof.color\"."), + " \"Color house.roof.color\" to \"ColorDto house.roof.color\"."), @Diagnostic(type = BaseDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Wheel car.wheels\" to \"org.mapstruct.ap.test" + - ".nestedbeans.unmappable.WheelDto car.wheels\"."), + " \"Wheel car.wheels\" to \"WheelDto car.wheels\"."), @Diagnostic(type = BaseDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Word dictionary.wordMap{:key}\" to \"org" + - ".mapstruct.ap.test.nestedbeans.unmappable.WordDto dictionary.wordMap{:key}\"."), + " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\"."), @Diagnostic(type = BaseDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWord dictionary.wordMap{:value}\" " + - "to \"org.mapstruct.ap.test.nestedbeans.unmappable.ForeignWordDto dictionary.wordMap{:value}\"."), + " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\"."), @Diagnostic(type = BaseCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info computers[].info\" to \"org.mapstruct.ap" + - ".test.nestedbeans.unmappable.InfoDto computers[].info\"."), + " \"Info computers[].info\" to \"InfoDto computers[].info\"."), @Diagnostic(type = BaseValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 10, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"org.mapstruct.ap.test.nestedbeans.unmappable.Info catNameMap{:value}.info\" to \"org" + - ".mapstruct.ap.test.nestedbeans.unmappable.InfoDto catNameMap{:value}.info\".") + " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\".") } ) public void testWarnUnmappedTargetProperties() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index 267dfb438c..19abea74b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -31,31 +31,25 @@ public class ErroneousJavaInternalTest { @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType date\" to " + - "\"java.util.Date date\". Consider to declare/implement a mapping method: \"java.util.Date map" + - "(org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType value)\"."), + message = "Can't map property \"Source.MyType date\" to \"Date date\". " + + "Consider to declare/implement a mapping method: \"Date map(Source.MyType value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType calendar\"" + - " to \"java.util.GregorianCalendar calendar\". Consider to declare/implement a mapping method: " + - "\"java.util.GregorianCalendar map(org.mapstruct.ap.test.nestedbeans.exclusions.Source.MyType " + - "value)\"."), + message = "Can't map property \"Source.MyType calendar\" to \"GregorianCalendar calendar\". " + + "Consider to declare/implement a mapping method: \"GregorianCalendar map(Source.MyType value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"java.util.List types\" to \"java.util.List types\". Consider to declare/implement a " + - "mapping method: \"java.util.List map(java.util.List value)\"."), + message = "Can't map property \"List types\" to \"List types\". " + + "Consider to declare/implement a mapping method: \"List map(List value)\"."), @Diagnostic(type = ErroneousJavaInternalMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "Can't map property \"java.util.List nestedMyType.deepNestedType.types\" to \"java.util.List nestedMyType" + - ".deepNestedType.types\". Consider to declare/implement a mapping method: \"java.util.List map(java.util.List " + - "value)\".") + message = "Can't map property \"List nestedMyType.deepNestedType.types\" to " + + "\"List nestedMyType.deepNestedType.types\". " + + "Consider to declare/implement a mapping method: " + + "\"List map(List value)\".") }) @Test public void shouldNotNestIntoJavaPackageObjects() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java index 1eccfdb4d7..45cc9a2343 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -33,11 +33,8 @@ public class ErroneousCustomExclusionTest { @Diagnostic(type = ErroneousCustomExclusionMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, - message = "Can't map property \"org.mapstruct.ap.test.nestedbeans.exclusions.custom.Source" + - ".NestedSource nested\" to \"org.mapstruct.ap.test.nestedbeans.exclusions.custom.Target" + - ".NestedTarget nested\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + - ".nestedbeans.exclusions.custom.Target.NestedTarget map(org.mapstruct.ap.test.nestedbeans" + - ".exclusions.custom.Source.NestedSource value)\".") + message = "Can't map property \"Source.NestedSource nested\" to \"Target.NestedTarget nested\". " + + "Consider to declare/implement a mapping method: \"Target.NestedTarget map(Source.NestedSource value)\".") } ) @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index f9d5b11eed..07d0a38611 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -171,8 +171,7 @@ public void shouldUseGetAsTargetAccessor() { @Diagnostic(type = ArtistToChartEntryErroneous.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 34, - message = "org.mapstruct.ap.test.nestedsourceproperties.ArtistToChartEntryErroneous.ChartPosition " + - "does not have an accessible constructor.") + message = "ArtistToChartEntryErroneous.ChartPosition does not have an accessible constructor.") } ) @WithClasses({ ArtistToChartEntryErroneous.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index b508787cc7..9d17f1725b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -85,12 +85,9 @@ public void shouldApplyGenericTypeMapper() { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + - ".generics.UpperBoundWrapper " + - "fooUpperBoundFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + - "fooUpperBoundFailure\". Consider to declare/implement a mapping method: \"org.mapstruct.ap.test" + - ".selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics.UpperBoundWrapper value)\".") + message = "No target bean properties found: can't map property " + + "\"UpperBoundWrapper fooUpperBoundFailure\" to \"TypeA fooUpperBoundFailure\". " + + "Consider to declare/implement a mapping method: \"TypeA map(UpperBoundWrapper value)\".") }) public void shouldFailOnUpperBound() { } @@ -102,12 +99,11 @@ public void shouldFailOnUpperBound() { @Diagnostic(type = ErroneousSourceTargetMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + - ".generics.WildCardExtendsWrapper " + - "fooWildCardExtendsTypeAFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + - "fooWildCardExtendsTypeAFailure\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics" + - ".WildCardExtendsWrapper value)\".") + message = "No target bean properties found: can't map property " + + "\"WildCardExtendsWrapper fooWildCardExtendsTypeAFailure\" to " + + "\"TypeA fooWildCardExtendsTypeAFailure\". " + + "Consider to declare/implement a mapping method: " + + "\"TypeA map(WildCardExtendsWrapper value)\".") }) public void shouldFailOnWildCardBound() { } @@ -119,12 +115,11 @@ public void shouldFailOnWildCardBound() { @Diagnostic(type = ErroneousSourceTargetMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + - ".generics.WildCardExtendsMBWrapper " + - "fooWildCardExtendsMBTypeBFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeB " + - "fooWildCardExtendsMBTypeBFailure\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.selection.generics.TypeB map(org.mapstruct.ap.test.selection.generics" + - ".WildCardExtendsMBWrapper value)\".") + message = "No target bean properties found: can't map property " + + "\"WildCardExtendsMBWrapper fooWildCardExtendsMBTypeBFailure\" to " + + "\"TypeB fooWildCardExtendsMBTypeBFailure\". " + + "Consider to declare/implement a mapping method: " + + "\"TypeB map(WildCardExtendsMBWrapper value)\".") }) public void shouldFailOnWildCardMultipleBounds() { } @@ -136,12 +131,11 @@ public void shouldFailOnWildCardMultipleBounds() { @Diagnostic(type = ErroneousSourceTargetMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + - ".generics.WildCardSuperWrapper " + - "fooWildCardSuperTypeAFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeA " + - "fooWildCardSuperTypeAFailure\". Consider to declare/implement a mapping method: \"org.mapstruct" + - ".ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.selection.generics" + - ".WildCardSuperWrapper value)\".") + message = "No target bean properties found: can't map property " + + "\"WildCardSuperWrapper fooWildCardSuperTypeAFailure\" to " + + "\"TypeA fooWildCardSuperTypeAFailure\". " + + "Consider to declare/implement a mapping method: " + + "\"TypeA map(WildCardSuperWrapper value)\".") }) public void shouldFailOnSuperBounds1() { } @@ -153,12 +147,9 @@ public void shouldFailOnSuperBounds1() { @Diagnostic(type = ErroneousSourceTargetMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 16, - message = "No target bean properties found: can't map property \"org.mapstruct.ap.test.selection" + - ".generics.WildCardSuperWrapper " + - "fooWildCardSuperTypeCFailure\" to \"org.mapstruct.ap.test.selection.generics.TypeC " + - "fooWildCardSuperTypeCFailure\". Consider to declare/implement a mapping method: \"org.mapstruct" + - ".ap.test.selection.generics.TypeC map(org.mapstruct.ap.test.selection.generics" + - ".WildCardSuperWrapper value)\".") + message = "No target bean properties found: can't map property \"WildCardSuperWrapper " + + "fooWildCardSuperTypeCFailure\" to \"TypeC fooWildCardSuperTypeCFailure\". " + + "Consider to declare/implement a mapping method: \"TypeC map(WildCardSuperWrapper value)\".") }) public void shouldFailOnSuperBounds2() { } @@ -172,13 +163,10 @@ public void shouldFailOnSuperBounds2() { }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper6.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 17, message = - "No target bean properties found: can't map property \"org.mapstruct.ap.test.NoProperties " - + "foo.wrapped\" to" - + " \"org.mapstruct.ap.test.selection.generics.TypeA " - + "foo.wrapped\". Consider to declare/implement a mapping method: \"org" + - ".mapstruct.ap.test.selection.generics.TypeA map(org.mapstruct.ap.test.NoProperties " + - "value)\".") + line = 17, + message = "No target bean properties found: can't map property " + + "\"NoProperties foo.wrapped\" to \"TypeA foo.wrapped\". " + + "Consider to declare/implement a mapping method: \"TypeA map(NoProperties value)\".") }) public void shouldFailOnNonMatchingWildCards() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 37ecfb1be6..17c3c77863 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -109,9 +109,8 @@ public void shouldMatchClassAndMethod() { type = ErroneousMapper.class, kind = Kind.ERROR, line = 28, - message = - "Can't map property \"java.lang.String title\" to \"java.lang.String title\". Consider to " + - "declare/implement a mapping method: \"java.lang.String map(java.lang.String value)\".") + message = "Can't map property \"String title\" to \"String title\". " + + "Consider to declare/implement a mapping method: \"String map(String value)\".") } ) public void shouldNotProduceMatchingMethod() { @@ -188,9 +187,8 @@ public void testFactorySelectionWithQualifier() { @Diagnostic(type = ErroneousMovieFactoryMapper.class, kind = Kind.ERROR, line = 24, - message = "The return type org.mapstruct.ap.test.selection.qualifier.bean.AbstractEntry is an " + - "abstract class or interface. Provide a non abstract / non interface result type or a factory " + - "method.") + message = "The return type AbstractEntry is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method.") } ) public void testEmptyBeanMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 9db58ec201..388532bbe8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -45,11 +45,10 @@ public class InheritanceSelectionTest { @Diagnostic(type = ErroneousFruitMapper.class, kind = Kind.ERROR, line = 23, - message = "Ambiguous factory methods found for creating org.mapstruct.ap.test.selection.resulttype" + - ".Fruit: org.mapstruct.ap.test.selection.resulttype.Apple org.mapstruct.ap.test.selection" + - ".resulttype.ConflictingFruitFactory.createApple(), org.mapstruct.ap.test.selection.resulttype" + - ".Banana org.mapstruct.ap.test.selection.resulttype.ConflictingFruitFactory.createBanana()." + - " See https://mapstruct.org/faq/#ambiguous for more info." + message = "Ambiguous factory methods found for creating Fruit: " + + "Apple ConflictingFruitFactory.createApple(), " + + "Banana ConflictingFruitFactory.createBanana(). " + + "See https://mapstruct.org/faq/#ambiguous for more info." ) } ) @@ -65,8 +64,8 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() @Diagnostic(type = ErroneousResultTypeNoAccessibleConstructorMapper.class, kind = Kind.ERROR, line = 18, - message = "org.mapstruct.ap.test.selection.resulttype" + - ".ErroneousResultTypeNoAccessibleConstructorMapper.Banana does not have an accessible constructor.") + message = + "ErroneousResultTypeNoAccessibleConstructorMapper.Banana does not have an accessible constructor.") } ) public void testResultTypeHasNoSuitableAccessibleConstructor() { @@ -112,8 +111,8 @@ public void testResultTypeBasedConstructionOfResultForInterface() { @Diagnostic(type = ResultTypeConstructingFruitInterfaceErroneousMapper.class, kind = Kind.ERROR, line = 23, - message = "The return type org.mapstruct.ap.test.selection.resulttype.IsFruit is an abstract class or" + - " interface. Provide a non abstract / non interface result type or a factory method." + message = "The return type IsFruit is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method." ) } ) @@ -129,8 +128,7 @@ public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { @Diagnostic(type = ErroneousFruitMapper2.class, kind = Kind.ERROR, line = 22, - message = "org.mapstruct.ap.test.selection.resulttype.Banana not assignable to: org.mapstruct.ap.test" + - ".selection.resulttype.Apple.") + message = "Banana not assignable to: Apple.") } ) @IssueKey("434") diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java index e22150fe36..27c33d3bd7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java @@ -17,17 +17,19 @@ public class TwoStepMappingTest { @Test - @WithClasses( ErroneousMapperMM.class ) - @ExpectedCompilationOutcome( value = CompilationResult.FAILED, + @WithClasses(ErroneousMapperMM.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousMapperMM.class, line = 16, - message = "Ambiguous 2step methods found, mapping SourceType s to TargetType. " - + "Found methodY( methodX ( parameter ) ): " - + "method(s)Y: TargetType:methodY1(TypeInTheMiddleA), methodX: TypeInTheMiddleA:methodX1(SourceType); " - + "method(s)Y: TargetType:methodY2(TypeInTheMiddleB), methodX: TypeInTheMiddleB:methodX2(SourceType); ." - ) ) + message = "Ambiguous 2step methods found, mapping SourceType s to TargetType. " + + "Found methodY( methodX ( parameter ) ): " + + "method(s)Y: ErroneousMapperMM.TargetType methodY1(ErroneousMapperMM.TypeInTheMiddleA s), " + + "methodX: ErroneousMapperMM.TypeInTheMiddleA methodX1(ErroneousMapperMM.SourceType s); " + + "method(s)Y: ErroneousMapperMM.TargetType methodY2(ErroneousMapperMM.TypeInTheMiddleB s), " + + "methodX: ErroneousMapperMM.TypeInTheMiddleB methodX2(ErroneousMapperMM.SourceType s); ." + )) public void methodAndMethodTest() { } @@ -39,10 +41,10 @@ public void methodAndMethodTest() { kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousMapperCM.class, line = 18, - message = "Ambiguous 2step methods found, mapping BigDecimal s to TargetType. " - + "Found methodY( conversionX ( parameter ) ): " - + "method(s)Y: TargetType:methodY1(String), conversionX: BigDecimal-->String; " - + "method(s)Y: TargetType:methodY2(Double), conversionX: BigDecimal-->Double; ." + message = "Ambiguous 2step methods found, mapping BigDecimal s to TargetType. " + + "Found methodY( conversionX ( parameter ) ): " + + "method(s)Y: ErroneousMapperCM.TargetType methodY1(String s), conversionX: BigDecimal-->String; " + + "method(s)Y: ErroneousMapperCM.TargetType methodY2(Double d), conversionX: BigDecimal-->Double; ." ), @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, @@ -62,10 +64,10 @@ public void conversionAndMethodTest() { kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousMapperMC.class, line = 18, - message = "Ambiguous 2step methods found, mapping SourceType s to String. " - + "Found conversionY( methodX ( parameter ) ): " - + "conversionY: BigDecimal-->String, method(s)X: BigDecimal:methodX1(SourceType); " - + "conversionY: Double-->String, method(s)X: Double:methodX2(SourceType); ." + message = "Ambiguous 2step methods found, mapping SourceType s to String. " + + "Found conversionY( methodX ( parameter ) ): " + + "conversionY: BigDecimal-->String, method(s)X: BigDecimal methodX1(ErroneousMapperMC.SourceType s); " + + "conversionY: Double-->String, method(s)X: Double methodX2(ErroneousMapperMC.SourceType s); ." ), @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java index 98a6970598..ce386ab7b0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java @@ -70,38 +70,33 @@ public void testNumericConstants() { @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 25, - message = "Can't map \"java.lang.String \"zz\"\" to \"boolean booleanValue\". Reason: only 'true' or " + - "'false' are supported."), + message = + "Can't map \"zz\" to \"boolean booleanValue\". Reason: only 'true' or 'false' are supported."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 26, - message = "Can't map \"java.lang.String \"'ba'\"\" to \"char charValue\". Reason: invalid character " + - "literal."), + message = "Can't map \"'ba'\" to \"char charValue\". Reason: invalid character literal."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 27, - message = "Can't map \"java.lang.String \"200\"\" to \"byte byteValue\". Reason: Value out of range. " + - "Value:\"200\" Radix:10."), + message = + "Can't map \"200\" to \"byte byteValue\". Reason: Value out of range. Value:\"200\" Radix:10."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 28, - message = "Can't map \"java.lang.String \"0xFFFF_FFFF_FFFF\"\" to \"int intValue\". Reason: integer " + - "number too large."), + message = "Can't map \"0xFFFF_FFFF_FFFF\" to \"int intValue\". Reason: integer number too large."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 29, - message = "Can't map \"java.lang.String \"1\"\" to \"long longValue\". Reason: L/l mandatory for long" + - " types."), + message = "Can't map \"1\" to \"long longValue\". Reason: L/l mandatory for long types."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 30, - message = "Can't map \"java.lang.String \"1.40e-_45f\"\" to \"float floatValue\". Reason: improperly " + - "placed underscores."), + message = "Can't map \"1.40e-_45f\" to \"float floatValue\". Reason: improperly placed underscores."), @Diagnostic(type = ErroneousConstantMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 31, - message = "Can't map \"java.lang.String \"1e-137000\"\" to \"double doubleValue\". Reason: floating " + - "point number too small.") + message = "Can't map \"1e-137000\" to \"double doubleValue\". Reason: floating point number too small.") } ) public void miscellaneousDetailMessages() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 7e7bc2d69e..3b307c233c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -192,13 +192,11 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, line = 28, - message = "Constant \"DENMARK\" doesn't exist in enum type org.mapstruct.ap.test.source." - + "constants.CountryEnum for property \"country\"."), + message = "Constant \"DENMARK\" doesn't exist in enum type CountryEnum for property \"country\"."), @Diagnostic(type = ErroneousMapper5.class, kind = Kind.ERROR, line = 28, - message = "Can't map \"java.lang.String \"DENMARK\"\" to \"org.mapstruct.ap.test.source." - + "constants.CountryEnum country\".") + message = "Can't map \"DENMARK\" to \"CountryEnum country\".") } ) public void errorOnNonExistingEnumConstant() throws ParseException { @@ -219,8 +217,7 @@ public void errorOnNonExistingEnumConstant() throws ParseException { @Diagnostic(type = ErroneousMapper6.class, kind = Kind.ERROR, line = 25, - message = "Can't map \"java.lang.String \"3001\"\" to \"java.lang.Long " - + "longWrapperConstant\". Reason: L/l mandatory for long types.") + message = "Can't map \"3001\" to \"Long longWrapperConstant\". Reason: L/l mandatory for long types.") } ) public void cannotMapIntConstantToLong() throws ParseException { diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index 1b93d04a53..d7e5bdea43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -175,8 +175,7 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } @Diagnostic(type = ErroneousOrganizationMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 35, - message = "org.mapstruct.ap.test.updatemethods.ErroneousOrganizationMapper2.DepartmentEntity does not" + - " have an accessible constructor.") + message = "ErroneousOrganizationMapper2.DepartmentEntity does not have an accessible constructor.") }) public void testShouldFailOnConstantMappingNoPropertyGetter() { @@ -196,9 +195,8 @@ public void testShouldFailOnConstantMappingNoPropertyGetter() { @Diagnostic(type = CompanyMapper1.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 23, - message = "Unmapped target property: \"employees\". Mapping from property \"org.mapstruct.ap.test" + - ".updatemethods.UnmappableDepartmentDto department\" to \"org.mapstruct.ap.test.updatemethods" + - ".DepartmentEntity department\".") + message = "Unmapped target property: \"employees\". " + + "Mapping from property \"UnmappableDepartmentDto department\" to \"DepartmentEntity department\".") } ) public void testShouldNotUseTwoNestedUpdateMethods() { From 609824037b21693da664863a3491b2c951fad21d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 1 Aug 2020 11:43:46 +0200 Subject: [PATCH 0493/1006] #2167 Add missing @since 1.4 to new interfaces, classes and methods --- core/src/main/java/org/mapstruct/MapperConfig.java | 2 ++ core/src/main/java/org/mapstruct/control/MappingControl.java | 2 ++ core/src/main/java/org/mapstruct/control/MappingControls.java | 2 ++ .../java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java | 2 ++ .../src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java | 2 ++ .../org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java | 2 ++ .../mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java | 2 ++ .../mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java | 2 ++ .../org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java | 2 ++ 9 files changed, 18 insertions(+) diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 326041164f..24951fb348 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -83,6 +83,8 @@ * their simple name rather than their fully-qualified name. * * @return classes to add in the imports of the generated implementation. + * + * @since 1.4 */ Class[] imports() default { }; diff --git a/core/src/main/java/org/mapstruct/control/MappingControl.java b/core/src/main/java/org/mapstruct/control/MappingControl.java index 975ff52e90..1d416dafd7 100644 --- a/core/src/main/java/org/mapstruct/control/MappingControl.java +++ b/core/src/main/java/org/mapstruct/control/MappingControl.java @@ -87,6 +87,8 @@ * * * @author Sjaak Derksen + * + * @since 1.4 */ @Retention(RetentionPolicy.CLASS) @Repeatable(MappingControls.class) diff --git a/core/src/main/java/org/mapstruct/control/MappingControls.java b/core/src/main/java/org/mapstruct/control/MappingControls.java index d3b4fe1556..a3efef661f 100644 --- a/core/src/main/java/org/mapstruct/control/MappingControls.java +++ b/core/src/main/java/org/mapstruct/control/MappingControls.java @@ -14,6 +14,8 @@ * Allows multiple {@link MappingControl} on a class declaration. * * @author Sjaak Derksen + * + * @since 1.4 */ @Retention(RetentionPolicy.CLASS) @Target(ElementType.ANNOTATION_TYPE) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java index 526d0a24f2..a54df7bc06 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java @@ -11,6 +11,8 @@ /** * @author Filip Hrisafov + * + * @since 1.4 */ public class DefaultEnumNamingStrategy implements EnumNamingStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java index c135cc9ab2..a2361eefd0 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java @@ -13,6 +13,8 @@ * A service provider interface for the mapping between different enum constants * * @author Arne Seime + * + * @since 1.4 */ @Experimental("This SPI can have it's signature changed in subsequent releases") public interface EnumNamingStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java index eaa7b75512..abb6e9cb4f 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java @@ -7,6 +7,8 @@ /** * @author Filip Hrisafov + * + * @since 1.4 */ public class PrefixEnumTransformationStrategy implements EnumTransformationStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java index d7f03c9b7b..d3f0c515b3 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java @@ -7,6 +7,8 @@ /** * @author Filip Hrisafov + * + * @since 1.4 */ public class StripPrefixEnumTransformationStrategy implements EnumTransformationStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java index 223837924e..cf239600d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java @@ -7,6 +7,8 @@ /** * @author Filip Hrisafov + * + * @since 1.4 */ public class StripSuffixEnumTransformationStrategy implements EnumTransformationStrategy { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java index 29a109fadf..4cd92b9af8 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java @@ -7,6 +7,8 @@ /** * @author Filip Hrisafov + * + * @since 1.4 */ public class SuffixEnumTransformationStrategy implements EnumTransformationStrategy { From ed16d62a91374553059a8296abf8ec297d9a34dd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 1 Aug 2020 09:02:29 +0200 Subject: [PATCH 0494/1006] #2170 Make sure that an import is created for constructor mapping defined variables --- .../ap/internal/model/BeanMappingMethod.java | 4 ++ .../ap/test/bugs/_2170/Issue2170Test.java | 55 +++++++++++++++++++ .../ap/test/bugs/_2170/dto/AddressDto.java | 31 +++++++++++ .../ap/test/bugs/_2170/dto/PersonDto.java | 23 ++++++++ .../ap/test/bugs/_2170/entity/Address.java | 29 ++++++++++ .../ap/test/bugs/_2170/entity/Person.java | 21 +++++++ .../test/bugs/_2170/mapper/AddressMapper.java | 23 ++++++++ .../test/bugs/_2170/mapper/EntityMapper.java | 21 +++++++ .../test/bugs/_2170/mapper/PersonMapper.java | 18 ++++++ 9 files changed, 225 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/AddressDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/PersonDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Address.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Person.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/AddressMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/EntityMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/PersonMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 3d86a59299..b0562373ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1488,6 +1488,10 @@ public Set getImportTypes() { for ( PropertyMapping propertyMapping : propertyMappings ) { types.addAll( propertyMapping.getImportTypes() ); + if ( propertyMapping.isConstructorMapping() ) { + // We need to add the target type imports for a constructor mapper since we define its parameters + types.addAll( propertyMapping.getTargetType().getImportTypes() ); + } } if ( returnTypeToConstruct != null ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java new file mode 100644 index 0000000000..779cc7fd03 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._2170.dto.AddressDto; +import org.mapstruct.ap.test.bugs._2170.dto.PersonDto; +import org.mapstruct.ap.test.bugs._2170.entity.Address; +import org.mapstruct.ap.test.bugs._2170.entity.Person; +import org.mapstruct.ap.test.bugs._2170.mapper.AddressMapper; +import org.mapstruct.ap.test.bugs._2170.mapper.EntityMapper; +import org.mapstruct.ap.test.bugs._2170.mapper.PersonMapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2170") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Address.class, + Person.class, + AddressDto.class, + PersonDto.class, + AddressMapper.class, + PersonMapper.class, + EntityMapper.class, +}) +public class Issue2170Test { + + @Test + public void shouldGenerateCodeThatCompiles() { + + AddressDto addressDto = AddressMapper.INSTANCE.toDto( new Address( + "10000", + Collections.singletonList( new Person( "Tester" ) ) + ) ); + + assertThat( addressDto ).isNotNull(); + assertThat( addressDto.getZipCode() ).isEqualTo( "10000" ); + assertThat( addressDto.getPeople() ) + .extracting( PersonDto::getName ) + .containsExactly( "Tester" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/AddressDto.java new file mode 100644 index 0000000000..c0b9b06317 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/AddressDto.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.dto; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class AddressDto { + + private final String zipCode; + private final List people; + + public AddressDto(String zipCode, + List people) { + this.zipCode = zipCode; + this.people = people; + } + + public String getZipCode() { + return zipCode; + } + + public List getPeople() { + return people; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/PersonDto.java new file mode 100644 index 0000000000..7e6d22e72a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/dto/PersonDto.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.dto; + +/** + * @author Filip Hrisafov + */ +public +class PersonDto { + + private final String name; + + public PersonDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Address.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Address.java new file mode 100644 index 0000000000..660ff0a260 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Address.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.entity; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Address { + private final String zipCode; + private final List people; + + public Address(String zipCode, List people) { + this.zipCode = zipCode; + this.people = people; + } + + public String getZipCode() { + return zipCode; + } + + public List getPeople() { + return people; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Person.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Person.java new file mode 100644 index 0000000000..dc36699c5b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/entity/Person.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.entity; + +/** + * @author Filip Hrisafov + */ +public class Person { + private final String name; + + public Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/AddressMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/AddressMapper.java new file mode 100644 index 0000000000..e31937609e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/AddressMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2170.dto.AddressDto; +import org.mapstruct.ap.test.bugs._2170.entity.Address; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +//CHECKSTYLE:OFF +@Mapper(uses = { PersonMapper.class }) +//CHECKSTYLE:ON +public interface AddressMapper extends EntityMapper { + + AddressMapper INSTANCE = Mappers.getMapper( AddressMapper.class ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/EntityMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/EntityMapper.java new file mode 100644 index 0000000000..0f24b05483 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/EntityMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.mapper; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public interface EntityMapper { + E toEntity(D dto); + + D toDto(E entity); + + List toEntity(List dtoList); + + List toDto(List entityList); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/PersonMapper.java new file mode 100644 index 0000000000..28e7d0a31e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/mapper/PersonMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2170.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2170.dto.PersonDto; +import org.mapstruct.ap.test.bugs._2170.entity.Person; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface PersonMapper extends EntityMapper { + +} From e6279d10c78795231cd6fb790760e53147d5459a Mon Sep 17 00:00:00 2001 From: Makoto Oda Date: Wed, 26 Aug 2020 03:34:02 +0900 Subject: [PATCH 0495/1006] Is 'r' missing? (#2188) --- .../src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index bc9cf7646c..54c33ed938 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -2,7 +2,7 @@ == Using the MapStruct SPI === Custom Accessor Naming Strategy -MapStruct offers the possibility to override the `AccessorNamingStrategy` via the Service Provide Interface (SPI). A nice example is the use of the fluent API on the source object `GolfPlayer` and `GolfPlayerDto` below. +MapStruct offers the possibility to override the `AccessorNamingStrategy` via the Service Provider Interface (SPI). A nice example is the use of the fluent API on the source object `GolfPlayer` and `GolfPlayerDto` below. .Source object GolfPlayer with fluent API. ==== From 18a5f1bdc0de319e3f02def64891e55c409f1824 Mon Sep 17 00:00:00 2001 From: Makoto Oda Date: Wed, 26 Aug 2020 03:37:02 +0900 Subject: [PATCH 0496/1006] Documentation: Extra phrase inserted? (#2187) --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 28d6e9d1e0..4220c4d305 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -185,7 +185,7 @@ For all other objects an new instance is created. Please note that a default con 2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. -The strategy works in a hierarchical fashion. Setting `Mapping#nullValuePropertyMappingStrategy` on mapping level will override `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. +The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. [NOTE] ==== From 99a1fd609c2d71c3ce8a39c1e56a51bb3242f0b2 Mon Sep 17 00:00:00 2001 From: Makoto Oda Date: Wed, 26 Aug 2020 03:38:19 +0900 Subject: [PATCH 0497/1006] Documentation: typo? (#2186) --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 4220c4d305..ddf7fbcaed 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -144,7 +144,7 @@ public class FruitFactory { ---- ==== -So, which `Fruit` must be factorized in the mapping method `Fruit map(FruitDto source);`? A `Banana` or an `Apple`? Here's were the `@BeanMapping#resultType` comes in handy. It controls the factory method to select, or in absence of a factory method, the return type to create. +So, which `Fruit` must be factorized in the mapping method `Fruit map(FruitDto source);`? A `Banana` or an `Apple`? Here's where the `@BeanMapping#resultType` comes in handy. It controls the factory method to select, or in absence of a factory method, the return type to create. [TIP] ==== From 3ce9786cf654050d6146ba9305f7216fee163371 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Aug 2020 08:59:20 +0200 Subject: [PATCH 0498/1006] #2174 Forged methods should inherit all thrown exceptions from their property mappings --- .../ap/internal/model/BeanMappingMethod.java | 14 +- .../ap/test/bugs/_2174/Issue2174Test.java | 45 ++++++ .../ap/test/bugs/_2174/UserMapper.java | 128 ++++++++++++++++++ 3 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/UserMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b0562373ff..0062611e2e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -296,8 +296,18 @@ else if ( !method.isUpdateMethod() ) { existingVariableNames ); - if (factoryMethod != null && method instanceof ForgedMethod ) { - ( (ForgedMethod) method ).addThrownTypes( factoryMethod.getThrownTypes() ); + if ( method instanceof ForgedMethod ) { + ForgedMethod forgedMethod = (ForgedMethod) method; + if ( factoryMethod != null ) { + forgedMethod.addThrownTypes( factoryMethod.getThrownTypes() ); + } + + for ( PropertyMapping propertyMapping : propertyMappings ) { + if ( propertyMapping.getAssignment() != null ) { + forgedMethod.addThrownTypes( propertyMapping.getAssignment().getThrownTypes() ); + } + } + } MethodReference finalizeMethod = null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java new file mode 100644 index 0000000000..89359957c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2174; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2174") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses(UserMapper.class) +public class Issue2174Test { + + @Test + public void shouldNotWrapCheckedException() throws Exception { + + UserMapper.User user = UserMapper.INSTANCE.map( new UserMapper.UserDto( "Test City", "10000" ) ); + + assertThat( user ).isNotNull(); + assertThat( user.getAddress() ).isNotNull(); + assertThat( user.getAddress().getCity() ).isNotNull(); + assertThat( user.getAddress().getCity().getName() ).isEqualTo( "Test City" ); + assertThat( user.getAddress().getCode() ).isNotNull(); + assertThat( user.getAddress().getCode().getCode() ).isEqualTo( "10000" ); + + assertThatThrownBy( () -> UserMapper.INSTANCE.map( new UserMapper.UserDto( "Zurich", "10000" ) ) ) + .isInstanceOf( UserMapper.CityNotFoundException.class ) + .hasMessage( "City with name 'Zurich' does not exist" ); + + assertThatThrownBy( () -> UserMapper.INSTANCE.map( new UserMapper.UserDto( "Test City", "1000" ) ) ) + .isInstanceOf( UserMapper.PostalCodeNotFoundException.class ) + .hasMessage( "Postal code '1000' does not exist" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/UserMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/UserMapper.java new file mode 100644 index 0000000000..025201b30c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/UserMapper.java @@ -0,0 +1,128 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2174; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface UserMapper { + + UserMapper INSTANCE = Mappers.getMapper( UserMapper.class ); + + @Mapping(target = "address.city", source = "city") + @Mapping(target = "address.code", source = "postalCode") + User map(UserDto dto) throws CityNotFoundException, PostalCodeNotFoundException; + + default City mapCity(String city) throws CityNotFoundException { + if ( "Test City".equals( city ) ) { + return new City( city ); + } + + throw new CityNotFoundException( "City with name '" + city + "' does not exist" ); + } + + default PostalCode mapCode(String code) throws PostalCodeNotFoundException { + if ( "10000".equals( code ) ) { + return new PostalCode( code ); + } + + throw new PostalCodeNotFoundException( "Postal code '" + code + "' does not exist" ); + } + + class UserDto { + private final String city; + private final String postalCode; + + public UserDto(String city, String postalCode) { + this.city = city; + this.postalCode = postalCode; + } + + public String getCity() { + return city; + } + + public String getPostalCode() { + return postalCode; + } + } + + class User { + + private final Address address; + + public User(Address address) { + this.address = address; + } + + public Address getAddress() { + return address; + } + } + + class Address { + private final City city; + private final PostalCode code; + + public Address(City city, PostalCode code) { + this.city = city; + this.code = code; + } + + public City getCity() { + return city; + } + + public PostalCode getCode() { + return code; + } + } + + class City { + + private final String name; + + public City(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class PostalCode { + + private final String code; + + public PostalCode(String code) { + this.code = code; + } + + public String getCode() { + return code; + } + } + + class CityNotFoundException extends Exception { + + public CityNotFoundException(String message) { + super( message ); + } + } + + class PostalCodeNotFoundException extends Exception { + + public PostalCodeNotFoundException(String message) { + super( message ); + } + } +} From c1feafef4c68053999b3d92be030ad41bd8843ba Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Aug 2020 11:22:18 +0200 Subject: [PATCH 0499/1006] #2177 Mapping into a generic class / record with a typed constructor argument should work --- .../itest/records/CustomerMapper.java | 3 ++ .../itest/records/GenericRecord.java | 13 ++++++ .../mapstruct/itest/records/RecordsTest.java | 12 +++++ .../ap/internal/model/BeanMappingMethod.java | 27 +++++++++--- .../accessor/ParameterElementAccessor.java | 6 ++- .../ap/test/bugs/_2177/Issue2177Mapper.java | 44 +++++++++++++++++++ .../ap/test/bugs/_2177/Issue2177Test.java | 34 ++++++++++++++ 7 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/GenericRecord.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java index a3c7037f03..addb8c5906 100644 --- a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CustomerMapper.java @@ -24,4 +24,7 @@ public interface CustomerMapper { @InheritInverseConfiguration CustomerDto toRecord(CustomerEntity entity); + @Mapping(target = "value", source = "name") + GenericRecord toValue(CustomerEntity entity); + } diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/GenericRecord.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/GenericRecord.java new file mode 100644 index 0000000000..9a39b59968 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/GenericRecord.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public record GenericRecord(T value) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index 824a763fc7..b404681806 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -35,4 +35,16 @@ public void shouldMapIntoRecord() { assertThat( customer.name() ).isEqualTo( "Kermit" ); assertThat( customer.email() ).isEqualTo( "kermit@test.com" ); } + + @Test + public void shouldMapIntoGenericRecord() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Kermit" ); + entity.setMail( "kermit@test.com" ); + + GenericRecord value = CustomerMapper.INSTANCE.toValue( entity ); + + assertThat( value ).isNotNull(); + assertThat( value.value() ).isEqualTo( "Kermit" ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0062611e2e..d6f06b49e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -27,6 +27,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.tools.Diagnostic; @@ -598,15 +599,21 @@ private ConstructorAccessor getConstructorAccessor(Type type) { List parameterBindings = new ArrayList<>( recordComponents.size() ); Map constructorAccessors = new LinkedHashMap<>(); for ( Element recordComponent : recordComponents ) { + TypeMirror recordComponentMirror = ctx.getTypeUtils() + .asMemberOf( (DeclaredType) type.getTypeMirror(), recordComponent ); String parameterName = recordComponent.getSimpleName().toString(); - Accessor accessor = createConstructorAccessor( recordComponent, parameterName ); + Accessor accessor = createConstructorAccessor( + recordComponent, + recordComponentMirror, + parameterName + ); constructorAccessors.put( parameterName, accessor ); parameterBindings.add( ParameterBinding.fromTypeAndName( - ctx.getTypeFactory().getType( recordComponent.asType() ), + ctx.getTypeFactory().getType( recordComponentMirror ), accessor.getSimpleName() ) ); } @@ -718,7 +725,11 @@ private ConstructorAccessor getConstructorAccessor(Type type, ExecutableElement for ( Parameter constructorParameter : constructorParameters ) { String parameterName = constructorParameter.getName(); Element parameterElement = constructorParameter.getElement(); - Accessor constructorAccessor = createConstructorAccessor( parameterElement, parameterName ); + Accessor constructorAccessor = createConstructorAccessor( + parameterElement, + constructorParameter.getType().getTypeMirror(), + parameterName + ); constructorAccessors.put( parameterName, constructorAccessor @@ -746,7 +757,11 @@ else if ( constructorProperties.size() != constructorParameters.size() ) { String parameterName = constructorProperties.get( i ); Parameter constructorParameter = constructorParameters.get( i ); Element parameterElement = constructorParameter.getElement(); - Accessor constructorAccessor = createConstructorAccessor( parameterElement, parameterName ); + Accessor constructorAccessor = createConstructorAccessor( + parameterElement, + constructorParameter.getType().getTypeMirror(), + parameterName + ); constructorAccessors.put( parameterName, constructorAccessor @@ -761,13 +776,13 @@ else if ( constructorProperties.size() != constructorParameters.size() ) { } } - private Accessor createConstructorAccessor(Element element, String parameterName) { + private Accessor createConstructorAccessor(Element element, TypeMirror accessedType, String parameterName) { String safeParameterName = Strings.getSafeVariableName( parameterName, existingVariableNames ); existingVariableNames.add( safeParameterName ); - return new ParameterElementAccessor( element, safeParameterName ); + return new ParameterElementAccessor( element, accessedType, safeParameterName ); } private boolean hasDefaultAnnotationFromAnyPackage(Element element) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java index e1877cb0bb..9991370059 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java @@ -17,10 +17,12 @@ public class ParameterElementAccessor extends AbstractAccessor { protected final String name; + protected final TypeMirror accessedType; - public ParameterElementAccessor(Element element, String name) { + public ParameterElementAccessor(Element element, TypeMirror accessedType, String name) { super( element ); this.name = name; + this.accessedType = accessedType; } @Override @@ -30,7 +32,7 @@ public String getSimpleName() { @Override public TypeMirror getAccessedType() { - return element.asType(); + return accessedType; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Mapper.java new file mode 100644 index 0000000000..bf96c6b5b8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Mapper.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2177; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2177Mapper { + + Issue2177Mapper INSTANCE = Mappers.getMapper( Issue2177Mapper.class ); + + Target map(Source source); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + private final T value; + + public Target(T value) { + this.value = value; + } + + public T getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java new file mode 100644 index 0000000000..50c1d9f69b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2177; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2177") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2177Mapper.class +}) +public class Issue2177Test { + + @Test + public void shouldCorrectlyUseGenericClassesWithConstructorMapping() { + + Issue2177Mapper.Target target = Issue2177Mapper.INSTANCE.map( new Issue2177Mapper.Source( "test" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "test" ); + } +} From a9451b1159522c2203f3788222a678163d78b4ab Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Aug 2020 11:44:13 +0200 Subject: [PATCH 0500/1006] #2185 Fix StackOverflow error when recursive use of mapper in Mapper#uses --- .../processor/MethodRetrievalProcessor.java | 21 +++++++-- .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/test/bugs/_2185/Issue2185Test.java | 45 ++++++++++++++++++ .../ap/test/bugs/_2185/TodoMapper.java | 46 +++++++++++++++++++ 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/TodoMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 672d905ee0..059a000bc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -176,11 +176,22 @@ private List retrieveMethods(TypeElement usedMapper, TypeElement m //Add all methods of used mappers in order to reference them in the aggregated model if ( usedMapper.equals( mapperToImplement ) ) { for ( DeclaredType mapper : mapperOptions.uses() ) { - methods.addAll( retrieveMethods( - asTypeElement( mapper ), - mapperToImplement, - mapperOptions, - prototypeMethods ) ); + TypeElement usesMapperElement = asTypeElement( mapper ); + if ( !mapperToImplement.equals( usesMapperElement ) ) { + methods.addAll( retrieveMethods( + usesMapperElement, + mapperToImplement, + mapperOptions, + prototypeMethods ) ); + } + else { + messager.printMessage( + mapperToImplement, + mapperOptions.getAnnotationMirror(), + Message.RETRIEVAL_MAPPER_USES_CYCLE, + mapperToImplement + ); + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 67cd1aba06..6f0db248bf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -149,6 +149,7 @@ public enum Message { RETRIEVAL_WILDCARD_SUPER_BOUND_SOURCE( "Can't generate mapping method for a wildcard super bound source." ), RETRIEVAL_WILDCARD_EXTENDS_BOUND_RESULT( "Can't generate mapping method for a wildcard extends bound result." ), RETRIEVAL_CONTEXT_PARAMS_WITH_SAME_TYPE( "The types of @Context parameters must be unique." ), + RETRIEVAL_MAPPER_USES_CYCLE( "The mapper %s is referenced itself in Mapper#uses.", Diagnostic.Kind.WARNING ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java new file mode 100644 index 0000000000..3b26842c0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2185; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2185") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + TodoMapper.class +}) +public class Issue2185Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = TodoMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 14, + message = "The mapper org.mapstruct.ap.test.bugs._2185.TodoMapper is referenced itself in Mapper#uses.") + } + ) + public void shouldCompile() { + + TodoMapper.TodoResponse response = TodoMapper.INSTANCE.toResponse( new TodoMapper.TodoEntity( "test" ) ); + + assertThat( response ).isNotNull(); + assertThat( response.getNote() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/TodoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/TodoMapper.java new file mode 100644 index 0000000000..2d52bed1fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/TodoMapper.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2185; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = TodoMapper.class) +public interface TodoMapper { + + TodoMapper INSTANCE = Mappers.getMapper( TodoMapper.class ); + + TodoResponse toResponse(TodoEntity entity); + + class TodoResponse { + + private final String note; + + public TodoResponse(String note) { + this.note = note; + } + + public String getNote() { + return note; + } + } + + class TodoEntity { + + private final String note; + + public TodoEntity(String note) { + this.note = note; + } + + public String getNote() { + return note; + } + } +} From 7dcbef349d234e986ba41a4838937274f55e5c14 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Aug 2020 13:53:30 +0200 Subject: [PATCH 0501/1006] #2169 Add support for defining a custom unexpected value mapping exception Expose definition via: * `@EnumMapping` * `@Mapper` * `@MapperConfig` * `EnumMappingStrategy` SPI Rename `EnumNamingStrategy` to `EnumMappingStrategy` --- .../main/java/org/mapstruct/EnumMapping.java | 25 ++++- core/src/main/java/org/mapstruct/Mapper.java | 23 ++++ .../main/java/org/mapstruct/MapperConfig.java | 22 ++++ .../chapter-13-using-mapstruct-spi.asciidoc | 8 +- .../internal/model/MappingBuilderContext.java | 12 +-- .../ap/internal/model/ValueMappingMethod.java | 48 +++++++-- .../internal/model/source/DefaultOptions.java | 6 ++ .../model/source/DelegatingOptions.java | 4 + .../model/source/EnumMappingOptions.java | 64 +++++++++-- .../model/source/MapperConfigOptions.java | 8 ++ .../internal/model/source/MapperOptions.java | 8 ++ .../DefaultModelElementProcessorContext.java | 6 +- .../processor/MapperCreationProcessor.java | 2 +- .../processor/ModelElementProcessor.java | 4 +- .../util/AnnotationProcessorContext.java | 16 +-- .../mapstruct/ap/internal/util/Message.java | 4 +- .../mapstruct/ap/internal/util/Strings.java | 4 + ...y.java => DefaultEnumMappingStrategy.java} | 11 +- ...Strategy.java => EnumMappingStrategy.java} | 11 +- .../ap/internal/model/ValueMappingMethod.ftl | 4 +- .../value/CustomIllegalArgumentException.java | 16 +++ .../erroneous/EmptyEnumMappingMapper.java | 25 +++++ .../erroneous/ErroneousEnumMappingTest.java | 63 +++++++++++ .../NoConfigurationEnumMappingMapper.java | 26 +++++ .../ap/test/value/exception/Config.java | 16 +++ ...dValueMappingExceptionDefinedInMapper.java | 35 ++++++ ...xceptionDefinedInMapperAndEnumMapping.java | 38 +++++++ ...MappingExceptionDefinedInMapperConfig.java | 34 ++++++ ...UnexpectedValueMappingExceptionMapper.java | 39 +++++++ ...omUnexpectedValueMappingExceptionTest.java | 48 +++++++++ .../ap/test/value/spi/CustomCheeseMapper.java | 3 + ...gy.java => CustomEnumMappingStrategy.java} | 12 ++- ...ava => CustomEnumMappingStrategyTest.java} | 10 +- ...> CustomErroneousEnumMappingStrategy.java} | 6 +- ...stomErroneousEnumMappingStrategyTest.java} | 14 +-- ...tionDefinedInMapperAndEnumMappingImpl.java | 101 ++++++++++++++++++ ...ingExceptionDefinedInMapperConfigImpl.java | 101 ++++++++++++++++++ ...ueMappingExceptionDefinedInMapperImpl.java | 101 ++++++++++++++++++ ...pectedValueMappingExceptionMapperImpl.java | 101 ++++++++++++++++++ .../value/spi/CustomCheeseMapperImpl.java | 7 +- 40 files changed, 1014 insertions(+), 72 deletions(-) rename processor/src/main/java/org/mapstruct/ap/spi/{DefaultEnumNamingStrategy.java => DefaultEnumMappingStrategy.java} (68%) rename processor/src/main/java/org/mapstruct/ap/spi/{EnumNamingStrategy.java => EnumMappingStrategy.java} (80%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/CustomIllegalArgumentException.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/erroneous/EmptyEnumMappingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/erroneous/NoConfigurationEnumMappingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java rename processor/src/test/java/org/mapstruct/ap/test/value/spi/{CustomEnumNamingStrategy.java => CustomEnumMappingStrategy.java} (77%) rename processor/src/test/java/org/mapstruct/ap/test/value/spi/{CustomEnumNamingStrategyTest.java => CustomEnumMappingStrategyTest.java} (94%) rename processor/src/test/java/org/mapstruct/ap/test/value/spi/{CustomErroneousEnumNamingStrategy.java => CustomErroneousEnumMappingStrategy.java} (87%) rename processor/src/test/java/org/mapstruct/ap/test/value/spi/{CustomErroneousEnumNamingStrategyTest.java => CustomErroneousEnumMappingStrategyTest.java} (90%) create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMappingImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfigImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/EnumMapping.java b/core/src/main/java/org/mapstruct/EnumMapping.java index c184448aad..2f908579e8 100644 --- a/core/src/main/java/org/mapstruct/EnumMapping.java +++ b/core/src/main/java/org/mapstruct/EnumMapping.java @@ -111,7 +111,7 @@ * * @return the name transformation strategy */ - String nameTransformationStrategy(); + String nameTransformationStrategy() default ""; /** * The configuration that should be passed on the appropriate name transformation strategy. @@ -119,5 +119,26 @@ * * @return the configuration to use */ - String configuration(); + String configuration() default ""; + + /** + * Exception that should be thrown by the generated code if no mapping matches. + * If no exception is configured, the exception given via {@link MapperConfig#unexpectedValueMappingException()} or + * {@link Mapper#unexpectedValueMappingException()} will be used, using {@link IllegalArgumentException} by default. + * + *

    + * Note: + *

      + *
    • + * The defined exception should at least have a constructor with a {@link String} parameter. + *
    • + *
    • + * If the defined exception is a checked exception then the enum mapping methods should have that exception + * in the throws clause. + *
    • + *
    + * + * @return the exception that should be used in the generated code + */ + Class unexpectedValueMappingException() default IllegalArgumentException.class; } diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index ce8eebf1cb..233907621a 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -296,4 +296,27 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default * @see org.mapstruct.control.MappingControl */ Class mappingControl() default MappingControl.class; + + /** + * Exception that should be thrown by the generated code if no mapping matches for enums. + * If no exception is configured, the exception given via {@link MapperConfig#unexpectedValueMappingException()} + * will be used, using {@link IllegalArgumentException} by default. + * + *

    + * Note: + *

      + *
    • + * The defined exception should at least have a constructor with a {@link String} parameter. + *
    • + *
    • + * If the defined exception is a checked exception then the enum mapping methods should have that exception + * in the throws clause. + *
    • + *
    + * + * @return the exception that should be used in the generated code + * + * @since 1.4 + */ + Class unexpectedValueMappingException() default IllegalArgumentException.class; } diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 24951fb348..d251ff3798 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -273,5 +273,27 @@ MappingInheritanceStrategy mappingInheritanceStrategy() */ Class mappingControl() default MappingControl.class; + /** + * Exception that should be thrown by the generated code if no mapping matches for enums. + * If no exception is configured, {@link IllegalArgumentException} will be used by default. + * + *

    + * Note: + *

      + *
    • + * The defined exception should at least have a constructor with a {@link String} parameter. + *
    • + *
    • + * If the defined exception is a checked exception then the enum mapping methods should have that exception + * in the throws clause. + *
    • + *
    + * + * @return the exception that should be used in the generated code + * + * @since 1.4 + */ + Class unexpectedValueMappingException() default IllegalArgumentException.class; + } diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index 54c33ed938..51fec968bf 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -202,7 +202,7 @@ include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] [[custom-enum-naming-strategy]] === Custom Enum Naming Strategy -MapStruct offers the possibility to override the `EnumNamingStrategy` via the Service Provider Interface (SPI). +MapStruct offers the possibility to override the `EnumMappingStrategy` via the Service Provider Interface (SPI). This can be used when you have certain enums that follow some conventions within your organization. For example all enums which implement an interface named `CustomEnumMarker` are prefixed with `CUSTOM_` and the default value for them when mapping from `null` is `UNSPECIFIED` @@ -250,15 +250,15 @@ public interface CheeseTypeMapper { ---- ==== -This can be achieved with implementing the SPI `org.mapstruct.ap.spi.EnumNamingStrategy` as in the following example. -Here’s an implemented `org.mapstruct.ap.spi.EnumNamingStrategy`: +This can be achieved with implementing the SPI `org.mapstruct.ap.spi.EnumMappingStrategy` as in the following example. +Here’s an implemented `org.mapstruct.ap.spi.EnumMappingStrategy`: .Custom enum naming strategy ==== [source, java, linenums] [subs="verbatim,attributes"] ---- -public class CustomEnumNamingStrategy extends DefaultEnumNamingStrategy { +public class CustomEnumMappingStrategy extends DefaultEnumMappingStrategy { @Override public String getDefaultNullEnumConstant(TypeElement enumType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index f5c5887d54..8da5cb5085 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -30,7 +30,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.MappingExclusionProvider; @@ -107,7 +107,7 @@ Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory descrip private final Types typeUtils; private final FormattingMessager messager; private final AccessorNamingUtils accessorNaming; - private final EnumNamingStrategy enumNamingStrategy; + private final EnumMappingStrategy enumMappingStrategy; private final Map enumTransformationStrategies; private final Options options; private final TypeElement mapperTypeElement; @@ -124,7 +124,7 @@ public MappingBuilderContext(TypeFactory typeFactory, Types typeUtils, FormattingMessager messager, AccessorNamingUtils accessorNaming, - EnumNamingStrategy enumNamingStrategy, + EnumMappingStrategy enumMappingStrategy, Map enumTransformationStrategies, Options options, MappingResolver mappingResolver, @@ -136,7 +136,7 @@ public MappingBuilderContext(TypeFactory typeFactory, this.typeUtils = typeUtils; this.messager = messager; this.accessorNaming = accessorNaming; - this.enumNamingStrategy = enumNamingStrategy; + this.enumMappingStrategy = enumMappingStrategy; this.enumTransformationStrategies = enumTransformationStrategies; this.options = options; this.mappingResolver = mappingResolver; @@ -191,8 +191,8 @@ public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } - public EnumNamingStrategy getEnumNamingStrategy() { - return enumNamingStrategy; + public EnumMappingStrategy getEnumMappingStrategy() { + return enumMappingStrategy; } public Map getEnumTransformationStrategies() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 72f8153c5e..9c7272f2ba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -43,7 +43,9 @@ public class ValueMappingMethod extends MappingMethod { private final List valueMappings; private final String defaultTarget; private final String nullTarget; - private final boolean throwIllegalArgumentException; + + private final Type unexpectedValueMappingException; + private final boolean overridden; public static class Builder { @@ -90,7 +92,7 @@ public ValueMappingMethod build() { if ( targetType.isEnumType() && valueMappings.nullTarget == null ) { // If null target is not set it means that the user has not explicitly defined a mapping for null - valueMappings.nullValueTarget = ctx.getEnumNamingStrategy() + valueMappings.nullValueTarget = ctx.getEnumMappingStrategy() .getDefaultNullEnumConstant( targetType.getTypeElement() ); } @@ -118,14 +120,14 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { mappingEntries, valueMappings.nullValueTarget, valueMappings.defaultTargetValue, - !valueMappings.hasDefaultValue, + determineUnexpectedValueMappingException(), beforeMappingMethods, afterMappingMethods ); } private void initializeEnumTransformationStrategy() { - if ( !enumMapping.hasAnnotation() ) { + if ( !enumMapping.hasNameTransformationStrategy() ) { enumTransformationInvoker = EnumTransformationStrategyInvoker.DEFAULT; } else { @@ -290,7 +292,7 @@ private List stringToEnumMapping(Method method, Type targetType ) } private String getEnumConstant(TypeElement typeElement, String enumConstant) { - return ctx.getEnumNamingStrategy().getEnumConstant( typeElement, enumConstant ); + return ctx.getEnumMappingStrategy().getEnumConstant( typeElement, enumConstant ); } private SelectionParameters getSelectionParameters(Method method, Types typeUtils) { @@ -408,12 +410,26 @@ else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != n Message.VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI, valueMappings.nullValueTarget, method.getReturnType(), - ctx.getEnumNamingStrategy() + ctx.getEnumMappingStrategy() ); } return !foundIncorrectMapping; } + + private Type determineUnexpectedValueMappingException() { + if ( !valueMappings.hasDefaultValue ) { + TypeMirror unexpectedValueMappingException = enumMapping.getUnexpectedValueMappingException(); + if ( unexpectedValueMappingException != null ) { + return ctx.getTypeFactory().getType( unexpectedValueMappingException ); + } + + return ctx.getTypeFactory() + .getType( ctx.getEnumMappingStrategy().getUnexpectedValueMappingExceptionType() ); + } + + return null; + } } private static class EnumTransformationStrategyInvoker { @@ -485,16 +501,28 @@ String getValue(ValueMappingOptions valueMapping) { } private ValueMappingMethod(Method method, List enumMappings, String nullTarget, String defaultTarget, - boolean throwIllegalArgumentException, List beforeMappingMethods, + Type unexpectedValueMappingException, + List beforeMappingMethods, List afterMappingMethods) { super( method, beforeMappingMethods, afterMappingMethods ); this.valueMappings = enumMappings; this.nullTarget = nullTarget; this.defaultTarget = defaultTarget; - this.throwIllegalArgumentException = throwIllegalArgumentException; + this.unexpectedValueMappingException = unexpectedValueMappingException; this.overridden = method.overridesMethod(); } + @Override + public Set getImportTypes() { + Set importTypes = super.getImportTypes(); + + if ( unexpectedValueMappingException != null && !unexpectedValueMappingException.isJavaLangType() ) { + importTypes.addAll( unexpectedValueMappingException.getImportTypes() ); + } + + return importTypes; + } + public List getValueMappings() { return valueMappings; } @@ -507,8 +535,8 @@ public String getNullTarget() { return nullTarget; } - public boolean isThrowIllegalArgumentException() { - return throwIllegalArgumentException; + public Type getUnexpectedValueMappingException() { + return unexpectedValueMappingException; } public Parameter getSourceParameter() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 77911be2e6..81f870e25b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.Set; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.option.Options; @@ -127,6 +128,11 @@ public MappingControl getMappingControl(Elements elementUtils) { return MappingControl.fromTypeMirror( mapper.mappingControl().getDefaultValue(), elementUtils ); } + @Override + public TypeMirror getUnexpectedValueMappingException() { + return null; + } + @Override public boolean hasAnnotation() { return false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 8bc6ab982b..c458681988 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -105,6 +105,10 @@ public MappingControl getMappingControl(Elements elementUtils) { return next.getMappingControl( elementUtils ); } + public TypeMirror getUnexpectedValueMappingException() { + return next.getUnexpectedValueMappingException(); + } + DelegatingOptions next() { return next; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java index 576474e680..86c415a4f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java @@ -7,6 +7,7 @@ import java.util.Map; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.gem.EnumMappingGem; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -14,6 +15,8 @@ import org.mapstruct.ap.spi.EnumTransformationStrategy; import static org.mapstruct.ap.internal.util.Message.ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY; +import static org.mapstruct.ap.internal.util.Message.ENUMMAPPING_MISSING_CONFIGURATION; +import static org.mapstruct.ap.internal.util.Message.ENUMMAPPING_NO_ELEMENTS; /** * @author Filip Hrisafov @@ -40,12 +43,25 @@ public boolean isValid() { return valid; } + public boolean hasNameTransformationStrategy() { + return hasAnnotation() && Strings.isNotEmpty( getNameTransformationStrategy() ); + } + public String getNameTransformationStrategy() { - return enumMapping.nameTransformationStrategy().get(); + return enumMapping.nameTransformationStrategy().getValue(); } public String getNameTransformationConfiguration() { - return enumMapping.configuration().get(); + return enumMapping.configuration().getValue(); + } + + @Override + public TypeMirror getUnexpectedValueMappingException() { + if ( enumMapping != null && enumMapping.unexpectedValueMappingException().hasValue() ) { + return enumMapping.unexpectedValueMappingException().getValue(); + } + + return next().getUnexpectedValueMappingException(); } public boolean isInverse() { @@ -79,21 +95,47 @@ private static boolean isConsistent(EnumMappingGem gem, ExecutableElement method Map enumTransformationStrategies, FormattingMessager messager) { String strategy = gem.nameTransformationStrategy().getValue(); + String configuration = gem.configuration().getValue(); + + boolean isConsistent = false; + + if ( Strings.isNotEmpty( strategy ) || Strings.isNotEmpty( configuration ) ) { + if ( !enumTransformationStrategies.containsKey( strategy ) ) { + String registeredStrategies = Strings.join( enumTransformationStrategies.keySet(), ", " ); + messager.printMessage( + method, + gem.mirror(), + gem.nameTransformationStrategy().getAnnotationValue(), + ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY, + strategy, + registeredStrategies + ); + + return false; + } + else if ( Strings.isEmpty( configuration ) ) { + messager.printMessage( + method, + gem.mirror(), + gem.configuration().getAnnotationValue(), + ENUMMAPPING_MISSING_CONFIGURATION + ); + return false; + } + + isConsistent = true; + } - if ( !enumTransformationStrategies.containsKey( strategy ) ) { - String registeredStrategies = Strings.join( enumTransformationStrategies.keySet(), ", " ); + isConsistent = isConsistent || gem.unexpectedValueMappingException().hasValue(); + + if ( !isConsistent ) { messager.printMessage( method, gem.mirror(), - gem.nameTransformationStrategy().getAnnotationValue(), - ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY, - strategy, - registeredStrategies + ENUMMAPPING_NO_ELEMENTS ); - - return false; } - return true; + return isConsistent; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index ef25fda053..07f668e655 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -7,6 +7,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -137,6 +138,13 @@ public MappingControl getMappingControl(Elements elementUtils) { next().getMappingControl( elementUtils ); } + @Override + public TypeMirror getUnexpectedValueMappingException() { + return mapperConfig.unexpectedValueMappingException().hasValue() ? + mapperConfig.unexpectedValueMappingException().get() : + next().getUnexpectedValueMappingException(); + } + @Override public boolean hasAnnotation() { return mapperConfig != null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 19b7d8f0b4..b054c628a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -11,6 +11,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.option.Options; @@ -167,6 +168,13 @@ public MappingControl getMappingControl(Elements elementUtils) { next().getMappingControl( elementUtils ); } + @Override + public TypeMirror getUnexpectedValueMappingException() { + return mapper.unexpectedValueMappingException().hasValue() ? + mapper.unexpectedValueMappingException().get() : + next().getUnexpectedValueMappingException(); + } + // @Mapper specific public DeclaredType mapperConfigType() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index f8f7eee5bc..1514f4f5e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -26,7 +26,7 @@ import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.workarounds.TypesDecorator; import org.mapstruct.ap.internal.version.VersionInformation; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; /** @@ -101,8 +101,8 @@ public Map getEnumTransformationStrategies() } @Override - public EnumNamingStrategy getEnumNamingStrategy() { - return roundContext.getAnnotationProcessorContext().getEnumNamingStrategy(); + public EnumMappingStrategy getEnumMappingStrategy() { + return roundContext.getAnnotationProcessorContext().getEnumMappingStrategy(); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index adb0b8f24f..58c6f2513a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -101,7 +101,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L typeUtils, messager, accessorNaming, - context.getEnumNamingStrategy(), + context.getEnumMappingStrategy(), context.getEnumTransformationStrategies(), options, new MappingResolverImpl( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index 0689af54a5..ac0a161a28 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -17,7 +17,7 @@ import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.version.VersionInformation; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; /** @@ -56,7 +56,7 @@ public interface ProcessorContext { Map getEnumTransformationStrategies(); - EnumNamingStrategy getEnumNamingStrategy(); + EnumMappingStrategy getEnumMappingStrategy(); Options getOptions(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 4b70bd60ad..86fb7e3092 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -24,8 +24,8 @@ import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.DefaultAccessorNamingStrategy; import org.mapstruct.ap.spi.DefaultBuilderProvider; -import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.DefaultEnumMappingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.FreeBuilderAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; @@ -43,7 +43,7 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private BuilderProvider builderProvider; private AccessorNamingStrategy accessorNamingStrategy; - private EnumNamingStrategy enumNamingStrategy; + private EnumMappingStrategy enumMappingStrategy; private boolean initialized; private Map enumTransformationStrategies; @@ -113,13 +113,13 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! } this.accessorNaming = new AccessorNamingUtils( this.accessorNamingStrategy ); - this.enumNamingStrategy = Services.get( EnumNamingStrategy.class, new DefaultEnumNamingStrategy() ); - this.enumNamingStrategy.init( this ); + this.enumMappingStrategy = Services.get( EnumMappingStrategy.class, new DefaultEnumMappingStrategy() ); + this.enumMappingStrategy.init( this ); if ( verbose ) { messager.printMessage( Diagnostic.Kind.NOTE, "MapStruct: Using enum naming strategy: " - + this.enumNamingStrategy.getClass().getCanonicalName() + + this.enumMappingStrategy.getClass().getCanonicalName() ); } @@ -250,9 +250,9 @@ public AccessorNamingStrategy getAccessorNamingStrategy() { return accessorNamingStrategy; } - public EnumNamingStrategy getEnumNamingStrategy() { + public EnumMappingStrategy getEnumMappingStrategy() { initialize(); - return enumNamingStrategy; + return enumMappingStrategy; } public BuilderProvider getBuilderProvider() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 6f0db248bf..87d3a9abdd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -105,6 +105,8 @@ public enum Message { ENUMMAPPING_UNMAPPED_SOURCES( "The following constants from the source enum have no corresponding constant in the target enum and must be be mapped via adding additional mappings: %s." ), ENUMMAPPING_REMOVED( "Mapping of Enums via @Mapping is removed. Please use @ValueMapping instead!" ), ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY( "There is no registered EnumTransformationStrategy for '%s'. Registered strategies are: %s." ), + ENUMMAPPING_MISSING_CONFIGURATION( "Configuration has to be defined when strategy is defined." ), + ENUMMAPPING_NO_ELEMENTS( "'nameTransformationStrategy', 'configuration' and 'unexpectedValueMappingException' are undefined in @EnumMapping, define at least one of them." ), LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), @@ -169,7 +171,7 @@ public enum Message { VALUEMAPPING_UNMAPPED_SOURCES( "The following constants from the %s enum have no corresponding constant in the %s enum and must be be mapped via adding additional mappings: %s." ), VALUEMAPPING_ANY_REMAINING_FOR_NON_ENUM( "Source = \"\" can only be used on targets of type enum and not for %s." ), VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING( "Source = \"\" or \"\" is advisable for mapping of type String to an enum type.", Diagnostic.Kind.WARNING ), - VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI( "Constant %s doesn't exist in enum type %s. Constant was returned from EnumNamingStrategy: %s"), + VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI( "Constant %s doesn't exist in enum type %s. Constant was returned from EnumMappingStrategy: %s"), VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); // CHECKSTYLE:ON diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 07049c17ad..f1eca88156 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -129,6 +129,10 @@ public static boolean isEmpty(String string) { return string == null || string.isEmpty(); } + public static boolean isNotEmpty(String string) { + return !isEmpty( string ); + } + public static String getSafeVariableName(String name, String... existingVariableNames) { return getSafeVariableName( name, Arrays.asList( existingVariableNames ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java similarity index 68% rename from processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java rename to processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java index a54df7bc06..62d6c32809 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java @@ -14,7 +14,7 @@ * * @since 1.4 */ -public class DefaultEnumNamingStrategy implements EnumNamingStrategy { +public class DefaultEnumMappingStrategy implements EnumMappingStrategy { protected Elements elementUtils; protected Types typeUtils; @@ -34,4 +34,13 @@ public String getDefaultNullEnumConstant(TypeElement enumType) { public String getEnumConstant(TypeElement enumType, String enumConstant) { return enumConstant; } + + @Override + public TypeElement getUnexpectedValueMappingExceptionType() { + return elementUtils.getTypeElement( getUnexpectedValueMappingExceptionClass().getCanonicalName() ); + } + + protected Class getUnexpectedValueMappingExceptionClass() { + return IllegalArgumentException.class; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java similarity index 80% rename from processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java rename to processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java index a2361eefd0..97088cd8c6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/EnumNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java @@ -13,11 +13,12 @@ * A service provider interface for the mapping between different enum constants * * @author Arne Seime + * @author Filip Hrisafov * * @since 1.4 */ @Experimental("This SPI can have it's signature changed in subsequent releases") -public interface EnumNamingStrategy { +public interface EnumMappingStrategy { /** * Initializes the enum value mapping strategy @@ -47,4 +48,12 @@ default void init(MapStructProcessingEnvironment processingEnvironment) { * never return null */ String getEnumConstant(TypeElement enumType, String enumConstant); + + /** + * Return the type element of the exception that should be used in the generated code + * for an unexpected enum constant. + * + * @return the type element of the exception that should be used, never {@code null} + */ + TypeElement getUnexpectedValueMappingExceptionType(); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index ba16d56a2d..530d5643e1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -25,7 +25,7 @@ case <@writeSource source=valueMapping.source/>: ${resultName} = <@writeTarget target=valueMapping.target/>; break; - default: <#if throwIllegalArgumentException>throw new IllegalArgumentException( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget/>; + default: <#if unexpectedValueMappingException??>throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget/>; } <#list beforeMappingReferencesWithMappingTarget as callback> <#if callback_index = 0> @@ -40,7 +40,7 @@ <@includeModel object=callback targetBeanName=resultName targetType=resultType/> - <#if !(valueMappings.empty && throwIllegalArgumentException)> + <#if !(valueMappings.empty && unexpectedValueMappingException??)> return ${resultName}; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/CustomIllegalArgumentException.java b/processor/src/test/java/org/mapstruct/ap/test/value/CustomIllegalArgumentException.java new file mode 100644 index 0000000000..e5552d798a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/CustomIllegalArgumentException.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value; + +/** + * @author Filip Hrisafov + */ +public class CustomIllegalArgumentException extends RuntimeException { + + public CustomIllegalArgumentException(String message) { + super( message ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/EmptyEnumMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/EmptyEnumMappingMapper.java new file mode 100644 index 0000000000..e0f2f112db --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/EmptyEnumMappingMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.erroneous; + +import org.mapstruct.EnumMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface EmptyEnumMappingMapper { + + @EnumMapping + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java new file mode 100644 index 0000000000..45d374f217 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.erroneous; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2169") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + CustomIllegalArgumentException.class, + ExternalOrderType.class, + OrderType.class, +}) +public class ErroneousEnumMappingTest { + + @Test + @WithClasses({ + EmptyEnumMappingMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = EmptyEnumMappingMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "'nameTransformationStrategy', 'configuration' and 'unexpectedValueMappingException' are " + + "undefined in @EnumMapping, define at least one of them." + ) + } + ) + public void shouldCompileErrorWhenEnumMappingIsEmpty() { + } + + @Test + @WithClasses({ + NoConfigurationEnumMappingMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = NoConfigurationEnumMappingMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 21, + message = "Configuration has to be defined when strategy is defined.") + } + ) + public void shouldCompileErrorWhenEnumMappingHasStrategyButNoConfiguration() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/NoConfigurationEnumMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/NoConfigurationEnumMappingMapper.java new file mode 100644 index 0000000000..9d82ed059d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/NoConfigurationEnumMappingMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.erroneous; + +import org.mapstruct.EnumMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface NoConfigurationEnumMappingMapper { + + @EnumMapping(nameTransformationStrategy = MappingConstants.PREFIX_TRANSFORMATION) + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/Config.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/Config.java new file mode 100644 index 0000000000..627ac79700 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/Config.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.mapstruct.MapperConfig; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(unexpectedValueMappingException = CustomIllegalArgumentException.class) +public interface Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapper.java new file mode 100644 index 0000000000..6fc94fb8a8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper(unexpectedValueMappingException = CustomIllegalArgumentException.class) +public interface CustomUnexpectedValueMappingExceptionDefinedInMapper { + + @ValueMapping(source = MappingConstants.ANY_UNMAPPED, target = "DEFAULT") + ExternalOrderType withAnyUnmapped(OrderType orderType); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "DEFAULT") + ExternalOrderType withAnyRemaining(OrderType orderType); + + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); + + @InheritInverseConfiguration(name = "onlyWithMappings") + OrderType inverseOnlyWithMappings(ExternalOrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.java new file mode 100644 index 0000000000..c5396ad480 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper(unexpectedValueMappingException = CustomIllegalArgumentException.class) +public interface CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping { + + @ValueMapping(source = MappingConstants.ANY_UNMAPPED, target = "DEFAULT") + ExternalOrderType withAnyUnmapped(OrderType orderType); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "DEFAULT") + ExternalOrderType withAnyRemaining(OrderType orderType); + + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); + + // If unexpectedValueMappingException is explicitly defined then it should be used instead of what is in the SPI + @EnumMapping(unexpectedValueMappingException = IllegalArgumentException.class) + @InheritInverseConfiguration(name = "onlyWithMappings") + OrderType inverseOnlyWithMappings(ExternalOrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.java new file mode 100644 index 0000000000..3e3d7e2199 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = Config.class) +public interface CustomUnexpectedValueMappingExceptionDefinedInMapperConfig { + + @ValueMapping(source = MappingConstants.ANY_UNMAPPED, target = "DEFAULT") + ExternalOrderType withAnyUnmapped(OrderType orderType); + + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "DEFAULT") + ExternalOrderType withAnyRemaining(OrderType orderType); + + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); + + @InheritInverseConfiguration(name = "onlyWithMappings") + OrderType inverseOnlyWithMappings(ExternalOrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapper.java new file mode 100644 index 0000000000..96c8b297c6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomUnexpectedValueMappingExceptionMapper { + + @EnumMapping(unexpectedValueMappingException = CustomIllegalArgumentException.class) + @ValueMapping( source = MappingConstants.ANY_UNMAPPED, target = "DEFAULT" ) + ExternalOrderType withAnyUnmapped(OrderType orderType); + + @EnumMapping(unexpectedValueMappingException = CustomIllegalArgumentException.class) + @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "DEFAULT" ) + ExternalOrderType withAnyRemaining(OrderType orderType); + + @EnumMapping(unexpectedValueMappingException = CustomIllegalArgumentException.class) + @ValueMapping(source = "EXTRA", target = "SPECIAL") + @ValueMapping(source = "STANDARD", target = "DEFAULT") + @ValueMapping(source = "NORMAL", target = "DEFAULT") + ExternalOrderType onlyWithMappings(OrderType orderType); + + @InheritInverseConfiguration(name = "onlyWithMappings") + OrderType inverseOnlyWithMappings(ExternalOrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java new file mode 100644 index 0000000000..fbbf702854 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2169") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Config.class, + CustomUnexpectedValueMappingExceptionDefinedInMapper.class, + CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.class, + CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.class, + CustomUnexpectedValueMappingExceptionMapper.class, + CustomIllegalArgumentException.class, + ExternalOrderType.class, + OrderType.class +}) +public class CustomUnexpectedValueMappingExceptionTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + public void shouldGenerateCustomUnexpectedValueMappingException() { + generatedSource.addComparisonToFixtureFor( + CustomUnexpectedValueMappingExceptionDefinedInMapper.class, + CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping.class, + CustomUnexpectedValueMappingExceptionDefinedInMapperConfig.class, + CustomUnexpectedValueMappingExceptionMapper.class + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java index 6524f67c36..b042405c43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomCheeseMapper.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.value.spi; +import org.mapstruct.EnumMapping; import org.mapstruct.Mapper; import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; @@ -24,6 +25,8 @@ public interface CustomCheeseMapper { String mapToString(CustomCheeseType cheeseType); + // If unexpectedValueMappingException is explicitly defined then it should be used instead of what is in the SPI + @EnumMapping(unexpectedValueMappingException = IllegalArgumentException.class) String mapToString(CheeseType cheeseType); @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "CUSTOM_BRIE") diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java similarity index 77% rename from processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java rename to processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java index f84ebaf7b3..b505dd640b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java @@ -9,13 +9,14 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.gem.MappingConstantsGem; -import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.DefaultEnumMappingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; /** * @author Filip Hrisafov */ -public class CustomEnumNamingStrategy extends DefaultEnumNamingStrategy implements EnumNamingStrategy { +public class CustomEnumMappingStrategy extends DefaultEnumMappingStrategy implements EnumMappingStrategy { @Override public String getDefaultNullEnumConstant(TypeElement enumType) { @@ -51,4 +52,9 @@ protected boolean isCustomEnum(TypeElement enumType) { return false; } + + @Override + protected Class getUnexpectedValueMappingExceptionClass() { + return CustomIllegalArgumentException.class; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java similarity index 94% rename from processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java rename to processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java index 47a0a5d64e..9cce52d7bd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumNamingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java @@ -8,6 +8,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @@ -23,9 +24,10 @@ CheeseType.class, CustomCheeseType.class, CustomEnumMarker.class, + CustomIllegalArgumentException.class, }) -@WithServiceImplementation(CustomEnumNamingStrategy.class) -public class CustomEnumNamingStrategyTest { +@WithServiceImplementation(CustomEnumMappingStrategy.class) +public class CustomEnumMappingStrategyTest { @Rule public final GeneratedSource generatedSource = new GeneratedSource(); @@ -34,7 +36,7 @@ public class CustomEnumNamingStrategyTest { @WithClasses({ CustomCheeseMapper.class }) - public void shouldApplyCustomEnumNamingStrategy() { + public void shouldApplyCustomEnumMappingStrategy() { generatedSource.addComparisonToFixtureFor( CustomCheeseMapper.class ); CustomCheeseMapper mapper = CustomCheeseMapper.INSTANCE; @@ -80,7 +82,7 @@ public void shouldApplyCustomEnumNamingStrategy() { @WithClasses({ OverridesCustomCheeseMapper.class }) - public void shouldApplyDefinedMappingsInsteadOfCustomEnumNamingStrategy() { + public void shouldApplyDefinedMappingsInsteadOfCustomEnumMappingStrategy() { OverridesCustomCheeseMapper mapper = OverridesCustomCheeseMapper.INSTANCE; // CheeseType -> CustomCheeseType diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategy.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java rename to processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategy.java index 671ad45c04..8a4f2b5bd9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategy.java @@ -9,13 +9,13 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.gem.MappingConstantsGem; -import org.mapstruct.ap.spi.DefaultEnumNamingStrategy; -import org.mapstruct.ap.spi.EnumNamingStrategy; +import org.mapstruct.ap.spi.DefaultEnumMappingStrategy; +import org.mapstruct.ap.spi.EnumMappingStrategy; /** * @author Filip Hrisafov */ -public class CustomErroneousEnumNamingStrategy extends DefaultEnumNamingStrategy implements EnumNamingStrategy { +public class CustomErroneousEnumMappingStrategy extends DefaultEnumMappingStrategy implements EnumMappingStrategy { @Override public String getDefaultNullEnumConstant(TypeElement enumType) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java similarity index 90% rename from processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java rename to processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java index 82d6be4c26..9cb1337bc8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumNamingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java @@ -25,8 +25,8 @@ CustomCheeseType.class, CustomEnumMarker.class, }) -@WithServiceImplementation(CustomErroneousEnumNamingStrategy.class) -public class CustomErroneousEnumNamingStrategyTest { +@WithServiceImplementation(CustomErroneousEnumMappingStrategy.class) +public class CustomErroneousEnumMappingStrategyTest { @Test @WithClasses({ @@ -37,18 +37,18 @@ public class CustomErroneousEnumNamingStrategyTest { @Diagnostic( type = CustomCheeseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 23, + line = 24, messageRegExp = "Constant INCORRECT doesn't exist in enum type " + "org\\.mapstruct\\.ap\\.test\\.value\\.spi\\.CustomCheeseType." + - " Constant was returned from EnumNamingStrategy: .*CustomErroneousEnumNamingStrategy@.*" + " Constant was returned from EnumMappingStrategy: .*CustomErroneousEnumMappingStrategy@.*" ), @Diagnostic( type = CustomCheeseMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 30, + line = 33, messageRegExp = "Constant INCORRECT doesn't exist in enum type " + "org\\.mapstruct\\.ap\\.test\\.value\\.spi\\.CustomCheeseType." + - " Constant was returned from EnumNamingStrategy: .*CustomErroneousEnumNamingStrategy@.*" + " Constant was returned from EnumMappingStrategy: .*CustomErroneousEnumMappingStrategy@.*" ) } ) @@ -59,7 +59,7 @@ public void shouldThrowCompileErrorWhenDefaultEnumDoesNotExist() { @WithClasses({ OverridesCustomCheeseMapper.class }) - public void shouldApplyDefinedMappingsInsteadOfCustomEnumNamingStrategy() { + public void shouldApplyDefinedMappingsInsteadOfCustomEnumMappingStrategy() { OverridesCustomCheeseMapper mapper = OverridesCustomCheeseMapper.INSTANCE; // CheeseType -> CustomCheeseType diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMappingImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMappingImpl.java new file mode 100644 index 0000000000..f0ae6eecd3 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMappingImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-08-29T09:36:57+0200", + comments = "version: , compiler: javac, environment: Java 11.0.2 (AdoptOpenJDK)" +) +public class CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMappingImpl implements CustomUnexpectedValueMappingExceptionDefinedInMapperAndEnumMapping { + + @Override + public ExternalOrderType withAnyUnmapped(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType withAnyRemaining(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType onlyWithMappings(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case EXTRA: externalOrderType = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } + + @Override + public OrderType inverseOnlyWithMappings(ExternalOrderType orderType) { + if ( orderType == null ) { + return null; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = OrderType.STANDARD; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfigImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfigImpl.java new file mode 100644 index 0000000000..fee7a2bb1e --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperConfigImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-08-29T09:36:57+0200", + comments = "version: , compiler: javac, environment: Java 11.0.2 (AdoptOpenJDK)" +) +public class CustomUnexpectedValueMappingExceptionDefinedInMapperConfigImpl implements CustomUnexpectedValueMappingExceptionDefinedInMapperConfig { + + @Override + public ExternalOrderType withAnyUnmapped(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType withAnyRemaining(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType onlyWithMappings(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case EXTRA: externalOrderType = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } + + @Override + public OrderType inverseOnlyWithMappings(ExternalOrderType orderType) { + if ( orderType == null ) { + return null; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = OrderType.STANDARD; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperImpl.java new file mode 100644 index 0000000000..a897339181 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionDefinedInMapperImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-08-29T09:36:57+0200", + comments = "version: , compiler: javac, environment: Java 11.0.2 (AdoptOpenJDK)" +) +public class CustomUnexpectedValueMappingExceptionDefinedInMapperImpl implements CustomUnexpectedValueMappingExceptionDefinedInMapper { + + @Override + public ExternalOrderType withAnyUnmapped(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType withAnyRemaining(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType onlyWithMappings(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case EXTRA: externalOrderType = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } + + @Override + public OrderType inverseOnlyWithMappings(ExternalOrderType orderType) { + if ( orderType == null ) { + return null; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = OrderType.STANDARD; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapperImpl.java new file mode 100644 index 0000000000..c22ff08f60 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionMapperImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.exception; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-08-02T09:36:57+0200", + comments = "version: , compiler: javac, environment: Java 11.0.2 (AdoptOpenJDK)" +) +public class CustomUnexpectedValueMappingExceptionMapperImpl implements CustomUnexpectedValueMappingExceptionMapper { + + @Override + public ExternalOrderType withAnyUnmapped(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType withAnyRemaining(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: externalOrderType = ExternalOrderType.DEFAULT; + } + + return externalOrderType; + } + + @Override + public ExternalOrderType onlyWithMappings(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case EXTRA: externalOrderType = ExternalOrderType.SPECIAL; + break; + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case NORMAL: externalOrderType = ExternalOrderType.DEFAULT; + break; + case RETAIL: externalOrderType = ExternalOrderType.RETAIL; + break; + case B2B: externalOrderType = ExternalOrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } + + @Override + public OrderType inverseOnlyWithMappings(ExternalOrderType orderType) { + if ( orderType == null ) { + return null; + } + + OrderType orderType1; + + switch ( orderType ) { + case SPECIAL: orderType1 = OrderType.EXTRA; + break; + case DEFAULT: orderType1 = OrderType.STANDARD; + break; + case RETAIL: orderType1 = OrderType.RETAIL; + break; + case B2B: orderType1 = OrderType.B2B; + break; + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return orderType1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java index 9798c41597..b2ba34a328 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/spi/CustomCheeseMapperImpl.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.value.spi; import javax.annotation.processing.Generated; +import org.mapstruct.ap.test.value.CustomIllegalArgumentException; @Generated( value = "org.mapstruct.ap.MappingProcessor", @@ -31,7 +32,7 @@ public CheeseType map(CustomCheeseType cheese) { break; case UNRECOGNIZED: cheeseType = null; break; - default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + cheese ); } return cheeseType; @@ -50,7 +51,7 @@ public CustomCheeseType map(CheeseType cheese) { break; case ROQUEFORT: customCheeseType = CustomCheeseType.CUSTOM_ROQUEFORT; break; - default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheese ); + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + cheese ); } return customCheeseType; @@ -73,7 +74,7 @@ public String mapToString(CustomCheeseType cheeseType) { break; case UNRECOGNIZED: string = null; break; - default: throw new IllegalArgumentException( "Unexpected enum constant: " + cheeseType ); + default: throw new CustomIllegalArgumentException( "Unexpected enum constant: " + cheeseType ); } return string; From e0eb0f6bb85970e534ebc4a5ea99c85c23bcf8be Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 30 Aug 2020 12:49:09 +0200 Subject: [PATCH 0502/1006] #2164 parameter matching should be done based on name when source name is absent (#2193) --- .../ap/internal/model/BeanMappingMethod.java | 29 ++++++++++---- .../ap/test/bugs/_2164/Issue2164Mapper.java | 40 +++++++++++++++++++ .../ap/test/bugs/_2164/Issue2164Test.java | 31 ++++++++++++++ 3 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d6f06b49e6..a0ea064f1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1068,10 +1068,23 @@ else if ( mapping.getJavaExpression() != null ) { // its a plain-old property mapping else { - // determine source parameter SourceReference sourceRef = mappingRef.getSourceReference(); + // sourceRef is not defined, check if a source property has the same name if ( sourceRef == null && method.getSourceParameters().size() == 1 ) { - sourceRef = getSourceRef( method.getSourceParameters().get( 0 ), targetPropertyName ); + sourceRef = getSourceRefByTargetName( method.getSourceParameters().get( 0 ), targetPropertyName ); + } + + if ( sourceRef == null ) { + // still no match. Try if one of the parameters has the same name + sourceRef = method.getSourceParameters() + .stream() + .filter( p -> targetPropertyName.equals( p.getName() ) ) + .findAny() + .map( p -> new SourceReference.BuilderFromProperty() + .sourceParameter( p ) + .name( targetPropertyName ) + .build() ) + .orElse( null ); } if ( sourceRef != null ) { @@ -1153,7 +1166,7 @@ private void applyPropertyNameBasedMapping() { List sourceReferences = new ArrayList<>(); for ( String targetPropertyName : unprocessedTargetProperties.keySet() ) { for ( Parameter sourceParameter : method.getSourceParameters() ) { - SourceReference sourceRef = getSourceRef( sourceParameter, targetPropertyName ); + SourceReference sourceRef = getSourceRefByTargetName( sourceParameter, targetPropertyName ); if ( sourceRef != null ) { sourceReferences.add( sourceRef ); } @@ -1251,7 +1264,7 @@ private void applyParameterNameBasedMapping() { } } - private SourceReference getSourceRef(Parameter sourceParameter, String targetPropertyName) { + private SourceReference getSourceRefByTargetName(Parameter sourceParameter, String targetPropertyName) { SourceReference sourceRef = null; @@ -1261,11 +1274,11 @@ private SourceReference getSourceRef(Parameter sourceParameter, String targetPro Accessor sourceReadAccessor = sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); - - Accessor sourcePresenceChecker = - sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); - if ( sourceReadAccessor != null ) { + // property mapping + Accessor sourcePresenceChecker = + sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); + DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); Type returnType = ctx.getTypeFactory().getReturnType( declaredSourceType, sourceReadAccessor ); sourceRef = new SourceReference.BuilderFromProperty().sourceParameter( sourceParameter ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Mapper.java new file mode 100644 index 0000000000..7d152e88c1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Mapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2164; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2164Mapper { + + Issue2164Mapper INSTANCE = Mappers.getMapper( Issue2164Mapper.class ); + + @Mapping(target = "value", qualifiedByName = "truncate2") + Target map(BigDecimal value); + + @Named( "truncate2" ) + default String truncate2(String in) { + return in.substring( 0, 2 ); + } + + class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java new file mode 100644 index 0000000000..3ed5cf1654 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2164; + +import java.math.BigDecimal; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2164") +@WithClasses(Issue2164Mapper.class) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2164Test { + + @Test + public void shouldSelectProperMethod() { + + Issue2164Mapper.Target target = Issue2164Mapper.INSTANCE.map( new BigDecimal( "1234" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "12" ); + } +} From c96296254641c503c79b75834300cb4b2ba366ad Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 30 Aug 2020 16:31:44 +0200 Subject: [PATCH 0503/1006] [maven-release-plugin] prepare release 1.4.0.CR1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c908377c8..55926697b2 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 63311b5950..4e8a37fc77 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c74e0b8bb1..c128f1449d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b404ed3cee..bface19897 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ceb3cb1db6..ab9098fb10 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a643bab4b8..e7a98ec35f 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b26cf8683d..28c895e9a4 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.CR1 diff --git a/pom.xml b/pom.xml index f9c649c168..25a602f932 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.CR1 diff --git a/processor/pom.xml b/processor/pom.xml index c047301268..5b704cc379 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.CR1 ../parent/pom.xml From 8b22654abdfb005381124800ebc155af2de3c312 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 30 Aug 2020 16:31:45 +0200 Subject: [PATCH 0504/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 55926697b2..6c908377c8 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 4e8a37fc77..63311b5950 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c128f1449d..c74e0b8bb1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index bface19897..b404ed3cee 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ab9098fb10..ceb3cb1db6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index e7a98ec35f..a643bab4b8 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 28c895e9a4..b26cf8683d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.CR1 + HEAD diff --git a/pom.xml b/pom.xml index 25a602f932..f9c649c168 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.CR1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 5b704cc379..c047301268 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.CR1 + 1.4.0-SNAPSHOT ../parent/pom.xml From 427f5023efec6f6a91fd8946bb2b6e86a1ed2a19 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 6 Sep 2020 16:12:01 +0200 Subject: [PATCH 0505/1006] #2195 @Beanmapping#resultType should be used to construct return type also if it's a builder (#2196) --- .../ap/internal/model/BeanMappingMethod.java | 30 +++++++------- .../processor/MapperCreationProcessor.java | 13 +++++- .../ap/test/bugs/_2195/Issue2195Mapper.java | 23 +++++++++++ .../ap/test/bugs/_2195/Issue2195Test.java | 35 ++++++++++++++++ .../ap/test/bugs/_2195/dto/Source.java | 18 +++++++++ .../ap/test/bugs/_2195/dto/Target.java | 31 ++++++++++++++ .../ap/test/bugs/_2195/dto/TargetBase.java | 40 +++++++++++++++++++ 7 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/TargetBase.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index a0ea064f1f..c2434da51d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -87,6 +87,7 @@ public static class Builder { private MappingBuilderContext ctx; private Method method; + private Type userDefinedReturnType; /* returnType to construct can have a builder */ private BuilderType returnTypeBuilder; @@ -108,6 +109,11 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { return this; } + public Builder userDefinedReturnType(Type userDefinedReturnType) { + this.userDefinedReturnType = userDefinedReturnType; + return this; + } + public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { this.returnTypeBuilder = returnTypeBuilder; return this; @@ -148,20 +154,22 @@ public BeanMappingMethod build() { // determine which return type to construct boolean cannotConstructReturnType = false; if ( !method.getReturnType().isVoid() ) { - Type returnTypeImpl = getReturnTypeToConstructFromSelectionParameters( selectionParameters ); - if ( returnTypeImpl != null ) { + Type returnTypeImpl = null; + if ( isBuilderRequired() ) { + // the userDefinedReturn type can also require a builder. That buildertype is already set + returnTypeImpl = returnTypeBuilder.getBuilder(); initializeFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } else { cannotConstructReturnType = true; } } - else if ( isBuilderRequired() ) { - returnTypeImpl = returnTypeBuilder.getBuilder(); + else if ( userDefinedReturnType != null ) { + returnTypeImpl = userDefinedReturnType; initializeFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } else { @@ -482,16 +490,6 @@ private void sortPropertyMappingsByDependencies() { } } - private Type getReturnTypeToConstructFromSelectionParameters(SelectionParameters selectionParams) { - // resultType only applies to method that actually has @BeanMapping annotation, never to forged methods - if ( !( method instanceof ForgedMethod ) - && selectionParams != null - && selectionParams.getResultType() != null ) { - return ctx.getTypeFactory().getType( selectionParams.getResultType() ); - } - return null; - } - private boolean canResultTypeFromBeanMappingBeConstructed(Type resultType) { boolean error = true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 58c6f2513a..25632350be 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -367,11 +367,14 @@ else if ( method.isStreamMapping() ) { else { this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + Type userDefinedReturnType = getUserDesiredReturnType( method ); + Type builderBaseType = userDefinedReturnType != null ? userDefinedReturnType : method.getReturnType(); BeanMappingMethod.Builder beanMappingBuilder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = beanMappingBuilder .mappingContext( mappingContext ) .sourceMethod( method ) - .returnTypeBuilder( typeFactory.builderTypeFor( method.getReturnType(), builder ) ) + .userDefinedReturnType( userDefinedReturnType ) + .returnTypeBuilder( typeFactory.builderTypeFor( builderBaseType, builder ) ) .build(); // We can consider that the bean mapping method can always be constructed. If there is a problem @@ -392,6 +395,14 @@ else if ( method.isStreamMapping() ) { return mappingMethods; } + private Type getUserDesiredReturnType(SourceMethod method) { + SelectionParameters selectionParameters = method.getOptions().getBeanMapping().getSelectionParameters(); + if ( selectionParameters != null && selectionParameters.getResultType() != null ) { + return typeFactory.getType( selectionParameters.getResultType() ); + } + return null; + } + private M createWithElementMappingMethod(SourceMethod method, MappingMethodOptions mappingMethodOptions, ContainerMappingMethodBuilder builder) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Mapper.java new file mode 100644 index 0000000000..cde09dd2e3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Mapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2195; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2195.dto.Source; +import org.mapstruct.ap.test.bugs._2195.dto.Target; +import org.mapstruct.ap.test.bugs._2195.dto.TargetBase; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2195Mapper { + + Issue2195Mapper INSTANCE = Mappers.getMapper( Issue2195Mapper.class ); + + @BeanMapping( resultType = Target.class ) + TargetBase map(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java new file mode 100644 index 0000000000..8d8a754d7f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2195; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._2195.dto.Source; +import org.mapstruct.ap.test.bugs._2195.dto.Target; +import org.mapstruct.ap.test.bugs._2195.dto.TargetBase; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2195") +@WithClasses( { Source.class, Target.class, TargetBase.class } ) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2195Test { + + @Test + @WithClasses( Issue2195Mapper.class ) + public void test() { + + Source source = new Source(); + source.setName( "JohnDoe" ); + + TargetBase target = Issue2195Mapper.INSTANCE.map( source ); + + assertThat( target ).isInstanceOf( Target.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Source.java new file mode 100644 index 0000000000..78a4bba1a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Source.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2195.dto; + +public class Source { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Target.java new file mode 100644 index 0000000000..8a74d44104 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/Target.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2195.dto; + +public class Target extends TargetBase { + + protected Target(Builder builder) { + super( builder ); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends TargetBase.Builder { + + protected Builder() { + } + + public Target build() { + return new Target( this ); + } + + public Builder name(String name) { + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/TargetBase.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/TargetBase.java new file mode 100644 index 0000000000..ffb2eff2bc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/dto/TargetBase.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2195.dto; + +public class TargetBase { + + private final String name; + + protected TargetBase(Builder builder) { + this.name = builder.name; + } + + public static Builder builder() { + return new Builder(); + } + + public String getName() { + return name; + } + + public static class Builder { + + protected Builder() { + } + + private String name; + + public TargetBase build() { + return new TargetBase( this ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + } +} From 52ab22bbd87c89610e913ecf6b4a891475846d33 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 19 Sep 2020 09:54:55 +0200 Subject: [PATCH 0506/1006] #2197 Strip leading underscores and digits when sanitizing identifier name --- .../mapstruct/ap/internal/util/Strings.java | 13 +++--- .../ap/internal/util/StringsTest.java | 11 +++++ .../ap/test/bugs/_2197/Issue2197Mapper.java | 46 +++++++++++++++++++ .../ap/test/bugs/_2197/Issue2197Test.java | 34 ++++++++++++++ .../test/bugs/_2197/Issue2197MapperImpl.java | 31 +++++++++++++ 5 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2197/Issue2197MapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index f1eca88156..42727ed816 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -174,15 +174,16 @@ public static String getSafeVariableName(String name, Collection existin public static String sanitizeIdentifierName(String identifier) { if ( identifier != null && identifier.length() > 0 ) { - int firstNonUnderScoreIndex = 0; - while ( firstNonUnderScoreIndex < identifier.length() && - identifier.charAt( firstNonUnderScoreIndex ) == UNDERSCORE ) { - firstNonUnderScoreIndex++; + int firstAlphabeticIndex = 0; + while ( firstAlphabeticIndex < identifier.length() && + ( identifier.charAt( firstAlphabeticIndex ) == UNDERSCORE || + Character.isDigit( identifier.charAt( firstAlphabeticIndex ) ) ) ) { + firstAlphabeticIndex++; } - if ( firstNonUnderScoreIndex < identifier.length()) { + if ( firstAlphabeticIndex < identifier.length()) { // If it is not consisted of only underscores - return identifier.substring( firstNonUnderScoreIndex ).replace( "[]", "Array" ); + return identifier.substring( firstAlphabeticIndex ).replace( "[]", "Array" ); } return identifier.replace( "[]", "Array" ); diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index e0eb961d10..9d6dc88655 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -85,6 +85,8 @@ public void testGetSaveVariableNameWithArrayExistingVariables() { assertThat( Strings.getSafeVariableName( "prop", "prop", "prop_" ) ).isEqualTo( "prop1" ); assertThat( Strings.getSafeVariableName( "_Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "__Test" ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "_0Test" ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "_0123Test" ) ).isEqualTo( "test" ); } @Test @@ -103,6 +105,10 @@ public void testGetSaveVariableNameWithCollection() { assertThat( Strings.getSafeVariableName( "_Test", new ArrayList<>() ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "__Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); assertThat( Strings.getSafeVariableName( "___", new ArrayList<>() ) ).isEqualTo( "___" ); + assertThat( Strings.getSafeVariableName( "_0Test", new ArrayList<>() ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "__0Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); + assertThat( Strings.getSafeVariableName( "___0", new ArrayList<>() ) ).isEqualTo( "___0" ); + assertThat( Strings.getSafeVariableName( "__0123456789Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); } @Test @@ -114,6 +120,11 @@ public void testSanitizeIdentifierName() { assertThat( Strings.sanitizeIdentifierName( "__int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "test_" ) ).isEqualTo( "test_" ); assertThat( Strings.sanitizeIdentifierName( "___" ) ).isEqualTo( "___" ); + assertThat( Strings.sanitizeIdentifierName( "_0Test" ) ).isEqualTo( "Test" ); + assertThat( Strings.sanitizeIdentifierName( "_0123456789Test" ) ).isEqualTo( "Test" ); + assertThat( Strings.sanitizeIdentifierName( "_0int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.sanitizeIdentifierName( "__0int[]" ) ).isEqualTo( "intArray" ); + assertThat( Strings.sanitizeIdentifierName( "___0" ) ).isEqualTo( "___0" ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Mapper.java new file mode 100644 index 0000000000..def6f8f601 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Mapper.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2197; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2197Mapper { + + Issue2197Mapper INSTANCE = Mappers.getMapper( Issue2197Mapper.class ); + + _0Target map(Source source); + + // CHECKSTYLE:OFF + class _0Target { + // CHECKSTYLE:ON + private final String value; + + public _0Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java new file mode 100644 index 0000000000..52be67564c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2197; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2197") +@WithClasses(Issue2197Mapper.class) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2197Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( Issue2197Mapper.class ); + + @Test + public void underscoreAndDigitPrefixShouldBeStrippedFromGeneratedLocalVariables() { + Issue2197Mapper._0Target target = Issue2197Mapper.INSTANCE.map( new Issue2197Mapper.Source( "value1" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "value1" ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2197/Issue2197MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2197/Issue2197MapperImpl.java new file mode 100644 index 0000000000..dcf0bd2fed --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2197/Issue2197MapperImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2197; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2019-02-10T09:58:11+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class Issue2197MapperImpl implements Issue2197Mapper { + + @Override + public _0Target map(Source source) { + if ( source == null ) { + return null; + } + + String value = null; + + value = source.getValue(); + + _0Target target = new _0Target( value ); + + return target; + } +} From e17e744b209d8c1d622c628469375c28b3c80d6f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 20 Sep 2020 11:06:33 +0200 Subject: [PATCH 0507/1006] Dependency upgrades Upgrades: * Maven Enforcer Plugin to 3.0.0-M3 * Maven Surefire Plugin to 3.0.0-M5 * Maven Checkstyle Plugin to 3.1.1 * Maven Bundle Plugin to 5.1.1 * Jacoco Maven Plugin to 0.8.6 * Checkstyle to 8.36.1 * JUnit Jipiter to 5.7.0 * AssertJ to 3.17.2 * Guava to 29.0-jre Fix AssertJ breaking changes Use Java 8 or Apache Commons IO instead of Guava where possible Update GitHub Actions to use JDK 14 and JDK 15-ea --- .github/workflows/java-ea.yml | 2 +- .github/workflows/main.yml | 2 +- parent/pom.xml | 19 +++++++++---------- .../ap/test/bugs/_1338/Issue1338Test.java | 6 ++---- .../ap/test/bugs/_1359/Issue1359Test.java | 6 +++--- .../ap/test/bugs/_895/Issue895Test.java | 2 +- .../nestedprop/expanding/FlattenedStock.java | 6 +++--- .../mapstruct/ap/test/collection/Target.java | 9 ++++----- .../StringListMapper.java | 4 +--- .../testutil/assertions/JavaFileAssert.java | 6 ++---- .../testutil/runner/CompilingStatement.java | 8 ++++---- 11 files changed, 31 insertions(+), 39 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index c20151eccd..a5afa065c7 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - java: [15-ea] + java: [16-ea] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d1f65d18f2..08278a1ade 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - java: [11, 13, 14] + java: [11, 13, 15] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: diff --git a/parent/pom.xml b/parent/pom.xml index b26cf8683d..e28caa20b8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -22,17 +22,16 @@ UTF-8 1.0.0.Alpha2 - - 3.0.0-M1 - 3.0.0-M3 + 3.0.0-M3 + 3.0.0-M5 3.1.0 4.0.3.RELEASE 1.6.0 - 8.29 - 5.6.0 + 8.36.1 + 5.7.0 1 - 3.11.1 + 3.17.2 jdt_apt @@ -112,7 +111,7 @@ com.google.guava guava - 19.0 + 29.0-jre org.mapstruct.tools.gem @@ -307,7 +306,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.0 + 3.1.1 build-config/checkstyle.xml true @@ -383,7 +382,7 @@ org.apache.felix maven-bundle-plugin - 4.0.0 + 5.1.1 bundle-manifest @@ -529,7 +528,7 @@ org.jacoco jacoco-maven-plugin - 0.8.5 + 0.8.6 org.jvnet.jaxb2.maven2 diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java index 8274b748ae..83c5212d23 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java @@ -14,7 +14,6 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.atIndex; /** * @author Filip Hrisafov @@ -34,9 +33,8 @@ public void shouldCorrectlyUseAdder() { source.setProperties( Arrays.asList( "first", "second" ) ); Target target = Issue1338Mapper.INSTANCE.map( source ); - assertThat( target ) - .extracting( "properties" ) - .contains( Arrays.asList( "first", "second" ), atIndex( 0 ) ); + assertThat( target.getProperties() ) + .containsExactly( "first", "second" ); Source mapped = Issue1338Mapper.INSTANCE.map( target ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java index 7434afa9fd..aa49cc59fe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java @@ -15,7 +15,7 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.atIndex; +import static org.assertj.core.api.InstanceOfAssertFactories.ITERABLE; /** * @author Filip Hrisafov @@ -33,14 +33,14 @@ public class Issue1359Test { public void shouldCompile() { Target target = new Target(); - assertThat( target ).extracting( "properties" ).contains( null, atIndex( 0 ) ); + assertThat( target ).extracting( "properties" ).isNull(); Set properties = new HashSet<>(); properties.add( "first" ); Source source = new Source( properties ); Issue1359Mapper.INSTANCE.map( target, source ); - assertThat( target ).extracting( "properties" ).contains( properties, atIndex( 0 ) ); + assertThat( target ).extracting( "properties", ITERABLE ).containsExactly( "first" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java index 9de76b43d8..d9f25f5fec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java @@ -32,6 +32,6 @@ public void properlyMapsMultiDimensionalArrays() { assertThat( listOfByteArray.getBytes() ).containsExactly( new byte[] { 0, 1 }, new byte[] { 1, 2 } ); arrayOfByteArray = Mappers.getMapper( MultiArrayMapper.class ).convert( listOfByteArray ); - assertThat( arrayOfByteArray.getBytes() ).containsExactly( new byte[] { 0, 1 }, new byte[] { 1, 2 } ); + assertThat( arrayOfByteArray.getBytes() ).isDeepEqualTo( new byte[][] { { 0, 1 }, { 1, 2 } } ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java index 70cbbb7f84..f7cce1a03f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/FlattenedStock.java @@ -5,7 +5,7 @@ */ package org.mapstruct.ap.test.builder.nestedprop.expanding; -import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.Objects.requireNonNull; public class FlattenedStock { private String article1; @@ -16,8 +16,8 @@ public FlattenedStock() { } public FlattenedStock(String article1, String article2, int count) { - this.article1 = checkNotNull( article1 ); - this.article2 = checkNotNull( article2 ); + this.article1 = requireNonNull( article1 ); + this.article2 = requireNonNull( article2 ); this.count = count; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java index 51a1edddab..2ff6cbfb2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/Target.java @@ -8,14 +8,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - public class Target { //CHECKSTYLE:OFF @@ -54,10 +52,11 @@ public class Target { private StringHolderToLongMap nonGenericMapStringtoLong; public Target() { - otherStringLongMap = Maps.newHashMap(); + otherStringLongMap = new HashMap<>(); otherStringLongMap.put( "not-present-after-mapping", 42L ); - otherStringList = Lists.newArrayList( "not-present-after-mapping" ); + otherStringList = new ArrayList<>(); + otherStringList.add( "not-present-after-mapping" ); } public List getStringList() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java index 1cbe6e128d..93983acf55 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/StringListMapper.java @@ -8,12 +8,10 @@ import java.util.Arrays; import java.util.List; -import com.google.common.base.Joiner; - public class StringListMapper { public String stringListToString(List strings) { - return strings == null ? null : Joiner.on( "-" ).join( strings ); + return strings == null ? null : String.join( "-", strings ); } public List stringToStringList(String string) { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 7a14619b04..2bcfbd94d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.io.FileUtils; import org.assertj.core.api.AbstractCharSequenceAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.FileAssert; @@ -23,9 +24,6 @@ import org.assertj.core.internal.Failures; import org.assertj.core.util.diff.Delta; -import com.google.common.base.Charsets; -import com.google.common.io.Files; - /** * Allows to perform assertions on .java source files. * @@ -58,7 +56,7 @@ public AbstractCharSequenceAssert content() { isFile(); try { - return Assertions.assertThat( Files.toString( actual, Charsets.UTF_8 ) ); + return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) ); } catch ( IOException e ) { failWithMessage( "Unable to read" + actual.toString() + ". Exception: " + e.getMessage() ); diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 59916e9818..3e61d8bd9e 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; @@ -26,6 +27,7 @@ import java.util.stream.Stream; import com.puppycrawl.tools.checkstyle.api.AutomaticBean; +import org.apache.commons.io.output.NullOutputStream; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; import org.mapstruct.ap.testutil.WithClasses; @@ -41,8 +43,6 @@ import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; import org.xml.sax.InputSource; -import com.google.common.collect.Lists; -import com.google.common.io.ByteStreams; import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.ConfigurationLoader; import com.puppycrawl.tools.checkstyle.DefaultLogger; @@ -217,7 +217,7 @@ private void assertCheckstyleRules() throws Exception { ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); checker.addListener( new DefaultLogger( - ByteStreams.nullOutputStream(), + NullOutputStream.NULL_OUTPUT_STREAM, AutomaticBean.OutputStreamOptions.CLOSE, errorStream, AutomaticBean.OutputStreamOptions.CLOSE @@ -234,7 +234,7 @@ private void assertCheckstyleRules() throws Exception { } private static List findGeneratedFiles(File file) { - final List files = Lists.newLinkedList(); + final List files = new LinkedList<>(); if ( file.canRead() ) { if ( file.isDirectory() ) { From 060f17e3e2e6d8ec9cd029d9721af2fa25a4c393 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 20 Sep 2020 12:48:47 +0200 Subject: [PATCH 0508/1006] #2125 Report an error when source parameter could not be determined from target mapping --- .../ap/internal/model/BeanMappingMethod.java | 27 +++++++ .../mapstruct/ap/internal/util/Message.java | 2 + .../bugs/_2077/Issue2077ErroneousMapper.java | 3 - .../ap/test/bugs/_2077/Issue2077Test.java | 5 +- .../mapstruct/ap/test/bugs/_2125/Comment.java | 27 +++++++ .../bugs/_2125/Issue2125ErroneousMapper.java | 28 ++++++++ .../ap/test/bugs/_2125/Issue2125Mapper.java | 28 ++++++++ .../ap/test/bugs/_2125/Issue2125Test.java | 71 +++++++++++++++++++ .../ap/test/bugs/_2125/Repository.java | 28 ++++++++ 9 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Comment.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125ErroneousMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Repository.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c2434da51d..deeadc7eaf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -65,6 +65,8 @@ import static org.mapstruct.ap.internal.util.Message.GENERAL_ABSTRACT_RETURN_TYPE; import static org.mapstruct.ap.internal.util.Message.GENERAL_AMBIGUOUS_CONSTRUCTORS; import static org.mapstruct.ap.internal.util.Message.GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS; +import static org.mapstruct.ap.internal.util.Message.PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET; +import static org.mapstruct.ap.internal.util.Message.PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET; /** * A {@link MappingMethod} implemented by a {@link Mapper} class which maps one bean type to another, optionally @@ -1113,6 +1115,31 @@ else if ( mapping.getJavaExpression() != null ) { errorOccured = true; } } + else { + errorOccured = true; + + if ( method.getSourceParameters().size() == 1 ) { + ctx.getMessager() + .printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET, + method.getSourceParameters().get( 0 ).getName(), + targetPropertyName + ); + } + else { + ctx.getMessager() + .printMessage( + method.getExecutable(), + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET, + targetPropertyName + ); + } + } } // remaining are the mappings without a 'source' so, 'only' a date format or qualifiers if ( propertyMapping != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 87d3a9abdd..67aa5849bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -73,6 +73,8 @@ public enum Message { PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_WHITESPACE_TRIMMED( "The property named \"%s\" has whitespaces, using trimmed property \"%s\" instead.", Diagnostic.Kind.WARNING ), + PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET("The type of parameter \"%s\" has no property named \"%s\". Please define the source property explicitly."), + PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET("No property named \"%s\" exists in source parameter(s). Please define the source explicitly."), CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ), CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java index ecbff63802..9d38e8bf45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077ErroneousMapper.java @@ -8,7 +8,6 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; /** * @author Sjaak Derksen @@ -16,8 +15,6 @@ @Mapper( unmappedTargetPolicy = ReportingPolicy.ERROR ) public interface Issue2077ErroneousMapper { - Issue2077ErroneousMapper INSTANCE = Mappers.getMapper( Issue2077ErroneousMapper.class ); - @Mapping(target = "s1", defaultValue = "xyz" ) Target map(String source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java index d8c3a1e5d7..332c3034dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java @@ -30,8 +30,9 @@ public class Issue2077Test { diagnostics = { @Diagnostic(type = Issue2077ErroneousMapper.class, kind = ERROR, - line = 22, - message = "Unmapped target property: \"s1\".") + line = 18, + message = "The type of parameter \"source\" has no property named \"s1\". Please define the source " + + "property explicitly.") } ) public void shouldNotCompile() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Comment.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Comment.java new file mode 100644 index 0000000000..13fe680bb0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Comment.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2125; + +/** + * @author Filip Hrisafov + */ +public class Comment { + private final Integer issueId; + private final String comment; + + public Comment(Integer issueId, String comment) { + this.issueId = issueId; + this.comment = comment; + } + + public Integer getIssueId() { + return issueId; + } + + public String getComment() { + return comment; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125ErroneousMapper.java new file mode 100644 index 0000000000..bdca172003 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125ErroneousMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2125; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +@Mapper +public interface Issue2125ErroneousMapper { + + @Mapping(target = "issueId", qualifiedByName = "mapIssueNumber") + @Mapping( target = "comment", ignore = true) + Comment clone(Repository repository); + + @Mapping(target = "issueId", qualifiedByName = "mapIssueNumber") + @Mapping( target = "comment", ignore = true) + Comment clone(Comment comment, Repository repository); + + @Named("mapIssueNumber") + default Integer mapIssueNumber(Integer issueNumber) { + return issueNumber != null ? issueNumber + 1 : null; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java new file mode 100644 index 0000000000..3a867baf46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2125; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2125Mapper { + + Issue2125Mapper INSTANCE = Mappers.getMapper( Issue2125Mapper.class ); + + Comment clone(Comment comment, Integer issueId); + + @Mapping(target = "issueId", qualifiedByName = "mapIssueNumber") + Comment cloneWithQualifier(Comment comment, Integer issueId); + + @Named("mapIssueNumber") + default Integer mapIssueNumber(Integer issueNumber) { + return issueNumber != null ? issueNumber + 1 : null; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java new file mode 100644 index 0000000000..38f235509f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java @@ -0,0 +1,71 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2125; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2125") +@WithClasses({ + Comment.class, + Repository.class, +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2125Test { + + @Test + @WithClasses({ + Issue2125Mapper.class + }) + public void shouldSelectProperMethod() { + + Comment comment = Issue2125Mapper.INSTANCE.clone( + new Comment( 2125, "Fix issue" ), + 1000 + ); + + assertThat( comment ).isNotNull(); + assertThat( comment.getIssueId() ).isEqualTo( 2125 ); + + comment = Issue2125Mapper.INSTANCE.cloneWithQualifier( + new Comment( 2125, "Fix issue" ), + 1000 + ); + + assertThat( comment ).isNotNull(); + assertThat( comment.getIssueId() ).isEqualTo( 1001 ); + } + + @Test + @WithClasses({ + Issue2125ErroneousMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Issue2125ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 15, + alternativeLine = 17, // For some reason javac reports the error on the method instead of the annotation + message = "The type of parameter \"repository\" has no property named \"issueId\". Please define the " + + "source property explicitly."), + @Diagnostic(type = Issue2125ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 19, + alternativeLine = 21, // For some reason javac reports the error on the method instead of the annotation + message = "No property named \"issueId\" exists in source parameter(s). Please define the source " + + "explicitly.") + }) + public void shouldReportErrorWhenMultipleSourcesMatch() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Repository.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Repository.java new file mode 100644 index 0000000000..bf0c80984f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Repository.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2125; + +/** + * @author Filip Hrisafov + */ +public class Repository { + + private final String owner; + private final String name; + + public Repository(String owner, String name) { + this.owner = owner; + this.name = name; + } + + public String getOwner() { + return owner; + } + + public String getName() { + return name; + } +} From 9973b92ccb15d57dc6c871b7887fc9684a7950d5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 26 Sep 2020 10:20:45 +0200 Subject: [PATCH 0509/1006] [maven-release-plugin] prepare release 1.4.0.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c908377c8..b37ad28030 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 63311b5950..2adae1cbab 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c74e0b8bb1..c5619f6226 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b404ed3cee..5c4fa50c27 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index ceb3cb1db6..60cb9bac5b 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a643bab4b8..9521e4e54a 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e28caa20b8..8164300775 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final pom MapStruct Parent @@ -63,7 +63,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Final diff --git a/pom.xml b/pom.xml index f9c649c168..bb275f9902 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.0.Final diff --git a/processor/pom.xml b/processor/pom.xml index c047301268..5fdcae01f0 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0-SNAPSHOT + 1.4.0.Final ../parent/pom.xml From eb5b8bb71efd7a6bfa6f880bef2c503abdf007cf Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 26 Sep 2020 10:20:47 +0200 Subject: [PATCH 0510/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index b37ad28030..aaae7b5404 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 2adae1cbab..293043e6f9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index c5619f6226..b02b809ed7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 5c4fa50c27..30beb1d319 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 60cb9bac5b..0426805375 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 9521e4e54a..f19ecfe343 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8164300775..b38472cef0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT pom MapStruct Parent @@ -63,7 +63,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Final + HEAD diff --git a/pom.xml b/pom.xml index bb275f9902..28c35aea74 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.0.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 5fdcae01f0..bbec83bf29 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.0.Final + 1.5.0-SNAPSHOT ../parent/pom.xml From 2d750193d1f5fb8324836edb1b805ea8aaa62b26 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 26 Sep 2020 11:45:27 +0200 Subject: [PATCH 0511/1006] Update versions in readme to 1.4.0.Final --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 5daba3f777..f92ea452b8 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.3.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.3.1.Final + 1.4.0.Final ... @@ -119,10 +119,10 @@ apply plugin: 'net.ltgt.apt-eclipse' dependencies { ... - compile 'org.mapstruct:mapstruct:1.3.1.Final' + compile 'org.mapstruct:mapstruct:1.4.0.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final' // if you are using mapstruct in test code } ... ``` From 4480e0f367b4a34a448d16c9c0f39c0640742d49 Mon Sep 17 00:00:00 2001 From: Jasper Vandemalle Date: Fri, 2 Oct 2020 20:43:11 +0200 Subject: [PATCH 0512/1006] Fix minor typos --- .../main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 2 +- .../asciidoc/chapter-6-mapping-collections.asciidoc | 2 +- .../main/asciidoc/chapter-8-mapping-values.asciidoc | 2 +- .../mapstruct/ap/test/collection/adder/AdderTest.java | 2 +- ...bigiousMapperTest.java => AmbiguousMapperTest.java} | 2 +- .../ErroneousWithAmbiguousMethodsMapper.java | 2 +- ...rroneousWithMoreThanFiveAmbiguousMethodsMapper.java | 10 +++++----- .../manysourcearguments/ManySourceArgumentsTest.java | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/{AmbigiousMapperTest.java => AmbiguousMapperTest.java} (99%) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 7d2dd052f6..54a0dbd709 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -540,7 +540,7 @@ When there are multiple constructors then the following is done to pick the one * If a constructor is annotated with an annotation named `@Default` (from any package) it will be used. * If a single public constructor exists then it will be used to construct the object, and the other non public constructors will be ignored. * If a parameterless constructor exists then it will be used to construct the object, and the other constructors will be ignored. -* If there are multiple eligible constructors then there will be a compilation error due to ambigious constructors. In order to break the ambiquity an annotation named `@Default` (from any package) can used. +* If there are multiple eligible constructors then there will be a compilation error due to ambiguous constructors. In order to break the ambiguity an annotation named `@Default` (from any package) can used. .Deciding which constructor to use ==== diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc index 0713316a46..dcce306789 100644 --- a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -151,7 +151,7 @@ public Map stringStringMapToLongDateMap(Map source) MapStruct has a `CollectionMappingStrategy`, with the possible values: `ACCESSOR_ONLY`, `SETTER_PREFERRED`, `ADDER_PREFERRED` and `TARGET_IMMUTABLE`. -In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are applied to the presence/absense of a `set-s`, `add-` and / or `get-s` method on the target object: +In the table below, the dash `-` indicates a property name. Next, the trailing `s` indicates the plural form. The table explains the options and how they are applied to the presence/absence of a `set-s`, `add-` and / or `get-s` method on the target object: .Collection mapping strategy options |=== diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index 000fd06523..e38cee215b 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -155,7 +155,7 @@ MapStruct supports enum to a String mapping along the same lines as is described *`String` to enum* -1. Similarity: All not explicit defined mappings will result in the target enum constant mapped from the `String` value when that maches the target enum constant name. +1. Similarity: All not explicit defined mappings will result in the target enum constant mapped from the `String` value when that matches the target enum constant name. 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Similarity: `` will create a mapping for each target enum constant and proceed to the switch/default clause value. 4. Difference: A switch/default value needs to be provided to have a determined outcome (enum has a limited set of values, `String` has unlimited options). Failing to specify `` or ` will result in a warning. diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index 3398a99d79..d3c667099c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -178,7 +178,7 @@ public void testShouldPreferHumanSingular() { } @Test - public void testShouldFallBackToDaliSingularInAbsenseOfHumanSingular() { + public void testShouldFallBackToDaliSingularInAbsenceOfHumanSingular() { AdderUsageObserver.setUsed( false ); SourceTeeth source = new SourceTeeth(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java similarity index 99% rename from processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java rename to processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java index c13f1edd2f..3c4bd00a7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbigiousMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java @@ -17,7 +17,7 @@ @IssueKey("2156") @RunWith(AnnotationProcessorTestRunner.class) -public class AmbigiousMapperTest { +public class AmbiguousMapperTest { @Test @WithClasses( ErroneousWithAmbiguousMethodsMapper.class) diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java index 7ebce015d1..165f8d5945 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithAmbiguousMethodsMapper.java @@ -19,7 +19,7 @@ default LeafEntity map1(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map2(LeafDTO dto) { return new LeafEntity(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java index 1e050cea71..2ca70ccaf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/ErroneousWithMoreThanFiveAmbiguousMethodsMapper.java @@ -20,28 +20,28 @@ default LeafEntity map1(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map2(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map3(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map4(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map5(LeafDTO dto) { return new LeafEntity(); } - // duplicated method, triggering ambigious mapping method + // duplicated method, triggering ambiguous mapping method default LeafEntity map6(LeafDTO dto) { return new LeafEntity(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java index 549397def7..63aaf8b654 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java @@ -176,7 +176,7 @@ public void shouldUseConfig() { line = 16, message = "Several possible source properties for target property \"description\".") }) - public void shouldFailToGenerateMappingsForAmbigiousSourceProperty() { + public void shouldFailToGenerateMappingsForAmbiguousSourceProperty() { } @Test From 233fc6de98aa662172bd1b00401c574e25ae371d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 3 Oct 2020 12:46:14 +0200 Subject: [PATCH 0513/1006] #2215: Avoid NPE in IntelliJ EAP 2020.3 Starting from IntelliJ 2020.3 (Build 203.4203.26) the ProcessingEnvironment is wrapped in a Proxy class by IntelliJ. MapStruct should gracefully handle that and not throw an NPE. Additionally, we should do best effort to put the used compiler in the generated annotation info --- .../processor/DefaultVersionInformation.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java index 60e5f112d2..c4baf1bf5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.internal.processor; import java.io.IOException; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; import java.net.MalformedURLException; import java.net.URL; import java.util.jar.Manifest; @@ -103,7 +105,28 @@ static DefaultVersionInformation fromProcessingEnvironment(ProcessingEnvironment } private static String getCompiler(ProcessingEnvironment processingEnv) { - String className = processingEnv.getClass().getName(); + String className; + if ( Proxy.isProxyClass( processingEnv.getClass() ) ) { + // IntelliJ IDEA wraps the ProcessingEnvironment in a Proxy. + // Therefore we need smarter logic to determine the type of the compiler + String processingEnvToString = processingEnv.toString(); + if ( processingEnvToString.contains( COMPILER_NAME_JAVAC ) ) { + // The toString of the javac ProcessingEnvironment is "javac ProcessingEnvironment" + className = JAVAC_PE_CLASS; + } + else if ( processingEnvToString.startsWith( JDT_BATCH_PE_CLASS ) ) { + // The toString of the JDT Batch is from Object#toString so it contains the class name + className = JDT_BATCH_PE_CLASS; + } + else { + InvocationHandler invocationHandler = Proxy.getInvocationHandler( processingEnv ); + return "Proxy handler " + invocationHandler.getClass() + " from " + + getLibraryName( invocationHandler.getClass(), false ); + } + } + else { + className = processingEnv.getClass().getName(); + } if ( className.equals( JAVAC_PE_CLASS ) ) { return COMPILER_NAME_JAVAC; @@ -135,7 +158,10 @@ private static String getLibraryName(Class clazz, boolean preferVersionOnly) } } - if ( "jar".equals( resource.getProtocol() ) ) { + if ( resource == null ) { + return ""; + } + else if ( "jar".equals( resource.getProtocol() ) ) { return extractJarFileName( resource.getFile() ); } else if ( "jrt".equals( resource.getProtocol() ) ) { @@ -149,6 +175,9 @@ else if ( "bundleresource".equals( resource.getProtocol() ) && manifest != null } private static Manifest openManifest(String classFileName, URL resource) { + if ( resource == null ) { + return null; + } try { URL manifestUrl = createManifestUrl( classFileName, resource ); return new Manifest( manifestUrl.openStream() ); From 823b5edd9f5215d00321b37153e1838fa0485977 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 3 Oct 2020 10:20:03 +0200 Subject: [PATCH 0514/1006] #2213: primitive arrays should be directly mapped (we are cloning them anyways) Additionally fix problem when annotations `ElementType.TYPE_USE` not handled correctly for javac --- .../ap/internal/model/common/TypeFactory.java | 4 +- .../creation/MappingResolverImpl.java | 2 +- .../org/mapstruct/ap/test/bugs/_2213/Car.java | 28 ++++++++++ .../mapstruct/ap/test/bugs/_2213/Car2.java | 28 ++++++++++ .../ap/test/bugs/_2213/CarMapper.java | 22 ++++++++ .../ap/test/bugs/_2213/Issue2213Test.java | 53 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2213/NotNull.java | 22 ++++++++ .../ap/test/bugs/_2213/CarMapperImpl.java | 37 +++++++++++++ 8 files changed, 194 insertions(+), 2 deletions(-) create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car.java create mode 100755 processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/NotNull.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2213/CarMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 9cfe18c176..ba1dcc1920 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -274,7 +274,9 @@ else if (componentTypeMirror.getKind().isPrimitive()) { else { isEnumType = false; isInterface = false; - name = mirror.toString(); + // When the component type is primitive and is annotated with ElementType.TYPE_USE then + // the typeMirror#toString returns (@CustomAnnotation :: byte) for the javac compiler + name = mirror.getKind().isPrimitive() ? NativeTypes.getName( mirror.getKind() ) : mirror.toString(); packageName = null; qualifiedName = name; typeElement = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index fe7635f7f6..73392a00f8 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -367,7 +367,7 @@ private boolean allowDirect(Type type) { } if ( type.isArrayType() ) { - return type.isJavaLangType(); + return type.isJavaLangType() || type.getComponentType().isPrimitive(); } if ( type.isIterableOrStreamType() ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car.java new file mode 100755 index 0000000000..4f2ec92af6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +public class Car { + private int[] intData; + private Long[] longData; + + public int[] getIntData() { + return intData; + } + + public void setIntData(int[] intData) { + this.intData = intData; + } + + public Long[] getLongData() { + return longData; + } + + public void setLongData(Long[] longData) { + this.longData = longData; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car2.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car2.java new file mode 100755 index 0000000000..ec0cd6de6d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Car2.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +public class Car2 { + private int[] intData; + private Long[] longData; + + public @NotNull int[] getIntData() { + return intData; + } + + public void setIntData(int[] intData) { + this.intData = intData; + } + + public @NotNull Long[] getLongData() { + return longData; + } + + public void setLongData(Long[] longData) { + this.longData = longData; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/CarMapper.java new file mode 100644 index 0000000000..f3b25c0213 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/CarMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = DeepClone.class) +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + Car toCar(Car2 car2); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java new file mode 100644 index 0000000000..613b981d04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + NotNull.class, + CarMapper.class, + Car.class, + Car2.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey("2213") +public class Issue2213Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( CarMapper.class ); + + @Test + public void testShouldNotGenerateIntermediatePrimitiveMappingMethod() { + Car2 car = new Car2(); + int[] sourceInt = { 1, 2, 3 }; + car.setIntData( sourceInt ); + Long[] sourceLong = { 1L, 2L, 3L }; + car.setLongData( sourceLong ); + Car target = CarMapper.INSTANCE.toCar( car ); + + assertThat( target ).isNotNull(); + assertThat( target.getIntData() ) + .containsExactly( 1, 2, 3 ) + .isNotSameAs( sourceInt ); + assertThat( target.getLongData() ) + .containsExactly( 1L, 2L, 3L ) + .isNotSameAs( sourceLong ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/NotNull.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/NotNull.java new file mode 100644 index 0000000000..3b45f03ed4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/NotNull.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ + ElementType.METHOD, + ElementType.TYPE_USE +}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface NotNull { + +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2213/CarMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2213/CarMapperImpl.java new file mode 100644 index 0000000000..794d6d4864 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2213/CarMapperImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2213; + +import java.util.Arrays; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-10-03T10:12:15+0200", + comments = "version: , compiler: javac, environment: Java 11.0.4 (AdoptOpenJDK)" +) +public class CarMapperImpl implements CarMapper { + + @Override + public Car toCar(Car2 car2) { + if ( car2 == null ) { + return null; + } + + Car car = new Car(); + + int[] intData = car2.getIntData(); + if ( intData != null ) { + car.setIntData( Arrays.copyOf( intData, intData.length ) ); + } + Long[] longData = car2.getLongData(); + if ( longData != null ) { + car.setLongData( Arrays.copyOf( longData, longData.length ) ); + } + + return car; + } +} From a5f49e591ed3bb2e5c2b7565c0a9f968be47643d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 7 Oct 2020 23:03:16 +0200 Subject: [PATCH 0515/1006] #2221: Fix configuration inheritance when there are multiple matching source parameters of the same type --- .../model/beanmapping/SourceReference.java | 24 ++++++++--- .../ap/test/bugs/_2221/Issue2221Test.java | 43 +++++++++++++++++++ .../ap/test/bugs/_2221/RestConfig.java | 21 +++++++++ .../ap/test/bugs/_2221/RestSiteDto.java | 34 +++++++++++++++ .../ap/test/bugs/_2221/RestSiteMapper.java | 22 ++++++++++ .../mapstruct/ap/test/bugs/_2221/SiteDto.java | 34 +++++++++++++++ 6 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/SiteDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index cf52c96a2d..1d747c190e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.type.DeclaredType; @@ -239,11 +238,24 @@ private Parameter getSourceParameterFromMethodOrTemplate(String parameterName ) if ( isForwarded ) { Parameter parameter = Parameter.getSourceParameter( templateMethod.getParameters(), parameterName ); if ( parameter != null ) { - result = method.getSourceParameters() - .stream() - .filter( p -> p.getType().isAssignableTo( parameter.getType() ) ) - .collect( Collectors.reducing( (a, b) -> null ) ) - .orElse( null ); + + // When forward inheriting we should find the matching source parameter by type + // If there are multiple parameters of the same type + // then we fallback to match the parameter name to the current method source parameters + for ( Parameter sourceParameter : method.getSourceParameters() ) { + if ( sourceParameter.getType().isAssignableTo( parameter.getType() ) ) { + if ( result == null ) { + result = sourceParameter; + } + else { + // When we reach here it means that we found a second source parameter + // that has the same type, then fallback to the matching source parameter + // in the current method + result = Parameter.getSourceParameter( method.getParameters(), parameterName ); + break; + } + } + } } } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java new file mode 100644 index 0000000000..34514de929 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2221; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2221") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + RestConfig.class, + RestSiteDto.class, + RestSiteMapper.class, + SiteDto.class, +}) +public class Issue2221Test { + + @Test + public void multiSourceInheritConfigurationShouldWork() { + SiteDto site = RestSiteMapper.INSTANCE.convert( + new RestSiteDto( "restTenant", "restSite", "restCti" ), + "parameterTenant", + "parameterSite" + ); + + assertThat( site ).isNotNull(); + assertThat( site.getTenantId() ).isEqualTo( "parameterTenant" ); + assertThat( site.getSiteId() ).isEqualTo( "parameterSite" ); + assertThat( site.getCtiId() ).isEqualTo( "restCti" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestConfig.java new file mode 100644 index 0000000000..9a0f79f82d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestConfig.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2221; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@MapperConfig +public interface RestConfig { + + @Mapping(target = "tenantId", source = "tenantId") + @Mapping(target = "siteId", source = "siteId") + @Mapping(target = "ctiId", source = "source.cti", defaultValue = "unknown") + SiteDto convert(RestSiteDto source, String tenantId, String siteId); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteDto.java new file mode 100644 index 0000000000..eb1a56b344 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteDto.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2221; + +/** + * @author Filip Hrisafov + */ +public class RestSiteDto { + + private final String tenantId; + private final String siteId; + private final String cti; + + public RestSiteDto(String tenantId, String siteId, String cti) { + this.tenantId = tenantId; + this.siteId = siteId; + this.cti = cti; + } + + public String getTenantId() { + return tenantId; + } + + public String getSiteId() { + return siteId; + } + + public String getCti() { + return cti; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteMapper.java new file mode 100644 index 0000000000..cf7281f44f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/RestSiteMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2221; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = RestConfig.class) +public interface RestSiteMapper { + + RestSiteMapper INSTANCE = Mappers.getMapper( RestSiteMapper.class ); + + @InheritConfiguration + SiteDto convert(RestSiteDto source, String tenantId, String siteId); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/SiteDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/SiteDto.java new file mode 100644 index 0000000000..7c80410029 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/SiteDto.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2221; + +/** + * @author Filip Hrisafov + */ +public class SiteDto { + + private final String tenantId; + private final String siteId; + private final String ctiId; + + public SiteDto(String tenantId, String siteId, String ctiId) { + this.tenantId = tenantId; + this.siteId = siteId; + this.ctiId = ctiId; + } + + public String getTenantId() { + return tenantId; + } + + public String getSiteId() { + return siteId; + } + + public String getCtiId() { + return ctiId; + } +} From 53a5c34ed62739feb786a6840b5fe885296f10da Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 7 Oct 2020 21:42:26 +0200 Subject: [PATCH 0516/1006] #2206, #2214, #2220: Source property should be correctly determined when only target is defined When having multiple source properties and only target is defined then the same rules should be applied as if there was no mapping: * First we check for a matching property in any of the source type * Second we check if the parameter name matches --- .../ap/internal/model/BeanMappingMethod.java | 32 ++++++++++++++- .../ap/test/bugs/_2125/Issue2125Mapper.java | 7 ++++ .../ap/test/bugs/_2125/Issue2125Test.java | 14 ++++--- .../CountryMapperMultipleSources.java | 23 +++++++++++ .../test/defaultvalue/DefaultValueTest.java | 34 ++++++++++++++++ .../ErroneousMissingSourceMapper.java | 39 +++++++++++++++++++ 6 files changed, 141 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapperMultipleSources.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMissingSourceMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index deeadc7eaf..87b8a28b4d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1070,8 +1070,36 @@ else if ( mapping.getJavaExpression() != null ) { SourceReference sourceRef = mappingRef.getSourceReference(); // sourceRef is not defined, check if a source property has the same name - if ( sourceRef == null && method.getSourceParameters().size() == 1 ) { - sourceRef = getSourceRefByTargetName( method.getSourceParameters().get( 0 ), targetPropertyName ); + if ( sourceRef == null ) { + // Here we follow the same rules as when we implicitly map + // When we implicitly map we first do property name based mapping + // i.e. look for matching properties in the source types + // and then do parameter name based mapping + for ( Parameter sourceParameter : method.getSourceParameters() ) { + SourceReference matchingSourceRef = getSourceRefByTargetName( + sourceParameter, + targetPropertyName + ); + if ( matchingSourceRef != null ) { + if ( sourceRef != null ) { + errorOccured = true; + // This can only happen when the target property matches multiple properties + // within the different source parameters + ctx.getMessager() + .printMessage( + method.getExecutable(), + mappingRef.getMapping().getMirror(), + Message.BEANMAPPING_SEVERAL_POSSIBLE_SOURCES, + targetPropertyName + ); + break; + } + // We can't break here since it is possible that the same property exists in multiple + // source parameters + sourceRef = matchingSourceRef; + } + } + } if ( sourceRef == null ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java index 3a867baf46..83cf0e1b28 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Mapper.java @@ -15,11 +15,18 @@ public interface Issue2125Mapper { Issue2125Mapper INSTANCE = Mappers.getMapper( Issue2125Mapper.class ); + // In this case the issueId from the Comment is used Comment clone(Comment comment, Integer issueId); + // When source is not defined then we will use the issueId from the Comment, + // same as when there was no mapping @Mapping(target = "issueId", qualifiedByName = "mapIssueNumber") Comment cloneWithQualifier(Comment comment, Integer issueId); + // When source is defined then we will source the parameter name + @Mapping(target = "issueId", source = "issueId", qualifiedByName = "mapIssueNumber") + Comment cloneWithQualifierExplicitSource(Comment comment, Integer issueId); + @Named("mapIssueNumber") default Integer mapIssueNumber(Integer issueNumber) { return issueNumber != null ? issueNumber + 1 : null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java index 38f235509f..e98afe7d52 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java @@ -43,6 +43,14 @@ public void shouldSelectProperMethod() { 1000 ); + assertThat( comment ).isNotNull(); + assertThat( comment.getIssueId() ).isEqualTo( 2126 ); + + comment = Issue2125Mapper.INSTANCE.cloneWithQualifierExplicitSource( + new Comment( 2125, "Fix issue" ), + 1000 + ); + assertThat( comment ).isNotNull(); assertThat( comment.getIssueId() ).isEqualTo( 1001 ); } @@ -59,12 +67,6 @@ public void shouldSelectProperMethod() { alternativeLine = 17, // For some reason javac reports the error on the method instead of the annotation message = "The type of parameter \"repository\" has no property named \"issueId\". Please define the " + "source property explicitly."), - @Diagnostic(type = Issue2125ErroneousMapper.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 19, - alternativeLine = 21, // For some reason javac reports the error on the method instead of the annotation - message = "No property named \"issueId\" exists in source parameter(s). Please define the source " + - "explicitly.") }) public void shouldReportErrorWhenMultipleSourcesMatch() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapperMultipleSources.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapperMultipleSources.java new file mode 100644 index 0000000000..11a424d929 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/CountryMapperMultipleSources.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultvalue; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CountryMapperMultipleSources { + + CountryMapperMultipleSources INSTANCE = Mappers.getMapper( CountryMapperMultipleSources.class ); + + @Mapping(target = "code", defaultValue = "CH") + @Mapping(target = "region", source = "regionCode") + CountryDts map(CountryEntity entity, String regionCode); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index ff7bf00722..e834df3e3f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -159,4 +159,38 @@ public void errorOnDefaultValueAndConstant() { public void errorOnDefaultValueAndExpression() { } + @Test + @IssueKey("2214") + @WithClasses({ + CountryMapperMultipleSources.class, + Region.class, + }) + public void shouldBeAbleToDetermineDefaultValueBasedOnOnlyTargetType() { + CountryEntity entity = new CountryEntity(); + CountryDts target = CountryMapperMultipleSources.INSTANCE.map( entity, "ZH" ); + + assertThat( target ).isNotNull(); + assertThat( target.getCode() ).isEqualTo( "CH" ); + } + + @Test + @IssueKey("2220") + @WithClasses({ + ErroneousMissingSourceMapper.class, + Region.class, + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMissingSourceMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "The type of parameter \"tenant\" has no property named \"type\"." + + " Please define the source property explicitly."), + } + ) + public void errorWhenOnlyTargetDefinedAndSourceDoesNotHaveProperty() { + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMissingSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMissingSourceMapper.java new file mode 100644 index 0000000000..54fd3cc645 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/ErroneousMissingSourceMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultvalue; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousMissingSourceMapper { + + @Mapping(target = "type", defaultValue = "STANDARD") + Tenant map(TenantDto tenant); + + class Tenant { + + private final String id; + private final String type; + + public Tenant(String id, String type) { + this.id = id; + this.type = type; + } + } + + class TenantDto { + + private final String id; + + public TenantDto(String id) { + this.id = id; + } + } +} From 2b95e07d8e2648dccfbdbd8ba1f2fc3a4f67a303 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 10 Oct 2020 10:22:43 +0200 Subject: [PATCH 0517/1006] Turn of Maven connection pooling to avoid connection issues on CI The problem and solution are explained in https://github.com/actions/virtual-environments/issues/1499#issuecomment-689467080 --- .github/workflows/java-ea.yml | 5 ++++- .github/workflows/main.yml | 9 +++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index a5afa065c7..3e901b6119 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -2,6 +2,9 @@ name: Java EA on: [push] +env: + MAVEN_ARGS: -V -B --no-transfer-progress -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 + jobs: test_jdk_ea: strategy: @@ -18,4 +21,4 @@ jobs: with: java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw -V -B --no-transfer-progress install -DskipDistribution=true + run: ./mvnw ${MAVEN_ARGS} install -DskipDistribution=true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08278a1ade..f63a183d4b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,6 +5,7 @@ on: [push, pull_request] env: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + MAVEN_ARGS: -V -B --no-transfer-progress -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 jobs: test_jdk: @@ -22,7 +23,7 @@ jobs: with: java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw -V -B --no-transfer-progress install -DskipDistribution=true + run: ./mvnw ${MAVEN_ARGS} install -DskipDistribution=true linux: name: 'Linux JDK 8' runs-on: ubuntu-latest @@ -34,7 +35,7 @@ jobs: with: java-version: 8 - name: 'Test' - run: ./mvnw -V -B --no-transfer-progress install + run: ./mvnw ${MAVEN_ARGS} install - name: 'Generate coverage report' run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' @@ -52,7 +53,7 @@ jobs: with: java-version: 8 - name: 'Test' - run: ./mvnw -V -B --no-transfer-progress install + run: ./mvnw ${MAVEN_ARGS} install mac: name: 'Mac OS' runs-on: macos-latest @@ -63,4 +64,4 @@ jobs: with: java-version: 8 - name: 'Test' - run: ./mvnw -V -B --no-transfer-progress install + run: ./mvnw ${MAVEN_ARGS} install From d8f22f83116833b2a90469d748c7c966e93215e5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Oct 2020 09:35:30 +0200 Subject: [PATCH 0518/1006] [maven-release-plugin] prepare release 1.4.1.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index aaae7b5404..bd8b1c943d 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 293043e6f9..5367c3e97e 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index b02b809ed7..d01dd8efcf 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 30beb1d319..9529a1f85c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0426805375..47c5a55a33 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f19ecfe343..51bd59a6c9 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b38472cef0..e8255cb881 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final pom MapStruct Parent @@ -63,7 +63,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.1.Final diff --git a/pom.xml b/pom.xml index 28c35aea74..3ee2ea53f8 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.4.1.Final diff --git a/processor/pom.xml b/processor/pom.xml index bbec83bf29..4f63f685dd 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.4.1.Final ../parent/pom.xml From 58dbaee472c32a5f98535df293df621481561879 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Oct 2020 09:35:30 +0200 Subject: [PATCH 0519/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index bd8b1c943d..aaae7b5404 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 5367c3e97e..293043e6f9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index d01dd8efcf..b02b809ed7 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 9529a1f85c..30beb1d319 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 47c5a55a33..0426805375 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 51bd59a6c9..f19ecfe343 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e8255cb881..b38472cef0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT pom MapStruct Parent @@ -63,7 +63,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.1.Final + HEAD diff --git a/pom.xml b/pom.xml index 3ee2ea53f8..28c35aea74 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.4.1.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 4f63f685dd..bbec83bf29 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.4.1.Final + 1.5.0-SNAPSHOT ../parent/pom.xml From 0e902d6412d07d27a8efb2b72ec72ebcbbced55e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Oct 2020 10:00:24 +0200 Subject: [PATCH 0520/1006] Update versions in readme to 1.4.1.Final --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index f92ea452b8..c39a408ac2 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.4.0.Final + 1.4.1.Final ... @@ -119,10 +119,10 @@ apply plugin: 'net.ltgt.apt-eclipse' dependencies { ... - compile 'org.mapstruct:mapstruct:1.4.0.Final' + compile 'org.mapstruct:mapstruct:1.4.1.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.0.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' // if you are using mapstruct in test code } ... ``` From 4ddfd2ff510cfe5dcb630a1d371cb837ff915391 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 23:18:51 +0000 Subject: [PATCH 0521/1006] Bump junit from 4.12 to 4.13.1 in /parent Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1) Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index b38472cef0..9e5c04f27a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -126,7 +126,7 @@ junit junit - 4.12 + 4.13.1 com.puppycrawl.tools From 50aa9cdbdc5cd721dfe48721059544faf2c818ac Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 17 Oct 2020 12:30:31 +0200 Subject: [PATCH 0522/1006] Use junit version defined in parent in integration tests --- .../faultyAstModifyingAnnotationProcessorTest/usage/pom.xml | 1 - .../src/test/resources/superTypeGenerationTest/usage/pom.xml | 1 - .../src/test/resources/targetTypeGenerationTest/usage/pom.xml | 1 - .../src/test/resources/usesTypeGenerationTest/usage/pom.xml | 1 - 4 files changed, 4 deletions(-) diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml index cc0d0e4f98..90c95aa83b 100644 --- a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml @@ -23,7 +23,6 @@ junit junit - 4.12 test diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml index 07e89a9808..ee0d556b9f 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml @@ -23,7 +23,6 @@ junit junit - 4.12 test diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml index 8b0852ff07..da72f667a4 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -23,7 +23,6 @@ junit junit - 4.12 test diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml index e8b8d7bf07..79696df47d 100644 --- a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml @@ -23,7 +23,6 @@ junit junit - 4.12 test From 6102d0cc8ee1a62e26462ad78d5cf4fd507a3139 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Oct 2020 16:11:18 +0200 Subject: [PATCH 0523/1006] #2236 Different nested target mappings should generate different intermediate methods Make sure that MappingReferences are taken into consideration when comparing whether 2 mapping methods are equal. This makes sure that when using nested target mappings that have the same property mappings, but different mappings 2 distinct methods will be created --- .../ap/internal/model/BeanMappingMethod.java | 23 +++++++- .../model/beanmapping/MappingReferences.java | 33 +++++++++++ .../org/mapstruct/ap/test/bugs/_2236/Car.java | 49 ++++++++++++++++ .../mapstruct/ap/test/bugs/_2236/CarDto.java | 58 +++++++++++++++++++ .../ap/test/bugs/_2236/CarMapper.java | 27 +++++++++ .../ap/test/bugs/_2236/Issue2236Test.java | 57 ++++++++++++++++++ .../mapstruct/ap/test/bugs/_2236/Owner.java | 31 ++++++++++ .../mapstruct/ap/test/bugs/_2236/Vehicle.java | 30 ++++++++++ .../nestedbeans/mixed/FishTankMapperImpl.java | 41 ++++++++++++- 9 files changed, 344 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Owner.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Vehicle.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 87b8a28b4d..4d086b5126 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -85,6 +85,8 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; + private final MappingReferences mappingReferences; + public static class Builder { private MappingBuilderContext ctx; @@ -337,7 +339,8 @@ else if ( !method.isUpdateMethod() ) { returnTypeBuilder, beforeMappingMethods, afterMappingMethods, - finalizeMethod + finalizeMethod, + mappingReferences ); } @@ -1488,6 +1491,7 @@ private ConstructorAccessor( } } + //CHECKSTYLE:OFF private BeanMappingMethod(Method method, Collection existingVariableNames, List propertyMappings, @@ -1497,7 +1501,8 @@ private BeanMappingMethod(Method method, BuilderType returnTypeBuilder, List beforeMappingReferences, List afterMappingReferences, - MethodReference finalizerMethod) { + MethodReference finalizerMethod, + MappingReferences mappingReferences) { super( method, existingVariableNames, @@ -1506,10 +1511,12 @@ private BeanMappingMethod(Method method, beforeMappingReferences, afterMappingReferences ); + //CHECKSTYLE:ON this.propertyMappings = propertyMappings; this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; + this.mappingReferences = mappingReferences; // intialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. @@ -1628,7 +1635,17 @@ public boolean equals(Object obj) { if ( !super.equals( obj ) ) { return false; } - return Objects.equals( propertyMappings, that.propertyMappings ); + + if ( !Objects.equals( propertyMappings, that.propertyMappings ) ) { + return false; + } + + if ( !Objects.equals( mappingReferences, that.mappingReferences ) ) { + return false; + } + + + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index 06f0ed06c9..569c75e0eb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; @@ -139,6 +140,38 @@ public List getTargetThisReferences() { return targetThisReferences; } + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( !( o instanceof MappingReferences ) ) { + return false; + } + + MappingReferences that = (MappingReferences) o; + + if ( restrictToDefinedMappings != that.restrictToDefinedMappings ) { + return false; + } + if ( forForgedMethods != that.forForgedMethods ) { + return false; + } + if ( !Objects.equals( mappingReferences, that.mappingReferences ) ) { + return false; + } + if ( Objects.equals( targetThisReferences, that.targetThisReferences ) ) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return mappingReferences != null ? mappingReferences.hashCode() : 0; + } + /** * MapStruct filters automatically inversed invalid methods out. TODO: this is a principle we should discuss! * @param mappingRef diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Car.java new file mode 100644 index 0000000000..70bb9a413c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Car.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +/** + * @author Filip Hrisafov + */ +public class Car { + + private String name; + private String type; + private Owner ownerA; + private Owner ownerB; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Owner getOwnerA() { + return ownerA; + } + + public void setOwnerA(Owner ownerA) { + this.ownerA = ownerA; + } + + public Owner getOwnerB() { + return ownerB; + } + + public void setOwnerB(Owner ownerB) { + this.ownerB = ownerB; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarDto.java new file mode 100644 index 0000000000..909bb3649b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarDto.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +/** + * @author Filip Hrisafov + */ +public class CarDto { + + private String name; + private String ownerNameA; + private String ownerNameB; + private String ownerCityA; + private String ownerCityB; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOwnerNameA() { + return ownerNameA; + } + + public void setOwnerNameA(String ownerNameA) { + this.ownerNameA = ownerNameA; + } + + public String getOwnerNameB() { + return ownerNameB; + } + + public void setOwnerNameB(String ownerNameB) { + this.ownerNameB = ownerNameB; + } + + public String getOwnerCityA() { + return ownerCityA; + } + + public void setOwnerCityA(String ownerCityA) { + this.ownerCityA = ownerCityA; + } + + public String getOwnerCityB() { + return ownerCityB; + } + + public void setOwnerCityB(String ownerCityB) { + this.ownerCityB = ownerCityB; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarMapper.java new file mode 100644 index 0000000000..d3366ea2a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/CarMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + @Mapping(target = "ownerA.name", source = "carDto.ownerNameA") + @Mapping(target = "ownerA.city", source = "carDto.ownerCityA") + @Mapping(target = "ownerB.name", source = "carDto.ownerNameB") + @Mapping(target = "ownerB.city", source = "carDto.ownerCityB") + @Mapping(target = "name", source = "carDto.name") + @Mapping(target = "type", source = "type") + Car vehicleToCar(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java new file mode 100644 index 0000000000..17f42c8dc3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2236") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Car.class, + CarDto.class, + CarMapper.class, + Owner.class, + Vehicle.class, +}) +public class Issue2236Test { + + @Test + public void shouldCorrectlyMapSameTypesWithDifferentNestedMappings() { + + Vehicle vehicle = new Vehicle(); + vehicle.setType( "Sedan" ); + CarDto carDto = new CarDto(); + vehicle.setCarDto( carDto ); + + carDto.setName( "Private car" ); + carDto.setOwnerNameA( "Owner A" ); + carDto.setOwnerCityA( "Zurich" ); + + carDto.setOwnerNameB( "Owner B" ); + carDto.setOwnerCityB( "Bern" ); + + Car car = CarMapper.INSTANCE.vehicleToCar( vehicle ); + + assertThat( car ).isNotNull(); + assertThat( car.getType() ).isEqualTo( "Sedan" ); + assertThat( car.getName() ).isEqualTo( "Private car" ); + assertThat( car.getOwnerA() ).isNotNull(); + assertThat( car.getOwnerA().getName() ).isEqualTo( "Owner A" ); + assertThat( car.getOwnerA().getCity() ).isEqualTo( "Zurich" ); + assertThat( car.getOwnerB() ).isNotNull(); + assertThat( car.getOwnerB().getName() ).isEqualTo( "Owner B" ); + assertThat( car.getOwnerB().getCity() ).isEqualTo( "Bern" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Owner.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Owner.java new file mode 100644 index 0000000000..5f200f527a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Owner.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +/** + * @author Filip Hrisafov + */ +public class Owner { + + private String name; + private String city; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Vehicle.java new file mode 100644 index 0000000000..fc8e744e82 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Vehicle.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2236; + +/** + * @author Filip Hrisafov + */ +public class Vehicle { + private CarDto carDto; + private String type; + + public CarDto getCarDto() { + return carDto; + } + + public void setCarDto(CarDto carDto) { + this.carDto = carDto; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 2b81718dba..3642d15340 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -57,9 +57,9 @@ public FishTankDto mapAsWell(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setFish( fishToFishDto( source.getFish() ) ); + fishTankDto.setFish( fishToFishDto1( source.getFish() ) ); fishTankDto.setMaterial( fishTankToMaterialDto1( source ) ); - fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); + fishTankDto.setQuality( waterQualityToWaterQualityDto1( source.getQuality() ) ); fishTankDto.setOrnament( ornamentToOrnamentDto( sourceInteriorOrnament( source ) ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); @@ -197,6 +197,18 @@ protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { return waterPlantDto; } + protected FishDto fishToFishDto1(Fish fish) { + if ( fish == null ) { + return null; + } + + FishDto fishDto = new FishDto(); + + fishDto.setKind( fish.getType() ); + + return fishDto; + } + protected MaterialDto fishTankToMaterialDto1(FishTank fishTank) { if ( fishTank == null ) { return null; @@ -221,6 +233,31 @@ protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisati return waterQualityOrganisationDto; } + protected WaterQualityReportDto waterQualityReportToWaterQualityReportDto1(WaterQualityReport waterQualityReport) { + if ( waterQualityReport == null ) { + return null; + } + + WaterQualityReportDto waterQualityReportDto = new WaterQualityReportDto(); + + waterQualityReportDto.setOrganisation( waterQualityReportToWaterQualityOrganisationDto1( waterQualityReport ) ); + waterQualityReportDto.setVerdict( waterQualityReport.getVerdict() ); + + return waterQualityReportDto; + } + + protected WaterQualityDto waterQualityToWaterQualityDto1(WaterQuality waterQuality) { + if ( waterQuality == null ) { + return null; + } + + WaterQualityDto waterQualityDto = new WaterQualityDto(); + + waterQualityDto.setReport( waterQualityReportToWaterQualityReportDto1( waterQuality.getReport() ) ); + + return waterQualityDto; + } + protected Fish fishDtoToFish(FishDto fishDto) { if ( fishDto == null ) { return null; From 74d06fea5db684cc7e6967680d40761ede7b5ff4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 19 Oct 2020 23:34:59 +0200 Subject: [PATCH 0524/1006] #2233 Allow generic of generics in types when matching e.g. method signature such as T fromOptional(Optional optional) when T resolves to another generic class such as Collection --- .../internal/model/source/MethodMatcher.java | 11 +++- .../ap/test/bugs/_2233/Issue2233Test.java | 50 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2233/Program.java | 30 +++++++++++ .../ap/test/bugs/_2233/ProgramAggregate.java | 25 ++++++++++ .../ap/test/bugs/_2233/ProgramDto.java | 30 +++++++++++ .../ap/test/bugs/_2233/ProgramMapper.java | 31 ++++++++++++ .../test/bugs/_2233/ProgramResponseDto.java | 25 ++++++++++ 7 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Program.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramAggregate.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramResponseDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index cade509b15..2c509924c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -296,8 +296,17 @@ private DeclaredType toRawType(DeclaredType t) { public Boolean visitTypeVariable(TypeVariable t, TypeMirror p) { if ( genericTypesMap.containsKey( t ) ) { // when already found, the same mapping should apply + // Then we should visit the resolved generic type. + // Which can potentially be another generic type + // e.g. + // T fromOptional(Optional optional) + // T resolves to Collection + // We know what T resolves to, so we should treat it as if the method signature was + // Collection fromOptional(Optional optional) TypeMirror p1 = genericTypesMap.get( t ); - return typeUtils.isSubtype( p, p1 ); + // p (Integer) should be a subType of p1 (Number) + // i.e. you can assign p (Integer) to p1 (Number) + return visit( p, p1 ); } else { // check if types are in bound diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java new file mode 100644 index 0000000000..645de0d24b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Collections; +import java.util.Optional; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2233") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses( { + Program.class, + ProgramAggregate.class, + ProgramDto.class, + ProgramMapper.class, + ProgramResponseDto.class, +} ) +public class Issue2233Test { + + @Test + public void shouldCorrectlyMapFromOptionalToCollection() { + ProgramResponseDto response = ProgramMapper.INSTANCE.map( new ProgramAggregate( Collections.singleton( + new Program( + "Optional Mapping", + "123" + ) ) ) ); + + assertThat( response ).isNotNull(); + assertThat( response.getPrograms() ).isPresent(); + assertThat( response.getPrograms().get() ) + .extracting( ProgramDto::getName, ProgramDto::getNumber ) + .containsExactly( + tuple( Optional.of( "Optional Mapping" ), Optional.of( "123" ) ) + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Program.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Program.java new file mode 100644 index 0000000000..748ad4901c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Program.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class Program { + + private final String name; + private final String number; + + public Program(String name, String number) { + this.name = name; + this.number = number; + } + + public Optional getName() { + return Optional.ofNullable( name ); + } + + public Optional getNumber() { + return Optional.ofNullable( number ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramAggregate.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramAggregate.java new file mode 100644 index 0000000000..c3fdabe151 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramAggregate.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Collection; +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class ProgramAggregate { + + private final Collection programs; + + public ProgramAggregate(Collection programs) { + this.programs = programs; + } + + public Optional> getPrograms() { + return Optional.ofNullable( programs ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramDto.java new file mode 100644 index 0000000000..d567998667 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramDto.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class ProgramDto { + + private final String name; + private final String number; + + public ProgramDto(String name, String number) { + this.name = name; + this.number = number; + } + + public Optional getName() { + return Optional.ofNullable( name ); + } + + public Optional getNumber() { + return Optional.ofNullable( number ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramMapper.java new file mode 100644 index 0000000000..e2737f8e3b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Collection; +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ProgramMapper { + + ProgramMapper INSTANCE = Mappers.getMapper( ProgramMapper.class ); + + ProgramResponseDto map(ProgramAggregate programAggregate); + + ProgramDto map(Program sourceProgramDto); + + Collection mapPrograms(Collection sourcePrograms); + + default T fromOptional(Optional optional) { + return optional.orElse( null ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramResponseDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramResponseDto.java new file mode 100644 index 0000000000..61e7df4d00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/ProgramResponseDto.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2233; + +import java.util.Collection; +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class ProgramResponseDto { + + private final Collection programs; + + public ProgramResponseDto(Collection programs) { + this.programs = programs; + } + + public Optional> getPrograms() { + return Optional.ofNullable( programs ); + } +} From c2e803403027f3fae92bd15b0ba50ab7df5063e6 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Wed, 21 Oct 2020 20:02:28 +0200 Subject: [PATCH 0525/1006] 861 remove compiler specific workarounds (#2227) --- .../ap/internal/model/GeneratedType.java | 6 +- .../internal/model/MappingBuilderContext.java | 16 +- .../ap/internal/model/ValueMappingMethod.java | 4 +- .../ap/internal/model/common/BuilderType.java | 4 +- .../ap/internal/model/common/Type.java | 25 +- .../ap/internal/model/common/TypeFactory.java | 20 +- .../model/source/BeanMappingOptions.java | 8 +- .../internal/model/source/DefaultOptions.java | 4 +- .../model/source/DelegatingOptions.java | 4 +- .../model/source/IterableMappingOptions.java | 8 +- .../model/source/MapMappingOptions.java | 11 +- .../model/source/MapperConfigOptions.java | 4 +- .../internal/model/source/MapperOptions.java | 4 +- .../internal/model/source/MappingControl.java | 8 +- .../internal/model/source/MappingOptions.java | 11 +- .../internal/model/source/MethodMatcher.java | 16 +- .../model/source/SelectionParameters.java | 8 +- .../internal/model/source/SourceMethod.java | 8 +- .../source/selector/MethodSelectors.java | 6 +- .../source/selector/QualifierSelector.java | 8 +- .../source/selector/TargetTypeSelector.java | 6 +- .../selector/XmlElementDeclSelector.java | 6 +- .../DefaultModelElementProcessorContext.java | 19 +- .../processor/MapperCreationProcessor.java | 8 +- .../processor/MethodRetrievalProcessor.java | 30 +- .../processor/ModelElementProcessor.java | 10 +- .../creation/MappingResolverImpl.java | 8 +- .../util/AbstractElementUtilsDecorator.java | 286 ++++++++++++++++++ ...r.java => AbstractTypeUtilsDecorator.java} | 36 +-- .../ap/internal/util/ClassUtils.java | 4 +- .../util/EclipseElementUtilsDecorator.java | 40 +++ .../util/EclipseTypeUtilsDecorator.java | 15 + .../ap/internal/util/ElementUtils.java | 46 +++ .../ap/internal/util/Executables.java | 157 ---------- .../mapstruct/ap/internal/util/Fields.java | 53 ---- .../mapstruct/ap/internal/util/Filters.java | 5 +- .../util/JavacElementUtilsDecorator.java | 21 ++ .../util/JavacTypeUtilsDecorator.java | 15 + .../mapstruct/ap/internal/util/TypeUtils.java | 26 ++ .../EclipseAsMemberOfWorkaround.java | 182 ----------- .../workarounds/EclipseClassLoaderBridge.java | 75 ----- .../SpecificCompilerWorkarounds.java | 140 --------- .../model/source/SelectionParametersTest.java | 9 +- 43 files changed, 610 insertions(+), 770 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java rename processor/src/main/java/org/mapstruct/ap/internal/util/{workarounds/TypesDecorator.java => AbstractTypeUtilsDecorator.java} (75%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/JavacTypeUtilsDecorator.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/TypeUtils.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index a03f9af9a0..a6f573d4ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -12,7 +12,7 @@ import java.util.TreeSet; import javax.lang.model.type.TypeKind; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.ModelElement; @@ -35,7 +35,7 @@ protected abstract static class GeneratedTypeBuilder extraImportedTypes; @@ -46,7 +46,7 @@ protected abstract static class GeneratedTypeBuilder qualifiers = beanMapping.qualifiedBy().get(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 1b34f4698d..b94bb82efd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -9,7 +9,7 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.BuilderInfo; @@ -84,7 +84,7 @@ public Collection getBuildMethods() { } public static BuilderType create(BuilderInfo builderInfo, Type typeToBuild, TypeFactory typeFactory, - Types typeUtils) { + TypeUtils typeUtils) { if ( builderInfo == null ) { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index b2b12b8a25..910af60d40 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -28,22 +28,21 @@ import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; import javax.lang.model.util.ElementFilter; -import javax.lang.model.util.Elements; import javax.lang.model.util.SimpleTypeVisitor8; -import javax.lang.model.util.Types; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.AccessorNamingUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.Executables; -import org.mapstruct.ap.internal.util.Fields; import org.mapstruct.ap.internal.util.Filters; import org.mapstruct.ap.internal.util.JavaStreamConstants; +import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Nouns; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.util.Collections.first; -import org.mapstruct.ap.internal.util.NativeTypes; /** * Represents (a reference to) the type of a bean property, parameter etc. Types are managed per generated source file. @@ -57,8 +56,8 @@ */ public class Type extends ModelElement implements Comparable { - private final Types typeUtils; - private final Elements elementUtils; + private final TypeUtils typeUtils; + private final ElementUtils elementUtils; private final TypeFactory typeFactory; private final AccessorNamingUtils accessorNaming; @@ -109,7 +108,7 @@ public class Type extends ModelElement implements Comparable { private final Filters filters; //CHECKSTYLE:OFF - public Type(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, + public Type(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFactory, AccessorNamingUtils accessorNaming, TypeMirror typeMirror, TypeElement typeElement, List typeParameters, ImplementationType implementationType, Type componentType, @@ -662,7 +661,7 @@ else if ( candidate.getAccessorType() == AccessorType.GETTER private List getAllMethods() { if ( allMethods == null ) { - allMethods = Executables.getAllEnclosedExecutableElements( elementUtils, typeElement ); + allMethods = elementUtils.getAllEnclosedExecutableElements( typeElement ); } return allMethods; @@ -670,7 +669,7 @@ private List getAllMethods() { private List getAllFields() { if ( allFields == null ) { - allFields = Fields.getAllEnclosedFields( elementUtils, typeElement ); + allFields = elementUtils.getAllEnclosedFields( typeElement ); } return allFields; @@ -861,7 +860,7 @@ private boolean isCollection(TypeMirror candidate) { private boolean isStream(TypeMirror candidate) { TypeElement streamTypeElement = elementUtils.getTypeElement( JavaStreamConstants.STREAM_FQN ); TypeMirror streamType = streamTypeElement == null ? null : typeUtils.erasure( streamTypeElement.asType() ); - return streamType != null && typeUtils.isSubtype( candidate, streamType ); + return streamType != null && typeUtils.isSubtypeErased( candidate, streamType ); } private boolean isMap(TypeMirror candidate) { @@ -871,7 +870,7 @@ private boolean isMap(TypeMirror candidate) { private boolean isSubType(TypeMirror candidate, Class clazz) { String className = clazz.getCanonicalName(); TypeMirror classType = typeUtils.erasure( elementUtils.getTypeElement( className ).asType() ); - return typeUtils.isSubtype( candidate, classType ); + return typeUtils.isSubtypeErased( candidate, classType ); } /** @@ -1141,9 +1140,9 @@ public Type resolveTypeVarToType(Type declaredType, Type parameterizedType) { private static class TypeVarMatcher extends SimpleTypeVisitor8 { private TypeVariable typeVarToMatch; - private Types types; + private TypeUtils types; - TypeVarMatcher( Types types, Type typeVarToMatch ) { + TypeVarMatcher(TypeUtils types, Type typeVarToMatch ) { super( null ); this.typeVarToMatch = (TypeVariable) typeVarToMatch.getTypeMirror(); this.types = types; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index ba1dcc1920..8d3d215c52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -36,8 +36,8 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.util.AnnotationProcessingException; @@ -81,8 +81,8 @@ public class TypeFactory { return sb.toString(); }; - private final Elements elementUtils; - private final Types typeUtils; + private final ElementUtils elementUtils; + private final TypeUtils typeUtils; private final FormattingMessager messager; private final RoundContext roundContext; @@ -97,8 +97,8 @@ public class TypeFactory { private final boolean loggingVerbose; - public TypeFactory(Elements elementUtils, Types typeUtils, FormattingMessager messager, RoundContext roundContext, - Map notToBeImportedTypes, boolean loggingVerbose) { + public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMessager messager, + RoundContext roundContext, Map notToBeImportedTypes, boolean loggingVerbose) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; @@ -198,10 +198,10 @@ private Type getType(TypeMirror mirror, boolean isLiteral) { ImplementationType implementationType = getImplementationType( mirror ); - boolean isIterableType = typeUtils.isSubtype( mirror, iterableType ); - boolean isCollectionType = typeUtils.isSubtype( mirror, collectionType ); - boolean isMapType = typeUtils.isSubtype( mirror, mapType ); - boolean isStreamType = streamType != null && typeUtils.isSubtype( mirror, streamType ); + boolean isIterableType = typeUtils.isSubtypeErased( mirror, iterableType ); + boolean isCollectionType = typeUtils.isSubtypeErased( mirror, collectionType ); + boolean isMapType = typeUtils.isSubtypeErased( mirror, mapType ); + boolean isStreamType = streamType != null && typeUtils.isSubtypeErased( mirror, streamType ); boolean isEnumType; boolean isInterface; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index d8fd67510e..d600ed0fc0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -11,8 +11,8 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.gem.BeanMappingGem; @@ -50,7 +50,7 @@ public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, - Types typeUtils, TypeFactory typeFactory + TypeUtils typeUtils, TypeFactory typeFactory ) { if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) { BeanMappingOptions options = new BeanMappingOptions( null, null, mapperOptions ); @@ -143,7 +143,7 @@ public BuilderGem getBuilder() { } @Override - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::mappingControl ) .filter( GemValue::hasValue ) .map( GemValue::getValue ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 81f870e25b..4d80bf57be 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -9,7 +9,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -124,7 +124,7 @@ public BuilderGem getBuilder() { } @Override - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return MappingControl.fromTypeMirror( mapper.mappingControl().getDefaultValue(), elementUtils ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index c458681988..564358ec98 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -10,7 +10,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -101,7 +101,7 @@ public BuilderGem getBuilder() { return next.getBuilder(); } - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return next.getMappingControl( elementUtils ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index 73ae1907cf..40b5b25353 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -8,8 +8,8 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.gem.IterableMappingGem; @@ -31,7 +31,7 @@ public class IterableMappingOptions extends DelegatingOptions { public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, MapperOptions mappperOptions, ExecutableElement method, - FormattingMessager messager, Types typeUtils) { + FormattingMessager messager, TypeUtils typeUtils) { if ( iterableMapping == null || !isConsistent( iterableMapping, method, messager ) ) { IterableMappingOptions options = new IterableMappingOptions( null, null, null, mappperOptions ); @@ -102,7 +102,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } - public MappingControl getElementMappingControl(Elements elementUtils) { + public MappingControl getElementMappingControl(ElementUtils elementUtils) { return Optional.ofNullable( iterableMapping ).map( IterableMappingGem::elementMappingControl ) .filter( GemValue::hasValue ) .map( GemValue::getValue ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index 96ff577f48..c35a8e363d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -8,8 +8,8 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.gem.MapMappingGem; @@ -32,7 +32,8 @@ public class MapMappingOptions extends DelegatingOptions { private final MapMappingGem mapMapping; public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapperOptions, - ExecutableElement method, FormattingMessager messager, Types typeUtils) { + ExecutableElement method, FormattingMessager messager, + TypeUtils typeUtils) { if ( mapMapping == null || !isConsistent( mapMapping, method, messager ) ) { MapMappingOptions options = new MapMappingOptions( @@ -146,7 +147,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } - public MappingControl getKeyMappingControl(Elements elementUtils) { + public MappingControl getKeyMappingControl(ElementUtils elementUtils) { return Optional.ofNullable( mapMapping ).map( MapMappingGem::keyMappingControl ) .filter( GemValue::hasValue ) .map( GemValue::getValue ) @@ -154,7 +155,7 @@ public MappingControl getKeyMappingControl(Elements elementUtils) { .orElse( next().getMappingControl( elementUtils ) ); } - public MappingControl getValueMappingControl(Elements elementUtils) { + public MappingControl getValueMappingControl(ElementUtils elementUtils) { return Optional.ofNullable( mapMapping ).map( MapMappingGem::valueMappingControl ) .filter( GemValue::hasValue ) .map( GemValue::getValue ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index 07f668e655..7f8df7bf42 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -8,7 +8,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -132,7 +132,7 @@ public BuilderGem getBuilder() { } @Override - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return mapperConfig.mappingControl().hasValue() ? MappingControl.fromTypeMirror( mapperConfig.mappingControl().getValue(), elementUtils ) : next().getMappingControl( elementUtils ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index b054c628a9..b916cd2de5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -12,7 +12,7 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -162,7 +162,7 @@ public BuilderGem getBuilder() { } @Override - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return mapper.mappingControl().hasValue() ? MappingControl.fromTypeMirror( mapper.mappingControl().getValue(), elementUtils ) : next().getMappingControl( elementUtils ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java index fc896bb52e..ab2957086f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingControl.java @@ -14,7 +14,7 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.gem.MappingControlGem; import org.mapstruct.ap.internal.gem.MappingControlUseGem; @@ -32,7 +32,7 @@ public class MappingControl { private boolean allowMappingMethod = false; private boolean allow2Steps = false; - public static MappingControl fromTypeMirror(TypeMirror mirror, Elements elementUtils) { + public static MappingControl fromTypeMirror(TypeMirror mirror, ElementUtils elementUtils) { MappingControl mappingControl = new MappingControl(); if ( TypeKind.DECLARED == mirror.getKind() ) { resolveControls( mappingControl, ( (DeclaredType) mirror ).asElement(), new HashSet<>(), elementUtils ); @@ -60,7 +60,7 @@ public boolean allowBy2Steps() { } private static void resolveControls(MappingControl control, Element element, Set handledElements, - Elements elementUtils) { + ElementUtils elementUtils) { for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { Element lElement = annotationMirror.getAnnotationType().asElement(); if ( isAnnotation( lElement, MAPPING_CONTROL_FQN ) ) { @@ -102,7 +102,7 @@ private static void determineMappingControl(MappingControl in, MappingControlGem } } - private static boolean isAnnotationInPackage(Element element, String packageFQN, Elements elementUtils) { + private static boolean isAnnotationInPackage(Element element, String packageFQN, ElementUtils elementUtils) { if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index b826295f75..9db1b1c04c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -18,8 +18,8 @@ import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.MappingGem; import org.mapstruct.ap.internal.gem.MappingsGem; @@ -93,7 +93,7 @@ public static Set getMappingTargetNamesBy(Predicate pred public static void addInstances(MappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - FormattingMessager messager, Types typeUtils, + FormattingMessager messager, TypeUtils typeUtils, Set mappings) { for ( MappingGem mapping : gem.value().getValue() ) { @@ -102,7 +102,8 @@ public static void addInstances(MappingsGem gem, ExecutableElement method, } public static void addInstance(MappingGem mapping, ExecutableElement method, - BeanMappingOptions beanMappingOptions, FormattingMessager messager, Types typeUtils, + BeanMappingOptions beanMappingOptions, FormattingMessager messager, + TypeUtils typeUtils, Set mappings) { if ( !isConsistent( mapping, method, messager ) ) { @@ -421,7 +422,7 @@ public NullValuePropertyMappingStrategyGem getNullValuePropertyMappingStrategy() } @Override - public MappingControl getMappingControl(Elements elementUtils) { + public MappingControl getMappingControl(ElementUtils elementUtils) { return Optional.ofNullable( mapping ).map( MappingGem::mappingControl ) .filter( GemValue::hasValue ) .map( GemValue::getValue ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 2c509924c0..ea3f720440 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -19,7 +19,7 @@ import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; import javax.lang.model.util.SimpleTypeVisitor6; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -53,10 +53,10 @@ public class MethodMatcher { private final SourceMethod candidateMethod; - private final Types typeUtils; + private final TypeUtils typeUtils; private final TypeFactory typeFactory; - MethodMatcher(Types typeUtils, TypeFactory typeFactory, SourceMethod candidateMethod) { + MethodMatcher(TypeUtils typeUtils, TypeFactory typeFactory, SourceMethod candidateMethod) { this.typeUtils = typeUtils; this.candidateMethod = candidateMethod; this.typeFactory = typeFactory; @@ -312,8 +312,8 @@ public Boolean visitTypeVariable(TypeVariable t, TypeMirror p) { // check if types are in bound TypeMirror lowerBound = t.getLowerBound(); TypeMirror upperBound = t.getUpperBound(); - if ( ( isNullType( lowerBound ) || typeUtils.isSubtype( lowerBound, p ) ) - && ( isNullType( upperBound ) || typeUtils.isSubtype( p, upperBound ) ) ) { + if ( ( isNullType( lowerBound ) || typeUtils.isSubtypeErased( lowerBound, p ) ) + && ( isNullType( upperBound ) || typeUtils.isSubtypeErased( p, upperBound ) ) ) { genericTypesMap.put( t, p ); return Boolean.TRUE; } @@ -359,7 +359,7 @@ public Boolean visitWildcard(WildcardType t, TypeMirror p) { // for example method: String method(? super String) // to check super type, we can simply inverse the argument, but that would initially yield // a result: bounds = tpe != null ? tpe.getBounds() : null; if ( t != null && bounds != null ) { for ( TypeMirror bound : bounds ) { - if ( !( bound.getKind() == TypeKind.DECLARED && typeUtils.isSubtype( t, bound ) ) ) { + if ( !( bound.getKind() == TypeKind.DECLARED && typeUtils.isSubtypeErased( t, bound ) ) ) { return false; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index ed6851d9a1..a78409582d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -9,7 +9,7 @@ import java.util.List; import java.util.Objects; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.SourceRHS; @@ -24,7 +24,7 @@ public class SelectionParameters { private final List qualifiers; private final List qualifyingNames; private final TypeMirror resultType; - private final Types typeUtils; + private final TypeUtils typeUtils; private final SourceRHS sourceRHS; /** @@ -45,12 +45,12 @@ public static SelectionParameters forInheritance(SelectionParameters selectionPa } public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, - Types typeUtils) { + TypeUtils typeUtils) { this( qualifiers, qualifyingNames, resultType, typeUtils, null ); } private SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, - Types typeUtils, SourceRHS sourceRHS) { + TypeUtils typeUtils, SourceRHS sourceRHS) { this.qualifiers = qualifiers; this.qualifyingNames = qualifyingNames; this.resultType = resultType; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 98cffb4c35..bac1346d97 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -13,7 +13,7 @@ import java.util.stream.Collectors; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Parameter; @@ -37,7 +37,7 @@ */ public class SourceMethod implements Method { - private final Types typeUtils; + private final TypeUtils typeUtils; private final TypeFactory typeFactory; private final Type declaringMapper; @@ -82,7 +82,7 @@ public static class Builder { private IterableMappingOptions iterableMapping = null; private MapMappingOptions mapMapping = null; private BeanMappingOptions beanMapping = null; - private Types typeUtils; + private TypeUtils typeUtils; private TypeFactory typeFactory = null; private MapperOptions mapper = null; private List prototypeMethods = Collections.emptyList(); @@ -146,7 +146,7 @@ public Builder setEnumMappingOptions(EnumMappingOptions enumMappingOptions) { return this; } - public Builder setTypeUtils(Types typeUtils) { + public Builder setTypeUtils(TypeUtils typeUtils) { this.typeUtils = typeUtils; return this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 5bfbe84497..74fedcb75d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -8,8 +8,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -25,7 +25,7 @@ public class MethodSelectors { private final List selectors; - public MethodSelectors(Types typeUtils, Elements elementUtils, TypeFactory typeFactory, + public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFactory, FormattingMessager messager) { selectors = Arrays.asList( new MethodFamilySelector(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 27ad9eb60d..bca471f9c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -12,8 +12,8 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; @@ -40,10 +40,10 @@ */ public class QualifierSelector implements MethodSelector { - private final Types typeUtils; + private final TypeUtils typeUtils; private final TypeMirror namedAnnotationTypeMirror; - public QualifierSelector( Types typeUtils, Elements elementUtils ) { + public QualifierSelector(TypeUtils typeUtils, ElementUtils elementUtils ) { this.typeUtils = typeUtils; namedAnnotationTypeMirror = elementUtils.getTypeElement( "org.mapstruct.Named" ).asType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index 1cbcb6927e..ad1a5d47b5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -9,7 +9,7 @@ import java.util.List; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; @@ -24,9 +24,9 @@ */ public class TargetTypeSelector implements MethodSelector { - private final Types typeUtils; + private final TypeUtils typeUtils; - public TargetTypeSelector( Types typeUtils ) { + public TargetTypeSelector( TypeUtils typeUtils ) { this.typeUtils = typeUtils; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index c3c394aefd..ecf6657991 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -11,7 +11,7 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.XmlElementRefGem; import org.mapstruct.ap.internal.model.common.Type; @@ -37,9 +37,9 @@ */ public class XmlElementDeclSelector implements MethodSelector { - private final Types typeUtils; + private final TypeUtils typeUtils; - public XmlElementDeclSelector(Types typeUtils) { + public XmlElementDeclSelector(TypeUtils typeUtils) { this.typeUtils = typeUtils; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 1514f4f5e1..d6a05cec32 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -13,18 +13,17 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext; import org.mapstruct.ap.internal.util.AccessorNamingUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.RoundContext; -import org.mapstruct.ap.internal.util.workarounds.TypesDecorator; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.version.VersionInformation; import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; @@ -41,7 +40,8 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final Options options; private final TypeFactory typeFactory; private final VersionInformation versionInformation; - private final Types delegatingTypes; + private final TypeUtils delegatingTypes; + private final ElementUtils delegatingElements; private final AccessorNamingUtils accessorNaming; private final RoundContext roundContext; @@ -52,10 +52,11 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir this.messager = new DelegatingMessager( processingEnvironment.getMessager(), options.isVerbose() ); this.accessorNaming = roundContext.getAnnotationProcessorContext().getAccessorNaming(); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); - this.delegatingTypes = new TypesDecorator( processingEnvironment, versionInformation ); + this.delegatingTypes = TypeUtils.create( processingEnvironment, versionInformation ); + this.delegatingElements = ElementUtils.create( processingEnvironment, versionInformation ); this.roundContext = roundContext; this.typeFactory = new TypeFactory( - processingEnvironment.getElementUtils(), + delegatingElements, delegatingTypes, messager, roundContext, @@ -71,13 +72,13 @@ public Filer getFiler() { } @Override - public Types getTypeUtils() { + public TypeUtils getTypeUtils() { return delegatingTypes; } @Override - public Elements getElementUtils() { - return processingEnvironment.getElementUtils(); + public ElementUtils getElementUtils() { + return delegatingElements; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 25632350be..a0014f5934 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -18,8 +18,8 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.BeanMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethod; @@ -73,8 +73,8 @@ */ public class MapperCreationProcessor implements ModelElementProcessor, Mapper> { - private Elements elementUtils; - private Types typeUtils; + private ElementUtils elementUtils; + private TypeUtils typeUtils; private FormattingMessager messager; private Options options; private VersionInformation versionInformation; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 059a000bc5..693741bcd2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -21,9 +21,15 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeKind; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.gem.BeanMappingGem; +import org.mapstruct.ap.internal.gem.IterableMappingGem; +import org.mapstruct.ap.internal.gem.MapMappingGem; +import org.mapstruct.ap.internal.gem.MappingGem; +import org.mapstruct.ap.internal.gem.MappingsGem; +import org.mapstruct.ap.internal.gem.ObjectFactoryGem; +import org.mapstruct.ap.internal.gem.ValueMappingGem; +import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -36,24 +42,16 @@ import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.ValueMappingOptions; -import org.mapstruct.ap.internal.gem.BeanMappingGem; -import org.mapstruct.ap.internal.gem.IterableMappingGem; -import org.mapstruct.ap.internal.gem.MapMappingGem; -import org.mapstruct.ap.internal.gem.MappingGem; -import org.mapstruct.ap.internal.gem.MappingsGem; -import org.mapstruct.ap.internal.gem.ObjectFactoryGem; -import org.mapstruct.ap.internal.gem.ValueMappingGem; -import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.AnnotationProcessingException; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumTransformationStrategy; -import static org.mapstruct.ap.internal.util.Executables.getAllEnclosedExecutableElements; - /** * A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s * representing all the mapping methods of the given bean mapper type as well as @@ -73,8 +71,8 @@ public class MethodRetrievalProcessor implements ModelElementProcessor enumTransformationStrategies; - private Types typeUtils; - private Elements elementUtils; + private TypeUtils typeUtils; + private ElementUtils elementUtils; private Options options; @Override @@ -119,7 +117,7 @@ private List retrievePrototypeMethods(TypeElement mapperTypeElemen TypeElement typeElement = asTypeElement( mapperAnnotation.mapperConfigType() ); List methods = new ArrayList<>(); - for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, typeElement ) ) { + for ( ExecutableElement executable : elementUtils.getAllEnclosedExecutableElements( typeElement ) ) { ExecutableType methodType = typeFactory.getMethodType( mapperAnnotation.mapperConfigType(), executable ); List parameters = typeFactory.getParameters( methodType, executable ); @@ -160,7 +158,7 @@ private List retrieveMethods(TypeElement usedMapper, TypeElement m MapperOptions mapperOptions, List prototypeMethods) { List methods = new ArrayList<>(); - for ( ExecutableElement executable : getAllEnclosedExecutableElements( elementUtils, usedMapper ) ) { + for ( ExecutableElement executable : elementUtils.getAllEnclosedExecutableElements( usedMapper ) ) { SourceMethod method = getMethod( usedMapper, executable, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index ac0a161a28..d43b52953d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -8,8 +8,8 @@ import java.util.Map; import javax.annotation.processing.Filer; import javax.lang.model.element.TypeElement; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -35,7 +35,7 @@ public interface ModelElementProcessor { /** * Context object passed to * {@link ModelElementProcessor#process(ProcessorContext, TypeElement, Object)} - * providing access to common infrastructure objects such as {@link Types} + * providing access to common infrastructure objects such as {@link TypeUtils} * etc. * * @author Gunnar Morling @@ -44,9 +44,9 @@ public interface ProcessorContext { Filer getFiler(); - Types getTypeUtils(); + TypeUtils getTypeUtils(); - Elements getElementUtils(); + ElementUtils getElementUtils(); TypeFactory getTypeFactory(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 73392a00f8..debe8f30dc 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -32,8 +32,8 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.conversion.ConversionProvider; import org.mapstruct.ap.internal.conversion.Conversions; @@ -78,7 +78,7 @@ public class MappingResolverImpl implements MappingResolver { private static final int LIMIT_REPORTING_AMBIGUOUS = 5; private final FormattingMessager messager; - private final Types typeUtils; + private final TypeUtils typeUtils; private final TypeFactory typeFactory; private final List sourceModel; @@ -98,7 +98,7 @@ public class MappingResolverImpl implements MappingResolver { */ private final Set usedSupportedMappings = new HashSet<>(); - public MappingResolverImpl(FormattingMessager messager, Elements elementUtils, Types typeUtils, + public MappingResolverImpl(FormattingMessager messager, ElementUtils elementUtils, TypeUtils typeUtils, TypeFactory typeFactory, List sourceModel, List mapperReferences, boolean verboseLogging) { this.messager = messager; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java new file mode 100644 index 0000000000..8239dcb41b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java @@ -0,0 +1,286 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.Name; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; + +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; + +import static javax.lang.model.util.ElementFilter.fieldsIn; +import static javax.lang.model.util.ElementFilter.methodsIn; + +public abstract class AbstractElementUtilsDecorator implements ElementUtils { + + private final Elements delegate; + + AbstractElementUtilsDecorator(ProcessingEnvironment processingEnv) { + this.delegate = processingEnv.getElementUtils(); + } + + @Override + public PackageElement getPackageElement(CharSequence name) { + return delegate.getPackageElement( name ); + } + + @Override + public TypeElement getTypeElement(CharSequence name) { + return delegate.getTypeElement( name ); + } + + @Override + public Map getElementValuesWithDefaults( + AnnotationMirror a) { + return delegate.getElementValuesWithDefaults( a ); + } + + @Override + public String getDocComment(Element e) { + return delegate.getDocComment( e ); + } + + @Override + public boolean isDeprecated(Element e) { + return delegate.isDeprecated( e ); + } + + @Override + public Name getBinaryName(TypeElement type) { + return delegate.getBinaryName( type ); + } + + @Override + public PackageElement getPackageOf(Element type) { + return delegate.getPackageOf( type ); + } + + @Override + public List getAllMembers(TypeElement type) { + return delegate.getAllMembers( type ); + } + + @Override + public List getAllAnnotationMirrors(Element e) { + return delegate.getAllAnnotationMirrors( e ); + } + + @Override + public boolean hides(Element hider, Element hidden) { + return delegate.hides( hider, hidden ); + } + + @Override + public boolean overrides(ExecutableElement overrider, ExecutableElement overridden, TypeElement type) { + return delegate.overrides( overrider, overridden, type ); + } + + @Override + public String getConstantExpression(Object value) { + return delegate.getConstantExpression( value ); + } + + @Override + public void printElements(Writer w, Element... elements) { + delegate.printElements( w, elements ); + } + + @Override + public Name getName(CharSequence cs) { + return delegate.getName( cs ); + } + + @Override + public boolean isFunctionalInterface(TypeElement type) { + return delegate.isFunctionalInterface( type ); + } + + @Override + public List getAllEnclosedExecutableElements(TypeElement element) { + List enclosedElements = new ArrayList<>(); + element = replaceTypeElementIfNecessary( element ); + addEnclosedMethodsInHierarchy( enclosedElements, element, element ); + + return enclosedElements; + } + + @Override + public List getAllEnclosedFields( TypeElement element) { + List enclosedElements = new ArrayList<>(); + element = replaceTypeElementIfNecessary( element ); + addEnclosedFieldsInHierarchy( enclosedElements, element, element ); + + return enclosedElements; + } + + private void addEnclosedMethodsInHierarchy(List alreadyAdded, TypeElement element, + TypeElement parentType) { + if ( element != parentType ) { // otherwise the element was already checked for replacement + element = replaceTypeElementIfNecessary( element ); + } + + if ( element.asType().getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( element ); + } + + addMethodNotYetOverridden( alreadyAdded, methodsIn( element.getEnclosedElements() ), parentType ); + + if ( hasNonObjectSuperclass( element ) ) { + addEnclosedMethodsInHierarchy( + alreadyAdded, + asTypeElement( element.getSuperclass() ), + parentType + ); + } + + for ( TypeMirror interfaceType : element.getInterfaces() ) { + addEnclosedMethodsInHierarchy( + alreadyAdded, + asTypeElement( interfaceType ), + parentType + ); + } + + } + + /** + * @param alreadyCollected methods that have already been collected and to which the not-yet-overridden methods will + * be added + * @param methodsToAdd methods to add to alreadyAdded, if they are not yet overridden by an element in the list + * @param parentType the type for with elements are collected + */ + private void addMethodNotYetOverridden(List alreadyCollected, + List methodsToAdd, + TypeElement parentType) { + List safeToAdd = new ArrayList<>( methodsToAdd.size() ); + for ( ExecutableElement toAdd : methodsToAdd ) { + if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd ) + && methodWasNotYetOverridden( alreadyCollected, toAdd, parentType ) ) { + safeToAdd.add( toAdd ); + } + } + + alreadyCollected.addAll( 0, safeToAdd ); + } + + /** + * @param executable the executable to check + * @return {@code true}, iff the executable does not represent {@link java.lang.Object#equals(Object)} or an + * overridden version of it + */ + private boolean isNotObjectEquals(ExecutableElement executable) { + if ( executable.getSimpleName().contentEquals( "equals" ) && executable.getParameters().size() == 1 + && asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedName().contentEquals( + "java.lang.Object" + ) ) { + return false; + } + return true; + } + + /** + * @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to + * super-types) + * @param executable the method to check + * @param parentType the type for which elements are collected + * @return {@code true}, iff the given executable was not yet overridden by a method in the given list. + */ + private boolean methodWasNotYetOverridden(List alreadyCollected, + ExecutableElement executable, TypeElement parentType) { + for ( ListIterator it = alreadyCollected.listIterator(); it.hasNext(); ) { + ExecutableElement executableInSubtype = it.next(); + if ( executableInSubtype == null ) { + continue; + } + if ( delegate.overrides( executableInSubtype, executable, parentType ) ) { + return false; + } + else if ( delegate.overrides( executable, executableInSubtype, parentType ) ) { + // remove the method from another interface hierarchy that is overridden by the executable to add + it.remove(); + return true; + } + } + + return true; + } + + private void addEnclosedFieldsInHierarchy( List alreadyAdded, + TypeElement element, TypeElement parentType) { + if ( element != parentType ) { // otherwise the element was already checked for replacement + element = replaceTypeElementIfNecessary( element ); + } + + if ( element.asType().getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( element ); + } + + addFields( alreadyAdded, fieldsIn( element.getEnclosedElements() ) ); + + if ( hasNonObjectSuperclass( element ) ) { + addEnclosedFieldsInHierarchy( + alreadyAdded, + asTypeElement( element.getSuperclass() ), + parentType + ); + } + } + + private static void addFields(List alreadyCollected, List variablesToAdd) { + List safeToAdd = new ArrayList<>( variablesToAdd.size() ); + safeToAdd.addAll( variablesToAdd ); + + alreadyCollected.addAll( 0, safeToAdd ); + } + + /** + * @param element the type element to check + * @return {@code true}, iff the type has a super-class that is not java.lang.Object + */ + private boolean hasNonObjectSuperclass(TypeElement element) { + if ( element.getSuperclass().getKind() == TypeKind.ERROR ) { + throw new TypeHierarchyErroneousException( element ); + } + + return element.getSuperclass().getKind() == TypeKind.DECLARED + && !asTypeElement( element.getSuperclass() ).getQualifiedName().toString().equals( "java.lang.Object" ); + } + + /** + * @param mirror the type positionHint + * @return the corresponding type element + */ + private TypeElement asTypeElement(TypeMirror mirror) { + return (TypeElement) ( (DeclaredType) mirror ).asElement(); + } + + /** + * @param executable the executable to check + * @return {@code true}, iff the executable does not have a private modifier + */ + private boolean isNotPrivate(ExecutableElement executable) { + return !executable.getModifiers().contains( Modifier.PRIVATE ); + } + + protected abstract TypeElement replaceTypeElementIfNecessary(TypeElement element); + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractTypeUtilsDecorator.java similarity index 75% rename from processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java rename to processor/src/main/java/org/mapstruct/ap/internal/util/AbstractTypeUtilsDecorator.java index 097ab52631..2f7c4d604d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/TypesDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractTypeUtilsDecorator.java @@ -3,10 +3,9 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.util.workarounds; +package org.mapstruct.ap.internal.util; import java.util.List; - import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; @@ -21,23 +20,18 @@ import javax.lang.model.type.WildcardType; import javax.lang.model.util.Types; -import org.mapstruct.ap.internal.version.VersionInformation; - /** - * Replaces the usage of {@link Types} within MapStruct by delegating to the original implementation or to our specific - * workarounds if necessary. + * Replaces the usage of {@link TypeUtils} within MapStruct by delegating to the original implementation or to our + * specific workarounds if necessary. * * @author Andreas Gudian */ -public class TypesDecorator implements Types { +public abstract class AbstractTypeUtilsDecorator implements TypeUtils { + private final Types delegate; - private final ProcessingEnvironment processingEnv; - private final VersionInformation versionInformation; - public TypesDecorator(ProcessingEnvironment processingEnv, VersionInformation versionInformation) { + AbstractTypeUtilsDecorator(ProcessingEnvironment processingEnv) { this.delegate = processingEnv.getTypeUtils(); - this.processingEnv = processingEnv; - this.versionInformation = versionInformation; } @Override @@ -52,12 +46,12 @@ public boolean isSameType(TypeMirror t1, TypeMirror t2) { @Override public boolean isSubtype(TypeMirror t1, TypeMirror t2) { - return SpecificCompilerWorkarounds.isSubtype( delegate, t1, t2 ); + return delegate.isSubtype( t1, t2 ); } @Override public boolean isAssignable(TypeMirror t1, TypeMirror t2) { - return SpecificCompilerWorkarounds.isAssignable( delegate, t1, t2 ); + return delegate.isAssignable( t1, t2 ); } @Override @@ -77,7 +71,7 @@ public List directSupertypes(TypeMirror t) { @Override public TypeMirror erasure(TypeMirror t) { - return SpecificCompilerWorkarounds.erasure( delegate, t ); + return delegate.erasure( t ); } @Override @@ -132,11 +126,11 @@ public DeclaredType getDeclaredType(DeclaredType containing, TypeElement typeEle @Override public TypeMirror asMemberOf(DeclaredType containing, Element element) { - return SpecificCompilerWorkarounds.asMemberOf( - delegate, - processingEnv, - versionInformation, - containing, - element ); + return delegate.asMemberOf( containing, element ); + } + + @Override + public boolean isSubtypeErased(TypeMirror t1, TypeMirror t2) { + return delegate.isSubtype( erasure( t1 ), erasure( t2 ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java index 889b729318..d66d81f9b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java @@ -6,9 +6,9 @@ package org.mapstruct.ap.internal.util; /** - * Utilities for working with classes. It is mainly needed because using the {@link javax.lang.model.util.Elements} + * Utilities for working with classes. It is mainly needed because using the {@link ElementUtils} * is not always correct. For example when compiling with JDK 9 and source version 8 classes from different modules - * are available by {@link javax.lang.model.util.Elements#getTypeElement(CharSequence)} but they are actually not + * are available by {@link ElementUtils#getTypeElement(CharSequence)} but they are actually not * if those modules are not added during compilation. * * @author Filip Hrisafov diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java new file mode 100644 index 0000000000..aaf1bb7e20 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.Elements; + +public class EclipseElementUtilsDecorator extends AbstractElementUtilsDecorator { + + private final Elements delegate; + + EclipseElementUtilsDecorator(ProcessingEnvironment processingEnv) { + super( processingEnv ); + this.delegate = processingEnv.getElementUtils(); + } + + /** + * When running during Eclipse Incremental Compilation, we might get a TypeElement that has an UnresolvedTypeBinding + * and which is not automatically resolved. In that case, getEnclosedElements returns an empty list. We take that as + * a hint to check if the TypeElement resolved by FQN might have any enclosed elements and, if so, return the + * resolved element. + * + * @param element the original element + * @return the element freshly resolved using the qualified name, if the original element did not return any + * enclosed elements, whereas the resolved element does return enclosed elements. + */ + protected TypeElement replaceTypeElementIfNecessary(TypeElement element) { + if ( element.getEnclosedElements().isEmpty() ) { + TypeElement resolvedByName = delegate.getTypeElement( element.getQualifiedName() ); + if ( resolvedByName != null && !resolvedByName.getEnclosedElements().isEmpty() ) { + return resolvedByName; + } + } + return element; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java new file mode 100644 index 0000000000..ce01d99de8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import javax.annotation.processing.ProcessingEnvironment; + +public class EclipseTypeUtilsDecorator extends AbstractTypeUtilsDecorator { + + EclipseTypeUtilsDecorator(ProcessingEnvironment processingEnv) { + super( processingEnv ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java new file mode 100644 index 0000000000..fdd221c1a6 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.util.List; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.util.Elements; + +import org.mapstruct.ap.internal.version.VersionInformation; + +public interface ElementUtils extends Elements { + + static ElementUtils create(ProcessingEnvironment processingEnvironment, VersionInformation info ) { + if ( info.isEclipseJDTCompiler() ) { + return new EclipseElementUtilsDecorator( processingEnvironment ); + } + else { + return new JavacElementUtilsDecorator( processingEnvironment ); + } + } + + /** + * Finds all executable elements within the given type element, including executable elements defined in super + * classes and implemented interfaces. Methods defined in {@link java.lang.Object}, + * implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored + * + * @param element the element to inspect + * @return the executable elements usable in the type + */ + List getAllEnclosedExecutableElements(TypeElement element); + + /** + * Finds all variable elements within the given type element, including variable + * elements defined in super classes and implemented interfaces and including the fields in the . + * + * @param element the element to inspect + * @return the executable elements usable in the type + */ + List getAllEnclosedFields(TypeElement element); +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java index b6de4662b1..1592a39fda 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Executables.java @@ -7,24 +7,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; import org.mapstruct.ap.internal.gem.AfterMappingGem; import org.mapstruct.ap.internal.gem.BeforeMappingGem; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.spi.TypeHierarchyErroneousException; - -import static javax.lang.model.util.ElementFilter.methodsIn; -import static org.mapstruct.ap.internal.util.workarounds.SpecificCompilerWorkarounds.replaceTypeElementIfNecessary; /** * Provides functionality around {@link ExecutableElement}s. @@ -74,151 +62,6 @@ public static boolean isDefaultMethod(ExecutableElement method) { } } - /** - * @param mirror the type positionHint - * - * @return the corresponding type element - */ - private static TypeElement asTypeElement(TypeMirror mirror) { - return (TypeElement) ( (DeclaredType) mirror ).asElement(); - } - - /** - * Finds all executable elements within the given type element, including executable elements defined in super - * classes and implemented interfaces. Methods defined in {@link java.lang.Object}, - * implementations of {@link java.lang.Object#equals(Object)} and private methods are ignored - * - * @param elementUtils element helper - * @param element the element to inspect - * - * @return the executable elements usable in the type - */ - public static List getAllEnclosedExecutableElements(Elements elementUtils, TypeElement element) { - List enclosedElements = new ArrayList<>(); - element = replaceTypeElementIfNecessary( elementUtils, element ); - addEnclosedElementsInHierarchy( elementUtils, enclosedElements, element, element ); - - return enclosedElements; - } - - private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyAdded, - TypeElement element, TypeElement parentType) { - if ( element != parentType ) { // otherwise the element was already checked for replacement - element = replaceTypeElementIfNecessary( elementUtils, element ); - } - - if ( element.asType().getKind() == TypeKind.ERROR ) { - throw new TypeHierarchyErroneousException( element ); - } - - addNotYetOverridden( elementUtils, alreadyAdded, methodsIn( element.getEnclosedElements() ), parentType ); - - if ( hasNonObjectSuperclass( element ) ) { - addEnclosedElementsInHierarchy( - elementUtils, - alreadyAdded, - asTypeElement( element.getSuperclass() ), - parentType - ); - } - - for ( TypeMirror interfaceType : element.getInterfaces() ) { - addEnclosedElementsInHierarchy( - elementUtils, - alreadyAdded, - asTypeElement( interfaceType ), - parentType - ); - } - - } - - /** - * @param alreadyCollected methods that have already been collected and to which the not-yet-overridden methods will - * be added - * @param methodsToAdd methods to add to alreadyAdded, if they are not yet overridden by an element in the list - * @param parentType the type for with elements are collected - */ - private static void addNotYetOverridden(Elements elementUtils, List alreadyCollected, - List methodsToAdd, TypeElement parentType) { - List safeToAdd = new ArrayList<>( methodsToAdd.size() ); - for ( ExecutableElement toAdd : methodsToAdd ) { - if ( isNotPrivate( toAdd ) && isNotObjectEquals( toAdd ) - && wasNotYetOverridden( elementUtils, alreadyCollected, toAdd, parentType ) ) { - safeToAdd.add( toAdd ); - } - } - - alreadyCollected.addAll( 0, safeToAdd ); - } - - /** - * @param executable the executable to check - * - * @return {@code true}, iff the executable does not represent {@link java.lang.Object#equals(Object)} or an - * overridden version of it - */ - private static boolean isNotObjectEquals(ExecutableElement executable) { - if ( executable.getSimpleName().contentEquals( "equals" ) && executable.getParameters().size() == 1 - && asTypeElement( executable.getParameters().get( 0 ).asType() ).getQualifiedName().contentEquals( - "java.lang.Object" - ) ) { - return false; - } - return true; - } - - /** - * @param executable the executable to check - * - * @return {@code true}, iff the executable does not have a private modifier - */ - private static boolean isNotPrivate(ExecutableElement executable) { - return !executable.getModifiers().contains( Modifier.PRIVATE ); - } - - /** - * @param elementUtils the elementUtils - * @param alreadyCollected the list of already collected methods of one type hierarchy (order is from sub-types to - * super-types) - * @param executable the method to check - * @param parentType the type for which elements are collected - * @return {@code true}, iff the given executable was not yet overridden by a method in the given list. - */ - private static boolean wasNotYetOverridden(Elements elementUtils, List alreadyCollected, - ExecutableElement executable, TypeElement parentType) { - for ( ListIterator it = alreadyCollected.listIterator(); it.hasNext(); ) { - ExecutableElement executableInSubtype = it.next(); - if ( executableInSubtype == null ) { - continue; - } - if ( elementUtils.overrides( executableInSubtype, executable, parentType ) ) { - return false; - } - else if ( elementUtils.overrides( executable, executableInSubtype, parentType ) ) { - // remove the method from another interface hierarchy that is overridden by the executable to add - it.remove(); - return true; - } - } - - return true; - } - - /** - * @param element the type element to check - * - * @return {@code true}, iff the type has a super-class that is not java.lang.Object - */ - private static boolean hasNonObjectSuperclass(TypeElement element) { - if ( element.getSuperclass().getKind() == TypeKind.ERROR ) { - throw new TypeHierarchyErroneousException( element ); - } - - return element.getSuperclass().getKind() == TypeKind.DECLARED - && !asTypeElement( element.getSuperclass() ).getQualifiedName().toString().equals( "java.lang.Object" ); - } - /** * @param executableElement the element to check * @return {@code true}, if the executable element is a method annotated with {@code @BeforeMapping} or diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java index f394f4e8f2..8e16a95274 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java @@ -5,21 +5,15 @@ */ package org.mapstruct.ap.internal.util; -import java.util.ArrayList; -import java.util.List; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; -import static javax.lang.model.util.ElementFilter.fieldsIn; -import static org.mapstruct.ap.internal.util.workarounds.SpecificCompilerWorkarounds.replaceTypeElementIfNecessary; - /** * Provides functionality around {@link VariableElement}s. * @@ -42,53 +36,6 @@ private static boolean isNotStatic(VariableElement method) { return !method.getModifiers().contains( Modifier.STATIC ); } - /** - * Finds all variable elements within the given type element, including variable - * elements defined in super classes and implemented interfaces and including the fields in the . - * - * @param elementUtils element helper - * @param element the element to inspect - * - * @return the executable elements usable in the type - */ - public static List getAllEnclosedFields(Elements elementUtils, TypeElement element) { - List enclosedElements = new ArrayList<>(); - element = replaceTypeElementIfNecessary( elementUtils, element ); - addEnclosedElementsInHierarchy( elementUtils, enclosedElements, element, element ); - - return enclosedElements; - } - - private static void addEnclosedElementsInHierarchy(Elements elementUtils, List alreadyAdded, - TypeElement element, TypeElement parentType) { - if ( element != parentType ) { // otherwise the element was already checked for replacement - element = replaceTypeElementIfNecessary( elementUtils, element ); - } - - if ( element.asType().getKind() == TypeKind.ERROR ) { - throw new TypeHierarchyErroneousException( element ); - } - - addFields( alreadyAdded, fieldsIn( element.getEnclosedElements() ) ); - - - if ( hasNonObjectSuperclass( element ) ) { - addEnclosedElementsInHierarchy( - elementUtils, - alreadyAdded, - asTypeElement( element.getSuperclass() ), - parentType - ); - } - } - - private static void addFields(List alreadyCollected, List variablesToAdd) { - List safeToAdd = new ArrayList<>( variablesToAdd.size() ); - safeToAdd.addAll( variablesToAdd ); - - alreadyCollected.addAll( 0, safeToAdd ); - } - private static TypeElement asTypeElement(TypeMirror mirror) { return (TypeElement) ( (DeclaredType) mirror ).asElement(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index f4d52d7095..9cb923b3c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -20,7 +20,6 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.ExecutableType; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; @@ -60,10 +59,10 @@ public class Filters { } private final AccessorNamingUtils accessorNaming; - private final Types typeUtils; + private final TypeUtils typeUtils; private final TypeMirror typeMirror; - public Filters(AccessorNamingUtils accessorNaming, Types typeUtils, TypeMirror typeMirror) { + public Filters(AccessorNamingUtils accessorNaming, TypeUtils typeUtils, TypeMirror typeMirror) { this.accessorNaming = accessorNaming; this.typeUtils = typeUtils; this.typeMirror = typeMirror; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java new file mode 100644 index 0000000000..ad035743cf --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.TypeElement; + +public class JavacElementUtilsDecorator extends AbstractElementUtilsDecorator { + + JavacElementUtilsDecorator(ProcessingEnvironment processingEnv) { + super( processingEnv ); + } + + @Override + protected TypeElement replaceTypeElementIfNecessary(TypeElement element) { + return element; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavacTypeUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacTypeUtilsDecorator.java new file mode 100644 index 0000000000..8b3454e87e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacTypeUtilsDecorator.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import javax.annotation.processing.ProcessingEnvironment; + +public class JavacTypeUtilsDecorator extends AbstractTypeUtilsDecorator { + + JavacTypeUtilsDecorator(ProcessingEnvironment processingEnv) { + super( processingEnv ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/TypeUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/TypeUtils.java new file mode 100644 index 0000000000..926cd5eef8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/TypeUtils.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Types; + +import org.mapstruct.ap.internal.version.VersionInformation; + +public interface TypeUtils extends Types { + + static TypeUtils create(ProcessingEnvironment processingEnvironment, VersionInformation info ) { + if ( info.isEclipseJDTCompiler() ) { + return new EclipseTypeUtilsDecorator( processingEnvironment ); + } + else { + return new JavacTypeUtilsDecorator( processingEnvironment ); + } + } + + boolean isSubtypeErased(TypeMirror t1, TypeMirror t2); +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java deleted file mode 100644 index ab0d681728..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseAsMemberOfWorkaround.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.workarounds; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.Element; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Types; - -import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; -import org.eclipse.jdt.internal.compiler.apt.model.ElementImpl; -import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; -import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; - -/** - * Contains the workaround for {@link Types#asMemberOf(DeclaredType, Element)} using Eclipse implementation types. - *

    - * This class may only be accessed through {@link EclipseClassLoaderBridge} when running within Eclipse - * - * @author Andreas Gudian - */ -final class EclipseAsMemberOfWorkaround { - private EclipseAsMemberOfWorkaround() { - } - - /** - * Eclipse-specific implementation of {@link Types#asMemberOf(DeclaredType, Element)}. - *

    - * Returns {@code null} if the implementation could not determine the result. - */ - static TypeMirror asMemberOf(ProcessingEnvironment environment, DeclaredType containing, - Element element) { - - ElementImpl elementImpl = tryCast( element, ElementImpl.class ); - BaseProcessingEnvImpl env = tryCast( environment, BaseProcessingEnvImpl.class ); - - if ( elementImpl == null || env == null ) { - return null; - } - - ReferenceBinding referenceBinding = - (ReferenceBinding) ( (ElementImpl) environment.getTypeUtils().asElement( containing ) )._binding; - - MethodBinding methodBinding = (MethodBinding) elementImpl._binding; - - // matches in super-classes have priority - MethodBinding inSuperclassHiearchy = findInSuperclassHierarchy( methodBinding, referenceBinding ); - - if ( inSuperclassHiearchy != null ) { - return env.getFactory().newTypeMirror( inSuperclassHiearchy ); - } - - // if nothing was found, traverse the interfaces and collect all candidate methods that match - List candidatesFromInterfaces = new ArrayList<>(); - - collectFromInterfaces( - methodBinding, - referenceBinding, - new HashSet<>(), - candidatesFromInterfaces ); - - // there can be multiple matches for the same method name from adjacent interface hierarchies. - candidatesFromInterfaces.sort( MostSpecificMethodBindingComparator.INSTANCE ); - - if ( !candidatesFromInterfaces.isEmpty() ) { - // return the most specific match - return env.getFactory().newTypeMirror( candidatesFromInterfaces.get( 0 ) ); - } - - return null; - } - - private static T tryCast(Object instance, Class type) { - if ( type.isInstance( instance ) ) { - return type.cast( instance ); - } - - return null; - } - - private static void collectFromInterfaces(MethodBinding methodBinding, ReferenceBinding typeBinding, - Set visitedTypes, List found) { - if ( typeBinding == null ) { - return; - } - - // also check the interfaces of the superclass hierarchy (the superclasses themselves don't contain a match, - // we checked that already) - collectFromInterfaces( methodBinding, typeBinding.superclass(), visitedTypes, found ); - - for ( ReferenceBinding ifc : typeBinding.superInterfaces() ) { - if ( visitedTypes.contains( ifc ) ) { - continue; - } - - visitedTypes.add( ifc ); - - // finding a match in one interface - MethodBinding f = findMatchingMethodBinding( methodBinding, ifc.methods() ); - - if ( f == null ) { - collectFromInterfaces( methodBinding, ifc, visitedTypes, found ); - } - else { - // no need for recursion if we found a candidate in this type already - found.add( f ); - } - } - } - - /** - * @param baseMethod binding to compare against - * @param methods the candidate methods - * @return The method from the list of candidates that matches the name and original/erasure of - * {@code methodBinding}, or {@code null} if none was found. - */ - private static MethodBinding findMatchingMethodBinding(MethodBinding baseMethod, MethodBinding[] methods) { - for ( MethodBinding method : methods ) { - if ( CharOperation.equals( method.selector, baseMethod.selector ) - && ( method.original() == baseMethod || method.areParameterErasuresEqual( baseMethod ) ) ) { - return method; - } - } - - return null; - } - - private static MethodBinding findInSuperclassHierarchy(MethodBinding baseMethod, ReferenceBinding typeBinding) { - while ( typeBinding != null ) { - MethodBinding matching = findMatchingMethodBinding( baseMethod, typeBinding.methods() ); - if ( matching != null ) { - return matching; - } - - typeBinding = typeBinding.superclass(); - } - - return null; - } - - /** - * Compares MethodBindings by their signature: the more specific method is considered lower. - * - * @author Andreas Gudian - */ - private static final class MostSpecificMethodBindingComparator implements Comparator { - private static final MostSpecificMethodBindingComparator INSTANCE = new MostSpecificMethodBindingComparator(); - - @Override - public int compare(MethodBinding first, MethodBinding second) { - boolean firstParamsAssignableFromSecond = - first.areParametersCompatibleWith( second.parameters ); - boolean secondParamsAssignableFromFirst = - second.areParametersCompatibleWith( first.parameters ); - - if ( firstParamsAssignableFromSecond != secondParamsAssignableFromFirst ) { - return firstParamsAssignableFromSecond ? 1 : -1; - } - - if ( TypeBinding.equalsEquals( first.returnType, second.returnType ) ) { - return 0; - } - - boolean firstReturnTypeAssignableFromSecond = - second.returnType.isCompatibleWith( first.returnType ); - - return firstReturnTypeAssignableFromSecond ? 1 : -1; - } - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java deleted file mode 100644 index d7dee52fb4..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/EclipseClassLoaderBridge.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.workarounds; - -import java.lang.reflect.Method; -import java.net.URLClassLoader; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.Element; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; - -/** - * In Eclipse 4.6, the ClassLoader of the annotation processor does not provide access to the implementation types of - * the APT-API anymore, so we need to create a new ClassLoader containing the processor class path URLs and having the - * ClassLoader of the APT-API implementations as parent. The method invocation then consequently needs to be done via - * reflection. - * - * @author Andreas Gudian - */ -class EclipseClassLoaderBridge { - private static final String ECLIPSE_AS_MEMBER_OF_WORKAROUND = - "org.mapstruct.ap.internal.util.workarounds.EclipseAsMemberOfWorkaround"; - - private static ClassLoader classLoader; - private static Method asMemberOf; - - private EclipseClassLoaderBridge() { - } - - /** - * Invokes {@link EclipseAsMemberOfWorkaround#asMemberOf(ProcessingEnvironment, DeclaredType, Element)} via - * reflection using a special ClassLoader. - */ - static TypeMirror invokeAsMemberOfWorkaround(ProcessingEnvironment env, DeclaredType containing, Element element) - throws Exception { - return (TypeMirror) getAsMemberOf( element.getClass().getClassLoader() ).invoke( - null, - env, - containing, - element ); - } - - private static ClassLoader getOrCreateClassLoader(ClassLoader parent) { - if ( classLoader == null ) { - classLoader = new URLClassLoader( - ( (URLClassLoader) EclipseClassLoaderBridge.class.getClassLoader() ).getURLs(), - parent ); - } - - return classLoader; - } - - private static Method getAsMemberOf(ClassLoader platformClassLoader) throws Exception { - if ( asMemberOf == null ) { - Class workaroundClass = - getOrCreateClassLoader( platformClassLoader ).loadClass( ECLIPSE_AS_MEMBER_OF_WORKAROUND ); - - Method found = workaroundClass.getDeclaredMethod( - "asMemberOf", - ProcessingEnvironment.class, - DeclaredType.class, - Element.class ); - - found.setAccessible( true ); - - asMemberOf = found; - } - - return asMemberOf; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java b/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java deleted file mode 100644 index 69b45c1ca7..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/workarounds/SpecificCompilerWorkarounds.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.workarounds; - -import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.Element; -import javax.lang.model.element.TypeElement; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.Elements; -import javax.lang.model.util.Types; - -import org.mapstruct.ap.internal.version.VersionInformation; - -/** - * Contains workarounds for various quirks in specific compilers. - * - * @author Sjaak Derksen - * @author Andreas Gudian - */ -public class SpecificCompilerWorkarounds { - private SpecificCompilerWorkarounds() { - } - - /** - * Tests whether one type is assignable to another, checking for VOID first. - * - * @param types the type utils - * @param t1 the first type - * @param t2 the second type - * @return {@code true} if and only if the first type is assignable to the second - * @throws IllegalArgumentException if given an executable or package type - */ - static boolean isAssignable(Types types, TypeMirror t1, TypeMirror t2) { - if ( t1.getKind() == TypeKind.VOID ) { - return false; - } - - return types.isAssignable( t1, t2 ); - } - - /** - * Tests whether one type is a subtype of another. Any type is considered to be a subtype of itself. Also see JLS section 4.10, Subtyping. - *

    - * Work-around for a bug related to sub-typing in the Eclipse JSR 269 implementation. - * - * @param types the type utils - * @param t1 the first type - * @param t2 the second type - * @return {@code true} if and only if the first type is a subtype of the second - * @throws IllegalArgumentException if given an executable or package type - */ - static boolean isSubtype(Types types, TypeMirror t1, TypeMirror t2) { - if ( t1.getKind() == TypeKind.VOID ) { - return false; - } - - return types.isSubtype( erasure( types, t1 ), erasure( types, t2 ) ); - } - - /** - * Returns the erasure of a type. - *

    - * Performs an additional test on the given type to check if it is not void. Calling - * {@link Types#erasure(TypeMirror)} with a void kind type will create a ClassCastException in Eclipse JDT. See the - * JLS, section 4.6 Type Erasure, for reference. - * - * @param types the type utils - * @param t the type to be erased - * @return the erasure of the given type - * @throws IllegalArgumentException if given a package type - */ - static TypeMirror erasure(Types types, TypeMirror t) { - if ( t.getKind() == TypeKind.VOID || t.getKind() == TypeKind.NULL ) { - return t; - } - else { - return types.erasure( t ); - } - } - - /** - * When running during Eclipse Incremental Compilation, we might get a TypeElement that has an UnresolvedTypeBinding - * and which is not automatically resolved. In that case, getEnclosedElements returns an empty list. We take that as - * a hint to check if the TypeElement resolved by FQN might have any enclosed elements and, if so, return the - * resolved element. - * - * @param elementUtils element utils - * @param element the original element - * @return the element freshly resolved using the qualified name, if the original element did not return any - * enclosed elements, whereas the resolved element does return enclosed elements. - */ - public static TypeElement replaceTypeElementIfNecessary(Elements elementUtils, TypeElement element) { - if ( element.getEnclosedElements().isEmpty() ) { - TypeElement resolvedByName = elementUtils.getTypeElement( element.getQualifiedName() ); - if ( resolvedByName != null && !resolvedByName.getEnclosedElements().isEmpty() ) { - return resolvedByName; - } - } - return element; - } - - /** - * Workaround for Bugs in the Eclipse implementation of {@link Types#asMemberOf(DeclaredType, Element)}. - * - * @see Eclipse Bug 382590 (fixed in Eclipse 4.6) - * @see Eclipse Bug 481555 - */ - static TypeMirror asMemberOf(Types typeUtils, ProcessingEnvironment env, VersionInformation versionInformation, - DeclaredType containing, Element element) { - TypeMirror result = null; - Exception lastException = null; - try { - try { - result = typeUtils.asMemberOf( containing, element ); - } - catch ( IllegalArgumentException e ) { - lastException = e; - if ( versionInformation.isEclipseJDTCompiler() ) { - result = EclipseClassLoaderBridge.invokeAsMemberOfWorkaround( env, containing, element ); - } - } - } - catch ( Exception e ) { - lastException = e; - } - - if ( null == result ) { - throw new RuntimeException( "Fallback implementation of asMemberOf didn't work for " - + element + " in " + containing, lastException ); - } - - return result; - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java index 7f57ae75cb..19e194a764 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java @@ -23,9 +23,9 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVisitor; import javax.lang.model.type.WildcardType; -import javax.lang.model.util.Types; import org.junit.Test; +import org.mapstruct.ap.internal.util.TypeUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -73,7 +73,12 @@ public String toString() { } } - private final Types typeUtils = new Types() { + private final TypeUtils typeUtils = new TypeUtils() { + @Override + public boolean isSubtypeErased(TypeMirror t1, TypeMirror t2) { + throw new UnsupportedOperationException( "isSubTypeErased is not supported" ); + } + @Override public Element asElement(TypeMirror t) { throw new UnsupportedOperationException( "asElement is not supported" ); From 26f62b7ef0f8592196ef342b7fad450a64ae4751 Mon Sep 17 00:00:00 2001 From: Saheb Preet Singh Date: Tue, 20 Oct 2020 21:19:21 +0800 Subject: [PATCH 0526/1006] #607 Mapping Iterable object to an object instead of collection --- .../chapter-6-mapping-collections.asciidoc | 4 +-- .../processor/MethodRetrievalProcessor.java | 8 +++-- .../mapstruct/ap/internal/util/Message.java | 4 +-- .../ErroneousCollectionMappingTest.java | 12 ++++--- ...oneousCollectionToNonCollectionMapper.java | 2 ++ .../iterabletononiterable/Fruit.java | 27 ++++++++++++++ .../iterabletononiterable/FruitSalad.java | 29 +++++++++++++++ .../iterabletononiterable/FruitsMapper.java | 24 +++++++++++++ .../iterabletononiterable/FruitsMenu.java | 35 +++++++++++++++++++ .../IterableToNonIterableMappingTest.java | 26 +++++++++++++- .../erroneous/ErroneousStreamMappingTest.java | 4 +-- 11 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Fruit.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitSalad.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMenu.java diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc index dcce306789..785b460b12 100644 --- a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -90,7 +90,7 @@ carDto.getPassengers().addAll( personsToPersonDtos( car.getPassengers() ) ); [WARNING] ==== -It is not allowed to declare mapping methods with an iterable source and a non-iterable target or the other way around. An error will be raised when detecting this situation. +It is not allowed to declare mapping methods with an iterable source (from a java package) and a non-iterable target or the other way around. An error will be raised when detecting this situation. ==== [[mapping-maps]] @@ -224,4 +224,4 @@ When an iterable or map mapping method declares an interface type as return type |`ConcurrentMap`|`ConcurrentHashMap` |`ConcurrentNavigableMap`|`ConcurrentSkipListMap` -|=== \ No newline at end of file +|=== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 693741bcd2..5985d735c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -483,7 +483,7 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List strings); Set integerToStringSet(Integer integer); + + Set nonJavaStdlibToCollection(Source stringCollection); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Fruit.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Fruit.java new file mode 100644 index 0000000000..f012eb5a84 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/Fruit.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletononiterable; + +/** + * + * @author Saheb Preet Singh + */ +public class Fruit { + + private String type; + + public Fruit(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitSalad.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitSalad.java new file mode 100644 index 0000000000..a6298a6095 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitSalad.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletononiterable; + +import java.util.List; + +/** + * + * @author Saheb Preet Singh + */ +public class FruitSalad { + + private List fruits; + + public FruitSalad(List fruits) { + this.fruits = fruits; + } + + public List getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMapper.java new file mode 100644 index 0000000000..3d9cc94bad --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletononiterable; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Saheb Preet Singh + */ +@Mapper +public interface FruitsMapper { + + FruitsMapper INSTANCE = Mappers.getMapper( + FruitsMapper.class ); + + FruitsMenu fruitSaladToMenu(FruitSalad salad); + + FruitSalad fruitsMenuToSalad(FruitsMenu menu); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMenu.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMenu.java new file mode 100644 index 0000000000..0b1ef94ded --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/FruitsMenu.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletononiterable; + +import java.util.Iterator; +import java.util.List; + +/** + * + * @author Saheb Preet Singh + */ +public class FruitsMenu implements Iterable { + + private List fruits; + + public FruitsMenu(List fruits) { + this.fruits = fruits; + } + + public List getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } + + @Override + public Iterator iterator() { + return this.fruits.iterator(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java index b852a0a4d8..feb0948c65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java @@ -8,6 +8,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Arrays; +import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; @@ -15,7 +16,8 @@ import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class }) +@WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class, FruitsMenu.class, + FruitSalad.class, Fruit.class, FruitsMapper.class }) @RunWith(AnnotationProcessorTestRunner.class) public class IterableToNonIterableMappingTest { @@ -45,4 +47,26 @@ public void shouldReverseMapStringListToStringUsingCustomMapper() { assertThat( source.getNames() ).isEqualTo( Arrays.asList( "Alice", "Bob", "Jim" ) ); assertThat( source.publicNames ).isEqualTo( Arrays.asList( "Alice", "Bob", "Jim" ) ); } + + @Test + @IssueKey("607") + public void shouldMapIterableToNonIterable() { + List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ); + FruitsMenu menu = new FruitsMenu(fruits); + FruitSalad salad = FruitsMapper.INSTANCE.fruitsMenuToSalad( menu ); + assertThat( salad.getFruits().get( 0 ).getType() ).isEqualTo( "mango" ); + assertThat( salad.getFruits().get( 1 ).getType() ).isEqualTo( "apple" ); + assertThat( salad.getFruits().get( 2 ).getType() ).isEqualTo( "banana" ); + } + + @Test + @IssueKey("607") + public void shouldMapNonIterableToIterable() { + List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ); + FruitSalad salad = new FruitSalad(fruits); + FruitsMenu menu = FruitsMapper.INSTANCE.fruitSaladToMenu( salad ); + assertThat( salad.getFruits() ).extracting( Fruit::getType ).containsExactly( "mango", "apple", "banana" ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index e82ed945a6..e177b8a9a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -42,11 +42,11 @@ public class ErroneousStreamMappingTest { @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, line = 15, - message = "Can't generate mapping method from iterable type to non-iterable type."), + message = "Can't generate mapping method from iterable type from java stdlib to non-iterable type."), @Diagnostic(type = ErroneousStreamToNonStreamMapper.class, kind = Kind.ERROR, line = 17, - message = "Can't generate mapping method from non-iterable type to iterable type.") + message = "Can't generate mapping method from non-iterable type to iterable type from java stdlib.") } ) public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterable() { From e67daa37106fddf64e73b26924af3e7a22038728 Mon Sep 17 00:00:00 2001 From: Kemal Ozcan Date: Sat, 24 Oct 2020 17:57:12 +0300 Subject: [PATCH 0527/1006] mapstruct#597 Built-In conversion between String and StringBuilder --- .../internal/conversion/ConversionUtils.java | 11 ++++++++ .../ap/internal/conversion/Conversions.java | 1 + .../StringBuilderToStringConversion.java | 25 +++++++++++++++++++ .../ap/test/conversion/string/Source.java | 9 +++++++ .../string/StringConversionTest.java | 4 +++ .../ap/test/conversion/string/Target.java | 9 +++++++ .../string/SourceTargetMapperImpl.java | 10 ++++++-- 7 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/StringBuilderToStringConversion.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index 8d2557b334..2afcf3c6ad 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -231,4 +231,15 @@ public static String dateTimeFormatter(ConversionContext conversionContext) { public static String dateTimeFormat(ConversionContext conversionContext) { return typeReferenceName( conversionContext, JodaTimeConstants.DATE_TIME_FORMAT_FQN ); } + + /** + * Name for {@link java.lang.StringBuilder}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String stringBuilder(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, StringBuilder.class ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index ad5fe85db3..02c478bb70 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -175,6 +175,7 @@ public Conversions(TypeFactory typeFactory) { register( Character.class, String.class, new CharWrapperToStringConversion() ); register( BigInteger.class, String.class, new BigIntegerToStringConversion() ); register( BigDecimal.class, String.class, new BigDecimalToStringConversion() ); + register( StringBuilder.class, String.class, new StringBuilderToStringConversion() ); registerJodaConversions(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/StringBuilderToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StringBuilderToStringConversion.java new file mode 100644 index 0000000000..2f6705fab8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/StringBuilderToStringConversion.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import org.mapstruct.ap.internal.model.common.ConversionContext; + +/** + * Handles conversion between a target type {@link StringBuilder} and {@link String}. + * + */ +public class StringBuilderToStringConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toString()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return "new " + ConversionUtils.stringBuilder( conversionContext ) + "( )"; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java index ae9f226351..7f95abc797 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Source.java @@ -23,6 +23,7 @@ public class Source { private Boolean boolBool; private char c; private Character cc; + private StringBuilder sb; private Object object; public byte getB() { @@ -160,4 +161,12 @@ public Object getObject() { public void setObject(Object object) { this.object = object; } + + public StringBuilder getSb() { + return sb; + } + + public void setSb(StringBuilder sb) { + this.sb = sb; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java index 8b7fe0f058..bc98fff256 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java @@ -48,6 +48,7 @@ public void shouldApplyStringConversions() { source.setBoolBool( Boolean.TRUE ); source.setC( 'G' ); source.setCc( 'H' ); + source.setSb( new StringBuilder( "SB" ) ); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -68,6 +69,7 @@ public void shouldApplyStringConversions() { assertThat( target.getBoolBool() ).isEqualTo( "true" ); assertThat( target.getC() ).isEqualTo( "G" ); assertThat( target.getCc() ).isEqualTo( "H" ); + assertThat( target.getSb() ).isEqualTo( "SB" ); } @Test @@ -89,6 +91,7 @@ public void shouldApplyReverseStringConversions() { target.setBoolBool( "true" ); target.setC( "G" ); target.setCc( "H" ); + target.setSb( "SB" ); Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -109,6 +112,7 @@ public void shouldApplyReverseStringConversions() { assertThat( source.getBoolBool() ).isEqualTo( true ); assertThat( source.getC() ).isEqualTo( 'G' ); assertThat( source.getCc() ).isEqualTo( 'H' ); + assertThat( source.getSb().toString() ).isEqualTo( "SB" ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java index db6c3553c2..7d58e9c12b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/Target.java @@ -23,6 +23,7 @@ public class Target { private String boolBool; private String c; private String cc; + private String sb; private String object; public String getB() { @@ -160,4 +161,12 @@ public String getObject() { public void setObject(String object) { this.object = object; } + + public String getSb() { + return sb; + } + + public void setSb(String sb) { + this.sb = sb; + } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java index 7317a6ba60..ecfa910627 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/string/SourceTargetMapperImpl.java @@ -9,8 +9,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2016-12-30T19:22:52+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2020-10-24T17:41:29+0300", + comments = "version: , compiler: javac, environment: Java 1.8.0_265 (AdoptOpenJDK)" ) public class SourceTargetMapperImpl implements SourceTargetMapper { @@ -54,6 +54,9 @@ public Target sourceToTarget(Source source) { if ( source.getCc() != null ) { target.setCc( source.getCc().toString() ); } + if ( source.getSb() != null ) { + target.setSb( source.getSb().toString() ); + } return target; } @@ -115,6 +118,9 @@ public Source targetToSource(Target target) { source.setCc( target.getCc().charAt( 0 ) ); } source.setObject( target.getObject() ); + if ( target.getSb() != null ) { + source.setSb( new StringBuilder( target.getSb() ) ); + } return source; } From 85890dd442736ea79167bd099c8d68915d384f6c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Oct 2020 18:24:49 +0200 Subject: [PATCH 0528/1006] #2245 Local variable should be created when using default value --- .../ap/internal/model/PropertyMapping.java | 9 ++- .../ap/test/bugs/_2245/Issue2245Test.java | 42 ++++++++++++++ .../ap/test/bugs/_2245/TestMapper.java | 55 +++++++++++++++++++ .../ap/test/bugs/_2245/TestMapperImpl.java | 50 +++++++++++++++++ 4 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/TestMapper.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 240343ad9b..dbda3daac3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -374,6 +374,11 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { return null; } + private boolean hasDefaultValueAssignment(Assignment rhs) { + return ( defaultValue != null || defaultJavaExpression != null ) && + ( !rhs.getSourceType().isPrimitive() || rhs.getSourcePresenceCheckerReference() != null); + } + private Assignment assignToPlain(Type targetType, AccessorType targetAccessorType, Assignment rightHandSide) { @@ -415,7 +420,9 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { ); } else { - boolean includeSourceNullCheck = SetterWrapper.doSourceNullCheck( rhs, nvcs, nvpms, targetType ); + // If the property mapping has a default value assignment then we have to do a null value check + boolean includeSourceNullCheck = SetterWrapper.doSourceNullCheck( rhs, nvcs, nvpms, targetType ) + || hasDefaultValueAssignment( rhs ); if ( !includeSourceNullCheck ) { // solution for #834 introduced a local var and null check for nested properties always. // however, a local var is not needed if there's no need to check for null. diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java new file mode 100644 index 0000000000..5aa899d055 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2245; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2245") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + TestMapper.class +}) +public class Issue2245Test { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( TestMapper.class ); + + @Test + public void shouldGenerateSourceGetMethodOnce() { + + TestMapper.Tenant tenant = + TestMapper.INSTANCE.map( new TestMapper.TenantDTO( new TestMapper.Inner( "acme" ) ) ); + + assertThat( tenant ).isNotNull(); + assertThat( tenant.getId() ).isEqualTo( "acme" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/TestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/TestMapper.java new file mode 100644 index 0000000000..750ee12fa5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/TestMapper.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2245; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface TestMapper { + + TestMapper INSTANCE = Mappers.getMapper( TestMapper.class ); + + class Tenant { + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + class Inner { + private final String id; + + public Inner(String id) { + this.id = id; + } + + public String getId() { + return id; + } + } + + class TenantDTO { + private final Inner inner; + + public TenantDTO(Inner inner) { + this.inner = inner; + } + + public Inner getInner() { + return inner; + } + } + + @Mapping(target = "id", source = "inner.id", defaultValue = "test") + Tenant map(TenantDTO tenant); +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java new file mode 100644 index 0000000000..c3ecc02911 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2245; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2020-10-24T17:57:23+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_202 (AdoptOpenJdk)" +) +public class TestMapperImpl implements TestMapper { + + @Override + public Tenant map(TenantDTO tenant) { + if ( tenant == null ) { + return null; + } + + Tenant tenant1 = new Tenant(); + + String id = tenantInnerId( tenant ); + if ( id != null ) { + tenant1.setId( id ); + } + else { + tenant1.setId( "test" ); + } + + return tenant1; + } + + private String tenantInnerId(TenantDTO tenantDTO) { + if ( tenantDTO == null ) { + return null; + } + Inner inner = tenantDTO.getInner(); + if ( inner == null ) { + return null; + } + String id = inner.getId(); + if ( id == null ) { + return null; + } + return id; + } +} From 3256abb79ccee1727c0e84f1dc9847aa695ed918 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Oct 2020 17:46:20 +0200 Subject: [PATCH 0529/1006] #2244 Mark mapstruct-processor jar as Spring-Boot-Jar-Type: annotation-processor Doing this would make sure that starting from Spring Boot 2.4 the mapstruct-processor will not be included in the fat jar produced by the Spring Boot maven plugin if people have it as a maven provided dependency. This is an alternative if people are not using the maven-compiler-plugin annotationProcessorPaths --- processor/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/processor/pom.xml b/processor/pom.xml index bbec83bf29..2ff5d2d186 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -123,6 +123,7 @@ org.mapstruct.processor + annotation-processor From 749ded96c17114cec676b313d888f8bde464eb84 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 31 Oct 2020 12:56:25 +0100 Subject: [PATCH 0530/1006] #2251 Fix incorrect code generated for constructor mapping from implicit source parameter matching --- .../ap/internal/model/BeanMappingMethod.java | 1 + .../ap/test/bugs/_2251/Issue2251Mapper.java | 20 ++++++++++ .../ap/test/bugs/_2251/Issue2251Test.java | 37 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2251/Source.java | 22 +++++++++++ .../mapstruct/ap/test/bugs/_2251/Target.java | 24 ++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4d086b5126..b17e060848 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1315,6 +1315,7 @@ private void applyParameterNameBasedMapping() { sourceParameters.remove(); unprocessedDefinedTargets.remove( targetProperty.getKey() ); unprocessedSourceProperties.remove( targetProperty.getKey() ); + unprocessedConstructorProperties.remove( targetProperty.getKey() ); } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Mapper.java new file mode 100644 index 0000000000..d09f3440fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Mapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2251; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2251Mapper { + + Issue2251Mapper INSTANCE = Mappers.getMapper( Issue2251Mapper.class ); + + @Mapping(target = "value1", source = "source.value") + Target map(Source source, String value2); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java new file mode 100644 index 0000000000..d08a5f7d74 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2251; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2251") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2251Mapper.class, + Source.class, + Target.class, +}) +public class Issue2251Test { + + @Test + public void shouldGenerateCorrectCode() { + + Target target = Issue2251Mapper.INSTANCE.map( new Source( "source" ), "test" ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue1() ).isEqualTo( "source" ); + assertThat( target.getValue2() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Source.java new file mode 100644 index 0000000000..cbd882a8f8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2251; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Target.java new file mode 100644 index 0000000000..363129797f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Target.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2251; + +public class Target { + private final String value1; + private final String value2; + + public Target(String value1, String value2) { + this.value1 = value1; + this.value2 = value2; + } + + public String getValue1() { + return value1; + } + + public String getValue2() { + return value2; + } +} From 8f9df5b69b6adbc789243a76a5b72b61ea7422fe Mon Sep 17 00:00:00 2001 From: Nikolas Charalambidis Date: Wed, 4 Nov 2020 21:39:06 +0100 Subject: [PATCH 0531/1006] #2258 Fixes vague description of @Default and @ConstructorProperties annotations --- ...er-14-third-party-api-integration.asciidoc | 41 +++++++++++++++++++ .../chapter-3-defining-a-mapper.asciidoc | 6 +-- .../mapstruct-reference-guide.asciidoc | 4 +- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc diff --git a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc new file mode 100644 index 0000000000..03e18167e3 --- /dev/null +++ b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc @@ -0,0 +1,41 @@ +[[third-party-api-integration]] +== Third-party API integration + +[[non-shipped-annotations]] +=== Non-shipped annotations + +There are various use-cases you must resolve ambiguity for MapStruct to use a correct piece of code. +However, the primary goal of MapStruct is to focus on bean mapping without polluting the entity code. +For that reason, MapStruct is flexible enough to interact with already defined annotations from third-party libraries. +The requirement to enable this behavior is to match the _name_ of such annotation. +Hence, we say that annotation can be _from any package_. + +The annotations _named_ `@ConstructorProperties` and `@Default` are currently examples of this kind of annotation. + +[WARNING] +==== +If such named third-party annotation exists, it does not guarantee its `@Target` matches with the intended placement. +Be aware of placing a third-party annotation just for sake of mapping is not recommended as long as it might lead to unwanted side effects caused by that library. +==== + +A very common case is that no third-party dependency imported to your project provides such annotation or is inappropriate for use as already described. +In such cases create your own annotation, for example: + +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +package foo.support.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.CLASS) +public @interface Default { + +} +---- +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 54a0dbd709..acdfd98174 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -537,10 +537,10 @@ When doing a mapping MapStruct checks if there is a builder for the type being m If there is no builder, then MapStruct looks for a single accessible constructor. When there are multiple constructors then the following is done to pick the one which should be used: -* If a constructor is annotated with an annotation named `@Default` (from any package) it will be used. +* If a constructor is annotated with an annotation _named_ `@Default` (from any package, see <>) it will be used. * If a single public constructor exists then it will be used to construct the object, and the other non public constructors will be ignored. * If a parameterless constructor exists then it will be used to construct the object, and the other constructors will be ignored. -* If there are multiple eligible constructors then there will be a compilation error due to ambiguous constructors. In order to break the ambiguity an annotation named `@Default` (from any package) can used. +* If there are multiple eligible constructors then there will be a compilation error due to ambiguous constructors. In order to break the ambiguity an annotation _named_ `@Default` (from any package, see <>) can used. .Deciding which constructor to use ==== @@ -585,7 +585,7 @@ public class Van { ==== When using a constructor then the names of the parameters of the constructor will be used and matched to the target properties. -When the constructor has an annotation named `@ConstructorProperties` (from any package) then this annotation will be used to get the names of the parameters. +When the constructor has an annotation _named_ `@ConstructorProperties` (from any package, see <>) then this annotation will be used to get the names of the parameters. [NOTE] ==== diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 1aa08b17b8..b83c874c5e 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -44,4 +44,6 @@ include::chapter-11-reusing-mapping-configurations.asciidoc[] include::chapter-12-customizing-mapping.asciidoc[] -include::chapter-13-using-mapstruct-spi.asciidoc[] \ No newline at end of file +include::chapter-13-using-mapstruct-spi.asciidoc[] + +include::chapter-14-third-party-api-integration.asciidoc[] \ No newline at end of file From 75f963adf66461b246f3fad8b3bc46f94f42d7d0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Nov 2020 22:26:17 +0100 Subject: [PATCH 0532/1006] #2263 Fix IndexOutOfBoundsException when resolving TypeVar to a Type --- .../ap/internal/model/common/Type.java | 7 +++- .../test/bugs/_2263/Erroneous2263Mapper.java | 17 ++++++++ .../ap/test/bugs/_2263/Issue2263Test.java | 41 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2263/Source.java | 22 ++++++++++ .../mapstruct/ap/test/bugs/_2263/Target.java | 22 ++++++++++ 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Erroneous2263Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 910af60d40..b3d01f4131 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -1159,7 +1159,12 @@ public Type visitTypeVariable(TypeVariable t, Type parameterized) { @Override public Type visitDeclared(DeclaredType t, Type parameterized) { if ( types.isAssignable( types.erasure( t ), types.erasure( parameterized.getTypeMirror() ) ) ) { - // if same type, we can cast en assume number of type args are also the same + // We can't assume that the type args are the same + // e.g. List is assignable to Object + if ( t.getTypeArguments().size() != parameterized.getTypeParameters().size() ) { + return super.visitDeclared( t, parameterized ); + } + for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { Type result = visit( t.getTypeArguments().get( i ), parameterized.getTypeParameters().get( i ) ); if ( result != null ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Erroneous2263Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Erroneous2263Mapper.java new file mode 100644 index 0000000000..59a0a42ddb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Erroneous2263Mapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2263; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Erroneous2263Mapper { + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java new file mode 100644 index 0000000000..03e545b210 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2263; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2263") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Erroneous2263Mapper.class, + Source.class, + Target.class, +}) +public class Issue2263Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = Erroneous2263Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 16, + message = "Can't map property \"Object value\" to \"String value\". " + + "Consider to declare/implement a mapping method: \"String map(Object value)\".") + }) + public void shouldCorrectlyReportUnmappableTargetObject() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Source.java new file mode 100644 index 0000000000..54e5b7fd38 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2263; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final Object value; + + public Source(Object value) { + this.value = value; + } + + public Object getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Target.java new file mode 100644 index 0000000000..943a51264c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2263; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} From 6df9243d92f66490ceccdc6df40ffe41def2e217 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 6 Nov 2020 21:24:52 +0100 Subject: [PATCH 0533/1006] #2253 remove unmapped source properties when source parameter is directly mapped --- .../ap/internal/model/BeanMappingMethod.java | 10 ++++ .../ap/test/bugs/_2253/Issue2253Test.java | 34 +++++++++++++ .../ap/test/bugs/_2253/TestMapper.java | 48 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/TestMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b17e060848..d19fb4f398 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1315,6 +1315,16 @@ private void applyParameterNameBasedMapping() { sourceParameters.remove(); unprocessedDefinedTargets.remove( targetProperty.getKey() ); unprocessedSourceProperties.remove( targetProperty.getKey() ); + + // The source parameter was directly mapped so ignore all of its source properties completely + if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) { + // We explicitly ignore source properties from primitives or array types + Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); + for ( String sourceProperty : readAccessors.keySet() ) { + unprocessedSourceProperties.remove( sourceProperty ); + } + } + unprocessedConstructorProperties.remove( targetProperty.getKey() ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java new file mode 100644 index 0000000000..fc0e007daa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2253; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2253") +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( { + TestMapper.class, +} ) +public class Issue2253Test { + + @Test + public void shouldNotTreatMatchedSourceParameterAsBean() { + + TestMapper.Person person = TestMapper.INSTANCE.map( new TestMapper.PersonDto( 20 ), "Tester" ); + + assertThat( person.getAge() ).isEqualTo( 20 ); + assertThat( person.getName() ).isEqualTo( "Tester" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/TestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/TestMapper.java new file mode 100644 index 0000000000..1e05e444a2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/TestMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2253; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface TestMapper { + + TestMapper INSTANCE = Mappers.getMapper( TestMapper.class ); + + Person map(PersonDto personDto, String name); + + class Person { + private final int age; + private final String name; + + public Person(int age, String name) { + this.age = age; + this.name = name; + } + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + } + + class PersonDto { + private final int age; + + public PersonDto(int age) { + this.age = age; + } + + public int getAge() { + return age; + } + } +} From 6daea86a1b367e061f1968ece4329cc4aa8bd67d Mon Sep 17 00:00:00 2001 From: Nikolas Charalambidis Date: Wed, 11 Nov 2020 22:28:53 +0100 Subject: [PATCH 0534/1006] Add Lombok subsection in the documentation (#2266) --- ...er-14-third-party-api-integration.asciidoc | 151 +++++++++++++++++- .../chapter-3-defining-a-mapper.asciidoc | 3 +- 2 files changed, 152 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc index 03e18167e3..c31424a0de 100644 --- a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc +++ b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc @@ -38,4 +38,153 @@ public @interface Default { } ---- -==== \ No newline at end of file +==== + +[[lombok]] +=== Lombok + +MapStruct works together with https://projectlombok.org/[Project Lombok] as of MapStruct 1.2.0.Beta1 and Lombok 1.16.14. + +MapStruct takes advantage of generated getters, setters, and constructors and uses them to generate the mapper implementations. + +[NOTE] +==== +Lombok 1.18.16 introduces a breaking change (https://projectlombok.org/changelog[changelog]). +The additional annotation processor `lombok-mapstruct-binding` (https://mvnrepository.com/artifact/org.projectlombok/lombok-mapstruct-binding[Maven]) must be added otherwise MapStruct stops working with Lombok. +This resolves the compilation issues of Lombok and MapStruct modules. + +[source, xml] +---- + + org.projectlombok + lombok-mapstruct-binding + 0.1.0 + +---- +==== + +==== Set up + +The set up using Maven or Gradle does not differ from what is described in <>. Additionally, you need to provide Lombok dependencies. + +.Maven configuration +==== +[source, xml, linenums] +[subs="verbatim,attributes"] +---- + + + {mapstructVersion} + 1.18.16 + 1.8 + 1.8 + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + + org.projectlombok + lombok + ${org.projectlombok.version} + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + org.projectlombok + lombok + ${org.projectlombok.version} + + + + + org.projectlombok + lombok-mapstruct-binding + 0.1.0 + + + + + + +---- +==== + +.Gradle configuration (3.4 and later) +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- + +dependencies { + + implementation "org.mapstruct:mapstruct:${mapstructVersion}" + implementation "org.projectlombok:lombok:1.18.16" + annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.1.0" + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + annotationProcessor "org.projectlombok:lombok:1.18.16" +} + +---- +==== + +The usage combines what you already know from <> and Lombok. + +.Usage of MapStruct with Lombok +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Data +public class Source { + + private String test; +} + +public class Target { + + private Long testing; + + public Long getTesting() { + return testing; + } + + public void setTesting( Long testing ) { + this.testing = testing; + } +} + +@Mapper +public interface SourceTargetMapper { + + SourceTargetMapper MAPPER = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping( source = "test", target = "testing" ) + Target toTarget( Source s ); +} + +---- +==== + +A working example can be found on the GitHub project https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-lombok[mapstruct-lombok]. diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index acdfd98174..be3435b541 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -516,7 +516,8 @@ public class PersonMapperImpl implements PersonMapper { Supported builder frameworks: -* https://projectlombok.org/[Lombok] - requires having the Lombok classes in a separate module. See for more information https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] +* https://projectlombok.org/[Lombok] - It is required to have the Lombok classes in a separate module. +See for more information at https://github.com/rzwitserloot/lombok/issues/1538[rzwitserloot/lombok#1538] and to set up Lombok with MapStruct, refer to <>. * https://github.com/google/auto/blob/master/value/userguide/index.md[AutoValue] * https://immutables.github.io/[Immutables] - When Immutables are present on the annotation processor path then the `ImmutablesAccessorNamingStrategy` and `ImmutablesBuilderProvider` would be used by default * https://github.com/google/FreeBuilder[FreeBuilder] - When FreeBuilder is present on the annotation processor path then the `FreeBuilderAccessorNamingStrategy` would be used by default. From 84c3bda5a23e48956ad5de4955792ef0a278638e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 22 Nov 2020 13:04:26 +0100 Subject: [PATCH 0535/1006] #2274, #2023 Fix problems with property mapping using source parameters Fixes problems when property mapping is using source parameter and has default value / expression or is doing an update --- .../ap/internal/model/BeanMappingMethod.java | 39 ++++++++++++- .../ap/internal/model/PropertyMapping.java | 53 +++++++++++++++--- .../model/assignment/SetterWrapper.java | 30 ---------- .../ap/internal/model/BeanMappingMethod.ftl | 8 +-- .../ap/test/bugs/_2023/Issue2023Mapper.java | 24 ++++++++ .../ap/test/bugs/_2023/Issue2023Test.java | 51 +++++++++++++++++ .../ap/test/bugs/_2023/NewPersonRequest.java | 42 ++++++++++++++ .../ap/test/bugs/_2023/PersonDto.java | 31 ++++++++++ .../ManySourceArgumentsConstructorMapper.java | 25 +++++++++ ...SourceArgumentsConstructorMappingTest.java | 40 +++++++++++++ .../manysourcearguments/ExampleMapper.java | 19 +++++++ .../manysourcearguments/ExampleMember.java | 19 +++++++ .../manysourcearguments/ExampleSource.java | 21 +++++++ .../manysourcearguments/ExampleTarget.java | 31 ++++++++++ .../ManyArgumentsUpdateMappingTest.java | 56 +++++++++++++++++++ 15 files changed, 446 insertions(+), 43 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/NewPersonRequest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/PersonDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMember.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d19fb4f398..7ea17bf27b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1619,12 +1619,47 @@ public List getSourceParametersExcludingPrimitives() { .collect( Collectors.toList() ); } - public List getSourcePrimitiveParameters() { + public List getSourceParametersNeedingNullCheck() { return getSourceParameters().stream() - .filter( parameter -> parameter.getType().isPrimitive() ) + .filter( this::needsNullCheck ) .collect( Collectors.toList() ); } + public List getSourceParametersNotNeedingNullCheck() { + return getSourceParameters().stream() + .filter( parameter -> !needsNullCheck( parameter ) ) + .collect( Collectors.toList() ); + } + + private boolean needsNullCheck(Parameter parameter) { + if ( parameter.getType().isPrimitive() ) { + return false; + } + + List mappings = propertyMappingsByParameter( parameter ); + if ( mappings.size() == 1 && doesNotNeedNullCheckForSourceParameter( mappings.get( 0 ) ) ) { + return false; + } + + mappings = constructorPropertyMappingsByParameter( parameter ); + + if ( mappings.size() == 1 && doesNotNeedNullCheckForSourceParameter( mappings.get( 0 ) ) ) { + return false; + } + + return true; + } + + private boolean doesNotNeedNullCheckForSourceParameter(PropertyMapping mapping) { + if ( mapping.getAssignment().isCallingUpdateMethod() ) { + // If the mapping assignment is calling an update method then we should do a null check + // in the bean mapping + return false; + } + + return mapping.getAssignment().isSourceReferenceParameter(); + } + @Override public int hashCode() { //Needed for Checkstyle, otherwise it fails due to EqualsHashCode rule diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index dbda3daac3..61e1fca864 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -46,6 +46,8 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; import static org.mapstruct.ap.internal.model.ForgedMethod.forParameterMapping; import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping; @@ -374,11 +376,6 @@ private Assignment getDefaultValueAssignment( Assignment rhs ) { return null; } - private boolean hasDefaultValueAssignment(Assignment rhs) { - return ( defaultValue != null || defaultJavaExpression != null ) && - ( !rhs.getSourceType().isPrimitive() || rhs.getSourcePresenceCheckerReference() != null); - } - private Assignment assignToPlain(Type targetType, AccessorType targetAccessorType, Assignment rightHandSide) { @@ -421,8 +418,7 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { } else { // If the property mapping has a default value assignment then we have to do a null value check - boolean includeSourceNullCheck = SetterWrapper.doSourceNullCheck( rhs, nvcs, nvpms, targetType ) - || hasDefaultValueAssignment( rhs ); + boolean includeSourceNullCheck = setterWrapperNeedsSourceNullCheck( rhs, targetType ); if ( !includeSourceNullCheck ) { // solution for #834 introduced a local var and null check for nested properties always. // however, a local var is not needed if there's no need to check for null. @@ -438,6 +434,49 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { } } + /** + * Checks whether the setter wrapper should include a null / presence check or not + * + * @param rhs the source right hand side + * @param targetType the target type + * + * @return whether to include a null / presence check or not + */ + private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs, Type targetType) { + if ( rhs.getSourceType().isPrimitive() && rhs.getSourcePresenceCheckerReference() == null ) { + // If the source type is primitive or it doesn't have a presence checker then + // we shouldn't do a null check + return false; + } + + if ( nvcs == ALWAYS ) { + // NullValueCheckStrategy is ALWAYS -> do a null check + return true; + } + + if ( nvpms == SET_TO_DEFAULT || nvpms == IGNORE ) { + // NullValuePropertyMapping is SET_TO_DEFAULT or IGNORE -> do a null check + return true; + } + + if ( rhs.getType().isConverted() ) { + // A type conversion is applied, so a null check is required + return true; + } + + if ( rhs.getType().isDirect() && targetType.isPrimitive() ) { + // If the type is direct and the target type is primitive (i.e. we are unboxing) then check is needed + return true; + } + + if ( defaultValue != null || defaultJavaExpression != null ) { + // If there is default value defined then a check is needed + return true; + } + + return false; + } + private Assignment assignToPlainViaAdder( Assignment rightHandSide) { Assignment result = rightHandSide; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index e9fc38741a..7be948c857 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -10,12 +10,6 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; -import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; - -import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; /** * Wraps the assignment in a target setter. @@ -77,28 +71,4 @@ public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } - /** - * Wraps the assignment in a target setter. include a null check when - * - * - Not if source is the parameter iso property, because the null check is than handled by the bean mapping - * - Not when source is primitive, you can't null check a primitive - * - The source property is fed to a conversion somehow before its assigned to the target - * - The user decided to ALLWAYS include a null check - * - * @param rhs the source righthand side - * @param nvcs null value check strategy - * @param nvpms null value property mapping strategy - * @param targetType the target type - * - * @return include a null check - */ - public static boolean doSourceNullCheck(Assignment rhs, NullValueCheckStrategyGem nvcs, - NullValuePropertyMappingStrategyGem nvpms, Type targetType) { - return !rhs.isSourceReferenceParameter() - && !rhs.getSourceType().isPrimitive() - && (ALWAYS == nvcs - || SET_TO_DEFAULT == nvpms || IGNORE == nvpms - || rhs.getType().isConverted() - || (rhs.getType().isDirect() && targetType.isPrimitive())); - } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index c58f9e7581..f5d6e799e1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -27,7 +27,7 @@ <#if !existingInstanceMapping> <#if hasConstructorMappings()> <#if (sourceParameters?size > 1)> - <#list sourceParametersExcludingPrimitives as sourceParam> + <#list sourceParametersNeedingNullCheck as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; @@ -39,7 +39,7 @@ } - <#list sourcePrimitiveParameters as sourceParam> + <#list sourceParametersNotNeedingNullCheck as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; @@ -80,7 +80,7 @@ <#if (sourceParameters?size > 1)> - <#list sourceParametersExcludingPrimitives as sourceParam> + <#list sourceParametersNeedingNullCheck as sourceParam> <#if (propertyMappingsByParameter(sourceParam)?size > 0)> if ( ${sourceParam.name} != null ) { <#list propertyMappingsByParameter(sourceParam) as propertyMapping> @@ -89,7 +89,7 @@ } - <#list sourcePrimitiveParameters as sourceParam> + <#list sourceParametersNotNeedingNullCheck as sourceParam> <#if (propertyMappingsByParameter(sourceParam)?size > 0)> <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Mapper.java new file mode 100644 index 0000000000..a2fafb7a2d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Mapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2023; + +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2023Mapper { + + Issue2023Mapper INSTANCE = Mappers.getMapper( Issue2023Mapper.class ); + + @Mapping(target = "correlationId", source = "correlationId", defaultExpression = "java(UUID.randomUUID())") + NewPersonRequest createRequest(PersonDto person, UUID correlationId); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java new file mode 100644 index 0000000000..ffc3df5e07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2023; + +import java.util.UUID; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2023") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2023Mapper.class, + NewPersonRequest.class, + PersonDto.class, +}) +public class Issue2023Test { + + @Test + public void shouldUseDefaultExpressionCorrectly() { + PersonDto person = new PersonDto(); + person.setName( "John" ); + person.setEmail( "john@doe.com" ); + + NewPersonRequest request = Issue2023Mapper.INSTANCE.createRequest( person, null ); + + assertThat( request ).isNotNull(); + assertThat( request.getName() ).isEqualTo( "John" ); + assertThat( request.getEmail() ).isEqualTo( "john@doe.com" ); + assertThat( request.getCorrelationId() ).isNotNull(); + + UUID correlationId = UUID.randomUUID(); + request = Issue2023Mapper.INSTANCE.createRequest( person, correlationId ); + + assertThat( request ).isNotNull(); + assertThat( request.getName() ).isEqualTo( "John" ); + assertThat( request.getEmail() ).isEqualTo( "john@doe.com" ); + assertThat( request.getCorrelationId() ).isEqualTo( correlationId ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/NewPersonRequest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/NewPersonRequest.java new file mode 100644 index 0000000000..98f3d0b5b6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/NewPersonRequest.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2023; + +import java.util.UUID; + +/** + * @author Filip Hrisafov + */ +public class NewPersonRequest { + + private String name; + private String email; + private UUID correlationId; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public UUID getCorrelationId() { + return correlationId; + } + + public void setCorrelationId(UUID correlationId) { + this.correlationId = correlationId; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/PersonDto.java new file mode 100644 index 0000000000..d2551c50c6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/PersonDto.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2023; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + + private String name; + private String email; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMapper.java new file mode 100644 index 0000000000..dfa3b4be5c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.manysourcearguments; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.constructor.Person; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ManySourceArgumentsConstructorMapper { + + ManySourceArgumentsConstructorMapper INSTANCE = Mappers.getMapper( ManySourceArgumentsConstructorMapper.class ); + + @Mapping(target = "name", defaultValue = "Tester") + @Mapping(target = "city", defaultExpression = "java(\"Zurich\")") + Person map(String name, String city); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java new file mode 100644 index 0000000000..dde307adf7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.constructor.manysourcearguments; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.constructor.Person; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith( AnnotationProcessorTestRunner.class ) +@WithClasses( { + ManySourceArgumentsConstructorMapper.class, + Person.class, +} ) +public class ManySourceArgumentsConstructorMappingTest { + + @Test + public void shouldCorrectlyUseDefaultValueForSourceParameters() { + Person person = ManySourceArgumentsConstructorMapper.INSTANCE.map( null, "Test Valley" ); + + assertThat( person ).isNotNull(); + assertThat( person.getName() ).isEqualTo( "Tester" ); + assertThat( person.getCity() ).isEqualTo( "Test Valley" ); + + person = ManySourceArgumentsConstructorMapper.INSTANCE.map( "Other Tester", null ); + + assertThat( person ).isNotNull(); + assertThat( person.getName() ).isEqualTo( "Other Tester" ); + assertThat( person.getCity() ).isEqualTo( "Zurich" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMapper.java new file mode 100644 index 0000000000..dbbceeae6e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods.manysourcearguments; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ExampleMapper { + + ExampleMapper INSTANCE = Mappers.getMapper( ExampleMapper.class ); + + void update(@MappingTarget ExampleTarget target, ExampleSource source, ExampleMember member); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMember.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMember.java new file mode 100644 index 0000000000..7a4e1a9916 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleMember.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods.manysourcearguments; + +public class ExampleMember { + + private final String name; + + public ExampleMember(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleSource.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleSource.java new file mode 100644 index 0000000000..2e23ed4add --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleSource.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods.manysourcearguments; + +import java.time.LocalDate; + +public class ExampleSource { + + private final LocalDate birthday; + + public ExampleSource(LocalDate birthday) { + this.birthday = birthday; + } + + public LocalDate getBirthday() { + return birthday; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleTarget.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleTarget.java new file mode 100644 index 0000000000..142503b6de --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ExampleTarget.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods.manysourcearguments; + +import java.time.LocalDate; + +public class ExampleTarget { + + private LocalDate birthday; + + private ExampleMember member; + + public LocalDate getBirthday() { + return birthday; + } + + public void setBirthday(LocalDate birthday) { + this.birthday = birthday; + } + + public ExampleMember getMember() { + return member; + } + + public void setMember(ExampleMember member) { + this.member = member; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java new file mode 100644 index 0000000000..8a6ac225a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods.manysourcearguments; + +import java.time.LocalDate; +import java.time.Month; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2274") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + ExampleMapper.class, + ExampleMember.class, + ExampleSource.class, + ExampleTarget.class, +}) +public class ManyArgumentsUpdateMappingTest { + + @Test + public void shouldUpdateToNullIfSourceParametersAreNull() { + ExampleTarget target = new ExampleTarget(); + target.setBirthday( LocalDate.of( 2020, Month.NOVEMBER, 15 ) ); + target.setMember( new ExampleMember( "test" ) ); + ExampleMapper.INSTANCE.update( + target, + new ExampleSource( LocalDate.of( 2020, Month.AUGUST, 30 ) ), + null + ); + + assertThat( target.getBirthday() ).isEqualTo( LocalDate.of( 2020, Month.AUGUST, 30 ) ); + assertThat( target.getMember() ).isNull(); + + ExampleMapper.INSTANCE.update( + target, + new ExampleSource( null ), + new ExampleMember( "second test" ) + ); + + assertThat( target.getBirthday() ).isNull(); + assertThat( target.getMember() ).isNotNull(); + assertThat( target.getMember().getName() ).isEqualTo( "second test" ); + } +} From e73dd1b485ecc535ae338492eb052d15758563cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20D=C3=BCsterhus?= Date: Mon, 14 Dec 2020 11:44:04 +0100 Subject: [PATCH 0536/1006] Update chapter-2-set-up.asciidoc See official maven doc on this: https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html Otherwise for example intellij doesn't recognize the compiler options on maven import --- .../src/main/asciidoc/chapter-2-set-up.asciidoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index fb954ac58f..cb0067f2f3 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -187,15 +187,15 @@ When invoking javac directly, these options are passed to the compiler in the fo true - + -Amapstruct.suppressGeneratorTimestamp=true - - + + -Amapstruct.suppressGeneratorVersionInfoComment=true - - + + -Amapstruct.verbose=true - + From f84f756a4cc142c4cb4bdce540f009b79da03f23 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 5 Dec 2020 10:29:48 +0100 Subject: [PATCH 0537/1006] #2293 Use MapperConfig instead of MappingConfig in the documentation --- .../chapter-10-advanced-mapping-options.asciidoc | 12 ++++++------ .../chapter-5-data-type-conversions.asciidoc | 2 +- .../ap/internal/model/source/DefaultOptions.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index ddf7fbcaed..4ccad69f2c 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -161,13 +161,13 @@ The mechanism is also present on iterable mapping and map mapping. `@IterableMap MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. By default `null` will be returned. -However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MappingConfig`, the mapping result can be altered to return empty *default* values. This means for: +However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MapperConfig`, the mapping result can be altered to return empty *default* values. This means for: * *Bean mappings*: an 'empty' target bean will be returned, with the exception of constants and expressions, they will be populated when present. * *Iterables / Arrays*: an empty iterable will be returned. * *Maps*: an empty map will be returned. -The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MappingConfig#nullValueMappingStrategy`. +The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MapperConfig#nullValueMappingStrategy`. [[mapping-result-for-null-properties]] @@ -179,13 +179,13 @@ By default the target property will be set to null. However: -1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result can be altered to return *default* values. +1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result can be altered to return *default* values. For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. -2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MappingConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. +2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. -The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MappingConfig#nullValuePropertyMappingStrategy`. +The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MapperConfig#nullValuePropertyMappingStrategy`. [NOTE] ==== @@ -213,7 +213,7 @@ First calling a mapping method on the source property is not protected by a null The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. -The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MappingConfig#nullValueCheckStrategy`. +The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MaperConfig#nullValueCheckStrategy`. [[source-presence-check]] === Source presence checking diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 725c69bad0..9619d0fe26 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -155,7 +155,7 @@ When generating the implementation of a mapping method, MapStruct will apply the . If no such method was found MapStruct will try to generate an automatic sub-mapping method that will do the mapping between the source and target attributes. . If MapStruct could not create a name based mapping method an error will be raised at build time, indicating the non-mappable attribute and its path. -A mapping control (`MappingControl`) can be defined on all levels (`@MappingConfig`, `@Mapper`, `@BeanMapping`, `@Mapping`), the latter taking precedence over the former. For example: `@Mapper( mappingControl = NoComplexMapping.class )` takes precedence over `@MapperConfig( mappingControl = DeepClone.class )`. `@IterableMapping` and `@MapMapping` work similar as `@Mapping`. MappingControl is experimental from MapStruct 1.4. +A mapping control (`MappingControl`) can be defined on all levels (`@MapperConfig`, `@Mapper`, `@BeanMapping`, `@Mapping`), the latter taking precedence over the former. For example: `@Mapper( mappingControl = NoComplexMapping.class )` takes precedence over `@MapperConfig( mappingControl = DeepClone.class )`. `@IterableMapping` and `@MapMapping` work similar as `@Mapping`. MappingControl is experimental from MapStruct 1.4. `MappingControl` has an enum that corresponds to the first 4 options above: `MappingControl.Use#DIRECT`, `MappingControl.Use#MAPPING_METHOD`, `MappingControl.Use#BUILT_IN_CONVERSION` and `MappingControl.Use#COMPLEX_MAPPING` the presence of which allows the user to switch *on* a option. The absence of an enum switches *off* a mapping option. Default they are all present enabling all mapping options. [NOTE] diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 4d80bf57be..58f03ad55d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -119,7 +119,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { public BuilderGem getBuilder() { // TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility // but assuming a default @Builder will make testcases fail. Not having a default means that you need to - // specify this mandatory on @MappingConfig and @Mapper. + // specify this mandatory on @MapperConfig and @Mapper. return null; } From 700293f0898fb5e9014d0e241bc9674695430ebe Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 19 Dec 2020 19:50:32 +0100 Subject: [PATCH 0538/1006] #2301 Implicitly ignore forward inherited mappings from different method types --- .../ap/internal/model/BeanMappingMethod.java | 9 +++ .../ap/test/bugs/_2301/Artifact.java | 66 +++++++++++++++++++ .../ap/test/bugs/_2301/ArtifactDto.java | 22 +++++++ .../ap/test/bugs/_2301/Issue2301Mapper.java | 28 ++++++++ .../ap/test/bugs/_2301/Issue2301Test.java | 40 +++++++++++ 5 files changed, 165 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 7ea17bf27b..459a4f82d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -938,6 +938,15 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp if ( targetWriteAccessor == null ) { if ( targetReadAccessor == null ) { + if ( mapping.getInheritContext() != null && mapping.getInheritContext().isForwarded() && + mapping.getInheritContext().getTemplateMethod().isUpdateMethod() != method.isUpdateMethod() ) { + // When a configuration is inherited and the template method is not same type as the current + // method then we can safely ignore this mapping. + // This means that a property which is inherited might be present for a direct mapping + // via the Builder, but not for an update mapping (directly on the object itself), + // or vice versa + return false; + } Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java new file mode 100644 index 0000000000..316959f48b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Artifact.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2301; + +import java.util.Set; + +/** + * @author Filip Hrisafov + */ +public class Artifact { + + private String name; + private Set dependantBuildRecords; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getDependantBuildRecords() { + return dependantBuildRecords; + } + + public void setDependantBuildRecords(Set dependantBuildRecords) { + this.dependantBuildRecords = dependantBuildRecords; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String name; + private Set dependantBuildRecords; + + public Artifact build() { + Artifact artifact = new Artifact(); + artifact.setName( name ); + artifact.setDependantBuildRecords( dependantBuildRecords ); + + return artifact; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder dependantBuildRecord(String dependantBuildRecord) { + this.dependantBuildRecords.add( dependantBuildRecord ); + return this; + } + + public Builder dependantBuildRecords(Set dependantBuildRecords) { + this.dependantBuildRecords = dependantBuildRecords; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java new file mode 100644 index 0000000000..68b9280930 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/ArtifactDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2301; + +/** + * @author Filip Hrisafov + */ +public class ArtifactDto { + + private final String name; + + public ArtifactDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java new file mode 100644 index 0000000000..cd3cca3744 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Mapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2301; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2301Mapper { + + Issue2301Mapper INSTANCE = Mappers.getMapper( Issue2301Mapper.class ); + + @Mapping(target = "dependantBuildRecords", ignore = true) + @Mapping(target = "dependantBuildRecord", ignore = true) + Artifact map(ArtifactDto dto); + + @InheritConfiguration + void update(@MappingTarget Artifact artifact, ArtifactDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java new file mode 100644 index 0000000000..8c237a2d30 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2301; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2301") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Artifact.class, + ArtifactDto.class, + Issue2301Mapper.class +}) +public class Issue2301Test { + + @Test + public void shouldCorrectlyIgnoreProperties() { + Artifact artifact = Issue2301Mapper.INSTANCE.map( new ArtifactDto( "mapstruct" ) ); + + assertThat( artifact ).isNotNull(); + assertThat( artifact.getName() ).isEqualTo( "mapstruct" ); + assertThat( artifact.getDependantBuildRecords() ).isNull(); + + Issue2301Mapper.INSTANCE.update( artifact, new ArtifactDto( "mapstruct-processor" ) ); + + assertThat( artifact.getName() ).isEqualTo( "mapstruct-processor" ); + } +} From 4223e3ab812a496aeb31b67a63737fb648bd2ddb Mon Sep 17 00:00:00 2001 From: Tomas Poledny Date: Thu, 5 Nov 2020 14:09:30 +0100 Subject: [PATCH 0539/1006] #2255 Add constants for componentModel --- core/src/main/java/org/mapstruct/Mapper.java | 6 +-- .../main/java/org/mapstruct/MapperConfig.java | 2 +- .../java/org/mapstruct/MappingConstants.java | 45 +++++++++++++++++++ .../chapter-4-retrieving-a-mapper.asciidoc | 6 +-- .../chapter-5-data-type-conversions.asciidoc | 2 +- .../cdi/DecoratedSourceTargetMapper.java | 3 +- .../itest/cdi/SourceTargetMapper.java | 3 +- .../jsr330/DecoratedSourceTargetMapper.java | 3 +- .../SecondDecoratedSourceTargetMapper.java | 3 +- .../itest/jsr330/SourceTargetMapper.java | 3 +- .../spring/DecoratedSourceTargetMapper.java | 3 +- .../SecondDecoratedSourceTargetMapper.java | 3 +- .../itest/spring/SourceTargetMapper.java | 3 +- .../ap/internal/gem/MappingConstantsGem.java | 19 ++++++++ .../processor/CdiComponentProcessor.java | 3 +- .../processor/Jsr330ComponentProcessor.java | 3 +- .../processor/MapperServiceProcessor.java | 3 +- .../processor/SpringComponentProcessor.java | 3 +- .../ap/test/bugs/_1395/Issue1395Mapper.java | 4 +- .../ap/test/bugs/_880/Issue880Test.java | 5 ++- .../_880/UsesConfigFromAnnotationMapper.java | 3 +- .../test/decorator/jsr330/PersonMapper.java | 3 +- .../spring/constructor/PersonMapper.java | 3 +- .../decorator/spring/field/PersonMapper.java | 3 +- .../DestinationClassNameWithJsr330Mapper.java | 3 +- .../mapstruct/ap/test/gem/ConstantTest.java | 9 ++++ .../ap/test/imports/SourceTargetMapper.java | 3 +- ...Jsr330DefaultCompileOptionFieldMapper.java | 4 +- ...Jsr330DefaultCompileOptionFieldMapper.java | 3 +- ...rJsr330CompileOptionConstructorMapper.java | 3 +- ...rJsr330CompileOptionConstructorMapper.java | 3 +- .../constructor/ConstructorJsr330Config.java | 4 +- .../CustomerJsr330ConstructorMapper.java | 3 +- .../field/CustomerJsr330FieldMapper.java | 4 +- .../jsr330/field/FieldJsr330Config.java | 3 +- .../_default/CustomerSpringDefaultMapper.java | 3 +- .../_default/GenderSpringDefaultMapper.java | 3 +- ...dSpringCompileOptionConstructorMapper.java | 3 +- ...rSpringCompileOptionConstructorMapper.java | 3 +- ...rSpringCompileOptionConstructorMapper.java | 3 +- .../constructor/ConstructorSpringConfig.java | 4 +- ...CustomerRecordSpringConstructorMapper.java | 3 +- .../CustomerSpringConstructorMapper.java | 3 +- .../field/CustomerSpringFieldMapper.java | 4 +- .../spring/field/FieldSpringConfig.java | 3 +- .../samename/Jsr330SourceTargetMapper.java | 3 +- 46 files changed, 166 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 233907621a..5ed9eab17f 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -35,7 +35,7 @@ *

    *
    
      * // we have MarkMapper (map field "mark" to field "name" to upper case)
    - * @Mapper(componentModel = "spring")
    + * @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
      * public class MarkMapper {
      *     public String mapMark(String mark) {
      *         return mark.toUpperCase();
    @@ -43,7 +43,7 @@
      * }
      * // we have CarMapper
      * @Mapper(
    - *      componentModel = "spring",
    + *      componentModel = MappingConstants.ComponentModel.SPRING,
      *      uses = MarkMapper.class,
      *      injectionStrategy = InjectionStrategy.CONSTRUCTOR)
      * public interface CarMapper {
    @@ -148,7 +148,7 @@
          *
          * @return The component model for the generated mapper.
          */
    -    String componentModel() default "default";
    +    String componentModel() default MappingConstants.ComponentModel.DEFAULT;
     
         /**
          * Specifies the name of the implementation class. The {@code } will be replaced by the
    diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java
    index d251ff3798..ecfd888ca2 100644
    --- a/core/src/main/java/org/mapstruct/MapperConfig.java
    +++ b/core/src/main/java/org/mapstruct/MapperConfig.java
    @@ -135,7 +135,7 @@
          *
          * @return The component model for the generated mapper.
          */
    -    String componentModel() default "default";
    +    String componentModel() default MappingConstants.ComponentModel.DEFAULT;
     
         /**
          * Specifies the name of the implementation class. The {@code } will be replaced by the
    diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java
    index 2c5757038f..6e30f08c21 100644
    --- a/core/src/main/java/org/mapstruct/MappingConstants.java
    +++ b/core/src/main/java/org/mapstruct/MappingConstants.java
    @@ -66,4 +66,49 @@ private MappingConstants() {
          */
         public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix";
     
    +    /**
    +    * Specifies the component model constants to which the generated mapper should adhere.
    +    * It can be used with the annotation {@link Mapper#componentModel()} or {@link MapperConfig#componentModel()}
    +    *
    +    * 

    + * Example: + *

    + *
    
    +    * // Spring component model
    +    * @Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
    +    * 
    + * + * @since 1.5.0 + */ + public static final class ComponentModel { + + private ComponentModel() { + } + + /** + * The mapper uses no component model, instances are typically retrieved + * via {@link org.mapstruct.factory.Mappers#getMapper(java.lang.Class)} + * + */ + public static final String DEFAULT = "default"; + + /** + * The generated mapper is an application-scoped CDI bean and can be retrieved via @Inject + */ + public static final String CDI = "cdi"; + + /** + * The generated mapper is a Spring bean and can be retrieved via @Autowired + * + */ + public static final String SPRING = "spring"; + + /** + * The generated mapper is annotated with @javax.inject.Named and @Singleton, and can be retrieved via @Inject + * + */ + public static final String JSR330 = "jsr330"; + + } + } diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc index 75b5b10294..724b42fbb7 100644 --- a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc @@ -69,14 +69,14 @@ Note that mappers generated by MapStruct are stateless and thread-safe and thus If you're working with a dependency injection framework such as http://jcp.org/en/jsr/detail?id=346[CDI] (Contexts and Dependency Injection for Java^TM^ EE) or the http://www.springsource.org/spring-framework[Spring Framework], it is recommended to obtain mapper objects via dependency injection and *not* via the `Mappers` class as described above. For that purpose you can specify the component model which generated mapper classes should be based on either via `@Mapper#componentModel` or using a processor option as described in <>. -Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: +Currently there is support for CDI and Spring (the latter either via its custom annotations or using the JSR 330 annotations). See <> for the allowed values of the `componentModel` attribute which are the same as for the `mapstruct.defaultComponentModel` processor option and constants are defined in a class `MappingConstants.ComponentModel`. In both cases the required annotations will be added to the generated mapper implementations classes in order to make the same subject to dependency injection. The following shows an example using CDI: .A mapper using the CDI component model ==== [source, java, linenums] [subs="verbatim,attributes"] ---- -@Mapper(componentModel = "cdi") +@Mapper(componentModel = MappingConstants.ComponentModel.CDI) public interface CarMapper { CarDto carToCarDto(Car car); @@ -110,7 +110,7 @@ This can be done by either providing the injection strategy via `@Mapper` or `@M [source, java, linenums] [subs="verbatim,attributes"] ---- -@Mapper(componentModel = "cdi", uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = EngineMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR) public interface CarMapper { CarDto carToCarDto(Car car); } diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 9619d0fe26..9978cd3f25 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -405,7 +405,7 @@ public class ReferenceMapper { } } -@Mapper(componentModel = "cdi", uses = ReferenceMapper.class ) +@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = ReferenceMapper.class ) public interface CarMapper { Car carDtoToCar(CarDto carDto); diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java index 1787fd3c90..18a57ce25e 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/DecoratedSourceTargetMapper.java @@ -6,10 +6,11 @@ package org.mapstruct.itest.cdi; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.DecoratedWith; import org.mapstruct.itest.cdi.other.DateMapper; -@Mapper( componentModel = "cdi", uses = DateMapper.class ) +@Mapper( componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class ) public interface DecoratedSourceTargetMapper { Target sourceToTarget(Source source); diff --git a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java index 3a46a20889..eb895f5e5a 100644 --- a/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/cdiTest/src/main/java/org/mapstruct/itest/cdi/SourceTargetMapper.java @@ -6,9 +6,10 @@ package org.mapstruct.itest.cdi; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.itest.cdi.other.DateMapper; -@Mapper(componentModel = "cdi", uses = DateMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.CDI, uses = DateMapper.class) public interface SourceTargetMapper { Target sourceToTarget(Source source); diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java index 137f234c26..77f5ec558a 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/DecoratedSourceTargetMapper.java @@ -6,10 +6,11 @@ package org.mapstruct.itest.jsr330; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.DecoratedWith; import org.mapstruct.itest.jsr330.other.DateMapper; -@Mapper(componentModel = "jsr330", uses = DateMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class) @DecoratedWith(SourceTargetMapperDecorator.class) public interface DecoratedSourceTargetMapper { diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java index cdec6dc19d..f088e21de4 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SecondDecoratedSourceTargetMapper.java @@ -6,10 +6,11 @@ package org.mapstruct.itest.jsr330; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.DecoratedWith; import org.mapstruct.itest.jsr330.other.DateMapper; -@Mapper(componentModel = "jsr330", uses = DateMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class) @DecoratedWith(SecondSourceTargetMapperDecorator.class) public interface SecondDecoratedSourceTargetMapper { diff --git a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java index c5ba3670fb..a96a860da5 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/jsr330Test/src/main/java/org/mapstruct/itest/jsr330/SourceTargetMapper.java @@ -6,9 +6,10 @@ package org.mapstruct.itest.jsr330; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.itest.jsr330.other.DateMapper; -@Mapper(componentModel = "jsr330", uses = DateMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = DateMapper.class) public interface SourceTargetMapper { Target sourceToTarget(Source source); diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java index f1bbf87d3a..a020ab2b27 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/DecoratedSourceTargetMapper.java @@ -6,10 +6,11 @@ package org.mapstruct.itest.spring; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.DecoratedWith; import org.mapstruct.itest.spring.other.DateMapper; -@Mapper( componentModel = "spring", uses = DateMapper.class ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class ) @DecoratedWith( SourceTargetMapperDecorator.class ) public interface DecoratedSourceTargetMapper { diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java index 88e2906300..7c04262595 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SecondDecoratedSourceTargetMapper.java @@ -6,10 +6,11 @@ package org.mapstruct.itest.spring; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.DecoratedWith; import org.mapstruct.itest.spring.other.DateMapper; -@Mapper( componentModel = "spring", uses = DateMapper.class ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class ) @DecoratedWith( SecondSourceTargetMapperDecorator.class ) public interface SecondDecoratedSourceTargetMapper { diff --git a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java index 06e4be4d22..e6d6b46339 100644 --- a/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/springTest/src/main/java/org/mapstruct/itest/spring/SourceTargetMapper.java @@ -6,9 +6,10 @@ package org.mapstruct.itest.spring; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.itest.spring.other.DateMapper; -@Mapper(componentModel = "spring", uses = DateMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = DateMapper.class) public interface SourceTargetMapper { Target sourceToTarget(Source source); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index 685f5a543c..5df7fd3f92 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -28,4 +28,23 @@ private MappingConstantsGem() { public static final String PREFIX_TRANSFORMATION = "prefix"; public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; + + /** + * Gem for the class {@link org.mapstruct.MappingConstants.ComponentModel} + * + */ + public final class ComponentModelGem { + + private ComponentModelGem() { + } + + public static final String DEFAULT = "default"; + + public static final String CDI = "cdi"; + + public static final String SPRING = "spring"; + + public static final String JSR330 = "jsr330"; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java index a5e3458681..74ff2b118b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; +import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; @@ -23,7 +24,7 @@ public class CdiComponentProcessor extends AnnotationBasedComponentModelProcesso @Override protected String getComponentModelIdentifier() { - return "cdi"; + return MappingConstantsGem.ComponentModelGem.CDI; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java index 4f7b46d643..18a6e4f69d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; +import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; @@ -23,7 +24,7 @@ public class Jsr330ComponentProcessor extends AnnotationBasedComponentModelProcessor { @Override protected String getComponentModelIdentifier() { - return "jsr330"; + return MappingConstantsGem.ComponentModelGem.JSR330; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java index f74a84c491..c9e37596f7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java @@ -11,6 +11,7 @@ import javax.tools.FileObject; import javax.tools.StandardLocation; +import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.GeneratedType; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.ServicesEntry; @@ -38,7 +39,7 @@ public Void process(ProcessorContext context, TypeElement mapperTypeElement, Map String componentModel = MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ).componentModel( ); - spiGenerationNeeded = "default".equals( componentModel ); + spiGenerationNeeded = MappingConstantsGem.ComponentModelGem.DEFAULT.equals( componentModel ); } if ( !context.isErroneous() && spiGenerationNeeded && mapper.hasCustomImplementation() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index 7780501a78..f7aa9b4fea 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; +import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; @@ -24,7 +25,7 @@ public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor { @Override protected String getComponentModelIdentifier() { - return "spring"; + return MappingConstantsGem.ComponentModelGem.SPRING; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java index 559e39512e..ebc9ae27e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java @@ -7,11 +7,13 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; /** * @author Filip Hrisafov */ -@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = "spring", uses = NotUsedService.class) +@Mapper(injectionStrategy = InjectionStrategy.CONSTRUCTOR, componentModel = MappingConstants.ComponentModel.SPRING, + uses = NotUsedService.class) public interface Issue1395Mapper { Target map(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index 2a80961bc5..4d491b1b2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -10,6 +10,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; @@ -30,7 +31,7 @@ Poodle.class, Config.class }) @ProcessorOptions({ - @ProcessorOption(name = "mapstruct.defaultComponentModel", value = "spring"), + @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING), @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") }) public class Issue880Test { @Rule @@ -40,7 +41,7 @@ public class Issue880Test { @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic(kind = Kind.WARNING, - type = UsesConfigFromAnnotationMapper.class, line = 16, + type = UsesConfigFromAnnotationMapper.class, line = 17, message = "Unmapped target property: \"core\".")) public void compilationSucceedsAndAppliesCorrectComponentModel() { generatedSource.forMapper( UsesConfigFromAnnotationMapper.class ).containsNoImportFor( Component.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java index ed4267cf12..d9a1efe33e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java @@ -6,12 +6,13 @@ package org.mapstruct.ap.test.bugs._880; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; /** * @author Andreas Gudian * */ -@Mapper(componentModel = "default", config = Config.class) +@Mapper(componentModel = MappingConstants.ComponentModel.DEFAULT, config = Config.class) public interface UsesConfigFromAnnotationMapper { Poodle metamorph(Object essence); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java index b37557bae1..770393f817 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/PersonMapper.java @@ -8,12 +8,13 @@ import org.mapstruct.DecoratedWith; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; -@Mapper(componentModel = "jsr330") +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) @DecoratedWith(PersonMapperDecorator.class) public interface PersonMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java index e1e57eb6f3..4ada1124c0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/PersonMapper.java @@ -9,12 +9,13 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; -@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.CONSTRUCTOR) @DecoratedWith(PersonMapperDecorator.class) public interface PersonMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java index fc03b6ce1a..5cbe867e7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/PersonMapper.java @@ -9,12 +9,13 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; -@Mapper(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD) @DecoratedWith(PersonMapperDecorator.class) public interface PersonMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java index 48d5547ff2..92c72a877d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java @@ -6,11 +6,12 @@ package org.mapstruct.ap.test.destination; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; /** * @author Christophe Labouisse on 27/05/2015. */ -@Mapper(implementationName = "Jsr330Impl", componentModel = "jsr330") +@Mapper(implementationName = "Jsr330Impl", componentModel = MappingConstants.ComponentModel.JSR330) public interface DestinationClassNameWithJsr330Mapper { String intToString(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index a2a6afefde..69fa56a310 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -30,4 +30,13 @@ public void constantsShouldBeEqual() { assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION ) .isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION ); } + + @Test + public void componentModelContantsShouldBeEqual() { + assertThat( MappingConstants.ComponentModel.DEFAULT ) + .isEqualTo( MappingConstantsGem.ComponentModelGem.DEFAULT ); + assertThat( MappingConstants.ComponentModel.CDI ).isEqualTo( MappingConstantsGem.ComponentModelGem.CDI ); + assertThat( MappingConstants.ComponentModel.SPRING ).isEqualTo( MappingConstantsGem.ComponentModelGem.SPRING ); + assertThat( MappingConstants.ComponentModel.JSR330 ).isEqualTo( MappingConstantsGem.ComponentModelGem.JSR330 ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java index 8e5e7b0de2..1380ca400a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java @@ -8,6 +8,7 @@ import java.util.Date; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.imports.referenced.Source; import org.mapstruct.ap.test.imports.referenced.Target; import org.mapstruct.ap.test.imports.to.Foo; @@ -16,7 +17,7 @@ /** * @author Gunnar Morling */ -@Mapper(componentModel = "jsr330") +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java index 9ce6b1215e..7fcbe97d5a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/CustomerJsr330DefaultCompileOptionFieldMapper.java @@ -6,13 +6,15 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330._default; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Andrei Arlou */ -@Mapper(componentModel = "jsr330", uses = GenderJsr330DefaultCompileOptionFieldMapper.class) +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, + uses = GenderJsr330DefaultCompileOptionFieldMapper.class) public interface CustomerJsr330DefaultCompileOptionFieldMapper { CustomerDto asTarget(CustomerEntity customerEntity); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java index 6701ce42fa..1ecf720cbf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/GenderJsr330DefaultCompileOptionFieldMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330._default; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; @@ -14,7 +15,7 @@ /** * @author Andrei Arlou */ -@Mapper(componentModel = "jsr330") +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) public interface GenderJsr330DefaultCompileOptionFieldMapper { @ValueMappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java index 0e89ec8943..143c452886 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java @@ -7,13 +7,14 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Andrei Arlou */ -@Mapper( componentModel = "jsr330", +@Mapper( componentModel = MappingConstants.ComponentModel.JSR330, uses = GenderJsr330CompileOptionConstructorMapper.class ) public interface CustomerJsr330CompileOptionConstructorMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java index da3caed5be..bffcc06bb9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/GenderJsr330CompileOptionConstructorMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; @@ -14,7 +15,7 @@ /** * @author Andrei Arlou */ -@Mapper(componentModel = "jsr330") +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) public interface GenderJsr330CompileOptionConstructorMapper { @ValueMappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java index 3bfc7d23ae..177b70d1dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/ConstructorJsr330Config.java @@ -7,10 +7,12 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; /** * @author Filip Hrisafov */ -@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330, + injectionStrategy = InjectionStrategy.CONSTRUCTOR) public interface ConstructorJsr330Config { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java index 001cb9f736..638e71a3aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java @@ -8,13 +8,14 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Kevin Grüneberg */ -@Mapper( componentModel = "jsr330", +@Mapper( componentModel = MappingConstants.ComponentModel.JSR330, uses = GenderJsr330ConstructorMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR ) public interface CustomerJsr330ConstructorMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java index 5c53a91c0f..a9e02280a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/CustomerJsr330FieldMapper.java @@ -7,13 +7,15 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Kevin Grüneberg */ -@Mapper(componentModel = "jsr330", uses = GenderJsr330FieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, uses = GenderJsr330FieldMapper.class, + injectionStrategy = InjectionStrategy.FIELD) public interface CustomerJsr330FieldMapper { CustomerDto asTarget(CustomerEntity customerEntity); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java index 33b5bbe8dc..ba3938ae48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/FieldJsr330Config.java @@ -7,10 +7,11 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; /** * @author Filip Hrisafov */ -@MapperConfig(componentModel = "jsr330", injectionStrategy = InjectionStrategy.FIELD) +@MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330, injectionStrategy = InjectionStrategy.FIELD) public interface FieldJsr330Config { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java index 34b06fc788..c7c2243d59 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/CustomerSpringDefaultMapper.java @@ -6,13 +6,14 @@ package org.mapstruct.ap.test.injectionstrategy.spring._default; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Filip Hrisafov */ -@Mapper(componentModel = "spring", uses = GenderSpringDefaultMapper.class ) +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringDefaultMapper.class ) public interface CustomerSpringDefaultMapper { CustomerDto asTarget(CustomerEntity customerEntity); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java index 106b93519e..e49a820994 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/GenderSpringDefaultMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.injectionstrategy.spring._default; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; @@ -14,7 +15,7 @@ /** * @author Filip Hrisafov */ -@Mapper(componentModel = "spring") +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) public interface GenderSpringDefaultMapper { @ValueMappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java index d7debfb96c..f411ba506f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerRecordSpringCompileOptionConstructorMapper.java @@ -6,13 +6,14 @@ package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; /** * @author Andrei Arlou */ -@Mapper(componentModel = "spring", +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = { CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class }, disableSubMappingMethodsGeneration = true) public interface CustomerRecordSpringCompileOptionConstructorMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java index db11c1b7ad..47060104f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java @@ -7,13 +7,14 @@ import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Andrei Arlou */ -@Mapper( componentModel = "spring", +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringCompileOptionConstructorMapper.class) public interface CustomerSpringCompileOptionConstructorMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java index c909f1dc5c..096fe91b96 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/GenderSpringCompileOptionConstructorMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.injectionstrategy.spring.compileoptionconstructor; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; @@ -14,7 +15,7 @@ /** * @author Andrei Arlou */ -@Mapper(componentModel = "spring") +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) public interface GenderSpringCompileOptionConstructorMapper { @ValueMappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java index f4b46e35c3..0bb89895cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/ConstructorSpringConfig.java @@ -7,10 +7,12 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; /** * @author Filip Hrisafov */ -@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.CONSTRUCTOR) +@MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING, + injectionStrategy = InjectionStrategy.CONSTRUCTOR) public interface ConstructorSpringConfig { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java index a7f9e8a8b2..c2a5862978 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerRecordSpringConstructorMapper.java @@ -7,13 +7,14 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; /** * @author Kevin Grüneberg */ -@Mapper(componentModel = "spring", +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = { CustomerSpringConstructorMapper.class, GenderSpringConstructorMapper.class }, injectionStrategy = InjectionStrategy.CONSTRUCTOR, disableSubMappingMethodsGeneration = true) diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java index 9a9ab0119a..4ea869ec5f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java @@ -8,13 +8,14 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Kevin Grüneberg */ -@Mapper( componentModel = "spring", +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringConstructorMapper.class, injectionStrategy = InjectionStrategy.CONSTRUCTOR ) public interface CustomerSpringConstructorMapper { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java index 449cc5e435..fb8a316c59 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/CustomerSpringFieldMapper.java @@ -7,13 +7,15 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; /** * @author Kevin Grüneberg */ -@Mapper(componentModel = "spring", uses = GenderSpringFieldMapper.class, injectionStrategy = InjectionStrategy.FIELD) +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, uses = GenderSpringFieldMapper.class, + injectionStrategy = InjectionStrategy.FIELD) public interface CustomerSpringFieldMapper { CustomerDto asTarget(CustomerEntity customerEntity); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java index d44a54c935..c9e3c3f0f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/FieldSpringConfig.java @@ -7,10 +7,11 @@ import org.mapstruct.InjectionStrategy; import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; /** * @author Filip Hrisafov */ -@MapperConfig(componentModel = "spring", injectionStrategy = InjectionStrategy.FIELD) +@MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.FIELD) public interface FieldSpringConfig { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java index 6d613b0f91..f63b49eef5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/Jsr330SourceTargetMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.references.samename; import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.test.references.samename.a.CustomMapper; import org.mapstruct.ap.test.references.samename.model.Source; import org.mapstruct.ap.test.references.samename.model.Target; @@ -15,7 +16,7 @@ * @author Gunnar Morling */ @Mapper( - componentModel = "jsr330", + componentModel = MappingConstants.ComponentModel.JSR330, uses = { CustomMapper.class, org.mapstruct.ap.test.references.samename.b.CustomMapper.class From dfc752809604dfcff8bec9d5c1c8f679c9dcae61 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 17 Jan 2021 11:39:57 +0100 Subject: [PATCH 0540/1006] Small fixes for Java 16 * Upgrade japicmp-maven-plugin to 0.15.2 * Do not use deprecated for removal Long constructor * Update Spring to 5.3.3 * Upgrade Lombok to 1.18.16 + add lombok-mapstruct-binding --- integrationtest/pom.xml | 1 - .../src/test/resources/lombokBuilderTest/pom.xml | 6 ++++++ parent/pom.xml | 8 ++++---- .../mapstruct/ap/test/exceptions/ExceptionTestMapper.java | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f19ecfe343..17a6a4a9a9 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -65,7 +65,6 @@ commons-io commons-io - 2.6 test diff --git a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml index 92ece809fe..5d43efb1d3 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/lombokBuilderTest/pom.xml @@ -25,5 +25,11 @@ lombok compile + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + compile + diff --git a/parent/pom.xml b/parent/pom.xml index 9e5c04f27a..b6a619a90b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ 3.0.0-M3 3.0.0-M5 3.1.0 - 4.0.3.RELEASE + 5.3.3 1.6.0 8.36.1 5.7.0 @@ -202,7 +202,7 @@ org.projectlombok lombok - 1.18.10 + 1.18.16 org.immutables @@ -261,7 +261,7 @@ commons-io commons-io - 2.5 + 2.6 @@ -553,7 +553,7 @@ com.github.siom79.japicmp japicmp-maven-plugin - 0.13.1 + 0.15.2 verify diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java index c856c0d3bf..13d0d1f5cf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTestMapper.java @@ -20,6 +20,6 @@ public Long toLong(Integer size) throws TestException1, TestException2 { else if ( size == 2 ) { throw new TestException2(); } - return new Long(size); + return Long.valueOf( size ); } } From 8478a5455b6dec8da99c1978ac00f0f2605a51c3 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 23 Jan 2021 09:15:46 +0100 Subject: [PATCH 0541/1006] #2278 inherited property ignored due to ignore on nested level (#2332) Co-authored-by: sjaakd --- .../model/source/MappingMethodOptions.java | 10 +- .../ap/test/bugs/_2278/Issue2278MapperA.java | 62 ++++++++++ .../ap/test/bugs/_2278/Issue2278MapperB.java | 65 ++++++++++ .../bugs/_2278/Issue2278ReferenceMapper.java | 54 ++++++++ .../ap/test/bugs/_2278/Issue2278Test.java | 95 +++++++++++++++ .../ap/test/bugs/_2318/Issue2318Mapper.java | 115 ++++++++++++++++++ .../ap/test/bugs/_2318/Issue2318Test.java | 38 ++++++ 7 files changed, 435 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index b7fd7f00d0..859a4c6f5f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -230,9 +230,11 @@ private void addAllNonRedefined(Set inheritedMappings) { } private boolean isRedefined(Set redefinedNames, String inheritedName ) { - for ( String redefinedName : redefinedNames ) { - if ( elementsAreContainedIn( redefinedName, inheritedName ) ) { - return true; + if ( inheritedName != null ) { + for ( String redefinedName : redefinedNames ) { + if ( elementsAreContainedIn( inheritedName, redefinedName ) ) { + return true; + } } } return false; @@ -241,7 +243,7 @@ private boolean isRedefined(Set redefinedNames, String inheritedName ) { private boolean elementsAreContainedIn( String redefinedName, String inheritedName ) { if ( inheritedName != null && redefinedName.startsWith( inheritedName ) ) { // it is possible to redefine an exact matching source name, because the same source can be mapped to - // multiple targets. It is not possible for target, but caught by the Set and equals methoded in + // multiple targets. It is not possible for target, but caught by the Set and equals method in // MappingOptions. SourceName == null also could hint at redefinition if ( redefinedName.length() > inheritedName.length() ) { // redefined.lenght() > inherited.length(), first following character should be separator diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java new file mode 100644 index 0000000000..8527be3f89 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperA.java @@ -0,0 +1,62 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2278; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * ReproducerA + * + */ +@Mapper +public interface Issue2278MapperA { + + Issue2278MapperA INSTANCE = Mappers.getMapper( Issue2278MapperA.class ); + + @Mapping( target = "detailsDTO", source = "details" ) + @Mapping( target = "detailsDTO.fuelType", ignore = true ) + CarDTO map(Car in); + + // checkout the Issue2278ReferenceMapper, the @InheritInverseConfiguration + // is de-facto @Mapping( target = "details", source = "detailsDTO" ) + @InheritInverseConfiguration + @Mapping( target = "details.model", ignore = true ) + @Mapping( target = "details.type", constant = "gto") + @Mapping( target = "details.fuel", source = "detailsDTO.fuelType") + Car map(CarDTO in); + + class Car { + //CHECKSTYLE:OFF + public Details details; + //CHECKSTYLE:ON + } + + class CarDTO { + //CHECKSTYLE:OFF + public DetailsDTO detailsDTO; + //CHECKSTYLE:ON + } + + class Details { + //CHECKSTYLE:OFF + public String brand; + public String model; + public String type; + public String fuel; + //CHECKSTYLE:ON + } + + class DetailsDTO { + //CHECKSTYLE:OFF + public String brand; + public String fuelType; + //CHECKSTYLE:ON + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java new file mode 100644 index 0000000000..b9d0abd523 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278MapperB.java @@ -0,0 +1,65 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2278; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * ReproducerB + * + */ +@Mapper +public interface Issue2278MapperB { + + Issue2278MapperB INSTANCE = Mappers.getMapper( Issue2278MapperB.class ); + + // id mapping is cros-linked + @Mapping( target = "amount", source = "price" ) + @Mapping( target = "detailsDTO.brand", source = "details.type" ) + @Mapping( target = "detailsDTO.id1", source = "details.id2" ) + @Mapping( target = "detailsDTO.id2", source = "details.id1" ) + CarDTO map(Car in); + + // inherit inverse, but undo cross-link in one sweep + @InheritInverseConfiguration // inherits all + @Mapping( target = "details", source = "detailsDTO" ) // resets everything on details <> detailsDto + @Mapping( target = "details.type", source = "detailsDTO.brand" ) // so this needs to be redone + Car map2(CarDTO in); + + class Car { + //CHECKSTYLE:OFF + public float price; + public Details details; + //CHECKSTYLE:ON + } + + class CarDTO { + //CHECKSTYLE:OFF + public float amount; + public DetailsDTO detailsDTO; + //CHECKSTYLE:ON + } + + class Details { + //CHECKSTYLE:OFF + public String type; + public String id1; + public String id2; + //CHECKSTYLE:ON + } + + class DetailsDTO { + //CHECKSTYLE:OFF + public String brand; + public String id1; + public String id2; + //CHECKSTYLE:ON + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java new file mode 100644 index 0000000000..48b457f84c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278ReferenceMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2278; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * A reference mapper, that checks how a regular forward merge works + */ +@Mapper +public interface Issue2278ReferenceMapper { + + Issue2278ReferenceMapper INSTANCE = Mappers.getMapper( Issue2278ReferenceMapper.class ); + + @Mapping( target = "details", source = "detailsDTO" ) + @Mapping( target = "details.model", ignore = true ) + @Mapping( target = "details.type", constant = "gto") + @Mapping( target = "details.fuel", source = "detailsDTO.fuelType") + Car map(CarDTO in); + + class Car { + //CHECKSTYLE:OFF + public Details details; + //CHECKSTYLE:ON + } + + class CarDTO { + //CHECKSTYLE:OFF + public DetailsDTO detailsDTO; + //CHECKSTYLE:ON + } + + class Details { + //CHECKSTYLE:OFF + public String brand; + public String model; + public String type; + public String fuel; + //CHECKSTYLE:ON + } + + class DetailsDTO { + //CHECKSTYLE:OFF + public String brand; + public String fuelType; + //CHECKSTYLE:ON + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java new file mode 100644 index 0000000000..eefebfa870 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java @@ -0,0 +1,95 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2278; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +@IssueKey("2278") +@RunWith( AnnotationProcessorTestRunner.class) +public class Issue2278Test { + + @Test + @WithClasses( Issue2278ReferenceMapper.class ) + public void testReferenceMergeBehaviour() { + + Issue2278ReferenceMapper.CarDTO dto = new Issue2278ReferenceMapper.CarDTO(); + dto.detailsDTO = new Issue2278ReferenceMapper.DetailsDTO(); + dto.detailsDTO.brand = "Ford"; + dto.detailsDTO.fuelType = "petrol"; + + Issue2278ReferenceMapper.Car target = Issue2278ReferenceMapper.INSTANCE.map( dto ); + + assertThat( target ).isNotNull(); + assertThat( target.details ).isNotNull(); + assertThat( target.details.brand ).isEqualTo( "Ford" ); + assertThat( target.details.model ).isNull(); + assertThat( target.details.type ).isEqualTo( "gto" ); + assertThat( target.details.fuel ).isEqualTo( "petrol" ); + + } + + @Test + @WithClasses( Issue2278MapperA.class ) + public void shouldBehaveJustAsTestReferenceMergeBehaviour() { + + Issue2278MapperA.CarDTO dto = new Issue2278MapperA.CarDTO(); + dto.detailsDTO = new Issue2278MapperA.DetailsDTO(); + dto.detailsDTO.brand = "Ford"; + dto.detailsDTO.fuelType = "petrol"; + + Issue2278MapperA.Car target = Issue2278MapperA.INSTANCE.map( dto ); + + assertThat( target ).isNotNull(); + assertThat( target.details ).isNotNull(); + assertThat( target.details.brand ).isEqualTo( "Ford" ); + assertThat( target.details.model ).isNull(); + assertThat( target.details.type ).isEqualTo( "gto" ); + assertThat( target.details.fuel ).isEqualTo( "petrol" ); + + } + + @Test + @WithClasses( Issue2278MapperB.class ) + public void shouldOverrideDetailsMappingWithRedefined() { + + Issue2278MapperB.Car source = new Issue2278MapperB.Car(); + source.details = new Issue2278MapperB.Details(); + source.details.type = "Ford"; + source.details.id1 = "id1"; + source.details.id2 = "id2"; + source.price = 20000f; + + Issue2278MapperB.CarDTO target1 = Issue2278MapperB.INSTANCE.map( source ); + + assertThat( target1 ).isNotNull(); + assertThat( target1.amount ).isEqualTo( 20000f ); + assertThat( target1.detailsDTO ).isNotNull(); + assertThat( target1.detailsDTO.brand ).isEqualTo( "Ford" ); + assertThat( target1.detailsDTO.id1 ).isEqualTo( "id2" ); + assertThat( target1.detailsDTO.id2 ).isEqualTo( "id1" ); + + // restore the mappings, just to make it logical again + target1.detailsDTO.id1 = "id1"; + target1.detailsDTO.id2 = "id2"; + + // now check the reverse inheritance + Issue2278MapperB.Car target2 = Issue2278MapperB.INSTANCE.map2( target1 ); + + assertThat( target2 ).isNotNull(); + assertThat( target2.price ).isEqualTo( 20000f ); + assertThat( target2.details ).isNotNull(); + assertThat( target2.details.type ).isEqualTo( "Ford" ); // should inherit + assertThat( target2.details.id1 ).isEqualTo( "id1" ); // should be undone + assertThat( target2.details.id2 ).isEqualTo( "id2" ); // should be undone + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java new file mode 100644 index 0000000000..20621e4d01 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Mapper.java @@ -0,0 +1,115 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2318; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper(config = Issue2318Mapper.Config.class) +public interface Issue2318Mapper { + + Issue2318Mapper INSTANCE = Mappers.getMapper( Issue2318Mapper.class ); + + @MapperConfig + interface Config { + + @Mapping(target = "parentValue1", source = "holder") + TargetParent mapParent(SourceParent parent); + + @InheritConfiguration(name = "mapParent") + @Mapping(target = "childValue", source = "value") + @Mapping(target = "parentValue2", source = "holder.parentValue2") + TargetChild mapChild(SourceChild child); + } + + @InheritConfiguration(name = "mapChild") + TargetChild mapChild(SourceChild child); + + default String parentValue1(SourceParent.Holder holder) { + return holder.getParentValue1(); + } + + class SourceParent { + private Holder holder; + + public Holder getHolder() { + return holder; + } + + public void setHolder(Holder holder) { + this.holder = holder; + } + + public static class Holder { + private String parentValue1; + private Integer parentValue2; + + public String getParentValue1() { + return parentValue1; + } + + public void setParentValue1(String parentValue1) { + this.parentValue1 = parentValue1; + } + + public Integer getParentValue2() { + return parentValue2; + } + + public void setParentValue2(Integer parentValue2) { + this.parentValue2 = parentValue2; + } + } + } + + class SourceChild extends SourceParent { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class TargetParent { + private String parentValue1; + private Integer parentValue2; + + public String getParentValue1() { + return parentValue1; + } + + public void setParentValue1(String parentValue1) { + this.parentValue1 = parentValue1; + } + + public Integer getParentValue2() { + return parentValue2; + } + + public void setParentValue2(Integer parentValue2) { + this.parentValue2 = parentValue2; + } + } + + class TargetChild extends TargetParent { + private String childValue; + + public String getChildValue() { + return childValue; + } + + public void setChildValue(String childValue) { + this.childValue = childValue; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java new file mode 100644 index 0000000000..a1f1ad250b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2318; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.SourceChild; +import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.TargetChild; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("2318") +@RunWith(AnnotationProcessorTestRunner.class) +public class Issue2318Test { + + @Test + @WithClasses( Issue2318Mapper.class ) + public void shouldMap() { + + SourceChild source = new SourceChild(); + source.setValue( "From child" ); + source.setHolder( new Issue2318Mapper.SourceParent.Holder() ); + source.getHolder().setParentValue1( "From parent" ); + source.getHolder().setParentValue2( 12 ); + + TargetChild target = Issue2318Mapper.INSTANCE.mapChild( source ); + + assertThat( target.getParentValue1() ).isEqualTo( "From parent" ); + assertThat( target.getParentValue2() ).isEqualTo( 12 ); + assertThat( target.getChildValue() ).isEqualTo( "From child" ); + } +} From 0d8bbacc53bfd101015a5d8860d67a3c2d71ea1c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 16 Jan 2021 19:43:22 +0100 Subject: [PATCH 0542/1006] #2250, #2324 Do not throw error when qualifier is missing on iterable mapping With this change we are relaxing the error handling when qualifiers are used in `@Mapping` and we allow defining qualifiers for collections / array mapping to mean the same as if it was defined on `@IterableMapping` i.e. apply the qualifier on the element mapping --- .../model/ContainerMappingMethodBuilder.java | 10 +++- .../ap/internal/model/PropertyMapping.java | 1 + .../creation/MappingResolverImpl.java | 8 +++- ...neousMessageByNamedWithIterableMapper.java | 31 ++++++++++++ .../qualifier/errors/QualfierMessageTest.java | 23 +++++++++ .../selection/qualifier/iterable/Cities.java | 23 +++++++++ .../iterable/IterableAndQualifiersTest.java | 40 +++++++++++++++- .../selection/qualifier/iterable/Rivers.java | 23 +++++++++ .../qualifier/iterable/TopologyMapper.java | 17 ------- .../TopologyWithoutIterableMappingMapper.java | 47 +++++++++++++++++++ 10 files changed, 203 insertions(+), 20 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java index b9bbf6d094..be08ac1ca4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethodBuilder.java @@ -22,6 +22,8 @@ import static org.mapstruct.ap.internal.util.Collections.first; +import javax.lang.model.element.AnnotationMirror; + /** * Builder that can be used to build {@link ContainerMappingMethod}(s). * @@ -37,6 +39,7 @@ public abstract class ContainerMappingMethodBuilder selfType, String errorMessagePart) { super( selfType ); @@ -58,6 +61,11 @@ public B callingContextTargetPropertyName(String callingContextTargetPropertyNam return myself; } + public B positionHint(AnnotationMirror positionHint) { + this.positionHint = positionHint; + return myself; + } + @Override public final M build() { Type sourceParameterType = first( method.getSourceParameters() ).getType(); @@ -88,7 +96,7 @@ public final M build() { formattingParameters, criteria, sourceRHS, - null, + positionHint, () -> forge( sourceRHS, sourceElementType, targetElementType ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 61e1fca864..48ebc34d29 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -656,6 +656,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou .method( methodRef ) .selectionParameters( selectionParameters ) .callingContextTargetPropertyName( targetPropertyName ) + .positionHint( positionHint ) .build(); return createForgedAssignment( source, methodRef, iterableMappingMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index debe8f30dc..5f9121082c 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -298,7 +298,13 @@ && allowDirect( sourceType, targetType ) ) { } if ( hasQualfiers() ) { - printQualifierMessage( selectionCriteria ); + if ((sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType()) { + // Allow forging iterable mapping when no iterable mapping already found + return forger.get(); + } + else { + printQualifierMessage( selectionCriteria ); + } } else if ( allowMappingMethod() ) { // only forge if we would allow mapping method diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java new file mode 100644 index 0000000000..088207c610 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/ErroneousMessageByNamedWithIterableMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.errors; + +import java.util.Collection; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousMessageByNamedWithIterableMapper { + + @Mapping(target = "elements", qualifiedByName = "SelectMe") + Target map(Source source); + + // CHECKSTYLE:OFF + class Source { + + public Collection elements; + } + + class Target { + + public Collection elements; + } + // CHECKSTYLE ON + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java index 4c8edc64dd..48295ed4fb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java @@ -87,4 +87,27 @@ public void testNoQualifyingMethodByNamedFound() { ) public void testNoQualifyingMethodByAnnotationAndNamedFound() { } + + @Test + @WithClasses(ErroneousMessageByNamedWithIterableMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousMessageByNamedWithIterableMapper.class, + kind = ERROR, + line = 16, + message = "Qualifier error. No method found annotated with @Named#value: [ SelectMe ]. " + + "See https://mapstruct.org/faq/#qualifier for more info."), + @Diagnostic( + type = ErroneousMessageByNamedWithIterableMapper.class, + kind = ERROR, + line = 16, + messageRegExp = "Can't map property.*"), + + } + ) + public void testNoQualifyingMethodByNamedForForgedIterableFound() { + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java new file mode 100644 index 0000000000..828750399a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Cities.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.iterable; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Qualifier; + +/** + * @author Filip Hrisafov + */ +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface Cities { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java index db8de9496e..c2465b255e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.factory.Mappers; /** * @@ -22,20 +23,22 @@ */ @IssueKey( "707" ) @WithClasses( { + Cities.class, CityDto.class, CityEntity.class, RiverDto.class, RiverEntity.class, + Rivers.class, TopologyDto.class, TopologyEntity.class, TopologyFeatureDto.class, TopologyFeatureEntity.class, - TopologyMapper.class } ) @RunWith( AnnotationProcessorTestRunner.class ) public class IterableAndQualifiersTest { @Test + @WithClasses(TopologyMapper.class) public void testGenerationBasedOnQualifier() { TopologyDto topologyDto1 = new TopologyDto(); @@ -67,4 +70,39 @@ public void testGenerationBasedOnQualifier() { assertThat( ( (CityEntity) result2.getTopologyFeatures().get( 0 ) ).getPopulation() ).isEqualTo( 800000 ); } + + @Test + @WithClasses(TopologyWithoutIterableMappingMapper.class) + public void testIterableGeneratorBasedOnQualifier() { + + TopologyWithoutIterableMappingMapper mapper = Mappers.getMapper( TopologyWithoutIterableMappingMapper.class ); + + TopologyDto riverTopologyDto = new TopologyDto(); + List topologyFeatures1 = new ArrayList<>(); + RiverDto riverDto = new RiverDto(); + riverDto.setName( "Rhine" ); + riverDto.setLength( 5 ); + topologyFeatures1.add( riverDto ); + riverTopologyDto.setTopologyFeatures( topologyFeatures1 ); + + TopologyEntity riverTopology = mapper.mapTopologyAsRiver( riverTopologyDto ); + assertThat( riverTopology.getTopologyFeatures() ).hasSize( 1 ); + assertThat( riverTopology.getTopologyFeatures().get( 0 ).getName() ).isEqualTo( "Rhine" ); + assertThat( riverTopology.getTopologyFeatures().get( 0 ) ).isInstanceOf( RiverEntity.class ); + assertThat( ( (RiverEntity) riverTopology.getTopologyFeatures().get( 0 ) ).getLength() ).isEqualTo( 5 ); + + TopologyDto cityTopologyDto = new TopologyDto(); + List topologyFeatures2 = new ArrayList<>(); + CityDto cityDto = new CityDto(); + cityDto.setName( "Amsterdam" ); + cityDto.setPopulation( 800000 ); + topologyFeatures2.add( cityDto ); + cityTopologyDto.setTopologyFeatures( topologyFeatures2 ); + + TopologyEntity cityTopology = mapper.mapTopologyAsCity( cityTopologyDto ); + assertThat( cityTopology.getTopologyFeatures() ).hasSize( 1 ); + assertThat( cityTopology.getTopologyFeatures().get( 0 ).getName() ).isEqualTo( "Amsterdam" ); + assertThat( cityTopology.getTopologyFeatures().get( 0 ) ).isInstanceOf( CityEntity.class ); + assertThat( ( (CityEntity) cityTopology.getTopologyFeatures().get( 0 ) ).getPopulation() ).isEqualTo( 800000 ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java new file mode 100644 index 0000000000..f6a56951a1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/Rivers.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.iterable; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Qualifier; + +/** + * @author Filip Hrisafov + */ +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface Rivers { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java index 22e87dd084..84c4bc58a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyMapper.java @@ -5,16 +5,11 @@ */ package org.mapstruct.ap.test.selection.qualifier.iterable; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.util.List; import org.mapstruct.IterableMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Qualifier; import org.mapstruct.factory.Mappers; /** @@ -64,16 +59,4 @@ protected TopologyFeatureEntity mapCity( TopologyFeatureDto dto ) { return topologyFeatureEntity; } - @Qualifier - @Target(ElementType.METHOD) - @Retention(RetentionPolicy.CLASS) - public @interface Rivers { - } - - @Qualifier - @Target(ElementType.METHOD) - @Retention(RetentionPolicy.CLASS) - public @interface Cities { - } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java new file mode 100644 index 0000000000..4b72b34663 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/TopologyWithoutIterableMappingMapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.iterable; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface TopologyWithoutIterableMappingMapper { + + @Mapping( target = "topologyFeatures", qualifiedBy = Rivers.class ) + TopologyEntity mapTopologyAsRiver(TopologyDto dto); + + @Mapping( target = "topologyFeatures", qualifiedBy = Cities.class ) + TopologyEntity mapTopologyAsCity(TopologyDto dto); + + @Rivers + default TopologyFeatureEntity mapRiver( TopologyFeatureDto dto ) { + TopologyFeatureEntity topologyFeatureEntity = null; + if ( dto instanceof RiverDto ) { + RiverEntity riverEntity = new RiverEntity(); + riverEntity.setLength( ( (RiverDto) dto ).getLength() ); + topologyFeatureEntity = riverEntity; + topologyFeatureEntity.setName( dto.getName() ); + } + return topologyFeatureEntity; + } + + @Cities + default TopologyFeatureEntity mapCity( TopologyFeatureDto dto ) { + TopologyFeatureEntity topologyFeatureEntity = null; + if ( dto instanceof CityDto ) { + CityEntity cityEntity = new CityEntity(); + cityEntity.setPopulation( ( (CityDto) dto ).getPopulation() ); + topologyFeatureEntity = cityEntity; + topologyFeatureEntity.setName( dto.getName() ); + } + return topologyFeatureEntity; + } + +} From 08af258533c6f949de8b0e1a71fb79beab895b5a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 Jan 2021 10:35:04 +0100 Subject: [PATCH 0543/1006] #2346 Update documentation and readme about MapStruct and Gradle Remove obsolete net.ltgt.apt Use com.diffplug.eclipse.apt for Eclipse IntelliJ works transparently --- .../main/asciidoc/chapter-2-set-up.asciidoc | 36 ++----------------- readme.md | 7 +--- 2 files changed, 3 insertions(+), 40 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index cb0067f2f3..76626f44ce 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -76,7 +76,7 @@ It will not work with older versions. Add the following to your Gradle build file in order to enable MapStruct: -.Gradle configuration (3.4 and later) +.Gradle configuration ==== [source, groovy, linenums] [subs="verbatim,attributes"] @@ -84,14 +84,9 @@ Add the following to your Gradle build file in order to enable MapStruct: ... plugins { ... - id 'net.ltgt.apt' version '0.20' + id "com.diffplug.eclipse.apt" version "3.26.0" // Only for Eclipse } -// You can integrate with your IDEs. -// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides -apply plugin: 'net.ltgt.apt-idea' -apply plugin: 'net.ltgt.apt-eclipse' - dependencies { ... implementation "org.mapstruct:mapstruct:${mapstructVersion}" @@ -103,33 +98,6 @@ dependencies { ... ---- ==== -.Gradle (3.3 and older) -==== -[source, groovy, linenums] -[subs="verbatim,attributes"] ----- -... -plugins { - ... - id 'net.ltgt.apt' version '0.20' -} - -// You can integrate with your IDEs. -// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides -apply plugin: 'net.ltgt.apt-idea' -apply plugin: 'net.ltgt.apt-eclipse' - -dependencies { - ... - compile "org.mapstruct:mapstruct:${mapstructVersion}" - annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" - - // If you are using mapstruct in test code - testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" -} -... ----- -==== You can find a complete example in the https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-on-gradle[mapstruct-examples] project on GitHub. diff --git a/readme.md b/readme.md index c39a408ac2..45eeda27e6 100644 --- a/readme.md +++ b/readme.md @@ -109,14 +109,9 @@ For Gradle, you need something along the following lines: ```groovy plugins { ... - id 'net.ltgt.apt' version '0.15' + id "com.diffplug.eclipse.apt" version "3.26.0" // Only for Eclipse } -// You can integrate with your IDEs. -// See more details: https://github.com/tbroyer/gradle-apt-plugin#usage-with-ides -apply plugin: 'net.ltgt.apt-idea' -apply plugin: 'net.ltgt.apt-eclipse' - dependencies { ... compile 'org.mapstruct:mapstruct:1.4.1.Final' From aeadf8cb77978334619e40801faed25e5eaa54b3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 31 Jan 2021 14:52:11 +0100 Subject: [PATCH 0544/1006] Update readme with latest released 1.4.2.Final release --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 45eeda27e6..5fc8399748 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.2.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.4.1.Final + 1.4.2.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - compile 'org.mapstruct:mapstruct:1.4.1.Final' + compile 'org.mapstruct:mapstruct:1.4.2.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.1.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // if you are using mapstruct in test code } ... ``` From c59ca79e7f992d051661fa2d39eb1cbee014b116 Mon Sep 17 00:00:00 2001 From: dmngb <26900086+dmngb@users.noreply.github.com> Date: Sat, 6 Feb 2021 16:10:32 +0100 Subject: [PATCH 0545/1006] #2277 default component model: mapper reference use singleton INSTANCE if it exists (#2280) This allows to easily avoid the runtime dependency on mapstruct.jar: we can avoid Mappers.getMapper(...) for instantiating used mappers if the code follows the conventional pattern for creating mapper singletons. Co-authored-by: GIBOU Damien --- .../model/DefaultMapperReference.java | 18 +++++++++---- .../processor/MapperCreationProcessor.java | 26 +++++++++++++++++++ .../internal/model/DefaultMapperReference.ftl | 2 +- .../selection/OrganizationMapper1Impl.java | 3 +-- .../selection/OrganizationMapper3Impl.java | 3 +-- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java index 924648368a..6ac0c1c74d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java @@ -21,19 +21,22 @@ */ public class DefaultMapperReference extends MapperReference { + private final boolean isSingleton; private final boolean isAnnotatedMapper; private final Set importTypes; - private DefaultMapperReference(Type type, boolean isAnnotatedMapper, Set importTypes, String variableName) { + private DefaultMapperReference(Type type, boolean isAnnotatedMapper, boolean isSingleton, + Set importTypes, String variableName) { super( type, variableName ); this.isAnnotatedMapper = isAnnotatedMapper; this.importTypes = importTypes; + this.isSingleton = isSingleton; } - public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedMapper, TypeFactory typeFactory, - List otherMapperReferences) { + public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedMapper, boolean isSingleton, + TypeFactory typeFactory, List otherMapperReferences) { Set importTypes = Collections.asSet( type ); - if ( isAnnotatedMapper ) { + if ( isAnnotatedMapper && !isSingleton) { importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) ); } @@ -42,7 +45,7 @@ public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedM otherMapperReferences ); - return new DefaultMapperReference( type, isAnnotatedMapper, importTypes, variableName ); + return new DefaultMapperReference( type, isAnnotatedMapper, isSingleton, importTypes, variableName ); } @Override @@ -53,4 +56,9 @@ public Set getImportTypes() { public boolean isAnnotatedMapper() { return isAnnotatedMapper; } + + public boolean isSingleton() { + return isSingleton; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index a0014f5934..ad6d84b9e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.processor; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -13,7 +14,9 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -60,6 +63,9 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; +import static javax.lang.model.element.Modifier.FINAL; +import static javax.lang.model.element.Modifier.PUBLIC; +import static javax.lang.model.element.Modifier.STATIC; import static org.mapstruct.ap.internal.model.SupportingConstructorFragment.addAllFragmentsIn; import static org.mapstruct.ap.internal.model.SupportingField.addAllFieldsIn; import static org.mapstruct.ap.internal.util.Collections.first; @@ -73,6 +79,9 @@ */ public class MapperCreationProcessor implements ModelElementProcessor, Mapper> { + /** Modifiers for public "constant" e.g. "public static final" */ + private static final List PUBLIC_CONSTANT_MODIFIERS = Arrays.asList( PUBLIC, STATIC, FINAL ); + private ElementUtils elementUtils; private TypeUtils typeUtils; private FormattingMessager messager; @@ -136,6 +145,7 @@ private List initReferencedMappers(TypeElement element, MapperO DefaultMapperReference mapperReference = DefaultMapperReference.getInstance( typeFactory.getType( usedMapper ), MapperGem.instanceOn( typeUtils.asElement( usedMapper ) ) != null, + hasSingletonInstance( usedMapper ), typeFactory, variableNames ); @@ -147,6 +157,22 @@ private List initReferencedMappers(TypeElement element, MapperO return result; } + private boolean hasSingletonInstance(TypeMirror mapper) { + return typeUtils.asElement( mapper ).getEnclosedElements().stream() + .anyMatch( a -> isPublicConstantOfType( a, "INSTANCE", mapper ) ); + } + + /** + * @return true if the element is a "public static final" field (e.g. a constant) + * named fieldName of type "fieldType" + */ + private boolean isPublicConstantOfType(Element element, String fieldName, TypeMirror fieldType) { + return element.getKind().isField() && + element.getModifiers().containsAll( PUBLIC_CONSTANT_MODIFIERS ) && + element.getSimpleName().contentEquals( fieldName ) && + typeUtils.isSameType( element.asType(), fieldType ); + } + private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List methods) { List mappingMethods = getMappingMethods( mapperOptions, methods ); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl index e4eeddb4b5..b2ab4cb6f0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/DefaultMapperReference.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.DefaultMapperReference" --> -private final <@includeModel object=type/> ${variableName} = <#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>(); \ No newline at end of file +private final <@includeModel object=type/> ${variableName} = <#if singleton><@includeModel object=type/>.INSTANCE;<#else><#if annotatedMapper>Mappers.getMapper( <@includeModel object=type/>.class );<#else>new <@includeModel object=type/>(); \ No newline at end of file diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java index 7e53df87c4..98f603d365 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper1Impl.java @@ -9,7 +9,6 @@ import org.mapstruct.ap.test.updatemethods.CompanyDto; import org.mapstruct.ap.test.updatemethods.CompanyEntity; import org.mapstruct.ap.test.updatemethods.DepartmentEntityFactory; -import org.mapstruct.factory.Mappers; @Generated( value = "org.mapstruct.ap.MappingProcessor", @@ -18,7 +17,7 @@ ) public class OrganizationMapper1Impl implements OrganizationMapper1 { - private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class ); + private final ExternalMapper externalMapper = ExternalMapper.INSTANCE; private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); @Override diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java index 11c3bd0df6..76b2d3d9e8 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/OrganizationMapper3Impl.java @@ -9,7 +9,6 @@ import org.mapstruct.ap.test.updatemethods.BossDto; import org.mapstruct.ap.test.updatemethods.BossEntity; import org.mapstruct.ap.test.updatemethods.ConstructableDepartmentEntity; -import org.mapstruct.factory.Mappers; @Generated( value = "org.mapstruct.ap.MappingProcessor", @@ -18,7 +17,7 @@ ) public class OrganizationMapper3Impl implements OrganizationMapper3 { - private final ExternalMapper externalMapper = Mappers.getMapper( ExternalMapper.class ); + private final ExternalMapper externalMapper = ExternalMapper.INSTANCE; @Override public void toBossEntity(BossDto dto, BossEntity entity) { From b643061b57f39dbf75d7142ec7b9144ed184331b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Feb 2021 16:27:24 +0100 Subject: [PATCH 0546/1006] #2277 Add tests with fixtures with testing the generated source code --- .../DefaultComponentModelMapperTest.java | 46 +++++++++++++++++++ .../InstanceIterableMapper.java | 19 ++++++++ .../defaultcomponentmodel/InstanceMapper.java | 20 ++++++++ .../NonInstanceIterableMapper.java | 19 ++++++++ .../NonInstanceMapper.java | 20 ++++++++ .../NonPublicIterableMapper.java | 19 ++++++++ .../NonPublicMapper.java | 20 ++++++++ .../ap/test/defaultcomponentmodel/Source.java | 22 +++++++++ .../ap/test/defaultcomponentmodel/Target.java | 22 +++++++++ .../InstanceIterableMapperImpl.java | 34 ++++++++++++++ .../NonInstanceIterableMapperImpl.java | 35 ++++++++++++++ .../NonPublicIterableMapperImpl.java | 35 ++++++++++++++ 12 files changed, 311 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java new file mode 100644 index 0000000000..b6b19ea88d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2277") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Source.class, + Target.class, +}) +public class DefaultComponentModelMapperTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ + InstanceIterableMapper.class, + InstanceMapper.class, + NonInstanceIterableMapper.class, + NonInstanceMapper.class, + NonPublicIterableMapper.class, + NonPublicMapper.class, + }) + public void shouldGenerateCorrectMapperInstantiation() { + generatedSource.addComparisonToFixtureFor( + InstanceIterableMapper.class, + NonInstanceIterableMapper.class, + NonPublicIterableMapper.class + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java new file mode 100644 index 0000000000..b5b0506b62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.List; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = InstanceMapper.class) +public interface InstanceIterableMapper { + + List map(List list); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java new file mode 100644 index 0000000000..902ed551cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/InstanceMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface InstanceMapper { + + InstanceMapper INSTANCE = Mappers.getMapper( InstanceMapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java new file mode 100644 index 0000000000..6cdbe53006 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.List; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = NonInstanceMapper.class) +public interface NonInstanceIterableMapper { + + List map(List list); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java new file mode 100644 index 0000000000..0d7f68392c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface NonInstanceMapper { + + NonInstanceMapper MAPPER = Mappers.getMapper( NonInstanceMapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java new file mode 100644 index 0000000000..20d6dbc1e7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.List; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = NonPublicMapper.class) +public interface NonPublicIterableMapper { + + List map(List list); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java new file mode 100644 index 0000000000..36f9b978f2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public abstract class NonPublicMapper { + + static final NonPublicMapper INSTANCE = Mappers.getMapper( NonPublicMapper.class ); + + public abstract Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java new file mode 100644 index 0000000000..a6aa152e20 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String id; + + public Source(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java new file mode 100644 index 0000000000..da7bfdbed0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String id; + + public Target(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java new file mode 100644 index 0000000000..7dab330793 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/InstanceIterableMapperImpl.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-02-06T16:20:45+0100", + comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)" +) +public class InstanceIterableMapperImpl implements InstanceIterableMapper { + + private final InstanceMapper instanceMapper = InstanceMapper.INSTANCE; + + @Override + public List map(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList( list.size() ); + for ( Source source : list ) { + list1.add( instanceMapper.map( source ) ); + } + + return list1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java new file mode 100644 index 0000000000..3854376bad --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonInstanceIterableMapperImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.processing.Generated; +import org.mapstruct.factory.Mappers; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-02-06T16:20:45+0100", + comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)" +) +public class NonInstanceIterableMapperImpl implements NonInstanceIterableMapper { + + private final NonInstanceMapper nonInstanceMapper = Mappers.getMapper( NonInstanceMapper.class ); + + @Override + public List map(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList( list.size() ); + for ( Source source : list ) { + list1.add( nonInstanceMapper.map( source ) ); + } + + return list1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java new file mode 100644 index 0000000000..4cca04617a --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/defaultcomponentmodel/NonPublicIterableMapperImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.defaultcomponentmodel; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.processing.Generated; +import org.mapstruct.factory.Mappers; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-02-06T16:20:45+0100", + comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)" +) +public class NonPublicIterableMapperImpl implements NonPublicIterableMapper { + + private final NonPublicMapper nonPublicMapper = Mappers.getMapper( NonPublicMapper.class ); + + @Override + public List map(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList( list.size() ); + for ( Source source : list ) { + list1.add( nonPublicMapper.map( source ) ); + } + + return list1; + } +} From 630a8da904d4669507fdf31f86ef96ac0deb1954 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Feb 2021 16:44:07 +0100 Subject: [PATCH 0547/1006] Fix a typo in the Mapper#componentModel --- core/src/main/java/org/mapstruct/Mapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 5ed9eab17f..92d393f6c8 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -143,7 +143,7 @@ * {@code jsr330}: the generated mapper is annotated with {@code @javax.inject.Named} and * {@code @Singleton}, and can be retrieved via {@code @Inject} * - * The method overrides an unmappedTargetPolicy set in a central configuration set + * The method overrides a componentModel set in a central configuration set * by {@link #config() } * * @return The component model for the generated mapper. From f4b62ded8910c0bc6d09fc677f887c3775ed1827 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 5 Feb 2021 23:01:41 +0100 Subject: [PATCH 0548/1006] #2352 Add source element type for Iterable mappings When the Iterable type we are mapping is not generic (i.e. it is a custom type extending an Iterable) then the source element type which is included in the loop was not imported. --- .../internal/model/IterableMappingMethod.java | 9 ++++ .../ap/test/bugs/_2352/Issue2352Test.java | 49 +++++++++++++++++++ .../ap/test/bugs/_2352/dto/TheDto.java | 22 +++++++++ .../ap/test/bugs/_2352/dto/TheModel.java | 22 +++++++++ .../ap/test/bugs/_2352/dto/TheModels.java | 15 ++++++ .../bugs/_2352/mapper/TheModelMapper.java | 19 +++++++ .../bugs/_2352/mapper/TheModelsMapper.java | 24 +++++++++ 7 files changed, 160 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 5310fa382d..38ec44f1e1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -9,6 +9,7 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import org.mapstruct.ap.internal.model.assignment.LocalVarWrapper; import org.mapstruct.ap.internal.model.assignment.SetterWrapper; @@ -86,6 +87,14 @@ private IterableMappingMethod(Method method, Collection existingVariable ); } + @Override + public Set getImportTypes() { + Set types = super.getImportTypes(); + + types.add( getSourceElementType() ); + return types; + } + public Type getSourceElementType() { Type sourceParameterType = getSourceParameter().getType(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java new file mode 100644 index 0000000000..ebf6ac1e1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.bugs._2352.dto.TheDto; +import org.mapstruct.ap.test.bugs._2352.dto.TheModel; +import org.mapstruct.ap.test.bugs._2352.dto.TheModels; +import org.mapstruct.ap.test.bugs._2352.mapper.TheModelMapper; +import org.mapstruct.ap.test.bugs._2352.mapper.TheModelsMapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2352") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + TheDto.class, + TheModel.class, + TheModels.class, + TheModelMapper.class, + TheModelsMapper.class, +}) +public class Issue2352Test { + + @Test + public void shouldGenerateValidCode() { + TheModels theModels = new TheModels(); + theModels.add( new TheModel( "1" ) ); + theModels.add( new TheModel( "2" ) ); + + List theDtos = TheModelsMapper.INSTANCE.convert( theModels ); + + assertThat( theDtos ) + .extracting( TheDto::getId ) + .containsExactly( "1", "2" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java new file mode 100644 index 0000000000..a07c8bd093 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352.dto; + +/** + * @author Filip Hrisafov + */ +public class TheDto { + + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java new file mode 100644 index 0000000000..fc7b1e89be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModel.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352.dto; + +/** + * @author Filip Hrisafov + */ +public class TheModel { + + private final String id; + + public TheModel(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java new file mode 100644 index 0000000000..37359ce779 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/dto/TheModels.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352.dto; + +import java.util.ArrayList; + +/** + * @author Filip Hrisafov + */ +public class TheModels extends ArrayList { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java new file mode 100644 index 0000000000..2e9b5be478 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2352.dto.TheDto; +import org.mapstruct.ap.test.bugs._2352.dto.TheModel; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface TheModelMapper { + + TheDto convert(TheModel theModel); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java new file mode 100644 index 0000000000..cf6c30409c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/mapper/TheModelsMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2352.mapper; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2352.dto.TheDto; +import org.mapstruct.ap.test.bugs._2352.dto.TheModels; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = TheModelMapper.class) +public interface TheModelsMapper { + + TheModelsMapper INSTANCE = Mappers.getMapper( TheModelsMapper.class ); + + List convert(TheModels theModels); +} From 07f5189a722396c17e1df8a2debbaefb5a337e32 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Feb 2021 10:26:08 +0100 Subject: [PATCH 0549/1006] #2347 Do not generate mapper implementation for private mappers Provide a compiler error message instead of generating code that will not compile --- .../processor/MapperCreationProcessor.java | 12 +++++ .../mapstruct/ap/internal/util/Message.java | 1 + .../ErroneousClassWithPrivateMapper.java | 51 +++++++++++++++++++ .../ap/test/bugs/_2347/Issue2347Test.java | 49 ++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index ad6d84b9e9..c887140723 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -15,6 +15,7 @@ import java.util.SortedSet; import java.util.TreeSet; import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; @@ -210,6 +211,17 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< mappingContext.getForgedMethodsUnderCreation().keySet() ); } + if ( element.getModifiers().contains( Modifier.PRIVATE ) ) { + // If the mapper element is private then we should report an error + // we can't generate an implementation for a private mapper + mappingContext.getMessager() + .printMessage( element, + Message.GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER, + element.getSimpleName().toString(), + element.getKind() == ElementKind.INTERFACE ? "interface" : "class" + ); + } + return mapper; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index d88791fda1..378395d4da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -115,6 +115,7 @@ public enum Message { DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ), DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), + GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER("Cannot create an implementation for mapper %s, because it is a private %s."), GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ), GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java new file mode 100644 index 0000000000..c18620887e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/ErroneousClassWithPrivateMapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2347; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +public class ErroneousClassWithPrivateMapper { + + public static class Target { + private final String id; + + public Target(String id) { + this.id = id; + } + + public String getId() { + return id; + } + } + + public static class Source { + + private final String id; + + public Source(String id) { + this.id = id; + } + + public String getId() { + return id; + } + } + + @Mapper + private interface PrivateInterfaceMapper { + + Target map(Source source); + } + + @Mapper + private abstract class PrivateClassMapper { + + public abstract Target map(Source source); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java new file mode 100644 index 0000000000..f5e04fc776 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2347; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2347") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + ErroneousClassWithPrivateMapper.class +}) +public class Issue2347Test { + + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousClassWithPrivateMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 41, + message = "Cannot create an implementation for mapper PrivateInterfaceMapper," + + " because it is a private interface." + ), + @Diagnostic( + type = ErroneousClassWithPrivateMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 47, + message = "Cannot create an implementation for mapper PrivateClassMapper," + + " because it is a private class." + ) + } + ) + @Test + public void shouldGenerateCompileErrorWhenMapperIsPrivate() { + + } +} From 85af901ea7d7bc6cbdc52952211df76fc290f426 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Feb 2021 09:05:40 +0100 Subject: [PATCH 0550/1006] #2350 Generate core string to enum mapping when AnyRemaining or AnyUnmapped is not used --- .../ap/internal/model/ValueMappingMethod.java | 9 +++------ .../string2enum/StringToEnumMappingTest.java | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index c26dd5df6b..627a4b7288 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -262,8 +262,8 @@ private List stringToEnumMapping(Method method, Type targetType ) List mappings = new ArrayList<>(); List unmappedSourceConstants = new ArrayList<>( targetType.getEnumConstants() ); boolean sourceErrorOccurred = !reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType ); - boolean mandatoryMissing = !reportErrorIfAnyRemainingOrAnyUnMappedMissing( method ); - if ( sourceErrorOccurred || mandatoryMissing ) { + reportWarningIfAnyRemainingOrAnyUnMappedMissing( method ); + if ( sourceErrorOccurred ) { return mappings; } Set mappedSources = new LinkedHashSet<>(); @@ -344,17 +344,14 @@ private boolean reportErrorIfSourceEnumConstantsContainsAnyRemaining(Method meth return !foundIncorrectMapping; } - private boolean reportErrorIfAnyRemainingOrAnyUnMappedMissing(Method method) { - boolean foundIncorrectMapping = false; + private void reportWarningIfAnyRemainingOrAnyUnMappedMissing(Method method) { if ( !( valueMappings.hasMapAnyUnmapped || valueMappings.hasMapAnyRemaining ) ) { ctx.getMessager().printMessage( method.getExecutable(), Message.VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING ); - foundIncorrectMapping = true; } - return !foundIncorrectMapping; } private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, Type targetType) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java index 7bf06ab860..fea8efac12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java @@ -16,6 +16,7 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; @IssueKey( "1557" ) @WithClasses({ OrderType.class, OrderMapper.class }) @@ -53,7 +54,20 @@ public void testRemainingAndNull() { "type String to an enum type." ) } ) - public void shouldRaiseErrorWhenUsingAnyRemaining() { + public void shouldRaiseWarningWhenNotUsingAnyRemainingOrAnyUnmapped() { + + assertThatThrownBy( () -> ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "unknown" ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Unexpected enum constant: unknown" ); + + assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( null ) ) + .isEqualTo( OrderType.STANDARD ); + + assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "STANDARD" ) ) + .isNull(); + + assertThat( ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.INSTANCE.map( "RETAIL" ) ) + .isEqualTo( OrderType.RETAIL ); } } From d5703d3ee8ecb8bd12ce80c6cd7a477119b2bfb8 Mon Sep 17 00:00:00 2001 From: Jeroen van Wilgenburg Date: Mon, 1 Mar 2021 07:27:47 +0100 Subject: [PATCH 0551/1006] #2368 fix order of target parameter in documentation --- core/src/main/java/org/mapstruct/Mapper.java | 2 +- core/src/main/java/org/mapstruct/Mappings.java | 8 ++++---- .../main/java/org/mapstruct/ValueMapping.java | 6 +++--- .../main/java/org/mapstruct/ValueMappings.java | 8 ++++---- ...er-11-reusing-mapping-configurations.asciidoc | 2 +- .../chapter-3-defining-a-mapper.asciidoc | 16 ++++++++-------- .../asciidoc/chapter-8-mapping-values.asciidoc | 6 +++--- .../model/beanmapping/SourceReference.java | 2 +- .../model/beanmapping/TargetReference.java | 2 +- readme.md | 2 +- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 92d393f6c8..98022f1a6c 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -47,7 +47,7 @@ * uses = MarkMapper.class, * injectionStrategy = InjectionStrategy.CONSTRUCTOR) * public interface CarMapper { - * @Mapping(source = "mark", target = "name") + * @Mapping(target = "name", source = "mark") * CarDto convertMap(CarEntity carEntity); * } *
    diff --git a/core/src/main/java/org/mapstruct/Mappings.java b/core/src/main/java/org/mapstruct/Mappings.java index 039ec7b3c7..1578a648a9 100644 --- a/core/src/main/java/org/mapstruct/Mappings.java +++ b/core/src/main/java/org/mapstruct/Mappings.java @@ -23,8 +23,8 @@ * @Mapper * public interface MyMapper { * @Mappings({ - * @Mapping(source = "first", target = "firstProperty"), - * @Mapping(source = "second", target = "secondProperty") + * @Mapping(target = "firstProperty", source = "first"), + * @Mapping(target = "secondProperty", source = "second") * }) * HumanDto toHumanDto(Human human); * } @@ -33,8 +33,8 @@ * // Java 8 and later * @Mapper * public interface MyMapper { - * @Mapping(source = "first", target = "firstProperty"), - * @Mapping(source = "second", target = "secondProperty") + * @Mapping(target = "firstProperty", source = "first"), + * @Mapping(target = "secondProperty", source = "second") * HumanDto toHumanDto(Human human); * } * diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index 26ed661dce..f8f2d3b18e 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -27,9 +27,9 @@ * * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT } * - * @ValueMapping(source = "EXTRA", target = "SPECIAL"), - * @ValueMapping(source = "STANDARD", target = "DEFAULT"), - * @ValueMapping(source = "NORMAL", target = "DEFAULT") + * @ValueMapping(target = "SPECIAL", source = "EXTRA"), + * @ValueMapping(target = "DEFAULT", source = "STANDARD"), + * @ValueMapping(target = "DEFAULT", source = "NORMAL") * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); * * Mapping result: diff --git a/core/src/main/java/org/mapstruct/ValueMappings.java b/core/src/main/java/org/mapstruct/ValueMappings.java index a1b4666178..faefbf7105 100644 --- a/core/src/main/java/org/mapstruct/ValueMappings.java +++ b/core/src/main/java/org/mapstruct/ValueMappings.java @@ -22,8 +22,8 @@ * @Mapper * public interface GenderMapper { * @ValueMappings({ - * @ValueMapping(source = "MALE", target = "M"), - * @ValueMapping(source = "FEMALE", target = "F") + * @ValueMapping(target = "M", source = "MALE"), + * @ValueMapping(target = "F", source = "FEMALE") * }) * GenderDto mapToDto(Gender gender); * } @@ -32,8 +32,8 @@ * //Java 8 and later * @Mapper * public interface GenderMapper { - * @ValueMapping(source = "MALE", target = "M"), - * @ValueMapping(source = "FEMALE", target = "F") + * @ValueMapping(target = "M", source = "MALE"), + * @ValueMapping(target = "F", source = "FEMALE") * GenderDto mapToDto(Gender gender); * } * diff --git a/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc index 104b0a9b2f..fb8c71a622 100644 --- a/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc +++ b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc @@ -54,7 +54,7 @@ Use the annotation `@InheritInverseConfiguration` to indicate that a method shal @Mapper public interface CarMapper { - @Mapping(source = "numberOfSeats", target = "seatCount") + @Mapping(target = "seatCount", source = "numberOfSeats") CarDto carToDto(Car car); @InheritInverseConfiguration diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index be3435b541..f679d4494a 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -16,11 +16,11 @@ To create a mapper simply define a Java interface with the required mapping meth @Mapper public interface CarMapper { - @Mapping(source = "make", target = "manufacturer") - @Mapping(source = "numberOfSeats", target = "seatCount") + @Mapping(target = "manufacturer", source = "make") + @Mapping(target = "seatCount", source = "numberOfSeats") CarDto carToCarDto(Car car); - @Mapping(source = "name", target = "fullName") + @Mapping(target = "fullName", source = "name") PersonDto personToPersonDto(Person person); } ---- @@ -236,8 +236,8 @@ MapStruct also supports mapping methods with several source parameters. This is @Mapper public interface AddressMapper { - @Mapping(source = "person.description", target = "description") - @Mapping(source = "address.houseNo", target = "houseNumber") + @Mapping(target = "description", source = "person.description") + @Mapping(target = "houseNumber", source = "address.houseNo") DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Address address); } ---- @@ -267,8 +267,8 @@ MapStruct also offers the possibility to directly refer to a source parameter. @Mapper public interface AddressMapper { - @Mapping(source = "person.description", target = "description") - @Mapping(source = "hn", target = "houseNumber") + @Mapping(target = "description", source = "person.description") + @Mapping(target = "houseNumber", source = "hn") DeliveryAddressDto personAndAddressToDeliveryAddressDto(Person person, Integer hn); } ---- @@ -368,7 +368,7 @@ public interface CustomerMapper { CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); - @Mapping(source = "customerName", target = "name") + @Mapping(target = "name", source = "customerName") Customer toCustomer(CustomerDto customerDto); @InheritInverseConfiguration diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index e38cee215b..57b9433a20 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -20,9 +20,9 @@ public interface OrderMapper { OrderMapper INSTANCE = Mappers.getMapper( OrderMapper.class ); @ValueMappings({ - @ValueMapping(source = "EXTRA", target = "SPECIAL"), - @ValueMapping(source = "STANDARD", target = "DEFAULT"), - @ValueMapping(source = "NORMAL", target = "DEFAULT") + @ValueMapping(target = "SPECIAL", source = "EXTRA"), + @ValueMapping(target = "DEFAULT", source = "STANDARD"), + @ValueMapping(target = "DEFAULT", source = "NORMAL") }) ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 1d747c190e..d43a242278 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -34,7 +34,7 @@ * mapping method: * *
    - * @Mapping(source = "in.propA.propB" target = "propC")
    + * @Mapping(target = "propC", source = "in.propA.propB")
      * TypeB mappingMethod(TypeA in);
      * 
    * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index fee97f840d..22bfd6343b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -32,7 +32,7 @@ * method: * *
    - * @Mapping(source = "in.propA.propB" target = "propC")
    + * @Mapping(target = "propC", source = "in.propA.propB")
      * TypeB mappingMethod(TypeA in);
      * 
    * diff --git a/readme.md b/readme.md index 5fc8399748..645f3ee992 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,7 @@ public interface CarMapper { CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); - @Mapping(source = "numberOfSeats", target = "seatCount") + @Mapping(target = "seatCount", source = "numberOfSeats") CarDto carToCarDto(Car car); } ``` From d9fdd86b94585ba59e918924ecbbcd33e4048573 Mon Sep 17 00:00:00 2001 From: Jeroen van Wilgenburg Date: Mon, 1 Mar 2021 08:10:31 +0100 Subject: [PATCH 0552/1006] #2368 fix order of target parameter in tests (and removed some spaces) --- .../itest/gradle/lib/TestMapper.java | 2 +- .../ap/test/bugs/_636/SourceTargetMapper.java | 4 +-- .../mapstruct/itest/java8/Java8Mapper.java | 4 +-- .../simple/SourceTargetAbstractMapper.java | 6 ++-- .../itest/simple/SourceTargetMapper.java | 6 ++-- .../AbstractSourceTargetMapperPrivate.java | 2 +- .../AbstractSourceTargetMapperProtected.java | 2 +- .../SourceTargetMapperDefaultOther.java | 2 +- .../SourceTargetMapperDefaultSame.java | 2 +- .../referenced/SourceTargetMapperPrivate.java | 2 +- .../SourceTargetMapperProtected.java | 2 +- .../ap/test/bugs/_1124/Issue1124Mapper.java | 2 +- .../ap/test/bugs/_1148/Issue1148Mapper.java | 32 +++++++++---------- .../ap/test/bugs/_1155/Issue1155Mapper.java | 2 +- .../mapstruct/ap/test/bugs/_1650/AMapper.java | 4 +-- .../ap/test/bugs/_1685/UserMapper.java | 10 +++--- .../ap/test/bugs/_1714/Issue1714Mapper.java | 2 +- .../ap/test/bugs/_1881/VehicleDtoMapper.java | 6 ++-- .../SameNameForSourceAndTargetCarsMapper.java | 2 +- .../ap/test/bugs/_405/PersonMapper.java | 2 +- .../ap/test/bugs/_846/Mapper846.java | 2 +- .../ap/test/bugs/_849/Issue849Mapper.java | 2 +- .../ap/test/bugs/_891/BuggyMapper.java | 2 +- .../test/collection/SourceTargetMapper.java | 14 ++++---- .../collection/adder/SourceTargetMapper.java | 2 +- .../SourceTargetMapper.java | 2 +- .../mapstruct/ap/test/complex/CarMapper.java | 4 +-- .../test/conversion/SourceTargetMapper.java | 4 +-- .../SourceTargetMapper.java | 4 +-- .../attributereference/ErroneousMapper1.java | 2 +- .../ap/test/fields/SourceTargetMapper.java | 2 +- ...rJsr330CompileOptionConstructorMapper.java | 2 +- .../CustomerJsr330ConstructorMapper.java | 2 +- ...rSpringCompileOptionConstructorMapper.java | 2 +- .../CustomerSpringConstructorMapper.java | 2 +- .../test/java8stream/SourceTargetMapper.java | 14 ++++---- .../test/java8stream/base/StreamMapper.java | 4 +-- .../SourceTargetMapper.java | 2 +- .../erroneous/PersonAgeMapper.java | 2 +- .../PersonGarageWrongTargetMapper.java | 4 +-- .../erroneous/PersonNameMapper.java | 2 +- .../SourceTypeTargetDtoMapper.java | 2 +- .../exceptions/ResourceMapper.java | 2 +- .../CustomerDefaultMapper.java | 4 +-- .../CustomerMapper.java | 4 +-- ...ustomerNvpmsOnBeanMappingMethodMapper.java | 2 +- .../CustomerNvpmsOnConfigMapper.java | 2 +- .../CustomerNvpmsOnMapperMapper.java | 2 +- .../CustomerNvpmsPropertyMappingMapper.java | 2 +- .../ErroneousCustomerMapper1.java | 2 +- .../ErroneousCustomerMapper2.java | 2 +- .../ErroneousCustomerMapper3.java | 2 +- .../ErroneousCustomerMapper4.java | 2 +- .../ErroneousCustomerMapper5.java | 2 +- .../ap/test/oneway/SourceTargetMapper.java | 2 +- .../ap/test/reverse/SourceTargetMapper.java | 12 +++---- .../SourceTargetMapperAmbiguous1.java | 12 +++---- .../SourceTargetMapperAmbiguous2.java | 12 +++---- .../SourceTargetMapperAmbiguous3.java | 12 +++---- .../SourceTargetMapperNonMatchingName.java | 6 ++-- .../source/constants/ErroneousMapper1.java | 2 +- .../source/constants/ErroneousMapper4.java | 2 +- .../SourceTargetMapperSeveralSources.java | 4 +-- .../SourceTargetMapperSeveralSources.java | 4 +-- .../SourceTargetConfig.java | 4 +-- .../SourceTargetMapper.java | 10 +++--- .../SourceTargetMapper.java | 8 ++--- .../ErroneousOrganizationMapper1.java | 6 ++-- .../ErroneousOrganizationMapper2.java | 2 +- .../updatemethods/OrganizationMapper.java | 8 ++--- 70 files changed, 154 insertions(+), 154 deletions(-) diff --git a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/src/main/java/org/mapstruct/itest/gradle/lib/TestMapper.java b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/src/main/java/org/mapstruct/itest/gradle/lib/TestMapper.java index 13ae2ef5fc..6137ff0eca 100644 --- a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/src/main/java/org/mapstruct/itest/gradle/lib/TestMapper.java +++ b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/src/main/java/org/mapstruct/itest/gradle/lib/TestMapper.java @@ -14,6 +14,6 @@ @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface TestMapper { - @Mapping(source = "value", target = "field") + @Mapping(target = "field", source = "value") public Target toTarget(Source source); } diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java index b619771fd3..85102e1918 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/ap/test/bugs/_636/SourceTargetMapper.java @@ -15,8 +15,8 @@ public interface SourceTargetMapper extends SourceTargetBaseMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "idFoo", target = "foo"), - @Mapping(source = "idBar", target = "bar") + @Mapping(target = "foo", source = "idFoo"), + @Mapping(target = "bar", source = "idBar") }) Target mapSourceToTarget(Source source); } diff --git a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java index 4acd23d08e..f16228b60e 100644 --- a/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java +++ b/integrationtest/src/test/resources/java8Test/src/main/java/org/mapstruct/itest/java8/Java8Mapper.java @@ -14,7 +14,7 @@ public interface Java8Mapper { Java8Mapper INSTANCE = Mappers.getMapper( Java8Mapper.class ); - @Mapping(source = "firstName", target = "givenName") - @Mapping(source = "lastName", target = "surname") + @Mapping(target = "givenName", source = "firstName") + @Mapping(target = "surname", source = "lastName") Target sourceToTarget(Source source); } diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java index c5a222a6ca..dd893384f7 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetAbstractMapper.java @@ -16,9 +16,9 @@ public abstract class SourceTargetAbstractMapper { public static SourceTargetAbstractMapper INSTANCE = Mappers.getMapper( SourceTargetAbstractMapper.class ); @Mappings({ - @Mapping(source = "qax", target = "baz"), - @Mapping(source = "baz", target = "qax"), - @Mapping(source = "forNested.value", target = "fromNested") + @Mapping(target = "baz", source = "qax"), + @Mapping(target = "qax", source = "baz"), + @Mapping(target = "fromNested", source = "forNested.value") }) public abstract Target sourceToTarget(Source source); diff --git a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java index 3de0b84722..b3fd443c6b 100644 --- a/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java +++ b/integrationtest/src/test/resources/simpleTest/src/main/java/org/mapstruct/itest/simple/SourceTargetMapper.java @@ -17,9 +17,9 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "qax", target = "baz"), - @Mapping(source = "baz", target = "qax"), - @Mapping(source = "forNested.value", target = "fromNested") + @Mapping(target = "baz", source = "qax"), + @Mapping(target = "qax", source = "baz"), + @Mapping(target = "fromNested", source = "forNested.value") }) Target sourceToTarget(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java index fa612bd956..507e63a957 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java @@ -19,6 +19,6 @@ public abstract class AbstractSourceTargetMapperPrivate extends SourceTargetmapp public static final AbstractSourceTargetMapperPrivate INSTANCE = Mappers.getMapper( AbstractSourceTargetMapperPrivate.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") public abstract Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java index 2ae40488f2..ef5df10285 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java @@ -19,6 +19,6 @@ public abstract class AbstractSourceTargetMapperProtected extends SourceTargetma public static final AbstractSourceTargetMapperProtected INSTANCE = Mappers.getMapper( AbstractSourceTargetMapperProtected.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") public abstract Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java index 4ada977bc8..682a258e3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultOther.java @@ -20,6 +20,6 @@ public interface SourceTargetMapperDefaultOther { SourceTargetMapperDefaultOther INSTANCE = Mappers.getMapper( SourceTargetMapperDefaultOther.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java index 36127e1af6..536f45d5be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperDefaultSame.java @@ -18,6 +18,6 @@ public interface SourceTargetMapperDefaultSame { SourceTargetMapperDefaultSame INSTANCE = Mappers.getMapper( SourceTargetMapperDefaultSame.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java index 1ec1aa6c5b..4615ff3e6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivate.java @@ -18,6 +18,6 @@ public interface SourceTargetMapperPrivate { SourceTargetMapperPrivate INSTANCE = Mappers.getMapper( SourceTargetMapperPrivate.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java index f8ac1b4d28..c18c6127e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtected.java @@ -18,6 +18,6 @@ public interface SourceTargetMapperProtected { SourceTargetMapperProtected INSTANCE = Mappers.getMapper( SourceTargetMapperProtected.class ); - @Mapping(source = "referencedSource", target = "referencedTarget") + @Mapping(target = "referencedTarget", source = "referencedSource") Target toTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java index fce8ffcd6d..cae987aabe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Mapper.java @@ -59,6 +59,6 @@ public void setEntity(DTO entity) { class MappingContext { } - @Mapping(source = "entity.id", target = "id") + @Mapping(target = "id", source = "entity.id") DTO map(Entity entity, @Context MappingContext context); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java index fa997becf0..cf2cfdfaf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Mapper.java @@ -19,26 +19,26 @@ public interface Issue1148Mapper { Issue1148Mapper INSTANCE = Mappers.getMapper( Issue1148Mapper.class ); @Mappings({ - @Mapping(source = "senderId", target = "sender.nestedClient.id"), - @Mapping(source = "recipientId", target = "recipient.nestedClient.id"), - @Mapping(source = "sameLevel.client.id", target = "client.nestedClient.id"), - @Mapping(source = "sameLevel2.client.id", target = "client2.nestedClient.id"), - @Mapping(source = "level.client.id", target = "nested.id"), - @Mapping(source = "level2.client.id", target = "nested2.id"), - @Mapping(source = "nestedDto.id", target = "id"), - @Mapping(source = "nestedDto2.id", target = "id2") + @Mapping(target = "sender.nestedClient.id", source = "senderId"), + @Mapping(target = "recipient.nestedClient.id", source = "recipientId"), + @Mapping(target = "client.nestedClient.id", source = "sameLevel.client.id"), + @Mapping(target = "client2.nestedClient.id", source = "sameLevel2.client.id"), + @Mapping(target = "nested.id", source = "level.client.id"), + @Mapping(target = "nested2.id", source = "level2.client.id"), + @Mapping(target = "id", source = "nestedDto.id"), + @Mapping(target = "id2", source = "nestedDto2.id") }) Entity toEntity(Entity.Dto dto); @Mappings({ - @Mapping(source = "dto2.senderId", target = "sender.nestedClient.id"), - @Mapping(source = "dto1.recipientId", target = "recipient.nestedClient.id"), - @Mapping(source = "dto1.sameLevel.client.id", target = "client.nestedClient.id"), - @Mapping(source = "dto2.sameLevel2.client.id", target = "client2.nestedClient.id"), - @Mapping(source = "dto1.level.client.id", target = "nested.id"), - @Mapping(source = "dto2.level2.client.id", target = "nested2.id"), - @Mapping(source = "dto1.nestedDto.id", target = "id"), - @Mapping(source = "dto2.nestedDto2.id", target = "id2") + @Mapping(target = "sender.nestedClient.id", source = "dto2.senderId"), + @Mapping(target = "recipient.nestedClient.id", source = "dto1.recipientId"), + @Mapping(target = "client.nestedClient.id", source = "dto1.sameLevel.client.id"), + @Mapping(target = "client2.nestedClient.id", source = "dto2.sameLevel2.client.id"), + @Mapping(target = "nested.id", source = "dto1.level.client.id"), + @Mapping(target = "nested2.id", source = "dto2.level2.client.id"), + @Mapping(target = "id", source = "dto1.nestedDto.id"), + @Mapping(target = "id2", source = "dto2.nestedDto2.id") }) Entity toEntity(Entity.Dto dto1, Entity.Dto dto2); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java index cb2fd3453c..072121bf79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Mapper.java @@ -17,6 +17,6 @@ public interface Issue1155Mapper { Issue1155Mapper INSTANCE = Mappers.getMapper( Issue1155Mapper.class ); - @Mapping(source = "clientId", target = "client.id") + @Mapping(target = "client.id", source = "clientId") Entity toEntity(Entity.Dto dto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java index 860c3b21e3..ba6eeda861 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/AMapper.java @@ -15,12 +15,12 @@ public interface AMapper { AMapper INSTANCE = Mappers.getMapper( AMapper.class ); - @Mapping(source = "b.c", target = "cPrime") + @Mapping(target = "cPrime", source = "b.c") APrime toAPrime(A a, @MappingTarget APrime mappingTarget); CPrime toCPrime(C c, @MappingTarget CPrime mappingTarget); - @Mapping(source = "b.c", target = "cPrime") + @Mapping(target = "cPrime", source = "b.c") APrime toAPrime(A a); CPrime toCPrime(C c); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java index 38800dc757..4c838a3d55 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/UserMapper.java @@ -21,11 +21,11 @@ public interface UserMapper { UserMapper INSTANCE = Mappers.getMapper( UserMapper.class ); @Mappings({ - @Mapping(source = "email", target = "contactDataDTO.email"), - @Mapping(source = "phone", target = "contactDataDTO.phone"), - @Mapping(source = "address", target = "contactDataDTO.address"), - @Mapping(source = "preferences", target = "contactDataDTO.preferences"), - @Mapping(source = "settings", target = "contactDataDTO.settings") + @Mapping(target = "contactDataDTO.email", source = "email" ), + @Mapping(target = "contactDataDTO.phone", source = "phone"), + @Mapping(target = "contactDataDTO.address", source = "address"), + @Mapping(target = "contactDataDTO.preferences", source = "preferences"), + @Mapping(target = "contactDataDTO.settings", source = "settings") }) UserDTO userToUserDTO(User user); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java index 0273457e8a..3985606d94 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Mapper.java @@ -15,7 +15,7 @@ public interface Issue1714Mapper { Issue1714Mapper INSTANCE = Mappers.getMapper( Issue1714Mapper.class ); - @Mapping(source = "programInstance", target = "seasonNumber", qualifiedByName = "getSeasonNumber") + @Mapping(target = "seasonNumber", source = "programInstance", qualifiedByName = "getSeasonNumber") OfferEntity map(OnDemand offerStatusDTO); @Named("getTitle") diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/VehicleDtoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/VehicleDtoMapper.java index 34d9f77a75..79ccf8f3a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/VehicleDtoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/VehicleDtoMapper.java @@ -15,9 +15,9 @@ public interface VehicleDtoMapper { VehicleDtoMapper INSTANCE = Mappers.getMapper( VehicleDtoMapper.class ); - @Mapping(source = "name", target = "name") - @Mapping(source = "size", target = "vehicleProperties.size") - @Mapping(source = "type", target = "vehicleProperties.type") + @Mapping(target = "name", source = "name") + @Mapping(target = "vehicleProperties.size", source = "size") + @Mapping(target = "vehicleProperties.type", source = "type") VehicleDto map(Vehicle vehicle); class VehicleDto { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java index 8cca546200..1d43087a51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameNameForSourceAndTargetCarsMapper.java @@ -21,7 +21,7 @@ public interface SameNameForSourceAndTargetCarsMapper { SameNameForSourceAndTargetCarsMapper INSTANCE = Mappers.getMapper( SameNameForSourceAndTargetCarsMapper.class ); @Mappings({ - @Mapping(source = "numberOfSeats", target = "seatCount") + @Mapping(target = "seatCount", source = "numberOfSeats") }) AnotherCar sourceCarToTargetCar(org.mapstruct.ap.test.bugs._394.source.AnotherCar car); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java index b9e15b1da9..4be1356aed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/PersonMapper.java @@ -19,7 +19,7 @@ public abstract class PersonMapper { public static final PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); @Mappings( { - @Mapping( source = "id", target = "name" ) } + @Mapping(target = "name", source = "id") } ) abstract People personToPeople(Person person); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java index f52f226ef1..5ce79afa03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/Mapper846.java @@ -56,7 +56,7 @@ public void setaName(String name) { @Mapper interface MyMapper { - @Mapping(source = "name", target = "aName") + @Mapping(target = "aName", source = "name") A convert(BInterface b); @InheritInverseConfiguration diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java index a54a3cb3bc..2891971dfd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Mapper.java @@ -18,7 +18,7 @@ public interface Issue849Mapper { Issue849Mapper INSTANCE = Mappers.getMapper( Issue849Mapper.class ); - @Mapping(source = "sourceList", target = "targetList") + @Mapping(target = "targetList", source = "sourceList") Target mapSourceToTarget(Source source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java index ebc654bf16..fbb9fcd6c9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/BuggyMapper.java @@ -18,6 +18,6 @@ public interface BuggyMapper { BuggyMapper INSTANCE = Mappers.getMapper( BuggyMapper.class ); - @Mapping(source = "nested.propInt", target = "propLong") + @Mapping(target = "propLong", source = "nested.propInt") Dest convert(Src src); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java index d716918d78..1a07dd1f78 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java @@ -21,13 +21,13 @@ public abstract class SourceTargetMapper { static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "integerList", target = "integerCollection"), - @Mapping(source = "integerSet", target = "set"), - @Mapping(source = "anotherIntegerSet", target = "anotherStringSet"), - @Mapping(source = "stringList2", target = "stringListNoSetter"), - @Mapping(source = "stringSet2", target = "stringListNoSetter2"), - @Mapping(source = "stringList3", target = "nonGenericStringList"), - @Mapping(source = "stringLongMapForNonGeneric", target = "nonGenericMapStringtoLong") + @Mapping(target = "integerCollection", source = "integerList"), + @Mapping(target = "set", source = "integerSet"), + @Mapping(target = "anotherStringSet", source = "anotherIntegerSet"), + @Mapping(target = "stringListNoSetter", source = "stringList2"), + @Mapping(target = "stringListNoSetter2", source = "stringSet2"), + @Mapping(target = "nonGenericStringList", source = "stringList3"), + @Mapping(target = "nonGenericMapStringtoLong", source = "stringLongMapForNonGeneric") }) public abstract Target sourceToTarget(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java index 5e3017c19a..18b542e99d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/SourceTargetMapper.java @@ -42,6 +42,6 @@ public interface SourceTargetMapper { TargetViaTargetType toTargetViaTargetType(Source source); - @Mapping(source = "pet", target = "pets") + @Mapping(target = "pets", source = "pet") Target fromSingleElementSource(SingleElementSource source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java index 1143a311ad..2f0d8085e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapper.java @@ -26,7 +26,7 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping(source = "fooList", target = "fooListNoSetter") + @Mapping(target = "fooListNoSetter", source = "fooList") Target sourceToTarget(Source source); TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo); diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java index 20309ccae4..b635f6b023 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapper.java @@ -24,8 +24,8 @@ public interface CarMapper { CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); @Mappings({ - @Mapping(source = "numberOfSeats", target = "seatCount"), - @Mapping(source = "manufacturingDate", target = "manufacturingYear") + @Mapping(target = "seatCount", source = "numberOfSeats"), + @Mapping(target = "manufacturingYear", source = "manufacturingDate") }) CarDto carToCarDto(Car car); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java index ae5a4e9ce0..0bd3888809 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/SourceTargetMapper.java @@ -17,8 +17,8 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "qax", target = "baz"), - @Mapping(source = "baz", target = "qax") + @Mapping(target = "baz", source = "qax"), + @Mapping(target = "qax", source = "baz") }) Target sourceToTarget(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java index cc456aa0a0..ed4c1d374d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/localdatetimetoxmlgregoriancalendarconversion/SourceTargetMapper.java @@ -17,9 +17,9 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping(source = "xmlGregorianCalendar", target = "localDateTime") + @Mapping(target = "localDateTime", source = "xmlGregorianCalendar") Target toTarget(Source source); - @Mapping(source = "localDateTime", target = "xmlGregorianCalendar") + @Mapping(target = "xmlGregorianCalendar", source = "localDateTime") Source toSource(Target target); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java index ce9134cc9a..502ac44b1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMapper1.java @@ -13,7 +13,7 @@ public interface ErroneousMapper1 { @Mappings({ - @Mapping(source = "source.foobar", target = "foo") + @Mapping(target = "foo", source = "source.foobar") }) Target sourceToTarget(Source source, DummySource source1); diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java index a872c25feb..99b7b50aa4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java @@ -18,7 +18,7 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping(source = "fieldOnlyWithGetter", target = "fieldWithMethods") + @Mapping(target = "fieldWithMethods", source = "fieldOnlyWithGetter") Target toSource(Source source); @InheritInverseConfiguration diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java index 143c452886..02aeaef088 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/CustomerJsr330CompileOptionConstructorMapper.java @@ -18,7 +18,7 @@ uses = GenderJsr330CompileOptionConstructorMapper.class ) public interface CustomerJsr330CompileOptionConstructorMapper { - @Mapping(source = "gender", target = "gender") + @Mapping(target = "gender", source = "gender") CustomerDto asTarget(CustomerEntity customerEntity); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java index 638e71a3aa..32ef9d308b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/CustomerJsr330ConstructorMapper.java @@ -20,7 +20,7 @@ injectionStrategy = InjectionStrategy.CONSTRUCTOR ) public interface CustomerJsr330ConstructorMapper { - @Mapping(source = "gender", target = "gender") + @Mapping(target = "gender", source = "gender") CustomerDto asTarget(CustomerEntity customerEntity); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java index 47060104f7..3d28e3e49e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/CustomerSpringCompileOptionConstructorMapper.java @@ -18,6 +18,6 @@ uses = GenderSpringCompileOptionConstructorMapper.class) public interface CustomerSpringCompileOptionConstructorMapper { - @Mapping( source = "gender", target = "gender" ) + @Mapping(target = "gender", source = "gender") CustomerDto asTarget(CustomerEntity customerEntity); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java index 4ea869ec5f..ef7120585d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/CustomerSpringConstructorMapper.java @@ -20,6 +20,6 @@ injectionStrategy = InjectionStrategy.CONSTRUCTOR ) public interface CustomerSpringConstructorMapper { - @Mapping( source = "gender", target = "gender" ) + @Mapping(target = "gender", source = "gender") CustomerDto asTarget(CustomerEntity customerEntity); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java index 8dc5c93484..86d83844e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/SourceTargetMapper.java @@ -22,13 +22,13 @@ public abstract class SourceTargetMapper { static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "stringStream", target = "stringList"), - @Mapping(source = "stringArrayStream", target = "stringArrayList"), - @Mapping(source = "stringStreamToSet", target = "stringSet"), - @Mapping(source = "integerStream", target = "integerCollection"), - @Mapping(source = "anotherIntegerStream", target = "anotherStringSet"), - @Mapping(source = "stringStream2", target = "stringListNoSetter"), - @Mapping(source = "stringStream3", target = "nonGenericStringList") + @Mapping(target = "stringList", source = "stringStream"), + @Mapping(target = "stringArrayList", source = "stringArrayStream"), + @Mapping(target = "stringSet", source = "stringStreamToSet"), + @Mapping(target = "integerCollection", source = "integerStream"), + @Mapping(target = "anotherStringSet", source = "anotherIntegerStream"), + @Mapping(target = "stringListNoSetter", source = "stringStream2"), + @Mapping(target = "nonGenericStringList", source = "stringStream3") }) public abstract Target sourceToTarget(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java index edd6b87d19..71a582845c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamMapper.java @@ -21,8 +21,8 @@ public interface StreamMapper { StreamMapper INSTANCE = Mappers.getMapper( StreamMapper.class ); @Mappings( { - @Mapping( source = "stream", target = "targetStream"), - @Mapping( source = "sourceElements", target = "targetElements") + @Mapping(target = "targetStream", source = "stream"), + @Mapping(target = "targetElements", source = "sourceElements") } ) Target map(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java index 77d24916f5..b027dc9a0e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/SourceTargetMapper.java @@ -22,7 +22,7 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping(source = "fooStream", target = "fooListNoSetter") + @Mapping(target = "fooListNoSetter", source = "fooStream") Target sourceToTarget(Source source); TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo); diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java index 70c1b13c83..9cf3de5e74 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonAgeMapper.java @@ -16,7 +16,7 @@ public interface PersonAgeMapper { PersonAgeMapper MAPPER = Mappers.getMapper( PersonAgeMapper.class ); - @Mapping(source = "agee", target = "fullAge") + @Mapping(target = "fullAge", source = "agee") Person mapPerson(PersonDto dto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java index 8a7805237a..fc587e0b71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonGarageWrongTargetMapper.java @@ -16,9 +16,9 @@ public interface PersonGarageWrongTargetMapper { PersonGarageWrongTargetMapper MAPPER = Mappers.getMapper( PersonGarageWrongTargetMapper.class ); - @Mapping(source = "garage.color.rgb", target = "garage.colour.rgb") + @Mapping(target = "garage.colour.rgb", source = "garage.color.rgb") Person mapPerson(PersonDto dto); - @Mapping(source = "garage.color", target = "garage.colour") + @Mapping(target = "garage.colour", source = "garage.color") Person mapPersonGarage(PersonDto dto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java index 11bd389a5f..b14a0d0cf9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/erroneous/PersonNameMapper.java @@ -16,7 +16,7 @@ public interface PersonNameMapper { PersonNameMapper MAPPER = Mappers.getMapper( PersonNameMapper.class ); - @Mapping(source = "name", target = "fulName") + @Mapping(target = "fulName", source = "name") Person mapPerson(PersonDto dto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java index 87371f004f..895d3dc922 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/SourceTypeTargetDtoMapper.java @@ -17,7 +17,7 @@ public interface SourceTypeTargetDtoMapper { SourceTypeTargetDtoMapper INSTANCE = Mappers.getMapper( SourceTypeTargetDtoMapper.class ); - @Mapping(source = "date", target = "date", dateFormat = "dd.MM.yyyy") + @Mapping(target = "date", source = "date", dateFormat = "dd.MM.yyyy") TargetDto sourceToTarget(SourceType source); SourceType targetToSource( TargetDto source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java index b1dcd8cd04..712d160908 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/ResourceMapper.java @@ -15,7 +15,7 @@ @Mapper public interface ResourceMapper { - @Mapping(source = "bucket.user.uuid", target = "userId") + @Mapping(target = "userId", source = "bucket.user.uuid") ResourceDto map(Resource r) throws NoSuchUser; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java index 362a129991..1f95649dd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerDefaultMapper.java @@ -16,10 +16,10 @@ public interface CustomerDefaultMapper { CustomerDefaultMapper INSTANCE = Mappers.getMapper( CustomerDefaultMapper.class ); - @Mapping(source = "address", target = "homeDTO.addressDTO") + @Mapping(target = "homeDTO.addressDTO", source = "address") void mapCustomer(Customer customer, @MappingTarget UserDTO userDTO); - @Mapping(source = "houseNumber", target = "houseNo", defaultValue = "0") + @Mapping(target = "houseNo", defaultValue = "0", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java index 56b930c51a..339f70516b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerMapper.java @@ -16,10 +16,10 @@ public interface CustomerMapper { CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); - @Mapping(source = "address", target = "homeDTO.addressDTO") + @Mapping(target = "homeDTO.addressDTO", source = "address") void mapCustomer(Customer customer, @MappingTarget UserDTO userDTO); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java index 7801084639..85a685b943 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnBeanMappingMethodMapper.java @@ -21,7 +21,7 @@ public interface CustomerNvpmsOnBeanMappingMethodMapper { void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java index 941b7d2b43..7693c2c969 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnConfigMapper.java @@ -17,7 +17,7 @@ public interface CustomerNvpmsOnConfigMapper { void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java index 592a687c6e..1b65c6d5fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsOnMapperMapper.java @@ -18,7 +18,7 @@ public interface CustomerNvpmsOnMapperMapper { void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java index 28eaf8f337..a6b3b021fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/CustomerNvpmsPropertyMappingMapper.java @@ -21,7 +21,7 @@ public interface CustomerNvpmsPropertyMappingMapper { @Mapping( target = "details", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java index 3c2dd51344..e025cfd86c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper1.java @@ -21,7 +21,7 @@ public interface ErroneousCustomerMapper1 { @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java index 4b7f2bec75..fad47afb27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper2.java @@ -21,7 +21,7 @@ public interface ErroneousCustomerMapper2 { @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java index 755b468539..1a0eae5f4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper3.java @@ -21,7 +21,7 @@ public interface ErroneousCustomerMapper3 { @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java index 88fe1a7cbf..da54f8c9b5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper4.java @@ -21,7 +21,7 @@ public interface ErroneousCustomerMapper4 { @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java index 05ed1c1fe6..fc2861bc15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/ErroneousCustomerMapper5.java @@ -21,7 +21,7 @@ public interface ErroneousCustomerMapper5 { @Mapping(target = "address", nullValuePropertyMappingStrategy = IGNORE) void map(Customer customer, @MappingTarget CustomerDTO mappingTarget); - @Mapping(source = "houseNumber", target = "houseNo") + @Mapping(target = "houseNo", source = "houseNumber") void mapCustomerHouse(Address address, @MappingTarget AddressDTO addrDTO); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java index efc62ee6ea..e8cf4c5681 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/SourceTargetMapper.java @@ -14,7 +14,7 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); - @Mapping(source = "qax", target = "qux") + @Mapping(target = "qux", source = "qax") Target sourceToTarget(Source source); Source targetToSource(Target target); diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java index 79d0ed43ad..014eeba1e3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/SourceTargetMapper.java @@ -20,16 +20,16 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forwardNotToReverse(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java index de2da07ece..d01f54a3a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous1.java @@ -22,16 +22,16 @@ public interface SourceTargetMapperAmbiguous1 { SourceTargetMapperAmbiguous1 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous1.class ); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forwardNotToReverse(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java index 25a1939b67..fd2ef5ba9e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous2.java @@ -22,16 +22,16 @@ public interface SourceTargetMapperAmbiguous2 { SourceTargetMapperAmbiguous2 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous2.class ); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forwardNotToReverse(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java index e12505b42d..b7d13a32f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperAmbiguous3.java @@ -23,16 +23,16 @@ public interface SourceTargetMapperAmbiguous3 { SourceTargetMapperAmbiguous3 INSTANCE = Mappers.getMapper( SourceTargetMapperAmbiguous3.class ); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source, @MappingTarget Target target); diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java index 970b24a721..4fb0afa5e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/erroneous/SourceTargetMapperNonMatchingName.java @@ -22,9 +22,9 @@ public interface SourceTargetMapperNonMatchingName { SourceTargetMapperNonMatchingName INSTANCE = Mappers.getMapper( SourceTargetMapperNonMatchingName.class ); @Mappings({ - @Mapping(source = "stringPropX", target = "stringPropY"), - @Mapping(source = "integerPropX", target = "integerPropY"), - @Mapping(source = "propertyToIgnoreDownstream", target = "propertyNotToIgnoreUpstream") + @Mapping(target = "stringPropY", source = "stringPropX"), + @Mapping(target = "integerPropY", source = "integerPropX"), + @Mapping(target = "propertyNotToIgnoreUpstream", source = "propertyToIgnoreDownstream") }) Target forward(Source source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java index 6d1990bd0d..8c52cb7ade 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper1.java @@ -21,7 +21,7 @@ public interface ErroneousMapper1 { @Mappings({ @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), - @Mapping(source = "test", target = "integerConstant", constant = "14"), + @Mapping(target = "integerConstant", source = "test", constant = "14"), @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java index 3ff8bd1b88..9d40a0683c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ErroneousMapper4.java @@ -21,7 +21,7 @@ public interface ErroneousMapper4 { @Mappings({ @Mapping(target = "stringConstant", constant = "stringConstant"), @Mapping(target = "emptyStringConstant", constant = ""), - @Mapping(source = "test", target = "integerConstant", expression = "java('test')"), + @Mapping(target = "integerConstant", source = "test", expression = "java('test')"), @Mapping(target = "longWrapperConstant", constant = "3001L"), @Mapping(target = "dateConstant", dateFormat = "dd-MM-yyyy", constant = "09-01-2014"), @Mapping(target = "nameConstants", constant = "jack-jill-tom"), diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java index 6e9a63e6d2..51a59783ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceTargetMapperSeveralSources.java @@ -19,8 +19,8 @@ public interface SourceTargetMapperSeveralSources { SourceTargetMapperSeveralSources INSTANCE = Mappers.getMapper( SourceTargetMapperSeveralSources.class ); @Mappings({ - @Mapping(source = "s1.someProp", target = "someProp" ), - @Mapping(source = "s2.anotherProp", target = "anotherProp" ), + @Mapping(target = "someProp", source = "s1.someProp"), + @Mapping(target = "anotherProp", source = "s2.anotherProp"), @Mapping(target = "someConstant", constant = "stringConstant"), }) Target2 sourceToTarget(Source1 s1, Source2 s2); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java index 5c57b154a8..ea37eafeca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapperSeveralSources.java @@ -20,8 +20,8 @@ public interface SourceTargetMapperSeveralSources { SourceTargetMapperSeveralSources INSTANCE = Mappers.getMapper( SourceTargetMapperSeveralSources.class ); @Mappings( { - @Mapping( target = "timeAndFormat", expression = "java( new TimeAndFormat( s.getTime(), s.getFormat() ))" ), - @Mapping( source = "s1.anotherProp", target = "anotherProp" ) + @Mapping(target = "timeAndFormat", expression = "java( new TimeAndFormat( s.getTime(), s.getFormat() ))"), + @Mapping(target = "anotherProp", source = "s1.anotherProp") } ) Target sourceToTarget( Source s, Source2 s1 ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java index b64186e6bd..c4fbd1eb9b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetConfig.java @@ -11,8 +11,8 @@ @MapperConfig public interface SourceTargetConfig { - @Mapping(source = "address.houseNo", target = "houseNumber") - @Mapping(source = "person.description", target = "description") + @Mapping(target = "houseNumber", source = "address.houseNo") + @Mapping(target = "description", source = "person.description") DeliveryAddress personAndAddressToDeliveryAddress(Person person, Address address); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java index f9289dc99d..78f1654c48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/SourceTargetMapper.java @@ -17,19 +17,19 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings({ - @Mapping(source = "address.houseNo", target = "houseNumber"), - @Mapping(source = "person.description", target = "description") + @Mapping(target = "houseNumber", source = "address.houseNo"), + @Mapping(target = "description", source = "person.description") }) DeliveryAddress personAndAddressToDeliveryAddress(Person person, Address address); @Mappings({ - @Mapping(source = "address.houseNo", target = "houseNumber"), - @Mapping(source = "person.description", target = "description") + @Mapping(target = "houseNumber", source = "address.houseNo"), + @Mapping(target = "description", source = "person.description") }) void personAndAddressToDeliveryAddress(Person person, Address address, @MappingTarget DeliveryAddress deliveryAddress); - @Mapping( target = "description", source = "person.description") + @Mapping(target = "description", source = "person.description") DeliveryAddress personAndAddressToDeliveryAddress(Person person, Integer houseNumber, int zipCode, String street); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java index 06084b4e6e..a3dff45d1d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceTargetMapper.java @@ -19,10 +19,10 @@ public interface SourceTargetMapper { @Mappings( { - @Mapping(source = "name", target = "name1"), - @Mapping(source = "name", target = "name2"), - @Mapping(source = "timeAndFormat", target = "time"), - @Mapping(source = "timeAndFormat", target = "format") + @Mapping(target = "name1", source = "name"), + @Mapping(target = "name2", source = "name"), + @Mapping(target = "time", source = "timeAndFormat"), + @Mapping(target = "format", source = "timeAndFormat") }) Target sourceToTarget(Source s); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java index 126e6801f0..fbc7de9064 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper1.java @@ -25,12 +25,12 @@ public interface ErroneousOrganizationMapper1 { void toCompanyEntity(CompanyDto dto, @MappingTarget CompanyEntity entity); - @Mapping(source = "type", target = "type") + @Mapping(target = "type", source = "type") void toName(String type, @MappingTarget OrganizationTypeEntity entity); @Mappings({ - @Mapping( target = "employees", ignore = true ), - @Mapping( target = "secretaryToEmployee", ignore = true ) + @Mapping(target = "employees", ignore = true ), + @Mapping(target = "secretaryToEmployee", ignore = true ) }) DepartmentEntity toDepartmentEntity(DepartmentDto dto); diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java index f57e4c95a4..dff339d9a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/ErroneousOrganizationMapper2.java @@ -25,7 +25,7 @@ public interface ErroneousOrganizationMapper2 { void toCompanyEntity(CompanyDto dto, @MappingTarget CompanyEntity entity); - @Mapping(source = "type", target = "type") + @Mapping(target = "type", source = "type") void toName(String type, @MappingTarget OrganizationTypeEntity entity); @Mappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java index d2b71b439e..4f2715d0db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/OrganizationMapper.java @@ -29,14 +29,14 @@ public interface OrganizationMapper { void toCompanyEntity(CompanyDto dto, @MappingTarget CompanyEntity entity); @Mappings({ - @Mapping( target = "employees", ignore = true ), - @Mapping( target = "secretaryToEmployee", ignore = true ) + @Mapping(target = "employees", ignore = true ), + @Mapping(target = "secretaryToEmployee", ignore = true ) }) DepartmentEntity toDepartmentEntity(DepartmentDto dto); - @Mapping(source = "type", target = "type") + @Mapping(target = "type", source = "type") void toName(String type, @MappingTarget OrganizationTypeEntity entity); - @Mapping(source = "number", target = "number") + @Mapping(target = "number", source = "number") void toNumber(Integer number, @MappingTarget OrganizationTypeNrEntity entity); } From 228660c74f4c863a07bb850c292dfba74b254a2e Mon Sep 17 00:00:00 2001 From: Jude Niroshan Date: Sun, 7 Mar 2021 14:11:45 +0100 Subject: [PATCH 0553/1006] #2366 Update documentation in regards to Java Module System --- .../main/asciidoc/chapter-2-set-up.asciidoc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 76626f44ce..fd27b25e42 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -248,20 +248,8 @@ If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, |`WARN` |=== -=== Using MapStruct on Java 9 +=== Using MapStruct with the Java Module System -MapStruct can be used with Java 9 (JPMS), support for it is experimental. +MapStruct can be used with Java 9 and higher versions. -A core theme of Java 9 is the modularization of the JDK. One effect of this is that a specific module needs to be enabled for a project in order to use the `javax.annotation.Generated` annotation. `@Generated` is added by MapStruct to generated mapper classes to tag them as generated code, stating the date of generation, the generator version etc. - -To allow usage of the `@Generated` annotation the module _java.xml.ws.annotation_ must be enabled. When using Maven, this can be done like this: - - export MAVEN_OPTS="--add-modules java.xml.ws.annotation" - -If the `@Generated` annotation is not available, MapStruct will detect this situation and not add it to generated mappers. - -[NOTE] -===== -In Java 9 `java.annotation.processing.Generated` was added (part of the `java.compiler` module), -if this annotation is available then it will be used. -===== +To allow usage of the `@Generated` annotation `java.annotation.processing.Generated` (part of the `java.compiler` module) can be enabled. From c4135e68ed8330fbc5180abd828e35b30f606ece Mon Sep 17 00:00:00 2001 From: "jude.niroshan11@gmail.com" Date: Fri, 19 Feb 2021 23:06:42 +0100 Subject: [PATCH 0554/1006] #2339 Support throwing an exception as an Enum Mapping option --- .../java/org/mapstruct/MappingConstants.java | 8 ++ .../main/java/org/mapstruct/ValueMapping.java | 27 +++++- .../ap/internal/gem/MappingConstantsGem.java | 2 + .../ap/internal/model/ValueMappingMethod.java | 82 +++++++++++++--- .../model/source/ValueMappingOptions.java | 3 +- .../mapstruct/ap/internal/util/Message.java | 3 +- .../ap/internal/model/ValueMappingMethod.ftl | 10 +- .../DefaultOrderThrowExceptionMapper.java | 26 ++++++ .../enum2enum/EnumToEnumMappingTest.java | 30 +++--- .../EnumToEnumThrowExceptionMappingTest.java | 93 +++++++++++++++++++ ...OrderMapperThrowExceptionAsSourceType.java | 32 +++++++ .../enum2enum/OrderThrowExceptionMapper.java | 35 +++++++ .../value/enum2enum/SpecialOrderMapper.java | 8 +- .../SpecialThrowExceptionMapper.java | 47 ++++++++++ .../enum2enum/SpecialOrderMapperImpl.java | 4 +- 15 files changed, 368 insertions(+), 42 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/DefaultOrderThrowExceptionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/ErroneousOrderMapperThrowExceptionAsSourceType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/OrderThrowExceptionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialThrowExceptionMapper.java diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index 6e30f08c21..53528f559e 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -36,6 +36,14 @@ private MappingConstants() { */ public static final String ANY_UNMAPPED = ""; + /** + * In an {@link ValueMapping} this represents any target that will be mapped to an + * {@link java.lang.IllegalArgumentException} which will be thrown at runtime. + *

    + * NOTE: The value is only applicable to {@link ValueMapping#target()} and not to {@link ValueMapping#source()}. + */ + public static final String THROW_EXCEPTION = ""; + /** * In an {@link EnumMapping} this represent the enum transformation strategy that adds a suffix to the source enum. * diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index f8f2d3b18e..2d4a586366 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -23,7 +23,8 @@ * *

      * 
    - * public enum OrderType { RETAIL, B2B, EXTRA, STANDARD, NORMAL }
    + *
    + * public enum OrderType { RETAIL, B2B, C2C, EXTRA, STANDARD, NORMAL }
      *
      * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
      *
    @@ -45,13 +46,12 @@
      * +---------------------+----------------------------+
      * 
    * - * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found an - * {@link java.lang.IllegalStateException} will be thrown. *

    * Example 2: * *

      * 
    + *
      * @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
      * @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
      * @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
    @@ -70,6 +70,26 @@
      * +---------------------+----------------------------+
      * 
    * + *

    + * Example 3: + *

    + * + *

    MapStruct will WARN on incomplete mappings. However, if for some reason no match is found, an + * {@link java.lang.IllegalStateException} will be thrown. This compile-time error can be avoided by + * using {@link MappingConstants#THROW_EXCEPTION} for {@link ValueMapping#target()}. It will result an + * {@link java.lang.IllegalArgumentException} at runtime. + *
    + * 
    + *
    + * @ValueMapping( source = "STANDARD", target = "DEFAULT" ),
    + * @ValueMapping( source = "C2C", target = MappingConstants.THROW_EXCEPTION )
    + * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
    + * 
    + * Mapping result:
    + * {@link java.lang.IllegalArgumentException} with the error message:
    + * Unexpected enum constant: C2C
    + * 
    + * * @author Sjaak Derksen */ @Repeatable(ValueMappings.class) @@ -104,6 +124,7 @@ *
      *
    1. enum constant name
    2. *
    3. {@link MappingConstants#NULL}
    4. + *
    5. {@link MappingConstants#THROW_EXCEPTION}
    6. *
    * * @return The target value. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index 5df7fd3f92..be8f23b76d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -21,6 +21,8 @@ private MappingConstantsGem() { public static final String ANY_UNMAPPED = ""; + public static final String THROW_EXCEPTION = ""; + public static final String SUFFIX_TRANSFORMATION = "suffix"; public static final String STRIP_SUFFIX_TRANSFORMATION = "stripSuffix"; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 627a4b7288..e292d38e3a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -14,7 +14,6 @@ import java.util.Set; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.model.common.Parameter; @@ -25,11 +24,13 @@ import org.mapstruct.ap.internal.model.source.ValueMappingOptions; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumTransformationStrategy; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.NULL; +import static org.mapstruct.ap.internal.gem.MappingConstantsGem.THROW_EXCEPTION; import static org.mapstruct.ap.internal.util.Collections.first; /** @@ -43,6 +44,8 @@ public class ValueMappingMethod extends MappingMethod { private final List valueMappings; private final String defaultTarget; private final String nullTarget; + private boolean nullAsException; + private boolean defaultAsException; private final Type unexpectedValueMappingException; @@ -119,10 +122,12 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { return new ValueMappingMethod( method, mappingEntries, valueMappings.nullValueTarget, + valueMappings.hasNullValueAsException, valueMappings.defaultTargetValue, determineUnexpectedValueMappingException(), beforeMappingMethods, - afterMappingMethods + afterMappingMethods, + determineExceptionMappingForDefaultCase() ); } @@ -313,7 +318,17 @@ private boolean reportErrorIfMappedSourceEnumConstantsDontExist(Method method, T for ( ValueMappingOptions mappedConstant : valueMappings.regularValueMappings ) { - if ( !sourceEnumConstants.contains( mappedConstant.getSource() ) ) { + if ( !enumMapping.isInverse() && THROW_EXCEPTION.equals( mappedConstant.getSource() ) ) { + ctx.getMessager().printMessage( + method.getExecutable(), + mappedConstant.getMirror(), + mappedConstant.getSourceAnnotationValue(), + Message.VALUEMAPPING_THROW_EXCEPTION_SOURCE + ); + foundIncorrectMapping = true; + } + else if ( !sourceEnumConstants.contains( mappedConstant.getSource() ) ) { + ctx.getMessager().printMessage( method.getExecutable(), mappedConstant.getMirror(), @@ -361,6 +376,7 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T for ( ValueMappingOptions mappedConstant : valueMappings.regularValueMappings ) { if ( !NULL.equals( mappedConstant.getTarget() ) + && !THROW_EXCEPTION.equals( mappedConstant.getTarget() ) && !targetEnumConstants.contains( mappedConstant.getTarget() ) ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -374,7 +390,9 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T } } - if ( valueMappings.defaultTarget != null && !NULL.equals( valueMappings.defaultTarget.getTarget() ) + if ( valueMappings.defaultTarget != null + && !THROW_EXCEPTION.equals( valueMappings.defaultTarget.getTarget() ) + && !NULL.equals( valueMappings.defaultTarget.getTarget() ) && !targetEnumConstants.contains( valueMappings.defaultTarget.getTarget() ) ) { ctx.getMessager().printMessage( method.getExecutable(), @@ -415,7 +433,9 @@ else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != n } private Type determineUnexpectedValueMappingException() { - if ( !valueMappings.hasDefaultValue ) { + boolean noDefaultValueForSwitchCase = !valueMappings.hasDefaultValue; + if ( noDefaultValueForSwitchCase || valueMappings.hasAtLeastOneExceptionValue + || valueMappings.hasNullValueAsException ) { TypeMirror unexpectedValueMappingException = enumMapping.getUnexpectedValueMappingException(); if ( unexpectedValueMappingException != null ) { return ctx.getTypeFactory().getType( unexpectedValueMappingException ); @@ -427,6 +447,15 @@ private Type determineUnexpectedValueMappingException() { return null; } + + private boolean determineExceptionMappingForDefaultCase() { + if ( valueMappings.hasDefaultValue ) { + return THROW_EXCEPTION.equals( valueMappings.defaultTargetValue ); + } + else { + return true; + } + } } private static class EnumTransformationStrategyInvoker { @@ -464,7 +493,8 @@ private static class ValueMappings { boolean hasMapAnyUnmapped = false; boolean hasMapAnyRemaining = false; boolean hasDefaultValue = false; - boolean hasNullValue = false; + boolean hasNullValueAsException = false; + boolean hasAtLeastOneExceptionValue = false; ValueMappings(List valueMappings) { @@ -484,11 +514,17 @@ else if ( ANY_UNMAPPED.equals( valueMapping.getSource() ) ) { else if ( NULL.equals( valueMapping.getSource() ) ) { nullTarget = valueMapping; nullValueTarget = getValue( nullTarget ); - hasNullValue = true; + if ( THROW_EXCEPTION.equals( nullValueTarget ) ) { + hasNullValueAsException = true; + } } else { regularValueMappings.add( valueMapping ); } + + if ( THROW_EXCEPTION.equals( valueMapping.getTarget() ) ) { + hasAtLeastOneExceptionValue = true; + } } } @@ -497,14 +533,20 @@ String getValue(ValueMappingOptions valueMapping) { } } - private ValueMappingMethod(Method method, List enumMappings, String nullTarget, String defaultTarget, - Type unexpectedValueMappingException, - List beforeMappingMethods, - List afterMappingMethods) { + private ValueMappingMethod(Method method, + List enumMappings, + String nullTarget, + boolean hasNullTargetAsException, + String defaultTarget, + Type unexpectedValueMappingException, + List beforeMappingMethods, + List afterMappingMethods, boolean defaultAsException) { super( method, beforeMappingMethods, afterMappingMethods ); this.valueMappings = enumMappings; this.nullTarget = nullTarget; + this.nullAsException = hasNullTargetAsException; this.defaultTarget = defaultTarget; + this.defaultAsException = defaultAsException; this.unexpectedValueMappingException = unexpectedValueMappingException; this.overridden = method.overridesMethod(); } @@ -532,10 +574,18 @@ public String getNullTarget() { return nullTarget; } + public boolean isNullAsException() { + return nullAsException; + } + public Type getUnexpectedValueMappingException() { return unexpectedValueMappingException; } + public boolean isDefaultAsException() { + return defaultAsException; + } + public Parameter getSourceParameter() { return first( getSourceParameters() ); } @@ -547,17 +597,25 @@ public boolean isOverridden() { public static class MappingEntry { private final String source; private final String target; + private boolean targetAsException = false; - MappingEntry( String source, String target ) { + MappingEntry(String source, String target) { this.source = source; if ( !NULL.equals( target ) ) { this.target = target; + if ( THROW_EXCEPTION.equals( target ) ) { + this.targetAsException = true; + } } else { this.target = null; } } + public boolean isTargetAsException() { + return targetAsException; + } + public String getSource() { return source; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java index 10aef4bfa8..963683b5c5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java @@ -18,6 +18,7 @@ import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_REMAINING; import static org.mapstruct.ap.internal.gem.MappingConstantsGem.ANY_UNMAPPED; +import static org.mapstruct.ap.internal.gem.MappingConstantsGem.THROW_EXCEPTION; /** * Represents the mapping between one value constant and another. @@ -112,7 +113,7 @@ public AnnotationValue getTargetAnnotationValue() { public ValueMappingOptions inverse() { ValueMappingOptions result; - if ( !(ANY_REMAINING.equals( source ) || ANY_UNMAPPED.equals( source ) ) ) { + if ( !(ANY_REMAINING.equals( source ) || ANY_UNMAPPED.equals( source ) || THROW_EXCEPTION.equals( target ) ) ) { result = new ValueMappingOptions( target, source, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 378395d4da..e30407ea20 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -175,7 +175,8 @@ public enum Message { VALUEMAPPING_ANY_REMAINING_FOR_NON_ENUM( "Source = \"\" can only be used on targets of type enum and not for %s." ), VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING( "Source = \"\" or \"\" is advisable for mapping of type String to an enum type.", Diagnostic.Kind.WARNING ), VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI( "Constant %s doesn't exist in enum type %s. Constant was returned from EnumMappingStrategy: %s"), - VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ); + VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ), + VALUEMAPPING_THROW_EXCEPTION_SOURCE( "Source = \"\" is not allowed. Target = \"\" can only be used." ); // CHECKSTYLE:ON diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 530d5643e1..2844b43e3e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -15,17 +15,17 @@ if ( ${sourceParameter.name} == null ) { - return <@writeTarget target=nullTarget/>; + <#if nullAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else>return <@writeTarget target=nullTarget/>; } <@includeModel object=resultType/> ${resultName}; switch ( ${sourceParameter.name} ) { <#list valueMappings as valueMapping> - case <@writeSource source=valueMapping.source/>: ${resultName} = <@writeTarget target=valueMapping.target/>; - break; + case <@writeSource source=valueMapping.source/>: <#if valueMapping.targetAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else>${resultName} = <@writeTarget target=valueMapping.target/>; + break; - default: <#if unexpectedValueMappingException??>throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget/>; + default: <#if defaultAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget/>; } <#list beforeMappingReferencesWithMappingTarget as callback> <#if callback_index = 0> @@ -65,4 +65,4 @@ null - \ No newline at end of file + diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/DefaultOrderThrowExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/DefaultOrderThrowExceptionMapper.java new file mode 100644 index 0000000000..ab1ca97828 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/DefaultOrderThrowExceptionMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.enum2enum; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.Named; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.factory.Mappers; + +/** + * @author Jude Niroshan + */ +@Mapper +public interface DefaultOrderThrowExceptionMapper { + DefaultOrderThrowExceptionMapper INSTANCE = Mappers.getMapper( DefaultOrderThrowExceptionMapper.class ); + + @Named("orderTypeToExternalOrderTypeAnyUnmappedToException") + @ValueMapping(source = MappingConstants.ANY_UNMAPPED, target = MappingConstants.THROW_EXCEPTION) + ExternalOrderType orderTypeToExternalOrderTypeAnyUnmappedToException(OrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java index 43b621f8cc..1e93f4b00d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.value.enum2enum; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; import org.junit.Rule; @@ -22,14 +20,18 @@ import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for the generation and invocation of enum mapping methods. * * @author Gunnar Morling, Sjaak Derksen */ @IssueKey("128") -@WithClasses({ OrderMapper.class, SpecialOrderMapper.class, DefaultOrderMapper.class, OrderEntity.class, - OrderType.class, OrderDto.class, ExternalOrderType.class }) +@WithClasses({ + OrderMapper.class, SpecialOrderMapper.class, DefaultOrderMapper.class, OrderEntity.class, + OrderType.class, OrderDto.class, ExternalOrderType.class +}) @RunWith(AnnotationProcessorTestRunner.class) public class EnumToEnumMappingTest { @@ -74,16 +76,16 @@ public void shouldInvokeEnumMappingMethodForPropertyMapping() { @Test public void shouldApplyReverseMappings() { - OrderType result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); + OrderType result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); assertThat( result ).isEqualTo( OrderType.EXTRA ); - result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.DEFAULT ); + result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.DEFAULT ); assertThat( result ).isEqualTo( OrderType.STANDARD ); - result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.RETAIL ); + result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.RETAIL ); assertThat( result ).isEqualTo( OrderType.RETAIL ); - result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.B2B ); + result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.B2B ); assertThat( result ).isEqualTo( OrderType.B2B ); } @@ -141,16 +143,16 @@ public void shouldApplyDefaultMappings() { @Test public void shouldApplyDefaultReverseMappings() { - OrderType result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); + OrderType result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); assertThat( result ).isEqualTo( OrderType.EXTRA ); - result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.DEFAULT ); + result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.DEFAULT ); assertThat( result ).isNull(); - result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.RETAIL ); + result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.RETAIL ); assertThat( result ).isEqualTo( OrderType.RETAIL ); - result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.B2B ); + result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.B2B ); assertThat( result ).isEqualTo( OrderType.B2B ); } @@ -186,7 +188,7 @@ public void shouldMappAllUnmappedToDefault() { } - @IssueKey( "1091" ) + @IssueKey("1091") @Test public void shouldMapAnyRemainingToNullCorrectly() { ExternalOrderType externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.RETAIL ); @@ -265,7 +267,7 @@ public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeI @Diagnostic(type = ErroneousOrderMapperDuplicateANY.class, kind = Kind.ERROR, line = 28, - message = "Source = \"\" or \"\" can only be used once." ) + message = "Source = \"\" or \"\" can only be used once.") } ) public void shouldRaiseErrorIfMappingsContainDuplicateANY() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java new file mode 100644 index 0000000000..15f0d7964d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java @@ -0,0 +1,93 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.enum2enum; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Jude Niroshan + */ +@IssueKey("2339") +@WithClasses({ + OrderEntity.class, + OrderType.class, ExternalOrderType.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class EnumToEnumThrowExceptionMappingTest { + + @IssueKey("2339") + @Test + @WithClasses(DefaultOrderThrowExceptionMapper.class) + public void shouldBeAbleToMapAnyUnmappedToThrowException() { + + assertThatThrownBy( () -> + DefaultOrderThrowExceptionMapper.INSTANCE + .orderTypeToExternalOrderTypeAnyUnmappedToException( OrderType.EXTRA ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Unexpected enum constant: EXTRA" ); + } + + @IssueKey("2339") + @Test + @WithClasses({ DefaultOrderThrowExceptionMapper.class, ErroneousOrderMapperThrowExceptionAsSourceType.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousOrderMapperThrowExceptionAsSourceType.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + message = "Source = \"\" is not allowed. " + + "Target = \"\" can only be used.") + } + ) + public void shouldRaiseErrorWhenThrowExceptionUsedAsSourceType() { + } + + @IssueKey("2339") + @Test + @WithClasses({OrderThrowExceptionMapper.class, OrderDto.class}) + public void shouldIgnoreThrowExceptionWhenInverseValueMappings() { + + OrderType target = OrderThrowExceptionMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.B2B ); + assertThat( target ).isEqualTo( OrderType.B2B ); + } + + @IssueKey("2339") + @Test + @WithClasses({SpecialThrowExceptionMapper.class, OrderDto.class}) + public void shouldBeAbleToMapAnyRemainingToThrowException() { + + assertThatThrownBy( () -> + SpecialThrowExceptionMapper.INSTANCE + .orderTypeToExternalOrderType( OrderType.EXTRA ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Unexpected enum constant: EXTRA" ); + } + + @IssueKey("2339") + @Test + @WithClasses({SpecialThrowExceptionMapper.class, OrderDto.class}) + public void shouldBeAbleToMapNullToThrowException() { + + assertThatThrownBy( () -> + SpecialThrowExceptionMapper.INSTANCE + .anyRemainingToNullToException( null ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Unexpected enum constant: null" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/ErroneousOrderMapperThrowExceptionAsSourceType.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/ErroneousOrderMapperThrowExceptionAsSourceType.java new file mode 100644 index 0000000000..5c872c2de8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/ErroneousOrderMapperThrowExceptionAsSourceType.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.enum2enum; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.factory.Mappers; + +/** + * @author Jude Niroshan + */ +@Mapper +public interface ErroneousOrderMapperThrowExceptionAsSourceType { + + ErroneousOrderMapperThrowExceptionAsSourceType INSTANCE = Mappers.getMapper( + ErroneousOrderMapperThrowExceptionAsSourceType.class ); + + @ValueMappings({ + @ValueMapping(source = "EXTRA", target = "SPECIAL"), + @ValueMapping(source = "STANDARD", target = "DEFAULT"), + @ValueMapping(source = "NORMAL", target = "DEFAULT"), + @ValueMapping(source = "", target = "DEFAULT"), + @ValueMapping(source = "", target = "DEFAULT") + }) + ExternalOrderType orderTypeToExternalOrderTypeWithErroneousSourceMapping(OrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/OrderThrowExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/OrderThrowExceptionMapper.java new file mode 100644 index 0000000000..c189b22d51 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/OrderThrowExceptionMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.enum2enum; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.factory.Mappers; + +/** + * @author Jude Niroshan + */ +@Mapper +public interface OrderThrowExceptionMapper { + OrderThrowExceptionMapper INSTANCE = Mappers.getMapper( OrderThrowExceptionMapper.class ); + + OrderDto orderEntityToDto(OrderEntity order); + + @ValueMappings({ + @ValueMapping(source = "EXTRA", target = "SPECIAL"), + @ValueMapping(source = "STANDARD", target = "DEFAULT"), + @ValueMapping(source = "NORMAL", target = MappingConstants.THROW_EXCEPTION) + }) + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); + + @InheritInverseConfiguration + OrderType externalOrderTypeToOrderType(ExternalOrderType orderType); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapper.java index 46ffb8b1cf..60d2d5f673 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapper.java @@ -29,14 +29,14 @@ public interface SpecialOrderMapper { @Named("orderTypeToExternalOrderType") @ValueMappings({ - @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ), - @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ), - @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" ) + @ValueMapping(source = MappingConstants.NULL, target = "DEFAULT"), + @ValueMapping(source = "STANDARD", target = MappingConstants.NULL), + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = "SPECIAL") }) ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); @InheritInverseConfiguration(name = "orderTypeToExternalOrderType") - @ValueMapping( target = "EXTRA", source = "SPECIAL" ) + @ValueMapping(target = "EXTRA", source = "SPECIAL") OrderType externalOrderTypeToOrderType(ExternalOrderType orderType); @ValueMappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialThrowExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialThrowExceptionMapper.java new file mode 100644 index 0000000000..0c6d4740ca --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/SpecialThrowExceptionMapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.enum2enum; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.Named; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.factory.Mappers; + +/** + * @author Jude Niroshan + */ +@Mapper +public interface SpecialThrowExceptionMapper { + SpecialThrowExceptionMapper INSTANCE = Mappers.getMapper( SpecialThrowExceptionMapper.class ); + + @Mapping(target = "orderType", source = "orderType", qualifiedByName = "orderTypeToExternalOrderType") + OrderDto orderEntityToDto(OrderEntity order); + + @Named("orderTypeToExternalOrderType") + @ValueMappings({ + @ValueMapping(source = MappingConstants.NULL, target = "DEFAULT"), + @ValueMapping(source = "STANDARD", target = MappingConstants.NULL), + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.THROW_EXCEPTION) + }) + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); + + @InheritInverseConfiguration(name = "orderTypeToExternalOrderType") + @ValueMapping(target = "EXTRA", source = "SPECIAL") + OrderType externalOrderTypeToOrderType(ExternalOrderType orderType); + + @ValueMappings({ + @ValueMapping(source = MappingConstants.NULL, target = MappingConstants.THROW_EXCEPTION), + @ValueMapping(source = "STANDARD", target = MappingConstants.NULL), + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + }) + ExternalOrderType anyRemainingToNullToException(OrderType orderType); +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapperImpl.java index f420a63baf..7b5f6f288f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/value/enum2enum/SpecialOrderMapperImpl.java @@ -11,8 +11,8 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2017-02-20T21:25:45+0100", - comments = "version: , compiler: javac, environment: Java 1.8.0_112 (Oracle Corporation)" + date = "2021-02-19T21:20:19+0100", + comments = "version: , compiler: javac, environment: Java 1.8.0_191 (Oracle Corporation)" ) public class SpecialOrderMapperImpl implements SpecialOrderMapper { From 197dd4327afe1f9cf55a10579491aa3fe162fb0b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 15 Mar 2021 00:21:24 +0100 Subject: [PATCH 0555/1006] #2339 Polish PR #2362 Use MappingEntry for defaultTarget and nullTarget in ValueMappingMethod to simplify certain things --- .../ap/internal/model/ValueMappingMethod.java | 76 +++++++------------ .../ap/internal/model/ValueMappingMethod.ftl | 6 +- .../mapstruct/ap/test/gem/ConstantTest.java | 1 + .../value/spi/CustomEnumMappingStrategy.java | 21 +++++ .../spi/CustomEnumMappingStrategyTest.java | 23 ++++++ .../value/spi/CustomThrowingCheeseMapper.java | 22 ++++++ .../value/spi/CustomThrowingCheeseType.java | 17 +++++ .../value/spi/CustomThrowingEnumMarker.java | 12 +++ 8 files changed, 125 insertions(+), 53 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingEnumMarker.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index e292d38e3a..6e7fe3f0da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -42,10 +42,8 @@ public class ValueMappingMethod extends MappingMethod { private final List valueMappings; - private final String defaultTarget; - private final String nullTarget; - private boolean nullAsException; - private boolean defaultAsException; + private final MappingEntry defaultTarget; + private final MappingEntry nullTarget; private final Type unexpectedValueMappingException; @@ -122,12 +120,10 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { return new ValueMappingMethod( method, mappingEntries, valueMappings.nullValueTarget, - valueMappings.hasNullValueAsException, valueMappings.defaultTargetValue, determineUnexpectedValueMappingException(), beforeMappingMethods, - afterMappingMethods, - determineExceptionMappingForDefaultCase() + afterMappingMethods ); } @@ -417,6 +413,7 @@ private boolean reportErrorIfMappedTargetEnumConstantsDontExist(Method method, T foundIncorrectMapping = true; } else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != null + && !valueMappings.nullValueTarget.equals( THROW_EXCEPTION ) && !targetEnumConstants.contains( valueMappings.nullValueTarget ) ) { // if there is no nullTarget, but nullValueTarget has a value it means that there was an SPI // which returned an enum for the target enum @@ -433,28 +430,13 @@ else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != n } private Type determineUnexpectedValueMappingException() { - boolean noDefaultValueForSwitchCase = !valueMappings.hasDefaultValue; - if ( noDefaultValueForSwitchCase || valueMappings.hasAtLeastOneExceptionValue - || valueMappings.hasNullValueAsException ) { - TypeMirror unexpectedValueMappingException = enumMapping.getUnexpectedValueMappingException(); - if ( unexpectedValueMappingException != null ) { - return ctx.getTypeFactory().getType( unexpectedValueMappingException ); - } - - return ctx.getTypeFactory() - .getType( ctx.getEnumMappingStrategy().getUnexpectedValueMappingExceptionType() ); + TypeMirror unexpectedValueMappingException = enumMapping.getUnexpectedValueMappingException(); + if ( unexpectedValueMappingException != null ) { + return ctx.getTypeFactory().getType( unexpectedValueMappingException ); } - return null; - } - - private boolean determineExceptionMappingForDefaultCase() { - if ( valueMappings.hasDefaultValue ) { - return THROW_EXCEPTION.equals( valueMappings.defaultTargetValue ); - } - else { - return true; - } + return ctx.getTypeFactory() + .getType( ctx.getEnumMappingStrategy().getUnexpectedValueMappingExceptionType() ); } } @@ -493,7 +475,6 @@ private static class ValueMappings { boolean hasMapAnyUnmapped = false; boolean hasMapAnyRemaining = false; boolean hasDefaultValue = false; - boolean hasNullValueAsException = false; boolean hasAtLeastOneExceptionValue = false; ValueMappings(List valueMappings) { @@ -501,22 +482,19 @@ private static class ValueMappings { for ( ValueMappingOptions valueMapping : valueMappings ) { if ( ANY_REMAINING.equals( valueMapping.getSource() ) ) { defaultTarget = valueMapping; - defaultTargetValue = getValue( defaultTarget ); + defaultTargetValue = defaultTarget.getTarget(); hasDefaultValue = true; hasMapAnyRemaining = true; } else if ( ANY_UNMAPPED.equals( valueMapping.getSource() ) ) { defaultTarget = valueMapping; - defaultTargetValue = getValue( defaultTarget ); + defaultTargetValue = defaultTarget.getTarget(); hasDefaultValue = true; hasMapAnyUnmapped = true; } else if ( NULL.equals( valueMapping.getSource() ) ) { nullTarget = valueMapping; nullValueTarget = getValue( nullTarget ); - if ( THROW_EXCEPTION.equals( nullValueTarget ) ) { - hasNullValueAsException = true; - } } else { regularValueMappings.add( valueMapping ); @@ -536,17 +514,14 @@ String getValue(ValueMappingOptions valueMapping) { private ValueMappingMethod(Method method, List enumMappings, String nullTarget, - boolean hasNullTargetAsException, String defaultTarget, Type unexpectedValueMappingException, List beforeMappingMethods, - List afterMappingMethods, boolean defaultAsException) { + List afterMappingMethods) { super( method, beforeMappingMethods, afterMappingMethods ); this.valueMappings = enumMappings; - this.nullTarget = nullTarget; - this.nullAsException = hasNullTargetAsException; - this.defaultTarget = defaultTarget; - this.defaultAsException = defaultAsException; + this.nullTarget = new MappingEntry( null, nullTarget ); + this.defaultTarget = new MappingEntry( null, defaultTarget != null ? defaultTarget : THROW_EXCEPTION); this.unexpectedValueMappingException = unexpectedValueMappingException; this.overridden = method.overridesMethod(); } @@ -556,36 +531,37 @@ public Set getImportTypes() { Set importTypes = super.getImportTypes(); if ( unexpectedValueMappingException != null && !unexpectedValueMappingException.isJavaLangType() ) { - importTypes.addAll( unexpectedValueMappingException.getImportTypes() ); + if ( defaultTarget.isTargetAsException() || nullTarget.isTargetAsException() || + hasMappingWithTargetAsException() ) { + importTypes.addAll( unexpectedValueMappingException.getImportTypes() ); + } } return importTypes; } + protected boolean hasMappingWithTargetAsException() { + return getValueMappings() + .stream() + .anyMatch( MappingEntry::isTargetAsException ); + } + public List getValueMappings() { return valueMappings; } - public String getDefaultTarget() { + public MappingEntry getDefaultTarget() { return defaultTarget; } - public String getNullTarget() { + public MappingEntry getNullTarget() { return nullTarget; } - public boolean isNullAsException() { - return nullAsException; - } - public Type getUnexpectedValueMappingException() { return unexpectedValueMappingException; } - public boolean isDefaultAsException() { - return defaultAsException; - } - public Parameter getSourceParameter() { return first( getSourceParameters() ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 2844b43e3e..4d961c40af 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -15,7 +15,7 @@ if ( ${sourceParameter.name} == null ) { - <#if nullAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else>return <@writeTarget target=nullTarget/>; + <#if nullTarget.targetAsException>throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else>return <@writeTarget target=nullTarget.target/>; } <@includeModel object=resultType/> ${resultName}; @@ -25,7 +25,7 @@ case <@writeSource source=valueMapping.source/>: <#if valueMapping.targetAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} );<#else>${resultName} = <@writeTarget target=valueMapping.target/>; break; - default: <#if defaultAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget/>; + default: <#if defaultTarget.targetAsException >throw new <@includeModel object=unexpectedValueMappingException />( "Unexpected enum constant: " + ${sourceParameter.name} )<#else>${resultName} = <@writeTarget target=defaultTarget.target/>; } <#list beforeMappingReferencesWithMappingTarget as callback> <#if callback_index = 0> @@ -40,7 +40,7 @@ <@includeModel object=callback targetBeanName=resultName targetType=resultType/> - <#if !(valueMappings.empty && unexpectedValueMappingException??)> + <#if !(valueMappings.empty && defaultTarget.targetAsException)> return ${resultName}; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index 69fa56a310..711d6d467a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -23,6 +23,7 @@ public void constantsShouldBeEqual() { assertThat( MappingConstants.ANY_REMAINING ).isEqualTo( MappingConstantsGem.ANY_REMAINING ); assertThat( MappingConstants.ANY_UNMAPPED ).isEqualTo( MappingConstantsGem.ANY_UNMAPPED ); assertThat( MappingConstants.NULL ).isEqualTo( MappingConstantsGem.NULL ); + assertThat( MappingConstants.THROW_EXCEPTION ).isEqualTo( MappingConstantsGem.THROW_EXCEPTION ); assertThat( MappingConstants.SUFFIX_TRANSFORMATION ).isEqualTo( MappingConstantsGem.SUFFIX_TRANSFORMATION ); assertThat( MappingConstants.STRIP_SUFFIX_TRANSFORMATION ) .isEqualTo( MappingConstantsGem.STRIP_SUFFIX_TRANSFORMATION ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java index b505dd640b..7cf7a24938 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategy.java @@ -8,6 +8,7 @@ import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; +import org.mapstruct.MappingConstants; import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.spi.DefaultEnumMappingStrategy; import org.mapstruct.ap.spi.EnumMappingStrategy; @@ -20,6 +21,10 @@ public class CustomEnumMappingStrategy extends DefaultEnumMappingStrategy implem @Override public String getDefaultNullEnumConstant(TypeElement enumType) { + if ( isCustomThrowingEnum( enumType ) ) { + return MappingConstants.THROW_EXCEPTION; + } + if ( isCustomEnum( enumType ) ) { return "UNSPECIFIED"; } @@ -29,6 +34,10 @@ public String getDefaultNullEnumConstant(TypeElement enumType) { @Override public String getEnumConstant(TypeElement enumType, String enumConstant) { + if ( isCustomThrowingEnum( enumType ) ) { + return getCustomEnumConstant( enumConstant ); + } + if ( isCustomEnum( enumType ) ) { return getCustomEnumConstant( enumConstant ); } @@ -53,6 +62,18 @@ protected boolean isCustomEnum(TypeElement enumType) { return false; } + protected boolean isCustomThrowingEnum(TypeElement enumType) { + for ( TypeMirror enumTypeInterface : enumType.getInterfaces() ) { + if ( typeUtils.asElement( enumTypeInterface ) + .getSimpleName() + .contentEquals( "CustomThrowingEnumMarker" ) ) { + return true; + } + } + + return false; + } + @Override protected Class getUnexpectedValueMappingExceptionClass() { return CustomIllegalArgumentException.class; diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java index 9cce52d7bd..313a7553bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java @@ -9,12 +9,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.test.value.CustomIllegalArgumentException; +import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @author Filip Hrisafov @@ -24,6 +26,8 @@ CheeseType.class, CustomCheeseType.class, CustomEnumMarker.class, + CustomThrowingCheeseType.class, + CustomThrowingEnumMarker.class, CustomIllegalArgumentException.class, }) @WithServiceImplementation(CustomEnumMappingStrategy.class) @@ -122,4 +126,23 @@ public void shouldApplyDefinedMappingsInsteadOfCustomEnumMappingStrategy() { assertThat( mapper.mapStringToCustom( "ROQUEFORT" ) ).isEqualTo( CustomCheeseType.CUSTOM_ROQUEFORT ); assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); } + + @Test + @IssueKey("2339") + @WithClasses({ + CustomThrowingCheeseMapper.class + }) + public void shouldApplyCustomEnumMappingStrategyWithThrowingException() { + CustomThrowingCheeseMapper mapper = CustomThrowingCheeseMapper.INSTANCE; + + // CustomCheeseType -> CustomThrowingCheeseType + assertThatThrownBy( () -> mapper.map( (CheeseType) null ) ) + .isInstanceOf( CustomIllegalArgumentException.class ) + .hasMessage( "Unexpected enum constant: null" ); + assertThat( mapper.map( CheeseType.BRIE ) ).isEqualTo( CustomThrowingCheeseType.CUSTOM_BRIE ); + + // CustomThrowingCheeseType -> CustomCheeseType + assertThat( mapper.map( (CustomThrowingCheeseType) null ) ).isNull(); + assertThat( mapper.map( CustomThrowingCheeseType.CUSTOM_BRIE ) ).isEqualTo( CheeseType.BRIE ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseMapper.java new file mode 100644 index 0000000000..a62dba55fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomThrowingCheeseMapper { + + CustomThrowingCheeseMapper INSTANCE = Mappers.getMapper( CustomThrowingCheeseMapper.class ); + + CustomThrowingCheeseType map(CheeseType cheese); + + CheeseType map(CustomThrowingCheeseType cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseType.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseType.java new file mode 100644 index 0000000000..f97b39a6d8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingCheeseType.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +/** + * @author Filip Hrisafov + */ +public enum CustomThrowingCheeseType implements CustomThrowingEnumMarker { + + UNSPECIFIED, + CUSTOM_BRIE, + CUSTOM_ROQUEFORT, + UNRECOGNIZED, +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingEnumMarker.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingEnumMarker.java new file mode 100644 index 0000000000..aa5943bbcb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomThrowingEnumMarker.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.spi; + +/** + * @author Filip Hrisafov + */ +public interface CustomThrowingEnumMarker { +} From 1964c809d86ad670c04b08a8b0e924251241c0be Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 16 Mar 2021 20:24:51 +0100 Subject: [PATCH 0556/1006] Fix typo in missing code formatting in documentation Closes #2385 --- .../src/main/asciidoc/chapter-5-data-type-conversions.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 9978cd3f25..ce842df0e8 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -20,7 +20,7 @@ Currently the following conversions are applied automatically: [WARNING] ==== -Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. The `Mapper` and `MapperConfig` annotations have a method `typeConversionPolicy` to control warnings / errors. Due to backward compatibility reasons the default value is 'ReportingPolicy.IGNORE`. +Converting from larger data types to smaller ones (e.g. from `long` to `int`) can cause a value or precision loss. The `Mapper` and `MapperConfig` annotations have a method `typeConversionPolicy` to control warnings / errors. Due to backward compatibility reasons the default value is `ReportingPolicy.IGNORE`. ==== * Between all Java primitive types (including their wrappers) and `String`, e.g. between `int` and `String` or `Boolean` and `String`. A format string as understood by `java.text.DecimalFormat` can be specified. From e7f6813d9ac03e0e0881d2ca7e5f525952f19dfc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Feb 2021 13:56:08 +0100 Subject: [PATCH 0557/1006] #2356 Implicitly ignore reverse inherited mappings that do not have read and write methods --- .../ap/internal/model/BeanMappingMethod.java | 26 +++++++--- .../ap/test/bugs/_2356/Issue2356Mapper.java | 49 +++++++++++++++++++ .../ap/test/bugs/_2356/Issue2356Test.java | 45 +++++++++++++++++ 3 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 459a4f82d9..0ce80c993c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -938,14 +938,24 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp if ( targetWriteAccessor == null ) { if ( targetReadAccessor == null ) { - if ( mapping.getInheritContext() != null && mapping.getInheritContext().isForwarded() && - mapping.getInheritContext().getTemplateMethod().isUpdateMethod() != method.isUpdateMethod() ) { - // When a configuration is inherited and the template method is not same type as the current - // method then we can safely ignore this mapping. - // This means that a property which is inherited might be present for a direct mapping - // via the Builder, but not for an update mapping (directly on the object itself), - // or vice versa - return false; + MappingOptions.InheritContext inheritContext = mapping.getInheritContext(); + if ( inheritContext != null ) { + if ( inheritContext.isForwarded() && + inheritContext.getTemplateMethod().isUpdateMethod() != method.isUpdateMethod() ) { + // When a configuration is inherited and the template method is not same type as the current + // method then we can safely ignore this mapping. + // This means that a property which is inherited might be present for a direct mapping + // via the Builder, but not for an update mapping (directly on the object itself), + // or vice versa + return false; + } + else if ( inheritContext.isReversed() ) { + // When a configuration is reverse inherited and there are no read or write accessor + // then we should ignore this mapping. + // This most likely means that we were mapping the source parameter to the target. + // If the error is due to something else it will be reported on the original mapping + return false; + } } Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Mapper.java new file mode 100644 index 0000000000..173645d118 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Mapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2356; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2356Mapper { + + Issue2356Mapper INSTANCE = Mappers.getMapper( Issue2356Mapper.class ); + + class Car { + //CHECKSTYLE:OFF + public String brand; + public String model; + public String modelInternational; + //CHECKSTYLE:ON + } + + class CarDTO { + //CHECKSTYLE:OFF + public String brand; + public String modelName; + //CHECKSTYLE:ON + } + + // When using InheritInverseConfiguration the mapping from in to modelName should be ignored + // and shouldn't lead to a compile error. + @Mapping(target = "modelName", source = "in") + CarDTO map(Car in); + + default String mapToModel(Car in) { + return in.modelInternational == null ? in.model : in.modelInternational; + } + + @InheritInverseConfiguration + @Mapping(target = "model", source = "modelName") + @Mapping(target = "modelInternational", ignore = true) + Car map(CarDTO in); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java new file mode 100644 index 0000000000..e37f36528c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2356; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2356") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2356Mapper.class +}) +public class Issue2356Test { + + @Test + public void shouldCompile() { + Issue2356Mapper.Car car = new Issue2356Mapper.Car(); + car.brand = "Tesla"; + car.model = "X"; + car.modelInternational = "3"; + Issue2356Mapper.CarDTO dto = Issue2356Mapper.INSTANCE.map( car ); + + assertThat( dto ).isNotNull(); + assertThat( dto.brand ).isEqualTo( "Tesla" ); + assertThat( dto.modelName ).isEqualTo( "3" ); + + car = Issue2356Mapper.INSTANCE.map( dto ); + + assertThat( car ).isNotNull(); + assertThat( car.brand ).isEqualTo( "Tesla" ); + assertThat( car.model ).isEqualTo( "3" ); + assertThat( car.modelInternational ).isNull(); + } +} From 1187e357c1bca9d78cd58794b873822802694964 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sun, 28 Mar 2021 17:34:59 +0200 Subject: [PATCH 0558/1006] #2239 matching generics (#2320) --- .../ap/internal/model/ForgedMethod.java | 5 + .../ap/internal/model/HelperMethod.java | 5 + .../model/LifecycleMethodResolver.java | 1 + .../internal/model/MappingBuilderContext.java | 3 +- .../model/ObjectFactoryMethodResolver.java | 17 +- .../ap/internal/model/common/Type.java | 339 +++++++++-- .../ap/internal/model/common/TypeFactory.java | 6 +- .../ap/internal/model/source/Method.java | 7 + .../internal/model/source/MethodMatcher.java | 564 +++++++++--------- .../internal/model/source/SourceMethod.java | 16 + .../model/source/builtin/BuiltInMethod.java | 7 +- .../selector/CreateOrUpdateSelector.java | 8 +- .../selector/FactoryParameterSelector.java | 8 +- .../source/selector/InheritanceSelector.java | 8 +- .../source/selector/MethodFamilySelector.java | 8 +- .../model/source/selector/MethodSelector.java | 11 +- .../source/selector/MethodSelectors.java | 19 +- .../source/selector/QualifierSelector.java | 8 +- .../source/selector/TargetTypeSelector.java | 8 +- .../model/source/selector/TypeSelector.java | 22 +- .../selector/XmlElementDeclSelector.java | 4 +- .../processor/MethodRetrievalProcessor.java | 4 +- .../creation/MappingResolverImpl.java | 7 +- .../util/EclipseTypeUtilsDecorator.java | 39 ++ .../ap/internal/model/common/Type.ftl | 4 +- .../ap/test/bugs/_1482/Issue1482Test.java | 4 +- .../test/bugs/_1482/TargetSourceMapper.java | 4 +- .../test/collection/SourceTargetMapper.java | 2 - .../selection/generics/ConversionTest.java | 26 +- .../selection/generics/GenericTypeMapper.java | 5 - .../ap/test/selection/generics/Source.java | 27 - .../ap/test/selection/generics/Target.java | 27 - .../array/BothParameterizedMapper.java | 75 +++ .../array/GenericArrayTest.java | 64 ++ .../array/ReturnTypeIsTypeVarArrayMapper.java | 71 +++ .../array/SourceTypeIsTypeVarArrayMapper.java | 67 +++ .../methodgenerics/bounds/BoundsTest.java | 36 ++ .../SourceTypeIsBoundedTypeVarMapper.java | 87 +++ .../multiple/MultipleTypeVarTest.java | 73 +++ ...peHasMultipleTypeVarBothGenericMapper.java | 76 +++ ...ypeHasMultipleTypeVarOneGenericMapper.java | 58 ++ ...peHasMultipleTypeVarBothGenericMapper.java | 86 +++ .../nestedgenerics/NestedGenericsTest.java | 49 ++ .../ReturnTypeHasNestedTypeVarMapper.java | 57 ++ .../SourceTypeHasNestedTypeVarMapper.java | 58 ++ .../plain/BothParameterizedMapper.java | 75 +++ .../methodgenerics/plain/PlainTest.java | 75 +++ .../plain/ReturnTypeIsRawTypeMapper.java | 50 ++ .../plain/ReturnTypeIsTypeVarMapper.java | 64 ++ .../plain/SourceTypeIsTypeVarMapper.java | 63 ++ .../targettype/NestedTargetTypeMapper.java | 75 +++ .../targettype/PlainTargetTypeMapper.java | 66 ++ .../targettype/TargetTypeTest.java | 43 ++ .../wildcards/IntersectionMapper.java | 77 +++ .../SourceWildCardExtendsMapper.java | 87 +++ .../wildcards/WildCardTest.java | 62 ++ .../SourceWildCardExtendsMapper.java | 66 ++ .../selection/typegenerics/WildCardTest.java | 41 ++ .../ReturnTypeWildCardExtendsMapper.java | 70 +++ .../SourceWildCardExtendsMapper.java | 66 ++ .../selection/wildcards/WildCardTest.java | 58 ++ 61 files changed, 2640 insertions(+), 478 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/BothParameterizedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/ReturnTypeIsTypeVarArrayMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/SourceTypeIsTypeVarArrayMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/SourceTypeIsBoundedTypeVarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarBothGenericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarOneGenericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/SourceTypeHasMultipleTypeVarBothGenericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/ReturnTypeHasNestedTypeVarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/SourceTypeHasNestedTypeVarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/BothParameterizedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsRawTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsTypeVarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/SourceTypeIsTypeVarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/NestedTargetTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/PlainTargetTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/IntersectionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/SourceWildCardExtendsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/SourceWildCardExtendsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/ReturnTypeWildCardExtendsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/SourceWildCardExtendsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index e02107881b..820a09c22a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -340,6 +340,11 @@ public MappingMethodOptions getOptions() { return basedOn.getOptions(); } + @Override + public List getTypeParameters() { + return Collections.emptyList(); + } + @Override public String describe() { // the name of the forged method is never fully qualified, so no need to distinguish diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index fcf8068ed6..35b35aee73 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -128,6 +128,11 @@ public boolean isObjectFactory() { return false; } + @Override + public List getTypeParameters() { + return Collections.emptyList(); + } + /** * the conversion context is used to format an auxiliary parameter in the method call with context specific * information such as a date format. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 61610badf8..87527e87f8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -141,6 +141,7 @@ private static List collectLifecycleCallbackMe callbackMethods, Collections.emptyList(), targetType, + method.getReturnType(), SelectionCriteria.forLifecycleMethods( selectionParameters ) ); return toLifecycleCallbackMethodRefs( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 46e1d4ee4e..a9d4fd0918 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -78,12 +78,13 @@ public interface MappingResolver { * returns a parameter assignment * * @param mappingMethod target mapping method - * @param description + * @param description the description source * @param targetType return type to match * @param formattingParameters used for formatting dates and numbers * @param criteria parameters criteria in the selection process * @param sourceRHS source information * @param positionHint the mirror for reporting problems + * @param forger the supplier of the callback method to forge a method * * @return an assignment to a method parameter, which can either be: *
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index d320bb49da..f0bd9c4dff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -5,9 +5,12 @@ */ package org.mapstruct.ap.internal.model; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; + import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -23,8 +26,6 @@ import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Message; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * * @author Sjaak Derksen @@ -129,11 +130,13 @@ public static List> getMatchingFactoryMethods( Meth new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); return selectors.getMatchingMethods( - method, - getAllAvailableMethods( method, ctx.getSourceModel() ), - java.util.Collections.emptyList(), - alternativeTarget, - SelectionCriteria.forFactoryMethods( selectionParameters ) ); + method, + getAllAvailableMethods( method, ctx.getSourceModel() ), + java.util.Collections.emptyList(), + alternativeTarget, + alternativeTarget, + SelectionCriteria.forFactoryMethods( selectionParameters ) + ); } public static MethodReference getBuilderFactoryMethod(Method method, BuilderType builder ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index b3d01f4131..15f787829b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -12,15 +12,18 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; + import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; +import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; @@ -103,6 +106,8 @@ public class Type extends ModelElement implements Comparable { private Type boundingBase = null; + private Type boxedEquivalent = null; + private Boolean hasAccessibleConstructor; private final Filters filters; @@ -311,7 +316,12 @@ public boolean isStreamType() { return isStream; } - public boolean isWildCardSuperBound() { + /** + * A wild card type can have two types of bounds (mutual exclusive): extends and super. + * + * @return true if the bound has a wild card super bound (e.g. ? super Number) + */ + public boolean hasSuperBound() { boolean result = false; if ( typeMirror.getKind() == TypeKind.WILDCARD ) { WildcardType wildcardType = (WildcardType) typeMirror; @@ -320,7 +330,12 @@ public boolean isWildCardSuperBound() { return result; } - public boolean isWildCardExtendsBound() { + /** + * A wild card type can have two types of bounds (mutual exclusive): extends and super. + * + * @return true if the bound has a wild card super bound (e.g. ? extends Number) + */ + public boolean hasExtendsBound() { boolean result = false; if ( typeMirror.getKind() == TypeKind.WILDCARD ) { WildcardType wildcardType = (WildcardType) typeMirror; @@ -329,6 +344,40 @@ public boolean isWildCardExtendsBound() { return result; } + /** + * A type variable type can have two types of bounds (mutual exclusive): lower and upper. + * + * Note that its use is only permitted on a definition (not on the place where its used). For instance: + * {@code T map( T in)} + * + * @return true if the bound has a type variable lower bound (e.g. T super Number) + */ + public boolean hasLowerBound() { + boolean result = false; + if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { + TypeVariable typeVarType = (TypeVariable) typeMirror; + result = typeVarType.getLowerBound() != null; + } + return result; + } + + /** + * A type variable type can have two types of bounds (mutual exclusive): lower and upper. + * + * Note that its use is only permitted on a definition (not on the place where its used). For instance: + * {@code> T map( T in)} + * + * @return true if the bound has a type variable upper bound (e.g. T extends Number) + */ + public boolean hasUpperBound() { + boolean result = false; + if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { + TypeVariable typeVarType = (TypeVariable) typeMirror; + result = typeVarType.getUpperBound() != null; + } + return result; + } + public String getFullyQualifiedName() { return qualifiedName; } @@ -356,7 +405,7 @@ public Set getImportTypes() { result.addAll( parameter.getImportTypes() ); } - if ( ( isWildCardExtendsBound() || isWildCardSuperBound() ) && getTypeBound() != null ) { + if ( ( hasExtendsBound() || hasSuperBound() ) && getTypeBound() != null ) { result.addAll( getTypeBound().getImportTypes() ); } @@ -470,22 +519,19 @@ public Type withoutBounds() { } /** - * Whether this type is assignable to the given other type. + * Whether this type is assignable to the given other type, considering the "extends / upper bounds" + * as well. * * @param other The other type. * * @return {@code true} if and only if this type is assignable to the given other type. */ - // TODO This doesn't yet take super wild card types into account; - // e.g. Number wouldn't be assignable to ? super Number atm. (is there any practical use case) public boolean isAssignableTo(Type other) { - if ( equals( other ) ) { - return true; + if ( TypeKind.WILDCARD == typeMirror.getKind() ) { + return typeUtils.contains( typeMirror, other.typeMirror ); } - TypeMirror typeMirrorToMatch = isWildCardExtendsBound() ? getTypeBound().typeMirror : typeMirror; - - return typeUtils.isAssignable( typeMirrorToMatch, other.typeMirror ); + return typeUtils.isAssignable( typeMirror, other.typeMirror ); } /** @@ -506,6 +552,19 @@ public boolean isRawAssignableTo(Type other) { return typeUtils.isAssignable( typeUtils.erasure( typeMirror ), typeUtils.erasure( other.typeMirror ) ); } + /** + * removes any bounds from this type. + * @return the raw type + */ + public Type asRawType() { + if ( getTypeBound() != null ) { + return typeFactory.getType( typeUtils.erasure( typeMirror ) ); + } + else { + return this; + } + } + /** * getPropertyReadAccessors * @@ -1004,7 +1063,14 @@ public boolean equals(Object obj) { } Type other = (Type) obj; - return typeUtils.isSameType( typeMirror, other.typeMirror ); + if ( this.isWildCardBoundByTypeVar() && other.isWildCardBoundByTypeVar() ) { + return ( this.hasExtendsBound() == this.hasExtendsBound() + || this.hasSuperBound() == this.hasSuperBound() ) + && typeUtils.isSameType( getTypeBound().getTypeMirror(), other.getTypeBound().getTypeMirror() ); + } + else { + return typeUtils.isSameType( typeMirror, other.typeMirror ); + } } @Override @@ -1085,6 +1151,19 @@ public boolean hasAccessibleConstructor() { return hasAccessibleConstructor; } + /** + * Returns the direct supertypes of a type. The interface types, if any, + * will appear last in the list. + * + * @return the direct supertypes, or an empty list if none + */ + public List getDirectSuperTypes() { + return typeUtils.directSupertypes( typeMirror ) + .stream() + .map( typeFactory::getType ) + .collect( Collectors.toList() ); + } + /** * Searches for the given superclass and collects all type arguments for the given class * @@ -1121,59 +1200,239 @@ public boolean isLiteral() { } /** - * Steps through the declaredType in order to find a match for this typevar Type. It allignes with + * Steps through the declaredType in order to find a match for this typeVar Type. It aligns with * the provided parameterized type where this typeVar type is used. * - * @param declaredType the type - * @param parameterizedType the parameterized type + * For example: + * {@code + * this: T + * declaredType: JAXBElement + * parameterizedType: JAXBElement + * result: String + * + * + * this: T, T[] or ? extends T, + * declaredType: E.g. Callable + * parameterizedType: Callable + * return: BigDecimal + * } + * + * @param declared the type + * @param parameterized the parameterized type * - * @return the matching declared type. + * @return - the same type when this is not a type var in the broadest sense (T, T[], or ? extends T) + * - the matching parameter in the parameterized type when this is a type var when found + * - null in all other cases */ - public Type resolveTypeVarToType(Type declaredType, Type parameterizedType) { - if ( isTypeVar() ) { - TypeVarMatcher typeVarMatcher = new TypeVarMatcher( typeUtils, this ); - return typeVarMatcher.visit( parameterizedType.getTypeMirror(), declaredType ); + public ResolvedPair resolveParameterToType(Type declared, Type parameterized) { + if ( isTypeVar() || isArrayTypeVar() || isWildCardBoundByTypeVar() ) { + TypeVarMatcher typeVarMatcher = new TypeVarMatcher( typeFactory, typeUtils, this ); + return typeVarMatcher.visit( parameterized.getTypeMirror(), declared ); } - return this; + return new ResolvedPair( this, this ); + } + + public boolean isWildCardBoundByTypeVar() { + return ( hasExtendsBound() || hasSuperBound() ) && getTypeBound().isTypeVar(); } - private static class TypeVarMatcher extends SimpleTypeVisitor8 { + public boolean isArrayTypeVar() { + return isArrayType() && getComponentType().isTypeVar(); + } + + private static class TypeVarMatcher extends SimpleTypeVisitor8 { - private TypeVariable typeVarToMatch; - private TypeUtils types; + private final TypeFactory typeFactory; + private final Type typeToMatch; + private final TypeUtils types; - TypeVarMatcher(TypeUtils types, Type typeVarToMatch ) { - super( null ); - this.typeVarToMatch = (TypeVariable) typeVarToMatch.getTypeMirror(); + /** + * @param typeFactory factory + * @param types type utils + * @param typeToMatch the typeVar or wildcard with typeVar bound + */ + TypeVarMatcher(TypeFactory typeFactory, TypeUtils types, Type typeToMatch) { + super( new ResolvedPair( typeToMatch, null ) ); + this.typeFactory = typeFactory; + this.typeToMatch = typeToMatch; this.types = types; } @Override - public Type visitTypeVariable(TypeVariable t, Type parameterized) { - if ( types.isSameType( t, typeVarToMatch ) ) { - return parameterized; + public ResolvedPair visitTypeVariable(TypeVariable parameterized, Type declared) { + if ( typeToMatch.isTypeVar() && types.isSameType( parameterized, typeToMatch.getTypeMirror() ) ) { + return new ResolvedPair( typeFactory.getType( parameterized ), declared ); } - return super.visitTypeVariable( t, parameterized ); + return super.DEFAULT_VALUE; } + /** + * If ? extends SomeTime equals the boundary set in typeVarToMatch (NOTE: you can't compare the wildcard itself) + * then return a result; + */ @Override - public Type visitDeclared(DeclaredType t, Type parameterized) { - if ( types.isAssignable( types.erasure( t ), types.erasure( parameterized.getTypeMirror() ) ) ) { + public ResolvedPair visitWildcard(WildcardType parameterized, Type declared) { + if ( typeToMatch.hasExtendsBound() && parameterized.getExtendsBound() != null + && types.isSameType( typeToMatch.getTypeBound().getTypeMirror(), parameterized.getExtendsBound() ) ) { + return new ResolvedPair( typeToMatch, declared); + } + else if ( typeToMatch.hasSuperBound() && parameterized.getSuperBound() != null + && types.isSameType( typeToMatch.getTypeBound().getTypeMirror(), parameterized.getSuperBound() ) ) { + return new ResolvedPair( typeToMatch, declared); + } + if ( parameterized.getExtendsBound() != null ) { + ResolvedPair match = visit( parameterized.getExtendsBound(), declared ); + if ( match.match != null ) { + return new ResolvedPair( typeFactory.getType( parameterized ), declared ); + } + } + else if (parameterized.getSuperBound() != null ) { + ResolvedPair match = visit( parameterized.getSuperBound(), declared ); + if ( match.match != null ) { + return new ResolvedPair( typeFactory.getType( parameterized ), declared ); + } + + } + return super.DEFAULT_VALUE; + } + + @Override + public ResolvedPair visitArray(ArrayType parameterized, Type declared) { + if ( types.isSameType( parameterized.getComponentType(), typeToMatch.getTypeMirror() ) ) { + return new ResolvedPair( typeFactory.getType( parameterized ), declared ); + } + if ( declared.isArrayType() ) { + return visit( parameterized.getComponentType(), declared.getComponentType() ); + } + return super.DEFAULT_VALUE; + } + + @Override + public ResolvedPair visitDeclared(DeclaredType parameterized, Type declared) { + + List results = new ArrayList<>( ); + if ( parameterized.getTypeArguments().isEmpty() ) { + return super.DEFAULT_VALUE; + } + else if ( types.isSameType( types.erasure( parameterized ), types.erasure( declared.getTypeMirror() ) ) ) { // We can't assume that the type args are the same // e.g. List is assignable to Object - if ( t.getTypeArguments().size() != parameterized.getTypeParameters().size() ) { - return super.visitDeclared( t, parameterized ); + if ( parameterized.getTypeArguments().size() != declared.getTypeParameters().size() ) { + return super.visitDeclared( parameterized, declared ); } - for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { - Type result = visit( t.getTypeArguments().get( i ), parameterized.getTypeParameters().get( i ) ); - if ( result != null ) { - return result; + // only possible to compare parameters when the types are exactly the same + for ( int i = 0; i < parameterized.getTypeArguments().size(); i++ ) { + TypeMirror parameterizedTypeArg = parameterized.getTypeArguments().get( i ); + Type declaredTypeArg = declared.getTypeParameters().get( i ); + ResolvedPair result = visit( parameterizedTypeArg, declaredTypeArg ); + if ( result != super.DEFAULT_VALUE ) { + results.add( result ); } } } - return super.visitDeclared( t, parameterized ); + else { + // Also check whether the implemented interfaces are parameterized + for ( Type declaredSuperType : declared.getDirectSuperTypes() ) { + if ( Object.class.getName().equals( declaredSuperType.getFullyQualifiedName() ) ) { + continue; + } + ResolvedPair result = visitDeclared( parameterized, declaredSuperType ); + if ( result != super.DEFAULT_VALUE ) { + results.add( result ); + } + } + + for ( TypeMirror parameterizedSuper : types.directSupertypes( parameterized ) ) { + if ( isJavaLangObject( parameterizedSuper ) ) { + continue; + } + ResolvedPair result = visitDeclared( (DeclaredType) parameterizedSuper, declared ); + if ( result != super.DEFAULT_VALUE ) { + results.add( result ); + } + } + } + if ( results.isEmpty() ) { + return super.DEFAULT_VALUE; + } + else { + return results.stream().allMatch( results.get( 0 )::equals ) ? results.get( 0 ) : super.DEFAULT_VALUE; + } } + + private boolean isJavaLangObject(TypeMirror type) { + if ( type instanceof DeclaredType ) { + return ( (TypeElement) ( (DeclaredType) type ).asElement() ).getQualifiedName() + .contentEquals( Object.class.getName() ); + } + return false; + } + } + + /** + * Reflects any Resolved Pair, examples are + * T, String + * ? extends T, BigDecimal + * T[], Integer[] + */ + public static class ResolvedPair { + + public ResolvedPair(Type parameter, Type match) { + this.parameter = parameter; + this.match = match; + } + + /** + * parameter, e.g. T, ? extends T or T[] + */ + private Type parameter; + + /** + * match, e.g. String, BigDecimal, Integer[] + */ + private Type match; + + public Type getParameter() { + return parameter; + } + + public Type getMatch() { + return match; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + ResolvedPair that = (ResolvedPair) o; + return Objects.equals( parameter, that.parameter ) && Objects.equals( match, that.match ); + } + + @Override + public int hashCode() { + return Objects.hash( parameter ); + } + } + + /** + * Gets the boxed equivalent type if the type is primitive, int will return Integer + * + * @return boxed equivalent + */ + public Type getBoxedEquivalent() { + if ( boxedEquivalent != null ) { + return boxedEquivalent; + } + else if ( isPrimitive() ) { + boxedEquivalent = typeFactory.getType( typeUtils.boxedClass( (PrimitiveType) typeMirror ) ); + return boxedEquivalent; + } + return this; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 8d3d215c52..f8c67f740e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -613,7 +613,11 @@ else if ( typeMirror.getKind() == TypeKind.TYPEVAR ) { if ( typeVariableType.getUpperBound() != null ) { return typeVariableType.getUpperBound(); } - // Lowerbounds intentionally left out: Type variables otherwise have a lower bound of NullType. + // lower bounds ( T super Number ) cannot be used for argument parameters, but can be used for + // method parameters: e.g. T map (T in); + if ( typeVariableType.getLowerBound() != null ) { + return typeVariableType.getLowerBound(); + } } return typeMirror; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 2039aa86aa..8a38ed2acb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -199,4 +199,11 @@ default Type getMappingSourceType() { * @return the short name for error messages when verbose, full name when not */ String describe(); + + /** + * Returns the formal type parameters of this method in declaration order. + * + * @return the formal type parameters, or an empty list if there are none + */ + List getTypeParameters(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index ea3f720440..136828adfc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -5,25 +5,19 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; -import javax.lang.model.element.TypeElement; -import javax.lang.model.element.TypeParameterElement; -import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.PrimitiveType; -import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import javax.lang.model.type.TypeVariable; -import javax.lang.model.type.WildcardType; -import javax.lang.model.util.SimpleTypeVisitor6; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.TypeUtils; /** * SourceMethodMatcher $8.4 of the JavaLanguage specification describes a method body as such: @@ -66,362 +60,348 @@ public class MethodMatcher { * Whether the given source and target types are matched by this matcher's candidate method. * * @param sourceTypes the source types - * @param resultType the target type + * @param targetType the target type * @return {@code true} when both, source type and target types match the signature of this matcher's method; * {@code false} otherwise. */ - boolean matches(List sourceTypes, Type resultType) { - - // check & collect generic types. - Map genericTypesMap = new HashMap<>(); + boolean matches(List sourceTypes, Type targetType) { - if ( candidateMethod.getParameters().size() == sourceTypes.size() ) { - int i = 0; - for ( Parameter candidateParam : candidateMethod.getParameters() ) { - Type sourceType = sourceTypes.get( i++ ); - if ( sourceType == null - || !matchSourceType( sourceType, candidateParam.getType(), genericTypesMap ) ) { - return false; - } - } - } - else { + GenericAnalyser analyser = + new GenericAnalyser( typeFactory, typeUtils, candidateMethod, sourceTypes, targetType ); + if ( !analyser.lineUp() ) { return false; } - // check if the method matches the proper result type to construct - Parameter targetTypeParameter = candidateMethod.getTargetTypeParameter(); - if ( targetTypeParameter != null ) { - Type returnClassType = typeFactory.classTypeOf( resultType ); - if ( !matchSourceType( returnClassType, targetTypeParameter.getType(), genericTypesMap ) ) { + for ( int i = 0; i < sourceTypes.size(); i++ ) { + Type candidateSourceParType = analyser.candidateParTypes.get( i ); + if ( !sourceTypes.get( i ).isAssignableTo( candidateSourceParType ) + || isPrimitiveToObject( sourceTypes.get( i ), candidateSourceParType ) ) { return false; } } + // TODO: TargetType checking should not be part of method selection, it should be in checking the annotation + // (the relation target / target type, target type being a class) - // check result type - if ( !matchResultType( resultType, genericTypesMap ) ) { - return false; - } - - // check if all type parameters are indeed mapped - if ( candidateMethod.getExecutable().getTypeParameters().size() != genericTypesMap.size() ) { - return false; - } - - // check if all entries are in the bounds - for ( Map.Entry entry : genericTypesMap.entrySet() ) { - if ( !isWithinBounds( entry.getValue(), getTypeParamFromCandidate( entry.getKey() ) ) ) { - // checks if the found Type is in bounds of the TypeParameters bounds. + if ( !analyser.candidateReturnType.isVoid() ) { + if ( !( analyser.candidateReturnType.isAssignableTo( targetType ) ) ) { return false; } } + return true; } - private boolean matchSourceType(Type sourceType, - Type candidateSourceType, - Map genericTypesMap) { - - if ( !isJavaLangObject( candidateSourceType.getTypeMirror() ) ) { - TypeMatcher parameterMatcher = new TypeMatcher( Assignability.VISITED_ASSIGNABLE_FROM, genericTypesMap ); - if ( !parameterMatcher.visit( candidateSourceType.getTypeMirror(), sourceType.getTypeMirror() ) ) { - if ( sourceType.isPrimitive() ) { - // the candidate source is primitive, so promote to its boxed type and check again (autobox) - TypeMirror boxedType = typeUtils.boxedClass( (PrimitiveType) sourceType.getTypeMirror() ).asType(); - if ( !parameterMatcher.visit( candidateSourceType.getTypeMirror(), boxedType ) ) { - return false; - } - } - else { - // NOTE: unboxing is deliberately not considered here. This should be handled via type-conversion - // (for NPE safety). - return false; - } - } + /** + * Primitive to Object (Boxed Type) should be handled by a type conversion rather than a direct mapping + * Direct mapping runs the risk of null pointer exceptions: e.g. in the assignment of Integer to int, Integer + * can be null. + * + * @param type the type to be assigned + * @param isAssignableTo the type to which @param type should be assignable to + * @return true if isAssignable is a primitive type and type is an object + */ + private boolean isPrimitiveToObject( Type type, Type isAssignableTo ) { + if ( isAssignableTo.isPrimitive() ) { + return !type.isPrimitive(); } - return true; + return false; } - private boolean matchResultType(Type resultType, Map genericTypesMap) { + private static class GenericAnalyser { + + private TypeFactory typeFactory; + private TypeUtils typeUtils; + private Method candidateMethod; + private List sourceTypes; + private Type targetType; + + GenericAnalyser(TypeFactory typeFactory, TypeUtils typeUtils, Method candidateMethod, + List sourceTypes, Type targetType) { + this.typeFactory = typeFactory; + this.typeUtils = typeUtils; + this.candidateMethod = candidateMethod; + this.sourceTypes = sourceTypes; + this.targetType = targetType; + } - Type candidateResultType = candidateMethod.getResultType(); + Type candidateReturnType = null; + List candidateParTypes; - if ( !isJavaLangObject( candidateResultType.getTypeMirror() ) && !candidateResultType.isVoid() ) { + private boolean lineUp() { - final Assignability visitedAssignability; - if ( candidateMethod.getReturnType().isVoid() ) { - // for void-methods, the result-type of the candidate needs to be assignable from the given result type - visitedAssignability = Assignability.VISITED_ASSIGNABLE_FROM; - } - else { - // for non-void methods, the result-type of the candidate needs to be assignable to the given result - // type - visitedAssignability = Assignability.VISITED_ASSIGNABLE_TO; + if ( candidateMethod.getParameters().size() != sourceTypes.size() ) { + return false; } - TypeMatcher returnTypeMatcher = new TypeMatcher( visitedAssignability, genericTypesMap ); - if ( !returnTypeMatcher.visit( candidateResultType.getTypeMirror(), resultType.getTypeMirror() ) ) { - if ( resultType.isPrimitive() ) { - TypeMirror boxedType = typeUtils.boxedClass( (PrimitiveType) resultType.getTypeMirror() ).asType(); - TypeMatcher boxedReturnTypeMatcher = - new TypeMatcher( visitedAssignability, genericTypesMap ); + if ( !candidateMethod.getTypeParameters().isEmpty() ) { - if ( !boxedReturnTypeMatcher.visit( candidateResultType.getTypeMirror(), boxedType ) ) { - return false; + this.candidateParTypes = new ArrayList<>(); + + // Per generic method parameter the associated type variable candidates + Map methodParCandidates = new HashMap<>(); + + // Get candidates + boolean success = getCandidates( methodParCandidates ); + if ( !success ) { + return false; + } + + // Check type bounds + boolean withinBounds = candidatesWithinBounds( methodParCandidates ); + if ( !withinBounds ) { + return false; + } + + // Represent result as map. + Map resolvedPairs = new HashMap<>(); + for ( TypeVarCandidate candidate : methodParCandidates.values() ) { + for ( Type.ResolvedPair pair : candidate.pairs) { + resolvedPairs.put( pair.getParameter(), pair.getMatch() ); } } - else if ( candidateResultType.getTypeMirror().getKind().isPrimitive() ) { - TypeMirror boxedCandidateReturnType = - typeUtils.boxedClass( (PrimitiveType) candidateResultType.getTypeMirror() ).asType(); - TypeMatcher boxedReturnTypeMatcher = - new TypeMatcher( visitedAssignability, genericTypesMap ); - if ( !boxedReturnTypeMatcher.visit( boxedCandidateReturnType, resultType.getTypeMirror() ) ) { + // Resolve parameters and return type by using the found candidates + int nrOfMethodPars = candidateMethod.getParameters().size(); + for ( int i = 0; i < nrOfMethodPars; i++ ) { + Type candidateType = resolve( candidateMethod.getParameters().get( i ).getType(), resolvedPairs ); + if ( candidateType == null ) { return false; } + this.candidateParTypes.add( candidateType ); } + if ( !candidateMethod.getReturnType().isVoid() ) { + this.candidateReturnType = resolve( candidateMethod.getReturnType(), resolvedPairs ); + if ( this.candidateReturnType == null ) { + return false; + } + } else { - return false; + this.candidateReturnType = candidateMethod.getReturnType(); } } + else { + this.candidateParTypes = candidateMethod.getParameters().stream() + .map( Parameter::getType ) + .collect( Collectors.toList() ); + this.candidateReturnType = candidateMethod.getReturnType(); + } + return true; } - return true; - } - - /** - * @param type the type - * @return {@code true}, if the type represents java.lang.Object - */ - private boolean isJavaLangObject(TypeMirror type) { - return type.getKind() == TypeKind.DECLARED - && ( (TypeElement) ( (DeclaredType) type ).asElement() ).getQualifiedName().contentEquals( - Object.class.getName() ); - } - - private enum Assignability { - VISITED_ASSIGNABLE_FROM, VISITED_ASSIGNABLE_TO; - Assignability invert() { - return this == VISITED_ASSIGNABLE_FROM - ? VISITED_ASSIGNABLE_TO - : VISITED_ASSIGNABLE_FROM; + /** + * {@code T map( U in ) } + * + * Resolves all method generic parameter candidates + * + * @param methodParCandidates Map, keyed by the method generic parameter (T, U extends Number), with their + * respective candidates + * + * @return false no match or conflict has been found * + */ + boolean getCandidates( Map methodParCandidates) { + + int nrOfMethodPars = candidateMethod.getParameters().size(); + Type returnType = candidateMethod.getReturnType(); + + for ( int i = 0; i < nrOfMethodPars; i++ ) { + Type sourceType = sourceTypes.get( i ); + Parameter par = candidateMethod.getParameters().get( i ); + Type parType = par.getType(); + boolean success = getCandidates( parType, sourceType, methodParCandidates ); + if ( !success ) { + return false; + } + } + if ( !returnType.isVoid() ) { + boolean success = getCandidates( returnType, targetType, methodParCandidates ); + if ( !success ) { + return false; + } + } + return true; } - } - private class TypeMatcher extends SimpleTypeVisitor6 { - private final Assignability assignability; - private final Map genericTypesMap; - private final TypeMatcher inverse; - - TypeMatcher(Assignability assignability, Map genericTypesMap) { - super( Boolean.FALSE ); // default value - this.assignability = assignability; - this.genericTypesMap = genericTypesMap; - this.inverse = new TypeMatcher( this, genericTypesMap ); - } + /** + * @param aCandidateMethodType parameter type or return type from candidate method + * @param matchingType source type / target type to match + * @param candidates Map, keyed by the method generic parameter, with the candidates + * + * @return false no match or conflict has been found + */ + boolean getCandidates(Type aCandidateMethodType, Type matchingType, Map candidates ) { + + if ( !( aCandidateMethodType.isTypeVar() + || aCandidateMethodType.isArrayTypeVar() + || aCandidateMethodType.isWildCardBoundByTypeVar() + || hasGenericTypeParameters( aCandidateMethodType ) ) ) { + // the typeFromCandidateMethod is not a generic (parameterized) type + return true; + } - TypeMatcher(TypeMatcher inverse, Map genericTypesMap) { - super( Boolean.FALSE ); // default value - this.assignability = inverse.assignability.invert(); - this.genericTypesMap = genericTypesMap; - this.inverse = inverse; - } + for ( Type mthdParType : candidateMethod.getTypeParameters() ) { - @Override - public Boolean visitPrimitive(PrimitiveType t, TypeMirror p) { - return typeUtils.isSameType( t, p ); - } + // typeFromCandidateMethod itself is a generic type, e.g. String method( T par ); + // typeFromCandidateMethod is a generic arrayType e.g. String method( T[] par ); + // typeFromCandidateMethod is embedded in another type e.g. String method( Callable par ); + // typeFromCandidateMethod is a wildcard, bounded by a typeVar + // e.g. String method( List in ) - @Override - public Boolean visitArray(ArrayType t, TypeMirror p) { + Type.ResolvedPair resolved = mthdParType.resolveParameterToType( matchingType, aCandidateMethodType ); + if ( resolved == null ) { + // cannot find a candidate type, but should have since the typeFromCandidateMethod had parameters + // to be resolved + return !hasGenericTypeParameters( aCandidateMethodType ); + } - if ( p.getKind().equals( TypeKind.ARRAY ) ) { - return t.getComponentType().accept( this, ( (ArrayType) p ).getComponentType() ); - } - else { - return Boolean.FALSE; - } - } + // resolved something at this point, a candidate can be fetched or created + TypeVarCandidate typeVarCandidate; + if ( candidates.containsKey( mthdParType ) ) { + typeVarCandidate = candidates.get( mthdParType ); + } + else { + // add a new type + typeVarCandidate = new TypeVarCandidate( ); + candidates.put( mthdParType, typeVarCandidate ); + } - @Override - public Boolean visitDeclared(DeclaredType t, TypeMirror p) { - // its a match when: 1) same kind of type, name is equals, nr of type args are the same - // (type args are checked later). - if ( p.getKind() == TypeKind.DECLARED ) { - DeclaredType t1 = (DeclaredType) p; - if ( rawAssignabilityMatches( t, t1 ) ) { - if ( t.getTypeArguments().size() == t1.getTypeArguments().size() ) { - // compare type var side by side - for ( int i = 0; i < t.getTypeArguments().size(); i++ ) { - if ( !visit( t.getTypeArguments().get( i ), t1.getTypeArguments().get( i ) ) ) { - return Boolean.FALSE; - } + // check what we've resolved + if ( resolved.getParameter().isTypeVar() ) { + // it might be already set, but we just checked if its an equivalent type + if ( typeVarCandidate.match == null ) { + typeVarCandidate.match = resolved.getMatch(); + if ( typeVarCandidate.match == null) { + return false; } - return Boolean.TRUE; + typeVarCandidate.pairs.add( resolved ); } - else { - // return true (e.g. matching Enumeration with an enumeration E) - // but do not try to line up raw type arguments with types that do have arguments. - return assignability == Assignability.VISITED_ASSIGNABLE_TO ? - !t1.getTypeArguments().isEmpty() : !t.getTypeArguments().isEmpty(); + else if ( !areEquivalent( resolved.getMatch(), typeVarCandidate.match ) ) { + // type has been resolved twice, but with a different candidate (conflict) + return false; } + + } + else if ( resolved.getParameter().isArrayTypeVar() + && resolved.getParameter().getComponentType().isAssignableTo( mthdParType ) ) { + // e.g. T map( List in ), the match for T should be assignable + // to the parameter T extends Number + typeVarCandidate.pairs.add( resolved ); + } + else if ( resolved.getParameter().isWildCardBoundByTypeVar() + && resolved.getParameter().getTypeBound().isAssignableTo( mthdParType ) ) { + // e.g. T map( List in ), the match for ? super T should be assignable + // to the parameter T extends Number + typeVarCandidate.pairs.add( resolved ); } else { - return Boolean.FALSE; + // none of the above + return false; } } - else if ( p.getKind() == TypeKind.WILDCARD ) { - return inverse.visit( p, t ); // inverse, as we switch the params - } - else { - return Boolean.FALSE; - } + return true; } - private boolean rawAssignabilityMatches(DeclaredType t1, DeclaredType t2) { - if ( assignability == Assignability.VISITED_ASSIGNABLE_TO ) { - return typeUtils.isAssignable( toRawType( t1 ), toRawType( t2 ) ); - } - else { - return typeUtils.isAssignable( toRawType( t2 ), toRawType( t1 ) ); + /** + * Checks whether all found candidates are within the bounds of the method type var. For instance + * @ U map( T in ). Note that only the relation between the + * match for U and Callable are checked. Not the correct parameter. + * + * @param methodParCandidates + * + * @return true when all within bounds. + */ + private boolean candidatesWithinBounds(Map methodParCandidates ) { + for ( Map.Entry entry : methodParCandidates.entrySet() ) { + Type bound = entry.getKey().getTypeBound(); + if ( bound != null ) { + for ( Type.ResolvedPair pair : entry.getValue().pairs ) { + if ( entry.getKey().hasUpperBound() ) { + if ( !pair.getMatch().asRawType().isAssignableTo( bound.asRawType() ) ) { + return false; + } + } + else { + // lower bound + if ( !bound.asRawType().isAssignableTo( pair.getMatch().asRawType() ) ) { + return false; + } + } + } + } } + return true; } - private DeclaredType toRawType(DeclaredType t) { - return typeUtils.getDeclaredType( (TypeElement) t.asElement() ); - } - - @Override - public Boolean visitTypeVariable(TypeVariable t, TypeMirror p) { - if ( genericTypesMap.containsKey( t ) ) { - // when already found, the same mapping should apply - // Then we should visit the resolved generic type. - // Which can potentially be another generic type - // e.g. - // T fromOptional(Optional optional) - // T resolves to Collection - // We know what T resolves to, so we should treat it as if the method signature was - // Collection fromOptional(Optional optional) - TypeMirror p1 = genericTypesMap.get( t ); - // p (Integer) should be a subType of p1 (Number) - // i.e. you can assign p (Integer) to p1 (Number) - return visit( p, p1 ); - } - else { - // check if types are in bound - TypeMirror lowerBound = t.getLowerBound(); - TypeMirror upperBound = t.getUpperBound(); - if ( ( isNullType( lowerBound ) || typeUtils.isSubtypeErased( lowerBound, p ) ) - && ( isNullType( upperBound ) || typeUtils.isSubtypeErased( p, upperBound ) ) ) { - genericTypesMap.put( t, p ); - return Boolean.TRUE; + private boolean hasGenericTypeParameters(Type typeFromCandidateMethod) { + for ( Type typeParam : typeFromCandidateMethod.getTypeParameters() ) { + if ( typeParam.isTypeVar() || typeParam.isWildCardBoundByTypeVar() || typeParam.isArrayTypeVar() ) { + return true; } else { - return Boolean.FALSE; + if ( hasGenericTypeParameters( typeParam ) ) { + return true; + } } } + return false; } - private boolean isNullType(TypeMirror type) { - return type == null || type.getKind() == TypeKind.NULL; - } - - @Override - public Boolean visitWildcard(WildcardType t, TypeMirror p) { - - // check extends bound - TypeMirror extendsBound = t.getExtendsBound(); - if ( !isNullType( extendsBound ) ) { - switch ( extendsBound.getKind() ) { - case DECLARED: - // for example method: String method(? extends String) - // isSubType checks range [subtype, type], e.g. isSubtype [Object, String]==true - return visit( extendsBound, p ); - - case TYPEVAR: - // for example method: T method(? extends T) - // this can be done the directly by checking: ? extends String & Serializable - // this checks the part? - return isWithinBounds( p, getTypeParamFromCandidate( extendsBound ) ); - - default: - // does this situation occur? - return Boolean.FALSE; - } + private Type resolve( Type typeFromCandidateMethod, Map pairs ) { + if ( typeFromCandidateMethod.isTypeVar() || typeFromCandidateMethod.isArrayTypeVar() ) { + return pairs.get( typeFromCandidateMethod ); } - - // check super bound - TypeMirror superBound = t.getSuperBound(); - if ( !isNullType( superBound ) ) { - switch ( superBound.getKind() ) { - case DECLARED: - // for example method: String method(? super String) - // to check super type, we can simply inverse the argument, but that would initially yield - // a result: T method(? super T) - if ( !isWithinBounds( p, typeParameter ) ) { - // this checks the part? - return Boolean.FALSE; + else if ( hasGenericTypeParameters( typeFromCandidateMethod ) ) { + TypeMirror[] typeArgs = new TypeMirror[ typeFromCandidateMethod.getTypeParameters().size() ]; + for ( int i = 0; i < typeFromCandidateMethod.getTypeParameters().size(); i++ ) { + Type typeFromCandidateMethodTypeParameter = typeFromCandidateMethod.getTypeParameters().get( i ); + if ( hasGenericTypeParameters( typeFromCandidateMethodTypeParameter ) ) { + // nested type var, lets resolve some more (recur) + Type matchingType = resolve( typeFromCandidateMethodTypeParameter, pairs ); + if ( matchingType == null ) { + // something went wrong + return null; + } + typeArgs[i] = matchingType.getTypeMirror(); + } + else if ( typeFromCandidateMethodTypeParameter.isWildCardBoundByTypeVar() + || typeFromCandidateMethodTypeParameter.isTypeVar() + || typeFromCandidateMethodTypeParameter.isArrayTypeVar() + ) { + Type matchingType = pairs.get( typeFromCandidateMethodTypeParameter ); + if ( matchingType == null ) { + // something went wrong + return null; } - // now, it becomes a bit more hairy. We have the relation (? super T). From T we know that - // it is a subclass of String & Serializable. However, The Java Language Secification, - // Chapter 4.4, states that a bound is either: 'A type variable-', 'A class-' or 'An - // interface-' type followed by further interface types. So we must compare with the first - // argument in the Expression String & Serializable & ..., so, in this case String. - // to check super type, we can simply inverse the argument, but that would initially yield - // a result: ), String is not a type var + typeArgs[i] = typeFromCandidateMethodTypeParameter.getTypeMirror(); + } } + DeclaredType typeArg = typeUtils.getDeclaredType( typeFromCandidateMethod.getTypeElement(), typeArgs ); + return typeFactory.getType( typeArg ); + } + else { + // its not a type var or generic parameterized (e.g. just a plain type) + return typeFromCandidateMethod; } - return Boolean.TRUE; } - } - - /** - * Looks through the list of type parameters of the candidate method for a match - * - * @param t type parameter to match - * - * @return matching type parameter - */ - private TypeParameterElement getTypeParamFromCandidate(TypeMirror t) { - for ( TypeParameterElement candidateTypeParam : candidateMethod.getExecutable().getTypeParameters() ) { - if ( typeUtils.isSameType( candidateTypeParam.asType(), t ) ) { - return candidateTypeParam; + boolean areEquivalent( Type a, Type b ) { + if ( a == null || b == null ) { + return false; } + return a.getBoxedEquivalent().equals( b.getBoxedEquivalent() ); } - return null; } - /** - * checks whether a type t is in bounds of the typeParameter tpe - * - * @return true if within bounds - */ - private boolean isWithinBounds(TypeMirror t, TypeParameterElement tpe) { - List bounds = tpe != null ? tpe.getBounds() : null; - if ( t != null && bounds != null ) { - for ( TypeMirror bound : bounds ) { - if ( !( bound.getKind() == TypeKind.DECLARED && typeUtils.isSubtypeErased( t, bound ) ) ) { - return false; - } - } - return true; - } - return false; + private static class TypeVarCandidate { + + private Type match; + private List pairs = new ArrayList<>(); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index bac1346d97..83898d4b38 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import org.mapstruct.ap.internal.util.TypeUtils; @@ -56,6 +57,7 @@ public class SourceMethod implements Method { private final List sourceParameters; private final List contextParameters; private final ParameterProvidedMethods contextProvidedMethods; + private final List typeParameters; private List parameterNames; @@ -89,6 +91,8 @@ public static class Builder { private List valueMappings; private EnumMappingOptions enumMappingOptions; private ParameterProvidedMethods contextProvidedMethods; + private List typeParameters; + private boolean verboseLogging; public Builder setDeclaringMapper(Type declaringMapper) { @@ -197,6 +201,12 @@ public SourceMethod build() { valueMappings ); + this.typeParameters = this.executable.getTypeParameters() + .stream() + .map( Element::asType ) + .map( typeFactory::getType ) + .collect( Collectors.toList() ); + return new SourceMethod( this, mappingMethodOptions ); } } @@ -214,6 +224,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); this.contextProvidedMethods = builder.contextProvidedMethods; + this.typeParameters = builder.typeParameters; this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); @@ -533,6 +544,11 @@ public boolean hasObjectFactoryAnnotation() { return hasObjectFactoryAnnotation; } + @Override + public List getTypeParameters() { + return this.typeParameters; + } + @Override public String describe() { if ( verboseLogging ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index 7854534ed6..e54a8ea4b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -67,7 +67,7 @@ public boolean matches(List sourceTypes, Type targetType) { Type sourceType = first( sourceTypes ); - Type returnType = getReturnType().resolveTypeVarToType( sourceType, getParameter().getType() ); + Type returnType = getReturnType().resolveParameterToType( sourceType, getParameter().getType() ).getMatch(); if ( returnType == null ) { return false; } @@ -151,6 +151,11 @@ public String getContextParameter(ConversionContext conversionContext) { return null; } + @Override + public List getTypeParameters() { + return Collections.emptyList(); + } + /** * hashCode based on class * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index be729220ce..0e24774025 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -30,9 +30,11 @@ public class CreateOrUpdateSelector implements MethodSelector { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { if ( criteria.isLifecycleCallbackRequired() || criteria.isObjectFactoryRequired() ) { return methods; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java index 4e52731225..41d37e8b69 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java @@ -22,10 +22,10 @@ public class FactoryParameterSelector implements MethodSelector { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - ListsourceTypes, - Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, Type returnType, + SelectionCriteria criteria) { if ( !criteria.isObjectFactoryRequired() || methods.size() <= 1 ) { return methods; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index 3866857bbe..a624c1accb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -23,10 +23,10 @@ public class InheritanceSelector implements MethodSelector { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, Type returnType, + SelectionCriteria criteria) { if ( sourceTypes.size() != 1 ) { return methods; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index c4a029da90..7e7925ca0e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -21,9 +21,11 @@ public class MethodFamilySelector implements MethodSelector { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type targetType, SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { List> result = new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java index 587a37a7fe..86d35bb3aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java @@ -26,12 +26,15 @@ interface MethodSelector { * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out * @param candidates list of available methods * @param sourceTypes parameter type(s) that should be matched - * @param targetType result type that should be matched + * @param mappingTargetType mappingTargetType that should be matched + * @param returnType return type that should be matched * @param criteria criteria used in the selection process * @return list of methods that passes the matching process */ List> getMatchingMethods(Method mappingMethod, - List> candidates, - List sourceTypes, - Type targetType, SelectionCriteria criteria); + List> candidates, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 74fedcb75d..b88de4f225 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -8,13 +8,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.TypeUtils; /** * Applies all known {@link MethodSelector}s in order. @@ -45,13 +45,17 @@ public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFacto * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out * @param methods list of available methods * @param sourceTypes parameter type(s) that should be matched - * @param targetType return type that should be matched + * @param mappingTargetType the mapping target type that should be matched + * @param returnType return type that should be matched * @param criteria criteria used in the selection process * @return list of methods that passes the matching process */ - public List> getMatchingMethods(Method mappingMethod, List methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + public List> getMatchingMethods(Method mappingMethod, + List methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { List> candidates = new ArrayList<>( methods.size() ); for ( T method : methods ) { @@ -63,7 +67,8 @@ public List> getMatchingMethods(Method mapp mappingMethod, candidates, sourceTypes, - targetType, + mappingTargetType, + returnType, criteria ); } return candidates; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index bca471f9c0..210e462e3e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -50,9 +50,11 @@ public QualifierSelector(TypeUtils typeUtils, ElementUtils elementUtils ) { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { int numberOfQualifiersToMatch = 0; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index ad1a5d47b5..38a907aedb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -32,9 +32,11 @@ public TargetTypeSelector( TypeUtils typeUtils ) { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { TypeMirror qualifyingTypeMirror = criteria.getQualifyingResultType(); if ( qualifyingTypeMirror != null && !criteria.isLifecycleCallbackRequired() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index c00a90760d..3d0bd4b9b4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -39,9 +39,11 @@ public TypeSelector(TypeFactory typeFactory, FormattingMessager messager) { @Override public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, Type targetType, - SelectionCriteria criteria) { + List> methods, + List sourceTypes, + Type mappingTargetType, + Type returnType, + SelectionCriteria criteria) { if ( methods.isEmpty() ) { return methods; @@ -54,12 +56,16 @@ public List> getMatchingMethods(Method mapp // if no source types are given, we have a factory or lifecycle method availableBindings = getAvailableParameterBindingsFromMethod( mappingMethod, - targetType, + mappingTargetType, criteria.getSourceRHS() ); } else { - availableBindings = getAvailableParameterBindingsFromSourceTypes( sourceTypes, targetType, mappingMethod ); + availableBindings = getAvailableParameterBindingsFromSourceTypes( + sourceTypes, + mappingTargetType, + mappingMethod + ); } for ( SelectedMethod method : methods ) { @@ -68,7 +74,7 @@ public List> getMatchingMethods(Method mapp if ( parameterBindingPermutations != null ) { SelectedMethod matchingMethod = - getMatchingParameterBinding( targetType, mappingMethod, method, parameterBindingPermutations ); + getMatchingParameterBinding( returnType, mappingMethod, method, parameterBindingPermutations ); if ( matchingMethod != null ) { result.add( matchingMethod ); @@ -143,7 +149,7 @@ else if ( pb.isTargetType() ) { } } - private SelectedMethod getMatchingParameterBinding(Type targetType, + private SelectedMethod getMatchingParameterBinding(Type returnType, Method mappingMethod, SelectedMethod selectedMethodInfo, List> parameterAssignmentVariants) { @@ -155,7 +161,7 @@ private SelectedMethod getMatchingParameterBinding(Type ta // remove all assignment variants that doesn't match the types from the method matchingParameterAssignmentVariants.removeIf( parameterAssignments -> - !selectedMethod.matches( extractTypes( parameterAssignments ), targetType ) + !selectedMethod.matches( extractTypes( parameterAssignments ), returnType ) ); if ( matchingParameterAssignmentVariants.isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index ecf6657991..7bdae0b771 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -46,7 +46,9 @@ public XmlElementDeclSelector(TypeUtils typeUtils) { @Override public List> getMatchingMethods(Method mappingMethod, List> methods, - List sourceTypes, Type targetType, + List sourceTypes, + Type mappingTargetType, + Type returnType, SelectionCriteria criteria) { List> nameMatches = new ArrayList<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 5985d735c2..b959a15dc0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -513,14 +513,14 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List List> getBestMatch(List methods, methods, singletonList( source ), target, + target, selectionCriteria ); } @@ -758,7 +759,7 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType) { attempt.selectionCriteria.setPreferUpdateMapping( false ); for ( T2 yCandidate : yMethods ) { Type ySourceType = yCandidate.getMappingSourceType(); - ySourceType = ySourceType.resolveTypeVarToType( targetType, yCandidate.getResultType() ); + ySourceType = ySourceType.resolveParameterToType( targetType, yCandidate.getResultType() ).getMatch(); Type yTargetType = yCandidate.getResultType(); if ( ySourceType == null || !yTargetType.isRawAssignableTo( targetType ) @@ -876,7 +877,7 @@ private ConversionMethod getBestMatch(Type sourceType, Type targetType) { for ( T yCandidate : methods ) { Type ySourceType = yCandidate.getMappingSourceType(); - ySourceType = ySourceType.resolveTypeVarToType( targetType, yCandidate.getResultType() ); + ySourceType = ySourceType.resolveParameterToType( targetType, yCandidate.getResultType() ).getMatch(); Type yTargetType = yCandidate.getResultType(); if ( ySourceType == null || !yTargetType.isRawAssignableTo( targetType ) @@ -993,7 +994,7 @@ private MethodConversion getBestMatch(Type sourceType, Type targetType) { for ( T xCandidate : methods ) { Type xTargetType = xCandidate.getReturnType(); Type xSourceType = xCandidate.getMappingSourceType(); - xTargetType = xTargetType.resolveTypeVarToType( sourceType, xSourceType ); + xTargetType = xTargetType.resolveParameterToType( sourceType, xSourceType ).getMatch(); if ( xTargetType == null || xCandidate.isUpdateMethod() || !sourceType.isRawAssignableTo( xSourceType ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java index ce01d99de8..380df67bd5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseTypeUtilsDecorator.java @@ -6,10 +6,49 @@ package org.mapstruct.ap.internal.util; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; +import javax.lang.model.type.WildcardType; +import javax.lang.model.util.Types; public class EclipseTypeUtilsDecorator extends AbstractTypeUtilsDecorator { + private final Types delegate; + EclipseTypeUtilsDecorator(ProcessingEnvironment processingEnv) { super( processingEnv ); + this.delegate = processingEnv.getTypeUtils(); + } + + @Override + public boolean contains(TypeMirror t1, TypeMirror t2) { + if ( TypeKind.TYPEVAR == t2.getKind() ) { + return containsType( t1, ( (TypeVariable) t2 ).getLowerBound() ); + } + else { + return containsType( t1, t2 ); + } } + + private boolean containsType(TypeMirror t1, TypeMirror t2) { + + boolean result = false; + if ( TypeKind.DECLARED == t2.getKind() ) { + if ( TypeKind.WILDCARD == t1.getKind() ) { + WildcardType wct = (WildcardType) t1; + if ( wct.getExtendsBound() != null ) { + result = isAssignable( t2, wct.getExtendsBound() ); + } + else if ( wct.getSuperBound() != null ) { + result = isAssignable( wct.getSuperBound(), t2 ); + } + else { + result = isAssignable( t2, wct ); + } + } + } + return result; + } + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl index 89b2279a6d..ee7d0b106f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/Type.ftl @@ -7,9 +7,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Type" --> <@compress single_line=true> - <#if wildCardExtendsBound> + <#if hasExtendsBound()> ? extends <@includeModel object=typeBound /> - <#elseif wildCardSuperBound> + <#elseif hasSuperBound()> ? super <@includeModel object=typeBound /> <#else> <#if ext.asVarArgs!false>${createReferenceName()?remove_ending("[]")}...<#else>${createReferenceName()}<#if (!ext.raw?? && typeParameters?size > 0) ><<#list typeParameters as typeParameter><@includeModel object=typeParameter /><#if typeParameter_has_next>, > diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java index 74f6923734..4b77eb2c34 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java @@ -20,8 +20,6 @@ Source2.class, Target.class, SourceEnum.class, - SourceTargetMapper.class, - TargetSourceMapper.class, BigDecimalWrapper.class, ValueWrapper.class }) @@ -30,6 +28,7 @@ public class Issue1482Test { @Test + @WithClasses( SourceTargetMapper.class ) public void testForward() { Source source = new Source(); @@ -45,6 +44,7 @@ public void testForward() { } @Test + @WithClasses( TargetSourceMapper.class ) public void testReverse() { Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java index d589927a19..401d0c42ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/TargetSourceMapper.java @@ -20,9 +20,9 @@ public abstract class TargetSourceMapper { @Mapping(target = "wrapper", source = "bigDecimal") abstract Source2 map(Target target); - protected > Enum map(String in, @TargetType Classclz ) { + protected > T map(String in, @TargetType Classclz ) { if ( clz.isAssignableFrom( SourceEnum.class )) { - return (Enum) SourceEnum.valueOf( in ); + return (T) SourceEnum.valueOf( in ); } return null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java index 1a07dd1f78..1782ebdb57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/SourceTargetMapper.java @@ -37,8 +37,6 @@ public abstract class SourceTargetMapper { @InheritConfiguration public abstract Target sourceToTargetTwoArg(Source source, @MappingTarget Target target); - public abstract Set integerSetToStringSet(Set integers); - @InheritInverseConfiguration public abstract Set stringSetToIntegerSet(Set strings); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 9d17f1725b..2e86c96055 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.selection.generics; +import static org.assertj.core.api.Assertions.assertThat; + import java.math.BigDecimal; import org.junit.Test; @@ -17,8 +19,6 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for the invocation of generic methods for mapping bean properties. * @@ -39,7 +39,6 @@ public void shouldApplyGenericTypeMapper() { // setup used types TypeB typeB = new TypeB(); - TypeC typeC = new TypeC(); // setup source Source source = new Source(); @@ -51,10 +50,7 @@ public void shouldApplyGenericTypeMapper() { source.setFooNested( new Wrapper<>( new Wrapper<>( new BigDecimal( 5 ) ) ) ); source.setFooUpperBoundCorrect( new UpperBoundWrapper<>( typeB ) ); source.setFooWildCardExtendsString( new WildCardExtendsWrapper<>( "test3" ) ); - source.setFooWildCardExtendsTypeCCorrect( new WildCardExtendsWrapper<>( typeC ) ); - source.setFooWildCardExtendsTypeBCorrect( new WildCardExtendsWrapper<>( typeB ) ); source.setFooWildCardSuperString( new WildCardSuperWrapper<>( "test4" ) ); - source.setFooWildCardExtendsMBTypeCCorrect( new WildCardExtendsMBWrapper<>( typeC ) ); source.setFooWildCardSuperTypeBCorrect( new WildCardSuperWrapper<>( typeB ) ); // define wrapper @@ -71,12 +67,8 @@ public void shouldApplyGenericTypeMapper() { assertThat( target.getFooNested() ).isEqualTo( new BigDecimal( 5 ) ); assertThat( target.getFooUpperBoundCorrect() ).isEqualTo( typeB ); assertThat( target.getFooWildCardExtendsString() ).isEqualTo( "test3" ); - assertThat( target.getFooWildCardExtendsTypeCCorrect() ).isEqualTo( typeC ); - assertThat( target.getFooWildCardExtendsTypeBCorrect() ).isEqualTo( typeB ); assertThat( target.getFooWildCardSuperString() ).isEqualTo( "test4" ); - assertThat( target.getFooWildCardExtendsMBTypeCCorrect() ).isEqualTo( typeC ); assertThat( target.getFooWildCardSuperTypeBCorrect() ).isEqualTo( typeB ); - } @Test @@ -140,20 +132,6 @@ public void shouldFailOnWildCardMultipleBounds() { public void shouldFailOnSuperBounds1() { } - @Test - @WithClasses({ ErroneousSource5.class, ErroneousTarget5.class, ErroneousSourceTargetMapper5.class }) - @ExpectedCompilationOutcome(value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = ErroneousSourceTargetMapper5.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 16, - message = "No target bean properties found: can't map property \"WildCardSuperWrapper " + - "fooWildCardSuperTypeCFailure\" to \"TypeC fooWildCardSuperTypeCFailure\". " + - "Consider to declare/implement a mapping method: \"TypeC map(WildCardSuperWrapper value)\".") - }) - public void shouldFailOnSuperBounds2() { - } - @Test @WithClasses({ ErroneousSource6.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java index 33b93473b1..4dcd033866 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericTypeMapper.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.selection.generics; -import java.io.Serializable; - public class GenericTypeMapper { public T getWrapped(Wrapper source) { @@ -53,7 +51,4 @@ public String getWildCardSupersString(WildCardSuperWrapper t) { return (String) t.getWrapped(); } - public T getWildCardExtendsMBType(WildCardExtendsMBWrapper t) { - return t.getWrapped(); - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java index ce99476501..28c724e9ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Source.java @@ -17,10 +17,7 @@ public class Source { private Wrapper> fooNested; private UpperBoundWrapper fooUpperBoundCorrect; private WildCardExtendsWrapper fooWildCardExtendsString; - private WildCardExtendsWrapper fooWildCardExtendsTypeCCorrect; - private WildCardExtendsWrapper fooWildCardExtendsTypeBCorrect; private WildCardSuperWrapper fooWildCardSuperString; - private WildCardExtendsMBWrapper fooWildCardExtendsMBTypeCCorrect; private WildCardSuperWrapper fooWildCardSuperTypeBCorrect; public Wrapper getFooInteger() { @@ -87,22 +84,6 @@ public void setFooWildCardExtendsString(WildCardExtendsWrapper fooWildCa this.fooWildCardExtendsString = fooWildCardExtendsString; } - public void setFooWildCardExtendsTypeCCorrect(WildCardExtendsWrapper fooWildCardExtendsTypeCCorrect) { - this.fooWildCardExtendsTypeCCorrect = fooWildCardExtendsTypeCCorrect; - } - - public WildCardExtendsWrapper getFooWildCardExtendsTypeCCorrect() { - return fooWildCardExtendsTypeCCorrect; - } - - public WildCardExtendsWrapper getFooWildCardExtendsTypeBCorrect() { - return fooWildCardExtendsTypeBCorrect; - } - - public void setFooWildCardExtendsTypeBCorrect(WildCardExtendsWrapper fooWildCardExtendsTypeBCorrect) { - this.fooWildCardExtendsTypeBCorrect = fooWildCardExtendsTypeBCorrect; - } - public WildCardSuperWrapper getFooWildCardSuperString() { return fooWildCardSuperString; } @@ -111,14 +92,6 @@ public void setFooWildCardSuperString(WildCardSuperWrapper fooWildCardSu this.fooWildCardSuperString = fooWildCardSuperString; } - public WildCardExtendsMBWrapper getFooWildCardExtendsMBTypeCCorrect() { - return fooWildCardExtendsMBTypeCCorrect; - } - - public void setFooWildCardExtendsMBTypeCCorrect(WildCardExtendsMBWrapper fooWildCardExtendsMBTypeCCorrect) { - this.fooWildCardExtendsMBTypeCCorrect = fooWildCardExtendsMBTypeCCorrect; - } - public WildCardSuperWrapper getFooWildCardSuperTypeBCorrect() { return fooWildCardSuperTypeBCorrect; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java index 85d672ca94..6169356743 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/Target.java @@ -17,10 +17,7 @@ public class Target { private BigDecimal fooNested; private TypeB fooUpperBoundCorrect; private String fooWildCardExtendsString; - private TypeC fooWildCardExtendsTypeCCorrect; - private TypeB fooWildCardExtendsTypeBCorrect; private String fooWildCardSuperString; - private TypeC fooWildCardExtendsMBTypeCCorrect; private TypeB fooWildCardSuperTypeBCorrect; public Integer getFooInteger() { @@ -87,22 +84,6 @@ public void setFooWildCardExtendsString(String fooWildCardExtendsString) { this.fooWildCardExtendsString = fooWildCardExtendsString; } - public TypeC getFooWildCardExtendsTypeCCorrect() { - return fooWildCardExtendsTypeCCorrect; - } - - public void setFooWildCardExtendsTypeCCorrect(TypeC fooWildCardExtendsTypeCCorrect) { - this.fooWildCardExtendsTypeCCorrect = fooWildCardExtendsTypeCCorrect; - } - - public TypeB getFooWildCardExtendsTypeBCorrect() { - return fooWildCardExtendsTypeBCorrect; - } - - public void setFooWildCardExtendsTypeBCorrect(TypeB fooWildCardExtendsTypeBCorrect) { - this.fooWildCardExtendsTypeBCorrect = fooWildCardExtendsTypeBCorrect; - } - public String getFooWildCardSuperString() { return fooWildCardSuperString; } @@ -111,14 +92,6 @@ public void setFooWildCardSuperString(String fooWildCardSuperString) { this.fooWildCardSuperString = fooWildCardSuperString; } - public TypeC getFooWildCardExtendsMBTypeCCorrect() { - return fooWildCardExtendsMBTypeCCorrect; - } - - public void setFooWildCardExtendsMBTypeCCorrect(TypeC fooWildCardExtendsMBTypeCCorrect) { - this.fooWildCardExtendsMBTypeCCorrect = fooWildCardExtendsMBTypeCCorrect; - } - public TypeB getFooWildCardSuperTypeBCorrect() { return fooWildCardSuperTypeBCorrect; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/BothParameterizedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/BothParameterizedMapper.java new file mode 100644 index 0000000000..1c0ddfdc57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/BothParameterizedMapper.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.array; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface BothParameterizedMapper { + + BothParameterizedMapper INSTANCE = Mappers.getMapper( BothParameterizedMapper.class ); + + Target sourceToTarget(Source source); + + default GenericTargetWrapper map(GenericSourceWrapper in ) { + return new GenericTargetWrapper<>( in.getWrapped() ); + } + + class Source { + + private final GenericSourceWrapper prop; + + public Source(GenericSourceWrapper prop) { + this.prop = prop; + } + + public GenericSourceWrapper getProp() { + return prop; + } + + } + + class Target { + + private GenericTargetWrapper prop; + + public GenericTargetWrapper getProp() { + return prop; + } + + public void setProp(GenericTargetWrapper prop) { + this.prop = prop; + } + } + + class GenericTargetWrapper { + private final T wrapped; + + public GenericTargetWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } + + class GenericSourceWrapper { + private final T wrapped; + + public GenericSourceWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java new file mode 100644 index 0000000000..0b6dbc1137 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.array; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class GenericArrayTest { + + @Test + @WithClasses( ReturnTypeIsTypeVarArrayMapper.class ) + public void testGenericReturnTypeVar() { + + ReturnTypeIsTypeVarArrayMapper.GenericWrapper wrapper = + new ReturnTypeIsTypeVarArrayMapper.GenericWrapper<>( "test" ); + ReturnTypeIsTypeVarArrayMapper.Source source = new ReturnTypeIsTypeVarArrayMapper.Source( wrapper ); + + ReturnTypeIsTypeVarArrayMapper.Target target = ReturnTypeIsTypeVarArrayMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).containsExactly( "test" ); + } + + @Test + @WithClasses( SourceTypeIsTypeVarArrayMapper.class ) + public void testGenericSourceTypeVar() { + + SourceTypeIsTypeVarArrayMapper.Source source = + new SourceTypeIsTypeVarArrayMapper.Source( new String[] { "test" } ); + SourceTypeIsTypeVarArrayMapper.Target target = SourceTypeIsTypeVarArrayMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getWrapped() ).isEqualTo( "test" ); + + } + + @Test + @WithClasses( BothParameterizedMapper.class ) + public void testBothParameterized() { + + BothParameterizedMapper.GenericSourceWrapper wrapper = + new BothParameterizedMapper.GenericSourceWrapper<>( new String[] { "test" } ); + BothParameterizedMapper.Source source = new BothParameterizedMapper.Source( wrapper ); + BothParameterizedMapper.Target target = BothParameterizedMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getWrapped() ).containsExactly( "test" ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/ReturnTypeIsTypeVarArrayMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/ReturnTypeIsTypeVarArrayMapper.java new file mode 100644 index 0000000000..76751f2cc8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/ReturnTypeIsTypeVarArrayMapper.java @@ -0,0 +1,71 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.array; + +import java.lang.reflect.Array; +import java.util.Collections; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ReturnTypeIsTypeVarArrayMapper { + + ReturnTypeIsTypeVarArrayMapper INSTANCE = Mappers.getMapper( ReturnTypeIsTypeVarArrayMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings( "unchecked" ) + default T[] map(GenericWrapper in) { + return Collections.singletonList( in.getWrapped() ) + .toArray( (T[]) Array.newInstance( in.getWrapped().getClass(), 1 ) ); + } + + class Source { + + private GenericWrapper prop; + + public Source(GenericWrapper prop) { + this.prop = prop; + } + + public GenericWrapper getProp() { + return prop; + } + + public void setProp(GenericWrapper prop) { + this.prop = prop; + } + } + + class Target { + + private String[] prop; + + public String[] getProp() { + return prop; + } + + public void setProp(String[] prop) { + this.prop = prop; + } + } + + class GenericWrapper { + private final T wrapped; + + public GenericWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/SourceTypeIsTypeVarArrayMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/SourceTypeIsTypeVarArrayMapper.java new file mode 100644 index 0000000000..4abeb4b59f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/SourceTypeIsTypeVarArrayMapper.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.array; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface SourceTypeIsTypeVarArrayMapper { + + SourceTypeIsTypeVarArrayMapper INSTANCE = Mappers.getMapper( SourceTypeIsTypeVarArrayMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings("unchecked") + default GenericWrapper map( T[] in ) { + if ( in.length > 0 ) { + return new GenericWrapper<>( in[0] ); + } + return null; + } + + class Source { + + private String[] prop; + + public Source(String[] prop) { + this.prop = prop; + } + + public String[] getProp() { + return prop; + } + + } + + class Target { + + private GenericWrapper prop; + + public GenericWrapper getProp() { + return prop; + } + + public void setProp(GenericWrapper prop) { + this.prop = prop; + } + } + + class GenericWrapper { + private final T wrapped; + + public GenericWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java new file mode 100644 index 0000000000..c181cfe0b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.bounds; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith( AnnotationProcessorTestRunner.class ) +public class BoundsTest { + + @Test + @WithClasses( SourceTypeIsBoundedTypeVarMapper.class ) + public void testGenericSourceTypeVar() { + + SourceTypeIsBoundedTypeVarMapper.Source source = new SourceTypeIsBoundedTypeVarMapper.Source( "5", "test" ); + SourceTypeIsBoundedTypeVarMapper.Target target = + SourceTypeIsBoundedTypeVarMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp1() ).isEqualTo( 5L ); + assertThat( target.getProp2().getProp() ).isEqualTo( "test" ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/SourceTypeIsBoundedTypeVarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/SourceTypeIsBoundedTypeVarMapper.java new file mode 100644 index 0000000000..4aa260a736 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/SourceTypeIsBoundedTypeVarMapper.java @@ -0,0 +1,87 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.bounds; + +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface SourceTypeIsBoundedTypeVarMapper { + + SourceTypeIsBoundedTypeVarMapper INSTANCE = Mappers.getMapper( SourceTypeIsBoundedTypeVarMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings( "unchecked" ) + default T map(String in, @TargetType Class clz) { + if ( clz == Nested.class ) { + return (T) new Nested( in ); + } + return null; + } + + class Source { + + private final String prop1; + private final String prop2; + + public Source(String prop1, String prop2) { + this.prop1 = prop1; + this.prop2 = prop2; + } + + public String getProp1() { + return prop1; + } + + public String getProp2() { + return prop2; + } + } + + class Target { + + private Long prop1; + private Nested prop2; + + public Long getProp1() { + return prop1; + } + + public void setProp1(Long prop1) { + this.prop1 = prop1; + } + + public Nested getProp2() { + return prop2; + } + + public void setProp2(Nested prop2) { + this.prop2 = prop2; + } + } + + class NestedBase { + } + + class Nested extends NestedBase { + + private String prop; + + public Nested(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java new file mode 100644 index 0000000000..b11162bb33 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java @@ -0,0 +1,73 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.multiple; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +import java.util.Collections; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith( AnnotationProcessorTestRunner.class) +public class MultipleTypeVarTest { + + @Test + @WithClasses( ReturnTypeHasMultipleTypeVarOneGenericMapper.class ) + public void testGenericSourceTypeVarOneGeneric() { + + ReturnTypeHasMultipleTypeVarOneGenericMapper.Source src = + new ReturnTypeHasMultipleTypeVarOneGenericMapper.Source( 5L ); + ReturnTypeHasMultipleTypeVarOneGenericMapper.Target target = + ReturnTypeHasMultipleTypeVarOneGenericMapper.INSTANCE.toTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp() ).containsExactly( entry( "test", 5L ) ); + } + + @Test + @WithClasses( ReturnTypeHasMultipleTypeVarBothGenericMapper.class ) + public void testGenericReturnTypeVarBothGeneric() { + + ReturnTypeHasMultipleTypeVarBothGenericMapper.Pair pair + = new ReturnTypeHasMultipleTypeVarBothGenericMapper.Pair( "test", 5L ); + ReturnTypeHasMultipleTypeVarBothGenericMapper.Source src = + new ReturnTypeHasMultipleTypeVarBothGenericMapper.Source( pair ); + ReturnTypeHasMultipleTypeVarBothGenericMapper.Target target = + ReturnTypeHasMultipleTypeVarBothGenericMapper.INSTANCE.toTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp() ).containsExactly( entry( "test", 5L ) ); + } + + @Test + @WithClasses( SourceTypeHasMultipleTypeVarBothGenericMapper.class ) + public void testGenericSourceTypeVarBothGeneric() { + + Map map = Collections.singletonMap( "test", 5L ); + SourceTypeHasMultipleTypeVarBothGenericMapper.Source src = + new SourceTypeHasMultipleTypeVarBothGenericMapper.Source( map ); + SourceTypeHasMultipleTypeVarBothGenericMapper.Target target = + SourceTypeHasMultipleTypeVarBothGenericMapper.INSTANCE.toTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getFirst() ).isEqualTo( "test" ); + assertThat( target.getProp().getSecond() ).isEqualTo( 5L ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarBothGenericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarBothGenericMapper.java new file mode 100644 index 0000000000..b31a190b60 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarBothGenericMapper.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.multiple; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ReturnTypeHasMultipleTypeVarBothGenericMapper { + + ReturnTypeHasMultipleTypeVarBothGenericMapper INSTANCE = + Mappers.getMapper( ReturnTypeHasMultipleTypeVarBothGenericMapper.class ); + + Target toTarget(Source source); + + default HashMap toMap( Pair entry) { + HashMap result = new HashMap<>( ); + result.put( entry.first, entry.second ); + return result; + } + + class Source { + + private Pair prop; + + public Source(Pair prop) { + this.prop = prop; + } + + public Pair getProp() { + return prop; + } + } + + class Target { + + private Map prop; + + public Map getProp() { + return prop; + } + + public Target setProp(Map prop) { + this.prop = prop; + return this; + } + } + + class Pair { + private final T first; + private final U second; + + public Pair(T first, U second) { + this.first = first; + this.second = second; + } + + public T getFirst() { + return first; + } + + public U getSecond() { + return second; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarOneGenericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarOneGenericMapper.java new file mode 100644 index 0000000000..f22741a87f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarOneGenericMapper.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.multiple; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ReturnTypeHasMultipleTypeVarOneGenericMapper { + + ReturnTypeHasMultipleTypeVarOneGenericMapper INSTANCE = + Mappers.getMapper( ReturnTypeHasMultipleTypeVarOneGenericMapper.class ); + + Target toTarget(Source source); + + default HashMap toMap( T entry) { + HashMap result = new HashMap<>( ); + result.put( "test", entry ); + return result; + } + + class Source { + + private Long prop; + + public Source(Long prop) { + this.prop = prop; + } + + public Long getProp() { + return prop; + } + } + + class Target { + + private Map prop; + + public Map getProp() { + return prop; + } + + public Target setProp(Map prop) { + this.prop = prop; + return this; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/SourceTypeHasMultipleTypeVarBothGenericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/SourceTypeHasMultipleTypeVarBothGenericMapper.java new file mode 100644 index 0000000000..09c427fd05 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/SourceTypeHasMultipleTypeVarBothGenericMapper.java @@ -0,0 +1,86 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.multiple; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface SourceTypeHasMultipleTypeVarBothGenericMapper { + + SourceTypeHasMultipleTypeVarBothGenericMapper INSTANCE = + Mappers.getMapper( SourceTypeHasMultipleTypeVarBothGenericMapper.class ); + + Target toTarget(Source source); + + default HashMap toMap( Pair entry) { + HashMap result = new HashMap<>( ); + result.put( entry.first, entry.second ); + return result; + } + + default Pair toPair( Map map) { + if ( !map.isEmpty() ) { + Map.Entry firstEntry = map.entrySet().iterator().next(); + return new Pair<>( firstEntry.getKey(), firstEntry.getValue() ); + } + return null; + } + + class Source { + + private final Map prop; + + public Source(Map prop) { + this.prop = prop; + } + + public Map getProp() { + return prop; + } + + } + + class Target { + + private Pair prop; + + public Target(Pair prop) { + this.prop = prop; + } + + public Pair getProp() { + return prop; + } + } + + class Pair { + + private final T first; + private final U second; + + public Pair(T first, U second) { + this.first = first; + this.second = second; + } + + public T getFirst() { + return first; + } + + public U getSecond() { + return second; + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java new file mode 100644 index 0000000000..c177fb45e8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.nestedgenerics; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith( AnnotationProcessorTestRunner.class) +public class NestedGenericsTest { + + @Test + @WithClasses( ReturnTypeHasNestedTypeVarMapper.class ) + public void testGenericReturnTypeVar() { + + ReturnTypeHasNestedTypeVarMapper.Source source = new ReturnTypeHasNestedTypeVarMapper.Source("test" ); + ReturnTypeHasNestedTypeVarMapper.Target target = ReturnTypeHasNestedTypeVarMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).hasSize( 1 ); + assertThat( target.getProp().get( 0 ) ).contains( "test" ); + } + + @Test + @WithClasses( SourceTypeHasNestedTypeVarMapper.class ) + public void testGenericSourceTypeVar() { + + SourceTypeHasNestedTypeVarMapper.Source src = + new SourceTypeHasNestedTypeVarMapper.Source( Collections.singletonList( Collections.singleton( "test" ) ) ); + SourceTypeHasNestedTypeVarMapper.Target target = SourceTypeHasNestedTypeVarMapper.INSTANCE.toTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( "test" ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/ReturnTypeHasNestedTypeVarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/ReturnTypeHasNestedTypeVarMapper.java new file mode 100644 index 0000000000..891058d885 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/ReturnTypeHasNestedTypeVarMapper.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.nestedgenerics; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ReturnTypeHasNestedTypeVarMapper { + + ReturnTypeHasNestedTypeVarMapper INSTANCE = Mappers.getMapper( ReturnTypeHasNestedTypeVarMapper.class ); + + Target toTarget(Source source); + + default List> wrapAsSetInList(T entry) { + return Collections.singletonList( Collections.singleton( entry ) ); + } + + class Source { + + private final String prop; + + public Source(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + + } + + class Target { + + private List> prop; + + public List> getProp() { + return prop; + } + + public Target setProp(List> prop) { + this.prop = prop; + return this; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/SourceTypeHasNestedTypeVarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/SourceTypeHasNestedTypeVarMapper.java new file mode 100644 index 0000000000..faeb5fe935 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/SourceTypeHasNestedTypeVarMapper.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.nestedgenerics; + +import java.util.List; +import java.util.Set; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface SourceTypeHasNestedTypeVarMapper { + + SourceTypeHasNestedTypeVarMapper INSTANCE = Mappers.getMapper( SourceTypeHasNestedTypeVarMapper.class ); + + Target toTarget(Source source); + + default T unwrapToOneElement(List> listOfSet) { + if ( !listOfSet.isEmpty() && listOfSet.get( 0 ).iterator().hasNext() ) { + return listOfSet.get( 0 ).iterator().next(); + } + return null; + } + + class Source { + + private final List> prop; + + public Source(List> prop) { + this.prop = prop; + } + + public List> getProp() { + return prop; + } + + } + + class Target { + + private String prop; + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/BothParameterizedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/BothParameterizedMapper.java new file mode 100644 index 0000000000..16b09a2749 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/BothParameterizedMapper.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.plain; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface BothParameterizedMapper { + + BothParameterizedMapper INSTANCE = Mappers.getMapper( BothParameterizedMapper.class ); + + Target sourceToTarget(Source source); + + default GenericTargetWrapper map(GenericSourceWrapper in ) { + return new GenericTargetWrapper<>( in.getWrapped() ); + } + + class Source { + + private final GenericSourceWrapper prop; + + public Source(GenericSourceWrapper prop) { + this.prop = prop; + } + + public GenericSourceWrapper getProp() { + return prop; + } + + } + + class Target { + + private GenericTargetWrapper prop; + + public GenericTargetWrapper getProp() { + return prop; + } + + public void setProp(GenericTargetWrapper prop) { + this.prop = prop; + } + } + + class GenericTargetWrapper { + private final T wrapped; + + public GenericTargetWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } + + class GenericSourceWrapper { + private final T wrapped; + + public GenericSourceWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java new file mode 100644 index 0000000000..8f7c878810 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.plain; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class PlainTest { + + @Test + @WithClasses( ReturnTypeIsTypeVarMapper.class ) + public void testGenericReturnTypeVar() { + + ReturnTypeIsTypeVarMapper.Source source = + new ReturnTypeIsTypeVarMapper.Source( new ReturnTypeIsTypeVarMapper.GenericWrapper<>( "test" ) ); + ReturnTypeIsTypeVarMapper.Target target = ReturnTypeIsTypeVarMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( "test" ); + } + + @Test + @WithClasses( SourceTypeIsTypeVarMapper.class ) + public void testGenericSourceTypeVar() { + + SourceTypeIsTypeVarMapper.Source source = new SourceTypeIsTypeVarMapper.Source( "test" ); + SourceTypeIsTypeVarMapper.Target target = SourceTypeIsTypeVarMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getWrapped() ).isEqualTo( "test" ); + + } + + @Test + @WithClasses( BothParameterizedMapper.class ) + public void testBothParameterized() { + + BothParameterizedMapper.Source source = + new BothParameterizedMapper.Source( new BothParameterizedMapper.GenericSourceWrapper<>( "test" ) ); + BothParameterizedMapper.Target target = BothParameterizedMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getWrapped() ).isEqualTo( "test" ); + + } + + @Test + @WithClasses( ReturnTypeIsRawTypeMapper.class ) + public void testRaw() { + + ReturnTypeIsRawTypeMapper.Source source = new ReturnTypeIsRawTypeMapper.Source( Collections.singleton( 5 ) ); + + ReturnTypeIsRawTypeMapper.Target target = ReturnTypeIsRawTypeMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().iterator().next() ).isEqualTo( "5" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsRawTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsRawTypeMapper.java new file mode 100644 index 0000000000..24af41648c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsRawTypeMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.plain; + +import java.util.Set; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ReturnTypeIsRawTypeMapper { + + ReturnTypeIsRawTypeMapper INSTANCE = Mappers.getMapper( ReturnTypeIsRawTypeMapper.class ); + + Target sourceToTarget(Source source); + + Set selectMe(Set integers); + + Set doNotSelectMe(Set strings); + + class Source { + + private final Set prop; + + public Source(Set prop) { + this.prop = prop; + } + + public Set getProp() { + return prop; + } + } + + class Target { + + private Set prop; + + public Set getProp() { + return prop; + } + + public Target setProp(Set prop) { + this.prop = prop; + return this; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsTypeVarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsTypeVarMapper.java new file mode 100644 index 0000000000..137f00ca62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/ReturnTypeIsTypeVarMapper.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.plain; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface ReturnTypeIsTypeVarMapper { + + ReturnTypeIsTypeVarMapper INSTANCE = Mappers.getMapper( ReturnTypeIsTypeVarMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings("unchecked") + default T map(GenericWrapper in) { + return in.getWrapped(); + } + + class Source { + + private final GenericWrapper prop; + + public Source(GenericWrapper prop) { + this.prop = prop; + } + + public GenericWrapper getProp() { + return prop; + } + + } + + class Target { + + private String prop; + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } + + class GenericWrapper { + private final T wrapped; + + public GenericWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/SourceTypeIsTypeVarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/SourceTypeIsTypeVarMapper.java new file mode 100644 index 0000000000..3f2c2a50ce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/SourceTypeIsTypeVarMapper.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.plain; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface SourceTypeIsTypeVarMapper { + + SourceTypeIsTypeVarMapper INSTANCE = Mappers.getMapper( SourceTypeIsTypeVarMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings("unchecked") + default GenericWrapper map( T in ) { + return new GenericWrapper<>( in ); + } + + class Source { + + private final String prop; + + public Source(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + } + + class Target { + + private GenericWrapper prop; + + public GenericWrapper getProp() { + return prop; + } + + public void setProp(GenericWrapper prop) { + this.prop = prop; + } + } + + class GenericWrapper { + private final T wrapped; + + public GenericWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/NestedTargetTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/NestedTargetTypeMapper.java new file mode 100644 index 0000000000..665683f653 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/NestedTargetTypeMapper.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.targettype; + +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface NestedTargetTypeMapper { + + NestedTargetTypeMapper INSTANCE = Mappers.getMapper( NestedTargetTypeMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings("unchecked") + default T map(String string, @TargetType Class clazz) { + if ( clazz == GenericWrapper.class ) { + return (T) new GenericWrapper<>( string ); + } + + return null; + } + + class Source { + + private String prop; + + public Source(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } + + class Target { + + private GenericWrapper prop; + + public GenericWrapper getProp() { + return prop; + } + + public void setProp(GenericWrapper prop) { + this.prop = prop; + } + } + + class BaseType { + } + + class GenericWrapper extends BaseType { + private final T wrapped; + + public GenericWrapper(T someType) { + this.wrapped = someType; + } + + public T getWrapped() { + return wrapped; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/PlainTargetTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/PlainTargetTypeMapper.java new file mode 100644 index 0000000000..15e27da824 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/PlainTargetTypeMapper.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.targettype; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper +public interface PlainTargetTypeMapper { + + PlainTargetTypeMapper INSTANCE = Mappers.getMapper( PlainTargetTypeMapper.class ); + + Target sourceToTarget(Source source); + + @SuppressWarnings("unchecked") + default T map(String string, @TargetType Class clazz) { + if ( clazz == BigDecimal.class ) { + return (T) new BigDecimal( string ); + } + + return null; + } + + class Source { + + private String prop; + + public Source(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } + + class Target { + + private BigDecimal prop; + + public BigDecimal getProp() { + return prop; + } + + public void setProp(BigDecimal prop) { + this.prop = prop; + } + } + + class BaseType { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java new file mode 100644 index 0000000000..47037ec6be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.targettype; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class TargetTypeTest { + + @Test + @WithClasses( PlainTargetTypeMapper.class ) + public void testPlain() { + + PlainTargetTypeMapper.Target target = + PlainTargetTypeMapper.INSTANCE.sourceToTarget( new PlainTargetTypeMapper.Source( "15" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp().toPlainString() ).isEqualTo( "15" ); + } + + @Test + @WithClasses( NestedTargetTypeMapper.class ) + public void testNestedTypeVar() { + NestedTargetTypeMapper.Target target = + NestedTargetTypeMapper.INSTANCE.sourceToTarget( new NestedTargetTypeMapper.Source( "test" ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getProp().getWrapped() ).isEqualTo( "test" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/IntersectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/IntersectionMapper.java new file mode 100644 index 0000000000..376acd0d57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/IntersectionMapper.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.wildcards; + +import java.io.Serializable; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface IntersectionMapper { + + IntersectionMapper INSTANCE = Mappers.getMapper( IntersectionMapper.class ); + + Target map( Source source); + + default T unwrap(Wrapper t) { + return t.getWrapped(); + } + + class Source { + + private final Wrapper prop; + + public Source(Wrapper prop) { + this.prop = prop; + } + + public Wrapper getProp() { + return prop; + } + + } + + class Wrapper { + + private final T wrapped; + + public Wrapper(T wrapped) { + this.wrapped = wrapped; + } + + public T getWrapped() { + return wrapped; + } + + } + + class Target { + + private TypeC prop; + + public TypeC getProp() { + return prop; + } + + public void setProp(TypeC prop) { + this.prop = prop; + } + } + + /** + * TypeC must intersect both TypeB & Serializable + */ + class TypeC extends TypeB implements Serializable { + } + + class TypeB extends TypeA { + } + + class TypeA { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/SourceWildCardExtendsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/SourceWildCardExtendsMapper.java new file mode 100644 index 0000000000..24c8b77379 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/SourceWildCardExtendsMapper.java @@ -0,0 +1,87 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.wildcards; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceWildCardExtendsMapper { + + SourceWildCardExtendsMapper INSTANCE = Mappers.getMapper( SourceWildCardExtendsMapper.class ); + + Target map( Source source); + + default T unwrap(Wrapper t) { + return t.getWrapped(); + } + + class Source { + + private final Wrapper propB; + private final Wrapper propC; + + public Source(Wrapper propB, Wrapper propC) { + this.propB = propB; + this.propC = propC; + } + + public Wrapper getPropB() { + return propB; + } + + public Wrapper getPropC() { + return propC; + } + + } + + class Wrapper { + + private final T wrapped; + + public Wrapper(T wrapped) { + this.wrapped = wrapped; + } + + public T getWrapped() { + return wrapped; + } + + } + + class Target { + + private TypeB propB; + private TypeC propC; + + public TypeB getPropB() { + return propB; + } + + public void setPropB(TypeB propB) { + this.propB = propB; + } + + public TypeC getPropC() { + return propC; + } + + public void setPropC(TypeC propC) { + this.propC = propC; + } + } + + class TypeC extends TypeB { + } + + class TypeB extends TypeA { + } + + class TypeA { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java new file mode 100644 index 0000000000..1df99d4d9a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java @@ -0,0 +1,62 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.wildcards; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class WildCardTest { + + @Test + @WithClasses( SourceWildCardExtendsMapper.class ) + public void testExtendsRelation() { + + // prepare source + SourceWildCardExtendsMapper.TypeB typeB = new SourceWildCardExtendsMapper.TypeB(); + SourceWildCardExtendsMapper.Wrapper wrapperB = new SourceWildCardExtendsMapper.Wrapper( typeB ); + SourceWildCardExtendsMapper.TypeC typeC = new SourceWildCardExtendsMapper.TypeC(); + SourceWildCardExtendsMapper.Wrapper wrapperC = new SourceWildCardExtendsMapper.Wrapper( typeC ); + SourceWildCardExtendsMapper.Source source = new SourceWildCardExtendsMapper.Source( wrapperB, wrapperC ); + + // action + SourceWildCardExtendsMapper.Target target = SourceWildCardExtendsMapper.INSTANCE.map( source ); + + // verify target + assertThat( target ).isNotNull(); + assertThat( target.getPropB() ).isEqualTo( typeB ); + assertThat( target.getPropC() ).isEqualTo( typeC ); + } + + @Test + @WithClasses( IntersectionMapper.class ) + // Eclipse does not handle intersection types correctly (TODO: worthwhile to investigate?) + @DisabledOnCompiler( Compiler.ECLIPSE ) + public void testIntersectionRelation() { + + // prepare source + IntersectionMapper.TypeC typeC = new IntersectionMapper.TypeC(); + IntersectionMapper.Wrapper wrapper = new IntersectionMapper.Wrapper( typeC ); + IntersectionMapper.Source source = new IntersectionMapper.Source( wrapper ); + + // action + IntersectionMapper.Target target = IntersectionMapper.INSTANCE.map( source ); + + // verify target + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( typeC ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/SourceWildCardExtendsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/SourceWildCardExtendsMapper.java new file mode 100644 index 0000000000..feb49267d8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/SourceWildCardExtendsMapper.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.typegenerics; + +import java.math.BigInteger; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceWildCardExtendsMapper { + + SourceWildCardExtendsMapper INSTANCE = Mappers.getMapper( SourceWildCardExtendsMapper.class ); + + Target map( Source source); + + default String unwrap(Wrapper t) { + return t.getWrapped().toString(); + } + + class Source { + + private final Wrapper prop; + + public Source(Wrapper prop) { + + this.prop = prop; + } + + public Wrapper getProp() { + return prop; + } + } + + class Wrapper { + + private final T wrapped; + + public Wrapper(T wrapped) { + this.wrapped = wrapped; + } + + public T getWrapped() { + return wrapped; + } + + } + + class Target { + + private String prop; + + public String getProp() { + return prop; + } + + public Target setProp(String prop) { + this.prop = prop; + return this; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java new file mode 100644 index 0000000000..362e00331c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.typegenerics; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigInteger; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class WildCardTest { + + @Test + @WithClasses( SourceWildCardExtendsMapper.class ) + public void testWildCard() { + + // prepare source + SourceWildCardExtendsMapper.Wrapper wrapper = + new SourceWildCardExtendsMapper.Wrapper<>( new BigInteger( "5" ) ); + SourceWildCardExtendsMapper.Source source = new SourceWildCardExtendsMapper.Source( wrapper ); + + // action + SourceWildCardExtendsMapper.Target target = SourceWildCardExtendsMapper.INSTANCE.map( source ); + + // verify target + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( "5" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/ReturnTypeWildCardExtendsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/ReturnTypeWildCardExtendsMapper.java new file mode 100644 index 0000000000..3e4366e06f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/ReturnTypeWildCardExtendsMapper.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.wildcards; + +import java.math.BigInteger; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ReturnTypeWildCardExtendsMapper { + + ReturnTypeWildCardExtendsMapper INSTANCE = Mappers.getMapper( ReturnTypeWildCardExtendsMapper.class ); + + Target map(Source source); + + default Wrapper wrap(String in) { + return new Wrapper<>( new BigInteger( in ) ); + } + + class Source { + + private String prop; + + public Source(String prop) { + this.prop = prop; + } + + public String getProp() { + return prop; + } + + public Source setProp(String prop) { + this.prop = prop; + return this; + } + } + + class Target { + + private Wrapper prop; + + public Target setProp(Wrapper prop) { + this.prop = prop; + return this; + } + + public Wrapper getProp() { + return prop; + } + } + + class Wrapper { + + private final T wrapped; + + public Wrapper(T wrapped) { + this.wrapped = wrapped; + } + + public T getWrapped() { + return wrapped; + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/SourceWildCardExtendsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/SourceWildCardExtendsMapper.java new file mode 100644 index 0000000000..c82ae3cccd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/SourceWildCardExtendsMapper.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.wildcards; + +import java.math.BigInteger; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceWildCardExtendsMapper { + + SourceWildCardExtendsMapper INSTANCE = Mappers.getMapper( SourceWildCardExtendsMapper.class ); + + Target map( Source source); + + default String unwrap(Wrapper t) { + return t.getWrapped().toString(); + } + + class Source { + + private final Wrapper prop; + + public Source(Wrapper prop) { + + this.prop = prop; + } + + public Wrapper getProp() { + return prop; + } + } + + class Wrapper { + + private final T wrapped; + + public Wrapper(T wrapped) { + this.wrapped = wrapped; + } + + public T getWrapped() { + return wrapped; + } + + } + + class Target { + + private String prop; + + public String getProp() { + return prop; + } + + public Target setProp(String prop) { + this.prop = prop; + return this; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java new file mode 100644 index 0000000000..405a22320e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.wildcards; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigInteger; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +/** + * @author Sjaak Derksen + * + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class WildCardTest { + + @Test + @WithClasses( SourceWildCardExtendsMapper.class ) + public void testWildCardAsSourceType() { + + // prepare source + SourceWildCardExtendsMapper.Wrapper wrapper = + new SourceWildCardExtendsMapper.Wrapper<>( new BigInteger( "5" ) ); + SourceWildCardExtendsMapper.Source source = new SourceWildCardExtendsMapper.Source( wrapper ); + + // action + SourceWildCardExtendsMapper.Target target = SourceWildCardExtendsMapper.INSTANCE.map( source ); + + // verify target + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( "5" ); + } + + @Test + @WithClasses( ReturnTypeWildCardExtendsMapper.class ) + public void testWildCardAsReturnType() { + + // prepare source + ReturnTypeWildCardExtendsMapper.Source source = new ReturnTypeWildCardExtendsMapper.Source( "5" ); + + // action + ReturnTypeWildCardExtendsMapper.Target target = ReturnTypeWildCardExtendsMapper.INSTANCE.map( source ); + + // verify target + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isNotNull(); + assertThat( target.getProp().getWrapped() ).isEqualTo( BigInteger.valueOf( 5 ) ); + + } + +} From 85d3b310f781f186ed8f18b56f9514a8a3c8e65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Silv=C3=A8re=20Marie?= Date: Mon, 29 Mar 2021 17:42:22 +0200 Subject: [PATCH 0559/1006] Fix method naming --- .../java/org/mapstruct/ap/test/fields/FieldsMappingTest.java | 2 +- .../java/org/mapstruct/ap/test/fields/SourceTargetMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java index 8c87e7e14d..d215a00ab5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java @@ -29,7 +29,7 @@ public void shouldMapSourceToTarget() { source.normalList = Lists.newArrayList( 10, 11, 12 ); source.fieldOnlyWithGetter = 20; - Target target = SourceTargetMapper.INSTANCE.toSource( source ); + Target target = SourceTargetMapper.INSTANCE.toTarget( source ); assertThat( target ).isNotNull(); assertThat( target.finalInt ).isEqualTo( "10" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java index 99b7b50aa4..0716c380be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/SourceTargetMapper.java @@ -19,7 +19,7 @@ public interface SourceTargetMapper { SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mapping(target = "fieldWithMethods", source = "fieldOnlyWithGetter") - Target toSource(Source source); + Target toTarget(Source source); @InheritInverseConfiguration Source toSource(Target target); From c9199b7068726c279f8daf738f3a2d4076c940b7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 5 Apr 2021 12:44:55 +0200 Subject: [PATCH 0560/1006] #2393 Use includeModel when generating GeneratedType With this we make sure that the implementation type will have a correct import in case of a clash with another mapper named the same --- .../ap/internal/model/Decorator.java | 25 ++++++----- .../ap/internal/model/GeneratedType.java | 26 ++++-------- .../mapstruct/ap/internal/model/Mapper.java | 17 ++++---- .../processor/MapperServiceProcessor.java | 23 ++++++++-- .../ap/internal/model/GeneratedType.ftl | 2 +- .../mapstruct/ap/test/bugs/_2393/Address.java | 28 +++++++++++++ .../ap/test/bugs/_2393/AddressDto.java | 42 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2393/Country.java | 22 ++++++++++ .../ap/test/bugs/_2393/CountryDto.java | 42 +++++++++++++++++++ .../ap/test/bugs/_2393/Issue2393Test.java | 40 ++++++++++++++++++ 10 files changed, 224 insertions(+), 43 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Address.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/AddressDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Country.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/CountryDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index e61a25a475..a54045dca0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -8,7 +8,6 @@ import java.util.Arrays; import java.util.List; import java.util.SortedSet; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -74,7 +73,8 @@ public Decorator build() { hasDelegateConstructor ); - String elementPackage = elementUtils.getPackageOf( mapperElement ).getQualifiedName().toString(); + Type mapperType = typeFactory.getType( mapperElement ); + String elementPackage = mapperType.getPackageName(); String packageName = implPackage.replace( Mapper.PACKAGE_NAME_PLACEHOLDER, elementPackage ); return new Decorator( @@ -82,10 +82,8 @@ public Decorator build() { packageName, implementationName, decoratorType, - elementPackage, - mapperElement.getKind() == ElementKind.INTERFACE ? mapperElement.getSimpleName().toString() : null, + mapperType, methods, - Arrays.asList( new Field( typeFactory.getType( mapperElement ), "delegate", true ) ), options, versionInformation, Accessibility.fromModifiers( mapperElement.getModifiers() ), @@ -96,22 +94,22 @@ public Decorator build() { } private final Type decoratorType; + private final Type mapperType; @SuppressWarnings( "checkstyle:parameternumber" ) private Decorator(TypeFactory typeFactory, String packageName, String name, Type decoratorType, - String interfacePackage, String interfaceName, List methods, - List fields, Options options, VersionInformation versionInformation, + Type mapperType, + List methods, + Options options, VersionInformation versionInformation, Accessibility accessibility, SortedSet extraImports, DecoratorConstructor decoratorConstructor) { super( typeFactory, packageName, name, - decoratorType.getName(), - interfacePackage, - interfaceName, + decoratorType, methods, - fields, + Arrays.asList( new Field( mapperType, "delegate", true ) ), options, versionInformation, accessibility, @@ -120,6 +118,7 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type ); this.decoratorType = decoratorType; + this.mapperType = mapperType; } @Override @@ -148,4 +147,8 @@ public SortedSet getImportTypes() { protected String getTemplateName() { return getTemplateNameForClass( GeneratedType.class ); } + + public Type getMapperType() { + return mapperType; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index a6f573d4ff..620559ea24 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -80,9 +80,7 @@ public T methods(List methods) { private final String packageName; private final String name; - private final String superClassName; - private final String interfacePackage; - private final String interfaceName; + private final Type mapperDefinitionType; private final List annotations; private final List methods; @@ -102,15 +100,13 @@ public T methods(List methods) { private final boolean generatedTypeAvailable; // CHECKSTYLE:OFF - protected GeneratedType(TypeFactory typeFactory, String packageName, String name, String superClassName, - String interfacePackage, String interfaceName, List methods, + protected GeneratedType(TypeFactory typeFactory, String packageName, String name, + Type mapperDefinitionType, List methods, List fields, Options options, VersionInformation versionInformation, Accessibility accessibility, SortedSet extraImportedTypes, Constructor constructor) { this.packageName = packageName; this.name = name; - this.superClassName = superClassName; - this.interfacePackage = interfacePackage; - this.interfaceName = interfaceName; + this.mapperDefinitionType = mapperDefinitionType; this.extraImportedTypes = extraImportedTypes; this.annotations = new ArrayList<>(); @@ -153,16 +149,8 @@ public String getName() { return name; } - public String getSuperClassName() { - return superClassName; - } - - public String getInterfacePackage() { - return interfacePackage; - } - - public String getInterfaceName() { - return interfaceName; + public Type getMapperDefinitionType() { + return mapperDefinitionType; } public List getAnnotations() { @@ -214,6 +202,8 @@ public SortedSet getImportTypes() { SortedSet importedTypes = new TreeSet<>(); addIfImportRequired( importedTypes, generatedType ); + addIfImportRequired( importedTypes, mapperDefinitionType ); + for ( MappingMethod mappingMethod : methods ) { for ( Type type : mappingMethod.getImportTypes() ) { addIfImportRequired( importedTypes, type ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index 0ebd1f0ffd..db63a8431d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -10,7 +10,6 @@ import java.util.SortedSet; import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -90,13 +89,14 @@ public Mapper build() { if ( !fragments.isEmpty() ) { constructor = new NoArgumentConstructor( implementationName, fragments ); } + + Type definitionType = typeFactory.getType( element ); + return new Mapper( typeFactory, packageName, implementationName, - element.getKind() != ElementKind.INTERFACE ? element.getSimpleName().toString() : null, - elementPackage, - element.getKind() == ElementKind.INTERFACE ? element.getSimpleName().toString() : null, + definitionType, customPackage, customName, methods, @@ -117,8 +117,9 @@ public Mapper build() { private Decorator decorator; @SuppressWarnings( "checkstyle:parameternumber" ) - private Mapper(TypeFactory typeFactory, String packageName, String name, String superClassName, - String interfacePackage, String interfaceName, boolean customPackage, boolean customImplName, + private Mapper(TypeFactory typeFactory, String packageName, String name, + Type mapperDefinitionType, + boolean customPackage, boolean customImplName, List methods, Options options, VersionInformation versionInformation, Accessibility accessibility, List fields, Constructor constructor, Decorator decorator, SortedSet extraImportedTypes ) { @@ -127,9 +128,7 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, String typeFactory, packageName, name, - superClassName, - interfacePackage, - interfaceName, + mapperDefinitionType, methods, fields, options, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java index c9e37596f7..ee0bf34634 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperServiceProcessor.java @@ -12,9 +12,11 @@ import javax.tools.StandardLocation; import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.GeneratedType; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.ServicesEntry; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.MapperOptions; import org.mapstruct.ap.internal.writer.ModelWriter; @@ -55,15 +57,28 @@ public int getPriority() { private void writeToSourceFile(Filer filer, Mapper model) { ModelWriter modelWriter = new ModelWriter(); - ServicesEntry servicesEntry = getServicesEntry( model.getDecorator() == null ? model : model.getDecorator() ); + ServicesEntry servicesEntry = getServicesEntry( model ); createSourceFile( servicesEntry, modelWriter, filer ); } - private ServicesEntry getServicesEntry(GeneratedType model) { - String mapperName = model.getInterfaceName() != null ? model.getInterfaceName() : model.getSuperClassName(); + private ServicesEntry getServicesEntry(Mapper mapper) { + if ( mapper.getDecorator() != null ) { + return getServicesEntry( mapper.getDecorator() ); + } + + return getServicesEntry( mapper.getMapperDefinitionType(), mapper ); + } + + private ServicesEntry getServicesEntry(Decorator decorator) { + return getServicesEntry( decorator.getMapperType(), decorator ); + } + + private ServicesEntry getServicesEntry(Type mapperType, GeneratedType model) { + String mapperName = mapperType.getName(); + String mapperPackageName = mapperType.getPackageName(); - return new ServicesEntry(model.getInterfacePackage(), mapperName, + return new ServicesEntry(mapperPackageName, mapperName, model.getPackageName(), model.getName()); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 3bdae0582a..4981882403 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -24,7 +24,7 @@ import ${importedType}; <#list annotations as annotation> <#nt><@includeModel object=annotation/> -<#lt>${accessibility.keyword} class ${name}<#if superClassName??> extends ${superClassName}<#if interfaceName??> implements ${interfaceName} { +<#lt>${accessibility.keyword} class ${name} <#if mapperDefinitionType.interface>implements<#else>extends <@includeModel object=mapperDefinitionType/> { <#list fields as field><#if field.used><#nt> <@includeModel object=field/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Address.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Address.java new file mode 100644 index 0000000000..8651165d82 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Address.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2393; + +/** + * @author Filip Hrisafov + */ +public class Address { + + private final String city; + private final Country country; + + public Address(String city, Country country) { + this.city = city; + this.country = country; + } + + public String getCity() { + return city; + } + + public Country getCountry() { + return country; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/AddressDto.java new file mode 100644 index 0000000000..41f771f319 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/AddressDto.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2393; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +public class AddressDto { + + private String city; + private CountryDto country; + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public CountryDto getCountry() { + return country; + } + + public void setCountry(CountryDto country) { + this.country = country; + } + + @Mapper(uses = CountryDto.Converter.class) + public interface Converter { + + Converter INSTANCE = Mappers.getMapper( Converter.class ); + + AddressDto convert(Address address); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Country.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Country.java new file mode 100644 index 0000000000..efeaad6fc0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Country.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2393; + +/** + * @author Filip Hrisafov + */ +public class Country { + + private final String name; + + public Country(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/CountryDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/CountryDto.java new file mode 100644 index 0000000000..7e3751efb3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/CountryDto.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2393; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +public class CountryDto { + + private String name; + private String code; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + @Mapper + public interface Converter { + + @Mapping(target = "code", constant = "UNKNOWN") + CountryDto convert(Country from); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java new file mode 100644 index 0000000000..0bb88e5e59 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2393; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2393") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Address.class, + AddressDto.class, + Country.class, + CountryDto.class, +}) +public class Issue2393Test { + + @Test + public void shouldUseCorrectImport() { + AddressDto dto = AddressDto.Converter.INSTANCE.convert( new Address( + "Zurich", + new Country( "Switzerland" ) + ) ); + + assertThat( dto.getCity() ).isEqualTo( "Zurich" ); + assertThat( dto.getCountry().getName() ).isEqualTo( "Switzerland" ); + assertThat( dto.getCountry().getCode() ).isEqualTo( "UNKNOWN" ); + } +} From 5f1b3d7862446269924bd5386576f6d55fd600a0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 5 Apr 2021 10:04:16 +0200 Subject: [PATCH 0561/1006] #2402 Always add source parameter name when constructing the source references for target this --- .../model/beanmapping/SourceReference.java | 7 ++- .../ap/test/bugs/_2042/Issue2402Mapper.java | 59 +++++++++++++++++++ .../ap/test/bugs/_2042/Issue2402Test.java | 36 +++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index d43a242278..c87c6fb46d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -421,8 +421,13 @@ public List push(TypeFactory typeFactory, FormattingMessager me if ( deepestProperty != null ) { Type type = deepestProperty.getType(); Map newDeepestReadAccessors = type.getPropertyReadAccessors(); + String parameterName = getParameter().getName(); + String deepestPropertyFullName = deepestProperty.getFullName(); for ( Map.Entry newDeepestReadAccessorEntry : newDeepestReadAccessors.entrySet() ) { - String newFullName = deepestProperty.getFullName() + "." + newDeepestReadAccessorEntry.getKey(); + // Always include the parameter name in the new full name. + // Otherwise multi source parameters might be reported incorrectly + String newFullName = + parameterName + "." + deepestPropertyFullName + "." + newDeepestReadAccessorEntry.getKey(); SourceReference sourceReference = new BuilderFromMapping() .sourceName( newFullName ) .method( method ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Mapper.java new file mode 100644 index 0000000000..3fe52aaafd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Mapper.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2042; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2402Mapper { + + Issue2402Mapper INSTANCE = Mappers.getMapper( Issue2402Mapper.class ); + + @Mapping(target = ".", source = "source.info") + Target map(Source source, String other); + + class Target { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class Source { + + private final Info info; + + public Source(Info info) { + this.info = info; + } + + public Info getInfo() { + return info; + } + } + + class Info { + private final String name; + + public Info(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java new file mode 100644 index 0000000000..26e585c23d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2042; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2402") +@RunWith(AnnotationProcessorTestRunner.class) +@WithClasses({ + Issue2402Mapper.class +}) +public class Issue2402Test { + + @Test + public void shouldCompile() { + Issue2402Mapper.Target target = Issue2402Mapper.INSTANCE. + map( + new Issue2402Mapper.Source( new Issue2402Mapper.Info( "test" ) ), + "other test" + ); + + assertThat( target.getName() ).isEqualTo( "test" ); + } +} From 2be536bb65d220495b8d7f7f224451f1d59a1bb9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 5 Apr 2021 13:27:08 +0200 Subject: [PATCH 0562/1006] #2303 Generated code should use iteration order preserving LinkedHash(Map|Set) instead of Hash(Map|Set) --- ...apter-10-advanced-mapping-options.asciidoc | 2 +- .../chapter-6-mapping-collections.asciidoc | 8 ++--- .../chapter-7-mapping-streams.asciidoc | 2 +- .../ap/internal/model/common/TypeFactory.java | 6 ++-- .../test/bugs/_1453/Issue1453MapperImpl.java | 8 ++--- .../ap/test/bugs/_1707/ConverterImpl.java | 6 ++-- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 16 ++++----- .../DomainDtoWithNvmsDefaultMapperImpl.java | 34 +++++++++---------- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 16 ++++----- .../DomainDtoWithPresenceCheckMapperImpl.java | 16 ++++----- .../SourceTargetMapperImpl.java | 8 ++--- .../updatemethods/CompanyMapper1Impl.java | 4 +-- .../selection/DepartmentMapperImpl.java | 4 +-- 13 files changed, 66 insertions(+), 64 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 4ccad69f2c..158aa632f9 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -180,7 +180,7 @@ By default the target property will be set to null. However: 1. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result can be altered to return *default* values. -For `List` MapStruct generates an `ArrayList`, for `Map` a `HashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. +For `List` MapStruct generates an `ArrayList`, for `Map` a `LinkedHashMap`, for arrays an empty array, for `String` `""` and for primitive / boxed types a representation of `false` or `0`. For all other objects an new instance is created. Please note that a default constructor is required. If not available, use the `@Mapping#defaultValue`. 2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc index 785b460b12..17025da4de 100644 --- a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -36,7 +36,7 @@ public Set integerSetToStringSet(Set integers) { return null; } - Set set = new HashSet(); + Set set = new LinkedHashSet(); for ( Integer integer : integers ) { set.add( String.valueOf( integer ) ); @@ -125,7 +125,7 @@ public Map stringStringMapToLongDateMap(Map source) return null; } - Map map = new HashMap(); + Map map = new LinkedHashMap(); for ( Map.Entry entry : source.entrySet() ) { @@ -210,13 +210,13 @@ When an iterable or map mapping method declares an interface type as return type |`List`|`ArrayList` -|`Set`|`HashSet` +|`Set`|`LinkedHashSet` |`SortedSet`|`TreeSet` |`NavigableSet`|`TreeSet` -|`Map`|`HashMap` +|`Map`|`LinkedHashMap` |`SortedMap`|`TreeMap` diff --git a/documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc b/documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc index ccc3e56854..ec41719eb8 100644 --- a/documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc +++ b/documentation/src/main/asciidoc/chapter-7-mapping-streams.asciidoc @@ -42,7 +42,7 @@ public Set integerStreamToStringSet(Stream integers) { } return integers.map( integer -> String.valueOf( integer ) ) - .collect( Collectors.toCollection( HashSet::new ) ); + .collect( Collectors.toCollection( LinkedHashSet::new ) ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index f8c67f740e..127ec74270 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -10,6 +10,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -116,11 +118,11 @@ public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMes implementationTypes.put( Collection.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); implementationTypes.put( List.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); - implementationTypes.put( Set.class.getName(), withLoadFactorAdjustment( getType( HashSet.class ) ) ); + implementationTypes.put( Set.class.getName(), withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) ); implementationTypes.put( SortedSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); implementationTypes.put( NavigableSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); - implementationTypes.put( Map.class.getName(), withLoadFactorAdjustment( getType( HashMap.class ) ) ); + implementationTypes.put( Map.class.getName(), withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) ); implementationTypes.put( SortedMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); implementationTypes.put( NavigableMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); implementationTypes.put( diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java index 00e01f6f17..201b007603 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.bugs._1453; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.annotation.Generated; @@ -68,7 +68,7 @@ public Map mapExtend(Map map = new HashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) ); + Map map = new LinkedHashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : auctions.entrySet() ) { AuctionDto key = map( entry.getKey() ); @@ -85,7 +85,7 @@ public Map mapExtend(Map map = new HashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) ); + Map map = new LinkedHashMap( Math.max( (int) ( auctions.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : auctions.entrySet() ) { AuctionDto key = map( entry.getKey() ); @@ -126,7 +126,7 @@ protected Map paymentPaymentMapToPaymentDtoPaymentDtoMap return null; } - Map map1 = new HashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); + Map map1 = new LinkedHashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : map.entrySet() ) { PaymentDto key = paymentToPaymentDto( entry.getKey() ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java index 898b134188..abe4a62a3d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java @@ -5,7 +5,7 @@ */ package org.mapstruct.ap.test.bugs._1707; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -24,10 +24,10 @@ public Set convert(Stream source) { return null; } - Set set = new HashSet(); + Set set = new LinkedHashSet(); set.addAll( source.map( source1 -> convert( source1 ) ) - .collect( Collectors.toCollection( HashSet::new ) ) + .collect( Collectors.toCollection( LinkedHashSet::new ) ) ); addCustomValue( set ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index e7e1be5b1d..b3a8c89c60 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.bugs._913; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.Generated; @@ -30,14 +30,14 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new HashSet( list ) ); + domain.setStrings( new LinkedHashSet( list ) ); } if ( source.hasStrings() ) { domain.setLongs( stringListToLongSet( source.getStrings() ) ); } if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - domain.setStringsInitialized( new HashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); } if ( source.hasStringsInitialized() ) { domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); @@ -68,7 +68,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -91,7 +91,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -140,7 +140,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -163,7 +163,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -204,7 +204,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); + Set set = new LinkedHashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index f0f2ea5f01..f1bf0fa78f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.bugs._913; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.Generated; @@ -28,12 +28,12 @@ public Domain create(Dto source) { if ( source != null ) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new HashSet( list ) ); + domain.setStrings( new LinkedHashSet( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new HashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); @@ -59,13 +59,13 @@ public void update(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new HashSet() ); + target.setStrings( new LinkedHashSet() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -75,7 +75,7 @@ public void update(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new HashSet() ); + target.setLongs( new LinkedHashSet() ); } } else { @@ -91,13 +91,13 @@ public void update(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new HashSet() ); + target.setStringsInitialized( new LinkedHashSet() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -107,7 +107,7 @@ public void update(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new HashSet() ); + target.setLongsInitialized( new LinkedHashSet() ); } } else { @@ -149,13 +149,13 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStrings().addAll( list ); } else { - target.setStrings( new HashSet() ); + target.setStrings( new LinkedHashSet() ); } } else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -165,7 +165,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongs().addAll( set ); } else { - target.setLongs( new HashSet() ); + target.setLongs( new LinkedHashSet() ); } } else { @@ -181,13 +181,13 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getStringsInitialized().addAll( list1 ); } else { - target.setStringsInitialized( new HashSet() ); + target.setStringsInitialized( new LinkedHashSet() ); } } else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -197,7 +197,7 @@ public Domain updateWithReturn(Dto source, Domain target) { target.getLongsInitialized().addAll( set1 ); } else { - target.setLongsInitialized( new HashSet() ); + target.setLongsInitialized( new LinkedHashSet() ); } } else { @@ -232,10 +232,10 @@ public Domain updateWithReturn(Dto source, Domain target) { protected Set stringListToLongSet(List list) { if ( list == null ) { - return new HashSet(); + return new LinkedHashSet(); } - Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); + Set set = new LinkedHashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index a07601a4df..59a770d049 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.bugs._913; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.Generated; @@ -30,12 +30,12 @@ public Domain create(Dto source) { List list = source.getStrings(); if ( list != null ) { - domain.setStrings( new HashSet( list ) ); + domain.setStrings( new LinkedHashSet( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); List list1 = source.getStringsInitialized(); if ( list1 != null ) { - domain.setStringsInitialized( new HashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); List list2 = source.getStringsWithDefault(); @@ -68,7 +68,7 @@ public void update(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -100,7 +100,7 @@ public void update(Dto source, Domain target) { else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -159,7 +159,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list = source.getStrings(); if ( list != null ) { - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -191,7 +191,7 @@ public Domain updateWithReturn(Dto source, Domain target) { else { List list1 = source.getStringsInitialized(); if ( list1 != null ) { - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -238,7 +238,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); + Set set = new LinkedHashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index 6ed369c4d9..ba18dfda11 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.bugs._913; import java.util.ArrayList; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import javax.annotation.Generated; @@ -30,12 +30,12 @@ public Domain create(DtoWithPresenceCheck source) { if ( source.hasStrings() ) { List list = source.getStrings(); - domain.setStrings( new HashSet( list ) ); + domain.setStrings( new LinkedHashSet( list ) ); } domain.setLongs( stringListToLongSet( source.getStrings() ) ); if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - domain.setStringsInitialized( new HashSet( list1 ) ); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); } domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); if ( source.hasStringsWithDefault() ) { @@ -64,7 +64,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -87,7 +87,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -136,7 +136,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStrings() ) { List list = source.getStrings(); - target.setStrings( new HashSet( list ) ); + target.setStrings( new LinkedHashSet( list ) ); } } if ( target.getLongs() != null ) { @@ -159,7 +159,7 @@ public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { else { if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); - target.setStringsInitialized( new HashSet( list1 ) ); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); } } if ( target.getLongsInitialized() != null ) { @@ -200,7 +200,7 @@ protected Set stringListToLongSet(List list) { return null; } - Set set = new HashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); + Set set = new LinkedHashSet( Math.max( (int) ( list.size() / .75f ) + 1, 16 ) ); for ( String string : list ) { set.add( Long.parseLong( string ) ); } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java index 6310026170..853ad59560 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java @@ -7,8 +7,8 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -82,7 +82,7 @@ public Set sourceFoosToTargetFoos(Set foos) { return null; } - Set set = new HashSet( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + Set set = new LinkedHashSet( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); for ( SourceFoo sourceFoo : foos ) { set.add( sourceFooToTargetFoo( sourceFoo ) ); } @@ -178,7 +178,7 @@ public Map sourceFooMapToTargetFooMap(Map fo return null; } - Map map = new HashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + Map map = new LinkedHashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : foos.entrySet() ) { String key = String.valueOf( entry.getKey() ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java index 121dbea3ec..5eff50e342 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java @@ -5,7 +5,7 @@ */ package org.mapstruct.ap.test.updatemethods; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import javax.annotation.Generated; @@ -83,7 +83,7 @@ protected Map secretaryDtoEmployeeDtoMapToSecre return null; } - Map map1 = new HashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); + Map map1 = new LinkedHashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); for ( java.util.Map.Entry entry : map.entrySet() ) { SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() ); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java index 338d6e9b57..1f21f0f637 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/updatemethods/selection/DepartmentMapperImpl.java @@ -6,7 +6,7 @@ package org.mapstruct.ap.test.updatemethods.selection; import java.util.ArrayList; -import java.util.HashMap; +import java.util.LinkedHashMap; import javax.annotation.Generated; import org.mapstruct.ap.test.updatemethods.DepartmentDto; import org.mapstruct.ap.test.updatemethods.DepartmentEntity; @@ -42,7 +42,7 @@ public void toDepartmentEntity(DepartmentDto dto, DepartmentEntity entity) { } if ( dto.getSecretaryToEmployee() != null ) { if ( entity.getSecretaryToEmployee() == null ) { - entity.setSecretaryToEmployee( new HashMap() ); + entity.setSecretaryToEmployee( new LinkedHashMap() ); } externalHandWrittenMapper.toSecretaryEmployeeEntityMap( dto.getSecretaryToEmployee(), entity.getSecretaryToEmployee() ); } From 903e6f3f44dda85f935125b81d7e66e0056f5aa4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 5 Apr 2021 13:58:18 +0200 Subject: [PATCH 0563/1006] #597 Add String <-> StringBuilder conversion in the documentation --- .../src/main/asciidoc/chapter-5-data-type-conversions.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index ce842df0e8..7800b6a933 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -117,6 +117,8 @@ public interface CarMapper { * Between `java.util.Currency` and `String`. ** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown +* Between `String` and `StringBuilder` + [[mapping-object-references]] === Mapping object references From 1c8fff1475829ad7524cf706d1d0b2ab36dc29bc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Apr 2021 17:55:25 +0200 Subject: [PATCH 0564/1006] #2423 Use SetterWrapperForCollectionsAndMapsWithNullCheck if the source has a presence check method --- .../model/CollectionAssignmentBuilder.java | 28 ++++++- .../ap/internal/model/PropertyMapping.java | 5 ++ .../spi/CollectionPresenceMapper.java | 52 +++++++++++++ .../spi/CollectionWithNonDirectMapper.java | 77 +++++++++++++++++++ .../CollectionWithNullValueCheckMapper.java | 53 +++++++++++++ .../presencecheck/spi/NonDirectMapper.java | 76 ++++++++++++++++++ .../spi/PresenceCheckMappingTest.java | 70 +++++++++++++++++ .../DomainDtoWithPresenceCheckMapperImpl.java | 8 +- 8 files changed, 365 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionPresenceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNonDirectMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNullValueCheckMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/NonDirectMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 7ab9814e23..dd6db1b0ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -22,6 +22,7 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL; @@ -168,8 +169,7 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { targetAccessorType.isFieldAssignment() ); } - else if ( result.getType() == Assignment.AssignmentType.DIRECT || - nvcs == NullValueCheckStrategyGem.ALWAYS ) { + else if ( setterWrapperNeedsSourceNullCheck( result ) ) { result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, @@ -212,4 +212,28 @@ else if ( result.getType() == Assignment.AssignmentType.DIRECT || return result; } + /** + * Checks whether the setter wrapper should include a null / presence check or not + * + * @param rhs the source right hand side + * @return whether to include a null / presence check or not + */ + private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs) { + if ( rhs.getSourcePresenceCheckerReference() != null ) { + // If there is a source presence check then we should do a null check + return true; + } + + if ( nvcs == ALWAYS ) { + // NullValueCheckStrategy is ALWAYS -> do a null check + return true; + } + + if ( rhs.getType().isDirect() ) { + return true; + } + + return false; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 48ebc34d29..3e53e2ce06 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -454,6 +454,11 @@ private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs, Type targetTyp return true; } + if ( rhs.getSourcePresenceCheckerReference() != null ) { + // There is an explicit source presence check method -> do a null / presence check + return true; + } + if ( nvpms == SET_TO_DEFAULT || nvpms == IGNORE ) { // NullValuePropertyMapping is SET_TO_DEFAULT or IGNORE -> do a null check return true; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionPresenceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionPresenceMapper.java new file mode 100644 index 0000000000..f99cae4d3e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionPresenceMapper.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import java.util.Collection; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CollectionPresenceMapper { + + CollectionPresenceMapper INSTANCE = Mappers.getMapper( CollectionPresenceMapper.class ); + + Target map(Source source); + + class Target { + + private Collection players; + + public Collection getPlayers() { + return players; + } + + public void setPlayers(Collection players) { + this.players = players; + } + } + + class Source { + + private final Collection players; + + public Source(Collection players) { + this.players = players; + } + + public Collection getPlayers() { + return players; + } + + public boolean hasPlayers() { + return players != null && !players.isEmpty(); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNonDirectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNonDirectMapper.java new file mode 100644 index 0000000000..67daa22116 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNonDirectMapper.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import java.util.Collection; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CollectionWithNonDirectMapper { + + CollectionWithNonDirectMapper INSTANCE = Mappers.getMapper( CollectionWithNonDirectMapper.class ); + + Target map(Source source); + + class Target { + + private Collection players; + + public Collection getPlayers() { + return players; + } + + public void setPlayers(Collection players) { + this.players = players; + } + } + + class Player { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class Source { + + private final Collection players; + + public Source(Collection players) { + this.players = players; + } + + public Collection getPlayers() { + return players; + } + + public boolean hasPlayers() { + return players != null && !players.isEmpty(); + } + } + + class PlayerSource { + + private final String name; + + public PlayerSource(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNullValueCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNullValueCheckMapper.java new file mode 100644 index 0000000000..ef03be20c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/CollectionWithNullValueCheckMapper.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import java.util.Collection; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS) +public interface CollectionWithNullValueCheckMapper { + + CollectionWithNullValueCheckMapper INSTANCE = Mappers.getMapper( CollectionWithNullValueCheckMapper.class ); + + Target map(Source source); + + class Target { + + private Collection players; + + public Collection getPlayers() { + return players; + } + + public void setPlayers(Collection players) { + this.players = players; + } + } + + class Source { + + private final Collection players; + + public Source(Collection players) { + this.players = players; + } + + public Collection getPlayers() { + return players; + } + + public boolean hasPlayers() { + return players != null && !players.isEmpty(); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/NonDirectMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/NonDirectMapper.java new file mode 100644 index 0000000000..100ff39370 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/NonDirectMapper.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface NonDirectMapper { + + NonDirectMapper INSTANCE = Mappers.getMapper( NonDirectMapper.class ); + + SoccerTeam map(SoccerTeamSource source); + + class SoccerTeam { + + private Goalkeeper goalKeeper; + + public Goalkeeper getGoalKeeper() { + return goalKeeper; + } + + public void setGoalKeeper(Goalkeeper goalKeeper) { + this.goalKeeper = goalKeeper; + } + } + + class Goalkeeper { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class SoccerTeamSource { + + private final GoalKeeperSource goalKeeper; + + public SoccerTeamSource(GoalKeeperSource goalKeeper) { + this.goalKeeper = goalKeeper; + } + + public GoalKeeperSource getGoalKeeper() { + return goalKeeper; + } + + public boolean hasGoalKeeper() { + return goalKeeper != null && goalKeeper.getName() != null && !goalKeeper.getName().isEmpty(); + } + } + + class GoalKeeperSource { + + private final String name; + + public GoalKeeperSource(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java new file mode 100644 index 0000000000..c25dad70b5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.presencecheck.spi; + +import java.util.Collections; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@RunWith(AnnotationProcessorTestRunner.class) +public class PresenceCheckMappingTest { + + @Test + @WithClasses({ + CollectionPresenceMapper.class + }) + public void collectionPresenceCheckShouldBeUsedByDefault() { + CollectionPresenceMapper.Source source = new CollectionPresenceMapper.Source( Collections.emptyList() ); + CollectionPresenceMapper.Target target = CollectionPresenceMapper.INSTANCE.map( source ); + + assertThat( target.getPlayers() ).isNull(); + } + + @Test + @WithClasses({ + CollectionWithNullValueCheckMapper.class + }) + public void collectionPresenceCheckShouldBeUsedByWhenNullValueCheckIsAlways() { + CollectionWithNullValueCheckMapper.Source source = + new CollectionWithNullValueCheckMapper.Source( Collections.emptyList() ); + CollectionWithNullValueCheckMapper.Target target = + CollectionWithNullValueCheckMapper.INSTANCE.map( source ); + + assertThat( target.getPlayers() ).isNull(); + } + + @Test + @WithClasses({ + CollectionWithNonDirectMapper.class + }) + public void nonDirectCollectionPresenceCheckShouldBeUsedByDefault() { + CollectionWithNonDirectMapper.Source source = + new CollectionWithNonDirectMapper.Source( Collections.emptyList() ); + CollectionWithNonDirectMapper.Target target = CollectionWithNonDirectMapper.INSTANCE.map( source ); + + assertThat( target.getPlayers() ).isNull(); + } + + @Test + @WithClasses({ + NonDirectMapper.class + }) + public void nonDirectMappingWithPresenceCheckShouldBeUsedByDefault() { + NonDirectMapper.SoccerTeamSource source = + new NonDirectMapper.SoccerTeamSource( new NonDirectMapper.GoalKeeperSource( "" ) ); + NonDirectMapper.SoccerTeam target = NonDirectMapper.INSTANCE.map( source ); + + assertThat( target.getGoalKeeper() ).isNull(); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index ba18dfda11..8cc41c47d5 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -32,12 +32,16 @@ public Domain create(DtoWithPresenceCheck source) { List list = source.getStrings(); domain.setStrings( new LinkedHashSet( list ) ); } - domain.setLongs( stringListToLongSet( source.getStrings() ) ); + if ( source.hasStrings() ) { + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + } if ( source.hasStringsInitialized() ) { List list1 = source.getStringsInitialized(); domain.setStringsInitialized( new LinkedHashSet( list1 ) ); } - domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + if ( source.hasStringsInitialized() ) { + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } if ( source.hasStringsWithDefault() ) { List list2 = source.getStringsWithDefault(); domain.setStringsWithDefault( new ArrayList( list2 ) ); From a2e1404b9326d9b4953a66ba3226a31137224056 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 27 Mar 2021 18:38:41 +0100 Subject: [PATCH 0565/1006] Refactor presence checks to object in order to simplify the conditional mapping --- .../ap/internal/model/MethodReference.java | 3 +- .../model/NestedPropertyMappingMethod.java | 46 ++++++++++++--- .../ap/internal/model/PropertyMapping.java | 29 +++++++-- .../ap/internal/model/TypeConversion.java | 3 +- .../model/assignment/AssignmentWrapper.java | 3 +- .../ap/internal/model/common/Assignment.java | 2 +- .../internal/model/common/PresenceCheck.java | 24 ++++++++ .../ap/internal/model/common/SourceRHS.java | 11 +++- .../AllPresenceChecksPresenceCheck.java | 59 +++++++++++++++++++ .../model/presence/NullPresenceCheck.java | 52 ++++++++++++++++ .../SourceReferenceMethodPresenceCheck.java | 59 +++++++++++++++++++ .../model/NestedPropertyMappingMethod.ftl | 9 ++- .../ap/internal/model/macro/CommonMacros.ftl | 4 +- .../AllPresenceChecksPresenceCheck.ftl | 16 +++++ .../model/presence/NullPresenceCheck.ftl | 9 +++ .../SourceReferenceMethodPresenceCheck.ftl | 9 +++ 16 files changed, 309 insertions(+), 29 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 58c4ba890a..78a3830f45 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -19,6 +19,7 @@ import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; @@ -197,7 +198,7 @@ public String getSourceReference() { } @Override - public String getSourcePresenceCheckerReference() { + public PresenceCheck getSourcePresenceCheckerReference() { return assignment.getSourcePresenceCheckerReference(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index f5616d1278..82c02f5385 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -11,8 +11,10 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; +import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; @@ -52,17 +54,27 @@ public Builder mappingContext(MappingBuilderContext mappingContext) { public NestedPropertyMappingMethod build() { List existingVariableNames = new ArrayList<>(); + Parameter sourceParameter = null; for ( Parameter parameter : method.getSourceParameters() ) { existingVariableNames.add( parameter.getName() ); + if ( sourceParameter == null && !parameter.isMappingTarget() && !parameter.isMappingContext() ) { + sourceParameter = parameter; + } } final List thrownTypes = new ArrayList<>(); List safePropertyEntries = new ArrayList<>(); + if ( sourceParameter == null ) { + throw new IllegalStateException( "Method " + method + " has no source parameter." ); + } + + String previousPropertyName = sourceParameter.getName(); for ( PropertyEntry propertyEntry : propertyEntries ) { String safeName = Strings.getSafeVariableName( propertyEntry.getName(), existingVariableNames ); - safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName ) ); + safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName, previousPropertyName ) ); existingVariableNames.add( safeName ); thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( propertyEntry.getReadAccessor() ) ); + previousPropertyName = safeName; } method.addThrownTypes( thrownTypes ); return new NestedPropertyMappingMethod( method, safePropertyEntries ); @@ -92,6 +104,9 @@ public Set getImportTypes() { Set types = super.getImportTypes(); for ( SafePropertyEntry propertyEntry : safePropertyEntries) { types.add( propertyEntry.getType() ); + if ( propertyEntry.getPresenceChecker() != null ) { + types.addAll( propertyEntry.getPresenceChecker().getImportTypes() ); + } } return types; } @@ -143,18 +158,23 @@ public static class SafePropertyEntry { private final String safeName; private final String readAccessorName; - private final String presenceCheckerName; + private final PresenceCheck presenceChecker; + private final String previousPropertyName; private final Type type; - public SafePropertyEntry(PropertyEntry entry, String safeName) { + public SafePropertyEntry(PropertyEntry entry, String safeName, String previousPropertyName) { this.safeName = safeName; this.readAccessorName = ValueProvider.of( entry.getReadAccessor() ).getValue(); if ( entry.getPresenceChecker() != null ) { - this.presenceCheckerName = entry.getPresenceChecker().getSimpleName(); + this.presenceChecker = new SourceReferenceMethodPresenceCheck( + previousPropertyName, + entry.getPresenceChecker().getSimpleName() + ); } else { - this.presenceCheckerName = null; + this.presenceChecker = null; } + this.previousPropertyName = previousPropertyName; this.type = entry.getType(); } @@ -166,8 +186,12 @@ public String getAccessorName() { return readAccessorName; } - public String getPresenceCheckerName() { - return presenceCheckerName; + public PresenceCheck getPresenceChecker() { + return presenceChecker; + } + + public String getPreviousPropertyName() { + return previousPropertyName; } public Type getType() { @@ -189,7 +213,11 @@ public boolean equals(Object o) { return false; } - if ( !Objects.equals( presenceCheckerName, that.presenceCheckerName ) ) { + if ( !Objects.equals( presenceChecker, that.presenceChecker ) ) { + return false; + } + + if ( !Objects.equals( previousPropertyName, that.previousPropertyName ) ) { return false; } @@ -203,7 +231,7 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = readAccessorName != null ? readAccessorName.hashCode() : 0; - result = 31 * result + ( presenceCheckerName != null ? presenceCheckerName.hashCode() : 0 ); + result = 31 * result + ( presenceChecker != null ? presenceChecker.hashCode() : 0 ); result = 31 * result + ( type != null ? type.hashCode() : 0 ); return result; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 3e53e2ce06..d1d7eaebd5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -28,8 +28,12 @@ import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; +import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; import org.mapstruct.ap.internal.model.source.DelegatingOptions; import org.mapstruct.ap.internal.model.source.MappingControl; import org.mapstruct.ap.internal.model.source.MappingOptions; @@ -609,30 +613,43 @@ else if ( !sourceReference.isNested() ) { } } - private String getSourcePresenceCheckerRef( SourceReference sourceReference ) { - String sourcePresenceChecker = null; + private PresenceCheck getSourcePresenceCheckerRef(SourceReference sourceReference ) { + PresenceCheck sourcePresenceChecker = null; if ( !sourceReference.getPropertyEntries().isEmpty() ) { Parameter sourceParam = sourceReference.getParameter(); // TODO is first correct here?? shouldn't it be last since the remainer is checked // in the forged method? PropertyEntry propertyEntry = sourceReference.getShallowestProperty(); if ( propertyEntry.getPresenceChecker() != null ) { - sourcePresenceChecker = sourceParam.getName() - + "." + propertyEntry.getPresenceChecker().getSimpleName() + "()"; + List presenceChecks = new ArrayList<>(); + presenceChecks.add( new SourceReferenceMethodPresenceCheck( + sourceParam.getName(), + propertyEntry.getPresenceChecker().getSimpleName() + ) ); String variableName = sourceParam.getName() + "." + propertyEntry.getReadAccessor().getSimpleName() + "()"; for (int i = 1; i < sourceReference.getPropertyEntries().size(); i++) { PropertyEntry entry = sourceReference.getPropertyEntries().get( i ); if (entry.getPresenceChecker() != null && entry.getReadAccessor() != null) { - sourcePresenceChecker += " && " + variableName + " != null && " - + variableName + "." + entry.getPresenceChecker().getSimpleName() + "()"; + presenceChecks.add( new NullPresenceCheck( variableName ) ); + presenceChecks.add( new SourceReferenceMethodPresenceCheck( + variableName, + entry.getPresenceChecker().getSimpleName() + ) ); variableName = variableName + "." + entry.getReadAccessor().getSimpleName() + "()"; } else { break; } } + + if ( presenceChecks.size() == 1 ) { + sourcePresenceChecker = presenceChecks.get( 0 ); + } + else { + sourcePresenceChecker = new AllPresenceChecksPresenceCheck( presenceChecks ); + } } } return sourcePresenceChecker; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java index 3f06ce7e85..c5b4bc6915 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/TypeConversion.java @@ -11,6 +11,7 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; /** @@ -79,7 +80,7 @@ public boolean isSourceReferenceParameter() { } @Override - public String getSourcePresenceCheckerReference() { + public PresenceCheck getSourcePresenceCheckerReference() { return assignment.getSourcePresenceCheckerReference(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java index 551d20d72b..54885012a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AssignmentWrapper.java @@ -10,6 +10,7 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; /** @@ -57,7 +58,7 @@ public boolean isSourceReferenceParameter() { } @Override - public String getSourcePresenceCheckerReference() { + public PresenceCheck getSourcePresenceCheckerReference() { return decoratedAssignment.getSourcePresenceCheckerReference(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index 3cd32c82ea..293df9516b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -90,7 +90,7 @@ public boolean isConverted() { * * @return source reference */ - String getSourcePresenceCheckerReference(); + PresenceCheck getSourcePresenceCheckerReference(); /** * the source type used in the matching process diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java new file mode 100644 index 0000000000..e77e24f218 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.common; + +import java.util.Set; + +/** + * Marker interface for presence checks. + * + * @author Filip Hrisafov + */ +public interface PresenceCheck { + + /** + * returns all types required as import by the presence check. + * + * @return imported types + */ + Set getImportTypes(); + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index 5dc5d91832..7861c03f2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Stream; @@ -30,7 +31,7 @@ public class SourceRHS extends ModelElement implements Assignment { private String sourceLoopVarName; private final Set existingVariableNames; private final String sourceErrorMessagePart; - private final String sourcePresenceCheckerReference; + private final PresenceCheck sourcePresenceCheckerReference; private boolean useElementAsSourceTypeForMatching = false; private final String sourceParameterName; @@ -39,7 +40,7 @@ public SourceRHS(String sourceReference, Type sourceType, Set existingVa this( sourceReference, sourceReference, null, sourceType, existingVariableNames, sourceErrorMessagePart ); } - public SourceRHS(String sourceParameterName, String sourceReference, String sourcePresenceCheckerReference, + public SourceRHS(String sourceParameterName, String sourceReference, PresenceCheck sourcePresenceCheckerReference, Type sourceType, Set existingVariableNames, String sourceErrorMessagePart ) { this.sourceReference = sourceReference; this.sourceType = sourceType; @@ -60,7 +61,7 @@ public boolean isSourceReferenceParameter() { } @Override - public String getSourcePresenceCheckerReference() { + public PresenceCheck getSourcePresenceCheckerReference() { return sourcePresenceCheckerReference; } @@ -96,6 +97,10 @@ public void setSourceLoopVarName(String sourceLoopVarName) { @Override public Set getImportTypes() { + if ( sourcePresenceCheckerReference != null ) { + return sourcePresenceCheckerReference.getImportTypes(); + } + return Collections.emptySet(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java new file mode 100644 index 0000000000..4ee62cf542 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class AllPresenceChecksPresenceCheck extends ModelElement implements PresenceCheck { + + private final Collection presenceChecks; + + public AllPresenceChecksPresenceCheck(Collection presenceChecks) { + this.presenceChecks = presenceChecks; + } + + public Collection getPresenceChecks() { + return presenceChecks; + } + + @Override + public Set getImportTypes() { + Set importTypes = new HashSet<>(); + for ( PresenceCheck presenceCheck : presenceChecks ) { + importTypes.addAll( presenceCheck.getImportTypes() ); + } + + return importTypes; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + AllPresenceChecksPresenceCheck that = (AllPresenceChecksPresenceCheck) o; + return Objects.equals( presenceChecks, that.presenceChecks ); + } + + @Override + public int hashCode() { + return Objects.hash( presenceChecks ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java new file mode 100644 index 0000000000..c9cae61b7c --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class NullPresenceCheck extends ModelElement implements PresenceCheck { + + private final String sourceReference; + + public NullPresenceCheck(String sourceReference) { + this.sourceReference = sourceReference; + } + + public String getSourceReference() { + return sourceReference; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + NullPresenceCheck that = (NullPresenceCheck) o; + return Objects.equals( sourceReference, that.sourceReference ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceReference ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java new file mode 100644 index 0000000000..374eac0c8e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class SourceReferenceMethodPresenceCheck extends ModelElement implements PresenceCheck { + + private final String sourceReference; + private final String methodName; + + public SourceReferenceMethodPresenceCheck(String sourceReference, String methodName) { + this.sourceReference = sourceReference; + this.methodName = methodName; + } + + public String getSourceReference() { + return sourceReference; + } + + public String getMethodName() { + return methodName; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SourceReferenceMethodPresenceCheck that = (SourceReferenceMethodPresenceCheck) o; + return Objects.equals( sourceReference, that.sourceReference ) && + Objects.equals( methodName, that.methodName ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceReference, methodName ); + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 22dc2d8c37..ce6dab0714 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -11,13 +11,13 @@ return ${returnType.null}; } <#list propertyEntries as entry> - <#if entry.presenceCheckerName?? > - if ( <#if entry_index != 0><@localVarName index=entry_index/> == null || !<@localVarName index=entry_index/>.${entry.presenceCheckerName}() ) { + <#if entry.presenceChecker?? > + if ( <#if entry_index != 0>${entry.previousPropertyName} == null || !<@includeModel object=entry.presenceChecker /> ) { return ${returnType.null}; } - <@includeModel object=entry.type.typeBound/> ${entry.name} = <@localVarName index=entry_index/>.${entry.accessorName}; - <#if !entry.presenceCheckerName?? > + <@includeModel object=entry.type.typeBound/> ${entry.name} = ${entry.previousPropertyName}.${entry.accessorName}; + <#if !entry.presenceChecker?? > <#if !entry.type.primitive> if ( ${entry.name} == null ) { return ${returnType.null}; @@ -29,7 +29,6 @@ } -<#macro localVarName index><#if index == 0>${sourceParameter.name}<#else>${propertyEntries[index-1].name} <#macro throws> <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> <#list thrownTypes as exceptionType> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index de456ca773..048402401b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -15,7 +15,7 @@ --> <#macro handleSourceReferenceNullCheck> <#if sourcePresenceCheckerReference??> - if ( ${sourcePresenceCheckerReference} ) { + if ( <@includeModel object=sourcePresenceCheckerReference /> ) { <#nested> } <@elseDefaultAssignment/> @@ -57,7 +57,7 @@ --> <#macro handleLocalVarNullCheck needs_explicit_local_var> <#if sourcePresenceCheckerReference??> - if ( ${sourcePresenceCheckerReference} ) { + if ( <@includeModel object=sourcePresenceCheckerReference /> ) { <#if needs_explicit_local_var> <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; <#nested> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.ftl new file mode 100644 index 0000000000..d0c81ff2ce --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.ftl @@ -0,0 +1,16 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck" --> +<@compress single_line=true> +<#list presenceChecks as presenceCheck> + <#if presenceCheck_index != 0> + && + + <@includeModel object=presenceCheck /> + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl new file mode 100644 index 0000000000..6e5494c735 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.NullPresenceCheck" --> +${sourceReference} != null \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl new file mode 100644 index 0000000000..930d5e24bc --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck" --> +${sourceReference}.${methodName}() \ No newline at end of file From 51cdbd67e3f6b65ca2f3879f333661be2c5d215b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 4 Apr 2021 19:36:46 +0200 Subject: [PATCH 0566/1006] #2051, #2084 Add new `@Condition` annotation for custom presence check methods --- .../main/java/org/mapstruct/Condition.java | 78 ++++++ core/src/main/java/org/mapstruct/Mapping.java | 68 ++++++ ...apter-10-advanced-mapping-options.asciidoc | 72 ++++++ .../ap/internal/gem/GemGenerator.java | 2 + .../ap/internal/model/BeanMappingMethod.java | 1 + .../model/MethodReferencePresenceCheck.java | 51 ++++ .../model/PresenceCheckMethodResolver.java | 149 ++++++++++++ .../ap/internal/model/PropertyMapping.java | 61 ++++- .../ap/internal/model/common/SourceRHS.java | 7 +- .../AllPresenceChecksPresenceCheck.java | 1 - .../presence/JavaExpressionPresenceCheck.java | 52 ++++ .../internal/model/source/MappingOptions.java | 35 +++ .../ap/internal/model/source/Method.java | 8 + .../model/source/SelectionParameters.java | 64 ++++- .../internal/model/source/SourceMethod.java | 22 ++ .../selector/CreateOrUpdateSelector.java | 3 +- .../source/selector/MethodFamilySelector.java | 4 +- .../source/selector/MethodSelectors.java | 1 + .../source/selector/SelectionCriteria.java | 55 +++-- .../source/selector/SourceRhsSelector.java | 49 ++++ .../model/source/selector/TypeSelector.java | 2 +- .../processor/MethodRetrievalProcessor.java | 19 +- .../mapstruct/ap/internal/util/Message.java | 2 + .../model/MethodReferencePresenceCheck.ftl | 9 + .../presence/JavaExpressionPresenceCheck.ftl | 9 + .../ap/test/conditional/Employee.java | 36 +++ .../ap/test/conditional/EmployeeDto.java | 36 +++ .../test/conditional/basic/BasicEmployee.java | 22 ++ .../conditional/basic/BasicEmployeeDto.java | 32 +++ .../basic/ConditionalMappingTest.java | 229 ++++++++++++++++++ ...ionalMethodAndBeanPresenceCheckMapper.java | 44 ++++ .../ConditionalMethodForCollectionMapper.java | 81 +++++++ .../ConditionalMethodInContextMapper.java | 29 +++ .../basic/ConditionalMethodInMapper.java | 26 ++ .../basic/ConditionalMethodInUsesMapper.java | 30 +++ .../ConditionalMethodInUsesStaticMapper.java | 30 +++ ...thodWithSourceParameterAndValueMapper.java | 38 +++ ...tionalMethodWithSourceParameterMapper.java | 28 +++ ...neousAmbiguousConditionalMethodMapper.java | 28 +++ .../basic/OptionalLikeConditionalMapper.java | 77 ++++++ .../expression/ConditionalExpressionTest.java | 97 ++++++++ .../ConditionalMethodsInUtilClassMapper.java | 38 +++ .../ErroneousConditionExpressionMapper.java | 21 ++ .../SimpleConditionalExpressionMapper.java | 46 ++++ ...tionalMethodWithClassQualifiersMapper.java | 63 +++++ ...tionalMethodWithSourceParameterMapper.java | 48 ++++ .../qualifier/ConditionalQualifierTest.java | 92 +++++++ .../basic/ConditionalMethodInMapperImpl.java | 31 +++ ...WithSourceParameterAndValueMapperImpl.java | 31 +++ 49 files changed, 2015 insertions(+), 42 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/Condition.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/Employee.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/EmployeeDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployee.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployeeDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodAndBeanPresenceCheckMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForCollectionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInContextMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesStaticMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousConditionalMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/OptionalLikeConditionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalMethodsInUtilClassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/expression/SimpleConditionalExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithClassQualifiersMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceParameterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/Condition.java b/core/src/main/java/org/mapstruct/Condition.java new file mode 100644 index 0000000000..ec1bf06a88 --- /dev/null +++ b/core/src/main/java/org/mapstruct/Condition.java @@ -0,0 +1,78 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation marks a method as a presence check method to check check for presence in beans. + *

      + * By default bean properties are checked against {@code null} or using a presence check method in the source bean. + * If a presence check method is available then it will be used instead. + *

      + * Presence check methods have to return {@code boolean}. + * The following parameters are accepted for the presence check methods: + *

        + *
      • The parameter with the value of the source property. + * e.g. the value given by calling {@code getName()} for the name property of the source bean
      • + *
      • The mapping source parameter
      • + *
      • {@code @}{@link Context} parameter
      • + *
      + * + * Note: The usage of this annotation is mandatory + * for a method to be considered as a presence check method. + * + *
      
      + * public class PresenceCheckUtils {
      + *
      + *   @Condition
      + *   public static boolean isNotEmpty(String value) {
      + *      return value != null && !value.isEmpty();
      + *   }
      + * }
      + *
      + * @Mapper(uses = PresenceCheckUtils.class)
      + * public interface MovieMapper {
      + *
      + *     MovieDto map(Movie movie);
      + * }
      + * 
      + * + * The following implementation of {@code MovieMapper} will be generated: + * + *
      + * 
      + * public class MovieMapperImpl implements MovieMapper {
      + *
      + *     @Override
      + *     public MovieDto map(Movie movie) {
      + *         if ( movie == null ) {
      + *             return null;
      + *         }
      + *
      + *         MovieDto movieDto = new MovieDto();
      + *
      + *         if ( PresenceCheckUtils.isNotEmpty( movie.getTitle() ) ) {
      + *             movieDto.setTitle( movie.getTitle() );
      + *         }
      + *
      + *         return movieDto;
      + *     }
      + * }
      + * 
      + * 
      + * + * @author Filip Hrisafov + * @since 1.5 + */ +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.CLASS) +public @interface Condition { + +} diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index b5ce5c7a83..b4bfa30d88 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -316,6 +316,74 @@ */ String[] qualifiedByName() default { }; + /** + * A qualifier can be specified to aid the selection process of a suitable presence check method. + * This is useful in case multiple presence check methods qualify and thus would result in an + * 'Ambiguous presence check methods found' error. + * A qualifier is a custom annotation and can be placed on a hand written mapper class or a method. + * This is similar to the {@link #qualifiedBy()}, but it is only applied for {@link Condition} methods. + * + * @return the qualifiers + * @see Qualifier + * @see #qualifiedBy() + * @since 1.5 + */ + Class[] conditionQualifiedBy() default { }; + + /** + * String-based form of qualifiers for condition / presence check methods; + * When looking for a suitable presence check method for a given property, MapStruct will + * only consider those methods carrying directly or indirectly (i.e. on the class-level) a {@link Named} annotation + * for each of the specified qualifier names. + * + * This is similar like {@link #qualifiedByName()} but it is only applied for {@link Condition} methods. + *

      + * Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and + * are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large + * number of qualifiers as no custom annotation types are needed. + *

      + * + * + * @return One or more qualifier name(s) + * @see #conditionQualifiedBy() + * @see #qualifiedByName() + * @see Named + * @since 1.5 + */ + String[] conditionQualifiedByName() default { }; + + /** + * A conditionExpression {@link String} based on which the specified property is to be checked + * whether it is present or not. + *

      + * Currently, Java is the only supported "expression language" and expressions must be given in form of Java + * expressions using the following format: {@code java()}. For instance the mapping: + *

      
      +     * @Mapping(
      +     *     target = "someProp",
      +     *     conditionExpression = "java(s.getAge() < 18)"
      +     * )
      +     * 
      + *

      + * will cause the following target property assignment to be generated: + *

      
      +     *     if (s.getAge() < 18) {
      +     *         targetBean.setSomeProp( s.getSomeProp() );
      +     *     }
      +     * 
      + *

      + *

      + * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be + * imported via {@link Mapper#imports()}. + *

      + * This attribute can not be used together with {@link #expression()} or {@link #constant()}. + * + * @return An expression specifying a condition check for the designated property + * + * @since 1.5 + */ + String conditionExpression() default ""; + /** * Specifies the result type of the mapping method to be used in case multiple mapping methods qualify. * diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 158aa632f9..d3ab2424b1 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -229,6 +229,78 @@ The source presence checker name can be changed in the MapStruct service provide Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property null check, regardless the value of the `NullValueCheckStrategy` to avoid addition of `null` to the target collection or map. ==== + +[[conditional-mapping]] +=== Conditional Mapping + +Conditional Mapping is a type of <>. +The difference is that it allows users to write custom condition methods that will be invoked to check if a property needs to be mapped or not. + +A custom condition method is a method that is annotated with `org.mapstruct.Condition` and returns `boolean`. + +e.g. if you only want to map a String property when it is not `null, and it is not empty then you can do something like: + +.Mapper using custom condition check method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarDto carToCarDto(Car car); + + @Condition + default boolean isNotEmpty(String value) { + return value != null && !value.isEmpty(); + } +} +---- +==== + +The generated mapper will look like: + +.try-catch block in generated implementation +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + if ( isNotEmpty( car.getOwner() ) ) { + carDto.setOwner( car.getOwner() ); + } + + // Mapping of other properties + + return carDto; + } +} +---- +==== + +[IMPORTANT] +==== +If there is a custom `@Condition` method applicable for the property it will have a precedence over a presence check method in the bean itself. +==== + +[NOTE] +==== +Methods annotated with `@Condition` in addition to the value of the source property can also have the source parameter as an input. +==== + +<> is also valid for `@Condition` methods. +In order to use a more specific condition method you will need to use one of `Mapping#conditionQualifiedByName` or `Mapping#conditionQualifiedBy`. + [[exceptions]] === Exceptions diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 524ea995d3..f8bdbc539d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -12,6 +12,7 @@ import org.mapstruct.BeanMapping; import org.mapstruct.BeforeMapping; import org.mapstruct.Builder; +import org.mapstruct.Condition; import org.mapstruct.Context; import org.mapstruct.DecoratedWith; import org.mapstruct.EnumMapping; @@ -61,6 +62,7 @@ @GemDefinition(ValueMappings.class) @GemDefinition(Context.class) @GemDefinition(Builder.class) +@GemDefinition(Condition.class) @GemDefinition(MappingControl.class) @GemDefinition(MappingControls.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0ce80c993c..2e82366f8b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1155,6 +1155,7 @@ else if ( mapping.getJavaExpression() != null ) { .dependsOn( mapping.getDependsOn() ) .defaultValue( mapping.getDefaultValue() ) .defaultJavaExpression( mapping.getDefaultJavaExpression() ) + .conditionJavaExpression( mapping.getConditionJavaExpression() ) .mirror( mapping.getMirror() ) .options( mapping ) .build(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java new file mode 100644 index 0000000000..e6adceab03 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class MethodReferencePresenceCheck extends ModelElement implements PresenceCheck { + + protected final MethodReference methodReference; + + public MethodReferencePresenceCheck(MethodReference methodReference) { + this.methodReference = methodReference; + } + + @Override + public Set getImportTypes() { + return methodReference.getImportTypes(); + } + + public MethodReference getMethodReference() { + return methodReference; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + MethodReferencePresenceCheck that = (MethodReferencePresenceCheck) o; + return Objects.equals( methodReference, that.methodReference ); + } + + @Override + public int hashCode() { + return Objects.hash( methodReference ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java new file mode 100644 index 0000000000..9d4910bdce --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -0,0 +1,149 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; +import org.mapstruct.ap.internal.model.source.SelectionParameters; +import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; +import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.util.Message; + +/** + * @author Filip Hrisafov + */ +public final class PresenceCheckMethodResolver { + + private PresenceCheckMethodResolver() { + + } + + public static PresenceCheck getPresenceCheck( + Method method, + SelectionParameters selectionParameters, + MappingBuilderContext ctx + ) { + SelectedMethod matchingMethod = findMatchingPresenceCheckMethod( + method, + selectionParameters, + ctx + ); + + if ( matchingMethod == null ) { + return null; + } + + MethodReference methodReference = getPresenceCheckMethodReference( method, matchingMethod, ctx ); + + return new MethodReferencePresenceCheck( methodReference ); + + } + + private static SelectedMethod findMatchingPresenceCheckMethod( + Method method, + SelectionParameters selectionParameters, + MappingBuilderContext ctx + ) { + MethodSelectors selectors = new MethodSelectors( + ctx.getTypeUtils(), + ctx.getElementUtils(), + ctx.getTypeFactory(), + ctx.getMessager() + ); + + Type booleanType = ctx.getTypeFactory().getType( Boolean.class ); + List> matchingMethods = selectors.getMatchingMethods( + method, + getAllAvailableMethods( method, ctx.getSourceModel() ), + Collections.emptyList(), + booleanType, + booleanType, + SelectionCriteria.forPresenceCheckMethods( selectionParameters ) + ); + + if ( matchingMethods.isEmpty() ) { + return null; + } + + if ( matchingMethods.size() > 1 ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD, + selectionParameters.getSourceRHS().getSourceType().describe(), + matchingMethods.stream() + .map( SelectedMethod::getMethod ) + .map( Method::describe ) + .collect( Collectors.joining( ", " ) ) + ); + + return null; + } + + return matchingMethods.get( 0 ); + } + + private static MethodReference getPresenceCheckMethodReference( + Method method, + SelectedMethod matchingMethod, + MappingBuilderContext ctx + ) { + + Parameter providingParameter = + method.getContextProvidedMethods().getParameterForProvidedMethod( matchingMethod.getMethod() ); + if ( providingParameter != null ) { + return MethodReference.forParameterProvidedMethod( + matchingMethod.getMethod(), + providingParameter, + matchingMethod.getParameterBindings() + ); + } + else { + MapperReference ref = MapperReference.findMapperReference( + ctx.getMapperReferences(), + matchingMethod.getMethod() + ); + + return MethodReference.forMapperReference( + matchingMethod.getMethod(), + ref, + matchingMethod.getParameterBindings() + ); + } + } + + private static List getAllAvailableMethods(Method method, List sourceModelMethods) { + ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods(); + if ( contextProvidedMethods.isEmpty() ) { + return sourceModelMethods; + } + + List methodsProvidedByParams = contextProvidedMethods + .getAllProvidedMethodsInParameterOrder( method.getContextParameters() ); + + List availableMethods = + new ArrayList<>( methodsProvidedByParams.size() + sourceModelMethods.size() ); + + for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { + // add only methods from context that do have the @Condition annotation + if ( methodProvidedByParams.isPresenceCheck() ) { + availableMethods.add( methodProvidedByParams ); + } + } + availableMethods.addAll( sourceModelMethods ); + + return availableMethods; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index d1d7eaebd5..b53b8f90ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -13,6 +13,9 @@ import java.util.Set; import javax.lang.model.element.AnnotationMirror; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.model.assignment.AdderWrapper; import org.mapstruct.ap.internal.model.assignment.ArrayCopyWrapper; import org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper; @@ -32,6 +35,7 @@ import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck; +import org.mapstruct.ap.internal.model.presence.JavaExpressionPresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; import org.mapstruct.ap.internal.model.source.DelegatingOptions; @@ -40,9 +44,6 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; -import org.mapstruct.ap.internal.gem.BuilderGem; -import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; -import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; @@ -52,12 +53,12 @@ import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL; import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; import static org.mapstruct.ap.internal.model.ForgedMethod.forParameterMapping; import static org.mapstruct.ap.internal.model.ForgedMethod.forPropertyMapping; import static org.mapstruct.ap.internal.model.common.Assignment.AssignmentType.DIRECT; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL; /** * Represents the mapping between a source and target property, e.g. from {@code String Source#foo} to @@ -142,6 +143,7 @@ public static class PropertyMappingBuilder extends MappingBuilderBase existingVariableNames; private final String sourceErrorMessagePart; - private final PresenceCheck sourcePresenceCheckerReference; + private PresenceCheck sourcePresenceCheckerReference; private boolean useElementAsSourceTypeForMatching = false; private final String sourceParameterName; @@ -65,6 +64,10 @@ public PresenceCheck getSourcePresenceCheckerReference() { return sourcePresenceCheckerReference; } + public void setSourcePresenceCheckerReference(PresenceCheck sourcePresenceCheckerReference) { + this.sourcePresenceCheckerReference = sourcePresenceCheckerReference; + } + @Override public Type getSourceType() { return sourceType; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java index 4ee62cf542..df8b008032 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.model.presence; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; import java.util.Objects; import java.util.Set; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java new file mode 100644 index 0000000000..d4f52c9f27 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class JavaExpressionPresenceCheck extends ModelElement implements PresenceCheck { + + private final String javaExpression; + + public JavaExpressionPresenceCheck(String javaExpression) { + this.javaExpression = javaExpression; + } + + public String getJavaExpression() { + return javaExpression; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + JavaExpressionPresenceCheck that = (JavaExpressionPresenceCheck) o; + return Objects.equals( javaExpression, that.javaExpression ); + } + + @Override + public int hashCode() { + return Objects.hash( javaExpression ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 9db1b1c04c..d7d6ad6291 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -43,6 +43,7 @@ public class MappingOptions extends DelegatingOptions { private final String constant; private final String javaExpression; private final String defaultJavaExpression; + private final String conditionJavaExpression; private final String targetName; private final String defaultValue; private final FormattingParameters formattingParameters; @@ -114,6 +115,7 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, String constant = mapping.constant().getValue(); String expression = getExpression( mapping, method, messager ); String defaultExpression = getDefaultExpression( mapping, method, messager ); + String conditionExpression = getConditionExpression( mapping, method, messager ); String dateFormat = mapping.dateFormat().getValue(); String numberFormat = mapping.numberFormat().getValue(); String defaultValue = mapping.defaultValue().getValue(); @@ -132,6 +134,8 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, SelectionParameters selectionParams = new SelectionParameters( mapping.qualifiedBy().get(), mapping.qualifiedByName().get(), + mapping.conditionQualifiedBy().get(), + mapping.conditionQualifiedByName().get(), mapping.resultType().getValue(), typeUtils ); @@ -145,6 +149,7 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, constant, expression, defaultExpression, + conditionExpression, defaultValue, mapping.ignore().get(), formattingParam, @@ -174,6 +179,7 @@ public static MappingOptions forIgnore(String targetName) { null, null, null, + null, true, null, null, @@ -261,6 +267,7 @@ private MappingOptions(String targetName, String constant, String javaExpression, String defaultJavaExpression, + String conditionJavaExpression, String defaultValue, boolean isIgnored, FormattingParameters formattingParameters, @@ -279,6 +286,7 @@ private MappingOptions(String targetName, this.constant = constant; this.javaExpression = javaExpression; this.defaultJavaExpression = defaultJavaExpression; + this.conditionJavaExpression = conditionJavaExpression; this.defaultValue = defaultValue; this.isIgnored = isIgnored; this.formattingParameters = formattingParameters; @@ -330,6 +338,27 @@ private static String getDefaultExpression(MappingGem mapping, ExecutableElement return javaExpressionMatcher.group( 1 ).trim(); } + private static String getConditionExpression(MappingGem mapping, ExecutableElement element, + FormattingMessager messager) { + if ( !mapping.conditionExpression().hasValue() ) { + return null; + } + + Matcher javaExpressionMatcher = JAVA_EXPRESSION.matcher( mapping.conditionExpression().get() ); + + if ( !javaExpressionMatcher.matches() ) { + messager.printMessage( + element, + mapping.mirror(), + mapping.conditionExpression().getAnnotationValue(), + Message.PROPERTYMAPPING_INVALID_CONDITION_EXPRESSION + ); + return null; + } + + return javaExpressionMatcher.group( 1 ).trim(); + } + public String getTargetName() { return targetName; } @@ -364,6 +393,10 @@ public String getDefaultJavaExpression() { return defaultJavaExpression; } + public String getConditionJavaExpression() { + return conditionJavaExpression; + } + public String getDefaultValue() { return defaultValue; } @@ -452,6 +485,7 @@ public MappingOptions copyForInverseInheritance(SourceMethod templateMethod, null, // constant null, // expression null, // defaultExpression + null, // conditionExpression null, isIgnored, formattingParameters, @@ -481,6 +515,7 @@ public MappingOptions copyForForwardInheritance(SourceMethod templateMethod, constant, javaExpression, defaultJavaExpression, + conditionJavaExpression, defaultValue, isIgnored, formattingParameters, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 8a38ed2acb..0c60f41364 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -90,6 +90,14 @@ public interface Method { */ boolean isObjectFactory(); + /** + * Returns whether the method is designated as a presence check method + * @return {@code true} if it is a presence check method + */ + default boolean isPresenceCheck() { + return false; + } + /** * Returns the parameter designated as target type (if present) {@link org.mapstruct.TargetType } * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index a78409582d..697f0d9e4a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -23,6 +23,8 @@ public class SelectionParameters { private final List qualifiers; private final List qualifyingNames; + private final List conditionQualifiers; + private final List conditionQualifyingNames; private final TypeMirror resultType; private final TypeUtils typeUtils; private final SourceRHS sourceRHS; @@ -39,6 +41,8 @@ public static SelectionParameters forInheritance(SelectionParameters selectionPa return new SelectionParameters( selectionParameters.qualifiers, selectionParameters.qualifyingNames, + selectionParameters.conditionQualifiers, + selectionParameters.conditionQualifyingNames, null, selectionParameters.typeUtils ); @@ -46,13 +50,32 @@ public static SelectionParameters forInheritance(SelectionParameters selectionPa public SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, TypeUtils typeUtils) { - this( qualifiers, qualifyingNames, resultType, typeUtils, null ); + this( + qualifiers, + qualifyingNames, + Collections.emptyList(), + Collections.emptyList(), + resultType, + typeUtils, + null + ); } - private SelectionParameters(List qualifiers, List qualifyingNames, TypeMirror resultType, + public SelectionParameters(List qualifiers, List qualifyingNames, + List conditionQualifiers, List conditionQualifyingNames, + TypeMirror resultType, + TypeUtils typeUtils) { + this( qualifiers, qualifyingNames, conditionQualifiers, conditionQualifyingNames, resultType, typeUtils, null ); + } + + private SelectionParameters(List qualifiers, List qualifyingNames, + List conditionQualifiers, List conditionQualifyingNames, + TypeMirror resultType, TypeUtils typeUtils, SourceRHS sourceRHS) { this.qualifiers = qualifiers; this.qualifyingNames = qualifyingNames; + this.conditionQualifiers = conditionQualifiers; + this.conditionQualifyingNames = conditionQualifyingNames; this.resultType = resultType; this.typeUtils = typeUtils; this.sourceRHS = sourceRHS; @@ -74,6 +97,21 @@ public List getQualifyingNames() { return qualifyingNames; } + /** + * @return qualifiers used for further select the appropriate presence check method based on class and name + */ + public List getConditionQualifiers() { + return conditionQualifiers; + } + + /** + * @return qualifyingNames, used in combination with with @Named + * @see #getConditionQualifiers() + */ + public List getConditionQualifyingNames() { + return conditionQualifyingNames; + } + /** * * @return resultType used for further select the appropriate mapping method based on resultType (bean mapping) @@ -119,6 +157,14 @@ public boolean equals(Object obj) { return false; } + if ( !Objects.equals( this.conditionQualifiers, other.conditionQualifiers ) ) { + return false; + } + + if ( !Objects.equals( this.conditionQualifyingNames, other.conditionQualifyingNames ) ) { + return false; + } + if ( !Objects.equals( this.sourceRHS, other.sourceRHS ) ) { return false; } @@ -151,8 +197,22 @@ private boolean equals(TypeMirror mirror1, TypeMirror mirror2) { } } + public SelectionParameters withSourceRHS(SourceRHS sourceRHS) { + return new SelectionParameters( + this.qualifiers, + this.qualifyingNames, + this.conditionQualifiers, + this.conditionQualifyingNames, + null, + this.typeUtils, + sourceRHS + ); + } + public static SelectionParameters forSourceRHS(SourceRHS sourceRHS) { return new SelectionParameters( + Collections.emptyList(), + Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 83898d4b38..86f19618d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -14,6 +14,8 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; + +import org.mapstruct.ap.internal.gem.ConditionGem; import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Accessibility; @@ -47,6 +49,7 @@ public class SourceMethod implements Method { private final Parameter mappingTargetParameter; private final Parameter targetTypeParameter; private final boolean isObjectFactory; + private final boolean isPresenceCheck; private final Type returnType; private final Accessibility accessibility; private final List exceptionTypes; @@ -230,6 +233,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null; this.isObjectFactory = determineIfIsObjectFactory(); + this.isPresenceCheck = determineIfIsPresenceCheck(); this.typeUtils = builder.typeUtils; this.typeFactory = builder.typeFactory; @@ -247,6 +251,19 @@ private boolean determineIfIsObjectFactory() { && ( hasObjectFactoryAnnotation || hasNoSourceParameters ); } + private boolean determineIfIsPresenceCheck() { + if ( returnType.isPrimitive() ) { + if ( !returnType.getName().equals( "boolean" ) ) { + return false; + } + } + else if ( !returnType.getFullyQualifiedName().equals( Boolean.class.getCanonicalName() ) ) { + return false; + } + + return ConditionGem.instanceOn( executable ) != null; + } + @Override public Type getDeclaringMapper() { return declaringMapper; @@ -519,6 +536,11 @@ public boolean isLifecycleCallbackMethod() { return Executables.isLifecycleCallbackMethod( getExecutable() ); } + @Override + public boolean isPresenceCheck() { + return isPresenceCheck; + } + public boolean isAfterMappingMethod() { return Executables.isAfterMappingMethod( getExecutable() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index 0e24774025..ed1c72ab2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -36,7 +36,8 @@ public List> getMatchingMethods(Method mapp Type returnType, SelectionCriteria criteria) { - if ( criteria.isLifecycleCallbackRequired() || criteria.isObjectFactoryRequired() ) { + if ( criteria.isLifecycleCallbackRequired() || criteria.isObjectFactoryRequired() + || criteria.isPresenceCheckRequired() ) { return methods; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index 7e7925ca0e..37502ec56d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -30,7 +30,9 @@ public List> getMatchingMethods(Method mapp List> result = new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { if ( method.getMethod().isObjectFactory() == criteria.isObjectFactoryRequired() - && method.getMethod().isLifecycleCallbackMethod() == criteria.isLifecycleCallbackRequired() ) { + && method.getMethod().isLifecycleCallbackMethod() == criteria.isLifecycleCallbackRequired() + && method.getMethod().isPresenceCheck() == criteria.isPresenceCheckRequired() + ) { result.add( method ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index b88de4f225..de429174da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -35,6 +35,7 @@ public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFacto new XmlElementDeclSelector( typeUtils ), new InheritanceSelector(), new CreateOrUpdateSelector(), + new SourceRhsSelector(), new FactoryParameterSelector() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 23c67b230e..b70e94b6d1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -26,20 +26,23 @@ public class SelectionCriteria { private final String targetPropertyName; private final TypeMirror qualifyingResultType; private final SourceRHS sourceRHS; - private boolean preferUpdateMapping; - private final boolean objectFactoryRequired; - private final boolean lifecycleCallbackRequired; + private Type type; private final boolean allowDirect; private final boolean allowConversion; private final boolean allowMappingMethod; private final boolean allow2Steps; public SelectionCriteria(SelectionParameters selectionParameters, MappingControl mappingControl, - String targetPropertyName, boolean preferUpdateMapping, boolean objectFactoryRequired, - boolean lifecycleCallbackRequired) { + String targetPropertyName, Type type) { if ( selectionParameters != null ) { - qualifiers.addAll( selectionParameters.getQualifiers() ); - qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); + if ( type == Type.PRESENCE_CHECK ) { + qualifiers.addAll( selectionParameters.getConditionQualifiers() ); + qualifiedByNames.addAll( selectionParameters.getConditionQualifyingNames() ); + } + else { + qualifiers.addAll( selectionParameters.getQualifiers() ); + qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); + } qualifyingResultType = selectionParameters.getResultType(); sourceRHS = selectionParameters.getSourceRHS(); } @@ -60,23 +63,28 @@ public SelectionCriteria(SelectionParameters selectionParameters, MappingControl this.allow2Steps = true; } this.targetPropertyName = targetPropertyName; - this.preferUpdateMapping = preferUpdateMapping; - this.objectFactoryRequired = objectFactoryRequired; - this.lifecycleCallbackRequired = lifecycleCallbackRequired; + this.type = type; } /** * @return true if factory methods should be selected, false otherwise. */ public boolean isObjectFactoryRequired() { - return objectFactoryRequired; + return type == Type.OBJECT_FACTORY; } /** * @return true if lifecycle callback methods should be selected, false otherwise. */ public boolean isLifecycleCallbackRequired() { - return lifecycleCallbackRequired; + return type == Type.LIFECYCLE_CALLBACK; + } + + /** + * @return {@code true} if presence check methods should be selected, {@code false} otherwise + */ + public boolean isPresenceCheckRequired() { + return type == Type.PRESENCE_CHECK; } public List getQualifiers() { @@ -96,7 +104,7 @@ public TypeMirror getQualifyingResultType() { } public boolean isPreferUpdateMapping() { - return preferUpdateMapping; + return type == Type.PREFER_UPDATE_MAPPING; } public SourceRHS getSourceRHS() { @@ -104,7 +112,7 @@ public SourceRHS getSourceRHS() { } public void setPreferUpdateMapping(boolean preferUpdateMapping) { - this.preferUpdateMapping = preferUpdateMapping; + this.type = preferUpdateMapping ? Type.PREFER_UPDATE_MAPPING : null; } public boolean hasQualfiers() { @@ -135,17 +143,26 @@ public static SelectionCriteria forMappingMethods(SelectionParameters selectionP selectionParameters, mappingControl, targetPropertyName, - preferUpdateMapping, - false, - false + preferUpdateMapping ? Type.PREFER_UPDATE_MAPPING : null ); } public static SelectionCriteria forFactoryMethods(SelectionParameters selectionParameters) { - return new SelectionCriteria( selectionParameters, null, null, false, true, false ); + return new SelectionCriteria( selectionParameters, null, null, Type.OBJECT_FACTORY ); } public static SelectionCriteria forLifecycleMethods(SelectionParameters selectionParameters) { - return new SelectionCriteria( selectionParameters, null, null, false, false, true ); + return new SelectionCriteria( selectionParameters, null, null, Type.LIFECYCLE_CALLBACK ); + } + + public static SelectionCriteria forPresenceCheckMethods(SelectionParameters selectionParameters) { + return new SelectionCriteria( selectionParameters, null, null, Type.PRESENCE_CHECK ); + } + + public enum Type { + PREFER_UPDATE_MAPPING, + OBJECT_FACTORY, + LIFECYCLE_CALLBACK, + PRESENCE_CHECK, } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java new file mode 100644 index 0000000000..930ce2d403 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * Selector that tries to resolve an ambiquity between methods that contain source parameters and + * {@link org.mapstruct.ap.internal.model.common.SourceRHS SourceRHS} type parameters. + * @author Filip Hrisafov + */ +public class SourceRhsSelector implements MethodSelector { + + @Override + public List> getMatchingMethods(Method mappingMethod, + List> candidates, + List sourceTypes, Type mappingTargetType, + Type returnType, SelectionCriteria criteria) { + if ( candidates.size() < 2 || criteria.getSourceRHS() == null ) { + return candidates; + } + + List> sourceRHSFavoringCandidates = new ArrayList<>(); + + for ( SelectedMethod candidate : candidates ) { + for ( ParameterBinding parameterBinding : candidate.getParameterBindings() ) { + if ( parameterBinding.getSourceRHS() != null ) { + sourceRHSFavoringCandidates.add( candidate ); + break; + } + } + + } + + if ( !sourceRHSFavoringCandidates.isEmpty() ) { + return sourceRHSFavoringCandidates; + } + + return candidates; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 3d0bd4b9b4..74e518c84d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -89,7 +89,7 @@ private List getAvailableParameterBindingsFromMethod(Method me List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); if ( sourceRHS != null ) { - availableParams.addAll( ParameterBinding.fromParameters( method.getContextParameters() ) ); + availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index b959a15dc0..c6e510d315 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -23,6 +23,7 @@ import javax.lang.model.type.TypeKind; import org.mapstruct.ap.internal.gem.BeanMappingGem; +import org.mapstruct.ap.internal.gem.ConditionGem; import org.mapstruct.ap.internal.gem.IterableMappingGem; import org.mapstruct.ap.internal.gem.MapMappingGem; import org.mapstruct.ap.internal.gem.MappingGem; @@ -225,7 +226,8 @@ private SourceMethod getMethod(TypeElement usedMapper, } // otherwise add reference to existing mapper method else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( method, parameters, returnType ) - || isValidLifecycleCallbackMethod( method ) ) { + || isValidLifecycleCallbackMethod( method ) + || isValidPresenceCheckMethod( method, returnType ) ) { return getReferencedMethod( usedMapper, methodType, method, mapperToImplement, parameters ); } else { @@ -333,7 +335,8 @@ private ParameterProvidedMethods retrieveContextProvidedMethods( List contextProvidedMethods = new ArrayList<>( contextParamMethods.size() ); for ( SourceMethod sourceMethod : contextParamMethods ) { - if ( sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() ) { + if ( sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() + || sourceMethod.isPresenceCheck() ) { contextProvidedMethods.add( sourceMethod ); } } @@ -389,10 +392,22 @@ private boolean hasFactoryAnnotation(ExecutableElement method) { return ObjectFactoryGem.instanceOn( method ) != null; } + private boolean isValidPresenceCheckMethod(ExecutableElement method, Type returnType) { + return isBoolean( returnType ) && hasConditionAnnotation( method ); + } + + private boolean hasConditionAnnotation(ExecutableElement method) { + return ConditionGem.instanceOn( method ) != null; + } + private boolean isVoid(Type returnType) { return returnType.getTypeMirror().getKind() == TypeKind.VOID; } + private boolean isBoolean(Type returnType) { + return Boolean.class.getCanonicalName().equals( returnType.getBoxedEquivalent().getFullyQualifiedName() ); + } + private boolean isValidReferencedOrFactoryMethod(int sourceParamCount, int targetParamCount, List parameters) { int validSourceParameters = 0; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index e30407ea20..50aeb701d8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -66,6 +66,7 @@ public enum Message { PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED("Expression and a qualifier both defined in @Mapping, either define an expression or a qualifier."), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), + PROPERTYMAPPING_INVALID_CONDITION_EXPRESSION( "Value for condition expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no source parameter named \"%s\". Method source parameters are: \"%s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s). Did you mean \"%s\"?" ), @@ -120,6 +121,7 @@ public enum Message { GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), + GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD( "Ambiguous presence check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl new file mode 100644 index 0000000000..44ec296736 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> +<@includeModel object=methodReference/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.ftl new file mode 100644 index 0000000000..447fa375cf --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.JavaExpressionPresenceCheck" --> +${javaExpression} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/Employee.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/Employee.java new file mode 100644 index 0000000000..ab7cdf4adf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/Employee.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional; + +public class Employee { + private String name; + private String ssid; + private String nin; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSsid() { + return ssid; + } + + public void setSsid(String ssid) { + this.ssid = ssid; + } + + public String getNin() { + return nin; + } + + public void setNin(String nin) { + this.nin = nin; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/EmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/EmployeeDto.java new file mode 100644 index 0000000000..f8b9b319fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/EmployeeDto.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional; + +public class EmployeeDto { + private String name; + private String country; + private String uniqueIdNumber; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getUniqueIdNumber() { + return uniqueIdNumber; + } + + public void setUniqueIdNumber(String uniqueIdNumber) { + this.uniqueIdNumber = uniqueIdNumber; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployee.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployee.java new file mode 100644 index 0000000000..9fcaa6e761 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployee.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +/** + * @author Filip Hrisafov + */ +public class BasicEmployee { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployeeDto.java new file mode 100644 index 0000000000..24a944137c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/BasicEmployeeDto.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +/** + * @author Filip Hrisafov + */ +public class BasicEmployeeDto { + + private final String name; + private final String strategy; + + public BasicEmployeeDto(String name) { + this( name, "default" ); + } + + public BasicEmployeeDto(String name, String strategy) { + this.name = name; + this.strategy = strategy; + } + + public String getName() { + return name; + } + + public String getStrategy() { + return strategy; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java new file mode 100644 index 0000000000..300f97bce4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java @@ -0,0 +1,229 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import java.util.Arrays; +import java.util.Collections; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2051") +@WithClasses({ + BasicEmployee.class, + BasicEmployeeDto.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ConditionalMappingTest { + + @Rule + public final GeneratedSource generatedSource = new GeneratedSource(); + + @Test + @WithClasses({ + ConditionalMethodInMapper.class + }) + public void conditionalMethodInMapper() { + generatedSource.addComparisonToFixtureFor( ConditionalMethodInMapper.class ); + ConditionalMethodInMapper mapper = ConditionalMethodInMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new BasicEmployeeDto( "Tester" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( new BasicEmployeeDto( "" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( " " ) ); + assertThat( employee.getName() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodAndBeanPresenceCheckMapper.class + }) + public void conditionalMethodAndBeanPresenceCheckMapper() { + ConditionalMethodAndBeanPresenceCheckMapper mapper = ConditionalMethodAndBeanPresenceCheckMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new ConditionalMethodAndBeanPresenceCheckMapper.EmployeeDto( "Tester" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( new ConditionalMethodAndBeanPresenceCheckMapper.EmployeeDto( "" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new ConditionalMethodAndBeanPresenceCheckMapper.EmployeeDto( " " ) ); + assertThat( employee.getName() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodInUsesMapper.class + }) + public void conditionalMethodInUsesMapper() { + ConditionalMethodInUsesMapper mapper = ConditionalMethodInUsesMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new BasicEmployeeDto( "Tester" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( new BasicEmployeeDto( "" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( " " ) ); + assertThat( employee.getName() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodInUsesStaticMapper.class + }) + public void conditionalMethodInUsesStaticMapper() { + ConditionalMethodInUsesStaticMapper mapper = ConditionalMethodInUsesStaticMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new BasicEmployeeDto( "Tester" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( new BasicEmployeeDto( "" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( " " ) ); + assertThat( employee.getName() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodInContextMapper.class + }) + public void conditionalMethodInUsesContextMapper() { + ConditionalMethodInContextMapper mapper = ConditionalMethodInContextMapper.INSTANCE; + + ConditionalMethodInContextMapper.PresenceUtils utils = new ConditionalMethodInContextMapper.PresenceUtils(); + BasicEmployee employee = mapper.map( new BasicEmployeeDto( "Tester" ), utils ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( new BasicEmployeeDto( "" ), utils ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( " " ), utils ); + assertThat( employee.getName() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodWithSourceParameterMapper.class + }) + public void conditionalMethodWithSourceParameter() { + ConditionalMethodWithSourceParameterMapper mapper = ConditionalMethodWithSourceParameterMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new BasicEmployeeDto( "Tester" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( "Tester", "map" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + } + + @Test + @WithClasses({ + ConditionalMethodWithSourceParameterAndValueMapper.class + }) + public void conditionalMethodWithSourceParameterAndValue() { + generatedSource.addComparisonToFixtureFor( ConditionalMethodWithSourceParameterAndValueMapper.class ); + ConditionalMethodWithSourceParameterAndValueMapper mapper = + ConditionalMethodWithSourceParameterAndValueMapper.INSTANCE; + + BasicEmployee employee = mapper.map( new BasicEmployeeDto( " ", "empty" ) ); + assertThat( employee.getName() ).isEqualTo( " " ); + + employee = mapper.map( new BasicEmployeeDto( " ", "blank" ) ); + assertThat( employee.getName() ).isNull(); + + employee = mapper.map( new BasicEmployeeDto( "Tester", "blank" ) ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + } + + @Test + @WithClasses({ + ErroneousAmbiguousConditionalMethodMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousAmbiguousConditionalMethodMapper.class, + line = 17, + message = "Ambiguous presence check methods found for checking String: " + + "boolean isNotBlank(String value), " + + "boolean isNotEmpty(String value). " + + "See https://mapstruct.org/faq/#ambiguous for more info." + ) + } + ) + public void ambiguousConditionalMethod() { + + } + + @Test + @WithClasses({ + ConditionalMethodForCollectionMapper.class + }) + public void conditionalMethodForCollection() { + ConditionalMethodForCollectionMapper mapper = ConditionalMethodForCollectionMapper.INSTANCE; + + ConditionalMethodForCollectionMapper.Author author = new ConditionalMethodForCollectionMapper.Author(); + ConditionalMethodForCollectionMapper.AuthorDto dto = mapper.map( author ); + + assertThat( dto.getBooks() ).isNull(); + + author.setBooks( Collections.emptyList() ); + dto = mapper.map( author ); + + assertThat( dto.getBooks() ).isNull(); + + author.setBooks( Arrays.asList( + new ConditionalMethodForCollectionMapper.Book( "Test" ), + new ConditionalMethodForCollectionMapper.Book( "Test Vol. 2" ) + ) ); + dto = mapper.map( author ); + + assertThat( dto.getBooks() ) + .extracting( ConditionalMethodForCollectionMapper.BookDto::getName ) + .containsExactly( "Test", "Test Vol. 2" ); + } + + @Test + @WithClasses({ + OptionalLikeConditionalMapper.class + }) + @IssueKey("2084") + public void optionalLikeConditional() { + OptionalLikeConditionalMapper mapper = OptionalLikeConditionalMapper.INSTANCE; + + OptionalLikeConditionalMapper.Target target = mapper.map( new OptionalLikeConditionalMapper.Source( + OptionalLikeConditionalMapper.Nullable.ofNullable( "test" ) ) ); + + assertThat( target.getValue() ).isEqualTo( "test" ); + + target = mapper.map( + new OptionalLikeConditionalMapper.Source( OptionalLikeConditionalMapper.Nullable.undefined() ) + ); + + assertThat( target.getValue() ).isEqualTo( "initial" ); + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodAndBeanPresenceCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodAndBeanPresenceCheckMapper.java new file mode 100644 index 0000000000..ad37d5832b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodAndBeanPresenceCheckMapper.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodAndBeanPresenceCheckMapper { + + ConditionalMethodAndBeanPresenceCheckMapper INSTANCE = Mappers.getMapper( + ConditionalMethodAndBeanPresenceCheckMapper.class ); + + BasicEmployee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + class EmployeeDto { + + private final String name; + + public EmployeeDto(String name) { + this.name = name; + } + + public boolean hasName() { + return false; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForCollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForCollectionMapper.java new file mode 100644 index 0000000000..a27a0aaf0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForCollectionMapper.java @@ -0,0 +1,81 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import java.util.Collection; +import java.util.List; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodForCollectionMapper { + + ConditionalMethodForCollectionMapper INSTANCE = Mappers.getMapper( ConditionalMethodForCollectionMapper.class ); + + AuthorDto map(Author author); + + @Condition + default boolean isNotEmpty(Collection collection) { + return collection != null && !collection.isEmpty(); + } + + class Author { + private List books; + + public List getBooks() { + return books; + } + + public boolean hasBooks() { + return false; + } + + public void setBooks(List books) { + this.books = books; + } + } + + class Book { + private final String name; + + public Book(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class AuthorDto { + private List books; + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } + } + + class BookDto { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInContextMapper.java new file mode 100644 index 0000000000..26ad844146 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInContextMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodInContextMapper { + + ConditionalMethodInContextMapper INSTANCE = Mappers.getMapper( ConditionalMethodInContextMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee, @Context PresenceUtils utils); + + class PresenceUtils { + @Condition + public boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapper.java new file mode 100644 index 0000000000..256419f687 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodInMapper { + + ConditionalMethodInMapper INSTANCE = Mappers.getMapper( ConditionalMethodInMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesMapper.java new file mode 100644 index 0000000000..fb30d19c80 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = ConditionalMethodInUsesMapper.PresenceUtils.class) +public interface ConditionalMethodInUsesMapper { + + ConditionalMethodInUsesMapper INSTANCE = Mappers.getMapper( ConditionalMethodInUsesMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + class PresenceUtils { + + @Condition + public boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesStaticMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesStaticMapper.java new file mode 100644 index 0000000000..5e77d6f8fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInUsesStaticMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = ConditionalMethodInUsesStaticMapper.PresenceUtils.class) +public interface ConditionalMethodInUsesStaticMapper { + + ConditionalMethodInUsesStaticMapper INSTANCE = Mappers.getMapper( ConditionalMethodInUsesStaticMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + interface PresenceUtils { + + @Condition + static boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapper.java new file mode 100644 index 0000000000..e39c5c88e8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodWithSourceParameterAndValueMapper { + + ConditionalMethodWithSourceParameterAndValueMapper INSTANCE = Mappers.getMapper( + ConditionalMethodWithSourceParameterAndValueMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition + default boolean isPresent(BasicEmployeeDto source, String value) { + if ( value == null ) { + return false; + } + switch ( source.getStrategy() ) { + case "blank": + return !value.trim().isEmpty(); + case "empty": + return !value.isEmpty(); + default: + return true; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterMapper.java new file mode 100644 index 0000000000..9a499a6039 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodWithSourceParameterMapper { + + ConditionalMethodWithSourceParameterMapper INSTANCE = + Mappers.getMapper( ConditionalMethodWithSourceParameterMapper.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition + default boolean shouldMap(BasicEmployeeDto source) { + return "map".equals( source.getStrategy() ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousConditionalMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousConditionalMethodMapper.java new file mode 100644 index 0000000000..49e354c913 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousConditionalMethodMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousAmbiguousConditionalMethodMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + @Condition + default boolean isNotEmpty(String value) { + return value != null && value.isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/OptionalLikeConditionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/OptionalLikeConditionalMapper.java new file mode 100644 index 0000000000..4d097d7b5f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/OptionalLikeConditionalMapper.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OptionalLikeConditionalMapper { + + OptionalLikeConditionalMapper INSTANCE = Mappers.getMapper( OptionalLikeConditionalMapper.class ); + + Target map(Source source); + + default T map(Nullable nullable) { + return nullable.value; + } + + @Condition + default boolean isPresent(Nullable nullable) { + return nullable.isPresent(); + } + + class Nullable { + + private final T value; + private final boolean present; + + private Nullable(T value, boolean present) { + this.value = value; + this.present = present; + } + + public boolean isPresent() { + return present; + } + + public static Nullable undefined() { + return new Nullable<>( null, false ); + } + + public static Nullable ofNullable(T value) { + return new Nullable<>( value, true ); + } + } + + class Source { + protected final Nullable value; + + public Source(Nullable value) { + this.value = value; + } + + public Nullable getValue() { + return value; + } + } + + class Target { + protected String value = "initial"; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java new file mode 100644 index 0000000000..cf38d85dd1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java @@ -0,0 +1,97 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.expression; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.conditional.Employee; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.ap.test.conditional.basic.BasicEmployee; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2051") +@WithClasses({ + Employee.class, + EmployeeDto.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ConditionalExpressionTest { + + @Test + @WithClasses({ + ConditionalMethodsInUtilClassMapper.class + }) + public void conditionalExpressionInStaticClassMethod() { + ConditionalMethodsInUtilClassMapper mapper = ConditionalMethodsInUtilClassMapper.INSTANCE; + + EmployeeDto dto = new EmployeeDto(); + dto.setName( "Tester" ); + dto.setUniqueIdNumber( "SSID-001" ); + dto.setCountry( null ); + + Employee employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "UK" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isEqualTo( "SSID-001" ); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "US" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isEqualTo( "SSID-001" ); + + dto.setCountry( "CH" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + } + + @Test + @WithClasses({ + SimpleConditionalExpressionMapper.class + }) + public void conditionalSimpleExpression() { + SimpleConditionalExpressionMapper mapper = SimpleConditionalExpressionMapper.INSTANCE; + + SimpleConditionalExpressionMapper.Target target = + mapper.map( new SimpleConditionalExpressionMapper.Source( 50 ) ); + assertThat( target.getValue() ).isEqualTo( 50 ); + + target = mapper.map( new SimpleConditionalExpressionMapper.Source( 101 ) ); + assertThat( target.getValue() ).isEqualTo( 0 ); + } + + @Test + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousConditionExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 19, + message = "Value for condition expression must be given in the form \"java()\"." + ) + } + ) + @WithClasses({ + BasicEmployee.class, + ErroneousConditionExpressionMapper.class + } ) + public void invalidJavaConditionExpression() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalMethodsInUtilClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalMethodsInUtilClassMapper.java new file mode 100644 index 0000000000..3c49de5bf0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalMethodsInUtilClassMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.expression; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.conditional.Employee; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(imports = ConditionalMethodsInUtilClassMapper.StaticUtil.class) +public interface ConditionalMethodsInUtilClassMapper { + + ConditionalMethodsInUtilClassMapper INSTANCE = Mappers.getMapper( ConditionalMethodsInUtilClassMapper.class ); + + @Mapping(target = "ssid", source = "uniqueIdNumber", + conditionExpression = "java(StaticUtil.isAmericanCitizen( employee ))") + @Mapping(target = "nin", source = "uniqueIdNumber", + conditionExpression = "java(StaticUtil.isBritishCitizen( employee ))") + Employee map(EmployeeDto employee); + + interface StaticUtil { + + static boolean isAmericanCitizen(EmployeeDto employeeDto) { + return "US".equals( employeeDto.getCountry() ); + } + + static boolean isBritishCitizen(EmployeeDto employeeDto) { + return "UK".equals( employeeDto.getCountry() ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java new file mode 100644 index 0000000000..c74c552531 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.expression; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.ap.test.conditional.basic.BasicEmployee; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousConditionExpressionMapper { + + @Mapping(target = "name", conditionExpression = "!employee.getName().isEmpty()") + BasicEmployee map(EmployeeDto employee); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/SimpleConditionalExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/SimpleConditionalExpressionMapper.java new file mode 100644 index 0000000000..861fa0c1e3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/SimpleConditionalExpressionMapper.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.expression; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleConditionalExpressionMapper { + + SimpleConditionalExpressionMapper INSTANCE = Mappers.getMapper( SimpleConditionalExpressionMapper.class ); + + @Mapping(target = "value", conditionExpression = "java(source.getValue() < 100)") + Target map(Source source); + + class Source { + private final int value; + + public Source(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + + class Target { + private int value; + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithClassQualifiersMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithClassQualifiersMapper.java new file mode 100644 index 0000000000..7cbef82a5a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithClassQualifiersMapper.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.qualifier; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.Qualifier; +import org.mapstruct.ap.test.conditional.Employee; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = ConditionalMethodWithClassQualifiersMapper.StaticUtil.class) +public interface ConditionalMethodWithClassQualifiersMapper { + + ConditionalMethodWithClassQualifiersMapper INSTANCE = + Mappers.getMapper( ConditionalMethodWithClassQualifiersMapper.class ); + + @Mapping(target = "ssid", source = "uniqueIdNumber", + conditionQualifiedBy = UtilConditions.class, conditionQualifiedByName = "american") + @Mapping(target = "nin", source = "uniqueIdNumber", + conditionQualifiedBy = UtilConditions.class, conditionQualifiedByName = "british") + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + @UtilConditions + interface StaticUtil { + + @Condition + @Named("american") + static boolean isAmericanCitizen(EmployeeDto employerDto) { + return "US".equals( employerDto.getCountry() ); + } + + @Condition + @Named("british") + static boolean isBritishCitizen(EmployeeDto employeeDto) { + return "UK".equals( employeeDto.getCountry() ); + } + } + + @Qualifier + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.CLASS) + @interface UtilConditions { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceParameterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceParameterMapper.java new file mode 100644 index 0000000000..c04269d574 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceParameterMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.qualifier; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.ap.test.conditional.Employee; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(uses = ConditionalMethodWithSourceParameterMapper.StaticUtil.class) +public interface ConditionalMethodWithSourceParameterMapper { + + ConditionalMethodWithSourceParameterMapper INSTANCE = + Mappers.getMapper( ConditionalMethodWithSourceParameterMapper.class ); + + @Mapping(target = "ssid", source = "uniqueIdNumber", conditionQualifiedByName = "isAmericanCitizen") + @Mapping(target = "nin", source = "uniqueIdNumber", conditionQualifiedByName = "isBritishCitizen") + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + + @Condition + @Named("isAmericanCitizen") + default boolean isAmericanCitizen(EmployeeDto employerDto) { + return "US".equals( employerDto.getCountry() ); + } + + interface StaticUtil { + + @Condition + @Named("isBritishCitizen") + static boolean isBritishCitizen(EmployeeDto employeeDto) { + return "UK".equals( employeeDto.getCountry() ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java new file mode 100644 index 0000000000..3dc6d7c8aa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java @@ -0,0 +1,92 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.qualifier; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mapstruct.ap.test.conditional.Employee; +import org.mapstruct.ap.test.conditional.EmployeeDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2051") +@WithClasses({ + Employee.class, + EmployeeDto.class +}) +@RunWith(AnnotationProcessorTestRunner.class) +public class ConditionalQualifierTest { + + @Test + @WithClasses({ + ConditionalMethodWithSourceParameterMapper.class + }) + public void conditionalMethodWithSourceParameter() { + ConditionalMethodWithSourceParameterMapper mapper = ConditionalMethodWithSourceParameterMapper.INSTANCE; + + EmployeeDto dto = new EmployeeDto(); + dto.setName( "Tester" ); + dto.setUniqueIdNumber( "SSID-001" ); + dto.setCountry( null ); + + Employee employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "UK" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isEqualTo( "SSID-001" ); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "US" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isEqualTo( "SSID-001" ); + + dto.setCountry( "CH" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + } + + @Test + @WithClasses({ + ConditionalMethodWithClassQualifiersMapper.class + }) + public void conditionalClassQualifiers() { + ConditionalMethodWithClassQualifiersMapper mapper = ConditionalMethodWithClassQualifiersMapper.INSTANCE; + + EmployeeDto dto = new EmployeeDto(); + dto.setName( "Tester" ); + dto.setUniqueIdNumber( "SSID-001" ); + dto.setCountry( null ); + + Employee employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "UK" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isEqualTo( "SSID-001" ); + assertThat( employee.getSsid() ).isNull(); + + dto.setCountry( "US" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isEqualTo( "SSID-001" ); + + dto.setCountry( "CH" ); + employee = mapper.map( dto ); + assertThat( employee.getNin() ).isNull(); + assertThat( employee.getSsid() ).isNull(); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapperImpl.java new file mode 100644 index 0000000000..8f07ed89ba --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodInMapperImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-04-19T21:10:40+0200", + comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)" +) +public class ConditionalMethodInMapperImpl implements ConditionalMethodInMapper { + + @Override + public BasicEmployee map(BasicEmployeeDto employee) { + if ( employee == null ) { + return null; + } + + BasicEmployee basicEmployee = new BasicEmployee(); + + if ( isNotBlank( employee.getName() ) ) { + basicEmployee.setName( employee.getName() ); + } + + return basicEmployee; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapperImpl.java new file mode 100644 index 0000000000..ee629fb72a --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithSourceParameterAndValueMapperImpl.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-04-19T21:10:38+0200", + comments = "version: , compiler: javac, environment: Java 11.0.9.1 (AdoptOpenJDK)" +) +public class ConditionalMethodWithSourceParameterAndValueMapperImpl implements ConditionalMethodWithSourceParameterAndValueMapper { + + @Override + public BasicEmployee map(BasicEmployeeDto employee) { + if ( employee == null ) { + return null; + } + + BasicEmployee basicEmployee = new BasicEmployee(); + + if ( isPresent( employee, employee.getName() ) ) { + basicEmployee.setName( employee.getName() ); + } + + return basicEmployee; + } +} From 5bbd1a78ea67442cf8024fdcef7c9dff4356408d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 14 Feb 2021 21:37:09 +0100 Subject: [PATCH 0567/1006] Migrate the processor test infrastructure from JUnit 4 to JUnit Jupiter With JUnit Jupiter it is still not possible to set the ClassLoader for loading the test class. However, since 5.8 M1 there is a way to hook into the launcher discovery process and change the Current Thread ContextClassLoader which would load the classes with our customer ClassLoader. Once JUnit Jupiter 201 is resolved we can simplify this. The CompilationCache is stored in the GlobalCache with the CompilationRequest as key. This means that even when methods are not executed in some particular order if they have same WithClasses then they would reuse the cache. --- parent/pom.xml | 2 +- processor/pom.xml | 15 +- .../mapstruct/ap/testutil/ProcessorTest.java | 50 +++++ .../runner/AnnotationProcessorTestRunner.java | 160 -------------- .../testutil/runner/CompilationRequest.java | 9 +- .../ap/testutil/runner/Compiler.java | 21 +- .../CompilerLauncherDiscoveryListener.java | 29 +++ .../CompilerTestEnabledOnJreCondition.java | 39 ++++ ...Statement.java => CompilingExtension.java} | 172 +++++++-------- .../testutil/runner/DisabledOnCompiler.java | 26 --- ...nt.java => EclipseCompilingExtension.java} | 15 +- .../ap/testutil/runner/EnabledOnCompiler.java | 26 --- .../runner/FilteringParentClassLoader.java | 5 + .../ap/testutil/runner/GeneratedSource.java | 60 +++--- .../InnerAnnotationProcessorRunner.java | 145 ------------- .../runner/Jdk11CompilingStatement.java | 37 ---- ...tement.java => JdkCompilingExtension.java} | 30 +-- .../runner/ProcessorTestExtension.java | 38 ++++ .../ProcessorTestInvocationContext.java | 48 +++++ .../testutil/runner/ReplacableTestClass.java | 199 ------------------ .../testutil/runner/WithSingleCompiler.java | 29 --- ...latform.launcher.LauncherDiscoveryListener | 1 + 22 files changed, 373 insertions(+), 783 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/ProcessorTest.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerLauncherDiscoveryListener.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerTestEnabledOnJreCondition.java rename processor/src/test/java/org/mapstruct/ap/testutil/runner/{CompilingStatement.java => CompilingExtension.java} (81%) delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java rename processor/src/test/java/org/mapstruct/ap/testutil/runner/{EclipseCompilingStatement.java => EclipseCompilingExtension.java} (94%) delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java rename processor/src/test/java/org/mapstruct/ap/testutil/runner/{JdkCompilingStatement.java => JdkCompilingExtension.java} (81%) create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/ProcessorTestExtension.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/ProcessorTestInvocationContext.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java create mode 100644 processor/src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener diff --git a/parent/pom.xml b/parent/pom.xml index b6a619a90b..c7ac37a41d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -28,7 +28,7 @@ 5.3.3 1.6.0 8.36.1 - 5.7.0 + 5.8.0-M1 1 3.17.2 diff --git a/processor/pom.xml b/processor/pom.xml index 2ff5d2d186..5aa6470ff9 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -49,8 +49,13 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine test @@ -104,6 +109,12 @@ test + + org.junit.platform + junit-platform-launcher + test + + joda-time diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/ProcessorTest.java b/processor/src/test/java/org/mapstruct/ap/testutil/ProcessorTest.java new file mode 100644 index 0000000000..cebacf4587 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/ProcessorTest.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mapstruct.ap.testutil.runner.Compiler; +import org.mapstruct.ap.testutil.runner.ProcessorTestExtension; + +/** + * JUnit Jupiter test template for the MapStruct Processor tests. + *

      + * Test classes are safe to be executed in parallel, but test methods are not safe to be executed in parallel. + *

      + * By default this template would generate tests for the JDK and Eclipse Compiler. + * If only a single compiler is needed then specify the compiler in the value. + *

      + * The classes to be compiled for a given test method must be specified via {@link WithClasses}. In addition the + * following things can be configured optionally : + *

        + *
      • Processor options to be considered during compilation via + * {@link org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption ProcessorOption}.
      • + *
      • The expected compilation outcome and expected diagnostics can be specified via + * {@link org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome ExpectedCompilationOutcome}. + * If no outcome is specified, a successful compilation is assumed.
      • + *
      + * + * @author Filip Hrisafov + */ +@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@TestTemplate +@ExtendWith(ProcessorTestExtension.class) +public @interface ProcessorTest { + + Compiler[] value() default { + Compiler.JDK, + Compiler.ECLIPSE + }; +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java deleted file mode 100644 index 2891121afb..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/AnnotationProcessorTestRunner.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.List; - -import org.junit.runner.Description; -import org.junit.runner.Runner; -import org.junit.runner.manipulation.Filter; -import org.junit.runner.manipulation.NoTestsRemainException; -import org.junit.runner.notification.RunNotifier; -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.ParentRunner; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; - -/** - * A JUnit4 runner for Annotation Processor tests. - *

      - * Test classes are safe to be executed in parallel, but test methods are not safe to be executed in parallel. - *

      - * The classes to be compiled for a given test method must be specified via {@link WithClasses}. In addition the - * following things can be configured optionally : - *

        - *
      • Processor options to be considered during compilation via {@link ProcessorOption}.
      • - *
      • The expected compilation outcome and expected diagnostics can be specified via {@link ExpectedCompilationOutcome} - * . If no outcome is specified, a successful compilation is assumed.
      • - *
      - * - * @author Gunnar Morling - * @author Andreas Gudian - */ -public class AnnotationProcessorTestRunner extends ParentRunner { - - private static final boolean IS_AT_LEAST_JAVA_9 = isIsAtLeastJava9(); - - private static boolean isIsAtLeastJava9() { - try { - Runtime.class.getMethod( "version" ); - return true; - } - catch ( NoSuchMethodException e ) { - return false; - } - } - - private final List runners; - - /** - * @param klass the test class - * - * @throws Exception see {@link BlockJUnit4ClassRunner#BlockJUnit4ClassRunner(Class)} - */ - public AnnotationProcessorTestRunner(Class klass) throws Exception { - super( klass ); - - runners = createRunners( klass ); - } - - @SuppressWarnings("deprecation") - private List createRunners(Class klass) throws Exception { - WithSingleCompiler singleCompiler = klass.getAnnotation( WithSingleCompiler.class ); - - if (singleCompiler != null) { - return Arrays.asList( new InnerAnnotationProcessorRunner( klass, singleCompiler.value() ) ); - } - else if ( IS_AT_LEAST_JAVA_9 ) { - // Current tycho-compiler-jdt (0.26.0) is not compatible with Java 11 - // Updating to latest version 1.3.0 fails some tests - // Once https://github.com/mapstruct/mapstruct/pull/1587 is resolved we can remove this line - return Arrays.asList( - new InnerAnnotationProcessorRunner( klass, Compiler.JDK11 ), - new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE11 ) - ); - } - - return Arrays.asList( - new InnerAnnotationProcessorRunner( klass, Compiler.JDK ), - new InnerAnnotationProcessorRunner( klass, Compiler.ECLIPSE ) - ); - } - - @Override - protected List getChildren() { - return runners; - } - - @Override - protected Description describeChild(Runner child) { - return child.getDescription(); - } - - @Override - protected void runChild(Runner child, RunNotifier notifier) { - child.run( notifier ); - } - - @Override - public void filter(Filter filter) throws NoTestsRemainException { - super.filter( new FilterDecorator( filter ) ); - } - - /** - * Allows to only execute selected methods, even if the executing framework is not aware of parameterized tests - * (e.g. some versions of IntelliJ, Netbeans, Eclipse). - */ - private static final class FilterDecorator extends Filter { - private final Filter delegate; - - private FilterDecorator(Filter delegate) { - this.delegate = delegate; - } - - @Override - public boolean shouldRun(Description description) { - boolean shouldRun = delegate.shouldRun( description ); - if ( !shouldRun ) { - return delegate.shouldRun( withoutParameterizedName( description ) ); - } - - return shouldRun; - } - - @Override - public String describe() { - return delegate.describe(); - } - - private Description withoutParameterizedName(Description description) { - String cleanDisplayName = removeParameter( description.getDisplayName() ); - Description cleanDescription = - Description.createSuiteDescription( - cleanDisplayName, - description.getAnnotations().toArray( new Annotation[description.getAnnotations().size()] ) ); - - for ( Description child : description.getChildren() ) { - cleanDescription.addChild( withoutParameterizedName( child ) ); - } - - return cleanDescription; - } - - private String removeParameter(String name) { - if ( name.startsWith( "[" ) ) { - return name; - } - - // remove "[compiler]" from "method[compiler](class)" - int open = name.indexOf( '[' ); - int close = name.indexOf( ']' ) + 1; - return name.substring( 0, open ) + name.substring( close ); - } - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index 46a112da2e..3f1599aad0 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -13,11 +13,14 @@ * Represents a compilation task for a number of sources with given processor options. */ public class CompilationRequest { + private final Compiler compiler; private final Set> sourceClasses; private final Map, Class> services; private final List processorOptions; - CompilationRequest(Set> sourceClasses, Map, Class> services, List processorOptions) { + CompilationRequest(Compiler compiler, Set> sourceClasses, Map, Class> services, + List processorOptions) { + this.compiler = compiler; this.sourceClasses = sourceClasses; this.services = services; this.processorOptions = processorOptions; @@ -27,6 +30,7 @@ public class CompilationRequest { public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ( ( compiler == null ) ? 0 : compiler.hashCode() ); result = prime * result + ( ( processorOptions == null ) ? 0 : processorOptions.hashCode() ); result = prime * result + ( ( services == null ) ? 0 : services.hashCode() ); result = prime * result + ( ( sourceClasses == null ) ? 0 : sourceClasses.hashCode() ); @@ -46,7 +50,8 @@ public boolean equals(Object obj) { } CompilationRequest other = (CompilationRequest) obj; - return processorOptions.equals( other.processorOptions ) + return compiler.equals( other.compiler ) + && processorOptions.equals( other.processorOptions ) && services.equals( other.services ) && sourceClasses.equals( other.sourceClasses ); } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java index 4b24bb091b..e38ae28775 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Compiler.java @@ -5,10 +5,27 @@ */ package org.mapstruct.ap.testutil.runner; +import org.junit.jupiter.api.condition.JRE; + /** * @author Andreas Gudian - * + * @author Filip Hrisafov */ public enum Compiler { - JDK, JDK11, ECLIPSE, ECLIPSE11; + JDK, + ECLIPSE; + + private final JRE latestSupportedJre; + + Compiler() { + this( JRE.OTHER ); + } + + Compiler(JRE latestSupportedJre) { + this.latestSupportedJre = latestSupportedJre; + } + + public JRE latestSupportedJre() { + return latestSupportedJre; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerLauncherDiscoveryListener.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerLauncherDiscoveryListener.java new file mode 100644 index 0000000000..fde6d0d599 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerLauncherDiscoveryListener.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import org.junit.platform.engine.UniqueId; +import org.junit.platform.launcher.LauncherDiscoveryListener; + +/** + * @author Filip Hrisafov + */ +public class CompilerLauncherDiscoveryListener implements LauncherDiscoveryListener { + @Override + public void engineDiscoveryStarted(UniqueId engineId) { + // Currently JUnit Jupiter does not have an SPI for providing a ClassLoader for loading the class + // However, we can change the current context class loaded when the engine discovery starts. + // This would make sure that JUnit Jupiter uses our ClassLoader to correctly load the mappers + ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader(); + FilteringParentClassLoader filteringParentClassLoader = new FilteringParentClassLoader( + currentClassLoader, + "org.mapstruct.ap.test." + ); + ModifiableURLClassLoader newClassLoader = new ModifiableURLClassLoader( filteringParentClassLoader ); + newClassLoader.withOriginOf( getClass() ); + Thread.currentThread().setContextClassLoader( newClassLoader ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerTestEnabledOnJreCondition.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerTestEnabledOnJreCondition.java new file mode 100644 index 0000000000..29e3280e8b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilerTestEnabledOnJreCondition.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * Every compiler is registered with it's max supported JRE that it can run on. + * This condition is used to check if the test for a particular compiler can be run with the current JRE. + * + * @author Filip Hrisafov + */ +public class CompilerTestEnabledOnJreCondition implements ExecutionCondition { + + static final ConditionEvaluationResult ENABLED_ON_CURRENT_JRE = + ConditionEvaluationResult.enabled( "Enabled on JRE version: " + System.getProperty( "java.version" ) ); + + static final ConditionEvaluationResult DISABLED_ON_CURRENT_JRE = + ConditionEvaluationResult.disabled( "Disabled on JRE version: " + System.getProperty( "java.version" ) ); + + protected final Compiler compiler; + + public CompilerTestEnabledOnJreCondition(Compiler compiler) { + this.compiler = compiler; + } + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + // If the max JRE is greater or equal to the current version the test is enabled + return compiler.latestSupportedJre().compareTo( JRE.currentVersion() ) >= 0 ? ENABLED_ON_CURRENT_JRE : + DISABLED_ON_CURRENT_JRE; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java similarity index 81% rename from processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java rename to processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index 3e61d8bd9e..b372974461 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.testutil.runner; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -26,34 +24,38 @@ import java.util.Set; import java.util.stream.Stream; +import com.puppycrawl.tools.checkstyle.Checker; +import com.puppycrawl.tools.checkstyle.ConfigurationLoader; +import com.puppycrawl.tools.checkstyle.DefaultLogger; +import com.puppycrawl.tools.checkstyle.PropertiesExpander; import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import org.apache.commons.io.output.NullOutputStream; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; -import org.mapstruct.ap.testutil.WithServiceImplementations; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; import org.xml.sax.InputSource; -import com.puppycrawl.tools.checkstyle.Checker; -import com.puppycrawl.tools.checkstyle.ConfigurationLoader; -import com.puppycrawl.tools.checkstyle.DefaultLogger; -import com.puppycrawl.tools.checkstyle.PropertiesExpander; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation; +import static org.junit.platform.commons.support.AnnotationSupport.findRepeatableAnnotations; /** - * A JUnit4 statement that performs source generation using the annotation processor and compiles those sources. + * A JUnit Jupiter Extension that performs source generation using the annotation processor and compiles those sources. * * @author Andreas Gudian + * @author Filip Hrisafov */ -abstract class CompilingStatement extends Statement { +abstract class CompilingExtension implements BeforeEachCallback { + + static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create( new Object() ); private static final String TARGET_COMPILATION_TESTS = "/target/compilation-tests/"; @@ -67,46 +69,20 @@ abstract class CompilingStatement extends Statement { protected static final List PROCESSOR_CLASSPATH = buildProcessorClasspath(); - private final FrameworkMethod method; - private final CompilationCache compilationCache; - private final boolean runCheckstyle; - private Statement next; - private String classOutputDir; private String sourceOutputDir; private String additionalCompilerClasspath; - private CompilationRequest compilationRequest; - - CompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { - this.method = method; - this.compilationCache = compilationCache; - this.runCheckstyle = !method.getMethod().getDeclaringClass().isAnnotationPresent( DisableCheckstyle.class ); - - this.compilationRequest = new CompilationRequest( getTestClasses(), getServices(), getProcessorOptions() ); - } - - void setNextStatement(Statement next) { - this.next = next; - } - - @Override - public void evaluate() throws Throwable { - generateMapperImplementation(); - - GeneratedSource.setCompilingStatement( this ); - next.evaluate(); - GeneratedSource.clearCompilingStatement(); - } + private final Compiler compiler; - String getSourceOutputDir() { - return compilationCache.getLastSourceOutputDir(); + protected CompilingExtension(Compiler compiler) { + this.compiler = compiler; } - protected void setupDirectories() { + protected void setupDirectories(Method testMethod, Class testClass) { String compilationRoot = getBasePath() + TARGET_COMPILATION_TESTS - + method.getDeclaringClass().getName() - + "/" + method.getName() + + testClass.getName() + + "/" + testMethod.getName() + getPathSuffix(); classOutputDir = compilationRoot + "/classes"; @@ -118,7 +94,9 @@ protected void setupDirectories() { ( (ModifiableURLClassLoader) Thread.currentThread().getContextClassLoader() ).withPath( classOutputDir ); } - protected abstract String getPathSuffix(); + protected String getPathSuffix() { + return "_" + compiler.name().toLowerCase(); + } private static List buildTestCompilationClasspath() { String[] whitelist = @@ -169,14 +147,21 @@ private static boolean isWhitelisted(String path, String[] whitelist) { return Stream.of( whitelist ).anyMatch( path::contains ); } - protected void generateMapperImplementation() throws Exception { - CompilationOutcomeDescriptor actualResult = compile(); + @Override + public void beforeEach(ExtensionContext context) throws Exception { + CompilationOutcomeDescriptor actualResult = compile( context ); + assertResult( actualResult, context ); + } + + private void assertResult(CompilationOutcomeDescriptor actualResult, ExtensionContext context) throws Exception { + Method testMethod = context.getRequiredTestMethod(); + Class testClass = context.getRequiredTestClass(); CompilationOutcomeDescriptor expectedResult = CompilationOutcomeDescriptor.forExpectedCompilationResult( - method.getAnnotation( ExpectedCompilationOutcome.class ), - method.getAnnotation( ExpectedNote.ExpectedNotes.class ), - method.getAnnotation( ExpectedNote.class ) + findAnnotation( testMethod, ExpectedCompilationOutcome.class ).orElse( null ), + findAnnotation( testMethod, ExpectedNote.ExpectedNotes.class ).orElse( null ), + findAnnotation( testMethod, ExpectedNote.class ).orElse( null ) ); if ( expectedResult.getCompilationResult() == CompilationResult.SUCCEEDED ) { @@ -195,7 +180,7 @@ protected void generateMapperImplementation() throws Exception { assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() ); assertNotes( actualResult.getNotes(), expectedResult.getNotes() ); - if ( runCheckstyle ) { + if ( !findAnnotation( testClass, DisableCheckstyle.class ).isPresent() ) { assertCheckstyleRules(); } } @@ -349,18 +334,14 @@ protected List filterExpectedDiagnostics(List> getTestClasses() { + private Set> getTestClasses(Method testMethod, Class testClass) { Set> testClasses = new HashSet<>(); - WithClasses withClasses = method.getAnnotation( WithClasses.class ); - if ( withClasses != null ) { - testClasses.addAll( Arrays.asList( withClasses.value() ) ); - } + findAnnotation( testMethod, WithClasses.class ) + .ifPresent( withClasses -> testClasses.addAll( Arrays.asList( withClasses.value() ) ) ); - withClasses = method.getMethod().getDeclaringClass().getAnnotation( WithClasses.class ); - if ( withClasses != null ) { - testClasses.addAll( Arrays.asList( withClasses.value() ) ); - } + findAnnotation( testClass, WithClasses.class ) + .ifPresent( withClasses -> testClasses.addAll( Arrays.asList( withClasses.value() ) ) ); if ( testClasses.isEmpty() ) { throw new IllegalStateException( @@ -377,24 +358,19 @@ private Set> getTestClasses() { * @return A map containing the package were to look for a resource (key) and the resource (value) to be compiled * for this test */ - private Map, Class> getServices() { + private Map, Class> getServices(Method testMethod, Class testClass) { Map, Class> services = new HashMap<>(); - addServices( services, method.getAnnotation( WithServiceImplementations.class ) ); - addService( services, method.getAnnotation( WithServiceImplementation.class ) ); + addServices( services, findRepeatableAnnotations( testMethod, WithServiceImplementation.class ) ); - Class declaringClass = method.getMethod().getDeclaringClass(); - addServices( services, declaringClass.getAnnotation( WithServiceImplementations.class ) ); - addService( services, declaringClass.getAnnotation( WithServiceImplementation.class ) ); + addServices( services, findRepeatableAnnotations( testClass, WithServiceImplementation.class ) ); return services; } - private void addServices(Map, Class> services, WithServiceImplementations withImplementations) { - if ( withImplementations != null ) { - for ( WithServiceImplementation resource : withImplementations.value() ) { - addService( services, resource ); - } + private void addServices(Map, Class> services, List withImplementations) { + for ( WithServiceImplementation withImplementation : withImplementations ) { + addService( services, withImplementation ); } } @@ -425,17 +401,11 @@ private void addService(Map, Class> services, WithServiceImplementat * * @return A list containing the processor options to be used for this test */ - private List getProcessorOptions() { - List processorOptions = - getProcessorOptions( - method.getAnnotation( ProcessorOptions.class ), - method.getAnnotation( ProcessorOption.class ) ); + private List getProcessorOptions(Method testMethod, Class testClass) { + List processorOptions = findRepeatableAnnotations( testMethod, ProcessorOption.class ); if ( processorOptions.isEmpty() ) { - processorOptions = - getProcessorOptions( - method.getMethod().getDeclaringClass().getAnnotation( ProcessorOptions.class ), - method.getMethod().getDeclaringClass().getAnnotation( ProcessorOption.class ) ); + processorOptions = findRepeatableAnnotations( testClass, ProcessorOption.class ); } List result = new ArrayList<>( processorOptions.size() ); @@ -449,17 +419,6 @@ private List getProcessorOptions() { return result; } - private List getProcessorOptions(ProcessorOptions options, ProcessorOption option) { - if ( options != null ) { - return Arrays.asList( options.value() ); - } - else if ( option != null ) { - return Arrays.asList( option ); - } - - return Collections.emptyList(); - } - private String asOptionString(ProcessorOption processorOption) { return String.format( "-A%s=%s", processorOption.name(), processorOption.value() ); } @@ -479,17 +438,32 @@ protected static Set getSourceFiles(Collection> classes) { return sourceFiles; } - private CompilationOutcomeDescriptor compile() - throws Exception { + private CompilationOutcomeDescriptor compile(ExtensionContext context) { + Method testMethod = context.getRequiredTestMethod(); + Class testClass = context.getRequiredTestClass(); + + CompilationRequest compilationRequest = new CompilationRequest( + compiler, + getTestClasses( testMethod, testClass ), + getServices( testMethod, testClass ), + getProcessorOptions( testMethod, testClass ) + ); + + ExtensionContext.Store rootStore = context.getRoot().getStore( NAMESPACE ); + + // We need to put the compilation request in the store, so the GeneratedSource can use it + context.getStore( NAMESPACE ).put( context.getUniqueId() + "-compilationRequest", compilationRequest ); + CompilationCache compilationCache = rootStore + .getOrComputeIfAbsent( compilationRequest, request -> new CompilationCache(), CompilationCache.class ); - if ( !needsRecompilation() ) { + if ( !needsRecompilation( compilationRequest, compilationCache ) ) { return compilationCache.getLastResult(); } - setupDirectories(); + setupDirectories( testMethod, testClass ); compilationCache.setLastSourceOutputDir( sourceOutputDir ); - boolean needsAdditionalCompilerClasspath = prepareServices(); + boolean needsAdditionalCompilerClasspath = prepareServices( compilationRequest ); CompilationOutcomeDescriptor resultHolder; resultHolder = compileWithSpecificCompiler( @@ -517,7 +491,7 @@ protected abstract CompilationOutcomeDescriptor compileWithSpecificCompiler( String classOutputDir, String additionalCompilerClasspath); - boolean needsRecompilation() { + boolean needsRecompilation(CompilationRequest compilationRequest, CompilationCache compilationCache) { return !compilationRequest.equals( compilationCache.getLastRequest() ); } @@ -559,7 +533,7 @@ private void deleteDirectory(File path) { path.delete(); } - private boolean prepareServices() { + private boolean prepareServices(CompilationRequest compilationRequest) { if ( !compilationRequest.getServices().isEmpty() ) { String servicesDir = additionalCompilerClasspath + File.separator + "META-INF" + File.separator + "services"; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java deleted file mode 100644 index 6fdfa37268..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/DisabledOnCompiler.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This should be used with care. - * This is similar to the JUnit 5 DisabledOnJre (once we have JUnit 5 we can replace this one) - * - * @author Filip Hrisafov - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface DisabledOnCompiler { - /** - * @return The compiler to use. - */ - Compiler[] value(); -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java similarity index 94% rename from processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java rename to processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java index 4dac535389..6cab46cc7f 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java @@ -16,16 +16,16 @@ import org.codehaus.plexus.compiler.CompilerResult; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.eclipse.tycho.compiler.jdt.JDTCompiler; -import org.junit.runners.model.FrameworkMethod; import org.mapstruct.ap.MappingProcessor; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; /** - * Statement that uses the Eclipse JDT compiler to compile. + * Extension that uses the Eclipse JDT compiler to compile. * * @author Andreas Gudian + * @author Filip Hrisafov */ -class EclipseCompilingStatement extends CompilingStatement { +class EclipseCompilingExtension extends CompilingExtension { private static final List ECLIPSE_COMPILER_CLASSPATH = buildEclipseCompilerClasspath(); @@ -35,8 +35,8 @@ class EclipseCompilingStatement extends CompilingStatement { .withPaths( PROCESSOR_CLASSPATH ) .withOriginOf( ClassLoaderExecutor.class ); - EclipseCompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { - super( method, compilationCache ); + EclipseCompilingExtension() { + super( Compiler.ECLIPSE ); } @Override @@ -152,9 +152,4 @@ private static List buildEclipseCompilerClasspath() { return filterBootClassPath( whitelist ); } - - @Override - protected String getPathSuffix() { - return "_eclipse"; - } } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java deleted file mode 100644 index 7c6d79e0fc..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EnabledOnCompiler.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This should be used with care. - * This is similar to the JUnit 5 EnabledOnJre (once we have JUnit 5 we can replace this one) - * - * @author Filip Hrisafov - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface EnabledOnCompiler { - /** - * @return The compiler to use. - */ - Compiler[] value(); -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java index 983b8867f1..c83b76c10b 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/FilteringParentClassLoader.java @@ -25,6 +25,11 @@ final class FilteringParentClassLoader extends ClassLoader { this.excludedPrefixes = new ArrayList<>( Arrays.asList( excludedPrefixes ) ); } + FilteringParentClassLoader(ClassLoader parent, String... excludedPrefixes) { + super( parent ); + this.excludedPrefixes = new ArrayList<>( Arrays.asList( excludedPrefixes ) ); + } + /** * @param classes The classes to hide (inner classes are hidden as well) * @return {@code this} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index f5a98bfee7..c0993ea098 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -13,48 +13,60 @@ import java.util.Arrays; import java.util.List; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterTestExecutionCallback; +import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.mapstruct.ap.testutil.assertions.JavaFileAssert; import static org.assertj.core.api.Assertions.fail; +import static org.mapstruct.ap.testutil.runner.CompilingExtension.NAMESPACE; /** - * A {@link TestRule} to perform assertions on generated source files. + * A {@link org.junit.jupiter.api.extension.RegisterExtension RegisterExtension} to perform assertions on generated + * source files. *

      * To add it to the test, use: * *

      - * @Rule
      - * public GeneratedSource generatedSources = new GeneratedSource();
      + * @RegisterExtension
      + * final GeneratedSource generatedSources = new GeneratedSource();
        * 
      * * @author Andreas Gudian */ -public class GeneratedSource implements TestRule { +public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestExecutionCallback { private static final String FIXTURES_ROOT = "fixtures/"; /** - * static ThreadLocal, as the {@link CompilingStatement} must inject itself statically for this rule to gain access - * to the statement's information. As test execution of different classes in parallel is supported. + * ThreadLocal, as the source dir must be injected for this extension to gain access + * to the compilation information. As test execution of different classes in parallel is supported. */ - private static ThreadLocal compilingStatement = new ThreadLocal<>(); + private ThreadLocal sourceOutputDir = new ThreadLocal<>(); private List> fixturesFor = new ArrayList<>(); @Override - public Statement apply(Statement base, Description description) { - return new GeneratedSourceStatement( base ); + public void beforeTestExecution(ExtensionContext context) throws Exception { + CompilationRequest compilationRequest = context.getStore( NAMESPACE ) + .get( context.getUniqueId() + "-compilationRequest", CompilationRequest.class ); + setSourceOutputDir( context.getStore( NAMESPACE ) + .get( compilationRequest, CompilationCache.class ) + .getLastSourceOutputDir() ); } - static void setCompilingStatement(CompilingStatement compilingStatement) { - GeneratedSource.compilingStatement.set( compilingStatement ); + @Override + public void afterTestExecution(ExtensionContext context) throws Exception { + handleFixtureComparison(); + clearSourceOutputDir(); + } + + private void setSourceOutputDir(String sourceOutputDir) { + this.sourceOutputDir.set( sourceOutputDir ); } - static void clearCompilingStatement() { - GeneratedSource.compilingStatement.remove(); + private void clearSourceOutputDir() { + this.sourceOutputDir.remove(); } /** @@ -101,21 +113,7 @@ public JavaFileAssert forDecoratedMapper(Class mapperClass) { * @return an assert for the file specified by the given path */ public JavaFileAssert forJavaFile(String path) { - return new JavaFileAssert( new File( compilingStatement.get().getSourceOutputDir() + "/" + path ) ); - } - - private class GeneratedSourceStatement extends Statement { - private final Statement next; - - private GeneratedSourceStatement(Statement next) { - this.next = next; - } - - @Override - public void evaluate() throws Throwable { - next.evaluate(); - handleFixtureComparison(); - } + return new JavaFileAssert( new File( sourceOutputDir.get() + "/" + path ) ); } private void handleFixtureComparison() throws UnsupportedEncodingException { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java deleted file mode 100644 index 50ab9c6eb5..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/InnerAnnotationProcessorRunner.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; -import org.junit.runners.model.TestClass; - -/** - * Internal test runner that runs the tests of one class for one specific compiler implementation. - * - * @author Andreas Gudian - */ -class InnerAnnotationProcessorRunner extends BlockJUnit4ClassRunner { - static final ModifiableURLClassLoader TEST_CLASS_LOADER = new ModifiableURLClassLoader(); - private final Class klass; - private final Compiler compiler; - private final CompilationCache compilationCache; - private Class klassToUse; - private ReplacableTestClass replacableTestClass; - - /** - * @param klass the test class - * - * @throws Exception see {@link BlockJUnit4ClassRunner#BlockJUnit4ClassRunner(Class)} - */ - InnerAnnotationProcessorRunner(Class klass, Compiler compiler) throws Exception { - super( klass ); - this.klass = klass; - this.compiler = compiler; - this.compilationCache = new CompilationCache(); - } - - /** - * newly loads the class with the test class loader and sets that loader as context class loader of the thread - * - * @param klass the class to replace - * - * @return the class loaded with the test class loader - */ - private static Class replaceClassLoaderAndClass(Class klass) { - replaceContextClassLoader( klass ); - - try { - return Thread.currentThread().getContextClassLoader().loadClass( klass.getName() ); - } - catch ( ClassNotFoundException e ) { - throw new RuntimeException( e ); - } - - } - - private static void replaceContextClassLoader(Class klass) { - ModifiableURLClassLoader testClassLoader = new ModifiableURLClassLoader().withOriginOf( klass ); - - Thread.currentThread().setContextClassLoader( testClassLoader ); - } - - @Override - protected boolean isIgnored(FrameworkMethod child) { - return super.isIgnored( child ) || isIgnoredForCompiler( child ); - } - - protected boolean isIgnoredForCompiler(FrameworkMethod child) { - EnabledOnCompiler enabledOnCompiler = child.getAnnotation( EnabledOnCompiler.class ); - if ( enabledOnCompiler != null ) { - for ( Compiler value : enabledOnCompiler.value() ) { - if ( value != compiler ) { - return true; - } - } - } - - DisabledOnCompiler disabledOnCompiler = child.getAnnotation( DisabledOnCompiler.class ); - if ( disabledOnCompiler != null ) { - for ( Compiler value : disabledOnCompiler.value() ) { - if ( value == compiler ) { - return true; - } - } - } - - return false; - } - - @Override - protected TestClass createTestClass(final Class testClass) { - replacableTestClass = new ReplacableTestClass( testClass ); - return replacableTestClass; - } - - private FrameworkMethod replaceFrameworkMethod(FrameworkMethod m) { - try { - return new FrameworkMethod( - klassToUse.getDeclaredMethod( m.getName(), m.getMethod().getParameterTypes() ) ); - } - catch ( NoSuchMethodException e ) { - throw new RuntimeException( e ); - } - } - - @Override - protected Statement methodBlock(FrameworkMethod method) { - CompilingStatement statement = createCompilingStatement( method ); - if ( statement.needsRecompilation() ) { - klassToUse = replaceClassLoaderAndClass( klass ); - - replacableTestClass.replaceClass( klassToUse ); - } - - method = replaceFrameworkMethod( method ); - - Statement next = super.methodBlock( method ); - - statement.setNextStatement( next ); - - return statement; - } - - private CompilingStatement createCompilingStatement(FrameworkMethod method) { - if ( compiler == Compiler.JDK ) { - return new JdkCompilingStatement( method, compilationCache ); - } - else if ( compiler == Compiler.JDK11 ) { - return new Jdk11CompilingStatement( method, compilationCache ); - } - else { - return new EclipseCompilingStatement( method, compilationCache ); - } - } - - @Override - protected String getName() { - return "[" + compiler.name().toLowerCase() + "]"; - } - - @Override - protected String testName(FrameworkMethod method) { - return method.getName() + getName(); - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java deleted file mode 100644 index 30f12aead7..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/Jdk11CompilingStatement.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.util.List; - -import org.junit.runners.model.FrameworkMethod; -import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; - -/** - * Statement that uses the JDK compiler to compile. - * - * @author Filip Hrisafov - */ -class Jdk11CompilingStatement extends JdkCompilingStatement { - - Jdk11CompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { - super( method, compilationCache ); - } - - - /** - * The JDK 11 compiler reports all ERROR diagnostics properly. Also when there are multiple per line. - */ - @Override - protected List filterExpectedDiagnostics(List expectedDiagnostics) { - return expectedDiagnostics; - } - - @Override - protected String getPathSuffix() { - return "_jdk"; - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java similarity index 81% rename from processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java rename to processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 454f2c3c3c..1761956678 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -11,7 +11,6 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; - import javax.annotation.processing.Processor; import javax.tools.Diagnostic.Kind; import javax.tools.DiagnosticCollector; @@ -22,17 +21,18 @@ import javax.tools.StandardLocation; import javax.tools.ToolProvider; -import org.junit.runners.model.FrameworkMethod; +import org.junit.jupiter.api.condition.JRE; import org.mapstruct.ap.MappingProcessor; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; /** - * Statement that uses the JDK compiler to compile. + * Extension that uses the JDK compiler to compile. * * @author Andreas Gudian + * @author Filip Hrisafov */ -class JdkCompilingStatement extends CompilingStatement { +class JdkCompilingExtension extends CompilingExtension { private static final List COMPILER_CLASSPATH_FILES = asFiles( TEST_COMPILATION_CLASSPATH ); @@ -40,8 +40,8 @@ class JdkCompilingStatement extends CompilingStatement { new ModifiableURLClassLoader( new FilteringParentClassLoader( "org.mapstruct." ) ) .withPaths( PROCESSOR_CLASSPATH ); - JdkCompilingStatement(FrameworkMethod method, CompilationCache compilationCache) { - super( method, compilationCache ); + JdkCompilingExtension() { + super( Compiler.JDK ); } @Override @@ -107,14 +107,20 @@ private static List asFiles(List paths) { } /** - * The JDK compiler only reports the first message of kind ERROR that is reported for one source file line, so we - * filter out the surplus diagnostics. The input list is already sorted by file name and line number, with the order - * for the diagnostics in the same line being kept at the order as given in the test. + * The JDK 8 compiler needs some special treatment for the diagnostics. + * See comment in the function. */ @Override protected List filterExpectedDiagnostics(List expectedDiagnostics) { - List filtered = new ArrayList<>( expectedDiagnostics.size() ); + if ( JRE.currentVersion() != JRE.JAVA_8 ) { + // The JDK 8+ compilers report all ERROR diagnostics properly. Also when there are multiple per line. + return expectedDiagnostics; + } + List filtered = new ArrayList( expectedDiagnostics.size() ); + // The JDK 8 compiler only reports the first message of kind ERROR that is reported for one source file line, + // so we filter out the surplus diagnostics. The input list is already sorted by file name and line number, + // with the order for the diagnostics in the same line being kept at the order as given in the test. DiagnosticDescriptor previous = null; for ( DiagnosticDescriptor diag : expectedDiagnostics ) { if ( diag.getKind() != Kind.ERROR @@ -129,8 +135,4 @@ protected List filterExpectedDiagnostics(List provideTestTemplateInvocationContexts(ExtensionContext context) { + Method testMethod = context.getRequiredTestMethod(); + ProcessorTest processorTest = AnnotationSupport.findAnnotation( testMethod, ProcessorTest.class ) + .orElseThrow( () -> new RuntimeException( "Failed to get CompilerTest on " + testMethod ) ); + + return Stream.of( processorTest.value() ) + .map( ProcessorTestInvocationContext::new ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ProcessorTestInvocationContext.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ProcessorTestInvocationContext.java new file mode 100644 index 0000000000..d557095dff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ProcessorTestInvocationContext.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil.runner; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; + +/** + * The template invocation processor responsible for providing the appropriate extensions for the different compilers. + * + * @author Filip Hrisafov + */ +public class ProcessorTestInvocationContext implements TestTemplateInvocationContext { + + protected Compiler compiler; + + public ProcessorTestInvocationContext(Compiler compiler) { + this.compiler = compiler; + } + + @Override + public String getDisplayName(int invocationIndex) { + return "[" + compiler.name().toLowerCase() + "]"; + } + + @Override + public List getAdditionalExtensions() { + List extensions = new ArrayList<>(); + extensions.add( new CompilerTestEnabledOnJreCondition( compiler ) ); + if ( compiler == Compiler.JDK ) { + extensions.add( new JdkCompilingExtension() ); + } + else if ( compiler == Compiler.ECLIPSE ) { + extensions.add( new EclipseCompilingExtension() ); + } + else { + throw new IllegalArgumentException( "Compiler [" + compiler + "] is not known" ); + } + + return extensions; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java deleted file mode 100644 index 7141b78146..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ReplacableTestClass.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.util.List; - -import org.junit.runners.model.FrameworkField; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.TestClass; - -/** - * A {@link TestClass} where the wrapped Class can be replaced - * - * @author Andreas Gudian - */ -class ReplacableTestClass extends TestClass { - private TestClass delegate; - - /** - * @see TestClass#TestClass(Class) - */ - ReplacableTestClass(Class clazz) { - super( clazz ); - } - - /** - * @param clazz the new class - */ - void replaceClass(Class clazz) { - delegate = new TestClass( clazz ); - } - - @Override - public List getAnnotatedMethods() { - if ( null == delegate ) { - return super.getAnnotatedMethods(); - } - else { - return delegate.getAnnotatedMethods(); - } - } - - @Override - public List getAnnotatedMethods(Class annotationClass) { - if ( null == delegate ) { - return super.getAnnotatedMethods( annotationClass ); - } - else { - return delegate.getAnnotatedMethods( annotationClass ); - } - } - - @Override - public List getAnnotatedFields() { - if ( null == delegate ) { - return super.getAnnotatedFields(); - } - else { - return delegate.getAnnotatedFields(); - } - } - - @Override - public List getAnnotatedFields(Class annotationClass) { - if ( null == delegate ) { - return super.getAnnotatedFields( annotationClass ); - } - else { - return delegate.getAnnotatedFields( annotationClass ); - } - } - - @Override - public Class getJavaClass() { - if ( null == delegate ) { - return super.getJavaClass(); - } - else { - return delegate.getJavaClass(); - } - } - - @Override - public String getName() { - if ( null == delegate ) { - return super.getName(); - } - else { - return delegate.getName(); - } - } - - @Override - public Constructor getOnlyConstructor() { - if ( null == delegate ) { - return super.getOnlyConstructor(); - } - else { - return delegate.getOnlyConstructor(); - } - } - - @Override - public Annotation[] getAnnotations() { - if ( null == delegate ) { - return super.getAnnotations(); - } - else { - return delegate.getAnnotations(); - } - } - - @Override - public T getAnnotation(Class annotationType) { - if ( null == delegate ) { - return super.getAnnotation( annotationType ); - } - else { - return delegate.getAnnotation( annotationType ); - } - } - - @Override - public List getAnnotatedFieldValues(Object test, Class annotationClass, - Class valueClass) { - if ( null == delegate ) { - return super.getAnnotatedFieldValues( test, annotationClass, valueClass ); - } - else { - return delegate.getAnnotatedFieldValues( test, annotationClass, valueClass ); - } - } - - @Override - public List getAnnotatedMethodValues(Object test, Class annotationClass, - Class valueClass) { - if ( null == delegate ) { - return super.getAnnotatedMethodValues( test, annotationClass, valueClass ); - } - else { - return delegate.getAnnotatedMethodValues( test, annotationClass, valueClass ); - } - } - - @Override - public String toString() { - if ( null == delegate ) { - return super.toString(); - } - else { - return delegate.toString(); - } - } - - @Override - public boolean isPublic() { - if ( null == delegate ) { - return super.isPublic(); - } - else { - return delegate.isPublic(); - } - } - - @Override - public boolean isANonStaticInnerClass() { - if ( null == delegate ) { - return super.isANonStaticInnerClass(); - } - else { - return delegate.isANonStaticInnerClass(); - } - } - - @Override - public int hashCode() { - if ( null == delegate ) { - return super.hashCode(); - } - else { - return delegate.hashCode(); - } - } - - @Override - public boolean equals(Object obj) { - if ( null == delegate ) { - return super.equals( obj ); - } - else { - return delegate.equals( obj ); - } - } -} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java deleted file mode 100644 index dc930f370a..0000000000 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/WithSingleCompiler.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.testutil.runner; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Temporarily only use the specified compiler for the test during debugging / implementation. - *

      - * Do not commit tests with this annotation present! - * - * @deprecated Do not commit tests with this annotation present. Tests are expected to work with all compilers. - * @author Andreas Gudian - */ -@Deprecated -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface WithSingleCompiler { - /** - * @return The compiler to use. - */ - Compiler value(); -} diff --git a/processor/src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener b/processor/src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener new file mode 100644 index 0000000000..8ffa996976 --- /dev/null +++ b/processor/src/test/resources/META-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener @@ -0,0 +1 @@ +org.mapstruct.ap.testutil.runner.CompilerLauncherDiscoveryListener \ No newline at end of file From 2d66f08ee563bab15485f4da4ee48242d7fd96d2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 14 Feb 2021 21:37:09 +0100 Subject: [PATCH 0568/1006] Migrate process tests to use new JUnit Jupiter Infrastructure Update test annotations to be JUnit Jupiter compatible Replace all Test annotations from tests that are run with the AnnotationProcessorTestRunner with ProcessorTest. Replace JUnit 4 Test#expected with assertThatThrownBy from AssertJ. Replace Rule for GeneratedSource with RegisterExtension. Fix some tests that were not reverting the changes to the default Locale and TimeZone. Replace usage of org.junit.Assert with equivalent from org.junit.jupiter.api.Assertions or AssertJ. --- .../DateFormatValidatorFactoryTest.java | 2 +- .../common/DefaultConversionContextTest.java | 2 +- .../model/source/SelectionParametersTest.java | 2 +- .../ap/internal/util/NativeTypesTest.java | 7 +- .../ap/internal/util/StringsTest.java | 10 +-- .../ap/spi/util/IntrospectorUtilsTest.java | 4 +- .../test/abstractclass/AbstractClassTest.java | 15 ++-- .../generics/GenericsHierarchyTest.java | 25 +++---- .../test/accessibility/AccessibilityTest.java | 17 ++--- .../ReferencedAccessibilityTest.java | 23 +++--- .../ap/test/array/ArrayMappingTest.java | 53 +++++++------- .../ap/test/bool/BooleanMappingTest.java | 15 ++-- .../ap/test/bugs/_1005/Issue1005Test.java | 13 ++-- .../ap/test/bugs/_1029/Issue1029Test.java | 7 +- .../ap/test/bugs/_1061/Issue1061Test.java | 7 +- .../ap/test/bugs/_1111/Issue1111Test.java | 12 ++- .../ap/test/bugs/_1124/Issue1124Test.java | 11 +-- .../ap/test/bugs/_1130/Issue1130Test.java | 11 +-- .../ap/test/bugs/_1131/Issue1131Test.java | 10 +-- .../ap/test/bugs/_1148/Issue1148Test.java | 21 +++--- .../ap/test/bugs/_1153/Issue1153Test.java | 7 +- .../ap/test/bugs/_1155/Issue1155Test.java | 7 +- .../ap/test/bugs/_1159/Issue1159Test.java | 12 +-- .../ap/test/bugs/_1164/Issue1164Test.java | 7 +- .../ap/test/bugs/_1170/AdderTest.java | 13 ++-- .../ap/test/bugs/_1180/Issue1180Test.java | 7 +- .../ap/test/bugs/_1215/Issue1215Test.java | 7 +- .../ap/test/bugs/_1227/Issue1227Test.java | 7 +- .../ap/test/bugs/_1242/Issue1242Test.java | 13 ++-- .../ap/test/bugs/_1244/Issue1244Test.java | 7 +- .../ap/test/bugs/_1247/Issue1247Test.java | 11 +-- .../ap/test/bugs/_1255/Issue1255Test.java | 12 ++- .../ap/test/bugs/_1269/Issue1269Test.java | 7 +- .../ap/test/bugs/_1273/Issue1273Test.java | 13 ++-- .../ap/test/bugs/_1283/Issue1283Test.java | 9 +-- .../ap/test/bugs/_1320/Issue1320Test.java | 7 +- .../ap/test/bugs/_1338/Issue1338Test.java | 7 +- .../ap/test/bugs/_1339/Issue1339Test.java | 7 +- .../ap/test/bugs/_1340/Issue1340Test.java | 7 +- .../ap/test/bugs/_1345/Issue1345Test.java | 7 +- .../ap/test/bugs/_1353/Issue1353Test.java | 7 +- .../ap/test/bugs/_1359/Issue1359Test.java | 7 +- .../ap/test/bugs/_1375/Issue1375Test.java | 7 +- .../ap/test/bugs/_1395/Issue1395Test.java | 7 +- .../ap/test/bugs/_1425/Issue1425Test.java | 7 +- .../ap/test/bugs/_1435/Issue1435Test.java | 7 +- .../ap/test/bugs/_1453/Issue1453Test.java | 13 ++-- .../ap/test/bugs/_1457/Issue1457Test.java | 17 ++--- .../ap/test/bugs/_1460/Issue1460Test.java | 7 +- .../_1460/java8/Issue1460JavaTimeTest.java | 7 +- .../ap/test/bugs/_1482/Issue1482Test.java | 9 +-- .../test/bugs/_1523/java8/Issue1523Test.java | 15 ++-- .../ap/test/bugs/_1541/Issue1541Test.java | 21 +++--- .../ap/test/bugs/_1552/Issue1552Test.java | 7 +- .../test/bugs/_1558/java8/Issue1558Test.java | 7 +- .../ap/test/bugs/_1561/Issue1561Test.java | 13 ++-- .../ap/test/bugs/_1566/Issue1566Test.java | 7 +- .../test/bugs/_1569/java8/Issue1569Test.java | 7 +- .../test/bugs/_1576/java8/Issue1576Test.java | 13 ++-- .../ap/test/bugs/_1590/Issue1590Test.java | 7 +- .../ap/test/bugs/_1594/Issue1594Test.java | 7 +- .../ap/test/bugs/_1596/Issue1596Test.java | 7 +- .../ap/test/bugs/_1608/Issue1608Test.java | 7 +- .../ap/test/bugs/_1648/Issue1648Test.java | 7 +- .../ap/test/bugs/_1650/Issue1650Test.java | 7 +- .../ap/test/bugs/_1660/Issue1660Test.java | 7 +- .../ap/test/bugs/_1665/Issue1665Test.java | 13 ++-- .../ap/test/bugs/_1681/Issue1681Test.java | 9 +-- .../ap/test/bugs/_1685/Issue1685Test.java | 17 ++--- .../ap/test/bugs/_1698/Issue1698Test.java | 7 +- .../ap/test/bugs/_1707/Issue1707Test.java | 13 ++-- .../ap/test/bugs/_1714/Issue1714Test.java | 7 +- .../ap/test/bugs/_1719/Issue1719Test.java | 7 +- .../ap/test/bugs/_1738/Issue1738Test.java | 7 +- .../ap/test/bugs/_1742/Issue1742Test.java | 7 +- .../ap/test/bugs/_1751/Issue1751Test.java | 7 +- .../ap/test/bugs/_1772/Issue1772Test.java | 7 +- .../ap/test/bugs/_1788/Issue1788Test.java | 7 +- .../ap/test/bugs/_1790/Issue1790Test.java | 7 +- .../ap/test/bugs/_1797/Issue1797Test.java | 7 +- .../ap/test/bugs/_1799/Issue1799Test.java | 7 +- .../ap/test/bugs/_1801/Issue1801Test.java | 7 +- .../ap/test/bugs/_1821/Issue1821Test.java | 7 +- .../ap/test/bugs/_1826/Issue1826Test.java | 7 +- .../ap/test/bugs/_1828/Issue1828Test.java | 11 +-- .../ap/test/bugs/_1881/Issue1881Test.java | 7 +- .../ap/test/bugs/_1904/Issue1904Test.java | 7 +- .../ap/test/bugs/_1933/Issue1933Test.java | 7 +- .../ap/test/bugs/_1966/Issue1966Test.java | 7 +- .../ap/test/bugs/_2001/Issue2001Test.java | 7 +- .../ap/test/bugs/_2018/Issue2018Test.java | 7 +- .../ap/test/bugs/_2021/Issue2021Test.java | 7 +- .../ap/test/bugs/_2023/Issue2023Test.java | 7 +- .../ap/test/bugs/_2042/Issue2402Test.java | 7 +- .../ap/test/bugs/_2077/Issue2077Test.java | 7 +- .../ap/test/bugs/_2101/Issue2101Test.java | 13 ++-- .../ap/test/bugs/_2109/Issue2109Test.java | 7 +- .../ap/test/bugs/_2111/Issue2111Test.java | 7 +- .../ap/test/bugs/_2117/Issue2117Test.java | 7 +- .../ap/test/bugs/_2121/Issue2121Test.java | 7 +- .../ap/test/bugs/_2122/Issue2122Test.java | 12 +-- .../ap/test/bugs/_2124/Issue2124Test.java | 7 +- .../ap/test/bugs/_2125/Issue2125Test.java | 9 +-- .../ap/test/bugs/_2131/Issue2131Test.java | 7 +- .../ap/test/bugs/_2133/Issue2133Test.java | 7 +- .../ap/test/bugs/_2142/Issue2142Test.java | 13 ++-- .../ap/test/bugs/_2145/Issue2145Test.java | 7 +- .../ap/test/bugs/_2149/Issue2149Test.java | 7 +- .../ap/test/bugs/_2164/Issue2164Test.java | 7 +- .../ap/test/bugs/_2170/Issue2170Test.java | 7 +- .../ap/test/bugs/_2174/Issue2174Test.java | 7 +- .../ap/test/bugs/_2177/Issue2177Test.java | 7 +- .../ap/test/bugs/_2185/Issue2185Test.java | 7 +- .../ap/test/bugs/_2195/Issue2195Test.java | 7 +- .../ap/test/bugs/_2197/Issue2197Test.java | 13 ++-- .../ap/test/bugs/_2213/Issue2213Test.java | 13 ++-- .../ap/test/bugs/_2221/Issue2221Test.java | 7 +- .../ap/test/bugs/_2233/Issue2233Test.java | 7 +- .../ap/test/bugs/_2236/Issue2236Test.java | 7 +- .../ap/test/bugs/_2245/Issue2245Test.java | 13 ++-- .../ap/test/bugs/_2251/Issue2251Test.java | 7 +- .../ap/test/bugs/_2253/Issue2253Test.java | 7 +- .../ap/test/bugs/_2263/Issue2263Test.java | 7 +- .../ap/test/bugs/_2278/Issue2278Test.java | 11 +-- .../ap/test/bugs/_2301/Issue2301Test.java | 7 +- .../ap/test/bugs/_2318/Issue2318Test.java | 7 +- .../ap/test/bugs/_2347/Issue2347Test.java | 7 +- .../ap/test/bugs/_2352/Issue2352Test.java | 7 +- .../ap/test/bugs/_2356/Issue2356Test.java | 7 +- .../ap/test/bugs/_2393/Issue2393Test.java | 7 +- .../ap/test/bugs/_289/Issue289Test.java | 15 ++-- .../ap/test/bugs/_306/Issue306Test.java | 7 +- .../ap/test/bugs/_373/Issue373Test.java | 7 +- .../ap/test/bugs/_374/Issue374Test.java | 23 +++--- .../ap/test/bugs/_375/Issue375Test.java | 7 +- .../SameClassNameInDifferentPackageTest.java | 11 +-- .../ap/test/bugs/_405/Issue405Test.java | 7 +- .../ap/test/bugs/_513/Issue513Test.java | 27 ++++--- .../ap/test/bugs/_515/Issue515Test.java | 7 +- .../ap/test/bugs/_516/Issue516Test.java | 11 +-- .../ap/test/bugs/_537/Issue537Test.java | 7 +- .../ap/test/bugs/_543/Issue543Test.java | 13 ++-- .../ap/test/bugs/_577/Issue577Test.java | 11 +-- .../ap/test/bugs/_581/Issue581Test.java | 11 +-- .../ap/test/bugs/_590/Issue590Test.java | 7 +- .../ap/test/bugs/_611/Issue611Test.java | 11 +-- .../ap/test/bugs/_625/Issue625Test.java | 11 +-- .../ap/test/bugs/_631/Issue631Test.java | 7 +- .../test/bugs/_634/GenericContainerTest.java | 11 +-- .../IterableWithBoundedElementTypeTest.java | 13 ++-- .../mapstruct/ap/test/bugs/_843/Commit.java | 4 + .../ap/test/bugs/_843/GitlabTag.java | 4 + .../ap/test/bugs/_843/Issue843Test.java | 13 ++-- .../ap/test/bugs/_846/UpdateTest.java | 7 +- .../ap/test/bugs/_849/Issue849Test.java | 11 +-- .../ap/test/bugs/_855/OrderingBug855Test.java | 13 ++-- .../ap/test/bugs/_865/Issue865Test.java | 12 ++- .../ap/test/bugs/_880/Issue880Test.java | 13 ++-- .../ap/test/bugs/_891/Issue891Test.java | 7 +- .../ap/test/bugs/_892/Issue892Test.java | 11 +-- .../ap/test/bugs/_895/Issue895Test.java | 11 +-- .../ap/test/bugs/_909/Issue909Test.java | 11 +-- ...ssue913GetterMapperForCollectionsTest.java | 26 +++---- ...ssue913SetterMapperForCollectionsTest.java | 41 +++++------ .../ap/test/bugs/_931/Issue931Test.java | 11 +-- .../ap/test/bugs/_955/Issue955Test.java | 7 +- .../ap/test/bugs/_971/Issue971Test.java | 9 +-- .../abstractBuilder/AbstractBuilderTest.java | 9 +-- .../AbstractGenericTargetBuilderTest.java | 7 +- .../factory/BuilderFactoryMapperTest.java | 9 +-- .../builder/ignore/BuilderIgnoringTest.java | 11 +-- .../BuilderLifecycleCallbacksTest.java | 7 +- .../simple/BuilderInfoTargetTest.java | 19 ++--- .../multiple/MultipleBuilderMapperTest.java | 17 ++--- .../expanding/BuilderNestedPropertyTest.java | 7 +- .../flattening/BuilderNestedPropertyTest.java | 7 +- .../builder/noop/NoOpBuilderProviderTest.java | 7 +- .../SimpleNotRealyImmutableBuilderTest.java | 13 ++-- .../parentchild/ParentChildBuilderTest.java | 7 +- .../simple/SimpleImmutableBuilderTest.java | 15 ++-- .../ap/test/builtin/BuiltInTest.java | 50 ++++++------- .../ap/test/builtin/DatatypeFactoryTest.java | 15 ++-- .../test/builtin/jodatime/JodaTimeTest.java | 57 +++++++-------- .../ap/test/callbacks/CallbackMethodTest.java | 29 ++++---- .../MappingResultPostprocessorTest.java | 11 +-- .../CallbacksWithReturnValuesTest.java | 28 +++---- .../CallbackMethodTypeMatchingTest.java | 11 +-- .../collection/CollectionMappingTest.java | 67 ++++++++--------- .../ap/test/collection/adder/AdderTest.java | 54 +++++++------- .../DefaultCollectionImplementationTest.java | 45 ++++++------ .../NoSetterCollectionMappingTest.java | 13 ++-- .../ErroneousCollectionMappingTest.java | 25 +++---- .../forged/CollectionMappingTest.java | 28 +++---- .../immutabletarget/ImmutableProductTest.java | 13 ++-- .../IterableToNonIterableMappingTest.java | 13 ++-- .../test/collection/map/MapMappingTest.java | 25 +++---- .../collection/wildcard/WildCardTest.java | 30 ++++---- .../ap/test/complex/CarMapperTest.java | 37 +++++----- .../basic/ConditionalMappingTest.java | 31 ++++---- .../expression/ConditionalExpressionTest.java | 11 +-- .../qualifier/ConditionalQualifierTest.java | 9 +-- .../SimpleConstructorPropertiesTest.java | 11 +-- ...SimpleDefaultAnnotatedConstructorTest.java | 11 +-- .../erroneous/ErroneousConstructorTest.java | 9 +-- ...SourceArgumentsConstructorMappingTest.java | 7 +- .../ConstructorMixedWithSettersTest.java | 7 +- ...NestedSourcePropertiesConstructorTest.java | 17 ++--- ...NestedSourcePropertiesConstructorTest.java | 17 ++--- ...estedProductPropertiesConstructorTest.java | 15 ++-- .../simple/SimpleConstructorTest.java | 11 +-- .../unmapped/UnmappedConstructorTest.java | 7 +- .../visibility/ConstructorVisibilityTest.java | 11 +-- .../ContextParameterErroneousTest.java | 7 +- .../ap/test/context/ContextParameterTest.java | 15 ++-- .../ContextWithObjectFactoryTest.java | 11 +-- .../ap/test/conversion/ConversionTest.java | 19 ++--- .../bignumbers/BigNumbersConversionTest.java | 31 +++----- .../currency/CurrencyConversionTest.java | 9 +-- .../conversion/date/DateConversionTest.java | 67 +++++++---------- .../erroneous/InvalidDateFormatTest.java | 7 +- .../java8time/Java8TimeConversionTest.java | 71 +++++++++--------- ...eToXMLGregorianCalendarConversionTest.java | 22 +++--- ...eToXMLGregorianCalendarConversionTest.java | 14 ++-- .../jodatime/JodaConversionTest.java | 61 +++++++--------- .../conversion/lossy/LossyConversionTest.java | 23 +++--- .../nativetypes/BooleanConversionTest.java | 15 ++-- .../nativetypes/CharConversionTest.java | 15 ++-- .../nativetypes/NumberConversionTest.java | 35 ++++----- .../numbers/NumberFormatConversionTest.java | 25 +++---- .../conversion/precedence/ConversionTest.java | 11 +-- .../string/StringConversionTest.java | 17 ++--- .../ap/test/decorator/DecoratorTest.java | 24 +++--- .../decorator/jsr330/Jsr330DecoratorTest.java | 36 ++++----- .../constructor/SpringDecoratorTest.java | 21 +++--- .../spring/field/SpringDecoratorTest.java | 21 +++--- .../DefaultComponentModelMapperTest.java | 13 ++-- .../test/defaultvalue/DefaultValueTest.java | 21 +++--- .../ap/test/dependency/GraphAnalyzerTest.java | 6 +- .../ap/test/dependency/OrderingTest.java | 17 ++--- .../destination/DestinationClassNameTest.java | 25 +++---- .../DestinationPackageNameTest.java | 19 ++--- .../AmbiguousAnnotatedFactoryTest.java | 7 +- .../ambiguousfactorymethod/FactoryTest.java | 7 +- .../ambiguousmapping/AmbiguousMapperTest.java | 11 +-- .../AnnotationNotFoundTest.java | 7 +- .../ErroneousMappingsTest.java | 11 +-- .../MisbalancedBracesTest.java | 7 +- .../ErroneousPropertyMappingTest.java | 13 ++-- .../typemismatch/ErroneousMappingsTest.java | 7 +- .../ap/test/exceptions/ExceptionTest.java | 62 +++++++++------- .../ap/test/factories/FactoryTest.java | 13 ++-- .../ParameterAssigmentFactoryTest.java | 15 ++-- .../qualified/QualifiedFactoryTest.java | 15 ++-- .../targettype/ProductTypeFactoryTest.java | 13 ++-- .../ap/test/fields/FieldsMappingTest.java | 13 ++-- .../mapstruct/ap/test/gem/ConstantTest.java | 6 +- .../mapstruct/ap/test/gem/EnumGemsTest.java | 6 +- .../ap/test/generics/GenericsTest.java | 11 +-- .../MapperWithGenericSuperClassTest.java | 11 +-- .../ap/test/ignore/IgnorePropertyTest.java | 17 ++--- .../ignore/expand/IgnorePropertyTest.java | 11 +-- .../ignore/inherit/IgnorePropertyTest.java | 15 ++-- .../imports/ConflictingTypesNamesTest.java | 25 +++---- .../test/imports/InnerClassesImportsTest.java | 25 +++---- .../DecoratorInAnotherPackageTest.java | 11 +-- ...ontainsCollectionWithExtendsBoundTest.java | 21 ++---- .../ap/test/inheritance/InheritanceTest.java | 17 ++--- .../attribute/AttributeInheritanceTest.java | 13 ++-- .../complex/ComplexInheritanceTest.java | 16 ++-- .../InheritedMappingMethodTest.java | 17 ++--- .../InheritFromConfigTest.java | 43 +++++------ .../multiple/CarMapperTest.java | 15 ++-- ...30DefaultCompileOptionFieldMapperTest.java | 23 +++--- ...330CompileOptionConstructorMapperTest.java | 23 +++--- .../Jsr330ConstructorMapperTest.java | 23 +++--- .../jsr330/field/Jsr330FieldMapperTest.java | 23 +++--- .../_default/SpringDefaultMapperTest.java | 23 +++--- ...ingCompileOptionConstructorMapperTest.java | 31 ++++---- .../SpringConstructorMapperTest.java | 31 ++++---- .../spring/field/SpringFieldMapperTest.java | 23 +++--- .../test/java8stream/StreamMappingTest.java | 43 +++++------ .../ap/test/java8stream/base/StreamsTest.java | 17 ++--- .../context/StreamWithContextTest.java | 11 +-- .../DefaultStreamImplementationTest.java | 35 ++++----- .../NoSetterStreamMappingTest.java | 11 +-- .../erroneous/ErroneousStreamMappingTest.java | 23 +++--- .../forged/ForgedStreamMappingTest.java | 23 +++--- .../StreamToNonIterableMappingTest.java | 13 ++-- .../java8stream/wildcard/WildCardTest.java | 21 +++--- .../ap/test/mapperconfig/ConfigTest.java | 17 ++--- .../mappingcomposition/CompositionTest.java | 7 +- .../mappingcontrol/MappingControlTest.java | 27 +++---- .../SuggestMostSimilarNameTest.java | 13 ++-- .../ap/test/naming/VariableNamingTest.java | 13 ++-- .../naming/spi/CustomNamingStrategyTest.java | 11 +-- ...DisablingNestedSimpleBeansMappingTest.java | 9 +-- .../nestedbeans/DottedErrorMessageTest.java | 23 +++--- .../MultipleForgedMethodsTest.java | 24 +++--- .../NestedSimpleBeansMappingTest.java | 17 ++--- .../ap/test/nestedbeans/RecursionTest.java | 13 ++-- .../NestedMappingsWithExceptionTest.java | 7 +- .../exclusions/ErroneousJavaInternalTest.java | 7 +- .../custom/ErroneousCustomExclusionTest.java | 7 +- .../mixed/AutomappingAndNestedTest.java | 25 +++---- .../NestedMappingMethodInvocationTest.java | 24 +++--- .../simple/SimpleNestedPropertiesTest.java | 26 +++---- .../exceptions/NestedExceptionTest.java | 7 +- .../parameter/NormalizingTest.java | 11 +-- .../NestedSourcePropertiesTest.java | 33 ++++----- .../ReversingNestedSourcePropertiesTest.java | 24 +++--- .../NestedProductPropertiesTest.java | 19 ++--- .../nonvoidsetter/NonVoidSettersTest.java | 11 +-- .../ap/test/nullcheck/NullCheckTest.java | 23 +++--- .../strategy/NullValueCheckTest.java | 17 ++--- .../NullValueMappingTest.java | 33 ++++----- .../NullValuePropertyMappingTest.java | 27 +++---- .../mapstruct/ap/test/oneway/OnewayTest.java | 15 ++-- .../test/references/ReferencedMapperTest.java | 19 ++--- ...ferencedMappersWithSameSimpleNameTest.java | 13 ++-- .../test/references/statics/StaticsTest.java | 23 ++---- .../InheritInverseConfigurationTest.java | 15 ++-- .../selection/generics/ConversionTest.java | 17 ++--- .../jaxb/JaxbFactoryMethodSelectionTest.java | 11 +-- .../jaxb/UnderscoreSelectionTest.java | 11 +-- .../array/GenericArrayTest.java | 15 ++-- .../methodgenerics/bounds/BoundsTest.java | 11 +-- .../multiple/MultipleTypeVarTest.java | 17 ++--- .../nestedgenerics/NestedGenericsTest.java | 13 ++-- .../methodgenerics/plain/PlainTest.java | 17 ++--- .../targettype/TargetTypeTest.java | 13 ++-- .../wildcards/WildCardTest.java | 13 +--- .../PrimitiveVsWrappedSelectionTest.java | 15 ++-- .../selection/qualifier/QualifierTest.java | 15 ++-- .../qualifier/errors/QualfierMessageTest.java | 13 ++-- .../qualifier/hybrid/HybridTest.java | 11 +-- .../iterable/IterableAndQualifiersTest.java | 9 +-- .../selection/qualifier/named/NamedTest.java | 15 ++-- .../resulttype/InheritanceSelectionTest.java | 29 ++++---- .../twosteperror/TwoStepMappingTest.java | 11 +-- .../selection/typegenerics/WildCardTest.java | 11 +-- .../selection/wildcards/WildCardTest.java | 13 ++-- .../test/source/constants/ConstantsTest.java | 15 ++-- .../source/constants/SourceConstantsTest.java | 26 +++---- .../java/JavaDefaultExpressionTest.java | 21 +++--- .../expressions/java/JavaExpressionTest.java | 21 +++--- .../IgnoreUnmappedSourcePropertiesTest.java | 7 +- .../ManySourceArgumentsTest.java | 29 ++++---- .../SourceToManyTargetPropertiesTest.java | 13 ++-- .../PresenceCheckTest.java | 17 ++--- .../spi/PresenceCheckMappingTest.java | 13 ++-- .../spi/PresenceCheckNestedObjectsTest.java | 10 +-- .../presencecheck/spi/PresenceCheckTest.java | 31 ++++---- .../targetthis/TargetThisMappingTest.java | 17 ++--- .../template/InheritConfigurationTest.java | 24 +++--- .../unmappedsource/UnmappedSourceTest.java | 17 ++--- .../unmappedtarget/UnmappedProductTest.java | 15 ++-- .../test/updatemethods/UpdateMethodsTest.java | 25 +++---- .../ManyArgumentsUpdateMappingTest.java | 7 +- .../selection/ExternalSelectionTest.java | 19 ++--- .../enum2enum/EnumToEnumMappingTest.java | 39 +++++----- .../EnumToEnumThrowExceptionMappingTest.java | 15 ++-- .../enum2string/EnumToStringMappingTest.java | 11 +-- .../erroneous/ErroneousEnumMappingTest.java | 9 +-- ...omUnexpectedValueMappingExceptionTest.java | 13 ++-- .../EnumNameTransformationStrategyTest.java | 17 ++--- .../spi/CustomEnumMappingStrategyTest.java | 17 ++--- ...ustomErroneousEnumMappingStrategyTest.java | 9 +-- .../string2enum/StringToEnumMappingTest.java | 11 +-- .../ap/test/verbose/VerboseTest.java | 73 +++---------------- .../ap/test/versioninfo/VersionInfoTest.java | 21 ++---- 370 files changed, 2147 insertions(+), 3298 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java index 7bbc80e51b..646f898063 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactoryTest.java @@ -20,7 +20,7 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVisitor; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.ap.internal.util.JodaTimeConstants; import org.mapstruct.ap.testutil.IssueKey; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index f8cceee9c0..ce2f895e0f 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -20,7 +20,7 @@ import javax.lang.model.type.TypeVisitor; import javax.tools.Diagnostic; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.testutil.IssueKey; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java index 19e194a764..4c6e78e0c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/source/SelectionParametersTest.java @@ -24,7 +24,7 @@ import javax.lang.model.type.TypeVisitor; import javax.lang.model.type.WildcardType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.ap.internal.util.TypeUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java index 74272cbae3..9c68a1de45 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java @@ -6,12 +6,13 @@ package org.mapstruct.ap.internal.util; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.math.BigInteger; -import org.junit.Test; + +import org.junit.jupiter.api.Test; /** * @author Ciaran Liedeman diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 9d6dc88655..44fbb565ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -11,9 +11,9 @@ import java.util.Arrays; import java.util.Locale; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Filip Hrisafov @@ -23,12 +23,12 @@ public class StringsTest { private static final Locale TURKEY_LOCALE = getTurkeyLocale(); private Locale defaultLocale; - @Before + @BeforeEach public void before() { defaultLocale = Locale.getDefault(); } - @After + @AfterEach public void after() { Locale.setDefault( defaultLocale ); } diff --git a/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java index 7114f7b9f8..84469f3f64 100644 --- a/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/spi/util/IntrospectorUtilsTest.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.spi.util; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; /** * @author Saheb Preet Singh diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java index f510fd32e9..4e931b487b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/AbstractClassTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.abstractclass; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for the generation of implementation of abstract base classes. @@ -31,10 +29,9 @@ Measurable.class, Holder.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AbstractClassTest { - @Test + @ProcessorTest @IssueKey("64") public void shouldCreateImplementationOfAbstractMethod() { Source source = new Source(); @@ -42,7 +39,7 @@ public void shouldCreateImplementationOfAbstractMethod() { assertResult( SourceTargetMapper.INSTANCE.sourceToTarget( source ) ); } - @Test + @ProcessorTest @IssueKey("165") public void shouldCreateImplementationOfMethodFromSuper() { Source source = new Source(); @@ -50,7 +47,7 @@ public void shouldCreateImplementationOfMethodFromSuper() { assertResult( SourceTargetMapper.INSTANCE.sourceToTargetFromBaseMapper( source ) ); } - @Test + @ProcessorTest @IssueKey("165") public void shouldCreateImplementationOfMethodFromInterface() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java index 282a8e8efb..fa483c9037 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/abstractclass/generics/GenericsHierarchyTest.java @@ -5,21 +5,17 @@ */ package org.mapstruct.ap.test.abstractclass.generics; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian * */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("644,687,688") @WithClasses({ AbstractAnimal.class, @@ -35,14 +31,11 @@ }) public class GenericsHierarchyTest { - @Test - // Disabled due to a bug in the Eclipse compiler (https://bugs.eclipse.org/bugs/show_bug.cgi?id=540101) + // Running only with the JDK compiler due to a bug in the Eclipse compiler + // (https://bugs.eclipse.org/bugs/show_bug.cgi?id=540101) // See https://github.com/mapstruct/mapstruct/issues/1553 and https://github.com/mapstruct/mapstruct/pull/1587 // for more information - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) public void determinesAnimalKeyGetter() { AbstractAnimal source = new Elephant(); @@ -56,7 +49,7 @@ public void determinesAnimalKeyGetter() { assertThat( target.getAnimalKey().typeParameterIsResolvedToKeyOfAllBeings() ).isFalse(); } - @Test + @ProcessorTest public void determinesKeyOfAllBeingsGetter() { AbstractHuman source = new Child(); @@ -69,7 +62,7 @@ public void determinesKeyOfAllBeingsGetter() { assertThat( target.getKeyOfAllBeings().typeParameterIsResolvedToKeyOfAllBeings() ).isTrue(); } - @Test + @ProcessorTest public void determinesItemCSourceSetter() { Target target = new Target(); @@ -81,7 +74,7 @@ public void determinesItemCSourceSetter() { assertThat( source.getKey().typeParameterIsResolvedToAnimalKey() ).isTrue(); } - @Test + @ProcessorTest public void determinesItemBSourceSetter() { Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java index 0ee789750c..d338cadedd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.accessibility; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + import static java.lang.reflect.Modifier.isPrivate; import static java.lang.reflect.Modifier.isProtected; import static java.lang.reflect.Modifier.isPublic; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.testutil.IssueKey; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test for different accessibility modifiers @@ -22,10 +20,9 @@ * @author Andreas Gudian */ @WithClasses({ Source.class, Target.class, DefaultSourceTargetMapperAbstr.class, DefaultSourceTargetMapperIfc.class }) -@RunWith( AnnotationProcessorTestRunner.class ) public class AccessibilityTest { - @Test + @ProcessorTest @IssueKey("103") public void testGeneratedModifiersFromAbstractClassAreCorrect() throws Exception { Class defaultFromAbstract = loadForMapper( DefaultSourceTargetMapperAbstr.class ); @@ -37,7 +34,7 @@ public void testGeneratedModifiersFromAbstractClassAreCorrect() throws Exception assertTrue( isDefault( modifiersFor( defaultFromAbstract, "defaultSourceToTarget" ) ) ); } - @Test + @ProcessorTest @IssueKey("103") public void testGeneratedModifiersFromInterfaceAreCorrect() throws Exception { Class defaultFromIfc = loadForMapper( DefaultSourceTargetMapperIfc.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 44aeb033fa..3cd62a8b4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.accessibility.referenced; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.accessibility.referenced.a.ReferencedMapperDefaultOther; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; /** @@ -23,13 +21,12 @@ * @author Sjaak Derksen */ @WithClasses( { Source.class, Target.class, ReferencedSource.class, ReferencedTarget.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class ReferencedAccessibilityTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @IssueKey("206") @WithClasses({ SourceTargetMapperPrivate.class, ReferencedMapperPrivate.class }) @ExpectedCompilationOutcome( @@ -46,17 +43,17 @@ public void shouldNotBeAbleToAccessPrivateMethodInReferenced() { generatedSource.addComparisonToFixtureFor( SourceTargetMapperPrivate.class ); } - @Test + @ProcessorTest @IssueKey( "206" ) @WithClasses( { SourceTargetMapperDefaultSame.class, ReferencedMapperDefaultSame.class } ) public void shouldBeAbleToAccessDefaultMethodInReferencedInSamePackage() { } - @Test + @ProcessorTest @IssueKey( "206" ) @WithClasses( { SourceTargetMapperProtected.class, ReferencedMapperProtected.class } ) public void shouldBeAbleToAccessProtectedMethodInReferencedInSamePackage() { } - @Test + @ProcessorTest @IssueKey("206") @WithClasses({ SourceTargetMapperDefaultOther.class, ReferencedMapperDefaultOther.class }) @ExpectedCompilationOutcome( @@ -73,12 +70,12 @@ public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() { generatedSource.addComparisonToFixtureFor( SourceTargetMapperDefaultOther.class ); } - @Test + @ProcessorTest @IssueKey( "206" ) @WithClasses( { AbstractSourceTargetMapperProtected.class, SourceTargetmapperProtectedBase.class } ) public void shouldBeAbleToAccessProtectedMethodInBase() { } - @Test + @ProcessorTest @IssueKey("206") @WithClasses({ AbstractSourceTargetMapperPrivate.class, SourceTargetmapperPrivateBase.class }) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index 39adff4eb7..07113f7cf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -5,31 +5,28 @@ */ package org.mapstruct.ap.test.array; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.array._target.ScientistDto; import org.mapstruct.ap.test.array.source.Scientist; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + @WithClasses( { Scientist.class, ScientistDto.class, ScienceMapper.class } ) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("108") public class ArrayMappingTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( ScienceMapper.class ); - @Test + @ProcessorTest public void shouldCopyArraysInBean() { Scientist source = new Scientist("Bob"); @@ -44,7 +41,7 @@ public void shouldCopyArraysInBean() { assertThat( dto.publicPublications ).containsOnly( "public the Lancet", "public Nature" ); } - @Test + @ProcessorTest public void shouldForgeMappingForIntToString() { Scientist source = new Scientist("Bob"); @@ -58,7 +55,7 @@ public void shouldForgeMappingForIntToString() { assertThat( dto.publicPublicationYears ).containsOnly( 1994, 1998 ); } - @Test + @ProcessorTest public void shouldMapArrayToArray() { ScientistDto[] dtos = ScienceMapper.INSTANCE .scientistsToDtos( new Scientist[]{ new Scientist( "Bob" ), new Scientist( "Larry" ) } ); @@ -67,7 +64,7 @@ public void shouldMapArrayToArray() { assertThat( dtos ).extracting( "name" ).containsOnly( "Bob", "Larry" ); } - @Test + @ProcessorTest public void shouldMapListToArray() { ScientistDto[] dtos = ScienceMapper.INSTANCE .scientistsToDtos( Arrays.asList( new Scientist( "Bob" ), new Scientist( "Larry" ) ) ); @@ -76,7 +73,7 @@ public void shouldMapListToArray() { assertThat( dtos ).extracting( "name" ).containsOnly( "Bob", "Larry" ); } - @Test + @ProcessorTest public void shouldMapArrayToList() { List dtos = ScienceMapper.INSTANCE .scientistsToDtosAsList( new Scientist[]{ new Scientist( "Bob" ), new Scientist( "Larry" ) } ); @@ -85,7 +82,7 @@ public void shouldMapArrayToList() { assertThat( dtos ).extracting( "name" ).containsOnly( "Bob", "Larry" ); } - @Test + @ProcessorTest public void shouldMapArrayToArrayExistingSmallerSizedTarget() { ScientistDto[] existingTarget = new ScientistDto[]{ new ScientistDto( "Jim" ) }; @@ -98,7 +95,7 @@ public void shouldMapArrayToArrayExistingSmallerSizedTarget() { assertThat( target ).extracting( "name" ).containsOnly( "Bob" ); } - @Test + @ProcessorTest public void shouldMapArrayToArrayExistingEqualSizedTarget() { ScientistDto[] existingTarget = new ScientistDto[]{ new ScientistDto( "Jim" ), new ScientistDto( "Bart" ) }; @@ -111,7 +108,7 @@ public void shouldMapArrayToArrayExistingEqualSizedTarget() { assertThat( target ).extracting( "name" ).containsOnly( "Bob", "Larry" ); } - @Test + @ProcessorTest public void shouldMapArrayToArrayExistingLargerSizedTarget() { ScientistDto[] existingTarget = @@ -125,7 +122,7 @@ public void shouldMapArrayToArrayExistingLargerSizedTarget() { assertThat( target ).extracting( "name" ).containsOnly( "Bob", "Larry", "John" ); } - @Test + @ProcessorTest public void shouldMapTargetToNullWhenNullSource() { // TODO: What about existing target? @@ -139,7 +136,7 @@ public void shouldMapTargetToNullWhenNullSource() { } @IssueKey("534") - @Test + @ProcessorTest public void shouldMapBooleanWhenReturnDefault() { boolean[] existingTarget = new boolean[]{true}; @@ -151,7 +148,7 @@ public void shouldMapBooleanWhenReturnDefault() { assertThat( ScienceMapper.INSTANCE.nvmMapping( null ) ).isEmpty(); } - @Test + @ProcessorTest public void shouldMapShortWhenReturnDefault() { short[] existingTarget = new short[]{ 5 }; short[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -160,7 +157,7 @@ public void shouldMapShortWhenReturnDefault() { assertThat( existingTarget ).containsOnly( new short[] { 0 } ); } - @Test + @ProcessorTest public void shouldMapCharWhenReturnDefault() { char[] existingTarget = new char[]{ 'a' }; char[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -169,7 +166,7 @@ public void shouldMapCharWhenReturnDefault() { assertThat( existingTarget ).containsOnly( new char[] { 0 } ); } - @Test + @ProcessorTest public void shouldMapIntWhenReturnDefault() { int[] existingTarget = new int[]{ 5 }; int[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -178,7 +175,7 @@ public void shouldMapIntWhenReturnDefault() { assertThat( existingTarget ).containsOnly( 0 ); } - @Test + @ProcessorTest public void shouldMapLongWhenReturnDefault() { long[] existingTarget = new long[]{ 5L }; long[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -187,7 +184,7 @@ public void shouldMapLongWhenReturnDefault() { assertThat( existingTarget ).containsOnly( 0L ); } - @Test + @ProcessorTest public void shouldMapFloatWhenReturnDefault() { float[] existingTarget = new float[]{ 3.1f }; float[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -196,7 +193,7 @@ public void shouldMapFloatWhenReturnDefault() { assertThat( existingTarget ).containsOnly( 0.0f ); } - @Test + @ProcessorTest public void shouldMapDoubleWhenReturnDefault() { double[] existingTarget = new double[]{ 5.0d }; double[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); @@ -205,21 +202,21 @@ public void shouldMapDoubleWhenReturnDefault() { assertThat( existingTarget ).containsOnly( 0.0d ); } - @Test + @ProcessorTest public void shouldVoidMapIntWhenReturnNull() { long[] existingTarget = new long[]{ 5L }; ScienceMapper.INSTANCE.nvmMappingVoidReturnNull( null, existingTarget ); assertThat( existingTarget ).containsOnly( 5L ); } - @Test + @ProcessorTest public void shouldVoidMapIntWhenReturnDefault() { long[] existingTarget = new long[]{ 5L }; ScienceMapper.INSTANCE.nvmMappingVoidReturnDefault( null, existingTarget ); assertThat( existingTarget ).containsOnly( 0L ); } - @Test + @ProcessorTest @IssueKey( "999" ) public void shouldNotContainFQNForStringArray() { generatedSource.forMapper( ScienceMapper.class ).content().doesNotContain( "java.lang.String[]" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java index 6ca327cce4..9efb09b1e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bool/BooleanMappingTest.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.bool; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Person.class, @@ -19,10 +17,9 @@ PersonMapper.class, YesNoMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class BooleanMappingTest { - @Test + @ProcessorTest public void shouldMapBooleanPropertyWithIsPrefixedGetter() { //given Person person = new Person(); @@ -35,7 +32,7 @@ public void shouldMapBooleanPropertyWithIsPrefixedGetter() { assertThat( personDto.getMarried() ).isEqualTo( "true" ); } - @Test + @ProcessorTest public void shouldMapBooleanPropertyPreferringGetPrefixedGetterOverIsPrefixedGetter() { //given Person person = new Person(); @@ -48,7 +45,7 @@ public void shouldMapBooleanPropertyPreferringGetPrefixedGetterOverIsPrefixedGet assertThat( personDto.getEngaged() ).isEqualTo( "true" ); } - @Test + @ProcessorTest public void shouldMapBooleanPropertyWithPropertyMappingMethod() { // given Person person = new Person(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java index 95509dc0ce..5198394eb1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1005/Issue1005Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._1005; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1005") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ AbstractEntity.class, HasKey.class, @@ -29,7 +26,7 @@ public class Issue1005Test { @WithClasses(Issue1005ErroneousAbstractResultTypeMapper.class) - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Issue1005ErroneousAbstractResultTypeMapper.class, @@ -41,7 +38,7 @@ public void shouldFailDueToAbstractResultType() { } @WithClasses(Issue1005ErroneousAbstractReturnTypeMapper.class) - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Issue1005ErroneousAbstractReturnTypeMapper.class, @@ -54,7 +51,7 @@ public void shouldFailDueToAbstractReturnType() { } @WithClasses(Issue1005ErroneousInterfaceResultTypeMapper.class) - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Issue1005ErroneousInterfaceResultTypeMapper.class, @@ -66,7 +63,7 @@ public void shouldFailDueToInterfaceResultType() { } @WithClasses(Issue1005ErroneousInterfaceReturnTypeMapper.class) - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Issue1005ErroneousInterfaceReturnTypeMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java index 037ac64069..c2a87b769a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1029/Issue1029Test.java @@ -7,26 +7,23 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Verifies that read-only properties can be explicitly mentioned as {@code ignored=true} without raising an error. * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(ErroneousIssue1029Mapper.class) @IssueKey("1029") public class Issue1029Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(kind = Kind.WARNING, line = 26, type = ErroneousIssue1029Mapper.class, message = "Unmapped target properties: \"knownProp, lastUpdated, computedMapping\"."), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java index fe0f463c4e..b060d9727f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1061/Issue1061Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._1061; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1061") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(SourceTargetMapper.class) public class Issue1061Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java index 623be34f04..5619b64175 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java @@ -5,17 +5,16 @@ */ package org.mapstruct.ap.test.bugs._1111; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; + import org.mapstruct.ap.test.bugs._1111.Issue1111Mapper.Source; import org.mapstruct.ap.test.bugs._1111.Issue1111Mapper.Target; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -23,10 +22,9 @@ */ @IssueKey( "1111") @WithClasses({Issue1111Mapper.class}) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1111Test { - @Test + @ProcessorTest public void shouldCompile() { List> source = Arrays.asList( Arrays.asList( new Source() ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java index 1516c66496..aecc0a3a15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1124/Issue1124Test.java @@ -5,26 +5,23 @@ */ package org.mapstruct.ap.test.bugs._1124; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.DTO; import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.Entity; import org.mapstruct.ap.test.bugs._1124.Issue1124Mapper.MappingContext; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Andreas Gudian */ @IssueKey("1124") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(Issue1124Mapper.class) public class Issue1124Test { - @Test + @ProcessorTest public void nestedPropertyWithContextCompiles() { Entity entity = new Entity(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java index 2024a83933..d0f8a1d3a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Test.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.bugs._1130; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.TargetType; import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.ADto; import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.AEntity; import org.mapstruct.ap.test.bugs._1130.Issue1130Mapper.BEntity; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests that when calling an update method for a previously null property, the factory method is called even if that * factory method has a {@link TargetType} annotation. @@ -25,10 +23,9 @@ * @author Andreas Gudian */ @IssueKey("1130") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(Issue1130Mapper.class) public class Issue1130Test { - @Test + @ProcessorTest public void factoryMethodWithTargetTypeInUpdateMethods() { AEntity aEntity = new AEntity(); aEntity.setB( new BEntity() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java index 04cfa25d44..7a8c2797d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1131/Issue1131Test.java @@ -7,18 +7,15 @@ import java.util.ArrayList; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1131") @WithClasses({ Issue1131Mapper.class, @@ -28,7 +25,7 @@ }) public class Issue1131Test { - @Test + @ProcessorTest public void shouldUseCreateWithSourceNested() { Source source = new Source(); @@ -38,6 +35,7 @@ public void shouldUseCreateWithSourceNested() { Target target = new Target(); + Issue1131Mapper.CALLED_METHODS.clear(); Issue1131Mapper.INSTANCE.merge( source, target ); assertThat( target.getNested() ).isNotNull(); @@ -49,7 +47,7 @@ public void shouldUseCreateWithSourceNested() { ); } - @Test + @ProcessorTest public void shouldUseContextObjectFactory() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java index 1c6ff15e53..a698cfbfc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1148/Issue1148Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1148; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,11 +18,10 @@ Entity.class, Issue1148Mapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1148") public class Issue1148Test { - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsNestedSource() { Entity.Dto dto = new Entity.Dto(); dto.nestedDto = new Entity.NestedDto( 30 ); @@ -35,7 +32,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedSource() { assertThat( entity.getId2() ).isEqualTo( 40 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() { Entity.Dto dto = new Entity.Dto(); dto.recipientId = 10; @@ -51,7 +48,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedTarget() { assertThat( entity.getSender().nestedClient.id ).isEqualTo( 20 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsSymmetric() { Entity.Dto dto = new Entity.Dto(); dto.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); @@ -67,7 +64,7 @@ public void shouldNotUseSameMethodForDifferentMappingsSymmetric() { assertThat( entity.client2.nestedClient.id ).isEqualTo( 40 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() { Entity.Dto dto = new Entity.Dto(); dto.level = new Entity.ClientDto(new Entity.NestedDto( 80 )); @@ -81,7 +78,7 @@ public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetric() { assertThat( entity.nested2.id ).isEqualTo( 90 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.nestedDto = new Entity.NestedDto( 30 ); @@ -93,7 +90,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedSourceMultiple() { assertThat( entity.getId2() ).isEqualTo( 40 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.recipientId = 10; @@ -110,7 +107,7 @@ public void shouldNotUseSameMethodForDifferentMappingsNestedTargetMultiple() { assertThat( entity.getSender().nestedClient.id ).isEqualTo( 20 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsSymmetricMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.sameLevel = new Entity.ClientDto(new Entity.NestedDto( 30 )); @@ -127,7 +124,7 @@ public void shouldNotUseSameMethodForDifferentMappingsSymmetricMultiple() { assertThat( entity.client2.nestedClient.id ).isEqualTo( 40 ); } - @Test + @ProcessorTest public void shouldNotUseSameMethodForDifferentMappingsHalfSymmetricMultiple() { Entity.Dto dto1 = new Entity.Dto(); dto1.level = new Entity.ClientDto(new Entity.NestedDto( 80 )); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java index 015268b53e..5ceb1bb715 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1153/Issue1153Test.java @@ -5,19 +5,16 @@ */ package org.mapstruct.ap.test.bugs._1153; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(ErroneousIssue1153Mapper.class) @IssueKey("1153") public class Issue1153Test { @@ -40,7 +37,7 @@ public class Issue1153Test { message = "Unknown property \"writable2\" in type ErroneousIssue1153Mapper.Target.NestedTarget " + "for target name \"nestedTarget2.writable2\". Did you mean \"nestedTarget2.writable\"?") }) - @Test + @ProcessorTest public void shouldReportErrorsCorrectly() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java index 553323b32b..9a6bb40ed1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1155/Issue1155Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1155; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,11 +18,10 @@ Entity.class, Issue1155Mapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1155") public class Issue1155Test { - @Test + @ProcessorTest public void shouldCompile() { Entity.Dto dto = new Entity.Dto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java index b93cd6d069..7740662632 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1159/Issue1159Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1159; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; import static org.assertj.core.api.Assertions.assertThat; @@ -24,7 +21,6 @@ * @author Filip Hrisafov */ @IssueKey("1159") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1159Mapper.class, }) @@ -34,12 +30,8 @@ ) public class Issue1159Test { - @Test + @ProcessorTest(Compiler.JDK) // The warning is not present in the Eclipse compilation for some reason - @DisabledOnCompiler({ - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - }) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic( kind = javax.tools.Diagnostic.Kind.WARNING, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java index 7fa5a343ad..6db73113b6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1164/Issue1164Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1164; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -20,11 +18,10 @@ GenericHolder.class, SourceTargetMapper.class } ) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey( "1164" ) public class Issue1164Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java index b68884e0e3..88576ba711 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1170/AdderTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.bugs._1170; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import org.assertj.core.api.ListAssert; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._1170._target.Target; import org.mapstruct.ap.test.bugs._1170.source.Source; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Cornelius Dirmeier @@ -27,11 +25,10 @@ AdderSourceTargetMapper.class, PetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AdderTest { @IssueKey("1170") - @Test + @ProcessorTest public void testWildcardAdder() { Source source = new Source(); source.addWithoutWildcard( "mouse" ); @@ -51,7 +48,7 @@ public void testWildcardAdder() { } @IssueKey("1170") - @Test + @ProcessorTest public void testWildcardAdderTargetToSource() { Target target = new Target(); target.addWithoutWildcard( 2L ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java index 32de67728e..865816d83e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.bugs._1180; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen @@ -23,11 +21,10 @@ SharedConfig.class, ErroneousIssue1180Mapper.class } ) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey( "1180" ) public class Issue1180Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousIssue1180Mapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java index c18a858d47..e3c08488a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1215/Issue1215Test.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.bugs._1215; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._1215.dto.EntityDTO; import org.mapstruct.ap.test.bugs._1215.entity.AnotherTag; import org.mapstruct.ap.test.bugs._1215.entity.Entity; import org.mapstruct.ap.test.bugs._1215.entity.Tag; import org.mapstruct.ap.test.bugs._1215.mapper.Issue1215Mapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -27,10 +25,9 @@ Issue1215Mapper.class } ) @IssueKey( "1215" ) -@RunWith( AnnotationProcessorTestRunner.class ) public class Issue1215Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java index e4612e9d87..f98f6de398 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1227/Issue1227Test.java @@ -5,24 +5,21 @@ */ package org.mapstruct.ap.test.bugs._1227; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1227") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1227Mapper.class, ThreadDto.class }) public class Issue1227Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index c7e9c42f95..f27051670c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.bugs._1242; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests that if multiple factory methods are applicable but only one of them has a source parameter, the one with the * source param is chosen. @@ -24,7 +22,6 @@ * @author Andreas Gudian */ @IssueKey("1242") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1242Mapper.class, SourceA.class, @@ -34,7 +31,7 @@ TargetFactories.class }) public class Issue1242Test { - @Test + @ProcessorTest public void factoryMethodWithSourceParamIsChosen() { SourceA sourceA = new SourceA(); sourceA.setB( new SourceB() ); @@ -51,7 +48,7 @@ public void factoryMethodWithSourceParamIsChosen() { assertThat( targetA.getB().getPassedViaConstructor() ).isEqualTo( "created by factory" ); } - @Test + @ProcessorTest @WithClasses(ErroneousIssue1242MapperMultipleSources.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java index ebb27fc202..231ff67334 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1244/Issue1244Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1244; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; import static org.assertj.core.api.Assertions.assertThat; @@ -18,11 +16,10 @@ * @author Filip Hrisafov */ @IssueKey("1244") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( SizeMapper.class ) public class Issue1244Test { - @Test + @ProcessorTest public void properlyCreatesMapperWithSizeAsParameterName() { SizeMapper.SizeHolder sizeHolder = new SizeMapper.SizeHolder(); sizeHolder.setSize( "size" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java index 884fb7fdb2..1dd12d6e23 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1247/Issue1247Test.java @@ -8,11 +8,9 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,7 +18,6 @@ * @author Filip Hrisafov */ @IssueKey("1247") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1247Mapper.class, DtoIn.class, @@ -33,7 +30,7 @@ }) public class Issue1247Test { - @Test + @ProcessorTest public void shouldCorrectlyUseMappings() { DtoIn in = new DtoIn( "data", "data2" ); @@ -48,7 +45,7 @@ public void shouldCorrectlyUseMappings() { assertThat( out.getInternal().getInternalData().getList() ).containsExactly( "first", "second" ); } - @Test + @ProcessorTest public void shouldCorrectlyUseMappingsWithConstantsExpressionsAndDefaults() { DtoIn in = new DtoIn( "data", "data2" ); @@ -68,7 +65,7 @@ public void shouldCorrectlyUseMappingsWithConstantsExpressionsAndDefaults() { assertThat( out.getInternal().getInternalData().getDefaultValue() ).isEqualTo( "data2" ); } - @Test + @ProcessorTest public void shouldCorrectlyUseMappingsWithConstantsExpressionsAndUseDefault() { DtoIn in = new DtoIn( "data", null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java index 4168a75b79..9d27fdf681 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1255/Issue1255Test.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.bugs._1255; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * * @author Sjaak Derksen */ @IssueKey("1255") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ AbstractA.class, SomeA.class, @@ -26,7 +24,7 @@ SomeMapperConfig.class}) public class Issue1255Test { - @Test + @ProcessorTest public void shouldMapSomeBToSomeAWithoutField1() { SomeB someB = new SomeB(); someB.setField1( "value1" ); @@ -40,7 +38,7 @@ public void shouldMapSomeBToSomeAWithoutField1() { assertThat( someA.getField2() ).isEqualTo( someB.getField2() ); } - @Test + @ProcessorTest public void shouldMapSomeAToSomeB() { SomeA someA = new SomeA(); someA.setField1( "value1" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java index 7f44ea012b..668b9e5110 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1269/Issue1269Test.java @@ -8,8 +8,6 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._1269.dto.VehicleDto; import org.mapstruct.ap.test.bugs._1269.dto.VehicleImageDto; import org.mapstruct.ap.test.bugs._1269.dto.VehicleInfoDto; @@ -18,8 +16,8 @@ import org.mapstruct.ap.test.bugs._1269.model.VehicleImage; import org.mapstruct.ap.test.bugs._1269.model.VehicleTypeInfo; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +25,6 @@ * @author Filip Hrisafov */ @IssueKey( "1269" ) -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { VehicleDto.class, VehicleImageDto.class, @@ -39,7 +36,7 @@ } ) public class Issue1269Test { - @Test + @ProcessorTest public void shouldMapNestedPropertiesCorrectly() { VehicleTypeInfo sourceTypeInfo = new VehicleTypeInfo( "Opel", "Corsa", 3 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java index e12edd50a2..9874b33436 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1273/Issue1273Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._1273; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + @IssueKey( "1273" ) -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { EntityMapperReturnDefault.class, EntityMapperReturnNull.class, Dto.class, Entity.class } ) public class Issue1273Test { - @Test + @ProcessorTest public void shouldCorrectlyMapCollectionWithNullValueMappingStrategyReturnDefault() { EntityMapperReturnDefault entityMapper = Mappers.getMapper( EntityMapperReturnDefault.class ); @@ -29,7 +26,7 @@ public void shouldCorrectlyMapCollectionWithNullValueMappingStrategyReturnDefaul assertThat( dto.getLongs() ).isNotNull(); } - @Test + @ProcessorTest public void shouldCorrectlyMapCollectionWithNullValueMappingStrategyReturnNull() { EntityMapperReturnNull entityMapper = Mappers.getMapper( EntityMapperReturnNull.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java index 0d4fef255a..1879c9398b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1283/Issue1283Test.java @@ -5,27 +5,24 @@ */ package org.mapstruct.ap.test.bugs._1283; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1283") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Source.class, Target.class }) public class Issue1283Test { - @Test + @ProcessorTest @WithClasses(ErroneousInverseTargetHasNoSuitableConstructorMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -40,7 +37,7 @@ public class Issue1283Test { public void inheritInverseConfigurationReturnTypeHasNoSuitableConstructor() { } - @Test + @ProcessorTest @WithClasses(ErroneousTargetHasNoSuitableConstructorMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java index 2b6b918bb3..b84fe2d8e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1320/Issue1320Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1320; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,14 +15,13 @@ * @author Filip Hrisafov */ @IssueKey("1320") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1320Mapper.class, Target.class }) public class Issue1320Test { - @Test + @ProcessorTest public void shouldCreateDeepNestedConstantsCorrectly() { Target target = Issue1320Mapper.INSTANCE.map( 10 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java index 83c5212d23..924f5e8c86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1338/Issue1338Test.java @@ -7,18 +7,15 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1338") @WithClasses({ Issue1338Mapper.class, @@ -27,7 +24,7 @@ }) public class Issue1338Test { - @Test + @ProcessorTest public void shouldCorrectlyUseAdder() { Source source = new Source(); source.setProperties( Arrays.asList( "first", "second" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java index 5846860098..fa1caff745 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1339/Issue1339Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1339; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,11 +18,10 @@ Issue1339Mapper.class, Callback.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1339") public class Issue1339Test { - @Test + @ProcessorTest public void shouldCompile() { Issue1339Mapper.Source source = new Issue1339Mapper.Source(); source.field = "test"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java index d4fdac257d..3135dfff67 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1340/Issue1340Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1340; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -18,10 +16,9 @@ Issue1340Mapper.class }) @IssueKey("1340") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1340Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java index c5ad1c3030..7be9b0edc1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1345; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen @@ -18,10 +16,9 @@ Issue1345Mapper.class }) @IssueKey("1345") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1345Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java index 953ecf8d17..4398d6ebcd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1353/Issue1353Test.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.bugs._1353; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,7 +18,6 @@ * @author Jeffrey Smyth */ @IssueKey ("1353") -@RunWith (AnnotationProcessorTestRunner.class) @WithClasses ({ Issue1353Mapper.class, Source.class, @@ -28,7 +25,7 @@ }) public class Issue1353Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome ( value = CompilationResult.SUCCEEDED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java index aa49cc59fe..a412cd19f6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1359/Issue1359Test.java @@ -8,11 +8,9 @@ import java.util.HashSet; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.InstanceOfAssertFactories.ITERABLE; @@ -25,11 +23,10 @@ Source.class, Target.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "1359" ) public class Issue1359Test { - @Test + @ProcessorTest public void shouldCompile() { Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java index d08d8d3d36..9dcb9655f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1375/Issue1375Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1375; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,11 +19,10 @@ Source.class, Issue1375Mapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "1375" ) public class Issue1375Test { - @Test + @ProcessorTest public void shouldGenerateCorrectMapperWhenIntermediaryReadAccessorIsMissing() { Target target = Issue1375Mapper.INSTANCE.map( new Source( "test value" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java index 21d2f5015b..757436a0f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1395; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -20,11 +18,10 @@ Source.class, Target.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "1395" ) public class Issue1395Test { - @Test + @ProcessorTest public void shouldGenerateValidCode() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java index 25a148e474..8c5700772f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java @@ -6,11 +6,9 @@ package org.mapstruct.ap.test.bugs._1425; import org.joda.time.LocalDate; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -22,11 +20,10 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1425") public class Issue1425Test { - @Test + @ProcessorTest public void shouldTestMappingLocalDates() { Source source = new Source(); source.setValue( LocalDate.parse( "2018-04-18" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java index ade951f2b1..2fa173cac1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1435/Issue1435Test.java @@ -5,15 +5,12 @@ */ package org.mapstruct.ap.test.bugs._1435; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1435") @WithClasses({ Config.class, @@ -22,7 +19,7 @@ OutObject.class, }) public class Issue1435Test { - @Test + @ProcessorTest public void mustNotSetListToNull() { InObject source = new InObject( "Rainbow Dash" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java index 9ba0a41cf3..d112df0355 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1453/Issue1453Test.java @@ -7,12 +7,10 @@ import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -21,7 +19,6 @@ * @author Filip Hrisafov */ @IssueKey("1453") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Auction.class, AuctionDto.class, @@ -31,10 +28,10 @@ }) public class Issue1453Test { - @Rule - public GeneratedSource source = new GeneratedSource().addComparisonToFixtureFor( Issue1453Mapper.class ); + @RegisterExtension + final GeneratedSource source = new GeneratedSource().addComparisonToFixtureFor( Issue1453Mapper.class ); - @Test + @ProcessorTest public void shouldGenerateCorrectCode() { AuctionDto target = Issue1453Mapper.INSTANCE.map( new Auction( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java index 910a1e7280..de1160771a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1457/Issue1457Test.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.bugs._1457; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,7 +19,6 @@ SourceBook.class, TargetBook.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1457") public class Issue1457Test { @@ -29,7 +26,7 @@ public class Issue1457Test { private String authorFirstName; private String authorLastName; - @Before + @BeforeEach public void setup() { sourceBook = new SourceBook(); sourceBook.setIsbn( "3453146972" ); @@ -39,7 +36,7 @@ public void setup() { authorLastName = "Adams"; } - @Test + @ProcessorTest @WithClasses({ BookMapper.class }) @@ -67,7 +64,7 @@ public void testMapperWithMatchingParameterNames() { assertThat( targetBook.isAfterMappingWithDifferentVariableName() ).isFalse(); } - @Test + @ProcessorTest @WithClasses({ DifferentOrderingBookMapper.class }) @@ -81,7 +78,7 @@ public void testMapperWithMatchingParameterNamesAndDifferentOrdering() { assertTargetBookMatchesSourceBook( targetBook ); } - @Test + @ProcessorTest @WithClasses({ ObjectFactoryBookMapper.class }) @@ -102,7 +99,7 @@ private void assertTargetBookMatchesSourceBook(TargetBook targetBook) { assertThat( authorLastName ).isEqualTo( targetBook.getAuthorLastName() ); } - @Test + @ProcessorTest @WithClasses({ ErroneousBookMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java index b436899147..077e66df76 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java @@ -9,11 +9,9 @@ import java.util.Locale; import org.joda.time.DateTime; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -25,11 +23,10 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1460") public class Issue1460Test { - @Test + @ProcessorTest public void shouldTestMappingLocalDates() { long dateInMs = 1524693600000L; String dateAsString = "2018-04-26"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java index ff3ea2d1c7..829402efaa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeTest.java @@ -7,11 +7,9 @@ import java.time.LocalDate; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,11 +21,10 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1460") public class Issue1460JavaTimeTest { - @Test + @ProcessorTest public void shouldTestMappingLocalDates() { String dateAsString = "2018-04-26"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java index 4b77eb2c34..d59b58dbda 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1482/Issue1482Test.java @@ -7,11 +7,9 @@ import java.math.BigDecimal; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -24,10 +22,9 @@ ValueWrapper.class }) @IssueKey(value = "1482") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1482Test { - @Test + @ProcessorTest @WithClasses( SourceTargetMapper.class ) public void testForward() { @@ -43,7 +40,7 @@ public void testForward() { } - @Test + @ProcessorTest @WithClasses( TargetSourceMapper.class ) public void testReverse() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java index d1f859db6f..f528432c18 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java @@ -9,13 +9,11 @@ import java.util.Calendar; import java.util.TimeZone; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -32,13 +30,12 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1523") public class Issue1523Test { private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getDefault(); - @BeforeClass + @BeforeAll public static void before() { // we want to test that the timezone will correctly be used in mapped XMLGregorianCalendar and not the // default one, so we must ensure that we use a different timezone than the default one -> set the default @@ -46,13 +43,13 @@ public static void before() { TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); } - @AfterClass + @AfterAll public static void after() { // revert the changed default TZ TimeZone.setDefault( DEFAULT_TIMEZONE ); } - @Test + @ProcessorTest public void testThatCorrectTimeZoneWillBeUsedInTarget() { Source source = new Source(); // default one was explicitly set to UTC, thus +01:00 is a different one diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java index 92a7f99ca7..01f7ed92a9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1541/Issue1541Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1541; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,11 +19,10 @@ Issue1541Mapper.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1541") public class Issue1541Test { - @Test + @ProcessorTest public void testMappingWithVarArgs() { Target target = Issue1541Mapper.INSTANCE.mapWithVarArgs( "code", "1", "2" ); @@ -38,7 +35,7 @@ public void testMappingWithVarArgs() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testMappingWithArray() { Target target = Issue1541Mapper.INSTANCE.mapWithArray( "code", new String[] { "1", "2" } ); @@ -52,7 +49,7 @@ public void testMappingWithArray() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testMappingWithVarArgsReassignment() { Target target = Issue1541Mapper.INSTANCE.mapWithReassigningVarArgs( "code", "1", "2" ); @@ -66,7 +63,7 @@ public void testMappingWithVarArgsReassignment() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testMappingWithArrayAndVarArgs() { Target target = Issue1541Mapper.INSTANCE.mapWithArrayAndVarArgs( "code", new String[] { "1", "2" }, "3", "4" ); @@ -80,7 +77,7 @@ public void testMappingWithArrayAndVarArgs() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testVarArgsInAfterMappingAsArray() { Target target = Issue1541Mapper.INSTANCE.mapParametersAsArrayInAfterMapping( "code", "1", "2" ); @@ -94,7 +91,7 @@ public void testVarArgsInAfterMappingAsArray() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testVarArgsInAfterMappingAsVarArgs() { Target target = Issue1541Mapper.INSTANCE.mapParametersAsVarArgsInAfterMapping( "code", "1", "2" ); @@ -108,7 +105,7 @@ public void testVarArgsInAfterMappingAsVarArgs() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testVarArgsInContextWithVarArgsAfterMapping() { Target target = Issue1541Mapper.INSTANCE.mapContextWithVarArgsInAfterMappingWithVarArgs( "code", @@ -127,7 +124,7 @@ public void testVarArgsInContextWithVarArgsAfterMapping() { assertThat( target.isAfterMappingContextWithVarArgsAsArrayCalled() ).isFalse(); } - @Test + @ProcessorTest public void testVarArgsInContextWithArrayAfterMapping() { Target target = Issue1541Mapper.INSTANCE.mapContextWithVarArgsInAfterMappingWithArray( "code", diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java index c06a00bb05..2dcaf182c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1552/Issue1552Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1552; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,11 +18,10 @@ Issue1552Mapper.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1552") public class Issue1552Test { - @Test + @ProcessorTest public void shouldCompile() { Target target = Issue1552Mapper.INSTANCE.twoArgsWithConstant( "first", "second" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java index 9840716429..38bafc1101 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1558/java8/Issue1558Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1558.java8; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen @@ -20,11 +18,10 @@ Car.class, Car2.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1558") public class Issue1558Test { - @Test + @ProcessorTest public void testShouldCompile() { Car2 car = new Car2(); Car target = CarMapper.INSTANCE.toCar( car ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java index 4b8e5704ee..3e17e1c605 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1561/Issue1561Test.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.bugs._1561; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -18,7 +16,6 @@ /** * @author Sebastian Haberey */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1561") @WithClasses({ Issue1561Mapper.class, @@ -28,12 +25,12 @@ }) public class Issue1561Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( Issue1561Mapper.class ); - @Test + @ProcessorTest public void shouldCorrectlyUseAdder() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java index 667f90d1ca..5de2af6ab3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1566/Issue1566Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1566; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +21,9 @@ Target.class }) @IssueKey("1566") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1566Test { - @Test + @ProcessorTest public void genericMapperIsCorrectlyUsed() { Source source = new Source(); source.setId( "id-123" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java index 079e792705..1bc7f4ca8d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1569/java8/Issue1569Test.java @@ -10,11 +10,9 @@ import java.time.ZoneOffset; import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -26,11 +24,10 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1569") public class Issue1569Test { - @Test + @ProcessorTest public void shouldGenerateCorrectMapping() { Source source = new Source(); Date date = Date.from( LocalDate.of( 2018, Month.AUGUST, 5 ).atTime( 20, 30 ).toInstant( ZoneOffset.UTC ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java index 4b367a15a9..36f10eb5ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1576/java8/Issue1576Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._1576.java8; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; @IssueKey("1576") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { Issue1576Mapper.class, Source.class, Target.class }) public class Issue1576Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( Issue1576Mapper.class ); - @Test + @ProcessorTest public void testLocalDateTimeIsImported() { Issue1576Mapper.INSTANCE.map( new Source() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java index 30613d1a27..d77add25de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java @@ -7,11 +7,9 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -24,11 +22,10 @@ Book.class, BookShelf.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1590") public class Issue1590Test { - @Test + @ProcessorTest public void shouldTestMappingLocalDates() { BookShelf source = new BookShelf(); source.setBooks( Arrays.asList( new Book() ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java index b498884b29..0c1fed523e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1594/Issue1594Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._1594; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1594") @WithClasses({ Issue1594Mapper.class }) public class Issue1594Test { - @Test + @ProcessorTest public void shouldGenerateCorrectMapping() { Issue1594Mapper.Dto dto = new Issue1594Mapper.Dto(); dto.setFullAddress( "Switzerland-Zurich" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java index 0d75feea03..96286aa1a1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1596/Issue1596Test.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.bugs._1596; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; @@ -15,10 +13,10 @@ import org.mapstruct.ap.test.bugs._1596.dto.ImmutableItemDTO; import org.mapstruct.ap.test.bugs._1596.dto.ItemDTO; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithServiceImplementations; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +30,6 @@ ItemDTO.class, ImmutableItemDTO.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1596") @WithServiceImplementations( { @WithServiceImplementation( provides = BuilderProvider.class, value = Issue1569BuilderProvider.class), @@ -40,7 +37,7 @@ }) public class Issue1596Test { - @Test + @ProcessorTest public void shouldIncludeBuildType() { ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java index 44abfd69fa..528bc9b91b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1608/Issue1608Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1608; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1608") @WithClasses({ Issue1608Mapper.class, @@ -25,7 +22,7 @@ }) public class Issue1608Test { - @Test + @ProcessorTest public void shouldCorrectlyUseFluentSettersStartingWithIs() { Book book = new Book(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java index 03ba02d4b0..5dfe65d77e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1648/Issue1648Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1648; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("1648") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1648Mapper.class, Source.class, @@ -25,7 +22,7 @@ }) public class Issue1648Test { - @Test + @ProcessorTest public void shouldCorrectlyMarkSourceAsUsed() { Source source = new Source(); source.setSourceValue( "value" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java index 9dd6f2dba6..2d1437eb77 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java @@ -5,16 +5,13 @@ */ package org.mapstruct.ap.test.bugs._1650; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("1650") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ AMapper.class, A.class, @@ -25,7 +22,7 @@ }) public class Issue1650Test { - @Test + @ProcessorTest public void shouldCompile() { A a = new A(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java index 838f705c20..7de37e6b43 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1660/Issue1660Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1660; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1660") @WithClasses({ Issue1660Mapper.class, @@ -25,7 +22,7 @@ }) public class Issue1660Test { - @Test + @ProcessorTest public void shouldNotUseStaticMethods() { Source source = new Source(); source.setValue( "source" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java index 4690d5d5a2..169e01029a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1665/Issue1665Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._1665; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.List; + import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -import java.util.ArrayList; -import java.util.List; - /** * @author Arne Seime */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1665") @WithClasses({ Issue1665Mapper.class, @@ -28,7 +25,7 @@ }) public class Issue1665Test { - @Test + @ProcessorTest public void shouldBoxIntPrimitive() { Source source = new Source(); List values = new ArrayList<>(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java index 812400be04..901794dea0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1681/Issue1681Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1681; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1681") @WithClasses({ Issue1681Mapper.class, @@ -25,7 +22,7 @@ }) public class Issue1681Test { - @Test + @ProcessorTest public void shouldCompile() { Target target = new Target( "before" ); Source source = new Source(); @@ -37,7 +34,7 @@ public void shouldCompile() { assertThat( updatedTarget.getValue() ).isEqualTo( "after" ); } - @Test + @ProcessorTest public void shouldCompileWithBuilder() { Target.Builder targetBuilder = Target.builder(); targetBuilder.builderValue( "before" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java index 5bff62f4c5..eccef6df2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1685/Issue1685Test.java @@ -5,17 +5,14 @@ */ package org.mapstruct.ap.test.bugs._1685; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1685") @WithClasses({ User.class, @@ -25,12 +22,12 @@ }) public class Issue1685Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( UserMapper.class ); - @Test + @ProcessorTest public void testSetToNullWhenNVPMSSetToNull() { User target = new User(); @@ -58,7 +55,7 @@ public void testSetToNullWhenNVPMSSetToNull() { assertThat( target.getSettings() ).isNull(); } - @Test + @ProcessorTest public void testIgnoreWhenNVPMSIgnore() { User target = new User(); @@ -86,7 +83,7 @@ public void testIgnoreWhenNVPMSIgnore() { assertThat( target.getSettings() ).containsExactly( "test" ); } - @Test + @ProcessorTest public void testSetToDefaultWhenNVPMSSetToDefault() { User target = new User(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java index a7a3b58e75..c5af6d923f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1698/Issue1698Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._1698; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1698") @WithClasses(Erroneous1698Mapper.class) public class Issue1698Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Erroneous1698Mapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java index 5d2083312b..9798ea1bb6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1707/Issue1707Test.java @@ -5,27 +5,24 @@ */ package org.mapstruct.ap.test.bugs._1707; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1707") @WithClasses({ Converter.class }) public class Issue1707Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( Converter.class ); - @Test + @ProcessorTest public void codeShouldBeGeneratedCorrectly() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java index 88a7848c84..4a2e42ad61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1714/Issue1714Test.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.bugs._1714; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1714") @WithClasses({ Issue1714Mapper.class }) public class Issue1714Test { - @Test + @ProcessorTest public void codeShouldBeGeneratedCorrectly() { Issue1714Mapper.OnDemand source = new Issue1714Mapper.OnDemand(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java index e34c790322..182e1849be 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java @@ -5,16 +5,13 @@ */ package org.mapstruct.ap.test.bugs._1719; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1719") @WithClasses({ Source.class, @@ -29,7 +26,7 @@ public class Issue1719Test { * from the child-parent relation. It cannot even assume that the the collection can be cleared at forehand. * Therefore the only sensible choice is for MapStruct to create a create method for the target elements. */ - @Test + @ProcessorTest @WithClasses(Issue1719Mapper.class) public void testShouldGiveNoErrorMessage() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java index b9d28ff27b..e0755312fa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1738/Issue1738Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1738; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1738") @WithClasses({ Issue1738Mapper.class, @@ -25,7 +22,7 @@ }) public class Issue1738Test { - @Test + @ProcessorTest public void shouldGenerateCorrectSourceNestedMapping() { Source source = new Source(); Source.Nested nested = new Source.Nested<>(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1742/Issue1742Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1742/Issue1742Test.java index e68f4657ff..6c64e0c261 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1742/Issue1742Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1742/Issue1742Test.java @@ -5,17 +5,14 @@ */ package org.mapstruct.ap.test.bugs._1742; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1742") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { Issue1742Mapper.class, NestedSource.class, @@ -25,7 +22,7 @@ } ) public class Issue1742Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java index 5061ba598f..e35424761a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1751/Issue1751Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1751; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("1772") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Holder.class, Issue1751Mapper.class, @@ -26,7 +23,7 @@ }) public class Issue1751Test { - @Test + @ProcessorTest public void name() { Source source = new Source(); source.setValue( "some value" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java index b77eb34ec0..e05938e2f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1772/Issue1772Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1772; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Sjaak Derksen */ @IssueKey("1772") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1772Mapper.class, Source.class, @@ -25,7 +22,7 @@ }) public class Issue1772Test { - @Test + @ProcessorTest public void shouldCorrectlyMarkSourceAsUsed() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1788/Issue1788Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1788/Issue1788Test.java index d9bf1c256c..bd5d687ae0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1788/Issue1788Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1788/Issue1788Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._1788; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey( "1788" ) -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( Issue1788Mapper.class ) public class Issue1788Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java index 8ea3c4c026..c92d240cbf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1790/Issue1790Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1790; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("1790") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1790Config.class, Issue1790Mapper.class, @@ -26,7 +23,7 @@ }) public class Issue1790Test { - @Test + @ProcessorTest public void shouldProperlyApplyNullValuePropertyMappingStrategyWhenInheriting() { Target target = new Target(); target.setName( "My name is set" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java index ecb531721d..bd9fcb92e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1797/Issue1797Test.java @@ -7,11 +7,9 @@ import java.util.EnumSet; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -19,7 +17,6 @@ * @author Filip Hrisafov */ @IssueKey("1797") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Customer.class, CustomerDto.class, @@ -27,7 +24,7 @@ }) public class Issue1797Test { - @Test + @ProcessorTest public void shouldCorrectlyMapEnumSetToEnumSet() { Customer customer = new Customer( EnumSet.of( Customer.Type.ONE ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java index 742c72f717..b3234cbcfc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1799/Issue1799Test.java @@ -7,11 +7,9 @@ import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -24,10 +22,9 @@ Target.class, }) @IssueKey("1799") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue1799Test { - @Test + @ProcessorTest public void fluentJavaBeanStyleSettersShouldWork() { Target target = Issue1799Mapper.INSTANCE.map( new Source( new Date( 150 ), "Switzerland" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java index e407c331f3..ee6076f823 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.bugs._1801; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; @@ -15,10 +13,10 @@ import org.mapstruct.ap.test.bugs._1801.dto.ImmutableItemDTO; import org.mapstruct.ap.test.bugs._1801.dto.ItemDTO; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithServiceImplementations; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -32,7 +30,6 @@ ItemDTO.class, ImmutableItemDTO.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1801") @WithServiceImplementations( { @WithServiceImplementation( provides = BuilderProvider.class, value = Issue1801BuilderProvider.class), @@ -40,7 +37,7 @@ }) public class Issue1801Test { - @Test + @ProcessorTest public void shouldIncludeBuildeType() { ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java index aa309e7fce..4481ed43e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._1821; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("1797") -@RunWith( AnnotationProcessorTestRunner.class) @WithClasses( Issue1821Mapper.class ) public class Issue1821Test { - @Test + @ProcessorTest public void shouldNotGiveNullPtr() { Issue1821Mapper.INSTANCE.map( new Issue1821Mapper.Source() ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java index 66f6cb14f3..be22569e5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1826/Issue1826Test.java @@ -5,15 +5,12 @@ */ package org.mapstruct.ap.test.bugs._1826; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1826") @WithClasses({ SourceParent.class, @@ -23,7 +20,7 @@ }) public class Issue1826Test { - @Test + @ProcessorTest public void testNestedPropertyMappingChecksForNull() { SourceParent sourceParent = new SourceParent(); sourceParent.setSourceChild( null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Issue1828Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Issue1828Test.java index 0d99cf9036..a3aa5b3581 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Issue1828Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1828/Issue1828Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1828; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("1828") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CompleteAddress.class, Employee.class, @@ -28,7 +25,7 @@ }) public class Issue1828Test { - @Test + @ProcessorTest public void testMapSpecialAndGeneralAddressSet() { Employee employee = new Employee(); @@ -55,7 +52,7 @@ public void testMapSpecialAndGeneralAddressSet() { assertThat( completeAddress.getCountry() ).isEqualTo( "Seven Kingdom" ); } - @Test + @ProcessorTest public void testMapGeneralAddressNull() { Employee employee = new Employee(); @@ -77,7 +74,7 @@ public void testMapGeneralAddressNull() { assertThat( completeAddress.getCountry() ).isNull(); } - @Test + @ProcessorTest public void testMapSpecialAddressNull() { Employee employee = new Employee(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/Issue1881Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/Issue1881Test.java index 6e947a1066..21bab07e52 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/Issue1881Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1881/Issue1881Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1881; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Filip Hrisafov */ @IssueKey("1881") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ VehicleDtoMapper.class, }) public class Issue1881Test { - @Test + @ProcessorTest public void shouldCompileCorrectly() { VehicleDtoMapper.VehicleDto vehicle = VehicleDtoMapper.INSTANCE.map( new VehicleDtoMapper.Vehicle( "Test", diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java index b6e0b03cf7..b369765433 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1904/Issue1904Test.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.bugs._1904; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("1904") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1904Mapper.class, }) @@ -30,7 +27,7 @@ ) public class Issue1904Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic( type = Issue1904Mapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1933/Issue1933Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1933/Issue1933Test.java index ae4ecb2e88..5d1ca351f9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1933/Issue1933Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1933/Issue1933Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1933; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,14 +15,13 @@ * @author Sjaak Derksen */ @IssueKey("1933") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1933Config.class, Issue1933Mapper.class }) public class Issue1933Test { - @Test + @ProcessorTest public void shouldIgnoreIdAndMapUpdateCount() { Issue1933Config.Dto dto = new Issue1933Config.Dto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1966/Issue1966Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1966/Issue1966Test.java index 9ad37958d0..528f45594a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1966/Issue1966Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1966/Issue1966Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._1966; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Sjaak Derksen */ @IssueKey("1966") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue1966Mapper.class }) public class Issue1966Test { - @Test + @ProcessorTest public void shouldSelectDefaultExpressionEvenWhenSourceInMappingIsNotSpecified() { Issue1966Mapper.AnimalRecord dto = new Issue1966Mapper.AnimalRecord(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2001/Issue2001Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2001/Issue2001Test.java index 7cb89f79e9..52525e9e9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2001/Issue2001Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2001/Issue2001Test.java @@ -5,17 +5,14 @@ */ package org.mapstruct.ap.test.bugs._2001; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2001") -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { Entity.class, EntityExtra.class, @@ -25,7 +22,7 @@ } ) public class Issue2001Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java index 21893e0676..68719b9ff0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2018/Issue2018Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2018; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2018") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2018Mapper.class, Source.class, @@ -25,7 +22,7 @@ }) public class Issue2018Test { - @Test + @ProcessorTest public void shouldGenerateCorrectCode() { Source source = new Source(); source.setSomeValue( "value" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java index f111799d53..bb6ef326b6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2021/Issue2021Test.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.bugs._2021; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2021") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2021Mapper.class }) public class Issue2021Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java index ffc3df5e07..99c97d9eb5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2023/Issue2023Test.java @@ -7,11 +7,9 @@ import java.util.UUID; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -19,7 +17,6 @@ * @author Filip Hrisafov */ @IssueKey("2023") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2023Mapper.class, NewPersonRequest.class, @@ -27,7 +24,7 @@ }) public class Issue2023Test { - @Test + @ProcessorTest public void shouldUseDefaultExpressionCorrectly() { PersonDto person = new PersonDto(); person.setName( "John" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java index 26e585c23d..9d1d18dac6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2042/Issue2402Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2042; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Filip Hrisafov */ @IssueKey("2402") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2402Mapper.class }) public class Issue2402Test { - @Test + @ProcessorTest public void shouldCompile() { Issue2402Mapper.Target target = Issue2402Mapper.INSTANCE. map( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java index 332c3034dc..607c1137f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2077/Issue2077Test.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.bugs._2077; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static javax.tools.Diagnostic.Kind.ERROR; @@ -20,10 +18,9 @@ * @author Sjaak Derksen */ @IssueKey("2077") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2077Test { - @Test + @ProcessorTest @WithClasses(Issue2077ErroneousMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java index 9148184b25..96c3f31b12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2101/Issue2101Test.java @@ -5,19 +5,16 @@ */ package org.mapstruct.ap.test.bugs._2101; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2101") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2101Test { - @Test + @ProcessorTest @WithClasses(Issue2101Mapper.class) public void shouldMap() { @@ -34,7 +31,7 @@ public void shouldMap() { } - @Test + @ProcessorTest @WithClasses(Issue2101AdditionalMapper.class) public void shouldMapSomeAdditionalTests1() { Issue2101AdditionalMapper.Source source = new Issue2101AdditionalMapper.Source(); @@ -49,7 +46,7 @@ public void shouldMapSomeAdditionalTests1() { assertThat( target.value3 ).isEqualTo( "value3" ); } - @Test + @ProcessorTest @WithClasses(Issue2101AdditionalMapper.class) public void shouldMapSomeAdditionalTests2() { Issue2101AdditionalMapper.Source source = new Issue2101AdditionalMapper.Source(); @@ -65,7 +62,7 @@ public void shouldMapSomeAdditionalTests2() { } - @Test + @ProcessorTest @WithClasses(Issue2102IgnoreAllButMapper.class) public void shouldApplyIgnoreAllButTemplateOfMethod1() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java index 6ee44acb97..bc1deed110 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2109/Issue2109Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2109; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2109") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2109Mapper.class, Source.class, @@ -25,7 +22,7 @@ }) public class Issue2109Test { - @Test + @ProcessorTest public void shouldCorrectlyMapArrayInConstructorMapping() { Target target = Issue2109Mapper.INSTANCE.map( new Source( 100L, new byte[] { 100, 120, 40, 40 } ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java index 0d6b9ef771..a3006ceb9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2111/Issue2111Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._2111; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen */ @IssueKey("2111") -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( Issue2111Mapper.class ) public class Issue2111Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java index fd51fd9384..984aa2daa9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2117/Issue2117Test.java @@ -7,11 +7,9 @@ import java.nio.file.AccessMode; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -19,13 +17,12 @@ * @author Filip Hrisafov */ @IssueKey("2117") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2117Mapper.class }) public class Issue2117Test { - @Test + @ProcessorTest public void shouldCompile() { Issue2117Mapper.Target target = Issue2117Mapper.INSTANCE.toTarget( AccessMode.READ, null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java index 3d6f6dfca1..24bb88450b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2121/Issue2121Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2121; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,11 +15,10 @@ * @author Filip Hrisafov */ @IssueKey("2121") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(Issue2121Mapper.class) public class Issue2121Test { - @Test + @ProcessorTest public void shouldCompile() { Issue2121Mapper mapper = Issue2121Mapper.INSTANCE; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java index 0d42a8f125..f0a82d8f0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2122/Issue2122Test.java @@ -7,11 +7,9 @@ import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -19,11 +17,9 @@ * @author Christian Bandowski */ @IssueKey("2122") -@RunWith(AnnotationProcessorTestRunner.class) - public class Issue2122Test { - @Test + @ProcessorTest @WithClasses( Issue2122Method2MethodMapper.class ) public void shouldMapMethod2Method() { Issue2122Method2MethodMapper.Source source = new Issue2122Method2MethodMapper.Source(); @@ -47,7 +43,7 @@ public void shouldMapMethod2Method() { .extracting( Issue2122Method2MethodMapper.EmbeddedTarget::getValue ).isEqualTo( "value" ); } - @Test + @ProcessorTest @WithClasses( Issue2122TypeConversion2MethodMapper.class ) public void shouldMapTypeConversion2Method() { Issue2122TypeConversion2MethodMapper.Source source = new Issue2122TypeConversion2MethodMapper.Source(); @@ -63,7 +59,7 @@ public void shouldMapTypeConversion2Method() { .isEqualTo( "5" ); } - @Test + @ProcessorTest @WithClasses( Issue2122Method2TypeConversionMapper.class ) public void shouldMapMethod2TypeConversion() { Issue2122Method2TypeConversionMapper.Source source = new Issue2122Method2TypeConversionMapper.Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java index 5671c78877..f2f9873fdb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2124/Issue2124Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2124; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,14 +15,13 @@ * @author Filip Hrisafov */ @IssueKey("2124") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CommitComment.class, Issue2124Mapper.class }) public class Issue2124Test { - @Test + @ProcessorTest public void shouldCompile() { CommitComment clone = Issue2124Mapper.INSTANCE.clone( new CommitComment( 100 ), null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java index e98afe7d52..69a564edf0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2125/Issue2125Test.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.bugs._2125; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +19,9 @@ Comment.class, Repository.class, }) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2125Test { - @Test + @ProcessorTest @WithClasses({ Issue2125Mapper.class }) @@ -55,7 +52,7 @@ public void shouldSelectProperMethod() { assertThat( comment.getIssueId() ).isEqualTo( 1001 ); } - @Test + @ProcessorTest @WithClasses({ Issue2125ErroneousMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java index 80cde5c5bf..6f7a3ec8a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2131/Issue2131Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2131; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,11 +15,10 @@ * @author Filip Hrisafov */ @IssueKey("2131") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(Issue2131Mapper.class) public class Issue2131Test { - @Test + @ProcessorTest public void shouldCompile() { Issue2131Mapper mapper = Issue2131Mapper.INSTANCE; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java index 8a8e8eebbe..5f78b3fdde 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2133/Issue2133Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._2133; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("2133") @WithClasses( Issue2133Mapper.class ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2133Test { - @Test + @ProcessorTest public void shouldCompile() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java index 8cfff232e5..287c39c175 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2142/Issue2142Test.java @@ -5,26 +5,23 @@ */ package org.mapstruct.ap.test.bugs._2142; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2142") @WithClasses(Issue2142Mapper.class) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2142Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( Issue2142Mapper.class ); - @Test + @ProcessorTest public void underscorePrefixShouldBeStrippedFromGeneratedLocalVariables() { Issue2142Mapper._Target target = Issue2142Mapper.INSTANCE.map( new Issue2142Mapper.Source( "value1" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java index 02ad2ba901..ec8bb4603c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._2145; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2145") @WithClasses(Issue2145Mapper.class) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2145Test { - @Test + @ProcessorTest public void test() { Issue2145Mapper.Source source = new Issue2145Mapper.Source(); source.setValue( "test" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java index 80cfbcc7db..8c19e2e090 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java @@ -5,26 +5,23 @@ */ package org.mapstruct.ap.test.bugs._2149; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2149") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Erroneous2149Mapper.class }) public class Issue2149Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java index 3ed5cf1654..5f7dc7f57f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2164/Issue2164Test.java @@ -7,20 +7,17 @@ import java.math.BigDecimal; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2164") @WithClasses(Issue2164Mapper.class) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2164Test { - @Test + @ProcessorTest public void shouldSelectProperMethod() { Issue2164Mapper.Target target = Issue2164Mapper.INSTANCE.map( new BigDecimal( "1234" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java index 779cc7fd03..b5c10d120a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2170/Issue2170Test.java @@ -7,8 +7,6 @@ import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._2170.dto.AddressDto; import org.mapstruct.ap.test.bugs._2170.dto.PersonDto; import org.mapstruct.ap.test.bugs._2170.entity.Address; @@ -17,8 +15,8 @@ import org.mapstruct.ap.test.bugs._2170.mapper.EntityMapper; import org.mapstruct.ap.test.bugs._2170.mapper.PersonMapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -26,7 +24,6 @@ * @author Filip Hrisafov */ @IssueKey("2170") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Address.class, Person.class, @@ -38,7 +35,7 @@ }) public class Issue2170Test { - @Test + @ProcessorTest public void shouldGenerateCodeThatCompiles() { AddressDto addressDto = AddressMapper.INSTANCE.toDto( new Address( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java index 89359957c9..b6ec1f08d2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2174/Issue2174Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2174; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -18,11 +16,10 @@ * @author Filip Hrisafov */ @IssueKey("2174") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(UserMapper.class) public class Issue2174Test { - @Test + @ProcessorTest public void shouldNotWrapCheckedException() throws Exception { UserMapper.User user = UserMapper.INSTANCE.map( new UserMapper.UserDto( "Test City", "10000" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java index 50c1d9f69b..5c1c16b27f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2177/Issue2177Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2177; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Filip Hrisafov */ @IssueKey("2177") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2177Mapper.class }) public class Issue2177Test { - @Test + @ProcessorTest public void shouldCorrectlyUseGenericClassesWithConstructorMapping() { Issue2177Mapper.Target target = Issue2177Mapper.INSTANCE.map( new Issue2177Mapper.Source( "test" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java index 3b26842c0a..7280d26e31 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.bugs._2185; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,13 +18,12 @@ * @author Filip Hrisafov */ @IssueKey("2185") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ TodoMapper.class }) public class Issue2185Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = TodoMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java index 8d8a754d7f..5ee3c35d86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2195/Issue2195Test.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.bugs._2195; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._2195.dto.Source; import org.mapstruct.ap.test.bugs._2195.dto.Target; import org.mapstruct.ap.test.bugs._2195.dto.TargetBase; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2195") @WithClasses( { Source.class, Target.class, TargetBase.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2195Test { - @Test + @ProcessorTest @WithClasses( Issue2195Mapper.class ) public void test() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java index 52be67564c..774d1f396f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2197/Issue2197Test.java @@ -5,26 +5,23 @@ */ package org.mapstruct.ap.test.bugs._2197; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2197") @WithClasses(Issue2197Mapper.class) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2197Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( Issue2197Mapper.class ); - @Test + @ProcessorTest public void underscoreAndDigitPrefixShouldBeStrippedFromGeneratedLocalVariables() { Issue2197Mapper._0Target target = Issue2197Mapper.INSTANCE.map( new Issue2197Mapper.Source( "value1" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java index 613b981d04..2f8f951668 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2213/Issue2213Test.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.bugs._2213; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -24,15 +22,14 @@ Car.class, Car2.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("2213") public class Issue2213Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( CarMapper.class ); - @Test + @ProcessorTest public void testShouldNotGenerateIntermediatePrimitiveMappingMethod() { Car2 car = new Car2(); int[] sourceInt = { 1, 2, 3 }; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java index 34514de929..ef7f2f4ba6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2221/Issue2221Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2221; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2221") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ RestConfig.class, RestSiteDto.class, @@ -26,7 +23,7 @@ }) public class Issue2221Test { - @Test + @ProcessorTest public void multiSourceInheritConfigurationShouldWork() { SiteDto site = RestSiteMapper.INSTANCE.convert( new RestSiteDto( "restTenant", "restSite", "restCti" ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java index 645de0d24b..66911d936d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2233/Issue2233Test.java @@ -8,11 +8,9 @@ import java.util.Collections; import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; @@ -21,7 +19,6 @@ * @author Filip Hrisafov */ @IssueKey("2233") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { Program.class, ProgramAggregate.class, @@ -31,7 +28,7 @@ } ) public class Issue2233Test { - @Test + @ProcessorTest public void shouldCorrectlyMapFromOptionalToCollection() { ProgramResponseDto response = ProgramMapper.INSTANCE.map( new ProgramAggregate( Collections.singleton( new Program( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java index 17f42c8dc3..a1bbea638b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2236/Issue2236Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2236; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2236") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Car.class, CarDto.class, @@ -27,7 +24,7 @@ }) public class Issue2236Test { - @Test + @ProcessorTest public void shouldCorrectlyMapSameTypesWithDifferentNestedMappings() { Vehicle vehicle = new Vehicle(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java index 5aa899d055..69af6fef8a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2245/Issue2245Test.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.bugs._2245; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -19,17 +17,16 @@ * @author Filip Hrisafov */ @IssueKey("2245") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ TestMapper.class }) public class Issue2245Test { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( TestMapper.class ); - @Test + @ProcessorTest public void shouldGenerateSourceGetMethodOnce() { TestMapper.Tenant tenant = diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java index d08a5f7d74..1c430b00ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2251/Issue2251Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2251; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2251") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2251Mapper.class, Source.class, @@ -25,7 +22,7 @@ }) public class Issue2251Test { - @Test + @ProcessorTest public void shouldGenerateCorrectCode() { Target target = Issue2251Mapper.INSTANCE.map( new Source( "source" ), "test" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java index fc0e007daa..ae1c1eea79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2253/Issue2253Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2253; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Filip Hrisafov */ @IssueKey("2253") -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { TestMapper.class, } ) public class Issue2253Test { - @Test + @ProcessorTest public void shouldNotTreatMatchedSourceParameterAsBean() { TestMapper.Person person = TestMapper.INSTANCE.map( new TestMapper.PersonDto( 20 ), "Tester" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java index 03e545b210..53fd5d88a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2263/Issue2263Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._2263; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2263") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Erroneous2263Mapper.class, Source.class, @@ -26,7 +23,7 @@ }) public class Issue2263Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = Erroneous2263Mapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java index eefebfa870..8c8a4cf01f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2278/Issue2278Test.java @@ -7,17 +7,14 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("2278") -@RunWith( AnnotationProcessorTestRunner.class) public class Issue2278Test { - @Test + @ProcessorTest @WithClasses( Issue2278ReferenceMapper.class ) public void testReferenceMergeBehaviour() { @@ -37,7 +34,7 @@ public void testReferenceMergeBehaviour() { } - @Test + @ProcessorTest @WithClasses( Issue2278MapperA.class ) public void shouldBehaveJustAsTestReferenceMergeBehaviour() { @@ -57,7 +54,7 @@ public void shouldBehaveJustAsTestReferenceMergeBehaviour() { } - @Test + @ProcessorTest @WithClasses( Issue2278MapperB.class ) public void shouldOverrideDetailsMappingWithRedefined() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java index 8c237a2d30..3986ab1066 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2301/Issue2301Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2301; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2301") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Artifact.class, ArtifactDto.class, @@ -25,7 +22,7 @@ }) public class Issue2301Test { - @Test + @ProcessorTest public void shouldCorrectlyIgnoreProperties() { Artifact artifact = Issue2301Mapper.INSTANCE.map( new ArtifactDto( "mapstruct" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java index a1f1ad250b..a9a06ea470 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2318/Issue2318Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._2318; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.SourceChild; import org.mapstruct.ap.test.bugs._2318.Issue2318Mapper.TargetChild; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2318") -@RunWith(AnnotationProcessorTestRunner.class) public class Issue2318Test { - @Test + @ProcessorTest @WithClasses( Issue2318Mapper.class ) public void shouldMap() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java index f5e04fc776..e54816d576 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2347/Issue2347Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._2347; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2347") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ ErroneousClassWithPrivateMapper.class }) @@ -42,7 +39,7 @@ public class Issue2347Test { ) } ) - @Test + @ProcessorTest public void shouldGenerateCompileErrorWhenMapperIsPrivate() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java index ebf6ac1e1c..fa9edf0bf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2352/Issue2352Test.java @@ -7,16 +7,14 @@ import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._2352.dto.TheDto; import org.mapstruct.ap.test.bugs._2352.dto.TheModel; import org.mapstruct.ap.test.bugs._2352.dto.TheModels; import org.mapstruct.ap.test.bugs._2352.mapper.TheModelMapper; import org.mapstruct.ap.test.bugs._2352.mapper.TheModelsMapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -24,7 +22,6 @@ * @author Filip Hrisafov */ @IssueKey("2352") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ TheDto.class, TheModel.class, @@ -34,7 +31,7 @@ }) public class Issue2352Test { - @Test + @ProcessorTest public void shouldGenerateValidCode() { TheModels theModels = new TheModels(); theModels.add( new TheModel( "1" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java index e37f36528c..8efc38abd2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2356/Issue2356Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2356; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,13 +15,12 @@ * @author Filip Hrisafov */ @IssueKey("2356") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue2356Mapper.class }) public class Issue2356Test { - @Test + @ProcessorTest public void shouldCompile() { Issue2356Mapper.Car car = new Issue2356Mapper.Car(); car.brand = "Tesla"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java index 0bb88e5e59..8595d4c7f1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2393/Issue2393Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._2393; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Filip Hrisafov */ @IssueKey("2393") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Address.class, AddressDto.class, @@ -26,7 +23,7 @@ }) public class Issue2393Test { - @Test + @ProcessorTest public void shouldUseCorrectImport() { AddressDto dto = AddressDto.Converter.INSTANCE.convert( new Address( "Zurich", diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java index fb9d16112a..4b95513fe2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_289/Issue289Test.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.bugs._289; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/289. @@ -27,10 +25,9 @@ SourceElement.class, TargetElement.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue289Test { - @Test + @ProcessorTest public void shouldLeaveEmptyTargetSetWhenSourceIsNullAndGetterOnlyForCreateMethod() { Source source = new Source(); @@ -41,7 +38,7 @@ public void shouldLeaveEmptyTargetSetWhenSourceIsNullAndGetterOnlyForCreateMetho assertThat( target.getCollection() ).isEmpty(); } - @Test + @ProcessorTest public void shouldLeaveEmptyTargetSetWhenSourceIsNullAndGetterOnlyForUpdateMethod() { Source source = new Source(); @@ -54,7 +51,7 @@ public void shouldLeaveEmptyTargetSetWhenSourceIsNullAndGetterOnlyForUpdateMetho assertThat( target.getCollection() ).isEmpty(); } - @Test + @ProcessorTest public void shouldLeaveNullTargetSetWhenSourceIsNullForCreateMethod() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java index 712e563ca8..5d4f0c84b2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_306/Issue306Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._306; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/306. @@ -17,10 +15,9 @@ * @author Sjaak Derksen */ @IssueKey( "306" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue306Test { - @Test + @ProcessorTest @WithClasses( { Issue306Mapper.class, Source.class, Target.class } ) public void shouldForgeNewIterableMappingMethod() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java index d860591fff..91c01ac7c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_373/Issue373Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._373; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/373. @@ -17,10 +15,9 @@ * @author Sjaak Derksen */ @IssueKey( "373" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue373Test { - @Test + @ProcessorTest @WithClasses( { Issue373Mapper.class, Branch.class, BranchLocation.class, Country.class, ResultDto.class } ) public void shouldForgeCorrectEntityBranchLocationCountry() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java index 7c1fa96719..7f174732ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.bugs._374; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/306. @@ -24,10 +22,9 @@ * @author Sjaak Derksen */ @IssueKey( "306" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue374Test { - @Test + @ProcessorTest @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingTargetToDefault() { @@ -38,7 +35,7 @@ public void shouldMapExistingTargetToDefault() { assertThat( result.getConstant() ).isEqualTo( "test" ); } - @Test + @ProcessorTest @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingTargetWithConstantToDefault() { @@ -49,7 +46,7 @@ public void shouldMapExistingTargetWithConstantToDefault() { assertThat( target2.getConstant() ).isNull(); } - @Test + @ProcessorTest @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingIterableTargetToDefault() { @@ -60,7 +57,7 @@ public void shouldMapExistingIterableTargetToDefault() { assertThat( targetList ).isEmpty(); } - @Test + @ProcessorTest @WithClasses( { Issue374Mapper.class, Source.class, Target.class } ) public void shouldMapExistingMapTargetToDefault() { @@ -71,7 +68,7 @@ public void shouldMapExistingMapTargetToDefault() { assertThat( resultMap ).isEqualTo( resultMap ); } - @Test + @ProcessorTest @WithClasses( { Issue374VoidMapper.class, Source.class, Target.class } ) public void shouldMapExistingTargetVoidReturnToDefault() { @@ -81,7 +78,7 @@ public void shouldMapExistingTargetVoidReturnToDefault() { assertThat( target.getConstant() ).isEqualTo( "test" ); } - @Test + @ProcessorTest @WithClasses( { Issue374VoidMapper.class, Source.class, Target.class } ) public void shouldMapExistingIterableTargetVoidReturnToDefault() { @@ -91,7 +88,7 @@ public void shouldMapExistingIterableTargetVoidReturnToDefault() { assertThat( targetList ).isEmpty(); } - @Test + @ProcessorTest @WithClasses( { Issue374VoidMapper.class, Source.class, Target.class } ) public void shouldMapExistingMapTargetVoidReturnToDefault() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java index e02c56a1d8..3cbd2fcad1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_375/Issue375Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._375; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/375. @@ -17,10 +15,9 @@ * @author Sjaak Derksen */ @IssueKey( "375" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue375Test { - @Test + @ProcessorTest @WithClasses( { Issue375Mapper.class, Source.class, Target.class, Int.class, Case.class } ) public void shouldForgeNewMappings() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java index ac9dbf93c1..78cbc6177e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_394/SameClassNameInDifferentPackageTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.bugs._394; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._394.source.AnotherCar; import org.mapstruct.ap.test.bugs._394.source.Cars; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses( { SameNameForSourceAndTargetCarsMapper.class, @@ -26,10 +24,9 @@ org.mapstruct.ap.test.bugs._394._target.AnotherCar.class } ) @IssueKey("394") -@RunWith(AnnotationProcessorTestRunner.class) public class SameClassNameInDifferentPackageTest { - @Test + @ProcessorTest public void shouldCreateMapMethodImplementation() { Map values = new HashMap(); //given diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java index 75f6e6952e..f1f34ee394 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_405/Issue405Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._405; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/405. @@ -17,10 +15,9 @@ * @author Sjaak Derksen */ @IssueKey( "405" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue405Test { - @Test + @ProcessorTest @WithClasses( { EntityFactory.class, Person.class, People.class, PersonMapper.class } ) public void shouldGenerateFactoryCorrectMethodForIterables() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java index 0b75d8681e..9bc5be096e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_513/Issue513Test.java @@ -8,11 +8,11 @@ import java.util.Arrays; import java.util.HashMap; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/513. @@ -34,10 +34,9 @@ MappingKeyException.class, MappingValueException.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue513Test { - @Test( expected = MappingException.class ) + @ProcessorTest public void shouldThrowMappingException() throws Exception { Source source = new Source(); @@ -45,11 +44,12 @@ public void shouldThrowMappingException() throws Exception { sourceElement.setValue( "test" ); source.setCollection( Arrays.asList( sourceElement ) ); - Issue513Mapper.INSTANCE.map( source ); + assertThatThrownBy( () -> Issue513Mapper.INSTANCE.map( source ) ) + .isInstanceOf( MappingException.class ); } - @Test( expected = MappingKeyException.class ) + @ProcessorTest public void shouldThrowMappingKeyException() throws Exception { Source source = new Source(); @@ -60,11 +60,12 @@ public void shouldThrowMappingKeyException() throws Exception { map.put( sourceKey, sourceValue ); source.setMap( map ); - Issue513Mapper.INSTANCE.map( source ); + assertThatThrownBy( () -> Issue513Mapper.INSTANCE.map( source ) ) + .isInstanceOf( MappingKeyException.class ); } - @Test( expected = MappingValueException.class ) + @ProcessorTest public void shouldThrowMappingValueException() throws Exception { Source source = new Source(); @@ -75,11 +76,12 @@ public void shouldThrowMappingValueException() throws Exception { map.put( sourceKey, sourceValue ); source.setMap( map ); - Issue513Mapper.INSTANCE.map( source ); + assertThatThrownBy( () -> Issue513Mapper.INSTANCE.map( source ) ) + .isInstanceOf( MappingValueException.class ); } - @Test( expected = MappingException.class ) + @ProcessorTest public void shouldThrowMappingCommonException() throws Exception { Source source = new Source(); @@ -90,7 +92,8 @@ public void shouldThrowMappingCommonException() throws Exception { map.put( sourceKey, sourceValue ); source.setMap( map ); - Issue513Mapper.INSTANCE.map( source ); + assertThatThrownBy( () -> Issue513Mapper.INSTANCE.map( source ) ) + .isInstanceOf( MappingException.class ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java index e322963db7..eb32a41a85 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_515/Issue515Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._515; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/515. @@ -17,10 +15,9 @@ * @author Sjaak Derksen */ @IssueKey( "515" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue515Test { - @Test + @ProcessorTest @WithClasses( { Issue515Mapper.class, Source.class, Target.class } ) public void shouldIgnoreParanthesesOpenInStringDefinition() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java index 5b64aca1dc..226a7f8157 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_516/Issue516Test.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.bugs._516; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/516. @@ -19,10 +17,9 @@ * @author Sjaak Derksen */ @IssueKey( "516" ) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue516Test { - @Test + @ProcessorTest @WithClasses( { SourceTargetMapper.class, Source.class, Target.class } ) public void shouldAddNullPtrCheckAroundSourceForAdder() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java index ce5fb5dcbb..6d60aaa79e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_537/Issue537Test.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.bugs._537; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Christian Bandowski */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("537") @WithClasses({ Issue537Mapper.class, @@ -27,7 +24,7 @@ }) public class Issue537Test { - @Test + @ProcessorTest public void testThatReferencedMapperWillBeUsed() { Target target = Issue537Mapper.INSTANCE.mapDto( new Source( "abc" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java index 0773f7d271..4a6f0176d1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_543/Issue543Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._543; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.bugs._543.dto.Source; import org.mapstruct.ap.test.bugs._543.dto.Target; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("543") @WithClasses({ Issue543Mapper.class, @@ -28,10 +25,10 @@ }) public class Issue543Test { - @Rule - public GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest public void shouldCompile() { generatedSource.forMapper( Issue543Mapper.class ).containsImportFor( Source.class ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java index 9b6672a539..198231f410 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_577/Issue577Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._577; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @IssueKey( "577" ) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue577Test { - @Test + @ProcessorTest public void shouldMapTwoArraysToCollections() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java index cf50b344e1..7c1dfb266e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_581/Issue581Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._581; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._581.source.Car; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @IssueKey( "581" ) @WithClasses({ Car.class, org.mapstruct.ap.test.bugs._581._target.Car.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue581Test { - @Test + @ProcessorTest public void shouldMapSourceAndTargetWithTheSameClassName() { Car source = new Car(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java index 60c3910c0a..0bf8553e15 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_590/Issue590Test.java @@ -7,22 +7,19 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(ErroneousSourceTargetMapper.class) public class Issue590Test { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java index 1a503a74b2..79a6e045ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.bugs._611; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -17,7 +15,6 @@ * @author Tillmann Gaida */ @IssueKey("611") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ SomeClass.class, SomeOtherClass.class @@ -26,7 +23,7 @@ public class Issue611Test { /** * Checks if an implementation of a nested mapper can be loaded at all. */ - @Test + @ProcessorTest public void mapperIsFound() { assertThat( SomeClass.InnerMapper.INSTANCE ).isNotNull(); } @@ -35,7 +32,7 @@ public void mapperIsFound() { * Checks if an implementation of a nested mapper can be loaded which is nested into an already * nested class. */ - @Test + @ProcessorTest public void mapperNestedInsideNestedClassIsFound() { assertThat( SomeClass.SomeInnerClass.InnerMapper.INSTANCE ).isNotNull(); } @@ -44,7 +41,7 @@ public void mapperNestedInsideNestedClassIsFound() { * Checks if it is possible to load two mapper implementations which have equal simple names * in the same package. */ - @Test + @ProcessorTest public void rightMapperIsFound() { SomeClass.InnerMapper.Source source1 = new SomeClass.InnerMapper.Source(); SomeOtherClass.InnerMapper.Source source2 = new SomeOtherClass.InnerMapper.Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java index 32fc27d56c..81ff528da5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_625/Issue625Test.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._625; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Andreas Gudian * */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ ObjectFactory.class, Source.class, @@ -27,7 +24,7 @@ }) @IssueKey("625") public class Issue625Test { - @Test + @ProcessorTest public void ignoresFactoryMethods() { Source s = new Source(); s.setProp( "works" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java index 5d582d1c1f..57a221c6d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_631/Issue631Test.java @@ -7,22 +7,19 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) public class Issue631Test { - @Test + @ProcessorTest @IssueKey("631") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java index f16a9e6f6a..99d609408e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_634/GenericContainerTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.bugs._634; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Gunnar Morling @@ -26,10 +24,9 @@ Target.class, SourceTargetMapper.class, }) -@RunWith(AnnotationProcessorTestRunner.class) public class GenericContainerTest { - @Test + @ProcessorTest @IssueKey("634") public void canMapGenericSourceTypeToGenericTargetType() { List items = Arrays.asList( new Foo( "42" ), new Foo( "84" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java index a3fe3dacd3..db2f376416 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_775/IterableWithBoundedElementTypeTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.bugs._775; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import org.assertj.core.api.IterableAssert; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies: @@ -26,7 +24,6 @@ * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("775") @WithClasses({ MapperWithForgedIterableMapping.class, @@ -36,7 +33,7 @@ }) public class IterableWithBoundedElementTypeTest { - @Test + @ProcessorTest public void createsForgedMethodForIterableLowerBoundInteger() { ListContainer source = new ListContainer(); @@ -47,7 +44,7 @@ public void createsForgedMethodForIterableLowerBoundInteger() { .contains( 42, 47 ); } - @Test + @ProcessorTest public void usesListIntegerMethodForIterableLowerBoundInteger() { ListContainer source = new ListContainer(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java index b0d74bae26..431a999c45 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Commit.java @@ -30,4 +30,8 @@ public static int getCallCounter() { return callCounter; } + public static void resetCallCounter() { + callCounter = 0; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java index ff298ad8a2..28df16ee08 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/GitlabTag.java @@ -28,4 +28,8 @@ public static int getCallCounter() { return callCounter; } + public static void resetCallCounter() { + callCounter = 0; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java index 1540df73d6..4937f6c3d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_843/Issue843Test.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.bugs._843; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Commit.class, TagInfo.class, @@ -29,7 +26,7 @@ @IssueKey("843") public class Issue843Test { - @Test + @ProcessorTest public void testMapperCreation() { Commit commit = new Commit(); @@ -37,6 +34,8 @@ public void testMapperCreation() { GitlabTag gitlabTag = new GitlabTag(); gitlabTag.setCommit( commit ); + Commit.resetCallCounter(); + GitlabTag.resetCallCounter(); TagMapper.INSTANCE.gitlabTagToTagInfo( gitlabTag ); assertThat( Commit.getCallCounter() ).isEqualTo( 1 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java index 9bac413c0b..776f3f70e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_846/UpdateTest.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.bugs._846; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("846") @WithClasses({ Mapper846.class }) public class UpdateTest { - @Test + @ProcessorTest public void shouldProduceMapper() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java index 5b9e33c353..22ec5bd309 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_849/Issue849Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._849; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian * */ @WithClasses({ Source.class, Target.class, Issue849Mapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class Issue849Test { - @Test + @ProcessorTest @IssueKey("849") public void shouldCompileWithAllImportsDeclared() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java index eaeba688d0..54ee84a89c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_855/OrderingBug855Test.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.bugs._855; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian * */ @WithClasses({ OrderedSource.class, OrderedTarget.class, OrderDemoMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class OrderingBug855Test { - @Test + @ProcessorTest @IssueKey("855") public void shouldApplyCorrectOrderingWithDependsOn() { OrderedSource source = new OrderedSource(); @@ -31,7 +28,7 @@ public void shouldApplyCorrectOrderingWithDependsOn() { assertThat( target.getOrder() ).containsExactly( "field2", "field0", "field1", "field3", "field4" ); } - @Test + @ProcessorTest public void shouldRetainDefaultOrderWithoutDependsOn() { OrderedSource source = new OrderedSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java index d1352cceb4..f5196ec7b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_865/Issue865Test.java @@ -5,17 +5,15 @@ */ package org.mapstruct.ap.test.bugs._865; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { ProjectDto.class, ProjectEntity.class, @@ -26,7 +24,7 @@ } ) public class Issue865Test { - @Test + @ProcessorTest public void shouldGenerateNpeCheckBeforeCallingAddAllWhenInUpdateMethods() { ProjectDto dto = new ProjectDto(); @@ -41,7 +39,7 @@ public void shouldGenerateNpeCheckBeforeCallingAddAllWhenInUpdateMethods() { assertThat( entity.getCoreUsers() ).isNull(); } - @Test + @ProcessorTest public void shouldGenerateNpeCheckBeforeCallingAddAllWhenInUpdateMethodsAndTargetWithoutSetter() { ProjectDto dto = new ProjectDto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index 4d491b1b2c..d05f01dc91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -7,9 +7,8 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.MappingConstants; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -17,14 +16,12 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.stereotype.Component; /** * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ UsesConfigFromAnnotationMapper.class, DefaultsToProcessorOptionsMapper.class, @@ -34,10 +31,10 @@ @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING), @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") }) public class Issue880Test { - @Rule - public GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = @Diagnostic(kind = Kind.WARNING, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java index a520a055d4..5fae478f2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_891/Issue891Test.java @@ -5,19 +5,16 @@ */ package org.mapstruct.ap.test.bugs._891; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({BuggyMapper.class, Dest.class, Src.class, SrcNested.class}) public class Issue891Test { - @Test + @ProcessorTest public void shouldNotThrowNPE() { BuggyMapper.INSTANCE.convert( new Src() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java index 6291a56233..0064a96338 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_892/Issue892Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._892; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._892.Issue892Mapper.Source; import org.mapstruct.ap.test.bugs._892.Issue892Mapper.Target; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * When having two setter methods with the same name, choose the one with the argument type matching the getter method. * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Issue892Mapper.class }) public class Issue892Test { - @Test + @ProcessorTest public void compiles() { Source src = new Source(); src.setType( 42 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java index d9f25f5fec..320c7d1306 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_895/Issue895Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._895; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._895.MultiArrayMapper.WithArrayOfByteArray; import org.mapstruct.ap.test.bugs._895.MultiArrayMapper.WithListOfByteArray; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * Verifies that forged iterable mapping methods for multi-dimensional arrays are generated properly. * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(MultiArrayMapper.class) public class Issue895Test { - @Test + @ProcessorTest public void properlyMapsMultiDimensionalArrays() { WithArrayOfByteArray arrayOfByteArray = new WithArrayOfByteArray(); arrayOfByteArray.setBytes( new byte[][] { new byte[] { 0, 1 }, new byte[] { 1, 2 } } ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java index da74677ee2..20710488f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_909/Issue909Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._909; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._909.ValuesMapper.ValuesHolder; import org.mapstruct.ap.test.bugs._909.ValuesMapper.ValuesHolderDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; + /** * Verifies that forged iterable mapping methods for multi-dimensional arrays are generated properly. * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses(ValuesMapper.class) public class Issue909Test { - @Test + @ProcessorTest public void properlyCreatesMapperWithValuesAsParameterName() { ValuesHolder valuesHolder = new ValuesHolder(); valuesHolder.setValues( "values" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java index e63d91b5e7..4e10a4895f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913GetterMapperForCollectionsTest.java @@ -5,12 +5,11 @@ */ package org.mapstruct.ap.test.bugs._913; -import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * All these test cases test the possible combinations in the GetterMapperForCollections. @@ -19,7 +18,6 @@ * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ DomainWithoutSetter.class, Dto.class, @@ -36,7 +34,7 @@ public class Issue913GetterMapperForCollectionsTest { * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForCreate() { Dto dto = new Dto(); @@ -52,7 +50,7 @@ public void shouldReturnNullForNvmsReturnNullForCreate() { * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForUpdate() { Dto dto = new Dto(); @@ -70,7 +68,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdate() { * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { Dto dto = new Dto(); @@ -92,7 +90,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { * * However, for plain mappings (strings to strings) the result will be null. */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { Dto dto = new Dto(); @@ -110,7 +108,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { * * However, for plain mappings (strings to strings) the result will be null. */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { Dto dto = new Dto(); @@ -131,7 +129,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { * However, for plain mappings (strings to strings) the result will be null. * */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { Dto dto = new Dto(); @@ -151,7 +149,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { * Test create method ICW presence checker * */ - @Test + @ProcessorTest public void shouldReturnNullForCreateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -166,7 +164,7 @@ public void shouldReturnNullForCreateWithPresenceChecker() { * Test update method ICW presence checker * */ - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -182,7 +180,7 @@ public void shouldReturnNullForUpdateWithPresenceChecker() { * Test update with return method ICW presence checker * */ - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java index 8a3ce7fb64..a549011446 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_913/Issue913SetterMapperForCollectionsTest.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.bugs._913; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.HashSet; import java.util.Set; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * All these test cases test the possible combinations in the SetterMapperForCollections. * @@ -25,7 +23,6 @@ * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Domain.class, Dto.class, @@ -38,8 +35,8 @@ @IssueKey( "913" ) public class Issue913SetterMapperForCollectionsTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( DomainDtoWithNvmsNullMapper.class, DomainDtoWithNvmsDefaultMapper.class, DomainDtoWithPresenceCheckMapper.class, @@ -55,7 +52,7 @@ public class Issue913SetterMapperForCollectionsTest { * variable for setting {@code strings} as a direct assignment and the copy constructor is used, in case the * assignment is {@code null} then {@code null} should be set for {@code string} */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForCreate() { Dto dto = new Dto(); @@ -71,7 +68,7 @@ public void shouldReturnNullForNvmsReturnNullForCreate() { * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForUpdate() { Dto dto = new Dto(); @@ -94,7 +91,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdate() { * target (stringsInitialized is Not Null) and source (stringInitialized is Null) target should * be explicitely set to null */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForUpdateWithNonNullTargetAndNullSource() { Dto dto = new Dto(); @@ -117,7 +114,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithNonNullTargetAndNullSo * conversion from string to long that return null in the entire mapper, so also for the forged * mapper. Note the default NVMS is RETURN_NULL. */ - @Test + @ProcessorTest public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { Dto dto = new Dto(); @@ -140,7 +137,7 @@ public void shouldReturnNullForNvmsReturnNullForUpdateWithReturn() { * * However, for plain mappings (strings to strings) the result will also be an empty collection. */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { Dto dto = new Dto(); @@ -158,7 +155,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForCreate() { * * However, for plain mappings (strings to strings) the result will also be an empty collection. */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { Dto dto = new Dto(); @@ -184,7 +181,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdate() { * However, for plain mappings (strings to strings) the result will also be an empty collection. * */ - @Test + @ProcessorTest public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { Dto dto = new Dto(); @@ -211,7 +208,7 @@ public void shouldReturnDefaultForNvmsReturnDefaultForUpdateWithReturn() { * Test create method ICW presence checker. The presence checker is responsible for the null check. * */ - @Test + @ProcessorTest public void shouldReturnNullForCreateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -229,7 +226,7 @@ public void shouldReturnNullForCreateWithPresenceChecker() { * */ @IssueKey( "#954") - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -252,7 +249,7 @@ public void shouldReturnNullForUpdateWithPresenceChecker() { * */ @IssueKey( "#954") - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -277,7 +274,7 @@ public void shouldReturnNullForUpdateWithReturnWithPresenceChecker() { * */ @IssueKey( "#954") - @Test + @ProcessorTest public void shouldReturnNullForCreateWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -295,7 +292,7 @@ public void shouldReturnNullForCreateWithNcvsAlways() { * */ @IssueKey( "#954") - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); @@ -318,7 +315,7 @@ public void shouldReturnNullForUpdateWithNcvsAlways() { * */ @IssueKey( "#954") - @Test + @ProcessorTest public void shouldReturnNullForUpdateWithReturnWithNcvsAlways() { DtoWithPresenceCheck dto = new DtoWithPresenceCheck(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java index 8fc0e0cbcf..25c2baf89d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_931/Issue931Test.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.bugs._931; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Verifies that source.nested == null, leads to target.id == null @@ -19,10 +17,9 @@ * @author Sjaak Derksen */ @IssueKey( "931" ) -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { Source.class, Nested.class, Target.class, SourceTargetMapper.class } ) public class Issue931Test { - @Test + @ProcessorTest public void shouldMapNestedNullToNull() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java index 8178668900..4e03de5373 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_955/Issue955Test.java @@ -5,24 +5,21 @@ */ package org.mapstruct.ap.test.bugs._955; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.bugs._955.dto.Car; import org.mapstruct.ap.test.bugs._955.dto.Person; import org.mapstruct.ap.test.bugs._955.dto.SuperCar; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * * @author Sjaak Derksen */ @IssueKey( "955" ) -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { CarMapper.class, CustomMapper.class, Car.class, SuperCar.class, Person.class } ) public class Issue955Test { - @Test + @ProcessorTest public void shouldCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java index 236f1641c9..fe178f815b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_971/Issue971Test.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.bugs._971; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov * */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("971") public class Issue971Test { - @Test + @ProcessorTest @WithClasses({ CollectionSource.class, CollectionTarget.class, Issue971CollectionMapper.class }) public void shouldCompileForCollections() { } - @Test + @ProcessorTest @WithClasses({ MapSource.class, MapTarget.class, Issue971MapMapper.class }) public void shouldCompileForMaps() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java index 8ff3bf9fad..47a534d20a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractBuilder/AbstractBuilderTest.java @@ -5,10 +5,8 @@ */ package org.mapstruct.ap.test.builder.abstractBuilder; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,7 +21,6 @@ ProductDto.class, ProductMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AbstractBuilderTest { /** @@ -35,7 +32,7 @@ public class AbstractBuilderTest { * - all values are mapped * - all values are set properly */ - @Test + @ProcessorTest public void testThatAbstractBuilderMapsAllProperties() { ImmutableProduct product = ProductMapper.INSTANCE.fromMutable( new ProductDto( "router", 31 ) ); @@ -43,7 +40,7 @@ public void testThatAbstractBuilderMapsAllProperties() { assertThat( product.getName() ).isEqualTo( "router" ); } - @Test + @ProcessorTest public void testThatAbstractBuilderReverseMapsAllProperties() { ProductDto product = ProductMapper.INSTANCE.fromImmutable( ImmutableProduct.builder() .price( 31000 ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java index 8ff58c5af3..2b77353175 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/abstractGenericTarget/AbstractGenericTargetBuilderTest.java @@ -5,10 +5,8 @@ */ package org.mapstruct.ap.test.builder.abstractGenericTarget; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -26,10 +24,9 @@ ParentSource.class, ParentMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AbstractGenericTargetBuilderTest { - @Test + @ProcessorTest public void testAbstractTargetMapper() { ParentSource parent = new ParentSource(); parent.setCount( 4 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java index 57641a6dc1..5ec38b2d0a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/factory/BuilderFactoryMapperTest.java @@ -5,17 +5,14 @@ */ package org.mapstruct.ap.test.builder.factory; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ BuilderFactoryMapper.class, BuilderImplicitFactoryMapper.class, @@ -24,7 +21,7 @@ }) public class BuilderFactoryMapperTest { - @Test + @ProcessorTest public void shouldUseBuilderFactory() { Person person = BuilderFactoryMapper.INSTANCE.map( new PersonDto( "Filip" ) ); @@ -32,7 +29,7 @@ public void shouldUseBuilderFactory() { assertThat( person.getSource() ).isEqualTo( "Factory with @ObjectFactory" ); } - @Test + @ProcessorTest public void shouldUseImplicitBuilderFactory() { Person person = BuilderImplicitFactoryMapper.INSTANCE.map( new PersonDto( "Filip" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java index 5d28aa3f53..5be9d50ff6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/ignore/BuilderIgnoringTest.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.builder.ignore; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1452") @WithClasses({ BaseDto.class, @@ -28,7 +25,7 @@ }) public class BuilderIgnoringTest { - @Test + @ProcessorTest @IssueKey( "1933" ) public void shouldIgnoreBase() { PersonDto source = new PersonDto(); @@ -43,7 +40,7 @@ public void shouldIgnoreBase() { assertThat( target.getLastName() ).isEqualTo( "Doe" ); } - @Test + @ProcessorTest public void shouldMapOnlyExplicit() { PersonDto source = new PersonDto(); source.setId( 100L ); @@ -57,7 +54,7 @@ public void shouldMapOnlyExplicit() { assertThat( target.getLastName() ).isNull(); } - @Test + @ProcessorTest public void shouldMapAll() { PersonDto source = new PersonDto(); source.setId( 100L ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java index 706a08eea1..e3892f2154 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java @@ -7,18 +7,15 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "1433" ) @WithClasses( { Item.class, @@ -30,7 +27,7 @@ } ) public class BuilderLifecycleCallbacksTest { - @Test + @ProcessorTest public void lifecycleMethodsShouldBeInvoked() { OrderDto source = new OrderDto(); source.setCreator( "Filip" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java index e44912ff99..3682f2ccc5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.builder.mappingTarget.simple; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -20,13 +18,12 @@ SimpleImmutableTarget.class, SimpleBuilderMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class BuilderInfoTargetTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest public void testSimpleImmutableBuilderHappyPath() { SimpleMutableSource source = new SimpleMutableSource(); source.setAge( 3 ); @@ -39,7 +36,7 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getName() ).isEqualTo( "Bob" ); } - @Test + @ProcessorTest public void testMutableTargetWithBuilder() { SimpleMutableSource source = new SimpleMutableSource(); source.setAge( 20 ); @@ -50,7 +47,7 @@ public void testMutableTargetWithBuilder() { assertThat( target.getSource() ).isEqualTo( "Builder" ); } - @Test + @ProcessorTest public void testUpdateMutableWithBuilder() { SimpleMutableSource source = new SimpleMutableSource(); source.setAge( 20 ); @@ -69,7 +66,7 @@ public void testUpdateMutableWithBuilder() { assertThat( target.getSource() ).isEqualTo( "Empty constructor" ); } - @Test + @ProcessorTest public void updatingTargetWithNoSettersShouldNotFail() { SimpleMutableSource source = new SimpleMutableSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java index 21b9566c4f..825794d6d7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/multiple/MultipleBuilderMapperTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.builder.multiple; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.builder.multiple.build.Process; import org.mapstruct.ap.test.builder.multiple.builder.Case; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1479") @WithClasses({ Process.class, @@ -53,7 +50,7 @@ public class MultipleBuilderMapperTest { "\"wrongCreate(), create()\"." ) }) - @Test + @ProcessorTest public void moreThanOneBuildMethod() { } @@ -72,14 +69,14 @@ public void moreThanOneBuildMethod() { "\"wrongCreate(), create()\"." ) }) - @Test + @ProcessorTest public void moreThanOneBuildMethodDefinedOnMapper() { } @WithClasses({ BuilderDefinedMapper.class }) - @Test + @ProcessorTest public void builderMappingDefined() { Process map = BuilderDefinedMapper.INSTANCE.map( new Source( "map" ) ); Process wrongMap = BuilderDefinedMapper.INSTANCE.wrongMap( new Source( "wrongMap" ) ); @@ -92,7 +89,7 @@ public void builderMappingDefined() { BuilderMapperConfig.class, BuilderConfigDefinedMapper.class }) - @Test + @ProcessorTest public void builderMappingMapperConfigDefined() { Process map = BuilderConfigDefinedMapper.INSTANCE.map( new Source( "map" ) ); Process wrongMap = BuilderConfigDefinedMapper.INSTANCE.wrongMap( new Source( "wrongMap" ) ); @@ -115,7 +112,7 @@ public void builderMappingMapperConfigDefined() { "implementing a custom BuilderProvider SPI." ) }) - @Test + @ProcessorTest public void tooManyBuilderCreationMethods() { Case caseTarget = TooManyBuilderCreationMethodsMapper.INSTANCE.map( new Source( "test" ) ); @@ -128,7 +125,7 @@ public void tooManyBuilderCreationMethods() { @WithClasses( { DefaultBuildMethodMapper.class } ) - @Test + @ProcessorTest public void defaultBuildMethod() { Task task = DefaultBuildMethodMapper.INSTANCE.map( new Source( "test" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java index 45073dd906..94233a373e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/expanding/BuilderNestedPropertyTest.java @@ -5,10 +5,8 @@ */ package org.mapstruct.ap.test.builder.nestedprop.expanding; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +19,9 @@ ImmutableArticle.class, ExpandingMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class BuilderNestedPropertyTest { - @Test + @ProcessorTest public void testNestedImmutablePropertyMapper() { FlattenedStock stock = new FlattenedStock( "Sock", "Tie", 33 ); ImmutableExpandedStock expandedTarget = ExpandingMapper.INSTANCE.writeToNestedProperty( stock ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java index a25e224472..861bf810bf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/nestedprop/flattening/BuilderNestedPropertyTest.java @@ -5,10 +5,8 @@ */ package org.mapstruct.ap.test.builder.nestedprop.flattening; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +19,9 @@ Article.class, FlatteningMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class BuilderNestedPropertyTest { - @Test + @ProcessorTest public void testNestedImmutablePropertyMapper() { Stock stock = new Stock(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java index 6334be7ff0..e90babfdd8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/noop/NoOpBuilderProviderTest.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.builder.noop; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.NoOpBuilderProvider; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "1418" ) @WithServiceImplementation(NoOpBuilderProvider.class) @WithClasses( { @@ -28,7 +25,7 @@ } ) public class NoOpBuilderProviderTest { - @Test + @ProcessorTest public void shouldNotUseBuilder() { Person person = PersonMapper.INSTANCE.map( new PersonDto( "Filip" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java index a98be84d22..cc11a8fcdb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.builder.off; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.factory.Mappers; @@ -21,13 +19,12 @@ SimpleMutablePerson.class, SimpleNotRealyImmutablePerson.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleNotRealyImmutableBuilderTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ SimpleMapper.class }) public void testSimpleImmutableBuilderHappyPath() { SimpleMapper mapper = Mappers.getMapper( SimpleMapper.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java index f1a3b4d617..dd45573a59 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java @@ -8,10 +8,8 @@ import java.util.ArrayList; import org.assertj.core.api.Condition; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -22,10 +20,9 @@ ImmutableParent.class, ParentChildMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ParentChildBuilderTest { - @Test + @ProcessorTest public void testParentChildBuilderMapper() { final MutableParent parent = new MutableParent(); parent.setCount( 4 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java index 3bc4e91ed8..7f77621644 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java @@ -7,14 +7,12 @@ import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.factory.Mappers; @@ -24,13 +22,12 @@ SimpleMutablePerson.class, SimpleImmutablePerson.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleImmutableBuilderTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ SimpleBuilderMapper.class }) public void testSimpleImmutableBuilderHappyPath() { SimpleBuilderMapper mapper = Mappers.getMapper( SimpleBuilderMapper.class ); @@ -50,7 +47,7 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousSimpleBuilderMapper.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = @Diagnostic( diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index a16cb26ee6..e6cd7a19b4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -24,12 +24,8 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import org.mapstruct.ap.test.builtin._target.IterableTarget; import org.mapstruct.ap.test.builtin._target.MapTarget; import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; @@ -62,8 +58,8 @@ import org.mapstruct.ap.test.builtin.source.IterableSource; import org.mapstruct.ap.test.builtin.source.MapSource; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -89,24 +85,22 @@ IterableSource.class, MapSource.class }) -@RunWith(AnnotationProcessorTestRunner.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class BuiltInTest { private static TimeZone originalTimeZone; - @BeforeClass + @BeforeAll public static void setDefaultTimeZoneToCet() { originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); } - @AfterClass + @AfterAll public static void restoreOriginalTimeZone() { TimeZone.setDefault( originalTimeZone ); } - @Test + @ProcessorTest @WithClasses( JaxbMapper.class ) public void shouldApplyBuiltInOnJAXBElement() { JaxbElementProperty source = new JaxbElementProperty(); @@ -119,7 +113,7 @@ public void shouldApplyBuiltInOnJAXBElement() { assertThat( target.publicProp ).isEqualTo( "PUBLIC TEST" ); } - @Test + @ProcessorTest @WithClasses( JaxbMapper.class ) @IssueKey( "1698" ) public void shouldApplyBuiltInOnJAXBElementExtra() { @@ -142,7 +136,7 @@ public void shouldApplyBuiltInOnJAXBElementExtra() { assertThat( target2.getProp() ).isNotNull(); } - @Test + @ProcessorTest @WithClasses( JaxbListMapper.class ) @IssueKey( "141" ) public void shouldApplyBuiltInOnJAXBElementList() { @@ -157,7 +151,7 @@ public void shouldApplyBuiltInOnJAXBElementList() { assertThat( target.publicProp.get( 0 ) ).isEqualTo( "PUBLIC TEST2" ); } - @Test + @ProcessorTest @WithClasses( DateToXmlGregCalMapper.class ) public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException { @@ -173,7 +167,7 @@ public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException { assertThat( target.publicProp.toString() ).isEqualTo( "2016-08-31T10:20:56.000+02:00" ); } - @Test + @ProcessorTest @WithClasses( XmlGregCalToDateMapper.class ) public void shouldApplyBuiltInOnXmlGregCalToDate() throws DatatypeConfigurationException { @@ -190,7 +184,7 @@ public void shouldApplyBuiltInOnXmlGregCalToDate() throws DatatypeConfigurationE } - @Test + @ProcessorTest @WithClasses( StringToXmlGregCalMapper.class ) public void shouldApplyBuiltInStringToXmlGregCal() { @@ -225,7 +219,7 @@ public void shouldApplyBuiltInStringToXmlGregCal() { } - @Test + @ProcessorTest @WithClasses( XmlGregCalToStringMapper.class ) public void shouldApplyBuiltInXmlGregCalToString() throws DatatypeConfigurationException { @@ -252,7 +246,7 @@ public void shouldApplyBuiltInXmlGregCalToString() throws DatatypeConfigurationE } - @Test + @ProcessorTest @WithClasses( CalendarToXmlGregCalMapper.class ) public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException { @@ -268,7 +262,7 @@ public void shouldApplyBuiltInOnCalendarToXmlGregCal() throws ParseException { assertThat( target.publicProp.toString() ).isEqualTo( "2016-03-02T00:00:00.000+01:00" ); } - @Test + @ProcessorTest @WithClasses( XmlGregCalToCalendarMapper.class ) public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws DatatypeConfigurationException { @@ -286,7 +280,7 @@ public void shouldApplyBuiltInOnXmlGregCalToCalendar() throws DatatypeConfigurat } - @Test + @ProcessorTest @WithClasses( CalendarToDateMapper.class ) public void shouldApplyBuiltInOnCalendarToDate() throws ParseException { @@ -302,7 +296,7 @@ public void shouldApplyBuiltInOnCalendarToDate() throws ParseException { assertThat( target.publicProp ).isEqualTo( createCalendar( "02.03.2016" ).getTime() ); } - @Test + @ProcessorTest @WithClasses( DateToCalendarMapper.class ) public void shouldApplyBuiltInOnDateToCalendar() throws ParseException { @@ -319,7 +313,7 @@ public void shouldApplyBuiltInOnDateToCalendar() throws ParseException { } - @Test + @ProcessorTest @WithClasses( CalendarToStringMapper.class ) public void shouldApplyBuiltInOnCalendarToString() throws ParseException { @@ -335,7 +329,7 @@ public void shouldApplyBuiltInOnCalendarToString() throws ParseException { assertThat( target.publicProp ).isEqualTo( "02.03.2016" ); } - @Test + @ProcessorTest @WithClasses( StringToCalendarMapper.class ) public void shouldApplyBuiltInOnStringToCalendar() throws ParseException { @@ -352,7 +346,7 @@ public void shouldApplyBuiltInOnStringToCalendar() throws ParseException { } - @Test + @ProcessorTest @WithClasses( IterableSourceTargetMapper.class ) public void shouldApplyBuiltInOnIterable() throws DatatypeConfigurationException { @@ -366,7 +360,7 @@ public void shouldApplyBuiltInOnIterable() throws DatatypeConfigurationException assertThat( target.publicDates ).containsExactly( "02.03.2016" ); } - @Test + @ProcessorTest @WithClasses( MapSourceTargetMapper.class ) public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException { @@ -382,7 +376,7 @@ public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException { assertThat( target.publicExample.get( "TEST" ) ).isEqualTo( "2016-03-02+01:00" ); } - @Test + @ProcessorTest @WithClasses( CalendarToZonedDateTimeMapper.class ) public void shouldApplyBuiltInOnCalendarToZonedDateTime() throws ParseException { assertThat( CalendarToZonedDateTimeMapper.INSTANCE.map( null ) ).isNull(); @@ -399,7 +393,7 @@ public void shouldApplyBuiltInOnCalendarToZonedDateTime() throws ParseException assertThat( target.publicProp ).isEqualTo( ZonedDateTime.of( 2016, 3, 2, 0, 0, 0, 0, ZoneId.systemDefault() ) ); } - @Test + @ProcessorTest @WithClasses( ZonedDateTimeToCalendarMapper.class ) public void shouldApplyBuiltInOnZonedDateTimeToCalendar() throws ParseException { assertThat( ZonedDateTimeToCalendarMapper.INSTANCE.map( null ) ).isNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java index 17d7980ff8..85c1bed399 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java @@ -12,17 +12,15 @@ import java.util.GregorianCalendar; import java.util.TimeZone; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.test.builtin.bean.CalendarProperty; import org.mapstruct.ap.test.builtin.bean.DatatypeFactory; import org.mapstruct.ap.test.builtin.bean.DateProperty; import org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarFactorizedProperty; import org.mapstruct.ap.test.builtin.mapper.ToXmlGregCalMapper; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -34,23 +32,22 @@ DateProperty.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class DatatypeFactoryTest { private TimeZone originalTimeZone; - @Before + @BeforeEach public void setUp() { originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); } - @After + @AfterEach public void tearDown() { TimeZone.setDefault( originalTimeZone ); } - @Test + @ProcessorTest public void testNoConflictsWithOwnDatatypeFactory() throws ParseException { DateProperty source1 = new DateProperty(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java index 9f1e6cef20..77c62c9cac 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.builtin.jodatime; -import static org.assertj.core.api.Assertions.assertThat; - import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; @@ -16,8 +14,6 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean; import org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateBean; import org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean; @@ -32,8 +28,10 @@ import org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime; import org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalTime; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -46,11 +44,10 @@ LocalDateTimeBean.class, XmlGregorianCalendarBean.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey( "689" ) public class JodaTimeTest { - @Test + @ProcessorTest @WithClasses(DateTimeToXmlGregorianCalendar.class) public void shouldMapDateTimeToXmlGregorianCalendar() { @@ -69,7 +66,7 @@ public void shouldMapDateTimeToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( -60 ); } - @Test + @ProcessorTest @WithClasses(DateTimeToXmlGregorianCalendar.class) public void shouldMapIncompleteDateTimeToXmlGregorianCalendar() { @@ -85,7 +82,7 @@ public void shouldMapIncompleteDateTimeToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getMinute() ).isEqualTo( 1 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarToDateTime() throws Exception { @@ -105,7 +102,7 @@ public void shouldMapXmlGregorianCalendarToDateTime() throws Exception { assertThat( res.getDateTime().getZone().getOffset( null ) ).isEqualTo( 3600000 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTimeZone() throws Exception { @@ -131,7 +128,7 @@ public void shouldMapXmlGregorianCalendarWithoutTimeZoneToDateTimeWithDefaultTim assertThat( res.getDateTime().getZone().getOffset( 0 ) ).isEqualTo( DateTimeZone.getDefault().getOffset( 0 ) ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarWithoutMillisToDateTime() throws Exception { @@ -157,7 +154,7 @@ public void shouldMapXmlGregorianCalendarWithoutMillisToDateTime() throws Except assertThat( res.getDateTime().getZone().getOffset( null ) ).isEqualTo( 3600000 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarWithoutMillisAndTimeZoneToDateTimeWithDefaultTimeZone() throws Exception { @@ -182,7 +179,7 @@ public void shouldMapXmlGregorianCalendarWithoutMillisAndTimeZoneToDateTimeWithD assertThat( res.getDateTime().getZone().getOffset( 0 ) ).isEqualTo( DateTimeZone.getDefault().getOffset( 0 ) ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarWithoutSecondsToDateTime() throws Exception { @@ -207,7 +204,7 @@ public void shouldMapXmlGregorianCalendarWithoutSecondsToDateTime() throws Excep assertThat( res.getDateTime().getZone().getOffset( null ) ).isEqualTo( 3600000 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWithDefaultTimeZone() throws Exception { @@ -231,7 +228,7 @@ public void shouldMapXmlGregorianCalendarWithoutSecondsAndTimeZoneToDateTimeWith assertThat( res.getDateTime().getZone().getOffset( 0 ) ).isEqualTo( DateTimeZone.getDefault().getOffset( 0 ) ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToDateTime.class) public void shouldNotMapXmlGregorianCalendarWithoutMinutes() throws Exception { @@ -247,7 +244,7 @@ public void shouldNotMapXmlGregorianCalendarWithoutMinutes() throws Exception { assertThat( res.getDateTime() ).isNull(); } - @Test + @ProcessorTest @WithClasses({DateTimeToXmlGregorianCalendar.class, XmlGregorianCalendarToDateTime.class}) public void shouldMapRoundTrip() { @@ -263,7 +260,7 @@ public void shouldMapRoundTrip() { } - @Test + @ProcessorTest @WithClasses(LocalDateTimeToXmlGregorianCalendar.class) public void shouldMapLocalDateTimeToXmlGregorianCalendar() { @@ -282,7 +279,7 @@ public void shouldMapLocalDateTimeToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); } - @Test + @ProcessorTest @WithClasses(LocalDateTimeToXmlGregorianCalendar.class) public void shouldMapIncompleteLocalDateTimeToXmlGregorianCalendar() { @@ -301,7 +298,7 @@ public void shouldMapIncompleteLocalDateTimeToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDateTime.class) public void shouldMapXmlGregorianCalendarToLocalDateTime() throws Exception { @@ -320,7 +317,7 @@ public void shouldMapXmlGregorianCalendarToLocalDateTime() throws Exception { assertThat( res.getLocalDateTime().getMillisOfSecond() ).isEqualTo( 100 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDateTime.class) public void shouldMapXmlGregorianCalendarWithoutMillisToLocalDateTime() throws Exception { @@ -344,7 +341,7 @@ public void shouldMapXmlGregorianCalendarWithoutMillisToLocalDateTime() throws E assertThat( res.getLocalDateTime().getMillisOfSecond() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDateTime.class) public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalDateTime() throws Exception { @@ -368,7 +365,7 @@ public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalDateTime() throws assertThat( res.getLocalDateTime().getMillisOfSecond() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDateTime.class) public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalDateTime() throws Exception { @@ -385,7 +382,7 @@ public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalDateTime() thro } - @Test + @ProcessorTest @WithClasses(LocalDateToXmlGregorianCalendar.class) public void shouldMapLocalDateToXmlGregorianCalendar() { @@ -404,7 +401,7 @@ public void shouldMapLocalDateToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDate.class) public void shouldMapXmlGregorianCalendarToLocalDate() throws Exception { @@ -422,7 +419,7 @@ public void shouldMapXmlGregorianCalendarToLocalDate() throws Exception { assertThat( res.getLocalDate().getDayOfMonth() ).isEqualTo( 25 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalDate.class) public void shouldNotMapXmlGregorianCalendarWithoutDaysToLocalDate() throws Exception { @@ -439,7 +436,7 @@ public void shouldNotMapXmlGregorianCalendarWithoutDaysToLocalDate() throws Exce } - @Test + @ProcessorTest @WithClasses(LocalTimeToXmlGregorianCalendar.class) public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() { @@ -458,7 +455,7 @@ public void shouldMapIncompleteLocalTimeToXmlGregorianCalendar() { assertThat( res.getxMLGregorianCalendar().getTimezone() ).isEqualTo( DatatypeConstants.FIELD_UNDEFINED ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalTime.class) public void shouldMapXmlGregorianCalendarToLocalTime() throws Exception { @@ -474,7 +471,7 @@ public void shouldMapXmlGregorianCalendarToLocalTime() throws Exception { assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 100 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalTime.class) public void shouldMapXmlGregorianCalendarWithoutMillisToLocalTime() throws Exception { @@ -492,7 +489,7 @@ public void shouldMapXmlGregorianCalendarWithoutMillisToLocalTime() throws Excep assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalTime.class) public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalTime() throws Exception { @@ -510,7 +507,7 @@ public void shouldMapXmlGregorianCalendarWithoutSecondsToLocalTime() throws Exce assertThat( res.getLocalTime().getMillisOfSecond() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses(XmlGregorianCalendarToLocalTime.class) public void shouldNotMapXmlGregorianCalendarWithoutMinutesToLocalTime() throws Exception { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java index e4f363d4c3..7026a335d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.callbacks; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -14,34 +12,33 @@ import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.AfterMapping; import org.mapstruct.BeforeMapping; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for callback methods that are defined using {@link BeforeMapping} / {@link AfterMapping} * * @author Andreas Gudian */ -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { ClassContainingCallbacks.class, Invocation.class, Source.class, Target.class, SourceTargetMapper.class, SourceTargetCollectionMapper.class, BaseMapper.class, Qualified.class, SourceEnum.class, TargetEnum.class }) @IssueKey("14") public class CallbackMethodTest { - @Before + @BeforeEach public void reset() { ClassContainingCallbacks.reset(); BaseMapper.reset(); } - @Test + @ProcessorTest public void callbackMethodsForBeanMappingCalled() { SourceTargetMapper.INSTANCE.sourceToTarget( createSource() ); @@ -49,7 +46,7 @@ public void callbackMethodsForBeanMappingCalled() { assertBeanMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void callbackMethodsForBeanMappingWithResultParamCalled() { SourceTargetMapper.INSTANCE.sourceToTarget( createSource(), createEmptyTarget() ); @@ -57,7 +54,7 @@ public void callbackMethodsForBeanMappingWithResultParamCalled() { assertBeanMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void callbackMethodsForIterableMappingCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( Arrays.asList( createSource() ) ); @@ -65,7 +62,7 @@ public void callbackMethodsForIterableMappingCalled() { assertIterableMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void callbackMethodsForIterableMappingWithResultParamCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( Arrays.asList( createSource() ), new ArrayList<>() ); @@ -74,7 +71,7 @@ public void callbackMethodsForIterableMappingWithResultParamCalled() { assertIterableMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void callbackMethodsForMapMappingCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( toMap( "foo", createSource() ) ); @@ -82,7 +79,7 @@ public void callbackMethodsForMapMappingCalled() { assertMapMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void callbackMethodsForMapMappingWithResultParamCalled() { SourceTargetCollectionMapper.INSTANCE.sourceToTarget( toMap( "foo", createSource() ), @@ -92,7 +89,7 @@ public void callbackMethodsForMapMappingWithResultParamCalled() { assertMapMappingInvocations( BaseMapper.getInvocations() ); } - @Test + @ProcessorTest public void qualifiersAreEvaluatedCorrectly() { Source source = createSource(); Target target = SourceTargetMapper.INSTANCE.qualifiedSourceToTarget( source ); @@ -109,7 +106,7 @@ public void qualifiersAreEvaluatedCorrectly() { assertQualifiedInvocations( BaseMapper.getInvocations(), sourceList, targetList ); } - @Test + @ProcessorTest public void callbackMethodsForEnumMappingCalled() { SourceEnum source = SourceEnum.B; TargetEnum target = SourceTargetMapper.INSTANCE.toTargetEnum( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java index 2927108002..6ec9ee129d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ongeneratedmethods/MappingResultPostprocessorTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.callbacks.ongeneratedmethods; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -31,10 +29,9 @@ CompanyMapperPostProcessing.class }) @IssueKey("183") -@RunWith(AnnotationProcessorTestRunner.class) public class MappingResultPostprocessorTest { - @Test + @ProcessorTest public void test() { // setup diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index 6dac09f190..8c391bbfeb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -5,17 +5,16 @@ */ package org.mapstruct.ap.test.callbacks.returning; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.callbacks.returning.NodeMapperContext.ContextListener; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Test case for https://github.com/mapstruct/mapstruct/issues/469 @@ -26,21 +25,22 @@ @WithClasses( { Attribute.class, AttributeDto.class, Node.class, NodeDto.class, NodeMapperDefault.class, NodeMapperWithContext.class, NodeMapperContext.class, Number.class, NumberMapperDefault.class, NumberMapperContext.class, NumberMapperWithContext.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class CallbacksWithReturnValuesTest { - @Test( expected = StackOverflowError.class ) + @ProcessorTest public void mappingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); - NodeMapperDefault.INSTANCE.nodeToNodeDto( root ); + assertThatThrownBy( () -> NodeMapperDefault.INSTANCE.nodeToNodeDto( root ) ) + .isInstanceOf( StackOverflowError.class ); } - @Test( expected = StackOverflowError.class ) + @ProcessorTest public void updatingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); - NodeMapperDefault.INSTANCE.nodeToNodeDto( root, new NodeDto() ); + assertThatThrownBy( () -> NodeMapperDefault.INSTANCE.nodeToNodeDto( root, new NodeDto() ) ) + .isInstanceOf( StackOverflowError.class ); } - @Test + @ProcessorTest public void mappingWithContextCorrectlyResolvesCycles() { final AtomicReference contextLevel = new AtomicReference<>( null ); ContextListener contextListener = new ContextListener() { @@ -74,7 +74,7 @@ private static Node buildNodes() { return root; } - @Test + @ProcessorTest public void numberMappingWithoutContextDoesNotUseCache() { Number n1 = NumberMapperDefault.INSTANCE.integerToNumber( 2342 ); Number n2 = NumberMapperDefault.INSTANCE.integerToNumber( 2342 ); @@ -82,7 +82,7 @@ public void numberMappingWithoutContextDoesNotUseCache() { assertThat( n1 ).isNotSameAs( n2 ); } - @Test + @ProcessorTest public void numberMappingWithContextUsesCache() { NumberMapperContext.putCache( new Number( 2342 ) ); Number n1 = NumberMapperWithContext.INSTANCE.integerToNumber( 2342 ); @@ -92,7 +92,7 @@ public void numberMappingWithContextUsesCache() { NumberMapperContext.clearCache(); } - @Test + @ProcessorTest public void numberMappingWithContextCallsVisitNumber() { Number n1 = NumberMapperWithContext.INSTANCE.integerToNumber( 1234 ); Number n2 = NumberMapperWithContext.INSTANCE.integerToNumber( 5678 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java index e92dec0105..ebdca6c04c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/typematching/CallbackMethodTypeMatchingTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.callbacks.typematching; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.callbacks.typematching.CarMapper.CarDto; import org.mapstruct.ap.test.callbacks.typematching.CarMapper.CarEntity; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian * */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CarMapper.class }) public class CallbackMethodTypeMatchingTest { - @Test + @ProcessorTest public void callbackMethodAreCalled() { CarEntity carEntity = CarMapper.INSTANCE.toCarEntity( new CarDto() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java index d67df4a983..42ef2a25a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/CollectionMappingTest.java @@ -5,9 +5,6 @@ */ package org.mapstruct.ap.test.collection; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; @@ -17,20 +14,20 @@ import java.util.Map; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; @WithClasses({ Source.class, Target.class, Colour.class, SourceTargetMapper.class, TestList.class, TestMap.class, StringHolderArrayList.class, StringHolderToLongMap.class, StringHolder.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class CollectionMappingTest { - @Test + @ProcessorTest @IssueKey("6") public void shouldMapNullList() { Source source = new Source(); @@ -41,7 +38,7 @@ public void shouldMapNullList() { assertThat( target.getStringList() ).isNull(); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapNullList() { Target target = new Target(); @@ -52,7 +49,7 @@ public void shouldReverseMapNullList() { assertThat( source.getStringList() ).isNull(); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapList() { Source source = new Source(); @@ -64,7 +61,7 @@ public void shouldMapList() { assertThat( target.getStringList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("92") public void shouldMapListWithoutSetter() { Source source = new Source(); @@ -76,7 +73,7 @@ public void shouldMapListWithoutSetter() { assertThat( target.getStringListNoSetter() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapList() { Target target = new Target(); @@ -88,7 +85,7 @@ public void shouldReverseMapList() { assertThat( source.getStringList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapListAsCopy() { Source source = new Source(); @@ -101,7 +98,7 @@ public void shouldMapListAsCopy() { assertThat( source.getStringList() ).isNotEqualTo( target.getStringList() ); } - @Test + @ProcessorTest @IssueKey( "153" ) public void shouldMapListWithClearAndAddAll() { Source source = new Source(); @@ -130,7 +127,7 @@ public void shouldMapListWithClearAndAddAll() { TestList.setAddAllCalled( false ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapListAsCopy() { Target target = new Target(); @@ -142,7 +139,7 @@ public void shouldReverseMapListAsCopy() { assertThat( target.getStringList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapArrayList() { Source source = new Source(); @@ -154,7 +151,7 @@ public void shouldMapArrayList() { assertThat( target.getStringArrayList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapArrayList() { Target target = new Target(); @@ -166,7 +163,7 @@ public void shouldReverseMapArrayList() { assertThat( source.getStringArrayList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapSet() { Source source = new Source(); @@ -178,7 +175,7 @@ public void shouldMapSet() { assertThat( target.getStringSet() ).contains( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapSet() { Target target = new Target(); @@ -190,7 +187,7 @@ public void shouldReverseMapSet() { assertThat( source.getStringSet() ).contains( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapSetAsCopy() { Source source = new Source(); @@ -202,7 +199,7 @@ public void shouldMapSetAsCopy() { assertThat( source.getStringSet() ).containsOnly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapHashSetAsCopy() { Source source = new Source(); @@ -214,7 +211,7 @@ public void shouldMapHashSetAsCopy() { assertThat( source.getStringHashSet() ).containsOnly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapSetAsCopy() { Target target = new Target(); @@ -226,7 +223,7 @@ public void shouldReverseMapSetAsCopy() { assertThat( target.getStringSet() ).containsOnly( "Bob", "Alice" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapListToCollection() { Source source = new Source(); @@ -238,7 +235,7 @@ public void shouldMapListToCollection() { assertThat( target.getIntegerCollection() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapListToCollection() { Target target = new Target(); @@ -250,7 +247,7 @@ public void shouldReverseMapListToCollection() { assertThat( source.getIntegerList() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapIntegerSetToRawSet() { Source source = new Source(); @@ -262,7 +259,7 @@ public void shouldMapIntegerSetToRawSet() { assertThat( target.getSet() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapIntegerSetToStringSet() { Source source = new Source(); @@ -274,7 +271,7 @@ public void shouldMapIntegerSetToStringSet() { assertThat( target.getAnotherStringSet() ).containsOnly( "1", "2" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapIntegerSetToStringSet() { Target target = new Target(); @@ -286,7 +283,7 @@ public void shouldReverseMapIntegerSetToStringSet() { assertThat( source.getAnotherIntegerSet() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldMapSetOfEnumToStringSet() { Source source = new Source(); @@ -298,7 +295,7 @@ public void shouldMapSetOfEnumToStringSet() { assertThat( target.getColours() ).containsOnly( "BLUE", "GREEN" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapSetOfEnumToStringSet() { Target target = new Target(); @@ -310,7 +307,7 @@ public void shouldReverseMapSetOfEnumToStringSet() { assertThat( source.getColours() ).containsOnly( Colour.GREEN, Colour.BLUE ); } - @Test + @ProcessorTest public void shouldMapMapAsCopy() { Source source = new Source(); @@ -326,7 +323,7 @@ public void shouldMapMapAsCopy() { assertThat( target.getStringLongMap() ).hasSize( 3 ); } - @Test + @ProcessorTest @IssueKey( "153" ) public void shouldMapMapWithClearAndPutAll() { Source source = new Source(); @@ -358,7 +355,7 @@ public void shouldMapMapWithClearAndPutAll() { TestMap.setPuttAllCalled( false ); } - @Test + @ProcessorTest @IssueKey("87") public void shouldMapIntegerSetToNumberSet() { Set numbers = SourceTargetMapper.INSTANCE @@ -368,7 +365,7 @@ public void shouldMapIntegerSetToNumberSet() { assertThat( numbers ).containsOnly( 123, 456 ); } - @Test + @ProcessorTest @IssueKey("732") public void shouldEnumSetAsCopy() { Source source = new Source(); @@ -381,7 +378,7 @@ public void shouldEnumSetAsCopy() { assertThat( target.getEnumSet() ).containsOnly( Colour.BLUE, Colour.GREEN ); } - @Test + @ProcessorTest @IssueKey("853") public void shouldMapNonGenericList() { Source source = new Source(); @@ -406,7 +403,7 @@ public void shouldMapNonGenericList() { assertThat( mappedSource.getStringList3() ).containsExactly( "Bill", "Bob" ); } - @Test + @ProcessorTest @IssueKey("853") public void shouldMapNonGenericMap() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java index d3c667099c..b555970770 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/AdderTest.java @@ -5,16 +5,10 @@ */ package org.mapstruct.ap.test.collection.adder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.ArrayList; import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.collection.adder._target.AdderUsageObserver; import org.mapstruct.ap.test.collection.adder._target.IndoorPet; import org.mapstruct.ap.test.collection.adder._target.OutdoorPet; @@ -34,10 +28,15 @@ import org.mapstruct.ap.test.collection.adder.source.SourceTeeth; import org.mapstruct.ap.test.collection.adder.source.SourceWithPets; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * @author Sjaak Derksen */ @@ -70,18 +69,17 @@ Source2Target2Mapper.class, Foo.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AdderTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( SourceTargetMapper.class, SourceTargetMapperStrategyDefault.class, SourceTargetMapperStrategySetterPreferred.class ); @IssueKey("241") - @Test + @ProcessorTest public void testAdd() throws DogException { AdderUsageObserver.setUsed( false ); @@ -95,28 +93,30 @@ public void testAdd() throws DogException { assertTrue( AdderUsageObserver.isUsed() ); } - @Test(expected = DogException.class) + @ProcessorTest public void testAddWithExceptionInThrowsClause() throws DogException { AdderUsageObserver.setUsed( false ); Source source = new Source(); source.setPets( Arrays.asList( "dog" ) ); - SourceTargetMapper.INSTANCE.toTarget( source ); + assertThatThrownBy( () -> SourceTargetMapper.INSTANCE.toTarget( source ) ) + .isInstanceOf( DogException.class ); } - @Test(expected = RuntimeException.class) + @ProcessorTest public void testAddWithExceptionNotInThrowsClause() throws DogException { AdderUsageObserver.setUsed( false ); Source source = new Source(); source.setPets( Arrays.asList( "cat" ) ); - SourceTargetMapper.INSTANCE.toTarget( source ); + assertThatThrownBy( () -> SourceTargetMapper.INSTANCE.toTarget( source ) ) + .isInstanceOf( RuntimeException.class ); } @IssueKey("241") - @Test + @ProcessorTest public void testAddWithExistingTarget() { AdderUsageObserver.setUsed( false ); @@ -134,7 +134,7 @@ public void testAddWithExistingTarget() { assertTrue( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testShouldUseDefaultStrategy() throws DogException { AdderUsageObserver.setUsed( false ); @@ -148,7 +148,7 @@ public void testShouldUseDefaultStrategy() throws DogException { assertFalse( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testShouldPreferSetterStrategyButThereIsNone() throws DogException { AdderUsageObserver.setUsed( false ); @@ -162,7 +162,7 @@ public void testShouldPreferSetterStrategyButThereIsNone() throws DogException { assertTrue( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testShouldPreferHumanSingular() { AdderUsageObserver.setUsed( false ); @@ -177,7 +177,7 @@ public void testShouldPreferHumanSingular() { assertTrue( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testShouldFallBackToDaliSingularInAbsenceOfHumanSingular() { AdderUsageObserver.setUsed( false ); @@ -191,7 +191,7 @@ public void testShouldFallBackToDaliSingularInAbsenceOfHumanSingular() { assertTrue( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testAddReverse() { AdderUsageObserver.setUsed( false ); @@ -204,7 +204,7 @@ public void testAddReverse() { assertThat( target.getPets().get( 0 ) ).isEqualTo( "cat" ); } - @Test + @ProcessorTest public void testAddOnlyGetter() throws DogException { AdderUsageObserver.setUsed( false ); @@ -218,7 +218,7 @@ public void testAddOnlyGetter() throws DogException { assertTrue( AdderUsageObserver.isUsed() ); } - @Test + @ProcessorTest public void testAddViaTargetType() { AdderUsageObserver.setUsed( false ); @@ -234,7 +234,7 @@ public void testAddViaTargetType() { } @IssueKey("242") - @Test + @ProcessorTest public void testSingleElementSource() { AdderUsageObserver.setUsed( false ); @@ -249,7 +249,7 @@ public void testSingleElementSource() { } @IssueKey( "310" ) - @Test + @ProcessorTest public void testMissingImport() { generatedSource.addComparisonToFixtureFor( Source2Target2Mapper.class ); @@ -262,7 +262,7 @@ public void testMissingImport() { } @IssueKey("1478") - @Test + @ProcessorTest public void useIterationNameFromSource() { generatedSource.addComparisonToFixtureFor( SourceTargetMapperWithDifferentProperties.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java index a6ba036e81..9d360656a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java @@ -5,9 +5,6 @@ */ package org.mapstruct.ap.test.collection.defaultimplementation; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -23,14 +20,15 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentNavigableMap; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + @WithClasses({ Source.class, Target.class, @@ -38,14 +36,13 @@ TargetFoo.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class DefaultCollectionImplementationTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource() + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() .addComparisonToFixtureFor( SourceTargetMapper.class ); - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForConcurrentMap() { ConcurrentMap target = @@ -54,7 +51,7 @@ public void shouldUseDefaultImplementationForConcurrentMap() { assertResultMap( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForConcurrentNavigableMap() { ConcurrentNavigableMap target = @@ -63,7 +60,7 @@ public void shouldUseDefaultImplementationForConcurrentNavigableMap() { assertResultMap( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForMap() { Map target = SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooMap( createSourceFooMap() ); @@ -71,7 +68,7 @@ public void shouldUseDefaultImplementationForMap() { assertResultMap( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForNavigableMap() { NavigableMap target = @@ -80,7 +77,7 @@ public void shouldUseDefaultImplementationForNavigableMap() { assertResultMap( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForSortedMap() { SortedMap target = @@ -89,7 +86,7 @@ public void shouldUseDefaultImplementationForSortedMap() { assertResultMap( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForNaviableSet() { NavigableSet target = @@ -98,7 +95,7 @@ public void shouldUseDefaultImplementationForNaviableSet() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForCollection() { Collection target = @@ -107,7 +104,7 @@ public void shouldUseDefaultImplementationForCollection() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForIterable() { Iterable target = @@ -116,7 +113,7 @@ public void shouldUseDefaultImplementationForIterable() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForList() { List target = SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( createSourceFooList() ); @@ -124,7 +121,7 @@ public void shouldUseDefaultImplementationForList() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForSet() { Set target = @@ -133,7 +130,7 @@ public void shouldUseDefaultImplementationForSet() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldUseDefaultImplementationForSortedSet() { SortedSet target = @@ -142,7 +139,7 @@ public void shouldUseDefaultImplementationForSortedSet() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldUseTargetParameterForMapping() { List target = new ArrayList<>(); @@ -154,7 +151,7 @@ public void shouldUseTargetParameterForMapping() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldUseAndReturnTargetParameterForMapping() { List target = new ArrayList<>(); @@ -166,7 +163,7 @@ public void shouldUseAndReturnTargetParameterForMapping() { assertResultList( target ); } - @Test + @ProcessorTest @IssueKey("92") public void shouldUseDefaultImplementationForListWithoutSetter() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java index 1d9747854b..8723969723 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterCollectionMappingTest.java @@ -5,29 +5,26 @@ */ package org.mapstruct.ap.test.collection.defaultimplementation; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * @author Andreas Gudian * */ @WithClasses( { NoSetterMapper.class, NoSetterSource.class, NoSetterTarget.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class NoSetterCollectionMappingTest { - @Test + @ProcessorTest @IssueKey( "220" ) public void compilesAndMapsCorrectly() { NoSetterSource source = new NoSetterSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java index e386be191c..d9861be87e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/erroneous/ErroneousCollectionMappingTest.java @@ -7,26 +7,23 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.NoProperties; import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Test for illegal mappings between collection types, iterable and non-iterable types etc. * * @author Gunnar Morling */ -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousCollectionMappingTest { - @Test + @ProcessorTest @IssueKey("6") @WithClasses({ ErroneousCollectionToNonCollectionMapper.class, Source.class }) @ExpectedCompilationOutcome( @@ -49,7 +46,7 @@ public class ErroneousCollectionMappingTest { public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollectionWithResultTypeFromJava() { } - @Test + @ProcessorTest @IssueKey("729") @WithClasses({ ErroneousCollectionToPrimitivePropertyMapper.class, Source.class, Target.class }) @ExpectedCompilationOutcome( @@ -65,7 +62,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndNonCollectionW public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { } - @Test + @ProcessorTest @IssueKey("417") @WithClasses({ EmptyItererableMappingMapper.class }) @ExpectedCompilationOutcome( @@ -81,7 +78,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { public void shouldFailOnEmptyIterableAnnotation() { } - @Test + @ProcessorTest @IssueKey("417") @WithClasses({ EmptyMapMappingMapper.class }) @ExpectedCompilationOutcome( @@ -98,7 +95,7 @@ public void shouldFailOnEmptyIterableAnnotation() { public void shouldFailOnEmptyMapAnnotation() { } - @Test + @ProcessorTest @IssueKey("459") @WithClasses({ ErroneousCollectionNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( @@ -115,7 +112,7 @@ public void shouldFailOnEmptyMapAnnotation() { public void shouldFailOnNoElementMappingFound() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousCollectionNoElementMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( @@ -131,7 +128,7 @@ public void shouldFailOnNoElementMappingFound() { public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { } - @Test + @ProcessorTest @IssueKey("459") @WithClasses({ ErroneousCollectionNoKeyMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( @@ -148,7 +145,7 @@ public void shouldFailOnNoElementMappingFoundWithDisabledAuto() { public void shouldFailOnNoKeyMappingFound() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousCollectionNoKeyMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( @@ -164,7 +161,7 @@ public void shouldFailOnNoKeyMappingFound() { public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { } - @Test + @ProcessorTest @IssueKey("459") @WithClasses({ ErroneousCollectionNoValueMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( @@ -181,7 +178,7 @@ public void shouldFailOnNoKeyMappingFoundWithDisabledAuto() { public void shouldFailOnNoValueMappingFound() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousCollectionNoValueMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java index 9fe6fec56a..67cabc9f95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/forged/CollectionMappingTest.java @@ -5,24 +5,19 @@ */ package org.mapstruct.ap.test.collection.forged; - -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Map; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.google.common.collect.ImmutableMap; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import com.google.common.collect.ImmutableMap; +import static org.assertj.core.api.Assertions.assertThat; /** * Test for mappings between collection types, @@ -30,10 +25,9 @@ * @author Sjaak Derksen */ @IssueKey( "4" ) -@RunWith(AnnotationProcessorTestRunner.class) public class CollectionMappingTest { - @Test + @ProcessorTest @WithClasses({ CollectionMapper.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethod() { @@ -52,7 +46,7 @@ public void shouldForgeNewIterableMappingMethod() { assertThat( source2.publicFooSet ).isEqualTo( Collections.asSet( "3", "4" ) ); } - @Test + @ProcessorTest @WithClasses({ CollectionMapper.class, Source.class, Target.class }) public void shouldForgeNewMapMappingMethod() { @@ -74,7 +68,7 @@ public void shouldForgeNewMapMappingMethod() { assertThat( source2.publicBarMap ).isEqualTo( source.publicBarMap ); } - @Test + @ProcessorTest @WithClasses({ ErroneousCollectionNonMappableSetMapper.class, ErroneousNonMappableSetSource.class, @@ -96,7 +90,7 @@ public void shouldForgeNewMapMappingMethod() { public void shouldGenerateNonMappleMethodForSetMapping() { } - @Test + @ProcessorTest @WithClasses({ ErroneousCollectionNonMappableMapMapper.class, ErroneousNonMappableMapSource.class, ErroneousNonMappableMapTarget.class, @@ -123,7 +117,7 @@ public void shouldGenerateNonMappleMethodForSetMapping() { public void shouldGenerateNonMappleMethodForMapMapping() { } - @Test + @ProcessorTest @IssueKey( "640" ) @WithClasses({ CollectionMapper.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() { @@ -143,7 +137,7 @@ public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() { assertThat( source2.publicFooSet ).isNull(); } - @Test + @ProcessorTest @IssueKey( "640" ) @WithClasses({ CollectionMapper.class, Source.class, Target.class }) public void shouldForgeNewMapMappingMethodReturnNullOnNullSource() { @@ -163,7 +157,7 @@ public void shouldForgeNewMapMappingMethodReturnNullOnNullSource() { assertThat( source2.publicBarMap ).isNull(); } - @Test + @ProcessorTest @IssueKey( "640" ) @WithClasses({ CollectionMapperNullValueMappingReturnDefault.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethodReturnEmptyOnNullSource() { @@ -185,7 +179,7 @@ public void shouldForgeNewIterableMappingMethodReturnEmptyOnNullSource() { assertThat( source2.publicBarMap ).isEmpty(); } - @Test + @ProcessorTest @IssueKey( "640" ) @WithClasses({ CollectionMapperNullValueMappingReturnDefault.class, Source.class, Target.class }) public void shouldForgeNewMapMappingMethodReturnEmptyOnNullSource() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index 85dff16393..b3d2096bc3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -5,30 +5,27 @@ */ package org.mapstruct.ap.test.collection.immutabletarget; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({CupboardDto.class, CupboardEntity.class, CupboardMapper.class}) @IssueKey( "1126" ) public class ImmutableProductTest { - @Test + @ProcessorTest public void shouldHandleImmutableTarget() { CupboardDto in = new CupboardDto(); @@ -42,7 +39,7 @@ public void shouldHandleImmutableTarget() { assertThat( out.getContent() ).containsExactly( "cups", "soucers" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousCupboardMapper.class, CupboardEntityOnlyGetter.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java index feb0948c65..892e24df4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletononiterable/IterableToNonIterableMappingTest.java @@ -10,18 +10,15 @@ import java.util.Arrays; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class, FruitsMenu.class, FruitSalad.class, Fruit.class, FruitsMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class IterableToNonIterableMappingTest { - @Test + @ProcessorTest @IssueKey("6") public void shouldMapStringListToStringUsingCustomMapper() { Source source = new Source(); @@ -34,7 +31,7 @@ public void shouldMapStringListToStringUsingCustomMapper() { assertThat( target.publicNames ).isEqualTo( "Alice-Bob-Jim" ); } - @Test + @ProcessorTest @IssueKey("6") public void shouldReverseMapStringListToStringUsingCustomMapper() { Target target = new Target(); @@ -48,7 +45,7 @@ public void shouldReverseMapStringListToStringUsingCustomMapper() { assertThat( source.publicNames ).isEqualTo( Arrays.asList( "Alice", "Bob", "Jim" ) ); } - @Test + @ProcessorTest @IssueKey("607") public void shouldMapIterableToNonIterable() { List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), @@ -60,7 +57,7 @@ public void shouldMapIterableToNonIterable() { assertThat( salad.getFruits().get( 2 ).getType() ).isEqualTo( "banana" ); } - @Test + @ProcessorTest @IssueKey("607") public void shouldMapNonIterableToIterable() { List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index a9a17e5416..ddba51f826 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -5,21 +5,19 @@ */ package org.mapstruct.ap.test.collection.map; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.collection.map.other.ImportedType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * Test for implementation of {@code Map} mapping methods. @@ -28,10 +26,9 @@ */ @WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class, ImportedType.class }) @IssueKey("44") -@RunWith(AnnotationProcessorTestRunner.class) public class MapMappingTest { - @Test + @ProcessorTest public void shouldCreateMapMethodImplementation() { Map values = new HashMap<>(); values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); @@ -47,7 +44,7 @@ public void shouldCreateMapMethodImplementation() { ); } - @Test + @ProcessorTest public void shouldCreateReverseMapMethodImplementation() { Map values = createStringStringMap(); @@ -56,7 +53,7 @@ public void shouldCreateReverseMapMethodImplementation() { assertResult( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldCreateMapMethodImplementationWithTargetParameter() { Map values = createStringStringMap(); @@ -69,7 +66,7 @@ public void shouldCreateMapMethodImplementationWithTargetParameter() { assertResult( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldCreateMapMethodImplementationWithReturnedTargetParameter() { Map values = createStringStringMap(); @@ -101,7 +98,7 @@ private Map createStringStringMap() { return values; } - @Test + @ProcessorTest public void shouldInvokeMapMethodImplementationForMapTypedProperty() { Map values = new HashMap<>(); values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); @@ -130,7 +127,7 @@ public void shouldInvokeMapMethodImplementationForMapTypedProperty() { ); } - @Test + @ProcessorTest public void shouldInvokeReverseMapMethodImplementationForMapTypedProperty() { Map values = createStringStringMap(); @@ -164,7 +161,7 @@ private Map createIntIntMap() { return values; } - @Test + @ProcessorTest @IssueKey("87") public void shouldCreateMapMethodImplementationWithoutConversionOrElementMappingMethod() { Map values = createIntIntMap(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index aa09cdbc4f..37ed4606f6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -5,37 +5,33 @@ */ package org.mapstruct.ap.test.collection.wildcard; -import static org.assertj.core.api.Assertions.assertThat; - import java.math.BigDecimal; - import javax.xml.bind.JAXBElement; import javax.xml.namespace.QName; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Reproducer for https://github.com/mapstruct/mapstruct/issues/527. * * @author Sjaak Derksen */ @IssueKey("527") -@RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ ExtendsBoundSourceTargetMapper.class, ExtendsBoundSource.class, @@ -57,7 +53,7 @@ public void shouldGenerateExtendsBoundSourceForgedIterableMethod() { .doesNotContain( "? extends org.mapstruct.ap.test.collection.wildcard.Idea" ); } - @Test + @ProcessorTest @WithClasses({ SourceSuperBoundTargetMapper.class, Source.class, @@ -79,7 +75,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { .doesNotContain( "? super org.mapstruct.ap.test.collection.wildcard.Idea" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableSuperBoundSourceMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -93,7 +89,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { public void shouldFailOnSuperBoundSource() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableExtendsBoundTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -107,7 +103,7 @@ public void shouldFailOnSuperBoundSource() { public void shouldFailOnExtendsBoundTarget() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMethod.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -121,7 +117,7 @@ public void shouldFailOnExtendsBoundTarget() { public void shouldFailOnTypeVarSource() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -135,7 +131,7 @@ public void shouldFailOnTypeVarSource() { public void shouldFailOnTypeVarTarget() { } - @Test + @ProcessorTest @WithClasses( { BeanMapper.class, GoodIdea.class, CunningPlan.class } ) public void shouldMapBean() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java index 128abccf55..5eaf44765d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java @@ -5,24 +5,22 @@ */ package org.mapstruct.ap.test.complex; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.complex._target.CarDto; import org.mapstruct.ap.test.complex._target.PersonDto; import org.mapstruct.ap.test.complex.other.DateMapper; import org.mapstruct.ap.test.complex.source.Car; import org.mapstruct.ap.test.complex.source.Category; import org.mapstruct.ap.test.complex.source.Person; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Car.class, @@ -33,15 +31,14 @@ Category.class, DateMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class CarMapperTest { - @Test + @ProcessorTest public void shouldProvideMapperInstance() { assertThat( CarMapper.INSTANCE ).isNotNull(); } - @Test + @ProcessorTest public void shouldMapAttributeByName() { //given Car car = new Car( @@ -60,7 +57,7 @@ public void shouldMapAttributeByName() { assertThat( carDto.getMake() ).isEqualTo( car.getMake() ); } - @Test + @ProcessorTest public void shouldMapReferenceAttribute() { //given Car car = new Car( @@ -80,7 +77,7 @@ public void shouldMapReferenceAttribute() { assertThat( carDto.getDriver().getName() ).isEqualTo( "Bob" ); } - @Test + @ProcessorTest public void shouldReverseMapReferenceAttribute() { //given CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); @@ -94,7 +91,7 @@ public void shouldReverseMapReferenceAttribute() { assertThat( car.getDriver().getName() ).isEqualTo( "Bob" ); } - @Test + @ProcessorTest public void shouldMapAttributeWithCustomMapping() { //given Car car = new Car( @@ -113,7 +110,7 @@ public void shouldMapAttributeWithCustomMapping() { assertThat( carDto.getSeatCount() ).isEqualTo( car.getNumberOfSeats() ); } - @Test + @ProcessorTest public void shouldConsiderCustomMappingForReverseMapping() { //given CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); @@ -126,7 +123,7 @@ public void shouldConsiderCustomMappingForReverseMapping() { assertThat( car.getNumberOfSeats() ).isEqualTo( carDto.getSeatCount() ); } - @Test + @ProcessorTest public void shouldApplyConverter() { //given Car car = new Car( @@ -145,7 +142,7 @@ public void shouldApplyConverter() { assertThat( carDto.getManufacturingYear() ).isEqualTo( "1980" ); } - @Test + @ProcessorTest public void shouldApplyConverterForReverseMapping() { //given CarDto carDto = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); @@ -160,7 +157,7 @@ public void shouldApplyConverterForReverseMapping() { ); } - @Test + @ProcessorTest public void shouldMapIterable() { //given Car car1 = new Car( @@ -196,7 +193,7 @@ public void shouldMapIterable() { assertThat( dtos.get( 1 ).getDriver().getName() ).isEqualTo( "Bill" ); } - @Test + @ProcessorTest public void shouldReverseMapIterable() { //given CarDto car1 = new CarDto( "Morris", 2, "1980", new PersonDto( "Bob" ), new ArrayList<>() ); @@ -224,7 +221,7 @@ public void shouldReverseMapIterable() { assertThat( cars.get( 1 ).getDriver().getName() ).isEqualTo( "Bill" ); } - @Test + @ProcessorTest public void shouldMapIterableAttribute() { //given Car car = new Car( @@ -246,7 +243,7 @@ public void shouldMapIterableAttribute() { assertThat( dto.getPassengers().get( 1 ).getName() ).isEqualTo( "Bill" ); } - @Test + @ProcessorTest public void shouldReverseMapIterableAttribute() { //given CarDto carDto = new CarDto( @@ -268,7 +265,7 @@ public void shouldReverseMapIterableAttribute() { assertThat( car.getPassengers().get( 1 ).getName() ).isEqualTo( "Bill" ); } - @Test + @ProcessorTest public void shouldMapEnumToString() { //given Car car = new Car(); @@ -281,7 +278,7 @@ public void shouldMapEnumToString() { assertThat( carDto.getCategory() ).isEqualTo( "CONVERTIBLE" ); } - @Test + @ProcessorTest public void shouldMapStringToEnum() { //given CarDto carDto = new CarDto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java index 300f97bce4..0fc791fb13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java @@ -8,15 +8,13 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -29,13 +27,12 @@ BasicEmployee.class, BasicEmployeeDto.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConditionalMappingTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ ConditionalMethodInMapper.class }) @@ -53,7 +50,7 @@ public void conditionalMethodInMapper() { assertThat( employee.getName() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodAndBeanPresenceCheckMapper.class }) @@ -70,7 +67,7 @@ public void conditionalMethodAndBeanPresenceCheckMapper() { assertThat( employee.getName() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodInUsesMapper.class }) @@ -87,7 +84,7 @@ public void conditionalMethodInUsesMapper() { assertThat( employee.getName() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodInUsesStaticMapper.class }) @@ -104,7 +101,7 @@ public void conditionalMethodInUsesStaticMapper() { assertThat( employee.getName() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodInContextMapper.class }) @@ -122,7 +119,7 @@ public void conditionalMethodInUsesContextMapper() { assertThat( employee.getName() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodWithSourceParameterMapper.class }) @@ -136,7 +133,7 @@ public void conditionalMethodWithSourceParameter() { assertThat( employee.getName() ).isEqualTo( "Tester" ); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodWithSourceParameterAndValueMapper.class }) @@ -155,7 +152,7 @@ public void conditionalMethodWithSourceParameterAndValue() { assertThat( employee.getName() ).isEqualTo( "Tester" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousAmbiguousConditionalMethodMapper.class }) @@ -177,7 +174,7 @@ public void ambiguousConditionalMethod() { } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodForCollectionMapper.class }) @@ -205,7 +202,7 @@ public void conditionalMethodForCollection() { .containsExactly( "Test", "Test Vol. 2" ); } - @Test + @ProcessorTest @WithClasses({ OptionalLikeConditionalMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java index cf38d85dd1..60179cdeac 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java @@ -5,17 +5,15 @@ */ package org.mapstruct.ap.test.conditional.expression; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.conditional.Employee; import org.mapstruct.ap.test.conditional.EmployeeDto; import org.mapstruct.ap.test.conditional.basic.BasicEmployee; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -27,10 +25,9 @@ Employee.class, EmployeeDto.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConditionalExpressionTest { - @Test + @ProcessorTest @WithClasses({ ConditionalMethodsInUtilClassMapper.class }) @@ -62,7 +59,7 @@ public void conditionalExpressionInStaticClassMethod() { assertThat( employee.getSsid() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ SimpleConditionalExpressionMapper.class }) @@ -77,7 +74,7 @@ public void conditionalSimpleExpression() { assertThat( target.getValue() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java index 3dc6d7c8aa..5d13787e65 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.conditional.qualifier; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.conditional.Employee; import org.mapstruct.ap.test.conditional.EmployeeDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +21,9 @@ Employee.class, EmployeeDto.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConditionalQualifierTest { - @Test + @ProcessorTest @WithClasses({ ConditionalMethodWithSourceParameterMapper.class }) @@ -58,7 +55,7 @@ public void conditionalMethodWithSourceParameter() { assertThat( employee.getSsid() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ConditionalMethodWithClassQualifiersMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java index b58d55f1ee..3e26b442ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/constructorproperties/SimpleConstructorPropertiesTest.java @@ -7,12 +7,10 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.ConstructorProperties; import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -25,10 +23,9 @@ PersonDto.class, SimpleConstructorPropertiesMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleConstructorPropertiesTest { - @Test + @ProcessorTest public void mapDefault() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -48,7 +45,7 @@ public void mapDefault() { assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); } - @Test + @ProcessorTest public void mapWithConstants() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -68,7 +65,7 @@ public void mapWithConstants() { assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); } - @Test + @ProcessorTest public void mapWithExpressions() { PersonDto source = new PersonDto(); source.setName( "Bob" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java index ac447d7878..25f4fb8b1d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/defaultannotated/SimpleDefaultAnnotatedConstructorTest.java @@ -7,12 +7,10 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.Default; import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -25,10 +23,9 @@ PersonDto.class, SimpleDefaultAnnotatedConstructorMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleDefaultAnnotatedConstructorTest { - @Test + @ProcessorTest public void mapDefault() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -44,7 +41,7 @@ public void mapDefault() { assertThat( target.getAge() ).isEqualTo( 30 ); } - @Test + @ProcessorTest public void mapWithConstants() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -61,7 +58,7 @@ public void mapWithConstants() { assertThat( target.getAge() ).isEqualTo( 25 ); } - @Test + @ProcessorTest public void mapWithExpressions() { PersonDto source = new PersonDto(); source.setName( "Bob" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java index eac6188ab6..2799e10847 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.constructor.erroneous; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.ConstructorProperties; import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousConstructorTest { - @Test + @ProcessorTest @WithClasses({ ErroneousAmbiguousConstructorsMapper.class, PersonDto.class @@ -39,7 +36,7 @@ public class ErroneousConstructorTest { public void shouldUseMultipleConstructors() { } - @Test + @ProcessorTest @WithClasses({ ConstructorProperties.class, ErroneousConstructorPropertiesMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java index dde307adf7..7611cc2364 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/manysourcearguments/ManySourceArgumentsConstructorMappingTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.constructor.manysourcearguments; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.Person; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { ManySourceArgumentsConstructorMapper.class, Person.class, } ) public class ManySourceArgumentsConstructorMappingTest { - @Test + @ProcessorTest public void shouldCorrectlyUseDefaultValueForSourceParameters() { Person person = ManySourceArgumentsConstructorMapper.INSTANCE.map( null, "Test Valley" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java index 2c24e33cb5..dde9b798f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/mixed/ConstructorMixedWithSettersTest.java @@ -7,11 +7,9 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +21,9 @@ PersonDto.class, ConstructorMixedWithSettersMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConstructorMixedWithSettersTest { - @Test + @ProcessorTest public void mapDefault() { PersonDto source = new PersonDto(); source.setName( "Bob" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java index 4fe43506ab..653fccd118 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/NestedSourcePropertiesConstructorTest.java @@ -7,9 +7,7 @@ import java.util.Collections; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; @@ -17,8 +15,8 @@ import org.mapstruct.ap.test.constructor.nestedsource.source.Song; import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -28,13 +26,12 @@ */ @WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) @IssueKey("73") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedSourcePropertiesConstructorTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldGenerateImplementationForPropertyNamesOnly() { generatedSource.addComparisonToFixtureFor( ArtistToChartEntry.class ); @@ -58,7 +55,7 @@ public void shouldGenerateImplementationForPropertyNamesOnly() { assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldGenerateImplementationForMultipleParam() { @@ -113,7 +110,7 @@ public void shouldGenerateImplementationForMultipleParam() { assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldPickPropertyNameOverParameterName() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java index 231a4fcad7..73b23c5677 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedsource/ReversingNestedSourcePropertiesConstructorTest.java @@ -7,8 +7,6 @@ import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.nestedsource._target.BaseChartEntry; import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntryComposed; @@ -21,8 +19,8 @@ import org.mapstruct.ap.test.constructor.nestedsource.source.Song; import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -31,10 +29,9 @@ */ @IssueKey("73") @WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ReversingNestedSourcePropertiesConstructorTest { - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryReverse.class }) public void shouldGenerateNestedReverse() { @@ -63,7 +60,7 @@ public void shouldGenerateNestedReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithIgnoresReverse.class }) public void shouldIgnoreEverytingBelowArtist() { @@ -86,7 +83,7 @@ public void shouldIgnoreEverytingBelowArtist() { assertThat( song2.getArtist() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithFactoryReverse.class }) public void shouldGenerateNestedReverseWithFactory() { @@ -116,7 +113,7 @@ public void shouldGenerateNestedReverseWithFactory() { } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class }) public void shouldGenerateNestedComposedReverse() { @@ -146,7 +143,7 @@ public void shouldGenerateNestedComposedReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithMappingReverse.class, ChartEntryWithMapping.class }) public void shouldGenerateNestedWithMappingReverse() { @@ -175,7 +172,7 @@ public void shouldGenerateNestedWithMappingReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithConfigReverse.class, ArtistToChartEntryConfig.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java index 78d113a8c8..c5cbe8279c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/nestedtarget/NestedProductPropertiesConstructorTest.java @@ -5,9 +5,7 @@ */ package org.mapstruct.ap.test.constructor.nestedtarget; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry; import org.mapstruct.ap.test.constructor.nestedsource.source.Artist; import org.mapstruct.ap.test.constructor.nestedsource.source.Chart; @@ -15,8 +13,8 @@ import org.mapstruct.ap.test.constructor.nestedsource.source.Song; import org.mapstruct.ap.test.constructor.nestedsource.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -34,15 +32,14 @@ ChartEntryToArtist.class, }) @IssueKey("73") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedProductPropertiesConstructorTest { - @Rule - public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( ChartEntryToArtist.class ); - @Test + @ProcessorTest public void shouldMapNestedTarget() { ChartEntry chartEntry = new ChartEntry( @@ -72,7 +69,7 @@ public void shouldMapNestedTarget() { } - @Test + @ProcessorTest public void shouldReverseNestedTarget() { ChartEntry chartEntry = new ChartEntry( diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java index e24abb84b1..49bb7e6d8a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/simple/SimpleConstructorTest.java @@ -7,12 +7,10 @@ import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.Person; import org.mapstruct.ap.test.constructor.PersonDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -24,10 +22,9 @@ PersonDto.class, SimpleConstructorMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleConstructorTest { - @Test + @ProcessorTest public void mapDefault() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -47,7 +44,7 @@ public void mapDefault() { assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); } - @Test + @ProcessorTest public void mapWithConstants() { PersonDto source = new PersonDto(); source.setName( "Bob" ); @@ -67,7 +64,7 @@ public void mapWithConstants() { assertThat( target.getChildren() ).containsExactly( "Alice", "Tom" ); } - @Test + @ProcessorTest public void mapWithExpressions() { PersonDto source = new PersonDto(); source.setName( "Bob" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java index 7a7f859041..0e35361f48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/unmapped/UnmappedConstructorTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.constructor.unmapped; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +21,9 @@ OrderDto.class, UnmappedConstructorMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class UnmappedConstructorTest { - @Test + @ProcessorTest @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = UnmappedConstructorMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java index b40dcbf17c..b7a254296d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.constructor.visibility; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.constructor.Default; import org.mapstruct.ap.test.constructor.PersonDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -19,14 +17,13 @@ * @author Filip Hrisafov */ @IssueKey("2150") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ PersonDto.class, Default.class, }) public class ConstructorVisibilityTest { - @Test + @ProcessorTest @WithClasses({ SimpleWithPublicConstructorMapper.class }) @@ -43,7 +40,7 @@ public void shouldUseSinglePublicConstructorAlways() { assertThat( target.getAge() ).isEqualTo( 30 ); } - @Test + @ProcessorTest @WithClasses({ SimpleWithPublicParameterlessConstructorMapper.class }) @@ -60,7 +57,7 @@ public void shouldUsePublicParameterConstructorIfPresent() { assertThat( target.getAge() ).isEqualTo( -1 ); } - @Test + @ProcessorTest @WithClasses({ SimpleWithPublicParameterlessConstructorAndDefaultAnnotatedMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java index 2569973372..77fefe756e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -7,16 +7,14 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.Context; import org.mapstruct.ap.test.context.erroneous.ErroneousNodeMapperWithNonUniqueContextTypes; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Tests the erroneous usage of the {@link Context} annotation in the following situations: @@ -31,10 +29,9 @@ Node.class, NodeDto.class, CycleContext.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ContextParameterErroneousTest { - @Test + @ProcessorTest @WithClasses(ErroneousNodeMapperWithNonUniqueContextTypes.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = @Diagnostic( diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java index 8fc6e436e0..017183743b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.context; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.BeforeMapping; import org.mapstruct.Context; import org.mapstruct.ObjectFactory; import org.mapstruct.ap.test.context.Node.Attribute; import org.mapstruct.ap.test.context.NodeDto.AttributeDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the usage of the {@link Context} annotation in the following situations: @@ -44,12 +42,11 @@ CycleContextLifecycleMethods.class, FactoryContextMethods.class, SelfContainingCycleContext.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ContextParameterTest { private static final int MAGIC_NUMBER_OFFSET = 10; - @Test + @ProcessorTest public void mappingWithContextCorrectlyResolvesCycles() { Node root = buildNodes(); NodeDto rootDto = @@ -61,7 +58,7 @@ public void mappingWithContextCorrectlyResolvesCycles() { assertResult( updated ); } - @Test + @ProcessorTest public void automappingWithContextCorrectlyResolvesCycles() { Node root = buildNodes(); NodeDto rootDto = AutomappingNodeMapperWithContext.INSTANCE @@ -74,7 +71,7 @@ public void automappingWithContextCorrectlyResolvesCycles() { assertResult( updated ); } - @Test + @ProcessorTest public void automappingWithSelfContainingContextCorrectlyResolvesCycles() { Node root = buildNodes(); NodeDto rootDto = AutomappingNodeMapperWithSelfContainingContext.INSTANCE diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java index 08ca1ce1b9..068a5a0d95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/objectfactory/ContextWithObjectFactoryTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.context.objectfactory; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -23,10 +21,9 @@ ValveDto.class, ContextObjectFactory.class, ContextWithObjectFactoryMapper.class}) -@RunWith(AnnotationProcessorTestRunner.class) public class ContextWithObjectFactoryTest { - @Test + @ProcessorTest public void testFactoryCalled( ) { ValveDto dto = new ValveDto(); dto.setOneWay( true ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java index 400026254a..d59f069458 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/ConversionTest.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.conversion; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConversionTest { - @Test + @ProcessorTest public void shouldApplyConversions() { Source source = new Source(); source.setFoo( 42 ); @@ -31,7 +28,7 @@ public void shouldApplyConversions() { assertThat( target.getZip() ).isEqualTo( "73" ); } - @Test + @ProcessorTest public void shouldHandleNulls() { Source source = new Source(); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); @@ -42,7 +39,7 @@ public void shouldHandleNulls() { assertThat( target.getZip() ).isEqualTo( "0" ); } - @Test + @ProcessorTest public void shouldApplyConversionsToMappedProperties() { Source source = new Source(); source.setQax( 42 ); @@ -55,7 +52,7 @@ public void shouldApplyConversionsToMappedProperties() { assertThat( target.getQax() ).isEqualTo( 23 ); } - @Test + @ProcessorTest public void shouldApplyConversionsForReverseMapping() { Target target = new Target(); target.setFoo( 42L ); @@ -70,7 +67,7 @@ public void shouldApplyConversionsForReverseMapping() { assertThat( source.getZip() ).isEqualTo( 73 ); } - @Test + @ProcessorTest public void shouldApplyConversionsToMappedPropertiesForReverseMapping() { Target target = new Target(); target.setQax( 42 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java index 95adb3e050..69f87f3980 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java @@ -5,35 +5,28 @@ */ package org.mapstruct.ap.test.conversion.bignumbers; -import static org.assertj.core.api.Assertions.assertThat; - import java.math.BigDecimal; import java.math.BigInteger; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests conversions between {@link BigInteger} and numbers as well as String. * * @author Gunnar Morling */ -@RunWith(AnnotationProcessorTestRunner.class) public class BigNumbersConversionTest { - private final GeneratedSource generatedSource = new GeneratedSource(); - - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @IssueKey("21") @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) public void shouldApplyBigIntegerConversions() { @@ -70,7 +63,7 @@ public void shouldApplyBigIntegerConversions() { assertThat( target.getString() ).isEqualTo( "13" ); } - @Test + @ProcessorTest @IssueKey("21") @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) public void shouldApplyReverseBigIntegerConversions() { @@ -107,7 +100,7 @@ public void shouldApplyReverseBigIntegerConversions() { assertThat( source.getString() ).isEqualTo( new BigInteger( "13" ) ); } - @Test + @ProcessorTest @IssueKey("21") @WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class }) public void shouldApplyBigDecimalConversions() { @@ -146,7 +139,7 @@ public void shouldApplyBigDecimalConversions() { assertThat( target.getBigInteger() ).isEqualTo( new BigInteger( "14" ) ); } - @Test + @ProcessorTest @IssueKey("21") @WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class }) public void shouldApplyReverseBigDecimalConversions() { @@ -185,10 +178,10 @@ public void shouldApplyReverseBigDecimalConversions() { assertThat( source.getBigInteger() ).isEqualTo( new BigDecimal( "14" ) ); } - @Test + @ProcessorTest @IssueKey("1009") @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) public void shouldNotGenerateCreateDecimalFormatMethod() { - getGeneratedSource().forMapper( BigIntegerMapper.class ).content().doesNotContain( "createDecimalFormat" ); + generatedSource.forMapper( BigIntegerMapper.class ).content().doesNotContain( "createDecimalFormat" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java index 092388e2e8..57b4f7e4e4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/currency/CurrencyConversionTest.java @@ -9,12 +9,10 @@ import java.util.HashSet; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,10 +21,9 @@ */ @WithClasses({ CurrencyMapper.class, CurrencySource.class, CurrencyTarget.class }) @IssueKey("1355") -@RunWith(AnnotationProcessorTestRunner.class) public class CurrencyConversionTest { - @Test + @ProcessorTest public void shouldApplyCurrencyConversions() { final CurrencySource source = new CurrencySource(); source.setCurrencyA( Currency.getInstance( "USD" ) ); @@ -44,7 +41,7 @@ public void shouldApplyCurrencyConversions() { .containsExactlyInAnyOrder( "EUR", "CHF" ); } - @Test + @ProcessorTest public void shouldApplyReverseConversions() { final CurrencyTarget target = new CurrencyTarget(); target.setCurrencyA( "USD" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 2d98b73bc9..363b287b71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.conversion.date; -import static org.assertj.core.api.Assertions.assertThat; - import java.sql.Time; import java.sql.Timestamp; import java.util.Arrays; @@ -16,16 +14,16 @@ import java.util.List; import java.util.Locale; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; -import org.mapstruct.ap.testutil.runner.EnabledOnCompiler; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests application of format strings for conversions between strings and dates. @@ -38,27 +36,23 @@ SourceTargetMapper.class }) @IssueKey("43") -@RunWith(AnnotationProcessorTestRunner.class) public class DateConversionTest { private Locale originalLocale; - @Before + @BeforeEach public void setDefaultLocale() { originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } - @After + @AfterEach public void tearDown() { Locale.setDefault( originalLocale ); } - @Test - @DisabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledOnJre( JRE.JAVA_8 ) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversions() { Source source = new Source(); @@ -72,11 +66,8 @@ public void shouldApplyDateFormatForConversions() { assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13 00:00" ); } - @Test - @EnabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledForJreRange(min = JRE.JAVA_11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionsJdk11() { Source source = new Source(); @@ -90,11 +81,8 @@ public void shouldApplyDateFormatForConversionsJdk11() { assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); } - @Test - @DisabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledOnJre(JRE.JAVA_8) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMapping() { Target target = new Target(); @@ -110,11 +98,8 @@ public void shouldApplyDateFormatForConversionInReverseMapping() { ); } - @Test - @EnabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledForJreRange(min = JRE.JAVA_11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { Target target = new Target(); @@ -130,7 +115,7 @@ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { ); } - @Test + @ProcessorTest public void shouldApplyStringConversionForIterableMethod() { List dates = Arrays.asList( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), @@ -144,7 +129,7 @@ public void shouldApplyStringConversionForIterableMethod() { assertThat( stringDates ).containsExactly( "06.07.2013", "14.02.2013", "11.04.2013" ); } - @Test + @ProcessorTest public void shouldApplyStringConversionForArrayMethod() { List dates = Arrays.asList( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), @@ -158,7 +143,7 @@ public void shouldApplyStringConversionForArrayMethod() { assertThat( stringDates ).isEqualTo( new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" } ); } - @Test + @ProcessorTest public void shouldApplyStringConversionForReverseIterableMethod() { List stringDates = Arrays.asList( "06.07.2013", "14.02.2013", "11.04.2013" ); @@ -172,7 +157,7 @@ public void shouldApplyStringConversionForReverseIterableMethod() { ); } - @Test + @ProcessorTest public void shouldApplyStringConversionForReverseArrayMethod() { String[] stringDates = new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" }; @@ -186,7 +171,7 @@ public void shouldApplyStringConversionForReverseArrayMethod() { ); } - @Test + @ProcessorTest public void shouldApplyStringConversionForReverseArrayArrayMethod() { Date[] dates = new Date[]{ new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), @@ -199,7 +184,7 @@ public void shouldApplyStringConversionForReverseArrayArrayMethod() { assertThat( stringDates ).isEqualTo( new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" } ); } - @Test + @ProcessorTest public void shouldApplyDateConversionForReverseArrayArrayMethod() { String[] stringDates = new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" }; @@ -214,7 +199,7 @@ public void shouldApplyDateConversionForReverseArrayArrayMethod() { } @IssueKey("858") - @Test + @ProcessorTest public void shouldApplyDateToSqlConversion() { GregorianCalendar time = new GregorianCalendar( 2016, Calendar.AUGUST, 24, 20, 30, 30 ); GregorianCalendar sqlDate = new GregorianCalendar( 2016, Calendar.AUGUST, 23, 21, 35, 35 ); @@ -236,7 +221,7 @@ public void shouldApplyDateToSqlConversion() { } @IssueKey("858") - @Test + @ProcessorTest public void shouldApplySqlToDateConversion() { Target target = new Target(); GregorianCalendar time = new GregorianCalendar( 2016, Calendar.AUGUST, 24, 20, 30, 30 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java index 8f630df22c..5eb67bee05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.conversion.erroneous; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -22,7 +20,6 @@ Target.class }) @IssueKey("725") -@RunWith(AnnotationProcessorTestRunner.class) public class InvalidDateFormatTest { @WithClasses({ @@ -79,7 +76,7 @@ public class InvalidDateFormatTest { line = 43, message = "Given date format \"qwertz\" is invalid. Message: \"Illegal pattern character 'q'\".") }) - @Test + @ProcessorTest public void shouldFailWithInvalidDateFormats() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index 25ed958867..bcd5045646 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -17,37 +17,34 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * Tests for conversions to/from Java 8 date and time types. */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @IssueKey("121") public class Java8TimeConversionTest { private TimeZone originalTimeZone; - @Before + @BeforeEach public void setUp() { originalTimeZone = TimeZone.getDefault(); } - @After + @AfterEach public void tearDown() { TimeZone.setDefault( originalTimeZone ); } - @Test + @ProcessorTest public void testDateTimeToString() { Source src = new Source(); src.setZonedDateTime( ZonedDateTime.of( java.time.LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ) ); @@ -56,7 +53,7 @@ public void testDateTimeToString() { assertThat( target.getZonedDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); } - @Test + @ProcessorTest public void testLocalDateTimeToString() { Source src = new Source(); src.setLocalDateTime( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ); @@ -65,7 +62,7 @@ public void testLocalDateTimeToString() { assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); } - @Test + @ProcessorTest public void testLocalDateToString() { Source src = new Source(); src.setLocalDate( LocalDate.of( 2014, 1, 1 ) ); @@ -74,7 +71,7 @@ public void testLocalDateToString() { assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); } - @Test + @ProcessorTest public void testLocalTimeToString() { Source src = new Source(); src.setLocalTime( LocalTime.of( 0, 0 ) ); @@ -83,7 +80,7 @@ public void testLocalTimeToString() { assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); } - @Test + @ProcessorTest public void testSourceToTargetMappingForStrings() { Source src = new Source(); src.setLocalTime( LocalTime.of( 0, 0 ) ); @@ -109,7 +106,7 @@ public void testSourceToTargetMappingForStrings() { assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); } - @Test + @ProcessorTest public void testStringToDateTime() { String dateTimeAsString = "01.01.2014 00:00 UTC"; Target target = new Target(); @@ -122,7 +119,7 @@ public void testStringToDateTime() { assertThat( src.getZonedDateTime() ).isEqualTo( sourceDateTime ); } - @Test + @ProcessorTest public void testStringToLocalDateTime() { String dateTimeAsString = "01.01.2014 00:00"; Target target = new Target(); @@ -135,7 +132,7 @@ public void testStringToLocalDateTime() { assertThat( src.getLocalDateTime() ).isEqualTo( sourceDateTime ); } - @Test + @ProcessorTest public void testStringToLocalDate() { String dateTimeAsString = "01.01.2014"; Target target = new Target(); @@ -148,7 +145,7 @@ public void testStringToLocalDate() { assertThat( src.getLocalDate() ).isEqualTo( sourceDate ); } - @Test + @ProcessorTest public void testStringToLocalTime() { String dateTimeAsString = "00:00"; Target target = new Target(); @@ -161,7 +158,7 @@ public void testStringToLocalTime() { assertThat( src.getLocalTime() ).isEqualTo( sourceTime ); } - @Test + @ProcessorTest public void testTargetToSourceNullMapping() { Target target = new Target(); Source src = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -173,7 +170,7 @@ public void testTargetToSourceNullMapping() { assertThat( src.getLocalTime() ).isNull(); } - @Test + @ProcessorTest public void testTargetToSourceMappingForStrings() { Target target = new Target(); @@ -198,7 +195,7 @@ public void testTargetToSourceMappingForStrings() { assertThat( src.getLocalTime() ).isEqualTo( LocalTime.of( 0, 0 ) ); } - @Test + @ProcessorTest public void testCalendarMapping() { Source source = new Source(); ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); @@ -223,7 +220,7 @@ public void testCalendarMapping() { assertThat( source.getForCalendarConversion() ).isEqualTo( dateTime ); } - @Test + @ProcessorTest public void testZonedDateTimeToDateMapping() { TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); Source source = new Source(); @@ -248,7 +245,7 @@ public void testZonedDateTimeToDateMapping() { assertThat( source.getForDateConversionWithZonedDateTime() ).isEqualTo( dateTime ); } - @Test + @ProcessorTest public void testInstantToDateMapping() { Instant instant = Instant.ofEpochMilli( 1539366615000L ); @@ -263,7 +260,7 @@ public void testInstantToDateMapping() { assertThat( source.getForDateConversionWithInstant() ).isEqualTo( instant ); } - @Test + @ProcessorTest public void testLocalDateTimeToDateMapping() { TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); @@ -289,7 +286,7 @@ public void testLocalDateTimeToDateMapping() { assertThat( source.getForDateConversionWithLocalDateTime() ).isEqualTo( dateTime ); } - @Test + @ProcessorTest public void testLocalDateToDateMapping() { TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); @@ -313,7 +310,7 @@ public void testLocalDateToDateMapping() { assertThat( source.getForDateConversionWithLocalDate() ).isEqualTo( localDate ); } - @Test + @ProcessorTest public void testLocalDateToSqlDateMapping() { TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); @@ -337,7 +334,7 @@ public void testLocalDateToSqlDateMapping() { assertThat( source.getForSqlDateConversionWithLocalDate() ).isEqualTo( localDate ); } - @Test + @ProcessorTest public void testInstantToStringMapping() { Source source = new Source(); source.setForInstantConversionWithString( Instant.ofEpochSecond( 42L ) ); @@ -347,7 +344,7 @@ public void testInstantToStringMapping() { assertThat( periodString ).isEqualTo( "1970-01-01T00:00:42Z" ); } - @Test + @ProcessorTest public void testInstantToStringNullMapping() { Source source = new Source(); source.setForInstantConversionWithString( null ); @@ -357,7 +354,7 @@ public void testInstantToStringNullMapping() { assertThat( periodString ).isNull(); } - @Test + @ProcessorTest public void testStringToInstantMapping() { Target target = new Target(); target.setForInstantConversionWithString( "1970-01-01T00:00:00.000Z" ); @@ -367,7 +364,7 @@ public void testStringToInstantMapping() { assertThat( instant ).isEqualTo( Instant.EPOCH ); } - @Test + @ProcessorTest public void testStringToInstantNullMapping() { Target target = new Target(); target.setForInstantConversionWithString( null ); @@ -377,7 +374,7 @@ public void testStringToInstantNullMapping() { assertThat( instant ).isNull(); } - @Test + @ProcessorTest public void testPeriodToStringMapping() { Source source = new Source(); source.setForPeriodConversionWithString( Period.ofDays( 42 ) ); @@ -387,7 +384,7 @@ public void testPeriodToStringMapping() { assertThat( periodString ).isEqualTo( "P42D" ); } - @Test + @ProcessorTest public void testPeriodToStringNullMapping() { Source source = new Source(); source.setForPeriodConversionWithString( null ); @@ -397,7 +394,7 @@ public void testPeriodToStringNullMapping() { assertThat( periodString ).isNull(); } - @Test + @ProcessorTest public void testStringToPeriodMapping() { Target target = new Target(); target.setForPeriodConversionWithString( "P1Y2M3D" ); @@ -407,7 +404,7 @@ public void testStringToPeriodMapping() { assertThat( period ).isEqualTo( Period.of( 1, 2, 3 ) ); } - @Test + @ProcessorTest public void testStringToPeriodNullMapping() { Target target = new Target(); target.setForPeriodConversionWithString( null ); @@ -417,7 +414,7 @@ public void testStringToPeriodNullMapping() { assertThat( period ).isNull(); } - @Test + @ProcessorTest public void testDurationToStringMapping() { Source source = new Source(); source.setForDurationConversionWithString( Duration.ofMinutes( 42L ) ); @@ -427,7 +424,7 @@ public void testDurationToStringMapping() { assertThat( durationString ).isEqualTo( "PT42M" ); } - @Test + @ProcessorTest public void testDurationToStringNullMapping() { Source source = new Source(); source.setForDurationConversionWithString( null ); @@ -437,7 +434,7 @@ public void testDurationToStringNullMapping() { assertThat( durationString ).isNull(); } - @Test + @ProcessorTest public void testStringToDurationMapping() { Target target = new Target(); target.setForDurationConversionWithString( "PT20.345S" ); @@ -447,7 +444,7 @@ public void testStringToDurationMapping() { assertThat( duration ).isEqualTo( Duration.ofSeconds( 20L, 345000000L ) ); } - @Test + @ProcessorTest public void testStringToDurationNullMapping() { Target target = new Target(); target.setForDurationConversionWithString( null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java index ebaa271d04..5f656f2f76 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateTimeToXMLGregorianCalendarConversionTest.java @@ -7,19 +7,16 @@ import java.time.LocalDateTime; import java.util.Calendar; - import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.SourceTargetMapper; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Source; +import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.SourceTargetMapper; import org.mapstruct.ap.test.conversion.java8time.localdatetimetoxmlgregoriancalendarconversion.Target; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; import static org.assertj.core.api.Assertions.assertThat; @@ -27,10 +24,9 @@ * @author Andrei Arlou */ @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class LocalDateTimeToXMLGregorianCalendarConversionTest { - @Test + @ProcessorTest public void shouldNullCheckOnConversionToTarget() { Target target = SourceTargetMapper.INSTANCE.toTarget( new Source() ); @@ -38,7 +34,7 @@ public void shouldNullCheckOnConversionToTarget() { assertThat( target.getLocalDateTime() ).isNull(); } - @Test + @ProcessorTest public void shouldNullCheckOnConversionToSource() { Source source = SourceTargetMapper.INSTANCE.toSource( new Target() ); @@ -46,7 +42,7 @@ public void shouldNullCheckOnConversionToSource() { assertThat( source.getXmlGregorianCalendar() ).isNull(); } - @Test + @ProcessorTest public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithNanoseconds() throws DatatypeConfigurationException { LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30, 50, 9000000 ); @@ -64,7 +60,7 @@ public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithNanoseconds assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); } - @Test + @ProcessorTest public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithSeconds() throws DatatypeConfigurationException { LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30, 50 ); @@ -82,7 +78,7 @@ public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithSeconds() assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); } - @Test + @ProcessorTest public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithMinutes() throws DatatypeConfigurationException { LocalDateTime localDateTime = LocalDateTime.of( 1994, Calendar.MARCH, 5, 11, 30 ); @@ -100,7 +96,7 @@ public void shouldMapLocalDateTimeToXmlGregorianCalendarCorrectlyWithMinutes() assertThat( source.getXmlGregorianCalendar() ).isEqualTo( expectedCalendar ); } - @Test + @ProcessorTest public void shouldMapXmlGregorianCalendarToLocalDateTimeCorrectly() throws DatatypeConfigurationException { XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance() .newXMLGregorianCalendar( 1994, Calendar.MARCH, 5, 11, 30, 50, 500, diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java index 2e5c7b63e7..935e12d55d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/LocalDateToXMLGregorianCalendarConversionTest.java @@ -5,32 +5,28 @@ */ package org.mapstruct.ap.test.conversion.java8time; -import static org.assertj.core.api.Assertions.assertThat; - import java.time.LocalDate; - import javax.xml.datatype.DatatypeConstants; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Source; import org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.SourceTargetMapper; import org.mapstruct.ap.test.conversion.java8time.localdatetoxmlgregoriancalendarconversion.Target; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian */ @IssueKey("580") @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class LocalDateToXMLGregorianCalendarConversionTest { - @Test + @ProcessorTest public void shouldNullCheckOnBuiltinAndConversion() { Target target = SourceTargetMapper.INSTANCE.toTarget( new Source() ); @@ -43,7 +39,7 @@ public void shouldNullCheckOnBuiltinAndConversion() { assertThat( source.getDate() ).isNull(); } - @Test + @ProcessorTest public void shouldMapCorrectlyOnBuiltinAndConversion() throws Exception { XMLGregorianCalendar calendarDate = DatatypeFactory.newInstance().newXMLGregorianCalendarDate( 2007, diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 9f61c222db..e861497169 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.conversion.jodatime; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; @@ -16,41 +14,40 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.EnabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; -import org.mapstruct.ap.testutil.runner.EnabledOnCompiler; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests the conversion between Joda-Time types and String/Date/Calendar. * * @author Timo Eckhardt */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @IssueKey("75") public class JodaConversionTest { private Locale originalLocale; - @Before + @BeforeEach public void setDefaultLocale() { originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } - @After + @AfterEach public void tearDown() { Locale.setDefault( originalLocale ); } - @Test + @ProcessorTest public void testDateTimeToString() { Source src = new Source(); src.setDateTime( new DateTime( 2014, 1, 1, 0, 0, 0, DateTimeZone.UTC ) ); @@ -59,7 +56,7 @@ public void testDateTimeToString() { assertThat( target.getDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); } - @Test + @ProcessorTest public void testLocalDateTimeToString() { Source src = new Source(); src.setLocalDateTime( new LocalDateTime( 2014, 1, 1, 0, 0 ) ); @@ -68,7 +65,7 @@ public void testLocalDateTimeToString() { assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); } - @Test + @ProcessorTest public void testLocalDateToString() { Source src = new Source(); src.setLocalDate( new LocalDate( 2014, 1, 1 ) ); @@ -77,7 +74,7 @@ public void testLocalDateToString() { assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); } - @Test + @ProcessorTest public void testLocalTimeToString() { Source src = new Source(); src.setLocalTime( new LocalTime( 0, 0 ) ); @@ -86,11 +83,8 @@ public void testLocalTimeToString() { assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); } - @Test - @DisabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledOnJre(JRE.JAVA_8) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStrings() { Source src = new Source(); @@ -117,11 +111,8 @@ public void testSourceToTargetMappingForStrings() { assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); } - @Test - @EnabledOnCompiler({ - Compiler.JDK11, - Compiler.ECLIPSE11 - }) + @ProcessorTest + @EnabledForJreRange(min = JRE.JAVA_11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStringsJdk11() { Source src = new Source(); @@ -148,7 +139,7 @@ public void testSourceToTargetMappingForStringsJdk11() { assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); } - @Test + @ProcessorTest public void testStringToDateTime() { String dateTimeAsString = "01.01.2014 00:00 UTC"; Target target = new Target(); @@ -161,7 +152,7 @@ public void testStringToDateTime() { assertThat( src.getDateTime() ).isEqualTo( sourceDateTime ); } - @Test + @ProcessorTest public void testStringToLocalDateTime() { String dateTimeAsString = "01.01.2014 00:00"; Target target = new Target(); @@ -174,7 +165,7 @@ public void testStringToLocalDateTime() { assertThat( src.getLocalDateTime() ).isEqualTo( sourceDateTime ); } - @Test + @ProcessorTest public void testStringToLocalDate() { String dateTimeAsString = "01.01.2014"; Target target = new Target(); @@ -187,7 +178,7 @@ public void testStringToLocalDate() { assertThat( src.getLocalDate() ).isEqualTo( sourceDate ); } - @Test + @ProcessorTest public void testStringToLocalTime() { String dateTimeAsString = "00:00"; Target target = new Target(); @@ -200,7 +191,7 @@ public void testStringToLocalTime() { assertThat( src.getLocalTime() ).isEqualTo( sourceTime ); } - @Test + @ProcessorTest public void testTargetToSourceNullMapping() { Target target = new Target(); Source src = SourceTargetMapper.INSTANCE.targetToSource( target ); @@ -212,7 +203,7 @@ public void testTargetToSourceNullMapping() { assertThat( src.getLocalTime() ).isNull(); } - @Test + @ProcessorTest public void testTargetToSourceMappingForStrings() { Target target = new Target(); @@ -229,7 +220,7 @@ public void testTargetToSourceMappingForStrings() { assertThat( src.getLocalTime() ).isEqualTo( new LocalTime( 0, 0 ) ); } - @Test + @ProcessorTest public void testCalendar() { Calendar calendar = Calendar.getInstance( TimeZone.getTimeZone( "CET" ) ); DateTime dateTimeWithCalendar = new DateTime( calendar ); @@ -245,7 +236,7 @@ public void testCalendar() { assertThat( mappedSource.getDateTimeForCalendarConversion() ).isEqualTo( dateTimeWithCalendar ); } - @Test + @ProcessorTest @WithClasses({ StringToLocalDateMapper.class, SourceWithStringDate.class, TargetWithLocalDate.class }) @IssueKey("456") public void testStringToLocalDateUsingDefaultFormat() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index 1e5d275f43..d27f04374a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.conversion.lossy; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.withinPercentage; @@ -22,7 +20,6 @@ * * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ OversizedKitchenDrawerDto.class, RegularKitchenDrawerEntity.class, @@ -35,7 +32,7 @@ @IssueKey("5") public class LossyConversionTest { - @Test + @ProcessorTest public void testNoErrorCase() { CutleryInventoryDto dto = new CutleryInventoryDto(); @@ -51,7 +48,7 @@ public void testNoErrorCase() { assertThat( entity.getApproximateKnifeLength() ).isCloseTo( 3.7d, withinPercentage( 0.0001d ) ); } - @Test + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper1.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -64,7 +61,7 @@ public void testNoErrorCase() { public void testConversionFromLongToInt() { } - @Test + @ProcessorTest @WithClasses(KitchenDrawerMapper2.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @@ -77,7 +74,7 @@ public void testConversionFromLongToInt() { public void testConversionFromBigIntegerToInteger() { } - @Test + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper3.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -90,7 +87,7 @@ public void testConversionFromBigIntegerToInteger() { public void test2StepConversionFromBigIntegerToLong() { } - @Test + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper4.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -103,7 +100,7 @@ public void test2StepConversionFromBigIntegerToLong() { public void testConversionFromDoubleToFloat() { } - @Test + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper5.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -116,7 +113,7 @@ public void testConversionFromDoubleToFloat() { public void testConversionFromBigDecimalToFloat() { } - @Test + @ProcessorTest @WithClasses(KitchenDrawerMapper6.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @@ -128,7 +125,7 @@ public void testConversionFromBigDecimalToFloat() { public void test2StepConversionFromDoubleToFloat() { } - @Test + @ProcessorTest @WithClasses(ListMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @@ -140,7 +137,7 @@ public void test2StepConversionFromDoubleToFloat() { public void testListElementConversion() { } - @Test + @ProcessorTest @WithClasses(MapMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java index 0f90586007..7c4035417b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/BooleanConversionTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.conversion.nativetypes; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ BooleanSource.class, BooleanTarget.class, BooleanMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class BooleanConversionTest { - @Test + @ProcessorTest public void shouldApplyBooleanConversion() { BooleanSource source = new BooleanSource(); source.setB( true ); @@ -34,7 +31,7 @@ public void shouldApplyBooleanConversion() { assertThat( target.getBool() ).isEqualTo( Boolean.TRUE ); } - @Test + @ProcessorTest public void shouldApplyReverseBooleanConversion() { BooleanTarget target = new BooleanTarget(); target.setB( Boolean.TRUE ); @@ -47,7 +44,7 @@ public void shouldApplyReverseBooleanConversion() { assertThat( source.getBool() ).isEqualTo( true ); } - @Test + @ProcessorTest @IssueKey( "229" ) public void wrapperToPrimitiveIsNullSafe() { BooleanTarget target = new BooleanTarget(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java index 29b8b76484..def3b45ac5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/CharConversionTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.conversion.nativetypes; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ CharSource.class, CharTarget.class, CharMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class CharConversionTest { - @Test + @ProcessorTest public void shouldApplyCharConversion() { CharSource source = new CharSource(); source.setC( 'G' ); @@ -32,7 +29,7 @@ public void shouldApplyCharConversion() { assertThat( target.getC() ).isEqualTo( Character.valueOf( 'G' ) ); } - @Test + @ProcessorTest public void shouldApplyReverseCharConversion() { CharTarget target = new CharTarget(); target.setC( 'G' ); @@ -43,7 +40,7 @@ public void shouldApplyReverseCharConversion() { assertThat( source.getC() ).isEqualTo( 'G' ); } - @Test + @ProcessorTest @IssueKey( "229" ) public void wrapperToPrimitiveIsNullSafe() { CharTarget target = new CharTarget(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java index bba6b9fc27..61be21e797 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberConversionTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.conversion.nativetypes; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ ByteSource.class, @@ -40,10 +38,9 @@ DoubleWrapperTarget.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NumberConversionTest { - @Test + @ProcessorTest public void shouldApplyByteConversions() { ByteSource source = new ByteSource(); source.setB( (byte) 1 ); @@ -76,7 +73,7 @@ public void shouldApplyByteConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyByteWrapperConversions() { ByteWrapperSource source = new ByteWrapperSource(); source.setB( (byte) 1 ); @@ -109,7 +106,7 @@ public void shouldApplyByteWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyShortConversions() { ShortSource source = new ShortSource(); source.setB( (short) 1 ); @@ -142,7 +139,7 @@ public void shouldApplyShortConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyShortWrapperConversions() { ShortWrapperSource source = new ShortWrapperSource(); source.setB( (short) 1 ); @@ -175,7 +172,7 @@ public void shouldApplyShortWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyIntConversions() { IntSource source = new IntSource(); source.setB( 1 ); @@ -208,7 +205,7 @@ public void shouldApplyIntConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyIntWrapperConversions() { IntWrapperSource source = new IntWrapperSource(); source.setB( 1 ); @@ -241,7 +238,7 @@ public void shouldApplyIntWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyLongConversions() { LongSource source = new LongSource(); source.setB( 1 ); @@ -274,7 +271,7 @@ public void shouldApplyLongConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyLongWrapperConversions() { LongWrapperSource source = new LongWrapperSource(); source.setB( (long) 1 ); @@ -307,7 +304,7 @@ public void shouldApplyLongWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyFloatConversions() { FloatSource source = new FloatSource(); source.setB( 1 ); @@ -340,7 +337,7 @@ public void shouldApplyFloatConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyFloatWrapperConversions() { FloatWrapperSource source = new FloatWrapperSource(); source.setB( 1f ); @@ -373,7 +370,7 @@ public void shouldApplyFloatWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyDoubleConversions() { DoubleSource source = new DoubleSource(); source.setB( 1 ); @@ -406,7 +403,7 @@ public void shouldApplyDoubleConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest public void shouldApplyDoubleWrapperConversions() { DoubleWrapperSource source = new DoubleWrapperSource(); source.setB( 1d ); @@ -439,7 +436,7 @@ public void shouldApplyDoubleWrapperConversions() { assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); } - @Test + @ProcessorTest @IssueKey( "229" ) public void wrapperToPrimitiveIsNullSafe() { assertThat( SourceTargetMapper.INSTANCE.sourceToTarget( new ByteWrapperSource() ) ).isNotNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index 9b92182f6f..ea1dd0da60 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -5,13 +5,6 @@ */ package org.mapstruct.ap.test.conversion.numbers; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; - import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; @@ -20,6 +13,11 @@ import java.util.Locale; import java.util.Map; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -28,23 +26,22 @@ Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NumberFormatConversionTest { private Locale originalLocale; - @Before + @BeforeEach public void setDefaultLocale() { originalLocale = Locale.getDefault(); Locale.setDefault( Locale.ENGLISH ); } - @After + @AfterEach public void tearDown() { Locale.setDefault( originalLocale ); } - @Test + @ProcessorTest public void shouldApplyStringConversions() { Source source = new Source(); source.setI( 1 ); @@ -85,7 +82,7 @@ public void shouldApplyStringConversions() { assertThat( target.getBigInteger1() ).isEqualTo( "1.23456789E12" ); } - @Test + @ProcessorTest public void shouldApplyReverseStringConversions() { Target target = new Target(); target.setI( "1.00" ); @@ -126,7 +123,7 @@ public void shouldApplyReverseStringConversions() { assertThat( source.getBigInteger1() ).isEqualTo( new BigInteger( "1234567890000" ) ); } - @Test + @ProcessorTest public void shouldApplyStringConversionsToIterables() { List target = SourceTargetMapper.INSTANCE.sourceToTarget( Arrays.asList( 2f ) ); @@ -139,7 +136,7 @@ public void shouldApplyStringConversionsToIterables() { assertThat( source ).isEqualTo( Arrays.asList( 2.00f ) ); } - @Test + @ProcessorTest public void shouldApplyStringConversionsToMaps() { Map source1 = new HashMap<>(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java index 5a3a968c1e..42c72e0727 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/precedence/ConversionTest.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.conversion.precedence; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, Target.class, SourceTargetMapper.class, IntegerStringMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConversionTest { - @Test + @ProcessorTest public void shouldInvokeMappingMethodInsteadOfConversion() { Source source = new Source(); source.setFoo( 42 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java index bc98fff256..994b47957b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java @@ -5,12 +5,10 @@ */ package org.mapstruct.ap.test.conversion.string; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -20,16 +18,15 @@ Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class StringConversionTest { private static final String STRING_CONSTANT = "String constant"; - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( SourceTargetMapper.class ); - @Test + @ProcessorTest public void shouldApplyStringConversions() { Source source = new Source(); source.setB( (byte) 1 ); @@ -72,7 +69,7 @@ public void shouldApplyStringConversions() { assertThat( target.getSb() ).isEqualTo( "SB" ); } - @Test + @ProcessorTest public void shouldApplyReverseStringConversions() { Target target = new Target(); target.setB( "1" ); @@ -115,7 +112,7 @@ public void shouldApplyReverseStringConversions() { assertThat( source.getSb().toString() ).isEqualTo( "SB" ); } - @Test + @ProcessorTest @IssueKey( "328" ) public void stringShouldBeMappedToObjectByReference() { Target target = new Target(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java index 59d59eb987..4e70581983 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratorTest.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.decorator; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Calendar; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for the application of decorators. @@ -32,10 +29,9 @@ AddressDto.class }) @IssueKey("163") -@RunWith(AnnotationProcessorTestRunner.class) public class DecoratorTest { - @Test + @ProcessorTest @WithClasses({ PersonMapper.class, PersonMapperDecorator.class @@ -56,7 +52,7 @@ public void shouldInvokeDecoratorMethods() { assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest @WithClasses({ PersonMapper.class, PersonMapperDecorator.class @@ -73,7 +69,7 @@ public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { assertThat( addressDto.getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest @WithClasses({ PersonMapper.class, PersonMapperDecorator.class @@ -91,7 +87,7 @@ public void shouldDelegateNonDecoratedVoidMethodsToDefaultImplementation() { assertThat( address.getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest @WithClasses({ AnotherPersonMapper.class, AnotherPersonMapperDecorator.class @@ -112,7 +108,7 @@ public void shouldApplyDecoratorWithDefaultConstructor() { assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest @WithClasses({ YetAnotherPersonMapper.class, YetAnotherPersonMapperDecorator.class @@ -135,7 +131,7 @@ public void shouldApplyDelegateToClassBasedMapper() { } @IssueKey("173") - @Test + @ProcessorTest @WithClasses({ Person2Mapper.class, Person2MapperDecorator.class, @@ -171,7 +167,7 @@ public void shouldApplyCustomMappers() { assertThat( personDto.getSportsClub().getName() ).isEqualTo( "SC Duckburg" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousPersonMapper.class, ErroneousPersonMapperDecorator.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index ba1f6012bc..d00368dfd4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -5,32 +5,29 @@ */ package org.mapstruct.ap.test.decorator.jsr330; -import static java.lang.System.lineSeparator; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Calendar; - import javax.inject.Inject; import javax.inject.Named; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for the application of decorators using component model jsr330. * @@ -45,37 +42,32 @@ PersonMapperDecorator.class }) @IssueKey("592") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = Jsr330DecoratorTest.class) @Configuration public class Jsr330DecoratorTest { - private final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Inject @Named private PersonMapper personMapper; private ConfigurableApplicationContext context; - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } - - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldInvokeDecoratorMethods() { Calendar birthday = Calendar.getInstance(); birthday.set( 1928, Calendar.MAY, 23 ); @@ -89,7 +81,7 @@ public void shouldInvokeDecoratorMethods() { assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { Address address = new Address( "42 Ocean View Drive" ); @@ -100,7 +92,7 @@ public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { } @IssueKey("664") - @Test + @ProcessorTest public void hasSingletonAnnotation() { // check the decorator generatedSource.forMapper( PersonMapper.class ).content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java index feffc8c52c..dc834683e3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java @@ -5,27 +5,25 @@ */ package org.mapstruct.ap.test.decorator.spring.constructor; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Calendar; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for the application of decorators using component model spring. * @@ -40,7 +38,6 @@ PersonMapperDecorator.class }) @IssueKey("592") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = SpringDecoratorTest.class) @Configuration public class SpringDecoratorTest { @@ -49,20 +46,20 @@ public class SpringDecoratorTest { private PersonMapper personMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldInvokeDecoratorMethods() { //given Calendar birthday = Calendar.getInstance(); @@ -79,7 +76,7 @@ public void shouldInvokeDecoratorMethods() { assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { //given Address address = new Address( "42 Ocean View Drive" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java index d882dfc6db..1b81ed8c48 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java @@ -5,27 +5,25 @@ */ package org.mapstruct.ap.test.decorator.spring.field; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Calendar; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for the application of decorators using component model spring. * @@ -40,7 +38,6 @@ PersonMapperDecorator.class }) @IssueKey("592") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = SpringDecoratorTest.class) @Configuration public class SpringDecoratorTest { @@ -49,20 +46,20 @@ public class SpringDecoratorTest { private PersonMapper personMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldInvokeDecoratorMethods() { //given Calendar birthday = Calendar.getInstance(); @@ -79,7 +76,7 @@ public void shouldInvokeDecoratorMethods() { assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); } - @Test + @ProcessorTest public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { //given Address address = new Address( "42 Ocean View Drive" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java index b6b19ea88d..2c860f05f7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultcomponentmodel/DefaultComponentModelMapperTest.java @@ -5,29 +5,26 @@ */ package org.mapstruct.ap.test.defaultcomponentmodel; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Filip Hrisafov */ @IssueKey("2277") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Source.class, Target.class, }) public class DefaultComponentModelMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ InstanceIterableMapper.class, InstanceMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java index e834df3e3f..114d762c03 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/defaultvalue/DefaultValueTest.java @@ -5,27 +5,24 @@ */ package org.mapstruct.ap.test.defaultvalue; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.defaultvalue.other.Continent; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("600") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CountryEntity.class, CountryDts.class, Continent.class }) public class DefaultValueTest { - @Test + @ProcessorTest @WithClasses({ Region.class, CountryMapper.class @@ -55,7 +52,7 @@ public void shouldDefaultValueAndUseConstantExpression() { assertThat( countryDts.getContinent() ).isEqualTo( Continent.EUROPE ); } - @Test + @ProcessorTest @WithClasses({ Region.class, CountryMapper.class @@ -76,7 +73,7 @@ public void shouldIgnoreDefaultValue() { assertThat( countryDts.getContinent() ).isEqualTo( Continent.NORTH_AMERICA ); } - @Test + @ProcessorTest @WithClasses({ Region.class, CountryMapper.class @@ -94,7 +91,7 @@ public void shouldHandleUpdateMethodsFromDtsToEntity() { assertThat( countryEntity.getContinent() ).isEqualTo( Continent.EUROPE ); } - @Test + @ProcessorTest @WithClasses({ Region.class, CountryMapper.class @@ -113,7 +110,7 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { assertThat( target.getContinent() ).isEqualTo( Continent.EUROPE ); } - @Test + @ProcessorTest @WithClasses({ ErroneousMapper.class, Region.class, @@ -136,7 +133,7 @@ public void shouldHandleUpdateMethodsFromEntityToEntity() { public void errorOnDefaultValueAndConstant() { } - @Test + @ProcessorTest @WithClasses({ ErroneousMapper2.class, Region.class, @@ -159,7 +156,7 @@ public void errorOnDefaultValueAndConstant() { public void errorOnDefaultValueAndExpression() { } - @Test + @ProcessorTest @IssueKey("2214") @WithClasses({ CountryMapperMultipleSources.class, @@ -173,7 +170,7 @@ public void shouldBeAbleToDetermineDefaultValueBasedOnOnlyTargetType() { assertThat( target.getCode() ).isEqualTo( "CH" ); } - @Test + @ProcessorTest @IssueKey("2220") @WithClasses({ ErroneousMissingSourceMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java index d9f611d6d4..cbb0959b89 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/GraphAnalyzerTest.java @@ -5,16 +5,16 @@ */ package org.mapstruct.ap.test.dependency; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.util.Strings; +import static org.assertj.core.api.Assertions.assertThat; + /** * Unit test for {@link GraphAnalyzer}. * diff --git a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java index 0a2ed604cf..cdf4cf6e97 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/dependency/OrderingTest.java @@ -5,17 +5,15 @@ */ package org.mapstruct.ap.test.dependency; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.Mapping; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for ordering mapped attributes by means of {@link Mapping#dependsOn()}. @@ -23,10 +21,9 @@ * @author Gunnar Morling */ @WithClasses({ Person.class, PersonDto.class, Address.class, AddressDto.class, AddressMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class OrderingTest { - @Test + @ProcessorTest @IssueKey("304") public void shouldApplyChainOfDependencies() { Address source = new Address(); @@ -40,7 +37,7 @@ public void shouldApplyChainOfDependencies() { assertThat( target.getFullName() ).isEqualTo( "Bob J. McRobb" ); } - @Test + @ProcessorTest @IssueKey("304") public void shouldApplySeveralDependenciesConfiguredForOneProperty() { Person source = new Person(); @@ -54,7 +51,7 @@ public void shouldApplySeveralDependenciesConfiguredForOneProperty() { assertThat( target.getFullName() ).isEqualTo( "Bob J. McRobb" ); } - @Test + @ProcessorTest @IssueKey("304") @WithClasses(ErroneousAddressMapperWithCyclicDependency.class) @ExpectedCompilationOutcome( @@ -71,7 +68,7 @@ public void shouldApplySeveralDependenciesConfiguredForOneProperty() { public void shouldReportErrorIfDependenciesContainCycle() { } - @Test + @ProcessorTest @IssueKey("304") @WithClasses(ErroneousAddressMapperWithUnknownPropertyInDependsOn.class) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java index 4f4454bcea..e61bd1cb2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java @@ -5,35 +5,32 @@ */ package org.mapstruct.ap.test.destination; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + /** * @author Christophe Labouisse on 27/05/2015. */ -@RunWith(AnnotationProcessorTestRunner.class) public class DestinationClassNameTest { - @Test + @ProcessorTest @WithClasses({ DestinationClassNameMapper.class }) public void shouldGenerateRightName() { DestinationClassNameMapper instance = DestinationClassNameMapper.INSTANCE; assertThat( instance.getClass().getSimpleName() ).isEqualTo( "MyDestinationClassNameMapperCustomImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationClassNameWithJsr330Mapper.class }) public void shouldNotGenerateSpi() throws Exception { Class clazz = DestinationClassNameWithJsr330Mapper.class; try { Mappers.getMapper( clazz ); - Assert.fail( "Should have thrown an ClassNotFoundException" ); + fail( "Should have thrown an ClassNotFoundException" ); } catch ( RuntimeException e ) { assertThat( e.getCause() ).isNotNull() @@ -46,7 +43,7 @@ public void shouldNotGenerateSpi() throws Exception { assertThat( instance.getClass().getSimpleName() ).isEqualTo( "DestinationClassNameWithJsr330MapperJsr330Impl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationClassNameMapperConfig.class, DestinationClassNameMapperWithConfig.class }) public void shouldGenerateRightNameWithConfig() { DestinationClassNameMapperWithConfig instance = DestinationClassNameMapperWithConfig.INSTANCE; @@ -54,7 +51,7 @@ public void shouldGenerateRightNameWithConfig() { .isEqualTo( "MyDestinationClassNameMapperWithConfigConfigImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationClassNameMapperConfig.class, DestinationClassNameMapperWithConfigOverride.class }) public void shouldGenerateRightNameWithConfigOverride() { DestinationClassNameMapperWithConfigOverride instance = DestinationClassNameMapperWithConfigOverride.INSTANCE; @@ -62,7 +59,7 @@ public void shouldGenerateRightNameWithConfigOverride() { .isEqualTo( "CustomDestinationClassNameMapperWithConfigOverrideMyImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationClassNameMapperDecorated.class, DestinationClassNameMapperDecorator.class }) public void shouldGenerateRightNameWithDecorator() { DestinationClassNameMapperDecorated instance = DestinationClassNameMapperDecorated.INSTANCE; @@ -73,7 +70,7 @@ public void shouldGenerateRightNameWithDecorator() { .isEqualTo( "MyDestinationClassNameMapperDecoratedCustomImpl_" ); } - @Test + @ProcessorTest @WithClasses({ AbstractDestinationClassNameMapper.class, AbstractDestinationPackageNameMapper.class }) public void shouldWorkWithAbstractClasses() { AbstractDestinationClassNameMapper mapper1 = AbstractDestinationClassNameMapper.INSTANCE; diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java index 8f55dedc9b..63c7ece6d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.destination; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Christophe Labouisse on 27/05/2015. */ @IssueKey( "556" ) -@RunWith(AnnotationProcessorTestRunner.class) public class DestinationPackageNameTest { - @Test + @ProcessorTest @WithClasses({ DestinationPackageNameMapper.class }) public void shouldGenerateInRightPackage() { DestinationPackageNameMapper instance = DestinationPackageNameMapper.INSTANCE; @@ -27,7 +24,7 @@ public void shouldGenerateInRightPackage() { .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationPackageNameMapperWithSuffix.class }) public void shouldGenerateInRightPackageWithSuffix() { DestinationPackageNameMapperWithSuffix instance = DestinationPackageNameMapperWithSuffix.INSTANCE; @@ -35,7 +32,7 @@ public void shouldGenerateInRightPackageWithSuffix() { .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperWithSuffixMyImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationPackageNameMapperConfig.class, DestinationPackageNameMapperWithConfig.class }) public void shouldGenerateRightSuffixWithConfig() { DestinationPackageNameMapperWithConfig instance = DestinationPackageNameMapperWithConfig.INSTANCE; @@ -43,7 +40,7 @@ public void shouldGenerateRightSuffixWithConfig() { .isEqualTo( "org.mapstruct.ap.test.destination.dest.DestinationPackageNameMapperWithConfigImpl" ); } - @Test + @ProcessorTest @WithClasses({ DestinationPackageNameMapperConfig.class, DestinationPackageNameMapperWithConfigOverride.class }) public void shouldGenerateRightSuffixWithConfigOverride() { DestinationPackageNameMapperWithConfigOverride instance = @@ -54,7 +51,7 @@ public void shouldGenerateRightSuffixWithConfigOverride() { ); } - @Test + @ProcessorTest @WithClasses({ DestinationPackageNameMapperDecorated.class, DestinationPackageNameMapperDecorator.class }) public void shouldGenerateRightSuffixWithDecorator() { DestinationPackageNameMapperDecorated instance = DestinationPackageNameMapperDecorated.INSTANCE; diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java index 3887cd4a46..99fd2b98cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousannotatedfactorymethod/AmbiguousAnnotatedFactoryTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousannotatedfactorymethod; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Remo Meier @@ -20,10 +18,9 @@ Bar.class, Foo.class, AmbiguousBarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class AmbiguousAnnotatedFactoryTest { - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java index dbce2ab5b2..b9ae5b8ffa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousfactorymethod/FactoryTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousfactorymethod; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.erroneous.ambiguousfactorymethod.a.BarFactory; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Sjaak Derksen @@ -23,10 +21,9 @@ Bar.class, Foo.class, BarFactory.class, Source.class, SourceTargetMapperAndBarFactory.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class FactoryTest { - @Test + @ProcessorTest @IssueKey("81") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java index 3c4bd00a7e..c3fa15b244 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/ambiguousmapping/AmbiguousMapperTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.erroneous.ambiguousmapping; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("2156") -@RunWith(AnnotationProcessorTestRunner.class) public class AmbiguousMapperTest { - @Test + @ProcessorTest @WithClasses( ErroneousWithAmbiguousMethodsMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -38,7 +35,7 @@ public class AmbiguousMapperTest { public void testErrorMessageForAmbiguous() { } - @Test + @ProcessorTest @WithClasses( ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -63,7 +60,7 @@ public void testErrorMessageForAmbiguous() { public void testErrorMessageForManyAmbiguous() { } - @Test + @ProcessorTest @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses( ErroneousWithMoreThanFiveAmbiguousMethodsMapper.class) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java index 50d5b7c82b..8a5ffefe6d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/annotationnotfound/AnnotationNotFoundTest.java @@ -7,14 +7,12 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Test for (custom / external) annotation that is not on class path @@ -22,10 +20,9 @@ * @author Sjaak Derksen */ @WithClasses( { Source.class, Target.class, ErroneousMapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class AnnotationNotFoundTest { - @Test + @ProcessorTest @IssueKey( "298" ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java index bc36e2af42..0d040f7366 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/attributereference/ErroneousMappingsTest.java @@ -7,14 +7,12 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Test for using unknown attributes in {@code @Mapping}. @@ -22,10 +20,9 @@ * @author Gunnar Morling */ @WithClasses({ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousMappingsTest { - @Test + @ProcessorTest @IssueKey("11") @WithClasses( { ErroneousMapper.class, AnotherTarget.class } ) @ExpectedCompilationOutcome( @@ -58,7 +55,7 @@ public class ErroneousMappingsTest { public void shouldFailToGenerateMappings() { } - @Test + @ProcessorTest @WithClasses( { ErroneousMapper1.class, DummySource.class } ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -72,7 +69,7 @@ public void shouldFailToGenerateMappings() { public void shouldFailToGenerateMappingsErrorOnMandatoryParameterName() { } - @Test + @ProcessorTest @WithClasses( { ErroneousMapper2.class } ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java index bc270d446e..f3f6e2417a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/misbalancedbraces/MisbalancedBracesTest.java @@ -7,15 +7,13 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Test for making sure that expressions with too many closing braces are passed through, letting the compiler raise an @@ -25,12 +23,11 @@ */ @WithClasses({ MapperWithMalformedExpression.class, Source.class, Target.class }) @DisableCheckstyle -@RunWith(AnnotationProcessorTestRunner.class) public class MisbalancedBracesTest { // the compiler messages due to the additional closing brace differ between JDK and Eclipse, hence we can only // assert on the line number but not the message - @Test + @ProcessorTest @IssueKey("1056") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java index 627478d1c0..43d7dfca5b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/propertymapping/ErroneousPropertyMappingTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.erroneous.propertymapping; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @IssueKey("1504") @WithClasses({ Source.class, Target.class, UnmappableClass.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousPropertyMappingTest { - @Test + @ProcessorTest @WithClasses(ErroneousMapper1.class) @IssueKey("1504") @ExpectedCompilationOutcome( @@ -34,7 +31,7 @@ public class ErroneousPropertyMappingTest { public void testUnmappableSourceProperty() { } - @Test + @ProcessorTest @WithClasses(ErroneousMapper2.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -48,7 +45,7 @@ public void testUnmappableSourceProperty() { public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { } - @Test + @ProcessorTest @WithClasses(ErroneousMapper3.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -61,7 +58,7 @@ public void testUnmappableSourcePropertyWithNoSourceDefinedInMapping() { public void testUnmappableConstantAssignment() { } - @Test + @ProcessorTest @WithClasses(ErroneousMapper4.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java index 2a1b2bae28..a045d16dfa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/typemismatch/ErroneousMappingsTest.java @@ -7,14 +7,12 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Tests failures expected for unmappable attributes. @@ -22,10 +20,9 @@ * @author Gunnar Morling */ @WithClasses({ ErroneousMapper.class, Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousMappingsTest { - @Test + @ProcessorTest @IssueKey("6") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java index 2364381efe..212893052a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/exceptions/ExceptionTest.java @@ -11,13 +11,13 @@ import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.exceptions.imports.TestException1; import org.mapstruct.ap.test.exceptions.imports.TestExceptionBase; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @@ -32,105 +32,115 @@ TestExceptionBase.class, TestException1.class, TestException2.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class ExceptionTest { - @Test( expected = RuntimeException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowRuntimeInBeanMapping() throws TestException2, ParseException { Source source = new Source(); source.setSize( 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.sourceToTarget( source ); + assertThatThrownBy( () -> sourceTargetMapper.sourceToTarget( source ) ) + .isInstanceOf( RuntimeException.class ); } - @Test( expected = TestException2.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestException2InBeanMapping() throws TestException2, ParseException { Source source = new Source(); source.setSize( 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.sourceToTarget( source ); + assertThatThrownBy( () -> sourceTargetMapper.sourceToTarget( source ) ) + .isInstanceOf( TestException2.class ); } - @Test( expected = ParseException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestParseExceptionInBeanMappingDueToTypeConverion() throws TestException2, ParseException { Source source = new Source(); source.setDate( "nonsense" ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.sourceToTarget( source ); + assertThatThrownBy( () -> sourceTargetMapper.sourceToTarget( source ) ) + .isInstanceOf( ParseException.class ); } - @Test( expected = RuntimeException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowRuntimeInIterableMapping() throws TestException2 { List source = new ArrayList<>(); source.add( 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerListToLongList( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerListToLongList( source ) ) + .isInstanceOf( RuntimeException.class ); } - @Test( expected = TestException2.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestException2InIterableMapping() throws TestException2 { List source = new ArrayList<>(); source.add( 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerListToLongList( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerListToLongList( source ) ) + .isInstanceOf( TestException2.class ); } - @Test( expected = RuntimeException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowRuntimeInMapKeyMapping() throws TestException2 { Map source = new HashMap<>(); source.put( 1, "test" ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerKeyMapToLongKeyMap( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerKeyMapToLongKeyMap( source ) ) + .isInstanceOf( RuntimeException.class ); } - @Test( expected = TestException2.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestException2InMapKeyMapping() throws TestException2 { Map source = new HashMap<>(); source.put( 2, "test" ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerKeyMapToLongKeyMap( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerKeyMapToLongKeyMap( source ) ) + .isInstanceOf( TestException2.class ); } - @Test( expected = RuntimeException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowRuntimeInMapValueMapping() throws TestException2 { Map source = new HashMap<>(); source.put( "test", 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerValueMapToLongValueMap( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerValueMapToLongValueMap( source ) ) + .isInstanceOf( RuntimeException.class ); } - @Test( expected = TestException2.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestException2InMapValueMapping() throws TestException2 { Map source = new HashMap<>(); source.put( "test", 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.integerValueMapToLongValueMap( source ); + assertThatThrownBy( () -> sourceTargetMapper.integerValueMapToLongValueMap( source ) ) + .isInstanceOf( TestException2.class ); } - @Test( expected = RuntimeException.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowRuntimeInBeanMappingViaBaseException() throws TestExceptionBase { Source source = new Source(); source.setSize( 1 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.sourceToTargetViaBaseException( source ); + assertThatThrownBy( () -> sourceTargetMapper.sourceToTargetViaBaseException( source ) ) + .isInstanceOf( RuntimeException.class ); } - @Test( expected = TestException2.class ) + @ProcessorTest @IssueKey( "198" ) public void shouldThrowTestException2InBeanMappingViaBaseException() throws TestExceptionBase { Source source = new Source(); source.setSize( 2 ); SourceTargetMapper sourceTargetMapper = SourceTargetMapper.INSTANCE; - sourceTargetMapper.sourceToTargetViaBaseException( source ); + assertThatThrownBy( () -> sourceTargetMapper.sourceToTargetViaBaseException( source ) ) + .isInstanceOf( TestException2.class ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java index 1480c146fa..58cb0a1fcf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/FactoryTest.java @@ -5,15 +5,11 @@ */ package org.mapstruct.ap.test.factories; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.factories.a.BarFactory; import org.mapstruct.ap.test.factories.targettype.Bar9Base; import org.mapstruct.ap.test.factories.targettype.Bar9Child; @@ -21,8 +17,10 @@ import org.mapstruct.ap.test.factories.targettype.Foo9Base; import org.mapstruct.ap.test.factories.targettype.Foo9Child; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen @@ -33,9 +31,8 @@ org.mapstruct.ap.test.factories.b.BarFactory.class, org.mapstruct.ap.test.factories.c.BarFactory.class, Bar9Factory.class, Source.class, SourceTargetMapperAndBar2Factory.class, Target.class, CustomList.class, CustomListImpl.class, CustomMap.class, CustomMapImpl.class, FactoryCreatable.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class FactoryTest { - @Test + @ProcessorTest public void shouldUseThreeFactoryMethods() { Target target = SourceTargetMapperAndBar2Factory.INSTANCE.sourceToTarget( createSource() ); @@ -94,7 +91,7 @@ private Source createSource() { return source; } - @Test + @ProcessorTest @IssueKey( "136" ) @WithClasses( { GenericFactory.class, SourceTargetMapperWithGenericFactory.class } ) public void shouldUseGenericFactory() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java index 5ea82a5096..41140a00a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/assignment/ParameterAssigmentFactoryTest.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.factories.assignment; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Remo Meier */ @WithClasses( { Bar5.class, Foo5A.class, Foo5B.class, Bar6.class, Foo6A.class, Foo6B.class, Bar7.class, Foo7A.class, Foo7B.class, Bar5Factory.class, Bar6Factory.class, Bar7Factory.class, ParameterAssignmentFactoryTestMapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class ParameterAssigmentFactoryTest { - @Test + @ProcessorTest public void shouldUseFactoryMethodWithMultipleParams() { Foo5A foo5a = new Foo5A(); foo5a.setPropB( "foo5a" ); @@ -38,7 +35,7 @@ public void shouldUseFactoryMethodWithMultipleParams() { assertThat( bar5.getSomeTypeProp1() ).isEqualTo( "foo5b" ); } - @Test + @ProcessorTest public void shouldUseFactoryMethodWithFirstParamsOfMappingMethod() { Foo6A foo6a = new Foo6A(); foo6a.setPropB( "foo6a" ); @@ -54,7 +51,7 @@ public void shouldUseFactoryMethodWithFirstParamsOfMappingMethod() { assertThat( bar6.getSomeTypeProp0() ).isEqualTo( "FOO6A" ); } - @Test + @ProcessorTest public void shouldUseFactoryMethodWithSecondParamsOfMappingMethod() { Foo7A foo7a = new Foo7A(); foo7a.setPropB( "foo7a" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java index 226c2ca8b9..ac84e555d3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/qualified/QualifiedFactoryTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.factories.qualified; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Remo Meier */ @WithClasses( { Foo10.class, Bar10.class, TestQualifier.class, Bar10Factory.class, QualifiedFactoryTestMapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class QualifiedFactoryTest { - @Test + @ProcessorTest public void shouldUseFactoryWithoutQualifier() { Foo10 foo10 = new Foo10(); foo10.setProp( "foo10" ); @@ -31,7 +28,7 @@ public void shouldUseFactoryWithoutQualifier() { assertThat( bar10.getSomeTypeProp() ).isEqualTo( "foo10" ); } - @Test + @ProcessorTest public void shouldUseFactoryWithQualifier() { Foo10 foo10 = new Foo10(); foo10.setProp( "foo10" ); @@ -43,7 +40,7 @@ public void shouldUseFactoryWithQualifier() { assertThat( bar10.getSomeTypeProp() ).isEqualTo( "foo10" ); } - @Test + @ProcessorTest public void shouldUseFactoryWithQualifierName() { Foo10 foo10 = new Foo10(); foo10.setProp( "foo10" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java index 0d39e433c0..ce140ee93c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/factories/targettype/ProductTypeFactoryTest.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.factories.targettype; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Remo Meier */ @WithClasses( { Foo9Base.class, Foo9Child.class, Bar9Base.class, Bar9Child.class, Bar9Factory.class, TargetTypeFactoryTestMapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class ProductTypeFactoryTest { - @Test + @ProcessorTest public void shouldUseFactoryTwoCreateBaseClassDueToTargetType() { Foo9Base foo9 = new Foo9Base(); foo9.setProp( "foo9" ); @@ -32,7 +29,7 @@ public void shouldUseFactoryTwoCreateBaseClassDueToTargetType() { assertThat( bar9.getSomeTypeProp() ).isEqualTo( "FOO9" ); } - @Test + @ProcessorTest public void shouldUseFactoryTwoCreateChildClassDueToTargetType() { Foo9Child foo9 = new Foo9Child(); foo9.setProp( "foo9" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java index d215a00ab5..8e594969fc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/fields/FieldsMappingTest.java @@ -5,24 +5,21 @@ */ package org.mapstruct.ap.test.fields; -import static org.assertj.core.api.Assertions.assertThat; - import org.assertj.core.util.Lists; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey( "557" ) @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) public class FieldsMappingTest { - @Test + @ProcessorTest public void shouldMapSourceToTarget() { Source source = new Source(); source.normalInt = 4; @@ -41,7 +38,7 @@ public void shouldMapSourceToTarget() { assertThat( target.fieldWithMethods ).isEqualTo( "4111" ); } - @Test + @ProcessorTest public void shouldMapTargetToSource() { Target target = new Target(); target.finalInt = "40"; diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index 711d6d467a..87a22931ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -5,12 +5,12 @@ */ package org.mapstruct.ap.test.gem; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.MappingConstants; import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test constants values * diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java index 3da35b91fb..0c92fc6bbe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.gem; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.InjectionStrategy; import org.mapstruct.MappingInheritanceStrategy; @@ -25,6 +23,8 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for manually created gems on enumeration types * diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java index 3f1ca3a818..091c59f78d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/GenericsTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.generics; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian @@ -24,10 +22,9 @@ SourceTargetMapper.class, TargetTo.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class GenericsTest { - @Test + @ProcessorTest @IssueKey("574") public void mapsIdCorrectly() { TargetTo target = new TargetTo(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java index 30b961432c..4caa6f5712 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/generics/genericsupertype/MapperWithGenericSuperClassTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.generics.genericsupertype; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Gunnar Morling @@ -24,10 +22,9 @@ MapperBase.class, VesselSearchResultMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class MapperWithGenericSuperClassTest { - @Test + @ProcessorTest public void canCreateImplementationForMapperWithGenericSuperClass() { Vessel vessel = new Vessel(); vessel.setName( "Pacific Queen" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java index 417a0aa26a..3bafb776a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/IgnorePropertyTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.ignore; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for ignoring properties during the mapping. @@ -24,10 +22,9 @@ * @author Gunnar Morling */ @WithClasses({ Animal.class, AnimalDto.class, AnimalMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class IgnorePropertyTest { - @Test + @ProcessorTest @IssueKey("72") public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { Animal animal = new Animal( "Bruno", 100, 23, "black" ); @@ -43,7 +40,7 @@ public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { assertThat( animalDto.publicColor ).isNull(); } - @Test + @ProcessorTest @IssueKey("1392") public void shouldIgnoreAllTargetPropertiesWithNoUnmappedTargetWarnings() { Animal animal = new Animal( "Bruno", 100, 23, "black" ); @@ -59,7 +56,7 @@ public void shouldIgnoreAllTargetPropertiesWithNoUnmappedTargetWarnings() { assertThat( animalDto.publicColor ).isNull(); } - @Test + @ProcessorTest @IssueKey("337") public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore() { AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); @@ -73,7 +70,7 @@ public void propertyIsIgnoredInReverseMappingWhenSourceIsAlsoSpecifiedICWIgnore( assertThat( animal.publicColour ).isNull(); } - @Test + @ProcessorTest @IssueKey("833") @WithClasses({Preditor.class, PreditorDto.class, ErroneousTargetHasNoWriteAccessorMapper.class}) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java index f3dc994a6e..deaa75bbe7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/expand/IgnorePropertyTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.ignore.expand; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for ignoring properties during the mapping. @@ -25,10 +23,9 @@ FlattenedToolBox.class, ToolBoxMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class IgnorePropertyTest { - @Test + @ProcessorTest @IssueKey("1392") public void shouldIgnoreAll() { FlattenedToolBox toolboxSource = new FlattenedToolBox(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java index ef0cf6fc68..7ff4ea386d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignore/inherit/IgnorePropertyTest.java @@ -7,13 +7,11 @@ import java.util.Date; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for ignoring properties during the mapping. @@ -30,10 +28,9 @@ WorkBenchEntity.class, ToolMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class IgnorePropertyTest { - @Test + @ProcessorTest @IssueKey("1392") /** * Should not issue warnings on unmapped target properties @@ -54,7 +51,7 @@ public void shouldIgnoreAllExeptOveriddenInherited() { } - @Test + @ProcessorTest @IssueKey("1933") public void shouldInheritIgnoreByDefaultFromBase() { @@ -74,7 +71,7 @@ public void shouldInheritIgnoreByDefaultFromBase() { assertThat( benchTarget.getCreationDate() ).isNull(); } - @Test + @ProcessorTest @IssueKey("1933") public void shouldOnlyIgnoreBase() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java index 0fda48c63d..d09ddf66a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java @@ -5,11 +5,7 @@ */ package org.mapstruct.ap.test.imports; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.imports.from.Foo; import org.mapstruct.ap.test.imports.from.FooWrapper; import org.mapstruct.ap.test.imports.referenced.GenericMapper; @@ -17,10 +13,12 @@ import org.mapstruct.ap.test.imports.referenced.Source; import org.mapstruct.ap.test.imports.referenced.Target; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for generating a mapper which references types whose names clash with names of used annotations and exceptions. * @@ -43,17 +41,12 @@ org.mapstruct.ap.test.imports.to.FooWrapper.class, SecondSourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ConflictingTypesNamesTest { - private final GeneratedSource generatedSource = new GeneratedSource(); - - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest public void mapperImportingTypesWithConflictingNamesCanBeGenerated() { Named source = new Named(); source.setFoo( 123 ); @@ -71,7 +64,7 @@ public void mapperImportingTypesWithConflictingNamesCanBeGenerated() { assertThat( foo2.getName() ).isEqualTo( "bar" ); } - @Test + @ProcessorTest @IssueKey("178") public void mapperHasNoUnnecessaryImports() { Source source = new Source(); @@ -91,7 +84,7 @@ public void mapperHasNoUnnecessaryImports() { generatedSource.forMapper( SecondSourceTargetMapper.class ).containsNoImportFor( NotImportedDatatype.class ); } - @Test + @ProcessorTest @IssueKey("156") public void importsForTargetTypes() { FooWrapper source = new FooWrapper(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java index 95dbbd3ee8..91e5df6a27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java @@ -5,11 +5,7 @@ */ package org.mapstruct.ap.test.imports; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.imports.innerclasses.BeanFacade; import org.mapstruct.ap.test.imports.innerclasses.BeanWithInnerEnum; import org.mapstruct.ap.test.imports.innerclasses.BeanWithInnerEnum.InnerEnum; @@ -21,10 +17,12 @@ import org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass.TargetInnerClass; import org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for generating a mapper which references nested types (static inner classes). * @@ -34,17 +32,12 @@ SourceWithInnerClass.class, TargetWithInnerClass.class, InnerClassMapper.class, // BeanFacade.class, BeanWithInnerEnum.class, BeanWithInnerEnumMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InnerClassesImportsTest { - private final GeneratedSource generatedSource = new GeneratedSource(); - - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @IssueKey( "412" ) public void mapperRequiresInnerClassImports() { SourceWithInnerClass source = new SourceWithInnerClass(); @@ -58,7 +51,7 @@ public void mapperRequiresInnerClassImports() { generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( TargetInnerClass.class ); } - @Test + @ProcessorTest @IssueKey( "412" ) public void mapperRequiresInnerInnerClassImports() { SourceInnerClass source = new SourceInnerClass(); @@ -72,7 +65,7 @@ public void mapperRequiresInnerInnerClassImports() { generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( TargetInnerInnerClass.class ); } - @Test + @ProcessorTest @IssueKey( "209" ) public void mapperRequiresInnerEnumImports() { BeanWithInnerEnum source = new BeanWithInnerEnum(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java index 13f373278f..90249b319e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/decorator/DecoratorInAnotherPackageTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.imports.decorator; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.imports.decorator.other.ActorMapperDecorator; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for having a decorator in another package than the mapper interface. @@ -26,10 +24,9 @@ ActorMapper.class, ActorMapperDecorator.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class DecoratorInAnotherPackageTest { - @Test + @ProcessorTest public void shouldApplyDecoratorFromAnotherPackage() { Actor actor = new Actor(); actor.setAwards( 3 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java index 069e23a58f..37f4b7a0a7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/sourcewithextendsbound/SourceTypeContainsCollectionWithExtendsBoundTest.java @@ -5,23 +5,21 @@ */ package org.mapstruct.ap.test.imports.sourcewithextendsbound; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Collections; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.imports.sourcewithextendsbound.astronautmapper.AstronautMapper; import org.mapstruct.ap.test.imports.sourcewithextendsbound.dto.AstronautDto; import org.mapstruct.ap.test.imports.sourcewithextendsbound.dto.SpaceshipDto; import org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Astronaut; import org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Spaceship; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for generating a mapper which references nested types (static inner classes). * @@ -31,17 +29,12 @@ Astronaut.class, Spaceship.class, AstronautDto.class, SpaceshipDto.class, SpaceshipMapper.class, AstronautMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SourceTypeContainsCollectionWithExtendsBoundTest { - private final GeneratedSource generatedSource = new GeneratedSource(); - - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @IssueKey("768") public void generatesImportsForCollectionWithExtendsBoundInSourceType() { Astronaut astronaut = new Astronaut(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java index b13629d06c..d127a9ac11 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.inheritance; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for propagation of attributes inherited from super types. @@ -19,10 +17,9 @@ * @author Gunnar Morling */ @WithClasses({ SourceBase.class, SourceExt.class, TargetBase.class, TargetExt.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InheritanceTest { - @Test + @ProcessorTest @IssueKey("17") public void shouldMapAttributeFromSuperType() { SourceExt source = createSource(); @@ -32,7 +29,7 @@ public void shouldMapAttributeFromSuperType() { assertResult( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldMapAttributeFromSuperTypeUsingTargetParameter() { SourceExt source = createSource(); @@ -43,7 +40,7 @@ public void shouldMapAttributeFromSuperTypeUsingTargetParameter() { assertResult( target ); } - @Test + @ProcessorTest @IssueKey("19") public void shouldMapAttributeFromSuperTypeUsingReturnedTargetParameter() { SourceExt source = createSource(); @@ -71,7 +68,7 @@ private SourceExt createSource() { return source; } - @Test + @ProcessorTest @IssueKey("17") public void shouldReverseMapAttributeFromSuperType() { TargetExt target = new TargetExt(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java index f00319dcf7..7b9f2d6196 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/attribute/AttributeInheritanceTest.java @@ -5,27 +5,24 @@ */ package org.mapstruct.ap.test.inheritance.attribute; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for setting an attribute where the target attribute of a super-type. * * @author Gunnar Morling */ -@RunWith(AnnotationProcessorTestRunner.class) public class AttributeInheritanceTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) public void shouldMapAttributeFromSuperType() { Source source = new Source(); @@ -36,7 +33,7 @@ public void shouldMapAttributeFromSuperType() { assertThat( target.getFoo().toString() ).isEqualTo( "Bob" ); } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, ErroneousTargetSourceMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java index d67734423e..e2dc947d35 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/complex/ComplexInheritanceTest.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.inheritance.complex; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for propagation of attributes inherited from super types. @@ -30,10 +27,9 @@ SourceExt.class, SourceExt2.class, TargetComposite.class, AdditionalFooSource.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ComplexInheritanceTest { - @Test + @ProcessorTest @IssueKey("34") @WithClasses({ StandaloneSourceCompositeTargetCompositeMapper.class }) public void shouldMapAttributesWithSuperTypeInStandaloneMapper() { @@ -47,7 +43,7 @@ public void shouldMapAttributesWithSuperTypeInStandaloneMapper() { assertThat( target.getProp5() ).containsOnly( 42, 999 ); } - @Test + @ProcessorTest @IssueKey("34") @WithClasses({ SourceCompositeTargetCompositeMapper.class, SourceBaseMappingHelper.class }) public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { @@ -61,7 +57,7 @@ public void shouldMapAttributesWithSuperTypeUsingOtherMapper() { assertThat( target.getProp5() ).containsOnly( 43, 1000 ); } - @Test + @ProcessorTest @IssueKey("34") @WithClasses({ ErroneousSourceCompositeTargetCompositeMapper.class, AdditionalMappingHelper.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java index 874acfc81d..36c7c5ea08 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritedmappingmethod/InheritedMappingMethodTest.java @@ -5,33 +5,30 @@ */ package org.mapstruct.ap.test.inheritedmappingmethod; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.inheritedmappingmethod._target.CarDto; import org.mapstruct.ap.test.inheritedmappingmethod._target.FastCarDto; import org.mapstruct.ap.test.inheritedmappingmethod.source.Car; import org.mapstruct.ap.test.inheritedmappingmethod.source.FastCar; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @IssueKey( "274" ) @WithClasses({ Car.class, CarDto.class, UnboundMappable.class, CarMapper.class, // FastCar.class, FastCarDto.class, BoundMappable.class, FastCarMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InheritedMappingMethodTest { - @Test + @ProcessorTest public void shouldProvideUnboundedMapperInstance() { UnboundMappable instance = CarMapper.INSTANCE; assertThat( instance ).isNotNull(); } - @Test + @ProcessorTest public void shouldMapUsingUnboundedInheretedMappingMethod() { // given CarDto bikeDto = new CarDto(); @@ -45,13 +42,13 @@ public void shouldMapUsingUnboundedInheretedMappingMethod() { assertThat( bike.getHorsepower() ).isEqualTo( 130 ); } - @Test + @ProcessorTest public void shouldProvideBoundedMapperInstance() { BoundMappable instance = FastCarMapper.INSTANCE; assertThat( instance ).isNotNull(); } - @Test + @ProcessorTest public void shouldMapUsingBoundedInheretedMappingMethod() { // given FastCarDto bikeDto = new FastCarDto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java index 8ab3583aa9..4d8e0c28ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/InheritFromConfigTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.inheritfromconfig; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ BaseVehicleDto.class, BaseVehicleEntity.class, @@ -35,7 +32,7 @@ @IssueKey("168") public class InheritFromConfigTest { - @Test + @ProcessorTest public void autoInheritedMappingIsApplied() { CarDto carDto = newTestDto(); @@ -44,7 +41,7 @@ public void autoInheritedMappingIsApplied() { assertEntity( carEntity ); } - @Test + @ProcessorTest public void autoInheritedMappingIsAppliedForMappingTarget() { CarDto carDto = newTestDto(); CarEntity carEntity = new CarEntity(); @@ -54,7 +51,7 @@ public void autoInheritedMappingIsAppliedForMappingTarget() { assertEntity( carEntity ); } - @Test + @ProcessorTest public void autoInheritedMappingIsAppliedForMappingTargetWithTwoStepInheritance() { CarDto carDto = newTestDto(); CarEntity carEntity = new CarEntity(); @@ -77,7 +74,7 @@ private CarDto newTestDto() { return carDto; } - @Test + @ProcessorTest public void autoInheritedMappingIsOverriddenAtMethodLevel() { CarDto carDto = newTestDto(); @@ -88,7 +85,7 @@ public void autoInheritedMappingIsOverriddenAtMethodLevel() { assertThat( carEntity.getAuditTrail() ).isEqualTo( "fixed" ); } - @Test + @ProcessorTest public void autoInheritedMappingIsAppliedInReverse() { CarEntity carEntity = new CarEntity(); carEntity.setColor( "red" ); @@ -100,7 +97,7 @@ public void autoInheritedMappingIsAppliedInReverse() { assertThat( carDto.getId() ).isEqualTo( 42L ); } - @Test + @ProcessorTest public void explicitInheritedMappingIsAppliedInReverse() { CarEntity carEntity = new CarEntity(); carEntity.setColor( "red" ); @@ -112,7 +109,7 @@ public void explicitInheritedMappingIsAppliedInReverse() { assertThat( carDto.getId() ).isEqualTo( 42L ); } - @Test + @ProcessorTest @IssueKey( "1065" ) @WithClasses({ CarMapperReverseWithExplicitInheritance.class } ) public void explicitInheritedMappingIsAppliedInReverseDirectlyFromConfig() { @@ -127,7 +124,7 @@ public void explicitInheritedMappingIsAppliedInReverseDirectlyFromConfig() { assertThat( carDto.getId() ).isEqualTo( 42L ); } - @Test + @ProcessorTest @IssueKey( "1255" ) @WithClasses({ CarMapperReverseWithAutoInheritance.class, AutoInheritedReverseConfig.class } ) public void autoInheritedMappingIsAppliedInReverseDirectlyFromConfig() { @@ -142,7 +139,7 @@ public void autoInheritedMappingIsAppliedInReverseDirectlyFromConfig() { assertThat( carDto.getId() ).isEqualTo( 42L ); } - @Test + @ProcessorTest @IssueKey( "1255" ) @WithClasses({ CarMapperAllWithAutoInheritance.class, AutoInheritedAllConfig.class } ) public void autoInheritedMappingIsAppliedInForwardAndReverseDirectlyFromConfig() { @@ -156,7 +153,7 @@ public void autoInheritedMappingIsAppliedInForwardAndReverseDirectlyFromConfig() assertThat( carDto.getId() ).isEqualTo( carDto2.getId() ); } - @Test + @ProcessorTest public void explicitInheritedMappingWithTwoLevelsIsOverriddenAtMethodLevel() { CarDto carDto = newTestDto(); @@ -167,7 +164,7 @@ public void explicitInheritedMappingWithTwoLevelsIsOverriddenAtMethodLevel() { assertThat( carEntity.getAuditTrail() ).isEqualTo( "fixed" ); } - @Test + @ProcessorTest public void explicitInheritedMappingIsApplied() { CarDto carDto = newTestDto(); @@ -176,7 +173,7 @@ public void explicitInheritedMappingIsApplied() { assertEntity( carEntity ); } - @Test + @ProcessorTest @WithClasses({ DriverDto.class, CarWithDriverEntity.class, @@ -195,7 +192,7 @@ public void autoInheritedFromMultipleSources() { assertThat( carWithDriverEntity.getDriverName() ).isEqualTo( "Malcroft" ); } - @Test + @ProcessorTest @WithClasses({ Erroneous1Mapper.class, Erroneous1Config.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -227,7 +224,7 @@ public void autoInheritedFromMultipleSources() { public void erroneous1MultiplePrototypeMethodsMatch() { } - @Test + @ProcessorTest @WithClasses({ Erroneous2Mapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -247,7 +244,7 @@ public void erroneous1MultiplePrototypeMethodsMatch() { public void erroneous2InheritanceCycle() { } - @Test + @ProcessorTest @IssueKey( "1255" ) @WithClasses({ ErroneousMapperAutoInheritance.class, AutoInheritedReverseConfig.class } ) @ExpectedCompilationOutcome( @@ -261,7 +258,7 @@ public void erroneous2InheritanceCycle() { ) public void erroneousWrongReverseConfigInherited() { } - @Test + @ProcessorTest @IssueKey( "1255" ) @WithClasses({ ErroneousMapperReverseWithAutoInheritance.class, AutoInheritedConfig.class } ) @ExpectedCompilationOutcome( @@ -275,7 +272,7 @@ public void erroneousWrongReverseConfigInherited() { } ) public void erroneousWrongConfigInherited() { } - @Test + @ProcessorTest @IssueKey("1255") @WithClasses({ Erroneous3Mapper.class, Erroneous3Config.class }) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java index 3e765d9b18..bc59060e13 100755 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritfromconfig/multiple/CarMapperTest.java @@ -5,17 +5,14 @@ */ package org.mapstruct.ap.test.inheritfromconfig.multiple; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@RunWith(AnnotationProcessorTestRunner.class) +import static org.assertj.core.api.Assertions.assertThat; + @WithClasses({ BaseDto.class, BaseEntity.class, @@ -30,7 +27,7 @@ @IssueKey("1367") public class CarMapperTest { - @Test + @ProcessorTest public void testMapEntityToDto() { CarDto dto = CarMapper.MAPPER.mapTo( newCar() ); assertThat( dto.getDbId() ).isEqualTo( 9L ); @@ -38,7 +35,7 @@ public void testMapEntityToDto() { assertThat( dto.getSeatCount() ).isEqualTo( 5 ); } - @Test + @ProcessorTest public void testMapDtoToEntity() { CarEntity car = CarMapper.MAPPER.mapFrom( newCarDto() ); assertThat( car.getId() ).isEqualTo( 9L ); @@ -48,7 +45,7 @@ public void testMapDtoToEntity() { assertThat( car.getCreationDate() ).isNull(); } - @Test + @ProcessorTest public void testForwardMappingShouldTakePrecedence() { Car2Dto dto = new Car2Dto(); dto.setMaker( "mazda" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java index 61c767869a..65d8acfb2c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java @@ -8,17 +8,15 @@ import javax.inject.Inject; import javax.inject.Named; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -42,33 +40,32 @@ CustomerJsr330DefaultCompileOptionFieldMapper.class, GenderJsr330DefaultCompileOptionFieldMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class) @Configuration public class Jsr330DefaultCompileOptionFieldMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Inject @Named private CustomerJsr330DefaultCompileOptionFieldMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -84,7 +81,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerJsr330DefaultCompileOptionFieldMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java index dbf4a4f7ee..c564648ecf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.injectionstrategy.jsr330.compileoptionconstructor; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -41,33 +39,32 @@ CustomerJsr330CompileOptionConstructorMapper.class, GenderJsr330CompileOptionConstructorMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class) @Configuration public class Jsr330CompileOptionConstructorMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerJsr330CompileOptionConstructorMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -83,7 +80,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveConstructorInjectionFromCompileOption() { generatedSource.forMapper( CustomerJsr330CompileOptionConstructorMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java index d76b077a3f..06f4180289 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.injectionstrategy.jsr330.constructor; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -42,32 +40,31 @@ ConstructorJsr330Config.class }) @IssueKey("571") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class) @Configuration public class Jsr330ConstructorMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerJsr330ConstructorMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -83,7 +80,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveConstructorInjection() { generatedSource.forMapper( CustomerJsr330ConstructorMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java index 551821df05..fc3bd09561 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -8,18 +8,16 @@ import javax.inject.Inject; import javax.inject.Named; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -44,33 +42,32 @@ FieldJsr330Config.class }) @IssueKey("571") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class) @Configuration public class Jsr330FieldMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Inject @Named private CustomerJsr330FieldMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -86,7 +83,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerJsr330FieldMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java index c695214937..ef1b79b34b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.injectionstrategy.spring._default; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -41,32 +39,31 @@ GenderSpringDefaultMapper.class }) @IssueKey("571") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerSpringDefaultMapper.class) @Configuration public class SpringDefaultMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerSpringDefaultMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -82,7 +79,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerSpringDefaultMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java index 7608963a6d..8043c24305 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java @@ -10,22 +10,20 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -53,7 +51,6 @@ CustomerSpringCompileOptionConstructorMapper.class, GenderSpringCompileOptionConstructorMapper.class } ) -@RunWith(AnnotationProcessorTestRunner.class) @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class) @Configuration @@ -61,38 +58,38 @@ public class SpringCompileOptionConstructorMapperTest { private static TimeZone originalTimeZone; - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerRecordSpringCompileOptionConstructorMapper customerRecordMapper; private ConfigurableApplicationContext context; - @BeforeClass + @BeforeAll public static void setDefaultTimeZoneToCet() { originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); } - @AfterClass + @AfterAll public static void restoreOriginalTimeZone() { TimeZone.setDefault( originalTimeZone ); } - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() throws Exception { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -119,7 +116,7 @@ private Date createDate(String date) throws ParseException { return sdf.parse( date ); } - @Test + @ProcessorTest public void shouldConstructorInjectionFromCompileOption() { generatedSource.forMapper( CustomerSpringCompileOptionConstructorMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java index 267ad8dd33..1346ac1ee8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -10,13 +10,11 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; @@ -24,8 +22,8 @@ import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -54,45 +52,44 @@ ConstructorSpringConfig.class } ) @IssueKey( "571" ) -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class) @Configuration public class SpringConstructorMapperTest { private static TimeZone originalTimeZone; - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerRecordSpringConstructorMapper customerRecordMapper; private ConfigurableApplicationContext context; - @BeforeClass + @BeforeAll public static void setDefaultTimeZoneToCet() { originalTimeZone = TimeZone.getDefault(); TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); } - @AfterClass + @AfterAll public static void restoreOriginalTimeZone() { TimeZone.setDefault( originalTimeZone ); } - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() throws Exception { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -114,7 +111,7 @@ public void shouldConvertToTarget() throws Exception { assertThat( customerRecordDto.getRegistrationDate().toString() ).isEqualTo( "1982-08-31T10:20:56.000+02:00" ); } - @Test + @ProcessorTest public void shouldHaveConstructorInjection() { generatedSource.forMapper( CustomerSpringConstructorMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java index 12cb9577dc..8ee03f4bfb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.injectionstrategy.spring.field; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.Gender; import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -42,32 +40,31 @@ FieldSpringConfig.class }) @IssueKey("571") -@RunWith(AnnotationProcessorTestRunner.class) @ComponentScan(basePackageClasses = CustomerSpringFieldMapper.class) @Configuration public class SpringFieldMapperTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); @Autowired private CustomerSpringFieldMapper customerMapper; private ConfigurableApplicationContext context; - @Before + @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); context.getAutowireCapableBeanFactory().autowireBean( this ); } - @After + @AfterEach public void springDown() { if ( context != null ) { context.close(); } } - @Test + @ProcessorTest public void shouldConvertToTarget() { // given CustomerEntity customerEntity = new CustomerEntity(); @@ -83,7 +80,7 @@ public void shouldConvertToTarget() { assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); } - @Test + @ProcessorTest public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerSpringFieldMapper.class ) .content() diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java index a6fa793d57..a15468e5e1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/StreamMappingTest.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.java8stream; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, @@ -29,10 +27,9 @@ StringHolder.class }) @IssueKey( "962" ) -@RunWith(AnnotationProcessorTestRunner.class) public class StreamMappingTest { - @Test + @ProcessorTest public void shouldMapNullList() { Source source = new Source(); @@ -42,7 +39,7 @@ public void shouldMapNullList() { assertThat( target.getStringList() ).isNull(); } - @Test + @ProcessorTest public void shouldReverseMapNullList() { Target target = new Target(); @@ -52,7 +49,7 @@ public void shouldReverseMapNullList() { assertThat( source.getStringStream() ).isNull(); } - @Test + @ProcessorTest public void shouldMapList() { Source source = new Source(); source.setStringStream( Stream.of( "Bob", "Alice" ) ); @@ -63,7 +60,7 @@ public void shouldMapList() { assertThat( target.getStringList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldMapListWithoutSetter() { Source source = new Source(); source.setStringStream2( Stream.of( "Bob", "Alice" ) ); @@ -74,7 +71,7 @@ public void shouldMapListWithoutSetter() { assertThat( target.getStringListNoSetter() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldReverseMapList() { Target target = new Target(); target.setStringList( Arrays.asList( "Bob", "Alice" ) ); @@ -85,7 +82,7 @@ public void shouldReverseMapList() { assertThat( source.getStringStream() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldMapArrayList() { Source source = new Source(); source.setStringArrayStream( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); @@ -96,7 +93,7 @@ public void shouldMapArrayList() { assertThat( target.getStringArrayList() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldReverseMapArrayList() { Target target = new Target(); target.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) ); @@ -107,7 +104,7 @@ public void shouldReverseMapArrayList() { assertThat( source.getStringArrayStream() ).containsExactly( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldMapSet() { Source source = new Source(); source.setStringStreamToSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); @@ -118,7 +115,7 @@ public void shouldMapSet() { assertThat( target.getStringSet() ).contains( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldReverseMapSet() { Target target = new Target(); target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) ); @@ -129,7 +126,7 @@ public void shouldReverseMapSet() { assertThat( source.getStringStreamToSet() ).contains( "Bob", "Alice" ); } - @Test + @ProcessorTest public void shouldMapListToCollection() { Source source = new Source(); source.setIntegerStream( Stream.of( 1, 2 ) ); @@ -140,7 +137,7 @@ public void shouldMapListToCollection() { assertThat( target.getIntegerCollection() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest public void shouldReverseMapListToCollection() { Target target = new Target(); target.setIntegerCollection( Arrays.asList( 1, 2 ) ); @@ -151,7 +148,7 @@ public void shouldReverseMapListToCollection() { assertThat( source.getIntegerStream() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest public void shouldMapIntegerSetToStringSet() { Source source = new Source(); source.setAnotherIntegerStream( new HashSet<>( Arrays.asList( 1, 2 ) ).stream() ); @@ -162,7 +159,7 @@ public void shouldMapIntegerSetToStringSet() { assertThat( target.getAnotherStringSet() ).containsOnly( "1", "2" ); } - @Test + @ProcessorTest public void shouldReverseMapIntegerSetToStringSet() { Target target = new Target(); target.setAnotherStringSet( new HashSet<>( Arrays.asList( "1", "2" ) ) ); @@ -173,7 +170,7 @@ public void shouldReverseMapIntegerSetToStringSet() { assertThat( source.getAnotherIntegerStream() ).containsOnly( 1, 2 ); } - @Test + @ProcessorTest public void shouldMapSetOfEnumToStringSet() { Source source = new Source(); source.setColours( Stream.of( Colour.BLUE, Colour.GREEN ) ); @@ -184,7 +181,7 @@ public void shouldMapSetOfEnumToStringSet() { assertThat( target.getColours() ).containsOnly( "BLUE", "GREEN" ); } - @Test + @ProcessorTest public void shouldReverseMapSetOfEnumToStringSet() { Target target = new Target(); target.setColours( new HashSet<>( Arrays.asList( "BLUE", "GREEN" ) ) ); @@ -195,7 +192,7 @@ public void shouldReverseMapSetOfEnumToStringSet() { assertThat( source.getColours() ).containsOnly( Colour.GREEN, Colour.BLUE ); } - @Test + @ProcessorTest public void shouldMapIntegerStreamToNumberSet() { Set numbers = SourceTargetMapper.INSTANCE .integerStreamToNumberSet( Stream.of( 123, 456 ) ); @@ -204,7 +201,7 @@ public void shouldMapIntegerStreamToNumberSet() { assertThat( numbers ).containsOnly( 123, 456 ); } - @Test + @ProcessorTest public void shouldMapNonGenericList() { Source source = new Source(); source.setStringStream3( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ).stream() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java index c91889e063..027f619c98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/base/StreamsTest.java @@ -10,13 +10,11 @@ import java.util.TreeSet; import java.util.stream.Stream; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -25,7 +23,6 @@ * @author Filip Hrisafov */ @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Source.class, Target.class, @@ -36,10 +33,10 @@ }) public class StreamsTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest public void shouldNotContainFunctionIdentity() { generatedSource.forMapper( StreamMapper.class ) .content() @@ -47,7 +44,7 @@ public void shouldNotContainFunctionIdentity() { .doesNotContain( "Function.identity()" ); } - @Test + @ProcessorTest public void shouldMapSourceStream() { List someInts = Arrays.asList( 1, 2, 3 ); Stream stream = someInts.stream(); @@ -84,7 +81,7 @@ public void shouldMapSourceStream() { assertThat( target.getTargetElements().get( 0 ).getSource() ).isEqualTo( "source1" ); } - @Test + @ProcessorTest public void shouldMapTargetStream() { List someInts = Arrays.asList( 1, 2, 3 ); Stream stream = someInts.stream(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java index 91c1a41256..74fbeb10b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/context/StreamWithContextTest.java @@ -8,11 +8,9 @@ import java.util.Collection; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +19,9 @@ */ @WithClasses({ StreamContext.class, StreamWithContextMapper.class }) @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class StreamWithContextTest { - @Test + @ProcessorTest public void shouldApplyAfterMapping() { Stream stringStream = StreamWithContextMapper.INSTANCE.intStreamToStringStream( Stream.of( 1, 2, 3, 5 ) ); @@ -32,7 +29,7 @@ public void shouldApplyAfterMapping() { assertThat( stringStream ).containsOnly( "1", "2" ); } - @Test + @ProcessorTest public void shouldApplyBeforeMappingOnArray() { Integer[] integers = new Integer[] { 1, 3 }; Stream stringStream = StreamWithContextMapper.INSTANCE.arrayToStream( integers ); @@ -40,7 +37,7 @@ public void shouldApplyBeforeMappingOnArray() { assertThat( stringStream ).containsOnly( 30, 3 ); } - @Test + @ProcessorTest public void shouldApplyBeforeAndAfterMappingOnCollection() { Collection stringsStream = StreamWithContextMapper.INSTANCE.streamToCollection( Stream.of( 10, 20, 40 ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java index ae64592c0e..91be53fe64 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.java8stream.defaultimplementation; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -17,11 +15,11 @@ import java.util.TreeSet; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, @@ -31,10 +29,9 @@ SourceTargetMapper.class }) @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class DefaultStreamImplementationTest { - @Test + @ProcessorTest public void shouldUseDefaultImplementationForNavigableSet() { NavigableSet target = SourceTargetMapper.INSTANCE.streamToNavigableSet( createSourceFooStream() ); @@ -43,7 +40,7 @@ public void shouldUseDefaultImplementationForNavigableSet() { assertThat( target ).isInstanceOf( TreeSet.class ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForCollection() { Collection target = SourceTargetMapper.INSTANCE.streamToCollection( createSourceFooStream() ); @@ -52,7 +49,7 @@ public void shouldUseDefaultImplementationForCollection() { assertThat( target ).isInstanceOf( ArrayList.class ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForIterable() { Iterable target = SourceTargetMapper.INSTANCE.streamToIterable( createSourceFooStream() ); @@ -61,7 +58,7 @@ public void shouldUseDefaultImplementationForIterable() { assertThat( target ).isInstanceOf( ArrayList.class ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForList() { List target = SourceTargetMapper.INSTANCE.streamToList( createSourceFooStream() ); @@ -69,7 +66,7 @@ public void shouldUseDefaultImplementationForList() { assertThat( target ).isInstanceOf( ArrayList.class ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForSet() { Set target = SourceTargetMapper.INSTANCE.streamToSet( createSourceFooStream() ); @@ -78,7 +75,7 @@ public void shouldUseDefaultImplementationForSet() { assertThat( target ).isInstanceOf( HashSet.class ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForSortedSet() { SortedSet target = SourceTargetMapper.INSTANCE.streamToSortedSet( createSourceFooStream() ); @@ -87,7 +84,7 @@ public void shouldUseDefaultImplementationForSortedSet() { assertThat( target ).isInstanceOf( TreeSet.class ); } - @Test + @ProcessorTest public void shouldUseTargetParameterForMapping() { List target = new ArrayList<>(); SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter( @@ -98,7 +95,7 @@ public void shouldUseTargetParameterForMapping() { assertResultList( target ); } - @Test + @ProcessorTest public void shouldUseTargetParameterForArrayMapping() { TargetFoo[] target = new TargetFoo[3]; SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameter( @@ -110,7 +107,7 @@ public void shouldUseTargetParameterForArrayMapping() { assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ), null ); } - @Test + @ProcessorTest public void shouldUseTargetParameterForArrayMappingAndSmallerArray() { TargetFoo[] target = new TargetFoo[1]; SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameter( @@ -122,7 +119,7 @@ public void shouldUseTargetParameterForArrayMappingAndSmallerArray() { assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); } - @Test + @ProcessorTest public void shouldUseAndReturnTargetParameterForArrayMapping() { TargetFoo[] target = new TargetFoo[3]; TargetFoo[] result = @@ -133,7 +130,7 @@ public void shouldUseAndReturnTargetParameterForArrayMapping() { assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ), null ); } - @Test + @ProcessorTest public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() { TargetFoo[] target = new TargetFoo[1]; TargetFoo[] result = @@ -144,7 +141,7 @@ public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() { assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); } - @Test + @ProcessorTest public void shouldUseAndReturnTargetParameterForMapping() { List target = new ArrayList<>(); Iterable result = @@ -155,7 +152,7 @@ public void shouldUseAndReturnTargetParameterForMapping() { assertResultList( target ); } - @Test + @ProcessorTest public void shouldUseDefaultImplementationForListWithoutSetter() { Source source = new Source(); source.setFooStream( createSourceFooStream() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java index 813b9d87e1..f82a522bf5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/NoSetterStreamMappingTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.java8stream.defaultimplementation; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.List; import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisfaov @@ -22,10 +20,9 @@ */ @WithClasses({ NoSetterMapper.class, NoSetterSource.class, NoSetterTarget.class }) @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class NoSetterStreamMappingTest { - @Test + @ProcessorTest public void compilesAndMapsCorrectly() { NoSetterSource source = new NoSetterSource(); source.setListValues( Stream.of( "foo", "bar" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java index e177b8a9a3..f3e540b7ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/erroneous/ErroneousStreamMappingTest.java @@ -7,16 +7,14 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.NoProperties; import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Test for illegal mappings between collection/stream types, iterable and non-iterable types etc. @@ -31,10 +29,9 @@ * @author Filip Hrisafov */ @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class ErroneousStreamMappingTest { - @Test + @ProcessorTest @WithClasses({ ErroneousStreamToNonStreamMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -52,7 +49,7 @@ public class ErroneousStreamMappingTest { public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterable() { } - @Test + @ProcessorTest @WithClasses({ ErroneousStreamToPrimitivePropertyMapper.class, Source.class, Target.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -67,7 +64,7 @@ public void shouldFailToGenerateImplementationBetweenStreamAndNonStreamOrIterabl public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { } - @Test + @ProcessorTest @WithClasses({ EmptyStreamMappingMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -92,7 +89,7 @@ public void shouldFailToGenerateImplementationBetweenCollectionAndPrimitive() { public void shouldFailOnEmptyIterableAnnotationStreamMappings() { } - @Test + @ProcessorTest @WithClasses({ ErroneousStreamToStreamNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -108,7 +105,7 @@ public void shouldFailOnEmptyIterableAnnotationStreamMappings() { public void shouldFailOnNoElementMappingFoundForStreamToStream() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousStreamToStreamNoElementMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( @@ -124,7 +121,7 @@ public void shouldFailOnNoElementMappingFoundForStreamToStream() { public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() { } - @Test + @ProcessorTest @WithClasses({ ErroneousListToStreamNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -140,7 +137,7 @@ public void shouldFailOnNoElementMappingFoundForStreamToStreamWithDisabledAuto() public void shouldFailOnNoElementMappingFoundForListToStream() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousListToStreamNoElementMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( @@ -156,7 +153,7 @@ public void shouldFailOnNoElementMappingFoundForListToStream() { public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { } - @Test + @ProcessorTest @WithClasses({ ErroneousStreamToListNoElementMappingFound.class, NoProperties.class, WithProperties.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -172,7 +169,7 @@ public void shouldFailOnNoElementMappingFoundForListToStreamWithDisabledAuto() { public void shouldFailOnNoElementMappingFoundForStreamToList() { } - @Test + @ProcessorTest @IssueKey("993") @WithClasses({ ErroneousStreamToListNoElementMappingFoundDisabledAuto.class }) @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java index bcd35e5b5e..2ad882891f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/forged/ForgedStreamMappingTest.java @@ -5,35 +5,32 @@ */ package org.mapstruct.ap.test.java8stream.forged; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * Test for mappings between collection and stream types, * * @author Filip Hrisafov */ @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class ForgedStreamMappingTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ StreamMapper.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethod() { @@ -56,7 +53,7 @@ public void shouldForgeNewIterableMappingMethod() { .doesNotContain( "Stream.empty()" ); } - @Test + @ProcessorTest @WithClasses({ ErroneousStreamNonMappableStreamMapper.class, ErroneousNonMappableStreamSource.class, @@ -78,7 +75,7 @@ public void shouldForgeNewIterableMappingMethod() { public void shouldGenerateNonMappableMethodForSetMapping() { } - @Test + @ProcessorTest @WithClasses({ StreamMapper.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() { @@ -96,7 +93,7 @@ public void shouldForgeNewIterableMappingMethodReturnNullOnNullSource() { assertThat( source2.getFooStream3() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ StreamMapperNullValueMappingReturnDefault.class, Source.class, Target.class }) public void shouldForgeNewIterableMappingMethodReturnEmptyOnNullSource() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java index 6472ce6db3..26c8e88324 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/streamtononiterable/StreamToNonIterableMappingTest.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.java8stream.streamtononiterable; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.stream.Stream; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; @WithClasses({ Source.class, Target.class, SourceTargetMapper.class, StringListMapper.class }) @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class StreamToNonIterableMappingTest { - @Test + @ProcessorTest public void shouldMapStringStreamToStringUsingCustomMapper() { Source source = new Source(); source.setNames( Stream.of( "Alice", "Bob", "Jim" ) ); @@ -30,7 +27,7 @@ public void shouldMapStringStreamToStringUsingCustomMapper() { assertThat( target.getNames() ).isEqualTo( "Alice-Bob-Jim" ); } - @Test + @ProcessorTest public void shouldReverseMapStringStreamToStringUsingCustomMapper() { Target target = new Target(); target.setNames( "Alice-Bob-Jim" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java index acf89c5b93..a039951495 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/WildCardTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.java8stream.wildcard; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ @IssueKey("962") -@RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { - @Test + @ProcessorTest @WithClasses({ ExtendsBoundSourceTargetMapper.class, ExtendsBoundSource.class, @@ -43,7 +40,7 @@ public void shouldGenerateExtendsBoundSourceForgedStreamMethod() { } - @Test + @ProcessorTest @WithClasses({ SourceSuperBoundTargetMapper.class, Source.class, @@ -63,7 +60,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableSuperBoundSourceMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -77,7 +74,7 @@ public void shouldGenerateSuperBoundTargetForgedIterableMethod() { public void shouldFailOnSuperBoundSource() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableExtendsBoundTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -91,7 +88,7 @@ public void shouldFailOnSuperBoundSource() { public void shouldFailOnExtendsBoundTarget() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMethod.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -105,7 +102,7 @@ public void shouldFailOnExtendsBoundTarget() { public void shouldFailOnTypeVarSource() { } - @Test + @ProcessorTest @WithClasses({ ErroneousIterableTypeVarBoundMapperOnMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java index d128e6f77e..1f7fe423f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mapperconfig/ConfigTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.mapperconfig; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -31,10 +29,9 @@ CustomMapperViaMapperConfig.class, SourceTargetMapper.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class ConfigTest { - @Test + @ProcessorTest @WithClasses( { Target.class, SourceTargetMapper.class } ) public void shouldUseCustomMapperViaMapperForFooToEntity() { @@ -43,7 +40,7 @@ public void shouldUseCustomMapperViaMapperForFooToEntity() { assertThat( target.getFoo().getCreatedBy() ).isEqualTo( CustomMapperViaMapper.class.getSimpleName() ); } - @Test + @ProcessorTest @WithClasses( { Target.class, SourceTargetMapper.class } ) public void shouldUseCustomMapperViaMapperConfigForFooToDto() { @@ -52,7 +49,7 @@ public void shouldUseCustomMapperViaMapperConfigForFooToDto() { assertThat( source.getFoo().getCreatedBy() ).isEqualTo( CustomMapperViaMapperConfig.class.getSimpleName() ); } - @Test + @ProcessorTest @WithClasses( { TargetNoFoo.class, SourceTargetMapperWarn.class } ) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @@ -63,7 +60,7 @@ public void shouldUseCustomMapperViaMapperConfigForFooToDto() { public void shouldUseWARNViaMapper() { } - @Test + @ProcessorTest @WithClasses( { TargetNoFoo.class, SourceTargetMapperErroneous.class } ) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcomposition/CompositionTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcomposition/CompositionTest.java index 6850c6f4ea..0a5a361313 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcomposition/CompositionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcomposition/CompositionTest.java @@ -7,11 +7,9 @@ import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -28,10 +26,9 @@ StorageMapper.class, ToEntity.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class CompositionTest { - @Test + @ProcessorTest public void shouldCompose() { Date now = new Date(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index 5324f3f2cd..d542801799 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -10,14 +10,12 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; @@ -37,13 +35,12 @@ UseDirect.class, UseComplex.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class MappingControlTest { /** * Baseline Test, normal, direct allowed */ - @Test + @ProcessorTest @WithClasses(DirectMapper.class) public void directSelectionAllowed() { @@ -58,7 +55,7 @@ public void directSelectionAllowed() { /** * Test the deep cloning annotation */ - @Test + @ProcessorTest @WithClasses(CloningMapper.class) public void testDeepCloning() { @@ -75,7 +72,7 @@ public void testDeepCloning() { /** * Test the deep cloning annotation with lists */ - @Test + @ProcessorTest @WithClasses(CloningListMapper.class) public void testDeepCloningListsAndMaps() { @@ -121,7 +118,7 @@ public void testDeepCloningListsAndMaps() { * MapStruct gets too creative when we allow complex (2 step mappings) to convert if we also allow * it to forge methods (which is contradiction with the fact that we do not allow methods on this mapper) */ - @Test + @ProcessorTest @WithClasses(ErroneousDirectMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -138,7 +135,7 @@ public void directSelectionNotAllowed() { /** * Baseline Test, normal, method allowed */ - @Test + @ProcessorTest @WithClasses(MethodMapper.class) public void methodSelectionAllowed() { Fridge fridge = MethodMapper.INSTANCE.map( createFridgeDTO() ); @@ -148,7 +145,7 @@ public void methodSelectionAllowed() { assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); } - @Test + @ProcessorTest @WithClasses(ErroneousMethodMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -165,7 +162,7 @@ public void methodSelectionNotAllowed() { /** * Baseline Test, normal, conversion allowed */ - @Test + @ProcessorTest @WithClasses(ConversionMapper.class) public void conversionSelectionAllowed() { Fridge fridge = ConversionMapper.INSTANCE.map( createFridgeDTO().getShelve().getCoolBeer() ); @@ -174,7 +171,7 @@ public void conversionSelectionAllowed() { assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); } - @Test + @ProcessorTest @WithClasses(ErroneousConversionMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -191,7 +188,7 @@ public void conversionSelectionNotAllowed() { /** * Baseline Test, normal, complex mapping allowed */ - @Test + @ProcessorTest @WithClasses(ComplexMapper.class) public void complexSelectionAllowed() { Fridge fridge = ComplexMapper.INSTANCE.map( createFridgeDTO() ); @@ -200,7 +197,7 @@ public void complexSelectionAllowed() { assertThat( fridge.getBeerCount() ).isEqualTo( 5 ); } - @Test + @ProcessorTest @WithClasses(ErroneousComplexMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -214,7 +211,7 @@ public void complexSelectionAllowed() { public void complexSelectionNotAllowed() { } - @Test + @ProcessorTest @WithClasses({ Config.class, ErroneousComplexMapperWithConfig.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java index f9ad0b435b..079b2f3020 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/namesuggestion/SuggestMostSimilarNameTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.namesuggestion; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.namesuggestion.erroneous.PersonAgeMapper; import org.mapstruct.ap.test.namesuggestion.erroneous.PersonGarageWrongSourceMapper; import org.mapstruct.ap.test.namesuggestion.erroneous.PersonGarageWrongTargetMapper; import org.mapstruct.ap.test.namesuggestion.erroneous.PersonNameMapper; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Person.class, PersonDto.class, Garage.class, GarageDto.class, ColorRgb.class, ColorRgbDto.class }) public class SuggestMostSimilarNameTest { - @Test + @ProcessorTest @WithClasses({ PersonAgeMapper.class }) @@ -39,7 +36,7 @@ public class SuggestMostSimilarNameTest { public void testAgeSuggestion() { } - @Test + @ProcessorTest @WithClasses({ PersonNameMapper.class }) @@ -55,7 +52,7 @@ public void testAgeSuggestion() { public void testNameSuggestion() { } - @Test + @ProcessorTest @WithClasses({ PersonGarageWrongTargetMapper.class }) @@ -85,7 +82,7 @@ public void testNameSuggestion() { public void testGarageTargetSuggestion() { } - @Test + @ProcessorTest @WithClasses({ PersonGarageWrongSourceMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java index c70f21b2cd..4b5c7982ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java @@ -5,9 +5,6 @@ */ package org.mapstruct.ap.test.naming; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Arrays; import java.util.Calendar; import java.util.Date; @@ -15,11 +12,12 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * Test for naming of variables/members which conflict with keywords or parameter names. @@ -28,10 +26,9 @@ */ @WithClasses({ SourceTargetMapper.class, While.class, Break.class, Source.class }) @IssueKey("53") -@RunWith(AnnotationProcessorTestRunner.class) public class VariableNamingTest { - @Test + @ProcessorTest public void shouldGenerateImplementationsOfMethodsWithProblematicVariableNmes() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java index d443d952ba..78608dd7ba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/spi/CustomNamingStrategyTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.naming.spi; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test do demonstrate the usage of custom implementations of {@link AccessorNamingStrategy}. * * @author Andreas Gudian */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ GolfPlayer.class, GolfPlayerDto.class, GolfPlayerMapper.class }) @WithServiceImplementation(CustomAccessorNamingStrategy.class) public class CustomNamingStrategyTest { - @Test + @ProcessorTest public void shouldApplyCustomNamingStrategy() { GolfPlayer player = new GolfPlayer() .withName( "Jared" ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java index bc9bded0cc..7331a5cc2d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DisablingNestedSimpleBeansMappingTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.nestedbeans; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -22,7 +20,6 @@ Roof.class, RoofDto.class, RoofType.class, ExternalRoofType.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class DisablingNestedSimpleBeansMappingTest { @WithClasses({ @@ -37,7 +34,7 @@ public class DisablingNestedSimpleBeansMappingTest { "Consider to declare/implement a mapping method: \"RoofDto map(Roof value)\"." ) }) - @Test + @ProcessorTest public void shouldUseDisabledMethodGenerationOnMapper() { } @@ -54,7 +51,7 @@ public void shouldUseDisabledMethodGenerationOnMapper() { "Consider to declare/implement a mapping method: \"RoofDto map(Roof value)\"." ) }) - @Test + @ProcessorTest public void shouldUseDisabledMethodGenerationOnMapperConfig() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index 3117f17fc9..fb10616577 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -5,8 +5,6 @@ */ package org.mapstruct.ap.test.nestedbeans; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseCollectionElementPropertyMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseDeepListMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.BaseDeepMapKeyMapper; @@ -59,11 +57,11 @@ import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnDeepMapValueMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnDeepNestingMapper; import org.mapstruct.ap.test.nestedbeans.unmappable.warn.UnmappableWarnValuePropertyMapper; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; @WithClasses({ Car.class, CarDto.class, Color.class, ColorDto.class, @@ -81,7 +79,6 @@ BaseDeepNestingMapper.class, BaseValuePropertyMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class DottedErrorMessageTest { private static final String PROPERTY = "property"; @@ -89,7 +86,7 @@ public class DottedErrorMessageTest { private static final String MAP_KEY = "Map key"; private static final String MAP_VALUE = "Map value"; - @Test + @ProcessorTest @WithClasses({ UnmappableDeepNestingMapper.class }) @@ -106,7 +103,7 @@ public class DottedErrorMessageTest { public void testDeepNestedBeans() { } - @Test + @ProcessorTest @WithClasses({ UnmappableDeepListMapper.class }) @@ -123,7 +120,7 @@ public void testDeepNestedBeans() { public void testIterables() { } - @Test + @ProcessorTest @WithClasses({ UnmappableDeepMapKeyMapper.class }) @@ -140,7 +137,7 @@ public void testIterables() { public void testMapKeys() { } - @Test + @ProcessorTest @WithClasses({ UnmappableDeepMapValueMapper.class }) @@ -157,7 +154,7 @@ public void testMapKeys() { public void testMapValues() { } - @Test + @ProcessorTest @WithClasses({ UnmappableCollectionElementPropertyMapper.class }) @@ -174,7 +171,7 @@ public void testMapValues() { public void testCollectionElementProperty() { } - @Test + @ProcessorTest @WithClasses({ UnmappableValuePropertyMapper.class }) @@ -191,7 +188,7 @@ public void testCollectionElementProperty() { public void testMapValueProperty() { } - @Test + @ProcessorTest @WithClasses({ UnmappableEnumMapper.class }) @@ -211,7 +208,7 @@ public void testMapValueProperty() { public void testMapEnumProperty() { } - @Test + @ProcessorTest @WithClasses({ UnmappableWarnDeepNestingMapper.class, UnmappableWarnDeepListMapper.class, @@ -258,7 +255,7 @@ public void testMapEnumProperty() { public void testWarnUnmappedTargetProperties() { } - @Test + @ProcessorTest @WithClasses({ UnmappableIgnoreDeepNestingMapper.class, UnmappableIgnoreDeepListMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java index ecd371d3f6..9231ed46e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/MultipleForgedMethodsTest.java @@ -5,9 +5,9 @@ */ package org.mapstruct.ap.test.nestedbeans; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.Arrays; +import java.util.HashMap; + import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionary; import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionaryDto; import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper; @@ -16,22 +16,20 @@ import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage; import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto; import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import java.util.Arrays; -import java.util.HashMap; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * This test is for a case when several identical methods could be generated, what is an easy edge case to miss. */ -@RunWith(AnnotationProcessorTestRunner.class) public class MultipleForgedMethodsTest { @WithClasses({ Word.class, WordDto.class, AntonymsDictionaryDto.class, AntonymsDictionary.class, AutoMapMapper.class }) - @Test + @ProcessorTest public void testNestedMapsAutoMap() { HashMap dtoAntonyms = new HashMap<>(); @@ -52,8 +50,10 @@ public void testNestedMapsAutoMap() { AntonymsDictionary mappedAntonymsDictionary = AutoMapMapper.INSTANCE.entityToDto( new AntonymsDictionaryDto( dtoAntonyms ) ); - Assert.assertEquals( "Mapper did not map dto to entity correctly", new AntonymsDictionary( entityAntonyms ), - mappedAntonymsDictionary + assertEquals( + new AntonymsDictionary( entityAntonyms ), + mappedAntonymsDictionary, + "Mapper did not map dto to entity correctly" ); } @@ -61,7 +61,7 @@ public void testNestedMapsAutoMap() { MultipleListMapper.class, Garage.class, GarageDto.class, Car.class, CarDto.class, Wheel.class, WheelDto.class }) - @Test + @ProcessorTest public void testMultipleCollections() { GarageDto dto = new GarageDto( Arrays.asList( new CarDto( @@ -97,7 +97,7 @@ public void testMultipleCollections() { GarageDto mappedDto = MultipleListMapper.INSTANCE.convert( entity ); - Assert.assertEquals( "Mapper did not map entity to dto correctly", dto, mappedDto ); + assertEquals( dto, mappedDto, "Mapper did not map entity to dto correctly" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java index 84d78cdd1c..b78da21860 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/NestedSimpleBeansMappingTest.java @@ -9,11 +9,9 @@ import java.util.stream.Collectors; import org.assertj.core.groups.Tuple; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -33,17 +31,16 @@ UserDtoMapperSmart.class, UserDtoUpdateMapperSmart.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NestedSimpleBeansMappingTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( UserDtoMapperClassic.class, UserDtoMapperSmart.class, UserDtoUpdateMapperSmart.class ); - @Test + @ProcessorTest public void shouldHaveAllFields() { // If this test fails that means something new was added to the structure of the User/UserDto. // Make sure that the other tests are also updated (the new field is asserted) @@ -68,7 +65,7 @@ public void shouldHaveAllFields() { assertThat( RoofDto.class ).hasOnlyDeclaredFields( roofFields ); } - @Test + @ProcessorTest public void shouldMapNestedBeans() { User user = TestData.createUser(); @@ -80,7 +77,7 @@ public void shouldMapNestedBeans() { assertUserDto( smartMapping, user ); } - @Test + @ProcessorTest public void shouldMapUpdateNestedBeans() { User user = TestData.createUser(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java index 90f5553278..e8caa784b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/RecursionTest.java @@ -9,24 +9,21 @@ import java.util.Iterator; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedbeans.recursive.RecursionMapper; import org.mapstruct.ap.test.nestedbeans.recursive.TreeRecursionMapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@RunWith(AnnotationProcessorTestRunner.class) public class RecursionTest { @WithClasses({ RecursionMapper.class }) - @Test + @ProcessorTest @IssueKey("1103") public void testRecursiveAutoMap() { RecursionMapper.RootDto rootDto = new RecursionMapper.RootDto( @@ -61,7 +58,7 @@ private void assertChildEquals(RecursionMapper.ChildDto childDto, RecursionMappe @WithClasses({ TreeRecursionMapper.class }) - @Test + @ProcessorTest @IssueKey("1103") public void testRecursiveTreeAutoMap() { TreeRecursionMapper.RootDto rootDto = new TreeRecursionMapper.RootDto( diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java index 509ca1e146..2a5f10ad22 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exceptions/NestedMappingsWithExceptionTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.nestedbeans.exceptions; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedbeans.exceptions._target.DeveloperDto; import org.mapstruct.ap.test.nestedbeans.exceptions._target.ProjectDto; import org.mapstruct.ap.test.nestedbeans.exceptions.source.Developer; import org.mapstruct.ap.test.nestedbeans.exceptions.source.Project; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -28,10 +26,9 @@ EntityFactory.class }) @IssueKey("1304") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedMappingsWithExceptionTest { - @Test + @ProcessorTest public void shouldGenerateCodeThatCompiles() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java index 19abea74b3..ae4a7d945a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/ErroneousJavaInternalTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.nestedbeans.exclusions; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -22,7 +20,6 @@ Target.class, ErroneousJavaInternalMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1154") public class ErroneousJavaInternalTest { @@ -51,7 +48,7 @@ public class ErroneousJavaInternalTest { "Consider to declare/implement a mapping method: " + "\"List map(List value)\".") }) - @Test + @ProcessorTest public void shouldNotNestIntoJavaPackageObjects() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java index 45cc9a2343..4fb90cf6ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/exclusions/custom/ErroneousCustomExclusionTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.nestedbeans.exclusions.custom; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -24,7 +22,6 @@ ErroneousCustomExclusionMapper.class }) @WithServiceImplementation( CustomMappingExclusionProvider.class ) -@RunWith(AnnotationProcessorTestRunner.class) @IssueKey("1154") public class ErroneousCustomExclusionTest { @@ -37,7 +34,7 @@ public class ErroneousCustomExclusionTest { "Consider to declare/implement a mapping method: \"Target.NestedTarget map(Source.NestedSource value)\".") } ) - @Test + @ProcessorTest public void shouldFailToCreateMappingForExcludedClass() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java index 3c381cfb4a..80922ae5c6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/mixed/AutomappingAndNestedTest.java @@ -5,11 +5,7 @@ */ package org.mapstruct.ap.test.nestedbeans.mixed; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.nestedbeans.mixed._target.FishDto; import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankDto; import org.mapstruct.ap.test.nestedbeans.mixed._target.FishTankWithNestedDocumentDto; @@ -30,10 +26,12 @@ import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQuality; import org.mapstruct.ap.test.nestedbeans.mixed.source.WaterQualityReport; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * * @author Sjaak Derksen @@ -64,18 +62,17 @@ FishTankMapperWithDocument.class }) @IssueKey("1057") -@RunWith(AnnotationProcessorTestRunner.class) public class AutomappingAndNestedTest { - @Rule - public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( FishTankMapper.class, FishTankMapperConstant.class, FishTankMapperExpression.class, FishTankMapperWithDocument.class ); - @Test + @ProcessorTest public void shouldAutomapAndHandleSourceAndTargetPropertyNesting() { // -- prepare @@ -117,7 +114,7 @@ public void shouldAutomapAndHandleSourceAndTargetPropertyNesting() { .isEqualTo( source.getQuality().getReport().getOrganisationName() ); } - @Test + @ProcessorTest public void shouldAutomapAndHandleSourceAndTargetPropertyNestingReverse() { // -- prepare @@ -156,7 +153,7 @@ public void shouldAutomapAndHandleSourceAndTargetPropertyNestingReverse() { .isEqualTo( source.getQuality().getReport().getVerdict() ); } - @Test + @ProcessorTest public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndConstant() { // -- prepare @@ -185,7 +182,7 @@ public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndConstant() { } - @Test + @ProcessorTest public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndExpresion() { // -- prepare @@ -210,7 +207,7 @@ public void shouldAutomapAndHandleSourceAndTargetPropertyNestingAndExpresion() { assertThat( target.getQuality().getReport().getOrganisation().getName() ).isEqualTo( "Dunno" ); } - @Test + @ProcessorTest public void shouldAutomapIntermediateLevelAndMapConstant() { // -- prepare diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 3738f56282..375f524d68 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -5,14 +5,11 @@ */ package org.mapstruct.ap.test.nestedmethodcall; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; - import javax.xml.bind.JAXBElement; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; @@ -20,13 +17,13 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for the nested invocation of mapping methods. @@ -34,25 +31,24 @@ * @author Sjaak Derksen */ @IssueKey("134") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedMappingMethodInvocationTest { public static final QName QNAME = new QName( "dont-care" ); private Locale originalLocale; - @Before + @BeforeEach public void setDefaultLocale() { originalLocale = Locale.getDefault(); Locale.setDefault( Locale.GERMAN ); } - @After + @AfterEach public void tearDown() { Locale.setDefault( originalLocale ); } - @Test + @ProcessorTest @WithClasses( { OrderTypeToOrderDtoMapper.class, OrderDto.class, @@ -73,7 +69,7 @@ public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException assertThat( target.getOrderDetails().getDescription() ).containsExactly( "elem1", "elem2" ); } - @Test + @ProcessorTest @WithClasses( { SourceTypeTargetDtoMapper.class, SourceType.class, @@ -89,7 +85,7 @@ public void shouldMapViaMethodAndConversion() { assertThat( target.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); } - @Test + @ProcessorTest @WithClasses( { SourceTypeTargetDtoMapper.class, SourceType.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java index 98faca0cca..ae5833794e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedproperties/simple/SimpleNestedPropertiesTest.java @@ -5,38 +5,36 @@ */ package org.mapstruct.ap.test.nestedproperties.simple; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedproperties.simple._target.TargetObject; import org.mapstruct.ap.test.nestedproperties.simple.source.SourceProps; import org.mapstruct.ap.test.nestedproperties.simple.source.SourceRoot; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Sebastian Hasait */ @WithClasses({ SourceRoot.class, SourceProps.class, TargetObject.class }) @IssueKey("407") -@RunWith(AnnotationProcessorTestRunner.class) public class SimpleNestedPropertiesTest { - @Test + @ProcessorTest @WithClasses({ SimpleMapper.class }) public void testNull() { TargetObject targetObject = SimpleMapper.MAPPER.toTargetObject( null ); - assertNull( targetObject ); + assertThat( targetObject ).isNull(); } - @Test + @ProcessorTest @WithClasses({ SimpleMapper.class }) public void testViaNull() { SourceRoot sourceRoot = new SourceRoot(); @@ -57,7 +55,7 @@ public void testViaNull() { assertNull( targetObject.getStringValue() ); } - @Test + @ProcessorTest @WithClasses({ SimpleMapper.class }) public void testFilled() { SourceRoot sourceRoot = new SourceRoot(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java index 09f47ccebb..97206784aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/exceptions/NestedExceptionTest.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.nestedsource.exceptions; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @@ -24,10 +22,9 @@ ResourceMapper.class }) @IssueKey("1332") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedExceptionTest { - @Test + @ProcessorTest public void shouldGenerateCodeThatCompiles() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java index 696d983dc6..de9a821527 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsource/parameter/NormalizingTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.nestedsource.parameter; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen */ @WithClasses({ FontDto.class, LetterDto.class, LetterEntity.class, LetterMapper.class }) @IssueKey("836") -@RunWith(AnnotationProcessorTestRunner.class) public class NormalizingTest { - @Test + @ProcessorTest public void shouldGenerateImplementationForPropertyNamesOnly() { FontDto fontIn = new FontDto(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java index 07d0a38611..2a0a80cbda 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/NestedSourcePropertiesTest.java @@ -5,15 +5,9 @@ */ package org.mapstruct.ap.test.nestedsourceproperties; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - import java.util.Arrays; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.nestedsourceproperties._target.AdderUsageObserver; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartPositions; @@ -23,25 +17,26 @@ import org.mapstruct.ap.test.nestedsourceproperties.source.Song; import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * @author Sjaak Derksen */ @WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) @IssueKey("65") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedSourcePropertiesTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldGenerateImplementationForPropertyNamesOnly() { generatedSource.addComparisonToFixtureFor( ArtistToChartEntry.class ); @@ -73,7 +68,7 @@ public void shouldGenerateImplementationForPropertyNamesOnly() { assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldGenerateImplementationForMultipleParam() { @@ -108,7 +103,7 @@ public void shouldGenerateImplementationForMultipleParam() { assertThat( chartEntry.getSongTitle() ).isEqualTo( "A Hard Day's Night" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntry.class }) public void shouldPickPropertyNameOverParameterName() { @@ -127,7 +122,7 @@ public void shouldPickPropertyNameOverParameterName() { assertThat( chartEntry.getSongTitle() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryAdder.class, ChartPositions.class, AdderUsageObserver.class }) public void shouldUseAddAsTargetAccessor() { @@ -142,10 +137,10 @@ public void shouldUseAddAsTargetAccessor() { assertThat( positions ).isNotNull(); assertThat( positions.getPositions() ).containsExactly( 3L, 5L ); - assertTrue( AdderUsageObserver.isUsed() ); + assertThat( AdderUsageObserver.isUsed() ).isTrue(); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryGetter.class, ChartPositions.class, AdderUsageObserver.class }) public void shouldUseGetAsTargetAccessor() { @@ -160,10 +155,10 @@ public void shouldUseGetAsTargetAccessor() { assertThat( positions ).isNotNull(); assertThat( positions.getPositions() ).containsExactly( 3L, 5L ); - assertFalse( AdderUsageObserver.isUsed() ); + assertThat( AdderUsageObserver.isUsed() ).isFalse(); } - @Test + @ProcessorTest @IssueKey("838") @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java index db27970b51..2010a205de 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedsourceproperties/ReversingNestedSourcePropertiesTest.java @@ -5,11 +5,6 @@ */ package org.mapstruct.ap.test.nestedsourceproperties; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nestedsourceproperties._target.BaseChartEntry; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntryComposed; @@ -23,18 +18,19 @@ import org.mapstruct.ap.test.nestedsourceproperties.source.SourceDtoFactory; import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen */ @IssueKey("389") @WithClasses({ Song.class, Artist.class, Chart.class, Label.class, Studio.class, ChartEntry.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ReversingNestedSourcePropertiesTest { - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryReverse.class }) public void shouldGenerateNestedReverse() { @@ -63,7 +59,7 @@ public void shouldGenerateNestedReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithIgnoresReverse.class }) public void shouldIgnoreEverytingBelowArtist() { @@ -86,7 +82,7 @@ public void shouldIgnoreEverytingBelowArtist() { assertThat( song2.getArtist() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryUpdateReverse.class }) public void shouldGenerateNestedUpdateReverse() { @@ -116,7 +112,7 @@ public void shouldGenerateNestedUpdateReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses( { ArtistToChartEntryWithFactoryReverse.class, SourceDtoFactory.class } ) public void shouldGenerateNestedReverseWithFactory() { @@ -151,7 +147,7 @@ public void shouldGenerateNestedReverseWithFactory() { } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryComposedReverse.class, ChartEntryComposed.class, ChartEntryLabel.class }) public void shouldGenerateNestedComposedReverse() { @@ -181,7 +177,7 @@ public void shouldGenerateNestedComposedReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithMappingReverse.class, ChartEntryWithMapping.class }) public void shouldGenerateNestedWithMappingReverse() { @@ -210,7 +206,7 @@ public void shouldGenerateNestedWithMappingReverse() { assertThat( song2.getArtist().getLabel().getStudio().getName() ).isEqualTo( "Abbey Road" ); } - @Test + @ProcessorTest @WithClasses({ ArtistToChartEntryWithConfigReverse.class, ArtistToChartEntryConfig.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java index 44a73abd4b..b10c51ab39 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedtargetproperties/NestedProductPropertiesTest.java @@ -5,9 +5,7 @@ */ package org.mapstruct.ap.test.nestedtargetproperties; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry; import org.mapstruct.ap.test.nestedsourceproperties.source.Artist; import org.mapstruct.ap.test.nestedsourceproperties.source.Chart; @@ -15,8 +13,8 @@ import org.mapstruct.ap.test.nestedsourceproperties.source.Song; import org.mapstruct.ap.test.nestedsourceproperties.source.Studio; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -36,16 +34,15 @@ ChartEntryToArtistUpdate.class } ) @IssueKey("389") -@RunWith(AnnotationProcessorTestRunner.class) public class NestedProductPropertiesTest { - @Rule - public GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( ChartEntryToArtist.class, ChartEntryToArtistUpdate.class ); - @Test + @ProcessorTest public void shouldMapNestedTarget() { ChartEntry chartEntry = new ChartEntry(); @@ -74,7 +71,7 @@ public void shouldMapNestedTarget() { } - @Test + @ProcessorTest public void shouldMapNestedComposedTarget() { ChartEntry chartEntry1 = new ChartEntry(); @@ -105,7 +102,7 @@ public void shouldMapNestedComposedTarget() { } - @Test + @ProcessorTest public void shouldReverseNestedTarget() { ChartEntry chartEntry = new ChartEntry(); @@ -128,7 +125,7 @@ public void shouldReverseNestedTarget() { assertThat( result.getSongTitle() ).isEqualTo( "Purple Rain" ); } - @Test + @ProcessorTest public void shouldMapNestedTargetWitUpdate() { ChartEntry chartEntry = new ChartEntry(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java index 6745f52c02..883464ebfe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nonvoidsetter/NonVoidSettersTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.nonvoidsetter; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for using non-void setters (fluent style) in the target. @@ -19,10 +17,9 @@ * @author Gunnar Morling */ @WithClasses({ Actor.class, ActorDto.class, ActorMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NonVoidSettersTest { - @Test + @ProcessorTest @IssueKey("353") public void shouldMapAttributeWithoutSetterInSourceType() { ActorDto target = ActorMapper.INSTANCE.actorToActorDto( new Actor( 3, "Hickory Black" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java index 290a34f733..816db7a1dc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/NullCheckTest.java @@ -5,13 +5,12 @@ */ package org.mapstruct.ap.test.nullcheck; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * Test for correct handling of null checks. @@ -28,10 +27,9 @@ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NullCheckTest { - @Test(expected = NullPointerException.class) + @ProcessorTest @IssueKey("214") public void shouldThrowNullptrWhenCustomMapperIsInvoked() { @@ -40,10 +38,11 @@ public void shouldThrowNullptrWhenCustomMapperIsInvoked() { source.setSomeInteger( 7 ); source.setSomeLong( 2L ); - SourceTargetMapper.INSTANCE.sourceToTarget( source ); + assertThatThrownBy( () -> SourceTargetMapper.INSTANCE.sourceToTarget( source ) ) + .isInstanceOf( NullPointerException.class ); } - @Test + @ProcessorTest @IssueKey("214") public void shouldSurroundTypeConversionWithNullCheck() { @@ -58,7 +57,7 @@ public void shouldSurroundTypeConversionWithNullCheck() { } - @Test + @ProcessorTest @IssueKey("214") public void shouldSurroundArrayListConstructionWithNullCheck() { @@ -72,7 +71,7 @@ public void shouldSurroundArrayListConstructionWithNullCheck() { assertThat( target.getSomeList() ).isNull(); } - @Test + @ProcessorTest @IssueKey("237") public void shouldSurroundConversionPassedToMappingMethodWithNullCheck() { @@ -86,7 +85,7 @@ public void shouldSurroundConversionPassedToMappingMethodWithNullCheck() { assertThat( target.getSomeInteger() ).isNull(); } - @Test + @ProcessorTest @IssueKey("231") public void shouldSurroundConversionFromWrappedPassedToMappingMethodWithPrimitiveArgWithNullCheck() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java index 957b3e7b1a..256d3f7d92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullcheck/strategy/NullValueCheckTest.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.nullcheck.strategy; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -21,10 +19,9 @@ HouseMapperConfig.class, HouseMapperWithConfig.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NullValueCheckTest { - @Test + @ProcessorTest public void testDefinedOnMapper() { HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnMapper( new HouseDto() ); @@ -35,7 +32,7 @@ public void testDefinedOnMapper() { } - @Test + @ProcessorTest public void testDefinedOnBean() { HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnBean( new HouseDto() ); @@ -46,7 +43,7 @@ public void testDefinedOnBean() { } - @Test + @ProcessorTest public void testDefinedOnMapping() { HouseEntity entity = HouseMapper.INSTANCE.mapWithNvcsOnMapping( new HouseDto() ); @@ -57,7 +54,7 @@ public void testDefinedOnMapping() { } - @Test + @ProcessorTest public void testDefinedOnConfig() { HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnMapper( new HouseDto() ); @@ -68,7 +65,7 @@ public void testDefinedOnConfig() { } - @Test + @ProcessorTest public void testDefinedOnConfigAndBean() { HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnBean( new HouseDto() ); @@ -79,7 +76,7 @@ public void testDefinedOnConfigAndBean() { } - @Test + @ProcessorTest public void testDefinedOnConfigAndMapping() { HouseEntity entity = HouseMapperWithConfig.INSTANCE.mapWithNvcsOnMapping( new HouseDto() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java index 5c6caf6b1f..4bd9324a9a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java @@ -5,22 +5,20 @@ */ package org.mapstruct.ap.test.nullvaluemapping; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; import org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto; import org.mapstruct.ap.test.nullvaluemapping.source.Car; import org.mapstruct.ap.test.nullvaluemapping.source.Driver; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for the strategies for mapping {@code null} values, given via {@code NullValueMapping} etc. @@ -38,15 +36,14 @@ CentralConfig.class, CarMapperSettingOnConfig.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class NullValueMappingTest { - @Test + @ProcessorTest public void shouldProvideMapperInstance() { assertThat( CarMapper.INSTANCE ).isNotNull(); } - @Test + @ProcessorTest public void shouldMapExpressionAndConstantRegardlessNullArg() { //given Car car = new Car( "Morris", 2 ); @@ -72,7 +69,7 @@ public void shouldMapExpressionAndConstantRegardlessNullArg() { assertThat( carDto2.getCatalogId() ).isNotEmpty(); } - @Test + @ProcessorTest public void shouldMapExpressionAndConstantRegardlessNullArgSeveralSources() { //given Car car = new Car( "Morris", 2 ); @@ -98,7 +95,7 @@ public void shouldMapExpressionAndConstantRegardlessNullArgSeveralSources() { assertThat( carDto2.getCatalogId() ).isNotEmpty(); } - @Test + @ProcessorTest public void shouldMapIterableWithNullArg() { //given @@ -119,7 +116,7 @@ public void shouldMapIterableWithNullArg() { assertThat( carDtos2.isEmpty() ).isTrue(); } - @Test + @ProcessorTest @SuppressWarnings({ "rawtypes", "unchecked" }) public void shouldMapMapWithNullArg() { @@ -143,7 +140,7 @@ public void shouldMapMapWithNullArg() { assertThat( carDtoMap2.isEmpty() ).isTrue(); } - @Test + @ProcessorTest public void shouldMapExpressionAndConstantRegardlessNullArgOnMapper() { //when @@ -157,7 +154,7 @@ public void shouldMapExpressionAndConstantRegardlessNullArgOnMapper() { assertThat( carDto.getCatalogId() ).isNotEmpty(); } - @Test + @ProcessorTest public void shouldMapIterableWithNullArgOnMapper() { //when @@ -168,7 +165,7 @@ public void shouldMapIterableWithNullArgOnMapper() { assertThat( carDtos.isEmpty() ).isTrue(); } - @Test + @ProcessorTest public void shouldMapMapWithNullArgOnMapper() { //when @@ -178,7 +175,7 @@ public void shouldMapMapWithNullArgOnMapper() { assertThat( carDtoMap ).isNull(); } - @Test + @ProcessorTest public void shouldMapExpressionAndConstantRegardlessNullArgOnConfig() { //when @@ -192,7 +189,7 @@ public void shouldMapExpressionAndConstantRegardlessNullArgOnConfig() { assertThat( carDto.getCatalogId() ).isNotEmpty(); } - @Test + @ProcessorTest public void shouldMapIterableWithNullArgOnConfig() { //when @@ -203,7 +200,7 @@ public void shouldMapIterableWithNullArgOnConfig() { assertThat( carDtos.isEmpty() ).isTrue(); } - @Test + @ProcessorTest public void shouldMapMapWithNullArgOnConfig() { //when @@ -213,7 +210,7 @@ public void shouldMapMapWithNullArgOnConfig() { assertThat( carDtoMap ).isNull(); } - @Test + @ProcessorTest public void shouldApplyConfiguredStrategyForMethodWithSeveralSourceParams() { //when DriverAndCarDto result = CarMapper.INSTANCE.driverAndCarToDto( null, null ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index 014c2c8220..dfe2e14d6f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -8,14 +8,12 @@ import java.util.Arrays; import java.util.function.BiConsumer; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -23,7 +21,6 @@ * @author Sjaak Derksen */ @IssueKey("1306") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Address.class, Customer.class, @@ -34,7 +31,7 @@ }) public class NullValuePropertyMappingTest { - @Test + @ProcessorTest @WithClasses(CustomerMapper.class) public void testStrategyAppliedOnForgedMethod() { @@ -56,31 +53,31 @@ public void testStrategyAppliedOnForgedMethod() { assertThat( userDTO.getDetails() ).containsExactly( "green hair" ); } - @Test + @ProcessorTest @WithClasses({ NvpmsConfig.class, CustomerNvpmsOnConfigMapper.class }) public void testHierarchyIgnoreOnConfig() { testConfig( CustomerNvpmsOnConfigMapper.INSTANCE::map ); } - @Test + @ProcessorTest @WithClasses(CustomerNvpmsOnMapperMapper.class) public void testHierarchyIgnoreOnMapping() { testConfig( CustomerNvpmsOnMapperMapper.INSTANCE::map ); } - @Test + @ProcessorTest @WithClasses(CustomerNvpmsOnBeanMappingMethodMapper.class) public void testHierarchyIgnoreOnBeanMappingMethod() { testConfig( CustomerNvpmsOnBeanMappingMethodMapper.INSTANCE::map ); } - @Test + @ProcessorTest @WithClasses(CustomerNvpmsPropertyMappingMapper.class) public void testHierarchyIgnoreOnPropertyMappingMethod() { testConfig( CustomerNvpmsPropertyMappingMapper.INSTANCE::map ); } - @Test + @ProcessorTest @WithClasses(CustomerDefaultMapper.class) public void testStrategyDefaultAppliedOnForgedMethod() { @@ -102,7 +99,7 @@ public void testStrategyDefaultAppliedOnForgedMethod() { assertThat( userDTO.getDetails() ).isEmpty(); } - @Test + @ProcessorTest @WithClasses(ErroneousCustomerMapper1.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -118,7 +115,7 @@ public void testStrategyDefaultAppliedOnForgedMethod() { public void testBothDefaultValueAndNvpmsDefined() { } - @Test + @ProcessorTest @WithClasses(ErroneousCustomerMapper2.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -134,7 +131,7 @@ public void testBothDefaultValueAndNvpmsDefined() { public void testBothExpressionAndNvpmsDefined() { } - @Test + @ProcessorTest @WithClasses(ErroneousCustomerMapper3.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -150,7 +147,7 @@ public void testBothExpressionAndNvpmsDefined() { public void testBothDefaultExpressionAndNvpmsDefined() { } - @Test + @ProcessorTest @WithClasses(ErroneousCustomerMapper4.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -166,7 +163,7 @@ public void testBothDefaultExpressionAndNvpmsDefined() { public void testBothConstantAndNvpmsDefined() { } - @Test + @ProcessorTest @WithClasses(ErroneousCustomerMapper5.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java b/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java index 7794b406d8..f69497f3a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/oneway/OnewayTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.oneway; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for propagation of attribute without setter in source and getter in @@ -20,10 +18,9 @@ * @author Gunnar Morling */ @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class OnewayTest { - @Test + @ProcessorTest @IssueKey("17") public void shouldMapAttributeWithoutSetterInSourceType() { Source source = new Source(); @@ -34,7 +31,7 @@ public void shouldMapAttributeWithoutSetterInSourceType() { assertThat( target.retrieveFoo() ).isEqualTo( Long.valueOf( 42 ) ); } - @Test + @ProcessorTest @IssueKey("41") public void shouldReverseMapAttributeWithoutSetterInTargetType() { Target target = new Target(); @@ -45,7 +42,7 @@ public void shouldReverseMapAttributeWithoutSetterInTargetType() { assertThat( source.retrieveBar() ).isEqualTo( 23 ); } - @Test + @ProcessorTest @IssueKey("104") public void shouldMapMappedAttributeWithoutSetterInSourceType() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java index ee34f53046..f8ea91034e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/ReferencedMapperTest.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.references; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * @author Andreas Gudian @@ -28,9 +26,8 @@ SourceTargetMapper.class, Target.class, BaseType.class, SomeType.class, SomeOtherType.class, GenericWrapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class ReferencedMapperTest { - @Test + @ProcessorTest public void referencedMappersAreInstatiatedCorrectly() { Target target = SourceTargetMapper.INSTANCE.sourceToTarget( createSource() ); @@ -55,7 +52,7 @@ private Source createSource() { return source; } - @Test + @ProcessorTest @IssueKey( "136" ) public void shouldUseGenericFactoryForIterable() { List result = SourceTargetMapper.INSTANCE.fromStringList( Arrays.asList( "foo1", "foo2" ) ); @@ -63,7 +60,7 @@ public void shouldUseGenericFactoryForIterable() { assertThat( result ).extracting( "value" ).containsExactly( "foo1", "foo2" ); } - @Test + @ProcessorTest @IssueKey( "136" ) public void shouldUseGenericFactoryForMap() { Map source = new HashMap<>(); @@ -77,7 +74,7 @@ public void shouldUseGenericFactoryForMap() { entry( new SomeType( "foo2" ), new SomeOtherType( "bar2" ) ) ); } - @Test + @ProcessorTest @IssueKey( "136" ) @WithClasses({ SourceTargetMapperWithPrimitives.class, SourceWithWrappers.class, TargetWithPrimitives.class }) public void shouldMapPrimitivesWithCustomMapper() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java index 3623be1937..68ae703769 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java @@ -5,17 +5,15 @@ */ package org.mapstruct.ap.test.references.samename; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.references.samename.a.AnotherSourceTargetMapper; import org.mapstruct.ap.test.references.samename.a.CustomMapper; import org.mapstruct.ap.test.references.samename.model.Source; import org.mapstruct.ap.test.references.samename.model.Target; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for referring several mappers with the same simple name. @@ -32,10 +30,9 @@ Jsr330SourceTargetMapper.class, AnotherSourceTargetMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SeveralReferencedMappersWithSameSimpleNameTest { - @Test + @ProcessorTest public void severalMappersWithSameSimpleNameCanBeReferenced() { Source source = new Source(); source.setFoo( 123 ); @@ -48,7 +45,7 @@ public void severalMappersWithSameSimpleNameCanBeReferenced() { assertThat( target.getBar() ).isEqualTo( "912" ); } - @Test + @ProcessorTest public void mapperInSamePackageAndAnotherMapperWithSameNameInAnotherPackageCanBeReferenced() { Source source = new Source(); source.setFoo( 123 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java index 645f3fc2c6..7ab323c5a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/statics/StaticsTest.java @@ -5,34 +5,27 @@ */ package org.mapstruct.ap.test.references.statics; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.references.statics.nonused.NonUsedMapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; +import static org.assertj.core.api.Assertions.assertThat; + /** * * @author Sjaak Derksen */ @IssueKey( "410" ) @WithClasses( { Beer.class, BeerDto.class, Category.class } ) -@RunWith(AnnotationProcessorTestRunner.class) public class StaticsTest { - private final GeneratedSource generatedSource = new GeneratedSource(); - - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses( { BeerMapper.class, CustomMapper.class } ) public void shouldUseStaticMethod() { @@ -44,7 +37,7 @@ public void shouldUseStaticMethod() { assertThat( result.getCategory() ).isEqualTo( Category.STRONG ); // why settle for less? } - @Test + @ProcessorTest @WithClasses( { BeerMapperWithNonUsedMapper.class, NonUsedMapper.class } ) public void shouldNotImportNonUsed() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java index 2e1598f8aa..32654e3c7e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/reverse/InheritInverseConfigurationTest.java @@ -7,18 +7,16 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.reverse.erroneous.SourceTargetMapperAmbiguous1; import org.mapstruct.ap.test.reverse.erroneous.SourceTargetMapperAmbiguous2; import org.mapstruct.ap.test.reverse.erroneous.SourceTargetMapperAmbiguous3; import org.mapstruct.ap.test.reverse.erroneous.SourceTargetMapperNonMatchingName; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -27,10 +25,9 @@ */ @IssueKey("252") @WithClasses({ Source.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InheritInverseConfigurationTest { - @Test + @ProcessorTest @WithClasses({ SourceTargetMapper.class }) public void shouldInheritInverseConfigurationMultipleCandidates() { @@ -53,7 +50,7 @@ public void shouldInheritInverseConfigurationMultipleCandidates() { assertThat( source.getPropertyToIgnoreDownstream() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous1.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -72,7 +69,7 @@ public void shouldInheritInverseConfigurationMultipleCandidates() { public void shouldRaiseAmbiguousReverseMethodError() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous2.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -91,7 +88,7 @@ public void shouldRaiseAmbiguousReverseMethodError() { public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous3.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -112,7 +109,7 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperNonMatchingName.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java index 2e86c96055..c8e7e00711 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/ConversionTest.java @@ -9,15 +9,13 @@ import java.math.BigDecimal; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.NoProperties; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * Tests for the invocation of generic methods for mapping bean properties. @@ -30,10 +28,9 @@ TypeA.class, TypeB.class, TypeC.class }) @IssueKey(value = "79") -@RunWith(AnnotationProcessorTestRunner.class) public class ConversionTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) public void shouldApplyGenericTypeMapper() { @@ -71,7 +68,7 @@ public void shouldApplyGenericTypeMapper() { assertThat( target.getFooWildCardSuperTypeBCorrect() ).isEqualTo( typeB ); } - @Test + @ProcessorTest @WithClasses({ ErroneousSource1.class, ErroneousTarget1.class, ErroneousSourceTargetMapper1.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -84,7 +81,7 @@ public void shouldApplyGenericTypeMapper() { public void shouldFailOnUpperBound() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSource2.class, ErroneousTarget2.class, ErroneousSourceTargetMapper2.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -100,7 +97,7 @@ public void shouldFailOnUpperBound() { public void shouldFailOnWildCardBound() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSource3.class, ErroneousTarget3.class, ErroneousSourceTargetMapper3.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -116,7 +113,7 @@ public void shouldFailOnWildCardBound() { public void shouldFailOnWildCardMultipleBounds() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSource4.class, ErroneousTarget4.class, ErroneousSourceTargetMapper4.class }) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { @@ -132,7 +129,7 @@ public void shouldFailOnWildCardMultipleBounds() { public void shouldFailOnSuperBounds1() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSource6.class, ErroneousTarget6.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java index 02eabb31b1..02705a097a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.selection.jaxb; -import static org.assertj.core.api.Assertions.assertThat; - import javax.xml.bind.annotation.XmlElementDecl; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.selection.jaxb.test1.OrderType; import org.mapstruct.ap.test.selection.jaxb.test2.ObjectFactory; import org.mapstruct.ap.test.selection.jaxb.test2.OrderShippingDetailsType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for the selection of JAXB mapping and factory methods based on the "name" and "scope" attributes @@ -30,10 +28,9 @@ OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class, OrderMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class JaxbFactoryMethodSelectionTest { - @Test + @ProcessorTest public void shouldMatchOnNameAndOrScope() { OrderType target = OrderMapper.INSTANCE.targetToSource( createSource() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java index 3dce6c35fd..f94dd7c94c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.selection.jaxb; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.selection.jaxb.underscores.ObjectFactory; import org.mapstruct.ap.test.selection.jaxb.underscores.SubType; import org.mapstruct.ap.test.selection.jaxb.underscores.SuperType; import org.mapstruct.ap.test.selection.jaxb.underscores.UnderscoreMapper; import org.mapstruct.ap.test.selection.jaxb.underscores.UnderscoreType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Ensure factory method selection works for classes generated from schemas using element names with underscores @@ -25,10 +23,9 @@ */ @IssueKey( "726" ) @WithClasses( { UnderscoreType.class, ObjectFactory.class, SuperType.class, SubType.class, UnderscoreMapper.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class UnderscoreSelectionTest { - @Test + @ProcessorTest public void selectingUnderscorePropertiesWorks() { SubType target = UnderscoreMapper.INSTANCE.map( createSource() ); assertThat( target.getInheritedUnderscore().getValue() ).isEqualTo( "hi" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java index 0b6dbc1137..ce1a14f3b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/array/GenericArrayTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.array; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class GenericArrayTest { - @Test + @ProcessorTest @WithClasses( ReturnTypeIsTypeVarArrayMapper.class ) public void testGenericReturnTypeVar() { @@ -33,7 +30,7 @@ public void testGenericReturnTypeVar() { assertThat( target.getProp() ).containsExactly( "test" ); } - @Test + @ProcessorTest @WithClasses( SourceTypeIsTypeVarArrayMapper.class ) public void testGenericSourceTypeVar() { @@ -47,7 +44,7 @@ public void testGenericSourceTypeVar() { } - @Test + @ProcessorTest @WithClasses( BothParameterizedMapper.class ) public void testBothParameterized() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java index c181cfe0b9..2ff9b078a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/bounds/BoundsTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.bounds; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author Sjaak Derksen * */ -@RunWith( AnnotationProcessorTestRunner.class ) public class BoundsTest { - @Test + @ProcessorTest @WithClasses( SourceTypeIsBoundedTypeVarMapper.class ) public void testGenericSourceTypeVar() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java index b11162bb33..b900fe21cc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/MultipleTypeVarTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.multiple; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Collections; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * @author Sjaak Derksen * */ -@RunWith( AnnotationProcessorTestRunner.class) public class MultipleTypeVarTest { - @Test + @ProcessorTest @WithClasses( ReturnTypeHasMultipleTypeVarOneGenericMapper.class ) public void testGenericSourceTypeVarOneGeneric() { @@ -37,7 +34,7 @@ public void testGenericSourceTypeVarOneGeneric() { assertThat( target.getProp() ).containsExactly( entry( "test", 5L ) ); } - @Test + @ProcessorTest @WithClasses( ReturnTypeHasMultipleTypeVarBothGenericMapper.class ) public void testGenericReturnTypeVarBothGeneric() { @@ -53,7 +50,7 @@ public void testGenericReturnTypeVarBothGeneric() { assertThat( target.getProp() ).containsExactly( entry( "test", 5L ) ); } - @Test + @ProcessorTest @WithClasses( SourceTypeHasMultipleTypeVarBothGenericMapper.class ) public void testGenericSourceTypeVarBothGeneric() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java index c177fb45e8..6073845c61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/nestedgenerics/NestedGenericsTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.nestedgenerics; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen * */ -@RunWith( AnnotationProcessorTestRunner.class) public class NestedGenericsTest { - @Test + @ProcessorTest @WithClasses( ReturnTypeHasNestedTypeVarMapper.class ) public void testGenericReturnTypeVar() { @@ -33,7 +30,7 @@ public void testGenericReturnTypeVar() { assertThat( target.getProp().get( 0 ) ).contains( "test" ); } - @Test + @ProcessorTest @WithClasses( SourceTypeHasNestedTypeVarMapper.class ) public void testGenericSourceTypeVar() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java index 8f7c878810..1fd5c0a202 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/plain/PlainTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.plain; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; /** * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class PlainTest { - @Test + @ProcessorTest @WithClasses( ReturnTypeIsTypeVarMapper.class ) public void testGenericReturnTypeVar() { @@ -33,7 +30,7 @@ public void testGenericReturnTypeVar() { assertThat( target.getProp() ).isEqualTo( "test" ); } - @Test + @ProcessorTest @WithClasses( SourceTypeIsTypeVarMapper.class ) public void testGenericSourceTypeVar() { @@ -46,7 +43,7 @@ public void testGenericSourceTypeVar() { } - @Test + @ProcessorTest @WithClasses( BothParameterizedMapper.class ) public void testBothParameterized() { @@ -60,7 +57,7 @@ public void testBothParameterized() { } - @Test + @ProcessorTest @WithClasses( ReturnTypeIsRawTypeMapper.class ) public void testRaw() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java index 47037ec6be..67a9a616fb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/targettype/TargetTypeTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.targettype; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class TargetTypeTest { - @Test + @ProcessorTest @WithClasses( PlainTargetTypeMapper.class ) public void testPlain() { @@ -30,7 +27,7 @@ public void testPlain() { assertThat( target.getProp().toPlainString() ).isEqualTo( "15" ); } - @Test + @ProcessorTest @WithClasses( NestedTargetTypeMapper.class ) public void testNestedTypeVar() { NestedTargetTypeMapper.Target target = diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java index 1df99d4d9a..a228304c72 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java @@ -5,12 +5,9 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.wildcards; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; import static org.assertj.core.api.Assertions.assertThat; @@ -18,10 +15,9 @@ * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { - @Test + @ProcessorTest @WithClasses( SourceWildCardExtendsMapper.class ) public void testExtendsRelation() { @@ -41,10 +37,9 @@ public void testExtendsRelation() { assertThat( target.getPropC() ).isEqualTo( typeC ); } - @Test - @WithClasses( IntersectionMapper.class ) // Eclipse does not handle intersection types correctly (TODO: worthwhile to investigate?) - @DisabledOnCompiler( Compiler.ECLIPSE ) + @ProcessorTest(Compiler.JDK) + @WithClasses( IntersectionMapper.class ) public void testIntersectionRelation() { // prepare source diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java index 7832a89c9f..4b82054283 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/primitives/PrimitiveVsWrappedSelectionTest.java @@ -5,13 +5,11 @@ */ package org.mapstruct.ap.test.selection.primitives; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -19,10 +17,9 @@ */ @IssueKey("205") @WithClasses({ Source.class, Target.class, MyLong.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class PrimitiveVsWrappedSelectionTest { - @Test + @ProcessorTest @WithClasses( { WrappedMapper.class, PrimitiveMapper.class, SourceTargetMapper.class } ) public void shouldAlwaysSelectWrappedAndExplicitlyTypeConvertWrappedtoPrimitive() { @@ -43,7 +40,7 @@ public void shouldAlwaysSelectWrappedAndExplicitlyTypeConvertWrappedtoPrimitive( } - @Test + @ProcessorTest @WithClasses( { PrimitiveMapper.class, SourceTargetMapperPrimitive.class } ) public void shouldSelectPrimitiveMapperAlsoForWrapped() { @@ -64,7 +61,7 @@ public void shouldSelectPrimitiveMapperAlsoForWrapped() { } - @Test + @ProcessorTest @WithClasses( { WrappedMapper.class, SourceTargetMapperWrapped.class } ) public void shouldSelectWrappedMapperAlsoForPrimitive() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java index 17c3c77863..9699b67f63 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/QualifierTest.java @@ -11,8 +11,6 @@ import java.util.Map; import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.selection.qualifier.annotation.CreateGermanRelease; import org.mapstruct.ap.test.selection.qualifier.annotation.EnglishToGerman; import org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated; @@ -28,11 +26,11 @@ import org.mapstruct.ap.test.selection.qualifier.handwritten.Titles; import org.mapstruct.ap.test.selection.qualifier.handwritten.YetAnotherMapper; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -49,10 +47,9 @@ SomeOtherMapper.class, NonQualifierAnnotated.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class QualifierTest { - @Test + @ProcessorTest @WithClasses( { Titles.class, Facts.class, @@ -90,7 +87,7 @@ public void shouldMatchClassAndMethod() { ); } - @Test + @ProcessorTest @WithClasses({ YetAnotherMapper.class, ErroneousMapper.class @@ -116,7 +113,7 @@ public void shouldMatchClassAndMethod() { public void shouldNotProduceMatchingMethod() { } - @Test + @ProcessorTest @WithClasses( { MapperWithoutQualifiedBy.class, Facts.class, @@ -136,7 +133,7 @@ public void shouldNotUseQualifierAnnotatedMethod() { } - @Test + @ProcessorTest @WithClasses( { MovieFactoryMapper.class, ReleaseFactory.class, @@ -171,7 +168,7 @@ public void testFactorySelectionWithQualifier() { ); } - @Test + @ProcessorTest @IssueKey("342") @WithClasses({ ErroneousMovieFactoryMapper.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java index 48295ed4fb..fe4ec6f7e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/errors/QualfierMessageTest.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.selection.qualifier.errors; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static javax.tools.Diagnostic.Kind.ERROR; @IssueKey("2135") -@RunWith(AnnotationProcessorTestRunner.class) public class QualfierMessageTest { - @Test + @ProcessorTest @WithClasses(ErroneousMessageByAnnotationMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -42,7 +39,7 @@ public class QualfierMessageTest { public void testNoQualifyingMethodByAnnotationFound() { } - @Test + @ProcessorTest @WithClasses(ErroneousMessageByNamedMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -64,7 +61,7 @@ public void testNoQualifyingMethodByAnnotationFound() { public void testNoQualifyingMethodByNamedFound() { } - @Test + @ProcessorTest @WithClasses(ErroneousMessageByAnnotationAndNamedMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -88,7 +85,7 @@ public void testNoQualifyingMethodByNamedFound() { public void testNoQualifyingMethodByAnnotationAndNamedFound() { } - @Test + @ProcessorTest @WithClasses(ErroneousMessageByNamedWithIterableMapper.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java index fc9c48d3a5..3b8d708806 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/hybrid/HybridTest.java @@ -5,18 +5,16 @@ */ package org.mapstruct.ap.test.selection.qualifier.hybrid; -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.selection.qualifier.annotation.EnglishToGerman; import org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated; import org.mapstruct.ap.test.selection.qualifier.annotation.TitleTranslator; import org.mapstruct.ap.test.selection.qualifier.handwritten.SomeOtherMapper; import org.mapstruct.ap.test.selection.qualifier.handwritten.Titles; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @@ -33,10 +31,9 @@ EnglishToGerman.class, TitleTranslator.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class HybridTest { - @Test + @ProcessorTest public void shouldMatchClassAndMethod() { SourceRelease foreignMovies = new SourceRelease(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java index c2465b255e..d55c9f2d00 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/iterable/IterableAndQualifiersTest.java @@ -10,11 +10,9 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.factory.Mappers; /** @@ -34,10 +32,9 @@ TopologyFeatureDto.class, TopologyFeatureEntity.class, } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class IterableAndQualifiersTest { - @Test + @ProcessorTest @WithClasses(TopologyMapper.class) public void testGenerationBasedOnQualifier() { @@ -71,7 +68,7 @@ public void testGenerationBasedOnQualifier() { } - @Test + @ProcessorTest @WithClasses(TopologyWithoutIterableMappingMapper.class) public void testIterableGeneratorBasedOnQualifier() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java index 3de7b1515e..bcb306d9e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/named/NamedTest.java @@ -5,16 +5,11 @@ */ package org.mapstruct.ap.test.selection.qualifier.named; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.entry; - import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.selection.qualifier.annotation.CreateGermanRelease; import org.mapstruct.ap.test.selection.qualifier.annotation.EnglishToGerman; import org.mapstruct.ap.test.selection.qualifier.annotation.NonQualifierAnnotated; @@ -28,8 +23,11 @@ import org.mapstruct.ap.test.selection.qualifier.handwritten.SomeOtherMapper; import org.mapstruct.ap.test.selection.qualifier.handwritten.Titles; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; /** * @@ -43,10 +41,9 @@ SomeOtherMapper.class, NonQualifierAnnotated.class } ) -@RunWith( AnnotationProcessorTestRunner.class ) public class NamedTest { - @Test + @ProcessorTest @WithClasses( { Titles.class, Facts.class, @@ -84,7 +81,7 @@ public void shouldMatchClassAndMethod() { ); } - @Test + @ProcessorTest @WithClasses( { MovieFactoryMapper.class, ReleaseFactory.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 388532bbe8..a6a4f1ad05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -11,14 +11,12 @@ import java.util.Map; import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -34,10 +32,9 @@ Apple.class, AppleDto.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InheritanceSelectionTest { - @Test + @ProcessorTest @WithClasses({ ConflictingFruitFactory.class, ErroneousFruitMapper.class, Banana.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -56,7 +53,7 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() } @IssueKey("1283") - @Test + @ProcessorTest @WithClasses({ ErroneousResultTypeNoAccessibleConstructorMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -71,7 +68,7 @@ public void testForkedInheritanceHierarchyShouldResultInAmbigousMappingMethod() public void testResultTypeHasNoSuitableAccessibleConstructor() { } - @Test + @ProcessorTest @WithClasses({ ConflictingFruitFactory.class, ResultTypeSelectingFruitMapper.class, Banana.class }) public void testResultTypeBasedFactoryMethodSelection() { @@ -82,7 +79,7 @@ public void testResultTypeBasedFactoryMethodSelection() { } - @Test + @ProcessorTest @IssueKey("434") @WithClasses({ ResultTypeConstructingFruitMapper.class }) public void testResultTypeBasedConstructionOfResult() { @@ -93,7 +90,7 @@ public void testResultTypeBasedConstructionOfResult() { assertThat( fruit.getType() ).isEqualTo( "constructed-by-constructor" ); } - @Test + @ProcessorTest @IssueKey("657") @WithClasses({ ResultTypeConstructingFruitInterfaceMapper.class }) public void testResultTypeBasedConstructionOfResultForInterface() { @@ -104,7 +101,7 @@ public void testResultTypeBasedConstructionOfResultForInterface() { assertThat( fruit.getType() ).isEqualTo( "constructed-by-constructor" ); } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -121,7 +118,7 @@ public void testResultTypeBasedConstructionOfResultForInterface() { public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -136,7 +133,7 @@ public void testResultTypeBasedConstructionOfResultForInterfaceErroneous() { public void testResultTypeBasedConstructionOfResultNonAssignable() { } - @Test + @ProcessorTest @IssueKey("433") @WithClasses({ FruitFamilyMapper.class, @@ -160,7 +157,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguity() { } - @Test + @ProcessorTest @IssueKey("433") @WithClasses({ FruitFamilyMapper.class, @@ -182,7 +179,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForIterable() { assertThat( result.get( 0 ).getType() ).isEqualTo( "AppleDto" ); } - @Test + @ProcessorTest @IssueKey("433") @WithClasses({ FruitFamilyMapper.class, @@ -210,7 +207,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() { } - @Test + @ProcessorTest @IssueKey("73") @WithClasses({ Citrus.class, @@ -227,7 +224,7 @@ public void testShouldUseConstructorFromResultTypeForInterface() { assertThat( citrus.getType() ).isEqualTo( "orange" ); } - @Test + @ProcessorTest @IssueKey("73") @WithClasses({ Citrus.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java index 27c33d3bd7..92dcbfe0a4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/TwoStepMappingTest.java @@ -5,18 +5,15 @@ */ package org.mapstruct.ap.test.selection.twosteperror; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -@RunWith( AnnotationProcessorTestRunner.class ) public class TwoStepMappingTest { - @Test + @ProcessorTest @WithClasses(ErroneousMapperMM.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = @Diagnostic( @@ -33,7 +30,7 @@ public class TwoStepMappingTest { public void methodAndMethodTest() { } - @Test + @ProcessorTest @WithClasses( ErroneousMapperCM.class ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -56,7 +53,7 @@ public void methodAndMethodTest() { public void conversionAndMethodTest() { } - @Test + @ProcessorTest @WithClasses( ErroneousMapperMC.class ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java index 362e00331c..e38089eaa5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/typegenerics/WildCardTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.selection.typegenerics; -import static org.assertj.core.api.Assertions.assertThat; - import java.math.BigInteger; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { - @Test + @ProcessorTest @WithClasses( SourceWildCardExtendsMapper.class ) public void testWildCard() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java index 405a22320e..4724748a91 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/wildcards/WildCardTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.selection.wildcards; -import static org.assertj.core.api.Assertions.assertThat; - import java.math.BigInteger; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen * */ -@RunWith(AnnotationProcessorTestRunner.class) public class WildCardTest { - @Test + @ProcessorTest @WithClasses( SourceWildCardExtendsMapper.class ) public void testWildCardAsSourceType() { @@ -38,7 +35,7 @@ public void testWildCardAsSourceType() { assertThat( target.getProp() ).isEqualTo( "5" ); } - @Test + @ProcessorTest @WithClasses( ReturnTypeWildCardExtendsMapper.class ) public void testWildCardAsReturnType() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java index ce386ab7b0..bb31ba1b20 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/ConstantsTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.source.constants; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -22,18 +20,17 @@ * * @author Sjaak Derksen */ -@RunWith( AnnotationProcessorTestRunner.class ) @WithClasses( { ConstantsMapper.class, ConstantsTarget.class } ) public class ConstantsTest { - @Rule - public final GeneratedSource generatedSrc = + @RegisterExtension + final GeneratedSource generatedSrc = new GeneratedSource().addComparisonToFixtureFor( ConstantsMapper.class ); - @Test + @ProcessorTest public void testNumericConstants() { ConstantsTarget target = ConstantsMapper.INSTANCE.mapFromConstants( "dummy" ); @@ -58,7 +55,7 @@ public void testNumericConstants() { assertThat( target.getDoubleBoxedZero() ).isEqualTo( 0.0 ); } - @Test + @ProcessorTest @IssueKey("1458") @WithClasses({ ConstantsTarget.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index 3b307c233c..b331a2efba 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -5,32 +5,28 @@ */ package org.mapstruct.ap.test.source.constants; -import static org.assertj.core.api.Assertions.assertThat; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) public class SourceConstantsTest { - @Test + @ProcessorTest @IssueKey("187, 305") @WithClasses({ Source.class, @@ -57,7 +53,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseE assertThat( target.getCountry() ).isEqualTo( CountryEnum.THE_NETHERLANDS ); } - @Test + @ProcessorTest @IssueKey("187") @WithClasses({ Source.class, @@ -76,7 +72,7 @@ public void shouldMapTargetToSourceWithoutWhining() throws ParseException { assertThat( target.getPropertyThatShouldBeMapped() ).isEqualTo( "SomeProperty" ); } - @Test + @ProcessorTest @IssueKey("187") @WithClasses({ Source.class, @@ -102,7 +98,7 @@ public void shouldMapTargetToSourceWithoutWhining() throws ParseException { public void errorOnSourceAndConstant() throws ParseException { } - @Test + @ProcessorTest @IssueKey("187") @WithClasses({ Source.class, @@ -129,7 +125,7 @@ public void errorOnSourceAndConstant() throws ParseException { public void errorOnConstantAndExpression() throws ParseException { } - @Test + @ProcessorTest @IssueKey("187") @WithClasses({ Source.class, @@ -155,7 +151,7 @@ public void errorOnConstantAndExpression() throws ParseException { public void errorOnSourceAndExpression() throws ParseException { } - @Test + @ProcessorTest @IssueKey("255") @WithClasses({ Source1.class, @@ -177,7 +173,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc assertThat( target.getSomeConstant() ).isEqualTo( "stringConstant" ); } - @Test + @ProcessorTest @IssueKey("700") @WithClasses({ Source.class, @@ -202,7 +198,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetPropertiesFromSeveralSourc public void errorOnNonExistingEnumConstant() throws ParseException { } - @Test + @ProcessorTest @IssueKey("1401") @WithClasses({ Source.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 24b2ee3538..3df90421b3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.source.defaultExpressions.java; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.Date; + +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; - -import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; /** * @author Jeffrey Smyth */ -@RunWith(AnnotationProcessorTestRunner.class) public class JavaDefaultExpressionTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) public void testJavaDefaultExpressionWithValues() { Source source = new Source(); @@ -37,7 +34,7 @@ public void testJavaDefaultExpressionWithValues() { assertThat( target.getSourceDate() ).isEqualTo( source.getDate() ); } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) public void testJavaDefaultExpressionWithNoValues() { Source source = new Source(); @@ -49,7 +46,7 @@ public void testJavaDefaultExpressionWithNoValues() { assertThat( target.getSourceDate() ).isEqualTo( new Date( 30L ) ); } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -70,7 +67,7 @@ public void testJavaDefaultExpressionWithNoValues() { public void testJavaDefaultExpressionExpression() { } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -91,7 +88,7 @@ public void testJavaDefaultExpressionExpression() { public void testJavaDefaultExpressionConstant() { } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { @@ -112,7 +109,7 @@ public void testJavaDefaultExpressionConstant() { public void testJavaDefaultExpressionDefaultValue() { } - @Test + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index 68d19376de..be80644606 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -5,30 +5,27 @@ */ package org.mapstruct.ap.test.source.expressions.java; -import static org.assertj.core.api.Assertions.assertThat; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.source.expressions.java.mapper.TimeAndFormat; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen */ -@RunWith(AnnotationProcessorTestRunner.class) public class JavaExpressionTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, TimeAndFormat.class, SourceTargetMapper.class }) public void testJavaExpressionInsertion() throws ParseException { Source source = new Source(); @@ -47,7 +44,7 @@ public void testJavaExpressionInsertion() throws ParseException { } @IssueKey( "255" ) - @Test + @ProcessorTest @WithClasses({ Source.class, Source2.class, @@ -79,7 +76,7 @@ private Date getTime(String format, String date) throws ParseException { return dateFormat.parse( date ); } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, TimeAndFormat.class, SourceTargetMapper.class }) public void testJavaExpressionInsertionWithExistingTarget() throws ParseException { Source source = new Source(); @@ -100,7 +97,7 @@ public void testJavaExpressionInsertionWithExistingTarget() throws ParseExceptio } @IssueKey( "278" ) - @Test + @ProcessorTest @WithClasses({ SourceBooleanWorkAround.class, TargetBooleanWorkAround.class, @@ -120,7 +117,7 @@ public void testBooleanGetterWorkAround() throws ParseException { } @IssueKey( "305" ) - @Test + @ProcessorTest @WithClasses({ SourceList.class, TargetList.class, @@ -136,7 +133,7 @@ public void testGetterOnly() throws ParseException { } @IssueKey( "1851" ) - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java index f8b6b7306a..5c3bafa231 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/ignore/IgnoreUnmappedSourcePropertiesTest.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.test.source.ignore; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov @@ -19,11 +17,10 @@ Person.class, PersonDto.class }) -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey("1317") public class IgnoreUnmappedSourcePropertiesTest { - @Test + @ProcessorTest public void shouldNotReportErrorOnIgnoredUnmappedSourceProperties() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java index 63aaf8b654..c4c68097f3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manysourcearguments/ManySourceArgumentsTest.java @@ -5,20 +5,18 @@ */ package org.mapstruct.ap.test.source.manysourcearguments; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for propagation of attribute without setter in source and getter in @@ -27,15 +25,14 @@ * @author Gunnar Morling */ @IssueKey("31") -@RunWith(AnnotationProcessorTestRunner.class) public class ManySourceArgumentsTest { - @Before + @BeforeEach public void reset() { ReferencedMapper.setBeforeMappingCalled( false ); } - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -58,7 +55,7 @@ public void shouldMapSeveralSourceAttributesToCombinedTarget() { assertThat( ReferencedMapper.isBeforeMappingCalled() ).isTrue(); } - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -80,7 +77,7 @@ public void shouldMapSeveralSourceAttributesToCombinedTargetWithTargetParameter( assertThat( ReferencedMapper.isBeforeMappingCalled() ).isTrue(); } - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -100,7 +97,7 @@ public void shouldSetAttributesFromNonNullParameters() { assertThat( deliveryAddress.getStreet() ).isNull(); } - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -114,7 +111,7 @@ public void shouldReturnNullIfAllParametersAreNull() { assertThat( deliveryAddress ).isNull(); } - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -135,7 +132,7 @@ public void shouldMapSeveralSourceAttributesAndParameters() { } @IssueKey( "1593" ) - @Test + @ProcessorTest @WithClasses( { Person.class, Address.class, @@ -157,7 +154,7 @@ public void shouldUseConfig() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSourceTargetMapper.class, Address.class, DeliveryAddress.class }) @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "IGNORE") @ExpectedCompilationOutcome( @@ -179,7 +176,7 @@ public void shouldUseConfig() { public void shouldFailToGenerateMappingsForAmbiguousSourceProperty() { } - @Test + @ProcessorTest @WithClasses({ ErroneousSourceTargetMapper2.class, Address.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java index 2da3dc8723..8ab34ceec9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/manytargetproperties/SourceToManyTargetPropertiesTest.java @@ -5,17 +5,15 @@ */ package org.mapstruct.ap.test.source.manytargetproperties; -import static org.assertj.core.api.Assertions.assertThat; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for the generation of implementation of abstract base classes. @@ -26,10 +24,9 @@ Source.class, Target.class, SourceTargetMapper.class, TimeAndFormat.class, TimeAndFormatMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class SourceToManyTargetPropertiesTest { - @Test + @ProcessorTest @IssueKey("94") public void shouldMapSameSourcePropertyToSeveralTargetProperties() { Source source = new Source(); @@ -42,7 +39,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetProperties() { assertThat( target.getName2() ).isEqualTo( "Bob" ); } - @Test + @ProcessorTest @IssueKey("94") public void shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper() throws ParseException { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java index eaa9e85159..c790750f00 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/nullvaluecheckstrategy/PresenceCheckTest.java @@ -5,12 +5,11 @@ */ package org.mapstruct.ap.test.source.nullvaluecheckstrategy; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** * @@ -25,10 +24,9 @@ RockFestivalMapperOveridingConfig.class, Stage.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class PresenceCheckTest { - @Test + @ProcessorTest public void testCallingMappingMethodWithNullSource() { RockFestivalSource source = new RockFestivalSource(); @@ -41,7 +39,7 @@ public void testCallingMappingMethodWithNullSource() { } - @Test + @ProcessorTest public void testCallingMappingMethodWithNullSourceWithConfig() { RockFestivalSource source = new RockFestivalSource(); @@ -54,10 +52,11 @@ public void testCallingMappingMethodWithNullSourceWithConfig() { } - @Test( expected = IllegalArgumentException.class ) + @ProcessorTest public void testCallingMappingMethodWithNullSourceOveridingConfig() { RockFestivalSource source = new RockFestivalSource(); - RockFestivalMapperOveridingConfig.INSTANCE.map( source ); + assertThatThrownBy( () -> RockFestivalMapperOveridingConfig.INSTANCE.map( source ) ) + .isInstanceOf( IllegalArgumentException.class ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java index c25dad70b5..f03172358d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckMappingTest.java @@ -7,20 +7,17 @@ import java.util.Collections; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) public class PresenceCheckMappingTest { - @Test + @ProcessorTest @WithClasses({ CollectionPresenceMapper.class }) @@ -31,7 +28,7 @@ public void collectionPresenceCheckShouldBeUsedByDefault() { assertThat( target.getPlayers() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ CollectionWithNullValueCheckMapper.class }) @@ -44,7 +41,7 @@ public void collectionPresenceCheckShouldBeUsedByWhenNullValueCheckIsAlways() { assertThat( target.getPlayers() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ CollectionWithNonDirectMapper.class }) @@ -56,7 +53,7 @@ public void nonDirectCollectionPresenceCheckShouldBeUsedByDefault() { assertThat( target.getPlayers() ).isNull(); } - @Test + @ProcessorTest @WithClasses({ NonDirectMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java index 1f39810831..45fe8d7e98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckNestedObjectsTest.java @@ -5,13 +5,10 @@ */ package org.mapstruct.ap.test.source.presencecheck.spi; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertFalse; /** * Test for correct handling of source presence checks for nested objects. @@ -25,10 +22,9 @@ SoccerTeamTargetWithPresenceCheck.class, Referee.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class PresenceCheckNestedObjectsTest { - @Test + @ProcessorTest public void testNestedWithSourcesAbsentOnNestingLevel() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); @@ -42,7 +38,7 @@ public void testNestedWithSourcesAbsentOnNestingLevel() { SoccerTeamTargetWithPresenceCheck target = SoccerTeamMapperNestedObjects.INSTANCE.mapNested( soccerTeamSource ); assertThat( target.getGoalKeeperName() ).isNull(); - assertFalse( target.hasGoalKeeperName() ); + assertThat( target.hasGoalKeeperName() ).isFalse(); assertThat( target.getReferee() ).isNotNull(); assertThat( target.getReferee().getName() ).isNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java index 8758ea8e9d..d99bfa343e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/presencecheck/spi/PresenceCheckTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.source.presencecheck.spi; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Test for correct handling of source presence checks. @@ -28,10 +26,9 @@ GoalKeeper.class, SoccerTeamTarget.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class PresenceCheckTest { - @Test + @ProcessorTest public void testWithSourcesPresent() { Source source = new Source(); @@ -49,7 +46,7 @@ public void testWithSourcesPresent() { assertThat( target.getSomeArray() ).isEqualTo( new String[]{ "x", "y"} ); } - @Test + @ProcessorTest public void testWithSourcesAbsent() { Source source = new Source(); @@ -67,7 +64,7 @@ public void testWithSourcesAbsent() { assertThat( target.getSomeArray() ).isNull(); } - @Test + @ProcessorTest public void testUpdateMethodWithSourcesPresent() { Source source = new Source(); @@ -86,7 +83,7 @@ public void testUpdateMethodWithSourcesPresent() { assertThat( target.getSomeArray() ).isEqualTo( new String[]{ "x", "y"} ); } - @Test + @ProcessorTest public void testUpdateMethodWithSourcesAbsent() { Source source = new Source(); @@ -105,7 +102,7 @@ public void testUpdateMethodWithSourcesAbsent() { assertThat( target.getSomeArray() ).isNull(); } - @Test + @ProcessorTest public void testWithSourcesPresentAndDefault() { Source source = new Source(); @@ -123,7 +120,7 @@ public void testWithSourcesPresentAndDefault() { assertThat( target.getSomeArray() ).isEqualTo( new String[]{ "x", "y"} ); } - @Test + @ProcessorTest public void testWithSourcesAbsentAndDefault() { Source source = new Source(); @@ -141,7 +138,7 @@ public void testWithSourcesAbsentAndDefault() { assertThat( target.getSomeArray() ).isEqualTo( new String[]{ "u", "v"} ); } - @Test + @ProcessorTest public void testAdderWithSourcesPresent() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); @@ -152,7 +149,7 @@ public void testAdderWithSourcesPresent() { assertThat( target.getPlayers() ).containsExactly( "pele", "cruyf" ); } - @Test + @ProcessorTest public void testAdderWithSourcesAbsent() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); @@ -163,7 +160,7 @@ public void testAdderWithSourcesAbsent() { assertThat( target.getPlayers() ).isNull(); } - @Test + @ProcessorTest public void testNestedWithSourcesPresent() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); @@ -176,7 +173,7 @@ public void testNestedWithSourcesPresent() { assertThat( target.getGoalKeeperName() ).isEqualTo( "Buffon" ); } - @Test + @ProcessorTest public void testNestedWithSourcesAbsentOnRootLevel() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); @@ -187,7 +184,7 @@ public void testNestedWithSourcesAbsentOnRootLevel() { assertThat( target.getGoalKeeperName() ).isNull(); } - @Test + @ProcessorTest public void testNestedWithSourcesAbsentOnNestingLevel() { SoccerTeamSource soccerTeamSource = new SoccerTeamSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java index 6ef6c29532..5c4f43ba3d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/targetthis/TargetThisMappingTest.java @@ -5,20 +5,17 @@ */ package org.mapstruct.ap.test.targetthis; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Dainius Figoras */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses( { OrderDTO.class, CustomerDTO.class, @@ -30,7 +27,7 @@ } ) public class TargetThisMappingTest { - @Test + @ProcessorTest @WithClasses( SimpleMapper.class ) public void testTargetingThis() { CustomerDTO ce = new CustomerDTO(); @@ -49,7 +46,7 @@ public void testTargetingThis() { assertThat( c.getStatus() ).isEqualTo( ce.getItem().getStatus() ); } - @Test + @ProcessorTest @WithClasses( NestedMapper.class ) public void testTargetingThisWithNestedLevels() { CustomerDTO customerDTO = new CustomerDTO(); @@ -70,7 +67,7 @@ public void testTargetingThisWithNestedLevels() { assertThat( c.getStatus() ).isEqualTo( customerDTO.getItem().getStatus() ); } - @Test + @ProcessorTest @WithClasses( SimpleMapperWithIgnore.class ) public void testTargetingThisWithIgnore() { CustomerDTO ce = new CustomerDTO(); @@ -89,7 +86,7 @@ public void testTargetingThisWithIgnore() { assertThat( c.getStatus() ).isEqualTo( ce.getItem().getStatus() ); } - @Test + @ProcessorTest @WithClasses( ErroneousNestedMapper.class ) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -107,7 +104,7 @@ public void testTargetingThisWithIgnore() { public void testNestedDuplicates() { } - @Test + @ProcessorTest @WithClasses( ConfictsResolvedNestedMapper.class ) public void testWithConflictsResolved() { @@ -128,7 +125,7 @@ public void testWithConflictsResolved() { assertThat( c.getId() ).isEqualTo( orderDTO.getCustomer().getItem().getId() ); } - @Test + @ProcessorTest @WithClasses( FlatteningMapper.class ) public void testFlattening() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java index f5eda7024d..0b50591a7a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/template/InheritConfigurationTest.java @@ -5,33 +5,29 @@ */ package org.mapstruct.ap.test.template; - -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.template.erroneous.SourceTargetMapperAmbiguous1; import org.mapstruct.ap.test.template.erroneous.SourceTargetMapperAmbiguous2; import org.mapstruct.ap.test.template.erroneous.SourceTargetMapperAmbiguous3; import org.mapstruct.ap.test.template.erroneous.SourceTargetMapperNonMatchingName; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Sjaak Derksen */ @IssueKey("383") @WithClasses({ Source.class, NestedSource.class, Target.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class InheritConfigurationTest { - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperSingle.class }) public void shouldInheritConfigurationSingleCandidates() { @@ -58,7 +54,7 @@ public void shouldInheritConfigurationSingleCandidates() { assertThat( updatedTarget.getConstantProp() ).isEqualTo( "constant" ); } - @Test + @ProcessorTest @WithClasses( { SourceTargetMapperMultiple.class } ) public void shouldInheritConfigurationMultipleCandidates() { @@ -86,7 +82,7 @@ public void shouldInheritConfigurationMultipleCandidates() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperSeveralArgs.class }) public void shouldInheritConfigurationSeveralArgs() { @@ -114,7 +110,7 @@ public void shouldInheritConfigurationSeveralArgs() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous1.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -134,7 +130,7 @@ public void shouldInheritConfigurationSeveralArgs() { public void shouldRaiseAmbiguousReverseMethodError() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous2.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -154,7 +150,7 @@ public void shouldRaiseAmbiguousReverseMethodError() { public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperAmbiguous3.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -176,7 +172,7 @@ public void shouldRaiseAmbiguousReverseMethodErrorWrongName() { public void shouldRaiseAmbiguousReverseMethodErrorDuplicatedName() { } - @Test + @ProcessorTest @WithClasses({ SourceTargetMapperNonMatchingName.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 0adcb9e0ff..59d44a6baf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -5,29 +5,26 @@ */ package org.mapstruct.ap.test.unmappedsource; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.test.unmappedtarget.Source; +import org.mapstruct.ap.test.unmappedtarget.Target; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; -import org.mapstruct.ap.test.unmappedtarget.Source; -import org.mapstruct.ap.test.unmappedtarget.Target; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests expected diagnostics for unmapped source properties. * * @author Gunnar Morling */ -@RunWith(AnnotationProcessorTestRunner.class) public class UnmappedSourceTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, @@ -53,7 +50,7 @@ public void shouldLeaveUnmappedSourcePropertyUnset() { assertThat( target.getBar() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, ErroneousStrictSourceTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index 4a31fb93ea..a36ec31436 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -5,19 +5,17 @@ */ package org.mapstruct.ap.test.unmappedtarget; -import static org.assertj.core.api.Assertions.assertThat; - import javax.tools.Diagnostic.Kind; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; + +import static org.assertj.core.api.Assertions.assertThat; /** * Tests expected diagnostics for unmapped target properties. @@ -25,10 +23,9 @@ * @author Gunnar Morling */ @IssueKey("35") -@RunWith(AnnotationProcessorTestRunner.class) public class UnmappedProductTest { - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, @@ -54,7 +51,7 @@ public void shouldLeaveUnmappedTargetPropertyUnset() { assertThat( target.getBar() ).isEqualTo( 0 ); } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, ErroneousStrictSourceTargetMapper.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -72,7 +69,7 @@ public void shouldLeaveUnmappedTargetPropertyUnset() { public void shouldRaiseErrorDueToUnsetTargetProperty() { } - @Test + @ProcessorTest @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ERROR") @ExpectedCompilationOutcome( diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java index d7e5bdea43..d681f0eabe 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/UpdateMethodsTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.updatemethods; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -23,7 +21,6 @@ * @author Sjaak Derksen */ @IssueKey("160") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ OrganizationDto.class, OrganizationEntity.class, @@ -41,10 +38,10 @@ }) public class UpdateMethodsTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses( { OrganizationMapper.class } ) @@ -73,7 +70,7 @@ public void testPreferUpdateMethod() { assertThat( organizationEntity.getCompany().getDepartment().getName() ).isEqualTo( "finance" ); } - @Test + @ProcessorTest @WithClasses( { OrganizationMapper.class } ) @@ -98,7 +95,7 @@ public void testUpdateMethodClearsExistingValues() { assertThat( organizationEntity.getTypeNr().getNumber() ).isEqualTo( 5 ); } - @Test + @ProcessorTest @WithClasses({ OrganizationMapper.class }) @@ -123,7 +120,7 @@ public void testPreferUpdateMethodSourceObjectNotDefined() { assertThat( organizationEntity.getCompany().getDepartment().getName() ).isEqualTo( "finance" ); } - @Test + @ProcessorTest @WithClasses( { CompanyMapper.class, DepartmentInBetween.class @@ -144,7 +141,7 @@ public void testPreferUpdateMethodEncapsulatingCreateMethod() { } - @Test + @ProcessorTest @WithClasses( { ErroneousOrganizationMapper1.class, OrganizationWithoutCompanyGetterEntity.class @@ -160,7 +157,7 @@ public void testPreferUpdateMethodEncapsulatingCreateMethod() { ) public void testShouldFailOnPropertyMappingNoPropertyGetter() { } - @Test + @ProcessorTest @WithClasses({ ErroneousOrganizationMapper2.class, OrganizationWithoutTypeGetterEntity.class @@ -181,7 +178,7 @@ public void testShouldFailOnPropertyMappingNoPropertyGetter() { } public void testShouldFailOnConstantMappingNoPropertyGetter() { } - @Test + @ProcessorTest @WithClasses({ CompanyMapper1.class, DepartmentInBetween.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java index 8a6ac225a6..081bd8bc01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/manysourcearguments/ManyArgumentsUpdateMappingTest.java @@ -8,11 +8,9 @@ import java.time.LocalDate; import java.time.Month; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @@ -20,7 +18,6 @@ * @author Filip Hrisafov */ @IssueKey("2274") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ ExampleMapper.class, ExampleMember.class, @@ -29,7 +26,7 @@ }) public class ManyArgumentsUpdateMappingTest { - @Test + @ProcessorTest public void shouldUpdateToNullIfSourceParametersAreNull() { ExampleTarget target = new ExampleTarget(); target.setBirthday( LocalDate.of( 2020, Month.NOVEMBER, 15 ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java index 8c10656ae4..23f75115b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/updatemethods/selection/ExternalSelectionTest.java @@ -9,9 +9,7 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.updatemethods.BossDto; import org.mapstruct.ap.test.updatemethods.BossEntity; import org.mapstruct.ap.test.updatemethods.CompanyDto; @@ -25,8 +23,8 @@ import org.mapstruct.ap.test.updatemethods.SecretaryDto; import org.mapstruct.ap.test.updatemethods.SecretaryEntity; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +34,6 @@ * @author Sjaak Derksen */ @IssueKey("160") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ OrganizationMapper1.class, ExternalMapper.class, @@ -57,14 +54,14 @@ }) public class ExternalSelectionTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( OrganizationMapper1.class, ExternalMapper.class, DepartmentMapper.class ); - @Test + @ProcessorTest @WithClasses({ OrganizationMapper1.class }) @@ -76,7 +73,7 @@ public void shouldSelectGeneratedExternalMapper() { OrganizationMapper1.INSTANCE.toCompanyEntity( dto, entity ); } - @Test + @ProcessorTest @WithClasses({ OrganizationMapper3.class }) @@ -89,7 +86,7 @@ public void shouldSelectGeneratedExternalMapperWithImportForPropertyType() { OrganizationMapper3.INSTANCE.toBossEntity( dto, entity ); } - @Test + @ProcessorTest @WithClasses({ OrganizationMapper2.class }) @@ -101,7 +98,7 @@ public void shouldSelectGeneratedHandWrittenExternalMapper() { OrganizationMapper2.INSTANCE.toCompanyEntity( dto, entity ); } - @Test + @ProcessorTest @IssueKey( "487" ) public void shouldSelectGeneratedExternalMapperForIterablesAndMaps() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java index 1e93f4b00d..30eeda4737 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumMappingTest.java @@ -7,17 +7,15 @@ import javax.tools.Diagnostic.Kind; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.value.ExternalOrderType; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -32,17 +30,16 @@ OrderMapper.class, SpecialOrderMapper.class, DefaultOrderMapper.class, OrderEntity.class, OrderType.class, OrderDto.class, ExternalOrderType.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class EnumToEnumMappingTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( DefaultOrderMapper.class, OrderMapper.class, SpecialOrderMapper.class ); - @Test + @ProcessorTest public void shouldGenerateEnumMappingMethod() { ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.B2B ); assertThat( target ).isEqualTo( ExternalOrderType.B2B ); @@ -51,7 +48,7 @@ public void shouldGenerateEnumMappingMethod() { assertThat( target ).isEqualTo( ExternalOrderType.RETAIL ); } - @Test + @ProcessorTest public void shouldConsiderConstantMappings() { ExternalOrderType target = OrderMapper.INSTANCE.orderTypeToExternalOrderType( OrderType.EXTRA ); assertThat( target ).isEqualTo( ExternalOrderType.SPECIAL ); @@ -63,7 +60,7 @@ public void shouldConsiderConstantMappings() { assertThat( target ).isEqualTo( ExternalOrderType.DEFAULT ); } - @Test + @ProcessorTest public void shouldInvokeEnumMappingMethodForPropertyMapping() { OrderEntity order = new OrderEntity(); order.setOrderType( OrderType.EXTRA ); @@ -73,7 +70,7 @@ public void shouldInvokeEnumMappingMethodForPropertyMapping() { assertThat( orderDto.getOrderType() ).isEqualTo( ExternalOrderType.SPECIAL ); } - @Test + @ProcessorTest public void shouldApplyReverseMappings() { OrderType result = OrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); @@ -90,7 +87,7 @@ public void shouldApplyReverseMappings() { } - @Test + @ProcessorTest public void shouldApplyNullMapping() { OrderEntity order = new OrderEntity(); order.setOrderType( null ); @@ -100,7 +97,7 @@ public void shouldApplyNullMapping() { assertThat( orderDto.getOrderType() ).isEqualTo( ExternalOrderType.DEFAULT ); } - @Test + @ProcessorTest public void shouldApplyTargetIsNullMapping() { OrderEntity order = new OrderEntity(); order.setOrderType( OrderType.STANDARD ); @@ -110,7 +107,7 @@ public void shouldApplyTargetIsNullMapping() { assertThat( orderDto.getOrderType() ).isNull(); } - @Test + @ProcessorTest public void shouldApplyDefaultMappings() { OrderEntity order = new OrderEntity(); @@ -140,7 +137,7 @@ public void shouldApplyDefaultMappings() { assertThat( orderDto.getOrderType() ).isEqualTo( ExternalOrderType.RETAIL ); } - @Test + @ProcessorTest public void shouldApplyDefaultReverseMappings() { OrderType result = SpecialOrderMapper.INSTANCE.externalOrderTypeToOrderType( ExternalOrderType.SPECIAL ); @@ -157,7 +154,7 @@ public void shouldApplyDefaultReverseMappings() { } - @Test + @ProcessorTest public void shouldMappAllUnmappedToDefault() { OrderEntity order = new OrderEntity(); @@ -189,7 +186,7 @@ public void shouldMappAllUnmappedToDefault() { } @IssueKey("1091") - @Test + @ProcessorTest public void shouldMapAnyRemainingToNullCorrectly() { ExternalOrderType externalOrderType = SpecialOrderMapper.INSTANCE.anyRemainingToNull( OrderType.RETAIL ); assertThat( externalOrderType ) @@ -211,7 +208,7 @@ public void shouldMapAnyRemainingToNullCorrectly() { assertThat( externalOrderType ).isNull(); } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperMappingSameConstantTwice.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -225,7 +222,7 @@ public void shouldMapAnyRemainingToNullCorrectly() { public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperUsingUnknownEnumConstants.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -244,7 +241,7 @@ public void shouldRaiseErrorIfSameSourceEnumConstantIsMappedTwice() { public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperNotMappingConstantWithoutMatchInTargetType.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -259,7 +256,7 @@ public void shouldRaiseErrorIfUnknownEnumConstantsAreSpecifiedInMapping() { public void shouldRaiseErrorIfSourceConstantWithoutMatchingConstantInTargetTypeIsNotMapped() { } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperDuplicateANY.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java index 15f0d7964d..0ee778304c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2enum/EnumToEnumThrowExceptionMappingTest.java @@ -5,16 +5,14 @@ */ package org.mapstruct.ap.test.value.enum2enum; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.value.ExternalOrderType; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -27,11 +25,10 @@ OrderEntity.class, OrderType.class, ExternalOrderType.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class EnumToEnumThrowExceptionMappingTest { @IssueKey("2339") - @Test + @ProcessorTest @WithClasses(DefaultOrderThrowExceptionMapper.class) public void shouldBeAbleToMapAnyUnmappedToThrowException() { @@ -43,7 +40,7 @@ public void shouldBeAbleToMapAnyUnmappedToThrowException() { } @IssueKey("2339") - @Test + @ProcessorTest @WithClasses({ DefaultOrderThrowExceptionMapper.class, ErroneousOrderMapperThrowExceptionAsSourceType.class }) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -59,7 +56,7 @@ public void shouldRaiseErrorWhenThrowExceptionUsedAsSourceType() { } @IssueKey("2339") - @Test + @ProcessorTest @WithClasses({OrderThrowExceptionMapper.class, OrderDto.class}) public void shouldIgnoreThrowExceptionWhenInverseValueMappings() { @@ -68,7 +65,7 @@ public void shouldIgnoreThrowExceptionWhenInverseValueMappings() { } @IssueKey("2339") - @Test + @ProcessorTest @WithClasses({SpecialThrowExceptionMapper.class, OrderDto.class}) public void shouldBeAbleToMapAnyRemainingToThrowException() { @@ -80,7 +77,7 @@ public void shouldBeAbleToMapAnyRemainingToThrowException() { } @IssueKey("2339") - @Test + @ProcessorTest @WithClasses({SpecialThrowExceptionMapper.class, OrderDto.class}) public void shouldBeAbleToMapNullToThrowException() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java index 145721b83d..cdf0fd8e99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/enum2string/EnumToStringMappingTest.java @@ -5,24 +5,21 @@ */ package org.mapstruct.ap.test.value.enum2string; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; @IssueKey( "1557" ) @WithClasses({ OrderType.class, OrderMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class EnumToStringMappingTest { - @Test + @ProcessorTest public void testTheNormalStuff() { assertThat( OrderMapper.INSTANCE.mapNormal( null ) ).isNull(); assertThat( OrderMapper.INSTANCE.mapNormal( OrderType.EXTRA ) ).isEqualTo( "SPECIAL" ); @@ -32,7 +29,7 @@ public void testTheNormalStuff() { assertThat( OrderMapper.INSTANCE.mapNormal( OrderType.RETAIL ) ).isEqualTo( "RETAIL" ); } - @Test + @ProcessorTest public void testRemainingAndNull() { assertThat( OrderMapper.INSTANCE.withAnyUnmappedAndNull( null ) ).isEqualTo( "DEFAULT" ); assertThat( OrderMapper.INSTANCE.withAnyUnmappedAndNull( OrderType.STANDARD ) ).isNull(); @@ -42,7 +39,7 @@ public void testRemainingAndNull() { assertThat( OrderMapper.INSTANCE.withAnyUnmappedAndNull( OrderType.EXTRA ) ).isEqualTo( "SPECIAL" ); } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperUsingAnyRemaining.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java index 45d374f217..424947fd98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/erroneous/ErroneousEnumMappingTest.java @@ -5,23 +5,20 @@ */ package org.mapstruct.ap.test.value.erroneous; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.value.CustomIllegalArgumentException; import org.mapstruct.ap.test.value.ExternalOrderType; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; /** * @author Filip Hrisafov */ @IssueKey("2169") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CustomIllegalArgumentException.class, ExternalOrderType.class, @@ -29,7 +26,7 @@ }) public class ErroneousEnumMappingTest { - @Test + @ProcessorTest @WithClasses({ EmptyEnumMappingMapper.class }) @@ -46,7 +43,7 @@ public class ErroneousEnumMappingTest { public void shouldCompileErrorWhenEnumMappingIsEmpty() { } - @Test + @ProcessorTest @WithClasses({ NoConfigurationEnumMappingMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java index fbbf702854..76ef4866c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/exception/CustomUnexpectedValueMappingExceptionTest.java @@ -5,22 +5,19 @@ */ package org.mapstruct.ap.test.value.exception; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.value.CustomIllegalArgumentException; import org.mapstruct.ap.test.value.ExternalOrderType; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Filip Hrisafov */ @IssueKey("2169") -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ Config.class, CustomUnexpectedValueMappingExceptionDefinedInMapper.class, @@ -33,10 +30,10 @@ }) public class CustomUnexpectedValueMappingExceptionTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest public void shouldGenerateCustomUnexpectedValueMappingException() { generatedSource.addComparisonToFixtureFor( CustomUnexpectedValueMappingExceptionDefinedInMapper.class, diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java index d5de5e872f..c27128edb6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.value.nametransformation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CheeseType.class, CheeseTypeSuffixed.class, @@ -28,7 +25,7 @@ }) public class EnumNameTransformationStrategyTest { - @Test + @ProcessorTest @WithClasses({ CheeseSuffixMapper.class }) @@ -43,7 +40,7 @@ public void shouldApplySuffixAndStripSuffixOnEnumToEnumMapping() { .isEqualTo( CheeseType.BRIE ); } - @Test + @ProcessorTest @WithClasses({ CheesePrefixMapper.class }) @@ -58,7 +55,7 @@ public void shouldApplyPrefixAndStripPrefixOnEnumToEnumMapping() { .isEqualTo( CheeseType.BRIE ); } - @Test + @ProcessorTest @WithClasses({ CheeseEnumToStringSuffixMapper.class }) @@ -71,7 +68,7 @@ public void shouldApplySuffixAndStripSuffixOnEnumToStringMapping() { assertThat( mapper.mapStripSuffix( "DEFAULT" ) ).isEqualTo( CheeseTypeSuffixed.DEFAULT ); } - @Test + @ProcessorTest @WithClasses({ CheeseEnumToStringPrefixMapper.class }) @@ -84,7 +81,7 @@ public void shouldApplyPrefixAndStripPrefixOnEnumToStringMapping() { assertThat( mapper.mapStripPrefix( "DEFAULT" ) ).isEqualTo( CheeseTypePrefixed.DEFAULT ); } - @Test + @ProcessorTest @WithClasses({ ErroneousNameTransformStrategyMapper.class }) @@ -102,7 +99,7 @@ public void shouldApplyPrefixAndStripPrefixOnEnumToStringMapping() { public void shouldGiveCompileErrorWhenUsingUnknownNameTransformStrategy() { } - @Test + @ProcessorTest @WithClasses({ ErroneousNameTransformStrategyMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java index 313a7553bb..e4cc708838 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomEnumMappingStrategyTest.java @@ -5,14 +5,12 @@ */ package org.mapstruct.ap.test.value.spi; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.value.CustomIllegalArgumentException; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -21,7 +19,6 @@ /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CheeseType.class, CustomCheeseType.class, @@ -33,10 +30,10 @@ @WithServiceImplementation(CustomEnumMappingStrategy.class) public class CustomEnumMappingStrategyTest { - @Rule - public final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Test + @ProcessorTest @WithClasses({ CustomCheeseMapper.class }) @@ -82,7 +79,7 @@ public void shouldApplyCustomEnumMappingStrategy() { assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); } - @Test + @ProcessorTest @WithClasses({ OverridesCustomCheeseMapper.class }) @@ -127,7 +124,7 @@ public void shouldApplyDefinedMappingsInsteadOfCustomEnumMappingStrategy() { assertThat( mapper.mapStringToCustom( "UNKNOWN" ) ).isEqualTo( CustomCheeseType.CUSTOM_BRIE ); } - @Test + @ProcessorTest @IssueKey("2339") @WithClasses({ CustomThrowingCheeseMapper.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java index 9cb1337bc8..840c659430 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/spi/CustomErroneousEnumMappingStrategyTest.java @@ -5,21 +5,18 @@ */ package org.mapstruct.ap.test.value.spi; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; /** * @author Filip Hrisafov */ -@RunWith(AnnotationProcessorTestRunner.class) @WithClasses({ CheeseType.class, CustomCheeseType.class, @@ -28,7 +25,7 @@ @WithServiceImplementation(CustomErroneousEnumMappingStrategy.class) public class CustomErroneousEnumMappingStrategyTest { - @Test + @ProcessorTest @WithClasses({ CustomCheeseMapper.class }) @@ -55,7 +52,7 @@ public class CustomErroneousEnumMappingStrategyTest { public void shouldThrowCompileErrorWhenDefaultEnumDoesNotExist() { } - @Test + @ProcessorTest @WithClasses({ OverridesCustomCheeseMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java index fea8efac12..7642887aae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/string2enum/StringToEnumMappingTest.java @@ -5,25 +5,22 @@ */ package org.mapstruct.ap.test.value.string2enum; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.test.value.OrderType; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @IssueKey( "1557" ) @WithClasses({ OrderType.class, OrderMapper.class }) -@RunWith(AnnotationProcessorTestRunner.class) public class StringToEnumMappingTest { - @Test + @ProcessorTest public void testTheNormalStuff() { assertThat( OrderMapper.INSTANCE.mapNormal( null ) ).isNull(); assertThat( OrderMapper.INSTANCE.mapNormal( "SPECIAL" ) ).isEqualTo( OrderType.EXTRA ); @@ -35,14 +32,14 @@ public void testTheNormalStuff() { assertThat( OrderMapper.INSTANCE.mapNormal( "blah" ) ).isEqualTo( OrderType.RETAIL ); } - @Test + @ProcessorTest public void testRemainingAndNull() { assertThat( OrderMapper.INSTANCE.mapWithAnyUnmapped( null ) ).isEqualTo( OrderType.STANDARD ); assertThat( OrderMapper.INSTANCE.mapWithAnyUnmapped( "DEFAULT" ) ).isNull(); assertThat( OrderMapper.INSTANCE.mapWithAnyUnmapped( "BLAH" ) ).isEqualTo( OrderType.RETAIL ); } - @Test + @ProcessorTest @WithClasses(ErroneousOrderMapperUsingNoAnyRemainingAndNoAnyUnmapped.class) @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java index fd17eed070..ac7add9d80 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/verbose/VerboseTest.java @@ -5,15 +5,13 @@ */ package org.mapstruct.ap.test.verbose; -import org.junit.Test; -import org.junit.runner.RunWith; import org.mapstruct.ap.spi.AccessorNamingStrategy; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderProvider; import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesBuilderProvider; - import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -21,19 +19,12 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.Compiler; -import org.mapstruct.ap.testutil.runner.DisabledOnCompiler; @IssueKey("37") -@RunWith(AnnotationProcessorTestRunner.class) public class VerboseTest { - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses({ CreateBeanMapping.class, CreateBeanMappingConfig.class }) @ExpectedNote("^MapStruct: Using accessor naming strategy:.*DefaultAccessorNamingStrategy.*$") @@ -43,11 +34,7 @@ public class VerboseTest { public void testGeneralMessages() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @WithServiceImplementation(provides = BuilderProvider.class, value = ImmutablesBuilderProvider.class) @WithServiceImplementation(provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) @ProcessorOption(name = "mapstruct.verbose", value = "true") @@ -59,11 +46,7 @@ public void testGeneralMessages() { public void testGeneralWithOtherSPI() { } - @Test - @DisabledOnCompiler({ - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - }) + @ProcessorTest(Compiler.JDK) @WithServiceImplementation(provides = AstModifyingAnnotationProcessor.class, value = AstModifyingAnnotationProcessorSaysNo.class) @ProcessorOption(name = "mapstruct.verbose", value = "true") @@ -83,11 +66,7 @@ public void testGeneralWithOtherSPI() { public void testDeferred() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses({ CreateBeanMapping.class, CreateBeanMappingConfig.class }) @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") @@ -95,11 +74,7 @@ public void testDeferred() { public void testCreateBeanMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectBeanMapping.class) @ExpectedNote("^- MapStruct: creating bean mapping method implementation for.*$") @@ -107,22 +82,14 @@ public void testCreateBeanMapping() { public void testSelectBeanMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(ValueMapping.class) @ExpectedNote("^- MapStruct: creating value mapping method implementation for.*$") public void testValueMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(CreateIterableMapping.class) @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") @@ -130,11 +97,7 @@ public void testValueMapping() { public void testVerboseCreateIterableMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectIterableMapping.class) @ExpectedNote("^- MapStruct: creating iterable mapping method implementation for.*$") @@ -142,22 +105,14 @@ public void testVerboseCreateIterableMapping() { public void testVerboseSelectingIterableMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectStreamMapping.class) @ExpectedNote("^- MapStruct: creating stream mapping method implementation for.*$") public void testVerboseSelectingStreamMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(CreateMapMapping.class) @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") @@ -166,11 +121,7 @@ public void testVerboseSelectingStreamMapping() { public void testVerboseCreateMapMapping() { } - @Test - @DisabledOnCompiler( { - Compiler.ECLIPSE, - Compiler.ECLIPSE11 - } ) + @ProcessorTest(Compiler.JDK) @ProcessorOption(name = "mapstruct.verbose", value = "true") @WithClasses(SelectMapMapping.class) @ExpectedNote("^- MapStruct: creating map mapping method implementation for.*$") diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java index 67c716468c..1eec91b951 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java @@ -5,32 +5,25 @@ */ package org.mapstruct.ap.test.versioninfo; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOptions; -import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; import org.mapstruct.ap.testutil.runner.GeneratedSource; /** * @author Andreas Gudian * */ -@RunWith( AnnotationProcessorTestRunner.class ) @IssueKey( "424" ) @WithClasses( SimpleMapper.class ) public class VersionInfoTest { - private final GeneratedSource generatedSource = new GeneratedSource(); + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); - @Rule - public GeneratedSource getGeneratedSource() { - return generatedSource; - } - - @Test + @ProcessorTest @ProcessorOption( name = "mapstruct.suppressGeneratorVersionInfoComment", value = "true" ) public void includesNoComment() { generatedSource.forMapper( SimpleMapper.class ).content() @@ -38,7 +31,7 @@ public void includesNoComment() { .doesNotContain( "comments = \"version: " ); } - @Test + @ProcessorTest @ProcessorOptions( { @ProcessorOption( name = "mapstruct.suppressGeneratorVersionInfoComment", value = "true" ), @ProcessorOption( name = "mapstruct.suppressGeneratorTimestamp", value = "true" ) @@ -49,7 +42,7 @@ public void includesNoCommentAndNoTimestamp() { .doesNotContain( "comments = \"version: " ); } - @Test + @ProcessorTest public void includesCommentAndTimestamp() { generatedSource.forMapper( SimpleMapper.class ).content() .contains( "date = \"" ) From 627be5308855aa257826beeaccf570390de195f0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 25 Apr 2021 12:39:04 +0200 Subject: [PATCH 0569/1006] Migrate mapstruct core tests to JUnit Jupiter --- core/pom.xml | 4 ++-- core/src/test/java/org/mapstruct/factory/MappersTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index b02b809ed7..10c95cf3b5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -22,8 +22,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/core/src/test/java/org/mapstruct/factory/MappersTest.java b/core/src/test/java/org/mapstruct/factory/MappersTest.java index 60371cada8..6118ba09cb 100644 --- a/core/src/test/java/org/mapstruct/factory/MappersTest.java +++ b/core/src/test/java/org/mapstruct/factory/MappersTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.test.model.Foo; import org.mapstruct.test.model.SomeClass; From 0cb053df8d0d8cf3f1370f6afa76c98c5c62b3ce Mon Sep 17 00:00:00 2001 From: "jason.bodnar@blackbaud.com" Date: Tue, 23 Mar 2021 13:40:30 -0500 Subject: [PATCH 0570/1006] #2391 Add implicit conversion between UUID <-> String --- .../chapter-5-data-type-conversions.asciidoc | 7 ++- .../internal/conversion/ConversionUtils.java | 12 ++++ .../ap/internal/conversion/Conversions.java | 3 + .../conversion/UUIDToStringConversion.java | 37 ++++++++++++ .../conversion/uuid/UUIDConversionTest.java | 56 +++++++++++++++++++ .../ap/test/conversion/uuid/UUIDMapper.java | 19 +++++++ .../ap/test/conversion/uuid/UUIDSource.java | 33 +++++++++++ .../ap/test/conversion/uuid/UUIDTarget.java | 30 ++++++++++ 8 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/UUIDToStringConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDTarget.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 7800b6a933..24f019fa63 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -115,7 +115,10 @@ public interface CarMapper { * When converting from a `String`, omitting `Mapping#dateFormat`, it leads to usage of the default pattern and date format symbols for the default locale. An exception to this rule is `XmlGregorianCalendar` which results in parsing the `String` according to http://www.w3.org/TR/xmlschema-2/#dateTime[XML Schema 1.0 Part 2, Section 3.2.7-14.1, Lexical Representation]. * Between `java.util.Currency` and `String`. -** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown +** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/ISO_4217[ISO-4217] alphabetic code otherwise an `IllegalArgumentException` is thrown. + +* Between `java.util.UUID` and `String`. +** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/Universally_unique_identifier[UUID] otherwise an `IllegalArgumentException` is thrown. * Between `String` and `StringBuilder` @@ -326,7 +329,7 @@ public abstract class FishTankMapperWithVolume { ---- ==== -Note the `@Mapping` annotation where `source` field is equal to `"source"`, indicating the parameter name `source` itself in the method `map(FishTank source)` instead of a (target) property in `FishTank`. +Note the `@Mapping` annotation where `source` field is equal to `"source"`, indicating the parameter name `source` itself in the method `map(FishTank source)` instead of a (target) property in `FishTank`. [[invoking-other-mappers]] diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index 2afcf3c6ad..20fb8a2fee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -18,6 +18,7 @@ import java.time.format.DateTimeFormatter; import java.util.Currency; import java.util.Locale; +import java.util.UUID; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.util.JodaTimeConstants; @@ -242,4 +243,15 @@ public static String dateTimeFormat(ConversionContext conversionContext) { public static String stringBuilder(ConversionContext conversionContext) { return typeReferenceName( conversionContext, StringBuilder.class ); } + + /** + * Name for {@link java.util.UUID}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String uuid(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, UUID.class ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 02c478bb70..4b3ab2a818 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.UUID; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -190,6 +191,8 @@ public Conversions(TypeFactory typeFactory) { // java.util.Currency <~> String register( Currency.class, String.class, new CurrencyToStringConversion() ); + + register( UUID.class, String.class, new UUIDToStringConversion() ); } private void registerJodaConversions() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/UUIDToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/UUIDToStringConversion.java new file mode 100644 index 0000000000..b07d799387 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/UUIDToStringConversion.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.util.Set; +import java.util.UUID; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.uuid; + +/** + * Conversion between {@link java.util.UUID} and {@link String}. + * + * @author Jason Bodnar + */ +public class UUIDToStringConversion extends SimpleConversion { + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toString()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return uuid( conversionContext ) + ".fromString( )"; + } + + @Override + protected Set getFromConversionImportTypes(final ConversionContext conversionContext) { + return Collections.asSet( conversionContext.getTypeFactory().getType( UUID.class ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDConversionTest.java new file mode 100644 index 0000000000..51eab29cda --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDConversionTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uuid; + +import java.util.UUID; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Tests conversions between {@link java.util.UUID} and String. + * + * @author Jason Bodnar + */ +@IssueKey("2391") +@WithClasses({ UUIDSource.class, UUIDTarget.class, UUIDMapper.class }) +public class UUIDConversionTest { + + @ProcessorTest + public void shouldApplyUUIDConversion() { + UUIDSource source = new UUIDSource(); + source.setUUIDA( UUID.randomUUID() ); + + UUIDTarget target = UUIDMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getUUIDA() ).isEqualTo( source.getUUIDA().toString() ); + } + + @ProcessorTest + public void shouldApplyReverseUUIDConversion() { + UUIDTarget target = new UUIDTarget(); + target.setUUIDA( UUID.randomUUID().toString() ); + + UUIDSource source = UUIDMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getUUIDA() ).isEqualTo( UUID.fromString( target.getUUIDA() ) ); + } + + @ProcessorTest + public void shouldHandleInvalidUUIDString() { + UUIDTarget target = new UUIDTarget(); + target.setInvalidUUID( "XXXXXXXXX" ); + + assertThatThrownBy( () -> UUIDMapper.INSTANCE.targetToSource( target ) ) + .isInstanceOf( IllegalArgumentException.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDMapper.java new file mode 100644 index 0000000000..8430b0fdce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uuid; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface UUIDMapper { + + UUIDMapper INSTANCE = Mappers.getMapper( UUIDMapper.class ); + + UUIDTarget sourceToTarget(UUIDSource source); + + UUIDSource targetToSource(UUIDTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDSource.java new file mode 100644 index 0000000000..220ce5a76a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDSource.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uuid; + +import java.util.UUID; + +/** + * @author Jason Bodnar + */ +public class UUIDSource { + private UUID uuidA; + + private UUID invalidUUID; + + public UUID getUUIDA() { + return this.uuidA; + } + + public void setUUIDA(final UUID uuidA) { + this.uuidA = uuidA; + } + + public UUID getInvalidUUID() { + return invalidUUID; + } + + public void setInvalidUUID(final UUID invalidUUID) { + this.invalidUUID = invalidUUID; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDTarget.java new file mode 100644 index 0000000000..4fd2558141 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uuid/UUIDTarget.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uuid; + +/** + * @author Jason Bodnar + */ +public class UUIDTarget { + private String uuidA; + private String invalidUUID; + + public String getUUIDA() { + return this.uuidA; + } + + public void setUUIDA(final String uuidA) { + this.uuidA = uuidA; + } + + public String getInvalidUUID() { + return this.invalidUUID; + } + + public void setInvalidUUID(final String invalidUUID) { + this.invalidUUID = invalidUUID; + } +} From 5c22eee6c327aa893109f098d5a7cc2b5976cdc1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Apr 2021 20:09:14 +0000 Subject: [PATCH 0571/1006] Bump commons-io from 2.6 to 2.7 in /parent Bumps commons-io from 2.6 to 2.7. Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index c7ac37a41d..c1172cbfe0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -261,7 +261,7 @@ commons-io commons-io - 2.6 + 2.7 From fdf3dcc8efaf0cdc1a2145dd53c1302346e2838a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Bassinello?= Date: Thu, 6 May 2021 15:13:13 -0300 Subject: [PATCH 0572/1006] #2445 Support for case changing enum transformation strategy Available case transformations: upper, lower, capital --- .../main/java/org/mapstruct/EnumMapping.java | 12 ++++ .../java/org/mapstruct/MappingConstants.java | 8 +++ .../chapter-8-mapping-values.asciidoc | 4 ++ .../ap/internal/gem/MappingConstantsGem.java | 2 + .../spi/CaseEnumTransformationStrategy.java | 59 +++++++++++++++ ...apstruct.ap.spi.EnumTransformationStrategy | 1 + .../mapstruct/ap/test/gem/ConstantTest.java | 1 + .../nametransformation/CheeseCaseMapper.java | 57 +++++++++++++++ .../value/nametransformation/CheeseType.java | 3 +- .../nametransformation/CheeseTypeCapital.java | 16 +++++ .../CheeseTypeCustomSuffix.java | 1 + .../nametransformation/CheeseTypeLower.java | 16 +++++ .../CheeseTypePrefixed.java | 1 + .../CheeseTypeSuffixed.java | 1 + .../EnumNameTransformationStrategyTest.java | 72 ++++++++++++++++++- 15 files changed, 252 insertions(+), 2 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseCaseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCapital.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeLower.java diff --git a/core/src/main/java/org/mapstruct/EnumMapping.java b/core/src/main/java/org/mapstruct/EnumMapping.java index 2f908579e8..ba3a5e0cb0 100644 --- a/core/src/main/java/org/mapstruct/EnumMapping.java +++ b/core/src/main/java/org/mapstruct/EnumMapping.java @@ -104,6 +104,18 @@ * prefix to the source enum *

    1. {@link MappingConstants#STRIP_PREFIX_TRANSFORMATION} - strips the given {@link #configuration()} from * the start of the source enum
    2. + *
    3. + * {@link MappingConstants#CASE_TRANSFORMATION} - applies the given {@link #configuration()} case + * transformation to the source enum. Supported configurations are: + *
        + *
      • upper - Performs upper case transformation to the source enum
      • + *
      • lower - Performs lower case transformation to the source enum
      • + *
      • + * capital - Performs capitalisation of the first character of every word in the source enum + * and everything else to lower case. A word is split by "_". + *
      • + *
      + *
    4. * * * It is possible to use custom name transformation strategies by implementing the {@code diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index 53528f559e..002f005299 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -74,6 +74,14 @@ private MappingConstants() { */ public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; + /** + * In an {@link EnumMapping} this represent the enum transformation strategy that applies case transformation + * at the source. + * + * @since 1.5 + */ + public static final String CASE_TRANSFORMATION = "case"; + /** * Specifies the component model constants to which the generated mapper should adhere. * It can be used with the annotation {@link Mapper#componentModel()} or {@link MapperConfig#componentModel()} diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index 57b9433a20..24c7324f1d 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -259,6 +259,10 @@ MapStruct provides the following out of the box enum name transformation strateg * _stripSuffix_ - Strips a suffix from the source enum * _prefix_ - Applies a prefix on the source enum * _stripPrefix_ - Strips a prefix from the source enum +* _case_ - Applies case transformation to the source enum. Supported _case_ transformations are: +** _upper_ - Performs upper case transformation to the source enum +** _lower_ - Performs lower case transformation to the source enum +** _capital_ - Performs capitalisation of the first character of every word in the source enum and everything else to lowercase. A word is split by "_" It is also possible to register custom strategies. For more information on how to do that have a look at <> diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index be8f23b76d..b49b9d17e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -31,6 +31,8 @@ private MappingConstantsGem() { public static final String STRIP_PREFIX_TRANSFORMATION = "stripPrefix"; + public static final String CASE_TRANSFORMATION = "case"; + /** * Gem for the class {@link org.mapstruct.MappingConstants.ComponentModel} * diff --git a/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java new file mode 100644 index 0000000000..2f99f56ce4 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import java.util.Arrays; +import java.util.Locale; +import java.util.stream.Collectors; + +/** + * Applies case transformation to the source enum + * + * @author jpbassinello + * @since 1.5 + */ +public class CaseEnumTransformationStrategy implements EnumTransformationStrategy { + + private static final String UPPER = "upper"; + private static final String LOWER = "lower"; + private static final String CAPITAL = "capital"; + + @Override + public String getStrategyName() { + return "case"; + } + + @Override + public String transform(String value, String configuration) { + switch ( configuration.toLowerCase() ) { + case UPPER: + return value.toUpperCase( Locale.ROOT ); + case LOWER: + return value.toLowerCase( Locale.ROOT ); + case CAPITAL: + return capitalize( value ); + default: + throw new IllegalArgumentException( + "Unexpected configuration for enum case transformation: " + configuration ); + } + } + + private static String capitalize(String value) { + return Arrays.stream( value.split( "_" ) ) + .map( CaseEnumTransformationStrategy::upperCaseFirst ) + .collect( Collectors.joining( "_" ) ); + } + + private static String upperCaseFirst(String value) { + char[] array = value.toCharArray(); + array[0] = Character.toUpperCase( array[0] ); + for ( int i = 1; i < array.length; i++ ) { + array[i] = Character.toLowerCase( array[i] ); + } + return new String( array ); + } + +} diff --git a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy index 1f52733ad9..264b82d744 100644 --- a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy +++ b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.spi.EnumTransformationStrategy @@ -6,3 +6,4 @@ org.mapstruct.ap.spi.PrefixEnumTransformationStrategy org.mapstruct.ap.spi.StripPrefixEnumTransformationStrategy org.mapstruct.ap.spi.StripSuffixEnumTransformationStrategy org.mapstruct.ap.spi.SuffixEnumTransformationStrategy +org.mapstruct.ap.spi.CaseEnumTransformationStrategy diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index 87a22931ca..e3a5b7c264 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -30,6 +30,7 @@ public void constantsShouldBeEqual() { assertThat( MappingConstants.PREFIX_TRANSFORMATION ).isEqualTo( MappingConstantsGem.PREFIX_TRANSFORMATION ); assertThat( MappingConstants.STRIP_PREFIX_TRANSFORMATION ) .isEqualTo( MappingConstantsGem.STRIP_PREFIX_TRANSFORMATION ); + assertThat( MappingConstants.CASE_TRANSFORMATION ).isEqualTo( MappingConstantsGem.CASE_TRANSFORMATION ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseCaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseCaseMapper.java new file mode 100644 index 0000000000..f29766be8f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseCaseMapper.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.factory.Mappers; + +/** + * @author jpbassinello + */ +@Mapper +public interface CheeseCaseMapper { + + CheeseCaseMapper INSTANCE = Mappers.getMapper( CheeseCaseMapper.class ); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "lower") + CheeseTypeLower mapToLower(CheeseType cheese); + + @InheritInverseConfiguration + CheeseType mapToLowerInverse(CheeseTypeLower cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "lower") + CheeseTypeLower mapToLower(CheeseTypeCapital cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "upper") + CheeseType mapToUpper(CheeseTypeLower cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "upper") + CheeseType mapToUpper(CheeseTypeCapital cheese); + + @InheritInverseConfiguration(name = "mapToUpper") + CheeseTypeCapital mapToUpperInverse(CheeseType cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "capital") + CheeseTypeCapital mapToCapital(CheeseTypeLower cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "capital") + CheeseTypeCapital mapToCapital(CheeseType cheese); + + @InheritInverseConfiguration(name = "mapToCapital") + CheeseType mapToCapitalInverse(CheeseTypeCapital cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "lower") + String mapToLowerString(CheeseType cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "upper") + String mapToUpperString(CheeseType cheese); + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "capital") + String mapToCapitalString(CheeseType cheese); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java index d7a1d2e288..d3e9d55b12 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseType.java @@ -11,5 +11,6 @@ public enum CheeseType { BRIE, - ROQUEFORT + ROQUEFORT, + COLBY_JACK } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCapital.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCapital.java new file mode 100644 index 0000000000..d5d890dce0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCapital.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author jpbassinello + */ +public enum CheeseTypeCapital { + + Brie, + Roquefort, + Colby_Jack +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java index b7eccd3d42..7249e8a929 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeCustomSuffix.java @@ -12,4 +12,5 @@ public enum CheeseTypeCustomSuffix { brie_TYPE, roquefort_TYPE, + colby_jack_TYPE } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeLower.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeLower.java new file mode 100644 index 0000000000..c6f064ec03 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeLower.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +/** + * @author jpbassinello + */ +public enum CheeseTypeLower { + + brie, + roquefort, + colby_jack +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java index 5f5b989c7b..171b4e7d36 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypePrefixed.java @@ -13,4 +13,5 @@ public enum CheeseTypePrefixed { DEFAULT, SWISS_BRIE, SWISS_ROQUEFORT, + SWISS_COLBY_JACK } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java index b2b264b78b..06b019c123 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/CheeseTypeSuffixed.java @@ -13,4 +13,5 @@ public enum CheeseTypeSuffixed { DEFAULT, BRIE_CHEESE_TYPE, ROQUEFORT_CHEESE_TYPE, + COLBY_JACK_CHEESE_TYPE } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java index c27128edb6..d5c74dbe83 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java @@ -22,6 +22,8 @@ CheeseTypeSuffixed.class, CheeseTypePrefixed.class, CheeseTypeCustomSuffix.class, + CheeseTypeLower.class, + CheeseTypeCapital.class }) public class EnumNameTransformationStrategyTest { @@ -92,7 +94,7 @@ public void shouldApplyPrefixAndStripPrefixOnEnumToStringMapping() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, message = "There is no registered EnumTransformationStrategy for 'custom'. Registered strategies are:" + - " prefix, stripPrefix, stripSuffix, suffix." + " prefix, stripPrefix, stripSuffix, suffix, case." ) } ) @@ -109,4 +111,72 @@ public void shouldUseCustomEnumTransformationStrategy() { .isEqualTo( CheeseTypeCustomSuffix.brie_TYPE ); } + @ProcessorTest + @WithClasses({ + CheeseCaseMapper.class + }) + public void shouldConvertCaseOnEnumToEnumMapping() { + CheeseCaseMapper mapper = CheeseCaseMapper.INSTANCE; + + assertThat( mapper.mapToLower( CheeseType.BRIE ) ) + .isEqualTo( CheeseTypeLower.brie ); + + assertThat( mapper.mapToLowerInverse( CheeseTypeLower.brie ) ) + .isEqualTo( CheeseType.BRIE ); + + assertThat( mapper.mapToLower( CheeseTypeCapital.Colby_Jack ) ) + .isEqualTo( CheeseTypeLower.colby_jack ); + + assertThat( mapper.mapToUpper( CheeseTypeLower.roquefort ) ) + .isEqualTo( CheeseType.ROQUEFORT ); + + assertThat( mapper.mapToUpper( CheeseTypeCapital.Colby_Jack ) ) + .isEqualTo( CheeseType.COLBY_JACK ); + + assertThat( mapper.mapToUpperInverse( CheeseType.COLBY_JACK ) ) + .isEqualTo( CheeseTypeCapital.Colby_Jack ); + + assertThat( mapper.mapToCapital( CheeseTypeLower.brie ) ) + .isEqualTo( CheeseTypeCapital.Brie ); + + assertThat( mapper.mapToCapital( CheeseType.ROQUEFORT ) ) + .isEqualTo( CheeseTypeCapital.Roquefort ); + + assertThat( mapper.mapToCapital( CheeseType.COLBY_JACK ) ) + .isEqualTo( CheeseTypeCapital.Colby_Jack ); + + assertThat( mapper.mapToCapitalInverse( CheeseTypeCapital.Roquefort ) ) + .isEqualTo( CheeseType.ROQUEFORT ); + + assertThat( mapper.mapToCapitalInverse( CheeseTypeCapital.Colby_Jack ) ) + .isEqualTo( CheeseType.COLBY_JACK ); + + assertThat( mapper.mapToCapital( CheeseTypeLower.colby_jack ) ) + .isEqualTo( CheeseTypeCapital.Colby_Jack ); + + } + + @ProcessorTest + @WithClasses({ + CheeseCaseMapper.class + }) + public void shouldConvertCaseOnEnumToStringMapping() { + CheeseCaseMapper mapper = CheeseCaseMapper.INSTANCE; + + assertThat( mapper.mapToLowerString( CheeseType.BRIE ) ) + .isEqualTo( "brie" ); + assertThat( mapper.mapToLowerString( CheeseType.COLBY_JACK ) ) + .isEqualTo( "colby_jack" ); + + assertThat( mapper.mapToUpperString( CheeseType.ROQUEFORT ) ) + .isEqualTo( "ROQUEFORT" ); + assertThat( mapper.mapToUpperString( CheeseType.COLBY_JACK ) ) + .isEqualTo( "COLBY_JACK" ); + + assertThat( mapper.mapToCapitalString( CheeseType.ROQUEFORT ) ) + .isEqualTo( "Roquefort" ); + assertThat( mapper.mapToCapitalString( CheeseType.COLBY_JACK ) ) + .isEqualTo( "Colby_Jack" ); + + } } From 4576103752df896d4548c1d618ab892bf540b628 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 15 May 2021 11:37:27 +0200 Subject: [PATCH 0573/1006] #2445 Improve error reporting when EnumTransformationStrategy throws an error during transformation --- .../ap/internal/model/ValueMappingMethod.java | 28 ++++++++++++++++--- .../model/source/EnumMappingOptions.java | 6 ++++ .../mapstruct/ap/internal/util/Message.java | 1 + .../EnumNameTransformationStrategyTest.java | 18 ++++++++++++ .../ErroneousCaseTransformStrategyMapper.java | 20 +++++++++++++ 5 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousCaseTransformStrategyMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 6e7fe3f0da..0d71ed5506 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -56,6 +56,7 @@ public static class Builder { private ValueMappings valueMappings; private EnumMappingOptions enumMapping; private EnumTransformationStrategyInvoker enumTransformationInvoker; + private boolean enumTransformationIllegalReported = false; public Builder mappingContext(MappingBuilderContext mappingContext) { this.ctx = mappingContext; @@ -144,6 +145,25 @@ private void initializeEnumTransformationStrategy() { } + private String transform(String source) { + try { + return enumTransformationInvoker.transform( source ); + } + catch ( IllegalArgumentException ex ) { + if ( !enumTransformationIllegalReported ) { + enumTransformationIllegalReported = true; + ctx.getMessager().printMessage( + method.getExecutable(), + enumMapping.getMirror(), + Message.ENUMMAPPING_ILLEGAL_TRANSFORMATION, + enumTransformationInvoker.transformationStrategy.getStrategyName(), + ex.getMessage() + ); + } + return source; + } + } + private List enumToEnumMapping(Method method, Type sourceType, Type targetType ) { List mappings = new ArrayList<>(); @@ -175,7 +195,7 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ if ( enumMappingInverse ) { // If the mapping is inverse we have to change the target enum constant targetConstants.put( - enumTransformationInvoker.transform( targetNameEnum ), + transform( targetNameEnum ), targetEnumConstant ); } @@ -189,7 +209,7 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ String sourceNameConstant = getEnumConstant( sourceTypeElement, sourceConstant ); String targetConstant; if ( !enumMappingInverse ) { - targetConstant = enumTransformationInvoker.transform( sourceNameConstant ); + targetConstant = transform( sourceNameConstant ); } else { targetConstant = sourceNameConstant; @@ -251,7 +271,7 @@ private List enumToStringMapping(Method method, Type sourceType ) // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { String sourceNameConstant = getEnumConstant( sourceTypeElement, sourceConstant ); - String targetConstant = enumTransformationInvoker.transform( sourceNameConstant ); + String targetConstant = transform( sourceNameConstant ); mappings.add( new MappingEntry( sourceConstant, targetConstant ) ); } } @@ -283,7 +303,7 @@ private List stringToEnumMapping(Method method, Type targetType ) // all remaining constants are mapped for ( String sourceConstant : unmappedSourceConstants ) { String sourceNameConstant = getEnumConstant( targetTypeElement, sourceConstant ); - String stringConstant = enumTransformationInvoker.transform( sourceNameConstant ); + String stringConstant = transform( sourceNameConstant ); if ( !mappedSources.contains( stringConstant ) ) { mappings.add( new MappingEntry( stringConstant, sourceConstant ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java index 86c415a4f1..85734c3083 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.internal.model.source; import java.util.Map; +import java.util.Optional; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; @@ -64,6 +66,10 @@ public TypeMirror getUnexpectedValueMappingException() { return next().getUnexpectedValueMappingException(); } + public AnnotationMirror getMirror() { + return Optional.ofNullable( enumMapping ).map( EnumMappingGem::mirror ).orElse( null ); + } + public boolean isInverse() { return inverse; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 50aeb701d8..cb182af6b9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -110,6 +110,7 @@ public enum Message { ENUMMAPPING_INCORRECT_TRANSFORMATION_STRATEGY( "There is no registered EnumTransformationStrategy for '%s'. Registered strategies are: %s." ), ENUMMAPPING_MISSING_CONFIGURATION( "Configuration has to be defined when strategy is defined." ), ENUMMAPPING_NO_ELEMENTS( "'nameTransformationStrategy', 'configuration' and 'unexpectedValueMappingException' are undefined in @EnumMapping, define at least one of them." ), + ENUMMAPPING_ILLEGAL_TRANSFORMATION( "Illegal transformation for '%s' EnumTransformationStrategy. Error: '%s'." ), LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java index d5c74dbe83..7a29ae40a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java @@ -101,6 +101,24 @@ public void shouldApplyPrefixAndStripPrefixOnEnumToStringMapping() { public void shouldGiveCompileErrorWhenUsingUnknownNameTransformStrategy() { } + @ProcessorTest + @WithClasses({ + ErroneousCaseTransformStrategyMapper.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + type = ErroneousCaseTransformStrategyMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 18, + message = "Illegal transformation for 'case' EnumTransformationStrategy." + + " Error: 'Unexpected configuration for enum case transformation: unknown'." + ) + } + ) + public void shouldGiveCompileErrorWhenUsingUnknownConfigurationForCaseTransformStrategy() { + } + @ProcessorTest @WithClasses({ ErroneousNameTransformStrategyMapper.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousCaseTransformStrategyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousCaseTransformStrategyMapper.java new file mode 100644 index 0000000000..fe8357a8a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/ErroneousCaseTransformStrategyMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.nametransformation; + +import org.mapstruct.EnumMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousCaseTransformStrategyMapper { + + @EnumMapping(nameTransformationStrategy = MappingConstants.CASE_TRANSFORMATION, configuration = "unknown") + CheeseType map(CheeseType cheese); +} From cc1562c5adacd09afcfd547b3bc340be95c953bd Mon Sep 17 00:00:00 2001 From: Lukas Lazar Date: Wed, 14 Apr 2021 14:39:22 +0200 Subject: [PATCH 0574/1006] #2132 Add unmappedTargetPolicy to @BeanMapping --- .../main/java/org/mapstruct/BeanMapping.java | 11 ++++++ .../main/asciidoc/chapter-2-set-up.asciidoc | 1 + .../ap/internal/model/BeanMappingMethod.java | 3 ++ .../model/source/BeanMappingOptions.java | 12 +++++++ .../BeanMappingSourceTargetMapper.java | 20 +++++++++++ ...usBeanMappingStrictSourceTargetMapper.java | 23 +++++++++++++ .../unmappedtarget/UnmappedProductTest.java | 34 +++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/BeanMappingSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousBeanMappingStrictSourceTargetMapper.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index 329d7bd50e..f8c749fbde 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -140,6 +140,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() */ String[] ignoreUnmappedSourceProperties() default {}; + /** + * How unmapped properties of the target type of a mapping should be reported. + * If no policy is configured, the policy given via {@link MapperConfig#unmappedTargetPolicy()} or + * {@link Mapper#unmappedTargetPolicy()} will be applied, using {@link ReportingPolicy#WARN} by default. + * + * @return The reporting policy for unmapped target properties. + * + * @since 1.5 + */ + ReportingPolicy unmappedTargetPolicy() default ReportingPolicy.WARN; + /** * The information that should be used for the builder mappings. This can be used to define custom build methods * for the builder strategy that one uses. diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index fd27b25e42..d26be72156 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -245,6 +245,7 @@ Supported values are: * `IGNORE`: unmapped target properties are ignored If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. +If a policy is given for a specific bean mapping via `@BeanMapping#unmappedTargetPolicy()`, it takes precedence over both `@Mapper#unmappedTargetPolicy()` and the option. |`WARN` |=== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 2e82366f8b..324df63cc8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1390,6 +1390,9 @@ private ReportingPolicyGem getUnmappedTargetPolicy() { if ( mappingReferences.isForForgedMethods() ) { return ReportingPolicyGem.IGNORE; } + if ( method.getOptions().getBeanMapping() != null ) { + return method.getOptions().getBeanMapping().unmappedTargetPolicy(); + } return method.getOptions().getMapper().unmappedTargetPolicy(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index d600ed0fc0..78800e6053 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -11,6 +11,8 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; + +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.TypeUtils; @@ -88,6 +90,7 @@ private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method && !gem.nullValueCheckStrategy().hasValue() && !gem.nullValuePropertyMappingStrategy().hasValue() && !gem.nullValueMappingStrategy().hasValue() + && !gem.unmappedTargetPolicy().hasValue() && !gem.ignoreByDefault().hasValue() && !gem.builder().hasValue() ) { @@ -134,6 +137,15 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } + @Override + public ReportingPolicyGem unmappedTargetPolicy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::unmappedTargetPolicy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( ReportingPolicyGem::valueOf ) + .orElse( next().unmappedTargetPolicy() ); + } + @Override public BuilderGem getBuilder() { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::builder ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/BeanMappingSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/BeanMappingSourceTargetMapper.java new file mode 100644 index 0000000000..4f15e5d6eb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/BeanMappingSourceTargetMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedtarget; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface BeanMappingSourceTargetMapper { + + BeanMappingSourceTargetMapper INSTANCE = Mappers.getMapper( BeanMappingSourceTargetMapper.class ); + + @BeanMapping(unmappedTargetPolicy = ReportingPolicy.WARN) + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousBeanMappingStrictSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousBeanMappingStrictSourceTargetMapper.java new file mode 100644 index 0000000000..77a946e634 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/ErroneousBeanMappingStrictSourceTargetMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedtarget; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousBeanMappingStrictSourceTargetMapper { + + ErroneousBeanMappingStrictSourceTargetMapper INSTANCE = + Mappers.getMapper( ErroneousBeanMappingStrictSourceTargetMapper.class ); + + @BeanMapping(unmappedTargetPolicy = ReportingPolicy.ERROR) + Target sourceToTarget(Source source); + + Source targetToSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java index a36ec31436..bd36365413 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedtarget/UnmappedProductTest.java @@ -87,4 +87,38 @@ public void shouldRaiseErrorDueToUnsetTargetProperty() { ) public void shouldRaiseErrorDueToUnsetTargetPropertyWithPolicySetViaProcessorOption() { } + + @ProcessorTest + @IssueKey("2132") + @WithClasses({ Source.class, Target.class, ErroneousBeanMappingStrictSourceTargetMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousBeanMappingStrictSourceTargetMapper.class, + kind = Kind.ERROR, + line = 20, + message = "Unmapped target property: \"bar\"."), + @Diagnostic(type = ErroneousBeanMappingStrictSourceTargetMapper.class, + kind = Kind.WARNING, + line = 22, + message = "Unmapped target property: \"qux\".") + } + ) + public void shouldRaiseErrorDueToUnsetTargetPropertyWithPolicySetViaBeanMapping() { + } + + @ProcessorTest + @IssueKey("2132") + @WithClasses({ Source.class, Target.class, BeanMappingSourceTargetMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = BeanMappingSourceTargetMapper.class, + kind = Kind.WARNING, + line = 19, + message = "Unmapped target property: \"bar\".") + } + ) + public void shouldLeaveUnmappedTargetPropertyUnsetWithWarnPolicySetViaBeanMapping() { + } } From a6ac4f3fd699ec71e7f4b1fcbe0f6e8061c3e1cf Mon Sep 17 00:00:00 2001 From: Ewald volkert Date: Thu, 15 Apr 2021 07:26:06 +0200 Subject: [PATCH 0575/1006] #2329 use fields for custom date formats with DateTimeFormatter in order to optimise its usage * GetDateTimeFormatterField ** a FieldReference that creates DateTimeFormatters for given dateFormat as mapper fields ** variableName is created using given dateFormat * AbstractJavaTimeToStringConversion provides GetDateTimeFormatterField as required helper field using DateTimeFormatter instances provided as mapper fields by GetDateTimeFormatterField * ConversionProvider might provide supporting fields directly * Refactoring moved/renamed BuiltInFieldReference, BuiltInConstuctorFragment to package model/common * MappingBuilderContext provides access to mapper support fields (that are independent of mapper methods) * MappingResolverImpl / MapperCreationProcessor process supporting fields provided by ConversionProvider * HelperMethod ** extended to supply additional template parameters to be more flexible in freemarker templates ** extended to support mapper field reference / constructor fragment * SupportingMappingMethod ** provide templateParameters to freemarker ** hashCode/equals base on name property instead of template name, as we use one specific template multiple times with different parameters generating multiple methods ** #getSafeField extracted to SupportingField * SupportingField ** removed hashCode/equals based on template name, as we use one specific template multiple times with different parameters generating multiple methods (superclass equals/hashcode is fine for that) ** added support for template parameters to be more flexible when compiling templates * Tests to verify DateTimeFormatter instance field creation --- .../AbstractJavaTimeToStringConversion.java | 19 +- .../conversion/ConversionProvider.java | 14 +- .../conversion/GetDateTimeFormatterField.java | 55 ++ .../internal/model/MappingBuilderContext.java | 10 +- .../model/SupportingConstructorFragment.java | 28 +- .../ap/internal/model/SupportingField.java | 59 +- .../model/SupportingMappingMethod.java | 53 +- .../ConstructorFragment.java} | 7 +- .../internal/model/common/FieldReference.java | 33 + .../builtin => common}/FinalField.java | 6 +- .../AbstractToXmlGregorianCalendar.java | 12 +- .../source/builtin/BuiltInFieldReference.java | 27 - .../model/source/builtin/BuiltInMethod.java | 11 +- ...NewDatatypeFactoryConstructorFragment.java | 4 +- .../processor/MapperCreationProcessor.java | 20 +- .../creation/MappingResolverImpl.java | 29 +- .../conversion/GetDateTimeFormatterField.ftl | 9 + .../{source/builtin => common}/FinalField.ftl | 0 ...PatternDateTimeFormatterGeneratedTest.java | 53 ++ .../java8time/Java8TimeConversionTest.java | 5 + .../Source.java | 40 ++ .../SourceTargetMapper.java | 29 + .../Target.java | 38 ++ .../java8time/SourceTargetMapperImpl.java | 640 ++++++++++++++++++ .../SourceTargetMapperImpl.java | 63 ++ 25 files changed, 1130 insertions(+), 134 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.java rename processor/src/main/java/org/mapstruct/ap/internal/model/{source/builtin/BuiltInConstructorFragment.java => common/ConstructorFragment.java} (58%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/FieldReference.java rename processor/src/main/java/org/mapstruct/ap/internal/model/{source/builtin => common}/FinalField.java (77%) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.ftl rename processor/src/main/resources/org/mapstruct/ap/internal/model/{source/builtin => common}/FinalField.ftl (100%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8CustomPatternDateTimeFormatterGeneratedTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Target.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java index e903c00e59..2f530618c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java @@ -6,9 +6,11 @@ package org.mapstruct.ap.internal.conversion; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.Strings; @@ -38,10 +40,8 @@ protected String getToExpression(ConversionContext conversionContext) { } private String dateTimeFormatter(ConversionContext conversionContext) { - if ( !Strings.isEmpty( conversionContext.getDateFormat() ) ) { - return ConversionUtils.dateTimeFormatter( conversionContext ) - + ".ofPattern( \"" + conversionContext.getDateFormat() - + "\" )"; + if ( Strings.isNotEmpty( conversionContext.getDateFormat() ) ) { + return GetDateTimeFormatterField.getDateTimeFormatterFieldName( conversionContext.getDateFormat() ); } else { return ConversionUtils.dateTimeFormatter( conversionContext ) + "." + defaultFormatterSuffix(); @@ -88,4 +88,15 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon return Collections.asSet( conversionContext.getTargetType() ); } + @Override + public List getRequiredHelperFields(ConversionContext conversionContext) { + if ( Strings.isNotEmpty( conversionContext.getDateFormat() ) ) { + return java.util.Collections.singletonList( + new GetDateTimeFormatterField( + conversionContext.getTypeFactory(), + conversionContext.getDateFormat() ) ); + } + + return super.getRequiredHelperFields( conversionContext ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java index 2ff73d3485..31d4d27585 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java @@ -5,11 +5,14 @@ */ package org.mapstruct.ap.internal.conversion; +import java.util.Collections; import java.util.List; + +import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.TypeConversion; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; -import org.mapstruct.ap.internal.model.HelperMethod; +import org.mapstruct.ap.internal.model.common.FieldReference; /** * Implementations create inline {@link TypeConversion}s such as @@ -49,4 +52,13 @@ public interface ConversionProvider { */ List getRequiredHelperMethods(ConversionContext conversionContext); + /** + * @param conversionContext ConversionContext providing optional information required for creating the conversion. + * + * @return any fields when required. + */ + default List getRequiredHelperFields(ConversionContext conversionContext) { + return Collections.emptyList(); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.java new file mode 100644 index 0000000000..052f2e7224 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.ap.internal.model.common.FieldReference; +import org.mapstruct.ap.internal.model.common.FinalField; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +public class GetDateTimeFormatterField extends FinalField implements FieldReference { + + private final String dateFormat; + + public GetDateTimeFormatterField(TypeFactory typeFactory, String dateFormat) { + super( typeFactory.getType( DateTimeFormatter.class ), getDateTimeFormatterFieldName( dateFormat ) ); + this.dateFormat = dateFormat; + } + + @Override + public Map getTemplateParameter() { + Map parameter = new HashMap<>(); + parameter.put( "dateFormat", dateFormat ); + return parameter; + } + + public static String getDateTimeFormatterFieldName(String dateFormat) { + StringBuilder sb = new StringBuilder(); + sb.append( "dateTimeFormatter_" ); + + dateFormat.codePoints().forEach( cp -> { + if ( Character.isJavaIdentifierPart( cp ) ) { + // safe to character to method name as is + sb.append( Character.toChars( cp ) ); + } + else { + // could not be used in method name + sb.append( "_" ); + } + } ); + + sb.append( "_" ); + + int hashCode = dateFormat.hashCode(); + sb.append( hashCode < 0 ? "0" : "1" ); + sb.append( Math.abs( hashCode ) ); + + return sb.toString(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index a9d4fd0918..fc82017a17 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -15,8 +15,6 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.TypeElement; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.FormattingParameters; @@ -28,8 +26,10 @@ import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.MappingExclusionProvider; @@ -101,6 +101,8 @@ Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory descrip Supplier forger); Set getUsedSupportedMappings(); + + Set getUsedSupportedFields(); } private final TypeFactory typeFactory; @@ -241,6 +243,10 @@ public Set getUsedSupportedMappings() { return mappingResolver.getUsedSupportedMappings(); } + public Set getUsedSupportedFields() { + return mappingResolver.getUsedSupportedFields(); + } + /** * @param sourceType from which an automatic sub-mapping needs to be generated * @param targetType to which an automatic sub-mapping needs to be generated diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java index f25bbfca9f..936a9a51ba 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingConstructorFragment.java @@ -9,9 +9,9 @@ import java.util.Objects; import java.util.Set; +import org.mapstruct.ap.internal.model.common.ConstructorFragment; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.builtin.BuiltInConstructorFragment; /** * A mapper instance field, initialized as null @@ -20,13 +20,15 @@ */ public class SupportingConstructorFragment extends ModelElement { + private final String variableName; private final String templateName; private final SupportingMappingMethod definingMethod; public SupportingConstructorFragment(SupportingMappingMethod definingMethod, - BuiltInConstructorFragment constructorFragment) { + ConstructorFragment constructorFragment, String variableName) { this.templateName = getTemplateNameForClass( constructorFragment.getClass() ); this.definingMethod = definingMethod; + this.variableName = variableName; } @Override @@ -43,10 +45,15 @@ public SupportingMappingMethod getDefiningMethod() { return definingMethod; } + public String getVariableName() { + return variableName; + } + @Override public int hashCode() { final int prime = 31; int result = 1; + result = prime * result + ( ( variableName == null ) ? 0 : variableName.hashCode() ); result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() ); return result; } @@ -64,10 +71,12 @@ public boolean equals(Object obj) { } SupportingConstructorFragment other = (SupportingConstructorFragment) obj; + if ( !Objects.equals( variableName, other.variableName ) ) { + return false; + } if ( !Objects.equals( templateName, other.templateName ) ) { return false; } - return true; } @@ -80,4 +89,17 @@ public static void addAllFragmentsIn(Set supportingMapp } } } + + public static SupportingConstructorFragment getSafeConstructorFragment(SupportingMappingMethod method, + ConstructorFragment fragment, + Field supportingField) { + if ( fragment == null ) { + return null; + } + + return new SupportingConstructorFragment( + method, + fragment, + supportingField != null ? supportingField.getVariableName() : null ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java index a92f4c9df4..caf6d6160e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java @@ -5,10 +5,11 @@ */ package org.mapstruct.ap.internal.model; -import java.util.Objects; +import java.util.Map; import java.util.Set; -import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference; +import org.mapstruct.ap.internal.model.common.FieldReference; +import org.mapstruct.ap.internal.util.Strings; /** * supports the @@ -18,11 +19,14 @@ public class SupportingField extends Field { private final String templateName; + private final Map templateParameter; + private final SupportingMappingMethod definingMethod; - public SupportingField(SupportingMappingMethod definingMethod, BuiltInFieldReference fieldReference, String name) { + public SupportingField(SupportingMappingMethod definingMethod, FieldReference fieldReference, String name) { super( fieldReference.getType(), name, true ); this.templateName = getTemplateNameForClass( fieldReference.getClass() ); + this.templateParameter = fieldReference.getTemplateParameter(); this.definingMethod = definingMethod; } @@ -31,36 +35,12 @@ public String getTemplateName() { return templateName; } - public SupportingMappingMethod getDefiningMethod() { - return definingMethod; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() ); - return result; + public Map getTemplateParameter() { + return templateParameter; } - @Override - public boolean equals(Object obj) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - SupportingField other = (SupportingField) obj; - - if ( !Objects.equals( templateName, other.templateName ) ) { - return false; - } - - return true; + public SupportingMappingMethod getDefiningMethod() { + return definingMethod; } public static void addAllFieldsIn(Set supportingMappingMethods, Set targets) { @@ -71,4 +51,21 @@ public static void addAllFieldsIn(Set supportingMapping } } } + + public static Field getSafeField(SupportingMappingMethod method, FieldReference ref, Set existingFields) { + if ( ref == null ) { + return null; + } + + String name = ref.getVariableName(); + for ( Field existingField : existingFields ) { + if ( existingField.getVariableName().equals( ref.getVariableName() ) + && existingField.getType().equals( ref.getType() ) ) { + // field already exists, use that one + return existingField; + } + } + name = Strings.getSafeVariableName( name, Field.getFieldNames( existingFields ) ); + return new SupportingField( method, ref, name ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java index 756330e5d9..9428454c1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingMappingMethod.java @@ -5,14 +5,13 @@ */ package org.mapstruct.ap.internal.model; +import java.util.Map; import java.util.Objects; import java.util.Set; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.builtin.BuiltInFieldReference; import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.builtin.NewDatatypeFactoryConstructorFragment; -import org.mapstruct.ap.internal.util.Strings; /** * A mapping method which is not based on an actual method declared in the original mapper interface but is added as @@ -21,7 +20,7 @@ * Specific templates all point to this class, for instance: * {@link org.mapstruct.ap.internal.model.source.builtin.XmlGregorianCalendarToCalendar}, * but also used fields and constructor elements, e.g. - * {@link org.mapstruct.ap.internal.model.source.builtin.FinalField} and + * {@link org.mapstruct.ap.internal.model.common.FinalField} and * {@link NewDatatypeFactoryConstructorFragment} * * @author Gunnar Morling @@ -32,49 +31,25 @@ public class SupportingMappingMethod extends MappingMethod { private final Set importTypes; private final Field supportingField; private final SupportingConstructorFragment supportingConstructorFragment; + private final Map templateParameter; public SupportingMappingMethod(BuiltInMethod method, Set existingFields) { super( method ); this.importTypes = method.getImportTypes(); this.templateName = getTemplateNameForClass( method.getClass() ); - if ( method.getFieldReference() != null ) { - this.supportingField = getSafeField( method.getFieldReference(), existingFields ); - } - else { - this.supportingField = null; - } - if ( method.getConstructorFragment() != null ) { - this.supportingConstructorFragment = new SupportingConstructorFragment( - this, - method.getConstructorFragment() - ); - } - else { - this.supportingConstructorFragment = null; - } - } - - private Field getSafeField(BuiltInFieldReference ref, Set existingFields) { - String name = ref.getVariableName(); - for ( Field existingField : existingFields ) { - if ( existingField.getType().equals( ref.getType() ) ) { - // field type already exist, use that one - return existingField; - } - } - for ( Field existingField : existingFields ) { - if ( existingField.getVariableName().equals( ref.getVariableName() ) ) { - // field with name exist, however its a wrong type - name = Strings.getSafeVariableName( name, Field.getFieldNames( existingFields ) ); - } - } - return new SupportingField( this, ref, name ); + this.templateParameter = null; + this.supportingField = SupportingField.getSafeField( this, method.getFieldReference(), existingFields ); + this.supportingConstructorFragment = SupportingConstructorFragment.getSafeConstructorFragment( + this, + method.getConstructorFragment(), + this.supportingField ); } public SupportingMappingMethod(HelperMethod method) { super( method ); this.importTypes = method.getImportTypes(); this.templateName = getTemplateNameForClass( method.getClass() ); + this.templateParameter = null; this.supportingField = null; this.supportingConstructorFragment = null; } @@ -120,11 +95,15 @@ public SupportingConstructorFragment getSupportingConstructorFragment() { return supportingConstructorFragment; } + public Map getTemplateParameter() { + return templateParameter; + } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ( ( templateName == null ) ? 0 : templateName.hashCode() ); + result = prime * result + ( ( getName() == null ) ? 0 : getName().hashCode() ); return result; } @@ -141,7 +120,7 @@ public boolean equals(Object obj) { } SupportingMappingMethod other = (SupportingMappingMethod) obj; - if ( !Objects.equals( templateName, other.templateName ) ) { + if ( !Objects.equals( getName(), other.getName() ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConstructorFragment.java similarity index 58% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/common/ConstructorFragment.java index ae8dbcc7cd..89d2928999 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInConstructorFragment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConstructorFragment.java @@ -3,10 +3,11 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source.builtin; +package org.mapstruct.ap.internal.model.common; /** - * ConstructorFragments are 'code snippets' added to the constructor to initialize fields used by {@link BuiltInMethod} + * ConstructorFragments are 'code snippets' added to the constructor to initialize fields used by + * BuiltInMethod/HelperMethod */ -public interface BuiltInConstructorFragment { +public interface ConstructorFragment { } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FieldReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FieldReference.java new file mode 100644 index 0000000000..bf1f5be445 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FieldReference.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.common; + +import java.util.Map; + +/** + * reference used by BuiltInMethod/HelperMethod to create an additional field in the mapper. + */ +public interface FieldReference { + + /** + * + * @return variable name of the field + */ + String getVariableName(); + + /** + * + * @return type of the field + */ + Type getType(); + + /** + * @return additional template parameters + */ + default Map getTemplateParameter() { + return null; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FinalField.java similarity index 77% rename from processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/common/FinalField.java index 5ce4167117..c3e1ef1f39 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/FinalField.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FinalField.java @@ -3,16 +3,14 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.internal.model.source.builtin; - -import org.mapstruct.ap.internal.model.common.Type; +package org.mapstruct.ap.internal.model.common; /** * A mapper instance field, initialized as null * * @author Sjaak Derksen */ -public class FinalField implements BuiltInFieldReference { +public class FinalField implements FieldReference { private final Type type; private String variableName; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java index 691d93d0f3..7a2ac5588f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java @@ -5,17 +5,21 @@ */ package org.mapstruct.ap.internal.model.source.builtin; +import static org.mapstruct.ap.internal.util.Collections.asSet; + import java.util.Set; + import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; +import org.mapstruct.ap.internal.model.common.ConstructorFragment; +import org.mapstruct.ap.internal.model.common.FieldReference; +import org.mapstruct.ap.internal.model.common.FinalField; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.Strings; -import static org.mapstruct.ap.internal.util.Collections.asSet; - /** * @author Sjaak Derksen */ @@ -46,12 +50,12 @@ public Type getReturnType() { } @Override - public BuiltInFieldReference getFieldReference() { + public FieldReference getFieldReference() { return new FinalField( dataTypeFactoryType, Strings.decapitalize( DatatypeFactory.class.getSimpleName() ) ); } @Override - public BuiltInConstructorFragment getConstructorFragment() { + public ConstructorFragment getConstructorFragment() { return new NewDatatypeFactoryConstructorFragment( ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java deleted file mode 100644 index 0eb15f289b..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInFieldReference.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.model.source.builtin; - -import org.mapstruct.ap.internal.model.common.Type; - -/** - * reference used by BuiltInMethod to create an additional field in the mapper. - */ -public interface BuiltInFieldReference { - - /** - * - * @return variable name of the field - */ - String getVariableName(); - - /** - * - * @return type of the field - */ - Type getType(); - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index e54a8ea4b8..f46b201576 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -5,15 +5,20 @@ */ package org.mapstruct.ap.internal.model.source.builtin; +import static org.mapstruct.ap.internal.util.Collections.first; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; + import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.common.Accessibility; +import org.mapstruct.ap.internal.model.common.ConstructorFragment; import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.MappingMethodOptions; @@ -21,8 +26,6 @@ import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.util.Strings; -import static org.mapstruct.ap.internal.util.Collections.first; - /** * Represents a "built-in" mapping method which will be added as private method to the generated mapper. Built-in * methods are used in cases where a simple conversation doesn't suffice, e.g. as several lines of source code or a @@ -265,11 +268,11 @@ public MappingMethodOptions getOptions() { return MappingMethodOptions.empty(); } - public BuiltInFieldReference getFieldReference() { + public FieldReference getFieldReference() { return null; } - public BuiltInConstructorFragment getConstructorFragment() { + public ConstructorFragment getConstructorFragment() { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java index a302b59375..e4f00f7d57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/NewDatatypeFactoryConstructorFragment.java @@ -5,7 +5,9 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -public class NewDatatypeFactoryConstructorFragment implements BuiltInConstructorFragment { +import org.mapstruct.ap.internal.model.common.ConstructorFragment; + +public class NewDatatypeFactoryConstructorFragment implements ConstructorFragment { public NewDatatypeFactoryConstructorFragment() { } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index c887140723..13e0010171 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -22,9 +22,14 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.gem.DecoratedWithGem; +import org.mapstruct.ap.internal.gem.InheritConfigurationGem; +import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem; +import org.mapstruct.ap.internal.gem.MapperGem; +import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.model.BeanMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder; @@ -50,18 +55,13 @@ import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.gem.BuilderGem; -import org.mapstruct.ap.internal.gem.DecoratedWithGem; -import org.mapstruct.ap.internal.gem.InheritConfigurationGem; -import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem; -import org.mapstruct.ap.internal.gem.MapperGem; -import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; -import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.processor.creation.MappingResolverImpl; import org.mapstruct.ap.internal.util.AccessorNamingUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.version.VersionInformation; import static javax.lang.model.element.Modifier.FINAL; @@ -182,7 +182,7 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< // handle fields List fields = new ArrayList<>( mappingContext.getMapperReferences() ); - Set supportingFieldSet = new LinkedHashSet<>(); + Set supportingFieldSet = new LinkedHashSet<>(mappingContext.getUsedSupportedFields()); addAllFieldsIn( mappingContext.getUsedSupportedMappings(), supportingFieldSet ); fields.addAll( supportingFieldSet ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index ca2889e01a..d9bd4d731b 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -32,8 +32,6 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.conversion.ConversionProvider; import org.mapstruct.ap.internal.conversion.Conversions; @@ -49,6 +47,7 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.DefaultConversionContext; +import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; @@ -60,11 +59,13 @@ import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.MessageConstants; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.TypeUtils; /** * The one and only implementation of {@link MappingResolver}. The class has been split into an interface an @@ -98,6 +99,11 @@ public class MappingResolverImpl implements MappingResolver { */ private final Set usedSupportedMappings = new HashSet<>(); + /** + * Private fields which are added to map certain property types. + */ + private final Set usedSupportedFields = new HashSet<>(); + public MappingResolverImpl(FormattingMessager messager, ElementUtils elementUtils, TypeUtils typeUtils, TypeFactory typeFactory, List sourceModel, List mapperReferences, boolean verboseLogging) { @@ -144,6 +150,11 @@ public Set getUsedSupportedMappings() { return usedSupportedMappings; } + @Override + public Set getUsedSupportedFields() { + return usedSupportedFields; + } + private MapperReference findMapperReference(Method method) { for ( MapperReference ref : mapperReferences ) { if ( ref.getType().equals( method.getDeclaringMapper() ) ) { @@ -424,8 +435,20 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy ); // add helper methods required in conversion + Set allUsedFields = new HashSet<>( mapperReferences ); + SupportingField.addAllFieldsIn( supportingMethodCandidates, allUsedFields ); + + for ( FieldReference helperField : conversionProvider.getRequiredHelperFields( ctx )) { + Field field = SupportingField.getSafeField( null, helperField, allUsedFields ); + allUsedFields.add( field ); + usedSupportedFields.add( field ); + } + for ( HelperMethod helperMethod : conversionProvider.getRequiredHelperMethods( ctx ) ) { - usedSupportedMappings.add( new SupportingMappingMethod( helperMethod ) ); + SupportingMappingMethod supportingMappingMethod = + new SupportingMappingMethod( helperMethod ); + SupportingField.addAllFieldsIn( Collections.asSet( supportingMappingMethod ), allUsedFields ); + usedSupportedMappings.add( supportingMappingMethod ); } Assignment conversion = conversionProvider.to( ctx ); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.ftl new file mode 100644 index 0000000000..6efbe7f0ff --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/GetDateTimeFormatterField.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingField" --> +private final <@includeModel object=type/> ${variableName} = <@includeModel object=type/>.ofPattern( "${templateParameter['dateFormat']}" ); \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/FinalField.ftl similarity index 100% rename from processor/src/main/resources/org/mapstruct/ap/internal/model/source/builtin/FinalField.ftl rename to processor/src/main/resources/org/mapstruct/ap/internal/model/common/FinalField.ftl diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8CustomPatternDateTimeFormatterGeneratedTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8CustomPatternDateTimeFormatterGeneratedTest.java new file mode 100644 index 0000000000..443de8aab5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8CustomPatternDateTimeFormatterGeneratedTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import java.time.LocalDateTime; +import java.time.Month; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated.Source; +import org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated.SourceTargetMapper; +import org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated.Target; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests generation of DateTimeFormatters as mapper instance fields for conversions to/from Java 8 date and time types. + */ +@WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) +@IssueKey("2329") +public class Java8CustomPatternDateTimeFormatterGeneratedTest { + + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( SourceTargetMapper.class ); + + @ProcessorTest + public void testDateTimeFormattersGenerated() { + + Source source = new Source(); + source.setLocalDateTime1( LocalDateTime.of( 2021, Month.MAY, 16, 12, 13, 10 ) ); + source.setLocalDateTime2( LocalDateTime.of( 2020, Month.APRIL, 10, 15, 10, 12 ) ); + source.setLocalDateTime3( LocalDateTime.of( 2021, Month.APRIL, 25, 9, 46, 13 ) ); + + Target target = SourceTargetMapper.INSTANCE.map( source ); + + assertThat( target.getLocalDateTime1() ).isEqualTo( "16.05.2021 12:13" ); + assertThat( target.getLocalDateTime2() ).isEqualTo( "10.04.2020 15:10" ); + assertThat( target.getLocalDateTime3() ).isEqualTo( "25.04.2021 09.46" ); + + source = SourceTargetMapper.INSTANCE.map( target ); + + assertThat( source.getLocalDateTime1() ).isEqualTo( LocalDateTime.of( 2021, Month.MAY, 16, 12, 13, 0 ) ); + assertThat( source.getLocalDateTime2() ).isEqualTo( LocalDateTime.of( 2020, Month.APRIL, 10, 15, 10, 0 ) ); + assertThat( source.getLocalDateTime3() ).isEqualTo( LocalDateTime.of( 2021, Month.APRIL, 25, 9, 46, 0 ) ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index bcd5045646..b95b5d1acd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -19,9 +19,11 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -32,6 +34,9 @@ @IssueKey("121") public class Java8TimeConversionTest { + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( SourceTargetMapper.class ); + private TimeZone originalTimeZone; @BeforeEach diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Source.java new file mode 100644 index 0000000000..f83721cbb5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Source.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated; + +import java.time.LocalDateTime; + +public class Source { + + private LocalDateTime localDateTime1; + private LocalDateTime localDateTime2; + private LocalDateTime localDateTime3; + + public LocalDateTime getLocalDateTime1() { + return localDateTime1; + } + + public void setLocalDateTime1(LocalDateTime localDateTime1) { + this.localDateTime1 = localDateTime1; + } + + public LocalDateTime getLocalDateTime2() { + return localDateTime2; + } + + public void setLocalDateTime2(LocalDateTime localDateTime2) { + this.localDateTime2 = localDateTime2; + } + + public LocalDateTime getLocalDateTime3() { + return localDateTime3; + } + + public void setLocalDateTime3(LocalDateTime localDateTime3) { + this.localDateTime3 = localDateTime3; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapper.java new file mode 100644 index 0000000000..960ceec3b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceTargetMapper { + + String LOCAL_DATE_TIME_FORMAT = "dd.MM.yyyy HH:mm"; + String VERY_SIMILAR_LOCAL_DATE_TIME_FORMAT = "dd.MM.yyyy HH.mm"; + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(target = "localDateTime1", dateFormat = LOCAL_DATE_TIME_FORMAT) + @Mapping(target = "localDateTime2", dateFormat = LOCAL_DATE_TIME_FORMAT) + @Mapping(target = "localDateTime3", dateFormat = VERY_SIMILAR_LOCAL_DATE_TIME_FORMAT) + Target map(Source source); + + @InheritInverseConfiguration + Source map(Target target); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Target.java new file mode 100644 index 0000000000..7d265ba4aa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/Target.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated; + +public class Target { + + private String localDateTime1; + private String localDateTime2; + private String localDateTime3; + + public String getLocalDateTime1() { + return localDateTime1; + } + + public void setLocalDateTime1(String localDateTime1) { + this.localDateTime1 = localDateTime1; + } + + public String getLocalDateTime2() { + return localDateTime2; + } + + public void setLocalDateTime2(String localDateTime2) { + this.localDateTime2 = localDateTime2; + } + + public String getLocalDateTime3() { + return localDateTime3; + } + + public void setLocalDateTime3(String localDateTime3) { + this.localDateTime3 = localDateTime3; + } + +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..58beaa19dd --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java @@ -0,0 +1,640 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-05-15T18:24:04+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_275 (AdoptOpenJDK)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + private final DateTimeFormatter dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 = DateTimeFormatter.ofPattern( "dd.MM.yyyy HH:mm" ); + private final DateTimeFormatter dateTimeFormatter_HH_mm_168697690 = DateTimeFormatter.ofPattern( "HH:mm" ); + private final DateTimeFormatter dateTimeFormatter_dd_MM_yyyy_11900521056 = DateTimeFormatter.ofPattern( "dd.MM.yyyy" ); + private final DateTimeFormatter dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668 = DateTimeFormatter.ofPattern( "dd.MM.yyyy HH:mm z" ); + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242.format( source.getLocalDateTime() ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( dateTimeFormatter_dd_MM_yyyy_11900521056.format( source.getLocalDate() ) ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( dateTimeFormatter_HH_mm_168697690.format( source.getLocalTime() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Target sourceToTargetDefaultMapping(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242.format( source.getLocalDateTime() ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( dateTimeFormatter_dd_MM_yyyy_11900521056.format( source.getLocalDate() ) ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( dateTimeFormatter_HH_mm_168697690.format( source.getLocalTime() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Target sourceToTargetDateTimeMapped(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( DateTimeFormatter.ISO_LOCAL_DATE_TIME.format( source.getLocalDateTime() ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( DateTimeFormatter.ISO_LOCAL_DATE.format( source.getLocalDate() ) ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( DateTimeFormatter.ISO_LOCAL_TIME.format( source.getLocalTime() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Target sourceToTargetLocalDateTimeMapped(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242.format( source.getLocalDateTime() ) ); + } + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( DateTimeFormatter.ISO_DATE_TIME.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( DateTimeFormatter.ISO_LOCAL_DATE.format( source.getLocalDate() ) ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( DateTimeFormatter.ISO_LOCAL_TIME.format( source.getLocalTime() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Target sourceToTargetLocalDateMapped(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getLocalDate() != null ) { + target.setLocalDate( dateTimeFormatter_dd_MM_yyyy_11900521056.format( source.getLocalDate() ) ); + } + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( DateTimeFormatter.ISO_DATE_TIME.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( DateTimeFormatter.ISO_LOCAL_DATE_TIME.format( source.getLocalDateTime() ) ); + } + if ( source.getLocalTime() != null ) { + target.setLocalTime( DateTimeFormatter.ISO_LOCAL_TIME.format( source.getLocalTime() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Target sourceToTargetLocalTimeMapped(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getLocalTime() != null ) { + target.setLocalTime( dateTimeFormatter_HH_mm_168697690.format( source.getLocalTime() ) ); + } + if ( source.getZonedDateTime() != null ) { + target.setZonedDateTime( DateTimeFormatter.ISO_DATE_TIME.format( source.getZonedDateTime() ) ); + } + if ( source.getLocalDateTime() != null ) { + target.setLocalDateTime( DateTimeFormatter.ISO_LOCAL_DATE_TIME.format( source.getLocalDateTime() ) ); + } + if ( source.getLocalDate() != null ) { + target.setLocalDate( DateTimeFormatter.ISO_LOCAL_DATE.format( source.getLocalDate() ) ); + } + target.setForCalendarConversion( zonedDateTimeToCalendar( source.getForCalendarConversion() ) ); + if ( source.getForDateConversionWithZonedDateTime() != null ) { + target.setForDateConversionWithZonedDateTime( Date.from( source.getForDateConversionWithZonedDateTime().toInstant() ) ); + } + if ( source.getForDateConversionWithLocalDateTime() != null ) { + target.setForDateConversionWithLocalDateTime( Date.from( source.getForDateConversionWithLocalDateTime().toInstant( ZoneOffset.UTC ) ) ); + } + if ( source.getForDateConversionWithLocalDate() != null ) { + target.setForDateConversionWithLocalDate( Date.from( source.getForDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant() ) ); + } + if ( source.getForSqlDateConversionWithLocalDate() != null ) { + target.setForSqlDateConversionWithLocalDate( new java.sql.Date( source.getForSqlDateConversionWithLocalDate().atStartOfDay( ZoneOffset.UTC ).toInstant().toEpochMilli() ) ); + } + if ( source.getForDateConversionWithInstant() != null ) { + target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); + } + if ( source.getForInstantConversionWithString() != null ) { + target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); + } + if ( source.getForPeriodConversionWithString() != null ) { + target.setForPeriodConversionWithString( source.getForPeriodConversionWithString().toString() ); + } + if ( source.getForDurationConversionWithString() != null ) { + target.setForDurationConversionWithString( source.getForDurationConversionWithString().toString() ); + } + + return target; + } + + @Override + public Source targetToSource(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668 ) ); + } + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 ) ); + } + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate(), dateTimeFormatter_dd_MM_yyyy_11900521056 ) ); + } + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime(), dateTimeFormatter_HH_mm_168697690 ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + @Override + public Source targetToSourceDateTimeMapped(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668 ) ); + } + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime() ) ); + } + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate() ) ); + } + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime() ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + @Override + public Source targetToSourceLocalDateTimeMapped(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 ) ); + } + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime() ) ); + } + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate() ) ); + } + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime() ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + @Override + public Source targetToSourceLocalDateMapped(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate(), dateTimeFormatter_dd_MM_yyyy_11900521056 ) ); + } + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime() ) ); + } + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime() ) ); + } + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime() ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + @Override + public Source targetToSourceLocalTimeMapped(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime(), dateTimeFormatter_HH_mm_168697690 ) ); + } + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime() ) ); + } + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime() ) ); + } + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate() ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + @Override + public Source targetToSourceDefaultMapping(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getZonedDateTime() != null ) { + source.setZonedDateTime( ZonedDateTime.parse( target.getZonedDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_z_01894582668 ) ); + } + if ( target.getLocalDateTime() != null ) { + source.setLocalDateTime( LocalDateTime.parse( target.getLocalDateTime(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 ) ); + } + if ( target.getLocalDate() != null ) { + source.setLocalDate( LocalDate.parse( target.getLocalDate(), dateTimeFormatter_dd_MM_yyyy_11900521056 ) ); + } + if ( target.getLocalTime() != null ) { + source.setLocalTime( LocalTime.parse( target.getLocalTime(), dateTimeFormatter_HH_mm_168697690 ) ); + } + source.setForCalendarConversion( calendarToZonedDateTime( target.getForCalendarConversion() ) ); + if ( target.getForDateConversionWithZonedDateTime() != null ) { + source.setForDateConversionWithZonedDateTime( ZonedDateTime.ofInstant( target.getForDateConversionWithZonedDateTime().toInstant(), ZoneId.systemDefault() ) ); + } + if ( target.getForDateConversionWithLocalDateTime() != null ) { + source.setForDateConversionWithLocalDateTime( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDateTime().toInstant(), ZoneId.of( "UTC" ) ) ); + } + if ( target.getForDateConversionWithLocalDate() != null ) { + source.setForDateConversionWithLocalDate( LocalDateTime.ofInstant( target.getForDateConversionWithLocalDate().toInstant(), ZoneOffset.UTC ).toLocalDate() ); + } + if ( target.getForSqlDateConversionWithLocalDate() != null ) { + source.setForSqlDateConversionWithLocalDate( target.getForSqlDateConversionWithLocalDate().toLocalDate() ); + } + if ( target.getForDateConversionWithInstant() != null ) { + source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); + } + if ( target.getForInstantConversionWithString() != null ) { + source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); + } + if ( target.getForPeriodConversionWithString() != null ) { + source.setForPeriodConversionWithString( Period.parse( target.getForPeriodConversionWithString() ) ); + } + if ( target.getForDurationConversionWithString() != null ) { + source.setForDurationConversionWithString( Duration.parse( target.getForDurationConversionWithString() ) ); + } + + return source; + } + + private ZonedDateTime calendarToZonedDateTime(Calendar cal) { + if ( cal == null ) { + return null; + } + + return ZonedDateTime.ofInstant( cal.toInstant(), cal.getTimeZone().toZoneId() ); + } + + private Calendar zonedDateTimeToCalendar(ZonedDateTime dateTime) { + if ( dateTime == null ) { + return null; + } + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( dateTime.getZone() ) ); + instance.setTimeInMillis( dateTime.toInstant().toEpochMilli() ); + return instance; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..98c2c19bb6 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/custompatterndatetimeformattergenerated/SourceTargetMapperImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time.custompatterndatetimeformattergenerated; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-05-16T13:11:04+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_275 (AdoptOpenJDK)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + private final DateTimeFormatter dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 = DateTimeFormatter.ofPattern( "dd.MM.yyyy HH:mm" ); + private final DateTimeFormatter dateTimeFormatter_dd_MM_yyyy_HH_mm_12071757710 = DateTimeFormatter.ofPattern( "dd.MM.yyyy HH.mm" ); + + @Override + public Target map(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( source.getLocalDateTime1() != null ) { + target.setLocalDateTime1( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242.format( source.getLocalDateTime1() ) ); + } + if ( source.getLocalDateTime2() != null ) { + target.setLocalDateTime2( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242.format( source.getLocalDateTime2() ) ); + } + if ( source.getLocalDateTime3() != null ) { + target.setLocalDateTime3( dateTimeFormatter_dd_MM_yyyy_HH_mm_12071757710.format( source.getLocalDateTime3() ) ); + } + + return target; + } + + @Override + public Source map(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + if ( target.getLocalDateTime1() != null ) { + source.setLocalDateTime1( LocalDateTime.parse( target.getLocalDateTime1(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 ) ); + } + if ( target.getLocalDateTime2() != null ) { + source.setLocalDateTime2( LocalDateTime.parse( target.getLocalDateTime2(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071769242 ) ); + } + if ( target.getLocalDateTime3() != null ) { + source.setLocalDateTime3( LocalDateTime.parse( target.getLocalDateTime3(), dateTimeFormatter_dd_MM_yyyy_HH_mm_12071757710 ) ); + } + + return source; + } +} From 70ea65f7aa5518cac236c277bf040b058907f713 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 16 May 2021 17:39:26 +0200 Subject: [PATCH 0576/1006] #2437 Do not visit the same type element twice when retrieving methods When using the diamond inheritance a TypeElement might be visited twice. This is however, incorrect. We need to visit a TypeElement exactly once. --- .../util/AbstractElementUtilsDecorator.java | 15 ++++++++-- .../ap/test/bugs/_2437/Issue2437Test.java | 30 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2437/Phone.java | 22 ++++++++++++++ .../ap/test/bugs/_2437/PhoneDto.java | 22 ++++++++++++++ .../ap/test/bugs/_2437/PhoneMapper.java | 15 ++++++++++ .../test/bugs/_2437/PhoneParent1Mapper.java | 12 ++++++++ .../test/bugs/_2437/PhoneParent2Mapper.java | 12 ++++++++ .../ap/test/bugs/_2437/PhoneSuperMapper.java | 14 +++++++++ 8 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Issue2437Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Phone.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent1Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent2Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneSuperMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java index 8239dcb41b..14734b9c8e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java @@ -7,6 +7,8 @@ import java.io.Writer; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -118,7 +120,7 @@ public boolean isFunctionalInterface(TypeElement type) { public List getAllEnclosedExecutableElements(TypeElement element) { List enclosedElements = new ArrayList<>(); element = replaceTypeElementIfNecessary( element ); - addEnclosedMethodsInHierarchy( enclosedElements, element, element ); + addEnclosedMethodsInHierarchy( enclosedElements, new HashSet<>(), element, element ); return enclosedElements; } @@ -132,7 +134,9 @@ public List getAllEnclosedFields( TypeElement element) { return enclosedElements; } - private void addEnclosedMethodsInHierarchy(List alreadyAdded, TypeElement element, + private void addEnclosedMethodsInHierarchy(List alreadyAdded, + Collection alreadyVisitedElements, + TypeElement element, TypeElement parentType) { if ( element != parentType ) { // otherwise the element was already checked for replacement element = replaceTypeElementIfNecessary( element ); @@ -142,11 +146,17 @@ private void addEnclosedMethodsInHierarchy(List alreadyAdded, throw new TypeHierarchyErroneousException( element ); } + if ( !alreadyVisitedElements.add( element.getQualifiedName().toString() ) ) { + // If we already visited the element we should not go into it again. + // This can happen when diamond inheritance is used with interfaces + return; + } addMethodNotYetOverridden( alreadyAdded, methodsIn( element.getEnclosedElements() ), parentType ); if ( hasNonObjectSuperclass( element ) ) { addEnclosedMethodsInHierarchy( alreadyAdded, + alreadyVisitedElements, asTypeElement( element.getSuperclass() ), parentType ); @@ -155,6 +165,7 @@ private void addEnclosedMethodsInHierarchy(List alreadyAdded, for ( TypeMirror interfaceType : element.getInterfaces() ) { addEnclosedMethodsInHierarchy( alreadyAdded, + alreadyVisitedElements, asTypeElement( interfaceType ), parentType ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Issue2437Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Issue2437Test.java new file mode 100644 index 0000000000..343b8fbf1f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Issue2437Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2437") +@WithClasses({ + Phone.class, + PhoneDto.class, + PhoneMapper.class, + PhoneParent1Mapper.class, + PhoneParent2Mapper.class, + PhoneSuperMapper.class, +}) +class Issue2437Test { + + @ProcessorTest + void shouldGenerateValidCode() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Phone.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Phone.java new file mode 100644 index 0000000000..98027861fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/Phone.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +/** + * @author Filip Hrisafov + */ +public class Phone { + + private final String number; + + public Phone(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneDto.java new file mode 100644 index 0000000000..883e086e89 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +/** + * @author Filip Hrisafov + */ +public class PhoneDto { + + private final String number; + + public PhoneDto(String number) { + this.number = number; + } + + public String getNumber() { + return number; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneMapper.java new file mode 100644 index 0000000000..16b01658be --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneMapper.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface PhoneMapper extends PhoneParent1Mapper, PhoneParent2Mapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent1Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent1Mapper.java new file mode 100644 index 0000000000..0b4da27c15 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent1Mapper.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +/** + * @author Filip Hrisafov + */ +public interface PhoneParent1Mapper extends PhoneSuperMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent2Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent2Mapper.java new file mode 100644 index 0000000000..77e9db6235 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneParent2Mapper.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +/** + * @author Filip Hrisafov + */ +public interface PhoneParent2Mapper extends PhoneSuperMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneSuperMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneSuperMapper.java new file mode 100644 index 0000000000..ba35b21d9b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2437/PhoneSuperMapper.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2437; + +/** + * @author Filip Hrisafov + */ +public interface PhoneSuperMapper { + + Phone map(PhoneDto dto); +} From 857f87276f686f0659b0fa604aa363e25701916b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 5 Jun 2021 09:22:37 +0200 Subject: [PATCH 0577/1006] #2466 Update dependencies so tests run on Java 16+ Update GitHub Actions for tests to run on Java 11, 13, 16 and 17-ea. Update Lombok so tests can run on 16+ Add jaxb-runtime dependency to the maven-jaxb2-plugin see https://github.com/highsource/maven-jaxb2-plugin/issues/148 Disable cdi integration test on Java 16+ until we find a solution for them --- .github/workflows/java-ea.yml | 2 +- .github/workflows/main.yml | 2 +- .../org/mapstruct/itest/tests/MavenIntegrationTest.java | 2 ++ integrationtest/src/test/resources/jaxbTest/pom.xml | 7 +++++++ parent/pom.xml | 2 +- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index 3e901b6119..598a8979a6 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - java: [16-ea] + java: [17-ea] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f63a183d4b..741f8bce61 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - java: [11, 13, 15] + java: [11, 13, 16] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 76a72b4b7f..e82f13a018 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -5,6 +5,7 @@ */ package org.mapstruct.itest.tests; +import org.junit.jupiter.api.condition.DisabledForJreRange; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.parallel.Execution; @@ -25,6 +26,7 @@ void autoValueBuilderTest() { } @ProcessorTest(baseDir = "cdiTest") + @DisabledForJreRange(min = JRE.JAVA_16) void cdiTest() { } diff --git a/integrationtest/src/test/resources/jaxbTest/pom.xml b/integrationtest/src/test/resources/jaxbTest/pom.xml index 8b3e4c7921..000e7cf598 100644 --- a/integrationtest/src/test/resources/jaxbTest/pom.xml +++ b/integrationtest/src/test/resources/jaxbTest/pom.xml @@ -47,6 +47,13 @@ true 2.1 + + + org.glassfish.jaxb + jaxb-runtime + 2.3.2 + + diff --git a/parent/pom.xml b/parent/pom.xml index c1172cbfe0..a924b1cd68 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -202,7 +202,7 @@ org.projectlombok lombok - 1.18.16 + 1.18.20 org.immutables From 9ce9d4fb3adad0c64a2b636ebea5f71ef2602f09 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 5 Jun 2021 08:56:11 +0200 Subject: [PATCH 0578/1006] #2375 Add records cross module integration test --- .../itest/tests/MavenIntegrationTest.java | 7 ++++ .../recordsCrossModuleTest/api/pom.xml | 22 +++++++++++ .../itest/records/api/CustomerDto.java | 13 +++++++ .../recordsCrossModuleTest/mapper/pom.xml | 30 ++++++++++++++ .../itest/records/mapper/CustomerEntity.java | 31 +++++++++++++++ .../itest/records/mapper/CustomerMapper.java | 28 +++++++++++++ .../itest/records/mapper/RecordsTest.java | 39 +++++++++++++++++++ .../resources/recordsCrossModuleTest/pom.xml | 26 +++++++++++++ 8 files changed, 196 insertions(+) create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/api/pom.xml create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/api/src/main/java/org/mapstruct/itest/records/api/CustomerDto.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/mapper/pom.xml create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerEntity.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerMapper.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleTest/pom.xml diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index e82f13a018..2ec0ba9aa9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -109,6 +109,13 @@ void protobufBuilderTest() { void recordsTest() { } + @ProcessorTest(baseDir = "recordsCrossModuleTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + @EnabledForJreRange(min = JRE.JAVA_17) + void recordsCrossModuleTest() { + } + @ProcessorTest(baseDir = "kotlinDataTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }, forkJvm = true) diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/api/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleTest/api/pom.xml new file mode 100644 index 0000000000..362f2d3840 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/api/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + + recordsCrossModuleTest + org.mapstruct + 1.0.0 + + + records-cross-module-api + + diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/api/src/main/java/org/mapstruct/itest/records/api/CustomerDto.java b/integrationtest/src/test/resources/recordsCrossModuleTest/api/src/main/java/org/mapstruct/itest/records/api/CustomerDto.java new file mode 100644 index 0000000000..344aa79d96 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/api/src/main/java/org/mapstruct/itest/records/api/CustomerDto.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.api; + +/** + * @author Filip Hrisafov + */ +public record CustomerDto(String name, String email) { + +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/pom.xml new file mode 100644 index 0000000000..6fc250ed45 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + + recordsCrossModuleTest + org.mapstruct + 1.0.0 + + + records-cross-module-mapper + + + + + org.mapstruct + records-cross-module-api + 1.0.0 + + + diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerEntity.java b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerEntity.java new file mode 100644 index 0000000000..51bcdaa8e1 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.mapper; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerMapper.java b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerMapper.java new file mode 100644 index 0000000000..7b679a4245 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/main/java/org/mapstruct/itest/records/mapper/CustomerMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.mapper; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; +import org.mapstruct.itest.records.api.CustomerDto; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromRecord(CustomerDto record); + + @InheritInverseConfiguration + CustomerDto toRecord(CustomerEntity entity); + +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java new file mode 100644 index 0000000000..2f274792b8 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.mapper; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.records.api.CustomerDto; +import org.mapstruct.itest.records.mapper.CustomerEntity; +import org.mapstruct.itest.records.mapper.CustomerMapper; + +public class RecordsTest { + + @Test + public void shouldMapRecord() { + CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } + + @Test + public void shouldMapIntoRecord() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Kermit" ); + entity.setMail( "kermit@test.com" ); + + CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity ); + + assertThat( customer ).isNotNull(); + assertThat( customer.name() ).isEqualTo( "Kermit" ); + assertThat( customer.email() ).isEqualTo( "kermit@test.com" ); + } + +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleTest/pom.xml new file mode 100644 index 0000000000..47c55ea410 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/pom.xml @@ -0,0 +1,26 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + recordsCrossModuleTest + pom + + + api + mapper + + From 08016d9ef24a4fb59347953f1f0cba9bcecca810 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 12 Jun 2021 10:16:40 +0200 Subject: [PATCH 0579/1006] #2446 Use DefaultLocale and DefaultTimeZone from JUnit Pioneer Configure the JUnit Platform to run the processor tests in parallel by running different test classes in concurrent threads --- parent/pom.xml | 6 ++++ processor/pom.xml | 6 ++++ .../ap/internal/util/StringsTest.java | 34 +++---------------- .../test/bugs/_1523/java8/Issue1523Test.java | 23 +++---------- .../ap/test/builtin/BuiltInTest.java | 18 ++-------- .../ap/test/builtin/DatatypeFactoryTest.java | 18 ++-------- .../conversion/date/DateConversionTest.java | 18 ++-------- .../java8time/Java8TimeConversionTest.java | 23 +++---------- .../jodatime/JodaConversionTest.java | 18 ++-------- .../numbers/NumberFormatConversionTest.java | 18 ++-------- ...ingCompileOptionConstructorMapperTest.java | 18 ++-------- .../SpringConstructorMapperTest.java | 15 ++------ .../NestedMappingMethodInvocationTest.java | 18 ++-------- .../test/resources/junit-platform.properties | 3 ++ 14 files changed, 46 insertions(+), 190 deletions(-) create mode 100644 processor/src/test/resources/junit-platform.properties diff --git a/parent/pom.xml b/parent/pom.xml index a924b1cd68..bb1229fcb8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -29,6 +29,7 @@ 1.6.0 8.36.1 5.8.0-M1 + 1.4.2 1 3.17.2 @@ -141,6 +142,11 @@ pom import + + org.junit-pioneer + junit-pioneer + ${junit-pioneer.version} + diff --git a/processor/pom.xml b/processor/pom.xml index 5aa6470ff9..fcc6dbbab8 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -115,6 +115,12 @@ test + + org.junit-pioneer + junit-pioneer + test + + joda-time diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 44fbb565ba..687b63f793 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -9,30 +9,15 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Locale; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.DefaultLocale; /** * @author Filip Hrisafov */ public class StringsTest { - private static final Locale TURKEY_LOCALE = getTurkeyLocale(); - private Locale defaultLocale; - - @BeforeEach - public void before() { - defaultLocale = Locale.getDefault(); - } - - @AfterEach - public void after() { - Locale.setDefault( defaultLocale ); - } - @Test public void testCapitalize() { assertThat( Strings.capitalize( null ) ).isNull(); @@ -137,40 +122,31 @@ public void findMostSimilarWord() { } @Test + @DefaultLocale("en") public void capitalizeEnglish() { - Locale.setDefault( Locale.ENGLISH ); String international = Strings.capitalize( "international" ); assertThat( international ).isEqualTo( "International" ); } @Test + @DefaultLocale("en") public void decapitalizeEnglish() { - Locale.setDefault( Locale.ENGLISH ); String international = Strings.decapitalize( "International" ); assertThat( international ).isEqualTo( "international" ); } @Test + @DefaultLocale("tr") public void capitalizeTurkish() { - Locale.setDefault( TURKEY_LOCALE ); String international = Strings.capitalize( "international" ); assertThat( international ).isEqualTo( "International" ); } @Test + @DefaultLocale("tr") public void decapitalizeTurkish() { - Locale.setDefault( TURKEY_LOCALE ); String international = Strings.decapitalize( "International" ); assertThat( international ).isEqualTo( "international" ); } - private static Locale getTurkeyLocale() { - Locale turkeyLocale = Locale.forLanguageTag( "tr" ); - - if ( turkeyLocale == null ) { - throw new IllegalStateException( "Can't find Turkey locale." ); - } - - return turkeyLocale; - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java index f528432c18..825e318356 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1523/java8/Issue1523Test.java @@ -9,8 +9,7 @@ import java.util.Calendar; import java.util.TimeZone; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -31,24 +30,12 @@ Target.class }) @IssueKey("1523") +// we want to test that the timezone will correctly be used in mapped XMLGregorianCalendar and not the +// default one, so we must ensure that we use a different timezone than the default one -> set the default +// one explicitly to UTC +@DefaultTimeZone("UTC") public class Issue1523Test { - private static final TimeZone DEFAULT_TIMEZONE = TimeZone.getDefault(); - - @BeforeAll - public static void before() { - // we want to test that the timezone will correctly be used in mapped XMLGregorianCalendar and not the - // default one, so we must ensure that we use a different timezone than the default one -> set the default - // one explicitly to UTC - TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); - } - - @AfterAll - public static void after() { - // revert the changed default TZ - TimeZone.setDefault( DEFAULT_TIMEZONE ); - } - @ProcessorTest public void testThatCorrectTimeZoneWillBeUsedInTarget() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index e6cd7a19b4..0f1983a851 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -17,15 +17,13 @@ import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; -import java.util.TimeZone; import javax.xml.bind.JAXBElement; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.builtin._target.IterableTarget; import org.mapstruct.ap.test.builtin._target.MapTarget; import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; @@ -85,21 +83,9 @@ IterableSource.class, MapSource.class }) +@DefaultTimeZone("Europe/Berlin") public class BuiltInTest { - private static TimeZone originalTimeZone; - - @BeforeAll - public static void setDefaultTimeZoneToCet() { - originalTimeZone = TimeZone.getDefault(); - TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); - } - - @AfterAll - public static void restoreOriginalTimeZone() { - TimeZone.setDefault( originalTimeZone ); - } - @ProcessorTest @WithClasses( JaxbMapper.class ) public void shouldApplyBuiltInOnJAXBElement() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java index 85c1bed399..1db8d3abcf 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/DatatypeFactoryTest.java @@ -10,10 +10,8 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import java.util.TimeZone; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.builtin.bean.CalendarProperty; import org.mapstruct.ap.test.builtin.bean.DatatypeFactory; import org.mapstruct.ap.test.builtin.bean.DateProperty; @@ -32,21 +30,9 @@ DateProperty.class } ) +@DefaultTimeZone("Europe/Berlin") public class DatatypeFactoryTest { - private TimeZone originalTimeZone; - - @BeforeEach - public void setUp() { - originalTimeZone = TimeZone.getDefault(); - TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); - } - - @AfterEach - public void tearDown() { - TimeZone.setDefault( originalTimeZone ); - } - @ProcessorTest public void testNoConflictsWithOwnDatatypeFactory() throws ParseException { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 363b287b71..83464f81a0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -12,13 +12,11 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.List; -import java.util.Locale; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; +import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -36,21 +34,9 @@ SourceTargetMapper.class }) @IssueKey("43") +@DefaultLocale("de") public class DateConversionTest { - private Locale originalLocale; - - @BeforeEach - public void setDefaultLocale() { - originalLocale = Locale.getDefault(); - Locale.setDefault( Locale.GERMAN ); - } - - @AfterEach - public void tearDown() { - Locale.setDefault( originalLocale ); - } - @ProcessorTest @EnabledOnJre( JRE.JAVA_8 ) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index b95b5d1acd..aa30865425 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -17,8 +17,7 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -37,18 +36,6 @@ public class Java8TimeConversionTest { @RegisterExtension GeneratedSource generatedSource = new GeneratedSource().addComparisonToFixtureFor( SourceTargetMapper.class ); - private TimeZone originalTimeZone; - - @BeforeEach - public void setUp() { - originalTimeZone = TimeZone.getDefault(); - } - - @AfterEach - public void tearDown() { - TimeZone.setDefault( originalTimeZone ); - } - @ProcessorTest public void testDateTimeToString() { Source src = new Source(); @@ -226,8 +213,8 @@ public void testCalendarMapping() { } @ProcessorTest + @DefaultTimeZone("UTC") public void testZonedDateTimeToDateMapping() { - TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); Source source = new Source(); ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); source.setForDateConversionWithZonedDateTime( @@ -266,8 +253,8 @@ public void testInstantToDateMapping() { } @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") public void testLocalDateTimeToDateMapping() { - TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); Source source = new Source(); LocalDateTime dateTime = LocalDateTime.of( 2014, 1, 1, 0, 0 ); @@ -292,8 +279,8 @@ public void testLocalDateTimeToDateMapping() { } @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") public void testLocalDateToDateMapping() { - TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); Source source = new Source(); LocalDate localDate = LocalDate.of( 2016, 3, 1 ); @@ -316,8 +303,8 @@ public void testLocalDateToDateMapping() { } @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") public void testLocalDateToSqlDateMapping() { - TimeZone.setDefault( TimeZone.getTimeZone( "Australia/Melbourne" ) ); Source source = new Source(); LocalDate localDate = LocalDate.of( 2016, 3, 1 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index e861497169..001b6390e2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.test.conversion.jodatime; import java.util.Calendar; -import java.util.Locale; import java.util.TimeZone; import org.joda.time.DateTime; @@ -14,11 +13,10 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; +import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -32,21 +30,9 @@ */ @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @IssueKey("75") +@DefaultLocale("de") public class JodaConversionTest { - private Locale originalLocale; - - @BeforeEach - public void setDefaultLocale() { - originalLocale = Locale.getDefault(); - Locale.setDefault( Locale.GERMAN ); - } - - @AfterEach - public void tearDown() { - Locale.setDefault( originalLocale ); - } - @ProcessorTest public void testDateTimeToString() { Source src = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index ea1dd0da60..6dfc1b3ca1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -10,11 +10,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -26,21 +24,9 @@ Target.class, SourceTargetMapper.class }) +@DefaultLocale("en") public class NumberFormatConversionTest { - private Locale originalLocale; - - @BeforeEach - public void setDefaultLocale() { - originalLocale = Locale.getDefault(); - Locale.setDefault( Locale.ENGLISH ); - } - - @AfterEach - public void tearDown() { - Locale.setDefault( originalLocale ); - } - @ProcessorTest public void shouldApplyStringConversions() { Source source = new Source(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java index 8043c24305..b106a5d788 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java @@ -8,13 +8,11 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.TimeZone; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; @@ -54,10 +52,9 @@ @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class) @Configuration +@DefaultTimeZone("Europe/Berlin") public class SpringCompileOptionConstructorMapperTest { - private static TimeZone originalTimeZone; - @RegisterExtension final GeneratedSource generatedSource = new GeneratedSource(); @@ -65,17 +62,6 @@ public class SpringCompileOptionConstructorMapperTest { private CustomerRecordSpringCompileOptionConstructorMapper customerRecordMapper; private ConfigurableApplicationContext context; - @BeforeAll - public static void setDefaultTimeZoneToCet() { - originalTimeZone = TimeZone.getDefault(); - TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); - } - - @AfterAll - public static void restoreOriginalTimeZone() { - TimeZone.setDefault( originalTimeZone ); - } - @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java index 1346ac1ee8..1ff3fc8428 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -10,11 +10,10 @@ import java.util.Date; import java.util.TimeZone; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.RegisterExtension; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; @@ -54,6 +53,7 @@ @IssueKey( "571" ) @ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class) @Configuration +@DefaultTimeZone("Europe/Berlin") public class SpringConstructorMapperTest { private static TimeZone originalTimeZone; @@ -65,17 +65,6 @@ public class SpringConstructorMapperTest { private CustomerRecordSpringConstructorMapper customerRecordMapper; private ConfigurableApplicationContext context; - @BeforeAll - public static void setDefaultTimeZoneToCet() { - originalTimeZone = TimeZone.getDefault(); - TimeZone.setDefault( TimeZone.getTimeZone( "Europe/Berlin" ) ); - } - - @AfterAll - public static void restoreOriginalTimeZone() { - TimeZone.setDefault( originalTimeZone ); - } - @BeforeEach public void springUp() { context = new AnnotationConfigApplicationContext( getClass() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 375f524d68..1e9b52cf62 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -9,7 +9,6 @@ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.List; -import java.util.Locale; import javax.xml.bind.JAXBElement; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConstants; @@ -17,8 +16,7 @@ import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.namespace.QName; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -31,23 +29,11 @@ * @author Sjaak Derksen */ @IssueKey("134") +@DefaultLocale("de") public class NestedMappingMethodInvocationTest { public static final QName QNAME = new QName( "dont-care" ); - private Locale originalLocale; - - @BeforeEach - public void setDefaultLocale() { - originalLocale = Locale.getDefault(); - Locale.setDefault( Locale.GERMAN ); - } - - @AfterEach - public void tearDown() { - Locale.setDefault( originalLocale ); - } - @ProcessorTest @WithClasses( { OrderTypeToOrderDtoMapper.class, diff --git a/processor/src/test/resources/junit-platform.properties b/processor/src/test/resources/junit-platform.properties new file mode 100644 index 0000000000..97a956feff --- /dev/null +++ b/processor/src/test/resources/junit-platform.properties @@ -0,0 +1,3 @@ +junit.jupiter.execution.parallel.enabled=true +junit.jupiter.execution.parallel.mode.default = same_thread +junit.jupiter.execution.parallel.mode.classes.default = concurrent From 046077f7011fd63e78205d5a8a3d1d0af6e98956 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 13 Jun 2021 10:02:11 +0200 Subject: [PATCH 0580/1006] #2483: Update Asciidoctor to latest versions --- documentation/pom.xml | 9 ++++----- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/documentation/pom.xml b/documentation/pom.xml index 0426805375..8850da641c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -21,9 +21,9 @@ MapStruct Documentation - 1.5.3 - 1.6.2 - 9.2.6.0 + 1.6.0 + 2.5.1 + 9.2.17.0 @@ -33,7 +33,7 @@ org.asciidoctor asciidoctor-maven-plugin - 1.6.0 + 2.1.0 org.asciidoctor @@ -52,7 +52,6 @@ - coderay mapstruct-reference-guide.asciidoc ${project.version} diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index b83c874c5e..7bffbca5c7 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -2,6 +2,7 @@ :revdate: {docdate} :toc: right :sectanchors: +:source-highlighter: coderay :Author: Gunnar Morling, Andreas Gudian, Sjaak Derksen, Filip Hrisafov and the MapStruct community :processor-dir: ../../../../processor :processor-ap-test: {processor-dir}/src/test/java/org/mapstruct/ap/test From 55c62ab43f150710e1939ed7b05b295a0d5dd8aa Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 13 Jun 2021 12:36:42 +0200 Subject: [PATCH 0581/1006] #2108 Make sure Javadoc can be generated with Java 11 Remove the org.jboss.apiviz.APIviz doclet since it is no longer compatible with Java 11. Add new group in the Javadoc for the MapStruct Processor SPI Fix Javadoc warnings --- .../java/org/mapstruct/DecoratedWith.java | 2 +- .../InheritInverseConfiguration.java | 2 +- core/src/main/java/org/mapstruct/Mapping.java | 1 - .../main/java/org/mapstruct/ValueMapping.java | 24 +++------ .../org/mapstruct/control/MappingControl.java | 2 +- distribution/pom.xml | 50 ++++++++++++++++--- .../mapstruct/ap/internal/model/Mapper.java | 4 ++ .../model/ObjectFactoryMethodResolver.java | 5 +- .../model/beanmapping/AbstractReference.java | 12 ++--- .../model/beanmapping/TargetReference.java | 2 +- .../model/source/BeanMappingOptions.java | 2 + .../internal/model/source/MappingOptions.java | 3 ++ .../model/source/SelectionParameters.java | 5 +- .../ap/internal/util/accessor/Accessor.java | 4 +- .../org/mapstruct/ap/spi/BuilderInfo.java | 11 ++++ 15 files changed, 85 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/org/mapstruct/DecoratedWith.java b/core/src/main/java/org/mapstruct/DecoratedWith.java index 7f740a8983..78b2c580ff 100644 --- a/core/src/main/java/org/mapstruct/DecoratedWith.java +++ b/core/src/main/java/org/mapstruct/DecoratedWith.java @@ -22,7 +22,7 @@ *

      * NOTE: This annotation is not supported for the component model {@code cdi}. Use CDI's own * {@code @Decorator} feature instead. - *

      + *

      *

      Examples

      *

      * For the examples below, consider the following mapper declaration: diff --git a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java index 3063ca07c9..ac582a5dfa 100644 --- a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java +++ b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java @@ -59,7 +59,7 @@ * } * } * - *

      + * *

      
        * @Mapper
        * public interface CarMapper {
      diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java
      index b4bfa30d88..0af73f3687 100644
      --- a/core/src/main/java/org/mapstruct/Mapping.java
      +++ b/core/src/main/java/org/mapstruct/Mapping.java
      @@ -372,7 +372,6 @@
            *     }
            * 
      *

      - *

      * Any types referenced in expressions must be given via their fully-qualified name. Alternatively, types can be * imported via {@link Mapper#imports()}. *

      diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index 2d4a586366..21ea5f4a83 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -18,12 +18,9 @@ *

        *
      1. Enumeration to Enumeration
      2. *
      - *

      - * Example 1: - * - *

      - * 
      + * Example 1:
        *
      + * 
      
        * public enum OrderType { RETAIL, B2B, C2C, EXTRA, STANDARD, NORMAL }
        *
        * public enum ExternalOrderType { RETAIL, B2B, SPECIAL, DEFAULT }
      @@ -46,12 +43,9 @@
        * +---------------------+----------------------------+
        * 
      * - *

      - * Example 2: - * - *

      - * 
      + * Example 2:
        *
      + * 
      
        * @ValueMapping( source = MappingConstants.NULL, target = "DEFAULT" ),
        * @ValueMapping( source = "STANDARD", target = MappingConstants.NULL ),
        * @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "SPECIAL" )
      @@ -70,17 +64,13 @@
        * +---------------------+----------------------------+
        * 
      * - *

      - * Example 3: - *

      + * Example 3: * - *

      MapStruct will WARN on incomplete mappings. However, if for some reason no match is found, an + * MapStruct will WARN on incomplete mappings. However, if for some reason no match is found, an * {@link java.lang.IllegalStateException} will be thrown. This compile-time error can be avoided by * using {@link MappingConstants#THROW_EXCEPTION} for {@link ValueMapping#target()}. It will result an * {@link java.lang.IllegalArgumentException} at runtime. - *
      - * 
      - *
      + * 
      
        * @ValueMapping( source = "STANDARD", target = "DEFAULT" ),
        * @ValueMapping( source = "C2C", target = MappingConstants.THROW_EXCEPTION )
        * ExternalOrderType orderTypeToExternalOrderType(OrderType orderType);
      diff --git a/core/src/main/java/org/mapstruct/control/MappingControl.java b/core/src/main/java/org/mapstruct/control/MappingControl.java
      index 1d416dafd7..c44797602a 100644
      --- a/core/src/main/java/org/mapstruct/control/MappingControl.java
      +++ b/core/src/main/java/org/mapstruct/control/MappingControl.java
      @@ -132,7 +132,7 @@ enum Use {
                * This means if source type and target type are of the same type, MapStruct will not perform
                * any mappings anymore and assign the target to the source direct.
                * 

      - * An exception are types from the package {@link java}, which will be mapped always directly. + * An exception are types from the package {@code java}, which will be mapped always directly. * * @since 1.4 */ diff --git a/distribution/pom.xml b/distribution/pom.xml index 30beb1d319..337ad35e51 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -34,6 +34,11 @@ org.freemarker freemarker + + + org.mapstruct.tools.gem + gem-api + @@ -96,18 +101,16 @@ MapStruct API org.mapstruct* + + MapStruct Processor SPI + org.mapstruct.ap.spi* + MapStruct Processor org.mapstruct.ap* - org.jboss.apiviz.APIviz - - org.jboss.apiviz - apiviz - 1.3.2.GA - true UTF-8 UTF-8 @@ -116,6 +119,23 @@ true true true + + + + + if (typeof useModuleDirectories !== 'undefined') { + useModuleDirectories = false; + } + + ]]> + + --allow-script-in-comments + @@ -156,4 +176,22 @@ + + + + jdk-11-or-newer + + [11 + + + + javax.xml.bind + jaxb-api + 2.3.1 + provided + true + + + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index db63a8431d..a066b123c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -162,6 +162,10 @@ protected String getTemplateName() { /** * Returns the same as {@link Class#getName()} but without the package declaration. + * + * @param element the element that should be flattened + * + * @return the flat name for the type element */ public static String getFlatName(TypeElement element) { if (!(element.getEnclosingElement() instanceof TypeElement)) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index f0bd9c4dff..397a001a4f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -40,10 +40,9 @@ private ObjectFactoryMethodResolver() { * * @param method target mapping method * @param selectionParameters parameters used in the selection process - * @param ctx + * @param ctx the mapping builder context * * @return a method reference to the factory method, or null if no suitable, or ambiguous method found - * */ public static MethodReference getFactoryMethod( Method method, SelectionParameters selectionParameters, @@ -57,7 +56,7 @@ public static MethodReference getFactoryMethod( Method method, * @param method target mapping method * @param alternativeTarget alternative to {@link Method#getResultType()} e.g. when target is abstract * @param selectionParameters parameters used in the selection process - * @param ctx + * @param ctx the mapping builder context * * @return a method reference to the factory method, or null if no suitable, or ambiguous method found * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java index 4db93505e3..72f2b8c8fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/AbstractReference.java @@ -56,8 +56,7 @@ public List getElementNames() { } /** - * returns the property name on the shallowest nesting level - * @return + * @return the property name on the shallowest nesting level */ public PropertyEntry getShallowestProperty() { if ( propertyEntries.isEmpty() ) { @@ -67,8 +66,7 @@ public PropertyEntry getShallowestProperty() { } /** - * returns the property name on the shallowest nesting level - * @return + * @return the property name on the shallowest nesting level */ public String getShallowestPropertyName() { if ( propertyEntries.isEmpty() ) { @@ -78,8 +76,7 @@ public String getShallowestPropertyName() { } /** - * returns the property name on the deepest nesting level - * @return + * @return the property name on the deepest nesting level */ public PropertyEntry getDeepestProperty() { if ( propertyEntries.isEmpty() ) { @@ -89,8 +86,7 @@ public PropertyEntry getDeepestProperty() { } /** - * returns the property name on the deepest nesting level - * @return + * @return the property name on the deepest nesting level */ public String getDeepestPropertyName() { if ( propertyEntries.isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java index 22bfd6343b..961e519561 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/TargetReference.java @@ -80,7 +80,7 @@ public List getElementNames() { } /** - * returns the property name on the shallowest nesting level + * @return the property name on the shallowest nesting level */ public String getShallowestPropertyName() { if ( propertyEntries.isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 78800e6053..9567dd80bf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -39,6 +39,8 @@ public class BeanMappingOptions extends DelegatingOptions { /** * creates a mapping for inheritance. Will set * + * @param beanMapping the bean mapping options that should be used + * * @return new mapping */ public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index d7d6ad6291..cb496a3a31 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -502,6 +502,9 @@ public MappingOptions copyForInverseInheritance(SourceMethod templateMethod, /** * Creates a copy of this mapping * + * @param templateMethod the template method for the inheritance + * @param beanMappingOptions the bean mapping options + * * @return the copy */ public MappingOptions copyForForwardInheritance(SourceMethod templateMethod, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index 697f0d9e4a..fb76c13629 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -34,8 +34,9 @@ public class SelectionParameters { * * ResultType is not inherited. * - * @param selectionParameters - * @return + * @param selectionParameters the selection parameters that need to be copied + * + * @return the selection parameters based on the given ones */ public static SelectionParameters forInheritance(SelectionParameters selectionParameters) { return new SelectionParameters( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java index 314302a14e..d624b7788a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/Accessor.java @@ -45,9 +45,7 @@ public interface Accessor { Element getElement(); /** - * The accessor type - * - * @return + * @return type of the accessor */ AccessorType getAccessorType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java index 0f95567481..5e37987f75 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/BuilderInfo.java @@ -54,6 +54,10 @@ public static class Builder { private Collection buildMethods; /** + * @param method The creation method for the builder + * + * @return the builder for chaining + * * @see BuilderInfo#getBuilderCreationMethod() */ public Builder builderCreationMethod(ExecutableElement method) { @@ -62,6 +66,10 @@ public Builder builderCreationMethod(ExecutableElement method) { } /** + * @param methods the build methods for the type + * + * @return the builder for chaining + * * @see BuilderInfo#getBuildMethods() */ public Builder buildMethod(Collection methods) { @@ -71,6 +79,9 @@ public Builder buildMethod(Collection methods) { /** * Create the {@link BuilderInfo}. + * + * @return the created {@link BuilderInfo} + * * @throws IllegalArgumentException if the builder creation or build methods are {@code null} */ public BuilderInfo build() { From 7f38efad4d21cf88a2b68ab1c164846e83978b47 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 19 Jun 2021 13:56:26 +0200 Subject: [PATCH 0582/1006] #2463 Selection stops when method type-args are flipped (#2487) --- .../internal/model/source/MethodMatcher.java | 15 ++-- .../multiple/MultipleTypeVarTest.java | 16 ++++ ...eVarBothArgumentsFlippedGenericMapper.java | 76 +++++++++++++++++++ .../objectfactory/ObjectFactoryMapper.java | 61 +++++++++++++++ .../objectfactory/ObjectFactoryTest.java | 28 +++++++ 5 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/multiple/ReturnTypeHasMultipleTypeVarBothArgumentsFlippedGenericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 136828adfc..f08e4a9152 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -248,10 +248,12 @@ boolean getCandidates(Type aCandidateMethodType, Type matchingType, Map String method( List in ) Type.ResolvedPair resolved = mthdParType.resolveParameterToType( matchingType, aCandidateMethodType ); - if ( resolved == null ) { - // cannot find a candidate type, but should have since the typeFromCandidateMethod had parameters - // to be resolved - return !hasGenericTypeParameters( aCandidateMethodType ); + if ( resolved.getMatch() == null ) { + // we should be dealing with something containing a type parameter at this point. This is + // covered with the checks above. Therefore resolved itself cannot be null. + // If there is no match here, continue with the next candidate, perhaps there will a match with + // the next method type parameter + continue; } // resolved something at this point, a candidate can be fetched or created @@ -270,13 +272,10 @@ boolean getCandidates(Type aCandidateMethodType, Type matchingType, Map HashMap toMap( Pair entry) { + HashMap result = new HashMap<>( ); + result.put( entry.first, entry.second ); + return result; + } + + class Source { + + private Pair prop; + + public Source(Pair prop) { + this.prop = prop; + } + + public Pair getProp() { + return prop; + } + } + + class Target { + + private Map prop; + + public Map getProp() { + return prop; + } + + public Target setProp(Map prop) { + this.prop = prop; + return this; + } + } + + class Pair { + private final T first; + private final U second; + + public Pair(T first, U second) { + this.first = first; + this.second = second; + } + + public T getFirst() { + return first; + } + + public U getSecond() { + return second; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java new file mode 100644 index 0000000000..2ea183bfc9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.objectfactory; + +import org.mapstruct.Mapper; +import org.mapstruct.ObjectFactory; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ObjectFactoryMapper { + + ObjectFactoryMapper INSTANCE = Mappers.getMapper( ObjectFactoryMapper.class ); + + TargetA toTarget(SourceA source); + + @ObjectFactory + default T createTarget(S source, @TargetType Class targetType) { + if ( source.isA() ) { + return (T) new TargetA(); + } + return (T) new TargetB(); + } + + abstract class Source { + public abstract boolean isA(); + } + + class SourceA extends Source { + @Override + public boolean isA() { + return true; + } + } + + class SourceB extends Source { + @Override + public boolean isA() { + return false; + } + } + + abstract class Target { + } + + class TargetA extends Target { + + private TargetA() { + } + } + + class TargetB extends Target { + + private TargetB() { + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryTest.java new file mode 100644 index 0000000000..21392710ba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryTest.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.objectfactory; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +public class ObjectFactoryTest { + + @IssueKey( "2463" ) + @ProcessorTest + @WithClasses( ObjectFactoryMapper.class ) + public void testSelectionOfFactoryMethod() { + + ObjectFactoryMapper.SourceA source = new ObjectFactoryMapper.SourceA(); + + ObjectFactoryMapper.Target target = ObjectFactoryMapper.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target ).isInstanceOf( ObjectFactoryMapper.TargetA.class ); + } +} From 934a47323a4a183054fc445fdb441bd42d34e0e8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 12 Jun 2021 10:41:39 +0200 Subject: [PATCH 0583/1006] #2478 Make sure that forged methods do not generate duplicate method parameters --- .../ap/internal/model/ForgedMethod.java | 12 ++- .../ap/test/bugs/_2478/Issue2478Mapper.java | 86 +++++++++++++++++++ .../ap/test/bugs/_2478/Issue2478Test.java | 33 +++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index 820a09c22a..b97d8be111 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; @@ -125,7 +126,16 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List( 1 + additionalParameters.size() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Mapper.java new file mode 100644 index 0000000000..3cec3e0b3c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Mapper.java @@ -0,0 +1,86 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2478; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2478Mapper { + + Issue2478Mapper INSTANCE = Mappers.getMapper( Issue2478Mapper.class ); + + ProductEntity productFromDto(Product dto, @Context Shop shop); + + class Product { + protected final String name; + protected final Shop shop; + + public Product(String name, Shop shop) { + this.name = name; + this.shop = shop; + } + + public String getName() { + return name; + } + + public Shop getShop() { + return shop; + } + } + + class Shop { + protected final String name; + + public Shop(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class ProductEntity { + + protected String name; + protected ShopEntity shop; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ShopEntity getShop() { + return shop; + } + + public void setShop(ShopEntity shop) { + this.shop = shop; + } + } + + class ShopEntity { + protected String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Test.java new file mode 100644 index 0000000000..05e21f4c40 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2478/Issue2478Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2478; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2478") +@WithClasses({ + Issue2478Mapper.class +}) +class Issue2478Test { + + @ProcessorTest + void shouldGenerateCodeThatCompiles() { + Issue2478Mapper.Product dto = new Issue2478Mapper.Product( "Test", new Issue2478Mapper.Shop( "Shopify" ) ); + Issue2478Mapper.ProductEntity entity = Issue2478Mapper.INSTANCE.productFromDto( dto, dto.getShop() ); + + assertThat( entity ).isNotNull(); + assertThat( entity.getName() ).isEqualTo( "Test" ); + assertThat( entity.getShop() ).isNotNull(); + assertThat( entity.getShop().getName() ).isEqualTo( "Shopify" ); + } +} From 845d83e9d510aa2405cbe82167ff35bb983fb5ac Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 5 Jun 2021 11:39:52 +0200 Subject: [PATCH 0584/1006] #2439 Do not throw NPE getting accessors for null typeElement Provide better error message if the source type has no read properties --- .../model/beanmapping/SourceReference.java | 36 +++++++++----- .../ap/internal/model/common/Type.java | 15 ++++-- .../mapstruct/ap/internal/util/Message.java | 1 + .../bugs/_2439/ErroneousIssue2439Mapper.java | 48 +++++++++++++++++++ .../ap/test/bugs/_2439/Issuer2439Test.java | 38 +++++++++++++++ 5 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/ErroneousIssue2439Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/Issuer2439Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index c87c6fb46d..4f2d0957e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.type.DeclaredType; @@ -277,17 +278,30 @@ private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, notFoundPropertyIndex = entries.size(); sourceType = last( entries ).getType(); } - String mostSimilarWord = Strings.getMostSimilarWord( - propertyNames[notFoundPropertyIndex], - sourceType.getPropertyReadAccessors().keySet() - ); - List elements = new ArrayList<>( - Arrays.asList( propertyNames ).subList( 0, notFoundPropertyIndex ) - ); - elements.add( mostSimilarWord ); - reportMappingError( - Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, sourceName, Strings.join( elements, "." ) - ); + + Set readProperties = sourceType.getPropertyReadAccessors().keySet(); + + if ( !readProperties.isEmpty() ) { + String mostSimilarWord = Strings.getMostSimilarWord( + propertyNames[notFoundPropertyIndex], + readProperties + ); + + List elements = new ArrayList<>( + Arrays.asList( propertyNames ).subList( 0, notFoundPropertyIndex ) + ); + elements.add( mostSimilarWord ); + reportMappingError( + Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, sourceName, Strings.join( elements, "." ) + ); + } + else { + reportMappingError( + Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME_SOURCE_HAS_NO_PROPERTIES, + sourceName, + sourceType.describe() + ); + } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 15f787829b..4da9128f98 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -14,6 +14,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -693,7 +694,7 @@ else if ( candidate.getAccessorType() == AccessorType.FIELD && ( Executables.is public List getRecordComponents() { if ( recordComponents == null ) { - recordComponents = filters.recordComponentsIn( typeElement ); + recordComponents = nullSafeTypeElementListConversion( filters::recordComponentsIn ); } return recordComponents; @@ -720,7 +721,7 @@ else if ( candidate.getAccessorType() == AccessorType.GETTER private List getAllMethods() { if ( allMethods == null ) { - allMethods = elementUtils.getAllEnclosedExecutableElements( typeElement ); + allMethods = nullSafeTypeElementListConversion( elementUtils::getAllEnclosedExecutableElements ); } return allMethods; @@ -728,12 +729,20 @@ private List getAllMethods() { private List getAllFields() { if ( allFields == null ) { - allFields = elementUtils.getAllEnclosedFields( typeElement ); + allFields = nullSafeTypeElementListConversion( elementUtils::getAllEnclosedFields ); } return allFields; } + private List nullSafeTypeElementListConversion(Function> conversionFunction) { + if ( typeElement != null ) { + return conversionFunction.apply( typeElement ); + } + + return Collections.emptyList(); + } + private String getPropertyName(Accessor accessor ) { Element accessorElement = accessor.getElement(); if ( accessorElement instanceof ExecutableElement ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index cb182af6b9..4c474186d3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -70,6 +70,7 @@ public enum Message { PROPERTYMAPPING_INVALID_PARAMETER_NAME( "Method has no source parameter named \"%s\". Method source parameters are: \"%s\"." ), PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER( "The type of parameter \"%s\" has no property named \"%s\"." ), PROPERTYMAPPING_INVALID_PROPERTY_NAME( "No property named \"%s\" exists in source parameter(s). Did you mean \"%s\"?" ), + PROPERTYMAPPING_INVALID_PROPERTY_NAME_SOURCE_HAS_NO_PROPERTIES( "No property named \"%s\" exists in source parameter(s). Type \"%s\" has no properties." ), PROPERTYMAPPING_NO_PRESENCE_CHECKER_FOR_SOURCE_TYPE( "Using custom source value presence checking strategy, but no presence checker found for %s in source type." ), PROPERTYMAPPING_NO_READ_ACCESSOR_FOR_TARGET_TYPE( "No read accessor found for property \"%s\" in target type." ), PROPERTYMAPPING_NO_WRITE_ACCESSOR_FOR_TARGET_TYPE( "No write accessor found for property \"%s\" in target type." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/ErroneousIssue2439Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/ErroneousIssue2439Mapper.java new file mode 100644 index 0000000000..a154d55fff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/ErroneousIssue2439Mapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2439; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousIssue2439Mapper { + + @Mapping(target = "modeName", source = "mode.desc") + LiveDto map(LiveEntity entity); + + class LiveEntity { + private final LiveMode[] mode; + + public LiveEntity(LiveMode... mode) { + this.mode = mode; + } + + public LiveMode[] getMode() { + return mode; + } + } + + class LiveDto { + private String modeName; + + public String getModeName() { + return modeName; + } + + public void setModeName(String modeName) { + this.modeName = modeName; + } + } + + enum LiveMode { + TEST, + PROD, + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/Issuer2439Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/Issuer2439Test.java new file mode 100644 index 0000000000..c3c4702927 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2439/Issuer2439Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2439; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2439") +@WithClasses({ + ErroneousIssue2439Mapper.class +}) +class Issuer2439Test { + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIssue2439Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "No property named \"mode.desc\" exists in source parameter(s)." + + " Type \"ErroneousIssue2439Mapper.LiveMode[]\" has no properties.") + } + ) + void shouldProvideGoodErrorMessage() { + + } +} From 5d8fcfa033f8f51614a7b07d791d1ba94b5df7f2 Mon Sep 17 00:00:00 2001 From: Tobias Meggendorfer Date: Sun, 13 Jun 2021 11:28:04 +0200 Subject: [PATCH 0585/1006] #2481 Report ignored source properties which are missing --- .../ap/internal/model/BeanMappingMethod.java | 25 ++++++++++++++- .../internal/model/source/MapperOptions.java | 1 - .../mapstruct/ap/internal/util/Message.java | 1 + .../ErroneousSourceTargetMapper.java | 21 +++++++++++++ .../MissingIgnoredSourceTest.java | 31 +++++++++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 324df63cc8..2dba4637fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -98,6 +98,7 @@ public static class Builder { private Map unprocessedConstructorProperties; private Map unprocessedTargetProperties; private Map unprocessedSourceProperties; + private Set missingIgnoredSourceProperties; private Set targetProperties; private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); @@ -248,9 +249,12 @@ else if ( !method.isUpdateMethod() ) { } // get bean mapping (when specified as annotation ) + this.missingIgnoredSourceProperties = new HashSet<>(); if ( beanMapping != null ) { for ( String ignoreUnmapped : beanMapping.getIgnoreUnmappedSourceProperties() ) { - unprocessedSourceProperties.remove( ignoreUnmapped ); + if ( unprocessedSourceProperties.remove( ignoreUnmapped ) == null ) { + missingIgnoredSourceProperties.add( ignoreUnmapped ); + } } } @@ -283,6 +287,7 @@ else if ( !method.isUpdateMethod() ) { // report errors on unmapped properties reportErrorForUnmappedTargetPropertiesIfRequired(); reportErrorForUnmappedSourcePropertiesIfRequired(); + reportErrorForMissingIgnoredSourceProperties(); // mapNullToDefault boolean mapNullToDefault = method.getOptions() @@ -1511,6 +1516,24 @@ private void reportErrorForUnmappedSourcePropertiesIfRequired() { ); } } + + private void reportErrorForMissingIgnoredSourceProperties() { + if ( !missingIgnoredSourceProperties.isEmpty() ) { + Object[] args = new Object[] { + MessageFormat.format( + "{0,choice,1#property|1 imports() { public ReportingPolicyGem unmappedTargetPolicy() { return mapper.unmappedTargetPolicy().hasValue() ? ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().get() ) : next().unmappedTargetPolicy(); - } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4c474186d3..4bacef6a07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -37,6 +37,7 @@ public enum Message { BEANMAPPING_UNMAPPED_FORGED_TARGETS_ERROR( "Unmapped target %s. Mapping from %s to %s." ), BEANMAPPING_UNMAPPED_SOURCES_WARNING( "Unmapped source %s.", Diagnostic.Kind.WARNING ), BEANMAPPING_UNMAPPED_SOURCES_ERROR( "Unmapped source %s." ), + BEANMAPPING_MISSING_IGNORED_SOURCES_ERROR( "Ignored unknown source %s." ), BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS( "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not allowed. You'll need to explicitly ignore the target properties that should be ignored instead." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java new file mode 100644 index 0000000000..659867ca40 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.missingignoredsource; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( + unmappedTargetPolicy = ReportingPolicy.IGNORE, + unmappedSourcePolicy = ReportingPolicy.IGNORE) +public interface ErroneousSourceTargetMapper { + ErroneousSourceTargetMapper INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper.class ); + + @BeanMapping(ignoreUnmappedSourceProperties = "bar") + Object sourceToTarget(Object source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java new file mode 100644 index 0000000000..77f80c5537 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.missingignoredsource; + +import javax.tools.Diagnostic.Kind; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +public class MissingIgnoredSourceTest { + + @ProcessorTest + @WithClasses({ ErroneousSourceTargetMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapper.class, + kind = Kind.ERROR, + line = 20, + message = "Ignored unknown source property: \"bar\".") + } + ) + public void shouldRaiseErrorDueToMissingIgnoredSourceProperty() { + } +} From 4c338fa1db0c6af9b73b5a3376f611efe22e507d Mon Sep 17 00:00:00 2001 From: chaos Date: Wed, 23 Jun 2021 10:31:30 +0800 Subject: [PATCH 0586/1006] fix(pom): fix gradle repo url 404 original url is 404 replace with new url --- integrationtest/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 17a6a4a9a9..4b48c19496 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -28,7 +28,7 @@ gradle - https://repo.gradle.org/gradle/libs-releases + https://repo.gradle.org/artifactory/libs-releases/ true From 1bf698785c795bf7d3832a129ff5ca3cb170ff3e Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 24 Jun 2021 19:19:02 +0200 Subject: [PATCH 0587/1006] Fix typo in Named.java (#2500) --- core/src/main/java/org/mapstruct/Named.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/Named.java b/core/src/main/java/org/mapstruct/Named.java index 0b6e8b53a9..773886a7b1 100644 --- a/core/src/main/java/org/mapstruct/Named.java +++ b/core/src/main/java/org/mapstruct/Named.java @@ -14,7 +14,7 @@ * Marks mapping methods with the given qualifier name. Can be used to qualify a single method or all methods of a given * type by specifying this annotation on the type level. *

      - * Will be used to to select the correct mapping methods when mapping a bean property type, element of an iterable type + * Will be used to select the correct mapping methods when mapping a bean property type, element of an iterable type * or the key/value of a map type. *

      * Example (both methods of {@code Titles} are capable to convert a string, but the ambiguity is resolved by applying From c5c292f602b7a60e762d1cbac04283e3330c6d87 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 26 Jun 2021 11:28:37 +0200 Subject: [PATCH 0588/1006] #2501 Add test case --- .../ap/test/bugs/_2501/Issue2501Mapper.java | 62 +++++++++++++++++++ .../ap/test/bugs/_2501/Issue2501Test.java | 30 +++++++++ 2 files changed, 92 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Mapper.java new file mode 100644 index 0000000000..08fa637791 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Mapper.java @@ -0,0 +1,62 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2501; + +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2501Mapper { + + Issue2501Mapper INSTANCE = Mappers.getMapper( Issue2501Mapper.class ); + + Customer map(CustomerDTO value); + + CustomerStatus map(DtoStatus status); + + default T unwrap(Optional optional) { + return optional.orElse( null ); + } + + enum CustomerStatus { + ENABLED, DISABLED, + } + + class Customer { + + private CustomerStatus status; + + public CustomerStatus getStatus() { + return status; + } + + public void setStatus(CustomerStatus stat) { + this.status = stat; + } + } + + enum DtoStatus { + ENABLED, DISABLED + } + + class CustomerDTO { + + private DtoStatus status; + + public Optional getStatus() { + return Optional.ofNullable( status ); + } + + public void setStatus(DtoStatus stat) { + this.status = stat; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Test.java new file mode 100644 index 0000000000..c5eb1e0aed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2501/Issue2501Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2501; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue2501Mapper.class +}) +class Issue2501Test { + + @ProcessorTest + void shouldUnwrapEnumOptional() { + Issue2501Mapper.CustomerDTO source = new Issue2501Mapper.CustomerDTO(); + source.setStatus( Issue2501Mapper.DtoStatus.DISABLED ); + + Issue2501Mapper.Customer target = Issue2501Mapper.INSTANCE.map( source ); + + assertThat( target.getStatus() ).isEqualTo( Issue2501Mapper.CustomerStatus.DISABLED ); + } +} From fb9c7a3dedcc751917109cae05d33026c12f92c6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 19 Jun 2021 17:11:04 +0200 Subject: [PATCH 0589/1006] #2491 Do not use types not part of java.base in MapStruct processor MapStruct should not use types that are outside of java.base. This makes sure that no additional dependencies (such as jaxb-api) are needed on the annotation processor path --- .../ProcessorInvocationInterceptor.java | 6 +- .../testutil/extension/ProcessorTest.java | 12 +++ integrationtest/src/test/resources/pom.xml | 32 ++++++++ .../common/DateFormatValidatorFactory.java | 2 +- .../AbstractToXmlGregorianCalendar.java | 14 ++-- .../source/builtin/BuiltInMappingMethods.java | 5 +- .../model/source/builtin/JaxbElemToValue.java | 5 +- ...daLocalDateTimeToXmlGregorianCalendar.java | 4 +- .../JodaLocalDateToXmlGregorianCalendar.java | 4 +- .../JodaLocalTimeToXmlGregorianCalendar.java | 4 +- .../LocalDateTimeToXmlGregorianCalendar.java | 5 +- .../LocalDateToXmlGregorianCalendar.java | 4 +- .../XmlGregorianCalendarToCalendar.java | 4 +- .../builtin/XmlGregorianCalendarToDate.java | 4 +- .../XmlGregorianCalendarToJodaDateTime.java | 7 +- .../XmlGregorianCalendarToJodaLocalDate.java | 7 +- ...lGregorianCalendarToJodaLocalDateTime.java | 7 +- .../XmlGregorianCalendarToJodaLocalTime.java | 7 +- .../XmlGregorianCalendarToLocalDate.java | 4 +- .../XmlGregorianCalendarToLocalDateTime.java | 8 +- .../builtin/XmlGregorianCalendarToString.java | 4 +- .../ap/internal/util/ClassUtils.java | 76 ------------------- .../ap/internal/util/JaxbConstants.java | 10 --- .../ap/internal/util/XmlConstants.java | 17 ++--- 24 files changed, 98 insertions(+), 154 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 839bf86f18..89009aaffe 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -136,7 +136,11 @@ private void addAdditionalCliArguments(Verifier verifier) private void configureProcessor(Verifier verifier) { String compilerId = processorTestContext.getProcessor().getCompilerId(); if ( compilerId != null ) { - verifier.addCliOption( "-Pgenerate-via-compiler-plugin" ); + String profile = processorTestContext.getProcessor().getProfile(); + if ( profile == null ) { + profile = "generate-via-compiler-plugin"; + } + verifier.addCliOption( "-P" + profile ); verifier.addCliOption( "-Dcompiler-id=" + compilerId ); } else { diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java index eb8553960c..95480eee9d 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java @@ -44,6 +44,7 @@ enum ProcessorType { JAVAC( "javac" ), + JAVAC_WITH_PATHS( "javac", JRE.OTHER, "generate-via-compiler-plugin-with-annotation-processor-paths" ), ECLIPSE_JDT( "jdt", JRE.JAVA_8 ), @@ -51,14 +52,20 @@ enum ProcessorType { private final String compilerId; private final JRE max; + private final String profile; ProcessorType(String compilerId) { this( compilerId, JRE.OTHER ); } ProcessorType(String compilerId, JRE max) { + this( compilerId, max, null ); + } + + ProcessorType(String compilerId, JRE max, String profile) { this.compilerId = compilerId; this.max = max; + this.profile = profile; } public String getCompilerId() { @@ -68,6 +75,10 @@ public String getCompilerId() { public JRE maxJre() { return max; } + + public String getProfile() { + return profile; + } } /** @@ -98,6 +109,7 @@ Collection getAdditionalCommandLineArguments(ProcessorType processorType */ ProcessorType[] processorTypes() default { ProcessorType.JAVAC, + ProcessorType.JAVAC_WITH_PATHS, ProcessorType.ECLIPSE_JDT, ProcessorType.PROCESSOR_PLUGIN }; diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index e209daf234..c8a19228f0 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -65,6 +65,38 @@ + + generate-via-compiler-plugin-with-annotation-processor-paths + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + \${compiler-id} + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + + + + + + org.eclipse.tycho + tycho-compiler-jdt + ${org.eclipse.tycho.compiler-jdt.version} + + + + + + generate-via-processor-plugin diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index 8e8c328f20..09e4957aad 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -75,7 +75,7 @@ public DateFormatValidationResult validate(String dateFormat) { private static boolean isXmlGregorianCalendarSupposedToBeMapped(Type sourceType, Type targetType) { return typesEqualsOneOf( - sourceType, targetType, XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + sourceType, targetType, XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); } private static boolean isJodaDateTimeSupposed(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java index 7a2ac5588f..e2ccc3f476 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java @@ -9,16 +9,12 @@ import java.util.Set; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.ConstructorFragment; import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.common.FinalField; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.XmlConstants; /** * @author Sjaak Derksen @@ -30,12 +26,12 @@ public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod { private final Type dataTypeFactoryType; public AbstractToXmlGregorianCalendar(TypeFactory typeFactory) { - this.returnType = typeFactory.getType( XMLGregorianCalendar.class ); - this.dataTypeFactoryType = typeFactory.getType( DatatypeFactory.class ); + this.returnType = typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); + this.dataTypeFactoryType = typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_FACTORY ); this.importTypes = asSet( returnType, dataTypeFactoryType, - typeFactory.getType( DatatypeConfigurationException.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONFIGURATION_EXCEPTION ) ); } @@ -51,7 +47,7 @@ public Type getReturnType() { @Override public FieldReference getFieldReference() { - return new FinalField( dataTypeFactoryType, Strings.decapitalize( DatatypeFactory.class.getSimpleName() ) ); + return new FinalField( dataTypeFactoryType, "datatypeFactory" ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 4b096f8035..0edae7f10f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -59,12 +59,11 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { } private static boolean isJaxbAvailable(TypeFactory typeFactory) { - return JaxbConstants.isJaxbElementPresent() && typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); + return typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); } private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) { - return XmlConstants.isXmlGregorianCalendarPresent() && - typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR ); + return typeFactory.isTypeAvailable( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ); } private static boolean isJodaTimeAvailable(TypeFactory typeFactory) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 4d116266fd..0d3d4c30af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -9,11 +9,10 @@ import java.util.Set; -import javax.xml.bind.JAXBElement; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.JaxbConstants; /** * @author Sjaak Derksen @@ -25,7 +24,7 @@ public class JaxbElemToValue extends BuiltInMethod { private final Set importTypes; public JaxbElemToValue(TypeFactory typeFactory) { - Type type = typeFactory.getType( JAXBElement.class ); + Type type = typeFactory.getType( JaxbConstants.JAXB_ELEMENT_FQN ); this.parameter = new Parameter( "element", type ); this.returnType = type.getTypeParameters().get( 0 ); this.importTypes = asSet( parameter.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java index fa87bff2db..80fa9ba326 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public JodaLocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java index e958ca952e..37c89ef360 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public JodaLocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java index e9daac39c8..b29c7aec54 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java @@ -6,12 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public JodaLocalTimeToXmlGregorianCalendar(TypeFactory typeFactory) { this.parameter = new Parameter( "dt", typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java index 8853c1aae7..178a77b5fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java @@ -9,11 +9,10 @@ import java.time.temporal.ChronoField; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -30,7 +29,7 @@ public LocalDateTimeToXmlGregorianCalendar(TypeFactory typeFactory) { this.parameter = new Parameter( "localDateTime", typeFactory.getType( LocalDateTime.class ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( ChronoField.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java index 96c8a8a31b..2e2544ade0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java @@ -7,11 +7,11 @@ import java.time.LocalDate; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,7 +28,7 @@ public LocalDateToXmlGregorianCalendar(TypeFactory typeFactory) { this.parameter = new Parameter( "localDate", typeFactory.getType( LocalDate.class ) ); this.importTypes = asSet( parameter.getType(), - typeFactory.getType( DatatypeConstants.class ) + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java index f4d8ceee9b..03927fd869 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java @@ -7,11 +7,11 @@ import java.util.Calendar; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToCalendar extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToCalendar(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( Calendar.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java index 7f270be5f6..38f76a66ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java @@ -7,11 +7,11 @@ import java.util.Date; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( Date.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java index ab2db49e8a..ab6658bfc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.DATE_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( JodaTimeConstants.DATE_TIME_ZONE_FQN ), returnType, parameter.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java index d26cde0215..f45488755c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_DATE_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java index 700c19c211..af7fd9e9fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_DATE_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java index b3eae20314..3725691134 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java @@ -6,13 +6,12 @@ package org.mapstruct.ap.internal.model.source.builtin; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JodaTimeConstants; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -26,10 +25,10 @@ public class XmlGregorianCalendarToJodaLocalTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToJodaLocalTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( JodaTimeConstants.LOCAL_TIME_FQN ); this.importTypes = asSet( - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java index 1da6951b9a..2c9ced3413 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java @@ -7,11 +7,11 @@ import java.time.LocalDate; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -25,7 +25,7 @@ public class XmlGregorianCalendarToLocalDate extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToLocalDate(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( LocalDate.class ); this.importTypes = asSet( returnType, parameter.getType() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java index 5d29892444..b676bd03a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java @@ -9,12 +9,10 @@ import java.time.LocalDateTime; import java.util.Set; -import javax.xml.datatype.DatatypeConstants; -import javax.xml.datatype.XMLGregorianCalendar; - import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -28,12 +26,12 @@ public class XmlGregorianCalendarToLocalDateTime extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToLocalDateTime(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( LocalDateTime.class ); this.importTypes = asSet( returnType, parameter.getType(), - typeFactory.getType( DatatypeConstants.class ), + typeFactory.getType( XmlConstants.JAVAX_XML_DATATYPE_CONSTANTS ), typeFactory.getType( Duration.class ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java index 73ac51fa2a..c932da6675 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java @@ -8,12 +8,12 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Set; -import javax.xml.datatype.XMLGregorianCalendar; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.XmlConstants; import static org.mapstruct.ap.internal.util.Collections.asSet; @@ -27,7 +27,7 @@ public class XmlGregorianCalendarToString extends BuiltInMethod { private final Set importTypes; public XmlGregorianCalendarToString(TypeFactory typeFactory) { - this.parameter = new Parameter( "xcal", typeFactory.getType( XMLGregorianCalendar.class ) ); + this.parameter = new Parameter( "xcal", typeFactory.getType( XmlConstants.JAVAX_XML_XML_GREGORIAN_CALENDAR ) ); this.returnType = typeFactory.getType( String.class ); this.importTypes = asSet( parameter.getType(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java deleted file mode 100644 index d66d81f9b0..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ClassUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util; - -/** - * Utilities for working with classes. It is mainly needed because using the {@link ElementUtils} - * is not always correct. For example when compiling with JDK 9 and source version 8 classes from different modules - * are available by {@link ElementUtils#getTypeElement(CharSequence)} but they are actually not - * if those modules are not added during compilation. - * - * @author Filip Hrisafov - */ -class ClassUtils { - - private ClassUtils() { - } - - /** - * Determine whether the {@link Class} identified by the supplied name is present - * and can be loaded. Will return {@code false} if either the class or - * one of its dependencies is not present or cannot be loaded. - * - * @param className the name of the class to check - * @param classLoader the class loader to use - * (may be {@code null}, which indicates the default class loader) - * - * @return whether the specified class is present - */ - static boolean isPresent(String className, ClassLoader classLoader) { - try { - ClassLoader classLoaderToUse = classLoader; - if ( classLoaderToUse == null ) { - classLoaderToUse = getDefaultClassLoader(); - } - classLoaderToUse.loadClass( className ); - return true; - } - catch ( ClassNotFoundException ex ) { - // Class or one of its dependencies is not present... - return false; - } - } - - /** - * Return the default ClassLoader to use: typically the thread context - * ClassLoader, if available; the ClassLoader that loaded the ClassUtils - * class will be used as fallback. - *

      Call this method if you intend to use the thread context ClassLoader - * in a scenario where you absolutely need a non-null ClassLoader reference: - * for example, for class path resource loading (but not necessarily for - * {@code Class.forName}, which accepts a {@code null} ClassLoader - * reference as well). - * - * @return the default ClassLoader (never {@code null}) - * - * @see Thread#getContextClassLoader() - */ - private static ClassLoader getDefaultClassLoader() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } - catch ( Throwable ex ) { - // Cannot access thread context ClassLoader - falling back to system class loader... - } - if ( cl == null ) { - // No thread context class loader -> use class loader of this class. - cl = ClassUtils.class.getClassLoader(); - } - return cl; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java index f8f01cd18c..db18673ba2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java @@ -11,18 +11,8 @@ public final class JaxbConstants { public static final String JAXB_ELEMENT_FQN = "javax.xml.bind.JAXBElement"; - private static final boolean IS_JAXB_ELEMENT_PRESENT = ClassUtils.isPresent( - JAXB_ELEMENT_FQN, - JaxbConstants.class.getClassLoader() - ); private JaxbConstants() { } - /** - * @return {@code true} if {@link javax.xml.bind.JAXBElement} is present, {@code false} otherwise - */ - public static boolean isJaxbElementPresent() { - return IS_JAXB_ELEMENT_PRESENT; - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java index 8216e83121..532b9f0bce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/XmlConstants.java @@ -12,19 +12,14 @@ */ public final class XmlConstants { - public static final String JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; - private static final boolean IS_XML_GREGORIAN_CALENDAR_PRESENT = ClassUtils.isPresent( - JAVAX_XML_DATATYPE_XMLGREGORIAN_CALENDAR, - XmlConstants.class.getClassLoader() - ); + // CHECKSTYLE:OFF + public static final String JAVAX_XML_XML_GREGORIAN_CALENDAR = "javax.xml.datatype.XMLGregorianCalendar"; + public static final String JAVAX_XML_DATATYPE_CONFIGURATION_EXCEPTION = "javax.xml.datatype.DatatypeConfigurationException"; + public static final String JAVAX_XML_DATATYPE_FACTORY = "javax.xml.datatype.DatatypeFactory"; + public static final String JAVAX_XML_DATATYPE_CONSTANTS = "javax.xml.datatype.DatatypeConstants"; + // CHECKSTYLE:ON private XmlConstants() { } - /** - * @return {@code true} if the {@link javax.xml.datatype.XMLGregorianCalendar} is present, {@code false} otherwise - */ - public static boolean isXmlGregorianCalendarPresent() { - return IS_XML_GREGORIAN_CALENDAR_PRESENT; - } } From 985ca2fe64745607b003c71a87559dfbe8ffe482 Mon Sep 17 00:00:00 2001 From: Christian Kosmowski Date: Sat, 26 Jun 2021 11:18:02 +0200 Subject: [PATCH 0590/1006] #1075 Support for Mapping from Map to Bean Co-authored-by: Filip Hrisafov --- .../chapter-3-defining-a-mapper.asciidoc | 65 +++ .../ap/internal/model/BeanMappingMethod.java | 43 +- .../ap/internal/model/PropertyMapping.java | 24 ++ .../model/beanmapping/SourceReference.java | 46 +++ ...urceReferenceContainsKeyPresenceCheck.java | 59 +++ .../mapstruct/ap/internal/util/Message.java | 6 +- .../ap/internal/util/ValueProvider.java | 5 + .../internal/util/accessor/AccessorType.java | 2 + .../util/accessor/MapValueAccessor.java | 55 +++ .../accessor/MapValuePresenceChecker.java | 55 +++ ...ourceReferenceContainsKeyPresenceCheck.ftl | 9 + .../ap/test/frommap/FromMapMappingTest.java | 371 ++++++++++++++++++ .../test/frommap/MapToBeanDefinedMapper.java | 38 ++ .../frommap/MapToBeanFromMapAndNestedMap.java | 67 ++++ .../MapToBeanFromMapAndNestedSource.java | 79 ++++ .../frommap/MapToBeanFromMultipleSources.java | 70 ++++ .../test/frommap/MapToBeanImplicitMapper.java | 36 ++ ...eanImplicitUnmappedSourcePolicyMapper.java | 38 ++ ...ToBeanNonStringMapAsMultiSourceMapper.java | 55 +++ .../test/frommap/MapToBeanRawMapMapper.java | 36 ++ .../frommap/MapToBeanTypeCheckMapper.java | 36 ++ .../MapToBeanUpdateImplicitMapper.java | 47 +++ .../MapToBeanUsingMappingMethodMapper.java | 42 ++ .../frommap/MapToBeanWithDefaultMapper.java | 38 ++ .../ObjectMapToBeanWithQualifierMapper.java | 74 ++++ .../test/frommap/StringMapToBeanMapper.java | 67 ++++ ...apToBeanWithCustomPresenceCheckMapper.java | 74 ++++ 27 files changed, 1535 insertions(+), 2 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanDefinedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMap.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMultipleSources.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitUnmappedSourcePolicyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanNonStringMapAsMultiSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanRawMapMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanTypeCheckMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUpdateImplicitMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanWithDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/ObjectMapToBeanWithQualifierMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanWithCustomPresenceCheckMapper.java diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index f679d4494a..2d2b930114 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -650,3 +650,68 @@ public class PersonMapperImpl implements PersonMapper { } ---- ==== + +[[mapping-map-to-bean]] +=== Mapping Map to Bean + +There are situations when a mapping from a `Map` into a specific bean is needed. +MapStruct offers a transparent way of doing such a mapping by using the target bean properties (or defined through `Mapping#source`) to extract the values from the map. +Such a mapping looks like: + +.Example classes for mapping map to bean +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Customer { + + private Long id; + private String name; + + //getters and setter omitted for brevity +} + +@Mapper +public interface CustomerMapper { + + @Mapping(target = "name", source = "customerName") + Customer toCustomer(Map map); + +} +---- +==== + +.Generated mapper for mapping map to bean +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CustomerMapperImpl implements CustomerMapper { + + @Override + public Customer toCustomer(Map map) { + // ... + if ( map.containsKey( "id" ) ) { + customer.setId( Integer.parseInt( map.get( "id" ) ) ); + } + if ( map.containsKey( "customerName" ) ) { + customer.setName( source.get( "customerName" ) ); + } + // ... + } +} +---- +==== + +[NOTE] +==== +All existing rules about mapping between different types and using other mappers defined with `Mapper#uses` or custom methods in the mappers are applied. +i.e. You can map from `Map` where for each property a conversion from `Integer` into the respective property will be needed. +==== + +[WARNING] +==== +When a raw map or a map that does not have a String as a key is used, then a warning will be generated. +The warning is not generated if the map itself is mapped into some other target property directly as is. +==== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 2dba4637fd..09cc20a6ed 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -238,9 +238,11 @@ else if ( !method.isUpdateMethod() ) { for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); - if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() ) { + if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() || + sourceParameter.getType().isMapType() ) { continue; } + Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); for ( Entry entry : readAccessors.entrySet() ) { @@ -276,6 +278,7 @@ else if ( !method.isUpdateMethod() ) { // map parameters without a mapping applyParameterNameBasedMapping(); + } // Process the unprocessed defined targets @@ -288,6 +291,7 @@ else if ( !method.isUpdateMethod() ) { reportErrorForUnmappedTargetPropertiesIfRequired(); reportErrorForUnmappedSourcePropertiesIfRequired(); reportErrorForMissingIgnoredSourceProperties(); + reportErrorForUnusedSourceParameters(); // mapNullToDefault boolean mapNullToDefault = method.getOptions() @@ -1364,6 +1368,16 @@ private SourceReference getSourceRefByTargetName(Parameter sourceParameter, Stri return sourceRef; } + if ( sourceParameter.getType().isMapType() ) { + List typeParameters = sourceParameter.getType().getTypeParameters(); + if ( typeParameters.size() == 2 && typeParameters.get( 0 ).isString() ) { + return SourceReference.fromMapSource( + new String[] { targetPropertyName }, + sourceParameter + ); + } + } + Accessor sourceReadAccessor = sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); if ( sourceReadAccessor != null ) { @@ -1534,6 +1548,33 @@ private void reportErrorForMissingIgnoredSourceProperties() { ); } } + + private void reportErrorForUnusedSourceParameters() { + for ( Parameter sourceParameter : unprocessedSourceParameters ) { + Type parameterType = sourceParameter.getType(); + if ( parameterType.isMapType() ) { + // We are only going to output a warning for the source parameter if it was unused + // i.e. the intention of the user was most likely to use it as a mapping from Bean to Map + List typeParameters = parameterType.getTypeParameters(); + if ( typeParameters.size() != 2 || !typeParameters.get( 0 ).isString() ) { + Message message = typeParameters.isEmpty() ? + Message.MAPTOBEANMAPPING_RAW_MAP : + Message.MAPTOBEANMAPPING_WRONG_KEY_TYPE; + ctx.getMessager() + .printMessage( + method.getExecutable(), + message, + sourceParameter.getName(), + String.format( + "Map<%s,%s>", + !typeParameters.isEmpty() ? typeParameters.get( 0 ).describe() : "", + typeParameters.size() > 1 ? typeParameters.get( 1 ).describe() : "" + ) + ); + } + } + } + } } private static class ConstructorAccessor { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index b53b8f90ec..82d2dd53fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -37,6 +37,7 @@ import org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck; import org.mapstruct.ap.internal.model.presence.JavaExpressionPresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; +import org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck; import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; import org.mapstruct.ap.internal.model.source.DelegatingOptions; import org.mapstruct.ap.internal.model.source.MappingControl; @@ -307,6 +308,9 @@ private Assignment forge( ) { else if ( sourceType.isMapType() && targetType.isMapType() ) { assignment = forgeMapMapping( sourceType, targetType, rightHandSide ); } + else if ( sourceType.isMapType() && !targetType.isMapType()) { + assignment = forgeMapToBeanMapping( sourceType, targetType, rightHandSide ); + } else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) || ( sourceType.isStreamType() && targetType.isStreamType() ) || ( sourceType.isStreamType() && targetType.isIterableType() ) ) { @@ -656,6 +660,13 @@ private PresenceCheck getSourcePresenceCheckerRef(SourceReference sourceReferenc // in the forged method? PropertyEntry propertyEntry = sourceReference.getShallowestProperty(); if ( propertyEntry.getPresenceChecker() != null ) { + if (propertyEntry.getPresenceChecker().getAccessorType() == AccessorType.MAP_CONTAINS ) { + return new SourceReferenceContainsKeyPresenceCheck( + sourceParam.getName(), + propertyEntry.getPresenceChecker().getSimpleName() + ); + } + List presenceChecks = new ArrayList<>(); presenceChecks.add( new SourceReferenceMethodPresenceCheck( sourceParam.getName(), @@ -742,6 +753,19 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s return createForgedAssignment( source, methodRef, mapMappingMethod ); } + private Assignment forgeMapToBeanMapping(Type sourceType, Type targetType, SourceRHS source) { + + targetType = targetType.withoutBounds(); + ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "{}" ); + + BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); + final BeanMappingMethod mapToBeanMappingMethod = builder.mappingContext( ctx ) + .forgedMethod( methodRef ) + .build(); + + return createForgedAssignment( source, methodRef, mapToBeanMappingMethod ); + } + private Assignment forgeMapping(SourceRHS sourceRHS) { Type sourceType; if ( targetWriteAccessorType == AccessorType.ADDER ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 4f2d0957e7..15b10b5782 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -7,13 +7,16 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -24,6 +27,8 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; +import org.mapstruct.ap.internal.util.accessor.MapValuePresenceChecker; import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.last; @@ -52,6 +57,26 @@ */ public class SourceReference extends AbstractReference { + public static SourceReference fromMapSource(String[] segments, Parameter parameter) { + Type parameterType = parameter.getType(); + Type valueType = parameterType.getTypeParameters().get( 1 ); + + TypeElement typeElement = parameterType.getTypeElement(); + TypeMirror typeMirror = valueType.getTypeMirror(); + String simpleName = String.join( ".", segments ); + + MapValueAccessor mapValueAccessor = new MapValueAccessor( typeElement, typeMirror, simpleName ); + MapValuePresenceChecker mapValuePresenceChecker = new MapValuePresenceChecker( + typeElement, + typeMirror, + simpleName + ); + List entries = Collections.singletonList( + PropertyEntry.forSourceReference( segments, mapValueAccessor, mapValuePresenceChecker, valueType ) + ); + return new SourceReference( parameter, entries, true ); + } + /** * Builds a {@link SourceReference} from an {@code @Mappping}. */ @@ -149,6 +174,10 @@ public SourceReference build() { */ private SourceReference buildFromSingleSourceParameters(String[] segments, Parameter parameter) { + if ( canBeTreatedAsMapSourceType( parameter.getType() ) ) { + return fromMapSource( segments, parameter ); + } + boolean foundEntryMatch; String[] propertyNames = segments; @@ -185,6 +214,14 @@ private SourceReference buildFromSingleSourceParameters(String[] segments, Param */ private SourceReference buildFromMultipleSourceParameters(String[] segments, Parameter parameter) { + if (parameter != null && canBeTreatedAsMapSourceType( parameter.getType() )) { + String[] propertyNames = new String[0]; + if ( segments.length > 1 ) { + propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); + } + return fromMapSource( propertyNames, parameter ); + } + boolean foundEntryMatch; String[] propertyNames = new String[0]; @@ -207,6 +244,15 @@ private SourceReference buildFromMultipleSourceParameters(String[] segments, Par return new SourceReference( parameter, entries, foundEntryMatch ); } + private boolean canBeTreatedAsMapSourceType(Type type) { + if ( !type.isMapType() ) { + return false; + } + + List typeParameters = type.getTypeParameters(); + return typeParameters.size() == 2 && typeParameters.get( 0 ).isString(); + } + /** * When there are more than one source parameters, the first segment name of the propery * needs to match the parameter name to avoid ambiguity diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java new file mode 100644 index 0000000000..d4c011a051 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class SourceReferenceContainsKeyPresenceCheck extends ModelElement implements PresenceCheck { + + private final String sourceReference; + private final String propertyName; + + public SourceReferenceContainsKeyPresenceCheck(String sourceReference, String propertyName) { + this.sourceReference = sourceReference; + this.propertyName = propertyName; + } + + public String getSourceReference() { + return sourceReference; + } + + public String getPropertyName() { + return propertyName; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SourceReferenceContainsKeyPresenceCheck that = (SourceReferenceContainsKeyPresenceCheck) o; + return Objects.equals( sourceReference, that.sourceReference ) && + Objects.equals( propertyName, that.propertyName ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceReference, propertyName ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4bacef6a07..f2226ab224 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -181,7 +181,11 @@ public enum Message { VALUEMAPPING_ANY_REMAINING_OR_UNMAPPED_MISSING( "Source = \"\" or \"\" is advisable for mapping of type String to an enum type.", Diagnostic.Kind.WARNING ), VALUEMAPPING_NON_EXISTING_CONSTANT_FROM_SPI( "Constant %s doesn't exist in enum type %s. Constant was returned from EnumMappingStrategy: %s"), VALUEMAPPING_NON_EXISTING_CONSTANT( "Constant %s doesn't exist in enum type %s." ), - VALUEMAPPING_THROW_EXCEPTION_SOURCE( "Source = \"\" is not allowed. Target = \"\" can only be used." ); + VALUEMAPPING_THROW_EXCEPTION_SOURCE( "Source = \"\" is not allowed. Target = \"\" can only be used." ), + + MAPTOBEANMAPPING_WRONG_KEY_TYPE( "The Map parameter \"%s\" cannot be used for property mapping. It must be typed with Map but it was typed with %s.", Diagnostic.Kind.WARNING ), + MAPTOBEANMAPPING_RAW_MAP( "The Map parameter \"%s\" cannot be used for property mapping. It must be typed with Map but it was raw.", Diagnostic.Kind.WARNING ), + ; // CHECKSTYLE:ON diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java index bbd73943db..16abd074dd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.util; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; /** * This a wrapper class which provides the value that needs to be used in the models. @@ -45,6 +46,10 @@ public static ValueProvider of(Accessor accessor) { return null; } String value = accessor.getSimpleName(); + if (accessor.getAccessorType() == AccessorType.MAP_GET ) { + value = "get( \"" + value + "\" )"; + return new ValueProvider( value ); + } if ( !accessor.getAccessorType().isFieldAssignment() ) { value += "()"; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java index 23448a9e98..4e3b7a4776 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java @@ -12,6 +12,8 @@ public enum AccessorType { GETTER, SETTER, ADDER, + MAP_GET, + MAP_CONTAINS, PRESENCE_CHECKER; public boolean isFieldAssignment() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java new file mode 100644 index 0000000000..ab086d9b0e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import java.util.Collections; +import java.util.Set; +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; +import javax.lang.model.type.TypeMirror; + +/** + * An {@link Accessor} that wraps a Map value. + * + * @author Christian Kosmowski + */ +public class MapValueAccessor implements Accessor { + + private final TypeMirror valueTypeMirror; + private final String simpleName; + private final Element element; + + public MapValueAccessor(Element element, TypeMirror valueTypeMirror, String simpleName) { + this.element = element; + this.valueTypeMirror = valueTypeMirror; + this.simpleName = simpleName; + } + + @Override + public TypeMirror getAccessedType() { + return valueTypeMirror; + } + + @Override + public String getSimpleName() { + return this.simpleName; + } + + @Override + public Set getModifiers() { + return Collections.emptySet(); + } + + @Override + public Element getElement() { + return this.element; + } + + @Override + public AccessorType getAccessorType() { + return AccessorType.MAP_GET; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java new file mode 100644 index 0000000000..3f72ed86c1 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import java.util.Collections; +import java.util.Set; +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; +import javax.lang.model.type.TypeMirror; + +/** + * An {@link Accessor} that wraps a Map value. + * + * @author Christian Kosmowski + */ +public class MapValuePresenceChecker implements Accessor { + + private final Element element; + private final TypeMirror valueTypeMirror; + private final String simpleName; + + public MapValuePresenceChecker(Element element, TypeMirror valueTypeMirror, String simpleName) { + this.element = element; + this.valueTypeMirror = valueTypeMirror; + this.simpleName = simpleName; + } + + @Override + public TypeMirror getAccessedType() { + return valueTypeMirror; + } + + @Override + public String getSimpleName() { + return this.simpleName; + } + + @Override + public Set getModifiers() { + return Collections.emptySet(); + } + + @Override + public Element getElement() { + return this.element; + } + + @Override + public AccessorType getAccessorType() { + return AccessorType.MAP_CONTAINS; + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl new file mode 100644 index 0000000000..5cffc481a1 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck" --> +${sourceReference}.containsKey( "${propertyName}" ) \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java new file mode 100644 index 0000000000..548aecc1ec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java @@ -0,0 +1,371 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.text.ParseException; +import java.time.LocalDate; +import java.time.Month; +import java.time.format.DateTimeParseException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Nested; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.entry; + +/** + * @author Christian Kosmowski + */ +@IssueKey("1075") +class FromMapMappingTest { + + @Nested + @WithClasses({ + StringMapToBeanMapper.class + }) + class StringMapToBeanTests { + + @ProcessorTest + void fromNullMap() { + assertThat( StringMapToBeanMapper.INSTANCE.fromMap( null ) ).isNull(); + } + + @ProcessorTest + void fromEmptyMap() { + StringMapToBeanMapper.Order order = StringMapToBeanMapper.INSTANCE.fromMap( Collections.emptyMap() ); + + assertThat( order ).isNotNull(); + assertThat( order.getName() ).isNull(); + assertThat( order.getPrice() ).isEqualTo( 0.0 ); + assertThat( order.getOrderDate() ).isNull(); + assertThat( order.getShipmentDate() ).isNull(); + } + + @ProcessorTest + void fromFullMap() { + Map map = new HashMap<>(); + map.put( "name", "Jacket" ); + map.put( "price", "25.5" ); + map.put( "shipmentDate", "2021-06-15" ); + StringMapToBeanMapper.Order order = StringMapToBeanMapper.INSTANCE.fromMap( map ); + + assertThat( order ).isNotNull(); + assertThat( order.getName() ).isEqualTo( "Jacket" ); + assertThat( order.getPrice() ).isEqualTo( 25.5 ); + assertThat( order.getOrderDate() ).isNull(); + assertThat( order.getShipmentDate() ).isEqualTo( LocalDate.of( 2021, Month.JUNE, 15 ) ); + } + + @ProcessorTest + void fromMapWithEmptyValuesForString() { + Map map = Collections.singletonMap( "name", "" ); + StringMapToBeanMapper.Order order = StringMapToBeanMapper.INSTANCE.fromMap( map ); + + assertThat( order ).isNotNull(); + assertThat( order.getName() ).isEqualTo( "" ); + assertThat( order.getPrice() ).isEqualTo( 0 ); + assertThat( order.getOrderDate() ).isNull(); + assertThat( order.getShipmentDate() ).isNull(); + } + + @ProcessorTest + void fromMapWithEmptyValuesForDouble() { + Map map = Collections.singletonMap( "price", "" ); + assertThatThrownBy( () -> StringMapToBeanMapper.INSTANCE.fromMap( map ) ) + .isInstanceOf( NumberFormatException.class ); + } + + @ProcessorTest + void fromMapWithEmptyValuesForDate() { + Map map = Collections.singletonMap( "orderDate", "" ); + assertThatThrownBy( () -> StringMapToBeanMapper.INSTANCE.fromMap( map ) ) + .isInstanceOf( RuntimeException.class ) + .getCause() + .isInstanceOf( ParseException.class ); + } + + @ProcessorTest + void fromMapWithEmptyValuesForLocalDate() { + Map map = Collections.singletonMap( "shipmentDate", "" ); + assertThatThrownBy( () -> StringMapToBeanMapper.INSTANCE.fromMap( map ) ) + .isInstanceOf( DateTimeParseException.class ); + } + } + + @Nested + @WithClasses({ + StringMapToBeanWithCustomPresenceCheckMapper.class + }) + class StringMapToBeanWithCustomPresenceCheckTests { + + @ProcessorTest + void fromFullMap() { + Map map = new HashMap<>(); + map.put( "name", "Jacket" ); + map.put( "price", "25.5" ); + map.put( "shipmentDate", "2021-06-15" ); + StringMapToBeanWithCustomPresenceCheckMapper.Order order = + StringMapToBeanWithCustomPresenceCheckMapper.INSTANCE.fromMap( map ); + + assertThat( order ).isNotNull(); + assertThat( order.getName() ).isEqualTo( "Jacket" ); + assertThat( order.getPrice() ).isEqualTo( 25.5 ); + assertThat( order.getOrderDate() ).isNull(); + assertThat( order.getShipmentDate() ).isEqualTo( LocalDate.of( 2021, Month.JUNE, 15 ) ); + } + + @ProcessorTest + void fromMapWithEmptyValuesForString() { + Map map = new HashMap<>(); + map.put( "name", "" ); + map.put( "price", "" ); + map.put( "orderDate", "" ); + map.put( "shipmentDate", "" ); + StringMapToBeanWithCustomPresenceCheckMapper.Order order = + StringMapToBeanWithCustomPresenceCheckMapper.INSTANCE.fromMap( map ); + + assertThat( order ).isNotNull(); + assertThat( order.getName() ).isNull(); + assertThat( order.getPrice() ).isEqualTo( 0 ); + assertThat( order.getOrderDate() ).isNull(); + assertThat( order.getShipmentDate() ).isNull(); + } + + } + + @ProcessorTest + @WithClasses(MapToBeanDefinedMapper.class) + void shouldMapWithDefinedMapping() { + Map sourceMap = new HashMap<>(); + sourceMap.put( "number", 44 ); + + MapToBeanDefinedMapper.Target target = MapToBeanDefinedMapper.INSTANCE.toTarget( sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getNormalInt() ).isEqualTo( "44" ); + } + + @ProcessorTest + @WithClasses(MapToBeanImplicitMapper.class) + void shouldMapWithImpicitMapping() { + Map sourceMap = new HashMap<>(); + sourceMap.put( "name", "mapstruct" ); + + MapToBeanImplicitMapper.Target target = MapToBeanImplicitMapper.INSTANCE.toTarget( sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "mapstruct" ); + } + + @ProcessorTest + @WithClasses(MapToBeanUpdateImplicitMapper.class) + void shouldMapToExistingTargetWithImplicitMapping() { + Map sourceMap = new HashMap<>(); + sourceMap.put( "rating", 5 ); + + MapToBeanUpdateImplicitMapper.Target existingTarget = new MapToBeanUpdateImplicitMapper.Target(); + existingTarget.setRating( 4 ); + existingTarget.setName( "mapstruct" ); + + MapToBeanUpdateImplicitMapper.Target target = MapToBeanUpdateImplicitMapper.INSTANCE + .toTarget( existingTarget, sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "mapstruct" ); + assertThat( target.getRating() ).isEqualTo( 5 ); + } + + @ProcessorTest + @WithClasses(MapToBeanWithDefaultMapper.class) + void shouldMapWithDefaultValue() { + Map sourceMap = new HashMap<>(); + + MapToBeanWithDefaultMapper.Target target = MapToBeanWithDefaultMapper.INSTANCE + .toTarget( sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getNormalInt() ).isEqualTo( "4711" ); + } + + @ProcessorTest + @WithClasses(MapToBeanUsingMappingMethodMapper.class) + void shouldMapUsingMappingMethod() { + Map sourceMap = new HashMap<>(); + sourceMap.put( "number", 23 ); + + MapToBeanUsingMappingMethodMapper.Target target = MapToBeanUsingMappingMethodMapper.INSTANCE + .toTarget( sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getNormalInt() ).isEqualTo( "converted_23" ); + } + + @ProcessorTest + @WithClasses(MapToBeanFromMultipleSources.class) + void shouldMapFromMultipleSources() { + Map integers = new HashMap<>(); + integers.put( "number", 23 ); + + Map strings = new HashMap<>(); + strings.put( "string", "stringFromMap" ); + + MapToBeanFromMultipleSources.Source source = new MapToBeanFromMultipleSources.Source(); + + MapToBeanFromMultipleSources.Target target = MapToBeanFromMultipleSources.INSTANCE + .toTarget( integers, strings, source ); + + assertThat( target ).isNotNull(); + assertThat( target.getInteger() ).isEqualTo( 23 ); + assertThat( target.getString() ).isEqualTo( "stringFromMap" ); + assertThat( target.getStringFromBean() ).isEqualTo( "stringFromBean" ); + } + + @ProcessorTest + @WithClasses(MapToBeanFromMapAndNestedSource.class) + void shouldMapFromNestedSource() { + Map integers = new HashMap<>(); + integers.put( "number", 23 ); + + MapToBeanFromMapAndNestedSource.Source source = new MapToBeanFromMapAndNestedSource.Source(); + + MapToBeanFromMapAndNestedSource.Target target = MapToBeanFromMapAndNestedSource.INSTANCE + .toTarget( integers, source ); + + assertThat( target ).isNotNull(); + assertThat( target.getInteger() ).isEqualTo( 23 ); + assertThat( target.getStringFromNestedSource() ).isEqualTo( "nestedString" ); + } + + @ProcessorTest + @WithClasses(MapToBeanFromMapAndNestedMap.class) + void shouldMapFromNestedMap() { + + MapToBeanFromMapAndNestedMap.Source source = new MapToBeanFromMapAndNestedMap.Source(); + MapToBeanFromMapAndNestedMap.Target target = MapToBeanFromMapAndNestedMap.INSTANCE + .toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getNestedTarget() ).isNotNull(); + assertThat( target.getNestedTarget().getStringFromNestedMap() ).isEqualTo( "valueFromNestedMap" ); + } + + @ProcessorTest + @WithClasses(ObjectMapToBeanWithQualifierMapper.class) + void shouldUseObjectQualifiedMethod() { + Map vehicles = new HashMap<>(); + vehicles.put( "car", new ObjectMapToBeanWithQualifierMapper.Car( "Tesla" ) ); + + ObjectMapToBeanWithQualifierMapper.VehiclesDto dto = + ObjectMapToBeanWithQualifierMapper.INSTANCE.map( vehicles ); + + assertThat( dto.getCar() ).isNotNull(); + assertThat( dto.getCar() ).isInstanceOf( ObjectMapToBeanWithQualifierMapper.CarDto.class ); + assertThat( dto.getCar().getBrand() ).isEqualTo( "Tesla" ); + } + + @ProcessorTest + @WithClasses(MapToBeanTypeCheckMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + type = MapToBeanTypeCheckMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + message = "Unmapped target property: \"value\"." + ), + @Diagnostic( + type = MapToBeanTypeCheckMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + message = "The Map parameter \"source\" cannot be used for property mapping. " + + "It must be typed with Map but it was typed with Map." + ), + } + ) + void shouldWarnAboutWrongMapTypes() { + + Map upsideDownMap = new HashMap<>(); + upsideDownMap.put( 23, "number" ); + + MapToBeanTypeCheckMapper.Target target = MapToBeanTypeCheckMapper.INSTANCE + .toTarget( upsideDownMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + } + + @ProcessorTest + @WithClasses(MapToBeanRawMapMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + type = MapToBeanRawMapMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + message = "Unmapped target property: \"value\"." + ), + @Diagnostic( + type = MapToBeanRawMapMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + message = "The Map parameter \"source\" cannot be used for property mapping. " + + "It must be typed with Map but it was raw." + ), + } + ) + void shouldWarnAboutRawMapTypes() { + + Map rawMap = new HashMap<>(); + rawMap.put( "value", "number" ); + + MapToBeanRawMapMapper.Target target = MapToBeanRawMapMapper.INSTANCE + .toTarget( rawMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + } + + @ProcessorTest + @WithClasses({ + MapToBeanNonStringMapAsMultiSourceMapper.class + }) + void shouldNotWarnIfMappedIsUsedAsSourceParameter() { + MapToBeanNonStringMapAsMultiSourceMapper.Target target = MapToBeanNonStringMapAsMultiSourceMapper.INSTANCE + .toTarget( + new MapToBeanNonStringMapAsMultiSourceMapper.Source( "test" ), + Collections.singletonMap( 10, "value" ) + ); + + assertThat( target.getValue() ).isEqualTo( "test" ); + assertThat( target.getMap() ) + .containsOnly( entry( "10", "value" ) ); + } + + @ProcessorTest + @WithClasses(MapToBeanImplicitUnmappedSourcePolicyMapper.class) + void shouldNotReportUnmappedSourcePropertiesWithMap() { + Map sourceMap = new HashMap<>(); + sourceMap.put( "name", "mapstruct" ); + + MapToBeanImplicitUnmappedSourcePolicyMapper.Target target = + MapToBeanImplicitUnmappedSourcePolicyMapper.INSTANCE.toTarget( sourceMap ); + + assertThat( target ).isNotNull(); + assertThat( target.getName() ).isEqualTo( "mapstruct" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanDefinedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanDefinedMapper.java new file mode 100644 index 0000000000..eef8c285b3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanDefinedMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanDefinedMapper { + + MapToBeanDefinedMapper INSTANCE = Mappers.getMapper( MapToBeanDefinedMapper.class ); + + @Mapping(target = "normalInt", source = "number") + Target toTarget(Map source); + + class Target { + + private String normalInt; + + public String getNormalInt() { + return normalInt; + } + + public void setNormalInt(String normalInt) { + this.normalInt = normalInt; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMap.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMap.java new file mode 100644 index 0000000000..f1b21263a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMap.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanFromMapAndNestedMap { + + MapToBeanFromMapAndNestedMap INSTANCE = Mappers.getMapper( MapToBeanFromMapAndNestedMap.class ); + + Target toTarget(Source source); + + class Source { + + private Map nestedTarget = new HashMap<>( ); + + public Map getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(Map nestedTarget) { + this.nestedTarget = nestedTarget; + } + + public Source() { + nestedTarget.put( "stringFromNestedMap", "valueFromNestedMap" ); + } + } + + class Target { + + private NestedTarget nestedTarget; + + public NestedTarget getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(NestedTarget nestedTarget) { + this.nestedTarget = nestedTarget; + } + + } + + class NestedTarget { + private String stringFromNestedMap; + + public String getStringFromNestedMap() { + return stringFromNestedMap; + } + + public void setStringFromNestedMap(String stringFromNestedMap) { + this.stringFromNestedMap = stringFromNestedMap; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedSource.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedSource.java new file mode 100644 index 0000000000..c66080332e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedSource.java @@ -0,0 +1,79 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanFromMapAndNestedSource { + + MapToBeanFromMapAndNestedSource INSTANCE = Mappers.getMapper( MapToBeanFromMapAndNestedSource.class ); + + @Mapping(target = "integer", source = "integers.number") + @Mapping(target = "stringFromNestedSource", source = "source.nestedSource.nestedString") + Target toTarget(Map integers, Source source); + + class Source { + + private String stringFromBean = "stringFromBean"; + private NestedSource nestedSource = new NestedSource(); + + public String getStringFromBean() { + return stringFromBean; + } + + public void setStringFromBean(String stringFromBean) { + this.stringFromBean = stringFromBean; + } + + public NestedSource getNestedSource() { + return nestedSource; + } + + public void setNestedSource(NestedSource nestedSource) { + this.nestedSource = nestedSource; + } + + class NestedSource { + + private String nestedString = "nestedString"; + + public String getNestedString() { + return nestedString; + } + } + } + + class Target { + + private int integer; + private String stringFromNestedSource; + + public int getInteger() { + return integer; + } + + public void setInteger(int integer) { + this.integer = integer; + } + + public String getStringFromNestedSource() { + return stringFromNestedSource; + } + + public void setStringFromNestedSource(String stringFromNestedSource) { + this.stringFromNestedSource = stringFromNestedSource; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMultipleSources.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMultipleSources.java new file mode 100644 index 0000000000..c5c9b2e665 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMultipleSources.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanFromMultipleSources { + + MapToBeanFromMultipleSources INSTANCE = Mappers.getMapper( MapToBeanFromMultipleSources.class ); + + @Mapping(target = "integer", source = "integers.number") + @Mapping(target = "string", source = "strings.string") + @Mapping(target = "stringFromBean", source = "bean.stringFromBean") + Target toTarget(Map integers, Map strings, Source bean); + + class Source { + private String stringFromBean = "stringFromBean"; + + public String getStringFromBean() { + return stringFromBean; + } + + public void setStringFromBean(String stringFromBean) { + this.stringFromBean = stringFromBean; + } + } + + class Target { + + private int integer; + private String string; + private String stringFromBean; + + public int getInteger() { + return integer; + } + + public void setInteger(int integer) { + this.integer = integer; + } + + public String getString() { + return string; + } + + public void setString(String string) { + this.string = string; + } + + public String getStringFromBean() { + return stringFromBean; + } + + public void setStringFromBean(String stringFromBean) { + this.stringFromBean = stringFromBean; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitMapper.java new file mode 100644 index 0000000000..ca4b7a3d21 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanImplicitMapper { + + MapToBeanImplicitMapper INSTANCE = Mappers.getMapper( MapToBeanImplicitMapper.class ); + + Target toTarget(Map source); + + class Target { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitUnmappedSourcePolicyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitUnmappedSourcePolicyMapper.java new file mode 100644 index 0000000000..2c72dc7b70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanImplicitUnmappedSourcePolicyMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface MapToBeanImplicitUnmappedSourcePolicyMapper { + + MapToBeanImplicitUnmappedSourcePolicyMapper INSTANCE = + Mappers.getMapper( MapToBeanImplicitUnmappedSourcePolicyMapper.class ); + + Target toTarget(Map source); + + class Target { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanNonStringMapAsMultiSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanNonStringMapAsMultiSourceMapper.java new file mode 100644 index 0000000000..2606a9a037 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanNonStringMapAsMultiSourceMapper.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanNonStringMapAsMultiSourceMapper { + + MapToBeanNonStringMapAsMultiSourceMapper INSTANCE = + Mappers.getMapper( MapToBeanNonStringMapAsMultiSourceMapper.class ); + + Target toTarget(Source source, Map map); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + + private final String value; + private final Map map; + + public Target(String value, Map map) { + this.value = value; + this.map = map; + } + + public String getValue() { + return value; + } + + public Map getMap() { + return map; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanRawMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanRawMapMapper.java new file mode 100644 index 0000000000..40215ab183 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanRawMapMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanRawMapMapper { + + MapToBeanRawMapMapper INSTANCE = Mappers.getMapper( MapToBeanRawMapMapper.class ); + + Target toTarget(Map source); + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanTypeCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanTypeCheckMapper.java new file mode 100644 index 0000000000..346c153d71 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanTypeCheckMapper.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanTypeCheckMapper { + + MapToBeanTypeCheckMapper INSTANCE = Mappers.getMapper( MapToBeanTypeCheckMapper.class ); + + Target toTarget(Map source); + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUpdateImplicitMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUpdateImplicitMapper.java new file mode 100644 index 0000000000..82fe906bfe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUpdateImplicitMapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface MapToBeanUpdateImplicitMapper { + + MapToBeanUpdateImplicitMapper INSTANCE = Mappers.getMapper( MapToBeanUpdateImplicitMapper.class ); + + Target toTarget(@MappingTarget Target target, Map source); + + class Target { + + private String name; + private Integer rating; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getRating() { + return rating; + } + + public void setRating(Integer rating) { + this.rating = rating; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java new file mode 100644 index 0000000000..9a6344ff15 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanUsingMappingMethodMapper { + + MapToBeanUsingMappingMethodMapper INSTANCE = Mappers.getMapper( MapToBeanUsingMappingMethodMapper.class ); + + @Mapping(target = "normalInt", source = "number") + Target toTarget(Map source); + + default String mapIntegerToString( Integer input ) { + return "converted_" + input; + } + + class Target { + + private String normalInt; + + public String getNormalInt() { + return normalInt; + } + + public void setNormalInt(String normalInt) { + this.normalInt = normalInt; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanWithDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanWithDefaultMapper.java new file mode 100644 index 0000000000..104d34bd0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanWithDefaultMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Christian Kosmowski + */ +@Mapper +public interface MapToBeanWithDefaultMapper { + + MapToBeanWithDefaultMapper INSTANCE = Mappers.getMapper( MapToBeanWithDefaultMapper.class ); + + @Mapping(target = "normalInt", source = "number", defaultValue = "4711") + Target toTarget(Map source); + + class Target { + + private String normalInt; + + public String getNormalInt() { + return normalInt; + } + + public void setNormalInt(String normalInt) { + this.normalInt = normalInt; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/ObjectMapToBeanWithQualifierMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/ObjectMapToBeanWithQualifierMapper.java new file mode 100644 index 0000000000..54ddb0e42a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/ObjectMapToBeanWithQualifierMapper.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ObjectMapToBeanWithQualifierMapper { + + ObjectMapToBeanWithQualifierMapper INSTANCE = Mappers.getMapper( ObjectMapToBeanWithQualifierMapper.class ); + + @Mapping( target = "car", qualifiedByName = "objectToCar") + VehiclesDto map(Map vehicles); + + @Named("objectToCar") + default CarDto objectToCar(Object object) { + CarDto car = new CarDto(); + + if ( object instanceof Car ) { + car.setBrand( ( (Car) object ).brand ); + } + + return car; + } + + class VehiclesDto { + + private VehicleDto car; + + public VehicleDto getCar() { + return car; + } + + public void setCar(VehicleDto car) { + this.car = car; + } + } + + class VehicleDto { + private String brand; + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + } + + class CarDto extends VehicleDto { + + } + + class Car { + + private final String brand; + + public Car(String brand) { + this.brand = brand; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanMapper.java new file mode 100644 index 0000000000..95b0f72597 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanMapper.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.frommap; + +import java.time.LocalDate; +import java.util.Date; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface StringMapToBeanMapper { + StringMapToBeanMapper INSTANCE = Mappers.getMapper( StringMapToBeanMapper.class ); + + Order fromMap(Map map); + + class Order { + private String name; + private double price; + private Date orderDate; + private LocalDate shipmentDate; + + public Order() { + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return this.price; + } + + public void setPrice(double price) { + this.price = price; + } + + public Date getOrderDate() { + return this.orderDate; + } + + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + public LocalDate getShipmentDate() { + return this.shipmentDate; + } + + public void setShipmentDate(LocalDate shipmentDate) { + this.shipmentDate = shipmentDate; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanWithCustomPresenceCheckMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanWithCustomPresenceCheckMapper.java new file mode 100644 index 0000000000..62c105599f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/StringMapToBeanWithCustomPresenceCheckMapper.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.frommap; + +import java.time.LocalDate; +import java.util.Date; +import java.util.Map; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface StringMapToBeanWithCustomPresenceCheckMapper { + StringMapToBeanWithCustomPresenceCheckMapper INSTANCE = + Mappers.getMapper( StringMapToBeanWithCustomPresenceCheckMapper.class ); + + Order fromMap(Map map); + + @Condition + default boolean isNotEmpty(String value) { + return value != null && !value.isEmpty(); + } + + class Order { + private String name; + private double price; + private Date orderDate; + private LocalDate shipmentDate; + + public Order() { + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return this.price; + } + + public void setPrice(double price) { + this.price = price; + } + + public Date getOrderDate() { + return this.orderDate; + } + + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + public LocalDate getShipmentDate() { + return this.shipmentDate; + } + + public void setShipmentDate(LocalDate shipmentDate) { + this.shipmentDate = shipmentDate; + } + } + +} From 38744d9f73d5ff921acd10431e364b31d7b075da Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 27 Jun 2021 18:43:13 +0200 Subject: [PATCH 0591/1006] Add users that have contributed to 1.5 to the copyright.txt --- copyright.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/copyright.txt b/copyright.txt index 2980f611b4..01b6526c70 100644 --- a/copyright.txt +++ b/copyright.txt @@ -18,17 +18,26 @@ Darren Rambaud - https://github.com/xyzst Dekel Pilli - https://github.com/dekelpilli Dilip Krishnan - https://github.com/dilipkrish Dmytro Polovinkin - https://github.com/navpil +Ewald Volkert - https://github.com/eforest Eric Martineau - https://github.com/ericmartineau Ewald Volkert - https://github.com/eforest Filip Hrisafov - https://github.com/filiphr Florian Tavares - https://github.com/neoXfire Gervais Blaise - https://github.com/gervaisb +Gibou Damien - https://github.com/dmngb Gunnar Morling - https://github.com/gunnarmorling Ivo Smid - https://github.com/bedla +Jason Bodnar - https://github.com/Blackbaud-JasonBodnar +Jeroen van Wilgenburg - https://github.com/jvwilge Jeff Smyth - https://github.com/smythie86 +João Paulo Bassinello - https://github.com/jpbassinello Jonathan Kraska - https://github.com/jakraska Joshua Spoerri - https://github.com/spoerri +Jude Niroshan - https://github.com/JudeNiroshan +Kemal Özcan - https://github.com/yekeoe Kevin Grüneberg - https://github.com/kevcodez +Lukas Lazar - https://github.com/LukeLaz +Nikolas Charalambidis - https://github.com/Nikolas-Charalambidis Michael Pardo - https://github.com/pardom Mustafa Caylak - https://github.com/luxmeter Oliver Ehrenmüller - https://github.com/greuelpirat @@ -48,6 +57,8 @@ Sjaak Derksen - https://github.com/sjaakd Stefan May - https://github.com/osthus-sm Taras Mychaskiw - https://github.com/twentylemon Thibault Duperron - https://github.com/Zomzog +Tomáš Poledný - https://github.com/Saljack +Tobias Meggendorfer - https://github.com/incaseoftrouble Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld From a95d1c59c3f531fc90b62c60092dd9c16bc93b66 Mon Sep 17 00:00:00 2001 From: Sjaak Derksen Date: Sat, 3 Jul 2021 15:28:10 +0200 Subject: [PATCH 0592/1006] #2505 deepclone generates enum mapping method (#2507) --- .../creation/MappingResolverImpl.java | 4 ++ .../ap/test/bugs/_2505/Issue2505Mapper.java | 51 +++++++++++++++++++ .../ap/test/bugs/_2505/Issue2505Test.java | 36 +++++++++++++ .../test/bugs/_2505/Issue2505MapperImpl.java | 29 +++++++++++ 4 files changed, 120 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2505/Issue2505MapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index d9bd4d731b..b971341fc9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -383,6 +383,10 @@ private boolean allowDirect(Type type) { return true; } + if ( type.isEnumType() ) { + return true; + } + if ( type.isArrayType() ) { return type.isJavaLangType() || type.getComponentType().isPrimitive(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Mapper.java new file mode 100644 index 0000000000..525eb09fd3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Mapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2505; + +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +/** + * @author Sjaak Derksen + */ +@Mapper( mappingControl = DeepClone.class ) +public interface Issue2505Mapper { + + Issue2505Mapper INSTANCE = Mappers.getMapper( Issue2505Mapper.class ); + + Customer map(CustomerDTO value); + + enum Status { + ENABLED, DISABLED, + } + + class Customer { + + private Status status; + + public Status getStatus() { + return status; + } + + public void setStatus(Status stat) { + this.status = stat; + } + } + + class CustomerDTO { + + private Status status; + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Test.java new file mode 100644 index 0000000000..b3fa6ea3c1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2505/Issue2505Test.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2505; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Sjaak derksen + */ +@IssueKey("2505") +@WithClasses( Issue2505Mapper.class ) +class Issue2505Test { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( Issue2505Mapper.class ); + + @ProcessorTest + void shouldNotGenerateEnumMappingMethodForDeepClone() { + Issue2505Mapper.CustomerDTO source = new Issue2505Mapper.CustomerDTO(); + source.setStatus( Issue2505Mapper.Status.DISABLED ); + + Issue2505Mapper.Customer target = Issue2505Mapper.INSTANCE.map( source ); + + assertThat( target.getStatus() ).isEqualTo( Issue2505Mapper.Status.DISABLED ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2505/Issue2505MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2505/Issue2505MapperImpl.java new file mode 100644 index 0000000000..87977b093b --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2505/Issue2505MapperImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2505; + +import javax.annotation.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-07-03T14:21:53+0200", + comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 1.8.0_181 (Oracle Corporation)" +) +public class Issue2505MapperImpl implements Issue2505Mapper { + + @Override + public Customer map(CustomerDTO value) { + if ( value == null ) { + return null; + } + + Customer customer = new Customer(); + + customer.setStatus( value.getStatus() ); + + return customer; + } +} From a91b93f357a2ab8d481ff3a3484440a507f06166 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Jul 2021 15:15:44 +0200 Subject: [PATCH 0593/1006] [maven-release-plugin] prepare release 1.5.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index aaae7b5404..bcf279c6c4 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 293043e6f9..3363f4c590 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 10c95cf3b5..9472ca45a1 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 337ad35e51..f8fe133b9f 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8850da641c..8d24c027ed 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4b48c19496..f9ad6782d4 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index bb1229fcb8..b249ad635d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Beta1 diff --git a/pom.xml b/pom.xml index 28c35aea74..03c1c0fcd9 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Beta1 diff --git a/processor/pom.xml b/processor/pom.xml index fcc6dbbab8..b79b61e2bc 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta1 ../parent/pom.xml From 43dfd92e05193111992807076ff0fe7b47da1075 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Jul 2021 15:15:44 +0200 Subject: [PATCH 0594/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index bcf279c6c4..aaae7b5404 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 3363f4c590..293043e6f9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 9472ca45a1..10c95cf3b5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f8fe133b9f..337ad35e51 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8d24c027ed..8850da641c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f9ad6782d4..4b48c19496 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index b249ad635d..bb1229fcb8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Beta1 + HEAD diff --git a/pom.xml b/pom.xml index 03c1c0fcd9..28c35aea74 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Beta1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index b79b61e2bc..fcc6dbbab8 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta1 + 1.5.0-SNAPSHOT ../parent/pom.xml From 8c554b95564f412466592f438661b64d36bed42e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Jul 2021 15:55:17 +0200 Subject: [PATCH 0595/1006] Change reference from Google Group to GitHub Discussions in reference guide --- .../src/main/asciidoc/mapstruct-reference-guide.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc index 7bffbca5c7..1705ed4af1 100644 --- a/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc +++ b/documentation/src/main/asciidoc/mapstruct-reference-guide.asciidoc @@ -12,7 +12,7 @@ [[Preface]] == Preface This is the reference documentation of MapStruct, an annotation processor for generating type-safe, performant and dependency-free bean mapping code. -This guide covers all the functionality provided by MapStruct. In case this guide doesn't answer all your questions just join the MapStruct https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users[Google group] to get help. +This guide covers all the functionality provided by MapStruct. In case this guide doesn't answer all your questions just join the MapStruct https://github.com/mapstruct/mapstruct/discussions[GitHub Discussions] to get help. You found a typo or other error in this guide? Please let us know by opening an issue in the https://github.com/mapstruct/mapstruct[MapStruct GitHub repository], or, better yet, help the community and send a pull request for fixing it! From e6e9b6ce923a07f75a598fdaf4a87dfc85ea3be8 Mon Sep 17 00:00:00 2001 From: Amogh Date: Thu, 22 Jul 2021 04:08:54 -0400 Subject: [PATCH 0596/1006] #2525 add available transformations to CaseEnumTransformationStrategy exception --- .../org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java | 4 +++- .../EnumNameTransformationStrategyTest.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java index 2f99f56ce4..3a4ba18ade 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/CaseEnumTransformationStrategy.java @@ -20,6 +20,7 @@ public class CaseEnumTransformationStrategy implements EnumTransformationStrateg private static final String UPPER = "upper"; private static final String LOWER = "lower"; private static final String CAPITAL = "capital"; + private static final String CASE_ENUM_TRANSFORMATION_STRATEGIES = UPPER + ", " + LOWER + ", " + CAPITAL; @Override public String getStrategyName() { @@ -37,7 +38,8 @@ public String transform(String value, String configuration) { return capitalize( value ); default: throw new IllegalArgumentException( - "Unexpected configuration for enum case transformation: " + configuration ); + "Unexpected configuration for enum case transformation: " + configuration + + ". Allowed values: " + CASE_ENUM_TRANSFORMATION_STRATEGIES); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java index 7a29ae40a8..012fc9961a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/value/nametransformation/EnumNameTransformationStrategyTest.java @@ -112,7 +112,8 @@ public void shouldGiveCompileErrorWhenUsingUnknownNameTransformStrategy() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 18, message = "Illegal transformation for 'case' EnumTransformationStrategy." + - " Error: 'Unexpected configuration for enum case transformation: unknown'." + " Error: 'Unexpected configuration for enum case transformation: unknown." + + " Allowed values: upper, lower, capital'." ) } ) From 196528e5783ab39401982fae449ec91de98b06ab Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Wed, 11 Aug 2021 06:49:05 +0200 Subject: [PATCH 0597/1006] #2530: fix missing supporting fields for ReverseConversion --- .../conversion/ReverseConversion.java | 5 +++ .../ap/test/bugs/_2530/Issue2530Mapper.java | 37 +++++++++++++++++++ .../ap/test/bugs/_2530/Issue2530Test.java | 34 +++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java index 7fd7f6bbb8..0e2cd3d832 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java @@ -9,6 +9,7 @@ import java.util.List; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.FieldReference; import org.mapstruct.ap.internal.model.HelperMethod; /** @@ -44,4 +45,8 @@ public List getRequiredHelperMethods(ConversionContext conversionC return Collections.emptyList(); } + @Override + public List getRequiredHelperFields(ConversionContext conversionContext) { + return conversionProvider.getRequiredHelperFields( conversionContext ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Mapper.java new file mode 100644 index 0000000000..268237376c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Mapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2530; + +import java.time.LocalDate; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Issue2530Mapper { + + Issue2530Mapper INSTANCE = Mappers.getMapper( Issue2530Mapper.class ); + + @Mapping(target = "date", source = ".", dateFormat = "yyyy-MM-dd") + Test map(String s); + + class Test { + + LocalDate date; + + public LocalDate getDate() { + return date; + } + + public void setDate(LocalDate dateTime) { + this.date = dateTime; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Test.java new file mode 100644 index 0000000000..a1ea466d0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2530/Issue2530Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2530; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Month; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@IssueKey("2530") +@WithClasses({ + Issue2530Mapper.class +}) +public class Issue2530Test { + + @ProcessorTest + public void shouldConvert() { + Issue2530Mapper.Test target = Issue2530Mapper.INSTANCE.map( "2021-07-31" ); + + assertThat( target ).isNotNull(); + assertThat( target.getDate().getYear() ).isEqualTo( 2021 ); + assertThat( target.getDate().getMonth() ).isEqualTo( Month.JULY ); + assertThat( target.getDate().getDayOfMonth() ).isEqualTo( 31 ); + } +} From 8ad55b164fbba3417150daf45cb2d67bf26b13b9 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Wed, 11 Aug 2021 11:35:45 +0200 Subject: [PATCH 0598/1006] #2544: fix missing helper methods for ReverseConversion --- .../conversion/ReverseConversion.java | 6 +-- .../ap/test/bugs/_2544/Issue2544Mapper.java | 37 +++++++++++++++++++ .../ap/test/bugs/_2544/Issue2544Test.java | 30 +++++++++++++++ 3 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java index 0e2cd3d832..cb496b0c54 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ReverseConversion.java @@ -5,12 +5,12 @@ */ package org.mapstruct.ap.internal.conversion; -import java.util.Collections; import java.util.List; + +import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.FieldReference; -import org.mapstruct.ap.internal.model.HelperMethod; /** * * A {@link ConversionProvider} which creates the inversed conversions for a @@ -42,7 +42,7 @@ public Assignment from(ConversionContext conversionContext) { @Override public List getRequiredHelperMethods(ConversionContext conversionContext) { - return Collections.emptyList(); + return conversionProvider.getRequiredHelperMethods( conversionContext ); } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Mapper.java new file mode 100644 index 0000000000..6d02d709a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Mapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2544; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Issue2544Mapper { + + Issue2544Mapper INSTANCE = Mappers.getMapper( Issue2544Mapper.class ); + + @Mapping( target = "bigNumber", source = ".", numberFormat = "##0.#####E0" ) + Target map(String s); + + class Target { + + private BigDecimal bigNumber; + + public BigDecimal getBigNumber() { + return bigNumber; + } + + public void setBigNumber(BigDecimal bigNumber) { + this.bigNumber = bigNumber; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java new file mode 100644 index 0000000000..5cc252bbf8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2544; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigDecimal; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@IssueKey( "2544" ) +@WithClasses( { Issue2544Mapper.class } ) +public class Issue2544Test { + + @ProcessorTest + public void shouldConvert() { + Issue2544Mapper.Target target = Issue2544Mapper.INSTANCE.map( "123.45679E6" ); + + assertThat( target ).isNotNull(); + assertThat( target.getBigNumber() ).isEqualTo( new BigDecimal( "1.2345679E+8" ) ); + } +} From c1fa9bd0bd1e29b01c2c7f951543788b60a4f356 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 14 Aug 2021 08:37:20 +0200 Subject: [PATCH 0599/1006] #2537 Fix incorrect unmapped source property when only defined in Mapping#target --- .../ap/internal/model/BeanMappingMethod.java | 1 + .../test/bugs/_2537/ImplicitSourceTest.java | 24 ++++++++++ ...dSourcePolicyWithImplicitSourceMapper.java | 45 +++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/ImplicitSourceTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/UnmappedSourcePolicyWithImplicitSourceMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 09cc20a6ed..4ebcd9f5ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1170,6 +1170,7 @@ else if ( mapping.getJavaExpression() != null ) { .build(); handledTargets.add( targetPropertyName ); unprocessedSourceParameters.remove( sourceRef.getParameter() ); + unprocessedSourceProperties.remove( sourceRef.getShallowestPropertyName() ); } else { errorOccured = true; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/ImplicitSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/ImplicitSourceTest.java new file mode 100644 index 0000000000..edcbbfd4d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/ImplicitSourceTest.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2537; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * implicit source-target mapping should list the source property as being mapped. + * + * @author Ben Zegveld + */ +@WithClasses( { UnmappedSourcePolicyWithImplicitSourceMapper.class } ) +@IssueKey( "2537" ) +public class ImplicitSourceTest { + + @ProcessorTest + public void situationCompilesWithoutErrors() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/UnmappedSourcePolicyWithImplicitSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/UnmappedSourcePolicyWithImplicitSourceMapper.java new file mode 100644 index 0000000000..21d8ca5332 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2537/UnmappedSourcePolicyWithImplicitSourceMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2537; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; + +/** + * @author Ben Zegveld + */ +@Mapper( unmappedSourcePolicy = ReportingPolicy.ERROR ) +public interface UnmappedSourcePolicyWithImplicitSourceMapper { + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "property" ) + Target map(Source source); + + class Source { + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } + + class Target { + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + } +} From 0d8729767be07b1c6496c585691089890e1cedf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20P=C3=B6ttker?= Date: Sat, 14 Aug 2021 08:38:36 +0200 Subject: [PATCH 0600/1006] Remove remaining references to Hickory (#2511) --- parent/pom.xml | 2 +- .../src/main/java/org/mapstruct/ap/MappingProcessor.java | 6 +++--- .../java/org/mapstruct/ap/internal/gem/GemGenerator.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index bb1229fcb8..8ce94764ea 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -34,7 +34,7 @@ 1 3.17.2 - + jdt_apt diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index e7e52be695..8369a8b270 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -67,9 +67,9 @@ *

    5. if no error occurred, write out the model into Java source files
    6. * *

      - * For reading annotation attributes, gems as generated with help of the Hickory tool are used. These gems allow a comfortable access to - * annotations and their attributes without depending on their class objects. + * For reading annotation attributes, gems as generated with help of Gem Tools. These gems allow comfortable access to annotations and + * their attributes without depending on their class objects. *

      * The creation of Java source files is done using the FreeMarker template engine. * Each node of the mapper model has a corresponding FreeMarker template file which provides the Java representation of diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index f8bdbc539d..df5a90d5c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -36,7 +36,7 @@ import org.mapstruct.tools.gem.GemDefinition; /** - * Triggers the generation of ge types using Hickory. + * Triggers the generation of gem types using Gem Tools. * * @author Gunnar Morling */ From 06c416043ca361e075e4bb19e09edf539010c499 Mon Sep 17 00:00:00 2001 From: Bas Claessen <35045227+basclaessen@users.noreply.github.com> Date: Sat, 14 Aug 2021 09:06:54 +0200 Subject: [PATCH 0601/1006] #2515 add ambiguous constructors to ambiguous constructor error message --- .../mapstruct/ap/internal/model/BeanMappingMethod.java | 10 +++++++++- .../java/org/mapstruct/ap/internal/util/Message.java | 2 +- .../erroneous/ErroneousConstructorTest.java | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4ebcd9f5ec..36dae0ba51 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -26,6 +26,7 @@ import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; +import javax.lang.model.element.VariableElement; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; @@ -699,7 +700,14 @@ private ConstructorAccessor getConstructorAccessor(Type type) { method.getExecutable(), GENERAL_AMBIGUOUS_CONSTRUCTORS, type, - Strings.join( constructors, ", " ) + constructors.stream() + .map( ExecutableElement::getParameters ) + .map( ps -> ps.stream() + .map( VariableElement::asType ) + .map( String::valueOf ) + .collect( Collectors.joining( ", ", type.getName() + "(", ")" ) ) + ) + .collect( Collectors.joining( ", " ) ) ); return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index f2226ab224..8d328d4796 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -125,7 +125,7 @@ public enum Message { GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD( "Ambiguous presence check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), - GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), + GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s: %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), GENERAL_VALID_DATE( "Given date format \"%s\" is valid.", Diagnostic.Kind.NOTE ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java index 2799e10847..5a8483f23b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/erroneous/ErroneousConstructorTest.java @@ -29,8 +29,10 @@ public class ErroneousConstructorTest { kind = javax.tools.Diagnostic.Kind.ERROR, line = 17, message = "Ambiguous constructors found for creating org.mapstruct.ap.test.constructor.erroneous" + - ".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors. Either declare parameterless " + - "constructor or annotate the default constructor with an annotation named @Default." + ".ErroneousAmbiguousConstructorsMapper.PersonWithMultipleConstructors: " + + "PersonWithMultipleConstructors(java.lang.String), " + + "PersonWithMultipleConstructors(java.lang.String, int). Either declare parameterless constructor " + + "or annotate the default constructor with an annotation named @Default." ) }) public void shouldUseMultipleConstructors() { From eb12c485eee83d60c48b4b00d299b4563aa8fbb6 Mon Sep 17 00:00:00 2001 From: Bas Claessen <35045227+basclaessen@users.noreply.github.com> Date: Sat, 14 Aug 2021 09:07:22 +0200 Subject: [PATCH 0602/1006] #2515 add ambiguous constructors to ambiguous constructor error message From c52ff812aa9a4c5fa9cc758e8d19bb77a1d09e0c Mon Sep 17 00:00:00 2001 From: Adam Szatyin Date: Tue, 17 Aug 2021 19:21:07 +0200 Subject: [PATCH 0603/1006] #2552 Add built in conversion between URL and String --- .../chapter-5-data-type-conversions.asciidoc | 3 + .../internal/conversion/ConversionUtils.java | 12 +++ .../ap/internal/conversion/Conversions.java | 13 ++++ .../conversion/URLToStringConversion.java | 46 +++++++++++ .../ap/test/conversion/url/Source.java | 33 ++++++++ .../ap/test/conversion/url/Target.java | 30 ++++++++ .../conversion/url/URLConversionTest.java | 76 +++++++++++++++++++ .../ap/test/conversion/url/URLMapper.java | 23 ++++++ 8 files changed, 236 insertions(+) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/URLToStringConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/url/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/url/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLMapper.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 24f019fa63..91f4afb1cf 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -122,6 +122,9 @@ public interface CarMapper { * Between `String` and `StringBuilder` +* Between `java.net.URL` and `String`. +** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/URL[URL] otherwise a `MalformedURLException` is thrown. + [[mapping-object-references]] === Mapping object references diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index 20fb8a2fee..e88bb93b86 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.net.URL; import java.sql.Time; import java.sql.Timestamp; import java.text.DecimalFormat; @@ -254,4 +255,15 @@ public static String stringBuilder(ConversionContext conversionContext) { public static String uuid(ConversionContext conversionContext) { return typeReferenceName( conversionContext, UUID.class ); } + + /** + * Name for {@link java.net.URL}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String url(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, URL.class ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 4b3ab2a818..e012481054 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.net.URL; import java.sql.Time; import java.sql.Timestamp; import java.time.Duration; @@ -193,6 +194,8 @@ public Conversions(TypeFactory typeFactory) { register( Currency.class, String.class, new CurrencyToStringConversion() ); register( UUID.class, String.class, new UUIDToStringConversion() ); + + registerURLConversion(); } private void registerJodaConversions() { @@ -294,6 +297,16 @@ private void registerBigDecimalConversion(Class targetType) { } } + private void registerURLConversion() { + if ( isJavaURLAvailable() ) { + register( URL.class, String.class, new URLToStringConversion() ); + } + } + + private boolean isJavaURLAvailable() { + return typeFactory.isTypeAvailable( "java.net.URL" ); + } + private void register(Class sourceClass, Class targetClass, ConversionProvider conversion) { Type sourceType = typeFactory.getType( sourceClass ); Type targetType = typeFactory.getType( targetClass ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/URLToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/URLToStringConversion.java new file mode 100644 index 0000000000..716dfb3bb2 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/URLToStringConversion.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.List; +import java.util.Set; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.url; +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * Conversion between {@link java.net.URL} and {@link String}. + * + * @author Adam Szatyin + */ +public class URLToStringConversion extends SimpleConversion { + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toString()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return "new " + url( conversionContext ) + "( )"; + } + + @Override + protected Set getFromConversionImportTypes(final ConversionContext conversionContext) { + return asSet( conversionContext.getTypeFactory().getType( URL.class ) ); + } + + @Override + protected List getFromConversionExceptionTypes(ConversionContext conversionContext) { + return java.util.Collections.singletonList( + conversionContext.getTypeFactory().getType( MalformedURLException.class ) + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Source.java new file mode 100644 index 0000000000..ece0501a08 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Source.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.url; + +import java.net.URL; + +/** + * @author Adam Szatyin + */ +public class Source { + private URL url; + + private URL invalidURL; + + public URL getURL() { + return url; + } + + public void setURL(URL url) { + this.url = url; + } + + public URL getInvalidURL() { + return invalidURL; + } + + public void setInvalidURL(URL invalidURL) { + this.invalidURL = invalidURL; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Target.java new file mode 100644 index 0000000000..060f5582e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/Target.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.url; + +/** + * @author Adam Szatyin + */ +public class Target { + private String url; + private String invalidURL; + + public String getURL() { + return this.url; + } + + public void setURL(final String url) { + this.url = url; + } + + public String getInvalidURL() { + return this.invalidURL; + } + + public void setInvalidURL(final String invalidURL) { + this.invalidURL = invalidURL; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLConversionTest.java new file mode 100644 index 0000000000..bd1eed1480 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLConversionTest.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.url; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import java.net.MalformedURLException; +import java.net.URL; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Tests conversions between {@link java.net.URL} and String. + * + * @author Adam Szatyin + */ +@WithClasses({ Source.class, Target.class, URLMapper.class }) +public class URLConversionTest { + + @ProcessorTest + public void shouldApplyURLConversion() throws MalformedURLException { + Source source = new Source(); + source.setURL( new URL("https://mapstruct.org/") ); + + Target target = URLMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getURL() ).isEqualTo( source.getURL().toString() ); + } + + @ProcessorTest + public void shouldApplyReverseURLConversion() throws MalformedURLException { + Target target = new Target(); + target.setURL( "https://mapstruct.org/" ); + + Source source = URLMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getURL() ).isEqualTo( new URL( target.getURL() ) ); + } + + @ProcessorTest + public void shouldHandleInvalidURLString() { + Target target = new Target(); + target.setInvalidURL( "XXXXXXXXX" ); + + assertThatThrownBy( () -> URLMapper.INSTANCE.targetToSource( target ) ) + .isInstanceOf( RuntimeException.class ) + .getRootCause().isInstanceOf( MalformedURLException.class ); + } + + @ProcessorTest + public void shouldHandleInvalidURLStringWithMalformedURLException() { + Target target = new Target(); + target.setInvalidURL( "XXXXXXXXX" ); + + assertThatThrownBy( () -> URLMapper.INSTANCE.targetToSourceWithMalformedURLException( target ) ) + .isInstanceOf( MalformedURLException.class ); + } + + @ProcessorTest + public void shouldHandleNullURLString() { + Source source = new Source(); + + Target target = URLMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getURL() ).isNull(); + assertThat( target.getInvalidURL() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLMapper.java new file mode 100644 index 0000000000..18fc5bc7de --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/url/URLMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.url; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.net.MalformedURLException; + +@Mapper +public interface URLMapper { + + URLMapper INSTANCE = Mappers.getMapper( URLMapper.class ); + + Target sourceToTarget(Source source); + + Source targetToSource(Target target); + + Source targetToSourceWithMalformedURLException(Target target) throws MalformedURLException; +} From 7064e0bc977dc88222ff8fe8d23f9e36cc76fcdf Mon Sep 17 00:00:00 2001 From: Daniel Franco Date: Mon, 23 Aug 2021 15:19:02 +0100 Subject: [PATCH 0604/1006] Update maven wrapper version to 3.8.2 (#2557) --- .mvn/wrapper/maven-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 642d572ce9..abd303b673 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,2 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar From 9ed4e389f8328b5f62655c82119f05cb59c4a439 Mon Sep 17 00:00:00 2001 From: Tobias Meggendorfer Date: Mon, 30 Aug 2021 16:40:09 +0200 Subject: [PATCH 0605/1006] #2560 Ignore source properties if ignoreByDefault = true --- .../main/java/org/mapstruct/BeanMapping.java | 2 +- .../ap/internal/model/BeanMappingMethod.java | 4 ++ .../ErroneousSourceTargetMapper.java | 21 ++++++++++ .../IgnoreByDefaultSourcesTest.java | 38 +++++++++++++++++++ .../ap/test/ignorebydefaultsource/Source.java | 27 +++++++++++++ .../SourceTargetMapper.java | 23 +++++++++++ .../ap/test/ignorebydefaultsource/Target.java | 18 +++++++++ 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Target.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index f8c749fbde..3359cd8914 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -118,7 +118,7 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() /** * Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No - * warning will be issued on missing target properties. + * warning will be issued on missing source or target properties. * * @return The ignore strategy (default false). * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 36dae0ba51..17bf2cb465 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1514,6 +1514,10 @@ private ReportingPolicyGem getUnmappedSourcePolicy() { if ( mappingReferences.isForForgedMethods() ) { return ReportingPolicyGem.IGNORE; } + // If we have ignoreByDefault = true, unprocessed source properties are not an issue. + if ( method.getOptions().getBeanMapping().isignoreByDefault() ) { + return ReportingPolicyGem.IGNORE; + } return method.getOptions().getMapper().unmappedSourcePolicy(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapper.java new file mode 100644 index 0000000000..4ec3c64500 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignorebydefaultsource; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( + unmappedTargetPolicy = ReportingPolicy.IGNORE, + unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface ErroneousSourceTargetMapper { + ErroneousSourceTargetMapper INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper.class ); + + @Mapping(source = "one", target = "one") + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java new file mode 100644 index 0000000000..98f2cde4c0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignorebydefaultsource; + +import javax.tools.Diagnostic.Kind; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +@IssueKey("2560") +public class IgnoreByDefaultSourcesTest { + + @ProcessorTest + @WithClasses({ SourceTargetMapper.class, Source.class, Target.class }) + public void shouldSucceed() { + } + + @ProcessorTest + @WithClasses({ ErroneousSourceTargetMapper.class, Source.class, Target.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapper.class, + kind = Kind.ERROR, + line = 20, + message = "Unmapped source property: \"other\".") + } + ) + public void shouldRaiseErrorDueToNonIgnoredSourceProperty() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Source.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Source.java new file mode 100644 index 0000000000..81d6441d57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Source.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignorebydefaultsource; + +class Source { + private int one; + private int other; + + public int getOne() { + return one; + } + + public void setOne(int one) { + this.one = one; + } + + public int getOther() { + return other; + } + + public void setOther(int other) { + this.other = other; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java new file mode 100644 index 0000000000..e029bd7391 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignorebydefaultsource; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( + unmappedTargetPolicy = ReportingPolicy.IGNORE, + unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface SourceTargetMapper { + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + @Mapping(source = "one", target = "one") + @BeanMapping(ignoreByDefault = true) + Target sourceToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Target.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Target.java new file mode 100644 index 0000000000..68ec5c8933 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/Target.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignorebydefaultsource; + +class Target { + private int one; + + public int getOne() { + return one; + } + + public void setOne(int one) { + this.one = one; + } +} From 9057d68cd2411517df790e91b710244c7038e2ab Mon Sep 17 00:00:00 2001 From: Tobias Meggendorfer Date: Tue, 31 Aug 2021 21:45:25 +0200 Subject: [PATCH 0606/1006] Use DefaultLocale for more stable Issue2544MapperTest (#2569) --- .../ap/test/bugs/_2544/Issue2544Test.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java index 5cc252bbf8..a070231839 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2544/Issue2544Test.java @@ -9,6 +9,7 @@ import java.math.BigDecimal; +import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -19,12 +20,23 @@ @IssueKey( "2544" ) @WithClasses( { Issue2544Mapper.class } ) public class Issue2544Test { + // Parsing numbers is sensitive to locale settings (e.g. decimal point) @ProcessorTest - public void shouldConvert() { + @DefaultLocale("en") + public void shouldConvertEn() { Issue2544Mapper.Target target = Issue2544Mapper.INSTANCE.map( "123.45679E6" ); assertThat( target ).isNotNull(); assertThat( target.getBigNumber() ).isEqualTo( new BigDecimal( "1.2345679E+8" ) ); } + + @ProcessorTest + @DefaultLocale("de") + public void shouldConvertDe() { + Issue2544Mapper.Target target = Issue2544Mapper.INSTANCE.map( "123,45679E6" ); + + assertThat( target ).isNotNull(); + assertThat( target.getBigNumber() ).isEqualTo( new BigDecimal( "1.2345679E+8" ) ); + } } From f0a13bb306e4e86f13d328512bde3be07ed0b72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusuf=20Kemal=20=C3=96zcan?= Date: Mon, 6 Sep 2021 00:38:38 +0300 Subject: [PATCH 0607/1006] #2555 Add unmappedSourcePolicy annotation processor argument --- .../main/asciidoc/chapter-2-set-up.asciidoc | 13 ++++++ .../org/mapstruct/ap/MappingProcessor.java | 4 ++ .../internal/model/source/DefaultOptions.java | 3 ++ .../mapstruct/ap/internal/option/Options.java | 7 +++ ...SourceTargetMapperWithoutMapperConfig.java | 25 +++++++++++ .../unmappedsource/UnmappedSourceTest.java | 43 +++++++++++++++++++ 6 files changed, 95 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapperWithoutMapperConfig.java diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index d26be72156..730433639d 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -247,6 +247,19 @@ Supported values are: If a policy is given for a specific mapper via `@Mapper#unmappedTargetPolicy()`, the value from the annotation takes precedence. If a policy is given for a specific bean mapping via `@BeanMapping#unmappedTargetPolicy()`, it takes precedence over both `@Mapper#unmappedTargetPolicy()` and the option. |`WARN` + +|`mapstruct.unmappedSourcePolicy` +|The default reporting policy to be applied in case an attribute of the source object of a mapping method is not populated with a target value. + +Supported values are: + +* `ERROR`: any unmapped source property will cause the mapping code generation to fail +* `WARN`: any unmapped source property will cause a warning at build time +* `IGNORE`: unmapped source properties are ignored + +If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence. +If a policy is given for a specific bean mapping via `@BeanMapping#ignoreUnmappedSourceProperties()`, it takes precedence over both `@Mapper#unmappedSourcePolicy()` and the option. +|`WARN` |=== === Using MapStruct with the Java Module System diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 8369a8b270..952257753a 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -84,6 +84,7 @@ MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP, MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, MappingProcessor.UNMAPPED_TARGET_POLICY, + MappingProcessor.UNMAPPED_SOURCE_POLICY, MappingProcessor.DEFAULT_COMPONENT_MODEL, MappingProcessor.DEFAULT_INJECTION_STRATEGY, MappingProcessor.VERBOSE @@ -99,6 +100,7 @@ public class MappingProcessor extends AbstractProcessor { protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT = "mapstruct.suppressGeneratorVersionInfoComment"; protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; + protected static final String UNMAPPED_SOURCE_POLICY = "mapstruct.unmappedSourcePolicy"; protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; protected static final String DEFAULT_INJECTION_STRATEGY = "mapstruct.defaultInjectionStrategy"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; @@ -134,11 +136,13 @@ public synchronized void init(ProcessingEnvironment processingEnv) { private Options createOptions() { String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY ); + String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); return new Options( Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, + unmappedSourcePolicy != null ? ReportingPolicyGem.valueOf( unmappedSourcePolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 58f03ad55d..d52d094930 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -63,6 +63,9 @@ public ReportingPolicyGem unmappedTargetPolicy() { @Override public ReportingPolicyGem unmappedSourcePolicy() { + if ( options.getUnmappedSourcePolicy() != null ) { + return options.getUnmappedSourcePolicy(); + } return ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().getDefaultValue() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 54b69c28b3..46a90d4b43 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -17,6 +17,7 @@ public class Options { private final boolean suppressGeneratorTimestamp; private final boolean suppressGeneratorVersionComment; private final ReportingPolicyGem unmappedTargetPolicy; + private final ReportingPolicyGem unmappedSourcePolicy; private final boolean alwaysGenerateSpi; private final String defaultComponentModel; private final String defaultInjectionStrategy; @@ -24,11 +25,13 @@ public class Options { public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyGem unmappedTargetPolicy, + ReportingPolicyGem unmappedSourcePolicy, String defaultComponentModel, String defaultInjectionStrategy, boolean alwaysGenerateSpi, boolean verbose) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; + this.unmappedSourcePolicy = unmappedSourcePolicy; this.defaultComponentModel = defaultComponentModel; this.defaultInjectionStrategy = defaultInjectionStrategy; this.alwaysGenerateSpi = alwaysGenerateSpi; @@ -47,6 +50,10 @@ public ReportingPolicyGem getUnmappedTargetPolicy() { return unmappedTargetPolicy; } + public ReportingPolicyGem getUnmappedSourcePolicy() { + return unmappedSourcePolicy; + } + public String getDefaultComponentModel() { return defaultComponentModel; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapperWithoutMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapperWithoutMapperConfig.java new file mode 100644 index 0000000000..4ab2d3688c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/SourceTargetMapperWithoutMapperConfig.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.unmappedtarget.Source; +import org.mapstruct.ap.test.unmappedtarget.Target; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Yusuf Kemal Ozcan + */ +@Mapper +public interface SourceTargetMapperWithoutMapperConfig { + + SourceTargetMapperWithoutMapperConfig INSTANCE = Mappers.getMapper( SourceTargetMapperWithoutMapperConfig.class ); + + Target sourceToTarget(Source source); + + Source targetToSource(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 59d44a6baf..9b244592a2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -14,6 +14,7 @@ import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import static org.assertj.core.api.Assertions.assertThat; @@ -67,4 +68,46 @@ public void shouldLeaveUnmappedSourcePropertyUnset() { ) public void shouldRaiseErrorDueToUnsetSourceProperty() { } + + @ProcessorTest + @WithClasses({ Source.class, Target.class, + org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class }) + @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "IGNORE") + @ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "ERROR") + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class, + kind = Kind.ERROR, + line = 22, + message = "Unmapped source property: \"qux\"."), + @Diagnostic(type = org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class, + kind = Kind.ERROR, + line = 24, + message = "Unmapped source property: \"bar\".") + } + ) + public void shouldRaiseErrorDueToUnsetSourcePropertyWithPolicySetViaProcessorOption() { + } + + @ProcessorTest + @WithClasses({ Source.class, Target.class, + org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class }) + @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "IGNORE") + @ProcessorOption(name = "mapstruct.unmappedSourcePolicy", value = "WARN") + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class, + kind = Kind.WARNING, + line = 22, + message = "Unmapped source property: \"qux\"."), + @Diagnostic(type = org.mapstruct.ap.test.unmappedsource.SourceTargetMapperWithoutMapperConfig.class, + kind = Kind.WARNING, + line = 24, + message = "Unmapped source property: \"bar\".") + } + ) + public void shouldLeaveUnmappedSourcePropertyUnsetWithWarnPolicySetViaProcessorOption() { + } } From 2c23b935db4079ddeaeb65c47284d823b8451349 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Aug 2021 13:50:20 +0200 Subject: [PATCH 0608/1006] #2541 fix incorrect name for TypeVar with ElementType.TYPE_USE for javac-with-errorprone --- .../ap/internal/model/common/TypeFactory.java | 12 ++++- .../ap/test/bugs/_2541/Issue2541Mapper.java | 47 +++++++++++++++++++ .../ap/test/bugs/_2541/Issue2541Test.java | 28 +++++++++++ .../ap/test/bugs/_2541/Nullable.java | 22 +++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Nullable.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 127ec74270..b209626725 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -278,7 +278,17 @@ else if (componentTypeMirror.getKind().isPrimitive()) { isInterface = false; // When the component type is primitive and is annotated with ElementType.TYPE_USE then // the typeMirror#toString returns (@CustomAnnotation :: byte) for the javac compiler - name = mirror.getKind().isPrimitive() ? NativeTypes.getName( mirror.getKind() ) : mirror.toString(); + if ( mirror.getKind().isPrimitive() ) { + name = NativeTypes.getName( mirror.getKind() ); + } + // When the component type is type var and is annotated with ElementType.TYPE_USE then + // the typeMirror#toString returns (@CustomAnnotation T) for the errorprone javac compiler + else if ( mirror.getKind() == TypeKind.TYPEVAR ) { + name = ( (TypeVariable) mirror ).asElement().getSimpleName().toString(); + } + else { + name = mirror.toString(); + } packageName = null; qualifiedName = name; typeElement = null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Mapper.java new file mode 100644 index 0000000000..0531f5242c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Mapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2541; + +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2541Mapper { + + Issue2541Mapper INSTANCE = Mappers.getMapper( Issue2541Mapper.class ); + + Target map(Source source); + + default Optional toOptional(@Nullable T value) { + return Optional.ofNullable( value ); + } + + class Target { + private Optional value; + + public Optional getValue() { + return value; + } + + public void setValue(Optional value) { + this.value = value; + } + } + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Test.java new file mode 100644 index 0000000000..d1b8bd7f52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Issue2541Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2541; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue2541Mapper.class, + Nullable.class, +}) +class Issue2541Test { + + @ProcessorTest + void shouldGenerateCorrectCode() { + Issue2541Mapper.Target target = Issue2541Mapper.INSTANCE.map( new Issue2541Mapper.Source( null ) ); + + assertThat( target.getValue() ).isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Nullable.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Nullable.java new file mode 100644 index 0000000000..24c52eb906 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2541/Nullable.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2541; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ + ElementType.METHOD, + ElementType.TYPE_USE +}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Nullable { + +} From b59a23965a0c77206851a118c5b1673819735dd4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 29 Aug 2021 11:24:34 +0200 Subject: [PATCH 0609/1006] #2554 Records should not treat collections as alternative target accessors --- .../java/org/mapstruct/itest/records/Car.java | 24 ++++++++++++++ .../itest/records/CarAndWheelMapper.java | 31 +++++++++++++++++++ .../org/mapstruct/itest/records/CarDto.java | 15 +++++++++ .../itest/records/WheelPosition.java | 22 +++++++++++++ .../mapstruct/itest/records/RecordsTest.java | 14 +++++++++ .../ap/internal/model/common/Type.java | 7 +++++ 6 files changed, 113 insertions(+) create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Car.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarAndWheelMapper.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarDto.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/WheelPosition.java diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Car.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Car.java new file mode 100644 index 0000000000..9332c47dfb --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Car.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public class Car { + + private List wheelPositions; + + public List getWheelPositions() { + return wheelPositions; + } + + public void setWheelPositions(List wheelPositions) { + this.wheelPositions = wheelPositions; + } +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarAndWheelMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarAndWheelMapper.java new file mode 100644 index 0000000000..cc69ae7605 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarAndWheelMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface CarAndWheelMapper { + + CarAndWheelMapper INSTANCE = Mappers.getMapper( CarAndWheelMapper.class ); + + default String stringFromWheelPosition(WheelPosition source) { + return source == null ? null : source.getPosition(); + } + + default WheelPosition wheelPositionFromString(String source) { + return source == null ? null : new WheelPosition(source); + } + + CarDto carDtoFromCar(Car source); + + Car carFromCarDto(CarDto source); +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarDto.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarDto.java new file mode 100644 index 0000000000..5470550060 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/CarDto.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public record CarDto(List wheelPositions) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/WheelPosition.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/WheelPosition.java new file mode 100644 index 0000000000..fe8016ddbf --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/WheelPosition.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public class WheelPosition { + + private final String position; + + public WheelPosition(String position) { + this.position = position; + } + + public String getPosition() { + return position; + } +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index b404681806..e3d055345e 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -5,6 +5,8 @@ */ package org.mapstruct.itest.records; +import java.util.Arrays; + import static org.assertj.core.api.Assertions.assertThat; import org.junit.Test; @@ -47,4 +49,16 @@ public void shouldMapIntoGenericRecord() { assertThat( value ).isNotNull(); assertThat( value.value() ).isEqualTo( "Kermit" ); } + + @Test + public void shouldMapIntoRecordWithList() { + Car car = new Car(); + car.setWheelPositions( Arrays.asList( new WheelPosition( "left" ) ) ); + + CarDto carDto = CarAndWheelMapper.INSTANCE.carDtoFromCar(car); + + assertThat( carDto ).isNotNull(); + assertThat( carDto.wheelPositions() ) + .containsExactly( "left" ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 4da9128f98..e13d7b9ddd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -874,6 +874,13 @@ private List getAdders() { * @return an unmodifiable list of alternative target accessors. */ private List getAlternativeTargetAccessors() { + if ( alternativeTargetAccessors != null ) { + return alternativeTargetAccessors; + } + + if ( isRecord() ) { + alternativeTargetAccessors = Collections.emptyList(); + } if ( alternativeTargetAccessors == null ) { From 8b84f5b7d78979be979940b8ded1cbbeb868e32c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 21 Sep 2021 22:17:24 +0200 Subject: [PATCH 0610/1006] #2591 Update dependencies so tests run on Java 18 Update GitHub Actions for tests to run on Java 11, 13, 16, 17 and 18-ea --- .github/workflows/java-ea.yml | 4 ++-- .github/workflows/main.yml | 4 ++-- parent/pom.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index 598a8979a6..f2b2a99be4 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - java: [17-ea] + java: [18-ea] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: @@ -21,4 +21,4 @@ jobs: with: java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} install -DskipDistribution=true + run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 741f8bce61..b023631628 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - java: [11, 13, 16] + java: [11, 13, 16, 17] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: @@ -23,7 +23,7 @@ jobs: with: java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} install -DskipDistribution=true + run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true linux: name: 'Linux JDK 8' runs-on: ubuntu-latest diff --git a/parent/pom.xml b/parent/pom.xml index 8ce94764ea..f4edccfc85 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ 3.0.0-M3 3.0.0-M5 3.1.0 - 5.3.3 + 5.3.10 1.6.0 8.36.1 5.8.0-M1 From f167e7a20c7e1bf4f87aab8e760983a359b43bbb Mon Sep 17 00:00:00 2001 From: valery1707 Date: Tue, 21 Sep 2021 10:42:25 +0300 Subject: [PATCH 0611/1006] Fix typo in JavaDoc --- core/src/main/java/org/mapstruct/Mapping.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 0af73f3687..7ca637f0ca 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -54,7 +54,7 @@ *

      Example 2: Mapping properties with different names

      *
      
        * // We need map Human.companyName to HumanDto.company
      - * // we can use @Mapping with parameters {@link #source()} and {@link #source()}
      + * // we can use @Mapping with parameters {@link #source()} and {@link #target()}
        * @Mapper
        * public interface HumanMapper {
        *    @Mapping(source="companyName", target="company")
      @@ -476,6 +476,4 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy()
            */
           Class mappingControl() default MappingControl.class;
       
      -
      -
       }
      
      From 5df6b7a75b97e58687027470e9048e6f6534bca5 Mon Sep 17 00:00:00 2001
      From: Zegveld <41897697+Zegveld@users.noreply.github.com>
      Date: Tue, 19 Oct 2021 20:44:25 +0200
      Subject: [PATCH 0612/1006] #131, #2438, #366 Add support for Type-Refinement
       (Downcast) Mapping (#2512)
      
      Add new `@SubclassMapping` for creating Downcast mapping.
      When a parent mapping method is annotated with `@SubclassMapping`
      it will now generate an instanceof check inside the parent mapping
      and generate the subclass mappings if they are not manually defined.
      
      There is also `SubclassExhaustiveStrategy` for controlling what MapStruct should do in case the target type is abstract and there is no suitable way to create it.
      ---
       .../main/java/org/mapstruct/BeanMapping.java  |  12 +
       core/src/main/java/org/mapstruct/Mapper.java  |  12 +
       .../main/java/org/mapstruct/MapperConfig.java |  12 +
       .../mapstruct/SubclassExhaustiveStrategy.java |  28 +++
       .../java/org/mapstruct/SubclassMapping.java   |  84 +++++++
       .../java/org/mapstruct/SubclassMappings.java  |  58 +++++
       ...apter-10-advanced-mapping-options.asciidoc |  43 ++++
       .../ap/internal/gem/GemGenerator.java         |   4 +
       .../gem/SubclassExhaustiveStrategyGem.java    |  27 +++
       .../model/AbstractMappingMethodBuilder.java   |  47 +++-
       .../ap/internal/model/BeanMappingMethod.java  | 138 ++++++++++-
       .../ap/internal/model/ForgedMethod.java       |  35 ++-
       .../ap/internal/model/SubclassMapping.java    |  69 ++++++
       .../model/assignment/ReturnWrapper.java       |  20 ++
       .../model/source/BeanMappingOptions.java      |  20 +-
       .../internal/model/source/DefaultOptions.java |   9 +-
       .../model/source/DelegatingOptions.java       |   7 +-
       .../model/source/MapperConfigOptions.java     |   8 +
       .../internal/model/source/MapperOptions.java  |   8 +
       .../model/source/MappingMethodOptions.java    |  31 ++-
       .../internal/model/source/SourceMethod.java   |  13 +-
       .../model/source/SubclassMappingOptions.java  | 171 +++++++++++++
       .../model/source/SubclassValidator.java       |  53 ++++
       .../processor/MethodRetrievalProcessor.java   | 229 +++++++++++++++---
       .../mapstruct/ap/internal/util/Message.java   |   6 +-
       .../ap/internal/model/BeanMappingMethod.ftl   |  15 ++
       .../model/assignment/ReturnWrapper.ftl        |  17 ++
       .../ErroneousSubclassMapper1.java             |  24 ++
       .../ErroneousSubclassUpdateMapper.java        |  28 +++
       .../MappingInheritanceTest.java               |  50 ++++
       .../subclassmapping/SimpleSubclassMapper.java |  31 +++
       .../test/subclassmapping/SubclassMapper.java  |  31 +++
       .../SubclassMapperUsingExistingMappings.java  |  36 +++
       .../subclassmapping/SubclassMappingTest.java  | 139 +++++++++++
       .../SubclassOrderWarningMapper.java           |  31 +++
       .../AbstractSuperClassTest.java               |  70 ++++++
       .../abstractsuperclass/AbstractVehicle.java   |  18 ++
       .../abstractsuperclass/Bike.java              |  18 ++
       .../abstractsuperclass/BikeDto.java           |  18 ++
       .../abstractsuperclass/Car.java               |  18 ++
       .../abstractsuperclass/CarDto.java            |  18 ++
       ...sSubclassWithAbstractSuperClassMapper.java |  27 +++
       .../abstractsuperclass/Motorcycle.java        |  10 +
       .../abstractsuperclass/MotorcycleDto.java     |  10 +
       .../SubclassWithAbstractSuperClassMapper.java |  26 ++
       .../abstractsuperclass/VehicleCollection.java |  17 ++
       .../VehicleCollectionDto.java                 |  17 ++
       .../abstractsuperclass/VehicleDto.java        |  18 ++
       .../fixture/AbstractParentSource.java         |  10 +
       .../fixture/AbstractParentTarget.java         |  10 +
       .../fixture/ImplementedParentSource.java      |  10 +
       .../fixture/ImplementedParentTarget.java      |  10 +
       .../fixture/InterfaceParentSource.java        |  10 +
       .../fixture/InterfaceParentTarget.java        |  10 +
       .../subclassmapping/fixture/SubSource.java    |  18 ++
       .../fixture/SubSourceOther.java               |  18 ++
       .../subclassmapping/fixture/SubTarget.java    |  18 ++
       .../fixture/SubTargetOther.java               |  18 ++
       .../fixture/SubclassAbstractMapper.java       |  21 ++
       .../fixture/SubclassFixtureTest.java          |  53 ++++
       .../fixture/SubclassImplementedMapper.java    |  17 ++
       .../fixture/SubclassInterfaceMapper.java      |  19 ++
       .../test/subclassmapping/mappables/Bike.java  |  18 ++
       .../subclassmapping/mappables/BikeDto.java    |  18 ++
       .../test/subclassmapping/mappables/Car.java   |  18 ++
       .../subclassmapping/mappables/CarDto.java     |  18 ++
       .../subclassmapping/mappables/HatchBack.java  |  18 ++
       .../mappables/HatchBackDto.java               |  18 ++
       .../subclassmapping/mappables/Source.java     |  42 ++++
       .../mappables/SourceSubclass.java             |  33 +++
       .../subclassmapping/mappables/Target.java     |  54 +++++
       .../subclassmapping/mappables/Vehicle.java    |  27 +++
       .../mappables/VehicleCollection.java          |  17 ++
       .../mappables/VehicleCollectionDto.java       |  17 ++
       .../subclassmapping/mappables/VehicleDto.java |  27 +++
       .../fixture/SubclassAbstractMapperImpl.java   |  59 +++++
       .../SubclassImplementedMapperImpl.java        |  61 +++++
       .../fixture/SubclassInterfaceMapperImpl.java  |  59 +++++
       78 files changed, 2505 insertions(+), 72 deletions(-)
       create mode 100644 core/src/main/java/org/mapstruct/SubclassExhaustiveStrategy.java
       create mode 100644 core/src/main/java/org/mapstruct/SubclassMapping.java
       create mode 100644 core/src/main/java/org/mapstruct/SubclassMappings.java
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/gem/SubclassExhaustiveStrategyGem.java
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/SubclassMapping.java
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.java
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java
       create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java
       create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassMapper1.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassUpdateMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/MappingInheritanceTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapperUsingExistingMappings.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassOrderWarningMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractSuperClassTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractVehicle.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Bike.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/BikeDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Car.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CarDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/ErroneousSubclassWithAbstractSuperClassMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Motorcycle.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MotorcycleDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/SubclassWithAbstractSuperClassMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollection.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollectionDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentSource.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentTarget.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSource.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOther.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTarget.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetOther.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Bike.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/BikeDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/CarDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBack.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBackDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Source.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/SourceSubclass.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Target.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Vehicle.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollection.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollectionDto.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleDto.java
       create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java
       create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java
       create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java
      
      diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java
      index 3359cd8914..be3df0d29d 100644
      --- a/core/src/main/java/org/mapstruct/BeanMapping.java
      +++ b/core/src/main/java/org/mapstruct/BeanMapping.java
      @@ -14,6 +14,7 @@
       import org.mapstruct.control.MappingControl;
       
       import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
      +import static org.mapstruct.SubclassExhaustiveStrategy.COMPILE_ERROR;
       
       /**
        * Configures the mapping between two bean types.
      @@ -116,6 +117,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy()
            */
           NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
       
      +    /**
      +     * Determines how to handle missing implementation for super classes when using the {@link SubclassMapping}.
      +     *
      +     * Overrides the setting on {@link MapperConfig} and {@link Mapper}.
      +     *
      +     * @return strategy to handle missing implementation combined with {@link SubclassMappings}.
      +     *
      +     * @since 1.5
      +     */
      +    SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR;
      +
           /**
            * Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No
            * warning will be issued on missing source or target properties.
      diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java
      index 98022f1a6c..9ddd9bff5c 100644
      --- a/core/src/main/java/org/mapstruct/Mapper.java
      +++ b/core/src/main/java/org/mapstruct/Mapper.java
      @@ -15,6 +15,7 @@
       import org.mapstruct.factory.Mappers;
       
       import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
      +import static org.mapstruct.SubclassExhaustiveStrategy.COMPILE_ERROR;
       
       /**
        * Marks an interface or abstract class as a mapper and activates the generation of a implementation of that type via
      @@ -237,6 +238,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default
            */
           NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
       
      +    /**
      +     * Determines how to handle missing implementation for super classes when using the {@link SubclassMapping}.
      +     *
      +     * Can be overridden by the one on {@link BeanMapping}, but overrides {@link MapperConfig}.
      +     *
      +     * @return strategy to handle missing implementation combined with {@link SubclassMappings}.
      +     *
      +     * @since 1.5
      +     */
      +    SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR;
      +
           /**
            * Determines whether to use field or constructor injection. This is only used on annotated based component models
            * such as CDI, Spring and JSR 330.
      diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java
      index ecfd888ca2..877495867c 100644
      --- a/core/src/main/java/org/mapstruct/MapperConfig.java
      +++ b/core/src/main/java/org/mapstruct/MapperConfig.java
      @@ -15,6 +15,7 @@
       import org.mapstruct.factory.Mappers;
       
       import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION;
      +import static org.mapstruct.SubclassExhaustiveStrategy.COMPILE_ERROR;
       
       /**
        * Marks a class or interface as configuration source for generated mappers. This allows to share common configurations
      @@ -210,6 +211,17 @@ MappingInheritanceStrategy mappingInheritanceStrategy()
            */
           NullValueCheckStrategy nullValueCheckStrategy() default ON_IMPLICIT_CONVERSION;
       
      +    /**
      +     * Determines how to handle missing implementation for super classes when using the {@link SubclassMapping}.
      +     *
      +     * Can be overridden by the one on {@link BeanMapping} or {@link Mapper}.
      +     *
      +     * @return strategy to handle missing implementation combined with {@link SubclassMappings}.
      +     *
      +     * @since 1.5
      +     */
      +    SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR;
      +
           /**
            * Determines whether to use field or constructor injection. This is only used on annotated based component models
            * such as CDI, Spring and JSR 330.
      diff --git a/core/src/main/java/org/mapstruct/SubclassExhaustiveStrategy.java b/core/src/main/java/org/mapstruct/SubclassExhaustiveStrategy.java
      new file mode 100644
      index 0000000000..a60d067faa
      --- /dev/null
      +++ b/core/src/main/java/org/mapstruct/SubclassExhaustiveStrategy.java
      @@ -0,0 +1,28 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct;
      +
      +/**
      + * Strategy for dealing with subclassMapping annotated methods.
      + *
      + * @since 1.5
      + * @author Ben Zegveld
      + */
      +public enum SubclassExhaustiveStrategy {
      +
      +    /**
      +     * If there is no valid constructor or known method to create the return value of a with `@SubclassMapping`
      +     * annotated mapping then a compilation error will be thrown.
      +     */
      +    COMPILE_ERROR,
      +
      +    /**
      +     * If there is no valid constructor or known method to create the return value of a with `@SubclassMapping`
      +     * annotated mapping then an {@link IllegalArgumentException} will be thrown if a call is made with a type for which
      +     * there is no {@link SubclassMapping} available.
      +     */
      +    RUNTIME_EXCEPTION;
      +}
      diff --git a/core/src/main/java/org/mapstruct/SubclassMapping.java b/core/src/main/java/org/mapstruct/SubclassMapping.java
      new file mode 100644
      index 0000000000..bfd4f9bec5
      --- /dev/null
      +++ b/core/src/main/java/org/mapstruct/SubclassMapping.java
      @@ -0,0 +1,84 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct;
      +
      +import java.lang.annotation.ElementType;
      +import java.lang.annotation.Repeatable;
      +import java.lang.annotation.Retention;
      +import java.lang.annotation.RetentionPolicy;
      +import java.lang.annotation.Target;
      +
      +import org.mapstruct.util.Experimental;
      +
      +/**
      + * Configures the mapping to handle hierarchy of the source type.
      + * 

      + * The subclass to be mapped is to be specified via {@link #source()}. + * The subclass to map to is to be specified via {@link #target()}. + *

      + *

      + * This annotation can be combined with @Mapping annotations. + *

      + * + *
      
      + * @Mapper
      + * public interface MyMapper {
      + *    @SubclassMapping (target = TargetSubclass.class, source = SourceSubclass.class)
      + *    TargetParent mapParent(SourceParent parent);
      + *
      + *    TargetSubclass mapSubclass(SourceSubclass subInstant);
      + * }
      + * 
      + * Below follow examples of the implementation for the mapParent method. + * Example 1: For parents that cannot be created. (e.g. abstract classes or interfaces) + *
      
      + * // generates
      + * @Override
      + * public TargetParent mapParent(SourceParent parent) {
      + *     if (parent instanceof SourceSubclass) {
      + *         return mapSubclass( (SourceSubclass) parent );
      + *     }
      + *     else {
      + *         throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for "
      + *                    + parent.getClass());
      + *     }
      + * }
      + * 
      + * Example 2: For parents that can be created. (e.g. normal classes or interfaces with + * @Mappper( uses = ObjectFactory.class ) ) + *
      
      + * // generates
      + * @Override
      + * public TargetParent mapParent(SourceParent parent) {
      + *     TargetParent targetParent1;
      + *     if (parent instanceof SourceSubclass) {
      + *         targetParent1 = mapSubclass( (SourceSubclass) parent );
      + *     }
      + *     else {
      + *         targetParent1 = new TargetParent();
      + *         // ...
      + *     }
      + * }
      + * 
      + * + * @author Ben Zegveld + * @since 1.5 + */ +@Repeatable(value = SubclassMappings.class) +@Retention(RetentionPolicy.CLASS) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) +@Experimental +public @interface SubclassMapping { + /** + * @return the source subclass to check for before using the default mapping as fallback. + */ + Class source(); + + /** + * @return the target subclass to map the source to. + */ + Class target(); +} diff --git a/core/src/main/java/org/mapstruct/SubclassMappings.java b/core/src/main/java/org/mapstruct/SubclassMappings.java new file mode 100644 index 0000000000..938b836f77 --- /dev/null +++ b/core/src/main/java/org/mapstruct/SubclassMappings.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.util.Experimental; + +/** + * Configures the SubclassMappings of several subclasses. + *

      + * TIP: When using java 8 or later, you can omit the @SubclassMappings + * Wrapper annotation and directly specify several @SubclassMapping annotations + * on one method. + *

      + *

      These two examples are equal. + *

      + *
      
      + * // before java 8
      + * @Mapper
      + * public interface MyMapper {
      + *     @SubclassMappings({
      + *         @SubclassMapping(source = FirstSub.class, target = FirstTargetSub.class),
      + *         @SubclassMapping(source = SecondSub.class, target = SecondTargetSub.class)
      + *     })
      + *     ParentTarget toParentTarget(Parent parent);
      + * }
      + * 
      + *
      
      + * // java 8 and later
      + * @Mapper
      + * public interface MyMapper {
      + *     @SubclassMapping(source = First.class, target = FirstTargetSub.class),
      + *     @SubclassMapping(source = SecondSub.class, target = SecondTargetSub.class)
      + *     ParentTarget toParentTarget(Parent parent);
      + * }
      + * 
      + * + * @author Ben Zegveld + * @since 1.5 + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +@Experimental +public @interface SubclassMappings { + + /** + * @return the subclassMappings to apply. + */ + SubclassMapping[] value(); + +} diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index d3ab2424b1..5d7da371a1 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -110,6 +110,49 @@ public interface SourceTargetMapper { The example demonstrates how to use defaultExpression to set an `ID` field if the source field is null, this could be used to take the existing `sourceId` from the source object if it is set, or create a new `Id` if it isn't. Please note that the fully qualified package name is specified because MapStruct does not take care of the import of the `UUID` class (unless it’s used otherwise explicitly in the `SourceTargetMapper`). This can be resolved by defining imports on the @Mapper annotation (see <>). +[[sub-class-mappings]] +=== Subclass Mapping + +When both input and result types have an inheritance relation, you would want the correct specialization be mapped to the matching specialization. +Suppose an `Apple` and a `Banana`, which are both specializations of `Fruit`. + +.Specifying the sub class mappings of a fruit mapping +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface FruitMapper { + + @SubclassMapping( source = AppleDto.class, target = Apple.class ) + @SubclassMapping( source = BananaDto.class, target = Banana.class ) + Fruit map( FruitDto source ); + +} +---- +==== + +If you would just use a normal mapping both the `AppleDto` and the `BananaDto` would be made into a `Fruit` object, instead of an `Apple` and a `Banana` object. +By using the subclass mapping an `AppleDtoToApple` mapping will be used for `AppleDto` objects, and an `BananaDtoToBanana` mapping will be used for `BananaDto` objects. +If you try to map a `GrapeDto` it would still turn it into a `Fruit`. + +In the case that the `Fruit` is an abstract class or an interface, you would get a compile error. + +To allow mappings for abstract classes or interfaces you need to set the `subclassExhaustiveStrategy` to `RUNTIME_EXCEPTION`, you can do this at the `@MapperConfig`, `@Mapper` or `@BeanMapping` annotations. If you then pass a `GrapeDto` an `IllegalArgumentException` will be thrown because it is unknown how to map a `GrapeDto`. +Adding the missing (`@SubclassMapping`) for it will fix that. + +[TIP] +==== +If the mapping method for the subclasses does not exist it will be created and any other annotations on the fruit mapping method will be inherited by the newly generated mappings. +==== + +[NOTE] +==== +Combining `@SubclassMapping` with update methods is not supported. +If you try to use subclass mappings there will be a compile error. +The same issue exists for the `@Context` and `@TargetType` parameters. +==== + [[determining-result-type]] === Determining the result type diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index df5a90d5c2..e0491cbc4e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -28,6 +28,8 @@ import org.mapstruct.Named; import org.mapstruct.ObjectFactory; import org.mapstruct.Qualifier; +import org.mapstruct.SubclassMapping; +import org.mapstruct.SubclassMappings; import org.mapstruct.TargetType; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; @@ -47,6 +49,8 @@ @GemDefinition(BeanMapping.class) @GemDefinition(EnumMapping.class) @GemDefinition(MapMapping.class) +@GemDefinition(SubclassMapping.class) +@GemDefinition(SubclassMappings.class) @GemDefinition(TargetType.class) @GemDefinition(MappingTarget.class) @GemDefinition(DecoratedWith.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/SubclassExhaustiveStrategyGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/SubclassExhaustiveStrategyGem.java new file mode 100644 index 0000000000..2367d649a9 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/SubclassExhaustiveStrategyGem.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.gem; + +/** + * Gem for the enum {@link org.mapstruct.SubclassExhaustiveStrategy} + * + * @author Ben Zegveld + */ +public enum SubclassExhaustiveStrategyGem { + + COMPILE_ERROR( false ), + RUNTIME_EXCEPTION( true ); + + private final boolean abstractReturnTypeAllowed; + + SubclassExhaustiveStrategyGem(boolean abstractReturnTypeAllowed) { + this.abstractReturnTypeAllowed = abstractReturnTypeAllowed; + } + + public boolean isAbstractReturnTypeAllowed() { + return abstractReturnTypeAllowed; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 91b8427630..efc7a71469 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -5,26 +5,45 @@ */ package org.mapstruct.ap.internal.model; +import org.mapstruct.ap.internal.gem.BuilderGem; +import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; 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.gem.BuilderGem; +import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.util.Strings; -import static org.mapstruct.ap.internal.model.ForgedMethod.forElementMapping; - /** * An abstract builder that can be reused for building {@link MappingMethod}(s). * * @author Filip Hrisafov */ public abstract class AbstractMappingMethodBuilder, - M extends MappingMethod> extends AbstractBaseBuilder { + M extends MappingMethod> + extends AbstractBaseBuilder { public AbstractMappingMethodBuilder(Class selfType) { super( selfType ); } + private interface ForgeMethodCreator { + ForgedMethod createMethod(String name, Type sourceType, Type returnType, Method basedOn, + ForgedMethodHistory history, boolean forgedNameBased); + + static ForgeMethodCreator forSubclassMapping(MappingReferences mappingReferences) { + return (name, sourceType, targetType, method, description, + forgedNameBased) -> ForgedMethod + .forSubclassMapping( + name, + sourceType, + targetType, + method, + mappingReferences, + description, + forgedNameBased ); + } + } + public abstract M build(); private ForgedMethodHistory description; @@ -35,6 +54,20 @@ public AbstractMappingMethodBuilder(Class selfType) { protected abstract boolean shouldUsePropertyNamesInHistory(); Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { + return forgeMapping( sourceRHS, sourceType, targetType, ForgedMethod::forElementMapping ); + } + + Assignment forgeSubclassMapping(SourceRHS sourceRHS, Type sourceType, Type targetType, + MappingReferences mappingReferences) { + return forgeMapping( + sourceRHS, + sourceType, + targetType, + ForgeMethodCreator.forSubclassMapping( mappingReferences ) ); + } + + private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType, + ForgeMethodCreator forgeMethodCreator) { if ( !canGenerateAutoSubMappingBetween( sourceType, targetType ) ) { return null; } @@ -55,14 +88,14 @@ Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targetType) { shouldUsePropertyNamesInHistory(), sourceRHS.getSourceErrorMessagePart() ); - ForgedMethod forgedMethod = forElementMapping( name, sourceType, targetType, method, description, true ); + ForgedMethod forgedMethod = + forgeMethodCreator.createMethod( name, sourceType, targetType, method, description, true ); BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); return createForgedAssignment( sourceRHS, ctx.getTypeFactory().builderTypeFor( targetType, builder ), - forgedMethod - ); + forgedMethod ); } private String getName(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 17bf2cb465..0b299067f5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -41,10 +41,14 @@ import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; import org.mapstruct.ap.internal.model.beanmapping.SourceReference; import org.mapstruct.ap.internal.model.beanmapping.TargetReference; +import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.BuilderType; +import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; import org.mapstruct.ap.internal.model.source.BeanMappingOptions; @@ -52,7 +56,9 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.SubclassMappingOptions; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; @@ -82,16 +88,15 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final Map> constructorMappingsByParameter; private final List constantMappings; private final List constructorConstantMappings; + private final List subclassMappings; private final Type returnTypeToConstruct; private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; private final MappingReferences mappingReferences; - public static class Builder { + public static class Builder extends AbstractMappingMethodBuilder { - private MappingBuilderContext ctx; - private Method method; private Type userDefinedReturnType; /* returnType to construct can have a builder */ @@ -110,9 +115,13 @@ public static class Builder { private MethodReference factoryMethod; private boolean hasFactoryMethod; - public Builder mappingContext(MappingBuilderContext mappingContext) { - this.ctx = mappingContext; - return this; + public Builder() { + super( Builder.class ); + } + + @Override + protected boolean shouldUsePropertyNamesInHistory() { + return true; } public Builder userDefinedReturnType(Type userDefinedReturnType) { @@ -126,12 +135,12 @@ public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { } public Builder sourceMethod(SourceMethod sourceMethod) { - this.method = sourceMethod; + method( sourceMethod ); return this; } public Builder forgedMethod(ForgedMethod forgedMethod) { - this.method = forgedMethod; + method( forgedMethod ); mappingReferences = forgedMethod.getMappingReferences(); Parameter sourceParameter = first( Parameter.getSourceParameters( forgedMethod.getParameters() ) ); for ( MappingReference mappingReference: mappingReferences.getMappingReferences() ) { @@ -165,7 +174,9 @@ public BeanMappingMethod build() { // the userDefinedReturn type can also require a builder. That buildertype is already set returnTypeImpl = returnTypeBuilder.getBuilder(); initializeFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null + || allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed( returnTypeImpl ) + || doesNotAllowAbstractReturnTypeAndCanBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } else { @@ -185,7 +196,9 @@ else if ( userDefinedReturnType != null ) { else if ( !method.isUpdateMethod() ) { returnTypeImpl = method.getReturnType(); initializeFactoryMethod( returnTypeImpl, selectionParameters ); - if ( factoryMethod != null || canReturnTypeBeConstructed( returnTypeImpl ) ) { + if ( factoryMethod != null + || allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed( returnTypeImpl ) + || doesNotAllowAbstractReturnTypeAndCanBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; } else { @@ -333,6 +346,11 @@ else if ( !method.isUpdateMethod() ) { } + List subclasses = new ArrayList<>(); + for ( SubclassMappingOptions subclassMappingOptions : method.getOptions().getSubclassMappings() ) { + subclasses.add( createSubclassMapping( subclassMappingOptions ) ); + } + MethodReference finalizeMethod = null; if ( shouldCallFinalizerMethod( returnTypeToConstruct ) ) { @@ -350,10 +368,74 @@ else if ( !method.isUpdateMethod() ) { beforeMappingMethods, afterMappingMethods, finalizeMethod, - mappingReferences + mappingReferences, + subclasses ); } + private boolean doesNotAllowAbstractReturnTypeAndCanBeConstructed(Type returnTypeImpl) { + return !isAbstractReturnTypeAllowed() + && canReturnTypeBeConstructed( returnTypeImpl ); + } + + private boolean allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed(Type returnTypeImpl) { + return isAbstractReturnTypeAllowed() + && isReturnTypeAbstractOrCanBeConstructed( returnTypeImpl ); + } + + private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMappingOptions) { + TypeFactory typeFactory = ctx.getTypeFactory(); + Type sourceType = typeFactory.getType( subclassMappingOptions.getSource() ); + Type targetType = typeFactory.getType( subclassMappingOptions.getTarget() ); + + SourceRHS rightHandSide = new SourceRHS( + "subclassMapping", + sourceType, + Collections.emptySet(), + "SubclassMapping for " + sourceType.getFullyQualifiedName() ); + SelectionCriteria criteria = + SelectionCriteria + .forMappingMethods( + new SelectionParameters( + Collections.emptyList(), + Collections.emptyList(), + subclassMappingOptions.getTarget(), + ctx.getTypeUtils() ).withSourceRHS( rightHandSide ), + null, + null, + false ); + Assignment assignment = ctx + .getMappingResolver() + .getTargetAssignment( + method, + null, + targetType, + FormattingParameters.EMPTY, + criteria, + rightHandSide, + null, + () -> forgeSubclassMapping( + rightHandSide, + sourceType, + targetType, + mappingReferences ) ); + String sourceArgument = null; + for ( Parameter parameter : method.getSourceParameters() ) { + if ( ctx + .getTypeUtils() + .isAssignable( sourceType.getTypeMirror(), parameter.getType().getTypeMirror() ) ) { + sourceArgument = parameter.getName(); + assignment.setSourceLocalVarName( "(" + sourceType.createReferenceName() + ") " + sourceArgument ); + } + } + return new SubclassMapping( sourceType, sourceArgument, targetType, assignment ); + } + + private boolean isAbstractReturnTypeAllowed() { + return method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed() + && !method.getOptions().getSubclassMappings().isEmpty(); + } + private void initializeMappingReferencesIfNeeded(Type resultTypeToMap) { if ( mappingReferences == null && method instanceof SourceMethod ) { Set readAndWriteTargetProperties = new HashSet<>( unprocessedTargetProperties.keySet() ); @@ -561,6 +643,20 @@ else if ( !returnType.hasAccessibleConstructor() ) { return error; } + private boolean isReturnTypeAbstractOrCanBeConstructed(Type returnType) { + boolean error = true; + if ( !returnType.isAbstract() && !returnType.hasAccessibleConstructor() ) { + ctx + .getMessager() + .printMessage( + method.getExecutable(), + Message.GENERAL_NO_SUITABLE_CONSTRUCTOR, + returnType.describe() ); + error = false; + } + return error; + } + /** * Find a factory method for a return type or for a builder. * @param returnTypeImpl the return type implementation to construct @@ -1613,7 +1709,8 @@ private BeanMappingMethod(Method method, List beforeMappingReferences, List afterMappingReferences, MethodReference finalizerMethod, - MappingReferences mappingReferences) { + MappingReferences mappingReferences, + List subclassMappings) { super( method, existingVariableNames, @@ -1659,6 +1756,7 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { } } this.returnTypeToConstruct = returnTypeToConstruct; + this.subclassMappings = subclassMappings; } public List getConstantMappings() { @@ -1669,6 +1767,10 @@ public List getConstructorConstantMappings() { return constructorConstantMappings; } + public List getSubclassMappings() { + return subclassMappings; + } + public List propertyMappingsByParameter(Parameter parameter) { // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value return mappingsByParameter.getOrDefault( parameter.getName(), Collections.emptyList() ); @@ -1683,6 +1785,15 @@ public Type getReturnTypeToConstruct() { return returnTypeToConstruct; } + public boolean hasSubclassMappings() { + return !subclassMappings.isEmpty(); + } + + public boolean isAbstractReturnType() { + return getFactoryMethod() == null && !hasConstructorMappings() && returnTypeToConstruct != null + && returnTypeToConstruct.isAbstract(); + } + public boolean hasConstructorMappings() { return !constructorMappingsByParameter.isEmpty() || !constructorConstantMappings.isEmpty(); } @@ -1702,6 +1813,9 @@ public Set getImportTypes() { types.addAll( propertyMapping.getTargetType().getImportTypes() ); } } + for ( SubclassMapping subclassMapping : subclassMappings ) { + types.addAll( subclassMapping.getImportTypes() ); + } if ( returnTypeToConstruct != null ) { types.addAll( returnTypeToConstruct.getImportTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index b97d8be111..a1f5b091ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; + import javax.lang.model.element.ExecutableElement; import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; @@ -42,6 +43,7 @@ public class ForgedMethod implements Method { private final Method basedOn; private final boolean forgedNameBased; + private MappingMethodOptions options; /** * Creates a new forged method with the given name for mapping a method parameter to a property. @@ -121,6 +123,33 @@ public static ForgedMethod forElementMapping(String name, Type sourceType, Type ); } + /** + * Creates a new forged method for mapping a SubclassMapping element + * + * @param name the (unique name) for this method + * @param sourceType the source type + * @param returnType the return type. + * @param basedOn the method that (originally) triggered this nested method generation. + * @param history a parent forged method if this is a forged method within a forged method + * @param forgedNameBased forges a name based (matched) mapping method + * + * @return a new forge method + */ + public static ForgedMethod forSubclassMapping(String name, Type sourceType, Type returnType, Method basedOn, + MappingReferences mappingReferences, ForgedMethodHistory history, + boolean forgedNameBased) { + return new ForgedMethod( + name, + sourceType, + returnType, + basedOn.getContextParameters(), + basedOn, + history, + mappingReferences == null ? MappingReferences.empty() : mappingReferences, + forgedNameBased + ); + } + private ForgedMethod(String name, Type sourceType, Type returnType, List additionalParameters, Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences, boolean forgedNameBased) { @@ -155,6 +184,8 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List getImportTypes() { + return Collections.singleton( sourceType ); + } + + public AssignmentWrapper getAssignment() { + return new ReturnWrapper( assignment ); + } + + public String getSourceArgument() { + return sourceArgument; + } + + @Override + public boolean equals(final Object other) { + if ( !( other instanceof SubclassMapping ) ) { + return false; + } + SubclassMapping castOther = (SubclassMapping) other; + return Objects.equals( sourceType, castOther.sourceType ) && Objects.equals( targetType, castOther.targetType ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceType, targetType ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.java new file mode 100644 index 0000000000..76e2c19fa7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.assignment; + +import org.mapstruct.ap.internal.model.common.Assignment; + +/** + * Decorates an assignment as a return variable. + * + * @author Ben Zegveld + */ +public class ReturnWrapper extends AssignmentWrapper { + + public ReturnWrapper(Assignment decoratedAssignment) { + super( decoratedAssignment, false ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 9567dd80bf..cc03878362 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -12,18 +12,18 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.gem.ReportingPolicyGem; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; - -import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.internal.gem.SubclassExhaustiveStrategyGem; +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.tools.gem.GemValue; /** @@ -92,6 +92,7 @@ private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method && !gem.nullValueCheckStrategy().hasValue() && !gem.nullValuePropertyMappingStrategy().hasValue() && !gem.nullValueMappingStrategy().hasValue() + && !gem.subclassExhaustiveStrategy().hasValue() && !gem.unmappedTargetPolicy().hasValue() && !gem.ignoreByDefault().hasValue() && !gem.builder().hasValue() ) { @@ -139,6 +140,15 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .orElse( next().getNullValueMappingStrategy() ); } + @Override + public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::subclassExhaustiveStrategy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( SubclassExhaustiveStrategyGem::valueOf ) + .orElse( next().getSubclassExhaustiveStrategy() ); + } + @Override public ReportingPolicyGem unmappedTargetPolicy() { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::unmappedTargetPolicy ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index d52d094930..5a7161b4c8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -9,9 +9,7 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.gem.InjectionStrategyGem; @@ -21,6 +19,9 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.internal.gem.SubclassExhaustiveStrategyGem; +import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.util.ElementUtils; public class DefaultOptions extends DelegatingOptions { @@ -119,6 +120,10 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { return NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().getDefaultValue() ); } + public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { + return SubclassExhaustiveStrategyGem.valueOf( mapper.subclassExhaustiveStrategy().getDefaultValue() ); + } + public BuilderGem getBuilder() { // TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility // but assuming a default @Builder will make testcases fail. Not having a default means that you need to diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 564358ec98..b2b36b68a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -10,7 +10,6 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -20,6 +19,8 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.internal.gem.SubclassExhaustiveStrategyGem; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** @@ -97,6 +98,10 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { return next.getNullValueMappingStrategy(); } + public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { + return next.getSubclassExhaustiveStrategy(); + } + public BuilderGem getBuilder() { return next.getBuilder(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index 7f8df7bf42..5288ab1304 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -19,6 +19,7 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.internal.gem.SubclassExhaustiveStrategyGem; public class MapperConfigOptions extends DelegatingOptions { @@ -126,6 +127,13 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { next().getNullValueMappingStrategy(); } + @Override + public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { + return mapperConfig.subclassExhaustiveStrategy().hasValue() ? + SubclassExhaustiveStrategyGem.valueOf( mapperConfig.subclassExhaustiveStrategy().get() ) : + next().getSubclassExhaustiveStrategy(); + } + @Override public BuilderGem getBuilder() { return mapperConfig.builder().hasValue() ? mapperConfig.builder().get() : next().getBuilder(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 82d17a9846..86aae34052 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -25,6 +25,7 @@ import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; +import org.mapstruct.ap.internal.gem.SubclassExhaustiveStrategyGem; public class MapperOptions extends DelegatingOptions { @@ -155,6 +156,13 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { next().getNullValueMappingStrategy(); } + @Override + public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { + return mapper.subclassExhaustiveStrategy().hasValue() ? + SubclassExhaustiveStrategyGem.valueOf( mapper.subclassExhaustiveStrategy().get() ) : + next().getSubclassExhaustiveStrategy(); + } + @Override public BuilderGem getBuilder() { return mapper.builder().hasValue() ? mapper.builder().get() : next().getBuilder(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 859a4c6f5f..45b1175f8d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -34,7 +34,8 @@ public class MappingMethodOptions { null, null, null, - Collections.emptyList() + Collections.emptyList(), + Collections.emptySet() ); private MapperOptions mapper; @@ -45,12 +46,14 @@ public class MappingMethodOptions { private EnumMappingOptions enumMappingOptions; private List valueMappings; private boolean fullyInitialized; + private Set subclassMapping; public MappingMethodOptions(MapperOptions mapper, Set mappings, IterableMappingOptions iterableMapping, MapMappingOptions mapMapping, BeanMappingOptions beanMapping, EnumMappingOptions enumMappingOptions, - List valueMappings) { + List valueMappings, + Set subclassMapping) { this.mapper = mapper; this.mappings = mappings; this.iterableMapping = iterableMapping; @@ -58,6 +61,7 @@ public MappingMethodOptions(MapperOptions mapper, Set mappings, this.beanMapping = beanMapping; this.enumMappingOptions = enumMappingOptions; this.valueMappings = valueMappings; + this.subclassMapping = subclassMapping; } /** @@ -97,6 +101,10 @@ public List getValueMappings() { return valueMappings; } + public Set getSubclassMappings() { + return subclassMapping; + } + public void setIterableMapping(IterableMappingOptions iterableMapping) { this.iterableMapping = iterableMapping; } @@ -188,6 +196,8 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } } + // Do NOT inherit subclass mapping options!!! + Set newMappings = new LinkedHashSet<>(); for ( MappingOptions mapping : templateOptions.getMappings() ) { if ( isInverse ) { @@ -315,4 +325,21 @@ private String getFirstTargetPropertyName(MappingOptions mapping) { return getPropertyEntries( mapping )[0]; } + /** + * SubclassMappingOptions are not inherited to forged methods. They would result in an infinite loop if they were. + * + * @return a MappingMethodOptions without SubclassMappingOptions. + */ + public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethodOptions options) { + return new MappingMethodOptions( + options.mapper, + options.mappings, + options.iterableMapping, + options.mapMapping, + options.beanMapping, + options.enumMappingOptions, + options.valueMappings, + Collections.emptySet() ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 86f19618d4..5895ecba2a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -95,6 +95,7 @@ public static class Builder { private EnumMappingOptions enumMappingOptions; private ParameterProvidedMethods contextProvidedMethods; private List typeParameters; + private Set subclassMappings; private boolean verboseLogging; @@ -153,6 +154,11 @@ public Builder setEnumMappingOptions(EnumMappingOptions enumMappingOptions) { return this; } + public Builder setSubclassMappings(Set subclassMappings) { + this.subclassMappings = subclassMappings; + return this; + } + public Builder setTypeUtils(TypeUtils typeUtils) { this.typeUtils = typeUtils; return this; @@ -194,6 +200,10 @@ public SourceMethod build() { mappings = Collections.emptySet(); } + if ( subclassMappings == null ) { + subclassMappings = Collections.emptySet(); + } + MappingMethodOptions mappingMethodOptions = new MappingMethodOptions( mapper, mappings, @@ -201,7 +211,8 @@ public SourceMethod build() { mapMapping, beanMapping, enumMappingOptions, - valueMappings + valueMappings, + subclassMappings ); this.typeParameters = this.executable.getTypeParameters() diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java new file mode 100644 index 0000000000..54a0ba4565 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java @@ -0,0 +1,171 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.List; +import java.util.Set; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.gem.SubclassMappingGem; +import org.mapstruct.ap.internal.gem.SubclassMappingsGem; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.TypeUtils; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; + +import static org.mapstruct.ap.internal.util.Message.SUBCLASSMAPPING_ILLEGAL_SUBCLASS; +import static org.mapstruct.ap.internal.util.Message.SUBCLASSMAPPING_NO_VALID_SUPERCLASS; +import static org.mapstruct.ap.internal.util.Message.SUBCLASSMAPPING_UPDATE_METHODS_NOT_SUPPORTED; + +/** + * Represents a subclass mapping as configured via {@code @SubclassMapping}. + * + * @author Ben Zegveld + */ +public class SubclassMappingOptions extends DelegatingOptions { + + private final TypeMirror source; + private final TypeMirror target; + + public SubclassMappingOptions(TypeMirror source, TypeMirror target, DelegatingOptions next) { + super( next ); + this.source = source; + this.target = target; + } + + @Override + public boolean hasAnnotation() { + return source != null && target != null; + } + + private static boolean isConsistent(SubclassMappingGem gem, ExecutableElement method, FormattingMessager messager, + TypeUtils typeUtils, List sourceParameters, Type resultType, + SubclassValidator subclassValidator) { + + if ( resultType == null ) { + messager.printMessage( method, gem.mirror(), SUBCLASSMAPPING_UPDATE_METHODS_NOT_SUPPORTED ); + return false; + } + + TypeMirror sourceSubclass = gem.source().getValue(); + TypeMirror targetSubclass = gem.target().getValue(); + TypeMirror targetParentType = resultType.getTypeMirror(); + validateTypeMirrors( sourceSubclass, targetSubclass, targetParentType ); + + boolean isConsistent = true; + + boolean isChildOfAParameter = false; + for ( Parameter sourceParameter : sourceParameters ) { + TypeMirror sourceParentType = sourceParameter.getType().getTypeMirror(); + validateTypeMirrors( sourceParentType ); + isChildOfAParameter = isChildOfAParameter || isChildOfParent( typeUtils, sourceSubclass, sourceParentType ); + } + if ( !isChildOfAParameter ) { + messager + .printMessage( + method, + gem.mirror(), + SUBCLASSMAPPING_NO_VALID_SUPERCLASS, + sourceSubclass.toString() ); + isConsistent = false; + } + if ( !isChildOfParent( typeUtils, targetSubclass, targetParentType ) ) { + messager + .printMessage( + method, + gem.mirror(), + SUBCLASSMAPPING_ILLEGAL_SUBCLASS, + targetParentType.toString(), + targetSubclass.toString() ); + isConsistent = false; + } + subclassValidator.isInCorrectOrder( method, gem.mirror(), targetSubclass ); + return isConsistent; + } + + private static void validateTypeMirrors(TypeMirror... typeMirrors) { + for ( TypeMirror typeMirror : typeMirrors ) { + if ( typeMirror == null ) { + // When a class used in uses or imports is created by another annotation processor + // then javac will not return correct TypeMirror with TypeKind#ERROR, but rather a string "" + // the gem tools would return a null TypeMirror in that case. + // Therefore throw TypeHierarchyErroneousException so we can postpone the generation of the mapper + throw new TypeHierarchyErroneousException( typeMirror ); + } + } + } + + private static boolean isChildOfParent(TypeUtils typeUtils, TypeMirror childType, TypeMirror parentType) { + return typeUtils.isSubtype( childType, parentType ); + } + + public TypeMirror getSource() { + return source; + } + + public TypeMirror getTarget() { + return target; + } + + public static void addInstances(SubclassMappingsGem gem, ExecutableElement method, + BeanMappingOptions beanMappingOptions, FormattingMessager messager, + TypeUtils typeUtils, Set mappings, + List sourceParameters, Type resultType) { + SubclassValidator subclassValidator = new SubclassValidator( messager, typeUtils ); + for ( SubclassMappingGem subclassMappingGem : gem.value().get() ) { + addAndValidateInstance( + subclassMappingGem, + method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType, + subclassValidator ); + } + } + + public static void addInstance(SubclassMappingGem subclassMapping, ExecutableElement method, + BeanMappingOptions beanMappingOptions, FormattingMessager messager, + TypeUtils typeUtils, Set mappings, + List sourceParameters, Type resultType) { + addAndValidateInstance( + subclassMapping, + method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType, + new SubclassValidator( messager, typeUtils ) ); + } + + private static void addAndValidateInstance(SubclassMappingGem subclassMapping, ExecutableElement method, + BeanMappingOptions beanMappingOptions, FormattingMessager messager, + TypeUtils typeUtils, Set mappings, + List sourceParameters, Type resultType, + SubclassValidator subclassValidator) { + if ( !isConsistent( + subclassMapping, + method, + messager, + typeUtils, + sourceParameters, + resultType, + subclassValidator ) ) { + return; + } + + TypeMirror sourceSubclass = subclassMapping.source().getValue(); + TypeMirror targetSubclass = subclassMapping.target().getValue(); + + mappings.add( new SubclassMappingOptions( sourceSubclass, targetSubclass, beanMappingOptions ) ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java new file mode 100644 index 0000000000..dd79ba0c02 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.ArrayList; +import java.util.List; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; + +/** + * Handles the validation of multiple @SubclassMapping annotations on the same method. + * + * @author Ben Zegveld + */ +class SubclassValidator { + + private final FormattingMessager messager; + private final List handledSubclasses = new ArrayList<>(); + private final TypeUtils typeUtils; + + SubclassValidator(FormattingMessager messager, TypeUtils typeUtils) { + this.messager = messager; + this.typeUtils = typeUtils; + } + + public boolean isInCorrectOrder(Element e, AnnotationMirror annotation, TypeMirror sourceType) { + for ( TypeMirror typeMirror : handledSubclasses ) { + if ( typeUtils.isAssignable( sourceType, typeMirror ) ) { + messager + .printMessage( + e, + annotation, + Message.SUBCLASSMAPPING_ILLOGICAL_ORDER, + sourceType, + typeMirror, + sourceType, + typeMirror ); + return true; + } + } + handledSubclasses.add( sourceType ); + return false; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index c6e510d315..9bf55e731f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -29,6 +29,8 @@ import org.mapstruct.ap.internal.gem.MappingGem; import org.mapstruct.ap.internal.gem.MappingsGem; import org.mapstruct.ap.internal.gem.ObjectFactoryGem; +import org.mapstruct.ap.internal.gem.SubclassMappingGem; +import org.mapstruct.ap.internal.gem.SubclassMappingsGem; import org.mapstruct.ap.internal.gem.ValueMappingGem; import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.model.common.Parameter; @@ -42,6 +44,7 @@ import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SourceMethod; +import org.mapstruct.ap.internal.model.source.SubclassMappingOptions; import org.mapstruct.ap.internal.model.source.ValueMappingOptions; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; @@ -52,6 +55,7 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumTransformationStrategy; +import org.mapstruct.tools.gem.Gem; /** * A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s @@ -67,6 +71,8 @@ public class MethodRetrievalProcessor implements ModelElementProcessor mappingOptions = - getMappings( method, method, beanMappingOptions, new LinkedHashSet<>(), new HashSet<>() ); + RepeatableMappings repeatableMappings = new RepeatableMappings(); + Set mappingOptions = repeatableMappings.getMappings( method, beanMappingOptions ); IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromGem( IterableMappingGem.instanceOn( method ), @@ -299,6 +305,15 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, messager ); + // We want to get as much error reporting as possible. + // If targetParameter is not null it means we have an update method + Set subclassMappingOptions = getSubclassMappings( + sourceParameters, + targetParameter != null ? null : resultType, + method, + beanMappingOptions + ); + return new SourceMethod.Builder() .setExecutable( method ) .setParameters( parameters ) @@ -311,6 +326,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setMapMappingOptions( mapMappingOptions ) .setValueMappingOptionss( getValueMappings( method ) ) .setEnumMappingOptions( enumMappingOptions ) + .setSubclassMappings( subclassMappingOptions ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) .setPrototypeMethods( prototypeMethods ) @@ -554,56 +570,189 @@ private boolean isStreamTypeOrIterableFromJavaStdLib(Type type) { } /** - * Retrieves the mappings configured via {@code @Mapping} from the given - * method. + * Retrieves the mappings configured via {@code @Mapping} from the given method. * * @param method The method of interest - * @param element Element of interest: method, or (meta) annotation * @param beanMapping options coming from bean mapping method - * @param mappingOptions LinkedSet of mappings found so far - * * @return The mappings for the given method, keyed by target property name */ - private Set getMappings(ExecutableElement method, Element element, - BeanMappingOptions beanMapping, Set mappingOptions, - Set handledElements) { - - for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { - Element lElement = annotationMirror.getAnnotationType().asElement(); - if ( isAnnotation( lElement, MAPPING_FQN ) ) { - // although getInstanceOn does a search on annotation mirrors, the order is preserved - MappingGem mapping = MappingGem.instanceOn( element ); - MappingOptions.addInstance( mapping, method, beanMapping, messager, typeUtils, mappingOptions ); - } - else if ( isAnnotation( lElement, MAPPINGS_FQN ) ) { - // although getInstanceOn does a search on annotation mirrors, the order is preserved - MappingsGem mappings = MappingsGem.instanceOn( element ); - MappingOptions.addInstances( mappings, method, beanMapping, messager, typeUtils, mappingOptions ); - } - else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) - && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG ) - && !handledElements.contains( lElement ) - ) { - // recur over annotation mirrors - handledElements.add( lElement ); - getMappings( method, lElement, beanMapping, mappingOptions, handledElements ); - } + private Set getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { + return new RepeatableMappings().getMappings( method, beanMapping ); + } + + /** + * Retrieves the subclass mappings configured via {@code @SubclassMapping} from the given method. + * + * @param method The method of interest + * @param beanMapping options coming from bean mapping method + * + * @return The subclass mappings for the given method + */ + private Set getSubclassMappings(List sourceParameters, Type resultType, + ExecutableElement method, BeanMappingOptions beanMapping) { + return new RepeatableSubclassMappings( sourceParameters, resultType ).getMappings( method, beanMapping ); + } + + private class RepeatableMappings extends RepeatableMappingAnnotations { + RepeatableMappings() { + super( MAPPING_FQN, MAPPINGS_FQN ); + } + + @Override + MappingGem singularInstanceOn(Element element) { + return MappingGem.instanceOn( element ); + } + + @Override + MappingsGem multipleInstanceOn(Element element) { + return MappingsGem.instanceOn( element ); + } + + @Override + void addInstance(MappingGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings) { + MappingOptions.addInstance( gem, method, beanMappingOptions, messager, typeUtils, mappings ); + } + + @Override + void addInstances(MappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings) { + MappingOptions.addInstances( gem, method, beanMappingOptions, messager, typeUtils, mappings ); } - return mappingOptions; } - private boolean isAnnotationInPackage(Element element, String packageFQN ) { - if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { - return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); + private class RepeatableSubclassMappings + extends RepeatableMappingAnnotations { + private final List sourceParameters; + private final Type resultType; + + RepeatableSubclassMappings(List sourceParameters, Type resultType) { + super( SUB_CLASS_MAPPING_FQN, SUB_CLASS_MAPPINGS_FQN ); + this.sourceParameters = sourceParameters; + this.resultType = resultType; + } + + @Override + SubclassMappingGem singularInstanceOn(Element element) { + return SubclassMappingGem.instanceOn( element ); + } + + @Override + SubclassMappingsGem multipleInstanceOn(Element element) { + return SubclassMappingsGem.instanceOn( element ); + } + + @Override + void addInstance(SubclassMappingGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings) { + SubclassMappingOptions + .addInstance( + gem, + method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType ); + } + + @Override + void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings) { + SubclassMappingOptions + .addInstances( + gem, + method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType ); } - return false; } - private boolean isAnnotation(Element element, String annotationFQN) { - if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { - return annotationFQN.equals( ( (TypeElement) element ).getQualifiedName().toString() ); + private abstract class RepeatableMappingAnnotations { + + private final String singularFqn; + private final String multipleFqn; + + RepeatableMappingAnnotations(String singularFqn, String multipleFqn) { + this.singularFqn = singularFqn; + this.multipleFqn = multipleFqn; + } + + abstract SINGULAR singularInstanceOn(Element element); + + abstract MULTIPLE multipleInstanceOn(Element element); + + abstract void addInstance(SINGULAR gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings); + + abstract void addInstances(MULTIPLE gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, + Set mappings); + + /** + * Retrieves the mappings configured via {@code @Mapping} from the given method. + * + * @param method The method of interest + * @param beanMapping options coming from bean mapping method + * @return The mappings for the given method, keyed by target property name + */ + public Set getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { + return getMappings( method, method, beanMapping, new LinkedHashSet<>(), new HashSet<>() ); + } + + /** + * Retrieves the mappings configured via {@code @Mapping} from the given method. + * + * @param method The method of interest + * @param element Element of interest: method, or (meta) annotation + * @param beanMapping options coming from bean mapping method + * @param mappingOptions LinkedSet of mappings found so far + * @return The mappings for the given method, keyed by target property name + */ + private Set getMappings(ExecutableElement method, Element element, + BeanMappingOptions beanMapping, LinkedHashSet mappingOptions, + Set handledElements) { + + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + Element lElement = annotationMirror.getAnnotationType().asElement(); + if ( isAnnotation( lElement, singularFqn ) ) { + // although getInstanceOn does a search on annotation mirrors, the order is preserved + SINGULAR mapping = singularInstanceOn( element ); + addInstance( mapping, method, beanMapping, mappingOptions ); + } + else if ( isAnnotation( lElement, multipleFqn ) ) { + // although getInstanceOn does a search on annotation mirrors, the order is preserved + MULTIPLE mappings = multipleInstanceOn( element ); + addInstances( mappings, method, beanMapping, mappingOptions ); + } + else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) + && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG ) + && !handledElements.contains( lElement ) ) { + // recur over annotation mirrors + handledElements.add( lElement ); + getMappings( method, lElement, beanMapping, mappingOptions, handledElements ); + } + } + return mappingOptions; + } + + private boolean isAnnotationInPackage(Element element, String packageFQN) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); + } + return false; + } + + private boolean isAnnotation(Element element, String annotationFQN) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return annotationFQN.equals( ( (TypeElement) element ).getQualifiedName().toString() ); + } + return false; } - return false; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 8d328d4796..66b37de7a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -114,6 +114,11 @@ public enum Message { ENUMMAPPING_NO_ELEMENTS( "'nameTransformationStrategy', 'configuration' and 'unexpectedValueMappingException' are undefined in @EnumMapping, define at least one of them." ), ENUMMAPPING_ILLEGAL_TRANSFORMATION( "Illegal transformation for '%s' EnumTransformationStrategy. Error: '%s'." ), + SUBCLASSMAPPING_ILLEGAL_SUBCLASS( "Class '%s' is not a subclass of '%s'." ), + SUBCLASSMAPPING_NO_VALID_SUPERCLASS( "Could not find a parameter that is a superclass for '%s'." ), + SUBCLASSMAPPING_UPDATE_METHODS_NOT_SUPPORTED( "SubclassMapping annotation can not be used for update methods." ), + SUBCLASSMAPPING_ILLOGICAL_ORDER( "SubclassMapping annotation for '%s' found after '%s', but all '%s' objects are also instances of '%s'.", Diagnostic.Kind.WARNING ), + LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS( "Lifecycle method has multiple matching parameters (e. g. same type), in this case please ensure to name the parameters in the lifecycle and mapping method identical. This lifecycle method will not be used for the mapping method '%s'.", Diagnostic.Kind.WARNING), DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ), @@ -188,7 +193,6 @@ public enum Message { ; // CHECKSTYLE:ON - private final String description; private final Diagnostic.Kind kind; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index f5d6e799e1..12a03c06ca 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -24,6 +24,17 @@ } + <#if hasSubclassMappings()> + <#list subclassMappings as subclass> + <#if subclass_index > 0>else if (${subclass.sourceArgument} instanceof <@includeModel object=subclass.sourceType/>) { + <@includeModel object=subclass.assignment existingInstanceMapping=existingInstanceMapping/> + } + + else { + + <#if isAbstractReturnType()> + throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + ${subclassMappings[0].sourceArgument}.getClass()); + <#else> <#if !existingInstanceMapping> <#if hasConstructorMappings()> <#if (sourceParameters?size > 1)> @@ -120,6 +131,10 @@ return ${resultName}; + + <#if hasSubclassMappings()> + } + } <#macro throws> <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl new file mode 100644 index 0000000000..9f46f3604f --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl @@ -0,0 +1,17 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.ReturnWrapper" --> +return <@_assignment/>; +<#macro _assignment> + <@includeModel object=assignment + targetBeanName=ext.targetBeanName + existingInstanceMapping=ext.existingInstanceMapping + targetReadAccessorName=ext.targetReadAccessorName + targetWriteAccessorName=ext.targetWriteAccessorName + targetType=ext.targetType/> + diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassMapper1.java new file mode 100644 index 0000000000..fc5e37d7b5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassMapper1.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousSubclassMapper1 { + ErroneousSubclassMapper1 INSTANCE = Mappers.getMapper( ErroneousSubclassMapper1.class ); + + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + @Mapping( target = "maker", ignore = true ) + CarDto map(Car vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassUpdateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassUpdateMapper.java new file mode 100644 index 0000000000..b002b1e32d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousSubclassUpdateMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousSubclassUpdateMapper { + ErroneousSubclassUpdateMapper INSTANCE = Mappers.getMapper( ErroneousSubclassUpdateMapper.class ); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker" ) + void map(@MappingTarget VehicleDto target, Car vehicle); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker" ) + VehicleDto mapWithReturnType(@MappingTarget VehicleDto target, Car vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/MappingInheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/MappingInheritanceTest.java new file mode 100644 index 0000000000..4cedd30510 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/MappingInheritanceTest.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.assertj.core.api.Assertions; +import org.mapstruct.ap.test.subclassmapping.mappables.Source; +import org.mapstruct.ap.test.subclassmapping.mappables.SourceSubclass; +import org.mapstruct.ap.test.subclassmapping.mappables.Target; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.factory.Mappers; + +@IssueKey( "2438" ) +@WithClasses( { Source.class, SourceSubclass.class, Target.class } ) +class MappingInheritanceTest { + + @ProcessorTest + @WithClasses( { SubclassMapper.class } ) + void inheritance() { + SubclassMapper mapper = Mappers.getMapper( SubclassMapper.class ); + SourceSubclass sourceSubclass = new SourceSubclass( "f1", "f2", "f3", "f4", "f5" ); + + Target result = mapper.mapSuperclass( sourceSubclass ); + + Assertions.assertThat( result.getTarget1() ).isEqualTo( "f1" ); + Assertions.assertThat( result.getTarget2() ).isEqualTo( "f2" ); + Assertions.assertThat( result.getTarget3() ).isEqualTo( "f3" ); + Assertions.assertThat( result.getTarget4() ).isEqualTo( "f4" ); + Assertions.assertThat( result.getTarget5() ).isEqualTo( "f5" ); + } + + @ProcessorTest + @WithClasses( { SubclassMapper.class } ) + void superclass() { + SubclassMapper mapper = Mappers.getMapper( SubclassMapper.class ); + Source source = new Source( "f1", "f2", "f3" ); + + Target result = mapper.mapSuperclass( source ); + + Assertions.assertThat( result.getTarget1() ).isEqualTo( "f1" ); + Assertions.assertThat( result.getTarget2() ).isEqualTo( "f2" ); + Assertions.assertThat( result.getTarget3() ).isEqualTo( "f3" ); + Assertions.assertThat( result.getTarget4() ).isNull(); + Assertions.assertThat( result.getTarget5() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java new file mode 100644 index 0000000000..eb71797864 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SimpleSubclassMapper { + SimpleSubclassMapper INSTANCE = Mappers.getMapper( SimpleSubclassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapper.java new file mode 100644 index 0000000000..8e77297dda --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Source; +import org.mapstruct.ap.test.subclassmapping.mappables.SourceSubclass; +import org.mapstruct.ap.test.subclassmapping.mappables.Target; + +@Mapper +public interface SubclassMapper { + + @SubclassMapping( source = SourceSubclass.class, target = Target.class ) + @Mapping( target = "target1", source = "property1" ) + @Mapping( target = "target2", source = "property2" ) + @Mapping( target = "target3", source = "property3" ) + @Mapping( target = "target4", ignore = true ) + @Mapping( target = "target5", ignore = true ) + Target mapSuperclass(Source source); + + @InheritConfiguration( name = "mapSuperclass" ) + @Mapping( target = "target4", source = "subclassProperty" ) + @Mapping( target = "target5" ) // Have to declare in order to override ignore with default behavior + Target mapSubclass(SourceSubclass source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapperUsingExistingMappings.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapperUsingExistingMappings.java new file mode 100644 index 0000000000..efdd357e3d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMapperUsingExistingMappings.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper( unmappedTargetPolicy = ReportingPolicy.IGNORE ) +public interface SubclassMapperUsingExistingMappings { + SubclassMapperUsingExistingMappings INSTANCE = Mappers.getMapper( SubclassMapperUsingExistingMappings.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + default CarDto existingMappingMethod(Car domain) { + CarDto dto = new CarDto(); + dto.setName( "created through existing mapping." ); + return dto; + } + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + VehicleDto map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java new file mode 100644 index 0000000000..e5a77b56d3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -0,0 +1,139 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBack; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("131") +@WithClasses({ + Bike.class, + BikeDto.class, + Car.class, + CarDto.class, + VehicleCollection.class, + VehicleCollectionDto.class, + Vehicle.class, + VehicleDto.class, + SimpleSubclassMapper.class, + SubclassMapperUsingExistingMappings.class, +}) +public class SubclassMappingTest { + + @ProcessorTest + void mappingIsDoneUsingSubclassMapping() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Bike() ); + + VehicleCollectionDto result = SimpleSubclassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( CarDto.class, BikeDto.class ); + } + + @ProcessorTest + void existingMappingsAreUsedWhenFound() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + + VehicleCollectionDto result = SubclassMapperUsingExistingMappings.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ) + .extracting( VehicleDto::getName ) + .containsExactly( "created through existing mapping." ); + } + + @ProcessorTest + void subclassMappingInheritsMapping() { + VehicleCollection vehicles = new VehicleCollection(); + Car car = new Car(); + car.setVehicleManufacturingCompany( "BenZ" ); + vehicles.getVehicles().add( car ); + + VehicleCollectionDto result = SimpleSubclassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ) + .extracting( VehicleDto::getMaker ) + .containsExactly( "BenZ" ); + } + + @ProcessorTest + @WithClasses({ + HatchBack.class, + HatchBackDto.class, + SubclassOrderWarningMapper.class, + }) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { + @Diagnostic(type = SubclassOrderWarningMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 28, + alternativeLine = 30, + message = "SubclassMapping annotation for " + + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto' found after " + + "'org.mapstruct.ap.test.subclassmapping.mappables.CarDto', but all " + + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto' " + + "objects are also instances of " + + "'org.mapstruct.ap.test.subclassmapping.mappables.CarDto'.") + }) + void subclassOrderWarning() { + } + + @ProcessorTest + @WithClasses({ ErroneousSubclassUpdateMapper.class }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(type = ErroneousSubclassUpdateMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 21, + message = "SubclassMapping annotation can not be used for update methods." + ), + @Diagnostic(type = ErroneousSubclassUpdateMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 25, + message = "SubclassMapping annotation can not be used for update methods." + ) + }) + void unsupportedUpdateMethod() { + } + + @ProcessorTest + @WithClasses({ ErroneousSubclassMapper1.class }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(type = ErroneousSubclassMapper1.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 21, + message = "Could not find a parameter that is a superclass for " + + "'org.mapstruct.ap.test.subclassmapping.mappables.Bike'." + ), + @Diagnostic(type = ErroneousSubclassMapper1.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 21, + message = "Class 'org.mapstruct.ap.test.subclassmapping.mappables.CarDto'" + + " is not a subclass of " + + "'org.mapstruct.ap.test.subclassmapping.mappables.BikeDto'." + ) + }) + void erroneousMethodWithSourceTargetType() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassOrderWarningMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassOrderWarningMapper.java new file mode 100644 index 0000000000..2ff7a7d836 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassOrderWarningMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBack; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SubclassOrderWarningMapper { + SubclassOrderWarningMapper INSTANCE = Mappers.getMapper( SubclassOrderWarningMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = HatchBack.class, target = HatchBackDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractSuperClassTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractSuperClassTest.java new file mode 100644 index 0000000000..31fbf1e00e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractSuperClassTest.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@IssueKey("366") +@WithClasses({ + AbstractVehicle.class, + VehicleCollection.class, + Bike.class, + BikeDto.class, + Car.class, + CarDto.class, + VehicleCollectionDto.class, + VehicleDto.class, +}) +public class AbstractSuperClassTest { + + @ProcessorTest + @WithClasses( SubclassWithAbstractSuperClassMapper.class ) + void downcastMappingInCollection() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Bike() ); + + VehicleCollectionDto result = SubclassWithAbstractSuperClassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( CarDto.class, BikeDto.class ); + } + + @ProcessorTest + @WithClasses( SubclassWithAbstractSuperClassMapper.class ) + void mappingOfUnknownChildThrowsIllegalArgumentException() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Motorcycle() ); + + assertThatThrownBy( () -> SubclassWithAbstractSuperClassMapper.INSTANCE.map( vehicles ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Not all subclasses are supported for this mapping. " + + "Missing for class org.mapstruct.ap.test.subclassmapping.abstractsuperclass.Motorcycle" ); + } + + @WithClasses( ErroneousSubclassWithAbstractSuperClassMapper.class ) + @ProcessorTest + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(type = ErroneousSubclassWithAbstractSuperClassMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + message = "The return type VehicleDto is an abstract class or interface. " + + "Provide a non abstract / non interface result type or a factory method.") + }) + void compileErrorWithAbstractClass() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractVehicle.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractVehicle.java new file mode 100644 index 0000000000..7cb155c402 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/AbstractVehicle.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public abstract class AbstractVehicle { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Bike.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Bike.java new file mode 100644 index 0000000000..72a84f629e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Bike.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class Bike extends AbstractVehicle { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/BikeDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/BikeDto.java new file mode 100644 index 0000000000..8950e26086 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/BikeDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class BikeDto extends VehicleDto { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Car.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Car.java new file mode 100644 index 0000000000..acd7e85f99 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Car.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class Car extends AbstractVehicle { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CarDto.java new file mode 100644 index 0000000000..6353b4c590 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CarDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class CarDto extends VehicleDto { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/ErroneousSubclassWithAbstractSuperClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/ErroneousSubclassWithAbstractSuperClassMapper.java new file mode 100644 index 0000000000..a3406bff08 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/ErroneousSubclassWithAbstractSuperClassMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper( subclassExhaustiveStrategy = SubclassExhaustiveStrategy.COMPILE_ERROR ) +public interface ErroneousSubclassWithAbstractSuperClassMapper { + ErroneousSubclassWithAbstractSuperClassMapper INSTANCE = + Mappers.getMapper( ErroneousSubclassWithAbstractSuperClassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + CarDto map(Car car); + + BikeDto map(Bike bike); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + VehicleDto map(AbstractVehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Motorcycle.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Motorcycle.java new file mode 100644 index 0000000000..f52edfd71f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/Motorcycle.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class Motorcycle extends AbstractVehicle { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MotorcycleDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MotorcycleDto.java new file mode 100644 index 0000000000..cada5e8e65 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MotorcycleDto.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class MotorcycleDto extends VehicleDto { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/SubclassWithAbstractSuperClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/SubclassWithAbstractSuperClassMapper.java new file mode 100644 index 0000000000..b0185f1f87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/SubclassWithAbstractSuperClassMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper( subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION ) +public interface SubclassWithAbstractSuperClassMapper { + SubclassWithAbstractSuperClassMapper INSTANCE = Mappers.getMapper( SubclassWithAbstractSuperClassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + CarDto map(Car car); + + BikeDto map(Bike bike); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + VehicleDto map(AbstractVehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollection.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollection.java new file mode 100644 index 0000000000..cbc847ff42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollection.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollection { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollectionDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollectionDto.java new file mode 100644 index 0000000000..1ea4e018a5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleCollectionDto.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollectionDto { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleDto.java new file mode 100644 index 0000000000..5f38db68d2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/VehicleDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public abstract class VehicleDto { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java new file mode 100644 index 0000000000..7f9f19a2ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public abstract class AbstractParentSource { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java new file mode 100644 index 0000000000..3215aee644 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public abstract class AbstractParentTarget { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java new file mode 100644 index 0000000000..94dde481b0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class ImplementedParentSource extends AbstractParentSource { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java new file mode 100644 index 0000000000..7f3d254e21 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class ImplementedParentTarget extends AbstractParentTarget { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentSource.java new file mode 100644 index 0000000000..b1ad034102 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentSource.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public interface InterfaceParentSource { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentTarget.java new file mode 100644 index 0000000000..0e41f58b36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/InterfaceParentTarget.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public interface InterfaceParentTarget { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSource.java new file mode 100644 index 0000000000..abb4c0dfba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSource.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubSource extends ImplementedParentSource implements InterfaceParentSource { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOther.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOther.java new file mode 100644 index 0000000000..6b83b78973 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOther.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubSourceOther extends ImplementedParentSource implements InterfaceParentSource { + private final String finalValue; + + public SubSourceOther(String finalValue) { + this.finalValue = finalValue; + } + + public String getFinalValue() { + return finalValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTarget.java new file mode 100644 index 0000000000..0227ec325d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTarget.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubTarget extends ImplementedParentTarget implements InterfaceParentTarget { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetOther.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetOther.java new file mode 100644 index 0000000000..f77c7c7a24 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetOther.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubTargetOther extends ImplementedParentTarget implements InterfaceParentTarget { + private final String finalValue; + + public SubTargetOther(String finalValue) { + this.finalValue = finalValue; + } + + public String getFinalValue() { + return finalValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java new file mode 100644 index 0000000000..8ef7908c30 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; + +import static org.mapstruct.SubclassExhaustiveStrategy.RUNTIME_EXCEPTION; + +@Mapper +public interface SubclassAbstractMapper { + + @BeanMapping( subclassExhaustiveStrategy = RUNTIME_EXCEPTION ) + @SubclassMapping( source = SubSource.class, target = SubTarget.class ) + @SubclassMapping( source = SubSourceOther.class, target = SubTargetOther.class ) + AbstractParentTarget map(AbstractParentSource item); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java new file mode 100644 index 0000000000..14dc16d4ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +@WithClasses({ + AbstractParentSource.class, + AbstractParentTarget.class, + ImplementedParentSource.class, + ImplementedParentTarget.class, + InterfaceParentSource.class, + InterfaceParentTarget.class, + SubSource.class, + SubSourceOther.class, + SubTarget.class, + SubTargetOther.class, +}) +public class SubclassFixtureTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses( { + SubclassInterfaceMapper.class, + } ) + void subclassInterfaceParentFixture() { + generatedSource.addComparisonToFixtureFor( SubclassInterfaceMapper.class ); + } + + @ProcessorTest + @WithClasses( { + SubclassAbstractMapper.class, + } ) + void subclassAbstractParentFixture() { + generatedSource.addComparisonToFixtureFor( SubclassAbstractMapper.class ); + } + + @ProcessorTest + @WithClasses( { + SubclassImplementedMapper.class, + } ) + void subclassImplementationParentFixture() { + generatedSource.addComparisonToFixtureFor( SubclassImplementedMapper.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapper.java new file mode 100644 index 0000000000..0ebb2a26ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; + +@Mapper +public interface SubclassImplementedMapper { + + @SubclassMapping( source = SubSource.class, target = SubTarget.class ) + @SubclassMapping( source = SubSourceOther.class, target = SubTargetOther.class ) + ImplementedParentTarget map(ImplementedParentSource item); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapper.java new file mode 100644 index 0000000000..ac7acaafdb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; + +import static org.mapstruct.SubclassExhaustiveStrategy.RUNTIME_EXCEPTION; + +@Mapper( subclassExhaustiveStrategy = RUNTIME_EXCEPTION ) +public interface SubclassInterfaceMapper { + + @SubclassMapping( source = SubSource.class, target = SubTarget.class ) + @SubclassMapping( source = SubSourceOther.class, target = SubTargetOther.class ) + InterfaceParentTarget map(InterfaceParentSource item); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Bike.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Bike.java new file mode 100644 index 0000000000..b414f733c4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Bike.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class Bike extends Vehicle { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/BikeDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/BikeDto.java new file mode 100644 index 0000000000..0eefc8f0c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/BikeDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class BikeDto extends VehicleDto { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java new file mode 100644 index 0000000000..71b2446d34 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class Car extends Vehicle { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/CarDto.java new file mode 100644 index 0000000000..bfaba22685 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/CarDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class CarDto extends VehicleDto { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBack.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBack.java new file mode 100644 index 0000000000..d03a57aa30 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBack.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class HatchBack extends Car { + private String doorType; + + public String getDoorType() { + return doorType; + } + + public void setDoorType(String doorType) { + this.doorType = doorType; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBackDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBackDto.java new file mode 100644 index 0000000000..6ec4d90f1b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/HatchBackDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class HatchBackDto extends CarDto { + private String doorType; + + public String getDoorType() { + return doorType; + } + + public void setDoorType(String doorType) { + this.doorType = doorType; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Source.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Source.java new file mode 100644 index 0000000000..52f07943ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Source.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class Source { + private String property1; + private String property2; + private String property3; + + public Source(String prop1, String prop2, String prop3) { + setProperty1( prop1 ); + setProperty2( prop2 ); + setProperty3( prop3 ); + } + + public String getProperty1() { + return property1; + } + + public String getProperty2() { + return property2; + } + + public String getProperty3() { + return property3; + } + + public void setProperty1(String property1) { + this.property1 = property1; + } + + public void setProperty2(String property2) { + this.property2 = property2; + } + + public void setProperty3(String property3) { + this.property3 = property3; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/SourceSubclass.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/SourceSubclass.java new file mode 100644 index 0000000000..600d4f383e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/SourceSubclass.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class SourceSubclass extends Source { + private String subclassProperty; + private String target5; + + public SourceSubclass(String prop1, String prop2, String prop3, String subProp, String target5) { + super( prop1, prop2, prop3 ); + setSubclassProperty( subProp ); + setTarget5( target5 ); + } + + public String getSubclassProperty() { + return subclassProperty; + } + + public String getTarget5() { + return target5; + } + + public void setSubclassProperty(String subclassProperty) { + this.subclassProperty = subclassProperty; + } + + public void setTarget5(String target5) { + this.target5 = target5; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Target.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Target.java new file mode 100644 index 0000000000..cb5e3d6bc3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Target.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class Target { + private String target1; + private String target2; + private String target3; + private String target4; + private String target5; + + public String getTarget1() { + return target1; + } + + public String getTarget2() { + return target2; + } + + public String getTarget3() { + return target3; + } + + public String getTarget4() { + return target4; + } + + public String getTarget5() { + return target5; + } + + public void setTarget1(String target1) { + this.target1 = target1; + } + + public void setTarget2(String target2) { + this.target2 = target2; + } + + public void setTarget3(String target3) { + this.target3 = target3; + } + + public void setTarget4(String target4) { + this.target4 = target4; + } + + public void setTarget5(String target5) { + this.target5 = target5; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Vehicle.java new file mode 100644 index 0000000000..9c3406fe53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Vehicle.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class Vehicle { + private String name; + private String vehicleManufacturingCompany; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVehicleManufacturingCompany() { + return vehicleManufacturingCompany; + } + + public void setVehicleManufacturingCompany(String vehicleManufacturingCompany) { + this.vehicleManufacturingCompany = vehicleManufacturingCompany; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollection.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollection.java new file mode 100644 index 0000000000..af4efbaef4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollection.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollection { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollectionDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollectionDto.java new file mode 100644 index 0000000000..9f06ee4b72 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleCollectionDto.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollectionDto { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleDto.java new file mode 100644 index 0000000000..fb6b40e93b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/VehicleDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.mappables; + +public class VehicleDto { + private String name; + private String maker; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMaker() { + return maker; + } + + public void setMaker(String maker) { + this.maker = maker; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java new file mode 100644 index 0000000000..6deed338c1 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-09-12T14:37:10+0200", + comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 11.0.12 (Azul Systems, Inc.)" +) +public class SubclassAbstractMapperImpl implements SubclassAbstractMapper { + + @Override + public AbstractParentTarget map(AbstractParentSource item) { + if ( item == null ) { + return null; + } + + if (item instanceof SubSource) { + return subSourceToSubTarget( (SubSource) item ); + } + else if (item instanceof SubSourceOther) { + return subSourceOtherToSubTargetOther( (SubSourceOther) item ); + } + else { + throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + item.getClass()); + } + } + + protected SubTarget subSourceToSubTarget(SubSource subSource) { + if ( subSource == null ) { + return null; + } + + SubTarget subTarget = new SubTarget(); + + subTarget.setValue( subSource.getValue() ); + + return subTarget; + } + + protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSourceOther) { + if ( subSourceOther == null ) { + return null; + } + + String finalValue = null; + + finalValue = subSourceOther.getFinalValue(); + + SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + + return subTargetOther; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java new file mode 100644 index 0000000000..444b012078 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-09-12T14:37:10+0200", + comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 11.0.12 (Azul Systems, Inc.)" +) +public class SubclassImplementedMapperImpl implements SubclassImplementedMapper { + + @Override + public ImplementedParentTarget map(ImplementedParentSource item) { + if ( item == null ) { + return null; + } + + if (item instanceof SubSource) { + return subSourceToSubTarget( (SubSource) item ); + } + else if (item instanceof SubSourceOther) { + return subSourceOtherToSubTargetOther( (SubSourceOther) item ); + } + else { + ImplementedParentTarget implementedParentTarget = new ImplementedParentTarget(); + + return implementedParentTarget; + } + } + + protected SubTarget subSourceToSubTarget(SubSource subSource) { + if ( subSource == null ) { + return null; + } + + SubTarget subTarget = new SubTarget(); + + subTarget.setValue( subSource.getValue() ); + + return subTarget; + } + + protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSourceOther) { + if ( subSourceOther == null ) { + return null; + } + + String finalValue = null; + + finalValue = subSourceOther.getFinalValue(); + + SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + + return subTargetOther; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java new file mode 100644 index 0000000000..8366d53ea9 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-09-12T14:37:10+0200", + comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 11.0.12 (Azul Systems, Inc.)" +) +public class SubclassInterfaceMapperImpl implements SubclassInterfaceMapper { + + @Override + public InterfaceParentTarget map(InterfaceParentSource item) { + if ( item == null ) { + return null; + } + + if (item instanceof SubSource) { + return subSourceToSubTarget( (SubSource) item ); + } + else if (item instanceof SubSourceOther) { + return subSourceOtherToSubTargetOther( (SubSourceOther) item ); + } + else { + throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + item.getClass()); + } + } + + protected SubTarget subSourceToSubTarget(SubSource subSource) { + if ( subSource == null ) { + return null; + } + + SubTarget subTarget = new SubTarget(); + + subTarget.setValue( subSource.getValue() ); + + return subTarget; + } + + protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSourceOther) { + if ( subSourceOther == null ) { + return null; + } + + String finalValue = null; + + finalValue = subSourceOther.getFinalValue(); + + SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + + return subTargetOther; + } +} From e86c0faf04109a99ac4049ce9c510653ce973f11 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 16 Oct 2021 19:10:40 +0200 Subject: [PATCH 0613/1006] #2611 Scope org.eclipse.tycho:tycho-compiler-jdt under test Since the removal of the Eclipse Specific compiler workarounds in c2e803403027f3fae92bd15b0ba50ab7df5063e6 the org.eclipse.tycho:tycho-compiler-jdt dependency is no longer needed in the compile code, we only need it for tests --- processor/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processor/pom.xml b/processor/pom.xml index fcc6dbbab8..4f2476ceb0 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -44,8 +44,7 @@ org.eclipse.tycho tycho-compiler-jdt - provided - true + test From 935c03e822d0df436f374349d4272d3e62fe9874 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 16 Oct 2021 22:00:30 +0200 Subject: [PATCH 0614/1006] #2614 Do not use FQN when mapping Stream to Array --- .../java/org/mapstruct/ap/internal/model/common/Type.java | 7 +++++-- .../mapstruct/ap/internal/model/StreamMappingMethod.ftl | 2 +- .../org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index e13d7b9ddd..caa7a9c626 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -444,8 +444,11 @@ public boolean isToBeImported() { } private boolean shouldUseSimpleName() { - String fqn = notToBeImportedTypes.get( name ); - return this.qualifiedName.equals( fqn ); + // Using trimSimpleClassName since the same is used in the isToBeImported() + // to check whether notToBeImportedTypes contains it + String trimmedName = trimSimpleClassName( name ); + String fqn = notToBeImportedTypes.get( trimmedName ); + return trimSimpleClassName( this.qualifiedName ).equals( fqn ); } public Type erasure() { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index f9a7309b5d..ae48a3477a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -55,7 +55,7 @@ <#if needVarDefine> <#assign needVarDefine = false /> <#-- We create a null array which later will be directly assigned from the stream--> - ${resultElementType}[] ${resultName} = null; + <@includeModel object=resultElementType/>[] ${resultName} = null; <#elseif resultType.iterableType> <#if existingInstanceMapping> diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java index abe4a62a3d..b822f3a61d 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1707/ConverterImpl.java @@ -36,12 +36,12 @@ public Set convert(Stream source) { } @Override - public org.mapstruct.ap.test.bugs._1707.Converter.Target[] convertArray(Stream source) { + public Target[] convertArray(Stream source) { if ( source == null ) { return null; } - org.mapstruct.ap.test.bugs._1707.Converter.Target[] targetTmp = null; + Target[] targetTmp = null; targetTmp = source.map( source1 -> convert( source1 ) ) .toArray( Target[]::new ); From 564455ee452b0b7b3862be969b69d501f5ea118b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 16 Oct 2021 18:50:04 +0200 Subject: [PATCH 0615/1006] #2596 Record components should have the highest priority for read accessors --- .../mapstruct/itest/records/MemberDto.java | 13 ++++++++ .../mapstruct/itest/records/MemberEntity.java | 31 +++++++++++++++++++ .../mapstruct/itest/records/MemberMapper.java | 24 ++++++++++++++ .../mapstruct/itest/records/RecordsTest.java | 22 +++++++++++++ .../ap/internal/model/common/Type.java | 28 ++++++++++++----- 5 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberDto.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberEntity.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberMapper.java diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberDto.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberDto.java new file mode 100644 index 0000000000..bf3ce6cd94 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberDto.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public record MemberDto(Boolean isActive, Boolean premium) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberEntity.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberEntity.java new file mode 100644 index 0000000000..50a7b1ce00 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +/** + * @author Filip Hrisafov + */ +public class MemberEntity { + + private Boolean isActive; + private Boolean premium; + + public Boolean getIsActive() { + return isActive; + } + + public void setIsActive(Boolean active) { + isActive = active; + } + + public Boolean getPremium() { + return premium; + } + + public void setPremium(Boolean premium) { + this.premium = premium; + } +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberMapper.java new file mode 100644 index 0000000000..3460aeed69 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/MemberMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface MemberMapper { + + MemberMapper INSTANCE = Mappers.getMapper( MemberMapper.class ); + + MemberEntity fromRecord(MemberDto record); + + MemberDto toRecord(MemberEntity entity); + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index e3d055345e..e98df8797e 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -61,4 +61,26 @@ public void shouldMapIntoRecordWithList() { assertThat( carDto.wheelPositions() ) .containsExactly( "left" ); } + + @Test + public void shouldMapMemberRecord() { + MemberEntity member = MemberMapper.INSTANCE.fromRecord( new MemberDto( true, false ) ); + + assertThat( member ).isNotNull(); + assertThat( member.getIsActive() ).isTrue(); + assertThat( member.getPremium() ).isFalse(); + } + + @Test + public void shouldMapIntoMemberRecord() { + MemberEntity entity = new MemberEntity(); + entity.setIsActive( false ); + entity.setPremium( true ); + + MemberDto value = MemberMapper.INSTANCE.toRecord( entity ); + + assertThat( value ).isNotNull(); + assertThat( value.isActive() ).isEqualTo( false ); + assertThat( value.premium() ).isEqualTo( true ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index caa7a9c626..bba33a2764 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -576,14 +576,33 @@ public Type asRawType() { */ public Map getPropertyReadAccessors() { if ( readAccessors == null ) { - List getterList = filters.getterMethodsIn( getAllMethods() ); Map modifiableGetters = new LinkedHashMap<>(); + + Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); + modifiableGetters.putAll( recordAccessors ); + + List getterList = filters.getterMethodsIn( getAllMethods() ); for ( Accessor getter : getterList ) { + String simpleName = getter.getSimpleName(); + if ( recordAccessors.containsKey( simpleName ) ) { + // If there is already a record accessor that contains the simple name + // then it means that the getter is actually a record component. + // In that case we need to ignore it. + // e.g. record component named isActive. + // The DefaultAccessorNamingStrategy will return active as property name, + // but the property name is isActive, since it is a record + continue; + } String propertyName = getPropertyName( getter ); + + if ( recordAccessors.containsKey( propertyName ) ) { + // If there is already a record accessor, the property needs to be ignored + continue; + } if ( modifiableGetters.containsKey( propertyName ) ) { // In the DefaultAccessorNamingStrategy, this can only be the case for Booleans: isFoo() and // getFoo(); The latter is preferred. - if ( !getter.getSimpleName().startsWith( "is" ) ) { + if ( !simpleName.startsWith( "is" ) ) { modifiableGetters.put( propertyName, getter ); } @@ -593,11 +612,6 @@ public Map getPropertyReadAccessors() { } } - Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); - for ( Map.Entry recordEntry : recordAccessors.entrySet() ) { - modifiableGetters.putIfAbsent( recordEntry.getKey(), recordEntry.getValue() ); - } - List fieldsList = filters.fieldsIn( getAllFields() ); for ( Accessor field : fieldsList ) { String propertyName = getPropertyName( field ); From 80d26a1a9c0ce2a7c5312d9ed498ade8d5cdedc3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 25 Oct 2021 08:22:26 +0200 Subject: [PATCH 0616/1006] #148, #1386, #2593 Only import top level classes Instead of importing all classes, inner classes will be used through their top level classes only. This also fixes the problem in #2593 since inner classes are no longer imported but used through their top classes --- .../itest/tests/MavenIntegrationTest.java | 5 + .../main/java/DefaultPackageObject.java | 97 +++++++++++++++++++ .../src/test/resources/defaultPackage/pom.xml | 21 ++++ .../test/java/DefaultPackageTest.java | 31 ++++++ .../ap/internal/model/common/Type.java | 69 ++++++++++++- .../test/imports/InnerClassesImportsTest.java | 9 +- .../imports/nested/NestedImportsTest.java | 54 +++++++++++ .../NestedSourceInOtherPackageMapper.java | 18 ++++ .../ap/test/imports/nested/Source.java | 48 +++++++++ .../nested/SourceInOtherPackageMapper.java | 18 ++++ .../ap/test/imports/nested/Target.java | 48 +++++++++ .../nested/TargetInOtherPackageMapper.java | 18 ++++ .../nested/other/SourceInOtherPackage.java | 48 +++++++++ .../nested/other/TargetInOtherPackage.java | 48 +++++++++ .../BeanWithInnerEnumMapperImpl.java | 48 +++++++++ .../innerclasses/InnerClassMapperImpl.java | 55 +++++++++++ .../NestedSourceInOtherPackageMapperImpl.java | 42 ++++++++ .../SourceInOtherPackageMapperImpl.java | 54 +++++++++++ .../TargetInOtherPackageMapperImpl.java | 54 +++++++++++ 19 files changed, 776 insertions(+), 9 deletions(-) create mode 100644 integrationtest/src/test/resources/defaultPackage/main/java/DefaultPackageObject.java create mode 100644 integrationtest/src/test/resources/defaultPackage/pom.xml create mode 100644 integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedImportsTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/SourceInOtherPackage.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/TargetInOtherPackage.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapperImpl.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 2ec0ba9aa9..59aa48b053 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -128,6 +128,11 @@ void kotlinDataTest() { void simpleTest() { } + // for issue #2593 + @ProcessorTest(baseDir = "defaultPackage") + void defaultPackageTest() { + } + @ProcessorTest(baseDir = "springTest") void springTest() { } diff --git a/integrationtest/src/test/resources/defaultPackage/main/java/DefaultPackageObject.java b/integrationtest/src/test/resources/defaultPackage/main/java/DefaultPackageObject.java new file mode 100644 index 0000000000..ba684850b4 --- /dev/null +++ b/integrationtest/src/test/resources/defaultPackage/main/java/DefaultPackageObject.java @@ -0,0 +1,97 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +public class DefaultPackageObject { + public enum CarType { + SEDAN, CAMPER, X4, TRUCK; + } + + static public class Car { + + private String make; + private int numberOfSeats; + private CarType type; + + public Car(String string, int numberOfSeats, CarType sedan) { + this.make = string; + this.numberOfSeats = numberOfSeats; + this.type = sedan; + } + + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public int getNumberOfSeats() { + return numberOfSeats; + } + + public void setNumberOfSeats(int numberOfSeats) { + this.numberOfSeats = numberOfSeats; + } + + public CarType getType() { + return type; + } + + public void setType(CarType type) { + this.type = type; + } + } + + static public class CarDto { + + private String make; + private int seatCount; + private String type; + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public int getSeatCount() { + return seatCount; + } + + public void setSeatCount(int seatCount) { + this.seatCount = seatCount; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + } + + + @Mapper + public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + @Mapping(source = "numberOfSeats", target = "seatCount") + CarDto carToCarDto(Car car); + } +} diff --git a/integrationtest/src/test/resources/defaultPackage/pom.xml b/integrationtest/src/test/resources/defaultPackage/pom.xml new file mode 100644 index 0000000000..d72300f618 --- /dev/null +++ b/integrationtest/src/test/resources/defaultPackage/pom.xml @@ -0,0 +1,21 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + defaultPackage + jar + diff --git a/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java b/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java new file mode 100644 index 0000000000..ddc834cc8e --- /dev/null +++ b/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ + +public class DefaultPackageTest { + + @Test + public void shouldWorkCorrectlyInDefaultPackage() { + DefaultPackageObject.CarDto carDto = DefaultPackageObject.CarMapper.INSTANCE.carToCarDto( + new DefaultPackageObject.Car( + "Morris", + 5, + DefaultPackageObject.CarType.SEDAN + ) ); + + assertThat( carDto ).isNotNull(); + assertThat( carDto.getMake() ).isEqualTo( "Morris" ); + assertThat( carDto.getSeatCount() ).isEqualTo( 5 ); + assertThat( carDto.getType() ).isEqualTo( "SEDAN" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index bba33a2764..00bcae371c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -5,9 +5,11 @@ */ package org.mapstruct.ap.internal.model.common; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -22,6 +24,7 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; +import javax.lang.model.element.NestingKind; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.ArrayType; @@ -71,9 +74,11 @@ public class Type extends ModelElement implements Comparable { private final ImplementationType implementationType; private final Type componentType; + private final Type topLevelType; private final String packageName; private final String name; + private final String nameWithTopLevelTypeName; private final String qualifiedName; private final boolean isInterface; @@ -172,6 +177,9 @@ public Type(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFact this.filters = new Filters( accessorNaming, typeUtils, typeMirror ); this.loggingVerbose = loggingVerbose; + + this.topLevelType = topLevelType( this.typeElement, this.typeFactory ); + this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( this.typeElement ); } //CHECKSTYLE:ON @@ -199,11 +207,23 @@ public String getName() { *

      * If the {@code java.time} variant is referred to first, the {@code java.time.LocalDateTime} will be imported * and the {@code org.joda} variant will be referred to with its FQN. + *

      + * If the type is nested and its top level type is to be imported + * then the name including its top level type will be returned. * - * @return Just the name if this {@link Type} will be imported, otherwise the fully-qualified name. + * @return Just the name if this {@link Type} will be imported, the name up to the top level {@link Type} + * (if the top level type is important, otherwise the fully-qualified name. */ public String createReferenceName() { - return isToBeImported() ? name : ( shouldUseSimpleName() ? name : qualifiedName ); + if ( isToBeImported() || shouldUseSimpleName() ) { + return name; + } + + if ( isTopLevelTypeToBeImported() && nameWithTopLevelTypeName != null ) { + return nameWithTopLevelTypeName; + } + + return qualifiedName; } public List getTypeParameters() { @@ -402,6 +422,10 @@ public Set getImportTypes() { result.addAll( componentType.getImportTypes() ); } + if ( topLevelType != null ) { + result.addAll( topLevelType.getImportTypes() ); + } + for ( Type parameter : typeParameters ) { result.addAll( parameter.getImportTypes() ); } @@ -413,6 +437,10 @@ public Set getImportTypes() { return result; } + protected boolean isTopLevelTypeToBeImported() { + return topLevelType != null && topLevelType.isToBeImported(); + } + /** * Whether this type is to be imported by means of an import statement in the currently generated source file * (it can be referenced in the generated source using its simple name) or not (referenced using the FQN). @@ -435,7 +463,7 @@ public boolean isToBeImported() { isToBeImported = true; } } - else { + else if ( typeElement == null || !typeElement.getNestingKind().isNested() ) { toBeImportedTypes.put( trimmedName, trimmedQualifiedName ); isToBeImported = true; } @@ -1492,4 +1520,39 @@ private String trimSimpleClassName(String className) { return trimmedClassName; } + private static String nameWithTopLevelTypeName(TypeElement element) { + if ( element == null ) { + return null; + } + if ( !element.getNestingKind().isNested() ) { + return element.getSimpleName().toString(); + } + + Deque elements = new ArrayDeque<>(); + elements.addFirst( element.getSimpleName() ); + Element parent = element.getEnclosingElement(); + while ( parent != null && parent.getKind() != ElementKind.PACKAGE ) { + elements.addFirst( parent.getSimpleName() ); + parent = parent.getEnclosingElement(); + } + + return String.join( ".", elements ); + } + + private static Type topLevelType(TypeElement typeElement, TypeFactory typeFactory) { + if ( typeElement == null || typeElement.getNestingKind() == NestingKind.TOP_LEVEL ) { + return null; + } + + Element parent = typeElement.getEnclosingElement(); + while ( parent != null ) { + if ( parent.getEnclosingElement() != null && + parent.getEnclosingElement().getKind() == ElementKind.PACKAGE ) { + break; + } + parent = parent.getEnclosingElement(); + } + return parent == null ? null : typeFactory.getType( parent.asType() ); + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java index 91e5df6a27..abad5e4177 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/InnerClassesImportsTest.java @@ -14,7 +14,6 @@ import org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass; import org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass.SourceInnerClass; import org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass; -import org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass.TargetInnerClass; import org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -47,8 +46,7 @@ public void mapperRequiresInnerClassImports() { assertThat( target ).isNotNull(); assertThat( target.getInnerClassMember().getValue() ).isEqualTo( 412 ); - generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( SourceInnerClass.class ); - generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( TargetInnerClass.class ); + generatedSource.addComparisonToFixtureFor( InnerClassMapper.class ); } @ProcessorTest @@ -61,8 +59,7 @@ public void mapperRequiresInnerInnerClassImports() { assertThat( target ).isNotNull(); assertThat( target.getValue() ).isEqualTo( 412 ); - generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( SourceInnerClass.class ); - generatedSource.forMapper( InnerClassMapper.class ).containsImportFor( TargetInnerInnerClass.class ); + generatedSource.addComparisonToFixtureFor( InnerClassMapper.class ); } @ProcessorTest @@ -82,6 +79,6 @@ public void mapperRequiresInnerEnumImports() { assertThat( sourceAgain ).isNotNull(); assertThat( sourceAgain.getInnerEnum() ).isEqualTo( InnerEnum.A ); - generatedSource.forMapper( BeanWithInnerEnumMapper.class ).containsImportFor( InnerEnum.class ); + generatedSource.addComparisonToFixtureFor( BeanWithInnerEnumMapper.class ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedImportsTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedImportsTest.java new file mode 100644 index 0000000000..37c522e4cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedImportsTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.imports.nested.other.SourceInOtherPackage; +import org.mapstruct.ap.test.imports.nested.other.TargetInOtherPackage; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + SourceInOtherPackage.class, + TargetInOtherPackage.class, + Source.class, + Target.class +}) +@IssueKey("1386,148") +class NestedImportsTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses( { + SourceInOtherPackageMapper.class + } ) + void shouldGenerateNestedInnerClassesForSourceInOtherPackage() { + generatedSource.addComparisonToFixtureFor( SourceInOtherPackageMapper.class ); + } + + @ProcessorTest + @WithClasses( { + NestedSourceInOtherPackageMapper.class + } ) + void shouldGenerateCorrectImportsForTopLevelClassesFromOnlyNestedInnerClasses() { + generatedSource.addComparisonToFixtureFor( NestedSourceInOtherPackageMapper.class ); + } + + @ProcessorTest + @WithClasses( { + TargetInOtherPackageMapper.class + } ) + void shouldGenerateNestedInnerClassesForTargetInOtherPackage() { + generatedSource.addComparisonToFixtureFor( TargetInOtherPackageMapper.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapper.java new file mode 100644 index 0000000000..7f98737d1d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.imports.nested.other.SourceInOtherPackage; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface NestedSourceInOtherPackageMapper { + + Target.Nested map(SourceInOtherPackage.Nested source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Source.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Source.java new file mode 100644 index 0000000000..2d2e9aa215 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Source.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private Nested value; + + public Nested getValue() { + return value; + } + + public void setValue(Nested value) { + this.value = value; + } + + public static class Nested { + + private Inner inner; + + public static class Inner { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public Inner getInner() { + return inner; + } + + public void setInner(Inner inner) { + this.inner = inner; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapper.java new file mode 100644 index 0000000000..7150823c1a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.imports.nested.other.SourceInOtherPackage; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SourceInOtherPackageMapper { + + Target map(SourceInOtherPackage source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Target.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Target.java new file mode 100644 index 0000000000..78a50fcb15 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/Target.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Nested value; + + public Nested getValue() { + return value; + } + + public void setValue(Nested value) { + this.value = value; + } + + public static class Nested { + + private Inner inner; + + public static class Inner { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public Inner getInner() { + return inner; + } + + public void setInner(Inner inner) { + this.inner = inner; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapper.java new file mode 100644 index 0000000000..a40d52eb1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.imports.nested.other.TargetInOtherPackage; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface TargetInOtherPackageMapper { + + TargetInOtherPackage map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/SourceInOtherPackage.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/SourceInOtherPackage.java new file mode 100644 index 0000000000..f6646c7160 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/SourceInOtherPackage.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested.other; + +/** + * @author Filip Hrisafov + */ +public class SourceInOtherPackage { + + private Nested value; + + public Nested getValue() { + return value; + } + + public void setValue(Nested value) { + this.value = value; + } + + public static class Nested { + + private Inner inner; + + public static class Inner { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public Inner getInner() { + return inner; + } + + public void setInner(Inner inner) { + this.inner = inner; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/TargetInOtherPackage.java b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/TargetInOtherPackage.java new file mode 100644 index 0000000000..da6b596c06 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/nested/other/TargetInOtherPackage.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested.other; + +/** + * @author Filip Hrisafov + */ +public class TargetInOtherPackage { + + private Nested value; + + public Nested getValue() { + return value; + } + + public void setValue(Nested value) { + this.value = value; + } + + public static class Nested { + + private Inner inner; + + public static class Inner { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + public Inner getInner() { + return inner; + } + + public void setInner(Inner inner) { + this.inner = inner; + } + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapperImpl.java new file mode 100644 index 0000000000..1428fabd8f --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/BeanWithInnerEnumMapperImpl.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.innerclasses; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-10-16T21:06:53+0200", + comments = "version: , compiler: javac, environment: Java 17 (Oracle Corporation)" +) +public class BeanWithInnerEnumMapperImpl implements BeanWithInnerEnumMapper { + + @Override + public BeanWithInnerEnum fromFacade(BeanFacade beanFacade) { + if ( beanFacade == null ) { + return null; + } + + BeanWithInnerEnum beanWithInnerEnum = new BeanWithInnerEnum(); + + beanWithInnerEnum.setTest( beanFacade.getTest() ); + if ( beanFacade.getInnerEnum() != null ) { + beanWithInnerEnum.setInnerEnum( Enum.valueOf( BeanWithInnerEnum.InnerEnum.class, beanFacade.getInnerEnum() ) ); + } + + return beanWithInnerEnum; + } + + @Override + public BeanFacade toFacade(BeanWithInnerEnum beanWithInnerEnum) { + if ( beanWithInnerEnum == null ) { + return null; + } + + BeanFacade beanFacade = new BeanFacade(); + + beanFacade.setTest( beanWithInnerEnum.getTest() ); + if ( beanWithInnerEnum.getInnerEnum() != null ) { + beanFacade.setInnerEnum( beanWithInnerEnum.getInnerEnum().name() ); + } + + return beanFacade; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapperImpl.java new file mode 100644 index 0000000000..bd85a7abee --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/innerclasses/InnerClassMapperImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.innerclasses; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-10-16T21:06:53+0200", + comments = "version: , compiler: javac, environment: Java 17 (Oracle Corporation)" +) +public class InnerClassMapperImpl implements InnerClassMapper { + + @Override + public TargetWithInnerClass sourceToTarget(SourceWithInnerClass source) { + if ( source == null ) { + return null; + } + + TargetWithInnerClass targetWithInnerClass = new TargetWithInnerClass(); + + targetWithInnerClass.setInnerClassMember( innerSourceToInnerTarget( source.getInnerClassMember() ) ); + + return targetWithInnerClass; + } + + @Override + public TargetWithInnerClass.TargetInnerClass innerSourceToInnerTarget(SourceWithInnerClass.SourceInnerClass source) { + if ( source == null ) { + return null; + } + + TargetWithInnerClass.TargetInnerClass targetInnerClass = new TargetWithInnerClass.TargetInnerClass(); + + targetInnerClass.setValue( source.getValue() ); + + return targetInnerClass; + } + + @Override + public TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass innerSourceToInnerInnerTarget(SourceWithInnerClass.SourceInnerClass source) { + if ( source == null ) { + return null; + } + + TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass targetInnerInnerClass = new TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass(); + + targetInnerInnerClass.setValue( source.getValue() ); + + return targetInnerInnerClass; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapperImpl.java new file mode 100644 index 0000000000..53dd91b9e2 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/NestedSourceInOtherPackageMapperImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import javax.annotation.processing.Generated; +import org.mapstruct.ap.test.imports.nested.other.SourceInOtherPackage; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-10-24T19:26:14+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_161 (Oracle Corporation)" +) +public class NestedSourceInOtherPackageMapperImpl implements NestedSourceInOtherPackageMapper { + + @Override + public Target.Nested map(SourceInOtherPackage.Nested source) { + if ( source == null ) { + return null; + } + + Target.Nested nested = new Target.Nested(); + + nested.setInner( innerToInner( source.getInner() ) ); + + return nested; + } + + protected Target.Nested.Inner innerToInner(SourceInOtherPackage.Nested.Inner inner) { + if ( inner == null ) { + return null; + } + + Target.Nested.Inner inner1 = new Target.Nested.Inner(); + + inner1.setValue( inner.getValue() ); + + return inner1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapperImpl.java new file mode 100644 index 0000000000..a167518464 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/SourceInOtherPackageMapperImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import javax.annotation.Generated; +import org.mapstruct.ap.test.imports.nested.other.SourceInOtherPackage; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2018-08-19T19:13:35+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_161 (Oracle Corporation)" +) +public class SourceInOtherPackageMapperImpl implements SourceInOtherPackageMapper { + + @Override + public Target map(SourceInOtherPackage source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setValue( nestedToNested( source.getValue() ) ); + + return target; + } + + protected Target.Nested.Inner innerToInner(SourceInOtherPackage.Nested.Inner inner) { + if ( inner == null ) { + return null; + } + + Target.Nested.Inner inner1 = new Target.Nested.Inner(); + + inner1.setValue( inner.getValue() ); + + return inner1; + } + + protected Target.Nested nestedToNested(SourceInOtherPackage.Nested nested) { + if ( nested == null ) { + return null; + } + + Target.Nested nested1 = new Target.Nested(); + + nested1.setInner( innerToInner( nested.getInner() ) ); + + return nested1; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapperImpl.java new file mode 100644 index 0000000000..b1e5d09f40 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/imports/nested/TargetInOtherPackageMapperImpl.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.imports.nested; + +import javax.annotation.processing.Generated; +import org.mapstruct.ap.test.imports.nested.other.TargetInOtherPackage; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2021-10-24T13:45:02+0200", + comments = "version: , compiler: javac, environment: Java 1.8.0_161 (Oracle Corporation)" +) +public class TargetInOtherPackageMapperImpl implements TargetInOtherPackageMapper { + + @Override + public TargetInOtherPackage map(Source source) { + if ( source == null ) { + return null; + } + + TargetInOtherPackage targetInOtherPackage = new TargetInOtherPackage(); + + targetInOtherPackage.setValue( nestedToNested( source.getValue() ) ); + + return targetInOtherPackage; + } + + protected TargetInOtherPackage.Nested.Inner innerToInner(Source.Nested.Inner inner) { + if ( inner == null ) { + return null; + } + + TargetInOtherPackage.Nested.Inner inner1 = new TargetInOtherPackage.Nested.Inner(); + + inner1.setValue( inner.getValue() ); + + return inner1; + } + + protected TargetInOtherPackage.Nested nestedToNested(Source.Nested nested) { + if ( nested == null ) { + return null; + } + + TargetInOtherPackage.Nested nested1 = new TargetInOtherPackage.Nested(); + + nested1.setInner( innerToInner( nested.getInner() ) ); + + return nested1; + } +} From e32fc8c283085da5080044c9a41b1dd1e71198ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20P=C3=B6ttker?= Date: Mon, 25 Oct 2021 12:20:11 +0200 Subject: [PATCH 0617/1006] #2351 NullValueMappingStrategy for Maps and Iterables With two new parameters for Mapper and MapperConfig, it is now possible to override the nullValueMappingStrategy specifically for MapMapping and IterableMapping. --- core/src/main/java/org/mapstruct/Mapper.java | 26 +++ .../main/java/org/mapstruct/MapperConfig.java | 22 +++ .../internal/model/source/DefaultOptions.java | 8 + .../model/source/DelegatingOptions.java | 8 + .../model/source/IterableMappingOptions.java | 8 +- .../model/source/MapMappingOptions.java | 2 +- .../model/source/MapperConfigOptions.java | 22 +++ .../internal/model/source/MapperOptions.java | 22 +++ .../ap/test/nullvaluemapping/CarMapper.java | 15 +- .../CarMapperIterableSettingOnConfig.java | 35 ++++ .../CarMapperIterableSettingOnMapper.java | 40 +++++ .../CarMapperMapSettingOnConfig.java | 35 ++++ .../CarMapperMapSettingOnMapper.java | 40 +++++ .../CarMapperSettingOnConfig.java | 9 +- .../CarMapperSettingOnMapper.java | 9 +- .../CentralIterableMappingConfig.java | 17 ++ .../CentralMapMappingConfig.java | 17 ++ .../NullValueMappingTest.java | 150 +++++++++++++++++- 18 files changed, 453 insertions(+), 32 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralIterableMappingConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralMapMappingConfig.java diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 9ddd9bff5c..26442e4ff0 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -203,6 +203,32 @@ */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * The strategy to be applied when {@code null} is passed as source argument value to an {@link IterableMapping} of + * this mapper. If unset, the strategy set with {@link #nullValueMappingStrategy()} will be applied. If neither + * strategy is configured, the strategy given via {@link MapperConfig#nullValueIterableMappingStrategy()} will be + * applied, using {@link NullValueMappingStrategy#RETURN_NULL} by default. + * + * @since 1.5 + * + * @return The strategy to be applied when {@code null} is passed as source value to an {@link IterableMapping} of + * this mapper. + */ + NullValueMappingStrategy nullValueIterableMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + + /** + * The strategy to be applied when {@code null} is passed as source argument value to a {@link MapMapping} of this + * mapper. If unset, the strategy set with {@link #nullValueMappingStrategy()} will be applied. If neither strategy + * is configured, the strategy given via {@link MapperConfig#nullValueMapMappingStrategy()} will be applied, using + * {@link NullValueMappingStrategy#RETURN_NULL} by default. + * + * @since 1.5 + * + * @return The strategy to be applied when {@code null} is passed as source value to a {@link MapMapping} of this + * mapper. + */ + NullValueMappingStrategy nullValueMapMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is * configured, the strategy given via {@link MapperConfig#nullValuePropertyMappingStrategy()} will be applied, diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 877495867c..ce239322a2 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -177,6 +177,28 @@ */ NullValueMappingStrategy nullValueMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** + * The strategy to be applied when {@code null} is passed as source argument value to an {@link IterableMapping}. + * If no strategy is configured, the strategy given via {@link #nullValueMappingStrategy()} will be applied, using + * {@link NullValueMappingStrategy#RETURN_NULL} by default. + * + * @since 1.5 + * + * @return The strategy to be applied when {@code null} is passed as source value to an {@link IterableMapping}. + */ + NullValueMappingStrategy nullValueIterableMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + + /** + * The strategy to be applied when {@code null} is passed as source argument value to a {@link MapMapping}. + * If no strategy is configured, the strategy given via {@link #nullValueMappingStrategy()} will be applied, using + * {@link NullValueMappingStrategy#RETURN_NULL} by default. + * + * @since 1.5 + * + * @return The strategy to be applied when {@code null} is passed as source value to a {@link MapMapping}. + */ + NullValueMappingStrategy nullValueMapMappingStrategy() default NullValueMappingStrategy.RETURN_NULL; + /** * The strategy to be applied when a source bean property is {@code null} or not present. If no strategy is * configured, {@link NullValuePropertyMappingStrategy#SET_TO_NULL} will be used by default. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 5a7161b4c8..1258707e43 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -124,6 +124,14 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { return SubclassExhaustiveStrategyGem.valueOf( mapper.subclassExhaustiveStrategy().getDefaultValue() ); } + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueIterableMappingStrategy().getDefaultValue() ); + } + + public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueMapMappingStrategy().getDefaultValue() ); + } + public BuilderGem getBuilder() { // TODO: I realized this is not correct, however it needs to be null in order to keep downward compatibility // but assuming a default @Builder will make testcases fail. Not having a default means that you need to diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index b2b36b68a6..12f610f1ac 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -102,6 +102,14 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { return next.getSubclassExhaustiveStrategy(); } + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + return next.getNullValueIterableMappingStrategy(); + } + + public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + return next.getNullValueMapMappingStrategy(); + } + public BuilderGem getBuilder() { return next.getBuilder(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index 40b5b25353..4affcd93e2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -30,11 +30,11 @@ public class IterableMappingOptions extends DelegatingOptions { private final IterableMappingGem iterableMapping; public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, - MapperOptions mappperOptions, ExecutableElement method, + MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, TypeUtils typeUtils) { if ( iterableMapping == null || !isConsistent( iterableMapping, method, messager ) ) { - IterableMappingOptions options = new IterableMappingOptions( null, null, null, mappperOptions ); + IterableMappingOptions options = new IterableMappingOptions( null, null, null, mapperOptions ); return options; } @@ -54,7 +54,7 @@ public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, ); IterableMappingOptions options = - new IterableMappingOptions( formatting, selection, iterableMapping, mappperOptions ); + new IterableMappingOptions( formatting, selection, iterableMapping, mapperOptions ); return options; } @@ -99,7 +99,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .filter( GemValue::hasValue ) .map( GemValue::getValue ) .map( NullValueMappingStrategyGem::valueOf ) - .orElse( next().getNullValueMappingStrategy() ); + .orElse( next().getNullValueIterableMappingStrategy() ); } public MappingControl getElementMappingControl(ElementUtils elementUtils) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index c35a8e363d..ca8f1ea544 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -144,7 +144,7 @@ public NullValueMappingStrategyGem getNullValueMappingStrategy() { .filter( GemValue::hasValue ) .map( GemValue::getValue ) .map( NullValueMappingStrategyGem::valueOf ) - .orElse( next().getNullValueMappingStrategy() ); + .orElse( next().getNullValueMapMappingStrategy() ); } public MappingControl getKeyMappingControl(ElementUtils elementUtils) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index 5288ab1304..623b97bc78 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -134,6 +134,28 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { next().getSubclassExhaustiveStrategy(); } + @Override + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + if ( mapperConfig.nullValueIterableMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueIterableMappingStrategy().get() ); + } + if ( mapperConfig.nullValueMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueMappingStrategy().get() ); + } + return next().getNullValueIterableMappingStrategy(); + } + + @Override + public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + if ( mapperConfig.nullValueMapMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueMapMappingStrategy().get() ); + } + if ( mapperConfig.nullValueMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapperConfig.nullValueMappingStrategy().get() ); + } + return next().getNullValueMapMappingStrategy(); + } + @Override public BuilderGem getBuilder() { return mapperConfig.builder().hasValue() ? mapperConfig.builder().get() : next().getBuilder(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 86aae34052..3261205116 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -163,6 +163,28 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { next().getSubclassExhaustiveStrategy(); } + @Override + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + if ( mapper.nullValueIterableMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueIterableMappingStrategy().get() ); + } + if ( mapper.nullValueMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().get() ); + } + return next().getNullValueIterableMappingStrategy(); + } + + @Override + public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + if ( mapper.nullValueMapMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueMapMappingStrategy().get() ); + } + if ( mapper.nullValueMappingStrategy().hasValue() ) { + return NullValueMappingStrategyGem.valueOf( mapper.nullValueMappingStrategy().get() ); + } + return next().getNullValueMapMappingStrategy(); + } + @Override public BuilderGem getBuilder() { return mapper.builder().hasValue() ? mapper.builder().get() : next().getBuilder(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java index d087d5ef4a..26e3f30e6b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapper.java @@ -16,7 +16,6 @@ import org.mapstruct.MapMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; import org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto; import org.mapstruct.ap.test.nullvaluemapping.source.Car; @@ -29,18 +28,14 @@ public interface CarMapper { CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); @BeanMapping(nullValueMappingStrategy = RETURN_DEFAULT) - @Mappings({ - @Mapping(target = "seatCount", source = "numberOfSeats"), - @Mapping(target = "model", constant = "ModelT"), - @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") - }) + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") CarDto carToCarDto(Car car); @BeanMapping(nullValueMappingStrategy = RETURN_DEFAULT) - @Mappings({ - @Mapping(target = "seatCount", source = "car.numberOfSeats"), - @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") - }) + @Mapping(target = "seatCount", source = "car.numberOfSeats") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") CarDto carToCarDto(Car car, String model); @IterableMapping(nullValueMappingStrategy = RETURN_DEFAULT) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnConfig.java new file mode 100644 index 0000000000..8fd9447073 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnConfig.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +@Mapper(imports = UUID.class, config = CentralIterableMappingConfig.class) +public interface CarMapperIterableSettingOnConfig { + + CarMapperIterableSettingOnConfig INSTANCE = Mappers.getMapper( CarMapperIterableSettingOnConfig.class ); + + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") + CarDto carToCarDto(Car car); + + @IterableMapping(dateFormat = "dummy") + List carsToCarDtos(List cars); + + @MapMapping(valueDateFormat = "dummy") + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnMapper.java new file mode 100644 index 0000000000..0e1e123c52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperIterableSettingOnMapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +@Mapper( + imports = UUID.class, + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_NULL +) +public interface CarMapperIterableSettingOnMapper { + + CarMapperIterableSettingOnMapper INSTANCE = Mappers.getMapper( CarMapperIterableSettingOnMapper.class ); + + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") + CarDto carToCarDto(Car car); + + @IterableMapping(dateFormat = "dummy") + List carsToCarDtos(List cars); + + @MapMapping(valueDateFormat = "dummy") + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnConfig.java new file mode 100644 index 0000000000..47f0f34f63 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnConfig.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +@Mapper(imports = UUID.class, config = CentralMapMappingConfig.class) +public interface CarMapperMapSettingOnConfig { + + CarMapperMapSettingOnConfig INSTANCE = Mappers.getMapper( CarMapperMapSettingOnConfig.class ); + + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") + CarDto carToCarDto(Car car); + + @IterableMapping(dateFormat = "dummy") + List carsToCarDtos(List cars); + + @MapMapping(valueDateFormat = "dummy") + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnMapper.java new file mode 100644 index 0000000000..0caad062c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperMapSettingOnMapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.mapstruct.IterableMapping; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +@Mapper( + imports = UUID.class, + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + nullValueMapMappingStrategy = NullValueMappingStrategy.RETURN_NULL +) +public interface CarMapperMapSettingOnMapper { + + CarMapperMapSettingOnMapper INSTANCE = Mappers.getMapper( CarMapperMapSettingOnMapper.class ); + + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") + CarDto carToCarDto(Car car); + + @IterableMapping(dateFormat = "dummy") + List carsToCarDtos(List cars); + + @MapMapping(valueDateFormat = "dummy") + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java index f8f15a3e77..8e4ca2dac6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnConfig.java @@ -13,7 +13,6 @@ import org.mapstruct.MapMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; import org.mapstruct.ap.test.nullvaluemapping.source.Car; @@ -24,11 +23,9 @@ public interface CarMapperSettingOnConfig { CarMapperSettingOnConfig INSTANCE = Mappers.getMapper( CarMapperSettingOnConfig.class ); - @Mappings({ - @Mapping(target = "seatCount", source = "numberOfSeats"), - @Mapping(target = "model", constant = "ModelT"), - @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") - }) + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") CarDto carToCarDto(Car car); @IterableMapping(dateFormat = "dummy") diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java index c3f7d5f2c7..2306b3add4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapperSettingOnMapper.java @@ -13,7 +13,6 @@ import org.mapstruct.MapMapping; import org.mapstruct.Mapper; import org.mapstruct.Mapping; -import org.mapstruct.Mappings; import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; import org.mapstruct.ap.test.nullvaluemapping.source.Car; @@ -24,11 +23,9 @@ public interface CarMapperSettingOnMapper { CarMapperSettingOnMapper INSTANCE = Mappers.getMapper( CarMapperSettingOnMapper.class ); - @Mappings({ - @Mapping(target = "seatCount", source = "numberOfSeats"), - @Mapping(target = "model", constant = "ModelT"), - @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") - }) + @Mapping(target = "seatCount", source = "numberOfSeats") + @Mapping(target = "model", constant = "ModelT") + @Mapping(target = "catalogId", expression = "java( UUID.randomUUID().toString() )") CarDto carToCarDto(Car car); @IterableMapping(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralIterableMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralIterableMappingConfig.java new file mode 100644 index 0000000000..559c3520a9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralIterableMappingConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import org.mapstruct.MapperConfig; +import org.mapstruct.NullValueMappingStrategy; + +@MapperConfig( + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_NULL +) +public class CentralIterableMappingConfig { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralMapMappingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralMapMappingConfig.java new file mode 100644 index 0000000000..7737e07de6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CentralMapMappingConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import org.mapstruct.MapperConfig; +import org.mapstruct.NullValueMappingStrategy; + +@MapperConfig( + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + nullValueMapMappingStrategy = NullValueMappingStrategy.RETURN_NULL +) +public class CentralMapMappingConfig { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java index 4bd9324a9a..a027acaba3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMappingTest.java @@ -33,8 +33,14 @@ DriverAndCarDto.class, CarMapper.class, CarMapperSettingOnMapper.class, + CarMapperIterableSettingOnMapper.class, + CarMapperMapSettingOnMapper.class, CentralConfig.class, - CarMapperSettingOnConfig.class + CarMapperSettingOnConfig.class, + CentralIterableMappingConfig.class, + CarMapperIterableSettingOnConfig.class, + CentralMapMappingConfig.class, + CarMapperMapSettingOnConfig.class, }) public class NullValueMappingTest { @@ -161,8 +167,7 @@ public void shouldMapIterableWithNullArgOnMapper() { List carDtos = CarMapperSettingOnMapper.INSTANCE.carsToCarDtos( null ); //then - assertThat( carDtos ).isNotNull(); - assertThat( carDtos.isEmpty() ).isTrue(); + assertThat( carDtos ).isEmpty(); } @ProcessorTest @@ -175,6 +180,74 @@ public void shouldMapMapWithNullArgOnMapper() { assertThat( carDtoMap ).isNull(); } + @ProcessorTest + public void shouldMapExpressionAndConstantRegardlessOfIterableNullArgOnMapper() { + + //when + CarDto carDto = CarMapperIterableSettingOnMapper.INSTANCE.carToCarDto( null ); + + //then + assertThat( carDto ).isNotNull(); + assertThat( carDto.getMake() ).isNull(); + assertThat( carDto.getSeatCount() ).isEqualTo( 0 ); + assertThat( carDto.getModel() ).isEqualTo( "ModelT" ); + assertThat( carDto.getCatalogId() ).isNotEmpty(); + } + + @ProcessorTest + public void shouldMapIterableToNullWithIterableNullArgOnMapper() { + + //when + List carDtos = CarMapperIterableSettingOnMapper.INSTANCE.carsToCarDtos( null ); + + //then + assertThat( carDtos ).isNull(); + } + + @ProcessorTest + public void shouldMapMapRegardlessOfIterableNullArgOnMapper() { + + //when + Map carDtoMap = CarMapperIterableSettingOnMapper.INSTANCE.carsToCarDtoMap( null ); + + //then + assertThat( carDtoMap ).isEmpty(); + } + + @ProcessorTest + public void shouldMapExpressionAndConstantRegardlessMapNullArgOnMapper() { + + //when + CarDto carDto = CarMapperMapSettingOnMapper.INSTANCE.carToCarDto( null ); + + //then + assertThat( carDto ).isNotNull(); + assertThat( carDto.getMake() ).isNull(); + assertThat( carDto.getSeatCount() ).isEqualTo( 0 ); + assertThat( carDto.getModel() ).isEqualTo( "ModelT" ); + assertThat( carDto.getCatalogId() ).isNotEmpty(); + } + + @ProcessorTest + public void shouldMapIterableRegardlessOfMapNullArgOnMapper() { + + //when + List carDtos = CarMapperMapSettingOnMapper.INSTANCE.carsToCarDtos( null ); + + //then + assertThat( carDtos ).isEmpty(); + } + + @ProcessorTest + public void shouldMapMapToWithMapNullArgOnMapper() { + + //when + Map carDtoMap = CarMapperMapSettingOnMapper.INSTANCE.carsToCarDtoMap( null ); + + //then + assertThat( carDtoMap ).isNull(); + } + @ProcessorTest public void shouldMapExpressionAndConstantRegardlessNullArgOnConfig() { @@ -196,8 +269,7 @@ public void shouldMapIterableWithNullArgOnConfig() { List carDtos = CarMapperSettingOnConfig.INSTANCE.carsToCarDtos( null ); //then - assertThat( carDtos ).isNotNull(); - assertThat( carDtos.isEmpty() ).isTrue(); + assertThat( carDtos ).isEmpty(); } @ProcessorTest @@ -210,6 +282,74 @@ public void shouldMapMapWithNullArgOnConfig() { assertThat( carDtoMap ).isNull(); } + @ProcessorTest + public void shouldMapExpressionAndConstantRegardlessOfIterableNullArgOnConfig() { + + //when + CarDto carDto = CarMapperIterableSettingOnConfig.INSTANCE.carToCarDto( null ); + + //then + assertThat( carDto ).isNotNull(); + assertThat( carDto.getMake() ).isNull(); + assertThat( carDto.getSeatCount() ).isEqualTo( 0 ); + assertThat( carDto.getModel() ).isEqualTo( "ModelT" ); + assertThat( carDto.getCatalogId() ).isNotEmpty(); + } + + @ProcessorTest + public void shouldMapIterableToNullWithIterableNullArgOnConfig() { + + //when + List carDtos = CarMapperIterableSettingOnConfig.INSTANCE.carsToCarDtos( null ); + + //then + assertThat( carDtos ).isNull(); + } + + @ProcessorTest + public void shouldMapMapRegardlessOfIterableNullArgOnConfig() { + + //when + Map carDtoMap = CarMapperIterableSettingOnConfig.INSTANCE.carsToCarDtoMap( null ); + + //then + assertThat( carDtoMap ).isEmpty(); + } + + @ProcessorTest + public void shouldMapExpressionAndConstantRegardlessOfMapNullArgOnConfig() { + + //when + CarDto carDto = CarMapperMapSettingOnConfig.INSTANCE.carToCarDto( null ); + + //then + assertThat( carDto ).isNotNull(); + assertThat( carDto.getMake() ).isNull(); + assertThat( carDto.getSeatCount() ).isEqualTo( 0 ); + assertThat( carDto.getModel() ).isEqualTo( "ModelT" ); + assertThat( carDto.getCatalogId() ).isNotEmpty(); + } + + @ProcessorTest + public void shouldMapIterableRegardlessOfMapNullArgOnConfig() { + + //when + List carDtos = CarMapperMapSettingOnConfig.INSTANCE.carsToCarDtos( null ); + + //then + assertThat( carDtos ).isEmpty(); + } + + @ProcessorTest + public void shouldMapMapToNullWithMapNullArgOnConfig() { + + //when + Map carDtoMap = CarMapperMapSettingOnConfig.INSTANCE.carsToCarDtoMap( null ); + + //then + assertThat( carDtoMap ).isNull(); + } + @ProcessorTest public void shouldApplyConfiguredStrategyForMethodWithSeveralSourceParams() { //when From ca2529f862c2e439a1341d2f3b85189513c140ad Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 31 Oct 2021 16:46:35 +0100 Subject: [PATCH 0618/1006] #598: Errors/Warnings now end up in the @Mapper annotated class. (#2634) #598: Errors/Warnings now end up in the @Mapper annotated class. Co-authored-by: Ben Zegveld --- .../MapperAnnotatedFormattingMessenger.java | 136 ++++++++++++++++++ .../processor/MapperCreationProcessor.java | 3 +- .../mapstruct/ap/internal/util/Message.java | 2 + .../AbstractMapper.java | 11 ++ .../ErroneousMapper1.java | 13 ++ .../ErroneousMapper2.java | 14 ++ .../ErroneousPropertyMappingTest.java | 51 +++++++ .../Source.java | 19 +++ .../Target.java | 20 +++ .../UnmappableClass.java | 9 ++ .../nestedbeans/DottedErrorMessageTest.java | 84 ++++++----- 11 files changed, 325 insertions(+), 37 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/AbstractMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper1.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousPropertyMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/UnmappableClass.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java new file mode 100644 index 0000000000..eeb84570b0 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java @@ -0,0 +1,136 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.processor; + +import java.util.stream.Collectors; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.element.VariableElement; +import javax.tools.Diagnostic.Kind; + +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; + +/** + * Handles redirection of errors/warnings so that they're shown on the mapper instead of hidden on a superclass. + * + * @author Ben Zegveld + */ +public class MapperAnnotatedFormattingMessenger implements FormattingMessager { + + private FormattingMessager delegateMessager; + private TypeElement mapperTypeElement; + private TypeUtils typeUtils; + + public MapperAnnotatedFormattingMessenger(FormattingMessager delegateMessager, TypeElement mapperTypeElement, + TypeUtils typeUtils) { + this.delegateMessager = delegateMessager; + this.mapperTypeElement = mapperTypeElement; + this.typeUtils = typeUtils; + } + + @Override + public void printMessage(Message msg, Object... args) { + delegateMessager.printMessage( msg, args ); + } + + @Override + public void printMessage(Element e, Message msg, Object... args) { + delegateMessager + .printMessage( + determineDelegationElement( e ), + determineDelegationMessage( e, msg ), + determineDelegationArguments( e, msg, args ) ); + } + + @Override + public void printMessage(Element e, AnnotationMirror a, Message msg, Object... args) { + delegateMessager + .printMessage( + determineDelegationElement( e ), + a, + determineDelegationMessage( e, msg ), + determineDelegationArguments( e, msg, args ) ); + } + + @Override + public void printMessage(Element e, AnnotationMirror a, AnnotationValue v, Message msg, Object... args) { + delegateMessager + .printMessage( + determineDelegationElement( e ), + a, + v, + determineDelegationMessage( e, msg ), + determineDelegationArguments( e, msg, args ) ); + } + + @Override + public void note(int level, Message log, Object... args) { + delegateMessager.note( level, log, args ); + } + + @Override + public boolean isErroneous() { + return delegateMessager.isErroneous(); + } + + private Object[] determineDelegationArguments(Element e, Message msg, Object[] args) { + if ( methodInMapperClass( e ) ) { + return args; + } + String originalMessage = String.format( msg.getDescription(), args ); + return new Object[] { originalMessage, constructMethod( e ), e.getEnclosingElement().getSimpleName() }; + } + + /** + * ExecutableElement.toString() has different values depending on the compiler. Constructing the method itself + * manually will ensure that the message is always traceable to it's source. + */ + private String constructMethod(Element e) { + if ( e instanceof ExecutableElement ) { + ExecutableElement ee = (ExecutableElement) e; + StringBuilder method = new StringBuilder(); + method.append( typeUtils.asElement( ee.getReturnType() ).getSimpleName() ); + method.append( " " ); + method.append( ee.getSimpleName() ); + method.append( "(" ); + method.append( ee.getParameters() + .stream() + .map( this::parameterToString ) + .collect( Collectors.joining( ", " ) ) ); + method.append( ")" ); + return method.toString(); + } + return e.toString(); + } + + private String parameterToString(VariableElement element) { + return typeUtils.asElement( element.asType() ).getSimpleName() + " " + element.getSimpleName(); + } + + private Message determineDelegationMessage(Element e, Message msg) { + if ( methodInMapperClass( e ) ) { + return msg; + } + if ( msg.getDiagnosticKind() == Kind.ERROR ) { + return Message.MESSAGE_MOVED_TO_MAPPER_ERROR; + } + return Message.MESSAGE_MOVED_TO_MAPPER_WARNING; + } + + private Element determineDelegationElement(Element e) { + return methodInMapperClass( e ) ? e : mapperTypeElement; + } + + private boolean methodInMapperClass(Element e) { + return mapperTypeElement == null || e.equals( mapperTypeElement ) + || e.getEnclosingElement().equals( mapperTypeElement ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 13e0010171..539e40daf5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -96,7 +96,8 @@ public class MapperCreationProcessor implements ModelElementProcessor sourceModel) { this.elementUtils = context.getElementUtils(); this.typeUtils = context.getTypeUtils(); - this.messager = context.getMessager(); + this.messager = + new MapperAnnotatedFormattingMessenger( context.getMessager(), mapperTypeElement, context.getTypeUtils() ); this.options = context.getOptions(); this.versionInformation = context.getVersionInformation(); this.typeFactory = context.getTypeFactory(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 66b37de7a1..9b21e4090f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -20,6 +20,8 @@ public enum Message { // CHECKSTYLE:OFF PROCESSING_NOTE( "processing: %s.", Diagnostic.Kind.NOTE ), CONFIG_NOTE( "applying mapper configuration: %s.", Diagnostic.Kind.NOTE ), + MESSAGE_MOVED_TO_MAPPER_ERROR( "%s Occured at '%s' in '%s'." ), + MESSAGE_MOVED_TO_MAPPER_WARNING( "%s Occured at '%s' in '%s'.", Diagnostic.Kind.WARNING ), BEANMAPPING_CREATE_NOTE( "creating bean mapping method implementation for %s.", Diagnostic.Kind.NOTE ), BEANMAPPING_NO_ELEMENTS( "'nullValueMappingStrategy', 'nullValuePropertyMappingStrategy', 'resultType' and 'qualifiedBy' are undefined in @BeanMapping, define at least one of them." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/AbstractMapper.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/AbstractMapper.java new file mode 100644 index 0000000000..5155ac386c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/AbstractMapper.java @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +public interface AbstractMapper { + + TARGET map(SOURCE source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper1.java new file mode 100644 index 0000000000..95a0784934 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper1.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +import org.mapstruct.Mapper; + +@Mapper +public interface ErroneousMapper1 extends AbstractMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper2.java new file mode 100644 index 0000000000..b75f1a0e73 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousMapper2.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +import org.mapstruct.Mapper; + +@Mapper +public interface ErroneousMapper2 extends AbstractMapper { + @Override + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousPropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousPropertyMappingTest.java new file mode 100644 index 0000000000..147f1d6929 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/ErroneousPropertyMappingTest.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +@IssueKey( "598" ) +@WithClasses( { Source.class, Target.class, UnmappableClass.class, AbstractMapper.class } ) +public class ErroneousPropertyMappingTest { + + @ProcessorTest + @WithClasses( ErroneousMapper1.class ) + @IssueKey( "598" ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapper1.class, + line = 11, + messageRegExp = "Can't map property \"UnmappableClass property\" to \"String property\"\\. " + + "Consider to declare/implement a mapping method: \"String map\\(UnmappableClass value\\)\"\\. " + + "Occured at 'TARGET map\\(SOURCE source\\)' in 'AbstractMapper'\\.") + } + ) + public void testUnmappableSourcePropertyInSuperclass() { + } + + @ProcessorTest + @WithClasses( ErroneousMapper2.class ) + @IssueKey( "598" ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapper2.class, + line = 13, + message = "Can't map property \"UnmappableClass property\" to \"String property\". " + + "Consider to declare/implement a mapping method: \"String map(UnmappableClass value)\".") } ) + public void testMethodOverride() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Source.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Source.java new file mode 100644 index 0000000000..383eb1dbe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Source.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +public class Source { + + private UnmappableClass property; + + public UnmappableClass getProperty() { + return property; + } + + public void setProperty(UnmappableClass property) { + this.property = property; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Target.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Target.java new file mode 100644 index 0000000000..f647ad7afa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/Target.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +public class Target { + + private String property; + + public String getProperty() { + return property; + } + + public void setProperty(String property) { + this.property = property; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/UnmappableClass.java b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/UnmappableClass.java new file mode 100644 index 0000000000..af239fb046 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/erroneous/supermappingwithsubclassmapper/UnmappableClass.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.erroneous.supermappingwithsubclassmapper; + +public class UnmappableClass { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java index fb10616577..f98da19a75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/DottedErrorMessageTest.java @@ -93,11 +93,12 @@ public class DottedErrorMessageTest { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseDeepNestingMapper.class, + @Diagnostic(type = UnmappableDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + - " \"Color house.roof.color\" to \"ColorDto house.roof.color\".") + " \"Color house.roof.color\" to \"ColorDto house.roof.color\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepNestingMapper'.") } ) public void testDeepNestedBeans() { @@ -110,11 +111,12 @@ public void testDeepNestedBeans() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseDeepListMapper.class, + @Diagnostic(type = UnmappableDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + - " \"Wheel car.wheels\" to \"WheelDto car.wheels\".") + " \"Wheel car.wheels\" to \"WheelDto car.wheels\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepListMapper'.") } ) public void testIterables() { @@ -127,11 +129,12 @@ public void testIterables() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseDeepMapKeyMapper.class, + @Diagnostic(type = UnmappableDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + - " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\".") + " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepMapKeyMapper'.") } ) public void testMapKeys() { @@ -144,11 +147,12 @@ public void testMapKeys() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseDeepMapValueMapper.class, + @Diagnostic(type = UnmappableDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + - " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\".") + " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepMapValueMapper'.") } ) public void testMapValues() { @@ -161,11 +165,12 @@ public void testMapValues() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseCollectionElementPropertyMapper.class, + @Diagnostic(type = UnmappableCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"Info computers[].info\" to \"InfoDto computers[].info\".") + " \"Info computers[].info\" to \"InfoDto computers[].info\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseCollectionElementPropertyMapper'.") } ) public void testCollectionElementProperty() { @@ -178,11 +183,12 @@ public void testCollectionElementProperty() { @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { - @Diagnostic(type = BaseValuePropertyMapper.class, + @Diagnostic(type = UnmappableValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 10, + line = 14, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\".") + " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseValuePropertyMapper'.") } ) public void testMapValueProperty() { @@ -220,36 +226,42 @@ public void testMapEnumProperty() { @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = { - @Diagnostic(type = BaseDeepNestingMapper.class, + @Diagnostic(type = UnmappableWarnDeepNestingMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"rgb\". Mapping from " + PROPERTY + - " \"Color house.roof.color\" to \"ColorDto house.roof.color\"."), - @Diagnostic(type = BaseDeepListMapper.class, + " \"Color house.roof.color\" to \"ColorDto house.roof.color\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepNestingMapper'."), + @Diagnostic(type = UnmappableWarnDeepListMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"left\". Mapping from " + COLLECTION_ELEMENT + - " \"Wheel car.wheels\" to \"WheelDto car.wheels\"."), - @Diagnostic(type = BaseDeepMapKeyMapper.class, + " \"Wheel car.wheels\" to \"WheelDto car.wheels\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepListMapper'."), + @Diagnostic(type = UnmappableWarnDeepMapKeyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_KEY + - " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\"."), - @Diagnostic(type = BaseDeepMapValueMapper.class, + " \"Word dictionary.wordMap{:key}\" to \"WordDto dictionary.wordMap{:key}\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepMapKeyMapper'."), + @Diagnostic(type = UnmappableWarnDeepMapValueMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"pronunciation\". Mapping from " + MAP_VALUE + - " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\"."), - @Diagnostic(type = BaseCollectionElementPropertyMapper.class, + " \"ForeignWord dictionary.wordMap{:value}\" to \"ForeignWordDto dictionary.wordMap{:value}\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseDeepMapValueMapper'."), + @Diagnostic(type = UnmappableWarnCollectionElementPropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"Info computers[].info\" to \"InfoDto computers[].info\"."), - @Diagnostic(type = BaseValuePropertyMapper.class, + " \"Info computers[].info\" to \"InfoDto computers[].info\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseCollectionElementPropertyMapper'."), + @Diagnostic(type = UnmappableWarnValuePropertyMapper.class, kind = javax.tools.Diagnostic.Kind.WARNING, - line = 10, + line = 13, message = "Unmapped target property: \"color\". Mapping from " + PROPERTY + - " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\".") + " \"Info catNameMap{:value}.info\" to \"InfoDto catNameMap{:value}.info\"." + + " Occured at 'UserDto userToUserDto(User user)' in 'BaseValuePropertyMapper'.") } ) public void testWarnUnmappedTargetProperties() { From 907d605160386d818e8df0a577fef32da30b147e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 24 Oct 2021 17:20:56 +0200 Subject: [PATCH 0619/1006] #2624 Nested target methods should be inherited for forged Map to Bean methods --- .../ap/internal/model/PropertyMapping.java | 19 ++--- .../ap/test/bugs/_2624/Issue2624Mapper.java | 76 +++++++++++++++++++ .../ap/test/bugs/_2624/Issue2624Test.java | 43 +++++++++++ 3 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 82d2dd53fa..1d902e54e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -309,7 +309,7 @@ else if ( sourceType.isMapType() && targetType.isMapType() ) { assignment = forgeMapMapping( sourceType, targetType, rightHandSide ); } else if ( sourceType.isMapType() && !targetType.isMapType()) { - assignment = forgeMapToBeanMapping( sourceType, targetType, rightHandSide ); + assignment = forgeMapping( sourceType, targetType.withoutBounds(), rightHandSide ); } else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) || ( sourceType.isStreamType() && targetType.isStreamType() ) @@ -753,19 +753,6 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s return createForgedAssignment( source, methodRef, mapMappingMethod ); } - private Assignment forgeMapToBeanMapping(Type sourceType, Type targetType, SourceRHS source) { - - targetType = targetType.withoutBounds(); - ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "{}" ); - - BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder(); - final BeanMappingMethod mapToBeanMappingMethod = builder.mappingContext( ctx ) - .forgedMethod( methodRef ) - .build(); - - return createForgedAssignment( source, methodRef, mapToBeanMappingMethod ); - } - private Assignment forgeMapping(SourceRHS sourceRHS) { Type sourceType; if ( targetWriteAccessorType == AccessorType.ADDER ) { @@ -778,6 +765,10 @@ private Assignment forgeMapping(SourceRHS sourceRHS) { return null; } + return forgeMapping( sourceType, targetType, sourceRHS ); + } + + private Assignment forgeMapping(Type sourceType, Type targetType, SourceRHS sourceRHS) { //Fail fast. If we could not find the method by now, no need to try if ( sourceType.isPrimitive() || targetType.isPrimitive() ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Mapper.java new file mode 100644 index 0000000000..f4d3c3d22d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Mapper.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2624; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2624Mapper { + + Issue2624Mapper INSTANCE = Mappers.getMapper( Issue2624Mapper.class ); + + @Mapping( target = "department.id", source = "did") + @Mapping( target = "department.name", source = "dname") + Employee fromMap(Map source); + + class Employee { + private String id; + private String name; + private Department department; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + } + + class Department { + private String id; + private String name; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Test.java new file mode 100644 index 0000000000..2fb04ef3a0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2624/Issue2624Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2624; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue2624Mapper.class +}) +class Issue2624Test { + + @ProcessorTest + void shouldCorrectlyMapNestedTargetFromMap() { + Map map = new HashMap<>(); + map.put( "id", "1234" ); + map.put( "name", "Tester" ); + map.put( "did", "4321" ); //Department Id + map.put( "dname", "Test" ); // Department name + + Issue2624Mapper.Employee employee = Issue2624Mapper.INSTANCE.fromMap( map ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getId() ).isEqualTo( "1234" ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + Issue2624Mapper.Department department = employee.getDepartment(); + assertThat( department ).isNotNull(); + assertThat( department.getId() ).isEqualTo( "4321" ); + assertThat( department.getName() ).isEqualTo( "Test" ); + } +} From 166eb699c75b60979c3713c1492f98150ccfcac4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 Oct 2021 14:27:24 +0200 Subject: [PATCH 0620/1006] #1752 Always return mapping target when using update methods with return --- .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../internal/model/IterableMappingMethod.ftl | 3 +-- .../ap/internal/model/MapMappingMethod.ftl | 2 +- .../ap/internal/model/StreamMappingMethod.ftl | 3 +-- .../ap/test/array/ArrayMappingTest.java | 13 ++++++--- .../ap/test/bugs/_374/Issue374Test.java | 3 ++- .../simple/BuilderInfoTargetTest.java | 13 +++++++++ .../DefaultCollectionImplementationTest.java | 16 ++++++++++- .../test/collection/map/MapMappingTest.java | 14 ++++++++++ .../ap/test/inheritance/InheritanceTest.java | 14 ++++++++++ .../DefaultStreamImplementationTest.java | 27 +++++++++++++++++++ .../ap/test/array/ScienceMapperImpl.java | 2 +- .../DomainDtoWithNcvsAlwaysMapperImpl.java | 2 +- .../_913/DomainDtoWithNvmsNullMapperImpl.java | 2 +- .../DomainDtoWithPresenceCheckMapperImpl.java | 2 +- .../SourceTargetMapperImpl.java | 2 +- 16 files changed, 104 insertions(+), 16 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 12a03c06ca..81e3b61fd7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -20,7 +20,7 @@ <#if !mapNullToDefault> if ( <#list sourceParametersExcludingPrimitives as sourceParam>${sourceParam.name} == null<#if sourceParam_has_next> && ) { - return<#if returnType.name != "void"> null; + return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /><#else>null; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 3af75079b9..495111b7a1 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -16,8 +16,7 @@ if ( ${sourceParameter.name} == null ) { <#if !mapNullToDefault> - <#-- returned target type starts to miss-align here with target handed via param, TODO is this right? --> - return<#if returnType.name != "void"> null; + return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> <#if resultType.arrayType> <#if existingInstanceMapping> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 1c6e6bad35..443d87cba7 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -16,7 +16,7 @@ if ( ${sourceParameter.name} == null ) { <#if !mapNullToDefault> - return<#if returnType.name != "void"> null; + return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> <#if existingInstanceMapping> ${resultName}.clear(); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index ae48a3477a..860859fc3a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -17,8 +17,7 @@ if ( ${sourceParameter.name} == null ) { <#if !mapNullToDefault> - <#-- returned target type starts to miss-align here with target handed via param, TODO is this right? --> - return<#if returnType.name != "void"> null; + return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> <#if resultType.arrayType> <#if existingInstanceMapping> diff --git a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java index 07113f7cf4..67ef2216d8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/array/ArrayMappingTest.java @@ -123,15 +123,15 @@ public void shouldMapArrayToArrayExistingLargerSizedTarget() { } @ProcessorTest - public void shouldMapTargetToNullWhenNullSource() { - // TODO: What about existing target? + public void shouldReturnMapTargetWhenNullSource() { ScientistDto[] existingTarget = new ScientistDto[]{ new ScientistDto( "Jim" ) }; ScientistDto[] target = ScienceMapper.INSTANCE.scientistsToDtos( null, existingTarget ); - assertThat( target ).isNull(); + assertThat( target ).isNotNull(); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).extracting( "name" ).containsOnly( "Jim" ); } @@ -143,6 +143,7 @@ public void shouldMapBooleanWhenReturnDefault() { boolean[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( false ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( false ); assertThat( ScienceMapper.INSTANCE.nvmMapping( null ) ).isEmpty(); @@ -154,6 +155,7 @@ public void shouldMapShortWhenReturnDefault() { short[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( new short[] { 0 } ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( new short[] { 0 } ); } @@ -163,6 +165,7 @@ public void shouldMapCharWhenReturnDefault() { char[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( new char[] { 0 } ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( new char[] { 0 } ); } @@ -172,6 +175,7 @@ public void shouldMapIntWhenReturnDefault() { int[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( 0 ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( 0 ); } @@ -181,6 +185,7 @@ public void shouldMapLongWhenReturnDefault() { long[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( 0L ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( 0L ); } @@ -190,6 +195,7 @@ public void shouldMapFloatWhenReturnDefault() { float[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( 0.0f ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( 0.0f ); } @@ -199,6 +205,7 @@ public void shouldMapDoubleWhenReturnDefault() { double[] target = ScienceMapper.INSTANCE.nvmMapping( null, existingTarget ); assertThat( target ).containsOnly( 0.0d ); + assertThat( target ).isEqualTo( existingTarget ); assertThat( existingTarget ).containsOnly( 0.0d ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java index 7f174732ff..2bc6d6a170 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_374/Issue374Test.java @@ -41,7 +41,8 @@ public void shouldMapExistingTargetWithConstantToDefault() { Target target2 = new Target(); Target result2 = Issue374Mapper.INSTANCE.map2( null, target2 ); - assertThat( result2 ).isNull(); + assertThat( result2 ).isNotNull(); + assertThat( result2 ).isEqualTo( target2 ); assertThat( target2.getTest() ).isNull(); assertThat( target2.getConstant() ).isNull(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java index 3682f2ccc5..4f3d8b85f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.builder.mappingTarget.simple; import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.GeneratedSource; @@ -36,6 +37,18 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getName() ).isEqualTo( "Bob" ); } + @ProcessorTest + @IssueKey("1752") + public void testSimpleImmutableBuilderFromNullSource() { + SimpleImmutableTarget targetObject = SimpleBuilderMapper.INSTANCE.toImmutable( + null, + SimpleImmutableTarget.builder().age( 3 ).name( "Bob" ) + ); + assertThat( targetObject ).isNotNull(); + assertThat( targetObject.getAge() ).isEqualTo( 3 ); + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + } + @ProcessorTest public void testMutableTargetWithBuilder() { SimpleMutableSource source = new SimpleMutableSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java index 9d360656a0..dccfcf01ca 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/DefaultCollectionImplementationTest.java @@ -159,7 +159,21 @@ public void shouldUseAndReturnTargetParameterForMapping() { SourceTargetMapper.INSTANCE .sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooList(), target ); - assertThat( target == result ).isTrue(); + assertThat( result ).isSameAs( target ); + assertResultList( target ); + } + + @ProcessorTest + @IssueKey("1752") + public void shouldUseAndReturnTargetParameterForNullMapping() { + List target = new ArrayList<>(); + target.add( new TargetFoo( "Bob" ) ); + target.add( new TargetFoo( "Alice" ) ); + Iterable result = + SourceTargetMapper.INSTANCE + .sourceFoosToTargetFoosUsingTargetParameterAndReturn( null, target ); + + assertThat( result ).isSameAs( target ); assertResultList( target ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index ddba51f826..d0dd66d22b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -82,6 +82,20 @@ public void shouldCreateMapMethodImplementationWithReturnedTargetParameter() { assertResult( target ); } + @ProcessorTest + @IssueKey("1752") + public void shouldCreateMapMethodImplementationWithReturnedTargetParameterAndNullSource() { + Map target = new HashMap<>(); + target.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ); + target.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() ); + + Map returnedTarget = SourceTargetMapper.INSTANCE + .stringStringMapToLongDateMapUsingTargetParameterAndReturn( null, target ); + + assertThat( target ).isSameAs( returnedTarget ); + assertResult( target ); + } + private void assertResult(Map target) { assertThat( target ).isNotNull(); assertThat( target ).hasSize( 2 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java index d127a9ac11..aaf299635e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/inheritance/InheritanceTest.java @@ -53,6 +53,20 @@ public void shouldMapAttributeFromSuperTypeUsingReturnedTargetParameter() { assertResult( target ); } + @ProcessorTest + @IssueKey("1752") + public void shouldMapAttributeFromSuperTypeUsingReturnedTargetParameterAndNullSource() { + + TargetExt target = new TargetExt(); + target.setFoo( 42L ); + target.publicFoo = 52L; + target.setBar( 23 ); + TargetBase result = SourceTargetMapper.INSTANCE.sourceToTargetWithTargetParameterAndReturn( null, target ); + + assertThat( target ).isSameAs( result ); + assertResult( target ); + } + private void assertResult(TargetExt target) { assertThat( target ).isNotNull(); assertThat( target.getFoo() ).isEqualTo( Long.valueOf( 42 ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java index 91be53fe64..8e69bafce2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/defaultimplementation/DefaultStreamImplementationTest.java @@ -141,6 +141,19 @@ public void shouldUseAndReturnTargetParameterForArrayMappingAndSmallerArray() { assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); } + @ProcessorTest + @IssueKey("1752") + public void shouldUseAndReturnTargetParameterArrayForNullSource() { + TargetFoo[] target = new TargetFoo[1]; + target[0] = new TargetFoo( "Bob" ); + TargetFoo[] result = + SourceTargetMapper.INSTANCE.streamToArrayUsingTargetParameterAndReturn( null, target ); + + assertThat( result ).isSameAs( target ); + assertThat( target ).isNotNull(); + assertThat( target ).containsOnly( new TargetFoo( "Bob" ) ); + } + @ProcessorTest public void shouldUseAndReturnTargetParameterForMapping() { List target = new ArrayList<>(); @@ -152,6 +165,20 @@ public void shouldUseAndReturnTargetParameterForMapping() { assertResultList( target ); } + @ProcessorTest + @IssueKey("1752") + public void shouldUseAndReturnTargetParameterForNullMapping() { + List target = new ArrayList<>(); + target.add( new TargetFoo( "Bob" ) ); + target.add( new TargetFoo( "Alice" ) ); + Iterable result = + SourceTargetMapper.INSTANCE + .sourceFoosToTargetFoosUsingTargetParameterAndReturn( null, target ); + + assertThat( result ).isSameAs( target ); + assertResultList( target ); + } + @ProcessorTest public void shouldUseDefaultImplementationForListWithoutSetter() { Source source = new Source(); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java index 066901bc45..c1f4557fbf 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/array/ScienceMapperImpl.java @@ -92,7 +92,7 @@ public List scientistsToDtosAsList(Scientist[] scientists) { @Override public ScientistDto[] scientistsToDtos(Scientist[] scientists, ScientistDto[] target) { if ( scientists == null ) { - return null; + return target; } int i = 0; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java index b3a8c89c60..22fed55509 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -128,7 +128,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { @Override public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { if ( source == null ) { - return null; + return target; } if ( target.getStrings() != null ) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java index 59a770d049..e257ac8443 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -143,7 +143,7 @@ public void update(Dto source, Domain target) { @Override public Domain updateWithReturn(Dto source, Domain target) { if ( source == null ) { - return null; + return target; } if ( target.getStrings() != null ) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java index 8cc41c47d5..ddba54dbd1 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -128,7 +128,7 @@ public void update(DtoWithPresenceCheck source, Domain target) { @Override public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { if ( source == null ) { - return null; + return target; } if ( target.getStrings() != null ) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java index 853ad59560..d9e60ad1e1 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java @@ -133,7 +133,7 @@ public void sourceFoosToTargetFoosUsingTargetParameter(List targetFoo @Override public Iterable sourceFoosToTargetFoosUsingTargetParameterAndReturn(Iterable sourceFoos, List targetFoos) { if ( sourceFoos == null ) { - return null; + return targetFoos; } targetFoos.clear(); From 735a5bef6a36644a48bfc5bebde31e217574551c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Nov 2021 09:21:16 +0100 Subject: [PATCH 0621/1006] #2225 Add support for suppressing the generation of the timestamp through Mapper and MapperConfig --- core/src/main/java/org/mapstruct/Mapper.java | 13 +++++++++++ .../main/java/org/mapstruct/MapperConfig.java | 11 ++++++++++ .../ap/internal/model/Decorator.java | 9 ++++++++ .../ap/internal/model/GeneratedType.java | 3 ++- .../mapstruct/ap/internal/model/Mapper.java | 9 ++++++++ .../internal/model/source/DefaultOptions.java | 7 ++++++ .../model/source/DelegatingOptions.java | 4 ++++ .../model/source/MapperConfigOptions.java | 7 ++++++ .../internal/model/source/MapperOptions.java | 7 ++++++ .../processor/MapperCreationProcessor.java | 14 ++++++------ .../SuppressTimestampViaMapper.java | 16 ++++++++++++++ .../SuppressTimestampViaMapperConfig.java | 22 +++++++++++++++++++ .../ap/test/versioninfo/VersionInfoTest.java | 16 ++++++++++++++ 13 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 26442e4ff0..c5aed661f3 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -357,4 +357,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default * @since 1.4 */ Class unexpectedValueMappingException() default IllegalArgumentException.class; + + /** + * Flag indicating whether the addition of a time stamp in the {@code @Generated} annotation should be suppressed. + * i.e. not be added. + * + * The method overrides the flag set in a central configuration set by {@link #config()} + * or through an annotation processor option. + * + * @return whether the addition of a timestamp should be suppressed + * + * @since 1.5 + */ + boolean suppressTimestampInGenerated() default false; } diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index ce239322a2..757a4ab0af 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -329,5 +329,16 @@ MappingInheritanceStrategy mappingInheritanceStrategy() */ Class unexpectedValueMappingException() default IllegalArgumentException.class; + /** + * Flag indicating whether the addition of a time stamp in the {@code @Generated} annotation should be suppressed. + * i.e. not be added. + * + * The method overrides the flag set through an annotation processor option. + * + * @return whether the addition of a timestamp should be suppressed + * + * @since 1.5 + */ + boolean suppressTimestampInGenerated() default false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index a54045dca0..b7dc0effcb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -32,6 +32,7 @@ public static class Builder extends GeneratedTypeBuilder { private boolean hasDelegateConstructor; private String implName; private String implPackage; + private boolean suppressGeneratorTimestamp; public Builder() { super( Builder.class ); @@ -62,6 +63,11 @@ public Builder implPackage(String implPackage) { return this; } + public Builder suppressGeneratorTimestamp(boolean suppressGeneratorTimestamp) { + this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; + return this; + } + public Decorator build() { String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER, Mapper.getFlatName( mapperElement ) ); @@ -86,6 +92,7 @@ public Decorator build() { methods, options, versionInformation, + suppressGeneratorTimestamp, Accessibility.fromModifiers( mapperElement.getModifiers() ), extraImportedTypes, decoratorConstructor @@ -101,6 +108,7 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type Type mapperType, List methods, Options options, VersionInformation versionInformation, + boolean suppressGeneratorTimestamp, Accessibility accessibility, SortedSet extraImports, DecoratorConstructor decoratorConstructor) { super( @@ -112,6 +120,7 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type Arrays.asList( new Field( mapperType, "delegate", true ) ), options, versionInformation, + suppressGeneratorTimestamp, accessibility, extraImports, decoratorConstructor diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 620559ea24..134ab081dc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -103,6 +103,7 @@ public T methods(List methods) { protected GeneratedType(TypeFactory typeFactory, String packageName, String name, Type mapperDefinitionType, List methods, List fields, Options options, VersionInformation versionInformation, + boolean suppressGeneratorTimestamp, Accessibility accessibility, SortedSet extraImportedTypes, Constructor constructor) { this.packageName = packageName; this.name = name; @@ -113,7 +114,7 @@ protected GeneratedType(TypeFactory typeFactory, String packageName, String name this.methods = methods; this.fields = fields; - this.suppressGeneratorTimestamp = options.isSuppressGeneratorTimestamp(); + this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = options.isSuppressGeneratorVersionComment(); this.versionInformation = versionInformation; this.accessibility = accessibility; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index a066b123c9..fa15cd8ed0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -42,6 +42,7 @@ public static class Builder extends GeneratedTypeBuilder { private boolean customName; private String implPackage; private boolean customPackage; + private boolean suppressGeneratorTimestamp; public Builder() { super( Builder.class ); @@ -79,6 +80,11 @@ public Builder implPackage(String implPackage) { return this; } + public Builder suppressGeneratorTimestamp(boolean suppressGeneratorTimestamp) { + this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; + return this; + } + public Mapper build() { String implementationName = implName.replace( CLASS_NAME_PLACEHOLDER, getFlatName( element ) ) + ( decorator == null ? "" : "_" ); @@ -102,6 +108,7 @@ public Mapper build() { methods, options, versionInformation, + suppressGeneratorTimestamp, Accessibility.fromModifiers( element.getModifiers() ), fields, constructor, @@ -121,6 +128,7 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, Type mapperDefinitionType, boolean customPackage, boolean customImplName, List methods, Options options, VersionInformation versionInformation, + boolean suppressGeneratorTimestamp, Accessibility accessibility, List fields, Constructor constructor, Decorator decorator, SortedSet extraImportedTypes ) { @@ -133,6 +141,7 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, fields, options, versionInformation, + suppressGeneratorTimestamp, accessibility, extraImportedTypes, constructor diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 1258707e43..5c76e7face 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -83,6 +83,13 @@ public String componentModel() { return mapper.componentModel().getDefaultValue(); } + public boolean suppressTimestampInGenerated() { + if ( mapper.suppressTimestampInGenerated().hasValue() ) { + return mapper.suppressTimestampInGenerated().getValue(); + } + return options.isSuppressGeneratorTimestamp(); + } + @Override public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { return MappingInheritanceStrategyGem.valueOf( mapper.mappingInheritanceStrategy().getDefaultValue() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 12f610f1ac..50c1d84541 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -68,6 +68,10 @@ public String componentModel() { return next.componentModel(); } + public boolean suppressTimestampInGenerated() { + return next.suppressTimestampInGenerated(); + } + public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { return next.getMappingInheritanceStrategy(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index 623b97bc78..e3ca6162a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -76,6 +76,13 @@ public String componentModel() { return mapperConfig.componentModel().hasValue() ? mapperConfig.componentModel().get() : next().componentModel(); } + @Override + public boolean suppressTimestampInGenerated() { + return mapperConfig.suppressTimestampInGenerated().hasValue() ? + mapperConfig.suppressTimestampInGenerated().get() : + next().suppressTimestampInGenerated(); + } + @Override public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { return mapperConfig.mappingInheritanceStrategy().hasValue() ? diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 3261205116..ed1af34f79 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -105,6 +105,13 @@ public String componentModel() { return mapper.componentModel().hasValue() ? mapper.componentModel().get() : next().componentModel(); } + @Override + public boolean suppressTimestampInGenerated() { + return mapper.suppressTimestampInGenerated().hasValue() ? + mapper.suppressTimestampInGenerated().get() : + next().suppressTimestampInGenerated(); + } + @Override public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { return mapper.mappingInheritanceStrategy().hasValue() ? diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 539e40daf5..bae0cda1ae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -198,13 +198,13 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< .constructorFragments( constructorFragments ) .options( options ) .versionInformation( versionInformation ) - .decorator( getDecorator( element, methods, mapperOptions.implementationName(), - mapperOptions.implementationPackage(), getExtraImports( element, mapperOptions ) ) ) + .decorator( getDecorator( element, methods, mapperOptions ) ) .typeFactory( typeFactory ) .elementUtils( elementUtils ) .extraImports( getExtraImports( element, mapperOptions ) ) .implName( mapperOptions.implementationName() ) .implPackage( mapperOptions.implementationPackage() ) + .suppressGeneratorTimestamp( mapperOptions.suppressTimestampInGenerated() ) .build(); if ( !mappingContext.getForgedMethodsUnderCreation().isEmpty() ) { @@ -226,8 +226,7 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< return mapper; } - private Decorator getDecorator(TypeElement element, List methods, String implName, - String implPackage, SortedSet extraImports) { + private Decorator getDecorator(TypeElement element, List methods, MapperOptions mapperOptions) { DecoratedWithGem decoratedWith = DecoratedWithGem.instanceOn( element ); if ( decoratedWith == null ) { @@ -287,9 +286,10 @@ else if ( constructor.getParameters().size() == 1 ) { .hasDelegateConstructor( hasDelegateConstructor ) .options( options ) .versionInformation( versionInformation ) - .implName( implName ) - .implPackage( implPackage ) - .extraImports( extraImports ) + .implName( mapperOptions.implementationName() ) + .implPackage( mapperOptions.implementationPackage() ) + .extraImports( getExtraImports( element, mapperOptions ) ) + .suppressGeneratorTimestamp( mapperOptions.suppressTimestampInGenerated() ) .build(); return decorator; diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java new file mode 100644 index 0000000000..02a7b467b1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.versioninfo; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(suppressTimestampInGenerated = true) +public interface SuppressTimestampViaMapper { + Object toObject(Object object); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java new file mode 100644 index 0000000000..a471cad028 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.versioninfo; + +import org.mapstruct.Mapper; +import org.mapstruct.MapperConfig; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = SuppressTimestampViaMapperConfig.Config.class) +public interface SuppressTimestampViaMapperConfig { + Object toObject(Object object); + + @MapperConfig(suppressTimestampInGenerated = true) + interface Config { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java index 1eec91b951..f3192b85ad 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java @@ -49,4 +49,20 @@ public void includesCommentAndTimestamp() { .contains( "comments = \"version: " ); } + @ProcessorTest + @WithClasses(SuppressTimestampViaMapper.class) + @IssueKey("2225") + void includesNoTimestampViaMapper() { + generatedSource.forMapper( SuppressTimestampViaMapper.class ).content() + .doesNotContain( "date = \"" ); + } + + @ProcessorTest + @WithClasses(SuppressTimestampViaMapperConfig.class) + @IssueKey("2225") + void includesNoTimestampViaMapperConfig() { + generatedSource.forMapper( SuppressTimestampViaMapperConfig.class ).content() + .doesNotContain( "date = \"" ); + } + } From 72e6b1feb56c228eae5dfb91ee0a6b6c7acc9b42 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 14 Nov 2021 20:11:05 +0100 Subject: [PATCH 0622/1006] #2636: defaultValue combined with qualified should not convert if not needed (#2637) --- core/src/main/java/org/mapstruct/Mapping.java | 8 +++ .../chapter-5-data-type-conversions.asciidoc | 70 +++++++++++++++++++ .../DefaultExpressionUsageMapper.java | 27 +++++++ .../defaults/DefaultValueUsageMapper.java | 27 +++++++ .../qualifier/defaults/DirectoryNode.java | 21 ++++++ .../FaultyDefaultValueUsageMapper.java | 26 +++++++ .../selection/qualifier/defaults/Folder.java | 29 ++++++++ .../defaults/QualifierWithDefaultsTest.java | 51 ++++++++++++++ 8 files changed, 259 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultExpressionUsageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultValueUsageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DirectoryNode.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/FaultyDefaultValueUsageMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/Folder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/QualifierWithDefaultsTest.java diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 7ca637f0ca..92ae29eb54 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -218,6 +218,10 @@ * *

    *

    + * You can use {@link #qualifiedBy()} or {@link #qualifiedByName()} to force the use of a conversion method + * even when one would not apply. (e.g. {@code String} to {@code String}) + *

    + *

    * This attribute can not be used together with {@link #source()}, {@link #defaultValue()}, * {@link #defaultExpression()} or {@link #expression()}. * @@ -295,6 +299,8 @@ * A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple * mapping methods (hand written or generated) qualify and thus would result in an 'Ambiguous mapping methods found' * error. A qualifier is a custom annotation and can be placed on a hand written mapper class or a method. + *

    + * Note that {@link #defaultValue()} usage will also be converted using this qualifier. * * @return the qualifiers * @see Qualifier @@ -309,6 +315,8 @@ * Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and * are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large * number of qualifiers as no custom annotation types are needed. + *

    + * Note that {@link #defaultValue()} usage will also be converted using this qualifier. * * @return One or more qualifier name(s) * @see #qualifiedBy() diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 91f4afb1cf..e456af01ba 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -703,3 +703,73 @@ public interface MovieMapper { ==== Although the used mechanism is the same, the user has to be a bit more careful. Refactoring the name of a defined qualifier in an IDE will neatly refactor all other occurrences as well. This is obviously not the case for changing a name. ==== + +=== Combining qualifiers with defaults +Please note that the `Mapping#defaultValue` is in essence a `String`, which needs to be converted to the `Mapping#target`. Providing a `Mapping#qualifiedByName` or `Mapping#qualifiedBy` will force MapStruct to use that method. If you want different behavior for the `Mapping#defaultValue`, then please provide an appropriate mapping method. This mapping method needs to transforms a `String` into the desired type of `Mapping#target` and also be annotated so that it can be found by the `Mapping#qualifiedByName` or `Mapping#qualifiedBy`. + +.Mapper using defaultValue +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface MovieMapper { + + @Mapping( target = "category", qualifiedByName = "CategoryToString", defaultValue = "DEFAULT" ) + GermanRelease toGerman( OriginalRelease movies ); + + @Named("CategoryToString") + default String defaultValueForQualifier(Category cat) { + // some mapping logic + } +} +---- +==== + +In the above example in case that category is null, the method `CategoryToString( Enum.valueOf( Category.class, "DEFAULT" ) )` will be called and the result will be set to the category field. + +.Mapper using defaultValue and default method. +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface MovieMapper { + + @Mapping( target = "category", qualifiedByName = "CategoryToString", defaultValue = "Unknown" ) + GermanRelease toGerman( OriginalRelease movies ); + + @Named("CategoryToString") + default String defaultValueForQualifier(Category cat) { + // some mapping logic + } + + @Named("CategoryToString") + default String defaultValueForQualifier(String value) { + return value; + } +} +---- +==== +In the above example in case that category is null, the method `defaultValueForQualifier( "Unknown" )` will be called and the result will be set to the category field. + +If the above mentioned methods do not work there is the option to use `defaultExpression` to set the default value. + +.Mapper using defaultExpression +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface MovieMapper { + + @Mapping( target = "category", qualifiedByName = "CategoryToString", defaultExpression = "java(\"Unknown\")" ) + GermanRelease toGerman( OriginalRelease movies ); + + @Named("CategoryToString") + default String defaultValueForQualifier(Category cat) { + // some mapping logic + } +} +---- +==== diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultExpressionUsageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultExpressionUsageMapper.java new file mode 100644 index 0000000000..69c025983e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultExpressionUsageMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface DefaultExpressionUsageMapper { + @Mapping( source = "folder.ancestor.id", target = "parent", + defaultExpression = "java(\"#\")", qualifiedByName = "uuidToString" ) + DirectoryNode convert(Folder folder); + + @Named( "uuidToString" ) + default String uuidToString(UUID id) { + return id.toString(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultValueUsageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultValueUsageMapper.java new file mode 100644 index 0000000000..622cd9193a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DefaultValueUsageMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface DefaultValueUsageMapper { + @Mapping( source = "folder.ancestor.id", target = "parent", + defaultValue = "00000000-0000-4000-0000-000000000000", qualifiedByName = "uuidToString" ) + DirectoryNode convert(Folder folder); + + @Named( "uuidToString" ) + default String uuidToString(UUID id) { + return id.toString(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DirectoryNode.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DirectoryNode.java new file mode 100644 index 0000000000..5f52f07275 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/DirectoryNode.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +/** + * @author Ben Zegveld + */ +class DirectoryNode { + private String parent; + + public void setParent(String parent) { + this.parent = parent; + } + + public String getParent() { + return parent; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/FaultyDefaultValueUsageMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/FaultyDefaultValueUsageMapper.java new file mode 100644 index 0000000000..e394536daa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/FaultyDefaultValueUsageMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +import java.util.UUID; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface FaultyDefaultValueUsageMapper { + @Mapping( source = "folder.ancestor.id", target = "parent", defaultValue = "#", qualifiedByName = "uuidToString" ) + DirectoryNode convert(Folder folder); + + @Named( "uuidToString" ) + default String uuidToString(UUID id) { + return id.toString(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/Folder.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/Folder.java new file mode 100644 index 0000000000..a6e7b5a9b2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/Folder.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +import java.util.UUID; + +/** + * @author Ben Zegveld + */ +class Folder { + private UUID id; + private Folder ancestor; + + Folder(UUID id, Folder ancestor) { + this.id = id; + this.ancestor = ancestor; + } + + public Folder getAncestor() { + return ancestor; + } + + public UUID getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/QualifierWithDefaultsTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/QualifierWithDefaultsTest.java new file mode 100644 index 0000000000..63af9911f6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/qualifier/defaults/QualifierWithDefaultsTest.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.qualifier.defaults; + +import java.util.UUID; +import org.assertj.core.api.Assertions; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@WithClasses( { DirectoryNode.class, Folder.class } ) +public class QualifierWithDefaultsTest { + + @ProcessorTest + @WithClasses( FaultyDefaultValueUsageMapper.class ) + void defaultValueHasInvalidValue() { + Folder rootFolder = new Folder( UUID.randomUUID(), null ); + FaultyDefaultValueUsageMapper faultyMapper = Mappers.getMapper( FaultyDefaultValueUsageMapper.class ); + + Assertions + .assertThatThrownBy( () -> faultyMapper.convert( rootFolder ) ) + .isInstanceOf( IllegalArgumentException.class ); // UUID.valueOf should throw this. + } + + @ProcessorTest + @WithClasses( DefaultValueUsageMapper.class ) + void defaultValuehasUsableValue() { + Folder rootFolder = new Folder( UUID.randomUUID(), null ); + + DirectoryNode node = Mappers.getMapper( DefaultValueUsageMapper.class ).convert( rootFolder ); + + Assertions.assertThat( node.getParent() ).isEqualTo( "00000000-0000-4000-0000-000000000000" ); + } + + @ProcessorTest + @WithClasses( DefaultExpressionUsageMapper.class ) + void defaultExpressionDoesNotGetConverted() { + Folder rootFolder = new Folder( UUID.randomUUID(), null ); + + DirectoryNode node = Mappers.getMapper( DefaultExpressionUsageMapper.class ).convert( rootFolder ); + + Assertions.assertThat( node.getParent() ).isEqualTo( "#" ); + } +} From 29008e12bf4d8f5c2136f8ab3cb6aec8547d3325 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 7 Nov 2021 09:14:13 +0100 Subject: [PATCH 0623/1006] #2005 Parameter type should only be checked if we are mapping from a single argument source --- .../processor/MethodRetrievalProcessor.java | 54 ++++++++++--------- .../test/multisource/MultiSourceMapper.java | 46 ++++++++++++++++ .../multisource/MultiSourceMapperTest.java | 45 ++++++++++++++++ 3 files changed, 119 insertions(+), 26 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/multisource/MultiSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/multisource/MultiSourceMapperTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 9bf55e731f..b226c1a050 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -512,25 +512,39 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List elements); + + Target mapFromCollectionAndPrimitive(Collection elements, int value); + + class Target { + private int value; + private Collection elements; + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public Collection getElements() { + return elements; + } + + public void setElements(Collection elements) { + this.elements = elements; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/multisource/MultiSourceMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/multisource/MultiSourceMapperTest.java new file mode 100644 index 0000000000..c4e1eaaee4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/multisource/MultiSourceMapperTest.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.multisource; + +import java.util.Collections; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +public class MultiSourceMapperTest { + + @IssueKey("2005") + @ProcessorTest + @WithClasses({ + MultiSourceMapper.class + }) + void shouldBeAbleToMapFromPrimitiveAndCollectionAsMultiSource() { + MultiSourceMapper.Target target = MultiSourceMapper.INSTANCE.mapFromPrimitiveAndCollection( + 10, + Collections.singleton( "test" ) + ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( 10 ); + assertThat( target.getElements() ).containsExactly( "test" ); + + target = MultiSourceMapper.INSTANCE.mapFromCollectionAndPrimitive( + Collections.singleton( "otherTest" ), + 20 + ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( 20 ); + assertThat( target.getElements() ).containsExactly( "otherTest" ); + } +} From 13bc0c023c82e40f6cb14b41f5fba462859bd308 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Nov 2021 08:48:08 +0100 Subject: [PATCH 0624/1006] #2553 Support source property paths for maps --- .../ap/internal/model/BeanMappingMethod.java | 23 ++--- .../model/NestedPropertyMappingMethod.java | 22 +++-- .../NestedTargetPropertyMappingHolder.java | 2 +- .../model/beanmapping/SourceReference.java | 84 ++++--------------- .../ap/internal/model/common/Type.java | 50 +++++++++++ .../ap/test/frommap/FromMapMappingTest.java | 14 ++++ ...FromMapAndNestedMapWithDefinedMapping.java | 57 +++++++++++++ 7 files changed, 162 insertions(+), 90 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMapWithDefinedMapping.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0b299067f5..37dec16410 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -504,7 +504,7 @@ private void handleUnprocessedDefinedTargets() { .build(); Accessor targetPropertyReadAccessor = - method.getResultType().getPropertyReadAccessors().get( propertyName ); + method.getResultType().getReadAccessor( propertyName ); MappingReferences mappingRefs = extractMappingReferences( propertyName, true ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) @@ -1047,7 +1047,7 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp } Accessor targetWriteAccessor = unprocessedTargetProperties.get( targetPropertyName ); - Accessor targetReadAccessor = resultTypeToMap.getPropertyReadAccessors().get( targetPropertyName ); + Accessor targetReadAccessor = resultTypeToMap.getReadAccessor( targetPropertyName ); if ( targetWriteAccessor == null ) { if ( targetReadAccessor == null ) { @@ -1389,7 +1389,7 @@ private void applyPropertyNameBasedMapping(List sourceReference } Accessor targetPropertyReadAccessor = - method.getResultType().getPropertyReadAccessors().get( targetPropertyName ); + method.getResultType().getReadAccessor( targetPropertyName ); MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) .sourceMethod( method ) @@ -1432,7 +1432,7 @@ private void applyParameterNameBasedMapping() { .build(); Accessor targetPropertyReadAccessor = - method.getResultType().getPropertyReadAccessors().get( targetProperty.getKey() ); + method.getResultType().getReadAccessor( targetProperty.getKey() ); MappingReferences mappingRefs = extractMappingReferences( targetProperty.getKey(), false ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) @@ -1473,22 +1473,11 @@ private SourceReference getSourceRefByTargetName(Parameter sourceParameter, Stri return sourceRef; } - if ( sourceParameter.getType().isMapType() ) { - List typeParameters = sourceParameter.getType().getTypeParameters(); - if ( typeParameters.size() == 2 && typeParameters.get( 0 ).isString() ) { - return SourceReference.fromMapSource( - new String[] { targetPropertyName }, - sourceParameter - ); - } - } - - Accessor sourceReadAccessor = - sourceParameter.getType().getPropertyReadAccessors().get( targetPropertyName ); + Accessor sourceReadAccessor = sourceParameter.getType().getReadAccessor( targetPropertyName ); if ( sourceReadAccessor != null ) { // property mapping Accessor sourcePresenceChecker = - sourceParameter.getType().getPropertyPresenceCheckers().get( targetPropertyName ); + sourceParameter.getType().getPresenceChecker( targetPropertyName ); DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); Type returnType = ctx.getTypeFactory().getReturnType( declaredSourceType, sourceReadAccessor ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 82c02f5385..dd87f8e005 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -14,9 +14,12 @@ import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; +import org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck; import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.ValueProvider; +import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.AccessorType; /** * This method is used to convert the nested properties as listed in propertyEntries into a method @@ -165,11 +168,20 @@ public static class SafePropertyEntry { public SafePropertyEntry(PropertyEntry entry, String safeName, String previousPropertyName) { this.safeName = safeName; this.readAccessorName = ValueProvider.of( entry.getReadAccessor() ).getValue(); - if ( entry.getPresenceChecker() != null ) { - this.presenceChecker = new SourceReferenceMethodPresenceCheck( - previousPropertyName, - entry.getPresenceChecker().getSimpleName() - ); + Accessor presenceChecker = entry.getPresenceChecker(); + if ( presenceChecker != null ) { + if ( presenceChecker.getAccessorType() == AccessorType.MAP_CONTAINS ) { + this.presenceChecker = new SourceReferenceContainsKeyPresenceCheck( + previousPropertyName, + presenceChecker.getSimpleName() + ); + } + else { + this.presenceChecker = new SourceReferenceMethodPresenceCheck( + previousPropertyName, + presenceChecker.getSimpleName() + ); + } } else { this.presenceChecker = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 254ba62871..402c2447b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -642,7 +642,7 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences m boolean forceUpdateMethod) { Accessor targetWriteAccessor = targetPropertiesWriteAccessors.get( targetPropertyName ); - Accessor targetReadAccessor = targetType.getPropertyReadAccessors().get( targetPropertyName ); + Accessor targetReadAccessor = targetType.getReadAccessor( targetPropertyName ); if ( targetWriteAccessor == null ) { Set readAccessors = targetType.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 15b10b5782..47f4830838 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -7,16 +7,13 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; -import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; @@ -27,8 +24,6 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; -import org.mapstruct.ap.internal.util.accessor.MapValuePresenceChecker; import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.last; @@ -51,32 +46,13 @@ *

  • {@code propertyEntries[1]} will describe {@code propB}
  • * * - * After building, {@link #isValid()} will return true when when no problems are detected during building. + * After building, {@link #isValid()} will return true when no problems are detected during building. * * @author Sjaak Derksen + * @author Filip Hrisafov */ public class SourceReference extends AbstractReference { - public static SourceReference fromMapSource(String[] segments, Parameter parameter) { - Type parameterType = parameter.getType(); - Type valueType = parameterType.getTypeParameters().get( 1 ); - - TypeElement typeElement = parameterType.getTypeElement(); - TypeMirror typeMirror = valueType.getTypeMirror(); - String simpleName = String.join( ".", segments ); - - MapValueAccessor mapValueAccessor = new MapValueAccessor( typeElement, typeMirror, simpleName ); - MapValuePresenceChecker mapValuePresenceChecker = new MapValuePresenceChecker( - typeElement, - typeMirror, - simpleName - ); - List entries = Collections.singletonList( - PropertyEntry.forSourceReference( segments, mapValueAccessor, mapValuePresenceChecker, valueType ) - ); - return new SourceReference( parameter, entries, true ); - } - /** * Builds a {@link SourceReference} from an {@code @Mappping}. */ @@ -173,11 +149,6 @@ public SourceReference build() { * @return the source reference */ private SourceReference buildFromSingleSourceParameters(String[] segments, Parameter parameter) { - - if ( canBeTreatedAsMapSourceType( parameter.getType() ) ) { - return fromMapSource( segments, parameter ); - } - boolean foundEntryMatch; String[] propertyNames = segments; @@ -214,14 +185,6 @@ private SourceReference buildFromSingleSourceParameters(String[] segments, Param */ private SourceReference buildFromMultipleSourceParameters(String[] segments, Parameter parameter) { - if (parameter != null && canBeTreatedAsMapSourceType( parameter.getType() )) { - String[] propertyNames = new String[0]; - if ( segments.length > 1 ) { - propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - } - return fromMapSource( propertyNames, parameter ); - } - boolean foundEntryMatch; String[] propertyNames = new String[0]; @@ -244,17 +207,8 @@ private SourceReference buildFromMultipleSourceParameters(String[] segments, Par return new SourceReference( parameter, entries, foundEntryMatch ); } - private boolean canBeTreatedAsMapSourceType(Type type) { - if ( !type.isMapType() ) { - return false; - } - - List typeParameters = type.getTypeParameters(); - return typeParameters.size() == 2 && typeParameters.get( 0 ).isString(); - } - /** - * When there are more than one source parameters, the first segment name of the propery + * When there are more than one source parameters, the first segment name of the property * needs to match the parameter name to avoid ambiguity * * consider: {@code Target map( Source1 source1, Source2 source2 )} @@ -356,24 +310,20 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent Type newType = type; for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; - Map sourceReadAccessors = newType.getPropertyReadAccessors(); - Map sourcePresenceCheckers = newType.getPropertyPresenceCheckers(); - - for ( Map.Entry getter : sourceReadAccessors.entrySet() ) { - if ( getter.getKey().equals( entryNames[i] ) ) { - newType = typeFactory.getReturnType( - (DeclaredType) newType.getTypeMirror(), - getter.getValue() - ); - sourceEntries.add( forSourceReference( - Arrays.copyOf( entryNames, i + 1 ), - getter.getValue(), - sourcePresenceCheckers.get( entryNames[i] ), - newType - ) ); - matchFound = true; - break; - } + Accessor readAccessor = newType.getReadAccessor( entryNames[i] ); + if ( readAccessor != null ) { + Accessor presenceChecker = newType.getPresenceChecker( entryNames[i] ); + newType = typeFactory.getReturnType( + (DeclaredType) newType.getTypeMirror(), + readAccessor + ); + sourceEntries.add( forSourceReference( + Arrays.copyOf( entryNames, i + 1 ), + readAccessor, + presenceChecker, + newType + ) ); + matchFound = true; } if ( !matchFound ) { break; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 00bcae371c..4abec925cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -48,6 +48,8 @@ import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; +import org.mapstruct.ap.internal.util.accessor.MapValuePresenceChecker; import static org.mapstruct.ap.internal.util.Collections.first; @@ -60,6 +62,7 @@ * through {@link TypeFactory}. * * @author Gunnar Morling + * @author Filip Hrisafov */ public class Type extends ModelElement implements Comparable { @@ -308,6 +311,17 @@ public boolean isMapType() { return isMapType; } + private boolean hasStringMapSignature() { + if ( isMapType() ) { + List typeParameters = getTypeParameters(); + if ( typeParameters.size() == 2 && typeParameters.get( 0 ).isString() ) { + return true; + } + } + + return false; + } + public boolean isCollectionOrMapType() { return isCollectionType || isMapType; } @@ -597,6 +611,42 @@ public Type asRawType() { } } + public Accessor getReadAccessor(String propertyName) { + if ( hasStringMapSignature() ) { + ExecutableElement getMethod = getAllMethods() + .stream() + .filter( m -> m.getSimpleName().contentEquals( "get" ) ) + .filter( m -> m.getParameters().size() == 1 ) + .findAny() + .orElse( null ); + return new MapValueAccessor( getMethod, typeParameters.get( 1 ).getTypeMirror(), propertyName ); + } + + Map readAccessors = getPropertyReadAccessors(); + + return readAccessors.get( propertyName ); + } + + public Accessor getPresenceChecker(String propertyName) { + if ( hasStringMapSignature() ) { + ExecutableElement containsKeyMethod = getAllMethods() + .stream() + .filter( m -> m.getSimpleName().contentEquals( "containsKey" ) ) + .filter( m -> m.getParameters().size() == 1 ) + .findAny() + .orElse( null ); + + return new MapValuePresenceChecker( + containsKeyMethod, + typeParameters.get( 1 ).getTypeMirror(), + propertyName + ); + } + + Map presenceCheckers = getPropertyPresenceCheckers(); + return presenceCheckers.get( propertyName ); + } + /** * getPropertyReadAccessors * diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java index 548aecc1ec..bcb78d8dcc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/FromMapMappingTest.java @@ -261,6 +261,20 @@ void shouldMapFromNestedMap() { assertThat( target.getNestedTarget().getStringFromNestedMap() ).isEqualTo( "valueFromNestedMap" ); } + @IssueKey("2553") + @ProcessorTest + @WithClasses(MapToBeanFromMapAndNestedMapWithDefinedMapping.class) + void shouldMapFromNestedMapWithDefinedMapping() { + + MapToBeanFromMapAndNestedMapWithDefinedMapping.Source source = + new MapToBeanFromMapAndNestedMapWithDefinedMapping.Source(); + MapToBeanFromMapAndNestedMapWithDefinedMapping.Target target = + MapToBeanFromMapAndNestedMapWithDefinedMapping.INSTANCE.toTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getNested() ).isEqualTo( "valueFromNestedMap" ); + } + @ProcessorTest @WithClasses(ObjectMapToBeanWithQualifierMapper.class) void shouldUseObjectQualifiedMethod() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMapWithDefinedMapping.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMapWithDefinedMapping.java new file mode 100644 index 0000000000..2203836ea6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMapWithDefinedMapping.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.frommap; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MapToBeanFromMapAndNestedMapWithDefinedMapping { + + MapToBeanFromMapAndNestedMapWithDefinedMapping INSTANCE = Mappers.getMapper( + MapToBeanFromMapAndNestedMapWithDefinedMapping.class ); + + @Mapping(target = "nested", source = "nestedTarget.nested") + Target toTarget(Source source); + + class Source { + + private Map nestedTarget = new HashMap<>(); + + public Map getNestedTarget() { + return nestedTarget; + } + + public void setNestedTarget(Map nestedTarget) { + this.nestedTarget = nestedTarget; + } + + public Source() { + nestedTarget.put( "nested", "valueFromNestedMap" ); + } + } + + class Target { + + private String nested; + + public String getNested() { + return nested; + } + + public void setNested(String nested) { + this.nested = nested; + } + } + +} From 754aaf2ef4a15e7956abb4178c4e79c3d821882d Mon Sep 17 00:00:00 2001 From: dersvenhesse Date: Sun, 21 Nov 2021 22:01:09 +0100 Subject: [PATCH 0625/1006] [DOCS] Fixed reference variable --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 2d2b930114..370c09e249 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -696,7 +696,7 @@ public class CustomerMapperImpl implements CustomerMapper { customer.setId( Integer.parseInt( map.get( "id" ) ) ); } if ( map.containsKey( "customerName" ) ) { - customer.setName( source.get( "customerName" ) ); + customer.setName( map.get( "customerName" ) ); } // ... } From 00df0bc3d0ab347fb79d726c3b19417b04b503c2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 3 Dec 2021 19:13:41 +0100 Subject: [PATCH 0626/1006] #2680 Refactor accessors Split the `PresenceCheck`s accessor from the current `Accessor`. Introduce a `ReadAccessor` that would allow us to more easily implement certain things. Remove `MAP_GET` and `MAP_CONTAINS` from the AccessorType and use the new refactored mechanism --- .../ap/internal/model/BeanMappingMethod.java | 21 +++--- .../model/NestedPropertyMappingMethod.java | 29 +++------ .../NestedTargetPropertyMappingHolder.java | 3 +- .../ap/internal/model/PropertyMapping.java | 42 +++++------- .../model/beanmapping/PropertyEntry.java | 18 +++--- .../model/beanmapping/SourceReference.java | 19 +++--- .../ap/internal/model/common/Type.java | 64 +++++++++---------- ...urceReferenceContainsKeyPresenceCheck.java | 59 ----------------- ...nceCheck.java => SuffixPresenceCheck.java} | 20 +++--- .../mapstruct/ap/internal/util/Filters.java | 25 +++----- .../ap/internal/util/ValueProvider.java | 58 ----------------- .../internal/util/accessor/AccessorType.java | 5 +- .../util/accessor/DelegateAccessor.java | 48 ++++++++++++++ .../util/accessor/MapValueAccessor.java | 9 ++- .../accessor/MapValuePresenceChecker.java | 55 ---------------- .../util/accessor/PresenceCheckAccessor.java | 29 +++++++++ .../internal/util/accessor/ReadAccessor.java | 36 +++++++++++ .../util/accessor/ReadDelegateAccessor.java | 17 +++++ ...ourceReferenceContainsKeyPresenceCheck.ftl | 9 --- ...senceCheck.ftl => SuffixPresenceCheck.ftl} | 4 +- 20 files changed, 251 insertions(+), 319 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java rename processor/src/main/java/org/mapstruct/ap/internal/model/presence/{SourceReferenceMethodPresenceCheck.java => SuffixPresenceCheck.java} (66%) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java delete mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl rename processor/src/main/resources/org/mapstruct/ap/internal/model/presence/{SourceReferenceMethodPresenceCheck.ftl => SuffixPresenceCheck.ftl} (72%) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 37dec16410..bdfd8cf54a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -64,6 +64,8 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; import org.mapstruct.ap.internal.util.accessor.ParameterElementAccessor; +import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.model.beanmapping.MappingReferences.forSourceMethod; import static org.mapstruct.ap.internal.util.Collections.first; @@ -257,9 +259,9 @@ else if ( !method.isUpdateMethod() ) { continue; } - Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); + Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); - for ( Entry entry : readAccessors.entrySet() ) { + for ( Entry entry : readAccessors.entrySet() ) { unprocessedSourceProperties.put( entry.getKey(), entry.getValue() ); } } @@ -503,7 +505,7 @@ private void handleUnprocessedDefinedTargets() { .name( propertyName ) .build(); - Accessor targetPropertyReadAccessor = + ReadAccessor targetPropertyReadAccessor = method.getResultType().getReadAccessor( propertyName ); MappingReferences mappingRefs = extractMappingReferences( propertyName, true ); PropertyMapping propertyMapping = new PropertyMappingBuilder() @@ -1047,7 +1049,7 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp } Accessor targetWriteAccessor = unprocessedTargetProperties.get( targetPropertyName ); - Accessor targetReadAccessor = resultTypeToMap.getReadAccessor( targetPropertyName ); + ReadAccessor targetReadAccessor = resultTypeToMap.getReadAccessor( targetPropertyName ); if ( targetWriteAccessor == null ) { if ( targetReadAccessor == null ) { @@ -1388,7 +1390,7 @@ private void applyPropertyNameBasedMapping(List sourceReference continue; } - Accessor targetPropertyReadAccessor = + ReadAccessor targetPropertyReadAccessor = method.getResultType().getReadAccessor( targetPropertyName ); MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) @@ -1431,7 +1433,7 @@ private void applyParameterNameBasedMapping() { .name( targetProperty.getKey() ) .build(); - Accessor targetPropertyReadAccessor = + ReadAccessor targetPropertyReadAccessor = method.getResultType().getReadAccessor( targetProperty.getKey() ); MappingReferences mappingRefs = extractMappingReferences( targetProperty.getKey(), false ); PropertyMapping propertyMapping = new PropertyMappingBuilder() @@ -1453,7 +1455,8 @@ private void applyParameterNameBasedMapping() { // The source parameter was directly mapped so ignore all of its source properties completely if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) { // We explicitly ignore source properties from primitives or array types - Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); + Map readAccessors = sourceParameter.getType() + .getPropertyReadAccessors(); for ( String sourceProperty : readAccessors.keySet() ) { unprocessedSourceProperties.remove( sourceProperty ); } @@ -1473,10 +1476,10 @@ private SourceReference getSourceRefByTargetName(Parameter sourceParameter, Stri return sourceRef; } - Accessor sourceReadAccessor = sourceParameter.getType().getReadAccessor( targetPropertyName ); + ReadAccessor sourceReadAccessor = sourceParameter.getType().getReadAccessor( targetPropertyName ); if ( sourceReadAccessor != null ) { // property mapping - Accessor sourcePresenceChecker = + PresenceCheckAccessor sourcePresenceChecker = sourceParameter.getType().getPresenceChecker( targetPropertyName ); DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index dd87f8e005..96004cb474 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -10,16 +10,13 @@ import java.util.Objects; import java.util.Set; +import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.beanmapping.PropertyEntry; -import org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck; -import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; +import org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck; import org.mapstruct.ap.internal.util.Strings; -import org.mapstruct.ap.internal.util.ValueProvider; -import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.AccessorType; +import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; /** * This method is used to convert the nested properties as listed in propertyEntries into a method @@ -167,21 +164,13 @@ public static class SafePropertyEntry { public SafePropertyEntry(PropertyEntry entry, String safeName, String previousPropertyName) { this.safeName = safeName; - this.readAccessorName = ValueProvider.of( entry.getReadAccessor() ).getValue(); - Accessor presenceChecker = entry.getPresenceChecker(); + this.readAccessorName = entry.getReadAccessor().getReadValueSource(); + PresenceCheckAccessor presenceChecker = entry.getPresenceChecker(); if ( presenceChecker != null ) { - if ( presenceChecker.getAccessorType() == AccessorType.MAP_CONTAINS ) { - this.presenceChecker = new SourceReferenceContainsKeyPresenceCheck( - previousPropertyName, - presenceChecker.getSimpleName() - ); - } - else { - this.presenceChecker = new SourceReferenceMethodPresenceCheck( - previousPropertyName, - presenceChecker.getSimpleName() - ); - } + this.presenceChecker = new SuffixPresenceCheck( + previousPropertyName, + presenceChecker.getPresenceCheckSuffix() + ); } else { this.presenceChecker = null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 402c2447b2..61e3926047 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -21,6 +21,7 @@ import org.mapstruct.ap.internal.model.beanmapping.SourceReference; import org.mapstruct.ap.internal.model.beanmapping.TargetReference; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; @@ -642,7 +643,7 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences m boolean forceUpdateMethod) { Accessor targetWriteAccessor = targetPropertiesWriteAccessors.get( targetPropertyName ); - Accessor targetReadAccessor = targetType.getReadAccessor( targetPropertyName ); + ReadAccessor targetReadAccessor = targetType.getReadAccessor( targetPropertyName ); if ( targetWriteAccessor == null ) { Set readAccessors = targetType.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 1d902e54e7..c83f856587 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -37,8 +37,7 @@ import org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck; import org.mapstruct.ap.internal.model.presence.JavaExpressionPresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; -import org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck; -import org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck; +import org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck; import org.mapstruct.ap.internal.model.source.DelegatingOptions; import org.mapstruct.ap.internal.model.source.MappingControl; import org.mapstruct.ap.internal.model.source.MappingOptions; @@ -48,9 +47,9 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.Strings; -import org.mapstruct.ap.internal.util.ValueProvider; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; @@ -73,7 +72,7 @@ public class PropertyMapping extends ModelElement { private final String name; private final String sourceBeanName; private final String targetWriteAccessorName; - private final ValueProvider targetReadAccessorProvider; + private final ReadAccessor targetReadAccessorProvider; private final Type targetType; private final Assignment assignment; private final Set dependsOn; @@ -87,7 +86,7 @@ private static class MappingBuilderBase> extends protected AccessorType targetWriteAccessorType; protected Type targetType; protected BuilderType targetBuilderType; - protected Accessor targetReadAccessor; + protected ReadAccessor targetReadAccessor; protected String targetPropertyName; protected String sourcePropertyName; @@ -103,7 +102,7 @@ public T sourceMethod(Method sourceMethod) { return super.method( sourceMethod ); } - public T target(String targetPropertyName, Accessor targetReadAccessor, Accessor targetWriteAccessor) { + public T target(String targetPropertyName, ReadAccessor targetReadAccessor, Accessor targetWriteAccessor) { this.targetPropertyName = targetPropertyName; this.targetReadAccessor = targetReadAccessor; this.targetWriteAccessor = targetWriteAccessor; @@ -290,7 +289,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get targetPropertyName, rightHandSide.getSourceParameterName(), targetWriteAccessor.getSimpleName(), - ValueProvider.of( targetReadAccessor ), + targetReadAccessor, targetType, assignment, dependsOn, @@ -567,7 +566,7 @@ private SourceRHS getSourceRHS( SourceReference sourceReference ) { } // simple property else if ( !sourceReference.isNested() ) { - String sourceRef = sourceParam.getName() + "." + ValueProvider.of( propertyEntry.getReadAccessor() ); + String sourceRef = sourceParam.getName() + "." + propertyEntry.getReadAccessor().getReadValueSource(); SourceRHS sourceRHS = new SourceRHS( sourceParam.getName(), sourceRef, @@ -660,28 +659,21 @@ private PresenceCheck getSourcePresenceCheckerRef(SourceReference sourceReferenc // in the forged method? PropertyEntry propertyEntry = sourceReference.getShallowestProperty(); if ( propertyEntry.getPresenceChecker() != null ) { - if (propertyEntry.getPresenceChecker().getAccessorType() == AccessorType.MAP_CONTAINS ) { - return new SourceReferenceContainsKeyPresenceCheck( - sourceParam.getName(), - propertyEntry.getPresenceChecker().getSimpleName() - ); - } - List presenceChecks = new ArrayList<>(); - presenceChecks.add( new SourceReferenceMethodPresenceCheck( + presenceChecks.add( new SuffixPresenceCheck( sourceParam.getName(), - propertyEntry.getPresenceChecker().getSimpleName() + propertyEntry.getPresenceChecker().getPresenceCheckSuffix() ) ); String variableName = sourceParam.getName() + "." - + propertyEntry.getReadAccessor().getSimpleName() + "()"; + + propertyEntry.getReadAccessor().getReadValueSource(); for (int i = 1; i < sourceReference.getPropertyEntries().size(); i++) { PropertyEntry entry = sourceReference.getPropertyEntries().get( i ); if (entry.getPresenceChecker() != null && entry.getReadAccessor() != null) { presenceChecks.add( new NullPresenceCheck( variableName ) ); - presenceChecks.add( new SourceReferenceMethodPresenceCheck( + presenceChecks.add( new SuffixPresenceCheck( variableName, - entry.getPresenceChecker().getSimpleName() + entry.getPresenceChecker().getPresenceCheckSuffix() ) ); variableName = variableName + "." + entry.getReadAccessor().getSimpleName() + "()"; } @@ -992,7 +984,7 @@ else if ( errorMessageDetails == null ) { return new PropertyMapping( targetPropertyName, targetWriteAccessor.getSimpleName(), - ValueProvider.of( targetReadAccessor ), + targetReadAccessor, targetType, assignment, dependsOn, @@ -1058,7 +1050,7 @@ public PropertyMapping build() { return new PropertyMapping( targetPropertyName, targetWriteAccessor.getSimpleName(), - ValueProvider.of( targetReadAccessor ), + targetReadAccessor, targetType, assignment, dependsOn, @@ -1071,7 +1063,7 @@ public PropertyMapping build() { // Constructor for creating mappings of constant expressions. private PropertyMapping(String name, String targetWriteAccessorName, - ValueProvider targetReadAccessorProvider, + ReadAccessor targetReadAccessorProvider, Type targetType, Assignment propertyAssignment, Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { this( name, null, targetWriteAccessorName, targetReadAccessorProvider, @@ -1081,7 +1073,7 @@ private PropertyMapping(String name, String targetWriteAccessorName, } private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, - ValueProvider targetReadAccessorProvider, Type targetType, + ReadAccessor targetReadAccessorProvider, Type targetType, Assignment assignment, Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { this.name = name; @@ -1112,7 +1104,7 @@ public String getTargetWriteAccessorName() { } public String getTargetReadAccessorName() { - return targetReadAccessorProvider == null ? null : targetReadAccessorProvider.getValue(); + return targetReadAccessorProvider == null ? null : targetReadAccessorProvider.getReadValueSource(); } public Type getTargetType() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java index 8ac5e46671..cb6cd8af79 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java @@ -9,7 +9,8 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.Strings; -import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; /** * A PropertyEntry contains information on the name, readAccessor and presenceCheck (for source) @@ -18,8 +19,8 @@ public class PropertyEntry { private final String[] fullName; - private final Accessor readAccessor; - private final Accessor presenceChecker; + private final ReadAccessor readAccessor; + private final PresenceCheckAccessor presenceChecker; private final Type type; /** @@ -29,7 +30,8 @@ public class PropertyEntry { * @param readAccessor * @param type */ - private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor presenceChecker, Type type) { + private PropertyEntry(String[] fullName, ReadAccessor readAccessor, PresenceCheckAccessor presenceChecker, + Type type) { this.fullName = fullName; this.readAccessor = readAccessor; this.presenceChecker = presenceChecker; @@ -45,8 +47,8 @@ private PropertyEntry(String[] fullName, Accessor readAccessor, Accessor presenc * @param type type of the property * @return the property entry for given parameters. */ - public static PropertyEntry forSourceReference(String[] name, Accessor readAccessor, - Accessor presenceChecker, Type type) { + public static PropertyEntry forSourceReference(String[] name, ReadAccessor readAccessor, + PresenceCheckAccessor presenceChecker, Type type) { return new PropertyEntry( name, readAccessor, presenceChecker, type ); } @@ -54,11 +56,11 @@ public String getName() { return fullName[fullName.length - 1]; } - public Accessor getReadAccessor() { + public ReadAccessor getReadAccessor() { return readAccessor; } - public Accessor getPresenceChecker() { + public PresenceCheckAccessor getPresenceChecker() { return presenceChecker; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 47f4830838..d5c18a99f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -23,7 +23,8 @@ import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.Strings; -import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.model.beanmapping.PropertyEntry.forSourceReference; import static org.mapstruct.ap.internal.util.Collections.last; @@ -310,9 +311,9 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent Type newType = type; for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; - Accessor readAccessor = newType.getReadAccessor( entryNames[i] ); + ReadAccessor readAccessor = newType.getReadAccessor( entryNames[i] ); if ( readAccessor != null ) { - Accessor presenceChecker = newType.getPresenceChecker( entryNames[i] ); + PresenceCheckAccessor presenceChecker = newType.getPresenceChecker( entryNames[i] ); newType = typeFactory.getReturnType( (DeclaredType) newType.getTypeMirror(), readAccessor @@ -343,8 +344,8 @@ private void reportMappingError(Message msg, Object... objects) { public static class BuilderFromProperty { private String name; - private Accessor readAccessor; - private Accessor presenceChecker; + private ReadAccessor readAccessor; + private PresenceCheckAccessor presenceChecker; private Type type; private Parameter sourceParameter; @@ -353,12 +354,12 @@ public BuilderFromProperty name(String name) { return this; } - public BuilderFromProperty readAccessor(Accessor readAccessor) { + public BuilderFromProperty readAccessor(ReadAccessor readAccessor) { this.readAccessor = readAccessor; return this; } - public BuilderFromProperty presenceChecker(Accessor presenceChecker) { + public BuilderFromProperty presenceChecker(PresenceCheckAccessor presenceChecker) { this.presenceChecker = presenceChecker; return this; } @@ -430,10 +431,10 @@ public List push(TypeFactory typeFactory, FormattingMessager me PropertyEntry deepestProperty = getDeepestProperty(); if ( deepestProperty != null ) { Type type = deepestProperty.getType(); - Map newDeepestReadAccessors = type.getPropertyReadAccessors(); + Map newDeepestReadAccessors = type.getPropertyReadAccessors(); String parameterName = getParameter().getName(); String deepestPropertyFullName = deepestProperty.getFullName(); - for ( Map.Entry newDeepestReadAccessorEntry : newDeepestReadAccessors.entrySet() ) { + for ( Map.Entry newDeepestReadAccessorEntry : newDeepestReadAccessors.entrySet() ) { // Always include the parameter name in the new full name. // Otherwise multi source parameters might be reported incorrectly String newFullName = diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 4abec925cf..ab2871c69d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -48,8 +48,10 @@ import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; +import org.mapstruct.ap.internal.util.accessor.FieldElementAccessor; import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; -import org.mapstruct.ap.internal.util.accessor.MapValuePresenceChecker; +import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.util.Collections.first; @@ -101,8 +103,8 @@ public class Type extends ModelElement implements Comparable { private final Map notToBeImportedTypes; private Boolean isToBeImported; - private Map readAccessors = null; - private Map presenceCheckers = null; + private Map readAccessors = null; + private Map presenceCheckers = null; private List allMethods = null; private List allFields = null; @@ -611,7 +613,7 @@ public Type asRawType() { } } - public Accessor getReadAccessor(String propertyName) { + public ReadAccessor getReadAccessor(String propertyName) { if ( hasStringMapSignature() ) { ExecutableElement getMethod = getAllMethods() .stream() @@ -622,28 +624,17 @@ public Accessor getReadAccessor(String propertyName) { return new MapValueAccessor( getMethod, typeParameters.get( 1 ).getTypeMirror(), propertyName ); } - Map readAccessors = getPropertyReadAccessors(); + Map readAccessors = getPropertyReadAccessors(); return readAccessors.get( propertyName ); } - public Accessor getPresenceChecker(String propertyName) { + public PresenceCheckAccessor getPresenceChecker(String propertyName) { if ( hasStringMapSignature() ) { - ExecutableElement containsKeyMethod = getAllMethods() - .stream() - .filter( m -> m.getSimpleName().contentEquals( "containsKey" ) ) - .filter( m -> m.getParameters().size() == 1 ) - .findAny() - .orElse( null ); - - return new MapValuePresenceChecker( - containsKeyMethod, - typeParameters.get( 1 ).getTypeMirror(), - propertyName - ); + return PresenceCheckAccessor.mapContainsKey( propertyName ); } - Map presenceCheckers = getPropertyPresenceCheckers(); + Map presenceCheckers = getPropertyPresenceCheckers(); return presenceCheckers.get( propertyName ); } @@ -652,15 +643,15 @@ public Accessor getPresenceChecker(String propertyName) { * * @return an unmodifiable map of all read accessors (including 'is' for booleans), indexed by property name */ - public Map getPropertyReadAccessors() { + public Map getPropertyReadAccessors() { if ( readAccessors == null ) { - Map modifiableGetters = new LinkedHashMap<>(); + Map modifiableGetters = new LinkedHashMap<>(); - Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); + Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); modifiableGetters.putAll( recordAccessors ); - List getterList = filters.getterMethodsIn( getAllMethods() ); - for ( Accessor getter : getterList ) { + List getterList = filters.getterMethodsIn( getAllMethods() ); + for ( ReadAccessor getter : getterList ) { String simpleName = getter.getSimpleName(); if ( recordAccessors.containsKey( simpleName ) ) { // If there is already a record accessor that contains the simple name @@ -690,8 +681,8 @@ public Map getPropertyReadAccessors() { } } - List fieldsList = filters.fieldsIn( getAllFields() ); - for ( Accessor field : fieldsList ) { + List fieldsList = filters.fieldsIn( getAllFields(), ReadAccessor::fromField ); + for ( ReadAccessor field : fieldsList ) { String propertyName = getPropertyName( field ); // If there was no getter or is method for booleans, then resort to the field. // If a field was already added do not add it again. @@ -707,12 +698,15 @@ public Map getPropertyReadAccessors() { * * @return an unmodifiable map of all presence checkers, indexed by property name */ - public Map getPropertyPresenceCheckers() { + public Map getPropertyPresenceCheckers() { if ( presenceCheckers == null ) { - List checkerList = filters.presenceCheckMethodsIn( getAllMethods() ); - Map modifiableCheckers = new LinkedHashMap<>(); - for ( Accessor checker : checkerList ) { - modifiableCheckers.put( getPropertyName( checker ), checker ); + List checkerList = filters.presenceCheckMethodsIn( getAllMethods() ); + Map modifiableCheckers = new LinkedHashMap<>(); + for ( ExecutableElement checker : checkerList ) { + modifiableCheckers.put( + getPropertyName( checker ), + PresenceCheckAccessor.methodInvocation( checker ) + ); } presenceCheckers = Collections.unmodifiableMap( modifiableCheckers ); } @@ -841,13 +835,17 @@ private List nullSafeTypeElementListConversion(Function getAlternativeTargetAccessors() { List setterMethods = getSetters(); List readAccessors = new ArrayList<>( getPropertyReadAccessors().values() ); // All the fields are also alternative accessors - readAccessors.addAll( filters.fieldsIn( getAllFields() ) ); + readAccessors.addAll( filters.fieldsIn( getAllFields(), FieldElementAccessor::new ) ); // there could be a read accessor (field or method) for a list/map that is not present as setter. // an accessor could substitute the setter in that case and act as setter. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java deleted file mode 100644 index d4c011a051..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.model.presence; - -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - -import org.mapstruct.ap.internal.model.common.ModelElement; -import org.mapstruct.ap.internal.model.common.PresenceCheck; -import org.mapstruct.ap.internal.model.common.Type; - -/** - * @author Filip Hrisafov - */ -public class SourceReferenceContainsKeyPresenceCheck extends ModelElement implements PresenceCheck { - - private final String sourceReference; - private final String propertyName; - - public SourceReferenceContainsKeyPresenceCheck(String sourceReference, String propertyName) { - this.sourceReference = sourceReference; - this.propertyName = propertyName; - } - - public String getSourceReference() { - return sourceReference; - } - - public String getPropertyName() { - return propertyName; - } - - @Override - public Set getImportTypes() { - return Collections.emptySet(); - } - - @Override - public boolean equals(Object o) { - if ( this == o ) { - return true; - } - if ( o == null || getClass() != o.getClass() ) { - return false; - } - SourceReferenceContainsKeyPresenceCheck that = (SourceReferenceContainsKeyPresenceCheck) o; - return Objects.equals( sourceReference, that.sourceReference ) && - Objects.equals( propertyName, that.propertyName ); - } - - @Override - public int hashCode() { - return Objects.hash( sourceReference, propertyName ); - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java similarity index 66% rename from processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java rename to processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java index 374eac0c8e..3710e97173 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java @@ -16,22 +16,22 @@ /** * @author Filip Hrisafov */ -public class SourceReferenceMethodPresenceCheck extends ModelElement implements PresenceCheck { +public class SuffixPresenceCheck extends ModelElement implements PresenceCheck { private final String sourceReference; - private final String methodName; + private final String suffix; - public SourceReferenceMethodPresenceCheck(String sourceReference, String methodName) { + public SuffixPresenceCheck(String sourceReference, String suffix) { this.sourceReference = sourceReference; - this.methodName = methodName; + this.suffix = suffix; } public String getSourceReference() { return sourceReference; } - public String getMethodName() { - return methodName; + public String getSuffix() { + return suffix; } @Override @@ -47,13 +47,13 @@ public boolean equals(Object o) { if ( o == null || getClass() != o.getClass() ) { return false; } - SourceReferenceMethodPresenceCheck that = (SourceReferenceMethodPresenceCheck) o; - return Objects.equals( sourceReference, that.sourceReference ) && - Objects.equals( methodName, that.methodName ); + SuffixPresenceCheck that = (SuffixPresenceCheck) o; + return Objects.equals( sourceReference, that.sourceReference ) + && Objects.equals( suffix, that.suffix ); } @Override public int hashCode() { - return Objects.hash( sourceReference, methodName ); + return Objects.hash( sourceReference, suffix ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 9cb923b3c8..123f72832b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -12,6 +12,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; @@ -23,12 +24,10 @@ import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; -import org.mapstruct.ap.internal.util.accessor.FieldElementAccessor; +import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.accessor.AccessorType.ADDER; -import static org.mapstruct.ap.internal.util.accessor.AccessorType.GETTER; -import static org.mapstruct.ap.internal.util.accessor.AccessorType.PRESENCE_CHECKER; import static org.mapstruct.ap.internal.util.accessor.AccessorType.SETTER; /** @@ -68,10 +67,10 @@ public Filters(AccessorNamingUtils accessorNaming, TypeUtils typeUtils, TypeMirr this.typeMirror = typeMirror; } - public List getterMethodsIn(List elements) { + public List getterMethodsIn(List elements) { return elements.stream() .filter( accessorNaming::isGetterMethod ) - .map( method -> new ExecutableElementAccessor( method, getReturnType( method ), GETTER ) ) + .map( method -> ReadAccessor.fromGetter( method, getReturnType( method ) ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } @@ -89,21 +88,18 @@ public List recordComponentsIn(TypeElement typeElement) { } } - public Map recordAccessorsIn(Collection recordComponents) { + public Map recordAccessorsIn(Collection recordComponents) { if ( RECORD_COMPONENT_ACCESSOR_METHOD == null ) { return java.util.Collections.emptyMap(); } try { - Map recordAccessors = new LinkedHashMap<>(); + Map recordAccessors = new LinkedHashMap<>(); for ( Element recordComponent : recordComponents ) { ExecutableElement recordExecutableElement = (ExecutableElement) RECORD_COMPONENT_ACCESSOR_METHOD.invoke( recordComponent ); recordAccessors.put( recordComponent.getSimpleName().toString(), - new ExecutableElementAccessor( recordExecutableElement, - getReturnType( recordExecutableElement ), - GETTER - ) + ReadAccessor.fromGetter( recordExecutableElement, getReturnType( recordExecutableElement ) ) ); } @@ -118,17 +114,16 @@ private TypeMirror getReturnType(ExecutableElement executableElement) { return getWithinContext( executableElement ).getReturnType(); } - public List fieldsIn(List accessors) { + public List fieldsIn(List accessors, Function creator) { return accessors.stream() .filter( Fields::isFieldAccessor ) - .map( FieldElementAccessor::new ) + .map( creator ) .collect( Collectors.toCollection( LinkedList::new ) ); } - public List presenceCheckMethodsIn(List elements) { + public List presenceCheckMethodsIn(List elements) { return elements.stream() .filter( accessorNaming::isPresenceCheckMethod ) - .map( method -> new ExecutableElementAccessor( method, getReturnType( method ), PRESENCE_CHECKER ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java deleted file mode 100644 index 16abd074dd..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ValueProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util; - -import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.AccessorType; - -/** - * This a wrapper class which provides the value that needs to be used in the models. - * - * It is used to provide the read value for a difference kind of {@link Accessor}. - * - * @author Filip Hrisafov - */ -public class ValueProvider { - - private final String value; - - private ValueProvider(String value) { - this.value = value; - } - - public String getValue() { - return value; - } - - @Override - public String toString() { - return value; - } - - /** - * Creates a {@link ValueProvider} from the provided {@code accessor}. The base value is - * {@link Accessor#getSimpleName()}. If the {@code accessor} is for an executable, then {@code ()} is - * appended. - * - * @param accessor that provides the value - * - * @return a {@link ValueProvider} tha provides a read value for the {@code accessor} - */ - public static ValueProvider of(Accessor accessor) { - if ( accessor == null ) { - return null; - } - String value = accessor.getSimpleName(); - if (accessor.getAccessorType() == AccessorType.MAP_GET ) { - value = "get( \"" + value + "\" )"; - return new ValueProvider( value ); - } - if ( !accessor.getAccessorType().isFieldAssignment() ) { - value += "()"; - } - return new ValueProvider( value ); - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java index 4e3b7a4776..112c1c512d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AccessorType.java @@ -11,10 +11,7 @@ public enum AccessorType { FIELD, GETTER, SETTER, - ADDER, - MAP_GET, - MAP_CONTAINS, - PRESENCE_CHECKER; + ADDER; public boolean isFieldAssignment() { return this == FIELD || this == PARAMETER; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java new file mode 100644 index 0000000000..9b2981d7c5 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import java.util.Set; +import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; +import javax.lang.model.type.TypeMirror; + +/** + * @author Filip Hrisafov + */ +public abstract class DelegateAccessor implements Accessor { + + protected final Accessor delegate; + + protected DelegateAccessor(Accessor delegate) { + this.delegate = delegate; + } + + @Override + public TypeMirror getAccessedType() { + return delegate.getAccessedType(); + } + + @Override + public String getSimpleName() { + return delegate.getSimpleName(); + } + + @Override + public Set getModifiers() { + return delegate.getModifiers(); + } + + @Override + public Element getElement() { + return delegate.getElement(); + } + + @Override + public AccessorType getAccessorType() { + return delegate.getAccessorType(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java index ab086d9b0e..7a708995cd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValueAccessor.java @@ -16,7 +16,7 @@ * * @author Christian Kosmowski */ -public class MapValueAccessor implements Accessor { +public class MapValueAccessor implements ReadAccessor { private final TypeMirror valueTypeMirror; private final String simpleName; @@ -50,6 +50,11 @@ public Element getElement() { @Override public AccessorType getAccessorType() { - return AccessorType.MAP_GET; + return AccessorType.GETTER; + } + + @Override + public String getReadValueSource() { + return "get( \"" + getSimpleName() + "\" )"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java deleted file mode 100644 index 3f72ed86c1..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/MapValuePresenceChecker.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.accessor; - -import java.util.Collections; -import java.util.Set; -import javax.lang.model.element.Element; -import javax.lang.model.element.Modifier; -import javax.lang.model.type.TypeMirror; - -/** - * An {@link Accessor} that wraps a Map value. - * - * @author Christian Kosmowski - */ -public class MapValuePresenceChecker implements Accessor { - - private final Element element; - private final TypeMirror valueTypeMirror; - private final String simpleName; - - public MapValuePresenceChecker(Element element, TypeMirror valueTypeMirror, String simpleName) { - this.element = element; - this.valueTypeMirror = valueTypeMirror; - this.simpleName = simpleName; - } - - @Override - public TypeMirror getAccessedType() { - return valueTypeMirror; - } - - @Override - public String getSimpleName() { - return this.simpleName; - } - - @Override - public Set getModifiers() { - return Collections.emptySet(); - } - - @Override - public Element getElement() { - return this.element; - } - - @Override - public AccessorType getAccessorType() { - return AccessorType.MAP_CONTAINS; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java new file mode 100644 index 0000000000..cc974b939f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import javax.lang.model.element.ExecutableElement; + +/** + * @author Filip Hrisafov + */ +public interface PresenceCheckAccessor { + + String getPresenceCheckSuffix(); + + static PresenceCheckAccessor methodInvocation(ExecutableElement element) { + return suffix( "." + element.getSimpleName() + "()" ); + } + + static PresenceCheckAccessor mapContainsKey(String propertyName) { + return suffix( ".containsKey( \"" + propertyName + "\" )" ); + } + + static PresenceCheckAccessor suffix(String suffix) { + return () -> suffix; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java new file mode 100644 index 0000000000..a790a3361b --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; + +/** + * @author Filip Hrisafov + */ +public interface ReadAccessor extends Accessor { + + String getReadValueSource(); + + static ReadAccessor fromField(VariableElement variableElement) { + return new ReadDelegateAccessor( new FieldElementAccessor( variableElement ) ) { + @Override + public String getReadValueSource() { + return getSimpleName(); + } + }; + } + + static ReadAccessor fromGetter(ExecutableElement element, TypeMirror accessedType) { + return new ReadDelegateAccessor( new ExecutableElementAccessor( element, accessedType, AccessorType.GETTER ) ) { + @Override + public String getReadValueSource() { + return getSimpleName() + "()"; + } + }; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java new file mode 100644 index 0000000000..608c1b21cf --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +/** + * @author Filip Hrisafov + */ +public abstract class ReadDelegateAccessor extends DelegateAccessor implements ReadAccessor { + + protected ReadDelegateAccessor(Accessor delegate) { + super( delegate ); + } + +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl deleted file mode 100644 index 5cffc481a1..0000000000 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceContainsKeyPresenceCheck.ftl +++ /dev/null @@ -1,9 +0,0 @@ -<#-- - - Copyright MapStruct Authors. - - Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - ---> -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SourceReferenceContainsKeyPresenceCheck" --> -${sourceReference}.containsKey( "${propertyName}" ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl similarity index 72% rename from processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl rename to processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl index 930d5e24bc..103b4e7f9c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SourceReferenceMethodPresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl @@ -5,5 +5,5 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> -<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SourceReferenceMethodPresenceCheck" --> -${sourceReference}.${methodName}() \ No newline at end of file +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck" --> +${sourceReference}${suffix} \ No newline at end of file From 5de813c16f19050e6cd0a8cd08dc18799a37271b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Nov 2021 13:48:24 +0100 Subject: [PATCH 0627/1006] #2666 Presence Check should be applied to source parameters when used in `@Mapping` --- .../ap/internal/model/PropertyMapping.java | 14 +- .../expression/ConditionalExpressionTest.java | 37 +++++ ...nalWithSourceToTargetExpressionMapper.java | 132 ++++++++++++++++++ ...itionalMethodWithSourceToTargetMapper.java | 132 ++++++++++++++++++ .../qualifier/ConditionalQualifierTest.java | 37 +++++ 5 files changed, 348 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalWithSourceToTargetExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index c83f856587..f17ab9ddb1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -558,11 +558,17 @@ private SourceRHS getSourceRHS( SourceReference sourceReference ) { // parameter reference if ( propertyEntry == null ) { - return new SourceRHS( sourceParam.getName(), - sourceParam.getType(), - existingVariableNames, - sourceReference.toString() + SourceRHS sourceRHS = new SourceRHS( + sourceParam.getName(), + sourceParam.getType(), + existingVariableNames, + sourceReference.toString() ); + sourceRHS.setSourcePresenceCheckerReference( getSourcePresenceCheckerRef( + sourceReference, + sourceRHS + ) ); + return sourceRHS; } // simple property else if ( !sourceReference.isNested() ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java index 60179cdeac..42219cfb6a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java @@ -74,6 +74,43 @@ public void conditionalSimpleExpression() { assertThat( target.getValue() ).isEqualTo( 0 ); } + @ProcessorTest + @WithClasses({ + ConditionalWithSourceToTargetExpressionMapper.class + }) + @IssueKey("2666") + public void conditionalExpressionForSourceToTarget() { + ConditionalWithSourceToTargetExpressionMapper mapper = ConditionalWithSourceToTargetExpressionMapper.INSTANCE; + + ConditionalWithSourceToTargetExpressionMapper.OrderDTO orderDto = + new ConditionalWithSourceToTargetExpressionMapper.OrderDTO(); + + ConditionalWithSourceToTargetExpressionMapper.Order order = mapper.convertToOrder( orderDto ); + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNull(); + + orderDto = new ConditionalWithSourceToTargetExpressionMapper.OrderDTO(); + orderDto.setCustomerName( "Tester" ); + order = mapper.convertToOrder( orderDto ); + + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNotNull(); + assertThat( order.getCustomer().getName() ).isEqualTo( "Tester" ); + assertThat( order.getCustomer().getAddress() ).isNull(); + + orderDto = new ConditionalWithSourceToTargetExpressionMapper.OrderDTO(); + orderDto.setLine1( "Line 1" ); + order = mapper.convertToOrder( orderDto ); + + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNotNull(); + assertThat( order.getCustomer().getName() ).isNull(); + assertThat( order.getCustomer().getAddress() ).isNotNull(); + assertThat( order.getCustomer().getAddress().getLine1() ).isEqualTo( "Line 1" ); + assertThat( order.getCustomer().getAddress().getLine2() ).isNull(); + + } + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalWithSourceToTargetExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalWithSourceToTargetExpressionMapper.java new file mode 100644 index 0000000000..c32fe99e03 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalWithSourceToTargetExpressionMapper.java @@ -0,0 +1,132 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.expression; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(imports = ConditionalWithSourceToTargetExpressionMapper.Util.class) +public interface ConditionalWithSourceToTargetExpressionMapper { + + ConditionalWithSourceToTargetExpressionMapper INSTANCE = + Mappers.getMapper( ConditionalWithSourceToTargetExpressionMapper.class ); + + @Mapping(source = "orderDTO", target = "customer", + conditionExpression = "java(Util.mapCustomerFromOrder( orderDTO ))") + Order convertToOrder(OrderDTO orderDTO); + + @Mapping(source = "customerName", target = "name") + @Mapping(source = "orderDTO", target = "address", + conditionExpression = "java(Util.mapAddressFromOrder( orderDTO ))") + Customer convertToCustomer(OrderDTO orderDTO); + + Address convertToAddress(OrderDTO orderDTO); + + class OrderDTO { + + private String customerName; + private String line1; + private String line2; + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getLine1() { + return line1; + } + + public void setLine1(String line1) { + this.line1 = line1; + } + + public String getLine2() { + return line2; + } + + public void setLine2(String line2) { + this.line2 = line2; + } + + } + + class Order { + + private Customer customer; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + } + + class Customer { + private String name; + private Address address; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + } + + class Address { + + private String line1; + private String line2; + + public String getLine1() { + return line1; + } + + public void setLine1(String line1) { + this.line1 = line1; + } + + public String getLine2() { + return line2; + } + + public void setLine2(String line2) { + this.line2 = line2; + } + } + + interface Util { + + static boolean mapCustomerFromOrder(OrderDTO orderDTO) { + return orderDTO != null && ( orderDTO.getCustomerName() != null || mapAddressFromOrder( orderDTO ) ); + } + + static boolean mapAddressFromOrder(OrderDTO orderDTO) { + return orderDTO != null && ( orderDTO.getLine1() != null || orderDTO.getLine2() != null ); + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java new file mode 100644 index 0000000000..35864fe62c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java @@ -0,0 +1,132 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.qualifier; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodWithSourceToTargetMapper { + + ConditionalMethodWithSourceToTargetMapper INSTANCE = + Mappers.getMapper( ConditionalMethodWithSourceToTargetMapper.class ); + + @Mapping(source = "orderDTO", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder") + Order convertToOrder(OrderDTO orderDTO); + + @Mapping(source = "customerName", target = "name") + @Mapping(source = "orderDTO", target = "address", conditionQualifiedByName = "mapAddressFromOrder") + Customer convertToCustomer(OrderDTO orderDTO); + + Address convertToAddress(OrderDTO orderDTO); + + @Condition + @Named("mapCustomerFromOrder") + default boolean mapCustomerFromOrder(OrderDTO orderDTO) { + return orderDTO != null && ( orderDTO.getCustomerName() != null || mapAddressFromOrder( orderDTO ) ); + } + + @Condition + @Named("mapAddressFromOrder") + default boolean mapAddressFromOrder(OrderDTO orderDTO) { + return orderDTO != null && ( orderDTO.getLine1() != null || orderDTO.getLine2() != null ); + } + + class OrderDTO { + + private String customerName; + private String line1; + private String line2; + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getLine1() { + return line1; + } + + public void setLine1(String line1) { + this.line1 = line1; + } + + public String getLine2() { + return line2; + } + + public void setLine2(String line2) { + this.line2 = line2; + } + + } + + class Order { + + private Customer customer; + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + } + + class Customer { + private String name; + private Address address; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + } + + class Address { + + private String line1; + private String line2; + + public String getLine1() { + return line1; + } + + public void setLine1(String line1) { + this.line1 = line1; + } + + public String getLine2() { + return line2; + } + + public void setLine2(String line2) { + this.line2 = line2; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java index 5d13787e65..69c9a048cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalQualifierTest.java @@ -86,4 +86,41 @@ public void conditionalClassQualifiers() { assertThat( employee.getNin() ).isNull(); assertThat( employee.getSsid() ).isNull(); } + + @ProcessorTest + @WithClasses({ + ConditionalMethodWithSourceToTargetMapper.class + }) + @IssueKey("2666") + public void conditionalQualifiersForSourceToTarget() { + ConditionalMethodWithSourceToTargetMapper mapper = ConditionalMethodWithSourceToTargetMapper.INSTANCE; + + ConditionalMethodWithSourceToTargetMapper.OrderDTO orderDto = + new ConditionalMethodWithSourceToTargetMapper.OrderDTO(); + + ConditionalMethodWithSourceToTargetMapper.Order order = mapper.convertToOrder( orderDto ); + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNull(); + + orderDto = new ConditionalMethodWithSourceToTargetMapper.OrderDTO(); + orderDto.setCustomerName( "Tester" ); + order = mapper.convertToOrder( orderDto ); + + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNotNull(); + assertThat( order.getCustomer().getName() ).isEqualTo( "Tester" ); + assertThat( order.getCustomer().getAddress() ).isNull(); + + orderDto = new ConditionalMethodWithSourceToTargetMapper.OrderDTO(); + orderDto.setLine1( "Line 1" ); + order = mapper.convertToOrder( orderDto ); + + assertThat( order ).isNotNull(); + assertThat( order.getCustomer() ).isNotNull(); + assertThat( order.getCustomer().getName() ).isNull(); + assertThat( order.getCustomer().getAddress() ).isNotNull(); + assertThat( order.getCustomer().getAddress().getLine1() ).isEqualTo( "Line 1" ); + assertThat( order.getCustomer().getAddress().getLine2() ).isNull(); + + } } From ea45666d665c51c02a79bb9a670855b9fab06059 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 11 Dec 2021 14:16:19 +0100 Subject: [PATCH 0628/1006] #2673: Fix optional wrapping pattern throwing exception when primitive types are present MethodMatcher incorrectly reported that a primitive type matches a candidate for a type var --- .../internal/model/source/MethodMatcher.java | 7 +- .../ap/test/bugs/_2673/Issue2673Mapper.java | 66 +++++++++++++++++++ .../ap/test/bugs/_2673/Issue2673Test.java | 24 +++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2673/Issue2673Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2673/Issue2673Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index f08e4a9152..f0d9536799 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -10,7 +10,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; @@ -239,6 +238,8 @@ boolean getCandidates(Type aCandidateMethodType, Type matchingType, Map String method( T par ); @@ -256,6 +257,8 @@ boolean getCandidates(Type aCandidateMethodType, Type matchingType, Map T map(Optional opt) { + return opt.orElse( null ); + } + + default Optional map(T t) { + return Optional.ofNullable( t ); + } + + class Target { + private final int primitive; + private final String nonPrimitive; + + public Target(int primitive, String nonPrimitive) { + this.primitive = primitive; + this.nonPrimitive = nonPrimitive; + } + + public int getPrimitive() { + return primitive; + } + + public String getNonPrimitive() { + return nonPrimitive; + } + } + + class Source { + private final int primitive; + private final Optional nonPrimitive; + + public Source(int primitive, Optional nonPrimitive) { + this.primitive = primitive; + this.nonPrimitive = nonPrimitive; + } + + public int getPrimitive() { + return primitive; + } + + public Optional getNonPrimitive() { + return nonPrimitive; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2673/Issue2673Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2673/Issue2673Test.java new file mode 100644 index 0000000000..40a5e79276 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2673/Issue2673Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2673; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@WithClasses({ + Issue2673Mapper.class +}) +class Issue2673Test { + + @ProcessorTest + @IssueKey( "2673" ) + void shouldCompile() { + } +} From 0de10ca83c682303f4082c27b3a22eec5fbcb258 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Dec 2021 12:48:55 +0100 Subject: [PATCH 0629/1006] [maven-release-plugin] prepare release 1.5.0.Beta2 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index aaae7b5404..6eaf876961 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 293043e6f9..ef963caadd 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 10c95cf3b5..8012b3be5e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 337ad35e51..d2bf1509d5 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8850da641c..3341ffb5cc 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4b48c19496..69b81e4321 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index f4edccfc85..f5f241762a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Beta2 diff --git a/pom.xml b/pom.xml index 28c35aea74..2179424cbd 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Beta2 diff --git a/processor/pom.xml b/processor/pom.xml index 4f2476ceb0..c1751f395f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Beta2 ../parent/pom.xml From 930b07aab82d9270a871f89b957717825a693385 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 12 Dec 2021 12:48:56 +0100 Subject: [PATCH 0630/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6eaf876961..aaae7b5404 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index ef963caadd..293043e6f9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 8012b3be5e..10c95cf3b5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index d2bf1509d5..337ad35e51 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 3341ffb5cc..8850da641c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 69b81e4321..4b48c19496 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index f5f241762a..f4edccfc85 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT pom MapStruct Parent @@ -64,7 +64,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Beta2 + HEAD diff --git a/pom.xml b/pom.xml index 2179424cbd..28c35aea74 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Beta2 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index c1751f395f..4f2476ceb0 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Beta2 + 1.5.0-SNAPSHOT ../parent/pom.xml From 0a7b8134d4eaf5430e392403f33881129eaeba98 Mon Sep 17 00:00:00 2001 From: Ben Zegveld Date: Fri, 24 Dec 2021 14:44:59 +0100 Subject: [PATCH 0631/1006] #2689: documentation: fix example title. --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 5d7da371a1..fdbe5f8059 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -303,7 +303,7 @@ public interface CarMapper { The generated mapper will look like: -.try-catch block in generated implementation +.Custom condition check in generated implementation ==== [source, java, linenums] [subs="verbatim,attributes"] From 42cfa05c40d1cd8d68397ed5581de147929c1250 Mon Sep 17 00:00:00 2001 From: Valentin Kulesh Date: Sun, 26 Dec 2021 13:22:05 +0300 Subject: [PATCH 0632/1006] #2704 Fix broken reference to constants within nested enums --- .../model/assignment/EnumConstantWrapper.ftl | 2 +- .../ap/test/bugs/_2704/Issue2704Test.java | 21 +++++++++++++++++++ .../ap/test/bugs/_2704/TestMapper.java | 19 +++++++++++++++++ .../ap/test/bugs/_2704/TopLevel.java | 21 +++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/Issue2704Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TestMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TopLevel.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl index 7364f7922e..449a273614 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.EnumConstantWrapper" --> -${ext.targetType.name}.${assignment} \ No newline at end of file +${ext.targetType.createReferenceName()}.${assignment} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/Issue2704Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/Issue2704Test.java new file mode 100644 index 0000000000..5920a6022b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/Issue2704Test.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2704; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Valentin Kulesh + */ +@IssueKey("2704") +@WithClasses({ TestMapper.class, TopLevel.class }) +public class Issue2704Test { + @ProcessorTest + public void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TestMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TestMapper.java new file mode 100644 index 0000000000..846a783437 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TestMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2704; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.bugs._2704.TopLevel.Target; + +/** + * @author Valentin Kulesh + */ +@Mapper(implementationPackage = "") +public interface TestMapper { + @Mapping(target = "e", constant = "VALUE1") + Target test(Object unused); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TopLevel.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TopLevel.java new file mode 100644 index 0000000000..ef30c2cd6e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2704/TopLevel.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2704; + +/** + * @author Valentin Kulesh + */ +public interface TopLevel { + enum InnerEnum { + VALUE1, + VALUE2, + } + + class Target { + public void setE(@SuppressWarnings("unused") InnerEnum e) { + } + } +} From f7f65ac1dee0db41daf702382fba0284bff5419a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 25 Dec 2021 13:12:29 +0100 Subject: [PATCH 0633/1006] #2687 Add documentation for NullValueMappingStrategy for collections and maps --- ...apter-10-advanced-mapping-options.asciidoc | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index fdbe5f8059..463ebcf7c4 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -212,6 +212,29 @@ However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETU The strategy works in a hierarchical fashion. Setting `nullValueMappingStrategy` on mapping method level will override `@Mapper#nullValueMappingStrategy`, and `@Mapper#nullValueMappingStrategy` will override `@MapperConfig#nullValueMappingStrategy`. +[[mapping-result-for-null-collection-or-map-arguments]] +=== Controlling mapping result for 'null' collection or map arguments + +With <> it is possible to control how the return type should be constructed when the source argument of the mapping method is `null`. +That is applied for all mapping methods (bean, iterable or map mapping methods). + +However, MapStruct also offers a more dedicated way to control how collections / maps should be mapped. +e.g. return default (empty) collections / maps, but return `null` for beans. + +For collections (iterables) this can be controlled through: + +* `MapperConfig#nullValueIterableMappingStrategy` +* `Mapper#nullValueIterableMappingStrategy` +* `IterableMapping#nullValueMappingStrategy` + +For maps this can be controlled through: + +* `MapperConfig#nullValueMapMappingStrategy` +* `Mapper#nullValueMapMappingStrategy` +* `MapMapping#nullValueMappingStrategy` + +How the value of the `NullValueMappingStrategy` is applied is the same as in <> + [[mapping-result-for-null-properties]] === Controlling mapping result for 'null' properties in bean mappings (update mapping methods only). From 59c5f40ac3c6f83e0e4c333a9ed67ae23b6ae664 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 18 Jan 2022 18:22:47 +0100 Subject: [PATCH 0634/1006] #2686 Add documentation about when mappers are injected --- .../src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc index 724b42fbb7..67db28c7c0 100644 --- a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc @@ -117,7 +117,7 @@ public interface CarMapper { ---- ==== -The generated mapper will inject all classes defined in the **uses** attribute. +The generated mapper will inject classes defined in the **uses** attribute if MapStruct has detected that it needs to use an instance of it for a mapping. When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. For now, the default injection strategy is field injection, but it can be configured with <>. From 277b6f5d2b357097a968d1201d29b3012928b72d Mon Sep 17 00:00:00 2001 From: Ben Zegveld Date: Thu, 20 Jan 2022 23:02:12 +0100 Subject: [PATCH 0635/1006] #2719: added a note at the builder documentation to point towards the Before-/AfterMapping documentation. --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 370c09e249..9d5124ee97 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -445,6 +445,11 @@ The <> are also considered for the builder type. E.g. If an object factory exists for our `PersonBuilder` then this factory would be used instead of the builder creation method. ====== +[NOTE] +====== +Detected builders influence `@BeforeMapping` and `@AfterMapping` behavior. See chapter `Mapping customization with before-mapping and after-mapping methods` for more information. +====== + .Person with Builder example ==== [source, java, linenums] From 0f297ae60f2a839578576b46c38b08832f167bc4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Jan 2022 22:33:51 +0000 Subject: [PATCH 0636/1006] Bump protobuf-java from 3.6.0 to 3.16.1 in /parent Bumps [protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.6.0 to 3.16.1. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/master/generate_changelog.py) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.6.0...v3.16.1) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index f4edccfc85..263aa73503 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -223,7 +223,7 @@ com.google.protobuf protobuf-java - 3.6.0 + 3.16.1 org.inferred From 0a8e9b738cb2868628d2d8d12833c92b8ede1d04 Mon Sep 17 00:00:00 2001 From: Goni-Dev <56092853+Goni-Dev@users.noreply.github.com> Date: Sun, 23 Jan 2022 17:26:21 +0100 Subject: [PATCH 0637/1006] #2709 Corrected description for example demonstrating default expression --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 463ebcf7c4..0bbec1fe57 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -88,7 +88,7 @@ Default expressions are a combination of default values and expressions. They wi The same warnings and restrictions apply to default expressions that apply to expressions. Only Java is supported, and MapStruct will not validate the expression at generation-time. -The example below demonstrates how two source properties can be mapped to one target: +The example below demonstrates how a default expression can be used to set a value when the source attribute is not present (e.g. is `null`): .Mapping method using a default expression ==== From b22efd9ad7d8878c45d8f5c906b39dbbfe3aeaec Mon Sep 17 00:00:00 2001 From: Justyna <98126210+JKLedzion@users.noreply.github.com> Date: Mon, 24 Jan 2022 14:17:24 +0100 Subject: [PATCH 0638/1006] =?UTF-8?q?#2674:=20Add=20check=20if=20method=20?= =?UTF-8?q?without=20implementation=20doesn=E2=80=99t=20have=20`@AfterMapp?= =?UTF-8?q?ing`=20/=20`@BeforeMapping`=20annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processor/MethodRetrievalProcessor.java | 10 +++++ .../mapstruct/ap/internal/util/Message.java | 2 + .../_2674/ErroneousSourceTargetMapping.java | 28 +++++++++++++ .../ap/test/bugs/_2674/Issue2674Test.java | 40 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2674/Source.java | 28 +++++++++++++ .../mapstruct/ap/test/bugs/_2674/Target.java | 28 +++++++++++++ 6 files changed, 136 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2674/ErroneousSourceTargetMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2674/Issue2674Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2674/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2674/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index b226c1a050..a31fb41a7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -564,6 +564,16 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List Date: Sat, 29 Jan 2022 00:37:24 +0100 Subject: [PATCH 0639/1006] #2668: Added support for collections and maps with a no-args constructor (#2671) #2668: Added support for collections and maps with a no-args constructor. Added a compiler error in case of a collection or map without either a no-arg constructor or a copy constructor. --- .../model/CollectionAssignmentBuilder.java | 84 +++++++++++- ...nceSetterWrapperForCollectionsAndMaps.java | 43 +++++++ ...perForCollectionsAndMapsWithNullCheck.java | 2 +- .../ap/internal/model/common/Type.java | 6 +- .../mapstruct/ap/internal/util/Message.java | 1 + ...anceSetterWrapperForCollectionsAndMaps.ftl | 23 ++++ .../bugs/_2668/Erroneous2668ListMapper.java | 54 ++++++++ .../bugs/_2668/Erroneous2668MapMapper.java | 54 ++++++++ .../ap/test/bugs/_2668/Issue2668Mapper.java | 120 ++++++++++++++++++ .../ap/test/bugs/_2668/Issue2668Test.java | 59 +++++++++ 10 files changed, 438 insertions(+), 8 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668ListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668MapMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index dd6db1b0ee..e3bc85342a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -5,19 +5,27 @@ */ package org.mapstruct.ap.internal.model; +import java.util.function.Predicate; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; + +import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.model.assignment.ExistingInstanceSetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.GetterWrapperForCollectionsAndMaps; +import org.mapstruct.ap.internal.model.assignment.NewInstanceSetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMaps; import org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck; import org.mapstruct.ap.internal.model.assignment.UpdateWrapper; import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.Assignment.AssignmentType; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; -import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; -import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; -import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; @@ -169,7 +177,8 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { targetAccessorType.isFieldAssignment() ); } - else if ( setterWrapperNeedsSourceNullCheck( result ) ) { + else if ( setterWrapperNeedsSourceNullCheck( result ) + && canBeMappedOrDirectlyAssigned( result ) ) { result = new SetterWrapperForCollectionsAndMapsWithNullCheck( result, @@ -179,7 +188,7 @@ else if ( setterWrapperNeedsSourceNullCheck( result ) ) { targetAccessorType.isFieldAssignment() ); } - else { + else if ( canBeMappedOrDirectlyAssigned( result ) ) { //TODO init default value // target accessor is setter, so wrap the setter in setter map/ collection handling @@ -190,6 +199,21 @@ else if ( setterWrapperNeedsSourceNullCheck( result ) ) { targetAccessorType.isFieldAssignment() ); } + else if ( hasNoArgsConstructor() ) { + result = new NewInstanceSetterWrapperForCollectionsAndMaps( + result, + method.getThrownTypes(), + targetType, + ctx.getTypeFactory(), + targetAccessorType.isFieldAssignment() ); + } + else { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.PROPERTYMAPPING_NO_SUITABLE_COLLECTION_OR_MAP_CONSTRUCTOR, + targetType + ); + } } else { if ( targetImmutable ) { @@ -212,6 +236,12 @@ else if ( setterWrapperNeedsSourceNullCheck( result ) ) { return result; } + private boolean canBeMappedOrDirectlyAssigned(Assignment result) { + return result.getType() != AssignmentType.DIRECT + || hasCopyConstructor() + || targetType.isEnumSet(); + } + /** * Checks whether the setter wrapper should include a null / presence check or not * @@ -236,4 +266,48 @@ private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs) { return false; } + private boolean hasCopyConstructor() { + return checkConstructorForPredicate( this::hasCopyConstructor ); + } + + private boolean hasNoArgsConstructor() { + return checkConstructorForPredicate( this::hasNoArgsConstructor ); + } + + private boolean checkConstructorForPredicate(Predicate predicate) { + if ( targetType.isCollectionOrMapType() ) { + if ( "java.util".equals( targetType.getPackageName() ) ) { + return true; + } + else { + Element sourceElement = targetType.getImplementationType() != null + ? targetType.getImplementationType().getTypeElement() + : targetType.getTypeElement(); + if ( sourceElement != null ) { + for ( Element element : sourceElement.getEnclosedElements() ) { + if ( element.getKind() == ElementKind.CONSTRUCTOR + && element.getModifiers().contains( Modifier.PUBLIC ) ) { + if ( predicate.test( element ) ) { + return true; + } + } + } + } + } + } + return false; + } + + private boolean hasNoArgsConstructor(Element element) { + return ( (ExecutableElement) element ).getParameters().isEmpty(); + } + + private boolean hasCopyConstructor(Element element) { + if ( element instanceof ExecutableElement ) { + ExecutableElement ee = (ExecutableElement) element; + return ee.getParameters().size() == 1 + && ctx.getTypeUtils().isAssignable( targetType.getTypeMirror(), ee.getParameters().get( 0 ).asType() ); + } + return false; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.java new file mode 100644 index 0000000000..f0e23470a7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.assignment; + +import java.util.List; + +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +/** + * This wrapper handles the situation where an assignment is done via the setter, while creating the collection or map + * using a no-args constructor. + * + * @author Ben Zegveld + */ +public class NewInstanceSetterWrapperForCollectionsAndMaps extends SetterWrapperForCollectionsAndMapsWithNullCheck { + + private String instanceVar; + + public NewInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, + List thrownTypesToExclude, + Type targetType, + TypeFactory typeFactory, + boolean fieldAssignment) { + + super( + decoratedAssignment, + thrownTypesToExclude, + targetType, + typeFactory, + fieldAssignment + ); + this.instanceVar = decoratedAssignment.createUniqueVarName( targetType.getName() ); + } + + public String getInstanceVar() { + return instanceVar; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index 5e3f4d63fe..a0c9f799e9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -68,7 +68,7 @@ public boolean isDirectAssignment() { } public boolean isEnumSet() { - return "java.util.EnumSet".equals( targetType.getFullyQualifiedName() ); + return targetType.isEnumSet(); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ab2871c69d..ba5f62254d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -19,7 +19,6 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -113,7 +112,6 @@ public class Type extends ModelElement implements Comparable { private List setters = null; private List adders = null; private List alternativeTargetAccessors = null; - private Map constructorAccessors = null; private Type boundingBase = null; @@ -1603,4 +1601,8 @@ private static Type topLevelType(TypeElement typeElement, TypeFactory typeFactor return parent == null ? null : typeFactory.getType( parent.asType() ); } + public boolean isEnumSet() { + return "java.util.EnumSet".equals( getFullyQualifiedName() ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 26f4a33c5d..8588ec183a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -80,6 +80,7 @@ public enum Message { PROPERTYMAPPING_WHITESPACE_TRIMMED( "The property named \"%s\" has whitespaces, using trimmed property \"%s\" instead.", Diagnostic.Kind.WARNING ), PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET("The type of parameter \"%s\" has no property named \"%s\". Please define the source property explicitly."), PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET("No property named \"%s\" exists in source parameter(s). Please define the source explicitly."), + PROPERTYMAPPING_NO_SUITABLE_COLLECTION_OR_MAP_CONSTRUCTOR( "%s does not have an accessible copy or no-args constructor." ), CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ), CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.ftl new file mode 100644 index 0000000000..4582e68a1e --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/NewInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -0,0 +1,23 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.SetterWrapperForCollectionsAndMapsWithNullCheck" --> +<#import "../macro/CommonMacros.ftl" as lib> +<@lib.sourceLocalVarAssignment/> +<@lib.handleExceptions> + <@callTargetWriteAccessor/> + +<#-- + assigns the target via the regular target write accessor (usually the setter) +--> +<#macro callTargetWriteAccessor> + <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> + <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/> ${instanceVar} = new <#if ext.targetType.implementationType??><@includeModel object=ext.targetType.implementationType/><#else><@includeModel object=ext.targetType/>(); + ${instanceVar}.<#if ext.targetType.collectionType>addAll<#else>putAll( ${nullCheckLocalVarName} ); + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite>${instanceVar}; + + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668ListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668ListMapper.java new file mode 100644 index 0000000000..beb1d3283a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668ListMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2668; + +import java.util.ArrayList; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Erroneous2668ListMapper { + + Erroneous2668ListMapper INSTANCE = Mappers.getMapper( Erroneous2668ListMapper.class ); + + CollectionTarget map(CollectionSource source); + + class CollectionTarget { + MyArrayList list; + + public MyArrayList getList() { + return list; + } + + public void setList(MyArrayList list) { + this.list = list; + } + } + + class CollectionSource { + MyArrayList list; + + public MyArrayList getList() { + return list; + } + + public void setList(MyArrayList list) { + this.list = list; + } + } + + class MyArrayList extends ArrayList { + private String unusable; + + public MyArrayList(String unusable) { + this.unusable = unusable; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668MapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668MapMapper.java new file mode 100644 index 0000000000..3c9bcd3926 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Erroneous2668MapMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2668; + +import java.util.HashMap; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Erroneous2668MapMapper { + + Erroneous2668MapMapper INSTANCE = Mappers.getMapper( Erroneous2668MapMapper.class ); + + CollectionTarget map(CollectionSource source); + + class CollectionTarget { + MyHashMap map; + + public MyHashMap getMap() { + return map; + } + + public void setMap(MyHashMap map) { + this.map = map; + } + } + + class CollectionSource { + MyHashMap map; + + public MyHashMap getMap() { + return map; + } + + public void setMap(MyHashMap map) { + this.map = map; + } + } + + class MyHashMap extends HashMap { + private String unusable; + + public MyHashMap(String unusable) { + this.unusable = unusable; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Mapper.java new file mode 100644 index 0000000000..1b72e2f636 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Mapper.java @@ -0,0 +1,120 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2668; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Issue2668Mapper { + + Issue2668Mapper INSTANCE = Mappers.getMapper( Issue2668Mapper.class ); + + CollectionTarget map(CollectionSource source); + + class CollectionTarget { + MyArrayList list; + MyHashMap map; + MyCopyArrayList copyList; + MyCopyHashMap copyMap; + + public MyArrayList getList() { + return list; + } + + public MyHashMap getMap() { + return map; + } + + public void setList(MyArrayList list) { + this.list = list; + } + + public void setMap(MyHashMap map) { + this.map = map; + } + + public MyCopyArrayList getCopyList() { + return copyList; + } + + public MyCopyHashMap getCopyMap() { + return copyMap; + } + + public void setCopyList(MyCopyArrayList copyList) { + this.copyList = copyList; + } + + public void setCopyMap(MyCopyHashMap copyMap) { + this.copyMap = copyMap; + } + } + + class CollectionSource { + MyArrayList list; + MyHashMap map; + MyCopyArrayList copyList; + MyCopyHashMap copyMap; + + public MyArrayList getList() { + return list; + } + + public MyHashMap getMap() { + return map; + } + + public void setList(MyArrayList list) { + this.list = list; + } + + public void setMap(MyHashMap map) { + this.map = map; + } + + public MyCopyArrayList getCopyList() { + return copyList; + } + + public MyCopyHashMap getCopyMap() { + return copyMap; + } + + public void setCopyList(MyCopyArrayList copyList) { + this.copyList = copyList; + } + + public void setCopyMap(MyCopyHashMap copyMap) { + this.copyMap = copyMap; + } + } + + class MyArrayList extends ArrayList { + } + + class MyHashMap extends HashMap { + } + + class MyCopyArrayList extends ArrayList { + public MyCopyArrayList(Collection copy) { + super( copy ); + } + } + + class MyCopyHashMap extends HashMap { + public MyCopyHashMap(HashMap copy) { + super( copy ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Test.java new file mode 100644 index 0000000000..20b4e445fd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2668/Issue2668Test.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2668; + +import javax.tools.Diagnostic.Kind; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * @author Ben Zegveld + */ +@IssueKey( "2668" ) +class Issue2668Test { + + @ProcessorTest + @WithClasses( Issue2668Mapper.class ) + void shouldCompileCorrectlyWithAvailableConstructors() { + } + + @ProcessorTest + @WithClasses( Erroneous2668ListMapper.class ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = Kind.ERROR, + line = 21, + message = "org.mapstruct.ap.test.bugs._2668.Erroneous2668ListMapper.MyArrayList" + + " does not have an accessible copy or no-args constructor." + ) + } + ) + void errorExpectedBecauseCollectionIsNotUsable() { + } + + @ProcessorTest + @WithClasses( Erroneous2668MapMapper.class ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = Kind.ERROR, + line = 21, + message = "org.mapstruct.ap.test.bugs._2668.Erroneous2668MapMapper.MyHashMap" + + " does not have an accessible copy or no-args constructor." + ) + } + ) + void errorExpectedBecauseMapIsNotUsable() { + } +} From ec30f5d2797670f053e6b2cc5eb96f62dcc3541c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Jan 2022 11:03:44 +0100 Subject: [PATCH 0640/1006] #2725 Update tools-gem to 1.0.0.Alpha3 and run GitHub Action with Java 19-ea Also update Spring to 5.3.15 to be able to run on Java 19 --- .github/workflows/java-ea.yml | 2 +- parent/pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index f2b2a99be4..76e24db3b1 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - java: [18-ea] + java: [18-ea, 19-ea] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: diff --git a/parent/pom.xml b/parent/pom.xml index 263aa73503..242d5215de 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -21,11 +21,11 @@ UTF-8 - 1.0.0.Alpha2 + 1.0.0.Alpha3 3.0.0-M3 3.0.0-M5 3.1.0 - 5.3.10 + 5.3.15 1.6.0 8.36.1 5.8.0-M1 From 20ff51ebb8782afe571e797b992e9660e3667e74 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Jan 2022 11:13:16 +0100 Subject: [PATCH 0641/1006] #2728 Add new WithTestDependency annotation for our processor testing Adding this dependency allows us to dynamically pick the dependencies that we want to have on the test compilation classpath. It would allow us to more granularly test things with different dependencies, such as javax inject and jakarta inject --- .../ap/test/bugs/_1395/Issue1395Test.java | 2 + .../ap/test/bugs/_1425/Issue1425Test.java | 2 + .../ap/test/bugs/_1460/Issue1460Test.java | 2 + .../ap/test/bugs/_2145/Issue2145Test.java | 2 + .../ap/test/bugs/_880/Issue880Test.java | 2 + .../ap/test/builtin/BuiltInTest.java | 28 +++++++--- .../test/builtin/jodatime/JodaTimeTest.java | 4 ++ .../collection/wildcard/WildCardTest.java | 2 + .../erroneous/InvalidDateFormatTest.java | 2 + .../jodatime/JodaConversionTest.java | 2 + .../decorator/jsr330/Jsr330DecoratorTest.java | 2 + .../constructor/SpringDecoratorTest.java | 2 + .../spring/field/SpringDecoratorTest.java | 2 + .../destination/DestinationClassNameTest.java | 2 + .../imports/ConflictingTypesNamesTest.java | 2 + ...30DefaultCompileOptionFieldMapperTest.java | 2 + ...330CompileOptionConstructorMapperTest.java | 2 + .../Jsr330ConstructorMapperTest.java | 2 + .../jsr330/field/Jsr330FieldMapperTest.java | 2 + .../_default/SpringDefaultMapperTest.java | 2 + ...ingCompileOptionConstructorMapperTest.java | 2 + .../SpringConstructorMapperTest.java | 2 + .../spring/field/SpringFieldMapperTest.java | 2 + .../NestedMappingMethodInvocationTest.java | 4 ++ ...ferencedMappersWithSameSimpleNameTest.java | 2 + .../jaxb/JaxbFactoryMethodSelectionTest.java | 2 + .../jaxb/UnderscoreSelectionTest.java | 2 + .../ap/testutil/WithJavaxInject.java | 27 ++++++++++ .../mapstruct/ap/testutil/WithJavaxJaxb.java | 27 ++++++++++ .../org/mapstruct/ap/testutil/WithJoda.java | 27 ++++++++++ .../org/mapstruct/ap/testutil/WithSpring.java | 28 ++++++++++ .../ap/testutil/WithTestDependencies.java | 22 ++++++++ .../ap/testutil/WithTestDependency.java | 28 ++++++++++ .../testutil/runner/CompilationRequest.java | 11 +++- .../testutil/runner/CompilingExtension.java | 52 ++++++++++++------- .../runner/EclipseCompilingExtension.java | 25 +++++++-- .../runner/JdkCompilingExtension.java | 20 ++++++- 37 files changed, 319 insertions(+), 32 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxInject.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxJaxb.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJoda.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependencies.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependency.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java index 757436a0f4..042d0288cd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java @@ -8,6 +8,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; /** * @author Filip Hrisafov @@ -18,6 +19,7 @@ Source.class, Target.class } ) +@WithSpring @IssueKey( "1395" ) public class Issue1395Test { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java index 8c5700772f..a71c33c396 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1425/Issue1425Test.java @@ -9,6 +9,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJoda; import static org.assertj.core.api.Assertions.assertThat; @@ -21,6 +22,7 @@ Target.class }) @IssueKey("1425") +@WithJoda public class Issue1425Test { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java index 077e66df76..e9c97f39bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Test.java @@ -12,6 +12,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJoda; import static org.assertj.core.api.Assertions.assertThat; @@ -24,6 +25,7 @@ Target.class }) @IssueKey("1460") +@WithJoda public class Issue1460Test { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java index ec8bb4603c..38aed76003 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2145/Issue2145Test.java @@ -8,11 +8,13 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @IssueKey("2145") @WithClasses(Issue2145Mapper.class) +@WithJavaxJaxb public class Issue2145Test { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java index d05f01dc91..9d8540b409 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java @@ -11,6 +11,7 @@ import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.MappingConstants; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @@ -30,6 +31,7 @@ @ProcessorOptions({ @ProcessorOption(name = "mapstruct.defaultComponentModel", value = MappingConstants.ComponentModel.SPRING), @ProcessorOption(name = "mapstruct.unmappedTargetPolicy", value = "ignore") }) +@WithSpring public class Issue880Test { @RegisterExtension final GeneratedSource generatedSource = new GeneratedSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 0f1983a851..2dc41b822d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -58,6 +58,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @@ -71,8 +72,6 @@ MapTarget.class, CalendarProperty.class, DateProperty.class, - JaxbElementListProperty.class, - JaxbElementProperty.class, StringListProperty.class, StringProperty.class, BigDecimalProperty.class, @@ -81,13 +80,16 @@ XmlGregorianCalendarProperty.class, ZonedDateTimeProperty.class, IterableSource.class, - MapSource.class }) @DefaultTimeZone("Europe/Berlin") public class BuiltInTest { @ProcessorTest - @WithClasses( JaxbMapper.class ) + @WithClasses( { + JaxbMapper.class, + JaxbElementProperty.class, + } ) + @WithJavaxJaxb public void shouldApplyBuiltInOnJAXBElement() { JaxbElementProperty source = new JaxbElementProperty(); source.setProp( createJaxb( "TEST" ) ); @@ -100,7 +102,11 @@ public void shouldApplyBuiltInOnJAXBElement() { } @ProcessorTest - @WithClasses( JaxbMapper.class ) + @WithClasses( { + JaxbMapper.class, + JaxbElementProperty.class, + } ) + @WithJavaxJaxb @IssueKey( "1698" ) public void shouldApplyBuiltInOnJAXBElementExtra() { JaxbElementProperty source = new JaxbElementProperty(); @@ -123,7 +129,11 @@ public void shouldApplyBuiltInOnJAXBElementExtra() { } @ProcessorTest - @WithClasses( JaxbListMapper.class ) + @WithClasses( { + JaxbListMapper.class, + JaxbElementListProperty.class, + } ) + @WithJavaxJaxb @IssueKey( "141" ) public void shouldApplyBuiltInOnJAXBElementList() { @@ -347,7 +357,11 @@ public void shouldApplyBuiltInOnIterable() throws DatatypeConfigurationException } @ProcessorTest - @WithClasses( MapSourceTargetMapper.class ) + @WithClasses( { + MapSourceTargetMapper.class, + MapSource.class, + } ) + @WithJavaxJaxb public void shouldApplyBuiltInOnMap() throws DatatypeConfigurationException { MapSource source = new MapSource(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java index 77c62c9cac..cb0c3d2378 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/jodatime/JodaTimeTest.java @@ -30,6 +30,8 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; +import org.mapstruct.ap.testutil.WithJoda; import static org.assertj.core.api.Assertions.assertThat; @@ -45,6 +47,8 @@ XmlGregorianCalendarBean.class }) @IssueKey( "689" ) +@WithJoda +@WithJavaxJaxb public class JodaTimeTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java index 37ed4606f6..4da6f8648a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/WildCardTest.java @@ -13,6 +13,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @@ -133,6 +134,7 @@ public void shouldFailOnTypeVarTarget() { @ProcessorTest @WithClasses( { BeanMapper.class, GoodIdea.class, CunningPlan.class } ) + @WithJavaxJaxb public void shouldMapBean() { GoodIdea aGoodIdea = new GoodIdea(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java index 5eb67bee05..81bf3eb568 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/erroneous/InvalidDateFormatTest.java @@ -8,6 +8,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJoda; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @@ -19,6 +20,7 @@ Source.class, Target.class }) +@WithJoda @IssueKey("725") public class InvalidDateFormatTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 001b6390e2..1ab73616d5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -20,6 +20,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJoda; import static org.assertj.core.api.Assertions.assertThat; @@ -31,6 +32,7 @@ @WithClasses({ Source.class, Target.class, SourceTargetMapper.class }) @IssueKey("75") @DefaultLocale("de") +@WithJoda public class JodaConversionTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index d00368dfd4..a3bad68b92 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -19,6 +19,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -44,6 +45,7 @@ @IssueKey("592") @ComponentScan(basePackageClasses = Jsr330DecoratorTest.class) @Configuration +@WithJavaxInject public class Jsr330DecoratorTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java index dc834683e3..6d18555372 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/constructor/SpringDecoratorTest.java @@ -16,6 +16,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -40,6 +41,7 @@ @IssueKey("592") @ComponentScan(basePackageClasses = SpringDecoratorTest.class) @Configuration +@WithSpring public class SpringDecoratorTest { @Autowired diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java index 1b81ed8c48..ac0af86381 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/field/SpringDecoratorTest.java @@ -16,6 +16,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -37,6 +38,7 @@ PersonMapper.class, PersonMapperDecorator.class }) +@WithSpring @IssueKey("592") @ComponentScan(basePackageClasses = SpringDecoratorTest.class) @Configuration diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java index e61bd1cb2c..30611a8d60 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java @@ -7,6 +7,7 @@ import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.factory.Mappers; import static org.assertj.core.api.Assertions.assertThat; @@ -25,6 +26,7 @@ public void shouldGenerateRightName() { @ProcessorTest @WithClasses({ DestinationClassNameWithJsr330Mapper.class }) + @WithJavaxInject public void shouldNotGenerateSpi() throws Exception { Class clazz = DestinationClassNameWithJsr330Mapper.class; diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java index d09ddf66a2..8d61eb8f8a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/ConflictingTypesNamesTest.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -41,6 +42,7 @@ org.mapstruct.ap.test.imports.to.FooWrapper.class, SecondSourceTargetMapper.class }) +@WithJavaxInject public class ConflictingTypesNamesTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java index 65d8acfb2c..dd639684b8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java @@ -17,6 +17,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -41,6 +42,7 @@ GenderJsr330DefaultCompileOptionFieldMapper.class }) @ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class) +@WithJavaxInject @Configuration public class Jsr330DefaultCompileOptionFieldMapperTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java index c564648ecf..24bfba5511 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java @@ -14,6 +14,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +43,7 @@ @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class) @Configuration +@WithJavaxInject public class Jsr330CompileOptionConstructorMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java index 06f4180289..8543d57e38 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -42,6 +43,7 @@ @IssueKey("571") @ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class) @Configuration +@WithJavaxInject public class Jsr330ConstructorMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java index fc3bd09561..d8cf0c3925 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -18,6 +18,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -44,6 +45,7 @@ @IssueKey("571") @ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class) @Configuration +@WithJavaxInject public class Jsr330FieldMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java index ef1b79b34b..2d9c374721 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/_default/SpringDefaultMapperTest.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -41,6 +42,7 @@ @IssueKey("571") @ComponentScan(basePackageClasses = CustomerSpringDefaultMapper.class) @Configuration +@WithSpring public class SpringDefaultMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java index b106a5d788..c3291a5f3b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/compileoptionconstructor/SpringCompileOptionConstructorMapperTest.java @@ -21,6 +21,7 @@ import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; @@ -52,6 +53,7 @@ @ProcessorOption( name = "mapstruct.defaultInjectionStrategy", value = "constructor") @ComponentScan(basePackageClasses = CustomerSpringCompileOptionConstructorMapper.class) @Configuration +@WithSpring @DefaultTimeZone("Europe/Berlin") public class SpringCompileOptionConstructorMapperTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java index 1ff3fc8428..2594d5c23d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/constructor/SpringConstructorMapperTest.java @@ -23,6 +23,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -53,6 +54,7 @@ @IssueKey( "571" ) @ComponentScan(basePackageClasses = CustomerSpringConstructorMapper.class) @Configuration +@WithSpring @DefaultTimeZone("Europe/Berlin") public class SpringConstructorMapperTest { diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java index 8ee03f4bfb..d464dd5b16 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/field/SpringFieldMapperTest.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ConfigurableApplicationContext; @@ -42,6 +43,7 @@ @IssueKey("571") @ComponentScan(basePackageClasses = CustomerSpringFieldMapper.class) @Configuration +@WithSpring public class SpringFieldMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 1e9b52cf62..8d600d8604 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -20,6 +20,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @@ -42,6 +43,7 @@ public class NestedMappingMethodInvocationTest { OrderDetailsType.class, OrderType.class } ) + @WithJavaxJaxb public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException { OrderTypeToOrderDtoMapper instance = OrderTypeToOrderDtoMapper.INSTANCE; OrderDto target = instance.sourceToTarget( createOrderType() ); @@ -62,6 +64,7 @@ public void shouldMapViaMethodAndMethod() throws DatatypeConfigurationException ObjectFactory.class, TargetDto.class } ) + @WithJavaxJaxb public void shouldMapViaMethodAndConversion() { SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; @@ -78,6 +81,7 @@ public void shouldMapViaMethodAndConversion() { ObjectFactory.class, TargetDto.class } ) + @WithJavaxJaxb public void shouldMapViaConversionAndMethod() { SourceTypeTargetDtoMapper instance = SourceTypeTargetDtoMapper.INSTANCE; diff --git a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java index 68ae703769..fe99685e9c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/references/samename/SeveralReferencedMappersWithSameSimpleNameTest.java @@ -12,6 +12,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; import static org.assertj.core.api.Assertions.assertThat; @@ -30,6 +31,7 @@ Jsr330SourceTargetMapper.class, AnotherSourceTargetMapper.class }) +@WithJavaxInject public class SeveralReferencedMappersWithSameSimpleNameTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java index 02705a097a..94fe8a1c10 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/JaxbFactoryMethodSelectionTest.java @@ -13,6 +13,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @@ -28,6 +29,7 @@ OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class, OrderMapper.class }) +@WithJavaxJaxb public class JaxbFactoryMethodSelectionTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java index f94dd7c94c..caa60eeea3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/jaxb/UnderscoreSelectionTest.java @@ -13,6 +13,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @@ -23,6 +24,7 @@ */ @IssueKey( "726" ) @WithClasses( { UnderscoreType.class, ObjectFactory.class, SuperType.class, SubType.class, UnderscoreMapper.class } ) +@WithJavaxJaxb public class UnderscoreSelectionTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxInject.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxInject.java new file mode 100644 index 0000000000..de2ae231e7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxInject.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "javax.inject", +}) +public @interface WithJavaxInject { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxJaxb.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxJaxb.java new file mode 100644 index 0000000000..a404187b52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJavaxJaxb.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "jaxb-api", +}) +public @interface WithJavaxJaxb { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJoda.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJoda.java new file mode 100644 index 0000000000..5b8bede20b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJoda.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "joda-time" +}) +public @interface WithJoda { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java new file mode 100644 index 0000000000..40db5afd81 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "spring-beans", + "spring-context" +}) +public @interface WithSpring { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependencies.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependencies.java new file mode 100644 index 0000000000..c9e8d8c523 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependencies.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Filip Hrisafov + * @see WithTestDependency + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +public @interface WithTestDependencies { + + WithTestDependency[] value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependency.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependency.java new file mode 100644 index 0000000000..26d478b666 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithTestDependency.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies the group id of the additional test dependencies that should be added to the test compile path + * + * @author Filip Hrisafov + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +@Repeatable( WithTestDependencies.class ) +public @interface WithTestDependency { + /** + * @return The group ids of the additional test dependencies for the test compile path + */ + String[] value(); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index 3f1599aad0..60e9a30072 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.testutil.runner; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; @@ -17,13 +18,15 @@ public class CompilationRequest { private final Set> sourceClasses; private final Map, Class> services; private final List processorOptions; + private final Collection testDependencies; CompilationRequest(Compiler compiler, Set> sourceClasses, Map, Class> services, - List processorOptions) { + List processorOptions, Collection testDependencies) { this.compiler = compiler; this.sourceClasses = sourceClasses; this.services = services; this.processorOptions = processorOptions; + this.testDependencies = testDependencies; } @Override @@ -34,6 +37,7 @@ public int hashCode() { result = prime * result + ( ( processorOptions == null ) ? 0 : processorOptions.hashCode() ); result = prime * result + ( ( services == null ) ? 0 : services.hashCode() ); result = prime * result + ( ( sourceClasses == null ) ? 0 : sourceClasses.hashCode() ); + result = prime * result + ( ( testDependencies == null ) ? 0 : testDependencies.hashCode() ); return result; } @@ -53,6 +57,7 @@ public boolean equals(Object obj) { return compiler.equals( other.compiler ) && processorOptions.equals( other.processorOptions ) && services.equals( other.services ) + && testDependencies.equals( other.testDependencies ) && sourceClasses.equals( other.sourceClasses ); } @@ -67,4 +72,8 @@ public List getProcessorOptions() { public Map, Class> getServices() { return services; } + + public Collection getTestDependencies() { + return testDependencies; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index b372974461..7c47d2a2e8 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -22,7 +23,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.stream.Stream; import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.ConfigurationLoader; @@ -34,6 +34,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.WithTestDependency; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.DisableCheckstyle; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @@ -98,37 +99,38 @@ protected String getPathSuffix() { return "_" + compiler.name().toLowerCase(); } + /** + * Build the default test compilation classpath + * needed for compiling the generated sources once the processor has run. + */ private static List buildTestCompilationClasspath() { - String[] whitelist = - new String[] { + Collection whitelist = Arrays.asList( // MapStruct annotations in multi-module reactor build or IDE "core" + File.separator + "target", // MapStruct annotations in single module build "org" + File.separator + "mapstruct" + File.separator + "mapstruct" + File.separator, - "guava", - "javax.inject", - "spring-beans", - "spring-context", - "jaxb-api", - "joda-time" }; + "guava" + ); return filterBootClassPath( whitelist ); } + /** + * Build the annotation processor classpath. + * i.e. the classpath that is needed to run the annotation processor with its own dependencies only. + * The optional dependencies are not needed in this classpath. + */ private static List buildProcessorClasspath() { - String[] whitelist = - new String[] { + Collection whitelist = Arrays.asList( "processor" + File.separator + "target", // the processor itself, "freemarker", - "javax.inject", - "spring-context", - "gem-api", - "joda-time" }; + "gem-api" + ); return filterBootClassPath( whitelist ); } - protected static List filterBootClassPath(String[] whitelist) { + protected static List filterBootClassPath(Collection whitelist) { String[] bootClasspath = System.getProperty( "java.class.path" ).split( File.pathSeparator ); String testClasses = "target" + File.separator + "test-classes"; @@ -143,8 +145,8 @@ protected static List filterBootClassPath(String[] whitelist) { return classpath; } - private static boolean isWhitelisted(String path, String[] whitelist) { - return Stream.of( whitelist ).anyMatch( path::contains ); + private static boolean isWhitelisted(String path, Collection whitelist) { + return whitelist.stream().anyMatch( path::contains ); } @Override @@ -368,6 +370,17 @@ private Map, Class> getServices(Method testMethod, Class testClas return services; } + private Collection getAdditionalTestDependencies(Method testMethod, Class testClass) { + Collection testDependencies = new HashSet<>(); + findRepeatableAnnotations( testMethod, WithTestDependency.class ) + .forEach( annotation -> Collections.addAll( testDependencies, annotation.value() ) ); + + findRepeatableAnnotations( testClass, WithTestDependency.class ) + .forEach( annotation -> Collections.addAll( testDependencies, annotation.value() ) ); + + return testDependencies; + } + private void addServices(Map, Class> services, List withImplementations) { for ( WithServiceImplementation withImplementation : withImplementations ) { addService( services, withImplementation ); @@ -446,7 +459,8 @@ private CompilationOutcomeDescriptor compile(ExtensionContext context) { compiler, getTestClasses( testMethod, testClass ), getServices( testMethod, testClass ), - getProcessorOptions( testMethod, testClass ) + getProcessorOptions( testMethod, testClass ), + getAdditionalTestDependencies( testMethod, testClass ) ); ExtensionContext.Store rootStore = context.getRoot().getStore( NAMESPACE ); diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java index 6cab46cc7f..c356347664 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java @@ -6,6 +6,9 @@ package org.mapstruct.ap.testutil.runner; import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -65,13 +68,27 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe return clHelper.compileInOtherClassloader( compilationRequest, - TEST_COMPILATION_CLASSPATH, + getTestCompilationClasspath( compilationRequest ), getSourceFiles( compilationRequest.getSourceClasses() ), SOURCE_DIR, sourceOutputDir, classOutputDir ); } + private static List getTestCompilationClasspath(CompilationRequest request) { + Collection testDependencies = request.getTestDependencies(); + if ( testDependencies.isEmpty() ) { + return TEST_COMPILATION_CLASSPATH; + } + + List testCompilationPaths = new ArrayList<>( + TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() ); + + testCompilationPaths.addAll( TEST_COMPILATION_CLASSPATH ); + testCompilationPaths.addAll( filterBootClassPath( testDependencies ) ); + return testCompilationPaths; + } + private static FilteringParentClassLoader newFilteringClassLoaderForEclipse() { return new FilteringParentClassLoader( // reload eclipse compiler classes @@ -143,12 +160,12 @@ private static String getSourceVersion() { } private static List buildEclipseCompilerClasspath() { - String[] whitelist = - new String[] { + Collection whitelist = Arrays.asList( "tycho-compiler", "ecj", "plexus-compiler-api", - "plexus-component-annotations" }; + "plexus-component-annotations" + ); return filterBootClassPath( whitelist ); } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 1761956678..2a0b6ba537 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Objects; import javax.annotation.processing.Processor; @@ -57,7 +58,7 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.getSourceClasses() ) ); try { - fileManager.setLocation( StandardLocation.CLASS_PATH, COMPILER_CLASSPATH_FILES ); + fileManager.setLocation( StandardLocation.CLASS_PATH, getCompilerClasspathFiles( compilationRequest ) ); fileManager.setLocation( StandardLocation.CLASS_OUTPUT, Arrays.asList( new File( classOutputDir ) ) ); fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Arrays.asList( new File( sourceOutputDir ) ) ); } @@ -97,6 +98,23 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe diagnostics.getDiagnostics() ); } + private static List getCompilerClasspathFiles(CompilationRequest request) { + Collection testDependencies = request.getTestDependencies(); + if ( testDependencies.isEmpty() ) { + return COMPILER_CLASSPATH_FILES; + } + + List compilerClasspathFiles = new ArrayList<>( + COMPILER_CLASSPATH_FILES.size() + testDependencies.size() ); + + compilerClasspathFiles.addAll( COMPILER_CLASSPATH_FILES ); + for ( String testDependencyPath : filterBootClassPath( testDependencies ) ) { + compilerClasspathFiles.add( new File( testDependencyPath ) ); + } + + return compilerClasspathFiles; + } + private static List asFiles(List paths) { List classpath = new ArrayList<>(); for ( String path : paths ) { From aade31f095f037a0ddf934de24f1638cb24aac6b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Jan 2022 21:12:30 +0100 Subject: [PATCH 0642/1006] #2468 Update needed dependencies for running CDI tests on Java 16+ --- .../mapstruct/itest/tests/MavenIntegrationTest.java | 2 -- integrationtest/src/test/resources/cdiTest/pom.xml | 2 +- .../org/mapstruct/itest/cdi/CdiBasedMapperTest.java | 4 +++- parent/pom.xml | 11 ++++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 59aa48b053..9696542f58 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -5,7 +5,6 @@ */ package org.mapstruct.itest.tests; -import org.junit.jupiter.api.condition.DisabledForJreRange; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.parallel.Execution; @@ -26,7 +25,6 @@ void autoValueBuilderTest() { } @ProcessorTest(baseDir = "cdiTest") - @DisabledForJreRange(min = JRE.JAVA_16) void cdiTest() { } diff --git a/integrationtest/src/test/resources/cdiTest/pom.xml b/integrationtest/src/test/resources/cdiTest/pom.xml index 30d35a421e..0b3c394e82 100644 --- a/integrationtest/src/test/resources/cdiTest/pom.xml +++ b/integrationtest/src/test/resources/cdiTest/pom.xml @@ -56,7 +56,7 @@ org.jboss.weld - weld-core + weld-core-impl test diff --git a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java index 702ab6d255..0c343fce27 100644 --- a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java +++ b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java @@ -38,7 +38,9 @@ public static JavaArchive createDeployment() { .addPackage( SourceTargetMapper.class.getPackage() ) .addPackage( DateMapper.class.getPackage() ) .addAsManifestResource( - new StringAsset("org.mapstruct.itest.cdi.SourceTargetMapperDecorator"), + new StringAsset("" + + "org.mapstruct.itest.cdi.SourceTargetMapperDecorator" + + ""), "beans.xml" ); } diff --git a/parent/pom.xml b/parent/pom.xml index 242d5215de..21413dcef0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -152,7 +152,7 @@ javax.enterprise cdi-api - 1.2 + 2.0.SP1 javax.inject @@ -162,19 +162,20 @@ org.jboss.arquillian arquillian-bom - 1.0.2.Final + 1.6.0.Final import pom org.jboss.arquillian.container arquillian-weld-se-embedded-1.1 - 1.0.0.CR7 + 1.0.0.Final org.jboss.weld - weld-core - 2.3.2.Final + weld-core-impl + 3.1.8.Final + test org.glassfish From 5f4d355838adffe2691f4e2d3eb3ac7f6c4c7850 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Jan 2022 11:46:34 +0100 Subject: [PATCH 0643/1006] #1661 Add support for globally disabling builders --- .../src/main/asciidoc/chapter-2-set-up.asciidoc | 5 +++++ .../chapter-3-defining-a-mapper.asciidoc | 2 +- .../java/org/mapstruct/ap/MappingProcessor.java | 4 ++++ .../mapstruct/ap/internal/option/Options.java | 10 +++++++++- .../util/AnnotationProcessorContext.java | 10 ++++++++-- .../off/SimpleNotRealyImmutableBuilderTest.java | 17 ++++++++++++++++- .../builder/off/SimpleWithBuilderMapper.java | 17 +++++++++++++++++ 7 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleWithBuilderMapper.java diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 730433639d..54906f7893 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -260,6 +260,11 @@ Supported values are: If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence. If a policy is given for a specific bean mapping via `@BeanMapping#ignoreUnmappedSourceProperties()`, it takes precedence over both `@Mapper#unmappedSourcePolicy()` and the option. |`WARN` + +|`mapstruct. +disableBuilders` +|If set to `true`, then MapStruct will not use builder patterns when doing the mapping. This is equivalent to doing `@Mapper( builder = @Builder( disableBuilder = true ) )` for all of your mappers. +|`false` |=== === Using MapStruct with the Java Module System diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 9d5124ee97..d1c63c25a2 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -532,7 +532,7 @@ Otherwise, you would need to write a custom `BuilderProvider` [TIP] ==== -In case you want to disable using builders then you can use the `NoOpBuilderProvider` by creating a `org.mapstruct.ap.spi.BuilderProvider` file in the `META-INF/services` directory with `org.mapstruct.ap.spi.NoOpBuilderProvider` as it's content. +In case you want to disable using builders then you can pass the MapStruct processor option `mapstruct.disableBuilders` to the compiler. e.g. `-Amapstruct.disableBuilders=true`. ==== [[mapping-with-constructors]] diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 952257753a..0cc6b7cce3 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -87,6 +87,7 @@ MappingProcessor.UNMAPPED_SOURCE_POLICY, MappingProcessor.DEFAULT_COMPONENT_MODEL, MappingProcessor.DEFAULT_INJECTION_STRATEGY, + MappingProcessor.DISABLE_BUILDERS, MappingProcessor.VERBOSE }) public class MappingProcessor extends AbstractProcessor { @@ -104,6 +105,7 @@ public class MappingProcessor extends AbstractProcessor { protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; protected static final String DEFAULT_INJECTION_STRATEGY = "mapstruct.defaultInjectionStrategy"; protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; + protected static final String DISABLE_BUILDERS = "mapstruct.disableBuilders"; protected static final String VERBOSE = "mapstruct.verbose"; private Options options; @@ -130,6 +132,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { processingEnv.getElementUtils(), processingEnv.getTypeUtils(), processingEnv.getMessager(), + options.isDisableBuilders(), options.isVerbose() ); } @@ -146,6 +149,7 @@ private Options createOptions() { processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), + Boolean.valueOf( processingEnv.getOptions().get( DISABLE_BUILDERS ) ), Boolean.valueOf( processingEnv.getOptions().get( VERBOSE ) ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 46a90d4b43..65089cc139 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -21,13 +21,16 @@ public class Options { private final boolean alwaysGenerateSpi; private final String defaultComponentModel; private final String defaultInjectionStrategy; + private final boolean disableBuilders; private final boolean verbose; public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyGem unmappedTargetPolicy, ReportingPolicyGem unmappedSourcePolicy, String defaultComponentModel, String defaultInjectionStrategy, - boolean alwaysGenerateSpi, boolean verbose) { + boolean alwaysGenerateSpi, + boolean disableBuilders, + boolean verbose) { this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; @@ -35,6 +38,7 @@ public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVers this.defaultComponentModel = defaultComponentModel; this.defaultInjectionStrategy = defaultInjectionStrategy; this.alwaysGenerateSpi = alwaysGenerateSpi; + this.disableBuilders = disableBuilders; this.verbose = verbose; } @@ -66,6 +70,10 @@ public boolean isAlwaysGenerateSpi() { return alwaysGenerateSpi; } + public boolean isDisableBuilders() { + return disableBuilders; + } + public boolean isVerbose() { return verbose; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 86fb7e3092..7421dfde7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; import org.mapstruct.ap.spi.ImmutablesBuilderProvider; import org.mapstruct.ap.spi.MapStructProcessingEnvironment; +import org.mapstruct.ap.spi.NoOpBuilderProvider; /** * Keeps contextual data in the scope of the entire annotation processor ("application scope"). @@ -51,14 +52,17 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private Elements elementUtils; private Types typeUtils; private Messager messager; + private boolean disableBuilder; private boolean verbose; - public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messager messager, boolean verbose) { + public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messager messager, boolean disableBuilder, + boolean verbose) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors( messager ) ); this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; + this.disableBuilder = disableBuilder; this.verbose = verbose; } @@ -103,7 +107,9 @@ else if ( elementUtils.getTypeElement( FreeBuilderConstants.FREE_BUILDER_FQN ) ! + this.accessorNamingStrategy.getClass().getCanonicalName() ); } - this.builderProvider = Services.get( BuilderProvider.class, defaultBuilderProvider ); + this.builderProvider = this.disableBuilder ? + new NoOpBuilderProvider() : + Services.get( BuilderProvider.class, defaultBuilderProvider ); this.builderProvider.init( this ); if ( verbose ) { messager.printMessage( diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java index cc11a8fcdb..30cf5ff12d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleNotRealyImmutableBuilderTest.java @@ -9,12 +9,13 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.factory.Mappers; import static org.assertj.core.api.Assertions.assertThat; -@IssueKey("1743") +@IssueKey("1661") @WithClasses({ SimpleMutablePerson.class, SimpleNotRealyImmutablePerson.class @@ -36,4 +37,18 @@ public void testSimpleImmutableBuilderHappyPath() { assertThat( targetObject.getName() ).isEqualTo( "Bob" ); } + + @ProcessorTest + @WithClasses({ SimpleWithBuilderMapper.class }) + @ProcessorOption( name = "mapstruct.disableBuilders", value = "true") + public void builderGloballyDisabled() { + SimpleWithBuilderMapper mapper = Mappers.getMapper( SimpleWithBuilderMapper.class ); + SimpleMutablePerson source = new SimpleMutablePerson(); + source.setFullName( "Bob" ); + + SimpleNotRealyImmutablePerson targetObject = mapper.toNotRealyImmutable( source ); + + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleWithBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleWithBuilderMapper.java new file mode 100644 index 0000000000..6df547db78 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/off/SimpleWithBuilderMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.off; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface SimpleWithBuilderMapper { + + @Mapping(target = "name", source = "fullName") + SimpleNotRealyImmutablePerson toNotRealyImmutable(SimpleMutablePerson source); +} From 464adc914306ce32c5a5c89cd537009806c6ec34 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Jan 2022 09:24:56 +0100 Subject: [PATCH 0644/1006] #2682 Change RetentionPolicy of `@DecoratedWith` to `CLASS` In some circumstances (used with other types of aggregating processors, e.g. Spring) the Gradle incremental compilation works correctly only for classes annotated with the `CLASS` or `RUNTIME` retention policy. The `@DecoratedWith` is the only annotation from MapStruct that was `SOURCE` retention. With this commit we are changing its retention policy in order for better compatibility with the Gradle Incremental compilation --- core/src/main/java/org/mapstruct/DecoratedWith.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/DecoratedWith.java b/core/src/main/java/org/mapstruct/DecoratedWith.java index 78b2c580ff..8a644f4b22 100644 --- a/core/src/main/java/org/mapstruct/DecoratedWith.java +++ b/core/src/main/java/org/mapstruct/DecoratedWith.java @@ -145,7 +145,7 @@ * @author Gunnar Morling */ @Target(ElementType.TYPE) -@Retention(RetentionPolicy.SOURCE) +@Retention(RetentionPolicy.CLASS) public @interface DecoratedWith { /** From aed3ff5295fd91f28622f41ea14cf0a4e9670efa Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Jan 2022 22:04:12 +0100 Subject: [PATCH 0645/1006] #1997 Use builders to construct empty objects in update wrapper --- .../ap/internal/model/MethodReference.java | 53 +++++++++++++++++++ .../model/ObjectFactoryMethodResolver.java | 6 ++- .../ap/internal/model/PropertyMapping.java | 22 ++++++++ .../ap/internal/model/MethodReference.ftl | 2 + .../org/mapstruct/ap/test/bugs/_1997/Car.java | 44 +++++++++++++++ .../ap/test/bugs/_1997/CarDetail.java | 44 +++++++++++++++ .../ap/test/bugs/_1997/CarInsurance.java | 44 +++++++++++++++ .../test/bugs/_1997/CarInsuranceMapper.java | 23 ++++++++ .../ap/test/bugs/_1997/Issue1997Test.java | 35 ++++++++++++ 9 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarDetail.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsurance.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsuranceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Issue1997Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java index 78a3830f45..e2e518c55b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReference.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; @@ -58,8 +59,10 @@ public class MethodReference extends ModelElement implements Assignment { private final Type definingType; private final List parameterBindings; private final Parameter providingParameter; + private final List methodsToChain; private final boolean isStatic; private final boolean isConstructor; + private final boolean isMethodChaining; /** * Creates a new reference to the given method. @@ -95,6 +98,8 @@ protected MethodReference(Method method, MapperReference declaringMapper, Parame this.isStatic = method.isStatic(); this.name = method.getName(); this.isConstructor = false; + this.methodsToChain = Collections.emptyList(); + this.isMethodChaining = false; } private MethodReference(BuiltInMethod method, ConversionContext contextParam) { @@ -111,6 +116,8 @@ private MethodReference(BuiltInMethod method, ConversionContext contextParam) { this.isStatic = method.isStatic(); this.name = method.getName(); this.isConstructor = false; + this.methodsToChain = Collections.emptyList(); + this.isMethodChaining = false; } private MethodReference(String name, Type definingType, boolean isStatic) { @@ -127,6 +134,8 @@ private MethodReference(String name, Type definingType, boolean isStatic) { this.providingParameter = null; this.isStatic = isStatic; this.isConstructor = false; + this.methodsToChain = Collections.emptyList(); + this.isMethodChaining = false; } private MethodReference(Type definingType, List parameterBindings) { @@ -142,6 +151,8 @@ private MethodReference(Type definingType, List parameterBindi this.providingParameter = null; this.isStatic = false; this.isConstructor = true; + this.methodsToChain = Collections.emptyList(); + this.isMethodChaining = false; if ( parameterBindings.isEmpty() ) { this.importTypes = Collections.emptySet(); @@ -159,6 +170,24 @@ private MethodReference(Type definingType, List parameterBindi } } + private MethodReference(MethodReference... references) { + this.name = null; + this.definingType = null; + this.sourceParameters = Collections.emptyList(); + this.returnType = null; + this.declaringMapper = null; + this.importTypes = Collections.emptySet(); + this.thrownTypes = Collections.emptyList(); + this.isUpdateMethod = false; + this.contextParam = null; + this.parameterBindings = null; + this.providingParameter = null; + this.isStatic = false; + this.isConstructor = false; + this.methodsToChain = Arrays.asList( references ); + this.isMethodChaining = true; + } + public MapperReference getDeclaringMapper() { return declaringMapper; } @@ -267,6 +296,12 @@ public Set getImportTypes() { if ( isStatic() ) { imported.add( definingType ); } + if ( isMethodChaining() ) { + for ( MethodReference methodToChain : methodsToChain ) { + imported.addAll( methodToChain.getImportTypes() ); + } + } + return imported; } @@ -276,6 +311,12 @@ public List getThrownTypes() { if ( assignment != null ) { exceptions.addAll( assignment.getThrownTypes() ); } + if ( isMethodChaining() ) { + for ( MethodReference methodToChain : methodsToChain ) { + exceptions.addAll( methodToChain.getThrownTypes() ); + } + + } return exceptions; } @@ -311,6 +352,14 @@ public boolean isConstructor() { return isConstructor; } + public boolean isMethodChaining() { + return isMethodChaining; + } + + public List getMethodsToChain() { + return methodsToChain; + } + public List getParameterBindings() { return parameterBindings; } @@ -385,6 +434,10 @@ public static MethodReference forConstructorInvocation(Type type, List> getMatchingFactoryMethods( Meth } public static MethodReference getBuilderFactoryMethod(Method method, BuilderType builder ) { + return getBuilderFactoryMethod( method.getReturnType(), builder ); + } + + public static MethodReference getBuilderFactoryMethod(Type typeToBuild, BuilderType builder ) { if ( builder == null ) { return null; } @@ -149,7 +153,7 @@ public static MethodReference getBuilderFactoryMethod(Method method, BuilderType return null; } - if ( !builder.getBuildingType().isAssignableTo( method.getReturnType() ) ) { + if ( !builder.getBuildingType().isAssignableTo( typeToBuild ) ) { //TODO print error message return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index f17ab9ddb1..ad788de43b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -419,6 +419,28 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { Assignment factory = ObjectFactoryMethodResolver .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ), ctx ); + + if ( factory == null && targetBuilderType != null) { + // If there is no dedicated factory method and the target has a builder we will try to use that + MethodReference builderFactoryMethod = ObjectFactoryMethodResolver.getBuilderFactoryMethod( + targetType, + targetBuilderType + ); + + if ( builderFactoryMethod != null ) { + + MethodReference finisherMethod = BuilderFinisherMethodResolver.getBuilderFinisherMethod( + method, + targetBuilderType, + ctx + ); + + if ( finisherMethod != null ) { + factory = MethodReference.forMethodChaining( builderFactoryMethod, finisherMethod ); + } + } + + } return new UpdateWrapper( rhs, method.getThrownTypes(), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index d0ee7bef3b..271ba58f9b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -18,6 +18,8 @@ <@includeModel object=definingType/>.<@methodCall/> <#elseif constructor> new <@includeModel object=definingType/><#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() + <#elseif methodChaining> + <#list methodsToChain as methodToChain><@includeModel object=methodToChain /><#if methodToChain_has_next>. <#else> <@methodCall/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Car.java new file mode 100644 index 0000000000..87722cdb50 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Car.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1997; + +/** + * @author Filip Hrisafov + */ +public class Car { + private String model; + + private Car(Builder builder) { + this.model = builder.model; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String model; + + public Builder model(String model) { + this.model = model; + return this; + } + + public Car build() { + return new Car( this ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarDetail.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarDetail.java new file mode 100644 index 0000000000..84472d1263 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarDetail.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1997; + +/** + * @author Filip Hrisafov + */ +public class CarDetail { + private String model; + + private CarDetail(Builder builder) { + this.model = builder.model; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String model; + + public Builder model(String model) { + this.model = model; + return this; + } + + public CarDetail build() { + return new CarDetail( this ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsurance.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsurance.java new file mode 100644 index 0000000000..83fb4350dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsurance.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1997; + +/** + * @author Filip Hrisafov + */ +public class CarInsurance { + private CarDetail detail; + + private CarInsurance(Builder builder) { + this.detail = builder.detail; + } + + public CarDetail getDetail() { + return detail; + } + + public void setDetail(CarDetail detail) { + this.detail = detail; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private CarDetail detail; + + public Builder detail(CarDetail detail) { + this.detail = detail; + return this; + } + + public CarInsurance build() { + return new CarInsurance( this ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsuranceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsuranceMapper.java new file mode 100644 index 0000000000..79369b9a79 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/CarInsuranceMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1997; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CarInsuranceMapper { + + CarInsuranceMapper INSTANCE = Mappers.getMapper( CarInsuranceMapper.class ); + + @Mapping(source = "model", target = "detail.model") + void update(Car source, @MappingTarget CarInsurance target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Issue1997Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Issue1997Test.java new file mode 100644 index 0000000000..5645ca173b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1997/Issue1997Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1997; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Car.class, + CarDetail.class, + CarInsurance.class, + CarInsuranceMapper.class +}) +class Issue1997Test { + + @ProcessorTest + void shouldCorrectCreateIntermediateObjectsWithBuilder() { + Car source = Car.builder().model( "Model S" ).build(); + CarInsurance target = CarInsurance.builder().build(); + assertThat( target.getDetail() ).isNull(); + + CarInsuranceMapper.INSTANCE.update( source, target ); + + assertThat( target.getDetail() ).isNotNull(); + assertThat( target.getDetail().getModel() ).isEqualTo( "Model S" ); + } +} From 12070186a43f9d4f03c0b441cbe5cd56c16089a9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Jan 2022 18:57:41 +0100 Subject: [PATCH 0646/1006] #2567 Add support for Jakarta Injection Support for Jakarta is done in 2 ways: * current jsr330 component model - In this case Jakarta Inject will be used if javax.inject is not available * new jakarta component model - In this case Jakarta Inject will always be used --- .../java/org/mapstruct/DecoratedWith.java | 8 +- .../java/org/mapstruct/InjectionStrategy.java | 2 +- core/src/main/java/org/mapstruct/Mapper.java | 7 +- .../main/java/org/mapstruct/MapperConfig.java | 7 +- .../java/org/mapstruct/MappingConstants.java | 15 +++- .../main/asciidoc/chapter-2-set-up.asciidoc | 3 +- .../test/resources/fullFeatureTest/pom.xml | 4 + parent/pom.xml | 5 ++ processor/pom.xml | 5 ++ .../ap/internal/gem/MappingConstantsGem.java | 2 + .../processor/JakartaComponentProcessor.java | 78 +++++++++++++++++++ .../processor/Jsr330ComponentProcessor.java | 24 +++++- ...p.internal.processor.ModelElementProcessor | 1 + .../jsr330/JakartaJsr330DecoratorTest.java | 55 +++++++++++++ .../jakarta/jsr330/PersonMapper.java | 25 ++++++ .../jakarta/jsr330/PersonMapperDecorator.java | 27 +++++++ .../mapstruct/ap/test/gem/ConstantTest.java | 2 + ...akartaDefaultCompileOptionFieldMapper.java | 21 +++++ ...akartaDefaultCompileOptionFieldMapper.java | 26 +++++++ ...30DefaultCompileOptionFieldMapperTest.java | 55 +++++++++++++ ...taDefaultCompileOptionFieldMapperTest.java | 53 +++++++++++++ ...JakartaCompileOptionConstructorMapper.java | 24 ++++++ ...JakartaCompileOptionConstructorMapper.java | 26 +++++++ ...330CompileOptionConstructorMapperTest.java | 59 ++++++++++++++ ...rtaCompileOptionConstructorMapperTest.java | 57 ++++++++++++++ .../constructor/ConstructorJakartaConfig.java | 18 +++++ .../CustomerJakartaConstructorMapper.java | 26 +++++++ .../GenderJakartaConstructorMapper.java | 25 ++++++ ...JakartaAndJsr330ConstructorMapperTest.java | 58 ++++++++++++++ .../JakartaConstructorMapperTest.java | 56 +++++++++++++ .../jakarta/field/CustomerFieldMapper.java | 22 ++++++ .../jakarta/field/FieldJakartaConfig.java | 17 ++++ .../field/GenderJakartaFieldMapper.java | 25 ++++++ .../JakartaAndJsr330FieldMapperTest.java | 53 +++++++++++++ .../jakarta/field/JakartaFieldMapperTest.java | 51 ++++++++++++ ...30DefaultCompileOptionFieldMapperTest.java | 3 + ...330CompileOptionConstructorMapperTest.java | 3 + .../Jsr330ConstructorMapperTest.java | 3 + .../jsr330/field/Jsr330FieldMapperTest.java | 3 + ...Jsr330DefaultCompileOptionFieldMapper.java | 21 +++++ ...Jsr330DefaultCompileOptionFieldMapper.java | 26 +++++++ ...30DefaultCompileOptionFieldMapperTest.java | 55 +++++++++++++ ...30DefaultCompileOptionFieldMapperTest.java | 53 +++++++++++++ .../ap/testutil/WithJakartaInject.java | 27 +++++++ 44 files changed, 1123 insertions(+), 13 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/JakartaJsr330DecoratorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/CustomerJakartaDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/GenderJakartaDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/CustomerJakartaCompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/GenderJakartaCompileOptionConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaAndJsr330CompileOptionConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaCompileOptionConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/ConstructorJakartaConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/CustomerJakartaConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/GenderJakartaConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaAndJsr330ConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaConstructorMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/CustomerFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/FieldJakartaConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/GenderJakartaFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaAndJsr330FieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/CustomerJsr330DefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/GenderJsr330DefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaJsr330DefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaInject.java diff --git a/core/src/main/java/org/mapstruct/DecoratedWith.java b/core/src/main/java/org/mapstruct/DecoratedWith.java index 8a644f4b22..b4ca05f3de 100644 --- a/core/src/main/java/org/mapstruct/DecoratedWith.java +++ b/core/src/main/java/org/mapstruct/DecoratedWith.java @@ -103,12 +103,12 @@ * private PersonMapper personMapper; // injects the decorator, with the injected original mapper * * - *

    3. Component model 'jsr330'

    + *

    3. Component model 'jsr330' or 'jakarta'

    *

    Referencing the original mapper

    *

    - * JSR 330 doesn't specify qualifiers and only allows to specifically name the beans. Hence, the generated - * implementation of the original mapper is annotated with - * {@code @javax.inject.Named("fully-qualified-name-of-generated-impl")} and {@code @Singleton} (please note that when + * JSR 330 / Jakarta Inject doesn't specify qualifiers and only allows to specifically name the beans. Hence, + * the generated implementation of the original mapper is annotated with + * {@code @Named("fully-qualified-name-of-generated-impl")} and {@code @Singleton} (please note that when * using a decorator, the class name of the mapper implementation ends with an underscore). To inject that bean in your * decorator, add the same annotation to the delegate field (e.g. by copy/pasting it from the generated class): * diff --git a/core/src/main/java/org/mapstruct/InjectionStrategy.java b/core/src/main/java/org/mapstruct/InjectionStrategy.java index 84baa8afa9..b841667671 100644 --- a/core/src/main/java/org/mapstruct/InjectionStrategy.java +++ b/core/src/main/java/org/mapstruct/InjectionStrategy.java @@ -7,7 +7,7 @@ /** * Strategy for handling injection. This is only used on annotated based component models such as CDI, Spring and - * JSR330. + * JSR330 / Jakarta. * * @author Kevin Grüneberg */ diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index c5aed661f3..0436c0cf69 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -142,7 +142,12 @@ * can be retrieved via {@code @Autowired} *

  • * {@code jsr330}: the generated mapper is annotated with {@code @javax.inject.Named} and - * {@code @Singleton}, and can be retrieved via {@code @Inject}
  • + * {@code @Singleton}, and can be retrieved via {@code @Inject}. + * The annotations will either be from javax.inject or jakarta.inject, + * depending on which one is available, with javax.inject having precedence. + *
  • + * {@code jakarta}: the generated mapper is annotated with {@code @jakarta.inject.Named} and + * {@code @Singleton}, and can be retrieved via {@code @Inject}.
  • * * The method overrides a componentModel set in a central configuration set * by {@link #config() } diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 757a4ab0af..893801cdaa 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -131,7 +131,12 @@ * can be retrieved via {@code @Autowired} *
  • * {@code jsr330}: the generated mapper is annotated with {@code @javax.inject.Named} and - * {@code @Singleton}, and can be retrieved via {@code @Inject}
  • + * {@code @Singleton}, and can be retrieved via {@code @Inject}. + * The annotations will either be from javax.inject or jakarta.inject, + * depending on which one is available, with javax.inject having precedence. + *
  • + * {@code jakarta}: the generated mapper is annotated with {@code @jakarta.inject.Named} and + * {@code @Singleton}, and can be retrieved via {@code @Inject}.
  • * * * @return The component model for the generated mapper. diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index 002f005299..ce2438298c 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -120,11 +120,24 @@ private ComponentModel() { public static final String SPRING = "spring"; /** - * The generated mapper is annotated with @javax.inject.Named and @Singleton, and can be retrieved via @Inject + * The generated mapper is annotated with @Named and @Singleton, and can be retrieved via @Inject. + * The annotations are either from {@code javax.inject} or {@code jakarta.inject}. + * Priority have the {@code javax.inject} annotations. + * In case you want to only use Jakarta then use {@link #JAKARTA}. * + * @see #JAKARTA */ public static final String JSR330 = "jsr330"; + /** + * The generated mapper is annotated with @Named and @Singleton, and can be retrieved via @Inject. + * The annotations are from {@code jakarta.inject}. + * In case you want to use {@code javax.inject} then use {@link #JSR330}. + * + * @see #JSR330 + */ + public static final String JAKARTA = "jakarta"; + } } diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 54906f7893..d95983e840 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -217,7 +217,8 @@ Supported values are: * `default`: the mapper uses no component model, instances are typically retrieved via `Mappers#getMapper(Class)` * `cdi`: the generated mapper is an application-scoped CDI bean and can be retrieved via `@Inject` * `spring`: the generated mapper is a singleton-scoped Spring bean and can be retrieved via `@Autowired` -* `jsr330`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject`, e.g. using Spring +* `jsr330`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject` (from javax.inject or jakarta.inject, depending which one is available with javax.inject having priority), e.g. using Spring +* `jakarta`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject` (from jakarta.inject), e.g. using Spring If a component model is given for a specific mapper via `@Mapper#componentModel()`, the value from the annotation takes precedence. |`default` diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index ebf4590d30..ec26f45ce2 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -60,6 +60,10 @@ javax.inject javax.inject
    + + jakarta.inject + jakarta.inject-api + diff --git a/parent/pom.xml b/parent/pom.xml index 21413dcef0..1f75e9d6d5 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -159,6 +159,11 @@ javax.inject 1 + + jakarta.inject + jakarta.inject-api + 2.0.1 + org.jboss.arquillian arquillian-bom diff --git a/processor/pom.xml b/processor/pom.xml index 4f2476ceb0..2a3c38abfc 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -83,6 +83,11 @@ javax.inject test + + jakarta.inject + jakarta.inject-api + test + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index b49b9d17e5..cb6d49c0cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -49,6 +49,8 @@ private ComponentModelGem() { public static final String SPRING = "spring"; public static final String JSR330 = "jsr330"; + + public static final String JAKARTA = "jakarta"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java new file mode 100644 index 0000000000..5161ea689c --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java @@ -0,0 +1,78 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.processor; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import org.mapstruct.ap.internal.model.Annotation; +import org.mapstruct.ap.internal.model.Mapper; + +/** + * A {@link ModelElementProcessor} which converts the given {@link Mapper} + * object into a Jakarta Inject style bean in case "jakarta" is configured as the + * target component model for this mapper. + * + * @author Filip Hrisafov + */ +public class JakartaComponentProcessor extends AnnotationBasedComponentModelProcessor { + @Override + protected String getComponentModelIdentifier() { + return MappingConstantsGem.ComponentModelGem.JAKARTA; + } + + @Override + protected List getTypeAnnotations(Mapper mapper) { + if ( mapper.getDecorator() == null ) { + return Arrays.asList( singleton(), named() ); + } + else { + return Arrays.asList( singleton(), namedDelegate( mapper ) ); + } + } + + @Override + protected List getDecoratorAnnotations() { + return Arrays.asList( singleton(), named() ); + } + + @Override + protected List getDelegatorReferenceAnnotations(Mapper mapper) { + return Arrays.asList( inject(), namedDelegate( mapper ) ); + } + + @Override + protected List getMapperReferenceAnnotations() { + return Collections.singletonList( inject() ); + } + + @Override + protected boolean requiresGenerationOfDecoratorClass() { + return true; + } + + private Annotation singleton() { + return new Annotation( getTypeFactory().getType( "jakarta.inject.Singleton" ) ); + } + + private Annotation named() { + return new Annotation( getTypeFactory().getType( "jakarta.inject.Named" ) ); + } + + private Annotation namedDelegate(Mapper mapper) { + return new Annotation( + getTypeFactory().getType( "jakarta.inject.Named" ), + Collections.singletonList( '"' + mapper.getPackageName() + "." + mapper.getName() + '"' ) + ); + } + + private Annotation inject() { + return new Annotation( getTypeFactory().getType( "jakarta.inject.Inject" ) ); + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java index 18a6e4f69d..6a6cc16580 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.AnnotationProcessingException; /** * A {@link ModelElementProcessor} which converts the given {@link Mapper} @@ -58,21 +60,35 @@ protected boolean requiresGenerationOfDecoratorClass() { } private Annotation singleton() { - return new Annotation( getTypeFactory().getType( "javax.inject.Singleton" ) ); + return new Annotation( getType( "Singleton" ) ); } private Annotation named() { - return new Annotation( getTypeFactory().getType( "javax.inject.Named" ) ); + return new Annotation( getType( "Named" ) ); } private Annotation namedDelegate(Mapper mapper) { return new Annotation( - getTypeFactory().getType( "javax.inject.Named" ), + getType( "Named" ), Collections.singletonList( '"' + mapper.getPackageName() + "." + mapper.getName() + '"' ) ); } private Annotation inject() { - return new Annotation( getTypeFactory().getType( "javax.inject.Inject" ) ); + return new Annotation( getType( "Inject" ) ); + } + + private Type getType(String simpleName) { + if ( getTypeFactory().isTypeAvailable( "javax.inject." + simpleName ) ) { + return getTypeFactory().getType( "javax.inject." + simpleName ); + } + + if ( getTypeFactory().isTypeAvailable( "jakarta.inject." + simpleName ) ) { + return getTypeFactory().getType( "jakarta.inject." + simpleName ); + } + + throw new AnnotationProcessingException( + "Couldn't find any of the JSR330 or Jakarta Dependency Inject types." + + " Are you missing a dependency on your classpath?" ); } } diff --git a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor index 7b27e54faf..cab1d83ed7 100644 --- a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor +++ b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor @@ -4,6 +4,7 @@ org.mapstruct.ap.internal.processor.CdiComponentProcessor org.mapstruct.ap.internal.processor.Jsr330ComponentProcessor +org.mapstruct.ap.internal.processor.JakartaComponentProcessor org.mapstruct.ap.internal.processor.MapperCreationProcessor org.mapstruct.ap.internal.processor.MapperRenderingProcessor org.mapstruct.ap.internal.processor.MethodRetrievalProcessor diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/JakartaJsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/JakartaJsr330DecoratorTest.java new file mode 100644 index 0000000000..2e0dfcec00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/JakartaJsr330DecoratorTest.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.jsr330; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + PersonMapper.class, + PersonMapperDecorator.class +}) +@IssueKey("2567") +@WithJakartaInject +// We can't use Spring for testing since Spring 5 does not support Jakarta Inject +// However, we can test the generated source code +public class JakartaJsr330DecoratorTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void hasCorrectImports() { + // check the decorator + generatedSource.forMapper( PersonMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Singleton" + lineSeparator() + "@Named" ) + .doesNotContain( "javax.inject" ); + // check the plain mapper + generatedSource.forDecoratedMapper( PersonMapper.class ).content() + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Singleton" + lineSeparator() + "@Named" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapper.java new file mode 100644 index 0000000000..74ef38439f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.jsr330; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) +@DecoratedWith(PersonMapperDecorator.class) +public interface PersonMapper { + + @Mapping( target = "name", ignore = true ) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapperDecorator.java new file mode 100644 index 0000000000..f16a9f8c1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/jsr330/PersonMapperDecorator.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.jsr330; + +import jakarta.inject.Inject; +import jakarta.inject.Named; + +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +public abstract class PersonMapperDecorator implements PersonMapper { + + @Inject + @Named("org.mapstruct.ap.test.decorator.jakarta.jsr330.PersonMapperImpl_") + private PersonMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index e3a5b7c264..548ee61f2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -40,5 +40,7 @@ public void componentModelContantsShouldBeEqual() { assertThat( MappingConstants.ComponentModel.CDI ).isEqualTo( MappingConstantsGem.ComponentModelGem.CDI ); assertThat( MappingConstants.ComponentModel.SPRING ).isEqualTo( MappingConstantsGem.ComponentModelGem.SPRING ); assertThat( MappingConstants.ComponentModel.JSR330 ).isEqualTo( MappingConstantsGem.ComponentModelGem.JSR330 ); + assertThat( MappingConstants.ComponentModel.JAKARTA ) + .isEqualTo( MappingConstantsGem.ComponentModelGem.JAKARTA ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/CustomerJakartaDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/CustomerJakartaDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..2fb6ae0d07 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/CustomerJakartaDefaultCompileOptionFieldMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA, + uses = GenderJakartaDefaultCompileOptionFieldMapper.class) +public interface CustomerJakartaDefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/GenderJakartaDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/GenderJakartaDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..da3409ef41 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/GenderJakartaDefaultCompileOptionFieldMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA) +public interface GenderJakartaDefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..c647605e66 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta._default; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jakarta. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaDefaultCompileOptionFieldMapper.class, + GenderJakartaDefaultCompileOptionFieldMapper.class +}) +@WithJakartaInject +@WithJavaxInject +public class JakartaAndJsr330DefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaDefaultCompileOptionFieldMapper" ) + .doesNotContain( "public CustomerJakartaDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..01b43c5b46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/_default/JakartaDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta._default; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jakarta. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaDefaultCompileOptionFieldMapper.class, + GenderJakartaDefaultCompileOptionFieldMapper.class +}) +@WithJakartaInject +public class JakartaDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaDefaultCompileOptionFieldMapper" ) + .doesNotContain( "public CustomerJakartaDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/CustomerJakartaCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/CustomerJakartaCompileOptionConstructorMapper.java new file mode 100644 index 0000000000..9775d05c87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/CustomerJakartaCompileOptionConstructorMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper( componentModel = MappingConstants.ComponentModel.JAKARTA, + uses = GenderJakartaCompileOptionConstructorMapper.class ) +public interface CustomerJakartaCompileOptionConstructorMapper { + + @Mapping(target = "gender", source = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/GenderJakartaCompileOptionConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/GenderJakartaCompileOptionConstructorMapper.java new file mode 100644 index 0000000000..4539bb1c69 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/GenderJakartaCompileOptionConstructorMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.compileoptionconstructor; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA) +public interface GenderJakartaCompileOptionConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaAndJsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaAndJsr330CompileOptionConstructorMapperTest.java new file mode 100644 index 0000000000..c897891b14 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaAndJsr330CompileOptionConstructorMapperTest.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.compileoptionconstructor; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test constructor injection for component model jakarta with compile option + * mapstruct.defaultInjectionStrategy=constructor + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaCompileOptionConstructorMapper.class, + GenderJakartaCompileOptionConstructorMapper.class +}) +@ProcessorOption(name = "mapstruct.defaultInjectionStrategy", value = "constructor") +@WithJakartaInject +@WithJavaxInject +public class JakartaAndJsr330CompileOptionConstructorMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaCompileOptionConstructorMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "private final GenderJakartaCompileOptionConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJakartaCompileOptionConstructorMapperImpl" + + "(GenderJakartaCompileOptionConstructorMapper" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaCompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaCompileOptionConstructorMapperTest.java new file mode 100644 index 0000000000..cc36591bb7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/compileoptionconstructor/JakartaCompileOptionConstructorMapperTest.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.compileoptionconstructor; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test constructor injection for component model jakarta with compile option + * mapstruct.defaultInjectionStrategy=constructor + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaCompileOptionConstructorMapper.class, + GenderJakartaCompileOptionConstructorMapper.class +}) +@ProcessorOption(name = "mapstruct.defaultInjectionStrategy", value = "constructor") +@WithJakartaInject +public class JakartaCompileOptionConstructorMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaCompileOptionConstructorMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "private final GenderJakartaCompileOptionConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJakartaCompileOptionConstructorMapperImpl" + + "(GenderJakartaCompileOptionConstructorMapper" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/ConstructorJakartaConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/ConstructorJakartaConfig.java new file mode 100644 index 0000000000..0bc9bb16e6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/ConstructorJakartaConfig.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = MappingConstants.ComponentModel.JAKARTA, + injectionStrategy = InjectionStrategy.CONSTRUCTOR) +public interface ConstructorJakartaConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/CustomerJakartaConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/CustomerJakartaConstructorMapper.java new file mode 100644 index 0000000000..73d201cbfb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/CustomerJakartaConstructorMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.constructor; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper( componentModel = MappingConstants.ComponentModel.JAKARTA, + uses = GenderJakartaConstructorMapper.class, + injectionStrategy = InjectionStrategy.CONSTRUCTOR ) +public interface CustomerJakartaConstructorMapper { + + @Mapping(target = "gender", source = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/GenderJakartaConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/GenderJakartaConstructorMapper.java new file mode 100644 index 0000000000..7cbd0bb3df --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/GenderJakartaConstructorMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.constructor; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = ConstructorJakartaConfig.class) +public interface GenderJakartaConstructorMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaAndJsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaAndJsr330ConstructorMapperTest.java new file mode 100644 index 0000000000..03b5dcf2bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaAndJsr330ConstructorMapperTest.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.constructor; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaConstructorMapper.class, + GenderJakartaConstructorMapper.class, + ConstructorJakartaConfig.class +}) +@ComponentScan(basePackageClasses = CustomerJakartaConstructorMapper.class) +@Configuration +@WithJakartaInject +@WithJavaxInject +public class JakartaAndJsr330ConstructorMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaConstructorMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "private final GenderJakartaConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJakartaConstructorMapperImpl(GenderJakartaConstructorMapper" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaConstructorMapperTest.java new file mode 100644 index 0000000000..45ea7efca8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/constructor/JakartaConstructorMapperTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.constructor; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaConstructorMapper.class, + GenderJakartaConstructorMapper.class, + ConstructorJakartaConfig.class +}) +@ComponentScan(basePackageClasses = CustomerJakartaConstructorMapper.class) +@Configuration +@WithJakartaInject +public class JakartaConstructorMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaConstructorMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "private final GenderJakartaConstructorMapper" ) + .contains( "@Inject" + lineSeparator() + + " public CustomerJakartaConstructorMapperImpl(GenderJakartaConstructorMapper" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/CustomerFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/CustomerFieldMapper.java new file mode 100644 index 0000000000..550d4ee945 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/CustomerFieldMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA, uses = GenderJakartaFieldMapper.class, + injectionStrategy = InjectionStrategy.FIELD) +public interface CustomerFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/FieldJakartaConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/FieldJakartaConfig.java new file mode 100644 index 0000000000..b3ad9474cf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/FieldJakartaConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.field; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = MappingConstants.ComponentModel.JAKARTA, injectionStrategy = InjectionStrategy.FIELD) +public interface FieldJakartaConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/GenderJakartaFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/GenderJakartaFieldMapper.java new file mode 100644 index 0000000000..ee5b959307 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/GenderJakartaFieldMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.field; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = FieldJakartaConfig.class) +public interface GenderJakartaFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaAndJsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaAndJsr330FieldMapperTest.java new file mode 100644 index 0000000000..56ea535571 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaAndJsr330FieldMapperTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.field; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerFieldMapper.class, + GenderJakartaFieldMapper.class, + FieldJakartaConfig.class +}) +@IssueKey("2567") +@WithJakartaInject +@WithJavaxInject +public class JakartaAndJsr330FieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerFieldMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaFieldMapper" ) + .doesNotContain( "public CustomerJakartaFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaFieldMapperTest.java new file mode 100644 index 0000000000..2257bcb7ba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/field/JakartaFieldMapperTest.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.field; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerFieldMapper.class, + GenderJakartaFieldMapper.class, + FieldJakartaConfig.class +}) +@IssueKey("2567") +@WithJakartaInject +public class JakartaFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerFieldMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaFieldMapper" ) + .doesNotContain( "public CustomerJakartaFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java index dd639684b8..6b92d9815a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java @@ -87,6 +87,9 @@ public void shouldConvertToTarget() { public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerJsr330DefaultCompileOptionFieldMapper.class ) .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) .contains( "@Inject" + lineSeparator() + " private GenderJsr330DefaultCompileOptionFieldMapper" ) .doesNotContain( "public CustomerJsr330DefaultCompileOptionFieldMapperImpl(" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java index 24bfba5511..fe9cf295f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java @@ -86,6 +86,9 @@ public void shouldConvertToTarget() { public void shouldHaveConstructorInjectionFromCompileOption() { generatedSource.forMapper( CustomerJsr330CompileOptionConstructorMapper.class ) .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) .contains( "private final GenderJsr330CompileOptionConstructorMapper" ) .contains( "@Inject" + lineSeparator() + " public CustomerJsr330CompileOptionConstructorMapperImpl" + diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java index 8543d57e38..a5cfce5c2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -86,6 +86,9 @@ public void shouldConvertToTarget() { public void shouldHaveConstructorInjection() { generatedSource.forMapper( CustomerJsr330ConstructorMapper.class ) .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) .contains( "private final GenderJsr330ConstructorMapper" ) .contains( "@Inject" + lineSeparator() + " public CustomerJsr330ConstructorMapperImpl(GenderJsr330ConstructorMapper" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java index d8cf0c3925..84e67f63a8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -89,6 +89,9 @@ public void shouldConvertToTarget() { public void shouldHaveFieldInjection() { generatedSource.forMapper( CustomerJsr330FieldMapper.class ) .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) .contains( "@Inject" + lineSeparator() + " private GenderJsr330FieldMapper" ) .doesNotContain( "public CustomerJsr330FieldMapperImpl(" ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/CustomerJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/CustomerJsr330DefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..80f5c60ef0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/CustomerJsr330DefaultCompileOptionFieldMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.jakarta; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330, + uses = GenderJsr330DefaultCompileOptionFieldMapper.class) +public interface CustomerJsr330DefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/GenderJsr330DefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/GenderJsr330DefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..4a9b56c1b2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/GenderJsr330DefaultCompileOptionFieldMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.jakarta; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Andrei Arlou + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) +public interface GenderJsr330DefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..da7176fc7a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaAndJsr330DefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.jakarta; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jsr330. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330DefaultCompileOptionFieldMapper.class, + GenderJsr330DefaultCompileOptionFieldMapper.class +}) +@WithJakartaInject +@WithJavaxInject +public class JakartaAndJsr330DefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJavaxInjection() { + generatedSource.forMapper( CustomerJsr330DefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJsr330DefaultCompileOptionFieldMapper" ) + .doesNotContain( "public CustomerJsr330DefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "jakarta.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaJsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaJsr330DefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..f78721fb1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/jakarta/JakartaJsr330DefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.jakarta; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jsr330. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2567") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330DefaultCompileOptionFieldMapper.class, + GenderJsr330DefaultCompileOptionFieldMapper.class +}) +@WithJakartaInject +public class JakartaJsr330DefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJsr330DefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJsr330DefaultCompileOptionFieldMapper" ) + .doesNotContain( "public CustomerJsr330DefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaInject.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaInject.java new file mode 100644 index 0000000000..ccb0b030a1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaInject.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "jakarta.inject-api", +}) +public @interface WithJakartaInject { + +} From 37835a560770c307b1955a11cb399985bdc6a7b4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 30 Jan 2022 20:49:05 +0100 Subject: [PATCH 0647/1006] #2677 Use type without bounds when looking for read / presence accessor in a SourceReference --- .../model/beanmapping/SourceReference.java | 7 +- .../ap/test/bugs/_2677/Issue2677Mapper.java | 117 ++++++++++++++++++ .../ap/test/bugs/_2677/Issue2677Test.java | 92 ++++++++++++++ 3 files changed, 213 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index d5c18a99f1..8824f95901 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -311,11 +311,12 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent Type newType = type; for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; - ReadAccessor readAccessor = newType.getReadAccessor( entryNames[i] ); + Type noBoundsType = newType.withoutBounds(); + ReadAccessor readAccessor = noBoundsType.getReadAccessor( entryNames[i] ); if ( readAccessor != null ) { - PresenceCheckAccessor presenceChecker = newType.getPresenceChecker( entryNames[i] ); + PresenceCheckAccessor presenceChecker = noBoundsType.getPresenceChecker( entryNames[i] ); newType = typeFactory.getReturnType( - (DeclaredType) newType.getTypeMirror(), + (DeclaredType) noBoundsType.getTypeMirror(), readAccessor ); sourceEntries.add( forSourceReference( diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Mapper.java new file mode 100644 index 0000000000..e74ad1e770 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Mapper.java @@ -0,0 +1,117 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2677; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2677Mapper { + + Issue2677Mapper INSTANCE = Mappers.getMapper( Issue2677Mapper.class ); + + @Mapping(target = "id", source = "value.id") + Output map(Wrapper in); + + @Mapping(target = ".", source = "value") + Output mapImplicitly(Wrapper in); + + @Mapping(target = "id", source = "value.id") + Output mapFromParent(Wrapper in); + + @Mapping(target = "id", source = "value.id") + Output mapFromChild(Wrapper in); + + @Mapping( target = "value", source = "wrapperValue") + Wrapper mapToWrapper(String wrapperValue, Wrapper wrapper); + + @Mapping(target = "id", source = "value.id") + Output mapWithPresenceCheck(Wrapper in); + + class Wrapper { + private final T value; + private final String status; + + public Wrapper(T value, String status) { + this.value = value; + this.status = status; + } + + public String getStatus() { + return status; + } + + public T getValue() { + return value; + } + } + + class Parent { + private final int id; + + public Parent(int id) { + this.id = id; + } + + public int getId() { + return id; + } + } + + class Child extends Parent { + private final String whatever; + + public Child(int id, String whatever) { + super( id ); + this.whatever = whatever; + } + + public String getWhatever() { + return whatever; + } + } + + class ParentWithPresenceCheck { + private final int id; + + public ParentWithPresenceCheck(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public boolean hasId() { + return id > 10; + } + } + + class Output { + private int id; + private String status; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Test.java new file mode 100644 index 0000000000..0eb4d6d794 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2677/Issue2677Test.java @@ -0,0 +1,92 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2677; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2677") +@WithClasses({ + Issue2677Mapper.class +}) +class Issue2677Test { + + @ProcessorTest + void shouldCorrectlyUseGenericsWithExtends() { + Issue2677Mapper.Parent parent = new Issue2677Mapper.Parent( 10 ); + Issue2677Mapper.Child child = new Issue2677Mapper.Child( 15, "Test" ); + + Issue2677Mapper.Output output = Issue2677Mapper.INSTANCE.map( new Issue2677Mapper.Wrapper<>( + parent, + "extends" + ) ); + + assertThat( output.getStatus() ).isEqualTo( "extends" ); + assertThat( output.getId() ).isEqualTo( 10 ); + + output = Issue2677Mapper.INSTANCE.mapFromChild( new Issue2677Mapper.Wrapper<>( + child, + "child" + ) ); + + assertThat( output.getStatus() ).isEqualTo( "child" ); + assertThat( output.getId() ).isEqualTo( 15 ); + + output = Issue2677Mapper.INSTANCE.mapFromParent( new Issue2677Mapper.Wrapper<>( + parent, + "parent" + ) ); + + assertThat( output.getStatus() ).isEqualTo( "parent" ); + assertThat( output.getId() ).isEqualTo( 10 ); + + output = Issue2677Mapper.INSTANCE.mapImplicitly( new Issue2677Mapper.Wrapper<>( + child, + "implicit" + ) ); + + assertThat( output.getStatus() ).isEqualTo( "implicit" ); + assertThat( output.getId() ).isEqualTo( 15 ); + + Issue2677Mapper.Wrapper result = Issue2677Mapper.INSTANCE.mapToWrapper( + "test", + new Issue2677Mapper.Wrapper<>( + child, + "super" + ) + ); + + assertThat( result.getStatus() ).isEqualTo( "super" ); + assertThat( result.getValue() ).isEqualTo( "test" ); + + output = Issue2677Mapper.INSTANCE.mapWithPresenceCheck( + new Issue2677Mapper.Wrapper<>( + new Issue2677Mapper.ParentWithPresenceCheck( 8 ), + "presenceCheck" + ) + ); + + assertThat( output.getStatus() ).isEqualTo( "presenceCheck" ); + assertThat( output.getId() ).isEqualTo( 0 ); + + output = Issue2677Mapper.INSTANCE.mapWithPresenceCheck( + new Issue2677Mapper.Wrapper<>( + new Issue2677Mapper.ParentWithPresenceCheck( 15 ), + "presenceCheck" + ) + ); + + assertThat( output.getStatus() ).isEqualTo( "presenceCheck" ); + assertThat( output.getId() ).isEqualTo( 15 ); + + } +} From 2a2c11e871001909187cea173d442624e724c64c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 30 Jan 2022 20:52:22 +0100 Subject: [PATCH 0648/1006] #2629 Use ModuleElement when getting type element Prior to this MapStruct would only use `Elements#getTypeElement`. With this PR if the mapper being generated is within a module MapStruct will use that module for the methods that are needed (getTypeElement and getPackageElement). Adapt the build to require a minimum Java 11 for building the processor module. Adapt the GitHub actions to properly run integration tests with Java 8 Ignore Java 9 usages for the animal-sniffer-plugin --- .github/workflows/main.yml | 36 ++++++-- .../itest/tests/MavenIntegrationTest.java | 8 ++ .../test/resources/lombokModuleTest/pom.xml | 85 +++++++++++++++++++ .../src/main/java/module-info.java | 9 ++ .../org/mapstruct/itest/lombok/Address.java | 18 ++++ .../mapstruct/itest/lombok/AddressDto.java | 19 +++++ .../org/mapstruct/itest/lombok/Person.java | 30 +++++++ .../org/mapstruct/itest/lombok/PersonDto.java | 30 +++++++ .../mapstruct/itest/lombok/PersonMapper.java | 21 +++++ .../itest/lombok/LombokMapperTest.java | 37 ++++++++ parent/pom.xml | 12 ++- processor/pom.xml | 1 + .../org/mapstruct/ap/MappingProcessor.java | 6 +- .../DefaultModelElementProcessorContext.java | 5 +- .../util/AbstractElementUtilsDecorator.java | 33 ++++++- .../util/EclipseElementUtilsDecorator.java | 4 +- .../ap/internal/util/ElementUtils.java | 7 +- .../internal/util/IgnoreJRERequirement.java | 16 ++++ .../util/JavacElementUtilsDecorator.java | 4 +- 19 files changed, 357 insertions(+), 24 deletions(-) create mode 100644 integrationtest/src/test/resources/lombokModuleTest/pom.xml create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/module-info.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Address.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Person.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java create mode 100644 integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/IgnoreJRERequirement.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b023631628..6d80d2da89 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - java: [11, 13, 16, 17] + java: [13, 16, 17] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: @@ -25,15 +25,15 @@ jobs: - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true linux: - name: 'Linux JDK 8' + name: 'Linux JDK 11' runs-on: ubuntu-latest steps: - name: 'Checkout' uses: actions/checkout@v2 - - name: 'Set up JDK 8' + - name: 'Set up JDK 11' uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 11 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install - name: 'Generate coverage report' @@ -43,25 +43,43 @@ jobs: - name: 'Publish Snapshots' if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy + linux-jdk-8: + name: 'Linux JDK 8' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v2 + - name: 'Set up JDK 11 for building everything' + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: 'Install Processor' + run: ./mvnw ${MAVEN_ARGS} -DskipTests install -pl processor -am + - name: 'Set up JDK 8 for running integration tests' + uses: actions/setup-java@v1 + with: + java-version: 8 + - name: 'Run integration tests' + run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest windows: name: 'Windows' runs-on: windows-latest steps: - uses: actions/checkout@v2 - - name: 'Set up JDK 8' + - name: 'Set up JDK 11' uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 11 - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} install + run: ./mvnw %MAVEN_ARGS% install mac: name: 'Mac OS' runs-on: macos-latest steps: - uses: actions/checkout@v2 - - name: 'Set up JDK 8' + - name: 'Set up JDK 11' uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 11 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 9696542f58..4f4182d5c7 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -85,6 +85,14 @@ void jsr330Test() { void lombokBuilderTest() { } + @ProcessorTest(baseDir = "lombokModuleTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC, + ProcessorTest.ProcessorType.JAVAC_WITH_PATHS + }) + @EnabledForJreRange(min = JRE.JAVA_11) + void lombokModuleTest() { + } + @ProcessorTest(baseDir = "namingStrategyTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }) diff --git a/integrationtest/src/test/resources/lombokModuleTest/pom.xml b/integrationtest/src/test/resources/lombokModuleTest/pom.xml new file mode 100644 index 0000000000..16b32cfb4f --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + lombokModuleIntegrationTest + jar + + + 11 + 11 + + + + + org.projectlombok + lombok + compile + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + compile + + + + + + generate-via-compiler-plugin-with-annotation-processor-paths + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + \${compiler-id} + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + + + org.projectlombok + lombok + 1.18.22 + + + org.projectlombok + lombok-mapstruct-binding + 0.2.0 + + + + + + org.eclipse.tycho + tycho-compiler-jdt + ${org.eclipse.tycho.compiler-jdt.version} + + + + + + + + diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/module-info.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/module-info.java new file mode 100644 index 0000000000..9bc85bea86 --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/module-info.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +module org.example { + requires org.mapstruct; + requires lombok; +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Address.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Address.java new file mode 100644 index 0000000000..f83c6881ce --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Address.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +public class Address { + private final String addressLine; + + public Address(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java new file mode 100644 index 0000000000..d6b4f30f88 --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/AddressDto.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +public class AddressDto { + + private final String addressLine; + + public AddressDto(String addressLine) { + this.addressLine = addressLine; + } + + public String getAddressLine() { + return addressLine; + } +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Person.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Person.java new file mode 100644 index 0000000000..b6ca47fca1 --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/Person.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +public class Person { + private final String name; + private final int age; + private final Address address; + + public Person(String name, int age, Address address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public Address getAddress() { + return address; + } +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java new file mode 100644 index 0000000000..3223778663 --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonDto.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +public class PersonDto { + private final String name; + private final int age; + private final AddressDto address; + + public PersonDto(String name, int age, AddressDto address) { + this.name = name; + this.age = age; + this.address = address; + } + + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + public AddressDto getAddress() { + return address; + } +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java new file mode 100644 index 0000000000..27184bad27 --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/main/java/org/mapstruct/itest/lombok/PersonMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface PersonMapper { + + PersonMapper INSTANCE = Mappers.getMapper( PersonMapper.class ); + + Person fromDto(PersonDto personDto); + PersonDto toDto(Person personDto); +} diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java b/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java new file mode 100644 index 0000000000..f8b702896d --- /dev/null +++ b/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.lombok; + +import org.junit.Test; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for generation of Lombok Builder Mapper implementations + * + * @author Eric Martineau + */ +public class LombokMapperTest { + + @Test + public void testSimpleImmutableBuilderHappyPath() { + PersonDto personDto = PersonMapper.INSTANCE.toDto( new Person( "Bob", 33, new Address( "Wild Drive" ) ) ); + assertThat( personDto.getAge() ).isEqualTo( 33 ); + assertThat( personDto.getName() ).isEqualTo( "Bob" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } + + @Test + public void testLombokToImmutable() { + Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); + assertThat( person.getAge() ).isEqualTo( 33 ); + assertThat( person.getName() ).isEqualTo( "Bob" ); + assertThat( person.getAddress() ).isNotNull(); + assertThat( person.getAddress().getAddressLine() ).isEqualTo( "Wild Drive" ); + } +} diff --git a/parent/pom.xml b/parent/pom.xml index 1f75e9d6d5..4ca3d9b2c0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -36,6 +36,11 @@ jdt_apt + + 1.8
    @@ -214,7 +219,7 @@ org.projectlombok lombok - 1.18.20 + 1.18.22 org.immutables @@ -666,6 +671,9 @@ java18 1.0 + + org.mapstruct.ap.internal.util.IgnoreJRERequirement + @@ -685,7 +693,7 @@ - [1.8,) + [${minimum.java.version},) diff --git a/processor/pom.xml b/processor/pom.xml index 2a3c38abfc..ec3f20a241 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -24,6 +24,7 @@ + 11 diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 0cc6b7cce3..4f9e0fa384 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -269,7 +269,11 @@ private void processMapperElements(Set mapperElements, RoundContext // of one outer interface List tst = mapperElement.getEnclosedElements(); ProcessorContext context = new DefaultModelElementProcessorContext( - processingEnv, options, roundContext, getDeclaredTypesNotToBeImported( mapperElement ) + processingEnv, + options, + roundContext, + getDeclaredTypesNotToBeImported( mapperElement ), + mapperElement ); processMapperTypeElement( context, mapperElement ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index d6a05cec32..51ea5dd786 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -13,6 +13,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.model.common.TypeFactory; @@ -46,14 +47,14 @@ public class DefaultModelElementProcessorContext implements ProcessorContext { private final RoundContext roundContext; public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvironment, Options options, - RoundContext roundContext, Map notToBeImported) { + RoundContext roundContext, Map notToBeImported, TypeElement mapperElement) { this.processingEnvironment = processingEnvironment; this.messager = new DelegatingMessager( processingEnvironment.getMessager(), options.isVerbose() ); this.accessorNaming = roundContext.getAnnotationProcessorContext().getAccessorNaming(); this.versionInformation = DefaultVersionInformation.fromProcessingEnvironment( processingEnvironment ); this.delegatingTypes = TypeUtils.create( processingEnvironment, versionInformation ); - this.delegatingElements = ElementUtils.create( processingEnvironment, versionInformation ); + this.delegatingElements = ElementUtils.create( processingEnvironment, versionInformation, mapperElement ); this.roundContext = roundContext; this.typeFactory = new TypeFactory( delegatingElements, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java index 14734b9c8e..72a44d106f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java @@ -13,11 +13,13 @@ import java.util.ListIterator; import java.util.Map; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; +import javax.lang.model.element.ModuleElement; import javax.lang.model.element.Name; import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; @@ -35,19 +37,44 @@ public abstract class AbstractElementUtilsDecorator implements ElementUtils { private final Elements delegate; + /** + * The module element when running with the module system, + * {@code null} otherwise. + */ + private final Element moduleElement; - AbstractElementUtilsDecorator(ProcessingEnvironment processingEnv) { + @IgnoreJRERequirement + AbstractElementUtilsDecorator(ProcessingEnvironment processingEnv, TypeElement mapperElement) { this.delegate = processingEnv.getElementUtils(); + if ( SourceVersion.RELEASE_8.compareTo( processingEnv.getSourceVersion() ) >= 0 ) { + // We are running with Java 8 or lower + this.moduleElement = null; + } + else { + this.moduleElement = this.delegate.getModuleOf( mapperElement ); + } } @Override + @IgnoreJRERequirement public PackageElement getPackageElement(CharSequence name) { - return delegate.getPackageElement( name ); + if ( this.moduleElement == null ) { + return this.delegate.getPackageElement( name ); + } + + // If the module element is not null then we must be running on Java 8+ + return this.delegate.getPackageElement( (ModuleElement) moduleElement, name ); } @Override + @IgnoreJRERequirement public TypeElement getTypeElement(CharSequence name) { - return delegate.getTypeElement( name ); + if ( this.moduleElement == null ) { + return this.delegate.getTypeElement( name ); + } + + // If the module element is not null then we must be running on Java 8+ + return this.delegate.getTypeElement( (ModuleElement) moduleElement, name ); } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java index aaf1bb7e20..3c1dc84d36 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/EclipseElementUtilsDecorator.java @@ -13,8 +13,8 @@ public class EclipseElementUtilsDecorator extends AbstractElementUtilsDecorator private final Elements delegate; - EclipseElementUtilsDecorator(ProcessingEnvironment processingEnv) { - super( processingEnv ); + EclipseElementUtilsDecorator(ProcessingEnvironment processingEnv, TypeElement mapperElement) { + super( processingEnv, mapperElement ); this.delegate = processingEnv.getElementUtils(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java index fdd221c1a6..3e026cde80 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/ElementUtils.java @@ -16,12 +16,13 @@ public interface ElementUtils extends Elements { - static ElementUtils create(ProcessingEnvironment processingEnvironment, VersionInformation info ) { + static ElementUtils create(ProcessingEnvironment processingEnvironment, VersionInformation info, + TypeElement mapperElement) { if ( info.isEclipseJDTCompiler() ) { - return new EclipseElementUtilsDecorator( processingEnvironment ); + return new EclipseElementUtilsDecorator( processingEnvironment, mapperElement ); } else { - return new JavacElementUtilsDecorator( processingEnvironment ); + return new JavacElementUtilsDecorator( processingEnvironment, mapperElement ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/IgnoreJRERequirement.java b/processor/src/main/java/org/mapstruct/ap/internal/util/IgnoreJRERequirement.java new file mode 100644 index 0000000000..565ebcce12 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/IgnoreJRERequirement.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.CLASS) +@Target({ ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE }) +public @interface IgnoreJRERequirement { +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java index ad035743cf..fa0e46171b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavacElementUtilsDecorator.java @@ -10,8 +10,8 @@ public class JavacElementUtilsDecorator extends AbstractElementUtilsDecorator { - JavacElementUtilsDecorator(ProcessingEnvironment processingEnv) { - super( processingEnv ); + JavacElementUtilsDecorator(ProcessingEnvironment processingEnv, TypeElement mapperElement) { + super( processingEnv, mapperElement ); } @Override From 7bb85d05c0a7f8dc755c271a37e8feb3b09a592e Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 6 Feb 2022 20:03:23 +0100 Subject: [PATCH 0649/1006] 2696: Invert `@SubclassMappings` with `@InheritInverseConfiguration`. (#2708) * #2696: Added support for '@InheritInverseConfiguration' with '@SubclassMappings'. * #2696: Overriding of inverse inheritence implemented. New order has preference over inherited order. --- .../ap/internal/model/BeanMappingMethod.java | 1 + .../model/source/MappingMethodOptions.java | 50 ++++++++++--- .../internal/model/source/SourceMethod.java | 14 +++- .../model/source/SubclassMappingOptions.java | 72 ++++++++++++------ .../model/source/SubclassValidator.java | 19 +++-- .../processor/MapperCreationProcessor.java | 36 ++++++--- .../processor/MethodRetrievalProcessor.java | 22 ++++-- .../mapstruct/ap/internal/util/Message.java | 1 + .../ErroneousInverseSubclassMapper.java | 29 ++++++++ .../InverseOrderSubclassMapper.java | 40 ++++++++++ .../subclassmapping/SimpleSubclassMapper.java | 6 ++ .../subclassmapping/SubclassMappingTest.java | 74 +++++++++++++++---- .../fixture/SubSourceOverride.java | 18 +++++ .../fixture/SubSourceSeparate.java | 18 +++++ .../fixture/SubTargetSeparate.java | 18 +++++ .../fixture/SubclassAbstractMapper.java | 6 ++ .../fixture/SubclassFixtureTest.java | 4 + .../fixture/SubclassAbstractMapperImpl.java | 62 +++++++++++++++- 18 files changed, 417 insertions(+), 73 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousInverseSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InverseOrderSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOverride.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceSeparate.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetSeparate.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index bdfd8cf54a..267702826b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -157,6 +157,7 @@ public Builder forgedMethod(ForgedMethod forgedMethod) { return this; } + @Override public BeanMappingMethod build() { BeanMappingOptions beanMapping = method.getOptions().getBeanMapping(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 45b1175f8d..4a140c4fb9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import javax.lang.model.element.AnnotationMirror; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.model.common.Type; @@ -35,7 +36,8 @@ public class MappingMethodOptions { null, null, Collections.emptyList(), - Collections.emptySet() + Collections.emptySet(), + null ); private MapperOptions mapper; @@ -46,14 +48,16 @@ public class MappingMethodOptions { private EnumMappingOptions enumMappingOptions; private List valueMappings; private boolean fullyInitialized; - private Set subclassMapping; + private Set subclassMappings; + + private SubclassValidator subclassValidator; public MappingMethodOptions(MapperOptions mapper, Set mappings, IterableMappingOptions iterableMapping, MapMappingOptions mapMapping, BeanMappingOptions beanMapping, EnumMappingOptions enumMappingOptions, List valueMappings, - Set subclassMapping) { + Set subclassMappings, SubclassValidator subclassValidator) { this.mapper = mapper; this.mappings = mappings; this.iterableMapping = iterableMapping; @@ -61,7 +65,8 @@ public MappingMethodOptions(MapperOptions mapper, Set mappings, this.beanMapping = beanMapping; this.enumMappingOptions = enumMappingOptions; this.valueMappings = valueMappings; - this.subclassMapping = subclassMapping; + this.subclassMappings = subclassMappings; + this.subclassValidator = subclassValidator; } /** @@ -102,7 +107,7 @@ public List getValueMappings() { } public Set getSubclassMappings() { - return subclassMapping; + return subclassMappings; } public void setIterableMapping(IterableMappingOptions iterableMapping) { @@ -144,10 +149,13 @@ public void markAsFullyInitialized() { /** * Merges in all the mapping options configured, giving the already defined options precedence. * + * @param sourceMethod the method which inherits the options. * @param templateMethod the template method with the options to inherit, may be {@code null} * @param isInverse if {@code true}, the specified options are from an inverse method + * @param annotationMirror the annotation on which the compile errors will be shown. */ - public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse) { + public void applyInheritedOptions(SourceMethod sourceMethod, SourceMethod templateMethod, boolean isInverse, + AnnotationMirror annotationMirror) { MappingMethodOptions templateOptions = templateMethod.getOptions(); if ( null != templateOptions ) { if ( !getIterableMapping().hasAnnotation() && templateOptions.getIterableMapping().hasAnnotation() ) { @@ -184,7 +192,7 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } else { if ( templateOptions.getValueMappings() != null ) { - // iff there are also inherited mappings, we inverse and add them. + // if there are also inherited mappings, we inverse and add them. for ( ValueMappingOptions inheritedValueMapping : templateOptions.getValueMappings() ) { ValueMappingOptions valueMapping = isInverse ? inheritedValueMapping.inverse() : inheritedValueMapping; @@ -196,7 +204,13 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } } - // Do NOT inherit subclass mapping options!!! + if ( isInverse ) { + // normal inheritence of subclass mappings will result runtime in infinite loops. + List inheritedMappings = SubclassMappingOptions.copyForInverseInheritance( + templateOptions.getSubclassMappings(), + getBeanMapping() ); + addAllNonRedefined( sourceMethod, annotationMirror, inheritedMappings ); + } Set newMappings = new LinkedHashSet<>(); for ( MappingOptions mapping : templateOptions.getMappings() ) { @@ -218,6 +232,21 @@ public void applyInheritedOptions(SourceMethod templateMethod, boolean isInverse } } + private void addAllNonRedefined(SourceMethod sourceMethod, AnnotationMirror annotationMirror, + List inheritedMappings) { + Set redefinedSubclassMappings = new HashSet<>( subclassMappings ); + for ( SubclassMappingOptions subclassMappingOption : inheritedMappings ) { + if ( !redefinedSubclassMappings.contains( subclassMappingOption ) ) { + if ( subclassValidator.isValidUsage( + sourceMethod.getExecutable(), + annotationMirror, + subclassMappingOption.getSource() ) ) { + subclassMappings.add( subclassMappingOption ); + } + } + } + } + private void addAllNonRedefined(Set inheritedMappings) { Set redefinedSources = new HashSet<>(); Set redefinedTargets = new HashSet<>(); @@ -328,7 +357,7 @@ private String getFirstTargetPropertyName(MappingOptions mapping) { /** * SubclassMappingOptions are not inherited to forged methods. They would result in an infinite loop if they were. * - * @return a MappingMethodOptions without SubclassMappingOptions. + * @return a MappingMethodOptions without SubclassMappingOptions or SubclassValidator. */ public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethodOptions options) { return new MappingMethodOptions( @@ -339,7 +368,8 @@ public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethod options.beanMapping, options.enumMappingOptions, options.valueMappings, - Collections.emptySet() ); + Collections.emptySet(), + null ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 5895ecba2a..92180bca8a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -16,15 +16,14 @@ import javax.lang.model.element.Modifier; import org.mapstruct.ap.internal.gem.ConditionGem; -import org.mapstruct.ap.internal.util.TypeUtils; - +import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.TypeUtils; import static org.mapstruct.ap.internal.model.source.MappingMethodUtils.isEnumMapping; import static org.mapstruct.ap.internal.util.Collections.first; @@ -98,6 +97,7 @@ public static class Builder { private Set subclassMappings; private boolean verboseLogging; + private SubclassValidator subclassValidator; public Builder setDeclaringMapper(Type declaringMapper) { this.declaringMapper = declaringMapper; @@ -159,6 +159,11 @@ public Builder setSubclassMappings(Set subclassMappings) return this; } + public Builder setSubclassValidator(SubclassValidator subclassValidator) { + this.subclassValidator = subclassValidator; + return this; + } + public Builder setTypeUtils(TypeUtils typeUtils) { this.typeUtils = typeUtils; return this; @@ -212,7 +217,8 @@ public SourceMethod build() { beanMapping, enumMappingOptions, valueMappings, - subclassMappings + subclassMappings, + subclassValidator ); this.typeParameters = this.executable.getTypeParameters() diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java index 54a0ba4565..08df8083bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model.source; +import java.util.ArrayList; import java.util.List; import java.util.Set; import javax.lang.model.element.ExecutableElement; @@ -31,11 +32,13 @@ public class SubclassMappingOptions extends DelegatingOptions { private final TypeMirror source; private final TypeMirror target; + private final TypeUtils typeUtils; - public SubclassMappingOptions(TypeMirror source, TypeMirror target, DelegatingOptions next) { + public SubclassMappingOptions(TypeMirror source, TypeMirror target, TypeUtils typeUtils, DelegatingOptions next) { super( next ); this.source = source; this.target = target; + this.typeUtils = typeUtils; } @Override @@ -84,7 +87,9 @@ private static boolean isConsistent(SubclassMappingGem gem, ExecutableElement me targetSubclass.toString() ); isConsistent = false; } - subclassValidator.isInCorrectOrder( method, gem.mirror(), targetSubclass ); + if ( !subclassValidator.isValidUsage( method, gem.mirror(), sourceSubclass ) ) { + isConsistent = false; + } return isConsistent; } @@ -115,10 +120,10 @@ public TypeMirror getTarget() { public static void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, TypeUtils typeUtils, Set mappings, - List sourceParameters, Type resultType) { - SubclassValidator subclassValidator = new SubclassValidator( messager, typeUtils ); + List sourceParameters, Type resultType, + SubclassValidator subclassValidator) { for ( SubclassMappingGem subclassMappingGem : gem.value().get() ) { - addAndValidateInstance( + addInstance( subclassMappingGem, method, beanMappingOptions, @@ -134,24 +139,8 @@ public static void addInstances(SubclassMappingsGem gem, ExecutableElement metho public static void addInstance(SubclassMappingGem subclassMapping, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, TypeUtils typeUtils, Set mappings, - List sourceParameters, Type resultType) { - addAndValidateInstance( - subclassMapping, - method, - beanMappingOptions, - messager, - typeUtils, - mappings, - sourceParameters, - resultType, - new SubclassValidator( messager, typeUtils ) ); - } - - private static void addAndValidateInstance(SubclassMappingGem subclassMapping, ExecutableElement method, - BeanMappingOptions beanMappingOptions, FormattingMessager messager, - TypeUtils typeUtils, Set mappings, - List sourceParameters, Type resultType, - SubclassValidator subclassValidator) { + List sourceParameters, Type resultType, + SubclassValidator subclassValidator) { if ( !isConsistent( subclassMapping, method, @@ -166,6 +155,41 @@ private static void addAndValidateInstance(SubclassMappingGem subclassMapping, E TypeMirror sourceSubclass = subclassMapping.source().getValue(); TypeMirror targetSubclass = subclassMapping.target().getValue(); - mappings.add( new SubclassMappingOptions( sourceSubclass, targetSubclass, beanMappingOptions ) ); + mappings + .add( + new SubclassMappingOptions( + sourceSubclass, + targetSubclass, + typeUtils, + beanMappingOptions ) ); + } + + public static List copyForInverseInheritance(Set subclassMappings, + BeanMappingOptions beanMappingOptions) { + // we are not interested in keeping it unique at this point. + List mappings = new ArrayList<>(); + for ( SubclassMappingOptions subclassMapping : subclassMappings ) { + mappings.add( + new SubclassMappingOptions( + subclassMapping.target, + subclassMapping.source, + subclassMapping.typeUtils, + beanMappingOptions ) ); + } + return mappings; + } + + @Override + public boolean equals(Object obj) { + if ( obj == null || !( obj instanceof SubclassMappingOptions ) ) { + return false; + } + SubclassMappingOptions other = (SubclassMappingOptions) obj; + return typeUtils.isSameType( source, other.source ); + } + + @Override + public int hashCode() { + return 1; // use a stable value because TypeMirror is not safe to use for hashCode. } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java index dd79ba0c02..601b588e42 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassValidator.java @@ -20,19 +20,28 @@ * * @author Ben Zegveld */ -class SubclassValidator { +public class SubclassValidator { private final FormattingMessager messager; private final List handledSubclasses = new ArrayList<>(); private final TypeUtils typeUtils; - SubclassValidator(FormattingMessager messager, TypeUtils typeUtils) { + public SubclassValidator(FormattingMessager messager, TypeUtils typeUtils) { this.messager = messager; this.typeUtils = typeUtils; } - public boolean isInCorrectOrder(Element e, AnnotationMirror annotation, TypeMirror sourceType) { + public boolean isValidUsage(Element e, AnnotationMirror annotation, TypeMirror sourceType) { for ( TypeMirror typeMirror : handledSubclasses ) { + if ( typeUtils.isSameType( sourceType, typeMirror ) ) { + messager + .printMessage( + e, + annotation, + Message.SUBCLASSMAPPING_DOUBLE_SOURCE_SUBCLASS, + sourceType ); + return false; + } if ( typeUtils.isAssignable( sourceType, typeMirror ) ) { messager .printMessage( @@ -43,11 +52,11 @@ public boolean isInCorrectOrder(Element e, AnnotationMirror annotation, TypeMirr typeMirror, sourceType, typeMirror ); - return true; + return false; } } handledSubclasses.add( sourceType ); - return false; + return true; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index bae0cda1ae..d8acb10398 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -320,7 +321,7 @@ private List getMappingMethods(MapperOptions mapperAnnotation, Li continue; } - mergeInheritedOptions( method, mapperAnnotation, methods, new ArrayList<>() ); + mergeInheritedOptions( method, mapperAnnotation, methods, new ArrayList<>(), null ); MappingMethodOptions mappingOptions = method.getOptions(); @@ -462,7 +463,8 @@ private M createWithElementMappingMethod(Sour } private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConfig, - List availableMethods, List initializingMethods) { + List availableMethods, List initializingMethods, + AnnotationMirror annotationMirror) { if ( initializingMethods.contains( method ) ) { // cycle detected @@ -497,10 +499,10 @@ private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConf // apply defined (@InheritConfiguration, @InheritInverseConfiguration) mappings if ( forwardTemplateMethod != null ) { - mappingOptions.applyInheritedOptions( forwardTemplateMethod, false ); + mappingOptions.applyInheritedOptions( method, forwardTemplateMethod, false, annotationMirror ); } if ( inverseTemplateMethod != null ) { - mappingOptions.applyInheritedOptions( inverseTemplateMethod, true ); + mappingOptions.applyInheritedOptions( method, inverseTemplateMethod, true, annotationMirror ); } // apply auto inherited options @@ -510,7 +512,8 @@ private void mergeInheritedOptions(SourceMethod method, MapperOptions mapperConf // but.. there should not be an @InheritedConfiguration if ( forwardTemplateMethod == null && inheritanceStrategy.isApplyForward() ) { if ( applicablePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( first( applicablePrototypeMethods ), false ); + mappingOptions.applyInheritedOptions( method, first( applicablePrototypeMethods ), false, + annotationMirror ); } else if ( applicablePrototypeMethods.size() > 1 ) { messager.printMessage( @@ -523,7 +526,8 @@ else if ( applicablePrototypeMethods.size() > 1 ) { // or no @InheritInverseConfiguration if ( inverseTemplateMethod == null && inheritanceStrategy.isApplyReverse() ) { if ( applicableReversePrototypeMethods.size() == 1 ) { - mappingOptions.applyInheritedOptions( first( applicableReversePrototypeMethods ), true ); + mappingOptions.applyInheritedOptions( method, first( applicableReversePrototypeMethods ), true, + annotationMirror ); } else if ( applicableReversePrototypeMethods.size() > 1 ) { messager.printMessage( @@ -607,16 +611,23 @@ else if ( nameFilteredcandidates.size() > 1 ) { } } - return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods ); + return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods, + getAnnotationMirror( inverseConfiguration ) ); + } + + private AnnotationMirror getAnnotationMirror(InheritInverseConfigurationGem inverseConfiguration) { + return inverseConfiguration == null ? null : inverseConfiguration.mirror(); } private SourceMethod extractInitializedOptions(SourceMethod resultMethod, List rawMethods, MapperOptions mapperConfig, - List initializingMethods) { + List initializingMethods, + AnnotationMirror annotationMirror) { if ( resultMethod != null ) { if ( !resultMethod.getOptions().isFullyInitialized() ) { - mergeInheritedOptions( resultMethod, mapperConfig, rawMethods, initializingMethods ); + mergeInheritedOptions( resultMethod, mapperConfig, rawMethods, initializingMethods, + annotationMirror ); } return resultMethod; @@ -684,7 +695,12 @@ else if ( nameFilteredcandidates.size() > 1 ) { } } - return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods ); + return extractInitializedOptions( resultMethod, rawMethods, mapperConfig, initializingMethods, + getAnnotationMirror( inheritConfiguration ) ); + } + + private AnnotationMirror getAnnotationMirror(InheritConfigurationGem inheritConfiguration) { + return inheritConfiguration == null ? null : inheritConfiguration.mirror(); } private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index a31fb41a7a..201f1a1f22 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -45,6 +45,7 @@ import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.SubclassMappingOptions; +import org.mapstruct.ap.internal.model.source.SubclassValidator; import org.mapstruct.ap.internal.model.source.ValueMappingOptions; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.AccessorNamingUtils; @@ -307,11 +308,13 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, // We want to get as much error reporting as possible. // If targetParameter is not null it means we have an update method + SubclassValidator subclassValidator = new SubclassValidator( messager, typeUtils ); Set subclassMappingOptions = getSubclassMappings( sourceParameters, targetParameter != null ? null : resultType, method, - beanMappingOptions + beanMappingOptions, + subclassValidator ); return new SourceMethod.Builder() @@ -327,6 +330,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, .setValueMappingOptionss( getValueMappings( method ) ) .setEnumMappingOptions( enumMappingOptions ) .setSubclassMappings( subclassMappingOptions ) + .setSubclassValidator( subclassValidator ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) .setPrototypeMethods( prototypeMethods ) @@ -601,8 +605,10 @@ private Set getMappings(ExecutableElement method, BeanMappingOpt * @return The subclass mappings for the given method */ private Set getSubclassMappings(List sourceParameters, Type resultType, - ExecutableElement method, BeanMappingOptions beanMapping) { - return new RepeatableSubclassMappings( sourceParameters, resultType ).getMappings( method, beanMapping ); + ExecutableElement method, BeanMappingOptions beanMapping, + SubclassValidator validator) { + return new RepeatableSubclassMappings( sourceParameters, resultType, validator ) + .getMappings( method, beanMapping ); } private class RepeatableMappings extends RepeatableMappingAnnotations { @@ -637,11 +643,13 @@ private class RepeatableSubclassMappings extends RepeatableMappingAnnotations { private final List sourceParameters; private final Type resultType; + private SubclassValidator validator; - RepeatableSubclassMappings(List sourceParameters, Type resultType) { + RepeatableSubclassMappings(List sourceParameters, Type resultType, SubclassValidator validator) { super( SUB_CLASS_MAPPING_FQN, SUB_CLASS_MAPPINGS_FQN ); this.sourceParameters = sourceParameters; this.resultType = resultType; + this.validator = validator; } @Override @@ -666,7 +674,8 @@ void addInstance(SubclassMappingGem gem, ExecutableElement method, BeanMappingOp typeUtils, mappings, sourceParameters, - resultType ); + resultType, + validator ); } @Override @@ -681,7 +690,8 @@ void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMapping typeUtils, mappings, sourceParameters, - resultType ); + resultType, + validator ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 8588ec183a..6d8fed1a95 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -117,6 +117,7 @@ public enum Message { ENUMMAPPING_NO_ELEMENTS( "'nameTransformationStrategy', 'configuration' and 'unexpectedValueMappingException' are undefined in @EnumMapping, define at least one of them." ), ENUMMAPPING_ILLEGAL_TRANSFORMATION( "Illegal transformation for '%s' EnumTransformationStrategy. Error: '%s'." ), + SUBCLASSMAPPING_DOUBLE_SOURCE_SUBCLASS( "Subclass '%s' is already defined as a source." ), SUBCLASSMAPPING_ILLEGAL_SUBCLASS( "Class '%s' is not a subclass of '%s'." ), SUBCLASSMAPPING_NO_VALID_SUPERCLASS( "Could not find a parameter that is a superclass for '%s'." ), SUBCLASSMAPPING_UPDATE_METHODS_NOT_SUPPORTED( "SubclassMapping annotation can not be used for update methods." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousInverseSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousInverseSubclassMapper.java new file mode 100644 index 0000000000..a6cbba2cbc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/ErroneousInverseSubclassMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousInverseSubclassMapper { + ErroneousInverseSubclassMapper INSTANCE = Mappers.getMapper( ErroneousInverseSubclassMapper.class ); + + @SubclassMapping( source = Bike.class, target = VehicleDto.class ) + @SubclassMapping( source = Car.class, target = VehicleDto.class ) + @Mapping( target = "maker", source = "vehicleManufacturingCompany" ) + VehicleDto map(Vehicle vehicle); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InverseOrderSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InverseOrderSubclassMapper.java new file mode 100644 index 0000000000..302c036488 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InverseOrderSubclassMapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBack; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface InverseOrderSubclassMapper { + InverseOrderSubclassMapper INSTANCE = Mappers.getMapper( InverseOrderSubclassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = HatchBack.class, target = CarDto.class ) + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @SubclassMapping( source = CarDto.class, target = Car.class ) + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java index eb71797864..6fedf2c57a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SimpleSubclassMapper.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.subclassmapping; +import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.SubclassMapping; @@ -28,4 +29,9 @@ public interface SimpleSubclassMapper { @SubclassMapping( source = Bike.class, target = BikeDto.class ) @Mapping( source = "vehicleManufacturingCompany", target = "maker") VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java index e5a77b56d3..7df555ecc2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -34,12 +34,11 @@ VehicleCollectionDto.class, Vehicle.class, VehicleDto.class, - SimpleSubclassMapper.class, - SubclassMapperUsingExistingMappings.class, }) public class SubclassMappingTest { @ProcessorTest + @WithClasses( SimpleSubclassMapper.class ) void mappingIsDoneUsingSubclassMapping() { VehicleCollection vehicles = new VehicleCollection(); vehicles.getVehicles().add( new Car() ); @@ -54,6 +53,22 @@ void mappingIsDoneUsingSubclassMapping() { } @ProcessorTest + @WithClasses( SimpleSubclassMapper.class ) + void inverseMappingIsDoneUsingSubclassMapping() { + VehicleCollectionDto vehicles = new VehicleCollectionDto(); + vehicles.getVehicles().add( new CarDto() ); + vehicles.getVehicles().add( new BikeDto() ); + + VehicleCollection result = SimpleSubclassMapper.INSTANCE.mapInverse( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( Car.class, Bike.class ); + } + + @ProcessorTest + @WithClasses( SubclassMapperUsingExistingMappings.class ) void existingMappingsAreUsedWhenFound() { VehicleCollection vehicles = new VehicleCollection(); vehicles.getVehicles().add( new Car() ); @@ -66,19 +81,38 @@ void existingMappingsAreUsedWhenFound() { } @ProcessorTest - void subclassMappingInheritsMapping() { - VehicleCollection vehicles = new VehicleCollection(); - Car car = new Car(); - car.setVehicleManufacturingCompany( "BenZ" ); - vehicles.getVehicles().add( car ); + @WithClasses( SimpleSubclassMapper.class ) + void subclassMappingInheritsInverseMapping() { + VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); + CarDto carDto = new CarDto(); + carDto.setMaker( "BenZ" ); + vehiclesDto.getVehicles().add( carDto ); - VehicleCollectionDto result = SimpleSubclassMapper.INSTANCE.map( vehicles ); + VehicleCollection result = SimpleSubclassMapper.INSTANCE.mapInverse( vehiclesDto ); assertThat( result.getVehicles() ) - .extracting( VehicleDto::getMaker ) + .extracting( Vehicle::getVehicleManufacturingCompany ) .containsExactly( "BenZ" ); } + @ProcessorTest + @WithClasses( { + HatchBack.class, + InverseOrderSubclassMapper.class + } ) + void subclassMappingOverridesInverseInheritsMapping() { + VehicleCollectionDto vehicleDtos = new VehicleCollectionDto(); + CarDto carDto = new CarDto(); + carDto.setMaker( "BenZ" ); + vehicleDtos.getVehicles().add( carDto ); + + VehicleCollection result = InverseOrderSubclassMapper.INSTANCE.mapInverse( vehicleDtos ); + + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( Car.class ); + } + @ProcessorTest @WithClasses({ HatchBack.class, @@ -91,11 +125,11 @@ void subclassMappingInheritsMapping() { line = 28, alternativeLine = 30, message = "SubclassMapping annotation for " - + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto' found after " - + "'org.mapstruct.ap.test.subclassmapping.mappables.CarDto', but all " - + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBackDto' " + + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBack' found after " + + "'org.mapstruct.ap.test.subclassmapping.mappables.Car', but all " + + "'org.mapstruct.ap.test.subclassmapping.mappables.HatchBack' " + "objects are also instances of " - + "'org.mapstruct.ap.test.subclassmapping.mappables.CarDto'.") + + "'org.mapstruct.ap.test.subclassmapping.mappables.Car'.") }) void subclassOrderWarning() { } @@ -136,4 +170,18 @@ void unsupportedUpdateMethod() { }) void erroneousMethodWithSourceTargetType() { } + + @ProcessorTest + @WithClasses({ ErroneousInverseSubclassMapper.class }) + @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diagnostics = { + @Diagnostic(type = ErroneousInverseSubclassMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 28, + message = "Subclass " + + "'org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto'" + + " is already defined as a source." + ) + }) + void inverseSubclassMappingNotPossible() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOverride.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOverride.java new file mode 100644 index 0000000000..97b9079e87 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceOverride.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubSourceOverride extends ImplementedParentSource implements InterfaceParentSource { + private final String finalValue; + + public SubSourceOverride(String finalValue) { + this.finalValue = finalValue; + } + + public String getFinalValue() { + return finalValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceSeparate.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceSeparate.java new file mode 100644 index 0000000000..ccae04efff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubSourceSeparate.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubSourceSeparate extends ImplementedParentSource implements InterfaceParentSource { + private final String separateValue; + + public SubSourceSeparate(String separateValue) { + this.separateValue = separateValue; + } + + public String getSeparateValue() { + return separateValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetSeparate.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetSeparate.java new file mode 100644 index 0000000000..6b98c24106 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubTargetSeparate.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.fixture; + +public class SubTargetSeparate extends ImplementedParentTarget implements InterfaceParentTarget { + private final String separateValue; + + public SubTargetSeparate(String separateValue) { + this.separateValue = separateValue; + } + + public String getSeparateValue() { + return separateValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java index 8ef7908c30..c50afb9e57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.subclassmapping.fixture; import org.mapstruct.BeanMapping; +import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.Mapper; import org.mapstruct.SubclassMapping; @@ -18,4 +19,9 @@ public interface SubclassAbstractMapper { @SubclassMapping( source = SubSource.class, target = SubTarget.class ) @SubclassMapping( source = SubSourceOther.class, target = SubTargetOther.class ) AbstractParentTarget map(AbstractParentSource item); + + @SubclassMapping( source = SubTargetSeparate.class, target = SubSourceSeparate.class ) + @InheritInverseConfiguration + @SubclassMapping( source = SubTargetOther.class, target = SubSourceOverride.class ) + AbstractParentSource map(AbstractParentTarget item); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java index 14dc16d4ab..9bc72942e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/SubclassFixtureTest.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.subclassmapping.fixture; import org.junit.jupiter.api.extension.RegisterExtension; + import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.GeneratedSource; @@ -37,6 +38,9 @@ void subclassInterfaceParentFixture() { @ProcessorTest @WithClasses( { + SubSourceOverride.class, + SubSourceSeparate.class, + SubTargetSeparate.class, SubclassAbstractMapper.class, } ) void subclassAbstractParentFixture() { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java index 6deed338c1..a66b646f1e 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java @@ -9,7 +9,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2021-09-12T14:37:10+0200", + date = "2022-01-31T19:35:15+0100", comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 11.0.12 (Azul Systems, Inc.)" ) public class SubclassAbstractMapperImpl implements SubclassAbstractMapper { @@ -31,6 +31,26 @@ else if (item instanceof SubSourceOther) { } } + @Override + public AbstractParentSource map(AbstractParentTarget item) { + if ( item == null ) { + return null; + } + + if (item instanceof SubTargetSeparate) { + return subTargetSeparateToSubSourceSeparate( (SubTargetSeparate) item ); + } + else if (item instanceof SubTargetOther) { + return subTargetOtherToSubSourceOverride( (SubTargetOther) item ); + } + else if (item instanceof SubTarget) { + return subTargetToSubSource( (SubTarget) item ); + } + else { + throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + item.getClass()); + } + } + protected SubTarget subSourceToSubTarget(SubSource subSource) { if ( subSource == null ) { return null; @@ -56,4 +76,44 @@ protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSource return subTargetOther; } + + protected SubSourceSeparate subTargetSeparateToSubSourceSeparate(SubTargetSeparate subTargetSeparate) { + if ( subTargetSeparate == null ) { + return null; + } + + String separateValue = null; + + separateValue = subTargetSeparate.getSeparateValue(); + + SubSourceSeparate subSourceSeparate = new SubSourceSeparate( separateValue ); + + return subSourceSeparate; + } + + protected SubSourceOverride subTargetOtherToSubSourceOverride(SubTargetOther subTargetOther) { + if ( subTargetOther == null ) { + return null; + } + + String finalValue = null; + + finalValue = subTargetOther.getFinalValue(); + + SubSourceOverride subSourceOverride = new SubSourceOverride( finalValue ); + + return subSourceOverride; + } + + protected SubSource subTargetToSubSource(SubTarget subTarget) { + if ( subTarget == null ) { + return null; + } + + SubSource subSource = new SubSource(); + + subSource.setValue( subTarget.getValue() ); + + return subSource; + } } From 9b434f80f8572e3f2cf03ce2a5bc932ff3f2eeae Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 6 Feb 2022 20:05:42 +0100 Subject: [PATCH 0650/1006] #2715: Updated documentation to reflect impact of conditions on update mappers. (#2740) * #2715: added an example with an update mapper for Conditional behavior. --- ...apter-10-advanced-mapping-options.asciidoc | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 0bbec1fe57..1cc19fcc3e 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -354,6 +354,56 @@ public class CarMapperImpl implements CarMapper { ---- ==== +When using this in combination with an update mapping method it will replace the `null-check` there, for example: + +.Update mapper using custom condition check method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarDto carToCarDto(Car car, @MappingTarget CarDto carDto); + + @Condition + default boolean isNotEmpty(String value) { + return value != null && !value.isEmpty(); + } +} +---- +==== + +The generated update mapper will look like: + +.Custom condition check in generated implementation +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car, CarDto carDto) { + if ( car == null ) { + return carDto; + } + + if ( isNotEmpty( car.getOwner() ) ) { + carDto.setOwner( car.getOwner() ); + } else { + carDto.setOwner( null ); + } + + // Mapping of other properties + + return carDto; + } +} +---- +==== + [IMPORTANT] ==== If there is a custom `@Condition` method applicable for the property it will have a precedence over a presence check method in the bean itself. From 0b2c7e58b264adb5674de51634509d70a4578da2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 23 Feb 2022 15:55:20 +0100 Subject: [PATCH 0651/1006] Add Christian Kosmowski to the copyright.txt --- copyright.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/copyright.txt b/copyright.txt index 01b6526c70..8008a66bb9 100644 --- a/copyright.txt +++ b/copyright.txt @@ -8,6 +8,7 @@ Andrei Arlou - https://github.com/Captain1653 Andres Jose Sebastian Rincon Gonzalez - https://github.com/stianrincon Arne Seime - https://github.com/seime Christian Bandowski - https://github.com/chris922 +Christian Kosmowski - https://github.com/ckosmowski Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman From b6a3aa151228c17183979da0fd1573bebd1e9ed3 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 12 Mar 2022 18:01:15 +0100 Subject: [PATCH 0652/1006] #2758: fallback to param.variableName if ext.targetBeanName is not present in MethodReference handling. (#2759) --- .../ap/internal/model/MethodReference.ftl | 2 +- .../basic/ConditionalMappingTest.java | 17 ++++++++++- ...MethodWithMappingTargetInUpdateMapper.java | 29 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithMappingTargetInUpdateMapper.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 271ba58f9b..d8236140f5 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -41,7 +41,7 @@ <#-- a class is passed on for casting, see @TargetType --> <@includeModel object=inferTypeWhenEnum( ext.targetType ) raw=true/>.class<#t> <#elseif param.mappingTarget> - ${ext.targetBeanName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> + <#if ext.targetBeanName??>${ext.targetBeanName}<#else>${param.variableName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> <#elseif param.mappingContext> ${param.variableName}<#t> <#elseif param.sourceRHS??> diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java index 0fc791fb13..62fd79ae84 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java @@ -7,8 +7,8 @@ import java.util.Arrays; import java.util.Collections; - import org.junit.jupiter.api.extension.RegisterExtension; + import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -223,4 +223,19 @@ public void optionalLikeConditional() { } + @ProcessorTest + @WithClasses( { + ConditionalMethodWithMappingTargetInUpdateMapper.class + } ) + @IssueKey( "2758" ) + public void conditionalMethodWithMappingTarget() { + ConditionalMethodWithMappingTargetInUpdateMapper mapper = + ConditionalMethodWithMappingTargetInUpdateMapper.INSTANCE; + + BasicEmployee targetEmployee = new BasicEmployee(); + targetEmployee.setName( "CurrentName" ); + mapper.map( new BasicEmployeeDto( "ReplacementName" ), targetEmployee ); + + assertThat( targetEmployee.getName() ).isEqualTo( "CurrentName" ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithMappingTargetInUpdateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithMappingTargetInUpdateMapper.java new file mode 100644 index 0000000000..12f4a00212 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithMappingTargetInUpdateMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper( nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE ) +public interface ConditionalMethodWithMappingTargetInUpdateMapper { + + ConditionalMethodWithMappingTargetInUpdateMapper INSTANCE = + Mappers.getMapper( ConditionalMethodWithMappingTargetInUpdateMapper.class ); + + void map(BasicEmployeeDto employee, @MappingTarget BasicEmployee targetEmployee); + + @Condition + default boolean isNotBlankAndNotPresent(String value, @MappingTarget BasicEmployee targetEmployee) { + return value != null && !value.trim().isEmpty() && targetEmployee.getName() == null; + } +} From 0a69492983a34a5a41dd6968fa0c2f18f97484e8 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 12 Mar 2022 18:02:01 +0100 Subject: [PATCH 0653/1006] #2755: use raw Type when calling a static method. (#2762) --- .../ap/internal/model/MethodReference.ftl | 2 +- .../selection/generics/GenericMapperBase.java | 48 +++++++++++++++++++ .../generics/GenericMapperBaseTest.java | 25 ++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBase.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBaseTest.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index d8236140f5..6ccdf26871 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -15,7 +15,7 @@ <#if static><@includeModel object=providingParameter.type/><#else>${providingParameter.name}.<@methodCall/> <#-- method is referenced java8 static method in the mapper to implement (interface) --> <#elseif static> - <@includeModel object=definingType/>.<@methodCall/> + <@includeModel object=definingType raw=true/>.<@methodCall/> <#elseif constructor> new <@includeModel object=definingType/><#if (parameterBindings?size > 0)>( <@arguments/> )<#else>() <#elseif methodChaining> diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBase.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBase.java new file mode 100644 index 0000000000..025acba4ae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBase.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.generics; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +public interface GenericMapperBase { + + T toDto(Map prop); + + @Named( "StringArrayToString" ) + static String stringArrayToString(Property property) { + return "converted"; + } +} + +class Property { + +} + +class ProjectDto { + private String productionSite; + + public void setProductionSite(String productionSite) { + this.productionSite = productionSite; + } + + public String getProductionSite() { + return productionSite; + } +} + +@Mapper +interface ProjectMapper extends GenericMapperBase { + ProjectMapper INSTANCE = Mappers.getMapper( ProjectMapper.class ); + + @Mapping( target = "productionSite", source = "productionSite", qualifiedByName = "StringArrayToString" ) + @Override + ProjectDto toDto(Map projectProp); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBaseTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBaseTest.java new file mode 100644 index 0000000000..1fe4930e2e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/generics/GenericMapperBaseTest.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.generics; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@WithClasses( { + GenericMapperBase.class +} ) +@IssueKey( "2755" ) +class GenericMapperBaseTest { + + @ProcessorTest + void generatesCompilableCode() { + } + +} From ad00adfa8659d22fca4fd725434e6d5971418692 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 12 Mar 2022 23:57:17 +0100 Subject: [PATCH 0654/1006] #2538 Allow using 2 step mappings with only one of the 2 methods being qualified --- .../source/selector/SelectionCriteria.java | 10 ++++- .../creation/MappingResolverImpl.java | 41 ++++++++++++++++-- .../mapstruct/ap/test/bugs/_2538/Group.java | 22 ++++++++++ .../ap/test/bugs/_2538/GroupDto.java | 22 ++++++++++ .../ap/test/bugs/_2538/Issue2538Test.java | 39 +++++++++++++++++ .../ap/test/bugs/_2538/TeamMapper.java | 42 +++++++++++++++++++ .../ap/test/bugs/_2538/TeamRole.java | 22 ++++++++++ .../ap/test/bugs/_2538/TeamRoleDto.java | 22 ++++++++++ 8 files changed, 215 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Group.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/GroupDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Issue2538Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRole.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRoleDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index b70e94b6d1..da8bae365a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model.source.selector; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.lang.model.type.TypeMirror; @@ -26,6 +27,7 @@ public class SelectionCriteria { private final String targetPropertyName; private final TypeMirror qualifyingResultType; private final SourceRHS sourceRHS; + private boolean ignoreQualifiers = false; private Type type; private final boolean allowDirect; private final boolean allowConversion; @@ -87,12 +89,16 @@ public boolean isPresenceCheckRequired() { return type == Type.PRESENCE_CHECK; } + public void setIgnoreQualifiers(boolean ignoreQualifiers) { + this.ignoreQualifiers = ignoreQualifiers; + } + public List getQualifiers() { - return qualifiers; + return ignoreQualifiers ? Collections.emptyList() : qualifiers; } public List getQualifiedByNames() { - return qualifiedByNames; + return ignoreQualifiers ? Collections.emptyList() : qualifiedByNames; } public String getTargetPropertyName() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index b971341fc9..2e2a760bf4 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -712,6 +712,11 @@ public int hashCode() { } } + private enum BestMatchType { + IGNORE_QUALIFIERS_BEFORE_Y_CANDIDATES, + IGNORE_QUALIFIERS_AFTER_Y_CANDIDATES, + } + /** * Suppose mapping required from A to C and: *
      @@ -743,6 +748,17 @@ static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targe if ( mmAttempt.hasResult ) { return mmAttempt.result; } + if ( att.hasQualfiers() ) { + mmAttempt = mmAttempt.getBestMatchIgnoringQualifiersBeforeY( sourceType, targetType ); + if ( mmAttempt.hasResult ) { + return mmAttempt.result; + } + + mmAttempt = mmAttempt.getBestMatchIgnoringQualifiersAfterY( sourceType, targetType ); + if ( mmAttempt.hasResult ) { + return mmAttempt.result; + } + } MethodMethod mbAttempt = new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef ) .getBestMatch( sourceType, targetType ); @@ -772,6 +788,18 @@ static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targe } private MethodMethod getBestMatch(Type sourceType, Type targetType) { + return getBestMatch( sourceType, targetType, null ); + } + + private MethodMethod getBestMatchIgnoringQualifiersBeforeY(Type sourceType, Type targetType) { + return getBestMatch( sourceType, targetType, BestMatchType.IGNORE_QUALIFIERS_BEFORE_Y_CANDIDATES ); + } + + private MethodMethod getBestMatchIgnoringQualifiersAfterY(Type sourceType, Type targetType) { + return getBestMatch( sourceType, targetType, BestMatchType.IGNORE_QUALIFIERS_AFTER_Y_CANDIDATES ); + } + + private MethodMethod getBestMatch(Type sourceType, Type targetType, BestMatchType matchType) { Set yCandidates = new HashSet<>(); Map, List>> xCandidates = new LinkedHashMap<>(); @@ -784,6 +812,9 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType) { // sourceMethod or builtIn that fits the signature B to C. Only then there is a match. If we have a match // a nested method call can be called. so C = methodY( methodX (A) ) attempt.selectionCriteria.setPreferUpdateMapping( false ); + attempt.selectionCriteria.setIgnoreQualifiers( + matchType == BestMatchType.IGNORE_QUALIFIERS_BEFORE_Y_CANDIDATES ); + for ( T2 yCandidate : yMethods ) { Type ySourceType = yCandidate.getMappingSourceType(); ySourceType = ySourceType.resolveParameterToType( targetType, yCandidate.getResultType() ).getMatch(); @@ -796,13 +827,16 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType) { } List> xMatches = attempt.getBestMatch( xMethods, sourceType, ySourceType ); if ( !xMatches.isEmpty() ) { - xMatches.stream().forEach( x -> xCandidates.put( x, new ArrayList<>() ) ); - final Type typeInTheMiddle = ySourceType; - xMatches.stream().forEach( x -> typesInTheMiddle.put( x, typeInTheMiddle ) ); + for ( SelectedMethod x : xMatches ) { + xCandidates.put( x, new ArrayList<>() ); + typesInTheMiddle.put( x, ySourceType ); + } yCandidates.add( yCandidate ); } } attempt.selectionCriteria.setPreferUpdateMapping( true ); + attempt.selectionCriteria.setIgnoreQualifiers( + matchType == BestMatchType.IGNORE_QUALIFIERS_AFTER_Y_CANDIDATES ); // collect all results List yCandidatesList = new ArrayList<>( yCandidates ); @@ -816,6 +850,7 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType) { } } + attempt.selectionCriteria.setIgnoreQualifiers( false ); // no results left if ( xCandidates.isEmpty() ) { return this; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Group.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Group.java new file mode 100644 index 0000000000..4451431fee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Group.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +/** + * @author Filip Hrisafov + */ +public class Group { + + private final String id; + + public Group(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/GroupDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/GroupDto.java new file mode 100644 index 0000000000..0d94c90815 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/GroupDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +/** + * @author Filip Hrisafov + */ +public class GroupDto { + + private final String id; + + public GroupDto(String id) { + this.id = id; + } + + public String getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Issue2538Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Issue2538Test.java new file mode 100644 index 0000000000..cf99e67f92 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/Issue2538Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Group.class, + GroupDto.class, + TeamMapper.class, + TeamRole.class, + TeamRoleDto.class, +}) +class Issue2538Test { + + @ProcessorTest + void shouldCorrectlyUseQualifiedMethodIn2StepMapping() { + TeamRole role = TeamMapper.INSTANCE.mapUsingFirstLookup( new TeamRoleDto( "test" ) ); + + assertThat( role ).isNotNull(); + assertThat( role.getGroup() ).isNotNull(); + assertThat( role.getGroup().getId() ).isEqualTo( "lookup-test" ); + + role = TeamMapper.INSTANCE.mapUsingSecondLookup( new TeamRoleDto( "test" ) ); + + assertThat( role ).isNotNull(); + assertThat( role.getGroup() ).isNotNull(); + assertThat( role.getGroup().getId() ).isEqualTo( "second-test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamMapper.java new file mode 100644 index 0000000000..5615e7bc43 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamMapper.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface TeamMapper { + + TeamMapper INSTANCE = Mappers.getMapper( TeamMapper.class ); + + // This method is testing methodX(methodY(...)) where methodY is qualified + @Mapping(target = "group", source = "groupId", qualifiedByName = "firstLookup") + TeamRole mapUsingFirstLookup(TeamRoleDto in); + + // This method is testing methodX(methodY(...)) where methodX is qualified + @Mapping(target = "group", source = "groupId", qualifiedByName = "secondLookup") + TeamRole mapUsingSecondLookup(TeamRoleDto in); + + Group map(GroupDto in); + + @Named("firstLookup") + default GroupDto lookupGroup(String groupId) { + return groupId != null ? new GroupDto( "lookup-" + groupId ) : null; + } + + default GroupDto normalLookup(String groupId) { + return groupId != null ? new GroupDto( groupId ) : null; + } + + @Named("secondLookup") + default Group mapSecondLookup(GroupDto in) { + return in != null ? new Group( "second-" + in.getId() ) : null; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRole.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRole.java new file mode 100644 index 0000000000..f73700fa4d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRole.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +/** + * @author Filip Hrisafov + */ +public class TeamRole { + + private final Group group; + + public TeamRole(Group group) { + this.group = group; + } + + public Group getGroup() { + return group; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRoleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRoleDto.java new file mode 100644 index 0000000000..fac5a1a9ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2538/TeamRoleDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2538; + +/** + * @author Filip Hrisafov + */ +public class TeamRoleDto { + + private final String groupId; + + public TeamRoleDto(String groupId) { + this.groupId = groupId; + } + + public String getGroupId() { + return groupId; + } +} From ab528678318cb0983f50767b8170ab4697ba4e75 Mon Sep 17 00:00:00 2001 From: Chris DeLashmutt Date: Sat, 19 Mar 2022 06:51:19 -0400 Subject: [PATCH 0655/1006] #2748 Support mapping map keys with invalid chars for methods --- .../mapstruct/ap/internal/util/Strings.java | 14 +++++- .../ap/internal/util/StringsTest.java | 3 ++ .../ap/test/bugs/_2748/Issue2748Mapper.java | 48 +++++++++++++++++++ .../ap/test/bugs/_2748/Issue2748Test.java | 36 ++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java index 42727ed816..88e0bdf6f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Strings.java @@ -183,7 +183,19 @@ public static String sanitizeIdentifierName(String identifier) { if ( firstAlphabeticIndex < identifier.length()) { // If it is not consisted of only underscores - return identifier.substring( firstAlphabeticIndex ).replace( "[]", "Array" ); + String firstAlphaString = identifier.substring( firstAlphabeticIndex ).replace( "[]", "Array" ); + + StringBuilder sb = new StringBuilder( firstAlphaString.length() ); + for ( int i = 0; i < firstAlphaString.length(); i++ ) { + int codePoint = firstAlphaString.codePointAt( i ); + if ( Character.isJavaIdentifierPart( codePoint ) || codePoint == '.') { + sb.appendCodePoint( codePoint ); + } + else { + sb.append( '_' ); + } + } + return sb.toString(); } return identifier.replace( "[]", "Array" ); diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java index 687b63f793..524fd193aa 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/StringsTest.java @@ -72,6 +72,7 @@ public void testGetSaveVariableNameWithArrayExistingVariables() { assertThat( Strings.getSafeVariableName( "__Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "_0Test" ) ).isEqualTo( "test" ); assertThat( Strings.getSafeVariableName( "_0123Test" ) ).isEqualTo( "test" ); + assertThat( Strings.getSafeVariableName( "bad/test" ) ).isEqualTo( "bad_test" ); } @Test @@ -94,6 +95,7 @@ public void testGetSaveVariableNameWithCollection() { assertThat( Strings.getSafeVariableName( "__0Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); assertThat( Strings.getSafeVariableName( "___0", new ArrayList<>() ) ).isEqualTo( "___0" ); assertThat( Strings.getSafeVariableName( "__0123456789Test", Arrays.asList( "test" ) ) ).isEqualTo( "test1" ); + assertThat( Strings.getSafeVariableName( "bad/test", Arrays.asList( "bad_test" ) ) ).isEqualTo( "bad_test1" ); } @Test @@ -110,6 +112,7 @@ public void testSanitizeIdentifierName() { assertThat( Strings.sanitizeIdentifierName( "_0int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "__0int[]" ) ).isEqualTo( "intArray" ); assertThat( Strings.sanitizeIdentifierName( "___0" ) ).isEqualTo( "___0" ); + assertThat( Strings.sanitizeIdentifierName( "bad/test" ) ).isEqualTo( "bad_test" ); } @Test diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Mapper.java new file mode 100644 index 0000000000..0062667df4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Mapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2748; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2748Mapper { + + Issue2748Mapper INSTANCE = Mappers.getMapper( Issue2748Mapper.class ); + + @Mapping(target = "specificValue", source = "annotations.specific/value") + Target map(Source source); + + class Target { + private final String specificValue; + + public Target(String specificValue) { + this.specificValue = specificValue; + } + + public String getSpecificValue() { + return specificValue; + } + } + + class Source { + private final Map annotations; + + public Source(Map annotations) { + this.annotations = annotations; + } + + public Map getAnnotations() { + return annotations; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Test.java new file mode 100644 index 0000000000..4bda2cd43d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2748/Issue2748Test.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2748; + +import java.util.Collections; +import java.util.Map; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2748") +@WithClasses( { + Issue2748Mapper.class +} ) +class Issue2748Test { + + @ProcessorTest + void shouldMapNonJavaIdentifier() { + Map annotations = Collections.singletonMap( "specific/value", "value" ); + Issue2748Mapper.Source source = new Issue2748Mapper.Source( annotations ); + + Issue2748Mapper.Target target = Issue2748Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getSpecificValue() ).isEqualTo( "value" ); + } +} From 190b486b7919a64e5fe4f80e6dc551554b0d6455 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 19 Mar 2022 12:09:30 +0100 Subject: [PATCH 0656/1006] Add users that have contributed post 1.5.0.Beta2 to copyright.txt --- copyright.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/copyright.txt b/copyright.txt index 8008a66bb9..1b23a0e84a 100644 --- a/copyright.txt +++ b/copyright.txt @@ -8,6 +8,7 @@ Andrei Arlou - https://github.com/Captain1653 Andres Jose Sebastian Rincon Gonzalez - https://github.com/stianrincon Arne Seime - https://github.com/seime Christian Bandowski - https://github.com/chris922 +Chris DeLashmutt - https://github.com/cdelashmutt-pivotal Christian Kosmowski - https://github.com/ckosmowski Christian Schuster - https://github.com/chschu Christophe Labouisse - https://github.com/ggtools @@ -35,6 +36,7 @@ João Paulo Bassinello - https://github.com/jpbassinello Jonathan Kraska - https://github.com/jakraska Joshua Spoerri - https://github.com/spoerri Jude Niroshan - https://github.com/JudeNiroshan +Justyna Kubica-Ledzion - https://github.com/JKLedzion Kemal Özcan - https://github.com/yekeoe Kevin Grüneberg - https://github.com/kevcodez Lukas Lazar - https://github.com/LukeLaz @@ -63,4 +65,5 @@ Tobias Meggendorfer - https://github.com/incaseoftrouble Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld +Valentin Kulesh - https://github.com/unshare Vincent Alexander Beelte - https://github.com/grandmasterpixel From 7e00af6ff451b15d125242af91df2864a0a58aea Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 21 Mar 2022 08:14:08 +0100 Subject: [PATCH 0657/1006] [maven-release-plugin] prepare release 1.5.0.RC1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index aaae7b5404..6c34822f96 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 293043e6f9..2a412327da 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 10c95cf3b5..4d16fc611f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 337ad35e51..4769c58d25 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8850da641c..a46ea17a53 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4b48c19496..a1ec01d3a6 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 4ca3d9b2c0..958d4bcafb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.RC1 diff --git a/pom.xml b/pom.xml index 28c35aea74..b89fd7d12e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.RC1 diff --git a/processor/pom.xml b/processor/pom.xml index ec3f20a241..369e8066d2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.RC1 ../parent/pom.xml From 08a0313840307e96d17246509cbea99c4b048dec Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 21 Mar 2022 08:14:09 +0100 Subject: [PATCH 0658/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 6c34822f96..aaae7b5404 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 2a412327da..293043e6f9 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 4d16fc611f..10c95cf3b5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4769c58d25..337ad35e51 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index a46ea17a53..8850da641c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a1ec01d3a6..4b48c19496 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 958d4bcafb..4ca3d9b2c0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.RC1 + HEAD diff --git a/pom.xml b/pom.xml index b89fd7d12e..28c35aea74 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.RC1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 369e8066d2..ec3f20a241 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.RC1 + 1.5.0-SNAPSHOT ../parent/pom.xml From 07eeea6bc9563e6964e9e573795d1ccb5ad34c87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 31 Mar 2022 18:41:52 +0000 Subject: [PATCH 0659/1006] Bump spring-beans from 5.3.15 to 5.3.18 in /parent Bumps [spring-beans](https://github.com/spring-projects/spring-framework) from 5.3.15 to 5.3.18. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v5.3.15...v5.3.18) --- updated-dependencies: - dependency-name: org.springframework:spring-beans dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 4ca3d9b2c0..1a9fddff92 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -25,7 +25,7 @@ 3.0.0-M3 3.0.0-M5 3.1.0 - 5.3.15 + 5.3.18 1.6.0 8.36.1 5.8.0-M1 From 2473c3eaaa812490b23dc32287b90bd36d539ecf Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 2 Apr 2022 11:59:25 +0200 Subject: [PATCH 0660/1006] #2797: Add the nested type import types in the NestedPropertyMappingMethod * #2797: Reproduction scenario * Add the nested type import types in the NestedPropertyMappingMethod Co-authored-by: Ben Zegveld Co-authored-by: Filip Hrisafov --- .../model/NestedPropertyMappingMethod.java | 2 +- .../ap/test/bugs/_2797/ExampleDto.java | 31 +++++++++++++ .../ap/test/bugs/_2797/ExampleMapper.java | 23 ++++++++++ .../ap/test/bugs/_2797/Issue2797Test.java | 24 ++++++++++ .../ap/test/bugs/_2797/model/BasePerson.java | 44 +++++++++++++++++++ .../ap/test/bugs/_2797/model/Example.java | 16 +++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/Issue2797Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/BasePerson.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/Example.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 96004cb474..da73e1783f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -103,7 +103,7 @@ public List getPropertyEntries() { public Set getImportTypes() { Set types = super.getImportTypes(); for ( SafePropertyEntry propertyEntry : safePropertyEntries) { - types.add( propertyEntry.getType() ); + types.addAll( propertyEntry.getType().getImportTypes() ); if ( propertyEntry.getPresenceChecker() != null ) { types.addAll( propertyEntry.getPresenceChecker().getImportTypes() ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleDto.java new file mode 100644 index 0000000000..eff9f26271 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleDto.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2797; + +/** + * @author Ben Zegveld + */ +public class ExampleDto { + + private String personFirstName; + private String personLastName; + + public String getPersonFirstName() { + return personFirstName; + } + + public String getPersonLastName() { + return personLastName; + } + + public void setPersonFirstName(String personFirstName) { + this.personFirstName = personFirstName; + } + + public void setPersonLastName(String personLastName) { + this.personLastName = personLastName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleMapper.java new file mode 100644 index 0000000000..eccac27256 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/ExampleMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2797; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.bugs._2797.model.Example.Person; + +import static org.mapstruct.ReportingPolicy.ERROR; + +/** + * @author Ben Zegveld + */ +@Mapper(unmappedTargetPolicy = ERROR) +public interface ExampleMapper { + + @Mapping(target = "personFirstName", source = "names.first") + @Mapping(target = "personLastName", source = "names.last") + ExampleDto map(Person person); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/Issue2797Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/Issue2797Test.java new file mode 100644 index 0000000000..7f3dd5f3de --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/Issue2797Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2797; + +import org.mapstruct.ap.test.bugs._2797.model.BasePerson; +import org.mapstruct.ap.test.bugs._2797.model.Example; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@IssueKey( "2797" ) +@WithClasses( { ExampleDto.class, ExampleMapper.class, Example.class, BasePerson.class } ) +public class Issue2797Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/BasePerson.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/BasePerson.java new file mode 100644 index 0000000000..6b54e6ee31 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/BasePerson.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2797.model; + +/** + * @author Ben Zegveld + */ +public class BasePerson { + + private Names names; + + public Names getNames() { + return names; + } + + public void setNames(Names names) { + this.names = names; + } + + public static class Names { + + private String first; + private String last; + + public String getFirst() { + return first; + } + + public String getLast() { + return last; + } + + public void setFirst(String first) { + this.first = first; + } + + public void setLast(String last) { + this.last = last; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/Example.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/Example.java new file mode 100644 index 0000000000..4dfa40f695 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2797/model/Example.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2797.model; + +/** + * @author Ben Zegveld + */ +public class Example { + + public static class Person extends BasePerson { + + } +} From 03d44b5a872f796b79336429d8cde2ee7918910a Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 2 Apr 2022 18:55:06 +0200 Subject: [PATCH 0661/1006] #2795: use 'includeModel' for the 'sourcePresenceCheckerReference' in the 'UpdateWrapper'. (#2796) * #2795: use 'includeModel' for the 'sourcePresenceCheckerReference' in the 'UpdateWrapper'. * Simplify the tests Co-authored-by: Ben Zegveld Co-authored-by: Filip Hrisafov --- .../model/assignment/UpdateWrapper.ftl | 2 +- .../ap/test/bugs/_2795/Issue2795Mapper.java | 30 +++++++++++++++++++ .../ap/test/bugs/_2795/Issue2795Test.java | 25 ++++++++++++++++ .../mapstruct/ap/test/bugs/_2795/Nested.java | 20 +++++++++++++ .../ap/test/bugs/_2795/NestedDto.java | 20 +++++++++++++ .../mapstruct/ap/test/bugs/_2795/Source.java | 22 ++++++++++++++ .../mapstruct/ap/test/bugs/_2795/Target.java | 20 +++++++++++++ 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Nested.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/NestedDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Target.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 58416fc63b..9cdd07c230 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -10,7 +10,7 @@ <@lib.handleExceptions> <#if includeSourceNullCheck> <@lib.sourceLocalVarAssignment/> - if ( <#if sourcePresenceCheckerReference?? >${sourcePresenceCheckerReference}<#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { + if ( <#if sourcePresenceCheckerReference?? ><@includeModel object=sourcePresenceCheckerReference /><#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { <@assignToExistingTarget/> <@lib.handleAssignment/>; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Mapper.java new file mode 100644 index 0000000000..41f29da920 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Mapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +import java.util.Optional; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; + +@Mapper +public interface Issue2795Mapper { + + void update(Source update, @MappingTarget Target destination); + + void update(NestedDto update, @MappingTarget Nested destination); + + static T unwrap(Optional optional) { + return optional.orElse( null ); + } + + @Condition + static boolean isNotEmpty(Optional field) { + return field != null && field.isPresent(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Test.java new file mode 100644 index 0000000000..4b7b599527 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Issue2795Test.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +@IssueKey("2795") +@WithClasses({ + Issue2795Mapper.class, + Nested.class, + NestedDto.class, + Target.class, + Source.class, +}) +public class Issue2795Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Nested.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Nested.java new file mode 100644 index 0000000000..5214c7d076 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Nested.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +public class Nested { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/NestedDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/NestedDto.java new file mode 100644 index 0000000000..1b27453435 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/NestedDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +public class NestedDto { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Source.java new file mode 100644 index 0000000000..927e2b09f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +import java.util.Optional; + +public class Source { + + private Optional nested = Optional.empty(); + + public Optional getNested() { + return nested; + } + + public void setNested(Optional nested) { + this.nested = nested; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Target.java new file mode 100644 index 0000000000..ed69a6d48f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2795/Target.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2795; + +public class Target { + + private Nested nested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + +} From 66046177300c9c89bbec6e841a61208e6d08140a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 2 Apr 2022 14:51:26 +0200 Subject: [PATCH 0662/1006] #2794 Compile error when condition expression used with constant or expression --- .../ap/internal/model/source/MappingOptions.java | 6 ++++++ .../org/mapstruct/ap/internal/util/Message.java | 2 ++ .../expression/ConditionalExpressionTest.java | 13 +++++++++++++ .../ErroneousConditionExpressionMapper.java | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index cb496a3a31..e788b51f6e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -222,9 +222,15 @@ else if ( gem.constant().hasValue() && gem.defaultValue().hasValue() ) { else if ( gem.expression().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } + else if ( gem.expression().hasValue() && gem.conditionExpression().hasValue() ) { + message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONDITION_EXPRESSION_BOTH_DEFINED; + } else if ( gem.constant().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } + else if ( gem.constant().hasValue() && gem.conditionExpression().hasValue() ) { + message = Message.PROPERTYMAPPING_CONSTANT_AND_CONDITION_EXPRESSION_BOTH_DEFINED; + } else if ( gem.defaultValue().hasValue() && gem.defaultExpression().hasValue() ) { message = Message.PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 6d8fed1a95..4e1c0302fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -59,7 +59,9 @@ public enum Message { PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_VALUE_BOTH_DEFINED( "Expression and default value are both defined in @Mapping, either define a defaultValue or an expression." ), PROPERTYMAPPING_CONSTANT_AND_DEFAULT_VALUE_BOTH_DEFINED( "Constant and default value are both defined in @Mapping, either define a defaultValue or a constant." ), PROPERTYMAPPING_EXPRESSION_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Expression and default expression are both defined in @Mapping, either define an expression or a default expression." ), + PROPERTYMAPPING_EXPRESSION_AND_CONDITION_EXPRESSION_BOTH_DEFINED( "Expression and condition expression are both defined in @Mapping, either define an expression or a condition expression." ), PROPERTYMAPPING_CONSTANT_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Constant and default expression are both defined in @Mapping, either define a constant or a default expression." ), + PROPERTYMAPPING_CONSTANT_AND_CONDITION_EXPRESSION_BOTH_DEFINED( "Constant and condition expression are both defined in @Mapping, either define a constant or a condition expression." ), PROPERTYMAPPING_DEFAULT_VALUE_AND_DEFAULT_EXPRESSION_BOTH_DEFINED( "Default value and default expression are both defined in @Mapping, either define a default value or a default expression." ), PROPERTYMAPPING_DEFAULT_VALUE_AND_NVPMS( "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultValue or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_EXPRESSION_VALUE_AND_NVPMS( "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define an expression or an nullValuePropertyMappingStrategy." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java index 42219cfb6a..1ad36f7de1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ConditionalExpressionTest.java @@ -111,6 +111,7 @@ public void conditionalExpressionForSourceToTarget() { } + @IssueKey("2794") @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -119,6 +120,18 @@ public void conditionalExpressionForSourceToTarget() { kind = javax.tools.Diagnostic.Kind.ERROR, line = 19, message = "Value for condition expression must be given in the form \"java()\"." + ), + @Diagnostic(type = ErroneousConditionExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 22, + message = "Constant and condition expression are both defined in @Mapping," + + " either define a constant or a condition expression." + ), + @Diagnostic(type = ErroneousConditionExpressionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 25, + message = "Expression and condition expression are both defined in @Mapping," + + " either define an expression or a condition expression." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java index c74c552531..c8e5db243e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/expression/ErroneousConditionExpressionMapper.java @@ -18,4 +18,10 @@ public interface ErroneousConditionExpressionMapper { @Mapping(target = "name", conditionExpression = "!employee.getName().isEmpty()") BasicEmployee map(EmployeeDto employee); + + @Mapping(target = "name", conditionExpression = "java(true)", constant = "test") + BasicEmployee mapConstant(EmployeeDto employee); + + @Mapping(target = "name", conditionExpression = "java(true)", expression = "java(\"test\")") + BasicEmployee mapExpression(EmployeeDto employee); } From 437a70d6dfa238f3d0262d1bf90d88003152fbbf Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Fri, 8 Apr 2022 20:57:40 +0200 Subject: [PATCH 0663/1006] #2807: Include LifeCycleMethod importTypes in the list of importTypes. (#2808) Co-authored-by: Ben Zegveld --- .../ap/internal/model/MappingMethod.java | 21 +++++++++++---- .../ap/test/bugs/_2807/Issue2807Test.java | 27 +++++++++++++++++++ .../bugs/_2807/SpringLifeCycleMapper.java | 26 ++++++++++++++++++ .../ap/test/bugs/_2807/after/AfterMethod.java | 23 ++++++++++++++++ .../test/bugs/_2807/before/BeforeMethod.java | 21 +++++++++++++++ .../beforewithtarget/BeforeWithTarget.java | 23 ++++++++++++++++ 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index c7d329916f..5b9eda644b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -5,11 +5,9 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName; -import static org.mapstruct.ap.internal.util.Strings.join; - import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -21,6 +19,9 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; +import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName; +import static org.mapstruct.ap.internal.util.Strings.join; + /** * A method implemented or referenced by a {@link Mapper} class. * @@ -70,7 +71,7 @@ protected MappingMethod(Method method, List parameters, Collection parameters) { @@ -153,6 +154,16 @@ public Set getImportTypes() { types.addAll( type.getImportTypes() ); } + for ( LifecycleCallbackMethodReference reference : beforeMappingReferencesWithMappingTarget ) { + types.addAll( reference.getImportTypes() ); + } + for ( LifecycleCallbackMethodReference reference : beforeMappingReferencesWithoutMappingTarget ) { + types.addAll( reference.getImportTypes() ); + } + for ( LifecycleCallbackMethodReference reference : afterMappingReferences ) { + types.addAll( reference.getImportTypes() ); + } + return types; } @@ -178,7 +189,7 @@ public String toString() { private List filterMappingTarget(List methods, boolean mustHaveMappingTargetParameter) { if ( methods == null ) { - return null; + return Collections.emptyList(); } List result = diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java new file mode 100644 index 0000000000..2cb96ce37e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2807; + +import org.mapstruct.ap.test.bugs._2807.after.AfterMethod; +import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod; +import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; + +/** + * @author Ben Zegveld + */ +@IssueKey( "2807" ) +public class Issue2807Test { + + @ProcessorTest + @WithSpring + @WithClasses( { SpringLifeCycleMapper.class, BeforeMethod.class, BeforeWithTarget.class, AfterMethod.class } ) + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java new file mode 100644 index 0000000000..daabe7f52a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2807; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.bugs._2807.after.AfterMethod; +import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod; +import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper( componentModel = "spring", uses = { BeforeMethod.class, AfterMethod.class, + BeforeWithTarget.class }, unmappedTargetPolicy = ReportingPolicy.IGNORE ) +public interface SpringLifeCycleMapper { + SpringLifeCycleMapper INSTANCE = Mappers.getMapper( SpringLifeCycleMapper.class ); + + List map(List list); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java new file mode 100644 index 0000000000..f7c7457348 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2807.after; + +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.MappingTarget; + +/** + * @author Ben Zegveld + */ +public class AfterMethod { + private AfterMethod() { + } + + @AfterMapping + public static void doNothing(@MappingTarget List source) { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java new file mode 100644 index 0000000000..5252bee150 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2807.before; + +import org.mapstruct.BeforeMapping; + +/** + * @author Ben Zegveld + */ +public class BeforeMethod { + private BeforeMethod() { + } + + @BeforeMapping + public static void doNothing(Iterable source) { + return; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java new file mode 100644 index 0000000000..69e62bdea1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2807.beforewithtarget; + +import java.util.List; + +import org.mapstruct.BeforeMapping; +import org.mapstruct.MappingTarget; + +/** + * @author Ben Zegveld + */ +public class BeforeWithTarget { + private BeforeWithTarget() { + } + + @BeforeMapping + public static void doNothingBeforeWithTarget(Iterable source, @MappingTarget List target) { + } +} From a4162809a400f297e3c8c51e03f1cd6f8fe8a90d Mon Sep 17 00:00:00 2001 From: Hao Zhang <452227361@qq.com> Date: Sat, 28 May 2022 17:37:21 +0800 Subject: [PATCH 0664/1006] Doc: correct the annotation processor version (#2859) The lombok-mapstruct-binding anotation procossor version given by document will result a compile problem, correct it by the example repository so that work fine --- .../chapter-14-third-party-api-integration.asciidoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc index c31424a0de..69bef46ea6 100644 --- a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc +++ b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc @@ -58,7 +58,7 @@ This resolves the compilation issues of Lombok and MapStruct modules. org.projectlombok lombok-mapstruct-binding - 0.1.0 + 0.2.0 ---- ==== @@ -121,7 +121,7 @@ The set up using Maven or Gradle does not differ from what is described in < org.projectlombok lombok-mapstruct-binding - 0.1.0 + 0.2.0 @@ -141,7 +141,7 @@ dependencies { implementation "org.mapstruct:mapstruct:${mapstructVersion}" implementation "org.projectlombok:lombok:1.18.16" - annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.1.0" + annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" annotationProcessor "org.projectlombok:lombok:1.18.16" } From 9769f51756e1e3d3173a1b9026635757909b90ad Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 30 May 2022 21:09:21 +0200 Subject: [PATCH 0665/1006] #2851 Fix typo in readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 645f3ee992..c7f237ad06 100644 --- a/readme.md +++ b/readme.md @@ -34,7 +34,7 @@ Compared to mapping frameworks working at runtime, MapStruct offers the followin * mappings are incorrect (cannot find a proper mapping method or type conversion) * **Easily debuggable mapping code** (or editable by hand—e.g. in case of a bug in the generator) -To create a mapping between two types, declare a mapper class like this: +To create a mapping between two types, declare a mapper interface like this: ```java @Mapper From c945ccd628a46cda862532f38acce5b2b070c3f8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 30 May 2022 21:20:09 +0200 Subject: [PATCH 0666/1006] #2835 Upgrade jacoco-maven-plugin to latest 0.8.8 to support Java 17 --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 1a9fddff92..4b5ea78486 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -545,7 +545,7 @@ org.jacoco jacoco-maven-plugin - 0.8.6 + 0.8.8 org.jvnet.jaxb2.maven2 From 0559c47c2174254a3a8fa8ec828ec9dd14d393c0 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Mon, 30 May 2022 21:51:57 +0200 Subject: [PATCH 0667/1006] #2739 Enhance documentation around SPI usage --- .../chapter-13-using-mapstruct-spi.asciidoc | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index 51fec968bf..1095d41656 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -1,7 +1,18 @@ [[using-spi]] == Using the MapStruct SPI + +To use a custom SPI implementation, it must be located in a separate JAR file together with a file named after the SPI (e.g. `org.mapstruct.ap.spi.AccessorNamingStrategy`) in `META-INF/services/` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). + + +[NOTE] +==== +It might also be necessary to add the jar to your IDE's annotation processor factory path. Otherwise you might get an error stating that it cannot be found, while a run using your build tool does succeed. +==== + === Custom Accessor Naming Strategy +SPI name: `org.mapstruct.ap.spi.AccessorNamingStrategy` + MapStruct offers the possibility to override the `AccessorNamingStrategy` via the Service Provider Interface (SPI). A nice example is the use of the fluent API on the source object `GolfPlayer` and `GolfPlayerDto` below. .Source object GolfPlayer with fluent API. @@ -121,14 +132,14 @@ public class CustomAccessorNamingStrategy extends DefaultAccessorNamingStrategy ==== The `CustomAccessorNamingStrategy` makes use of the `DefaultAccessorNamingStrategy` (also available in mapstruct-processor) and relies on that class to leave most of the default behaviour unchanged. -To use a custom SPI implementation, it must be located in a separate JAR file together with the file `META-INF/services/org.mapstruct.ap.spi.AccessorNamingStrategy` with the fully qualified name of your custom implementation as content (e.g. `org.mapstruct.example.CustomAccessorNamingStrategy`). This JAR file needs to be added to the annotation processor classpath (i.e. add it next to the place where you added the mapstruct-processor jar). - [TIP] Fore more details: The example above is present in our examples repository (https://github.com/mapstruct/mapstruct-examples). -[mapping-exclusion-provider] +[[mapping-exclusion-provider]] === Mapping Exclusion Provider +SPI name: `org.mapstruct.ap.spi.MappingExclusionProvider` + MapStruct offers the possibility to override the `MappingExclusionProvider` via the Service Provider Interface (SPI). A nice example is to not allow MapStruct to create an automatic sub-mapping for a certain type, i.e. MapStruct will not try to generate an automatic sub-mapping method for an excluded type. @@ -177,16 +188,12 @@ include::{processor-ap-test}/nestedbeans/exclusions/custom/CustomMappingExclusio ---- ==== -To use a custom SPI implementation, it must be located in a separate JAR file -together with the file `META-INF/services/org.mapstruct.ap.spi.MappingExclusionProvider` with the fully qualified name of your custom implementation as content -(e.g. `org.mapstruct.example.CustomMappingExclusionProvider`). -This JAR file needs to be added to the annotation processor classpath -(i.e. add it next to the place where you added the mapstruct-processor jar). - [[custom-builder-provider]] === Custom Builder Provider +SPI name: org.mapstruct.ap.spi.BuilderProvider + MapStruct offers the possibility to override the `DefaultProvider` via the Service Provider Interface (SPI). A nice example is to provide support for a custom builder strategy. @@ -202,6 +209,8 @@ include::{processor-ap-main}/spi/NoOpBuilderProvider.java[tag=documentation] [[custom-enum-naming-strategy]] === Custom Enum Naming Strategy +SPI name: `org.mapstruct.ap.spi.EnumMappingStrategy` + MapStruct offers the possibility to override the `EnumMappingStrategy` via the Service Provider Interface (SPI). This can be used when you have certain enums that follow some conventions within your organization. For example all enums which implement an interface named `CustomEnumMarker` are prefixed with `CUSTOM_` @@ -349,6 +358,8 @@ public class CheeseTypeMapperImpl implements CheeseTypeMapper { [[custom-enum-transformation-strategy]] === Custom Enum Transformation Strategy +SPI name: `org.mapstruct.ap.spi.EnumTransformationStrategy` + MapStruct offers the possibility to other transformations strategies by implementing `EnumTransformationStrategy` via the Service Provider Interface (SPI). A nice example is to provide support for a custom transformation strategy. From a1a0786cf2c25651eae795f3c2649e75b4b641f9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 2 Jun 2022 22:14:42 +0200 Subject: [PATCH 0668/1006] #2846 Add test case showing that everything works as expected --- .../string/StringConversionTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java index 994b47957b..37d3c77b04 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/string/StringConversionTest.java @@ -69,6 +69,33 @@ public void shouldApplyStringConversions() { assertThat( target.getSb() ).isEqualTo( "SB" ); } + @IssueKey("2846") + @ProcessorTest + public void shouldNotApplyStringConversionsWhenNull() { + Source source = new Source(); + + Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( "0" ); + assertThat( target.getBb() ).isNull(); + assertThat( target.getS() ).isEqualTo( "0" ); + assertThat( target.getSs() ).isNull(); + assertThat( target.getI() ).isEqualTo( "0" ); + assertThat( target.getIi() ).isNull(); + assertThat( target.getL() ).isEqualTo( "0" ); + assertThat( target.getLl() ).isNull(); + assertThat( target.getF() ).isEqualTo( "0.0" ); + assertThat( target.getFf() ).isNull(); + assertThat( target.getD() ).isEqualTo( "0.0" ); + assertThat( target.getDd() ).isNull(); + assertThat( target.getBool() ).isEqualTo( "false" ); + assertThat( target.getBoolBool() ).isNull(); + assertThat( target.getC() ).isEqualTo( String.valueOf( '\u0000' ) ); + assertThat( target.getCc() ).isNull(); + assertThat( target.getSb() ).isNull(); + } + @ProcessorTest public void shouldApplyReverseStringConversions() { Target target = new Target(); From efa11ba312bf601179289369b219c97ed9307f07 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 2 Jun 2022 23:11:41 +0200 Subject: [PATCH 0669/1006] [maven-release-plugin] prepare release 1.5.0.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index aaae7b5404..8cc783f39a 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 293043e6f9..903558558f 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 10c95cf3b5..bf4e4387ae 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 337ad35e51..404001b0c3 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 8850da641c..7ca09c75f4 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4b48c19496..e103296690 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 4b5ea78486..da625ee0dc 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Final diff --git a/pom.xml b/pom.xml index 28c35aea74..811dda0bfb 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.0.Final diff --git a/processor/pom.xml b/processor/pom.xml index ec3f20a241..6feeff0796 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0-SNAPSHOT + 1.5.0.Final ../parent/pom.xml From 5efe5e291c0433cafa53bd76cb5f170529f5a60a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 2 Jun 2022 23:11:41 +0200 Subject: [PATCH 0670/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 8cc783f39a..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 903558558f..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index bf4e4387ae..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 404001b0c3..9ceeb505ea 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 7ca09c75f4..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index e103296690..364faae643 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index da625ee0dc..8c6a55ebed 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Final + HEAD diff --git a/pom.xml b/pom.xml index 811dda0bfb..25a5ead6bc 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.0.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 6feeff0796..6f2bb6495c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.0.Final + 1.6.0-SNAPSHOT ../parent/pom.xml From 07265630241fa87cb2ec443219c134aac56457c5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 2 Jun 2022 23:30:17 +0200 Subject: [PATCH 0671/1006] Update readme with latest released 1.5.0.Final release --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index c7f237ad06..c56eefb771 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.4.2.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.4.2.Final + 1.5.0.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - compile 'org.mapstruct:mapstruct:1.4.2.Final' + compile 'org.mapstruct:mapstruct:1.5.0.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.4.2.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Final' // if you are using mapstruct in test code } ... ``` From 46b78bfe59c0473d3b92c08c73bbb782e03491bd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Jun 2022 21:52:59 +0200 Subject: [PATCH 0672/1006] #2867 Fix NPE when reporting message on parent mappers --- .../MapperAnnotatedFormattingMessenger.java | 11 +++++- .../test/bugs/_2867/Issue2867BaseMapper.java | 17 ++++++++ .../ap/test/bugs/_2867/Issue2867Mapper.java | 31 +++++++++++++++ .../ap/test/bugs/_2867/Issue2867Test.java | 39 +++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867BaseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java index eeb84570b0..d3384f0b4c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperAnnotatedFormattingMessenger.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.processor; +import java.util.Objects; import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; @@ -12,6 +13,7 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -97,7 +99,7 @@ private String constructMethod(Element e) { if ( e instanceof ExecutableElement ) { ExecutableElement ee = (ExecutableElement) e; StringBuilder method = new StringBuilder(); - method.append( typeUtils.asElement( ee.getReturnType() ).getSimpleName() ); + method.append( typeMirrorToString( ee.getReturnType() ) ); method.append( " " ); method.append( ee.getSimpleName() ); method.append( "(" ); @@ -112,7 +114,12 @@ private String constructMethod(Element e) { } private String parameterToString(VariableElement element) { - return typeUtils.asElement( element.asType() ).getSimpleName() + " " + element.getSimpleName(); + return typeMirrorToString( element.asType() ) + " " + element.getSimpleName(); + } + + private String typeMirrorToString(TypeMirror type) { + Element element = typeUtils.asElement( type ); + return element != null ? element.getSimpleName().toString() : Objects.toString( type ); } private Message determineDelegationMessage(Element e, Message msg) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867BaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867BaseMapper.java new file mode 100644 index 0000000000..8ebe1aa98d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867BaseMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2867; + +import org.mapstruct.MappingTarget; + +/** + * @author Filip Hrisafov + */ +public interface Issue2867BaseMapper { + + void update(@MappingTarget T target, S source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Mapper.java new file mode 100644 index 0000000000..77dfda0fc9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Mapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2867; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2867Mapper extends Issue2867BaseMapper { + + class Target { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class Source { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Test.java new file mode 100644 index 0000000000..5f0e7ad763 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2867/Issue2867Test.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2867; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue2867BaseMapper.class, + Issue2867Mapper.class, +}) +@IssueKey("2867") +class Issue2867Test { + + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = @Diagnostic( + type = Issue2867Mapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 14, + message = "Unmapped target property: \"name\"." + + " Occured at 'void update(T target, S source)' in 'Issue2867BaseMapper'." + ) + ) + @ProcessorTest + void shouldCompile() { + + } +} From ec9288ce6693abc1d14687d315f10e7e7697dd5e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 08:42:55 +0200 Subject: [PATCH 0673/1006] [maven-release-plugin] prepare release 1.5.1.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..58ab41d726 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..8ef899caaf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..527ace445d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 9ceeb505ea..73a358a613 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..d55ec5dae5 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 364faae643..4881caebfd 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8c6a55ebed..48bb5c8cba 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.1.Final diff --git a/pom.xml b/pom.xml index 25a5ead6bc..7a90e263b9 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.1.Final diff --git a/processor/pom.xml b/processor/pom.xml index 6f2bb6495c..61fde05422 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.1.Final ../parent/pom.xml From 20e97714d4e2d357c96a5065b22223f2152a6978 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 08:42:56 +0200 Subject: [PATCH 0674/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 58ab41d726..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 8ef899caaf..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 527ace445d..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 73a358a613..9ceeb505ea 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index d55ec5dae5..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4881caebfd..364faae643 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 48bb5c8cba..8c6a55ebed 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.1.Final + HEAD diff --git a/pom.xml b/pom.xml index 7a90e263b9..25a5ead6bc 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.1.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 61fde05422..6f2bb6495c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.1.Final + 1.6.0-SNAPSHOT ../parent/pom.xml From 4c9aa00369efbea00bc05b5631b5deea29baaced Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 08:53:10 +0200 Subject: [PATCH 0675/1006] Update readme with latest released 1.5.1.Final release --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index c56eefb771..e9ccc8d890 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.0.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.5.0.Final + 1.5.1.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - compile 'org.mapstruct:mapstruct:1.5.0.Final' + compile 'org.mapstruct:mapstruct:1.5.1.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.0.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.1.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.1.Final' // if you are using mapstruct in test code } ... ``` From 9247c5d7fbc5302061be1e5cc5cca8a747320b14 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 12:15:26 +0200 Subject: [PATCH 0676/1006] #2870 Use codecov action v2 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6d80d2da89..387b004642 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,7 +39,7 @@ jobs: - name: 'Generate coverage report' run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v2 - name: 'Publish Snapshots' if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy From d7c0d15fe1ef3382471de8027f728f30fd456809 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 15:58:19 +0200 Subject: [PATCH 0677/1006] Change required Java version for running MapStruct in the readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e9ccc8d890..0d6a93c781 100644 --- a/readme.md +++ b/readme.md @@ -130,7 +130,7 @@ To learn more about MapStruct, refer to the [project homepage](http://mapstruct. ## Building from Source -MapStruct uses Maven for its build. Java 8 is required for building MapStruct from source. To build the complete project, run +MapStruct uses Maven for its build. Java 11 is required for building MapStruct from source. To build the complete project, run mvn clean install From 05ae9922ea2bd6a6db5aac9358e8016adb5e82bb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 17:24:49 +0200 Subject: [PATCH 0678/1006] Update GitHub actions Run tests with Java 18 Change actions/checkout to v3 Change actions/setup-java to v3 --- .github/workflows/java-ea.yml | 7 ++++--- .github/workflows/main.yml | 30 ++++++++++++++++++------------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index 76e24db3b1..3cc488ca7e 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -10,15 +10,16 @@ jobs: strategy: fail-fast: false matrix: - java: [18-ea, 19-ea] + java: [19-ea] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 'Set up JDK' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: ${{ matrix.java }} - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 387b004642..40999c680a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,15 +12,16 @@ jobs: strategy: fail-fast: false matrix: - java: [13, 16, 17] + java: [13, 17, 18] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 'Set up JDK' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: ${{ matrix.java }} - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true @@ -29,10 +30,11 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install @@ -48,16 +50,18 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: 'Set up JDK 11 for building everything' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: 'Install Processor' run: ./mvnw ${MAVEN_ARGS} -DskipTests install -pl processor -am - name: 'Set up JDK 8 for running integration tests' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 8 - name: 'Run integration tests' run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest @@ -65,10 +69,11 @@ jobs: name: 'Windows' runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: 'Test' run: ./mvnw %MAVEN_ARGS% install @@ -76,10 +81,11 @@ jobs: name: 'Mac OS' runs-on: macos-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: 'Set up JDK 11' - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install From 22ad9f636d9f786bc18febf1fb623a17145c33a5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 14 Jun 2022 22:03:32 +0200 Subject: [PATCH 0679/1006] #2806 Try to stabilise some date conversion tests by locking them on reading the default timezone --- .../mapstruct/ap/test/conversion/date/DateConversionTest.java | 2 ++ .../java/org/mapstruct/ap/test/naming/VariableNamingTest.java | 2 ++ .../nestedmethodcall/NestedMappingMethodInvocationTest.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 83464f81a0..9ccf8e7e1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -17,6 +17,7 @@ import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; import org.junitpioneer.jupiter.DefaultLocale; +import org.junitpioneer.jupiter.ReadsDefaultTimeZone; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -35,6 +36,7 @@ }) @IssueKey("43") @DefaultLocale("de") +@ReadsDefaultTimeZone public class DateConversionTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java index 4b5c7982ea..a8e833ee06 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/naming/VariableNamingTest.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +import org.junitpioneer.jupiter.ReadsDefaultTimeZone; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -26,6 +27,7 @@ */ @WithClasses({ SourceTargetMapper.class, While.class, Break.class, Source.class }) @IssueKey("53") +@ReadsDefaultTimeZone public class VariableNamingTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java index 8d600d8604..03c47f7a49 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedmethodcall/NestedMappingMethodInvocationTest.java @@ -17,6 +17,7 @@ import javax.xml.namespace.QName; import org.junitpioneer.jupiter.DefaultLocale; +import org.junitpioneer.jupiter.ReadsDefaultTimeZone; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -31,6 +32,7 @@ */ @IssueKey("134") @DefaultLocale("de") +@ReadsDefaultTimeZone public class NestedMappingMethodInvocationTest { public static final QName QNAME = new QName( "dont-care" ); From fa800926e7cbf6d1ed5b219ae79309036d2c0879 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 5 Jun 2022 18:16:00 +0200 Subject: [PATCH 0680/1006] #2837 Add support for text blocks in expressions --- .../itest/tests/MavenIntegrationTest.java | 7 +++ .../expressionTextBlocksTest/pom.xml | 22 ++++++++++ .../org/mapstruct/itest/textBlocks/Car.java | 22 ++++++++++ .../itest/textBlocks/CarAndWheelMapper.java | 41 +++++++++++++++++ .../mapstruct/itest/textBlocks/CarDto.java | 15 +++++++ .../itest/textBlocks/WheelPosition.java | 22 ++++++++++ .../itest/textBlocks/TextBlocksTest.java | 27 ++++++++++++ .../internal/model/source/MappingOptions.java | 2 +- .../java/JavaDefaultExpressionTest.java | 20 +++++++++ .../MultiLineDefaultExpressionMapper.java | 44 +++++++++++++++++++ .../expressions/java/JavaExpressionTest.java | 25 +++++++++++ .../java/MultiLineExpressionMapper.java | 37 ++++++++++++++++ 12 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/pom.xml create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/Car.java create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarAndWheelMapper.java create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarDto.java create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/WheelPosition.java create mode 100644 integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/MultiLineDefaultExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 4f4182d5c7..7d63ccf774 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -122,6 +122,13 @@ void recordsTest() { void recordsCrossModuleTest() { } + @ProcessorTest(baseDir = "expressionTextBlocksTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + @EnabledForJreRange(min = JRE.JAVA_17) + void expressionTextBlocksTest() { + } + @ProcessorTest(baseDir = "kotlinDataTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }, forkJvm = true) diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/pom.xml b/integrationtest/src/test/resources/expressionTextBlocksTest/pom.xml new file mode 100644 index 0000000000..b70c48f9d0 --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + expressionTextBlocksTest + jar + + diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/Car.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/Car.java new file mode 100644 index 0000000000..28d4fd3cd5 --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/Car.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.textBlocks; + +/** + * @author Filip Hrisafov + */ +public class Car { + + private WheelPosition wheelPosition; + + public WheelPosition getWheelPosition() { + return wheelPosition; + } + + public void setWheelPosition(WheelPosition wheelPosition) { + this.wheelPosition = wheelPosition; + } +} diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarAndWheelMapper.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarAndWheelMapper.java new file mode 100644 index 0000000000..23d665c6ff --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarAndWheelMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.textBlocks; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface CarAndWheelMapper { + + CarAndWheelMapper INSTANCE = Mappers.getMapper( CarAndWheelMapper.class ); + + @Mapping(target = "wheelPosition", + expression = + """ + java( + source.getWheelPosition() == null ? + null : + source.getWheelPosition().getPosition() + ) + """) + CarDto carDtoFromCar(Car source); + + @Mapping(target = "wheelPosition", + expression = """ + java( + source.wheelPosition() == null ? + null : + new WheelPosition(source.wheelPosition()) + ) + """) + Car carFromCarDto(CarDto source); +} diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarDto.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarDto.java new file mode 100644 index 0000000000..f4baa4d044 --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/CarDto.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.textBlocks; + +import java.util.List; + +/** + * @author Filip Hrisafov + */ +public record CarDto(String wheelPosition) { + +} diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/WheelPosition.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/WheelPosition.java new file mode 100644 index 0000000000..6effd485a3 --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/main/java/org/mapstruct/itest/textBlocks/WheelPosition.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.textBlocks; + +/** + * @author Filip Hrisafov + */ +public class WheelPosition { + + private final String position; + + public WheelPosition(String position) { + this.position = position; + } + + public String getPosition() { + return position; + } +} diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java new file mode 100644 index 0000000000..42ed70b18e --- /dev/null +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.textBlocks; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class TextBlocksTest { + + @Test + public void textBlockExpressionShouldWork() { + Car car = new Car(); + car.setWheelPosition( new WheelPosition( "left" ) ); + + CarDto carDto = CarAndWheelMapper.INSTANCE.carDtoFromCar(car); + + assertThat( carDto ).isNotNull(); + assertThat( carDto.wheelPosition() ) + .isEqualTo( "left" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index e788b51f6e..5046ce8b29 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -37,7 +37,7 @@ */ public class MappingOptions extends DelegatingOptions { - private static final Pattern JAVA_EXPRESSION = Pattern.compile( "^java\\((.*)\\)$" ); + private static final Pattern JAVA_EXPRESSION = Pattern.compile( "^\\s*java\\((.*)\\)\\s*$", Pattern.DOTALL ); private final String sourceName; private final String constant; diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java index 3df90421b3..8f3a745e84 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/JavaDefaultExpressionTest.java @@ -5,6 +5,9 @@ */ package org.mapstruct.ap.test.source.defaultExpressions.java; +import java.time.LocalDate; +import java.time.Month; +import java.time.ZoneOffset; import java.util.Date; import org.mapstruct.ap.testutil.ProcessorTest; @@ -46,6 +49,23 @@ public void testJavaDefaultExpressionWithNoValues() { assertThat( target.getSourceDate() ).isEqualTo( new Date( 30L ) ); } + @ProcessorTest + @WithClasses({ Source.class, Target.class, MultiLineDefaultExpressionMapper.class }) + public void testMultiLineJavaDefaultExpression() { + Source source = new Source(); + + Target target = MultiLineDefaultExpressionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getSourceId() ).isEqualTo( "test" ); + assertThat( target.getSourceDate() ) + .isEqualTo( Date.from( + LocalDate.of( 2022, Month.JUNE, 5 ) + .atTime( 17, 10 ) + .toInstant( ZoneOffset.UTC ) + ) ); + } + @ProcessorTest @ExpectedCompilationOutcome( value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/MultiLineDefaultExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/MultiLineDefaultExpressionMapper.java new file mode 100644 index 0000000000..ba27726377 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/defaultExpressions/java/MultiLineDefaultExpressionMapper.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.defaultExpressions.java; + +import java.time.LocalDate; +import java.time.Month; +import java.time.ZoneOffset; +import java.util.Date; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(imports = { Date.class, LocalDate.class, ZoneOffset.class, Month.class }) +public interface MultiLineDefaultExpressionMapper { + + MultiLineDefaultExpressionMapper INSTANCE = Mappers.getMapper( MultiLineDefaultExpressionMapper.class ); + + @Mappings({ + @Mapping( + target = "sourceId", + source = "id", + defaultExpression = "java( new StringBuilder()\n.append( \"test\" )\n.toString() )" + ), + @Mapping( + target = "sourceDate", + source = "date", + defaultExpression = "java(" + + "Date.from(\n" + + "LocalDate.of( 2022, Month.JUNE, 5 )\n" + + ".atTime( 17, 10 )\n" + + ".toInstant( ZoneOffset.UTC )\n)" + + ")" + ) + }) + Target sourceToTarget(Source s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java index be80644606..9a20ddcdbd 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/JavaExpressionTest.java @@ -132,6 +132,31 @@ public void testGetterOnly() throws ParseException { assertThat( target.getList() ).isEqualTo( Arrays.asList( "test2" ) ); } + @ProcessorTest + @WithClasses({ Source.class, Target.class, TimeAndFormat.class, MultiLineExpressionMapper.class }) + public void testMultiLineJavaExpressionInsertion() throws ParseException { + Source source = new Source(); + String format = "dd-MM-yyyy,hh:mm:ss"; + Date time = getTime( format, "09-01-2014,01:35:03" ); + + source.setFormat( format ); + source.setTime( time ); + + Target target = MultiLineExpressionMapper.INSTANCE.mapUsingMultiLineExpression( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getTimeAndFormat().getTime() ).isEqualTo( time ); + assertThat( target.getTimeAndFormat().getFormat() ).isEqualTo( format ); + assertThat( target.getAnotherProp() ).isNull(); + + target = MultiLineExpressionMapper.INSTANCE.mapUsingMultiLineExpressionWithLeadingSpaces( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getTimeAndFormat().getTime() ).isEqualTo( time ); + assertThat( target.getTimeAndFormat().getFormat() ).isEqualTo( format ); + assertThat( target.getAnotherProp() ).isNull(); + } + @IssueKey( "1851" ) @ProcessorTest @WithClasses({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java new file mode 100644 index 0000000000..50d0b4b2cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.source.expressions.java; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.source.expressions.java.mapper.TimeAndFormat; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(imports = TimeAndFormat.class) +public interface MultiLineExpressionMapper { + + + MultiLineExpressionMapper INSTANCE = Mappers.getMapper( MultiLineExpressionMapper.class ); + + @Mappings({ + @Mapping(target = "timeAndFormat", expression = "java( new TimeAndFormat(\ns.getTime(),\ns.getFormat()\n ))"), + @Mapping(target = "anotherProp", ignore = true) + }) + Target mapUsingMultiLineExpression(Source s); + + @Mappings({ + @Mapping( + target = "timeAndFormat", + expression = " java( new TimeAndFormat(\ns.getTime(),\ns.getFormat()\n )) " + ), + @Mapping(target = "anotherProp", ignore = true) + }) + Target mapUsingMultiLineExpressionWithLeadingSpaces(Source s); +} From 98eb46aee9aec4135fed2bd0c2fbd0c621c22b08 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jun 2022 13:59:03 +0200 Subject: [PATCH 0681/1006] #2880 Fix missing import for array mapping methods Co-authored-by: Martin Kamp Jensen --- .../ap/internal/model/common/Type.java | 27 ++++++++++++++----- .../ap/test/bugs/_2880/Issue2880Mapper.java | 14 ++++++++++ .../ap/test/bugs/_2880/Issue2880Test.java | 25 +++++++++++++++++ .../mapstruct/ap/test/bugs/_2880/Outer.java | 16 +++++++++++ .../mapstruct/ap/test/bugs/_2880/Source.java | 21 +++++++++++++++ .../mapstruct/ap/test/bugs/_2880/Target.java | 21 +++++++++++++++ .../ap/test/bugs/_2880/TargetData.java | 13 +++++++++ 7 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Outer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/TargetData.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ba5f62254d..ce82fff621 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -181,8 +181,11 @@ public Type(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFact this.loggingVerbose = loggingVerbose; - this.topLevelType = topLevelType( this.typeElement, this.typeFactory ); - this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( this.typeElement ); + // The top level type for an array type is the top level type of the component type + TypeElement typeElementForTopLevel = + this.componentType == null ? this.typeElement : this.componentType.getTypeElement(); + this.topLevelType = topLevelType( typeElementForTopLevel, this.typeFactory ); + this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( typeElementForTopLevel, this.name ); } //CHECKSTYLE:ON @@ -218,11 +221,21 @@ public String getName() { * (if the top level type is important, otherwise the fully-qualified name. */ public String createReferenceName() { - if ( isToBeImported() || shouldUseSimpleName() ) { + if ( isToBeImported() ) { + // isToBeImported() returns true for arrays. + // Therefore, we need to check the top level type when creating the reference + if ( isTopLevelTypeToBeImported() ) { + return nameWithTopLevelTypeName != null ? nameWithTopLevelTypeName : name; + } + + return name; + } + + if ( shouldUseSimpleName() ) { return name; } - if ( isTopLevelTypeToBeImported() && nameWithTopLevelTypeName != null ) { + if ( isTopLevelTypeToBeImported() && nameWithTopLevelTypeName != null) { return nameWithTopLevelTypeName; } @@ -1566,16 +1579,16 @@ private String trimSimpleClassName(String className) { return trimmedClassName; } - private static String nameWithTopLevelTypeName(TypeElement element) { + private static String nameWithTopLevelTypeName(TypeElement element, String name) { if ( element == null ) { return null; } if ( !element.getNestingKind().isNested() ) { - return element.getSimpleName().toString(); + return name; } Deque elements = new ArrayDeque<>(); - elements.addFirst( element.getSimpleName() ); + elements.addFirst( name ); Element parent = element.getEnclosingElement(); while ( parent != null && parent.getKind() != ElementKind.PACKAGE ) { elements.addFirst( parent.getSimpleName() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Mapper.java new file mode 100644 index 0000000000..218f6d384b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Mapper.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +import org.mapstruct.Mapper; + +@Mapper +public interface Issue2880Mapper { + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Test.java new file mode 100644 index 0000000000..e3d0f810c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Issue2880Test.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +@IssueKey("2880") +@WithClasses({ + Issue2880Mapper.class, + Outer.class, + Source.class, + Target.class, + TargetData.class +}) +public class Issue2880Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Outer.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Outer.java new file mode 100644 index 0000000000..90b756137a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Outer.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +public class Outer { + + public static class SourceData { + + // CHECKSTYLE:OFF + public String value; + // CHECKSTYLE:ON + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Source.java new file mode 100644 index 0000000000..0ab3b81661 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Source.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +import java.util.List; + +public class Source { + + // CHECKSTYLE:OFF + public Outer.SourceData[] data1; + + public Outer.SourceData[] data2; + + public List data3; + + public List data4; + // CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Target.java new file mode 100644 index 0000000000..28c6b1cca1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/Target.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +import java.util.List; + +public class Target { + + // CHECKSTYLE:OFF + public TargetData[] data1; + + public List data2; + + public TargetData[] data3; + + public List data4; + // CHECKSTYLE:ON +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/TargetData.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/TargetData.java new file mode 100644 index 0000000000..28cca96601 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2880/TargetData.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2880; + +public class TargetData { + + // CHECKSTYLE:OFF + public String value; + // CHECKSTYLE:ON +} From 406ae3fc13a665fd52144dd476af371623b73a88 Mon Sep 17 00:00:00 2001 From: Sergei Portnov <3230150+prtnv@users.noreply.github.com> Date: Sat, 18 Jun 2022 19:47:07 +0300 Subject: [PATCH 0682/1006] #2891 Fix subclass mapping while superclass has non-empty constructor Co-authored-by: Filip Hrisafov --- .../ap/internal/model/BeanMappingMethod.java | 10 ++- .../ap/test/bugs/_2891/Issue2891Mapper.java | 76 +++++++++++++++++++ .../ap/test/bugs/_2891/Issue2891Test.java | 30 ++++++++ .../test/bugs/_2891/Issue2891MapperImpl.java | 61 +++++++++++++++ 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2891/Issue2891MapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 267702826b..d17718370d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -704,6 +704,14 @@ else if ( matchingFactoryMethods.size() == 1 ) { } private ConstructorAccessor getConstructorAccessor(Type type) { + if ( type.isAbstract() ) { + // We cannot construct abstract classes. + // Usually we won't reach here, + // but if SubclassMapping is used with SubclassExhaustiveStrategy#RUNTIME_EXCEPTION + // then we will still generate the code. + // We shouldn't generate anything for those abstract types + return null; + } if ( type.isRecord() ) { // If the type is a record then just get the record components and use then @@ -1783,7 +1791,7 @@ public boolean hasSubclassMappings() { } public boolean isAbstractReturnType() { - return getFactoryMethod() == null && !hasConstructorMappings() && returnTypeToConstruct != null + return getFactoryMethod() == null && returnTypeToConstruct != null && returnTypeToConstruct.isAbstract(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Mapper.java new file mode 100644 index 0000000000..205978aeb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Mapper.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2891; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; + +/** + * @author Sergei Portnov + */ +@Mapper +public interface Issue2891Mapper { + + @BeanMapping(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) + @SubclassMapping(source = Source1.class, target = Target1.class) + @SubclassMapping(source = Source2.class, target = Target2.class) + AbstractTarget map(AbstractSource source); + + abstract class AbstractTarget { + + private final String name; + + protected AbstractTarget(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class Target1 extends AbstractTarget { + + protected Target1(String name) { + super( name ); + } + } + + class Target2 extends AbstractTarget { + + protected Target2(String name) { + super( name ); + } + } + + abstract class AbstractSource { + + private final String name; + + protected AbstractSource(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class Source1 extends AbstractSource { + protected Source1(String name) { + super( name ); + } + } + + class Source2 extends AbstractSource { + + protected Source2(String name) { + super( name ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Test.java new file mode 100644 index 0000000000..c82d5aa63e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2891/Issue2891Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2891; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Sergei Portnov + */ +@WithClasses({ + Issue2891Mapper.class +}) +@IssueKey("2891") +class Issue2891Test { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( Issue2891Mapper.class ); + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2891/Issue2891MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2891/Issue2891MapperImpl.java new file mode 100644 index 0000000000..64ea2dc834 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2891/Issue2891MapperImpl.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2891; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2022-06-18T14:48:32+0300", + comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 11.0.15.1 (BellSoft)" +) +public class Issue2891MapperImpl implements Issue2891Mapper { + + @Override + public AbstractTarget map(AbstractSource source) { + if ( source == null ) { + return null; + } + + if (source instanceof Source1) { + return source1ToTarget1( (Source1) source ); + } + else if (source instanceof Source2) { + return source2ToTarget2( (Source2) source ); + } + else { + throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + source.getClass()); + } + } + + protected Target1 source1ToTarget1(Source1 source1) { + if ( source1 == null ) { + return null; + } + + String name = null; + + name = source1.getName(); + + Target1 target1 = new Target1( name ); + + return target1; + } + + protected Target2 source2ToTarget2(Source2 source2) { + if ( source2 == null ) { + return null; + } + + String name = null; + + name = source2.getName(); + + Target2 target2 = new Target2( name ); + + return target2; + } +} From 19973ff818e20531cbd81e5048404fd48c3c7508 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jun 2022 19:01:16 +0200 Subject: [PATCH 0683/1006] [maven-release-plugin] prepare release 1.5.2.Final --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..2979ad289d 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..9bce0a907a 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..b2dec2c1ea 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 9ceeb505ea..2c2351640c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..0691b8b88a 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 364faae643..0c2f866da0 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8c6a55ebed..335d917363 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.2.Final diff --git a/pom.xml b/pom.xml index 25a5ead6bc..66b25f8d89 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.5.2.Final diff --git a/processor/pom.xml b/processor/pom.xml index 6f2bb6495c..20e8150f91 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.5.2.Final ../parent/pom.xml From 1459aabfc3f1867d8e6ebbae641f1e38b6a1c0e2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jun 2022 19:01:18 +0200 Subject: [PATCH 0684/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 2979ad289d..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 9bce0a907a..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index b2dec2c1ea..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 2c2351640c..9ceeb505ea 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0691b8b88a..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 0c2f866da0..364faae643 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 335d917363..8c6a55ebed 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -69,7 +69,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.2.Final + HEAD diff --git a/pom.xml b/pom.xml index 66b25f8d89..25a5ead6bc 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.5.2.Final + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 20e8150f91..6f2bb6495c 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.5.2.Final + 1.6.0-SNAPSHOT ../parent/pom.xml From 07d144ebd1167fd4549835db0799413943091d4a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jun 2022 19:11:39 +0200 Subject: [PATCH 0685/1006] Update readme with latest released 1.5.2.Final release --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 0d6a93c781..e5811060a6 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.1.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.2.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.5.1.Final + 1.5.2.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - compile 'org.mapstruct:mapstruct:1.5.1.Final' + compile 'org.mapstruct:mapstruct:1.5.2.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.1.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.1.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' // if you are using mapstruct in test code } ... ``` From 88745d151ec60c7a0c2b8b840189c2db06fe053f Mon Sep 17 00:00:00 2001 From: Ben Zegveld Date: Thu, 9 Jun 2022 22:36:47 +0200 Subject: [PATCH 0686/1006] #2882: target type is now correctly passed on through the MethodReferencePresenceCheck to the MethodReference. --- .../model/MethodReferencePresenceCheck.ftl | 3 ++- .../ap/internal/model/macro/CommonMacros.ftl | 3 ++- .../basic/ConditionalMappingTest.java | 6 +++++ .../ConditionalMethodWithTargetType.java | 27 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithTargetType.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl index 44ec296736..9a2837a02d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -6,4 +6,5 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> -<@includeModel object=methodReference/> \ No newline at end of file +<@includeModel object=methodReference + targetType=ext.targetType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 048402401b..6d05ddd131 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -15,7 +15,8 @@ --> <#macro handleSourceReferenceNullCheck> <#if sourcePresenceCheckerReference??> - if ( <@includeModel object=sourcePresenceCheckerReference /> ) { + if ( <@includeModel object=sourcePresenceCheckerReference + targetType=ext.targetType/> ) { <#nested> } <@elseDefaultAssignment/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java index 62fd79ae84..57a68a9526 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java @@ -50,6 +50,12 @@ public void conditionalMethodInMapper() { assertThat( employee.getName() ).isNull(); } + @IssueKey( "2882" ) + @ProcessorTest + @WithClasses( { ConditionalMethodWithTargetType.class } ) + public void conditionalMethodWithTargetTypeShouldCompile() { + } + @ProcessorTest @WithClasses({ ConditionalMethodAndBeanPresenceCheckMapper.class diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithTargetType.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithTargetType.java new file mode 100644 index 0000000000..5ec242d8ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodWithTargetType.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface ConditionalMethodWithTargetType { + + ConditionalMethodWithTargetType INSTANCE = Mappers.getMapper( ConditionalMethodWithTargetType.class ); + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition + default boolean isNotBlank(String value, @TargetType Class targetType) { + return value != null && !value.trim().isEmpty(); + } +} From de8c0c7070aabd10656c67088b5c7b52b92c954b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 18 Jun 2022 15:16:21 +0200 Subject: [PATCH 0687/1006] Use UTF-8 when compiling the tests The test infrastructure that we are using should use UTF-8 for generating the StandardJavaFileManager --- .../mapstruct/ap/testutil/runner/JdkCompilingExtension.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 2a0b6ba537..7b44a4733b 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -52,7 +53,7 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe String additionalCompilerClasspath) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector diagnostics = new DiagnosticCollector<>(); - StandardJavaFileManager fileManager = compiler.getStandardFileManager( null, null, null ); + StandardJavaFileManager fileManager = compiler.getStandardFileManager( null, null, StandardCharsets.UTF_8 ); Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.getSourceClasses() ) ); From a2b4454a669759a9e423e2b85e803ef6d4ddf251 Mon Sep 17 00:00:00 2001 From: fml2 <534392+fml2@users.noreply.github.com> Date: Fri, 1 Jul 2022 17:18:46 +0200 Subject: [PATCH 0688/1006] fix(docs): No Lombok classes in the runtime --- .../asciidoc/chapter-14-third-party-api-integration.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc index 69bef46ea6..0f12d67e22 100644 --- a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc +++ b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc @@ -140,7 +140,7 @@ The set up using Maven or Gradle does not differ from what is described in < Date: Wed, 6 Jul 2022 14:39:21 +0200 Subject: [PATCH 0689/1006] #2922 Fix protobuf tests for M1 Macs --- .../src/test/resources/protobufBuilderTest/pom.xml | 6 +++--- parent/pom.xml | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/integrationtest/src/test/resources/protobufBuilderTest/pom.xml b/integrationtest/src/test/resources/protobufBuilderTest/pom.xml index ecbbf1d6d8..c0d8e2a81b 100644 --- a/integrationtest/src/test/resources/protobufBuilderTest/pom.xml +++ b/integrationtest/src/test/resources/protobufBuilderTest/pom.xml @@ -23,7 +23,7 @@ 1.6.0 - 0.5.1 + 0.6.1 @@ -55,10 +55,10 @@ compile-custom - com.google.protobuf:protoc:3.2.0:exe:${os.detected.classifier} + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} grpc-java - io.grpc:protoc-gen-grpc-java:1.2.0:exe:${os.detected.classifier} + io.grpc:protoc-gen-grpc-java:1.47.0:exe:${os.detected.classifier} diff --git a/parent/pom.xml b/parent/pom.xml index 8c6a55ebed..1c031a7b71 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -41,6 +41,7 @@ The processor module needs at least Java 11. --> 1.8 + 3.21.2 @@ -234,7 +235,7 @@ com.google.protobuf protobuf-java - 3.16.1 + ${protobuf.version} org.inferred From dd5ac3b637e20db014d89560e7467d09a65075e2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 8 Jul 2022 20:40:26 +0200 Subject: [PATCH 0690/1006] #2929 Improve documentation for `BeanMapping#ignoreByDefault` --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index d1c63c25a2..ab33666435 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -40,6 +40,7 @@ The property name as defined in the http://www.oracle.com/technetwork/java/javas [TIP] ==== By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. +This allows to ignore all fields, except the ones that are explicitly defined through `@Mapping`. ==== [TIP] ==== From 691488951027b0b016f52928e746677a39201900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cassius=20Vinicius=20de=20Magalh=C3=A3es?= Date: Thu, 14 Jul 2022 14:38:18 -0300 Subject: [PATCH 0691/1006] Update Chapter 11.2 - Inverse Mappings Clarification of the inverse mapping usage. --- .../chapter-11-reusing-mapping-configurations.asciidoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc index fb8c71a622..efacaedbe5 100644 --- a/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc +++ b/documentation/src/main/asciidoc/chapter-11-reusing-mapping-configurations.asciidoc @@ -46,6 +46,8 @@ In case of bi-directional mappings, e.g. from entity to DTO and from DTO to enti Use the annotation `@InheritInverseConfiguration` to indicate that a method shall inherit the inverse configuration of the corresponding reverse method. +In the example below, there is no need to write the inverse mapping manually. Think of a case where there are several mappings, so writing the inverse ones can be cumbersome and error prone. + .Inverse mapping method inheriting its configuration and ignoring some of them ==== [source, java, linenums] @@ -162,4 +164,4 @@ The attributes `@Mapper#mappingInheritanceStrategy()` / `@MapperConfig#mappingIn * `EXPLICIT` (default): the configuration will only be inherited, if the target mapping method is annotated with `@InheritConfiguration` and the source and target types are assignable to the corresponding types of the prototype method, all as described in <>. * `AUTO_INHERIT_FROM_CONFIG`: the configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritConfiguration(name = ...)` which will cause `AUTO_INHERIT_FROM_CONFIG` to be ignored. * `AUTO_INHERIT_REVERSE_FROM_CONFIG`: the inverse configuration will be inherited automatically, if the source and target types of the target mapping method are assignable to the corresponding types of the prototype method. If multiple prototype methods match, the ambiguity must be resolved using `@InheritInverseConfiguration(name = ...)` which will cause ``AUTO_INHERIT_REVERSE_FROM_CONFIG` to be ignored. -* `AUTO_INHERIT_ALL_FROM_CONFIG`: both the configuration and the inverse configuration will be inherited automatically. The same rules apply as for `AUTO_INHERIT_FROM_CONFIG` or `AUTO_INHERIT_REVERSE_FROM_CONFIG`. \ No newline at end of file +* `AUTO_INHERIT_ALL_FROM_CONFIG`: both the configuration and the inverse configuration will be inherited automatically. The same rules apply as for `AUTO_INHERIT_FROM_CONFIG` or `AUTO_INHERIT_REVERSE_FROM_CONFIG`. From 62e73464b2c3dd16c0c88a3d5bfebe7b710facec Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Jul 2022 12:42:32 +0000 Subject: [PATCH 0692/1006] Bump kotlin-stdlib in /integrationtest/src/test/resources/kotlinDataTest Bumps [kotlin-stdlib](https://github.com/JetBrains/kotlin) from 1.3.70 to 1.6.0. - [Release notes](https://github.com/JetBrains/kotlin/releases) - [Changelog](https://github.com/JetBrains/kotlin/blob/v1.6.0/ChangeLog.md) - [Commits](https://github.com/JetBrains/kotlin/compare/v1.3.70...v1.6.0) --- updated-dependencies: - dependency-name: org.jetbrains.kotlin:kotlin-stdlib dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- integrationtest/src/test/resources/kotlinDataTest/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationtest/src/test/resources/kotlinDataTest/pom.xml b/integrationtest/src/test/resources/kotlinDataTest/pom.xml index 8a43a04194..f86f92b9c4 100644 --- a/integrationtest/src/test/resources/kotlinDataTest/pom.xml +++ b/integrationtest/src/test/resources/kotlinDataTest/pom.xml @@ -22,7 +22,7 @@ jar - 1.3.70 + 1.6.0 From 8fa286fe4ce790cc2a65adff55c813bc9717437a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Iva=C4=8Di=C4=8D?= Date: Mon, 30 May 2022 12:33:47 +0200 Subject: [PATCH 0693/1006] #2688: Support accessing to the target property name --- .../main/java/org/mapstruct/Condition.java | 1 + .../org/mapstruct/TargetPropertyName.java | 25 ++ ...apter-10-advanced-mapping-options.asciidoc | 57 ++++ .../ap/internal/gem/GemGenerator.java | 2 + .../ap/internal/model/common/Parameter.java | 22 +- .../model/common/ParameterBinding.java | 28 +- .../internal/model/source/SourceMethod.java | 9 +- .../model/source/selector/TypeSelector.java | 16 +- .../ap/internal/model/MethodReference.ftl | 3 + .../model/MethodReferencePresenceCheck.ftl | 1 + .../ap/internal/model/PropertyMapping.ftl | 1 + .../ap/internal/model/TypeConversion.ftl | 1 + .../model/assignment/Java8FunctionWrapper.ftl | 1 + .../model/assignment/LocalVarWrapper.ftl | 1 + .../model/assignment/ReturnWrapper.ftl | 1 + .../ap/internal/model/macro/CommonMacros.ftl | 6 +- .../targetpropertyname/Address.java | 21 ++ .../targetpropertyname/AddressDto.java | 21 ++ ...ollectionMapperWithTargetPropertyName.java | 41 +++ ...onalMethodInMapperWithAllExceptTarget.java | 46 +++ ...nditionalMethodInMapperWithAllOptions.java | 52 ++++ ...lMethodInMapperWithTargetPropertyName.java | 32 ++ ...hodInUsesMapperWithTargetPropertyName.java | 36 +++ ...WithTargetPropertyNameInContextMapper.java | 89 ++++++ .../targetpropertyname/DomainModel.java | 15 + .../targetpropertyname/Employee.java | 99 ++++++ .../targetpropertyname/EmployeeDto.java | 98 ++++++ .../TargetPropertyNameTest.java | 281 ++++++++++++++++++ 28 files changed, 993 insertions(+), 13 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/TargetPropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java diff --git a/core/src/main/java/org/mapstruct/Condition.java b/core/src/main/java/org/mapstruct/Condition.java index ec1bf06a88..148ec4879d 100644 --- a/core/src/main/java/org/mapstruct/Condition.java +++ b/core/src/main/java/org/mapstruct/Condition.java @@ -23,6 +23,7 @@ * e.g. the value given by calling {@code getName()} for the name property of the source bean *
    • The mapping source parameter
    • *
    • {@code @}{@link Context} parameter
    • + *
    • {@code @}{@link TargetPropertyName} parameter
    • *
    * * Note: The usage of this annotation is mandatory diff --git a/core/src/main/java/org/mapstruct/TargetPropertyName.java b/core/src/main/java/org/mapstruct/TargetPropertyName.java new file mode 100644 index 0000000000..17af966fa8 --- /dev/null +++ b/core/src/main/java/org/mapstruct/TargetPropertyName.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation marks a presence check method parameter as a property name parameter. + *

    + * This parameter enables conditional filtering based on target property name at run-time. + * Parameter must be of type {@link String} and can be present only in {@link Condition} method. + *

    + * @author Nikola Ivačič + * @since 1.6 + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.CLASS) +public @interface TargetPropertyName { +} diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 1cc19fcc3e..decee792d0 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -404,6 +404,61 @@ public class CarMapperImpl implements CarMapper { ---- ==== +Additionally `@TargetPropertyName` of type `java.lang.String` can be used in custom condition check method: + +.Mapper using custom condition check method with `@TargetPropertyName` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarDto carToCarDto(Car car, @MappingTarget CarDto carDto); + + @Condition + default boolean isNotEmpty(String value, @TargetPropertyName String name) { + if ( name.equals( "owner" ) { + return value != null + && !value.isEmpty() + && !value.equals( value.toLowerCase() ); + } + return value != null && !value.isEmpty(); + } +} +---- +==== + +The generated mapper with `@TargetPropertyName` will look like: + +.Custom condition check in generated implementation +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car, CarDto carDto) { + if ( car == null ) { + return carDto; + } + + if ( isNotEmpty( car.getOwner(), "owner" ) ) { + carDto.setOwner( car.getOwner() ); + } else { + carDto.setOwner( null ); + } + + // Mapping of other properties + + return carDto; + } +} +---- +==== + [IMPORTANT] ==== If there is a custom `@Condition` method applicable for the property it will have a precedence over a presence check method in the bean itself. @@ -412,6 +467,8 @@ If there is a custom `@Condition` method applicable for the property it will hav [NOTE] ==== Methods annotated with `@Condition` in addition to the value of the source property can also have the source parameter as an input. + +`@TargetPropertyName` parameter can only be used in `@Condition` methods. ==== <> is also valid for `@Condition` methods. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index e0491cbc4e..70098c952e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -30,6 +30,7 @@ import org.mapstruct.Qualifier; import org.mapstruct.SubclassMapping; import org.mapstruct.SubclassMappings; +import org.mapstruct.TargetPropertyName; import org.mapstruct.TargetType; import org.mapstruct.ValueMapping; import org.mapstruct.ValueMappings; @@ -52,6 +53,7 @@ @GemDefinition(SubclassMapping.class) @GemDefinition(SubclassMappings.class) @GemDefinition(TargetType.class) +@GemDefinition(TargetPropertyName.class) @GemDefinition(MappingTarget.class) @GemDefinition(DecoratedWith.class) @GemDefinition(MapperConfig.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index dc62018be5..600c8ac337 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -15,6 +15,7 @@ import org.mapstruct.ap.internal.gem.ContextGem; import org.mapstruct.ap.internal.gem.MappingTargetGem; import org.mapstruct.ap.internal.gem.TargetTypeGem; +import org.mapstruct.ap.internal.gem.TargetPropertyNameGem; import org.mapstruct.ap.internal.util.Collections; /** @@ -31,6 +32,7 @@ public class Parameter extends ModelElement { private final boolean mappingTarget; private final boolean targetType; private final boolean mappingContext; + private final boolean targetPropertyName; private final boolean varArgs; @@ -42,10 +44,12 @@ private Parameter(Element element, Type type, boolean varArgs) { this.mappingTarget = MappingTargetGem.instanceOn( element ) != null; this.targetType = TargetTypeGem.instanceOn( element ) != null; this.mappingContext = ContextGem.instanceOn( element ) != null; + this.targetPropertyName = TargetPropertyNameGem.instanceOn( element ) != null; this.varArgs = varArgs; } private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext, + boolean targetPropertyName, boolean varArgs) { this.element = null; this.name = name; @@ -54,11 +58,12 @@ private Parameter(String name, Type type, boolean mappingTarget, boolean targetT this.mappingTarget = mappingTarget; this.targetType = targetType; this.mappingContext = mappingContext; + this.targetPropertyName = targetPropertyName; this.varArgs = varArgs; } public Parameter(String name, Type type) { - this( name, type, false, false, false, false ); + this( name, type, false, false, false, false, false ); } public Element getElement() { @@ -94,6 +99,7 @@ private String format() { return ( mappingTarget ? "@MappingTarget " : "" ) + ( targetType ? "@TargetType " : "" ) + ( mappingContext ? "@Context " : "" ) + + ( targetPropertyName ? "@TargetPropertyName " : "" ) + "%s " + name; } @@ -110,6 +116,10 @@ public boolean isMappingContext() { return mappingContext; } + public boolean isTargetPropertyName() { + return targetPropertyName; + } + public boolean isVarArgs() { return varArgs; } @@ -154,6 +164,7 @@ public static Parameter forForgedMappingTarget(Type parameterType) { true, false, false, + false, false ); } @@ -195,8 +206,15 @@ public static Parameter getTargetTypeParameter(List parameters) { return parameters.stream().filter( Parameter::isTargetType ).findAny().orElse( null ); } + public static Parameter getTargetPropertyNameParameter(List parameters) { + return parameters.stream().filter( Parameter::isTargetPropertyName ).findAny().orElse( null ); + } + private static boolean isSourceParameter( Parameter parameter ) { - return !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext(); + return !parameter.isMappingTarget() && + !parameter.isTargetType() && + !parameter.isMappingContext() && + !parameter.isTargetPropertyName(); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 36e4d3e864..18274e5492 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -22,15 +22,17 @@ public class ParameterBinding { private final boolean targetType; private final boolean mappingTarget; private final boolean mappingContext; + private final boolean targetPropertyName; private final SourceRHS sourceRHS; private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType, - boolean mappingContext, SourceRHS sourceRHS) { + boolean mappingContext, boolean targetPropertyName, SourceRHS sourceRHS) { this.type = parameterType; this.variableName = variableName; this.targetType = targetType; this.mappingTarget = mappingTarget; this.mappingContext = mappingContext; + this.targetPropertyName = targetPropertyName; this.sourceRHS = sourceRHS; } @@ -62,6 +64,13 @@ public boolean isMappingContext() { return mappingContext; } + /** + * @return {@code true}, if the parameter being bound is a {@code @TargetPropertyName} parameter. + */ + public boolean isTargetPropertyName() { + return targetPropertyName; + } + /** * @return the type of the parameter that is bound */ @@ -99,6 +108,7 @@ public static ParameterBinding fromParameter(Parameter parameter) { parameter.isMappingTarget(), parameter.isTargetType(), parameter.isMappingContext(), + parameter.isTargetPropertyName(), null ); } @@ -118,6 +128,7 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame false, false, false, + false, null ); } @@ -127,7 +138,14 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame * @return a parameter binding representing a target type parameter */ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, true, false, null ); + return new ParameterBinding( classTypeOf, null, false, true, false, false, null ); + } + + /** + * @return a parameter binding representing a target property name parameter + */ + public static ParameterBinding forTargetPropertyNameBinding(Type classTypeOf) { + return new ParameterBinding( classTypeOf, null, false, false, false, true, null ); } /** @@ -135,7 +153,7 @@ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { * @return a parameter binding representing a mapping target parameter */ public static ParameterBinding forMappingTargetBinding(Type resultType) { - return new ParameterBinding( resultType, null, true, false, false, null ); + return new ParameterBinding( resultType, null, true, false, false, false, null ); } /** @@ -143,10 +161,10 @@ public static ParameterBinding forMappingTargetBinding(Type resultType) { * @return a parameter binding representing a mapping source type */ public static ParameterBinding forSourceTypeBinding(Type sourceType) { - return new ParameterBinding( sourceType, null, false, false, false, null ); + return new ParameterBinding( sourceType, null, false, false, false, false, null ); } public static ParameterBinding fromSourceRHS(SourceRHS sourceRHS) { - return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, sourceRHS ); + return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, false, sourceRHS ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 92180bca8a..37b57d9025 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -47,6 +47,7 @@ public class SourceMethod implements Method { private final List parameters; private final Parameter mappingTargetParameter; private final Parameter targetTypeParameter; + private final Parameter targetPropertyNameParameter; private final boolean isObjectFactory; private final boolean isPresenceCheck; private final Type returnType; @@ -248,6 +249,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); + this.targetPropertyNameParameter = Parameter.getTargetPropertyNameParameter( parameters ); this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null; this.isObjectFactory = determineIfIsObjectFactory(); this.isPresenceCheck = determineIfIsPresenceCheck(); @@ -263,8 +265,9 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) private boolean determineIfIsObjectFactory() { boolean hasNoSourceParameters = getSourceParameters().isEmpty(); boolean hasNoMappingTargetParam = getMappingTargetParameter() == null; + boolean hasNoTargetPropertyNameParam = getTargetPropertyNameParameter() == null; return !isLifecycleCallbackMethod() && !returnType.isVoid() - && hasNoMappingTargetParam + && hasNoMappingTargetParam && hasNoTargetPropertyNameParam && ( hasObjectFactoryAnnotation || hasNoSourceParameters ); } @@ -379,6 +382,10 @@ public Parameter getTargetTypeParameter() { return targetTypeParameter; } + public Parameter getTargetPropertyNameParameter() { + return targetPropertyNameParameter; + } + public boolean isIterableMapping() { if ( isIterableMapping == null ) { isIterableMapping = getSourceParameters().size() == 1 diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 74e518c84d..8acdd327c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -96,7 +96,7 @@ private List getAvailableParameterBindingsFromMethod(Method me availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); } - addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + addTargetRelevantBindings( availableParams, targetType ); return availableParams; } @@ -116,7 +116,7 @@ private List getAvailableParameterBindingsFromSourceTypes(List } } - addMappingTargetAndTargetTypeBindings( availableParams, targetType ); + addTargetRelevantBindings( availableParams, targetType ); return availableParams; } @@ -127,9 +127,10 @@ private List getAvailableParameterBindingsFromSourceTypes(List * @param availableParams Already available params, new entries will be added to this list * @param targetType Target type */ - private void addMappingTargetAndTargetTypeBindings(List availableParams, Type targetType) { + private void addTargetRelevantBindings(List availableParams, Type targetType) { boolean mappingTargetAvailable = false; boolean targetTypeAvailable = false; + boolean targetPropertyNameAvailable = false; // search available parameter bindings if mapping-target and/or target-type is available for ( ParameterBinding pb : availableParams ) { @@ -139,6 +140,9 @@ private void addMappingTargetAndTargetTypeBindings(List availa else if ( pb.isTargetType() ) { targetTypeAvailable = true; } + else if ( pb.isTargetPropertyName() ) { + targetPropertyNameAvailable = true; + } } if ( !mappingTargetAvailable ) { @@ -147,6 +151,9 @@ else if ( pb.isTargetType() ) { if ( !targetTypeAvailable ) { availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); } + if ( !targetPropertyNameAvailable ) { + availableParams.add( ParameterBinding.forTargetPropertyNameBinding( typeFactory.getType( String.class ) ) ); + } } private SelectedMethod getMatchingParameterBinding(Type returnType, @@ -301,7 +308,8 @@ private static List findCandidateBindingsForParameter(List${ext.targetBeanName}<#else>${param.variableName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> <#elseif param.mappingContext> ${param.variableName}<#t> + <#elseif param.targetPropertyName> + "${ext.targetPropertyName}"<#t> <#elseif param.sourceRHS??> <@_assignment assignmentToUse=param.sourceRHS/><#t> <#elseif assignment??> @@ -66,5 +68,6 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=singleSourceParameterType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl index 9a2837a02d..24f871e214 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -7,4 +7,5 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> <@includeModel object=methodReference + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index 20e6f1734c..e6aef4cecd 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -11,5 +11,6 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=targetReadAccessorName targetWriteAccessorName=targetWriteAccessorName + targetPropertyName=name targetType=targetType defaultValueAssignment=defaultValueAssignment /> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl index 370fe7c978..4a9d356ce4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl @@ -14,6 +14,7 @@ ${openExpression}<@_assignment/>${closeExpression} existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl index 2795dac7bc..ce1fcdcd6c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl @@ -34,5 +34,6 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl index 53e987e476..97ea856ece 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl @@ -25,5 +25,6 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl index 9f46f3604f..9917dbacf8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ReturnWrapper.ftl @@ -13,5 +13,6 @@ return <@_assignment/>; existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 6d05ddd131..e5fb970605 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -16,6 +16,7 @@ <#macro handleSourceReferenceNullCheck> <#if sourcePresenceCheckerReference??> if ( <@includeModel object=sourcePresenceCheckerReference + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> ) { <#nested> } @@ -58,7 +59,8 @@ --> <#macro handleLocalVarNullCheck needs_explicit_local_var> <#if sourcePresenceCheckerReference??> - if ( <@includeModel object=sourcePresenceCheckerReference /> ) { + if ( <@includeModel object=sourcePresenceCheckerReference + targetPropertyName=ext.targetPropertyName/> ) { <#if needs_explicit_local_var> <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; <#nested> @@ -113,6 +115,7 @@ Performs a standard assignment. existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> <#-- @@ -124,6 +127,7 @@ Performs a default assignment with a default value. existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + targetPropertyName=ext.targetPropertyName targetType=ext.targetType defaultValue=ext.defaultValue/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java new file mode 100644 index 0000000000..162ed118bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +/** + * @author Nikola Ivačič + */ +public class Address implements DomainModel { + private String street; + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java new file mode 100644 index 0000000000..f4cbc71915 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +/** + * @author Nikola Ivačič + */ +public class AddressDto implements DomainModel { + private final String street; + + public AddressDto(String street) { + this.street = street; + } + + public String getStreet() { + return street; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java new file mode 100644 index 0000000000..71baa0942b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java @@ -0,0 +1,41 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +import java.util.Collection; + +/** + * @author Nikola Ivačič + */ +@Mapper +public interface ConditionalMethodForCollectionMapperWithTargetPropertyName { + + ConditionalMethodForCollectionMapperWithTargetPropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodForCollectionMapperWithTargetPropertyName.class ); + + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotEmpty(Collection collection, @TargetPropertyName String propName) { + if ( "addresses".equalsIgnoreCase( propName ) ) { + return false; + } + return collection != null && !collection.isEmpty(); + } + + @Condition + default boolean isNotBlank(String value, @TargetPropertyName String propName) { + if ( propName.equalsIgnoreCase( "lastName" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java new file mode 100644 index 0000000000..430303d06d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + */ +@Mapper +public interface ConditionalMethodInMapperWithAllExceptTarget { + + ConditionalMethodInMapperWithAllExceptTarget INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithAllExceptTarget.class ); + + class PresenceUtils { + Set visited = new LinkedHashSet<>(); + Set visitedSources = new LinkedHashSet<>(); + } + + Employee map(EmployeeDto employee, @Context PresenceUtils utils); + + @Condition + default boolean isNotBlank(String value, + DomainModel source, + @TargetPropertyName String propName, + @Context PresenceUtils utils) { + utils.visited.add( propName ); + utils.visitedSources.add( source.getClass().getSimpleName() ); + if ( propName.equalsIgnoreCase( "firstName" ) ) { + return true; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java new file mode 100644 index 0000000000..a18ba0db73 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + */ +@Mapper +public interface ConditionalMethodInMapperWithAllOptions { + + ConditionalMethodInMapperWithAllOptions INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithAllOptions.class ); + + class PresenceUtils { + Set visited = new LinkedHashSet<>(); + Set visitedSources = new LinkedHashSet<>(); + Set visitedTargets = new LinkedHashSet<>(); + } + + void map(EmployeeDto employeeDto, + @MappingTarget Employee employee, + @Context PresenceUtils utils); + + @Condition + default boolean isNotBlank(String value, + DomainModel source, + @MappingTarget DomainModel target, + @TargetPropertyName String propName, + @Context PresenceUtils utils) { + utils.visited.add( propName ); + utils.visitedSources.add( source.getClass().getSimpleName() ); + utils.visitedTargets.add( target.getClass().getSimpleName() ); + if ( propName.equalsIgnoreCase( "lastName" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java new file mode 100644 index 0000000000..6d27bc9036 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + */ +@Mapper +public interface ConditionalMethodInMapperWithTargetPropertyName { + + ConditionalMethodInMapperWithTargetPropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithTargetPropertyName.class ); + + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value, @TargetPropertyName String propName) { + if ( propName.equalsIgnoreCase( "lastName" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java new file mode 100644 index 0000000000..7c526884e9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + */ +@Mapper(uses = ConditionalMethodInUsesMapperWithTargetPropertyName.PresenceUtils.class) +public interface ConditionalMethodInUsesMapperWithTargetPropertyName { + + ConditionalMethodInUsesMapperWithTargetPropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodInUsesMapperWithTargetPropertyName.class ); + + Employee map(EmployeeDto employee); + + class PresenceUtils { + + @Condition + public boolean isNotBlank(String value, @TargetPropertyName String propName) { + if ( propName.equalsIgnoreCase( "lastName" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java new file mode 100644 index 0000000000..a7cde220c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java @@ -0,0 +1,89 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.factory.Mappers; + +import java.util.Deque; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.Set; + +/** + * @author Nikola Ivačič + */ +@Mapper +public interface ConditionalMethodWithTargetPropertyNameInContextMapper { + + ConditionalMethodWithTargetPropertyNameInContextMapper INSTANCE + = Mappers.getMapper( ConditionalMethodWithTargetPropertyNameInContextMapper.class ); + + Employee map(EmployeeDto employee, @Context PresenceUtils utils); + + Address map(AddressDto addressDto, @Context PresenceUtils utils); + + class PresenceUtils { + Set visited = new LinkedHashSet<>(); + + @Condition + public boolean isNotBlank(String value, @TargetPropertyName String propName) { + visited.add( propName ); + return value != null && !value.trim().isEmpty(); + } + } + + Employee map(EmployeeDto employee, @Context PresenceUtilsAllProps utils); + + Address map(AddressDto addressDto, @Context PresenceUtilsAllProps utils); + + class PresenceUtilsAllProps { + Set visited = new LinkedHashSet<>(); + + @Condition + public boolean collect(@TargetPropertyName String propName) { + visited.add( propName ); + return true; + } + } + + Employee map(EmployeeDto employee, @Context PresenceUtilsAllPropsWithSource utils); + + Address map(AddressDto addressDto, @Context PresenceUtilsAllPropsWithSource utils); + + @BeforeMapping + default void before(DomainModel source, @Context PresenceUtilsAllPropsWithSource utils) { + String lastProp = utils.visitedSegments.peekLast(); + if ( lastProp != null && source != null ) { + utils.path.offerLast( lastProp ); + } + } + + @AfterMapping + default void after(@Context PresenceUtilsAllPropsWithSource utils) { + utils.path.pollLast(); + } + + class PresenceUtilsAllPropsWithSource { + Deque visitedSegments = new LinkedList<>(); + Deque visited = new LinkedList<>(); + Deque path = new LinkedList<>(); + + @Condition + public boolean collect(@TargetPropertyName String propName) { + visitedSegments.offerLast( propName ); + path.offerLast( propName ); + visited.offerLast( String.join( ".", path ) ); + path.pollLast(); + return true; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java new file mode 100644 index 0000000000..4d2c716a96 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +/** + * Target Property Name test entities + * + * @author Nikola Ivačič + */ +public interface DomainModel { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java new file mode 100644 index 0000000000..59ee3426e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java @@ -0,0 +1,99 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import java.util.List; + +/** + * @author Nikola Ivačič + */ +public class Employee implements DomainModel { + + private String firstName; + private String lastName; + private String title; + private String country; + private boolean active; + private int age; + + private Employee boss; + + private Address primaryAddress; + + private List
    addresses; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Employee getBoss() { + return boss; + } + + public void setBoss(Employee boss) { + this.boss = boss; + } + + public Address getPrimaryAddress() { + return primaryAddress; + } + + public void setPrimaryAddress(Address primaryAddress) { + this.primaryAddress = primaryAddress; + } + + public List
    getAddresses() { + return addresses; + } + + public void setAddresses(List
    addresses) { + this.addresses = addresses; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java new file mode 100644 index 0000000000..5d81a9334b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java @@ -0,0 +1,98 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import java.util.List; + +/** + * @author Nikola Ivačič + */ +public class EmployeeDto implements DomainModel { + + private String firstName; + private String lastName; + private String title; + private String country; + private boolean active; + private int age; + + private EmployeeDto boss; + + private AddressDto primaryAddress; + private List addresses; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public EmployeeDto getBoss() { + return boss; + } + + public void setBoss(EmployeeDto boss) { + this.boss = boss; + } + + public AddressDto getPrimaryAddress() { + return primaryAddress; + } + + public void setPrimaryAddress(AddressDto primaryAddress) { + this.primaryAddress = primaryAddress; + } + + public List getAddresses() { + return addresses; + } + + public void setAddresses(List addresses) { + this.addresses = addresses; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java new file mode 100644 index 0000000000..3d96e66664 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java @@ -0,0 +1,281 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + */ +@IssueKey("2051") +@WithClasses({ + Address.class, + AddressDto.class, + Employee.class, + EmployeeDto.class, + DomainModel.class +}) +public class TargetPropertyNameTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithTargetPropertyName.class + }) + public void conditionalMethodInMapperWithTargetPropertyName() { + ConditionalMethodInMapperWithTargetPropertyName mapper + = ConditionalMethodInMapperWithTargetPropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodForCollectionMapperWithTargetPropertyName.class + }) + public void conditionalMethodForCollectionMapperWithTargetPropertyName() { + ConditionalMethodForCollectionMapperWithTargetPropertyName mapper + = ConditionalMethodForCollectionMapperWithTargetPropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ).isNull(); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInUsesMapperWithTargetPropertyName.class + }) + public void conditionalMethodInUsesMapperWithTargetPropertyName() { + ConditionalMethodInUsesMapperWithTargetPropertyName mapper + = ConditionalMethodInUsesMapperWithTargetPropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithAllOptions.class + }) + public void conditionalMethodInMapperWithAllOptions() { + ConditionalMethodInMapperWithAllOptions mapper + = ConditionalMethodInMapperWithAllOptions.INSTANCE; + + ConditionalMethodInMapperWithAllOptions.PresenceUtils utils = + new ConditionalMethodInMapperWithAllOptions.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = new Employee(); + mapper.map( employeeDto, employee, utils ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visited ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "country" ); + assertThat( utils.visitedSources ).containsExactly( "EmployeeDto" ); + assertThat( utils.visitedTargets ).containsExactly( "Employee" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithAllExceptTarget.class + }) + public void conditionalMethodInMapperWithAllExceptTarget() { + ConditionalMethodInMapperWithAllExceptTarget mapper + = ConditionalMethodInMapperWithAllExceptTarget.INSTANCE; + + ConditionalMethodInMapperWithAllExceptTarget.PresenceUtils utils = + new ConditionalMethodInMapperWithAllExceptTarget.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto, utils ); + assertThat( employee.getLastName() ).isEqualTo( "Testirovich" ); + assertThat( employee.getFirstName() ).isEqualTo( " " ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visited ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "country", "street" ); + assertThat( utils.visitedSources ).containsExactlyInAnyOrder( "EmployeeDto", "AddressDto" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodWithTargetPropertyNameInContextMapper.class + }) + public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { + ConditionalMethodWithTargetPropertyNameInContextMapper mapper + = ConditionalMethodWithTargetPropertyNameInContextMapper.INSTANCE; + + ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtils utils = + new ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setLastName( " " ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto, utils ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visited ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "country", "street" ); + + ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtilsAllProps allPropsUtils = + new ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtilsAllProps(); + + employeeDto = new EmployeeDto(); + employeeDto.setLastName( "Tester" ); + employeeDto.setCountry( "US" ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + employee = mapper.map( employeeDto, allPropsUtils ); + assertThat( employee.getLastName() ).isEqualTo( "Tester" ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( allPropsUtils.visited ) + .containsExactlyInAnyOrder( + "firstName", + "lastName", + "title", + "country", + "active", + "age", + "boss", + "primaryAddress", + "addresses", + "street" + ); + + ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtilsAllPropsWithSource allPropsUtilsWithSource = + new ConditionalMethodWithTargetPropertyNameInContextMapper.PresenceUtilsAllPropsWithSource(); + + EmployeeDto bossEmployeeDto = new EmployeeDto(); + bossEmployeeDto.setLastName( "Boss Tester" ); + bossEmployeeDto.setCountry( "US" ); + bossEmployeeDto.setAddresses( Collections.singletonList( new AddressDto( + "Testing St. 10" ) ) ); + + employeeDto = new EmployeeDto(); + employeeDto.setLastName( "Tester" ); + employeeDto.setCountry( "US" ); + employeeDto.setBoss( bossEmployeeDto ); + employeeDto.setAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + employee = mapper.map( employeeDto, allPropsUtilsWithSource ); + assertThat( employee.getLastName() ).isEqualTo( "Tester" ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ).isNotEmpty(); + assertThat( employee.getAddresses().get( 0 ).getStreet() ).isEqualTo( "Testing St. 6" ); + assertThat( employee.getBoss() ).isNotNull(); + assertThat( employee.getBoss().getCountry() ).isEqualTo( "US" ); + assertThat( employee.getBoss().getLastName() ).isEqualTo( "Boss Tester" ); + assertThat( employee.getBoss().getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 10" ); + assertThat( allPropsUtilsWithSource.visited ) + .containsExactly( + "firstName", + "lastName", + "title", + "country", + "active", + "age", + "boss", + "boss.firstName", + "boss.lastName", + "boss.title", + "boss.country", + "boss.active", + "boss.age", + "boss.boss", + "boss.primaryAddress", + "boss.addresses", + "boss.addresses.street", + "primaryAddress", + "addresses", + "addresses.street" + ); + } +} From 849085e02647d5d0cc63c9c2da98c8e959f4e6e2 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 20 Aug 2022 12:59:38 +0200 Subject: [PATCH 0694/1006] #1574: Support for annotating the generated code with custom annotations Add new `@AnnotateWith` annotation. This annotation can be used to instruct the MapStruct processor to generate custom annotations in the generated code. --- .../main/java/org/mapstruct/AnnotateWith.java | 176 +++++ .../java/org/mapstruct/AnnotateWiths.java | 31 + .../src/main/java/org/mapstruct/NullEnum.java | 15 + .../chapter-3-defining-a-mapper.asciidoc | 40 ++ .../ap/internal/gem/GemGenerator.java | 5 + .../model/AdditionalAnnotationsBuilder.java | 602 ++++++++++++++++++ .../ap/internal/model/Annotation.java | 18 +- .../ap/internal/model/BeanMappingMethod.java | 15 + .../ap/internal/model/GeneratedType.java | 7 +- .../mapstruct/ap/internal/model/Mapper.java | 11 +- .../model/annotation/AnnotationElement.java | 128 ++++ .../EnumAnnotationElementHolder.java | 35 + .../processor/JakartaComponentProcessor.java | 7 +- .../processor/Jsr330ComponentProcessor.java | 8 +- .../processor/MapperCreationProcessor.java | 6 + .../processor/MethodRetrievalProcessor.java | 198 ++---- .../processor/SpringComponentProcessor.java | 8 +- .../mapstruct/ap/internal/util/Message.java | 14 + .../internal/util/RepeatableAnnotations.java | 120 ++++ .../ap/internal/model/Annotation.ftl | 2 +- .../ap/internal/model/BeanMappingMethod.ftl | 3 + .../model/annotation/AnnotationElement.ftl | 48 ++ .../EnumAnnotationElementHolder.ftl | 9 + .../test/annotatewith/AnnotateWithEnum.java | 10 + .../test/annotatewith/AnnotateWithTest.java | 548 ++++++++++++++++ .../AnnotationWithRequiredParameter.java | 19 + .../AnnotationWithoutElementNameMapper.java | 15 + .../annotatewith/ClassMetaAnnotation.java | 20 + .../test/annotatewith/CustomAnnotation.java | 19 + .../CustomAnnotationOnlyAnnotation.java | 18 + .../CustomAnnotationWithParams.java | 64 ++ .../CustomAnnotationWithParamsContainer.java | 19 + ...omAnnotationWithTwoAnnotationElements.java | 20 + .../CustomClassOnlyAnnotation.java | 18 + .../CustomMethodOnlyAnnotation.java | 18 + .../CustomNamedGenericClassMapper.java | 22 + .../test/annotatewith/CustomNamedMapper.java | 40 ++ .../CustomRepeatableAnnotation.java | 21 + .../CustomRepeatableAnnotationContainer.java | 19 + .../DeprecateAndCustomMapper.java | 19 + ...oneousMapperWithAnnotationOnlyOnClass.java | 18 + ...usMapperWithAnnotationOnlyOnInterface.java | 18 + .../ErroneousMapperWithClassOnMethod.java | 27 + .../ErroneousMapperWithMethodOnClass.java | 18 + .../ErroneousMapperWithMethodOnInterface.java | 18 + .../ErroneousMapperWithMissingEnumClass.java | 22 + .../ErroneousMapperWithMissingEnums.java | 21 + .../ErroneousMapperWithMissingParameter.java | 18 + .../ErroneousMapperWithNonExistantEnum.java | 22 + .../ErroneousMapperWithParameterRepeat.java | 22 + ...erWithRepeatOfNotRepeatableAnnotation.java | 19 + ...neousMapperWithTooManyParameterValues.java | 21 + .../ErroneousMapperWithUnknownParameter.java | 21 + .../ErroneousMapperWithWrongParameter.java | 45 ++ .../ErroneousMultipleArrayValuesMapper.java | 31 + ...MapperWithIdenticalAnnotationRepeated.java | 19 + ...apperWithMissingAnnotationElementName.java | 21 + .../MapperWithRepeatableAnnotation.java | 19 + .../annotatewith/MetaAnnotatedMapper.java | 14 + .../annotatewith/MethodMetaAnnotation.java | 20 + .../MultipleArrayValuesMapper.java | 31 + .../annotatewith/WrongAnnotateWithEnum.java | 10 + .../annotatewith/CustomNamedMapperImpl.java | 17 + .../MultipleArrayValuesMapperImpl.java | 18 + 64 files changed, 2774 insertions(+), 151 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/AnnotateWith.java create mode 100644 core/src/main/java/org/mapstruct/AnnotateWiths.java create mode 100644 core/src/main/java/org/mapstruct/NullEnum.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/AnnotationElement.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithEnum.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithRequiredParameter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithoutElementNameMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ClassMetaAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationOnlyAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParams.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParamsContainer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithTwoAnnotationElements.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomClassOnlyAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomMethodOnlyAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedGenericClassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotationContainer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/DeprecateAndCustomMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnInterface.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnInterface.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnumClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnums.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingParameter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithNonExistantEnum.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithParameterRepeat.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithRepeatOfNotRepeatableAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithTooManyParameterValues.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithUnknownParameter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithWrongParameter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMultipleArrayValuesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithIdenticalAnnotationRepeated.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithMissingAnnotationElementName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithRepeatableAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MetaAnnotatedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MethodMetaAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/WrongAnnotateWithEnum.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/AnnotateWith.java b/core/src/main/java/org/mapstruct/AnnotateWith.java new file mode 100644 index 0000000000..090a7bc0d8 --- /dev/null +++ b/core/src/main/java/org/mapstruct/AnnotateWith.java @@ -0,0 +1,176 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.Annotation; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +/** + * This can be used to have mapstruct generate additional annotations on classes/methods. + *

    + * Examples based on the spring framework annotations. + *

    + * Marking a class as `Lazy`: + * + *
    
    + * @AnnotateWith( value = Lazy.class )
    + * @Mapper
    + * public interface FooMapper {
    + *     // mapper code
    + * }
    + * 
    + * + * The following code would be generated: + * + *
    
    + * @Lazy
    + * public class FooMapperImpl implements FooMapper {
    + *     // mapper code
    + * }
    + * 
    + * Setting the profile on the generated implementation: + * + *
    
    + * @AnnotateWith( value = Profile.class, elements = @AnnotateWith.Element( strings = "prod" ) )
    + * @Mapper
    + * public interface FooMapper {
    + *     // mapper code
    + * }
    + * 
    + * + * The following code would be generated: + * + *
    
    + * @Profile( value = "prod" )
    + * public class FooMapperImpl implements FooMapper {
    + *     // mapper code
    + * }
    + * 
    + * + * @author Ben Zegveld + * @since 1.6 + */ +@Repeatable( AnnotateWiths.class ) +@Retention( CLASS ) +@Target( { TYPE, METHOD, ANNOTATION_TYPE } ) +public @interface AnnotateWith { + /** + * @return the annotation class that needs to be added. + */ + Class value(); + + /** + * @return the annotation elements that are to be applied to this annotation. + */ + Element[] elements() default {}; + + /** + * Used in combination with {@link AnnotateWith} to configure the annotation elements. Only 1 value type may be used + * within the same annotation at a time. For example mixing shorts and ints is not allowed. + * + * @author Ben Zegveld + * @since 1.6 + */ + @interface Element { + /** + * @return name of the annotation element. + */ + String name() default "value"; + + /** + * cannot be used in conjunction with other value fields. + * + * @return short value(s) for the annotation element. + */ + short[] shorts() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return byte value(s) for the annotation element. + */ + byte[] bytes() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return int value(s) for the annotation element. + */ + int[] ints() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return long value(s) for the annotation element. + */ + long[] longs() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return float value(s) for the annotation element. + */ + float[] floats() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return double value(s) for the annotation element. + */ + double[] doubles() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return char value(s) for the annotation element. + */ + char[] chars() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return boolean value(s) for the annotation element. + */ + boolean[] booleans() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return string value(s) for the annotation element. + */ + String[] strings() default {}; + + /** + * cannot be used in conjunction with other value fields. + * + * @return class value(s) for the annotation element. + */ + Class[] classes() default {}; + + /** + * only used in conjunction with the {@link #enums()} annotation element. + * + * @return the class of the enum. + */ + Class> enumClass() default NullEnum.class; + + /** + * cannot be used in conjunction with other value fields. {@link #enumClass()} is also required when using + * {@link #enums()} + * + * @return enum value(s) for the annotation element. + */ + String[] enums() default {}; + + } +} diff --git a/core/src/main/java/org/mapstruct/AnnotateWiths.java b/core/src/main/java/org/mapstruct/AnnotateWiths.java new file mode 100644 index 0000000000..5e86ad9a19 --- /dev/null +++ b/core/src/main/java/org/mapstruct/AnnotateWiths.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.CLASS; + +/** + * This can be used to have mapstruct generate additional annotations on classes/methods. + * + * @author Ben Zegveld + * @since 1.6 + */ +@Retention( CLASS ) +@Target( { TYPE, METHOD } ) +public @interface AnnotateWiths { + + /** + * The configuration of the additional annotations. + * + * @return The configuration of the additional annotations. + */ + AnnotateWith[] value(); +} diff --git a/core/src/main/java/org/mapstruct/NullEnum.java b/core/src/main/java/org/mapstruct/NullEnum.java new file mode 100644 index 0000000000..ac39b3485d --- /dev/null +++ b/core/src/main/java/org/mapstruct/NullEnum.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +/** + * To be used as a default value for enum class annotation elements. + * + * @author Ben Zegveld + * @since 1.6 + */ +enum NullEnum { +} diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index ab33666435..e4a77f5391 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -721,3 +721,43 @@ i.e. You can map from `Map` where for each property a conversio When a raw map or a map that does not have a String as a key is used, then a warning will be generated. The warning is not generated if the map itself is mapped into some other target property directly as is. ==== + +[[adding-annotations]] +=== Adding annotations + +Other frameworks sometimes requires you to add annotations to certain classes so that they can easily detect the mappers. +Using the `@AnnotateWith` annotation you can generate an annotation at the specified location. + +For example Apache Camel has a `@Converter` annotation which you can apply to generated mappers using the `@AnnotateWith` annotation. + +.AnnotateWith source example +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +@AnnotateWith( + value = Converter.class, + elements = @AnnotateWith.Element( name = "generateBulkLoader", booleans = true ) +) +public interface MyConverter { + @AnnotateWith( Converter.class ) + DomainObject map( DtoObject dto ); +} +---- +==== + +.AnnotateWith generated mapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Converter( generateBulkLoader = true ) +public class MyConverterImpl implements MyConverter { + @Converter + public DomainObject map( DtoObject dto ) { + // default mapping behaviour + } +} +---- +==== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 70098c952e..cbb59f4e57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -9,6 +9,8 @@ import javax.xml.bind.annotation.XmlElementRef; import org.mapstruct.AfterMapping; +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWiths; import org.mapstruct.BeanMapping; import org.mapstruct.BeforeMapping; import org.mapstruct.Builder; @@ -43,6 +45,9 @@ * * @author Gunnar Morling */ +@GemDefinition(AnnotateWith.class) +@GemDefinition(AnnotateWith.Element.class) +@GemDefinition(AnnotateWiths.class) @GemDefinition(Mapper.class) @GemDefinition(Mapping.class) @GemDefinition(Mappings.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java new file mode 100644 index 0000000000..f28cdfef9c --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java @@ -0,0 +1,602 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Target; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.gem.AnnotateWithGem; +import org.mapstruct.ap.internal.gem.AnnotateWithsGem; +import org.mapstruct.ap.internal.gem.ElementGem; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; +import org.mapstruct.ap.internal.model.annotation.EnumAnnotationElementHolder; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.RepeatableAnnotations; +import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.spi.TypeHierarchyErroneousException; +import org.mapstruct.tools.gem.GemValue; + +import static javax.lang.model.util.ElementFilter.methodsIn; + +/** + * @author Ben Zegveld + * @since 1.5 + */ +public class AdditionalAnnotationsBuilder + extends RepeatableAnnotations { + private static final String ANNOTATE_WITH_FQN = "org.mapstruct.AnnotateWith"; + private static final String ANNOTATE_WITHS_FQN = "org.mapstruct.AnnotateWiths"; + + private TypeFactory typeFactory; + private FormattingMessager messager; + + public AdditionalAnnotationsBuilder(ElementUtils elementUtils, TypeFactory typeFactory, + FormattingMessager messager) { + super( elementUtils, ANNOTATE_WITH_FQN, ANNOTATE_WITHS_FQN ); + this.typeFactory = typeFactory; + this.messager = messager; + } + + @Override + protected AnnotateWithGem singularInstanceOn(Element element) { + return AnnotateWithGem.instanceOn( element ); + } + + @Override + protected AnnotateWithsGem multipleInstanceOn(Element element) { + return AnnotateWithsGem.instanceOn( element ); + } + + @Override + protected void addInstance(AnnotateWithGem gem, Element source, Set mappings) { + buildAnnotation( gem, source ).ifPresent( t -> addAndValidateMapping( mappings, source, gem, t ) ); + } + + @Override + protected void addInstances(AnnotateWithsGem gem, Element source, Set mappings) { + for ( AnnotateWithGem annotateWithGem : gem.value().get() ) { + buildAnnotation( + annotateWithGem, + source ).ifPresent( t -> addAndValidateMapping( mappings, source, annotateWithGem, t ) ); + } + } + + private void addAndValidateMapping(Set mappings, Element source, AnnotateWithGem gem, Annotation anno) { + if ( anno.getType().getTypeElement().getAnnotation( Repeatable.class ) == null ) { + if ( mappings.stream().anyMatch( existing -> existing.getType().equals( anno.getType() ) ) ) { + messager.printMessage( + source, + gem.mirror(), + Message.ANNOTATE_WITH_ANNOTATION_IS_NOT_REPEATABLE, + anno.getType().describe() ); + return; + } + } + if ( mappings.stream().anyMatch( existing -> { + return existing.getType().equals( anno.getType() ) + && existing.getProperties().equals( anno.getProperties() ); + } ) ) { + messager.printMessage( + source, + gem.mirror(), + Message.ANNOTATE_WITH_DUPLICATE, + anno.getType().describe() ); + return; + } + mappings.add( anno ); + } + + private Optional buildAnnotation(AnnotateWithGem annotationGem, Element element) { + Type annotationType = typeFactory.getType( getTypeMirror( annotationGem.value() ) ); + List eleGems = annotationGem.elements().get(); + if ( isValid( annotationType, eleGems, element, annotationGem.mirror() ) ) { + return Optional.of( new Annotation( annotationType, convertToProperties( eleGems ) ) ); + } + return Optional.empty(); + } + + private List convertToProperties(List eleGems) { + return eleGems.stream().map( gem -> convertToProperty( gem, typeFactory ) ).collect( Collectors.toList() ); + } + + private enum ConvertToProperty { + BOOLEAN( + AnnotationElementType.BOOLEAN, + (eleGem, typeFactory) -> eleGem.booleans().get(), + eleGem -> eleGem.booleans().hasValue() + ), + BYTE( + AnnotationElementType.BYTE, + (eleGem, typeFactory) -> eleGem.bytes().get(), + eleGem -> eleGem.bytes().hasValue() + ), + CHARACTER( + AnnotationElementType.CHARACTER, + (eleGem, typeFactory) -> eleGem.chars().get(), + eleGem -> eleGem.chars().hasValue() + ), + CLASSES( + AnnotationElementType.CLASS, + (eleGem, typeFactory) -> { + return eleGem.classes().get().stream().map( typeFactory::getType ).collect( Collectors.toList() ); + }, + eleGem -> eleGem.classes().hasValue() + ), + DOUBLE( + AnnotationElementType.DOUBLE, + (eleGem, typeFactory) -> eleGem.doubles().get(), + eleGem -> eleGem.doubles().hasValue() + ), + ENUM( + AnnotationElementType.ENUM, + (eleGem, typeFactory) -> { + List values = new ArrayList<>(); + for ( String enumName : eleGem.enums().get() ) { + Type type = typeFactory.getType( eleGem.enumClass().get() ); + values.add( new EnumAnnotationElementHolder( type, enumName ) ); + } + return values; + }, + eleGem -> eleGem.enums().hasValue() && eleGem.enumClass().hasValue() + ), + FLOAT( + AnnotationElementType.FLOAT, + (eleGem, typeFactory) -> eleGem.floats().get(), + eleGem -> eleGem.floats().hasValue() + ), + INT( + AnnotationElementType.INTEGER, + (eleGem, typeFactory) -> eleGem.ints().get(), + eleGem -> eleGem.ints().hasValue() + ), + LONG( + AnnotationElementType.LONG, + (eleGem, typeFactory) -> eleGem.longs().get(), + eleGem -> eleGem.longs().hasValue() + ), + SHORT( + AnnotationElementType.SHORT, + (eleGem, typeFactory) -> eleGem.shorts().get(), + eleGem -> eleGem.shorts().hasValue() + ), + STRING( + AnnotationElementType.STRING, + (eleGem, typeFactory) -> eleGem.strings().get(), + eleGem -> eleGem.strings().hasValue() + ); + + private final AnnotationElementType type; + private final BiFunction> factory; + private final Predicate usabilityChecker; + + ConvertToProperty(AnnotationElementType type, + BiFunction> factory, + Predicate usabilityChecker) { + this.type = type; + this.factory = factory; + this.usabilityChecker = usabilityChecker; + } + + AnnotationElement toProperty(ElementGem eleGem, TypeFactory typeFactory) { + return new AnnotationElement( + type, + eleGem.name().get(), + factory.apply( eleGem, typeFactory ) + ); + } + + boolean isUsable(ElementGem eleGem) { + return usabilityChecker.test( eleGem ); + } + } + + private AnnotationElement convertToProperty(ElementGem eleGem, TypeFactory typeFactory) { + for ( ConvertToProperty convertToJava : ConvertToProperty.values() ) { + if ( convertToJava.isUsable( eleGem ) ) { + return convertToJava.toProperty( eleGem, typeFactory ); + } + } + return null; + } + + private boolean isValid(Type annotationType, List eleGems, Element element, + AnnotationMirror annotationMirror) { + boolean isValid = true; + if ( !annotationIsAllowed( annotationType, element, annotationMirror ) ) { + isValid = false; + } + + List annotationElements = methodsIn( annotationType.getTypeElement() + .getEnclosedElements() ); + if ( !allRequiredElementsArePresent( annotationType, annotationElements, eleGems, element, + annotationMirror ) ) { + isValid = false; + } + if ( !allElementsAreKnownInAnnotation( annotationType, annotationElements, eleGems, element ) ) { + isValid = false; + } + if ( !allElementsAreOfCorrectType( annotationType, annotationElements, eleGems, element ) ) { + isValid = false; + } + if ( !enumConstructionIsCorrectlyUsed( eleGems, element ) ) { + isValid = false; + } + if ( !allElementsAreUnique( eleGems, element ) ) { + isValid = false; + } + return isValid; + } + + private boolean allElementsAreUnique(List eleGems, Element element) { + boolean isValid = true; + List checkedElements = new ArrayList<>(); + for ( ElementGem elementGem : eleGems ) { + String elementName = elementGem.name().get(); + if ( checkedElements.contains( elementName ) ) { + isValid = false; + messager + .printMessage( + element, + elementGem.mirror(), + Message.ANNOTATE_WITH_DUPLICATE_PARAMETER, + elementName ); + } + else { + checkedElements.add( elementName ); + } + } + return isValid; + } + + private boolean enumConstructionIsCorrectlyUsed(List eleGems, Element element) { + boolean isValid = true; + for ( ElementGem elementGem : eleGems ) { + if ( elementGem.enums().hasValue() ) { + if ( elementGem.enumClass().getValue() == null ) { + isValid = false; + messager + .printMessage( + element, + elementGem.mirror(), + Message.ANNOTATE_WITH_ENUM_CLASS_NOT_DEFINED ); + } + else { + Type type = typeFactory.getType( getTypeMirror( elementGem.enumClass() ) ); + if ( type.isEnumType() ) { + List enumConstants = type.getEnumConstants(); + for ( String enumName : elementGem.enums().get() ) { + if ( !enumConstants.contains( enumName ) ) { + isValid = false; + messager + .printMessage( + element, + elementGem.mirror(), + elementGem.enums().getAnnotationValue(), + Message.ANNOTATE_WITH_ENUM_VALUE_DOES_NOT_EXIST, + type.describe(), + enumName ); + } + } + } + } + } + else if ( elementGem.enumClass().getValue() != null ) { + isValid = false; + messager.printMessage( element, elementGem.mirror(), Message.ANNOTATE_WITH_ENUMS_NOT_DEFINED ); + } + } + return isValid; + } + + private boolean annotationIsAllowed(Type annotationType, Element element, AnnotationMirror annotationMirror) { + Target target = annotationType.getTypeElement().getAnnotation( Target.class ); + if ( target == null ) { + return true; + } + + Set annotationTargets = Stream.of( target.value() ) + // The eclipse compiler returns null for some values + // Therefore, we filter out null values + .filter( Objects::nonNull ) + .collect( Collectors.toCollection( () -> EnumSet.noneOf( ElementType.class ) ) ); + + boolean isValid = true; + if ( isTypeTarget( element ) && !annotationTargets.contains( ElementType.TYPE ) ) { + isValid = false; + messager.printMessage( + element, + annotationMirror, + Message.ANNOTATE_WITH_NOT_ALLOWED_ON_CLASS, + annotationType.describe() + ); + } + if ( isMethodTarget( element ) && !annotationTargets.contains( ElementType.METHOD ) ) { + isValid = false; + messager.printMessage( + element, + annotationMirror, + Message.ANNOTATE_WITH_NOT_ALLOWED_ON_METHODS, + annotationType.describe() + ); + } + return isValid; + } + + private boolean isTypeTarget(Element element) { + return element.getKind().isInterface() || element.getKind().isClass(); + } + + private boolean isMethodTarget(Element element) { + return element.getKind() == ElementKind.METHOD; + } + + private boolean allElementsAreKnownInAnnotation(Type annotationType, List annotationParameters, + List eleGems, Element element) { + Set allowedAnnotationParameters = annotationParameters.stream() + .map( ee -> ee.getSimpleName().toString() ) + .collect( Collectors.toSet() ); + boolean isValid = true; + for ( ElementGem eleGem : eleGems ) { + if ( eleGem.name().isValid() + && !allowedAnnotationParameters.contains( eleGem.name().get() ) ) { + isValid = false; + messager + .printMessage( + element, + eleGem.mirror(), + eleGem.name().getAnnotationValue(), + Message.ANNOTATE_WITH_UNKNOWN_PARAMETER, + eleGem.name().get(), + annotationType.describe(), + Strings.getMostSimilarWord( eleGem.name().get(), allowedAnnotationParameters ) + ); + } + } + return isValid; + } + + private boolean allRequiredElementsArePresent(Type annotationType, List annotationParameters, + List elements, Element element, + AnnotationMirror annotationMirror) { + + boolean valid = true; + for ( ExecutableElement annotationParameter : annotationParameters ) { + if ( annotationParameter.getDefaultValue() == null ) { + // Mandatory parameter, must be present in the elements + String parameterName = annotationParameter.getSimpleName().toString(); + boolean elementGemDefined = false; + for ( ElementGem elementGem : elements ) { + if ( elementGem.isValid() && elementGem.name().get().equals( parameterName ) ) { + elementGemDefined = true; + break; + } + } + + if ( !elementGemDefined ) { + valid = false; + messager + .printMessage( + element, + annotationMirror, + Message.ANNOTATE_WITH_MISSING_REQUIRED_PARAMETER, + parameterName, + annotationType.describe() + ); + } + } + } + + + return valid; + } + + private boolean allElementsAreOfCorrectType(Type annotationType, List annotationParameters, + List elements, + Element element) { + Map annotationParametersByName = + annotationParameters.stream() + .collect( Collectors.toMap( ee -> ee.getSimpleName().toString(), Function.identity() ) ); + boolean isValid = true; + for ( ElementGem eleGem : elements ) { + Type annotationParameterType = getAnnotationParameterType( annotationParametersByName, eleGem ); + Type annotationParameterTypeSingular = getNonArrayType( annotationParameterType ); + if ( annotationParameterTypeSingular == null ) { + continue; + } + if ( hasTooManyDifferentTypes( eleGem ) ) { + isValid = false; + messager.printMessage( + element, + eleGem.mirror(), + eleGem.name().getAnnotationValue(), + Message.ANNOTATE_WITH_TOO_MANY_VALUE_TYPES, + eleGem.name().get(), + annotationParameterType.describe(), + annotationType.describe() + ); + } + else { + Map elementTypes = getParameterTypes( eleGem ); + Set reportedSizeError = new HashSet<>(); + for ( Type eleGemType : elementTypes.keySet() ) { + if ( !sameTypeOrAssignableClass( annotationParameterTypeSingular, eleGemType ) ) { + isValid = false; + messager.printMessage( + element, + eleGem.mirror(), + eleGem.name().getAnnotationValue(), + Message.ANNOTATE_WITH_WRONG_PARAMETER, + eleGem.name().get(), + eleGemType.describe(), + annotationParameterType.describe(), + annotationType.describe() + ); + } + else if ( !annotationParameterType.isArrayType() + && elementTypes.get( eleGemType ) > 1 + && !reportedSizeError.contains( eleGem ) ) { + isValid = false; + messager.printMessage( + element, + eleGem.mirror(), + Message.ANNOTATE_WITH_PARAMETER_ARRAY_NOT_EXPECTED, + eleGem.name().get(), + annotationType.describe() + ); + reportedSizeError.add( eleGem ); + } + } + } + } + return isValid; + } + + private boolean hasTooManyDifferentTypes( ElementGem eleGem ) { + return Arrays.stream( ConvertToProperty.values() ) + .filter( anotationElement -> anotationElement.isUsable( eleGem ) ) + .count() > 1; + } + + private Type getNonArrayType(Type annotationParameterType) { + if ( annotationParameterType == null ) { + return null; + } + if ( annotationParameterType.isArrayType() ) { + return annotationParameterType.getComponentType(); + } + + return annotationParameterType; + } + + private boolean sameTypeOrAssignableClass(Type annotationParameterType, Type eleGemType) { + return annotationParameterType.equals( eleGemType ) + || eleGemType.isAssignableTo( getTypeBound( annotationParameterType ) ); + } + + private Type getTypeBound(Type annotationParameterType) { + List typeParameters = annotationParameterType.getTypeParameters(); + if ( typeParameters.size() != 1 ) { + return annotationParameterType; + } + return typeParameters.get( 0 ).getTypeBound(); + } + + private Map getParameterTypes(ElementGem eleGem) { + Map suppliedParameterTypes = new HashMap<>(); + if ( eleGem.booleans().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( boolean.class ), + eleGem.booleans().get().size() ); + } + if ( eleGem.bytes().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( byte.class ), + eleGem.bytes().get().size() ); + } + if ( eleGem.chars().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( char.class ), + eleGem.chars().get().size() ); + } + if ( eleGem.classes().hasValue() ) { + for ( TypeMirror mirror : eleGem.classes().get() ) { + suppliedParameterTypes.put( + typeFactory.getType( typeMirrorFromAnnotation( mirror ) ), + eleGem.classes().get().size() + ); + } + } + if ( eleGem.doubles().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( double.class ), + eleGem.doubles().get().size() ); + } + if ( eleGem.floats().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( float.class ), + eleGem.floats().get().size() ); + } + if ( eleGem.ints().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( int.class ), + eleGem.ints().get().size() ); + } + if ( eleGem.longs().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( long.class ), + eleGem.longs().get().size() ); + } + if ( eleGem.shorts().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( short.class ), + eleGem.shorts().get().size() ); + } + if ( eleGem.strings().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( String.class ), + eleGem.strings().get().size() ); + } + if ( eleGem.enums().hasValue() && eleGem.enumClass().hasValue() ) { + suppliedParameterTypes.put( + typeFactory.getType( getTypeMirror( eleGem.enumClass() ) ), + eleGem.enums().get().size() ); + } + return suppliedParameterTypes; + } + + private Type getAnnotationParameterType(Map annotationParameters, + ElementGem element) { + if ( annotationParameters.containsKey( element.name().get() ) ) { + return typeFactory.getType( annotationParameters.get( element.name().get() ).getReturnType() ); + } + else { + return null; + } + } + + private TypeMirror getTypeMirror(GemValue gemValue) { + return typeMirrorFromAnnotation( gemValue.getValue() ); + } + + private TypeMirror typeMirrorFromAnnotation(TypeMirror typeMirror) { + if ( typeMirror == null ) { + // When a class used in an annotation is created by another annotation processor + // then javac will not return correct TypeMirror with TypeKind#ERROR, but rather a string "" + // the gem tools would return a null TypeMirror in that case. + // Therefore, throw TypeHierarchyErroneousException so we can postpone the generation of the mapper + throw new TypeHierarchyErroneousException( typeMirror ); + } + + return typeMirror; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java index 405958ccdf..866012c51a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Annotation.java @@ -6,9 +6,11 @@ package org.mapstruct.ap.internal.model; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Type; @@ -21,16 +23,13 @@ public class Annotation extends ModelElement { private final Type type; - /** - * List of annotation attributes. Quite simplistic, but it's sufficient for now. - */ - private List properties; + private List properties; public Annotation(Type type) { this( type, Collections.emptyList() ); } - public Annotation(Type type, List properties) { + public Annotation(Type type, List properties) { this.type = type; this.properties = properties; } @@ -41,10 +40,15 @@ public Type getType() { @Override public Set getImportTypes() { - return Collections.singleton( type ); + Set types = new HashSet<>(); + for ( AnnotationElement prop : properties ) { + types.addAll( prop.getImportTypes() ); + } + types.add( type ); + return types; } - public List getProperties() { + public List getProperties() { return properties; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d17718370d..e748c173af 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -85,6 +85,7 @@ */ public class BeanMappingMethod extends NormalTypeMappingMethod { + private final List annotations; private final List propertyMappings; private final Map> mappingsByParameter; private final Map> constructorMappingsByParameter; @@ -112,6 +113,7 @@ public static class Builder extends AbstractMappingMethodBuilder unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); + private final List annotations = new ArrayList<>(); private MappingReferences mappingReferences; private MethodReference factoryMethod; @@ -214,6 +216,12 @@ else if ( !method.isUpdateMethod() ) { // If the return type cannot be constructed then no need to try to create mappings return null; } + AdditionalAnnotationsBuilder additionalAnnotationsBuilder = + new AdditionalAnnotationsBuilder( + ctx.getElementUtils(), + ctx.getTypeFactory(), + ctx.getMessager() ); + annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; @@ -362,6 +370,7 @@ else if ( !method.isUpdateMethod() ) { return new BeanMappingMethod( method, + annotations, existingVariableNames, propertyMappings, factoryMethod, @@ -1701,6 +1710,7 @@ private ConstructorAccessor( //CHECKSTYLE:OFF private BeanMappingMethod(Method method, + List annotations, Collection existingVariableNames, List propertyMappings, MethodReference factoryMethod, @@ -1722,6 +1732,7 @@ private BeanMappingMethod(Method method, ); //CHECKSTYLE:ON + this.annotations = annotations; this.propertyMappings = propertyMappings; this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; @@ -1760,6 +1771,10 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { this.subclassMappings = subclassMappings; } + public List getAnnotations() { + return annotations; + } + public List getConstantMappings() { return constantMappings; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 134ab081dc..f8f65c927f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -10,15 +10,14 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; - import javax.lang.model.type.TypeKind; -import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.version.VersionInformation; @@ -220,7 +219,9 @@ public SortedSet getImportTypes() { } for ( Annotation annotation : annotations ) { - addIfImportRequired( importedTypes, annotation.getType() ); + for ( Type type : annotation.getImportTypes() ) { + addIfImportRequired( importedTypes, type ); + } } for ( Type extraImport : extraImportedTypes ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index fa15cd8ed0..9b7729e8fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Set; import java.util.SortedSet; - import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; @@ -43,6 +42,7 @@ public static class Builder extends GeneratedTypeBuilder { private String implPackage; private boolean customPackage; private boolean suppressGeneratorTimestamp; + private Set customAnnotations; public Builder() { super( Builder.class ); @@ -63,6 +63,11 @@ public Builder constructorFragments(Set fragment return this; } + public Builder additionalAnnotations(Set customAnnotations) { + this.customAnnotations = customAnnotations; + return this; + } + public Builder decorator(Decorator decorator) { this.decorator = decorator; return this; @@ -105,6 +110,7 @@ public Mapper build() { definitionType, customPackage, customName, + customAnnotations, methods, options, versionInformation, @@ -126,7 +132,7 @@ public Mapper build() { @SuppressWarnings( "checkstyle:parameternumber" ) private Mapper(TypeFactory typeFactory, String packageName, String name, Type mapperDefinitionType, - boolean customPackage, boolean customImplName, + boolean customPackage, boolean customImplName, Set customAnnotations, List methods, Options options, VersionInformation versionInformation, boolean suppressGeneratorTimestamp, Accessibility accessibility, List fields, Constructor constructor, @@ -148,6 +154,7 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, ); this.customPackage = customPackage; this.customImplName = customImplName; + customAnnotations.forEach( this::addAnnotation ); this.decorator = decorator; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java new file mode 100644 index 0000000000..6ecde886bf --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java @@ -0,0 +1,128 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.annotation; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Ben Zegveld + */ +public class AnnotationElement extends ModelElement { + public enum AnnotationElementType { + BOOLEAN, BYTE, CHARACTER, CLASS, DOUBLE, ENUM, FLOAT, INTEGER, LONG, SHORT, STRING + } + + private final String elementName; + private final List values; + private final AnnotationElementType type; + + public AnnotationElement(AnnotationElementType type, List values) { + this( type, null, values ); + } + + public AnnotationElement(AnnotationElementType type, String elementName, List values) { + this.type = type; + this.elementName = elementName; + this.values = values; + } + + public String getElementName() { + return elementName; + } + + public List getValues() { + return values; + } + + @Override + public Set getImportTypes() { + Set importTypes = null; + for ( Object value : values ) { + if ( value instanceof ModelElement ) { + if ( importTypes == null ) { + importTypes = new HashSet<>(); + } + importTypes.addAll( ( (ModelElement) value ).getImportTypes() ); + } + } + + return importTypes == null ? Collections.emptySet() : importTypes; + } + + public boolean isBoolean() { + return type == AnnotationElementType.BOOLEAN; + } + + public boolean isByte() { + return type == AnnotationElementType.BYTE; + } + + public boolean isCharacter() { + return type == AnnotationElementType.CHARACTER; + } + + public boolean isClass() { + return type == AnnotationElementType.CLASS; + } + + public boolean isDouble() { + return type == AnnotationElementType.DOUBLE; + } + + public boolean isEnum() { + return type == AnnotationElementType.ENUM; + } + + public boolean isFloat() { + return type == AnnotationElementType.FLOAT; + } + + public boolean isInteger() { + return type == AnnotationElementType.INTEGER; + } + + public boolean isLong() { + return type == AnnotationElementType.LONG; + } + + public boolean isShort() { + return type == AnnotationElementType.SHORT; + } + + public boolean isString() { + return type == AnnotationElementType.STRING; + } + + @Override + public int hashCode() { + return Objects.hash( elementName, type, values ); + } + + @Override + public boolean equals(Object obj) { + if ( this == obj ) { + return true; + } + if ( obj == null ) { + return false; + } + if ( getClass() != obj.getClass() ) { + return false; + } + AnnotationElement other = (AnnotationElement) obj; + return Objects.equals( elementName, other.elementName ) + && type == other.type + && Objects.equals( values, other.values ); + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.java new file mode 100644 index 0000000000..de87f32525 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.annotation; + +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; + +public class EnumAnnotationElementHolder extends ModelElement { + + private final Type enumClass; + private final String name; + + public EnumAnnotationElementHolder(Type enumClass, String name) { + this.enumClass = enumClass; + this.name = name; + } + + public Type getEnumClass() { + return enumClass; + } + + public String getName() { + return name; + } + + @Override + public Set getImportTypes() { + return enumClass.getImportTypes(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java index 5161ea689c..999c0a51df 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; /** * A {@link ModelElementProcessor} which converts the given {@link Mapper} @@ -67,7 +69,10 @@ private Annotation named() { private Annotation namedDelegate(Mapper mapper) { return new Annotation( getTypeFactory().getType( "jakarta.inject.Named" ), - Collections.singletonList( '"' + mapper.getPackageName() + "." + mapper.getName() + '"' ) + Collections.singletonList( + new AnnotationElement( AnnotationElementType.STRING, + Collections.singletonList( mapper.getPackageName() + "." + mapper.getName() ) + ) ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java index 6a6cc16580..00ba72a079 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.util.AnnotationProcessingException; @@ -70,7 +72,11 @@ private Annotation named() { private Annotation namedDelegate(Mapper mapper) { return new Annotation( getType( "Named" ), - Collections.singletonList( '"' + mapper.getPackageName() + "." + mapper.getName() + '"' ) + Collections.singletonList( + new AnnotationElement( + AnnotationElementType.STRING, + Collections.singletonList( mapper.getPackageName() + "." + mapper.getName() ) + ) ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index d8acb10398..c05d2d18bd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.gem.MapperGem; import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.model.AdditionalAnnotationsBuilder; import org.mapstruct.ap.internal.model.BeanMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder; @@ -93,6 +94,8 @@ public class MapperCreationProcessor implements ModelElementProcessor sourceModel) { this.elementUtils = context.getElementUtils(); @@ -103,6 +106,8 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L this.versionInformation = context.getVersionInformation(); this.typeFactory = context.getTypeFactory(); this.accessorNaming = context.getAccessorNaming(); + additionalAnnotationsBuilder = + new AdditionalAnnotationsBuilder( elementUtils, typeFactory, messager ); MapperOptions mapperOptions = MapperOptions.getInstanceOn( mapperTypeElement, context.getOptions() ); List mapperReferences = initReferencedMappers( mapperTypeElement, mapperOptions ); @@ -206,6 +211,7 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< .implName( mapperOptions.implementationName() ) .implPackage( mapperOptions.implementationPackage() ) .suppressGeneratorTimestamp( mapperOptions.suppressTimestampInGenerated() ) + .additionalAnnotations( additionalAnnotationsBuilder.getProcessedAnnotations( element ) ) .build(); if ( !mappingContext.getForgedMethodsUnderCreation().isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 201f1a1f22..bda33b6a92 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -8,13 +8,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; -import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; @@ -54,9 +51,9 @@ import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.RepeatableAnnotations; import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumTransformationStrategy; -import org.mapstruct.tools.gem.Gem; /** * A {@link ModelElementProcessor} which retrieves a list of {@link SourceMethod}s @@ -68,8 +65,6 @@ */ public class MethodRetrievalProcessor implements ModelElementProcessor> { - private static final String JAVA_LANG_ANNOTATION_PGK = "java.lang.annotation"; - private static final String ORG_MAPSTRUCT_PKG = "org.mapstruct"; private static final String MAPPING_FQN = "org.mapstruct.Mapping"; private static final String MAPPINGS_FQN = "org.mapstruct.Mappings"; private static final String SUB_CLASS_MAPPING_FQN = "org.mapstruct.SubclassMapping"; @@ -280,8 +275,7 @@ private SourceMethod getMethodRequiringImplementation(ExecutableType methodType, typeUtils, typeFactory ); - RepeatableMappings repeatableMappings = new RepeatableMappings(); - Set mappingOptions = repeatableMappings.getMappings( method, beanMappingOptions ); + Set mappingOptions = getMappings( method, beanMappingOptions ); IterableMappingOptions iterableMappingOptions = IterableMappingOptions.fromGem( IterableMappingGem.instanceOn( method ), @@ -593,7 +587,7 @@ private boolean isStreamTypeOrIterableFromJavaStdLib(Type type) { * @return The mappings for the given method, keyed by target property name */ private Set getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { - return new RepeatableMappings().getMappings( method, beanMapping ); + return new RepeatableMappings( beanMapping ).getProcessedAnnotations( method ); } /** @@ -607,173 +601,107 @@ private Set getMappings(ExecutableElement method, BeanMappingOpt private Set getSubclassMappings(List sourceParameters, Type resultType, ExecutableElement method, BeanMappingOptions beanMapping, SubclassValidator validator) { - return new RepeatableSubclassMappings( sourceParameters, resultType, validator ) - .getMappings( method, beanMapping ); + return new RepeatableSubclassMappings( beanMapping, sourceParameters, resultType, validator ) + .getProcessedAnnotations( method ); } - private class RepeatableMappings extends RepeatableMappingAnnotations { - RepeatableMappings() { - super( MAPPING_FQN, MAPPINGS_FQN ); + private class RepeatableMappings extends RepeatableAnnotations { + private BeanMappingOptions beanMappingOptions; + + RepeatableMappings(BeanMappingOptions beanMappingOptions) { + super( elementUtils, MAPPING_FQN, MAPPINGS_FQN ); + this.beanMappingOptions = beanMappingOptions; } @Override - MappingGem singularInstanceOn(Element element) { + protected MappingGem singularInstanceOn(Element element) { return MappingGem.instanceOn( element ); } @Override - MappingsGem multipleInstanceOn(Element element) { + protected MappingsGem multipleInstanceOn(Element element) { return MappingsGem.instanceOn( element ); } @Override - void addInstance(MappingGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings) { - MappingOptions.addInstance( gem, method, beanMappingOptions, messager, typeUtils, mappings ); + protected void addInstance(MappingGem gem, Element method, Set mappings) { + MappingOptions.addInstance( + gem, + (ExecutableElement) method, + beanMappingOptions, + messager, + typeUtils, + mappings ); } @Override - void addInstances(MappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings) { - MappingOptions.addInstances( gem, method, beanMappingOptions, messager, typeUtils, mappings ); + protected void addInstances(MappingsGem gem, Element method, Set mappings) { + MappingOptions.addInstances( + gem, + (ExecutableElement) method, + beanMappingOptions, + messager, + typeUtils, + mappings ); } } private class RepeatableSubclassMappings - extends RepeatableMappingAnnotations { + extends RepeatableAnnotations { private final List sourceParameters; private final Type resultType; private SubclassValidator validator; + private BeanMappingOptions beanMappingOptions; - RepeatableSubclassMappings(List sourceParameters, Type resultType, SubclassValidator validator) { - super( SUB_CLASS_MAPPING_FQN, SUB_CLASS_MAPPINGS_FQN ); + RepeatableSubclassMappings(BeanMappingOptions beanMappingOptions, List sourceParameters, + Type resultType, SubclassValidator validator) { + super( elementUtils, SUB_CLASS_MAPPING_FQN, SUB_CLASS_MAPPINGS_FQN ); + this.beanMappingOptions = beanMappingOptions; this.sourceParameters = sourceParameters; this.resultType = resultType; this.validator = validator; } @Override - SubclassMappingGem singularInstanceOn(Element element) { + protected SubclassMappingGem singularInstanceOn(Element element) { return SubclassMappingGem.instanceOn( element ); } @Override - SubclassMappingsGem multipleInstanceOn(Element element) { + protected SubclassMappingsGem multipleInstanceOn(Element element) { return SubclassMappingsGem.instanceOn( element ); } @Override - void addInstance(SubclassMappingGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings) { - SubclassMappingOptions - .addInstance( - gem, - method, - beanMappingOptions, - messager, - typeUtils, - mappings, - sourceParameters, - resultType, - validator ); + protected void addInstance(SubclassMappingGem gem, + Element method, + Set mappings) { + SubclassMappingOptions.addInstance( + gem, + (ExecutableElement) method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType, + validator ); } @Override - void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings) { - SubclassMappingOptions - .addInstances( - gem, - method, - beanMappingOptions, - messager, - typeUtils, - mappings, - sourceParameters, - resultType, - validator ); - } - } - - private abstract class RepeatableMappingAnnotations { - - private final String singularFqn; - private final String multipleFqn; - - RepeatableMappingAnnotations(String singularFqn, String multipleFqn) { - this.singularFqn = singularFqn; - this.multipleFqn = multipleFqn; - } - - abstract SINGULAR singularInstanceOn(Element element); - - abstract MULTIPLE multipleInstanceOn(Element element); - - abstract void addInstance(SINGULAR gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings); - - abstract void addInstances(MULTIPLE gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, - Set mappings); - - /** - * Retrieves the mappings configured via {@code @Mapping} from the given method. - * - * @param method The method of interest - * @param beanMapping options coming from bean mapping method - * @return The mappings for the given method, keyed by target property name - */ - public Set getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { - return getMappings( method, method, beanMapping, new LinkedHashSet<>(), new HashSet<>() ); - } - - /** - * Retrieves the mappings configured via {@code @Mapping} from the given method. - * - * @param method The method of interest - * @param element Element of interest: method, or (meta) annotation - * @param beanMapping options coming from bean mapping method - * @param mappingOptions LinkedSet of mappings found so far - * @return The mappings for the given method, keyed by target property name - */ - private Set getMappings(ExecutableElement method, Element element, - BeanMappingOptions beanMapping, LinkedHashSet mappingOptions, - Set handledElements) { - - for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { - Element lElement = annotationMirror.getAnnotationType().asElement(); - if ( isAnnotation( lElement, singularFqn ) ) { - // although getInstanceOn does a search on annotation mirrors, the order is preserved - SINGULAR mapping = singularInstanceOn( element ); - addInstance( mapping, method, beanMapping, mappingOptions ); - } - else if ( isAnnotation( lElement, multipleFqn ) ) { - // although getInstanceOn does a search on annotation mirrors, the order is preserved - MULTIPLE mappings = multipleInstanceOn( element ); - addInstances( mappings, method, beanMapping, mappingOptions ); - } - else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) - && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG ) - && !handledElements.contains( lElement ) ) { - // recur over annotation mirrors - handledElements.add( lElement ); - getMappings( method, lElement, beanMapping, mappingOptions, handledElements ); - } - } - return mappingOptions; - } - - private boolean isAnnotationInPackage(Element element, String packageFQN) { - if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { - return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); - } - return false; - } - - private boolean isAnnotation(Element element, String annotationFQN) { - if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { - return annotationFQN.equals( ( (TypeElement) element ).getQualifiedName().toString() ); - } - return false; + protected void addInstances(SubclassMappingsGem gem, + Element method, + Set mappings) { + SubclassMappingOptions.addInstances( + gem, + (ExecutableElement) method, + beanMappingOptions, + messager, + typeUtils, + mappings, + sourceParameters, + resultType, + validator ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index f7aa9b4fea..4efc537c3d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -13,6 +13,8 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement; +import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; /** * A {@link ModelElementProcessor} which converts the given {@link Mapper} @@ -75,7 +77,11 @@ private Annotation autowired() { private Annotation qualifierDelegate() { return new Annotation( getTypeFactory().getType( "org.springframework.beans.factory.annotation.Qualifier" ), - Collections.singletonList( "\"delegate\"" ) ); + Collections.singletonList( + new AnnotationElement( + AnnotationElementType.STRING, + Collections.singletonList( "delegate" ) + ) ) ); } private Annotation primary() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4e1c0302fa..92951ad521 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -198,6 +198,20 @@ public enum Message { MAPTOBEANMAPPING_WRONG_KEY_TYPE( "The Map parameter \"%s\" cannot be used for property mapping. It must be typed with Map but it was typed with %s.", Diagnostic.Kind.WARNING ), MAPTOBEANMAPPING_RAW_MAP( "The Map parameter \"%s\" cannot be used for property mapping. It must be typed with Map but it was raw.", Diagnostic.Kind.WARNING ), + + ANNOTATE_WITH_MISSING_REQUIRED_PARAMETER( "Parameter \"%s\" is required for annotation \"%s\"." ), + ANNOTATE_WITH_UNKNOWN_PARAMETER( "Unknown parameter \"%s\" for annotation \"%s\". Did you mean \"%s\"?" ), + ANNOTATE_WITH_DUPLICATE_PARAMETER( "Parameter \"%s\" must not be defined more than once." ), + ANNOTATE_WITH_WRONG_PARAMETER( "Parameter \"%s\" is not of type \"%s\" but of type \"%s\" for annotation \"%s\"." ), + ANNOTATE_WITH_TOO_MANY_VALUE_TYPES( "Parameter \"%s\" has too many value types supplied, type \"%s\" is expected for annotation \"%s\"." ), + ANNOTATE_WITH_PARAMETER_ARRAY_NOT_EXPECTED( "Parameter \"%s\" does not accept multiple values for annotation \"%s\"." ), + ANNOTATE_WITH_NOT_ALLOWED_ON_CLASS( "Annotation \"%s\" is not allowed on classes." ), + ANNOTATE_WITH_NOT_ALLOWED_ON_METHODS( "Annotation \"%s\" is not allowed on methods." ), + ANNOTATE_WITH_ENUM_VALUE_DOES_NOT_EXIST( "Enum \"%s\" does not have value \"%s\"." ), + ANNOTATE_WITH_ENUM_CLASS_NOT_DEFINED( "enumClass needs to be defined when using enums." ), + ANNOTATE_WITH_ENUMS_NOT_DEFINED( "enums needs to be defined when using enumClass." ), + ANNOTATE_WITH_ANNOTATION_IS_NOT_REPEATABLE( "Annotation \"%s\" is not repeatable." ), + ANNOTATE_WITH_DUPLICATE( "Annotation \"%s\" is already present with the same elements configuration.", Diagnostic.Kind.WARNING ), ; // CHECKSTYLE:ON diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java new file mode 100644 index 0000000000..accae77718 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java @@ -0,0 +1,120 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; + +import org.mapstruct.tools.gem.Gem; + +/** + * @author Ben Zegveld + */ +public abstract class RepeatableAnnotations { + private static final String JAVA_LANG_ANNOTATION_PGK = "java.lang.annotation"; + private static final String ORG_MAPSTRUCT_PKG = "org.mapstruct"; + + private ElementUtils elementUtils; + private final String singularFqn; + private final String multipleFqn; + + protected RepeatableAnnotations(ElementUtils elementUtils, String singularFqn, String multipleFqn) { + this.elementUtils = elementUtils; + this.singularFqn = singularFqn; + this.multipleFqn = multipleFqn; + } + + /** + * @param element the element on which the Gem needs to be found + * @return the Gem found on the element. + */ + protected abstract SINGULAR singularInstanceOn(Element element); + + /** + * @param element the element on which the Gems needs to be found + * @return the Gems found on the element. + */ + protected abstract MULTIPLE multipleInstanceOn(Element element); + + /** + * @param gem the annotation gem to be processed + * @param source the source element where the request originated from + * @param mappings the collection of completed processing + */ + protected abstract void addInstance(SINGULAR gem, Element source, Set mappings); + + /** + * @param gems the annotation gems to be processed + * @param source the source element where the request originated from + * @param mappings the collection of completed processing + */ + protected abstract void addInstances(MULTIPLE gems, Element source, Set mappings); + + /** + * Retrieves the processed annotations. + * + * @param source The source element of interest + * @return The processed annotations for the given element + */ + public Set getProcessedAnnotations(Element source) { + return getMappings( source, source, new LinkedHashSet<>(), new HashSet<>() ); + } + + /** + * Retrieves the processed annotations. + * + * @param source The source element of interest + * @param element Element of interest: method, or (meta) annotation + * @param mappingOptions LinkedSet of mappings found so far + * @param handledElements The collection of already handled elements to handle recursion correctly. + * @return The processed annotations for the given element + */ + private Set getMappings(Element source, Element element, + LinkedHashSet mappingOptions, + Set handledElements) { + + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + Element lElement = annotationMirror.getAnnotationType().asElement(); + if ( isAnnotation( lElement, singularFqn ) ) { + // although getInstanceOn does a search on annotation mirrors, the order is preserved + SINGULAR mapping = singularInstanceOn( element ); + addInstance( mapping, source, mappingOptions ); + } + else if ( isAnnotation( lElement, multipleFqn ) ) { + // although getInstanceOn does a search on annotation mirrors, the order is preserved + MULTIPLE mappings = multipleInstanceOn( element ); + addInstances( mappings, source, mappingOptions ); + } + else if ( !isAnnotationInPackage( lElement, JAVA_LANG_ANNOTATION_PGK ) + && !isAnnotationInPackage( lElement, ORG_MAPSTRUCT_PKG ) + && !handledElements.contains( lElement ) ) { + // recur over annotation mirrors + handledElements.add( lElement ); + getMappings( source, lElement, mappingOptions, handledElements ); + } + } + return mappingOptions; + } + + private boolean isAnnotationInPackage(Element element, String packageFQN) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return packageFQN.equals( elementUtils.getPackageOf( element ).getQualifiedName().toString() ); + } + return false; + } + + private boolean isAnnotation(Element element, String annotationFQN) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return annotationFQN.equals( ( (TypeElement) element ).getQualifiedName().toString() ); + } + return false; + } +} diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index 4391bcb975..eb67d732fc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> -@<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property>${property}<#if property_has_next>, ) \ No newline at end of file +@<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property><@includeModel object=property/><#if property_has_next>, ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 81e3b61fd7..1b402a57f0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -6,6 +6,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.BeanMappingMethod" --> +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#assign targetType = resultType /> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/AnnotationElement.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/AnnotationElement.ftl new file mode 100644 index 0000000000..21c1977f58 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/AnnotationElement.ftl @@ -0,0 +1,48 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.annotation.AnnotationElement" --> +<@compress single_line=true> + <#if elementName??> + ${elementName} = + + <#if (values?size > 1) > + { + + <#-- rt and lt tags below are for formatting the arrays so that there are no spaces before ',' --> + <#list values as value> + <#if boolean> + ${value?c}<#rt> + <#elseif byte> + ${value}<#rt> + <#elseif character> + '${value}'<#rt> + <#elseif class> + <@includeModel object=value raw=true/>.class<#rt> + <#elseif double> + ${value?c}<#rt> + <#elseif enum> + <@includeModel object=value/><#rt> + <#elseif float> + ${value?c}f<#rt> + <#elseif integer> + ${value?c}<#rt> + <#elseif long> + ${value?c}L<#rt> + <#elseif short> + ${value?c}<#rt> + <#elseif string> + "${value}"<#rt> + + <#if value_has_next> + , <#lt> + + + <#if (values?size > 1) > + } + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.ftl new file mode 100644 index 0000000000..145b933156 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/annotation/EnumAnnotationElementHolder.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.annotation.EnumAnnotationElementHolder" --> +<@includeModel object=enumClass raw=true/>.${name}<#rt> \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithEnum.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithEnum.java new file mode 100644 index 0000000000..b2627fd8ce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithEnum.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +public enum AnnotateWithEnum { + EXISTING, OTHER_EXISTING +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java new file mode 100644 index 0000000000..c2055b4c5c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java @@ -0,0 +1,548 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.junit.jupiter.api.extension.RegisterExtension; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Ben Zegveld + */ +@IssueKey("1574") +@WithClasses(AnnotateWithEnum.class) +public class AnnotateWithTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses({ DeprecateAndCustomMapper.class, CustomAnnotation.class }) + public void mapperBecomesDeprecatedAndGetsCustomAnnotation() { + DeprecateAndCustomMapper mapper = Mappers.getMapper( DeprecateAndCustomMapper.class ); + + assertThat( mapper.getClass() ).hasAnnotations( Deprecated.class, CustomAnnotation.class ); + } + + @ProcessorTest + @WithClasses( { CustomNamedMapper.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void annotationWithValue() { + generatedSource.addComparisonToFixtureFor( CustomNamedMapper.class ); + } + + @ProcessorTest + @WithClasses( { MultipleArrayValuesMapper.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void annotationWithMultipleValues() { + generatedSource.addComparisonToFixtureFor( MultipleArrayValuesMapper.class ); + } + + @ProcessorTest + @WithClasses( { CustomNamedGenericClassMapper.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void annotationWithCorrectGenericClassValue() { + CustomNamedGenericClassMapper mapper = Mappers.getMapper( CustomNamedGenericClassMapper.class ); + + CustomAnnotationWithParams annotation = mapper.getClass().getAnnotation( CustomAnnotationWithParams.class ); + assertThat( annotation ).isNotNull(); + assertThat( annotation.stringParam() ).isEqualTo( "test" ); + assertThat( annotation.genericTypedClass() ).isEqualTo( Mapper.class ); + } + + @ProcessorTest + @WithClasses( { AnnotationWithoutElementNameMapper.class, CustomAnnotation.class } ) + public void annotateWithoutElementName() { + generatedSource + .forMapper( AnnotationWithoutElementNameMapper.class ) + .content() + .contains( "@CustomAnnotation(value = \"value\")" ); + } + + @ProcessorTest + @WithClasses({ MetaAnnotatedMapper.class, ClassMetaAnnotation.class, CustomClassOnlyAnnotation.class }) + public void metaAnnotationWorks() { + MetaAnnotatedMapper mapper = Mappers.getMapper( MetaAnnotatedMapper.class ); + + assertThat( mapper.getClass() ).hasAnnotation( CustomClassOnlyAnnotation.class ); + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithMissingParameter.class, + line = 15, + message = "Parameter \"required\" is required for annotation \"AnnotationWithRequiredParameter\"." + ) + } + ) + @WithClasses({ ErroneousMapperWithMissingParameter.class, AnnotationWithRequiredParameter.class }) + public void erroneousMapperWithMissingParameter() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithMethodOnInterface.class, + line = 15, + message = "Annotation \"CustomMethodOnlyAnnotation\" is not allowed on classes." + ) + } + ) + @WithClasses({ ErroneousMapperWithMethodOnInterface.class, CustomMethodOnlyAnnotation.class }) + public void erroneousMapperWithMethodOnInterface() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithMethodOnClass.class, + line = 15, + message = "Annotation \"CustomMethodOnlyAnnotation\" is not allowed on classes." + ) + } + ) + @WithClasses({ ErroneousMapperWithMethodOnClass.class, CustomMethodOnlyAnnotation.class }) + public void erroneousMapperWithMethodOnClass() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithAnnotationOnlyOnInterface.class, + line = 15, + message = "Annotation \"CustomAnnotationOnlyAnnotation\" is not allowed on classes." + ) + } + ) + @WithClasses({ ErroneousMapperWithAnnotationOnlyOnInterface.class, CustomAnnotationOnlyAnnotation.class }) + public void erroneousMapperWithAnnotationOnlyOnInterface() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithAnnotationOnlyOnClass.class, + line = 15, + message = "Annotation \"CustomAnnotationOnlyAnnotation\" is not allowed on classes." + ) + } + ) + @WithClasses({ ErroneousMapperWithAnnotationOnlyOnClass.class, CustomAnnotationOnlyAnnotation.class }) + public void erroneousMapperWithAnnotationOnlyOnClass() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithClassOnMethod.class, + line = 17, + message = "Annotation \"CustomClassOnlyAnnotation\" is not allowed on methods." + ) + } + ) + @WithClasses({ ErroneousMapperWithClassOnMethod.class, CustomClassOnlyAnnotation.class }) + public void erroneousMapperWithClassOnMethod() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithUnknownParameter.class, + line = 17, + message = "Unknown parameter \"unknownParameter\" for annotation \"CustomAnnotation\"." + + " Did you mean \"value\"?" + ) + } + ) + @WithClasses({ ErroneousMapperWithUnknownParameter.class, CustomAnnotation.class }) + public void erroneousMapperWithUnknownParameter() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithNonExistantEnum.class, + line = 17, + message = "Enum \"AnnotateWithEnum\" does not have value \"NON_EXISTANT\"." + ) + } + ) + @WithClasses( { ErroneousMapperWithNonExistantEnum.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperWithNonExistantEnum() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithTooManyParameterValues.class, + line = 17, + message = "Parameter \"stringParam\" has too many value types supplied, type \"String\" is expected" + + " for annotation \"CustomAnnotationWithParams\"." + ) + } + ) + @WithClasses( { ErroneousMapperWithTooManyParameterValues.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperWithTooManyParameterValues() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 16, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"boolean\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 18, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"byte\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 20, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"char\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 22, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"CustomAnnotationWithParams\"" + + " but of type \"String\" for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 24, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"double\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 26, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"float\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 28, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"int\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 30, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"long\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 32, + alternativeLine = 43, + message = "Parameter \"stringParam\" is not of type \"short\" but of type \"String\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 35, + alternativeLine = 43, + message = "Parameter \"genericTypedClass\" is not of type \"String\" " + + "but of type \"Class\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 36, + alternativeLine = 43, + message = "Parameter \"enumParam\" is not of type \"WrongAnnotateWithEnum\" " + + "but of type \"AnnotateWithEnum\" for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 40, + alternativeLine = 43, + message = "Parameter \"genericTypedClass\" is not of type \"ErroneousMapperWithWrongParameter\" " + + "but of type \"Class\" " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithWrongParameter.class, + line = 42, + alternativeLine = 43, + message = "Parameter \"value\" is not of type \"boolean\" " + + "but of type \"String\" for annotation \"CustomAnnotation\"." + ) + } + ) + @WithClasses({ + ErroneousMapperWithWrongParameter.class, CustomAnnotationWithParams.class, + CustomAnnotationWithParamsContainer.class, WrongAnnotateWithEnum.class, CustomAnnotation.class + }) + public void erroneousMapperWithWrongParameter() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 17, + alternativeLine = 43, + message = "Parameter \"stringParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 18, + alternativeLine = 43, + message = "Parameter \"booleanParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 19, + alternativeLine = 32, + message = "Parameter \"byteParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 20, + alternativeLine = 32, + message = "Parameter \"charParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 21, + alternativeLine = 32, + message = "Parameter \"doubleParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 22, + alternativeLine = 32, + message = "Parameter \"floatParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 23, + alternativeLine = 32, + message = "Parameter \"intParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 24, + alternativeLine = 32, + message = "Parameter \"longParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 25, + alternativeLine = 32, + message = "Parameter \"shortParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 26, + alternativeLine = 32, + message = "Parameter \"genericTypedClass\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMultipleArrayValuesMapper.class, + line = 27, + alternativeLine = 32, + message = "Parameter \"enumParam\" does not accept multiple values " + + "for annotation \"CustomAnnotationWithParams\"." + ) + } + ) + @WithClasses( { ErroneousMultipleArrayValuesMapper.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperUsingMultipleValuesInsteadOfSingle() { + } + + @ProcessorTest + @WithClasses( { MapperWithMissingAnnotationElementName.class, + CustomAnnotationWithTwoAnnotationElements.class } ) + public void mapperWithMissingAnnotationElementNameShouldCompile() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithMissingEnumClass.class, + line = 17, + message = "enumClass needs to be defined when using enums." + ) + } + ) + @WithClasses( { ErroneousMapperWithMissingEnumClass.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperWithMissingEnumClass() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithMissingEnums.class, + line = 17, + message = "enums needs to be defined when using enumClass." + ) + } + ) + @WithClasses( { ErroneousMapperWithMissingEnums.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperWithMissingEnums() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithRepeatOfNotRepeatableAnnotation.class, + line = 16, + alternativeLine = 17, + message = "Annotation \"CustomAnnotation\" is not repeatable." + ) + } + ) + @WithClasses( { ErroneousMapperWithRepeatOfNotRepeatableAnnotation.class, CustomAnnotation.class } ) + public void erroneousMapperWithRepeatOfNotRepeatableAnnotation() { + } + + @ProcessorTest + @WithClasses( { MapperWithRepeatableAnnotation.class, CustomRepeatableAnnotation.class, + CustomRepeatableAnnotationContainer.class } ) + public void mapperWithRepeatableAnnotationShouldCompile() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousMapperWithParameterRepeat.class, + line = 18, + message = "Parameter \"stringParam\" must not be defined more than once." + ) + } + ) + @WithClasses( { ErroneousMapperWithParameterRepeat.class, CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class } ) + public void erroneousMapperWithParameterRepeat() { + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = MapperWithIdenticalAnnotationRepeated.class, + line = 16, + alternativeLine = 17, + message = "Annotation \"CustomRepeatableAnnotation\" is already present " + + "with the same elements configuration." + ) + } + ) + @WithClasses( { MapperWithIdenticalAnnotationRepeated.class, CustomRepeatableAnnotation.class, + CustomRepeatableAnnotationContainer.class } ) + public void mapperWithIdenticalAnnotationRepeated() { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithRequiredParameter.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithRequiredParameter.java new file mode 100644 index 0000000000..183b865928 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithRequiredParameter.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +public @interface AnnotationWithRequiredParameter { + String required(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithoutElementNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithoutElementNameMapper.java new file mode 100644 index 0000000000..8bb83ba562 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotationWithoutElementNameMapper.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@AnnotateWith( value = CustomAnnotation.class, elements = @AnnotateWith.Element( strings = "value" ) ) +public interface AnnotationWithoutElementNameMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ClassMetaAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ClassMetaAnnotation.java new file mode 100644 index 0000000000..057cb384fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ClassMetaAnnotation.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.AnnotateWith; + +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.TYPE } ) +@AnnotateWith( CustomClassOnlyAnnotation.class ) +public @interface ClassMetaAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotation.java new file mode 100644 index 0000000000..71ee6f12e3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotation.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +public @interface CustomAnnotation { + String value() default ""; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationOnlyAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationOnlyAnnotation.java new file mode 100644 index 0000000000..52d3e386a0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationOnlyAnnotation.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention(RUNTIME) +@Target({ ANNOTATION_TYPE }) +public @interface CustomAnnotationOnlyAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParams.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParams.java new file mode 100644 index 0000000000..bc25302fc1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParams.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Annotation; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { METHOD, TYPE } ) +@Repeatable( CustomAnnotationWithParamsContainer.class ) +public @interface CustomAnnotationWithParams { + String stringParam(); + + Class genericTypedClass() default CustomAnnotationWithParams.class; + + AnnotateWithEnum enumParam() default AnnotateWithEnum.EXISTING; + + byte byteParam() default 0x00; + + char charParam() default 'a'; + + double doubleParam() default 0.0; + + float floatParam() default 0.0f; + + int intParam() default 0; + + long longParam() default 0L; + + short shortParam() default 0; + + boolean booleanParam() default false; + + short[] shortArray() default {}; + + byte[] byteArray() default {}; + + int[] intArray() default {}; + + long[] longArray() default {}; + + float[] floatArray() default {}; + + double[] doubleArray() default {}; + + char[] charArray() default {}; + + boolean[] booleanArray() default {}; + + String[] stringArray() default {}; + + Class[] classArray() default {}; + + AnnotateWithEnum[] enumArray() default {}; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParamsContainer.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParamsContainer.java new file mode 100644 index 0000000000..51ed62885c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithParamsContainer.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +public @interface CustomAnnotationWithParamsContainer { + CustomAnnotationWithParams[] value() default {}; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithTwoAnnotationElements.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithTwoAnnotationElements.java new file mode 100644 index 0000000000..fb8c5c69f8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomAnnotationWithTwoAnnotationElements.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +public @interface CustomAnnotationWithTwoAnnotationElements { + String value() default ""; + boolean namedAnnotationElement() default false; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomClassOnlyAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomClassOnlyAnnotation.java new file mode 100644 index 0000000000..858c8fb52f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomClassOnlyAnnotation.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE } ) +public @interface CustomClassOnlyAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomMethodOnlyAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomMethodOnlyAnnotation.java new file mode 100644 index 0000000000..1dfe8e734e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomMethodOnlyAnnotation.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { METHOD } ) +public @interface CustomMethodOnlyAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedGenericClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedGenericClassMapper.java new file mode 100644 index 0000000000..a320d56bba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedGenericClassMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element( name = "stringParam", strings = "test" ), + @Element( name = "genericTypedClass", classes = Mapper.class ) +} ) +public interface CustomNamedGenericClassMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java new file mode 100644 index 0000000000..32241ab4ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element( name = "stringArray", strings = "test" ), + @Element( name = "stringParam", strings = "test" ), + @Element( name = "booleanArray", booleans = true ), + @Element( name = "booleanParam", booleans = true ), + @Element( name = "byteArray", bytes = 0x10 ), + @Element( name = "byteParam", bytes = 0x13 ), + @Element( name = "charArray", chars = 'd' ), + @Element( name = "charParam", chars = 'a' ), + @Element( name = "enumArray", enumClass = AnnotateWithEnum.class, enums = "EXISTING" ), + @Element( name = "enumParam", enumClass = AnnotateWithEnum.class, enums = "EXISTING" ), + @Element( name = "doubleArray", doubles = 0.3 ), + @Element( name = "doubleParam", doubles = 1.2 ), + @Element( name = "floatArray", floats = 0.3f ), + @Element( name = "floatParam", floats = 1.2f ), + @Element( name = "intArray", ints = 3 ), + @Element( name = "intParam", ints = 1 ), + @Element( name = "longArray", longs = 3L ), + @Element( name = "longParam", longs = 1L ), + @Element( name = "shortArray", shorts = 3 ), + @Element( name = "shortParam", shorts = 1 ) +} ) +public interface CustomNamedMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotation.java new file mode 100644 index 0000000000..d7c0c85107 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotation.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +@Repeatable( CustomRepeatableAnnotationContainer.class ) +public @interface CustomRepeatableAnnotation { + String value() default ""; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotationContainer.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotationContainer.java new file mode 100644 index 0000000000..8de3a8bf0a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomRepeatableAnnotationContainer.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Retention( RUNTIME ) +@Target( { TYPE, METHOD } ) +public @interface CustomRepeatableAnnotationContainer { + CustomRepeatableAnnotation[] value() default {}; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/DeprecateAndCustomMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/DeprecateAndCustomMapper.java new file mode 100644 index 0000000000..809ad5702a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/DeprecateAndCustomMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( Deprecated.class ) +@AnnotateWith( CustomAnnotation.class ) +public interface DeprecateAndCustomMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnClass.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnClass.java new file mode 100644 index 0000000000..d617e8d0fc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnClass.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +@AnnotateWith( value = CustomAnnotationOnlyAnnotation.class ) +public abstract class ErroneousMapperWithAnnotationOnlyOnClass { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnInterface.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnInterface.java new file mode 100644 index 0000000000..4e914b30a3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithAnnotationOnlyOnInterface.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +@AnnotateWith( value = CustomAnnotationOnlyAnnotation.class ) +public interface ErroneousMapperWithAnnotationOnlyOnInterface { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java new file mode 100644 index 0000000000..d3d53c910a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface ErroneousMapperWithClassOnMethod { + + @AnnotateWith( value = CustomClassOnlyAnnotation.class ) + Target toString(Source value); + + class Source { + + } + + class Target { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnClass.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnClass.java new file mode 100644 index 0000000000..262880d6f5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnClass.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomMethodOnlyAnnotation.class ) +public abstract class ErroneousMapperWithMethodOnClass { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnInterface.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnInterface.java new file mode 100644 index 0000000000..75f9039093 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMethodOnInterface.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomMethodOnlyAnnotation.class ) +public interface ErroneousMapperWithMethodOnInterface { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnumClass.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnumClass.java new file mode 100644 index 0000000000..6905a363f2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnumClass.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = { @Element( name = "enumParam", enums = "EXISTING" ), + @Element( name = "stringParam", strings = "required" ) } +) +public interface ErroneousMapperWithMissingEnumClass { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnums.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnums.java new file mode 100644 index 0000000000..fc7096d290 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingEnums.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @Element( name = "stringParam", strings = "required", enumClass = AnnotateWithEnum.class ) +) +public interface ErroneousMapperWithMissingEnums { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingParameter.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingParameter.java new file mode 100644 index 0000000000..40ffa53094 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithMissingParameter.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( AnnotationWithRequiredParameter.class ) +public interface ErroneousMapperWithMissingParameter { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithNonExistantEnum.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithNonExistantEnum.java new file mode 100644 index 0000000000..1ed85b990d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithNonExistantEnum.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = { @Element( name = "enumParam", enumClass = AnnotateWithEnum.class, enums = "NON_EXISTANT" ), + @Element( name = "stringParam", strings = "required" ) } +) +public interface ErroneousMapperWithNonExistantEnum { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithParameterRepeat.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithParameterRepeat.java new file mode 100644 index 0000000000..d75c7a4ee4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithParameterRepeat.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element( name = "stringParam", strings = "test" ), + @Element( name = "stringParam", strings = "otherValue" ) +} ) +public interface ErroneousMapperWithParameterRepeat { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithRepeatOfNotRepeatableAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithRepeatOfNotRepeatableAnnotation.java new file mode 100644 index 0000000000..be9596ea46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithRepeatOfNotRepeatableAnnotation.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotation.class ) +@AnnotateWith( value = CustomAnnotation.class ) +public interface ErroneousMapperWithRepeatOfNotRepeatableAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithTooManyParameterValues.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithTooManyParameterValues.java new file mode 100644 index 0000000000..4b6c20c39b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithTooManyParameterValues.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @Element( name = "stringParam", booleans = true, strings = "test" ) +) +public interface ErroneousMapperWithTooManyParameterValues { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithUnknownParameter.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithUnknownParameter.java new file mode 100644 index 0000000000..c705dc88f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithUnknownParameter.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotation.class, + elements = @Element( name = "unknownParameter", strings = "unknown" ) +) +public interface ErroneousMapperWithUnknownParameter { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithWrongParameter.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithWrongParameter.java new file mode 100644 index 0000000000..3251122b22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithWrongParameter.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", booleans = true ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", bytes = 0x12 ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", chars = 'a' ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", classes = CustomAnnotationWithParams.class ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", doubles = 12.34 ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", floats = 12.34f ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", ints = 1234 ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", longs = 1234L ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, + elements = @AnnotateWith.Element( name = "stringParam", shorts = 12 ) ) +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @AnnotateWith.Element( name = "stringParam", strings = "correctValue" ), + @AnnotateWith.Element( name = "genericTypedClass", strings = "wrong" ), + @AnnotateWith.Element( name = "enumParam", enumClass = WrongAnnotateWithEnum.class, enums = "EXISTING" ) +} ) +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @AnnotateWith.Element( name = "stringParam", strings = "correctValue" ), + @AnnotateWith.Element( name = "genericTypedClass", classes = ErroneousMapperWithWrongParameter.class ) +} ) +@AnnotateWith( value = CustomAnnotation.class, elements = @AnnotateWith.Element( booleans = true ) ) +public interface ErroneousMapperWithWrongParameter { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMultipleArrayValuesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMultipleArrayValuesMapper.java new file mode 100644 index 0000000000..f6bf7629cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMultipleArrayValuesMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element( name = "stringParam", strings = { "test1", "test2" } ), + @Element( name = "booleanParam", booleans = { false, true } ), + @Element( name = "byteParam", bytes = { 0x08, 0x1f } ), + @Element( name = "charParam", chars = { 'b', 'c' } ), + @Element( name = "doubleParam", doubles = { 1.2, 3.4 } ), + @Element( name = "floatParam", floats = { 1.2f, 3.4f } ), + @Element( name = "intParam", ints = { 12, 34 } ), + @Element( name = "longParam", longs = { 12L, 34L } ), + @Element( name = "shortParam", shorts = { 12, 34 } ), + @Element( name = "genericTypedClass", classes = { Mapper.class, CustomAnnotationWithParams.class } ), + @Element( name = "enumParam", enumClass = AnnotateWithEnum.class, enums = { "EXISTING", "OTHER_EXISTING" } ) +} ) +public interface ErroneousMultipleArrayValuesMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithIdenticalAnnotationRepeated.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithIdenticalAnnotationRepeated.java new file mode 100644 index 0000000000..0959ee305a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithIdenticalAnnotationRepeated.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomRepeatableAnnotation.class, elements = @AnnotateWith.Element( strings = "identical" ) ) +@AnnotateWith( value = CustomRepeatableAnnotation.class, elements = @AnnotateWith.Element( strings = "identical" ) ) +public interface MapperWithIdenticalAnnotationRepeated { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithMissingAnnotationElementName.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithMissingAnnotationElementName.java new file mode 100644 index 0000000000..ed9523c545 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithMissingAnnotationElementName.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithTwoAnnotationElements.class, elements = { + @AnnotateWith.Element( strings = "unnamed annotation element" ), + @AnnotateWith.Element( name = "namedAnnotationElement", booleans = false ) +} ) +public abstract class MapperWithMissingAnnotationElementName { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithRepeatableAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithRepeatableAnnotation.java new file mode 100644 index 0000000000..b66ec68261 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MapperWithRepeatableAnnotation.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomRepeatableAnnotation.class ) +@AnnotateWith( value = CustomRepeatableAnnotation.class, elements = @AnnotateWith.Element( strings = "different" ) ) +public interface MapperWithRepeatableAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MetaAnnotatedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MetaAnnotatedMapper.java new file mode 100644 index 0000000000..2dddb17f83 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MetaAnnotatedMapper.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.Mapper; + +@ClassMetaAnnotation +@Mapper +public interface MetaAnnotatedMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MethodMetaAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MethodMetaAnnotation.java new file mode 100644 index 0000000000..a93d54c283 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MethodMetaAnnotation.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.AnnotateWith; + +@Retention( RetentionPolicy.RUNTIME ) +@Target( { ElementType.METHOD } ) +@AnnotateWith( CustomMethodOnlyAnnotation.class ) +public @interface MethodMetaAnnotation { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapper.java new file mode 100644 index 0000000000..2ccdbb0ea2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.AnnotateWith.Element; +import org.mapstruct.Mapper; + +/** + * @author Ben Zegveld + */ +@Mapper +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element( name = "stringArray", strings = { "test1", "test2" } ), + @Element( name = "booleanArray", booleans = { false, true } ), + @Element( name = "byteArray", bytes = { 0x08, 0x1f } ), + @Element( name = "charArray", chars = { 'b', 'c' } ), + @Element( name = "doubleArray", doubles = { 1.2, 3.4 } ), + @Element( name = "floatArray", floats = { 1.2f, 3.4f } ), + @Element( name = "intArray", ints = { 12, 34 } ), + @Element( name = "longArray", longs = { 12L, 34L } ), + @Element( name = "shortArray", shorts = { 12, 34 } ), + @Element( name = "classArray", classes = { Mapper.class, CustomAnnotationWithParams.class } ), + @Element( name = "stringParam", strings = "required parameter" ) +} ) +public interface MultipleArrayValuesMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/WrongAnnotateWithEnum.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/WrongAnnotateWithEnum.java new file mode 100644 index 0000000000..677a6cc6d5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/WrongAnnotateWithEnum.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +public enum WrongAnnotateWithEnum { + EXISTING +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java new file mode 100644 index 0000000000..cb01cfec85 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2022-06-06T16:48:18+0200", + comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)" +) +@CustomAnnotationWithParams(stringArray = "test", stringParam = "test", booleanArray = true, booleanParam = true, byteArray = 16, byteParam = 19, charArray = 'd', charParam = 'a', enumArray = AnnotateWithEnum.EXISTING, enumParam = AnnotateWithEnum.EXISTING, doubleArray = 0.3, doubleParam = 1.2, floatArray = 0.300000011920929f, floatParam = 1.2000000476837158f, intArray = 3, intParam = 1, longArray = 3L, longParam = 1L, shortArray = 3, shortParam = 1) +public class CustomNamedMapperImpl implements CustomNamedMapper { +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java new file mode 100644 index 0000000000..fe9bb93f13 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import javax.annotation.processing.Generated; +import org.mapstruct.Mapper; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2022-06-06T16:48:23+0200", + comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)" +) +@CustomAnnotationWithParams(stringArray = { "test1", "test2" }, booleanArray = { false, true }, byteArray = { 8, 31 }, charArray = { 'b', 'c' }, doubleArray = { 1.2, 3.4 }, floatArray = { 1.2000000476837158f, 3.4000000953674316f }, intArray = { 12, 34 }, longArray = { 12L, 34L }, shortArray = { 12, 34 }, classArray = { Mapper.class, CustomAnnotationWithParams.class }, stringParam = "required parameter") +public class MultipleArrayValuesMapperImpl implements MultipleArrayValuesMapper { +} From 17997ef617e6ba5d9b9c70e7e5e8484cd82dbc53 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 20 Aug 2022 13:01:47 +0200 Subject: [PATCH 0695/1006] #2901: Fix `@TargetType` annotation on a `@Condition` annotated method for a Collection value --- .../ap/internal/model/macro/CommonMacros.ftl | 3 ++- ...itionWithTargetTypeOnCollectionMapper.java | 23 +++++++++++++++++++ .../ap/test/bugs/_2901/Issue2901Test.java | 22 ++++++++++++++++++ .../mapstruct/ap/test/bugs/_2901/Source.java | 21 +++++++++++++++++ .../mapstruct/ap/test/bugs/_2901/Target.java | 21 +++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/ConditionWithTargetTypeOnCollectionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Issue2901Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Target.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index e5fb970605..bce28ebe19 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -60,7 +60,8 @@ <#macro handleLocalVarNullCheck needs_explicit_local_var> <#if sourcePresenceCheckerReference??> if ( <@includeModel object=sourcePresenceCheckerReference - targetPropertyName=ext.targetPropertyName/> ) { + targetType=ext.targetType + targetPropertyName=ext.targetPropertyName /> ) { <#if needs_explicit_local_var> <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; <#nested> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/ConditionWithTargetTypeOnCollectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/ConditionWithTargetTypeOnCollectionMapper.java new file mode 100644 index 0000000000..7e833cfc53 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/ConditionWithTargetTypeOnCollectionMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2901; + +import java.util.List; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; + +@Mapper +public interface ConditionWithTargetTypeOnCollectionMapper { + + Target map(Source source); + + @Condition + default boolean check(List test, @TargetType Class type) { + return type.isInstance( test ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Issue2901Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Issue2901Test.java new file mode 100644 index 0000000000..3ae2c3db86 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Issue2901Test.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2901; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Ben Zegveld + */ +@IssueKey( "2901" ) +class Issue2901Test { + + @ProcessorTest + @WithClasses( { Source.class, Target.class, ConditionWithTargetTypeOnCollectionMapper.class } ) + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Source.java new file mode 100644 index 0000000000..4eb50d58fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Source.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2901; + +import java.util.List; + +public class Source { + + private List field; + + public List getField() { + return field; + } + + public void setField(List field) { + this.field = field; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Target.java new file mode 100644 index 0000000000..b4c5299f35 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2901/Target.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2901; + +import java.util.List; + +public class Target { + + private List field; + + public List getField() { + return field; + } + + public void setField(List field) { + this.field = field; + } +} From 46900cabde211f885521b9b57d1d3de3f07a849a Mon Sep 17 00:00:00 2001 From: Prasanth Omanakuttan Date: Sat, 20 Aug 2022 17:07:43 +0530 Subject: [PATCH 0696/1006] Update Typos in javadoc (#2958) --- .../main/java/org/mapstruct/InheritInverseConfiguration.java | 4 ++-- .../org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java | 2 +- .../mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java | 4 ++-- .../mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java index ac582a5dfa..b659b7f37a 100644 --- a/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java +++ b/core/src/main/java/org/mapstruct/InheritInverseConfiguration.java @@ -81,8 +81,8 @@ public @interface InheritInverseConfiguration { /** - * The name of the inverse mapping method to inherit the mappings from. Needs only to be specified in case more than - * one inverse method with matching source and target type exists. + * The name of the inverse mapping method to inherit the mappings from. Needs to be specified only in case more than + * one inverse method exists with a matching source and target type exists. * * @return The name of the inverse mapping method to inherit the mappings from. */ diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java index 8ac41395bf..6b9e079523 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.java @@ -15,7 +15,7 @@ *

    * This contract will be queried by MapStruct when examining types referenced by mappers to be generated, most notably * the source and target types of mapping methods. If at least one AST-modifying processor announces further changes to - * such type, the generation of the affected mapper(s) will be deferred to a future round in the annnotation processing + * such type, the generation of the affected mapper(s) will be deferred to a future round in the annotation processing * cycle. *

    * Implementations are discovered via the service loader, i.e. a JAR providing an AST-modifying processor needs to diff --git a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java index 92fef3a1be..dc14e20de6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/FreeBuilderAccessorNamingStrategy.java @@ -20,8 +20,8 @@ *

  • {@code mergeFrom(Target.Builder)}
  • * *

    - * When the JavaBean convention is not used with FreeBuilder then the getters are non standard and MapStruct - * won't recognize them. Therefore one needs to use the JavaBean convention in which the fluent setters + * When the JavaBean convention is not used with FreeBuilder then the getters are non-standard and MapStruct + * won't recognize them. Therefore, one needs to use the JavaBean convention in which the fluent setters * start with {@code set}. * * @author Filip Hrisafov diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index 69c66cdd28..100798e063 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -10,9 +10,9 @@ import org.mapstruct.util.Experimental; /** - * Accesor naming strategy for Immutables. + * Accessor naming strategy for Immutables. * The generated Immutables also have a from that works as a copy. Our default strategy considers this method - * as a setter with a name {@code from}. Therefore we are ignoring it. + * as a setter with a name {@code from}. Therefore, we are ignoring it. * * @author Filip Hrisafov */ From 54321d6e663d656a0d33bbddb3a7e030f8faa74c Mon Sep 17 00:00:00 2001 From: Hakan Date: Sat, 20 Aug 2022 15:23:32 +0200 Subject: [PATCH 0697/1006] #2839 Keep thrown types when creating a new ForgedMethod with the same arguments This fixes a compilation error when mapping fields with the same type due to not wrapping in a `try-catch` block --- .../ap/internal/model/ForgedMethod.java | 2 +- .../org/mapstruct/ap/test/bugs/_2839/Car.java | 36 ++++++++++++ .../mapstruct/ap/test/bugs/_2839/CarDto.java | 36 ++++++++++++ .../ap/test/bugs/_2839/CarMapper.java | 25 +++++++++ .../org/mapstruct/ap/test/bugs/_2839/Id.java | 28 ++++++++++ .../test/bugs/_2839/Issue2839Exception.java | 16 ++++++ .../ap/test/bugs/_2839/Issue2839Test.java | 56 +++++++++++++++++++ 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Id.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Exception.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index a1f5b091ce..a33bc7520e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -196,7 +196,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List(); + this.thrownTypes = forgedMethod.thrownTypes; this.history = forgedMethod.history; this.sourceParameters = Parameter.getSourceParameters( parameters ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Car.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Car.java new file mode 100644 index 0000000000..9419223a42 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Car.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +import java.util.List; + +/** + * @author Hakan Özkan + */ +public final class Car { + + private final Id id; + private final List seatIds; + private final List tireIds; + + public Car(Id id, List seatIds, List tireIds) { + this.id = id; + this.seatIds = seatIds; + this.tireIds = tireIds; + } + + public Id getId() { + return id; + } + + public List getSeatIds() { + return seatIds; + } + + public List getTireIds() { + return tireIds; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarDto.java new file mode 100644 index 0000000000..68741ebc92 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarDto.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +import java.util.List; + +/** + * @author Hakan Özkan + */ +public final class CarDto { + + private final String id; + private final List seatIds; + private final List tireIds; + + public CarDto(String id, List seatIds, List tireIds) { + this.id = id; + this.seatIds = seatIds; + this.tireIds = tireIds; + } + + public String getId() { + return id; + } + + public List getSeatIds() { + return seatIds; + } + + public List getTireIds() { + return tireIds; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarMapper.java new file mode 100644 index 0000000000..e535935d21 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/CarMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Hakan Özkan + */ +@Mapper +public abstract class CarMapper { + + public static final CarMapper MAPPER = Mappers.getMapper( CarMapper.class ); + + public abstract Car toEntity(CarDto dto); + + protected Id mapId(String id) throws Issue2839Exception { + throw new Issue2839Exception("For id " + id); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Id.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Id.java new file mode 100644 index 0000000000..5bb9a29dd7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Id.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +import java.util.UUID; + +/** + * @author Hakan Özkan + */ +public class Id { + + private final UUID id; + + public Id() { + this.id = UUID.randomUUID(); + } + + public Id(UUID id) { + this.id = id; + } + + public UUID getId() { + return id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Exception.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Exception.java new file mode 100644 index 0000000000..91f02014d6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Exception.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +/** + * @author Hakan Özkan + */ +public class Issue2839Exception extends Exception { + + public Issue2839Exception(String message) { + super( message ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Test.java new file mode 100644 index 0000000000..ed61c39a63 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2839/Issue2839Test.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2839; + +import java.util.Collections; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Hakan Özkan + */ +@IssueKey("2839") +@WithClasses({ + Car.class, + CarDto.class, + CarMapper.class, + Id.class, + Issue2839Exception.class, +}) +public class Issue2839Test { + + @ProcessorTest + void shouldCompile() { + CarDto car1 = new CarDto( + "carId", + Collections.singletonList( "seatId" ), + Collections.singletonList( "tireId" ) + ); + assertThatThrownBy( () -> CarMapper.MAPPER.toEntity( car1 ) ) + .isExactlyInstanceOf( RuntimeException.class ) + .getCause() + .isInstanceOf( Issue2839Exception.class ) + .hasMessage( "For id seatId" ); + + CarDto car2 = new CarDto( "carId", Collections.emptyList(), Collections.singletonList( "tireId" ) ); + assertThatThrownBy( () -> CarMapper.MAPPER.toEntity( car2 ) ) + .isExactlyInstanceOf( RuntimeException.class ) + .getCause() + .isInstanceOf( Issue2839Exception.class ) + .hasMessage( "For id tireId" ); + + CarDto car3 = new CarDto( "carId", Collections.emptyList(), Collections.emptyList() ); + assertThatThrownBy( () -> CarMapper.MAPPER.toEntity( car3 ) ) + .isExactlyInstanceOf( RuntimeException.class ) + .getCause() + .isInstanceOf( Issue2839Exception.class ) + .hasMessage( "For id carId" ); + } +} From 4118a446306ab3d413285ccf1e0c709aa55de4c2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Aug 2022 10:56:16 +0200 Subject: [PATCH 0698/1006] #2974 Fix typos in documentation Closes #2974 --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- documentation/src/main/asciidoc/chapter-2-set-up.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index decee792d0..9c1b2243eb 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -292,7 +292,7 @@ The source presence checker name can be changed in the MapStruct service provide [NOTE] ==== -Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor see `CollectionMappingStrategy`, MapStruct will always generate a source property +Some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder as target accessor (see `CollectionMappingStrategy`), MapStruct will always generate a source property null check, regardless the value of the `NullValueCheckStrategy` to avoid addition of `null` to the target collection or map. ==== diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index d95983e840..48b352bd94 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -130,7 +130,7 @@ You can find a complete example in the https://github.com/mapstruct/mapstruct-ex The MapStruct code generator can be configured using _annotation processor options_. -When invoking javac directly, these options are passed to the compiler in the form _-Akey=value_. When using MapStruct via Maven, any processor options can be passed using an `options` element within the configuration of the Maven processor plug-in like this: +When invoking javac directly, these options are passed to the compiler in the form _-Akey=value_. When using MapStruct via Maven, any processor options can be passed using `compilerArgs` within the configuration of the Maven processor plug-in like this: .Maven configuration ==== From 3e0c62ac36e6adbf689031a62be3b96457348740 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Aug 2022 11:26:42 +0200 Subject: [PATCH 0699/1006] Publish snapshots when on main --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40999c680a..54cf0b1076 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -43,7 +43,7 @@ jobs: - name: 'Upload coverage to Codecov' uses: codecov/codecov-action@v2 - name: 'Publish Snapshots' - if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'mapstruct/mapstruct' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy linux-jdk-8: name: 'Linux JDK 8' From ef4c26b075896dd564e63235ae98dbaedb7d512f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 Aug 2022 18:36:43 +0200 Subject: [PATCH 0700/1006] #2949 Do not inverse inherit BeanMapping#ignoreUnmappedSourceProperties --- .../model/source/BeanMappingOptions.java | 11 ++-- .../ap/test/bugs/_2949/Issue2949Mapper.java | 59 +++++++++++++++++++ .../ap/test/bugs/_2949/Issue2949Test.java | 35 +++++++++++ 3 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index cc03878362..60aac32e54 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -34,6 +34,7 @@ public class BeanMappingOptions extends DelegatingOptions { private final SelectionParameters selectionParameters; + private final List ignoreUnmappedSourceProperties; private final BeanMappingGem beanMapping; /** @@ -46,6 +47,7 @@ public class BeanMappingOptions extends DelegatingOptions { public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) { BeanMappingOptions options = new BeanMappingOptions( SelectionParameters.forInheritance( beanMapping.selectionParameters ), + Collections.emptyList(), beanMapping.beanMapping, beanMapping ); @@ -57,7 +59,7 @@ public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, Mappe TypeUtils typeUtils, TypeFactory typeFactory ) { if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) { - BeanMappingOptions options = new BeanMappingOptions( null, null, mapperOptions ); + BeanMappingOptions options = new BeanMappingOptions( null, Collections.emptyList(), null, mapperOptions ); return options; } @@ -77,6 +79,7 @@ public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, Mappe //TODO Do we want to add the reporting policy to the BeanMapping as well? To give more granular support? BeanMappingOptions options = new BeanMappingOptions( selectionParameters, + beanMapping.ignoreUnmappedSourceProperties().get(), beanMapping, mapperOptions ); @@ -104,10 +107,12 @@ private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method } private BeanMappingOptions(SelectionParameters selectionParameters, + List ignoreUnmappedSourceProperties, BeanMappingGem beanMapping, DelegatingOptions next) { super( next ); this.selectionParameters = selectionParameters; + this.ignoreUnmappedSourceProperties = ignoreUnmappedSourceProperties; this.beanMapping = beanMapping; } @@ -188,9 +193,7 @@ public boolean isignoreByDefault() { } public List getIgnoreUnmappedSourceProperties() { - return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreUnmappedSourceProperties ) - .map( GemValue::get ) - .orElse( Collections.emptyList() ); + return ignoreUnmappedSourceProperties; } public AnnotationMirror getMirror() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Mapper.java new file mode 100644 index 0000000000..553563066e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Mapper.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2949; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue2949Mapper { + + Issue2949Mapper INSTANCE = Mappers.getMapper( Issue2949Mapper.class ); + + @Mapping( target = "property1", ignore = true) + @InheritInverseConfiguration + Source toSource(Target target); + + @BeanMapping(ignoreUnmappedSourceProperties = { "property1" }) + Target toTarget(Source source); + + class Target { + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + private final String value; + private final String property1; + + public Source(String value, String property1) { + this.value = value; + this.property1 = property1; + } + + public String getValue() { + return value; + } + + public String getProperty1() { + return property1; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Test.java new file mode 100644 index 0000000000..2a277a4bfd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2949/Issue2949Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2949; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue2949Mapper.class +}) +class Issue2949Test { + + @ProcessorTest + void shouldCorrectlyInheritInverseBeanMappingWithIgnoreUnmappedSourceProeprties() { + Issue2949Mapper.Target target = Issue2949Mapper.INSTANCE.toTarget( new Issue2949Mapper.Source( + "test", + "first" + ) ); + + assertThat( target.getValue() ).isEqualTo( "test" ); + + Issue2949Mapper.Source source = Issue2949Mapper.INSTANCE.toSource( target ); + + assertThat( source.getValue() ).isEqualTo( "test" ); + assertThat( source.getProperty1() ).isNull(); + } +} From 874bf1fd2c44065376483c2a9a700455aa0c31ce Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 Aug 2022 18:38:44 +0200 Subject: [PATCH 0701/1006] #2950 Add support for Jakarta CDI --- .../java/org/mapstruct/MappingConstants.java | 13 ++++- .../test/resources/fullFeatureTest/pom.xml | 4 ++ parent/pom.xml | 5 ++ processor/pom.xml | 5 ++ .../ap/internal/gem/MappingConstantsGem.java | 2 + .../processor/CdiComponentProcessor.java | 26 ++++++++- .../JakartaCdiComponentProcessor.java | 52 +++++++++++++++++ ...p.internal.processor.ModelElementProcessor | 1 + .../mapstruct/ap/test/gem/ConstantTest.java | 4 +- ...diDefaultCompileOptionFieldMapperTest.java | 54 ++++++++++++++++++ ...merCdiDefaultCompileOptionFieldMapper.java | 21 +++++++ ...derCdiDefaultCompileOptionFieldMapper.java | 26 +++++++++ ...merCdiDefaultCompileOptionFieldMapper.java | 21 +++++++ ...derCdiDefaultCompileOptionFieldMapper.java | 26 +++++++++ ...diDefaultCompileOptionFieldMapperTest.java | 56 +++++++++++++++++++ ...diDefaultCompileOptionFieldMapperTest.java | 54 ++++++++++++++++++ ...rtaCdiDefaultCompileOptionFieldMapper.java | 21 +++++++ ...rtaCdiDefaultCompileOptionFieldMapper.java | 26 +++++++++ ...diDefaultCompileOptionFieldMapperTest.java | 55 ++++++++++++++++++ ...diDefaultCompileOptionFieldMapperTest.java | 54 ++++++++++++++++++ .../org/mapstruct/ap/testutil/WithCdi.java | 28 ++++++++++ .../mapstruct/ap/testutil/WithJakartaCdi.java | 28 ++++++++++ 22 files changed, 578 insertions(+), 4 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaCdiComponentProcessor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CdiDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CustomerCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/GenderCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/CustomerCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/GenderCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiCdiDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/CustomerJakartaCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/GenderJakartaCdiDefaultCompileOptionFieldMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiDefaultCompileOptionFieldMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithCdi.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaCdi.java diff --git a/core/src/main/java/org/mapstruct/MappingConstants.java b/core/src/main/java/org/mapstruct/MappingConstants.java index ce2438298c..3d3d8a4c77 100644 --- a/core/src/main/java/org/mapstruct/MappingConstants.java +++ b/core/src/main/java/org/mapstruct/MappingConstants.java @@ -109,7 +109,12 @@ private ComponentModel() { public static final String DEFAULT = "default"; /** - * The generated mapper is an application-scoped CDI bean and can be retrieved via @Inject + * The generated mapper is an application-scoped CDI bean and can be retrieved via @Inject. + * The annotations are either from {@code javax} or {@code jakarta}. + * Priority have the {@code javax} annotations. + * In case you want to only use Jakarta then use {@link #JAKARTA_CDI}. + * + * @see #JAKARTA_CDI */ public static final String CDI = "cdi"; @@ -138,6 +143,12 @@ private ComponentModel() { */ public static final String JAKARTA = "jakarta"; + /** + * The generated mapper is an application-scoped Jakarta CDI bean and can be retrieved via @Inject. + * @see #CDI + */ + public static final String JAKARTA_CDI = "jakarta-cdi"; + } } diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index ec26f45ce2..62f7986e9c 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -64,6 +64,10 @@ jakarta.inject jakarta.inject-api + + jakarta.enterprise + jakarta.enterprise.cdi-api + diff --git a/parent/pom.xml b/parent/pom.xml index 1c031a7b71..426405b4b7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -160,6 +160,11 @@ cdi-api 2.0.SP1 + + jakarta.enterprise + jakarta.enterprise.cdi-api + 4.0.1 + javax.inject javax.inject diff --git a/processor/pom.xml b/processor/pom.xml index 6f2bb6495c..ff7864f32e 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -89,6 +89,11 @@ jakarta.inject-api test + + jakarta.enterprise + jakarta.enterprise.cdi-api + test + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java index cb6d49c0cb..bc58024ca3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/MappingConstantsGem.java @@ -51,6 +51,8 @@ private ComponentModelGem() { public static final String JSR330 = "jsr330"; public static final String JAKARTA = "jakarta"; + + public static final String JAKARTA_CDI = "jakarta-cdi"; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java index 74ff2b118b..d8f136034b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/CdiComponentProcessor.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.AnnotationProcessingException; /** * A {@link ModelElementProcessor} which converts the given {@link Mapper} @@ -30,13 +32,13 @@ protected String getComponentModelIdentifier() { @Override protected List getTypeAnnotations(Mapper mapper) { return Collections.singletonList( - new Annotation( getTypeFactory().getType( "javax.enterprise.context.ApplicationScoped" ) ) + new Annotation( getType( "ApplicationScoped" ) ) ); } @Override protected List getMapperReferenceAnnotations() { - return Arrays.asList( new Annotation( getTypeFactory().getType( "javax.inject.Inject" ) ) ); + return Arrays.asList( new Annotation( getType( "Inject" ) ) ); } @Override @@ -48,4 +50,24 @@ protected boolean requiresGenerationOfDecoratorClass() { protected boolean additionalPublicEmptyConstructor() { return true; } + + private Type getType(String simpleName) { + String javaxPrefix = "javax.inject."; + String jakartaPrefix = "jakarta.inject."; + if ( "ApplicationScoped".equals( simpleName ) ) { + javaxPrefix = "javax.enterprise.context."; + jakartaPrefix = "jakarta.enterprise.context."; + } + if ( getTypeFactory().isTypeAvailable( javaxPrefix + simpleName ) ) { + return getTypeFactory().getType( javaxPrefix + simpleName ); + } + + if ( getTypeFactory().isTypeAvailable( jakartaPrefix + simpleName ) ) { + return getTypeFactory().getType( jakartaPrefix + simpleName ); + } + + throw new AnnotationProcessingException( + "Couldn't find any of the CDI or Jakarta CDI Dependency types." + + " Are you missing a dependency on your classpath?" ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaCdiComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaCdiComponentProcessor.java new file mode 100644 index 0000000000..11c765668e --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaCdiComponentProcessor.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.processor; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.mapstruct.ap.internal.gem.MappingConstantsGem; +import org.mapstruct.ap.internal.model.Annotation; +import org.mapstruct.ap.internal.model.Mapper; + +/** + * A {@link ModelElementProcessor} which converts the given {@link Mapper} + * object into an application-scoped Jakarta CDI bean in case Jakarta CDI + * is configured as the target component model for this mapper. + * + * @author Filip Hrisafov + */ +public class JakartaCdiComponentProcessor extends AnnotationBasedComponentModelProcessor { + + @Override + protected String getComponentModelIdentifier() { + return MappingConstantsGem.ComponentModelGem.JAKARTA_CDI; + } + + @Override + protected List getTypeAnnotations(Mapper mapper) { + return Collections.singletonList( + new Annotation( getTypeFactory().getType( "jakarta.enterprise.context.ApplicationScoped" ) ) + ); + } + + @Override + protected List getMapperReferenceAnnotations() { + return Arrays.asList( new Annotation( getTypeFactory().getType( "jakarta.inject.Inject" ) ) ); + } + + @Override + protected boolean requiresGenerationOfDecoratorClass() { + return false; + } + + @Override + protected boolean additionalPublicEmptyConstructor() { + return true; + } + +} diff --git a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor index cab1d83ed7..d5234fca5b 100644 --- a/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor +++ b/processor/src/main/resources/META-INF/services/org.mapstruct.ap.internal.processor.ModelElementProcessor @@ -3,6 +3,7 @@ # Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 org.mapstruct.ap.internal.processor.CdiComponentProcessor +org.mapstruct.ap.internal.processor.JakartaCdiComponentProcessor org.mapstruct.ap.internal.processor.Jsr330ComponentProcessor org.mapstruct.ap.internal.processor.JakartaComponentProcessor org.mapstruct.ap.internal.processor.MapperCreationProcessor diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java index 548ee61f2e..25489a5b6b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/ConstantTest.java @@ -34,7 +34,7 @@ public void constantsShouldBeEqual() { } @Test - public void componentModelContantsShouldBeEqual() { + public void componentModelConstantsShouldBeEqual() { assertThat( MappingConstants.ComponentModel.DEFAULT ) .isEqualTo( MappingConstantsGem.ComponentModelGem.DEFAULT ); assertThat( MappingConstants.ComponentModel.CDI ).isEqualTo( MappingConstantsGem.ComponentModelGem.CDI ); @@ -42,5 +42,7 @@ public void componentModelContantsShouldBeEqual() { assertThat( MappingConstants.ComponentModel.JSR330 ).isEqualTo( MappingConstantsGem.ComponentModelGem.JSR330 ); assertThat( MappingConstants.ComponentModel.JAKARTA ) .isEqualTo( MappingConstantsGem.ComponentModelGem.JAKARTA ); + assertThat( MappingConstants.ComponentModel.JAKARTA_CDI ) + .isEqualTo( MappingConstantsGem.ComponentModelGem.JAKARTA_CDI ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CdiDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CdiDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..bf8b292ec7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CdiDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi._default; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithCdi; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jakarta-cdi. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2950") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerCdiDefaultCompileOptionFieldMapper.class, + GenderCdiDefaultCompileOptionFieldMapper.class +}) +@WithCdi +public class CdiDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerCdiDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import javax.enterprise.context.ApplicationScoped;" ) + .contains( "import javax.inject.Inject;" ) + .contains( "@Inject" + lineSeparator() + " private GenderCdiDefaultCompileOptionFieldMapper" ) + .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) + .doesNotContain( "public CustomerCdiDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "jakarta.inject" ) + .doesNotContain( "jakarta.enterprise" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CustomerCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CustomerCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..ed0ed0a76e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/CustomerCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.CDI, + uses = GenderCdiDefaultCompileOptionFieldMapper.class) +public interface CustomerCdiDefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/GenderCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/GenderCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..14d6a2e0d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/_default/GenderCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.CDI) +public interface GenderCdiDefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/CustomerCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/CustomerCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..4c893b7486 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/CustomerCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.CDI, + uses = GenderCdiDefaultCompileOptionFieldMapper.class) +public interface CustomerCdiDefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/GenderCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/GenderCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..8664b0b433 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/GenderCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.CDI) +public interface GenderCdiDefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..55480399a3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithCdi; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaCdi; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jsr330. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2950") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerCdiDefaultCompileOptionFieldMapper.class, + GenderCdiDefaultCompileOptionFieldMapper.class +}) +@WithJakartaCdi +@WithCdi +public class JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveCdiInjection() { + generatedSource.forMapper( CustomerCdiDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import javax.enterprise.context.ApplicationScoped;" ) + .contains( "import javax.inject.Inject;" ) + .contains( "@Inject" + lineSeparator() + " private GenderCdiDefaultCompileOptionFieldMapper" ) + .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) + .doesNotContain( "public CustomerCdiDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "jakarta.inject" ) + .doesNotContain( "jakarta.enterprise" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiCdiDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiCdiDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..953747e404 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/cdi/jakarta/JakartaCdiCdiDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.cdi.jakarta; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaCdi; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jsr330. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2950") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerCdiDefaultCompileOptionFieldMapper.class, + GenderCdiDefaultCompileOptionFieldMapper.class +}) +@WithJakartaCdi +public class JakartaCdiCdiDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaCdiInjection() { + generatedSource.forMapper( CustomerCdiDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.enterprise.context.ApplicationScoped;" ) + .contains( "import jakarta.inject.Inject;" ) + .contains( "@Inject" + lineSeparator() + " private GenderCdiDefaultCompileOptionFieldMapper" ) + .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) + .doesNotContain( "public CustomerCdiDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ) + .doesNotContain( "javax.enterprise" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/CustomerJakartaCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/CustomerJakartaCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..9ec0709f52 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/CustomerJakartaCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta_cdi._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA_CDI, + uses = GenderJakartaCdiDefaultCompileOptionFieldMapper.class) +public interface CustomerJakartaCdiDefaultCompileOptionFieldMapper { + + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/GenderJakartaCdiDefaultCompileOptionFieldMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/GenderJakartaCdiDefaultCompileOptionFieldMapper.java new file mode 100644 index 0000000000..0c1aef6ec6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/GenderJakartaCdiDefaultCompileOptionFieldMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta_cdi._default; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) +public interface GenderJakartaCdiDefaultCompileOptionFieldMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..b542c99c2a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta_cdi._default; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithCdi; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaCdi; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jakarta. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2950") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaCdiDefaultCompileOptionFieldMapper.class, + GenderJakartaCdiDefaultCompileOptionFieldMapper.class +}) +@WithJakartaCdi +@WithCdi +public class JakartaCdiAndCdiDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveJakartaInjection() { + generatedSource.forMapper( CustomerJakartaCdiDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.enterprise.context.ApplicationScoped;" ) + .contains( "import jakarta.inject.Inject;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaCdiDefaultCompileOptionFieldMapper" ) + .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) + .doesNotContain( "javax.inject" ) + .doesNotContain( "javax.enterprise" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiDefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiDefaultCompileOptionFieldMapperTest.java new file mode 100644 index 0000000000..57714cdb01 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/_default/JakartaCdiDefaultCompileOptionFieldMapperTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta_cdi._default; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaCdi; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test field injection for component model jakarta-cdi. + * Default value option mapstruct.defaultInjectionStrategy is "field" + * + * @author Filip Hrisafov + */ +@IssueKey("2950") +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaCdiDefaultCompileOptionFieldMapper.class, + GenderJakartaCdiDefaultCompileOptionFieldMapper.class +}) +@WithJakartaCdi +public class JakartaCdiDefaultCompileOptionFieldMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveFieldInjection() { + generatedSource.forMapper( CustomerJakartaCdiDefaultCompileOptionFieldMapper.class ) + .content() + .contains( "import jakarta.enterprise.context.ApplicationScoped;" ) + .contains( "import jakarta.inject.Inject;" ) + .contains( "@Inject" + lineSeparator() + " private GenderJakartaCdiDefaultCompileOptionFieldMapper" ) + .contains( "@ApplicationScoped" + lineSeparator() + "public class" ) + .doesNotContain( "public CustomerJakartaCdiDefaultCompileOptionFieldMapperImpl(" ) + .doesNotContain( "javax.inject" ) + .doesNotContain( "javax.enterprise" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithCdi.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithCdi.java new file mode 100644 index 0000000000..6da78fbfe0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithCdi.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "javax.inject", + "cdi-api", +}) +public @interface WithCdi { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaCdi.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaCdi.java new file mode 100644 index 0000000000..f22a1d26e1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaCdi.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "jakarta.inject-api", + "jakarta.enterprise.cdi-api", +}) +public @interface WithJakartaCdi { + +} From fd4a2548b3a1317cf4c419ef022889680fc6b056 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Aug 2022 11:16:48 +0200 Subject: [PATCH 0702/1006] #2928 Add IntelliJ and Eclipse plugin information --- .../main/asciidoc/chapter-2-set-up.asciidoc | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 48b352bd94..601bc42a99 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -273,3 +273,28 @@ disableBuilders` MapStruct can be used with Java 9 and higher versions. To allow usage of the `@Generated` annotation `java.annotation.processing.Generated` (part of the `java.compiler` module) can be enabled. + +=== IDE Integration + +There are optional MapStruct plugins for IntelliJ and Eclipse that allow you to have additional completion support (and more) in the annotations. + +==== IntelliJ + +The https://plugins.jetbrains.com/plugin/10036-mapstruct-support[MapStruct IntelliJ] plugin offers assistance in projects that use MapStruct. + +Some features include: + +* Code completion in `target`, `source`, `expression` +* Go To Declaration for properties in `target` and `source` +* Find Usages of properties in `target` and `source` +* Refactoring support +* Errors and Quick Fixes + +==== Eclipse + +The https://marketplace.eclipse.org/content/mapstruct-eclipse-plugin[MapStruct Eclipse] Plugin offers assistance in projects that use MapStruct. + +Some features include: + +* Code completion in `target` and `source` +* Quick Fixes From 237543c47cb1827189e8c8d81b5b5b9c2eabadf1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 Aug 2022 18:59:31 +0200 Subject: [PATCH 0703/1006] #2897 Always import types defined in `Mapper#imports` --- .../ap/internal/model/common/TypeFactory.java | 19 ++++++++++- .../processor/MapperCreationProcessor.java | 2 +- .../ap/test/bugs/_2897/Issue2897Mapper.java | 23 +++++++++++++ .../ap/test/bugs/_2897/Issue2897Test.java | 33 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2897/Source.java | 22 +++++++++++++ .../mapstruct/ap/test/bugs/_2897/Target.java | 22 +++++++++++++ .../ap/test/bugs/_2897/util/Util.java | 21 ++++++++++++ 7 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/util/Util.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index b209626725..f28e0c687e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -193,7 +193,24 @@ public Type getType(TypeMirror mirror) { return getType( mirror, false ); } + /** + * Return a type that is always going to be imported. + * This is useful when using it in {@code Mapper#imports} + * for types that should be used in expressions. + * + * @param mirror the type mirror for which we need a type + * + * @return the type + */ + public Type getAlwaysImportedType(TypeMirror mirror) { + return getType( mirror, false, true ); + } + private Type getType(TypeMirror mirror, boolean isLiteral) { + return getType( mirror, isLiteral, null ); + } + + private Type getType(TypeMirror mirror, boolean isLiteral, Boolean alwaysImport) { if ( !canBeProcessed( mirror ) ) { throw new TypeHierarchyErroneousException( mirror ); } @@ -212,7 +229,7 @@ private Type getType(TypeMirror mirror, boolean isLiteral) { String qualifiedName; TypeElement typeElement; Type componentType; - Boolean toBeImported = null; + Boolean toBeImported = alwaysImport; if ( mirror.getKind() == TypeKind.DECLARED ) { DeclaredType declaredType = (DeclaredType) mirror; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index c05d2d18bd..b69ba388b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -307,7 +307,7 @@ private SortedSet getExtraImports(TypeElement element, MapperOptions mapp for ( TypeMirror extraImport : mapperOptions.imports() ) { - Type type = typeFactory.getType( extraImport ); + Type type = typeFactory.getAlwaysImportedType( extraImport ); extraImports.add( type ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Mapper.java new file mode 100644 index 0000000000..e13f2083ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Mapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2897; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.bugs._2897.util.Util; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(imports = Util.Factory.class) +public interface Issue2897Mapper { + + Issue2897Mapper INSTANCE = Mappers.getMapper( Issue2897Mapper.class ); + + @Mapping( target = "value", expression = "java(Factory.parse( source ))") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Test.java new file mode 100644 index 0000000000..718ece4a90 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Issue2897Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2897; + +import org.mapstruct.ap.test.bugs._2897.util.Util; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2897") +@WithClasses({ + Util.class, + Issue2897Mapper.class, + Source.class, + Target.class, +}) +class Issue2897Test { + + @ProcessorTest + void shouldImportNestedClassInMapperImports() { + Target target = Issue2897Mapper.INSTANCE.map( new Source( "test" ) ); + + assertThat( target.getValue() ).isEqualTo( "parsed(test)" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Source.java new file mode 100644 index 0000000000..5d46ad1ba3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2897; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Target.java new file mode 100644 index 0000000000..71fbabbe57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2897; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/util/Util.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/util/Util.java new file mode 100644 index 0000000000..5ef0c7e254 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2897/util/Util.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2897.util; + +import org.mapstruct.ap.test.bugs._2897.Source; + +/** + * @author Filip Hrisafov + */ +public class Util { + + public static class Factory { + + public static String parse(Source source) { + return source == null ? null : "parsed(" + source.getValue() + ")"; + } + } +} From b24e831cf0960cc25a4967fe6e1f11c536c0b118 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 Aug 2022 19:11:52 +0200 Subject: [PATCH 0704/1006] #2937 Fix conditional check for collections with adders --- .../ap/internal/model/MethodReference.ftl | 1 + .../model/MethodReferencePresenceCheck.ftl | 1 + .../ap/internal/model/common/SourceRHS.ftl | 2 +- .../ap/test/bugs/_2937/Issue2937Mapper.java | 59 +++++++++++++++++++ .../ap/test/bugs/_2937/Issue2937Test.java | 42 +++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Test.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 80f893f1a2..4b45643dc8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -64,6 +64,7 @@ --> <#macro _assignment assignmentToUse> <@includeModel object=assignmentToUse + presenceCheck=ext.presenceCheck targetBeanName=ext.targetBeanName existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl index 24f871e214..9a1c7b24ae 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -7,5 +7,6 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> <@includeModel object=methodReference + presenceCheck=true targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl index 0b60bd39ae..aaf1eb8df4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/SourceRHS.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.SourceRHS" --> -<#if sourceLoopVarName??>${sourceLoopVarName}<#elseif sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file +<#if sourceLoopVarName?? && !ext.presenceCheck??>${sourceLoopVarName}<#elseif sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Mapper.java new file mode 100644 index 0000000000..95d767acb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Mapper.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2937; + +import java.util.ArrayList; +import java.util.Collection; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue2937Mapper { + + Issue2937Mapper INSTANCE = Mappers.getMapper( Issue2937Mapper.class ); + + Target map(Source source); + + @Condition + default boolean isApplicable(Collection collection) { + return collection == null || collection.size() > 1; + } + + class Source { + private final Collection names; + + public Source(Collection names) { + this.names = names; + } + + public Collection getNames() { + return names; + } + + } + + class Target { + private final Collection names; + + public Target() { + this.names = new ArrayList<>(); + } + + public Collection getNames() { + return names; + } + + public void addName(String name) { + this.names.add( name ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Test.java new file mode 100644 index 0000000000..140575263c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2937/Issue2937Test.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2937; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2937") +@WithClasses({ + Issue2937Mapper.class, +}) +class Issue2937Test { + + @ProcessorTest + void shouldCorrectlyUseConditionalForAdder() { + List sourceNames = new ArrayList<>(); + sourceNames.add( "Tester 1" ); + Issue2937Mapper.Source source = new Issue2937Mapper.Source( sourceNames ); + Issue2937Mapper.Target target = Issue2937Mapper.INSTANCE.map( source ); + + assertThat( target.getNames() ).isEmpty(); + + sourceNames.add( "Tester 2" ); + + target = Issue2937Mapper.INSTANCE.map( source ); + + assertThat( target.getNames() ) + .containsExactly( "Tester 1", "Tester 2" ); + } +} From 71b1a7b8a2f33016d38f01590f641e0e20d424ae Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Aug 2022 09:50:06 +0200 Subject: [PATCH 0705/1006] #2945 Stabilise top level imports Make sure that GeneratedType always gets the imported types from a Type before adding them --- .../ap/internal/model/GeneratedType.java | 6 ++-- .../ap/test/bugs/_2945/Issue2945Mapper.java | 22 ++++++++++++ .../ap/test/bugs/_2945/Issue2945Test.java | 35 +++++++++++++++++++ .../test/bugs/_2945/_target/EnumHolder.java | 13 +++++++ .../ap/test/bugs/_2945/_target/Target.java | 18 ++++++++++ .../ap/test/bugs/_2945/source/Source.java | 22 ++++++++++++ 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/EnumHolder.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/source/Source.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index f8f65c927f..df6ed9b2b1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -258,8 +258,10 @@ protected void addIfImportRequired(Collection collection, Type typeToAdd) return; } - if ( needsImportDeclaration( typeToAdd ) ) { - collection.add( typeToAdd ); + for ( Type type : typeToAdd.getImportTypes() ) { + if ( needsImportDeclaration( type ) ) { + collection.add( type ); + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Mapper.java new file mode 100644 index 0000000000..604d546273 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2945; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2945._target.Target; +import org.mapstruct.ap.test.bugs._2945.source.Source; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2945Mapper { + + Issue2945Mapper INSTANCE = Mappers.getMapper( Issue2945Mapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Test.java new file mode 100644 index 0000000000..11dcf752c0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/Issue2945Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2945; + +import org.mapstruct.ap.test.bugs._2945._target.EnumHolder; +import org.mapstruct.ap.test.bugs._2945._target.Target; +import org.mapstruct.ap.test.bugs._2945.source.Source; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2945") +@WithClasses({ + EnumHolder.class, + Issue2945Mapper.class, + Source.class, + Target.class, +}) +class Issue2945Test { + + @ProcessorTest + void shouldCompile() { + Target target = Issue2945Mapper.INSTANCE.map( new Source( "VALUE_1" ) ); + + assertThat( target.getProperty() ).isEqualTo( EnumHolder.Property.VALUE_1 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/EnumHolder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/EnumHolder.java new file mode 100644 index 0000000000..0b75e9ce36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/EnumHolder.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2945._target; + +public class EnumHolder { + public enum Property { + VALUE_1, + VALUE_2; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/Target.java new file mode 100644 index 0000000000..25b69eed29 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/_target/Target.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2945._target; + +public class Target { + private EnumHolder.Property property; + + public EnumHolder.Property getProperty() { + return property; + } + + public void setProperty(EnumHolder.Property property) { + this.property = property; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/source/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/source/Source.java new file mode 100644 index 0000000000..8364941ad1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2945/source/Source.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2945.source; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final String property; + + public Source(String property) { + this.property = property; + } + + public String getProperty() { + return property; + } +} From 42500ca755a68eef115261adea79ff80892ddd49 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 Aug 2022 18:54:33 +0200 Subject: [PATCH 0706/1006] #2907 Add test case for nested import of array --- .../ap/test/bugs/_2907/Issue2907Test.java | 35 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2907/Source.java | 21 +++++++++++ .../ap/test/bugs/_2907/SourceNested.java | 19 ++++++++++ .../mapstruct/ap/test/bugs/_2907/Target.java | 31 ++++++++++++++++ .../bugs/_2907/mapper/Issue2907Mapper.java | 17 +++++++++ 5 files changed, 123 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Issue2907Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/SourceNested.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/mapper/Issue2907Mapper.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Issue2907Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Issue2907Test.java new file mode 100644 index 0000000000..a005b6a1ad --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Issue2907Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2907; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.bugs._2907.mapper.Issue2907Mapper; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2907") +@WithClasses({ + Issue2907Mapper.class, + Source.class, + SourceNested.class, + Target.class, +}) +class Issue2907Test { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void shouldNotGeneratedImportForNestedClass() { + generatedSource.forMapper( Issue2907Mapper.class ) + .containsNoImportFor( Target.TargetNested.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Source.java new file mode 100644 index 0000000000..42d015fde7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Source.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2907; + +import java.util.Set; + +public class Source { + + private Set nested; + + public Set getNested() { + return nested; + } + + public void setNested(Set nested) { + this.nested = nested; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/SourceNested.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/SourceNested.java new file mode 100644 index 0000000000..a58a94f0f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/SourceNested.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2907; + +public class SourceNested { + + private String prop; + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Target.java new file mode 100644 index 0000000000..80a796d20d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/Target.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2907; + +public class Target { + + private TargetNested[] nested; + + public TargetNested[] getNested() { + return nested; + } + + public void setNested(TargetNested[] nested) { + this.nested = nested; + } + + public static class TargetNested { + private String prop; + + public String getProp() { + return prop; + } + + public void setProp(String prop) { + this.prop = prop; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/mapper/Issue2907Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/mapper/Issue2907Mapper.java new file mode 100644 index 0000000000..5244f95bb4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2907/mapper/Issue2907Mapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2907.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._2907.Source; +import org.mapstruct.ap.test.bugs._2907.Target; + +@Mapper +public interface Issue2907Mapper { + + Target map(Source source); + +} From 853e7b27df3f7a053bec28846a646588557fcfca Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 Aug 2022 19:39:09 +0200 Subject: [PATCH 0707/1006] #2925 Fix IllegalArgumentException when resolving generic parameters When resolving the parameter for a method like: ``` Optional from(T value) ``` There was an exception in javac because getting a DeclaredType from an Optional with a primitive type argument throws an exception. Therefore, when assigning the type arguments we get the boxed equivalent. This problem does not happen in the Eclipse compiler --- .../internal/model/source/MethodMatcher.java | 4 ++- .../ap/test/bugs/_2925/Issue2925Mapper.java | 23 +++++++++++++ .../ap/test/bugs/_2925/Issue2925Test.java | 32 +++++++++++++++++++ .../mapstruct/ap/test/bugs/_2925/Source.java | 19 +++++++++++ .../mapstruct/ap/test/bugs/_2925/Target.java | 22 +++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index f0d9536799..baa3d7eac5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -374,7 +374,9 @@ else if ( typeFromCandidateMethodTypeParameter.isWildCardBoundByTypeVar() // something went wrong return null; } - typeArgs[i] = matchingType.getTypeMirror(); + // Use the boxed equivalent for the type arguments, + // because a primitive type cannot be a type argument + typeArgs[i] = matchingType.getBoxedEquivalent().getTypeMirror(); } else { // it is not a type var (e.g. Map ), String is not a type var diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Mapper.java new file mode 100644 index 0000000000..d231413820 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Mapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2925; + +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue2925Mapper { + + Issue2925Mapper INSTANCE = Mappers.getMapper( Issue2925Mapper.class ); + + Target map(Source source); + + static Optional toOptional(T value) { + return Optional.ofNullable( value ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Test.java new file mode 100644 index 0000000000..73d009d093 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Issue2925Test.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2925; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2925") +@WithClasses({ + Issue2925Mapper.class, + Source.class, + Target.class, +}) +class Issue2925Test { + + @ProcessorTest + void shouldUseOptionalWrappingMethod() { + Target target = Issue2925Mapper.INSTANCE.map( new Source( 10L ) ); + + assertThat( target.getValue() ) + .hasValue( 10L ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Source.java new file mode 100644 index 0000000000..c21ce67775 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Source.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2925; + +public class Source { + + private final long value; + + public Source(long value) { + this.value = value; + } + + public long getValue() { + return value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Target.java new file mode 100644 index 0000000000..4693a83fdb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2925/Target.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2925; + +import java.util.Optional; + +public class Target { + + private Long value; + + public Optional getValue() { + return Optional.ofNullable( value ); + } + + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public void setValue(Optional value) { + this.value = value.orElse( null ); + } +} From 3f798744ac347fbddaa7e9f79383c0798e479f18 Mon Sep 17 00:00:00 2001 From: Taihao Zhang <46465678+zhtaihao@users.noreply.github.com> Date: Wed, 24 Aug 2022 19:40:08 +0200 Subject: [PATCH 0708/1006] Fix typo in docs (#2982) --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 9c1b2243eb..a6e42b6d48 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -304,7 +304,7 @@ The difference is that it allows users to write custom condition methods that wi A custom condition method is a method that is annotated with `org.mapstruct.Condition` and returns `boolean`. -e.g. if you only want to map a String property when it is not `null, and it is not empty then you can do something like: +e.g. if you only want to map a String property when it is not `null`, and it is not empty then you can do something like: .Mapper using custom condition check method ==== From 4fa66229d9e3949f451fe8b79b62dcbbd138b669 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 26 Aug 2022 19:35:54 +0200 Subject: [PATCH 0709/1006] #2990 Stabilise top level imports --- .../mapstruct/ap/internal/model/common/Type.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index ce82fff621..fd7f3d6904 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -181,9 +181,16 @@ public Type(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFact this.loggingVerbose = loggingVerbose; - // The top level type for an array type is the top level type of the component type - TypeElement typeElementForTopLevel = - this.componentType == null ? this.typeElement : this.componentType.getTypeElement(); + TypeElement typeElementForTopLevel; + if ( Boolean.TRUE.equals( isToBeImported ) ) { + // If the is to be imported is explicitly set to true then we shouldn't look for the top level type + typeElementForTopLevel = null; + } + else { + // The top level type for an array type is the top level type of the component type + typeElementForTopLevel = + this.componentType == null ? this.typeElement : this.componentType.getTypeElement(); + } this.topLevelType = topLevelType( typeElementForTopLevel, this.typeFactory ); this.nameWithTopLevelTypeName = nameWithTopLevelTypeName( typeElementForTopLevel, this.name ); } From 4708f4b2aa1d165b17f8d42586085c2c8d8aaf2a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 25 Aug 2022 08:40:50 +0200 Subject: [PATCH 0710/1006] #2950 Disable CDI in the full features tests on Java 8 --- .../tests/FullFeatureCompilationExclusionCliEnhancer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index c8bac6208c..0f261d6568 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -28,6 +28,10 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1801/*.java" ); switch ( currentJreVersion ) { + case JAVA_8: + additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/cdi/**/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); + break; case JAVA_9: // TODO find out why this fails: additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); From ac356cab2529e1ab71205e2f9389686fe3b303c3 Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:33:46 +0800 Subject: [PATCH 0711/1006] #2983 Add `@AnnotateWith` support to non bean mapping methods --- .../model/AbstractMappingMethodBuilder.java | 14 ++++++ .../ap/internal/model/BeanMappingMethod.java | 16 +------ .../model/ContainerMappingMethod.java | 5 +- .../internal/model/IterableMappingMethod.java | 5 +- .../ap/internal/model/MapMappingMethod.java | 6 ++- .../model/NormalTypeMappingMethod.java | 13 +++++- .../internal/model/StreamMappingMethod.java | 21 +++++---- .../ap/internal/model/ValueMappingMethod.java | 20 +++++++- .../internal/model/IterableMappingMethod.ftl | 3 ++ .../ap/internal/model/MapMappingMethod.ftl | 3 ++ .../ap/internal/model/StreamMappingMethod.ftl | 3 ++ .../ap/internal/model/ValueMappingMethod.ftl | 3 ++ .../AnnotateBeanMappingMethodMapper.java | 46 +++++++++++++++++++ .../AnnotateIterableMappingMethodMapper.java | 21 +++++++++ .../AnnotateMapMappingMethodMapper.java | 24 ++++++++++ .../AnnotateStreamMappingMethodMapper.java | 21 +++++++++ .../AnnotateValueMappingMethodMapper.java | 26 +++++++++++ .../test/annotatewith/AnnotateWithTest.java | 46 ++++++++++++++++++- 18 files changed, 264 insertions(+), 32 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateBeanMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateIterableMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateMapMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateStreamMappingMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateValueMappingMethodMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index efc7a71469..6efb67ba9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -13,6 +13,9 @@ import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.util.Strings; +import java.util.ArrayList; +import java.util.List; + /** * An abstract builder that can be reused for building {@link MappingMethod}(s). * @@ -117,4 +120,15 @@ public ForgedMethodHistory getDescription() { return description; } + public List getMethodAnnotations() { + AdditionalAnnotationsBuilder additionalAnnotationsBuilder = + new AdditionalAnnotationsBuilder( + ctx.getElementUtils(), + ctx.getTypeFactory(), + ctx.getMessager() ); + List annotations = new ArrayList<>(); + annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); + return annotations; + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index e748c173af..4f2dc4e5f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -85,7 +85,6 @@ */ public class BeanMappingMethod extends NormalTypeMappingMethod { - private final List annotations; private final List propertyMappings; private final Map> mappingsByParameter; private final Map> constructorMappingsByParameter; @@ -113,7 +112,6 @@ public static class Builder extends AbstractMappingMethodBuilder unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); - private final List annotations = new ArrayList<>(); private MappingReferences mappingReferences; private MethodReference factoryMethod; @@ -216,12 +214,6 @@ else if ( !method.isUpdateMethod() ) { // If the return type cannot be constructed then no need to try to create mappings return null; } - AdditionalAnnotationsBuilder additionalAnnotationsBuilder = - new AdditionalAnnotationsBuilder( - ctx.getElementUtils(), - ctx.getTypeFactory(), - ctx.getMessager() ); - annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); /* the type that needs to be used in the mapping process as target */ Type resultTypeToMap = returnTypeToConstruct == null ? method.getResultType() : returnTypeToConstruct; @@ -370,7 +362,7 @@ else if ( !method.isUpdateMethod() ) { return new BeanMappingMethod( method, - annotations, + getMethodAnnotations(), existingVariableNames, propertyMappings, factoryMethod, @@ -1724,6 +1716,7 @@ private BeanMappingMethod(Method method, List subclassMappings) { super( method, + annotations, existingVariableNames, factoryMethod, mapNullToDefault, @@ -1732,7 +1725,6 @@ private BeanMappingMethod(Method method, ); //CHECKSTYLE:ON - this.annotations = annotations; this.propertyMappings = propertyMappings; this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; @@ -1771,10 +1763,6 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { this.subclassMappings = subclassMappings; } - public List getAnnotations() { - return annotations; - } - public List getConstantMappings() { return constantMappings; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 382aff9737..21e547eea0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -32,12 +32,13 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { private final String index2Name; private IterableCreation iterableCreation; - ContainerMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + ContainerMappingMethod(Method method, List annotations, + Collection existingVariables, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters) { - super( method, existingVariables, factoryMethod, mapNullToDefault, beforeMappingReferences, + super( method, annotations, existingVariables, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); this.elementAssignment = parameterAssignment; this.loopVariableName = loopVariableName; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java index 38ec44f1e1..10e64b7008 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/IterableMappingMethod.java @@ -57,6 +57,7 @@ protected IterableMappingMethod instantiateMappingMethod(Method method, Collecti List afterMappingMethods, SelectionParameters selectionParameters) { return new IterableMappingMethod( method, + getMethodAnnotations(), existingVariables, assignment, factoryMethod, @@ -69,13 +70,15 @@ protected IterableMappingMethod instantiateMappingMethod(Method method, Collecti } } - private IterableMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + private IterableMappingMethod(Method method, List annotations, + Collection existingVariables, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters) { super( method, + annotations, existingVariables, parameterAssignment, factoryMethod, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index a8b68b435f..85766e2eca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -199,6 +199,7 @@ public MapMappingMethod build() { return new MapMappingMethod( method, + getMethodAnnotations(), existingVariables, keyAssignment, valueAssignment, @@ -224,11 +225,12 @@ protected boolean shouldUsePropertyNamesInHistory() { } - private MapMappingMethod(Method method, Collection existingVariableNames, Assignment keyAssignment, + private MapMappingMethod(Method method, List annotations, + Collection existingVariableNames, Assignment keyAssignment, Assignment valueAssignment, MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, List afterMappingReferences) { - super( method, existingVariableNames, factoryMethod, mapNullToDefault, beforeMappingReferences, + super( method, annotations, existingVariableNames, factoryMethod, mapNullToDefault, beforeMappingReferences, afterMappingReferences ); this.keyAssignment = keyAssignment; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index fcd8d70d52..79cd0e0566 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -24,7 +24,10 @@ public abstract class NormalTypeMappingMethod extends MappingMethod { private final boolean overridden; private final boolean mapNullToDefault; - NormalTypeMappingMethod(Method method, Collection existingVariableNames, MethodReference factoryMethod, + private final List annotations; + + NormalTypeMappingMethod(Method method, List annotations, + Collection existingVariableNames, MethodReference factoryMethod, boolean mapNullToDefault, List beforeMappingReferences, List afterMappingReferences) { @@ -32,6 +35,7 @@ public abstract class NormalTypeMappingMethod extends MappingMethod { this.factoryMethod = factoryMethod; this.overridden = method.overridesMethod(); this.mapNullToDefault = mapNullToDefault; + this.annotations = annotations; } @Override @@ -45,6 +49,9 @@ public Set getImportTypes() { else if ( factoryMethod != null ) { types.addAll( factoryMethod.getImportTypes() ); } + for ( Annotation annotation : annotations ) { + types.addAll( annotation.getImportTypes() ); + } return types; } @@ -60,6 +67,10 @@ public MethodReference getFactoryMethod() { return this.factoryMethod; } + public List getAnnotations() { + return annotations; + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java index 552040d8ce..57ee9ccdf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/StreamMappingMethod.java @@ -5,6 +5,12 @@ */ package org.mapstruct.ap.internal.model; +import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; + import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -13,12 +19,6 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper; -import org.mapstruct.ap.internal.model.common.Assignment; -import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.source.Method; -import org.mapstruct.ap.internal.model.source.SelectionParameters; - import static org.mapstruct.ap.internal.util.Collections.first; /** @@ -63,9 +63,9 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Collection sourceParameterType.isIterableType() ) { helperImports.add( ctx.getTypeFactory().getType( StreamSupport.class ) ); } - return new StreamMappingMethod( method, + getMethodAnnotations(), existingVariables, assignment, factoryMethod, @@ -78,14 +78,16 @@ protected StreamMappingMethod instantiateMappingMethod(Method method, Collection ); } } - - private StreamMappingMethod(Method method, Collection existingVariables, Assignment parameterAssignment, + //CHECKSTYLE:OFF + private StreamMappingMethod(Method method, List annotations, + Collection existingVariables, Assignment parameterAssignment, MethodReference factoryMethod, boolean mapNullToDefault, String loopVariableName, List beforeMappingReferences, List afterMappingReferences, SelectionParameters selectionParameters, Set helperImports) { super( method, + annotations, existingVariables, parameterAssignment, factoryMethod, @@ -95,6 +97,7 @@ private StreamMappingMethod(Method method, Collection existingVariables, afterMappingReferences, selectionParameters ); + //CHECKSTYLE:ON this.helperImports = helperImports; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 0d71ed5506..f61e80c2d4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -41,6 +41,7 @@ */ public class ValueMappingMethod extends MappingMethod { + private final List annotations; private final List valueMappings; private final MappingEntry defaultTarget; private final MappingEntry nullTarget; @@ -116,9 +117,16 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); - + AdditionalAnnotationsBuilder additionalAnnotationsBuilder = + new AdditionalAnnotationsBuilder( + ctx.getElementUtils(), + ctx.getTypeFactory(), + ctx.getMessager() ); + List annotations = new ArrayList<>(); + annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); // finally return a mapping return new ValueMappingMethod( method, + annotations, mappingEntries, valueMappings.nullValueTarget, valueMappings.defaultTargetValue, @@ -532,6 +540,7 @@ String getValue(ValueMappingOptions valueMapping) { } private ValueMappingMethod(Method method, + List annotations, List enumMappings, String nullTarget, String defaultTarget, @@ -544,6 +553,7 @@ private ValueMappingMethod(Method method, this.defaultTarget = new MappingEntry( null, defaultTarget != null ? defaultTarget : THROW_EXCEPTION); this.unexpectedValueMappingException = unexpectedValueMappingException; this.overridden = method.overridesMethod(); + this.annotations = annotations; } @Override @@ -556,7 +566,9 @@ public Set getImportTypes() { importTypes.addAll( unexpectedValueMappingException.getImportTypes() ); } } - + for ( Annotation annotation : annotations ) { + importTypes.addAll( annotation.getImportTypes() ); + } return importTypes; } @@ -590,6 +602,10 @@ public boolean isOverridden() { return overridden; } + public List getAnnotations() { + return annotations; + } + public static class MappingEntry { private final String source; private final String target; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 495111b7a1..9af6e762bf 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -6,6 +6,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.IterableMappingMethod" --> +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 443d87cba7..0e388da103 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -6,6 +6,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MapMappingMethod" --> +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index 860859fc3a..7b5b44bd56 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -6,6 +6,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.StreamMappingMethod" --> +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable--> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 4d961c40af..2c3e2b6410 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -6,6 +6,9 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ValueMappingMethod" --> +<#list annotations as annotation> + <#nt><@includeModel object=annotation/> + <#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateBeanMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateBeanMappingMethodMapper.java new file mode 100644 index 0000000000..cc19c2d282 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateBeanMappingMethodMapper.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +/** + * @author orange add + */ +@Mapper +public interface AnnotateBeanMappingMethodMapper { + + @AnnotateWith(CustomMethodOnlyAnnotation.class) + Target map(Source source); + + class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateIterableMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateIterableMappingMethodMapper.java new file mode 100644 index 0000000000..40c6e60fe6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateIterableMappingMethodMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +import java.util.List; + +/** + * @author orange add + */ +@Mapper +public interface AnnotateIterableMappingMethodMapper { + + @AnnotateWith(CustomMethodOnlyAnnotation.class) + List toStringList(List integers); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateMapMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateMapMappingMethodMapper.java new file mode 100644 index 0000000000..458cb68d4d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateMapMappingMethodMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.MapMapping; +import org.mapstruct.Mapper; + +import java.util.Date; +import java.util.Map; + +/** + * @author orange add + */ +@Mapper +public interface AnnotateMapMappingMethodMapper { + + @MapMapping(valueDateFormat = "dd.MM.yyyy") + @AnnotateWith(CustomMethodOnlyAnnotation.class) + Map longDateMapToStringStringMap(Map source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateStreamMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateStreamMappingMethodMapper.java new file mode 100644 index 0000000000..c574b59697 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateStreamMappingMethodMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +import java.util.stream.Stream; + +/** + * @author orange add + */ +@Mapper +public interface AnnotateStreamMappingMethodMapper { + + @AnnotateWith(CustomMethodOnlyAnnotation.class) + Stream toStringStream(Stream integerStream); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateValueMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateValueMappingMethodMapper.java new file mode 100644 index 0000000000..a9e7c7b519 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateValueMappingMethodMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; + +/** + * @author orange add + */ +@Mapper +public interface AnnotateValueMappingMethodMapper { + + @ValueMappings({ + @ValueMapping(target = "EXISTING", source = "EXISTING"), + @ValueMapping( source = MappingConstants.ANY_REMAINING, target = "OTHER_EXISTING" ) + }) + @AnnotateWith(CustomMethodOnlyAnnotation.class) + AnnotateWithEnum map(String str); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java index c2055b4c5c..31b8d8fad9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.test.annotatewith; import org.junit.jupiter.api.extension.RegisterExtension; - import org.mapstruct.Mapper; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -17,6 +16,11 @@ import org.mapstruct.ap.testutil.runner.GeneratedSource; import org.mapstruct.factory.Mappers; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -545,4 +549,44 @@ public void erroneousMapperWithParameterRepeat() { public void mapperWithIdenticalAnnotationRepeated() { } + @ProcessorTest + @WithClasses( {AnnotateBeanMappingMethodMapper.class, CustomMethodOnlyAnnotation.class} ) + public void beanMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodException { + AnnotateBeanMappingMethodMapper mapper = Mappers.getMapper( AnnotateBeanMappingMethodMapper.class ); + Method method = mapper.getClass().getMethod( "map", AnnotateBeanMappingMethodMapper.Source.class ); + assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); + } + + @ProcessorTest + @WithClasses( {AnnotateIterableMappingMethodMapper.class, CustomMethodOnlyAnnotation.class} ) + public void iterableMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodException { + AnnotateIterableMappingMethodMapper mapper = Mappers.getMapper( AnnotateIterableMappingMethodMapper.class ); + Method method = mapper.getClass().getMethod( "toStringList", List.class ); + assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); + } + + @ProcessorTest + @WithClasses( {AnnotateMapMappingMethodMapper.class, CustomMethodOnlyAnnotation.class} ) + public void mapMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodException { + AnnotateMapMappingMethodMapper mapper = Mappers.getMapper( AnnotateMapMappingMethodMapper.class ); + Method method = mapper.getClass().getMethod( "longDateMapToStringStringMap", Map.class ); + assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); + } + + @ProcessorTest + @WithClasses( {AnnotateStreamMappingMethodMapper.class, CustomMethodOnlyAnnotation.class} ) + public void streamMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodException { + AnnotateStreamMappingMethodMapper mapper = Mappers.getMapper( AnnotateStreamMappingMethodMapper.class ); + Method method = mapper.getClass().getMethod( "toStringStream", Stream.class ); + assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); + } + + @ProcessorTest + @WithClasses( {AnnotateValueMappingMethodMapper.class, AnnotateWithEnum.class, CustomMethodOnlyAnnotation.class} ) + public void valueMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodException { + AnnotateValueMappingMethodMapper mapper = Mappers.getMapper( AnnotateValueMappingMethodMapper.class ); + Method method = mapper.getClass().getMethod( "map", String.class ); + assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); + } + } From 3cc2aa76751b8a2f11f0577303df90737e783e1b Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Sun, 28 Aug 2022 18:41:25 +0800 Subject: [PATCH 0712/1006] #2825 Fix SubclassMapping stackoverflow exception --- .../creation/MappingResolverImpl.java | 6 +-- .../mapstruct/ap/test/bugs/_2825/Animal.java | 21 +++++++++++ .../org/mapstruct/ap/test/bugs/_2825/Cat.java | 21 +++++++++++ .../org/mapstruct/ap/test/bugs/_2825/Dog.java | 21 +++++++++++ .../ap/test/bugs/_2825/Issue2825Mapper.java | 24 ++++++++++++ .../ap/test/bugs/_2825/Issue2825Test.java | 37 +++++++++++++++++++ .../ap/test/bugs/_2825/TargetAnimal.java | 31 ++++++++++++++++ 7 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Animal.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Cat.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Dog.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/TargetAnimal.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 2e2a760bf4..5a2af176f6 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -196,7 +196,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM this.mappingMethod = mappingMethod; this.description = description; - this.methods = filterPossibleCandidateMethods( sourceModel ); + this.methods = filterPossibleCandidateMethods( sourceModel, mappingMethod ); this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; @@ -210,10 +210,10 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM } // CHECKSTYLE:ON - private List filterPossibleCandidateMethods(List candidateMethods) { + private List filterPossibleCandidateMethods(List candidateMethods, T mappingMethod) { List result = new ArrayList<>( candidateMethods.size() ); for ( T candidate : candidateMethods ) { - if ( isCandidateForMapping( candidate ) ) { + if ( isCandidateForMapping( candidate ) && !candidate.equals( mappingMethod )) { result.add( candidate ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Animal.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Animal.java new file mode 100644 index 0000000000..3d60eac9fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Animal.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +/** + * @author orange add + */ +public class Animal { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Cat.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Cat.java new file mode 100644 index 0000000000..ec826c0ffb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Cat.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +/** + * @author orange add + */ +public class Cat extends Animal { + private String race; + + public String getRace() { + return race; + } + + public void setRace(String race) { + this.race = race; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Dog.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Dog.java new file mode 100644 index 0000000000..53b41a98c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Dog.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +/** + * @author orange add + */ +public class Dog extends Animal { + private String race; + + public String getRace() { + return race; + } + + public void setRace(String race) { + this.race = race; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Mapper.java new file mode 100644 index 0000000000..c515011b0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Mapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author orange add + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface Issue2825Mapper { + + Issue2825Mapper INSTANCE = Mappers.getMapper( Issue2825Mapper.class ); + + @SubclassMapping(target = TargetAnimal.class, source = Dog.class) + @SubclassMapping(target = TargetAnimal.class, source = Cat.class) + TargetAnimal map(Animal source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Test.java new file mode 100644 index 0000000000..9c0609b754 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/Issue2825Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author orange add + */ +@IssueKey("2825") +@WithClasses({ + Animal.class, + Cat.class, + Dog.class, + Issue2825Mapper.class, + TargetAnimal.class, +}) +public class Issue2825Test { + + @ProcessorTest + public void mappingMethodShouldNotBeReusedForSubclassMappings() { + Dog dog = new Dog(); + dog.setName( "Lucky" ); + dog.setRace( "Shepherd" ); + TargetAnimal target = Issue2825Mapper.INSTANCE.map( dog ); + assertThat( target.getName() ).isEqualTo( "Lucky" ); + assertThat( target.getRace() ).isEqualTo( "Shepherd" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/TargetAnimal.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/TargetAnimal.java new file mode 100644 index 0000000000..479741099a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2825/TargetAnimal.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2825; + +/** + * @author orange add + */ +public class TargetAnimal { + private String name; + + private String race; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRace() { + return race; + } + + public void setRace(String race) { + this.race = race; + } +} From 68571de01bd9b06cef647a3d9ad073f0f0cd2456 Mon Sep 17 00:00:00 2001 From: Prasanth Omanakuttan Date: Fri, 26 Aug 2022 19:25:58 +0530 Subject: [PATCH 0713/1006] Update Typos in java-doc Closes #2989 --- .../conversion/AbstractJavaTimeToStringConversion.java | 8 ++++---- ...xistingInstanceSetterWrapperForCollectionsAndMaps.java | 2 +- .../assignment/GetterWrapperForCollectionsAndMaps.java | 2 +- .../ap/internal/model/assignment/UpdateWrapper.java | 2 +- .../ap/internal/model/beanmapping/PropertyEntry.java | 2 +- .../ap/internal/model/beanmapping/SourceReference.java | 4 ++-- .../java/org/mapstruct/ap/internal/util/RoundContext.java | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java index 2f530618c9..3503a0e274 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/AbstractJavaTimeToStringConversion.java @@ -21,15 +21,15 @@ *

    *

    * In general each type comes with a "parse" method to convert a string to this particular type. - * For formatting a dedicated instance of {@link java.time.format.DateTimeFormatter} is used. + * For formatting a dedicated instance of {@link DateTimeFormatter} is used. *

    *

    * If no date format for mapping is specified predefined ISO* formatters from - * {@link java.time.format.DateTimeFormatter} are used. + * {@link DateTimeFormatter} are used. *

    *

    - * An overview of date and time types shipped with Java 8 can be found at - * http://docs.oracle.com/javase/tutorial/datetime/iso/index.html. + * An overview of date and time types shipped with Java 8 can be found at the + * Standard Calendar Tutorial *

    */ public abstract class AbstractJavaTimeToStringConversion extends SimpleConversion { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index 06a2712f00..2dd7f81a0b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -22,7 +22,7 @@ /** * This wrapper handles the situation where an assignment is done for an update method. * - * In case of a pre-existing target the wrapper checks if there is an collection or map initialized on the target bean + * In case of a pre-existing target the wrapper checks if there is a collection or map initialized on the target bean * (not null). If so it uses the addAll (for collections) or putAll (for maps). The collection / map is cleared in case * of a pre-existing target {@link org.mapstruct.MappingTarget }before adding the source entries. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index 40e195dcd0..d29a80b420 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -16,7 +16,7 @@ * This wrapper handles the situation were an assignment must be done via a target getter method because there * is no setter available. * - * The wrapper checks if there is an collection or map initialized on the target bean (not null). If so it uses the + * The wrapper checks if there is a collection or map initialized on the target bean (not null). If so it uses the * addAll (for collections) or putAll (for maps). The collection / map is cleared in case of a pre-existing target * {@link org.mapstruct.MappingTarget }before adding the source entries. The goal is that the same collection / map * is used as target. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index cf0140e8ce..ff5089d6c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -54,7 +54,7 @@ private static Type determineImplType(Assignment factoryMethod, Type targetType) return targetType.getImplementationType(); } - // no factory method means we create a new instance ourself and thus need to import the type + // no factory method means we create a new instance ourselves and thus need to import the type return targetType; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java index cb6cd8af79..a3c8a74e3f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/PropertyEntry.java @@ -14,7 +14,7 @@ /** * A PropertyEntry contains information on the name, readAccessor and presenceCheck (for source) - * and return type of a property. + * and return type of property. */ public class PropertyEntry { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 8824f95901..4e7dad220c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -143,7 +143,7 @@ public SourceReference build() { * the parameter name to avoid ambiguity * * consider: {@code Target map( Source1 source1 )} - * entries in an @Mapping#source can be "source1.propx" or just "propx" to be valid + * entries in a @Mapping#source can be "source1.propx" or just "propx" to be valid * * @param segments the segments of @Mapping#source * @param parameter the one and only parameter @@ -213,7 +213,7 @@ private SourceReference buildFromMultipleSourceParameters(String[] segments, Par * needs to match the parameter name to avoid ambiguity * * consider: {@code Target map( Source1 source1, Source2 source2 )} - * entries in an @Mapping#source need to be "source1.propx" or "source2.propy.propz" to be valid + * entries in a @Mapping#source need to be "source1.propx" or "source2.propy.propz" to be valid * * @param segments the segments of @Mapping#source * @return parameter that matches with first segment of @Mapping#source diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java index 78e61fbf29..e34d013bc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RoundContext.java @@ -41,7 +41,7 @@ public void addTypeReadyForProcessing(TypeMirror type) { /** * Whether the given type has been found to be ready for further processing or not. This is the case if the type's - * hierarchy is complete (no super-types need to be generated by other processors) an no processors have signaled + * hierarchy is complete (no super-types need to be generated by other processors) and no processors have signaled * the intention to amend the given type. * * @param type the typed to be checked for its readiness From 21069e5a2ece79d3f4a7f7d247b2f96060ccedbb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 29 Aug 2022 21:15:01 +0200 Subject: [PATCH 0714/1006] #2895 Generate more readable annotations --- .../ap/internal/model/Annotation.ftl | 15 +++++- .../test/annotatewith/AnnotateWithTest.java | 9 +++- .../test/annotatewith/CustomNamedMapper.java | 38 +++++++++++++++ .../annotatewith/CustomNamedMapperImpl.java | 46 ++++++++++++++++++- .../MultipleArrayValuesMapperImpl.java | 14 +++++- 5 files changed, 117 insertions(+), 5 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index eb67d732fc..81f3d2ba8b 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -6,4 +6,17 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> -@<@includeModel object=type/><#if (properties?size > 0) >(<#list properties as property><@includeModel object=property/><#if property_has_next>, ) \ No newline at end of file +<#switch properties?size> + <#case 0> + @<@includeModel object=type/><#rt> + <#break> + <#case 1> + @<@includeModel object=type/>(<@includeModel object=properties[0]/>)<#rt> + <#break> + <#default> + @<@includeModel object=type/>( + <#list properties as property> + <#nt><@includeModel object=property/><#if property_has_next>, + + )<#rt> + \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java index 31b8d8fad9..e3b20f547e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java @@ -42,8 +42,13 @@ public void mapperBecomesDeprecatedAndGetsCustomAnnotation() { } @ProcessorTest - @WithClasses( { CustomNamedMapper.class, CustomAnnotationWithParamsContainer.class, - CustomAnnotationWithParams.class } ) + @WithClasses( { + CustomNamedMapper.class, + CustomAnnotationWithParamsContainer.class, + CustomAnnotationWithParams.class, + CustomClassOnlyAnnotation.class, + CustomMethodOnlyAnnotation.class, + } ) public void annotationWithValue() { generatedSource.addComparisonToFixtureFor( CustomNamedMapper.class ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java index 32241ab4ab..9f48d8c764 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/CustomNamedMapper.java @@ -13,6 +13,7 @@ * @author Ben Zegveld */ @Mapper +@AnnotateWith( CustomClassOnlyAnnotation.class ) @AnnotateWith( value = CustomAnnotationWithParams.class, elements = { @Element( name = "stringArray", strings = "test" ), @Element( name = "stringParam", strings = "test" ), @@ -35,6 +36,43 @@ @Element( name = "shortArray", shorts = 3 ), @Element( name = "shortParam", shorts = 1 ) } ) +@AnnotateWith( value = CustomAnnotationWithParams.class, elements = { + @Element(name = "stringParam", strings = "single value") +}) public interface CustomNamedMapper { + @AnnotateWith(value = CustomAnnotationWithParams.class, elements = { + @Element(name = "stringParam", strings = "double method value"), + @Element(name = "stringArray", strings = { "first", "second" }), + }) + @AnnotateWith(value = CustomAnnotationWithParams.class, elements = { + @Element(name = "stringParam", strings = "single method value") + }) + @AnnotateWith( CustomMethodOnlyAnnotation.class ) + Target map(Source source); + + class Target { + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java index cb01cfec85..a485d6676f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/CustomNamedMapperImpl.java @@ -12,6 +12,50 @@ date = "2022-06-06T16:48:18+0200", comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)" ) -@CustomAnnotationWithParams(stringArray = "test", stringParam = "test", booleanArray = true, booleanParam = true, byteArray = 16, byteParam = 19, charArray = 'd', charParam = 'a', enumArray = AnnotateWithEnum.EXISTING, enumParam = AnnotateWithEnum.EXISTING, doubleArray = 0.3, doubleParam = 1.2, floatArray = 0.300000011920929f, floatParam = 1.2000000476837158f, intArray = 3, intParam = 1, longArray = 3L, longParam = 1L, shortArray = 3, shortParam = 1) +@CustomClassOnlyAnnotation +@CustomAnnotationWithParams( + stringArray = "test", + stringParam = "test", + booleanArray = true, + booleanParam = true, + byteArray = 16, + byteParam = 19, + charArray = 'd', + charParam = 'a', + enumArray = AnnotateWithEnum.EXISTING, + enumParam = AnnotateWithEnum.EXISTING, + doubleArray = 0.3, + doubleParam = 1.2, + floatArray = 0.300000011920929f, + floatParam = 1.2000000476837158f, + intArray = 3, + intParam = 1, + longArray = 3L, + longParam = 1L, + shortArray = 3, + shortParam = 1 +) +@CustomAnnotationWithParams(stringParam = "single value") public class CustomNamedMapperImpl implements CustomNamedMapper { + + @CustomAnnotationWithParams( + stringParam = "double method value", + stringArray = { "first", "second" } + ) + @CustomAnnotationWithParams(stringParam = "single method value") + @CustomMethodOnlyAnnotation + @Override + public Target map(Source source) { + if ( source == null ) { + return null; + } + + String value = null; + + value = source.getValue(); + + Target target = new Target( value ); + + return target; + } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java index fe9bb93f13..ea15207c66 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/annotatewith/MultipleArrayValuesMapperImpl.java @@ -13,6 +13,18 @@ date = "2022-06-06T16:48:23+0200", comments = "version: , compiler: javac, environment: Java 11.0.12 (Azul Systems, Inc.)" ) -@CustomAnnotationWithParams(stringArray = { "test1", "test2" }, booleanArray = { false, true }, byteArray = { 8, 31 }, charArray = { 'b', 'c' }, doubleArray = { 1.2, 3.4 }, floatArray = { 1.2000000476837158f, 3.4000000953674316f }, intArray = { 12, 34 }, longArray = { 12L, 34L }, shortArray = { 12, 34 }, classArray = { Mapper.class, CustomAnnotationWithParams.class }, stringParam = "required parameter") +@CustomAnnotationWithParams( + stringArray = { "test1", "test2" }, + booleanArray = { false, true }, + byteArray = { 8, 31 }, + charArray = { 'b', 'c' }, + doubleArray = { 1.2, 3.4 }, + floatArray = { 1.2000000476837158f, 3.4000000953674316f }, + intArray = { 12, 34 }, + longArray = { 12L, 34L }, + shortArray = { 12, 34 }, + classArray = { Mapper.class, CustomAnnotationWithParams.class }, + stringParam = "required parameter" +) public class MultipleArrayValuesMapperImpl implements MultipleArrayValuesMapper { } From bbf63ae1777981d1d89693d6f9d980064997cf28 Mon Sep 17 00:00:00 2001 From: Iaroslav Bogdanchikov <6546969+ibogdanchikov@users.noreply.github.com> Date: Fri, 2 Sep 2022 22:04:01 +0200 Subject: [PATCH 0715/1006] #2730 Add support for Jakarta XML Binding --- distribution/pom.xml | 8 +- integrationtest/pom.xml | 2 +- .../itest/tests/MavenIntegrationTest.java | 4 + .../test/resources/fullFeatureTest/pom.xml | 17 ++- .../test/resources/jakartaJaxbTest/pom.xml | 64 ++++++++++ .../itest/jakarta/jaxb/OrderDetailsDto.java | 42 +++++++ .../itest/jakarta/jaxb/OrderDto.java | 52 ++++++++ .../itest/jakarta/jaxb/OrderStatusDto.java | 35 ++++++ .../jakarta/jaxb/ShippingAddressDto.java | 50 ++++++++ .../jakarta/jaxb/SourceTargetMapper.java | 50 ++++++++ .../itest/jakarta/jaxb/SubTypeDto.java | 27 ++++ .../itest/jakarta/jaxb/SuperTypeDto.java | 27 ++++ .../src/main/resources/binding/binding.xjb | 28 +++++ .../src/main/resources/schema/test1.xsd | 36 ++++++ .../src/main/resources/schema/test2.xsd | 33 +++++ .../src/main/resources/schema/underscores.xsd | 34 +++++ .../jaxb/JakartaJaxbBasedMapperTest.java | 118 ++++++++++++++++++ .../src/test/resources/jaxbTest/pom.xml | 12 +- parent/pom.xml | 29 ++++- processor/pom.xml | 8 +- .../gem/jakarta/JakartaGemGenerator.java | 26 ++++ .../source/builtin/BuiltInMappingMethods.java | 21 +++- .../model/source/builtin/JaxbElemToValue.java | 11 +- .../JakartaXmlElementDeclSelector.java | 48 +++++++ .../selector/JavaxXmlElementDeclSelector.java | 48 +++++++ .../source/selector/MethodSelectors.java | 3 +- .../selector/XmlElementDeclSelector.java | 65 +++++++--- .../ap/internal/util/JaxbConstants.java | 3 +- .../ap/test/builtin/BuiltInTest.java | 77 ++++++++++++ .../bean/JakartaJaxbElementListProperty.java | 28 +++++ .../bean/JakartaJaxbElementProperty.java | 25 ++++ .../builtin/mapper/JakartaJaxbListMapper.java | 19 +++ .../builtin/mapper/JakartaJaxbMapper.java | 31 +++++ .../ap/testutil/WithJakartaJaxb.java | 27 ++++ 34 files changed, 1062 insertions(+), 46 deletions(-) create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/pom.xml create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDetailsDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderStatusDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/ShippingAddressDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SourceTargetMapper.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SubTypeDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SuperTypeDto.java create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/binding/binding.xjb create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test1.xsd create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test2.xsd create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/underscores.xsd create mode 100644 integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/gem/jakarta/JakartaGemGenerator.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementListProperty.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementProperty.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaJaxb.java diff --git a/distribution/pom.xml b/distribution/pom.xml index 9ceeb505ea..11fb7c9f37 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -39,6 +39,13 @@ org.mapstruct.tools.gem gem-api + + + jakarta.xml.bind + jakarta.xml.bind-api + provided + true + @@ -187,7 +194,6 @@ javax.xml.bind jaxb-api - 2.3.1 provided true diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 364faae643..f888e226ff 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -133,8 +133,8 @@ javax.xml.bind jaxb-api - 2.3.1 provided + true diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 7d63ccf774..75513dd6c6 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -75,6 +75,10 @@ void java8Test() { void jaxbTest() { } + @ProcessorTest(baseDir = "jakartaJaxbTest") + void jakartaJaxbTest() { + } + @ProcessorTest(baseDir = "jsr330Test") void jsr330Test() { } diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 62f7986e9c..ac69114bd6 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -83,6 +83,13 @@ joda-time joda-time + + + jakarta.xml.bind + jakarta.xml.bind-api + provided + true + @@ -93,14 +100,16 @@ - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.2 + javax.xml.bind + jaxb-api + provided + true org.glassfish.jaxb jaxb-runtime - 2.3.2 + provided + true diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/pom.xml b/integrationtest/src/test/resources/jakartaJaxbTest/pom.xml new file mode 100644 index 0000000000..3aabc1c7ae --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + jakartaJaxbTest + jar + + + + jakarta.xml.bind + jakarta.xml.bind-api + provided + true + + + com.sun.xml.bind + jaxb-impl + provided + true + + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + 3.1.0 + + + xjc + initialize + + xjc + + + + + + ${project.build.resources[0].directory}/binding + + + ${project.build.resources[0].directory}/schema + + + + + + diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDetailsDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDetailsDto.java new file mode 100644 index 0000000000..e8500633e4 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDetailsDto.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +import java.util.List; + +/** + * @author Sjaak Derksen + */ +public class OrderDetailsDto { + + private String name; + private List description; + private OrderStatusDto status; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getDescription() { + return description; + } + + public void setDescription(List description) { + this.description = description; + } + + public OrderStatusDto getStatus() { + return status; + } + + public void setStatus(OrderStatusDto status) { + this.status = status; + } +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDto.java new file mode 100644 index 0000000000..f94d5362ef --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderDto.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +import java.util.Date; + +/** + * @author Sjaak Derksen + */ +public class OrderDto { + + private Long orderNumber; + private Date orderDate; + private OrderDetailsDto orderDetails; + private ShippingAddressDto shippingAddress; + + public Long getOrderNumber() { + return orderNumber; + } + + public void setOrderNumber(Long orderNumber) { + this.orderNumber = orderNumber; + } + + public Date getOrderDate() { + return orderDate; + } + + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + public OrderDetailsDto getOrderDetails() { + return orderDetails; + } + + public void setOrderDetails(OrderDetailsDto orderDetails) { + this.orderDetails = orderDetails; + } + + public ShippingAddressDto getShippingAddress() { + return shippingAddress; + } + + public void setShippingAddress(ShippingAddressDto shippingAddress) { + this.shippingAddress = shippingAddress; + } + +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderStatusDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderStatusDto.java new file mode 100644 index 0000000000..5da5d45c99 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/OrderStatusDto.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +/** + * @author Sjaak Derksen + */ +public enum OrderStatusDto { + + ORDERED( "small" ), + PROCESSED( "medium" ), + DELIVERED( "large" ); + private final String value; + + OrderStatusDto(String v) { + value = v; + } + + public String value() { + return value; + } + + public static OrderStatusDto fromValue(String v) { + for ( OrderStatusDto c : OrderStatusDto.values() ) { + if ( c.value.equals( v ) ) { + return c; + } + } + throw new IllegalArgumentException( v ); + } + +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/ShippingAddressDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/ShippingAddressDto.java new file mode 100644 index 0000000000..6bc40a19b2 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/ShippingAddressDto.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +/** + * @author Sjaak Derksen + */ +public class ShippingAddressDto { + + private String street; + private String houseNumber; + private String city; + private String country; + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getHouseNumber() { + return houseNumber; + } + + public void setHouseNumber(String houseNumber) { + this.houseNumber = houseNumber; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SourceTargetMapper.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SourceTargetMapper.java new file mode 100644 index 0000000000..3b76aad437 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SourceTargetMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; +import org.mapstruct.itest.jakarta.jaxb.xsd.test1.OrderDetailsType; +import org.mapstruct.itest.jakarta.jaxb.xsd.test1.OrderType; +import org.mapstruct.itest.jakarta.jaxb.xsd.test2.OrderStatusType; +import org.mapstruct.itest.jakarta.jaxb.xsd.test2.ShippingAddressType; +import org.mapstruct.itest.jakarta.jaxb.xsd.underscores.SubType; + + +/** + * @author Sjaak Derksen + */ +@Mapper(uses = { + org.mapstruct.itest.jakarta.jaxb.xsd.test1.ObjectFactory.class, + org.mapstruct.itest.jakarta.jaxb.xsd.test2.ObjectFactory.class, + org.mapstruct.itest.jakarta.jaxb.xsd.underscores.ObjectFactory.class +}) +public interface SourceTargetMapper { + + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + // source 2 target methods + OrderDto sourceToTarget(OrderType source); + + OrderDetailsDto detailsToDto(OrderDetailsType source); + + OrderStatusDto statusToDto(OrderStatusType source); + + ShippingAddressDto shippingAddressToDto(ShippingAddressType source); + + SubTypeDto subTypeToDto(SubType source); + + // target 2 source methods + OrderType targetToSource(OrderDto target); + + OrderDetailsType dtoToDetails(OrderDetailsDto target); + + OrderStatusType dtoToStatus(OrderStatusDto target); + + ShippingAddressType dtoToShippingAddress(ShippingAddressDto source); + + SubType dtoToSubType(SubTypeDto source); +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SubTypeDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SubTypeDto.java new file mode 100644 index 0000000000..88218c2771 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SubTypeDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +public class SubTypeDto extends SuperTypeDto { + private String declaredCamelCase; + private String declaredUnderscore; + + public String getDeclaredCamelCase() { + return declaredCamelCase; + } + + public void setDeclaredCamelCase(String declaredCamelCase) { + this.declaredCamelCase = declaredCamelCase; + } + + public String getDeclaredUnderscore() { + return declaredUnderscore; + } + + public void setDeclaredUnderscore(String declaredUnderscore) { + this.declaredUnderscore = declaredUnderscore; + } +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SuperTypeDto.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SuperTypeDto.java new file mode 100644 index 0000000000..cd0c6e22e7 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/java/org/mapstruct/itest/jakarta/jaxb/SuperTypeDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +public class SuperTypeDto { + private String inheritedCamelCase; + private String inheritedUnderscore; + + public String getInheritedCamelCase() { + return inheritedCamelCase; + } + + public void setInheritedCamelCase(String inheritedCamelCase) { + this.inheritedCamelCase = inheritedCamelCase; + } + + public String getInheritedUnderscore() { + return inheritedUnderscore; + } + + public void setInheritedUnderscore(String inheritedUnderscore) { + this.inheritedUnderscore = inheritedUnderscore; + } +} diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/binding/binding.xjb b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/binding/binding.xjb new file mode 100644 index 0000000000..8f26b1a1ea --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/binding/binding.xjb @@ -0,0 +1,28 @@ + + + + + + + + + + + + + diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test1.xsd b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test1.xsd new file mode 100644 index 0000000000..3433b01465 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test1.xsd @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test2.xsd b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test2.xsd new file mode 100644 index 0000000000..f3b564a48e --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/test2.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/underscores.xsd b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/underscores.xsd new file mode 100644 index 0000000000..b7f5904656 --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/main/resources/schema/underscores.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java new file mode 100644 index 0000000000..b81c946d9c --- /dev/null +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java @@ -0,0 +1,118 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.jakarta.jaxb; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.ByteArrayOutputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +import jakarta.xml.bind.JAXBContext; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.JAXBException; +import jakarta.xml.bind.Marshaller; + +import org.junit.Test; +import org.mapstruct.itest.jakarta.jaxb.xsd.test1.ObjectFactory; +import org.mapstruct.itest.jakarta.jaxb.xsd.test1.OrderType; +import org.mapstruct.itest.jakarta.jaxb.xsd.underscores.SubType; + +/** + * Test for generation of Jakarta JAXB based mapper implementations. + * + * @author Iaroslav Bogdanchikov + */ +public class JakartaJaxbBasedMapperTest { + + @Test + public void shouldMapJakartaJaxb() throws ParseException, JAXBException { + + SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; + + OrderDto source1 = new OrderDto(); + source1.setOrderDetails( new OrderDetailsDto() ); + source1.setOrderNumber( 11L ); + source1.setOrderDate( createDate( "31-08-1982 10:20:56" ) ); + source1.setShippingAddress( new ShippingAddressDto() ); + source1.getShippingAddress().setCity( "SmallTown" ); + source1.getShippingAddress().setHouseNumber( "11a" ); + source1.getShippingAddress().setStreet( "Awesome rd" ); + source1.getShippingAddress().setCountry( "USA" ); + source1.getOrderDetails().setDescription( new ArrayList() ); + source1.getOrderDetails().setName( "Shopping list for a Mapper" ); + source1.getOrderDetails().getDescription().add( "1 MapStruct" ); + source1.getOrderDetails().getDescription().add( "3 Lines of Code" ); + source1.getOrderDetails().getDescription().add( "1 Dose of Luck" ); + source1.getOrderDetails().setStatus( OrderStatusDto.ORDERED ); + + // map to JAXB + OrderType target = mapper.targetToSource( source1 ); + + // do a pretty print + ObjectFactory of = new ObjectFactory(); + System.out.println( toXml( of.createOrder( target ) ) ); + + // map back from JAXB + OrderDto source2 = mapper.sourceToTarget( target ); + + // verify that source1 and source 2 are equal + assertThat( source2.getOrderNumber() ).isEqualTo( source1.getOrderNumber() ); + assertThat( source2.getOrderDate() ).isEqualTo( source1.getOrderDate() ); + assertThat( source2.getOrderDetails().getDescription().size() ).isEqualTo( + source1.getOrderDetails().getDescription().size() + ); + assertThat( source2.getOrderDetails().getDescription().get( 0 ) ).isEqualTo( + source1.getOrderDetails().getDescription().get( 0 ) + ); + assertThat( source2.getOrderDetails().getDescription().get( 1 ) ).isEqualTo( + source1.getOrderDetails().getDescription().get( 1 ) + ); + assertThat( source2.getOrderDetails().getDescription().get( 2 ) ).isEqualTo( + source1.getOrderDetails().getDescription().get( 2 ) + ); + assertThat( source2.getOrderDetails().getName() ).isEqualTo( source1.getOrderDetails().getName() ); + assertThat( source2.getOrderDetails().getStatus() ).isEqualTo( source1.getOrderDetails().getStatus() ); + } + + @Test + public void underscores() throws ParseException, JAXBException { + + SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; + + SubTypeDto source1 = new SubTypeDto(); + source1.setInheritedCamelCase("InheritedCamelCase"); + source1.setInheritedUnderscore("InheritedUnderscore"); + source1.setDeclaredCamelCase("DeclaredCamelCase"); + source1.setDeclaredUnderscore("DeclaredUnderscore"); + + SubType target = mapper.dtoToSubType( source1 ); + + SubTypeDto source2 = mapper.subTypeToDto( target ); + + assertThat( source2.getInheritedCamelCase() ).isEqualTo( source1.getInheritedCamelCase() ); + assertThat( source2.getInheritedUnderscore() ).isEqualTo( source1.getInheritedUnderscore() ); + assertThat( source2.getDeclaredCamelCase() ).isEqualTo( source1.getDeclaredCamelCase() ); + assertThat( source2.getDeclaredUnderscore() ).isEqualTo( source1.getDeclaredUnderscore() ); + } + + private Date createDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); + return sdf.parse( date ); + } + + private String toXml(JAXBElement element) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance( element.getValue().getClass() ); + Marshaller marshaller = jc.createMarshaller(); + marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE ); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + marshaller.marshal( element, baos ); + return baos.toString(); + } +} diff --git a/integrationtest/src/test/resources/jaxbTest/pom.xml b/integrationtest/src/test/resources/jaxbTest/pom.xml index 000e7cf598..0e69e23e01 100644 --- a/integrationtest/src/test/resources/jaxbTest/pom.xml +++ b/integrationtest/src/test/resources/jaxbTest/pom.xml @@ -51,7 +51,7 @@ org.glassfish.jaxb jaxb-runtime - 2.3.2 + ${jaxb-runtime.version} @@ -66,14 +66,16 @@ - jakarta.xml.bind - jakarta.xml.bind-api - 2.3.2 + javax.xml.bind + jaxb-api + provided + true org.glassfish.jaxb jaxb-runtime - 2.3.2 + provided + true diff --git a/parent/pom.xml b/parent/pom.xml index 426405b4b7..3f536034c7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -42,6 +42,7 @@ --> 1.8 3.21.2 + 2.3.2 @@ -255,6 +256,30 @@ 2.9 + + + + javax.xml.bind + jaxb-api + 2.3.1 + + + org.glassfish.jaxb + jaxb-runtime + ${jaxb-runtime.version} + + + + jakarta.xml.bind + jakarta.xml.bind-api + 3.0.1 + + + com.sun.xml.bind + jaxb-impl + 3.0.2 + + org.eclipse.tycho @@ -488,12 +513,12 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.17 + 1.20 org.ow2.asm asm - 6.2.1 + 7.0 diff --git a/processor/pom.xml b/processor/pom.xml index ff7864f32e..12fc615f5f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -137,6 +137,13 @@ joda-time test + + + jakarta.xml.bind + jakarta.xml.bind-api + provided + true + @@ -375,7 +382,6 @@ javax.xml.bind jaxb-api - 2.3.1 provided true diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/jakarta/JakartaGemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/jakarta/JakartaGemGenerator.java new file mode 100644 index 0000000000..93bdebeaef --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/jakarta/JakartaGemGenerator.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.gem.jakarta; + +import jakarta.xml.bind.annotation.XmlElementDecl; +import jakarta.xml.bind.annotation.XmlElementRef; +import org.mapstruct.tools.gem.GemDefinition; + +/** + * This class is a temporary solution to an issue in the Gem Tools library. + * + *

    + * This class can be merged with {@link org.mapstruct.ap.internal.gem.GemGenerator} + * after the mentioned issue is resolved. + *

    + * + * @see Gem Tools issue #10 + * @author Iaroslav Bogdanchikov + */ +@GemDefinition(XmlElementDecl.class) +@GemDefinition(XmlElementRef.class) +class JakartaGemGenerator { +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java index 0edae7f10f..6cd1605b23 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMappingMethods.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; +import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.util.JaxbConstants; import org.mapstruct.ap.internal.util.JodaTimeConstants; @@ -24,7 +25,7 @@ public class BuiltInMappingMethods { public BuiltInMappingMethods(TypeFactory typeFactory) { boolean isXmlGregorianCalendarPresent = isXmlGregorianCalendarAvailable( typeFactory ); - builtInMethods = new ArrayList<>( 20 ); + builtInMethods = new ArrayList<>( 21 ); if ( isXmlGregorianCalendarPresent ) { builtInMethods.add( new DateToXmlGregorianCalendar( typeFactory ) ); builtInMethods.add( new XmlGregorianCalendarToDate( typeFactory ) ); @@ -39,8 +40,14 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { builtInMethods.add( new XmlGregorianCalendarToLocalDateTime( typeFactory ) ); } - if ( isJaxbAvailable( typeFactory ) ) { - builtInMethods.add( new JaxbElemToValue( typeFactory ) ); + if ( isJavaxJaxbAvailable( typeFactory ) ) { + Type type = typeFactory.getType( JaxbConstants.JAVAX_JAXB_ELEMENT_FQN ); + builtInMethods.add( new JaxbElemToValue( type ) ); + } + + if ( isJakartaJaxbAvailable( typeFactory ) ) { + Type type = typeFactory.getType( JaxbConstants.JAKARTA_JAXB_ELEMENT_FQN ); + builtInMethods.add( new JaxbElemToValue( type ) ); } builtInMethods.add( new ZonedDateTimeToCalendar( typeFactory ) ); @@ -58,8 +65,12 @@ public BuiltInMappingMethods(TypeFactory typeFactory) { } } - private static boolean isJaxbAvailable(TypeFactory typeFactory) { - return typeFactory.isTypeAvailable( JaxbConstants.JAXB_ELEMENT_FQN ); + private static boolean isJavaxJaxbAvailable(TypeFactory typeFactory) { + return typeFactory.isTypeAvailable( JaxbConstants.JAVAX_JAXB_ELEMENT_FQN ); + } + + private static boolean isJakartaJaxbAvailable(TypeFactory typeFactory) { + return typeFactory.isTypeAvailable( JaxbConstants.JAKARTA_JAXB_ELEMENT_FQN ); } private static boolean isXmlGregorianCalendarAvailable(TypeFactory typeFactory) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java index 0d3d4c30af..2a5d1639e6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JaxbElemToValue.java @@ -5,26 +5,23 @@ */ package org.mapstruct.ap.internal.model.source.builtin; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.util.JaxbConstants; + +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * @author Sjaak Derksen */ -public class JaxbElemToValue extends BuiltInMethod { +class JaxbElemToValue extends BuiltInMethod { private final Parameter parameter; private final Type returnType; private final Set importTypes; - public JaxbElemToValue(TypeFactory typeFactory) { - Type type = typeFactory.getType( JaxbConstants.JAXB_ELEMENT_FQN ); + JaxbElemToValue(Type type) { this.parameter = new Parameter( "element", type ); this.returnType = type.getTypeParameters().get( 0 ); this.importTypes = asSet( parameter.getType() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java new file mode 100644 index 0000000000..df5cd848a5 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import javax.lang.model.element.Element; + +import org.mapstruct.ap.internal.gem.jakarta.XmlElementDeclGem; +import org.mapstruct.ap.internal.gem.jakarta.XmlElementRefGem; +import org.mapstruct.ap.internal.util.TypeUtils; + +/** + * The concrete implementation of the {@link XmlElementDeclSelector} that + * works with {@link jakarta.xml.bind.annotation.XmlElementRef} and + * {@link jakarta.xml.bind.annotation.XmlElementDecl}. + * + * @author Iaroslav Bogdanchikov + */ +class JakartaXmlElementDeclSelector extends XmlElementDeclSelector { + + JakartaXmlElementDeclSelector(TypeUtils typeUtils) { + super( typeUtils ); + } + + @Override + XmlElementDeclInfo getXmlElementDeclInfo(Element element) { + XmlElementDeclGem gem = XmlElementDeclGem.instanceOn( element ); + + if (gem == null) { + return null; + } + + return new XmlElementDeclInfo( gem.name().get(), gem.scope().get() ); + } + + @Override + XmlElementRefInfo getXmlElementRefInfo(Element element) { + XmlElementRefGem gem = XmlElementRefGem.instanceOn( element ); + + if (gem == null) { + return null; + } + + return new XmlElementRefInfo( gem.name().get(), gem.type().get() ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java new file mode 100644 index 0000000000..1d02e97e90 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import javax.lang.model.element.Element; + +import org.mapstruct.ap.internal.gem.XmlElementDeclGem; +import org.mapstruct.ap.internal.gem.XmlElementRefGem; +import org.mapstruct.ap.internal.util.TypeUtils; + +/** + * The concrete implementation of the {@link XmlElementDeclSelector} that + * works with {@link javax.xml.bind.annotation.XmlElementRef} and + * {@link javax.xml.bind.annotation.XmlElementDecl}. + * + * @author Iaroslav Bogdanchikov + */ +class JavaxXmlElementDeclSelector extends XmlElementDeclSelector { + + JavaxXmlElementDeclSelector(TypeUtils typeUtils) { + super( typeUtils ); + } + + @Override + XmlElementDeclInfo getXmlElementDeclInfo(Element element) { + XmlElementDeclGem gem = XmlElementDeclGem.instanceOn( element ); + + if (gem == null) { + return null; + } + + return new XmlElementDeclInfo( gem.name().get(), gem.scope().get() ); + } + + @Override + XmlElementRefInfo getXmlElementRefInfo(Element element) { + XmlElementRefGem gem = XmlElementRefGem.instanceOn( element ); + + if (gem == null) { + return null; + } + + return new XmlElementRefInfo( gem.name().get(), gem.type().get() ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index de429174da..519e1c3d6d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -32,7 +32,8 @@ public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFacto new TypeSelector( typeFactory, messager ), new QualifierSelector( typeUtils, elementUtils ), new TargetTypeSelector( typeUtils ), - new XmlElementDeclSelector( typeUtils ), + new JavaxXmlElementDeclSelector( typeUtils ), + new JakartaXmlElementDeclSelector( typeUtils ), new InheritanceSelector(), new CreateOrUpdateSelector(), new SourceRhsSelector(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 7bdae0b771..91b4b5ca10 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -11,19 +11,17 @@ import javax.lang.model.element.ElementKind; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.TypeUtils; -import org.mapstruct.ap.internal.gem.XmlElementRefGem; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SourceMethod; -import org.mapstruct.ap.internal.gem.XmlElementDeclGem; +import org.mapstruct.ap.internal.util.TypeUtils; /** - * Finds the {@link javax.xml.bind.annotation.XmlElementRef} annotation on a field (of the mapping result type or its + * Finds the {@code XmlElementRef} annotation on a field (of the mapping result type or its * super types) matching the * target property name. Then selects those methods with matching {@code name} and {@code scope} attributes of the - * {@link javax.xml.bind.annotation.XmlElementDecl} annotation, if that is present. Matching happens in the following + * {@code XmlElementDecl} annotation, if that is present. Matching happens in the following * order: *
      *
    1. Name and Scope matches
    2. @@ -34,12 +32,15 @@ * the given method is not annotated with {@code XmlElementDecl} it will be considered as matching. * * @author Sjaak Derksen + * + * @see JavaxXmlElementDeclSelector + * @see JakartaXmlElementDeclSelector */ -public class XmlElementDeclSelector implements MethodSelector { +abstract class XmlElementDeclSelector implements MethodSelector { private final TypeUtils typeUtils; - public XmlElementDeclSelector(TypeUtils typeUtils) { + XmlElementDeclSelector(TypeUtils typeUtils) { this.typeUtils = typeUtils; } @@ -63,15 +64,14 @@ public List> getMatchingMethods(Method mapp } SourceMethod candidateMethod = (SourceMethod) candidate.getMethod(); - XmlElementDeclGem xmlElementDecl = - XmlElementDeclGem.instanceOn( candidateMethod.getExecutable() ); + XmlElementDeclInfo xmlElementDeclInfo = getXmlElementDeclInfo( candidateMethod.getExecutable() ); - if ( xmlElementDecl == null ) { + if ( xmlElementDeclInfo == null ) { continue; } - String name = xmlElementDecl.name().get(); - TypeMirror scope = xmlElementDecl.scope().getValue(); + String name = xmlElementDeclInfo.nameValue(); + TypeMirror scope = xmlElementDeclInfo.scopeType(); boolean nameIsSetAndMatches = name != null && name.equals( xmlElementRefInfo.nameValue() ); boolean scopeIsSetAndMatches = @@ -142,9 +142,9 @@ private XmlElementRefInfo findXmlElementRef(Type resultType, String targetProper for ( Element enclosed : currentElement.getEnclosedElements() ) { if ( enclosed.getKind().equals( ElementKind.FIELD ) && enclosed.getSimpleName().contentEquals( targetPropertyName ) ) { - XmlElementRefGem xmlElementRef = XmlElementRefGem.instanceOn( enclosed ); - if ( xmlElementRef != null ) { - return new XmlElementRefInfo( xmlElementRef.name().get(), currentMirror ); + XmlElementRefInfo xmlElementRefInfo = getXmlElementRefInfo( enclosed ); + if ( xmlElementRefInfo != null ) { + return new XmlElementRefInfo( xmlElementRefInfo.nameValue(), currentMirror ); } } } @@ -154,7 +154,11 @@ private XmlElementRefInfo findXmlElementRef(Type resultType, String targetProper return defaultInfo; } - private static class XmlElementRefInfo { + abstract XmlElementDeclInfo getXmlElementDeclInfo(Element element); + + abstract XmlElementRefInfo getXmlElementRefInfo(Element element); + + static class XmlElementRefInfo { private final String nameValue; private final TypeMirror sourceType; @@ -163,12 +167,37 @@ private static class XmlElementRefInfo { this.sourceType = sourceType; } - public String nameValue() { + String nameValue() { return nameValue; } - public TypeMirror sourceType() { + TypeMirror sourceType() { return sourceType; } } + + /** + * A class, whose purpose is to combine the use of + * {@link org.mapstruct.ap.internal.gem.XmlElementDeclGem} + * and + * {@link org.mapstruct.ap.internal.gem.jakarta.XmlElementDeclGem}. + */ + static class XmlElementDeclInfo { + + private final String nameValue; + private final TypeMirror scopeType; + + XmlElementDeclInfo(String nameValue, TypeMirror scopeType) { + this.nameValue = nameValue; + this.scopeType = scopeType; + } + + String nameValue() { + return nameValue; + } + + TypeMirror scopeType() { + return scopeType; + } + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java index db18673ba2..c89877062e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JaxbConstants.java @@ -10,7 +10,8 @@ */ public final class JaxbConstants { - public static final String JAXB_ELEMENT_FQN = "javax.xml.bind.JAXBElement"; + public static final String JAVAX_JAXB_ELEMENT_FQN = "javax.xml.bind.JAXBElement"; + public static final String JAKARTA_JAXB_ELEMENT_FQN = "jakarta.xml.bind.JAXBElement"; private JaxbConstants() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java index 2dc41b822d..c8ee922af9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/BuiltInTest.java @@ -29,6 +29,8 @@ import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; import org.mapstruct.ap.test.builtin.bean.CalendarProperty; import org.mapstruct.ap.test.builtin.bean.DateProperty; +import org.mapstruct.ap.test.builtin.bean.JakartaJaxbElementListProperty; +import org.mapstruct.ap.test.builtin.bean.JakartaJaxbElementProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementListProperty; import org.mapstruct.ap.test.builtin.bean.JaxbElementProperty; import org.mapstruct.ap.test.builtin.bean.SomeType; @@ -45,6 +47,8 @@ import org.mapstruct.ap.test.builtin.mapper.DateToCalendarMapper; import org.mapstruct.ap.test.builtin.mapper.DateToXmlGregCalMapper; import org.mapstruct.ap.test.builtin.mapper.IterableSourceTargetMapper; +import org.mapstruct.ap.test.builtin.mapper.JakartaJaxbListMapper; +import org.mapstruct.ap.test.builtin.mapper.JakartaJaxbMapper; import org.mapstruct.ap.test.builtin.mapper.JaxbListMapper; import org.mapstruct.ap.test.builtin.mapper.JaxbMapper; import org.mapstruct.ap.test.builtin.mapper.MapSourceTargetMapper; @@ -58,6 +62,7 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaJaxb; import org.mapstruct.ap.testutil.WithJavaxJaxb; import static org.assertj.core.api.Assertions.assertThat; @@ -101,6 +106,23 @@ public void shouldApplyBuiltInOnJAXBElement() { assertThat( target.publicProp ).isEqualTo( "PUBLIC TEST" ); } + @ProcessorTest + @WithClasses( { + JakartaJaxbMapper.class, + JakartaJaxbElementProperty.class, + } ) + @WithJakartaJaxb + public void shouldApplyBuiltInOnJakartaJaxbElement() { + JakartaJaxbElementProperty source = new JakartaJaxbElementProperty(); + source.setProp( createJakartaJaxb( "TEST" ) ); + source.publicProp = createJakartaJaxb( "PUBLIC TEST" ); + + StringProperty target = JakartaJaxbMapper.INSTANCE.map( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( "TEST" ); + assertThat( target.publicProp ).isEqualTo( "PUBLIC TEST" ); + } + @ProcessorTest @WithClasses( { JaxbMapper.class, @@ -128,6 +150,33 @@ public void shouldApplyBuiltInOnJAXBElementExtra() { assertThat( target2.getProp() ).isNotNull(); } + @ProcessorTest + @WithClasses( { + JakartaJaxbMapper.class, + JakartaJaxbElementProperty.class, + } ) + @WithJakartaJaxb + @IssueKey( "1698" ) + public void shouldApplyBuiltInOnJakartaJAXBElementExtra() { + JakartaJaxbElementProperty source = new JakartaJaxbElementProperty(); + source.setProp( createJakartaJaxb( "5" ) ); + source.publicProp = createJakartaJaxb( "5" ); + + BigDecimalProperty target = JakartaJaxbMapper.INSTANCE.mapBD( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp() ).isEqualTo( new BigDecimal( "5" ) ); + assertThat( target.publicProp ).isEqualTo( new BigDecimal( "5" ) ); + + JakartaJaxbElementProperty source2 = new JakartaJaxbElementProperty(); + source2.setProp( createJakartaJaxb( "5" ) ); + source2.publicProp = createJakartaJaxb( "5" ); + + SomeTypeProperty target2 = JakartaJaxbMapper.INSTANCE.mapSomeType( source2 ); + assertThat( target2 ).isNotNull(); + assertThat( target2.publicProp ).isNotNull(); + assertThat( target2.getProp() ).isNotNull(); + } + @ProcessorTest @WithClasses( { JaxbListMapper.class, @@ -147,6 +196,24 @@ public void shouldApplyBuiltInOnJAXBElementList() { assertThat( target.publicProp.get( 0 ) ).isEqualTo( "PUBLIC TEST2" ); } + @ProcessorTest + @WithClasses( { + JakartaJaxbListMapper.class, + JakartaJaxbElementListProperty.class, + } ) + @WithJakartaJaxb + @IssueKey( "141" ) + public void shouldApplyBuiltInOnJakartaJAXBElementList() { + JakartaJaxbElementListProperty source = new JakartaJaxbElementListProperty(); + source.setProp( createJakartaJaxbList( "TEST2" ) ); + source.publicProp = createJakartaJaxbList( "PUBLIC TEST2" ); + + StringListProperty target = JakartaJaxbListMapper.INSTANCE.map( source ); + assertThat( target ).isNotNull(); + assertThat( target.getProp().get( 0 ) ).isEqualTo( "TEST2" ); + assertThat( target.publicProp.get( 0 ) ).isEqualTo( "PUBLIC TEST2" ); + } + @ProcessorTest @WithClasses( DateToXmlGregCalMapper.class ) public void shouldApplyBuiltInOnDateToXmlGregCal() throws ParseException { @@ -414,12 +481,22 @@ private JAXBElement createJaxb(String test) { return new JAXBElement<>( new QName( "www.mapstruct.org", "test" ), String.class, test ); } + private jakarta.xml.bind.JAXBElement createJakartaJaxb(String test) { + return new jakarta.xml.bind.JAXBElement<>( new QName( "www.mapstruct.org", "test" ), String.class, test ); + } + private List> createJaxbList(String test) { List> result = new ArrayList<>(); result.add( createJaxb( test ) ); return result; } + private List> createJakartaJaxbList(String test) { + List> result = new ArrayList<>(); + result.add( createJakartaJaxb( test ) ); + return result; + } + private Date createDate(String date) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); return sdf.parse( date ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementListProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementListProperty.java new file mode 100644 index 0000000000..f6ab537253 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementListProperty.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +import java.util.List; + +import jakarta.xml.bind.JAXBElement; + +public class JakartaJaxbElementListProperty { + + // CHECKSTYLE:OFF + public List> publicProp; + // CHECKSTYLE:ON + + private List> prop; + + public List> getProp() { + return prop; + } + + public void setProp( List> prop ) { + this.prop = prop; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementProperty.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementProperty.java new file mode 100644 index 0000000000..0336afe814 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/bean/JakartaJaxbElementProperty.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.bean; + +import jakarta.xml.bind.JAXBElement; + +public class JakartaJaxbElementProperty { + + // CHECKSTYLE:OFF + public JAXBElement publicProp; + // CHECKSTYLE:ON + + private JAXBElement prop; + + public JAXBElement getProp() { + return prop; + } + + public void setProp( JAXBElement prop ) { + this.prop = prop; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbListMapper.java new file mode 100644 index 0000000000..602e2180f1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbListMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.JakartaJaxbElementListProperty; +import org.mapstruct.ap.test.builtin.bean.StringListProperty; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface JakartaJaxbListMapper { + + JakartaJaxbListMapper INSTANCE = Mappers.getMapper( JakartaJaxbListMapper.class ); + + StringListProperty map(JakartaJaxbElementListProperty source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbMapper.java new file mode 100644 index 0000000000..9334792572 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builtin/mapper/JakartaJaxbMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builtin.mapper; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.builtin.bean.BigDecimalProperty; +import org.mapstruct.ap.test.builtin.bean.JakartaJaxbElementProperty; +import org.mapstruct.ap.test.builtin.bean.SomeType; +import org.mapstruct.ap.test.builtin.bean.SomeTypeProperty; +import org.mapstruct.ap.test.builtin.bean.StringProperty; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface JakartaJaxbMapper { + + JakartaJaxbMapper INSTANCE = Mappers.getMapper( JakartaJaxbMapper.class ); + + StringProperty map(JakartaJaxbElementProperty source); + + BigDecimalProperty mapBD(JakartaJaxbElementProperty source); + + SomeTypeProperty mapSomeType(JakartaJaxbElementProperty source); + + @SuppressWarnings( "unused" ) + default SomeType map( String in ) { + return new SomeType(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaJaxb.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaJaxb.java new file mode 100644 index 0000000000..86c9d83a54 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithJakartaJaxb.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Jakarta XML Binding dependencies. + * + * @author Iaroslav Bogdanchikov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithTestDependency({ + "jakarta.xml.bind", +}) +public @interface WithJakartaJaxb { + +} From 97c67552882d6fb1c6ab51bf14a6c9d289e652c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Campanero=20Ortiz?= Date: Sun, 4 Sep 2022 13:58:10 +0200 Subject: [PATCH 0716/1006] #2963 Add support for enum to integer conversion --- .../chapter-5-data-type-conversions.asciidoc | 3 + .../ap/internal/conversion/Conversions.java | 14 +++- .../conversion/EnumToIntegerConversion.java | 38 +++++++++ .../_enum/EnumToIntegerConversionTest.java | 77 +++++++++++++++++++ .../conversion/_enum/EnumToIntegerEnum.java | 14 ++++ .../conversion/_enum/EnumToIntegerMapper.java | 19 +++++ .../conversion/_enum/EnumToIntegerSource.java | 28 +++++++ .../conversion/_enum/EnumToIntegerTarget.java | 28 +++++++ 8 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumToIntegerConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerEnum.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerTarget.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index e456af01ba..51ccb21a46 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -43,6 +43,9 @@ public interface CarMapper { ==== * Between `enum` types and `String`. +* Between `enum` types and `Integer`, according to `enum.ordinal()`. +** When converting from an `Integer`, the value needs to be less than the number of values of the enum, otherwise an `ArrayOutOfBoundsException` is thrown. + * Between big number types (`java.math.BigInteger`, `java.math.BigDecimal`) and Java primitive types (including their wrappers) as well as String. A format string as understood by `java.text.DecimalFormat` can be specified. .Conversion from BigDecimal to String diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index e012481054..e947c78571 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -41,6 +41,7 @@ public class Conversions { private final Map conversions = new HashMap<>(); private final Type enumType; private final Type stringType; + private final Type integerType; private final TypeFactory typeFactory; public Conversions(TypeFactory typeFactory) { @@ -48,6 +49,7 @@ public Conversions(TypeFactory typeFactory) { this.enumType = typeFactory.getType( Enum.class ); this.stringType = typeFactory.getType( String.class ); + this.integerType = typeFactory.getType( Integer.class ); //native types <> native types, including wrappers registerNativeTypeConversion( byte.class, Byte.class ); @@ -185,6 +187,8 @@ public Conversions(TypeFactory typeFactory) { //misc. register( Enum.class, String.class, new EnumStringConversion() ); + register( Enum.class, Integer.class, new EnumToIntegerConversion() ); + register( Enum.class, int.class, new EnumToIntegerConversion() ); register( Date.class, String.class, new DateToStringConversion() ); register( BigDecimal.class, BigInteger.class, new BigDecimalToBigIntegerConversion() ); @@ -324,10 +328,16 @@ private void register(String sourceTypeName, Class targetClass, ConversionPro } public ConversionProvider getConversion(Type sourceType, Type targetType) { - if ( sourceType.isEnumType() && targetType.equals( stringType ) ) { + if ( sourceType.isEnumType() && + ( targetType.equals( stringType ) || + targetType.getBoxedEquivalent().equals( integerType ) ) + ) { sourceType = enumType; } - else if ( targetType.isEnumType() && sourceType.equals( stringType ) ) { + else if ( targetType.isEnumType() && + ( sourceType.equals( stringType ) || + sourceType.getBoxedEquivalent().equals( integerType ) ) + ) { targetType = enumType; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumToIntegerConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumToIntegerConversion.java new file mode 100644 index 0000000000..b43dc4a48f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/EnumToIntegerConversion.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import static org.mapstruct.ap.internal.util.Collections.asSet; + +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * Conversion between {@link Enum} and {@link Integer} types. + * + * @author Jose Carlos Campanero Ortiz + */ +public class EnumToIntegerConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".ordinal()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return conversionContext.getTargetType().createReferenceName() + ".values()[ ]"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return asSet( + conversionContext.getTargetType() + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java new file mode 100644 index 0000000000..1302c22bc9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Tests conversions between {@link Enum} and Integer. + * + * @author Jose Carlos Campanero Ortiz + */ +@IssueKey("2963") +@WithClasses({ + EnumToIntegerSource.class, + EnumToIntegerTarget.class, + EnumToIntegerMapper.class, + EnumToIntegerEnum.class +}) +public class EnumToIntegerConversionTest { + + @ProcessorTest + public void shouldApplyEnumToIntegerConversion() { + EnumToIntegerSource source = new EnumToIntegerSource(); + + for ( EnumToIntegerEnum value: EnumToIntegerEnum.values() ) { + source.setEnumValue( value ); + + EnumToIntegerTarget target = EnumToIntegerMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getEnumValue() ).isEqualTo( source.getEnumValue().ordinal() ); + } + } + + @ProcessorTest + public void shouldApplyReverseEnumToIntegerConversion() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + + int numberOfValues = EnumToIntegerEnum.values().length; + for ( int value = 0; value < numberOfValues; value++ ) { + target.setEnumValue( value ); + + EnumToIntegerSource source = EnumToIntegerMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getEnumValue() ).isEqualTo( EnumToIntegerEnum.values()[ target.getEnumValue() ] ); + } + } + + @ProcessorTest + public void shouldHandleOutOfBoundsEnumOrdinal() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + target.setInvalidEnumValue( EnumToIntegerEnum.values().length + 1 ); + + assertThatThrownBy( () -> EnumToIntegerMapper.INSTANCE.targetToSource( target ) ) + .isInstanceOf( ArrayIndexOutOfBoundsException.class ); + } + + @ProcessorTest + public void shouldHandleNullIntegerValue() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + + EnumToIntegerSource source = EnumToIntegerMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getEnumValue() ).isNull(); + assertThat( source.getInvalidEnumValue() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerEnum.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerEnum.java new file mode 100644 index 0000000000..4aad7bef57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerEnum.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +public enum EnumToIntegerEnum { + ARBITRARY_VALUE_ZERO, + ARBITRARY_VALUE_ONE, + ARBITRARY_VALUE_TWO, + ARBITRARY_VALUE_THREE +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerMapper.java new file mode 100644 index 0000000000..946ee7c463 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface EnumToIntegerMapper { + EnumToIntegerMapper INSTANCE = Mappers.getMapper( EnumToIntegerMapper.class ); + + EnumToIntegerTarget sourceToTarget(EnumToIntegerSource source); + + EnumToIntegerSource targetToSource(EnumToIntegerTarget target); +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerSource.java new file mode 100644 index 0000000000..4e60311d9b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerSource.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +public class EnumToIntegerSource { + private EnumToIntegerEnum enumValue; + + private EnumToIntegerEnum invalidEnumValue; + + public EnumToIntegerEnum getEnumValue() { + return enumValue; + } + + public void setEnumValue(final EnumToIntegerEnum enumValue) { + this.enumValue = enumValue; + } + + public EnumToIntegerEnum getInvalidEnumValue() { + return invalidEnumValue; + } + + public void setInvalidEnumValue(EnumToIntegerEnum invalidEnumValue) { + this.invalidEnumValue = invalidEnumValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerTarget.java new file mode 100644 index 0000000000..a8819c27ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerTarget.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +public class EnumToIntegerTarget { + private Integer enumValue; + + private Integer invalidEnumValue; + + public Integer getEnumValue() { + return enumValue; + } + + public void setEnumValue(final Integer enumValue) { + this.enumValue = enumValue; + } + + public Integer getInvalidEnumValue() { + return invalidEnumValue; + } + + public void setInvalidEnumValue(Integer invalidEnumValue) { + this.invalidEnumValue = invalidEnumValue; + } +} From d593afed694e407c108596df584bd7fc739c2f5c Mon Sep 17 00:00:00 2001 From: Prasanth Omanakuttan Date: Mon, 12 Sep 2022 22:15:22 +0530 Subject: [PATCH 0717/1006] Avoid unnecessary unboxing of Boolean (#3003) --- .../java/org/mapstruct/ap/MappingProcessor.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 4f9e0fa384..2a4af558f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -8,7 +8,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; @@ -119,7 +118,7 @@ public class MappingProcessor extends AbstractProcessor { *

      * If the hierarchy of a mapper's source/target types is never completed (i.e. the missing super-types are not * generated by other processors), this mapper will not be generated; That's fine, the compiler will raise an error - * due to the inconsistent Java types used as source or target anyways. + * due to the inconsistent Java types used as source or target anyway. */ private Set deferredMappers = new HashSet<>(); @@ -142,15 +141,15 @@ private Options createOptions() { String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); return new Options( - Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), - Boolean.valueOf( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), + Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), + Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, unmappedSourcePolicy != null ? ReportingPolicyGem.valueOf( unmappedSourcePolicy.toUpperCase() ) : null, processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), - Boolean.valueOf( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), - Boolean.valueOf( processingEnv.getOptions().get( DISABLE_BUILDERS ) ), - Boolean.valueOf( processingEnv.getOptions().get( VERBOSE ) ) + Boolean.parseBoolean( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), + Boolean.parseBoolean( processingEnv.getOptions().get( DISABLE_BUILDERS ) ), + Boolean.parseBoolean( processingEnv.getOptions().get( VERBOSE ) ) ); } @@ -352,7 +351,7 @@ private R process(ProcessorContext context, ModelElementProcessor p /** * Retrieves all model element processors, ordered by their priority value - * (with the method retrieval processor having the lowest priority value (1) + * (with the method retrieval processor having the lowest priority value (1)) * and the code generation processor the highest priority value. * * @return A list with all model element processors. @@ -372,7 +371,7 @@ private R process(ProcessorContext context, ModelElementProcessor p processors.add( processorIterator.next() ); } - Collections.sort( processors, new ProcessorComparator() ); + processors.sort( new ProcessorComparator() ); return processors; } From 8d670e7db72961a6a3470a8fdc85ec164007ca51 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 4 Sep 2022 09:39:27 +0200 Subject: [PATCH 0718/1006] #3008 Replace old issue template with new GitHub issue form templates --- .github/ISSUE_TEMPLATE/bug_report.yml | 45 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 16 ++++++++ .github/ISSUE_TEMPLATE/feature_request.yml | 43 +++++++++++++++++++++ ISSUE_TEMPLATE.md | 9 ----- 4 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml delete mode 100644 ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000..b6703e1800 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,45 @@ +name: Bug report +description: Create a report and help us improve +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Please fill in all required fields with as many details as possible. + - type: textarea + id: expected + attributes: + label: Expected behavior + description: | + Describe what you were expecting MapStruct to do + placeholder: | + Here you can also add the generated code that you would like MapStruct to generate + - type: textarea + id: actual + attributes: + label: Actual behavior + description: | + Describe what you observed MapStruct did instead + placeholder: | + Here you can also add the generated code that MapStruct generated + - type: textarea + id: steps + attributes: + label: Steps to reproduce the problem + description: | + - Share your mapping configuration + - An [MCVE (Minimal Complete Verifiable Example)](https://stackoverflow.com/help/minimal-reproducible-example) can be helpful to provide a complete reproduction case + placeholder: | + Share your MapStruct configuration + validations: + required: true + - type: input + id: mapstruct-version + attributes: + label: MapStruct Version + description: | + Which MapStruct version did you use? + Note: While you can obviously continue using older versions of MapStruct, it may well be that your bug is already fixed. If you're using an older version, please also try to reproduce the bug in the latest version of MapStruct before reporting it. + placeholder: ex. MapStruct 1.5.2 + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000..5b7ced86a4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,16 @@ +contact_links: + - name: MapStruct Discussions + url: https://github.com/mapstruct/mapstruct/discussions + about: Please use the MapStruct GitHub Discussions for open ended discussions and to reach out to the community. + - name: Stack Overflow + url: https://stackoverflow.com/questions/tagged/mapstruct + about: For questions about how to use MapStruct, consider asking your question on Stack Overflow, tagged [mapstruct]. + - name: Documentation + url: https://mapstruct.org/documentation/stable/reference/html/ + about: The MapStruct reference documentation. + - name: Gitter Chat + url: https://gitter.im/mapstruct/mapstruct-users + about: For realtime communication with the MapStruct community, consider writing in our Gitter chat room. + - name: MapStruct Examples + url: https://github.com/mapstruct/mapstruct-examples + about: Some examples of what can be achieved with MapStruct. (contributions are always welcome) diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000000..191bba8345 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,43 @@ +name: Feature Request +description: Suggest an idea +body: + - type: markdown + attributes: + value: | + Please describe the use-case you have. This will better help us understand the context in which you're looking for a new feature. + - type: textarea + id: use-case + attributes: + label: Use case + description: | + Please describe the use-case you have. This will better help us understand the context in which you're looking for a new feature. + placeholder: Describe the use-case here + validations: + required: true + - type: textarea + id: solution + attributes: + label: Generated Code + description: | + Please describe the possible generated code you'd like to see in MapStruct generate. + Please note, it's not always easy to describe a good solution. Describing the use-case above is much more important to us. + placeholder: Describe the possible solution here. + validations: + required: false + - type: textarea + id: workarounds + attributes: + label: Possible workarounds + description: | + Please describe the possible workarounds you've implemented to work around the lacking functionality. + placeholder: Describe the possible workarounds here. + validations: + required: false + - type: input + id: mapstruct-version + attributes: + label: MapStruct Version + description: What MapStruct version and edition did you try? + placeholder: ex. MapStruct 1.5.2 + validations: + required: false diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md deleted file mode 100644 index ecaf441514..0000000000 --- a/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,9 +0,0 @@ -- [ ] Is this an issue (and hence not a question)? - -If this is a question how to use MapStruct there are several resources available. -- Our reference- and API [documentation](http://mapstruct.org/documentation/reference-guide/). -- Our [examples](https://github.com/mapstruct/mapstruct-examples) repository (contributions always welcome) -- Our [FAQ](http://mapstruct.org/faq/) -- [StackOverflow](https://stackoverflow.com), tag MapStruct -- [Gitter](https://gitter.im/mapstruct/mapstruct-users) (you usually get fast feedback) -- Our [google group](https://groups.google.com/forum/#!forum/mapstruct-users) \ No newline at end of file From 811cd569bb80ed45f0da74cb603d9bfea774ad0c Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 27 Sep 2022 02:02:01 +0900 Subject: [PATCH 0719/1006] Javadoc and documentation polishing (#3026) --- core/src/main/java/org/mapstruct/EnumMapping.java | 2 +- .../java/org/mapstruct/NullValueCheckStrategy.java | 2 +- .../mapstruct/ap/internal/model/HelperMethod.java | 2 +- .../internal/model/source/builtin/BuiltInMethod.java | 2 +- .../java/org/mapstruct/ap/internal/util/Message.java | 2 +- .../ap/internal/model/StreamMappingMethod.ftl | 2 +- .../mapstruct/ap/test/bugs/_1719/Issue1719Test.java | 4 ++-- .../test/context/ContextParameterErroneousTest.java | 2 +- readme.md | 12 ++++++------ 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/org/mapstruct/EnumMapping.java b/core/src/main/java/org/mapstruct/EnumMapping.java index ba3a5e0cb0..375f969b01 100644 --- a/core/src/main/java/org/mapstruct/EnumMapping.java +++ b/core/src/main/java/org/mapstruct/EnumMapping.java @@ -98,7 +98,7 @@ *

        *
      • {@link MappingConstants#SUFFIX_TRANSFORMATION} - applies the given {@link #configuration()} as a * suffix to the source enum
      • - *
      • {@link MappingConstants#STRIP_SUFFIX_TRANSFORMATION} - strips the the given {@link #configuration()} + *
      • {@link MappingConstants#STRIP_SUFFIX_TRANSFORMATION} - strips the given {@link #configuration()} * from the end of the source enum
      • *
      • {@link MappingConstants#PREFIX_TRANSFORMATION} - applies the given {@link #configuration()} as a * prefix to the source enum
      • diff --git a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java index 446b879d92..22dba7c58b 100644 --- a/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValueCheckStrategy.java @@ -8,7 +8,7 @@ /** * Strategy for dealing with null source values. * - * Note: This strategy is not in effect when the a specific source presence check method is defined + * Note: This strategy is not in effect when a specific source presence check method is defined * in the service provider interface (SPI). *

        * Note: some types of mappings (collections, maps), in which MapStruct is instructed to use a getter or adder diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java index 35b35aee73..6ff85c585f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/HelperMethod.java @@ -176,7 +176,7 @@ public boolean equals(Object obj) { * * @param parameter source * @param returnType target - * @return {@code true}, iff the the type variables match + * @return {@code true}, iff the type variables match */ public boolean doTypeVarsMatch(Type parameter, Type returnType) { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java index f46b201576..6d41872159 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/BuiltInMethod.java @@ -190,7 +190,7 @@ public boolean equals(Object obj) { * * @param parameter source * @param returnType target - * @return {@code true}, iff the the type variables match + * @return {@code true}, iff the type variables match */ public boolean doTypeVarsMatch(Type parameter, Type returnType) { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 92951ad521..29600489fb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -159,7 +159,7 @@ public enum Message { RETRIEVAL_NO_INPUT_ARGS( "Can't generate mapping method with no input arguments." ), RETRIEVAL_DUPLICATE_MAPPING_TARGETS( "Can't generate mapping method with more than one @MappingTarget parameter." ), RETRIEVAL_VOID_MAPPING_METHOD( "Can't generate mapping method with return type void." ), - RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE( "The result type is not assignable to the the return type." ), + RETRIEVAL_NON_ASSIGNABLE_RESULTTYPE( "The result type is not assignable to the return type." ), RETRIEVAL_ITERABLE_TO_NON_ITERABLE( "Can't generate mapping method from iterable type from java stdlib to non-iterable type." ), RETRIEVAL_MAPPING_HAS_TARGET_TYPE_PARAMETER( "Can't generate mapping method that has a parameter annotated with @TargetType." ), RETRIEVAL_NON_ITERABLE_TO_ITERABLE( "Can't generate mapping method from non-iterable type to iterable type from java stdlib." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index 7b5b44bd56..29977bdd5d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -114,7 +114,7 @@ <#else> <#-- Streams are immutable so we can't update them --> <#if !existingInstanceMapping> - <#--TODO fhr: after the the result is no longer the same instance, how does it affect the + <#--TODO fhr: after the result is no longer the same instance, how does it affect the Before mapping methods. Does it even make sense to have before mapping on a stream? --> <#if sourceParameter.type.arrayType> <@returnLocalVarDefOrUpdate>Stream.of( ${sourceParameter.name} )<@streamMapSupplier />; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java index 182e1849be..7a8665e49f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1719/Issue1719Test.java @@ -23,8 +23,8 @@ public class Issue1719Test { /** * For adder methods MapStuct cannot generate an update method. MapStruct would cannot know how to remove objects - * from the child-parent relation. It cannot even assume that the the collection can be cleared at forehand. - * Therefore the only sensible choice is for MapStruct to create a create method for the target elements. + * from the child-parent relation. It cannot even assume that the collection can be cleared at forehand. + * Therefore, the only sensible choice is for MapStruct to create a create method for the target elements. */ @ProcessorTest @WithClasses(Issue1719Mapper.class) diff --git a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java index 77fefe756e..46bb08cb70 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/context/ContextParameterErroneousTest.java @@ -19,7 +19,7 @@ /** * Tests the erroneous usage of the {@link Context} annotation in the following situations: *

          - *
        • using the the same context parameter type twice in the same method + *
        • using the same context parameter type twice in the same method *
        * * @author Andreas Gudian diff --git a/readme.md b/readme.md index e5811060a6..e1ee8f9deb 100644 --- a/readme.md +++ b/readme.md @@ -114,7 +114,7 @@ plugins { dependencies { ... - compile 'org.mapstruct:mapstruct:1.5.2.Final' + implementation 'org.mapstruct:mapstruct:1.5.2.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' // if you are using mapstruct in test code @@ -122,7 +122,7 @@ dependencies { ... ``` -If you don't work with a dependency management tool, you can obtain a distribution bundle from [SourceForge](https://sourceforge.net/projects/mapstruct/files/). +If you don't work with a dependency management tool, you can obtain a distribution bundle from [Releases page](https://github.com/mapstruct/mapstruct/releases). ## Documentation and getting help @@ -132,16 +132,16 @@ To learn more about MapStruct, refer to the [project homepage](http://mapstruct. MapStruct uses Maven for its build. Java 11 is required for building MapStruct from source. To build the complete project, run - mvn clean install + ./mvnw clean install from the root of the project directory. To skip the distribution module, run - mvn clean install -DskipDistribution=true + ./mvnw clean install -DskipDistribution=true ## Importing into IDE -MapStruct uses the gem annotation processor to generate mapping gems for it's own annotations. -Therefore for seamless integration within an IDE annotation processing needs to be enabled. +MapStruct uses the gem annotation processor to generate mapping gems for its own annotations. +Therefore, for seamless integration within an IDE annotation processing needs to be enabled. ### IntelliJ From 73e8fd6152153ba8c2f76fc5e9a84b16d33f6a0b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 27 Sep 2022 09:35:54 +0200 Subject: [PATCH 0720/1006] #2840, #2913, #2921: MethodMatcher should not match widening methods In the MethodMatcher we need to do a special check when the target type is primitive. The reason for that is that a Long is assignable to a primitive double. However, doing that means that information can be lost and thus we should not pick such methods. When the target type is primitive, then a method will be matched if and only if boxed equivalent of the target type is assignable to the boxed equivalent of the candidate return type --- .../internal/model/source/MethodMatcher.java | 11 +++ .../ap/test/bugs/_2840/Issue2840Mapper.java | 51 +++++++++++ .../ap/test/bugs/_2840/Issue2840Test.java | 31 +++++++ .../ap/test/bugs/_2913/Issue2913Mapper.java | 85 +++++++++++++++++++ .../ap/test/bugs/_2913/Issue2913Test.java | 35 ++++++++ .../ap/test/bugs/_2921/Issue2921Mapper.java | 49 +++++++++++ .../ap/test/bugs/_2921/Issue2921Test.java | 28 ++++++ 7 files changed, 290 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index baa3d7eac5..42c26f09a0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -82,6 +82,17 @@ boolean matches(List sourceTypes, Type targetType) { // (the relation target / target type, target type being a class) if ( !analyser.candidateReturnType.isVoid() ) { + if ( targetType.isPrimitive() ) { + // If the target type is primitive + // then we are going to check if its boxed equivalent + // is assignable to the candidate return type + // This is done because primitives can be assigned from their own narrower counterparts + // directly without any casting. + // e.g. a Long is assignable to a primitive double + // However, in order not to lose information we are not going to allow this + return targetType.getBoxedEquivalent() + .isAssignableTo( analyser.candidateReturnType.getBoxedEquivalent() ); + } if ( !( analyser.candidateReturnType.isAssignableTo( targetType ) ) ) { return false; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Mapper.java new file mode 100644 index 0000000000..d2baac8cac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Mapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2840; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2840Mapper { + + Issue2840Mapper INSTANCE = + Mappers.getMapper( Issue2840Mapper.class ); + + Issue2840Mapper.Target map(Short shortValue, Integer intValue); + + default int toInt(Number number) { + return number.intValue() + 5; + } + + default short toShort(Number number) { + return (short) (number.shortValue() + 10); + } + + class Target { + + private int intValue; + private short shortValue; + + public int getIntValue() { + return intValue; + } + + public void setIntValue(int intValue) { + this.intValue = intValue; + } + + public short getShortValue() { + return shortValue; + } + + public void setShortValue(short shortValue) { + this.shortValue = shortValue; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Test.java new file mode 100644 index 0000000000..1c6b19306f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2840/Issue2840Test.java @@ -0,0 +1,31 @@ + +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2840; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2840") +@WithClasses({ + Issue2840Mapper.class, +}) +class Issue2840Test { + + @ProcessorTest + void shouldUseMethodWithMostSpecificReturnType() { + Issue2840Mapper.Target target = Issue2840Mapper.INSTANCE.map( (short) 10, 50 ); + + assertThat( target.getShortValue() ).isEqualTo( (short) 20 ); + assertThat( target.getIntValue() ).isEqualTo( 55 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Mapper.java new file mode 100644 index 0000000000..095f5457fd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Mapper.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2913; + +import java.math.BigDecimal; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2913Mapper { + + Issue2913Mapper INSTANCE = Mappers.getMapper( Issue2913Mapper.class ); + + @Mapping(target = "doublePrimitiveValue", source = "rounding") + @Mapping(target = "doubleValue", source = "rounding") + @Mapping(target = "longPrimitiveValue", source = "rounding") + @Mapping(target = "longValue", source = "rounding") + Target map(Source source); + + default Long mapAmount(BigDecimal amount) { + return amount != null ? amount.movePointRight( 2 ).longValue() : null; + } + + class Target { + + private double doublePrimitiveValue; + private Double doubleValue; + private long longPrimitiveValue; + private Long longValue; + + public double getDoublePrimitiveValue() { + return doublePrimitiveValue; + } + + public void setDoublePrimitiveValue(double doublePrimitiveValue) { + this.doublePrimitiveValue = doublePrimitiveValue; + } + + public Double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(Double doubleValue) { + this.doubleValue = doubleValue; + } + + public long getLongPrimitiveValue() { + return longPrimitiveValue; + } + + public void setLongPrimitiveValue(long longPrimitiveValue) { + this.longPrimitiveValue = longPrimitiveValue; + } + + public Long getLongValue() { + return longValue; + } + + public void setLongValue(Long longValue) { + this.longValue = longValue; + } + } + + class Source { + + private final BigDecimal rounding; + + public Source(BigDecimal rounding) { + this.rounding = rounding; + } + + public BigDecimal getRounding() { + return rounding; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Test.java new file mode 100644 index 0000000000..7257c9ab7e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2913/Issue2913Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2913; + +import java.math.BigDecimal; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2913") +@WithClasses({ + Issue2913Mapper.class, +}) +class Issue2913Test { + + @ProcessorTest + void shouldNotWidenWithUserDefinedMethods() { + Issue2913Mapper.Source source = new Issue2913Mapper.Source( BigDecimal.valueOf( 10.543 ) ); + Issue2913Mapper.Target target = Issue2913Mapper.INSTANCE.map( source ); + + assertThat( target.getDoubleValue() ).isEqualTo( 10.543 ); + assertThat( target.getDoublePrimitiveValue() ).isEqualTo( 10.543 ); + assertThat( target.getLongValue() ).isEqualTo( 1054 ); + assertThat( target.getLongPrimitiveValue() ).isEqualTo( 1054 ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Mapper.java new file mode 100644 index 0000000000..d686fcbc16 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Mapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2921; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue2921Mapper { + + Issue2921Mapper INSTANCE = Mappers.getMapper( Issue2921Mapper.class ); + + Target map(Source source); + + default Short toShort(Integer value) { + throw new UnsupportedOperationException( "toShort method should not be used" ); + } + + class Source { + private final Integer value; + + public Source(Integer value) { + this.value = value; + } + + public Integer getValue() { + return value; + } + } + + class Target { + private final int value; + + public Target(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Test.java new file mode 100644 index 0000000000..5b8dd0386c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2921/Issue2921Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2921; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2921") +@WithClasses({ + Issue2921Mapper.class, +}) +class Issue2921Test { + + @ProcessorTest + void shouldNotUseIntegerToShortForMappingIntegerToInt() { + Issue2921Mapper.Target target = Issue2921Mapper.INSTANCE.map( new Issue2921Mapper.Source( 10 ) ); + assertThat( target.getValue() ).isEqualTo( 10 ); + } +} From e979f506fac6aeabfa3a1993b3b986449fcb7b3a Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Thu, 29 Sep 2022 04:17:59 +0800 Subject: [PATCH 0721/1006] #2773 Copy `@Deprecated` annotation from method or mapper to implementation --- ...eatureCompilationExclusionCliEnhancer.java | 1 + .../test/resources/fullFeatureTest/pom.xml | 2 + .../ap/internal/gem/GemGenerator.java | 1 + .../model/AdditionalAnnotationsBuilder.java | 42 ++++++++++++- .../test/annotatewith/AnnotateWithTest.java | 1 - .../deprecated/DeprecatedMapperWithClass.java | 13 ++++ .../DeprecatedMapperWithMethod.java | 44 +++++++++++++ .../deprecated/DeprecatedTest.java | 56 +++++++++++++++++ .../deprecated/RepeatDeprecatedMapper.java | 15 +++++ .../jdk11/DeprecatedMapperWithClass.java | 13 ++++ .../jdk11/DeprecatedMapperWithMethod.java | 44 +++++++++++++ .../deprecated/jdk11/DeprecatedTest.java | 63 +++++++++++++++++++ .../RepeatDeprecatedMapperWithParams.java | 21 +++++++ 13 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithMethod.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/RepeatDeprecatedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithClass.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithMethod.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/RepeatDeprecatedMapperWithParams.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index 0f261d6568..e017d1b003 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -31,6 +31,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces case JAVA_8: additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/annotatewith/deprecated/jdk11/*.java" ); break; case JAVA_9: // TODO find out why this fails: diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index ac69114bd6..8a62f48588 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -25,6 +25,7 @@ x x x + x @@ -45,6 +46,7 @@ ${additionalExclude2} ${additionalExclude3} ${additionalExclude4} + ${additionalExclude5} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index cbb59f4e57..5caea8a008 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -45,6 +45,7 @@ * * @author Gunnar Morling */ +@GemDefinition(Deprecated.class) @GemDefinition(AnnotateWith.class) @GemDefinition(AnnotateWith.Element.class) @GemDefinition(AnnotateWiths.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java index f28cdfef9c..3f0b2123ae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java @@ -10,6 +10,7 @@ import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; @@ -31,6 +32,7 @@ import org.mapstruct.ap.internal.gem.AnnotateWithGem; import org.mapstruct.ap.internal.gem.AnnotateWithsGem; +import org.mapstruct.ap.internal.gem.DeprecatedGem; import org.mapstruct.ap.internal.gem.ElementGem; import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; @@ -55,7 +57,6 @@ public class AdditionalAnnotationsBuilder extends RepeatableAnnotations { private static final String ANNOTATE_WITH_FQN = "org.mapstruct.AnnotateWith"; private static final String ANNOTATE_WITHS_FQN = "org.mapstruct.AnnotateWiths"; - private TypeFactory typeFactory; private FormattingMessager messager; @@ -90,6 +91,45 @@ protected void addInstances(AnnotateWithsGem gem, Element source, Set getProcessedAnnotations(Element source) { + Set processedAnnotations = super.getProcessedAnnotations( source ); + return addDeprecatedAnnotation( source, processedAnnotations ); + } + + private Set addDeprecatedAnnotation(Element source, Set annotations) { + DeprecatedGem deprecatedGem = DeprecatedGem.instanceOn( source ); + if ( deprecatedGem == null ) { + return annotations; + } + Type deprecatedType = typeFactory.getType( Deprecated.class ); + if ( annotations.stream().anyMatch( annotation -> annotation.getType().equals( deprecatedType ) ) ) { + messager.printMessage( + source, + deprecatedGem.mirror(), + Message.ANNOTATE_WITH_DUPLICATE, + deprecatedType.describe() ); + return annotations; + } + List annotationElements = new ArrayList<>(); + if ( deprecatedGem.since() != null && deprecatedGem.since().hasValue() ) { + annotationElements.add( new AnnotationElement( + AnnotationElementType.STRING, + "since", + Collections.singletonList( deprecatedGem.since().getValue() ) + ) ); + } + if ( deprecatedGem.forRemoval() != null && deprecatedGem.forRemoval().hasValue() ) { + annotationElements.add( new AnnotationElement( + AnnotationElementType.BOOLEAN, + "forRemoval", + Collections.singletonList( deprecatedGem.forRemoval().getValue() ) + ) ); + } + annotations.add( new Annotation(deprecatedType, annotationElements ) ); + return annotations; + } + private void addAndValidateMapping(Set mappings, Element source, AnnotateWithGem gem, Annotation anno) { if ( anno.getType().getTypeElement().getAnnotation( Repeatable.class ) == null ) { if ( mappings.stream().anyMatch( existing -> existing.getType().equals( anno.getType() ) ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java index e3b20f547e..3687fe2bc0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java @@ -593,5 +593,4 @@ public void valueMappingMethodWithCorrectCustomAnnotation() throws NoSuchMethodE Method method = mapper.getClass().getMethod( "map", String.class ); assertThat( method.getAnnotation( CustomMethodOnlyAnnotation.class ) ).isNotNull(); } - } diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithClass.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithClass.java new file mode 100644 index 0000000000..d0164e8be0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithClass.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated; + +import org.mapstruct.Mapper; + +@Mapper +@Deprecated +public class DeprecatedMapperWithClass { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithMethod.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithMethod.java new file mode 100644 index 0000000000..b6c2c8eb62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedMapperWithMethod.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; + +@Mapper +public interface DeprecatedMapperWithMethod { + + @AnnotateWith(CustomMethodOnlyAnnotation.class) + @Deprecated + Target map(Source source); + + class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedTest.java new file mode 100644 index 0000000000..5abca7171e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/DeprecatedTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated; + +import java.lang.reflect.Method; +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author orange add + */ +public class DeprecatedTest { + + @ProcessorTest + @WithClasses( { DeprecatedMapperWithMethod.class, CustomMethodOnlyAnnotation.class} ) + public void deprecatedWithMethodCorrectCopy() throws NoSuchMethodException { + DeprecatedMapperWithMethod mapper = Mappers.getMapper( DeprecatedMapperWithMethod.class ); + Method method = mapper.getClass().getMethod( "map", DeprecatedMapperWithMethod.Source.class ); + Deprecated annotation = method.getAnnotation( Deprecated.class ); + assertThat( annotation ).isNotNull(); + } + + @ProcessorTest + @WithClasses(DeprecatedMapperWithClass.class) + public void deprecatedWithClassCorrectCopy() { + DeprecatedMapperWithClass mapper = Mappers.getMapper( DeprecatedMapperWithClass.class ); + Deprecated annotation = mapper.getClass().getAnnotation( Deprecated.class ); + assertThat( annotation ).isNotNull(); + } + + @ProcessorTest + @WithClasses(RepeatDeprecatedMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = RepeatDeprecatedMapper.class, + message = "Annotation \"Deprecated\" is already present with the " + + "same elements configuration." + ) + } + ) + public void deprecatedWithRepeat() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/RepeatDeprecatedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/RepeatDeprecatedMapper.java new file mode 100644 index 0000000000..dd085f101c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/RepeatDeprecatedMapper.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@Deprecated +@AnnotateWith(Deprecated.class) +public class RepeatDeprecatedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithClass.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithClass.java new file mode 100644 index 0000000000..2e0507f5ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithClass.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated.jdk11; + +import org.mapstruct.Mapper; + +@Mapper +@Deprecated(since = "11") +public class DeprecatedMapperWithClass { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithMethod.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithMethod.java new file mode 100644 index 0000000000..bf898e2043 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedMapperWithMethod.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated.jdk11; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; + +@Mapper +public interface DeprecatedMapperWithMethod { + + @AnnotateWith(CustomMethodOnlyAnnotation.class) + @Deprecated(since = "18", forRemoval = false) + Target map(Source source); + + class Source { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedTest.java new file mode 100644 index 0000000000..4e10b6ded6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/DeprecatedTest.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated.jdk11; + +import java.lang.reflect.Method; +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author orange add + */ +public class DeprecatedTest { + @ProcessorTest + @WithClasses({ DeprecatedMapperWithMethod.class, CustomMethodOnlyAnnotation.class}) + public void deprecatedWithMethodCorrectCopyForJdk11() throws NoSuchMethodException { + DeprecatedMapperWithMethod mapper = Mappers.getMapper( DeprecatedMapperWithMethod.class ); + Method method = mapper.getClass().getMethod( "map", DeprecatedMapperWithMethod.Source.class ); + Deprecated annotation = method.getAnnotation( Deprecated.class ); + assertThat( annotation ).isNotNull(); + assertThat( annotation.since() ).isEqualTo( "18" ); + assertThat( annotation.forRemoval() ).isEqualTo( false ); + } + + @ProcessorTest + @WithClasses(DeprecatedMapperWithClass.class) + public void deprecatedWithClassCorrectCopyForJdk11() { + DeprecatedMapperWithClass mapper = Mappers.getMapper( DeprecatedMapperWithClass.class ); + Deprecated annotation = mapper.getClass().getAnnotation( Deprecated.class ); + assertThat( annotation ).isNotNull(); + assertThat( annotation.since() ).isEqualTo( "11" ); + } + + @ProcessorTest + @WithClasses( { RepeatDeprecatedMapperWithParams.class}) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = RepeatDeprecatedMapperWithParams.class, + message = "Annotation \"Deprecated\" is already present with the " + + "same elements configuration." + ) + } + ) + public void bothExistPriorityAnnotateWithForJdk11() { + RepeatDeprecatedMapperWithParams mapper = Mappers.getMapper( RepeatDeprecatedMapperWithParams.class ); + Deprecated deprecated = mapper.getClass().getAnnotation( Deprecated.class ); + assertThat( deprecated ).isNotNull(); + assertThat( deprecated.since() ).isEqualTo( "1.5" ); + assertThat( deprecated.forRemoval() ).isEqualTo( false ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/RepeatDeprecatedMapperWithParams.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/RepeatDeprecatedMapperWithParams.java new file mode 100644 index 0000000000..971791bfd2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/deprecated/jdk11/RepeatDeprecatedMapperWithParams.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.annotatewith.deprecated.jdk11; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; + +@Mapper +@Deprecated( since = "1.8" ) +@AnnotateWith( + value = Deprecated.class, + elements = { + @AnnotateWith.Element( name = "forRemoval", booleans = false), + @AnnotateWith.Element( name = "since", strings = "1.5") + } +) +public class RepeatDeprecatedMapperWithParams { +} From 608d476ed26ce4ac3096e2d9a2ee2a8226e42a00 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Thu, 29 Sep 2022 21:35:51 +0200 Subject: [PATCH 0722/1006] #3018: Use MappingControl with SubclassMapping --- .../ap/internal/model/BeanMappingMethod.java | 2 +- .../test/subclassmapping/DeepCloneMapper.java | 23 ++++++++++++++ .../DeepCloneMethodMapper.java | 26 ++++++++++++++++ .../subclassmapping/SubclassMappingTest.java | 30 +++++++++++++++++++ .../test/subclassmapping/mappables/Car.java | 1 + 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4f2dc4e5f1..24e160b9de 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -405,7 +405,7 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap Collections.emptyList(), subclassMappingOptions.getTarget(), ctx.getTypeUtils() ).withSourceRHS( rightHandSide ), - null, + subclassMappingOptions.getMappingControl( ctx.getElementUtils() ), null, false ); Assignment assignment = ctx diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMapper.java new file mode 100644 index 0000000000..24d0244729 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +@Mapper(mappingControl = DeepClone.class) +public interface DeepCloneMapper { + DeepCloneMapper INSTANCE = Mappers.getMapper( DeepCloneMapper.class ); + + @SubclassMapping( source = Car.class, target = Car.class ) + @SubclassMapping( source = Bike.class, target = Bike.class ) + Vehicle map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java new file mode 100644 index 0000000000..3f276b24cd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DeepCloneMethodMapper { + DeepCloneMethodMapper INSTANCE = Mappers.getMapper( DeepCloneMethodMapper.class ); + + @SubclassMapping( source = Car.class, target = Car.class ) + @SubclassMapping( source = Bike.class, target = Bike.class ) + @BeanMapping( mappingControl = DeepClone.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL ) + Vehicle map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java index 7df555ecc2..6f9b6e160c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -52,6 +52,36 @@ void mappingIsDoneUsingSubclassMapping() { .containsExactly( CarDto.class, BikeDto.class ); } + @ProcessorTest + @WithClasses( DeepCloneMapper.class ) + void deepCloneMappingClonesObjects() { + Car car = new Car(); + car.setManual( true ); + car.setName( "namedCar" ); + car.setVehicleManufacturingCompany( "veMac" ); + + Vehicle result = DeepCloneMapper.INSTANCE.map( car ); + + assertThat( result ).isInstanceOf( Car.class ); + assertThat( result ).isNotSameAs( car ); + assertThat( result ).usingRecursiveComparison().isEqualTo( car ); + } + + @ProcessorTest + @WithClasses( DeepCloneMethodMapper.class ) + void deepCloneMappingOnMethodClonesObjects() { + Car car = new Car(); + car.setManual( true ); + car.setName( "namedCar" ); + car.setVehicleManufacturingCompany( "veMac" ); + + Vehicle result = DeepCloneMethodMapper.INSTANCE.map( car ); + + assertThat( result ).isInstanceOf( Car.class ); + assertThat( result ).isNotSameAs( car ); + assertThat( result ).usingRecursiveComparison().isEqualTo( car ); + } + @ProcessorTest @WithClasses( SimpleSubclassMapper.class ) void inverseMappingIsDoneUsingSubclassMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java index 71b2446d34..6f33a6cb61 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/mappables/Car.java @@ -15,4 +15,5 @@ public boolean isManual() { public void setManual(boolean manual) { this.manual = manual; } + } From af1eab0ece084aa04798e2d86fc20bd65bfa784e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Sep 2022 22:10:27 +0200 Subject: [PATCH 0723/1006] #2743 BeanMappingOptions should not be inherited for forged methods --- .../model/source/BeanMappingOptions.java | 7 +- .../model/source/MappingMethodOptions.java | 2 +- .../ap/test/bugs/_2743/Issue2743Mapper.java | 75 +++++++++++++++++++ .../ap/test/bugs/_2743/Issue2743Test.java | 24 ++++++ 4 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 60aac32e54..b73b4084fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -54,13 +54,16 @@ public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) return options; } + public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) { + return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions ); + } + public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions, ExecutableElement method, FormattingMessager messager, TypeUtils typeUtils, TypeFactory typeFactory ) { if ( beanMapping == null || !isConsistent( beanMapping, method, messager ) ) { - BeanMappingOptions options = new BeanMappingOptions( null, Collections.emptyList(), null, mapperOptions ); - return options; + return empty( mapperOptions ); } Objects.requireNonNull( method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 4a140c4fb9..a1a64872a9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -365,7 +365,7 @@ public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethod options.mappings, options.iterableMapping, options.mapMapping, - options.beanMapping, + BeanMappingOptions.empty( options.beanMapping.next() ), options.enumMappingOptions, options.valueMappings, Collections.emptySet(), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Mapper.java new file mode 100644 index 0000000000..db3c0e6d49 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Mapper.java @@ -0,0 +1,75 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2743; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue2743Mapper { + + @BeanMapping(ignoreUnmappedSourceProperties = { "number" }) + Target map(Source source); + + class Source { + + private final int number = 10; + private final NestedSource nested; + + public Source(NestedSource nested) { + this.nested = nested; + } + + public int getNumber() { + return number; + } + + public NestedSource getNested() { + return nested; + } + } + + class NestedSource { + private final String value; + + public NestedSource(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + + private final NestedTarget nested; + + public Target(NestedTarget nested) { + this.nested = nested; + } + + public NestedTarget getNested() { + return nested; + } + } + + class NestedTarget { + private final String value; + + public NestedTarget(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Test.java new file mode 100644 index 0000000000..5c2bb61279 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2743/Issue2743Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2743; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2743") +@WithClasses({ + Issue2743Mapper.class +}) +class Issue2743Test { + + @ProcessorTest + void shouldCompile() { + } +} From 90a487ac0641c39ebec6680567cc97eaede49365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Campanero=20Ortiz?= Date: Sat, 1 Oct 2022 13:47:49 +0200 Subject: [PATCH 0724/1006] #1427 Add support for custom name in Spring stereotype annotations --- .../processor/SpringComponentProcessor.java | 67 +++++++++++++- .../spring/annotateWith/CustomStereotype.java | 21 +++++ ...ustomerSpringComponentQualifiedMapper.java | 20 ++++ ...stomerSpringControllerQualifiedMapper.java | 19 ++++ ...SpringCustomStereotypeQualifiedMapper.java | 21 +++++ ...stomerSpringRepositoryQualifiedMapper.java | 19 ++++ .../CustomerSpringServiceQualifiedMapper.java | 19 ++++ .../SpringAnnotateWithMapperTest.java | 91 +++++++++++++++++++ 8 files changed, 276 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomStereotype.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringComponentQualifiedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringControllerQualifiedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringCustomStereotypeQualifiedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringRepositoryQualifiedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringServiceQualifiedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/SpringAnnotateWithMapperTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index 4efc537c3d..84a672bcc9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -8,7 +8,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; @@ -16,6 +18,13 @@ import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; + +import static javax.lang.model.element.ElementKind.PACKAGE; + /** * A {@link ModelElementProcessor} which converts the given {@link Mapper} * object into a Spring bean in case Spring is configured as the @@ -25,6 +34,7 @@ * @author Andreas Gudian */ public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor { + @Override protected String getComponentModelIdentifier() { return MappingConstantsGem.ComponentModelGem.SPRING; @@ -33,7 +43,9 @@ protected String getComponentModelIdentifier() { @Override protected List getTypeAnnotations(Mapper mapper) { List typeAnnotations = new ArrayList<>(); - typeAnnotations.add( component() ); + if ( !isAlreadyAnnotatedAsSpringStereotype( mapper ) ) { + typeAnnotations.add( component() ); + } if ( mapper.getDecorator() != null ) { typeAnnotations.add( qualifierDelegate() ); @@ -91,4 +103,57 @@ private Annotation primary() { private Annotation component() { return new Annotation( getTypeFactory().getType( "org.springframework.stereotype.Component" ) ); } + + private boolean isAlreadyAnnotatedAsSpringStereotype(Mapper mapper) { + Set handledElements = new HashSet<>(); + return mapper.getAnnotations() + .stream() + .anyMatch( + annotation -> isOrIncludesComponentAnnotation( annotation, handledElements ) + ); + } + + private boolean isOrIncludesComponentAnnotation(Annotation annotation, Set handledElements) { + return isOrIncludesComponentAnnotation( + annotation.getType().getTypeElement(), handledElements + ); + } + + private boolean isOrIncludesComponentAnnotation(Element element, Set handledElements) { + if ( "org.springframework.stereotype.Component".equals( + ( (TypeElement) element ).getQualifiedName().toString() + )) { + return true; + } + + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + Element annotationMirrorElement = annotationMirror.getAnnotationType().asElement(); + // Bypass java lang annotations to improve performance avoiding unnecessary checks + if ( !isAnnotationInPackage( annotationMirrorElement, "java.lang.annotation" ) && + !handledElements.contains( annotationMirrorElement ) ) { + handledElements.add( annotationMirrorElement ); + boolean isOrIncludesComponentAnnotation = isOrIncludesComponentAnnotation( + annotationMirrorElement, handledElements + ); + + if ( isOrIncludesComponentAnnotation ) { + return true; + } + } + } + + return false; + } + + private PackageElement getPackageOf( Element element ) { + while ( element.getKind() != PACKAGE ) { + element = element.getEnclosingElement(); + } + + return (PackageElement) element; + } + + private boolean isAnnotationInPackage(Element element, String packageFQN) { + return packageFQN.equals( getPackageOf( element ).getQualifiedName().toString() ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomStereotype.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomStereotype.java new file mode 100644 index 0000000000..ccc196c5d3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomStereotype.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.springframework.stereotype.Component; + +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface CustomStereotype { + String value() default ""; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringComponentQualifiedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringComponentQualifiedMapper.java new file mode 100644 index 0000000000..be08ff0b1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringComponentQualifiedMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.springframework.stereotype.Component; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; + +/** + * @author Ben Zegveld + */ +@AnnotateWith( value = Component.class, elements = @AnnotateWith.Element( strings = "AnnotateWithComponent" ) ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING ) +public interface CustomerSpringComponentQualifiedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringControllerQualifiedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringControllerQualifiedMapper.java new file mode 100644 index 0000000000..7203fad7a9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringControllerQualifiedMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.springframework.stereotype.Controller; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@AnnotateWith( value = Controller.class, elements = @AnnotateWith.Element( strings = "AnnotateWithController" ) ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING ) +public interface CustomerSpringControllerQualifiedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringCustomStereotypeQualifiedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringCustomStereotypeQualifiedMapper.java new file mode 100644 index 0000000000..18a062497d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringCustomStereotypeQualifiedMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@AnnotateWith( + value = CustomStereotype.class, + elements = @AnnotateWith.Element( strings = "AnnotateWithCustomStereotype" ) +) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING ) +public interface CustomerSpringCustomStereotypeQualifiedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringRepositoryQualifiedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringRepositoryQualifiedMapper.java new file mode 100644 index 0000000000..7bbefbee2b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringRepositoryQualifiedMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.springframework.stereotype.Repository; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@AnnotateWith( value = Repository.class, elements = @AnnotateWith.Element( strings = "AnnotateWithRepository" ) ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING ) +public interface CustomerSpringRepositoryQualifiedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringServiceQualifiedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringServiceQualifiedMapper.java new file mode 100644 index 0000000000..52dff8ef8f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/CustomerSpringServiceQualifiedMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.springframework.stereotype.Service; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@AnnotateWith( value = Service.class, elements = @AnnotateWith.Element( strings = "AnnotateWithService" ) ) +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING ) +public interface CustomerSpringServiceQualifiedMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/SpringAnnotateWithMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/SpringAnnotateWithMapperTest.java new file mode 100644 index 0000000000..cdc741814c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/annotateWith/SpringAnnotateWithMapperTest.java @@ -0,0 +1,91 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.annotateWith; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * Test field injection for component model spring. + * + * @author Filip Hrisafov + * @author Jose Carlos Campanero Ortiz + */ +@WithClasses({ + CustomerSpringComponentQualifiedMapper.class, + CustomerSpringControllerQualifiedMapper.class, + CustomerSpringServiceQualifiedMapper.class, + CustomerSpringRepositoryQualifiedMapper.class, + CustomStereotype.class, + CustomerSpringCustomStereotypeQualifiedMapper.class +}) +@IssueKey( "1427" ) +@WithSpring +public class SpringAnnotateWithMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveComponentAnnotatedQualifiedMapper() { + + // then + generatedSource.forMapper( CustomerSpringComponentQualifiedMapper.class ) + .content() + .contains( "@Component(value = \"AnnotateWithComponent\")" ) + .doesNotContain( "@Component" + System.lineSeparator() ); + + } + + @ProcessorTest + public void shouldHaveControllerAnnotatedQualifiedMapper() { + + // then + generatedSource.forMapper( CustomerSpringControllerQualifiedMapper.class ) + .content() + .contains( "@Controller(value = \"AnnotateWithController\")" ) + .doesNotContain( "@Component" ); + + } + + @ProcessorTest + public void shouldHaveServiceAnnotatedQualifiedMapper() { + + // then + generatedSource.forMapper( CustomerSpringServiceQualifiedMapper.class ) + .content() + .contains( "@Service(value = \"AnnotateWithService\")" ) + .doesNotContain( "@Component" ); + + } + + @ProcessorTest + public void shouldHaveRepositoryAnnotatedQualifiedMapper() { + + // then + generatedSource.forMapper( CustomerSpringRepositoryQualifiedMapper.class ) + .content() + .contains( "@Repository(value = \"AnnotateWithRepository\")" ) + .doesNotContain( "@Component" ); + + } + + @ProcessorTest + public void shouldHaveCustomStereotypeAnnotatedQualifiedMapper() { + + // then + generatedSource.forMapper( CustomerSpringCustomStereotypeQualifiedMapper.class ) + .content() + .contains( "@CustomStereotype(value = \"AnnotateWithCustomStereotype\")" ) + .doesNotContain( "@Component" ); + + } + +} From 411cc24dac06892dc7e5582aff9ce409302916b8 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 2 Oct 2022 09:34:03 +0200 Subject: [PATCH 0725/1006] #2955 Fix `@AfterMapping` with return type not called for update mappings --- .../model/LifecycleMethodResolver.java | 2 +- .../CallbacksWithReturnValuesTest.java | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 87527e87f8..8b44dee254 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -141,7 +141,7 @@ private static List collectLifecycleCallbackMe callbackMethods, Collections.emptyList(), targetType, - method.getReturnType(), + method.getResultType(), SelectionCriteria.forLifecycleMethods( selectionParameters ) ); return toLifecycleCallbackMethodRefs( diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index 8c391bbfeb..7d6eaacb79 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.concurrent.atomic.AtomicReference; +import org.junit.jupiter.api.AfterEach; import org.mapstruct.ap.test.callbacks.returning.NodeMapperContext.ContextListener; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -25,23 +26,29 @@ @WithClasses( { Attribute.class, AttributeDto.class, Node.class, NodeDto.class, NodeMapperDefault.class, NodeMapperWithContext.class, NodeMapperContext.class, Number.class, NumberMapperDefault.class, NumberMapperContext.class, NumberMapperWithContext.class } ) -public class CallbacksWithReturnValuesTest { +class CallbacksWithReturnValuesTest { + @AfterEach + void cleanup() { + NumberMapperContext.clearCache(); + NumberMapperContext.clearVisited(); + } + @ProcessorTest - public void mappingWithDefaultHandlingRaisesStackOverflowError() { + void mappingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); assertThatThrownBy( () -> NodeMapperDefault.INSTANCE.nodeToNodeDto( root ) ) .isInstanceOf( StackOverflowError.class ); } @ProcessorTest - public void updatingWithDefaultHandlingRaisesStackOverflowError() { + void updatingWithDefaultHandlingRaisesStackOverflowError() { Node root = buildNodes(); assertThatThrownBy( () -> NodeMapperDefault.INSTANCE.nodeToNodeDto( root, new NodeDto() ) ) .isInstanceOf( StackOverflowError.class ); } @ProcessorTest - public void mappingWithContextCorrectlyResolvesCycles() { + void mappingWithContextCorrectlyResolvesCycles() { final AtomicReference contextLevel = new AtomicReference<>( null ); ContextListener contextListener = new ContextListener() { @Override @@ -75,28 +82,49 @@ private static Node buildNodes() { } @ProcessorTest - public void numberMappingWithoutContextDoesNotUseCache() { + void numberMappingWithoutContextDoesNotUseCache() { Number n1 = NumberMapperDefault.INSTANCE.integerToNumber( 2342 ); Number n2 = NumberMapperDefault.INSTANCE.integerToNumber( 2342 ); + assertThat( n1 ).isEqualTo( n2 ); assertThat( n1 ).isNotSameAs( n2 ); } @ProcessorTest - public void numberMappingWithContextUsesCache() { + void numberMappingWithContextUsesCache() { NumberMapperContext.putCache( new Number( 2342 ) ); Number n1 = NumberMapperWithContext.INSTANCE.integerToNumber( 2342 ); Number n2 = NumberMapperWithContext.INSTANCE.integerToNumber( 2342 ); + assertThat( n1 ).isEqualTo( n2 ); assertThat( n1 ).isSameAs( n2 ); - NumberMapperContext.clearCache(); } @ProcessorTest - public void numberMappingWithContextCallsVisitNumber() { + void numberMappingWithContextCallsVisitNumber() { Number n1 = NumberMapperWithContext.INSTANCE.integerToNumber( 1234 ); Number n2 = NumberMapperWithContext.INSTANCE.integerToNumber( 5678 ); + assertThat( NumberMapperContext.getVisited() ).isEqualTo( Arrays.asList( n1, n2 ) ); - NumberMapperContext.clearVisited(); + } + + @ProcessorTest + @IssueKey( "2955" ) + void numberUpdateMappingWithContextUsesCacheAndThereforeDoesNotVisitNumber() { + Number target = new Number(); + Number expectedReturn = new Number( 2342 ); + NumberMapperContext.putCache( expectedReturn ); + NumberMapperWithContext.INSTANCE.integerToNumber( 2342, target ); + + assertThat( NumberMapperContext.getVisited() ).isEmpty(); + } + + @ProcessorTest + @IssueKey( "2955" ) + void numberUpdateMappingWithContextCallsVisitNumber() { + Number target = new Number(); + NumberMapperWithContext.INSTANCE.integerToNumber( 2342, target ); + + assertThat( NumberMapperContext.getVisited() ).contains( target ); } } From 266c5fa41ce6a07c4fb11b745b461c4ca19a8301 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Oct 2022 19:20:13 +0200 Subject: [PATCH 0726/1006] #1216 Pick candidate method with most specific return type When there are multiple candidate methods returning different types. We should be able to use the method with the most specific return type (if such a method exists) --- .../source/selector/MethodSelectors.java | 4 +- .../MostSpecificResultTypeSelector.java | 45 +++++++++++++ .../source/selector/SelectionCriteria.java | 8 +++ ...MostSpecificResultTypeSelectingMapper.java | 31 +++++++++ .../selection/resulttype/FruitFamily.java | 22 ++++++ .../resulttype/InheritanceSelectionTest.java | 67 +++++++++++++++++++ ...MostSpecificResultTypeSelectingMapper.java | 30 +++++++++ ...ecificResultTypeSelectingUpdateMapper.java | 65 ++++++++++++++++++ 8 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamily.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingUpdateMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 519e1c3d6d..74fa1a33a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -37,7 +37,9 @@ public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFacto new InheritanceSelector(), new CreateOrUpdateSelector(), new SourceRhsSelector(), - new FactoryParameterSelector() ); + new FactoryParameterSelector(), + new MostSpecificResultTypeSelector() + ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java new file mode 100644 index 0000000000..6e86a30bc7 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * @author Filip Hrisafov + */ +public class MostSpecificResultTypeSelector implements MethodSelector { + + @Override + public List> getMatchingMethods(Method mappingMethod, + List> candidates, + List sourceTypes, Type mappingTargetType, + Type returnType, SelectionCriteria criteria) { + if ( candidates.size() < 2 || !criteria.isForMapping() || criteria.getQualifyingResultType() != null) { + return candidates; + } + + List> result = new ArrayList<>(); + + for ( SelectedMethod candidate : candidates ) { + if ( candidate.getMethod() + .getResultType() + .getBoxedEquivalent() + .equals( mappingTargetType.getBoxedEquivalent() ) ) { + // If the result type is the same as the target type + // then this candidate has the most specific match and should be used + result.add( candidate ); + } + } + + + // If not most specific types were found then return the current candidates + return result.isEmpty() ? candidates : result; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index da8bae365a..7e12bbd188 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -68,6 +68,14 @@ public SelectionCriteria(SelectionParameters selectionParameters, MappingControl this.type = type; } + /** + * + * @return {@code true} if only mapping methods should be selected + */ + public boolean isForMapping() { + return type == null || type == Type.PREFER_UPDATE_MAPPING; + } + /** * @return true if factory methods should be selected, false otherwise. */ diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.java new file mode 100644 index 0000000000..28a925c32b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousAmbiguousMostSpecificResultTypeSelectingMapper { + + @Mapping( target = "apple", source = "fruit") + AppleFamily map(FruitFamily fruitFamily); + + default GoldenDelicious toGolden(IsFruit fruit) { + return fruit != null ? new GoldenDelicious( fruit.getType() ) : null; + } + + default Apple toApple1(IsFruit fruit) { + return fruit != null ? new Apple( fruit.getType() ) : null; + } + + default Apple toApple2(IsFruit fruit) { + return fruit != null ? new Apple( fruit.getType() ) : null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamily.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamily.java new file mode 100644 index 0000000000..347e5a0be0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/FruitFamily.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +/** + * @author Filip Hrisafov + */ +public class FruitFamily { + + private IsFruit fruit; + + public IsFruit getFruit() { + return fruit; + } + + public void setFruit(IsFruit fruit) { + this.fruit = fruit; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index a6a4f1ad05..05245bafe0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -240,4 +240,71 @@ public void testShouldUseConstructorFromResultType() { .hasMessage( "Not allowed to change citrus type" ); assertThat( citrus.getType() ).isEqualTo( "lemon" ); } + + @ProcessorTest + @IssueKey("1216") + @WithClasses({ + Citrus.class, + GoldenDelicious.class, + FruitFamily.class, + AppleFamily.class, + MostSpecificResultTypeSelectingMapper.class, + Citrus.class + }) + public void testShouldUseMethodWithMostSpecificReturnType() { + FruitFamily fruitFamily = new FruitFamily(); + fruitFamily.setFruit( new Citrus( "citrus" ) ); + AppleFamily appleFamily = MostSpecificResultTypeSelectingMapper.INSTANCE.map( fruitFamily ); + + assertThat( appleFamily.getApple() ).isExactlyInstanceOf( Apple.class ); + assertThat( appleFamily.getApple().getType() ).isEqualTo( "citrus" ); + } + + @ProcessorTest + @IssueKey("1216") + @WithClasses({ + Citrus.class, + FruitFamily.class, + GoldenDelicious.class, + MostSpecificResultTypeSelectingUpdateMapper.class, + Citrus.class + }) + public void testShouldUseMethodWithMostSpecificReturnTypeForUpdateMappings() { + FruitFamily fruitFamily = new FruitFamily(); + fruitFamily.setFruit( new Citrus( "citrus" ) ); + MostSpecificResultTypeSelectingUpdateMapper.Target target = + new MostSpecificResultTypeSelectingUpdateMapper.Target( + new Apple( "from_test" ), + new GoldenDelicious( "from_test" ) + ); + MostSpecificResultTypeSelectingUpdateMapper.INSTANCE.update( target, fruitFamily ); + + assertThat( target.getApple() ).isExactlyInstanceOf( Apple.class ); + assertThat( target.getApple().getType() ).isEqualTo( "apple updated citrus" ); + assertThat( target.getGoldenApple() ).isExactlyInstanceOf( GoldenDelicious.class ); + assertThat( target.getGoldenApple().getType() ).isEqualTo( "golden updated citrus" ); + } + + @ProcessorTest + @IssueKey("1216") + @WithClasses({ + GoldenDelicious.class, + FruitFamily.class, + AppleFamily.class, + ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousAmbiguousMostSpecificResultTypeSelectingMapper.class, + kind = Kind.ERROR, + line = 17, + message = "Ambiguous mapping methods found for mapping property \"IsFruit fruit\" to Apple: " + + "Apple toApple1(IsFruit fruit), Apple toApple2(IsFruit fruit). " + + "See https://mapstruct.org/faq/#ambiguous for more info." + ) + } + ) + public void testAmbiguousMostSpecificResultTypeErroneous() { + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingMapper.java new file mode 100644 index 0000000000..16d9750ec2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MostSpecificResultTypeSelectingMapper { + + MostSpecificResultTypeSelectingMapper INSTANCE = Mappers.getMapper( MostSpecificResultTypeSelectingMapper.class ); + + @Mapping( target = "apple", source = "fruit") + AppleFamily map(FruitFamily fruitFamily); + + default GoldenDelicious toGolden(IsFruit fruit) { + return fruit != null ? new GoldenDelicious( fruit.getType() ) : null; + } + + default Apple toApple(IsFruit fruit) { + return fruit != null ? new Apple( fruit.getType() ) : null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingUpdateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingUpdateMapper.java new file mode 100644 index 0000000000..5f270116d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/MostSpecificResultTypeSelectingUpdateMapper.java @@ -0,0 +1,65 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.resulttype; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.ObjectFactory; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MostSpecificResultTypeSelectingUpdateMapper { + + MostSpecificResultTypeSelectingUpdateMapper INSTANCE = Mappers.getMapper( + MostSpecificResultTypeSelectingUpdateMapper.class ); + + @Mapping(target = "apple", source = "fruit") + @Mapping(target = "goldenApple", source = "fruit") + void update(@MappingTarget Target target, FruitFamily fruitFamily); + + default void updateGolden(@MappingTarget GoldenDelicious target, IsFruit fruit) { + target.setType( "golden updated " + fruit.getType() ); + } + + default void updateApple(@MappingTarget Apple target, IsFruit fruit) { + target.setType( "apple updated " + fruit.getType() ); + } + + @ObjectFactory + default GoldenDelicious createGolden() { + return new GoldenDelicious( "from_object_factory" ); + } + + class Target { + protected Apple apple; + protected GoldenDelicious goldenApple; + + public Target(Apple apple, GoldenDelicious goldenApple) { + this.apple = apple; + this.goldenApple = goldenApple; + } + + public Apple getApple() { + return apple; + } + + public void setApple(Apple apple) { + this.apple = apple; + } + + public GoldenDelicious getGoldenApple() { + return goldenApple; + } + + public void setGoldenApple(GoldenDelicious goldenApple) { + this.goldenApple = goldenApple; + } + } +} From 3a325ea66bdd07741d1bda43d3c77c2709464ea7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 3 Oct 2022 21:12:19 +0200 Subject: [PATCH 0727/1006] #3036 Fix compile errors when intersection types are used in lifecycle methods --- ...eatureCompilationExclusionCliEnhancer.java | 4 + .../test/resources/fullFeatureTest/pom.xml | 1 + .../ap/internal/model/common/Type.java | 29 ++++++ .../internal/model/source/MethodMatcher.java | 3 +- .../LifecycleIntersectionMapper.java | 96 +++++++++++++++++++ .../wildcards/WildCardTest.java | 20 ++++ 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index e017d1b003..e64b207990 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -32,6 +32,10 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/annotatewith/deprecated/jdk11/*.java" ); + if ( processorType == ProcessorTest.ProcessorType.ECLIPSE_JDT ) { + additionalExcludes.add( + "org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java" ); + } break; case JAVA_9: // TODO find out why this fails: diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 8a62f48588..9c17f6c7d5 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -26,6 +26,7 @@ x x x + x diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index fd7f3d6904..6d86aad452 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -28,6 +28,7 @@ import javax.lang.model.element.VariableElement; import javax.lang.model.type.ArrayType; import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.IntersectionType; import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; @@ -114,6 +115,7 @@ public class Type extends ModelElement implements Comparable { private List alternativeTargetAccessors = null; private Type boundingBase = null; + private List boundTypes = null; private Type boxedEquivalent = null; @@ -354,6 +356,10 @@ public boolean isTypeVar() { return (typeMirror.getKind() == TypeKind.TYPEVAR); } + public boolean isIntersection() { + return typeMirror.getKind() == TypeKind.INTERSECTION; + } + public boolean isJavaLangType() { return packageName != null && packageName.startsWith( "java." ); } @@ -1264,6 +1270,29 @@ public Type getTypeBound() { return boundingBase; } + public List getTypeBounds() { + if ( this.boundTypes != null ) { + return boundTypes; + } + Type bound = getTypeBound(); + if ( bound == null ) { + this.boundTypes = Collections.emptyList(); + } + else if ( !bound.isIntersection() ) { + this.boundTypes = Collections.singletonList( bound ); + } + else { + List bounds = ( (IntersectionType) bound.typeMirror ).getBounds(); + this.boundTypes = new ArrayList<>( bounds.size() ); + for ( TypeMirror mirror : bounds ) { + boundTypes.add( typeFactory.getType( mirror ) ); + } + } + + return this.boundTypes; + + } + public boolean hasAccessibleConstructor() { if ( hasAccessibleConstructor == null ) { hasAccessibleConstructor = false; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 42c26f09a0..3d8bfea135 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -325,8 +325,7 @@ else if ( resolved.getParameter().isWildCardBoundByTypeVar() */ private boolean candidatesWithinBounds(Map methodParCandidates ) { for ( Map.Entry entry : methodParCandidates.entrySet() ) { - Type bound = entry.getKey().getTypeBound(); - if ( bound != null ) { + for ( Type bound : entry.getKey().getTypeBounds() ) { for ( Type.ResolvedPair pair : entry.getValue().pairs ) { if ( entry.getKey().hasUpperBound() ) { if ( !pair.getMatch().asRawType().isAssignableTo( bound.asRawType() ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java new file mode 100644 index 0000000000..c466ee0d91 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java @@ -0,0 +1,96 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.selection.methodgenerics.wildcards; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface LifecycleIntersectionMapper { + + LifecycleIntersectionMapper INSTANCE = Mappers.getMapper( LifecycleIntersectionMapper.class ); + + @Mapping(target = "realm", ignore = true) + RealmTarget mapRealm(String source); + + @Mapping(target = "uniqueRealm", ignore = true) + UniqueRealmTarget mapUniqueRealm(String source); + + @Mapping(target = "realm", ignore = true) + @Mapping(target = "uniqueRealm", ignore = true) + BothRealmsTarget mapBothRealms(String source); + + @AfterMapping + default void afterMapping(String source, @MappingTarget T target) { + target.setRealm( "realm_" + source ); + target.setUniqueRealm( "uniqueRealm_" + source ); + } + + interface RealmObject { + void setRealm(String realm); + } + + interface UniqueRealmObject { + void setUniqueRealm(String realm); + } + + class RealmTarget implements RealmObject { + + protected String realm; + + public String getRealm() { + return realm; + } + + @Override + public void setRealm(String realm) { + this.realm = realm; + } + } + + class UniqueRealmTarget implements UniqueRealmObject { + protected String uniqueRealm; + + @Override + public void setUniqueRealm(String uniqueRealm) { + this.uniqueRealm = uniqueRealm; + } + + public String getUniqueRealm() { + return uniqueRealm; + } + } + + class BothRealmsTarget implements RealmObject, UniqueRealmObject { + + protected String realm; + protected String uniqueRealm; + + public String getRealm() { + return realm; + } + + @Override + public void setRealm(String realm) { + this.realm = realm; + } + + public String getUniqueRealm() { + return uniqueRealm; + } + + @Override + public void setUniqueRealm(String uniqueRealm) { + this.uniqueRealm = uniqueRealm; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java index a228304c72..9e27129635 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/wildcards/WildCardTest.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.selection.methodgenerics.wildcards; +import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.runner.Compiler; @@ -54,4 +55,23 @@ public void testIntersectionRelation() { assertThat( target ).isNotNull(); assertThat( target.getProp() ).isEqualTo( typeC ); } + + // Eclipse does not handle intersection types correctly (TODO: worthwhile to investigate?) + @ProcessorTest(Compiler.JDK) + @WithClasses(LifecycleIntersectionMapper.class) + @IssueKey("3036") + public void testLifecycleIntersection() { + + LifecycleIntersectionMapper.RealmTarget realmTarget = LifecycleIntersectionMapper.INSTANCE.mapRealm( "test" ); + assertThat( realmTarget.getRealm() ).isNull(); + + LifecycleIntersectionMapper.UniqueRealmTarget uniqueRealmTarget = + LifecycleIntersectionMapper.INSTANCE.mapUniqueRealm( "test" ); + assertThat( uniqueRealmTarget.getUniqueRealm() ).isNull(); + + LifecycleIntersectionMapper.BothRealmsTarget bothRealmsTarget = + LifecycleIntersectionMapper.INSTANCE.mapBothRealms( "test" ); + assertThat( bothRealmsTarget.getRealm() ).isEqualTo( "realm_test" ); + assertThat( bothRealmsTarget.getUniqueRealm() ).isEqualTo( "uniqueRealm_test" ); + } } From 481ab36ca35f53a6160bac179c495d6a1774388e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 3 Oct 2022 21:16:25 +0200 Subject: [PATCH 0728/1006] #3036 Add missing exclude to full feature test --- integrationtest/src/test/resources/fullFeatureTest/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 9c17f6c7d5..1a31b28221 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -48,6 +48,7 @@ ${additionalExclude3} ${additionalExclude4} ${additionalExclude5} + ${additionalExclude6} From a5d3542c24419ff2a66132f3ce2bae12182e3ac0 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 7 Oct 2022 20:43:15 +0200 Subject: [PATCH 0729/1006] Update latest release version to 1.5.3.Final --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index e1ee8f9deb..58d1c515bb 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.2.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.3.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.5.2.Final + 1.5.3.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - implementation 'org.mapstruct:mapstruct:1.5.2.Final' + implementation 'org.mapstruct:mapstruct:1.5.3.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' // if you are using mapstruct in test code } ... ``` From 81b2f70dac328d96d788d7746a57fbeb3978e543 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Oct 2022 19:36:20 +0200 Subject: [PATCH 0730/1006] #3039 Upgrade FreeMarker to 2.3.31 --- distribution/pom.xml | 2 +- distribution/src/main/assembly/dist.xml | 6 +----- parent/pom.xml | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index 11fb7c9f37..be82f52b3c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -66,7 +66,7 @@ org.freemarker freemarker ${project.build.directory}/freemarker-unpacked - META-INF/LICENSE.txt,META-INF/NOTICE.txt + META-INF/LICENSE diff --git a/distribution/src/main/assembly/dist.xml b/distribution/src/main/assembly/dist.xml index f519e5fc9c..f0c727f8da 100644 --- a/distribution/src/main/assembly/dist.xml +++ b/distribution/src/main/assembly/dist.xml @@ -42,11 +42,7 @@ / - target/freemarker-unpacked/META-INF/NOTICE.txt - / - - - target/freemarker-unpacked/META-INF/LICENSE.txt + target/freemarker-unpacked/META-INF/LICENSE etc/freemarker diff --git a/parent/pom.xml b/parent/pom.xml index 3f536034c7..e87db14551 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -109,7 +109,7 @@ org.freemarker freemarker - 2.3.21 + 2.3.31 org.assertj From bb099a55ee3c1b9ae7fc2fbad6c6f9c8fe3ae911 Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Fri, 4 Nov 2022 05:02:58 +0800 Subject: [PATCH 0731/1006] #3040: Allow using only `BeanMapping#mappingControl` --- .../mapstruct/ap/internal/model/source/BeanMappingOptions.java | 1 + .../ap/test/subclassmapping/DeepCloneMethodMapper.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index b73b4084fd..90ad0aabb4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -92,6 +92,7 @@ public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, Mappe private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method, FormattingMessager messager) { if ( !gem.resultType().hasValue() + && !gem.mappingControl().hasValue() && !gem.qualifiedBy().hasValue() && !gem.qualifiedByName().hasValue() && !gem.ignoreUnmappedSourceProperties().hasValue() diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java index 3f276b24cd..036b98a318 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/DeepCloneMethodMapper.java @@ -7,7 +7,6 @@ import org.mapstruct.BeanMapping; import org.mapstruct.Mapper; -import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.SubclassMapping; import org.mapstruct.ap.test.subclassmapping.mappables.Bike; import org.mapstruct.ap.test.subclassmapping.mappables.Car; @@ -21,6 +20,6 @@ public interface DeepCloneMethodMapper { @SubclassMapping( source = Car.class, target = Car.class ) @SubclassMapping( source = Bike.class, target = Bike.class ) - @BeanMapping( mappingControl = DeepClone.class, nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL ) + @BeanMapping( mappingControl = DeepClone.class ) Vehicle map(Vehicle vehicle); } From 6a394ad466b5bda8b17e2406b56be34be3312e21 Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Fri, 4 Nov 2022 06:21:43 +0800 Subject: [PATCH 0732/1006] #3037 Support `@ValueMapping` in meta annotations --- .../main/java/org/mapstruct/ValueMapping.java | 2 +- .../java/org/mapstruct/ValueMappings.java | 2 +- .../chapter-8-mapping-values.asciidoc | 39 +++++++++++++++ .../model/source/ValueMappingOptions.java | 4 +- .../processor/MethodRetrievalProcessor.java | 39 ++++++++++----- .../composition/CustomValueAnnotation.java | 21 ++++++++ .../composition/ValueCompositionTest.java | 48 +++++++++++++++++++ .../ValueMappingCompositionMapper.java | 25 ++++++++++ 8 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/composition/CustomValueAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueCompositionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueMappingCompositionMapper.java diff --git a/core/src/main/java/org/mapstruct/ValueMapping.java b/core/src/main/java/org/mapstruct/ValueMapping.java index 21ea5f4a83..7ad3726e48 100644 --- a/core/src/main/java/org/mapstruct/ValueMapping.java +++ b/core/src/main/java/org/mapstruct/ValueMapping.java @@ -84,7 +84,7 @@ */ @Repeatable(ValueMappings.class) @Retention(RetentionPolicy.CLASS) -@Target(ElementType.METHOD) +@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) public @interface ValueMapping { /** * The source value constant to use for this mapping. diff --git a/core/src/main/java/org/mapstruct/ValueMappings.java b/core/src/main/java/org/mapstruct/ValueMappings.java index faefbf7105..bb593f53d1 100644 --- a/core/src/main/java/org/mapstruct/ValueMappings.java +++ b/core/src/main/java/org/mapstruct/ValueMappings.java @@ -40,7 +40,7 @@ * * @author Sjaak Derksen */ -@Target(ElementType.METHOD) +@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.CLASS) public @interface ValueMappings { diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index 24c7324f1d..ce16b33ecd 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -266,3 +266,42 @@ MapStruct provides the following out of the box enum name transformation strateg It is also possible to register custom strategies. For more information on how to do that have a look at <> + +[[value-mapping-composition]] +=== ValueMapping Composition + +The `@ValueMapping` annotation supports now `@Target` with `ElementType#ANNOTATION_TYPE` in addition to `ElementType#METHOD`. +This allows `@ValueMapping` to be used on other (user defined) annotations for re-use purposes. +For example: + +.Custom value mapping annotations +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Retention( RetentionPolicy.CLASS ) +@ValueMapping(source = "EXTRA", target = "SPECIAL") +@ValueMapping(source = MappingConstants.ANY_REMAINING, target = "DEFAULT") +public @interface CustomValueAnnotation { +} +---- +==== +It can be used to describe some common value mapping relationships to avoid duplicate declarations, as in the following example: + +.Using custom combination annotations +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface ValueMappingCompositionMapper { + + @CustomValueAnnotation + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); + + @CustomValueAnnotation + @ValueMapping(source = "STANDARD", target = "SPECIAL") + ExternalOrderType duplicateAnnotation(OrderType orderType); +} +---- +==== diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java index 963683b5c5..9c412733c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ValueMappingOptions.java @@ -5,8 +5,8 @@ */ package org.mapstruct.ap.internal.model.source; -import java.util.List; import java.util.Objects; +import java.util.Set; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.ExecutableElement; @@ -34,7 +34,7 @@ public class ValueMappingOptions { private final AnnotationValue targetAnnotationValue; public static void fromMappingsGem(ValueMappingsGem mappingsGem, ExecutableElement method, - FormattingMessager messager, List mappings) { + FormattingMessager messager, Set mappings) { boolean anyFound = false; for ( ValueMappingGem mappingGem : mappingsGem.value().get() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index bda33b6a92..4ad531d334 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -69,7 +69,8 @@ public class MethodRetrievalProcessor implements ModelElementProcessor getValueMappings(ExecutableElement method) { - List valueMappings = new ArrayList<>(); + Set processedAnnotations = new RepeatValueMappings().getProcessedAnnotations( method ); + return new ArrayList<>(processedAnnotations); + } - ValueMappingGem mappingAnnotation = ValueMappingGem.instanceOn( method ); - ValueMappingsGem mappingsAnnotation = ValueMappingsGem.instanceOn( method ); + private class RepeatValueMappings + extends RepeatableAnnotations { - if ( mappingAnnotation != null ) { - ValueMappingOptions valueMapping = ValueMappingOptions.fromMappingGem( mappingAnnotation ); - if ( valueMapping != null ) { - valueMappings.add( valueMapping ); - } + protected RepeatValueMappings() { + super( elementUtils, VALUE_MAPPING_FQN, VALUE_MAPPINGS_FQN ); + } + + @Override + protected ValueMappingGem singularInstanceOn(Element element) { + return ValueMappingGem.instanceOn( element ); } - if ( mappingsAnnotation != null ) { - ValueMappingOptions.fromMappingsGem( mappingsAnnotation, method, messager, valueMappings ); + @Override + protected ValueMappingsGem multipleInstanceOn(Element element) { + return ValueMappingsGem.instanceOn( element ); + } + + @Override + protected void addInstance(ValueMappingGem gem, Element source, Set mappings) { + ValueMappingOptions valueMappingOptions = ValueMappingOptions.fromMappingGem( gem ); + mappings.add( valueMappingOptions ); } - return valueMappings; + @Override + protected void addInstances(ValueMappingsGem gems, Element source, Set mappings) { + ValueMappingOptions.fromMappingsGem( gems, (ExecutableElement) source, messager, mappings ); + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/composition/CustomValueAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/value/composition/CustomValueAnnotation.java new file mode 100644 index 0000000000..f9a7500a35 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/composition/CustomValueAnnotation.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.composition; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; + +/** + * @author orange add + */ +@Retention( RetentionPolicy.CLASS ) +@ValueMapping(source = "EXTRA", target = "SPECIAL") +@ValueMapping(source = MappingConstants.ANY_REMAINING, target = "DEFAULT") +public @interface CustomValueAnnotation { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueCompositionTest.java b/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueCompositionTest.java new file mode 100644 index 0000000000..d6d8ce0bed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueCompositionTest.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.composition; + +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; +/** + * @author orange add + */ +@IssueKey("3037") +@WithClasses({ + ValueMappingCompositionMapper.class, + ExternalOrderType.class, + OrderType.class, + CustomValueAnnotation.class +}) +public class ValueCompositionTest { + + @ProcessorTest + public void shouldValueCompositionSuccess() { + ValueMappingCompositionMapper compositionMapper = Mappers.getMapper( ValueMappingCompositionMapper.class ); + assertThat( compositionMapper.orderTypeToExternalOrderType( OrderType.EXTRA ) ) + .isEqualTo( ExternalOrderType.SPECIAL ); + assertThat( compositionMapper.orderTypeToExternalOrderType( OrderType.NORMAL ) ) + .isEqualTo( ExternalOrderType.DEFAULT ); + } + + @ProcessorTest + public void duplicateValueMappingAnnotation() { + ValueMappingCompositionMapper compositionMapper = Mappers.getMapper( ValueMappingCompositionMapper.class ); + assertThat( compositionMapper.duplicateAnnotation( OrderType.EXTRA ) ) + .isEqualTo( ExternalOrderType.SPECIAL ); + assertThat( compositionMapper.duplicateAnnotation( OrderType.STANDARD ) ) + .isEqualTo( ExternalOrderType.SPECIAL ); + assertThat( compositionMapper.duplicateAnnotation( OrderType.NORMAL ) ) + .isEqualTo( ExternalOrderType.DEFAULT ); + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueMappingCompositionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueMappingCompositionMapper.java new file mode 100644 index 0000000000..c3e0e64d69 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/value/composition/ValueMappingCompositionMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.value.composition; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ap.test.value.ExternalOrderType; +import org.mapstruct.ap.test.value.OrderType; + +/** + * @author orange add + */ +@Mapper +public interface ValueMappingCompositionMapper { + + @CustomValueAnnotation + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); + + @CustomValueAnnotation + @ValueMapping(source = "STANDARD", target = "SPECIAL") + ExternalOrderType duplicateAnnotation(OrderType orderType); +} From 93f7c3b8eadef4ad37b35ae1bb4e6ac41b09a781 Mon Sep 17 00:00:00 2001 From: Orange Add <48479242+chenzijia12300@users.noreply.github.com> Date: Fri, 4 Nov 2022 06:22:35 +0800 Subject: [PATCH 0733/1006] #3015 Fix annotations to the forged methods --- .../model/AbstractMappingMethodBuilder.java | 4 + .../ap/internal/model/ValueMappingMethod.java | 20 ++- .../ap/test/bugs/_3015/Issue3015Mapper.java | 153 ++++++++++++++++++ .../ap/test/bugs/_3015/Issue3015Test.java | 38 +++++ 4 files changed, 209 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 6efb67ba9c..c23dd50430 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -14,6 +14,7 @@ import org.mapstruct.ap.internal.util.Strings; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -121,6 +122,9 @@ public ForgedMethodHistory getDescription() { } public List getMethodAnnotations() { + if ( method instanceof ForgedMethod ) { + return Collections.emptyList(); + } AdditionalAnnotationsBuilder additionalAnnotationsBuilder = new AdditionalAnnotationsBuilder( ctx.getElementUtils(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index f61e80c2d4..6b33faa464 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -117,13 +118,20 @@ else if ( sourceType.isString() && targetType.isEnumType() ) { LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables ); List afterMappingMethods = LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables ); - AdditionalAnnotationsBuilder additionalAnnotationsBuilder = + List annotations; + if ( method instanceof ForgedMethod ) { + annotations = Collections.emptyList(); + } + else { + annotations = new ArrayList<>(); + AdditionalAnnotationsBuilder additionalAnnotationsBuilder = new AdditionalAnnotationsBuilder( - ctx.getElementUtils(), - ctx.getTypeFactory(), - ctx.getMessager() ); - List annotations = new ArrayList<>(); - annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); + ctx.getElementUtils(), + ctx.getTypeFactory(), + ctx.getMessager() ); + + annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); + } // finally return a mapping return new ValueMappingMethod( method, annotations, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Mapper.java new file mode 100644 index 0000000000..1683db8f39 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Mapper.java @@ -0,0 +1,153 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3015; + +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; + +/** + * @author orange add + */ +@Mapper +public interface Issue3015Mapper { + + @AnnotateWith( CustomMethodOnlyAnnotation.class ) + Target map(Source source); + + class Source { + + private NestedSource nested; + private List list; + private Stream stream; + private AnnotateSourceEnum annotateWithEnum; + private Map map; + + public NestedSource getNested() { + return nested; + } + + public void setNested(NestedSource nested) { + this.nested = nested; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public Stream getStream() { + return stream; + } + + public void setStream(Stream stream) { + this.stream = stream; + } + + public AnnotateSourceEnum getAnnotateWithEnum() { + return annotateWithEnum; + } + + public void setAnnotateWithEnum(AnnotateSourceEnum annotateWithEnum) { + this.annotateWithEnum = annotateWithEnum; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + } + + class Target { + private NestedTarget nested; + private List list; + private Stream stream; + private AnnotateTargetEnum annotateWithEnum; + private Map map; + + public NestedTarget getNested() { + return nested; + } + + public void setNested(NestedTarget nested) { + this.nested = nested; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + + public Stream getStream() { + return stream; + } + + public void setStream(Stream stream) { + this.stream = stream; + } + + public AnnotateTargetEnum getAnnotateWithEnum() { + return annotateWithEnum; + } + + public void setAnnotateWithEnum(AnnotateTargetEnum annotateWithEnum) { + this.annotateWithEnum = annotateWithEnum; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + } + + enum AnnotateSourceEnum { + EXISTING; + } + + enum AnnotateTargetEnum { + EXISTING; + } + + class NestedSource { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class NestedTarget { + private Integer value; + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Test.java new file mode 100644 index 0000000000..96004b8c2d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3015/Issue3015Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3015; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author orange add + */ +@WithClasses({ + Issue3015Mapper.class, + CustomMethodOnlyAnnotation.class +}) +class Issue3015Test { + + @ProcessorTest + void noNeedPassAnnotationToForgeMethod() { + Issue3015Mapper mapper = Mappers.getMapper( Issue3015Mapper.class ); + Method[] declaredMethods = mapper.getClass().getDeclaredMethods(); + List annotationMethods = Arrays.stream( declaredMethods ) + .filter( method -> method.getAnnotation( CustomMethodOnlyAnnotation.class ) != null ) + .collect( Collectors.toList() ); + assertThat( annotationMethods ).hasSize( 1 ); + } +} From 16e3ceadec76ad4f3657e8af2f99172241b8dfd3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 3 Nov 2022 23:29:47 +0100 Subject: [PATCH 0734/1006] #2952 Do not treat a getter as an alternative write accessor when using `CollectionMappingStrategy#TARGET_IMMUTABLE` --- .../mapstruct/CollectionMappingStrategy.java | 48 ++++++++++++++ .../ap/internal/model/common/Type.java | 7 +++ .../ap/test/bugs/_2952/Issue2952Mapper.java | 62 +++++++++++++++++++ .../ap/test/bugs/_2952/Issue2952Test.java | 29 +++++++++ .../CupboardEntityOnlyGetter.java | 3 +- ...apper.java => CupboardNoSetterMapper.java} | 4 +- .../immutabletarget/ImmutableProductTest.java | 23 +++---- 7 files changed, 159 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Test.java rename processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/{ErroneousCupboardMapper.java => CupboardNoSetterMapper.java} (80%) diff --git a/core/src/main/java/org/mapstruct/CollectionMappingStrategy.java b/core/src/main/java/org/mapstruct/CollectionMappingStrategy.java index afaba97370..0ea3ee7df5 100644 --- a/core/src/main/java/org/mapstruct/CollectionMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/CollectionMappingStrategy.java @@ -7,6 +7,54 @@ /** * Strategy for propagating the value of collection-typed properties from source to target. + *

        + * In the table below, the dash {@code -} indicates a property name. + * Next, the trailing {@code s} indicates the plural form. + * The table explains the options and how they are applied to the presence / absence of a + * {@code set-s}, {@code add-} and / or {@code get-s} method on the target object. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
        Collection mapping strategy options
        OptionOnly target set-s AvailableOnly target add- AvailableBoth set-s/add- AvailableNo set-s/add- AvailableExisting Target ({@code @TargetType})
        {@link #ACCESSOR_ONLY}set-sget-sset-sget-sget-s
        {@link #SETTER_PREFERRED}set-sadd-set-sget-sget-s
        {@link #ADDER_PREFERRED}set-sadd-add-get-sget-s
        {@link #TARGET_IMMUTABLE}set-sexceptionset-sexceptionset-s
        * * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6d86aad452..6894906266 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -788,6 +788,13 @@ else if ( candidate.getAccessorType() == AccessorType.GETTER ) { // an adder has been found (according strategy) so overrule current choice. candidate = adderMethod; } + + if ( cmStrategy == CollectionMappingStrategyGem.TARGET_IMMUTABLE + && candidate.getAccessorType() == AccessorType.GETTER ) { + // If the collection mapping strategy is target immutable + // then the getter method cannot be used as a setter + continue; + } } else if ( candidate.getAccessorType() == AccessorType.FIELD && ( Executables.isFinal( candidate ) || result.containsKey( targetPropertyName ) ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Mapper.java new file mode 100644 index 0000000000..885d74448f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Mapper.java @@ -0,0 +1,62 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2952; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE) +public interface Issue2952Mapper { + + Issue2952Mapper INSTANCE = Mappers.getMapper( Issue2952Mapper.class ); + + Target map(Source source); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + private final Map attributes = new HashMap<>(); + private final List values = new ArrayList<>(); + private String value; + + public Map getAttributes() { + return Collections.unmodifiableMap( attributes ); + } + + public List getValues() { + return Collections.unmodifiableList( values ); + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Test.java new file mode 100644 index 0000000000..7a517ec979 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2952/Issue2952Test.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2952; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("2952") +@WithClasses({ + Issue2952Mapper.class +}) +class Issue2952Test { + + @ProcessorTest + void shouldCorrectIgnoreImmutableIterable() { + Issue2952Mapper.Target target = Issue2952Mapper.INSTANCE.map( new Issue2952Mapper.Source( "test" ) ); + + assertThat( target.getValue() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java index bbf3a6d24e..1f2f2f00b7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardEntityOnlyGetter.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.collection.immutabletarget; +import java.util.ArrayList; import java.util.List; /** @@ -13,7 +14,7 @@ */ public class CupboardEntityOnlyGetter { - private List content; + private List content = new ArrayList<>(); public List getContent() { return content; diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardNoSetterMapper.java similarity index 80% rename from processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardNoSetterMapper.java index 028ac4d765..a6674e629f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ErroneousCupboardMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/CupboardNoSetterMapper.java @@ -15,9 +15,9 @@ * @author Sjaak Derksen */ @Mapper( collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE ) -public interface ErroneousCupboardMapper { +public interface CupboardNoSetterMapper { - ErroneousCupboardMapper INSTANCE = Mappers.getMapper( ErroneousCupboardMapper.class ); + CupboardNoSetterMapper INSTANCE = Mappers.getMapper( CupboardNoSetterMapper.class ); void map( CupboardDto in, @MappingTarget CupboardEntityOnlyGetter out ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index b3d2096bc3..de22436296 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -11,9 +11,6 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; -import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; -import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; -import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import static org.assertj.core.api.Assertions.assertThat; @@ -41,19 +38,17 @@ public void shouldHandleImmutableTarget() { @ProcessorTest @WithClasses({ - ErroneousCupboardMapper.class, + CupboardNoSetterMapper.class, CupboardEntityOnlyGetter.class }) - @ExpectedCompilationOutcome( - value = CompilationResult.FAILED, - diagnostics = { - @Diagnostic(type = ErroneousCupboardMapper.class, - kind = javax.tools.Diagnostic.Kind.ERROR, - line = 22, - message = "No write accessor found for property \"content\" in target type.") - } - ) - public void testShouldFailOnPropertyMappingNoPropertySetterOnlyGetter() { + public void shouldIgnoreImmutableTarget() { + CupboardDto in = new CupboardDto(); + in.setContent( Arrays.asList( "flour", "peas" ) ); + CupboardEntityOnlyGetter out = new CupboardEntityOnlyGetter(); + out.getContent().add( "bread" ); + CupboardNoSetterMapper.INSTANCE.map( in, out ); + + assertThat( out.getContent() ).containsExactly( "bread" ); } } From 8894cd5935f238ae32338f49cd4595e4562f87f2 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Fri, 4 Nov 2022 14:21:05 +0100 Subject: [PATCH 0735/1006] #3057: limit do not allow self to subclassmappings. (#3063) * #3057: limit do not allow self to subclassmappings. * #3057: determine method candidates after all other fields are set in the constructor. Co-authored-by: Ben Zegveld Co-authored-by: Filip Hrisafov --- .../ap/internal/model/BeanMappingMethod.java | 6 +- .../source/selector/SelectionCriteria.java | 10 ++++ .../creation/MappingResolverImpl.java | 8 ++- .../ap/test/bugs/_3057/Issue3057Mapper.java | 55 +++++++++++++++++++ .../test/bugs/_3057/Issue3057MapperTest.java | 34 ++++++++++++ 5 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057MapperTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 24e160b9de..0ea4ecd197 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -399,15 +399,13 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap "SubclassMapping for " + sourceType.getFullyQualifiedName() ); SelectionCriteria criteria = SelectionCriteria - .forMappingMethods( + .forSubclassMappingMethods( new SelectionParameters( Collections.emptyList(), Collections.emptyList(), subclassMappingOptions.getTarget(), ctx.getTypeUtils() ).withSourceRHS( rightHandSide ), - subclassMappingOptions.getMappingControl( ctx.getElementUtils() ), - null, - false ); + subclassMappingOptions.getMappingControl( ctx.getElementUtils() ) ); Assignment assignment = ctx .getMappingResolver() .getTargetAssignment( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 7e12bbd188..2d288dd56e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -149,6 +149,10 @@ public boolean isAllow2Steps() { return allow2Steps; } + public boolean isSelfAllowed() { + return type != Type.SELF_NOT_ALLOWED; + } + public static SelectionCriteria forMappingMethods(SelectionParameters selectionParameters, MappingControl mappingControl, String targetPropertyName, boolean preferUpdateMapping) { @@ -173,10 +177,16 @@ public static SelectionCriteria forPresenceCheckMethods(SelectionParameters sele return new SelectionCriteria( selectionParameters, null, null, Type.PRESENCE_CHECK ); } + public static SelectionCriteria forSubclassMappingMethods(SelectionParameters selectionParameters, + MappingControl mappingControl) { + return new SelectionCriteria( selectionParameters, mappingControl, null, Type.SELF_NOT_ALLOWED ); + } + public enum Type { PREFER_UPDATE_MAPPING, OBJECT_FACTORY, LIFECYCLE_CALLBACK, PRESENCE_CHECK, + SELF_NOT_ALLOWED, } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 5a2af176f6..12b345d238 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -196,7 +196,6 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM this.mappingMethod = mappingMethod; this.description = description; - this.methods = filterPossibleCandidateMethods( sourceModel, mappingMethod ); this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; @@ -207,13 +206,14 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM this.builtIns = builtIns; this.messager = messager; this.reportingLimitAmbiguous = verboseLogging ? Integer.MAX_VALUE : LIMIT_REPORTING_AMBIGUOUS; + this.methods = filterPossibleCandidateMethods( sourceModel, mappingMethod ); } // CHECKSTYLE:ON private List filterPossibleCandidateMethods(List candidateMethods, T mappingMethod) { List result = new ArrayList<>( candidateMethods.size() ); for ( T candidate : candidateMethods ) { - if ( isCandidateForMapping( candidate ) && !candidate.equals( mappingMethod )) { + if ( isCandidateForMapping( candidate ) && isNotSelfOrSelfAllowed( mappingMethod, candidate )) { result.add( candidate ); } } @@ -221,6 +221,10 @@ private List filterPossibleCandidateMethods(List candid return result; } + private boolean isNotSelfOrSelfAllowed(T mappingMethod, T candidate) { + return selectionCriteria == null || selectionCriteria.isSelfAllowed() || !candidate.equals( mappingMethod ); + } + private Assignment getTargetAssignment(Type sourceType, Type targetType) { Assignment assignment; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057Mapper.java new file mode 100644 index 0000000000..d8c444d8c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057Mapper.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3057; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@Mapper +public interface Issue3057Mapper { + + Issue3057Mapper INSTANCE = Mappers.getMapper( Issue3057Mapper.class ); + + class Source { + private Source self; + + public Source getSelf() { + return self; + } + + public void setSelf(Source self) { + this.self = self; + } + } + + class Target { + private Target self; + private String value; + + public Target getSelf() { + return self; + } + + public void setSelf(Target self) { + this.self = self; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + @Mapping( target = "value", constant = "constantValue" ) + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057MapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057MapperTest.java new file mode 100644 index 0000000000..7e64f529f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3057/Issue3057MapperTest.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3057; + +import org.mapstruct.ap.test.bugs._3057.Issue3057Mapper.Source; +import org.mapstruct.ap.test.bugs._3057.Issue3057Mapper.Target; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Ben Zegveld + */ +@WithClasses(Issue3057Mapper.class) +@IssueKey("3057") +class Issue3057MapperTest { + + @ProcessorTest + void mapsSelf() { + Source sourceOuter = new Issue3057Mapper.Source(); + Source sourceInner = new Issue3057Mapper.Source(); + sourceOuter.setSelf( sourceInner ); + + Target targetOuter = Issue3057Mapper.INSTANCE.map( sourceOuter ); + + assertThat( targetOuter.getValue() ).isEqualTo( "constantValue" ); + assertThat( targetOuter.getSelf().getValue() ).isEqualTo( "constantValue" ); + } +} From 82b19b0d8a7addcb137b1d53e9e753fde0957304 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 12 Nov 2022 10:04:03 +0100 Subject: [PATCH 0736/1006] #3077 Add test case --- .../ap/test/bugs/_3077/Issue3077Mapper.java | 65 +++++++++++++++++++ .../test/bugs/_3077/Issue3077MapperTest.java | 31 +++++++++ 2 files changed, 96 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077MapperTest.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077Mapper.java new file mode 100644 index 0000000000..f1a630a444 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077Mapper.java @@ -0,0 +1,65 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3077; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3077Mapper { + + Issue3077Mapper INSTANCE = Mappers.getMapper( Issue3077Mapper.class ); + + class Source { + private final String source; + private final Source self; + + public Source(String source, Source self) { + this.source = source; + this.self = self; + } + + public String getSource() { + return source; + } + + public Source getSelf() { + return self; + } + } + + class Target { + private String value; + private Target self; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Target getSelf() { + return self; + } + + public void setSelf(Target self) { + this.self = self; + } + + } + + @Named("self") + @Mapping(target = "value", source = "source") + @Mapping(target = "self", qualifiedByName = "self") + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077MapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077MapperTest.java new file mode 100644 index 0000000000..bfba7988aa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3077/Issue3077MapperTest.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3077; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3077Mapper.class) +@IssueKey("3057") +class Issue3077MapperTest { + + @ProcessorTest + void mapsSelf() { + Issue3077Mapper.Source sourceInner = new Issue3077Mapper.Source( "inner", null ); + Issue3077Mapper.Source sourceOuter = new Issue3077Mapper.Source( "outer", sourceInner ); + + Issue3077Mapper.Target targetOuter = Issue3077Mapper.INSTANCE.map( sourceOuter ); + + assertThat( targetOuter.getValue() ).isEqualTo( "outer" ); + assertThat( targetOuter.getSelf().getValue() ).isEqualTo( "inner" ); + } +} From fd27380185fe83feb6d26308c7d358025783ff8f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 13 Nov 2022 14:22:25 +0100 Subject: [PATCH 0737/1006] #2953 Add support for globally defining nullValueMapMappingStrategy and nullValueIterableMappingStrategy --- .../main/asciidoc/chapter-2-set-up.asciidoc | 24 ++++++++++ .../org/mapstruct/ap/MappingProcessor.java | 18 +++++++- .../internal/model/source/DefaultOptions.java | 8 ++++ .../mapstruct/ap/internal/option/Options.java | 20 ++++++++- .../test/nullvaluemapping/CarListMapper.java | 30 +++++++++++++ .../CarListMapperSettingOnMapper.java | 31 +++++++++++++ .../test/nullvaluemapping/CarMapMapper.java | 30 +++++++++++++ .../CarMapMapperSettingOnMapper.java | 31 +++++++++++++ .../NullValueIterableMappingStrategyTest.java | 45 +++++++++++++++++++ .../NullValueMapMappingStrategyTest.java | 45 +++++++++++++++++++ 10 files changed, 279 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapperSettingOnMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapperSettingOnMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueIterableMappingStrategyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMapMappingStrategyTest.java diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 601bc42a99..12c399c1f5 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -266,6 +266,30 @@ If a policy is given for a specific bean mapping via `@BeanMapping#ignoreUnmappe disableBuilders` |If set to `true`, then MapStruct will not use builder patterns when doing the mapping. This is equivalent to doing `@Mapper( builder = @Builder( disableBuilder = true ) )` for all of your mappers. |`false` + +|`mapstruct.nullValueIterableMappingStrategy` +|The strategy to be applied when `null` is passed as a source value to an iterable mapping. + +Supported values are: + +* `RETURN_NULL`: if `null` is passed as a source value, then `null` will be returned +* `RETURN_DEFAULT`: if `null` is passed then a default value (empty collection) will be returned + +If a strategy is given for a specific mapper via `@Mapper#nullValueIterableMappingStrategy()`, the value from the annotation takes precedence. +If a strategy is given for a specific iterable mapping via `@IterableMapping#nullValueMappingStrategy()`, it takes precedence over both `@Mapper#nullValueIterableMappingStrategy()` and the option. +|`RETURN_NULL` + +|`mapstruct.nullValueMapMappingStrategy` +|The strategy to be applied when `null` is passed as a source value to a map mapping. + +Supported values are: + +* `RETURN_NULL`: if `null` is passed as a source value, then `null` will be returned +* `RETURN_DEFAULT`: if `null` is passed then a default value (empty map) will be returned + +If a strategy is given for a specific mapper via `@Mapper#nullValueMapMappingStrategy()`, the value from the annotation takes precedence. +If a strategy is given for a specific map mapping via `@MapMapping#nullValueMappingStrategy()`, it takes precedence over both `@Mapper#nullValueMapMappingStrategy()` and the option. +|`RETURN_NULL` |=== === Using MapStruct with the Java Module System diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 2a4af558f2..8c842f007b 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -12,6 +12,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.ServiceLoader; import java.util.Set; @@ -32,6 +33,7 @@ import javax.lang.model.util.ElementKindVisitor6; import javax.tools.Diagnostic.Kind; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.MapperGem; @@ -87,7 +89,9 @@ MappingProcessor.DEFAULT_COMPONENT_MODEL, MappingProcessor.DEFAULT_INJECTION_STRATEGY, MappingProcessor.DISABLE_BUILDERS, - MappingProcessor.VERBOSE + MappingProcessor.VERBOSE, + MappingProcessor.NULL_VALUE_ITERABLE_MAPPING_STRATEGY, + MappingProcessor.NULL_VALUE_MAP_MAPPING_STRATEGY, }) public class MappingProcessor extends AbstractProcessor { @@ -106,6 +110,8 @@ public class MappingProcessor extends AbstractProcessor { protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; protected static final String DISABLE_BUILDERS = "mapstruct.disableBuilders"; protected static final String VERBOSE = "mapstruct.verbose"; + protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY = "mapstruct.nullValueIterableMappingStrategy"; + protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY = "mapstruct.nullValueMapMappingStrategy"; private Options options; @@ -139,6 +145,9 @@ public synchronized void init(ProcessingEnvironment processingEnv) { private Options createOptions() { String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY ); String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); + String nullValueIterableMappingStrategy = processingEnv.getOptions() + .get( NULL_VALUE_ITERABLE_MAPPING_STRATEGY ); + String nullValueMapMappingStrategy = processingEnv.getOptions().get( NULL_VALUE_MAP_MAPPING_STRATEGY ); return new Options( Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), @@ -149,7 +158,12 @@ private Options createOptions() { processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), Boolean.parseBoolean( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), Boolean.parseBoolean( processingEnv.getOptions().get( DISABLE_BUILDERS ) ), - Boolean.parseBoolean( processingEnv.getOptions().get( VERBOSE ) ) + Boolean.parseBoolean( processingEnv.getOptions().get( VERBOSE ) ), + nullValueIterableMappingStrategy != null ? + NullValueMappingStrategyGem.valueOf( nullValueIterableMappingStrategy.toUpperCase( Locale.ROOT ) ) : + null, + nullValueMapMappingStrategy != null ? + NullValueMappingStrategyGem.valueOf( nullValueMapMappingStrategy.toUpperCase( Locale.ROOT ) ) : null ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index 5c76e7face..c754d3c395 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -132,10 +132,18 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { } public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + NullValueMappingStrategyGem nullValueIterableMappingStrategy = options.getNullValueIterableMappingStrategy(); + if ( nullValueIterableMappingStrategy != null ) { + return nullValueIterableMappingStrategy; + } return NullValueMappingStrategyGem.valueOf( mapper.nullValueIterableMappingStrategy().getDefaultValue() ); } public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + NullValueMappingStrategyGem nullValueMapMappingStrategy = options.getNullValueMapMappingStrategy(); + if ( nullValueMapMappingStrategy != null ) { + return nullValueMapMappingStrategy; + } return NullValueMappingStrategyGem.valueOf( mapper.nullValueMapMappingStrategy().getDefaultValue() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 65089cc139..a544374c0e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.option; +import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; /** @@ -23,14 +24,21 @@ public class Options { private final String defaultInjectionStrategy; private final boolean disableBuilders; private final boolean verbose; + private final NullValueMappingStrategyGem nullValueIterableMappingStrategy; + private final NullValueMappingStrategyGem nullValueMapMappingStrategy; + //CHECKSTYLE:OFF public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, ReportingPolicyGem unmappedTargetPolicy, ReportingPolicyGem unmappedSourcePolicy, String defaultComponentModel, String defaultInjectionStrategy, boolean alwaysGenerateSpi, boolean disableBuilders, - boolean verbose) { + boolean verbose, + NullValueMappingStrategyGem nullValueIterableMappingStrategy, + NullValueMappingStrategyGem nullValueMapMappingStrategy + ) { + //CHECKSTYLE:ON this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; this.unmappedTargetPolicy = unmappedTargetPolicy; @@ -40,6 +48,8 @@ public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVers this.alwaysGenerateSpi = alwaysGenerateSpi; this.disableBuilders = disableBuilders; this.verbose = verbose; + this.nullValueIterableMappingStrategy = nullValueIterableMappingStrategy; + this.nullValueMapMappingStrategy = nullValueMapMappingStrategy; } public boolean isSuppressGeneratorTimestamp() { @@ -77,4 +87,12 @@ public boolean isDisableBuilders() { public boolean isVerbose() { return verbose; } + + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { + return nullValueIterableMappingStrategy; + } + + public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { + return nullValueMapMappingStrategy; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapper.java new file mode 100644 index 0000000000..d239f9ace7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CarListMapper { + + CarListMapper INSTANCE = Mappers.getMapper( CarListMapper.class ); + + @Mapping(target = "seatCount", ignore = true) + @Mapping(target = "model", ignore = true) + @Mapping(target = "catalogId", ignore = true) + CarDto map(Car car); + + List carsToCarDtoList(List cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapperSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapperSettingOnMapper.java new file mode 100644 index 0000000000..860b17654a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarListMapperSettingOnMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValueIterableMappingStrategy = NullValueMappingStrategy.RETURN_NULL) +public interface CarListMapperSettingOnMapper { + + CarListMapperSettingOnMapper INSTANCE = Mappers.getMapper( CarListMapperSettingOnMapper.class ); + + @Mapping(target = "seatCount", ignore = true) + @Mapping(target = "model", ignore = true) + @Mapping(target = "catalogId", ignore = true) + CarDto map(Car car); + + List carsToCarDtoList(List cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapper.java new file mode 100644 index 0000000000..0227949f4d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapper.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CarMapMapper { + + CarMapMapper INSTANCE = Mappers.getMapper( CarMapMapper.class ); + + @Mapping(target = "seatCount", ignore = true) + @Mapping(target = "model", ignore = true) + @Mapping(target = "catalogId", ignore = true) + CarDto map(Car car); + + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapperSettingOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapperSettingOnMapper.java new file mode 100644 index 0000000000..adb99887bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/CarMapMapperSettingOnMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValueMapMappingStrategy = NullValueMappingStrategy.RETURN_NULL) +public interface CarMapMapperSettingOnMapper { + + CarMapMapperSettingOnMapper INSTANCE = Mappers.getMapper( CarMapMapperSettingOnMapper.class ); + + @Mapping(target = "seatCount", ignore = true) + @Mapping(target = "model", ignore = true) + @Mapping(target = "catalogId", ignore = true) + CarDto map(Car car); + + Map carsToCarDtoMap(Map cars); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueIterableMappingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueIterableMappingStrategyTest.java new file mode 100644 index 0000000000..c4acecd64f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueIterableMappingStrategyTest.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CarDto.class, + Car.class +}) +@IssueKey("2953") +public class NullValueIterableMappingStrategyTest { + + @ProcessorTest + @ProcessorOption(name = "mapstruct.nullValueIterableMappingStrategy", value = "return_default") + @WithClasses({ + CarListMapper.class + }) + void globalNullIterableMappingStrategy() { + assertThat( CarListMapper.INSTANCE.carsToCarDtoList( null ) ).isEmpty(); + } + + @ProcessorTest + @ProcessorOption(name = "mapstruct.nullValueIterableMappingStrategy", value = "return_default") + @WithClasses({ + CarListMapperSettingOnMapper.class + }) + void globalNullMapMappingStrategyWithOverrideInMapper() { + // Explicit definition in @Mapper should override global + assertThat( CarListMapperSettingOnMapper.INSTANCE.carsToCarDtoList( null ) ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMapMappingStrategyTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMapMappingStrategyTest.java new file mode 100644 index 0000000000..33b5942f85 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluemapping/NullValueMapMappingStrategyTest.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluemapping; + +import org.mapstruct.ap.test.nullvaluemapping._target.CarDto; +import org.mapstruct.ap.test.nullvaluemapping.source.Car; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CarDto.class, + Car.class +}) +@IssueKey("2953") +public class NullValueMapMappingStrategyTest { + + @ProcessorTest + @ProcessorOption(name = "mapstruct.nullValueMapMappingStrategy", value = "return_default") + @WithClasses({ + CarMapMapper.class + }) + void globalNullMapMappingStrategy() { + assertThat( CarMapMapper.INSTANCE.carsToCarDtoMap( null ) ).isEmpty(); + } + + @ProcessorTest + @ProcessorOption(name = "mapstruct.nullValueMapMappingStrategy", value = "return_default") + @WithClasses({ + CarMapMapperSettingOnMapper.class + }) + void globalNullMapMappingStrategyWithOverrideInMapper() { + // Explicit definition in @Mapper should override global + assertThat( CarMapMapperSettingOnMapper.INSTANCE.carsToCarDtoMap( null ) ).isNull(); + } +} From a7ba12676d237957be0753076f436d7974c9f7f4 Mon Sep 17 00:00:00 2001 From: Claudio Nave Date: Sun, 5 Feb 2023 12:17:02 +0100 Subject: [PATCH 0738/1006] #3110 Fix throws declaration for ValueMapping annotated methods (#3122) #3110 Fix throws declaration for ValueMapping annotated methods --- .../ap/internal/model/ValueMappingMethod.ftl | 10 ++++++- .../ap/test/bugs/_3110/Issue3110Mapper.java | 29 +++++++++++++++++++ .../test/bugs/_3110/Issue3110MapperTest.java | 27 +++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110MapperTest.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 2c3e2b6410..016cfcd182 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -10,7 +10,7 @@ <#nt><@includeModel object=annotation/> <#if overridden>@Override -<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { +<#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> <#if !callback_has_next> @@ -69,3 +69,11 @@ +<#macro throws> + <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> + <#list thrownTypes as exceptionType> + <@includeModel object=exceptionType/> + <#if exceptionType_has_next>, <#t> + + + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110Mapper.java new file mode 100644 index 0000000000..12dd823760 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110Mapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3110; + +import org.mapstruct.EnumMapping; +import org.mapstruct.Mapper; + +@Mapper +public interface Issue3110Mapper { + enum SourceEnum { + FOO, BAR + } + + enum TargetEnum { + FOO, BAR + } + + class CustomCheckedException extends Exception { + public CustomCheckedException(String message) { + super( message ); + } + } + + @EnumMapping(unexpectedValueMappingException = CustomCheckedException.class) + TargetEnum map(SourceEnum sourceEnum) throws CustomCheckedException; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110MapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110MapperTest.java new file mode 100644 index 0000000000..3b256ba100 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3110/Issue3110MapperTest.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3110; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +@WithClasses({ + Issue3110Mapper.class +}) +@IssueKey("3110") +class Issue3110MapperTest { + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void throwsException() { + generatedSource.forMapper( Issue3110Mapper.class ).content() + .contains( "throws CustomCheckedException" ); + } +} From 89db26a1af35fb759a2fa74b8bc7586cb743c454 Mon Sep 17 00:00:00 2001 From: Claudio Nave Date: Fri, 17 Mar 2023 09:06:13 +0100 Subject: [PATCH 0739/1006] #3119 Add qualifiedBy and qualifiedByName to SubclassMapping annotation --- .../main/java/org/mapstruct/Qualifier.java | 1 + .../java/org/mapstruct/SubclassMapping.java | 26 ++ ...apter-10-advanced-mapping-options.asciidoc | 2 + .../ap/internal/model/BeanMappingMethod.java | 20 +- .../model/source/SubclassMappingOptions.java | 33 +- .../subclassmapping/qualifier/Composer.java | 18 ++ .../qualifier/ComposerDto.java | 18 ++ .../ErroneousSubclassQualifiedByMapper.java | 16 + ...rroneousSubclassQualifiedByNameMapper.java | 16 + .../test/subclassmapping/qualifier/Light.java | 19 ++ .../qualifier/NonExistent.java | 19 ++ .../subclassmapping/qualifier/Rossini.java | 20 ++ .../subclassmapping/qualifier/RossiniDto.java | 20 ++ .../qualifier/RossiniMapper.java | 50 +++ .../qualifier/SubclassQualifiedByMapper.java | 37 +++ .../SubclassQualifiedByNameMapper.java | 37 +++ .../SubclassQualifierMapperTest.java | 297 ++++++++++++++++++ .../subclassmapping/qualifier/Unused.java | 19 ++ .../subclassmapping/qualifier/Vivaldi.java | 20 ++ .../subclassmapping/qualifier/VivaldiDto.java | 20 ++ .../qualifier/VivaldiMapper.java | 50 +++ 21 files changed, 740 insertions(+), 18 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Composer.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ComposerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByNameMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Light.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/NonExistent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Rossini.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByNameMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Unused.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Vivaldi.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiMapper.java diff --git a/core/src/main/java/org/mapstruct/Qualifier.java b/core/src/main/java/org/mapstruct/Qualifier.java index be51f49e04..9e18c3e420 100644 --- a/core/src/main/java/org/mapstruct/Qualifier.java +++ b/core/src/main/java/org/mapstruct/Qualifier.java @@ -21,6 +21,7 @@ *

      • {@link IterableMapping#qualifiedBy() }
      • *
      • {@link MapMapping#keyQualifiedBy() }
      • *
      • {@link MapMapping#valueQualifiedBy() }
      • + *
      • {@link SubclassMapping#qualifiedBy() }
      • *
      *

      Example:

      *
      
      diff --git a/core/src/main/java/org/mapstruct/SubclassMapping.java b/core/src/main/java/org/mapstruct/SubclassMapping.java
      index bfd4f9bec5..ccf8d4d472 100644
      --- a/core/src/main/java/org/mapstruct/SubclassMapping.java
      +++ b/core/src/main/java/org/mapstruct/SubclassMapping.java
      @@ -5,6 +5,7 @@
        */
       package org.mapstruct;
       
      +import java.lang.annotation.Annotation;
       import java.lang.annotation.ElementType;
       import java.lang.annotation.Repeatable;
       import java.lang.annotation.Retention;
      @@ -81,4 +82,29 @@
            * @return the target subclass to map the source to.
            */
           Class target();
      +
      +    /**
      +     * A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple
      +     * mapping methods (hand written or generated) qualify and thus would result in an 'Ambiguous mapping methods found'
      +     * error. A qualifier is a custom annotation and can be placed on a hand written mapper class or a method.
      +     *
      +     * @return the qualifiers
      +     * @see Qualifier
      +     */
      +    Class[] qualifiedBy() default {};
      +
      +    /**
      +     * String-based form of qualifiers; When looking for a suitable mapping method for a given property, MapStruct will
      +     * only consider those methods carrying directly or indirectly (i.e. on the class-level) a {@link Named} annotation
      +     * for each of the specified qualifier names.
      +     * 

      + * Note that annotation-based qualifiers are generally preferable as they allow more easily to find references and + * are safe for refactorings, but name-based qualifiers can be a less verbose alternative when requiring a large + * number of qualifiers as no custom annotation types are needed. + * + * @return One or more qualifier name(s) + * @see #qualifiedBy() + * @see Named + */ + String[] qualifiedByName() default {}; } diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index a6e42b6d48..87dffce31c 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -141,6 +141,8 @@ In the case that the `Fruit` is an abstract class or an interface, you would get To allow mappings for abstract classes or interfaces you need to set the `subclassExhaustiveStrategy` to `RUNTIME_EXCEPTION`, you can do this at the `@MapperConfig`, `@Mapper` or `@BeanMapping` annotations. If you then pass a `GrapeDto` an `IllegalArgumentException` will be thrown because it is unknown how to map a `GrapeDto`. Adding the missing (`@SubclassMapping`) for it will fix that. +<> can be used to further control which methods may be chosen to map a specific subclass. For that, you will need to use one of `SubclassMapping#qualifiedByName` or `SubclassMapping#qualifiedBy`. + [TIP] ==== If the mapping method for the subclasses does not exist it will be created and any other annotations on the fruit mapping method will be inherited by the newly generated mappings. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 0ea4ecd197..29d27c8d68 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -399,13 +399,10 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap "SubclassMapping for " + sourceType.getFullyQualifiedName() ); SelectionCriteria criteria = SelectionCriteria - .forSubclassMappingMethods( - new SelectionParameters( - Collections.emptyList(), - Collections.emptyList(), - subclassMappingOptions.getTarget(), - ctx.getTypeUtils() ).withSourceRHS( rightHandSide ), - subclassMappingOptions.getMappingControl( ctx.getElementUtils() ) ); + .forSubclassMappingMethods( + subclassMappingOptions.getSelectionParameters().withSourceRHS( rightHandSide ), + subclassMappingOptions.getMappingControl( ctx.getElementUtils() ) + ); Assignment assignment = ctx .getMappingResolver() .getTargetAssignment( @@ -424,10 +421,13 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap String sourceArgument = null; for ( Parameter parameter : method.getSourceParameters() ) { if ( ctx - .getTypeUtils() - .isAssignable( sourceType.getTypeMirror(), parameter.getType().getTypeMirror() ) ) { + .getTypeUtils() + .isAssignable( sourceType.getTypeMirror(), parameter.getType().getTypeMirror() ) ) { sourceArgument = parameter.getName(); - assignment.setSourceLocalVarName( "(" + sourceType.createReferenceName() + ") " + sourceArgument ); + if ( assignment != null ) { + assignment.setSourceLocalVarName( + "(" + sourceType.createReferenceName() + ") " + sourceArgument ); + } } } return new SubclassMapping( sourceType, sourceArgument, targetType, assignment ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java index 08df8083bc..6ed1117ebd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java @@ -33,12 +33,15 @@ public class SubclassMappingOptions extends DelegatingOptions { private final TypeMirror source; private final TypeMirror target; private final TypeUtils typeUtils; + private final SelectionParameters selectionParameters; - public SubclassMappingOptions(TypeMirror source, TypeMirror target, TypeUtils typeUtils, DelegatingOptions next) { + public SubclassMappingOptions(TypeMirror source, TypeMirror target, TypeUtils typeUtils, DelegatingOptions next, + SelectionParameters selectionParameters) { super( next ); this.source = source; this.target = target; this.typeUtils = typeUtils; + this.selectionParameters = selectionParameters; } @Override @@ -117,6 +120,10 @@ public TypeMirror getTarget() { return target; } + public SelectionParameters getSelectionParameters() { + return selectionParameters; + } + public static void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, TypeUtils typeUtils, Set mappings, @@ -154,6 +161,12 @@ public static void addInstance(SubclassMappingGem subclassMapping, ExecutableEle TypeMirror sourceSubclass = subclassMapping.source().getValue(); TypeMirror targetSubclass = subclassMapping.target().getValue(); + SelectionParameters selectionParameters = new SelectionParameters( + subclassMapping.qualifiedBy().get(), + subclassMapping.qualifiedByName().get(), + targetSubclass, + typeUtils + ); mappings .add( @@ -161,20 +174,24 @@ public static void addInstance(SubclassMappingGem subclassMapping, ExecutableEle sourceSubclass, targetSubclass, typeUtils, - beanMappingOptions ) ); + beanMappingOptions, + selectionParameters + ) ); } public static List copyForInverseInheritance(Set subclassMappings, - BeanMappingOptions beanMappingOptions) { + BeanMappingOptions beanMappingOptions) { // we are not interested in keeping it unique at this point. List mappings = new ArrayList<>(); for ( SubclassMappingOptions subclassMapping : subclassMappings ) { mappings.add( - new SubclassMappingOptions( - subclassMapping.target, - subclassMapping.source, - subclassMapping.typeUtils, - beanMappingOptions ) ); + new SubclassMappingOptions( + subclassMapping.target, + subclassMapping.source, + subclassMapping.typeUtils, + beanMappingOptions, + subclassMapping.selectionParameters + ) ); } return mappings; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Composer.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Composer.java new file mode 100644 index 0000000000..116304ae5d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Composer.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +public class Composer { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ComposerDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ComposerDto.java new file mode 100644 index 0000000000..1f9d27681f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ComposerDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +public class ComposerDto { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java new file mode 100644 index 0000000000..26cdd4715e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; + +@Mapper(uses = { RossiniMapper.class, VivaldiMapper.class }) +public interface ErroneousSubclassQualifiedByMapper { + @SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedBy = NonExistent.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class) + ComposerDto toDto(Composer composer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByNameMapper.java new file mode 100644 index 0000000000..23887baf0f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByNameMapper.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; + +@Mapper(uses = { RossiniMapper.class, VivaldiMapper.class }) +public interface ErroneousSubclassQualifiedByNameMapper { + @SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedByName = "non-existent") + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class) + ComposerDto toDto(Composer composer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Light.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Light.java new file mode 100644 index 0000000000..0a24c561c9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Light.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface Light { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/NonExistent.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/NonExistent.java new file mode 100644 index 0000000000..d1d74f76f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/NonExistent.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface NonExistent { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Rossini.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Rossini.java new file mode 100644 index 0000000000..cfd41847d0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Rossini.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.util.List; + +public class Rossini extends Composer { + private List crescendo; + + public List getCrescendo() { + return crescendo; + } + + public void setCrescendo(List crescendo) { + this.crescendo = crescendo; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniDto.java new file mode 100644 index 0000000000..355de1876e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.util.List; + +public class RossiniDto extends ComposerDto { + private List crescendo; + + public List getCrescendo() { + return crescendo; + } + + public void setCrescendo(List crescendo) { + this.crescendo = crescendo; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniMapper.java new file mode 100644 index 0000000000..c4bb5e2497 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/RossiniMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +@Mapper +public interface RossiniMapper { + RossiniDto toDto(Rossini rossini); + + @Light + @Mapping(target = "crescendo", ignore = true) + RossiniDto toDtoLight(Rossini source); + + @Named("light") + @Mapping(target = "crescendo", ignore = true) + RossiniDto toDtoLightNamed(Rossini source); + + @Unused + @BeanMapping(ignoreByDefault = true) + RossiniDto toDtoUnused(Rossini source); + + @Named("unused") + @BeanMapping(ignoreByDefault = true) + RossiniDto toDtoUnusedNamed(Rossini source); + + Rossini fromDto(RossiniDto rossini); + + @Light + @Mapping(target = "crescendo", ignore = true) + Rossini fromDtoLight(RossiniDto source); + + @Named("light") + @Mapping(target = "crescendo", ignore = true) + Rossini fromDtoLightNamed(RossiniDto source); + + @Unused + @BeanMapping(ignoreByDefault = true) + Rossini fromDtoUnused(RossiniDto source); + + @Named("unused") + @BeanMapping(ignoreByDefault = true) + Rossini fromDtoUnusedNamed(RossiniDto source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByMapper.java new file mode 100644 index 0000000000..7f486804fd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByMapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = { RossiniMapper.class, VivaldiMapper.class }) +public interface SubclassQualifiedByMapper { + SubclassQualifiedByMapper INSTANCE = Mappers.getMapper( SubclassQualifiedByMapper.class ); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class) + ComposerDto toDto(Composer composer); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedBy = Light.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class, qualifiedBy = Light.class) + ComposerDto toDtoLight(Composer composer); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class, qualifiedBy = Light.class) + ComposerDto toDtoLightJustVivaldi(Composer composer); + + @InheritInverseConfiguration(name = "toDto") + Composer fromDto(ComposerDto composer); + + @InheritInverseConfiguration(name = "toDtoLight") + Composer fromDtoLight(ComposerDto composer); + + @InheritInverseConfiguration(name = "toDtoLightJustVivaldi") + Composer fromDtoLightJustVivaldi(ComposerDto composer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByNameMapper.java new file mode 100644 index 0000000000..e4816ef732 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifiedByNameMapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper(uses = { RossiniMapper.class, VivaldiMapper.class }) +public interface SubclassQualifiedByNameMapper { + SubclassQualifiedByNameMapper INSTANCE = Mappers.getMapper( SubclassQualifiedByNameMapper.class ); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class) + ComposerDto toDto(Composer composer); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedByName = "light") + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class, qualifiedByName = "light") + ComposerDto toDtoLight(Composer composer); + + @SubclassMapping(source = Rossini.class, target = RossiniDto.class) + @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class, qualifiedByName = "light") + ComposerDto toDtoLightJustVivaldi(Composer composer); + + @InheritInverseConfiguration(name = "toDto") + Composer fromDto(ComposerDto composer); + + @InheritInverseConfiguration(name = "toDtoLight") + Composer fromDtoLight(ComposerDto composer); + + @InheritInverseConfiguration(name = "toDtoLightJustVivaldi") + Composer fromDtoLightJustVivaldi(ComposerDto composer); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java new file mode 100644 index 0000000000..df67c27013 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java @@ -0,0 +1,297 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Composer.class, + ComposerDto.class, + Rossini.class, + RossiniDto.class, + Vivaldi.class, + VivaldiDto.class, + VivaldiDto.class, + VivaldiDto.class, + Light.class, + Unused.class, + NonExistent.class, + RossiniMapper.class, + VivaldiMapper.class +}) +@IssueKey("3119") +public class SubclassQualifierMapperTest { + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses(SubclassQualifiedByMapper.class) + void subclassQualifiedBy() { + Rossini rossini = buildRossini(); + + Vivaldi vivaldi = buildVivaldi(); + + RossiniDto rossiniDto = (RossiniDto) SubclassQualifiedByMapper.INSTANCE.toDto( rossini ); + RossiniDto rossiniDtoLight = (RossiniDto) SubclassQualifiedByMapper.INSTANCE.toDtoLight( rossini ); + + VivaldiDto vivaldiDto = (VivaldiDto) SubclassQualifiedByMapper.INSTANCE.toDto( vivaldi ); + VivaldiDto vivaldiDtoLight = (VivaldiDto) SubclassQualifiedByMapper.INSTANCE.toDtoLight( vivaldi ); + + assertThat( rossiniDto.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDto.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + assertThat( rossiniDtoLight.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDtoLight.getCrescendo() ).isNull(); + + assertThat( vivaldiDto.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDto.getSeasons() ).containsExactly( "spring", "winter" ); + assertThat( vivaldiDtoLight.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDtoLight.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByMapper.class) + void subclassQualifiedByOnlyOne() { + Rossini rossini = buildRossini(); + + Vivaldi vivaldi = buildVivaldi(); + + RossiniDto rossiniDto = (RossiniDto) SubclassQualifiedByMapper.INSTANCE.toDtoLightJustVivaldi( rossini ); + + VivaldiDto vivaldiDto = (VivaldiDto) SubclassQualifiedByMapper.INSTANCE.toDtoLightJustVivaldi( vivaldi ); + + assertThat( rossiniDto.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDto.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + + assertThat( vivaldiDto.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDto.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByNameMapper.class) + void subclassQualifiedByName() { + Rossini rossini = buildRossini(); + + Vivaldi vivaldi = buildVivaldi(); + + RossiniDto rossiniDto = (RossiniDto) SubclassQualifiedByNameMapper.INSTANCE.toDto( rossini ); + RossiniDto rossiniDtoLight = (RossiniDto) SubclassQualifiedByNameMapper.INSTANCE.toDtoLight( rossini ); + + VivaldiDto vivaldiDto = (VivaldiDto) SubclassQualifiedByNameMapper.INSTANCE.toDto( vivaldi ); + VivaldiDto vivaldiDtoLight = (VivaldiDto) SubclassQualifiedByNameMapper.INSTANCE.toDtoLight( vivaldi ); + + assertThat( rossiniDto.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDto.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + assertThat( rossiniDtoLight.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDtoLight.getCrescendo() ).isNull(); + + assertThat( vivaldiDto.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDto.getSeasons() ).containsExactly( "spring", "winter" ); + assertThat( vivaldiDtoLight.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDtoLight.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByNameMapper.class) + void subclassQualifiedByNameOnlyOne() { + Rossini rossini = buildRossini(); + + Vivaldi vivaldi = buildVivaldi(); + + RossiniDto rossiniDto = (RossiniDto) SubclassQualifiedByNameMapper.INSTANCE.toDtoLightJustVivaldi( rossini ); + + VivaldiDto vivaldiDto = (VivaldiDto) SubclassQualifiedByNameMapper.INSTANCE.toDtoLightJustVivaldi( vivaldi ); + + assertThat( rossiniDto.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniDto.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + + assertThat( vivaldiDto.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiDto.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByMapper.class) + void subclassQualifiedByInverse() { + RossiniDto rossiniDto = buildRossiniDto(); + + VivaldiDto vivaldiDto = buildVivaldiDto(); + + Rossini rossini = (Rossini) SubclassQualifiedByMapper.INSTANCE.fromDto( rossiniDto ); + Rossini rossiniLight = (Rossini) SubclassQualifiedByMapper.INSTANCE.fromDtoLight( rossiniDto ); + + Vivaldi vivaldi = (Vivaldi) SubclassQualifiedByMapper.INSTANCE.fromDto( vivaldiDto ); + Vivaldi vivaldiLight = (Vivaldi) SubclassQualifiedByMapper.INSTANCE.fromDtoLight( vivaldiDto ); + + assertThat( rossini.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossini.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + assertThat( rossiniLight.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniLight.getCrescendo() ).isNull(); + + assertThat( vivaldi.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldi.getSeasons() ).containsExactly( "spring", "winter" ); + assertThat( vivaldiLight.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiLight.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByMapper.class) + void subclassQualifiedByOnlyOneInverse() { + RossiniDto rossiniDto = buildRossiniDto(); + + VivaldiDto vivaldiDto = buildVivaldiDto(); + + Rossini rossini = (Rossini) SubclassQualifiedByMapper.INSTANCE.fromDtoLightJustVivaldi( rossiniDto ); + + Vivaldi vivaldi = (Vivaldi) SubclassQualifiedByMapper.INSTANCE.fromDtoLightJustVivaldi( vivaldiDto ); + + assertThat( rossini.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossini.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + + assertThat( vivaldi.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldi.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByNameMapper.class) + void subclassQualifiedByNameInverse() { + RossiniDto rossiniDto = buildRossiniDto(); + + VivaldiDto vivaldiDto = buildVivaldiDto(); + + Rossini rossini = (Rossini) SubclassQualifiedByNameMapper.INSTANCE.fromDto( rossiniDto ); + Rossini rossiniLight = (Rossini) SubclassQualifiedByNameMapper.INSTANCE.fromDtoLight( rossiniDto ); + + Vivaldi vivaldi = (Vivaldi) SubclassQualifiedByNameMapper.INSTANCE.fromDto( vivaldiDto ); + Vivaldi vivaldiLight = (Vivaldi) SubclassQualifiedByNameMapper.INSTANCE.fromDtoLight( vivaldiDto ); + + assertThat( rossini.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossini.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + assertThat( rossiniLight.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossiniLight.getCrescendo() ).isNull(); + + assertThat( vivaldi.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldi.getSeasons() ).containsExactly( "spring", "winter" ); + assertThat( vivaldiLight.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldiLight.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByNameMapper.class) + void subclassQualifiedByNameOnlyOneInverse() { + RossiniDto rossiniDto = buildRossiniDto(); + + VivaldiDto vivaldiDto = buildVivaldiDto(); + + Rossini rossini = (Rossini) SubclassQualifiedByNameMapper.INSTANCE.fromDtoLightJustVivaldi( rossiniDto ); + + Vivaldi vivaldi = (Vivaldi) SubclassQualifiedByNameMapper.INSTANCE.fromDtoLightJustVivaldi( vivaldiDto ); + + assertThat( rossini.getName() ).isEqualTo( "gioacchino" ); + assertThat( rossini.getCrescendo() ).containsExactly( "andante", "allegro", "vivace" ); + + assertThat( vivaldi.getName() ).isEqualTo( "antonio" ); + assertThat( vivaldi.getSeasons() ).isNull(); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByMapper.class) + void subclassQualifiedByDoesNotContainUnused() { + generatedSource.forMapper( SubclassQualifiedByMapper.class ) + .content() + .doesNotContain( "DtoUnused" ); + } + + @ProcessorTest + @WithClasses(SubclassQualifiedByNameMapper.class) + void subclassQualifiedByNameDoesNotContainUnused() { + generatedSource.forMapper( SubclassQualifiedByNameMapper.class ) + .content() + .doesNotContain( "DtoUnused" ); + } + + @ProcessorTest + @WithClasses(ErroneousSubclassQualifiedByMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + type = ErroneousSubclassQualifiedByMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 15, + message = "Qualifier error. No method found annotated with: [ @NonExistent ]. " + + "See https://mapstruct.org/faq/#qualifier for more info." + ) + ) + void subclassQualifiedByErroneous() { + } + + @ProcessorTest + @WithClasses(ErroneousSubclassQualifiedByNameMapper.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + type = ErroneousSubclassQualifiedByNameMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 15, + message = "Qualifier error. No method found annotated with @Named#value: [ non-existent ]. " + + "See https://mapstruct.org/faq/#qualifier for more info." + ) + ) + void subclassQualifiedByNameErroneous() { + } + + private Rossini buildRossini() { + Rossini rossini = new Rossini(); + rossini.setName( "gioacchino" ); + List crescendo = new ArrayList<>(); + crescendo.add( "andante" ); + crescendo.add( "allegro" ); + crescendo.add( "vivace" ); + rossini.setCrescendo( crescendo ); + return rossini; + } + + private Vivaldi buildVivaldi() { + Vivaldi vivaldi = new Vivaldi(); + vivaldi.setName( "antonio" ); + List season = new ArrayList<>(); + season.add( "spring" ); + season.add( "winter" ); + vivaldi.setSeasons( season ); + return vivaldi; + } + + private RossiniDto buildRossiniDto() { + RossiniDto rossiniDto = new RossiniDto(); + rossiniDto.setName( "gioacchino" ); + List crescendo = new ArrayList<>(); + crescendo.add( "andante" ); + crescendo.add( "allegro" ); + crescendo.add( "vivace" ); + rossiniDto.setCrescendo( crescendo ); + return rossiniDto; + } + + private VivaldiDto buildVivaldiDto() { + VivaldiDto vivaldiDto = new VivaldiDto(); + vivaldiDto.setName( "antonio" ); + List season = new ArrayList<>(); + season.add( "spring" ); + season.add( "winter" ); + vivaldiDto.setSeasons( season ); + return vivaldiDto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Unused.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Unused.java new file mode 100644 index 0000000000..10da0434e2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Unused.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.mapstruct.Qualifier; + +@Qualifier +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.CLASS) +public @interface Unused { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Vivaldi.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Vivaldi.java new file mode 100644 index 0000000000..75df3d66f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/Vivaldi.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.util.List; + +public class Vivaldi extends Composer { + private List seasons; + + public List getSeasons() { + return seasons; + } + + public void setSeasons(List seasons) { + this.seasons = seasons; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiDto.java new file mode 100644 index 0000000000..79cd5fef33 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import java.util.List; + +public class VivaldiDto extends ComposerDto { + private List seasons; + + public List getSeasons() { + return seasons; + } + + public void setSeasons(List seasons) { + this.seasons = seasons; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiMapper.java new file mode 100644 index 0000000000..2b3b1fa3e7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/VivaldiMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.qualifier; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +@Mapper +public interface VivaldiMapper { + VivaldiDto toDto(Vivaldi vivaldi); + + @Light + @Mapping(target = "seasons", ignore = true) + VivaldiDto toDtoLight(Vivaldi vivaldi); + + @Named("light") + @Mapping(target = "seasons", ignore = true) + VivaldiDto toDtoLightNamed(Vivaldi vivaldi); + + @Unused + @BeanMapping(ignoreByDefault = true) + VivaldiDto toDtoUnused(Vivaldi vivaldi); + + @Named("unused") + @BeanMapping(ignoreByDefault = true) + VivaldiDto toDtoUnusedNamed(Vivaldi vivaldi); + + Vivaldi fromDto(VivaldiDto vivaldi); + + @Light + @Mapping(target = "seasons", ignore = true) + Vivaldi fromDtoLight(VivaldiDto vivaldi); + + @Named("light") + @Mapping(target = "seasons", ignore = true) + Vivaldi fromDtoLightNamed(VivaldiDto vivaldi); + + @Unused + @BeanMapping(ignoreByDefault = true) + Vivaldi fromDtoUnused(VivaldiDto vivaldi); + + @Named("unused") + @BeanMapping(ignoreByDefault = true) + Vivaldi fromDtoUnusedNamed(VivaldiDto vivaldi); +} From 62c7ce1cdf0ccc5528dca84decaf07cbecadaed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Campanero=20Ortiz?= Date: Thu, 13 Apr 2023 21:48:13 +0200 Subject: [PATCH 0740/1006] #3112 Document in the reference guide --- .../chapter-8-mapping-values.asciidoc | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index ce16b33ecd..b9cb308d4f 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -65,7 +65,7 @@ public class OrderMapperImpl implements OrderMapper { ---- ==== By default an error will be raised by MapStruct in case a constant of the source enum type does not have a corresponding constant with the same name in the target type and also is not mapped to another constant via `@ValueMapping`. This ensures that all constants are mapped in a safe and predictable manner. The generated -mapping method will throw an IllegalStateException if for some reason an unrecognized source value occurs. +mapping method will throw an `IllegalStateException` if for some reason an unrecognized source value occurs. MapStruct also has a mechanism for mapping any remaining (unspecified) mappings to a default. This can be used only once in a set of value mappings and only applies to the source. It comes in two flavors: `` and ``. They cannot be used at the same time. @@ -75,14 +75,18 @@ MapStruct will *not* attempt such name based mapping for `` and di MapStruct is able to handle `null` sources and `null` targets by means of the `` keyword. +In addition, the constant value `` can be used for throwing an exception for particular value mappings. This value is only applicable to `ValueMapping#target()` and not `ValueMapping#source()` since MapStruct can't map from exceptions. + [TIP] ==== -Constants for ``, `` and `` are available in the `MappingConstants` class. +Constants for ``, ``, `` and `` are available in the `MappingConstants` class. ==== Finally `@InheritInverseConfiguration` and `@InheritConfiguration` can be used in combination with `@ValueMappings`. `` and `` will be ignored in that case. -.Enum mapping method, and +The following code snippets exemplify the use of the aforementioned constants. + +.Enum mapping method, `` and `` ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -102,7 +106,7 @@ public interface SpecialOrderMapper { ---- ==== -.Enum mapping method result, and +.Enum mapping method result, `` and `` ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -137,6 +141,55 @@ public class SpecialOrderMapperImpl implements SpecialOrderMapper { *Note:* MapStruct would have refrained from mapping the `RETAIL` and `B2B` when `` was used instead of ``. +.Enum mapping method with `` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface SpecialOrderMapper { + + SpecialOrderMapper INSTANCE = Mappers.getMapper( SpecialOrderMapper.class ); + + @ValueMappings({ + @ValueMapping( source = "STANDARD", target = "DEFAULT" ), + @ValueMapping( source = "C2C", target = MappingConstants.THROW_EXCEPTION ) + }) + ExternalOrderType orderTypeToExternalOrderType(OrderType orderType); +} +---- +==== + +.Enum mapping method with `` result +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class SpecialOrderMapperImpl implements SpecialOrderMapper { + + @Override + public ExternalOrderType orderTypeToExternalOrderType(OrderType orderType) { + if ( orderType == null ) { + return null; + } + + ExternalOrderType externalOrderType; + + switch ( orderType ) { + case STANDARD: externalOrderType = ExternalOrderType.DEFAULT; + break; + case C2C: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + default: throw new IllegalArgumentException( "Unexpected enum constant: " + orderType ); + } + + return externalOrderType; + } +} +---- +==== + + [WARNING] ==== The mapping of enum to enum via the `@Mapping` annotation is *DEPRECATED*. It will be removed from future versions of MapStruct. Please adapt existing enum mapping methods to make use of `@ValueMapping` instead. @@ -152,6 +205,7 @@ MapStruct supports enum to a String mapping along the same lines as is described 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Difference: `` will result in an error. It acts on the premise that there is name similarity between enum constants in source and target which does not make sense for a String type. 4. Difference: Given 1. and 3. there will never be unmapped values. +5. Similarity: `THROW_EXCEPTION` can be used for throwing an exception for particular enum values. *`String` to enum* @@ -159,6 +213,7 @@ MapStruct supports enum to a String mapping along the same lines as is described 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Similarity: `` will create a mapping for each target enum constant and proceed to the switch/default clause value. 4. Difference: A switch/default value needs to be provided to have a determined outcome (enum has a limited set of values, `String` has unlimited options). Failing to specify `` or ` will result in a warning. +5. Similarity: `THROW_EXCEPTION` can be used for throwing an exception for any arbitrary `String` value. === Custom name transformation From 2be1f306a1179b437e850f8ac99ceb492373dced Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 17 Mar 2023 11:23:53 +0100 Subject: [PATCH 0741/1006] #3135 BeanMapping#mappingControl should be inherited by forged methods --- .../model/source/BeanMappingOptions.java | 11 ++++++++++ .../model/source/MappingMethodOptions.java | 2 +- .../model/source/SelectionParameters.java | 4 ++++ .../CloningBeanMappingMapper.java | 21 +++++++++++++++++++ .../mappingcontrol/MappingControlTest.java | 15 +++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningBeanMappingMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 90ad0aabb4..24811768e7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -54,6 +54,17 @@ public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) return options; } + public static BeanMappingOptions forForgedMethods(BeanMappingOptions beanMapping) { + BeanMappingOptions options = new BeanMappingOptions( + beanMapping.selectionParameters != null ? + SelectionParameters.withoutResultType( beanMapping.selectionParameters ) : null, + Collections.emptyList(), + beanMapping.beanMapping, + beanMapping + ); + return options; + } + public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) { return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index a1a64872a9..9f5da7b8de 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -365,7 +365,7 @@ public static MappingMethodOptions getForgedMethodInheritedOptions(MappingMethod options.mappings, options.iterableMapping, options.mapMapping, - BeanMappingOptions.empty( options.beanMapping.next() ), + BeanMappingOptions.forForgedMethods( options.beanMapping ), options.enumMappingOptions, options.valueMappings, Collections.emptySet(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index fb76c13629..7237668e2c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -39,6 +39,10 @@ public class SelectionParameters { * @return the selection parameters based on the given ones */ public static SelectionParameters forInheritance(SelectionParameters selectionParameters) { + return withoutResultType( selectionParameters ); + } + + public static SelectionParameters withoutResultType(SelectionParameters selectionParameters) { return new SelectionParameters( selectionParameters.qualifiers, selectionParameters.qualifyingNames, diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningBeanMappingMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningBeanMappingMapper.java new file mode 100644 index 0000000000..a5c05d974d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/CloningBeanMappingMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.control.DeepClone; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CloningBeanMappingMapper { + + CloningBeanMappingMapper INSTANCE = Mappers.getMapper( CloningBeanMappingMapper.class ); + + @BeanMapping(mappingControl = DeepClone.class) + FridgeDTO clone(FridgeDTO in); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index d542801799..c9c2e095f5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -69,6 +69,21 @@ public void testDeepCloning() { assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" ); } + @ProcessorTest + @IssueKey("3135") + @WithClasses(CloningBeanMappingMapper.class) + public void testDeepCloningViaBeanMapping() { + + FridgeDTO in = createFridgeDTO(); + FridgeDTO out = CloningBeanMappingMapper.INSTANCE.clone( in ); + + assertThat( out ).isNotNull(); + assertThat( out.getShelve() ).isNotNull(); + assertThat( out.getShelve() ).isNotSameAs( in.getShelve() ); + assertThat( out.getShelve().getCoolBeer() ).isNotSameAs( in.getShelve().getCoolBeer() ); + assertThat( out.getShelve().getCoolBeer().getBeerCount() ).isEqualTo( "5" ); + } + /** * Test the deep cloning annotation with lists */ From 6e9fa87ba99bb8637ae7f525636610fc77ad6e22 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 13 Apr 2023 21:52:15 +0200 Subject: [PATCH 0742/1006] #3142 Nested forged methods should declare throws from lifecycle methods --- .../ap/internal/model/BeanMappingMethod.java | 8 ++++ .../test/bugs/_3142/Issue3142Exception.java | 16 +++++++ .../ap/test/bugs/_3142/Issue3142Test.java | 48 +++++++++++++++++++ ...ue3142WithAfterMappingExceptionMapper.java | 32 +++++++++++++ ...e3142WithBeforeMappingExceptionMapper.java | 32 +++++++++++++ .../mapstruct/ap/test/bugs/_3142/Source.java | 33 +++++++++++++ .../mapstruct/ap/test/bugs/_3142/Target.java | 42 ++++++++++++++++ 7 files changed, 211 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Exception.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithAfterMappingExceptionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithBeforeMappingExceptionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 29d27c8d68..8942c62789 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -340,6 +340,14 @@ else if ( !method.isUpdateMethod() ) { if ( factoryMethod != null ) { forgedMethod.addThrownTypes( factoryMethod.getThrownTypes() ); } + for ( LifecycleCallbackMethodReference beforeMappingMethod : beforeMappingMethods ) { + forgedMethod.addThrownTypes( beforeMappingMethod.getThrownTypes() ); + } + + for ( LifecycleCallbackMethodReference afterMappingMethod : afterMappingMethods ) { + forgedMethod.addThrownTypes( afterMappingMethod.getThrownTypes() ); + } + for ( PropertyMapping propertyMapping : propertyMappings ) { if ( propertyMapping.getAssignment() != null ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Exception.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Exception.java new file mode 100644 index 0000000000..54ed903ee7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Exception.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +/** + * @author Filip Hrisafov + */ +public class Issue3142Exception extends Exception { + + public Issue3142Exception(String message) { + super( message ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Test.java new file mode 100644 index 0000000000..a8b44874bb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142Test.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + Issue3142Exception.class, + Source.class, + Target.class, +}) +@IssueKey("3142") +class Issue3142Test { + + @ProcessorTest + @WithClasses({ + Issue3142WithBeforeMappingExceptionMapper.class + }) + void exceptionThrownInBeforeMapping() { + assertThatThrownBy( () -> Issue3142WithBeforeMappingExceptionMapper.INSTANCE.map( + new Source( new Source.Nested( "throwException" ) ), "test" ) + ) + .isInstanceOf( Issue3142Exception.class ) + .hasMessage( "Source nested exception" ); + } + + @ProcessorTest + @WithClasses({ + Issue3142WithAfterMappingExceptionMapper.class + }) + void exceptionThrownInAfterMapping() { + assertThatThrownBy( () -> Issue3142WithAfterMappingExceptionMapper.INSTANCE.map( + new Source( new Source.Nested( "throwException" ) ), "test" ) + ) + .isInstanceOf( Issue3142Exception.class ) + .hasMessage( "Source nested exception" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithAfterMappingExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithAfterMappingExceptionMapper.java new file mode 100644 index 0000000000..e188626424 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithAfterMappingExceptionMapper.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3142WithAfterMappingExceptionMapper { + + Issue3142WithAfterMappingExceptionMapper INSTANCE = + Mappers.getMapper( Issue3142WithAfterMappingExceptionMapper.class ); + + Target map(Source source, String id) throws Issue3142Exception; + + @AfterMapping + default void afterMappingValidation(Object source) throws Issue3142Exception { + if ( source instanceof Source.Nested ) { + Source.Nested nested = (Source.Nested) source; + if ( "throwException".equals( nested.getValue() ) ) { + throw new Issue3142Exception( "Source nested exception" ); + } + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithBeforeMappingExceptionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithBeforeMappingExceptionMapper.java new file mode 100644 index 0000000000..ee27d87b7f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Issue3142WithBeforeMappingExceptionMapper.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +import org.mapstruct.BeforeMapping; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3142WithBeforeMappingExceptionMapper { + + Issue3142WithBeforeMappingExceptionMapper INSTANCE = + Mappers.getMapper( Issue3142WithBeforeMappingExceptionMapper.class ); + + Target map(Source source, String id) throws Issue3142Exception; + + @BeforeMapping + default void preMappingValidation(Object source) throws Issue3142Exception { + if ( source instanceof Source.Nested ) { + Source.Nested nested = (Source.Nested) source; + if ( "throwException".equals( nested.getValue() ) ) { + throw new Issue3142Exception( "Source nested exception" ); + } + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Source.java new file mode 100644 index 0000000000..2b78ffa022 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Source.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +/** + * @author Filip Hrisafov + */ +public class Source { + private final Nested nested; + + public Source(Nested nested) { + this.nested = nested; + } + + public Nested getNested() { + return nested; + } + + public static class Nested { + private final String value; + + public Nested(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Target.java new file mode 100644 index 0000000000..6f832b6ecf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3142/Target.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3142; + +/** + * @author Filip Hrisafov + */ +public class Target { + private String id; + private Nested nested; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + + public static class Nested { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} From 03563d8ffea0ca5ff4eadb297795f2407001c5dd Mon Sep 17 00:00:00 2001 From: Ben Zegveld Date: Sat, 25 Feb 2023 21:29:23 +0100 Subject: [PATCH 0743/1006] #3174 Also allow multiple SubclassMapping annotations on an annotation @interface. --- .../java/org/mapstruct/SubclassMappings.java | 2 +- .../CompositeSubclassMappingAnnotation.java | 19 ++++++++ .../SubclassCompositeMapper.java | 29 ++++++++++++ .../subclassmapping/SubclassMappingTest.java | 45 +++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/CompositeSubclassMappingAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassCompositeMapper.java diff --git a/core/src/main/java/org/mapstruct/SubclassMappings.java b/core/src/main/java/org/mapstruct/SubclassMappings.java index 938b836f77..2ddafaf516 100644 --- a/core/src/main/java/org/mapstruct/SubclassMappings.java +++ b/core/src/main/java/org/mapstruct/SubclassMappings.java @@ -45,7 +45,7 @@ * @author Ben Zegveld * @since 1.5 */ -@Target(ElementType.METHOD) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.CLASS) @Experimental public @interface SubclassMappings { diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/CompositeSubclassMappingAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/CompositeSubclassMappingAnnotation.java new file mode 100644 index 0000000000..a121c08799 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/CompositeSubclassMappingAnnotation.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; + +@SubclassMapping( source = Car.class, target = CarDto.class ) +@SubclassMapping( source = Bike.class, target = BikeDto.class ) +@Mapping( source = "vehicleManufacturingCompany", target = "maker") +public @interface CompositeSubclassMappingAnnotation { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassCompositeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassCompositeMapper.java new file mode 100644 index 0000000000..c660cd2390 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassCompositeMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollectionDto; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SubclassCompositeMapper { + SubclassCompositeMapper INSTANCE = Mappers.getMapper( SubclassCompositeMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @CompositeSubclassMappingAnnotation + VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java index 6f9b6e160c..5a5ce1ef99 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -143,6 +143,51 @@ void subclassMappingOverridesInverseInheritsMapping() { .containsExactly( Car.class ); } + @ProcessorTest + @WithClasses( { SubclassCompositeMapper.class, CompositeSubclassMappingAnnotation.class }) + void mappingIsDoneUsingSubclassMappingWithCompositeMapping() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Bike() ); + + VehicleCollectionDto result = SubclassCompositeMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( CarDto.class, BikeDto.class ); + } + + @ProcessorTest + @WithClasses( { SubclassCompositeMapper.class, CompositeSubclassMappingAnnotation.class }) + void inverseMappingIsDoneUsingSubclassMappingWithCompositeMapping() { + VehicleCollectionDto vehicles = new VehicleCollectionDto(); + vehicles.getVehicles().add( new CarDto() ); + vehicles.getVehicles().add( new BikeDto() ); + + VehicleCollection result = SubclassCompositeMapper.INSTANCE.mapInverse( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( Car.class, Bike.class ); + } + + @ProcessorTest + @WithClasses( { SubclassCompositeMapper.class, CompositeSubclassMappingAnnotation.class }) + void subclassMappingInheritsInverseMappingWithCompositeMapping() { + VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); + CarDto carDto = new CarDto(); + carDto.setMaker( "BenZ" ); + vehiclesDto.getVehicles().add( carDto ); + + VehicleCollection result = SubclassCompositeMapper.INSTANCE.mapInverse( vehiclesDto ); + + assertThat( result.getVehicles() ) + .extracting( Vehicle::getVehicleManufacturingCompany ) + .containsExactly( "BenZ" ); + } + @ProcessorTest @WithClasses({ HatchBack.class, From 162fdb44f402e47d549778d57f369db144ce5e0d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 16 Apr 2023 10:17:32 +0200 Subject: [PATCH 0744/1006] #3195 Update the location for asking questions --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 58d1c515bb..4807b5fba0 100644 --- a/readme.md +++ b/readme.md @@ -126,7 +126,7 @@ If you don't work with a dependency management tool, you can obtain a distributi ## Documentation and getting help -To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help, come and join the [mapstruct-users](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) group. +To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help please ask it in the [Discussions](https://github.com/mapstruct/mapstruct/discussions). ## Building from Source From 3c81d36810caf052f1d8bc73e30d9e3a8c8622f4 Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Mon, 17 Apr 2023 04:51:33 +0900 Subject: [PATCH 0745/1006] Polish links in docs (#3214) --- core/src/main/java/org/mapstruct/Mapper.java | 2 +- core/src/main/java/org/mapstruct/MapperConfig.java | 2 +- core/src/main/java/org/mapstruct/package-info.java | 2 +- distribution/pom.xml | 2 +- parent/pom.xml | 2 +- readme.md | 14 +++++++------- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 0436c0cf69..60725cc441 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -298,7 +298,7 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default * Can be configured by the {@link MapperConfig#disableSubMappingMethodsGeneration()} as well. *

      * Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at - * mapstruct.org or + * mapstruct.org or * github.com/mapstruct/mapstruct to share what problem you * are facing with the automatic sub-mapping generation. * diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 893801cdaa..915f3dd120 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -269,7 +269,7 @@ MappingInheritanceStrategy mappingInheritanceStrategy() * Can be overridden by {@link Mapper#disableSubMappingMethodsGeneration()} *

      * Note: If you need to use {@code disableSubMappingMethodsGeneration} please contact the MapStruct team at - * mapstruct.org or + * mapstruct.org or * github.com/mapstruct/mapstruct to share what problem you * are facing with the automatic sub-mapping generation. * diff --git a/core/src/main/java/org/mapstruct/package-info.java b/core/src/main/java/org/mapstruct/package-info.java index 02f2b31a42..5a53b5a6d3 100644 --- a/core/src/main/java/org/mapstruct/package-info.java +++ b/core/src/main/java/org/mapstruct/package-info.java @@ -13,6 +13,6 @@ * This package contains several annotations which allow to configure how mapper interfaces are generated. *

      * - * @see MapStruct reference documentation + * @see MapStruct reference documentation */ package org.mapstruct; diff --git a/distribution/pom.xml b/distribution/pom.xml index be82f52b3c..bcfa1f3db0 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -100,7 +100,7 @@ MapStruct ${project.version} MapStruct ${project.version} - MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.]]> + MapStruct Authors; All rights reserved. Released under the Apache Software License 2.0.]]> diff --git a/parent/pom.xml b/parent/pom.xml index e87db14551..b306446b65 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -16,7 +16,7 @@ MapStruct Parent An annotation processor for generating type-safe bean mappers - http://mapstruct.org/ + https://mapstruct.org/ 2012 diff --git a/readme.md b/readme.md index 4807b5fba0..4e0c2f6ad4 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.3.Final-blue.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct%20AND%20v%3A1.*.Final) -[![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aorg.mapstruct) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.3.Final-blue.svg)](https://search.maven.org/search?q=g:org.mapstruct%20AND%20v:1.*.Final) +[![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://search.maven.org/search?q=g:org.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) [![Build Status](https://github.com/mapstruct/mapstruct/workflows/CI/badge.svg?branch=master)](https://github.com/mapstruct/mapstruct/actions?query=branch%3Amaster+workflow%3ACI) @@ -22,7 +22,7 @@ ## What is MapStruct? -MapStruct is a Java [annotation processor](http://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html) for the generation of type-safe and performant mappers for Java bean classes. It saves you from writing mapping code by hand, which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior. +MapStruct is a Java [annotation processor](https://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html) for the generation of type-safe and performant mappers for Java bean classes. It saves you from writing mapping code by hand, which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior. Compared to mapping frameworks working at runtime, MapStruct offers the following advantages: @@ -126,7 +126,7 @@ If you don't work with a dependency management tool, you can obtain a distributi ## Documentation and getting help -To learn more about MapStruct, refer to the [project homepage](http://mapstruct.org). The [reference documentation](http://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help please ask it in the [Discussions](https://github.com/mapstruct/mapstruct/discussions). +To learn more about MapStruct, refer to the [project homepage](https://mapstruct.org). The [reference documentation](https://mapstruct.org/documentation/reference-guide/) covers all provided functionality in detail. If you need help please ask it in the [Discussions](https://github.com/mapstruct/mapstruct/discussions). ## Building from Source @@ -154,13 +154,13 @@ Make sure that you have the [m2e_apt](https://marketplace.eclipse.org/content/m2 ## Links -* [Homepage](http://mapstruct.org) +* [Homepage](https://mapstruct.org) * [Source code](https://github.com/mapstruct/mapstruct/) -* [Downloads](https://sourceforge.net/projects/mapstruct/files/) +* [Downloads](https://github.com/mapstruct/mapstruct/releases) * [Issue tracker](https://github.com/mapstruct/mapstruct/issues) * [User group](https://groups.google.com/forum/?hl=en#!forum/mapstruct-users) * [CI build](https://github.com/mapstruct/mapstruct/actions/) ## Licensing -MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. +MapStruct is licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0. From 00f891be5834da6d81db330cde7ddaab6abe6bf8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Apr 2023 17:14:46 +0200 Subject: [PATCH 0746/1006] #3112 Add missing brackets --- .../src/main/asciidoc/chapter-8-mapping-values.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index b9cb308d4f..965479541e 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -205,7 +205,7 @@ MapStruct supports enum to a String mapping along the same lines as is described 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Difference: `` will result in an error. It acts on the premise that there is name similarity between enum constants in source and target which does not make sense for a String type. 4. Difference: Given 1. and 3. there will never be unmapped values. -5. Similarity: `THROW_EXCEPTION` can be used for throwing an exception for particular enum values. +5. Similarity: `` can be used for throwing an exception for particular enum values. *`String` to enum* @@ -213,7 +213,7 @@ MapStruct supports enum to a String mapping along the same lines as is described 2. Similarity: ` stops after handling defined mapping and proceeds to the switch/default clause value. 3. Similarity: `` will create a mapping for each target enum constant and proceed to the switch/default clause value. 4. Difference: A switch/default value needs to be provided to have a determined outcome (enum has a limited set of values, `String` has unlimited options). Failing to specify `` or ` will result in a warning. -5. Similarity: `THROW_EXCEPTION` can be used for throwing an exception for any arbitrary `String` value. +5. Similarity: `` can be used for throwing an exception for any arbitrary `String` value. === Custom name transformation From 9adcb06c3486ea53ab37020b3080f776efe9fb48 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Apr 2023 17:22:26 +0200 Subject: [PATCH 0747/1006] #3236 Add missing jakarta-cdi to the documentation --- documentation/src/main/asciidoc/chapter-2-set-up.asciidoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 12c399c1f5..666954c4b1 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -215,10 +215,11 @@ suppressGeneratorVersionInfoComment` Supported values are: * `default`: the mapper uses no component model, instances are typically retrieved via `Mappers#getMapper(Class)` -* `cdi`: the generated mapper is an application-scoped CDI bean and can be retrieved via `@Inject` +* `cdi`: the generated mapper is an application-scoped (from javax.enterprise.context or jakarta.enterprise.context, depending on which one is available with javax.inject having priority) CDI bean and can be retrieved via `@Inject` * `spring`: the generated mapper is a singleton-scoped Spring bean and can be retrieved via `@Autowired` * `jsr330`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject` (from javax.inject or jakarta.inject, depending which one is available with javax.inject having priority), e.g. using Spring * `jakarta`: the generated mapper is annotated with {@code @Named} and can be retrieved via `@Inject` (from jakarta.inject), e.g. using Spring +* `jakarta-cdi`: the generated mapper is an application-scoped (from jakarta.enterprise.context) CDI bean and can be retrieved via `@Inject` If a component model is given for a specific mapper via `@Mapper#componentModel()`, the value from the annotation takes precedence. |`default` From b1034e67035fea9329b13e288aa4503533f6912c Mon Sep 17 00:00:00 2001 From: Claudio Nave Date: Sat, 18 Mar 2023 13:01:49 +0100 Subject: [PATCH 0748/1006] #3202 Improve line location report for invalid qualifier for SubclassMapping --- .../ap/internal/model/BeanMappingMethod.java | 2 +- .../model/source/SubclassMappingOptions.java | 40 +++++++++++-------- .../ErroneousSubclassQualifiedByMapper.java | 1 - .../SubclassQualifierMapperTest.java | 5 ++- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 8942c62789..c8fbe0205b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -420,7 +420,7 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap FormattingParameters.EMPTY, criteria, rightHandSide, - null, + subclassMappingOptions.getMirror(), () -> forgeSubclassMapping( rightHandSide, sourceType, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java index 6ed1117ebd..11b4b283c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java @@ -7,7 +7,10 @@ import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; +import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.type.TypeMirror; @@ -34,14 +37,16 @@ public class SubclassMappingOptions extends DelegatingOptions { private final TypeMirror target; private final TypeUtils typeUtils; private final SelectionParameters selectionParameters; + private final SubclassMappingGem subclassMapping; public SubclassMappingOptions(TypeMirror source, TypeMirror target, TypeUtils typeUtils, DelegatingOptions next, - SelectionParameters selectionParameters) { + SelectionParameters selectionParameters, SubclassMappingGem subclassMapping) { super( next ); this.source = source; this.target = target; this.typeUtils = typeUtils; this.selectionParameters = selectionParameters; + this.subclassMapping = subclassMapping; } @Override @@ -124,14 +129,18 @@ public SelectionParameters getSelectionParameters() { return selectionParameters; } + public AnnotationMirror getMirror() { + return Optional.ofNullable( subclassMapping ).map( SubclassMappingGem::mirror ).orElse( null ); + } + public static void addInstances(SubclassMappingsGem gem, ExecutableElement method, BeanMappingOptions beanMappingOptions, FormattingMessager messager, TypeUtils typeUtils, Set mappings, List sourceParameters, Type resultType, SubclassValidator subclassValidator) { - for ( SubclassMappingGem subclassMappingGem : gem.value().get() ) { + for ( SubclassMappingGem subclassMapping : gem.value().get() ) { addInstance( - subclassMappingGem, + subclassMapping, method, beanMappingOptions, messager, @@ -175,25 +184,22 @@ public static void addInstance(SubclassMappingGem subclassMapping, ExecutableEle targetSubclass, typeUtils, beanMappingOptions, - selectionParameters + selectionParameters, + subclassMapping ) ); } - public static List copyForInverseInheritance(Set subclassMappings, + public static List copyForInverseInheritance(Set mappings, BeanMappingOptions beanMappingOptions) { // we are not interested in keeping it unique at this point. - List mappings = new ArrayList<>(); - for ( SubclassMappingOptions subclassMapping : subclassMappings ) { - mappings.add( - new SubclassMappingOptions( - subclassMapping.target, - subclassMapping.source, - subclassMapping.typeUtils, - beanMappingOptions, - subclassMapping.selectionParameters - ) ); - } - return mappings; + return mappings.stream().map( mapping -> new SubclassMappingOptions( + mapping.target, + mapping.source, + mapping.typeUtils, + beanMappingOptions, + mapping.selectionParameters, + mapping.subclassMapping + ) ).collect( Collectors.toCollection( ArrayList::new ) ); } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java index 26cdd4715e..fb5dcca11c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/ErroneousSubclassQualifiedByMapper.java @@ -11,6 +11,5 @@ @Mapper(uses = { RossiniMapper.class, VivaldiMapper.class }) public interface ErroneousSubclassQualifiedByMapper { @SubclassMapping(source = Rossini.class, target = RossiniDto.class, qualifiedBy = NonExistent.class) - @SubclassMapping(source = Vivaldi.class, target = VivaldiDto.class) ComposerDto toDto(Composer composer); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java index df67c27013..2b301d8981 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/qualifier/SubclassQualifierMapperTest.java @@ -230,7 +230,7 @@ void subclassQualifiedByNameDoesNotContainUnused() { diagnostics = @Diagnostic( type = ErroneousSubclassQualifiedByMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 15, + line = 13, message = "Qualifier error. No method found annotated with: [ @NonExistent ]. " + "See https://mapstruct.org/faq/#qualifier for more info." ) @@ -245,7 +245,8 @@ void subclassQualifiedByErroneous() { diagnostics = @Diagnostic( type = ErroneousSubclassQualifiedByNameMapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 15, + line = 13, + alternativeLine = 15, message = "Qualifier error. No method found annotated with @Named#value: [ non-existent ]. " + "See https://mapstruct.org/faq/#qualifier for more info." ) From d10d48ccff8e3715b44ddfd3ad3f5a54e1238479 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Apr 2023 18:36:42 +0200 Subject: [PATCH 0749/1006] #3248 BeanMapping#ignoreUnmappedSourceProperties should be inherited for `@InheritConfiguration` --- .../model/source/BeanMappingOptions.java | 5 +- .../model/source/MappingMethodOptions.java | 2 +- .../ap/test/bugs/_3248/Issue3248Mapper.java | 52 +++++++++++++++++++ .../ap/test/bugs/_3248/Issue3248Test.java | 25 +++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index 24811768e7..e8f19f91f6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -41,13 +41,14 @@ public class BeanMappingOptions extends DelegatingOptions { * creates a mapping for inheritance. Will set * * @param beanMapping the bean mapping options that should be used + * @param isInverse whether the inheritance is inverse * * @return new mapping */ - public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping) { + public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping, boolean isInverse) { BeanMappingOptions options = new BeanMappingOptions( SelectionParameters.forInheritance( beanMapping.selectionParameters ), - Collections.emptyList(), + isInverse ? Collections.emptyList() : beanMapping.ignoreUnmappedSourceProperties, beanMapping.beanMapping, beanMapping ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 9f5da7b8de..2124dd974d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -167,7 +167,7 @@ public void applyInheritedOptions(SourceMethod sourceMethod, SourceMethod templa } if ( !getBeanMapping().hasAnnotation() && templateOptions.getBeanMapping().hasAnnotation() ) { - setBeanMapping( BeanMappingOptions.forInheritance( templateOptions.getBeanMapping( ) ) ); + setBeanMapping( BeanMappingOptions.forInheritance( templateOptions.getBeanMapping( ), isInverse ) ); } if ( !getEnumMappingOptions().hasAnnotation() && templateOptions.getEnumMappingOptions().hasAnnotation() ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Mapper.java new file mode 100644 index 0000000000..e0cbba40f7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Mapper.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3248; + +import org.mapstruct.BeanMapping; +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue3248Mapper { + + @BeanMapping(ignoreUnmappedSourceProperties = "otherValue") + Target map(Source source); + + @InheritConfiguration + Target secondMap(Source source); + + class Target { + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public String getOtherValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Test.java new file mode 100644 index 0000000000..ad8cf2e499 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3248/Issue3248Test.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3248; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3248") +@WithClasses({ + Issue3248Mapper.class +}) +class Issue3248Test { + + @ProcessorTest + void shouldCompileCode() { + + } +} From c6ea69eaf9bba177a52f6ddebebc1378797b0eb2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 15 Apr 2023 23:18:32 +0200 Subject: [PATCH 0750/1006] #3186 Do not use conversions in 2-step mapping when they are disabled --- .../creation/MappingResolverImpl.java | 54 ++++++----- .../ErroneousBuiltInAndBuiltInMapper.java | 44 +++++++++ .../ErroneousBuiltInAndMethodMapper.java | 50 +++++++++++ .../ErroneousConversionAndMethodMapper.java | 48 ++++++++++ .../ErroneousMethodAndBuiltInMapper.java | 49 ++++++++++ .../ErroneousMethodAndConversionMapper.java | 48 ++++++++++ .../mappingcontrol/MappingControlTest.java | 90 +++++++++++++++++++ .../ap/test/mappingcontrol/NoConversion.java | 20 +++++ 8 files changed, 380 insertions(+), 23 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndBuiltInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionAndMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndBuiltInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndConversionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/NoConversion.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 12b345d238..0c8e2cc4c4 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -295,20 +295,24 @@ && allowDirect( sourceType, targetType ) ) { } // 2 step method, then: method(conversion(source)) - assignment = ConversionMethod.getBestMatch( this, sourceType, targetType ); - if ( assignment != null ) { - usedSupportedMappings.addAll( supportingMethodCandidates ); - return assignment; + if ( allowConversion() ) { + assignment = ConversionMethod.getBestMatch( this, sourceType, targetType ); + if ( assignment != null ) { + usedSupportedMappings.addAll( supportingMethodCandidates ); + return assignment; + } } // stop here when looking for update methods. selectionCriteria.setPreferUpdateMapping( false ); // 2 step method, finally: conversion(method(source)) - assignment = MethodConversion.getBestMatch( this, sourceType, targetType ); - if ( assignment != null ) { - usedSupportedMappings.addAll( supportingMethodCandidates ); - return assignment; + if ( allowConversion() ) { + assignment = MethodConversion.getBestMatch( this, sourceType, targetType ); + if ( assignment != null ) { + usedSupportedMappings.addAll( supportingMethodCandidates ); + return assignment; + } } } @@ -763,22 +767,26 @@ static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targe return mmAttempt.result; } } - MethodMethod mbAttempt = - new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef ) - .getBestMatch( sourceType, targetType ); - if ( mbAttempt.hasResult ) { - return mbAttempt.result; - } - MethodMethod bmAttempt = - new MethodMethod<>( att, att.builtIns, att.methods, att::toBuildInRef, att::toMethodRef ) - .getBestMatch( sourceType, targetType ); - if ( bmAttempt.hasResult ) { - return bmAttempt.result; + if ( att.allowConversion() ) { + MethodMethod mbAttempt = + new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + if ( mbAttempt.hasResult ) { + return mbAttempt.result; + } + MethodMethod bmAttempt = + new MethodMethod<>( att, att.builtIns, att.methods, att::toBuildInRef, att::toMethodRef ) + .getBestMatch( sourceType, targetType ); + if ( bmAttempt.hasResult ) { + return bmAttempt.result; + } + MethodMethod bbAttempt = + new MethodMethod<>( att, att.builtIns, att.builtIns, att::toBuildInRef, att::toBuildInRef ) + .getBestMatch( sourceType, targetType ); + return bbAttempt.result; } - MethodMethod bbAttempt = - new MethodMethod<>( att, att.builtIns, att.builtIns, att::toBuildInRef, att::toBuildInRef ) - .getBestMatch( sourceType, targetType ); - return bbAttempt.result; + + return null; } MethodMethod(ResolvingAttempt attempt, List xMethods, List yMethods, diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndBuiltInMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndBuiltInMapper.java new file mode 100644 index 0000000000..eb9f7ea9ce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndBuiltInMapper.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.time.ZonedDateTime; +import java.util.Date; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = NoConversion.class) +public interface ErroneousBuiltInAndBuiltInMapper { + + Target map(Source source); + + class Source { + private final ZonedDateTime time; + + public Source(ZonedDateTime time) { + this.time = time; + } + + public ZonedDateTime getTime() { + return time; + } + } + + class Target { + private final Date time; + + public Target(Date time) { + this.time = time; + } + + public Date getTime() { + return time; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndMethodMapper.java new file mode 100644 index 0000000000..fdd7545da7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousBuiltInAndMethodMapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.time.Instant; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Calendar; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = NoConversion.class) +public interface ErroneousBuiltInAndMethodMapper { + + Target map(Source source); + + default ZonedDateTime fromInt(int time) { + return ZonedDateTime.ofInstant( Instant.ofEpochMilli( time ), ZoneOffset.UTC ); + } + + class Source { + private final int time; + + public Source(int time) { + this.time = time; + } + + public int getTime() { + return time; + } + } + + class Target { + private Calendar time; + + public Target(Calendar time) { + this.time = time; + } + + public Calendar getTime() { + return time; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionAndMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionAndMethodMapper.java new file mode 100644 index 0000000000..91a94aeca2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousConversionAndMethodMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.time.Instant; +import java.util.Date; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = NoConversion.class) +public interface ErroneousConversionAndMethodMapper { + + Target map(Source source); + + default Instant fromDate(int time) { + return Instant.ofEpochMilli( time ); + } + + class Source { + private final int time; + + public Source(int time) { + this.time = time; + } + + public int getTime() { + return time; + } + } + + class Target { + private Date time; + + public Target(Date time) { + this.time = time; + } + + public Date getTime() { + return time; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndBuiltInMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndBuiltInMapper.java new file mode 100644 index 0000000000..d7798161c1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndBuiltInMapper.java @@ -0,0 +1,49 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Date; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = NoConversion.class) +public interface ErroneousMethodAndBuiltInMapper { + + Target map(Source source); + + default Date fromCalendar(Calendar calendar) { + return calendar != null ? calendar.getTime() : null; + } + + class Source { + private final ZonedDateTime time; + + public Source(ZonedDateTime time) { + this.time = time; + } + + public ZonedDateTime getTime() { + return time; + } + } + + class Target { + private final Date time; + + public Target(Date time) { + this.time = time; + } + + public Date getTime() { + return time; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndConversionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndConversionMapper.java new file mode 100644 index 0000000000..5a372addd9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/ErroneousMethodAndConversionMapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.time.Instant; +import java.util.Date; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper(mappingControl = NoConversion.class) +public interface ErroneousMethodAndConversionMapper { + + Target map(Source source); + + default long fromInstant(Instant value) { + return value != null ? value.getEpochSecond() : null; + } + + class Source { + private final Date time; + + public Source(Date time) { + this.time = time; + } + + public Date getTime() { + return time; + } + } + + class Target { + private long time; + + public Target(long time) { + this.time = time; + } + + public long getTime() { + return time; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java index c9c2e095f5..171fe4bc6a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/MappingControlTest.java @@ -240,6 +240,96 @@ public void complexSelectionNotAllowed() { public void complexSelectionNotAllowedWithConfig() { } + @ProcessorTest + @IssueKey("3186") + @WithClasses({ + ErroneousMethodAndBuiltInMapper.class, + NoConversion.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMethodAndBuiltInMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Can't map property \"ZonedDateTime time\" to \"Date time\". " + + "Consider to declare/implement a mapping method: \"Date map(ZonedDateTime value)\"." + ) + }) + public void conversionSelectionNotAllowedInTwoStepMethodBuiltIdConversion() { + } + + @ProcessorTest + @IssueKey("3186") + @WithClasses({ + ErroneousBuiltInAndBuiltInMapper.class, + NoConversion.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousBuiltInAndBuiltInMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 19, + message = "Can't map property \"ZonedDateTime time\" to \"Date time\". " + + "Consider to declare/implement a mapping method: \"Date map(ZonedDateTime value)\"." + ) + }) + public void conversionSelectionNotAllowedInTwoStepBuiltInBuiltInConversion() { + } + + @ProcessorTest + @IssueKey("3186") + @WithClasses({ + ErroneousBuiltInAndMethodMapper.class, + NoConversion.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousBuiltInAndMethodMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 21, + message = "Can't map property \"int time\" to \"Calendar time\". " + + "Consider to declare/implement a mapping method: \"Calendar map(int value)\"." + ) + }) + public void conversionSelectionNotAllowedInTwoStepBuiltInMethodConversion() { + } + + @ProcessorTest + @IssueKey("3186") + @WithClasses({ + ErroneousMethodAndConversionMapper.class, + NoConversion.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMethodAndConversionMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 19, + message = "Can't map property \"Date time\" to \"long time\". " + + "Consider to declare/implement a mapping method: \"long map(Date value)\"." + ) + }) + public void conversionSelectionNotAllowedInTwoStepMethodConversionConversion() { + } + + @ProcessorTest + @IssueKey("3186") + @WithClasses({ + ErroneousConversionAndMethodMapper.class, + NoConversion.class + }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousConversionAndMethodMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 19, + message = "Can't map property \"int time\" to \"Date time\". " + + "Consider to declare/implement a mapping method: \"Date map(int value)\"." + ) + }) + public void conversionSelectionNotAllowedInTwoStepConversionMethodConversion() { + } + private FridgeDTO createFridgeDTO() { FridgeDTO fridgeDTO = new FridgeDTO(); ShelveDTO shelveDTO = new ShelveDTO(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/NoConversion.java b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/NoConversion.java new file mode 100644 index 0000000000..6f05c16bb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/mappingcontrol/NoConversion.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.mappingcontrol; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import org.mapstruct.control.MappingControl; +import org.mapstruct.util.Experimental; + +@Retention(RetentionPolicy.CLASS) +@Experimental +@MappingControl( MappingControl.Use.DIRECT ) +@MappingControl( MappingControl.Use.MAPPING_METHOD ) +@MappingControl( MappingControl.Use.COMPLEX_MAPPING ) +public @interface NoConversion { +} From e69843f46e47332ea6899717e530266b853cee8f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Apr 2023 19:47:08 +0200 Subject: [PATCH 0751/1006] #3158 BeanMapping#ignoreByDefault should work properly for constructor properties --- .../ap/internal/model/BeanMappingMethod.java | 10 ++++- .../ap/test/bugs/_2149/Issue2149Test.java | 6 --- .../ap/test/bugs/_3158/Issue3158Mapper.java | 43 +++++++++++++++++++ .../ap/test/bugs/_3158/Issue3158Test.java | 31 +++++++++++++ 4 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c8fbe0205b..58b4640c95 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -285,7 +285,11 @@ else if ( !method.isUpdateMethod() ) { return null; } - if ( !mappingReferences.isRestrictToDefinedMappings() ) { + boolean applyImplicitMappings = !mappingReferences.isRestrictToDefinedMappings(); + if ( applyImplicitMappings ) { + applyImplicitMappings = beanMapping == null || !beanMapping.isignoreByDefault(); + } + if ( applyImplicitMappings ) { // apply name based mapping from a source reference applyTargetThisMapping(); @@ -1522,6 +1526,10 @@ private ReportingPolicyGem getUnmappedTargetPolicy() { if ( mappingReferences.isForForgedMethods() ) { return ReportingPolicyGem.IGNORE; } + // If we have ignoreByDefault = true, unprocessed target properties are not an issue. + if ( method.getOptions().getBeanMapping().isignoreByDefault() ) { + return ReportingPolicyGem.IGNORE; + } if ( method.getOptions().getBeanMapping() != null ) { return method.getOptions().getBeanMapping().unmappedTargetPolicy(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java index 8c19e2e090..39c415f340 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2149/Issue2149Test.java @@ -30,12 +30,6 @@ public class Issue2149Test { line = 18, message = "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not " + "allowed. You'll need to explicitly ignore the target properties that should be ignored instead." - ), - @Diagnostic( - type = Erroneous2149Mapper.class, - kind = javax.tools.Diagnostic.Kind.WARNING, - line = 20, - message = "Unmapped target property: \"address\"." ) } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Mapper.java new file mode 100644 index 0000000000..25af6b3d44 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Mapper.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3158; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3158Mapper { + + Issue3158Mapper INSTANCE = Mappers.getMapper( Issue3158Mapper.class ); + + @BeanMapping(ignoreByDefault = true) + @Mapping(target = "name") + Target map(Target target); + + class Target { + private final String name; + private final String email; + + public Target(String name, String email) { + this.name = name; + this.email = email; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Test.java new file mode 100644 index 0000000000..e4832edfa9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3158/Issue3158Test.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3158; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3158Mapper.class) +@IssueKey("3158") +class Issue3158Test { + + @ProcessorTest + void beanMappingIgnoreByDefaultShouldBeRespectedForConstructorProperties() { + Issue3158Mapper.Target target = Issue3158Mapper.INSTANCE.map( new Issue3158Mapper.Target( + "tester", + "tester@test.com" + ) ); + + assertThat( target.getName() ).isEqualTo( "tester" ); + assertThat( target.getEmail() ).isNull(); + } +} From 979b35a2f46e75358af7029f0cd1ee7bbf40d8a7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 2 Apr 2023 19:06:45 +0200 Subject: [PATCH 0752/1006] #3153 Do not use compress directive to strip whitespaces for value mapping switch method When using the compress directive it is going to strip whitespaces from the templates as well (i.e. what the user defined in `ValueMapping#source` and / or `ValueMapping#target --- .../ap/internal/model/ValueMappingMethod.ftl | 30 ++++++++--------- .../ap/test/bugs/_3153/Issue3153Mapper.java | 33 +++++++++++++++++++ .../ap/test/bugs/_3153/Issue3153Test.java | 30 +++++++++++++++++ 3 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Test.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl index 016cfcd182..104fd98437 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ValueMappingMethod.ftl @@ -48,26 +48,22 @@ } <#macro writeSource source=""> - <@compress single_line=true> - <#if sourceParameter.type.enumType> - ${source} - <#elseif sourceParameter.type.string> - "${source}" - - + <#if sourceParameter.type.enumType> + ${source}<#t> + <#elseif sourceParameter.type.string> + "${source}"<#t> + <#macro writeTarget target=""> - <@compress single_line=true> - <#if target?has_content> - <#if returnType.enumType> - <@includeModel object=returnType/>.${target} - <#elseif returnType.string> - "${target}" - - <#else> - null + <#if target?has_content> + <#if returnType.enumType> + <@includeModel object=returnType/>.${target}<#t> + <#elseif returnType.string> + "${target}"<#t> - + <#else> + null<#t> + <#macro throws> <#if (thrownTypes?size > 0)><#lt> throws <@compress single_line=true> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Mapper.java new file mode 100644 index 0000000000..af54d23a8d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Mapper.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3153; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ValueMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +interface Issue3153Mapper { + + Issue3153Mapper INSTANCE = Mappers.getMapper( Issue3153Mapper.class ); + + @ValueMapping(source = " PR", target = "PR") + @ValueMapping(source = " PR", target = "PR") + @ValueMapping(source = " PR", target = "PR") + @ValueMapping(source = MappingConstants.ANY_REMAINING, target = MappingConstants.NULL) + Target mapToEnum(String value); + + @ValueMapping(source = "PR", target = " PR") + String mapFromEnum(Target value); + + enum Target { + PR, + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Test.java new file mode 100644 index 0000000000..658a497086 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3153/Issue3153Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3153; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3153Mapper.class) +@IssueKey("3153") +class Issue3153Test { + + @ProcessorTest + void shouldNotTrimStringValueSource() { + assertThat( Issue3153Mapper.INSTANCE.mapToEnum( "PR" ) ).isEqualTo( Issue3153Mapper.Target.PR ); + assertThat( Issue3153Mapper.INSTANCE.mapToEnum( " PR" ) ).isEqualTo( Issue3153Mapper.Target.PR ); + assertThat( Issue3153Mapper.INSTANCE.mapToEnum( " PR" ) ).isEqualTo( Issue3153Mapper.Target.PR ); + assertThat( Issue3153Mapper.INSTANCE.mapToEnum( " PR" ) ).isEqualTo( Issue3153Mapper.Target.PR ); + + assertThat( Issue3153Mapper.INSTANCE.mapFromEnum( Issue3153Mapper.Target.PR ) ).isEqualTo( " PR" ); + } +} From 1bc3436c5c64077503a1656eb8ef516c69d0e3b4 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Apr 2023 22:30:52 +0200 Subject: [PATCH 0753/1006] #3239 Mapping composition is no longer experimental --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index e4a77f5391..8609ac4f77 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -126,7 +126,7 @@ Collection-typed attributes with the same element type will be copied by creatin MapStruct takes all public properties of the source and target types into account. This includes properties declared on super-types. [[mapping-composition]] -=== Mapping Composition (experimental) +=== Mapping Composition MapStruct supports the use of meta annotations. The `@Mapping` annotation supports now `@Target` with `ElementType#ANNOTATION_TYPE` in addition to `ElementType#METHOD`. This allows `@Mapping` to be used on other (user defined) annotations for re-use purposes. For example: ==== @@ -164,7 +164,7 @@ public interface StorageMapper { Still, they do have some properties in common. The `@ToEntity` assumes both target beans `ShelveEntity` and `BoxEntity` have properties: `"id"`, `"creationDate"` and `"name"`. It furthermore assumes that the source beans `ShelveDto` and `BoxDto` always have a property `"groupName"`. This concept is also known as "duck-typing". In other words, if it quacks like duck, walks like a duck its probably a duck. -This feature is still experimental. Error messages are not mature yet: the method on which the problem occurs is displayed, as well as the concerned values in the `@Mapping` annotation. However, the composition aspect is not visible. The messages are "as if" the `@Mapping` would be present on the concerned method directly. +Error messages are not mature yet: the method on which the problem occurs is displayed, as well as the concerned values in the `@Mapping` annotation. However, the composition aspect is not visible. The messages are "as if" the `@Mapping` would be present on the concerned method directly. Therefore, the user should use this feature with care, especially when uncertain when a property is always present. A more typesafe (but also more verbose) way would be to define base classes / interfaces on the target bean and the source bean and use `@InheritConfiguration` to achieve the same result (see <>). From 86a668661a45037adc795f003e6134f89faa3c3c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 22 Apr 2023 23:33:59 +0200 Subject: [PATCH 0754/1006] #3159 Do null value check for collections with default expression --- .../ap/internal/model/PropertyMapping.java | 8 ++- .../ap/test/bugs/_3159/Issue3159Mapper.java | 64 +++++++++++++++++++ .../ap/test/bugs/_3159/Issue3159Test.java | 27 ++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index ad788de43b..7114ccf57b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -510,7 +510,7 @@ private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs, Type targetTyp return true; } - if ( defaultValue != null || defaultJavaExpression != null ) { + if ( hasDefaultValueOrDefaultExpression() ) { // If there is default value defined then a check is needed return true; } @@ -518,6 +518,10 @@ private boolean setterWrapperNeedsSourceNullCheck(Assignment rhs, Type targetTyp return false; } + private boolean hasDefaultValueOrDefaultExpression() { + return defaultValue != null || defaultJavaExpression != null; + } + private Assignment assignToPlainViaAdder( Assignment rightHandSide) { Assignment result = rightHandSide; @@ -555,7 +559,7 @@ private Assignment assignToCollection(Type targetType, AccessorType targetAccess .targetAccessorType( targetAccessorType ) .rightHandSide( rightHandSide ) .assignment( rhs ) - .nullValueCheckStrategy( nvcs ) + .nullValueCheckStrategy( hasDefaultValueOrDefaultExpression() ? ALWAYS : nvcs ) .nullValuePropertyMappingStrategy( nvpms ) .build(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Mapper.java new file mode 100644 index 0000000000..42c77c71dd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Mapper.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3159; + +import java.util.Collection; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3159Mapper { + + Issue3159Mapper INSTANCE = Mappers.getMapper( Issue3159Mapper.class ); + + @Mapping(target = "elements", defaultExpression = "java(new ArrayList<>())") + Target map(Source source); + + default String elementName(Element element) { + return element != null ? element.getName() : null; + } + + class Target { + private final Collection elements; + + public Target(Collection elements) { + this.elements = elements; + } + + public Collection getElements() { + return elements; + } + } + + class Source { + private final Collection elements; + + public Source(Collection elements) { + this.elements = elements; + } + + public Collection getElements() { + return elements; + } + } + + class Element { + private final String name; + + public Element(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Test.java new file mode 100644 index 0000000000..77feba151c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3159/Issue3159Test.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3159; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3159") +@WithClasses(Issue3159Mapper.class) +class Issue3159Test { + + @ProcessorTest + void shouldUseDefaultExpressionForCollection() { + Issue3159Mapper.Target target = Issue3159Mapper.INSTANCE.map( new Issue3159Mapper.Source( null ) ); + + assertThat( target.getElements() ).isEmpty(); + } +} From 1ab5db6a2774a58a6c41b5e4c2bfb23b2fa1bab7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 23 Apr 2023 22:20:05 +0200 Subject: [PATCH 0755/1006] Update latest release version to 1.5.5.Final --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 4e0c2f6ad4..8b8af9a69f 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.3.Final-blue.svg)](https://search.maven.org/search?q=g:org.mapstruct%20AND%20v:1.*.Final) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.5.Final-blue.svg)](https://search.maven.org/search?q=g:org.mapstruct%20AND%20v:1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://search.maven.org/search?q=g:org.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.5.3.Final + 1.5.5.Final ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - implementation 'org.mapstruct:mapstruct:1.5.3.Final' + implementation 'org.mapstruct:mapstruct:1.5.5.Final' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' // if you are using mapstruct in test code } ... ``` From 2f78d3f4e2f493239ed15e6fe2bb85daab4bfed8 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 30 Apr 2023 16:33:00 +0200 Subject: [PATCH 0756/1006] #3125: Allow subclassmapping inheritance for methods with identical signature Co-authored-by: Ben Zegveld --- .../model/source/MappingMethodOptions.java | 36 ++++++++++++++++-- .../model/source/SubclassMappingOptions.java | 17 +++++++++ .../InheritedSubclassMapper.java | 38 +++++++++++++++++++ .../subclassmapping/SubclassMappingTest.java | 20 +++++++++- 4 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InheritedSubclassMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 2124dd974d..73474a8478 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -5,12 +5,15 @@ */ package org.mapstruct.ap.internal.model.source; +import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy; + import java.util.Collections; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; + import javax.lang.model.element.AnnotationMirror; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; @@ -20,8 +23,6 @@ import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.accessor.Accessor; -import static org.mapstruct.ap.internal.model.source.MappingOptions.getMappingTargetNamesBy; - /** * Encapsulates all options specifiable on a mapping method * @@ -205,12 +206,19 @@ public void applyInheritedOptions(SourceMethod sourceMethod, SourceMethod templa } if ( isInverse ) { - // normal inheritence of subclass mappings will result runtime in infinite loops. List inheritedMappings = SubclassMappingOptions.copyForInverseInheritance( templateOptions.getSubclassMappings(), getBeanMapping() ); addAllNonRedefined( sourceMethod, annotationMirror, inheritedMappings ); } + else if ( methodsHaveIdenticalSignature( templateMethod, sourceMethod ) ) { + List inheritedMappings = + SubclassMappingOptions + .copyForInheritance( + templateOptions.getSubclassMappings(), + getBeanMapping() ); + addAllNonRedefined( sourceMethod, annotationMirror, inheritedMappings ); + } Set newMappings = new LinkedHashSet<>(); for ( MappingOptions mapping : templateOptions.getMappings() ) { @@ -232,6 +240,28 @@ public void applyInheritedOptions(SourceMethod sourceMethod, SourceMethod templa } } + private boolean methodsHaveIdenticalSignature(SourceMethod templateMethod, SourceMethod sourceMethod) { + return parametersAreOfIdenticalTypeAndOrder( templateMethod, sourceMethod ) + && resultTypeIsTheSame( templateMethod, sourceMethod ); + } + + private boolean parametersAreOfIdenticalTypeAndOrder(SourceMethod templateMethod, SourceMethod sourceMethod) { + if (templateMethod.getParameters().size() != sourceMethod.getParameters().size()) { + return false; + } + for ( int i = 0; i < templateMethod.getParameters().size(); i++ ) { + if (!templateMethod.getParameters().get( i ).getType().equals( + sourceMethod.getParameters().get( i ).getType() ) ) { + return false; + } + } + return true; + } + + private boolean resultTypeIsTheSame(SourceMethod templateMethod, SourceMethod sourceMethod) { + return templateMethod.getResultType().equals( sourceMethod.getResultType() ); + } + private void addAllNonRedefined(SourceMethod sourceMethod, AnnotationMirror annotationMirror, List inheritedMappings) { Set redefinedSubclassMappings = new HashSet<>( subclassMappings ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java index 11b4b283c2..2b0e6dd13e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SubclassMappingOptions.java @@ -202,6 +202,23 @@ public static List copyForInverseInheritance(Set copyForInheritance(Set subclassMappings, + BeanMappingOptions beanMappingOptions) { + // we are not interested in keeping it unique at this point. + List mappings = new ArrayList<>(); + for ( SubclassMappingOptions subclassMapping : subclassMappings ) { + mappings.add( + new SubclassMappingOptions( + subclassMapping.source, + subclassMapping.target, + subclassMapping.typeUtils, + beanMappingOptions, + subclassMapping.selectionParameters, + subclassMapping.subclassMapping ) ); + } + return mappings; + } + @Override public boolean equals(Object obj) { if ( obj == null || !( obj instanceof SubclassMappingOptions ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InheritedSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InheritedSubclassMapper.java new file mode 100644 index 0000000000..6e4aca98ba --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/InheritedSubclassMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.HatchBack; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper( unmappedTargetPolicy = ReportingPolicy.IGNORE ) +public interface InheritedSubclassMapper { + InheritedSubclassMapper INSTANCE = Mappers.getMapper( InheritedSubclassMapper.class ); + + @SubclassMapping( source = HatchBack.class, target = CarDto.class ) + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker" ) + VehicleDto map(Vehicle vehicle); + + @InheritConfiguration( name = "map" ) + VehicleDto mapInherited(Vehicle dto); + + @SubclassMapping( source = Bike.class, target = CarDto.class ) + @InheritConfiguration( name = "map" ) + VehicleDto mapInheritedOverride(Vehicle dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java index 5a5ce1ef99..ba64d2cc7f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -130,7 +130,7 @@ void subclassMappingInheritsInverseMapping() { HatchBack.class, InverseOrderSubclassMapper.class } ) - void subclassMappingOverridesInverseInheritsMapping() { + void subclassMappingOverridesInverseInheritedMapping() { VehicleCollectionDto vehicleDtos = new VehicleCollectionDto(); CarDto carDto = new CarDto(); carDto.setMaker( "BenZ" ); @@ -143,6 +143,24 @@ void subclassMappingOverridesInverseInheritsMapping() { .containsExactly( Car.class ); } + @IssueKey( "3125" ) + @ProcessorTest + @WithClasses( { + HatchBack.class, + InheritedSubclassMapper.class + } ) + void subclassMappingOverridesInheritedMapping() { + Vehicle bike = new Bike(); + + VehicleDto result = InheritedSubclassMapper.INSTANCE.map( bike ); + VehicleDto resultInherited = InheritedSubclassMapper.INSTANCE.mapInherited( bike ); + VehicleDto resultOverride = InheritedSubclassMapper.INSTANCE.mapInheritedOverride( bike ); + + assertThat( result ).isInstanceOf( BikeDto.class ); + assertThat( resultInherited ).isInstanceOf( BikeDto.class ); + assertThat( resultOverride ).isInstanceOf( CarDto.class ); + } + @ProcessorTest @WithClasses( { SubclassCompositeMapper.class, CompositeSubclassMappingAnnotation.class }) void mappingIsDoneUsingSubclassMappingWithCompositeMapping() { From 931591a385a352795090a8bf9db96778d9325a3b Mon Sep 17 00:00:00 2001 From: ro0sterjam Date: Sun, 30 Apr 2023 11:02:39 -0400 Subject: [PATCH 0757/1006] #3071 Support defining custom processor options by custom SPI --- .../chapter-13-using-mapstruct-spi.asciidoc | 51 +++++++++++ .../org/mapstruct/ap/MappingProcessor.java | 84 ++++++++++++++++++- .../util/AnnotationProcessorContext.java | 9 +- .../mapstruct/ap/internal/util/Services.java | 4 + .../AdditionalSupportedOptionsProvider.java | 23 +++++ .../spi/MapStructProcessingEnvironment.java | 9 ++ ...dditionalSupportedOptionsProviderTest.java | 56 +++++++++++++ ...tomAdditionalSupportedOptionsProvider.java | 22 +++++ .../EmptyMapper.java | 12 +++ ...lidAdditionalSupportedOptionsProvider.java | 20 +++++ .../test/additionalsupportedoptions/Pet.java | 14 ++++ .../PetWithMissing.java | 15 ++++ .../UnknownEnumMappingStrategy.java | 29 +++++++ .../UnknownEnumMappingStrategyMapper.java | 17 ++++ 14 files changed, 361 insertions(+), 4 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/spi/AdditionalSupportedOptionsProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/AdditionalSupportedOptionsProviderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/CustomAdditionalSupportedOptionsProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/EmptyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/InvalidAdditionalSupportedOptionsProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/Pet.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/PetWithMissing.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategyMapper.java diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index 1095d41656..ce9b288428 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -370,4 +370,55 @@ A nice example is to provide support for a custom transformation strategy. ---- include::{processor-ap-test}/value/nametransformation/CustomEnumTransformationStrategy.java[tag=documentation] ---- +==== + +[[additional-supported-options-provider]] +=== Additional Supported Options Provider + +SPI name: `org.mapstruct.ap.spi.AdditionalSupportedOptionsProvider` + +MapStruct offers the ability to pass through declared compiler args (or "options") provided to the MappingProcessor +to the individual SPIs, by implementing `AdditionalSupportedOptionsProvider` via the Service Provider Interface (SPI). + +.Custom Additional Supported Options Provider that declares `myorg.custom.defaultNullEnumConstant` as an option to pass through +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/additionalsupportedoptions/CustomAdditionalSupportedOptionsProvider.java[tag=documentation] +---- +==== + +The value of this option is provided by including an `arg` to the `compilerArgs` tag when defining your custom SPI +implementation. + +.Example maven configuration with additional options +==== +[source, maven, linenums] +[subs="verbatim,attributes"] +---- + + + + org.myorg + custom-spi-impl + ${project.version} + + + + -Amyorg.custom.defaultNullEnumConstant=MISSING + + +---- +==== + +Your custom SPI implementations can then access this configured value via `MapStructProcessingEnvironment#getOptions()`. + +.Accessing your custom options +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +include::{processor-ap-test}/additionalsupportedoptions/UnknownEnumMappingStrategy.java[tag=documentation] +---- ==== \ No newline at end of file diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 8c842f007b..407166f6fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -8,6 +8,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; @@ -33,17 +34,19 @@ import javax.lang.model.util.ElementKindVisitor6; import javax.tools.Diagnostic.Kind; +import org.mapstruct.ap.internal.gem.MapperGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.gem.MapperGem; -import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext; import org.mapstruct.ap.internal.processor.ModelElementProcessor; import org.mapstruct.ap.internal.processor.ModelElementProcessor.ProcessorContext; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.AnnotationProcessorContext; import org.mapstruct.ap.internal.util.RoundContext; +import org.mapstruct.ap.internal.util.Services; +import org.mapstruct.ap.spi.AdditionalSupportedOptionsProvider; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; import static javax.lang.model.element.ElementKind.CLASS; @@ -113,6 +116,9 @@ public class MappingProcessor extends AbstractProcessor { protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY = "mapstruct.nullValueIterableMappingStrategy"; protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY = "mapstruct.nullValueMapMappingStrategy"; + private final Set additionalSupportedOptions; + private final String additionalSupportedOptionsError; + private Options options; private AnnotationProcessorContext annotationProcessorContext; @@ -128,6 +134,21 @@ public class MappingProcessor extends AbstractProcessor { */ private Set deferredMappers = new HashSet<>(); + public MappingProcessor() { + Set additionalSupportedOptions; + String additionalSupportedOptionsError; + try { + additionalSupportedOptions = resolveAdditionalSupportedOptions(); + additionalSupportedOptionsError = null; + } + catch ( IllegalStateException ex ) { + additionalSupportedOptions = Collections.emptySet(); + additionalSupportedOptionsError = ex.getMessage(); + } + this.additionalSupportedOptions = additionalSupportedOptions; + this.additionalSupportedOptionsError = additionalSupportedOptionsError; + } + @Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init( processingEnv ); @@ -138,8 +159,13 @@ public synchronized void init(ProcessingEnvironment processingEnv) { processingEnv.getTypeUtils(), processingEnv.getMessager(), options.isDisableBuilders(), - options.isVerbose() + options.isVerbose(), + resolveAdditionalOptions( processingEnv.getOptions() ) ); + + if ( additionalSupportedOptionsError != null ) { + processingEnv.getMessager().printMessage( Kind.ERROR, additionalSupportedOptionsError ); + } } private Options createOptions() { @@ -225,6 +251,17 @@ else if ( !deferredMappers.isEmpty() ) { return ANNOTATIONS_CLAIMED_EXCLUSIVELY; } + @Override + public Set getSupportedOptions() { + Set supportedOptions = super.getSupportedOptions(); + if ( additionalSupportedOptions.isEmpty() ) { + return supportedOptions; + } + Set allSupportedOptions = new HashSet<>( supportedOptions ); + allSupportedOptions.addAll( additionalSupportedOptions ); + return allSupportedOptions; + } + /** * Gets fresh copies of all mappers deferred from previous rounds (the originals may contain references to * erroneous source/target type elements). @@ -407,6 +444,35 @@ public TypeElement visitTypeAsClass(TypeElement e, Void p) { ); } + /** + * Fetch the additional supported options provided by the SPI {@link AdditionalSupportedOptionsProvider}. + * + * @return the additional supported options + */ + private static Set resolveAdditionalSupportedOptions() { + Set additionalSupportedOptions = null; + for ( AdditionalSupportedOptionsProvider optionsProvider : + Services.all( AdditionalSupportedOptionsProvider.class ) ) { + if ( additionalSupportedOptions == null ) { + additionalSupportedOptions = new HashSet<>(); + } + Set providerOptions = optionsProvider.getAdditionalSupportedOptions(); + + for ( String providerOption : providerOptions ) { + // Ensure additional options are not in the mapstruct namespace + if ( providerOption.startsWith( "mapstruct" ) ) { + throw new IllegalStateException( + "Additional SPI options cannot start with \"mapstruct\". Provider " + optionsProvider + + " provided option " + providerOption ); + } + additionalSupportedOptions.add( providerOption ); + } + + } + + return additionalSupportedOptions == null ? Collections.emptySet() : additionalSupportedOptions; + } + private static class ProcessorComparator implements Comparator> { @Override @@ -425,4 +491,16 @@ private DeferredMapper(TypeElement deferredMapperElement, Element erroneousEleme this.erroneousElement = erroneousElement; } } + + /** + * Filters only the options belonging to the declared additional supported options. + * + * @param options all processor environment options + * @return filtered options + */ + private Map resolveAdditionalOptions(Map options) { + return options.entrySet().stream() + .filter( entry -> additionalSupportedOptions.contains( entry.getKey() ) ) + .collect( Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue ) ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java index 7421dfde7a..81640848d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AnnotationProcessorContext.java @@ -55,8 +55,10 @@ public class AnnotationProcessorContext implements MapStructProcessingEnvironmen private boolean disableBuilder; private boolean verbose; + private Map options; + public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messager messager, boolean disableBuilder, - boolean verbose) { + boolean verbose, Map options) { astModifyingAnnotationProcessors = java.util.Collections.unmodifiableList( findAstModifyingAnnotationProcessors( messager ) ); this.elementUtils = elementUtils; @@ -64,6 +66,7 @@ public AnnotationProcessorContext(Elements elementUtils, Types typeUtils, Messag this.messager = messager; this.disableBuilder = disableBuilder; this.verbose = verbose; + this.options = java.util.Collections.unmodifiableMap( options ); } /** @@ -270,4 +273,8 @@ public Map getEnumTransformationStrategies() initialize(); return enumTransformationStrategies; } + + public Map getOptions() { + return this.options; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java index 2d37c46db8..292512ff80 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Services.java @@ -18,6 +18,10 @@ public class Services { private Services() { } + public static Iterable all(Class serviceType) { + return ServiceLoader.load( serviceType, Services.class.getClassLoader() ); + } + public static T get(Class serviceType, T defaultValue) { Iterator services = ServiceLoader.load( serviceType, Services.class.getClassLoader() ).iterator(); diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AdditionalSupportedOptionsProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/AdditionalSupportedOptionsProvider.java new file mode 100644 index 0000000000..3638f70320 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/spi/AdditionalSupportedOptionsProvider.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.spi; + +import java.util.Set; + +/** + * Provider for any additional supported options required for custom SPI implementations. + * The resolved values are retrieved from {@link MapStructProcessingEnvironment#getOptions()}. + */ +public interface AdditionalSupportedOptionsProvider { + + /** + * Returns the supported options required for custom SPI implementations. + * + * @return the additional supported options. + */ + Set getAdditionalSupportedOptions(); + +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java index 0471108a51..0cea4369eb 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MapStructProcessingEnvironment.java @@ -7,6 +7,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; +import java.util.Map; /** * MapStruct will provide the implementations of its SPIs with on object implementing this interface so they can use @@ -36,4 +37,12 @@ public interface MapStructProcessingEnvironment { */ Types getTypeUtils(); + /** + * Returns the resolved options specified by the impl of + * {@link AdditionalSupportedOptionsProvider}. + * + * @return resolved options + */ + Map getOptions(); + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/AdditionalSupportedOptionsProviderTest.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/AdditionalSupportedOptionsProviderTest.java new file mode 100644 index 0000000000..ff2c85139f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/AdditionalSupportedOptionsProviderTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.mapstruct.ap.spi.EnumMappingStrategy; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; +import org.mapstruct.ap.testutil.runner.Compiler; + +import static org.assertj.core.api.Assertions.assertThat; + +@Execution( ExecutionMode.CONCURRENT ) +public class AdditionalSupportedOptionsProviderTest { + + @ProcessorTest + @WithClasses({ + Pet.class, + PetWithMissing.class, + UnknownEnumMappingStrategyMapper.class + }) + @WithServiceImplementation(CustomAdditionalSupportedOptionsProvider.class) + @WithServiceImplementation(value = UnknownEnumMappingStrategy.class, provides = EnumMappingStrategy.class) + @ProcessorOption(name = "myorg.custom.defaultNullEnumConstant", value = "MISSING") + public void shouldUseConfiguredPrefix() { + assertThat( UnknownEnumMappingStrategyMapper.INSTANCE.map( null ) ) + .isEqualTo( PetWithMissing.MISSING ); + } + + @ProcessorTest(Compiler.JDK) // The eclipse compiler does not parse the error message properly + @WithClasses({ + EmptyMapper.class + }) + @WithServiceImplementation(InvalidAdditionalSupportedOptionsProvider.class) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + messageRegExp = "Additional SPI options cannot start with \"mapstruct\". Provider " + + "org.mapstruct.ap.test.additionalsupportedoptions.InvalidAdditionalSupportedOptionsProvider@.*" + + " provided option mapstruct.custom.test" + ) + ) + public void shouldFailWhenOptionsProviderUsesMapstructPrefix() { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/CustomAdditionalSupportedOptionsProvider.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/CustomAdditionalSupportedOptionsProvider.java new file mode 100644 index 0000000000..87a994bb4e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/CustomAdditionalSupportedOptionsProvider.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +// tag::documentation[] +import java.util.Collections; +import java.util.Set; + +import org.mapstruct.ap.spi.AdditionalSupportedOptionsProvider; + +public class CustomAdditionalSupportedOptionsProvider implements AdditionalSupportedOptionsProvider { + + @Override + public Set getAdditionalSupportedOptions() { + return Collections.singleton( "myorg.custom.defaultNullEnumConstant" ); + } + +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/EmptyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/EmptyMapper.java new file mode 100644 index 0000000000..13a6f0aece --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/EmptyMapper.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +import org.mapstruct.Mapper; + +@Mapper +public interface EmptyMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/InvalidAdditionalSupportedOptionsProvider.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/InvalidAdditionalSupportedOptionsProvider.java new file mode 100644 index 0000000000..1a387abba2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/InvalidAdditionalSupportedOptionsProvider.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +import java.util.Collections; +import java.util.Set; + +import org.mapstruct.ap.spi.AdditionalSupportedOptionsProvider; + +public class InvalidAdditionalSupportedOptionsProvider implements AdditionalSupportedOptionsProvider { + + @Override + public Set getAdditionalSupportedOptions() { + return Collections.singleton( "mapstruct.custom.test" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/Pet.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/Pet.java new file mode 100644 index 0000000000..8fe9b39558 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/Pet.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +public enum Pet { + + DOG, + CAT, + BEAR + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/PetWithMissing.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/PetWithMissing.java new file mode 100644 index 0000000000..21d5f4a649 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/PetWithMissing.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +public enum PetWithMissing { + + DOG, + CAT, + BEAR, + MISSING + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategy.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategy.java new file mode 100644 index 0000000000..ca4403925e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategy.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +// tag::documentation[] +import javax.lang.model.element.TypeElement; + +import org.mapstruct.ap.spi.DefaultEnumMappingStrategy; +import org.mapstruct.ap.spi.MapStructProcessingEnvironment; + +public class UnknownEnumMappingStrategy extends DefaultEnumMappingStrategy { + + private String defaultNullEnumConstant; + + @Override + public void init(MapStructProcessingEnvironment processingEnvironment) { + super.init( processingEnvironment ); + defaultNullEnumConstant = processingEnvironment.getOptions().get( "myorg.custom.defaultNullEnumConstant" ); + } + + @Override + public String getDefaultNullEnumConstant(TypeElement enumType) { + return defaultNullEnumConstant; + } +} +// end::documentation[] diff --git a/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategyMapper.java new file mode 100644 index 0000000000..be8c74e227 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/additionalsupportedoptions/UnknownEnumMappingStrategyMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.additionalsupportedoptions; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface UnknownEnumMappingStrategyMapper { + + UnknownEnumMappingStrategyMapper INSTANCE = Mappers.getMapper( UnknownEnumMappingStrategyMapper.class ); + + PetWithMissing map(Pet pet); +} From d3b4a168b7abef6c31fea4f3506996ffe23ad718 Mon Sep 17 00:00:00 2001 From: Bragolgirith Date: Mon, 1 May 2023 09:11:05 +0200 Subject: [PATCH 0758/1006] #3199 Add support for implicit conversion between java.time.LocalDate and java.time.LocalDateTime --- .../chapter-5-data-type-conversions.asciidoc | 2 + .../internal/conversion/ConversionUtils.java | 12 +++++ .../ap/internal/conversion/Conversions.java | 5 +- ...avaLocalDateTimeToLocalDateConversion.java | 46 +++++++++++++++++++ .../java8time/Java8TimeConversionTest.java | 15 ++++++ .../ap/test/conversion/java8time/Source.java | 10 ++++ .../ap/test/conversion/java8time/Target.java | 11 +++++ .../java8time/SourceTargetMapperImpl.java | 36 +++++++++++++++ 8 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 51ccb21a46..258c7085f2 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -107,6 +107,8 @@ public interface CarMapper { * Between `java.time.Instant` from Java 8 Date-Time package and `java.util.Date`. +* Between `java.time.LocalDateTime` from Java 8 Date-Time package and `java.time.LocalDate` from the same package. + * Between `java.time.ZonedDateTime` from Java 8 Date-Time package and `java.util.Calendar`. * Between `java.sql.Date` and `java.util.Date` diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index e88bb93b86..496d11676f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -12,6 +12,7 @@ import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; @@ -190,6 +191,17 @@ public static String zoneId(ConversionContext conversionContext) { return typeReferenceName( conversionContext, ZoneId.class ); } + /** + * Name for {@link java.time.LocalDate}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String localDate(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, LocalDate.class ); + } + /** * Name for {@link java.time.LocalDateTime}. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index e947c78571..9a4085df83 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -233,12 +233,15 @@ private void registerJava8TimeConversions() { register( Period.class, String.class, new StaticParseToStringConversion() ); register( Duration.class, String.class, new StaticParseToStringConversion() ); - // Java 8 to Date + // Java 8 time to Date register( ZonedDateTime.class, Date.class, new JavaZonedDateTimeToDateConversion() ); register( LocalDateTime.class, Date.class, new JavaLocalDateTimeToDateConversion() ); register( LocalDate.class, Date.class, new JavaLocalDateToDateConversion() ); register( Instant.class, Date.class, new JavaInstantToDateConversion() ); + // Java 8 time + register( LocalDateTime.class, LocalDate.class, new JavaLocalDateTimeToLocalDateConversion() ); + } private void registerJavaTimeSqlConversions() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java new file mode 100644 index 0000000000..ae571ad6b0 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +/** + * SimpleConversion for mapping {@link LocalDateTime} to + * {@link LocalDate} and vice versa. + */ + +public class JavaLocalDateTimeToLocalDateConversion extends SimpleConversion { + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toLocalDate()"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( LocalDate.class ) + ); + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return ".atStartOfDay()"; + } + + @Override + protected Set getFromConversionImportTypes(ConversionContext conversionContext) { + return Collections.asSet( + conversionContext.getTypeFactory().getType( LocalDateTime.class ) + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java index aa30865425..0059630532 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8TimeConversionTest.java @@ -252,6 +252,21 @@ public void testInstantToDateMapping() { assertThat( source.getForDateConversionWithInstant() ).isEqualTo( instant ); } + @ProcessorTest + public void testLocalDateTimeToLocalDateMapping() { + LocalDate localDate = LocalDate.of( 2014, 1, 1 ); + + Source source = new Source(); + source.setForLocalDateTimeConversionWithLocalDate( localDate ); + Target target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + LocalDateTime localDateTime = target.getForLocalDateTimeConversionWithLocalDate(); + assertThat( localDateTime ).isNotNull(); + assertThat( localDateTime ).isEqualTo( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ); + + source = SourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForLocalDateTimeConversionWithLocalDate() ).isEqualTo( localDate ); + } + @ProcessorTest @DefaultTimeZone("Australia/Melbourne") public void testLocalDateTimeToDateMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java index 91298617cd..93479f8a86 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Source.java @@ -38,6 +38,8 @@ public class Source { private Instant forDateConversionWithInstant; + private LocalDate forLocalDateTimeConversionWithLocalDate; + private Instant forInstantConversionWithString; private Period forPeriodConversionWithString; @@ -124,6 +126,14 @@ public void setForDateConversionWithInstant(Instant forDateConversionWithInstant this.forDateConversionWithInstant = forDateConversionWithInstant; } + public LocalDate getForLocalDateTimeConversionWithLocalDate() { + return forLocalDateTimeConversionWithLocalDate; + } + + public void setForLocalDateTimeConversionWithLocalDate(LocalDate forLocalDateTimeConversionWithLocalDate) { + this.forLocalDateTimeConversionWithLocalDate = forLocalDateTimeConversionWithLocalDate; + } + public Instant getForInstantConversionWithString() { return forInstantConversionWithString; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java index 188a6d0e20..d2a4878731 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Target.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.conversion.java8time; +import java.time.LocalDateTime; import java.util.Calendar; import java.util.Date; @@ -33,6 +34,8 @@ public class Target { private Date forDateConversionWithInstant; + private LocalDateTime forLocalDateTimeConversionWithLocalDate; + private String forInstantConversionWithString; private String forPeriodConversionWithString; @@ -119,6 +122,14 @@ public void setForDateConversionWithInstant(Date forDateConversionWithInstant) { this.forDateConversionWithInstant = forDateConversionWithInstant; } + public LocalDateTime getForLocalDateTimeConversionWithLocalDate() { + return forLocalDateTimeConversionWithLocalDate; + } + + public void setForLocalDateTimeConversionWithLocalDate(LocalDateTime forLocalDateTimeConversionWithLocalDate) { + this.forLocalDateTimeConversionWithLocalDate = forLocalDateTimeConversionWithLocalDate; + } + public String getForInstantConversionWithString() { return forInstantConversionWithString; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java index 58beaa19dd..3e0f5f84fe 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapperImpl.java @@ -68,6 +68,9 @@ public Target sourceToTarget(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -117,6 +120,9 @@ public Target sourceToTargetDefaultMapping(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -166,6 +172,9 @@ public Target sourceToTargetDateTimeMapped(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -215,6 +224,9 @@ public Target sourceToTargetLocalDateTimeMapped(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -264,6 +276,9 @@ public Target sourceToTargetLocalDateMapped(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -313,6 +328,9 @@ public Target sourceToTargetLocalTimeMapped(Source source) { if ( source.getForDateConversionWithInstant() != null ) { target.setForDateConversionWithInstant( Date.from( source.getForDateConversionWithInstant() ) ); } + if ( source.getForLocalDateTimeConversionWithLocalDate() != null ) { + target.setForLocalDateTimeConversionWithLocalDate( source.getForLocalDateTimeConversionWithLocalDate().atStartOfDay() ); + } if ( source.getForInstantConversionWithString() != null ) { target.setForInstantConversionWithString( source.getForInstantConversionWithString().toString() ); } @@ -362,6 +380,9 @@ public Source targetToSource(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } @@ -411,6 +432,9 @@ public Source targetToSourceDateTimeMapped(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } @@ -460,6 +484,9 @@ public Source targetToSourceLocalDateTimeMapped(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } @@ -509,6 +536,9 @@ public Source targetToSourceLocalDateMapped(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } @@ -558,6 +588,9 @@ public Source targetToSourceLocalTimeMapped(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } @@ -607,6 +640,9 @@ public Source targetToSourceDefaultMapping(Target target) { if ( target.getForDateConversionWithInstant() != null ) { source.setForDateConversionWithInstant( target.getForDateConversionWithInstant().toInstant() ); } + if ( target.getForLocalDateTimeConversionWithLocalDate() != null ) { + source.setForLocalDateTimeConversionWithLocalDate( target.getForLocalDateTimeConversionWithLocalDate().toLocalDate() ); + } if ( target.getForInstantConversionWithString() != null ) { source.setForInstantConversionWithString( Instant.parse( target.getForInstantConversionWithString() ) ); } From 970984785d5d2714fc398255c5938ee539a0d8c0 Mon Sep 17 00:00:00 2001 From: todzhang's cloudsdocker Date: Mon, 1 May 2023 17:12:23 +1000 Subject: [PATCH 0759/1006] Update one typo in JavaDoc (#2938) --- core/src/main/java/org/mapstruct/Mapping.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 92ae29eb54..42384152d0 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -287,7 +287,7 @@ /** * Whether the property specified via {@link #target()} should be ignored by the generated mapping method or not. - * This can be useful when certain attributes should not be propagated from source or target or when properties in + * This can be useful when certain attributes should not be propagated from source to target or when properties in * the target object are populated using a decorator and thus would be reported as unmapped target property by * default. * From a8df94cc2049099dce5f42ead520965da563e9b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Campanero=20Ortiz?= Date: Mon, 1 May 2023 09:22:59 +0200 Subject: [PATCH 0760/1006] #2987 Support for defining Javadoc in the generated mapper implementation --- core/src/main/java/org/mapstruct/Javadoc.java | 115 ++++++++++++++++++ core/src/main/java/org/mapstruct/Mapper.java | 1 + .../chapter-3-defining-a-mapper.asciidoc | 100 +++++++++++++++ .../ap/internal/gem/GemGenerator.java | 2 + .../ap/internal/model/GeneratedType.java | 4 + .../mapstruct/ap/internal/model/Javadoc.java | 92 ++++++++++++++ .../mapstruct/ap/internal/model/Mapper.java | 19 ++- .../processor/MapperCreationProcessor.java | 31 +++++ .../mapstruct/ap/internal/util/Message.java | 2 + .../ap/internal/model/GeneratedType.ftl | 1 + .../mapstruct/ap/internal/model/Javadoc.ftl | 25 ++++ .../test/javadoc/ErroneousJavadocMapper.java | 17 +++ .../JavadocAnnotatedWithAttributesMapper.java | 21 ++++ .../JavadocAnnotatedWithValueMapper.java | 22 ++++ .../ap/test/javadoc/JavadocTest.java | 54 ++++++++ ...adocAnnotatedWithAttributesMapperImpl.java | 27 ++++ .../JavadocAnnotatedWithValueMapperImpl.java | 27 ++++ 17 files changed, 558 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/Javadoc.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/Javadoc.java b/core/src/main/java/org/mapstruct/Javadoc.java new file mode 100644 index 0000000000..4b5d2fb839 --- /dev/null +++ b/core/src/main/java/org/mapstruct/Javadoc.java @@ -0,0 +1,115 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Allows the definition of Javadoc comments in the MapStruct Mapper generated class. + * + *

      The annotation provides support for the usual Javadoc comments elements by defining analogous attributes.

      + * + * + *

      Please, note that at least one of these attributes must be specified.

      + * + *

      + * For instance, the following definition; + *

      + *
      
      + * @Javadoc(
      + *     value = "This is the description",
      + *     authors = { "author1", "author2" },
      + *     deprecated = "Use {@link OtherMapper} instead",
      + *     since = "0.1"
      + * )
      + * 
      + * + *

      + * will generate: + *

      + * + *
      
      + * /**
      + * * This is the description
      + * *
      + * * @author author1
      + * * @author author2
      + * *
      + * * @deprecated Use {@link OtherMapper} instead
      + * * @since 0.1
      + * */
      + * 
      + * + *

      + * The entire Javadoc comment block can be passed directly: + *

      + *
      
      + * @Javadoc("This is the description\n"
      + *            + "\n"
      + *            + "@author author1\n"
      + *            + "@author author2\n"
      + *            + "\n"
      + *            + "@deprecated Use {@link OtherMapper} instead\n"
      + *            + "@since 0.1\n"
      + * )
      + * 
      + * + *
      
      + * // or using Text Blocks
      + * @Javadoc(
      + *     """
      + *     This is the description
      + *
      + *     @author author1
      + *     @author author2
      + *
      + *     @deprecated Use {@link OtherMapper} instead
      + *     @since 0.1
      + *     """
      + * )
      + * 
      + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Javadoc { + /** + * Main Javadoc comment text block. + * + * @return Main Javadoc comment text block. + */ + String value() default ""; + + /** + * List of authors of the code that it is being documented. + *

      + * It will generate a list of the Javadoc tool comment element @author + * with the different values and in the order provided. + * + * @return array of javadoc authors. + */ + String[] authors() default { }; + + /** + * Specifies that the functionality that is being documented is deprecated. + *

      + * Corresponds to the @deprecated Javadoc tool comment element. + * + * @return Deprecation message about the documented functionality + */ + String deprecated() default ""; + + /** + * Specifies the version since the functionality that is being documented is available. + *

      + * Corresponds to the @since Javadoc tool comment element. + * + * @return Version since the functionality is available + */ + String since() default ""; +} diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 60725cc441..8a6f48dad9 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -74,6 +74,7 @@ *

      * * @author Gunnar Morling + * @see Javadoc */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 8609ac4f77..eb3d5a80ec 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -761,3 +761,103 @@ public class MyConverterImpl implements MyConverter { } ---- ==== + + +[[javadoc]] +=== Adding Javadoc comments + +MapStruct provides support for defining Javadoc comments in the generated mapper implementation using the +`org.mapstruct.Javadoc` annotation. + +This functionality could be relevant especially in situations where certain Javadoc standards need to be met or +to deal with Javadoc validation constraints. + +The `@Javadoc` annotation defines attributes for the different Javadoc elements. + +Consider the following example: + +.Javadoc annotation example +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +@Javadoc( + value = "This is the description", + authors = { "author1", "author2" }, + deprecated = "Use {@link OtherMapper} instead", + since = "0.1" +) +public interface MyAnnotatedWithJavadocMapper { + //... +} +---- +==== + +.Javadoc annotated generated mapper +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +/** +* This is the description +* +* @author author1 +* @author author2 +* +* @deprecated Use {@link OtherMapper} instead +* @since 0.1 +*/ +public class MyAnnotatedWithJavadocMapperImpl implements MyAnnotatedWithJavadocMapper { + //... +} +---- +==== + +The entire Javadoc comment block can be provided directly as well. + +.Javadoc annotation example with the entire Javadoc comment block provided directly +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +@Javadoc( + "This is the description\n" + + "\n" + + "@author author1\n" + + "@author author2\n" + + "\n" + + "@deprecated Use {@link OtherMapper} instead\n" + + "@since 0.1\n" +) +public interface MyAnnotatedWithJavadocMapper { + //... +} +---- +==== + +Or using Text blocks: + +.Javadoc annotation example with the entire Javadoc comment block provided directly using Text blocks +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +@Javadoc( + """ + This is the description + + @author author1 + @author author2 + + @deprecated Use {@link OtherMapper} instead + @since 0.1 + """ +) +public interface MyAnnotatedWithJavadocMapper { + //... +} +---- +==== \ No newline at end of file diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 5caea8a008..9ac13184cd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -21,6 +21,7 @@ import org.mapstruct.InheritConfiguration; import org.mapstruct.InheritInverseConfiguration; import org.mapstruct.IterableMapping; +import org.mapstruct.Javadoc; import org.mapstruct.MapMapping; import org.mapstruct.Mapper; import org.mapstruct.MapperConfig; @@ -75,6 +76,7 @@ @GemDefinition(Context.class) @GemDefinition(Builder.class) @GemDefinition(Condition.class) +@GemDefinition(Javadoc.class) @GemDefinition(MappingControl.class) @GemDefinition(MappingControls.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index df6ed9b2b1..8348ecd84b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -253,6 +253,10 @@ public void removeConstructor() { constructor = null; } + public Javadoc getJavadoc() { + return null; + } + protected void addIfImportRequired(Collection collection, Type typeToAdd) { if ( typeToAdd == null ) { return; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java new file mode 100644 index 0000000000..a1efc8c022 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java @@ -0,0 +1,92 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.Type; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * Represents the javadoc information that should be generated for a {@link Mapper}. + * + * @author Jose Carlos Campanero Ortiz + */ +public class Javadoc extends ModelElement { + + public static class Builder { + + private String value; + private List authors; + private String deprecated; + private String since; + + public Builder value(String value) { + this.value = value; + return this; + } + + public Builder authors(List authors) { + this.authors = authors; + return this; + } + + public Builder deprecated(String deprecated) { + this.deprecated = deprecated; + return this; + } + + public Builder since(String since) { + this.since = since; + return this; + } + + public Javadoc build() { + return new Javadoc( + value, + authors, + deprecated, + since + ); + } + } + + private final String value; + private final List authors; + private final String deprecated; + private final String since; + + private Javadoc(String value, List authors, String deprecated, String since) { + this.value = value; + this.authors = authors != null ? Collections.unmodifiableList( authors ) : Collections.emptyList(); + this.deprecated = deprecated; + this.since = since; + } + + public String getValue() { + return value; + } + + public List getAuthors() { + return authors; + } + + public String getDeprecated() { + return deprecated; + } + + public String getSince() { + return since; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index 9b7729e8fa..cd092ca4f4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -43,6 +43,7 @@ public static class Builder extends GeneratedTypeBuilder { private boolean customPackage; private boolean suppressGeneratorTimestamp; private Set customAnnotations; + private Javadoc javadoc; public Builder() { super( Builder.class ); @@ -90,6 +91,11 @@ public Builder suppressGeneratorTimestamp(boolean suppressGeneratorTimestamp) { return this; } + public Builder javadoc(Javadoc javadoc) { + this.javadoc = javadoc; + return this; + } + public Mapper build() { String implementationName = implName.replace( CLASS_NAME_PLACEHOLDER, getFlatName( element ) ) + ( decorator == null ? "" : "_" ); @@ -119,7 +125,8 @@ public Mapper build() { fields, constructor, decorator, - extraImportedTypes + extraImportedTypes, + javadoc ); } @@ -128,6 +135,7 @@ public Mapper build() { private final boolean customPackage; private final boolean customImplName; private Decorator decorator; + private final Javadoc javadoc; @SuppressWarnings( "checkstyle:parameternumber" ) private Mapper(TypeFactory typeFactory, String packageName, String name, @@ -136,7 +144,7 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, List methods, Options options, VersionInformation versionInformation, boolean suppressGeneratorTimestamp, Accessibility accessibility, List fields, Constructor constructor, - Decorator decorator, SortedSet extraImportedTypes ) { + Decorator decorator, SortedSet extraImportedTypes, Javadoc javadoc ) { super( typeFactory, @@ -157,6 +165,8 @@ private Mapper(TypeFactory typeFactory, String packageName, String name, customAnnotations.forEach( this::addAnnotation ); this.decorator = decorator; + + this.javadoc = javadoc; } public Decorator getDecorator() { @@ -171,6 +181,11 @@ public boolean hasCustomImplementation() { return customImplName || customPackage; } + @Override + public Javadoc getJavadoc() { + return javadoc; + } + @Override protected String getTemplateName() { return getTemplateNameForClass( GeneratedType.class ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index b69ba388b0..24dd528f6b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -28,6 +28,7 @@ import org.mapstruct.ap.internal.gem.DecoratedWithGem; import org.mapstruct.ap.internal.gem.InheritConfigurationGem; import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem; +import org.mapstruct.ap.internal.gem.JavadocGem; import org.mapstruct.ap.internal.gem.MapperGem; import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; @@ -40,6 +41,7 @@ import org.mapstruct.ap.internal.model.DelegatingMethod; import org.mapstruct.ap.internal.model.Field; import org.mapstruct.ap.internal.model.IterableMappingMethod; +import org.mapstruct.ap.internal.model.Javadoc; import org.mapstruct.ap.internal.model.MapMappingMethod; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.MapperReference; @@ -212,6 +214,7 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< .implPackage( mapperOptions.implementationPackage() ) .suppressGeneratorTimestamp( mapperOptions.suppressTimestampInGenerated() ) .additionalAnnotations( additionalAnnotationsBuilder.getProcessedAnnotations( element ) ) + .javadoc( getJavadoc( element ) ) .build(); if ( !mappingContext.getForgedMethodsUnderCreation().isEmpty() ) { @@ -441,6 +444,23 @@ else if ( method.isStreamMapping() ) { return mappingMethods; } + private Javadoc getJavadoc(TypeElement element) { + JavadocGem javadocGem = JavadocGem.instanceOn( element ); + + if ( javadocGem == null || !isConsistent( javadocGem, element, messager ) ) { + return null; + } + + Javadoc javadoc = new Javadoc.Builder() + .value( javadocGem.value().getValue() ) + .authors( javadocGem.authors().getValue() ) + .deprecated( javadocGem.deprecated().getValue() ) + .since( javadocGem.since().getValue() ) + .build(); + + return javadoc; + } + private Type getUserDesiredReturnType(SourceMethod method) { SelectionParameters selectionParameters = method.getOptions().getBeanMapping().getSelectionParameters(); if ( selectionParameters != null && selectionParameters.getResultType() != null ) { @@ -810,4 +830,15 @@ private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMe onlyCandidate.getName() ); } + + private boolean isConsistent( JavadocGem gem, TypeElement element, FormattingMessager messager ) { + if ( !gem.value().hasValue() + && !gem.authors().hasValue() + && !gem.deprecated().hasValue() + && !gem.since().hasValue() ) { + messager.printMessage( element, gem.mirror(), Message.JAVADOC_NO_ELEMENTS ); + return false; + } + return true; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 29600489fb..6f72f720f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -130,6 +130,8 @@ public enum Message { DECORATOR_NO_SUBTYPE( "Specified decorator type is no subtype of the annotated mapper type." ), DECORATOR_CONSTRUCTOR( "Specified decorator type has no default constructor nor a constructor with a single parameter accepting the decorated mapper type." ), + JAVADOC_NO_ELEMENTS( "'value', 'authors', 'deprecated' and 'since' are undefined in @Javadoc, define at least one of them." ), + GENERAL_CANNOT_IMPLEMENT_PRIVATE_MAPPER("Cannot create an implementation for mapper %s, because it is a private %s."), GENERAL_NO_IMPLEMENTATION( "No implementation type is registered for return type %s." ), GENERAL_ABSTRACT_RETURN_TYPE( "The return type %s is an abstract class or interface. Provide a non abstract / non interface result type or a factory method." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl index 4981882403..c65b3e5f85 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/GeneratedType.ftl @@ -14,6 +14,7 @@ package ${packageName}; import ${importedType}; +<#if javadoc??><#nt><@includeModel object=javadoc/> <#if !generatedTypeAvailable>/* @Generated( value = "org.mapstruct.ap.MappingProcessor"<#if suppressGeneratorTimestamp == false>, diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl new file mode 100644 index 0000000000..89ac57b9ef --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Javadoc.ftl @@ -0,0 +1,25 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Javadoc" --> +/** +<#list value?split("\n") as line><#nt>*<#if line?has_content> ${line?trim} + +<#if !authors.isEmpty()> +* +<#list authors as author> <#nt>* @author ${author?trim} + + +<#if deprecated?has_content> +* +<#nt>* @deprecated ${deprecated?trim} + +<#if since?has_content> +* +<#nt>* @since ${since?trim} + +<#nt> */ \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java new file mode 100644 index 0000000000..39f6da2890 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/ErroneousJavadocMapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import org.mapstruct.Javadoc; +import org.mapstruct.Mapper; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@Mapper +@Javadoc +public interface ErroneousJavadocMapper { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java new file mode 100644 index 0000000000..eb6285ff13 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import org.mapstruct.Javadoc; +import org.mapstruct.Mapper; + +@Mapper +@Javadoc( + value = "This is the description", + authors = { "author1", "author2" }, + deprecated = "Use {@link OtherMapper} instead", + since = "0.1" +) +@Deprecated +public interface JavadocAnnotatedWithAttributesMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java new file mode 100644 index 0000000000..150d7e5f76 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import org.mapstruct.Javadoc; +import org.mapstruct.Mapper; + +@Mapper +@Javadoc("This is the description\n" + + "\n" + + "@author author1\n" + + "@author author2\n" + + "\n" + + "@deprecated Use {@link OtherMapper} instead\n" + + "@since 0.1\n") +@Deprecated +public interface JavadocAnnotatedWithValueMapper { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java new file mode 100644 index 0000000000..316114389f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/javadoc/JavadocTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Jose Carlos Campanero Ortiz + */ +@IssueKey("2987") +class JavadocTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses( { JavadocAnnotatedWithValueMapper.class } ) + void javadocAnnotatedWithValueMapper() { + generatedSource.addComparisonToFixtureFor( JavadocAnnotatedWithValueMapper.class ); + } + + @ProcessorTest + @WithClasses( { JavadocAnnotatedWithAttributesMapper.class } ) + void javadocAnnotatedWithAttributesMapper() { + generatedSource.addComparisonToFixtureFor( JavadocAnnotatedWithAttributesMapper.class ); + } + + @ProcessorTest + @IssueKey("2987") + @WithClasses({ ErroneousJavadocMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousJavadocMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 15, + message = "'value', 'authors', 'deprecated' and 'since' are undefined in @Javadoc, " + + "define at least one of them.") + } + ) + void shouldFailOnEmptyJavadocAnnotation() { + } + +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java new file mode 100644 index 0000000000..53b9a08e92 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithAttributesMapperImpl.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import javax.annotation.processing.Generated; + +/** +* This is the description +* +* @author author1 +* @author author2 +* +* @deprecated Use {@link OtherMapper} instead +* +* @since 0.1 +*/ +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2023-04-30T17:36:38+0200", + comments = "version: , compiler: javac, environment: Java 11.0.18 (Ubuntu)" +) +@Deprecated +public class JavadocAnnotatedWithAttributesMapperImpl implements JavadocAnnotatedWithAttributesMapper { +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java new file mode 100644 index 0000000000..7bcc54ca44 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/javadoc/JavadocAnnotatedWithValueMapperImpl.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.javadoc; + +import javax.annotation.processing.Generated; + +/** +* This is the description +* +* @author author1 +* @author author2 +* +* @deprecated Use {@link OtherMapper} instead +* @since 0.1 +* +*/ +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2023-04-30T17:38:45+0200", + comments = "version: , compiler: javac, environment: Java 11.0.18 (Ubuntu)" +) +@Deprecated +public class JavadocAnnotatedWithValueMapperImpl implements JavadocAnnotatedWithValueMapper { +} From 4843123e6ef98589831a8cc8b7cc4330c7f9ed64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Etien=20Ro=C5=BEnik?= <12816736+eroznik@users.noreply.github.com> Date: Mon, 1 May 2023 09:42:58 +0200 Subject: [PATCH 0761/1006] #3165 Support adders for array / iterable to collection --- .../ap/internal/model/PropertyMapping.java | 2 +- .../model/assignment/AdderWrapper.java | 10 ++- .../ap/internal/model/common/SourceRHS.java | 6 ++ .../ap/test/bugs/_3165/Issue3165Mapper.java | 65 +++++++++++++++++++ .../test/bugs/_3165/Issue3165MapperTest.java | 32 +++++++++ 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165MapperTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 7114ccf57b..bedb37cc8f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -527,7 +527,7 @@ private Assignment assignToPlainViaAdder( Assignment rightHandSide) { Assignment result = rightHandSide; String adderIteratorName = sourcePropertyName == null ? targetPropertyName : sourcePropertyName; - if ( result.getSourceType().isCollectionType() ) { + if ( result.getSourceType().isIterableType() ) { result = new AdderWrapper( result, method.getThrownTypes(), isFieldAssignment(), adderIteratorName ); } else if ( result.getSourceType().isStreamType() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java index c5778628e9..13dfe832c9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/AdderWrapper.java @@ -39,7 +39,15 @@ public AdderWrapper( Assignment rhs, // localVar is iteratorVariable String desiredName = Nouns.singularize( adderIteratorName ); rhs.setSourceLoopVarName( rhs.createUniqueVarName( desiredName ) ); - adderType = first( getSourceType().determineTypeArguments( Collection.class ) ); + if ( getSourceType().isCollectionType() ) { + adderType = first( getSourceType().determineTypeArguments( Collection.class ) ); + } + else if ( getSourceType().isArrayType() ) { + adderType = getSourceType().getComponentType(); + } + else { // iterable + adderType = first( getSourceType().determineTypeArguments( Iterable.class ) ); + } } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java index b73d1ecf44..b4d422c797 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/SourceRHS.java @@ -149,6 +149,12 @@ public Type getSourceTypeForMatching() { else if ( sourceType.isStreamType() ) { return first( sourceType.determineTypeArguments( Stream.class ) ); } + else if ( sourceType.isArrayType() ) { + return sourceType.getComponentType(); + } + else if ( sourceType.isIterableType() ) { + return first( sourceType.determineTypeArguments( Iterable.class ) ); + } } return sourceType; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165Mapper.java new file mode 100644 index 0000000000..e065871ea3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165Mapper.java @@ -0,0 +1,65 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3165; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.ArrayList; +import java.util.List; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue3165Mapper { + + Issue3165Mapper INSTANCE = Mappers.getMapper( Issue3165Mapper.class ); + + Target toTarget(Source source); + + class Source { + private String[] pets; + private Iterable cats; + + public Source(String[] pets, Iterable cats) { + this.pets = pets; + this.cats = cats; + } + + public String[] getPets() { + return pets; + } + + public Iterable getCats() { + return cats; + } + } + + class Target { + private List pets; + private List cats; + + Target() { + this.pets = new ArrayList<>(); + this.cats = new ArrayList<>(); + } + + public List getPets() { + return pets; + } + + public void addPet(String pet) { + pets.add( pet ); + } + + public List getCats() { + return cats; + } + + public void addCat(String cat) { + cats.add( cat ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165MapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165MapperTest.java new file mode 100644 index 0000000000..4fb9e0ab3a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3165/Issue3165MapperTest.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3165; + +import java.util.Arrays; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Issue3165Mapper.class +}) +@IssueKey("3165") +class Issue3165MapperTest { + + @ProcessorTest + void supportsAdderWhenMappingArrayAndIterableToCollection() { + Issue3165Mapper.Source src = new Issue3165Mapper.Source( + new String[] { "cat", "dog", "mouse" }, + Arrays.asList( "ivy", "flu", "freya" ) + ); + Issue3165Mapper.Target target = Issue3165Mapper.INSTANCE.toTarget( src ); + assertThat( target.getPets() ).containsExactly( "cat", "dog", "mouse" ); + assertThat( target.getCats() ).containsExactly( "ivy", "flu", "freya" ); + } +} From f3dac94701b316e5a62df3a34e52b3d75c483fe7 Mon Sep 17 00:00:00 2001 From: MengxingYuan Date: Mon, 1 May 2023 16:28:51 +0800 Subject: [PATCH 0762/1006] #2781 Remove unmapped source properties when source parameter is directly mapped --- .../ap/internal/model/BeanMappingMethod.java | 36 ++++++++----- .../ap/test/bugs/_2781/Issue2781Mapper.java | 53 +++++++++++++++++++ .../ap/test/bugs/_2781/Issue2781Test.java | 24 +++++++++ 3 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 58b4640c95..84cfd18285 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1295,8 +1295,16 @@ else if ( mapping.getJavaExpression() != null ) { .options( mapping ) .build(); handledTargets.add( targetPropertyName ); - unprocessedSourceParameters.remove( sourceRef.getParameter() ); - unprocessedSourceProperties.remove( sourceRef.getShallowestPropertyName() ); + Parameter sourceParameter = sourceRef.getParameter(); + unprocessedSourceParameters.remove( sourceParameter ); + // If the source parameter was directly mapped + if ( sourceRef.getPropertyEntries().isEmpty() ) { + // Ignore all of its source properties completely + ignoreSourceProperties( sourceParameter ); + } + else { + unprocessedSourceProperties.remove( sourceRef.getShallowestPropertyName() ); + } } else { errorOccured = true; @@ -1471,23 +1479,25 @@ private void applyParameterNameBasedMapping() { sourceParameters.remove(); unprocessedDefinedTargets.remove( targetProperty.getKey() ); unprocessedSourceProperties.remove( targetProperty.getKey() ); - - // The source parameter was directly mapped so ignore all of its source properties completely - if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) { - // We explicitly ignore source properties from primitives or array types - Map readAccessors = sourceParameter.getType() - .getPropertyReadAccessors(); - for ( String sourceProperty : readAccessors.keySet() ) { - unprocessedSourceProperties.remove( sourceProperty ); - } - } - unprocessedConstructorProperties.remove( targetProperty.getKey() ); + ignoreSourceProperties( sourceParameter ); } } } } + private void ignoreSourceProperties(Parameter sourceParameter) { + // The source parameter was directly mapped so ignore all of its source properties completely + if ( !sourceParameter.getType().isPrimitive() && !sourceParameter.getType().isArrayType() ) { + // We explicitly ignore source properties from primitives or array types + Map readAccessors = sourceParameter.getType() + .getPropertyReadAccessors(); + for ( String sourceProperty : readAccessors.keySet() ) { + unprocessedSourceProperties.remove( sourceProperty ); + } + } + } + private SourceReference getSourceRefByTargetName(Parameter sourceParameter, String targetPropertyName) { SourceReference sourceRef = null; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Mapper.java new file mode 100644 index 0000000000..9abdf560c4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Mapper.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2781; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Mengxing Yuan + */ +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface Issue2781Mapper { + + Issue2781Mapper INSTANCE = Mappers.getMapper( Issue2781Mapper.class ); + + @Mapping(target = "nested", source = "source") + Target map(Source source); + + class Target { + private Source nested; + + public Source getNested() { + return nested; + } + + public void setNested(Source nested) { + this.nested = nested; + } + } + + class Source { + private String field1; + private String field2; + + public Source(String field1, String field2) { + this.field1 = field1; + this.field2 = field2; + } + + public String getField1() { + return field1; + } + + public String getField2() { + return field2; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Test.java new file mode 100644 index 0000000000..80ac4f5ce3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2781/Issue2781Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2781; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Mengxing Yuan + */ +@IssueKey("2781") +@WithClasses({ + Issue2781Mapper.class +}) +class Issue2781Test { + + @ProcessorTest + void shouldCompileWithoutErrors() { + } +} From be94569791e8b587c8ef3a33c1c7e55db4a90ead Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 23:28:54 +0000 Subject: [PATCH 0763/1006] Bump protobuf-java from 3.21.2 to 3.21.7 in /parent Bumps [protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.21.2 to 3.21.7. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/generate_changelog.py) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.21.2...v3.21.7) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index b306446b65..6e9c2836b6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -41,7 +41,7 @@ The processor module needs at least Java 11. --> 1.8 - 3.21.2 + 3.21.7 2.3.2 From bc5a8771217365b32782f160f132d1dd2a1c4fa1 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Mon, 1 May 2023 11:54:24 +0200 Subject: [PATCH 0764/1006] #3054: Allow abstract return type when all directly sealed subtypes are covered by subclass mappings Co-authored-by: Ben Zegveld --- .../itest/tests/MavenIntegrationTest.java | 5 + .../test/resources/sealedSubclassTest/pom.xml | 102 ++++++++++++++++++ .../mapstruct/itest/sealedsubclass/Bike.java | 18 ++++ .../itest/sealedsubclass/BikeDto.java | 18 ++++ .../mapstruct/itest/sealedsubclass/Car.java | 19 ++++ .../itest/sealedsubclass/CarDto.java | 18 ++++ .../itest/sealedsubclass/Davidson.java | 18 ++++ .../itest/sealedsubclass/DavidsonDto.java | 18 ++++ .../itest/sealedsubclass/Harley.java | 18 ++++ .../itest/sealedsubclass/HarleyDto.java | 18 ++++ .../mapstruct/itest/sealedsubclass/Motor.java | 18 ++++ .../itest/sealedsubclass/MotorDto.java | 18 ++++ .../sealedsubclass/SealedSubclassMapper.java | 31 ++++++ .../itest/sealedsubclass/Vehicle.java | 27 +++++ .../sealedsubclass/VehicleCollection.java | 17 +++ .../sealedsubclass/VehicleCollectionDto.java | 17 +++ .../itest/sealedsubclass/VehicleDto.java | 27 +++++ .../sealedsubclass/SealedSubclassTest.java | 59 ++++++++++ .../ap/internal/model/BeanMappingMethod.java | 35 +++++- .../ap/internal/model/common/Type.java | 38 +++++++ 20 files changed, 537 insertions(+), 2 deletions(-) create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/pom.xml create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Bike.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/BikeDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Car.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/CarDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Davidson.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/DavidsonDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Harley.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/HarleyDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Motor.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/MotorDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/SealedSubclassMapper.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Vehicle.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollection.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollectionDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleDto.java create mode 100644 integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 75513dd6c6..7e9175dd92 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -112,6 +112,11 @@ void namingStrategyTest() { void protobufBuilderTest() { } + @ProcessorTest(baseDir = "sealedSubclassTest") + @EnabledForJreRange(min = JRE.JAVA_17) + void sealedSubclassTest() { + } + @ProcessorTest(baseDir = "recordsTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }) diff --git a/integrationtest/src/test/resources/sealedSubclassTest/pom.xml b/integrationtest/src/test/resources/sealedSubclassTest/pom.xml new file mode 100644 index 0000000000..0706425e01 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/pom.xml @@ -0,0 +1,102 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + sealedSubclassTest + jar + + + + generate-via-compiler-plugin + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + \${compiler-id} + --enable-preview + + + + org.eclipse.tycho + tycho-compiler-jdt + ${org.eclipse.tycho.compiler-jdt.version} + + + + + + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + provided + + + + + debug-forked-javac + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + default-compile + + true + + --enable-preview + -J-Xdebug + -J-Xnoagent + -J-Djava.compiler=NONE + -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + 1 + --enable-preview + + + + + + diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Bike.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Bike.java new file mode 100644 index 0000000000..5b68f52e64 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Bike.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class Bike extends Vehicle { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/BikeDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/BikeDto.java new file mode 100644 index 0000000000..d51e95633b --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/BikeDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class BikeDto extends VehicleDto { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Car.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Car.java new file mode 100644 index 0000000000..0ed238e2a5 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Car.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class Car extends Vehicle { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } + +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/CarDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/CarDto.java new file mode 100644 index 0000000000..800bd23d39 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/CarDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class CarDto extends VehicleDto { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Davidson.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Davidson.java new file mode 100644 index 0000000000..e883c14be3 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Davidson.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class Davidson extends Motor { + private int numberOfExhausts; + + public int getNumberOfExhausts() { + return numberOfExhausts; + } + + public void setNumberOfExhausts(int numberOfExhausts) { + this.numberOfExhausts = numberOfExhausts; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/DavidsonDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/DavidsonDto.java new file mode 100644 index 0000000000..e975226e3e --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/DavidsonDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class DavidsonDto extends MotorDto { + private int numberOfExhausts; + + public int getNumberOfExhausts() { + return numberOfExhausts; + } + + public void setNumberOfExhausts(int numberOfExhausts) { + this.numberOfExhausts = numberOfExhausts; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Harley.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Harley.java new file mode 100644 index 0000000000..87a48034c6 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Harley.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class Harley extends Motor { + private int engineDb; + + public int getEngineDb() { + return engineDb; + } + + public void setEngineDb(int engineDb) { + this.engineDb = engineDb; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/HarleyDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/HarleyDto.java new file mode 100644 index 0000000000..2090ee7450 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/HarleyDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public final class HarleyDto extends MotorDto { + private int engineDb; + + public int getEngineDb() { + return engineDb; + } + + public void setEngineDb(int engineDb) { + this.engineDb = engineDb; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Motor.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Motor.java new file mode 100644 index 0000000000..fcd5f4e4dc --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Motor.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public sealed abstract class Motor extends Vehicle permits Harley, Davidson { + private int cc; + + public int getCc() { + return cc; + } + + public void setCc(int cc) { + this.cc = cc; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/MotorDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/MotorDto.java new file mode 100644 index 0000000000..bd74eb9296 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/MotorDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public sealed abstract class MotorDto extends VehicleDto permits HarleyDto, DavidsonDto { + private int cc; + + public int getCc() { + return cc; + } + + public void setCc(int cc) { + this.cc = cc; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/SealedSubclassMapper.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/SealedSubclassMapper.java new file mode 100644 index 0000000000..b37f623686 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/SealedSubclassMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SealedSubclassMapper { + SealedSubclassMapper INSTANCE = Mappers.getMapper( SealedSubclassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = Car.class, target = CarDto.class ) + @SubclassMapping( source = Bike.class, target = BikeDto.class ) + @SubclassMapping( source = Harley.class, target = HarleyDto.class ) + @SubclassMapping( source = Davidson.class, target = DavidsonDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Vehicle.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Vehicle.java new file mode 100644 index 0000000000..2a4e7560f6 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/Vehicle.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public abstract sealed class Vehicle permits Bike, Car, Motor { + private String name; + private String vehicleManufacturingCompany; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVehicleManufacturingCompany() { + return vehicleManufacturingCompany; + } + + public void setVehicleManufacturingCompany(String vehicleManufacturingCompany) { + this.vehicleManufacturingCompany = vehicleManufacturingCompany; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollection.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollection.java new file mode 100644 index 0000000000..1ada92a298 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollection.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollection { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollectionDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollectionDto.java new file mode 100644 index 0000000000..0cae412177 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleCollectionDto.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollectionDto { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleDto.java b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleDto.java new file mode 100644 index 0000000000..8c50bdcad9 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/main/java/org/mapstruct/itest/sealedsubclass/VehicleDto.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +public abstract sealed class VehicleDto permits CarDto, BikeDto, MotorDto { + private String name; + private String maker; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMaker() { + return maker; + } + + public void setMaker(String maker) { + this.maker = maker; + } +} diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java b/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java new file mode 100644 index 0000000000..379341ff66 --- /dev/null +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.sealedsubclass; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class SealedSubclassTest { + + @Test + public void mappingIsDoneUsingSubclassMapping() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Bike() ); + vehicles.getVehicles().add( new Harley() ); + vehicles.getVehicles().add( new Davidson() ); + + VehicleCollectionDto result = SealedSubclassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( CarDto.class, BikeDto.class, HarleyDto.class, DavidsonDto.class ); + } + + @Test + public void inverseMappingIsDoneUsingSubclassMapping() { + VehicleCollectionDto vehicles = new VehicleCollectionDto(); + vehicles.getVehicles().add( new CarDto() ); + vehicles.getVehicles().add( new BikeDto() ); + vehicles.getVehicles().add( new HarleyDto() ); + vehicles.getVehicles().add( new DavidsonDto() ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( Car.class, Bike.class, Harley.class, Davidson.class ); + } + + @Test + public void subclassMappingInheritsInverseMapping() { + VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); + CarDto carDto = new CarDto(); + carDto.setMaker( "BenZ" ); + vehiclesDto.getVehicles().add( carDto ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehiclesDto ); + + assertThat( result.getVehicles() ) + .extracting( Vehicle::getVehicleManufacturingCompany ) + .containsExactly( "BenZ" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 84cfd18285..cf3e23db9e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -446,8 +446,39 @@ private SubclassMapping createSubclassMapping(SubclassMappingOptions subclassMap } private boolean isAbstractReturnTypeAllowed() { - return method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed() - && !method.getOptions().getSubclassMappings().isEmpty(); + return !method.getOptions().getSubclassMappings().isEmpty() + && ( method.getOptions().getBeanMapping().getSubclassExhaustiveStrategy().isAbstractReturnTypeAllowed() + || isCorrectlySealed() ); + } + + private boolean isCorrectlySealed() { + Type mappingSourceType = method.getMappingSourceType(); + return isCorrectlySealed( mappingSourceType ); + } + + private boolean isCorrectlySealed(Type mappingSourceType) { + if ( mappingSourceType.isSealed() ) { + List unusedPermittedSubclasses = + new ArrayList<>( mappingSourceType.getPermittedSubclasses() ); + method.getOptions().getSubclassMappings().forEach( subClassOption -> { + for (Iterator iterator = unusedPermittedSubclasses.iterator(); + iterator.hasNext(); ) { + if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) { + iterator.remove(); + } + } + } ); + for ( Iterator iterator = unusedPermittedSubclasses.iterator(); + iterator.hasNext(); ) { + TypeMirror typeMirror = iterator.next(); + Type type = ctx.getTypeFactory().getType( typeMirror ); + if ( type.isAbstract() && isCorrectlySealed( type ) ) { + iterator.remove(); + } + } + return unusedPermittedSubclasses.isEmpty(); + } + return false; } private void initializeMappingReferencesIfNeeded(Type resultTypeToMap) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6894906266..4254913d83 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.internal.model.common; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; @@ -53,6 +55,7 @@ import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; +import static java.util.Collections.emptyList; import static org.mapstruct.ap.internal.util.Collections.first; /** @@ -67,6 +70,18 @@ * @author Filip Hrisafov */ public class Type extends ModelElement implements Comparable { + private static final Method SEALED_PERMITTED_SUBCLASSES_METHOD; + + static { + Method permittedSubclassesMethod; + try { + permittedSubclassesMethod = TypeElement.class.getMethod( "getPermittedSubclasses" ); + } + catch ( NoSuchMethodException e ) { + permittedSubclassesMethod = null; + } + SEALED_PERMITTED_SUBCLASSES_METHOD = permittedSubclassesMethod; + } private final TypeUtils typeUtils; private final ElementUtils elementUtils; @@ -1661,4 +1676,27 @@ public boolean isEnumSet() { return "java.util.EnumSet".equals( getFullyQualifiedName() ); } + /** + * return true if this type is a java 17+ sealed class + */ + public boolean isSealed() { + return typeElement.getModifiers().stream().map( Modifier::name ).anyMatch( "SEALED"::equals ); + } + + /** + * return the list of permitted TypeMirrors for the java 17+ sealed class + */ + @SuppressWarnings( "unchecked" ) + public List getPermittedSubclasses() { + if (SEALED_PERMITTED_SUBCLASSES_METHOD == null) { + return emptyList(); + } + try { + return (List) SEALED_PERMITTED_SUBCLASSES_METHOD.invoke( typeElement ); + } + catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { + return emptyList(); + } + } + } From d0e4c48228dc03722d34deb5506ec159ac38514d Mon Sep 17 00:00:00 2001 From: Jason Bodnar Date: Mon, 8 May 2023 15:23:03 -0500 Subject: [PATCH 0765/1006] #3172 Add mapping between Locale and String --- .../chapter-5-data-type-conversions.asciidoc | 3 ++ .../ap/internal/conversion/Conversions.java | 2 + .../conversion/LocaleToStringConversion.java | 37 +++++++++++++++ .../locale/LocaleConversionTest.java | 46 +++++++++++++++++++ .../test/conversion/locale/LocaleMapper.java | 19 ++++++++ .../test/conversion/locale/LocaleSource.java | 23 ++++++++++ .../test/conversion/locale/LocaleTarget.java | 21 +++++++++ 7 files changed, 151 insertions(+) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/LocaleToStringConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleTarget.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 258c7085f2..30430fe97e 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -130,6 +130,9 @@ public interface CarMapper { * Between `java.net.URL` and `String`. ** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/URL[URL] otherwise a `MalformedURLException` is thrown. +* Between `java.util.Locale` and `String`. +** When converting from a `Locale`, the resulting `String` will be a well-formed IETF BCP 47 language tag representing the locale. When converting from a `String`, the locale that best represents the language tag will be returned. See https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#forLanguageTag-java.lang.String-[Locale.forLanguageTag()] and https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#toLanguageTag--[Locale.toLanguageTag()] for more information. + [[mapping-object-references]] === Mapping object references diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 9a4085df83..6acb69492a 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -21,6 +21,7 @@ import java.util.Currency; import java.util.Date; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -198,6 +199,7 @@ public Conversions(TypeFactory typeFactory) { register( Currency.class, String.class, new CurrencyToStringConversion() ); register( UUID.class, String.class, new UUIDToStringConversion() ); + register( Locale.class, String.class, new LocaleToStringConversion() ); registerURLConversion(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/LocaleToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/LocaleToStringConversion.java new file mode 100644 index 0000000000..05a6da0b19 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/LocaleToStringConversion.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.util.Locale; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Collections; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; + +/** + * Conversion between {@link java.util.Locale} and {@link String}. + * + * @author Jason Bodnar + */ +public class LocaleToStringConversion extends SimpleConversion { + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toLanguageTag()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return locale( conversionContext ) + ".forLanguageTag( )"; + } + + @Override + protected Set getFromConversionImportTypes(final ConversionContext conversionContext) { + return Collections.asSet( conversionContext.getTypeFactory().getType( Locale.class ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleConversionTest.java new file mode 100644 index 0000000000..cba7785512 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleConversionTest.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.locale; + +import java.util.Locale; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests conversions between {@link Locale} and String. + * + * @author Jason Bodnar + */ +@IssueKey("3172") +@WithClasses({ LocaleSource.class, LocaleTarget.class, LocaleMapper.class }) +public class LocaleConversionTest { + + @ProcessorTest + public void shouldApplyLocaleConversion() { + LocaleSource source = new LocaleSource(); + source.setLocaleA( Locale.getDefault() ); + + LocaleTarget target = LocaleMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getLocaleA() ).isEqualTo( source.getLocaleA().toLanguageTag() ); + } + + @ProcessorTest + public void shouldApplyReverseLocaleConversion() { + LocaleTarget target = new LocaleTarget(); + target.setLocaleA( Locale.getDefault().toLanguageTag() ); + + LocaleSource source = LocaleMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getLocaleA() ).isEqualTo( Locale.forLanguageTag( target.getLocaleA() ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleMapper.java new file mode 100644 index 0000000000..3da3fc4ae4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.locale; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface LocaleMapper { + + LocaleMapper INSTANCE = Mappers.getMapper( LocaleMapper.class ); + + LocaleTarget sourceToTarget(LocaleSource source); + + LocaleSource targetToSource(LocaleTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleSource.java new file mode 100644 index 0000000000..69ea5bda2d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleSource.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.locale; + +import java.util.Locale; + +/** + * @author Jason Bodnar + */ +public class LocaleSource { + private Locale localeA; + + public Locale getLocaleA() { + return localeA; + } + + public void setLocaleA(Locale localeA) { + this.localeA = localeA; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleTarget.java new file mode 100644 index 0000000000..000ff86b05 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/locale/LocaleTarget.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.locale; + +/** + * @author Jason Bodnar + */ +public class LocaleTarget { + private String localeA; + + public String getLocaleA() { + return localeA; + } + + public void setLocaleA(String localeA) { + this.localeA = localeA; + } +} From a89c34f00c58e4b74bb81a102f7e615405c38692 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 1 May 2023 09:44:05 +0200 Subject: [PATCH 0766/1006] #3238 Compile error instead of null pointer exception for invalid ignore with target this --- .../internal/model/source/MappingOptions.java | 3 ++ .../mapstruct/ap/internal/util/Message.java | 1 + .../bugs/_3238/ErroneousIssue3238Mapper.java | 42 +++++++++++++++++++ .../ap/test/bugs/_3238/Issue3238Test.java | 37 ++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/ErroneousIssue3238Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/Issue3238Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 5046ce8b29..2af1c95f71 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -254,6 +254,9 @@ else if ( gem.nullValuePropertyMappingStrategy().hasValue() && gem.ignore().hasValue() && gem.ignore().getValue() ) { message = Message.PROPERTYMAPPING_IGNORE_AND_NVPMS; } + else if ( ".".equals( gem.target().get() ) && gem.ignore().hasValue() && gem.ignore().getValue() ) { + message = Message.PROPERTYMAPPING_TARGET_THIS_AND_IGNORE; + } if ( message == null ) { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 6f72f720f1..249825ec50 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -68,6 +68,7 @@ public enum Message { PROPERTYMAPPING_CONSTANT_VALUE_AND_NVPMS( "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a constant or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS( "DefaultExpression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_IGNORE_AND_NVPMS( "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, either define ignore or an nullValuePropertyMappingStrategy." ), + PROPERTYMAPPING_TARGET_THIS_AND_IGNORE( "Using @Mapping( target = \".\", ignore = true ) is not allowed. You need to use @BeanMapping( ignoreByDefault = true ) if you would like to ignore all non explicitly mapped target properties." ), PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED("Expression and a qualifier both defined in @Mapping, either define an expression or a qualifier."), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/ErroneousIssue3238Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/ErroneousIssue3238Mapper.java new file mode 100644 index 0000000000..fd0d4672a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/ErroneousIssue3238Mapper.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3238; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface ErroneousIssue3238Mapper { + + @Mapping(target = ".", ignore = true) + Target map(Source source); + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/Issue3238Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/Issue3238Test.java new file mode 100644 index 0000000000..6648495a70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3238/Issue3238Test.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3238; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * @author Filip Hrisafov + */ +@WithClasses(ErroneousIssue3238Mapper.class) +@IssueKey("3238") +class Issue3238Test { + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = @Diagnostic( type = ErroneousIssue3238Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 14, + message = "Using @Mapping( target = \".\", ignore = true ) is not allowed." + + " You need to use @BeanMapping( ignoreByDefault = true ) if you would like to ignore" + + " all non explicitly mapped target properties." + ) + ) + void shouldGenerateValidCompileError() { + + } + +} From efaa67aadf6f24c8f12804a1f18c1218d929d56f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 1 May 2023 10:18:23 +0200 Subject: [PATCH 0767/1006] #3104 Update methods with NullValuePropertyMappingStrategy.IGNORE should use SetterWrapperForCollectionsAndMapsWithNullCheck --- .../model/CollectionAssignmentBuilder.java | 11 +++ .../ap/test/bugs/_3104/Issue3104Mapper.java | 77 +++++++++++++++++++ .../ap/test/bugs/_3104/Issue3104Test.java | 38 +++++++++ 3 files changed, 126 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index e3bc85342a..9a0a025845 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -31,6 +31,7 @@ import org.mapstruct.ap.internal.util.accessor.AccessorType; import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_NULL; @@ -177,6 +178,16 @@ else if ( method.isUpdateMethod() && !targetImmutable ) { targetAccessorType.isFieldAssignment() ); } + else if ( method.isUpdateMethod() && nvpms == IGNORE ) { + + result = new SetterWrapperForCollectionsAndMapsWithNullCheck( + result, + method.getThrownTypes(), + targetType, + ctx.getTypeFactory(), + targetAccessorType.isFieldAssignment() + ); + } else if ( setterWrapperNeedsSourceNullCheck( result ) && canBeMappedOrDirectlyAssigned( result ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Mapper.java new file mode 100644 index 0000000000..e561f40bab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Mapper.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3104; + +import java.util.Collections; +import java.util.List; + +import org.mapstruct.BeanMapping; +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.TARGET_IMMUTABLE) +public interface Issue3104Mapper { + + Issue3104Mapper INSTANCE = Mappers.getMapper( Issue3104Mapper.class ); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + void update(@MappingTarget Target target, Source source); + + class Target { + private List children = Collections.emptyList(); + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + if ( children == null ) { + throw new IllegalArgumentException( "children is null" ); + } + this.children = Collections.unmodifiableList( children ); + } + } + + class Child { + private String myField; + + public String getMyField() { + return myField; + } + + public void setMyField(String myField) { + this.myField = myField; + } + } + + class Source { + private final List children; + + public Source(List children) { + this.children = children; + } + + public List getChildren() { + return children; + } + + } + + class ChildSource { + private final String myField; + + public ChildSource(String myField) { + this.myField = myField; + } + + public String getMyField() { + return myField; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Test.java new file mode 100644 index 0000000000..5f3a9e160b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3104/Issue3104Test.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3104; + +import java.util.Collections; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3104") +@WithClasses(Issue3104Mapper.class) +class Issue3104Test { + + @ProcessorTest + void shouldCorrectlyMapUpdateMappingWithTargetImmutableCollectionStrategy() { + Issue3104Mapper.Target target = new Issue3104Mapper.Target(); + Issue3104Mapper.INSTANCE.update( target, new Issue3104Mapper.Source( null ) ); + + assertThat( target.getChildren() ).isEmpty(); + + Issue3104Mapper.INSTANCE.update( + target, + new Issue3104Mapper.Source( Collections.singletonList( new Issue3104Mapper.ChildSource( "tester" ) ) ) + ); + assertThat( target.getChildren() ) + .extracting( Issue3104Mapper.Child::getMyField ) + .containsExactly( "tester" ); + } +} From 7c90592d051c828cc20af0818f899c6fc5adc0e4 Mon Sep 17 00:00:00 2001 From: paparadva Date: Sun, 30 Oct 2022 13:11:26 +0300 Subject: [PATCH 0768/1006] #2863 Add validation of String type to @TargetPropertyName --- .../processor/MethodRetrievalProcessor.java | 15 ++++++++++-- .../mapstruct/ap/internal/util/Message.java | 1 + ...sNonStringTargetPropertyNameParameter.java | 21 +++++++++++++++++ .../TargetPropertyNameTest.java | 23 +++++++++++++++++++ 4 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 4ad531d334..6f1febae9d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -28,6 +28,7 @@ import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.gem.SubclassMappingGem; import org.mapstruct.ap.internal.gem.SubclassMappingsGem; +import org.mapstruct.ap.internal.gem.TargetPropertyNameGem; import org.mapstruct.ap.internal.gem.ValueMappingGem; import org.mapstruct.ap.internal.gem.ValueMappingsGem; import org.mapstruct.ap.internal.model.common.Parameter; @@ -230,7 +231,7 @@ private SourceMethod getMethod(TypeElement usedMapper, // otherwise add reference to existing mapper method else if ( isValidReferencedMethod( parameters ) || isValidFactoryMethod( method, parameters, returnType ) || isValidLifecycleCallbackMethod( method ) - || isValidPresenceCheckMethod( method, returnType ) ) { + || isValidPresenceCheckMethod( method, parameters, returnType ) ) { return getReferencedMethod( usedMapper, methodType, method, mapperToImplement, parameters ); } else { @@ -407,7 +408,17 @@ private boolean hasFactoryAnnotation(ExecutableElement method) { return ObjectFactoryGem.instanceOn( method ) != null; } - private boolean isValidPresenceCheckMethod(ExecutableElement method, Type returnType) { + private boolean isValidPresenceCheckMethod(ExecutableElement method, List parameters, Type returnType) { + for ( Parameter param : parameters ) { + if ( param.isTargetPropertyName() && !param.getType().isString() ) { + messager.printMessage( + param.getElement(), + TargetPropertyNameGem.instanceOn( param.getElement() ).mirror(), + Message.RETRIEVAL_TARGET_PROPERTY_NAME_WRONG_TYPE + ); + return false; + } + } return isBoolean( returnType ) && hasConditionAnnotation( method ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 249825ec50..a24a43036c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -176,6 +176,7 @@ public enum Message { RETRIEVAL_MAPPER_USES_CYCLE( "The mapper %s is referenced itself in Mapper#uses.", Diagnostic.Kind.WARNING ), RETRIEVAL_AFTER_METHOD_NOT_IMPLEMENTED( "@AfterMapping can only be applied to an implemented method." ), RETRIEVAL_BEFORE_METHOD_NOT_IMPLEMENTED( "@BeforeMapping can only be applied to an implemented method." ), + RETRIEVAL_TARGET_PROPERTY_NAME_WRONG_TYPE( "@TargetPropertyName can only by applied to a String parameter." ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), INHERITINVERSECONFIGURATION_INVALID_NAME( "None of the candidates %s() matches given name: \"%s\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java new file mode 100644 index 0000000000..ec545a058b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.targetpropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; + +@Mapper +public interface ErroneousNonStringTargetPropertyNameParameter { + + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value, @TargetPropertyName int propName) { + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java index 3d96e66664..91e4b77de2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java @@ -9,6 +9,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.GeneratedSource; import java.util.Collections; @@ -278,4 +281,24 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { "addresses.street" ); } + + @IssueKey("2863") + @ProcessorTest + @WithClasses({ + ErroneousNonStringTargetPropertyNameParameter.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousNonStringTargetPropertyNameParameter.class, + line = 18, + message = "@TargetPropertyName can only by applied to a String parameter." + ) + } + ) + public void nonStringTargetPropertyNameParameter() { + + } } From 6d205e5bc46365444774609e860f60819818ef4b Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Sun, 21 May 2023 22:49:41 +0200 Subject: [PATCH 0769/1006] #1454 Support for lifecycle methods on type being built with builders Add missing support for lifecycle methods with builders: * `@BeforeMapping` with `@TargetType` the type being build * `@AftereMapping` with `@TargetType` the type being build * `@AfterMapping` with `@MappingTarget` the type being build --- .../resources/build-config/checkstyle.xml | 4 +- .../chapter-12-customizing-mapping.asciidoc | 14 ++-- .../chapter-13-using-mapstruct-spi.asciidoc | 2 +- .../ap/internal/model/BeanMappingMethod.java | 72 ++++++++++++++++++- .../ap/internal/model/MappingMethod.java | 4 +- .../ap/internal/model/BeanMappingMethod.ftl | 21 +++++- .../BuilderLifecycleCallbacksTest.java | 6 +- .../builder/lifecycle/MappingContext.java | 10 ++- 8 files changed, 119 insertions(+), 14 deletions(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index a4591c39de..a1ff4af23a 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -29,7 +29,9 @@ - + + + diff --git a/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc index 0c873eac09..dc07b30e62 100644 --- a/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc +++ b/documentation/src/main/asciidoc/chapter-12-customizing-mapping.asciidoc @@ -248,9 +248,8 @@ All before/after-mapping methods that *can* be applied to a mapping method *will The order of the method invocation is determined primarily by their variant: -1. `@BeforeMapping` methods without an `@MappingTarget` parameter are called before any null-checks on source -parameters and constructing a new target bean. -2. `@BeforeMapping` methods with an `@MappingTarget` parameter are called after constructing a new target bean. +1. `@BeforeMapping` methods without parameters, a `@MappingTarget` parameter or a `@TargetType` parameter are called before any null-checks on source parameters and constructing a new target bean. +2. `@BeforeMapping` methods with a `@MappingTarget` parameter are called after constructing a new target bean. 3. `@AfterMapping` methods are called at the end of the mapping method before the last `return` statement. Within those groups, the method invocations are ordered by their location of definition: @@ -262,4 +261,11 @@ Within those groups, the method invocations are ordered by their location of def *Important:* the order of methods declared within one type can not be guaranteed, as it depends on the compiler and the processing environment implementation. -*Important:* when using a builder, the `@AfterMapping` annotated method must have the builder as `@MappingTarget` annotated parameter so that the method is able to modify the object going to be build. The `build` method is called when the `@AfterMapping` annotated method scope finishes. MapStruct will not call the `@AfterMapping` annotated method if the real target is used as `@MappingTarget` annotated parameter. \ No newline at end of file +[NOTE] +==== +Before/After-mapping methods can also be used with builders: + +* `@BeforeMapping` methods with a `@MappingTarget` parameter of the real target will not be invoked because it is only available after the mapping was already performed. +* To be able to modify the object that is going to be built, the `@AfterMapping` annotated method must have the builder as `@MappingTarget` annotated parameter. The `build` method is called when the `@AfterMapping` annotated method scope finishes. +* The `@AfterMapping` annotated method can also have the real target as `@TargetType` or `@MappingTarget`. It will be invoked after the real target was built (first the methods annotated with `@TargetType`, then the methods annotated with `@MappingTarget`) +==== \ No newline at end of file diff --git a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc index ce9b288428..51b2bbff3c 100644 --- a/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc +++ b/documentation/src/main/asciidoc/chapter-13-using-mapstruct-spi.asciidoc @@ -71,7 +71,7 @@ public class GolfPlayerDto { public GolfPlayerDto withName(String name) { this.name = name; - return this + return this; } } ---- diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index cf3e23db9e..b6afce74d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -94,6 +94,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final Type returnTypeToConstruct; private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; + private final String finalizedResultName; + private final List beforeMappingReferencesWithFinalizedReturnType; + private final List afterMappingReferencesWithFinalizedReturnType; private final MappingReferences mappingReferences; @@ -368,8 +371,35 @@ else if ( !method.isUpdateMethod() ) { MethodReference finalizeMethod = null; + List beforeMappingReferencesWithFinalizedReturnType = new ArrayList<>(); + List afterMappingReferencesWithFinalizedReturnType = new ArrayList<>(); if ( shouldCallFinalizerMethod( returnTypeToConstruct ) ) { finalizeMethod = getFinalizerMethod(); + + Type actualReturnType = method.getReturnType(); + + beforeMappingReferencesWithFinalizedReturnType.addAll( filterMappingTarget( + LifecycleMethodResolver.beforeMappingMethods( + method, + actualReturnType, + selectionParameters, + ctx, + existingVariableNames + ), + false + ) ); + + afterMappingReferencesWithFinalizedReturnType.addAll( LifecycleMethodResolver.afterMappingMethods( + method, + actualReturnType, + selectionParameters, + ctx, + existingVariableNames + ) ); + + // remove methods without parameters as they are already being invoked + removeMappingReferencesWithoutSourceParameters( beforeMappingReferencesWithFinalizedReturnType ); + removeMappingReferencesWithoutSourceParameters( afterMappingReferencesWithFinalizedReturnType ); } return new BeanMappingMethod( @@ -383,12 +413,18 @@ else if ( !method.isUpdateMethod() ) { returnTypeBuilder, beforeMappingMethods, afterMappingMethods, + beforeMappingReferencesWithFinalizedReturnType, + afterMappingReferencesWithFinalizedReturnType, finalizeMethod, mappingReferences, subclasses ); } + private void removeMappingReferencesWithoutSourceParameters(List references) { + references.removeIf( r -> r.getSourceParameters().isEmpty() && r.getReturnType().isVoid() ); + } + private boolean doesNotAllowAbstractReturnTypeAndCanBeConstructed(Type returnTypeImpl) { return !isAbstractReturnTypeAllowed() && canReturnTypeBeConstructed( returnTypeImpl ); @@ -706,7 +742,6 @@ private boolean isReturnTypeAbstractOrCanBeConstructed(Type returnType) { * Find a factory method for a return type or for a builder. * @param returnTypeImpl the return type implementation to construct * @param @selectionParameters - * @return */ private void initializeFactoryMethod(Type returnTypeImpl, SelectionParameters selectionParameters) { List> matchingFactoryMethods = @@ -1380,7 +1415,7 @@ else if ( mapping.getJavaExpression() != null ) { *

      * When a target property matches its name with the (nested) source property, it is added to the list if and * only if it is an unprocessed target property. - * + *

      * duplicates will be handled by {@link #applyPropertyNameBasedMapping(List)} */ private void applyTargetThisMapping() { @@ -1766,6 +1801,8 @@ private BeanMappingMethod(Method method, BuilderType returnTypeBuilder, List beforeMappingReferences, List afterMappingReferences, + List beforeMappingReferencesWithFinalizedReturnType, + List afterMappingReferencesWithFinalizedReturnType, MethodReference finalizerMethod, MappingReferences mappingReferences, List subclassMappings) { @@ -1783,9 +1820,20 @@ private BeanMappingMethod(Method method, this.propertyMappings = propertyMappings; this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; + if ( this.finalizerMethod != null ) { + this.finalizedResultName = + Strings.getSafeVariableName( getResultName() + "Result", existingVariableNames ); + existingVariableNames.add( this.finalizedResultName ); + } + else { + this.finalizedResultName = null; + } this.mappingReferences = mappingReferences; - // intialize constant mappings as all mappings, but take out the ones that can be contributed to a + this.beforeMappingReferencesWithFinalizedReturnType = beforeMappingReferencesWithFinalizedReturnType; + this.afterMappingReferencesWithFinalizedReturnType = afterMappingReferencesWithFinalizedReturnType; + + // initialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. this.mappingsByParameter = new HashMap<>(); this.constantMappings = new ArrayList<>( propertyMappings.size() ); @@ -1830,6 +1878,18 @@ public List getSubclassMappings() { return subclassMappings; } + public String getFinalizedResultName() { + return finalizedResultName; + } + + public List getBeforeMappingReferencesWithFinalizedReturnType() { + return beforeMappingReferencesWithFinalizedReturnType; + } + + public List getAfterMappingReferencesWithFinalizedReturnType() { + return afterMappingReferencesWithFinalizedReturnType; + } + public List propertyMappingsByParameter(Parameter parameter) { // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value return mappingsByParameter.getOrDefault( parameter.getName(), Collections.emptyList() ); @@ -1882,6 +1942,12 @@ public Set getImportTypes() { if ( returnTypeBuilder != null ) { types.add( returnTypeBuilder.getOwningType() ); } + for ( LifecycleCallbackMethodReference reference : beforeMappingReferencesWithFinalizedReturnType ) { + types.addAll( reference.getImportTypes() ); + } + for ( LifecycleCallbackMethodReference reference : afterMappingReferencesWithFinalizedReturnType ) { + types.addAll( reference.getImportTypes() ); + } return types; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 5b9eda644b..4c59216e09 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -186,8 +186,8 @@ public String toString() { return returnType + " " + getName() + "(" + join( parameters, ", " ) + ")"; } - private List filterMappingTarget(List methods, - boolean mustHaveMappingTargetParameter) { + protected static List filterMappingTarget( + List methods, boolean mustHaveMappingTargetParameter) { if ( methods == null ) { return Collections.emptyList(); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 1b402a57f0..a0fbe24b3e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -21,6 +21,12 @@ + <#list beforeMappingReferencesWithFinalizedReturnType as callback> + <@includeModel object=callback targetBeanName=finalizedResultName targetType=returnType/> + <#if !callback_has_next> + + + <#if !mapNullToDefault> if ( <#list sourceParametersExcludingPrimitives as sourceParam>${sourceParam.name} == null<#if sourceParam_has_next> && ) { return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /><#else>null; @@ -129,7 +135,20 @@ <#if returnType.name != "void"> <#if finalizerMethod??> - return ${resultName}.<@includeModel object=finalizerMethod />; + <#if (afterMappingReferencesWithFinalizedReturnType?size > 0)> + ${returnType.name} ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; + + <#list afterMappingReferencesWithFinalizedReturnType as callback> + <#if callback_index = 0> + + + <@includeModel object=callback targetBeanName=finalizedResultName targetType=returnType/> + + + return ${finalizedResultName}; + <#else> + return ${resultName}.<@includeModel object=finalizerMethod />; + <#else> return ${resultName}; diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java index e3892f2154..3d5fb7e533 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/BuilderLifecycleCallbacksTest.java @@ -43,12 +43,16 @@ public void lifecycleMethodsShouldBeInvoked() { assertThat( context.getInvokedMethods() ) .contains( "beforeWithoutParameters", + "beforeWithTargetType", "beforeWithBuilderTargetType", "beforeWithBuilderTarget", "afterWithoutParameters", "afterWithBuilderTargetType", "afterWithBuilderTarget", - "afterWithBuilderTargetReturningTarget" + "afterWithBuilderTargetReturningTarget", + "afterWithTargetType", + "afterWithTarget", + "afterWithTargetReturningTarget" ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java index 96b9b30db6..079be90a81 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java @@ -74,7 +74,15 @@ public void afterWithBuilderTarget(OrderDto source, @MappingTarget Order.Builder public Order afterWithBuilderTargetReturningTarget(@MappingTarget Order.Builder orderBuilder) { invokedMethods.add( "afterWithBuilderTargetReturningTarget" ); - return orderBuilder.create(); + // return null, so that @AfterMapping methods on the finalized object will be called in the tests + return null; + } + + @AfterMapping + public Order afterWithTargetReturningTarget(@MappingTarget Order order) { + invokedMethods.add( "afterWithTargetReturningTarget" ); + + return order; } public List getInvokedMethods() { From 84c443df9c141d9947253a19facbb952cbda816e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Campanero=20Ortiz?= Date: Wed, 24 May 2023 05:44:36 +0200 Subject: [PATCH 0770/1006] #3245 Remove redundant null checks in nested properties --- .../model/NestedPropertyMappingMethod.ftl | 9 ++-- .../test/bugs/_1561/Issue1561MapperImpl.java | 9 +--- .../ap/test/bugs/_1685/UserMapperImpl.java | 45 +++---------------- .../ap/test/bugs/_2245/TestMapperImpl.java | 9 +--- .../nestedsource/ArtistToChartEntryImpl.java | 27 ++--------- .../nestedtarget/ChartEntryToArtistImpl.java | 45 +++---------------- .../nestedbeans/mixed/FishTankMapperImpl.java | 27 ++--------- .../ArtistToChartEntryImpl.java | 27 ++--------- .../ChartEntryToArtistImpl.java | 45 +++---------------- 9 files changed, 30 insertions(+), 213 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index ce6dab0714..8eabe23a16 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -7,15 +7,16 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.NestedPropertyMappingMethod" --> <#lt>private <@includeModel object=returnType.typeBound/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { - if ( ${sourceParameter.name} == null ) { - return ${returnType.null}; - } <#list propertyEntries as entry> <#if entry.presenceChecker?? > if ( <#if entry_index != 0>${entry.previousPropertyName} == null || !<@includeModel object=entry.presenceChecker /> ) { return ${returnType.null}; } + <#if !entry_has_next> + return ${entry.previousPropertyName}.${entry.accessorName}; + + <#if entry_has_next> <@includeModel object=entry.type.typeBound/> ${entry.name} = ${entry.previousPropertyName}.${entry.accessorName}; <#if !entry.presenceChecker?? > <#if !entry.type.primitive> @@ -24,8 +25,6 @@ } - <#if !entry_has_next> - return ${entry.name}; } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java index dde54d65b7..83cebe2bde 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1561/Issue1561MapperImpl.java @@ -61,17 +61,10 @@ protected NestedTarget sourceToNestedTarget(Source source) { } private Stream targetNestedTargetProperties(Target target) { - if ( target == null ) { - return null; - } NestedTarget nestedTarget = target.getNestedTarget(); if ( nestedTarget == null ) { return null; } - Stream properties = nestedTarget.getProperties(); - if ( properties == null ) { - return null; - } - return properties; + return nestedTarget.getProperties(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java index b8d3e9db4b..3c019a0dd8 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_1685/UserMapperImpl.java @@ -168,77 +168,42 @@ protected ContactDataDTO userToContactDataDTO(User user) { } private String userDTOContactDataDTOEmail(UserDTO userDTO) { - if ( userDTO == null ) { - return null; - } ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); if ( contactDataDTO == null ) { return null; } - String email = contactDataDTO.getEmail(); - if ( email == null ) { - return null; - } - return email; + return contactDataDTO.getEmail(); } private String userDTOContactDataDTOPhone(UserDTO userDTO) { - if ( userDTO == null ) { - return null; - } ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); if ( contactDataDTO == null ) { return null; } - String phone = contactDataDTO.getPhone(); - if ( phone == null ) { - return null; - } - return phone; + return contactDataDTO.getPhone(); } private String userDTOContactDataDTOAddress(UserDTO userDTO) { - if ( userDTO == null ) { - return null; - } ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); if ( contactDataDTO == null ) { return null; } - String address = contactDataDTO.getAddress(); - if ( address == null ) { - return null; - } - return address; + return contactDataDTO.getAddress(); } private List userDTOContactDataDTOPreferences(UserDTO userDTO) { - if ( userDTO == null ) { - return null; - } ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); if ( contactDataDTO == null ) { return null; } - List preferences = contactDataDTO.getPreferences(); - if ( preferences == null ) { - return null; - } - return preferences; + return contactDataDTO.getPreferences(); } private String[] userDTOContactDataDTOSettings(UserDTO userDTO) { - if ( userDTO == null ) { - return null; - } ContactDataDTO contactDataDTO = userDTO.getContactDataDTO(); if ( contactDataDTO == null ) { return null; } - String[] settings = contactDataDTO.getSettings(); - if ( settings == null ) { - return null; - } - return settings; + return contactDataDTO.getSettings(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java index c3ecc02911..b7a18048a0 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_2245/TestMapperImpl.java @@ -34,17 +34,10 @@ public Tenant map(TenantDTO tenant) { } private String tenantInnerId(TenantDTO tenantDTO) { - if ( tenantDTO == null ) { - return null; - } Inner inner = tenantDTO.getInner(); if ( inner == null ) { return null; } - String id = inner.getId(); - if ( id == null ) { - return null; - } - return id; + return inner.getId(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java index 09f96b4b3a..40c16c6086 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedsource/ArtistToChartEntryImpl.java @@ -96,24 +96,14 @@ public ChartEntry map(Chart name) { } private String songArtistName(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { - return null; - } - return name; + return artist.getName(); } private String songArtistLabelStudioName(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; @@ -126,17 +116,10 @@ private String songArtistLabelStudioName(Song song) { if ( studio == null ) { return null; } - String name = studio.getName(); - if ( name == null ) { - return null; - } - return name; + return studio.getName(); } private String songArtistLabelStudioCity(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; @@ -149,10 +132,6 @@ private String songArtistLabelStudioCity(Song song) { if ( studio == null ) { return null; } - String city = studio.getCity(); - if ( city == null ) { - return null; - } - return city; + return studio.getCity(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java index 0413ef5b79..cbd125366e 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/constructor/nestedtarget/ChartEntryToArtistImpl.java @@ -132,24 +132,14 @@ protected Song chartEntryToSong(ChartEntry chartEntry) { } private String chartSongTitle(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; } - String title = song.getTitle(); - if ( title == null ) { - return null; - } - return title; + return song.getTitle(); } private String chartSongArtistName(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -158,17 +148,10 @@ private String chartSongArtistName(Chart chart) { if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { - return null; - } - return name; + return artist.getName(); } private String chartSongArtistLabelStudioName(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -185,17 +168,10 @@ private String chartSongArtistLabelStudioName(Chart chart) { if ( studio == null ) { return null; } - String name = studio.getName(); - if ( name == null ) { - return null; - } - return name; + return studio.getName(); } private String chartSongArtistLabelStudioCity(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -212,25 +188,14 @@ private String chartSongArtistLabelStudioCity(Chart chart) { if ( studio == null ) { return null; } - String city = studio.getCity(); - if ( city == null ) { - return null; - } - return city; + return studio.getCity(); } private List chartSongPositions(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; } - List positions = song.getPositions(); - if ( positions == null ) { - return null; - } - return positions; + return song.getPositions(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index 3642d15340..dc70a28ce8 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -159,18 +159,11 @@ protected WaterQualityDto waterQualityToWaterQualityDto(WaterQuality waterQualit } private Ornament sourceInteriorOrnament(FishTank fishTank) { - if ( fishTank == null ) { - return null; - } Interior interior = fishTank.getInterior(); if ( interior == null ) { return null; } - Ornament ornament = interior.getOrnament(); - if ( ornament == null ) { - return null; - } - return ornament; + return interior.getOrnament(); } protected OrnamentDto ornamentToOrnamentDto(Ornament ornament) { @@ -295,18 +288,11 @@ protected Interior fishTankDtoToInterior(FishTankDto fishTankDto) { } private String waterQualityReportDtoOrganisationName(WaterQualityReportDto waterQualityReportDto) { - if ( waterQualityReportDto == null ) { - return null; - } WaterQualityOrganisationDto organisation = waterQualityReportDto.getOrganisation(); if ( organisation == null ) { return null; } - String name = organisation.getName(); - if ( name == null ) { - return null; - } - return name; + return organisation.getName(); } protected WaterQualityReport waterQualityReportDtoToWaterQualityReport(WaterQualityReportDto waterQualityReportDto) { @@ -335,18 +321,11 @@ protected WaterQuality waterQualityDtoToWaterQuality(WaterQualityDto waterQualit } private MaterialTypeDto sourceMaterialMaterialType(FishTankDto fishTankDto) { - if ( fishTankDto == null ) { - return null; - } MaterialDto material = fishTankDto.getMaterial(); if ( material == null ) { return null; } - MaterialTypeDto materialType = material.getMaterialType(); - if ( materialType == null ) { - return null; - } - return materialType; + return material.getMaterialType(); } protected MaterialType materialTypeDtoToMaterialType(MaterialTypeDto materialTypeDto) { diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java index 131566ad4f..e43534dc84 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedsourceproperties/ArtistToChartEntryImpl.java @@ -74,24 +74,14 @@ public ChartEntry map(Chart name) { } private String songArtistName(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { - return null; - } - return name; + return artist.getName(); } private String songArtistLabelStudioName(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; @@ -104,17 +94,10 @@ private String songArtistLabelStudioName(Song song) { if ( studio == null ) { return null; } - String name = studio.getName(); - if ( name == null ) { - return null; - } - return name; + return studio.getName(); } private String songArtistLabelStudioCity(Song song) { - if ( song == null ) { - return null; - } Artist artist = song.getArtist(); if ( artist == null ) { return null; @@ -127,10 +110,6 @@ private String songArtistLabelStudioCity(Song song) { if ( studio == null ) { return null; } - String city = studio.getCity(); - if ( city == null ) { - return null; - } - return city; + return studio.getCity(); } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java index 8877bd421f..725f5b8efe 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedtargetproperties/ChartEntryToArtistImpl.java @@ -198,24 +198,14 @@ protected void chartEntryToSong2(ChartEntry chartEntry, Song mappingTarget) { } private String chartSongTitle(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; } - String title = song.getTitle(); - if ( title == null ) { - return null; - } - return title; + return song.getTitle(); } private String chartSongArtistName(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -224,17 +214,10 @@ private String chartSongArtistName(Chart chart) { if ( artist == null ) { return null; } - String name = artist.getName(); - if ( name == null ) { - return null; - } - return name; + return artist.getName(); } private String chartSongArtistLabelStudioName(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -251,17 +234,10 @@ private String chartSongArtistLabelStudioName(Chart chart) { if ( studio == null ) { return null; } - String name = studio.getName(); - if ( name == null ) { - return null; - } - return name; + return studio.getName(); } private String chartSongArtistLabelStudioCity(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; @@ -278,25 +254,14 @@ private String chartSongArtistLabelStudioCity(Chart chart) { if ( studio == null ) { return null; } - String city = studio.getCity(); - if ( city == null ) { - return null; - } - return city; + return studio.getCity(); } private List chartSongPositions(Chart chart) { - if ( chart == null ) { - return null; - } Song song = chart.getSong(); if ( song == null ) { return null; } - List positions = song.getPositions(); - if ( positions == null ) { - return null; - } - return positions; + return song.getPositions(); } } From 51f4e7eba9c65d9078491711d616c7b5b38ecc1a Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Wed, 24 May 2023 06:04:13 +0200 Subject: [PATCH 0771/1006] #3231 Prefer record constructor annotated with `@Default` --- .../org/mapstruct/itest/records/Default.java | 21 ++++++++++++++++++ .../org/mapstruct/itest/records/Task.java | 15 +++++++++++++ .../org/mapstruct/itest/records/TaskDto.java | 20 +++++++++++++++++ .../mapstruct/itest/records/TaskMapper.java | 22 +++++++++++++++++++ .../mapstruct/itest/records/RecordsTest.java | 12 ++++++++++ .../ap/internal/model/BeanMappingMethod.java | 18 ++++++++++++++- 6 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Default.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Task.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskDto.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskMapper.java diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Default.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Default.java new file mode 100644 index 0000000000..b845bdd730 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Default.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Filip Hrisafov + */ +@Documented +@Target(ElementType.CONSTRUCTOR) +@Retention(RetentionPolicy.SOURCE) +public @interface Default { +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Task.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Task.java new file mode 100644 index 0000000000..3f990fc89a --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/Task.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import java.util.List; + +/** + * @author Oliver Erhart + */ +public record Task( String id, Long number ) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskDto.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskDto.java new file mode 100644 index 0000000000..1ba6eb2be9 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import java.util.List; + +/** + * @author Oliver Erhart + */ +public record TaskDto(String id, Long number) { + + @Default + TaskDto(String id) { + this( id, 1L ); + } + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskMapper.java new file mode 100644 index 0000000000..8d9da767cd --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/TaskMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Oliver Erhart + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface TaskMapper { + + TaskMapper INSTANCE = Mappers.getMapper( TaskMapper.class ); + + TaskDto toRecord(Task source); + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index e98df8797e..2f77e8d49f 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -83,4 +83,16 @@ public void shouldMapIntoMemberRecord() { assertThat( value.isActive() ).isEqualTo( false ); assertThat( value.premium() ).isEqualTo( true ); } + + @Test + public void shouldUseDefaultConstructor() { + Task entity = new Task( "some-id", 1000L ); + + TaskDto value = TaskMapper.INSTANCE.toRecord( entity ); + + assertThat( value ).isNotNull(); + assertThat( value.id() ).isEqualTo( "some-id" ); + assertThat( value.number() ).isEqualTo( 1L ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b6afce74d2..9d0acea91b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -791,7 +791,23 @@ private ConstructorAccessor getConstructorAccessor(Type type) { } if ( type.isRecord() ) { - // If the type is a record then just get the record components and use then + + List constructors = ElementFilter.constructorsIn( type.getTypeElement() + .getEnclosedElements() ); + + for ( ExecutableElement constructor : constructors ) { + if ( constructor.getModifiers().contains( Modifier.PRIVATE ) ) { + continue; + } + + // prefer constructor annotated with @Default + if ( hasDefaultAnnotationFromAnyPackage( constructor ) ) { + return getConstructorAccessor( type, constructor ); + } + } + + + // Other than that, just get the record components and use them List recordComponents = type.getRecordComponents(); List parameterBindings = new ArrayList<>( recordComponents.size() ); Map constructorAccessors = new LinkedHashMap<>(); From c2eed45df12802cacaec158420656431c061471c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 21 May 2023 23:01:58 +0200 Subject: [PATCH 0772/1006] #3126 Apply target this references in the BeanMappingMethod --- .../ap/internal/model/BeanMappingMethod.java | 14 ++- .../model/beanmapping/MappingReferences.java | 30 +----- .../ap/test/bugs/_3126/Issue3126Mapper.java | 92 +++++++++++++++++++ .../ap/test/bugs/_3126/Issue3126Test.java | 28 ++++++ .../nestedbeans/mixed/FishTankMapperImpl.java | 41 +-------- 5 files changed, 137 insertions(+), 68 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 9d0acea91b..361d04b390 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -117,6 +117,7 @@ public static class Builder extends AbstractMappingMethodBuilder> unprocessedDefinedTargets = new LinkedHashMap<>(); private MappingReferences mappingReferences; + private List targetThisReferences; private MethodReference factoryMethod; private boolean hasFactoryMethod; @@ -1068,6 +1069,14 @@ private boolean handleDefinedMappings(Type resultTypeToMap) { for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { if ( mapping.isValid() ) { String target = mapping.getTargetReference().getShallowestPropertyName(); + if ( target == null ) { + // When the shallowest property name is null then it is for @Mapping(target = ".") + if ( this.targetThisReferences == null ) { + this.targetThisReferences = new ArrayList<>(); + } + this.targetThisReferences.add( mapping ); + continue; + } if ( !handledTargets.contains( target ) ) { if ( handleDefinedMapping( mapping, resultTypeToMap, handledTargets ) ) { errorOccurred = true; @@ -1435,8 +1444,11 @@ else if ( mapping.getJavaExpression() != null ) { * duplicates will be handled by {@link #applyPropertyNameBasedMapping(List)} */ private void applyTargetThisMapping() { + if ( this.targetThisReferences == null ) { + return; + } Set handledTargetProperties = new HashSet<>(); - for ( MappingReference targetThis : mappingReferences.getTargetThisReferences() ) { + for ( MappingReference targetThis : this.targetThisReferences ) { // handle all prior unprocessed target properties, but let duplicates fall through List sourceRefs = targetThis diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index 569c75e0eb..ced945bb90 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -5,10 +5,8 @@ */ package org.mapstruct.ap.internal.model.beanmapping; -import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; -import java.util.List; import java.util.Objects; import java.util.Set; @@ -23,7 +21,6 @@ public class MappingReferences { private static final MappingReferences EMPTY = new MappingReferences( Collections.emptySet(), false ); private final Set mappingReferences; - private final List targetThisReferences; private final boolean restrictToDefinedMappings; private final boolean forForgedMethods; @@ -38,7 +35,6 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, TypeFactory typeFactory) { Set references = new LinkedHashSet<>(); - List targetThisReferences = new ArrayList<>( ); for ( MappingOptions mapping : sourceMethod.getOptions().getMappings() ) { @@ -61,30 +57,16 @@ public static MappingReferences forSourceMethod(SourceMethod sourceMethod, // add when inverse is also valid MappingReference mappingReference = new MappingReference( mapping, targetReference, sourceReference ); if ( isValidWhenInversed( mappingReference ) ) { - if ( ".".equals( mapping.getTargetName() ) ) { - targetThisReferences.add( mappingReference ); - } - else { - references.add( mappingReference ); - } + references.add( mappingReference ); } } - return new MappingReferences( references, targetThisReferences, false ); - } - - public MappingReferences(Set mappingReferences, List targetThisReferences, - boolean restrictToDefinedMappings) { - this.mappingReferences = mappingReferences; - this.restrictToDefinedMappings = restrictToDefinedMappings; - this.forForgedMethods = restrictToDefinedMappings; - this.targetThisReferences = targetThisReferences; + return new MappingReferences( references, false ); } public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings) { this.mappingReferences = mappingReferences; this.restrictToDefinedMappings = restrictToDefinedMappings; this.forForgedMethods = restrictToDefinedMappings; - this.targetThisReferences = Collections.emptyList(); } public MappingReferences(Set mappingReferences, boolean restrictToDefinedMappings, @@ -92,7 +74,6 @@ public MappingReferences(Set mappingReferences, boolean restri this.mappingReferences = mappingReferences; this.restrictToDefinedMappings = restrictToDefinedMappings; this.forForgedMethods = forForgedMethods; - this.targetThisReferences = Collections.emptyList(); } public Set getMappingReferences() { @@ -136,10 +117,6 @@ public boolean hasNestedTargetReferences() { return false; } - public List getTargetThisReferences() { - return targetThisReferences; - } - @Override public boolean equals(Object o) { if ( this == o ) { @@ -160,9 +137,6 @@ public boolean equals(Object o) { if ( !Objects.equals( mappingReferences, that.mappingReferences ) ) { return false; } - if ( Objects.equals( targetThisReferences, that.targetThisReferences ) ) { - return false; - } return true; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Mapper.java new file mode 100644 index 0000000000..e680db9317 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Mapper.java @@ -0,0 +1,92 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3126; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) +public interface Issue3126Mapper { + + Issue3126Mapper INSTANCE = Mappers.getMapper( Issue3126Mapper.class ); + + @SubclassMapping(target = HomeAddressDto.class, source = HomeAddress.class) + @SubclassMapping(target = OfficeAddressDto.class, source = OfficeAddress.class) + @Mapping(target = ".", source = "auditable") + AddressDto map(Address address); + + interface AddressDto { + + } + + class HomeAddressDto implements AddressDto { + private String createdBy; + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + } + + class OfficeAddressDto implements AddressDto { + private String createdBy; + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + } + + class HomeAddress extends Address { + + public HomeAddress(Auditable auditable) { + super( auditable ); + } + } + + class OfficeAddress extends Address { + + public OfficeAddress(Auditable auditable) { + super( auditable ); + } + } + + abstract class Address { + + private final Auditable auditable; + + protected Address(Auditable auditable) { + this.auditable = auditable; + } + + public Auditable getAuditable() { + return auditable; + } + } + + class Auditable { + + private final String createdBy; + + public Auditable(String createdBy) { + this.createdBy = createdBy; + } + + public String getCreatedBy() { + return createdBy; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Test.java new file mode 100644 index 0000000000..35e3eb873c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3126/Issue3126Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3126; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3126") +@WithClasses(Issue3126Mapper.class) +class Issue3126Test { + + @ProcessorTest + void shouldCompile() { + Issue3126Mapper.Auditable auditable = new Issue3126Mapper.Auditable( "home-user" ); + Issue3126Mapper.Address address = new Issue3126Mapper.HomeAddress( auditable ); + Issue3126Mapper.AddressDto addressDto = Issue3126Mapper.INSTANCE.map( address ); + + assertThat( addressDto ).isInstanceOfSatisfying( Issue3126Mapper.HomeAddressDto.class, homeAddress -> { + assertThat( homeAddress.getCreatedBy() ).isEqualTo( "home-user" ); + } ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java index dc70a28ce8..b98223fa6f 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/nestedbeans/mixed/FishTankMapperImpl.java @@ -57,9 +57,9 @@ public FishTankDto mapAsWell(FishTank source) { FishTankDto fishTankDto = new FishTankDto(); - fishTankDto.setFish( fishToFishDto1( source.getFish() ) ); + fishTankDto.setFish( fishToFishDto( source.getFish() ) ); fishTankDto.setMaterial( fishTankToMaterialDto1( source ) ); - fishTankDto.setQuality( waterQualityToWaterQualityDto1( source.getQuality() ) ); + fishTankDto.setQuality( waterQualityToWaterQualityDto( source.getQuality() ) ); fishTankDto.setOrnament( ornamentToOrnamentDto( sourceInteriorOrnament( source ) ) ); fishTankDto.setPlant( waterPlantToWaterPlantDto( source.getPlant() ) ); fishTankDto.setName( source.getName() ); @@ -190,18 +190,6 @@ protected WaterPlantDto waterPlantToWaterPlantDto(WaterPlant waterPlant) { return waterPlantDto; } - protected FishDto fishToFishDto1(Fish fish) { - if ( fish == null ) { - return null; - } - - FishDto fishDto = new FishDto(); - - fishDto.setKind( fish.getType() ); - - return fishDto; - } - protected MaterialDto fishTankToMaterialDto1(FishTank fishTank) { if ( fishTank == null ) { return null; @@ -226,31 +214,6 @@ protected WaterQualityOrganisationDto waterQualityReportToWaterQualityOrganisati return waterQualityOrganisationDto; } - protected WaterQualityReportDto waterQualityReportToWaterQualityReportDto1(WaterQualityReport waterQualityReport) { - if ( waterQualityReport == null ) { - return null; - } - - WaterQualityReportDto waterQualityReportDto = new WaterQualityReportDto(); - - waterQualityReportDto.setOrganisation( waterQualityReportToWaterQualityOrganisationDto1( waterQualityReport ) ); - waterQualityReportDto.setVerdict( waterQualityReport.getVerdict() ); - - return waterQualityReportDto; - } - - protected WaterQualityDto waterQualityToWaterQualityDto1(WaterQuality waterQuality) { - if ( waterQuality == null ) { - return null; - } - - WaterQualityDto waterQualityDto = new WaterQualityDto(); - - waterQualityDto.setReport( waterQualityReportToWaterQualityReportDto1( waterQuality.getReport() ) ); - - return waterQualityDto; - } - protected Fish fishDtoToFish(FishDto fishDto) { if ( fishDto == null ) { return null; From 62d1bd3490974468494853a46ec79f6bd5904bdd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 27 May 2023 15:04:34 +0200 Subject: [PATCH 0773/1006] #3280 Refactor method selection and use a context to be able to more easily access information --- .../model/LifecycleMethodResolver.java | 12 +- .../model/ObjectFactoryMethodResolver.java | 10 +- .../model/PresenceCheckMethodResolver.java | 12 +- .../selector/CreateOrUpdateSelector.java | 11 +- .../selector/FactoryParameterSelector.java | 9 +- .../source/selector/InheritanceSelector.java | 14 +- .../source/selector/MethodFamilySelector.java | 10 +- .../model/source/selector/MethodSelector.java | 15 +- .../source/selector/MethodSelectors.java | 28 +- .../MostSpecificResultTypeSelector.java | 8 +- .../source/selector/QualifierSelector.java | 9 +- .../source/selector/SelectionContext.java | 240 ++++++++++++++++++ .../source/selector/SourceRhsSelector.java | 8 +- .../source/selector/TargetTypeSelector.java | 10 +- .../model/source/selector/TypeSelector.java | 112 +------- .../selector/XmlElementDeclSelector.java | 12 +- .../creation/MappingResolverImpl.java | 10 +- 17 files changed, 302 insertions(+), 228 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index 8b44dee254..b713fa5f0c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -6,7 +6,6 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -19,7 +18,7 @@ import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; -import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.model.source.selector.SelectionContext; /** * Factory for creating lists of appropriate {@link LifecycleCallbackMethodReference}s @@ -134,15 +133,12 @@ private static List collectLifecycleCallbackMe MappingBuilderContext ctx, Set existingVariableNames) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager() ); List> matchingMethods = selectors.getMatchingMethods( - method, callbackMethods, - Collections.emptyList(), - targetType, - method.getResultType(), - SelectionCriteria.forLifecycleMethods( selectionParameters ) ); + SelectionContext.forLifecycleMethods( method, targetType, selectionParameters, ctx.getTypeFactory() ) + ); return toLifecycleCallbackMethodRefs( method, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index aded4cbe5f..4cf653b46b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -23,7 +23,7 @@ import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; -import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.model.source.selector.SelectionContext; import org.mapstruct.ap.internal.util.Message; /** @@ -126,15 +126,11 @@ public static List> getMatchingFactoryMethods( Meth MappingBuilderContext ctx) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager() ); return selectors.getMatchingMethods( - method, getAllAvailableMethods( method, ctx.getSourceModel() ), - java.util.Collections.emptyList(), - alternativeTarget, - alternativeTarget, - SelectionCriteria.forFactoryMethods( selectionParameters ) + SelectionContext.forFactoryMethods( method, alternativeTarget, selectionParameters, ctx.getTypeFactory() ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index 9d4910bdce..a5c873743d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -6,20 +6,18 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.SourceMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; -import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; +import org.mapstruct.ap.internal.model.source.selector.SelectionContext; import org.mapstruct.ap.internal.util.Message; /** @@ -60,18 +58,12 @@ private static SelectedMethod findMatchingPresenceCheckMethod( MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), - ctx.getTypeFactory(), ctx.getMessager() ); - Type booleanType = ctx.getTypeFactory().getType( Boolean.class ); List> matchingMethods = selectors.getMatchingMethods( - method, getAllAvailableMethods( method, ctx.getSourceModel() ), - Collections.emptyList(), - booleanType, - booleanType, - SelectionCriteria.forPresenceCheckMethods( selectionParameters ) + SelectionContext.forPresenceCheckMethods( method, selectionParameters, ctx.getTypeFactory() ) ); if ( matchingMethods.isEmpty() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index ed1c72ab2a..03a671de57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -29,13 +28,9 @@ public class CreateOrUpdateSelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { - + public List> getMatchingMethods(List> methods, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); if ( criteria.isLifecycleCallbackRequired() || criteria.isObjectFactoryRequired() || criteria.isPresenceCheckRequired() ) { return methods; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java index 41d37e8b69..50896195f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/FactoryParameterSelector.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -21,11 +20,9 @@ public class FactoryParameterSelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); if ( !criteria.isObjectFactoryRequired() || methods.size() <= 1 ) { return methods; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index a624c1accb..297dcaa4a3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -22,18 +22,14 @@ public class InheritanceSelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { - if ( sourceTypes.size() != 1 ) { + Type sourceType = context.getSourceType(); + if ( sourceType == null ) { return methods; } - Type singleSourceType = first( sourceTypes ); - List> candidatesWithBestMatchingSourceType = new ArrayList<>(); int bestMatchingSourceTypeDistance = Integer.MAX_VALUE; @@ -41,7 +37,7 @@ public List> getMatchingMethods(Method mapp for ( SelectedMethod method : methods ) { Parameter singleSourceParam = first( method.getMethod().getSourceParameters() ); - int sourceTypeDistance = singleSourceType.distanceTo( singleSourceParam.getType() ); + int sourceTypeDistance = sourceType.distanceTo( singleSourceParam.getType() ); bestMatchingSourceTypeDistance = addToCandidateListIfMinimal( candidatesWithBestMatchingSourceType, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java index 37502ec56d..d81269421f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodFamilySelector.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.List; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -20,12 +19,9 @@ public class MethodFamilySelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); List> result = new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java index 86d35bb3aa..375d5a9bf8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelector.java @@ -7,7 +7,6 @@ import java.util.List; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -23,18 +22,10 @@ interface MethodSelector { * Selects those methods which match the given types and other criteria * * @param either SourceMethod or BuiltInMethod - * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out * @param candidates list of available methods - * @param sourceTypes parameter type(s) that should be matched - * @param mappingTargetType mappingTargetType that should be matched - * @param returnType return type that should be matched - * @param criteria criteria used in the selection process + * @param context the context for the matching * @return list of methods that passes the matching process */ - List> getMatchingMethods(Method mappingMethod, - List> candidates, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria); + List> getMatchingMethods(List> candidates, + SelectionContext context); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index 74fa1a33a3..c14729a90f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -9,8 +9,6 @@ import java.util.Arrays; import java.util.List; -import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -25,11 +23,11 @@ public class MethodSelectors { private final List selectors; - public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFactory typeFactory, + public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, FormattingMessager messager) { selectors = Arrays.asList( new MethodFamilySelector(), - new TypeSelector( typeFactory, messager ), + new TypeSelector( messager ), new QualifierSelector( typeUtils, elementUtils ), new TargetTypeSelector( typeUtils ), new JavaxXmlElementDeclSelector( typeUtils ), @@ -46,20 +44,12 @@ public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, TypeFacto * Selects those methods which match the given types and other criteria * * @param either SourceMethod or BuiltInMethod - * @param mappingMethod mapping method, defined in Mapper for which this selection is carried out * @param methods list of available methods - * @param sourceTypes parameter type(s) that should be matched - * @param mappingTargetType the mapping target type that should be matched - * @param returnType return type that should be matched - * @param criteria criteria used in the selection process + * @param context the selection context that should be used in the matching process * @return list of methods that passes the matching process */ - public List> getMatchingMethods(Method mappingMethod, - List methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List methods, + SelectionContext context) { List> candidates = new ArrayList<>( methods.size() ); for ( T method : methods ) { @@ -67,13 +57,7 @@ public List> getMatchingMethods(Method mapp } for ( MethodSelector selector : selectors ) { - candidates = selector.getMatchingMethods( - mappingMethod, - candidates, - sourceTypes, - mappingTargetType, - returnType, - criteria ); + candidates = selector.getMatchingMethods( candidates, context ); } return candidates; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java index 6e86a30bc7..23af0a55f9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java @@ -17,10 +17,10 @@ public class MostSpecificResultTypeSelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> candidates, - List sourceTypes, Type mappingTargetType, - Type returnType, SelectionCriteria criteria) { + public List> getMatchingMethods(List> candidates, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); + Type mappingTargetType = context.getMappingTargetType(); if ( candidates.size() < 2 || !criteria.isForMapping() || criteria.getQualifyingResultType() != null) { return candidates; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java index 210e462e3e..f2f5b591d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/QualifierSelector.java @@ -49,12 +49,9 @@ public QualifierSelector(TypeUtils typeUtils, ElementUtils elementUtils ) { } @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); int numberOfQualifiersToMatch = 0; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java new file mode 100644 index 0000000000..9e82dae25d --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java @@ -0,0 +1,240 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.SourceRHS; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; +import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.model.source.SelectionParameters; + +/** + * Context passed to the selectors to get the information they need. + * + * @author Filip Hrisafov + */ +public class SelectionContext { + + private final Type sourceType; + private final SelectionCriteria selectionCriteria; + private final Method mappingMethod; + private final Type mappingTargetType; + private final Type returnType; + private final Supplier> parameterBindingsProvider; + private List parameterBindings; + + private SelectionContext(Type sourceType, SelectionCriteria selectionCriteria, Method mappingMethod, + Type mappingTargetType, Type returnType, + Supplier> parameterBindingsProvider) { + this.sourceType = sourceType; + this.selectionCriteria = selectionCriteria; + this.mappingMethod = mappingMethod; + this.mappingTargetType = mappingTargetType; + this.returnType = returnType; + this.parameterBindingsProvider = parameterBindingsProvider; + } + + /** + * @return the source type that should be matched + */ + public Type getSourceType() { + return sourceType; + } + + /** + * @return the criteria used in the selection process + */ + public SelectionCriteria getSelectionCriteria() { + return selectionCriteria; + } + + /** + * @return the mapping target type that should be matched + */ + public Type getMappingTargetType() { + return mappingTargetType; + } + + /** + * @return the return type that should be matched + */ + public Type getReturnType() { + return returnType; + } + + /** + * @return the available parameter bindings for the matching + */ + public List getAvailableParameterBindings() { + if ( this.parameterBindings == null ) { + this.parameterBindings = this.parameterBindingsProvider.get(); + } + return parameterBindings; + } + + /** + * @return the mapping method, defined in Mapper for which this selection is carried out + */ + public Method getMappingMethod() { + return mappingMethod; + } + + public static SelectionContext forMappingMethods(Method mappingMethod, Type source, Type target, + SelectionCriteria criteria, TypeFactory typeFactory) { + return new SelectionContext( + source, + criteria, + mappingMethod, + target, + target, + () -> getAvailableParameterBindingsFromSourceType( + source, + target, + mappingMethod, + typeFactory + ) + ); + } + + public static SelectionContext forLifecycleMethods(Method mappingMethod, Type targetType, + SelectionParameters selectionParameters, + TypeFactory typeFactory) { + SelectionCriteria criteria = SelectionCriteria.forLifecycleMethods( selectionParameters ); + return new SelectionContext( + null, + criteria, + mappingMethod, + targetType, + mappingMethod.getResultType(), + () -> getAvailableParameterBindingsFromMethod( + mappingMethod, + targetType, + criteria.getSourceRHS(), + typeFactory + ) + ); + } + + public static SelectionContext forFactoryMethods(Method mappingMethod, Type alternativeTarget, + SelectionParameters selectionParameters, + TypeFactory typeFactory) { + SelectionCriteria criteria = SelectionCriteria.forFactoryMethods( selectionParameters ); + return new SelectionContext( + null, + criteria, + mappingMethod, + alternativeTarget, + alternativeTarget, + () -> getAvailableParameterBindingsFromMethod( + mappingMethod, + alternativeTarget, + criteria.getSourceRHS(), + typeFactory + ) + ); + } + + public static SelectionContext forPresenceCheckMethods(Method mappingMethod, + SelectionParameters selectionParameters, + TypeFactory typeFactory) { + SelectionCriteria criteria = SelectionCriteria.forPresenceCheckMethods( selectionParameters ); + Type booleanType = typeFactory.getType( Boolean.class ); + return new SelectionContext( + null, + criteria, + mappingMethod, + booleanType, + booleanType, + () -> getAvailableParameterBindingsFromMethod( + mappingMethod, + booleanType, + criteria.getSourceRHS(), + typeFactory + ) + ); + } + + private static List getAvailableParameterBindingsFromMethod(Method method, Type targetType, + SourceRHS sourceRHS, + TypeFactory typeFactory) { + List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); + + if ( sourceRHS != null ) { + availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); + availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); + } + else { + availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); + } + + addTargetRelevantBindings( availableParams, targetType, typeFactory ); + + return availableParams; + } + + private static List getAvailableParameterBindingsFromSourceType(Type sourceType, + Type targetType, + Method mappingMethod, + TypeFactory typeFactory) { + + List availableParams = new ArrayList<>(); + + availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); + + for ( Parameter param : mappingMethod.getParameters() ) { + if ( param.isMappingContext() ) { + availableParams.add( ParameterBinding.fromParameter( param ) ); + } + } + + addTargetRelevantBindings( availableParams, targetType, typeFactory ); + + return availableParams; + } + + /** + * Adds default parameter bindings for the mapping-target and target-type if not already available. + * + * @param availableParams Already available params, new entries will be added to this list + * @param targetType Target type + */ + private static void addTargetRelevantBindings(List availableParams, Type targetType, + TypeFactory typeFactory) { + boolean mappingTargetAvailable = false; + boolean targetTypeAvailable = false; + boolean targetPropertyNameAvailable = false; + + // search available parameter bindings if mapping-target and/or target-type is available + for ( ParameterBinding pb : availableParams ) { + if ( pb.isMappingTarget() ) { + mappingTargetAvailable = true; + } + else if ( pb.isTargetType() ) { + targetTypeAvailable = true; + } + else if ( pb.isTargetPropertyName() ) { + targetPropertyNameAvailable = true; + } + } + + if ( !mappingTargetAvailable ) { + availableParams.add( ParameterBinding.forMappingTargetBinding( targetType ) ); + } + if ( !targetTypeAvailable ) { + availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); + } + if ( !targetPropertyNameAvailable ) { + availableParams.add( ParameterBinding.forTargetPropertyNameBinding( typeFactory.getType( String.class ) ) ); + } + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java index 930ce2d403..fb797f5808 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java @@ -9,7 +9,6 @@ import java.util.List; import org.mapstruct.ap.internal.model.common.ParameterBinding; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -20,10 +19,9 @@ public class SourceRhsSelector implements MethodSelector { @Override - public List> getMatchingMethods(Method mappingMethod, - List> candidates, - List sourceTypes, Type mappingTargetType, - Type returnType, SelectionCriteria criteria) { + public List> getMatchingMethods(List> candidates, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); if ( candidates.size() < 2 || criteria.getSourceRHS() == null ) { return candidates; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java index 38a907aedb..0afae641db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TargetTypeSelector.java @@ -11,7 +11,6 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.util.TypeUtils; -import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; /** @@ -31,12 +30,9 @@ public TargetTypeSelector( TypeUtils typeUtils ) { } @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { + SelectionCriteria criteria = context.getSelectionCriteria(); TypeMirror qualifyingTypeMirror = criteria.getQualifyingResultType(); if ( qualifyingTypeMirror != null && !criteria.isLifecycleCallbackRequired() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 8acdd327c4..24275f594b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -11,9 +11,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; -import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.MethodMatcher; import org.mapstruct.ap.internal.util.FormattingMessager; @@ -29,44 +27,24 @@ */ public class TypeSelector implements MethodSelector { - private TypeFactory typeFactory; private FormattingMessager messager; - public TypeSelector(TypeFactory typeFactory, FormattingMessager messager) { - this.typeFactory = typeFactory; + public TypeSelector(FormattingMessager messager) { this.messager = messager; } @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { - + public List> getMatchingMethods(List> methods, + SelectionContext context) { if ( methods.isEmpty() ) { return methods; } + Type returnType = context.getReturnType(); + List> result = new ArrayList<>(); - List availableBindings; - if ( sourceTypes.isEmpty() ) { - // if no source types are given, we have a factory or lifecycle method - availableBindings = getAvailableParameterBindingsFromMethod( - mappingMethod, - mappingTargetType, - criteria.getSourceRHS() - ); - } - else { - availableBindings = getAvailableParameterBindingsFromSourceTypes( - sourceTypes, - mappingTargetType, - mappingMethod - ); - } + List availableBindings = context.getAvailableParameterBindings(); for ( SelectedMethod method : methods ) { List> parameterBindingPermutations = @@ -74,7 +52,7 @@ public List> getMatchingMethods(Method mapp if ( parameterBindingPermutations != null ) { SelectedMethod matchingMethod = - getMatchingParameterBinding( returnType, mappingMethod, method, parameterBindingPermutations ); + getMatchingParameterBinding( returnType, context, method, parameterBindingPermutations ); if ( matchingMethod != null ) { result.add( matchingMethod ); @@ -84,80 +62,8 @@ public List> getMatchingMethods(Method mapp return result; } - private List getAvailableParameterBindingsFromMethod(Method method, Type targetType, - SourceRHS sourceRHS) { - List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); - - if ( sourceRHS != null ) { - availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); - availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); - } - else { - availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); - } - - addTargetRelevantBindings( availableParams, targetType ); - - return availableParams; - } - - private List getAvailableParameterBindingsFromSourceTypes(List sourceTypes, - Type targetType, Method mappingMethod) { - - List availableParams = new ArrayList<>( sourceTypes.size() + 2 ); - - for ( Type sourceType : sourceTypes ) { - availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); - } - - for ( Parameter param : mappingMethod.getParameters() ) { - if ( param.isMappingContext() ) { - availableParams.add( ParameterBinding.fromParameter( param ) ); - } - } - - addTargetRelevantBindings( availableParams, targetType ); - - return availableParams; - } - - /** - * Adds default parameter bindings for the mapping-target and target-type if not already available. - * - * @param availableParams Already available params, new entries will be added to this list - * @param targetType Target type - */ - private void addTargetRelevantBindings(List availableParams, Type targetType) { - boolean mappingTargetAvailable = false; - boolean targetTypeAvailable = false; - boolean targetPropertyNameAvailable = false; - - // search available parameter bindings if mapping-target and/or target-type is available - for ( ParameterBinding pb : availableParams ) { - if ( pb.isMappingTarget() ) { - mappingTargetAvailable = true; - } - else if ( pb.isTargetType() ) { - targetTypeAvailable = true; - } - else if ( pb.isTargetPropertyName() ) { - targetPropertyNameAvailable = true; - } - } - - if ( !mappingTargetAvailable ) { - availableParams.add( ParameterBinding.forMappingTargetBinding( targetType ) ); - } - if ( !targetTypeAvailable ) { - availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); - } - if ( !targetPropertyNameAvailable ) { - availableParams.add( ParameterBinding.forTargetPropertyNameBinding( typeFactory.getType( String.class ) ) ); - } - } - private SelectedMethod getMatchingParameterBinding(Type returnType, - Method mappingMethod, SelectedMethod selectedMethodInfo, + SelectionContext context, SelectedMethod selectedMethodInfo, List> parameterAssignmentVariants) { List> matchingParameterAssignmentVariants = new ArrayList<>( @@ -200,7 +106,7 @@ else if ( matchingParameterAssignmentVariants.size() == 1 ) { messager.printMessage( selectedMethod.getExecutable(), Message.LIFECYCLEMETHOD_AMBIGUOUS_PARAMETERS, - mappingMethod + context.getMappingMethod() ); return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java index 91b4b5ca10..a32cb250d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/XmlElementDeclSelector.java @@ -45,18 +45,16 @@ abstract class XmlElementDeclSelector implements MethodSelector { } @Override - public List> getMatchingMethods(Method mappingMethod, - List> methods, - List sourceTypes, - Type mappingTargetType, - Type returnType, - SelectionCriteria criteria) { + public List> getMatchingMethods(List> methods, + SelectionContext context) { + Type resultType = context.getMappingMethod().getResultType(); + String targetPropertyName = context.getSelectionCriteria().getTargetPropertyName(); List> nameMatches = new ArrayList<>(); List> scopeMatches = new ArrayList<>(); List> nameAndScopeMatches = new ArrayList<>(); XmlElementRefInfo xmlElementRefInfo = - findXmlElementRef( mappingMethod.getResultType(), criteria.getTargetPropertyName() ); + findXmlElementRef( resultType, targetPropertyName ); for ( SelectedMethod candidate : methods ) { if ( !( candidate.getMethod() instanceof SourceMethod ) ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 0c8e2cc4c4..586465d5f1 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.internal.processor.creation; -import static java.util.Collections.singletonList; import static org.mapstruct.ap.internal.util.Collections.first; import static org.mapstruct.ap.internal.util.Collections.firstKey; import static org.mapstruct.ap.internal.util.Collections.firstValue; @@ -57,6 +56,7 @@ import org.mapstruct.ap.internal.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; +import org.mapstruct.ap.internal.model.source.selector.SelectionContext; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Collections; import org.mapstruct.ap.internal.util.ElementUtils; @@ -116,7 +116,7 @@ public MappingResolverImpl(FormattingMessager messager, ElementUtils elementUtil this.conversions = new Conversions( typeFactory ); this.builtInMethods = new BuiltInMappingMethods( typeFactory ); - this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, typeFactory, messager ); + this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, messager ); this.verboseLogging = verboseLogging; } @@ -491,12 +491,8 @@ private boolean isUpdateMethodForMapping(Method methodCandidate) { private List> getBestMatch(List methods, Type source, Type target) { return methodSelectors.getMatchingMethods( - mappingMethod, methods, - singletonList( source ), - target, - target, - selectionCriteria + SelectionContext.forMappingMethods( mappingMethod, source, target, selectionCriteria, typeFactory ) ); } From d075d9a5b69a2377069dc0a9de86613dff8c2619 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 24 May 2023 06:09:57 +0200 Subject: [PATCH 0774/1006] Upgrade Freemarker to 2.3.32 --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 6e9c2836b6..f9531590f6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -109,7 +109,7 @@ org.freemarker freemarker - 2.3.31 + 2.3.32 org.assertj From 86919c637f228ec3a668f8140b9b68e2092f5189 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 May 2023 09:55:40 +0200 Subject: [PATCH 0775/1006] #3144 Map to Bean should only be possible for single source mappings and if explicitly used in multi source mappings --- .../ap/internal/model/BeanMappingMethod.java | 16 +++-- .../NestedTargetPropertyMappingHolder.java | 5 +- .../model/beanmapping/SourceReference.java | 23 +++++-- .../ap/internal/model/common/Type.java | 4 +- .../ap/test/bugs/_3144/Issue3144Mapper.java | 66 +++++++++++++++++++ .../ap/test/bugs/_3144/Issue3144Test.java | 63 ++++++++++++++++++ .../MapToBeanUsingMappingMethodMapper.java | 2 +- 7 files changed, 165 insertions(+), 14 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 361d04b390..903dfa5cc5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -586,7 +586,7 @@ private void handleUnprocessedDefinedTargets() { .build(); ReadAccessor targetPropertyReadAccessor = - method.getResultType().getReadAccessor( propertyName ); + method.getResultType().getReadAccessor( propertyName, forceUpdateMethod ); MappingReferences mappingRefs = extractMappingReferences( propertyName, true ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) @@ -1160,7 +1160,10 @@ private boolean handleDefinedMapping(MappingReference mappingRef, Type resultTyp } Accessor targetWriteAccessor = unprocessedTargetProperties.get( targetPropertyName ); - ReadAccessor targetReadAccessor = resultTypeToMap.getReadAccessor( targetPropertyName ); + ReadAccessor targetReadAccessor = resultTypeToMap.getReadAccessor( + targetPropertyName, + method.getSourceParameters().size() == 1 + ); if ( targetWriteAccessor == null ) { if ( targetReadAccessor == null ) { @@ -1513,7 +1516,8 @@ private void applyPropertyNameBasedMapping(List sourceReference } ReadAccessor targetPropertyReadAccessor = - method.getResultType().getReadAccessor( targetPropertyName ); + method.getResultType() + .getReadAccessor( targetPropertyName, method.getSourceParameters().size() == 1 ); MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) .sourceMethod( method ) @@ -1556,7 +1560,8 @@ private void applyParameterNameBasedMapping() { .build(); ReadAccessor targetPropertyReadAccessor = - method.getResultType().getReadAccessor( targetProperty.getKey() ); + method.getResultType() + .getReadAccessor( targetProperty.getKey(), method.getSourceParameters().size() == 1 ); MappingReferences mappingRefs = extractMappingReferences( targetProperty.getKey(), false ); PropertyMapping propertyMapping = new PropertyMappingBuilder() .mappingContext( ctx ) @@ -1600,7 +1605,8 @@ private SourceReference getSourceRefByTargetName(Parameter sourceParameter, Stri return sourceRef; } - ReadAccessor sourceReadAccessor = sourceParameter.getType().getReadAccessor( targetPropertyName ); + ReadAccessor sourceReadAccessor = sourceParameter.getType() + .getReadAccessor( targetPropertyName, method.getSourceParameters().size() == 1 ); if ( sourceReadAccessor != null ) { // property mapping PresenceCheckAccessor sourcePresenceChecker = diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 61e3926047..b7bfc69780 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -643,7 +643,10 @@ private PropertyMapping createPropertyMappingForNestedTarget(MappingReferences m boolean forceUpdateMethod) { Accessor targetWriteAccessor = targetPropertiesWriteAccessors.get( targetPropertyName ); - ReadAccessor targetReadAccessor = targetType.getReadAccessor( targetPropertyName ); + ReadAccessor targetReadAccessor = targetType.getReadAccessor( + targetPropertyName, + method.getSourceParameters().size() == 1 + ); if ( targetWriteAccessor == null ) { Set readAccessors = targetType.getPropertyReadAccessors().keySet(); String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 4e7dad220c..73ec84b6b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -152,15 +152,27 @@ public SourceReference build() { private SourceReference buildFromSingleSourceParameters(String[] segments, Parameter parameter) { boolean foundEntryMatch; + boolean allowedMapToBean = false; + if ( segments.length > 0 ) { + if ( parameter.getType().isMapType() ) { + // When the parameter type is a map and the parameter name matches the first segment + // then the first segment should not be treated as a property of the map + allowedMapToBean = !segments[0].equals( parameter.getName() ); + } + } String[] propertyNames = segments; - List entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + List entries = matchWithSourceAccessorTypes( + parameter.getType(), + propertyNames, + allowedMapToBean + ); foundEntryMatch = ( entries.size() == propertyNames.length ); if ( !foundEntryMatch ) { //Lets see if the expression contains the parameterName, so parameterName.propName1.propName2 if ( getSourceParameterFromMethodOrTemplate( segments[0] ) != null ) { propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames, true ); foundEntryMatch = ( entries.size() == propertyNames.length ); } else { @@ -193,7 +205,7 @@ private SourceReference buildFromMultipleSourceParameters(String[] segments, Par if ( segments.length > 1 && parameter != null ) { propertyNames = Arrays.copyOfRange( segments, 1, segments.length ); - entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames ); + entries = matchWithSourceAccessorTypes( parameter.getType(), propertyNames, true ); foundEntryMatch = ( entries.size() == propertyNames.length ); } else { @@ -306,13 +318,14 @@ private void reportErrorOnNoMatch( Parameter parameter, String[] propertyNames, } } - private List matchWithSourceAccessorTypes(Type type, String[] entryNames) { + private List matchWithSourceAccessorTypes(Type type, String[] entryNames, + boolean allowedMapToBean) { List sourceEntries = new ArrayList<>(); Type newType = type; for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; Type noBoundsType = newType.withoutBounds(); - ReadAccessor readAccessor = noBoundsType.getReadAccessor( entryNames[i] ); + ReadAccessor readAccessor = noBoundsType.getReadAccessor( entryNames[i], i > 0 || allowedMapToBean ); if ( readAccessor != null ) { PresenceCheckAccessor presenceChecker = noBoundsType.getPresenceChecker( entryNames[i] ); newType = typeFactory.getReturnType( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 4254913d83..93358c2a27 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -652,8 +652,8 @@ public Type asRawType() { } } - public ReadAccessor getReadAccessor(String propertyName) { - if ( hasStringMapSignature() ) { + public ReadAccessor getReadAccessor(String propertyName, boolean allowedMapToBean) { + if ( allowedMapToBean && hasStringMapSignature() ) { ExecutableElement getMethod = getAllMethods() .stream() .filter( m -> m.getSimpleName().contentEquals( "get" ) ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Mapper.java new file mode 100644 index 0000000000..df5b767876 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Mapper.java @@ -0,0 +1,66 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3144; + +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface Issue3144Mapper { + + Issue3144Mapper INSTANCE = Mappers.getMapper( Issue3144Mapper.class ); + + @Mapping(target = "map", source = "sourceMap") + Target mapExplicitDefined(Map sourceMap); + + @Mapping(target = "map", ignore = true) + Target map(Map sourceMap); + + Target mapMultiParameters(Source source, Map map); + + @Mapping(target = "value", source = "map.testValue") + Target mapMultiParametersDefinedMapping(Source source, Map map); + + class Source { + private final String sourceValue; + + public Source(String sourceValue) { + this.sourceValue = sourceValue; + } + + public String getSourceValue() { + return sourceValue; + } + } + + class Target { + private String value; + private Map map; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Test.java new file mode 100644 index 0000000000..13f349414a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3144/Issue3144Test.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3144; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3144Mapper.class) +@IssueKey("3144") +class Issue3144Test { + + @ProcessorTest + void shouldCorrectlyHandleMapBeanMapping() { + Map map = new HashMap<>(); + map.put( "value", "Map Value" ); + map.put( "testValue", "Map Test Value" ); + + Issue3144Mapper.Target target = Issue3144Mapper.INSTANCE.mapExplicitDefined( map ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "Map Value" ); + assertThat( target.getMap() ) + .containsOnly( + entry( "value", "Map Value" ), + entry( "testValue", "Map Test Value" ) + ); + + target = Issue3144Mapper.INSTANCE.map( map ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "Map Value" ); + assertThat( target.getMap() ).isNull(); + + target = Issue3144Mapper.INSTANCE.mapMultiParameters( null, map ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + assertThat( target.getMap() ) + .containsOnly( + entry( "value", "Map Value" ), + entry( "testValue", "Map Test Value" ) + ); + + target = Issue3144Mapper.INSTANCE.mapMultiParametersDefinedMapping( null, map ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "Map Test Value" ); + assertThat( target.getMap() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java index 9a6344ff15..225ca00adc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanUsingMappingMethodMapper.java @@ -19,7 +19,7 @@ public interface MapToBeanUsingMappingMethodMapper { MapToBeanUsingMappingMethodMapper INSTANCE = Mappers.getMapper( MapToBeanUsingMappingMethodMapper.class ); - @Mapping(target = "normalInt", source = "number") + @Mapping(target = "normalInt", source = "source.number") Target toTarget(Map source); default String mapIntegerToString( Integer input ) { From 1b1325da6d27ecc995aa659551c98dcf4ee764a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Jun 2023 22:28:38 +0000 Subject: [PATCH 0776/1006] Bump guava from 29.0-jre to 32.0.0-jre in /parent Bumps [guava](https://github.com/google/guava) from 29.0-jre to 32.0.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index f9531590f6..32f7e2897a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -119,7 +119,7 @@ com.google.guava guava - 29.0-jre + 32.0.0-jre org.mapstruct.tools.gem From 04434af17a1195268af14b9775c93d48936f7e6e Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sat, 8 Jul 2023 18:03:56 +0200 Subject: [PATCH 0777/1006] #3296: Skip default and static methods when determining prototype methods --- .../processor/MethodRetrievalProcessor.java | 5 +++ .../mapstruct/ap/test/bugs/_3296/Entity.java | 18 ++++++++ .../ap/test/bugs/_3296/Issue3296Test.java | 43 +++++++++++++++++++ .../MapperConfigWithPayloadArgument.java | 24 +++++++++++ .../MapperConfigWithoutPayloadArgument.java | 23 ++++++++++ .../bugs/_3296/MapperExtendingConfig.java | 13 ++++++ .../bugs/_3296/MapperNotExtendingConfig.java | 13 ++++++ .../mapstruct/ap/test/bugs/_3296/Payload.java | 19 ++++++++ 8 files changed, 158 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Entity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Issue3296Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithPayloadArgument.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithoutPayloadArgument.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperExtendingConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperNotExtendingConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Payload.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 6f1febae9d..faf7a786fd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -124,6 +124,11 @@ private List retrievePrototypeMethods(TypeElement mapperTypeElemen List methods = new ArrayList<>(); for ( ExecutableElement executable : elementUtils.getAllEnclosedExecutableElements( typeElement ) ) { + if ( executable.isDefault() || executable.getModifiers().contains( Modifier.STATIC ) ) { + // skip the default and static methods because these are not prototypes. + continue; + } + ExecutableType methodType = typeFactory.getMethodType( mapperAnnotation.mapperConfigType(), executable ); List parameters = typeFactory.getParameters( methodType, executable ); boolean containsTargetTypeParameter = SourceMethod.containsTargetTypeParameter( parameters ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Entity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Entity.java new file mode 100644 index 0000000000..cfd038b03c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Entity.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +public class Entity { + String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Issue3296Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Issue3296Test.java new file mode 100644 index 0000000000..941eee9a70 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Issue3296Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.factory.Mappers; + +/** + * @author Ben Zegveld + */ +@IssueKey( "3296" ) +@WithClasses( { Entity.class, Payload.class } ) +public class Issue3296Test { + + @ProcessorTest + @WithClasses( { MapperExtendingConfig.class, MapperConfigWithPayloadArgument.class } ) + public void shouldNotRaiseErrorForDefaultAfterMappingMethodImplementation() { + Payload payload = new Payload(); + payload.setName( "original" ); + + Entity entity = Mappers.getMapper( MapperExtendingConfig.class ).toEntity( payload ); + + assertThat( entity.getName() ).isEqualTo( "AfterMapping called" ); + } + + @ProcessorTest + @WithClasses( { MapperNotExtendingConfig.class, MapperConfigWithoutPayloadArgument.class } ) + public void shouldNotRaiseErrorRequiringArgumentsForDefaultMethods() { + Payload payload = new Payload(); + payload.setName( "original" ); + + Entity entity = Mappers.getMapper( MapperNotExtendingConfig.class ).toEntity( payload ); + + assertThat( entity.getName() ).isEqualTo( "original" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithPayloadArgument.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithPayloadArgument.java new file mode 100644 index 0000000000..69826aa10e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithPayloadArgument.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +import org.mapstruct.AfterMapping; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingTarget; + +@MapperConfig +public interface MapperConfigWithPayloadArgument { + + @AfterMapping + default void afterMapping(@MappingTarget Entity entity, Payload unused) { + staticMethod( entity ); + } + + static void staticMethod(Entity entity) { + entity.setName( "AfterMapping called" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithoutPayloadArgument.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithoutPayloadArgument.java new file mode 100644 index 0000000000..36cc046d12 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperConfigWithoutPayloadArgument.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +import org.mapstruct.AfterMapping; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingTarget; + +@MapperConfig +public interface MapperConfigWithoutPayloadArgument { + + @AfterMapping + default void afterMapping(@MappingTarget Entity entity) { + staticMethod( entity ); + } + + static void staticMethod(Entity entity) { + entity.setName( "AfterMapping called" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperExtendingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperExtendingConfig.java new file mode 100644 index 0000000000..157bd051cb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperExtendingConfig.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +import org.mapstruct.Mapper; + +@Mapper( config = MapperConfigWithPayloadArgument.class ) +public interface MapperExtendingConfig extends MapperConfigWithPayloadArgument { + Entity toEntity(Payload payload); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperNotExtendingConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperNotExtendingConfig.java new file mode 100644 index 0000000000..2ceb18c253 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/MapperNotExtendingConfig.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +import org.mapstruct.Mapper; + +@Mapper( config = MapperConfigWithoutPayloadArgument.class ) +public interface MapperNotExtendingConfig { + Entity toEntity(Payload payload); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Payload.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Payload.java new file mode 100644 index 0000000000..2502e5e4a2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3296/Payload.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3296; + +public class Payload { + + String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} From 53c73324ff85e0b718d2a8f2f64bcdbb9256632b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 8 Jul 2023 17:45:00 +0200 Subject: [PATCH 0778/1006] #3310 Make sure that adders work properly when they are in a generic class --- .../ap/internal/model/common/Type.java | 5 +- .../ap/test/bugs/_3310/Issue3310Mapper.java | 61 +++++++++++++++++++ .../ap/test/bugs/_3310/Issue3310Test.java | 31 ++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 93358c2a27..933f1f6ce0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -958,9 +958,8 @@ private List getAccessorCandidates(Type property, Class superclass) List adderList = getAdders(); List candidateList = new ArrayList<>(); for ( Accessor adder : adderList ) { - ExecutableElement executable = (ExecutableElement) adder.getElement(); - VariableElement arg = executable.getParameters().get( 0 ); - if ( typeUtils.isSameType( boxed( arg.asType() ), boxed( typeArg ) ) ) { + TypeMirror adderParameterType = determineTargetType( adder ).getTypeMirror(); + if ( typeUtils.isSameType( boxed( adderParameterType ), boxed( typeArg ) ) ) { candidateList.add( adder ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Mapper.java new file mode 100644 index 0000000000..2975a5de8a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Mapper.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3310; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface Issue3310Mapper { + + Issue3310Mapper INSTANCE = Mappers.getMapper( Issue3310Mapper.class ); + + Target map(Source source); + + abstract class BaseClass { + + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + throw new UnsupportedOperationException( "adder should be used instead" ); + } + + public void addItem(T item) { + if ( items == null ) { + items = new ArrayList<>(); + } + items.add( item ); + } + } + + class Target extends BaseClass { + + } + + class Source { + + private final List items; + + public Source(List items) { + this.items = items; + } + + public List getItems() { + return items; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Test.java new file mode 100644 index 0000000000..a00526985f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3310/Issue3310Test.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3310; + +import java.util.Collections; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3310") +@WithClasses(Issue3310Mapper.class) +class Issue3310Test { + + @ProcessorTest + void shouldUseAdderWithGenericBaseClass() { + Issue3310Mapper.Source source = new Issue3310Mapper.Source( Collections.singletonList( "test" ) ); + Issue3310Mapper.Target target = Issue3310Mapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getItems() ).containsExactly( "test" ); + } +} From 4abf2d42029e8b5e7b767a6f4ac74050e188170a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 8 Jul 2023 18:32:10 +0200 Subject: [PATCH 0779/1006] #3317 Do not generate source parameter if check for only primitives --- .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../ap/test/bugs/_3317/Issue3317Mapper.java | 39 +++++++++++++++++++ .../ap/test/bugs/_3317/Issue3317Test.java | 28 +++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Test.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index a0fbe24b3e..0f9b96bb66 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -27,7 +27,7 @@ - <#if !mapNullToDefault> + <#if !mapNullToDefault && !sourceParametersExcludingPrimitives.empty> if ( <#list sourceParametersExcludingPrimitives as sourceParam>${sourceParam.name} == null<#if sourceParam_has_next> && ) { return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /><#else>null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Mapper.java new file mode 100644 index 0000000000..33a40b1dfb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Mapper.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3317; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3317Mapper { + + Issue3317Mapper INSTANCE = Mappers.getMapper( Issue3317Mapper.class ); + + Target map(int id, long value); + + class Target { + + private final int id; + private final long value; + + public Target(int id, long value) { + this.id = id; + this.value = value; + } + + public int getId() { + return id; + } + + public long getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Test.java new file mode 100644 index 0000000000..218a1f8979 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3317/Issue3317Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3317; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3317") +@WithClasses(Issue3317Mapper.class) +class Issue3317Test { + + @ProcessorTest + void shouldGenerateValidCode() { + Issue3317Mapper.Target target = Issue3317Mapper.INSTANCE.map( 10, 42L ); + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( 10 ); + assertThat( target.getValue() ).isEqualTo( 42L ); + } +} From 230e84efd1dde2f06e3032200051f69932402424 Mon Sep 17 00:00:00 2001 From: Roberto Oliveira Date: Tue, 25 Jul 2023 18:10:23 +0200 Subject: [PATCH 0780/1006] #3340 Update tarLongFileMode to use POSIX --- distribution/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index bcfa1f3db0..afa8e31002 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -162,7 +162,7 @@ ${basedir}/src/main/assembly/dist.xml mapstruct-${project.version} - gnu + posix From 0460c373c06d771e7766dd17aaaad7d1a28928a1 Mon Sep 17 00:00:00 2001 From: Lucas Resch Date: Sun, 30 Jul 2023 10:38:24 +0200 Subject: [PATCH 0781/1006] #3229: Implement InjectionStrategy.SETTER --- .../java/org/mapstruct/InjectionStrategy.java | 6 +- .../chapter-4-retrieving-a-mapper.asciidoc | 6 +- .../ap/internal/gem/InjectionStrategyGem.java | 3 +- .../ap/internal/model/AnnotatedSetter.java | 59 +++++++++ .../ap/internal/model/GeneratedType.java | 8 +- .../internal/model/GeneratedTypeMethod.java | 15 +++ .../ap/internal/model/MappingMethod.java | 3 +- ...nnotationBasedComponentModelProcessor.java | 70 +++++++++-- .../ap/internal/model/AnnotatedSetter.ftl | 14 +++ .../decorator/spring/setter/PersonMapper.java | 26 ++++ .../spring/setter/PersonMapperDecorator.java | 29 +++++ .../spring/setter/SpringDecoratorTest.java | 88 +++++++++++++ .../setter/CustomerJakartaSetterMapper.java | 26 ++++ .../setter/GenderJakartaSetterMapper.java | 25 ++++ .../setter/JakartaSetterMapperTest.java | 57 +++++++++ .../jakarta/setter/SetterJakartaConfig.java | 18 +++ .../setter/CustomerJsr330SetterMapper.java | 26 ++++ .../setter/GenderJsr330SetterMapper.java | 25 ++++ .../jsr330/setter/Jsr330SetterMapperTest.java | 98 +++++++++++++++ .../jsr330/setter/SetterJsr330Config.java | 18 +++ .../CustomerRecordSpringSetterMapper.java | 23 ++++ .../setter/CustomerSpringSetterMapper.java | 25 ++++ .../setter/GenderSpringSetterMapper.java | 25 ++++ .../spring/setter/SetterSpringConfig.java | 17 +++ .../spring/setter/SpringSetterMapperTest.java | 119 ++++++++++++++++++ 25 files changed, 813 insertions(+), 16 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedSetter.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/SpringDecoratorTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/CustomerJakartaSetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/GenderJakartaSetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/JakartaSetterMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/SetterJakartaConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/CustomerJsr330SetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/GenderJsr330SetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/SetterJsr330Config.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerRecordSpringSetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerSpringSetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/GenderSpringSetterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SetterSpringConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SpringSetterMapperTest.java diff --git a/core/src/main/java/org/mapstruct/InjectionStrategy.java b/core/src/main/java/org/mapstruct/InjectionStrategy.java index b841667671..f5029e2246 100644 --- a/core/src/main/java/org/mapstruct/InjectionStrategy.java +++ b/core/src/main/java/org/mapstruct/InjectionStrategy.java @@ -10,6 +10,7 @@ * JSR330 / Jakarta. * * @author Kevin Grüneberg + * @author Lucas Resch */ public enum InjectionStrategy { @@ -17,5 +18,8 @@ public enum InjectionStrategy { FIELD, /** Annotations are written on the constructor **/ - CONSTRUCTOR + CONSTRUCTOR, + + /** A dedicated setter method is created */ + SETTER } diff --git a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc index 67db28c7c0..35afc93a51 100644 --- a/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-4-retrieving-a-mapper.asciidoc @@ -102,7 +102,7 @@ A mapper which uses other mapper classes (see <>) will o [[injection-strategy]] === Injection strategy -When using <>, you can choose between field and constructor injection. +When using <>, you can choose between constructor, field, or setter injection. This can be done by either providing the injection strategy via `@Mapper` or `@MapperConfig` annotation. .Using constructor injection @@ -120,9 +120,13 @@ public interface CarMapper { The generated mapper will inject classes defined in the **uses** attribute if MapStruct has detected that it needs to use an instance of it for a mapping. When `InjectionStrategy#CONSTRUCTOR` is used, the constructor will have the appropriate annotation and the fields won't. When `InjectionStrategy#FIELD` is used, the annotation is on the field itself. +When `InjectionStrategy#SETTER` is used the annotation is on a generated setter method. For now, the default injection strategy is field injection, but it can be configured with <>. It is recommended to use constructor injection to simplify testing. +When you define mappers in Spring with circular dependencies compilation may fail. +In that case utilize the `InjectionStrategy#SETTER` strategy. + [TIP] ==== For abstract classes or decorators setter injection should be used. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java index f8ed93eeb4..621d07fd09 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/InjectionStrategyGem.java @@ -13,5 +13,6 @@ public enum InjectionStrategyGem { FIELD, - CONSTRUCTOR; + CONSTRUCTOR, + SETTER; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java new file mode 100644 index 0000000000..5614376ea4 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Lucas Resch + */ +public class AnnotatedSetter extends GeneratedTypeMethod { + + private final Field field; + private final Collection methodAnnotations; + private final Collection parameterAnnotations; + + public AnnotatedSetter(Field field, Collection methodAnnotations, + Collection parameterAnnotations) { + this.field = field; + this.methodAnnotations = methodAnnotations; + this.parameterAnnotations = parameterAnnotations; + } + + @Override + public Set getImportTypes() { + Set importTypes = new HashSet<>( field.getImportTypes() ); + for ( Annotation annotation : methodAnnotations ) { + importTypes.addAll( annotation.getImportTypes() ); + } + + for ( Annotation annotation : parameterAnnotations ) { + importTypes.addAll( annotation.getImportTypes() ); + } + + return importTypes; + } + + public Type getType() { + return field.getType(); + } + + public String getFieldName() { + return field.getVariableName(); + } + + public Collection getMethodAnnotations() { + return methodAnnotations; + } + + public Collection getParameterAnnotations() { + return parameterAnnotations; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 8348ecd84b..0bc3ec7bf0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -82,7 +82,7 @@ public T methods(List methods) { private final Type mapperDefinitionType; private final List annotations; - private final List methods; + private final List methods; private final SortedSet extraImportedTypes; private final boolean suppressGeneratorTimestamp; @@ -110,7 +110,7 @@ protected GeneratedType(TypeFactory typeFactory, String packageName, String name this.extraImportedTypes = extraImportedTypes; this.annotations = new ArrayList<>(); - this.methods = methods; + this.methods = new ArrayList<>(methods); this.fields = fields; this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; @@ -161,7 +161,7 @@ public void addAnnotation(Annotation annotation) { annotations.add( annotation ); } - public List getMethods() { + public List getMethods() { return methods; } @@ -204,7 +204,7 @@ public SortedSet getImportTypes() { addIfImportRequired( importedTypes, mapperDefinitionType ); - for ( MappingMethod mappingMethod : methods ) { + for ( GeneratedTypeMethod mappingMethod : methods ) { for ( Type type : mappingMethod.getImportTypes() ) { addIfImportRequired( importedTypes, type ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java new file mode 100644 index 0000000000..f02cc16b2c --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import org.mapstruct.ap.internal.model.common.ModelElement; + +/** + * @author Filip Hrisafov + */ +public abstract class GeneratedTypeMethod extends ModelElement { + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 4c59216e09..599ddf1d35 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -14,7 +14,6 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.Accessibility; -import org.mapstruct.ap.internal.model.common.ModelElement; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; @@ -27,7 +26,7 @@ * * @author Gunnar Morling */ -public abstract class MappingMethod extends ModelElement { +public abstract class MappingMethod extends GeneratedTypeMethod { private final String name; private final List parameters; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index d68936f545..014ceda58e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -11,10 +11,11 @@ import java.util.List; import java.util.ListIterator; import java.util.Set; - +import java.util.stream.Collectors; import javax.lang.model.element.TypeElement; import org.mapstruct.ap.internal.model.AnnotatedConstructor; +import org.mapstruct.ap.internal.model.AnnotatedSetter; import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.AnnotationMapperReference; import org.mapstruct.ap.internal.model.Decorator; @@ -77,6 +78,9 @@ else if ( mapper.getDecorator() != null ) { if ( injectionStrategy == InjectionStrategyGem.CONSTRUCTOR ) { buildConstructors( mapper ); } + else if ( injectionStrategy == InjectionStrategyGem.SETTER ) { + buildSetters( mapper ); + } return mapper; } @@ -110,6 +114,42 @@ private List toMapperReferences(List fields) { return mapperReferences; } + private void buildSetters(Mapper mapper) { + List mapperReferences = toMapperReferences( mapper.getFields() ); + for ( MapperReference mapperReference : mapperReferences ) { + if ( mapperReference.isUsed() ) { + AnnotatedSetter setter = new AnnotatedSetter( + mapperReference, + getMapperReferenceAnnotations(), + Collections.emptyList() + ); + mapper.getMethods().add( setter ); + } + } + + Decorator decorator = mapper.getDecorator(); + if ( decorator != null ) { + List mapperReferenceAnnotations = getMapperReferenceAnnotations(); + Set mapperReferenceAnnotationsTypes = mapperReferenceAnnotations + .stream() + .map( Annotation::getType ) + .collect( Collectors.toSet() ); + for ( Field field : decorator.getFields() ) { + if ( field instanceof AnnotationMapperReference ) { + + List fieldAnnotations = ( (AnnotationMapperReference) field ).getAnnotations(); + + List qualifiers = extractMissingAnnotations( + fieldAnnotations, + mapperReferenceAnnotationsTypes + ); + + decorator.getMethods().add( new AnnotatedSetter( field, mapperReferenceAnnotations, qualifiers ) ); + } + } + } + } + private void buildConstructors(Mapper mapper) { if ( !toMapperReferences( mapper.getFields() ).isEmpty() ) { AnnotatedConstructor annotatedConstructor = buildAnnotatedConstructorForMapper( mapper ); @@ -197,17 +237,33 @@ private void removeDuplicateAnnotations(List annotati AnnotationMapperReference annotationMapperReference = mapperReferenceIterator.next(); mapperReferenceIterator.remove(); - List qualifiers = new ArrayList<>(); - for ( Annotation annotation : annotationMapperReference.getAnnotations() ) { - if ( !mapperReferenceAnnotationsTypes.contains( annotation.getType() ) ) { - qualifiers.add( annotation ); - } - } + List qualifiers = extractMissingAnnotations( + annotationMapperReference.getAnnotations(), + mapperReferenceAnnotationsTypes + ); mapperReferenceIterator.add( annotationMapperReference.withNewAnnotations( qualifiers ) ); } } + /** + * Extract all annotations from {@code annotations} that do not have a type in {@code annotationTypes}. + * + * @param annotations the annotations from which we need to extract information + * @param annotationTypes the annotation types to ignore + * @return the annotations that are not in the {@code annotationTypes} + */ + private List extractMissingAnnotations(List annotations, + Set annotationTypes) { + List qualifiers = new ArrayList<>(); + for ( Annotation annotation : annotations ) { + if ( !annotationTypes.contains( annotation.getType() ) ) { + qualifiers.add( annotation ); + } + } + return qualifiers; + } + protected boolean additionalPublicEmptyConstructor() { return false; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedSetter.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedSetter.ftl new file mode 100644 index 0000000000..74d4241fa5 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/AnnotatedSetter.ftl @@ -0,0 +1,14 @@ + <#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> + <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.AnnotatedSetter" --> + <#list methodAnnotations as annotation> + <#nt><@includeModel object=annotation/> + +public void set${fieldName?cap_first}(<#list parameterAnnotations as annotation><#nt><@includeModel object=annotation/> <@includeModel object=type/> ${fieldName}) { + this.${fieldName} = ${fieldName}; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapper.java new file mode 100644 index 0000000000..20ac9d874c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.setter; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.SETTER) +@DecoratedWith(PersonMapperDecorator.class) +public interface PersonMapper { + + @Mapping( target = "name", ignore = true ) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapperDecorator.java new file mode 100644 index 0000000000..8f306284a1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/PersonMapperDecorator.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.setter; + +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +public abstract class PersonMapperDecorator implements PersonMapper { + + private PersonMapper decoratorDelegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = decoratorDelegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + + return dto; + } + + @Autowired + public void setDecoratorDelegate(@Qualifier("delegate") PersonMapper decoratorDelegate) { + this.decoratorDelegate = decoratorDelegate; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/SpringDecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/SpringDecoratorTest.java new file mode 100644 index 0000000000..c03b05395a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/setter/SpringDecoratorTest.java @@ -0,0 +1,88 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.setter; + +import java.util.Calendar; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + PersonMapper.class, + PersonMapperDecorator.class +}) +@WithSpring +@IssueKey("3229") +@ComponentScan(basePackageClasses = SpringDecoratorTest.class) +@Configuration +public class SpringDecoratorTest { + + @Autowired + private PersonMapper personMapper; + private ConfigurableApplicationContext context; + + @BeforeEach + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @AfterEach + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @ProcessorTest + public void shouldInvokeDecoratorMethods() { + //given + Calendar birthday = Calendar.getInstance(); + birthday.set( 1928, Calendar.MAY, 23 ); + Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); + + //when + PersonDto personDto = personMapper.personToPersonDto( person ); + + //then + assertThat( personDto ).isNotNull(); + assertThat( personDto.getName() ).isEqualTo( "Gary Crant" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } + + @ProcessorTest + public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() { + //given + Address address = new Address( "42 Ocean View Drive" ); + + //when + AddressDto addressDto = personMapper.addressToAddressDto( address ); + + //then + assertThat( addressDto ).isNotNull(); + assertThat( addressDto.getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/CustomerJakartaSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/CustomerJakartaSetterMapper.java new file mode 100644 index 0000000000..d422442791 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/CustomerJakartaSetterMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper( componentModel = MappingConstants.ComponentModel.JAKARTA, + uses = GenderJakartaSetterMapper.class, + injectionStrategy = InjectionStrategy.SETTER ) +public interface CustomerJakartaSetterMapper { + + @Mapping(target = "gender", source = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/GenderJakartaSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/GenderJakartaSetterMapper.java new file mode 100644 index 0000000000..f0d9b851e9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/GenderJakartaSetterMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.setter; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = SetterJakartaConfig.class) +public interface GenderJakartaSetterMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/JakartaSetterMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/JakartaSetterMapperTest.java new file mode 100644 index 0000000000..13eba2e866 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/JakartaSetterMapperTest.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.setter; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJakartaSetterMapper.class, + GenderJakartaSetterMapper.class, + SetterJakartaConfig.class +}) +@IssueKey("3229") +@Configuration +@WithJakartaInject +public class JakartaSetterMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void shouldHaveSetterInjection() { + String method = "@Inject" + lineSeparator() + + " public void setGenderJakartaSetterMapper(GenderJakartaSetterMapper genderJakartaSetterMapper) {" + + lineSeparator() + " this.genderJakartaSetterMapper = genderJakartaSetterMapper;" + + lineSeparator() + " }"; + generatedSource.forMapper( CustomerJakartaSetterMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "private GenderJakartaSetterMapper genderJakartaSetterMapper;" ) + .doesNotContain( "@Inject" + lineSeparator() + " private GenderJakartaSetterMapper" ) + .contains( method ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/SetterJakartaConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/SetterJakartaConfig.java new file mode 100644 index 0000000000..a189244936 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jakarta/setter/SetterJakartaConfig.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jakarta.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = MappingConstants.ComponentModel.JAKARTA, + injectionStrategy = InjectionStrategy.SETTER) +public interface SetterJakartaConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/CustomerJsr330SetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/CustomerJsr330SetterMapper.java new file mode 100644 index 0000000000..ab269f83f8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/CustomerJsr330SetterMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Filip Hrisafov + */ +@Mapper( componentModel = MappingConstants.ComponentModel.JSR330, + uses = GenderJsr330SetterMapper.class, + injectionStrategy = InjectionStrategy.SETTER ) +public interface CustomerJsr330SetterMapper { + + @Mapping(target = "gender", source = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/GenderJsr330SetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/GenderJsr330SetterMapper.java new file mode 100644 index 0000000000..d9b2f8ea9c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/GenderJsr330SetterMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.setter; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Filip Hrisafov + */ +@Mapper(config = SetterJsr330Config.class) +public interface GenderJsr330SetterMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java new file mode 100644 index 0000000000..558206e51c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java @@ -0,0 +1,98 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.setter; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerJsr330SetterMapper.class, + GenderJsr330SetterMapper.class, + SetterJsr330Config.class +}) +@IssueKey("3229") +@ComponentScan(basePackageClasses = CustomerJsr330SetterMapper.class) +@Configuration +@WithJavaxInject +public class Jsr330SetterMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerJsr330SetterMapper customerMapper; + private ConfigurableApplicationContext context; + + @BeforeEach + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @AfterEach + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @ProcessorTest + public void shouldConvertToTarget() { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + + // when + CustomerDto customerDto = customerMapper.asTarget( customerEntity ); + + // then + assertThat( customerDto ).isNotNull(); + assertThat( customerDto.getName() ).isEqualTo( "Samuel" ); + assertThat( customerDto.getGender() ).isEqualTo( GenderDto.M ); + } + + @ProcessorTest + public void shouldHaveSetterInjection() { + String method = "@Inject" + lineSeparator() + + " public void setGenderJsr330SetterMapper(GenderJsr330SetterMapper genderJsr330SetterMapper) {" + + lineSeparator() + " this.genderJsr330SetterMapper = genderJsr330SetterMapper;" + + lineSeparator() + " }"; + generatedSource.forMapper( CustomerJsr330SetterMapper.class ) + .content() + .contains( "import javax.inject.Inject;" ) + .contains( "import javax.inject.Named;" ) + .contains( "import javax.inject.Singleton;" ) + .contains( "private GenderJsr330SetterMapper genderJsr330SetterMapper;" ) + .doesNotContain( "@Inject" + lineSeparator() + " private GenderJsr330SetterMapper" ) + .contains( method ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/SetterJsr330Config.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/SetterJsr330Config.java new file mode 100644 index 0000000000..2b13a56feb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/SetterJsr330Config.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.jsr330.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; + +/** + * @author Filip Hrisafov + */ +@MapperConfig(componentModel = MappingConstants.ComponentModel.JSR330, + injectionStrategy = InjectionStrategy.SETTER) +public interface SetterJsr330Config { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerRecordSpringSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerRecordSpringSetterMapper.java new file mode 100644 index 0000000000..1d09bdda03 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerRecordSpringSetterMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; + +/** + * @author Lucas Resch + */ +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, + uses = { CustomerSpringSetterMapper.class, GenderSpringSetterMapper.class }, + injectionStrategy = InjectionStrategy.SETTER) +public interface CustomerRecordSpringSetterMapper { + + CustomerRecordDto asTarget(CustomerRecordEntity customerRecordEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerSpringSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerSpringSetterMapper.java new file mode 100644 index 0000000000..67dbab5e9c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/CustomerSpringSetterMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; + +/** + * @author Lucas Resch + */ +@Mapper( componentModel = MappingConstants.ComponentModel.SPRING, + uses = GenderSpringSetterMapper.class, + injectionStrategy = InjectionStrategy.SETTER ) +public interface CustomerSpringSetterMapper { + + @Mapping(target = "gender", source = "gender") + CustomerDto asTarget(CustomerEntity customerEntity); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/GenderSpringSetterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/GenderSpringSetterMapper.java new file mode 100644 index 0000000000..6243465ab5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/GenderSpringSetterMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.setter; + +import org.mapstruct.Mapper; +import org.mapstruct.ValueMapping; +import org.mapstruct.ValueMappings; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; + +/** + * @author Lucas Resch + */ +@Mapper(config = SetterSpringConfig.class) +public interface GenderSpringSetterMapper { + + @ValueMappings({ + @ValueMapping(source = "MALE", target = "M"), + @ValueMapping(source = "FEMALE", target = "F") + }) + GenderDto mapToDto(Gender gender); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SetterSpringConfig.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SetterSpringConfig.java new file mode 100644 index 0000000000..18227f315a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SetterSpringConfig.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.setter; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.MapperConfig; +import org.mapstruct.MappingConstants; + +/** + * @author Lucas Resch + */ +@MapperConfig(componentModel = MappingConstants.ComponentModel.SPRING, injectionStrategy = InjectionStrategy.SETTER) +public interface SetterSpringConfig { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SpringSetterMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SpringSetterMapperTest.java new file mode 100644 index 0000000000..4dcf098a9e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/spring/setter/SpringSetterMapperTest.java @@ -0,0 +1,119 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.injectionstrategy.spring.setter; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junitpioneer.jupiter.DefaultTimeZone; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordDto; +import org.mapstruct.ap.test.injectionstrategy.shared.CustomerRecordEntity; +import org.mapstruct.ap.test.injectionstrategy.shared.Gender; +import org.mapstruct.ap.test.injectionstrategy.shared.GenderDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static java.lang.System.lineSeparator; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test setter injection for component model spring. + * + * @author Lucas Resch + */ +@WithClasses( { + CustomerRecordDto.class, + CustomerRecordEntity.class, + CustomerDto.class, + CustomerEntity.class, + Gender.class, + GenderDto.class, + CustomerRecordSpringSetterMapper.class, + CustomerSpringSetterMapper.class, + GenderSpringSetterMapper.class, + SetterSpringConfig.class +} ) +@IssueKey( "3229" ) +@ComponentScan(basePackageClasses = CustomerSpringSetterMapper.class) +@Configuration +@WithSpring +@DefaultTimeZone("Europe/Berlin") +public class SpringSetterMapperTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private CustomerRecordSpringSetterMapper customerRecordMapper; + private ConfigurableApplicationContext context; + + @BeforeEach + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @AfterEach + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @ProcessorTest + public void shouldConvertToTarget() throws Exception { + // given + CustomerEntity customerEntity = new CustomerEntity(); + customerEntity.setName( "Samuel" ); + customerEntity.setGender( Gender.MALE ); + CustomerRecordEntity customerRecordEntity = new CustomerRecordEntity(); + customerRecordEntity.setCustomer( customerEntity ); + customerRecordEntity.setRegistrationDate( createDate( "31-08-1982 10:20:56" ) ); + + // when + CustomerRecordDto customerRecordDto = customerRecordMapper.asTarget( customerRecordEntity ); + + // then + assertThat( customerRecordDto ).isNotNull(); + assertThat( customerRecordDto.getCustomer() ).isNotNull(); + assertThat( customerRecordDto.getCustomer().getName() ).isEqualTo( "Samuel" ); + assertThat( customerRecordDto.getCustomer().getGender() ).isEqualTo( GenderDto.M ); + assertThat( customerRecordDto.getRegistrationDate() ).isNotNull(); + assertThat( customerRecordDto.getRegistrationDate() ).hasToString( "1982-08-31T10:20:56.000+02:00" ); + } + + @ProcessorTest + public void shouldHaveSetterInjection() { + String method = "@Autowired" + lineSeparator() + + " public void setGenderSpringSetterMapper(GenderSpringSetterMapper genderSpringSetterMapper) {" + + lineSeparator() + " this.genderSpringSetterMapper = genderSpringSetterMapper;" + + lineSeparator() + " }"; + generatedSource.forMapper( CustomerSpringSetterMapper.class ) + .content() + .contains( "private GenderSpringSetterMapper genderSpringSetterMapper;" ) + .contains( method ); + } + + private Date createDate(String date) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat( "dd-M-yyyy hh:mm:ss" ); + return sdf.parse( date ); + } + +} From 28d827a724bab212c8069903bd1bac3679370ad6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 29 Jul 2023 14:52:24 +0200 Subject: [PATCH 0782/1006] Add test case for subclass mapping and bean mapping ignore by default --- .../SubclassIgnoreByDefaultMapper.java | 29 +++++++++++++++++++ .../subclassmapping/SubclassMappingTest.java | 14 +++++++++ 2 files changed, 43 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassIgnoreByDefaultMapper.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassIgnoreByDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassIgnoreByDefaultMapper.java new file mode 100644 index 0000000000..d138eb4ec3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassIgnoreByDefaultMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.ap.test.subclassmapping.mappables.Bike; +import org.mapstruct.ap.test.subclassmapping.mappables.BikeDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Car; +import org.mapstruct.ap.test.subclassmapping.mappables.CarDto; +import org.mapstruct.ap.test.subclassmapping.mappables.Vehicle; +import org.mapstruct.ap.test.subclassmapping.mappables.VehicleDto; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SubclassIgnoreByDefaultMapper { + SubclassIgnoreByDefaultMapper INSTANCE = Mappers.getMapper( SubclassIgnoreByDefaultMapper.class ); + + @BeanMapping(ignoreByDefault = true) + @SubclassMapping(source = Car.class, target = CarDto.class) + @SubclassMapping(source = Bike.class, target = BikeDto.class) + @Mapping(target = "name") + VehicleDto map(Vehicle vehicle); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java index ba64d2cc7f..60e274ef19 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/SubclassMappingTest.java @@ -277,4 +277,18 @@ void erroneousMethodWithSourceTargetType() { }) void inverseSubclassMappingNotPossible() { } + + @ProcessorTest + @WithClasses(SubclassIgnoreByDefaultMapper.class) + void beanMappingIgnoreByDefaultShouldBePropagated() { + Car car = new Car(); + car.setName( "Test car" ); + car.setManual( true ); + VehicleDto target = SubclassIgnoreByDefaultMapper.INSTANCE.map( car ); + assertThat( target ) + .isInstanceOfSatisfying( CarDto.class, carDto -> { + assertThat( carDto.getName() ).isEqualTo( "Test car" ); + assertThat( carDto.isManual() ).isFalse(); + } ); + } } From 279ab2248291cba77391cae38a4b2ea40fbeae7c Mon Sep 17 00:00:00 2001 From: Venkatesh Prasad Kannan Date: Tue, 1 Aug 2023 08:48:20 +0100 Subject: [PATCH 0783/1006] #3309 Add `BeanMapping#unmappedSourcePolicy` --- .../main/java/org/mapstruct/BeanMapping.java | 11 +++ .../ap/internal/model/BeanMappingMethod.java | 2 +- .../model/source/BeanMappingOptions.java | 10 +++ .../unmappedsource/UnmappedSourceTest.java | 1 + ...eanMappingSourcePolicyErroneousMapper.java | 18 +++++ .../BeanMappingSourcePolicyMapper.java | 25 +++++++ .../unmappedsource/beanmapping/Source.java | 30 +++++++++ .../unmappedsource/beanmapping/Target.java | 20 ++++++ .../beanmapping/UnmappedSourceTest.java | 67 +++++++++++++++++++ 9 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyErroneousMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/UnmappedSourceTest.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index be3df0d29d..a03546b07d 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -152,6 +152,17 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() */ String[] ignoreUnmappedSourceProperties() default {}; + /** + * How unmapped properties of the source type of a mapping should be reported. + * If no policy is configured, the policy given via {@link MapperConfig#unmappedSourcePolicy()} or + * {@link Mapper#unmappedSourcePolicy()} will be applied, using {@link ReportingPolicy#IGNORE} by default. + * + * @return The reporting policy for unmapped source properties. + * + * @since 1.6 + */ + ReportingPolicy unmappedSourcePolicy() default ReportingPolicy.IGNORE; + /** * How unmapped properties of the target type of a mapping should be reported. * If no policy is configured, the policy given via {@link MapperConfig#unmappedTargetPolicy()} or diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 903dfa5cc5..11245b3376 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1740,7 +1740,7 @@ private ReportingPolicyGem getUnmappedSourcePolicy() { if ( method.getOptions().getBeanMapping().isignoreByDefault() ) { return ReportingPolicyGem.IGNORE; } - return method.getOptions().getMapper().unmappedSourcePolicy(); + return method.getOptions().getBeanMapping().unmappedSourcePolicy(); } private void reportErrorForUnmappedSourcePropertiesIfRequired() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index e8f19f91f6..6f36238a35 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -113,6 +113,7 @@ private static boolean isConsistent(BeanMappingGem gem, ExecutableElement method && !gem.nullValueMappingStrategy().hasValue() && !gem.subclassExhaustiveStrategy().hasValue() && !gem.unmappedTargetPolicy().hasValue() + && !gem.unmappedSourcePolicy().hasValue() && !gem.ignoreByDefault().hasValue() && !gem.builder().hasValue() ) { @@ -179,6 +180,15 @@ public ReportingPolicyGem unmappedTargetPolicy() { .orElse( next().unmappedTargetPolicy() ); } + @Override + public ReportingPolicyGem unmappedSourcePolicy() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::unmappedSourcePolicy ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .map( ReportingPolicyGem::valueOf ) + .orElse( next().unmappedSourcePolicy() ); + } + @Override public BuilderGem getBuilder() { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::builder ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java index 9b244592a2..75231f3f53 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/UnmappedSourceTest.java @@ -110,4 +110,5 @@ public void shouldRaiseErrorDueToUnsetSourcePropertyWithPolicySetViaProcessorOpt ) public void shouldLeaveUnmappedSourcePropertyUnsetWithWarnPolicySetViaProcessorOption() { } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyErroneousMapper.java new file mode 100644 index 0000000000..eab3f8f425 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyErroneousMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource.beanmapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +@Mapper(unmappedSourcePolicy = ReportingPolicy.WARN) +public interface BeanMappingSourcePolicyErroneousMapper { + + @BeanMapping(unmappedSourcePolicy = ReportingPolicy.ERROR) + Target map(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyMapper.java new file mode 100644 index 0000000000..11e1f07132 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/BeanMappingSourcePolicyMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource.beanmapping; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR) +public interface BeanMappingSourcePolicyMapper { + + BeanMappingSourcePolicyMapper MAPPER = + Mappers.getMapper( BeanMappingSourcePolicyMapper.class ); + + @BeanMapping(unmappedSourcePolicy = ReportingPolicy.WARN) + Target map(Source source); + + @BeanMapping(unmappedSourcePolicy = ReportingPolicy.IGNORE) + Target map2(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Source.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Source.java new file mode 100644 index 0000000000..fc92d1a5c1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Source.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource.beanmapping; + +public class Source { + + private int foo; + + private int bar; + + public int getFoo() { + return foo; + } + + public void setFoo(int foo) { + this.foo = foo; + } + + public int getBar() { + return bar; + } + + public void setBar(int bar) { + this.bar = bar; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Target.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Target.java new file mode 100644 index 0000000000..5696455b46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/Target.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource.beanmapping; + +public class Target { + + private int foo; + + public int getFoo() { + return foo; + } + + public void setFoo(int foo) { + this.foo = foo; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/UnmappedSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/UnmappedSourceTest.java new file mode 100644 index 0000000000..6eff388774 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/unmappedsource/beanmapping/UnmappedSourceTest.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.unmappedsource.beanmapping; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.tools.Diagnostic.Kind; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +@IssueKey("3309") +class UnmappedSourceTest { + + @ProcessorTest + @WithClasses({ Source.class, Target.class, BeanMappingSourcePolicyMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = BeanMappingSourcePolicyMapper.class, + kind = Kind.WARNING, + line = 20, + message = "Unmapped source property: \"bar\".") + } + ) + public void shouldCompileWithUnmappedSourcePolicySetToWarnWithBeanMapping() { + Source source = new Source(); + Source source2 = new Source(); + + source.setFoo( 10 ); + source.setBar( 20 ); + + source2.setFoo( 1 ); + source2.setBar( 2 ); + + Target target = BeanMappingSourcePolicyMapper.MAPPER.map( source ); + Target target2 = BeanMappingSourcePolicyMapper.MAPPER.map2( source2 ); + + assertThat( target ).isNotNull(); + assertThat( target.getFoo() ).isEqualTo( 10 ); + + assertThat( target2 ).isNotNull(); + assertThat( target2.getFoo() ).isEqualTo( 1 ); + } + + @ProcessorTest + @WithClasses({ Source.class, Target.class, BeanMappingSourcePolicyErroneousMapper.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = BeanMappingSourcePolicyErroneousMapper.class, + kind = Kind.ERROR, + line = 16, + message = "Unmapped source property: \"bar\".") + } + ) + public void shouldErrorWithUnmappedSourcePolicySetToErrorWithBeanMapping() { + } + +} From b2dc64136d39547dec3bf3386837be8de7130e0c Mon Sep 17 00:00:00 2001 From: Anton Erofeev Date: Tue, 1 Aug 2023 14:17:50 +0200 Subject: [PATCH 0784/1006] #3292 Simplify expressions, remove redundant expressions --- .../FullFeatureCompilationExclusionCliEnhancer.java | 2 +- .../itest/tests/GradleIncrementalCompilationTest.java | 2 +- .../conversion/BigDecimalToStringConversion.java | 2 +- .../conversion/BigIntegerToStringConversion.java | 2 +- .../ap/internal/model/AbstractMappingMethodBuilder.java | 4 +--- .../mapstruct/ap/internal/model/BeanMappingMethod.java | 6 ++---- .../model/NestedTargetPropertyMappingHolder.java | 2 +- .../org/mapstruct/ap/internal/model/PropertyMapping.java | 2 +- .../model/common/DateFormatValidatorFactory.java | 9 ++------- .../org/mapstruct/ap/internal/model/common/Type.java | 3 +-- .../ap/test/builder/lifecycle/MappingContext.java | 2 +- .../test/builder/parentchild/ParentChildBuilderTest.java | 2 +- .../ap/test/builder/simple/SimpleImmutablePerson.java | 4 ++-- .../java/org/mapstruct/ap/test/callbacks/BaseMapper.java | 2 +- .../mapstruct/ap/test/callbacks/CallbackMethodTest.java | 2 +- .../ap/test/callbacks/ClassContainingCallbacks.java | 2 +- .../returning/CallbacksWithReturnValuesTest.java | 7 +------ .../ap/test/callbacks/returning/NodeMapperContext.java | 6 +++--- .../ap/test/collection/adder/_target/Target2.java | 2 +- .../collection/defaultimplementation/NoSetterTarget.java | 4 ++-- .../java/org/mapstruct/ap/test/java8stream/Target.java | 2 +- .../java/org/mapstruct/ap/test/nestedbeans/HouseDto.java | 6 ++++-- .../ap/test/nestedbeans/maps/AntonymsDictionaryDto.java | 4 ++-- .../selection/resulttype/InheritanceSelectionTest.java | 2 +- .../org/mapstruct/ap/test/source/constants/Target.java | 2 +- .../mapstruct/ap/testutil/assertions/JavaFileAssert.java | 2 +- .../testutil/compilation/model/DiagnosticDescriptor.java | 4 ++-- .../ap/testutil/runner/JdkCompilingExtension.java | 2 +- .../ap/testutil/runner/ModifiableURLClassLoader.java | 2 +- 29 files changed, 40 insertions(+), 53 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index e64b207990..c0ea96fd5c 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -44,7 +44,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces default: } - Collection result = new ArrayList( additionalExcludes.size() ); + Collection result = new ArrayList<>(additionalExcludes.size()); for ( int i = 0; i < additionalExcludes.size(); i++ ) { result.add( "-DadditionalExclude" + i + "=" + additionalExcludes.get( i ) ); } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java index 0162582468..3d496906c0 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java @@ -62,7 +62,7 @@ private void replaceInFile(File file, CharSequence target, CharSequence replacem } private GradleRunner getRunner(String... additionalArguments) { - List fullArguments = new ArrayList( compileArgs ); + List fullArguments = new ArrayList<>(compileArgs); fullArguments.addAll( Arrays.asList( additionalArguments ) ); return runner.withArguments( fullArguments ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index d696cf5bb5..92a93e3893 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -45,7 +45,7 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { StringBuilder sb = new StringBuilder(); - sb.append( "(" + bigDecimal( conversionContext ) + ") " ); + sb.append( "(" ).append( bigDecimal( conversionContext ) ).append( ") " ); appendDecimalFormatter( sb, conversionContext ); sb.append( ".parse( )" ); return sb.toString(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index 9cb1cf41cb..df0a48a673 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -47,7 +47,7 @@ public String getToExpression(ConversionContext conversionContext) { public String getFromExpression(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { StringBuilder sb = new StringBuilder(); - sb.append( "( (" + bigDecimal( conversionContext ) + ") " ); + sb.append( "( (" ).append( bigDecimal( conversionContext ) ).append( ") " ); appendDecimalFormatter( sb, conversionContext ); sb.append( ".parse( )" ); sb.append( " ).toBigInteger()" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index c23dd50430..7329df5ab7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -130,9 +130,7 @@ public List getMethodAnnotations() { ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); - List annotations = new ArrayList<>(); - annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); - return annotations; + return new ArrayList<>( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 11245b3376..00e1d9f9f9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -266,9 +266,7 @@ else if ( !method.isUpdateMethod() ) { Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); - for ( Entry entry : readAccessors.entrySet() ) { - unprocessedSourceProperties.put( entry.getKey(), entry.getValue() ); - } + unprocessedSourceProperties.putAll( readAccessors ); } // get bean mapping (when specified as annotation ) @@ -499,7 +497,7 @@ private boolean isCorrectlySealed(Type mappingSourceType) { new ArrayList<>( mappingSourceType.getPermittedSubclasses() ); method.getOptions().getSubclassMappings().forEach( subClassOption -> { for (Iterator iterator = unusedPermittedSubclasses.iterator(); - iterator.hasNext(); ) { + iterator.hasNext(); ) { if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) { iterator.remove(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index b7bfc69780..20825c2dd9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -607,7 +607,7 @@ else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { * @param hasNoMappings parameter indicating whether there were any extracted mappings for this target property * @param sourceParameter the source parameter for which the grouping is being done * - * @return a list with valid single target references + * @return a set with valid single target references */ private Set extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( Set singleTargetReferences, Set sourceParameterMappings, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index bedb37cc8f..b81cf55447 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -1115,7 +1115,7 @@ private PropertyMapping(String name, String sourceBeanName, String targetWriteAc this.targetType = targetType; this.assignment = assignment; - this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet(); + this.dependsOn = dependsOn != null ? dependsOn : Collections.emptySet(); this.defaultValueAssignment = defaultValueAssignment; this.constructorMapping = constructorMapping; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java index 09e4957aad..4d54f3c3e9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DateFormatValidatorFactory.java @@ -61,13 +61,8 @@ else if ( isJodaDateTimeSupposed( sourceType, targetType ) ) { dateFormatValidator = new JodaTimeDateFormatValidator(); } else { - dateFormatValidator = new DateFormatValidator() { - @Override - public DateFormatValidationResult validate(String dateFormat) { - return new DateFormatValidationResult( true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK, - sourceType, targetType ); - } - }; + dateFormatValidator = dateFormat -> new DateFormatValidationResult( + true, Message.GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK, sourceType, targetType ); } return dateFormatValidator; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 933f1f6ce0..a6d942748d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -684,10 +684,9 @@ public PresenceCheckAccessor getPresenceChecker(String propertyName) { */ public Map getPropertyReadAccessors() { if ( readAccessors == null ) { - Map modifiableGetters = new LinkedHashMap<>(); Map recordAccessors = filters.recordAccessorsIn( getRecordComponents() ); - modifiableGetters.putAll( recordAccessors ); + Map modifiableGetters = new LinkedHashMap<>(recordAccessors); List getterList = filters.getterMethodsIn( getAllMethods() ); for ( ReadAccessor getter : getterList ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java index 079be90a81..2065bad478 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/lifecycle/MappingContext.java @@ -18,7 +18,7 @@ */ public class MappingContext { - private final List invokedMethods = new ArrayList(); + private final List invokedMethods = new ArrayList<>(); @BeforeMapping public void beforeWithoutParameters() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java index dd45573a59..562770a2bb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/parentchild/ParentChildBuilderTest.java @@ -26,7 +26,7 @@ public class ParentChildBuilderTest { public void testParentChildBuilderMapper() { final MutableParent parent = new MutableParent(); parent.setCount( 4 ); - parent.setChildren( new ArrayList() ); + parent.setChildren( new ArrayList<>() ); parent.getChildren().add( new MutableChild( "Phineas" ) ); parent.getChildren().add( new MutableChild( "Ferb" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java index daa3dfad0b..2fe2c8ded2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java @@ -22,7 +22,7 @@ public class SimpleImmutablePerson { this.job = builder.job; this.city = builder.city; this.address = builder.address; - this.children = new ArrayList( builder.children ); + this.children = new ArrayList<>(builder.children); } public static Builder builder() { @@ -59,7 +59,7 @@ public static class Builder { private String job; private String city; private String address; - private List children = new ArrayList(); + private List children = new ArrayList<>(); public Builder age(int age) { this.age = age; diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java index bee462accc..4e02045ed5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/BaseMapper.java @@ -24,7 +24,7 @@ public abstract class BaseMapper { @Qualified public abstract Target sourceToTargetQualified(Source source); - private static final List INVOCATIONS = new ArrayList(); + private static final List INVOCATIONS = new ArrayList<>(); @BeforeMapping public void noArgsBeforeMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java index 7026a335d8..825b359152 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/CallbackMethodTest.java @@ -111,7 +111,7 @@ public void callbackMethodsForEnumMappingCalled() { SourceEnum source = SourceEnum.B; TargetEnum target = SourceTargetMapper.INSTANCE.toTargetEnum( source ); - List invocations = new ArrayList(); + List invocations = new ArrayList<>(); invocations.addAll( allBeforeMappingMethods( source, target, TargetEnum.class ) ); invocations.addAll( allAfterMappingMethods( source, target, TargetEnum.class ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java index 762247045d..2889a4ad30 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/ClassContainingCallbacks.java @@ -18,7 +18,7 @@ * @author Andreas Gudian */ public class ClassContainingCallbacks { - private static final List INVOCATIONS = new ArrayList(); + private static final List INVOCATIONS = new ArrayList<>(); @BeforeMapping public void noArgsBeforeMapping() { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java index 7d6eaacb79..10d2a29cd7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/CallbacksWithReturnValuesTest.java @@ -50,12 +50,7 @@ void updatingWithDefaultHandlingRaisesStackOverflowError() { @ProcessorTest void mappingWithContextCorrectlyResolvesCycles() { final AtomicReference contextLevel = new AtomicReference<>( null ); - ContextListener contextListener = new ContextListener() { - @Override - public void methodCalled(Integer level, String method, Object source, Object target) { - contextLevel.set( level ); - } - }; + ContextListener contextListener = (level, method, source, target) -> contextLevel.set( level ); NodeMapperContext.addContextListener( contextListener ); try { diff --git a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java index 40a1a63937..325778b85e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java +++ b/processor/src/test/java/org/mapstruct/ap/test/callbacks/returning/NodeMapperContext.java @@ -19,11 +19,11 @@ * @author Pascal Grün */ public class NodeMapperContext { - private static final ThreadLocal LEVEL = new ThreadLocal(); - private static final ThreadLocal> MAPPING = new ThreadLocal>(); + private static final ThreadLocal LEVEL = new ThreadLocal<>(); + private static final ThreadLocal> MAPPING = new ThreadLocal<>(); /** Only for test-inspection */ - private static final List LISTENERS = new CopyOnWriteArrayList(); + private static final List LISTENERS = new CopyOnWriteArrayList<>(); private NodeMapperContext() { // Only allow static access diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java index 850c6ee94d..bd6e8f9979 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/adder/_target/Target2.java @@ -16,7 +16,7 @@ */ public class Target2 { - private List attributes = new ArrayList(); + private List attributes = new ArrayList<>(); public Foo addAttribute( Foo foo ) { attributes.add( foo ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java index 562966dfd1..817879fa01 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/NoSetterTarget.java @@ -15,8 +15,8 @@ * */ public class NoSetterTarget { - private List listValues = new ArrayList(); - private Map mapValues = new HashMap(); + private List listValues = new ArrayList<>(); + private Map mapValues = new HashMap<>(); public List getListValues() { return listValues; diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java index 2d63c3f166..49b23530df 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/Target.java @@ -77,7 +77,7 @@ public Set getColours() { public List getStringListNoSetter() { if ( stringListNoSetter == null ) { - stringListNoSetter = new ArrayList(); + stringListNoSetter = new ArrayList<>(); } return stringListNoSetter; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java index 1d92eb7e4f..71beedaa93 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/HouseDto.java @@ -5,6 +5,8 @@ */ package org.mapstruct.ap.test.nestedbeans; +import java.util.Objects; + public class HouseDto { private String name; @@ -58,10 +60,10 @@ public boolean equals(Object o) { if ( year != houseDto.year ) { return false; } - if ( name != null ? !name.equals( houseDto.name ) : houseDto.name != null ) { + if ( !Objects.equals( name, houseDto.name ) ) { return false; } - return roof != null ? roof.equals( houseDto.roof ) : houseDto.roof == null; + return Objects.equals( roof, houseDto.roof ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java index 33ccfbc1cc..9ac7913c9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nestedbeans/maps/AntonymsDictionaryDto.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.nestedbeans.maps; import java.util.Map; +import java.util.Objects; public class AntonymsDictionaryDto { private Map antonyms; @@ -36,8 +37,7 @@ public boolean equals(Object o) { AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o; - return antonyms != null ? antonyms.equals( antonymsDictionaryDto.antonyms ) : - antonymsDictionaryDto.antonyms == null; + return Objects.equals( antonyms, antonymsDictionaryDto.antonyms ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java index 05245bafe0..8cd58f0664 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/resulttype/InheritanceSelectionTest.java @@ -192,7 +192,7 @@ public void testShouldSelectResultTypeInCaseOfAmbiguityForIterable() { }) public void testShouldSelectResultTypeInCaseOfAmbiguityForMap() { - Map source = new HashMap(); + Map source = new HashMap<>(); source.put( new AppleDto( "GoldenDelicious" ), new AppleDto( "AppleDto" ) ); Map result = FruitFamilyMapper.INSTANCE.mapToGoldenDeliciousMap( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java index 98ca13eb0b..7897fe2bd6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/Target.java @@ -20,7 +20,7 @@ public class Target { private int integerConstant; private Long longWrapperConstant; private Date dateConstant; - private List nameConstants = new ArrayList(); + private List nameConstants = new ArrayList<>(); private CountryEnum country; public String getPropertyThatShouldBeMapped() { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java index 2bcfbd94d3..e6eabd9f84 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java @@ -59,7 +59,7 @@ public AbstractCharSequenceAssert content() { return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) ); } catch ( IOException e ) { - failWithMessage( "Unable to read" + actual.toString() + ". Exception: " + e.getMessage() ); + failWithMessage( "Unable to read" + actual + ". Exception: " + e.getMessage() ); } return null; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index 94dda74708..ecfec14a16 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -131,7 +131,7 @@ private static URI getUri(javax.tools.Diagnostic diagn //Make the URI absolute in case it isn't (the case with JDK 6) try { - return new URI( "file:" + uri.toString() ); + return new URI( "file:" + uri ); } catch ( URISyntaxException e ) { throw new RuntimeException( e ); @@ -189,7 +189,7 @@ public boolean equals(Object obj) { if ( kind != other.kind ) { return false; } - if ( line != other.line ) { + if ( !Objects.equals( line, other.line ) ) { return false; } if ( !Objects.equals( message, other.message ) ) { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 7b44a4733b..5185bfb7ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -135,7 +135,7 @@ protected List filterExpectedDiagnostics(List filtered = new ArrayList( expectedDiagnostics.size() ); + List filtered = new ArrayList<>(expectedDiagnostics.size()); // The JDK 8 compiler only reports the first message of kind ERROR that is reported for one source file line, // so we filter out the surplus diagnostics. The input list is already sorted by file name and line number, diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java index 9cc41fe134..2dd5d5b8e7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/ModifiableURLClassLoader.java @@ -31,7 +31,7 @@ final class ModifiableURLClassLoader extends URLClassLoader { tryRegisterAsParallelCapable(); } - private final ConcurrentMap addedURLs = new ConcurrentHashMap(); + private final ConcurrentMap addedURLs = new ConcurrentHashMap<>(); ModifiableURLClassLoader(ClassLoader parent) { super( new URL[] { }, parent ); From 812faeef5100ea28db6081c9f7b5b22b4450bf95 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Tue, 1 Aug 2023 09:53:58 +0200 Subject: [PATCH 0785/1006] Use presence checks for checking source parameter presence Instead of explicitly doing a null check use a PresenceCheck mechanism for * BeanMappingMethod * ContainerMappingMethod * MapMappingMethod --- .../ap/internal/model/BeanMappingMethod.java | 49 +++++++++++------ .../model/ContainerMappingMethod.java | 26 ++++++++-- .../ap/internal/model/MapMappingMethod.java | 26 ++++++++-- .../model/MethodReferencePresenceCheck.java | 15 ++++++ .../model/common/NegatePresenceCheck.java | 52 +++++++++++++++++++ .../internal/model/common/PresenceCheck.java | 2 + .../AllPresenceChecksPresenceCheck.java | 6 +++ .../presence/JavaExpressionPresenceCheck.java | 6 +++ .../model/presence/NullPresenceCheck.java | 16 ++++++ .../model/presence/SuffixPresenceCheck.java | 16 ++++++ .../ap/internal/model/BeanMappingMethod.ftl | 20 +++---- .../internal/model/IterableMappingMethod.ftl | 2 +- .../ap/internal/model/MapMappingMethod.ftl | 2 +- .../model/MethodReferencePresenceCheck.ftl | 2 +- .../ap/internal/model/StreamMappingMethod.ftl | 2 +- .../model/common/NegatePresenceCheck.ftl | 9 ++++ .../model/presence/NullPresenceCheck.ftl | 2 +- .../model/presence/SuffixPresenceCheck.ftl | 2 +- 18 files changed, 214 insertions(+), 41 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 00e1d9f9f9..ee347ef35e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -46,11 +46,13 @@ import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.source.BeanMappingOptions; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; @@ -88,6 +90,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final List propertyMappings; private final Map> mappingsByParameter; private final Map> constructorMappingsByParameter; + private final Map presenceChecksByParameter; private final List constantMappings; private final List constructorConstantMappings; private final List subclassMappings; @@ -1869,11 +1872,19 @@ private BeanMappingMethod(Method method, // parameter mapping. this.mappingsByParameter = new HashMap<>(); this.constantMappings = new ArrayList<>( propertyMappings.size() ); + this.presenceChecksByParameter = new LinkedHashMap<>(); this.constructorMappingsByParameter = new LinkedHashMap<>(); this.constructorConstantMappings = new ArrayList<>(); - Set sourceParameterNames = getSourceParameters().stream() - .map( Parameter::getName ) - .collect( Collectors.toSet() ); + Set sourceParameterNames = new HashSet<>(); + for ( Parameter sourceParameter : getSourceParameters() ) { + sourceParameterNames.add( sourceParameter.getName() ); + if ( !sourceParameter.getType().isPrimitive() ) { + presenceChecksByParameter.put( + sourceParameter.getName(), + new NullPresenceCheck( sourceParameter.getName() ) + ); + } + } for ( PropertyMapping mapping : propertyMappings ) { if ( mapping.isConstructorMapping() ) { if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { @@ -1984,44 +1995,50 @@ public Set getImportTypes() { return types; } - public List getSourceParametersExcludingPrimitives() { - return getSourceParameters().stream() - .filter( parameter -> !parameter.getType().isPrimitive() ) - .collect( Collectors.toList() ); + public Collection getSourcePresenceChecks() { + return presenceChecksByParameter.values(); + } + + public Map getPresenceChecksByParameter() { + return presenceChecksByParameter; + } + + public PresenceCheck getPresenceCheckByParameter(Parameter parameter) { + return presenceChecksByParameter.get( parameter.getName() ); } - public List getSourceParametersNeedingNullCheck() { + public List getSourceParametersNeedingPresenceCheck() { return getSourceParameters().stream() - .filter( this::needsNullCheck ) + .filter( this::needsPresenceCheck ) .collect( Collectors.toList() ); } - public List getSourceParametersNotNeedingNullCheck() { + public List getSourceParametersNotNeedingPresenceCheck() { return getSourceParameters().stream() - .filter( parameter -> !needsNullCheck( parameter ) ) + .filter( parameter -> !needsPresenceCheck( parameter ) ) .collect( Collectors.toList() ); } - private boolean needsNullCheck(Parameter parameter) { - if ( parameter.getType().isPrimitive() ) { + private boolean needsPresenceCheck(Parameter parameter) { + if ( !presenceChecksByParameter.containsKey( parameter.getName() ) ) { return false; } List mappings = propertyMappingsByParameter( parameter ); - if ( mappings.size() == 1 && doesNotNeedNullCheckForSourceParameter( mappings.get( 0 ) ) ) { + if ( mappings.size() == 1 && doesNotNeedPresenceCheckForSourceParameter( mappings.get( 0 ) ) ) { return false; } mappings = constructorPropertyMappingsByParameter( parameter ); - if ( mappings.size() == 1 && doesNotNeedNullCheckForSourceParameter( mappings.get( 0 ) ) ) { + if ( mappings.size() == 1 && doesNotNeedPresenceCheckForSourceParameter( mappings.get( 0 ) ) ) { return false; } return true; } - private boolean doesNotNeedNullCheckForSourceParameter(PropertyMapping mapping) { + private boolean doesNotNeedPresenceCheckForSourceParameter(PropertyMapping mapping) { if ( mapping.getAssignment().isCallingUpdateMethod() ) { // If the mapping assignment is calling an update method then we should do a null check // in the bean mapping diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 21e547eea0..7ecb7b0ed1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -12,7 +12,9 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.util.Strings; @@ -30,6 +32,8 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { private final SelectionParameters selectionParameters; private final String index1Name; private final String index2Name; + private final Parameter sourceParameter; + private final PresenceCheck sourceParameterPresenceCheck; private IterableCreation iterableCreation; ContainerMappingMethod(Method method, List annotations, @@ -45,16 +49,30 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { this.selectionParameters = selectionParameters; this.index1Name = Strings.getSafeVariableName( "i", existingVariables ); this.index2Name = Strings.getSafeVariableName( "j", existingVariables ); - } - public Parameter getSourceParameter() { + Parameter sourceParameter = null; for ( Parameter parameter : getParameters() ) { if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { - return parameter; + sourceParameter = parameter; + break; } } - throw new IllegalStateException( "Method " + this + " has no source parameter." ); + if ( sourceParameter == null ) { + throw new IllegalStateException( "Method " + this + " has no source parameter." ); + } + + this.sourceParameter = sourceParameter; + this.sourceParameterPresenceCheck = new NullPresenceCheck( this.sourceParameter.getName() ); + + } + + public Parameter getSourceParameter() { + return sourceParameter; + } + + public PresenceCheck getSourceParameterPresenceCheck() { + return sourceParameterPresenceCheck; } public IterableCreation getIterableCreation() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java index 85766e2eca..42dbf826d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MapMappingMethod.java @@ -15,8 +15,10 @@ import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.SourceRHS; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.SelectionParameters; import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; @@ -35,6 +37,8 @@ public class MapMappingMethod extends NormalTypeMappingMethod { private final Assignment keyAssignment; private final Assignment valueAssignment; + private final Parameter sourceParameter; + private final PresenceCheck sourceParameterPresenceCheck; private IterableCreation iterableCreation; public static class Builder extends AbstractMappingMethodBuilder { @@ -235,16 +239,28 @@ private MapMappingMethod(Method method, List annotations, this.keyAssignment = keyAssignment; this.valueAssignment = valueAssignment; - } - - public Parameter getSourceParameter() { + Parameter sourceParameter = null; for ( Parameter parameter : getParameters() ) { if ( !parameter.isMappingTarget() && !parameter.isMappingContext() ) { - return parameter; + sourceParameter = parameter; + break; } } - throw new IllegalStateException( "Method " + this + " has no source parameter." ); + if ( sourceParameter == null ) { + throw new IllegalStateException( "Method " + this + " has no source parameter." ); + } + + this.sourceParameter = sourceParameter; + this.sourceParameterPresenceCheck = new NullPresenceCheck( this.sourceParameter.getName() ); + } + + public Parameter getSourceParameter() { + return sourceParameter; + } + + public PresenceCheck getSourceParameterPresenceCheck() { + return sourceParameterPresenceCheck; } public List getSourceElementTypes() { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java index e6adceab03..879a76efbe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java @@ -18,9 +18,15 @@ public class MethodReferencePresenceCheck extends ModelElement implements PresenceCheck { protected final MethodReference methodReference; + protected final boolean negate; public MethodReferencePresenceCheck(MethodReference methodReference) { + this( methodReference, false ); + } + + public MethodReferencePresenceCheck(MethodReference methodReference, boolean negate) { this.methodReference = methodReference; + this.negate = negate; } @Override @@ -32,6 +38,15 @@ public MethodReference getMethodReference() { return methodReference; } + public boolean isNegate() { + return negate; + } + + @Override + public PresenceCheck negate() { + return new MethodReferencePresenceCheck( methodReference, true ); + } + @Override public boolean equals(Object o) { if ( this == o ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java new file mode 100644 index 0000000000..f8844edcdd --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.common; + +import java.util.Objects; +import java.util.Set; + +/** + * @author Filip Hrisafov + */ +public class NegatePresenceCheck extends ModelElement implements PresenceCheck { + + private final PresenceCheck presenceCheck; + + public NegatePresenceCheck(PresenceCheck presenceCheck) { + this.presenceCheck = presenceCheck; + } + + public PresenceCheck getPresenceCheck() { + return presenceCheck; + } + + @Override + public Set getImportTypes() { + return presenceCheck.getImportTypes(); + } + + @Override + public PresenceCheck negate() { + return presenceCheck; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + NegatePresenceCheck that = (NegatePresenceCheck) o; + return Objects.equals( presenceCheck, that.presenceCheck ); + } + + @Override + public int hashCode() { + return Objects.hash( presenceCheck ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java index e77e24f218..ec286480d9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/PresenceCheck.java @@ -21,4 +21,6 @@ public interface PresenceCheck { */ Set getImportTypes(); + PresenceCheck negate(); + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java index df8b008032..6bb191214f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java @@ -11,6 +11,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.NegatePresenceCheck; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; @@ -29,6 +30,11 @@ public Collection getPresenceChecks() { return presenceChecks; } + @Override + public PresenceCheck negate() { + return new NegatePresenceCheck( this ); + } + @Override public Set getImportTypes() { Set importTypes = new HashSet<>(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java index d4f52c9f27..e100be7e79 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java @@ -10,6 +10,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.NegatePresenceCheck; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; @@ -28,6 +29,11 @@ public String getJavaExpression() { return javaExpression; } + @Override + public PresenceCheck negate() { + return new NegatePresenceCheck( this ); + } + @Override public Set getImportTypes() { return Collections.emptySet(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java index c9cae61b7c..3496486e1d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java @@ -19,20 +19,36 @@ public class NullPresenceCheck extends ModelElement implements PresenceCheck { private final String sourceReference; + private final boolean negate; public NullPresenceCheck(String sourceReference) { this.sourceReference = sourceReference; + this.negate = false; + } + + public NullPresenceCheck(String sourceReference, boolean negate) { + this.sourceReference = sourceReference; + this.negate = negate; } public String getSourceReference() { return sourceReference; } + public boolean isNegate() { + return negate; + } + @Override public Set getImportTypes() { return Collections.emptySet(); } + @Override + public PresenceCheck negate() { + return new NullPresenceCheck( sourceReference, !negate ); + } + @Override public boolean equals(Object o) { if ( this == o ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java index 3710e97173..0f75fbba69 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java @@ -10,6 +10,7 @@ import java.util.Set; import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.NegatePresenceCheck; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; @@ -20,10 +21,16 @@ public class SuffixPresenceCheck extends ModelElement implements PresenceCheck { private final String sourceReference; private final String suffix; + private final boolean negate; public SuffixPresenceCheck(String sourceReference, String suffix) { + this( sourceReference, suffix, false ); + } + + public SuffixPresenceCheck(String sourceReference, String suffix, boolean negate) { this.sourceReference = sourceReference; this.suffix = suffix; + this.negate = negate; } public String getSourceReference() { @@ -34,6 +41,15 @@ public String getSuffix() { return suffix; } + public boolean isNegate() { + return negate; + } + + @Override + public PresenceCheck negate() { + return new NegatePresenceCheck( this ); + } + @Override public Set getImportTypes() { return Collections.emptySet(); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 0f9b96bb66..8fb5bfdef0 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -27,8 +27,8 @@ - <#if !mapNullToDefault && !sourceParametersExcludingPrimitives.empty> - if ( <#list sourceParametersExcludingPrimitives as sourceParam>${sourceParam.name} == null<#if sourceParam_has_next> && ) { + <#if !mapNullToDefault && !sourcePresenceChecks.empty> + if ( <#list sourcePresenceChecks as sourcePresenceCheck><@includeModel object=sourcePresenceCheck.negate() /><#if sourcePresenceCheck_has_next> && ) { return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /><#else>null; } @@ -47,19 +47,19 @@ <#if !existingInstanceMapping> <#if hasConstructorMappings()> <#if (sourceParameters?size > 1)> - <#list sourceParametersNeedingNullCheck as sourceParam> + <#list sourceParametersNeedingPresenceCheck as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; - if ( ${sourceParam.name} != null ) { + if ( <@includeModel object=getPresenceCheckByParameter(sourceParam) /> ) { <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> } - <#list sourceParametersNotNeedingNullCheck as sourceParam> + <#list sourceParametersNotNeedingPresenceCheck as sourceParam> <#if (constructorPropertyMappingsByParameter(sourceParam)?size > 0)> <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; @@ -71,7 +71,7 @@ <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; - <#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) { + <#if mapNullToDefault>if ( <@includeModel object=getPresenceCheckByParameter(sourceParameters[0]) /> ) { <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -100,16 +100,16 @@ <#if (sourceParameters?size > 1)> - <#list sourceParametersNeedingNullCheck as sourceParam> + <#list sourceParametersNeedingPresenceCheck as sourceParam> <#if (propertyMappingsByParameter(sourceParam)?size > 0)> - if ( ${sourceParam.name} != null ) { + if ( <@includeModel object=getPresenceCheckByParameter(sourceParam) /> ) { <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> } - <#list sourceParametersNotNeedingNullCheck as sourceParam> + <#list sourceParametersNotNeedingPresenceCheck as sourceParam> <#if (propertyMappingsByParameter(sourceParam)?size > 0)> <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -117,7 +117,7 @@ <#else> - <#if mapNullToDefault>if ( ${sourceParameters[0].name} != null ) { + <#if mapNullToDefault>if ( <@includeModel object=getPresenceCheckByParameter(sourceParameters[0]) /> ) { <#list propertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 9af6e762bf..4d08c44b38 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -17,7 +17,7 @@ - if ( ${sourceParameter.name} == null ) { + if ( <@includeModel object=sourceParameterPresenceCheck.negate() /> ) { <#if !mapNullToDefault> return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 0e388da103..1227dbd27a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -17,7 +17,7 @@ - if ( ${sourceParameter.name} == null ) { + if ( <@includeModel object=sourceParameterPresenceCheck.negate() /> ) { <#if !mapNullToDefault> return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl index 9a1c7b24ae..0452e1699a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -6,7 +6,7 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> -<@includeModel object=methodReference +<#if isNegate()>!<@includeModel object=methodReference presenceCheck=true targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index 29977bdd5d..7d0080a1d2 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -18,7 +18,7 @@ - if ( ${sourceParameter.name} == null ) { + if ( <@includeModel object=sourceParameterPresenceCheck.negate() /> ) { <#if !mapNullToDefault> return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#else>null; <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.ftl new file mode 100644 index 0000000000..6951952487 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.ftl @@ -0,0 +1,9 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.NegatePresenceCheck" --> +!( <@includeModel object=presenceCheck /> ) \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl index 6e5494c735..ebd9f12eca 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.NullPresenceCheck" --> -${sourceReference} != null \ No newline at end of file +${sourceReference} <#if isNegate()>==<#else>!= null \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl index 103b4e7f9c..8eddad3485 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.ftl @@ -6,4 +6,4 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck" --> -${sourceReference}${suffix} \ No newline at end of file +<#if isNegate()>!${sourceReference}${suffix} \ No newline at end of file From 721288140aa1c1210de222224b44f23e82be0c53 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:14:53 +0200 Subject: [PATCH 0786/1006] Feature/2663 (#3007) #2663 Fix for 2-step mapping with generics. --------- Co-authored-by: Ben Zegveld --- .../ap/internal/model/common/Type.java | 116 +++++++++++++++++- .../creation/MappingResolverImpl.java | 2 +- .../ap/test/bugs/_2663/Issue2663Mapper.java | 31 +++++ .../ap/test/bugs/_2663/Issue2663Test.java | 47 +++++++ .../ap/test/bugs/_2663/JsonNullable.java | 44 +++++++ .../ap/test/bugs/_2663/Nullable.java | 45 +++++++ .../ap/test/bugs/_2663/NullableHelper.java | 23 ++++ .../mapstruct/ap/test/bugs/_2663/Request.java | 44 +++++++ .../ap/test/bugs/_2663/RequestDto.java | 44 +++++++ 9 files changed, 390 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/JsonNullable.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Nullable.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/NullableHelper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Request.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/RequestDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index a6d942748d..c18574fcfb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -605,6 +605,21 @@ public Type withoutBounds() { ); } + private Type replaceGeneric(Type oldGenericType, Type newType) { + if ( !typeParameters.contains( oldGenericType ) || newType == null ) { + return this; + } + newType = newType.getBoxedEquivalent(); + TypeMirror[] replacedTypeMirrors = new TypeMirror[typeParameters.size()]; + for ( int i = 0; i < typeParameters.size(); i++ ) { + Type typeParameter = typeParameters.get( i ); + replacedTypeMirrors[i] = + typeParameter.equals( oldGenericType ) ? newType.typeMirror : typeParameter.typeMirror; + } + + return typeFactory.getType( typeUtils.getDeclaredType( typeElement, replacedTypeMirrors ) ); + } + /** * Whether this type is assignable to the given other type, considering the "extends / upper bounds" * as well. @@ -1377,9 +1392,9 @@ public boolean isLiteral() { /** * Steps through the declaredType in order to find a match for this typeVar Type. It aligns with - * the provided parameterized type where this typeVar type is used. - * - * For example: + * the provided parameterized type where this typeVar type is used.
      + *
      + * For example:

            * {@code
            * this: T
            * declaredType: JAXBElement
      @@ -1392,12 +1407,13 @@ public boolean isLiteral() {
            * parameterizedType: Callable
            * return: BigDecimal
            * }
      +     * 
      * * @param declared the type * @param parameterized the parameterized type * - * @return - the same type when this is not a type var in the broadest sense (T, T[], or ? extends T) - * - the matching parameter in the parameterized type when this is a type var when found + * @return - the same type when this is not a type var in the broadest sense (T, T[], or ? extends T)
      + * - the matching parameter in the parameterized type when this is a type var when found
      * - null in all other cases */ public ResolvedPair resolveParameterToType(Type declared, Type parameterized) { @@ -1408,6 +1424,96 @@ public ResolvedPair resolveParameterToType(Type declared, Type parameterized) { return new ResolvedPair( this, this ); } + /** + * Resolves generic types using the declared and parameterized types as input.
      + *
      + * For example: + *
      +     * {@code
      +     * this: T
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: Integer
      +     *
      +     * this: List
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: List
      +     *
      +     * this: List
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: List
      +     *
      +     * this: List>
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: List>
      +     * }
      +     * 
      + * It also works for partial matching.
      + *
      + * For example: + *
      +     * {@code
      +     * this: Map
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: Map
      +     * }
      +     * 
      + * It also works with multiple parameters at both sides.
      + *
      + * For example when reversing Key/Value for a Map: + *
      +     * {@code
      +     * this: Map
      +     * declaredType: HashMap
      +     * parameterizedType: HashMap
      +     * result: Map
      +     * }
      +     * 
      + * + * Mismatch result examples: + *
      +     * {@code
      +     * this: T
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: null
      +     *
      +     * this: List
      +     * declaredType: JAXBElement
      +     * parameterizedType: JAXBElement
      +     * result: List
      +     * }
      +     * 
      + * + * @param declared the type + * @param parameterized the parameterized type + * + * @return - the result of {@link #resolveParameterToType(Type, Type)} when this type itself is a type var.
      + * - the type but then with the matching type parameters replaced.
      + * - the same type when this type does not contain matching type parameters. + */ + public Type resolveGenericTypeParameters(Type declared, Type parameterized) { + if ( isTypeVar() || isArrayTypeVar() || isWildCardBoundByTypeVar() ) { + return resolveParameterToType( declared, parameterized ).getMatch(); + } + Type resultType = this; + for ( Type generic : getTypeParameters() ) { + if ( generic.isTypeVar() || generic.isArrayTypeVar() || generic.isWildCardBoundByTypeVar() ) { + ResolvedPair resolveParameterToType = generic.resolveParameterToType( declared, parameterized ); + resultType = resultType.replaceGeneric( generic, resolveParameterToType.getMatch() ); + } + else { + Type replacementType = generic.resolveParameterToType( declared, parameterized ).getMatch(); + resultType = resultType.replaceGeneric( generic, replacementType ); + } + } + return resultType; + } + public boolean isWildCardBoundByTypeVar() { return ( hasExtendsBound() || hasSuperBound() ) && getTypeBound().isTypeVar(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 586465d5f1..32fa1af931 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -825,7 +825,7 @@ private MethodMethod getBestMatch(Type sourceType, Type targetType, Best for ( T2 yCandidate : yMethods ) { Type ySourceType = yCandidate.getMappingSourceType(); - ySourceType = ySourceType.resolveParameterToType( targetType, yCandidate.getResultType() ).getMatch(); + ySourceType = ySourceType.resolveGenericTypeParameters( targetType, yCandidate.getResultType() ); Type yTargetType = yCandidate.getResultType(); if ( ySourceType == null || !yTargetType.isRawAssignableTo( targetType ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Mapper.java new file mode 100644 index 0000000000..0ac236372a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Mapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper( uses = NullableHelper.class ) +public interface Issue2663Mapper { + + Issue2663Mapper INSTANCE = Mappers.getMapper( Issue2663Mapper.class ); + + Request map(RequestDto dto); + + default JsonNullable mapJsonNullableChildren(JsonNullable dtos) { + if ( dtos.isPresent() ) { + return JsonNullable.of( mapChild( dtos.get() ) ); + } + else { + return JsonNullable.undefined(); + } + } + + Request.ChildRequest mapChild(RequestDto.ChildRequestDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Test.java new file mode 100644 index 0000000000..efd14b1d36 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Issue2663Test.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey( "2663" ) +@WithClasses({ + Issue2663Mapper.class, + JsonNullable.class, + Nullable.class, + NullableHelper.class, + Request.class, + RequestDto.class +}) +public class Issue2663Test { + + @ProcessorTest + public void shouldUnpackGenericsCorrectly() { + RequestDto dto = new RequestDto(); + dto.setName( JsonNullable.of( "Tester" ) ); + + Request request = Issue2663Mapper.INSTANCE.map( dto ); + + assertThat( request.getName() ) + .extracting( Nullable::get ) + .isEqualTo( "Tester" ); + + dto.setName( JsonNullable.undefined() ); + + request = Issue2663Mapper.INSTANCE.map( dto ); + + assertThat( request.getName() ) + .extracting( Nullable::isPresent ) + .isEqualTo( false ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/JsonNullable.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/JsonNullable.java new file mode 100644 index 0000000000..4794aff940 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/JsonNullable.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +import java.util.NoSuchElementException; + +/** + * @author Filip Hrisafov + */ +public class JsonNullable { + + private static final JsonNullable UNDEFINED = new JsonNullable<>( null, false ); + + private final T value; + private final boolean present; + + private JsonNullable(T value, boolean present) { + this.value = value; + this.present = present; + } + + public T get() { + if (!present) { + throw new NoSuchElementException("Value is undefined"); + } + return value; + } + + public boolean isPresent() { + return present; + } + + @SuppressWarnings("unchecked") + public static JsonNullable undefined() { + return (JsonNullable) UNDEFINED; + } + + public static JsonNullable of(T value) { + return new JsonNullable<>( value, true ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Nullable.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Nullable.java new file mode 100644 index 0000000000..f6309be1c6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Nullable.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +import java.util.NoSuchElementException; + +/** + * @author Filip Hrisafov + */ +public class Nullable { + + @SuppressWarnings("rawtypes") + private static final Nullable UNDEFINED = new Nullable<>( null, false ); + + private final T value; + private final boolean present; + + private Nullable(T value, boolean present) { + this.value = value; + this.present = present; + } + + public T get() { + if (!present) { + throw new NoSuchElementException("Value is undefined"); + } + return value; + } + + public boolean isPresent() { + return present; + } + + public static Nullable of(T value) { + return new Nullable<>( value, true ); + } + + @SuppressWarnings("unchecked") + public static Nullable undefined() { + return (Nullable) UNDEFINED; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/NullableHelper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/NullableHelper.java new file mode 100644 index 0000000000..ae68300e62 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/NullableHelper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +/** + * @author Filip Hrisafov + */ +public class NullableHelper { + + private NullableHelper() { + // Helper class + } + + public static Nullable jsonNullableToNullable(JsonNullable jsonNullable) { + if ( jsonNullable.isPresent() ) { + return Nullable.of( jsonNullable.get() ); + } + return Nullable.undefined(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Request.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Request.java new file mode 100644 index 0000000000..8b58e2e0b5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/Request.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +/** + * @author Filip Hrisafov + */ +public class Request { + + private Nullable name = Nullable.undefined(); + private Nullable child = Nullable.undefined(); + + public Nullable getName() { + return name; + } + + public void setName(Nullable name) { + this.name = name; + } + + public Nullable getChild() { + return child; + } + + public void setChild(Nullable child) { + this.child = child; + } + + public static class ChildRequest { + + private Nullable name = Nullable.undefined(); + + public Nullable getName() { + return name; + } + + public void setName(Nullable name) { + this.name = name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/RequestDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/RequestDto.java new file mode 100644 index 0000000000..d1a93a9bd4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2663/RequestDto.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._2663; + +/** + * @author Filip Hrisafov + */ +public class RequestDto { + + private JsonNullable name = JsonNullable.undefined(); + private JsonNullable child = JsonNullable.undefined(); + + public JsonNullable getName() { + return name; + } + + public void setName(JsonNullable name) { + this.name = name; + } + + public JsonNullable getChild() { + return child; + } + + public void setChild(JsonNullable child) { + this.child = child; + } + + public static class ChildRequestDto { + + private JsonNullable name = JsonNullable.undefined(); + + public JsonNullable getName() { + return name; + } + + public void setName(JsonNullable name) { + this.name = name; + } + } +} From 8cc2bdd0928a11acf2ef656e93a0ebadbb740b90 Mon Sep 17 00:00:00 2001 From: Ben Zegveld Date: Tue, 1 Aug 2023 15:04:15 +0200 Subject: [PATCH 0787/1006] #3163: Strip wild card when checking for type assignability --- .../ap/internal/model/common/Type.java | 9 +++-- .../ap/test/bugs/_3163/Issue3163Mapper.java | 22 +++++++++++ .../ap/test/bugs/_3163/Issue3163Test.java | 21 ++++++++++ .../mapstruct/ap/test/bugs/_3163/Source.java | 34 +++++++++++++++++ .../mapstruct/ap/test/bugs/_3163/Target.java | 38 +++++++++++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index c18574fcfb..f742e1ba0f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -629,11 +629,14 @@ private Type replaceGeneric(Type oldGenericType, Type newType) { * @return {@code true} if and only if this type is assignable to the given other type. */ public boolean isAssignableTo(Type other) { + TypeMirror otherMirror = other.typeMirror; + if ( otherMirror.getKind() == TypeKind.WILDCARD ) { + otherMirror = typeUtils.erasure( other.typeMirror ); + } if ( TypeKind.WILDCARD == typeMirror.getKind() ) { - return typeUtils.contains( typeMirror, other.typeMirror ); + return typeUtils.contains( typeMirror, otherMirror ); } - - return typeUtils.isAssignable( typeMirror, other.typeMirror ); + return typeUtils.isAssignable( typeMirror, otherMirror ); } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Mapper.java new file mode 100644 index 0000000000..bd44a9d386 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3163; + +import java.util.Optional; + +import org.mapstruct.Mapper; + +@Mapper +public interface Issue3163Mapper { + + Target map(Source value); + + Target.Nested map(Source.Nested value); + + default Optional wrapAsOptional(T value) { + return Optional.ofNullable( value ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Test.java new file mode 100644 index 0000000000..5c16a707f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Issue3163Test.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3163; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +@WithClasses({ + Issue3163Mapper.class, + Source.class, + Target.class +}) +class Issue3163Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Source.java new file mode 100644 index 0000000000..8f5a57f1bf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Source.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3163; + +/** + * @author Filip Hrisafov + */ +public class Source { + + private final Nested nested; + + public Source(Nested nested) { + this.nested = nested; + } + + public Nested getNested() { + return nested; + } + + public static class Nested { + private final String value; + + public Nested(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Target.java new file mode 100644 index 0000000000..301a281d2d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3163/Target.java @@ -0,0 +1,38 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3163; + +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private Nested nested; + + public Optional getNested() { + return Optional.ofNullable( nested ); + } + + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + public final void setNested(Optional nested) { + this.nested = nested.orElse( null ); + } + + public static class Nested { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} From ea997f83cefd7d3900f8a6a218af1c20f7a1ef8a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 19 Aug 2023 10:09:36 +0200 Subject: [PATCH 0788/1006] #2340 Add FUNDING.yml --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..be6d63e5d2 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: mapstruct +open_collective: mapstruct From f61a3acec301de2a781bd46a56cdcf5c83ca159e Mon Sep 17 00:00:00 2001 From: GVladi <47348760+GVladi@users.noreply.github.com> Date: Wed, 30 Aug 2023 22:07:38 +0200 Subject: [PATCH 0789/1006] #3089 Improve support for Map attributes for Immutables Co-Authored-By: thunderhook <8238759+thunderhook@users.noreply.github.com> --- ...eatureCompilationExclusionCliEnhancer.java | 1 + .../spi/ImmutablesAccessorNamingStrategy.java | 13 +- .../ap/test/bugs/_1801/Issue1801Test.java | 2 +- .../test/bugs/_1801/domain/ImmutableItem.java | 2 +- .../bugs/_3089/Issue3089BuilderProvider.java | 96 +++++ .../ap/test/bugs/_3089/Issue3089Test.java | 61 ++++ .../ap/test/bugs/_3089/ItemMapper.java | 23 ++ .../test/bugs/_3089/domain/ImmutableItem.java | 296 ++++++++++++++++ .../ap/test/bugs/_3089/domain/Item.java | 19 + .../test/bugs/_3089/dto/ImmutableItemDTO.java | 330 ++++++++++++++++++ .../ap/test/bugs/_3089/dto/ItemDTO.java | 18 + 11 files changed, 858 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089BuilderProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/ItemMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/ImmutableItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/Item.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ImmutableItemDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ItemDTO.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index c0ea96fd5c..15d9e42598 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -26,6 +26,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces // SPI not working correctly here.. (not picked up) additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1596/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/bugs/_1801/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/bugs/_3089/*.java" ); switch ( currentJreVersion ) { case JAVA_8: diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java index 100798e063..1df6ebc1b6 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesAccessorNamingStrategy.java @@ -21,7 +21,18 @@ public class ImmutablesAccessorNamingStrategy extends DefaultAccessorNamingStrat @Override protected boolean isFluentSetter(ExecutableElement method) { - return super.isFluentSetter( method ) && !method.getSimpleName().toString().equals( "from" ); + return super.isFluentSetter( method ) && + !method.getSimpleName().toString().equals( "from" ) && + !isPutterWithUpperCase4thCharacter( method ); + } + + private boolean isPutterWithUpperCase4thCharacter(ExecutableElement method) { + return isPutterMethod( method ) && Character.isUpperCase( method.getSimpleName().toString().charAt( 3 ) ); + } + + public boolean isPutterMethod(ExecutableElement method) { + String methodName = method.getSimpleName().toString(); + return methodName.startsWith( "put" ) && methodName.length() > 3; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java index ee6076f823..40b9515305 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/Issue1801Test.java @@ -38,7 +38,7 @@ public class Issue1801Test { @ProcessorTest - public void shouldIncludeBuildeType() { + public void shouldIncludeBuilderType() { ItemDTO item = ImmutableItemDTO.builder().id( "test" ).build(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java index 68231f12ef..393dc153d6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1801/domain/ImmutableItem.java @@ -124,7 +124,7 @@ public final Builder from(Item instance) { /** * Initializes the value for the {@link Item#getId() id} attribute. - * @param id The value for id + * @param id The value for id * @return {@code this} builder for use in a chained invocation */ public final Builder id(String id) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089BuilderProvider.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089BuilderProvider.java new file mode 100644 index 0000000000..c827d32587 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089BuilderProvider.java @@ -0,0 +1,96 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089; + +import java.util.List; +import java.util.Objects; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; + +import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; + +/** + * @author Oliver Erhart + */ +public class Issue3089BuilderProvider extends ImmutablesBuilderProvider implements BuilderProvider { + + @Override + protected BuilderInfo findBuilderInfo(TypeElement typeElement) { + Name name = typeElement.getQualifiedName(); + if ( name.toString().endsWith( ".Item" ) ) { + BuilderInfo info = findBuilderInfoFromInnerBuilderClass( typeElement ); + if ( info != null ) { + return info; + } + } + return super.findBuilderInfo( typeElement ); + } + + /** + * Looks for inner builder class in the Immutable interface / abstract class. + * + * The inner builder class should be be declared with the following line + * + *
      +     *     public static Builder() extends ImmutableItem.Builder { }
      +     * 
      + * + * The Immutable instance should be created with the following line + * + *
      +     *     new Item.Builder().withId("123").build();
      +     * 
      + * + * @see org.mapstruct.ap.test.bugs._3089.domain.Item + * + * @param typeElement + * @return + */ + private BuilderInfo findBuilderInfoFromInnerBuilderClass(TypeElement typeElement) { + if (shouldIgnore( typeElement )) { + return null; + } + + List innerTypes = ElementFilter.typesIn( typeElement.getEnclosedElements() ); + ExecutableElement defaultConstructor = innerTypes.stream() + .filter( this::isBuilderCandidate ) + .map( this::getEmptyArgPublicConstructor ) + .filter( Objects::nonNull ) + .findAny() + .orElse( null ); + + if ( defaultConstructor != null ) { + return new BuilderInfo.Builder() + .builderCreationMethod( defaultConstructor ) + .buildMethod( findBuildMethods( (TypeElement) defaultConstructor.getEnclosingElement(), typeElement ) ) + .build(); + } + return null; + } + + private boolean isBuilderCandidate(TypeElement innerType ) { + TypeElement outerType = (TypeElement) innerType.getEnclosingElement(); + String packageName = this.elementUtils.getPackageOf( outerType ).getQualifiedName().toString(); + Name outerSimpleName = outerType.getSimpleName(); + String builderClassName = packageName + ".Immutable" + outerSimpleName + ".Builder"; + return innerType.getSimpleName().contentEquals( "Builder" ) + && getTypeElement( innerType.getSuperclass() ).getQualifiedName().contentEquals( builderClassName ) + && innerType.getModifiers().contains( Modifier.PUBLIC ); + } + + private ExecutableElement getEmptyArgPublicConstructor(TypeElement builderType) { + return ElementFilter.constructorsIn( builderType.getEnclosedElements() ).stream() + .filter( c -> c.getParameters().isEmpty() ) + .filter( c -> c.getModifiers().contains( Modifier.PUBLIC ) ) + .findAny() + .orElse( null ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089Test.java new file mode 100644 index 0000000000..f7c138c146 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/Issue3089Test.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.test.bugs._3089.domain.ImmutableItem; +import org.mapstruct.ap.test.bugs._3089.domain.Item; +import org.mapstruct.ap.test.bugs._3089.dto.ImmutableItemDTO; +import org.mapstruct.ap.test.bugs._3089.dto.ItemDTO; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.WithServiceImplementations; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Oliver Erhart + */ +@WithClasses({ + ItemMapper.class, + Item.class, + ImmutableItem.class, + ItemDTO.class, + ImmutableItemDTO.class +}) +@IssueKey("3089") +@WithServiceImplementations({ + @WithServiceImplementation(provides = BuilderProvider.class, value = Issue3089BuilderProvider.class), + @WithServiceImplementation(provides = AccessorNamingStrategy.class, value = ImmutablesAccessorNamingStrategy.class) +}) +public class Issue3089Test { + + @ProcessorTest + public void shouldIgnorePutterOfMap() { + + Map attributesMap = new HashMap<>(); + attributesMap.put( "a", "b" ); + attributesMap.put( "c", "d" ); + + ItemDTO item = ImmutableItemDTO.builder() + .id( "test" ) + .attributes( attributesMap ) + .build(); + + Item target = ItemMapper.INSTANCE.map( item ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( "test" ); + assertThat( target.getAttributes() ).isEqualTo( attributesMap ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/ItemMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/ItemMapper.java new file mode 100644 index 0000000000..ed06115ae2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/ItemMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089; + +import org.mapstruct.Builder; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._3089.domain.Item; +import org.mapstruct.ap.test.bugs._3089.dto.ItemDTO; +import org.mapstruct.factory.Mappers; + +/** + * @author Oliver Erhart + */ +@Mapper(builder = @Builder) +public abstract class ItemMapper { + + public static final ItemMapper INSTANCE = Mappers.getMapper( ItemMapper.class ); + + public abstract Item map(ItemDTO itemDTO); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/ImmutableItem.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/ImmutableItem.java new file mode 100644 index 0000000000..ab5a6afdc0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/ImmutableItem.java @@ -0,0 +1,296 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089.domain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Immutable implementation of {@link Item}. + *

      + * Superclass should expose a static subclass of the Builder to create immutable instance + * {@code public static Builder extends ImmutableItem.Builder}. + * + * @author Oliver Erhart + */ +@SuppressWarnings({"all"}) +public final class ImmutableItem extends Item { + private final String id; + private final Map attributes; + + private ImmutableItem(String id, Map attributes) { + this.id = id; + this.attributes = attributes; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * @return The value of the {@code attributes} attribute + */ + @Override + public Map getAttributes() { + return attributes; + } + + /** + * Copy the current immutable object by setting a value for the {@link Item#getId() id} attribute. + * An equals check used to prevent copying of the same value by returning {@code this}. + * @param value A new value for id + * @return A modified copy of the {@code this} object + */ + public final ImmutableItem withId(String value) { + String newValue = Objects.requireNonNull(value, "id"); + if (this.id.equals(newValue)) return this; + return new ImmutableItem(newValue, this.attributes); + } + + /** + * Copy the current immutable object by replacing the {@link Item#getAttributes() attributes} map with the specified map. + * Nulls are not permitted as keys or values. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * @param entries The entries to be added to the attributes map + * @return A modified copy of {@code this} object + */ + public final ImmutableItem withAttributes(Map entries) { + if (this.attributes == entries) return this; + Map newValue = createUnmodifiableMap(true, false, entries); + return new ImmutableItem(this.id, newValue); + } + + /** + * This instance is equal to all instances of {@code ImmutableItem} that have equal attribute values. + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if (this == another) return true; + return another instanceof ImmutableItem + && equalTo((ImmutableItem) another); + } + + private boolean equalTo(ImmutableItem another) { + return id.equals(another.id) + && attributes.equals(another.attributes); + } + + /** + * Computes a hash code from attributes: {@code id}, {@code attributes}. + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += (h << 5) + id.hashCode(); + h += (h << 5) + attributes.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code Item} with attribute values. + * @return A string representation of the value + */ + @Override + public String toString() { + return "Item{" + + "id=" + id + + ", attributes=" + attributes + + "}"; + } + + /** + * Creates an immutable copy of a {@link Item} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * @param instance The instance to copy + * @return A copied immutable Item instance + */ + public static ImmutableItem copyOf(Item instance) { + if (instance instanceof ImmutableItem) { + return (ImmutableItem) instance; + } + return ImmutableItem.builder() + .from(instance) + .build(); + } + + /** + * Creates a builder for {@link ImmutableItem ImmutableItem}. + *

      +   * ImmutableItem.builder()
      +   *    .id(String) // required {@link Item#getId() id}
      +   *    .putAttributes|putAllAttributes(String => String) // {@link Item#getAttributes() attributes} mappings
      +   *    .build();
      +   * 
      + * @return A new ImmutableItem builder + */ + public static ImmutableItem.Builder builder() { + return new ImmutableItem.Builder(); + } + + /** + * Builds instances of type {@link ImmutableItem ImmutableItem}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + private Map attributes = new LinkedHashMap(); + + public Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code Item} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * Collection elements and entries will be added, not replaced. + * @param instance The instance from which to copy values + * @return {@code this} builder for use in a chained invocation + */ + public final Builder from(Item instance) { + Objects.requireNonNull(instance, "instance"); + id(instance.getId()); + putAllAttributes(instance.getAttributes()); + return this; + } + + /** + * Initializes the value for the {@link Item#getId() id} attribute. + * @param id The value for id + * @return {@code this} builder for use in a chained invocation + */ + public final Builder id(String id) { + this.id = Objects.requireNonNull(id, "id"); + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Put one entry to the {@link Item#getAttributes() attributes} map. + * @param key The key in the attributes map + * @param value The associated value in the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Builder putAttributes(String key, String value) { + this.attributes.put( + Objects.requireNonNull(key, "attributes key"), + Objects.requireNonNull(value, "attributes value")); + return this; + } + + /** + * Put one entry to the {@link Item#getAttributes() attributes} map. Nulls are not permitted + * @param entry The key and value entry + * @return {@code this} builder for use in a chained invocation + */ + public final Builder putAttributes(Map.Entry entry) { + String k = entry.getKey(); + String v = entry.getValue(); + this.attributes.put( + Objects.requireNonNull(k, "attributes key"), + Objects.requireNonNull(v, "attributes value")); + return this; + } + + /** + * Sets or replaces all mappings from the specified map as entries for the {@link Item#getAttributes() attributes} map. Nulls are not permitted + * @param entries The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Builder attributes(Map entries) { + this.attributes.clear(); + return putAllAttributes(entries); + } + + /** + * Put all mappings from the specified map as entries to {@link Item#getAttributes() attributes} map. Nulls are not permitted + * @param entries The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Builder putAllAttributes(Map entries) { + for (Map.Entry e : entries.entrySet()) { + String k = e.getKey(); + String v = e.getValue(); + this.attributes.put( + Objects.requireNonNull(k, "attributes key"), + Objects.requireNonNull(v, "attributes value")); + } + return this; + } + + /** + * Builds a new {@link ImmutableItem ImmutableItem}. + * @return An immutable instance of Item + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItem build() { + if (initBits != 0) { + throw new IllegalStateException(formatRequiredAttributesMessage()); + } + return new ImmutableItem(id, createUnmodifiableMap(false, false, attributes)); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList<>(); + if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); + return "Cannot build Item, some of required attributes are not set " + attributes; + } + } + + private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map map) { + switch (map.size()) { + case 0: return Collections.emptyMap(); + case 1: { + Map.Entry e = map.entrySet().iterator().next(); + K k = e.getKey(); + V v = e.getValue(); + if (checkNulls) { + Objects.requireNonNull(k, "key"); + Objects.requireNonNull(v, "value"); + } + if (skipNulls && (k == null || v == null)) { + return Collections.emptyMap(); + } + return Collections.singletonMap(k, v); + } + default: { + Map linkedMap = new LinkedHashMap<>(map.size()); + if (skipNulls || checkNulls) { + for (Map.Entry e : map.entrySet()) { + K k = e.getKey(); + V v = e.getValue(); + if (skipNulls) { + if (k == null || v == null) continue; + } else if (checkNulls) { + Objects.requireNonNull(k, "key"); + Objects.requireNonNull(v, "value"); + } + linkedMap.put(k, v); + } + } else { + linkedMap.putAll(map); + } + return Collections.unmodifiableMap(linkedMap); + } + } + } +} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/Item.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/Item.java new file mode 100644 index 0000000000..e193432367 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/domain/Item.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089.domain; + +import java.util.Map; + +/** + * @author Oliver Erhart + */ +public abstract class Item { + public abstract String getId(); + + public abstract Map getAttributes(); + + public static class Builder extends ImmutableItem.Builder { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ImmutableItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ImmutableItemDTO.java new file mode 100644 index 0000000000..de64727bf1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ImmutableItemDTO.java @@ -0,0 +1,330 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089.dto; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Immutable implementation of {@link ItemDTO}. + *

      + * Use the builder to create immutable instances: + * {@code ImmutableItemDTO.builder()}. + * + * @author Oliver Erhart + */ +public final class ImmutableItemDTO extends ItemDTO { + private final String id; + private final Map attributes; + + private ImmutableItemDTO(String id, Map attributes) { + this.id = id; + this.attributes = attributes; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * @return The value of the {@code attributes} attribute + */ + @Override + public Map getAttributes() { + return attributes; + } + + /** + * Copy the current immutable object by setting a value for the {@link ItemDTO#getId() id} attribute. + * An equals check used to prevent copying of the same value by returning {@code this}. + * + * @param value A new value for id + * @return A modified copy of the {@code this} object + */ + public ImmutableItemDTO withId(String value) { + String newValue = Objects.requireNonNull( value, "id" ); + if ( this.id.equals( newValue ) ) { + return this; + } + return new ImmutableItemDTO( newValue, this.attributes ); + } + + /** + * Copy the current immutable object by replacing the {@link ItemDTO#getAttributes() attributes} map with + * the specified map. + * Nulls are not permitted as keys or values. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * + * @param entries The entries to be added to the attributes map + * @return A modified copy of {@code this} object + */ + public ImmutableItemDTO withAttributes(Map entries) { + if ( this.attributes == entries ) { + return this; + } + Map newValue = createUnmodifiableMap( true, false, entries ); + return new ImmutableItemDTO( this.id, newValue ); + } + + /** + * This instance is equal to all instances of {@code ImmutableItemDTO} that have equal attribute values. + * + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if ( this == another ) { + return true; + } + return another instanceof ImmutableItemDTO + && equalTo( (ImmutableItemDTO) another ); + } + + private boolean equalTo(ImmutableItemDTO another) { + return id.equals( another.id ) + && attributes.equals( another.attributes ); + } + + /** + * Computes a hash code from attributes: {@code id}, {@code attributes}. + * + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 5381; + h += ( h << 5 ) + id.hashCode(); + h += ( h << 5 ) + attributes.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code Item} with attribute values. + * + * @return A string representation of the value + */ + @Override + public String toString() { + return "Item{" + + "id=" + id + + ", attributes=" + attributes + + "}"; + } + + /** + * Creates an immutable copy of a {@link ItemDTO} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * + * @param instance The instance to copy + * @return A copied immutable Item instance + */ + public static ImmutableItemDTO copyOf(ItemDTO instance) { + if ( instance instanceof ImmutableItemDTO ) { + return (ImmutableItemDTO) instance; + } + return ImmutableItemDTO.builder() + .from( instance ) + .build(); + } + + /** + * Creates a builder for {@link ImmutableItemDTO ImmutableItemDTO}. + *

      +     * ImmutableItemDTO.builder()
      +     *    .id(String) // required {@link ItemDTO#getId() id}
      +     *    .putAttributes|putAllAttributes(String => String) // {@link ItemDTO#getAttributes() attributes} mappings
      +     *    .build();
      +     * 
      + * + * @return A new ImmutableItemDTO builder + */ + public static ImmutableItemDTO.Builder builder() { + return new ImmutableItemDTO.Builder(); + } + + /** + * Builds instances of type {@link ImmutableItemDTO ImmutableItemDTO}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + private Map attributes = new LinkedHashMap(); + + public Builder() { + } + + /** + * Fill a builder with attribute values from the provided {@code Item} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * Collection elements and entries will be added, not replaced. + * + * @param instance The instance from which to copy values + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder from(ItemDTO instance) { + Objects.requireNonNull( instance, "instance" ); + id( instance.getId() ); + putAllAttributes( instance.getAttributes() ); + return this; + } + + /** + * Initializes the value for the {@link ItemDTO#getId() id} attribute. + * + * @param id The value for id + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder id(String id) { + this.id = Objects.requireNonNull( id, "id" ); + initBits &= ~INIT_BIT_ID; + return this; + } + + /** + * Put one entry to the {@link ItemDTO#getAttributes() attributes} map. + * + * @param key The key in the attributes map + * @param value The associated value in the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder putAttributes(String key, String value) { + this.attributes.put( + Objects.requireNonNull( key, "attributes key" ), + Objects.requireNonNull( value, "attributes value" ) + ); + return this; + } + + /** + * Put one entry to the {@link ItemDTO#getAttributes() attributes} map. Nulls are not permitted + * + * @param entry The key and value entry + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder putAttributes(Map.Entry entry) { + String k = entry.getKey(); + String v = entry.getValue(); + this.attributes.put( + Objects.requireNonNull( k, "attributes key" ), + Objects.requireNonNull( v, "attributes value" ) + ); + return this; + } + + /** + * Sets or replaces all mappings from the specified map as entries for the {@link ItemDTO#getAttributes() + * attributes} map. Nulls are not permitted + * + * @param entries The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder attributes(Map entries) { + this.attributes.clear(); + return putAllAttributes( entries ); + } + + /** + * Put all mappings from the specified map as entries to {@link ItemDTO#getAttributes() attributes} map. + * Nulls are not permitted + * + * @param entries The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final ImmutableItemDTO.Builder putAllAttributes(Map entries) { + for ( Map.Entry e : entries.entrySet() ) { + String k = e.getKey(); + String v = e.getValue(); + this.attributes.put( + Objects.requireNonNull( k, "attributes key" ), + Objects.requireNonNull( v, "attributes value" ) + ); + } + return this; + } + + /** + * Builds a new {@link ImmutableItemDTO ImmutableItemDTO}. + * + * @return An immutable instance of Item + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItemDTO build() { + if ( initBits != 0 ) { + throw new IllegalStateException( formatRequiredAttributesMessage() ); + } + return new ImmutableItemDTO( id, createUnmodifiableMap( false, false, attributes ) ); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList<>(); + if ( ( initBits & INIT_BIT_ID ) != 0 ) { + attributes.add( "id" ); + } + return "Cannot build Item, some of required attributes are not set " + attributes; + } + } + + @SuppressWarnings( "checkstyle:AvoidNestedBlocks" ) + private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, + Map map) { + switch ( map.size() ) { + case 0: + return Collections.emptyMap(); + case 1: { + Map.Entry e = map.entrySet().iterator().next(); + K k = e.getKey(); + V v = e.getValue(); + if ( checkNulls ) { + Objects.requireNonNull( k, "key" ); + Objects.requireNonNull( v, "value" ); + } + if ( skipNulls && ( k == null || v == null ) ) { + return Collections.emptyMap(); + } + return Collections.singletonMap( k, v ); + } + default: { + Map linkedMap = new LinkedHashMap<>( map.size() ); + if ( skipNulls || checkNulls ) { + for ( Map.Entry e : map.entrySet() ) { + K k = e.getKey(); + V v = e.getValue(); + if ( skipNulls ) { + if ( k == null || v == null ) { + continue; + } + } + else if ( checkNulls ) { + Objects.requireNonNull( k, "key" ); + Objects.requireNonNull( v, "value" ); + } + linkedMap.put( k, v ); + } + } + else { + linkedMap.putAll( map ); + } + return Collections.unmodifiableMap( linkedMap ); + } + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ItemDTO.java new file mode 100644 index 0000000000..c38e37f08a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3089/dto/ItemDTO.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3089.dto; + +import java.util.Map; + +/** + * @author Oliver Erhart + */ +public abstract class ItemDTO { + public abstract String getId(); + + public abstract Map getAttributes(); + +} From 032ee4d77adaa23e2012381eb76e9ab94f937cc3 Mon Sep 17 00:00:00 2001 From: Nikolas Charalambidis Date: Sat, 16 Sep 2023 23:13:20 +0700 Subject: [PATCH 0790/1006] #3374 Lombok compatibility documentation --- .../asciidoc/chapter-14-third-party-api-integration.asciidoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc index 0f12d67e22..ef2a58f82e 100644 --- a/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc +++ b/documentation/src/main/asciidoc/chapter-14-third-party-api-integration.asciidoc @@ -46,8 +46,10 @@ public @interface Default { MapStruct works together with https://projectlombok.org/[Project Lombok] as of MapStruct 1.2.0.Beta1 and Lombok 1.16.14. MapStruct takes advantage of generated getters, setters, and constructors and uses them to generate the mapper implementations. +Be reminded that the generated code by Lombok might not always be compatible with the expectations from the individual mappings. +In such a case, either Mapstruct mapping must be changed or Lombok must be configured accordingly using https://projectlombok.org/features/configuration[`lombok.config`] for mutual synergy. -[NOTE] +[WARNING] ==== Lombok 1.18.16 introduces a breaking change (https://projectlombok.org/changelog[changelog]). The additional annotation processor `lombok-mapstruct-binding` (https://mvnrepository.com/artifact/org.projectlombok/lombok-mapstruct-binding[Maven]) must be added otherwise MapStruct stops working with Lombok. From 97c389d58bd125c022edf4a6cba1a485c33eb754 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:42:54 +0000 Subject: [PATCH 0791/1006] Bump org.codehaus.plexus:plexus-utils from 3.0.20 to 3.0.24 in /parent Bumps [org.codehaus.plexus:plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.0.20 to 3.0.24. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.0.20...plexus-utils-3.0.24) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 32f7e2897a..73239c87e3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -304,7 +304,7 @@ org.codehaus.plexus plexus-utils - 3.0.20 + 3.0.24 commons-io From c59eca2a77a02ea97ab0b87c8a90c48266e106dc Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 30 Sep 2023 21:52:07 +0200 Subject: [PATCH 0792/1006] #3361 Inheriting mappings should only be applied if the target has been redefined --- .../model/source/MappingMethodOptions.java | 8 +- .../ap/test/bugs/_3361/Issue3361Mapper.java | 80 +++++++++++++++++++ .../ap/test/bugs/_3361/Issue3361Test.java | 34 ++++++++ 3 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 73474a8478..d17172211b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -278,20 +278,16 @@ private void addAllNonRedefined(SourceMethod sourceMethod, AnnotationMirror anno } private void addAllNonRedefined(Set inheritedMappings) { - Set redefinedSources = new HashSet<>(); + // We are only adding the targets here since this mappings have already been reversed Set redefinedTargets = new HashSet<>(); for ( MappingOptions redefinedMappings : mappings ) { - if ( redefinedMappings.getSourceName() != null ) { - redefinedSources.add( redefinedMappings.getSourceName() ); - } if ( redefinedMappings.getTargetName() != null ) { redefinedTargets.add( redefinedMappings.getTargetName() ); } } for ( MappingOptions inheritedMapping : inheritedMappings ) { if ( inheritedMapping.isIgnored() - || ( !isRedefined( redefinedSources, inheritedMapping.getSourceName() ) - && !isRedefined( redefinedTargets, inheritedMapping.getTargetName() ) ) + || !isRedefined( redefinedTargets, inheritedMapping.getTargetName() ) ) { mappings.add( inheritedMapping ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Mapper.java new file mode 100644 index 0000000000..a556b63306 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Mapper.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3361; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class Issue3361Mapper { + + public static final Issue3361Mapper INSTANCE = Mappers.getMapper( Issue3361Mapper.class ); + + @Mapping(target = "someAttribute", source = "source.attribute") + @Mapping(target = "otherAttribute", source = "otherSource.anotherAttribute") + public abstract Target mapFromSource(Source source, OtherSource otherSource); + + @InheritConfiguration(name = "mapFromSource") + @Mapping(target = "otherAttribute", source = "source", qualifiedByName = "otherMapping") + public abstract Target mapInherited(Source source, OtherSource otherSource); + + @Named("otherMapping") + protected Long otherMapping(Source source) { + return source.getAttribute() != null ? 1L : 0L; + } + + public static class Target { + private String someAttribute; + private Long otherAttribute; + + public String getSomeAttribute() { + return someAttribute; + } + + public Target setSomeAttribute(String someAttribute) { + this.someAttribute = someAttribute; + return this; + } + + public Long getOtherAttribute() { + return otherAttribute; + } + + public Target setOtherAttribute(Long otherAttribute) { + this.otherAttribute = otherAttribute; + return this; + } + } + + public static class Source { + private final String attribute; + + public Source(String attribute) { + this.attribute = attribute; + } + + public String getAttribute() { + return attribute; + } + } + + public static class OtherSource { + + private final Long anotherAttribute; + + public OtherSource(Long anotherAttribute) { + this.anotherAttribute = anotherAttribute; + } + + public Long getAnotherAttribute() { + return anotherAttribute; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Test.java new file mode 100644 index 0000000000..3fa16ec1ae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3361/Issue3361Test.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3361; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3361") +@WithClasses(Issue3361Mapper.class) +class Issue3361Test { + + @ProcessorTest + void multiSourceShouldInherit() { + Issue3361Mapper.Source source = new Issue3361Mapper.Source( "Test" ); + Issue3361Mapper.OtherSource otherSource = new Issue3361Mapper.OtherSource( 10L ); + + Issue3361Mapper.Target target = Issue3361Mapper.INSTANCE.mapFromSource( source, otherSource ); + assertThat( target.getSomeAttribute() ).isEqualTo( "Test" ); + assertThat( target.getOtherAttribute() ).isEqualTo( 10L ); + + target = Issue3361Mapper.INSTANCE.mapInherited( source, otherSource ); + assertThat( target.getSomeAttribute() ).isEqualTo( "Test" ); + assertThat( target.getOtherAttribute() ).isEqualTo( 1L ); + } +} From 5d39314bd216b8818face21ec8be95d9f7cfff18 Mon Sep 17 00:00:00 2001 From: Xiu Hong Kooi Date: Wed, 1 Nov 2023 06:55:11 +0800 Subject: [PATCH 0793/1006] #3376 support mapping from iterables to collection --- .../internal/conversion/ConversionUtils.java | 1 + .../ap/internal/model/PropertyMapping.java | 3 +- .../creation/MappingResolverImpl.java | 1 - .../test/collection/iterabletolist/Fruit.java | 27 ++++++++++ .../collection/iterabletolist/FruitSalad.java | 29 +++++++++++ .../iterabletolist/FruitsMapper.java | 24 +++++++++ .../collection/iterabletolist/FruitsMenu.java | 35 +++++++++++++ .../IterableToListMappingTest.java | 47 +++++++++++++++++ .../test/collection/iterabletoset/Fruit.java | 27 ++++++++++ .../collection/iterabletoset/FruitSalad.java | 29 +++++++++++ .../iterabletoset/FruitsMapper.java | 24 +++++++++ .../collection/iterabletoset/FruitsMenu.java | 35 +++++++++++++ .../IterableToSetMappingTest.java | 50 +++++++++++++++++++ 13 files changed, 330 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/Fruit.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitSalad.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMenu.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/IterableToListMappingTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/Fruit.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitSalad.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMenu.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/IterableToSetMappingTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index 496d11676f..aa01a73276 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -278,4 +278,5 @@ public static String uuid(ConversionContext conversionContext) { public static String url(ConversionContext conversionContext) { return typeReferenceName( conversionContext, URL.class ); } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index b81cf55447..50f23ecbff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -301,7 +301,8 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get private Assignment forge( ) { Assignment assignment; Type sourceType = rightHandSide.getSourceType(); - if ( (sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() ) { + if ( ( sourceType.isCollectionType() || sourceType.isArrayType()) && targetType.isIterableType() + || ( sourceType.isIterableType() && targetType.isCollectionType() ) ) { assignment = forgeIterableMapping( sourceType, targetType, rightHandSide ); } else if ( sourceType.isMapType() && targetType.isMapType() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 32fa1af931..b290ff56bc 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -434,7 +434,6 @@ private boolean allow2Steps() { private ConversionAssignment resolveViaConversion(Type sourceType, Type targetType) { ConversionProvider conversionProvider = conversions.getConversion( sourceType, targetType ); - if ( conversionProvider == null ) { return null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/Fruit.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/Fruit.java new file mode 100644 index 0000000000..c989aa4e19 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/Fruit.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletolist; + +/** + * + * @author Xiu-Hong Kooi + */ +public class Fruit { + + private String type; + + public Fruit(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitSalad.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitSalad.java new file mode 100644 index 0000000000..6a04121044 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitSalad.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletolist; + +import java.util.List; + +/** + * + * @author Xiu-Hong Kooi + */ +public class FruitSalad { + + private Iterable fruits; + + public FruitSalad(List fruits) { + this.fruits = fruits; + } + + public Iterable getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMapper.java new file mode 100644 index 0000000000..bb4fdc66af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletolist; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Xiu-Hong Kooi + */ +@Mapper +public interface FruitsMapper { + + FruitsMapper INSTANCE = Mappers.getMapper( + FruitsMapper.class ); + + FruitsMenu fruitSaladToMenu(FruitSalad salad); + + FruitSalad fruitsMenuToSalad(FruitsMenu menu); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMenu.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMenu.java new file mode 100644 index 0000000000..6f272dc454 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/FruitsMenu.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletolist; + +import java.util.Iterator; +import java.util.List; + +/** + * + * @author Xiu-Hong Kooi + */ +public class FruitsMenu implements Iterable { + + private List fruits; + + public FruitsMenu(List fruits) { + this.fruits = fruits; + } + + public List getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } + + @Override + public Iterator iterator() { + return this.fruits.iterator(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/IterableToListMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/IterableToListMappingTest.java new file mode 100644 index 0000000000..915b9e5fd4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletolist/IterableToListMappingTest.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletolist; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * + * @author Xiu-Hong Kooi + */ +@WithClasses({ FruitsMenu.class, FruitSalad.class, Fruit.class, FruitsMapper.class }) +public class IterableToListMappingTest { + + @ProcessorTest + @IssueKey("3376") + public void shouldMapIterableToList() { + List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ); + FruitsMenu menu = new FruitsMenu(fruits); + FruitSalad salad = FruitsMapper.INSTANCE.fruitsMenuToSalad( menu ); + Iterator itr = salad.getFruits().iterator(); + assertThat( itr.next().getType() ).isEqualTo( "mango" ); + assertThat( itr.next().getType() ).isEqualTo( "apple" ); + assertThat( itr.next().getType() ).isEqualTo( "banana" ); + } + + @ProcessorTest + @IssueKey("3376") + public void shouldMapListToIterable() { + List fruits = Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ); + FruitSalad salad = new FruitSalad(fruits); + FruitsMenu menu = FruitsMapper.INSTANCE.fruitSaladToMenu( salad ); + assertThat( menu.getFruits() ).extracting( Fruit::getType ).containsExactly( "mango", "apple", "banana" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/Fruit.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/Fruit.java new file mode 100644 index 0000000000..a15b344908 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/Fruit.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletoset; + +/** + * + * @author Xiu-Hong Kooi + */ +public class Fruit { + + private String type; + + public Fruit(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitSalad.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitSalad.java new file mode 100644 index 0000000000..b92ac3160c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitSalad.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletoset; + +import java.util.List; + +/** + * + * @author Xiu-Hong Kooi + */ +public class FruitSalad { + + private Iterable fruits; + + public FruitSalad(Iterable fruits) { + this.fruits = fruits; + } + + public Iterable getFruits() { + return fruits; + } + + public void setFruits(List fruits) { + this.fruits = fruits; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMapper.java new file mode 100644 index 0000000000..413dd73617 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletoset; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Xiu-Hong Kooi + */ +@Mapper +public interface FruitsMapper { + + FruitsMapper INSTANCE = Mappers.getMapper( + FruitsMapper.class ); + + FruitsMenu fruitSaladToMenu(FruitSalad salad); + + FruitSalad fruitsMenuToSalad(FruitsMenu menu); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMenu.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMenu.java new file mode 100644 index 0000000000..8ae4b8b632 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/FruitsMenu.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletoset; + +import java.util.Iterator; +import java.util.Set; + +/** + * + * @author Xiu-Hong Kooi + */ +public class FruitsMenu implements Iterable { + + private Set fruits; + + public FruitsMenu(Set fruits) { + this.fruits = fruits; + } + + public Set getFruits() { + return fruits; + } + + public void setFruits(Set fruits) { + this.fruits = fruits; + } + + @Override + public Iterator iterator() { + return this.fruits.iterator(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/IterableToSetMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/IterableToSetMappingTest.java new file mode 100644 index 0000000000..8b2373d4d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/iterabletoset/IterableToSetMappingTest.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.iterabletoset; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * + * @author Xiu-Hong Kooi + */ +@WithClasses({ FruitsMenu.class, FruitSalad.class, Fruit.class, FruitsMapper.class }) +public class IterableToSetMappingTest { + + @ProcessorTest + @IssueKey("3376") + public void shouldMapIterableToSet() { + Set fruits = new HashSet<>( Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ) ); + FruitsMenu menu = new FruitsMenu(fruits); + FruitSalad salad = FruitsMapper.INSTANCE.fruitsMenuToSalad( menu ); + Iterator itr = salad.getFruits().iterator(); + Set fruitTypes = fruits.stream().map( Fruit::getType ).collect( Collectors.toSet() ); + assertThat( fruitTypes.contains( itr.next().getType() ) ); + assertThat( fruitTypes.contains( itr.next().getType() ) ); + assertThat( fruitTypes.contains( itr.next().getType() ) ); + } + + @ProcessorTest + @IssueKey("3376") + public void shouldMapSetToIterable() { + Set fruits = new HashSet<>( Arrays.asList( new Fruit( "mango" ), new Fruit( "apple" ), + new Fruit( "banana" ) ) ); + FruitSalad salad = new FruitSalad(fruits); + FruitsMenu menu = FruitsMapper.INSTANCE.fruitSaladToMenu( salad ); + assertThat( menu.getFruits() ).extracting( Fruit::getType ).contains( "mango", "apple", "banana" ); + } +} From b77d321ffb06f42eab9219e120fdf1782bccef1b Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Wed, 1 Nov 2023 00:01:45 +0100 Subject: [PATCH 0794/1006] Added recent contributors (including myself) --- copyright.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/copyright.txt b/copyright.txt index 1b23a0e84a..a111489d01 100644 --- a/copyright.txt +++ b/copyright.txt @@ -44,6 +44,7 @@ Nikolas Charalambidis - https://github.com/Nikolas-Charalambidis Michael Pardo - https://github.com/pardom Mustafa Caylak - https://github.com/luxmeter Oliver Ehrenmüller - https://github.com/greuelpirat +Oliver Erhart - https://github.com/thunderhook Paul Strugnell - https://github.com/ps-powa Pascal Grün - https://github.com/pascalgn Pavel Makhov - https://github.com/streetturtle @@ -67,3 +68,4 @@ Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld Valentin Kulesh - https://github.com/unshare Vincent Alexander Beelte - https://github.com/grandmasterpixel +Xiu Hong Kooi - https://github.com/kooixh From 79f01e2de09c34ee08fef5288f8d8fa686250174 Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Sat, 4 Nov 2023 21:35:40 +0100 Subject: [PATCH 0795/1006] Change master to main branch and fix CI status badge (#3423) --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 8b8af9a69f..21d820dc58 100644 --- a/readme.md +++ b/readme.md @@ -2,10 +2,10 @@ [![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.5.Final-blue.svg)](https://search.maven.org/search?q=g:org.mapstruct%20AND%20v:1.*.Final) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://search.maven.org/search?q=g:org.mapstruct) -[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/master/LICENSE.txt) +[![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/main/LICENSE.txt) -[![Build Status](https://github.com/mapstruct/mapstruct/workflows/CI/badge.svg?branch=master)](https://github.com/mapstruct/mapstruct/actions?query=branch%3Amaster+workflow%3ACI) -[![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct) +[![Build Status](https://github.com/mapstruct/mapstruct/workflows/CI/badge.svg?branch=main)](https://github.com/mapstruct/mapstruct/actions?query=branch%3Amain+workflow%3ACI) +[![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct/tree/main) [![Gitter](https://img.shields.io/gitter/room/mapstruct/mapstruct.svg)](https://gitter.im/mapstruct/mapstruct-users) [![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/context:java) [![Total Alerts](https://img.shields.io/lgtm/alerts/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/alerts) From 0ac0c42dbc481a86879e3796d0201c622da61200 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Nov 2023 23:06:16 +0100 Subject: [PATCH 0796/1006] [maven-release-plugin] prepare release 1.6.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..2e244492d9 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..ddf9514f19 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..5a6a8f500c 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index afa8e31002..e04b31cd73 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..49f1dc3d6e 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f888e226ff..f9f43c871c 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 73239c87e3..6701e069f7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 pom MapStruct Parent @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.6.0.Beta1 diff --git a/pom.xml b/pom.xml index 25a5ead6bc..4c99f88d0a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - HEAD + 1.6.0.Beta1 diff --git a/processor/pom.xml b/processor/pom.xml index 12fc615f5f..5ab8d5027f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta1 ../parent/pom.xml From 04deac2b3ae4b9ffe1c31ce293ee2d6ad3b20418 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 4 Nov 2023 23:06:17 +0100 Subject: [PATCH 0797/1006] [maven-release-plugin] prepare for next development iteration --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 4 ++-- processor/pom.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 2e244492d9..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index ddf9514f19..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 5a6a8f500c..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index e04b31cd73..afa8e31002 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 49f1dc3d6e..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f9f43c871c..f888e226ff 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 6701e069f7..73239c87e3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -71,7 +71,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.6.0.Beta1 + HEAD diff --git a/pom.xml b/pom.xml index 4c99f88d0a..25a5ead6bc 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT parent/pom.xml @@ -54,7 +54,7 @@ scm:git:git://github.com/mapstruct/mapstruct.git scm:git:git@github.com:mapstruct/mapstruct.git https://github.com/mapstruct/mapstruct/ - 1.6.0.Beta1 + HEAD diff --git a/processor/pom.xml b/processor/pom.xml index 5ab8d5027f..12fc615f5f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta1 + 1.6.0-SNAPSHOT ../parent/pom.xml From 2af291ce2f1a9978c9d3f449d8bb8a9bb3b969f2 Mon Sep 17 00:00:00 2001 From: wandi34 Date: Sat, 11 Nov 2023 21:48:52 +0100 Subject: [PATCH 0798/1006] Fix Typo Mappper in SubclassMapping Doc --- copyright.txt | 1 + core/src/main/java/org/mapstruct/SubclassMapping.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/copyright.txt b/copyright.txt index a111489d01..d6dc8d1b8a 100644 --- a/copyright.txt +++ b/copyright.txt @@ -68,4 +68,5 @@ Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld Valentin Kulesh - https://github.com/unshare Vincent Alexander Beelte - https://github.com/grandmasterpixel +Winter Andreas - https://github.dev/wandi34 Xiu Hong Kooi - https://github.com/kooixh diff --git a/core/src/main/java/org/mapstruct/SubclassMapping.java b/core/src/main/java/org/mapstruct/SubclassMapping.java index ccf8d4d472..f5463b9026 100644 --- a/core/src/main/java/org/mapstruct/SubclassMapping.java +++ b/core/src/main/java/org/mapstruct/SubclassMapping.java @@ -49,7 +49,7 @@ * } * * Example 2: For parents that can be created. (e.g. normal classes or interfaces with - * @Mappper( uses = ObjectFactory.class ) ) + * @Mapper( uses = ObjectFactory.class ) ) *

      
        * // generates
        * @Override
      
      From 2bb2aefed8957861bf297b8f953b40e8753a8c75 Mon Sep 17 00:00:00 2001
      From: Muhammad Usama 
      Date: Fri, 24 Nov 2023 10:34:15 +0500
      Subject: [PATCH 0799/1006] #3413 Using Mapping#expression and
       Mapping#conditionaQualifiedBy(Name) should lead to compile error
      
      ---
       copyright.txt                                 |  1 +
       .../internal/model/source/MappingOptions.java |  5 ++-
       .../mapstruct/ap/internal/util/Message.java   |  1 +
       .../test/bugs/_3413/Erroneous3413Mapper.java  | 45 +++++++++++++++++++
       .../ap/test/bugs/_3413/Issue3413Test.java     | 35 +++++++++++++++
       5 files changed, 86 insertions(+), 1 deletion(-)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Erroneous3413Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Issue3413Test.java
      
      diff --git a/copyright.txt b/copyright.txt
      index d6dc8d1b8a..71d47a796a 100644
      --- a/copyright.txt
      +++ b/copyright.txt
      @@ -42,6 +42,7 @@ Kevin Grüneberg - https://github.com/kevcodez
       Lukas Lazar - https://github.com/LukeLaz
       Nikolas Charalambidis - https://github.com/Nikolas-Charalambidis
       Michael Pardo - https://github.com/pardom
      +Muhammad Usama - https://github.com/the-mgi
       Mustafa Caylak - https://github.com/luxmeter
       Oliver Ehrenmüller - https://github.com/greuelpirat
       Oliver Erhart - https://github.com/thunderhook
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java
      index 2af1c95f71..dd5b2f17b9 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java
      @@ -207,10 +207,13 @@ private static boolean isConsistent(MappingGem gem, ExecutableElement method,
               if ( gem.source().hasValue() && gem.constant().hasValue() ) {
                   message = Message.PROPERTYMAPPING_SOURCE_AND_CONSTANT_BOTH_DEFINED;
               }
      +        else if ( gem.expression().hasValue() && gem.conditionQualifiedByName().hasValue() ) {
      +            message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONDITION_QUALIFIED_BY_NAME_BOTH_DEFINED;
      +        }
               else if ( gem.source().hasValue() && gem.expression().hasValue() ) {
                   message = Message.PROPERTYMAPPING_SOURCE_AND_EXPRESSION_BOTH_DEFINED;
               }
      -        else if (gem.expression().hasValue() && gem.constant().hasValue() ) {
      +        else if ( gem.expression().hasValue() && gem.constant().hasValue() ) {
                   message = Message.PROPERTYMAPPING_EXPRESSION_AND_CONSTANT_BOTH_DEFINED;
               }
               else if ( gem.expression().hasValue() && gem.defaultValue().hasValue() ) {
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      index a24a43036c..4b43315390 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java
      @@ -84,6 +84,7 @@ public enum Message {
           PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PROPERTY_FROM_TARGET("The type of parameter \"%s\" has no property named \"%s\". Please define the source property explicitly."),
           PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET("No property named \"%s\" exists in source parameter(s). Please define the source explicitly."),
           PROPERTYMAPPING_NO_SUITABLE_COLLECTION_OR_MAP_CONSTRUCTOR( "%s does not have an accessible copy or no-args constructor." ),
      +    PROPERTYMAPPING_EXPRESSION_AND_CONDITION_QUALIFIED_BY_NAME_BOTH_DEFINED( "Expression and condition qualified by name are both defined in @Mapping, either define an expression or a condition qualified by name." ),
       
           CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ),
           CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ),
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Erroneous3413Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Erroneous3413Mapper.java
      new file mode 100644
      index 0000000000..784e47b8e7
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Erroneous3413Mapper.java
      @@ -0,0 +1,45 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct.ap.test.bugs._3413;
      +
      +import org.mapstruct.Mapper;
      +import org.mapstruct.Mapping;
      +import org.mapstruct.factory.Mappers;
      +
      +/**
      + * @author Muhammad Usama
      + */
      +@Mapper
      +public interface Erroneous3413Mapper {
      +    Erroneous3413Mapper INSTANCE = Mappers.getMapper( Erroneous3413Mapper.class );
      +
      +    @Mapping(target = "", expression = "", conditionQualifiedByName = "")
      +    ToPOJO map(FromPOJO fromPOJO);
      +
      +    class FromPOJO {
      +        private String value;
      +
      +        public String getValue() {
      +            return value;
      +        }
      +
      +        public void setValue(String value) {
      +            this.value = value;
      +        }
      +    }
      +
      +    class ToPOJO {
      +        private String value;
      +
      +        public String getValue() {
      +            return value;
      +        }
      +
      +        public void setValue(String value) {
      +            this.value = value;
      +        }
      +    }
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Issue3413Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Issue3413Test.java
      new file mode 100644
      index 0000000000..f98ed9cdbd
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3413/Issue3413Test.java
      @@ -0,0 +1,35 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct.ap.test.bugs._3413;
      +
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.ProcessorTest;
      +import org.mapstruct.ap.testutil.WithClasses;
      +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
      +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
      +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
      +
      +/**
      + * @author Muhammad Usama
      + */
      +@IssueKey("3413")
      +public class Issue3413Test {
      +    @ProcessorTest
      +    @WithClasses(Erroneous3413Mapper.class)
      +    @ExpectedCompilationOutcome(
      +        value = CompilationResult.FAILED,
      +        diagnostics = {
      +            @Diagnostic(
      +                kind = javax.tools.Diagnostic.Kind.ERROR,
      +                line = 19,
      +                message = "Expression and condition qualified by name are both defined in @Mapping, " +
      +                    "either define an expression or a condition qualified by name."
      +            )
      +        }
      +    )
      +    void errorExpectedBecauseExpressionAndConditionQualifiedByNameCannotCoExists() {
      +    }
      +}
      
      From 930f5709b65d6f8a573172247ad02293649c08a9 Mon Sep 17 00:00:00 2001
      From: Ravil Galeyev 
      Date: Wed, 29 Nov 2023 22:25:22 +0100
      Subject: [PATCH 0800/1006] #3400 Remove unnecessary casts to long and double
      
      ---
       .../java/org/mapstruct/ap/internal/util/NativeTypes.java    | 4 ++--
       .../ap/test/source/constants/ConstantsMapperImpl.java       | 6 +++---
       2 files changed, 5 insertions(+), 5 deletions(-)
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      index 769f7b83f0..5498d4c698 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java
      @@ -284,7 +284,7 @@ void parse(String val, int radix) {
       
               @Override
               public Class getLiteral() {
      -            return float.class;
      +            return double.class;
               }
       
           }
      @@ -363,7 +363,7 @@ else if ( new BigInteger( val, radix ).bitLength() > 64 ) {
       
               @Override
               public Class getLiteral() {
      -            return int.class;
      +            return long.class;
               }
           }
       
      diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      index f5f37142c2..ec13eed3fc 100644
      --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/source/constants/ConstantsMapperImpl.java
      @@ -33,12 +33,12 @@ public ConstantsTarget mapFromConstants(String dummy) {
               constantsTarget.setIntValue( -03777777 );
               constantsTarget.setIntBoxed( 15 );
               constantsTarget.setLongValue( 0x7fffffffffffffffL );
      -        constantsTarget.setLongBoxed( (long) 0xCAFEBABEL );
      +        constantsTarget.setLongBoxed( 0xCAFEBABEL );
               constantsTarget.setFloatValue( 1.40e-45f );
               constantsTarget.setFloatBoxed( 3.4028235e38f );
               constantsTarget.setDoubleValue( 1e137 );
      -        constantsTarget.setDoubleBoxed( (double) 0x0.001P-1062d );
      -        constantsTarget.setDoubleBoxedZero( (double) 0.0 );
      +        constantsTarget.setDoubleBoxed( 0x0.001P-1062d );
      +        constantsTarget.setDoubleBoxedZero( 0.0 );
       
               return constantsTarget;
           }
      
      From fa857e9ff46b5bb3e5a6c2c8b1c56009944f5ef3 Mon Sep 17 00:00:00 2001
      From: mosesonline 
      Date: Sun, 10 Dec 2023 15:26:47 +0100
      Subject: [PATCH 0801/1006] bump some lib versions (#3460)
      
      ---
       parent/pom.xml                                | 16 ++++-----
       .../testutil/assertions/JavaFileAssert.java   | 34 ++++---------------
       2 files changed, 15 insertions(+), 35 deletions(-)
      
      diff --git a/parent/pom.xml b/parent/pom.xml
      index 73239c87e3..1b2c27741d 100644
      --- a/parent/pom.xml
      +++ b/parent/pom.xml
      @@ -22,17 +22,17 @@
           
               UTF-8
               1.0.0.Alpha3
      -        3.0.0-M3
      -        3.0.0-M5
      +        3.4.1
      +        3.2.2
               3.1.0
               5.3.18
               1.6.0
               8.36.1
      -        5.8.0-M1
      -        1.4.2
      +        5.10.1
      +        2.2.0
               
               1
      -        3.17.2
      +        3.24.2
               
               
               jdt_apt
      @@ -226,7 +226,7 @@
                   
                       org.projectlombok
                       lombok
      -                1.18.22
      +                1.18.30
                   
                   
                       org.immutables
      @@ -253,7 +253,7 @@
                   
                       joda-time
                       joda-time
      -                2.9
      +                2.12.5
                   
       
                   
      @@ -309,7 +309,7 @@
                   
                       commons-io
                       commons-io
      -                2.7
      +                2.15.0
                   
       
                   
      diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java
      index e6eabd9f84..4c6da0d13c 100644
      --- a/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java
      +++ b/processor/src/test/java/org/mapstruct/ap/testutil/assertions/JavaFileAssert.java
      @@ -5,7 +5,11 @@
        */
       package org.mapstruct.ap.testutil.assertions;
       
      -import static java.lang.String.format;
      +import org.assertj.core.api.FileAssert;
      +import org.assertj.core.error.ShouldHaveSameContent;
      +import org.assertj.core.internal.Diff;
      +import org.assertj.core.internal.Failures;
      +import org.assertj.core.util.diff.Delta;
       
       import java.io.File;
       import java.io.IOException;
      @@ -15,14 +19,7 @@
       import java.util.ArrayList;
       import java.util.List;
       
      -import org.apache.commons.io.FileUtils;
      -import org.assertj.core.api.AbstractCharSequenceAssert;
      -import org.assertj.core.api.Assertions;
      -import org.assertj.core.api.FileAssert;
      -import org.assertj.core.error.ShouldHaveSameContent;
      -import org.assertj.core.internal.Diff;
      -import org.assertj.core.internal.Failures;
      -import org.assertj.core.util.diff.Delta;
      +import static java.lang.String.format;
       
       /**
        * Allows to perform assertions on .java source files.
      @@ -39,7 +36,7 @@ public class JavaFileAssert extends FileAssert {
           private static final String IMPORT_GENERATED_ANNOTATION_REGEX = "import javax\\.annotation\\.(processing\\.)?" +
               "Generated;";
       
      -    private Diff diff = new Diff();
      +    private final Diff diff = new Diff();
       
           /**
            * @param actual the actual file
      @@ -48,22 +45,6 @@ public JavaFileAssert(File actual) {
               super( actual );
           }
       
      -    /**
      -     * @return assertion on the file content
      -     */
      -    public AbstractCharSequenceAssert content() {
      -        exists();
      -        isFile();
      -
      -        try {
      -            return Assertions.assertThat( FileUtils.readFileToString( actual, StandardCharsets.UTF_8 ) );
      -        }
      -        catch ( IOException e ) {
      -            failWithMessage( "Unable to read" + actual + ". Exception: " + e.getMessage() );
      -        }
      -        return null;
      -    }
      -
           /**
            * Verifies that the specified class is imported in this Java file
            *
      @@ -118,7 +99,6 @@ public void hasSameMapperContent(File expected) {
            * or if it is a change delta for the date/comments part of a {@code @Generated} annotation.
            *
            * @param delta that needs to be checked
      -     *
            * @return {@code true} if this delta should be ignored, {@code false} otherwise
            */
           private boolean ignoreDelta(Delta delta) {
      
      From 6d99f7b8f312617c8a9526e81fbb2dbf3eaa96a5 Mon Sep 17 00:00:00 2001
      From: Filip Hrisafov 
      Date: Mon, 18 Dec 2023 07:35:26 +0100
      Subject: [PATCH 0802/1006] #3473 Add Java 21 and EA to build matrix
      
      Fix tests not running green on Java 21
      Update Spring to run correctly on Java 21
      ---
       .github/workflows/java-ea.yml                            | 6 +++---
       .github/workflows/main.yml                               | 2 +-
       parent/pom.xml                                           | 4 ++--
       .../ap/test/conversion/jodatime/JodaConversionTest.java  | 9 ++++-----
       4 files changed, 10 insertions(+), 11 deletions(-)
      
      diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml
      index 3cc488ca7e..d9b018bfb8 100644
      --- a/.github/workflows/java-ea.yml
      +++ b/.github/workflows/java-ea.yml
      @@ -17,9 +17,9 @@ jobs:
             - name: 'Checkout'
               uses: actions/checkout@v3
             - name: 'Set up JDK'
      -        uses: actions/setup-java@v3
      +        uses: oracle-actions/setup-java@v1
               with:
      -          distribution: 'zulu'
      -          java-version: ${{ matrix.java }}
      +          website: jdk.java.net
      +          release: EA
             - name: 'Test'
               run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true
      diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
      index 54cf0b1076..b27dfc075a 100644
      --- a/.github/workflows/main.yml
      +++ b/.github/workflows/main.yml
      @@ -12,7 +12,7 @@ jobs:
           strategy:
             fail-fast: false
             matrix:
      -        java: [13, 17, 18]
      +        java: [17, 21]
           name: 'Linux JDK ${{ matrix.java }}'
           runs-on: ubuntu-latest
           steps:
      diff --git a/parent/pom.xml b/parent/pom.xml
      index 1b2c27741d..e3f0d89627 100644
      --- a/parent/pom.xml
      +++ b/parent/pom.xml
      @@ -25,7 +25,7 @@
               3.4.1
               3.2.2
               3.1.0
      -        5.3.18
      +        5.3.31
               1.6.0
               8.36.1
               5.10.1
      @@ -576,7 +576,7 @@
                       
                           org.jacoco
                           jacoco-maven-plugin
      -                    0.8.8
      +                    0.8.11
                       
                       
                           org.jvnet.jaxb2.maven2
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java
      index 1ab73616d5..8574c7a6be 100644
      --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java
      +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java
      @@ -14,7 +14,6 @@
       import org.joda.time.LocalDateTime;
       import org.joda.time.LocalTime;
       import org.junit.jupiter.api.condition.EnabledForJreRange;
      -import org.junit.jupiter.api.condition.EnabledOnJre;
       import org.junit.jupiter.api.condition.JRE;
       import org.junitpioneer.jupiter.DefaultLocale;
       import org.mapstruct.ap.testutil.IssueKey;
      @@ -72,7 +71,7 @@ public void testLocalTimeToString() {
           }
       
           @ProcessorTest
      -    @EnabledOnJre(JRE.JAVA_8)
      +    @EnabledForJreRange(min = JRE.JAVA_21)
           // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+
           public void testSourceToTargetMappingForStrings() {
               Source src = new Source();
      @@ -93,14 +92,14 @@ public void testSourceToTargetMappingForStrings() {
               // and now with default mappings
               target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( src );
               assertThat( target ).isNotNull();
      -        assertThat( target.getDateTime() ).isEqualTo( "1. Januar 2014 00:00:00 UTC" );
      -        assertThat( target.getLocalDateTime() ).isEqualTo( "1. Januar 2014 00:00:00" );
      +        assertThat( target.getDateTime() ).isEqualTo( "1. Januar 2014, 00:00:00 UTC" );
      +        assertThat( target.getLocalDateTime() ).isEqualTo( "1. Januar 2014, 00:00:00" );
               assertThat( target.getLocalDate() ).isEqualTo( "1. Januar 2014" );
               assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" );
           }
       
           @ProcessorTest
      -    @EnabledForJreRange(min = JRE.JAVA_11)
      +    @EnabledForJreRange(min = JRE.JAVA_11, max = JRE.JAVA_17)
           // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+
           public void testSourceToTargetMappingForStringsJdk11() {
               Source src = new Source();
      
      From 7e6fee8714396cb79d81aaecae5f5cd69e178d09 Mon Sep 17 00:00:00 2001
      From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com>
      Date: Wed, 27 Dec 2023 13:40:04 +0100
      Subject: [PATCH 0803/1006] #1064 Provide a switch to turn off CheckStyle on
       generated test sources
      
      ---
       .../mapstruct/ap/testutil/runner/CompilingExtension.java    | 6 +++++-
       1 file changed, 5 insertions(+), 1 deletion(-)
      
      diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java
      index 7c47d2a2e8..95874e4b3d 100644
      --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java
      +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java
      @@ -182,11 +182,15 @@ private void assertResult(CompilationOutcomeDescriptor actualResult, ExtensionCo
               assertDiagnostics( actualResult.getDiagnostics(), expectedResult.getDiagnostics() );
               assertNotes( actualResult.getNotes(), expectedResult.getNotes() );
       
      -        if ( !findAnnotation( testClass, DisableCheckstyle.class ).isPresent() ) {
      +        if ( !findAnnotation( testClass, DisableCheckstyle.class ).isPresent() && !skipCheckstyleBySystemProperty() ) {
                   assertCheckstyleRules();
               }
           }
       
      +    private static boolean skipCheckstyleBySystemProperty() {
      +        return Boolean.parseBoolean( System.getProperty( "checkstyle.skip" ) );
      +    }
      +
           private void assertCheckstyleRules() throws Exception {
               if ( sourceOutputDir != null ) {
                   Properties properties = new Properties();
      
      From 6cb126cd7cd03aaf8254b3f7f12a29cb6d2ee1b0 Mon Sep 17 00:00:00 2001
      From: Filip Hrisafov 
      Date: Sun, 31 Dec 2023 09:34:34 +0100
      Subject: [PATCH 0804/1006] #3462 Stream getters should not be treated as
       alternative setter
      
      ---
       .../ap/internal/model/common/Type.java        | 16 ++++--
       .../ap/test/bugs/_3462/Issue3462Mapper.java   | 56 +++++++++++++++++++
       .../ap/test/bugs/_3462/Issue3462Test.java     | 34 +++++++++++
       3 files changed, 100 insertions(+), 6 deletions(-)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Test.java
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      index f742e1ba0f..54305cffc1 100644
      --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java
      @@ -821,12 +821,6 @@ else if ( candidate.getAccessorType() == AccessorType.GETTER ) {
                           candidate = adderMethod;
                       }
       
      -                if ( cmStrategy == CollectionMappingStrategyGem.TARGET_IMMUTABLE
      -                    && candidate.getAccessorType() == AccessorType.GETTER ) {
      -                    // If the collection mapping strategy is target immutable
      -                    // then the getter method cannot be used as a setter
      -                    continue;
      -                }
                   }
                   else if ( candidate.getAccessorType() == AccessorType.FIELD  && ( Executables.isFinal( candidate ) ||
                       result.containsKey( targetPropertyName ) ) ) {
      @@ -834,6 +828,16 @@ else if ( candidate.getAccessorType() == AccessorType.FIELD  && ( Executables.is
                       continue;
                   }
       
      +            if ( candidate.getAccessorType() == AccessorType.GETTER ) {
      +                // When the candidate is a getter then it can't be used in the following cases:
      +                // 1. The collection mapping strategy is target immutable
      +                // 2. The target type is a stream (streams are immutable)
      +                if ( cmStrategy == CollectionMappingStrategyGem.TARGET_IMMUTABLE ||
      +                    targetType != null && targetType.isStreamType() ) {
      +                    continue;
      +                }
      +            }
      +
                   Accessor previousCandidate = result.get( targetPropertyName );
                   if ( previousCandidate == null || preferredType == null || ( targetType != null
                       && typeUtils.isAssignable( preferredType.getTypeMirror(), targetType.getTypeMirror() ) ) ) {
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Mapper.java
      new file mode 100644
      index 0000000000..1bf87672c6
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Mapper.java
      @@ -0,0 +1,56 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct.ap.test.bugs._3462;
      +
      +import java.util.List;
      +import java.util.stream.Stream;
      +
      +import org.mapstruct.Mapper;
      +import org.mapstruct.factory.Mappers;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +@Mapper
      +public interface Issue3462Mapper {
      +
      +    Issue3462Mapper INSTANCE = Mappers.getMapper( Issue3462Mapper.class );
      +
      +    Target map(Source source);
      +
      +    class Source {
      +        private final List values;
      +
      +        public Source(List values) {
      +            this.values = values;
      +        }
      +
      +        public List getValues() {
      +            return values;
      +        }
      +
      +        public Stream getValuesStream() {
      +            return values != null ? values.stream() : Stream.empty();
      +        }
      +    }
      +
      +    class Target {
      +        private List values;
      +
      +        public List getValues() {
      +            return values;
      +        }
      +
      +        public void setValues(List values) {
      +            this.values = values;
      +        }
      +
      +        public Stream getValuesStream() {
      +            return values != null ? values.stream() : Stream.empty();
      +        }
      +    }
      +
      +}
      diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Test.java
      new file mode 100644
      index 0000000000..16be4f441e
      --- /dev/null
      +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3462/Issue3462Test.java
      @@ -0,0 +1,34 @@
      +/*
      + * Copyright MapStruct Authors.
      + *
      + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
      + */
      +package org.mapstruct.ap.test.bugs._3462;
      +
      +import java.util.Arrays;
      +
      +import org.mapstruct.ap.testutil.IssueKey;
      +import org.mapstruct.ap.testutil.ProcessorTest;
      +import org.mapstruct.ap.testutil.WithClasses;
      +
      +import static org.assertj.core.api.Assertions.assertThat;
      +
      +/**
      + * @author Filip Hrisafov
      + */
      +@IssueKey("3462")
      +@WithClasses(Issue3462Mapper.class)
      +class Issue3462Test {
      +
      +    @ProcessorTest
      +    void shouldNotTreatStreamGettersAsAlternativeSetter() {
      +
      +        Issue3462Mapper.Source source = new Issue3462Mapper.Source( Arrays.asList( "first", "second" ) );
      +        Issue3462Mapper.Target target = Issue3462Mapper.INSTANCE.map( source );
      +
      +        assertThat( target ).isNotNull();
      +        assertThat( target.getValues() ).containsExactly( "first", "second" );
      +        assertThat( target.getValuesStream() ).containsExactly( "first", "second" );
      +
      +    }
      +}
      
      From 60f162ca881076ac0540822026f0bb1c0a65b36e Mon Sep 17 00:00:00 2001
      From: Filip Hrisafov 
      Date: Sun, 28 Jan 2024 17:47:39 +0100
      Subject: [PATCH 0805/1006] #3463 DefaultBuilderProvider should be able to
       handle methods in parent interfaces
      
      ---
       .../ap/spi/DefaultBuilderProvider.java        | 131 ++++++++++++++----
       .../ap/test/bugs/_3463/EntityBuilder.java     |  14 ++
       .../ap/test/bugs/_3463/Issue3463Mapper.java   |  21 +++
       .../ap/test/bugs/_3463/Issue3463Test.java     |  33 +++++
       .../mapstruct/ap/test/bugs/_3463/Person.java  |  50 +++++++
       .../ap/test/bugs/_3463/PersonDto.java         |  21 +++
       6 files changed, 242 insertions(+), 28 deletions(-)
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/EntityBuilder.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Mapper.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Test.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Person.java
       create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/PersonDto.java
      
      diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java
      index f89e99cd17..6395364a35 100644
      --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java
      +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java
      @@ -14,6 +14,7 @@
       import javax.lang.model.element.Modifier;
       import javax.lang.model.element.TypeElement;
       import javax.lang.model.type.DeclaredType;
      +import javax.lang.model.type.ExecutableType;
       import javax.lang.model.type.TypeKind;
       import javax.lang.model.type.TypeMirror;
       import javax.lang.model.util.ElementFilter;
      @@ -107,19 +108,17 @@ public BuilderInfo findBuilderInfo(TypeMirror type) {
            * @throws TypeHierarchyErroneousException if the {@link TypeMirror} is of kind {@link TypeKind#ERROR}
            */
           protected TypeElement getTypeElement(TypeMirror type) {
      -        if ( type.getKind() == TypeKind.ERROR ) {
      -            throw new TypeHierarchyErroneousException( type );
      -        }
      -        DeclaredType declaredType = type.accept(
      -            new SimpleTypeVisitor6() {
      -                @Override
      -                public DeclaredType visitDeclared(DeclaredType t, Void p) {
      -                    return t;
      -                }
      -            },
      -            null
      -        );
      +        DeclaredType declaredType = getDeclaredType( type );
      +        return getTypeElement( declaredType );
      +    }
       
      +    /**
      +     * Find the {@link TypeElement} for the given {@link DeclaredType}.
      +     *
      +     * @param declaredType for which the {@link TypeElement} needs to be found.
      +     * @return the type element or {@code null} if the declared type element is not {@link TypeElement}
      +     */
      +    private TypeElement getTypeElement(DeclaredType declaredType) {
               if ( declaredType == null ) {
                   return null;
               }
      @@ -135,6 +134,28 @@ public TypeElement visitType(TypeElement e, Void p) {
               );
           }
       
      +    /**
      +     * Find the {@link DeclaredType} for the given {@link TypeMirror}.
      +     *
      +     * @param type for which the {@link DeclaredType} needs to be found.
      +     * @return the declared or {@code null} if the {@link TypeMirror} is not a {@link DeclaredType}
      +     * @throws TypeHierarchyErroneousException if the {@link TypeMirror} is of kind {@link TypeKind#ERROR}
      +     */
      +    private DeclaredType getDeclaredType(TypeMirror type) {
      +        if ( type.getKind() == TypeKind.ERROR ) {
      +            throw new TypeHierarchyErroneousException( type );
      +        }
      +        return type.accept(
      +            new SimpleTypeVisitor6() {
      +                @Override
      +                public DeclaredType visitDeclared(DeclaredType t, Void p) {
      +                    return t;
      +                }
      +            },
      +            null
      +        );
      +    }
      +
           /**
            * Find the {@link BuilderInfo} for the given {@code typeElement}.
            * 

      @@ -218,21 +239,32 @@ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, Type * Searches for a build method for {@code typeElement} within the {@code builderElement}. *

      * The default implementation iterates over each method in {@code builderElement} and uses - * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement)} to check if the method is a - * build method for {@code typeElement}. + * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, DeclaredType, TypeElement)} + * to check if the method is a build method for {@code typeElement}. *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the * {@code builderElement} should be ignored, i.e. not checked for build elements. *

      - * If there are multiple methods that satisfy - * {@link DefaultBuilderProvider#isBuildMethod(ExecutableElement, TypeElement)} and one of those methods - * is names {@code build} that that method would be considered as a build method. * @param builderElement the element for the builder * @param typeElement the element for the type that is being built * @return the build method for the {@code typeElement} if it exists, or {@code null} if it does not * {@code build} */ protected Collection findBuildMethods(TypeElement builderElement, TypeElement typeElement) { + if ( shouldIgnore( builderElement ) || typeElement == null ) { + return Collections.emptyList(); + } + DeclaredType builderType = getDeclaredType( builderElement.asType() ); + + if ( builderType == null ) { + return Collections.emptyList(); + } + + return findBuildMethods( builderElement, builderType, typeElement ); + } + + private Collection findBuildMethods(TypeElement builderElement, DeclaredType builderType, + TypeElement typeElement) { if ( shouldIgnore( builderElement ) ) { return Collections.emptyList(); } @@ -240,23 +272,57 @@ protected Collection findBuildMethods(TypeElement builderElem List builderMethods = ElementFilter.methodsIn( builderElement.getEnclosedElements() ); List buildMethods = new ArrayList<>(); for ( ExecutableElement buildMethod : builderMethods ) { - if ( isBuildMethod( buildMethod, typeElement ) ) { + if ( isBuildMethod( buildMethod, builderType, typeElement ) ) { buildMethods.add( buildMethod ); } } - if ( buildMethods.isEmpty() ) { - return findBuildMethods( - getTypeElement( builderElement.getSuperclass() ), + if ( !buildMethods.isEmpty() ) { + return buildMethods; + } + + Collection parentClassBuildMethods = findBuildMethods( + getTypeElement( builderElement.getSuperclass() ), + builderType, + typeElement + ); + + if ( !parentClassBuildMethods.isEmpty() ) { + return parentClassBuildMethods; + } + + List interfaces = builderElement.getInterfaces(); + if ( interfaces.isEmpty() ) { + return Collections.emptyList(); + } + + Collection interfaceBuildMethods = new ArrayList<>(); + + for ( TypeMirror builderInterface : interfaces ) { + interfaceBuildMethods.addAll( findBuildMethods( + getTypeElement( builderInterface ), + builderType, typeElement - ); + ) ); } - return buildMethods; + return interfaceBuildMethods; + } + + /** + * @see #isBuildMethod(ExecutableElement, DeclaredType, TypeElement) + * @deprecated use {@link #isBuildMethod(ExecutableElement, DeclaredType, TypeElement)} instead + */ + @Deprecated + protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement) { + return buildMethod.getParameters().isEmpty() && + buildMethod.getModifiers().contains( Modifier.PUBLIC ) + && typeUtils.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); } /** - * Checks if the {@code buildMethod} is a method that creates {@code typeElement}. + * Checks if the {@code buildMethod} is a method that creates the {@code typeElement} + * as a member of the {@code builderType}. *

      * The default implementation considers a method to be a build method if the following is satisfied: *

        @@ -266,14 +332,23 @@ protected Collection findBuildMethods(TypeElement builderElem *
      * * @param buildMethod the method that should be checked + * @param builderType the type of the builder in which the {@code buildMethod} is located in * @param typeElement the type element that needs to be built * @return {@code true} if the {@code buildMethod} is a build method for {@code typeElement}, {@code false} * otherwise */ - protected boolean isBuildMethod(ExecutableElement buildMethod, TypeElement typeElement) { - return buildMethod.getParameters().isEmpty() && - buildMethod.getModifiers().contains( Modifier.PUBLIC ) - && typeUtils.isAssignable( buildMethod.getReturnType(), typeElement.asType() ); + protected boolean isBuildMethod(ExecutableElement buildMethod, DeclaredType builderType, TypeElement typeElement) { + if ( !buildMethod.getParameters().isEmpty() ) { + return false; + } + if ( !buildMethod.getModifiers().contains( Modifier.PUBLIC ) ) { + return false; + } + TypeMirror buildMethodType = typeUtils.asMemberOf( builderType, buildMethod ); + if ( buildMethodType instanceof ExecutableType ) { + return typeUtils.isAssignable( ( (ExecutableType) buildMethodType ).getReturnType(), typeElement.asType() ); + } + return false; } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/EntityBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/EntityBuilder.java new file mode 100644 index 0000000000..6b0b71993e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/EntityBuilder.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3463; + +/** + * @author Filip Hrisafov + */ +public interface EntityBuilder { + + T build(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Mapper.java new file mode 100644 index 0000000000..37ead3dfdf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Mapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3463; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3463Mapper { + + Issue3463Mapper INSTANCE = Mappers.getMapper( Issue3463Mapper.class ); + + Person map(PersonDto dto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Test.java new file mode 100644 index 0000000000..e6cfc3ece7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Issue3463Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3463; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3463") +@WithClasses({ + EntityBuilder.class, + Issue3463Mapper.class, + Person.class, + PersonDto.class +}) +class Issue3463Test { + + @ProcessorTest + void shouldUseInterfaceBuildMethod() { + Person person = Issue3463Mapper.INSTANCE.map( new PersonDto( "Tester" ) ); + + assertThat( person ).isNotNull(); + assertThat( person.getName() ).isEqualTo( "Tester" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Person.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Person.java new file mode 100644 index 0000000000..977d619474 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/Person.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3463; + +/** + * @author Filip Hrisafov + */ +public class Person { + + private final String name; + + private Person(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Builder builder() { + return new BuilderImpl(); + } + + public interface Builder extends EntityBuilder { + + Builder name(String name); + } + + private static final class BuilderImpl implements Builder { + + private String name; + + private BuilderImpl() { + } + + @Override + public Builder name(String name) { + this.name = name; + return this; + } + + @Override + public Person build() { + return new Person( this.name ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/PersonDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/PersonDto.java new file mode 100644 index 0000000000..447e4813cc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3463/PersonDto.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3463; + +/** + * @author Filip Hrisafov + */ +public class PersonDto { + private final String name; + + public PersonDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} From 632213802817629c413bb83c9aebfc9bf25ee245 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:50:33 +0100 Subject: [PATCH 0806/1006] Add missing generic diamond operator to MappingOptions (#3498) --- .../org/mapstruct/ap/internal/model/source/MappingOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index dd5b2f17b9..f60eba1931 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -121,7 +121,7 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, String defaultValue = mapping.defaultValue().getValue(); Set dependsOn = mapping.dependsOn().hasValue() ? - new LinkedHashSet( mapping.dependsOn().getValue() ) : + new LinkedHashSet<>( mapping.dependsOn().getValue() ) : Collections.emptySet(); FormattingParameters formattingParam = new FormattingParameters( From 6830258f77096c12b826ab15851d0dc17cd9a9b4 Mon Sep 17 00:00:00 2001 From: Chanyut Yuvacharuskul Date: Sun, 28 Jan 2024 23:51:57 +0700 Subject: [PATCH 0807/1006] Fix typo in chapter-10-advanced-mapping-options.asciidoc (#3500) --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 87dffce31c..9d6c93f211 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -281,7 +281,7 @@ First calling a mapping method on the source property is not protected by a null The option `nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS` will always include a null check when source is non primitive, unless a source presence checker is defined on the source bean. -The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MaperConfig#nullValueCheckStrategy`. +The strategy works in a hierarchical fashion. `@Mapping#nullValueCheckStrategy` will override `@BeanMapping#nullValueCheckStrategy`, `@BeanMapping#nullValueCheckStrategy` will override `@Mapper#nullValueCheckStrategy` and `@Mapper#nullValueCheckStrategy` will override `@MapperConfig#nullValueCheckStrategy`. [[source-presence-check]] === Source presence checking From 90a3ce0b464e96a82f6c7d81aaba1fd36fca7b8e Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sun, 28 Jan 2024 18:06:42 +0100 Subject: [PATCH 0808/1006] Use primitive types in NativeTypes (#3501) --- .../java/org/mapstruct/ap/internal/util/NativeTypes.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index 5498d4c698..729cb180ef 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -270,11 +270,11 @@ public void validate(String s) { @Override void parse(String val, int radix) { - Double d = Double.parseDouble( radix == 16 ? "0x" + val : val ); + double d = Double.parseDouble( radix == 16 ? "0x" + val : val ); if ( doubleHasBecomeZero( d ) ) { throw new NumberFormatException( "floating point number too small" ); } - if ( d.isInfinite() ) { + if ( Double.isInfinite( d ) ) { throw new NumberFormatException( "infinitive is not allowed" ); } } @@ -297,11 +297,11 @@ public void validate(String s) { NumberRepresentation br = new NumberRepresentation( s, false, false, true ) { @Override void parse(String val, int radix) { - Float f = Float.parseFloat( radix == 16 ? "0x" + val : val ); + float f = Float.parseFloat( radix == 16 ? "0x" + val : val ); if ( doubleHasBecomeZero( f ) ) { throw new NumberFormatException( "floating point number too small" ); } - if ( f.isInfinite() ) { + if ( Float.isInfinite( f ) ) { throw new NumberFormatException( "infinitive is not allowed" ); } } From 0a43bc088f2f0bd934438d5ec8ca58b72e09998a Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sun, 28 Jan 2024 18:07:57 +0100 Subject: [PATCH 0809/1006] Add missing generic type to Javadoc Builder (#3499) --- .../src/main/java/org/mapstruct/ap/internal/model/Javadoc.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java index a1efc8c022..1afb5258a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Javadoc.java @@ -31,7 +31,7 @@ public Builder value(String value) { return this; } - public Builder authors(List authors) { + public Builder authors(List authors) { this.authors = authors; return this; } From 8191c850e0c210a5215512fe9ff67380125e7120 Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:42:23 +0100 Subject: [PATCH 0810/1006] #3323 Support access to the source property name --- .../main/java/org/mapstruct/Condition.java | 1 + .../org/mapstruct/SourcePropertyName.java | 26 ++ .../org/mapstruct/TargetPropertyName.java | 6 +- ...apter-10-advanced-mapping-options.asciidoc | 22 +- .../ap/internal/gem/GemGenerator.java | 2 + .../ap/internal/model/BeanMappingMethod.java | 1 + .../ap/internal/model/PropertyMapping.java | 17 +- .../ap/internal/model/common/Parameter.java | 21 +- .../model/common/ParameterBinding.java | 33 +- .../internal/model/source/SourceMethod.java | 9 +- .../source/selector/SelectionContext.java | 18 + .../model/source/selector/TypeSelector.java | 1 + .../processor/MethodRetrievalProcessor.java | 11 + .../mapstruct/ap/internal/util/Message.java | 1 + .../ap/internal/model/MethodReference.ftl | 7 +- .../model/MethodReferencePresenceCheck.ftl | 3 +- .../ap/internal/model/PropertyMapping.ftl | 1 + .../ap/internal/model/TypeConversion.ftl | 1 + .../ap/internal/model/macro/CommonMacros.ftl | 2 + .../Address.java | 2 +- .../AddressDto.java | 2 +- .../DomainModel.java | 2 +- .../Employee.java | 2 +- .../EmployeeDto.java | 22 +- ...ollectionMapperWithSourcePropertyName.java | 48 +++ ...onalMethodInMapperWithAllExceptTarget.java | 54 +++ ...nditionalMethodInMapperWithAllOptions.java | 64 ++++ ...lMethodInMapperWithSourcePropertyName.java | 39 +++ ...hodInUsesMapperWithSourcePropertyName.java | 43 +++ ...WithSourcePropertyNameInContextMapper.java | 108 ++++++ ...sNonStringSourcePropertyNameParameter.java | 26 ++ .../SourcePropertyNameTest.java | 312 ++++++++++++++++++ ...ollectionMapperWithTargetPropertyName.java | 11 +- ...onalMethodInMapperWithAllExceptTarget.java | 14 +- ...nditionalMethodInMapperWithAllOptions.java | 26 +- ...lMethodInMapperWithTargetPropertyName.java | 7 +- ...hodInUsesMapperWithTargetPropertyName.java | 7 +- ...WithTargetPropertyNameInContextMapper.java | 33 +- ...sNonStringTargetPropertyNameParameter.java | 7 +- .../TargetPropertyNameTest.java | 67 ++-- 40 files changed, 979 insertions(+), 100 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/SourcePropertyName.java rename processor/src/test/java/org/mapstruct/ap/test/conditional/{targetpropertyname => propertyname}/Address.java (86%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{targetpropertyname => propertyname}/AddressDto.java (86%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{targetpropertyname => propertyname}/DomainModel.java (80%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{targetpropertyname => propertyname}/Employee.java (96%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{targetpropertyname => propertyname}/EmployeeDto.java (75%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodForCollectionMapperWithSourcePropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllExceptTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllOptions.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithSourcePropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInUsesMapperWithSourcePropertyName.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodWithSourcePropertyNameInContextMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ErroneousNonStringSourcePropertyNameParameter.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/SourcePropertyNameTest.java rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java (76%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java (76%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java (61%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java (70%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java (74%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java (70%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java (59%) rename processor/src/test/java/org/mapstruct/ap/test/conditional/{ => propertyname}/targetpropertyname/TargetPropertyNameTest.java (88%) diff --git a/core/src/main/java/org/mapstruct/Condition.java b/core/src/main/java/org/mapstruct/Condition.java index 148ec4879d..37f1553be1 100644 --- a/core/src/main/java/org/mapstruct/Condition.java +++ b/core/src/main/java/org/mapstruct/Condition.java @@ -24,6 +24,7 @@ *
    3. The mapping source parameter
    4. *
    5. {@code @}{@link Context} parameter
    6. *
    7. {@code @}{@link TargetPropertyName} parameter
    8. + *
    9. {@code @}{@link SourcePropertyName} parameter
    10. * * * Note: The usage of this annotation is mandatory diff --git a/core/src/main/java/org/mapstruct/SourcePropertyName.java b/core/src/main/java/org/mapstruct/SourcePropertyName.java new file mode 100644 index 0000000000..a9d036d5d8 --- /dev/null +++ b/core/src/main/java/org/mapstruct/SourcePropertyName.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation marks a presence check method parameter as a source property name parameter. + *

      + * This parameter enables conditional filtering based on source property name at run-time. + * Parameter must be of type {@link String} and can be present only in {@link Condition} method. + *

      + * + * @author Oliver Erhart + * @since 1.6 + */ +@Target(ElementType.PARAMETER) +@Retention(RetentionPolicy.CLASS) +public @interface SourcePropertyName { +} diff --git a/core/src/main/java/org/mapstruct/TargetPropertyName.java b/core/src/main/java/org/mapstruct/TargetPropertyName.java index 17af966fa8..c7ab8d957d 100644 --- a/core/src/main/java/org/mapstruct/TargetPropertyName.java +++ b/core/src/main/java/org/mapstruct/TargetPropertyName.java @@ -11,10 +11,10 @@ import java.lang.annotation.Target; /** - * This annotation marks a presence check method parameter as a property name parameter. + * This annotation marks a presence check method parameter as a target property name parameter. *

      - * This parameter enables conditional filtering based on target property name at run-time. - * Parameter must be of type {@link String} and can be present only in {@link Condition} method. + * This parameter enables conditional filtering based on target property name at run-time. + * Parameter must be of type {@link String} and can be present only in {@link Condition} method. *

      * @author Nikola Ivačič * @since 1.6 diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 9d6c93f211..db13c0548b 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -406,9 +406,9 @@ public class CarMapperImpl implements CarMapper { ---- ==== -Additionally `@TargetPropertyName` of type `java.lang.String` can be used in custom condition check method: +Additionally `@TargetPropertyName` or `@SourcePropertyName` of type `java.lang.String` can be used in custom condition check method: -.Mapper using custom condition check method with `@TargetPropertyName` +.Mapper using custom condition check method with `@TargetPropertyName` and `@SourcePropertyName` ==== [source, java, linenums] [subs="verbatim,attributes"] @@ -416,11 +416,19 @@ Additionally `@TargetPropertyName` of type `java.lang.String` can be used in cus @Mapper public interface CarMapper { + @Mapping(target = "owner", source = "ownerName") CarDto carToCarDto(Car car, @MappingTarget CarDto carDto); @Condition - default boolean isNotEmpty(String value, @TargetPropertyName String name) { - if ( name.equals( "owner" ) { + default boolean isNotEmpty( + String value, + @TargetPropertyName String targetPropertyName, + @SourcePropertyName String sourcePropertyName + ) { + + if ( targetPropertyName.equals( "owner" ) + && sourcePropertyName.equals( "ownerName" ) ) { + return value != null && !value.isEmpty() && !value.equals( value.toLowerCase() ); @@ -431,7 +439,7 @@ public interface CarMapper { ---- ==== -The generated mapper with `@TargetPropertyName` will look like: +The generated mapper with `@TargetPropertyName` and `@SourcePropertyName` will look like: .Custom condition check in generated implementation ==== @@ -447,7 +455,7 @@ public class CarMapperImpl implements CarMapper { return carDto; } - if ( isNotEmpty( car.getOwner(), "owner" ) ) { + if ( isNotEmpty( car.getOwner(), "owner", "ownerName" ) ) { carDto.setOwner( car.getOwner() ); } else { carDto.setOwner( null ); @@ -470,7 +478,7 @@ If there is a custom `@Condition` method applicable for the property it will hav ==== Methods annotated with `@Condition` in addition to the value of the source property can also have the source parameter as an input. -`@TargetPropertyName` parameter can only be used in `@Condition` methods. +`@TargetPropertyName` and `@SourcePropertyName` parameters can only be used in `@Condition` methods. ==== <> is also valid for `@Condition` methods. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 9ac13184cd..2ed9bd9a09 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -31,6 +31,7 @@ import org.mapstruct.Named; import org.mapstruct.ObjectFactory; import org.mapstruct.Qualifier; +import org.mapstruct.SourcePropertyName; import org.mapstruct.SubclassMapping; import org.mapstruct.SubclassMappings; import org.mapstruct.TargetPropertyName; @@ -57,6 +58,7 @@ @GemDefinition(BeanMapping.class) @GemDefinition(EnumMapping.class) @GemDefinition(MapMapping.class) +@GemDefinition(SourcePropertyName.class) @GemDefinition(SubclassMapping.class) @GemDefinition(SubclassMappings.class) @GemDefinition(TargetType.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index ee347ef35e..be7203507b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1522,6 +1522,7 @@ private void applyPropertyNameBasedMapping(List sourceReference MappingReferences mappingRefs = extractMappingReferences( targetPropertyName, false ); PropertyMapping propertyMapping = new PropertyMappingBuilder().mappingContext( ctx ) .sourceMethod( method ) + .sourcePropertyName( targetPropertyName ) .target( targetPropertyName, targetPropertyReadAccessor, targetPropertyWriteAccessor ) .sourceReference( sourceRef ) .existingVariableNames( existingVariableNames ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 50f23ecbff..2f30957962 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -70,6 +70,7 @@ public class PropertyMapping extends ModelElement { private final String name; + private final String sourcePropertyName; private final String sourceBeanName; private final String targetWriteAccessorName; private final ReadAccessor targetReadAccessorProvider; @@ -286,6 +287,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get } return new PropertyMapping( + sourcePropertyName, targetPropertyName, rightHandSide.getSourceParameterName(), targetWriteAccessor.getSimpleName(), @@ -1099,16 +1101,17 @@ private PropertyMapping(String name, String targetWriteAccessorName, ReadAccessor targetReadAccessorProvider, Type targetType, Assignment propertyAssignment, Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { - this( name, null, targetWriteAccessorName, targetReadAccessorProvider, + this( name, null, null, targetWriteAccessorName, targetReadAccessorProvider, targetType, propertyAssignment, dependsOn, defaultValueAssignment, constructorMapping ); } - private PropertyMapping(String name, String sourceBeanName, String targetWriteAccessorName, - ReadAccessor targetReadAccessorProvider, Type targetType, - Assignment assignment, - Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { + private PropertyMapping(String sourcePropertyName, String name, String sourceBeanName, + String targetWriteAccessorName, ReadAccessor targetReadAccessorProvider, Type targetType, + Assignment assignment, + Set dependsOn, Assignment defaultValueAssignment, boolean constructorMapping) { + this.sourcePropertyName = sourcePropertyName; this.name = name; this.sourceBeanName = sourceBeanName; this.targetWriteAccessorName = targetWriteAccessorName; @@ -1128,6 +1131,10 @@ public String getName() { return name; } + public String getSourcePropertyName() { + return sourcePropertyName; + } + public String getSourceBeanName() { return sourceBeanName; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 600c8ac337..44ac0eb7f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -14,8 +14,9 @@ import org.mapstruct.ap.internal.gem.ContextGem; import org.mapstruct.ap.internal.gem.MappingTargetGem; -import org.mapstruct.ap.internal.gem.TargetTypeGem; +import org.mapstruct.ap.internal.gem.SourcePropertyNameGem; import org.mapstruct.ap.internal.gem.TargetPropertyNameGem; +import org.mapstruct.ap.internal.gem.TargetTypeGem; import org.mapstruct.ap.internal.util.Collections; /** @@ -32,6 +33,7 @@ public class Parameter extends ModelElement { private final boolean mappingTarget; private final boolean targetType; private final boolean mappingContext; + private final boolean sourcePropertyName; private final boolean targetPropertyName; private final boolean varArgs; @@ -44,12 +46,13 @@ private Parameter(Element element, Type type, boolean varArgs) { this.mappingTarget = MappingTargetGem.instanceOn( element ) != null; this.targetType = TargetTypeGem.instanceOn( element ) != null; this.mappingContext = ContextGem.instanceOn( element ) != null; + this.sourcePropertyName = SourcePropertyNameGem.instanceOn( element ) != null; this.targetPropertyName = TargetPropertyNameGem.instanceOn( element ) != null; this.varArgs = varArgs; } private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext, - boolean targetPropertyName, + boolean sourcePropertyName, boolean targetPropertyName, boolean varArgs) { this.element = null; this.name = name; @@ -58,12 +61,13 @@ private Parameter(String name, Type type, boolean mappingTarget, boolean targetT this.mappingTarget = mappingTarget; this.targetType = targetType; this.mappingContext = mappingContext; + this.sourcePropertyName = sourcePropertyName; this.targetPropertyName = targetPropertyName; this.varArgs = varArgs; } public Parameter(String name, Type type) { - this( name, type, false, false, false, false, false ); + this( name, type, false, false, false, false, false, false ); } public Element getElement() { @@ -99,6 +103,7 @@ private String format() { return ( mappingTarget ? "@MappingTarget " : "" ) + ( targetType ? "@TargetType " : "" ) + ( mappingContext ? "@Context " : "" ) + + ( sourcePropertyName ? "@SourcePropertyName " : "" ) + ( targetPropertyName ? "@TargetPropertyName " : "" ) + "%s " + name; } @@ -120,6 +125,10 @@ public boolean isTargetPropertyName() { return targetPropertyName; } + public boolean isSourcePropertyName() { + return sourcePropertyName; + } + public boolean isVarArgs() { return varArgs; } @@ -165,6 +174,7 @@ public static Parameter forForgedMappingTarget(Type parameterType) { false, false, false, + false, false ); } @@ -206,6 +216,10 @@ public static Parameter getTargetTypeParameter(List parameters) { return parameters.stream().filter( Parameter::isTargetType ).findAny().orElse( null ); } + public static Parameter getSourcePropertyNameParameter(List parameters) { + return parameters.stream().filter( Parameter::isSourcePropertyName ).findAny().orElse( null ); + } + public static Parameter getTargetPropertyNameParameter(List parameters) { return parameters.stream().filter( Parameter::isTargetPropertyName ).findAny().orElse( null ); } @@ -214,6 +228,7 @@ private static boolean isSourceParameter( Parameter parameter ) { return !parameter.isMappingTarget() && !parameter.isTargetType() && !parameter.isMappingContext() && + !parameter.isSourcePropertyName() && !parameter.isTargetPropertyName(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 18274e5492..0791ee626a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -22,16 +22,19 @@ public class ParameterBinding { private final boolean targetType; private final boolean mappingTarget; private final boolean mappingContext; + private final boolean sourcePropertyName; private final boolean targetPropertyName; private final SourceRHS sourceRHS; private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType, - boolean mappingContext, boolean targetPropertyName, SourceRHS sourceRHS) { + boolean mappingContext, boolean sourcePropertyName, boolean targetPropertyName, + SourceRHS sourceRHS) { this.type = parameterType; this.variableName = variableName; this.targetType = targetType; this.mappingTarget = mappingTarget; this.mappingContext = mappingContext; + this.sourcePropertyName = sourcePropertyName; this.targetPropertyName = targetPropertyName; this.sourceRHS = sourceRHS; } @@ -64,11 +67,18 @@ public boolean isMappingContext() { return mappingContext; } + /** + * @return {@code true}, if the parameter being bound is a {@code @SourcePropertyName} parameter. + */ + public boolean isSourcePropertyName() { + return sourcePropertyName; + } + /** * @return {@code true}, if the parameter being bound is a {@code @TargetPropertyName} parameter. */ public boolean isTargetPropertyName() { - return targetPropertyName; + return targetPropertyName; } /** @@ -108,6 +118,7 @@ public static ParameterBinding fromParameter(Parameter parameter) { parameter.isMappingTarget(), parameter.isTargetType(), parameter.isMappingContext(), + parameter.isSourcePropertyName(), parameter.isTargetPropertyName(), null ); @@ -129,6 +140,7 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame false, false, false, + false, null ); } @@ -138,14 +150,21 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame * @return a parameter binding representing a target type parameter */ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, true, false, false, null ); + return new ParameterBinding( classTypeOf, null, false, true, false, false, false, null ); } /** * @return a parameter binding representing a target property name parameter */ public static ParameterBinding forTargetPropertyNameBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, false, false, true, null ); + return new ParameterBinding( classTypeOf, null, false, false, false, false, true, null ); + } + + /** + * @return a parameter binding representing a source property name parameter + */ + public static ParameterBinding forSourcePropertyNameBinding(Type classTypeOf) { + return new ParameterBinding( classTypeOf, null, false, false, false, true, false, null ); } /** @@ -153,7 +172,7 @@ public static ParameterBinding forTargetPropertyNameBinding(Type classTypeOf) { * @return a parameter binding representing a mapping target parameter */ public static ParameterBinding forMappingTargetBinding(Type resultType) { - return new ParameterBinding( resultType, null, true, false, false, false, null ); + return new ParameterBinding( resultType, null, true, false, false, false, false, null ); } /** @@ -161,10 +180,10 @@ public static ParameterBinding forMappingTargetBinding(Type resultType) { * @return a parameter binding representing a mapping source type */ public static ParameterBinding forSourceTypeBinding(Type sourceType) { - return new ParameterBinding( sourceType, null, false, false, false, false, null ); + return new ParameterBinding( sourceType, null, false, false, false, false, false, null ); } public static ParameterBinding fromSourceRHS(SourceRHS sourceRHS) { - return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, false, sourceRHS ); + return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, false, false, sourceRHS ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 37b57d9025..42c318ca49 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -47,6 +47,7 @@ public class SourceMethod implements Method { private final List parameters; private final Parameter mappingTargetParameter; private final Parameter targetTypeParameter; + private final Parameter sourcePropertyNameParameter; private final Parameter targetPropertyNameParameter; private final boolean isObjectFactory; private final boolean isPresenceCheck; @@ -249,6 +250,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.mappingTargetParameter = Parameter.getMappingTargetParameter( parameters ); this.targetTypeParameter = Parameter.getTargetTypeParameter( parameters ); + this.sourcePropertyNameParameter = Parameter.getSourcePropertyNameParameter( parameters ); this.targetPropertyNameParameter = Parameter.getTargetPropertyNameParameter( parameters ); this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null; this.isObjectFactory = determineIfIsObjectFactory(); @@ -265,9 +267,10 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) private boolean determineIfIsObjectFactory() { boolean hasNoSourceParameters = getSourceParameters().isEmpty(); boolean hasNoMappingTargetParam = getMappingTargetParameter() == null; + boolean hasNoSourcePropertyNameParam = getSourcePropertyNameParameter() == null; boolean hasNoTargetPropertyNameParam = getTargetPropertyNameParameter() == null; return !isLifecycleCallbackMethod() && !returnType.isVoid() - && hasNoMappingTargetParam && hasNoTargetPropertyNameParam + && hasNoMappingTargetParam && hasNoSourcePropertyNameParam && hasNoTargetPropertyNameParam && ( hasObjectFactoryAnnotation || hasNoSourceParameters ); } @@ -382,6 +385,10 @@ public Parameter getTargetTypeParameter() { return targetTypeParameter; } + public Parameter getSourcePropertyNameParameter() { + return sourcePropertyNameParameter; + } + public Parameter getTargetPropertyNameParameter() { return targetPropertyNameParameter; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java index 9e82dae25d..800278a4c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java @@ -171,6 +171,7 @@ private static List getAvailableParameterBindingsFromMethod(Me if ( sourceRHS != null ) { availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); availableParams.add( ParameterBinding.fromSourceRHS( sourceRHS ) ); + addSourcePropertyNameBindings( availableParams, sourceRHS.getSourceType(), typeFactory ); } else { availableParams.addAll( ParameterBinding.fromParameters( method.getParameters() ) ); @@ -189,6 +190,7 @@ private static List getAvailableParameterBindingsFromSourceTyp List availableParams = new ArrayList<>(); availableParams.add( ParameterBinding.forSourceTypeBinding( sourceType ) ); + addSourcePropertyNameBindings( availableParams, sourceType, typeFactory ); for ( Parameter param : mappingMethod.getParameters() ) { if ( param.isMappingContext() ) { @@ -201,6 +203,22 @@ private static List getAvailableParameterBindingsFromSourceTyp return availableParams; } + private static void addSourcePropertyNameBindings(List availableParams, Type sourceType, + TypeFactory typeFactory) { + + boolean sourcePropertyNameAvailable = false; + for ( ParameterBinding pb : availableParams ) { + if ( pb.isSourcePropertyName() ) { + sourcePropertyNameAvailable = true; + break; + } + } + if ( !sourcePropertyNameAvailable ) { + availableParams.add( ParameterBinding.forSourcePropertyNameBinding( typeFactory.getType( String.class ) ) ); + } + + } + /** * Adds default parameter bindings for the mapping-target and target-type if not already available. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java index 24275f594b..50f834d43e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/TypeSelector.java @@ -215,6 +215,7 @@ private static List findCandidateBindingsForParameter(List parameters, Type returnType) { for ( Parameter param : parameters ) { + + if ( param.isSourcePropertyName() && !param.getType().isString() ) { + messager.printMessage( + param.getElement(), + SourcePropertyNameGem.instanceOn( param.getElement() ).mirror(), + Message.RETRIEVAL_SOURCE_PROPERTY_NAME_WRONG_TYPE + ); + return false; + } + if ( param.isTargetPropertyName() && !param.getType().isString() ) { messager.printMessage( param.getElement(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 4b43315390..d8f27791ee 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -177,6 +177,7 @@ public enum Message { RETRIEVAL_MAPPER_USES_CYCLE( "The mapper %s is referenced itself in Mapper#uses.", Diagnostic.Kind.WARNING ), RETRIEVAL_AFTER_METHOD_NOT_IMPLEMENTED( "@AfterMapping can only be applied to an implemented method." ), RETRIEVAL_BEFORE_METHOD_NOT_IMPLEMENTED( "@BeforeMapping can only be applied to an implemented method." ), + RETRIEVAL_SOURCE_PROPERTY_NAME_WRONG_TYPE( "@SourcePropertyName can only by applied to a String parameter." ), RETRIEVAL_TARGET_PROPERTY_NAME_WRONG_TYPE( "@TargetPropertyName can only by applied to a String parameter." ), INHERITINVERSECONFIGURATION_DUPLICATES( "Several matching inverse methods exist: %s(). Specify a name explicitly." ), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl index 4b45643dc8..63f983df46 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReference.ftl @@ -44,6 +44,8 @@ <#if ext.targetBeanName??>${ext.targetBeanName}<#else>${param.variableName}<#if ext.targetReadAccessorName??>.${ext.targetReadAccessorName}<#t> <#elseif param.mappingContext> ${param.variableName}<#t> + <#elseif param.sourcePropertyName> + "${ext.sourcePropertyName}"<#t> <#elseif param.targetPropertyName> "${ext.targetPropertyName}"<#t> <#elseif param.sourceRHS??> @@ -60,7 +62,7 @@ <#-- macro: assignment - purpose: note: takes its targetyType from the singleSourceParameterType + purpose: note: takes its targetType from the singleSourceParameterType --> <#macro _assignment assignmentToUse> <@includeModel object=assignmentToUse @@ -69,6 +71,7 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + sourcePropertyName=ext.sourcePropertyName targetPropertyName=ext.targetPropertyName targetType=singleSourceParameterType/> - \ No newline at end of file + diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl index 0452e1699a..68b05d84ed 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.ftl @@ -8,5 +8,6 @@ <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.MethodReferencePresenceCheck" --> <#if isNegate()>!<@includeModel object=methodReference presenceCheck=true + sourcePropertyName=ext.sourcePropertyName targetPropertyName=ext.targetPropertyName - targetType=ext.targetType/> \ No newline at end of file + targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl index e6aef4cecd..f45659cb5d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/PropertyMapping.ftl @@ -11,6 +11,7 @@ existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=targetReadAccessorName targetWriteAccessorName=targetWriteAccessorName + sourcePropertyName=sourcePropertyName targetPropertyName=name targetType=targetType defaultValueAssignment=defaultValueAssignment /> \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl index 4a9d356ce4..a5e5798d1c 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/TypeConversion.ftl @@ -14,6 +14,7 @@ ${openExpression}<@_assignment/>${closeExpression} existingInstanceMapping=ext.existingInstanceMapping targetReadAccessorName=ext.targetReadAccessorName targetWriteAccessorName=ext.targetWriteAccessorName + sourcePropertyName=ext.sourcePropertyName targetPropertyName=ext.targetPropertyName targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index bce28ebe19..278b441aa9 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -17,6 +17,7 @@ <#if sourcePresenceCheckerReference??> if ( <@includeModel object=sourcePresenceCheckerReference targetPropertyName=ext.targetPropertyName + sourcePropertyName=ext.sourcePropertyName targetType=ext.targetType/> ) { <#nested> } @@ -61,6 +62,7 @@ <#if sourcePresenceCheckerReference??> if ( <@includeModel object=sourcePresenceCheckerReference targetType=ext.targetType + sourcePropertyName=ext.sourcePropertyName targetPropertyName=ext.targetPropertyName /> ) { <#if needs_explicit_local_var> <@includeModel object=nullCheckLocalVarType/> ${nullCheckLocalVarName} = <@lib.handleAssignment/>; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Address.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Address.java index 162ed118bb..339af75944 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Address.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Address.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname; /** * @author Nikola Ivačič diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/AddressDto.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/AddressDto.java index f4cbc71915..c6a63065d4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/AddressDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/AddressDto.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname; /** * @author Nikola Ivačič diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/DomainModel.java similarity index 80% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/DomainModel.java index 4d2c716a96..8e5fa8695d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/DomainModel.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/DomainModel.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname; /** * Target Property Name test entities diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Employee.java similarity index 96% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Employee.java index 59ee3426e1..497717a592 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/Employee.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/Employee.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname; import java.util.List; diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/EmployeeDto.java similarity index 75% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/EmployeeDto.java index 5d81a9334b..f49f25e4a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/EmployeeDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/EmployeeDto.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname; import java.util.List; @@ -15,14 +15,14 @@ public class EmployeeDto implements DomainModel { private String firstName; private String lastName; private String title; - private String country; + private String originCountry; private boolean active; private int age; private EmployeeDto boss; private AddressDto primaryAddress; - private List addresses; + private List originAddresses; public String getFirstName() { return firstName; @@ -48,12 +48,12 @@ public void setTitle(String title) { this.title = title; } - public String getCountry() { - return country; + public String getOriginCountry() { + return originCountry; } - public void setCountry(String country) { - this.country = country; + public void setOriginCountry(String originCountry) { + this.originCountry = originCountry; } public boolean isActive() { @@ -88,11 +88,11 @@ public void setPrimaryAddress(AddressDto primaryAddress) { this.primaryAddress = primaryAddress; } - public List getAddresses() { - return addresses; + public List getOriginAddresses() { + return originAddresses; } - public void setAddresses(List addresses) { - this.addresses = addresses; + public void setOriginAddresses(List originAddresses) { + this.originAddresses = originAddresses; } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodForCollectionMapperWithSourcePropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodForCollectionMapperWithSourcePropertyName.java new file mode 100644 index 0000000000..944fe5d146 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodForCollectionMapperWithSourcePropertyName.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import java.util.Collection; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper +public interface ConditionalMethodForCollectionMapperWithSourcePropertyName { + + ConditionalMethodForCollectionMapperWithSourcePropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodForCollectionMapperWithSourcePropertyName.class ); + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotEmpty(Collection collection, @SourcePropertyName String propName) { + if ( "originAddresses".equalsIgnoreCase( propName ) ) { + return false; + } + return collection != null && !collection.isEmpty(); + } + + @Condition + default boolean isNotBlank(String value, @SourcePropertyName String propName) { + if ( propName.equalsIgnoreCase( "originCountry" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllExceptTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllExceptTarget.java new file mode 100644 index 0000000000..ea6a77d94e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllExceptTarget.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import java.util.LinkedHashSet; +import java.util.Set; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper +public interface ConditionalMethodInMapperWithAllExceptTarget { + + ConditionalMethodInMapperWithAllExceptTarget INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithAllExceptTarget.class ); + + class PresenceUtils { + Set visited = new LinkedHashSet<>(); + Set visitedSources = new LinkedHashSet<>(); + } + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee, @Context PresenceUtils utils); + + @Condition + default boolean isNotBlank(String value, + DomainModel source, + @SourcePropertyName String propName, + @Context PresenceUtils utils) { + utils.visited.add( propName ); + utils.visitedSources.add( source.getClass().getSimpleName() ); + if ( propName.equalsIgnoreCase( "firstName" ) ) { + return true; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllOptions.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllOptions.java new file mode 100644 index 0000000000..ee3be57648 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithAllOptions.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import java.util.LinkedHashSet; +import java.util.Set; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper +public interface ConditionalMethodInMapperWithAllOptions { + + ConditionalMethodInMapperWithAllOptions INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithAllOptions.class ); + + class PresenceUtils { + Set visitedSourceNames = new LinkedHashSet<>(); + Set visitedTargetNames = new LinkedHashSet<>(); + Set visitedSources = new LinkedHashSet<>(); + Set visitedTargets = new LinkedHashSet<>(); + } + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + void map(EmployeeDto employeeDto, + @MappingTarget Employee employee, + @Context PresenceUtils utils); + + @Condition + default boolean isNotBlank(String value, + DomainModel source, + @MappingTarget DomainModel target, + @SourcePropertyName String sourcePropName, + @TargetPropertyName String targetPropName, + @Context PresenceUtils utils) { + utils.visitedSourceNames.add( sourcePropName ); + utils.visitedTargetNames.add( targetPropName ); + utils.visitedSources.add( source.getClass().getSimpleName() ); + utils.visitedTargets.add( target.getClass().getSimpleName() ); + if ( sourcePropName.equalsIgnoreCase( "lastName" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithSourcePropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithSourcePropertyName.java new file mode 100644 index 0000000000..41ff6c5264 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInMapperWithSourcePropertyName.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper +public interface ConditionalMethodInMapperWithSourcePropertyName { + + ConditionalMethodInMapperWithSourcePropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodInMapperWithSourcePropertyName.class ); + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value, @SourcePropertyName String propName) { + if ( propName.equalsIgnoreCase( "originCountry" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInUsesMapperWithSourcePropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInUsesMapperWithSourcePropertyName.java new file mode 100644 index 0000000000..8ba222512f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodInUsesMapperWithSourcePropertyName.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper(uses = ConditionalMethodInUsesMapperWithSourcePropertyName.PresenceUtils.class) +public interface ConditionalMethodInUsesMapperWithSourcePropertyName { + + ConditionalMethodInUsesMapperWithSourcePropertyName INSTANCE + = Mappers.getMapper( ConditionalMethodInUsesMapperWithSourcePropertyName.class ); + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee); + + class PresenceUtils { + + @Condition + public boolean isNotBlank(String value, @SourcePropertyName String propName) { + if ( propName.equalsIgnoreCase( "originCountry" ) ) { + return false; + } + return value != null && !value.trim().isEmpty(); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodWithSourcePropertyNameInContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodWithSourcePropertyNameInContextMapper.java new file mode 100644 index 0000000000..64b6fcbbab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ConditionalMethodWithSourcePropertyNameInContextMapper.java @@ -0,0 +1,108 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import java.util.Deque; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.TargetType; +import org.mapstruct.ap.test.conditional.propertyname.Address; +import org.mapstruct.ap.test.conditional.propertyname.AddressDto; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.factory.Mappers; + +/** + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@Mapper +public interface ConditionalMethodWithSourcePropertyNameInContextMapper { + + ConditionalMethodWithSourcePropertyNameInContextMapper INSTANCE + = Mappers.getMapper( ConditionalMethodWithSourcePropertyNameInContextMapper.class ); + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee, @Context PresenceUtils utils); + + Address map(AddressDto addressDto, @Context PresenceUtils utils); + + class PresenceUtils { + Set visited = new LinkedHashSet<>(); + + @Condition + public boolean isNotBlank(String value, @SourcePropertyName String propName) { + visited.add( propName ); + return value != null && !value.trim().isEmpty(); + } + } + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee, @Context PresenceUtilsAllProps utils); + + Address map(AddressDto addressDto, @Context PresenceUtilsAllProps utils); + + class PresenceUtilsAllProps { + Set visited = new LinkedHashSet<>(); + + @Condition + public boolean collect(@SourcePropertyName String propName) { + visited.add( propName ); + return true; + } + } + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee, @Context PresenceUtilsAllPropsWithSource utils); + + Address map(AddressDto addressDto, @Context PresenceUtilsAllPropsWithSource utils); + + @BeforeMapping + default void before(DomainModel source, @Context PresenceUtilsAllPropsWithSource utils) { + String lastProp = utils.visitedSegments.peekLast(); + if ( lastProp != null && source != null ) { + utils.path.offerLast( lastProp ); + } + } + + @AfterMapping + default void after(@TargetType Class targetClass, @Context PresenceUtilsAllPropsWithSource utils) { + // intermediate method for collection mapping must not change the path + if (targetClass != List.class) { + utils.path.pollLast(); + } + } + + class PresenceUtilsAllPropsWithSource { + Deque visitedSegments = new LinkedList<>(); + Deque visited = new LinkedList<>(); + Deque path = new LinkedList<>(); + + @Condition + public boolean collect(@SourcePropertyName String propName) { + visitedSegments.offerLast( propName ); + path.offerLast( propName ); + visited.offerLast( String.join( ".", path ) ); + path.pollLast(); + return true; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ErroneousNonStringSourcePropertyNameParameter.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ErroneousNonStringSourcePropertyNameParameter.java new file mode 100644 index 0000000000..5ed118676d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/ErroneousNonStringSourcePropertyNameParameter.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourcePropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; + +@Mapper +public interface ErroneousNonStringSourcePropertyNameParameter { + + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") + Employee map(EmployeeDto employee); + + @Condition + default boolean isNotBlank(String value, @SourcePropertyName int propName) { + return value != null && !value.trim().isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/SourcePropertyNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/SourcePropertyNameTest.java new file mode 100644 index 0000000000..2471ed647d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/sourcepropertyname/SourcePropertyNameTest.java @@ -0,0 +1,312 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.propertyname.sourcepropertyname; + +import java.util.Collections; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.conditional.propertyname.Address; +import org.mapstruct.ap.test.conditional.propertyname.AddressDto; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + * @author Nikola Ivačič + * @author Mohammad Al Zouabi + * @author Oliver Erhart + */ +@IssueKey("3323") +@WithClasses({ + Address.class, + AddressDto.class, + Employee.class, + EmployeeDto.class, + DomainModel.class +}) +public class SourcePropertyNameTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithSourcePropertyName.class + }) + public void conditionalMethodInMapperWithSourcePropertyName() { + ConditionalMethodInMapperWithSourcePropertyName mapper + = ConditionalMethodInMapperWithSourcePropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isEqualTo( "Testirovich" ); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isNull(); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodForCollectionMapperWithSourcePropertyName.class + }) + public void conditionalMethodForCollectionMapperWithSourcePropertyName() { + ConditionalMethodForCollectionMapperWithSourcePropertyName mapper + = ConditionalMethodForCollectionMapperWithSourcePropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isEqualTo( "Testirovich" ); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isNull(); + assertThat( employee.getAddresses() ).isNull(); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInUsesMapperWithSourcePropertyName.class + }) + public void conditionalMethodInUsesMapperWithSourcePropertyName() { + ConditionalMethodInUsesMapperWithSourcePropertyName mapper + = ConditionalMethodInUsesMapperWithSourcePropertyName.INSTANCE; + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto ); + assertThat( employee.getLastName() ).isEqualTo( "Testirovich" ); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isNull(); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithAllOptions.class + }) + public void conditionalMethodInMapperWithAllOptions() { + ConditionalMethodInMapperWithAllOptions mapper + = ConditionalMethodInMapperWithAllOptions.INSTANCE; + + ConditionalMethodInMapperWithAllOptions.PresenceUtils utils = + new ConditionalMethodInMapperWithAllOptions.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = new Employee(); + mapper.map( employeeDto, employee, utils ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getFirstName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visitedSourceNames ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "originCountry" ); + assertThat( utils.visitedTargetNames ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "country" ); + assertThat( utils.visitedSources ).containsExactly( "EmployeeDto" ); + assertThat( utils.visitedTargets ).containsExactly( "Employee" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodInMapperWithAllExceptTarget.class + }) + public void conditionalMethodInMapperWithAllExceptTarget() { + ConditionalMethodInMapperWithAllExceptTarget mapper + = ConditionalMethodInMapperWithAllExceptTarget.INSTANCE; + + ConditionalMethodInMapperWithAllExceptTarget.PresenceUtils utils = + new ConditionalMethodInMapperWithAllExceptTarget.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setFirstName( " " ); + employeeDto.setLastName( "Testirovich" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto, utils ); + assertThat( employee.getLastName() ).isEqualTo( "Testirovich" ); + assertThat( employee.getFirstName() ).isEqualTo( " " ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visited ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "originCountry", "street" ); + assertThat( utils.visitedSources ).containsExactlyInAnyOrder( "EmployeeDto", "AddressDto" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodWithSourcePropertyNameInContextMapper.class + }) + public void conditionalMethodWithSourcePropertyNameInUsesContextMapper() { + ConditionalMethodWithSourcePropertyNameInContextMapper mapper + = ConditionalMethodWithSourcePropertyNameInContextMapper.INSTANCE; + + ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtils utils = + new ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtils(); + + EmployeeDto employeeDto = new EmployeeDto(); + employeeDto.setLastName( " " ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + Employee employee = mapper.map( employeeDto, utils ); + assertThat( employee.getLastName() ).isNull(); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( utils.visited ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "originCountry", "street" ); + + ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtilsAllProps allPropsUtils = + new ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtilsAllProps(); + + employeeDto = new EmployeeDto(); + employeeDto.setLastName( "Tester" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + employee = mapper.map( employeeDto, allPropsUtils ); + assertThat( employee.getLastName() ).isEqualTo( "Tester" ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 6" ); + assertThat( allPropsUtils.visited ) + .containsExactlyInAnyOrder( + "firstName", + "lastName", + "title", + "originCountry", + "active", + "age", + "boss", + "primaryAddress", + "originAddresses", + "street" + ); + + ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtilsAllPropsWithSource allPropsUtilsWithSource = + new ConditionalMethodWithSourcePropertyNameInContextMapper.PresenceUtilsAllPropsWithSource(); + + EmployeeDto bossEmployeeDto = new EmployeeDto(); + bossEmployeeDto.setLastName( "Boss Tester" ); + bossEmployeeDto.setOriginCountry( "US" ); + bossEmployeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( + "Testing St. 10" ) ) ); + + employeeDto = new EmployeeDto(); + employeeDto.setLastName( "Tester" ); + employeeDto.setOriginCountry( "US" ); + employeeDto.setBoss( bossEmployeeDto ); + employeeDto.setOriginAddresses( + Collections.singletonList( new AddressDto( "Testing St. 6" ) ) + ); + + employee = mapper.map( employeeDto, allPropsUtilsWithSource ); + assertThat( employee.getLastName() ).isEqualTo( "Tester" ); + assertThat( employee.getCountry() ).isEqualTo( "US" ); + assertThat( employee.getAddresses() ).isNotEmpty(); + assertThat( employee.getAddresses().get( 0 ).getStreet() ).isEqualTo( "Testing St. 6" ); + assertThat( employee.getBoss() ).isNotNull(); + assertThat( employee.getBoss().getCountry() ).isEqualTo( "US" ); + assertThat( employee.getBoss().getLastName() ).isEqualTo( "Boss Tester" ); + assertThat( employee.getBoss().getAddresses() ) + .extracting( Address::getStreet ) + .containsExactly( "Testing St. 10" ); + assertThat( allPropsUtilsWithSource.visited ) + .containsExactly( + "originCountry", + "originAddresses", + "originAddresses.street", + "firstName", + "lastName", + "title", + "active", + "age", + "boss", + "boss.originCountry", + "boss.originAddresses", + "boss.originAddresses.street", + "boss.firstName", + "boss.lastName", + "boss.title", + "boss.active", + "boss.age", + "boss.boss", + "boss.primaryAddress", + "primaryAddress" + ); + } + + @ProcessorTest + @WithClasses({ + ErroneousNonStringSourcePropertyNameParameter.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousNonStringSourcePropertyNameParameter.class, + line = 23, + message = "@SourcePropertyName can only by applied to a String parameter." + ) + } + ) + public void nonStringSourcePropertyNameParameter() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java similarity index 76% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java index 71baa0942b..a51a318eb6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodForCollectionMapperWithTargetPropertyName.java @@ -3,15 +3,18 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; + +import java.util.Collection; import org.mapstruct.Condition; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; -import java.util.Collection; - /** * @author Nikola Ivačič */ @@ -21,6 +24,8 @@ public interface ConditionalMethodForCollectionMapperWithTargetPropertyName { ConditionalMethodForCollectionMapperWithTargetPropertyName INSTANCE = Mappers.getMapper( ConditionalMethodForCollectionMapperWithTargetPropertyName.class ); + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee); @Condition diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java similarity index 76% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java index 430303d06d..1d0dd3fa51 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllExceptTarget.java @@ -3,17 +3,21 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; + +import java.util.LinkedHashSet; +import java.util.Set; import org.mapstruct.Condition; import org.mapstruct.Context; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; -import java.util.LinkedHashSet; -import java.util.Set; - /** * @author Filip Hrisafov * @author Nikola Ivačič @@ -29,6 +33,8 @@ class PresenceUtils { Set visitedSources = new LinkedHashSet<>(); } + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee, @Context PresenceUtils utils); @Condition diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java similarity index 61% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java index a18ba0db73..d3ccb9ba2e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithAllOptions.java @@ -3,18 +3,23 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; + +import java.util.LinkedHashSet; +import java.util.Set; import org.mapstruct.Condition; import org.mapstruct.Context; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.MappingTarget; +import org.mapstruct.SourcePropertyName; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; -import java.util.LinkedHashSet; -import java.util.Set; - /** * @author Filip Hrisafov * @author Nikola Ivačič @@ -26,11 +31,14 @@ public interface ConditionalMethodInMapperWithAllOptions { = Mappers.getMapper( ConditionalMethodInMapperWithAllOptions.class ); class PresenceUtils { - Set visited = new LinkedHashSet<>(); + Set visitedSourceNames = new LinkedHashSet<>(); + Set visitedTargetNames = new LinkedHashSet<>(); Set visitedSources = new LinkedHashSet<>(); Set visitedTargets = new LinkedHashSet<>(); } + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") void map(EmployeeDto employeeDto, @MappingTarget Employee employee, @Context PresenceUtils utils); @@ -39,12 +47,14 @@ void map(EmployeeDto employeeDto, default boolean isNotBlank(String value, DomainModel source, @MappingTarget DomainModel target, - @TargetPropertyName String propName, + @SourcePropertyName String sourcePropName, + @TargetPropertyName String targetPropName, @Context PresenceUtils utils) { - utils.visited.add( propName ); + utils.visitedSourceNames.add( sourcePropName ); + utils.visitedTargetNames.add( targetPropName ); utils.visitedSources.add( source.getClass().getSimpleName() ); utils.visitedTargets.add( target.getClass().getSimpleName() ); - if ( propName.equalsIgnoreCase( "lastName" ) ) { + if ( targetPropName.equalsIgnoreCase( "lastName" ) ) { return false; } return value != null && !value.trim().isEmpty(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java similarity index 70% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java index 6d27bc9036..d5dc378f32 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInMapperWithTargetPropertyName.java @@ -3,11 +3,14 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; import org.mapstruct.Condition; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; /** @@ -20,6 +23,8 @@ public interface ConditionalMethodInMapperWithTargetPropertyName { ConditionalMethodInMapperWithTargetPropertyName INSTANCE = Mappers.getMapper( ConditionalMethodInMapperWithTargetPropertyName.class ); + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee); @Condition diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java index 7c526884e9..381b99d4f4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodInUsesMapperWithTargetPropertyName.java @@ -3,11 +3,14 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; import org.mapstruct.Condition; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; /** @@ -20,6 +23,8 @@ public interface ConditionalMethodInUsesMapperWithTargetPropertyName { ConditionalMethodInUsesMapperWithTargetPropertyName INSTANCE = Mappers.getMapper( ConditionalMethodInUsesMapperWithTargetPropertyName.class ); + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee); class PresenceUtils { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java similarity index 70% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java index a7cde220c9..44bc262435 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ConditionalMethodWithTargetPropertyNameInContextMapper.java @@ -3,21 +3,29 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; + +import java.util.Deque; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; import org.mapstruct.AfterMapping; import org.mapstruct.BeforeMapping; import org.mapstruct.Condition; import org.mapstruct.Context; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.TargetType; +import org.mapstruct.ap.test.conditional.propertyname.Address; +import org.mapstruct.ap.test.conditional.propertyname.AddressDto; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.factory.Mappers; -import java.util.Deque; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Set; - /** * @author Nikola Ivačič */ @@ -27,6 +35,8 @@ public interface ConditionalMethodWithTargetPropertyNameInContextMapper { ConditionalMethodWithTargetPropertyNameInContextMapper INSTANCE = Mappers.getMapper( ConditionalMethodWithTargetPropertyNameInContextMapper.class ); + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee, @Context PresenceUtils utils); Address map(AddressDto addressDto, @Context PresenceUtils utils); @@ -41,6 +51,8 @@ public boolean isNotBlank(String value, @TargetPropertyName String propName) { } } + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee, @Context PresenceUtilsAllProps utils); Address map(AddressDto addressDto, @Context PresenceUtilsAllProps utils); @@ -55,6 +67,8 @@ public boolean collect(@TargetPropertyName String propName) { } } + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee, @Context PresenceUtilsAllPropsWithSource utils); Address map(AddressDto addressDto, @Context PresenceUtilsAllPropsWithSource utils); @@ -68,8 +82,11 @@ default void before(DomainModel source, @Context PresenceUtilsAllPropsWithSource } @AfterMapping - default void after(@Context PresenceUtilsAllPropsWithSource utils) { - utils.path.pollLast(); + default void after(@TargetType Class targetClass, @Context PresenceUtilsAllPropsWithSource utils) { + // intermediate method for collection mapping must not change the path + if (targetClass != List.class) { + utils.path.pollLast(); + } } class PresenceUtilsAllPropsWithSource { diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java similarity index 59% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java index ec545a058b..d56277abf4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/ErroneousNonStringTargetPropertyNameParameter.java @@ -3,15 +3,20 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; import org.mapstruct.Condition; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; import org.mapstruct.TargetPropertyName; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; @Mapper public interface ErroneousNonStringTargetPropertyNameParameter { + @Mapping(target = "country", source = "originCountry") + @Mapping(target = "addresses", source = "originAddresses") Employee map(EmployeeDto employee); @Condition diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/TargetPropertyNameTest.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java rename to processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/TargetPropertyNameTest.java index 91e4b77de2..bb90c0b069 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/targetpropertyname/TargetPropertyNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/propertyname/targetpropertyname/TargetPropertyNameTest.java @@ -3,9 +3,16 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.conditional.targetpropertyname; +package org.mapstruct.ap.test.conditional.propertyname.targetpropertyname; + +import java.util.Collections; import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.conditional.propertyname.Address; +import org.mapstruct.ap.test.conditional.propertyname.AddressDto; +import org.mapstruct.ap.test.conditional.propertyname.DomainModel; +import org.mapstruct.ap.test.conditional.propertyname.Employee; +import org.mapstruct.ap.test.conditional.propertyname.EmployeeDto; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -14,8 +21,6 @@ import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.GeneratedSource; -import java.util.Collections; - import static org.assertj.core.api.Assertions.assertThat; /** @@ -46,8 +51,8 @@ public void conditionalMethodInMapperWithTargetPropertyName() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setFirstName( " " ); employeeDto.setLastName( "Testirovich" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -71,8 +76,8 @@ public void conditionalMethodForCollectionMapperWithTargetPropertyName() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setFirstName( " " ); employeeDto.setLastName( "Testirovich" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -94,8 +99,8 @@ public void conditionalMethodInUsesMapperWithTargetPropertyName() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setFirstName( " " ); employeeDto.setLastName( "Testirovich" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -122,8 +127,8 @@ public void conditionalMethodInMapperWithAllOptions() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setFirstName( " " ); employeeDto.setLastName( "Testirovich" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -135,7 +140,9 @@ public void conditionalMethodInMapperWithAllOptions() { assertThat( employee.getAddresses() ) .extracting( Address::getStreet ) .containsExactly( "Testing St. 6" ); - assertThat( utils.visited ) + assertThat( utils.visitedSourceNames ) + .containsExactlyInAnyOrder( "firstName", "lastName", "title", "originCountry" ); + assertThat( utils.visitedTargetNames ) .containsExactlyInAnyOrder( "firstName", "lastName", "title", "country" ); assertThat( utils.visitedSources ).containsExactly( "EmployeeDto" ); assertThat( utils.visitedTargets ).containsExactly( "Employee" ); @@ -155,8 +162,8 @@ public void conditionalMethodInMapperWithAllExceptTarget() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setFirstName( " " ); employeeDto.setLastName( "Testirovich" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -185,8 +192,8 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { EmployeeDto employeeDto = new EmployeeDto(); employeeDto.setLastName( " " ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -204,8 +211,8 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { employeeDto = new EmployeeDto(); employeeDto.setLastName( "Tester" ); - employeeDto.setCountry( "US" ); - employeeDto.setAddresses( + employeeDto.setOriginCountry( "US" ); + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -234,15 +241,15 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { EmployeeDto bossEmployeeDto = new EmployeeDto(); bossEmployeeDto.setLastName( "Boss Tester" ); - bossEmployeeDto.setCountry( "US" ); - bossEmployeeDto.setAddresses( Collections.singletonList( new AddressDto( + bossEmployeeDto.setOriginCountry( "US" ); + bossEmployeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 10" ) ) ); employeeDto = new EmployeeDto(); employeeDto.setLastName( "Tester" ); - employeeDto.setCountry( "US" ); + employeeDto.setOriginCountry( "US" ); employeeDto.setBoss( bossEmployeeDto ); - employeeDto.setAddresses( + employeeDto.setOriginAddresses( Collections.singletonList( new AddressDto( "Testing St. 6" ) ) ); @@ -259,26 +266,26 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { .containsExactly( "Testing St. 10" ); assertThat( allPropsUtilsWithSource.visited ) .containsExactly( + "country", + "addresses", + "addresses.street", "firstName", "lastName", "title", - "country", "active", "age", "boss", + "boss.country", + "boss.addresses", + "boss.addresses.street", "boss.firstName", "boss.lastName", "boss.title", - "boss.country", "boss.active", "boss.age", "boss.boss", "boss.primaryAddress", - "boss.addresses", - "boss.addresses.street", - "primaryAddress", - "addresses", - "addresses.street" + "primaryAddress" ); } @@ -293,7 +300,7 @@ public void conditionalMethodWithTargetPropertyNameInUsesContextMapper() { @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousNonStringTargetPropertyNameParameter.class, - line = 18, + line = 23, message = "@TargetPropertyName can only by applied to a String parameter." ) } From ca1fd0d85dc76f914167c94f1e034e8dfd55bb61 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 Feb 2024 12:51:19 +0100 Subject: [PATCH 0811/1006] #3331 Do not handle defined mappings if the result type is abstract due to runtime exception subclass exhaustive strategy (#3487) --- .../ap/internal/model/BeanMappingMethod.java | 43 +++++++++++-- .../ap/test/bugs/_3331/Issue3331Mapper.java | 27 ++++++++ .../ap/test/bugs/_3331/Issue3331Test.java | 48 ++++++++++++++ .../mapstruct/ap/test/bugs/_3331/Vehicle.java | 64 +++++++++++++++++++ .../ap/test/bugs/_3331/VehicleDto.java | 51 +++++++++++++++ 5 files changed, 229 insertions(+), 4 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Vehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/VehicleDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index be7203507b..8979901f80 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -284,10 +284,15 @@ else if ( !method.isUpdateMethod() ) { initializeMappingReferencesIfNeeded( resultTypeToMap ); - // map properties with mapping - boolean mappingErrorOccurred = handleDefinedMappings( resultTypeToMap ); - if ( mappingErrorOccurred ) { - return null; + boolean shouldHandledDefinedMappings = shouldHandledDefinedMappings( resultTypeToMap ); + + + if ( shouldHandledDefinedMappings ) { + // map properties with mapping + boolean mappingErrorOccurred = handleDefinedMappings( resultTypeToMap ); + if ( mappingErrorOccurred ) { + return null; + } } boolean applyImplicitMappings = !mappingReferences.isRestrictToDefinedMappings(); @@ -1045,6 +1050,36 @@ private List getValueAsList(AnnotationValue av) { return (List) av.getValue(); } + /** + * Determine whether defined mappings should be handled on the result type. + * They should be, if any of the following is true: + *
        + *
      • The {@code resultTypeToMap} is not abstract
      • + *
      • There is a factory method
      • + *
      • The method is an update method
      • + *
      + * Otherwise, it means that we have reached this because subclass mappings are being used + * and the chosen strategy is runtime exception. + * + * @param resultTypeToMap the type in which the defined target properties are defined + * @return {@code true} if defined mappings should be handled for the result type, {@code false} otherwise + */ + private boolean shouldHandledDefinedMappings(Type resultTypeToMap) { + if ( !resultTypeToMap.isAbstract() ) { + return true; + } + + if ( hasFactoryMethod ) { + return true; + } + + if ( method.isUpdateMethod() ) { + return true; + } + + return false; + } + /** * Iterates over all defined mapping methods ({@code @Mapping(s)}), either directly given or inherited from the * inverse mapping method. diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Mapper.java new file mode 100644 index 0000000000..3011479c65 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Mapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3331; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) +public interface Issue3331Mapper { + + Issue3331Mapper INSTANCE = Mappers.getMapper( Issue3331Mapper.class ); + + @SubclassMapping(source = Vehicle.Car.class, target = VehicleDto.Car.class) + @SubclassMapping(source = Vehicle.Motorbike.class, target = VehicleDto.Motorbike.class) + @Mapping(target = "name", constant = "noname") + VehicleDto map(Vehicle vehicle); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Test.java new file mode 100644 index 0000000000..3871868226 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Issue3331Test.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3331; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3331") +@WithClasses({ + Issue3331Mapper.class, + Vehicle.class, + VehicleDto.class, +}) +class Issue3331Test { + + @ProcessorTest + void shouldCorrectCompileAndThrowExceptionOnRuntime() { + VehicleDto target = Issue3331Mapper.INSTANCE.map( new Vehicle.Car( "Test car", 4 ) ); + + assertThat( target.getName() ).isEqualTo( "noname" ); + assertThat( target ) + .isInstanceOfSatisfying( VehicleDto.Car.class, car -> { + assertThat( car.getNumOfDoors() ).isEqualTo( 4 ); + } ); + + target = Issue3331Mapper.INSTANCE.map( new Vehicle.Motorbike( "Test bike", true ) ); + + assertThat( target.getName() ).isEqualTo( "noname" ); + assertThat( target ) + .isInstanceOfSatisfying( VehicleDto.Motorbike.class, bike -> { + assertThat( bike.isAllowedForMinor() ).isTrue(); + } ); + + assertThatThrownBy( () -> Issue3331Mapper.INSTANCE.map( new Vehicle.Truck( "Test truck", 3 ) ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Not all subclasses are supported for this mapping. Missing for " + Vehicle.Truck.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Vehicle.java new file mode 100644 index 0000000000..3b68a3acc4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/Vehicle.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3331; + +/** + * @author Filip Hrisafov + */ +public abstract class Vehicle { + + private final String name; + + protected Vehicle(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static class Car extends Vehicle { + + private final int numOfDoors; + + public Car(String name, int numOfDoors) { + super( name ); + this.numOfDoors = numOfDoors; + } + + public int getNumOfDoors() { + return numOfDoors; + } + } + + public static class Motorbike extends Vehicle { + + private final boolean allowedForMinor; + + public Motorbike(String name, boolean allowedForMinor) { + super( name ); + this.allowedForMinor = allowedForMinor; + } + + public boolean isAllowedForMinor() { + return allowedForMinor; + } + } + + public static class Truck extends Vehicle { + + private final int numOfAxis; + + public Truck(String name, int numOfAxis) { + super( name ); + this.numOfAxis = numOfAxis; + } + + public int getNumOfAxis() { + return numOfAxis; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/VehicleDto.java new file mode 100644 index 0000000000..8c2ef13dd2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3331/VehicleDto.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3331; + +/** + * @author Filip Hrisafov + */ +public abstract class VehicleDto { + + private final String name; + + protected VehicleDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static class Car extends VehicleDto { + + private final int numOfDoors; + + public Car(String name, int numOfDoors) { + super( name ); + this.numOfDoors = numOfDoors; + } + + public int getNumOfDoors() { + return numOfDoors; + } + } + + public static class Motorbike extends VehicleDto { + + private final boolean allowedForMinor; + + public Motorbike(String name, boolean allowedForMinor) { + super( name ); + this.allowedForMinor = allowedForMinor; + } + + public boolean isAllowedForMinor() { + return allowedForMinor; + } + } + +} From bb1cd6348502c592dfb77aa5ac86cfe62cc0ba32 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 11 Feb 2024 13:29:34 +0100 Subject: [PATCH 0812/1006] #2788 Improve unmapped source properties message for forged methods --- .../ap/internal/model/BeanMappingMethod.java | 115 +++---- .../mapstruct/ap/internal/util/Message.java | 2 + .../nestedbeans/DottedErrorMessageTest.java | 285 ++++++++++++++---- ...SourceCollectionElementPropertyMapper.java | 17 ++ .../UnmappableSourceDeepListMapper.java | 17 ++ .../UnmappableSourceDeepMapKeyMapper.java | 17 ++ .../UnmappableSourceDeepMapValueMapper.java | 17 ++ .../UnmappableSourceDeepNestingMapper.java | 17 ++ ...r.java => UnmappableSourceEnumMapper.java} | 2 +- .../UnmappableSourceValuePropertyMapper.java | 17 ++ ...argetCollectionElementPropertyMapper.java} | 4 +- ...va => UnmappableTargetDeepListMapper.java} | 4 +- ... => UnmappableTargetDeepMapKeyMapper.java} | 4 +- ...> UnmappableTargetDeepMapValueMapper.java} | 4 +- ...=> UnmappableTargetDeepNestingMapper.java} | 4 +- ... UnmappableTargetValuePropertyMapper.java} | 4 +- ...eWarnCollectionElementPropertyMapper.java} | 7 +- ...> UnmappableSourceWarnDeepListMapper.java} | 7 +- ...UnmappableSourceWarnDeepMapKeyMapper.java} | 7 +- ...mappableSourceWarnDeepMapValueMapper.java} | 7 +- ...nmappableSourceWarnDeepNestingMapper.java} | 7 +- ...appableSourceWarnValuePropertyMapper.java} | 7 +- ...etWarnCollectionElementPropertyMapper.java | 17 ++ .../UnmappableTargetWarnDeepListMapper.java | 17 ++ .../UnmappableTargetWarnDeepMapKeyMapper.java | 17 ++ ...nmappableTargetWarnDeepMapValueMapper.java | 17 ++ ...UnmappableTargetWarnDeepNestingMapper.java | 17 ++ ...mappableTargetWarnValuePropertyMapper.java | 17 ++ 28 files changed, 546 insertions(+), 128 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceDeepNestingMapper.java rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableEnumMapper.java => UnmappableSourceEnumMapper.java} (96%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/UnmappableSourceValuePropertyMapper.java rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableCollectionElementPropertyMapper.java => UnmappableTargetCollectionElementPropertyMapper.java} (68%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableDeepListMapper.java => UnmappableTargetDeepListMapper.java} (71%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableDeepMapKeyMapper.java => UnmappableTargetDeepMapKeyMapper.java} (71%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableDeepMapValueMapper.java => UnmappableTargetDeepMapValueMapper.java} (70%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableDeepNestingMapper.java => UnmappableTargetDeepNestingMapper.java} (71%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/erroneous/{UnmappableValuePropertyMapper.java => UnmappableTargetValuePropertyMapper.java} (70%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnCollectionElementPropertyMapper.java => UnmappableSourceWarnCollectionElementPropertyMapper.java} (55%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnDeepListMapper.java => UnmappableSourceWarnDeepListMapper.java} (56%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnDeepMapKeyMapper.java => UnmappableSourceWarnDeepMapKeyMapper.java} (56%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnDeepMapValueMapper.java => UnmappableSourceWarnDeepMapValueMapper.java} (56%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnDeepNestingMapper.java => UnmappableSourceWarnDeepNestingMapper.java} (56%) rename processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/{UnmappableWarnValuePropertyMapper.java => UnmappableSourceWarnValuePropertyMapper.java} (56%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnCollectionElementPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnDeepListMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnDeepMapKeyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnDeepMapValueMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnDeepNestingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nestedbeans/unmappable/warn/UnmappableTargetWarnValuePropertyMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 8979901f80..9abed3ec44 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1718,54 +1718,22 @@ private void reportErrorForUnmappedTargetPropertiesIfRequired() { } else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.requiresReport() ) { - if ( !( method instanceof ForgedMethod ) ) { - Message msg = unmappedTargetPolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ? - Message.BEANMAPPING_UNMAPPED_TARGETS_ERROR : Message.BEANMAPPING_UNMAPPED_TARGETS_WARNING; - Object[] args = new Object[] { - MessageFormat.format( - "{0,choice,1#property|1 unmappedProperties, + Message unmappedPropertiesMsg, + Message unmappedForgedPropertiesMsg) { + if ( !( method instanceof ForgedMethod ) ) { Object[] args = new Object[] { MessageFormat.format( "{0,choice,1#property|1 Date: Sun, 11 Feb 2024 19:53:38 +0100 Subject: [PATCH 0813/1006] #3360 Do not report unmapped source and target properties when result type is abstract due to runtime exception subclass exhaustive strategy (#3526) --- .../ap/internal/model/BeanMappingMethod.java | 6 +- .../ap/test/bugs/_3360/Issue3360Mapper.java | 34 ++++++++++++ .../ap/test/bugs/_3360/Issue3360Test.java | 43 +++++++++++++++ .../mapstruct/ap/test/bugs/_3360/Vehicle.java | 55 +++++++++++++++++++ .../ap/test/bugs/_3360/VehicleDto.java | 45 +++++++++++++++ 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Vehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/VehicleDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 9abed3ec44..dd3a86e2cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -319,8 +319,10 @@ else if ( !method.isUpdateMethod() ) { handleUnmappedConstructorProperties(); // report errors on unmapped properties - reportErrorForUnmappedTargetPropertiesIfRequired(); - reportErrorForUnmappedSourcePropertiesIfRequired(); + if ( shouldHandledDefinedMappings ) { + reportErrorForUnmappedTargetPropertiesIfRequired(); + reportErrorForUnmappedSourcePropertiesIfRequired(); + } reportErrorForMissingIgnoredSourceProperties(); reportErrorForUnusedSourceParameters(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Mapper.java new file mode 100644 index 0000000000..812d885489 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Mapper.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3360; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper( + subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION, + unmappedTargetPolicy = ReportingPolicy.ERROR, + unmappedSourcePolicy = ReportingPolicy.ERROR +) +public interface Issue3360Mapper { + + Issue3360Mapper INSTANCE = Mappers.getMapper( Issue3360Mapper.class ); + + @SubclassMapping(target = VehicleDto.Car.class, source = Vehicle.Car.class) + VehicleDto map(Vehicle vehicle); + + @Mapping(target = "model", source = "modelName") + @BeanMapping(ignoreUnmappedSourceProperties = "computedName") + VehicleDto.Car map(Vehicle.Car car); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Test.java new file mode 100644 index 0000000000..307c2b265a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Issue3360Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3360; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3360") +@WithClasses({ + Issue3360Mapper.class, + Vehicle.class, + VehicleDto.class, +}) +class Issue3360Test { + + @ProcessorTest + void shouldCompileWithoutErrorsAndWarnings() { + + Vehicle vehicle = new Vehicle.Car( "Test", "car", 4 ); + + VehicleDto target = Issue3360Mapper.INSTANCE.map( vehicle ); + + assertThat( target.getName() ).isEqualTo( "Test" ); + assertThat( target.getModel() ).isEqualTo( "car" ); + assertThat( target ).isInstanceOfSatisfying( VehicleDto.Car.class, car -> { + assertThat( car.getNumOfDoors() ).isEqualTo( 4 ); + } ); + + assertThatThrownBy( () -> Issue3360Mapper.INSTANCE.map( new Vehicle.Motorbike( "Test", "bike" ) ) ) + .isInstanceOf( IllegalArgumentException.class ) + .hasMessage( "Not all subclasses are supported for this mapping. Missing for " + Vehicle.Motorbike.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Vehicle.java new file mode 100644 index 0000000000..0cc2011bc9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/Vehicle.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3360; + +/** + * @author Filip Hrisafov + */ +public abstract class Vehicle { + + private final String name; + private final String modelName; + + protected Vehicle(String name, String modelName) { + this.name = name; + this.modelName = modelName; + } + + public String getName() { + return name; + } + + public String getModelName() { + return modelName; + } + + public String getComputedName() { + return null; + } + + public static class Car extends Vehicle { + + private final int numOfDoors; + + public Car(String name, String modelName, int numOfDoors) { + super( name, modelName ); + this.numOfDoors = numOfDoors; + } + + public int getNumOfDoors() { + return numOfDoors; + } + } + + public static class Motorbike extends Vehicle { + + public Motorbike(String name, String modelName) { + super( name, modelName ); + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/VehicleDto.java new file mode 100644 index 0000000000..fc93a2fcae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3360/VehicleDto.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3360; + +/** + * @author Filip Hrisafov + */ +public abstract class VehicleDto { + + private String name; + private String model; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public static class Car extends VehicleDto { + + private int numOfDoors; + + public int getNumOfDoors() { + return numOfDoors; + } + + public void setNumOfDoors(int numOfDoors) { + this.numOfDoors = numOfDoors; + } + } + +} From 2c12e75bfcae80aed0aa2674ccdf248280a6f4dc Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:59:32 +0100 Subject: [PATCH 0814/1006] #3485 Exception for Mapping to target = "." without source --- .../internal/model/source/MappingOptions.java | 3 ++ .../mapstruct/ap/internal/util/Message.java | 1 + .../bugs/_3485/ErroneousIssue3485Mapper.java | 35 +++++++++++++++++++ .../ap/test/bugs/_3485/Issue3485Test.java | 33 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index f60eba1931..e0994d746f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -260,6 +260,9 @@ else if ( gem.nullValuePropertyMappingStrategy().hasValue() else if ( ".".equals( gem.target().get() ) && gem.ignore().hasValue() && gem.ignore().getValue() ) { message = Message.PROPERTYMAPPING_TARGET_THIS_AND_IGNORE; } + else if ( ".".equals( gem.target().get() ) && !gem.source().hasValue() ) { + message = Message.PROPERTYMAPPING_TARGET_THIS_NO_SOURCE; + } if ( message == null ) { return true; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index ab8fa01010..68c079cb96 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -71,6 +71,7 @@ public enum Message { PROPERTYMAPPING_DEFAULT_EXPERSSION_AND_NVPMS( "DefaultExpression and nullValuePropertyMappingStrategy are both defined in @Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_IGNORE_AND_NVPMS( "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, either define ignore or an nullValuePropertyMappingStrategy." ), PROPERTYMAPPING_TARGET_THIS_AND_IGNORE( "Using @Mapping( target = \".\", ignore = true ) is not allowed. You need to use @BeanMapping( ignoreByDefault = true ) if you would like to ignore all non explicitly mapped target properties." ), + PROPERTYMAPPING_TARGET_THIS_NO_SOURCE( "Using @Mapping( target = \".\") requires a source property. Expression or constant cannot be used as a source."), PROPERTYMAPPING_EXPRESSION_AND_QUALIFIER_BOTH_DEFINED("Expression and a qualifier both defined in @Mapping, either define an expression or a qualifier."), PROPERTYMAPPING_INVALID_EXPRESSION( "Value for expression must be given in the form \"java()\"." ), PROPERTYMAPPING_INVALID_DEFAULT_EXPRESSION( "Value for default expression must be given in the form \"java()\"." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java new file mode 100644 index 0000000000..5714e04684 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3485; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author hduelme + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ErroneousIssue3485Mapper { + + ErroneousIssue3485Mapper INSTANCE = Mappers.getMapper( ErroneousIssue3485Mapper.class ); + class Target { + private final String value; + + public Target( String value ) { + this.value = value; + } + + public String getValue() { + return value; + } + + } + + @Mapping(target = ".") + Target targetFromExpression(String s); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java new file mode 100644 index 0000000000..cf7e0563af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3485; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * @author hduelme + */ +@IssueKey("3463") +public class Issue3485Test { + + @ProcessorTest + @WithClasses(ErroneousIssue3485Mapper.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousIssue3485Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 33, + message = "Using @Mapping( target = \".\") requires a source property. Expression or " + + "constant cannot be used as a source.") + }) + void thisMappingWithoutSource() { + } +} From e815e3cb1eabfef2930accf7d5f2c442ff2a456e Mon Sep 17 00:00:00 2001 From: Oliver Erhart <8238759+thunderhook@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:15:37 +0100 Subject: [PATCH 0815/1006] #3524 Provide tests with Lombok style super builders --- .../ap/test/superbuilder/AbstractVehicle.java | 46 +++++ .../test/superbuilder/AbstractVehicleDto.java | 20 +++ .../mapstruct/ap/test/superbuilder/Car.java | 63 +++++++ .../ap/test/superbuilder/CarDto.java | 21 +++ .../ap/test/superbuilder/CarMapper.java | 43 +++++ .../superbuilder/ChainedAccessorsCar.java | 58 +++++++ .../superbuilder/ChainedAccessorsVehicle.java | 72 ++++++++ .../superbuilder/InheritedAbstractCar.java | 54 ++++++ .../superbuilder/InheritedAbstractCarDto.java | 21 +++ .../ap/test/superbuilder/MuscleCar.java | 52 ++++++ .../ap/test/superbuilder/MuscleCarDto.java | 21 +++ .../ap/test/superbuilder/Passenger.java | 50 ++++++ .../ap/test/superbuilder/PassengerDto.java | 20 +++ .../test/superbuilder/SuperBuilderTest.java | 160 ++++++++++++++++++ .../ap/test/superbuilder/Vehicle.java | 50 ++++++ .../ap/test/superbuilder/VehicleDto.java | 25 +++ 16 files changed, 776 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicleDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/Car.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsCar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsVehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCarDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/Passenger.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/PassengerDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/SuperBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/Vehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/superbuilder/VehicleDto.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicle.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicle.java new file mode 100644 index 0000000000..d9cf159888 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicle.java @@ -0,0 +1,46 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public abstract class AbstractVehicle { + + private final int amountOfTires; + private final Passenger passenger; + + protected AbstractVehicle(AbstractVehicleBuilder b) { + this.amountOfTires = b.amountOfTires; + this.passenger = b.passenger; + } + + public int getAmountOfTires() { + return this.amountOfTires; + } + + public Passenger getPassenger() { + return this.passenger; + } + + public abstract static class AbstractVehicleBuilder> { + + private int amountOfTires; + private Passenger passenger; + + public B amountOfTires(int amountOfTires) { + this.amountOfTires = amountOfTires; + return self(); + } + + public B passenger(Passenger passenger) { + this.passenger = passenger; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicleDto.java new file mode 100644 index 0000000000..0b97398ae0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/AbstractVehicleDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public abstract class AbstractVehicleDto { + + private final int amountOfTires; + + public AbstractVehicleDto(int amountOfTires) { + this.amountOfTires = amountOfTires; + } + + public int getAmountOfTires() { + return amountOfTires; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Car.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Car.java new file mode 100644 index 0000000000..af15ee6631 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Car.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class Car extends Vehicle { + + private final String manufacturer; + private final Passenger passenger; + + protected Car(CarBuilder b) { + super( b ); + this.manufacturer = b.manufacturer; + this.passenger = b.passenger; + } + + public static CarBuilder builder() { + return new CarBuilderImpl(); + } + + public String getManufacturer() { + return this.manufacturer; + } + + public Passenger getPassenger() { + return this.passenger; + } + + public abstract static class CarBuilder> extends VehicleBuilder { + + private String manufacturer; + private Passenger passenger; + + public B manufacturer(String manufacturer) { + this.manufacturer = manufacturer; + return self(); + } + + public B passenger(Passenger passenger) { + this.passenger = passenger; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class CarBuilderImpl extends CarBuilder { + private CarBuilderImpl() { + } + + protected CarBuilderImpl self() { + return this; + } + + public Car build() { + return new Car( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarDto.java new file mode 100644 index 0000000000..9877e27d71 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarDto.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class CarDto extends VehicleDto { + + private final String manufacturer; + + public CarDto(int amountOfTires, String manufacturer, PassengerDto passenger) { + super( amountOfTires, passenger ); + this.manufacturer = manufacturer; + } + + public String getManufacturer() { + return manufacturer; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarMapper.java new file mode 100644 index 0000000000..a3def64ead --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/CarMapper.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CarMapper { + + CarMapper INSTANCE = Mappers.getMapper( CarMapper.class ); + + @Mapping(target = "amountOfTires", source = "tireCount") + Car carDtoToCar(CarDto source); + + @InheritInverseConfiguration(name = "carDtoToCar") + CarDto carToCarDto(Car source); + + @Mapping(target = "amountOfTires", source = "tireCount") + ChainedAccessorsCar carDtoToChainedAccessorsCar(CarDto source); + + @InheritInverseConfiguration(name = "carDtoToChainedAccessorsCar") + CarDto chainedAccessorsCarToCarDto(ChainedAccessorsCar source); + + @Mapping(target = "amountOfTires", source = "tireCount") + InheritedAbstractCar carDtoToInheritedAbstractCar(CarDto source); + + @InheritInverseConfiguration(name = "carDtoToInheritedAbstractCar") + CarDto inheritedAbstractCarToCarDto(InheritedAbstractCar source); + + @Mapping(target = "amountOfTires", source = "tireCount") + @Mapping(target = "horsePower", constant = "140.5f") + MuscleCar carDtoToMuscleCar(CarDto source); + + @InheritInverseConfiguration(name = "carDtoToMuscleCar") + CarDto muscleCarToCarDto(MuscleCar source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsCar.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsCar.java new file mode 100644 index 0000000000..48faa101c3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsCar.java @@ -0,0 +1,58 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class ChainedAccessorsCar extends ChainedAccessorsVehicle { + + private String manufacturer; + + protected ChainedAccessorsCar(ChainedAccessorsCarBuilder b) { + super( b ); + this.manufacturer = b.manufacturer; + } + + public static ChainedAccessorsCarBuilder builder() { + return new ChainedAccessorsCarBuilderImpl(); + } + + public String getManufacturer() { + return this.manufacturer; + } + + public ChainedAccessorsCar setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + return this; + } + + public abstract static class ChainedAccessorsCarBuilder> extends ChainedAccessorsVehicleBuilder { + + private String manufacturer; + + public B manufacturer(String manufacturer) { + this.manufacturer = manufacturer; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class ChainedAccessorsCarBuilderImpl + extends ChainedAccessorsCarBuilder { + private ChainedAccessorsCarBuilderImpl() { + } + + protected ChainedAccessorsCarBuilderImpl self() { + return this; + } + + public ChainedAccessorsCar build() { + return new ChainedAccessorsCar( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsVehicle.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsVehicle.java new file mode 100644 index 0000000000..3344fb26f9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/ChainedAccessorsVehicle.java @@ -0,0 +1,72 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class ChainedAccessorsVehicle { + private int amountOfTires; + private Passenger passenger; + + protected ChainedAccessorsVehicle(ChainedAccessorsVehicleBuilder b) { + this.amountOfTires = b.amountOfTires; + this.passenger = b.passenger; + } + + public static ChainedAccessorsVehicleBuilder builder() { + return new ChainedAccessorsVehicleBuilderImpl(); + } + + public int getAmountOfTires() { + return this.amountOfTires; + } + + public Passenger getPassenger() { + return this.passenger; + } + + public ChainedAccessorsVehicle setAmountOfTires(int amountOfTires) { + this.amountOfTires = amountOfTires; + return this; + } + + public ChainedAccessorsVehicle setPassenger(Passenger passenger) { + this.passenger = passenger; + return this; + } + + public abstract static class ChainedAccessorsVehicleBuilder> { + private int amountOfTires; + private Passenger passenger; + + public B amountOfTires(int amountOfTires) { + this.amountOfTires = amountOfTires; + return self(); + } + + public B passenger(Passenger passenger) { + this.passenger = passenger; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class ChainedAccessorsVehicleBuilderImpl + extends ChainedAccessorsVehicleBuilder { + private ChainedAccessorsVehicleBuilderImpl() { + } + + protected ChainedAccessorsVehicleBuilderImpl self() { + return this; + } + + public ChainedAccessorsVehicle build() { + return new ChainedAccessorsVehicle( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCar.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCar.java new file mode 100644 index 0000000000..1d07106af8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCar.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class InheritedAbstractCar extends AbstractVehicle { + + private final String manufacturer; + + protected InheritedAbstractCar(InheritedAbstractCarBuilder b) { + super( b ); + this.manufacturer = b.manufacturer; + } + + public static InheritedAbstractCarBuilder builder() { + return new InheritedAbstractCarBuilderImpl(); + } + + public String getManufacturer() { + return this.manufacturer; + } + + public abstract static class InheritedAbstractCarBuilder> + + extends AbstractVehicleBuilder { + private String manufacturer; + + public B manufacturer(String manufacturer) { + this.manufacturer = manufacturer; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class InheritedAbstractCarBuilderImpl + extends InheritedAbstractCarBuilder { + private InheritedAbstractCarBuilderImpl() { + } + + protected InheritedAbstractCarBuilderImpl self() { + return this; + } + + public InheritedAbstractCar build() { + return new InheritedAbstractCar( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCarDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCarDto.java new file mode 100644 index 0000000000..a9cc6bbdbb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/InheritedAbstractCarDto.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class InheritedAbstractCarDto extends AbstractVehicleDto { + + private final String manufacturer; + + public InheritedAbstractCarDto(int amountOfTires, String manufacturer) { + super( amountOfTires ); + this.manufacturer = manufacturer; + } + + public String getManufacturer() { + return manufacturer; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCar.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCar.java new file mode 100644 index 0000000000..ec330536ff --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCar.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class MuscleCar extends Car { + + private final float horsePower; + + protected MuscleCar(MuscleCarBuilder b) { + super( b ); + this.horsePower = b.horsePower; + } + + public static MuscleCarBuilder builder() { + return new MuscleCarBuilderImpl(); + } + + public float getHorsePower() { + return this.horsePower; + } + + public abstract static class MuscleCarBuilder> + extends CarBuilder { + + private float horsePower; + + public B horsePower(float horsePower) { + this.horsePower = horsePower; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class MuscleCarBuilderImpl extends MuscleCarBuilder { + private MuscleCarBuilderImpl() { + } + + protected MuscleCarBuilderImpl self() { + return this; + } + + public MuscleCar build() { + return new MuscleCar( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCarDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCarDto.java new file mode 100644 index 0000000000..7ffe150ecf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/MuscleCarDto.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class MuscleCarDto extends CarDto { + + private final float horsePower; + + public MuscleCarDto(int amountOfTires, String manufacturer, PassengerDto passenger, float horsePower) { + super( amountOfTires, manufacturer, passenger ); + this.horsePower = horsePower; + } + + public float getHorsePower() { + return horsePower; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Passenger.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Passenger.java new file mode 100644 index 0000000000..2b6740af78 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Passenger.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class Passenger { + + private final String name; + + protected Passenger(PassengerBuilder b) { + this.name = b.name; + } + + public static PassengerBuilder builder() { + return new PassengerBuilderImpl(); + } + + public String getName() { + return this.name; + } + + public abstract static class PassengerBuilder> { + + private String name; + + public B name(String name) { + this.name = name; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class PassengerBuilderImpl extends PassengerBuilder { + private PassengerBuilderImpl() { + } + + protected PassengerBuilderImpl self() { + return this; + } + + public Passenger build() { + return new Passenger( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/PassengerDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/PassengerDto.java new file mode 100644 index 0000000000..f63f6e0683 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/PassengerDto.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class PassengerDto { + + private final String name; + + public PassengerDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/SuperBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/SuperBuilderTest.java new file mode 100644 index 0000000000..93dfb746b0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/SuperBuilderTest.java @@ -0,0 +1,160 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests the mapping of models annotated with @SuperBuilder as source and target. + * + * @author Oliver Erhart + */ +@WithClasses({ + AbstractVehicleDto.class, + CarDto.class, + InheritedAbstractCarDto.class, + MuscleCarDto.class, + PassengerDto.class, + VehicleDto.class, + AbstractVehicle.class, + Car.class, + ChainedAccessorsCar.class, + ChainedAccessorsVehicle.class, + InheritedAbstractCar.class, + MuscleCar.class, + Passenger.class, + Vehicle.class, + CarMapper.class +}) +@IssueKey("3524") +public class SuperBuilderTest { + + @ProcessorTest + public void simpleMapping() { + + PassengerDto passenger = new PassengerDto( "Tom" ); + CarDto carDto = new CarDto( 4, "BMW", passenger ); + + Car car = CarMapper.INSTANCE.carDtoToCar( carDto ); + + assertThat( car.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( car.getAmountOfTires() ).isEqualTo( 4 ); + assertThat( car.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void simpleMappingInverse() { + + Passenger passenger = Passenger.builder().name( "Tom" ).build(); + Car car = Car.builder() + .manufacturer( "BMW" ) + .amountOfTires( 4 ) + .passenger( passenger ) + .build(); + + CarDto carDto = CarMapper.INSTANCE.carToCarDto( car ); + + assertThat( carDto.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( carDto.getTireCount() ).isEqualTo( 4 ); + assertThat( carDto.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void chainedMapping() { + + PassengerDto passenger = new PassengerDto( "Tom" ); + CarDto carDto = new CarDto( 4, "BMW", passenger ); + + ChainedAccessorsCar car = CarMapper.INSTANCE.carDtoToChainedAccessorsCar( carDto ); + + assertThat( car.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( car.getAmountOfTires() ).isEqualTo( 4 ); + assertThat( car.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void chainedMappingInverse() { + + Passenger passenger = Passenger.builder().name( "Tom" ).build(); + ChainedAccessorsCar chainedAccessorsCar = ChainedAccessorsCar.builder() + .manufacturer( "BMW" ) + .amountOfTires( 4 ) + .passenger( passenger ) + .build(); + + CarDto carDto = CarMapper.INSTANCE.chainedAccessorsCarToCarDto( chainedAccessorsCar ); + + assertThat( carDto.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( carDto.getTireCount() ).isEqualTo( 4 ); + assertThat( carDto.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void inheritedAbstractMapping() { + + PassengerDto passenger = new PassengerDto( "Tom" ); + CarDto carDto = new CarDto( 4, "BMW", passenger ); + + InheritedAbstractCar car = CarMapper.INSTANCE.carDtoToInheritedAbstractCar( carDto ); + + assertThat( car.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( car.getAmountOfTires() ).isEqualTo( 4 ); + assertThat( car.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void inheritedAbstractMappingInverse() { + + Passenger passenger = Passenger.builder().name( "Tom" ).build(); + InheritedAbstractCar inheritedAbstractCar = InheritedAbstractCar.builder() + .manufacturer( "BMW" ) + .amountOfTires( 4 ) + .passenger( passenger ) + .build(); + + CarDto carDto = CarMapper.INSTANCE.inheritedAbstractCarToCarDto( inheritedAbstractCar ); + + assertThat( carDto.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( carDto.getTireCount() ).isEqualTo( 4 ); + assertThat( carDto.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void secondLevelMapping() { + + PassengerDto passenger = new PassengerDto( "Tom" ); + CarDto carDto = new CarDto( 4, "BMW", passenger ); + + MuscleCar car = CarMapper.INSTANCE.carDtoToMuscleCar( carDto ); + + assertThat( car.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( car.getAmountOfTires() ).isEqualTo( 4 ); + assertThat( car.getHorsePower() ).isEqualTo( 140.5f ); + assertThat( car.getPassenger().getName() ).isEqualTo( "Tom" ); + } + + @ProcessorTest + public void secondLevelMappingInverse() { + + Passenger passenger = Passenger.builder().name( "Tom" ).build(); + MuscleCar muscleCar = MuscleCar.builder() + .manufacturer( "BMW" ) + .amountOfTires( 4 ) + .passenger( passenger ) + .build(); + + CarDto carDto = CarMapper.INSTANCE.muscleCarToCarDto( muscleCar ); + + assertThat( carDto.getManufacturer() ).isEqualTo( "BMW" ); + assertThat( carDto.getTireCount() ).isEqualTo( 4 ); + assertThat( carDto.getPassenger().getName() ).isEqualTo( "Tom" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Vehicle.java new file mode 100644 index 0000000000..2f4a19d842 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/Vehicle.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class Vehicle { + + private final int amountOfTires; + + protected Vehicle(VehicleBuilder b) { + this.amountOfTires = b.amountOfTires; + } + + public static VehicleBuilder builder() { + return new VehicleBuilderImpl(); + } + + public int getAmountOfTires() { + return this.amountOfTires; + } + + public abstract static class VehicleBuilder> { + + private int amountOfTires; + + public B amountOfTires(int amountOfTires) { + this.amountOfTires = amountOfTires; + return self(); + } + + protected abstract B self(); + + public abstract C build(); + } + + private static final class VehicleBuilderImpl extends VehicleBuilder { + private VehicleBuilderImpl() { + } + + protected VehicleBuilderImpl self() { + return this; + } + + public Vehicle build() { + return new Vehicle( this ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/superbuilder/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/VehicleDto.java new file mode 100644 index 0000000000..04dfefb205 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/superbuilder/VehicleDto.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.superbuilder; + +public class VehicleDto { + + private final int tireCount; + private final PassengerDto passenger; + + public VehicleDto(int tireCount, PassengerDto passenger) { + this.tireCount = tireCount; + this.passenger = passenger; + } + + public int getTireCount() { + return tireCount; + } + + public PassengerDto getPassenger() { + return passenger; + } +} From 8e66445fe9f13b37ea66191548067a80bcc6d048 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:00:41 +0200 Subject: [PATCH 0816/1006] #3564 Correct issue key for `Issue3485Test` --- .../java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java index cf7e0563af..7427b63a4e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java @@ -15,7 +15,7 @@ /** * @author hduelme */ -@IssueKey("3463") +@IssueKey("3485") public class Issue3485Test { @ProcessorTest From 5fbd36c44392b7f910e24ceec35fa47a98abba89 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:20:11 +0200 Subject: [PATCH 0817/1006] #3577 Improve `Mapping#ignoreByDefault` documentation --- core/src/main/java/org/mapstruct/BeanMapping.java | 6 ++++++ .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index a03546b07d..e94ff98f2d 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -19,6 +19,8 @@ /** * Configures the mapping between two bean types. *

      + * Unless otherwise specified these properties are inherited to the generated bean mapping methods. + *

      * Either {@link #resultType()}, {@link #qualifiedBy()} or {@link #nullValueMappingStrategy()} must be specified. *

      *

      Example: Determining the result type

      @@ -58,6 +60,8 @@ /** * Specifies the result type of the factory method to be used in case several factory methods qualify. + *

      + * NOTE: This property is not inherited to generated mapping methods * * @return the resultType to select */ @@ -145,6 +149,8 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() * source properties report. *

      * NOTE: This does not support ignoring nested source properties + *

      + * NOTE: This property is not inherited to generated mapping methods * * @return The source properties that should be ignored when performing a report * diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index eb3d5a80ec..2174822359 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -39,7 +39,7 @@ The property name as defined in the http://www.oracle.com/technetwork/java/javas ==== [TIP] ==== -By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. +By means of the `@BeanMapping(ignoreByDefault = true)` the default behavior will be *explicit mapping*, meaning that all mappings (including nested ones) have to be specified by means of the `@Mapping` and no warnings will be issued on missing target properties. This allows to ignore all fields, except the ones that are explicitly defined through `@Mapping`. ==== [TIP] From 0a935c67a7c9ca17a3c6980b96d964c46be527a1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 28 Apr 2024 19:04:57 +0200 Subject: [PATCH 0818/1006] #3565 Presence check methods should not be considered as valid mapping candidates --- .../creation/MappingResolverImpl.java | 3 + .../ap/test/bugs/_3565/Issue3565Mapper.java | 57 +++++++++++++++++++ .../ap/test/bugs/_3565/Issue3565Test.java | 33 +++++++++++ 3 files changed, 93 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index b290ff56bc..e6a26ba045 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -470,6 +470,9 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy } private boolean isCandidateForMapping(Method methodCandidate) { + if ( methodCandidate.isPresenceCheck() ) { + return false; + } return isCreateMethodForMapping( methodCandidate ) || isUpdateMethodForMapping( methodCandidate ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Mapper.java new file mode 100644 index 0000000000..b86e667e56 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Mapper.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3565; + +import java.util.Optional; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3565Mapper { + + Issue3565Mapper INSTANCE = Mappers.getMapper( Issue3565Mapper.class ); + + default T mapFromOptional(Optional value) { + return value.orElse( (T) null ); + } + + @Condition + default boolean isOptionalPresent(Optional value) { + return value.isPresent(); + } + + Target map(Source source); + + class Source { + + private final Boolean condition; + + public Source(Boolean condition) { + this.condition = condition; + } + + public Optional getCondition() { + return Optional.ofNullable( this.condition ); + } + } + + class Target { + private String condition; + + public Optional getCondition() { + return Optional.ofNullable( this.condition ); + } + + public void setCondition(String condition) { + this.condition = condition; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Test.java new file mode 100644 index 0000000000..c4cd028d45 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3565/Issue3565Test.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3565; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3565Mapper.class) +@IssueKey("3565") +class Issue3565Test { + + @ProcessorTest + void shouldGenerateValidCode() { + Issue3565Mapper.Target target = Issue3565Mapper.INSTANCE.map( new Issue3565Mapper.Source( null ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getCondition() ).isEmpty(); + + target = Issue3565Mapper.INSTANCE.map( new Issue3565Mapper.Source( false ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getCondition() ).hasValue( "false" ); + } +} From 0a2a0aa526fe1c970baba61c4f9dcc23e975c517 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 29 Apr 2024 08:05:52 +0200 Subject: [PATCH 0819/1006] #2610 Add support for conditions on source parameters + fix incorrect use of source parameter in presence check method (#3543) The new `@SourceParameterCondition` is also going to cover the problems in #3270 and #3459. The changes in the `MethodFamilySelector` are also fixing #3561 --- .../main/java/org/mapstruct/Condition.java | 40 ++-- .../java/org/mapstruct/ConditionStrategy.java | 23 ++ .../mapstruct/SourceParameterCondition.java | 74 +++++++ ...apter-10-advanced-mapping-options.asciidoc | 53 ++++- .../ap/internal/gem/ConditionStrategyGem.java | 15 ++ .../ap/internal/model/BeanMappingMethod.java | 34 ++- .../model/PresenceCheckMethodResolver.java | 92 ++++++-- .../ap/internal/model/common/Parameter.java | 16 +- .../model/common/ParameterBinding.java | 109 +++++++--- .../model/source/ConditionMethodOptions.java | 45 ++++ .../model/source/ConditionOptions.java | 170 +++++++++++++++ .../ap/internal/model/source/Method.java | 12 +- .../internal/model/source/SourceMethod.java | 43 ++-- .../selector/CreateOrUpdateSelector.java | 1 + .../source/selector/MethodFamilySelector.java | 18 +- .../source/selector/SelectionContext.java | 39 ++++ .../source/selector/SelectionCriteria.java | 12 ++ .../processor/MethodRetrievalProcessor.java | 46 +++- .../creation/MappingResolverImpl.java | 2 +- .../mapstruct/ap/internal/util/Message.java | 5 + .../ap/internal/util/MetaAnnotations.java | 85 ++++++++ .../basic/ConditionalMappingTest.java | 198 ++++++++++++++++++ .../ConditionalMethodForSourceBeanMapper.java | 64 ++++++ ...odForSourceParameterAndPropertyMapper.java | 85 ++++++++ ...ourceParameterConditionalMethodMapper.java | 28 +++ ...nditionalWithoutAppliesToMethodMapper.java | 24 +++ ...terConditionalWithMappingTargetMapper.java | 26 +++ ...nditionalWithSourcePropertyNameMapper.java | 26 +++ ...nditionalWithTargetPropertyNameMapper.java | 26 +++ ...ameterConditionalWithTargetTypeMapper.java | 26 +++ .../mapstruct/ap/test/gem/EnumGemsTest.java | 8 + 31 files changed, 1326 insertions(+), 119 deletions(-) create mode 100644 core/src/main/java/org/mapstruct/ConditionStrategy.java create mode 100644 core/src/main/java/org/mapstruct/SourceParameterCondition.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/gem/ConditionStrategyGem.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionMethodOptions.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceBeanMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceParameterAndPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousSourceParameterConditionalMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousConditionalWithoutAppliesToMethodMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithMappingTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetTypeMapper.java diff --git a/core/src/main/java/org/mapstruct/Condition.java b/core/src/main/java/org/mapstruct/Condition.java index 37f1553be1..1273deab0a 100644 --- a/core/src/main/java/org/mapstruct/Condition.java +++ b/core/src/main/java/org/mapstruct/Condition.java @@ -11,26 +11,35 @@ import java.lang.annotation.Target; /** - * This annotation marks a method as a presence check method to check check for presence in beans. + * This annotation marks a method as a presence check method to check for presence in beans + * or it can be used to define additional check methods for something like source parameters. *

      - * By default bean properties are checked against {@code null} or using a presence check method in the source bean. + * By default, bean properties are checked against {@code null} or using a presence check method in the source bean. * If a presence check method is available then it will be used instead. *

      * Presence check methods have to return {@code boolean}. * The following parameters are accepted for the presence check methods: *

        *
      • The parameter with the value of the source property. - * e.g. the value given by calling {@code getName()} for the name property of the source bean
      • + * e.g. the value given by calling {@code getName()} for the name property of the source bean + * - only possible when using the {@link ConditionStrategy#PROPERTIES} + * *
      • The mapping source parameter
      • *
      • {@code @}{@link Context} parameter
      • - *
      • {@code @}{@link TargetPropertyName} parameter
      • - *
      • {@code @}{@link SourcePropertyName} parameter
      • + *
      • + * {@code @}{@link TargetPropertyName} parameter - + * only possible when using the {@link ConditionStrategy#PROPERTIES} + *
      • + *
      • + * {@code @}{@link SourcePropertyName} parameter - + * only possible when using the {@link ConditionStrategy#PROPERTIES} + *
      • *
      * * Note: The usage of this annotation is mandatory * for a method to be considered as a presence check method. * - *
      
      + * 
      
        * public class PresenceCheckUtils {
        *
        *   @Condition
      @@ -45,11 +54,10 @@
        *     MovieDto map(Movie movie);
        * }
        * 
      - * + *

      * The following implementation of {@code MovieMapper} will be generated: * - *

      - * 
      + * 
      
        * public class MovieMapperImpl implements MovieMapper {
        *
        *     @Override
      @@ -67,14 +75,22 @@
        *         return movieDto;
        *     }
        * }
      - * 
      - * 
      + *
      + *

      + * This annotation can also be used as a meta-annotation to define the condition strategy. * * @author Filip Hrisafov + * @see SourceParameterCondition * @since 1.5 */ -@Target({ ElementType.METHOD }) +@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.CLASS) public @interface Condition { + /** + * @return the places where the condition should apply to + * @since 1.6 + */ + ConditionStrategy[] appliesTo() default ConditionStrategy.PROPERTIES; + } diff --git a/core/src/main/java/org/mapstruct/ConditionStrategy.java b/core/src/main/java/org/mapstruct/ConditionStrategy.java new file mode 100644 index 0000000000..6b042017c2 --- /dev/null +++ b/core/src/main/java/org/mapstruct/ConditionStrategy.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +/** + * Strategy for defining what to what a condition (check) method is applied to + * + * @author Filip Hrisafov + * @since 1.6 + */ +public enum ConditionStrategy { + /** + * The condition method should be applied whether a property should be mapped. + */ + PROPERTIES, + /** + * The condition method should be applied to check if a source parameters should be mapped. + */ + SOURCE_PARAMETERS, +} diff --git a/core/src/main/java/org/mapstruct/SourceParameterCondition.java b/core/src/main/java/org/mapstruct/SourceParameterCondition.java new file mode 100644 index 0000000000..8bff97abc4 --- /dev/null +++ b/core/src/main/java/org/mapstruct/SourceParameterCondition.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * This annotation marks a method as a check method to check if a source parameter needs to be mapped. + *

      + * By default, source parameters are checked against {@code null}, unless they are primitives. + *

      + * Check methods have to return {@code boolean}. + * The following parameters are accepted for the presence check methods: + *

        + *
      • The mapping source parameter
      • + *
      • {@code @}{@link Context} parameter
      • + *
      + * + * Note: The usage of this annotation is mandatory + * for a method to be considered as a source check method. + * + *
      
      + * public class PresenceCheckUtils {
      + *
      + *   @SourceParameterCondition
      + *   public static boolean isDefined(Car car) {
      + *      return car != null && car.getId() != null;
      + *   }
      + * }
      + *
      + * @Mapper(uses = PresenceCheckUtils.class)
      + * public interface CarMapper {
      + *
      + *     CarDto map(Car car);
      + * }
      + * 
      + * + * The following implementation of {@code CarMapper} will be generated: + * + *
      
      + * public class CarMapperImpl implements CarMapper {
      + *
      + *     @Override
      + *     public CarDto map(Car car) {
      + *         if ( !PresenceCheckUtils.isDefined( car ) ) {
      + *             return null;
      + *         }
      + *
      + *         CarDto carDto = new CarDto();
      + *
      + *         carDto.setId( car.getId() );
      + *         // ...
      + *
      + *         return carDto;
      + *     }
      + * }
      + * 
      + * + * @author Filip Hrisafov + * @since 1.6 + * @see Condition @Condition + */ +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.CLASS) +@Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) +public @interface SourceParameterCondition { + +} diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index db13c0548b..1e2bd133d4 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -303,8 +303,10 @@ null check, regardless the value of the `NullValueCheckStrategy` to avoid additi Conditional Mapping is a type of <>. The difference is that it allows users to write custom condition methods that will be invoked to check if a property needs to be mapped or not. +Conditional mapping can also be used to check if a source parameter should be mapped or not. -A custom condition method is a method that is annotated with `org.mapstruct.Condition` and returns `boolean`. +A custom condition method for properties is a method that is annotated with `org.mapstruct.Condition` and returns `boolean`. +A custom condition method for source parameters is annotated with `org.mapstruct.SourceParameterCondition`, `org.mapstruct.Condition(appliesTo = org.mapstruct.ConditionStrategy#SOURCE_PARAMETERS)` or meta-annotated with `Condition(appliesTo = ConditionStrategy#SOURCE_PARAMETERS)` e.g. if you only want to map a String property when it is not `null`, and it is not empty then you can do something like: @@ -484,6 +486,55 @@ Methods annotated with `@Condition` in addition to the value of the source prope <> is also valid for `@Condition` methods. In order to use a more specific condition method you will need to use one of `Mapping#conditionQualifiedByName` or `Mapping#conditionQualifiedBy`. +If we want to only map cars that have an id provided then we can do something like: + + +.Mapper using custom condition source parameter check method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface CarMapper { + + CarDto carToCarDto(Car car); + + @SourceParameterCondition + default boolean hasCar(Car car) { + return car != null && car.getId() != null; + } +} +---- +==== + +The generated mapper will look like: + +.Custom condition source parameter check generated implementation +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car) { + if ( !hasCar( car ) ) { + return null; + } + + CarDto carDto = new CarDto(); + + carDto.setOwner( car.getOwner() ); + + // Mapping of other properties + + return carDto; + } +} +---- +==== + [[exceptions]] === Exceptions diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/ConditionStrategyGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/ConditionStrategyGem.java new file mode 100644 index 0000000000..adea4b4c1f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/ConditionStrategyGem.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.gem; + +/** + * @author Filip Hrisafov + */ +public enum ConditionStrategyGem { + + PROPERTIES, + SOURCE_PARAMETERS +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index dd3a86e2cf..cf5179f9cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -411,6 +411,26 @@ else if ( !method.isUpdateMethod() ) { removeMappingReferencesWithoutSourceParameters( afterMappingReferencesWithFinalizedReturnType ); } + Map presenceChecksByParameter = new LinkedHashMap<>(); + for ( Parameter sourceParameter : method.getSourceParameters() ) { + PresenceCheck parameterPresenceCheck = PresenceCheckMethodResolver.getPresenceCheckForSourceParameter( + method, + selectionParameters, + sourceParameter, + ctx + ); + if ( parameterPresenceCheck != null ) { + presenceChecksByParameter.put( sourceParameter.getName(), parameterPresenceCheck ); + } + else if ( !sourceParameter.getType().isPrimitive() ) { + presenceChecksByParameter.put( + sourceParameter.getName(), + new NullPresenceCheck( sourceParameter.getName() ) + ); + } + } + + return new BeanMappingMethod( method, getMethodAnnotations(), @@ -426,7 +446,8 @@ else if ( !method.isUpdateMethod() ) { afterMappingReferencesWithFinalizedReturnType, finalizeMethod, mappingReferences, - subclasses + subclasses, + presenceChecksByParameter ); } @@ -1891,7 +1912,8 @@ private BeanMappingMethod(Method method, List afterMappingReferencesWithFinalizedReturnType, MethodReference finalizerMethod, MappingReferences mappingReferences, - List subclassMappings) { + List subclassMappings, + Map presenceChecksByParameter) { super( method, annotations, @@ -1923,18 +1945,12 @@ private BeanMappingMethod(Method method, // parameter mapping. this.mappingsByParameter = new HashMap<>(); this.constantMappings = new ArrayList<>( propertyMappings.size() ); - this.presenceChecksByParameter = new LinkedHashMap<>(); + this.presenceChecksByParameter = presenceChecksByParameter; this.constructorMappingsByParameter = new LinkedHashMap<>(); this.constructorConstantMappings = new ArrayList<>(); Set sourceParameterNames = new HashSet<>(); for ( Parameter sourceParameter : getSourceParameters() ) { sourceParameterNames.add( sourceParameter.getName() ); - if ( !sourceParameter.getType().isPrimitive() ) { - presenceChecksByParameter.put( - sourceParameter.getName(), - new NullPresenceCheck( sourceParameter.getName() ) - ); - } } for ( PropertyMapping mapping : propertyMappings ) { if ( mapping.isConstructorMapping() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index a5c873743d..5906db8219 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.stream.Collectors; +import org.mapstruct.ap.internal.gem.ConditionStrategyGem; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.source.Method; @@ -18,6 +19,7 @@ import org.mapstruct.ap.internal.model.source.selector.MethodSelectors; import org.mapstruct.ap.internal.model.source.selector.SelectedMethod; import org.mapstruct.ap.internal.model.source.selector.SelectionContext; +import org.mapstruct.ap.internal.model.source.selector.SelectionCriteria; import org.mapstruct.ap.internal.util.Message; /** @@ -34,36 +36,53 @@ public static PresenceCheck getPresenceCheck( SelectionParameters selectionParameters, MappingBuilderContext ctx ) { - SelectedMethod matchingMethod = findMatchingPresenceCheckMethod( + List> matchingMethods = findMatchingMethods( method, - selectionParameters, + SelectionContext.forPresenceCheckMethods( method, selectionParameters, ctx.getTypeFactory() ), ctx ); - if ( matchingMethod == null ) { + if ( matchingMethods.isEmpty() ) { + return null; + } + + if ( matchingMethods.size() > 1 ) { + ctx.getMessager().printMessage( + method.getExecutable(), + Message.GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD, + selectionParameters.getSourceRHS().getSourceType().describe(), + matchingMethods.stream() + .map( SelectedMethod::getMethod ) + .map( Method::describe ) + .collect( Collectors.joining( ", " ) ) + ); + return null; } + SelectedMethod matchingMethod = matchingMethods.get( 0 ); + MethodReference methodReference = getPresenceCheckMethodReference( method, matchingMethod, ctx ); return new MethodReferencePresenceCheck( methodReference ); } - private static SelectedMethod findMatchingPresenceCheckMethod( + public static PresenceCheck getPresenceCheckForSourceParameter( Method method, SelectionParameters selectionParameters, + Parameter sourceParameter, MappingBuilderContext ctx ) { - MethodSelectors selectors = new MethodSelectors( - ctx.getTypeUtils(), - ctx.getElementUtils(), - ctx.getMessager() - ); - - List> matchingMethods = selectors.getMatchingMethods( - getAllAvailableMethods( method, ctx.getSourceModel() ), - SelectionContext.forPresenceCheckMethods( method, selectionParameters, ctx.getTypeFactory() ) + List> matchingMethods = findMatchingMethods( + method, + SelectionContext.forSourceParameterPresenceCheckMethods( + method, + selectionParameters, + sourceParameter, + ctx.getTypeFactory() + ), + ctx ); if ( matchingMethods.isEmpty() ) { @@ -73,8 +92,8 @@ private static SelectedMethod findMatchingPresenceCheckMethod( if ( matchingMethods.size() > 1 ) { ctx.getMessager().printMessage( method.getExecutable(), - Message.GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD, - selectionParameters.getSourceRHS().getSourceType().describe(), + Message.GENERAL_AMBIGUOUS_SOURCE_PARAMETER_CHECK_METHOD, + sourceParameter.getType().describe(), matchingMethods.stream() .map( SelectedMethod::getMethod ) .map( Method::describe ) @@ -84,7 +103,29 @@ private static SelectedMethod findMatchingPresenceCheckMethod( return null; } - return matchingMethods.get( 0 ); + SelectedMethod matchingMethod = matchingMethods.get( 0 ); + + MethodReference methodReference = getPresenceCheckMethodReference( method, matchingMethod, ctx ); + + return new MethodReferencePresenceCheck( methodReference ); + + } + + private static List> findMatchingMethods( + Method method, + SelectionContext selectionContext, + MappingBuilderContext ctx + ) { + MethodSelectors selectors = new MethodSelectors( + ctx.getTypeUtils(), + ctx.getElementUtils(), + ctx.getMessager() + ); + + return selectors.getMatchingMethods( + getAllAvailableMethods( method, ctx.getSourceModel(), selectionContext.getSelectionCriteria() ), + selectionContext + ); } private static MethodReference getPresenceCheckMethodReference( @@ -116,7 +157,8 @@ private static MethodReference getPresenceCheckMethodReference( } } - private static List getAllAvailableMethods(Method method, List sourceModelMethods) { + private static List getAllAvailableMethods(Method method, List sourceModelMethods, + SelectionCriteria selectionCriteria) { ParameterProvidedMethods contextProvidedMethods = method.getContextProvidedMethods(); if ( contextProvidedMethods.isEmpty() ) { return sourceModelMethods; @@ -129,9 +171,19 @@ private static List getAllAvailableMethods(Method method, List( methodsProvidedByParams.size() + sourceModelMethods.size() ); for ( SourceMethod methodProvidedByParams : methodsProvidedByParams ) { - // add only methods from context that do have the @Condition annotation - if ( methodProvidedByParams.isPresenceCheck() ) { - availableMethods.add( methodProvidedByParams ); + if ( selectionCriteria.isPresenceCheckRequired() ) { + // add only methods from context that do have the @Condition for properties annotation + if ( methodProvidedByParams.getConditionOptions() + .isStrategyApplicable( ConditionStrategyGem.PROPERTIES ) ) { + availableMethods.add( methodProvidedByParams ); + } + } + else if ( selectionCriteria.isSourceParameterCheckRequired() ) { + // add only methods from context that do have the @Condition for source parameters annotation + if ( methodProvidedByParams.getConditionOptions() + .isStrategyApplicable( ConditionStrategyGem.SOURCE_PARAMETERS ) ) { + availableMethods.add( methodProvidedByParams ); + } } } availableMethods.addAll( sourceModelMethods ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index 44ac0eb7f0..aaab7f46ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -133,6 +133,14 @@ public boolean isVarArgs() { return varArgs; } + public boolean isSourceParameter() { + return !isMappingTarget() && + !isTargetType() && + !isMappingContext() && + !isSourcePropertyName() && + !isTargetPropertyName(); + } + @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; @@ -224,12 +232,4 @@ public static Parameter getTargetPropertyNameParameter(List parameter return parameters.stream().filter( Parameter::isTargetPropertyName ).findAny().orElse( null ); } - private static boolean isSourceParameter( Parameter parameter ) { - return !parameter.isMappingTarget() && - !parameter.isTargetType() && - !parameter.isMappingContext() && - !parameter.isSourcePropertyName() && - !parameter.isTargetPropertyName(); - } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java index 0791ee626a..c1a594c73a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ParameterBinding.java @@ -6,7 +6,9 @@ package org.mapstruct.ap.internal.model.common; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.List; import java.util.Set; @@ -19,23 +21,14 @@ public class ParameterBinding { private final Type type; private final String variableName; - private final boolean targetType; - private final boolean mappingTarget; - private final boolean mappingContext; - private final boolean sourcePropertyName; - private final boolean targetPropertyName; private final SourceRHS sourceRHS; + private final Collection bindingTypes; - private ParameterBinding(Type parameterType, String variableName, boolean mappingTarget, boolean targetType, - boolean mappingContext, boolean sourcePropertyName, boolean targetPropertyName, + private ParameterBinding(Type parameterType, String variableName, Collection bindingTypes, SourceRHS sourceRHS) { this.type = parameterType; this.variableName = variableName; - this.targetType = targetType; - this.mappingTarget = mappingTarget; - this.mappingContext = mappingContext; - this.sourcePropertyName = sourcePropertyName; - this.targetPropertyName = targetPropertyName; + this.bindingTypes = bindingTypes; this.sourceRHS = sourceRHS; } @@ -46,39 +39,47 @@ public String getVariableName() { return variableName; } + public boolean isSourceParameter() { + return bindingTypes.contains( BindingType.PARAMETER ); + } + /** * @return {@code true}, if the parameter being bound is a {@code @TargetType} parameter. */ public boolean isTargetType() { - return targetType; + return bindingTypes.contains( BindingType.TARGET_TYPE ); } /** * @return {@code true}, if the parameter being bound is a {@code @MappingTarget} parameter. */ public boolean isMappingTarget() { - return mappingTarget; + return bindingTypes.contains( BindingType.MAPPING_TARGET ); } /** * @return {@code true}, if the parameter being bound is a {@code @MappingContext} parameter. */ public boolean isMappingContext() { - return mappingContext; + return bindingTypes.contains( BindingType.CONTEXT ); + } + + public boolean isForSourceRhs() { + return bindingTypes.contains( BindingType.SOURCE_RHS ); } /** * @return {@code true}, if the parameter being bound is a {@code @SourcePropertyName} parameter. */ public boolean isSourcePropertyName() { - return sourcePropertyName; + return bindingTypes.contains( BindingType.SOURCE_PROPERTY_NAME ); } /** * @return {@code true}, if the parameter being bound is a {@code @TargetPropertyName} parameter. */ public boolean isTargetPropertyName() { - return targetPropertyName; + return bindingTypes.contains( BindingType.TARGET_PROPERTY_NAME ); } /** @@ -96,7 +97,7 @@ public SourceRHS getSourceRHS() { } public Set getImportTypes() { - if ( targetType ) { + if ( isTargetType() ) { return type.getImportTypes(); } @@ -112,14 +113,31 @@ public Set getImportTypes() { * @return a parameter binding reflecting the given parameter as being used as argument for a method call */ public static ParameterBinding fromParameter(Parameter parameter) { + EnumSet bindingTypes = EnumSet.of( BindingType.PARAMETER ); + if ( parameter.isMappingTarget() ) { + bindingTypes.add( BindingType.MAPPING_TARGET ); + } + + if ( parameter.isTargetType() ) { + bindingTypes.add( BindingType.TARGET_TYPE ); + } + + if ( parameter.isMappingContext() ) { + bindingTypes.add( BindingType.CONTEXT ); + } + + if ( parameter.isSourcePropertyName() ) { + bindingTypes.add( BindingType.SOURCE_PROPERTY_NAME ); + } + + if ( parameter.isTargetPropertyName() ) { + bindingTypes.add( BindingType.TARGET_PROPERTY_NAME ); + } + return new ParameterBinding( parameter.getType(), parameter.getName(), - parameter.isMappingTarget(), - parameter.isTargetType(), - parameter.isMappingContext(), - parameter.isSourcePropertyName(), - parameter.isTargetPropertyName(), + bindingTypes, null ); } @@ -136,11 +154,7 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame return new ParameterBinding( parameterType, parameterName, - false, - false, - false, - false, - false, + Collections.emptySet(), null ); } @@ -150,21 +164,31 @@ public static ParameterBinding fromTypeAndName(Type parameterType, String parame * @return a parameter binding representing a target type parameter */ public static ParameterBinding forTargetTypeBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, true, false, false, false, null ); + return new ParameterBinding( classTypeOf, null, Collections.singleton( BindingType.TARGET_TYPE ), null ); } /** * @return a parameter binding representing a target property name parameter */ public static ParameterBinding forTargetPropertyNameBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, false, false, false, true, null ); + return new ParameterBinding( + classTypeOf, + null, + Collections.singleton( BindingType.TARGET_PROPERTY_NAME ), + null + ); } /** * @return a parameter binding representing a source property name parameter */ public static ParameterBinding forSourcePropertyNameBinding(Type classTypeOf) { - return new ParameterBinding( classTypeOf, null, false, false, false, true, false, null ); + return new ParameterBinding( + classTypeOf, + null, + Collections.singleton( BindingType.SOURCE_PROPERTY_NAME ), + null + ); } /** @@ -172,7 +196,7 @@ public static ParameterBinding forSourcePropertyNameBinding(Type classTypeOf) { * @return a parameter binding representing a mapping target parameter */ public static ParameterBinding forMappingTargetBinding(Type resultType) { - return new ParameterBinding( resultType, null, true, false, false, false, false, null ); + return new ParameterBinding( resultType, null, Collections.singleton( BindingType.MAPPING_TARGET ), null ); } /** @@ -180,10 +204,27 @@ public static ParameterBinding forMappingTargetBinding(Type resultType) { * @return a parameter binding representing a mapping source type */ public static ParameterBinding forSourceTypeBinding(Type sourceType) { - return new ParameterBinding( sourceType, null, false, false, false, false, false, null ); + return new ParameterBinding( sourceType, null, Collections.singleton( BindingType.SOURCE_TYPE ), null ); } public static ParameterBinding fromSourceRHS(SourceRHS sourceRHS) { - return new ParameterBinding( sourceRHS.getSourceType(), null, false, false, false, false, false, sourceRHS ); + return new ParameterBinding( + sourceRHS.getSourceType(), + null, + Collections.singleton( BindingType.SOURCE_RHS ), + sourceRHS + ); + } + + enum BindingType { + PARAMETER, + FROM_TYPE_AND_NAME, + TARGET_TYPE, + TARGET_PROPERTY_NAME, + SOURCE_PROPERTY_NAME, + MAPPING_TARGET, + CONTEXT, + SOURCE_TYPE, + SOURCE_RHS } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionMethodOptions.java new file mode 100644 index 0000000000..dfb0865ecc --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionMethodOptions.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.Collection; +import java.util.Collections; + +import org.mapstruct.ap.internal.gem.ConditionStrategyGem; + +/** + * Encapsulates all options specific for a condition check method. + * + * @author Filip Hrisafov + */ +public class ConditionMethodOptions { + + private static final ConditionMethodOptions EMPTY = new ConditionMethodOptions( Collections.emptyList() ); + + private final Collection conditionOptions; + + public ConditionMethodOptions(Collection conditionOptions) { + this.conditionOptions = conditionOptions; + } + + public boolean isStrategyApplicable(ConditionStrategyGem strategy) { + for ( ConditionOptions conditionOption : conditionOptions ) { + if ( conditionOption.getConditionStrategies().contains( strategy ) ) { + return true; + } + } + + return false; + } + + public boolean isAnyStrategyApplicable() { + return !conditionOptions.isEmpty(); + } + + public static ConditionMethodOptions empty() { + return EMPTY; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java new file mode 100644 index 0000000000..936d049af8 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java @@ -0,0 +1,170 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; + +import org.mapstruct.ap.internal.gem.ConditionGem; +import org.mapstruct.ap.internal.gem.ConditionStrategyGem; +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.Message; + +/** + * @author Filip Hrisafov + */ +public class ConditionOptions { + + private final Set conditionStrategies; + + private ConditionOptions(Set conditionStrategies) { + this.conditionStrategies = conditionStrategies; + } + + public Collection getConditionStrategies() { + return conditionStrategies; + } + + public static ConditionOptions getInstanceOn(ConditionGem condition, ExecutableElement method, + List parameters, + FormattingMessager messager) { + if ( condition == null ) { + return null; + } + + TypeMirror returnType = method.getReturnType(); + TypeKind returnTypeKind = returnType.getKind(); + // We only allow methods that return boolean or Boolean to be condition methods + if ( returnTypeKind != TypeKind.BOOLEAN ) { + if ( returnTypeKind != TypeKind.DECLARED ) { + return null; + } + DeclaredType declaredType = (DeclaredType) returnType; + TypeElement returnTypeElement = (TypeElement) declaredType.asElement(); + if ( !returnTypeElement.getQualifiedName().contentEquals( Boolean.class.getCanonicalName() ) ) { + return null; + } + } + + Set strategies = condition.appliesTo().get() + .stream() + .map( ConditionStrategyGem::valueOf ) + .collect( Collectors.toCollection( () -> EnumSet.noneOf( ConditionStrategyGem.class ) ) ); + + if ( strategies.isEmpty() ) { + messager.printMessage( + method, + condition.mirror(), + condition.appliesTo().getAnnotationValue(), + Message.CONDITION_MISSING_APPLIES_TO_STRATEGY + ); + + return null; + } + + boolean allStrategiesValid = true; + + for ( ConditionStrategyGem strategy : strategies ) { + boolean isStrategyValid = isValid( strategy, condition, method, parameters, messager ); + allStrategiesValid &= isStrategyValid; + } + + return allStrategiesValid ? new ConditionOptions( strategies ) : null; + } + + protected static boolean isValid(ConditionStrategyGem strategy, ConditionGem condition, + ExecutableElement method, List parameters, + FormattingMessager messager) { + if ( strategy == ConditionStrategyGem.SOURCE_PARAMETERS ) { + return hasValidStrategyForSourceProperties( condition, method, parameters, messager ); + } + else if ( strategy == ConditionStrategyGem.PROPERTIES ) { + return hasValidStrategyForProperties( condition, method, parameters, messager ); + } + else { + throw new IllegalStateException( "Invalid condition strategy: " + strategy ); + } + } + + protected static boolean hasValidStrategyForSourceProperties(ConditionGem condition, ExecutableElement method, + List parameters, + FormattingMessager messager) { + for ( Parameter parameter : parameters ) { + if ( parameter.isSourceParameter() ) { + // source parameter is a valid parameter for a source condition check + continue; + } + + if ( parameter.isMappingContext() ) { + // mapping context parameter is a valid parameter for a source condition check + continue; + } + + messager.printMessage( + method, + condition.mirror(), + Message.CONDITION_SOURCE_PARAMETERS_INVALID_PARAMETER, + parameter.describe() + ); + return false; + } + return true; + } + + protected static boolean hasValidStrategyForProperties(ConditionGem condition, ExecutableElement method, + List parameters, + FormattingMessager messager) { + for ( Parameter parameter : parameters ) { + if ( parameter.isSourceParameter() ) { + // source parameter is a valid parameter for a property condition check + continue; + } + + if ( parameter.isMappingContext() ) { + // mapping context parameter is a valid parameter for a property condition check + continue; + } + + if ( parameter.isTargetType() ) { + // target type parameter is a valid parameter for a property condition check + continue; + } + + if ( parameter.isMappingTarget() ) { + // mapping target parameter is a valid parameter for a property condition check + continue; + } + + if ( parameter.isSourcePropertyName() ) { + // source property name parameter is a valid parameter for a property condition check + continue; + } + + if ( parameter.isTargetPropertyName() ) { + // target property name parameter is a valid parameter for a property condition check + continue; + } + + messager.printMessage( + method, + condition.mirror(), + Message.CONDITION_PROPERTIES_INVALID_PARAMETER, + parameter + ); + return false; + } + return true; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index 0c60f41364..ad2882080a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -90,14 +90,6 @@ public interface Method { */ boolean isObjectFactory(); - /** - * Returns whether the method is designated as a presence check method - * @return {@code true} if it is a presence check method - */ - default boolean isPresenceCheck() { - return false; - } - /** * Returns the parameter designated as target type (if present) {@link org.mapstruct.TargetType } * @@ -187,6 +179,10 @@ default boolean isPresenceCheck() { */ MappingMethodOptions getOptions(); + default ConditionMethodOptions getConditionOptions() { + return ConditionMethodOptions.empty(); + } + /** * * @return true when @MappingTarget annotated parameter is the same type as the return type. The method has diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 42c318ca49..7103fb2858 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -15,7 +15,6 @@ import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; -import org.mapstruct.ap.internal.gem.ConditionGem; import org.mapstruct.ap.internal.gem.ObjectFactoryGem; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Parameter; @@ -50,11 +49,11 @@ public class SourceMethod implements Method { private final Parameter sourcePropertyNameParameter; private final Parameter targetPropertyNameParameter; private final boolean isObjectFactory; - private final boolean isPresenceCheck; private final Type returnType; private final Accessibility accessibility; private final List exceptionTypes; private final MappingMethodOptions mappingMethodOptions; + private final ConditionMethodOptions conditionMethodOptions; private final List prototypeMethods; private final Type mapperToImplement; @@ -95,6 +94,7 @@ public static class Builder { private List valueMappings; private EnumMappingOptions enumMappingOptions; private ParameterProvidedMethods contextProvidedMethods; + private Set conditionOptions; private List typeParameters; private Set subclassMappings; @@ -196,6 +196,11 @@ public Builder setContextProvidedMethods(ParameterProvidedMethods contextProvide return this; } + public Builder setConditionOptions(Set conditionOptions) { + this.conditionOptions = conditionOptions; + return this; + } + public Builder setVerboseLogging(boolean verboseLogging) { this.verboseLogging = verboseLogging; return this; @@ -223,17 +228,22 @@ public SourceMethod build() { subclassValidator ); + ConditionMethodOptions conditionMethodOptions = + conditionOptions != null ? new ConditionMethodOptions( conditionOptions ) : + ConditionMethodOptions.empty(); + this.typeParameters = this.executable.getTypeParameters() .stream() .map( Element::asType ) .map( typeFactory::getType ) .collect( Collectors.toList() ); - return new SourceMethod( this, mappingMethodOptions ); + return new SourceMethod( this, mappingMethodOptions, conditionMethodOptions ); } } - private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) { + private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions, + ConditionMethodOptions conditionMethodOptions) { this.declaringMapper = builder.declaringMapper; this.executable = builder.executable; this.parameters = builder.parameters; @@ -242,6 +252,7 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.accessibility = Accessibility.fromModifiers( builder.executable.getModifiers() ); this.mappingMethodOptions = mappingMethodOptions; + this.conditionMethodOptions = conditionMethodOptions; this.sourceParameters = Parameter.getSourceParameters( parameters ); this.contextParameters = Parameter.getContextParameters( parameters ); @@ -254,7 +265,6 @@ private SourceMethod(Builder builder, MappingMethodOptions mappingMethodOptions) this.targetPropertyNameParameter = Parameter.getTargetPropertyNameParameter( parameters ); this.hasObjectFactoryAnnotation = ObjectFactoryGem.instanceOn( executable ) != null; this.isObjectFactory = determineIfIsObjectFactory(); - this.isPresenceCheck = determineIfIsPresenceCheck(); this.typeUtils = builder.typeUtils; this.typeFactory = builder.typeFactory; @@ -274,19 +284,6 @@ private boolean determineIfIsObjectFactory() { && ( hasObjectFactoryAnnotation || hasNoSourceParameters ); } - private boolean determineIfIsPresenceCheck() { - if ( returnType.isPrimitive() ) { - if ( !returnType.getName().equals( "boolean" ) ) { - return false; - } - } - else if ( !returnType.getFullyQualifiedName().equals( Boolean.class.getCanonicalName() ) ) { - return false; - } - - return ConditionGem.instanceOn( executable ) != null; - } - @Override public Type getDeclaringMapper() { return declaringMapper; @@ -547,6 +544,11 @@ public MappingMethodOptions getOptions() { return mappingMethodOptions; } + @Override + public ConditionMethodOptions getConditionOptions() { + return conditionMethodOptions; + } + @Override public boolean isStatic() { return executable.getModifiers().contains( Modifier.STATIC ); @@ -567,11 +569,6 @@ public boolean isLifecycleCallbackMethod() { return Executables.isLifecycleCallbackMethod( getExecutable() ); } - @Override - public boolean isPresenceCheck() { - return isPresenceCheck; - } - public boolean isAfterMappingMethod() { return Executables.isAfterMappingMethod( getExecutable() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java index 03a671de57..b6e5ca0a53 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/CreateOrUpdateSelector.java @@ -32,6 +32,7 @@ public List> getMatchingMethods(List> result = new ArrayList<>( methods.size() ); for ( SelectedMethod method : methods ) { - if ( method.getMethod().isObjectFactory() == criteria.isObjectFactoryRequired() + if ( criteria.isPresenceCheckRequired() ) { + if ( method.getMethod() + .getConditionOptions() + .isStrategyApplicable( ConditionStrategyGem.PROPERTIES ) ) { + result.add( method ); + } + } + else if ( criteria.isSourceParameterCheckRequired() ) { + if ( method.getMethod() + .getConditionOptions() + .isStrategyApplicable( ConditionStrategyGem.SOURCE_PARAMETERS ) ) { + result.add( method ); + } + } + else if ( method.getMethod().isObjectFactory() == criteria.isObjectFactoryRequired() && method.getMethod().isLifecycleCallbackMethod() == criteria.isLifecycleCallbackRequired() - && method.getMethod().isPresenceCheck() == criteria.isPresenceCheckRequired() ) { result.add( method ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java index 800278a4c4..84bd04d7db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java @@ -163,6 +163,45 @@ public static SelectionContext forPresenceCheckMethods(Method mappingMethod, ); } + public static SelectionContext forSourceParameterPresenceCheckMethods(Method mappingMethod, + SelectionParameters selectionParameters, + Parameter sourceParameter, + TypeFactory typeFactory) { + SelectionCriteria criteria = SelectionCriteria.forSourceParameterCheckMethods( selectionParameters ); + Type booleanType = typeFactory.getType( Boolean.class ); + return new SelectionContext( + null, + criteria, + mappingMethod, + booleanType, + booleanType, + () -> getParameterBindingsForSourceParameterPresenceCheck( + mappingMethod, + booleanType, + sourceParameter, + typeFactory + ) + ); + } + + private static List getParameterBindingsForSourceParameterPresenceCheck(Method method, + Type targetType, + Parameter sourceParameter, + TypeFactory typeFactory) { + + List availableParams = new ArrayList<>( method.getParameters().size() + 3 ); + + availableParams.add( ParameterBinding.fromParameter( sourceParameter ) ); + availableParams.add( ParameterBinding.forTargetTypeBinding( typeFactory.classTypeOf( targetType ) ) ); + for ( Parameter parameter : method.getParameters() ) { + if ( !parameter.isSourceParameter( ) ) { + availableParams.add( ParameterBinding.fromParameter( parameter ) ); + } + } + + return availableParams; + } + private static List getAvailableParameterBindingsFromMethod(Method method, Type targetType, SourceRHS sourceRHS, TypeFactory typeFactory) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index 2d288dd56e..fa5e1c29c0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -97,6 +97,13 @@ public boolean isPresenceCheckRequired() { return type == Type.PRESENCE_CHECK; } + /** + * @return {@code true} if source parameter check methods should be selected, {@code false} otherwise + */ + public boolean isSourceParameterCheckRequired() { + return type == Type.SOURCE_PARAMETER_CHECK; + } + public void setIgnoreQualifiers(boolean ignoreQualifiers) { this.ignoreQualifiers = ignoreQualifiers; } @@ -177,6 +184,10 @@ public static SelectionCriteria forPresenceCheckMethods(SelectionParameters sele return new SelectionCriteria( selectionParameters, null, null, Type.PRESENCE_CHECK ); } + public static SelectionCriteria forSourceParameterCheckMethods(SelectionParameters selectionParameters) { + return new SelectionCriteria( selectionParameters, null, null, Type.SOURCE_PARAMETER_CHECK ); + } + public static SelectionCriteria forSubclassMappingMethods(SelectionParameters selectionParameters, MappingControl mappingControl) { return new SelectionCriteria( selectionParameters, mappingControl, null, Type.SELF_NOT_ALLOWED ); @@ -187,6 +198,7 @@ public enum Type { OBJECT_FACTORY, LIFECYCLE_CALLBACK, PRESENCE_CHECK, + SOURCE_PARAMETER_CHECK, SELF_NOT_ALLOWED, } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index a9099ea179..4bd2ed48a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -36,6 +36,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.BeanMappingOptions; +import org.mapstruct.ap.internal.model.source.ConditionOptions; import org.mapstruct.ap.internal.model.source.EnumMappingOptions; import org.mapstruct.ap.internal.model.source.IterableMappingOptions; import org.mapstruct.ap.internal.model.source.MapMappingOptions; @@ -53,6 +54,7 @@ import org.mapstruct.ap.internal.util.Executables; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.MetaAnnotations; import org.mapstruct.ap.internal.util.RepeatableAnnotations; import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.spi.EnumTransformationStrategy; @@ -73,6 +75,7 @@ public class MethodRetrievalProcessor implements ModelElementProcessor contextProvidedMethods = new ArrayList<>( contextParamMethods.size() ); for ( SourceMethod sourceMethod : contextParamMethods ) { if ( sourceMethod.isLifecycleCallbackMethod() || sourceMethod.isObjectFactory() - || sourceMethod.isPresenceCheck() ) { + || sourceMethod.getConditionOptions().isAnyStrategyApplicable() ) { contextProvidedMethods.add( sourceMethod ); } } @@ -393,6 +396,7 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType .setExceptionTypes( exceptionTypes ) .setTypeUtils( typeUtils ) .setTypeFactory( typeFactory ) + .setConditionOptions( getConditionOptions( method, parameters ) ) .setVerboseLogging( options.isVerbose() ) .build(); } @@ -633,6 +637,18 @@ private Set getSubclassMappings(List sourcePa .getProcessedAnnotations( method ); } + /** + * Retrieves the conditions configured via {@code @Condition} from the given method. + * + * @param method The method of interest + * @param parameters + * @return The condition options for the given method + */ + + private Set getConditionOptions(ExecutableElement method, List parameters) { + return new MetaConditions( parameters ).getProcessedAnnotations( method ); + } + private class RepeatableMappings extends RepeatableAnnotations { private BeanMappingOptions beanMappingOptions; @@ -774,4 +790,32 @@ protected void addInstances(ValueMappingsGem gems, Element source, Set { + + protected final List parameters; + + protected MetaConditions(List parameters) { + super( elementUtils, CONDITION_FQN ); + this.parameters = parameters; + } + + @Override + protected ConditionGem instanceOn(Element element) { + return ConditionGem.instanceOn( element ); + } + + @Override + protected void addInstance(ConditionGem gem, Element source, Set values) { + ConditionOptions options = ConditionOptions.getInstanceOn( + gem, + (ExecutableElement) source, + parameters, + messager + ); + if ( options != null ) { + values.add( options ); + } + } + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index e6a26ba045..d84ba974db 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -470,7 +470,7 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy } private boolean isCandidateForMapping(Method methodCandidate) { - if ( methodCandidate.isPresenceCheck() ) { + if ( methodCandidate.getConditionOptions().isAnyStrategyApplicable() ) { return false; } return isCreateMethodForMapping( methodCandidate ) || isUpdateMethodForMapping( methodCandidate ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 68c079cb96..5887ee07f0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -46,6 +46,10 @@ public enum Message { BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS( "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not allowed. You'll need to explicitly ignore the target properties that should be ignored instead." ), + CONDITION_MISSING_APPLIES_TO_STRATEGY("'appliesTo' has to have at least one value in @Condition" ), + CONDITION_SOURCE_PARAMETERS_INVALID_PARAMETER("Parameter \"%s\" cannot be used with the ConditionStrategy#SOURCE_PARAMETERS. Only source and @Context parameters are allowed for conditions applicable to source parameters." ), + CONDITION_PROPERTIES_INVALID_PARAMETER("Parameter \"%s\" cannot be used with the ConditionStrategy#PROPERTIES. Only source, @Context, @MappingTarget, @TargetType, @TargetPropertyName and @SourcePropertyName parameters are allowed for conditions applicable to properties." ), + PROPERTYMAPPING_MAPPING_NOTE( "mapping property: %s to: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_CREATE_NOTE( "creating property mapping: %s.", Diagnostic.Kind.NOTE ), PROPERTYMAPPING_SELECT_NOTE( "selecting property mapping: %s.", Diagnostic.Kind.NOTE ), @@ -143,6 +147,7 @@ public enum Message { GENERAL_AMBIGUOUS_MAPPING_METHOD( "Ambiguous mapping methods found for mapping %s to %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_FACTORY_METHOD( "Ambiguous factory methods found for creating %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_PRESENCE_CHECK_METHOD( "Ambiguous presence check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), + GENERAL_AMBIGUOUS_SOURCE_PARAMETER_CHECK_METHOD( "Ambiguous source parameter check methods found for checking %s: %s. See " + FAQ_AMBIGUOUS_URL + " for more info." ), GENERAL_AMBIGUOUS_CONSTRUCTORS( "Ambiguous constructors found for creating %s: %s. Either declare parameterless constructor or annotate the default constructor with an annotation named @Default." ), GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS( "Incorrect @ConstructorProperties for %s. The size of the @ConstructorProperties does not match the number of constructor parameters" ), GENERAL_UNSUPPORTED_DATE_FORMAT_CHECK( "No dateFormat check is supported for types %s, %s" ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java new file mode 100644 index 0000000000..f2328a91cc --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; + +import org.mapstruct.tools.gem.Gem; + +/** + * @author Filip Hrisafov + */ +public abstract class MetaAnnotations { + + private static final String JAVA_LANG_ANNOTATION_PGK = "java.lang.annotation"; + + private final ElementUtils elementUtils; + private final String annotationFqn; + + protected MetaAnnotations(ElementUtils elementUtils, String annotationFqn) { + this.elementUtils = elementUtils; + this.annotationFqn = annotationFqn; + } + + /** + * Retrieves the processed annotations. + * + * @param source The source element of interest + * @return The processed annotations for the given element + */ + public Set getProcessedAnnotations(Element source) { + return getValues( source, source, new LinkedHashSet<>(), new HashSet<>() ); + } + + protected abstract G instanceOn(Element element); + + protected abstract void addInstance(G gem, Element source, Set values); + + /** + * Retrieves the processed annotations. + * + * @param source The source element of interest + * @param element Element of interest: method, or (meta) annotation + * @param values the set of values found so far + * @param handledElements The collection of already handled elements to handle recursion correctly. + * @return The processed annotations for the given element + */ + private Set getValues(Element source, Element element, Set values, Set handledElements) { + for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { + Element annotationElement = annotationMirror.getAnnotationType().asElement(); + if ( isAnnotation( annotationElement, annotationFqn ) ) { + G gem = instanceOn( element ); + addInstance( gem, source, values ); + } + else if ( isNotJavaAnnotation( element ) && !handledElements.contains( annotationElement ) ) { + handledElements.add( annotationElement ); + getValues( source, annotationElement, values, handledElements ); + } + } + return values; + } + + private boolean isNotJavaAnnotation(Element element) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return !elementUtils.getPackageOf( element ).getQualifiedName().contentEquals( JAVA_LANG_ANNOTATION_PGK ); + } + return true; + } + + private boolean isAnnotation(Element element, String annotationFqn) { + if ( ElementKind.ANNOTATION_TYPE == element.getKind() ) { + return ( (TypeElement) element ).getQualifiedName().contentEquals( annotationFqn ); + } + + return false; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java index 57a68a9526..ae309988c8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMappingTest.java @@ -208,6 +208,84 @@ public void conditionalMethodForCollection() { .containsExactly( "Test", "Test Vol. 2" ); } + @ProcessorTest + @WithClasses({ + ConditionalMethodForSourceBeanMapper.class + }) + public void conditionalMethodForSourceBean() { + ConditionalMethodForSourceBeanMapper mapper = ConditionalMethodForSourceBeanMapper.INSTANCE; + + ConditionalMethodForSourceBeanMapper.Employee employee = mapper.map( + new ConditionalMethodForSourceBeanMapper.EmployeeDto( + "1", + "Tester" + ) ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getId() ).isEqualTo( "1" ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + + employee = mapper.map( null ); + + assertThat( employee ).isNull(); + + employee = mapper.map( new ConditionalMethodForSourceBeanMapper.EmployeeDto( null, "Tester" ) ); + + assertThat( employee ).isNull(); + + employee = mapper.map( new ConditionalMethodForSourceBeanMapper.EmployeeDto( "test-123", "Tester" ) ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getId() ).isEqualTo( "test-123" ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + } + + @ProcessorTest + @WithClasses({ + ConditionalMethodForSourceParameterAndPropertyMapper.class + }) + public void conditionalMethodForSourceParameterAndProperty() { + ConditionalMethodForSourceParameterAndPropertyMapper mapper = + ConditionalMethodForSourceParameterAndPropertyMapper.INSTANCE; + + ConditionalMethodForSourceParameterAndPropertyMapper.Employee employee = mapper.map( + new ConditionalMethodForSourceParameterAndPropertyMapper.EmployeeDto( + "1", + "Tester" + ) ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getId() ).isEqualTo( "1" ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + assertThat( employee.getManager() ).isNull(); + + employee = mapper.map( null ); + + assertThat( employee ).isNull(); + + employee = mapper.map( new ConditionalMethodForSourceParameterAndPropertyMapper.EmployeeDto( + "1", + "Tester", + new ConditionalMethodForSourceParameterAndPropertyMapper.EmployeeDto( null, "Manager" ) + ) ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getManager() ).isNull(); + + employee = mapper.map( new ConditionalMethodForSourceParameterAndPropertyMapper.EmployeeDto( + "1", + "Tester", + new ConditionalMethodForSourceParameterAndPropertyMapper.EmployeeDto( "2", "Manager" ) + ) ); + + assertThat( employee ).isNotNull(); + assertThat( employee.getId() ).isEqualTo( "1" ); + assertThat( employee.getName() ).isEqualTo( "Tester" ); + assertThat( employee.getManager() ).isNotNull(); + assertThat( employee.getManager().getId() ).isEqualTo( "2" ); + assertThat( employee.getManager().getName() ).isEqualTo( "Manager" ); + } + @ProcessorTest @WithClasses({ OptionalLikeConditionalMapper.class @@ -244,4 +322,124 @@ public void conditionalMethodWithMappingTarget() { assertThat( targetEmployee.getName() ).isEqualTo( "CurrentName" ); } + + @ProcessorTest + @WithClasses({ + ErroneousConditionalWithoutAppliesToMethodMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousConditionalWithoutAppliesToMethodMapper.class, + line = 19, + message = "'appliesTo' has to have at least one value in @Condition" + ) + } + ) + public void emptyConditional() { + } + + @ProcessorTest + @WithClasses({ + ErroneousSourceParameterConditionalWithMappingTargetMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSourceParameterConditionalWithMappingTargetMapper.class, + line = 21, + message = "Parameter \"@MappingTarget BasicEmployee employee\"" + + " cannot be used with the ConditionStrategy#SOURCE_PARAMETERS." + + " Only source and @Context parameters are allowed for conditions applicable to source parameters." + ) + } + ) + public void sourceParameterConditionalWithMappingTarget() { + } + + @ProcessorTest + @WithClasses({ + ErroneousSourceParameterConditionalWithTargetTypeMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSourceParameterConditionalWithTargetTypeMapper.class, + line = 21, + message = "Parameter \"@TargetType Class targetClass\"" + + " cannot be used with the ConditionStrategy#SOURCE_PARAMETERS." + + " Only source and @Context parameters are allowed for conditions applicable to source parameters." + ) + } + ) + public void sourceParameterConditionalWithTargetType() { + } + + @ProcessorTest + @WithClasses({ + ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.class, + line = 21, + message = "Parameter \"@TargetPropertyName String targetProperty\"" + + " cannot be used with the ConditionStrategy#SOURCE_PARAMETERS." + + " Only source and @Context parameters are allowed for conditions applicable to source parameters." + ) + } + ) + public void sourceParameterConditionalWithTargetPropertyName() { + } + + @ProcessorTest + @WithClasses({ + ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.class, + line = 21, + message = "Parameter \"@SourcePropertyName String sourceProperty\"" + + " cannot be used with the ConditionStrategy#SOURCE_PARAMETERS." + + " Only source and @Context parameters are allowed for conditions applicable to source parameters." + ) + } + ) + public void sourceParametersConditionalWithSourcePropertyName() { + } + + @ProcessorTest + @WithClasses({ + ErroneousAmbiguousSourceParameterConditionalMethodMapper.class + }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousAmbiguousSourceParameterConditionalMethodMapper.class, + line = 17, + message = "Ambiguous source parameter check methods found for checking BasicEmployeeDto: " + + "boolean hasName(BasicEmployeeDto value), " + + "boolean hasStrategy(BasicEmployeeDto value). " + + "See https://mapstruct.org/faq/#ambiguous for more info." + ) + } + ) + public void ambiguousSourceParameterConditionalMethod() { + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceBeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceBeanMapper.java new file mode 100644 index 0000000000..dd2fe4ac90 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceBeanMapper.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Mapper; +import org.mapstruct.SourceParameterCondition; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodForSourceBeanMapper { + + ConditionalMethodForSourceBeanMapper INSTANCE = Mappers.getMapper( ConditionalMethodForSourceBeanMapper.class ); + + Employee map(EmployeeDto employee); + + @SourceParameterCondition + default boolean canMapEmployeeDto(EmployeeDto employee) { + return employee != null && employee.getId() != null; + } + + class EmployeeDto { + + private final String id; + private final String name; + + public EmployeeDto(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + } + + class Employee { + + private final String id; + private final String name; + + public Employee(String id, String name) { + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceParameterAndPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceParameterAndPropertyMapper.java new file mode 100644 index 0000000000..11a97b7239 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ConditionalMethodForSourceParameterAndPropertyMapper.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.ConditionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ConditionalMethodForSourceParameterAndPropertyMapper { + + ConditionalMethodForSourceParameterAndPropertyMapper INSTANCE = Mappers.getMapper( + ConditionalMethodForSourceParameterAndPropertyMapper.class ); + + Employee map(EmployeeDto employee); + + @Condition(appliesTo = { + ConditionStrategy.SOURCE_PARAMETERS, + ConditionStrategy.PROPERTIES + }) + default boolean canMapEmployeeDto(EmployeeDto employee) { + return employee != null && employee.getId() != null; + } + + class EmployeeDto { + + private final String id; + private final String name; + private final EmployeeDto manager; + + public EmployeeDto(String id, String name) { + this( id, name, null ); + } + + public EmployeeDto(String id, String name, EmployeeDto manager) { + this.id = id; + this.name = name; + this.manager = manager; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public EmployeeDto getManager() { + return manager; + } + } + + class Employee { + + private final String id; + private final String name; + private final Employee manager; + + public Employee(String id, String name, Employee manager) { + this.id = id; + this.name = name; + this.manager = manager; + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Employee getManager() { + return manager; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousSourceParameterConditionalMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousSourceParameterConditionalMethodMapper.java new file mode 100644 index 0000000000..39433e2641 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousAmbiguousSourceParameterConditionalMethodMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Mapper; +import org.mapstruct.SourceParameterCondition; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousAmbiguousSourceParameterConditionalMethodMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @SourceParameterCondition + default boolean hasName(BasicEmployeeDto value) { + return value != null && value.getName() != null; + } + + @SourceParameterCondition + default boolean hasStrategy(BasicEmployeeDto value) { + return value != null && value.getStrategy() != null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousConditionalWithoutAppliesToMethodMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousConditionalWithoutAppliesToMethodMapper.java new file mode 100644 index 0000000000..76f62845d5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousConditionalWithoutAppliesToMethodMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousConditionalWithoutAppliesToMethodMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition(appliesTo = {}) + default boolean isNotBlank(String value) { + return value != null && !value.trim().isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithMappingTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithMappingTargetMapper.java new file mode 100644 index 0000000000..b1206798d6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithMappingTargetMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.ConditionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousSourceParameterConditionalWithMappingTargetMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) + default boolean isNotBlank(String value, @MappingTarget BasicEmployee employee) { + return value != null && !value.trim().isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.java new file mode 100644 index 0000000000..1bfd150afc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithSourcePropertyNameMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.ConditionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.SourcePropertyName; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousSourceParameterConditionalWithSourcePropertyNameMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) + default boolean isNotBlank(String value, @SourcePropertyName String sourceProperty) { + return value != null && !value.trim().isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.java new file mode 100644 index 0000000000..e9dac1ece5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetPropertyNameMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.ConditionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.TargetPropertyName; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousSourceParameterConditionalWithTargetPropertyNameMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) + default boolean isNotBlank(String value, @TargetPropertyName String targetProperty) { + return value != null && !value.trim().isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetTypeMapper.java new file mode 100644 index 0000000000..9ff55597ae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/basic/ErroneousSourceParameterConditionalWithTargetTypeMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conditional.basic; + +import org.mapstruct.Condition; +import org.mapstruct.ConditionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.TargetType; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface ErroneousSourceParameterConditionalWithTargetTypeMapper { + + BasicEmployee map(BasicEmployeeDto employee); + + @Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS) + default boolean isNotBlank(String value, @TargetType Class targetClass) { + return value != null && !value.trim().isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java index 0c92fc6bbe..f460180651 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/gem/EnumGemsTest.java @@ -11,12 +11,14 @@ import org.junit.jupiter.api.Test; import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.ConditionStrategy; import org.mapstruct.InjectionStrategy; import org.mapstruct.MappingInheritanceStrategy; import org.mapstruct.NullValueCheckStrategy; import org.mapstruct.NullValueMappingStrategy; import org.mapstruct.ReportingPolicy; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; +import org.mapstruct.ap.internal.gem.ConditionStrategyGem; import org.mapstruct.ap.internal.gem.InjectionStrategyGem; import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; @@ -67,6 +69,12 @@ public void injectionStrategyGemIsCorrect() { namesOf( InjectionStrategyGem.values() ) ); } + @Test + public void conditionStrategyGemIsCorrect() { + assertThat( namesOf( ConditionStrategy.values() ) ).isEqualTo( + namesOf( ConditionStrategyGem.values() ) ); + } + private static List namesOf(Enum[] values) { return Stream.of( values ) .map( Enum::name ) From b33942a0104af4b72554858ae2a21934ca759bc5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 29 Apr 2024 08:13:46 +0200 Subject: [PATCH 0820/1006] #3561 Add test case --- .../ap/test/bugs/_3561/Issue3561Mapper.java | 60 +++++++++++++++++++ .../ap/test/bugs/_3561/Issue3561Test.java | 35 +++++++++++ 2 files changed, 95 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Test.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Mapper.java new file mode 100644 index 0000000000..fd1137137b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Mapper.java @@ -0,0 +1,60 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3561; + +import org.mapstruct.Condition; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3561Mapper { + + Issue3561Mapper INSTANCE = Mappers.getMapper( Issue3561Mapper.class ); + + @Mapping(target = "value", conditionQualifiedByName = "shouldMapValue") + Target map(Source source, @Context boolean shouldMapValue); + + @Condition + @Named("shouldMapValue") + default boolean shouldMapValue(@Context boolean shouldMapValue) { + return shouldMapValue; + } + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Source { + + private String value; + private boolean valueInitialized; + + public String getValue() { + if ( valueInitialized ) { + return value; + } + + throw new IllegalStateException( "value is not initialized" ); + } + + public void setValue(String value) { + this.valueInitialized = true; + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Test.java new file mode 100644 index 0000000000..7cd0c26694 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3561/Issue3561Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3561; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3561Mapper.class) +@IssueKey("3561") +class Issue3561Test { + + @ProcessorTest + void shouldCorrectlyUseConditionWithContext() { + + Issue3561Mapper.Source source = new Issue3561Mapper.Source(); + + assertThatThrownBy( () -> Issue3561Mapper.INSTANCE.map( source, true ) ) + .isInstanceOf( IllegalStateException.class ) + .hasMessage( "value is not initialized" ); + + Issue3561Mapper.Target target = Issue3561Mapper.INSTANCE.map( source, false ); + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + } +} From 9a5e6b1892036d6485fe29e2c45bc68314d1300b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 May 2024 08:27:20 +0200 Subject: [PATCH 0821/1006] #3602 Automate release with JReleaser Add JReleaser for automating the release and add a step for automating the publishing of the website --- .github/scripts/update-website.sh | 76 ++++++++++++++++ .github/workflows/release.yml | 123 ++++++++++++++++++++++++++ NEXT_RELEASE_CHANGELOG.md | 29 ++++++ parent/pom.xml | 142 ++++++++++++++++++++++-------- pom.xml | 13 ++- 5 files changed, 345 insertions(+), 38 deletions(-) create mode 100644 .github/scripts/update-website.sh create mode 100644 .github/workflows/release.yml create mode 100644 NEXT_RELEASE_CHANGELOG.md diff --git a/.github/scripts/update-website.sh b/.github/scripts/update-website.sh new file mode 100644 index 0000000000..8fa989a1dd --- /dev/null +++ b/.github/scripts/update-website.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# +# Copyright MapStruct Authors. +# +# Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 +# + +# env vars: +# VERSION +# GH_BOT_EMAIL + +# This script has been inspired by the JReleaser update-website.sh (https://github.com/jreleaser/jreleaser/blob/main/.github/scripts/update-website.sh) +set -e + +function computePlainVersion() { + echo $1 | sed 's/\([[:digit:]]*\)\.\([[:digit:]]*\)\.\([[:digit:]]*\).*/\1.\2.\3/' +} + +function computeMajorMinorVersion() { + echo $1 | sed 's/\([[:digit:]]*\)\.\([[:digit:]]*\).*/\1.\2/' +} + +function isStable() { + local PLAIN_VERSION=$(computePlainVersion $1) + if [ "${PLAIN_VERSION}" == "$1" ]; then + echo "yes" + else + echo "no" + fi +} + +STABLE=$(isStable $VERSION) +MAJOR_MINOR_VERSION=$(computeMajorMinorVersion $VERSION) + +DEV_VERSION=`grep devVersion config.toml | sed 's/.*"\(.*\)"/\1/'` +MAJOR_MINOR_DEV_VERSION=$(computeMajorMinorVersion $DEV_VERSION) +STABLE_VERSION=`grep stableVersion config.toml | sed 's/.*"\(.*\)"/\1/'` +MAJOR_MINOR_STABLE_VERSION=$(computeMajorMinorVersion $STABLE_VERSION) + +echo "📝 Updating versions" +sed -i '' -e "s/^devVersion = \"\(.*\)\"/devVersion = \"${VERSION}\"/g" config.toml + +if [ "${STABLE}" == "yes" ]; then + sed -i '' -e "s/^stableVersion = \"\(.*\)\"/stableVersion = \"${VERSION}\"/g" config.toml + if [ "${MAJOR_MINOR_STABLE_VERSION}" != ${MAJOR_MINOR_VERSION} ]; then + echo "📝 Updating new stable version" + # This means that we have a new stable version and we need to change the order of the releases. + sed -i '' -e "s/^order = \(.*\)/order = 500/g" data/releases/${MAJOR_MINOR_VERSION}.toml + NEXT_STABLE_ORDER=$((`ls -1 data/releases | wc -l` - 2)) + sed -i '' -e "s/^order = \(.*\)/order = ${NEXT_STABLE_ORDER}/g" data/releases/${MAJOR_MINOR_STABLE_VERSION}.toml + git add data/releases/${MAJOR_MINOR_STABLE_VERSION}.toml + fi +elif [ "${MAJOR_MINOR_DEV_VERSION}" != "${MAJOR_MINOR_VERSION}" ]; then + echo "📝 Updating new dev version" + # This means that we are updating for a new dev version, but the last dev version is not the one that we are doing. + # Therefore, we need to update add the new data configuration + cp data/releases/${MAJOR_MINOR_DEV_VERSION}.toml data/releases/${MAJOR_MINOR_VERSION}.toml + sed -i '' -e "s/^order = \(.*\)/order = 1000/g" data/releases/${MAJOR_MINOR_VERSION}.toml +fi + +sed -i '' -e "s/^name = \"\(.*\)\"/name = \"${VERSION}\"/g" data/releases/${MAJOR_MINOR_VERSION}.toml +sed -i '' -e "s/^releaseDate = \(.*\)/releaseDate = $(date +%F)/g" data/releases/${MAJOR_MINOR_VERSION}.toml +git add data/releases/${MAJOR_MINOR_VERSION}.toml +git add config.toml + +echo "📝 Updating distribution resources" +tar -xf tmp/mapstruct-${VERSION}-dist.tar.gz --directory tmp +rm -rf static/documentation/${MAJOR_MINOR_VERSION} +cp -R tmp/mapstruct-${VERSION}/docs static/documentation/${MAJOR_MINOR_VERSION} +mv static/documentation/${MAJOR_MINOR_VERSION}/reference/html/mapstruct-reference-guide.html static/documentation/${MAJOR_MINOR_VERSION}/reference/html/index.html +git add static/documentation/${MAJOR_MINOR_VERSION} + +git config --global user.email "${GH_BOT_EMAIL}" +git config --global user.name "GitHub Action" +git commit -a -m "Releasing version ${VERSION}" +git push diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..5e4cddbeed --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,123 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version' + required: true + next: + description: 'Next version' + required: false + +env: + JAVA_VERSION: '11' + JAVA_DISTRO: 'zulu' + +jobs: + release: + # This job has been inspired by the moditect release (https://github.com/moditect/moditect/blob/main/.github/workflows/release.yml) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + java-version: ${{ vars.JAVA_VERSION }} + distribution: ${{ vars.JAVA_DISTRO }} + cache: maven + + - name: Set release version + id: version + run: | + RELEASE_VERSION=${{ github.event.inputs.version }} + NEXT_VERSION=${{ github.event.inputs.next }} + PLAIN_VERSION=`echo ${RELEASE_VERSION} | awk 'match($0, /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)/) { print substr($0, RSTART, RLENGTH); }'` + COMPUTED_NEXT_VERSION="${PLAIN_VERSION}-SNAPSHOT" + if [ -z $NEXT_VERSION ] + then + NEXT_VERSION=$COMPUTED_NEXT_VERSION + fi + ./mvnw -ntp -B versions:set versions:commit -DnewVersion=$RELEASE_VERSION -pl :mapstruct-parent -DgenerateBackupPoms=false + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.name "GitHub Action" + git commit -a -m "Releasing version $RELEASE_VERSION" + git push + echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV + echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_ENV + echo "PLAIN_VERSION=$PLAIN_VERSION" >> $GITHUB_ENV + + - name: Stage + run: | + export GPG_TTY=$(tty) + ./mvnw -ntp -B --file pom.xml \ + -Dmaven.site.skip=true -Drelease=true -Ppublication,stage + + - name: Release + env: + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + run: | + ./mvnw -ntp -B --file pom.xml -pl :mapstruct-parent -Pjreleaser jreleaser:release + + - name: JReleaser output + if: always() + uses: actions/upload-artifact@v4 + with: + name: jreleaser-release + path: | + parent/target/jreleaser/trace.log + parent/target/jreleaser/output.properties + + - name: Set next version + run: | + ./mvnw -ntp -B versions:set versions:commit -DnewVersion=${{ env.NEXT_VERSION }} -pl :mapstruct-parent -DgenerateBackupPoms=false + sed -i -e "s@project.build.outputTimestamp>.*\${git.commit.author.time} UTF-8 + + mapstruct/mapstruct + /tmp/repository + 1.8 + ${java.version} + ${java.version} + + ${git.commit.author.time} + 1.0.0.Alpha3 3.4.1 3.2.2 @@ -30,7 +39,7 @@ 8.36.1 5.10.1 2.2.0 - + 1.12.0 1 3.24.2 @@ -392,10 +401,6 @@ org.apache.maven.plugins maven-compiler-plugin 3.8.1 - - 1.8 - 1.8 - org.apache.maven.plugins @@ -410,11 +415,6 @@ true - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - org.apache.maven.plugins maven-enforcer-plugin @@ -461,21 +461,6 @@ 8 - - org.apache.maven.plugins - maven-release-plugin - 2.5.3 - - -DskipTests ${add.release.arguments} - clean install - false - true - @{project.version} - true - false - release - - org.apache.maven.plugins maven-resources-plugin @@ -522,6 +507,11 @@ + + org.codehaus.mojo + versions-maven-plugin + 2.16.2 + org.eclipse.m2e lifecycle-mapping @@ -663,6 +653,7 @@ maven-settings.xml readme.md CONTRIBUTING.md + NEXT_RELEASE_CHANGELOG.md .gitattributes .gitignore .factorypath @@ -791,12 +782,21 @@ + + org.codehaus.mojo + versions-maven-plugin + - release + publication + + + release + + @@ -823,18 +823,86 @@ + + + + + stage + + local::file:${maven.multiModuleProjectDirectory}/target/staging-deploy + + + deploy + + + + jreleaser + + - org.apache.maven.plugins - maven-gpg-plugin - - - sign-artifacts - verify - - sign - - - + org.jreleaser + jreleaser-maven-plugin + ${jreleaser.plugin.version} + + true + + + Mapstruct + + https://mapstruct.org/ + https://mapstruct.org/documentation/stable/reference/html/ + + + + ALWAYS + true + + + false + + + + + + ALWAYS + https://oss.sonatype.org/service/local + https://oss.sonatype.org/content/repositories/snapshots/ + true + true + ${maven.multiModuleProjectDirectory}/target/staging-deploy + + + org.mapstruct + mapstruct-jdk8 + false + false + + + + + + + + + {{projectVersion}} + {{projectVersion}} + + ${maven.multiModuleProjectDirectory}/NEXT_RELEASE_CHANGELOG.md + + + + + + + ${maven.multiModuleProjectDirectory}/distribution/target/mapstruct-{{projectVersion}}-dist.tar.gz + + + ${maven.multiModuleProjectDirectory}/distribution/target/mapstruct-{{projectVersion}}-dist.zip + + + + + diff --git a/pom.xml b/pom.xml index 25a5ead6bc..90402f0cae 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,6 @@ core core-jdk8 processor - integrationtest true @@ -71,5 +70,17 @@ distribution + + test + + + release + !true + + + + integrationtest + + From 8e53b4181fb76d992a5902d70afa5136768d4a41 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 May 2024 08:47:02 +0200 Subject: [PATCH 0822/1006] #3602 Fix setup-java action for release workflow --- .github/workflows/release.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5e4cddbeed..6dfd75a6f2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,10 +10,6 @@ on: description: 'Next version' required: false -env: - JAVA_VERSION: '11' - JAVA_DISTRO: 'zulu' - jobs: release: # This job has been inspired by the moditect release (https://github.com/moditect/moditect/blob/main/.github/workflows/release.yml) @@ -26,8 +22,8 @@ jobs: - name: Setup Java uses: actions/setup-java@v4 with: - java-version: ${{ vars.JAVA_VERSION }} - distribution: ${{ vars.JAVA_DISTRO }} + java-version: 11 + distribution: 'zulu' cache: maven - name: Set release version @@ -99,12 +95,6 @@ jobs: fetch-depth: 0 token: ${{ secrets.GIT_WEBSITE_ACCESS_TOKEN }} - - name: Setup Java - uses: actions/setup-java@v4 - with: - java-version: ${{ vars.JAVA_VERSION }} - distribution: ${{ vars.JAVA_DISTRO }} - - name: Download assets shell: bash run: | From 21a8b88a0f3cab99673d0bf94f11e5f731f00b90 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 07:01:58 +0000 Subject: [PATCH 0823/1006] Releasing version 1.6.0.Beta2 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..95be5f0b90 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..8830420981 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..7c8059144a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index afa8e31002..5c4a656d75 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..be0d7efe59 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f888e226ff..3e0fa3ec09 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e4109325f7..7acf7d5952 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-05-11T07:01:58Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 90402f0cae..ab4476277d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 12fc615f5f..7ce9548edf 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.Beta2 ../parent/pom.xml From 8a679b325d677ef93f7bda65c5a3da13b6aff524 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 07:10:47 +0000 Subject: [PATCH 0824/1006] Next version 1.6.0-SNAPSHOT --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 95be5f0b90..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 8830420981..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 7c8059144a..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 5c4a656d75..afa8e31002 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index be0d7efe59..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 3e0fa3ec09..f888e226ff 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 7acf7d5952..e4109325f7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-05-11T07:01:58Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index ab4476277d..90402f0cae 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 7ce9548edf..12fc615f5f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.Beta2 + 1.6.0-SNAPSHOT ../parent/pom.xml From baa02bf37725c2be8ca6ec8534170172c84583d9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 11 May 2024 09:32:27 +0200 Subject: [PATCH 0825/1006] #3602 Fix path for update-website.sh scrip in release workflow --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6dfd75a6f2..493fd2ad0c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,5 +109,5 @@ jobs: VERSION: ${{ github.event.inputs.version }} GH_BOT_EMAIL: ${{ vars.GH_BOT_EMAIL }} run: | - chmod +x update-website.sh - ./update-website.sh + chmod +x tmp/update-website.sh + tmp/update-website.sh From babb9dedd9cf3c9c75aa7e4c96a7bd24c40ed927 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 30 Jun 2024 14:47:27 +0200 Subject: [PATCH 0826/1006] #3602 Doing a release should reset NEXT_RELEASE_CHANGELOG.md --- .github/workflows/release.yml | 4 ++++ NEXT_RELEASE_CHANGELOG.md | 19 ------------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 493fd2ad0c..36cabf44f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -72,6 +72,10 @@ jobs: parent/target/jreleaser/trace.log parent/target/jreleaser/output.properties + - name: Reset NEXT_RELEASE_CHANGELOG.md + run: | + echo -e "### Features\n\n### Enhancements\n\n### Bugs\n\n### Documentation\n\n### Build\n" > NEXT_RELEASE_CHANGELOG.md + - name: Set next version run: | ./mvnw -ntp -B versions:set versions:commit -DnewVersion=${{ env.NEXT_VERSION }} -pl :mapstruct-parent -DgenerateBackupPoms=false diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index ed3f0e9c56..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,29 +1,10 @@ ### Features -* Support conditional mapping for source parameters (#2610, #3459, #3270) -* Add `@SourcePropertyName` to handle a property name of the source object (#3323) - Currently only applicable for `@Condition` methods - ### Enhancements -* Improve error message for mapping to `target = "."` using expression (#3485) -* Improve error messages for auto generated mappings (#2788) -* Remove unnecessary casts to long (#3400) - ### Bugs -* `@Condition` cannot be used only with `@Context` parameters (#3561) -* `@Condition` treated as ambiguous mapping for methods returning Boolean/boolean (#3565) -* Subclass mapping warns about unmapped property that is mapped in referenced mapper (#3360) -* Interface inherited build method is not found (#3463) -* Bean with getter returning Stream is treating the Stream as an alternative setter (#3462) -* Using `Mapping#expression` and `Mapping#conditionalQualifiedBy(Name)` should lead to compile error (#3413) -* Defined mappings for subclass mappings with runtime exception subclass exhaustive strategy not working if result type is abstract class (#3331) - ### Documentation -* Clarify that `Mapping#ignoreByDefault` is inherited in nested mappings in documentation (#3577) - ### Build -* Improve tests to show that Lombok `@SuperBuilder` is supported (#3524) -* Add Java 21 CI matrix build (#3473) From 69371708ee9371bdaf4267529f45b9122df80c62 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 6 Jul 2024 10:31:32 +0200 Subject: [PATCH 0827/1006] #3574 Respect only explicit mappings but fail on unmapped source fields * #3574 Respect only explicit mappings but fail on unmapped source fields This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties. Source properties are anyway ignored, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy --- NEXT_RELEASE_CHANGELOG.md | 4 ++++ .../ap/internal/model/BeanMappingMethod.java | 4 ---- ...neousSourceTargetMapperWithIgnoreByDefault.java} | 5 +++-- .../IgnoreByDefaultSourcesTest.java | 13 +++++++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/{SourceTargetMapper.java => ErroneousSourceTargetMapperWithIgnoreByDefault.java} (74%) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index e0f4cd31f0..a6c424b08e 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -2,6 +2,10 @@ ### Enhancements +* Breaking change:g (#3574) - +This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties. +Source properties are ignored anyway, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy + ### Bugs ### Documentation diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index cf5179f9cb..b437afadc0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1764,10 +1764,6 @@ private ReportingPolicyGem getUnmappedSourcePolicy() { if ( mappingReferences.isForForgedMethods() ) { return ReportingPolicyGem.IGNORE; } - // If we have ignoreByDefault = true, unprocessed source properties are not an issue. - if ( method.getOptions().getBeanMapping().isignoreByDefault() ) { - return ReportingPolicyGem.IGNORE; - } return method.getOptions().getBeanMapping().unmappedSourcePolicy(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapperWithIgnoreByDefault.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapperWithIgnoreByDefault.java index e029bd7391..459e2f426a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/ErroneousSourceTargetMapperWithIgnoreByDefault.java @@ -14,8 +14,9 @@ @Mapper( unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.ERROR) -public interface SourceTargetMapper { - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); +public interface ErroneousSourceTargetMapperWithIgnoreByDefault { + ErroneousSourceTargetMapperWithIgnoreByDefault INSTANCE = Mappers.getMapper( + ErroneousSourceTargetMapperWithIgnoreByDefault.class ); @Mapping(source = "one", target = "one") @BeanMapping(ignoreByDefault = true) diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java index 98f2cde4c0..fce6d49648 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/ignorebydefaultsource/IgnoreByDefaultSourcesTest.java @@ -18,8 +18,17 @@ public class IgnoreByDefaultSourcesTest { @ProcessorTest - @WithClasses({ SourceTargetMapper.class, Source.class, Target.class }) - public void shouldSucceed() { + @WithClasses({ ErroneousSourceTargetMapperWithIgnoreByDefault.class, Source.class, Target.class }) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousSourceTargetMapperWithIgnoreByDefault.class, + kind = Kind.ERROR, + line = 23, + message = "Unmapped source property: \"other\".") + } + ) + public void shouldRaiseErrorDueToNonIgnoredSourcePropertyWithBeanMappingIgnoreByDefault() { } @ProcessorTest From 037da5a1e1f450f670fa934640ee40ed67f0f781 Mon Sep 17 00:00:00 2001 From: Connor McGowan <53909969+cmcgowanprovidertrust@users.noreply.github.com> Date: Sun, 7 Jul 2024 14:19:38 -0500 Subject: [PATCH 0828/1006] #3635 Fix documentation of unmappedSourcePolicy default (#3637) --- documentation/src/main/asciidoc/chapter-2-set-up.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 666954c4b1..58759ff8e0 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -261,7 +261,7 @@ Supported values are: If a policy is given for a specific mapper via `@Mapper#unmappedSourcePolicy()`, the value from the annotation takes precedence. If a policy is given for a specific bean mapping via `@BeanMapping#ignoreUnmappedSourceProperties()`, it takes precedence over both `@Mapper#unmappedSourcePolicy()` and the option. -|`WARN` +|`IGNORE` |`mapstruct. disableBuilders` From 8fa2f40944b3a143a987a17448473eec2f78f076 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 15 Jul 2024 23:18:32 +0200 Subject: [PATCH 0829/1006] Enforce whitespaces around the for colon with CheckStyle (#3642) --- build-config/src/main/resources/build-config/checkstyle.xml | 4 +++- .../org/mapstruct/ap/internal/model/BeanMappingMethod.java | 2 +- .../ap/test/conversion/_enum/EnumToIntegerConversionTest.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index a1ff4af23a..71a7d35899 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -146,7 +146,9 @@ - + + + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b437afadc0..6535b07012 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -152,7 +152,7 @@ public Builder forgedMethod(ForgedMethod forgedMethod) { method( forgedMethod ); mappingReferences = forgedMethod.getMappingReferences(); Parameter sourceParameter = first( Parameter.getSourceParameters( forgedMethod.getParameters() ) ); - for ( MappingReference mappingReference: mappingReferences.getMappingReferences() ) { + for ( MappingReference mappingReference : mappingReferences.getMappingReferences() ) { SourceReference sourceReference = mappingReference.getSourceReference(); if ( sourceReference != null ) { mappingReference.setSourceReference( new SourceReference.BuilderFromSourceReference() diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java index 1302c22bc9..67d99dfbc6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/EnumToIntegerConversionTest.java @@ -30,7 +30,7 @@ public class EnumToIntegerConversionTest { public void shouldApplyEnumToIntegerConversion() { EnumToIntegerSource source = new EnumToIntegerSource(); - for ( EnumToIntegerEnum value: EnumToIntegerEnum.values() ) { + for ( EnumToIntegerEnum value : EnumToIntegerEnum.values() ) { source.setEnumValue( value ); EnumToIntegerTarget target = EnumToIntegerMapper.INSTANCE.sourceToTarget( source ); From eef3bdfca4037735507ef3776568b49201ca4906 Mon Sep 17 00:00:00 2001 From: thunderhook <8238759+thunderhook@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:54:06 +0200 Subject: [PATCH 0830/1006] #3639 fix documentation link --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 2174822359..ed64580eb4 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -448,7 +448,7 @@ E.g. If an object factory exists for our `PersonBuilder` then this factory would [NOTE] ====== -Detected builders influence `@BeforeMapping` and `@AfterMapping` behavior. See chapter `Mapping customization with before-mapping and after-mapping methods` for more information. +Detected builders influence `@BeforeMapping` and `@AfterMapping` behavior. See <> for more information. ====== .Person with Builder example From 52877d36c2e227e639fbca43d268174f4fa68bc6 Mon Sep 17 00:00:00 2001 From: thunderhook <8238759+thunderhook@users.noreply.github.com> Date: Sun, 7 Jul 2024 13:49:52 +0200 Subject: [PATCH 0831/1006] #3634 fix typo in experimental note --- .../java/org/mapstruct/ap/spi/EnumMappingStrategy.java | 2 +- .../org/mapstruct/ap/spi/EnumTransformationStrategy.java | 2 +- .../org/mapstruct/ap/spi/MappingExclusionProvider.java | 9 ++++----- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java index 97088cd8c6..8ad6737c63 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumMappingStrategy.java @@ -17,7 +17,7 @@ * * @since 1.4 */ -@Experimental("This SPI can have it's signature changed in subsequent releases") +@Experimental("This SPI can have its signature changed in subsequent releases") public interface EnumMappingStrategy { /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java index 2c498fc3a8..796bdb4954 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/EnumTransformationStrategy.java @@ -13,7 +13,7 @@ * @author Filip Hrisafov * @since 1.4 */ -@Experimental("This SPI can have it's signature changed in subsequent releases") +@Experimental("This SPI can have its signature changed in subsequent releases") public interface EnumTransformationStrategy { /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java index afd7e69511..9dae81cda2 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java @@ -12,10 +12,10 @@ /** * A service provider interface that is used to control if MapStruct is allowed to generate automatic sub-mapping for * a given {@link TypeElement}. - * + *

      * When generating the implementation of a mapping method, MapStruct will apply the following routine for each * attribute pair in the source and target object: - * + *

      *

        *
      • If source and target attribute have the same type, the value will be simply copied from source to target. * If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target @@ -30,14 +30,14 @@ *
      • If MapStruct could not create a name based mapping method an error will be raised at build time, * indicating the non-mappable attribute and its path.
      • *
      - * + *

      * With this SPI the last step before raising an error can be controlled. i.e. A user can control whether MapStruct * is allowed to generate such automatic sub-mapping method (for the source or target type) or not. * * @author Filip Hrisafov * @since 1.2 */ -@Experimental("This SPI can have it's signature changed in subsequent releases") +@Experimental("This SPI can have its signature changed in subsequent releases") public interface MappingExclusionProvider { /** @@ -46,7 +46,6 @@ public interface MappingExclusionProvider { * The given {@code typeElement} will be excluded from the automatic sub-mapping generation * * @param typeElement that needs to be checked - * * @return {@code true} if MapStruct should exclude the provided {@link TypeElement} from an automatic sub-mapping */ boolean isExcluded(TypeElement typeElement); From 66f4288842460f27b88ba4580cd5384551127d61 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Jul 2024 13:53:39 +0200 Subject: [PATCH 0832/1006] #3601 Always use SourceParameterCondition when checking source parameter This is a breaking change, with this change whenever a source parameter is used as a source for a target property the condition has to apply to source parameters and not properties --- NEXT_RELEASE_CHANGELOG.md | 68 +++++++++ .../source/selector/SelectionCriteria.java | 129 ++++++++++++------ .../ap/test/bugs/_3601/Issue3601Mapper.java | 50 +++++++ .../ap/test/bugs/_3601/Issue3601Test.java | 47 +++++++ ...itionalMethodWithSourceToTargetMapper.java | 6 +- 5 files changed, 252 insertions(+), 48 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Test.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index a6c424b08e..305bdda947 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -8,7 +8,75 @@ Source properties are ignored anyway, the `BeanMapping#unmappedSourcePolicy` sho ### Bugs +* Breaking change: Presence check method used only once when multiple source parameters are provided (#3601) + ### Documentation ### Build +## Breaking changes + +### Presence checks for source parameters + +In 1.6, support for presence checks on source parameters has been added. +This means that even if you want to map a source parameter directly to some target property the new `@SourceParameterCondition` or `@Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS)` should be used. + +e.g. + +If we had the following in 1.5: +```java +@Mapper +public interface OrderMapper { + + @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder") + Order map(OrderDTO dto); + + @Condition + @Named("mapCustomerFromOrder") + default boolean mapCustomerFromOrder(OrderDTO dto) { + return dto != null && dto.getCustomerName() != null; + } + +} +``` + +Them MapStruct would generate + +```java +public class OrderMapperImpl implements OrderMapper { + + @Override + public Order map(OrderDTO dto) { + if ( dto == null ) { + return null; + } + + Order order = new Order(); + + if ( mapCustomerFromOrder( dto ) ) { + order.setCustomer( orderDtoToCustomer( orderDTO ) ); + } + + return order; + } +} +``` + +In order for the same to be generated in 1.6, the mapper needs to look like this: + +```java +@Mapper +public interface OrderMapper { + + @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder") + Order map(OrderDTO dto); + + @SourceParameterCondition + @Named("mapCustomerFromOrder") + default boolean mapCustomerFromOrder(OrderDTO dto) { + return dto != null && dto.getCustomerName() != null; + } + +} +``` + diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java index fa5e1c29c0..ecc9ac9e01 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionCriteria.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.internal.model.source.selector; -import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -22,50 +21,31 @@ */ public class SelectionCriteria { - private final List qualifiers = new ArrayList<>(); - private final List qualifiedByNames = new ArrayList<>(); + private final QualifyingInfo qualifyingInfo; private final String targetPropertyName; - private final TypeMirror qualifyingResultType; private final SourceRHS sourceRHS; private boolean ignoreQualifiers = false; private Type type; - private final boolean allowDirect; - private final boolean allowConversion; - private final boolean allowMappingMethod; - private final boolean allow2Steps; + private final MappingControl mappingControl; public SelectionCriteria(SelectionParameters selectionParameters, MappingControl mappingControl, String targetPropertyName, Type type) { - if ( selectionParameters != null ) { - if ( type == Type.PRESENCE_CHECK ) { - qualifiers.addAll( selectionParameters.getConditionQualifiers() ); - qualifiedByNames.addAll( selectionParameters.getConditionQualifyingNames() ); - } - else { - qualifiers.addAll( selectionParameters.getQualifiers() ); - qualifiedByNames.addAll( selectionParameters.getQualifyingNames() ); - } - qualifyingResultType = selectionParameters.getResultType(); - sourceRHS = selectionParameters.getSourceRHS(); - } - else { - this.qualifyingResultType = null; - sourceRHS = null; - } - if ( mappingControl != null ) { - this.allowDirect = mappingControl.allowDirect(); - this.allowConversion = mappingControl.allowTypeConversion(); - this.allowMappingMethod = mappingControl.allowMappingMethod(); - this.allow2Steps = mappingControl.allowBy2Steps(); - } - else { - this.allowDirect = true; - this.allowConversion = true; - this.allowMappingMethod = true; - this.allow2Steps = true; - } + this( + QualifyingInfo.fromSelectionParameters( selectionParameters ), + selectionParameters != null ? selectionParameters.getSourceRHS() : null, + mappingControl, + targetPropertyName, + type + ); + } + + private SelectionCriteria(QualifyingInfo qualifyingInfo, SourceRHS sourceRHS, MappingControl mappingControl, + String targetPropertyName, Type type) { + this.qualifyingInfo = qualifyingInfo; this.targetPropertyName = targetPropertyName; + this.sourceRHS = sourceRHS; this.type = type; + this.mappingControl = mappingControl; } /** @@ -109,11 +89,11 @@ public void setIgnoreQualifiers(boolean ignoreQualifiers) { } public List getQualifiers() { - return ignoreQualifiers ? Collections.emptyList() : qualifiers; + return ignoreQualifiers ? Collections.emptyList() : qualifyingInfo.qualifiers(); } public List getQualifiedByNames() { - return ignoreQualifiers ? Collections.emptyList() : qualifiedByNames; + return ignoreQualifiers ? Collections.emptyList() : qualifyingInfo.qualifiedByNames(); } public String getTargetPropertyName() { @@ -121,7 +101,7 @@ public String getTargetPropertyName() { } public TypeMirror getQualifyingResultType() { - return qualifyingResultType; + return qualifyingInfo.qualifyingResultType(); } public boolean isPreferUpdateMapping() { @@ -137,23 +117,23 @@ public void setPreferUpdateMapping(boolean preferUpdateMapping) { } public boolean hasQualfiers() { - return !qualifiedByNames.isEmpty() || !qualifiers.isEmpty(); + return !qualifyingInfo.qualifiedByNames().isEmpty() || !qualifyingInfo.qualifiers().isEmpty(); } public boolean isAllowDirect() { - return allowDirect; + return mappingControl == null || mappingControl.allowDirect(); } public boolean isAllowConversion() { - return allowConversion; + return mappingControl == null || mappingControl.allowTypeConversion(); } public boolean isAllowMappingMethod() { - return allowMappingMethod; + return mappingControl == null || mappingControl.allowMappingMethod(); } public boolean isAllow2Steps() { - return allow2Steps; + return mappingControl == null || mappingControl.allowBy2Steps(); } public boolean isSelfAllowed() { @@ -181,7 +161,22 @@ public static SelectionCriteria forLifecycleMethods(SelectionParameters selectio } public static SelectionCriteria forPresenceCheckMethods(SelectionParameters selectionParameters) { - return new SelectionCriteria( selectionParameters, null, null, Type.PRESENCE_CHECK ); + SourceRHS sourceRHS = selectionParameters.getSourceRHS(); + Type type; + QualifyingInfo qualifyingInfo = new QualifyingInfo( + selectionParameters.getConditionQualifiers(), + selectionParameters.getConditionQualifyingNames(), + selectionParameters.getResultType() + ); + if ( sourceRHS != null && sourceRHS.isSourceReferenceParameter() ) { + // If the source reference is for a source parameter, + // then the presence check should be for the source parameter + type = Type.SOURCE_PARAMETER_CHECK; + } + else { + type = Type.PRESENCE_CHECK; + } + return new SelectionCriteria( qualifyingInfo, sourceRHS, null, null, type ); } public static SelectionCriteria forSourceParameterCheckMethods(SelectionParameters selectionParameters) { @@ -193,6 +188,50 @@ public static SelectionCriteria forSubclassMappingMethods(SelectionParameters se return new SelectionCriteria( selectionParameters, mappingControl, null, Type.SELF_NOT_ALLOWED ); } + private static class QualifyingInfo { + + private static final QualifyingInfo EMPTY = new QualifyingInfo( + Collections.emptyList(), + Collections.emptyList(), + null + ); + + private final List qualifiers; + private final List qualifiedByNames; + private final TypeMirror qualifyingResultType; + + private QualifyingInfo(List qualifiers, List qualifiedByNames, + TypeMirror qualifyingResultType) { + this.qualifiers = qualifiers; + this.qualifiedByNames = qualifiedByNames; + this.qualifyingResultType = qualifyingResultType; + } + + public List qualifiers() { + return qualifiers; + } + + public List qualifiedByNames() { + return qualifiedByNames; + } + + public TypeMirror qualifyingResultType() { + return qualifyingResultType; + } + + private static QualifyingInfo fromSelectionParameters(SelectionParameters selectionParameters) { + if ( selectionParameters == null ) { + return EMPTY; + } + return new QualifyingInfo( + selectionParameters.getQualifiers(), + selectionParameters.getQualifyingNames(), + selectionParameters.getResultType() + ); + } + } + + public enum Type { PREFER_UPDATE_MAPPING, OBJECT_FACTORY, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Mapper.java new file mode 100644 index 0000000000..851e353de7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Mapper.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3601; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SourceParameterCondition; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3601Mapper { + + Issue3601Mapper INSTANCE = Mappers.getMapper( Issue3601Mapper.class ); + + @Mapping(target = "currentId", source = "source.uuid") + @Mapping(target = "targetIds", source = "sourceIds") + Target map(Source source, List sourceIds); + + @SourceParameterCondition + default boolean isNotEmpty(List elements) { + return elements != null && !elements.isEmpty(); + } + + class Source { + private final String uuid; + + public Source(String uuid) { + this.uuid = uuid; + } + + public String getUuid() { + return uuid; + } + } + + class Target { + //CHECKSTYLE:OFF + public String currentId; + public List targetIds; + //CHECKSTYLE:ON + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Test.java new file mode 100644 index 0000000000..b9b68fb583 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3601/Issue3601Test.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3601; + +import java.util.Collections; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3601") +class Issue3601Test { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses( Issue3601Mapper.class ) + void shouldUseSourceParameterPresenceCheckCorrectly() { + Issue3601Mapper.Target target = Issue3601Mapper.INSTANCE.map( + new Issue3601Mapper.Source( "test1" ), + Collections.emptyList() + ); + + assertThat( target ).isNotNull(); + assertThat( target.currentId ).isEqualTo( "test1" ); + assertThat( target.targetIds ).isNull(); + + target = Issue3601Mapper.INSTANCE.map( + null, + Collections.emptyList() + ); + + assertThat( target ).isNull(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java index 35864fe62c..6577a6fd95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conditional/qualifier/ConditionalMethodWithSourceToTargetMapper.java @@ -5,10 +5,10 @@ */ package org.mapstruct.ap.test.conditional.qualifier; -import org.mapstruct.Condition; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; +import org.mapstruct.SourceParameterCondition; import org.mapstruct.factory.Mappers; /** @@ -29,13 +29,13 @@ public interface ConditionalMethodWithSourceToTargetMapper { Address convertToAddress(OrderDTO orderDTO); - @Condition + @SourceParameterCondition @Named("mapCustomerFromOrder") default boolean mapCustomerFromOrder(OrderDTO orderDTO) { return orderDTO != null && ( orderDTO.getCustomerName() != null || mapAddressFromOrder( orderDTO ) ); } - @Condition + @SourceParameterCondition @Named("mapAddressFromOrder") default boolean mapAddressFromOrder(OrderDTO orderDTO) { return orderDTO != null && ( orderDTO.getLine1() != null || orderDTO.getLine2() != null ); From df49ce5ff93fce8c062263a8d56594e776dc0a3a Mon Sep 17 00:00:00 2001 From: Obolrom <65775868+Obolrom@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:06:49 +0300 Subject: [PATCH 0833/1006] #3609 Pass bean mapping ignored unmapped source properties to subclass forged methods Co-authored-by: thunderhook <8238759+thunderhook@users.noreply.github.com> --- .../ap/internal/model/ForgedMethod.java | 21 ++++++++- .../model/source/BeanMappingOptions.java | 11 +++++ .../model/source/MappingMethodOptions.java | 13 ++++++ .../ap/test/bugs/_3609/Issue3609Mapper.java | 43 +++++++++++++++++++ .../ap/test/bugs/_3609/Issue3609Test.java | 23 ++++++++++ 5 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3609/Issue3609Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3609/Issue3609Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java index a33bc7520e..2aa12687d8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ForgedMethod.java @@ -146,13 +146,30 @@ public static ForgedMethod forSubclassMapping(String name, Type sourceType, Type basedOn, history, mappingReferences == null ? MappingReferences.empty() : mappingReferences, - forgedNameBased + forgedNameBased, + MappingMethodOptions.getSubclassForgedMethodInheritedOptions( basedOn.getOptions() ) ); } private ForgedMethod(String name, Type sourceType, Type returnType, List additionalParameters, Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences, boolean forgedNameBased) { + this( + name, + sourceType, + returnType, + additionalParameters, + basedOn, + history, + mappingReferences, + forgedNameBased, + MappingMethodOptions.getForgedMethodInheritedOptions( basedOn.getOptions() ) + ); + } + + private ForgedMethod(String name, Type sourceType, Type returnType, List additionalParameters, + Method basedOn, ForgedMethodHistory history, MappingReferences mappingReferences, + boolean forgedNameBased, MappingMethodOptions options) { // establish name String sourceParamSafeName; @@ -185,7 +202,7 @@ private ForgedMethod(String name, Type sourceType, Type returnType, List Date: Sat, 20 Jul 2024 16:19:59 +0200 Subject: [PATCH 0834/1006] #3591 Fix duplicate method generation with recursive auto mapping --- .../internal/model/AbstractBaseBuilder.java | 30 ++++--- .../model/ContainerMappingMethod.java | 3 +- .../ap/internal/model/PropertyMapping.java | 9 +- .../model/source/BeanMappingOptions.java | 4 +- .../model/source/IterableMappingOptions.java | 13 ++- .../model/source/MapMappingOptions.java | 4 +- .../internal/model/source/MappingOptions.java | 2 +- .../model/source/SelectionParameters.java | 15 ++++ .../mapstruct/ap/test/bugs/_3591/Bean.java | 36 ++++++++ .../mapstruct/ap/test/bugs/_3591/BeanDto.java | 30 +++++++ .../ap/test/bugs/_3591/BeanMapper.java | 21 +++++ .../ap/test/bugs/_3591/ContainerBean.java | 47 ++++++++++ .../ap/test/bugs/_3591/ContainerBeanDto.java | 40 +++++++++ .../test/bugs/_3591/ContainerBeanMapper.java | 22 +++++ .../ap/test/bugs/_3591/Issue3591Test.java | 79 +++++++++++++++++ .../bugs/_3591/ContainerBeanMapperImpl.java | 85 +++++++++++++++++++ 16 files changed, 416 insertions(+), 24 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Bean.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBean.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Issue3591Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index ba13854667..311cc00368 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model; +import java.util.function.Supplier; import javax.lang.model.element.AnnotationMirror; import org.mapstruct.ap.internal.model.common.Assignment; @@ -74,16 +75,9 @@ private boolean isDisableSubMappingMethodsGeneration() { */ Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, ForgedMethod forgedMethod) { - if ( ctx.getForgedMethodsUnderCreation().containsKey( forgedMethod ) ) { - return createAssignment( sourceRHS, ctx.getForgedMethodsUnderCreation().get( forgedMethod ) ); - } - else { - ctx.getForgedMethodsUnderCreation().put( forgedMethod, forgedMethod ); - } - - MappingMethod forgedMappingMethod; + Supplier forgedMappingMethodCreator; if ( MappingMethodUtils.isEnumMapping( forgedMethod ) ) { - forgedMappingMethod = new ValueMappingMethod.Builder() + forgedMappingMethodCreator = () -> new ValueMappingMethod.Builder() .method( forgedMethod ) .valueMappings( forgedMethod.getOptions().getValueMappings() ) .enumMapping( forgedMethod.getOptions().getEnumMappingOptions() ) @@ -91,15 +85,31 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, .build(); } else { - forgedMappingMethod = new BeanMappingMethod.Builder() + forgedMappingMethodCreator = () -> new BeanMappingMethod.Builder() .forgedMethod( forgedMethod ) .returnTypeBuilder( builderType ) .mappingContext( ctx ) .build(); } + return getOrCreateForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethodCreator ); + } + + Assignment getOrCreateForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod, + Supplier mappingMethodCreator) { + + if ( ctx.getForgedMethodsUnderCreation().containsKey( forgedMethod ) ) { + return createAssignment( sourceRHS, ctx.getForgedMethodsUnderCreation().get( forgedMethod ) ); + } + else { + ctx.getForgedMethodsUnderCreation().put( forgedMethod, forgedMethod ); + } + + MappingMethod forgedMappingMethod = mappingMethodCreator.get(); + Assignment forgedAssignment = createForgedAssignment( sourceRHS, forgedMethod, forgedMappingMethod ); ctx.getForgedMethodsUnderCreation().remove( forgedMethod ); + return forgedAssignment; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java index 7ecb7b0ed1..9e7e64fefa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ContainerMappingMethod.java @@ -46,7 +46,8 @@ public abstract class ContainerMappingMethod extends NormalTypeMappingMethod { afterMappingReferences ); this.elementAssignment = parameterAssignment; this.loopVariableName = loopVariableName; - this.selectionParameters = selectionParameters; + this.selectionParameters = selectionParameters != null ? selectionParameters : SelectionParameters.empty(); + this.index1Name = Strings.getSafeVariableName( "i", existingVariables ); this.index2Name = Strings.getSafeVariableName( "j", existingVariables ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 2f30957962..db14ccbd8e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.Supplier; import javax.lang.model.element.AnnotationMirror; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -746,7 +747,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou targetType = targetType.withoutBounds(); ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "[]" ); - ContainerMappingMethod iterableMappingMethod = builder + Supplier mappingMethodCreator = () -> builder .mappingContext( ctx ) .method( methodRef ) .selectionParameters( selectionParameters ) @@ -754,7 +755,7 @@ private Assignment forgeWithElementMapping(Type sourceType, Type targetType, Sou .positionHint( positionHint ) .build(); - return createForgedAssignment( source, methodRef, iterableMappingMethod ); + return getOrCreateForgedAssignment( source, methodRef, mappingMethodCreator ); } private ForgedMethod prepareForgedMethod(Type sourceType, Type targetType, SourceRHS source, String suffix) { @@ -772,12 +773,12 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "{}" ); MapMappingMethod.Builder builder = new MapMappingMethod.Builder(); - MapMappingMethod mapMappingMethod = builder + Supplier mapMappingMethodCreator = () -> builder .mappingContext( ctx ) .method( methodRef ) .build(); - return createForgedAssignment( source, methodRef, mapMappingMethod ); + return getOrCreateForgedAssignment( source, methodRef, mapMappingMethodCreator ); } private Assignment forgeMapping(SourceRHS sourceRHS) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index a31000e8b4..bc19860bb5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -58,7 +58,7 @@ public static BeanMappingOptions forInheritance(BeanMappingOptions beanMapping, public static BeanMappingOptions forForgedMethods(BeanMappingOptions beanMapping) { BeanMappingOptions options = new BeanMappingOptions( beanMapping.selectionParameters != null ? - SelectionParameters.withoutResultType( beanMapping.selectionParameters ) : null, + SelectionParameters.withoutResultType( beanMapping.selectionParameters ) : SelectionParameters.empty(), Collections.emptyList(), beanMapping.beanMapping, beanMapping @@ -78,7 +78,7 @@ public static BeanMappingOptions forSubclassForgedMethods(BeanMappingOptions bea } public static BeanMappingOptions empty(DelegatingOptions delegatingOptions) { - return new BeanMappingOptions( null, Collections.emptyList(), null, delegatingOptions ); + return new BeanMappingOptions( SelectionParameters.empty(), Collections.emptyList(), null, delegatingOptions ); } public static BeanMappingOptions getInstanceOn(BeanMappingGem beanMapping, MapperOptions mapperOptions, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index 4affcd93e2..c4770efde6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -8,14 +8,14 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.gem.IterableMappingGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.tools.gem.GemValue; /** @@ -34,7 +34,12 @@ public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, FormattingMessager messager, TypeUtils typeUtils) { if ( iterableMapping == null || !isConsistent( iterableMapping, method, messager ) ) { - IterableMappingOptions options = new IterableMappingOptions( null, null, null, mapperOptions ); + IterableMappingOptions options = new IterableMappingOptions( + null, + SelectionParameters.empty(), + null, + mapperOptions + ); return options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index ca8f1ea544..fd1758d8d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -38,9 +38,9 @@ public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions if ( mapMapping == null || !isConsistent( mapMapping, method, messager ) ) { MapMappingOptions options = new MapMappingOptions( null, + SelectionParameters.empty(), null, - null, - null, + SelectionParameters.empty(), null, mapperOptions ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index e0994d746f..24a94137f1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -182,7 +182,7 @@ public static MappingOptions forIgnore(String targetName) { null, true, null, - null, + SelectionParameters.empty(), Collections.emptySet(), null, null, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java index 7237668e2c..4706d219cb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SelectionParameters.java @@ -21,6 +21,16 @@ */ public class SelectionParameters { + private static final SelectionParameters EMPTY = new SelectionParameters( + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), + Collections.emptyList(), + null, + null, + null + ); + private final List qualifiers; private final List qualifyingNames; private final List conditionQualifiers; @@ -225,4 +235,9 @@ public static SelectionParameters forSourceRHS(SourceRHS sourceRHS) { sourceRHS ); } + + public static SelectionParameters empty() { + return EMPTY; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Bean.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Bean.java new file mode 100644 index 0000000000..7da423c906 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Bean.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.List; + +public class Bean { + private List beans; + private String value; + + public Bean() { + } + + public Bean(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public List getBeans() { + return beans; + } + + public void setBeans(List beans) { + this.beans = beans; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanDto.java new file mode 100644 index 0000000000..00e70ff228 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanDto.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.List; + +public class BeanDto { + + private List beans; + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public List getBeans() { + return beans; + } + + public void setBeans(List beans) { + this.beans = beans; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanMapper.java new file mode 100644 index 0000000000..eeb54b4710 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/BeanMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BeanMapper { + + BeanMapper INSTANCE = Mappers.getMapper( BeanMapper.class ); + + @Mapping(source = "beans", target = "beans") + BeanDto map(Bean bean, @MappingTarget BeanDto beanDto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBean.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBean.java new file mode 100644 index 0000000000..b0e68ecfcf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBean.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.Map; +import java.util.stream.Stream; + +public class ContainerBean { + + private String value; + private Map beanMap; + private Stream beanStream; + + public ContainerBean() { + } + + public ContainerBean(String value) { + this.value = value; + } + + public Map getBeanMap() { + return beanMap; + } + + public void setBeanMap(Map beanMap) { + this.beanMap = beanMap; + } + + public Stream getBeanStream() { + return beanStream; + } + + public void setBeanStream(Stream beanStream) { + this.beanStream = beanStream; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanDto.java new file mode 100644 index 0000000000..86bb0193ac --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanDto.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.Map; +import java.util.stream.Stream; + +public class ContainerBeanDto { + + private String value; + private Map beanMap; + private Stream beanStream; + + public Map getBeanMap() { + return beanMap; + } + + public void setBeanMap(Map beanMap) { + this.beanMap = beanMap; + } + + public Stream getBeanStream() { + return beanStream; + } + + public void setBeanStream(Stream beanStream) { + this.beanStream = beanStream; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapper.java new file mode 100644 index 0000000000..0da338aadf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ContainerBeanMapper { + + ContainerBeanMapper INSTANCE = Mappers.getMapper( ContainerBeanMapper.class ); + + @Mapping(source = "beanMap", target = "beanMap") + @Mapping(source = "beanStream", target = "beanStream") + ContainerBeanDto mapWithMapMapping(ContainerBean containerBean, @MappingTarget ContainerBeanDto containerBeanDto); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Issue3591Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Issue3591Test.java new file mode 100644 index 0000000000..15bb191ffc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3591/Issue3591Test.java @@ -0,0 +1,79 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3591") +class Issue3591Test { + + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses({ + BeanDto.class, + Bean.class, + BeanMapper.class + }) + void mapNestedBeansWithMappingAnnotation() { + Bean bean = new Bean( "parent" ); + Bean child = new Bean( "child" ); + bean.setBeans( Collections.singletonList( child ) ); + + BeanDto beanDto = BeanMapper.INSTANCE.map( bean, new BeanDto() ); + + assertThat( beanDto ).isNotNull(); + assertThat( beanDto.getValue() ).isEqualTo( "parent" ); + assertThat( beanDto.getBeans() ) + .extracting( BeanDto::getValue ) + .containsExactly( "child" ); + } + + @ProcessorTest + @WithClasses({ + ContainerBean.class, + ContainerBeanDto.class, + ContainerBeanMapper.class, + }) + void shouldMapNestedMapAndStream() { + generatedSource.addComparisonToFixtureFor( ContainerBeanMapper.class ); + + ContainerBean containerBean = new ContainerBean( "parent" ); + Map beanMap = new HashMap<>(); + beanMap.put( "child", new ContainerBean( "mapChild" ) ); + containerBean.setBeanMap( beanMap ); + + Stream streamChild = Stream.of( new ContainerBean( "streamChild" ) ); + containerBean.setBeanStream( streamChild ); + + ContainerBeanDto dto = ContainerBeanMapper.INSTANCE.mapWithMapMapping( containerBean, new ContainerBeanDto() ); + + assertThat( dto ).isNotNull(); + + assertThat( dto.getBeanMap() ) + .extractingByKey( "child" ) + .extracting( ContainerBeanDto::getValue ) + .isEqualTo( "mapChild" ); + + assertThat( dto.getBeanStream() ) + .singleElement() + .extracting( ContainerBeanDto::getValue ) + .isEqualTo( "streamChild" ); + } + +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java new file mode 100644 index 0000000000..47baa689c8 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Stream; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-05-25T14:23:23+0200", + comments = "version: , compiler: javac, environment: Java 17.0.11 (N/A)" +) +public class ContainerBeanMapperImpl implements ContainerBeanMapper { + + @Override + public ContainerBeanDto mapWithMapMapping(ContainerBean containerBean, ContainerBeanDto containerBeanDto) { + if ( containerBean == null ) { + return containerBeanDto; + } + + if ( containerBeanDto.getBeanMap() != null ) { + Map map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ); + if ( map != null ) { + containerBeanDto.getBeanMap().clear(); + containerBeanDto.getBeanMap().putAll( map ); + } + else { + containerBeanDto.setBeanMap( null ); + } + } + else { + Map map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ); + if ( map != null ) { + containerBeanDto.setBeanMap( map ); + } + } + containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) ); + containerBeanDto.setValue( containerBean.getValue() ); + + return containerBeanDto; + } + + protected Stream containerBeanStreamToContainerBeanDtoStream(Stream stream) { + if ( stream == null ) { + return null; + } + + return stream.map( containerBean -> containerBeanToContainerBeanDto( containerBean ) ); + } + + protected ContainerBeanDto containerBeanToContainerBeanDto(ContainerBean containerBean) { + if ( containerBean == null ) { + return null; + } + + ContainerBeanDto containerBeanDto = new ContainerBeanDto(); + + containerBeanDto.setBeanMap( stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ) ); + containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) ); + containerBeanDto.setValue( containerBean.getValue() ); + + return containerBeanDto; + } + + protected Map stringContainerBeanMapToStringContainerBeanDtoMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = new LinkedHashMap( Math.max( (int) ( map.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + String key = entry.getKey(); + ContainerBeanDto value = containerBeanToContainerBeanDto( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } +} From e2edb1a0864b1a2b1a39341a7113a63f40650e92 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Jul 2024 14:04:47 +0200 Subject: [PATCH 0835/1006] #3504 Add example classes for the passing target type documentation --- .../chapter-5-data-type-conversions.asciidoc | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 30430fe97e..bc406cf0b0 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -401,6 +401,39 @@ When having a custom mapper hooked into the generated mapper with `@Mapper#uses( For instance, the `CarDto` could have a property `owner` of type `Reference` that contains the primary key of a `Person` entity. You could now create a generic custom mapper that resolves any `Reference` objects to their corresponding managed JPA entity instances. +e.g. + +.Example classes for the passing target type example +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Car { + + private Person owner; + // ... +} + +public class Person extends BaseEntity { + + // ... +} + +public class Reference { + + private String pk; + // ... +} + +public class CarDto { + + private Reference owner; + // ... +} +---- +==== + + .Mapping method expecting mapping target type as parameter ==== [source, java, linenums] From 5ce9c537e963709c33f0fa830b6c1da8653bc885 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Jul 2024 16:27:04 +0200 Subject: [PATCH 0836/1006] Add release notes --- NEXT_RELEASE_CHANGELOG.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 305bdda947..39f23af6fc 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,19 +1,26 @@ -### Features - ### Enhancements -* Breaking change:g (#3574) - +* Breaking change: (#3574) - This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties. Source properties are ignored anyway, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy ### Bugs * Breaking change: Presence check method used only once when multiple source parameters are provided (#3601) +* Fix `@SubclassMapping` not working with `@BeanMapping#ignoreUnmappedSourceProperties` (#3609) +* Fix duplicate method generation with recursive auto mapping (#3591) ### Documentation +* Fix documentation of `unmappedSourcePolicy` default value (#3635) +* Fix documentation link of before and after mapping when using builders (#3639) +* Fix typo in experimental note (#3634) +* Add example classes for the passing target type documentation (#3504) + ### Build +* Enforce whitespaces around the for colon with CheckStyle (#3642) + ## Breaking changes ### Presence checks for source parameters From bbb9bb403c93e1c938907523ce9fcdeb67c2819c Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Jul 2024 17:20:31 +0200 Subject: [PATCH 0837/1006] Fix typo in changelog --- NEXT_RELEASE_CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 39f23af6fc..f08c6a2fd9 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -47,7 +47,7 @@ public interface OrderMapper { } ``` -Them MapStruct would generate +Then MapStruct would generate ```java public class OrderMapperImpl implements OrderMapper { From 6ef64ea3aa8320c52a924375d3bc6edf60f0c86d Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:36:11 +0000 Subject: [PATCH 0838/1006] Releasing version 1.6.0.RC1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..ff56bd7953 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..d2806fa413 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..478ef7308f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index afa8e31002..4bd4bc5dc4 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..d98933a414 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f888e226ff..10850bc821 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e4109325f7..2b3b8e65a6 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-07-20T15:36:10Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 90402f0cae..571623372b 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 12fc615f5f..e33e84ba65 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0.RC1 ../parent/pom.xml From 6365a606c1b7f2c8d2dfb1583c74d46fb122eb1d Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 20 Jul 2024 15:45:11 +0000 Subject: [PATCH 0839/1006] Next version 1.6.0-SNAPSHOT --- NEXT_RELEASE_CHANGELOG.md | 83 +-------------------------------------- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 +- pom.xml | 2 +- processor/pom.xml | 2 +- 10 files changed, 12 insertions(+), 91 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index f08c6a2fd9..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,89 +1,10 @@ -### Enhancements +### Features -* Breaking change: (#3574) - -This reverts #2560, because we've decided that `@BeanMapping(ignoreByDefault = true)` should only be applied to target properties and not to source properties. -Source properties are ignored anyway, the `BeanMapping#unmappedSourcePolicy` should be used to control what should happen with unmapped source policy +### Enhancements ### Bugs -* Breaking change: Presence check method used only once when multiple source parameters are provided (#3601) -* Fix `@SubclassMapping` not working with `@BeanMapping#ignoreUnmappedSourceProperties` (#3609) -* Fix duplicate method generation with recursive auto mapping (#3591) - ### Documentation -* Fix documentation of `unmappedSourcePolicy` default value (#3635) -* Fix documentation link of before and after mapping when using builders (#3639) -* Fix typo in experimental note (#3634) -* Add example classes for the passing target type documentation (#3504) - ### Build -* Enforce whitespaces around the for colon with CheckStyle (#3642) - -## Breaking changes - -### Presence checks for source parameters - -In 1.6, support for presence checks on source parameters has been added. -This means that even if you want to map a source parameter directly to some target property the new `@SourceParameterCondition` or `@Condition(appliesTo = ConditionStrategy.SOURCE_PARAMETERS)` should be used. - -e.g. - -If we had the following in 1.5: -```java -@Mapper -public interface OrderMapper { - - @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder") - Order map(OrderDTO dto); - - @Condition - @Named("mapCustomerFromOrder") - default boolean mapCustomerFromOrder(OrderDTO dto) { - return dto != null && dto.getCustomerName() != null; - } - -} -``` - -Then MapStruct would generate - -```java -public class OrderMapperImpl implements OrderMapper { - - @Override - public Order map(OrderDTO dto) { - if ( dto == null ) { - return null; - } - - Order order = new Order(); - - if ( mapCustomerFromOrder( dto ) ) { - order.setCustomer( orderDtoToCustomer( orderDTO ) ); - } - - return order; - } -} -``` - -In order for the same to be generated in 1.6, the mapper needs to look like this: - -```java -@Mapper -public interface OrderMapper { - - @Mapping(source = "dto", target = "customer", conditionQualifiedByName = "mapCustomerFromOrder") - Order map(OrderDTO dto); - - @SourceParameterCondition - @Named("mapCustomerFromOrder") - default boolean mapCustomerFromOrder(OrderDTO dto) { - return dto != null && dto.getCustomerName() != null; - } - -} -``` - diff --git a/build-config/pom.xml b/build-config/pom.xml index ff56bd7953..0bdec734cb 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index d2806fa413..160f963adf 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 478ef7308f..ac993c73d6 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4bd4bc5dc4..afa8e31002 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index d98933a414..0a62a3ef3c 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 10850bc821..f888e226ff 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 2b3b8e65a6..e4109325f7 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-07-20T15:36:10Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 571623372b..90402f0cae 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index e33e84ba65..12fc615f5f 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0.RC1 + 1.6.0-SNAPSHOT ../parent/pom.xml From 0f24633d04c0a568ab879e629a4720f37a51616b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 20 Jul 2024 17:56:48 +0200 Subject: [PATCH 0840/1006] Fix update website script to be able to run Linux --- .github/scripts/update-website.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/scripts/update-website.sh b/.github/scripts/update-website.sh index 8fa989a1dd..7c92b8b43b 100644 --- a/.github/scripts/update-website.sh +++ b/.github/scripts/update-website.sh @@ -38,16 +38,22 @@ STABLE_VERSION=`grep stableVersion config.toml | sed 's/.*"\(.*\)"/\1/'` MAJOR_MINOR_STABLE_VERSION=$(computeMajorMinorVersion $STABLE_VERSION) echo "📝 Updating versions" -sed -i '' -e "s/^devVersion = \"\(.*\)\"/devVersion = \"${VERSION}\"/g" config.toml + +SEDOPTION="-i" +if [[ "$OSTYPE" == "darwin"* ]]; then + SEDOPTION="-i ''" +fi + +sed $SEDOPTION -e "s/^devVersion = \"\(.*\)\"/devVersion = \"${VERSION}\"/g" config.toml if [ "${STABLE}" == "yes" ]; then - sed -i '' -e "s/^stableVersion = \"\(.*\)\"/stableVersion = \"${VERSION}\"/g" config.toml + sed $SEDOPTION -e "s/^stableVersion = \"\(.*\)\"/stableVersion = \"${VERSION}\"/g" config.toml if [ "${MAJOR_MINOR_STABLE_VERSION}" != ${MAJOR_MINOR_VERSION} ]; then echo "📝 Updating new stable version" # This means that we have a new stable version and we need to change the order of the releases. - sed -i '' -e "s/^order = \(.*\)/order = 500/g" data/releases/${MAJOR_MINOR_VERSION}.toml + sed $SEDOPTION -e "s/^order = \(.*\)/order = 500/g" data/releases/${MAJOR_MINOR_VERSION}.toml NEXT_STABLE_ORDER=$((`ls -1 data/releases | wc -l` - 2)) - sed -i '' -e "s/^order = \(.*\)/order = ${NEXT_STABLE_ORDER}/g" data/releases/${MAJOR_MINOR_STABLE_VERSION}.toml + sed $SEDOPTION -e "s/^order = \(.*\)/order = ${NEXT_STABLE_ORDER}/g" data/releases/${MAJOR_MINOR_STABLE_VERSION}.toml git add data/releases/${MAJOR_MINOR_STABLE_VERSION}.toml fi elif [ "${MAJOR_MINOR_DEV_VERSION}" != "${MAJOR_MINOR_VERSION}" ]; then @@ -55,11 +61,11 @@ elif [ "${MAJOR_MINOR_DEV_VERSION}" != "${MAJOR_MINOR_VERSION}" ]; then # This means that we are updating for a new dev version, but the last dev version is not the one that we are doing. # Therefore, we need to update add the new data configuration cp data/releases/${MAJOR_MINOR_DEV_VERSION}.toml data/releases/${MAJOR_MINOR_VERSION}.toml - sed -i '' -e "s/^order = \(.*\)/order = 1000/g" data/releases/${MAJOR_MINOR_VERSION}.toml + sed $SEDOPTION -e "s/^order = \(.*\)/order = 1000/g" data/releases/${MAJOR_MINOR_VERSION}.toml fi -sed -i '' -e "s/^name = \"\(.*\)\"/name = \"${VERSION}\"/g" data/releases/${MAJOR_MINOR_VERSION}.toml -sed -i '' -e "s/^releaseDate = \(.*\)/releaseDate = $(date +%F)/g" data/releases/${MAJOR_MINOR_VERSION}.toml +sed $SEDOPTION -e "s/^name = \"\(.*\)\"/name = \"${VERSION}\"/g" data/releases/${MAJOR_MINOR_VERSION}.toml +sed $SEDOPTION -e "s/^releaseDate = \(.*\)/releaseDate = $(date +%F)/g" data/releases/${MAJOR_MINOR_VERSION}.toml git add data/releases/${MAJOR_MINOR_VERSION}.toml git add config.toml From 81ca739040022ab06991cf3d1d4d12fb8fa68e5b Mon Sep 17 00:00:00 2001 From: thunderhook <8238759+thunderhook@users.noreply.github.com> Date: Sun, 21 Jul 2024 22:59:41 +0200 Subject: [PATCH 0841/1006] #3638 Remove deprecation note of enum mapping via @Mapping --- core/src/main/java/org/mapstruct/Mapping.java | 5 +---- .../src/main/asciidoc/chapter-8-mapping-values.asciidoc | 6 ------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 42384152d0..8b0c4adb0c 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -20,7 +20,7 @@ import static org.mapstruct.NullValueCheckStrategy.ON_IMPLICIT_CONVERSION; /** - * Configures the mapping of one bean attribute or enum constant. + * Configures the mapping of one bean attribute. *

      * The name of the mapped attribute or constant is to be specified via {@link #target()}. For mapped bean attributes it * is assumed by default that the attribute has the same name in the source bean. Alternatively, one of @@ -136,9 +136,6 @@ * } *

      * - * IMPORTANT NOTE: the enum mapping capability is deprecated and replaced by {@link ValueMapping} it - * will be removed in subsequent versions. - * * @author Gunnar Morling */ diff --git a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc index 965479541e..fcb353010d 100644 --- a/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc +++ b/documentation/src/main/asciidoc/chapter-8-mapping-values.asciidoc @@ -189,12 +189,6 @@ public class SpecialOrderMapperImpl implements SpecialOrderMapper { ---- ==== - -[WARNING] -==== -The mapping of enum to enum via the `@Mapping` annotation is *DEPRECATED*. It will be removed from future versions of MapStruct. Please adapt existing enum mapping methods to make use of `@ValueMapping` instead. -==== - === Mapping enum-to-String or String-to-enum MapStruct supports enum to a String mapping along the same lines as is described in <>. There are similarities and differences: From 38ec5c53350905fb8902935306b42fd1845c40c0 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 20:59:31 +0000 Subject: [PATCH 0842/1006] Releasing version 1.6.0 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0bdec734cb..3848c6f465 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 160f963adf..bc88fdbb71 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index ac993c73d6..f002c4dd28 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index afa8e31002..a44578dc47 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 0a62a3ef3c..f82f10d339 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index f888e226ff..4ee4319a23 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index e4109325f7..a47b1fad15 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-08-12T20:59:31Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 90402f0cae..361be72a33 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 12fc615f5f..589e37007e 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0-SNAPSHOT + 1.6.0 ../parent/pom.xml From 96d06984171f56ac6a910c144fd8a30cd42f1e3d Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 21:08:07 +0000 Subject: [PATCH 0843/1006] Next version 1.7.0-SNAPSHOT --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 3848c6f465..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index bc88fdbb71..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index f002c4dd28..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index a44578dc47..f826421092 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index f82f10d339..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 4ee4319a23..7c91837e79 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index a47b1fad15..94c84fb4d0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-08-12T20:59:31Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 361be72a33..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 589e37007e..ed2df7718b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.0 + 1.7.0-SNAPSHOT ../parent/pom.xml From b452d7f2c8cc48c384d61b87ad530d2f9c882fa1 Mon Sep 17 00:00:00 2001 From: Stefan Simon <35351956+Hypnagokali@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:46:35 +0200 Subject: [PATCH 0844/1006] #3652 Inverse Inheritance should be possible for ignore-mappings without source --- NEXT_RELEASE_CHANGELOG.md | 2 ++ .../internal/model/source/MappingOptions.java | 5 ++- .../org/mapstruct/ap/test/bugs/_3652/Bar.java | 30 ++++++++++++++++ .../org/mapstruct/ap/test/bugs/_3652/Foo.java | 21 +++++++++++ .../ap/test/bugs/_3652/FooBarConfig.java | 24 +++++++++++++ .../ap/test/bugs/_3652/FooBarMapper.java | 21 +++++++++++ .../ap/test/bugs/_3652/Issue3652Test.java | 35 +++++++++++++++++++ 7 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Bar.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Foo.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Issue3652Test.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index e0f4cd31f0..b4a6b4a75b 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -4,6 +4,8 @@ ### Bugs +* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652) + ### Documentation ### Build diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 24a94137f1..22f9ccdc2f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -479,13 +479,12 @@ public MappingControl getMappingControl(ElementUtils elementUtils) { } /** - * mapping can only be inversed if the source was not a constant nor an expression nor a nested property - * and the mapping is not a 'target-source-ignore' mapping + * Mapping can only be inversed if the source was not a constant nor an expression * * @return true when the above applies */ public boolean canInverse() { - return constant == null && javaExpression == null && !( isIgnored && sourceName == null ); + return constant == null && javaExpression == null; } public MappingOptions copyForInverseInheritance(SourceMethod templateMethod, diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Bar.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Bar.java new file mode 100644 index 0000000000..3ac8b595ee --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Bar.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3652; + +public class Bar { + + private int secret; + private int doesNotExistInFoo; + + public int getSecret() { + return secret; + } + + public void setSecret(int secret) { + this.secret = secret; + } + + public int getDoesNotExistInFoo() { + return doesNotExistInFoo; + } + + public void setDoesNotExistInFoo(int doesNotExistInFoo) { + this.doesNotExistInFoo = doesNotExistInFoo; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Foo.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Foo.java new file mode 100644 index 0000000000..02b5b6e8b0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Foo.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3652; + +public class Foo { + + private int secret; + + public int getSecret() { + return secret; + } + + public void setSecret(int secret) { + this.secret = secret; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarConfig.java new file mode 100644 index 0000000000..3cf19dfbfb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarConfig.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3652; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.MappingInheritanceStrategy; + +@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG) +public interface FooBarConfig { + + @Mapping(target = "doesNotExistInFoo", ignore = true) + @Mapping(target = "secret", ignore = true) + Bar toBar(Foo foo); + + @InheritInverseConfiguration(name = "toBar") + Foo toFoo(Bar bar); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarMapper.java new file mode 100644 index 0000000000..d58be74f1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/FooBarMapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3652; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper(config = FooBarConfig.class) +public interface FooBarMapper { + + FooBarMapper INSTANCE = Mappers.getMapper( FooBarMapper.class ); + + Bar toBar(Foo foo); + + Foo toFoo(Bar bar); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Issue3652Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Issue3652Test.java new file mode 100644 index 0000000000..aa8a64ada8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3652/Issue3652Test.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3652; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3652") +public class Issue3652Test { + + @WithClasses({ + Bar.class, + Foo.class, + FooBarConfig.class, + FooBarMapper.class, + }) + @ProcessorTest + void ignoreMappingsWithoutSourceShouldBeInvertible() { + Bar bar = new Bar(); + bar.setSecret( 123 ); + bar.setDoesNotExistInFoo( 6 ); + + Foo foo = FooBarMapper.INSTANCE.toFoo( bar ); + + assertThat( foo.getSecret() ).isEqualTo( 0 ); + } + +} From 60cd0a442026a3385385dbfb0fc8cd43289992fa Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Aug 2024 11:27:52 +0200 Subject: [PATCH 0845/1006] #3670 Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` --- NEXT_RELEASE_CHANGELOG.md | 1 + .../NestedTargetPropertyMappingHolder.java | 8 +- .../ap/test/bugs/_3670/Issue3670Mapper.java | 74 +++++++++++++++++++ .../ap/test/bugs/_3670/Issue3670Test.java | 22 ++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Test.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index b4a6b4a75b..a3ea4e5026 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -5,6 +5,7 @@ ### Bugs * Inverse Inheritance Strategy not working for ignored mappings only with target (#3652) +* Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670) ### Documentation diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 20825c2dd9..92da1f4509 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -362,7 +362,13 @@ private GroupedTargetReferences groupByTargetReferences( ) { Map> singleTargetReferences = new LinkedHashMap<>(); for ( MappingReference mapping : mappingReferences.getMappingReferences() ) { TargetReference targetReference = mapping.getTargetReference(); - String property = first( targetReference.getPropertyEntries() ); + List propertyEntries = targetReference.getPropertyEntries(); + if ( propertyEntries.isEmpty() ) { + // This can happen if the target property is target = ".", + // this usually happens when doing a reverse mapping + continue; + } + String property = first( propertyEntries ); MappingReference newMapping = mapping.popTargetReference(); if ( newMapping != null ) { // group properties on current name. diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Mapper.java new file mode 100644 index 0000000000..a014a7d52d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Mapper.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3670; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3670Mapper { + + @Mapping(target = "name", source = ".", qualifiedByName = "nestedName") + Target map(Source source); + + @InheritInverseConfiguration + @Mapping(target = "nested.nestedName", source = "name") + Source map(Target target); + + @Named("nestedName") + default String mapNestedName(Source source) { + if ( source == null ) { + return null; + } + + Nested nested = source.getNested(); + + return nested != null ? nested.getNestedName() : null; + } + + class Target { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } + + class Nested { + private String nestedName; + + public String getNestedName() { + return nestedName; + } + + public void setNestedName(String nestedName) { + this.nestedName = nestedName; + } + } + + class Source { + + private Nested nested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Test.java new file mode 100644 index 0000000000..fc3929b685 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3670/Issue3670Test.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3670; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3670") +@WithClasses(Issue3670Mapper.class) +class Issue3670Test { + + @ProcessorTest + void shouldCompile() { + } +} From 6c8a2e184bd0254d8fac8bc1e04382da56750a60 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 18 Aug 2024 23:47:35 +0200 Subject: [PATCH 0846/1006] #3667, #3673 MappingReference should custom MappingOption equality instead of the default only target name based one --- .../model/beanmapping/MappingReference.java | 32 ++++++++- .../ap/test/bugs/_3667/Issue3667Mapper.java | 22 ++++++ .../ap/test/bugs/_3667/Issue3667Test.java | 43 ++++++++++++ .../mapstruct/ap/test/bugs/_3667/Source.java | 51 ++++++++++++++ .../mapstruct/ap/test/bugs/_3667/Target.java | 32 +++++++++ .../mapstruct/ap/test/bugs/_3673/Animal.java | 45 ++++++++++++ .../org/mapstruct/ap/test/bugs/_3673/Cat.java | 19 ++++++ .../mapstruct/ap/test/bugs/_3673/Details.java | 19 ++++++ .../org/mapstruct/ap/test/bugs/_3673/Dog.java | 19 ++++++ .../bugs/_3673/Issue3673ConstantMapper.java | 25 +++++++ .../bugs/_3673/Issue3673ExpressionMapper.java | 25 +++++++ .../ap/test/bugs/_3673/Issue3673Test.java | 68 +++++++++++++++++++ 12 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Animal.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Cat.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Details.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Dog.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ConstantMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ExpressionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java index e2501ea952..d013a77a7a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java @@ -71,7 +71,37 @@ public boolean equals(Object o) { return false; } MappingReference that = (MappingReference) o; - return mapping.equals( that.mapping ); + if ( ".".equals( that.mapping.getTargetName() ) ) { + // target this will never be equal to any other target this or any other. + return false; + } + + if (!Objects.equals( mapping.getTargetName(), that.mapping.getTargetName() ) ) { + return false; + } + + if ( !Objects.equals( mapping.getConstant(), that.mapping.getConstant() ) ) { + return false; + } + + if ( !Objects.equals( mapping.getJavaExpression(), that.mapping.getJavaExpression() ) ) { + return false; + } + + if ( sourceReference == null ) { + return that.sourceReference == null; + } + + if ( that.sourceReference == null ) { + return false; + } + + + if (!Objects.equals( sourceReference.getPropertyEntries(), that.sourceReference.getPropertyEntries() ) ) { + return false; + } + + return true; } @Override diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Mapper.java new file mode 100644 index 0000000000..d4f2dff0af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Mapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3667; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3667Mapper { + + Issue3667Mapper INSTANCE = Mappers.getMapper( Issue3667Mapper.class ); + + @Mapping(target = "nested.value", source = "nested.nested1.value") + Target mapFirst(Source source); + + @Mapping(target = "nested.value", source = "nested.nested2.value") + Target mapSecond(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Test.java new file mode 100644 index 0000000000..1e91de00d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Issue3667Test.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3667; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3667") +@WithClasses({ + Issue3667Mapper.class, + Source.class, + Target.class +}) +class Issue3667Test { + + @ProcessorTest + void shouldCorrectlyMapNestedProperty() { + Source source = new Source( + new Source.Nested( + new Source.NestedNested( "value1" ), + new Source.NestedNested( "value2" ) + ) + ); + + Target target1 = Issue3667Mapper.INSTANCE.mapFirst( source ); + Target target2 = Issue3667Mapper.INSTANCE.mapSecond( source ); + + assertThat( target1 ).isNotNull(); + assertThat( target1.getNested() ).isNotNull(); + assertThat( target1.getNested().getValue() ).isEqualTo( "value1" ); + + assertThat( target2 ).isNotNull(); + assertThat( target2.getNested() ).isNotNull(); + assertThat( target2.getNested().getValue() ).isEqualTo( "value2" ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Source.java new file mode 100644 index 0000000000..ede78edf0d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Source.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3667; + +public class Source { + + private final Nested nested; + + public Source(Nested nested) { + this.nested = nested; + } + + public Nested getNested() { + return nested; + } + + public static class Nested { + + private final NestedNested nested1; + private final NestedNested nested2; + + public Nested(NestedNested nested1, NestedNested nested2) { + this.nested1 = nested1; + this.nested2 = nested2; + } + + public NestedNested getNested1() { + return nested1; + } + + public NestedNested getNested2() { + return nested2; + } + } + + public static class NestedNested { + + private final String value; + + public NestedNested(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Target.java new file mode 100644 index 0000000000..e0c8d23296 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3667/Target.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3667; + +public class Target { + + private Nested nested; + + public Nested getNested() { + return nested; + } + + public void setNested(Nested nested) { + this.nested = nested; + } + + public static class Nested { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Animal.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Animal.java new file mode 100644 index 0000000000..9fe97e0e79 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Animal.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +public class Animal { + + private AnimalDetails details; + + public AnimalDetails getDetails() { + return details; + } + + public void setDetails(AnimalDetails details) { + this.details = details; + } + + public enum Type { + CAT, + DOG + } + + public static class AnimalDetails { + private Type type; + private String name; + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Cat.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Cat.java new file mode 100644 index 0000000000..63e5391690 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Cat.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +public class Cat { + + private final Details details; + + public Cat(Details details) { + this.details = details; + } + + public Details getDetails() { + return details; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Details.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Details.java new file mode 100644 index 0000000000..8526793015 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Details.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +public class Details { + + private final String name; + + public Details(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Dog.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Dog.java new file mode 100644 index 0000000000..a021a5d579 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Dog.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +public class Dog { + + private final Details details; + + public Dog(Details details) { + this.details = details; + } + + public Details getDetails() { + return details; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ConstantMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ConstantMapper.java new file mode 100644 index 0000000000..d74a954f9f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ConstantMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3673ConstantMapper { + + Issue3673ConstantMapper INSTANCE = Mappers.getMapper( Issue3673ConstantMapper.class ); + + @Mapping(target = "details.name", source = "details.name") + @Mapping(target = "details.type", constant = "DOG") + Animal map(Dog dog); + + @Mapping(target = "details.name", source = "details.name") + @Mapping(target = "details.type", constant = "CAT") + Animal map(Cat cat); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ExpressionMapper.java new file mode 100644 index 0000000000..3aca966807 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673ExpressionMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3673ExpressionMapper { + + Issue3673ExpressionMapper INSTANCE = Mappers.getMapper( Issue3673ExpressionMapper.class ); + + @Mapping(target = "details.name", source = "details.name") + @Mapping(target = "details.type", expression = "java(Animal.Type.DOG)") + Animal map(Dog dog); + + @Mapping(target = "details.name", source = "details.name") + @Mapping(target = "details.type", expression = "java(Animal.Type.CAT)") + Animal map(Cat cat); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673Test.java new file mode 100644 index 0000000000..2d796b4670 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3673/Issue3673Test.java @@ -0,0 +1,68 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3673; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3673") +@WithClasses({ + Cat.class, + Dog.class, + Details.class, + Animal.class +}) +class Issue3673Test { + + @ProcessorTest + @WithClasses(Issue3673ConstantMapper.class) + void shouldCorrectlyMapNestedPropertyConstant() { + + Animal cat = Issue3673ConstantMapper.INSTANCE.map( + new Cat( new Details( "cat" ) ) + ); + + Animal dog = Issue3673ConstantMapper.INSTANCE.map( + new Dog( new Details( "dog" ) ) + ); + + assertThat( cat ).isNotNull(); + assertThat( cat.getDetails() ).isNotNull(); + assertThat( cat.getDetails().getName() ).isEqualTo( "cat" ); + assertThat( cat.getDetails().getType() ).isEqualTo( Animal.Type.CAT ); + + assertThat( dog ).isNotNull(); + assertThat( dog.getDetails() ).isNotNull(); + assertThat( dog.getDetails().getName() ).isEqualTo( "dog" ); + assertThat( dog.getDetails().getType() ).isEqualTo( Animal.Type.DOG ); + } + + @ProcessorTest + @WithClasses(Issue3673ExpressionMapper.class) + void shouldCorrectlyMapNestedPropertyExpression() { + + Animal cat = Issue3673ExpressionMapper.INSTANCE.map( + new Cat( new Details( "cat" ) ) + ); + + Animal dog = Issue3673ExpressionMapper.INSTANCE.map( + new Dog( new Details( "dog" ) ) + ); + + assertThat( cat ).isNotNull(); + assertThat( cat.getDetails() ).isNotNull(); + assertThat( cat.getDetails().getName() ).isEqualTo( "cat" ); + assertThat( cat.getDetails().getType() ).isEqualTo( Animal.Type.CAT ); + + assertThat( dog ).isNotNull(); + assertThat( dog.getDetails() ).isNotNull(); + assertThat( dog.getDetails().getName() ).isEqualTo( "dog" ); + assertThat( dog.getDetails().getType() ).isEqualTo( Animal.Type.DOG ); + } +} From c89b616f8c213f3210f3b5d5a6f7560d665b145b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Aug 2024 12:22:37 +0200 Subject: [PATCH 0847/1006] #3668 Do not apply implicit mappings when using `SubclassExhaustiveStrategy#RUNTIME_EXCEPTION` and return type is abstract --- NEXT_RELEASE_CHANGELOG.md | 1 + .../ap/internal/model/BeanMappingMethod.java | 4 ++- .../mapstruct/ap/test/bugs/_3668/Child.java | 23 +++++++++++++ .../ap/test/bugs/_3668/ChildDto.java | 23 +++++++++++++ .../ap/test/bugs/_3668/ChildMapper.java | 31 +++++++++++++++++ .../ap/test/bugs/_3668/Issue3668Test.java | 30 +++++++++++++++++ .../mapstruct/ap/test/bugs/_3668/Parent.java | 33 +++++++++++++++++++ .../ap/test/bugs/_3668/ParentDto.java | 33 +++++++++++++++++++ .../ap/test/bugs/_3668/ParentMapper.java | 31 +++++++++++++++++ 9 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Child.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Issue3668Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Parent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentMapper.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index a3ea4e5026..438f4e3a6f 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -5,6 +5,7 @@ ### Bugs * Inverse Inheritance Strategy not working for ignored mappings only with target (#3652) +* Inconsistent ambiguous mapping method error when using `SubclassMapping`: generic vs raw types (#3668) * Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670) ### Documentation diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 6535b07012..1bec5038c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -295,7 +295,9 @@ else if ( !method.isUpdateMethod() ) { } } - boolean applyImplicitMappings = !mappingReferences.isRestrictToDefinedMappings(); + // If defined mappings should not be handled then we should not apply implicit mappings + boolean applyImplicitMappings = + shouldHandledDefinedMappings && !mappingReferences.isRestrictToDefinedMappings(); if ( applyImplicitMappings ) { applyImplicitMappings = beanMapping == null || !beanMapping.isignoreByDefault(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Child.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Child.java new file mode 100644 index 0000000000..3c10c4d470 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Child.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +public abstract class Child { + + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public static class ChildA extends Child { } + + public static class ChildB extends Child { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildDto.java new file mode 100644 index 0000000000..458cc57a9a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildDto.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +public abstract class ChildDto { + + private Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public static class ChildDtoA extends ChildDto { } + + public static class ChildDtoB extends ChildDto { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildMapper.java new file mode 100644 index 0000000000..c381a99fcd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ChildMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; + +@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) +public interface ChildMapper { + + @SubclassMapping(target = Child.ChildA.class, source = ChildDto.ChildDtoA.class) + @SubclassMapping(target = Child.ChildB.class, source = ChildDto.ChildDtoB.class) + Child toEntity(ChildDto childDto); + + @SubclassMapping(target = ChildDto.ChildDtoA.class, source = Child.ChildA.class) + @SubclassMapping(target = ChildDto.ChildDtoB.class, source = Child.ChildB.class) + ChildDto toDto(Child child); + + Child.ChildA toEntity(ChildDto.ChildDtoA childDto); + + ChildDto.ChildDtoA toDto(Child.ChildA child); + + Child.ChildB toEntity(ChildDto.ChildDtoB childDto); + + ChildDto.ChildDtoB toDto(Child.ChildB child); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Issue3668Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Issue3668Test.java new file mode 100644 index 0000000000..a35ac70dce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Issue3668Test.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3668") +@WithClasses({ + Child.class, + ChildDto.class, + ChildMapper.class, + Parent.class, + ParentDto.class, + ParentMapper.class, +}) +class Issue3668Test { + + @ProcessorTest + void shouldCompile() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Parent.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Parent.java new file mode 100644 index 0000000000..900a7fa68b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/Parent.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +public abstract class Parent { + + private Long id; + + private T child; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public T getChild() { + return child; + } + + public void setChild(T child) { + this.child = child; + } + + public static class ParentA extends Parent { } + + public static class ParentB extends Parent { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentDto.java new file mode 100644 index 0000000000..f4736ceef0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentDto.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +public abstract class ParentDto { + + private Long id; + + private T child; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public T getChild() { + return child; + } + + public void setChild(T child) { + this.child = child; + } + + public static class ParentDtoA extends ParentDto { } + + public static class ParentDtoB extends ParentDto { } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentMapper.java new file mode 100644 index 0000000000..484ddbc930 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3668/ParentMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3668; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; + +@Mapper(uses = { ChildMapper.class }, subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) +public interface ParentMapper { + + @SubclassMapping(target = Parent.ParentA.class, source = ParentDto.ParentDtoA.class) + @SubclassMapping(target = Parent.ParentB.class, source = ParentDto.ParentDtoB.class) + Parent toEntity(ParentDto parentDto); + + @SubclassMapping(target = ParentDto.ParentDtoA.class, source = Parent.ParentA.class) + @SubclassMapping(target = ParentDto.ParentDtoB.class, source = Parent.ParentB.class) + ParentDto toDto(Parent parent); + + Parent.ParentA toEntity(ParentDto.ParentDtoA parentDto); + + ParentDto.ParentDtoA toDto(Parent.ParentA parent); + + Parent.ParentB toEntity(ParentDto.ParentDtoB parentDto); + + ParentDto.ParentDtoB toDto(Parent.ParentB parent); + +} From 58dcb9d81387963caa2f74a8c4b836afaef471b9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 28 Aug 2024 11:56:21 +0200 Subject: [PATCH 0848/1006] Update latest version and remove some obsolete badges --- readme.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/readme.md b/readme.md index 21d820dc58..6e5debbb78 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,11 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.5.5.Final-blue.svg)](https://search.maven.org/search?q=g:org.mapstruct%20AND%20v:1.*.Final) -[![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://search.maven.org/search?q=g:org.mapstruct) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.6.0-blue.svg)](https://central.sonatype.com/search?q=g:org.mapstruct%20v:1.6.0) +[![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://central.sonatype.com/search?q=g:org.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/main/LICENSE.txt) [![Build Status](https://github.com/mapstruct/mapstruct/workflows/CI/badge.svg?branch=main)](https://github.com/mapstruct/mapstruct/actions?query=branch%3Amain+workflow%3ACI) [![Coverage Status](https://img.shields.io/codecov/c/github/mapstruct/mapstruct.svg)](https://codecov.io/gh/mapstruct/mapstruct/tree/main) -[![Gitter](https://img.shields.io/gitter/room/mapstruct/mapstruct.svg)](https://gitter.im/mapstruct/mapstruct-users) -[![Code Quality: Java](https://img.shields.io/lgtm/grade/java/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/context:java) -[![Total Alerts](https://img.shields.io/lgtm/alerts/g/mapstruct/mapstruct.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/mapstruct/mapstruct/alerts) * [What is MapStruct?](#what-is-mapstruct) * [Requirements](#requirements) @@ -68,7 +65,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.5.5.Final + 1.6.0 ... @@ -84,10 +81,10 @@ For Maven-based projects, add the following to your POM file in order to use Map org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 - 1.8 - 1.8 + 17 + 1<7/target> org.mapstruct @@ -114,10 +111,10 @@ plugins { dependencies { ... - implementation 'org.mapstruct:mapstruct:1.5.5.Final' + implementation 'org.mapstruct:mapstruct:1.6.0' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0' // if you are using mapstruct in test code } ... ``` From c6010c917a6ee239c5c0d949b7460a6a7451df1f Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sat, 31 Aug 2024 16:31:51 +0200 Subject: [PATCH 0849/1006] Fix typo in readme Maven plugin config --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6e5debbb78..c0f798af83 100644 --- a/readme.md +++ b/readme.md @@ -84,7 +84,7 @@ For Maven-based projects, add the following to your POM file in order to use Map 3.13.0 17 - 1<7/target> + 17 org.mapstruct From 1e89d7497b1327c91cf782b80cb484adfdf87192 Mon Sep 17 00:00:00 2001 From: Obolrom <65775868+Obolrom@users.noreply.github.com> Date: Mon, 2 Sep 2024 09:44:17 +0300 Subject: [PATCH 0850/1006] Fix method name typo (#3622) --- .../org/mapstruct/ap/internal/model/BeanMappingMethod.java | 4 ++-- .../ap/internal/model/source/BeanMappingOptions.java | 2 +- .../ap/internal/processor/MapperCreationProcessor.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 1bec5038c4..4ccf2bb49a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -299,7 +299,7 @@ else if ( !method.isUpdateMethod() ) { boolean applyImplicitMappings = shouldHandledDefinedMappings && !mappingReferences.isRestrictToDefinedMappings(); if ( applyImplicitMappings ) { - applyImplicitMappings = beanMapping == null || !beanMapping.isignoreByDefault(); + applyImplicitMappings = beanMapping == null || !beanMapping.isIgnoredByDefault(); } if ( applyImplicitMappings ) { @@ -1699,7 +1699,7 @@ private ReportingPolicyGem getUnmappedTargetPolicy() { return ReportingPolicyGem.IGNORE; } // If we have ignoreByDefault = true, unprocessed target properties are not an issue. - if ( method.getOptions().getBeanMapping().isignoreByDefault() ) { + if ( method.getOptions().getBeanMapping().isIgnoredByDefault() ) { return ReportingPolicyGem.IGNORE; } if ( method.getOptions().getBeanMapping() != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index bc19860bb5..ac27dfff00 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -223,7 +223,7 @@ public SelectionParameters getSelectionParameters() { return selectionParameters; } - public boolean isignoreByDefault() { + public boolean isIgnoredByDefault() { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::ignoreByDefault ) .map( GemValue::get ) .orElse( false ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 24dd528f6b..5fc1b07823 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -565,7 +565,7 @@ else if ( applicableReversePrototypeMethods.size() > 1 ) { } // @BeanMapping( ignoreByDefault = true ) - if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isignoreByDefault() ) { + if ( mappingOptions.getBeanMapping() != null && mappingOptions.getBeanMapping().isIgnoredByDefault() ) { mappingOptions.applyIgnoreAll( method, typeFactory, mappingContext.getMessager() ); } From 23f4802374ae8e4703e8f127d85e332bf2e682fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EA=B8=B0=EC=84=9C?= <81108344+rlarltj@users.noreply.github.com> Date: Mon, 2 Sep 2024 16:05:01 +0900 Subject: [PATCH 0851/1006] Fix method name typo (#3691) --- .../java/org/mapstruct/ap/internal/util/NativeTypesTest.java | 4 ++-- .../mapstruct/ap/test/accessibility/AccessibilityTest.java | 2 +- .../ap/test/accessibility/DefaultSourceTargetMapperIfc.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java index 9c68a1de45..cd96592839 100644 --- a/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/util/NativeTypesTest.java @@ -122,7 +122,7 @@ public void testIntegerLiteralFromJLS() { .isNotNull(); // most negative int: dec / octal / int / binary - // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can disssapear (java8) + // NOTE parseInt should be changed to parseUnsignedInt in Java, than the - sign can dissapear (java8) // and the function will be true to what the compiler shows. assertThat( getLiteral( int.class.getCanonicalName(), "-2147483648" ) ).isNotNull(); assertThat( getLiteral( int.class.getCanonicalName(), "0x8000_0000" ) ).isNotNull(); @@ -177,7 +177,7 @@ public void testIntegerLiteralFromJLS() { * The following example shows other ways you can use the underscore in numeric literals: */ @Test - public void testFloatingPoingLiteralFromJLS() { + public void testFloatingPointLiteralFromJLS() { // The largest positive finite literal of type float is 3.4028235e38f. assertThat( getLiteral( float.class.getCanonicalName(), "3.4028235e38f" ) ).isNotNull(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java index d338cadedd..bab9ca9b71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/AccessibilityTest.java @@ -41,7 +41,7 @@ public void testGeneratedModifiersFromInterfaceAreCorrect() throws Exception { assertTrue( isDefault( defaultFromIfc.getModifiers() ) ); - assertTrue( isPublic( modifiersFor( defaultFromIfc, "implicitlyPublicSoureToTarget" ) ) ); + assertTrue( isPublic( modifiersFor( defaultFromIfc, "implicitlyPublicSourceToTarget" ) ) ); } private static Class loadForMapper(Class mapper) throws ClassNotFoundException { diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java index 84e9aebbbc..027d60b9ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/DefaultSourceTargetMapperIfc.java @@ -12,5 +12,5 @@ */ @Mapper interface DefaultSourceTargetMapperIfc { - Target implicitlyPublicSoureToTarget(Source source); + Target implicitlyPublicSourceToTarget(Source source); } From 4d9894ba25ba4e17c76211409f951f4cce956b3e Mon Sep 17 00:00:00 2001 From: Obolrom <65775868+Obolrom@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:26:48 +0300 Subject: [PATCH 0852/1006] #3113 Use LinkedHashSet, LinkedHashSet new factory methods for java >= 19 --- .../model/common/ImplementationType.java | 25 +- .../ap/internal/model/common/TypeFactory.java | 26 +- .../DefaultModelElementProcessorContext.java | 3 +- .../processor/DefaultVersionInformation.java | 7 + .../internal/version/VersionInformation.java | 2 + .../ap/internal/model/IterableCreation.ftl | 12 +- .../testutil/runner/CompilationRequest.java | 4 + .../ap/testutil/runner/GeneratedSource.java | 21 +- .../test/bugs/_1453/Issue1453MapperImpl.java | 139 ++++++++++ .../bugs/_3591/ContainerBeanMapperImpl.java | 85 ++++++ .../DomainDtoWithNcvsAlwaysMapperImpl.java | 214 +++++++++++++++ .../DomainDtoWithNvmsDefaultMapperImpl.java | 245 +++++++++++++++++ .../_913/DomainDtoWithNvmsNullMapperImpl.java | 248 +++++++++++++++++ .../DomainDtoWithPresenceCheckMapperImpl.java | 214 +++++++++++++++ .../SourceTargetMapperImpl.java | 259 ++++++++++++++++++ .../updatemethods/CompanyMapper1Impl.java | 120 ++++++++ 16 files changed, 1605 insertions(+), 19 deletions(-) create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java index 45b73c492f..af8c7ecfb3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ImplementationType.java @@ -16,23 +16,34 @@ public class ImplementationType { private final Type type; private final boolean initialCapacityConstructor; private final boolean loadFactorAdjustment; + private final String factoryMethodName; - private ImplementationType(Type type, boolean initialCapacityConstructor, boolean loadFactorAdjustment) { + private ImplementationType( + Type type, + boolean initialCapacityConstructor, + boolean loadFactorAdjustment, + String factoryMethodName + ) { this.type = type; this.initialCapacityConstructor = initialCapacityConstructor; this.loadFactorAdjustment = loadFactorAdjustment; + this.factoryMethodName = factoryMethodName; } public static ImplementationType withDefaultConstructor(Type type) { - return new ImplementationType( type, false, false ); + return new ImplementationType( type, false, false, null ); } public static ImplementationType withInitialCapacity(Type type) { - return new ImplementationType( type, true, false ); + return new ImplementationType( type, true, false, null ); } public static ImplementationType withLoadFactorAdjustment(Type type) { - return new ImplementationType( type, true, true ); + return new ImplementationType( type, true, true, null ); + } + + public static ImplementationType withFactoryMethod(Type type, String factoryMethodName) { + return new ImplementationType( type, true, false, factoryMethodName ); } /** @@ -44,7 +55,7 @@ public static ImplementationType withLoadFactorAdjustment(Type type) { * @return a new implementation type with the given {@code type} */ public ImplementationType createNew(Type type) { - return new ImplementationType( type, initialCapacityConstructor, loadFactorAdjustment ); + return new ImplementationType( type, initialCapacityConstructor, loadFactorAdjustment, factoryMethodName ); } /** @@ -71,4 +82,8 @@ public boolean hasInitialCapacityConstructor() { public boolean isLoadFactorAdjustment() { return loadFactorAdjustment; } + + public String getFactoryMethodName() { + return factoryMethodName; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index f28e0c687e..d65070426b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -38,12 +38,11 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.type.TypeVariable; import javax.lang.model.type.WildcardType; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.util.AnnotationProcessingException; import org.mapstruct.ap.internal.util.Collections; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.Extractor; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.JavaStreamConstants; @@ -51,13 +50,16 @@ import org.mapstruct.ap.internal.util.NativeTypes; import org.mapstruct.ap.internal.util.RoundContext; import org.mapstruct.ap.internal.util.Strings; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.util.accessor.Accessor; +import org.mapstruct.ap.internal.version.VersionInformation; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; import org.mapstruct.ap.spi.BuilderInfo; import org.mapstruct.ap.spi.MoreThanOneBuilderCreationMethodException; import org.mapstruct.ap.spi.TypeHierarchyErroneousException; import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor; +import static org.mapstruct.ap.internal.model.common.ImplementationType.withFactoryMethod; import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity; import static org.mapstruct.ap.internal.model.common.ImplementationType.withLoadFactorAdjustment; @@ -82,6 +84,8 @@ public class TypeFactory { sb.append( ')' ); return sb.toString(); }; + private static final String LINKED_HASH_SET_FACTORY_METHOD_NAME = "newLinkedHashSet"; + private static final String LINKED_HASH_MAP_FACTORY_METHOD_NAME = "newLinkedHashMap"; private final ElementUtils elementUtils; private final TypeUtils typeUtils; @@ -100,7 +104,8 @@ public class TypeFactory { private final boolean loggingVerbose; public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMessager messager, - RoundContext roundContext, Map notToBeImportedTypes, boolean loggingVerbose) { + RoundContext roundContext, Map notToBeImportedTypes, boolean loggingVerbose, + VersionInformation versionInformation) { this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; @@ -118,11 +123,22 @@ public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMes implementationTypes.put( Collection.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); implementationTypes.put( List.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) ); - implementationTypes.put( Set.class.getName(), withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) ); + boolean sourceVersionAtLeast19 = versionInformation.isSourceVersionAtLeast19(); + implementationTypes.put( + Set.class.getName(), + sourceVersionAtLeast19 ? + withFactoryMethod( getType( LinkedHashSet.class ), LINKED_HASH_SET_FACTORY_METHOD_NAME ) : + withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) + ); implementationTypes.put( SortedSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); implementationTypes.put( NavigableSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) ); - implementationTypes.put( Map.class.getName(), withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) ); + implementationTypes.put( + Map.class.getName(), + sourceVersionAtLeast19 ? + withFactoryMethod( getType( LinkedHashMap.class ), LINKED_HASH_MAP_FACTORY_METHOD_NAME ) : + withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) + ); implementationTypes.put( SortedMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); implementationTypes.put( NavigableMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) ); implementationTypes.put( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java index 51ea5dd786..8ac1cc067e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultModelElementProcessorContext.java @@ -62,7 +62,8 @@ public DefaultModelElementProcessorContext(ProcessingEnvironment processingEnvir messager, roundContext, notToBeImported, - options.isVerbose() + options.isVerbose(), + versionInformation ); this.options = options; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java index c4baf1bf5f..055bfe6095 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java @@ -41,6 +41,7 @@ public class DefaultVersionInformation implements VersionInformation { private final String runtimeVendor; private final String compiler; private final boolean sourceVersionAtLeast9; + private final boolean sourceVersionAtLeast19; private final boolean eclipseJDT; private final boolean javac; @@ -53,6 +54,7 @@ public class DefaultVersionInformation implements VersionInformation { this.javac = compiler.startsWith( COMPILER_NAME_JAVAC ); // If the difference between the source version and RELEASE_6 is more that 2 than we are at least on 9 this.sourceVersionAtLeast9 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 2; + this.sourceVersionAtLeast19 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 12; } @Override @@ -80,6 +82,11 @@ public boolean isSourceVersionAtLeast9() { return sourceVersionAtLeast9; } + @Override + public boolean isSourceVersionAtLeast19() { + return sourceVersionAtLeast19; + } + @Override public boolean isEclipseJDTCompiler() { return eclipseJDT; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java index 94e3520ad0..5e1972fcae 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java @@ -21,6 +21,8 @@ public interface VersionInformation { boolean isSourceVersionAtLeast9(); + boolean isSourceVersionAtLeast19(); + boolean isEclipseJDTCompiler(); boolean isJavacCompiler(); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl index d49397a985..d083bd113d 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableCreation.ftl @@ -11,13 +11,15 @@ <@includeModel object=factoryMethod targetType=resultType/> <#elseif enumSet> EnumSet.noneOf( <@includeModel object=enumSetElementType raw=true/>.class ) - <#else> - new - <#if resultType.implementationType??> - <@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>() + <#elseif resultType.implementation??> + <#if resultType.implementation.factoryMethodName?? && ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize> + <@includeModel object=resultType.implementationType raw=true />.${resultType.implementation.factoryMethodName}( <@sizeForCreation /> ) <#else> - <@includeModel object=resultType/>() + new <@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>() + <#else> + new <@includeModel object=resultType/>() + <#macro sizeForCreation> <@compress single_line=true> diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index 60e9a30072..9f1b78caa0 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -76,4 +76,8 @@ public Map, Class> getServices() { public Collection getTestDependencies() { return testDependencies; } + + public Compiler getCompiler() { + return compiler; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index c0993ea098..18a53b4971 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -44,12 +44,15 @@ public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestEx */ private ThreadLocal sourceOutputDir = new ThreadLocal<>(); + private Compiler compiler; + private List> fixturesFor = new ArrayList<>(); @Override public void beforeTestExecution(ExtensionContext context) throws Exception { CompilationRequest compilationRequest = context.getStore( NAMESPACE ) .get( context.getUniqueId() + "-compilationRequest", CompilationRequest.class ); + this.compiler = compilationRequest.getCompiler(); setSourceOutputDir( context.getStore( NAMESPACE ) .get( compilationRequest, CompilationCache.class ) .getLastSourceOutputDir() ); @@ -118,13 +121,13 @@ public JavaFileAssert forJavaFile(String path) { private void handleFixtureComparison() throws UnsupportedEncodingException { for ( Class fixture : fixturesFor ) { - String expectedFixture = FIXTURES_ROOT + getMapperName( fixture ); - URL expectedFile = getClass().getClassLoader().getResource( expectedFixture ); + String fixtureName = getMapperName( fixture ); + URL expectedFile = getExpectedResource( fixtureName ); if ( expectedFile == null ) { fail( String.format( "No reference file could be found for Mapper %s. You should create a file %s", fixture.getName(), - expectedFixture + FIXTURES_ROOT + fixtureName ) ); } else { @@ -135,4 +138,16 @@ private void handleFixtureComparison() throws UnsupportedEncodingException { } } + + private URL getExpectedResource( String fixtureName ) { + ClassLoader classLoader = getClass().getClassLoader(); + for ( int version = Runtime.version().feature(); version >= 11 && compiler != Compiler.ECLIPSE; version-- ) { + URL resource = classLoader.getResource( FIXTURES_ROOT + "/" + version + "/" + fixtureName ); + if ( resource != null ) { + return resource; + } + } + + return classLoader.getResource( FIXTURES_ROOT + fixtureName ); + } } diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java new file mode 100644 index 0000000000..78c3bea0d7 --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_1453/Issue1453MapperImpl.java @@ -0,0 +1,139 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._1453; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-18T14:48:39+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class Issue1453MapperImpl implements Issue1453Mapper { + + @Override + public AuctionDto map(Auction auction) { + if ( auction == null ) { + return null; + } + + AuctionDto auctionDto = new AuctionDto(); + + auctionDto.setPayments( paymentListToPaymentDtoList( auction.getPayments() ) ); + auctionDto.setOtherPayments( paymentListToPaymentDtoList( auction.getOtherPayments() ) ); + auctionDto.setMapPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapPayments() ) ); + auctionDto.setMapSuperPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapSuperPayments() ) ); + + return auctionDto; + } + + @Override + public List mapExtend(List auctions) { + if ( auctions == null ) { + return null; + } + + List list = new ArrayList( auctions.size() ); + for ( Auction auction : auctions ) { + list.add( map( auction ) ); + } + + return list; + } + + @Override + public List mapSuper(List auctions) { + if ( auctions == null ) { + return null; + } + + List list = new ArrayList( auctions.size() ); + for ( Auction auction : auctions ) { + list.add( map( auction ) ); + } + + return list; + } + + @Override + public Map mapExtend(Map auctions) { + if ( auctions == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( auctions.size() ); + + for ( java.util.Map.Entry entry : auctions.entrySet() ) { + AuctionDto key = map( entry.getKey() ); + AuctionDto value = map( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public Map mapSuper(Map auctions) { + if ( auctions == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( auctions.size() ); + + for ( java.util.Map.Entry entry : auctions.entrySet() ) { + AuctionDto key = map( entry.getKey() ); + AuctionDto value = map( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + protected PaymentDto paymentToPaymentDto(Payment payment) { + if ( payment == null ) { + return null; + } + + PaymentDto paymentDto = new PaymentDto(); + + paymentDto.setPrice( payment.getPrice() ); + + return paymentDto; + } + + protected List paymentListToPaymentDtoList(List list) { + if ( list == null ) { + return null; + } + + List list1 = new ArrayList( list.size() ); + for ( Payment payment : list ) { + list1.add( paymentToPaymentDto( payment ) ); + } + + return list1; + } + + protected Map paymentPaymentMapToPaymentDtoPaymentDtoMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = LinkedHashMap.newLinkedHashMap( map.size() ); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + PaymentDto key = paymentToPaymentDto( entry.getKey() ); + PaymentDto value = paymentToPaymentDto( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java new file mode 100644 index 0000000000..af3d293f7d --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_3591/ContainerBeanMapperImpl.java @@ -0,0 +1,85 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3591; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Stream; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-05-25T14:23:23+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class ContainerBeanMapperImpl implements ContainerBeanMapper { + + @Override + public ContainerBeanDto mapWithMapMapping(ContainerBean containerBean, ContainerBeanDto containerBeanDto) { + if ( containerBean == null ) { + return containerBeanDto; + } + + if ( containerBeanDto.getBeanMap() != null ) { + Map map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ); + if ( map != null ) { + containerBeanDto.getBeanMap().clear(); + containerBeanDto.getBeanMap().putAll( map ); + } + else { + containerBeanDto.setBeanMap( null ); + } + } + else { + Map map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ); + if ( map != null ) { + containerBeanDto.setBeanMap( map ); + } + } + containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) ); + containerBeanDto.setValue( containerBean.getValue() ); + + return containerBeanDto; + } + + protected Stream containerBeanStreamToContainerBeanDtoStream(Stream stream) { + if ( stream == null ) { + return null; + } + + return stream.map( containerBean -> containerBeanToContainerBeanDto( containerBean ) ); + } + + protected ContainerBeanDto containerBeanToContainerBeanDto(ContainerBean containerBean) { + if ( containerBean == null ) { + return null; + } + + ContainerBeanDto containerBeanDto = new ContainerBeanDto(); + + containerBeanDto.setBeanMap( stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ) ); + containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) ); + containerBeanDto.setValue( containerBean.getValue() ); + + return containerBeanDto; + } + + protected Map stringContainerBeanMapToStringContainerBeanDtoMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = LinkedHashMap.newLinkedHashMap( map.size() ); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + String key = entry.getKey(); + ContainerBeanDto value = containerBeanToContainerBeanDto( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java new file mode 100644 index 0000000000..d5cfd24723 --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNcvsAlwaysMapperImpl.java @@ -0,0 +1,214 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-19T11:20:01+0300", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Amazon.com Inc.)" +) +public class DomainDtoWithNcvsAlwaysMapperImpl implements DomainDtoWithNcvsAlwaysMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(DtoWithPresenceCheck source) { + if ( source == null ) { + return null; + } + + Domain domain = createNullDomain(); + + if ( source.hasStrings() ) { + List list = source.getStrings(); + domain.setStrings( new LinkedHashSet( list ) ); + } + if ( source.hasStrings() ) { + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + } + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + if ( source.hasStringsInitialized() ) { + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + + return domain; + } + + @Override + public void update(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + target.getLongs().clear(); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); + } + } + else { + if ( source.hasStrings() ) { + target.setLongs( stringListToLongSet( source.getStrings() ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + else { + if ( source.hasStringsInitialized() ) { + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + } + + @Override + public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return target; + } + + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + target.getLongs().clear(); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); + } + } + else { + if ( source.hasStrings() ) { + target.setLongs( stringListToLongSet( source.getStrings() ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + else { + if ( source.hasStringsInitialized() ) { + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = LinkedHashSet.newLinkedHashSet( list.size() ); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java new file mode 100644 index 0000000000..76de94378b --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -0,0 +1,245 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-18T14:48:39+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class DomainDtoWithNvmsDefaultMapperImpl implements DomainDtoWithNvmsDefaultMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(Dto source) { + + Domain domain = new Domain(); + + if ( source != null ) { + List list = source.getStrings(); + if ( list != null ) { + domain.setStrings( new LinkedHashSet( list ) ); + } + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + domain.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + } + + return domain; + } + + @Override + public void update(Dto source, Domain target) { + + if ( source != null ) { + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( new LinkedHashSet() ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( new LinkedHashSet() ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); + } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } + } + else { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set1 ); + } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } + } + else { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.setLongsInitialized( set1 ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list2 ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + } + } + + @Override + public Domain updateWithReturn(Dto source, Domain target) { + + if ( source != null ) { + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( new LinkedHashSet() ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( new LinkedHashSet() ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); + } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } + } + else { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set1 ); + } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } + } + else { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.setLongsInitialized( set1 ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list2 ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return new LinkedHashSet(); + } + + Set set = LinkedHashSet.newLinkedHashSet( list.size() ); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java new file mode 100644 index 0000000000..c61c2c68e8 --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsNullMapperImpl.java @@ -0,0 +1,248 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-18T14:48:39+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class DomainDtoWithNvmsNullMapperImpl implements DomainDtoWithNvmsNullMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(Dto source) { + if ( source == null ) { + return null; + } + + Domain domain = createNullDomain(); + + List list = source.getStrings(); + if ( list != null ) { + domain.setStrings( new LinkedHashSet( list ) ); + } + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + domain.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + + return domain; + } + + @Override + public void update(Dto source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set1 ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.setLongsInitialized( set1 ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list2 ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + } + + @Override + public Domain updateWithReturn(Dto source, Domain target) { + if ( source == null ) { + return target; + } + + if ( target.getStrings() != null ) { + List list = source.getStrings(); + if ( list != null ) { + target.getStrings().clear(); + target.getStrings().addAll( list ); + } + else { + target.setStrings( null ); + } + } + else { + List list = source.getStrings(); + if ( list != null ) { + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.getLongs().clear(); + target.getLongs().addAll( set ); + } + else { + target.setLongs( null ); + } + } + else { + Set set = stringListToLongSet( source.getStrings() ); + if ( set != null ) { + target.setLongs( set ); + } + } + if ( target.getStringsInitialized() != null ) { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( list1 ); + } + else { + target.setStringsInitialized( null ); + } + } + else { + List list1 = source.getStringsInitialized(); + if ( list1 != null ) { + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( set1 ); + } + else { + target.setLongsInitialized( null ); + } + } + else { + Set set1 = stringListToLongSet( source.getStringsInitialized() ); + if ( set1 != null ) { + target.setLongsInitialized( set1 ); + } + } + if ( target.getStringsWithDefault() != null ) { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( list2 ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + List list2 = source.getStringsWithDefault(); + if ( list2 != null ) { + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = LinkedHashSet.newLinkedHashSet( list.size() ); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java new file mode 100644 index 0000000000..6d01a91ec5 --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithPresenceCheckMapperImpl.java @@ -0,0 +1,214 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._913; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-19T11:03:59+0300", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Amazon.com Inc.)" +) +public class DomainDtoWithPresenceCheckMapperImpl implements DomainDtoWithPresenceCheckMapper { + + private final Helper helper = new Helper(); + + @Override + public Domain create(DtoWithPresenceCheck source) { + if ( source == null ) { + return null; + } + + Domain domain = createNullDomain(); + + if ( source.hasStrings() ) { + List list = source.getStrings(); + domain.setStrings( new LinkedHashSet( list ) ); + } + if ( source.hasStrings() ) { + domain.setLongs( stringListToLongSet( source.getStrings() ) ); + } + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + domain.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + if ( source.hasStringsInitialized() ) { + domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + domain.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + domain.setStringsWithDefault( helper.toList( "3" ) ); + } + + return domain; + } + + @Override + public void update(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return; + } + + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + target.getLongs().clear(); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); + } + } + else { + if ( source.hasStrings() ) { + target.setLongs( stringListToLongSet( source.getStrings() ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + else { + if ( source.hasStringsInitialized() ) { + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + } + + @Override + public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) { + if ( source == null ) { + return target; + } + + if ( target.getStrings() != null ) { + if ( source.hasStrings() ) { + target.getStrings().clear(); + target.getStrings().addAll( source.getStrings() ); + } + } + else { + if ( source.hasStrings() ) { + List list = source.getStrings(); + target.setStrings( new LinkedHashSet( list ) ); + } + } + if ( target.getLongs() != null ) { + if ( source.hasStrings() ) { + target.getLongs().clear(); + target.getLongs().addAll( stringListToLongSet( source.getStrings() ) ); + } + } + else { + if ( source.hasStrings() ) { + target.setLongs( stringListToLongSet( source.getStrings() ) ); + } + } + if ( target.getStringsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getStringsInitialized().clear(); + target.getStringsInitialized().addAll( source.getStringsInitialized() ); + } + } + else { + if ( source.hasStringsInitialized() ) { + List list1 = source.getStringsInitialized(); + target.setStringsInitialized( new LinkedHashSet( list1 ) ); + } + } + if ( target.getLongsInitialized() != null ) { + if ( source.hasStringsInitialized() ) { + target.getLongsInitialized().clear(); + target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + else { + if ( source.hasStringsInitialized() ) { + target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) ); + } + } + if ( target.getStringsWithDefault() != null ) { + if ( source.hasStringsWithDefault() ) { + target.getStringsWithDefault().clear(); + target.getStringsWithDefault().addAll( source.getStringsWithDefault() ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + else { + if ( source.hasStringsWithDefault() ) { + List list2 = source.getStringsWithDefault(); + target.setStringsWithDefault( new ArrayList( list2 ) ); + } + else { + target.setStringsWithDefault( helper.toList( "3" ) ); + } + } + + return target; + } + + protected Set stringListToLongSet(List list) { + if ( list == null ) { + return null; + } + + Set set = LinkedHashSet.newLinkedHashSet( list.size() ); + for ( String string : list ) { + set.add( Long.parseLong( string ) ); + } + + return set; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..3f0bee535a --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/collection/defaultimplementation/SourceTargetMapperImpl.java @@ -0,0 +1,259 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.defaultimplementation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.NavigableMap; +import java.util.NavigableSet; +import java.util.Set; +import java.util.SortedMap; +import java.util.SortedSet; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ConcurrentNavigableMap; +import java.util.concurrent.ConcurrentSkipListMap; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-18T14:48:39+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + if ( target.getFooListNoSetter() != null ) { + List list = sourceFoosToTargetFoos( source.getFooList() ); + if ( list != null ) { + target.getFooListNoSetter().addAll( list ); + } + } + + return target; + } + + @Override + public TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo) { + if ( sourceFoo == null ) { + return null; + } + + TargetFoo targetFoo = new TargetFoo(); + + targetFoo.setName( sourceFoo.getName() ); + + return targetFoo; + } + + @Override + public List sourceFoosToTargetFoos(List foos) { + if ( foos == null ) { + return null; + } + + List list = new ArrayList( foos.size() ); + for ( SourceFoo sourceFoo : foos ) { + list.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return list; + } + + @Override + public Set sourceFoosToTargetFoos(Set foos) { + if ( foos == null ) { + return null; + } + + Set set = LinkedHashSet.newLinkedHashSet( foos.size() ); + for ( SourceFoo sourceFoo : foos ) { + set.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return set; + } + + @Override + public Collection sourceFoosToTargetFoos(Collection foos) { + if ( foos == null ) { + return null; + } + + Collection collection = new ArrayList( foos.size() ); + for ( SourceFoo sourceFoo : foos ) { + collection.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return collection; + } + + @Override + public Iterable sourceFoosToTargetFoos(Iterable foos) { + if ( foos == null ) { + return null; + } + + ArrayList iterable = new ArrayList(); + for ( SourceFoo sourceFoo : foos ) { + iterable.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return iterable; + } + + @Override + public void sourceFoosToTargetFoosUsingTargetParameter(List targetFoos, Iterable sourceFoos) { + if ( sourceFoos == null ) { + return; + } + + targetFoos.clear(); + for ( SourceFoo sourceFoo : sourceFoos ) { + targetFoos.add( sourceFooToTargetFoo( sourceFoo ) ); + } + } + + @Override + public Iterable sourceFoosToTargetFoosUsingTargetParameterAndReturn(Iterable sourceFoos, List targetFoos) { + if ( sourceFoos == null ) { + return targetFoos; + } + + targetFoos.clear(); + for ( SourceFoo sourceFoo : sourceFoos ) { + targetFoos.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return targetFoos; + } + + @Override + public SortedSet sourceFoosToTargetFooSortedSet(Collection foos) { + if ( foos == null ) { + return null; + } + + SortedSet sortedSet = new TreeSet(); + for ( SourceFoo sourceFoo : foos ) { + sortedSet.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return sortedSet; + } + + @Override + public NavigableSet sourceFoosToTargetFooNavigableSet(Collection foos) { + if ( foos == null ) { + return null; + } + + NavigableSet navigableSet = new TreeSet(); + for ( SourceFoo sourceFoo : foos ) { + navigableSet.add( sourceFooToTargetFoo( sourceFoo ) ); + } + + return navigableSet; + } + + @Override + public Map sourceFooMapToTargetFooMap(Map foos) { + if ( foos == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( foos.size() ); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public SortedMap sourceFooMapToTargetFooSortedMap(Map foos) { + if ( foos == null ) { + return null; + } + + SortedMap sortedMap = new TreeMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + sortedMap.put( key, value ); + } + + return sortedMap; + } + + @Override + public NavigableMap sourceFooMapToTargetFooNavigableMap(Map foos) { + if ( foos == null ) { + return null; + } + + NavigableMap navigableMap = new TreeMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + navigableMap.put( key, value ); + } + + return navigableMap; + } + + @Override + public ConcurrentMap sourceFooMapToTargetFooConcurrentMap(Map foos) { + if ( foos == null ) { + return null; + } + + ConcurrentMap concurrentMap = new ConcurrentHashMap( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + concurrentMap.put( key, value ); + } + + return concurrentMap; + } + + @Override + public ConcurrentNavigableMap sourceFooMapToTargetFooConcurrentNavigableMap(Map foos) { + if ( foos == null ) { + return null; + } + + ConcurrentNavigableMap concurrentNavigableMap = new ConcurrentSkipListMap(); + + for ( java.util.Map.Entry entry : foos.entrySet() ) { + String key = String.valueOf( entry.getKey() ); + TargetFoo value = sourceFooToTargetFoo( entry.getValue() ); + concurrentNavigableMap.put( key, value ); + } + + return concurrentNavigableMap; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java new file mode 100644 index 0000000000..f34495cb28 --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/updatemethods/CompanyMapper1Impl.java @@ -0,0 +1,120 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.updatemethods; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-06-18T14:48:39+0200", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)" +) +public class CompanyMapper1Impl implements CompanyMapper1 { + + private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory(); + + @Override + public void toCompanyEntity(UnmappableCompanyDto dto, CompanyEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + if ( dto.getDepartment() != null ) { + if ( entity.getDepartment() == null ) { + entity.setDepartment( departmentEntityFactory.createDepartmentEntity() ); + } + unmappableDepartmentDtoToDepartmentEntity( dto.getDepartment(), entity.getDepartment() ); + } + else { + entity.setDepartment( null ); + } + } + + @Override + public void toInBetween(UnmappableDepartmentDto dto, DepartmentInBetween entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + } + + @Override + public void toDepartmentEntity(DepartmentInBetween dto, DepartmentEntity entity) { + if ( dto == null ) { + return; + } + + entity.setName( dto.getName() ); + } + + protected SecretaryEntity secretaryDtoToSecretaryEntity(SecretaryDto secretaryDto) { + if ( secretaryDto == null ) { + return null; + } + + SecretaryEntity secretaryEntity = new SecretaryEntity(); + + secretaryEntity.setName( secretaryDto.getName() ); + + return secretaryEntity; + } + + protected EmployeeEntity employeeDtoToEmployeeEntity(EmployeeDto employeeDto) { + if ( employeeDto == null ) { + return null; + } + + EmployeeEntity employeeEntity = new EmployeeEntity(); + + employeeEntity.setName( employeeDto.getName() ); + + return employeeEntity; + } + + protected Map secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap(Map map) { + if ( map == null ) { + return null; + } + + Map map1 = LinkedHashMap.newLinkedHashMap( map.size() ); + + for ( java.util.Map.Entry entry : map.entrySet() ) { + SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() ); + EmployeeEntity value = employeeDtoToEmployeeEntity( entry.getValue() ); + map1.put( key, value ); + } + + return map1; + } + + protected void unmappableDepartmentDtoToDepartmentEntity(UnmappableDepartmentDto unmappableDepartmentDto, DepartmentEntity mappingTarget) { + if ( unmappableDepartmentDto == null ) { + return; + } + + mappingTarget.setName( unmappableDepartmentDto.getName() ); + if ( mappingTarget.getSecretaryToEmployee() != null ) { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.getSecretaryToEmployee().clear(); + mappingTarget.getSecretaryToEmployee().putAll( map ); + } + else { + mappingTarget.setSecretaryToEmployee( null ); + } + } + else { + Map map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() ); + if ( map != null ) { + mappingTarget.setSecretaryToEmployee( map ); + } + } + } +} From 5232df2707b2c396f6d8bf6453a9f292684ef0f3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Sep 2024 15:06:36 +0200 Subject: [PATCH 0853/1006] Try to stabilise MapMappingTest and CarMapperTest --- .../org/mapstruct/ap/test/collection/map/MapMappingTest.java | 2 ++ .../test/java/org/mapstruct/ap/test/complex/CarMapperTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java index d0dd66d22b..1261525d4f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/map/MapMappingTest.java @@ -11,6 +11,7 @@ import java.util.HashMap; import java.util.Map; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.collection.map.other.ImportedType; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -26,6 +27,7 @@ */ @WithClasses({ SourceTargetMapper.class, CustomNumberMapper.class, Source.class, Target.class, ImportedType.class }) @IssueKey("44") +@DefaultTimeZone("UTC") public class MapMappingTest { @ProcessorTest diff --git a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java index 5eaf44765d..a1881a7613 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/complex/CarMapperTest.java @@ -11,6 +11,7 @@ import java.util.GregorianCalendar; import java.util.List; +import org.junitpioneer.jupiter.DefaultTimeZone; import org.mapstruct.ap.test.complex._target.CarDto; import org.mapstruct.ap.test.complex._target.PersonDto; import org.mapstruct.ap.test.complex.other.DateMapper; @@ -31,6 +32,7 @@ Category.class, DateMapper.class }) +@DefaultTimeZone("UTC") public class CarMapperTest { @ProcessorTest From 796dd9467486ec6ec91bdd919f663bde098896df Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Sep 2024 15:33:08 +0200 Subject: [PATCH 0854/1006] Update next release changelog with latest changes --- NEXT_RELEASE_CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 438f4e3a6f..19571780cd 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -2,11 +2,16 @@ ### Enhancements +* Use Java `LinkedHashSet` and `LinkedHashMap` new factory method with known capacity when on Java 19 or later (#3113) + ### Bugs * Inverse Inheritance Strategy not working for ignored mappings only with target (#3652) * Inconsistent ambiguous mapping method error when using `SubclassMapping`: generic vs raw types (#3668) * Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670) +* Deep mapping with multiple mappings broken in 1.6.0 (#3667) +* Two different constants are ignored in 1.6.0 (#3673) +* Inconsistent ambiguous mapping method error: generic vs raw types in 1.6.0 (#3668) ### Documentation From 12c9c6c1f067fde585a5f1aa4e7327d2770c7ef8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 6 Sep 2024 16:35:37 +0300 Subject: [PATCH 0855/1006] Use email variable for GitHub Bot git email --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36cabf44f8..f18a12b813 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,7 +38,7 @@ jobs: NEXT_VERSION=$COMPUTED_NEXT_VERSION fi ./mvnw -ntp -B versions:set versions:commit -DnewVersion=$RELEASE_VERSION -pl :mapstruct-parent -DgenerateBackupPoms=false - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --global user.email "${{ vars.GH_BOT_EMAIL }}" git config --global user.name "GitHub Action" git commit -a -m "Releasing version $RELEASE_VERSION" git push From 2686e852b6bd85295f723f705450d401e99f560d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Sep 2024 01:17:45 +0200 Subject: [PATCH 0856/1006] #3661 Use correct type for the Record component read accessors --- .../itest/tests/MavenIntegrationTest.java | 7 +++ .../module-1/pom.xml | 22 +++++++++ .../records/module1/NestedInterface.java | 10 +++++ .../itest/records/module1/RootInterface.java | 10 +++++ .../records/module1/SourceNestedRecord.java | 11 +++++ .../records/module1/SourceRootRecord.java | 11 +++++ .../module-2/pom.xml | 30 +++++++++++++ .../module2/RecordInterfaceIssueMapper.java | 18 ++++++++ .../records/module2/TargetNestedRecord.java | 11 +++++ .../records/module2/TargetRootRecord.java | 11 +++++ .../itest/records/module2/RecordsTest.java | 26 +++++++++++ .../recordsCrossModuleInterfaceTest/pom.xml | 26 +++++++++++ .../itest/records/mapper/RecordsTest.java | 0 .../ap/internal/model/common/Type.java | 4 +- .../mapstruct/ap/internal/util/Filters.java | 33 +++++--------- .../util/accessor/ElementAccessor.java | 45 +++++++++++++++++++ .../internal/util/accessor/ReadAccessor.java | 12 ++++- ...cessor.java => RecordElementAccessor.java} | 7 +-- 18 files changed, 265 insertions(+), 29 deletions(-) create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/pom.xml create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/NestedInterface.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/RootInterface.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceNestedRecord.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceRootRecord.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/pom.xml create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/RecordInterfaceIssueMapper.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetNestedRecord.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetRootRecord.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java create mode 100644 integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/pom.xml rename integrationtest/src/test/resources/recordsCrossModuleTest/mapper/{ => src}/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java (100%) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java rename processor/src/main/java/org/mapstruct/ap/internal/util/accessor/{FieldElementAccessor.java => RecordElementAccessor.java} (77%) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 7e9175dd92..0bef2994f6 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -131,6 +131,13 @@ void recordsTest() { void recordsCrossModuleTest() { } + @ProcessorTest(baseDir = "recordsCrossModuleInterfaceTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC + }) + @EnabledForJreRange(min = JRE.JAVA_17) + void recordsCrossModuleInterfaceTest() { + } + @ProcessorTest(baseDir = "expressionTextBlocksTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }) diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/pom.xml new file mode 100644 index 0000000000..72df10f62c --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + + recordsCrossModuleInterfaceTest + org.mapstruct + 1.0.0 + + + records-cross-module-1 + + diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/NestedInterface.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/NestedInterface.java new file mode 100644 index 0000000000..ffa53f88b1 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/NestedInterface.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module1; + +public interface NestedInterface { + String field(); +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/RootInterface.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/RootInterface.java new file mode 100644 index 0000000000..fb23ffe157 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/RootInterface.java @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module1; + +public interface RootInterface { + NestedInterface nested(); +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceNestedRecord.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceNestedRecord.java new file mode 100644 index 0000000000..6a0ddb86af --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceNestedRecord.java @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module1; + +public record SourceNestedRecord( + String field +) implements NestedInterface { +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceRootRecord.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceRootRecord.java new file mode 100644 index 0000000000..151ad5208d --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-1/src/main/java/org/mapstruct/itest/records/module1/SourceRootRecord.java @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module1; + +public record SourceRootRecord( + SourceNestedRecord nested +) implements RootInterface { +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/pom.xml new file mode 100644 index 0000000000..5f42efd18e --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/pom.xml @@ -0,0 +1,30 @@ + + + + 4.0.0 + + + recordsCrossModuleInterfaceTest + org.mapstruct + 1.0.0 + + + records-cross-module-2 + + + + + org.mapstruct + records-cross-module-1 + 1.0.0 + + + diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/RecordInterfaceIssueMapper.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/RecordInterfaceIssueMapper.java new file mode 100644 index 0000000000..a763359a98 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/RecordInterfaceIssueMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module2; + +import org.mapstruct.itest.records.module1.SourceRootRecord; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface RecordInterfaceIssueMapper { + + RecordInterfaceIssueMapper INSTANCE = Mappers.getMapper(RecordInterfaceIssueMapper.class); + + TargetRootRecord map(SourceRootRecord source); +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetNestedRecord.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetNestedRecord.java new file mode 100644 index 0000000000..d02a4b58e0 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetNestedRecord.java @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module2; + +public record TargetNestedRecord( + String field +) { +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetRootRecord.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetRootRecord.java new file mode 100644 index 0000000000..09a69f1bf1 --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/main/java/org/mapstruct/itest/records/module2/TargetRootRecord.java @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module2; + +public record TargetRootRecord( + TargetNestedRecord nested +) { +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java new file mode 100644 index 0000000000..5f7a99273a --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.module2; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.mapstruct.itest.records.module1.SourceRootRecord; +import org.mapstruct.itest.records.module1.SourceNestedRecord; + +public class RecordsTest { + + @Test + public void shouldMap() { + SourceRootRecord source = new SourceRootRecord( new SourceNestedRecord( "test" ) ); + TargetRootRecord target = RecordInterfaceIssueMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.nested() ).isNotNull(); + assertThat( target.nested().field() ).isEqualTo( "test" ); + } + +} diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/pom.xml b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/pom.xml new file mode 100644 index 0000000000..120c849dca --- /dev/null +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/pom.xml @@ -0,0 +1,26 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + recordsCrossModuleInterfaceTest + pom + + + module-1 + module-2 + + diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java similarity index 100% rename from integrationtest/src/test/resources/recordsCrossModuleTest/mapper/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java rename to integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 54305cffc1..6520834066 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -50,7 +50,7 @@ import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; -import org.mapstruct.ap.internal.util.accessor.FieldElementAccessor; +import org.mapstruct.ap.internal.util.accessor.ElementAccessor; import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; @@ -1047,7 +1047,7 @@ private List getAlternativeTargetAccessors() { List setterMethods = getSetters(); List readAccessors = new ArrayList<>( getPropertyReadAccessors().values() ); // All the fields are also alternative accessors - readAccessors.addAll( filters.fieldsIn( getAllFields(), FieldElementAccessor::new ) ); + readAccessors.addAll( filters.fieldsIn( getAllFields(), ElementAccessor::new ) ); // there could be a read accessor (field or method) for a list/map that is not present as setter. // an accessor could substitute the setter in that case and act as setter. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 123f72832b..5f7fe74bf2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -39,22 +39,16 @@ public class Filters { private static final Method RECORD_COMPONENTS_METHOD; - private static final Method RECORD_COMPONENT_ACCESSOR_METHOD; static { Method recordComponentsMethod; - Method recordComponentAccessorMethod; try { recordComponentsMethod = TypeElement.class.getMethod( "getRecordComponents" ); - recordComponentAccessorMethod = Class.forName( "javax.lang.model.element.RecordComponentElement" ) - .getMethod( "getAccessor" ); } - catch ( NoSuchMethodException | ClassNotFoundException e ) { + catch ( NoSuchMethodException e ) { recordComponentsMethod = null; - recordComponentAccessorMethod = null; } RECORD_COMPONENTS_METHOD = recordComponentsMethod; - RECORD_COMPONENT_ACCESSOR_METHOD = recordComponentAccessorMethod; } private final AccessorNamingUtils accessorNaming; @@ -89,25 +83,18 @@ public List recordComponentsIn(TypeElement typeElement) { } public Map recordAccessorsIn(Collection recordComponents) { - if ( RECORD_COMPONENT_ACCESSOR_METHOD == null ) { + if ( recordComponents.isEmpty() ) { return java.util.Collections.emptyMap(); } - try { - Map recordAccessors = new LinkedHashMap<>(); - for ( Element recordComponent : recordComponents ) { - ExecutableElement recordExecutableElement = - (ExecutableElement) RECORD_COMPONENT_ACCESSOR_METHOD.invoke( recordComponent ); - recordAccessors.put( - recordComponent.getSimpleName().toString(), - ReadAccessor.fromGetter( recordExecutableElement, getReturnType( recordExecutableElement ) ) - ); - } - - return recordAccessors; - } - catch ( IllegalAccessException | InvocationTargetException e ) { - return java.util.Collections.emptyMap(); + Map recordAccessors = new LinkedHashMap<>(); + for ( Element recordComponent : recordComponents ) { + recordAccessors.put( + recordComponent.getSimpleName().toString(), + ReadAccessor.fromRecordComponent( recordComponent ) + ); } + + return recordAccessors; } private TypeMirror getReturnType(ExecutableElement executableElement) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java new file mode 100644 index 0000000000..24e71cc85f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.accessor; + +import javax.lang.model.element.Element; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeMirror; + +/** + * An {@link Accessor} that wraps a {@link VariableElement}. + * + * @author Filip Hrisafov + */ +public class ElementAccessor extends AbstractAccessor { + + private final AccessorType accessorType; + + public ElementAccessor(VariableElement variableElement) { + this( variableElement, AccessorType.FIELD ); + } + + public ElementAccessor(Element element, AccessorType accessorType) { + super( element ); + this.accessorType = accessorType; + } + + @Override + public TypeMirror getAccessedType() { + return element.asType(); + } + + @Override + public String toString() { + return element.toString(); + } + + @Override + public AccessorType getAccessorType() { + return accessorType; + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java index a790a3361b..5177bfc75b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.util.accessor; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; @@ -17,7 +18,7 @@ public interface ReadAccessor extends Accessor { String getReadValueSource(); static ReadAccessor fromField(VariableElement variableElement) { - return new ReadDelegateAccessor( new FieldElementAccessor( variableElement ) ) { + return new ReadDelegateAccessor( new ElementAccessor( variableElement ) ) { @Override public String getReadValueSource() { return getSimpleName(); @@ -25,6 +26,15 @@ public String getReadValueSource() { }; } + static ReadAccessor fromRecordComponent(Element element) { + return new ReadDelegateAccessor( new ElementAccessor( element, AccessorType.GETTER ) ) { + @Override + public String getReadValueSource() { + return getSimpleName() + "()"; + } + }; + } + static ReadAccessor fromGetter(ExecutableElement element, TypeMirror accessedType) { return new ReadDelegateAccessor( new ExecutableElementAccessor( element, accessedType, AccessorType.GETTER ) ) { @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java similarity index 77% rename from processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java rename to processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java index 5174900532..d163f462f9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/FieldElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.util.accessor; +import javax.lang.model.element.Element; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; @@ -13,9 +14,9 @@ * * @author Filip Hrisafov */ -public class FieldElementAccessor extends AbstractAccessor { +public class RecordElementAccessor extends AbstractAccessor { - public FieldElementAccessor(VariableElement element) { + public RecordElementAccessor(Element element) { super( element ); } @@ -31,7 +32,7 @@ public String toString() { @Override public AccessorType getAccessorType() { - return AccessorType.FIELD; + return AccessorType.GETTER; } } From 4c1df35ba676814d06336ddf036f4408d9e0526d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Sep 2024 23:06:56 +0200 Subject: [PATCH 0857/1006] #3703 Use include model instead of manually writing the type name for return type for afterMappingReferencesWithFinalizedReturnType --- .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../ap/test/bugs/_3703/Issue3703Mapper.java | 37 +++++++++++++++++++ .../ap/test/bugs/_3703/Issue3703Test.java | 24 ++++++++++++ .../ap/test/bugs/_3703/dto/Contact.java | 37 +++++++++++++++++++ .../ap/test/bugs/_3703/entity/Contact.java | 37 +++++++++++++++++++ 5 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/dto/Contact.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/entity/Contact.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 8fb5bfdef0..61d9cc1837 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -136,7 +136,7 @@ <#if finalizerMethod??> <#if (afterMappingReferencesWithFinalizedReturnType?size > 0)> - ${returnType.name} ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; + <@includeModel object=returnType /> ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; <#list afterMappingReferencesWithFinalizedReturnType as callback> <#if callback_index = 0> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Mapper.java new file mode 100644 index 0000000000..287e7655fb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Mapper.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3703; + +import org.mapstruct.AfterMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ap.test.bugs._3703.dto.Contact; + +@Mapper +public interface Issue3703Mapper { + + Contact map(org.mapstruct.ap.test.bugs._3703.entity.Contact contact); + + org.mapstruct.ap.test.bugs._3703.entity.Contact map(Contact contact); + + @AfterMapping + default void afterMapping(@MappingTarget Contact target, org.mapstruct.ap.test.bugs._3703.entity.Contact contact) { + } + + @AfterMapping + default void afterMapping(@MappingTarget Contact.Builder targetBuilder, + org.mapstruct.ap.test.bugs._3703.entity.Contact contact) { + } + + @AfterMapping + default void afterMapping(@MappingTarget org.mapstruct.ap.test.bugs._3703.entity.Contact target, Contact contact) { + } + + @AfterMapping + default void afterMapping(@MappingTarget org.mapstruct.ap.test.bugs._3703.entity.Contact.Builder targetBuilder, + Contact contact) { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Test.java new file mode 100644 index 0000000000..ac5cae3959 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/Issue3703Test.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3703; + +import org.mapstruct.ap.test.bugs._3703.dto.Contact; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +@IssueKey("3703") +@WithClasses({ + Contact.class, + org.mapstruct.ap.test.bugs._3703.entity.Contact.class, + Issue3703Mapper.class +}) +public class Issue3703Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/dto/Contact.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/dto/Contact.java new file mode 100644 index 0000000000..a949864791 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/dto/Contact.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3703.dto; + +public class Contact { + + private final String name; + + private Contact(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static class Builder { + + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Contact build() { + return new Contact( name ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/entity/Contact.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/entity/Contact.java new file mode 100644 index 0000000000..31fde373fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3703/entity/Contact.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3703.entity; + +public class Contact { + + private final String name; + + private Contact(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public static class Builder { + + private String name; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Contact build() { + return new Contact( name ); + } + } +} From 3011dd77d7ee2de7a7a5d93d3e8e965bad971a43 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Sep 2024 10:28:20 +0200 Subject: [PATCH 0858/1006] #3678 before / after mapping for type using builder should only be kept if they are using the actual type in `@TargetType` or `@MappingTarget` --- .../ap/internal/model/BeanMappingMethod.java | 33 ++++- .../ap/test/bugs/_3678/Issue3678Mapper.java | 128 ++++++++++++++++++ .../ap/test/bugs/_3678/Issue3678Test.java | 50 +++++++ 3 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4ccf2bb49a..e6ac5b5bcf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -408,9 +408,8 @@ else if ( !method.isUpdateMethod() ) { existingVariableNames ) ); - // remove methods without parameters as they are already being invoked - removeMappingReferencesWithoutSourceParameters( beforeMappingReferencesWithFinalizedReturnType ); - removeMappingReferencesWithoutSourceParameters( afterMappingReferencesWithFinalizedReturnType ); + keepMappingReferencesUsingTarget( beforeMappingReferencesWithFinalizedReturnType, actualReturnType ); + keepMappingReferencesUsingTarget( afterMappingReferencesWithFinalizedReturnType, actualReturnType ); } Map presenceChecksByParameter = new LinkedHashMap<>(); @@ -453,8 +452,32 @@ else if ( !sourceParameter.getType().isPrimitive() ) { ); } - private void removeMappingReferencesWithoutSourceParameters(List references) { - references.removeIf( r -> r.getSourceParameters().isEmpty() && r.getReturnType().isVoid() ); + private void keepMappingReferencesUsingTarget(List references, Type type) { + references.removeIf( reference -> { + List bindings = reference.getParameterBindings(); + if ( bindings.isEmpty() ) { + return true; + } + for ( ParameterBinding binding : bindings ) { + if ( binding.isMappingTarget() ) { + if ( type.isAssignableTo( binding.getType() ) ) { + // If the mapping target matches the type then we need to keep this + return false; + } + } + else if ( binding.isTargetType() ) { + Type targetType = binding.getType(); + List targetTypeTypeParameters = targetType.getTypeParameters(); + if ( targetTypeTypeParameters.size() == 1 ) { + if ( type.isAssignableTo( targetTypeTypeParameters.get( 0 ) ) ) { + return false; + } + } + } + } + + return true; + } ); } private boolean doesNotAllowAbstractReturnTypeAndCanBeConstructed(Type returnTypeImpl) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Mapper.java new file mode 100644 index 0000000000..374fbf931a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Mapper.java @@ -0,0 +1,128 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3678; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3678Mapper { + + Issue3678Mapper INSTANCE = Mappers.getMapper( Issue3678Mapper.class ); + + @Mapping(target = "name", source = "sourceA.name") + @Mapping(target = "description", source = "sourceB.description") + Target map(SourceA sourceA, SourceB sourceB, @Context MappingContext context); + + @Mapping(target = "description", constant = "some description") + Target map(SourceA sourceA, @Context MappingContext context); + + class MappingContext { + + private final List invokedMethods = new ArrayList<>(); + + @BeforeMapping + public void beforeMappingSourceA(SourceA sourceA) { + invokedMethods.add( "beforeMappingSourceA" ); + } + + @AfterMapping + public void afterMappingSourceB(SourceA sourceA) { + invokedMethods.add( "afterMappingSourceA" ); + } + + @BeforeMapping + public void beforeMappingSourceB(SourceB sourceB) { + invokedMethods.add( "beforeMappingSourceB" ); + } + + @AfterMapping + public void afterMappingSourceB(SourceB sourceB) { + invokedMethods.add( "afterMappingSourceB" ); + } + + public List getInvokedMethods() { + return invokedMethods; + } + } + + class SourceA { + + private final String name; + + public SourceA(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } + + class SourceB { + + private final String description; + + public SourceB(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + } + + final class Target { + + private final String name; + private final String description; + + private Target(String name, String description) { + this.name = name; + this.description = description; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + + private String name; + private String description; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder description(String description) { + this.description = description; + return this; + } + + public Target build() { + return new Target( this.name, this.description ); + } + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Test.java new file mode 100644 index 0000000000..25e7e21622 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3678/Issue3678Test.java @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3678; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3678") +@WithClasses(Issue3678Mapper.class) +public class Issue3678Test { + + @ProcessorTest + void beforeAndAfterMappingOnlyCalledOnceForTwoSources() { + + Issue3678Mapper.MappingContext mappingContext = new Issue3678Mapper.MappingContext(); + Issue3678Mapper.SourceA sourceA = new Issue3678Mapper.SourceA( "name" ); + Issue3678Mapper.SourceB sourceB = new Issue3678Mapper.SourceB( "description" ); + Issue3678Mapper.INSTANCE.map( sourceA, sourceB, mappingContext ); + + assertThat( mappingContext.getInvokedMethods() ) + .containsExactly( + "beforeMappingSourceA", + "beforeMappingSourceB", + "afterMappingSourceA", + "afterMappingSourceB" + ); + } + + @ProcessorTest + void beforeAndAfterMappingOnlyCalledOnceForSingleSource() { + + Issue3678Mapper.MappingContext mappingContext = new Issue3678Mapper.MappingContext(); + Issue3678Mapper.SourceA sourceA = new Issue3678Mapper.SourceA( "name" ); + Issue3678Mapper.INSTANCE.map( sourceA, mappingContext ); + + assertThat( mappingContext.getInvokedMethods() ) + .containsExactly( + "beforeMappingSourceA", + "afterMappingSourceA" + ); + } + +} From c36f9ae5d10baa1fbae63df8a51e937db0569c07 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Sep 2024 17:11:24 +0200 Subject: [PATCH 0859/1006] Prepare release notes for 1.6.1 --- NEXT_RELEASE_CHANGELOG.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 19571780cd..5337e70daf 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,5 +1,3 @@ -### Features - ### Enhancements * Use Java `LinkedHashSet` and `LinkedHashMap` new factory method with known capacity when on Java 19 or later (#3113) @@ -12,8 +10,6 @@ * Deep mapping with multiple mappings broken in 1.6.0 (#3667) * Two different constants are ignored in 1.6.0 (#3673) * Inconsistent ambiguous mapping method error: generic vs raw types in 1.6.0 (#3668) - -### Documentation - -### Build - +* Fix cross module records with interfaces not recognizing accessors (#3661) +* `@AfterMapping` methods are called twice when using target with builder (#3678) +* Compile error when using `@AfterMapping` method with Builder and TargetObject (#3703) From 10d69878a197c1bff1e8743a3d056e36eda856d3 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 15:52:17 +0000 Subject: [PATCH 0860/1006] Releasing version 1.6.1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..3e347b5c93 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..ca326ef6f0 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..da17fa59dc 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f826421092..405f489865 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..5044ed7689 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 7c91837e79..96f86c6f0e 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 94c84fb4d0..8c36b4b6ea 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-09-15T15:52:17Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index f55f0955d3..a0e55059da 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index ed2df7718b..e605c32560 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.1 ../parent/pom.xml From c74e62a94c4c420ec5aa52fc177c56ea0483c50b Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:01:43 +0000 Subject: [PATCH 0861/1006] Next version 1.7.0-SNAPSHOT --- NEXT_RELEASE_CHANGELOG.md | 17 ++++++----------- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 10 files changed, 16 insertions(+), 21 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 5337e70daf..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,15 +1,10 @@ -### Enhancements +### Features -* Use Java `LinkedHashSet` and `LinkedHashMap` new factory method with known capacity when on Java 19 or later (#3113) +### Enhancements ### Bugs -* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652) -* Inconsistent ambiguous mapping method error when using `SubclassMapping`: generic vs raw types (#3668) -* Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670) -* Deep mapping with multiple mappings broken in 1.6.0 (#3667) -* Two different constants are ignored in 1.6.0 (#3673) -* Inconsistent ambiguous mapping method error: generic vs raw types in 1.6.0 (#3668) -* Fix cross module records with interfaces not recognizing accessors (#3661) -* `@AfterMapping` methods are called twice when using target with builder (#3678) -* Compile error when using `@AfterMapping` method with Builder and TargetObject (#3703) +### Documentation + +### Build + diff --git a/build-config/pom.xml b/build-config/pom.xml index 3e347b5c93..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index ca326ef6f0..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index da17fa59dc..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 405f489865..f826421092 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 5044ed7689..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 96f86c6f0e..7c91837e79 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8c36b4b6ea..94c84fb4d0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-09-15T15:52:17Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index a0e55059da..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index e605c32560..ed2df7718b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.1 + 1.7.0-SNAPSHOT ../parent/pom.xml From a3b4139070a3111872c3d17e0cb4dbcbaf8f4bf1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 16 Sep 2024 09:19:39 +0200 Subject: [PATCH 0862/1006] #3717 Fix ClassCastException when getting thrown types for a record accessor --- .../itest/records/nested/Address.java | 13 ++++++++++ .../itest/records/nested/CareProvider.java | 13 ++++++++++ .../itest/records/nested/CareProviderDto.java | 13 ++++++++++ .../records/nested/CareProviderMapper.java | 25 ++++++++++++++++++ .../records/nested/NestedRecordsTest.java | 26 +++++++++++++++++++ .../ap/internal/model/common/TypeFactory.java | 6 ++++- 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/Address.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProvider.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderDto.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderMapper.java create mode 100644 integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/Address.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/Address.java new file mode 100644 index 0000000000..fb857e90ca --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/Address.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.nested; + +/** + * @author Filip Hrisafov + */ +public record Address(String street, String city) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProvider.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProvider.java new file mode 100644 index 0000000000..a0ce13c0ba --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProvider.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.nested; + +/** + * @author Filip Hrisafov + */ +public record CareProvider(String externalId, Address address) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderDto.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderDto.java new file mode 100644 index 0000000000..d7ce7229e9 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderDto.java @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.nested; + +/** + * @author Filip Hrisafov + */ +public record CareProviderDto(String id, String street, String city) { + +} diff --git a/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderMapper.java b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderMapper.java new file mode 100644 index 0000000000..89ed688976 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/main/java/org/mapstruct/itest/records/nested/CareProviderMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.nested; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface CareProviderMapper { + + CareProviderMapper INSTANCE = Mappers.getMapper( CareProviderMapper.class ); + + @Mapping(target = "id", source = "externalId") + @Mapping(target = "street", source = "address.street") + @Mapping(target = "city", source = "address.city") + CareProviderDto map(CareProvider source); +} diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java new file mode 100644 index 0000000000..c8ccaf1a65 --- /dev/null +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.itest.records.nested; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class NestedRecordsTest { + + @Test + public void shouldMapRecord() { + CareProvider source = new CareProvider( "kermit", new Address( "Sesame Street", "New York" ) ); + CareProviderDto target = CareProviderMapper.INSTANCE.map( source ); + + assertThat( target ).isNotNull(); + assertThat( target.id() ).isEqualTo( "kermit" ); + assertThat( target.street() ).isEqualTo( "Sesame Street" ); + assertThat( target.city() ).isEqualTo( "New York" ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index d65070426b..ceb190a332 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -491,7 +491,11 @@ public List getThrownTypes(Accessor accessor) { if (accessor.getAccessorType().isFieldAssignment()) { return new ArrayList<>(); } - return extractTypes( ( (ExecutableElement) accessor.getElement() ).getThrownTypes() ); + Element element = accessor.getElement(); + if ( element instanceof ExecutableElement ) { + return extractTypes( ( (ExecutableElement) element ).getThrownTypes() ); + } + return new ArrayList<>(); } private List extractTypes(List typeMirrors) { From 4fd22d6b267f845038786364f46f16c5b0903d0a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 16 Sep 2024 09:54:30 +0200 Subject: [PATCH 0863/1006] Prepare release notes for 1.6.2 --- NEXT_RELEASE_CHANGELOG.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index e0f4cd31f0..dd5c9b2349 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,10 +1,3 @@ -### Features - -### Enhancements - ### Bugs -### Documentation - -### Build - +* Regression from 1.6.1: ClassCastException when using records (#3717) From 212607b4470c9e0deb8b6ad1fed56d016d58aa08 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 07:55:31 +0000 Subject: [PATCH 0864/1006] Releasing version 1.6.2 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..fa50066316 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..648c193e39 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..37ea12be4d 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f826421092..4539528a91 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..dfac83cca8 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 7c91837e79..ab8dcb26b7 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 94c84fb4d0..94f614ecbb 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-09-16T07:55:31Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index f55f0955d3..919e2d6460 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index ed2df7718b..e0052bf5d4 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.2 ../parent/pom.xml From 4e0d73db1d17c40d251d39812550206607a16824 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:06:43 +0000 Subject: [PATCH 0865/1006] Next version 1.7.0-SNAPSHOT --- NEXT_RELEASE_CHANGELOG.md | 9 ++++++++- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 10 files changed, 18 insertions(+), 11 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index dd5c9b2349..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,3 +1,10 @@ +### Features + +### Enhancements + ### Bugs -* Regression from 1.6.1: ClassCastException when using records (#3717) +### Documentation + +### Build + diff --git a/build-config/pom.xml b/build-config/pom.xml index fa50066316..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 648c193e39..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index 37ea12be4d..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4539528a91..f826421092 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index dfac83cca8..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index ab8dcb26b7..7c91837e79 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 94f614ecbb..94c84fb4d0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-09-16T07:55:31Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 919e2d6460..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index e0052bf5d4..ed2df7718b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.2 + 1.7.0-SNAPSHOT ../parent/pom.xml From 26c5bcd923c7206ad161e93237f841a79ca85efd Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 27 Sep 2024 09:15:17 +0200 Subject: [PATCH 0866/1006] Update readme with 1.6.2 --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index c0f798af83..7903ddeb84 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.6.0-blue.svg)](https://central.sonatype.com/search?q=g:org.mapstruct%20v:1.6.0) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.6.2-blue.svg)](https://central.sonatype.com/search?q=g:org.mapstruct%20v:1.6.2) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://central.sonatype.com/search?q=g:org.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/main/LICENSE.txt) @@ -65,7 +65,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.6.0 + 1.6.2 ... @@ -111,10 +111,10 @@ plugins { dependencies { ... - implementation 'org.mapstruct:mapstruct:1.6.0' + implementation 'org.mapstruct:mapstruct:1.6.2' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.0' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.2' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.2' // if you are using mapstruct in test code } ... ``` From 32f1fea7b50ab583b87e3634e25ac92752380682 Mon Sep 17 00:00:00 2001 From: Srimathi-S <75327301+Srimathi-S@users.noreply.github.com> Date: Sun, 3 Nov 2024 17:22:52 +0530 Subject: [PATCH 0867/1006] #3370 Prevent stack overflow error for Immutables with custom builder --- .../ap/spi/DefaultBuilderProvider.java | 9 +- .../ap/spi/ImmutablesBuilderProvider.java | 27 +- .../bugs/_3370/Issue3370BuilderProvider.java | 25 ++ .../ap/test/bugs/_3370/Issue3370Test.java | 55 +++ .../ap/test/bugs/_3370/ItemMapper.java | 19 ++ .../test/bugs/_3370/domain/ImmutableItem.java | 316 ++++++++++++++++++ .../ap/test/bugs/_3370/domain/Item.java | 27 ++ .../ap/test/bugs/_3370/dto/ItemDTO.java | 26 ++ 8 files changed, 496 insertions(+), 8 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370BuilderProvider.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/ItemMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/ImmutableItem.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/Item.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/dto/ItemDTO.java diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 6395364a35..92cd1ed80d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -176,6 +176,10 @@ public DeclaredType visitDeclared(DeclaredType t, Void p) { * @throws MoreThanOneBuilderCreationMethodException if there are multiple builder creation methods */ protected BuilderInfo findBuilderInfo(TypeElement typeElement) { + return findBuilderInfo( typeElement, true ); + } + + protected BuilderInfo findBuilderInfo(TypeElement typeElement, boolean checkParent) { if ( shouldIgnore( typeElement ) ) { return null; } @@ -203,7 +207,10 @@ else if ( builderInfo.size() > 1 ) { throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), builderInfo ); } - return findBuilderInfo( typeElement.getSuperclass() ); + if ( checkParent ) { + return findBuilderInfo( typeElement.getSuperclass() ); + } + return null; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java index d4ccd029ef..3431808418 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/ImmutablesBuilderProvider.java @@ -35,18 +35,31 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement) { if ( name.length() == 0 || JAVA_JAVAX_PACKAGE.matcher( name ).matches() ) { return null; } + + // First look if there is a builder defined in my own type + BuilderInfo info = findBuilderInfo( typeElement, false ); + if ( info != null ) { + return info; + } + + // Check for a builder in the generated immutable type + BuilderInfo immutableInfo = findBuilderInfoForImmutables( typeElement ); + if ( immutableInfo != null ) { + return immutableInfo; + } + + return super.findBuilderInfo( typeElement.getSuperclass() ); + } + + protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement) { TypeElement immutableAnnotation = elementUtils.getTypeElement( IMMUTABLE_FQN ); if ( immutableAnnotation != null ) { - BuilderInfo info = findBuilderInfoForImmutables( + return findBuilderInfoForImmutables( typeElement, immutableAnnotation ); - if ( info != null ) { - return info; - } } - - return super.findBuilderInfo( typeElement ); + return null; } protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, @@ -55,7 +68,7 @@ protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement, if ( typeUtils.isSameType( annotationMirror.getAnnotationType(), immutableAnnotation.asType() ) ) { TypeElement immutableElement = asImmutableElement( typeElement ); if ( immutableElement != null ) { - return super.findBuilderInfo( immutableElement ); + return super.findBuilderInfo( immutableElement, false ); } else { // Immutables processor has not run yet. Trigger a postpone to the next round for MapStruct diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370BuilderProvider.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370BuilderProvider.java new file mode 100644 index 0000000000..55a3f783c3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370BuilderProvider.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370; + +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; + +import org.mapstruct.ap.spi.BuilderInfo; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesBuilderProvider; + +public class Issue3370BuilderProvider extends ImmutablesBuilderProvider implements BuilderProvider { + + @Override + protected BuilderInfo findBuilderInfoForImmutables(TypeElement typeElement) { + Name name = typeElement.getQualifiedName(); + if ( name.toString().endsWith( ".Item" ) ) { + return super.findBuilderInfo( asImmutableElement( typeElement ) ); + } + return super.findBuilderInfo( typeElement ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370Test.java new file mode 100644 index 0000000000..0389de5b46 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/Issue3370Test.java @@ -0,0 +1,55 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370; + +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.ap.spi.AccessorNamingStrategy; +import org.mapstruct.ap.spi.BuilderProvider; +import org.mapstruct.ap.spi.ImmutablesAccessorNamingStrategy; +import org.mapstruct.ap.test.bugs._3370.domain.ImmutableItem; +import org.mapstruct.ap.test.bugs._3370.domain.Item; +import org.mapstruct.ap.test.bugs._3370.dto.ItemDTO; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithServiceImplementation; +import org.mapstruct.ap.testutil.WithServiceImplementations; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + ItemMapper.class, + Item.class, + ImmutableItem.class, + ItemDTO.class, +}) +@IssueKey("3370") +@WithServiceImplementations({ + @WithServiceImplementation(provides = BuilderProvider.class, value = Issue3370BuilderProvider.class), + @WithServiceImplementation(provides = AccessorNamingStrategy.class, + value = ImmutablesAccessorNamingStrategy.class), +}) +public class Issue3370Test { + + @ProcessorTest + public void shouldUseBuilderOfImmutableSuperClass() { + + Map attributesMap = new HashMap<>(); + attributesMap.put( "a", "b" ); + attributesMap.put( "c", "d" ); + + ItemDTO item = new ItemDTO( "test", attributesMap ); + + Item target = ItemMapper.INSTANCE.map( item ); + + assertThat( target ).isNotNull(); + assertThat( target.getId() ).isEqualTo( "test" ); + assertThat( target.getAttributes() ).isEqualTo( attributesMap ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/ItemMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/ItemMapper.java new file mode 100644 index 0000000000..5583e191b3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/ItemMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.bugs._3370.domain.Item; +import org.mapstruct.ap.test.bugs._3370.dto.ItemDTO; +import org.mapstruct.factory.Mappers; + +@Mapper +public abstract class ItemMapper { + + public static final ItemMapper INSTANCE = Mappers.getMapper( ItemMapper.class ); + + public abstract Item map(ItemDTO itemDTO); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/ImmutableItem.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/ImmutableItem.java new file mode 100644 index 0000000000..9258914c0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/ImmutableItem.java @@ -0,0 +1,316 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370.domain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * Immutable implementation of {@link Item}. + *

      + * Use the builder to create immutable instances: + * {@code new Item.Builder()}. + */ +@SuppressWarnings("all") +public final class ImmutableItem extends Item { + private final String id; + private final Map attributes; + + private ImmutableItem(String id, Map attributes) { + this.id = id; + this.attributes = attributes; + } + + /** + * @return The value of the {@code id} attribute + */ + @Override + public String getId() { + return id; + } + + /** + * @return The value of the {@code attributes} attribute + */ + @Override + public Map getAttributes() { + return attributes; + } + + /** + * Copy the current immutable object by setting a value for the {@link Item#getId() id} attribute. + * An equals check used to prevent copying of the same value by returning {@code this}. + * + * @param id A new value for id + * @return A modified copy of the {@code this} object + */ + public final ImmutableItem withId(String id) { + if ( this.id.equals( id ) ) { + return this; + } + String newValue = Objects.requireNonNull( id, "id" ); + return new ImmutableItem( newValue, this.attributes ); + } + + /** + * Copy the current immutable object by replacing the {@link Item#getAttributes() attributes} map with the specified map. + * Nulls are not permitted as keys or values. + * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. + * + * @param attributes The entries to be added to the attributes map + * @return A modified copy of {@code this} object + */ + public final ImmutableItem withAttributes(Map attributes) { + if ( this.attributes == attributes ) { + return this; + } + Map newValue = createUnmodifiableMap( true, false, attributes ); + return new ImmutableItem( this.id, newValue ); + } + + /** + * This instance is equal to all instances of {@code ImmutableItem} that have equal attribute values. + * + * @return {@code true} if {@code this} is equal to {@code another} instance + */ + @Override + public boolean equals(Object another) { + if ( this == another ) { + return true; + } + return another instanceof ImmutableItem + && equalTo( (ImmutableItem) another ); + } + + private boolean equalTo(ImmutableItem another) { + return id.equals( another.id ) + && attributes.equals( another.attributes ); + } + + /** + * Computes a hash code from attributes: {@code id}, {@code attributes}. + * + * @return hashCode value + */ + @Override + public int hashCode() { + int h = 31; + h = h * 17 + id.hashCode(); + h = h * 17 + attributes.hashCode(); + return h; + } + + /** + * Prints the immutable value {@code Item} with attribute values. + * + * @return A string representation of the value + */ + @Override + public String toString() { + return "Item{" + + "id=" + id + + ", attributes=" + attributes + + "}"; + } + + /** + * Creates an immutable copy of a {@link Item} value. + * Uses accessors to get values to initialize the new immutable instance. + * If an instance is already immutable, it is returned as is. + * + * @param instance The instance to copy + * @return A copied immutable Item instance + */ + public static ImmutableItem copyOf(Item instance) { + if ( instance instanceof ImmutableItem ) { + return (ImmutableItem) instance; + } + return new Item.Builder() + .from( instance ) + .build(); + } + + /** + * Builds instances of type {@link ImmutableItem ImmutableItem}. + * Initialize attributes and then invoke the {@link #build()} method to create an + * immutable instance. + *

      {@code Builder} is not thread-safe and generally should not be stored in a field or collection, + * but instead used immediately to create instances. + */ + public static class Builder { + private static final long INIT_BIT_ID = 0x1L; + private long initBits = 0x1L; + + private String id; + private Map attributes = new LinkedHashMap(); + + /** + * Creates a builder for {@link ImmutableItem ImmutableItem} instances. + */ + public Builder() { + if ( !( this instanceof Item.Builder ) ) { + throw new UnsupportedOperationException( "Use: new Item.Builder()" ); + } + } + + /** + * Fill a builder with attribute values from the provided {@code Item} instance. + * Regular attribute values will be replaced with those from the given instance. + * Absent optional values will not replace present values. + * Collection elements and entries will be added, not replaced. + * + * @param instance The instance from which to copy values + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder from(Item instance) { + Objects.requireNonNull( instance, "instance" ); + id( instance.getId() ); + putAllAttributes( instance.getAttributes() ); + return (Item.Builder) this; + } + + /** + * Initializes the value for the {@link Item#getId() id} attribute. + * + * @param id The value for id + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder id(String id) { + this.id = Objects.requireNonNull( id, "id" ); + initBits &= ~INIT_BIT_ID; + return (Item.Builder) this; + } + + /** + * Put one entry to the {@link Item#getAttributes() attributes} map. + * + * @param key The key in the attributes map + * @param value The associated value in the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder putAttributes(String key, String value) { + this.attributes.put( + Objects.requireNonNull( key, "attributes key" ), + Objects.requireNonNull( value, "attributes value" ) + ); + return (Item.Builder) this; + } + + /** + * Put one entry to the {@link Item#getAttributes() attributes} map. Nulls are not permitted + * + * @param entry The key and value entry + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder putAttributes(Map.Entry entry) { + String k = entry.getKey(); + String v = entry.getValue(); + this.attributes.put( + Objects.requireNonNull( k, "attributes key" ), + Objects.requireNonNull( v, "attributes value" ) + ); + return (Item.Builder) this; + } + + /** + * Sets or replaces all mappings from the specified map as entries for the {@link Item#getAttributes() attributes} map. Nulls are not permitted + * + * @param attributes The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder attributes(Map attributes) { + this.attributes.clear(); + return putAllAttributes( attributes ); + } + + /** + * Put all mappings from the specified map as entries to {@link Item#getAttributes() attributes} map. Nulls are not permitted + * + * @param attributes The entries that will be added to the attributes map + * @return {@code this} builder for use in a chained invocation + */ + public final Item.Builder putAllAttributes(Map attributes) { + for ( Map.Entry entry : attributes.entrySet() ) { + String k = entry.getKey(); + String v = entry.getValue(); + this.attributes.put( + Objects.requireNonNull( k, "attributes key" ), + Objects.requireNonNull( v, "attributes value" ) + ); + } + return (Item.Builder) this; + } + + /** + * Builds a new {@link ImmutableItem ImmutableItem}. + * + * @return An immutable instance of Item + * @throws java.lang.IllegalStateException if any required attributes are missing + */ + public ImmutableItem build() { + if ( initBits != 0 ) { + throw new IllegalStateException( formatRequiredAttributesMessage() ); + } + return new ImmutableItem( id, createUnmodifiableMap( false, false, attributes ) ); + } + + private String formatRequiredAttributesMessage() { + List attributes = new ArrayList(); + if ( ( initBits & INIT_BIT_ID ) != 0 ) { + attributes.add( "id" ); + } + return "Cannot build Item, some of required attributes are not set " + attributes; + } + } + + private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, + Map map) { + switch ( map.size() ) { + case 0: + return Collections.emptyMap(); + case 1: { + Map.Entry e = map.entrySet().iterator().next(); + K k = e.getKey(); + V v = e.getValue(); + if ( checkNulls ) { + Objects.requireNonNull( k, "key" ); + Objects.requireNonNull( v, "value" ); + } + if ( skipNulls && ( k == null || v == null ) ) { + return Collections.emptyMap(); + } + return Collections.singletonMap( k, v ); + } + default: { + Map linkedMap = new LinkedHashMap( map.size() ); + if ( skipNulls || checkNulls ) { + for ( Map.Entry e : map.entrySet() ) { + K k = e.getKey(); + V v = e.getValue(); + if ( skipNulls ) { + if ( k == null || v == null ) { + continue; + } + } + else if ( checkNulls ) { + Objects.requireNonNull( k, "key" ); + Objects.requireNonNull( v, "value" ); + } + linkedMap.put( k, v ); + } + } + else { + linkedMap.putAll( map ); + } + return Collections.unmodifiableMap( linkedMap ); + } + } + } +} \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/Item.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/Item.java new file mode 100644 index 0000000000..a78c3bc007 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/domain/Item.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370.domain; + +import java.util.Collections; +import java.util.Map; + +public abstract class Item { + + public abstract String getId(); + + public abstract Map getAttributes(); + + public static Item.Builder builder() { + return new Item.Builder(); + } + + public static class Builder extends ImmutableItem.Builder { + + public ImmutableItem.Builder addSomeData(String key, String data) { + return super.attributes( Collections.singletonMap( key, data ) ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/dto/ItemDTO.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/dto/ItemDTO.java new file mode 100644 index 0000000000..70dba87fe4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3370/dto/ItemDTO.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3370.dto; + +import java.util.Map; + +public class ItemDTO { + private final String id; + private final Map attributes; + + public ItemDTO(String id, Map attributes) { + this.id = id; + this.attributes = attributes; + } + + public String getId() { + return id; + } + + public Map getAttributes() { + return attributes; + } +} From 21fdaa0f824fc358efc05507c591f86767fa3245 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 3 Nov 2024 12:54:37 +0100 Subject: [PATCH 0868/1006] #3747 Do not generate redundant if condition with constructor mapping and RETURN_DEFAULT null value mapping strategy --- .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../ap/test/bugs/_3747/Issue3747Mapper.java | 42 +++++++++++++++++++ .../ap/test/bugs/_3747/Issue3747Test.java | 28 +++++++++++++ .../test/bugs/_3747/Issue3747MapperImpl.java | 29 +++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Test.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3747/Issue3747MapperImpl.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 61d9cc1837..3036e4a2c8 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -116,7 +116,7 @@ - <#else> + <#elseif !propertyMappingsByParameter(sourceParameters[0]).empty> <#if mapNullToDefault>if ( <@includeModel object=getPresenceCheckByParameter(sourceParameters[0]) /> ) { <#list propertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Mapper.java new file mode 100644 index 0000000000..04addc43f3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Mapper.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3747; + +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT) +public interface Issue3747Mapper { + + Target map(Source source); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Test.java new file mode 100644 index 0000000000..57650e4dc0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3747/Issue3747Test.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3747; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3747") +@WithClasses(Issue3747Mapper.class) +class Issue3747Test { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void shouldNotGenerateObsoleteCode() { + generatedSource.addComparisonToFixtureFor( Issue3747Mapper.class ); + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3747/Issue3747MapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3747/Issue3747MapperImpl.java new file mode 100644 index 0000000000..adc937dab1 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_3747/Issue3747MapperImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3747; + +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-11-03T12:50:02+0100", + comments = "version: , compiler: javac, environment: Java 21.0.3 (N/A)" +) +public class Issue3747MapperImpl implements Issue3747Mapper { + + @Override + public Target map(Source source) { + + String value = null; + if ( source != null ) { + value = source.getValue(); + } + + Target target = new Target( value ); + + return target; + } +} From c2bd847599c1cdfad562eb02ca47b16e8dfa56d6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Nov 2024 10:15:33 +0100 Subject: [PATCH 0869/1006] #3732 Do not generate obsolete imports for LocalDateTime <-> LocalDate conversion --- ...avaLocalDateTimeToLocalDateConversion.java | 16 ------- .../ap/test/bugs/_3732/Issue3732Mapper.java | 47 +++++++++++++++++++ .../ap/test/bugs/_3732/Issue3732Test.java | 22 +++++++++ 3 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java index ae571ad6b0..9116bada4c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/JavaLocalDateTimeToLocalDateConversion.java @@ -7,11 +7,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; -import org.mapstruct.ap.internal.model.common.Type; -import org.mapstruct.ap.internal.util.Collections; /** * SimpleConversion for mapping {@link LocalDateTime} to @@ -25,22 +22,9 @@ protected String getToExpression(ConversionContext conversionContext) { return ".toLocalDate()"; } - @Override - protected Set getToConversionImportTypes(ConversionContext conversionContext) { - return Collections.asSet( - conversionContext.getTypeFactory().getType( LocalDate.class ) - ); - } - @Override protected String getFromExpression(ConversionContext conversionContext) { return ".atStartOfDay()"; } - @Override - protected Set getFromConversionImportTypes(ConversionContext conversionContext) { - return Collections.asSet( - conversionContext.getTypeFactory().getType( LocalDateTime.class ) - ); - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Mapper.java new file mode 100644 index 0000000000..79b13aa8ce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Mapper.java @@ -0,0 +1,47 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3732; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3732Mapper { + + Target map(Source source); + + Source map(Target source); + + class Source { + private LocalDateTime value; + + public LocalDateTime getValue() { + return value; + } + + public void setValue(LocalDateTime value) { + this.value = value; + } + } + + class Target { + + private LocalDate value; + + public LocalDate getValue() { + return value; + } + + public void setValue(LocalDate value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Test.java new file mode 100644 index 0000000000..9dbd9c0bb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3732/Issue3732Test.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3732; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3732") +@WithClasses({ Issue3732Mapper.class }) +class Issue3732Test { + + @ProcessorTest + void shouldGenerateCorrectMapper() { + } +} From efdf435770dd4361ccfa6e64d643cc88f156e79e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Nov 2024 10:44:54 +0100 Subject: [PATCH 0870/1006] #3751 Improve readme to include support for Java 16+ records --- readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7903ddeb84..6932f4d748 100644 --- a/readme.md +++ b/readme.md @@ -19,7 +19,10 @@ ## What is MapStruct? -MapStruct is a Java [annotation processor](https://docs.oracle.com/javase/6/docs/technotes/guides/apt/index.html) for the generation of type-safe and performant mappers for Java bean classes. It saves you from writing mapping code by hand, which is a tedious and error-prone task. The generator comes with sensible defaults and many built-in type conversions, but it steps out of your way when it comes to configuring or implementing special behavior. +MapStruct is a Java [annotation processor](https://docs.oracle.com/en/java/javase/21/docs/specs/man/javac.html#annotation-processing) designed to generate type-safe and high-performance mappers for Java bean classes, including support for Java 16+ records. +By automating the creation of mappings, MapStruct eliminates the need for tedious and error-prone manual coding. +The generator provides sensible defaults and built-in type conversions, allowing it to handle standard mappings effortlessly, while also offering flexibility for custom configurations or specialized mapping behaviors. +With seamless integration into modern Java projects, MapStruct can map between conventional beans, records, and even complex hierarchies, making it an adaptable tool for diverse Java applications. Compared to mapping frameworks working at runtime, MapStruct offers the following advantages: From 772fae4c77ccd0d35c33afa7f04431090a964692 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 9 Nov 2024 12:20:14 +0100 Subject: [PATCH 0871/1006] Prepare release notes for 1.6.3 --- NEXT_RELEASE_CHANGELOG.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index e0f4cd31f0..dca36c820a 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,10 +1,9 @@ -### Features - -### Enhancements - ### Bugs -### Documentation +* Redundant if condition in Java record mapping with `RETURN_DEFAULT` strategy (#3747) +* Stackoverflow with Immutables custom builder (#3370) +* Unused import of `java.time.LocalDate` when mapping source `LocalDateTime` to target `LocalDate` (#3732) -### Build +### Documentation +* Add section to README.md comparing mapstruct with Java Records (#3751) From b4e25e49deae707b50ce061172e114292b414a23 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:31:12 +0000 Subject: [PATCH 0872/1006] Releasing version 1.6.3 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..e60cda2afe 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..adec24c93b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..e276a889ce 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index f826421092..4d820495cd 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..45f4eb19c6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 7c91837e79..d686c5a368 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 94c84fb4d0..ded84caf2e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2024-11-09T11:31:12Z 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index f55f0955d3..9df5b02892 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index ed2df7718b..7410fd0a35 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.6.3 ../parent/pom.xml From 5bf2b152afcb5e3f4335f35ea9e0d747963e4298 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 9 Nov 2024 11:40:01 +0000 Subject: [PATCH 0873/1006] Next version 1.7.0-SNAPSHOT --- NEXT_RELEASE_CHANGELOG.md | 11 ++++++----- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index dca36c820a..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,9 +1,10 @@ -### Bugs +### Features + +### Enhancements -* Redundant if condition in Java record mapping with `RETURN_DEFAULT` strategy (#3747) -* Stackoverflow with Immutables custom builder (#3370) -* Unused import of `java.time.LocalDate` when mapping source `LocalDateTime` to target `LocalDate` (#3732) +### Bugs ### Documentation -* Add section to README.md comparing mapstruct with Java Records (#3751) +### Build + diff --git a/build-config/pom.xml b/build-config/pom.xml index e60cda2afe..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index adec24c93b..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e276a889ce..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index 4d820495cd..f826421092 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 45f4eb19c6..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index d686c5a368..7c91837e79 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index ded84caf2e..94c84fb4d0 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2024-11-09T11:31:12Z + ${git.commit.author.time} 1.0.0.Alpha3 3.4.1 diff --git a/pom.xml b/pom.xml index 9df5b02892..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 7410fd0a35..ed2df7718b 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.6.3 + 1.7.0-SNAPSHOT ../parent/pom.xml From 0df3f6af957c1468ae4baaf85b528131fbde9711 Mon Sep 17 00:00:00 2001 From: cussle <109949453+cussle@users.noreply.github.com> Date: Thu, 14 Nov 2024 05:22:57 +0900 Subject: [PATCH 0874/1006] docs & refactor: fix typos and improve readability in multiple classes (#3767) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AnnotatedConstructor: Fixed a variable name typo (noArgConstructorToInBecluded → noArgConstructorToBeIncluded). - AbstractBaseBuilder: Improved Javadoc by fixing typos and clarifying wording. - SourceRhsSelector: Corrected a typo in the class-level Javadoc. - InheritanceSelector: Enhanced readability by fixing typos and refining comments. --- .../ap/internal/model/AbstractBaseBuilder.java | 4 ++-- .../ap/internal/model/AnnotatedConstructor.java | 8 ++++---- .../model/source/selector/InheritanceSelector.java | 10 +++++----- .../model/source/selector/SourceRhsSelector.java | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 311cc00368..56a1831d52 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -41,7 +41,7 @@ public B method(Method sourceMethod) { } /** - * Checks if MapStruct is allowed to generate an automatic sub-mapping between {@code sourceType} and @{code + * Checks if MapStruct is allowed to generate an automatic sub-mapping between {@code sourceType} and {@code * targetType}. * This will evaluate to {@code true}, when: *

    11. @@ -66,7 +66,7 @@ private boolean isDisableSubMappingMethodsGeneration() { /** * Creates a forged assignment from the provided {@code sourceRHS} and {@code forgedMethod}. If a mapping method - * for the {@code forgedMethod} already exists, then this method used for the assignment. + * for the {@code forgedMethod} already exists, this method will be used for the assignment. * * @param sourceRHS that needs to be used for the assignment * @param forgedMethod the forged method for which we want to create an {@link Assignment} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java index 1c38b1062b..889d602cdb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedConstructor.java @@ -36,14 +36,14 @@ public static AnnotatedConstructor forComponentModels(String name, if ( constructor instanceof NoArgumentConstructor ) { noArgumentConstructor = (NoArgumentConstructor) constructor; } - NoArgumentConstructor noArgConstructorToInBecluded = null; + NoArgumentConstructor noArgConstructorToBeIncluded = null; Set fragmentsToBeIncluded = Collections.emptySet(); if ( includeNoArgConstructor ) { if ( noArgumentConstructor != null ) { - noArgConstructorToInBecluded = noArgumentConstructor; + noArgConstructorToBeIncluded = noArgumentConstructor; } else { - noArgConstructorToInBecluded = new NoArgumentConstructor( name, fragmentsToBeIncluded ); + noArgConstructorToBeIncluded = new NoArgumentConstructor( name, fragmentsToBeIncluded ); } } else if ( noArgumentConstructor != null ) { @@ -53,7 +53,7 @@ else if ( noArgumentConstructor != null ) { name, mapperReferences, annotations, - noArgConstructorToInBecluded, + noArgConstructorToBeIncluded, fragmentsToBeIncluded ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java index 297dcaa4a3..9a4fba6e30 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/InheritanceSelector.java @@ -33,7 +33,7 @@ public List> getMatchingMethods(List int addToCandidateListIfMinimal(List> candidatesWithBestMathingType, + private int addToCandidateListIfMinimal(List> candidatesWithBestMatchingType, int bestMatchingTypeDistance, SelectedMethod method, int currentTypeDistance) { if ( currentTypeDistance == bestMatchingTypeDistance ) { - candidatesWithBestMathingType.add( method ); + candidatesWithBestMatchingType.add( method ); } else if ( currentTypeDistance < bestMatchingTypeDistance ) { bestMatchingTypeDistance = currentTypeDistance; - candidatesWithBestMathingType.clear(); - candidatesWithBestMathingType.add( method ); + candidatesWithBestMatchingType.clear(); + candidatesWithBestMatchingType.add( method ); } return bestMatchingTypeDistance; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java index fb797f5808..91a30902e0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SourceRhsSelector.java @@ -12,7 +12,7 @@ import org.mapstruct.ap.internal.model.source.Method; /** - * Selector that tries to resolve an ambiquity between methods that contain source parameters and + * Selector that tries to resolve an ambiguity between methods that contain source parameters and * {@link org.mapstruct.ap.internal.model.common.SourceRHS SourceRHS} type parameters. * @author Filip Hrisafov */ From 8de18e5a65a353e6ff12f6a8f130a08173bf9672 Mon Sep 17 00:00:00 2001 From: hsjni0110 <92289935+hsjni0110@users.noreply.github.com> Date: Thu, 14 Nov 2024 05:35:20 +0900 Subject: [PATCH 0875/1006] fix typos in method and variable names (#3766) --- .../internal/model/source/SourceMethod.java | 2 +- .../processor/MapperCreationProcessor.java | 26 +++++++++---------- .../processor/MethodRetrievalProcessor.java | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java index 7103fb2858..8427dd3eca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceMethod.java @@ -186,7 +186,7 @@ public Builder setPrototypeMethods(List prototypeMethods) { return this; } - public Builder setDefininingType(Type definingType) { + public Builder setDefiningType(Type definingType) { this.definingType = definingType; return this; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 5fc1b07823..3b38a05b59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -195,7 +195,7 @@ private Mapper getMapper(TypeElement element, MapperOptions mapperOptions, List< addAllFieldsIn( mappingContext.getUsedSupportedMappings(), supportingFieldSet ); fields.addAll( supportingFieldSet ); - // handle constructorfragments + // handle constructor fragments Set constructorFragments = new LinkedHashSet<>(); addAllFragmentsIn( mappingContext.getUsedSupportedMappings(), constructorFragments ); @@ -632,7 +632,7 @@ else if ( nameFilteredcandidates.size() > 1 ) { reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inverseConfiguration ); } else { - reportErrorWhenAmbigousReverseMapping( candidates, method, inverseConfiguration ); + reportErrorWhenAmbiguousReverseMapping( candidates, method, inverseConfiguration ); } } } @@ -702,21 +702,21 @@ else if ( sourceMethod.getName().equals( name ) ) { else if ( candidates.size() > 1 ) { // ambiguity: find a matching method that matches configuredBy - List nameFilteredcandidates = new ArrayList<>(); + List nameFilteredCandidates = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { if ( candidate.getName().equals( name ) ) { - nameFilteredcandidates.add( candidate ); + nameFilteredCandidates.add( candidate ); } } - if ( nameFilteredcandidates.size() == 1 ) { - resultMethod = first( nameFilteredcandidates ); + if ( nameFilteredCandidates.size() == 1 ) { + resultMethod = first( nameFilteredCandidates ); } - else if ( nameFilteredcandidates.size() > 1 ) { - reportErrorWhenSeveralNamesMatch( nameFilteredcandidates, method, inheritConfiguration ); + else if ( nameFilteredCandidates.size() > 1 ) { + reportErrorWhenSeveralNamesMatch( nameFilteredCandidates, method, inheritConfiguration ); } else { - reportErrorWhenAmbigousMapping( candidates, method, inheritConfiguration ); + reportErrorWhenAmbiguousMapping( candidates, method, inheritConfiguration ); } } } @@ -729,8 +729,8 @@ private AnnotationMirror getAnnotationMirror(InheritConfigurationGem inheritConf return inheritConfiguration == null ? null : inheritConfiguration.mirror(); } - private void reportErrorWhenAmbigousReverseMapping(List candidates, SourceMethod method, - InheritInverseConfigurationGem inverseGem) { + private void reportErrorWhenAmbiguousReverseMapping(List candidates, SourceMethod method, + InheritInverseConfigurationGem inverseGem) { List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { @@ -780,8 +780,8 @@ private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMe ); } - private void reportErrorWhenAmbigousMapping(List candidates, SourceMethod method, - InheritConfigurationGem gem) { + private void reportErrorWhenAmbiguousMapping(List candidates, SourceMethod method, + InheritConfigurationGem gem) { List candidateNames = new ArrayList<>(); for ( SourceMethod candidate : candidates ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 4bd2ed48a5..2c8ad5dcb9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -389,7 +389,7 @@ private SourceMethod getReferencedMethod(TypeElement usedMapper, ExecutableType return new SourceMethod.Builder() .setDeclaringMapper( usedMapper.equals( mapperToImplement ) ? null : usedMapperAsType ) - .setDefininingType( definingType ) + .setDefiningType( definingType ) .setExecutable( method ) .setParameters( parameters ) .setReturnType( returnType ) From bee983cd3c627333a613a58be555090ac754da95 Mon Sep 17 00:00:00 2001 From: Minji Kim <101392857+alsswl@users.noreply.github.com> Date: Sat, 16 Nov 2024 06:13:36 +0900 Subject: [PATCH 0876/1006] Fix typos in comments (#3769) --- distribution/pom.xml | 2 +- .../org/mapstruct/ap/internal/model/BeanMappingMethod.java | 6 +++--- .../mapstruct/ap/internal/model/MappingBuilderContext.java | 2 +- .../internal/model/NestedTargetPropertyMappingHolder.java | 4 ++-- .../org/mapstruct/ap/internal/model/ValueMappingMethod.java | 4 ++-- .../java/org/mapstruct/ap/spi/AccessorNamingStrategy.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/distribution/pom.xml b/distribution/pom.xml index f826421092..db654236e4 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -130,7 +130,7 @@ enumToStringMapping(Method method, Type sourceType ) return mappings; } - // Start to fill the mappings with the defined valuemappings + // Start to fill the mappings with the defined valueMappings for ( ValueMappingOptions valueMapping : valueMappings.regularValueMappings ) { mappings.add( new MappingEntry( valueMapping.getSource(), valueMapping.getTarget() ) ); unmappedSourceConstants.remove( valueMapping.getSource() ); @@ -305,7 +305,7 @@ private List stringToEnumMapping(Method method, Type targetType ) } Set mappedSources = new LinkedHashSet<>(); - // Start to fill the mappings with the defined valuemappings + // Start to fill the mappings with the defined value mappings for ( ValueMappingOptions valueMapping : valueMappings.regularValueMappings ) { mappedSources.add( valueMapping.getSource() ); mappings.add( new MappingEntry( valueMapping.getSource(), valueMapping.getTarget() ) ); diff --git a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java index c9d0734753..b4dde64324 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/AccessorNamingStrategy.java @@ -68,7 +68,7 @@ default void init(MapStructProcessingEnvironment processingEnvironment) { * * @return getter name for collection properties * - * @deprecated MapStuct will not call this method anymore. Use {@link #getMethodType(ExecutableElement)} to + * @deprecated MapStruct will not call this method anymore. Use {@link #getMethodType(ExecutableElement)} to * determine the {@link MethodType}. When collections somehow need to be treated special, it should be done in * {@link #getMethodType(ExecutableElement) } as well. In the future, this method will be removed. */ From 737af6b50a1641d936c8a5b152bb97bf1f843d18 Mon Sep 17 00:00:00 2001 From: Roman Obolonskyi <65775868+Obolrom@users.noreply.github.com> Date: Sun, 17 Nov 2024 17:46:59 +0200 Subject: [PATCH 0877/1006] #3628 Add support for locale parameter for numberFormat and dateFormat --- .../java/org/mapstruct/IterableMapping.java | 19 + .../main/java/org/mapstruct/MapMapping.java | 27 + core/src/main/java/org/mapstruct/Mapping.java | 19 + .../BigDecimalToStringConversion.java | 20 +- .../BigIntegerToStringConversion.java | 20 +- .../internal/conversion/ConversionUtils.java | 12 + .../conversion/CreateDecimalFormat.java | 37 +- .../conversion/DateToStringConversion.java | 35 +- .../PrimitiveToStringConversion.java | 39 +- .../conversion/WrapperToStringConversion.java | 39 +- .../model/common/ConversionContext.java | 2 + .../common/DefaultConversionContext.java | 7 + .../model/common/FormattingParameters.java | 10 +- .../model/source/IterableMappingOptions.java | 3 +- .../model/source/MapMappingOptions.java | 14 +- .../internal/model/source/MappingOptions.java | 9 +- .../conversion/CreateDecimalFormat.ftl | 7 +- .../common/DefaultConversionContextTest.java | 6 +- .../conversion/date/DateConversionTest.java | 120 ++++ .../conversion/date/SourceTargetMapper.java | 24 +- .../numbers/NumberFormatConversionTest.java | 126 ++++- .../numbers/SourceTargetMapper.java | 41 +- .../numbers/SourceTargetMapperImpl.java | 525 ++++++++++++++++++ .../numbers/SourceTargetMapperImpl.java | 525 ++++++++++++++++++ 24 files changed, 1631 insertions(+), 55 deletions(-) create mode 100644 processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java diff --git a/core/src/main/java/org/mapstruct/IterableMapping.java b/core/src/main/java/org/mapstruct/IterableMapping.java index 76153127bd..d644dfe03b 100644 --- a/core/src/main/java/org/mapstruct/IterableMapping.java +++ b/core/src/main/java/org/mapstruct/IterableMapping.java @@ -66,19 +66,38 @@ /** * A format string as processable by {@link SimpleDateFormat} if the annotated method maps from an iterable of * {@code String} to an iterable {@link Date} or vice-versa. Will be ignored for all other element types. + *

      + * If the {@link #locale()} is also specified, the format will consider the specified locale when processing + * the date. Otherwise, the system's default locale will be used. * * @return A date format string as processable by {@link SimpleDateFormat}. + * @see #locale() */ String dateFormat() default ""; /** * A format string as processable by {@link DecimalFormat} if the annotated method maps from a * {@link Number} to a {@link String} or vice-versa. Will be ignored for all other element types. + *

      + * If the {@link #locale()} is also specified, the number format will be applied in the context of the given locale. + * Otherwise, the system's default locale will be used to process the number format. * * @return A decimal format string as processable by {@link DecimalFormat}. + * @see #locale() */ String numberFormat() default ""; + /** + * Specifies the locale to be used when processing {@link #dateFormat()} or {@link #numberFormat()}. + *

      + * The locale should be a plain tag representing the language, such as "en" for English, "de" for German, etc. + *

      + * If no locale is specified, the system's default locale will be used. + * + * @return A string representing the locale to be used when formatting dates or numbers. + */ + String locale() default ""; + /** * A qualifier can be specified to aid the selection process of a suitable mapper. This is useful in case multiple * mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found' error. diff --git a/core/src/main/java/org/mapstruct/MapMapping.java b/core/src/main/java/org/mapstruct/MapMapping.java index 271272bb45..093099cf5a 100644 --- a/core/src/main/java/org/mapstruct/MapMapping.java +++ b/core/src/main/java/org/mapstruct/MapMapping.java @@ -56,8 +56,12 @@ /** * A format string as processable by {@link SimpleDateFormat} if the annotated method maps from a map with key type * {@code String} to an map with key type {@link Date} or vice-versa. Will be ignored for all other key types. + *

      + * If the {@link #locale()} is specified, the format will consider the specified locale when processing the date. + * Otherwise, the system's default locale will be used. * * @return A date format string as processable by {@link SimpleDateFormat}. + * @see #locale() */ String keyDateFormat() default ""; @@ -65,27 +69,50 @@ * A format string as processable by {@link SimpleDateFormat} if the annotated method maps from a map with value * type {@code String} to an map with value type {@link Date} or vice-versa. Will be ignored for all other value * types. + *

      + * If the {@link #locale()} is specified, the format will consider the specified locale when processing the date. + * Otherwise, the system's default locale will be used. * * @return A date format string as processable by {@link SimpleDateFormat}. + * @see #locale() */ String valueDateFormat() default ""; /** * A format string as processable by {@link DecimalFormat} if the annotated method maps from a * {@link Number} to a {@link String} or vice-versa. Will be ignored for all other key types. + *

      + * If the {@link #locale()} is specified, the number format will be applied in the context of the given locale. + * Otherwise, the system's default locale will be used. * * @return A decimal format string as processable by {@link DecimalFormat}. + * @see #locale() */ String keyNumberFormat() default ""; /** * A format string as processable by {@link DecimalFormat} if the annotated method maps from a * {@link Number} to a {@link String} or vice-versa. Will be ignored for all other value types. + *

      + * If the {@link #locale()} is specified, the number format will be applied in the context of the given locale. + * Otherwise, the system's default locale will be used. * * @return A decimal format string as processable by {@link DecimalFormat}. + * @see #locale() */ String valueNumberFormat() default ""; + /** + * Specifies the locale to be used when processing {@link SimpleDateFormat} or {@link DecimalFormat} for key or + * value mappings in maps. The locale should be a plain tag representing the language, such as "en" for English, + * "de" for German, etc. + *

      + * If no locale is specified, the system's default locale will be used. + * + * @return A string representing the locale to be used when formatting dates or numbers in maps. + */ + String locale() default ""; + /** * A key value qualifier can be specified to aid the selection process of a suitable mapper. This is useful in * case multiple mappers (hand written of internal) qualify and result in an 'Ambiguous mapping methods found' diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 8b0c4adb0c..6c95b0db2c 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -175,19 +175,38 @@ /** * A format string as processable by {@link SimpleDateFormat} if the attribute is mapped from {@code String} to * {@link Date} or vice-versa. Will be ignored for all other attribute types and when mapping enum constants. + *

      + * If the {@link #locale()} is also specified, the format will consider the specified locale when processing + * the date. Otherwise, the system's default locale will be used. * * @return A date format string as processable by {@link SimpleDateFormat}. + * @see #locale() */ String dateFormat() default ""; /** * A format string as processable by {@link DecimalFormat} if the annotated method maps from a * {@link Number} to a {@link String} or vice-versa. Will be ignored for all other element types. + *

      + * If the {@link #locale()} is also specified, the number format will be applied in the context of the given locale. + * Otherwise, the system's default locale will be used to process the number format. * * @return A decimal format string as processable by {@link DecimalFormat}. + * @see #locale() */ String numberFormat() default ""; + /** + * Specifies the locale to be used when processing {@link #dateFormat()} or {@link #numberFormat()}. + *

      + * The locale should be a plain tag representing the language, such as "en" for English, "de" for German, etc. + *

      + * If no locale is specified, the system's default locale will be used. + * + * @return A string representing the locale to be used when formatting dates or numbers. + */ + String locale() default ""; + /** * A constant {@link String} based on which the specified target property is to be set. *

      diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java index 92a93e3893..384013a7b3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigDecimalToStringConversion.java @@ -14,8 +14,9 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; -import static org.mapstruct.ap.internal.util.Collections.asSet; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigDecimal} and {@link String}. @@ -64,18 +65,31 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon public List getRequiredHelperMethods(ConversionContext conversionContext) { List helpers = new ArrayList<>(); if ( conversionContext.getNumberFormat() != null ) { - helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); + helpers.add( new CreateDecimalFormat( + conversionContext.getTypeFactory(), + conversionContext.getLocale() != null + ) ); } return helpers; } private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { - sb.append( "createDecimalFormat( " ); + boolean withLocale = conversionContext.getLocale() != null; + sb.append( "createDecimalFormat" ); + if ( withLocale ) { + sb.append( "WithLocale" ); + } + sb.append( "( " ); if ( conversionContext.getNumberFormat() != null ) { sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); sb.append( "\"" ); } + if ( withLocale ) { + sb.append( ", " ).append( locale( conversionContext ) ).append( ".forLanguageTag( \"" ); + sb.append( conversionContext.getLocale() ); + sb.append( "\" )" ); + } sb.append( " )" ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java index df0a48a673..540d89db58 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/BigIntegerToStringConversion.java @@ -15,9 +15,10 @@ import org.mapstruct.ap.internal.model.common.ConversionContext; import org.mapstruct.ap.internal.model.common.Type; -import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigDecimal; import static org.mapstruct.ap.internal.conversion.ConversionUtils.bigInteger; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link BigInteger} and {@link String}. @@ -72,18 +73,31 @@ protected Set getFromConversionImportTypes(ConversionContext conversionCon public List getRequiredHelperMethods(ConversionContext conversionContext) { List helpers = new ArrayList<>(); if ( conversionContext.getNumberFormat() != null ) { - helpers.add( new CreateDecimalFormat( conversionContext.getTypeFactory() ) ); + helpers.add( new CreateDecimalFormat( + conversionContext.getTypeFactory(), + conversionContext.getLocale() != null + ) ); } return helpers; } private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversionContext) { - sb.append( "createDecimalFormat( " ); + boolean withLocale = conversionContext.getLocale() != null; + sb.append( "createDecimalFormat" ); + if ( withLocale ) { + sb.append( "WithLocale" ); + } + sb.append( "( " ); if ( conversionContext.getNumberFormat() != null ) { sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); sb.append( "\"" ); } + if ( withLocale ) { + sb.append( ", " ).append( locale( conversionContext ) ).append( ".forLanguageTag( \"" ); + sb.append( conversionContext.getLocale() ); + sb.append( "\" )" ); + } sb.append( " )" ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index aa01a73276..96960c4a11 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -11,6 +11,7 @@ import java.sql.Time; import java.sql.Timestamp; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; @@ -279,4 +280,15 @@ public static String url(ConversionContext conversionContext) { return typeReferenceName( conversionContext, URL.class ); } + /** + * Name for {@link java.text.DecimalFormatSymbols}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String decimalFormatSymbols(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, DecimalFormatSymbols.class ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java index 77c59445ab..d1b49cff69 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.java @@ -5,9 +5,11 @@ */ package org.mapstruct.ap.internal.conversion; -import static org.mapstruct.ap.internal.util.Collections.asSet; - import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; import java.util.Set; import org.mapstruct.ap.internal.model.HelperMethod; @@ -16,6 +18,8 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.source.MappingMethodOptions; +import static org.mapstruct.ap.internal.util.Collections.asSet; + /** * HelperMethod that creates a {@link java.text.DecimalFormat} * @@ -27,13 +31,30 @@ public class CreateDecimalFormat extends HelperMethod { private final Parameter parameter; + private final Parameter localeParameter; private final Type returnType; private final Set importTypes; - public CreateDecimalFormat(TypeFactory typeFactory) { + public CreateDecimalFormat(TypeFactory typeFactory, boolean withLocale) { this.parameter = new Parameter( "numberFormat", typeFactory.getType( String.class ) ); + this.localeParameter = withLocale ? new Parameter( "locale", typeFactory.getType( Locale.class ) ) : null; this.returnType = typeFactory.getType( DecimalFormat.class ); - this.importTypes = asSet( parameter.getType(), returnType ); + if ( withLocale ) { + this.importTypes = asSet( + parameter.getType(), + returnType, + typeFactory.getType( DecimalFormatSymbols.class ), + typeFactory.getType( Locale.class ) + ); + } + else { + this.importTypes = asSet( parameter.getType(), returnType ); + } + } + + @Override + public String getName() { + return localeParameter == null ? "createDecimalFormat" : "createDecimalFormatWithLocale"; } @Override @@ -60,4 +81,12 @@ public MappingMethodOptions getOptions() { public String describe() { return null; } + + @Override + public List getParameters() { + if ( localeParameter == null ) { + return super.getParameters(); + } + return Arrays.asList( getParameter(), localeParameter ); + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java index 361ce9d9ab..35c7f88d74 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/DateToStringConversion.java @@ -10,15 +10,18 @@ import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Locale; +import java.util.Set; import org.mapstruct.ap.internal.model.HelperMethod; import org.mapstruct.ap.internal.model.TypeConversion; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; -import static java.util.Arrays.asList; -import static org.mapstruct.ap.internal.util.Collections.asSet; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; import static org.mapstruct.ap.internal.conversion.ConversionUtils.simpleDateFormat; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between {@link String} and {@link Date}. @@ -29,7 +32,7 @@ public class DateToStringConversion implements ConversionProvider { @Override public Assignment to(ConversionContext conversionContext) { - return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ), + return new TypeConversion( getImportTypes( conversionContext ), Collections.emptyList(), getConversionExpression( conversionContext, "format" ) ); @@ -37,8 +40,8 @@ public Assignment to(ConversionContext conversionContext) { @Override public Assignment from(ConversionContext conversionContext) { - return new TypeConversion( asSet( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ), - asList( conversionContext.getTypeFactory().getType( ParseException.class ) ), + return new TypeConversion( getImportTypes( conversionContext ), + Collections.singletonList( conversionContext.getTypeFactory().getType( ParseException.class ) ), getConversionExpression( conversionContext, "parse" ) ); } @@ -48,6 +51,17 @@ public List getRequiredHelperMethods(ConversionContext conversionC return Collections.emptyList(); } + private Set getImportTypes(ConversionContext conversionContext) { + if ( conversionContext.getLocale() == null ) { + return Collections.singleton( conversionContext.getTypeFactory().getType( SimpleDateFormat.class ) ); + } + + return asSet( + conversionContext.getTypeFactory().getType( SimpleDateFormat.class ), + conversionContext.getTypeFactory().getType( Locale.class ) + ); + } + private String getConversionExpression(ConversionContext conversionContext, String method) { StringBuilder conversionString = new StringBuilder( "new " ); conversionString.append( simpleDateFormat( conversionContext ) ); @@ -56,7 +70,16 @@ private String getConversionExpression(ConversionContext conversionContext, Stri if ( conversionContext.getDateFormat() != null ) { conversionString.append( " \"" ); conversionString.append( conversionContext.getDateFormat() ); - conversionString.append( "\" " ); + conversionString.append( "\"" ); + + if ( conversionContext.getLocale() != null ) { + conversionString.append( ", " ).append( locale( conversionContext ) ).append( ".forLanguageTag( \"" ); + conversionString.append( conversionContext.getLocale() ); + conversionString.append( "\" ) " ); + } + else { + conversionString.append( " " ); + } } conversionString.append( ")." ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java index fcc7241290..909ce8c0f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/PrimitiveToStringConversion.java @@ -6,7 +6,9 @@ package org.mapstruct.ap.internal.conversion; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.Collections; +import java.util.Locale; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; @@ -15,6 +17,9 @@ import org.mapstruct.ap.internal.util.Strings; import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormat; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormatSymbols; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between primitive types such as {@code byte} or {@code long} and @@ -53,9 +58,15 @@ public String getToExpression(ConversionContext conversionContext) { @Override public Set getToConversionImportTypes(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { - return Collections.singleton( - conversionContext.getTypeFactory().getType( DecimalFormat.class ) - ); + if ( conversionContext.getLocale() != null ) { + return asSet( + conversionContext.getTypeFactory().getType( DecimalFormat.class ), + conversionContext.getTypeFactory().getType( DecimalFormatSymbols.class ), + conversionContext.getTypeFactory().getType( Locale.class ) + ); + } + + return Collections.singleton( conversionContext.getTypeFactory().getType( DecimalFormat.class ) ); } return Collections.emptySet(); @@ -80,9 +91,15 @@ public String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { - return Collections.singleton( - conversionContext.getTypeFactory().getType( DecimalFormat.class ) - ); + if ( conversionContext.getLocale() != null ) { + return asSet( + conversionContext.getTypeFactory().getType( DecimalFormat.class ), + conversionContext.getTypeFactory().getType( DecimalFormatSymbols.class ), + conversionContext.getTypeFactory().getType( Locale.class ) + ); + } + + return Collections.singleton( conversionContext.getTypeFactory().getType( DecimalFormat.class ) ); } return Collections.emptySet(); @@ -97,6 +114,16 @@ private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversi sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); sb.append( "\"" ); + + if ( conversionContext.getLocale() != null ) { + sb.append( ", " ) + .append( decimalFormatSymbols( conversionContext ) ) + .append( ".getInstance( " ) + .append( locale( conversionContext ) ) + .append( ".forLanguageTag( \"" ) + .append( conversionContext.getLocale() ) + .append( " \" ) )" ); + } } sb.append( " )" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java index 300c901216..dd7b6bac8d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/WrapperToStringConversion.java @@ -6,7 +6,9 @@ package org.mapstruct.ap.internal.conversion; import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.Collections; +import java.util.Locale; import java.util.Set; import org.mapstruct.ap.internal.model.common.ConversionContext; @@ -15,6 +17,9 @@ import org.mapstruct.ap.internal.util.Strings; import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormat; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.decimalFormatSymbols; +import static org.mapstruct.ap.internal.conversion.ConversionUtils.locale; +import static org.mapstruct.ap.internal.util.Collections.asSet; /** * Conversion between wrapper types such as {@link Integer} and {@link String}. @@ -52,9 +57,15 @@ public String getToExpression(ConversionContext conversionContext) { @Override public Set getToConversionImportTypes(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { - return Collections.singleton( - conversionContext.getTypeFactory().getType( DecimalFormat.class ) - ); + if ( conversionContext.getLocale() != null ) { + return asSet( + conversionContext.getTypeFactory().getType( DecimalFormat.class ), + conversionContext.getTypeFactory().getType( DecimalFormatSymbols.class ), + conversionContext.getTypeFactory().getType( Locale.class ) + ); + } + + return Collections.singleton( conversionContext.getTypeFactory().getType( DecimalFormat.class ) ); } return Collections.emptySet(); @@ -79,9 +90,15 @@ public String getFromExpression(ConversionContext conversionContext) { @Override protected Set getFromConversionImportTypes(ConversionContext conversionContext) { if ( requiresDecimalFormat( conversionContext ) ) { - return Collections.singleton( - conversionContext.getTypeFactory().getType( DecimalFormat.class ) - ); + if ( conversionContext.getLocale() != null ) { + return asSet( + conversionContext.getTypeFactory().getType( DecimalFormat.class ), + conversionContext.getTypeFactory().getType( DecimalFormatSymbols.class ), + conversionContext.getTypeFactory().getType( Locale.class ) + ); + } + + return Collections.singleton( conversionContext.getTypeFactory().getType( DecimalFormat.class ) ); } return Collections.emptySet(); @@ -96,6 +113,16 @@ private void appendDecimalFormatter(StringBuilder sb, ConversionContext conversi sb.append( "\"" ); sb.append( conversionContext.getNumberFormat() ); sb.append( "\"" ); + + if ( conversionContext.getLocale() != null ) { + sb.append( ", " ) + .append( decimalFormatSymbols( conversionContext ) ) + .append( ".getInstance( " ) + .append( locale( conversionContext ) ) + .append( ".forLanguageTag( \"" ) + .append( conversionContext.getLocale() ) + .append( " \" ) )" ); + } } sb.append( " )" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java index c2aa73f307..96d3d6fe78 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java @@ -32,6 +32,8 @@ public interface ConversionContext { String getNumberFormat(); + String getLocale(); + TypeFactory getTypeFactory(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java index f5a9fcc761..159f1663e2 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java @@ -21,6 +21,7 @@ public class DefaultConversionContext implements ConversionContext { private final FormattingParameters formattingParameters; private final String dateFormat; private final String numberFormat; + private final String locale; private final TypeFactory typeFactory; public DefaultConversionContext(TypeFactory typeFactory, FormattingMessager messager, Type sourceType, @@ -32,6 +33,7 @@ public DefaultConversionContext(TypeFactory typeFactory, FormattingMessager mess this.formattingParameters = formattingParameters; this.dateFormat = this.formattingParameters.getDate(); this.numberFormat = this.formattingParameters.getNumber(); + this.locale = this.formattingParameters.getLocale(); validateDateFormat(); } @@ -64,6 +66,11 @@ public String getNumberFormat() { return numberFormat; } + @Override + public String getLocale() { + return locale != null ? locale.toString() : null; + } + @Override public String getDateFormat() { return dateFormat; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java index e21f5d74fa..48cee4bbe5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java @@ -15,21 +15,23 @@ */ public class FormattingParameters { - public static final FormattingParameters EMPTY = new FormattingParameters( null, null, null, null, null ); + public static final FormattingParameters EMPTY = new FormattingParameters( null, null, null, null, null, null ); private final String date; private final String number; private final AnnotationMirror mirror; private final AnnotationValue dateAnnotationValue; private final Element element; + private final String locale; public FormattingParameters(String date, String number, AnnotationMirror mirror, - AnnotationValue dateAnnotationValue, Element element) { + AnnotationValue dateAnnotationValue, Element element, String locale) { this.date = date; this.number = number; this.mirror = mirror; this.dateAnnotationValue = dateAnnotationValue; this.element = element; + this.locale = locale; } public String getDate() { @@ -51,4 +53,8 @@ public AnnotationValue getDateAnnotationValue() { public Element getElement() { return element; } + + public String getLocale() { + return locale; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java index c4770efde6..50fca3e4d2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/IterableMappingOptions.java @@ -55,7 +55,8 @@ public static IterableMappingOptions fromGem(IterableMappingGem iterableMapping, iterableMapping.numberFormat().get(), iterableMapping.mirror(), iterableMapping.dateFormat().getAnnotationValue(), - method + method, + iterableMapping.locale().getValue() ); IterableMappingOptions options = diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java index fd1758d8d2..9f3d12faf3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapMappingOptions.java @@ -8,14 +8,14 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; -import org.mapstruct.ap.internal.model.common.FormattingParameters; import org.mapstruct.ap.internal.gem.MapMappingGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; +import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.tools.gem.GemValue; /** @@ -47,6 +47,8 @@ public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions return options; } + String locale = mapMapping.locale().getValue(); + SelectionParameters keySelection = new SelectionParameters( mapMapping.keyQualifiedBy().get(), mapMapping.keyQualifiedByName().get(), @@ -66,7 +68,8 @@ public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapMapping.keyNumberFormat().get(), mapMapping.mirror(), mapMapping.keyDateFormat().getAnnotationValue(), - method + method, + locale ); FormattingParameters valueFormatting = new FormattingParameters( @@ -74,7 +77,8 @@ public static MapMappingOptions fromGem(MapMappingGem mapMapping, MapperOptions mapMapping.valueNumberFormat().get(), mapMapping.mirror(), mapMapping.valueDateFormat().getAnnotationValue(), - method + method, + locale ); MapMappingOptions options = new MapMappingOptions( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java index 22f9ccdc2f..746aca5a32 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingOptions.java @@ -18,16 +18,16 @@ import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; -import org.mapstruct.ap.internal.util.ElementUtils; -import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.ap.internal.gem.MappingGem; import org.mapstruct.ap.internal.gem.MappingsGem; import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.model.common.FormattingParameters; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Message; +import org.mapstruct.ap.internal.util.TypeUtils; import org.mapstruct.tools.gem.GemValue; /** @@ -118,6 +118,8 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, String conditionExpression = getConditionExpression( mapping, method, messager ); String dateFormat = mapping.dateFormat().getValue(); String numberFormat = mapping.numberFormat().getValue(); + String locale = mapping.locale().getValue(); + String defaultValue = mapping.defaultValue().getValue(); Set dependsOn = mapping.dependsOn().hasValue() ? @@ -129,7 +131,8 @@ public static void addInstance(MappingGem mapping, ExecutableElement method, numberFormat, mapping.mirror(), mapping.dateFormat().getAnnotationValue(), - method + method, + locale ); SelectionParameters selectionParams = new SelectionParameters( mapping.qualifiedBy().get(), diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl index ce0f605f11..6753a73d6f 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/conversion/CreateDecimalFormat.ftl @@ -5,9 +5,10 @@ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 --> -private DecimalFormat ${name}( String numberFormat ) { +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.SupportingMappingMethod" --> +private DecimalFormat ${name}( <#list parameters as param><@includeModel object=param/><#if param_has_next>, ) { - DecimalFormat df = new DecimalFormat( numberFormat ); + DecimalFormat df = new DecimalFormat( numberFormat<#if parameters.size() > 1>, DecimalFormatSymbols.getInstance( locale ) ); df.setParseBigDecimal( true ); return df; -} \ No newline at end of file +} diff --git a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java index ce2f895e0f..401a6b2240 100755 --- a/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java +++ b/processor/src/test/java/org/mapstruct/ap/internal/model/common/DefaultConversionContextTest.java @@ -70,7 +70,7 @@ public void testInvalidDateFormatValidation() { statefulMessagerMock, type, type, - new FormattingParameters( "qwertz", null, null, null, null ) + new FormattingParameters( "qwertz", null, null, null, null, null ) ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isEqualTo( Diagnostic.Kind.ERROR ); } @@ -84,7 +84,7 @@ public void testNullDateFormatValidation() { statefulMessagerMock, type, type, - new FormattingParameters( null, null, null, null, null ) + new FormattingParameters( null, null, null, null, null, null ) ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isNull(); } @@ -97,7 +97,7 @@ public void testUnsupportedType() { statefulMessagerMock, type, type, - new FormattingParameters( "qwertz", null, null, null, null ) + new FormattingParameters( "qwertz", null, null, null, null, null ) ); assertThat( statefulMessagerMock.getLastKindPrinted() ).isNull(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index 9ccf8e7e1f..bc90228206 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -54,6 +54,21 @@ public void shouldApplyDateFormatForConversions() { assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13 00:00" ); } + @ProcessorTest + @EnabledOnJre( JRE.JAVA_8 ) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionsWithCustomLocale() { + Source source = new Source(); + source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getDate() ).isEqualTo( "juillet 06, 2013" ); + assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); + } + @ProcessorTest @EnabledForJreRange(min = JRE.JAVA_11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ @@ -69,6 +84,21 @@ public void shouldApplyDateFormatForConversionsJdk11() { assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); } + @ProcessorTest + @EnabledForJreRange(min = JRE.JAVA_11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionsJdk11WithCustomLocale() { + Source source = new Source(); + source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getDate() ).isEqualTo( "juillet 06, 2013" ); + assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); + } + @ProcessorTest @EnabledOnJre(JRE.JAVA_8) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ @@ -86,6 +116,23 @@ public void shouldApplyDateFormatForConversionInReverseMapping() { ); } + @ProcessorTest + @EnabledOnJre(JRE.JAVA_8) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionInReverseMappingWithCustomLocale() { + Target target = new Target(); + target.setDate( "juillet 06, 2013" ); + target.setAnotherDate( "14.02.13 8:30" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + assertThat( source.getAnotherDate() ).isEqualTo( + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() + ); + } + @ProcessorTest @EnabledForJreRange(min = JRE.JAVA_11) // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ @@ -103,6 +150,23 @@ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { ); } + @ProcessorTest + @EnabledForJreRange(min = JRE.JAVA_11) + // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ + public void shouldApplyDateFormatForConversionInReverseMappingJdk11WithCustomLocale() { + Target target = new Target(); + target.setDate( "juillet 06, 2013" ); + target.setAnotherDate( "14.02.13, 8:30" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); + assertThat( source.getAnotherDate() ).isEqualTo( + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() + ); + } + @ProcessorTest public void shouldApplyStringConversionForIterableMethod() { List dates = Arrays.asList( @@ -117,6 +181,20 @@ public void shouldApplyStringConversionForIterableMethod() { assertThat( stringDates ).containsExactly( "06.07.2013", "14.02.2013", "11.04.2013" ); } + @ProcessorTest + public void shouldApplyStringConversionForIterableMethodWithCustomLocale() { + List dates = Arrays.asList( + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() + ); + + List stringDates = SourceTargetMapper.INSTANCE.stringListToDateListWithCustomLocale( dates ); + + assertThat( stringDates ).isNotNull(); + assertThat( stringDates ).containsExactly( "juillet 06, 2013", "février 14, 2013", "avril 11, 2013" ); + } + @ProcessorTest public void shouldApplyStringConversionForArrayMethod() { List dates = Arrays.asList( @@ -131,6 +209,20 @@ public void shouldApplyStringConversionForArrayMethod() { assertThat( stringDates ).isEqualTo( new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" } ); } + @ProcessorTest + public void shouldApplyStringConversionForArrayMethodWithCustomLocale() { + List dates = Arrays.asList( + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() + ); + + String[] stringDates = SourceTargetMapper.INSTANCE.stringListToDateArrayWithCustomLocale( dates ); + + assertThat( stringDates ).isNotNull(); + assertThat( stringDates ).isEqualTo( new String[]{ "juillet 06, 2013", "février 14, 2013", "avril 11, 2013" } ); + } + @ProcessorTest public void shouldApplyStringConversionForReverseIterableMethod() { List stringDates = Arrays.asList( "06.07.2013", "14.02.2013", "11.04.2013" ); @@ -145,6 +237,20 @@ public void shouldApplyStringConversionForReverseIterableMethod() { ); } + @ProcessorTest + public void shouldApplyStringConversionForReverseIterableMethodWithCustomLocale() { + List stringDates = Arrays.asList( "juillet 06, 2013", "février 14, 2013", "avril 11, 2013" ); + + List dates = SourceTargetMapper.INSTANCE.dateListToStringListWithCustomLocale( stringDates ); + + assertThat( dates ).isNotNull(); + assertThat( dates ).containsExactly( + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() + ); + } + @ProcessorTest public void shouldApplyStringConversionForReverseArrayMethod() { String[] stringDates = new String[]{ "06.07.2013", "14.02.2013", "11.04.2013" }; @@ -159,6 +265,20 @@ public void shouldApplyStringConversionForReverseArrayMethod() { ); } + @ProcessorTest + public void shouldApplyStringConversionForReverseArrayMethodWithCustomLocale() { + String[] stringDates = new String[]{ "juillet 06, 2013", "février 14, 2013", "avril 11, 2013" }; + + List dates = SourceTargetMapper.INSTANCE.stringArrayToDateListWithCustomLocale( stringDates ); + + assertThat( dates ).isNotNull(); + assertThat( dates ).containsExactly( + new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime(), + new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime(), + new GregorianCalendar( 2013, Calendar.APRIL, 11 ).getTime() + ); + } + @ProcessorTest public void shouldApplyStringConversionForReverseArrayArrayMethod() { Date[] dates = new Date[]{ diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java index 2ef6a7bd96..1971a8c066 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/SourceTargetMapper.java @@ -22,21 +22,39 @@ public interface SourceTargetMapper { @Mapping(target = "date", dateFormat = "dd.MM.yyyy") Target sourceToTarget(Source source); - @InheritInverseConfiguration + @Mapping(target = "date", dateFormat = "MMMM dd, yyyy", locale = "fr") + Target sourceToTargetWithCustomLocale(Source source); + + @InheritInverseConfiguration(name = "sourceToTarget") Source targetToSource(Target target); + @InheritInverseConfiguration(name = "sourceToTargetWithCustomLocale") + Source targetToSourceWithCustomLocale(Target target); + @IterableMapping(dateFormat = "dd.MM.yyyy") List stringListToDateList(List dates); + @IterableMapping(dateFormat = "MMMM dd, yyyy", locale = "fr") + List stringListToDateListWithCustomLocale(List dates); + @IterableMapping(dateFormat = "dd.MM.yyyy") String[] stringListToDateArray(List dates); - @InheritInverseConfiguration + @IterableMapping(dateFormat = "MMMM dd, yyyy", locale = "fr") + String[] stringListToDateArrayWithCustomLocale(List dates); + + @InheritInverseConfiguration(name = "stringListToDateList") List dateListToStringList(List strings); - @InheritInverseConfiguration + @InheritInverseConfiguration(name = "stringListToDateListWithCustomLocale") + List dateListToStringListWithCustomLocale(List strings); + + @InheritInverseConfiguration(name = "stringListToDateArray") List stringArrayToDateList(String[] dates); + @InheritInverseConfiguration(name = "stringListToDateArrayWithCustomLocale") + List stringArrayToDateListWithCustomLocale(String[] dates); + @IterableMapping(dateFormat = "dd.MM.yyyy") String[] dateArrayToStringArray(Date[] dates); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java index 6dfc1b3ca1..39b4e98319 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/NumberFormatConversionTest.java @@ -7,14 +7,15 @@ import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.junit.jupiter.api.extension.RegisterExtension; import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -27,6 +28,10 @@ @DefaultLocale("en") public class NumberFormatConversionTest { + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource() + .addComparisonToFixtureFor( SourceTargetMapper.class ); + @ProcessorTest public void shouldApplyStringConversions() { Source source = new Source(); @@ -68,6 +73,47 @@ public void shouldApplyStringConversions() { assertThat( target.getBigInteger1() ).isEqualTo( "1.23456789E12" ); } + @ProcessorTest + public void shouldApplyStringConversionsWithCustomLocale() { + Source source = new Source(); + source.setI( 1 ); + source.setIi( 2 ); + source.setD( 3.0 ); + source.setDd( 4.0 ); + source.setF( 3.0f ); + source.setFf( 4.0f ); + source.setL( 5L ); + source.setLl( 6L ); + source.setB( (byte) 7 ); + source.setBb( (byte) 8 ); + + source.setComplex1( 345346.456756 ); + source.setComplex2( 5007034.3 ); + + source.setBigDecimal1( new BigDecimal( "987E-20" ) ); + source.setBigInteger1( new BigInteger( "1234567890000" ) ); + + Target target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getI() ).isEqualTo( "1.00" ); + assertThat( target.getIi() ).isEqualTo( "2.00" ); + assertThat( target.getD() ).isEqualTo( "3.00" ); + assertThat( target.getDd() ).isEqualTo( "4.00" ); + assertThat( target.getF() ).isEqualTo( "3.00" ); + assertThat( target.getFf() ).isEqualTo( "4.00" ); + assertThat( target.getL() ).isEqualTo( "5.00" ); + assertThat( target.getLl() ).isEqualTo( "6.00" ); + assertThat( target.getB() ).isEqualTo( "7.00" ); + assertThat( target.getBb() ).isEqualTo( "8.00" ); + + assertThat( target.getComplex1() ).isEqualTo( "345.35E3" ); + assertThat( target.getComplex2() ).isEqualTo( "$5007034.30" ); + + assertThat( target.getBigDecimal1() ).isEqualTo( "9,87E-18" ); + assertThat( target.getBigInteger1() ).isEqualTo( "1,23456789E12" ); + } + @ProcessorTest public void shouldApplyReverseStringConversions() { Target target = new Target(); @@ -109,17 +155,73 @@ public void shouldApplyReverseStringConversions() { assertThat( source.getBigInteger1() ).isEqualTo( new BigInteger( "1234567890000" ) ); } + @ProcessorTest + public void shouldApplyReverseStringConversionsWithCustomLocale() { + Target target = new Target(); + target.setI( "1.00" ); + target.setIi( "2.00" ); + target.setD( "3.00" ); + target.setDd( "4.00" ); + target.setF( "3.00" ); + target.setFf( "4.00" ); + target.setL( "5.00" ); + target.setLl( "6.00" ); + target.setB( "7.00" ); + target.setBb( "8.00" ); + + target.setComplex1( "345.35E3" ); + target.setComplex2( "$5007034.30" ); + + target.setBigDecimal1( "9,87E-18" ); + target.setBigInteger1( "1,23456789E12" ); + + Source source = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getI() ).isEqualTo( 1 ); + assertThat( source.getIi() ).isEqualTo( Integer.valueOf( 2 ) ); + assertThat( source.getD() ).isEqualTo( 3.0 ); + assertThat( source.getDd() ).isEqualTo( Double.valueOf( 4.0 ) ); + assertThat( source.getF() ).isEqualTo( 3.0f ); + assertThat( source.getFf() ).isEqualTo( Float.valueOf( 4.0f ) ); + assertThat( source.getL() ).isEqualTo( 5L ); + assertThat( source.getLl() ).isEqualTo( Long.valueOf( 6L ) ); + assertThat( source.getB() ).isEqualTo( (byte) 7 ); + assertThat( source.getBb() ).isEqualTo( (byte) 8 ); + + assertThat( source.getComplex1() ).isEqualTo( 345350.0 ); + assertThat( source.getComplex2() ).isEqualTo( 5007034.3 ); + + assertThat( source.getBigDecimal1() ).isEqualTo( new BigDecimal( "987E-20" ) ); + assertThat( source.getBigInteger1() ).isEqualTo( new BigInteger( "1234567890000" ) ); + } + @ProcessorTest public void shouldApplyStringConversionsToIterables() { - List target = SourceTargetMapper.INSTANCE.sourceToTarget( Arrays.asList( 2f ) ); + List target = SourceTargetMapper.INSTANCE.sourceToTarget( List.of( 2f ) ); assertThat( target ).hasSize( 1 ); - assertThat( target ).isEqualTo( Arrays.asList( "2.00" ) ); + assertThat( target ).isEqualTo( List.of( "2.00" ) ); List source = SourceTargetMapper.INSTANCE.targetToSource( target ); assertThat( source ).hasSize( 1 ); - assertThat( source ).isEqualTo( Arrays.asList( 2.00f ) ); + assertThat( source ).isEqualTo( List.of( 2.00f ) ); + } + + @ProcessorTest + public void shouldApplyStringConversionsToIterablesWithCustomLocale() { + + List target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( + List.of( new BigDecimal("987E-20") ) + ); + + assertThat( target ).hasSize( 1 ); + assertThat( target ).isEqualTo( List.of( "9,87E-18" ) ); + + List source = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); + assertThat( source ).hasSize( 1 ); + assertThat( source ).isEqualTo( List.of( new BigDecimal("987E-20") ) ); } @ProcessorTest @@ -137,4 +239,20 @@ public void shouldApplyStringConversionsToMaps() { assertThat( source2 ).contains( entry( 1.00f, 2f ) ); } + + @ProcessorTest + public void shouldApplyStringConversionsToMapsWithCustomLocale() { + + Map source1 = new HashMap<>(); + source1.put( new BigDecimal( "987E-20" ), new BigDecimal( "97E-10" ) ); + + Map target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( source1 ); + assertThat( target ).hasSize( 1 ); + assertThat( target ).contains( entry( "9,87E-18", "9,7E-9" ) ); + + Map source2 = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); + assertThat( source2 ).hasSize( 1 ); + assertThat( source2 ).contains( entry( new BigDecimal( "987E-20" ), new BigDecimal( "97E-10" ) ) ); + + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java index 537452fca2..b82a7a6199 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapper.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.test.conversion.numbers; +import java.math.BigDecimal; import java.util.List; import java.util.Map; import org.mapstruct.InheritInverseConfiguration; @@ -41,21 +42,55 @@ public interface SourceTargetMapper { } ) Target sourceToTarget(Source source); - @InheritInverseConfiguration + @Mappings( { + @Mapping( target = "i", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "ii", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "d", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "dd", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "f", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "ff", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "l", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "ll", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "b", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "bb", numberFormat = NUMBER_FORMAT, locale = "ru" ), + @Mapping( target = "complex1", numberFormat = "##0.##E0", locale = "ru" ), + @Mapping( target = "complex2", numberFormat = "$#.00", locale = "ru" ), + @Mapping( target = "bigDecimal1", numberFormat = "#0.#E0", locale = "ru" ), + @Mapping( target = "bigInteger1", numberFormat = "0.#############E0", locale = "ru" ) + + } ) + Target sourceToTargetWithCustomLocale(Source source); + + @InheritInverseConfiguration( name = "sourceToTarget" ) Source targetToSource(Target target); + @InheritInverseConfiguration( name = "sourceToTargetWithCustomLocale" ) + Source targetToSourceWithCustomLocale(Target target); + @IterableMapping( numberFormat = NUMBER_FORMAT ) List sourceToTarget(List source); - @InheritInverseConfiguration + @InheritInverseConfiguration( name = "sourceToTarget" ) List targetToSource(List source); + @IterableMapping( numberFormat = "#0.#E0", locale = "fr" ) + List sourceToTargetWithCustomLocale(List source); + + @InheritInverseConfiguration( name = "sourceToTargetWithCustomLocale" ) + List targetToSourceWithCustomLocale(List source); + @MapMapping( keyNumberFormat = NUMBER_FORMAT, valueNumberFormat = "##" ) Map sourceToTarget(Map source); - @InheritInverseConfiguration + @MapMapping( keyNumberFormat = "#0.#E0", valueNumberFormat = "0.#############E0", locale = "fr" ) + Map sourceToTargetWithCustomLocale(Map source); + + @InheritInverseConfiguration( name = "sourceToTarget" ) Map targetToSource(Map source); + @InheritInverseConfiguration( name = "sourceToTargetWithCustomLocale" ) + Map targetToSourceWithCustomLocale(Map source); + } diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..ccf8042e6b --- /dev/null +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java @@ -0,0 +1,525 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.numbers; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-09-14T11:37:30+0300", + comments = "version: , compiler: javac, environment: Java 21.0.2 (Amazon.com Inc.)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setI( new DecimalFormat( "##.00" ).format( source.getI() ) ); + if ( source.getIi() != null ) { + target.setIi( new DecimalFormat( "##.00" ).format( source.getIi() ) ); + } + target.setD( new DecimalFormat( "##.00" ).format( source.getD() ) ); + if ( source.getDd() != null ) { + target.setDd( new DecimalFormat( "##.00" ).format( source.getDd() ) ); + } + target.setF( new DecimalFormat( "##.00" ).format( source.getF() ) ); + if ( source.getFf() != null ) { + target.setFf( new DecimalFormat( "##.00" ).format( source.getFf() ) ); + } + target.setL( new DecimalFormat( "##.00" ).format( source.getL() ) ); + if ( source.getLl() != null ) { + target.setLl( new DecimalFormat( "##.00" ).format( source.getLl() ) ); + } + target.setB( new DecimalFormat( "##.00" ).format( source.getB() ) ); + if ( source.getBb() != null ) { + target.setBb( new DecimalFormat( "##.00" ).format( source.getBb() ) ); + } + target.setComplex1( new DecimalFormat( "##0.##E0" ).format( source.getComplex1() ) ); + target.setComplex2( new DecimalFormat( "$#.00" ).format( source.getComplex2() ) ); + if ( source.getBigDecimal1() != null ) { + target.setBigDecimal1( createDecimalFormat( "#0.#E0" ).format( source.getBigDecimal1() ) ); + } + if ( source.getBigInteger1() != null ) { + target.setBigInteger1( createDecimalFormat( "0.#############E0" ).format( source.getBigInteger1() ) ); + } + + return target; + } + + @Override + public Target sourceToTargetWithCustomLocale(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setI( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getI() ) ); + if ( source.getIi() != null ) { + target.setIi( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getIi() ) ); + } + target.setD( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getD() ) ); + if ( source.getDd() != null ) { + target.setDd( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getDd() ) ); + } + target.setF( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getF() ) ); + if ( source.getFf() != null ) { + target.setFf( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getFf() ) ); + } + target.setL( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getL() ) ); + if ( source.getLl() != null ) { + target.setLl( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getLl() ) ); + } + target.setB( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getB() ) ); + if ( source.getBb() != null ) { + target.setBb( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getBb() ) ); + } + target.setComplex1( new DecimalFormat( "##0.##E0", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getComplex1() ) ); + target.setComplex2( new DecimalFormat( "$#.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getComplex2() ) ); + if ( source.getBigDecimal1() != null ) { + target.setBigDecimal1( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "ru" ) ).format( source.getBigDecimal1() ) ); + } + if ( source.getBigInteger1() != null ) { + target.setBigInteger1( createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "ru" ) ).format( source.getBigInteger1() ) ); + } + + return target; + } + + @Override + public Source targetToSource(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + try { + if ( target.getI() != null ) { + source.setI( new DecimalFormat( "##.00" ).parse( target.getI() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getIi() != null ) { + source.setIi( new DecimalFormat( "##.00" ).parse( target.getIi() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getD() != null ) { + source.setD( new DecimalFormat( "##.00" ).parse( target.getD() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getDd() != null ) { + source.setDd( new DecimalFormat( "##.00" ).parse( target.getDd() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getF() != null ) { + source.setF( new DecimalFormat( "##.00" ).parse( target.getF() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getFf() != null ) { + source.setFf( new DecimalFormat( "##.00" ).parse( target.getFf() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getL() != null ) { + source.setL( new DecimalFormat( "##.00" ).parse( target.getL() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getLl() != null ) { + source.setLl( new DecimalFormat( "##.00" ).parse( target.getLl() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getB() != null ) { + source.setB( new DecimalFormat( "##.00" ).parse( target.getB() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBb() != null ) { + source.setBb( new DecimalFormat( "##.00" ).parse( target.getBb() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex1() != null ) { + source.setComplex1( new DecimalFormat( "##0.##E0" ).parse( target.getComplex1() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex2() != null ) { + source.setComplex2( new DecimalFormat( "$#.00" ).parse( target.getComplex2() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigDecimal1() != null ) { + source.setBigDecimal1( (BigDecimal) createDecimalFormat( "#0.#E0" ).parse( target.getBigDecimal1() ) ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigInteger1() != null ) { + source.setBigInteger1( ( (BigDecimal) createDecimalFormat( "0.#############E0" ).parse( target.getBigInteger1() ) ).toBigInteger() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + + return source; + } + + @Override + public Source targetToSourceWithCustomLocale(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + try { + if ( target.getI() != null ) { + source.setI( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getI() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getIi() != null ) { + source.setIi( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getIi() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getD() != null ) { + source.setD( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getD() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getDd() != null ) { + source.setDd( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getDd() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getF() != null ) { + source.setF( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getF() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getFf() != null ) { + source.setFf( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getFf() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getL() != null ) { + source.setL( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getL() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getLl() != null ) { + source.setLl( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getLl() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getB() != null ) { + source.setB( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getB() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBb() != null ) { + source.setBb( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getBb() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex1() != null ) { + source.setComplex1( new DecimalFormat( "##0.##E0", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getComplex1() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex2() != null ) { + source.setComplex2( new DecimalFormat( "$#.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getComplex2() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigDecimal1() != null ) { + source.setBigDecimal1( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "ru" ) ).parse( target.getBigDecimal1() ) ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigInteger1() != null ) { + source.setBigInteger1( ( (BigDecimal) createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "ru" ) ).parse( target.getBigInteger1() ) ).toBigInteger() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + + return source; + } + + @Override + public List sourceToTarget(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( Float float1 : source ) { + list.add( new DecimalFormat( "##.00" ).format( float1 ) ); + } + + return list; + } + + @Override + public List targetToSource(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( String string : source ) { + try { + list.add( new DecimalFormat( "##.00" ).parse( string ).floatValue() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + } + + return list; + } + + @Override + public List sourceToTargetWithCustomLocale(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( BigDecimal bigDecimal : source ) { + list.add( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( bigDecimal ) ); + } + + return list; + } + + @Override + public List targetToSourceWithCustomLocale(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( String string : source ) { + try { + list.add( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( string ) ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + } + + return list; + } + + @Override + public Map sourceToTarget(Map source) { + if ( source == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( source.size() ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + String key = new DecimalFormat( "##.00" ).format( entry.getKey() ); + String value = new DecimalFormat( "##" ).format( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public Map sourceToTargetWithCustomLocale(Map source) { + if ( source == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( source.size() ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + String key = createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( entry.getKey() ); + String value = createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "fr" ) ).format( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public Map targetToSource(Map source) { + if ( source == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( source.size() ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + Float key; + try { + key = new DecimalFormat( "##.00" ).parse( entry.getKey() ).floatValue(); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + Float value; + try { + value = new DecimalFormat( "##" ).parse( entry.getValue() ).floatValue(); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + map.put( key, value ); + } + + return map; + } + + @Override + public Map targetToSourceWithCustomLocale(Map source) { + if ( source == null ) { + return null; + } + + Map map = LinkedHashMap.newLinkedHashMap( source.size() ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + BigDecimal key; + try { + key = (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( entry.getKey() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + BigDecimal value; + try { + value = (BigDecimal) createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "fr" ) ).parse( entry.getValue() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + map.put( key, value ); + } + + return map; + } + + private DecimalFormat createDecimalFormatWithLocale( String numberFormat, Locale locale ) { + + DecimalFormat df = new DecimalFormat( numberFormat, DecimalFormatSymbols.getInstance( locale ) ); + df.setParseBigDecimal( true ); + return df; + } + + private DecimalFormat createDecimalFormat( String numberFormat ) { + + DecimalFormat df = new DecimalFormat( numberFormat ); + df.setParseBigDecimal( true ); + return df; + } +} diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java new file mode 100644 index 0000000000..0b536b8327 --- /dev/null +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java @@ -0,0 +1,525 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.numbers; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import javax.annotation.processing.Generated; + +@Generated( + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-09-14T11:36:20+0300", + comments = "version: , compiler: javac, environment: Java 17.0.10 (Private Build)" +) +public class SourceTargetMapperImpl implements SourceTargetMapper { + + @Override + public Target sourceToTarget(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setI( new DecimalFormat( "##.00" ).format( source.getI() ) ); + if ( source.getIi() != null ) { + target.setIi( new DecimalFormat( "##.00" ).format( source.getIi() ) ); + } + target.setD( new DecimalFormat( "##.00" ).format( source.getD() ) ); + if ( source.getDd() != null ) { + target.setDd( new DecimalFormat( "##.00" ).format( source.getDd() ) ); + } + target.setF( new DecimalFormat( "##.00" ).format( source.getF() ) ); + if ( source.getFf() != null ) { + target.setFf( new DecimalFormat( "##.00" ).format( source.getFf() ) ); + } + target.setL( new DecimalFormat( "##.00" ).format( source.getL() ) ); + if ( source.getLl() != null ) { + target.setLl( new DecimalFormat( "##.00" ).format( source.getLl() ) ); + } + target.setB( new DecimalFormat( "##.00" ).format( source.getB() ) ); + if ( source.getBb() != null ) { + target.setBb( new DecimalFormat( "##.00" ).format( source.getBb() ) ); + } + target.setComplex1( new DecimalFormat( "##0.##E0" ).format( source.getComplex1() ) ); + target.setComplex2( new DecimalFormat( "$#.00" ).format( source.getComplex2() ) ); + if ( source.getBigDecimal1() != null ) { + target.setBigDecimal1( createDecimalFormat( "#0.#E0" ).format( source.getBigDecimal1() ) ); + } + if ( source.getBigInteger1() != null ) { + target.setBigInteger1( createDecimalFormat( "0.#############E0" ).format( source.getBigInteger1() ) ); + } + + return target; + } + + @Override + public Target sourceToTargetWithCustomLocale(Source source) { + if ( source == null ) { + return null; + } + + Target target = new Target(); + + target.setI( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getI() ) ); + if ( source.getIi() != null ) { + target.setIi( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getIi() ) ); + } + target.setD( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getD() ) ); + if ( source.getDd() != null ) { + target.setDd( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getDd() ) ); + } + target.setF( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getF() ) ); + if ( source.getFf() != null ) { + target.setFf( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getFf() ) ); + } + target.setL( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getL() ) ); + if ( source.getLl() != null ) { + target.setLl( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getLl() ) ); + } + target.setB( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getB() ) ); + if ( source.getBb() != null ) { + target.setBb( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getBb() ) ); + } + target.setComplex1( new DecimalFormat( "##0.##E0", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getComplex1() ) ); + target.setComplex2( new DecimalFormat( "$#.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).format( source.getComplex2() ) ); + if ( source.getBigDecimal1() != null ) { + target.setBigDecimal1( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "ru" ) ).format( source.getBigDecimal1() ) ); + } + if ( source.getBigInteger1() != null ) { + target.setBigInteger1( createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "ru" ) ).format( source.getBigInteger1() ) ); + } + + return target; + } + + @Override + public Source targetToSource(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + try { + if ( target.getI() != null ) { + source.setI( new DecimalFormat( "##.00" ).parse( target.getI() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getIi() != null ) { + source.setIi( new DecimalFormat( "##.00" ).parse( target.getIi() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getD() != null ) { + source.setD( new DecimalFormat( "##.00" ).parse( target.getD() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getDd() != null ) { + source.setDd( new DecimalFormat( "##.00" ).parse( target.getDd() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getF() != null ) { + source.setF( new DecimalFormat( "##.00" ).parse( target.getF() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getFf() != null ) { + source.setFf( new DecimalFormat( "##.00" ).parse( target.getFf() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getL() != null ) { + source.setL( new DecimalFormat( "##.00" ).parse( target.getL() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getLl() != null ) { + source.setLl( new DecimalFormat( "##.00" ).parse( target.getLl() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getB() != null ) { + source.setB( new DecimalFormat( "##.00" ).parse( target.getB() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBb() != null ) { + source.setBb( new DecimalFormat( "##.00" ).parse( target.getBb() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex1() != null ) { + source.setComplex1( new DecimalFormat( "##0.##E0" ).parse( target.getComplex1() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex2() != null ) { + source.setComplex2( new DecimalFormat( "$#.00" ).parse( target.getComplex2() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigDecimal1() != null ) { + source.setBigDecimal1( (BigDecimal) createDecimalFormat( "#0.#E0" ).parse( target.getBigDecimal1() ) ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigInteger1() != null ) { + source.setBigInteger1( ( (BigDecimal) createDecimalFormat( "0.#############E0" ).parse( target.getBigInteger1() ) ).toBigInteger() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + + return source; + } + + @Override + public Source targetToSourceWithCustomLocale(Target target) { + if ( target == null ) { + return null; + } + + Source source = new Source(); + + try { + if ( target.getI() != null ) { + source.setI( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getI() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getIi() != null ) { + source.setIi( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getIi() ).intValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getD() != null ) { + source.setD( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getD() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getDd() != null ) { + source.setDd( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getDd() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getF() != null ) { + source.setF( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getF() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getFf() != null ) { + source.setFf( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getFf() ).floatValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getL() != null ) { + source.setL( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getL() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getLl() != null ) { + source.setLl( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getLl() ).longValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getB() != null ) { + source.setB( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getB() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBb() != null ) { + source.setBb( new DecimalFormat( "##.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getBb() ).byteValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex1() != null ) { + source.setComplex1( new DecimalFormat( "##0.##E0", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getComplex1() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getComplex2() != null ) { + source.setComplex2( new DecimalFormat( "$#.00", DecimalFormatSymbols.getInstance( Locale.forLanguageTag( "ru " ) ) ).parse( target.getComplex2() ).doubleValue() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigDecimal1() != null ) { + source.setBigDecimal1( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "ru" ) ).parse( target.getBigDecimal1() ) ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + try { + if ( target.getBigInteger1() != null ) { + source.setBigInteger1( ( (BigDecimal) createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "ru" ) ).parse( target.getBigInteger1() ) ).toBigInteger() ); + } + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + + return source; + } + + @Override + public List sourceToTarget(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( Float float1 : source ) { + list.add( new DecimalFormat( "##.00" ).format( float1 ) ); + } + + return list; + } + + @Override + public List targetToSource(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( String string : source ) { + try { + list.add( new DecimalFormat( "##.00" ).parse( string ).floatValue() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + } + + return list; + } + + @Override + public List sourceToTargetWithCustomLocale(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( BigDecimal bigDecimal : source ) { + list.add( createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( bigDecimal ) ); + } + + return list; + } + + @Override + public List targetToSourceWithCustomLocale(List source) { + if ( source == null ) { + return null; + } + + List list = new ArrayList( source.size() ); + for ( String string : source ) { + try { + list.add( (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( string ) ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + } + + return list; + } + + @Override + public Map sourceToTarget(Map source) { + if ( source == null ) { + return null; + } + + Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + String key = new DecimalFormat( "##.00" ).format( entry.getKey() ); + String value = new DecimalFormat( "##" ).format( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public Map sourceToTargetWithCustomLocale(Map source) { + if ( source == null ) { + return null; + } + + Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + String key = createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).format( entry.getKey() ); + String value = createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "fr" ) ).format( entry.getValue() ); + map.put( key, value ); + } + + return map; + } + + @Override + public Map targetToSource(Map source) { + if ( source == null ) { + return null; + } + + Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + Float key; + try { + key = new DecimalFormat( "##.00" ).parse( entry.getKey() ).floatValue(); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + Float value; + try { + value = new DecimalFormat( "##" ).parse( entry.getValue() ).floatValue(); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + map.put( key, value ); + } + + return map; + } + + @Override + public Map targetToSourceWithCustomLocale(Map source) { + if ( source == null ) { + return null; + } + + Map map = new LinkedHashMap( Math.max( (int) ( source.size() / .75f ) + 1, 16 ) ); + + for ( java.util.Map.Entry entry : source.entrySet() ) { + BigDecimal key; + try { + key = (BigDecimal) createDecimalFormatWithLocale( "#0.#E0", Locale.forLanguageTag( "fr" ) ).parse( entry.getKey() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + BigDecimal value; + try { + value = (BigDecimal) createDecimalFormatWithLocale( "0.#############E0", Locale.forLanguageTag( "fr" ) ).parse( entry.getValue() ); + } + catch ( ParseException e ) { + throw new RuntimeException( e ); + } + map.put( key, value ); + } + + return map; + } + + private DecimalFormat createDecimalFormatWithLocale( String numberFormat, Locale locale ) { + + DecimalFormat df = new DecimalFormat( numberFormat, DecimalFormatSymbols.getInstance( locale ) ); + df.setParseBigDecimal( true ); + return df; + } + + private DecimalFormat createDecimalFormat( String numberFormat ) { + + DecimalFormat df = new DecimalFormat( numberFormat ); + df.setParseBigDecimal( true ); + return df; + } +} From f3d2b2e65b5709b7575076a220b938ece7931d21 Mon Sep 17 00:00:00 2001 From: dudxor4587 Date: Fri, 22 Nov 2024 07:14:16 +0900 Subject: [PATCH 0878/1006] Delete unnecessary conditions and modify return statement (#3772) --- .../mapstruct/ap/internal/conversion/Conversions.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 6acb69492a..5090c903f3 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -268,10 +268,10 @@ private void registerNativeTypeConversion(Class sourceType, Class targetTy if ( sourceType.isPrimitive() && targetType.isPrimitive() ) { register( sourceType, targetType, new PrimitiveToPrimitiveConversion( sourceType ) ); } - else if ( sourceType.isPrimitive() && !targetType.isPrimitive() ) { + else if ( sourceType.isPrimitive() ) { register( sourceType, targetType, new PrimitiveToWrapperConversion( sourceType, targetType ) ); } - else if ( !sourceType.isPrimitive() && targetType.isPrimitive() ) { + else if ( targetType.isPrimitive() ) { register( sourceType, targetType, inverse( new PrimitiveToWrapperConversion( targetType, sourceType ) ) ); } else { @@ -390,11 +390,7 @@ public boolean equals(Object obj) { return false; } - if ( !Objects.equals( targetType, other.targetType ) ) { - return false; - } - - return true; + return Objects.equals( targetType, other.targetType ); } } } From 084cf3abc148255404b0e2b79c878e68c8d606d1 Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Fri, 29 Nov 2024 15:33:41 +0700 Subject: [PATCH 0879/1006] Fix javadoc typos (#3780) --- .../java/org/mapstruct/NullValuePropertyMappingStrategy.java | 2 +- .../ap/internal/model/NestedTargetPropertyMappingHolder.java | 2 +- .../java/org/mapstruct/ap/internal/model/source/Method.java | 2 +- .../main/java/org/mapstruct/ap/internal/util/NativeTypes.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index 9e06e723b6..556d4253b1 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -10,7 +10,7 @@ * {@link NullValuePropertyMappingStrategy} can be defined on {@link MapperConfig}, {@link Mapper}, {@link BeanMapping} * and {@link Mapping}. * Precedence is arranged in the reverse order. So {@link Mapping} will override {@link BeanMapping}, will - * overide {@link Mapper} + * override {@link Mapper} * * The enum only applies to update methods: methods that update a pre-existing target (annotated with * {@code @}{@link MappingTarget}). diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index ea05b84cae..2b407e240c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -64,7 +64,7 @@ public List getProcessedSourceParameters() { } /** - * @return all the targets that were hanled + * @return all the targets that were handled */ public Set getHandledTargets() { return handledTargets; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index ad2882080a..bea4d56101 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -83,7 +83,7 @@ public interface Method { Parameter getMappingTargetParameter(); /** - * Returns whether the meethod is designated as bean factory for + * Returns whether the method is designated as bean factory for * mapping target {@link org.mapstruct.ObjectFactory } * * @return true if it is a target bean factory. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index 729cb180ef..0a4ca0cde0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -174,7 +174,7 @@ void removeAndValidateFloatingPointLiteralSuffix() { boolean endsWithDSuffix = PTRN_DOUBLE.matcher( val ).find(); // error handling if ( isFloat && endsWithDSuffix ) { - throw new NumberFormatException( "Assiging double to a float" ); + throw new NumberFormatException( "Assigning double to a float" ); } // remove suffix if ( endsWithLSuffix || endsWithFSuffix || endsWithDSuffix ) { From f98a742f9805dad05653d8fcbae05c085725e4da Mon Sep 17 00:00:00 2001 From: jinhyogyeom <148544516+jinhyogyeom@users.noreply.github.com> Date: Sun, 1 Dec 2024 19:22:51 +0900 Subject: [PATCH 0880/1006] Standardize Class Names to PascalCase in tests (#3773) --- .../referenced/AbstractSourceTargetMapperPrivate.java | 2 +- .../referenced/AbstractSourceTargetMapperProtected.java | 2 +- .../accessibility/referenced/ReferencedAccessibilityTest.java | 4 ++-- ...perPrivateBase.java => SourceTargetMapperPrivateBase.java} | 2 +- ...rotectedBase.java => SourceTargetMapperProtectedBase.java} | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/{SourceTargetmapperPrivateBase.java => SourceTargetMapperPrivateBase.java} (91%) rename processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/{SourceTargetmapperProtectedBase.java => SourceTargetMapperProtectedBase.java} (90%) diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java index 507e63a957..2a16c3980f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperPrivate.java @@ -14,7 +14,7 @@ * @author Sjaak Derksen */ @Mapper -public abstract class AbstractSourceTargetMapperPrivate extends SourceTargetmapperPrivateBase { +public abstract class AbstractSourceTargetMapperPrivate extends SourceTargetMapperPrivateBase { public static final AbstractSourceTargetMapperPrivate INSTANCE = Mappers.getMapper( AbstractSourceTargetMapperPrivate.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java index ef5df10285..ccdba61514 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/AbstractSourceTargetMapperProtected.java @@ -14,7 +14,7 @@ * @author Sjaak Derksen */ @Mapper -public abstract class AbstractSourceTargetMapperProtected extends SourceTargetmapperProtectedBase { +public abstract class AbstractSourceTargetMapperProtected extends SourceTargetMapperProtectedBase { public static final AbstractSourceTargetMapperProtected INSTANCE = Mappers.getMapper( AbstractSourceTargetMapperProtected.class ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java index 3cd62a8b4f..dc3d8ea10f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/ReferencedAccessibilityTest.java @@ -72,12 +72,12 @@ public void shouldNotBeAbleToAccessDefaultMethodInReferencedInOtherPackage() { @ProcessorTest @IssueKey( "206" ) - @WithClasses( { AbstractSourceTargetMapperProtected.class, SourceTargetmapperProtectedBase.class } ) + @WithClasses( { AbstractSourceTargetMapperProtected.class, SourceTargetMapperProtectedBase.class } ) public void shouldBeAbleToAccessProtectedMethodInBase() { } @ProcessorTest @IssueKey("206") - @WithClasses({ AbstractSourceTargetMapperPrivate.class, SourceTargetmapperPrivateBase.class }) + @WithClasses({ AbstractSourceTargetMapperPrivate.class, SourceTargetMapperPrivateBase.class }) @ExpectedCompilationOutcome( value = CompilationResult.SUCCEEDED, diagnostics = { diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateBase.java similarity index 91% rename from processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java rename to processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateBase.java index 94f9b2668f..06dbb0cec7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperPrivateBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperPrivateBase.java @@ -8,7 +8,7 @@ /** * @author Sjaak Derksen */ -public class SourceTargetmapperPrivateBase { +public class SourceTargetMapperPrivateBase { @SuppressWarnings("unused") private ReferencedTarget sourceToTarget(ReferencedSource source) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtectedBase.java similarity index 90% rename from processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java rename to processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtectedBase.java index 263d74bee6..fe5a50fa37 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetmapperProtectedBase.java +++ b/processor/src/test/java/org/mapstruct/ap/test/accessibility/referenced/SourceTargetMapperProtectedBase.java @@ -9,7 +9,7 @@ * * @author Sjaak Derksen */ -public class SourceTargetmapperProtectedBase { +public class SourceTargetMapperProtectedBase { protected ReferencedTarget sourceToTarget( ReferencedSource source ) { ReferencedTarget target = new ReferencedTarget(); From 4812d2b030b199f6761fc8da031236d55bf3538b Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Sat, 7 Dec 2024 14:57:13 +0100 Subject: [PATCH 0881/1006] Align README with v1.6.3 release (#3784) --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 6932f4d748..adb48b2fd4 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # MapStruct - Java bean mappings, the easy way! -[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.6.2-blue.svg)](https://central.sonatype.com/search?q=g:org.mapstruct%20v:1.6.2) +[![Latest Stable Version](https://img.shields.io/badge/Latest%20Stable%20Version-1.6.3-blue.svg)](https://central.sonatype.com/search?q=g:org.mapstruct%20v:1.6.3) [![Latest Version](https://img.shields.io/maven-central/v/org.mapstruct/mapstruct-processor.svg?maxAge=3600&label=Latest%20Release)](https://central.sonatype.com/search?q=g:org.mapstruct) [![License](https://img.shields.io/badge/License-Apache%202.0-yellowgreen.svg)](https://github.com/mapstruct/mapstruct/blob/main/LICENSE.txt) @@ -68,7 +68,7 @@ For Maven-based projects, add the following to your POM file in order to use Map ```xml ... - 1.6.2 + 1.6.3 ... @@ -114,10 +114,10 @@ plugins { dependencies { ... - implementation 'org.mapstruct:mapstruct:1.6.2' + implementation 'org.mapstruct:mapstruct:1.6.3' - annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.2' - testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.2' // if you are using mapstruct in test code + annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3' + testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.6.3' // if you are using mapstruct in test code } ... ``` From 8f962919117c30c95165e5349314c0adea455d8f Mon Sep 17 00:00:00 2001 From: Tran Ngoc Nhan Date: Sat, 18 Jan 2025 19:04:42 +0700 Subject: [PATCH 0882/1006] Fix documentation typo and code polish (#3787) --- .../src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc | 2 +- .../src/main/asciidoc/chapter-6-mapping-collections.asciidoc | 4 ++-- .../java/org/mapstruct/ap/spi/util/IntrospectorUtils.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index ed64580eb4..ea574603ea 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -302,7 +302,7 @@ If you don't want explicitly name all properties from nested source bean, you ca The generated code will map every property from `CustomerDto.record` to `Customer` directly, without need to manually name any of them. The same goes for `Customer.account`. -When there are conflicts, these can be resolved by explicitely defining the mapping. For instance in the example above. `name` occurs in `CustomerDto.record` and in `CustomerDto.account`. The mapping `@Mapping( target = "name", source = "record.name" )` resolves this conflict. +When there are conflicts, these can be resolved by explicitly defining the mapping. For instance in the example above. `name` occurs in `CustomerDto.record` and in `CustomerDto.account`. The mapping `@Mapping( target = "name", source = "record.name" )` resolves this conflict. This "target this" notation can be very useful when mapping hierarchical objects to flat objects and vice versa (`@InheritInverseConfiguration`). diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc index 17025da4de..79d4544f9b 100644 --- a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -192,7 +192,7 @@ The option `DEFAULT` should not be used explicitly. It is used to distinguish be [TIP] ==== -When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with intialized collections instead of Mapstruct creating the target entity by its constructor. +When working with an `adder` method and JPA entities, Mapstruct assumes that the target collections are initialized with a collection implementation (e.g. an `ArrayList`). You can use factories to create a new target entity with initialized collections instead of Mapstruct creating the target entity by its constructor. ==== [[implementation-types-for-collection-mappings]] @@ -224,4 +224,4 @@ When an iterable or map mapping method declares an interface type as return type |`ConcurrentMap`|`ConcurrentHashMap` |`ConcurrentNavigableMap`|`ConcurrentSkipListMap` -|=== +|=== \ No newline at end of file diff --git a/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java b/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java index fccc22b38b..95dcd7a92d 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/util/IntrospectorUtils.java @@ -32,7 +32,7 @@ private IntrospectorUtils() { * @return The decapitalized version of the string. */ public static String decapitalize(String name) { - if ( name == null || name.length() == 0 ) { + if ( name == null || name.isEmpty() ) { return name; } if ( name.length() > 1 && Character.isUpperCase( name.charAt( 1 ) ) && From e0a7d3d0e62695591eef532f63874729c56f64b7 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 17 Jan 2025 18:01:47 +0100 Subject: [PATCH 0883/1006] Use latest Maven Wrapper --- .mvn/wrapper/MavenWrapperDownloader.java | 117 ------ .mvn/wrapper/maven-wrapper.jar | Bin 50710 -> 0 bytes .mvn/wrapper/maven-wrapper.properties | 21 +- mvnw | 451 ++++++++++------------- mvnw.cmd | 281 +++++++------- 5 files changed, 343 insertions(+), 527 deletions(-) delete mode 100644 .mvn/wrapper/MavenWrapperDownloader.java delete mode 100644 .mvn/wrapper/maven-wrapper.jar diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index b901097f2d..0000000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.net.*; -import java.io.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to - * use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = - ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = - ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if(mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if(mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if(!outputFile.getParentFile().exists()) { - if(!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index 2cc7d4a55c0cd0092912bf49ae38b3a9e3fd0054..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50710 zcmbTd1CVCTmM+|7+wQV$+qP}n>auOywyU~q+qUhh+uxis_~*a##hm*_WW?9E7Pb7N%LRFiwbEGCJ0XP=%-6oeT$XZcYgtzC2~q zk(K08IQL8oTl}>>+hE5YRgXTB@fZ4TH9>7=79e`%%tw*SQUa9~$xKD5rS!;ZG@ocK zQdcH}JX?W|0_Afv?y`-NgLum62B&WSD$-w;O6G0Sm;SMX65z)l%m1e-g8Q$QTI;(Q z+x$xth4KFvH@Bs6(zn!iF#nenk^Y^ce;XIItAoCsow38eq?Y-Auh!1in#Rt-_D>H^ z=EjbclGGGa6VnaMGmMLj`x3NcwA43Jb(0gzl;RUIRAUDcR1~99l2SAPkVhoRMMtN} zXvC<tOmX83grD8GSo_Lo?%lNfhD#EBgPo z*nf@ppMC#B!T)Ae0RG$mlJWmGl7CkuU~B8-==5i;rS;8i6rJ=PoQxf446XDX9g|c> zU64ePyMlsI^V5Jq5A+BPe#e73+kpc_r1tv#B)~EZ;7^67F0*QiYfrk0uVW;Qb=NsG zN>gsuCwvb?s-KQIppEaeXtEMdc9dy6Dfduz-tMTms+i01{eD9JE&h?Kht*$eOl#&L zJdM_-vXs(V#$Ed;5wyNWJdPNh+Z$+;$|%qR(t`4W@kDhd*{(7-33BOS6L$UPDeE_53j${QfKN-0v-HG z(QfyvFNbwPK%^!eIo4ac1;b>c0vyf9}Xby@YY!lkz-UvNp zwj#Gg|4B~?n?G^{;(W;|{SNoJbHTMpQJ*Wq5b{l9c8(%?Kd^1?H1om1de0Da9M;Q=n zUfn{f87iVb^>Exl*nZ0hs(Yt>&V9$Pg`zX`AI%`+0SWQ4Zc(8lUDcTluS z5a_KerZWe}a-MF9#Cd^fi!y3%@RFmg&~YnYZ6<=L`UJ0v={zr)>$A;x#MCHZy1st7 ztT+N07NR+vOwSV2pvWuN1%lO!K#Pj0Fr>Q~R40{bwdL%u9i`DSM4RdtEH#cW)6}+I-eE< z&tZs+(Ogu(H_;$a$!7w`MH0r%h&@KM+<>gJL@O~2K2?VrSYUBbhCn#yy?P)uF3qWU z0o09mIik+kvzV6w>vEZy@&Mr)SgxPzUiDA&%07m17udz9usD82afQEps3$pe!7fUf z0eiidkJ)m3qhOjVHC_M(RYCBO%CZKZXFb8}s0-+}@CIn&EF(rRWUX2g^yZCvl0bI} zbP;1S)iXnRC&}5-Tl(hASKqdSnO?ASGJ*MIhOXIblmEudj(M|W!+I3eDc}7t`^mtg z)PKlaXe(OH+q-)qcQ8a@!llRrpGI8DsjhoKvw9T;TEH&?s=LH0w$EzI>%u;oD@x83 zJL7+ncjI9nn!TlS_KYu5vn%f*@qa5F;| zEFxY&B?g=IVlaF3XNm_03PA)=3|{n-UCgJoTr;|;1AU9|kPE_if8!Zvb}0q$5okF$ zHaJdmO&gg!9oN|M{!qGE=tb|3pVQ8PbL$}e;NgXz<6ZEggI}wO@aBP**2Wo=yN#ZC z4G$m^yaM9g=|&!^ft8jOLuzc3Psca*;7`;gnHm}tS0%f4{|VGEwu45KptfNmwxlE~ z^=r30gi@?cOm8kAz!EylA4G~7kbEiRlRIzwrb~{_2(x^$-?|#e6Bi_**(vyr_~9Of z!n>Gqf+Qwiu!xhi9f53=PM3`3tNF}pCOiPU|H4;pzjcsqbwg*{{kyrTxk<;mx~(;; z1NMrpaQ`57yn34>Jo3b|HROE(UNcQash!0p2-!Cz;{IRv#Vp5!3o$P8!%SgV~k&Hnqhp`5eLjTcy93cK!3Hm-$`@yGnaE=?;*2uSpiZTs_dDd51U%i z{|Zd9ou-;laGS_x=O}a+ zB||za<795A?_~Q=r=coQ+ZK@@ zId~hWQL<%)fI_WDIX#=(WNl!Dm$a&ROfLTd&B$vatq!M-2Jcs;N2vps$b6P1(N}=oI3<3luMTmC|0*{ zm1w8bt7vgX($!0@V0A}XIK)w!AzUn7vH=pZEp0RU0p?}ch2XC-7r#LK&vyc2=-#Q2 z^L%8)JbbcZ%g0Du;|8=q8B>X=mIQirpE=&Ox{TiuNDnOPd-FLI^KfEF729!!0x#Es z@>3ursjFSpu%C-8WL^Zw!7a0O-#cnf`HjI+AjVCFitK}GXO`ME&on|^=~Zc}^LBp9 zj=-vlN;Uc;IDjtK38l7}5xxQF&sRtfn4^TNtnzXv4M{r&ek*(eNbIu!u$>Ed%` z5x7+&)2P&4>0J`N&ZP8$vcR+@FS0126s6+Jx_{{`3ZrIMwaJo6jdrRwE$>IU_JTZ} z(||hyyQ)4Z1@wSlT94(-QKqkAatMmkT7pCycEB1U8KQbFX&?%|4$yyxCtm3=W`$4fiG0WU3yI@c zx{wfmkZAYE_5M%4{J-ygbpH|(|GD$2f$3o_Vti#&zfSGZMQ5_f3xt6~+{RX=$H8at z?GFG1Tmp}}lmm-R->ve*Iv+XJ@58p|1_jRvfEgz$XozU8#iJS})UM6VNI!3RUU!{5 zXB(+Eqd-E;cHQ>)`h0(HO_zLmzR3Tu-UGp;08YntWwMY-9i^w_u#wR?JxR2bky5j9 z3Sl-dQQU$xrO0xa&>vsiK`QN<$Yd%YXXM7*WOhnRdSFt5$aJux8QceC?lA0_if|s> ze{ad*opH_kb%M&~(~&UcX0nFGq^MqjxW?HJIP462v9XG>j(5Gat_)#SiNfahq2Mz2 zU`4uV8m$S~o9(W>mu*=h%Gs(Wz+%>h;R9Sg)jZ$q8vT1HxX3iQnh6&2rJ1u|j>^Qf`A76K%_ubL`Zu?h4`b=IyL>1!=*%!_K)=XC z6d}4R5L+sI50Q4P3upXQ3Z!~1ZXLlh!^UNcK6#QpYt-YC=^H=EPg3)z*wXo*024Q4b2sBCG4I# zlTFFY=kQ>xvR+LsuDUAk)q%5pEcqr(O_|^spjhtpb1#aC& zghXzGkGDC_XDa%t(X`E+kvKQ4zrQ*uuQoj>7@@ykWvF332)RO?%AA&Fsn&MNzmFa$ zWk&&^=NNjxLjrli_8ESU)}U|N{%j&TQmvY~lk!~Jh}*=^INA~&QB9em!in_X%Rl1&Kd~Z(u z9mra#<@vZQlOY+JYUwCrgoea4C8^(xv4ceCXcejq84TQ#sF~IU2V}LKc~Xlr_P=ry zl&Hh0exdCbVd^NPCqNNlxM3vA13EI8XvZ1H9#bT7y*U8Y{H8nwGpOR!e!!}*g;mJ#}T{ekSb}5zIPmye*If(}}_=PcuAW#yidAa^9-`<8Gr0 z)Fz=NiZ{)HAvw{Pl5uu)?)&i&Us$Cx4gE}cIJ}B4Xz~-q7)R_%owbP!z_V2=Aq%Rj z{V;7#kV1dNT9-6R+H}}(ED*_!F=~uz>&nR3gb^Ce%+0s#u|vWl<~JD3MvS0T9thdF zioIG3c#Sdsv;LdtRv3ml7%o$6LTVL>(H`^@TNg`2KPIk*8-IB}X!MT0`hN9Ddf7yN z?J=GxPL!uJ7lqwowsl?iRrh@#5C$%E&h~Z>XQcvFC*5%0RN-Opq|=IwX(dq(*sjs+ zqy99+v~m|6T#zR*e1AVxZ8djd5>eIeCi(b8sUk)OGjAsKSOg^-ugwl2WSL@d#?mdl zib0v*{u-?cq}dDGyZ%$XRY=UkQwt2oGu`zQneZh$=^! zj;!pCBWQNtvAcwcWIBM2y9!*W|8LmQy$H~5BEx)78J`4Z0(FJO2P^!YyQU{*Al+fs z){!4JvT1iLrJ8aU3k0t|P}{RN)_^v%$$r;+p0DY7N8CXzmS*HB*=?qaaF9D@#_$SN zSz{moAK<*RH->%r7xX~9gVW$l7?b|_SYI)gcjf0VAUJ%FcQP(TpBs; zg$25D!Ry_`8xpS_OJdeo$qh#7U+cepZ??TII7_%AXsT$B z=e)Bx#v%J0j``00Zk5hsvv6%T^*xGNx%KN-=pocSoqE5_R)OK%-Pbu^1MNzfds)mL zxz^F4lDKV9D&lEY;I+A)ui{TznB*CE$=9(wgE{m}`^<--OzV-5V4X2w9j(_!+jpTr zJvD*y6;39&T+==$F&tsRKM_lqa1HC}aGL0o`%c9mO=fts?36@8MGm7Vi{Y z^<7m$(EtdSr#22<(rm_(l_(`j!*Pu~Y>>xc>I9M#DJYDJNHO&4=HM%YLIp?;iR&$m z#_$ZWYLfGLt5FJZhr3jpYb`*%9S!zCG6ivNHYzNHcI%khtgHBliM^Ou}ZVD7ehU9 zS+W@AV=?Ro!=%AJ>Kcy9aU3%VX3|XM_K0A+ZaknKDyIS3S-Hw1C7&BSW5)sqj5Ye_ z4OSW7Yu-;bCyYKHFUk}<*<(@TH?YZPHr~~Iy%9@GR2Yd}J2!N9K&CN7Eq{Ka!jdu; zQNB*Y;i(7)OxZK%IHGt#Rt?z`I|A{q_BmoF!f^G}XVeTbe1Wnzh%1g>j}>DqFf;Rp zz7>xIs12@Ke0gr+4-!pmFP84vCIaTjqFNg{V`5}Rdt~xE^I;Bxp4)|cs8=f)1YwHz zqI`G~s2~qqDV+h02b`PQpUE#^^Aq8l%y2|ByQeXSADg5*qMprEAE3WFg0Q39`O+i1 z!J@iV!`Y~C$wJ!5Z+j5$i<1`+@)tBG$JL=!*uk=2k;T<@{|s1$YL079FvK%mPhyHV zP8^KGZnp`(hVMZ;s=n~3r2y;LTwcJwoBW-(ndU-$03{RD zh+Qn$ja_Z^OuMf3Ub|JTY74s&Am*(n{J3~@#OJNYuEVVJd9*H%)oFoRBkySGm`hx! zT3tG|+aAkXcx-2Apy)h^BkOyFTWQVeZ%e2@;*0DtlG9I3Et=PKaPt&K zw?WI7S;P)TWED7aSH$3hL@Qde?H#tzo^<(o_sv_2ci<7M?F$|oCFWc?7@KBj-;N$P zB;q!8@bW-WJY9do&y|6~mEruZAVe$!?{)N9rZZxD-|oltkhW9~nR8bLBGXw<632!l z*TYQn^NnUy%Ds}$f^=yQ+BM-a5X4^GHF=%PDrRfm_uqC zh{sKwIu|O0&jWb27;wzg4w5uA@TO_j(1X?8E>5Zfma|Ly7Bklq|s z9)H`zoAGY3n-+&JPrT!>u^qg9Evx4y@GI4$n-Uk_5wttU1_t?6><>}cZ-U+&+~JE) zPlDbO_j;MoxdLzMd~Ew|1o^a5q_1R*JZ=#XXMzg?6Zy!^hop}qoLQlJ{(%!KYt`MK z8umEN@Z4w!2=q_oe=;QttPCQy3Nm4F@x>@v4sz_jo{4m*0r%J(w1cSo;D_hQtJs7W z><$QrmG^+<$4{d2bgGo&3-FV}avg9zI|Rr(k{wTyl3!M1q+a zD9W{pCd%il*j&Ft z5H$nENf>>k$;SONGW`qo6`&qKs*T z2^RS)pXk9b@(_Fw1bkb)-oqK|v}r$L!W&aXA>IpcdNZ_vWE#XO8X`#Yp1+?RshVcd zknG%rPd*4ECEI0wD#@d+3NbHKxl}n^Sgkx==Iu%}HvNliOqVBqG?P2va zQ;kRJ$J6j;+wP9cS za#m;#GUT!qAV%+rdWolk+)6kkz4@Yh5LXP+LSvo9_T+MmiaP-eq6_k;)i6_@WSJ zlT@wK$zqHu<83U2V*yJ|XJU4farT#pAA&@qu)(PO^8PxEmPD4;Txpio+2)#!9 z>&=i7*#tc0`?!==vk>s7V+PL#S1;PwSY?NIXN2=Gu89x(cToFm))7L;< z+bhAbVD*bD=}iU`+PU+SBobTQ%S!=VL!>q$rfWsaaV}Smz>lO9JXT#`CcH_mRCSf4%YQAw`$^yY z3Y*^Nzk_g$xn7a_NO(2Eb*I=^;4f!Ra#Oo~LLjlcjke*k*o$~U#0ZXOQ5@HQ&T46l z7504MUgZkz2gNP1QFN8Y?nSEnEai^Rgyvl}xZfMUV6QrJcXp;jKGqB=D*tj{8(_pV zqyB*DK$2lgYGejmJUW)*s_Cv65sFf&pb(Yz8oWgDtQ0~k^0-wdF|tj}MOXaN@ydF8 zNr={U?=;&Z?wr^VC+`)S2xl}QFagy;$mG=TUs7Vi2wws5zEke4hTa2)>O0U?$WYsZ z<8bN2bB_N4AWd%+kncgknZ&}bM~eDtj#C5uRkp21hWW5gxWvc6b*4+dn<{c?w9Rmf zIVZKsPl{W2vQAlYO3yh}-{Os=YBnL8?uN5(RqfQ=-1cOiUnJu>KcLA*tQK3FU`_bM zM^T28w;nAj5EdAXFi&Kk1Nnl2)D!M{@+D-}bIEe+Lc4{s;YJc-{F#``iS2uk;2!Zp zF9#myUmO!wCeJIoi^A+T^e~20c+c2C}XltaR!|U-HfDA=^xF97ev}$l6#oY z&-&T{egB)&aV$3_aVA51XGiU07$s9vubh_kQG?F$FycvS6|IO!6q zq^>9|3U^*!X_C~SxX&pqUkUjz%!j=VlXDo$!2VLH!rKj@61mDpSr~7B2yy{>X~_nc zRI+7g2V&k zd**H++P9dg!-AOs3;GM`(g<+GRV$+&DdMVpUxY9I1@uK28$az=6oaa+PutlO9?6#? zf-OsgT>^@8KK>ggkUQRPPgC7zjKFR5spqQb3ojCHzj^(UH~v+!y*`Smv)VpVoPwa6 zWG18WJaPKMi*F6Zdk*kU^`i~NNTfn3BkJniC`yN98L-Awd)Z&mY? zprBW$!qL-OL7h@O#kvYnLsfff@kDIegt~?{-*5A7JrA;#TmTe?jICJqhub-G@e??D zqiV#g{)M!kW1-4SDel7TO{;@*h2=_76g3NUD@|c*WO#>MfYq6_YVUP+&8e4|%4T`w zXzhmVNziAHazWO2qXcaOu@R1MrPP{t)`N)}-1&~mq=ZH=w=;-E$IOk=y$dOls{6sRR`I5>|X zpq~XYW4sd;J^6OwOf**J>a7u$S>WTFPRkjY;BfVgQst)u4aMLR1|6%)CB^18XCz+r ztkYQ}G43j~Q&1em(_EkMv0|WEiKu;z2zhb(L%$F&xWwzOmk;VLBYAZ8lOCziNoPw1 zv2BOyXA`A8z^WH!nXhKXM`t0;6D*-uGds3TYGrm8SPnJJOQ^fJU#}@aIy@MYWz**H zvkp?7I5PE{$$|~{-ZaFxr6ZolP^nL##mHOErB^AqJqn^hFA=)HWj!m3WDaHW$C)i^ z9@6G$SzB=>jbe>4kqr#sF7#K}W*Cg-5y6kun3u&0L7BpXF9=#7IN8FOjWrWwUBZiU zT_se3ih-GBKx+Uw0N|CwP3D@-C=5(9T#BH@M`F2!Goiqx+Js5xC92|Sy0%WWWp={$(am!#l~f^W_oz78HX<0X#7 zp)p1u~M*o9W@O8P{0Qkg@Wa# z2{Heb&oX^CQSZWSFBXKOfE|tsAm#^U-WkDnU;IowZ`Ok4!mwHwH=s|AqZ^YD4!5!@ zPxJj+Bd-q6w_YG`z_+r;S86zwXb+EO&qogOq8h-Ect5(M2+>(O7n7)^dP*ws_3U6v zVsh)sk^@*c>)3EML|0<-YROho{lz@Nd4;R9gL{9|64xVL`n!m$-Jjrx?-Bacp!=^5 z1^T^eB{_)Y<9)y{-4Rz@9_>;_7h;5D+@QcbF4Wv7hu)s0&==&6u)33 zHRj+&Woq-vDvjwJCYES@$C4{$?f$Ibi4G()UeN11rgjF+^;YE^5nYprYoJNoudNj= zm1pXSeG64dcWHObUetodRn1Fw|1nI$D9z}dVEYT0lQnsf_E1x2vBLql7NrHH!n&Sq z6lc*mvU=WS6=v9Lrl}&zRiu_6u;6g%_DU{9b+R z#YHqX7`m9eydf?KlKu6Sb%j$%_jmydig`B*TN`cZL-g!R)iE?+Q5oOqBFKhx z%MW>BC^(F_JuG(ayE(MT{S3eI{cKiwOtPwLc0XO*{*|(JOx;uQOfq@lp_^cZo=FZj z4#}@e@dJ>Bn%2`2_WPeSN7si^{U#H=7N4o%Dq3NdGybrZgEU$oSm$hC)uNDC_M9xc zGzwh5Sg?mpBIE8lT2XsqTt3j3?We8}3bzLBTQd639vyg^$0#1epq8snlDJP2(BF)K zSx30RM+{f+b$g{9usIL8H!hCO117Xgv}ttPJm9wVRjPk;ePH@zxv%j9k5`TzdXLeT zFgFX`V7cYIcBls5WN0Pf6SMBN+;CrQ(|EsFd*xtwr#$R{Z9FP`OWtyNsq#mCgZ7+P z^Yn$haBJ)r96{ZJd8vlMl?IBxrgh=fdq_NF!1{jARCVz>jNdC)H^wfy?R94#MPdUjcYX>#wEx+LB#P-#4S-%YH>t-j+w zOFTI8gX$ard6fAh&g=u&56%3^-6E2tpk*wx3HSCQ+t7+*iOs zPk5ysqE}i*cQocFvA68xHfL|iX(C4h*67@3|5Qwle(8wT&!&{8*{f%0(5gH+m>$tq zp;AqrP7?XTEooYG1Dzfxc>W%*CyL16q|fQ0_jp%%Bk^k!i#Nbi(N9&T>#M{gez_Ws zYK=l}adalV(nH}I_!hNeb;tQFk3BHX7N}}R8%pek^E`X}%ou=cx8InPU1EE0|Hen- zyw8MoJqB5=)Z%JXlrdTXAE)eqLAdVE-=>wGHrkRet}>3Yu^lt$Kzu%$3#(ioY}@Gu zjk3BZuQH&~7H+C*uX^4}F*|P89JX;Hg2U!pt>rDi(n(Qe-c}tzb0#6_ItoR0->LSt zR~UT<-|@TO%O`M+_e_J4wx7^)5_%%u+J=yF_S#2Xd?C;Ss3N7KY^#-vx+|;bJX&8r zD?|MetfhdC;^2WG`7MCgs>TKKN=^=!x&Q~BzmQio_^l~LboTNT=I zC5pme^P@ER``p$2md9>4!K#vV-Fc1an7pl>_|&>aqP}+zqR?+~Z;f2^`a+-!Te%V? z;H2SbF>jP^GE(R1@%C==XQ@J=G9lKX+Z<@5}PO(EYkJh=GCv#)Nj{DkWJM2}F&oAZ6xu8&g7pn1ps2U5srwQ7CAK zN&*~@t{`31lUf`O;2w^)M3B@o)_mbRu{-`PrfNpF!R^q>yTR&ETS7^-b2*{-tZAZz zw@q5x9B5V8Qd7dZ!Ai$9hk%Q!wqbE1F1c96&zwBBaRW}(^axoPpN^4Aw}&a5dMe+*Gomky_l^54*rzXro$ z>LL)U5Ry>~FJi=*{JDc)_**c)-&faPz`6v`YU3HQa}pLtb5K)u%K+BOqXP0)rj5Au$zB zW1?vr?mDv7Fsxtsr+S6ucp2l#(4dnr9sD*v+@*>g#M4b|U?~s93>Pg{{a5|rm2xfI z`>E}?9S@|IoUX{Q1zjm5YJT|3S>&09D}|2~BiMo=z4YEjXlWh)V&qs;*C{`UMxp$9 zX)QB?G$fPD6z5_pNs>Jeh{^&U^)Wbr?2D6-q?)`*1k@!UvwQgl8eG$r+)NnFoT)L6 zg7lEh+E6J17krfYJCSjWzm67hEth24pomhz71|Qodn#oAILN)*Vwu2qpJirG)4Wnv}9GWOFrQg%Je+gNrPl8mw7ykE8{ z=|B4+uwC&bpp%eFcRU6{mxRV32VeH8XxX>v$du<$(DfinaaWxP<+Y97Z#n#U~V zVEu-GoPD=9$}P;xv+S~Ob#mmi$JQmE;Iz4(){y*9pFyW-jjgdk#oG$fl4o9E8bo|L zWjo4l%n51@Kz-n%zeSCD`uB?T%FVk+KBI}=ve zvlcS#wt`U6wrJo}6I6Rwb=1GzZfwE=I&Ne@p7*pH84XShXYJRgvK)UjQL%R9Zbm(m zxzTQsLTON$WO7vM)*vl%Pc0JH7WhP;$z@j=y#avW4X8iqy6mEYr@-}PW?H)xfP6fQ z&tI$F{NNct4rRMSHhaelo<5kTYq+(?pY)Ieh8*sa83EQfMrFupMM@nfEV@EmdHUv9 z35uzIrIuo4#WnF^_jcpC@uNNaYTQ~uZWOE6P@LFT^1@$o&q+9Qr8YR+ObBkpP9=F+$s5+B!mX2~T zAuQ6RenX?O{IlLMl1%)OK{S7oL}X%;!XUxU~xJN8xk z`xywS*naF(J#?vOpB(K=o~lE;m$zhgPWDB@=p#dQIW>xe_p1OLoWInJRKbEuoncf; zmS1!u-ycc1qWnDg5Nk2D)BY%jmOwCLC+Ny>`f&UxFowIsHnOXfR^S;&F(KXd{ODlm z$6#1ccqt-HIH9)|@fHnrKudu!6B$_R{fbCIkSIb#aUN|3RM>zuO>dpMbROZ`^hvS@ z$FU-;e4W}!ubzKrU@R*dW*($tFZ>}dd*4_mv)#O>X{U@zSzQt*83l9mI zI$8O<5AIDx`wo0}f2fsPC_l>ONx_`E7kdXu{YIZbp1$(^oBAH({T~&oQ&1{X951QW zmhHUxd)t%GQ9#ak5fTjk-cahWC;>^Rg7(`TVlvy0W@Y!Jc%QL3Ozu# zDPIqBCy&T2PWBj+d-JA-pxZlM=9ja2ce|3B(^VCF+a*MMp`(rH>Rt6W1$;r{n1(VK zLs>UtkT43LR2G$AOYHVailiqk7naz2yZGLo*xQs!T9VN5Q>eE(w zw$4&)&6xIV$IO^>1N-jrEUg>O8G4^@y+-hQv6@OmF@gy^nL_n1P1-Rtyy$Bl;|VcV zF=p*&41-qI5gG9UhKmmnjs932!6hceXa#-qfK;3d*a{)BrwNFeKU|ge?N!;zk+kB! zMD_uHJR#%b54c2tr~uGPLTRLg$`fupo}cRJeTwK;~}A>(Acy4k-Xk&Aa1&eWYS1ULWUj@fhBiWY$pdfy+F z@G{OG{*v*mYtH3OdUjwEr6%_ZPZ3P{@rfbNPQG!BZ7lRyC^xlMpWH`@YRar`tr}d> z#wz87t?#2FsH-jM6m{U=gp6WPrZ%*w0bFm(T#7m#v^;f%Z!kCeB5oiF`W33W5Srdt zdU?YeOdPG@98H7NpI{(uN{FJdu14r(URPH^F6tOpXuhU7T9a{3G3_#Ldfx_nT(Hec zo<1dyhsVsTw;ZkVcJ_0-h-T3G1W@q)_Q30LNv)W?FbMH+XJ* zy=$@39Op|kZv`Rt>X`zg&at(?PO^I=X8d9&myFEx#S`dYTg1W+iE?vt#b47QwoHI9 zNP+|3WjtXo{u}VG(lLUaW0&@yD|O?4TS4dfJI`HC-^q;M(b3r2;7|FONXphw-%7~* z&;2!X17|05+kZOpQ3~3!Nb>O94b&ZSs%p)TK)n3m=4eiblVtSx@KNFgBY_xV6ts;NF;GcGxMP8OKV^h6LmSb2E#Qnw ze!6Mnz7>lE9u{AgQ~8u2zM8CYD5US8dMDX-5iMlgpE9m*s+Lh~A#P1er*rF}GHV3h z=`STo?kIXw8I<`W0^*@mB1$}pj60R{aJ7>C2m=oghKyxMbFNq#EVLgP0cH3q7H z%0?L93-z6|+jiN|@v>ix?tRBU(v-4RV`}cQH*fp|)vd3)8i9hJ3hkuh^8dz{F5-~_ zUUr1T3cP%cCaTooM8dj|4*M=e6flH0&8ve32Q)0dyisl))XkZ7Wg~N}6y`+Qi2l+e zUd#F!nJp{#KIjbQdI`%oZ`?h=5G^kZ_uN`<(`3;a!~EMsWV|j-o>c?x#;zR2ktiB! z);5rrHl?GPtr6-o!tYd|uK;Vbsp4P{v_4??=^a>>U4_aUXPWQ$FPLE4PK$T^3Gkf$ zHo&9$U&G`d(Os6xt1r?sg14n)G8HNyWa^q8#nf0lbr4A-Fi;q6t-`pAx1T*$eKM*$ z|CX|gDrk#&1}>5H+`EjV$9Bm)Njw&7-ZR{1!CJTaXuP!$Pcg69`{w5BRHysB$(tWUes@@6aM69kb|Lx$%BRY^-o6bjH#0!7b;5~{6J+jKxU!Kmi# zndh@+?}WKSRY2gZ?Q`{(Uj|kb1%VWmRryOH0T)f3cKtG4oIF=F7RaRnH0Rc_&372={_3lRNsr95%ZO{IX{p@YJ^EI%+gvvKes5cY+PE@unghjdY5#9A!G z70u6}?zmd?v+{`vCu-53_v5@z)X{oPC@P)iA3jK$`r zSA2a7&!^zmUiZ82R2=1cumBQwOJUPz5Ay`RLfY(EiwKkrx%@YN^^XuET;tE zmr-6~I7j!R!KrHu5CWGSChO6deaLWa*9LLJbcAJsFd%Dy>a!>J`N)Z&oiU4OEP-!Ti^_!p}O?7`}i7Lsf$-gBkuY*`Zb z7=!nTT;5z$_5$=J=Ko+Cp|Q0J=%oFr>hBgnL3!tvFoLNhf#D0O=X^h+x08iB;@8pXdRHxX}6R4k@i6%vmsQwu^5z zk1ip`#^N)^#Lg#HOW3sPI33xqFB4#bOPVnY%d6prwxf;Y-w9{ky4{O6&94Ra8VN@K zb-lY;&`HtxW@sF!doT5T$2&lIvJpbKGMuDAFM#!QPXW87>}=Q4J3JeXlwHys?!1^#37q_k?N@+u&Ns20pEoBeZC*np;i;M{2C0Z4_br2gsh6eL z#8`#sn41+$iD?^GL%5?cbRcaa-Nx0vE(D=*WY%rXy3B%gNz0l?#noGJGP728RMY#q z=2&aJf@DcR?QbMmN)ItUe+VM_U!ryqA@1VVt$^*xYt~-qvW!J4Tp<-3>jT=7Zow5M z8mSKp0v4b%a8bxFr>3MwZHSWD73D@+$5?nZAqGM#>H@`)mIeC#->B)P8T$zh-Pxnc z8)~Zx?TWF4(YfKuF3WN_ckpCe5;x4V4AA3(i$pm|78{%!q?|~*eH0f=?j6i)n~Hso zmTo>vqEtB)`%hP55INf7HM@taH)v`Fw40Ayc*R!T?O{ziUpYmP)AH`euTK!zg9*6Z z!>M=$3pd0!&TzU=hc_@@^Yd3eUQpX4-33}b{?~5t5lgW=ldJ@dUAH%`l5US1y_`40 zs(X`Qk}vvMDYYq+@Rm+~IyCX;iD~pMgq^KY)T*aBz@DYEB={PxA>)mI6tM*sx-DmGQHEaHwRrAmNjO!ZLHO4b;;5mf@zzlPhkP($JeZGE7 z?^XN}Gf_feGoG~BjUgVa*)O`>lX=$BSR2)uD<9 z>o^|nb1^oVDhQbfW>>!;8-7<}nL6L^V*4pB=>wwW+RXAeRvKED(n1;R`A6v$6gy0I(;Vf?!4;&sgn7F%LpM}6PQ?0%2Z@b{It<(G1CZ|>913E0nR2r^Pa*Bp z@tFGi*CQ~@Yc-?{cwu1 zsilf=k^+Qs>&WZG(3WDixisHpR>`+ihiRwkL(3T|=xsoNP*@XX3BU8hr57l3k;pni zI``=3Nl4xh4oDj<%>Q1zYXHr%Xg_xrK3Nq?vKX3|^Hb(Bj+lONTz>4yhU-UdXt2>j z<>S4NB&!iE+ao{0Tx^N*^|EZU;0kJkx@zh}S^P{ieQjGl468CbC`SWnwLRYYiStXm zOxt~Rb3D{dz=nHMcY)#r^kF8|q8KZHVb9FCX2m^X*(|L9FZg!5a7((!J8%MjT$#Fs)M1Pb zq6hBGp%O1A+&%2>l0mpaIzbo&jc^!oN^3zxap3V2dNj3x<=TwZ&0eKX5PIso9j1;e zwUg+C&}FJ`k(M|%%}p=6RPUq4sT3-Y;k-<68ciZ~_j|bt>&9ZLHNVrp#+pk}XvM{8 z`?k}o-!if>hVlCP9j%&WI2V`5SW)BCeR5>MQhF)po=p~AYN%cNa_BbV6EEh_kk^@a zD>4&>uCGCUmyA-c)%DIcF4R6!>?6T~Mj_m{Hpq`*(wj>foHL;;%;?(((YOxGt)Bhx zuS+K{{CUsaC++%}S6~CJ=|vr(iIs-je)e9uJEU8ZJAz)w166q)R^2XI?@E2vUQ!R% zn@dxS!JcOimXkWJBz8Y?2JKQr>`~SmE2F2SL38$SyR1^yqj8_mkBp)o$@+3BQ~Mid z9U$XVqxX3P=XCKj0*W>}L0~Em`(vG<>srF8+*kPrw z20{z(=^w+ybdGe~Oo_i|hYJ@kZl*(9sHw#Chi&OIc?w`nBODp?ia$uF%Hs(X>xm?j zqZQ`Ybf@g#wli`!-al~3GWiE$K+LCe=Ndi!#CVjzUZ z!sD2O*;d28zkl))m)YN7HDi^z5IuNo3^w(zy8 zszJG#mp#Cj)Q@E@r-=NP2FVxxEAeOI2e=|KshybNB6HgE^(r>HD{*}S}mO>LuRGJT{*tfTzw_#+er-0${}%YPe@CMJ1Ng#j#)i)SnY@ss3gL;g zg2D~#Kpdfu#G;q1qz_TwSz1VJT(b3zby$Vk&;Y#1(A)|xj`_?i5YQ;TR%jice5E;0 zYHg;`zS5{S*9xI6o^j>rE8Ua*XhIw{_-*&@(R|C(am8__>+Ws&Q^ymy*X4~hR2b5r zm^p3sw}yv=tdyncy_Ui7{BQS732et~Z_@{-IhHDXAV`(Wlay<#hb>%H%WDi+K$862nA@BDtM#UCKMu+kM`!JHyWSi?&)A7_ z3{cyNG%a~nnH_!+;g&JxEMAmh-Z}rC!o7>OVzW&PoMyTA_g{hqXG)SLraA^OP**<7 zjWbr7z!o2n3hnx7A=2O=WL;`@9N{vQIM@&|G-ljrPvIuJHYtss0Er0fT5cMXNUf1B z7FAwBDixt0X7C3S)mPe5g`YtME23wAnbU)+AtV}z+e8G;0BP=bI;?(#|Ep!vVfDbK zvx+|CKF>yt0hWQ3drchU#XBU+HiuG*V^snFAPUp-5<#R&BUAzoB!aZ+e*KIxa26V}s6?nBK(U-7REa573wg-jqCg>H8~>O{ z*C0JL-?X-k_y%hpUFL?I>0WV{oV`Nb)nZbJG01R~AG>flIJf)3O*oB2i8~;!P?Wo_ z0|QEB*fifiL6E6%>tlAYHm2cjTFE@*<);#>689Z6S#BySQ@VTMhf9vYQyLeDg1*F} zjq>i1*x>5|CGKN{l9br3kB0EHY|k4{%^t7-uhjd#NVipUZa=EUuE5kS1_~qYX?>hJ z$}!jc9$O$>J&wnu0SgfYods^z?J4X;X7c77Me0kS-dO_VUQ39T(Kv(Y#s}Qqz-0AH z^?WRL(4RzpkD+T5FG_0NyPq-a-B7A5LHOCqwObRJi&oRi(<;OuIN7SV5PeHU$<@Zh zPozEV`dYmu0Z&Tqd>t>8JVde9#Pt+l95iHe$4Xwfy1AhI zDM4XJ;bBTTvRFtW>E+GzkN)9k!hA5z;xUOL2 zq4}zn-DP{qc^i|Y%rvi|^5k-*8;JZ~9a;>-+q_EOX+p1Wz;>i7c}M6Nv`^NY&{J-> z`(mzDJDM}QPu5i44**2Qbo(XzZ-ZDu%6vm8w@DUarqXj41VqP~ zs&4Y8F^Waik3y1fQo`bVUH;b=!^QrWb)3Gl=QVKr+6sxc=ygauUG|cm?|X=;Q)kQ8 zM(xrICifa2p``I7>g2R~?a{hmw@{!NS5`VhH8+;cV(F>B94M*S;5#O`YzZH1Z%yD? zZ61w(M`#aS-*~Fj;x|J!KM|^o;MI#Xkh0ULJcA?o4u~f%Z^16ViA27FxU5GM*rKq( z7cS~MrZ=f>_OWx8j#-Q3%!aEU2hVuTu(7`TQk-Bi6*!<}0WQi;_FpO;fhpL4`DcWp zGOw9vx0N~6#}lz(r+dxIGZM3ah-8qrqMmeRh%{z@dbUD2w15*_4P?I~UZr^anP}DB zU9CCrNiy9I3~d#&!$DX9e?A});BjBtQ7oGAyoI$8YQrkLBIH@2;lt4E^)|d6Jwj}z z&2_E}Y;H#6I4<10d_&P0{4|EUacwFHauvrjAnAm6yeR#}f}Rk27CN)vhgRqEyPMMS7zvunj2?`f;%?alsJ+-K+IzjJx>h8 zu~m_y$!J5RWAh|C<6+uiCNsOKu)E72M3xKK(a9Okw3e_*O&}7llNV!=P87VM2DkAk zci!YXS2&=P0}Hx|wwSc9JP%m8dMJA*q&VFB0yMI@5vWoAGraygwn){R+Cj6B1a2Px z5)u(K5{+;z2n*_XD!+Auv#LJEM)(~Hx{$Yb^ldQmcYF2zNH1V30*)CN_|1$v2|`LnFUT$%-tO0Eg|c5$BB~yDfzS zcOXJ$wpzVK0MfTjBJ0b$r#_OvAJ3WRt+YOLlJPYMx~qp>^$$$h#bc|`g0pF-Ao43? z>*A+8lx>}L{p(Tni2Vvk)dtzg$hUKjSjXRagj)$h#8=KV>5s)J4vGtRn5kP|AXIz! zPgbbVxW{2o4s-UM;c#We8P&mPN|DW7_uLF!a|^0S=wr6Esx9Z$2|c1?GaupU6$tb| zY_KU`(_29O_%k(;>^|6*pZURH3`@%EuKS;Ns z1lujmf;r{qAN&Q0&m{wJSZ8MeE7RM5+Sq;ul_ z`+ADrd_Um+G37js6tKsArNB}n{p*zTUxQr>3@wA;{EUbjNjlNd6$Mx zg0|MyU)v`sa~tEY5$en7^PkC=S<2@!nEdG6L=h(vT__0F=S8Y&eM=hal#7eM(o^Lu z2?^;05&|CNliYrq6gUv;|i!(W{0N)LWd*@{2q*u)}u*> z7MQgk6t9OqqXMln?zoMAJcc zMKaof_Up})q#DzdF?w^%tTI7STI^@8=Wk#enR*)&%8yje>+tKvUYbW8UAPg55xb70 zEn5&Ba~NmOJlgI#iS8W3-@N%>V!#z-ZRwfPO1)dQdQkaHsiqG|~we2ALqG7Ruup(DqSOft2RFg_X%3w?6VqvV1uzX_@F(diNVp z4{I|}35=11u$;?|JFBEE*gb;T`dy+8gWJ9~pNsecrO`t#V9jW-6mnfO@ff9od}b(3s4>p0i30gbGIv~1@a^F2kl7YO;DxmF3? zWi-RoXhzRJV0&XE@ACc?+@6?)LQ2XNm4KfalMtsc%4!Fn0rl zpHTrHwR>t>7W?t!Yc{*-^xN%9P0cs0kr=`?bQ5T*oOo&VRRu+1chM!qj%2I!@+1XF z4GWJ=7ix9;Wa@xoZ0RP`NCWw0*8247Y4jIZ>GEW7zuoCFXl6xIvz$ezsWgKdVMBH> z{o!A7f;R-@eK9Vj7R40xx)T<2$?F2E<>Jy3F;;=Yt}WE59J!1WN367 zA^6pu_zLoZIf*x031CcwotS{L8bJE(<_F%j_KJ2P_IusaZXwN$&^t716W{M6X2r_~ zaiMwdISX7Y&Qi&Uh0upS3TyEIXNDICQlT5fHXC`aji-c{U(J@qh-mWl-uMN|T&435 z5)a1dvB|oe%b2mefc=Vpm0C%IUYYh7HI*;3UdgNIz}R##(#{(_>82|zB0L*1i4B5j-xi9O4x10rs_J6*gdRBX=@VJ+==sWb&_Qc6tSOowM{BX@(zawtjl zdU!F4OYw2@Tk1L^%~JCwb|e#3CC>srRHQ*(N%!7$Mu_sKh@|*XtR>)BmWw!;8-mq7 zBBnbjwx8Kyv|hd*`5}84flTHR1Y@@uqjG`UG+jN_YK&RYTt7DVwfEDXDW4U+iO{>K zw1hr{_XE*S*K9TzzUlJH2rh^hUm2v7_XjwTuYap|>zeEDY$HOq3X4Tz^X}E9z)x4F zs+T?Ed+Hj<#jY-`Va~fT2C$=qFT-5q$@p9~0{G&eeL~tiIAHXA!f6C(rAlS^)&k<- zXU|ZVs}XQ>s5iONo~t!XXZgtaP$Iau;JT%h)>}v54yut~pykaNye4axEK#5@?TSsQ zE;Jvf9I$GVb|S`7$pG)4vgo9NXsKr?u=F!GnA%VS2z$@Z(!MR9?EPcAqi5ft)Iz6sNl`%kj+_H-X`R<>BFrBW=fSlD|{`D%@Rcbu2?%>t7i34k?Ujb)2@J-`j#4 zLK<69qcUuniIan-$A1+fR=?@+thwDIXtF1Tks@Br-xY zfB+zblrR(ke`U;6U~-;p1Kg8Lh6v~LjW@9l2P6s+?$2!ZRPX`(ZkRGe7~q(4&gEi<$ch`5kQ?*1=GSqkeV z{SA1EaW_A!t{@^UY2D^YO0(H@+kFVzZaAh0_`A`f(}G~EP~?B|%gtxu&g%^x{EYSz zk+T;_c@d;+n@$<>V%P=nk36?L!}?*=vK4>nJSm+1%a}9UlmTJTrfX4{Lb7smNQn@T zw9p2%(Zjl^bWGo1;DuMHN(djsEm)P8mEC2sL@KyPjwD@d%QnZ$ zMJ3cnn!_!iP{MzWk%PI&D?m?C(y2d|2VChluN^yHya(b`h>~GkI1y;}O_E57zOs!{ zt2C@M$^PR2U#(dZmA-sNreB@z-yb0Bf7j*yONhZG=onhx>t4)RB`r6&TP$n zgmN*)eCqvgriBO-abHQ8ECN0bw?z5Bxpx z=jF@?zFdVn?@gD5egM4o$m`}lV(CWrOKKq(sv*`mNcHcvw&Xryfw<{ch{O&qc#WCTXX6=#{MV@q#iHYba!OUY+MGeNTjP%Fj!WgM&`&RlI^=AWTOqy-o zHo9YFt!gQ*p7{Fl86>#-JLZo(b^O`LdFK~OsZBRR@6P?ad^Ujbqm_j^XycM4ZHFyg ziUbIFW#2tj`65~#2V!4z7DM8Z;fG0|APaQ{a2VNYpNotB7eZ5kp+tPDz&Lqs0j%Y4tA*URpcfi z_M(FD=fRGdqf430j}1z`O0I=;tLu81bwJXdYiN7_&a-?ly|-j*+=--XGvCq#32Gh(=|qj5F?kmihk{%M&$}udW5)DHK zF_>}5R8&&API}o0osZJRL3n~>76nUZ&L&iy^s>PMnNcYZ|9*1$v-bzbT3rpWsJ+y{ zPrg>5Zlery96Um?lc6L|)}&{992{_$J&=4%nRp9BAC6!IB=A&=tF>r8S*O-=!G(_( zwXbX_rGZgeiK*&n5E;f=k{ktyA1(;x_kiMEt0*gpp_4&(twlS2e5C?NoD{n>X2AT# zY@Zp?#!b1zNq96MQqeO*M1MMBin5v#RH52&Xd~DO6-BZLnA6xO1$sou(YJ1Dlc{WF zVa%2DyYm`V#81jP@70IJ;DX@y*iUt$MLm)ByAD$eUuji|5{ptFYq(q)mE(5bOpxjM z^Q`AHWq44SG3`_LxC9fwR)XRVIp=B%<(-lOC3jI#bb@dK(*vjom!=t|#<@dZql%>O z15y^{4tQoeW9Lu%G&V$90x6F)xN6y_oIn;!Q zs)8jT$;&;u%Y>=T3hg34A-+Y*na=|glcStr5D;&5*t5*DmD~x;zQAV5{}Ya`?RRGa zT*t9@$a~!co;pD^!J5bo?lDOWFx%)Y=-fJ+PDGc0>;=q=s?P4aHForSB+)v0WY2JH z?*`O;RHum6j%#LG)Vu#ciO#+jRC3!>T(9fr+XE7T2B7Z|0nR5jw@WG)kDDzTJ=o4~ zUpeyt7}_nd`t}j9BKqryOha{34erm)RmST)_9Aw)@ zHbiyg5n&E{_CQR@h<}34d7WM{s{%5wdty1l+KX8*?+-YkNK2Be*6&jc>@{Fd;Ps|| z26LqdI3#9le?;}risDq$K5G3yoqK}C^@-8z^wj%tdgw-6@F#Ju{Sg7+y)L?)U$ez> zoOaP$UFZ?y5BiFycir*pnaAaY+|%1%8&|(@VB)zweR%?IidwJyK5J!STzw&2RFx zZV@qeaCB01Hu#U9|1#=Msc8Pgz5P*4Lrp!Q+~(G!OiNR{qa7|r^H?FC6gVhkk3y7=uW#Sh;&>78bZ}aK*C#NH$9rX@M3f{nckYI+5QG?Aj1DM)@~z_ zw!UAD@gedTlePB*%4+55naJ8ak_;))#S;4ji!LOqY5VRI){GMwHR~}6t4g>5C_#U# ztYC!tjKjrKvRy=GAsJVK++~$|+s!w9z3H4G^mACv=EErXNSmH7qN}%PKcN|8%9=i)qS5+$L zu&ya~HW%RMVJi4T^pv?>mw*Gf<)-7gf#Qj|e#w2|v4#t!%Jk{&xlf;$_?jW*n!Pyx zkG$<18kiLOAUPuFfyu-EfWX%4jYnjBYc~~*9JEz6oa)_R|8wjZA|RNrAp%}14L7fW zi7A5Wym*K+V8pkqqO-X#3ft{0qs?KVt^)?kS>AicmeO&q+~J~ zp0YJ_P~_a8j= zsAs~G=8F=M{4GZL{|B__UorX@MRNQLn?*_gym4aW(~+i13knnk1P=khoC-ViMZk+x zLW(l}oAg1H`dU+Fv**;qw|ANDSRs>cGqL!Yw^`; zv;{E&8CNJcc)GHzTYM}f&NPw<6j{C3gaeelU#y!M)w-utYEHOCCJo|Vgp7K6C_$14 zqIrLUB0bsgz^D%V%fbo2f9#yb#CntTX?55Xy|Kps&Xek*4_r=KDZ z+`TQuv|$l}MWLzA5Ay6Cvsa^7xvwXpy?`w(6vx4XJ zWuf1bVSb#U8{xlY4+wlZ$9jjPk)X_;NFMqdgq>m&W=!KtP+6NL57`AMljW+es zzqjUjgz;V*kktJI?!NOg^s_)ph45>4UDA!Vo0hn>KZ+h-3=?Y3*R=#!fOX zP$Y~+14$f66ix?UWB_6r#fMcC^~X4R-<&OD1CSDNuX~y^YwJ>sW0j`T<2+3F9>cLo z#!j57$ll2K9(%$4>eA7(>FJX5e)pR5&EZK!IMQzOfik#FU*o*LGz~7u(8}XzIQRy- z!U7AlMTIe|DgQFmc%cHy_9^{o`eD%ja_L>ckU6$O4*U**o5uR7`FzqkU8k4gxtI=o z^P^oGFPm5jwZMI{;nH}$?p@uV8FT4r=|#GziKXK07bHJLtK}X%I0TON$uj(iJ`SY^ zc$b2CoxCQ>7LH@nxcdW&_C#fMYBtTxcg46dL{vf%EFCZ~eErMvZq&Z%Lhumnkn^4A zsx$ay(FnN7kYah}tZ@0?-0Niroa~13`?hVi6`ndno`G+E8;$<6^gsE-K3)TxyoJ4M zb6pj5=I8^FD5H@`^V#Qb2^0cx7wUz&cruA5g>6>qR5)O^t1(-qqP&1g=qvY#s&{bx zq8Hc%LsbK1*%n|Y=FfojpE;w~)G0-X4i*K3{o|J7`krhIOd*c*$y{WIKz2n2*EXEH zT{oml3Th5k*vkswuFXdGDlcLj15Nec5pFfZ*0?XHaF_lVuiB%Pv&p7z)%38}%$Gup zVTa~C8=cw%6BKn_|4E?bPNW4PT7}jZQLhDJhvf4z;~L)506IE0 zX!tWXX(QOQPRj-p80QG79t8T2^az4Zp2hOHziQlvT!|H)jv{Ixodabzv6lBj)6WRB z{)Kg@$~~(7$-az?lw$4@L%I&DI0Lo)PEJJziWP33a3azb?jyXt1v0N>2kxwA6b%l> zZqRpAo)Npi&loWbjFWtEV)783BbeIAhqyuc+~>i7aQ8shIXt)bjCWT6$~ro^>99G} z2XfmT0(|l!)XJb^E!#3z4oEGIsL(xd; zYX1`1I(cG|u#4R4T&C|m*9KB1`UzKvho5R@1eYtUL9B72{i(ir&ls8g!pD ztR|25xGaF!4z5M+U@@lQf(12?xGy`!|3E}7pI$k`jOIFjiDr{tqf0va&3pOn6Pu)% z@xtG2zjYuJXrV)DUrIF*y<1O1<$#54kZ#2;=X51J^F#0nZ0(;S$OZDt_U2bx{RZ=Q zMMdd$fH|!s{ zXq#l;{`xfV`gp&C>A`WrQU?d{!Ey5(1u*VLJt>i27aZ-^&2IIk=zP5p+{$q(K?2(b z8?9h)kvj9SF!Dr zoyF}?V|9;6abHxWk2cEvGs$-}Pg}D+ZzgkaN&$Snp%;5m%zh1E#?Wac-}x?BYlGN#U#Mek*}kek#I9XaHt?mz3*fDrRTQ#&#~xyeqJk1QJ~E$7qsw6 z?sV;|?*=-{M<1+hXoj?@-$y+(^BJ1H~wQ9G8C0#^aEAyhDduNX@haoa=PuPp zYsGv8UBfQaRHgBgLjmP^eh>fLMeh{8ic)?xz?#3kX-D#Z{;W#cd_`9OMFIaJg-=t`_3*!YDgtNQ2+QUEAJB9M{~AvT$H`E)IKmCR21H532+ata8_i_MR@ z2Xj<3w<`isF~Ah$W{|9;51ub*f4#9ziKrOR&jM{x7I_7()O@`F*5o$KtZ?fxU~g`t zUovNEVKYn$U~VX8eR)qb`7;D8pn*Pp$(otYTqL)5KH$lUS-jf}PGBjy$weoceAcPp z&5ZYB$r&P$MN{0H0AxCe4Qmd3T%M*5d4i%#!nmBCN-WU-4m4Tjxn-%j3HagwTxCZ9 z)j5vO-C7%s%D!&UfO>bi2oXiCw<-w{vVTK^rVbv#W=WjdADJy8$khnU!`ZWCIU`># zyjc^1W~pcu>@lDZ{zr6gv%)2X4n27~Ve+cQqcND%0?IFSP4sH#yIaXXYAq^z3|cg` z`I3$m%jra>e2W-=DiD@84T!cb%||k)nPmEE09NC%@PS_OLhkrX*U!cgD*;;&gIaA(DyVT4QD+q_xu z>r`tg{hiGY&DvD-)B*h+YEd+Zn)WylQl}<4>(_NlsKXCRV;a)Rcw!wtelM2_rWX`j zTh5A|i6=2BA(iMCnj_fob@*eA;V?oa4Z1kRBGaU07O70fb6-qmA$Hg$ps@^ka1=RO zTbE_2#)1bndC3VuK@e!Sftxq4=Uux}fDxXE#Q5_x=E1h>T5`DPHz zbH<_OjWx$wy7=%0!mo*qH*7N4tySm+R0~(rbus`7;+wGh;C0O%x~fEMkt!eV>U$`i z5>Q(o z=t$gPjgGh0&I7KY#k50V7DJRX<%^X z>6+ebc9efB3@eE2Tr){;?_w`vhgF>`-GDY(YkR{9RH(MiCnyRtd!LxXJ75z+?2 zGi@m^+2hKJ5sB1@Xi@s_@p_Kwbc<*LQ_`mr^Y%j}(sV_$`J(?_FWP)4NW*BIL~sR>t6 zM;qTJZ~GoY36&{h-Pf}L#y2UtR}>ZaI%A6VkU>vG4~}9^i$5WP2Tj?Cc}5oQxe2=q z8BeLa$hwCg_psjZyC2+?yX4*hJ58Wu^w9}}7X*+i5Rjqu5^@GzXiw#SUir1G1`jY% zOL=GE_ENYxhcyUrEt9XlMNP6kx6h&%6^u3@zB8KUCAa18T(R2J`%JjWZ z!{7cXaEW+Qu*iJPu+m>QqW}Lo$4Z+!I)0JNzZ&_M%=|B1yejFRM04bGAvu{=lNPd+ zJRI^DRQ(?FcVUD+bgEcAi@o(msqys9RTCG#)TjI!9~3-dc`>gW;HSJuQvH~d`MQs86R$|SKXHh zqS9Qy)u;T`>>a!$LuaE2keJV%;8g)tr&Nnc;EkvA-RanHXsy)D@XN0a>h}z2j81R; zsUNJf&g&rKpuD0WD@=dDrPHdBoK42WoBU|nMo17o(5^;M|dB4?|FsAGVrSyWcI`+FVw^vTVC`y}f(BwJl zrw3Sp151^9=}B})6@H*i4-dIN_o^br+BkcLa^H56|^2XsT0dESw2 zMX>(KqNl=x2K5=zIKg}2JpGAZu{I_IO}0$EQ5P{4zol**PCt3F4`GX}2@vr8#Y)~J zKb)gJeHcFnR@4SSh%b;c%J`l=W*40UPjF#q{<}ywv-=vHRFmDjv)NtmC zQx9qm)d%0zH&qG7AFa3VAU1S^(n8VFTC~Hb+HjYMjX8r#&_0MzlNR*mnLH5hi}`@{ zK$8qiDDvS_(L9_2vHgzEQ${DYSE;DqB!g*jhJghE&=LTnbgl&Xepo<*uRtV{2wDHN z)l;Kg$TA>Y|K8Lc&LjWGj<+bp4Hiye_@BfU(y#nF{fpR&|Ltbye?e^j0}8JC4#xi% zv29ZR%8%hk=3ZDvO-@1u8KmQ@6p%E|dlHuy#H1&MiC<*$YdLkHmR#F3ae;bKd;@*i z2_VfELG=B}JMLCO-6UQy^>RDE%K4b>c%9ki`f~Z2Qu8hO7C#t%Aeg8E%+}6P7Twtg z-)dj(w}_zFK&86KR@q9MHicUAucLVshUdmz_2@32(V`y3`&Kf8Q2I)+!n0mR=rrDU zXvv^$ho;yh*kNqJ#r1}b0|i|xRUF6;lhx$M*uG3SNLUTC@|htC z-=fsw^F%$qqz4%QdjBrS+ov}Qv!z00E+JWas>p?z@=t!WWU3K*?Z(0meTuTOC7OTx zU|kFLE0bLZ+WGcL$u4E}5dB0g`h|uwv3=H6f+{5z9oLv-=Q45+n~V4WwgO=CabjM% zBAN+RjM65(-}>Q2V#i1Na@a0`08g&y;W#@sBiX6Tpy8r}*+{RnyGUT`?XeHSqo#|J z^ww~c;ou|iyzpErDtlVU=`8N7JSu>4M z_pr9=tX0edVn9B}YFO2y(88j#S{w%E8vVOpAboK*27a7e4Ekjt0)hIX99*1oE;vex z7#%jhY=bPijA=Ce@9rRO(Vl_vnd00!^TAc<+wVvRM9{;hP*rqEL_(RzfK$er_^SN; z)1a8vo8~Dr5?;0X0J62Cusw$A*c^Sx1)dom`-)Pl7hsW4i(r*^Mw`z5K>!2ixB_mu z*Ddqjh}zceRFdmuX1akM1$3>G=#~|y?eYv(e-`Qy?bRHIq=fMaN~fB zUa6I8Rt=)jnplP>yuS+P&PxeWpJ#1$F`iqRl|jF$WL_aZFZl@kLo&d$VJtu&w?Q0O zzuXK>6gmygq(yXJy0C1SL}T8AplK|AGNUOhzlGeK_oo|haD@)5PxF}rV+5`-w{Aag zus45t=FU*{LguJ11Sr-28EZkq;!mJO7AQGih1L4rEyUmp>B!%X0YemsrV3QFvlgt* z5kwlPzaiJ+kZ^PMd-RRbl(Y?F*m`4*UIhIuf#8q>H_M=fM*L_Op-<_r zBZagV=4B|EW+KTja?srADTZXCd3Yv%^Chfpi)cg{ED${SI>InNpRj5!euKv?=Xn92 zsS&FH(*w`qLIy$doc>RE&A5R?u zzkl1sxX|{*fLpXvIW>9d<$ePROttn3oc6R!sN{&Y+>Jr@yeQN$sFR z;w6A<2-0%UA?c8Qf;sX7>>uKRBv3Ni)E9pI{uVzX|6Bb0U)`lhLE3hK58ivfRs1}d zNjlGK0hdq0qjV@q1qI%ZFMLgcpWSY~mB^LK)4GZ^h_@H+3?dAe_a~k*;9P_d7%NEFP6+ zgV(oGr*?W(ql?6SQ~`lUsjLb%MbfC4V$)1E0Y_b|OIYxz4?O|!kRb?BGrgiH5+(>s zoqM}v*;OBfg-D1l`M6T6{K`LG+0dJ1)!??G5g(2*vlNkm%Q(MPABT$r13q?|+kL4- zf)Mi5r$sn;u41aK(K#!m+goyd$c!KPl~-&-({j#D4^7hQkV3W|&>l_b!}!z?4($OA z5IrkfuT#F&S1(`?modY&I40%gtroig{YMvF{K{>5u^I51k8RriGd${z)=5k2tG zM|&Bp5kDTfb#vfuTTd?)a=>bX=lokw^y9+2LS?kwHQIWI~pYgy7 zb?A-RKVm_vM5!9?C%qYdfRAw& zAU7`up~%g=p@}pg#b7E)BFYx3g%(J36Nw(Dij!b>cMl@CSNbrW!DBDbTD4OXk!G4x zi}JBKc8HBYx$J~31PXH+4^x|UxK~(<@I;^3pWN$E=sYma@JP|8YL`L(zI6Y#c%Q{6 z*APf`DU$S4pr#_!60BH$FGViP14iJmbrzSrOkR;f3YZa{#E7Wpd@^4E-zH8EgPc-# zKWFPvh%WbqU_%ZEt`=Q?odKHc7@SUmY{GK`?40VuL~o)bS|is$Hn=<=KGHOsEC5tB zFb|q}gGlL97NUf$G$>^1b^3E18PZ~Pm9kX%*ftnolljiEt@2#F2R5ah$zbXd%V_Ev zyDd{1o_uuoBga$fB@Fw!V5F3jIr=a-ykqrK?WWZ#a(bglI_-8pq74RK*KfQ z0~Dzus7_l;pMJYf>Bk`)`S8gF!To-BdMnVw5M-pyu+aCiC5dwNH|6fgRsIKZcF&)g zr}1|?VOp}I3)IR@m1&HX1~#wsS!4iYqES zK}4J{Ei>;e3>LB#Oly>EZkW14^@YmpbgxCDi#0RgdM${&wxR+LiX}B+iRioOB0(pDKpVEI;ND?wNx>%e|m{RsqR_{(nmQ z3ZS}@t!p4a(BKx_-CYwrcyJ5u1TO9bcXti$8sy>xcLKqKCc#~UOZYD{llKTSFEjJ~ zyNWt>tLU}*>^`TvPxtP%F`ZJQw@W0^>x;!^@?k_)9#bF$j0)S3;mH-IR5y82l|%=F z2lR8zhP?XNP-ucZZ6A+o$xOyF!w;RaLHGh57GZ|TCXhJqY~GCh)aXEV$1O&$c}La1 zjuJxkY9SM4av^Hb;i7efiYaMwI%jGy`3NdY)+mcJhF(3XEiSlU3c|jMBi|;m-c?~T z+x0_@;SxcoY=(6xNgO$bBt~Pj8`-<1S|;Bsjrzw3@zSjt^JC3X3*$HI79i~!$RmTz zsblZsLYs7L$|=1CB$8qS!tXrWs!F@BVuh?kN(PvE5Av-*r^iYu+L^j^m9JG^#=m>@ z=1soa)H*w6KzoR$B8mBCXoU;f5^bVuwQ3~2LKg!yxomG1#XPmn(?YH@E~_ED+W6mxs%x{%Z<$pW`~ON1~2XjP5v(0{C{+6Dm$00tsd3w=f=ZENy zOgb-=f}|Hb*LQ$YdWg<(u7x3`PKF)B7ZfZ6;1FrNM63 z?O6tE%EiU@6%rVuwIQjvGtOofZBGZT1Sh(xLIYt9c4VI8`!=UJd2BfLjdRI#SbVAX ziT(f*RI^T!IL5Ac>ql7uduF#nuCRJ1)2bdvAyMxp-5^Ww5p#X{rb5)(X|fEhDHHW{ zw(Lfc$g;+Q`B0AiPGtmK%*aWfQQ$d!*U<|-@n2HZvCWSiw^I>#vh+LyC;aaVWGbmkENr z&kl*8o^_FW$T?rDYLO1Pyi%>@&kJKQoH2E0F`HjcN}Zlnx1ddoDA>G4Xu_jyp6vuT zPvC}pT&Owx+qB`zUeR|4G;OH(<<^_bzkjln0k40t`PQxc$7h(T8Ya~X+9gDc8Z9{Z z&y0RAU}#_kQGrM;__MK9vwIwK^aoqFhk~dK!ARf1zJqHMxF2?7-8|~yoO@_~Ed;_wvT%Vs{9RK$6uUQ|&@#6vyBsFK9eZW1Ft#D2)VpQRwpR(;x^ zdoTgMqfF9iBl%{`QDv7B0~8{8`8k`C4@cbZAXBu00v#kYl!#_Wug{)2PwD5cNp?K^ z9+|d-4z|gZ!L{57>!Ogfbzchm>J1)Y%?NThxIS8frAw@z>Zb9v%3_3~F@<=LG%r*U zaTov}{{^z~SeX!qgSYow`_5)ij*QtGp4lvF`aIGQ>@3ZTkDmsl#@^5*NGjOuu82}o zzLF~Q9SW+mP=>88%eSA1W4_W7-Q>rdq^?t=m6}^tDPaBRGFLg%ak93W!kOp#EO{6& zP%}Iff5HZQ9VW$~+9r=|Quj#z*=YwcnssS~9|ub2>v|u1JXP47vZ1&L1O%Z1DsOrDfSIMHU{VT>&>H=9}G3i@2rP+rx@eU@uE8rJNec zij~#FmuEBj03F1~ct@C@$>y)zB+tVyjV3*n`mtAhIM0$58vM9jOQC}JJOem|EpwqeMuYPxu3sv}oMS?S#o6GGK@8PN59)m&K4Dc&X% z(;XL_kKeYkafzS3Wn5DD>Yiw{LACy_#jY4op(>9q>>-*9@C0M+=b#bknAWZ37^(Ij zq>H%<@>o4a#6NydoF{_M4i4zB_KG)#PSye9bk0Ou8h%1Dtl7Q_y#7*n%g)?m>xF~( zjqvOwC;*qvN_3(*a+w2|ao0D?@okOvg8JskUw(l7n`0fncglavwKd?~l_ryKJ^Ky! zKCHkIC-o7%fFvPa$)YNh022lakMar^dgL=t#@XLyNHHw!b?%WlM)R@^!)I!smZL@k zBi=6wE5)2v&!UNV(&)oOYW(6Qa!nUjDKKBf-~Da=#^HE4(@mWk)LPvhyN3i4goB$3K8iV7uh zsv+a?#c4&NWeK(3AH;ETrMOIFgu{_@%XRwCZ;L=^8Ts)hix4Pf3yJRQ<8xb^CkdmC z?c_gB)XmRsk`9ch#tx4*hO=#qS7={~Vb4*tTf<5P%*-XMfUUYkI9T1cEF;ObfxxI-yNuA=I$dCtz3ey znVkctYD*`fUuZ(57+^B*R=Q}~{1z#2!ca?)+YsRQb+lt^LmEvZt_`=j^wqig+wz@n@ z`LIMQJT3bxMzuKg8EGBU+Q-6cs5(@5W?N>JpZL{$9VF)veF`L5%DSYTNQEypW%6$u zm_~}T{HeHj1bAlKl8ii92l9~$dm=UM21kLemA&b$;^!wB7#IKWGnF$TVq!!lBlG4 z{?Rjz?P(uvid+|i$VH?`-C&Gcb3{(~Vpg`w+O);Wk1|Mrjxrht0GfRUnZqz2MhrXa zqgVC9nemD5)H$to=~hp)c=l9?#~Z_7i~=U-`FZxb-|TR9@YCxx;Zjo-WpMNOn2)z) zFPGGVl%3N$f`gp$gPnWC+f4(rmts%fidpo^BJx72zAd7|*Xi{2VXmbOm)1`w^tm9% znM=0Fg4bDxH5PxPEm{P3#A(mxqlM7SIARP?|2&+c7qmU8kP&iApzL|F>Dz)Ixp_`O zP%xrP1M6@oYhgo$ZWwrAsYLa4 z|I;DAvJxno9HkQrhLPQk-8}=De{9U3U%)dJ$955?_AOms!9gia%)0E$Mp}$+0er@< zq7J&_SzvShM?e%V?_zUu{niL@gt5UFOjFJUJ}L?$f%eU%jUSoujr{^O=?=^{19`ON zlRIy8Uo_nqcPa6@yyz`CM?pMJ^^SN^Fqtt`GQ8Q#W4kE7`V9^LT}j#pMChl!j#g#J zr-=CCaV%xyFeQ9SK+mG(cTwW*)xa(eK;_Z(jy)woZp~> zA(4}-&VH+TEeLzPTqw&FOoK(ZjD~m{KW05fiGLe@E3Z2`rLukIDahE*`u!ubU)9`o zn^-lyht#E#-dt~S>}4y$-mSbR8{T@}22cn^refuQ08NjLOv?JiEWjyOnzk<^R5%gO zhUH_B{oz~u#IYwVnUg8?3P*#DqD8#X;%q%HY**=I>>-S|!X*-!x1{^l#OnR56O>iD zc;i;KS+t$koh)E3)w0OjWJl_aW2;xF=9D9Kr>)(5}4FqUbk# zI#$N8o0w;IChL49m9CJTzoC!|u{Ljd%ECgBOf$}&jA^$(V#P#~)`&g`H8E{uv52pp zwto`xUL-L&WTAVREEm$0g_gYPL(^vHq(*t1WCH_6alhkeW&GCZ3hL)|{O-jiFOBrF z!EW=Jej|dqQitT6!B-7&io2K)WIm~Q)v@yq%U|VpV+I?{y0@Yd%n8~-NuuM*pM~KA z85YB};IS~M(c<}4Hxx>qRK0cdl&e?t253N%vefkgds>Ubn8X}j6Vpgs>a#nFq$osY z1ZRwLqFv=+BTb=i%D2Wv>_yE0z}+niZ4?rE|*a3d7^kndWGwnFqt+iZ(7+aln<}jzbAQ(#Z2SS}3S$%Bd}^ zc9ghB%O)Z_mTZMRC&H#)I#fiLuIkGa^`4e~9oM5zKPx?zjkC&Xy0~r{;S?FS%c7w< zWbMpzc(xSw?9tGxG~_l}Acq}zjt5ClaB7-!vzqnlrX;}$#+PyQ9oU)_DfePh2E1<7 ztok6g6K^k^DuHR*iJ?jw?bs_whk|bx`dxu^nC6#e{1*m~z1eq7m}Cf$*^Eua(oi_I zAL+3opNhJteu&mWQ@kQWPucmiP)4|nFG`b2tpC;h{-PI@`+h?9v=9mn|0R-n8#t=+Z*FD(c5 zjj79Jxkgck*DV=wpFgRZuwr%}KTm+dx?RT@aUHJdaX-ODh~gByS?WGx&czAkvkg;x zrf92l8$Or_zOwJVwh>5rB`Q5_5}ef6DjS*$x30nZbuO3dijS*wvNEqTY5p1_A0gWr znH<(Qvb!os14|R)n2Ost>jS2;d1zyLHu`Svm|&dZD+PpP{Bh>U&`Md;gRl64q;>{8MJJM$?UNUd`aC>BiLe>*{ zJY15->yW+<3rLgYeTruFDtk1ovU<$(_y7#HgUq>)r0{^}Xbth}V#6?%5jeFYt;SG^ z3qF)=uWRU;Jj)Q}cpY8-H+l_n$2$6{ZR?&*IGr{>ek!69ZH0ZoJ*Ji+ezzlJ^%qL3 zO5a`6gwFw(moEzqxh=yJ9M1FTn!eo&qD#y5AZXErHs%22?A+JmS&GIolml!)rZTnUDM3YgzYfT#;OXn)`PWv3Ta z!-i|-Wojv*k&bC}_JJDjiAK(Ba|YZgUI{f}TdEOFT2+}nPmttytw7j%@bQZDV1vvj z^rp{gRkCDmYJHGrE1~e~AE!-&6B6`7UxVQuvRrfdFkGX8H~SNP_X4EodVd;lXd^>eV1jN+Tt4}Rsn)R0LxBz0c=NXU|pUe!MQQFkGBWbR3&(jLm z%RSLc#p}5_dO{GD=DEFr=Fc% z85CBF>*t!6ugI?soX(*JNxBp+-DdZ4X0LldiK}+WWGvXV(C(Ht|!3$psR=&c*HIM=BmX;pRIpz@Ale{9dhGe(U2|Giv;# zOc|;?p67J=Q(kamB*aus=|XP|m{jN^6@V*Bpm?ye56Njh#vyJqE=DweC;?Rv7faX~ zde03n^I~0B2vUmr;w^X37tVxUK?4}ifsSH5_kpKZIzpYu0;Kv}SBGfI2AKNp+VN#z`nI{UNDRbo-wqa4NEls zICRJpu)??cj^*WcZ^MAv+;bDbh~gpN$1Cor<{Y2oyIDws^JsfW^5AL$azE(T0p&pP z1Mv~6Q44R&RHoH95&OuGx2srIr<@zYJTOMKiVs;Bx3py89I87LOb@%mr`0)#;7_~Z zzcZj8?w=)>%5@HoCHE_&hnu(n_yQ-L(~VjpjjkbT7e)Dk5??fApg(d>vwLRJ-x{um z*Nt?DqTSxh_MIyogY!vf1mU1`Gld-&L)*43f6dilz`Q@HEz;+>MDDYv9u!s;WXeao zUq=TaL$P*IFgJzrGc>j1dDOd zed+=ZBo?w4mr$2)Ya}?vedDopomhW1`#P<%YOJ_j=WwClX0xJH-f@s?^tmzs_j7t!k zK@j^zS0Q|mM4tVP5Ram$VbS6|YDY&y?Q1r1joe9dj08#CM{RSMTU}(RCh`hp_Rkl- zGd|Cv~G@F{DLhCizAm9AN!^{rNs8hu!G@8RpnGx7e`-+K$ffN<0qjR zGq^$dj_Tv!n*?zOSyk5skI7JVKJ)3jysnjIu-@VSzQiP8r6MzudCU=~?v-U8yzo^7 zGf~SUTvEp+S*!X9uX!sq=o}lH;r{pzk~M*VA(uyQ`3C8!{C;)&6)95fv(cK!%Cuz$ z_Zal57H6kPN>25KNiI6z6F)jzEkh#%OqU#-__Xzy)KyH};81#N6OfX$$IXWzOn`Q& z4f$Z1t>)8&8PcYfEwY5UadU1yg+U*(1m2ZlHoC-!2?gB!!fLhmTl))D@dhvkx#+Yj z1O=LV{(T%{^IeCuFK>%QR!VZ4GnO5tK8a+thWE zg4VytZrwcS?7^ zuZfhYnB8dwd%VLO?DK7pV5Wi<(`~DYqOXn8#jUIL^)12*Dbhk4GmL_E2`WX&iT16o zk(t|hok(Y|v-wzn?4x34T)|+SfZP>fiq!><*%vnxGN~ypST-FtC+@TPv*vYv@iU!_ z@2gf|PrgQ?Ktf*9^CnJ(x*CtZVB8!OBfg0%!wL;Z8(tYYre0vcnPGlyCc$V(Ipl*P z_(J!a=o@vp^%Efme!K74(Ke7A>Y}|sxV+JL^aYa{~m%5#$$+R1? zGaQhZTTX!#s#=Xtpegqero$RNt&`4xn3g$)=y*;=N=Qai)}~`xtxI_N*#MMCIq#HFifT zz(-*m;pVH&+4bixL&Bbg)W5FN^bH87pAHp)zPkWNMfTFqS=l~AC$3FX3kQUSh_C?-ZftyClgM)o_D7cX$RGlEYblux0jv5 zTr|i-I3@ZPCGheCl~BGhImF)K4!9@?pC(gi3ozX=a!|r1)LFxy_8c&wY0<^{2cm|P zv6Y`QktY*;I)IUd5y3ne1CqpVanlY45z8hf4&$EUBnucDj16pDa4&GI&TArYhf*xh zdj>*%APH8(h~c>o@l#%T>R$e>rwVx_WUB|~V`p^JHsg*y12lzj&zF}w6W09HwB2yb z%Q~`es&(;7#*DUC_w-Dmt7|$*?TA_m;zB+-u{2;Bg{O}nV7G_@7~<)Bv8fH^G$XG8$(&{A zwXJK5LRK%M34(t$&NI~MHT{UQ9qN-V_yn|%PqC81EIiSzmMM=2zb`mIwiP_b)x+2M z7Gd`83h79j#SItpQ}luuf2uOU`my_rY5T{6P#BNlb%h%<#MZb=m@y5aW;#o1^2Z)SWo+b`y0gV^iRcZtz5!-05vF z7wNo=hc6h4hc&s@uL^jqRvD6thVYtbErDK9k!;+a0xoE0WL7zLixjn5;$fXvT=O3I zT6jI&^A7k6R{&5#lVjz#8%_RiAa2{di{`kx79K+j72$H(!ass|B%@l%KeeKchYLe_ z>!(JC2fxsv>XVen+Y42GeYPxMWqm`6F$(E<6^s|g(slNk!lL*6v^W2>f6hh^mE$s= z3D$)}{V5(Qm&A6bp%2Q}*GZ5Qrf}n7*Hr51?bJOyA-?B4vg6y_EX<*-e20h{=0Mxs zbuQGZ$fLyO5v$nQ&^kuH+mNq9O#MWSfThtH|0q1i!NrWj^S}_P;Q1OkYLW6U^?_7G zx2wg?CULj7))QU(n{$0JE%1t2dWrMi2g-Os{v|8^wK{@qlj%+1b^?NI z$}l2tjp0g>K3O+p%yK<9!XqmQ?E9>z&(|^Pi~aSRwI5x$jaA62GFz9%fmO3t3a>cq zK8Xbv=5Ps~4mKN5+Eqw12(!PEyedFXv~VLxMB~HwT1Vfo51pQ#D8e$e4pFZ{&RC2P z5gTIzl{3!&(tor^BwZfR8j4k{7Rq#`riKXP2O-Bh66#WWK2w=z;iD9GLl+3 zpHIaI4#lQ&S-xBK8PiQ%dwOh?%BO~DCo06pN7<^dnZCN@NzY{_Z1>rrB0U|nC&+!2 z2y!oBcTd2;@lzyk(B=TkyZ)zy0deK05*Q0zk+o$@nun`VI1Er7pjq>8V zNmlW{p7S^Btgb(TA}jL(uR>`0w8gHP^T~Sh5Tkip^spk4SBAhC{TZU}_Z)UJw-}zm zPq{KBm!k)?P{`-(9?LFt&YN4s%SIZ-9lJ!Ws~B%exHOeVFk3~}HewnnH(d)qkLQ_d z6h>O)pEE{vbOVw}E+jdYC^wM+AAhaI(YAibUc@B#_mDss0Ji&BK{WG`4 zOk>vSNq(Bq2IB@s>>Rxm6Wv?h;ZXkpb1l8u|+_qXWdC*jjcPCixq;!%BVPSp#hP zqo`%cNf&YoQXHC$D=D45RiT|5ngPlh?0T~?lUf*O)){K@*Kbh?3RW1j9-T?%lDk@y z4+~?wKI%Y!-=O|_IuKz|=)F;V7ps=5@g)RrE;;tvM$gUhG>jHcw2Hr@fS+k^Zr~>G z^JvPrZc}_&d_kEsqAEMTMJw!!CBw)u&ZVzmq+ZworuaE&TT>$pYsd9|g9O^0orAe8 z221?Va!l1|Y5X1Y?{G7rt1sX#qFA^?RLG^VjoxPf63;AS=_mVDfGJKg73L zsGdnTUD40y(>S##2l|W2Cy!H(@@5KBa(#gs`vlz}Y~$ot5VsqPQ{{YtjYFvIumZzt zA{CcxZLJR|4#{j7k~Tu*jkwz8QA|5G1$Cl895R`Zyp;irp1{KN){kB30O8P1W5;@bG znvX74roeMmQlUi=v9Y%(wl$ZC#9tKNFpvi3!C}f1m6Ct|l2g%psc{TJp)@yu)*e2> z((p0Fg*8gJ!|3WZke9;Z{8}&NRkv7iP=#_y-F}x^y?2m%-D_aj^)f04%mneyjo_;) z6qc_Zu$q37d~X``*eP~Q>I2gg%rrV8v=kDfpp$=%Vj}hF)^dsSWygoN(A$g*E=Do6FX?&(@F#7pbiJ`;c0c@Ul zDqW_90Wm#5f2L<(Lf3)3TeXtI7nhYwRm(F;*r_G6K@OPW4H(Y3O5SjUzBC}u3d|eQ8*8d@?;zUPE+i#QNMn=r(ap?2SH@vo*m z3HJ%XuG_S6;QbWy-l%qU;8x;>z>4pMW7>R}J%QLf%@1BY(4f_1iixd-6GlO7Vp*yU zp{VU^3?s?90i=!#>H`lxT!q8rk>W_$2~kbpz7eV{3wR|8E=8**5?qn8#n`*(bt1xRQrdGxyx2y%B$qmw#>ZV$c7%cO#%JM1lY$Y0q?Yuo> ze9KdJoiM)RH*SB%^;TAdX-zEjA7@%y=!0=Zg%iWK7jVI9b&Dk}0$Af&08KHo+ zOwDhFvA(E|ER%a^cdh@^wLUlmIv6?_3=BvX8jKk92L=Y}7Jf5OGMfh` zBdR1wFCi-i5@`9km{isRb0O%TX+f~)KNaEz{rXQa89`YIF;EN&gN)cigu6mNh>?Cm zAO&Im2flv6D{jwm+y<%WsPe4!89n~KN|7}Cb{Z;XweER73r}Qp2 zz}WP4j}U0&(uD&9yGy6`!+_v-S(yG*iytsTR#x_Rc>=6u^vnRDnf1gP{#2>`ffrAC% zTZ5WQ@hAK;P;>kX{D)mIXe4%a5p=LO1xXH@8T?mz7Q@d)$3pL{{B!2{-v70L*o1AO+|n5beiw~ zk@(>m?T3{2k2c;NWc^`4@P&Z?BjxXJ@;x1qhn)9Mn*IFdt_J-dIqx5#d`NfyfX~m( zIS~5)MfZ2Uy?_4W`47i}u0ZgPh<{D|w_d#;D}Q&U$Q-G}xM1A@1f{#%A$jh6Qp&0hQ<0bPOM z-{1Wm&p%%#eb_?x7i;bol EfAhh=DF6Tf diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index abd303b673..d58dfb70ba 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,2 +1,19 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/mvnw b/mvnw index 41c0f0c23d..19529ddf8c 100755 --- a/mvnw +++ b/mvnw @@ -19,292 +19,241 @@ # ---------------------------------------------------------------------------- # ---------------------------------------------------------------------------- -# Maven Start Up Batch script -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir +# Apache Maven Wrapper startup batch script, version 3.3.2 # # Optional ENV vars # ----------------- -# M2_HOME - location of maven2's installed home dir -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output # ---------------------------------------------------------------------------- -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac -fi +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - export JAVA_HOME="`/usr/libexec/java_home`" - else - export JAVA_HOME="/Library/Java/Home" + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 fi fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi fi -fi - -if [ -z "$M2_HOME" ] ; then - ## resolve links - $0 may be a link to maven's home - PRG="$0" +} - # need this for relative symlinks - while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG="`dirname "$PRG"`/$link" - fi +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" done + printf %x\\n $h +} - saveddir=`pwd` +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - M2_HOME=`dirname "$PRG"`/.. +die() { + printf %s\\n "$1" >&2 + exit 1 +} - # make it fully qualified - M2_HOME=`cd "$M2_HOME" && pwd` +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} - cd "$saveddir" - # echo Using m2 at $M2_HOME -fi +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --unix "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$M2_HOME" ] && - M2_HOME="`(cd "$M2_HOME"; pwd)`" - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" fi -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`which java`" - fi +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" fi -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" fi -CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true fi - # end of workaround - done - echo "${basedir}" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 fi -} - -BASE_DIR=`find_maven_basedir "$(pwd)"` -if [ -z "$BASE_DIR" ]; then - exit 1; fi -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - else - jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) jarUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $jarUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget "$jarUrl" -O "$wrapperJarPath" - else - wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl -o "$wrapperJarPath" "$jarUrl" -f - else - curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f - fi - - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaClass" ]; then - if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaClass") - fi - if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" fi -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$M2_HOME" ] && - M2_HOME=`cygpath --path --windows "$M2_HOME"` - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" -exec "$JAVACMD" \ - $MAVEN_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd index 86115719e5..249bdf3822 100644 --- a/mvnw.cmd +++ b/mvnw.cmd @@ -1,3 +1,4 @@ +<# : batch portion @REM ---------------------------------------------------------------------------- @REM Licensed to the Apache Software Foundation (ASF) under one @REM or more contributor license agreements. See the NOTICE file @@ -18,165 +19,131 @@ @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- -@REM Maven Start Up Batch script -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir +@REM Apache Maven Wrapper startup batch script, version 3.3.2 @REM @REM Optional ENV vars -@REM M2_HOME - location of maven2's installed home dir -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output @REM ---------------------------------------------------------------------------- -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" -if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - -FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %DOWNLOAD_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) ) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" -if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%" == "on" pause - -if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% - -exit /B %ERROR_CODE% +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" From 57d4f88a48f6dc95f02ecbd9d19b6c396be2444f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 20 Jan 2025 07:56:19 +0100 Subject: [PATCH 0884/1006] Java EA GitHub Actions improvements (#3803) * Use Java 17 for building MapStruct (still Java 8 compatible) * Upgrade to Spring 6 for tests * Adjust excludes and min tests version for some integration tests --- .github/workflows/java-ea.yml | 6 +-- .github/workflows/main.yml | 43 ++++++++----------- .github/workflows/release.yml | 2 +- ...eatureCompilationExclusionCliEnhancer.java | 3 ++ .../itest/tests/MavenIntegrationTest.java | 8 ++++ .../ProcessorInvocationInterceptor.java | 10 ++++- .../test/resources/fullFeatureTest/pom.xml | 10 +++++ .../superTypeGenerationTest/generator/pom.xml | 1 - .../superTypeGenerationTest/usage/pom.xml | 1 - .../generator/pom.xml | 1 - .../targetTypeGenerationTest/usage/pom.xml | 1 - parent/pom.xml | 6 +-- processor/pom.xml | 2 +- .../_1395/{ => spring}/Issue1395Mapper.java | 2 +- .../_1395/{ => spring}/Issue1395Test.java | 2 +- .../_1395/{ => spring}/NotUsedService.java | 2 +- .../test/bugs/_1395/{ => spring}/Source.java | 2 +- .../test/bugs/_1395/{ => spring}/Target.java | 2 +- .../_2807/{ => spring}/Issue2807Test.java | 8 ++-- .../{ => spring}/SpringLifeCycleMapper.java | 8 ++-- .../_2807/{ => spring}/after/AfterMethod.java | 2 +- .../{ => spring}/before/BeforeMethod.java | 2 +- .../beforewithtarget/BeforeWithTarget.java | 2 +- .../test/bugs/_880/{ => spring}/Config.java | 2 +- .../DefaultsToProcessorOptionsMapper.java | 2 +- .../bugs/_880/{ => spring}/Issue880Test.java | 2 +- .../test/bugs/_880/{ => spring}/Poodle.java | 2 +- .../UsesConfigFromAnnotationMapper.java | 2 +- .../decorator/jsr330/Jsr330DecoratorTest.java | 3 ++ ...30DefaultCompileOptionFieldMapperTest.java | 3 ++ ...330CompileOptionConstructorMapperTest.java | 3 ++ .../Jsr330ConstructorMapperTest.java | 3 ++ .../jsr330/field/Jsr330FieldMapperTest.java | 3 ++ .../jsr330/setter/Jsr330SetterMapperTest.java | 3 ++ .../org/mapstruct/ap/testutil/WithSpring.java | 3 ++ readme.md | 2 +- 36 files changed, 96 insertions(+), 63 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/{ => spring}/Issue1395Mapper.java (91%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/{ => spring}/Issue1395Test.java (92%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/{ => spring}/NotUsedService.java (81%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/{ => spring}/Source.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/{ => spring}/Target.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/{ => spring}/Issue2807Test.java (69%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/{ => spring}/SpringLifeCycleMapper.java (70%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/{ => spring}/after/AfterMethod.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/{ => spring}/before/BeforeMethod.java (87%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/{ => spring}/beforewithtarget/BeforeWithTarget.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_880/{ => spring}/Config.java (87%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_880/{ => spring}/DefaultsToProcessorOptionsMapper.java (86%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_880/{ => spring}/Issue880Test.java (97%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_880/{ => spring}/Poodle.java (88%) rename processor/src/test/java/org/mapstruct/ap/test/bugs/_880/{ => spring}/UsesConfigFromAnnotationMapper.java (90%) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index d9b018bfb8..fce2dc06b2 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -7,11 +7,7 @@ env: jobs: test_jdk_ea: - strategy: - fail-fast: false - matrix: - java: [19-ea] - name: 'Linux JDK ${{ matrix.java }}' + name: 'Linux JDK EA' runs-on: ubuntu-latest steps: - name: 'Checkout' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b27dfc075a..9cc098161d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,45 +24,38 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true - linux: - name: 'Linux JDK 11' - runs-on: ubuntu-latest - steps: - - name: 'Checkout' - uses: actions/checkout@v3 - - name: 'Set up JDK 11' - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 11 - - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} install + run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=${{ matrix.java != 17 }} install -DskipDistribution=${{ matrix.java != 17 }} - name: 'Generate coverage report' + if: matrix.java == 17 run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' + if: matrix.java == 17 uses: codecov/codecov-action@v2 - name: 'Publish Snapshots' - if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' + if: matrix.java == 17 && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy - linux-jdk-8: - name: 'Linux JDK 8' + integration_test_jdk: + strategy: + fail-fast: false + matrix: + java: [ 8, 11 ] + name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: - name: 'Checkout' uses: actions/checkout@v3 - - name: 'Set up JDK 11 for building everything' + - name: 'Set up JDK 17 for building everything' uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: 'Install Processor' run: ./mvnw ${MAVEN_ARGS} -DskipTests install -pl processor -am - - name: 'Set up JDK 8 for running integration tests' + - name: 'Set up JDK ${{ matrix.java }} for running integration tests' uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 8 + java-version: ${{ matrix.java }} - name: 'Run integration tests' run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest windows: @@ -70,11 +63,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v3 - - name: 'Set up JDK 11' + - name: 'Set up JDK 17' uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: 'Test' run: ./mvnw %MAVEN_ARGS% install mac: @@ -82,10 +75,10 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v3 - - name: 'Set up JDK 11' + - name: 'Set up JDK 17' uses: actions/setup-java@v3 with: distribution: 'zulu' - java-version: 11 + java-version: 17 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f18a12b813..682fa36876 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v4 with: - java-version: 11 + java-version: 17 distribution: 'zulu' cache: maven diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index 15d9e42598..77a5e2af06 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -30,6 +30,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces switch ( currentJreVersion ) { case JAVA_8: + additionalExcludes.add( "org/mapstruct/ap/test/**/spring/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/annotatewith/deprecated/jdk11/*.java" ); @@ -42,6 +43,8 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces // TODO find out why this fails: additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); break; + case JAVA_11: + additionalExcludes.add( "org/mapstruct/ap/test/**/spring/**/*.java" ); default: } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 0bef2994f6..ab43cc4cba 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -5,6 +5,7 @@ */ package org.mapstruct.itest.tests; +import org.junit.jupiter.api.condition.DisabledOnJre; import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.parallel.Execution; @@ -80,12 +81,15 @@ void jakartaJaxbTest() { } @ProcessorTest(baseDir = "jsr330Test") + @EnabledForJreRange(min = JRE.JAVA_17) + @DisabledOnJre(JRE.OTHER) void jsr330Test() { } @ProcessorTest(baseDir = "lombokBuilderTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }) + @DisabledOnJre(JRE.OTHER) void lombokBuilderTest() { } @@ -94,6 +98,7 @@ void lombokBuilderTest() { ProcessorTest.ProcessorType.JAVAC_WITH_PATHS }) @EnabledForJreRange(min = JRE.JAVA_11) + @DisabledOnJre(JRE.OTHER) void lombokModuleTest() { } @@ -150,6 +155,7 @@ void expressionTextBlocksTest() { }, forkJvm = true) // We have to fork the jvm because there is an NPE in com.intellij.openapi.util.SystemInfo.getRtVersion // and the kotlin-maven-plugin uses that. See also https://youtrack.jetbrains.com/issue/IDEA-238907 + @DisabledOnJre(JRE.OTHER) void kotlinDataTest() { } @@ -163,6 +169,8 @@ void defaultPackageTest() { } @ProcessorTest(baseDir = "springTest") + @EnabledForJreRange(min = JRE.JAVA_17) + @DisabledOnJre(JRE.OTHER) void springTest() { } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 89009aaffe..85ce64952f 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -134,14 +134,20 @@ private void addAdditionalCliArguments(Verifier verifier) } private void configureProcessor(Verifier verifier) { - String compilerId = processorTestContext.getProcessor().getCompilerId(); + ProcessorTest.ProcessorType processor = processorTestContext.getProcessor(); + String compilerId = processor.getCompilerId(); if ( compilerId != null ) { - String profile = processorTestContext.getProcessor().getProfile(); + String profile = processor.getProfile(); if ( profile == null ) { profile = "generate-via-compiler-plugin"; } verifier.addCliOption( "-P" + profile ); verifier.addCliOption( "-Dcompiler-id=" + compilerId ); + if ( processor == ProcessorTest.ProcessorType.JAVAC ) { + if ( CURRENT_VERSION.ordinal() >= JRE.JAVA_21.ordinal() ) { + verifier.addCliOption( "-Dmaven.compiler.proc=full" ); + } + } } else { verifier.addCliOption( "-Pgenerate-via-processor-plugin" ); diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 1a31b28221..849f7150fc 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -27,6 +27,11 @@ x x x + x + x + x + x + x @@ -49,6 +54,11 @@ ${additionalExclude4} ${additionalExclude5} ${additionalExclude6} + ${additionalExclude7} + ${additionalExclude8} + ${additionalExclude9} + ${additionalExclude10} + ${additionalExclude11} diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml index 1b84638ef2..5ab2d0d18f 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml @@ -32,7 +32,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 -proc:none diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml index ee0d556b9f..d1e1dd7dff 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml @@ -38,7 +38,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 -XprintProcessorInfo diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml index bf0d704851..67df383a18 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml @@ -32,7 +32,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 -proc:none diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml index da72f667a4..bd06b79a49 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -38,7 +38,6 @@ org.apache.maven.plugins maven-compiler-plugin - 3.1 -XprintProcessorInfo diff --git a/parent/pom.xml b/parent/pom.xml index 94c84fb4d0..5509e783d2 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -34,7 +34,7 @@ 3.4.1 3.2.2 3.1.0 - 5.3.31 + 6.2.2 1.6.0 8.36.1 5.10.1 @@ -47,7 +47,7 @@ jdt_apt 1.8 3.21.7 @@ -400,7 +400,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.13.0 org.apache.maven.plugins diff --git a/processor/pom.xml b/processor/pom.xml index ed2df7718b..13deafb413 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -24,7 +24,7 @@ - 11 + 17 diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Mapper.java similarity index 91% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Mapper.java index ebc9ae27e0..4e48020c8d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Mapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1395; +package org.mapstruct.ap.test.bugs._1395.spring; import org.mapstruct.InjectionStrategy; import org.mapstruct.Mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Test.java similarity index 92% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Test.java index 042d0288cd..3417fbd707 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Issue1395Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Issue1395Test.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1395; +package org.mapstruct.ap.test.bugs._1395.spring; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/NotUsedService.java similarity index 81% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/NotUsedService.java index 765764ef2b..ba47cf179f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/NotUsedService.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/NotUsedService.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1395; +package org.mapstruct.ap.test.bugs._1395.spring; /** * @author Filip Hrisafov diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Source.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Source.java index 1b676c2b62..8f2a52d462 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Source.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Source.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1395; +package org.mapstruct.ap.test.bugs._1395.spring; /** * @author Filip Hrisafov diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Target.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Target.java index 2c7b22fd4d..1ba393dbe0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/Target.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1395/spring/Target.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._1395; +package org.mapstruct.ap.test.bugs._1395.spring; /** * @author Filip Hrisafov diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/Issue2807Test.java similarity index 69% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/Issue2807Test.java index 2cb96ce37e..102a9d26eb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/Issue2807Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/Issue2807Test.java @@ -3,11 +3,11 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._2807; +package org.mapstruct.ap.test.bugs._2807.spring; -import org.mapstruct.ap.test.bugs._2807.after.AfterMethod; -import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod; -import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget; +import org.mapstruct.ap.test.bugs._2807.spring.after.AfterMethod; +import org.mapstruct.ap.test.bugs._2807.spring.before.BeforeMethod; +import org.mapstruct.ap.test.bugs._2807.spring.beforewithtarget.BeforeWithTarget; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/SpringLifeCycleMapper.java similarity index 70% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/SpringLifeCycleMapper.java index daabe7f52a..408a2ca3e0 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/SpringLifeCycleMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/SpringLifeCycleMapper.java @@ -3,15 +3,15 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._2807; +package org.mapstruct.ap.test.bugs._2807.spring; import java.util.List; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; -import org.mapstruct.ap.test.bugs._2807.after.AfterMethod; -import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod; -import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget; +import org.mapstruct.ap.test.bugs._2807.spring.after.AfterMethod; +import org.mapstruct.ap.test.bugs._2807.spring.before.BeforeMethod; +import org.mapstruct.ap.test.bugs._2807.spring.beforewithtarget.BeforeWithTarget; import org.mapstruct.factory.Mappers; /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/after/AfterMethod.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/after/AfterMethod.java index f7c7457348..05770c6603 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/after/AfterMethod.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/after/AfterMethod.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._2807.after; +package org.mapstruct.ap.test.bugs._2807.spring.after; import java.util.List; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/before/BeforeMethod.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/before/BeforeMethod.java index 5252bee150..9fb9e7e883 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/before/BeforeMethod.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/before/BeforeMethod.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._2807.before; +package org.mapstruct.ap.test.bugs._2807.spring.before; import org.mapstruct.BeforeMapping; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/beforewithtarget/BeforeWithTarget.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/beforewithtarget/BeforeWithTarget.java index 69e62bdea1..a3ee8b57ea 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/beforewithtarget/BeforeWithTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_2807/spring/beforewithtarget/BeforeWithTarget.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._2807.beforewithtarget; +package org.mapstruct.ap.test.bugs._2807.spring.beforewithtarget; import java.util.List; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Config.java similarity index 87% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Config.java index 32f58384b9..7aef1e9e1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Config.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Config.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._880; +package org.mapstruct.ap.test.bugs._880.spring; import org.mapstruct.MapperConfig; import org.mapstruct.ReportingPolicy; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/DefaultsToProcessorOptionsMapper.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/DefaultsToProcessorOptionsMapper.java index c54da3f7cb..5f67b41552 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/DefaultsToProcessorOptionsMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/DefaultsToProcessorOptionsMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._880; +package org.mapstruct.ap.test.bugs._880.spring; import org.mapstruct.Mapper; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Issue880Test.java similarity index 97% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Issue880Test.java index 9d8540b409..d2f371abed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Issue880Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Issue880Test.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._880; +package org.mapstruct.ap.test.bugs._880.spring; import javax.tools.Diagnostic.Kind; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Poodle.java similarity index 88% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Poodle.java index e822db1cfe..71166f6d4c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/Poodle.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/Poodle.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._880; +package org.mapstruct.ap.test.bugs._880.spring; /** * @author Andreas Gudian diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/UsesConfigFromAnnotationMapper.java similarity index 90% rename from processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/UsesConfigFromAnnotationMapper.java index d9a1efe33e..bb9a7def9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/UsesConfigFromAnnotationMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_880/spring/UsesConfigFromAnnotationMapper.java @@ -3,7 +3,7 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.bugs._880; +package org.mapstruct.ap.test.bugs._880.spring; import org.mapstruct.Mapper; import org.mapstruct.MappingConstants; diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index a3bad68b92..be1a67cf09 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -11,6 +11,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.decorator.Address; import org.mapstruct.ap.test.decorator.AddressDto; @@ -46,6 +48,7 @@ @ComponentScan(basePackageClasses = Jsr330DecoratorTest.class) @Configuration @WithJavaxInject +@DisabledOnJre(JRE.OTHER) public class Jsr330DecoratorTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java index 6b92d9815a..192059c8a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/_default/Jsr330DefaultCompileOptionFieldMapperTest.java @@ -10,6 +10,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; @@ -44,6 +46,7 @@ @ComponentScan(basePackageClasses = CustomerJsr330DefaultCompileOptionFieldMapper.class) @WithJavaxInject @Configuration +@DisabledOnJre(JRE.OTHER) public class Jsr330DefaultCompileOptionFieldMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java index fe9cf295f4..02b634da8d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/compileoptionconstructor/Jsr330CompileOptionConstructorMapperTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; @@ -44,6 +46,7 @@ @ComponentScan(basePackageClasses = CustomerJsr330CompileOptionConstructorMapper.class) @Configuration @WithJavaxInject +@DisabledOnJre(JRE.OTHER) public class Jsr330CompileOptionConstructorMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java index a5cfce5c2e..d51843f00c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/constructor/Jsr330ConstructorMapperTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; @@ -44,6 +46,7 @@ @ComponentScan(basePackageClasses = CustomerJsr330ConstructorMapper.class) @Configuration @WithJavaxInject +@DisabledOnJre(JRE.OTHER) public class Jsr330ConstructorMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java index 84e67f63a8..d713f9cc88 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/field/Jsr330FieldMapperTest.java @@ -10,6 +10,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; @@ -46,6 +48,7 @@ @ComponentScan(basePackageClasses = CustomerJsr330FieldMapper.class) @Configuration @WithJavaxInject +@DisabledOnJre(JRE.OTHER) public class Jsr330FieldMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java index 558206e51c..a6f18ed594 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/injectionstrategy/jsr330/setter/Jsr330SetterMapperTest.java @@ -7,6 +7,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerDto; import org.mapstruct.ap.test.injectionstrategy.shared.CustomerEntity; @@ -42,6 +44,7 @@ @ComponentScan(basePackageClasses = CustomerJsr330SetterMapper.class) @Configuration @WithJavaxInject +@DisabledOnJre(JRE.OTHER) public class Jsr330SetterMapperTest { @RegisterExtension diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java index 40db5afd81..04e387d429 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithSpring.java @@ -10,6 +10,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; /** * Meta annotation that adds the needed Spring Dependencies @@ -23,6 +25,7 @@ "spring-beans", "spring-context" }) +@DisabledOnJre(JRE.OTHER) public @interface WithSpring { } diff --git a/readme.md b/readme.md index adb48b2fd4..907c8411cd 100644 --- a/readme.md +++ b/readme.md @@ -130,7 +130,7 @@ To learn more about MapStruct, refer to the [project homepage](https://mapstruct ## Building from Source -MapStruct uses Maven for its build. Java 11 is required for building MapStruct from source. To build the complete project, run +MapStruct uses Maven for its build. Java 17 is required for building MapStruct from source. To build the complete project, run ./mvnw clean install From c08ba4ca7e2832ad398a61b6a5a181ebaecd4e0d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Wed, 22 Jan 2025 08:51:49 +0100 Subject: [PATCH 0885/1006] Update setup-java and checkout actions to v4 (#3804) --- .github/workflows/java-ea.yml | 2 +- .github/workflows/main.yml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index fce2dc06b2..fc3a4a0fb1 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Set up JDK' uses: oracle-actions/setup-java@v1 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9cc098161d..a760175c0e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,9 +17,9 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Set up JDK' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: ${{ matrix.java }} @@ -43,16 +43,16 @@ jobs: runs-on: ubuntu-latest steps: - name: 'Checkout' - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: 'Set up JDK 17 for building everything' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 - name: 'Install Processor' run: ./mvnw ${MAVEN_ARGS} -DskipTests install -pl processor -am - name: 'Set up JDK ${{ matrix.java }} for running integration tests' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: ${{ matrix.java }} @@ -62,9 +62,9 @@ jobs: name: 'Windows' runs-on: windows-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: 'Set up JDK 17' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 @@ -76,7 +76,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: 'Set up JDK 17' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 From 39551242d7cfbab7e6bbadfed8c771b483cc1a13 Mon Sep 17 00:00:00 2001 From: Zegveld <41897697+Zegveld@users.noreply.github.com> Date: Fri, 24 Jan 2025 14:41:35 +0100 Subject: [PATCH 0886/1006] #3786: Improve error message when mapping non-iterable to array --- .../processor/MethodRetrievalProcessor.java | 5 +++ .../mapstruct/ap/internal/util/Message.java | 1 + .../bugs/_3786/ErroneousByteArrayMapper.java | 13 +++++++ .../ap/test/bugs/_3786/Issue3786Test.java | 36 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3786/ErroneousByteArrayMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3786/Issue3786Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 2c8ad5dcb9..c8c13e6bf9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -555,6 +555,11 @@ private boolean checkParameterAndReturnType(ExecutableElement method, List Date: Sat, 10 May 2025 14:12:20 +0200 Subject: [PATCH 0887/1006] #3815: chore(docs): Improved wording about @Condition usage --- .../main/asciidoc/chapter-10-advanced-mapping-options.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 1e2bd133d4..b5c116ffd3 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -308,7 +308,7 @@ Conditional mapping can also be used to check if a source parameter should be ma A custom condition method for properties is a method that is annotated with `org.mapstruct.Condition` and returns `boolean`. A custom condition method for source parameters is annotated with `org.mapstruct.SourceParameterCondition`, `org.mapstruct.Condition(appliesTo = org.mapstruct.ConditionStrategy#SOURCE_PARAMETERS)` or meta-annotated with `Condition(appliesTo = ConditionStrategy#SOURCE_PARAMETERS)` -e.g. if you only want to map a String property when it is not `null`, and it is not empty then you can do something like: +e.g. if you only want to map a String property when it is not `null` and not empty then you can do something like: .Mapper using custom condition check method ==== From 668eeb5de1b1dc79cbf90e68cdf38fbba03c98a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:25:00 +0000 Subject: [PATCH 0888/1006] Bump com.google.protobuf:protobuf-java from 3.21.7 to 3.25.5 in /parent Bumps [com.google.protobuf:protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.21.7 to 3.25.5. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.21.7...v3.25.5) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index 5509e783d2..5735d4760c 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -50,7 +50,7 @@ The processor module needs at least Java 17. --> 1.8 - 3.21.7 + 3.25.5 2.3.2 From 2c84d04463a3ec2edd6c05e726a579b4ba936847 Mon Sep 17 00:00:00 2001 From: Cause Chung Date: Sun, 11 May 2025 17:33:35 +0200 Subject: [PATCH 0889/1006] #3240 Add Support for Java21 SequencedSet and SequencedMap --- .github/workflows/main.yml | 24 +++--- .github/workflows/release.yml | 2 +- .../chapter-6-mapping-collections.asciidoc | 4 + ...eatureCompilationExclusionCliEnhancer.java | 7 ++ .../test/resources/fullFeatureTest/pom.xml | 2 + parent/pom.xml | 2 +- processor/pom.xml | 2 +- .../ap/internal/model/common/TypeFactory.java | 13 ++++ .../util/JavaCollectionConstants.java | 21 ++++++ ...dCollectionsDefaultImplementationTest.java | 74 +++++++++++++++++++ .../jdk21/SequencedCollectionsMapper.java | 26 +++++++ readme.md | 3 +- 12 files changed, 164 insertions(+), 16 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/JavaCollectionConstants.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsDefaultImplementationTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsMapper.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a760175c0e..166466348d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - java: [17, 21] + java: [21] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: @@ -24,31 +24,31 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=${{ matrix.java != 17 }} install -DskipDistribution=${{ matrix.java != 17 }} + run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=${{ matrix.java != 21 }} install -DskipDistribution=${{ matrix.java != 21 }} - name: 'Generate coverage report' - if: matrix.java == 17 + if: matrix.java == 21 run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' - if: matrix.java == 17 + if: matrix.java == 21 uses: codecov/codecov-action@v2 - name: 'Publish Snapshots' - if: matrix.java == 17 && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' + if: matrix.java == 21 && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy integration_test_jdk: strategy: fail-fast: false matrix: - java: [ 8, 11 ] + java: [ 8, 11, 17 ] name: 'Linux JDK ${{ matrix.java }}' runs-on: ubuntu-latest steps: - name: 'Checkout' uses: actions/checkout@v4 - - name: 'Set up JDK 17 for building everything' + - name: 'Set up JDK 21 for building everything' uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 17 + java-version: 21 - name: 'Install Processor' run: ./mvnw ${MAVEN_ARGS} -DskipTests install -pl processor -am - name: 'Set up JDK ${{ matrix.java }} for running integration tests' @@ -63,11 +63,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v4 - - name: 'Set up JDK 17' + - name: 'Set up JDK 21' uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 17 + java-version: 21 - name: 'Test' run: ./mvnw %MAVEN_ARGS% install mac: @@ -75,10 +75,10 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v3 - - name: 'Set up JDK 17' + - name: 'Set up JDK 21' uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: 17 + java-version: 21 - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 682fa36876..61f347af3c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: - name: Setup Java uses: actions/setup-java@v4 with: - java-version: 17 + java-version: 21 distribution: 'zulu' cache: maven diff --git a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc index 79d4544f9b..4510c82cc0 100644 --- a/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc +++ b/documentation/src/main/asciidoc/chapter-6-mapping-collections.asciidoc @@ -212,12 +212,16 @@ When an iterable or map mapping method declares an interface type as return type |`Set`|`LinkedHashSet` +|`SequencedSet`|`LinkedHashSet` + |`SortedSet`|`TreeSet` |`NavigableSet`|`TreeSet` |`Map`|`LinkedHashMap` +|`SequencedMap`|`LinkedHashMap` + |`SortedMap`|`TreeMap` |`NavigableMap`|`TreeMap` diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index 77a5e2af06..0cc1a87818 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -34,6 +34,7 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/annotatewith/deprecated/jdk11/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); if ( processorType == ProcessorTest.ProcessorType.ECLIPSE_JDT ) { additionalExcludes.add( "org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java" ); @@ -42,9 +43,15 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces case JAVA_9: // TODO find out why this fails: additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); break; case JAVA_11: additionalExcludes.add( "org/mapstruct/ap/test/**/spring/**/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); + break; + case JAVA_17: + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); + break; default: } diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index 849f7150fc..b5ddae9a79 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -59,6 +59,8 @@ ${additionalExclude9} ${additionalExclude10} ${additionalExclude11} + ${additionalExclude12} + ${additionalExclude13} diff --git a/parent/pom.xml b/parent/pom.xml index 5735d4760c..f6ad60a22a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -47,7 +47,7 @@ jdt_apt 1.8 3.25.5 diff --git a/processor/pom.xml b/processor/pom.xml index 13deafb413..2341c4ddb0 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -24,7 +24,7 @@ - 17 + 21 diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index ceb190a332..c2646f63db 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -45,6 +45,7 @@ import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.Extractor; import org.mapstruct.ap.internal.util.FormattingMessager; +import org.mapstruct.ap.internal.util.JavaCollectionConstants; import org.mapstruct.ap.internal.util.JavaStreamConstants; import org.mapstruct.ap.internal.util.Message; import org.mapstruct.ap.internal.util.NativeTypes; @@ -149,6 +150,18 @@ public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMes ConcurrentNavigableMap.class.getName(), withDefaultConstructor( getType( ConcurrentSkipListMap.class ) ) ); + implementationTypes.put( + JavaCollectionConstants.SEQUENCED_SET_FQN, + sourceVersionAtLeast19 ? + withFactoryMethod( getType( LinkedHashSet.class ), LINKED_HASH_SET_FACTORY_METHOD_NAME ) : + withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) + ); + implementationTypes.put( + JavaCollectionConstants.SEQUENCED_MAP_FQN, + sourceVersionAtLeast19 ? + withFactoryMethod( getType( LinkedHashMap.class ), LINKED_HASH_MAP_FACTORY_METHOD_NAME ) : + withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) + ); this.loggingVerbose = loggingVerbose; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/JavaCollectionConstants.java b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaCollectionConstants.java new file mode 100644 index 0000000000..68d556c542 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/JavaCollectionConstants.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util; + +/** + * Helper holding Java collections full qualified class names for conversion registration, + * to achieve Java compatibility. + * + * @author Cause Chung + */ +public final class JavaCollectionConstants { + public static final String SEQUENCED_MAP_FQN = "java.util.SequencedMap"; + public static final String SEQUENCED_SET_FQN = "java.util.SequencedSet"; + + private JavaCollectionConstants() { + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsDefaultImplementationTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsDefaultImplementationTest.java new file mode 100644 index 0000000000..4551d5b0b3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsDefaultImplementationTest.java @@ -0,0 +1,74 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.defaultimplementation.jdk21; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.SequencedMap; +import java.util.SequencedSet; + +import org.mapstruct.ap.test.collection.defaultimplementation.Source; +import org.mapstruct.ap.test.collection.defaultimplementation.SourceFoo; +import org.mapstruct.ap.test.collection.defaultimplementation.Target; +import org.mapstruct.ap.test.collection.defaultimplementation.TargetFoo; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +@WithClasses({ + Source.class, + Target.class, + SourceFoo.class, + TargetFoo.class, + SequencedCollectionsMapper.class +}) +@IssueKey("3420") +class SequencedCollectionsDefaultImplementationTest { + + @ProcessorTest + public void shouldUseDefaultImplementationForSequencedMap() { + SequencedMap target = + SequencedCollectionsMapper.INSTANCE.sourceFooMapToTargetFooSequencedMap( createSourceFooMap() ); + + assertResultMap( target ); + } + + @ProcessorTest + public void shouldUseDefaultImplementationForSequencedSet() { + SequencedSet target = + SequencedCollectionsMapper.INSTANCE.sourceFoosToTargetFooSequencedSet( createSourceFooList() ); + + assertResultList( target ); + } + + private void assertResultList(Iterable fooIterable) { + assertThat( fooIterable ).isNotNull(); + assertThat( fooIterable ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) ); + } + + private void assertResultMap(Map result) { + assertThat( result ).isNotNull(); + assertThat( result ).hasSize( 2 ); + assertThat( result ).contains( entry( "1", new TargetFoo( "Bob" ) ), entry( "2", new TargetFoo( "Alice" ) ) ); + } + + private Map createSourceFooMap() { + Map map = new HashMap<>(); + map.put( 1L, new SourceFoo( "Bob" ) ); + map.put( 2L, new SourceFoo( "Alice" ) ); + + return map; + } + + private List createSourceFooList() { + return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsMapper.java new file mode 100644 index 0000000000..bbffb56b0c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/defaultimplementation/jdk21/SequencedCollectionsMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.collection.defaultimplementation.jdk21; + +import java.util.Collection; +import java.util.Map; +import java.util.SequencedMap; +import java.util.SequencedSet; + +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.collection.defaultimplementation.SourceFoo; +import org.mapstruct.ap.test.collection.defaultimplementation.TargetFoo; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SequencedCollectionsMapper { + + SequencedCollectionsMapper INSTANCE = Mappers.getMapper( SequencedCollectionsMapper.class ); + + SequencedSet sourceFoosToTargetFooSequencedSet(Collection foos); + + SequencedMap sourceFooMapToTargetFooSequencedMap(Map foos); +} diff --git a/readme.md b/readme.md index 907c8411cd..16a70f3f0b 100644 --- a/readme.md +++ b/readme.md @@ -130,7 +130,8 @@ To learn more about MapStruct, refer to the [project homepage](https://mapstruct ## Building from Source -MapStruct uses Maven for its build. Java 17 is required for building MapStruct from source. To build the complete project, run +MapStruct uses Maven for its build. Java 21 is required for building MapStruct from source. +To build the complete project, run ./mvnw clean install From 602e29083fe980be0256fd01d37906ceab1ff6ca Mon Sep 17 00:00:00 2001 From: zral <73640367+zyberzebra@users.noreply.github.com> Date: Sun, 11 May 2025 19:59:59 +0200 Subject: [PATCH 0890/1006] #1140 Add warning when target has no properties --- .../ap/internal/model/BeanMappingMethod.java | 78 ++++++++++++------- .../mapstruct/ap/internal/util/Message.java | 1 + .../test/annotatewith/AnnotateWithTest.java | 5 +- .../ErroneousMapperWithClassOnMethod.java | 10 +-- .../ap/test/bugs/_1111/Issue1111Mapper.java | 25 +++++- .../ap/test/bugs/_1111/Issue1111Test.java | 2 +- .../ap/test/bugs/_1130/Issue1130Mapper.java | 19 +++++ ...roneousIssue1242MapperMultipleSources.java | 3 +- .../ap/test/bugs/_1242/Issue1242Mapper.java | 3 +- .../ap/test/bugs/_1242/Issue1242Test.java | 2 +- .../mapstruct/ap/test/bugs/_1242/TargetB.java | 9 +++ .../ap/test/bugs/_1345/Issue1345Mapper.java | 18 +++++ .../ap/test/bugs/_1460/Issue1460Mapper.java | 21 ++++- .../_1460/java8/Issue1460JavaTimeMapper.java | 11 ++- .../mapstruct/ap/test/bugs/_1590/Book.java | 10 +++ .../ap/test/bugs/_1590/Issue1590Test.java | 2 +- .../org/mapstruct/ap/test/bugs/_1650/C.java | 10 +++ .../mapstruct/ap/test/bugs/_1650/CPrime.java | 10 +++ .../ap/test/bugs/_1650/Issue1650Test.java | 2 +- .../ap/test/bugs/_1821/Issue1821Mapper.java | 20 +++++ .../ap/test/bugs/_1821/Issue1821Test.java | 2 +- .../ap/test/bugs/_611/Issue611Test.java | 4 +- .../ap/test/bugs/_611/SomeClass.java | 40 ++++++++++ .../ap/test/bugs/_611/SomeOtherClass.java | 20 +++++ .../simple/BuilderInfoTargetTest.java | 16 +++- .../simple/SimpleBuilderMapper.java | 3 - .../simple/SimpleImmutableUpdateMapper.java | 19 +++++ .../immutabletarget/ImmutableProductTest.java | 10 +++ .../ap/test/collection/wildcard/Idea.java | 9 +++ .../ap/test/collection/wildcard/Plan.java | 9 +++ .../visibility/ConstructorVisibilityTest.java | 12 +++ .../AbstractDestinationClassNameMapper.java | 2 +- .../AbstractDestinationPackageNameMapper.java | 2 +- .../DestinationClassNameMapper.java | 2 +- .../DestinationClassNameMapperDecorated.java | 2 +- .../DestinationClassNameMapperDecorator.java | 4 +- .../DestinationClassNameMapperWithConfig.java | 2 +- ...tionClassNameMapperWithConfigOverride.java | 2 +- .../destination/DestinationClassNameTest.java | 1 + .../DestinationClassNameWithJsr330Mapper.java | 2 +- .../DestinationPackageNameMapper.java | 2 +- ...DestinationPackageNameMapperDecorated.java | 2 +- ...DestinationPackageNameMapperDecorator.java | 4 +- ...estinationPackageNameMapperWithConfig.java | 2 +- ...onPackageNameMapperWithConfigOverride.java | 2 +- ...estinationPackageNameMapperWithSuffix.java | 2 +- .../DestinationPackageNameTest.java | 1 + .../mapstruct/ap/test/destination/Target.java | 19 +++++ .../ap/test/emptytarget/EmptyTarget.java | 9 +++ .../test/emptytarget/EmptyTargetMapper.java | 18 +++++ .../ap/test/emptytarget/EmptyTargetTest.java | 39 ++++++++++ .../mapstruct/ap/test/emptytarget/Source.java | 36 +++++++++ .../mapstruct/ap/test/emptytarget/Target.java | 34 ++++++++ .../test/emptytarget/TargetWithNoSetters.java | 15 ++++ .../ap/test/imports/SourceTargetMapper.java | 10 ++- .../ap/test/java8stream/wildcard/Idea.java | 9 +++ .../ap/test/java8stream/wildcard/Plan.java | 9 +++ .../ErroneousSourceTargetMapper.java | 16 +++- .../MissingIgnoredSourceTest.java | 2 +- .../objectfactory/ObjectFactoryMapper.java | 13 +++- .../fixture/AbstractParentSource.java | 9 +++ .../fixture/AbstractParentTarget.java | 9 +++ .../fixture/ImplementedParentSource.java | 9 +++ .../fixture/ImplementedParentTarget.java | 9 +++ .../ap/test/versioninfo/SimpleMapper.java | 3 +- .../SuppressTimestampViaMapper.java | 3 +- .../SuppressTimestampViaMapperConfig.java | 3 +- .../ap/test/versioninfo/VersionInfoTest.java | 3 +- .../fixture/SubclassAbstractMapperImpl.java | 13 ++++ .../SubclassImplementedMapperImpl.java | 8 ++ .../fixture/SubclassInterfaceMapperImpl.java | 5 ++ 71 files changed, 657 insertions(+), 85 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableUpdateMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/destination/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/emptytarget/TargetWithNoSetters.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 4ff2e8079f..08c8ceda59 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -235,9 +235,10 @@ else if ( !method.isUpdateMethod() ) { this.unprocessedTargetProperties = new LinkedHashMap<>( accessors ); + boolean constructorAccessorHadError = false; if ( !method.isUpdateMethod() && !hasFactoryMethod ) { ConstructorAccessor constructorAccessor = getConstructorAccessor( resultTypeToMap ); - if ( constructorAccessor != null ) { + if ( constructorAccessor != null && !constructorAccessor.hasError ) { this.unprocessedConstructorProperties = constructorAccessor.constructorAccessors; @@ -250,8 +251,10 @@ else if ( !method.isUpdateMethod() ) { else { this.unprocessedConstructorProperties = new LinkedHashMap<>(); } + constructorAccessorHadError = constructorAccessor != null && constructorAccessor.hasError; this.targetProperties.addAll( this.unprocessedConstructorProperties.keySet() ); + this.unprocessedTargetProperties.putAll( this.unprocessedConstructorProperties ); } else { @@ -322,7 +325,7 @@ else if ( !method.isUpdateMethod() ) { // report errors on unmapped properties if ( shouldHandledDefinedMappings ) { - reportErrorForUnmappedTargetPropertiesIfRequired(); + reportErrorForUnmappedTargetPropertiesIfRequired( resultTypeToMap, constructorAccessorHadError ); reportErrorForUnmappedSourcePropertiesIfRequired(); } reportErrorForMissingIgnoredSourceProperties(); @@ -964,7 +967,7 @@ private ConstructorAccessor getConstructorAccessor(Type type) { ) .collect( Collectors.joining( ", " ) ) ); - return null; + return new ConstructorAccessor( true, Collections.emptyList(), Collections.emptyMap() ); } else { return getConstructorAccessor( type, accessibleConstructors.get( 0 ) ); @@ -1023,7 +1026,7 @@ else if ( constructorProperties.size() != constructorParameters.size() ) { GENERAL_CONSTRUCTOR_PROPERTIES_NOT_MATCHING_PARAMETERS, type ); - return null; + return new ConstructorAccessor( true, Collections.emptyList(), Collections.emptyMap() ); } else { Map constructorAccessors = new LinkedHashMap<>(); @@ -1731,36 +1734,45 @@ private ReportingPolicyGem getUnmappedTargetPolicy() { return method.getOptions().getMapper().unmappedTargetPolicy(); } - private void reportErrorForUnmappedTargetPropertiesIfRequired() { + private void reportErrorForUnmappedTargetPropertiesIfRequired(Type resultType, + boolean constructorAccessorHadError) { // fetch settings from element to implement ReportingPolicyGem unmappedTargetPolicy = getUnmappedTargetPolicy(); - if ( method instanceof ForgedMethod && targetProperties.isEmpty() ) { - //TODO until we solve 1140 we report this error when the target properties are empty - ForgedMethod forgedMethod = (ForgedMethod) method; - if ( forgedMethod.getHistory() == null ) { - Type sourceType = this.method.getParameters().get( 0 ).getType(); - Type targetType = this.method.getReturnType(); - ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, - sourceType.describe(), - targetType.describe(), - targetType.describe(), - sourceType.describe() - ); + if ( targetProperties.isEmpty() ) { + if ( method instanceof ForgedMethod ) { + ForgedMethod forgedMethod = (ForgedMethod) method; + if ( forgedMethod.getHistory() == null ) { + Type sourceType = this.method.getParameters().get( 0 ).getType(); + Type targetType = this.method.getReturnType(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_FORGED_MAPPING_NOT_FOUND, + sourceType.describe(), + targetType.describe(), + targetType.describe(), + sourceType.describe() + ); + } + else { + ForgedMethodHistory history = forgedMethod.getHistory(); + ctx.getMessager().printMessage( + this.method.getExecutable(), + Message.PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND, + history.createSourcePropertyErrorMessage(), + history.getTargetType().describe(), + history.createTargetPropertyName(), + history.getTargetType().describe(), + history.getSourceType().describe() + ); + } } - else { - ForgedMethodHistory history = forgedMethod.getHistory(); + else if ( !constructorAccessorHadError ) { ctx.getMessager().printMessage( - this.method.getExecutable(), - Message.PROPERTYMAPPING_FORGED_MAPPING_WITH_HISTORY_NOT_FOUND, - history.createSourcePropertyErrorMessage(), - history.getTargetType().describe(), - history.createTargetPropertyName(), - history.getTargetType().describe(), - history.getSourceType().describe() + method.getExecutable(), + Message.PROPERTYMAPPING_TARGET_HAS_NO_TARGET_PROPERTIES, + resultType.describe() ); } } @@ -1780,7 +1792,8 @@ else if ( !unprocessedTargetProperties.isEmpty() && unmappedTargetPolicy.require reportErrorForUnmappedProperties( unprocessedTargetProperties, unmappedPropertiesMsg, - unmappedForgedPropertiesMsg ); + unmappedForgedPropertiesMsg + ); } } @@ -1907,12 +1920,19 @@ private void reportErrorForUnusedSourceParameters() { } private static class ConstructorAccessor { + private final boolean hasError; private final List parameterBindings; private final Map constructorAccessors; private ConstructorAccessor( List parameterBindings, Map constructorAccessors) { + this( false, parameterBindings, constructorAccessors ); + } + + private ConstructorAccessor(boolean hasError, List parameterBindings, + Map constructorAccessors) { + this.hasError = hasError; this.parameterBindings = parameterBindings; this.constructorAccessors = constructorAccessors; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 221aed2859..883b3e3792 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -92,6 +92,7 @@ public enum Message { PROPERTYMAPPING_CANNOT_DETERMINE_SOURCE_PARAMETER_FROM_TARGET("No property named \"%s\" exists in source parameter(s). Please define the source explicitly."), PROPERTYMAPPING_NO_SUITABLE_COLLECTION_OR_MAP_CONSTRUCTOR( "%s does not have an accessible copy or no-args constructor." ), PROPERTYMAPPING_EXPRESSION_AND_CONDITION_QUALIFIED_BY_NAME_BOTH_DEFINED( "Expression and condition qualified by name are both defined in @Mapping, either define an expression or a condition qualified by name." ), + PROPERTYMAPPING_TARGET_HAS_NO_TARGET_PROPERTIES( "No target property found for target \"%s\".", Diagnostic.Kind.WARNING ), CONVERSION_LOSSY_WARNING( "%s has a possibly lossy conversion from %s to %s.", Diagnostic.Kind.WARNING ), CONVERSION_LOSSY_ERROR( "Can't map %s. It has a possibly lossy conversion from %s to %s." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java index 3687fe2bc0..eaa8832df7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/AnnotateWithTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -176,12 +177,12 @@ public void erroneousMapperWithAnnotationOnlyOnClass() { @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousMapperWithClassOnMethod.class, - line = 17, + line = 18, message = "Annotation \"CustomClassOnlyAnnotation\" is not allowed on methods." ) } ) - @WithClasses({ ErroneousMapperWithClassOnMethod.class, CustomClassOnlyAnnotation.class }) + @WithClasses({ ErroneousMapperWithClassOnMethod.class, CustomClassOnlyAnnotation.class, WithProperties.class }) public void erroneousMapperWithClassOnMethod() { } diff --git a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java index d3d53c910a..c34bce304f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java +++ b/processor/src/test/java/org/mapstruct/ap/test/annotatewith/ErroneousMapperWithClassOnMethod.java @@ -7,6 +7,7 @@ import org.mapstruct.AnnotateWith; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.WithProperties; /** * @author Ben Zegveld @@ -15,13 +16,6 @@ public interface ErroneousMapperWithClassOnMethod { @AnnotateWith( value = CustomClassOnlyAnnotation.class ) - Target toString(Source value); + WithProperties toString(String string); - class Source { - - } - - class Target { - - } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java index a5a624e684..7cdfa82316 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Mapper.java @@ -24,8 +24,29 @@ public interface Issue1111Mapper { List> listList(List> in); - class Source { } + class Source { + private final String value; - class Target { } + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java index 5619b64175..f5efb21e3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1111/Issue1111Test.java @@ -27,7 +27,7 @@ public class Issue1111Test { @ProcessorTest public void shouldCompile() { - List> source = Arrays.asList( Arrays.asList( new Source() ) ); + List> source = Arrays.asList( Arrays.asList( new Source( "test" ) ) ); List> target = Issue1111Mapper.INSTANCE.listList( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java index 042d5a2f8b..350d95eebc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1130/Issue1130Mapper.java @@ -30,6 +30,16 @@ public void setB(BEntity b) { } static class BEntity { + + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } } static class ADto { @@ -46,6 +56,7 @@ public void setB(BDto b) { class BDto { private final String passedViaConstructor; + private String id; BDto(String passedViaConstructor) { this.passedViaConstructor = passedViaConstructor; @@ -54,6 +65,14 @@ class BDto { String getPassedViaConstructor() { return passedViaConstructor; } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } } abstract void mergeA(AEntity source, @MappingTarget ADto target); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java index 7259d343b8..7a8ad05542 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/ErroneousIssue1242MapperMultipleSources.java @@ -7,13 +7,14 @@ import org.mapstruct.Mapper; import org.mapstruct.ObjectFactory; +import org.mapstruct.ReportingPolicy; /** * Results in an ambiguous factory method error, as there are two methods with matching source types available. * * @author Andreas Gudian */ -@Mapper(uses = TargetFactories.class) +@Mapper(uses = TargetFactories.class, unmappedTargetPolicy = ReportingPolicy.IGNORE) public abstract class ErroneousIssue1242MapperMultipleSources { abstract TargetA toTargetA(SourceA source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java index 0491b5ffe0..90ea60a2ee 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Mapper.java @@ -7,13 +7,14 @@ import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; /** * Test mapper for properly resolving the best fitting factory method * * @author Andreas Gudian */ -@Mapper(uses = TargetFactories.class) +@Mapper(uses = TargetFactories.class, unmappedTargetPolicy = ReportingPolicy.IGNORE) public abstract class Issue1242Mapper { abstract TargetA toTargetA(SourceA source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java index f27051670c..036a63f312 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/Issue1242Test.java @@ -54,7 +54,7 @@ public void factoryMethodWithSourceParamIsChosen() { diagnostics = { @Diagnostic(type = ErroneousIssue1242MapperMultipleSources.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 20, + line = 21, message = "Ambiguous factory methods found for creating TargetB: " + "TargetB anotherTargetBCreator(SourceB source), " + "TargetB TargetFactories.createTargetB(SourceB source, @TargetType Class clazz), " + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java index ab4f639697..6a28adc828 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1242/TargetB.java @@ -9,6 +9,7 @@ * @author Andreas Gudian */ class TargetB { + protected String value; private final String passedViaConstructor; TargetB(String passedViaConstructor) { @@ -18,4 +19,12 @@ class TargetB { String getPassedViaConstructor() { return passedViaConstructor; } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java index 7699a8f7e9..b2d89c96e6 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1345/Issue1345Mapper.java @@ -27,8 +27,17 @@ public interface Issue1345Mapper { class A { + private String value; private String readOnlyProperty; + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + public String getReadOnlyProperty() { return readOnlyProperty; } @@ -36,8 +45,17 @@ public String getReadOnlyProperty() { class B { + private String value; private String property; + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + public String getProperty() { return property; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java index 90ed83d28a..1d0d4fccbb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/Issue1460Mapper.java @@ -18,13 +18,13 @@ public abstract class Issue1460Mapper { public abstract Target map(Source source); - public abstract String forceUsageOfIssue1460Enum(Issue1460Enum source); + public abstract Value forceUsageOfIssue1460Enum(Issue1460Enum source); - public abstract String forceUsageOfLocale(Locale source); + public abstract Value forceUsageOfLocale(Locale source); - public abstract String forceUsageOfLocalDate(LocalDate source); + public abstract Value forceUsageOfLocalDate(LocalDate source); - public abstract String forceUsageOfDateTime(DateTime source); + public abstract Value forceUsageOfDateTime(DateTime source); public static class Issue1460Enum { } @@ -37,4 +37,17 @@ public static class LocalDate { public static class DateTime { } + + public static class Value { + + private final T source; + + public Value(T source) { + this.source = source; + } + + public T getSource() { + return source; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java index 216cda21fd..b9bedfe451 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1460/java8/Issue1460JavaTimeMapper.java @@ -18,8 +18,17 @@ public abstract class Issue1460JavaTimeMapper { public abstract Target map(Source source); - public abstract String forceUsageOfLocalDate(LocalDate source); + public abstract LocalTarget forceUsageOfLocalDate(LocalDate source); public static class LocalDate { } + + public static class LocalTarget { + + private final LocalDate source; + + public LocalTarget(LocalDate source) { + this.source = source; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java index 53355ee603..bfe79c1772 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Book.java @@ -6,4 +6,14 @@ package org.mapstruct.ap.test.bugs._1590; public class Book { + + private final String name; + + public Book(String name) { + this.name = name; + } + + public String getName() { + return name; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java index d77add25de..0a9113797c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1590/Issue1590Test.java @@ -28,7 +28,7 @@ public class Issue1590Test { @ProcessorTest public void shouldTestMappingLocalDates() { BookShelf source = new BookShelf(); - source.setBooks( Arrays.asList( new Book() ) ); + source.setBooks( Arrays.asList( new Book("Test") ) ); BookShelf target = BookShelfMapper.INSTANCE.map( source ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java index 705f2e2d69..dbbd74ec95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/C.java @@ -6,4 +6,14 @@ package org.mapstruct.ap.test.bugs._1650; public class C { + + private final int value; + + public C(int value) { + this.value = value; + } + + public int getValue() { + return value; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java index 24e4376f88..db504189f8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/CPrime.java @@ -6,4 +6,14 @@ package org.mapstruct.ap.test.bugs._1650; public class CPrime { + + private int value; + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java index 2d1437eb77..33237e726c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1650/Issue1650Test.java @@ -27,7 +27,7 @@ public void shouldCompile() { A a = new A(); a.setB( new B() ); - a.getB().setC( new C() ); + a.getB().setC( new C( 10 ) ); APrime aPrime = new APrime(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java index 08eccae32e..406fa7b71b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Mapper.java @@ -22,11 +22,31 @@ public interface Issue1821Mapper { ExtendedTarget mapExtended(Source source); class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } class ExtendedTarget extends Target { } class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java index 4481ed43e2..865ef8f6c1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1821/Issue1821Test.java @@ -15,7 +15,7 @@ public class Issue1821Test { @ProcessorTest public void shouldNotGiveNullPtr() { - Issue1821Mapper.INSTANCE.map( new Issue1821Mapper.Source() ); + Issue1821Mapper.INSTANCE.map( new Issue1821Mapper.Source( "test" ) ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java index 79a6e045ec..b77da90ad9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/Issue611Test.java @@ -43,8 +43,8 @@ public void mapperNestedInsideNestedClassIsFound() { */ @ProcessorTest public void rightMapperIsFound() { - SomeClass.InnerMapper.Source source1 = new SomeClass.InnerMapper.Source(); - SomeOtherClass.InnerMapper.Source source2 = new SomeOtherClass.InnerMapper.Source(); + SomeClass.InnerMapper.Source source1 = new SomeClass.InnerMapper.Source( "test" ); + SomeOtherClass.InnerMapper.Source source2 = new SomeOtherClass.InnerMapper.Source( "test2" ); SomeClass.InnerMapper.Target target1 = SomeClass.InnerMapper.INSTANCE.toTarget( source1 ); SomeOtherClass.InnerMapper.Target target2 = SomeOtherClass.InnerMapper.INSTANCE.toTarget( source2 ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java index 0d41128711..e0fb59d4d7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeClass.java @@ -19,9 +19,29 @@ public interface InnerMapper { Target toTarget(Source in); class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } } @@ -33,9 +53,29 @@ public interface InnerMapper { Target toTarget(Source in); class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java index e50187a82a..2ff2d0d831 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_611/SomeOtherClass.java @@ -19,9 +19,29 @@ public interface InnerMapper { Target toTarget(Source in); class Source { + + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } class Target { + + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } } } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java index 4f3d8b85f4..5d0ff919ec 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/BuilderInfoTargetTest.java @@ -9,6 +9,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.runner.GeneratedSource; import static org.assertj.core.api.Assertions.assertThat; @@ -80,6 +83,17 @@ public void testUpdateMutableWithBuilder() { } @ProcessorTest + @WithClasses( { + SimpleImmutableUpdateMapper.class + } ) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = SimpleImmutableUpdateMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 18, + message = "No target property found for target \"SimpleImmutableTarget\"."), + }) + public void updatingTargetWithNoSettersShouldNotFail() { SimpleMutableSource source = new SimpleMutableSource(); @@ -90,7 +104,7 @@ public void updatingTargetWithNoSettersShouldNotFail() { .build(); assertThat( target.getAge() ).isEqualTo( 20 ); - SimpleBuilderMapper.INSTANCE.toImmutable( source, target ); + SimpleImmutableUpdateMapper.INSTANCE.toImmutable( source, target ); assertThat( target.getAge() ).isEqualTo( 20 ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java index 9f7187c634..6185daee97 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleBuilderMapper.java @@ -21,9 +21,6 @@ public interface SimpleBuilderMapper { @Mapping(target = "builder.name", source = "source.fullName") void updateImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget.Builder builder); - // This method is fine as if the mapping target has setters it would use them, otherwise it won't - void toImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget target); - @Mapping(target = "name", source = "fullName") SimpleImmutableTarget toImmutable(SimpleMutableSource source); diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableUpdateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableUpdateMapper.java new file mode 100644 index 0000000000..c6eccc96c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/mappingTarget/simple/SimpleImmutableUpdateMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.mappingTarget.simple; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SimpleImmutableUpdateMapper { + + SimpleImmutableUpdateMapper INSTANCE = Mappers.getMapper( SimpleImmutableUpdateMapper.class ); + + // This method is fine as if the mapping target has setters it would use them, otherwise it won't + void toImmutable(SimpleMutableSource source, @MappingTarget SimpleImmutableTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java index de22436296..8097dfdfe9 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/immutabletarget/ImmutableProductTest.java @@ -11,6 +11,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import static org.assertj.core.api.Assertions.assertThat; @@ -41,6 +44,13 @@ public void shouldHandleImmutableTarget() { CupboardNoSetterMapper.class, CupboardEntityOnlyGetter.class }) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = CupboardNoSetterMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 22, + message = "No target property found for target \"CupboardEntityOnlyGetter\"."), + }) public void shouldIgnoreImmutableTarget() { CupboardDto in = new CupboardDto(); in.setContent( Arrays.asList( "flour", "peas" ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java index fc9b89b571..4e21b223db 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Idea.java @@ -11,4 +11,13 @@ */ public class Idea { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java index 29fcfc2f3a..00db02170c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java +++ b/processor/src/test/java/org/mapstruct/ap/test/collection/wildcard/Plan.java @@ -11,4 +11,13 @@ */ public class Plan { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java index b7a254296d..5eebaf5d05 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/constructor/visibility/ConstructorVisibilityTest.java @@ -10,6 +10,9 @@ import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import static org.assertj.core.api.Assertions.assertThat; @@ -44,6 +47,15 @@ public void shouldUseSinglePublicConstructorAlways() { @WithClasses({ SimpleWithPublicParameterlessConstructorMapper.class }) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = SimpleWithPublicParameterlessConstructorMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 21, + message = "No target property found for target " + + "\"SimpleWithPublicParameterlessConstructorMapper.Person\"."), + }) + public void shouldUsePublicParameterConstructorIfPresent() { PersonDto source = new PersonDto(); source.setName( "Bob" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java index 9498b832f7..8dd010cae3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationClassNameMapper.java @@ -16,5 +16,5 @@ public abstract class AbstractDestinationClassNameMapper { public static final AbstractDestinationClassNameMapper INSTANCE = Mappers.getMapper( AbstractDestinationClassNameMapper.class ); - public abstract String intToString(Integer source); + public abstract Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java index b59d5cd21b..e26a6bbe71 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/AbstractDestinationPackageNameMapper.java @@ -16,5 +16,5 @@ public abstract class AbstractDestinationPackageNameMapper { public static final AbstractDestinationPackageNameMapper INSTANCE = Mappers.getMapper( AbstractDestinationPackageNameMapper.class ); - public abstract String intToString(Integer source); + public abstract Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java index a331096a63..99bd8915a5 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapper.java @@ -15,5 +15,5 @@ public interface DestinationClassNameMapper { DestinationClassNameMapper INSTANCE = Mappers.getMapper( DestinationClassNameMapper.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java index ef44767379..454e5e15bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorated.java @@ -17,5 +17,5 @@ public interface DestinationClassNameMapperDecorated { DestinationClassNameMapperDecorated INSTANCE = Mappers.getMapper( DestinationClassNameMapperDecorated.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java index 216786da24..3ba1433e21 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperDecorator.java @@ -16,7 +16,7 @@ protected DestinationClassNameMapperDecorator(DestinationClassNameMapperDecorate } @Override - public String intToString(Integer source) { - return delegate.intToString( source ); + public Target map(Integer source) { + return delegate.map( source ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java index d76392d11d..d13675f0ab 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfig.java @@ -15,5 +15,5 @@ public interface DestinationClassNameMapperWithConfig { DestinationClassNameMapperWithConfig INSTANCE = Mappers.getMapper( DestinationClassNameMapperWithConfig.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java index b218fff158..a3f845462b 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameMapperWithConfigOverride.java @@ -16,5 +16,5 @@ public interface DestinationClassNameMapperWithConfigOverride { DestinationClassNameMapperWithConfigOverride INSTANCE = Mappers.getMapper( DestinationClassNameMapperWithConfigOverride.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java index 30611a8d60..1f6e255b95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameTest.java @@ -16,6 +16,7 @@ /** * @author Christophe Labouisse on 27/05/2015. */ +@WithClasses( Target.class ) public class DestinationClassNameTest { @ProcessorTest @WithClasses({ DestinationClassNameMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java index 92c72a877d..3358f68fd4 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationClassNameWithJsr330Mapper.java @@ -13,5 +13,5 @@ */ @Mapper(implementationName = "Jsr330Impl", componentModel = MappingConstants.ComponentModel.JSR330) public interface DestinationClassNameWithJsr330Mapper { - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java index 8c4740e323..c049036a13 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapper.java @@ -15,5 +15,5 @@ public interface DestinationPackageNameMapper { DestinationPackageNameMapper INSTANCE = Mappers.getMapper( DestinationPackageNameMapper.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java index 1dd371b48a..98f6236027 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorated.java @@ -17,5 +17,5 @@ public interface DestinationPackageNameMapperDecorated { DestinationPackageNameMapperDecorated INSTANCE = Mappers.getMapper( DestinationPackageNameMapperDecorated.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java index 4f6dd3242b..667bd99349 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperDecorator.java @@ -16,7 +16,7 @@ protected DestinationPackageNameMapperDecorator(DestinationPackageNameMapperDeco } @Override - public String intToString(Integer source) { - return delegate.intToString( source ); + public Target map(Integer source) { + return delegate.map( source ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java index fbe69ce43e..6a5a870520 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfig.java @@ -15,5 +15,5 @@ public interface DestinationPackageNameMapperWithConfig { DestinationPackageNameMapperWithConfig INSTANCE = Mappers.getMapper( DestinationPackageNameMapperWithConfig.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java index b53dcaae42..79699006b1 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithConfigOverride.java @@ -16,5 +16,5 @@ public interface DestinationPackageNameMapperWithConfigOverride { DestinationPackageNameMapperWithConfigOverride INSTANCE = Mappers.getMapper( DestinationPackageNameMapperWithConfigOverride.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java index 2a221e5f5b..068f30331d 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameMapperWithSuffix.java @@ -15,5 +15,5 @@ public interface DestinationPackageNameMapperWithSuffix { DestinationPackageNameMapperWithSuffix INSTANCE = Mappers.getMapper( DestinationPackageNameMapperWithSuffix.class ); - String intToString(Integer source); + Target map(Integer source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java index 63c7ece6d5..5e02c88d93 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/DestinationPackageNameTest.java @@ -15,6 +15,7 @@ * @author Christophe Labouisse on 27/05/2015. */ @IssueKey( "556" ) +@WithClasses( Target.class ) public class DestinationPackageNameTest { @ProcessorTest @WithClasses({ DestinationPackageNameMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/destination/Target.java b/processor/src/test/java/org/mapstruct/ap/test/destination/Target.java new file mode 100644 index 0000000000..5b3bb4ba34 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/destination/Target.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.destination; + +public class Target { + + private final Integer source; + + public Target(Integer source) { + this.source = source; + } + + public Integer getSource() { + return source; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTarget.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTarget.java new file mode 100644 index 0000000000..f1b3a0f073 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTarget.java @@ -0,0 +1,9 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +public class EmptyTarget { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetMapper.java new file mode 100644 index 0000000000..8c82f81b7b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +import org.mapstruct.Mapper; + +@Mapper +public interface EmptyTargetMapper { + + TargetWithNoSetters mapToTargetWithSetters(Source source); + + EmptyTarget mapToEmptyTarget(Source source); + + Target mapToTarget(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetTest.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetTest.java new file mode 100644 index 0000000000..66fa65b796 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/EmptyTargetTest.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +@IssueKey("1140") +@WithClasses({ + EmptyTarget.class, + EmptyTargetMapper.class, + Source.class, + Target.class, + TargetWithNoSetters.class, +}) +class EmptyTargetTest { + + @ProcessorTest + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = EmptyTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 13, + message = "No target property found for target \"TargetWithNoSetters\"."), + @Diagnostic(type = EmptyTargetMapper.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 15, + message = "No target property found for target \"EmptyTarget\".") + }) + void shouldProvideWarnings() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Source.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Source.java new file mode 100644 index 0000000000..643cdccf3a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Source.java @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +public class Source { + private String label; + private double weight; + private Object content; + + public Object getContent() { + return content; + } + + public void setContent(Object content) { + this.content = content; + } + + public double getWeight() { + return weight; + } + + public void setWeight(double weight) { + this.weight = weight; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Target.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Target.java new file mode 100644 index 0000000000..488a1fa8a6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/Target.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private final String label; + private final double weight; + private final Object content; + + public Target(String label, double weight, Object content) { + this.label = label; + this.weight = weight; + this.content = content; + } + + public String getLabel() { + return label; + } + + public double getWeight() { + return weight; + } + + public Object getContent() { + return content; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/emptytarget/TargetWithNoSetters.java b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/TargetWithNoSetters.java new file mode 100644 index 0000000000..edeb80f0d5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/emptytarget/TargetWithNoSetters.java @@ -0,0 +1,15 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.emptytarget; + +public class TargetWithNoSetters { + private int flightNumber; + private String airplaneName; + + public String getAirplaneName() { + return airplaneName; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java index 1380ca400a..845544ba9f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/imports/SourceTargetMapper.java @@ -25,7 +25,7 @@ public interface SourceTargetMapper { ParseException sourceToTarget(Named source); //custom types - Map listToMap(List list); + Value listToMap(List list); java.util.List namedsToExceptions(java.util.List source); @@ -36,4 +36,12 @@ public interface SourceTargetMapper { java.util.Map stringsToDates(java.util.Map stringDates); Target sourceToTarget(Source target); + + class Value { + private T value; + + public Value(List list) { + + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java index bb8434fd63..063a5e5615 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Idea.java @@ -11,4 +11,13 @@ */ public class Idea { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java index 8c55ebc273..7aa366ec95 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java +++ b/processor/src/test/java/org/mapstruct/ap/test/java8stream/wildcard/Plan.java @@ -11,4 +11,13 @@ */ public class Plan { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java index 659867ca40..1196d773cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/ErroneousSourceTargetMapper.java @@ -8,14 +8,24 @@ import org.mapstruct.BeanMapping; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; -import org.mapstruct.factory.Mappers; @Mapper( unmappedTargetPolicy = ReportingPolicy.IGNORE, unmappedSourcePolicy = ReportingPolicy.IGNORE) public interface ErroneousSourceTargetMapper { - ErroneousSourceTargetMapper INSTANCE = Mappers.getMapper( ErroneousSourceTargetMapper.class ); @BeanMapping(ignoreUnmappedSourceProperties = "bar") - Object sourceToTarget(Object source); + Target map(Target source); + + class Target { + private final String value; + + public Target(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java index 77f80c5537..5794126604 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/missingignoredsource/MissingIgnoredSourceTest.java @@ -22,7 +22,7 @@ public class MissingIgnoredSourceTest { diagnostics = { @Diagnostic(type = ErroneousSourceTargetMapper.class, kind = Kind.ERROR, - line = 20, + line = 18, message = "Ignored unknown source property: \"bar\".") } ) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java index 2ea183bfc9..5ea0a54cb2 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/methodgenerics/objectfactory/ObjectFactoryMapper.java @@ -7,10 +7,11 @@ import org.mapstruct.Mapper; import org.mapstruct.ObjectFactory; +import org.mapstruct.ReportingPolicy; import org.mapstruct.TargetType; import org.mapstruct.factory.Mappers; -@Mapper +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface ObjectFactoryMapper { ObjectFactoryMapper INSTANCE = Mappers.getMapper( ObjectFactoryMapper.class ); @@ -44,6 +45,16 @@ public boolean isA() { } abstract class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } } class TargetA extends Target { diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java index 7f9f19a2ab..295b4e2871 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentSource.java @@ -7,4 +7,13 @@ public abstract class AbstractParentSource { + private String parentValue; + + public String getParentValue() { + return parentValue; + } + + public void setParentValue(String parentValue) { + this.parentValue = parentValue; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java index 3215aee644..a95f58b260 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/AbstractParentTarget.java @@ -7,4 +7,13 @@ public abstract class AbstractParentTarget { + private String parentValue; + + public String getParentValue() { + return parentValue; + } + + public void setParentValue(String parentValue) { + this.parentValue = parentValue; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java index 94dde481b0..a047ee2573 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentSource.java @@ -7,4 +7,13 @@ public class ImplementedParentSource extends AbstractParentSource { + private String implementedParentValue; + + public String getImplementedParentValue() { + return implementedParentValue; + } + + public void setImplementedParentValue(String implementedParentValue) { + this.implementedParentValue = implementedParentValue; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java index 7f3d254e21..a187a87091 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/fixture/ImplementedParentTarget.java @@ -7,4 +7,13 @@ public class ImplementedParentTarget extends AbstractParentTarget { + private String implementedParentValue; + + public String getImplementedParentValue() { + return implementedParentValue; + } + + public void setImplementedParentValue(String implementedParentValue) { + this.implementedParentValue = implementedParentValue; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java index 3bcea83364..f40525538c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SimpleMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.versioninfo; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.WithProperties; /** * @author Andreas Gudian @@ -13,5 +14,5 @@ */ @Mapper public interface SimpleMapper { - Object toObject(Object object); + WithProperties toObject(WithProperties object); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java index 02a7b467b1..c3f9d39d26 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapper.java @@ -6,11 +6,12 @@ package org.mapstruct.ap.test.versioninfo; import org.mapstruct.Mapper; +import org.mapstruct.ap.test.WithProperties; /** * @author Filip Hrisafov */ @Mapper(suppressTimestampInGenerated = true) public interface SuppressTimestampViaMapper { - Object toObject(Object object); + WithProperties toObject(WithProperties object); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java index a471cad028..54dc6b2fb7 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/SuppressTimestampViaMapperConfig.java @@ -7,13 +7,14 @@ import org.mapstruct.Mapper; import org.mapstruct.MapperConfig; +import org.mapstruct.ap.test.WithProperties; /** * @author Filip Hrisafov */ @Mapper(config = SuppressTimestampViaMapperConfig.Config.class) public interface SuppressTimestampViaMapperConfig { - Object toObject(Object object); + WithProperties toObject(WithProperties object); @MapperConfig(suppressTimestampInGenerated = true) interface Config { diff --git a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java index f3192b85ad..60781c399f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/versioninfo/VersionInfoTest.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.versioninfo; import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.WithProperties; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -18,7 +19,7 @@ * */ @IssueKey( "424" ) -@WithClasses( SimpleMapper.class ) +@WithClasses( { SimpleMapper.class, WithProperties.class } ) public class VersionInfoTest { @RegisterExtension final GeneratedSource generatedSource = new GeneratedSource(); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java index a66b646f1e..b5dd2893c8 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassAbstractMapperImpl.java @@ -58,6 +58,8 @@ protected SubTarget subSourceToSubTarget(SubSource subSource) { SubTarget subTarget = new SubTarget(); + subTarget.setParentValue( subSource.getParentValue() ); + subTarget.setImplementedParentValue( subSource.getImplementedParentValue() ); subTarget.setValue( subSource.getValue() ); return subTarget; @@ -74,6 +76,9 @@ protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSource SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + subTargetOther.setParentValue( subSourceOther.getParentValue() ); + subTargetOther.setImplementedParentValue( subSourceOther.getImplementedParentValue() ); + return subTargetOther; } @@ -88,6 +93,9 @@ protected SubSourceSeparate subTargetSeparateToSubSourceSeparate(SubTargetSepara SubSourceSeparate subSourceSeparate = new SubSourceSeparate( separateValue ); + subSourceSeparate.setParentValue( subTargetSeparate.getParentValue() ); + subSourceSeparate.setImplementedParentValue( subTargetSeparate.getImplementedParentValue() ); + return subSourceSeparate; } @@ -102,6 +110,9 @@ protected SubSourceOverride subTargetOtherToSubSourceOverride(SubTargetOther sub SubSourceOverride subSourceOverride = new SubSourceOverride( finalValue ); + subSourceOverride.setParentValue( subTargetOther.getParentValue() ); + subSourceOverride.setImplementedParentValue( subTargetOther.getImplementedParentValue() ); + return subSourceOverride; } @@ -112,6 +123,8 @@ protected SubSource subTargetToSubSource(SubTarget subTarget) { SubSource subSource = new SubSource(); + subSource.setParentValue( subTarget.getParentValue() ); + subSource.setImplementedParentValue( subTarget.getImplementedParentValue() ); subSource.setValue( subTarget.getValue() ); return subSource; diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java index 444b012078..695ef03577 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassImplementedMapperImpl.java @@ -29,6 +29,9 @@ else if (item instanceof SubSourceOther) { else { ImplementedParentTarget implementedParentTarget = new ImplementedParentTarget(); + implementedParentTarget.setParentValue( item.getParentValue() ); + implementedParentTarget.setImplementedParentValue( item.getImplementedParentValue() ); + return implementedParentTarget; } } @@ -40,6 +43,8 @@ protected SubTarget subSourceToSubTarget(SubSource subSource) { SubTarget subTarget = new SubTarget(); + subTarget.setParentValue( subSource.getParentValue() ); + subTarget.setImplementedParentValue( subSource.getImplementedParentValue() ); subTarget.setValue( subSource.getValue() ); return subTarget; @@ -56,6 +61,9 @@ protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSource SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + subTargetOther.setParentValue( subSourceOther.getParentValue() ); + subTargetOther.setImplementedParentValue( subSourceOther.getImplementedParentValue() ); + return subTargetOther; } } diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java index 8366d53ea9..782831d6e3 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/subclassmapping/fixture/SubclassInterfaceMapperImpl.java @@ -38,6 +38,8 @@ protected SubTarget subSourceToSubTarget(SubSource subSource) { SubTarget subTarget = new SubTarget(); + subTarget.setParentValue( subSource.getParentValue() ); + subTarget.setImplementedParentValue( subSource.getImplementedParentValue() ); subTarget.setValue( subSource.getValue() ); return subTarget; @@ -54,6 +56,9 @@ protected SubTargetOther subSourceOtherToSubTargetOther(SubSourceOther subSource SubTargetOther subTargetOther = new SubTargetOther( finalValue ); + subTargetOther.setParentValue( subSourceOther.getParentValue() ); + subTargetOther.setImplementedParentValue( subSourceOther.getImplementedParentValue() ); + return subTargetOther; } } From 2fb5776350abf59f09cf26c727eb16ebfffadbc3 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 11 May 2025 20:07:53 +0200 Subject: [PATCH 0891/1006] Add release notes for next version --- NEXT_RELEASE_CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index e0f4cd31f0..20cbc8c3f8 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,10 +1,26 @@ ### Features +* Support for Java 21 Sequenced Collections (#3240) + + ### Enhancements +* Add support for locale parameter for numberFormat and dateFormat (#3628) +* Behaviour change: Warning when the target has no target properties (#1140) + + + ### Bugs +* Improve error message when mapping non-iterable to array (#3786) + ### Documentation ### Build +### Behaviour Change + +#### Warning when the target has no target properties + +With this change, if the target bean does not have any target properties, a warning will be shown. +This is like this to avoid potential mistakes by users, where they might think that the target bean has properties, but it does not. From fce73aee6ab655f3896dee440fa890a1971a281f Mon Sep 17 00:00:00 2001 From: roelmang Date: Sun, 11 May 2025 21:58:47 +0200 Subject: [PATCH 0892/1006] #3729 Support for using inner class Builder without using static factory method --- NEXT_RELEASE_CHANGELOG.md | 3 + .../chapter-3-defining-a-mapper.asciidoc | 7 +- .../ap/spi/DefaultBuilderProvider.java | 98 +++++++++++++--- .../ErroneousSimpleBuilderMapper.java | 5 +- .../{ => innerclass}/SimpleBuilderMapper.java | 5 +- ...lderThroughInnerClassConstructorTest.java} | 15 +-- ...ImmutablePersonWithInnerClassBuilder.java} | 14 +-- .../ErroneousSimpleBuilderMapper.java | 23 ++++ .../SimpleBuilderMapper.java | 23 ++++ ...BuilderThroughStaticFactoryMethodTest.java | 61 ++++++++++ ...ePersonWithStaticFactoryMethodBuilder.java | 105 ++++++++++++++++++ 11 files changed, 321 insertions(+), 38 deletions(-) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{ => innerclass}/ErroneousSimpleBuilderMapper.java (72%) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{ => innerclass}/SimpleBuilderMapper.java (74%) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{SimpleImmutableBuilderTest.java => innerclass/SimpleImmutableBuilderThroughInnerClassConstructorTest.java} (78%) rename processor/src/test/java/org/mapstruct/ap/test/builder/simple/{SimpleImmutablePerson.java => innerclass/SimpleImmutablePersonWithInnerClassBuilder.java} (86%) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/ErroneousSimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutableBuilderThroughStaticFactoryMethodTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutablePersonWithStaticFactoryMethodBuilder.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 20cbc8c3f8..2d0555cb24 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -6,6 +6,9 @@ ### Enhancements * Add support for locale parameter for numberFormat and dateFormat (#3628) +* Detect Builder without a factory method (#3729) - With this if there is an inner class that ends with `Builder` and has a constructor with parameters, +it will be treated as a potential builder. +Builders through static methods on the type have a precedence. * Behaviour change: Warning when the target has no target properties (#1140) diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index ea574603ea..81980a35ac 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -421,8 +421,11 @@ If a Builder exists for a certain type, then that builder will be used for the m The default implementation of the `BuilderProvider` assumes the following: -* The type has a parameterless public static builder creation method that returns a builder. -So for example `Person` has a public static method that returns `PersonBuilder`. +* The type has either +** A parameterless public static builder creation method that returns a builder. +e.g. `Person` has a public static method that returns `PersonBuilder`. +** A public static inner class with the name having the suffix "Builder", and a public no-args constructor +e.g. `Person` has an inner class `PersonBuilder` with a public no-args constructor. * The builder type has a parameterless public method (build method) that returns the type being built. In our example `PersonBuilder` has a method returning `Person`. * In case there are multiple build methods, MapStruct will look for a method called `build`, if such method exists diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 92cd1ed80d..afcee7d247 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -10,6 +10,8 @@ import java.util.Collections; import java.util.List; import java.util.regex.Pattern; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; @@ -184,32 +186,96 @@ protected BuilderInfo findBuilderInfo(TypeElement typeElement, boolean checkPare return null; } - List methods = ElementFilter.methodsIn( typeElement.getEnclosedElements() ); - List builderInfo = new ArrayList<>(); - for ( ExecutableElement method : methods ) { - if ( isPossibleBuilderCreationMethod( method, typeElement ) ) { - TypeElement builderElement = getTypeElement( method.getReturnType() ); - Collection buildMethods = findBuildMethods( builderElement, typeElement ); - if ( !buildMethods.isEmpty() ) { - builderInfo.add( new BuilderInfo.Builder() - .builderCreationMethod( method ) - .buildMethod( buildMethods ) - .build() - ); + // Builder infos which are determined by a static method on the type itself + List methodBuilderInfos = new ArrayList<>(); + // Builder infos which are determined by an inner builder class in the type itself + List innerClassBuilderInfos = new ArrayList<>(); + + for ( Element enclosedElement : typeElement.getEnclosedElements() ) { + if ( ElementKind.METHOD == enclosedElement.getKind() ) { + ExecutableElement method = (ExecutableElement) enclosedElement; + BuilderInfo builderInfo = determineMethodBuilderInfo( method, typeElement ); + if ( builderInfo != null ) { + methodBuilderInfos.add( builderInfo ); } } + else if ( ElementKind.CLASS == enclosedElement.getKind() ) { + if ( !methodBuilderInfos.isEmpty() ) { + // Small optimization to not check the inner classes + // if we already have at least one builder through a method + continue; + } + TypeElement classElement = (TypeElement) enclosedElement; + BuilderInfo builderInfo = determineInnerClassBuilderInfo( classElement, typeElement ); + if ( builderInfo != null ) { + innerClassBuilderInfos.add( builderInfo ); + } + } + } - if ( builderInfo.size() == 1 ) { - return builderInfo.get( 0 ); + if ( methodBuilderInfos.size() == 1 ) { + return methodBuilderInfos.get( 0 ); + } + else if ( methodBuilderInfos.size() > 1 ) { + throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), methodBuilderInfos ); } - else if ( builderInfo.size() > 1 ) { - throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), builderInfo ); + else if ( innerClassBuilderInfos.size() == 1 ) { + return innerClassBuilderInfos.get( 0 ); + } + else if ( innerClassBuilderInfos.size() > 1 ) { + throw new MoreThanOneBuilderCreationMethodException( typeElement.asType(), innerClassBuilderInfos ); } if ( checkParent ) { return findBuilderInfo( typeElement.getSuperclass() ); } + + return null; + } + + private BuilderInfo determineMethodBuilderInfo(ExecutableElement method, + TypeElement typeElement) { + if ( isPossibleBuilderCreationMethod( method, typeElement ) ) { + TypeElement builderElement = getTypeElement( method.getReturnType() ); + Collection buildMethods = findBuildMethods( builderElement, typeElement ); + if ( !buildMethods.isEmpty() ) { + return new BuilderInfo.Builder() + .builderCreationMethod( method ) + .buildMethod( buildMethods ) + .build(); + } + } + + return null; + } + + private BuilderInfo determineInnerClassBuilderInfo(TypeElement innerClassElement, + TypeElement typeElement) { + if ( innerClassElement.getModifiers().contains( Modifier.PUBLIC ) + && innerClassElement.getModifiers().contains( Modifier.STATIC ) + && innerClassElement.getSimpleName().toString().endsWith( "Builder" ) ) { + for ( Element element : innerClassElement.getEnclosedElements() ) { + if ( ElementKind.CONSTRUCTOR == element.getKind() ) { + ExecutableElement constructor = (ExecutableElement) element; + if ( constructor.getParameters().isEmpty() ) { + // We have a no-arg constructor + // Now check if we have build methods + Collection buildMethods = findBuildMethods( innerClassElement, typeElement ); + if ( !buildMethods.isEmpty() ) { + return new BuilderInfo.Builder() + .builderCreationMethod( constructor ) + .buildMethod( buildMethods ) + .build(); + } + // If we don't have any build methods + // then we can stop since we are only interested in the no-arg constructor + return null; + } + } + } + } + return null; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/ErroneousSimpleBuilderMapper.java similarity index 72% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/ErroneousSimpleBuilderMapper.java index 305ae77e80..18e82ed19c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/ErroneousSimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/ErroneousSimpleBuilderMapper.java @@ -3,12 +3,13 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.builder.simple; +package org.mapstruct.ap.test.builder.simple.innerclass; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; @Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) public interface ErroneousSimpleBuilderMapper { @@ -18,5 +19,5 @@ public interface ErroneousSimpleBuilderMapper { @Mapping(target = "job", ignore = true ), @Mapping(target = "city", ignore = true ) }) - SimpleImmutablePerson toImmutable(SimpleMutablePerson source); + SimpleImmutablePersonWithInnerClassBuilder toImmutable(SimpleMutablePerson source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleBuilderMapper.java similarity index 74% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleBuilderMapper.java index 0b0e961b30..e2c673401a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleBuilderMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleBuilderMapper.java @@ -3,12 +3,13 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.builder.simple; +package org.mapstruct.ap.test.builder.simple.innerclass; import org.mapstruct.CollectionMappingStrategy; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; @Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) public interface SimpleBuilderMapper { @@ -18,5 +19,5 @@ public interface SimpleBuilderMapper { @Mapping(target = "job", constant = "programmer"), @Mapping(target = "city", expression = "java(\"Bengalore\")") }) - SimpleImmutablePerson toImmutable(SimpleMutablePerson source); + SimpleImmutablePersonWithInnerClassBuilder toImmutable(SimpleMutablePerson source); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutableBuilderThroughInnerClassConstructorTest.java similarity index 78% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutableBuilderThroughInnerClassConstructorTest.java index 7f77621644..0a2c5287bc 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutableBuilderTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutableBuilderThroughInnerClassConstructorTest.java @@ -3,11 +3,12 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.builder.simple; +package org.mapstruct.ap.test.builder.simple.innerclass; import java.util.Arrays; import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -20,16 +21,16 @@ @WithClasses({ SimpleMutablePerson.class, - SimpleImmutablePerson.class + SimpleImmutablePersonWithInnerClassBuilder.class }) -public class SimpleImmutableBuilderTest { +public class SimpleImmutableBuilderThroughInnerClassConstructorTest { @RegisterExtension final GeneratedSource generatedSource = new GeneratedSource(); @ProcessorTest @WithClasses({ SimpleBuilderMapper.class }) - public void testSimpleImmutableBuilderHappyPath() { + public void testSimpleImmutableBuilderThroughInnerClassConstructorHappyPath() { SimpleBuilderMapper mapper = Mappers.getMapper( SimpleBuilderMapper.class ); SimpleMutablePerson source = new SimpleMutablePerson(); source.setAge( 3 ); @@ -37,7 +38,7 @@ public void testSimpleImmutableBuilderHappyPath() { source.setChildren( Arrays.asList( "Alice", "Tom" ) ); source.setAddress( "Plaza 1" ); - SimpleImmutablePerson targetObject = mapper.toImmutable( source ); + SimpleImmutablePersonWithInnerClassBuilder targetObject = mapper.toImmutable( source ); assertThat( targetObject.getAge() ).isEqualTo( 3 ); assertThat( targetObject.getName() ).isEqualTo( "Bob" ); @@ -53,8 +54,8 @@ public void testSimpleImmutableBuilderHappyPath() { diagnostics = @Diagnostic( kind = javax.tools.Diagnostic.Kind.ERROR, type = ErroneousSimpleBuilderMapper.class, - line = 21, + line = 22, message = "Unmapped target property: \"name\".")) - public void testSimpleImmutableBuilderMissingPropertyFailsToCompile() { + public void testSimpleImmutableBuilderThroughInnerClassConstructorMissingPropertyFailsToCompile() { } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutablePersonWithInnerClassBuilder.java similarity index 86% rename from processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java rename to processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutablePersonWithInnerClassBuilder.java index 2fe2c8ded2..a9bda42d33 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/SimpleImmutablePerson.java +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/innerclass/SimpleImmutablePersonWithInnerClassBuilder.java @@ -3,12 +3,12 @@ * * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -package org.mapstruct.ap.test.builder.simple; +package org.mapstruct.ap.test.builder.simple.innerclass; import java.util.ArrayList; import java.util.List; -public class SimpleImmutablePerson { +public class SimpleImmutablePersonWithInnerClassBuilder { private final String name; private final int age; private final String job; @@ -16,7 +16,7 @@ public class SimpleImmutablePerson { private final String address; private final List children; - SimpleImmutablePerson(Builder builder) { + SimpleImmutablePersonWithInnerClassBuilder(Builder builder) { this.name = builder.name; this.age = builder.age; this.job = builder.job; @@ -25,10 +25,6 @@ public class SimpleImmutablePerson { this.children = new ArrayList<>(builder.children); } - public static Builder builder() { - return new Builder(); - } - public int getAge() { return age; } @@ -66,8 +62,8 @@ public Builder age(int age) { return this; } - public SimpleImmutablePerson build() { - return new SimpleImmutablePerson( this ); + public SimpleImmutablePersonWithInnerClassBuilder build() { + return new SimpleImmutablePersonWithInnerClassBuilder( this ); } public Builder name(String name) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/ErroneousSimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/ErroneousSimpleBuilderMapper.java new file mode 100644 index 0000000000..6fc51ace3d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/ErroneousSimpleBuilderMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.simple.staticfactorymethod; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; + +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface ErroneousSimpleBuilderMapper { + + @Mappings({ + @Mapping(target = "address", ignore = true ), + @Mapping(target = "job", ignore = true ), + @Mapping(target = "city", ignore = true ) + }) + SimpleImmutablePersonWithStaticFactoryMethodBuilder toImmutable(SimpleMutablePerson source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleBuilderMapper.java new file mode 100644 index 0000000000..4bd200bc7c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleBuilderMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.simple.staticfactorymethod; + +import org.mapstruct.CollectionMappingStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; + +@Mapper(collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) +public interface SimpleBuilderMapper { + + @Mappings({ + @Mapping(target = "name", source = "fullName"), + @Mapping(target = "job", constant = "programmer"), + @Mapping(target = "city", expression = "java(\"Bengalore\")") + }) + SimpleImmutablePersonWithStaticFactoryMethodBuilder toImmutable(SimpleMutablePerson source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutableBuilderThroughStaticFactoryMethodTest.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutableBuilderThroughStaticFactoryMethodTest.java new file mode 100644 index 0000000000..90fac6061e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutableBuilderThroughStaticFactoryMethodTest.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.simple.staticfactorymethod; + +import java.util.Arrays; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.builder.simple.SimpleMutablePerson; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.mapstruct.factory.Mappers; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + SimpleMutablePerson.class, + SimpleImmutablePersonWithStaticFactoryMethodBuilder.class +}) +public class SimpleImmutableBuilderThroughStaticFactoryMethodTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + @WithClasses({ SimpleBuilderMapper.class }) + public void testSimpleImmutableBuilderThroughStaticFactoryMethodHappyPath() { + SimpleBuilderMapper mapper = Mappers.getMapper( SimpleBuilderMapper.class ); + SimpleMutablePerson source = new SimpleMutablePerson(); + source.setAge( 3 ); + source.setFullName( "Bob" ); + source.setChildren( Arrays.asList( "Alice", "Tom" ) ); + source.setAddress( "Plaza 1" ); + + SimpleImmutablePersonWithStaticFactoryMethodBuilder targetObject = mapper.toImmutable( source ); + + assertThat( targetObject.getAge() ).isEqualTo( 3 ); + assertThat( targetObject.getName() ).isEqualTo( "Bob" ); + assertThat( targetObject.getJob() ).isEqualTo( "programmer" ); + assertThat( targetObject.getCity() ).isEqualTo( "Bengalore" ); + assertThat( targetObject.getAddress() ).isEqualTo( "Plaza 1" ); + assertThat( targetObject.getChildren() ).contains( "Alice", "Tom" ); + } + + @ProcessorTest + @WithClasses({ ErroneousSimpleBuilderMapper.class }) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = ErroneousSimpleBuilderMapper.class, + line = 22, + message = "Unmapped target property: \"name\".")) + public void testSimpleImmutableBuilderThroughStaticFactoryMethodMissingPropertyFailsToCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutablePersonWithStaticFactoryMethodBuilder.java b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutablePersonWithStaticFactoryMethodBuilder.java new file mode 100644 index 0000000000..c3dc590210 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/builder/simple/staticfactorymethod/SimpleImmutablePersonWithStaticFactoryMethodBuilder.java @@ -0,0 +1,105 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.builder.simple.staticfactorymethod; + +import java.util.ArrayList; +import java.util.List; + +public class SimpleImmutablePersonWithStaticFactoryMethodBuilder { + private final String name; + private final int age; + private final String job; + private final String city; + private final String address; + private final List children; + + SimpleImmutablePersonWithStaticFactoryMethodBuilder(Builder builder) { + this.name = builder.name; + this.age = builder.age; + this.job = builder.job; + this.city = builder.city; + this.address = builder.address; + this.children = new ArrayList<>( builder.children ); + } + + public static Builder builder() { + return new Builder(); + } + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + + public String getJob() { + return job; + } + + public String getCity() { + return city; + } + + public String getAddress() { + return address; + } + + public List getChildren() { + return children; + } + + public static class Builder { + private String name; + private int age; + private String job; + private String city; + private String address; + private List children = new ArrayList<>(); + + private Builder() { + } + + public Builder age(int age) { + this.age = age; + return this; + } + + public SimpleImmutablePersonWithStaticFactoryMethodBuilder build() { + return new SimpleImmutablePersonWithStaticFactoryMethodBuilder( this ); + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder job(String job) { + this.job = job; + return this; + } + + public Builder city(String city) { + this.city = city; + return this; + } + + public Builder address(String address) { + this.address = address; + return this; + } + + public List getChildren() { + throw new UnsupportedOperationException( "This is just a marker method" ); + } + + public Builder addChild(String child) { + this.children.add( child ); + return this; + } + } +} From 6e6fd01a2eb08177d5cc360a97e1721db511239d Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sun, 18 May 2025 00:40:51 +0800 Subject: [PATCH 0893/1006] #3821: Add support for custom exception for subclass exhaustive strategy for `@SubclassMapping` --------- Signed-off-by: TangYang --- .../main/java/org/mapstruct/BeanMapping.java | 12 +++ core/src/main/java/org/mapstruct/Mapper.java | 12 +++ .../main/java/org/mapstruct/MapperConfig.java | 12 +++ .../ap/internal/model/BeanMappingMethod.java | 17 ++++- .../model/source/BeanMappingOptions.java | 9 +++ .../internal/model/source/DefaultOptions.java | 4 + .../model/source/DelegatingOptions.java | 4 + .../model/source/MapperConfigOptions.java | 6 ++ .../internal/model/source/MapperOptions.java | 7 ++ .../ap/internal/model/BeanMappingMethod.ftl | 2 +- .../CustomExceptionSubclassMapper.java | 25 ++++++ .../CustomSubclassMappingException.java | 12 +++ .../CustomSubclassMappingExceptionTest.java | 76 +++++++++++++++++++ .../MapperConfigSubclassMapper.java | 29 +++++++ .../MapperSubclassMapper.java | 24 ++++++ 15 files changed, 248 insertions(+), 3 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomExceptionSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingException.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingExceptionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperConfigSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperSubclassMapper.java diff --git a/core/src/main/java/org/mapstruct/BeanMapping.java b/core/src/main/java/org/mapstruct/BeanMapping.java index e94ff98f2d..309458f861 100644 --- a/core/src/main/java/org/mapstruct/BeanMapping.java +++ b/core/src/main/java/org/mapstruct/BeanMapping.java @@ -132,6 +132,18 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() */ SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR; + /** + * Specifies the exception type to be thrown when a missing subclass implementation is detected + * in combination with {@link SubclassMappings}, based on the {@link #subclassExhaustiveStrategy()}. + *

      + * This exception will only be thrown when the {@code subclassExhaustiveStrategy} is set to + * {@link SubclassExhaustiveStrategy#RUNTIME_EXCEPTION}. + * + * @return the exception class to throw when missing implementations are found. + * Defaults to {@link IllegalArgumentException}. + */ + Class subclassExhaustiveException() default IllegalArgumentException.class; + /** * Default ignore all mappings. All mappings have to be defined manually. No automatic mapping will take place. No * warning will be issued on missing source or target properties. diff --git a/core/src/main/java/org/mapstruct/Mapper.java b/core/src/main/java/org/mapstruct/Mapper.java index 8a6f48dad9..398dc1870a 100644 --- a/core/src/main/java/org/mapstruct/Mapper.java +++ b/core/src/main/java/org/mapstruct/Mapper.java @@ -281,6 +281,18 @@ NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy() default */ SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR; + /** + * Specifies the exception type to be thrown when a missing subclass implementation is detected + * in combination with {@link SubclassMappings}, based on the {@link #subclassExhaustiveStrategy()}. + *

      + * This exception will only be thrown when the {@code subclassExhaustiveStrategy} is set to + * {@link SubclassExhaustiveStrategy#RUNTIME_EXCEPTION}. + * + * @return the exception class to throw when missing implementations are found. + * Defaults to {@link IllegalArgumentException}. + */ + Class subclassExhaustiveException() default IllegalArgumentException.class; + /** * Determines whether to use field or constructor injection. This is only used on annotated based component models * such as CDI, Spring and JSR 330. diff --git a/core/src/main/java/org/mapstruct/MapperConfig.java b/core/src/main/java/org/mapstruct/MapperConfig.java index 915f3dd120..8631562a56 100644 --- a/core/src/main/java/org/mapstruct/MapperConfig.java +++ b/core/src/main/java/org/mapstruct/MapperConfig.java @@ -249,6 +249,18 @@ MappingInheritanceStrategy mappingInheritanceStrategy() */ SubclassExhaustiveStrategy subclassExhaustiveStrategy() default COMPILE_ERROR; + /** + * Specifies the exception type to be thrown when a missing subclass implementation is detected + * in combination with {@link SubclassMappings}, based on the {@link #subclassExhaustiveStrategy()}. + *

      + * This exception will only be thrown when the {@code subclassExhaustiveStrategy} is set to + * {@link SubclassExhaustiveStrategy#RUNTIME_EXCEPTION}. + * + * @return the exception class to throw when missing implementations are found. + * Defaults to {@link IllegalArgumentException}. + */ + Class subclassExhaustiveException() default IllegalArgumentException.class; + /** * Determines whether to use field or constructor injection. This is only used on annotated based component models * such as CDI, Spring and JSR 330. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 08c8ceda59..34c1ea3ccb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -100,6 +100,7 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final String finalizedResultName; private final List beforeMappingReferencesWithFinalizedReturnType; private final List afterMappingReferencesWithFinalizedReturnType; + private final Type subclassExhaustiveException; private final MappingReferences mappingReferences; @@ -378,6 +379,11 @@ else if ( !method.isUpdateMethod() ) { } + TypeMirror subclassExhaustiveException = method.getOptions() + .getBeanMapping() + .getSubclassExhaustiveException(); + Type subclassExhaustiveExceptionType = ctx.getTypeFactory().getType( subclassExhaustiveException ); + List subclasses = new ArrayList<>(); for ( SubclassMappingOptions subclassMappingOptions : method.getOptions().getSubclassMappings() ) { subclasses.add( createSubclassMapping( subclassMappingOptions ) ); @@ -451,7 +457,8 @@ else if ( !sourceParameter.getType().isPrimitive() ) { finalizeMethod, mappingReferences, subclasses, - presenceChecksByParameter + presenceChecksByParameter, + subclassExhaustiveExceptionType ); } @@ -1954,7 +1961,8 @@ private BeanMappingMethod(Method method, MethodReference finalizerMethod, MappingReferences mappingReferences, List subclassMappings, - Map presenceChecksByParameter) { + Map presenceChecksByParameter, + Type subclassExhaustiveException) { super( method, annotations, @@ -1969,6 +1977,7 @@ private BeanMappingMethod(Method method, this.propertyMappings = propertyMappings; this.returnTypeBuilder = returnTypeBuilder; this.finalizerMethod = finalizerMethod; + this.subclassExhaustiveException = subclassExhaustiveException; if ( this.finalizerMethod != null ) { this.finalizedResultName = Strings.getSafeVariableName( getResultName() + "Result", existingVariableNames ); @@ -2017,6 +2026,10 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { this.subclassMappings = subclassMappings; } + public Type getSubclassExhaustiveException() { + return subclassExhaustiveException; + } + public List getConstantMappings() { return constantMappings; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java index ac27dfff00..73a4d7c12d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/BeanMappingOptions.java @@ -11,6 +11,7 @@ import java.util.Optional; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.gem.BuilderGem; @@ -182,6 +183,14 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { .orElse( next().getSubclassExhaustiveStrategy() ); } + @Override + public TypeMirror getSubclassExhaustiveException() { + return Optional.ofNullable( beanMapping ).map( BeanMappingGem::subclassExhaustiveException ) + .filter( GemValue::hasValue ) + .map( GemValue::getValue ) + .orElse( next().getSubclassExhaustiveException() ); + } + @Override public ReportingPolicyGem unmappedTargetPolicy() { return Optional.ofNullable( beanMapping ).map( BeanMappingGem::unmappedTargetPolicy ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index c754d3c395..e1f04fd941 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -131,6 +131,10 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { return SubclassExhaustiveStrategyGem.valueOf( mapper.subclassExhaustiveStrategy().getDefaultValue() ); } + public TypeMirror getSubclassExhaustiveException() { + return mapper.subclassExhaustiveException().getDefaultValue(); + } + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { NullValueMappingStrategyGem nullValueIterableMappingStrategy = options.getNullValueIterableMappingStrategy(); if ( nullValueIterableMappingStrategy != null ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java index 50c1d84541..34478969fa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DelegatingOptions.java @@ -106,6 +106,10 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { return next.getSubclassExhaustiveStrategy(); } + public TypeMirror getSubclassExhaustiveException() { + return next.getSubclassExhaustiveException(); + } + public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { return next.getNullValueIterableMappingStrategy(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index e3ca6162a5..d606658878 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -141,6 +141,12 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { next().getSubclassExhaustiveStrategy(); } + public TypeMirror getSubclassExhaustiveException() { + return mapperConfig.subclassExhaustiveException().hasValue() ? + mapperConfig.subclassExhaustiveException().get() : + next().getSubclassExhaustiveException(); + } + @Override public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { if ( mapperConfig.nullValueIterableMappingStrategy().hasValue() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index ed1af34f79..9c2203efd5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -170,6 +170,13 @@ public SubclassExhaustiveStrategyGem getSubclassExhaustiveStrategy() { next().getSubclassExhaustiveStrategy(); } + @Override + public TypeMirror getSubclassExhaustiveException() { + return mapper.subclassExhaustiveException().hasValue() ? + mapper.subclassExhaustiveException().get() : + next().getSubclassExhaustiveException(); + } + @Override public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { if ( mapper.nullValueIterableMappingStrategy().hasValue() ) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 3036e4a2c8..da590bb506 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -42,7 +42,7 @@ else { <#if isAbstractReturnType()> - throw new IllegalArgumentException("Not all subclasses are supported for this mapping. Missing for " + ${subclassMappings[0].sourceArgument}.getClass()); + throw new <@includeModel object=subclassExhaustiveException />("Not all subclasses are supported for this mapping. Missing for " + ${subclassMappings[0].sourceArgument}.getClass()); <#else> <#if !existingInstanceMapping> <#if hasConstructorMappings()> diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomExceptionSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomExceptionSubclassMapper.java new file mode 100644 index 0000000000..52738ef6f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomExceptionSubclassMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface CustomExceptionSubclassMapper { + CustomExceptionSubclassMapper INSTANCE = Mappers.getMapper( CustomExceptionSubclassMapper.class ); + + @BeanMapping(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION, + subclassExhaustiveException = CustomSubclassMappingException.class) + @SubclassMapping(source = Car.class, target = CarDto.class) + @SubclassMapping(source = Bike.class, target = BikeDto.class) + VehicleDto map(AbstractVehicle vehicle); + + VehicleCollectionDto mapInverse(VehicleCollection vehicles); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingException.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingException.java new file mode 100644 index 0000000000..abb675bbb4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingException.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +public class CustomSubclassMappingException extends RuntimeException { + public CustomSubclassMappingException(String message) { + super( message ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingExceptionTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingExceptionTest.java new file mode 100644 index 0000000000..472c007269 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/CustomSubclassMappingExceptionTest.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@IssueKey("3821") +@WithClasses({ + Bike.class, + BikeDto.class, + Car.class, + CarDto.class, + Motorcycle.class, + VehicleCollection.class, + VehicleCollectionDto.class, + AbstractVehicle.class, + VehicleDto.class, + CustomSubclassMappingException.class, + CustomExceptionSubclassMapper.class +}) +public class CustomSubclassMappingExceptionTest { + + private static final String EXPECTED_ERROR_MESSAGE = "Not all subclasses are supported for this mapping. " + + "Missing for class org.mapstruct.ap.test.subclassmapping.abstractsuperclass.Motorcycle"; + + @ProcessorTest + void customExceptionIsThrownForUnknownSubclass() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Motorcycle() ); // undefine subclass + + assertThatThrownBy( () -> CustomExceptionSubclassMapper.INSTANCE.mapInverse( vehicles ) ) + .isInstanceOf( CustomSubclassMappingException.class ) + .hasMessage( EXPECTED_ERROR_MESSAGE ); + } + + @ProcessorTest + void customExceptionIsThrownForSingleVehicle() { + AbstractVehicle vehicle = new Motorcycle(); // undefine subclass + + assertThatThrownBy( () -> CustomExceptionSubclassMapper.INSTANCE.map( vehicle ) ) + .isInstanceOf( CustomSubclassMappingException.class ) + .hasMessage( EXPECTED_ERROR_MESSAGE ); + } + + @ProcessorTest + @WithClasses({ MapperConfigSubclassMapper.class }) + void customExceptionIsThrownForMapperConfig() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Motorcycle() ); // undefined subclass + + assertThatThrownBy( () -> MapperConfigSubclassMapper.INSTANCE.mapInverse( vehicles ) ) + .isInstanceOf( CustomSubclassMappingException.class ) + .hasMessage( EXPECTED_ERROR_MESSAGE ); + } + + @ProcessorTest + @WithClasses({ MapperSubclassMapper.class }) + void customExceptionIsThrownForMapper() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Car() ); + vehicles.getVehicles().add( new Motorcycle() ); // undefined subclass + + assertThatThrownBy( () -> MapperSubclassMapper.INSTANCE.mapInverse( vehicles ) ) + .isInstanceOf( CustomSubclassMappingException.class ) + .hasMessage( EXPECTED_ERROR_MESSAGE ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperConfigSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperConfigSubclassMapper.java new file mode 100644 index 0000000000..b3c1a66bb6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperConfigSubclassMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.Mapper; +import org.mapstruct.MapperConfig; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper(config = MapperConfigSubclassMapper.Config.class) +public interface MapperConfigSubclassMapper { + + MapperConfigSubclassMapper INSTANCE = Mappers.getMapper( MapperConfigSubclassMapper.class ); + + @MapperConfig(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION, + subclassExhaustiveException = CustomSubclassMappingException.class) + interface Config { + } + + @SubclassMapping(source = Car.class, target = CarDto.class) + @SubclassMapping(source = Bike.class, target = BikeDto.class) + VehicleDto map(AbstractVehicle vehicle); + + VehicleCollectionDto mapInverse(VehicleCollection vehicles); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperSubclassMapper.java new file mode 100644 index 0000000000..34ed3fde22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/abstractsuperclass/MapperSubclassMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.abstractsuperclass; + +import org.mapstruct.Mapper; +import org.mapstruct.SubclassExhaustiveStrategy; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION, + subclassExhaustiveException = CustomSubclassMappingException.class) +public interface MapperSubclassMapper { + + MapperSubclassMapper INSTANCE = Mappers.getMapper( MapperSubclassMapper.class ); + + @SubclassMapping(source = Car.class, target = CarDto.class) + @SubclassMapping(source = Bike.class, target = BikeDto.class) + VehicleDto map(AbstractVehicle vehicle); + + VehicleCollectionDto mapInverse(VehicleCollection vehicles); +} From 05f27e96e2108344d69a2963b04ee973c83b0eb0 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Sun, 25 May 2025 14:58:23 +0200 Subject: [PATCH 0894/1006] #3852 Initialize Optionals with empty instead of null --- .../ap/internal/model/common/Type.java | 17 +++++ .../nullvalue/OptionalDefaultMapper.java | 20 ++++++ .../nullvalue/OptionalDefaultMapperTest.java | 53 ++++++++++++++++ .../nullvalue/SimpleConstructorMapper.java | 29 +++++++++ .../ap/test/optional/nullvalue/Source.java | 61 ++++++++++++++++++ .../ap/test/optional/nullvalue/Target.java | 63 +++++++++++++++++++ 6 files changed, 243 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapperTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/SimpleConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Target.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6520834066..d0f65ce97a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -17,6 +17,10 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.OptionalLong; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -367,6 +371,15 @@ public boolean isArrayType() { return componentType != null; } + private boolean isType(Class type) { + return type.getName().equals( getFullyQualifiedName() ); + } + + private boolean isOptionalType() { + return isType( Optional.class ) || isType( OptionalInt.class ) || isType( OptionalDouble.class ) || + isType( OptionalLong.class ); + } + public boolean isTypeVar() { return (typeMirror.getKind() == TypeKind.TYPEVAR); } @@ -1166,6 +1179,10 @@ else if ( !method.getModifiers().contains( Modifier.PUBLIC ) ) { * FTL. */ public String getNull() { + if ( isOptionalType() ) { + return createReferenceName() + ".empty()"; + } + if ( !isPrimitive() || isArrayType() ) { return "null"; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapper.java new file mode 100644 index 0000000000..7397c2ccd1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nullvalue; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Dennis Melzer + */ +@Mapper +public interface OptionalDefaultMapper { + + OptionalDefaultMapper INSTANCE = Mappers.getMapper( OptionalDefaultMapper.class ); + + Target map(Source source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapperTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapperTest.java new file mode 100644 index 0000000000..78482831b9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/OptionalDefaultMapperTest.java @@ -0,0 +1,53 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nullvalue; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Dennis Melzer + */ +@WithClasses({ + OptionalDefaultMapper.class, + Source.class, + Target.class +}) +@IssueKey("3852") +public class OptionalDefaultMapperTest { + + @ProcessorTest + public void shouldOptionalNotNull() { + Source source = new Source( null, null, null, null, null, null, null ); + Target target = OptionalDefaultMapper.INSTANCE.map( source ); + + assertThat( target.getSomeString() ).isEmpty(); + assertThat( target.getSomeInteger() ).isEmpty(); + assertThat( target.getSomeDouble() ).isEmpty(); + assertThat( target.getSomeBoolean() ).isEmpty(); + assertThat( target.getSomeIntValue() ).isEmpty(); + assertThat( target.getSomeDoubleValue() ).isEmpty(); + assertThat( target.getSomeLongValue() ).isEmpty(); + } + + @ProcessorTest + public void shouldMapOptional() { + Source source = new Source( "someString", 10, 11D, Boolean.TRUE, 10, 100D, 200L ); + Target target = OptionalDefaultMapper.INSTANCE.map( source ); + + assertThat( target.getSomeString() ).contains( "someString" ); + assertThat( target.getSomeInteger() ).contains( 10 ); + assertThat( target.getSomeDouble() ).contains( 11D ); + assertThat( target.getSomeBoolean() ).contains( Boolean.TRUE ); + assertThat( target.getSomeIntValue() ).hasValue( 10 ); + assertThat( target.getSomeDoubleValue() ).hasValue( 100 ); + assertThat( target.getSomeLongValue() ).hasValue( 200 ); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/SimpleConstructorMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/SimpleConstructorMapper.java new file mode 100644 index 0000000000..158a01d3bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/SimpleConstructorMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nullvalue; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.Mapper; +import org.mapstruct.NullValueMappingStrategy; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.ap.test.nestedproperties.simple._target.TargetObject; +import org.mapstruct.ap.test.nestedproperties.simple.source.SourceRoot; +import org.mapstruct.factory.Mappers; + +/** + * @author Dennis Melzer + */ +@Mapper( + nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT, + injectionStrategy = InjectionStrategy.CONSTRUCTOR, unmappedTargetPolicy = ReportingPolicy.IGNORE +) +public interface SimpleConstructorMapper { + + SimpleConstructorMapper MAPPER = Mappers.getMapper( SimpleConstructorMapper.class ); + + TargetObject toTargetObject(SourceRoot sourceRoot); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Source.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Source.java new file mode 100644 index 0000000000..9746d4a152 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Source.java @@ -0,0 +1,61 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nullvalue; + +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.OptionalLong; + +public class Source { + + private final String someString; + private final Integer someInteger; + private final Double someDouble; + private final Boolean someBoolean; + private final Integer someIntValue; + private final Double someDoubleValue; + private final Long someLongValue; + + public Source(String someString, Integer someInteger, Double someDouble, Boolean someBoolean, Integer someIntValue, + Double someDoubleValue, Long someLongValue) { + this.someString = someString; + this.someInteger = someInteger; + this.someDouble = someDouble; + this.someBoolean = someBoolean; + this.someIntValue = someIntValue; + this.someDoubleValue = someDoubleValue; + this.someLongValue = someLongValue; + } + + public Optional getSomeString() { + return Optional.ofNullable( someString ); + } + + public Optional getSomeInteger() { + return Optional.ofNullable( someInteger ); + } + + public Optional getSomeDouble() { + return Optional.ofNullable( someDouble ); + } + + public Optional getSomeBoolean() { + return Optional.ofNullable( someBoolean ); + } + + public OptionalDouble getSomeDoubleValue() { + return someDouble != null ? OptionalDouble.of( someDoubleValue ) : OptionalDouble.empty(); + } + + public OptionalInt getSomeIntValue() { + return someIntValue != null ? OptionalInt.of( someIntValue ) : OptionalInt.empty(); + } + + public OptionalLong getSomeLongValue() { + return someLongValue != null ? OptionalLong.of( someLongValue ) : OptionalLong.empty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Target.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Target.java new file mode 100644 index 0000000000..5fd5d1730b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/Target.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nullvalue; + +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.OptionalLong; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class Target { + + private final Optional someString; + private final Optional someInteger; + private final Optional someDouble; + private final Optional someBoolean; + private final OptionalInt someIntValue; + private final OptionalDouble someDoubleValue; + private final OptionalLong someLongValue; + + public Target(Optional someString, Optional someInteger, Optional someDouble, + Optional someBoolean, OptionalInt someIntValue, OptionalDouble someDoubleValue, + OptionalLong someLongValue) { + this.someString = someString; + this.someInteger = someInteger; + this.someDouble = someDouble; + this.someBoolean = someBoolean; + this.someIntValue = someIntValue; + this.someDoubleValue = someDoubleValue; + this.someLongValue = someLongValue; + } + + public Optional getSomeString() { + return someString; + } + + public Optional getSomeInteger() { + return someInteger; + } + + public Optional getSomeDouble() { + return someDouble; + } + + public Optional getSomeBoolean() { + return someBoolean; + } + + public OptionalLong getSomeLongValue() { + return someLongValue; + } + + public OptionalDouble getSomeDoubleValue() { + return someDoubleValue; + } + + public OptionalInt getSomeIntValue() { + return someIntValue; + } +} From 42c87d1da99252e21699cde7d584538b5c961ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Eamil=20Can?= Date: Sun, 25 May 2025 15:22:47 +0200 Subject: [PATCH 0895/1006] #3848: Mark String to number as lossy conversion --- .../ap/internal/util/NativeTypes.java | 1 + .../conversion/lossy/CutleryInventoryDto.java | 9 +++++++++ .../lossy/CutleryInventoryEntity.java | 9 +++++++++ .../lossy/ErroneousKitchenDrawerMapper6.java | 20 +++++++++++++++++++ .../conversion/lossy/LossyConversionTest.java | 15 ++++++++++++++ .../lossy/OversizedKitchenDrawerDto.java | 8 ++++++++ .../lossy/RegularKitchenDrawerEntity.java | 8 ++++++++ 7 files changed, 70 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper6.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java index 0a4ca0cde0..ff01ae0ef3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/NativeTypes.java @@ -474,6 +474,7 @@ private NativeTypes() { tmp3.put( Double.class.getName(), 6 ); tmp3.put( BigInteger.class.getName(), 50 ); tmp3.put( BigDecimal.class.getName(), 51 ); + tmp3.put( String.class.getName(), 51 ); NARROWING_LUT = Collections.unmodifiableMap( tmp3 ); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java index 5a96d6deb2..3bc144511e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryDto.java @@ -10,6 +10,7 @@ public class CutleryInventoryDto { private short numberOfKnifes; private int numberOfForks; private byte numberOfSpoons; + private int drawerId; private float approximateKnifeLength; @@ -44,4 +45,12 @@ public float getApproximateKnifeLength() { public void setApproximateKnifeLength(float approximateKnifeLength) { this.approximateKnifeLength = approximateKnifeLength; } + + public int getDrawerId() { + return drawerId; + } + + public void setDrawerId(int drawerId) { + this.drawerId = drawerId; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java index 9575ed99dc..755dbc3637 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/CutleryInventoryEntity.java @@ -10,6 +10,7 @@ public class CutleryInventoryEntity { private int numberOfKnifes; private Long numberOfForks; private short numberOfSpoons; + private String drawerId; private double approximateKnifeLength; @@ -44,4 +45,12 @@ public double getApproximateKnifeLength() { public void setApproximateKnifeLength(double approximateKnifeLength) { this.approximateKnifeLength = approximateKnifeLength; } + + public String getDrawerId() { + return drawerId; + } + + public void setDrawerId(String drawerId) { + this.drawerId = drawerId; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper6.java new file mode 100644 index 0000000000..c33f1bd662 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerMapper6.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerMapper6 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "drawerId", source = "drawerId" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index d27f04374a..629f727273 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -40,12 +40,14 @@ public void testNoErrorCase() { dto.setNumberOfKnifes( (short) 7 ); dto.setNumberOfSpoons( (byte) 3 ); dto.setApproximateKnifeLength( 3.7f ); + dto.setDrawerId( 1 ); CutleryInventoryEntity entity = CutleryInventoryMapper.INSTANCE.map( dto ); assertThat( entity.getNumberOfForks() ).isEqualTo( 5L ); assertThat( entity.getNumberOfKnifes() ).isEqualTo( 7 ); assertThat( entity.getNumberOfSpoons() ).isEqualTo( (short) 3 ); assertThat( entity.getApproximateKnifeLength() ).isCloseTo( 3.7d, withinPercentage( 0.0001d ) ); + assertThat( entity.getDrawerId() ).isEqualTo( "1" ); } @ProcessorTest @@ -74,6 +76,19 @@ public void testConversionFromLongToInt() { public void testConversionFromBigIntegerToInteger() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerMapper6.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerMapper6.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "Can't map property \"String drawerId\". It has a possibly lossy conversion from " + + "String to int.") + }) + public void testConversionFromStringToInt() { + } + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper3.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java index 110bb2f07c..c42b24cc57 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerDto.java @@ -21,6 +21,7 @@ public class OversizedKitchenDrawerDto { private Double depth; private BigDecimal length; private double height; + private String drawerId; public long getNumberOfForks() { return numberOfForks; @@ -70,4 +71,11 @@ public void setHeight(double height) { this.height = height; } + public String getDrawerId() { + return drawerId; + } + + public void setDrawerId(String drawerId) { + this.drawerId = drawerId; + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java index d49a89052d..e3ae10bc1f 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/RegularKitchenDrawerEntity.java @@ -17,6 +17,7 @@ public class RegularKitchenDrawerEntity { private float depth; private Float length; private VerySpecialNumber height; + private int drawerId; public int getNumberOfForks() { return numberOfForks; @@ -66,4 +67,11 @@ public void setHeight(VerySpecialNumber height) { this.height = height; } + public int getDrawerId() { + return drawerId; + } + + public void setDrawerId(int drawerId) { + this.drawerId = drawerId; + } } From 3a5c70224d60aaa834986c5ff88fcb568df9fc85 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sun, 25 May 2025 21:40:43 +0800 Subject: [PATCH 0896/1006] #3809 Fix conditional mapping with `@TargetPropertyName` failing for nested update mappings Signed-off-by: TangYang --- .../model/assignment/UpdateWrapper.ftl | 15 +++- .../ap/test/bugs/_3809/Issue3809Mapper.java | 69 +++++++++++++++++++ .../ap/test/bugs/_3809/Issue3809Test.java | 20 ++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Test.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index 9cdd07c230..ea8eed2438 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -10,7 +10,7 @@ <@lib.handleExceptions> <#if includeSourceNullCheck> <@lib.sourceLocalVarAssignment/> - if ( <#if sourcePresenceCheckerReference?? ><@includeModel object=sourcePresenceCheckerReference /><#else><#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { + if ( <@handleSourceReferenceNullCheck/> ) { <@assignToExistingTarget/> <@lib.handleAssignment/>; } @@ -32,3 +32,16 @@ ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.initTargetObject/>; } + +<#macro handleSourceReferenceNullCheck> + <@compress single_line=true> + <#if sourcePresenceCheckerReference?? > + <@includeModel object=sourcePresenceCheckerReference + targetPropertyName=ext.targetPropertyName + sourcePropertyName=ext.sourcePropertyName + targetType=ext.targetType/> + <#else> + <#if sourceLocalVarName??> ${sourceLocalVarName} <#else> ${sourceReference} != null + + + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Mapper.java new file mode 100644 index 0000000000..10ff9e2628 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Mapper.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3809; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetPropertyName; + +@Mapper +public interface Issue3809Mapper { + void updateMappingFails(Source source, @MappingTarget Target target); + + @Condition + default boolean canMap(Object source, @TargetPropertyName String propertyName) { + return true; + } + + class Source { + private NestedSource param; + + public NestedSource getParam() { + return param; + } + } + + class NestedSource { + private String param1; + + public String getParam1() { + return param1; + } + + public void setParam1(String param1) { + this.param1 = param1; + } + + } + + class Target { + + private NestedTarget param; + + public NestedTarget getParam() { + return param; + } + + public void setParam(NestedTarget param) { + this.param = param; + } + + } + + class NestedTarget { + private String param1; + + public String getParam1() { + return param1; + } + + public void setParam1(String param1) { + this.param1 = param1; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Test.java new file mode 100644 index 0000000000..23d97b877c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3809/Issue3809Test.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3809; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +@WithClasses(Issue3809Mapper.class) +@IssueKey("3809") +public class Issue3809Test { + + @ProcessorTest + public void shouldCompileNoError() { + + } +} From 0badba70038875cb2fdf6d9ff328b6a9ba31d245 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sun, 25 May 2025 22:35:38 +0800 Subject: [PATCH 0897/1006] #3849: Resolve duplicate invocation of overloaded lifecycle methods with inheritance Add compiler option `mapstruct.disableLifecycleOverloadDeduplicateSelector` to disable the deduplication if needed. Signed-off-by: TangYang --- .../org/mapstruct/ap/MappingProcessor.java | 8 +- .../model/LifecycleMethodResolver.java | 2 +- .../model/ObjectFactoryMethodResolver.java | 7 +- .../model/PresenceCheckMethodResolver.java | 3 +- .../LifecycleOverloadDeduplicateSelector.java | 129 +++++++++++++++ .../source/selector/MethodSelectors.java | 16 +- .../mapstruct/ap/internal/option/Options.java | 9 +- .../creation/MappingResolverImpl.java | 2 +- .../mapstruct/ap/test/bugs/_3849/Child.java | 12 ++ .../ap/test/bugs/_3849/ChildDto.java | 16 ++ .../bugs/_3849/DeduplicateBySourceMapper.java | 69 ++++++++ .../bugs/_3849/DeduplicateByTargetMapper.java | 69 ++++++++ .../DeduplicateForCompileArgsMapper.java | 69 ++++++++ .../bugs/_3849/DeduplicateGenericMapper.java | 51 ++++++ .../ap/test/bugs/_3849/Issue3849Test.java | 150 ++++++++++++++++++ .../mapstruct/ap/test/bugs/_3849/Parent.java | 21 +++ .../ap/test/bugs/_3849/ParentDto.java | 22 +++ 17 files changed, 642 insertions(+), 13 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/LifecycleOverloadDeduplicateSelector.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Child.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ChildDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateBySourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateByTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateForCompileArgsMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateGenericMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Issue3849Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Parent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ParentDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 407166f6fa..b34b133262 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -95,6 +95,7 @@ MappingProcessor.VERBOSE, MappingProcessor.NULL_VALUE_ITERABLE_MAPPING_STRATEGY, MappingProcessor.NULL_VALUE_MAP_MAPPING_STRATEGY, + MappingProcessor.DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR, }) public class MappingProcessor extends AbstractProcessor { @@ -115,6 +116,8 @@ public class MappingProcessor extends AbstractProcessor { protected static final String VERBOSE = "mapstruct.verbose"; protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY = "mapstruct.nullValueIterableMappingStrategy"; protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY = "mapstruct.nullValueMapMappingStrategy"; + protected static final String DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR = + "mapstruct.disableLifecycleOverloadDeduplicateSelector"; private final Set additionalSupportedOptions; private final String additionalSupportedOptionsError; @@ -174,6 +177,8 @@ private Options createOptions() { String nullValueIterableMappingStrategy = processingEnv.getOptions() .get( NULL_VALUE_ITERABLE_MAPPING_STRATEGY ); String nullValueMapMappingStrategy = processingEnv.getOptions().get( NULL_VALUE_MAP_MAPPING_STRATEGY ); + String disableLifecycleOverloadDeduplicateSelector = processingEnv.getOptions() + .get( DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR ); return new Options( Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), @@ -189,7 +194,8 @@ private Options createOptions() { NullValueMappingStrategyGem.valueOf( nullValueIterableMappingStrategy.toUpperCase( Locale.ROOT ) ) : null, nullValueMapMappingStrategy != null ? - NullValueMappingStrategyGem.valueOf( nullValueMapMappingStrategy.toUpperCase( Locale.ROOT ) ) : null + NullValueMappingStrategyGem.valueOf( nullValueMapMappingStrategy.toUpperCase( Locale.ROOT ) ) : null, + Boolean.parseBoolean( disableLifecycleOverloadDeduplicateSelector ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index b713fa5f0c..cfe4f9f8b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -133,7 +133,7 @@ private static List collectLifecycleCallbackMe MappingBuilderContext ctx, Set existingVariableNames) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager(), ctx.getOptions() ); List> matchingMethods = selectors.getMatchingMethods( callbackMethods, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 4cf653b46b..89f295981f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -5,12 +5,9 @@ */ package org.mapstruct.ap.internal.model; -import static org.mapstruct.ap.internal.util.Collections.first; - import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; - import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -26,6 +23,8 @@ import org.mapstruct.ap.internal.model.source.selector.SelectionContext; import org.mapstruct.ap.internal.util.Message; +import static org.mapstruct.ap.internal.util.Collections.first; + /** * * @author Sjaak Derksen @@ -126,7 +125,7 @@ public static List> getMatchingFactoryMethods( Meth MappingBuilderContext ctx) { MethodSelectors selectors = - new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager() ); + new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager(), null ); return selectors.getMatchingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index 5906db8219..96826f8f66 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -119,7 +119,8 @@ private static List> findMatchingMethods( MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), - ctx.getMessager() + ctx.getMessager(), + null ); return selectors.getMatchingMethods( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/LifecycleOverloadDeduplicateSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/LifecycleOverloadDeduplicateSelector.java new file mode 100644 index 0000000000..7ce23af186 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/LifecycleOverloadDeduplicateSelector.java @@ -0,0 +1,129 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.source.selector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.stream.Collectors; + +import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; +import org.mapstruct.ap.internal.model.source.Method; + +/** + * Selector for deduplicating overloaded lifecycle callback methods + * whose parameter signatures differ only by type hierarchy. + *

      + * In the context of lifecycle callback method selection + * (such as @BeforeMapping or @AfterMapping), it is possible to have multiple overloaded methods + * whose parameter lists are structurally identical except for the specific types, + * where those types are related by inheritance (e.g., one parameter is a superclass or subclass of another). + *

      + * This selector groups such methods by their effective parameter signature + * (ignoring differences only in type hierarchy), and, within each group, + * retains only the method whose parameter types have the closest inheritance distance + * to the actual invocation types. + * This ensures that, for each group of nearly identical overloads, + * only the most specific and appropriate method is selected. + *

      + * Example (see Issue3849Test): + * + *

      {@code
      + * @AfterMapping
      + * default void afterMapping(Parent source, @MappingTarget ParentDto target) { ... }
      + * @AfterMapping
      + * default void afterMapping(Parent source, @MappingTarget ChildDto target) { ... }
      + * }
      + * When mapping a Child to a ChildDto, + * only the method with ChildDto is selected, even though both methods match by signature + * except for the target type's inheritance relationship. + */ +public class LifecycleOverloadDeduplicateSelector implements MethodSelector { + @Override + public List> getMatchingMethods(List> methods, + SelectionContext context) { + if ( !context.getSelectionCriteria().isLifecycleCallbackRequired() || methods.size() <= 1 ) { + return methods; + } + Collection>> methodSignatureGroups = + methods.stream() + .collect( Collectors.groupingBy( + LifecycleOverloadDeduplicateSelector::buildSignatureKey, + LinkedHashMap::new, + Collectors.toList() + ) ) + .values(); + List> deduplicatedMethods = new ArrayList<>( methods.size() ); + for ( List> signatureGroup : methodSignatureGroups ) { + if ( signatureGroup.size() == 1 ) { + deduplicatedMethods.add( signatureGroup.get( 0 ) ); + continue; + } + SelectedMethod bestInheritanceMethod = signatureGroup.get( 0 ); + for ( int i = 1; i < signatureGroup.size(); i++ ) { + SelectedMethod candidateMethod = signatureGroup.get( i ); + if ( isInheritanceBetter( candidateMethod, bestInheritanceMethod ) ) { + bestInheritanceMethod = candidateMethod; + } + } + deduplicatedMethods.add( bestInheritanceMethod ); + } + return deduplicatedMethods; + } + + /** + * Builds a grouping key for a method based on its defining type, + * method name, and a detailed breakdown of each parameter binding. + *

      + * The key consists of: + *

        + *
      • The type that defines the method
      • + *
      • The method name
      • + *
      • parameter bindings
      • + *
      + * This ensures that methods are grouped together only if all these aspects match, + * except for differences in type hierarchy, which are handled separately. + */ + private static List buildSignatureKey(SelectedMethod method) { + List key = new ArrayList<>(); + key.add( method.getMethod().getDefiningType() ); + key.add( method.getMethod().getName() ); + for ( ParameterBinding binding : method.getParameterBindings() ) { + key.add( binding.getType() ); + key.add( binding.getVariableName() ); + } + return key; + } + + /** + * Compare the inheritance distance of parameters between two methods to determine if candidateMethod is better. + * Compares parameters in order, returns as soon as a better one is found. + */ + private boolean isInheritanceBetter(SelectedMethod candidateMethod, + SelectedMethod currentBestMethod) { + List candidateBindings = candidateMethod.getParameterBindings(); + List bestBindings = currentBestMethod.getParameterBindings(); + List candidateParams = candidateMethod.getMethod().getParameters(); + List bestParams = currentBestMethod.getMethod().getParameters(); + int paramCount = candidateBindings.size(); + + for ( int i = 0; i < paramCount; i++ ) { + int candidateDistance = candidateBindings.get( i ) + .getType() + .distanceTo( candidateParams.get( i ).getType() ); + int bestDistance = bestBindings.get( i ).getType().distanceTo( bestParams.get( i ).getType() ); + if ( candidateDistance < bestDistance ) { + return true; + } + else if ( candidateDistance > bestDistance ) { + return false; + } + } + return false; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java index c14729a90f..774f25a8c3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MethodSelectors.java @@ -10,6 +10,7 @@ import java.util.List; import org.mapstruct.ap.internal.model.source.Method; +import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.TypeUtils; @@ -24,20 +25,27 @@ public class MethodSelectors { private final List selectors; public MethodSelectors(TypeUtils typeUtils, ElementUtils elementUtils, - FormattingMessager messager) { - selectors = Arrays.asList( + FormattingMessager messager, Options options) { + List selectorList = new ArrayList<>( Arrays.asList( new MethodFamilySelector(), new TypeSelector( messager ), new QualifierSelector( typeUtils, elementUtils ), new TargetTypeSelector( typeUtils ), new JavaxXmlElementDeclSelector( typeUtils ), new JakartaXmlElementDeclSelector( typeUtils ), - new InheritanceSelector(), + new InheritanceSelector() + ) ); + if ( options != null && !options.isDisableLifecycleOverloadDeduplicateSelector() ) { + selectorList.add( new LifecycleOverloadDeduplicateSelector() ); + } + + selectorList.addAll( Arrays.asList( new CreateOrUpdateSelector(), new SourceRhsSelector(), new FactoryParameterSelector(), new MostSpecificResultTypeSelector() - ); + ) ); + this.selectors = selectorList; } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index a544374c0e..095c472c87 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -26,6 +26,7 @@ public class Options { private final boolean verbose; private final NullValueMappingStrategyGem nullValueIterableMappingStrategy; private final NullValueMappingStrategyGem nullValueMapMappingStrategy; + private final boolean disableLifecycleOverloadDeduplicateSelector; //CHECKSTYLE:OFF public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, @@ -36,7 +37,8 @@ public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVers boolean disableBuilders, boolean verbose, NullValueMappingStrategyGem nullValueIterableMappingStrategy, - NullValueMappingStrategyGem nullValueMapMappingStrategy + NullValueMappingStrategyGem nullValueMapMappingStrategy, + boolean disableLifecycleOverloadDeduplicateSelector ) { //CHECKSTYLE:ON this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; @@ -50,6 +52,7 @@ public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVers this.verbose = verbose; this.nullValueIterableMappingStrategy = nullValueIterableMappingStrategy; this.nullValueMapMappingStrategy = nullValueMapMappingStrategy; + this.disableLifecycleOverloadDeduplicateSelector = disableLifecycleOverloadDeduplicateSelector; } public boolean isSuppressGeneratorTimestamp() { @@ -95,4 +98,8 @@ public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { return nullValueMapMappingStrategy; } + + public boolean isDisableLifecycleOverloadDeduplicateSelector() { + return disableLifecycleOverloadDeduplicateSelector; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index d84ba974db..ba903b6048 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -116,7 +116,7 @@ public MappingResolverImpl(FormattingMessager messager, ElementUtils elementUtil this.conversions = new Conversions( typeFactory ); this.builtInMethods = new BuiltInMappingMethods( typeFactory ); - this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, messager ); + this.methodSelectors = new MethodSelectors( typeUtils, elementUtils, messager, null ); this.verboseLogging = verboseLogging; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Child.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Child.java new file mode 100644 index 0000000000..393cb16970 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Child.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +public class Child extends Parent { + public Child() { + super(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ChildDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ChildDto.java new file mode 100644 index 0000000000..e8cdae4d17 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ChildDto.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +public class ChildDto extends ParentDto { + public ChildDto(String value) { + super( value ); + } + + public void setValue(String value) { + super.setValue( value ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateBySourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateBySourceMapper.java new file mode 100644 index 0000000000..68450c7d9d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateBySourceMapper.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DeduplicateBySourceMapper { + + DeduplicateBySourceMapper INSTANCE = Mappers.getMapper( DeduplicateBySourceMapper.class ); + List INVOKED_METHODS = new ArrayList<>(); + + ParentDto mapParent(Parent source, @Context MappingContext context); + + ParentDto mapChild(Child source, @Context MappingContext context); + + class MappingContext { + @BeforeMapping + void deduplicateBySourceForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentSourceInOtherClass" ); + } + + @BeforeMapping + void deduplicateBySourceForBefore(Child sourceChild, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingChildSourceInOtherClass" ); + } + + @AfterMapping + void deduplicateBySource(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentSourceInOtherClass" ); + } + + @AfterMapping + void deduplicateBySource(Child sourceChild, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingChildSourceInOtherClass" ); + } + } + + @BeforeMapping + default void deduplicateBySourceForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentSource" ); + } + + @BeforeMapping + default void deduplicateBySourceForBefore(Child sourceChild, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingChildSource" ); + } + + @AfterMapping + default void deduplicateBySource(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentSource" ); + } + + @AfterMapping + default void deduplicateBySource(Child sourceChild, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingChildSource" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateByTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateByTargetMapper.java new file mode 100644 index 0000000000..0aed8a2957 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateByTargetMapper.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DeduplicateByTargetMapper { + + DeduplicateByTargetMapper INSTANCE = Mappers.getMapper( DeduplicateByTargetMapper.class ); + List INVOKED_METHODS = new ArrayList<>(); + + ParentDto mapParent(Parent source, @Context MappingContext context); + + ChildDto mapChild(Parent source, @Context MappingContext context); + + class MappingContext { + @BeforeMapping + void deduplicateByTargetForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentTargetInOtherClass" ); + } + + @BeforeMapping + void deduplicateByTargetForBefore(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "beforeMappingChildTargetInOtherClass" ); + } + + @AfterMapping + void deduplicateByTarget(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentTargetInOtherClass" ); + } + + @AfterMapping + void deduplicateByTarget(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "afterMappingChildTargetInOtherClass" ); + } + } + + @BeforeMapping + default void deduplicateByTargetForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentTarget" ); + } + + @BeforeMapping + default void deduplicateByTargetForBefore(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "beforeMappingChildTarget" ); + } + + @AfterMapping + default void deduplicateByTarget(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentTarget" ); + } + + @AfterMapping + default void deduplicateByTarget(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "afterMappingChildTarget" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateForCompileArgsMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateForCompileArgsMapper.java new file mode 100644 index 0000000000..276a2c4352 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateForCompileArgsMapper.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DeduplicateForCompileArgsMapper { + + DeduplicateForCompileArgsMapper INSTANCE = Mappers.getMapper( DeduplicateForCompileArgsMapper.class ); + List INVOKED_METHODS = new ArrayList<>(); + + ParentDto mapParent(Parent source, @Context MappingContext context); + + ChildDto mapChild(Parent source, @Context MappingContext context); + + class MappingContext { + @BeforeMapping + void deduplicateByTargetForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentTargetInOtherClass" ); + } + + @BeforeMapping + void deduplicateByTargetForBefore(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "beforeMappingChildTargetInOtherClass" ); + } + + @AfterMapping + void deduplicateByTarget(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentTargetInOtherClass" ); + } + + @AfterMapping + void deduplicateByTarget(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "afterMappingChildTargetInOtherClass" ); + } + } + + @BeforeMapping + default void deduplicateByTargetForBefore(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "beforeMappingParentTarget" ); + } + + @BeforeMapping + default void deduplicateByTargetForBefore(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "beforeMappingChildTarget" ); + } + + @AfterMapping + default void deduplicateByTarget(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParentTarget" ); + } + + @AfterMapping + default void deduplicateByTarget(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "afterMappingChildTarget" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateGenericMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateGenericMapper.java new file mode 100644 index 0000000000..662137f1a9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/DeduplicateGenericMapper.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface DeduplicateGenericMapper { + + DeduplicateGenericMapper INSTANCE = Mappers.getMapper( DeduplicateGenericMapper.class ); + List INVOKED_METHODS = new ArrayList<>(); + + ParentDto mapParent(Parent source); + + ChildDto mapChild(Parent source); + + @BeforeMapping + default void deduplicateBefore(Parent source, @MappingTarget T target) { + INVOKED_METHODS.add( "beforeMappingParentGeneric" ); + } + + @BeforeMapping + default void deduplicateBefore(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "beforeMappingChild" ); + } + + @AfterMapping + default void deduplicate(Parent source, @MappingTarget T target) { + INVOKED_METHODS.add( "afterMappingGeneric" ); + } + + @AfterMapping + default void deduplicate(Parent source, @MappingTarget ParentDto target) { + INVOKED_METHODS.add( "afterMappingParent" ); + } + + @AfterMapping + default void deduplicate(Parent source, @MappingTarget ChildDto target) { + INVOKED_METHODS.add( "afterMappingChild" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Issue3849Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Issue3849Test.java new file mode 100644 index 0000000000..a58c52c921 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Issue3849Test.java @@ -0,0 +1,150 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ + +package org.mapstruct.ap.test.bugs._3849; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.ProcessorOption; + +import static org.assertj.core.api.Assertions.assertThat; + +@IssueKey("3849") +@WithClasses({ + Parent.class, + ParentDto.class, + Child.class, + ChildDto.class +}) +public class Issue3849Test { + + @ProcessorOption(name = "mapstruct.disableLifecycleOverloadDeduplicateSelector", value = "true") + @ProcessorTest() + @WithClasses(DeduplicateForCompileArgsMapper.class) + void lifecycleMappingOverloadSelectorDisableCompileArgs() { + Child child = new Child(); + Parent parent = new Parent(); + + DeduplicateForCompileArgsMapper.MappingContext mappingContext = + new DeduplicateForCompileArgsMapper.MappingContext(); + ParentDto parentDto = DeduplicateForCompileArgsMapper.INSTANCE.mapParent( parent, mappingContext ); + assertThat( DeduplicateForCompileArgsMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingParentTargetInOtherClass", + "beforeMappingParentTarget", + "afterMappingParentTargetInOtherClass", + "afterMappingParentTarget" + ); + + DeduplicateForCompileArgsMapper.INVOKED_METHODS.clear(); + + ParentDto childDto = DeduplicateForCompileArgsMapper.INSTANCE.mapChild( child, mappingContext ); + + assertThat( DeduplicateForCompileArgsMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingChildTargetInOtherClass", + "beforeMappingChildTargetInOtherClass", + "beforeMappingChildTarget", + "beforeMappingChildTarget", + "afterMappingChildTargetInOtherClass", + "afterMappingChildTargetInOtherClass", + "afterMappingChildTarget", + "afterMappingChildTarget" + ); + + DeduplicateForCompileArgsMapper.INVOKED_METHODS.clear(); + } + + @ProcessorTest() + @WithClasses( DeduplicateByTargetMapper.class ) + void lifecycleMappingOverloadByTarget() { + Child child = new Child(); + Parent parent = new Parent(); + + DeduplicateByTargetMapper.MappingContext mappingContext = new DeduplicateByTargetMapper.MappingContext(); + ParentDto parentDto = DeduplicateByTargetMapper.INSTANCE.mapParent( parent, mappingContext ); + assertThat( DeduplicateByTargetMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingParentTargetInOtherClass", + "beforeMappingParentTarget", + "afterMappingParentTargetInOtherClass", + "afterMappingParentTarget" + ); + + DeduplicateByTargetMapper.INVOKED_METHODS.clear(); + + ParentDto childDto = DeduplicateByTargetMapper.INSTANCE.mapChild( child, mappingContext ); + + assertThat( DeduplicateByTargetMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingChildTargetInOtherClass", + "beforeMappingChildTarget", + "afterMappingChildTargetInOtherClass", + "afterMappingChildTarget" + ); + + DeduplicateByTargetMapper.INVOKED_METHODS.clear(); + } + + @ProcessorTest + @WithClasses( DeduplicateBySourceMapper.class ) + void lifecycleMappingOverloadBySource() { + Child child = new Child(); + Parent parent = new Parent(); + + DeduplicateBySourceMapper.MappingContext mappingContext = new DeduplicateBySourceMapper.MappingContext(); + ParentDto parentDto = DeduplicateBySourceMapper.INSTANCE.mapParent( parent, mappingContext ); + assertThat( DeduplicateBySourceMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingParentSourceInOtherClass", + "beforeMappingParentSource", + "afterMappingParentSourceInOtherClass", + "afterMappingParentSource" + ); + + DeduplicateBySourceMapper.INVOKED_METHODS.clear(); + + ParentDto childDto = DeduplicateBySourceMapper.INSTANCE.mapChild( child, mappingContext ); + + assertThat( DeduplicateBySourceMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingChildSourceInOtherClass", + "beforeMappingChildSource", + "afterMappingChildSourceInOtherClass", + "afterMappingChildSource" + ); + + DeduplicateBySourceMapper.INVOKED_METHODS.clear(); + } + + @ProcessorTest + @WithClasses(DeduplicateGenericMapper.class) + void lifecycleMappingOverloadForGeneric() { + Child child = new Child(); + Parent parent = new Parent(); + + ParentDto parentDto = DeduplicateGenericMapper.INSTANCE.mapParent( parent ); + assertThat( DeduplicateGenericMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingParentGeneric", + "afterMappingParent" + ); + + DeduplicateGenericMapper.INVOKED_METHODS.clear(); + + ParentDto childDto = DeduplicateGenericMapper.INSTANCE.mapChild( child ); + + assertThat( DeduplicateGenericMapper.INVOKED_METHODS ) + .containsExactly( + "beforeMappingChild", + "afterMappingChild" + ); + + DeduplicateGenericMapper.INVOKED_METHODS.clear(); + } +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Parent.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Parent.java new file mode 100644 index 0000000000..4930677286 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/Parent.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +public class Parent { + private String value; + + public Parent() { + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ParentDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ParentDto.java new file mode 100644 index 0000000000..098917f001 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3849/ParentDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3849; + +public class ParentDto { + private String value; + + public ParentDto(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} From 6b6600c370cb50b2fbf40f56412238974575ae85 Mon Sep 17 00:00:00 2001 From: Aleksey Ivashin Date: Sun, 25 May 2025 18:05:18 +0300 Subject: [PATCH 0898/1006] #1958: Add support for ignoring multiple target properties at once --- core/src/main/java/org/mapstruct/Ignored.java | 67 ++++++++++++ .../main/java/org/mapstruct/IgnoredList.java | 54 ++++++++++ core/src/main/java/org/mapstruct/Mapping.java | 3 + .../chapter-5-data-type-conversions.asciidoc | 7 ++ .../ap/internal/gem/GemGenerator.java | 4 + .../processor/MethodRetrievalProcessor.java | 61 ++++++++++- .../org/mapstruct/ap/test/ignored/Animal.java | 64 +++++++++++ .../mapstruct/ap/test/ignored/AnimalDto.java | 63 +++++++++++ .../ap/test/ignored/AnimalMapper.java | 20 ++++ .../ap/test/ignored/ErroneousMapper.java | 26 +++++ .../ap/test/ignored/IgnoredPropertyTest.java | 102 ++++++++++++++++++ .../org/mapstruct/ap/test/ignored/Zoo.java | 48 +++++++++ .../org/mapstruct/ap/test/ignored/ZooDto.java | 48 +++++++++ .../mapstruct/ap/test/ignored/ZooMapper.java | 23 ++++ 14 files changed, 589 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/mapstruct/Ignored.java create mode 100644 core/src/main/java/org/mapstruct/IgnoredList.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/Animal.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/ErroneousMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/IgnoredPropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/Zoo.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/ZooDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignored/ZooMapper.java diff --git a/core/src/main/java/org/mapstruct/Ignored.java b/core/src/main/java/org/mapstruct/Ignored.java new file mode 100644 index 0000000000..47e4961f43 --- /dev/null +++ b/core/src/main/java/org/mapstruct/Ignored.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configures the ignored of one bean attribute. + * + *

      + * The name all attributes of for ignored is to be specified via {@link #targets()}. + *

      + * + *

      + * Example 1: Implicitly mapping fields with the same name: + *

      + * + *
      
      + * // We need ignored Human.name and Human.lastName
      + * // we can use @Ignored with parameters "name", "lastName" {@link #targets()}
      + * @Mapper
      + * public interface HumanMapper {
      + *    @Ignored( targets = { "name", "lastName" } )
      + *    HumanDto toHumanDto(Human human)
      + * }
      + * 
      + *
      
      + * // generates:
      + * @Override
      + * public HumanDto toHumanDto(Human human) {
      + *    humanDto.setFullName( human.getFullName() );
      + *    // ...
      + * }
      + * 
      + * + * @author Ivashin Aleksey + */ +@Repeatable(IgnoredList.class) +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE}) +public @interface Ignored { + + /** + * Whether the specified properties should be ignored by the generated mapping method. + * This can be useful when certain attributes should not be propagated from source to target or when properties in + * the target object are populated using a decorator and thus would be reported as unmapped target property by + * default. + * + * @return The target names of the configured properties that should be ignored + */ + String[] targets(); + + /** + * The prefix that should be applied to all the properties specified via {@link #targets()}. + * + * @return The target prefix to be applied to the defined properties + */ + String prefix() default ""; + +} diff --git a/core/src/main/java/org/mapstruct/IgnoredList.java b/core/src/main/java/org/mapstruct/IgnoredList.java new file mode 100644 index 0000000000..e47db6bac7 --- /dev/null +++ b/core/src/main/java/org/mapstruct/IgnoredList.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Configures the ignored list for several bean attributes. + *

      + * TIP: When using Java 8 or later, you can omit the {@code @IgnoredList} + * wrapper annotation and directly specify several {@code @Ignored} annotations on one method. + * + *

      These two examples are equal. + *

      + *
      
      + * // before Java 8
      + * @Mapper
      + * public interface MyMapper {
      + *     @IgnoredList({
      + *         @Ignored(targets = { "firstProperty" } ),
      + *         @Ignored(targets = { "secondProperty" } )
      + *     })
      + *     HumanDto toHumanDto(Human human);
      + * }
      + * 
      + *
      
      + * // Java 8 and later
      + * @Mapper
      + * public interface MyMapper {
      + *     @Ignored(targets = { "firstProperty" } ),
      + *     @Ignored(targets = { "secondProperty" } )
      + *     HumanDto toHumanDto(Human human);
      + * }
      + * 
      + * + * @author Ivashin Aleksey + */ +@Retention(RetentionPolicy.CLASS) +@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE }) +public @interface IgnoredList { + + /** + * The configuration of the bean attributes. + * + * @return The configuration of the bean attributes. + */ + Ignored[] value(); +} diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index 6c95b0db2c..f15cfb75cc 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -306,6 +306,9 @@ * This can be useful when certain attributes should not be propagated from source to target or when properties in * the target object are populated using a decorator and thus would be reported as unmapped target property by * default. + *

      + * If you have multiple properties to ignore, + * you can use the {@link Ignored} annotation instead and group them all at once. * * @return {@code true} if the given property should be ignored, {@code false} otherwise */ diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index bc406cf0b0..ad49fe2960 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -280,6 +280,13 @@ This puts the configuration of the nested mapping into one place (method) where instead of re-configuring the same things on all of those upper methods. ==== +[TIP] +==== +When ignoring multiple properties instead of defining multiple `@Mapping` annotations, you can use the `@Ignored` annotation to group them together. +e.g. for the `FishTankMapperWithDocument` example above, you could write: +`@Ignored(targets = { "plant", "ornament", "material" })` +==== + [NOTE] ==== In some cases the `ReportingPolicy` that is going to be used for the generated nested method would be `IGNORE`. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java index 2ed9bd9a09..a8b62babe9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/GemGenerator.java @@ -26,6 +26,8 @@ import org.mapstruct.Mapper; import org.mapstruct.MapperConfig; import org.mapstruct.Mapping; +import org.mapstruct.Ignored; +import org.mapstruct.IgnoredList; import org.mapstruct.MappingTarget; import org.mapstruct.Mappings; import org.mapstruct.Named; @@ -53,6 +55,8 @@ @GemDefinition(AnnotateWiths.class) @GemDefinition(Mapper.class) @GemDefinition(Mapping.class) +@GemDefinition(Ignored.class) +@GemDefinition(IgnoredList.class) @GemDefinition(Mappings.class) @GemDefinition(IterableMapping.class) @GemDefinition(BeanMapping.class) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index c8c13e6bf9..6843ac5bbe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -21,6 +21,8 @@ import org.mapstruct.ap.internal.gem.BeanMappingGem; import org.mapstruct.ap.internal.gem.ConditionGem; +import org.mapstruct.ap.internal.gem.IgnoredGem; +import org.mapstruct.ap.internal.gem.IgnoredListGem; import org.mapstruct.ap.internal.gem.IterableMappingGem; import org.mapstruct.ap.internal.gem.MapMappingGem; import org.mapstruct.ap.internal.gem.MappingGem; @@ -76,6 +78,8 @@ public class MethodRetrievalProcessor implements ModelElementProcessor getMappings(ExecutableElement method, BeanMappingOptions beanMapping) { - return new RepeatableMappings( beanMapping ).getProcessedAnnotations( method ); + Set processedAnnotations = new RepeatableMappings( beanMapping ) + .getProcessedAnnotations( method ); + processedAnnotations.addAll( new IgnoredConditions( processedAnnotations ) + .getProcessedAnnotations( method ) ); + return processedAnnotations; } /** @@ -823,4 +831,55 @@ protected void addInstance(ConditionGem gem, Element source, Set { + + protected final Set processedAnnotations; + + protected IgnoredConditions( Set processedAnnotations ) { + super( elementUtils, IGNORED_FQN, IGNORED_LIST_FQN ); + this.processedAnnotations = processedAnnotations; + } + + @Override + protected IgnoredGem singularInstanceOn(Element element) { + return IgnoredGem.instanceOn( element ); + } + + @Override + protected IgnoredListGem multipleInstanceOn(Element element) { + return IgnoredListGem.instanceOn( element ); + } + + @Override + protected void addInstance(IgnoredGem gem, Element method, Set mappings) { + IgnoredGem ignoredGem = IgnoredGem.instanceOn( method ); + if ( ignoredGem == null ) { + ignoredGem = gem; + } + String prefix = ignoredGem.prefix().get(); + for ( String target : ignoredGem.targets().get() ) { + String realTarget = target; + if ( !prefix.isEmpty() ) { + realTarget = prefix + "." + target; + } + MappingOptions mappingOptions = MappingOptions.forIgnore( realTarget ); + if ( processedAnnotations.contains( mappingOptions ) || mappings.contains( mappingOptions ) ) { + messager.printMessage( method, Message.PROPERTYMAPPING_DUPLICATE_TARGETS, realTarget ); + } + else { + mappings.add( mappingOptions ); + } + } + } + + @Override + protected void addInstances(IgnoredListGem gem, Element method, Set mappings) { + IgnoredListGem ignoredListGem = IgnoredListGem.instanceOn( method ); + for ( IgnoredGem ignoredGem : ignoredListGem.value().get() ) { + addInstance( ignoredGem, method, mappings ); + } + } + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/Animal.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/Animal.java new file mode 100644 index 0000000000..223f99f705 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/Animal.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +public class Animal { + + //CHECKSTYLE:OFF + public Integer publicAge; + public String publicColour; + //CHECKSTYLE:OFN + private String colour; + private String name; + private int size; + private Integer age; + + // private String colour; + public Animal() { + } + + public Animal(String name, int size, Integer age, String colour) { + this.name = name; + this.size = size; + this.publicAge = age; + this.age = age; + this.publicColour = colour; + this.colour = colour; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getColour() { + return colour; + } + + public void setColour( String colour ) { + this.colour = colour; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalDto.java new file mode 100644 index 0000000000..1651f9b56b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalDto.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +public class AnimalDto { + + //CHECKSTYLE:OFF + public Integer publicAge; + public String publicColor; + //CHECKSTYLE:ON + private String name; + private Integer size; + private Integer age; + private String color; + + public AnimalDto() { + + } + + public AnimalDto(String name, Integer size, Integer age, String color) { + this.name = name; + this.size = size; + this.publicAge = age; + this.age = age; + this.publicColor = color; + this.color = color; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getSize() { + return size; + } + + public void setSize(Integer size) { + this.size = size; + } + + public Integer getAge() { + return age; + } + + public void setAge(Integer age) { + this.age = age; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalMapper.java new file mode 100644 index 0000000000..2753b36070 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/AnimalMapper.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +import org.mapstruct.Ignored; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface AnimalMapper { + + AnimalMapper INSTANCE = Mappers.getMapper( AnimalMapper.class ); + + @Ignored( targets = { "publicAge", "age", "publicColor", "color" } ) + AnimalDto animalToDto( Animal animal ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/ErroneousMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/ErroneousMapper.java new file mode 100644 index 0000000000..b113e715aa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/ErroneousMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +import org.mapstruct.Ignored; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ErroneousMapper { + + ErroneousMapper INSTANCE = Mappers.getMapper( ErroneousMapper.class ); + + @Mapping(target = "name", ignore = true) + @Ignored(targets = { "name", "color", "publicColor" }) + AnimalDto ignoredAndMappingAnimalToDto( Animal animal ); + + @Mapping(target = "publicColor", source = "publicColour") + @Ignored(targets = { "publicColor", "color" }) + AnimalDto ignoredAndMappingAnimalToDtoMap( Animal animal ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/IgnoredPropertyTest.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/IgnoredPropertyTest.java new file mode 100644 index 0000000000..bc6fc2f6b7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/IgnoredPropertyTest.java @@ -0,0 +1,102 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for ignoring properties during the mapping. + * + * @author Ivashin Aleksey + */ +@WithClasses({ Animal.class, AnimalDto.class, Zoo.class, ZooDto.class, ZooMapper.class}) +public class IgnoredPropertyTest { + + @ProcessorTest + @IssueKey("1958") + @WithClasses( { AnimalMapper.class } ) + public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { + Animal animal = new Animal( "Bruno", 100, 23, "black" ); + + AnimalDto animalDto = AnimalMapper.INSTANCE.animalToDto( animal ); + + assertThat( animalDto ).isNotNull(); + assertThat( animalDto.getName() ).isEqualTo( "Bruno" ); + assertThat( animalDto.getSize() ).isEqualTo( 100 ); + assertThat( animalDto.getAge() ).isNull(); + assertThat( animalDto.publicAge ).isNull(); + assertThat( animalDto.getColor() ).isNull(); + assertThat( animalDto.publicColor ).isNull(); + } + + @ProcessorTest + @IssueKey("1958") + @WithClasses( { ErroneousMapper.class } ) + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Target property \"name\" must not be mapped more than once." ), + @Diagnostic(type = ErroneousMapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 24, + message = "Target property \"publicColor\" must not be mapped more than once." ) + } + ) + public void shouldFailToGenerateMappings() { + } + + @ProcessorTest + @IssueKey("1958") + @WithClasses( { AnimalMapper.class } ) + public void shouldNotPropagateIgnoredInnerPropertyGivenViaTargetAttribute() { + Animal animal = new Animal( "Bruno", 100, 23, "black" ); + Zoo zoo = new Zoo(animal, "Test name", "test address"); + + ZooDto zooDto = ZooMapper.INSTANCE.zooToDto( zoo ); + + assertThat( zooDto ).isNotNull(); + assertThat( zooDto.getName() ).isEqualTo( "Test name" ); + assertThat( zooDto.getAddress() ).isEqualTo( "test address" ); + assertThat( zooDto.getAnimal() ).isNotNull(); + assertThat( zooDto.getAnimal().getName() ).isEqualTo( "Bruno" ); + assertThat( zooDto.getAnimal().getAge() ).isNull(); + assertThat( zooDto.getAnimal().publicAge ).isNull(); + assertThat( zooDto.getAnimal().getColor() ).isNull(); + assertThat( zooDto.getAnimal().publicColor ).isNull(); + assertThat( zooDto.getAnimal().getSize() ).isNull(); + } + + @ProcessorTest + @IssueKey("1958") + @WithClasses( { AnimalMapper.class } ) + public void shouldNotPropagateIgnoredInnerPropertyGivenViaTargetAttribute2() { + Animal animal = new Animal( "Bruno", 100, 23, "black" ); + Zoo zoo = new Zoo(animal, "Test name", "test address"); + + ZooDto zooDto = ZooMapper.INSTANCE.zooToDto2( zoo ); + + assertThat( zooDto ).isNotNull(); + assertThat( zooDto.getName() ).isEqualTo( "Test name" ); + assertThat( zooDto.getAddress() ).isNull(); + assertThat( zooDto.getAnimal() ).isNotNull(); + assertThat( zooDto.getAnimal().getName() ).isEqualTo( "Bruno" ); + assertThat( zooDto.getAnimal().getAge() ).isNull(); + assertThat( zooDto.getAnimal().publicAge ).isNull(); + assertThat( zooDto.getAnimal().getColor() ).isNull(); + assertThat( zooDto.getAnimal().publicColor ).isNull(); + assertThat( zooDto.getAnimal().getSize() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/Zoo.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/Zoo.java new file mode 100644 index 0000000000..377e03b877 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/Zoo.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +public class Zoo { + + private Animal animal; + + private String name; + + private String address; + + public Zoo() { + } + + public Zoo(Animal animal, String name, String address ) { + this.animal = animal; + this.name = name; + this.address = address; + } + + public Animal getAnimal() { + return animal; + } + + public void setAnimal(Animal animal) { + this.animal = animal; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooDto.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooDto.java new file mode 100644 index 0000000000..7c062cab4c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooDto.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +public class ZooDto { + + private AnimalDto animal; + + private String name; + + private String address; + + public ZooDto() { + } + + public ZooDto(AnimalDto animal, String name, String address) { + this.animal = animal; + this.name = name; + this.address = address; + } + + public AnimalDto getAnimal() { + return animal; + } + + public void setAnimal(AnimalDto animal) { + this.animal = animal; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooMapper.java b/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooMapper.java new file mode 100644 index 0000000000..f05e045b5f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/ignored/ZooMapper.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.ignored; + +import org.mapstruct.Ignored; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface ZooMapper { + + ZooMapper INSTANCE = Mappers.getMapper( ZooMapper.class ); + + @Ignored( prefix = "animal", targets = { "publicAge", "size", "publicColor", "age", "color" } ) + ZooDto zooToDto( Zoo zoo ); + + @Ignored( targets = { "address" } ) + @Ignored( prefix = "animal", targets = { "publicAge", "size", "publicColor", "age", "color" } ) + ZooDto zooToDto2( Zoo zoo ); +} From 5464c3cff805a235e908976fe5d55d0162d2a323 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sat, 31 May 2025 17:10:24 +0800 Subject: [PATCH 0899/1006] #3711: Support generic `@Context` Signed-off-by: TangYang --- .../processor/MethodRetrievalProcessor.java | 25 +++++++++------ .../ap/test/bugs/_3711/BaseMapper.java | 12 +++++++ .../ap/test/bugs/_3711/Issue3711Test.java | 31 +++++++++++++++++++ .../ap/test/bugs/_3711/JpaContext.java | 31 +++++++++++++++++++ .../ap/test/bugs/_3711/ParentDto.java | 18 +++++++++++ .../ap/test/bugs/_3711/ParentEntity.java | 18 +++++++++++ .../test/bugs/_3711/SourceTargetMapper.java | 16 ++++++++++ 7 files changed, 142 insertions(+), 9 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/BaseMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/Issue3711Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/JpaContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/SourceTargetMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java index 6843ac5bbe..d7a0329aeb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MethodRetrievalProcessor.java @@ -114,7 +114,12 @@ public List process(ProcessorContext context, TypeElement mapperTy } List prototypeMethods = retrievePrototypeMethods( mapperTypeElement, mapperOptions ); - return retrieveMethods( mapperTypeElement, mapperTypeElement, mapperOptions, prototypeMethods ); + return retrieveMethods( + typeFactory.getType( mapperTypeElement.asType() ), + mapperTypeElement, + mapperOptions, + prototypeMethods + ); } @Override @@ -166,19 +171,21 @@ private List retrievePrototypeMethods(TypeElement mapperTypeElemen /** * Retrieves the mapping methods declared by the given mapper type. * - * @param usedMapper The type of interest (either the mapper to implement or a used mapper via @uses annotation) + * @param usedMapperType The type of interest (either the mapper to implement, a used mapper via @uses annotation, + * or a parameter type annotated with @Context) * @param mapperToImplement the top level type (mapper) that requires implementation * @param mapperOptions the mapper config * @param prototypeMethods prototype methods defined in mapper config type * @return All mapping methods declared by the given type */ - private List retrieveMethods(TypeElement usedMapper, TypeElement mapperToImplement, + private List retrieveMethods(Type usedMapperType, TypeElement mapperToImplement, MapperOptions mapperOptions, List prototypeMethods) { List methods = new ArrayList<>(); + TypeElement usedMapper = usedMapperType.getTypeElement(); for ( ExecutableElement executable : elementUtils.getAllEnclosedExecutableElements( usedMapper ) ) { SourceMethod method = getMethod( - usedMapper, + usedMapperType, executable, mapperToImplement, mapperOptions, @@ -195,7 +202,7 @@ private List retrieveMethods(TypeElement usedMapper, TypeElement m TypeElement usesMapperElement = asTypeElement( mapper ); if ( !mapperToImplement.equals( usesMapperElement ) ) { methods.addAll( retrieveMethods( - usesMapperElement, + typeFactory.getType( mapper ), mapperToImplement, mapperOptions, prototypeMethods ) ); @@ -218,13 +225,13 @@ private TypeElement asTypeElement(DeclaredType type) { return (TypeElement) type.asElement(); } - private SourceMethod getMethod(TypeElement usedMapper, + private SourceMethod getMethod(Type usedMapperType, ExecutableElement method, TypeElement mapperToImplement, MapperOptions mapperOptions, List prototypeMethods) { - - ExecutableType methodType = typeFactory.getMethodType( (DeclaredType) usedMapper.asType(), method ); + TypeElement usedMapper = usedMapperType.getTypeElement(); + ExecutableType methodType = typeFactory.getMethodType( (DeclaredType) usedMapperType.getTypeMirror(), method ); List parameters = typeFactory.getParameters( methodType, method ); Type returnType = typeFactory.getReturnType( methodType ); @@ -357,7 +364,7 @@ private ParameterProvidedMethods retrieveContextProvidedMethods( continue; } List contextParamMethods = retrieveMethods( - contextParam.getType().getTypeElement(), + contextParam.getType(), mapperToImplement, mapperConfig, Collections.emptyList() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/BaseMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/BaseMapper.java new file mode 100644 index 0000000000..e2a04fe336 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/BaseMapper.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +import org.mapstruct.Context; + +interface BaseMapper { + E toEntity(T s, @Context JpaContext ctx); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/Issue3711Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/Issue3711Test.java new file mode 100644 index 0000000000..7b141e9e14 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/Issue3711Test.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + ParentEntity.class, + ParentDto.class, + JpaContext.class, + SourceTargetMapper.class, + BaseMapper.class, +}) +@IssueKey("3711") +class Issue3711Test { + @ProcessorTest + void shouldGenerateContextMethod() { + JpaContext jpaContext = new JpaContext<>(); + SourceTargetMapper.INSTANCE.toEntity( new ParentDto(), jpaContext ); + + assertThat( jpaContext.getInvokedMethods() ) + .containsExactly( "beforeMapping", "afterMapping" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/JpaContext.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/JpaContext.java new file mode 100644 index 0000000000..b21bf639d7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/JpaContext.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +import java.util.ArrayList; +import java.util.List; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.MappingTarget; + +public class JpaContext { + private final List invokedMethods = new ArrayList<>(); + + @BeforeMapping + void beforeMapping(@MappingTarget T parentEntity) { + invokedMethods.add( "beforeMapping" ); + } + + @AfterMapping + void afterMapping(@MappingTarget T parentEntity) { + invokedMethods.add( "afterMapping" ); + } + + public List getInvokedMethods() { + return invokedMethods; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentDto.java new file mode 100644 index 0000000000..664d6e58ab --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentDto.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +public class ParentDto { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentEntity.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentEntity.java new file mode 100644 index 0000000000..aaefa949fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/ParentEntity.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +public class ParentEntity { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/SourceTargetMapper.java new file mode 100644 index 0000000000..b09333fd56 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3711/SourceTargetMapper.java @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3711; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SourceTargetMapper extends BaseMapper { + SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + ParentEntity toDTO(ParentDto dto); +} From 8fc97f5f62743cc72280f5334dbebf9fdc39bfee Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sat, 31 May 2025 17:13:50 +0800 Subject: [PATCH 0900/1006] #3806: Properly apply `NullValuePropertyMappingStrategy.IGNORE` for collections / maps without setters Signed-off-by: TangYang --- .../model/CollectionAssignmentBuilder.java | 1 + .../GetterWrapperForCollectionsAndMaps.java | 17 ++++ .../GetterWrapperForCollectionsAndMaps.ftl | 5 +- .../ap/test/bugs/_3806/Issue3806Mapper.java | 63 ++++++++++++++ .../ap/test/bugs/_3806/Issue3806Test.java | 86 +++++++++++++++++++ 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 9a0a025845..76e56cd976 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -240,6 +240,7 @@ else if ( hasNoArgsConstructor() ) { result, method.getThrownTypes(), targetType, + nvpms, targetAccessorType.isFieldAssignment() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java index d29a80b420..e1c0c8cb20 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.java @@ -9,9 +9,12 @@ import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; + /** * This wrapper handles the situation were an assignment must be done via a target getter method because there * is no setter available. @@ -26,6 +29,14 @@ * @author Sjaak Derksen */ public class GetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAndMaps { + private final boolean ignoreMapNull; + + public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, + List thrownTypesToExclude, + Type targetType, + boolean fieldAssignment) { + this( decoratedAssignment, thrownTypesToExclude, targetType, null, fieldAssignment ); + } /** * @param decoratedAssignment source RHS @@ -36,6 +47,7 @@ public class GetterWrapperForCollectionsAndMaps extends WrapperForCollectionsAnd public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, List thrownTypesToExclude, Type targetType, + NullValuePropertyMappingStrategyGem nvpms, boolean fieldAssignment) { super( @@ -44,6 +56,7 @@ public GetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, targetType, fieldAssignment ); + this.ignoreMapNull = nvpms == IGNORE; } @Override @@ -54,4 +67,8 @@ public Set getImportTypes() { } return imported; } + + public boolean isIgnoreMapNull() { + return ignoreMapNull; + } } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl index 4ef55f3b40..f47a37106e 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/GetterWrapperForCollectionsAndMaps.ftl @@ -10,10 +10,13 @@ <@lib.sourceLocalVarAssignment/> if ( ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing /> != null ) { <@lib.handleExceptions> - <#if ext.existingInstanceMapping> + <#if ext.existingInstanceMapping && !ignoreMapNull> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.clear(); <@lib.handleLocalVarNullCheck needs_explicit_local_var=false> + <#if ext.existingInstanceMapping && ignoreMapNull> + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.clear(); + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWriteAccesing />.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Mapper.java new file mode 100644 index 0000000000..89f325dfbb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Mapper.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3806; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface Issue3806Mapper { + + Issue3806Mapper INSTANCE = Mappers.getMapper( Issue3806Mapper.class ); + + void update(@MappingTarget Target target, Target source); + + class Target { + + private final Collection authors; + private final Map booksByAuthor; + + protected Collection books; + protected Map booksByPublisher; + + public Target(Collection authors, Map booksByAuthor) { + this.authors = authors != null ? new ArrayList<>( authors ) : null; + this.booksByAuthor = booksByAuthor != null ? new HashMap<>( booksByAuthor ) : null; + } + + public Collection getAuthors() { + return authors; + } + + public Map getBooksByAuthor() { + return booksByAuthor; + } + + public Collection getBooks() { + return books; + } + + public void setBooks(Collection books) { + this.books = books; + } + + public Map getBooksByPublisher() { + return booksByPublisher; + } + + public void setBooksByPublisher(Map booksByPublisher) { + this.booksByPublisher = booksByPublisher; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Test.java new file mode 100644 index 0000000000..1df3318c22 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3806/Issue3806Test.java @@ -0,0 +1,86 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3806; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +@WithClasses(Issue3806Mapper.class) +@IssueKey("3806") +class Issue3806Test { + + @ProcessorTest + void shouldNotClearGetterOnlyCollectionsInUpdateMapping() { + Map booksByAuthor = new HashMap<>(); + booksByAuthor.put( "author1", "book1" ); + booksByAuthor.put( "author2", "book2" ); + List authors = new ArrayList<>(); + authors.add( "author1" ); + authors.add( "author2" ); + + List books = new ArrayList<>(); + books.add( "book1" ); + books.add( "book2" ); + Map booksByPublisher = new HashMap<>(); + booksByPublisher.put( "publisher1", "book1" ); + booksByPublisher.put( "publisher2", "book2" ); + Issue3806Mapper.Target target = new Issue3806Mapper.Target( authors, booksByAuthor ); + target.setBooks( books ); + target.setBooksByPublisher( booksByPublisher ); + + Issue3806Mapper.Target source = new Issue3806Mapper.Target( null, null ); + Issue3806Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAuthors() ).containsExactly( "author1", "author2" ); + assertThat( target.getBooksByAuthor() ) + .containsOnly( + entry( "author1", "book1" ), + entry( "author2", "book2" ) + ); + + assertThat( target.getBooks() ).containsExactly( "book1", "book2" ); + assertThat( target.getBooksByPublisher() ) + .containsOnly( + entry( "publisher1", "book1" ), + entry( "publisher2", "book2" ) + ); + + booksByAuthor = new HashMap<>(); + booksByAuthor.put( "author3", "book3" ); + authors = new ArrayList<>(); + authors.add( "author3" ); + + books = new ArrayList<>(); + books.add( "book3" ); + booksByPublisher = new HashMap<>(); + booksByPublisher.put( "publisher3", "book3" ); + source = new Issue3806Mapper.Target( authors, booksByAuthor ); + source.setBooks( books ); + source.setBooksByPublisher( booksByPublisher ); + Issue3806Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAuthors() ).containsExactly( "author3" ); + assertThat( target.getBooksByAuthor() ) + .containsOnly( + entry( "author3", "book3" ) + ); + + assertThat( target.getBooks() ).containsExactly( "book3" ); + assertThat( target.getBooksByPublisher() ) + .containsOnly( + entry( "publisher3", "book3" ) + ); + } +} From bff88297e367ec856a1c5a5f68fcc9a62662ee70 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sat, 31 May 2025 19:29:39 +0800 Subject: [PATCH 0901/1006] #3807: Properly recognize the type of public generic fields Signed-off-by: TangYang --- .../ap/internal/model/BeanMappingMethod.java | 4 +- .../mapstruct/ap/internal/util/Filters.java | 23 +++++---- .../util/accessor/AbstractAccessor.java | 41 ---------------- .../util/accessor/ElementAccessor.java | 46 ++++++++++++++---- .../accessor/ExecutableElementAccessor.java | 41 ---------------- .../accessor/ParameterElementAccessor.java | 48 ------------------- .../internal/util/accessor/ReadAccessor.java | 10 ++-- .../util/accessor/RecordElementAccessor.java | 38 --------------- .../ap/test/bugs/_3807/Issue3807Mapper.java | 48 +++++++++++++++++++ .../ap/test/bugs/_3807/Issue3807Test.java | 32 +++++++++++++ 10 files changed, 140 insertions(+), 191 deletions(-) delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java delete mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 34c1ea3ccb..b5208d302b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -65,7 +65,7 @@ import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; -import org.mapstruct.ap.internal.util.accessor.ParameterElementAccessor; +import org.mapstruct.ap.internal.util.accessor.ElementAccessor; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; @@ -1067,7 +1067,7 @@ private Accessor createConstructorAccessor(Element element, TypeMirror accessedT existingVariableNames ); existingVariableNames.add( safeParameterName ); - return new ParameterElementAccessor( element, accessedType, safeParameterName ); + return new ElementAccessor( element, accessedType, safeParameterName ); } private boolean hasDefaultAnnotationFromAnyPackage(Element element) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java index 5f7fe74bf2..6492270705 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Filters.java @@ -12,7 +12,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.function.Function; +import java.util.function.BiFunction; import java.util.stream.Collectors; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; @@ -23,7 +23,7 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.internal.util.accessor.Accessor; -import org.mapstruct.ap.internal.util.accessor.ExecutableElementAccessor; +import org.mapstruct.ap.internal.util.accessor.ElementAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; import static org.mapstruct.ap.internal.util.Collections.first; @@ -64,7 +64,7 @@ public Filters(AccessorNamingUtils accessorNaming, TypeUtils typeUtils, TypeMirr public List getterMethodsIn(List elements) { return elements.stream() .filter( accessorNaming::isGetterMethod ) - .map( method -> ReadAccessor.fromGetter( method, getReturnType( method ) ) ) + .map( method -> ReadAccessor.fromGetter( method, getReturnType( method ) ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } @@ -90,7 +90,10 @@ public Map recordAccessorsIn(Collection recordCom for ( Element recordComponent : recordComponents ) { recordAccessors.put( recordComponent.getSimpleName().toString(), - ReadAccessor.fromRecordComponent( recordComponent ) + ReadAccessor.fromRecordComponent( + recordComponent, + typeUtils.asMemberOf( (DeclaredType) typeMirror, recordComponent ) + ) ); } @@ -101,10 +104,10 @@ private TypeMirror getReturnType(ExecutableElement executableElement) { return getWithinContext( executableElement ).getReturnType(); } - public List fieldsIn(List accessors, Function creator) { + public List fieldsIn(List accessors, BiFunction creator) { return accessors.stream() .filter( Fields::isFieldAccessor ) - .map( creator ) + .map( variableElement -> creator.apply( variableElement, getWithinContext( variableElement ) ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } @@ -117,7 +120,7 @@ public List presenceCheckMethodsIn(List el public List setterMethodsIn(List elements) { return elements.stream() .filter( accessorNaming::isSetterMethod ) - .map( method -> new ExecutableElementAccessor( method, getFirstParameter( method ), SETTER ) ) + .map( method -> new ElementAccessor( method, getFirstParameter( method ), SETTER ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } @@ -129,10 +132,14 @@ private ExecutableType getWithinContext( ExecutableElement executableElement ) { return (ExecutableType) typeUtils.asMemberOf( (DeclaredType) typeMirror, executableElement ); } + private TypeMirror getWithinContext( VariableElement variableElement ) { + return typeUtils.asMemberOf( (DeclaredType) typeMirror, variableElement ); + } + public List adderMethodsIn(List elements) { return elements.stream() .filter( accessorNaming::isAdderMethod ) - .map( method -> new ExecutableElementAccessor( method, getFirstParameter( method ), ADDER ) ) + .map( method -> new ElementAccessor( method, getFirstParameter( method ), ADDER ) ) .collect( Collectors.toCollection( LinkedList::new ) ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java deleted file mode 100644 index 04c4c99992..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/AbstractAccessor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.accessor; - -import java.util.Set; - -import javax.lang.model.element.Element; -import javax.lang.model.element.Modifier; - -/** - * This is an abstract implementation of an {@link Accessor} that provides the common implementation. - * - * @author Filip Hrisafov - */ -abstract class AbstractAccessor implements Accessor { - - protected final T element; - - AbstractAccessor(T element) { - this.element = element; - } - - @Override - public String getSimpleName() { - return element.getSimpleName().toString(); - } - - @Override - public Set getModifiers() { - return element.getModifiers(); - } - - @Override - public T getElement() { - return element; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java index 24e71cc85f..4b363815b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ElementAccessor.java @@ -5,31 +5,61 @@ */ package org.mapstruct.ap.internal.util.accessor; +import java.util.Set; import javax.lang.model.element.Element; +import javax.lang.model.element.Modifier; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; /** - * An {@link Accessor} that wraps a {@link VariableElement}. - * + * An {@link Accessor} that wraps a {@link Element}. + * Used for getter, setter, filed, constructor, record-class, etc. * @author Filip Hrisafov + * @author Tang Yang */ -public class ElementAccessor extends AbstractAccessor { +public class ElementAccessor implements Accessor { + private final Element element; + private final String name; private final AccessorType accessorType; + private final TypeMirror accessedType; + + public ElementAccessor(VariableElement variableElement, TypeMirror accessedType) { + this( variableElement, accessedType, AccessorType.FIELD ); + } - public ElementAccessor(VariableElement variableElement) { - this( variableElement, AccessorType.FIELD ); + public ElementAccessor(Element element, TypeMirror accessedType, String name) { + this.element = element; + this.name = name; + this.accessedType = accessedType; + this.accessorType = AccessorType.PARAMETER; } - public ElementAccessor(Element element, AccessorType accessorType) { - super( element ); + public ElementAccessor(Element element, TypeMirror accessedType, AccessorType accessorType) { + this.element = element; + this.accessedType = accessedType; this.accessorType = accessorType; + this.name = null; } @Override public TypeMirror getAccessedType() { - return element.asType(); + return accessedType != null ? accessedType : element.asType(); + } + + @Override + public String getSimpleName() { + return name != null ? name : element.getSimpleName().toString(); + } + + @Override + public Set getModifiers() { + return element.getModifiers(); + } + + @Override + public Element getElement() { + return element; } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java deleted file mode 100644 index af37acbce1..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ExecutableElementAccessor.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.accessor; - -import javax.lang.model.element.ExecutableElement; -import javax.lang.model.type.TypeMirror; - -/** - * An {@link Accessor} that wraps an {@link ExecutableElement}. - * - * @author Filip Hrisafov - */ -public class ExecutableElementAccessor extends AbstractAccessor { - - private final TypeMirror accessedType; - private final AccessorType accessorType; - - public ExecutableElementAccessor(ExecutableElement element, TypeMirror accessedType, AccessorType accessorType) { - super( element ); - this.accessedType = accessedType; - this.accessorType = accessorType; - } - - @Override - public TypeMirror getAccessedType() { - return accessedType; - } - - @Override - public String toString() { - return element.toString(); - } - - @Override - public AccessorType getAccessorType() { - return accessorType; - } -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java deleted file mode 100644 index 9991370059..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ParameterElementAccessor.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.accessor; - -import javax.lang.model.element.Element; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeMirror; - -/** - * An {@link Accessor} that wraps a {@link VariableElement}. - * - * @author Filip Hrisafov - */ -public class ParameterElementAccessor extends AbstractAccessor { - - protected final String name; - protected final TypeMirror accessedType; - - public ParameterElementAccessor(Element element, TypeMirror accessedType, String name) { - super( element ); - this.name = name; - this.accessedType = accessedType; - } - - @Override - public String getSimpleName() { - return name != null ? name : super.getSimpleName(); - } - - @Override - public TypeMirror getAccessedType() { - return accessedType; - } - - @Override - public String toString() { - return element.toString(); - } - - @Override - public AccessorType getAccessorType() { - return AccessorType.PARAMETER; - } - -} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java index 5177bfc75b..31edf3a6da 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java @@ -17,8 +17,8 @@ public interface ReadAccessor extends Accessor { String getReadValueSource(); - static ReadAccessor fromField(VariableElement variableElement) { - return new ReadDelegateAccessor( new ElementAccessor( variableElement ) ) { + static ReadAccessor fromField(VariableElement variableElement, TypeMirror accessedType) { + return new ReadDelegateAccessor( new ElementAccessor( variableElement, accessedType ) ) { @Override public String getReadValueSource() { return getSimpleName(); @@ -26,8 +26,8 @@ public String getReadValueSource() { }; } - static ReadAccessor fromRecordComponent(Element element) { - return new ReadDelegateAccessor( new ElementAccessor( element, AccessorType.GETTER ) ) { + static ReadAccessor fromRecordComponent(Element element, TypeMirror accessedType) { + return new ReadDelegateAccessor( new ElementAccessor( element, accessedType, AccessorType.GETTER ) ) { @Override public String getReadValueSource() { return getSimpleName() + "()"; @@ -36,7 +36,7 @@ public String getReadValueSource() { } static ReadAccessor fromGetter(ExecutableElement element, TypeMirror accessedType) { - return new ReadDelegateAccessor( new ExecutableElementAccessor( element, accessedType, AccessorType.GETTER ) ) { + return new ReadDelegateAccessor( new ElementAccessor( element, accessedType, AccessorType.GETTER ) ) { @Override public String getReadValueSource() { return getSimpleName() + "()"; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java deleted file mode 100644 index d163f462f9..0000000000 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/RecordElementAccessor.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright MapStruct Authors. - * - * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 - */ -package org.mapstruct.ap.internal.util.accessor; - -import javax.lang.model.element.Element; -import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeMirror; - -/** - * An {@link Accessor} that wraps a {@link VariableElement}. - * - * @author Filip Hrisafov - */ -public class RecordElementAccessor extends AbstractAccessor { - - public RecordElementAccessor(Element element) { - super( element ); - } - - @Override - public TypeMirror getAccessedType() { - return element.asType(); - } - - @Override - public String toString() { - return element.toString(); - } - - @Override - public AccessorType getAccessorType() { - return AccessorType.GETTER; - } - -} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Mapper.java new file mode 100644 index 0000000000..83ee1f32bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Mapper.java @@ -0,0 +1,48 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3807; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface Issue3807Mapper { + Issue3807Mapper INSTANCE = Mappers.getMapper( Issue3807Mapper.class ); + + TargetWithoutSetter mapNoSetter(Source target); + + NormalTarget mapNormalSource(Source target); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + //CHECKSTYLE:OFF + class TargetWithoutSetter { + public T value; + } + //CHECKSTYLE:ON + + class NormalTarget { + private T value; + + public T getValue() { + return value; + } + + public void setValue(T value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java new file mode 100644 index 0000000000..3b895f3e11 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3807; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses(Issue3807Mapper.class) +@IssueKey("3087") +class Issue3807Test { + + @ProcessorTest + void fieldAndSetterShouldWorkWithGeneric() { + Issue3807Mapper.Source source = new Issue3807Mapper.Source( "value" ); + Issue3807Mapper.TargetWithoutSetter targetWithoutSetter = + Issue3807Mapper.INSTANCE.mapNoSetter( source ); + + assertThat( targetWithoutSetter ).isNotNull(); + assertThat( targetWithoutSetter.value ).isEqualTo( "value" ); + + Issue3807Mapper.NormalTarget normalTarget = Issue3807Mapper.INSTANCE.mapNormalSource( source ); + + assertThat( normalTarget ).isNotNull(); + assertThat( normalTarget.getValue() ).isEqualTo( "value" ); + } +} From ce84c81de2ee809c1457dfb9078ec1ae785ad323 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sat, 31 May 2025 23:52:05 +0800 Subject: [PATCH 0902/1006] #3659: Support `@AnnotatedWith` on decorators Signed-off-by: TangYang --- .../ap/internal/model/Decorator.java | 20 ++- ...nnotationBasedComponentModelProcessor.java | 6 +- .../processor/JakartaComponentProcessor.java | 3 +- .../processor/Jsr330ComponentProcessor.java | 3 +- .../processor/MapperCreationProcessor.java | 5 + .../processor/SpringComponentProcessor.java | 130 ++++++++++++------ .../ap/test/decorator/AnnotatedMapper.java | 43 ++++++ .../decorator/AnnotatedMapperDecorator.java | 18 +++ .../DecoratedWithAnnotatedWithTest.java | 32 +++++ .../ap/test/decorator/TestAnnotation.java | 20 +++ .../JakartaAnnotateWithMapper.java | 40 ++++++ ...akartaAnnotateWithWithMapperDecorator.java | 31 +++++ .../JakartaDecoratorAnnotateWithTest.java | 59 ++++++++ .../decorator/jsr330/Jsr330DecoratorTest.java | 10 +- .../Jsr330AnnotateWithMapper.java | 28 ++++ .../Jsr330AnnotateWithMapperDecorator.java | 32 +++++ .../Jsr330DecoratorAnnotateWithTest.java | 95 +++++++++++++ .../spring/annotatewith/AnnotateMapper.java | 25 ++++ .../annotatewith/AnnotateMapperDecorator.java | 30 ++++ .../annotatewith/CustomAnnotateMapper.java | 25 ++++ .../CustomAnnotateMapperDecorator.java | 28 ++++ .../spring/annotatewith/CustomComponent.java | 20 +++ .../spring/annotatewith/CustomPrimary.java | 19 +++ .../SpringDecoratorAnnotateWithTest.java | 118 ++++++++++++++++ 24 files changed, 791 insertions(+), 49 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratedWithAnnotatedWithTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/TestAnnotation.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithWithMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaDecoratorAnnotateWithTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330DecoratorAnnotateWithTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapperDecorator.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomComponent.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomPrimary.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/SpringDecoratorAnnotateWithTest.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java index b7dc0effcb..df7940da31 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Decorator.java @@ -7,14 +7,15 @@ import java.util.Arrays; import java.util.List; +import java.util.Set; import java.util.SortedSet; import javax.lang.model.element.TypeElement; +import org.mapstruct.ap.internal.gem.DecoratedWithGem; import org.mapstruct.ap.internal.model.common.Accessibility; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.option.Options; -import org.mapstruct.ap.internal.gem.DecoratedWithGem; import org.mapstruct.ap.internal.version.VersionInformation; /** @@ -33,6 +34,7 @@ public static class Builder extends GeneratedTypeBuilder { private String implName; private String implPackage; private boolean suppressGeneratorTimestamp; + private Set customAnnotations; public Builder() { super( Builder.class ); @@ -68,6 +70,11 @@ public Builder suppressGeneratorTimestamp(boolean suppressGeneratorTimestamp) { return this; } + public Builder additionalAnnotations(Set customAnnotations) { + this.customAnnotations = customAnnotations; + return this; + } + public Decorator build() { String implementationName = implName.replace( Mapper.CLASS_NAME_PLACEHOLDER, Mapper.getFlatName( mapperElement ) ); @@ -95,7 +102,8 @@ public Decorator build() { suppressGeneratorTimestamp, Accessibility.fromModifiers( mapperElement.getModifiers() ), extraImportedTypes, - decoratorConstructor + decoratorConstructor, + customAnnotations ); } } @@ -110,7 +118,8 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type Options options, VersionInformation versionInformation, boolean suppressGeneratorTimestamp, Accessibility accessibility, SortedSet extraImports, - DecoratorConstructor decoratorConstructor) { + DecoratorConstructor decoratorConstructor, + Set customAnnotations) { super( typeFactory, packageName, @@ -128,6 +137,11 @@ private Decorator(TypeFactory typeFactory, String packageName, String name, Type this.decoratorType = decoratorType; this.mapperType = mapperType; + + // Add custom annotations + if ( customAnnotations != null ) { + customAnnotations.forEach( this::addAnnotation ); + } } @Override diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java index 014ceda58e..bbd695412a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/AnnotationBasedComponentModelProcessor.java @@ -14,6 +14,7 @@ import java.util.stream.Collectors; import javax.lang.model.element.TypeElement; +import org.mapstruct.ap.internal.gem.InjectionStrategyGem; import org.mapstruct.ap.internal.model.AnnotatedConstructor; import org.mapstruct.ap.internal.model.AnnotatedSetter; import org.mapstruct.ap.internal.model.Annotation; @@ -24,7 +25,6 @@ import org.mapstruct.ap.internal.model.MapperReference; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.gem.InjectionStrategyGem; import org.mapstruct.ap.internal.model.source.MapperOptions; /** @@ -88,7 +88,7 @@ else if ( injectionStrategy == InjectionStrategyGem.SETTER ) { protected void adjustDecorator(Mapper mapper, InjectionStrategyGem injectionStrategy) { Decorator decorator = mapper.getDecorator(); - for ( Annotation typeAnnotation : getDecoratorAnnotations() ) { + for ( Annotation typeAnnotation : getDecoratorAnnotations( decorator ) ) { decorator.addAnnotation( typeAnnotation ); } @@ -308,7 +308,7 @@ protected Field replacementMapperReference(Field originalReference, List getDecoratorAnnotations() { + protected List getDecoratorAnnotations(Decorator decorator) { return Collections.emptyList(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java index 999c0a51df..86c95d612b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/JakartaComponentProcessor.java @@ -11,6 +11,7 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; +import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; @@ -39,7 +40,7 @@ protected List getTypeAnnotations(Mapper mapper) { } @Override - protected List getDecoratorAnnotations() { + protected List getDecoratorAnnotations(Decorator decorator) { return Arrays.asList( singleton(), named() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java index 00ba72a079..7770eff16c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/Jsr330ComponentProcessor.java @@ -11,6 +11,7 @@ import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; +import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; @@ -42,7 +43,7 @@ protected List getTypeAnnotations(Mapper mapper) { } @Override - protected List getDecoratorAnnotations() { + protected List getDecoratorAnnotations(Decorator decorator) { return Arrays.asList( singleton(), named() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 3b38a05b59..4fbed6cbec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -33,6 +33,7 @@ import org.mapstruct.ap.internal.gem.MappingInheritanceStrategyGem; import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.model.AdditionalAnnotationsBuilder; +import org.mapstruct.ap.internal.model.Annotation; import org.mapstruct.ap.internal.model.BeanMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethod; import org.mapstruct.ap.internal.model.ContainerMappingMethodBuilder; @@ -287,6 +288,9 @@ else if ( constructor.getParameters().size() == 1 ) { messager.printMessage( element, decoratedWith.mirror(), Message.DECORATOR_CONSTRUCTOR ); } + // Get annotations from the decorator class + Set decoratorAnnotations = additionalAnnotationsBuilder.getProcessedAnnotations( decoratorElement ); + Decorator decorator = new Decorator.Builder() .elementUtils( elementUtils ) .typeFactory( typeFactory ) @@ -300,6 +304,7 @@ else if ( constructor.getParameters().size() == 1 ) { .implPackage( mapperOptions.implementationPackage() ) .extraImports( getExtraImports( element, mapperOptions ) ) .suppressGeneratorTimestamp( mapperOptions.suppressTimestampInGenerated() ) + .additionalAnnotations( decoratorAnnotations ) .build(); return decorator; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java index 84a672bcc9..c31ac51f06 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/SpringComponentProcessor.java @@ -9,20 +9,22 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; import org.mapstruct.ap.internal.gem.MappingConstantsGem; import org.mapstruct.ap.internal.model.Annotation; +import org.mapstruct.ap.internal.model.Decorator; import org.mapstruct.ap.internal.model.Mapper; import org.mapstruct.ap.internal.model.annotation.AnnotationElement; import org.mapstruct.ap.internal.model.annotation.AnnotationElement.AnnotationElementType; -import javax.lang.model.element.AnnotationMirror; -import javax.lang.model.element.Element; -import javax.lang.model.element.PackageElement; -import javax.lang.model.element.TypeElement; - import static javax.lang.model.element.ElementKind.PACKAGE; /** @@ -35,6 +37,9 @@ */ public class SpringComponentProcessor extends AnnotationBasedComponentModelProcessor { + private static final String SPRING_COMPONENT_ANNOTATION = "org.springframework.stereotype.Component"; + private static final String SPRING_PRIMARY_ANNOTATION = "org.springframework.context.annotation.Primary"; + @Override protected String getComponentModelIdentifier() { return MappingConstantsGem.ComponentModelGem.SPRING; @@ -54,12 +59,37 @@ protected List getTypeAnnotations(Mapper mapper) { return typeAnnotations; } + /** + * Returns the annotations that need to be added to the generated decorator, filtering out any annotations + * that are already present or represented as meta-annotations. + * + * @param decorator the decorator to process + * @return A list of annotations that should be added to the generated decorator. + */ @Override - protected List getDecoratorAnnotations() { - return Arrays.asList( - component(), - primary() - ); + protected List getDecoratorAnnotations(Decorator decorator) { + Set desiredAnnotationNames = new LinkedHashSet<>(); + desiredAnnotationNames.add( SPRING_COMPONENT_ANNOTATION ); + desiredAnnotationNames.add( SPRING_PRIMARY_ANNOTATION ); + List decoratorAnnotations = decorator.getAnnotations(); + if ( !decoratorAnnotations.isEmpty() ) { + Set handledElements = new HashSet<>(); + for ( Annotation annotation : decoratorAnnotations ) { + removeAnnotationsPresentOnElement( + annotation.getType().getTypeElement(), + desiredAnnotationNames, + handledElements + ); + if ( desiredAnnotationNames.isEmpty() ) { + // If all annotations are removed, we can stop further processing + return Collections.emptyList(); + } + } + } + + return desiredAnnotationNames.stream() + .map( this::createAnnotation ) + .collect( Collectors.toList() ); } @Override @@ -82,8 +112,12 @@ protected boolean requiresGenerationOfDecoratorClass() { return true; } + private Annotation createAnnotation(String canonicalName) { + return new Annotation( getTypeFactory().getType( canonicalName ) ); + } + private Annotation autowired() { - return new Annotation( getTypeFactory().getType( "org.springframework.beans.factory.annotation.Autowired" ) ); + return createAnnotation( "org.springframework.beans.factory.annotation.Autowired" ); } private Annotation qualifierDelegate() { @@ -96,34 +130,51 @@ private Annotation qualifierDelegate() { ) ) ); } - private Annotation primary() { - return new Annotation( getTypeFactory().getType( "org.springframework.context.annotation.Primary" ) ); - } - private Annotation component() { - return new Annotation( getTypeFactory().getType( "org.springframework.stereotype.Component" ) ); + return createAnnotation( SPRING_COMPONENT_ANNOTATION ); } private boolean isAlreadyAnnotatedAsSpringStereotype(Mapper mapper) { - Set handledElements = new HashSet<>(); - return mapper.getAnnotations() - .stream() - .anyMatch( - annotation -> isOrIncludesComponentAnnotation( annotation, handledElements ) - ); - } + Set desiredAnnotationNames = new LinkedHashSet<>(); + desiredAnnotationNames.add( SPRING_COMPONENT_ANNOTATION ); + + List mapperAnnotations = mapper.getAnnotations(); + if ( !mapperAnnotations.isEmpty() ) { + Set handledElements = new HashSet<>(); + for ( Annotation annotation : mapperAnnotations ) { + removeAnnotationsPresentOnElement( + annotation.getType().getTypeElement(), + desiredAnnotationNames, + handledElements + ); + if ( desiredAnnotationNames.isEmpty() ) { + // If all annotations are removed, we can stop further processing + return true; + } + } + } - private boolean isOrIncludesComponentAnnotation(Annotation annotation, Set handledElements) { - return isOrIncludesComponentAnnotation( - annotation.getType().getTypeElement(), handledElements - ); + return false; } - private boolean isOrIncludesComponentAnnotation(Element element, Set handledElements) { - if ( "org.springframework.stereotype.Component".equals( - ( (TypeElement) element ).getQualifiedName().toString() - )) { - return true; + /** + * Removes all the annotations and meta-annotations from {@code annotations} which are on the given element. + * + * @param element the element to check + * @param annotations the annotations to check for + * @param handledElements set of already handled elements to avoid infinite recursion + */ + private void removeAnnotationsPresentOnElement(Element element, Set annotations, + Set handledElements) { + if ( annotations.isEmpty() ) { + return; + } + if ( element instanceof TypeElement && + annotations.remove( ( (TypeElement) element ).getQualifiedName().toString() ) ) { + if ( annotations.isEmpty() ) { + // If all annotations are removed, we can stop further processing + return; + } } for ( AnnotationMirror annotationMirror : element.getAnnotationMirrors() ) { @@ -132,17 +183,16 @@ private boolean isOrIncludesComponentAnnotation(Element element, Set ha if ( !isAnnotationInPackage( annotationMirrorElement, "java.lang.annotation" ) && !handledElements.contains( annotationMirrorElement ) ) { handledElements.add( annotationMirrorElement ); - boolean isOrIncludesComponentAnnotation = isOrIncludesComponentAnnotation( - annotationMirrorElement, handledElements - ); - - if ( isOrIncludesComponentAnnotation ) { - return true; + if ( annotations.remove( ( (TypeElement) annotationMirrorElement ).getQualifiedName().toString() ) ) { + if ( annotations.isEmpty() ) { + // If all annotations are removed, we can stop further processing + return; + } } + + removeAnnotationsPresentOnElement( element, annotations, handledElements ); } } - - return false; } private PackageElement getPackageOf( Element element ) { diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapper.java new file mode 100644 index 0000000000..6da0d70c93 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapper.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +@DecoratedWith(AnnotatedMapperDecorator.class) +public interface AnnotatedMapper { + + AnnotatedMapper INSTANCE = Mappers.getMapper( AnnotatedMapper.class ); + + Target toTarget(Source source); + + class Source { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Target { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapperDecorator.java new file mode 100644 index 0000000000..6bf7a1fd66 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/AnnotatedMapperDecorator.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator; + +import org.mapstruct.AnnotateWith; + +@AnnotateWith(value = TestAnnotation.class, elements = @AnnotateWith.Element(strings = "decoratorValue")) +public abstract class AnnotatedMapperDecorator implements AnnotatedMapper { + + private final AnnotatedMapper delegate; + + public AnnotatedMapperDecorator(AnnotatedMapper delegate) { + this.delegate = delegate; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratedWithAnnotatedWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratedWithAnnotatedWithTest.java new file mode 100644 index 0000000000..1e3d574a6d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/DecoratedWithAnnotatedWithTest.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the application of @AnnotatedWith on decorator classes. + */ +@IssueKey("3659") +@WithClasses({ + TestAnnotation.class, + AnnotatedMapper.class, + AnnotatedMapperDecorator.class +}) +public class DecoratedWithAnnotatedWithTest { + + @ProcessorTest + public void shouldApplyAnnotationFromDecorator() { + Class implementationClass = AnnotatedMapper.INSTANCE.getClass(); + + assertThat( implementationClass ).hasAnnotation( TestAnnotation.class ); + assertThat( implementationClass.getAnnotation( TestAnnotation.class ).value() ).isEqualTo( "decoratorValue" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/TestAnnotation.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/TestAnnotation.java new file mode 100644 index 0000000000..742184d261 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/TestAnnotation.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Test annotation for testing @AnnotatedWith on decorators. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + String value() default ""; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithMapper.java new file mode 100644 index 0000000000..a1a754158b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithMapper.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.annotatewith; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +/** + * A mapper using Jakarta component model with a decorator. + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JAKARTA) +@DecoratedWith(JakartaAnnotateWithWithMapperDecorator.class) +public interface JakartaAnnotateWithMapper { + + /** + * Maps a person to a person DTO. + * + * @param person the person to map + * @return the person DTO + */ + @Mapping(target = "name", ignore = true) + PersonDto personToPersonDto(Person person); + + /** + * Maps an address to an address DTO. + * + * @param address the address to map + * @return the address DTO + */ + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithWithMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithWithMapperDecorator.java new file mode 100644 index 0000000000..89a42aaf6e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaAnnotateWithWithMapperDecorator.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.annotatewith; + +import jakarta.inject.Inject; +import jakarta.inject.Named; +import org.mapstruct.AnnotateWith; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.test.decorator.TestAnnotation; + +/** + * A decorator for {@link JakartaAnnotateWithMapper}. + */ +@AnnotateWith(value = TestAnnotation.class) +public abstract class JakartaAnnotateWithWithMapperDecorator implements JakartaAnnotateWithMapper { + + @Inject + @Named("org.mapstruct.ap.test.decorator.jakarta.annotatewith.JakartaAnnotateWithMapperImpl_") + private JakartaAnnotateWithMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaDecoratorAnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaDecoratorAnnotateWithTest.java new file mode 100644 index 0000000000..d98e26b217 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jakarta/annotatewith/JakartaDecoratorAnnotateWithTest.java @@ -0,0 +1,59 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jakarta.annotatewith; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.test.decorator.TestAnnotation; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJakartaInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static java.lang.System.lineSeparator; + +/** + * Test for the application of @AnnotateWith on decorator classes with Jakarta component model. + */ +@IssueKey("3659") +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + JakartaAnnotateWithMapper.class, + TestAnnotation.class, + JakartaAnnotateWithWithMapperDecorator.class +}) +@WithJakartaInject +public class JakartaDecoratorAnnotateWithTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + public void hasCorrectImports() { + // check the decorator + generatedSource.forMapper( JakartaAnnotateWithMapper.class ) + .content() + .contains( "import jakarta.inject.Inject;" ) + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@TestAnnotation" ) + .contains( "@Singleton" + lineSeparator() + "@Named" ) + .doesNotContain( "javax.inject" ); + // check the plain mapper + generatedSource.forDecoratedMapper( JakartaAnnotateWithMapper.class ).content() + .contains( "import jakarta.inject.Named;" ) + .contains( "import jakarta.inject.Singleton;" ) + .contains( "@Singleton" + lineSeparator() + "@Named" ) + .doesNotContain( "javax.inject" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java index be1a67cf09..a29310b9ed 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/Jsr330DecoratorTest.java @@ -18,6 +18,7 @@ import org.mapstruct.ap.test.decorator.AddressDto; import org.mapstruct.ap.test.decorator.Person; import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.test.decorator.jsr330.annotatewith.Jsr330DecoratorAnnotateWithTest; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; @@ -27,6 +28,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; import static java.lang.System.lineSeparator; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +47,13 @@ PersonMapperDecorator.class }) @IssueKey("592") -@ComponentScan(basePackageClasses = Jsr330DecoratorTest.class) +@ComponentScan( + basePackageClasses = Jsr330DecoratorTest.class, + excludeFilters = @ComponentScan.Filter( + type = FilterType.ASSIGNABLE_TYPE, + classes = { Jsr330DecoratorAnnotateWithTest.class } + ) +) @Configuration @WithJavaxInject @DisabledOnJre(JRE.OTHER) diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapper.java new file mode 100644 index 0000000000..7e6ab8b7bd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapper.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jsr330.annotatewith; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +/** + * A mapper using JSR-330 component model with a decorator. + */ +@Mapper(componentModel = MappingConstants.ComponentModel.JSR330) +@DecoratedWith(Jsr330AnnotateWithMapperDecorator.class) +public interface Jsr330AnnotateWithMapper { + + @Mapping(target = "name", ignore = true) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapperDecorator.java new file mode 100644 index 0000000000..96cee9f824 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330AnnotateWithMapperDecorator.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jsr330.annotatewith; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.test.decorator.TestAnnotation; + +/** + * A decorator for {@link Jsr330AnnotateWithMapper}. + */ +@AnnotateWith(value = TestAnnotation.class) +public abstract class Jsr330AnnotateWithMapperDecorator implements Jsr330AnnotateWithMapper { + + @Inject + @Named("org.mapstruct.ap.test.decorator.jsr330.annotatewith.Jsr330AnnotateWithMapperImpl_") + private Jsr330AnnotateWithMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330DecoratorAnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330DecoratorAnnotateWithTest.java new file mode 100644 index 0000000000..19d77dd5cb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/jsr330/annotatewith/Jsr330DecoratorAnnotateWithTest.java @@ -0,0 +1,95 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.jsr330.annotatewith; + +import java.util.Calendar; +import javax.inject.Inject; +import javax.inject.Named; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.test.decorator.TestAnnotation; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithJavaxInject; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the application of @AnnotateWith on decorator classes with JSR-330 component model. + */ +@IssueKey("3659") +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + Jsr330AnnotateWithMapper.class, + Jsr330AnnotateWithMapperDecorator.class, + TestAnnotation.class +}) +@ComponentScan(basePackageClasses = Jsr330DecoratorAnnotateWithTest.class) +@Configuration +@WithJavaxInject +@DisabledOnJre(JRE.OTHER) +public class Jsr330DecoratorAnnotateWithTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @Inject + @Named + private Jsr330AnnotateWithMapper jsr330AnnotateWithMapper; + + private ConfigurableApplicationContext context; + + @BeforeEach + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @AfterEach + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @ProcessorTest + public void shouldContainCustomAnnotation() { + generatedSource.forMapper( Jsr330AnnotateWithMapper.class ) + .content() + .contains( "@TestAnnotation" ); + } + + @ProcessorTest + public void shouldInvokeDecoratorMethods() { + Calendar birthday = Calendar.getInstance(); + birthday.set( 1928, Calendar.MAY, 23 ); + Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); + + PersonDto personDto = jsr330AnnotateWithMapper.personToPersonDto( person ); + + assertThat( personDto ).isNotNull(); + assertThat( personDto.getName() ).isEqualTo( "Gary Crant" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapper.java new file mode 100644 index 0000000000..0ba8e88299 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) +@DecoratedWith(AnnotateMapperDecorator.class) +public interface AnnotateMapper { + + @Mapping(target = "name", ignore = true) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapperDecorator.java new file mode 100644 index 0000000000..cff0a4c148 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/AnnotateMapperDecorator.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@AnnotateWith(value = Component.class, elements = @AnnotateWith.Element(strings = "decoratorComponent")) +@AnnotateWith(value = Primary.class) +public abstract class AnnotateMapperDecorator implements AnnotateMapper { + + @Autowired + @Qualifier("delegate") + private AnnotateMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapper.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapper.java new file mode 100644 index 0000000000..9e2e35676c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import org.mapstruct.DecoratedWith; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingConstants; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; + +@Mapper(componentModel = MappingConstants.ComponentModel.SPRING) +@DecoratedWith(CustomAnnotateMapperDecorator.class) +public interface CustomAnnotateMapper { + + @Mapping(target = "name", ignore = true) + PersonDto personToPersonDto(Person person); + + AddressDto addressToAddressDto(Address address); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapperDecorator.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapperDecorator.java new file mode 100644 index 0000000000..3668d98b04 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomAnnotateMapperDecorator.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import org.mapstruct.AnnotateWith; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +@AnnotateWith(value = CustomComponent.class, elements = @AnnotateWith.Element(strings = "customComponentDecorator")) +@AnnotateWith(value = CustomPrimary.class) +public abstract class CustomAnnotateMapperDecorator implements CustomAnnotateMapper { + + @Autowired + @Qualifier("delegate") + private CustomAnnotateMapper delegate; + + @Override + public PersonDto personToPersonDto(Person person) { + PersonDto dto = delegate.personToPersonDto( person ); + dto.setName( person.getFirstName() + " " + person.getLastName() ); + return dto; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomComponent.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomComponent.java new file mode 100644 index 0000000000..be71249f2a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomComponent.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.stereotype.Component; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Component +public @interface CustomComponent { + String value() default ""; +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomPrimary.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomPrimary.java new file mode 100644 index 0000000000..4e18bdbc7d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/CustomPrimary.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.context.annotation.Primary; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Primary +public @interface CustomPrimary { +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/SpringDecoratorAnnotateWithTest.java b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/SpringDecoratorAnnotateWithTest.java new file mode 100644 index 0000000000..7b3911c22b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/decorator/spring/annotatewith/SpringDecoratorAnnotateWithTest.java @@ -0,0 +1,118 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.decorator.spring.annotatewith; + +import java.util.Calendar; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.test.decorator.Address; +import org.mapstruct.ap.test.decorator.AddressDto; +import org.mapstruct.ap.test.decorator.Person; +import org.mapstruct.ap.test.decorator.PersonDto; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithSpring; +import org.mapstruct.ap.testutil.runner.GeneratedSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test for the application of @AnnotateWith on decorator classes with Spring component model. + */ +@IssueKey("3659") +@WithClasses({ + Person.class, + PersonDto.class, + Address.class, + AddressDto.class, + AnnotateMapper.class, + AnnotateMapperDecorator.class, + CustomComponent.class, + CustomPrimary.class, + CustomAnnotateMapper.class, + CustomAnnotateMapperDecorator.class +}) +@WithSpring +@ComponentScan(basePackageClasses = SpringDecoratorAnnotateWithTest.class) +@Configuration +public class SpringDecoratorAnnotateWithTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @Autowired + private AnnotateMapper annotateMapper; + + @Autowired + private CustomAnnotateMapper customAnnotateMapper; + + private ConfigurableApplicationContext context; + + @BeforeEach + public void springUp() { + context = new AnnotationConfigApplicationContext( getClass() ); + context.getAutowireCapableBeanFactory().autowireBean( this ); + } + + @AfterEach + public void springDown() { + if ( context != null ) { + context.close(); + } + } + + @ProcessorTest + public void shouldNotDuplicateComponentAnnotation() { + generatedSource.forMapper( AnnotateMapper.class ) + .content() + .contains( "@Component(value = \"decoratorComponent\")", "@Primary" ) + .doesNotContain( "@Component" + System.lineSeparator() ); + } + + @ProcessorTest + public void shouldNotDuplicateCustomComponentAnnotation() { + generatedSource.forMapper( CustomAnnotateMapper.class ) + .content() + .contains( "@CustomComponent(value = \"customComponentDecorator\")", "@CustomPrimary" ) + .doesNotContain( "@Component" ); + } + + @ProcessorTest + public void shouldInvokeAnnotateDecoratorMethods() { + Calendar birthday = Calendar.getInstance(); + birthday.set( 1928, Calendar.MAY, 23 ); + Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); + + PersonDto personDto = annotateMapper.personToPersonDto( person ); + + assertThat( personDto ).isNotNull(); + assertThat( personDto.getName() ).isEqualTo( "Gary Crant" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } + + @ProcessorTest + public void shouldInvokeCustomAnnotateDecoratorMethods() { + Calendar birthday = Calendar.getInstance(); + birthday.set( 1928, Calendar.MAY, 23 ); + Person person = new Person( "Gary", "Crant", birthday.getTime(), new Address( "42 Ocean View Drive" ) ); + + PersonDto personDto = customAnnotateMapper.personToPersonDto( person ); + + assertThat( personDto ).isNotNull(); + assertThat( personDto.getName() ).isEqualTo( "Gary Crant" ); + assertThat( personDto.getAddress() ).isNotNull(); + assertThat( personDto.getAddress().getAddressLine() ).isEqualTo( "42 Ocean View Drive" ); + } +} From 9847eaf195cb891c5a47df96db2b90a1b335b75b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 31 May 2025 18:14:13 +0200 Subject: [PATCH 0903/1006] #3876: Move Windows and Mac OS builds outside of the main workflow --- .github/workflows/macos.yml | 20 ++++++++++++++++++++ .github/workflows/main.yml | 24 ------------------------ .github/workflows/windows.yml | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/macos.yml create mode 100644 .github/workflows/windows.yml diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000000..833bb6ba39 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,20 @@ +name: Mac OS CI + +on: push + +env: + MAVEN_ARGS: -V -B --no-transfer-progress -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 + +jobs: + mac: + name: 'Mac OS' + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: 'Set up JDK 21' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: 'Test' + run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 166466348d..b6a2ef371e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,27 +58,3 @@ jobs: java-version: ${{ matrix.java }} - name: 'Run integration tests' run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest - windows: - name: 'Windows' - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - name: 'Set up JDK 21' - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: 21 - - name: 'Test' - run: ./mvnw %MAVEN_ARGS% install - mac: - name: 'Mac OS' - runs-on: macos-latest - steps: - - uses: actions/checkout@v3 - - name: 'Set up JDK 21' - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: 21 - - name: 'Test' - run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000000..bda38f8783 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,20 @@ +name: Windows CI + +on: push + +env: + MAVEN_ARGS: -V -B --no-transfer-progress -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 + +jobs: + windows: + name: 'Windows' + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: 'Set up JDK 21' + uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 21 + - name: 'Test' + run: ./mvnw %MAVEN_ARGS% install From 46ce011e4bd9b9fbcc0f0d337d5ad631f5d214b2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Jun 2025 07:52:18 +0200 Subject: [PATCH 0904/1006] Refactor options and add an enum (#3877) --- .../org/mapstruct/ap/MappingProcessor.java | 101 ++++++------------ .../internal/model/source/DefaultOptions.java | 20 ++-- .../ap/internal/option/MappingOption.java | 43 ++++++++ .../mapstruct/ap/internal/option/Options.java | 89 +++++++-------- 4 files changed, 128 insertions(+), 125 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index b34b133262..a66762d739 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -13,17 +13,16 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.ServiceLoader; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; -import javax.annotation.processing.SupportedOptions; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -35,9 +34,8 @@ import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.gem.MapperGem; -import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; -import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.Mapper; +import org.mapstruct.ap.internal.option.MappingOption; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext; import org.mapstruct.ap.internal.processor.ModelElementProcessor; @@ -84,19 +82,6 @@ * @author Gunnar Morling */ @SupportedAnnotationTypes("org.mapstruct.Mapper") -@SupportedOptions({ - MappingProcessor.SUPPRESS_GENERATOR_TIMESTAMP, - MappingProcessor.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT, - MappingProcessor.UNMAPPED_TARGET_POLICY, - MappingProcessor.UNMAPPED_SOURCE_POLICY, - MappingProcessor.DEFAULT_COMPONENT_MODEL, - MappingProcessor.DEFAULT_INJECTION_STRATEGY, - MappingProcessor.DISABLE_BUILDERS, - MappingProcessor.VERBOSE, - MappingProcessor.NULL_VALUE_ITERABLE_MAPPING_STRATEGY, - MappingProcessor.NULL_VALUE_MAP_MAPPING_STRATEGY, - MappingProcessor.DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR, -}) public class MappingProcessor extends AbstractProcessor { /** @@ -104,20 +89,32 @@ public class MappingProcessor extends AbstractProcessor { */ private static final boolean ANNOTATIONS_CLAIMED_EXCLUSIVELY = false; - protected static final String SUPPRESS_GENERATOR_TIMESTAMP = "mapstruct.suppressGeneratorTimestamp"; - protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT = - "mapstruct.suppressGeneratorVersionInfoComment"; - protected static final String UNMAPPED_TARGET_POLICY = "mapstruct.unmappedTargetPolicy"; - protected static final String UNMAPPED_SOURCE_POLICY = "mapstruct.unmappedSourcePolicy"; - protected static final String DEFAULT_COMPONENT_MODEL = "mapstruct.defaultComponentModel"; - protected static final String DEFAULT_INJECTION_STRATEGY = "mapstruct.defaultInjectionStrategy"; - protected static final String ALWAYS_GENERATE_SERVICE_FILE = "mapstruct.alwaysGenerateServicesFile"; - protected static final String DISABLE_BUILDERS = "mapstruct.disableBuilders"; - protected static final String VERBOSE = "mapstruct.verbose"; - protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY = "mapstruct.nullValueIterableMappingStrategy"; - protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY = "mapstruct.nullValueMapMappingStrategy"; - protected static final String DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR = - "mapstruct.disableLifecycleOverloadDeduplicateSelector"; + // CHECKSTYLE:OFF + // Deprecated options, kept for backwards compatibility. + // They will be removed in a future release. + @Deprecated + protected static final String SUPPRESS_GENERATOR_TIMESTAMP = MappingOption.SUPPRESS_GENERATOR_TIMESTAMP.getOptionName(); + @Deprecated + protected static final String SUPPRESS_GENERATOR_VERSION_INFO_COMMENT = MappingOption.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT.getOptionName(); + @Deprecated + protected static final String UNMAPPED_TARGET_POLICY = MappingOption.UNMAPPED_TARGET_POLICY.getOptionName(); + @Deprecated + protected static final String UNMAPPED_SOURCE_POLICY = MappingOption.UNMAPPED_SOURCE_POLICY.getOptionName(); + @Deprecated + protected static final String DEFAULT_COMPONENT_MODEL = MappingOption.DEFAULT_COMPONENT_MODEL.getOptionName(); + @Deprecated + protected static final String DEFAULT_INJECTION_STRATEGY = MappingOption.DEFAULT_INJECTION_STRATEGY.getOptionName(); + @Deprecated + protected static final String ALWAYS_GENERATE_SERVICE_FILE = MappingOption.ALWAYS_GENERATE_SERVICE_FILE.getOptionName(); + @Deprecated + protected static final String DISABLE_BUILDERS = MappingOption.DISABLE_BUILDERS.getOptionName(); + @Deprecated + protected static final String VERBOSE = MappingOption.VERBOSE.getOptionName(); + @Deprecated + protected static final String NULL_VALUE_ITERABLE_MAPPING_STRATEGY = MappingOption.NULL_VALUE_ITERABLE_MAPPING_STRATEGY.getOptionName(); + @Deprecated + protected static final String NULL_VALUE_MAP_MAPPING_STRATEGY = MappingOption.NULL_VALUE_MAP_MAPPING_STRATEGY.getOptionName(); + // CHECKSTYLE:ON private final Set additionalSupportedOptions; private final String additionalSupportedOptionsError; @@ -156,7 +153,7 @@ public MappingProcessor() { public synchronized void init(ProcessingEnvironment processingEnv) { super.init( processingEnv ); - options = createOptions(); + options = new Options( processingEnv.getOptions() ); annotationProcessorContext = new AnnotationProcessorContext( processingEnv.getElementUtils(), processingEnv.getTypeUtils(), @@ -171,34 +168,6 @@ public synchronized void init(ProcessingEnvironment processingEnv) { } } - private Options createOptions() { - String unmappedTargetPolicy = processingEnv.getOptions().get( UNMAPPED_TARGET_POLICY ); - String unmappedSourcePolicy = processingEnv.getOptions().get( UNMAPPED_SOURCE_POLICY ); - String nullValueIterableMappingStrategy = processingEnv.getOptions() - .get( NULL_VALUE_ITERABLE_MAPPING_STRATEGY ); - String nullValueMapMappingStrategy = processingEnv.getOptions().get( NULL_VALUE_MAP_MAPPING_STRATEGY ); - String disableLifecycleOverloadDeduplicateSelector = processingEnv.getOptions() - .get( DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR ); - - return new Options( - Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_TIMESTAMP ) ), - Boolean.parseBoolean( processingEnv.getOptions().get( SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ) ), - unmappedTargetPolicy != null ? ReportingPolicyGem.valueOf( unmappedTargetPolicy.toUpperCase() ) : null, - unmappedSourcePolicy != null ? ReportingPolicyGem.valueOf( unmappedSourcePolicy.toUpperCase() ) : null, - processingEnv.getOptions().get( DEFAULT_COMPONENT_MODEL ), - processingEnv.getOptions().get( DEFAULT_INJECTION_STRATEGY ), - Boolean.parseBoolean( processingEnv.getOptions().get( ALWAYS_GENERATE_SERVICE_FILE ) ), - Boolean.parseBoolean( processingEnv.getOptions().get( DISABLE_BUILDERS ) ), - Boolean.parseBoolean( processingEnv.getOptions().get( VERBOSE ) ), - nullValueIterableMappingStrategy != null ? - NullValueMappingStrategyGem.valueOf( nullValueIterableMappingStrategy.toUpperCase( Locale.ROOT ) ) : - null, - nullValueMapMappingStrategy != null ? - NullValueMappingStrategyGem.valueOf( nullValueMapMappingStrategy.toUpperCase( Locale.ROOT ) ) : null, - Boolean.parseBoolean( disableLifecycleOverloadDeduplicateSelector ) - ); - } - @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); @@ -259,13 +228,11 @@ else if ( !deferredMappers.isEmpty() ) { @Override public Set getSupportedOptions() { - Set supportedOptions = super.getSupportedOptions(); - if ( additionalSupportedOptions.isEmpty() ) { - return supportedOptions; - } - Set allSupportedOptions = new HashSet<>( supportedOptions ); - allSupportedOptions.addAll( additionalSupportedOptions ); - return allSupportedOptions; + return Stream.concat( + Stream.of( MappingOption.values() ).map( MappingOption::getOptionName ), + additionalSupportedOptions.stream() + ) + .collect( Collectors.toSet() ); } /** diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java index e1f04fd941..8d76e65c75 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/DefaultOptions.java @@ -56,16 +56,18 @@ public Set imports() { @Override public ReportingPolicyGem unmappedTargetPolicy() { - if ( options.getUnmappedTargetPolicy() != null ) { - return options.getUnmappedTargetPolicy(); + ReportingPolicyGem unmappedTargetPolicy = options.getUnmappedTargetPolicy(); + if ( unmappedTargetPolicy != null ) { + return unmappedTargetPolicy; } return ReportingPolicyGem.valueOf( mapper.unmappedTargetPolicy().getDefaultValue() ); } @Override public ReportingPolicyGem unmappedSourcePolicy() { - if ( options.getUnmappedSourcePolicy() != null ) { - return options.getUnmappedSourcePolicy(); + ReportingPolicyGem unmappedSourcePolicy = options.getUnmappedSourcePolicy(); + if ( unmappedSourcePolicy != null ) { + return unmappedSourcePolicy; } return ReportingPolicyGem.valueOf( mapper.unmappedSourcePolicy().getDefaultValue() ); } @@ -77,8 +79,9 @@ public ReportingPolicyGem typeConversionPolicy() { @Override public String componentModel() { - if ( options.getDefaultComponentModel() != null ) { - return options.getDefaultComponentModel(); + String defaultComponentModel = options.getDefaultComponentModel(); + if ( defaultComponentModel != null ) { + return defaultComponentModel; } return mapper.componentModel().getDefaultValue(); } @@ -97,8 +100,9 @@ public MappingInheritanceStrategyGem getMappingInheritanceStrategy() { @Override public InjectionStrategyGem getInjectionStrategy() { - if ( options.getDefaultInjectionStrategy() != null ) { - return InjectionStrategyGem.valueOf( options.getDefaultInjectionStrategy().toUpperCase() ); + String defaultInjectionStrategy = options.getDefaultInjectionStrategy(); + if ( defaultInjectionStrategy != null ) { + return InjectionStrategyGem.valueOf( defaultInjectionStrategy.toUpperCase() ); } return InjectionStrategyGem.valueOf( mapper.injectionStrategy().getDefaultValue() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java b/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java new file mode 100644 index 0000000000..d35b2c0dc6 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java @@ -0,0 +1,43 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.option; + +/** + * @author Filip Hrisafov + */ +public enum MappingOption { + + // CHECKSTYLE:OFF + SUPPRESS_GENERATOR_TIMESTAMP( "mapstruct.suppressGeneratorTimestamp" ), + SUPPRESS_GENERATOR_VERSION_INFO_COMMENT( "mapstruct.suppressGeneratorVersionInfoComment" ), + UNMAPPED_TARGET_POLICY("mapstruct.unmappedTargetPolicy"), + UNMAPPED_SOURCE_POLICY("mapstruct.unmappedSourcePolicy"), + DEFAULT_COMPONENT_MODEL("mapstruct.defaultComponentModel"), + DEFAULT_INJECTION_STRATEGY("mapstruct.defaultInjectionStrategy"), + ALWAYS_GENERATE_SERVICE_FILE("mapstruct.alwaysGenerateServicesFile"), + DISABLE_BUILDERS("mapstruct.disableBuilders"), + VERBOSE("mapstruct.verbose"), + NULL_VALUE_ITERABLE_MAPPING_STRATEGY("mapstruct.nullValueIterableMappingStrategy"), + NULL_VALUE_MAP_MAPPING_STRATEGY("mapstruct.nullValueMapMappingStrategy"), + DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR("mapstruct.disableLifecycleOverloadDeduplicateSelector"), + ; + // CHECKSTYLE:ON + + private final String optionName; + + MappingOption(String optionName) { + this.optionName = optionName; + } + + /** + * Returns the name of the option, which can be used in the compiler arguments. + * + * @return the name of the option + */ + public String getOptionName() { + return optionName; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java index 095c472c87..38474baf9c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/Options.java @@ -5,6 +5,9 @@ */ package org.mapstruct.ap.internal.option; +import java.util.Locale; +import java.util.Map; + import org.mapstruct.ap.internal.gem.NullValueMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; @@ -13,93 +16,79 @@ * * @author Andreas Gudian * @author Gunnar Morling + * @author Filip Hrisafov */ public class Options { - private final boolean suppressGeneratorTimestamp; - private final boolean suppressGeneratorVersionComment; - private final ReportingPolicyGem unmappedTargetPolicy; - private final ReportingPolicyGem unmappedSourcePolicy; - private final boolean alwaysGenerateSpi; - private final String defaultComponentModel; - private final String defaultInjectionStrategy; - private final boolean disableBuilders; - private final boolean verbose; - private final NullValueMappingStrategyGem nullValueIterableMappingStrategy; - private final NullValueMappingStrategyGem nullValueMapMappingStrategy; - private final boolean disableLifecycleOverloadDeduplicateSelector; - - //CHECKSTYLE:OFF - public Options(boolean suppressGeneratorTimestamp, boolean suppressGeneratorVersionComment, - ReportingPolicyGem unmappedTargetPolicy, - ReportingPolicyGem unmappedSourcePolicy, - String defaultComponentModel, String defaultInjectionStrategy, - boolean alwaysGenerateSpi, - boolean disableBuilders, - boolean verbose, - NullValueMappingStrategyGem nullValueIterableMappingStrategy, - NullValueMappingStrategyGem nullValueMapMappingStrategy, - boolean disableLifecycleOverloadDeduplicateSelector - ) { - //CHECKSTYLE:ON - this.suppressGeneratorTimestamp = suppressGeneratorTimestamp; - this.suppressGeneratorVersionComment = suppressGeneratorVersionComment; - this.unmappedTargetPolicy = unmappedTargetPolicy; - this.unmappedSourcePolicy = unmappedSourcePolicy; - this.defaultComponentModel = defaultComponentModel; - this.defaultInjectionStrategy = defaultInjectionStrategy; - this.alwaysGenerateSpi = alwaysGenerateSpi; - this.disableBuilders = disableBuilders; - this.verbose = verbose; - this.nullValueIterableMappingStrategy = nullValueIterableMappingStrategy; - this.nullValueMapMappingStrategy = nullValueMapMappingStrategy; - this.disableLifecycleOverloadDeduplicateSelector = disableLifecycleOverloadDeduplicateSelector; + + private final Map options; + + public Options(Map options) { + this.options = options; } public boolean isSuppressGeneratorTimestamp() { - return suppressGeneratorTimestamp; + return parseBoolean( MappingOption.SUPPRESS_GENERATOR_TIMESTAMP ); } public boolean isSuppressGeneratorVersionComment() { - return suppressGeneratorVersionComment; + return parseBoolean( MappingOption.SUPPRESS_GENERATOR_VERSION_INFO_COMMENT ); } public ReportingPolicyGem getUnmappedTargetPolicy() { - return unmappedTargetPolicy; + return parseEnum( MappingOption.UNMAPPED_TARGET_POLICY, ReportingPolicyGem.class ); } public ReportingPolicyGem getUnmappedSourcePolicy() { - return unmappedSourcePolicy; + return parseEnum( MappingOption.UNMAPPED_SOURCE_POLICY, ReportingPolicyGem.class ); } public String getDefaultComponentModel() { - return defaultComponentModel; + return options.get( MappingOption.DEFAULT_COMPONENT_MODEL.getOptionName() ); } public String getDefaultInjectionStrategy() { - return defaultInjectionStrategy; + return options.get( MappingOption.DEFAULT_INJECTION_STRATEGY.getOptionName() ); } public boolean isAlwaysGenerateSpi() { - return alwaysGenerateSpi; + return parseBoolean( MappingOption.ALWAYS_GENERATE_SERVICE_FILE ); } public boolean isDisableBuilders() { - return disableBuilders; + return parseBoolean( MappingOption.DISABLE_BUILDERS ); } public boolean isVerbose() { - return verbose; + return parseBoolean( MappingOption.VERBOSE ); } public NullValueMappingStrategyGem getNullValueIterableMappingStrategy() { - return nullValueIterableMappingStrategy; + return parseEnum( MappingOption.NULL_VALUE_ITERABLE_MAPPING_STRATEGY, NullValueMappingStrategyGem.class ); } public NullValueMappingStrategyGem getNullValueMapMappingStrategy() { - return nullValueMapMappingStrategy; + return parseEnum( MappingOption.NULL_VALUE_MAP_MAPPING_STRATEGY, NullValueMappingStrategyGem.class ); } public boolean isDisableLifecycleOverloadDeduplicateSelector() { - return disableLifecycleOverloadDeduplicateSelector; + return parseBoolean( MappingOption.DISABLE_LIFECYCLE_OVERLOAD_DEDUPLICATE_SELECTOR ); + } + + private boolean parseBoolean(MappingOption option) { + if ( options.isEmpty() ) { + return false; + } + return Boolean.parseBoolean( options.get( option.getOptionName() ) ); + } + + private > E parseEnum(MappingOption option, Class enumType) { + if ( options.isEmpty() ) { + return null; + } + String value = options.get( option.getOptionName() ); + if ( value == null ) { + return null; + } + return Enum.valueOf( enumType, value.toUpperCase( Locale.ROOT ) ); } } From d68819a233030b5d863e4d4645787a84e7db7d52 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Jun 2025 20:02:23 +0000 Subject: [PATCH 0905/1006] Bump org.springframework:spring-context from 6.2.2 to 6.2.7 in /parent Bumps [org.springframework:spring-context](https://github.com/spring-projects/spring-framework) from 6.2.2 to 6.2.7. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v6.2.2...v6.2.7) --- updated-dependencies: - dependency-name: org.springframework:spring-context dependency-version: 6.2.7 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- parent/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent/pom.xml b/parent/pom.xml index f6ad60a22a..35fc24e96b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -34,7 +34,7 @@ 3.4.1 3.2.2 3.1.0 - 6.2.2 + 6.2.7 1.6.0 8.36.1 5.10.1 From f4d18181719b821bc319f53314b7c8e19e929e16 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Jun 2025 21:33:19 +0200 Subject: [PATCH 0906/1006] Fix issue key in Issue3807Test --- .../java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java index 3b895f3e11..db82472f98 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3807/Issue3807Test.java @@ -12,7 +12,7 @@ import static org.assertj.core.api.Assertions.assertThat; @WithClasses(Issue3807Mapper.class) -@IssueKey("3087") +@IssueKey("3807") class Issue3807Test { @ProcessorTest From c90c93630e8580e330b09bcdd6f2bc99b08bdee6 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 14 Jun 2025 22:13:56 +0200 Subject: [PATCH 0907/1006] #3886: Records do not have property write accessors (apart from the record components) --- processor/pom.xml | 1 + .../ap/internal/model/common/Type.java | 4 +++ .../bugs/_3886/jdk21/Issue3886Mapper.java | 31 +++++++++++++++++++ .../test/bugs/_3886/jdk21/Issue3886Test.java | 25 +++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Test.java diff --git a/processor/pom.xml b/processor/pom.xml index 2341c4ddb0..87c3517018 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -286,6 +286,7 @@ org.apache.maven.plugins maven-compiler-plugin + ${minimum.java.version} org.mapstruct.tools.gem diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index d0f65ce97a..24f23ecea8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -796,6 +796,10 @@ public Map getPropertyPresenceCheckers() { * @return an unmodifiable map of all write accessors indexed by property name */ public Map getPropertyWriteAccessors( CollectionMappingStrategyGem cmStrategy ) { + if ( isRecord() ) { + // Records do not have setters, so we return an empty map + return Collections.emptyMap(); + } // collect all candidate target accessors List candidates = new ArrayList<>( getSetters() ); candidates.addAll( getAlternativeTargetAccessors() ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Mapper.java new file mode 100644 index 0000000000..aba305a0bf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Mapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3886.jdk21; + +import java.time.LocalDate; + +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * @author Filip Hrisafov + */ +@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR) +public interface Issue3886Mapper { + + RangeRecord map(LocalDate validFrom); + + record RangeRecord(LocalDate validFrom) { + + public RangeRecord restrictTo(RangeRecord other) { + return null; + } + + public void setName(String name) { + // This method is here to ensure that MapStruct won't treat it as a setter + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Test.java new file mode 100644 index 0000000000..93c068cbc7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3886/jdk21/Issue3886Test.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3886.jdk21; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.Compiler; + +/** + * @author Filip Hrisafov + */ +@WithClasses(Issue3886Mapper.class) +@IssueKey("3886") +class Issue3886Test { + + // The current version of the Eclipse compiler we use does not support records + @ProcessorTest(Compiler.JDK) + void shouldCompile() { + + } +} From e4bc1cdf1e39a3ff25f0a55b44bdb25837d49a69 Mon Sep 17 00:00:00 2001 From: Yang Tang Date: Sun, 15 Jun 2025 14:29:45 +0800 Subject: [PATCH 0908/1006] #3884 Ensure `NullValuePropertyMappingStrategy.SET_TO_DEFAULT` initializes empty collection/map when target is null Signed-off-by: TangYang --- ...anceSetterWrapperForCollectionsAndMaps.ftl | 4 + .../ap/test/bugs/_3884/DestinationType.java | 22 ++++ .../ap/test/bugs/_3884/Issue3884Mapper.java | 21 ++++ .../ap/test/bugs/_3884/Issue3884Test.java | 116 ++++++++++++++++++ .../ap/test/bugs/_3884/SourceType.java | 37 ++++++ .../DomainDtoWithNvmsDefaultMapperImpl.java | 24 ++++ .../DomainDtoWithNvmsDefaultMapperImpl.java | 24 ++++ 7 files changed, 248 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/DestinationType.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/SourceType.java diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index cee722e2d3..95662c4c79 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -30,6 +30,10 @@ <@lib.handleLocalVarNullCheck needs_explicit_local_var=directAssignment> ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if directAssignment><@wrapLocalVarInCollectionInitializer/><#else><@lib.handleWithAssignmentOrNullCheckVar/>; + <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && mapNullToDefault>else { + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><@lib.initTargetObject/>; + } + <#-- wraps the local variable in a collection initializer (new collection, or EnumSet.copyOf) diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/DestinationType.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/DestinationType.java new file mode 100644 index 0000000000..467b58990c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/DestinationType.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3884; + +import java.util.List; +import java.util.Map; + +/** + * Destination type interface for testing null value property mapping strategy with Map properties. + */ +public interface DestinationType { + Map getAttributes(); + + void setAttributes(Map attributes); + + List getItems(); + + void setItems(List items); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Mapper.java new file mode 100644 index 0000000000..6f6f4f924d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Mapper.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3884; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +/** + * Mapper for testing null value property mapping strategy with Map properties. + */ +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT) +public interface Issue3884Mapper { + Issue3884Mapper INSTANCE = Mappers.getMapper( Issue3884Mapper.class ); + + void update(@MappingTarget DestinationType destination, SourceType source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Test.java new file mode 100644 index 0000000000..6c789a0c29 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/Issue3884Test.java @@ -0,0 +1,116 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3884; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; + +/** + * Test for issue 3884: NullValuePropertyMappingStrategy.SET_TO_DEFAULT should set target Map/Collection to default + * when source and target are all null. + */ +@IssueKey("3884") +@WithClasses({ + DestinationType.class, + SourceType.class, + Issue3884Mapper.class +}) +public class Issue3884Test { + + @ProcessorTest + public void shouldSetTargetToDefaultWhenBothSourceAndTargetAreNull() { + DestinationType target = new SourceType(); + SourceType source = new SourceType(); + + assertThat( source.getAttributes() ).isNull(); + assertThat( target.getAttributes() ).isNull(); + assertThat( source.getItems() ).isNull(); + assertThat( target.getItems() ).isNull(); + + Issue3884Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAttributes() ).isEmpty(); + assertThat( target.getItems() ).isEmpty(); + } + + @ProcessorTest + public void shouldClearTargetWhenSourceIsNullAndTargetIsInitialized() { + DestinationType target = new SourceType(); + SourceType source = new SourceType(); + + Map targetAttributes = new HashMap<>(); + targetAttributes.put( "targetKey", "targetValue" ); + target.setAttributes( targetAttributes ); + + List targetItems = new ArrayList<>(); + targetItems.add( "targetItem" ); + target.setItems( targetItems ); + + assertThat( source.getAttributes() ).isNull(); + assertThat( target.getAttributes() ).isNotEmpty(); + assertThat( source.getItems() ).isNull(); + assertThat( target.getItems() ).isNotEmpty(); + + Issue3884Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAttributes() ).isEmpty(); + assertThat( target.getItems() ).isEmpty(); + } + + @ProcessorTest + public void shouldCopySourceToTargetWhenSourceIsInitializedAndTargetIsNull() { + DestinationType target = new SourceType(); + SourceType source = new SourceType(); + + source.setAttributes( Map.of( "sourceKey", "sourceValue" ) ); + source.setItems( List.of( "sourceItem" ) ); + + assertThat( source.getAttributes() ).isNotEmpty(); + assertThat( target.getAttributes() ).isNull(); + assertThat( source.getItems() ).isNotEmpty(); + assertThat( target.getItems() ).isNull(); + + Issue3884Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAttributes() ).containsOnly( entry( "sourceKey", "sourceValue" ) ); + assertThat( target.getItems() ).containsExactly( "sourceItem" ); + } + + @ProcessorTest + public void shouldCopySourceToTargetWhenBothSourceAndTargetAreInitialized() { + DestinationType target = new SourceType(); + SourceType source = new SourceType(); + + source.setAttributes( Map.of( "sourceKey", "sourceValue" ) ); + source.setItems( List.of( "sourceItem" ) ); + + Map targetAttributes = new HashMap<>(); + targetAttributes.put( "targetKey", "targetValue" ); + target.setAttributes( targetAttributes ); + List targetItems = new ArrayList<>(); + targetItems.add( "targetItem" ); + target.setItems( targetItems ); + + assertThat( source.getAttributes() ).isNotEmpty(); + assertThat( target.getAttributes() ).isNotEmpty(); + assertThat( source.getItems() ).isNotEmpty(); + assertThat( target.getItems() ).isNotEmpty(); + + Issue3884Mapper.INSTANCE.update( target, source ); + + assertThat( target.getAttributes() ).containsOnly( entry( "sourceKey", "sourceValue" ) ); + assertThat( target.getItems() ).containsExactly( "sourceItem" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/SourceType.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/SourceType.java new file mode 100644 index 0000000000..be5c19e01c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3884/SourceType.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3884; + +import java.util.List; +import java.util.Map; + +/** + * Source type class implementing DestinationType for testing null value property mapping strategy with Map properties. + */ +public class SourceType implements DestinationType { + private Map attributes; + private List items; + + @Override + public Map getAttributes() { + return attributes; + } + + @Override + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + @Override + public List getItems() { + return items; + } + + @Override + public void setItems(List items) { + this.items = items; + } +} diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index 76de94378b..f36e2e437d 100644 --- a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -67,6 +67,9 @@ public void update(Dto source, Domain target) { if ( list != null ) { target.setStrings( new LinkedHashSet( list ) ); } + else { + target.setStrings( new LinkedHashSet() ); + } } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); @@ -83,6 +86,9 @@ public void update(Dto source, Domain target) { if ( set != null ) { target.setLongs( set ); } + else { + target.setLongs( new LinkedHashSet() ); + } } if ( target.getStringsInitialized() != null ) { List list1 = source.getStringsInitialized(); @@ -99,6 +105,9 @@ public void update(Dto source, Domain target) { if ( list1 != null ) { target.setStringsInitialized( new LinkedHashSet( list1 ) ); } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } } if ( target.getLongsInitialized() != null ) { Set set1 = stringListToLongSet( source.getStringsInitialized() ); @@ -115,6 +124,9 @@ public void update(Dto source, Domain target) { if ( set1 != null ) { target.setLongsInitialized( set1 ); } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } } if ( target.getStringsWithDefault() != null ) { List list2 = source.getStringsWithDefault(); @@ -157,6 +169,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( list != null ) { target.setStrings( new LinkedHashSet( list ) ); } + else { + target.setStrings( new LinkedHashSet() ); + } } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); @@ -173,6 +188,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( set != null ) { target.setLongs( set ); } + else { + target.setLongs( new LinkedHashSet() ); + } } if ( target.getStringsInitialized() != null ) { List list1 = source.getStringsInitialized(); @@ -189,6 +207,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( list1 != null ) { target.setStringsInitialized( new LinkedHashSet( list1 ) ); } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } } if ( target.getLongsInitialized() != null ) { Set set1 = stringListToLongSet( source.getStringsInitialized() ); @@ -205,6 +226,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( set1 != null ) { target.setLongsInitialized( set1 ); } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } } if ( target.getStringsWithDefault() != null ) { List list2 = source.getStringsWithDefault(); diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java index f1bf0fa78f..87d2fccb26 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/bugs/_913/DomainDtoWithNvmsDefaultMapperImpl.java @@ -67,6 +67,9 @@ public void update(Dto source, Domain target) { if ( list != null ) { target.setStrings( new LinkedHashSet( list ) ); } + else { + target.setStrings( new LinkedHashSet() ); + } } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); @@ -83,6 +86,9 @@ public void update(Dto source, Domain target) { if ( set != null ) { target.setLongs( set ); } + else { + target.setLongs( new LinkedHashSet() ); + } } if ( target.getStringsInitialized() != null ) { List list1 = source.getStringsInitialized(); @@ -99,6 +105,9 @@ public void update(Dto source, Domain target) { if ( list1 != null ) { target.setStringsInitialized( new LinkedHashSet( list1 ) ); } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } } if ( target.getLongsInitialized() != null ) { Set set1 = stringListToLongSet( source.getStringsInitialized() ); @@ -115,6 +124,9 @@ public void update(Dto source, Domain target) { if ( set1 != null ) { target.setLongsInitialized( set1 ); } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } } if ( target.getStringsWithDefault() != null ) { List list2 = source.getStringsWithDefault(); @@ -157,6 +169,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( list != null ) { target.setStrings( new LinkedHashSet( list ) ); } + else { + target.setStrings( new LinkedHashSet() ); + } } if ( target.getLongs() != null ) { Set set = stringListToLongSet( source.getStrings() ); @@ -173,6 +188,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( set != null ) { target.setLongs( set ); } + else { + target.setLongs( new LinkedHashSet() ); + } } if ( target.getStringsInitialized() != null ) { List list1 = source.getStringsInitialized(); @@ -189,6 +207,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( list1 != null ) { target.setStringsInitialized( new LinkedHashSet( list1 ) ); } + else { + target.setStringsInitialized( new LinkedHashSet() ); + } } if ( target.getLongsInitialized() != null ) { Set set1 = stringListToLongSet( source.getStringsInitialized() ); @@ -205,6 +226,9 @@ public Domain updateWithReturn(Dto source, Domain target) { if ( set1 != null ) { target.setLongsInitialized( set1 ); } + else { + target.setLongsInitialized( new LinkedHashSet() ); + } } if ( target.getStringsWithDefault() != null ) { List list2 = source.getStringsWithDefault(); From 46a9c29fcabc7ade34f39a92741449c874d7547a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=98=84=EC=88=98?= Date: Thu, 31 Jul 2025 04:37:50 +0900 Subject: [PATCH 0909/1006] #3902: Validate unknown properties in @Ignored --- .../ap/internal/model/BeanMappingMethod.java | 60 +++++++++------- .../mapstruct/ap/internal/util/Message.java | 1 + .../bugs/_3902/ErroneousIssue3902Mapper.java | 69 +++++++++++++++++++ .../ap/test/bugs/_3902/Issue3902Test.java | 57 +++++++++++++++ 4 files changed, 164 insertions(+), 23 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index b5208d302b..c81fc51800 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1280,40 +1280,54 @@ else if ( inheritContext.isReversed() ) { return false; } } - Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); - String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); Message msg; String[] args; - if ( targetRef.getPathProperties().isEmpty() ) { - msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; + Element elementForMessage = mapping.getElement(); + if ( elementForMessage == null ) { + elementForMessage = method.getExecutable(); + } + + if ( mapping.isIgnored() && mapping.getElement() == null ) { + msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_IGNORED; args = new String[] { targetPropertyName, - resultTypeToMap.describe(), - mostSimilarProperty + resultTypeToMap.describe() }; } else { - List pathProperties = new ArrayList<>( targetRef.getPathProperties() ); - pathProperties.add( mostSimilarProperty ); - msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE; - args = new String[] { - targetPropertyName, - resultTypeToMap.describe(), - mapping.getTargetName(), - Strings.join( pathProperties, "." ) - }; + Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); + String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); + + if ( targetRef.getPathProperties().isEmpty() ) { + msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; + args = new String[] { + targetPropertyName, + resultTypeToMap.describe(), + mostSimilarProperty + }; + } + else { + List pathProperties = new ArrayList<>( targetRef.getPathProperties() ); + pathProperties.add( mostSimilarProperty ); + msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_TYPE; + args = new String[] { + targetPropertyName, + resultTypeToMap.describe(), + mapping.getTargetName(), + Strings.join( pathProperties, "." ) + }; + } } - ctx.getMessager() - .printMessage( - mapping.getElement(), - mapping.getMirror(), - mapping.getTargetAnnotationValue(), - msg, - args - ); + ctx.getMessager().printMessage( + elementForMessage, + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + msg, + args + ); return true; } else if ( mapping.getInheritContext() != null && mapping.getInheritContext().isReversed() ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 883b3e3792..8534758285 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -45,6 +45,7 @@ public enum Message { BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS( "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not allowed. You'll need to explicitly ignore the target properties that should be ignored instead." ), + BEANMAPPING_UNKNOWN_PROPERTY_IN_IGNORED("No property named \"%s\" exists in @Ignored for target type \"%s\""), CONDITION_MISSING_APPLIES_TO_STRATEGY("'appliesTo' has to have at least one value in @Condition" ), CONDITION_SOURCE_PARAMETERS_INVALID_PARAMETER("Parameter \"%s\" cannot be used with the ConditionStrategy#SOURCE_PARAMETERS. Only source and @Context parameters are allowed for conditions applicable to source parameters." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java new file mode 100644 index 0000000000..07f94ce6fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java @@ -0,0 +1,69 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3902; + +import org.mapstruct.Ignored; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * Mapper for testing bug #3902. + * + * @author znight1020 + */ +@Mapper +public interface ErroneousIssue3902Mapper { + + ErroneousIssue3902Mapper INSTANCE = Mappers.getMapper( ErroneousIssue3902Mapper.class ); + + @Ignored(targets = {"name", "foo", "bar"}) + ZooDto mapWithOneKnownAndMultipleUnknowns(Zoo source); + + @Ignored(targets = {"name", "address", "foo"}) + ZooDto mapWithMultipleKnownAndOneUnknown(Zoo source); + + class Zoo { + private String name; + private String address; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + } + + class ZooDto { + private String name; + private String address; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java new file mode 100644 index 0000000000..f1332bbdc6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3902; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; + +/** + * Verifies that using an unknown property in {@code @Ignored} yields a proper + * compile error instead of an internal processor error. + * + * @author znight1020 + */ +@WithClasses({ErroneousIssue3902Mapper.class}) +@IssueKey("3902") +public class Issue3902Test { + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + // Test case: mapWithOneKnownAndMultipleUnknowns + @Diagnostic( + type = ErroneousIssue3902Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 23, + message = "No property named \"foo\" exists in @Ignored for target type " + + "\"ErroneousIssue3902Mapper.ZooDto\"" + ), + @Diagnostic( + type = ErroneousIssue3902Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 23, + message = "No property named \"bar\" exists in @Ignored for target type " + + "\"ErroneousIssue3902Mapper.ZooDto\"" + ), + + // Test case: mapWithMultipleKnownAndOneUnknown + @Diagnostic( + type = ErroneousIssue3902Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 26, + message = "No property named \"foo\" exists in @Ignored for target type " + + "\"ErroneousIssue3902Mapper.ZooDto\"" + ) + } + ) + public void shouldFailOnUnknownPropertiesInIgnored() { + } +} From 29036542b85ff93a05fc5851793438ede8713f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=98=84=EC=88=98?= Date: Mon, 4 Aug 2025 15:08:22 +0900 Subject: [PATCH 0910/1006] #3908: Add similar suggestion for unknown property in `@Ignored` --- .../ap/internal/model/BeanMappingMethod.java | 22 ++++++++++--------- .../mapstruct/ap/internal/util/Message.java | 2 +- .../bugs/_3902/ErroneousIssue3902Mapper.java | 3 +++ .../ap/test/bugs/_3902/Issue3902Test.java | 15 ++++++++++--- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c81fc51800..7973ece427 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -1284,6 +1284,9 @@ else if ( inheritContext.isReversed() ) { Message msg; String[] args; + Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); + String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); + Element elementForMessage = mapping.getElement(); if ( elementForMessage == null ) { elementForMessage = method.getExecutable(); @@ -1293,13 +1296,11 @@ else if ( inheritContext.isReversed() ) { msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_IGNORED; args = new String[] { targetPropertyName, - resultTypeToMap.describe() + resultTypeToMap.describe(), + mostSimilarProperty }; } else { - Set readAccessors = resultTypeToMap.getPropertyReadAccessors().keySet(); - String mostSimilarProperty = Strings.getMostSimilarWord( targetPropertyName, readAccessors ); - if ( targetRef.getPathProperties().isEmpty() ) { msg = Message.BEANMAPPING_UNKNOWN_PROPERTY_IN_RESULTTYPE; args = new String[] { @@ -1321,12 +1322,13 @@ else if ( inheritContext.isReversed() ) { } } - ctx.getMessager().printMessage( - elementForMessage, - mapping.getMirror(), - mapping.getTargetAnnotationValue(), - msg, - args + ctx.getMessager() + .printMessage( + elementForMessage, + mapping.getMirror(), + mapping.getTargetAnnotationValue(), + msg, + args ); return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java index 8534758285..60aa55eb38 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Message.java @@ -45,7 +45,7 @@ public enum Message { BEANMAPPING_CYCLE_BETWEEN_PROPERTIES( "Cycle(s) between properties given via dependsOn(): %s." ), BEANMAPPING_UNKNOWN_PROPERTY_IN_DEPENDS_ON( "\"%s\" is no property of the method return type." ), BEANMAPPING_IGNORE_BY_DEFAULT_WITH_MAPPING_TARGET_THIS( "Using @BeanMapping( ignoreByDefault = true ) with @Mapping( target = \".\", ... ) is not allowed. You'll need to explicitly ignore the target properties that should be ignored instead." ), - BEANMAPPING_UNKNOWN_PROPERTY_IN_IGNORED("No property named \"%s\" exists in @Ignored for target type \"%s\""), + BEANMAPPING_UNKNOWN_PROPERTY_IN_IGNORED("No property named \"%s\" exists in @Ignored for target type \"%s\". Did you mean \"%s\"?"), CONDITION_MISSING_APPLIES_TO_STRATEGY("'appliesTo' has to have at least one value in @Condition" ), CONDITION_SOURCE_PARAMETERS_INVALID_PARAMETER("Parameter \"%s\" cannot be used with the ConditionStrategy#SOURCE_PARAMETERS. Only source and @Context parameters are allowed for conditions applicable to source parameters." ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java index 07f94ce6fe..b646f1a08e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/ErroneousIssue3902Mapper.java @@ -25,6 +25,9 @@ public interface ErroneousIssue3902Mapper { @Ignored(targets = {"name", "address", "foo"}) ZooDto mapWithMultipleKnownAndOneUnknown(Zoo source); + @Ignored(targets = {"name", "addres"}) + ZooDto mapWithTypo(Zoo source); + class Zoo { private String name; private String address; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java index f1332bbdc6..44247d8c27 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3902/Issue3902Test.java @@ -32,14 +32,14 @@ public class Issue3902Test { kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, message = "No property named \"foo\" exists in @Ignored for target type " + - "\"ErroneousIssue3902Mapper.ZooDto\"" + "\"ErroneousIssue3902Mapper.ZooDto\". Did you mean \"name\"?" ), @Diagnostic( type = ErroneousIssue3902Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 23, message = "No property named \"bar\" exists in @Ignored for target type " + - "\"ErroneousIssue3902Mapper.ZooDto\"" + "\"ErroneousIssue3902Mapper.ZooDto\". Did you mean \"name\"?" ), // Test case: mapWithMultipleKnownAndOneUnknown @@ -48,7 +48,16 @@ public class Issue3902Test { kind = javax.tools.Diagnostic.Kind.ERROR, line = 26, message = "No property named \"foo\" exists in @Ignored for target type " + - "\"ErroneousIssue3902Mapper.ZooDto\"" + "\"ErroneousIssue3902Mapper.ZooDto\". Did you mean \"name\"?" + ), + + // Test case: mapWithTypo + @Diagnostic( + type = ErroneousIssue3902Mapper.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 29, + message = "No property named \"addres\" exists in @Ignored for target type " + + "\"ErroneousIssue3902Mapper.ZooDto\". Did you mean \"address\"?" ) } ) From fe43563c8184dcf0e96a9ac9bfb40a8ace436e6f Mon Sep 17 00:00:00 2001 From: Ritesh Chopade <94113981+codeswithritesh@users.noreply.github.com> Date: Sun, 24 Aug 2025 19:47:30 +0530 Subject: [PATCH 0911/1006] #3837 Add warning/error for redundant ignoreUnmappedSourceProperties entries (#3906) Adds compiler warning / error when properties listed in `ignoreUnmappedSourceProperties` are actually mapped. Respects `unmappedSourcePolicy` and includes tests for redundant and valid ignore cases. --- .../ap/internal/model/BeanMappingMethod.java | 44 +++++- .../mapstruct/ap/internal/util/Message.java | 2 + .../IgnoredMappedPropertyTest.java | 136 ++++++++++++++++++ .../ap/test/ignoreunmapped/UserDto.java | 31 ++++ .../ap/test/ignoreunmapped/UserEntity.java | 40 ++++++ .../ignoreunmapped/mapper/UserMapper.java | 19 +++ ...rMapperWithIgnorePolicyInMapperConfig.java | 24 ++++ .../UserMapperWithIgnoreSourcePolicy.java | 21 +++ ...serMapperWithWarnPolicyInMapperConfig.java | 24 ++++ .../UserMapperWithWarnSourcePolicy.java | 21 +++ ...serMapperWithWarnSourcePolicyInMapper.java | 20 +++ .../mapper/UserMapperWithoutBeanMapping.java | 17 +++ ...erMapperWithErrorPolicyInMapperConfig.java | 24 ++++ .../UserMapperWithErrorSourcePolicy.java | 21 +++ ...erMapperWithErrorSourcePolicyInMapper.java | 20 +++ .../erroneous/UserMapperWithMultiMapping.java | 22 +++ 16 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/IgnoredMappedPropertyTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/UserDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/UserEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithIgnorePolicyInMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithIgnoreSourcePolicy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithWarnPolicyInMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithWarnSourcePolicy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithWarnSourcePolicyInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/UserMapperWithoutBeanMapping.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/erroneous/UserMapperWithErrorPolicyInMapperConfig.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/erroneous/UserMapperWithErrorSourcePolicy.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/erroneous/UserMapperWithErrorSourcePolicyInMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/ignoreunmapped/mapper/erroneous/UserMapperWithMultiMapping.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 7973ece427..05e0424a21 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -114,6 +114,7 @@ public static class Builder extends AbstractMappingMethodBuilder unprocessedTargetProperties; private Map unprocessedSourceProperties; private Set missingIgnoredSourceProperties; + private Set redundantIgnoredSourceProperties; private Set targetProperties; private final List propertyMappings = new ArrayList<>(); private final Set unprocessedSourceParameters = new HashSet<>(); @@ -278,11 +279,23 @@ else if ( !method.isUpdateMethod() ) { // get bean mapping (when specified as annotation ) this.missingIgnoredSourceProperties = new HashSet<>(); - if ( beanMapping != null ) { + this.redundantIgnoredSourceProperties = new HashSet<>(); + if ( beanMapping != null && !beanMapping.getIgnoreUnmappedSourceProperties().isEmpty() ) { + // Get source properties explicitly mapped using @Mapping annotations + Set mappedSourceProperties = method.getOptions().getMappings().stream() + .map( MappingOptions::getSourceName ) + .filter( Objects::nonNull ) + .collect( Collectors.toSet() ); + for ( String ignoreUnmapped : beanMapping.getIgnoreUnmappedSourceProperties() ) { + // Track missing ignored properties (i.e. not in source class) if ( unprocessedSourceProperties.remove( ignoreUnmapped ) == null ) { missingIgnoredSourceProperties.add( ignoreUnmapped ); } + // Track redundant ignored properties (actually mapped despite being ignored) + if ( mappedSourceProperties.contains( ignoreUnmapped ) ) { + redundantIgnoredSourceProperties.add( ignoreUnmapped ); + } } } @@ -331,6 +344,7 @@ else if ( !method.isUpdateMethod() ) { } reportErrorForMissingIgnoredSourceProperties(); reportErrorForUnusedSourceParameters(); + reportErrorForRedundantIgnoredSourceProperties(); // mapNullToDefault boolean mapNullToDefault = method.getOptions() @@ -1914,6 +1928,34 @@ private void reportErrorForMissingIgnoredSourceProperties() { } } + private void reportErrorForRedundantIgnoredSourceProperties() { + if ( !redundantIgnoredSourceProperties.isEmpty() ) { + ReportingPolicyGem unmappedSourcePolicy = getUnmappedSourcePolicy(); + if ( unmappedSourcePolicy == ReportingPolicyGem.IGNORE ) { //don't show warning + return; + } + + Message message = Message.BEANMAPPING_REDUNDANT_IGNORED_SOURCES_WARNING; + if ( unmappedSourcePolicy.getDiagnosticKind() == Diagnostic.Kind.ERROR ) { + message = Message.BEANMAPPING_REDUNDANT_IGNORED_SOURCES_ERROR; + } + + Object[] args = new Object[] { + MessageFormat.format( + "{0,choice,1#property|1 Date: Thu, 28 Aug 2025 22:31:52 +0200 Subject: [PATCH 0912/1006] docs: reference gh discussions --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6064004d73..14443592e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ You love MapStruct but miss a certain feature? You found a bug and want to repor * Source code: [http://github.com/mapstruct/mapstruct](http://github.com/mapstruct/mapstruct) * Issue tracker: [https://github.com/mapstruct/mapstruct/issues](https://github.com/mapstruct/mapstruct/issues) -* Discussions: Join the [mapstruct-users](https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users) Google group +* Discussions: [https://github.com/mapstruct/mapstruct/discussions](https://github.com/mapstruct/mapstruct/discussions) * CI build: [https://github.com/mapstruct/mapstruct/actions/](https://github.com/mapstruct/mapstruct/actions) MapStruct follows the _Fork & Pull_ development approach. To get started just fork the [MapStruct repository](http://github.com/mapstruct/mapstruct) to your GitHub account and create a new topic branch for each change. Once you are done with your change, submit a [pull request](https://help.github.com/articles/using-pull-requests) against the MapStruct repo. @@ -15,7 +15,7 @@ When doing changes, keep the following best practices in mind: * Use the code formatter for your IDE * [IntelliJ Formatter](https://github.com/mapstruct/mapstruct/blob/master/etc/mapstruct.xml) * Update the [reference documentation](mapstruct.org/documentation) on [mapstruct.org](mapstruct.org) where required -* Discuss new features you'd like to implement at the [Google group](https://groups.google.com/forum/?fromgroups#!forum/mapstruct-users) before getting started +* Discuss new features you'd like to implement in the [discussions](https://github.com/mapstruct/mapstruct/discussions) before getting started * Create one pull request per feature * Provide a meaningful history, e.g. squash intermediary commits before submitting a pull request From 0f7f5434295093d1f452d95d3d72c10c7f37103e Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 29 Aug 2025 15:57:31 +0200 Subject: [PATCH 0913/1006] Update Distribution management to point to new Maven Central Portal --- parent/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index 35fc24e96b..f90b066774 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -87,12 +87,12 @@ sonatype-nexus-staging Nexus Release Repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/ sonatype-nexus-snapshots Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots/ + https://central.sonatype.com/repository/maven-snapshots/ From 4e1720c2a899252de448c38eb10942f9fbbf5276 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 29 Aug 2025 16:11:26 +0200 Subject: [PATCH 0914/1006] #3905: Using custom class Override should compile --- .../model/AbstractMappingMethodBuilder.java | 9 ++++++- .../model/NormalTypeMappingMethod.java | 6 ----- .../ap/internal/model/BeanMappingMethod.ftl | 1 - .../internal/model/IterableMappingMethod.ftl | 1 - .../ap/internal/model/MapMappingMethod.ftl | 1 - .../ap/internal/model/StreamMappingMethod.ftl | 1 - .../ap/test/bugs/_3905/Issue3905Mapper.java | 17 ++++++++++++ .../ap/test/bugs/_3905/Issue3905Test.java | 26 +++++++++++++++++++ .../ap/test/bugs/_3905/Override.java | 22 ++++++++++++++++ .../ap/test/bugs/_3905/OverrideDto.java | 22 ++++++++++++++++ 10 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Mapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Override.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/OverrideDto.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 7329df5ab7..efb5887c95 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -130,7 +130,14 @@ public List getMethodAnnotations() { ctx.getElementUtils(), ctx.getTypeFactory(), ctx.getMessager() ); - return new ArrayList<>( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) ); + List annotations = new ArrayList<>( + additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) + ); + + if ( method.overridesMethod() ) { + annotations.add( new Annotation( ctx.getTypeFactory().getType( Override.class ) ) ); + } + return annotations; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java index 79cd0e0566..89ee1baab2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NormalTypeMappingMethod.java @@ -21,7 +21,6 @@ */ public abstract class NormalTypeMappingMethod extends MappingMethod { private final MethodReference factoryMethod; - private final boolean overridden; private final boolean mapNullToDefault; private final List annotations; @@ -33,7 +32,6 @@ public abstract class NormalTypeMappingMethod extends MappingMethod { List afterMappingReferences) { super( method, existingVariableNames, beforeMappingReferences, afterMappingReferences ); this.factoryMethod = factoryMethod; - this.overridden = method.overridesMethod(); this.mapNullToDefault = mapNullToDefault; this.annotations = annotations; } @@ -59,10 +57,6 @@ public boolean isMapNullToDefault() { return mapNullToDefault; } - public boolean isOverridden() { - return overridden; - } - public MethodReference getFactoryMethod() { return this.factoryMethod; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index da590bb506..059e2d77d4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -9,7 +9,6 @@ <#list annotations as annotation> <#nt><@includeModel object=annotation/> -<#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#assign targetType = resultType /> <#if !existingInstanceMapping> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl index 4d08c44b38..7c3d3071ac 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/IterableMappingMethod.ftl @@ -9,7 +9,6 @@ <#list annotations as annotation> <#nt><@includeModel object=annotation/> -<#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl index 1227dbd27a..957dc712ee 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/MapMappingMethod.ftl @@ -9,7 +9,6 @@ <#list annotations as annotation> <#nt><@includeModel object=annotation/> -<#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType /> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list beforeMappingReferencesWithoutMappingTarget as callback> <@includeModel object=callback targetBeanName=resultName targetType=resultType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl index 7d0080a1d2..2269892b8a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/StreamMappingMethod.ftl @@ -9,7 +9,6 @@ <#list annotations as annotation> <#nt><@includeModel object=annotation/> -<#if overridden>@Override <#lt>${accessibility.keyword} <@includeModel object=returnType/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#--TODO does it even make sense to do a callback if the result is a Stream, as they are immutable--> <#list beforeMappingReferencesWithoutMappingTarget as callback> diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Mapper.java new file mode 100644 index 0000000000..27e3ac9960 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Mapper.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3905; + +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface Issue3905Mapper { + + OverrideDto map(Override override); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Test.java new file mode 100644 index 0000000000..f15271362d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Issue3905Test.java @@ -0,0 +1,26 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3905; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +/** + * @author Filip Hrisafov + */ +@IssueKey("3905") +@WithClasses({ + Issue3905Mapper.class, + Override.class, + OverrideDto.class +}) +class Issue3905Test { + + @ProcessorTest + void shouldCompile() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Override.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Override.java new file mode 100644 index 0000000000..dedc6b28dc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/Override.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3905; + +/** + * @author Filip Hrisafov + */ +public class Override { + + private final String name; + + public Override(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/OverrideDto.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/OverrideDto.java new file mode 100644 index 0000000000..531fab505b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3905/OverrideDto.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3905; + +/** + * @author Filip Hrisafov + */ +public class OverrideDto { + + private final String name; + + public OverrideDto(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} From a0552131a5bf89f8192acb154b81bbd03d334ba4 Mon Sep 17 00:00:00 2001 From: hdulme Date: Wed, 31 Dec 2025 17:23:53 +0100 Subject: [PATCH 0915/1006] skip coverage upload to codecov on contributors repositories --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b6a2ef371e..c4e6092723 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,7 +29,7 @@ jobs: if: matrix.java == 21 run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' - if: matrix.java == 21 + if: matrix.java == 21 && github.repository == 'mapstruct/mapstruct' uses: codecov/codecov-action@v2 - name: 'Publish Snapshots' if: matrix.java == 21 && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' From 1c8b9107f99e986e5e28cff66ad604ca89975a8c Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Fri, 23 Jan 2026 22:01:18 +0100 Subject: [PATCH 0916/1006] Update codecov-action to v5 and use token (#3967) --- .github/workflows/main.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4e6092723..c4def2a89d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,7 +30,10 @@ jobs: run: ./mvnw jacoco:report - name: 'Upload coverage to Codecov' if: matrix.java == 21 && github.repository == 'mapstruct/mapstruct' - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v5 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} - name: 'Publish Snapshots' if: matrix.java == 21 && github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'mapstruct/mapstruct' run: ./mvnw -s etc/ci-settings.xml -DskipTests=true -DskipDistribution=true deploy From 7bcab2824d0d17fe0a68d520e0c73f83a0e82588 Mon Sep 17 00:00:00 2001 From: ro-otgo <116685946+ro-otgo@users.noreply.github.com> Date: Sat, 24 Jan 2026 15:44:21 +0100 Subject: [PATCH 0917/1006] Fix example 5 code comment. (#3968) Example 5: Mapping with default value should be using fullName instead of just name in order to map the property. --- core/src/main/java/org/mapstruct/Mapping.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapstruct/Mapping.java b/core/src/main/java/org/mapstruct/Mapping.java index f15cfb75cc..c1923eb41a 100644 --- a/core/src/main/java/org/mapstruct/Mapping.java +++ b/core/src/main/java/org/mapstruct/Mapping.java @@ -118,7 +118,7 @@ * // we can use {@link #defaultValue()} or {@link #defaultExpression()} for it * @Mapper * public interface HumanMapper { - * @Mapping(source="name", target="name", defaultValue="Somebody") + * @Mapping(source="name", target="fullName", defaultValue="Somebody") * HumanDto toHumanDto(Human human) * } * From 57790791abd0193cf0ff42d33524c69ab0eb6215 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 24 Jan 2026 15:46:36 +0100 Subject: [PATCH 0918/1006] BeanMappingMethod and NestedPropertyMappingMethod simplification (#3970) * Move `returnTypeBuilder` and `userDefinedReturnType` in `BeanMappingMethod#build` instead of doing it earlier * Move source parameter presence check resolving into `PresenceCheckMethodResolver` * Simplify `NestedPropertyMappingMethod.ftl` by moving logic into java instead of freemarker --- .../internal/model/AbstractBaseBuilder.java | 4 +- .../model/AbstractMappingMethodBuilder.java | 7 +- .../ap/internal/model/BeanMappingMethod.java | 32 +++----- .../model/NestedPropertyMappingMethod.java | 79 ++++++++++++------- .../model/PresenceCheckMethodResolver.java | 4 + .../ap/internal/model/PropertyMapping.java | 2 +- .../AnyPresenceChecksPresenceCheck.java | 64 +++++++++++++++ .../processor/MapperCreationProcessor.java | 14 ---- .../model/NestedPropertyMappingMethod.ftl | 16 +--- .../AnyPresenceChecksPresenceCheck.ftl | 16 ++++ 10 files changed, 152 insertions(+), 86 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.ftl diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 56a1831d52..584e0260bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -9,7 +9,6 @@ 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; @@ -73,7 +72,7 @@ private boolean isDisableSubMappingMethodsGeneration() { * * @return See above */ - Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, ForgedMethod forgedMethod) { + Assignment createForgedAssignment(SourceRHS sourceRHS, ForgedMethod forgedMethod) { Supplier forgedMappingMethodCreator; if ( MappingMethodUtils.isEnumMapping( forgedMethod ) ) { @@ -87,7 +86,6 @@ Assignment createForgedAssignment(SourceRHS sourceRHS, BuilderType builderType, else { forgedMappingMethodCreator = () -> new BeanMappingMethod.Builder() .forgedMethod( forgedMethod ) - .returnTypeBuilder( builderType ) .mappingContext( ctx ) .build(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index efb5887c95..3b6e3c1686 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -5,7 +5,6 @@ */ package org.mapstruct.ap.internal.model; -import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.model.beanmapping.MappingReferences; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.SourceRHS; @@ -94,12 +93,8 @@ private Assignment forgeMapping(SourceRHS sourceRHS, Type sourceType, Type targe ForgedMethod forgedMethod = forgeMethodCreator.createMethod( name, sourceType, targetType, method, description, true ); - BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); - return createForgedAssignment( - sourceRHS, - ctx.getTypeFactory().builderTypeFor( targetType, builder ), - forgedMethod ); + return createForgedAssignment( sourceRHS, forgedMethod ); } private String getName(Type sourceType, Type targetType) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 05e0424a21..39222efc88 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -32,6 +32,7 @@ import javax.lang.model.util.ElementFilter; import javax.tools.Diagnostic; +import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.gem.ReportingPolicyGem; import org.mapstruct.ap.internal.model.PropertyMapping.ConstantMappingBuilder; @@ -52,7 +53,6 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer; import org.mapstruct.ap.internal.model.dependency.GraphAnalyzer.GraphAnalyzerBuilder; -import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.source.BeanMappingOptions; import org.mapstruct.ap.internal.model.source.MappingOptions; import org.mapstruct.ap.internal.model.source.Method; @@ -106,8 +106,6 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { public static class Builder extends AbstractMappingMethodBuilder { - private Type userDefinedReturnType; - /* returnType to construct can have a builder */ private BuilderType returnTypeBuilder; private Map unprocessedConstructorProperties; @@ -135,16 +133,6 @@ protected boolean shouldUsePropertyNamesInHistory() { return true; } - public Builder userDefinedReturnType(Type userDefinedReturnType) { - this.userDefinedReturnType = userDefinedReturnType; - return this; - } - - public Builder returnTypeBuilder( BuilderType returnTypeBuilder ) { - this.returnTypeBuilder = returnTypeBuilder; - return this; - } - public Builder sourceMethod(SourceMethod sourceMethod) { method( sourceMethod ); return this; @@ -181,7 +169,17 @@ public BeanMappingMethod build() { // determine which return type to construct boolean cannotConstructReturnType = false; if ( !method.getReturnType().isVoid() ) { - Type returnTypeImpl = null; + BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); + Type returnTypeImpl; + Type userDefinedReturnType = null; + if ( selectionParameters != null && selectionParameters.getResultType() != null ) { + // This is a user-defined return type, which means we need to do some extra checks for it + userDefinedReturnType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ); + returnTypeBuilder = ctx.getTypeFactory().builderTypeFor( userDefinedReturnType, builder ); + } + else { + returnTypeBuilder = ctx.getTypeFactory().builderTypeFor( method.getReturnType(), builder ); + } if ( isBuilderRequired() ) { // the userDefinedReturn type can also require a builder. That buildertype is already set returnTypeImpl = returnTypeBuilder.getBuilder(); @@ -446,12 +444,6 @@ else if ( !method.isUpdateMethod() ) { if ( parameterPresenceCheck != null ) { presenceChecksByParameter.put( sourceParameter.getName(), parameterPresenceCheck ); } - else if ( !sourceParameter.getType().isPrimitive() ) { - presenceChecksByParameter.put( - sourceParameter.getName(), - new NullPresenceCheck( sourceParameter.getName() ) - ); - } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index da73e1783f..25c9f8fc03 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set; @@ -14,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.presence.AnyPresenceChecksPresenceCheck; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; @@ -68,9 +71,32 @@ public NestedPropertyMappingMethod build() { } String previousPropertyName = sourceParameter.getName(); - for ( PropertyEntry propertyEntry : propertyEntries ) { + for ( int i = 0; i < propertyEntries.size(); i++ ) { + PropertyEntry propertyEntry = propertyEntries.get( i ); + PresenceCheck presenceCheck = getPresenceCheck( propertyEntry, previousPropertyName ); + + if ( i > 0 ) { + // If this is not the first property entry, + // then we might need to combine the presence check with a null check of the previous property + if ( presenceCheck != null ) { + presenceCheck = new AnyPresenceChecksPresenceCheck( Arrays.asList( + new NullPresenceCheck( previousPropertyName, true ), + presenceCheck + ) ); + } + else { + presenceCheck = new NullPresenceCheck( previousPropertyName, true ); + } + } + String safeName = Strings.getSafeVariableName( propertyEntry.getName(), existingVariableNames ); - safePropertyEntries.add( new SafePropertyEntry( propertyEntry, safeName, previousPropertyName ) ); + String source = previousPropertyName + "." + propertyEntry.getReadAccessor().getReadValueSource(); + safePropertyEntries.add( new SafePropertyEntry( + propertyEntry.getType(), + safeName, + source, + presenceCheck + ) ); existingVariableNames.add( safeName ); thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( propertyEntry.getReadAccessor() ) ); @@ -79,6 +105,18 @@ public NestedPropertyMappingMethod build() { method.addThrownTypes( thrownTypes ); return new NestedPropertyMappingMethod( method, safePropertyEntries ); } + + private PresenceCheck getPresenceCheck(PropertyEntry propertyEntry, String previousPropertyName) { + PresenceCheckAccessor propertyPresenceChecker = propertyEntry.getPresenceChecker(); + if ( propertyPresenceChecker != null ) { + return new SuffixPresenceCheck( + previousPropertyName, + propertyPresenceChecker.getPresenceCheckSuffix(), + true + ); + } + return null; + } } private NestedPropertyMappingMethod( ForgedMethod method, List sourcePropertyEntries ) { @@ -157,44 +195,29 @@ public boolean equals( Object obj ) { public static class SafePropertyEntry { private final String safeName; - private final String readAccessorName; + private final String source; private final PresenceCheck presenceChecker; - private final String previousPropertyName; private final Type type; - public SafePropertyEntry(PropertyEntry entry, String safeName, String previousPropertyName) { + public SafePropertyEntry(Type type, String safeName, String source, PresenceCheck presenceCheck) { this.safeName = safeName; - this.readAccessorName = entry.getReadAccessor().getReadValueSource(); - PresenceCheckAccessor presenceChecker = entry.getPresenceChecker(); - if ( presenceChecker != null ) { - this.presenceChecker = new SuffixPresenceCheck( - previousPropertyName, - presenceChecker.getPresenceCheckSuffix() - ); - } - else { - this.presenceChecker = null; - } - this.previousPropertyName = previousPropertyName; - this.type = entry.getType(); + this.source = source; + this.presenceChecker = presenceCheck; + this.type = type; } public String getName() { return safeName; } - public String getAccessorName() { - return readAccessorName; + public String getSource() { + return source; } public PresenceCheck getPresenceChecker() { return presenceChecker; } - public String getPreviousPropertyName() { - return previousPropertyName; - } - public Type getType() { return type; } @@ -210,7 +233,7 @@ public boolean equals(Object o) { SafePropertyEntry that = (SafePropertyEntry) o; - if ( !Objects.equals( readAccessorName, that.readAccessorName ) ) { + if ( !Objects.equals( source, that.source ) ) { return false; } @@ -218,10 +241,6 @@ public boolean equals(Object o) { return false; } - if ( !Objects.equals( previousPropertyName, that.previousPropertyName ) ) { - return false; - } - if ( !Objects.equals( type, that.type ) ) { return false; } @@ -231,7 +250,7 @@ public boolean equals(Object o) { @Override public int hashCode() { - int result = readAccessorName != null ? readAccessorName.hashCode() : 0; + int result = source != null ? source.hashCode() : 0; result = 31 * result + ( presenceChecker != null ? presenceChecker.hashCode() : 0 ); result = 31 * result + ( type != null ? type.hashCode() : 0 ); return result; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index 96826f8f66..049e4caf37 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -12,6 +12,7 @@ import org.mapstruct.ap.internal.gem.ConditionStrategyGem; import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -86,6 +87,9 @@ public static PresenceCheck getPresenceCheckForSourceParameter( ); if ( matchingMethods.isEmpty() ) { + if ( !sourceParameter.getType().isPrimitive() ) { + return new NullPresenceCheck( sourceParameter.getName() ); + } return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index db14ccbd8e..08e8adbd1b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -829,7 +829,7 @@ private Assignment forgeMapping(Type sourceType, Type targetType, SourceRHS sour forgeMethodWithMappingReferences, forgedNamedBased ); - return createForgedAssignment( sourceRHS, targetBuilderType, forgedMethod ); + return createForgedAssignment( sourceRHS, forgedMethod ); } private ForgedMethodHistory getForgedMethodHistory(SourceRHS sourceRHS) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java new file mode 100644 index 0000000000..0b5770e42f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java @@ -0,0 +1,64 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.NegatePresenceCheck; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class AnyPresenceChecksPresenceCheck extends ModelElement implements PresenceCheck { + + private final Collection presenceChecks; + + public AnyPresenceChecksPresenceCheck(Collection presenceChecks) { + this.presenceChecks = presenceChecks; + } + + public Collection getPresenceChecks() { + return presenceChecks; + } + + @Override + public PresenceCheck negate() { + return new NegatePresenceCheck( this ); + } + + @Override + public Set getImportTypes() { + Set importTypes = new HashSet<>(); + for ( PresenceCheck presenceCheck : presenceChecks ) { + importTypes.addAll( presenceCheck.getImportTypes() ); + } + + return importTypes; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + AnyPresenceChecksPresenceCheck that = (AnyPresenceChecksPresenceCheck) o; + return Objects.equals( presenceChecks, that.presenceChecks ); + } + + @Override + public int hashCode() { + return Objects.hash( presenceChecks ); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index 4fbed6cbec..ba24e868aa 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -24,7 +24,6 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; -import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.DecoratedWithGem; import org.mapstruct.ap.internal.gem.InheritConfigurationGem; import org.mapstruct.ap.internal.gem.InheritInverseConfigurationGem; @@ -420,15 +419,10 @@ else if ( method.isStreamMapping() ) { } else { this.messager.note( 1, Message.BEANMAPPING_CREATE_NOTE, method ); - BuilderGem builder = method.getOptions().getBeanMapping().getBuilder(); - Type userDefinedReturnType = getUserDesiredReturnType( method ); - Type builderBaseType = userDefinedReturnType != null ? userDefinedReturnType : method.getReturnType(); BeanMappingMethod.Builder beanMappingBuilder = new BeanMappingMethod.Builder(); BeanMappingMethod beanMappingMethod = beanMappingBuilder .mappingContext( mappingContext ) .sourceMethod( method ) - .userDefinedReturnType( userDefinedReturnType ) - .returnTypeBuilder( typeFactory.builderTypeFor( builderBaseType, builder ) ) .build(); // We can consider that the bean mapping method can always be constructed. If there is a problem @@ -466,14 +460,6 @@ private Javadoc getJavadoc(TypeElement element) { return javadoc; } - private Type getUserDesiredReturnType(SourceMethod method) { - SelectionParameters selectionParameters = method.getOptions().getBeanMapping().getSelectionParameters(); - if ( selectionParameters != null && selectionParameters.getResultType() != null ) { - return typeFactory.getType( selectionParameters.getResultType() ); - } - return null; - } - private M createWithElementMappingMethod(SourceMethod method, MappingMethodOptions mappingMethodOptions, ContainerMappingMethodBuilder builder) { diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl index 8eabe23a16..04d385a9dc 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.ftl @@ -9,22 +9,14 @@ <#lt>private <@includeModel object=returnType.typeBound/> ${name}(<#list parameters as param><@includeModel object=param/><#if param_has_next>, )<@throws/> { <#list propertyEntries as entry> <#if entry.presenceChecker?? > - if ( <#if entry_index != 0>${entry.previousPropertyName} == null || !<@includeModel object=entry.presenceChecker /> ) { + if ( <@includeModel object=entry.presenceChecker /> ) { return ${returnType.null}; } - <#if !entry_has_next> - return ${entry.previousPropertyName}.${entry.accessorName}; - <#if entry_has_next> - <@includeModel object=entry.type.typeBound/> ${entry.name} = ${entry.previousPropertyName}.${entry.accessorName}; - <#if !entry.presenceChecker?? > - <#if !entry.type.primitive> - if ( ${entry.name} == null ) { - return ${returnType.null}; - } - - + <@includeModel object=entry.type.typeBound/> ${entry.name} = ${entry.source}; + <#else> + return ${entry.source}; } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.ftl new file mode 100644 index 0000000000..3df10348ad --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.ftl @@ -0,0 +1,16 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.AnyPresenceChecksPresenceCheck" --> +<@compress single_line=true> +<#list presenceChecks as presenceCheck> + <#if presenceCheck_index != 0> + || + + <@includeModel object=presenceCheck /> + + \ No newline at end of file From 9d75a48df5e40c1ed87d2f68d96fbb35807e3b91 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 26 Jan 2026 11:35:18 +0100 Subject: [PATCH 0919/1006] Block plexus.snapshots repository in GitHub actions #3972 --- .github/workflows/java-ea.yml | 3 +++ .github/workflows/macos.yml | 3 +++ .github/workflows/main.yml | 6 ++++++ .github/workflows/release.yml | 4 ++++ .github/workflows/windows.yml | 3 +++ 5 files changed, 19 insertions(+) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index fc3a4a0fb1..70b81c40f1 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -17,5 +17,8 @@ jobs: with: website: jdk.java.net release: EA + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 833bb6ba39..98b4e156e0 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,5 +16,8 @@ jobs: with: distribution: 'zulu' java-version: 21 + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4def2a89d..ca66a22291 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,6 +23,9 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=${{ matrix.java != 21 }} install -DskipDistribution=${{ matrix.java != 21 }} - name: 'Generate coverage report' @@ -59,5 +62,8 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Run integration tests' run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 61f347af3c..b4dffe0586 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,10 @@ jobs: distribution: 'zulu' cache: maven + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' + - name: Set release version id: version run: | diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index bda38f8783..fc37af6a9d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -16,5 +16,8 @@ jobs: with: distribution: 'zulu' java-version: 21 + - uses: s4u/maven-settings-action@v4.0.0 + with: + mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw %MAVEN_ARGS% install From 99e865f9861bba3d8cc24d90b89821e8bb191164 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 10:27:59 +0100 Subject: [PATCH 0920/1006] Improve testing support for Kotlin as part of the regular processor testing (#3977) --- .../itest/tests/MavenIntegrationTest.java | 6 + .../test/resources/fullFeatureTest/pom.xml | 1 + .../resources/kotlinFullFeatureTest/pom.xml | 143 ++++++++++++++++++ parent/pom.xml | 13 ++ processor/pom.xml | 68 +++++++++ .../ap/test/kotlin/data/CustomerDto.kt | 11 ++ .../ap/test/kotlin/data/CustomerEntity.java | 31 ++++ .../ap/test/kotlin/data/CustomerMapper.java | 27 ++++ .../ap/test/kotlin/data/KotlinDataTest.java | 54 +++++++ .../ap/testutil/WithKotlinSources.java | 32 ++++ .../model/CompilationOutcomeDescriptor.java | 31 ++++ .../model/DiagnosticDescriptor.java | 34 +++++ .../testutil/runner/CompilationRequest.java | 12 +- .../testutil/runner/CompilingExtension.java | 102 ++++++++++++- .../runner/EclipseCompilingExtension.java | 11 +- .../runner/JdkCompilingExtension.java | 15 +- 16 files changed, 579 insertions(+), 12 deletions(-) create mode 100644 integrationtest/src/test/resources/kotlinFullFeatureTest/pom.xml create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerDto.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerEntity.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithKotlinSources.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index ab43cc4cba..70e1f948b9 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -159,6 +159,12 @@ void expressionTextBlocksTest() { void kotlinDataTest() { } + @ProcessorTest(baseDir = "kotlinFullFeatureTest", processorTypes = { + ProcessorTest.ProcessorType.JAVAC_WITH_PATHS + }) + void kotlinFullFeatureTest() { + } + @ProcessorTest(baseDir = "simpleTest") void simpleTest() { } diff --git a/integrationtest/src/test/resources/fullFeatureTest/pom.xml b/integrationtest/src/test/resources/fullFeatureTest/pom.xml index b5ddae9a79..670d5cff92 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/pom.xml +++ b/integrationtest/src/test/resources/fullFeatureTest/pom.xml @@ -47,6 +47,7 @@ **/*Test.java **/testutil/**/*.java **/spi/**/*.java + **/kotlin/**/*.java ${additionalExclude0} ${additionalExclude1} ${additionalExclude2} diff --git a/integrationtest/src/test/resources/kotlinFullFeatureTest/pom.xml b/integrationtest/src/test/resources/kotlinFullFeatureTest/pom.xml new file mode 100644 index 0000000000..ba18457f42 --- /dev/null +++ b/integrationtest/src/test/resources/kotlinFullFeatureTest/pom.xml @@ -0,0 +1,143 @@ + + + + 4.0.0 + + + org.mapstruct + mapstruct-it-parent + 1.0.0 + ../pom.xml + + + kotlinFullFeatureTest + jar + + + 2.3.0 + + + + + generate-via-compiler-plugin-with-annotation-processor-paths + + false + + + + + maven-resources-plugin + + + filter-kotlin-patterns + generate-sources + + copy-resources + + + \${project.build.directory}/kotlin-sources + + + ../../../../../processor/src/test/java + + **/kotlin/**/*.kt + + + + true + + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + + + kotlin-compile + compile + + compile + + + + \${project.build.directory}/kotlin-sources + + + + ${project.groupId} + mapstruct-processor + ${mapstruct.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + + default-compile + none + + + default-testCompile + none + + + + + java-compile + compile + + compile + + + + ../../../../../processor/src/test/java + + + **/kotlin/**/*.java + + + **/erroneous/**/*.java + **/*Erroneous*.java + **/*Test.java + **/testutil/**/*.java + + + + + java-test-compile + test-compile + + testCompile + + + + + + + + + + + + org.jetbrains.kotlin + kotlin-stdlib + + + + diff --git a/parent/pom.xml b/parent/pom.xml index f90b066774..5c3a73da88 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -52,6 +52,7 @@ 1.8 3.25.5 2.3.2 + 2.3.0 @@ -151,6 +152,13 @@ ${com.puppycrawl.tools.checkstyle.version} + + org.jetbrains.kotlin + kotlin-bom + ${kotlin.version} + pom + import + org.junit junit-bom @@ -490,6 +498,11 @@ maven-shade-plugin 3.2.0 + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + com.mycila.maven-license-plugin maven-license-plugin diff --git a/processor/pom.xml b/processor/pom.xml index 87c3517018..9f24281e33 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -42,6 +42,11 @@ mapstruct provided + + org.jetbrains.kotlin + kotlin-compiler-embeddable + test + org.eclipse.tycho tycho-compiler-jdt @@ -282,6 +287,42 @@ + + org.jetbrains.kotlin + + kotlin-maven-plugin + + false + + + + kotlin-compile + compile + + compile + + + + src/main/kotlin + + src/main/java + + + + + kotlin-test-compile + test-compile + + test-compile + + + + src/test/java + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -296,6 +337,33 @@ + + + + default-compile + none + + + default-testCompile + none + + + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + + testCompile + + + org.apache.maven.plugins diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerDto.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerDto.kt new file mode 100644 index 0000000000..3fbd48b0b1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerDto.kt @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class CustomerDto(var name: String?, var email: String?) diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerEntity.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerEntity.java new file mode 100644 index 0000000000..7ddd41bda0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerEntity.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +/** + * @author Filip Hrisafov + */ +public class CustomerEntity { + + private String name; + private String mail; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMail() { + return mail; + } + + public void setMail(String mail) { + this.mail = mail; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerMapper.java new file mode 100644 index 0000000000..1830a9c583 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/CustomerMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface CustomerMapper { + + CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class ); + + @Mapping(target = "mail", source = "email") + CustomerEntity fromData(CustomerDto record); + + @InheritInverseConfiguration + CustomerDto toData(CustomerEntity entity); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java new file mode 100644 index 0000000000..310039363d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java @@ -0,0 +1,54 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.junit.jupiter.api.Nested; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithKotlinSources; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +class KotlinDataTest { + + @Nested + @WithClasses({ + CustomerEntity.class, + CustomerMapper.class + }) + @WithKotlinSources("CustomerDto.kt") + class Standard { + + @ProcessorTest + void shouldMapData() { + CustomerEntity customer = CustomerMapper.INSTANCE.fromData( new CustomerDto( + "Kermit", + "kermit@test.com" + ) ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" ); + } + + @ProcessorTest + void shouldMapIntoData() { + CustomerEntity entity = new CustomerEntity(); + entity.setName( "Kermit" ); + entity.setMail( "kermit@test.com" ); + + CustomerDto customer = CustomerMapper.INSTANCE.toData( entity ); + + assertThat( customer ).isNotNull(); + assertThat( customer.getName() ).isEqualTo( "Kermit" ); + assertThat( customer.getEmail() ).isEqualTo( "kermit@test.com" ); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlinSources.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlinSources.java new file mode 100644 index 0000000000..656dc9bc5f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlinSources.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.intellij.lang.annotations.Language; + +/** + * Specifies the kotlin sources to compile during an annotation processor test. + * If given both on the class-level and the method-level for a given test, all the given sources will be compiled. + * + * @author Filip Hrisafov + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +public @interface WithKotlinSources { + + /** + * The classes to be compiled for the annotated test class or method. + * + * @return the classes to be compiled for the annotated test class or method + */ + @Language(value = "file-reference", prefix = "", suffix = ".kt") + String[] value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java index b9f7bb8425..b5a4dc535d 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/CompilationOutcomeDescriptor.java @@ -18,6 +18,8 @@ import org.codehaus.plexus.compiler.CompilerMessage; import org.codehaus.plexus.compiler.CompilerResult; +import org.jetbrains.kotlin.cli.common.ExitCode; +import org.jetbrains.kotlin.cli.common.messages.MessageCollectorImpl; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedNote; @@ -104,6 +106,25 @@ public static CompilationOutcomeDescriptor forResult(String sourceDir, CompilerR return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors, Collections.emptyList() ); } + public static CompilationOutcomeDescriptor forResult(String sourceDir, ExitCode exitCode, + List messages) { + List notes = new ArrayList<>(); + List diagnosticDescriptors = new ArrayList<>( messages.size() ); + for ( MessageCollectorImpl.Message message : messages ) { + //ignore notes created by the compiler + DiagnosticDescriptor descriptor = DiagnosticDescriptor.forCompilerMessage( sourceDir, message ); + if ( descriptor.getKind() != Kind.NOTE ) { + diagnosticDescriptors.add( descriptor ); + } + else { + notes.add( descriptor.getMessage() ); + } + } + CompilationResult compilationResult = + exitCode == ExitCode.OK ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; + return new CompilationOutcomeDescriptor( compilationResult, diagnosticDescriptors, notes ); + } + public CompilationResult getCompilationResult() { return compilationResult; } @@ -116,6 +137,16 @@ public List getNotes() { return notes; } + public CompilationOutcomeDescriptor merge(CompilationOutcomeDescriptor other) { + CompilationResult compilationResult = + this.compilationResult == CompilationResult.SUCCEEDED ? other.compilationResult : this.compilationResult; + List diagnostics = new ArrayList<>( this.diagnostics ); + diagnostics.addAll( other.diagnostics ); + List notes = new ArrayList<>( this.notes ); + notes.addAll( other.notes ); + return new CompilationOutcomeDescriptor( compilationResult, diagnostics, notes ); + } + @Override public int hashCode() { final int prime = 31; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index ecfec14a16..68e2cb00fe 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -15,6 +15,9 @@ import javax.tools.JavaFileObject; import org.codehaus.plexus.compiler.CompilerMessage; +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity; +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation; +import org.jetbrains.kotlin.cli.common.messages.MessageCollectorImpl; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; /** @@ -100,6 +103,37 @@ private static Kind toJavaxKind(CompilerMessage.Kind kind) { } } + public static DiagnosticDescriptor forCompilerMessage(String sourceDir, MessageCollectorImpl.Message message) { + CompilerMessageSourceLocation location = message.getLocation(); + String sourceFileName; + Long line; + if ( location != null ) { + sourceFileName = location.getPath(); + line = (long) location.getLine(); + } + else { + sourceFileName = null; + line = null; + } + return new DiagnosticDescriptor( + sourceFileName, + toJavaxKind( message.getSeverity() ), + line, + message.getMessage(), + null + ); + } + + private static Kind toJavaxKind(CompilerMessageSeverity severity) { + return switch ( severity ) { + case ERROR, EXCEPTION -> Kind.ERROR; + case WARNING, FIXED_WARNING -> Kind.WARNING; + case STRONG_WARNING -> Kind.MANDATORY_WARNING; + case INFO, LOGGING -> Kind.NOTE; + case OUTPUT -> Kind.OTHER; + }; + } + private static String getSourceName(String sourceDir, javax.tools.Diagnostic diagnostic) { if ( diagnostic.getSource() == null ) { return null; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index 9f1b78caa0..8622fbe92c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -19,14 +19,17 @@ public class CompilationRequest { private final Map, Class> services; private final List processorOptions; private final Collection testDependencies; + private final Collection kotlinSources; CompilationRequest(Compiler compiler, Set> sourceClasses, Map, Class> services, - List processorOptions, Collection testDependencies) { + List processorOptions, Collection testDependencies, + Collection kotlinSources) { this.compiler = compiler; this.sourceClasses = sourceClasses; this.services = services; this.processorOptions = processorOptions; this.testDependencies = testDependencies; + this.kotlinSources = kotlinSources; } @Override @@ -58,7 +61,8 @@ public boolean equals(Object obj) { && processorOptions.equals( other.processorOptions ) && services.equals( other.services ) && testDependencies.equals( other.testDependencies ) - && sourceClasses.equals( other.sourceClasses ); + && sourceClasses.equals( other.sourceClasses ) + && kotlinSources.equals( other.kotlinSources ); } public Set> getSourceClasses() { @@ -77,6 +81,10 @@ public Collection getTestDependencies() { return testDependencies; } + public Collection getKotlinSources() { + return kotlinSources; + } + public Compiler getCompiler() { return compiler; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index 95874e4b3d..7ff78753a6 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.ConfigurationLoader; @@ -30,9 +31,15 @@ import com.puppycrawl.tools.checkstyle.PropertiesExpander; import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import org.apache.commons.io.output.NullOutputStream; +import org.jetbrains.kotlin.cli.common.ExitCode; +import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; +import org.jetbrains.kotlin.cli.common.messages.MessageCollectorImpl; +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; +import org.jetbrains.kotlin.config.Services; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithKotlinSources; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithTestDependency; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -455,6 +462,20 @@ protected static Set getSourceFiles(Collection> classes) { return sourceFiles; } + private Collection getKotlinSources(ExtensionContext context) { + Collection kotlinSources = new HashSet<>(); + Method testMethod = context.getRequiredTestMethod(); + Class testClass = context.getRequiredTestClass(); + + findAnnotation( testMethod, WithKotlinSources.class ) + .ifPresent( withKotlinSources -> Collections.addAll( kotlinSources, withKotlinSources.value() ) ); + + findAnnotation( testClass, WithKotlinSources.class ) + .ifPresent( withKotlinSources -> Collections.addAll( kotlinSources, withKotlinSources.value() ) ); + + return kotlinSources; + } + private CompilationOutcomeDescriptor compile(ExtensionContext context) { Method testMethod = context.getRequiredTestMethod(); Class testClass = context.getRequiredTestClass(); @@ -464,7 +485,8 @@ private CompilationOutcomeDescriptor compile(ExtensionContext context) { getTestClasses( testMethod, testClass ), getServices( testMethod, testClass ), getProcessorOptions( testMethod, testClass ), - getAdditionalTestDependencies( testMethod, testClass ) + getAdditionalTestDependencies( testMethod, testClass ), + getKotlinSources( context ) ); ExtensionContext.Store rootStore = context.getRoot().getStore( NAMESPACE ); @@ -484,7 +506,8 @@ private CompilationOutcomeDescriptor compile(ExtensionContext context) { boolean needsAdditionalCompilerClasspath = prepareServices( compilationRequest ); CompilationOutcomeDescriptor resultHolder; - resultHolder = compileWithSpecificCompiler( + resultHolder = compile( + context, compilationRequest, sourceOutputDir, classOutputDir, @@ -503,6 +526,81 @@ protected Object loadAndInstantiate(ClassLoader processorClassloader, Class c } } + protected CompilationOutcomeDescriptor compile( + ExtensionContext context, + CompilationRequest compilationRequest, + String sourceOutputDir, + String classOutputDir, + String additionalCompilerClasspath) { + CompilationOutcomeDescriptor kotlinCompilationOutcome = compileWithKotlin( + context, + compilationRequest, + sourceOutputDir, + classOutputDir + ); + + if ( kotlinCompilationOutcome != null && + kotlinCompilationOutcome.getCompilationResult() == CompilationResult.FAILED ) { + return kotlinCompilationOutcome; + } + + CompilationOutcomeDescriptor javaCompilationOutcome = compileWithSpecificCompiler( + compilationRequest, + sourceOutputDir, + classOutputDir, + additionalCompilerClasspath + ); + return kotlinCompilationOutcome == null ? javaCompilationOutcome : + kotlinCompilationOutcome.merge( javaCompilationOutcome ); + } + + private CompilationOutcomeDescriptor compileWithKotlin( + ExtensionContext context, + CompilationRequest compilationRequest, + String sourceOutputDir, + String classOutputDir + ) { + CompilationOutcomeDescriptor kotlinCompilationOutcome = null; + if ( !compilationRequest.getKotlinSources().isEmpty() ) { + K2JVMCompiler k2JvmCompiler = new K2JVMCompiler(); + MessageCollectorImpl messageCollector = new MessageCollectorImpl(); + K2JVMCompilerArguments k2JvmArguments = new K2JVMCompilerArguments(); + k2JvmArguments.setClasspath( + String.join( + File.pathSeparator, filterBootClassPath( List.of( + "kotlin-stdlib", + "kotlin-reflect" + ) ) + ) + ); + k2JvmArguments.setNoStdlib( true ); + k2JvmArguments.setNoReflect( true ); + String packageName = context.getRequiredTestClass() + .getPackageName(); + String sourcePrefix = + SOURCE_DIR + File.separator + packageName.replace( ".", File.separator ) + File.separator; + k2JvmArguments.setFreeArgs( Arrays.asList( + compilationRequest.getKotlinSources() + .stream() + .map( kotlinSource -> sourcePrefix + kotlinSource ) + .collect( Collectors.joining( File.pathSeparator ) ) + ) ); + k2JvmArguments.setVerbose( true ); + k2JvmArguments.setSuppressWarnings( false ); + k2JvmArguments.setDestination( classOutputDir ); + + ExitCode kotlinExitCode = k2JvmCompiler.exec( messageCollector, Services.EMPTY, k2JvmArguments ); + + kotlinCompilationOutcome = CompilationOutcomeDescriptor.forResult( + sourceOutputDir, + kotlinExitCode, + messageCollector.getMessages() + ); + + } + return kotlinCompilationOutcome; + } + protected abstract CompilationOutcomeDescriptor compileWithSpecificCompiler( CompilationRequest compilationRequest, String sourceOutputDir, diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java index c356347664..4755df0bd1 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java @@ -68,24 +68,27 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe return clHelper.compileInOtherClassloader( compilationRequest, - getTestCompilationClasspath( compilationRequest ), + getTestCompilationClasspath( compilationRequest, classOutputDir ), getSourceFiles( compilationRequest.getSourceClasses() ), SOURCE_DIR, sourceOutputDir, classOutputDir ); } - private static List getTestCompilationClasspath(CompilationRequest request) { + private static List getTestCompilationClasspath(CompilationRequest request, String classOutputDir) { Collection testDependencies = request.getTestDependencies(); - if ( testDependencies.isEmpty() ) { + if ( testDependencies.isEmpty() && request.getKotlinSources().isEmpty() ) { return TEST_COMPILATION_CLASSPATH; } List testCompilationPaths = new ArrayList<>( - TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() ); + TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() + 1 ); testCompilationPaths.addAll( TEST_COMPILATION_CLASSPATH ); testCompilationPaths.addAll( filterBootClassPath( testDependencies ) ); + if ( !request.getKotlinSources().isEmpty() ) { + testCompilationPaths.add( classOutputDir ); + } return testCompilationPaths; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 5185bfb7ed..b6d8afd3bf 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -59,7 +59,10 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe fileManager.getJavaFileObjectsFromFiles( getSourceFiles( compilationRequest.getSourceClasses() ) ); try { - fileManager.setLocation( StandardLocation.CLASS_PATH, getCompilerClasspathFiles( compilationRequest ) ); + fileManager.setLocation( + StandardLocation.CLASS_PATH, + getCompilerClasspathFiles( compilationRequest, classOutputDir ) + ); fileManager.setLocation( StandardLocation.CLASS_OUTPUT, Arrays.asList( new File( classOutputDir ) ) ); fileManager.setLocation( StandardLocation.SOURCE_OUTPUT, Arrays.asList( new File( sourceOutputDir ) ) ); } @@ -99,20 +102,24 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe diagnostics.getDiagnostics() ); } - private static List getCompilerClasspathFiles(CompilationRequest request) { + private static List getCompilerClasspathFiles(CompilationRequest request, String classOutputDir) { Collection testDependencies = request.getTestDependencies(); - if ( testDependencies.isEmpty() ) { + if ( testDependencies.isEmpty() && request.getKotlinSources().isEmpty() ) { return COMPILER_CLASSPATH_FILES; } List compilerClasspathFiles = new ArrayList<>( - COMPILER_CLASSPATH_FILES.size() + testDependencies.size() ); + COMPILER_CLASSPATH_FILES.size() + testDependencies.size() + 1 ); compilerClasspathFiles.addAll( COMPILER_CLASSPATH_FILES ); for ( String testDependencyPath : filterBootClassPath( testDependencies ) ) { compilerClasspathFiles.add( new File( testDependencyPath ) ); } + if ( !request.getKotlinSources().isEmpty() ) { + compilerClasspathFiles.add( new File( classOutputDir ) ); + } + return compilerClasspathFiles; } From d3006640938014a1d8fa193d735cee934771309b Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 12:30:13 +0100 Subject: [PATCH 0921/1006] Improve support for Kotlin Data Classes (#3978) * Properly handle single field data classes * Properly handle multi constructor data classes * Properly handle all defaults constructor data classes Fixes #2281, #2577, #3031 --- NEXT_RELEASE_CHANGELOG.md | 6 + distribution/pom.xml | 5 + .../main/asciidoc/chapter-2-set-up.asciidoc | 71 +++- parent/pom.xml | 5 + processor/pom.xml | 5 + .../ap/internal/model/BeanMappingMethod.java | 22 ++ .../ap/internal/model/common/Type.java | 156 ++++++++ .../internal/util/kotlin/KotlinMetadata.java | 21 + .../ap/spi/DefaultAccessorNamingStrategy.java | 68 +++- .../test/kotlin/data/AllDefaultsProperty.kt | 11 + .../data/AllDefaultsPropertyMapper.java | 39 ++ .../ap/test/kotlin/data/KotlinDataTest.java | 370 ++++++++++++++++++ .../kotlin/data/MultiConstructorProperty.kt | 13 + .../data/MultiConstructorPropertyMapper.java | 45 +++ .../data/MultiDefaultConstructorProperty.kt | 18 + ...MultiDefaultConstructorPropertyMapper.java | 45 +++ .../data/MultiSimilarConstructorProperty.kt | 50 +++ ...MultiSimilarConstructorPropertyMapper.java | 57 +++ .../ap/test/kotlin/data/SingleProperty.kt | 11 + .../kotlin/data/SinglePropertyMapper.java | 32 ++ .../org/mapstruct/ap/testutil/WithKotlin.java | 29 ++ .../testutil/WithProcessorDependencies.java | 22 ++ .../ap/testutil/WithProcessorDependency.java | 28 ++ .../testutil/runner/CompilationRequest.java | 8 + .../testutil/runner/CompilingExtension.java | 22 ++ .../runner/EclipseCompilingExtension.java | 18 +- .../runner/JdkCompilingExtension.java | 31 +- 27 files changed, 1186 insertions(+), 22 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorPropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SingleProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SinglePropertyMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithKotlin.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependencies.java create mode 100644 processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependency.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 2d0555cb24..f279193f6a 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,6 +1,12 @@ ### Features * Support for Java 21 Sequenced Collections (#3240) +* Improved support for Kotlin. Requires use of `org.jetbrains.kotlin:kotlin-metadata-jvm`. + - Data Classes (#2281, #2577, #3031) - MapStruct now properly handles: + - Single field data classes + - Proper primary constructor detection + - Data classes with multiple constructors + - Data classes with all default parameters ### Enhancements diff --git a/distribution/pom.xml b/distribution/pom.xml index db654236e4..b480e24a06 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -39,6 +39,11 @@ org.mapstruct.tools.gem gem-api + + + org.jetbrains.kotlin + kotlin-metadata-jvm + jakarta.xml.bind diff --git a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc index 58759ff8e0..86ed345630 100644 --- a/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc +++ b/documentation/src/main/asciidoc/chapter-2-set-up.asciidoc @@ -35,10 +35,10 @@ For Maven based projects add the following to your POM file in order to use MapS org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.14.1 - 1.8 - 1.8 + ${java.version} + ${java.version} org.mapstruct @@ -141,10 +141,10 @@ When invoking javac directly, these options are passed to the compiler in the fo org.apache.maven.plugins maven-compiler-plugin - 3.5.1 + 3.14.1 - 1.8 - 1.8 + ${java.version} + ${java.version} org.mapstruct @@ -323,3 +323,62 @@ Some features include: * Code completion in `target` and `source` * Quick Fixes + +[[kotlin-setup]] +=== Kotlin Support + +MapStruct provides support for Kotlin interoperability with Java. + +When using MapStruct with Kotlin, it's recommended to add the `org.jetbrains.kotlin:kotlin-metadata-jvm` library to enable proper introspection of Kotlin metadata: + +.Maven configuration for Kotlin support +==== +[source, xml, linenums] +[subs="verbatim,attributes"] +---- +... + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.1 + + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + org.jetbrains.kotlin + kotlin-metadata-jvm + ${kotlin.version} + + + + + + +---- +==== + +.Gradle configuration for Kotlin support +==== +[source, groovy, linenums] +[subs="verbatim,attributes"] +---- +dependencies { + implementation "org.mapstruct:mapstruct:${mapstructVersion}" + + annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" + annotationProcessor "org.jetbrains.kotlin:kotlin-metadata-jvm:${kotlinVersion}" +} +---- +==== + +[NOTE] +==== +The `org.jetbrains.kotlin:kotlin-metadata-jvm` dependency is optional but highly recommended when working with Kotlin and Java. +Without it, MapStruct will still work but may not handle complex Kotlin scenarios optimally. +==== \ No newline at end of file diff --git a/parent/pom.xml b/parent/pom.xml index 5c3a73da88..8c1266ed19 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -159,6 +159,11 @@ pom import + + org.jetbrains.kotlin + kotlin-metadata-jvm + ${kotlin.version} + org.junit junit-bom diff --git a/processor/pom.xml b/processor/pom.xml index 9f24281e33..c51c2bca26 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -42,6 +42,11 @@ mapstruct provided + + org.jetbrains.kotlin + kotlin-metadata-jvm + provided + org.jetbrains.kotlin kotlin-compiler-embeddable diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 39222efc88..619272a175 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -68,6 +68,7 @@ import org.mapstruct.ap.internal.util.accessor.ElementAccessor; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; +import org.mapstruct.ap.internal.util.kotlin.KotlinMetadata; import static org.mapstruct.ap.internal.model.beanmapping.MappingReferences.forSourceMethod; import static org.mapstruct.ap.internal.util.Collections.first; @@ -904,6 +905,27 @@ private ConstructorAccessor getConstructorAccessor(Type type) { return new ConstructorAccessor( parameterBindings, constructorAccessors ); } + KotlinMetadata kotlinMetadata = type.getKotlinMetadata(); + if ( kotlinMetadata != null && kotlinMetadata.isDataClass() ) { + List constructors = ElementFilter.constructorsIn( type.getTypeElement() + .getEnclosedElements() ); + + for ( ExecutableElement constructor : constructors ) { + if ( constructor.getModifiers().contains( Modifier.PRIVATE ) ) { + continue; + } + + // prefer constructor annotated with @Default + if ( hasDefaultAnnotationFromAnyPackage( constructor ) ) { + return getConstructorAccessor( type, constructor ); + } + } + + ExecutableElement primaryConstructor = kotlinMetadata.determinePrimaryConstructor( constructors ); + + return primaryConstructor != null ? getConstructorAccessor( type, primaryConstructor ) : null; + } + List constructors = ElementFilter.constructorsIn( type.getTypeElement() .getEnclosedElements() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 24f23ecea8..313ff38125 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -43,6 +43,13 @@ import javax.lang.model.util.ElementFilter; import javax.lang.model.util.SimpleTypeVisitor8; +import kotlin.Metadata; +import kotlin.metadata.Attributes; +import kotlin.metadata.KmClass; +import kotlin.metadata.KmConstructor; +import kotlin.metadata.jvm.JvmExtensionsKt; +import kotlin.metadata.jvm.JvmMethodSignature; +import kotlin.metadata.jvm.KotlinClassMetadata; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.util.AccessorNamingUtils; import org.mapstruct.ap.internal.util.ElementUtils; @@ -58,6 +65,7 @@ import org.mapstruct.ap.internal.util.accessor.MapValueAccessor; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; import org.mapstruct.ap.internal.util.accessor.ReadAccessor; +import org.mapstruct.ap.internal.util.kotlin.KotlinMetadata; import static java.util.Collections.emptyList; import static org.mapstruct.ap.internal.util.Collections.first; @@ -75,6 +83,7 @@ */ public class Type extends ModelElement implements Comparable { private static final Method SEALED_PERMITTED_SUBCLASSES_METHOD; + private static final boolean KOTLIN_METADATA_JVM_PRESENT; static { Method permittedSubclassesMethod; @@ -85,6 +94,16 @@ public class Type extends ModelElement implements Comparable { permittedSubclassesMethod = null; } SEALED_PERMITTED_SUBCLASSES_METHOD = permittedSubclassesMethod; + + boolean kotlinMetadataJvmPresent; + try { + Class.forName( "kotlin.metadata.jvm.KotlinClassMetadata", false, ModelElement.class.getClassLoader() ); + kotlinMetadataJvmPresent = true; + } + catch ( ClassNotFoundException e ) { + kotlinMetadataJvmPresent = false; + } + KOTLIN_METADATA_JVM_PRESENT = kotlinMetadataJvmPresent; } private final TypeUtils typeUtils; @@ -139,6 +158,8 @@ public class Type extends ModelElement implements Comparable { private Type boxedEquivalent = null; private Boolean hasAccessibleConstructor; + private KotlinMetadata kotlinMetadata; + private boolean kotlinMetadataInitialized; private final Filters filters; @@ -1370,6 +1391,23 @@ public boolean hasAccessibleConstructor() { return hasAccessibleConstructor; } + public KotlinMetadata getKotlinMetadata() { + if ( !kotlinMetadataInitialized ) { + kotlinMetadataInitialized = true; + if ( typeElement != null && KOTLIN_METADATA_JVM_PRESENT ) { + Metadata metadataAnnotation = typeElement.getAnnotation( Metadata.class ); + if ( metadataAnnotation != null ) { + KotlinClassMetadata classMetadata = KotlinClassMetadata.readLenient( metadataAnnotation ); + if ( classMetadata instanceof KotlinClassMetadata.Class ) { + kotlinMetadata = new KotlinMetadataImpl( (KotlinClassMetadata.Class) classMetadata ); + } + } + } + } + + return kotlinMetadata; + } + /** * Returns the direct supertypes of a type. The interface types, if any, * will appear last in the list. @@ -1831,4 +1869,122 @@ public List getPermittedSubclasses() { } } + private class KotlinMetadataImpl implements KotlinMetadata { + + private final KotlinClassMetadata.Class kotlinClassMetadata; + + private KotlinMetadataImpl(KotlinClassMetadata.Class kotlinClassMetadata) { + this.kotlinClassMetadata = kotlinClassMetadata; + } + + @Override + public boolean isDataClass() { + return Attributes.isData( kotlinClassMetadata.getKmClass() ); + } + + @Override + public ExecutableElement determinePrimaryConstructor(List constructors) { + if ( constructors.size() == 1 ) { + // If we have one constructor, that this constructor is the primary one + return constructors.get( 0 ); + } + KmClass kmClass = kotlinClassMetadata.getKmClass(); + KmConstructor primaryKmConstructor = null; + for ( KmConstructor constructor : kmClass.getConstructors() ) { + if ( !Attributes.isSecondary( constructor ) ) { + primaryKmConstructor = constructor; + } + + } + + if ( primaryKmConstructor == null ) { + return null; + } + + List sameParametersSizeConstructors = new ArrayList<>(); + for ( ExecutableElement constructor : constructors ) { + if ( constructor.getParameters().size() == primaryKmConstructor.getValueParameters().size() ) { + sameParametersSizeConstructors.add( constructor ); + } + } + + if ( sameParametersSizeConstructors.size() == 1 ) { + return sameParametersSizeConstructors.get( 0 ); + } + + JvmMethodSignature signature = JvmExtensionsKt.getSignature( primaryKmConstructor ); + if ( signature == null ) { + return null; + } + + String signatureDescriptor = signature.getDescriptor(); + for ( ExecutableElement constructor : constructors ) { + String constructorDescriptor = buildJvmConstructorDescriptor( constructor ); + if ( signatureDescriptor.equals( constructorDescriptor ) ) { + return constructor; + } + } + + return null; + } + + private String buildJvmConstructorDescriptor(ExecutableElement constructor) { + StringBuilder signature = new StringBuilder( "(" ); + + for ( VariableElement param : constructor.getParameters() ) { + signature.append( getJvmTypeDescriptor( param.asType() ) ); + } + + signature.append( ")V" ); + return signature.toString(); + } + + private String getJvmTypeDescriptor(TypeMirror type) { + return type.accept( + new SimpleTypeVisitor8() { + @Override + public String visitPrimitive(PrimitiveType t, Void p) { + switch ( t.getKind() ) { + case BOOLEAN: + return "Z"; + case BYTE: + return "B"; + case SHORT: + return "S"; + case INT: + return "I"; + case LONG: + return "J"; + case CHAR: + return "C"; + case FLOAT: + return "F"; + case DOUBLE: + return "D"; + default: + return ""; + } + } + + @Override + public String visitDeclared(DeclaredType t, Void p) { + TypeElement element = (TypeElement) t.asElement(); + String binaryName = elementUtils.getBinaryName( element ).toString(); + return "L" + binaryName.replace( '.', '/' ) + ";"; + } + + @Override + public String visitArray(ArrayType t, Void p) { + return "[" + getJvmTypeDescriptor( t.getComponentType() ); + } + + @Override + protected String defaultAction(TypeMirror e, Void p) { + return ""; + } + }, null + ); + } + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java b/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java new file mode 100644 index 0000000000..d58ab75c79 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.util.kotlin; + +import java.util.List; +import javax.lang.model.element.ExecutableElement; + +/** + * Information about a type in case it's a Kotlin type. + * + * @author Filip Hrisafov + */ +public interface KotlinMetadata { + + boolean isDataClass(); + + ExecutableElement determinePrimaryConstructor(List constructors); +} diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 82ecb4e17b..511504c937 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -7,6 +7,7 @@ import java.util.regex.Pattern; +import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.lang.model.type.DeclaredType; @@ -17,6 +18,9 @@ import javax.lang.model.util.SimpleTypeVisitor6; import javax.lang.model.util.Types; +import kotlin.Metadata; +import kotlin.metadata.Attributes; +import kotlin.metadata.jvm.KotlinClassMetadata; import org.mapstruct.ap.spi.util.IntrospectorUtils; /** @@ -28,6 +32,24 @@ public class DefaultAccessorNamingStrategy implements AccessorNamingStrategy { private static final Pattern JAVA_JAVAX_PACKAGE = Pattern.compile( "^javax?\\..*" ); + private static final boolean KOTLIN_METADATA_JVM_PRESENT; + + static { + boolean kotlinMetadataJvmPresent; + try { + Class.forName( + "kotlin.metadata.jvm.KotlinClassMetadata", + false, + AccessorNamingStrategy.class.getClassLoader() + ); + kotlinMetadataJvmPresent = true; + } + catch ( ClassNotFoundException e ) { + kotlinMetadataJvmPresent = false; + } + KOTLIN_METADATA_JVM_PRESENT = kotlinMetadataJvmPresent; + } + protected Elements elementUtils; protected Types typeUtils; @@ -102,10 +124,48 @@ public boolean isSetterMethod(ExecutableElement method) { } protected boolean isFluentSetter(ExecutableElement method) { - return method.getParameters().size() == 1 && - !JAVA_JAVAX_PACKAGE.matcher( method.getEnclosingElement().asType().toString() ).matches() && - !isAdderWithUpperCase4thCharacter( method ) && - typeUtils.isAssignable( method.getReturnType(), method.getEnclosingElement().asType() ); + if ( method.getParameters().size() != 1 ) { + return false; + } + Element methodOwnerElement = method.getEnclosingElement(); + if ( !canMethodOwnerBeUsedInFluentSetter( methodOwnerElement ) ) { + return false; + } + return !isAdderWithUpperCase4thCharacter( method ) && + typeUtils.isAssignable( method.getReturnType(), methodOwnerElement.asType() ); + } + + private boolean canMethodOwnerBeUsedInFluentSetter(Element methodOwnerElement) { + if ( !( methodOwnerElement instanceof TypeElement ) ) { + return false; + } + + TypeElement typeElement = (TypeElement) methodOwnerElement; + if ( JAVA_JAVAX_PACKAGE.matcher( typeElement.getQualifiedName().toString() ).matches() ) { + return false; + } + if ( isKotlinDataClass( typeElement ) ) { + return false; + } + + return true; + } + + private boolean isKotlinDataClass(TypeElement typeElement) { + if ( !KOTLIN_METADATA_JVM_PRESENT ) { + return false; + } + + Metadata kotlinMetadata = typeElement.getAnnotation( Metadata.class ); + if ( kotlinMetadata == null ) { + return false; + } + KotlinClassMetadata classMetadata = KotlinClassMetadata.readLenient( kotlinMetadata ); + if ( classMetadata instanceof KotlinClassMetadata.Class ) { + return Attributes.isData( ( (KotlinClassMetadata.Class) classMetadata ).getKmClass() ); + } + + return false; } /** diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsProperty.kt new file mode 100644 index 0000000000..e452102f6e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsProperty.kt @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class AllDefaultsProperty(val firstName: String? = null, val lastName: String? = null) diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsPropertyMapper.java new file mode 100644 index 0000000000..1f8aab4624 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/AllDefaultsPropertyMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface AllDefaultsPropertyMapper { + + AllDefaultsPropertyMapper INSTANCE = Mappers.getMapper( AllDefaultsPropertyMapper.class ); + + AllDefaultsProperty map(Source source); + + class Source { + + private final String firstName; + private final String lastName; + + public Source(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java index 310039363d..1daa19c231 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java @@ -8,7 +8,11 @@ import org.junit.jupiter.api.Nested; import org.mapstruct.ap.testutil.ProcessorTest; import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithKotlin; import org.mapstruct.ap.testutil.WithKotlinSources; +import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; +import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; +import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import static org.assertj.core.api.Assertions.assertThat; @@ -51,4 +55,370 @@ void shouldMapIntoData() { } } + + @Nested + @WithClasses({ + SinglePropertyMapper.class, + }) + @WithKotlinSources("SingleProperty.kt") + class SingleData { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + SingleProperty property = SinglePropertyMapper.INSTANCE.map( new SinglePropertyMapper.Source( "test" ) ); + assertThat( property ).isNotNull(); + assertThat( property.getValue() ).isEqualTo( "test" ); + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = SinglePropertyMapper.class, + line = 19, + message = "Unmapped target property: \"copy\"." + ) + } + ) + void shouldCompileWithWarnings() { + + SingleProperty property = SinglePropertyMapper.INSTANCE.map( new SinglePropertyMapper.Source( "test" ) ); + assertThat( property ).isNotNull(); + assertThat( property.getValue() ).isEqualTo( "test" ); + } + } + + @Nested + @WithClasses({ + AllDefaultsPropertyMapper.class, + }) + @WithKotlinSources("AllDefaultsProperty.kt") + class AllDefaults { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + AllDefaultsProperty property = AllDefaultsPropertyMapper.INSTANCE.map( new AllDefaultsPropertyMapper.Source( + "Kermit", + "the Frog" + ) ); + assertThat( property ).isNotNull(); + assertThat( property.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( property.getLastName() ).isEqualTo( "the Frog" ); + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = AllDefaultsPropertyMapper.class, + line = 19, + message = "No target property found for target \"AllDefaultsProperty\"." + ) + } + ) + void shouldCompileWithWarnings() { + + AllDefaultsProperty property = AllDefaultsPropertyMapper.INSTANCE.map( new AllDefaultsPropertyMapper.Source( + "Kermit", + "the Frog" + ) ); + assertThat( property ).isNotNull(); + assertThat( property.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( property.getLastName() ).isEqualTo( "the Frog" ); + } + } + + @Nested + @WithClasses({ + MultiConstructorPropertyMapper.class, + }) + @WithKotlinSources("MultiConstructorProperty.kt") + class MultiConstructor { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + MultiConstructorProperty property = MultiConstructorPropertyMapper.INSTANCE + .map( new MultiConstructorPropertyMapper.Source( + "Kermit", + "the Frog", + "Kermit the Frog" + ) ); + assertThat( property ).isNotNull(); + assertThat( property.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( property.getLastName() ).isEqualTo( "the Frog" ); + assertThat( property.getDisplayName() ).isEqualTo( "Kermit the Frog" ); + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiConstructorPropertyMapper.class, + line = 19, + messageRegExp = "Ambiguous constructors found for creating .*MultiConstructorProperty: " + + "MultiConstructorProperty\\(java.lang.String, java.lang.String.*\\), " + + "MultiConstructorProperty\\(java.lang.String, java.lang.String.*\\)\\. " + + "Either declare parameterless constructor or annotate the default constructor with an " + + "annotation named @Default\\." + ) + } + ) + void shouldFailToCompile() { + + } + } + + @Nested + @WithClasses({ + MultiSimilarConstructorPropertyMapper.class, + }) + @WithKotlinSources("MultiSimilarConstructorProperty.kt") + class MultiSimilarConstructor { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + PrimaryString primaryString = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + "Kermit the Frog" + ); + assertThat( primaryString ).isNotNull(); + assertThat( primaryString.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryString.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryString.getDisplayName() ).isEqualTo( "Kermit the Frog" ); + + PrimaryInt primaryInt = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + 42 + ); + assertThat( primaryInt ).isNotNull(); + assertThat( primaryInt.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryInt.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryInt.getAge() ).isEqualTo( 42 ); + + PrimaryLong primaryLong = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + 42L + ); + assertThat( primaryLong ).isNotNull(); + assertThat( primaryLong.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryLong.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryLong.getAge() ).isEqualTo( 42 ); + + PrimaryBoolean primaryBoolean = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + true + ); + assertThat( primaryBoolean ).isNotNull(); + assertThat( primaryBoolean.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryBoolean.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryBoolean.getActive() ).isTrue(); + + PrimaryByte primaryByte = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + (byte) 4 + ); + assertThat( primaryByte ).isNotNull(); + assertThat( primaryByte.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryByte.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryByte.getB() ).isEqualTo( (byte) 4 ); + + PrimaryShort primaryShort = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + (short) 4 + ); + assertThat( primaryShort ).isNotNull(); + assertThat( primaryShort.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryShort.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryShort.getAge() ).isEqualTo( (short) 4 ); + + PrimaryChar primaryChar = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + 't' + ); + assertThat( primaryChar ).isNotNull(); + assertThat( primaryChar.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryChar.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryChar.getC() ).isEqualTo( 't' ); + + PrimaryFloat primaryFloat = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + 42.2f + ); + assertThat( primaryFloat ).isNotNull(); + assertThat( primaryFloat.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryFloat.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryFloat.getPrice() ).isEqualTo( 42.2f ); + + PrimaryDouble primaryDouble = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + 42.2 + ); + assertThat( primaryDouble ).isNotNull(); + assertThat( primaryDouble.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryDouble.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryDouble.getPrice() ).isEqualTo( 42.2d ); + + PrimaryArray primaryArray = MultiSimilarConstructorPropertyMapper.INSTANCE.map( + new MultiSimilarConstructorPropertyMapper.Source( + "Kermit", + "the Frog" + ), + new String[] { "Kermit", "the Frog" } + ); + assertThat( primaryArray ).isNotNull(); + assertThat( primaryArray.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( primaryArray.getLastName() ).isEqualTo( "the Frog" ); + assertThat( primaryArray.getElements() ).containsExactly( "Kermit", "the Frog" ); + } + + @ProcessorTest + @ExpectedCompilationOutcome( + value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 19, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryString" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 21, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryInt" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 23, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryLong" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 25, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryBoolean" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 27, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryByte" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 29, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryShort" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 31, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryChar" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 33, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryFloat" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 35, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryDouble" + ), + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.ERROR, + type = MultiSimilarConstructorPropertyMapper.class, + line = 37, + messageRegExp = "Ambiguous constructors found for creating .*PrimaryArray" + ) + + + } + ) + void shouldFailToCompile() { + + } + } + + @Nested + @WithClasses({ + MultiDefaultConstructorPropertyMapper.class, + }) + @WithKotlinSources("MultiDefaultConstructorProperty.kt") + class MultiDefaultConstructor { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + MultiDefaultConstructorProperty property = MultiDefaultConstructorPropertyMapper.INSTANCE + .map( new MultiDefaultConstructorPropertyMapper.Source( + "Kermit", + "the Frog", + "Kermit the Frog" + ) ); + assertThat( property ).isNotNull(); + assertThat( property.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( property.getLastName() ).isEqualTo( "the Frog" ); + assertThat( property.getDisplayName() ).isNull(); + } + + @ProcessorTest + void shouldCompileWithoutKotlin() { + MultiDefaultConstructorProperty property = MultiDefaultConstructorPropertyMapper.INSTANCE + .map( new MultiDefaultConstructorPropertyMapper.Source( + "Kermit", + "the Frog", + "Kermit the Frog" + ) ); + assertThat( property ).isNotNull(); + assertThat( property.getFirstName() ).isEqualTo( "Kermit" ); + assertThat( property.getLastName() ).isEqualTo( "the Frog" ); + assertThat( property.getDisplayName() ).isNull(); + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorProperty.kt new file mode 100644 index 0000000000..46cb8034e9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorProperty.kt @@ -0,0 +1,13 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class MultiConstructorProperty(var firstName: String?, var lastName: String?, var displayName: String?) { + constructor(firstName: String?, lastName: String?) : this(firstName, lastName, null) +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorPropertyMapper.java new file mode 100644 index 0000000000..3186226a57 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiConstructorPropertyMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MultiConstructorPropertyMapper { + + MultiConstructorPropertyMapper INSTANCE = Mappers.getMapper( MultiConstructorPropertyMapper.class ); + + MultiConstructorProperty map(Source source); + + class Source { + + private final String firstName; + private final String lastName; + private final String displayName; + + public Source(String firstName, String lastName, String displayName) { + this.firstName = firstName; + this.lastName = lastName; + this.displayName = displayName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getDisplayName() { + return displayName; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt new file mode 100644 index 0000000000..712cf1151b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class MultiDefaultConstructorProperty(val firstName: String?, val lastName: String?, val displayName: String?) { + @Default + constructor(firstName: String?, lastName: String?) : this(firstName, lastName, null) +} + +@Target(AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.BINARY) +annotation class Default diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorPropertyMapper.java new file mode 100644 index 0000000000..da04c01fb8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorPropertyMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MultiDefaultConstructorPropertyMapper { + + MultiDefaultConstructorPropertyMapper INSTANCE = Mappers.getMapper( MultiDefaultConstructorPropertyMapper.class ); + + MultiDefaultConstructorProperty map(Source source); + + class Source { + + private final String firstName; + private final String lastName; + private final String displayName; + + public Source(String firstName, String lastName, String displayName) { + this.firstName = firstName; + this.lastName = lastName; + this.displayName = displayName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public String getDisplayName() { + return displayName; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorProperty.kt new file mode 100644 index 0000000000..e122169075 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorProperty.kt @@ -0,0 +1,50 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class PrimaryString(var firstName: String?, var lastName: String?, var displayName: String?) { + constructor(firstName: String?, lastName: String?, age: Int) : this(firstName, lastName, null as String?) +} + +data class PrimaryInt(var firstName: String?, var lastName: String?, var age: Int) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, -1) +} + +data class PrimaryLong(var firstName: String?, var lastName: String?, var age: Long) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, -1) +} + +data class PrimaryBoolean(var firstName: String?, var lastName: String?, var active: Boolean) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, false) +} + +data class PrimaryByte(var firstName: String?, var lastName: String?, var b: Byte) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, 0) +} + +data class PrimaryShort(var firstName: String?, var lastName: String?, var age: Short) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, 0) +} + +data class PrimaryChar(var firstName: String?, var lastName: String?, var c: Char) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, 'a') +} + +data class PrimaryFloat(var firstName: String?, var lastName: String?, var price: Float) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, 0.0f) +} + +data class PrimaryDouble(var firstName: String?, var lastName: String?, var price: Double) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, 0.0) +} + +@Suppress("ArrayInDataClass") +data class PrimaryArray(var firstName: String?, var lastName: String?, var elements: Array) { + constructor(firstName: String?, lastName: String?, displayName: String?) : this(firstName, lastName, emptyArray()) +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorPropertyMapper.java new file mode 100644 index 0000000000..86021cd6d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiSimilarConstructorPropertyMapper.java @@ -0,0 +1,57 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface MultiSimilarConstructorPropertyMapper { + + MultiSimilarConstructorPropertyMapper INSTANCE = Mappers.getMapper( MultiSimilarConstructorPropertyMapper.class ); + + PrimaryString map(Source source, String displayName); + + PrimaryInt map(Source source, int age); + + PrimaryLong map(Source source, long age); + + PrimaryBoolean map(Source source, boolean active); + + PrimaryByte map(Source source, byte b); + + PrimaryShort map(Source source, short age); + + PrimaryChar map(Source source, char c); + + PrimaryFloat map(Source source, float price); + + PrimaryDouble map(Source source, double price); + + PrimaryArray map(Source source, String[] elements); + + class Source { + + private final String firstName; + private final String lastName; + + public Source(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SingleProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SingleProperty.kt new file mode 100644 index 0000000000..1bb63c410d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SingleProperty.kt @@ -0,0 +1,11 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class SingleProperty(val value: String?) diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SinglePropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SinglePropertyMapper.java new file mode 100644 index 0000000000..d3d70f261c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/SinglePropertyMapper.java @@ -0,0 +1,32 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SinglePropertyMapper { + + SinglePropertyMapper INSTANCE = Mappers.getMapper( SinglePropertyMapper.class ); + + SingleProperty map(Source source); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlin.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlin.java new file mode 100644 index 0000000000..f4bd2c5970 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithKotlin.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Meta annotation that adds the needed Spring Dependencies + * + * @author Filip Hrisafov + */ +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@WithProcessorDependency({ + "kotlin-stdlib", + "kotlin-metadata-jvm", +}) +@WithTestDependency("kotlin-stdlib") +public @interface WithKotlin { + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependencies.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependencies.java new file mode 100644 index 0000000000..cccb30b6b4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependencies.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @author Filip Hrisafov + * @see WithProcessorDependency + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +public @interface WithProcessorDependencies { + + WithProcessorDependency[] value(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependency.java b/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependency.java new file mode 100644 index 0000000000..8dbf8c8acd --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/testutil/WithProcessorDependency.java @@ -0,0 +1,28 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.testutil; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies the group id of the additional dependencies that should be added to the processor path + * + * @author Filip Hrisafov + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +@Repeatable(WithProcessorDependencies.class) +public @interface WithProcessorDependency { + /** + * @return The group ids of the additional dependencies for the processor path + */ + String[] value(); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java index 8622fbe92c..c9718c6c21 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilationRequest.java @@ -19,16 +19,19 @@ public class CompilationRequest { private final Map, Class> services; private final List processorOptions; private final Collection testDependencies; + private final Collection processorDependencies; private final Collection kotlinSources; CompilationRequest(Compiler compiler, Set> sourceClasses, Map, Class> services, List processorOptions, Collection testDependencies, + Collection processorDependencies, Collection kotlinSources) { this.compiler = compiler; this.sourceClasses = sourceClasses; this.services = services; this.processorOptions = processorOptions; this.testDependencies = testDependencies; + this.processorDependencies = processorDependencies; this.kotlinSources = kotlinSources; } @@ -61,6 +64,7 @@ public boolean equals(Object obj) { && processorOptions.equals( other.processorOptions ) && services.equals( other.services ) && testDependencies.equals( other.testDependencies ) + && processorDependencies.equals( other.processorDependencies ) && sourceClasses.equals( other.sourceClasses ) && kotlinSources.equals( other.kotlinSources ); } @@ -81,6 +85,10 @@ public Collection getTestDependencies() { return testDependencies; } + public Collection getProcessorDependencies() { + return processorDependencies; + } + public Collection getKotlinSources() { return kotlinSources; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index 7ff78753a6..d8ed3b953d 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -40,6 +40,7 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithKotlinSources; +import org.mapstruct.ap.testutil.WithProcessorDependency; import org.mapstruct.ap.testutil.WithServiceImplementation; import org.mapstruct.ap.testutil.WithTestDependency; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; @@ -152,6 +153,15 @@ protected static List filterBootClassPath(Collection whitelist) return classpath; } + protected static Collection getProcessorClasspathDependencies(CompilationRequest request, + String additionalCompilerClasspath) { + List processClassPaths = filterBootClassPath( request.getProcessorDependencies() ); + if ( additionalCompilerClasspath != null ) { + processClassPaths.add( additionalCompilerClasspath ); + } + return processClassPaths; + } + private static boolean isWhitelisted(String path, Collection whitelist) { return whitelist.stream().anyMatch( path::contains ); } @@ -392,6 +402,17 @@ private Collection getAdditionalTestDependencies(Method testMethod, Clas return testDependencies; } + private Collection getAdditionalProcessorDependencies(Method testMethod, Class testClass) { + Collection processorDependencies = new HashSet<>(); + findRepeatableAnnotations( testMethod, WithProcessorDependency.class ) + .forEach( annotation -> Collections.addAll( processorDependencies, annotation.value() ) ); + + findRepeatableAnnotations( testClass, WithProcessorDependency.class ) + .forEach( annotation -> Collections.addAll( processorDependencies, annotation.value() ) ); + + return processorDependencies; + } + private void addServices(Map, Class> services, List withImplementations) { for ( WithServiceImplementation withImplementation : withImplementations ) { addService( services, withImplementation ); @@ -486,6 +507,7 @@ private CompilationOutcomeDescriptor compile(ExtensionContext context) { getServices( testMethod, testClass ), getProcessorOptions( testMethod, testClass ), getAdditionalTestDependencies( testMethod, testClass ), + getAdditionalProcessorDependencies( testMethod, testClass ), getKotlinSources( context ) ); diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java index 4755df0bd1..6b13036be3 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/EclipseCompilingExtension.java @@ -47,8 +47,12 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe String sourceOutputDir, String classOutputDir, String additionalCompilerClasspath) { + Collection processorClassPaths = getProcessorClasspathDependencies( + compilationRequest, + additionalCompilerClasspath + ); ClassLoader compilerClassloader; - if ( additionalCompilerClasspath == null ) { + if ( processorClassPaths.isEmpty() ) { compilerClassloader = DEFAULT_ECLIPSE_COMPILER_CLASSLOADER; } else { @@ -59,7 +63,7 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe compilerClassloader = loader.withPaths( ECLIPSE_COMPILER_CLASSPATH ) .withPaths( PROCESSOR_CLASSPATH ) .withOriginOf( ClassLoaderExecutor.class ) - .withPath( additionalCompilerClasspath ) + .withPaths( processorClassPaths ) .withOriginsOf( compilationRequest.getServices().values() ); } @@ -77,16 +81,19 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe private static List getTestCompilationClasspath(CompilationRequest request, String classOutputDir) { Collection testDependencies = request.getTestDependencies(); - if ( testDependencies.isEmpty() && request.getKotlinSources().isEmpty() ) { + Collection processorDependencies = request.getProcessorDependencies(); + Collection kotlinSources = request.getKotlinSources(); + if ( testDependencies.isEmpty() && processorDependencies.isEmpty() && kotlinSources.isEmpty() ) { return TEST_COMPILATION_CLASSPATH; } List testCompilationPaths = new ArrayList<>( - TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() + 1 ); + TEST_COMPILATION_CLASSPATH.size() + testDependencies.size() + processorDependencies.size() + 1 ); testCompilationPaths.addAll( TEST_COMPILATION_CLASSPATH ); testCompilationPaths.addAll( filterBootClassPath( testDependencies ) ); - if ( !request.getKotlinSources().isEmpty() ) { + testCompilationPaths.addAll( filterBootClassPath( processorDependencies ) ); + if ( !kotlinSources.isEmpty() ) { testCompilationPaths.add( classOutputDir ); } return testCompilationPaths; @@ -96,6 +103,7 @@ private static FilteringParentClassLoader newFilteringClassLoaderForEclipse() { return new FilteringParentClassLoader( // reload eclipse compiler classes "org.eclipse.", + "kotlin.", // reload mapstruct processor classes "org.mapstruct.ap.internal.", "org.mapstruct.ap.spi.", diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index b6d8afd3bf..115618382c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -39,7 +39,7 @@ class JdkCompilingExtension extends CompilingExtension { private static final List COMPILER_CLASSPATH_FILES = asFiles( TEST_COMPILATION_CLASSPATH ); private static final ClassLoader DEFAULT_PROCESSOR_CLASSLOADER = - new ModifiableURLClassLoader( new FilteringParentClassLoader( "org.mapstruct." ) ) + new ModifiableURLClassLoader( newFilteringClassLoaderForJdk() ) .withPaths( PROCESSOR_CLASSPATH ); JdkCompilingExtension() { @@ -70,15 +70,21 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe throw new RuntimeException( e ); } + Collection processorClassPaths = getProcessorClasspathDependencies( + compilationRequest, + additionalCompilerClasspath + ); ClassLoader processorClassloader; - if ( additionalCompilerClasspath == null ) { + if ( processorClassPaths.isEmpty() ) { processorClassloader = DEFAULT_PROCESSOR_CLASSLOADER; } else { processorClassloader = new ModifiableURLClassLoader( - new FilteringParentClassLoader( "org.mapstruct." ) ) + newFilteringClassLoaderForJdk() + .hidingClasses( compilationRequest.getServices().values() ) + ) .withPaths( PROCESSOR_CLASSPATH ) - .withPath( additionalCompilerClasspath ) + .withPaths( processorClassPaths ) .withOriginsOf( compilationRequest.getServices().values() ); } @@ -104,19 +110,21 @@ protected CompilationOutcomeDescriptor compileWithSpecificCompiler(CompilationRe private static List getCompilerClasspathFiles(CompilationRequest request, String classOutputDir) { Collection testDependencies = request.getTestDependencies(); - if ( testDependencies.isEmpty() && request.getKotlinSources().isEmpty() ) { + Collection processorDependencies = request.getProcessorDependencies(); + Collection kotlinSources = request.getKotlinSources(); + if ( testDependencies.isEmpty() && processorDependencies.isEmpty() && kotlinSources.isEmpty() ) { return COMPILER_CLASSPATH_FILES; } List compilerClasspathFiles = new ArrayList<>( - COMPILER_CLASSPATH_FILES.size() + testDependencies.size() + 1 ); + COMPILER_CLASSPATH_FILES.size() + testDependencies.size() + processorDependencies.size() + 1 ); compilerClasspathFiles.addAll( COMPILER_CLASSPATH_FILES ); for ( String testDependencyPath : filterBootClassPath( testDependencies ) ) { compilerClasspathFiles.add( new File( testDependencyPath ) ); } - if ( !request.getKotlinSources().isEmpty() ) { + if ( !kotlinSources.isEmpty() ) { compilerClasspathFiles.add( new File( classOutputDir ) ); } @@ -161,4 +169,13 @@ protected List filterExpectedDiagnostics(List Date: Thu, 29 Jan 2026 15:38:08 +0100 Subject: [PATCH 0922/1006] Add test case with Kotlin unsigned type (#3979) --- .../ap/internal/model/BeanMappingMethod.java | 5 +- .../mapstruct/ap/test/kotlin/data/Default.kt | 10 ++++ .../ap/test/kotlin/data/KotlinDataTest.java | 50 ++++++++++++++++++- .../data/MultiDefaultConstructorProperty.kt | 3 -- .../ap/test/kotlin/data/UnsignedProperty.kt | 17 +++++++ .../kotlin/data/UnsignedPropertyMapper.java | 35 +++++++++++++ .../testutil/runner/CompilingExtension.java | 11 ++-- 7 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/Default.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedPropertyMapper.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 619272a175..086773dbe9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -910,8 +910,11 @@ private ConstructorAccessor getConstructorAccessor(Type type) { List constructors = ElementFilter.constructorsIn( type.getTypeElement() .getEnclosedElements() ); - for ( ExecutableElement constructor : constructors ) { + Iterator constructorIterator = constructors.iterator(); + while ( constructorIterator.hasNext() ) { + ExecutableElement constructor = constructorIterator.next(); if ( constructor.getModifiers().contains( Modifier.PRIVATE ) ) { + constructorIterator.remove(); continue; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/Default.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/Default.kt new file mode 100644 index 0000000000..58ebbd128d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/Default.kt @@ -0,0 +1,10 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +@Target(AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.BINARY) +annotation class Default diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java index 1daa19c231..f55cb42535 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java @@ -10,6 +10,7 @@ import org.mapstruct.ap.testutil.WithClasses; import org.mapstruct.ap.testutil.WithKotlin; import org.mapstruct.ap.testutil.WithKotlinSources; +import org.mapstruct.ap.testutil.WithTestDependency; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; @@ -388,7 +389,10 @@ void shouldFailToCompile() { @WithClasses({ MultiDefaultConstructorPropertyMapper.class, }) - @WithKotlinSources("MultiDefaultConstructorProperty.kt") + @WithKotlinSources({ + "MultiDefaultConstructorProperty.kt", + "Default.kt" + }) class MultiDefaultConstructor { @ProcessorTest @@ -421,4 +425,48 @@ void shouldCompileWithoutKotlin() { assertThat( property.getDisplayName() ).isNull(); } } + + @Nested + @WithClasses({ + UnsignedPropertyMapper.class, + }) + @WithKotlinSources("UnsignedProperty.kt") + class Unsigned { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + UnsignedProperty property = UnsignedPropertyMapper.INSTANCE.map( new UnsignedPropertyMapper.Source( 10 ) ); + assertThat( property ).isNotNull(); + assertThat( property.getAge() ).isEqualTo( 10 ); + + UnsignedPropertyMapper.Source source = UnsignedPropertyMapper.INSTANCE.map( new UnsignedProperty( 20 ) ); + assertThat( source ).isNotNull(); + assertThat( source.getAge() ).isEqualTo( 20 ); + } + + @ProcessorTest + @WithTestDependency( "kotlin-stdlib" ) + @ExpectedCompilationOutcome( + value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic( + kind = javax.tools.Diagnostic.Kind.WARNING, + type = UnsignedPropertyMapper.class, + line = 19, + messageRegExp = "Unmapped target property: \"copy-.*\"\\." + ) + } + ) + void shouldCompileWithoutKotlinJvmMetadata() { + UnsignedProperty property = UnsignedPropertyMapper.INSTANCE.map( new UnsignedPropertyMapper.Source( 10 ) ); + assertThat( property ).isNotNull(); + assertThat( property.getAge() ).isEqualTo( 10 ); + + UnsignedPropertyMapper.Source source = UnsignedPropertyMapper.INSTANCE.map( new UnsignedProperty( 20 ) ); + assertThat( source ).isNotNull(); + assertThat( source.getAge() ).isEqualTo( 20 ); + } + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt index 712cf1151b..9f9af16053 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/MultiDefaultConstructorProperty.kt @@ -13,6 +13,3 @@ data class MultiDefaultConstructorProperty(val firstName: String?, val lastName: constructor(firstName: String?, lastName: String?) : this(firstName, lastName, null) } -@Target(AnnotationTarget.CONSTRUCTOR) -@Retention(AnnotationRetention.BINARY) -annotation class Default diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedProperty.kt new file mode 100644 index 0000000000..c52426b3af --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedProperty.kt @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class UnsignedProperty(val age: UInt?) { + // Java-friendly secondary constructor + constructor(age: Int?) : this(age?.toUInt()) + + @JvmName("getAge") + fun getAgeAsLong(): Long? = age?.toLong() +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedPropertyMapper.java new file mode 100644 index 0000000000..4f055c7b41 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/UnsignedPropertyMapper.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface UnsignedPropertyMapper { + + UnsignedPropertyMapper INSTANCE = Mappers.getMapper( UnsignedPropertyMapper.class ); + + UnsignedProperty map(Source source); + + Source map(UnsignedProperty property); + + class Source { + + private final int age; + + public Source(int age) { + this.age = age; + } + + public int getAge() { + return age; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index d8ed3b953d..08056ca697 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -601,12 +601,11 @@ File.pathSeparator, filterBootClassPath( List.of( .getPackageName(); String sourcePrefix = SOURCE_DIR + File.separator + packageName.replace( ".", File.separator ) + File.separator; - k2JvmArguments.setFreeArgs( Arrays.asList( - compilationRequest.getKotlinSources() - .stream() - .map( kotlinSource -> sourcePrefix + kotlinSource ) - .collect( Collectors.joining( File.pathSeparator ) ) - ) ); + k2JvmArguments.setFreeArgs( compilationRequest.getKotlinSources() + .stream() + .map( kotlinSource -> sourcePrefix + kotlinSource ) + .collect( Collectors.toList() ) + ); k2JvmArguments.setVerbose( true ); k2JvmArguments.setSuppressWarnings( false ); k2JvmArguments.setDestination( classOutputDir ); From 3f20144b2f0529e048eee06cdcd93015686544c8 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 15:54:38 +0100 Subject: [PATCH 0923/1006] Add test case for Kotlin property named default (#3980) --- .../ap/test/kotlin/data/DefaultProperty.kt | 16 ++++++ .../kotlin/data/DefaultPropertyMapper.java | 22 +++++++++ .../ap/test/kotlin/data/KotlinDataTest.java | 49 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultProperty.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultPropertyMapper.java diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultProperty.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultProperty.kt new file mode 100644 index 0000000000..f5ff27d3d3 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultProperty.kt @@ -0,0 +1,16 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data + +/** + * @author Filip Hrisafov + */ +data class DefaultPropertySource(val default: Boolean, val identifier: String?) + +class DefaultPropertyTarget( + var default: Boolean, + var identifier: String? +) diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultPropertyMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultPropertyMapper.java new file mode 100644 index 0000000000..ce08e26e7e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/DefaultPropertyMapper.java @@ -0,0 +1,22 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.data; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface DefaultPropertyMapper { + + DefaultPropertyMapper INSTANCE = Mappers.getMapper( DefaultPropertyMapper.class ); + + DefaultPropertyTarget map(DefaultPropertySource source); + + DefaultPropertySource map(DefaultPropertyTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java index f55cb42535..94d0d90d75 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/data/KotlinDataTest.java @@ -469,4 +469,53 @@ void shouldCompileWithoutKotlinJvmMetadata() { assertThat( source.getAge() ).isEqualTo( 20 ); } } + + @Nested + @WithClasses({ + DefaultPropertyMapper.class, + }) + @WithKotlinSources("DefaultProperty.kt") + class Default { + + @ProcessorTest + @WithKotlin + void shouldCompileWithoutWarnings() { + + DefaultPropertyTarget target = DefaultPropertyMapper.INSTANCE.map( new DefaultPropertySource( + true, + "test" + ) ); + assertThat( target ).isNotNull(); + assertThat( target.getDefault() ).isTrue(); + assertThat( target.getIdentifier() ).isEqualTo( "test" ); + + DefaultPropertySource source = DefaultPropertyMapper.INSTANCE.map( new DefaultPropertyTarget( + false, + "private" + ) ); + assertThat( source ).isNotNull(); + assertThat( source.getDefault() ).isFalse(); + assertThat( source.getIdentifier() ).isEqualTo( "private" ); + + } + + @ProcessorTest + void shouldCompileWithoutKotlin() { + DefaultPropertyTarget target = DefaultPropertyMapper.INSTANCE.map( new DefaultPropertySource( + true, + "test" + ) ); + assertThat( target ).isNotNull(); + assertThat( target.getDefault() ).isTrue(); + assertThat( target.getIdentifier() ).isEqualTo( "test" ); + + DefaultPropertySource source = DefaultPropertyMapper.INSTANCE.map( new DefaultPropertyTarget( + false, + "private" + ) ); + assertThat( source ).isNotNull(); + assertThat( source.getDefault() ).isFalse(); + assertThat( source.getIdentifier() ).isEqualTo( "private" ); + } + } } From ec1e5f9317d399b3af420191bc5d6d025726073d Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 16:07:57 +0100 Subject: [PATCH 0924/1006] Add tests for sealed classes in processor module --- ...eatureCompilationExclusionCliEnhancer.java | 6 ++ .../subclassmapping/jdk17/sealed/Motor.java | 42 ++++++++++ .../jdk17/sealed/MotorDto.java | 42 ++++++++++ .../jdk17/sealed/SealedSubclassMapper.java | 31 +++++++ .../jdk17/sealed/SealedSubclassTest.java | 80 +++++++++++++++++++ .../subclassmapping/jdk17/sealed/Vehicle.java | 51 ++++++++++++ .../jdk17/sealed/VehicleCollection.java | 17 ++++ .../jdk17/sealed/VehicleCollectionDto.java | 17 ++++ .../jdk17/sealed/VehicleDto.java | 51 ++++++++++++ 9 files changed, 337 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Motor.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/MotorDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Vehicle.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollection.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollectionDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleDto.java diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java index 0cc1a87818..7d397c9499 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/FullFeatureCompilationExclusionCliEnhancer.java @@ -35,6 +35,8 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces additionalExcludes.add( "org/mapstruct/ap/test/injectionstrategy/jakarta_cdi/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/annotatewith/deprecated/jdk11/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/**/*.java" ); if ( processorType == ProcessorTest.ProcessorType.ECLIPSE_JDT ) { additionalExcludes.add( "org/mapstruct/ap/test/selection/methodgenerics/wildcards/LifecycleIntersectionMapper.java" ); @@ -43,10 +45,14 @@ public Collection getAdditionalCommandLineArguments(ProcessorTest.Proces case JAVA_9: // TODO find out why this fails: additionalExcludes.add( "org/mapstruct/ap/test/collection/wildcard/BeanMapper.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); break; case JAVA_11: additionalExcludes.add( "org/mapstruct/ap/test/**/spring/**/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/*.java" ); + additionalExcludes.add( "org/mapstruct/ap/test/**/jdk17/**/*.java" ); additionalExcludes.add( "org/mapstruct/ap/test/**/jdk21/*.java" ); break; case JAVA_17: diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Motor.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Motor.java new file mode 100644 index 0000000000..3498bb09e0 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Motor.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +public abstract sealed class Motor extends Vehicle { + private int cc; + + public int getCc() { + return cc; + } + + public void setCc(int cc) { + this.cc = cc; + } + + public static final class Davidson extends Motor { + private int numberOfExhausts; + + public int getNumberOfExhausts() { + return numberOfExhausts; + } + + public void setNumberOfExhausts(int numberOfExhausts) { + this.numberOfExhausts = numberOfExhausts; + } + } + + public static final class Harley extends Motor { + private int engineDb; + + public int getEngineDb() { + return engineDb; + } + + public void setEngineDb(int engineDb) { + this.engineDb = engineDb; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/MotorDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/MotorDto.java new file mode 100644 index 0000000000..a7ec0be4a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/MotorDto.java @@ -0,0 +1,42 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +public abstract sealed class MotorDto extends VehicleDto { + private int cc; + + public int getCc() { + return cc; + } + + public void setCc(int cc) { + this.cc = cc; + } + + public static final class DavidsonDto extends MotorDto { + private int numberOfExhausts; + + public int getNumberOfExhausts() { + return numberOfExhausts; + } + + public void setNumberOfExhausts(int numberOfExhausts) { + this.numberOfExhausts = numberOfExhausts; + } + } + + public static final class HarleyDto extends MotorDto { + private int engineDb; + + public int getEngineDb() { + return engineDb; + } + + public void setEngineDb(int engineDb) { + this.engineDb = engineDb; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassMapper.java new file mode 100644 index 0000000000..806eec78a4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SealedSubclassMapper { + SealedSubclassMapper INSTANCE = Mappers.getMapper( SealedSubclassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = Vehicle.Car.class, target = VehicleDto.CarDto.class ) + @SubclassMapping( source = Vehicle.Bike.class, target = VehicleDto.BikeDto.class ) + @SubclassMapping( source = Motor.Harley.class, target = MotorDto.HarleyDto.class ) + @SubclassMapping( source = Motor.Davidson.class, target = MotorDto.DavidsonDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassTest.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassTest.java new file mode 100644 index 0000000000..f9f59c45ec --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/SealedSubclassTest.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.Compiler; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Motor.class, + MotorDto.class, + SealedSubclassMapper.class, + Vehicle.class, + VehicleCollection.class, + VehicleCollectionDto.class, + VehicleDto.class +}) +public class SealedSubclassTest { + + @ProcessorTest(Compiler.JDK) + public void mappingIsDoneUsingSubclassMapping() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Vehicle.Car() ); + vehicles.getVehicles().add( new Vehicle.Bike() ); + vehicles.getVehicles().add( new Motor.Harley() ); + vehicles.getVehicles().add( new Motor.Davidson() ); + + VehicleCollectionDto result = SealedSubclassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( + VehicleDto.CarDto.class, + VehicleDto.BikeDto.class, + MotorDto.HarleyDto.class, + MotorDto.DavidsonDto.class + ); + } + + @ProcessorTest(Compiler.JDK) + public void inverseMappingIsDoneUsingSubclassMapping() { + VehicleCollectionDto vehicles = new VehicleCollectionDto(); + vehicles.getVehicles().add( new VehicleDto.CarDto() ); + vehicles.getVehicles().add( new VehicleDto.BikeDto() ); + vehicles.getVehicles().add( new MotorDto.HarleyDto() ); + vehicles.getVehicles().add( new MotorDto.DavidsonDto() ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( + Vehicle.Car.class, + Vehicle.Bike.class, + Motor.Harley.class, + Motor.Davidson.class + ); + } + + @ProcessorTest(Compiler.JDK) + public void subclassMappingInheritsInverseMapping() { + VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); + VehicleDto.CarDto carDto = new VehicleDto.CarDto(); + carDto.setMaker( "BenZ" ); + vehiclesDto.getVehicles().add( carDto ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehiclesDto ); + + assertThat( result.getVehicles() ) + .extracting( Vehicle::getVehicleManufacturingCompany ) + .containsExactly( "BenZ" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Vehicle.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Vehicle.java new file mode 100644 index 0000000000..c558ec877e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/Vehicle.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +public abstract sealed class Vehicle permits Motor, Vehicle.Bike, Vehicle.Car { + private String name; + private String vehicleManufacturingCompany; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVehicleManufacturingCompany() { + return vehicleManufacturingCompany; + } + + public void setVehicleManufacturingCompany(String vehicleManufacturingCompany) { + this.vehicleManufacturingCompany = vehicleManufacturingCompany; + } + + public static final class Bike extends Vehicle { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } + } + + public static final class Car extends Vehicle { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollection.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollection.java new file mode 100644 index 0000000000..2285789baa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollection.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollection { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollectionDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollectionDto.java new file mode 100644 index 0000000000..6c9dc7d382 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleCollectionDto.java @@ -0,0 +1,17 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +import java.util.ArrayList; +import java.util.Collection; + +public class VehicleCollectionDto { + private Collection vehicles = new ArrayList<>(); + + public Collection getVehicles() { + return vehicles; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleDto.java b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleDto.java new file mode 100644 index 0000000000..40cbb0df60 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/subclassmapping/jdk17/sealed/VehicleDto.java @@ -0,0 +1,51 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.subclassmapping.jdk17.sealed; + +public abstract sealed class VehicleDto permits VehicleDto.CarDto, VehicleDto.BikeDto, MotorDto { + private String name; + private String maker; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMaker() { + return maker; + } + + public void setMaker(String maker) { + this.maker = maker; + } + + public static final class BikeDto extends VehicleDto { + private int numberOfGears; + + public int getNumberOfGears() { + return numberOfGears; + } + + public void setNumberOfGears(int numberOfGears) { + this.numberOfGears = numberOfGears; + } + } + + public static final class CarDto extends VehicleDto { + private boolean manual; + + public boolean isManual() { + return manual; + } + + public void setManual(boolean manual) { + this.manual = manual; + } + } +} From 49963e34dec5cebc7a3dceda03a568d96939c2f1 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 17:42:00 +0100 Subject: [PATCH 0925/1006] Upgrade to Checkstyle 13.0.0 Fix errors which are now reported. Run only on Java 21 or later for integration tests module --- integrationtest/pom.xml | 36 ++++++++++++------- parent/pom.xml | 4 +-- .../ap/internal/model/common/Assignment.java | 1 - .../ap/internal/model/source/Method.java | 1 - .../processor/ModelElementProcessor.java | 2 +- .../bugs/_3485/ErroneousIssue3485Mapper.java | 1 + .../ap/test/bugs/_3485/Issue3485Test.java | 2 +- .../java8time/SourceTargetMapper.java | 1 + .../java/MultiLineExpressionMapper.java | 1 - .../expressions/java/SourceTargetMapper.java | 1 - .../compilation/annotation/ExpectedNote.java | 2 +- .../testutil/runner/CompilingExtension.java | 8 ++--- 12 files changed, 34 insertions(+), 26 deletions(-) diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 7c91837e79..71a61fc2fe 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -107,19 +107,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - - - check-style - verify - - checkstyle - - - - @@ -138,5 +125,28 @@ + + jdk-21-or-newer + + [21 + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + check-style + verify + + checkstyle + + + + + + + diff --git a/parent/pom.xml b/parent/pom.xml index 8c1266ed19..f7d26dfd22 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -36,7 +36,7 @@ 3.1.0 6.2.7 1.6.0 - 8.36.1 + 13.0.0 5.10.1 2.2.0 1.12.0 @@ -376,7 +376,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.1.1 + 3.6.0 build-config/checkstyle.xml true diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java index 293df9516b..7ed0140d81 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Assignment.java @@ -147,7 +147,6 @@ public boolean isConverted() { */ void setSourceLoopVarName(String sourceLoopVarName); - /** * Returns whether the type of assignment * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index bea4d56101..ba32b12b46 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -97,7 +97,6 @@ public interface Method { */ Parameter getTargetTypeParameter(); - /** * Returns the {@link Accessibility} of this method. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java index d43b52953d..4a30b776b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/ModelElementProcessor.java @@ -40,7 +40,7 @@ public interface ModelElementProcessor { * * @author Gunnar Morling */ - public interface ProcessorContext { + interface ProcessorContext { Filer getFiler(); diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java index 5714e04684..dc1558907c 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/ErroneousIssue3485Mapper.java @@ -17,6 +17,7 @@ public interface ErroneousIssue3485Mapper { ErroneousIssue3485Mapper INSTANCE = Mappers.getMapper( ErroneousIssue3485Mapper.class ); + class Target { private final String value; diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java index 7427b63a4e..964de36ec8 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3485/Issue3485Test.java @@ -24,7 +24,7 @@ public class Issue3485Test { diagnostics = { @Diagnostic(type = ErroneousIssue3485Mapper.class, kind = javax.tools.Diagnostic.Kind.ERROR, - line = 33, + line = 34, message = "Using @Mapping( target = \".\") requires a source property. Expression or " + "constant cannot be used as a source.") }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java index 37fc7d6cbe..f2351f4175 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/SourceTargetMapper.java @@ -26,6 +26,7 @@ public interface SourceTargetMapper { String LOCAL_TIME_FORMAT = "HH:mm"; SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + @Mappings( { @Mapping( target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT ), @Mapping( target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT ), @Mapping( target = "localDate", dateFormat = LOCAL_DATE_FORMAT ), diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java index 50d0b4b2cd..76286bfa3a 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/MultiLineExpressionMapper.java @@ -17,7 +17,6 @@ @Mapper(imports = TimeAndFormat.class) public interface MultiLineExpressionMapper { - MultiLineExpressionMapper INSTANCE = Mappers.getMapper( MultiLineExpressionMapper.class ); @Mappings({ diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java index 0e462ab3b3..56809494a3 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/expressions/java/SourceTargetMapper.java @@ -18,7 +18,6 @@ @Mapper( imports = TimeAndFormat.class ) public interface SourceTargetMapper { - SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); @Mappings( { diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java index 1cb95f52c2..2070c028c7 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/ExpectedNote.java @@ -29,7 +29,7 @@ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) - public @interface ExpectedNotes { + @interface ExpectedNotes { /** * Regexp for the note to match. diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index 08056ca697..bcfc707d68 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -25,11 +25,11 @@ import java.util.Set; import java.util.stream.Collectors; +import com.puppycrawl.tools.checkstyle.AbstractAutomaticBean; import com.puppycrawl.tools.checkstyle.Checker; import com.puppycrawl.tools.checkstyle.ConfigurationLoader; import com.puppycrawl.tools.checkstyle.DefaultLogger; import com.puppycrawl.tools.checkstyle.PropertiesExpander; -import com.puppycrawl.tools.checkstyle.api.AutomaticBean; import org.apache.commons.io.output.NullOutputStream; import org.jetbrains.kotlin.cli.common.ExitCode; import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments; @@ -225,10 +225,10 @@ private void assertCheckstyleRules() throws Exception { ByteArrayOutputStream errorStream = new ByteArrayOutputStream(); checker.addListener( new DefaultLogger( - NullOutputStream.NULL_OUTPUT_STREAM, - AutomaticBean.OutputStreamOptions.CLOSE, + NullOutputStream.INSTANCE, + AbstractAutomaticBean.OutputStreamOptions.CLOSE, errorStream, - AutomaticBean.OutputStreamOptions.CLOSE + AbstractAutomaticBean.OutputStreamOptions.CLOSE ) ); From 60151132145a606990224376d35be6eaff9e250f Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 29 Jan 2026 22:33:00 +0100 Subject: [PATCH 0926/1006] #3404 Add support for Kotlin Sealed classes --- NEXT_RELEASE_CHANGELOG.md | 1 + .../ap/internal/model/common/Type.java | 26 ++++++ .../internal/util/kotlin/KotlinMetadata.java | 5 ++ .../mapstruct/ap/test/kotlin/sealed/Dtos.kt | 36 +++++++++ .../ap/test/kotlin/sealed/Entities.kt | 36 +++++++++ .../kotlin/sealed/SealedSubclassMapper.java | 31 +++++++ .../kotlin/sealed/SealedSubclassTest.java | 80 +++++++++++++++++++ 7 files changed, 215 insertions(+) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Dtos.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Entities.kt create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassTest.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index f279193f6a..1f7026c127 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -7,6 +7,7 @@ - Proper primary constructor detection - Data classes with multiple constructors - Data classes with all default parameters + - Sealed Classes (#3404) - Subclass exhaustiveness is now checked for Kotlin sealed classes ### Enhancements diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 313ff38125..8fb10090c2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -47,6 +47,7 @@ import kotlin.metadata.Attributes; import kotlin.metadata.KmClass; import kotlin.metadata.KmConstructor; +import kotlin.metadata.Modality; import kotlin.metadata.jvm.JvmExtensionsKt; import kotlin.metadata.jvm.JvmMethodSignature; import kotlin.metadata.jvm.KotlinClassMetadata; @@ -1850,6 +1851,10 @@ public boolean isEnumSet() { * return true if this type is a java 17+ sealed class */ public boolean isSealed() { + KotlinMetadata kotlinMetadata = getKotlinMetadata(); + if ( kotlinMetadata != null ) { + return kotlinMetadata.isSealedClass(); + } return typeElement.getModifiers().stream().map( Modifier::name ).anyMatch( "SEALED"::equals ); } @@ -1858,6 +1863,10 @@ public boolean isSealed() { */ @SuppressWarnings( "unchecked" ) public List getPermittedSubclasses() { + KotlinMetadata kotlinMetadata = getKotlinMetadata(); + if ( kotlinMetadata != null ) { + return kotlinMetadata.getPermittedSubclasses(); + } if (SEALED_PERMITTED_SUBCLASSES_METHOD == null) { return emptyList(); } @@ -1882,6 +1891,11 @@ public boolean isDataClass() { return Attributes.isData( kotlinClassMetadata.getKmClass() ); } + @Override + public boolean isSealedClass() { + return Attributes.getModality( kotlinClassMetadata.getKmClass() ) == Modality.SEALED; + } + @Override public ExecutableElement determinePrimaryConstructor(List constructors) { if ( constructors.size() == 1 ) { @@ -1928,6 +1942,18 @@ public ExecutableElement determinePrimaryConstructor(List con return null; } + @Override + public List getPermittedSubclasses() { + List sealedSubclassNames = kotlinClassMetadata.getKmClass().getSealedSubclasses(); + List permittedSubclasses = new ArrayList<>( sealedSubclassNames.size() ); + for ( String sealedSubclassName : sealedSubclassNames ) { + Type subclassType = typeFactory.getType( sealedSubclassName.replace( '/', '.' ) ); + permittedSubclasses.add( subclassType.getTypeMirror() ); + } + + return permittedSubclasses; + } + private String buildJvmConstructorDescriptor(ExecutableElement constructor) { StringBuilder signature = new StringBuilder( "(" ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java b/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java index d58ab75c79..66a6fafc02 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/kotlin/KotlinMetadata.java @@ -7,6 +7,7 @@ import java.util.List; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.type.TypeMirror; /** * Information about a type in case it's a Kotlin type. @@ -17,5 +18,9 @@ public interface KotlinMetadata { boolean isDataClass(); + boolean isSealedClass(); + ExecutableElement determinePrimaryConstructor(List constructors); + + List getPermittedSubclasses(); } diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Dtos.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Dtos.kt new file mode 100644 index 0000000000..5a9084a685 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Dtos.kt @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.sealed + +sealed class VehicleDto { + var name: String? = null + var maker: String? = null + + class BikeDto : VehicleDto() { + var numberOfGears: Int = 0 + } + + class CarDto : VehicleDto() { + var manual: Boolean = false + } + +} + +sealed class MotorDto : VehicleDto() { + var cc: Int = 0 + + class DavidsonDto : MotorDto() { + var numberOfExhausts: Int = 0 + } + + class HarleyDto : MotorDto() { + var engineDb: Int = 0 + } +} + +class VehicleCollectionDto { + var vehicles: MutableList = mutableListOf() +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Entities.kt b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Entities.kt new file mode 100644 index 0000000000..b380bac231 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/Entities.kt @@ -0,0 +1,36 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.sealed + +sealed class Vehicle { + var name: String? = null + var vehicleManufacturingCompany: String? = null + + class Bike : Vehicle() { + var numberOfGears: Int = 0 + } + + class Car : Vehicle() { + var manual: Boolean = false + } + +} + +sealed class Motor : Vehicle() { + var cc: Int = 0 + + class Davidson : Motor() { + var numberOfExhausts: Int = 0 + } + + class Harley : Motor() { + var engineDb: Int = 0 + } +} + +class VehicleCollection { + var vehicles: MutableList = mutableListOf() +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassMapper.java new file mode 100644 index 0000000000..bde7dc24cf --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.sealed; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.SubclassMapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface SealedSubclassMapper { + SealedSubclassMapper INSTANCE = Mappers.getMapper( SealedSubclassMapper.class ); + + VehicleCollectionDto map(VehicleCollection vehicles); + + @SubclassMapping( source = Vehicle.Car.class, target = VehicleDto.CarDto.class ) + @SubclassMapping( source = Vehicle.Bike.class, target = VehicleDto.BikeDto.class ) + @SubclassMapping( source = Motor.Harley.class, target = MotorDto.HarleyDto.class ) + @SubclassMapping( source = Motor.Davidson.class, target = MotorDto.DavidsonDto.class ) + @Mapping( source = "vehicleManufacturingCompany", target = "maker") + VehicleDto map(Vehicle vehicle); + + VehicleCollection mapInverse(VehicleCollectionDto vehicles); + + @InheritInverseConfiguration + Vehicle mapInverse(VehicleDto dto); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassTest.java b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassTest.java new file mode 100644 index 0000000000..f7162ec3a2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/kotlin/sealed/SealedSubclassTest.java @@ -0,0 +1,80 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.kotlin.sealed; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.WithKotlin; +import org.mapstruct.ap.testutil.WithKotlinSources; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + SealedSubclassMapper.class, +}) +@WithKotlinSources({ + "Dtos.kt", + "Entities.kt" +}) +@WithKotlin +public class SealedSubclassTest { + + @ProcessorTest + public void mappingIsDoneUsingSubclassMapping() { + VehicleCollection vehicles = new VehicleCollection(); + vehicles.getVehicles().add( new Vehicle.Car() ); + vehicles.getVehicles().add( new Vehicle.Bike() ); + vehicles.getVehicles().add( new Motor.Harley() ); + vehicles.getVehicles().add( new Motor.Davidson() ); + + VehicleCollectionDto result = SealedSubclassMapper.INSTANCE.map( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( + VehicleDto.CarDto.class, + VehicleDto.BikeDto.class, + MotorDto.HarleyDto.class, + MotorDto.DavidsonDto.class + ); + } + + @ProcessorTest + public void inverseMappingIsDoneUsingSubclassMapping() { + VehicleCollectionDto vehicles = new VehicleCollectionDto(); + vehicles.getVehicles().add( new VehicleDto.CarDto() ); + vehicles.getVehicles().add( new VehicleDto.BikeDto() ); + vehicles.getVehicles().add( new MotorDto.HarleyDto() ); + vehicles.getVehicles().add( new MotorDto.DavidsonDto() ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehicles ); + + assertThat( result.getVehicles() ).doesNotContainNull(); + assertThat( result.getVehicles() ) // remove generic so that test works. + .extracting( vehicle -> (Class) vehicle.getClass() ) + .containsExactly( + Vehicle.Car.class, + Vehicle.Bike.class, + Motor.Harley.class, + Motor.Davidson.class + ); + } + + @ProcessorTest + public void subclassMappingInheritsInverseMapping() { + VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); + VehicleDto.CarDto carDto = new VehicleDto.CarDto(); + carDto.setMaker( "BenZ" ); + vehiclesDto.getVehicles().add( carDto ); + + VehicleCollection result = SealedSubclassMapper.INSTANCE.mapInverse( vehiclesDto ); + + assertThat( result.getVehicles() ) + .extracting( Vehicle::getVehicleManufacturingCompany ) + .containsExactly( "BenZ" ); + } +} From 9923f78d91a8dae76f210c5de2ac0013baa078b2 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Fri, 30 Jan 2026 12:25:56 +0100 Subject: [PATCH 0927/1006] #674 Add support for `Optional` (#3971) MapStruct now fully supports Optional as both source and target types: * `Optional` to `Optional` - Both source and target wrapped in `Optional` * `Optional` to Non-`Optional` - Unwrapping `Optional` values * Non-`Optional` to `Optional` - Wrapping values in `Optional` * Always assume that optionals are not `null`, i.e. we can always call `isPresent()` / `isEmpty()` on an `Optional` * Add support for conversions e.g. `Optional` -> `String`, `Optional` -> `String` etc. --------- Co-authored-by: Ken Wang --- NEXT_RELEASE_CHANGELOG.md | 5 + copyright.txt | 3 +- .../mapstruct/NullValueMappingStrategy.java | 6 +- .../NullValuePropertyMappingStrategy.java | 5 +- ...apter-10-advanced-mapping-options.asciidoc | 17 +- .../chapter-3-defining-a-mapper.asciidoc | 415 +++++++++++ .../chapter-5-data-type-conversions.asciidoc | 8 + .../ap/internal/conversion/Conversions.java | 35 + .../OptionalWrapperConversionProvider.java | 97 +++ .../conversion/TypeToOptionalConversion.java | 44 ++ .../ap/internal/model/BeanMappingMethod.java | 160 +++- .../model/FromOptionalTypeConversion.java | 113 +++ .../model/LifecycleMethodResolver.java | 33 +- .../internal/model/MappingBuilderContext.java | 11 + .../ap/internal/model/MappingMethod.java | 6 +- .../model/NestedPropertyMappingMethod.java | 63 +- .../model/PresenceCheckMethodResolver.java | 6 +- .../ap/internal/model/PropertyMapping.java | 16 +- .../model/ToOptionalTypeConversion.java | 119 +++ .../model/assignment/OptionalGetWrapper.java | 35 + .../model/beanmapping/SourceReference.java | 10 + .../model/common/ConversionContext.java | 7 + .../common/DefaultConversionContext.java | 5 + .../ap/internal/model/common/Parameter.java | 26 +- .../ap/internal/model/common/Type.java | 23 +- .../model/presence/OptionalPresenceCheck.java | 77 ++ .../ap/internal/model/source/Method.java | 9 - .../source/selector/SelectionContext.java | 21 +- .../processor/DefaultVersionInformation.java | 7 + .../processor/MapperCreationProcessor.java | 1 + .../creation/MappingResolverImpl.java | 13 +- .../internal/version/VersionInformation.java | 2 + .../ap/internal/model/BeanMappingMethod.ftl | 81 +- .../model/FromOptionalTypeConversion.ftl | 16 + .../model/ToOptionalTypeConversion.ftl | 21 + .../model/assignment/OptionalGetWrapper.ftl | 15 + .../model/assignment/UpdateWrapper.ftl | 4 +- .../ap/internal/model/macro/CommonMacros.ftl | 28 +- .../model/presence/OptionalPresenceCheck.ftl | 19 + .../OptionalEnumToIntegerConversionTest.java | 73 ++ .../_enum/OptionalEnumToIntegerMapper.java | 19 + .../_enum/OptionalEnumToIntegerSource.java | 31 + .../bignumbers/BigDecimalOptionalMapper.java | 19 + .../bignumbers/BigDecimalOptionalSource.java | 139 ++++ .../bignumbers/BigIntegerOptionalMapper.java | 19 + .../bignumbers/BigIntegerOptionalSource.java | 131 ++++ .../bignumbers/BigNumbersConversionTest.java | 150 ++++ .../Java8OptionalTimeConversionTest.java | 466 ++++++++++++ .../conversion/java8time/OptionalSource.java | 160 ++++ .../java8time/OptionalSourceTargetMapper.java | 70 ++ ...ErroneousKitchenDrawerOptionalMapper1.java | 23 + ...ErroneousKitchenDrawerOptionalMapper3.java | 23 + ...ErroneousKitchenDrawerOptionalMapper4.java | 23 + ...ErroneousKitchenDrawerOptionalMapper5.java | 23 + ...ErroneousKitchenDrawerOptionalMapper6.java | 20 + .../lossy/KitchenDrawerOptionalMapper2.java | 23 + .../lossy/KitchenDrawerOptionalMapper6.java | 23 + .../conversion/lossy/LossyConversionTest.java | 94 +++ .../OversizedKitchenDrawerOptionalDto.java | 84 +++ .../lossy/VerySpecialNumberMapper.java | 6 + .../ByteWrapperOptionalSource.java | 121 +++ .../nativetypes/DoubleOptionalSource.java | 121 +++ .../DoubleWrapperOptionalSource.java | 121 +++ .../FloatWrapperOptionalSource.java | 121 +++ .../nativetypes/IntOptionalSource.java | 121 +++ .../nativetypes/IntWrapperOptionalSource.java | 121 +++ .../nativetypes/LongOptionalSource.java | 121 +++ .../LongWrapperOptionalSource.java | 121 +++ .../NumberOptionalConversionTest.java | 357 +++++++++ .../OptionalNumberConversionMapper.java | 52 ++ .../ShortWrapperOptionalSource.java | 121 +++ .../OptionalBeforeAfterMapper.java | 76 ++ .../beforeafter/OptionalBeforeAfterTest.java | 25 + .../ap/test/optional/beforeafter/Source.java | 87 +++ .../ap/test/optional/beforeafter/Target.java | 86 +++ .../optional/builder/OptionalBuilderTest.java | 31 + .../builder/SimpleOptionalBuilderMapper.java | 67 ++ .../optional/custom/CustomOptionalMapper.java | 63 ++ .../optional/custom/CustomOptionalTest.java | 60 ++ .../OptionalDifferentTypesMapper.java | 18 + .../OptionalDifferentTypesTest.java | 204 +++++ .../test/optional/differenttypes/Source.java | 89 +++ .../test/optional/differenttypes/Target.java | 84 +++ .../optional/lifecycle/MappingContext.java | 108 +++ .../lifecycle/OptionalLifecycleTest.java | 165 +++++ .../lifecycle/OptionalToOptionalMapper.java | 27 + .../OptionalToOptionalWithBuilderMapper.java | 24 + .../lifecycle/OptionalToTypeMapper.java | 27 + .../OptionalToTypeMultiSourceMapper.java | 27 + .../ap/test/optional/lifecycle/Source.java | 21 + .../ap/test/optional/lifecycle/Target.java | 39 + .../ap/test/optional/nested/Artist.java | 81 ++ .../optional/nested/OptionalNestedMapper.java | 23 + ...ptionalNestedPresenceCheckFirstMapper.java | 52 ++ .../OptionalNestedPresenceCheckMapper.java | 44 ++ .../optional/nested/OptionalNestedTest.java | 148 ++++ .../ap/test/optional/nested/Source.java | 76 ++ .../ap/test/optional/nested/Target.java | 48 ++ .../test/optional/nested/TargetAggregate.java | 49 ++ .../OptionalNullCheckAlwaysMapper.java | 19 + .../OptionalNullCheckAlwaysTest.java | 84 +++ .../test/optional/nullcheckalways/Source.java | 40 + .../test/optional/nullcheckalways/Target.java | 40 + .../nullvalue/OptionalDefaultMapperTest.java | 2 - .../nullvalue/SimpleConstructorMapper.java | 29 - .../sametype/OptionalSameTypeMapper.java | 18 + .../sametype/OptionalSameTypeTest.java | 186 +++++ .../ap/test/optional/sametype/Source.java | 74 ++ .../ap/test/optional/sametype/Target.java | 70 ++ .../optional/simple/OptionalSimpleTest.java | 110 +++ .../simple/OptionalToOptionalMapper.java | 23 + ...ionalToOptionalNullValueDefaultMapper.java | 25 + .../optional/simple/OptionalToTypeMapper.java | 23 + .../OptionalToTypeNullValueDefaultMapper.java | 24 + .../OptionalToTypeWithMappingMapper.java | 67 ++ .../ap/test/optional/simple/Source.java | 21 + .../ap/test/optional/simple/Target.java | 22 + .../optional/simple/TypeToOptionalMapper.java | 23 + .../optional/update/OptionalUpdateMapper.java | 21 + ...alUpdateNullValuePropertyIgnoreMapper.java | 23 + ...pdateNullValuePropertyToDefaultMapper.java | 23 + .../optional/update/OptionalUpdateTest.java | 117 +++ .../ap/test/optional/update/Source.java | 37 + .../ap/test/optional/update/Target.java | 37 + .../testutil/assertions/JavaFileAssert.java | 2 +- .../OptionalSourceTargetMapperImpl.java | 701 ++++++++++++++++++ .../OptionalBeforeAfterMapperImpl.java | 113 +++ .../OptionalDifferentTypesMapperImpl.java | 89 +++ .../nested/OptionalNestedMapperImpl.java | 71 ++ ...nalNestedPresenceCheckFirstMapperImpl.java | 117 +++ ...OptionalNestedPresenceCheckMapperImpl.java | 100 +++ .../OptionalNullCheckAlwaysMapperImpl.java | 38 + .../sametype/OptionalSameTypeMapperImpl.java | 55 ++ 133 files changed, 8860 insertions(+), 132 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.java create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.ftl create mode 100644 processor/src/main/resources/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.ftl create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8OptionalTimeConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSourceTargetMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper1.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper3.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper4.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper5.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper6.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper2.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper6.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerOptionalDto.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberOptionalConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/OptionalNumberConversionMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperOptionalSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/builder/OptionalBuilderTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/builder/SimpleOptionalBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/MappingContext.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalLifecycleTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalWithBuilderMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMultiSourceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/Artist.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/OptionalNestedMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/OptionalNestedPresenceCheckFirstMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/OptionalNestedPresenceCheckMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/OptionalNestedTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nested/TargetAggregate.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullcheckalways/OptionalNullCheckAlwaysMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullcheckalways/OptionalNullCheckAlwaysTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullcheckalways/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullcheckalways/Target.java delete mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/nullvalue/SimpleConstructorMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/sametype/OptionalSameTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/sametype/OptionalSameTypeTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/sametype/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/sametype/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalSimpleTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalToOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalToOptionalNullValueDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalToTypeMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalToTypeNullValueDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/OptionalToTypeWithMappingMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/Target.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/simple/TypeToOptionalMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/OptionalUpdateMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/OptionalUpdateNullValuePropertyIgnoreMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/OptionalUpdateNullValuePropertyToDefaultMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/OptionalUpdateTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/Source.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/optional/update/Target.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/conversion/java8time/OptionalSourceTargetMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/nested/OptionalNestedMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/nested/OptionalNestedPresenceCheckFirstMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/nested/OptionalNestedPresenceCheckMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/nullcheckalways/OptionalNullCheckAlwaysMapperImpl.java create mode 100644 processor/src/test/resources/fixtures/org/mapstruct/ap/test/optional/sametype/OptionalSameTypeMapperImpl.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 1f7026c127..59fed4fed3 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,6 +1,11 @@ ### Features * Support for Java 21 Sequenced Collections (#3240) +* Native support for `java.util.Optional` mapping (#674) - MapStruct now fully supports Optional as both source and target types: + - `Optional` to `Optional` - Both source and target wrapped in `Optional` + - `Optional` to Non-`Optional` - Unwrapping `Optional` values + - Non-`Optional` to `Optional` - Wrapping values in `Optional` + - `Optional` properties in beans with automatic presence checks. Note, there is no null check done for `Optional` properties. * Improved support for Kotlin. Requires use of `org.jetbrains.kotlin:kotlin-metadata-jvm`. - Data Classes (#2281, #2577, #3031) - MapStruct now properly handles: - Single field data classes diff --git a/copyright.txt b/copyright.txt index 71d47a796a..bd0034b076 100644 --- a/copyright.txt +++ b/copyright.txt @@ -38,6 +38,7 @@ Joshua Spoerri - https://github.com/spoerri Jude Niroshan - https://github.com/JudeNiroshan Justyna Kubica-Ledzion - https://github.com/JKLedzion Kemal Özcan - https://github.com/yekeoe +Ken Wang - https://github.com/ro0sterjam Kevin Grüneberg - https://github.com/kevcodez Lukas Lazar - https://github.com/LukeLaz Nikolas Charalambidis - https://github.com/Nikolas-Charalambidis @@ -70,4 +71,4 @@ Tomek Gubala - https://github.com/vgtworld Valentin Kulesh - https://github.com/unshare Vincent Alexander Beelte - https://github.com/grandmasterpixel Winter Andreas - https://github.dev/wandi34 -Xiu Hong Kooi - https://github.com/kooixh +Xiu Hong Kooi - https://github.com/kooixh \ No newline at end of file diff --git a/core/src/main/java/org/mapstruct/NullValueMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValueMappingStrategy.java index 519a28bd81..4cece83031 100644 --- a/core/src/main/java/org/mapstruct/NullValueMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValueMappingStrategy.java @@ -13,8 +13,9 @@ public enum NullValueMappingStrategy { /** - * If {@code null} is passed to a mapping method, {@code null} will be returned. That's the default behavior if no - * alternative strategy is configured globally, for given mapper or method. + * If {@code null} is passed to a mapping method, {@code null} will be returned, unless the return type is + * {@link java.util.Optional Optional}, in which case an empty optional will be returned. + * That's the default behavior if no alternative strategy is configured globally, for given mapper or method. */ RETURN_NULL, @@ -28,6 +29,7 @@ public enum NullValueMappingStrategy { * case. *

    12. For iterable mapping methods an empty collection will be returned.
    13. *
    14. For map mapping methods an empty map will be returned.
    15. + *
    16. For optional mapping methods an empty optional will be returned.
    17. * */ RETURN_DEFAULT; diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index 556d4253b1..a58eed8a2a 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -27,7 +27,9 @@ public enum NullValuePropertyMappingStrategy { /** - * If a source bean property equals {@code null} the target bean property will be set explicitly to {@code null}. + * If a source bean property equals {@code null} the target bean property will be set explicitly to {@code null} + * or {@link java.util.Optional#empty() Optional.empty()} in case the target type is an + * {@link java.util.Optional Optional}. */ SET_TO_NULL, @@ -36,6 +38,7 @@ public enum NullValuePropertyMappingStrategy { *

      * This means: *

        + *
      1. For {@code Optional} MapStruct generates an {@code Optional.empty()}
      2. *
      3. For {@code List} MapStruct generates an {@code ArrayList}
      4. *
      5. For {@code Map} a {@code HashMap}
      6. *
      7. For arrays an empty array
      8. diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index b5c116ffd3..43f8fc38a0 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -204,7 +204,8 @@ The mechanism is also present on iterable mapping and map mapping. `@IterableMap [[mapping-result-for-null-arguments]] === Controlling mapping result for 'null' arguments -MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. By default `null` will be returned. +MapStruct offers control over the object to create when the source argument of the mapping method equals `null`. +By default `null` will be returned, or `Optional.empty()` if the return type is `Optional`. However, by specifying `nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT` on `@BeanMapping`, `@IterableMapping`, `@MapMapping`, or globally on `@Mapper` or `@MapperConfig`, the mapping result can be altered to return empty *default* values. This means for: @@ -243,7 +244,7 @@ How the value of the `NullValueMappingStrategy` is applied is the same as in <> for detailed examples and behavior with Optional types. +==== + [[checking-source-property-for-null-arguments]] === Controlling checking result for 'null' properties in bean mapping diff --git a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc index 81980a35ac..96c76fc20d 100644 --- a/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc +++ b/documentation/src/main/asciidoc/chapter-3-defining-a-mapper.asciidoc @@ -660,6 +660,421 @@ public class PersonMapperImpl implements PersonMapper { ---- ==== +[[mapping-with-optional]] +=== Using Optional + +MapStruct provides comprehensive support for Java's `Optional` type, allowing you to use `Optional` as both source and target types in your mappings. +MapStruct handles all common `Optional` mapping scenarios, including conversions, nested properties, update mappings, and integration with builders and constructors. + +[[optional-basic-behavior]] +==== Basic Optional Behavior + +When using `Optional` as a source type, MapStruct performs presence checks using `Optional.isEmpty()` / `!Optional.isPresent()` instead of `null` checks. +When using `Optional` as a target type, MapStruct returns `Optional.empty()` instead of `null` when the source is absent. + +[[optional-mapping-scenarios]] +==== Optional Mapping Scenarios + +MapStruct supports three primary mapping scenarios with `Optional`: + +1. `Optional` to `Optional` - Both source and target are wrapped in `Optional` +2. `Optional` to Non-`Optional` - Source is `Optional`, target is a regular type +3. Non-`Optional` to `Optional` - Source is a regular type, target is `Optional` + +.Example mapper showing all Optional scenarios +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface ProductMapper { + + Optional map(Optional product); + + ProductDto unwrap(Optional product); + + Optional wrap(Product product); +} +---- +==== + +.Generated code for `Optional` to `Optional` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public Optional map(Optional product) { + if ( product.isEmpty() ) { + return Optional.empty(); + } + + Product productValue = product.get(); + + ProductDto productDto = new ProductDto(); + + productDto.setName( productValue.getName() ); + productDto.setPrice( productValue.getPrice() ); + + return Optional.of( productDto ); +} +---- +==== + +.Generated code for `Optional` to Non-`Optional` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public ProductDto unwrap(Optional product) { + if ( product.isEmpty() ) { + return null; + } + + Product productValue = product.get(); + + ProductDto productDto = new ProductDto(); + + productDto.setName( productValue.getName() ); + productDto.setPrice( productValue.getPrice() ); + + return productDto; +} +---- +==== + +.Generated code for Non-`Optional` to `Optional` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public Optional wrap(Product product) { + if ( product == null ) { + return Optional.empty(); + } + + ProductDto productDto = new ProductDto(); + + productDto.setName( product.getName() ); + productDto.setPrice( product.getPrice() ); + + return Optional.of( productDto ); +} +---- +==== + +[[optional-properties]] +==== Mapping Optional Properties + +MapStruct handles `Optional` properties within your beans seamlessly. +When mapping `Optional` properties, MapStruct generates appropriate presence checks before accessing the values. + +.Example with `Optional` properties +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class Car { + private Optional make; + private Optional numberOfSeats; + private Person driver; + + // getters omitted for brevity +} + +public class CarDto { + private String manufacturer; + private int seatCount; + private PersonDto driver; + + // getters and setters omitted for brevity +} + +@Mapper +public interface CarMapper { + + @Mapping(target = "manufacturer", source = "make") + @Mapping(target = "seatCount", source = "numberOfSeats") + CarDto carToCarDto(Car car); +} +---- +==== + +.Code generated by MapStruct for `Optional` properties +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +public class CarMapperImpl implements CarMapper { + + @Override + public CarDto carToCarDto(Car car) { + if ( car == null ) { + return null; + } + + CarDto carDto = new CarDto(); + + if ( car.getMake().isPresent() ) { + carDto.setManufacturer( car.getMake().get() ); + } + if ( car.getNumberOfSeats().isPresent() ) { + carDto.setSeatCount( car.getNumberOfSeats().get() ); + } + carDto.setDriver( personToPersonDto( car.getDriver() ) ); + + return carDto; + } + + protected PersonDto personToPersonDto(Person person) { + //... + } +} +---- +==== + +[[optional-update-mappings]] +==== Update Mappings with Optional + +`Optional` works seamlessly with update mappings using `@MappingTarget`. +When the source `Optional` is present, the target object is updated with the unwrapped value. +When the source `Optional` is empty, the behavior depends on the null value property mapping strategy. + +.Update mapping with an `Optional` source +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface ProductUpdateMapper { + + void updateProduct(ProductUpdateDto dto, @MappingTarget Product product); +} + +public class ProductUpdateDto { + private Optional name; + private Optional price; + + // getters omitted +} + +public class Product { + private String name; + private BigDecimal price; + + // getters and setters omitted +} +---- +==== + +.Generated update method +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public void updateProduct(ProductUpdateDto dto, Product product) { + if ( dto == null ) { + return; + } + + if ( dto.getName().isPresent() ) { + product.setName( dto.getName().get() ); + } + if ( dto.getPrice().isPresent() ) { + product.setPrice( dto.getPrice().get() ); + } +} +---- +==== + +[[optional-null-value-strategies]] +==== Null Value Mapping Strategies + +When working with `Optional` types, MapStruct's null value mapping strategies behave as follows: + +* For `Optional` return types: `NullValueMappingStrategy.RETURN_DEFAULT` will return `Optional.empty()` instead of `null` +* For `Optional` properties: When a source property `Optional` is empty, `NullValuePropertyMappingStrategy` determines whether to skip the property, set it to null/empty, or use a default value +* `IGNORE` strategy: When a source `Optional` is empty, the target property is not updated +* `SET_TO_NULL` strategy: When a source `Optional` is empty, the target property is set to `null` (for non-`Optional` targets) or `Optional.empty()` (for `Optional` targets) +* `SET_TO_DEFAULT` strategy: When a source `Optional` is empty, the target property is set to its default value + +.Using null value strategies with `Optional` +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +public interface ProductMapper { + + void updateProduct(ProductUpdateDto dto, @MappingTarget Product product); +} +---- +==== + +With the `IGNORE` strategy, when Optional properties are empty, they won't overwrite existing target values. + +[[optional-builders-constructors]] +==== Optional with Builders and Constructors + +MapStruct's Optional support works seamlessly with both builder patterns and constructor-based mappings. + +.Optional with builders +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface PersonMapper { + Optional map(Optional person); +} + +public class PersonDto { + private final String name; + private final Integer age; + + private PersonDto(Builder builder) { + this.name = builder.name; + this.age = builder.age; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String name; + private Integer age; + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder age(Integer age) { + this.age = age; + return this; + } + + public PersonDto build() { + return new PersonDto(this); + } + } + + // getters omitted +} +---- +==== + +.Generated code using builder +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +// GENERATED CODE +@Override +public Optional map(Optional person) { + if ( person.isEmpty() ) { + return Optional.empty(); + } + + Person personValue = person.get(); + + PersonDto.Builder builder = PersonDto.builder(); + + builder.name( personValue.getName() ); + builder.age( personValue.getAge() ); + + return Optional.of( builder.build() ); +} +---- +==== + +.Optional with constructors +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +public class PersonDto { + private final String name; + private final Integer age; + + public PersonDto(String name, Integer age) { + this.name = name; + this.age = age; + } + + // getters omitted +} +---- +==== + +When the target type uses constructors and has `Optional` properties, MapStruct will properly handle the `Optional` parameters. + +[[optional-complex-mappings]] +==== Complex Optional Mappings + +MapStruct can handle complex scenarios where `Optional` is combined with nested object mappings, collections, and custom mapping methods. + +.Complex nested Optional mappings +==== +[source, java, linenums] +[subs="verbatim,attributes"] +---- +@Mapper +public interface OrderMapper { + + OrderDto map(Order order); + + // MapStruct will automatically use this for nested mappings + CustomerDto map(Customer customer); +} + +public class Order { + private Optional customer; + private Optional
        shippingAddress; + + // getters omitted +} + +public class OrderDto { + private Optional customer; + private AddressDto shippingAddress; + + // getters and setters omitted +} +---- +==== + +When mapping nested objects that are wrapped in Optional, MapStruct will: + +1. Check if the source `Optional` is present +2. Extract the value from the `Optional` +3. Map the extracted value to the target type +4. Wrap the result in an `Optional` if the target is also Optional + +[[optional-best-practices]] +==== Best Practices and Limitations + +[NOTE] +==== +While MapStruct fully supports `Optional` for target properties (public fields or setter parameters), the Java community generally recommends using `Optional` only for return types (source properties / getters). +Consider your team's coding standards when deciding whether to use `Optional` for target properties. +==== + +[WARNING] +==== +Avoid using `null` when returning `Optional` values to prevent `NullPointerException`. +MapStruct assumes that if you're using `Optional`, the `Optional` itself is not null. +==== + [[mapping-map-to-bean]] === Mapping Map to Bean diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index ad49fe2960..9da7ff75c1 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -133,6 +133,14 @@ public interface CarMapper { * Between `java.util.Locale` and `String`. ** When converting from a `Locale`, the resulting `String` will be a well-formed IETF BCP 47 language tag representing the locale. When converting from a `String`, the locale that best represents the language tag will be returned. See https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#forLanguageTag-java.lang.String-[Locale.forLanguageTag()] and https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#toLanguageTag--[Locale.toLanguageTag()] for more information. +[NOTE] +==== +All the above conversions also work when the source or target type is wrapped in `java.util.Optional`, `java.util.OptionalDouble`, `java.util.OptionalLong` or `java.util.OptionalInt`. +For example, `Optional` can be converted to `String`, `int` can be converted to `Optional`, +or `Optional` can be converted to `Integer`. +The same conversion rules apply, with MapStruct automatically handling the wrapping and unwrapping of `Optional` values. +==== + [[mapping-object-references]] === Mapping object references diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 5090c903f3..076cd2f42e 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -333,6 +333,41 @@ private void register(String sourceTypeName, Class targetClass, ConversionPro } public ConversionProvider getConversion(Type sourceType, Type targetType) { + if ( sourceType.isOptionalType() ) { + if ( targetType.isOptionalType() ) { + // We cannot convert optional to optional + return null; + } + Type sourceBaseType = sourceType.getOptionalBaseType(); + if ( sourceBaseType.equals( targetType ) ) { + // Optional -> Type + return TypeToOptionalConversion.OPTIONAL_TO_TYPE_CONVERSION; + } + + ConversionProvider conversionProvider = getInternalConversion( sourceBaseType, targetType ); + if ( conversionProvider != null ) { + return inverse( new OptionalWrapperConversionProvider( conversionProvider ) ); + } + + } + else if ( targetType.isOptionalType() ) { + // Type -> Optional + Type targetBaseType = targetType.getOptionalBaseType(); + if ( targetBaseType.equals( sourceType )) { + return TypeToOptionalConversion.TYPE_TO_OPTIONAL_CONVERSION; + } + ConversionProvider conversionProvider = getInternalConversion( sourceType, targetBaseType ); + if ( conversionProvider != null ) { + return new OptionalWrapperConversionProvider( conversionProvider ); + } + return null; + + } + + return getInternalConversion( sourceType, targetType ); + } + + private ConversionProvider getInternalConversion(Type sourceType, Type targetType) { if ( sourceType.isEnumType() && ( targetType.equals( stringType ) || targetType.getBoxedEquivalent().equals( integerType ) ) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java new file mode 100644 index 0000000000..2b3e1bd960 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java @@ -0,0 +1,97 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.util.List; + +import org.mapstruct.ap.internal.model.FromOptionalTypeConversion; +import org.mapstruct.ap.internal.model.HelperMethod; +import org.mapstruct.ap.internal.model.ToOptionalTypeConversion; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.FieldReference; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.model.common.TypeFactory; + +/** + * @author Filip Hrisafov + */ +public class OptionalWrapperConversionProvider implements ConversionProvider { + + private final ConversionProvider conversionProvider; + + public OptionalWrapperConversionProvider(ConversionProvider conversionProvider) { + this.conversionProvider = conversionProvider; + } + + @Override + public Assignment to(ConversionContext conversionContext) { + Assignment assignment = conversionProvider.to( new OptionalConversionContext( conversionContext ) ); + return new ToOptionalTypeConversion( conversionContext.getTargetType(), assignment ); + } + + @Override + public Assignment from(ConversionContext conversionContext) { + Assignment assignment = conversionProvider.to( new OptionalConversionContext( conversionContext ) ); + return new FromOptionalTypeConversion( conversionContext.getSourceType(), assignment ); + } + + @Override + public List getRequiredHelperMethods(ConversionContext conversionContext) { + return conversionProvider.getRequiredHelperMethods( conversionContext ); + } + + @Override + public List getRequiredHelperFields(ConversionContext conversionContext) { + return conversionProvider.getRequiredHelperFields( conversionContext ); + } + + private static class OptionalConversionContext implements ConversionContext { + + private final ConversionContext delegate; + + private OptionalConversionContext(ConversionContext delegate) { + this.delegate = delegate; + } + + @Override + public Type getTargetType() { + return resolveType( delegate.getTargetType() ); + } + + @Override + public Type getSourceType() { + return resolveType( delegate.getSourceType() ); + } + + private Type resolveType(Type type) { + if ( type.isOptionalType() ) { + return type.getOptionalBaseType(); + } + return type; + } + + @Override + public String getDateFormat() { + return delegate.getDateFormat(); + } + + @Override + public String getNumberFormat() { + return delegate.getNumberFormat(); + } + + @Override + public String getLocale() { + return delegate.getLocale(); + } + + @Override + public TypeFactory getTypeFactory() { + return delegate.getTypeFactory(); + } + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java new file mode 100644 index 0000000000..ad488d1a8f --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java @@ -0,0 +1,44 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.util.Collections; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Strings; + +import static org.mapstruct.ap.internal.conversion.ReverseConversion.inverse; + +/** + * @author Filip Hrisafov + */ +public class TypeToOptionalConversion extends SimpleConversion { + + static final TypeToOptionalConversion TYPE_TO_OPTIONAL_CONVERSION = new TypeToOptionalConversion(); + static final ConversionProvider OPTIONAL_TO_TYPE_CONVERSION = inverse( TYPE_TO_OPTIONAL_CONVERSION ); + + @Override + protected String getToExpression(ConversionContext conversionContext) { + return conversionContext.getTargetType().asRawType().createReferenceName() + ".of( )"; + } + + @Override + protected Set getToConversionImportTypes(ConversionContext conversionContext) { + return Collections.singleton( conversionContext.getTargetType().asRawType() ); + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + StringBuilder sb = new StringBuilder(".get"); + Type optionalBaseType = conversionContext.getSourceType().getOptionalBaseType(); + if ( optionalBaseType.isPrimitive() ) { + sb.append( "As" ).append( Strings.capitalize( optionalBaseType.getName() ) ); + } + return sb.append( "()" ).toString(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index 086773dbe9..c6fc7753f2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -20,6 +20,7 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; @@ -99,9 +100,12 @@ public class BeanMappingMethod extends NormalTypeMappingMethod { private final BuilderType returnTypeBuilder; private final MethodReference finalizerMethod; private final String finalizedResultName; + private final String optionalResultName; private final List beforeMappingReferencesWithFinalizedReturnType; private final List afterMappingReferencesWithFinalizedReturnType; + private final List afterMappingReferencesWithOptionalReturnType; private final Type subclassExhaustiveException; + private final Map sourceParametersReassignments; private final MappingReferences mappingReferences; @@ -119,6 +123,7 @@ public static class Builder extends AbstractMappingMethodBuilder unprocessedSourceParameters = new HashSet<>(); private final Set existingVariableNames = new HashSet<>(); private final Map> unprocessedDefinedTargets = new LinkedHashMap<>(); + private final Map sourceParametersReassignments = new HashMap<>(); private MappingReferences mappingReferences; private List targetThisReferences; @@ -176,10 +181,18 @@ public BeanMappingMethod build() { if ( selectionParameters != null && selectionParameters.getResultType() != null ) { // This is a user-defined return type, which means we need to do some extra checks for it userDefinedReturnType = ctx.getTypeFactory().getType( selectionParameters.getResultType() ); + returnTypeImpl = userDefinedReturnType; returnTypeBuilder = ctx.getTypeFactory().builderTypeFor( userDefinedReturnType, builder ); } else { - returnTypeBuilder = ctx.getTypeFactory().builderTypeFor( method.getReturnType(), builder ); + Type methodReturnType = method.getReturnType(); + if ( methodReturnType.isOptionalType() ) { + returnTypeImpl = methodReturnType.getOptionalBaseType(); + } + else { + returnTypeImpl = methodReturnType; + } + returnTypeBuilder = ctx.getTypeFactory().builderTypeFor( returnTypeImpl, builder ); } if ( isBuilderRequired() ) { // the userDefinedReturn type can also require a builder. That buildertype is already set @@ -195,7 +208,6 @@ public BeanMappingMethod build() { } } else if ( userDefinedReturnType != null ) { - returnTypeImpl = userDefinedReturnType; initializeFactoryMethod( returnTypeImpl, selectionParameters ); if ( factoryMethod != null || canResultTypeFromBeanMappingBeConstructed( returnTypeImpl ) ) { returnTypeToConstruct = returnTypeImpl; @@ -205,7 +217,6 @@ else if ( userDefinedReturnType != null ) { } } else if ( !method.isUpdateMethod() ) { - returnTypeImpl = method.getReturnType(); initializeFactoryMethod( returnTypeImpl, selectionParameters ); if ( factoryMethod != null || allowsAbstractReturnTypeAndIsEitherAbstractOrCanBeConstructed( returnTypeImpl ) @@ -266,12 +277,25 @@ else if ( !method.isUpdateMethod() ) { for ( Parameter sourceParameter : method.getSourceParameters() ) { unprocessedSourceParameters.add( sourceParameter ); - if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() || - sourceParameter.getType().isMapType() ) { + Type sourceParameterType = sourceParameter.getType(); + if ( sourceParameterType.isOptionalType() ) { + String sourceParameterValueName = Strings.getSafeVariableName( + sourceParameter.getName() + "Value", + existingVariableNames + ); + existingVariableNames.add( sourceParameterValueName ); + sourceParameterType = sourceParameterType.getOptionalBaseType(); + sourceParametersReassignments.put( + sourceParameter.getName(), + new Parameter( sourceParameterValueName, sourceParameter.getName(), sourceParameterType ) + ); + } + if ( sourceParameterType.isPrimitive() || sourceParameterType.isArrayType() || + sourceParameterType.isMapType() ) { continue; } - Map readAccessors = sourceParameter.getType().getPropertyReadAccessors(); + Map readAccessors = sourceParameterType.getPropertyReadAccessors(); unprocessedSourceProperties.putAll( readAccessors ); } @@ -362,12 +386,24 @@ else if ( !method.isUpdateMethod() ) { ctx, existingVariableNames ); + + Supplier> additionalAfterMappingParameterBindingsProvider = () -> + sourceParametersReassignments.values() + .stream() + .map( parameter -> method.getSourceParameters().size() == 1 ? + ParameterBinding.fromParameter( parameter ) : + ParameterBinding.fromTypeAndName( + parameter.getType(), + parameter.getOriginalName() + ".get()" + ) ) + .collect( Collectors.toList() ); List afterMappingMethods = LifecycleMethodResolver.afterMappingMethods( method, resultTypeToMap, selectionParameters, ctx, - existingVariableNames + existingVariableNames, + Collections::emptyList ); if ( method instanceof ForgedMethod ) { @@ -409,12 +445,15 @@ else if ( !method.isUpdateMethod() ) { if ( shouldCallFinalizerMethod( returnTypeToConstruct ) ) { finalizeMethod = getFinalizerMethod(); - Type actualReturnType = method.getReturnType(); + Type finalizerReturnType = method.getReturnType(); + if ( finalizerReturnType.isOptionalType() ) { + finalizerReturnType = finalizerReturnType.getOptionalBaseType(); + } beforeMappingReferencesWithFinalizedReturnType.addAll( filterMappingTarget( LifecycleMethodResolver.beforeMappingMethods( method, - actualReturnType, + finalizerReturnType, selectionParameters, ctx, existingVariableNames @@ -424,14 +463,33 @@ else if ( !method.isUpdateMethod() ) { afterMappingReferencesWithFinalizedReturnType.addAll( LifecycleMethodResolver.afterMappingMethods( method, - actualReturnType, + finalizerReturnType, + selectionParameters, + ctx, + existingVariableNames, + additionalAfterMappingParameterBindingsProvider + ) ); + + keepMappingReferencesUsingTarget( beforeMappingReferencesWithFinalizedReturnType, finalizerReturnType ); + keepMappingReferencesUsingTarget( afterMappingReferencesWithFinalizedReturnType, finalizerReturnType ); + } + + List afterMappingReferencesWithOptionalReturnType = new ArrayList<>(); + if ( method.getReturnType().isOptionalType() ) { + afterMappingReferencesWithOptionalReturnType.addAll( LifecycleMethodResolver.afterMappingMethods( + method, + method.getReturnType(), selectionParameters, ctx, - existingVariableNames + existingVariableNames, + additionalAfterMappingParameterBindingsProvider ) ); - keepMappingReferencesUsingTarget( beforeMappingReferencesWithFinalizedReturnType, actualReturnType ); - keepMappingReferencesUsingTarget( afterMappingReferencesWithFinalizedReturnType, actualReturnType ); + keepMappingReferencesUsingTarget( + afterMappingReferencesWithOptionalReturnType, + method.getReturnType() + ); + } Map presenceChecksByParameter = new LinkedHashMap<>(); @@ -461,11 +519,13 @@ else if ( !method.isUpdateMethod() ) { afterMappingMethods, beforeMappingReferencesWithFinalizedReturnType, afterMappingReferencesWithFinalizedReturnType, + afterMappingReferencesWithOptionalReturnType, finalizeMethod, mappingReferences, subclasses, presenceChecksByParameter, - subclassExhaustiveExceptionType + subclassExhaustiveExceptionType, + sourceParametersReassignments ); } @@ -609,8 +669,17 @@ private void initializeMappingReferencesIfNeeded(Type resultTypeToMap) { * builder is not assignable to the return type (so without building). */ private boolean isBuilderRequired() { - return returnTypeBuilder != null - && ( !method.isUpdateMethod() || !method.isMappingTargetAssignableToReturnType() ); + if ( returnTypeBuilder == null ) { + return false; + } + if ( method.isUpdateMethod() ) { + // when @MappingTarget annotated parameter is the same type as the return type. + return !method.getResultType().isAssignableTo( method.getReturnType() ); + } + else { + // For non-update methods a builder is required when returnTypeBuilder is set + return true; + } } private boolean shouldCallFinalizerMethod(Type returnTypeToConstruct ) { @@ -1510,6 +1579,7 @@ else if ( mapping.getJavaExpression() != null ) { if ( sourceRef != null ) { // sourceRef == null is not considered an error here if ( sourceRef.isValid() ) { + Parameter sourceParameter = sourceRef.getParameter(); // targetProperty == null can occur: we arrived here because we want as many errors // as possible before we stop analysing @@ -1518,7 +1588,8 @@ else if ( mapping.getJavaExpression() != null ) { .sourceMethod( method ) .target( targetPropertyName, targetReadAccessor, targetWriteAccessor ) .sourcePropertyName( mapping.getSourceName() ) - .sourceReference( sourceRef ) + .sourceReference( sourceRef.withParameter( + sourceParametersReassignments.get( sourceParameter.getName() ) ) ) .selectionParameters( mapping.getSelectionParameters() ) .formattingParameters( mapping.getFormattingParameters() ) .existingVariableNames( existingVariableNames ) @@ -1530,7 +1601,6 @@ else if ( mapping.getJavaExpression() != null ) { .options( mapping ) .build(); handledTargets.add( targetPropertyName ); - Parameter sourceParameter = sourceRef.getParameter(); unprocessedSourceParameters.remove( sourceParameter ); // If the source parameter was directly mapped if ( sourceRef.getPropertyEntries().isEmpty() ) { @@ -1743,20 +1813,26 @@ private SourceReference getSourceRefByTargetName(Parameter sourceParameter, Stri SourceReference sourceRef = null; - if ( sourceParameter.getType().isPrimitive() || sourceParameter.getType().isArrayType() ) { + Type sourceParameterType = sourceParameter.getType(); + Parameter sourceParameterToUse = sourceParameter; + if ( sourceParameterType.isOptionalType() ) { + sourceParameterType = sourceParameterType.getOptionalBaseType(); + sourceParameterToUse = sourceParametersReassignments.get( sourceParameter.getName() ); + } + if ( sourceParameterType.isPrimitive() || sourceParameterType.isArrayType() ) { return sourceRef; } - ReadAccessor sourceReadAccessor = sourceParameter.getType() + ReadAccessor sourceReadAccessor = sourceParameterType .getReadAccessor( targetPropertyName, method.getSourceParameters().size() == 1 ); if ( sourceReadAccessor != null ) { // property mapping PresenceCheckAccessor sourcePresenceChecker = - sourceParameter.getType().getPresenceChecker( targetPropertyName ); + sourceParameterType.getPresenceChecker( targetPropertyName ); - DeclaredType declaredSourceType = (DeclaredType) sourceParameter.getType().getTypeMirror(); + DeclaredType declaredSourceType = (DeclaredType) sourceParameterType.getTypeMirror(); Type returnType = ctx.getTypeFactory().getReturnType( declaredSourceType, sourceReadAccessor ); - sourceRef = new SourceReference.BuilderFromProperty().sourceParameter( sourceParameter ) + sourceRef = new SourceReference.BuilderFromProperty().sourceParameter( sourceParameterToUse ) .type( returnType ) .readAccessor( sourceReadAccessor ) .presenceChecker( sourcePresenceChecker ) @@ -2033,11 +2109,14 @@ private BeanMappingMethod(Method method, List afterMappingReferences, List beforeMappingReferencesWithFinalizedReturnType, List afterMappingReferencesWithFinalizedReturnType, + List afterMappingReferencesWithOptionalReturnType, MethodReference finalizerMethod, MappingReferences mappingReferences, List subclassMappings, Map presenceChecksByParameter, - Type subclassExhaustiveException) { + Type subclassExhaustiveException, + Map sourceParametersReassignments + ) { super( method, annotations, @@ -2057,14 +2136,21 @@ private BeanMappingMethod(Method method, this.finalizedResultName = Strings.getSafeVariableName( getResultName() + "Result", existingVariableNames ); existingVariableNames.add( this.finalizedResultName ); + this.optionalResultName = + Strings.getSafeVariableName( getResultName() + "ResultOptional", existingVariableNames ); + existingVariableNames.add( this.optionalResultName ); } else { this.finalizedResultName = null; + this.optionalResultName = + Strings.getSafeVariableName( getResultName() + "Optional", existingVariableNames ); + existingVariableNames.add( this.optionalResultName ); } this.mappingReferences = mappingReferences; this.beforeMappingReferencesWithFinalizedReturnType = beforeMappingReferencesWithFinalizedReturnType; this.afterMappingReferencesWithFinalizedReturnType = afterMappingReferencesWithFinalizedReturnType; + this.afterMappingReferencesWithOptionalReturnType = afterMappingReferencesWithOptionalReturnType; // initialize constant mappings as all mappings, but take out the ones that can be contributed to a // parameter mapping. @@ -2099,6 +2185,7 @@ else if ( sourceParameterNames.contains( mapping.getSourceBeanName() ) ) { } this.returnTypeToConstruct = returnTypeToConstruct; this.subclassMappings = subclassMappings; + this.sourceParametersReassignments = sourceParametersReassignments; } public Type getSubclassExhaustiveException() { @@ -2121,6 +2208,18 @@ public String getFinalizedResultName() { return finalizedResultName; } + public Type getFinalizedReturnType() { + Type returnType = getReturnType(); + if ( returnType.isOptionalType() ) { + return returnType.getOptionalBaseType(); + } + return returnType; + } + + public String getOptionalResultName() { + return optionalResultName; + } + public List getBeforeMappingReferencesWithFinalizedReturnType() { return beforeMappingReferencesWithFinalizedReturnType; } @@ -2129,6 +2228,10 @@ public List getAfterMappingReferencesWithFinal return afterMappingReferencesWithFinalizedReturnType; } + public List getAfterMappingReferencesWithOptionalReturnType() { + return afterMappingReferencesWithOptionalReturnType; + } + public List propertyMappingsByParameter(Parameter parameter) { // issues: #909 and #1244. FreeMarker has problem getting values from a map when the search key is size or value return mappingsByParameter.getOrDefault( parameter.getName(), Collections.emptyList() ); @@ -2188,6 +2291,10 @@ public Set getImportTypes() { types.addAll( reference.getImportTypes() ); } + for ( LifecycleCallbackMethodReference reference : afterMappingReferencesWithOptionalReturnType ) { + types.addAll( reference.getImportTypes() ); + } + return types; } @@ -2215,6 +2322,10 @@ public List getSourceParametersNotNeedingPresenceCheck() { .collect( Collectors.toList() ); } + public Parameter getSourceParameterReassignment(Parameter parameter) { + return sourceParametersReassignments.get( parameter.getName() ); + } + private boolean needsPresenceCheck(Parameter parameter) { if ( !presenceChecksByParameter.containsKey( parameter.getName() ) ) { return false; @@ -2277,5 +2388,4 @@ public boolean equals(Object obj) { return true; } - } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java new file mode 100644 index 0000000000..f8c596a368 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java @@ -0,0 +1,113 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.assignment.OptionalGetWrapper; +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class FromOptionalTypeConversion extends ModelElement implements Assignment { + + private final Assignment conversionAssignment; + private final Type optionalType; + + public FromOptionalTypeConversion(Type optionalType, Assignment conversionAssignment) { + this.conversionAssignment = conversionAssignment; + this.optionalType = optionalType; + } + + @Override + public Set getImportTypes() { + return conversionAssignment.getImportTypes(); + } + + @Override + public List getThrownTypes() { + return conversionAssignment.getThrownTypes(); + } + + public Assignment getAssignment() { + return conversionAssignment; + } + + @Override + public String getSourceReference() { + return conversionAssignment.getSourceReference(); + } + + @Override + public boolean isSourceReferenceParameter() { + return conversionAssignment.isSourceReferenceParameter(); + } + + @Override + public PresenceCheck getSourcePresenceCheckerReference() { + return conversionAssignment.getSourcePresenceCheckerReference(); + } + + @Override + public Type getSourceType() { + return conversionAssignment.getSourceType(); + } + + @Override + public String createUniqueVarName(String desiredName) { + return conversionAssignment.createUniqueVarName( desiredName ); + } + + @Override + public String getSourceLocalVarName() { + return conversionAssignment.getSourceLocalVarName(); + } + + @Override + public void setSourceLocalVarName(String sourceLocalVarName) { + conversionAssignment.setSourceLocalVarName( sourceLocalVarName ); + } + + @Override + public String getSourceLoopVarName() { + return conversionAssignment.getSourceLoopVarName(); + } + + @Override + public void setSourceLoopVarName(String sourceLoopVarName) { + conversionAssignment.setSourceLoopVarName( sourceLoopVarName ); + } + + @Override + public String getSourceParameterName() { + return conversionAssignment.getSourceParameterName(); + } + + @Override + public void setAssignment(Assignment assignment) { + this.conversionAssignment.setAssignment( new OptionalGetWrapper( assignment, optionalType ) ); + } + + @Override + public AssignmentType getType() { + return conversionAssignment.getType(); + } + + @Override + public boolean isCallingUpdateMethod() { + return false; + } + + @Override + public String toString() { + return conversionAssignment.toString(); + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java index cfe4f9f8b7..ada9dac470 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/LifecycleMethodResolver.java @@ -6,11 +6,14 @@ package org.mapstruct.ap.internal.model; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.function.Supplier; import java.util.stream.Collectors; import org.mapstruct.ap.internal.model.common.Parameter; +import org.mapstruct.ap.internal.model.common.ParameterBinding; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; @@ -63,13 +66,16 @@ public static List afterMappingMethods(Method Type alternativeTarget, SelectionParameters selectionParameters, MappingBuilderContext ctx, - Set existingVariableNames) { + Set existingVariableNames, + Supplier> parameterBindingsProvider) { return collectLifecycleCallbackMethods( method, alternativeTarget, selectionParameters, filterAfterMappingMethods( getAllAvailableMethods( method, ctx.getSourceModel() ) ), ctx, - existingVariableNames ); + existingVariableNames, + parameterBindingsProvider + ); } /** @@ -131,13 +137,34 @@ private static List getAllAvailableMethods(Method method, List collectLifecycleCallbackMethods( Method method, Type targetType, SelectionParameters selectionParameters, List callbackMethods, MappingBuilderContext ctx, Set existingVariableNames) { + return collectLifecycleCallbackMethods( + method, + targetType, + selectionParameters, + callbackMethods, + ctx, + existingVariableNames, + Collections::emptyList + ); + } + + private static List collectLifecycleCallbackMethods( + Method method, Type targetType, SelectionParameters selectionParameters, List callbackMethods, + MappingBuilderContext ctx, Set existingVariableNames, + Supplier> parameterBindingsProvider) { MethodSelectors selectors = new MethodSelectors( ctx.getTypeUtils(), ctx.getElementUtils(), ctx.getMessager(), ctx.getOptions() ); List> matchingMethods = selectors.getMatchingMethods( callbackMethods, - SelectionContext.forLifecycleMethods( method, targetType, selectionParameters, ctx.getTypeFactory() ) + SelectionContext.forLifecycleMethods( + method, + targetType, + selectionParameters, + ctx.getTypeFactory(), + parameterBindingsProvider + ) ); return toLifecycleCallbackMethodRefs( diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 95c229c6e6..1ebf99ffeb 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -30,6 +30,7 @@ import org.mapstruct.ap.internal.util.FormattingMessager; import org.mapstruct.ap.internal.util.Services; import org.mapstruct.ap.internal.util.TypeUtils; +import org.mapstruct.ap.internal.version.VersionInformation; import org.mapstruct.ap.spi.EnumMappingStrategy; import org.mapstruct.ap.spi.EnumTransformationStrategy; import org.mapstruct.ap.spi.MappingExclusionProvider; @@ -109,6 +110,7 @@ Assignment getTargetAssignment(Method mappingMethod, ForgedMethodHistory descrip private final ElementUtils elementUtils; private final TypeUtils typeUtils; private final FormattingMessager messager; + private final VersionInformation versionInformation; private final AccessorNamingUtils accessorNaming; private final EnumMappingStrategy enumMappingStrategy; private final Map enumTransformationStrategies; @@ -126,6 +128,7 @@ public MappingBuilderContext(TypeFactory typeFactory, ElementUtils elementUtils, TypeUtils typeUtils, FormattingMessager messager, + VersionInformation versionInformation, AccessorNamingUtils accessorNaming, EnumMappingStrategy enumMappingStrategy, Map enumTransformationStrategies, @@ -138,6 +141,7 @@ public MappingBuilderContext(TypeFactory typeFactory, this.elementUtils = elementUtils; this.typeUtils = typeUtils; this.messager = messager; + this.versionInformation = versionInformation; this.accessorNaming = accessorNaming; this.enumMappingStrategy = enumMappingStrategy; this.enumTransformationStrategies = enumTransformationStrategies; @@ -190,6 +194,10 @@ public FormattingMessager getMessager() { return messager; } + public VersionInformation getVersionInformation() { + return versionInformation; + } + public AccessorNamingUtils getAccessorNaming() { return accessorNaming; } @@ -264,6 +272,9 @@ public boolean canGenerateAutoSubMappingBetween(Type sourceType, Type targetType * @return {@code true} if the type is not excluded from the {@link MappingExclusionProvider} */ private boolean canGenerateAutoSubMappingFor(Type type) { + if ( "java.util.Optional".equals( type.getFullyQualifiedName() ) ) { + return !SUB_MAPPING_EXCLUSION_PROVIDER.isExcluded( type.getOptionalBaseType().getTypeElement() ); + } return type.getTypeElement() != null && !SUB_MAPPING_EXCLUSION_PROVIDER.isExcluded( type.getTypeElement() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java index 599ddf1d35..0d04f5b6d5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingMethod.java @@ -97,7 +97,11 @@ else if ( getResultType().isArrayType() ) { return name; } else { - String name = getSafeVariableName( getResultType().getName(), existingVarNames ); + Type resultType = getResultType(); + if ( resultType.isOptionalType() ) { + resultType = resultType.getOptionalBaseType(); + } + String name = getSafeVariableName( resultType.getName(), existingVarNames ); existingVarNames.add( name ); return name; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index 25c9f8fc03..ed841ba5bc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -17,6 +17,7 @@ import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.presence.AnyPresenceChecksPresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; +import org.mapstruct.ap.internal.model.presence.OptionalPresenceCheck; import org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck; import org.mapstruct.ap.internal.util.Strings; import org.mapstruct.ap.internal.util.accessor.PresenceCheckAccessor; @@ -71,21 +72,58 @@ public NestedPropertyMappingMethod build() { } String previousPropertyName = sourceParameter.getName(); + Type previousPropertyType = sourceParameter.getType(); for ( int i = 0; i < propertyEntries.size(); i++ ) { PropertyEntry propertyEntry = propertyEntries.get( i ); - PresenceCheck presenceCheck = getPresenceCheck( propertyEntry, previousPropertyName ); - - if ( i > 0 ) { - // If this is not the first property entry, - // then we might need to combine the presence check with a null check of the previous property - if ( presenceCheck != null ) { - presenceCheck = new AnyPresenceChecksPresenceCheck( Arrays.asList( - new NullPresenceCheck( previousPropertyName, true ), - presenceCheck - ) ); + PresenceCheck presenceCheck; + + if ( previousPropertyType.isOptionalType() ) { + String optionalValueSafeName = Strings.getSafeVariableName( + previousPropertyName + "Value", + existingVariableNames + ); + existingVariableNames.add( optionalValueSafeName ); + + presenceCheck = getPresenceCheck( propertyEntry, optionalValueSafeName ); + + String optionalValueSource = previousPropertyName + ".get()"; + boolean doesNotNeedFollowUpProperty = false; + if ( i == propertyEntries.size() - 1 ) { + // If this is the last property, and we do not have a presence check, + // then we do not need to assign the optional value + // e.g., we need to generate .get().getXxx(); + doesNotNeedFollowUpProperty = presenceCheck == null; + if ( doesNotNeedFollowUpProperty ) { + optionalValueSource += "." + propertyEntry.getReadAccessor().getReadValueSource(); + } } - else { - presenceCheck = new NullPresenceCheck( previousPropertyName, true ); + Type optionalBaseType = previousPropertyType.getOptionalBaseType(); + safePropertyEntries.add( new SafePropertyEntry( + optionalBaseType, + optionalValueSafeName, + optionalValueSource, + new OptionalPresenceCheck( previousPropertyName, ctx.getVersionInformation(), true ) + ) ); + if ( doesNotNeedFollowUpProperty ) { + break; + } + previousPropertyName = optionalValueSafeName; + + } + else { + presenceCheck = getPresenceCheck( propertyEntry, previousPropertyName ); + if ( i > 0 ) { + // If this is not the first property entry, + // then we might need to combine the presence check with a null check of the previous property + if ( presenceCheck != null ) { + presenceCheck = new AnyPresenceChecksPresenceCheck( Arrays.asList( + new NullPresenceCheck( previousPropertyName, true ), + presenceCheck + ) ); + } + else { + presenceCheck = new NullPresenceCheck( previousPropertyName, true ); + } } } @@ -101,6 +139,7 @@ public NestedPropertyMappingMethod build() { thrownTypes.addAll( ctx.getTypeFactory().getThrownTypes( propertyEntry.getReadAccessor() ) ); previousPropertyName = safeName; + previousPropertyType = propertyEntry.getType(); } method.addThrownTypes( thrownTypes ); return new NestedPropertyMappingMethod( method, safePropertyEntries ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index 049e4caf37..784342b8d7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -13,6 +13,7 @@ import org.mapstruct.ap.internal.model.common.Parameter; import org.mapstruct.ap.internal.model.common.PresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; +import org.mapstruct.ap.internal.model.presence.OptionalPresenceCheck; import org.mapstruct.ap.internal.model.source.Method; import org.mapstruct.ap.internal.model.source.ParameterProvidedMethods; import org.mapstruct.ap.internal.model.source.SelectionParameters; @@ -87,7 +88,10 @@ public static PresenceCheck getPresenceCheckForSourceParameter( ); if ( matchingMethods.isEmpty() ) { - if ( !sourceParameter.getType().isPrimitive() ) { + if ( sourceParameter.getType().isOptionalType() ) { + return new OptionalPresenceCheck( sourceParameter.getName(), ctx.getVersionInformation() ); + } + else if ( !sourceParameter.getType().isPrimitive() ) { return new NullPresenceCheck( sourceParameter.getName() ); } return null; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 08e8adbd1b..622ba9cef0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -38,6 +38,7 @@ import org.mapstruct.ap.internal.model.presence.AllPresenceChecksPresenceCheck; import org.mapstruct.ap.internal.model.presence.JavaExpressionPresenceCheck; import org.mapstruct.ap.internal.model.presence.NullPresenceCheck; +import org.mapstruct.ap.internal.model.presence.OptionalPresenceCheck; import org.mapstruct.ap.internal.model.presence.SuffixPresenceCheck; import org.mapstruct.ap.internal.model.source.DelegatingOptions; import org.mapstruct.ap.internal.model.source.MappingControl; @@ -290,7 +291,7 @@ else if ( targetType.isArrayType() && sourceType.isArrayType() && assignment.get return new PropertyMapping( sourcePropertyName, targetPropertyName, - rightHandSide.getSourceParameterName(), + sourceReference.getParameter().getOriginalName(), targetWriteAccessor.getSimpleName(), targetReadAccessor, targetType, @@ -703,15 +704,26 @@ private PresenceCheck getSourcePresenceCheckerRef(SourceReference sourceReferenc String variableName = sourceParam.getName() + "." + propertyEntry.getReadAccessor().getReadValueSource(); + Type variableType = propertyEntry.getType(); for (int i = 1; i < sourceReference.getPropertyEntries().size(); i++) { PropertyEntry entry = sourceReference.getPropertyEntries().get( i ); if (entry.getPresenceChecker() != null && entry.getReadAccessor() != null) { - presenceChecks.add( new NullPresenceCheck( variableName ) ); + if ( variableType.isOptionalType() ) { + presenceChecks.add( new OptionalPresenceCheck( + variableName, + ctx.getVersionInformation() + ) ); + variableName = variableName + ".get()"; + } + else { + presenceChecks.add( new NullPresenceCheck( variableName ) ); + } presenceChecks.add( new SuffixPresenceCheck( variableName, entry.getPresenceChecker().getPresenceCheckSuffix() ) ); variableName = variableName + "." + entry.getReadAccessor().getSimpleName() + "()"; + variableType = entry.getType(); } else { break; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java new file mode 100644 index 0000000000..5925540e10 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java @@ -0,0 +1,119 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; + +/** + * @author Filip Hrisafov + */ +public class ToOptionalTypeConversion extends ModelElement implements Assignment { + + private final Assignment conversionAssignment; + private final Type targetType; + + public ToOptionalTypeConversion(Type targetType, Assignment conversionAssignment) { + this.conversionAssignment = conversionAssignment; + this.targetType = targetType; + } + + public Type getTargetType() { + return targetType; + } + + @Override + public Set getImportTypes() { + Set importTypes = new HashSet<>( conversionAssignment.getImportTypes() ); + importTypes.add( targetType ); + return importTypes; + } + + @Override + public List getThrownTypes() { + return conversionAssignment.getThrownTypes(); + } + + public Assignment getAssignment() { + return conversionAssignment; + } + + @Override + public String getSourceReference() { + return conversionAssignment.getSourceReference(); + } + + @Override + public boolean isSourceReferenceParameter() { + return conversionAssignment.isSourceReferenceParameter(); + } + + @Override + public PresenceCheck getSourcePresenceCheckerReference() { + return conversionAssignment.getSourcePresenceCheckerReference(); + } + + @Override + public Type getSourceType() { + return conversionAssignment.getSourceType(); + } + + @Override + public String createUniqueVarName(String desiredName) { + return conversionAssignment.createUniqueVarName( desiredName ); + } + + @Override + public String getSourceLocalVarName() { + return conversionAssignment.getSourceLocalVarName(); + } + + @Override + public void setSourceLocalVarName(String sourceLocalVarName) { + conversionAssignment.setSourceLocalVarName( sourceLocalVarName ); + } + + @Override + public String getSourceLoopVarName() { + return conversionAssignment.getSourceLoopVarName(); + } + + @Override + public void setSourceLoopVarName(String sourceLoopVarName) { + conversionAssignment.setSourceLoopVarName( sourceLoopVarName ); + } + + @Override + public String getSourceParameterName() { + return conversionAssignment.getSourceParameterName(); + } + + @Override + public void setAssignment(Assignment assignment) { + conversionAssignment.setAssignment( assignment ); + } + + @Override + public AssignmentType getType() { + return conversionAssignment.getType(); + } + + @Override + public boolean isCallingUpdateMethod() { + return false; + } + + @Override + public String toString() { + return targetType.getName() + ".of( " + conversionAssignment.toString() + " )"; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java new file mode 100644 index 0000000000..9064640bb4 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java @@ -0,0 +1,35 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.assignment; + +import org.mapstruct.ap.internal.model.common.Assignment; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.util.Strings; + +/** + * @author Filip Hrisafov + */ +public class OptionalGetWrapper extends AssignmentWrapper { + + private final Type optionalType; + + public OptionalGetWrapper(Assignment decoratedAssignment, Type optionalType) { + super( decoratedAssignment, false ); + this.optionalType = optionalType; + } + + public Type getOptionalType() { + return optionalType; + } + + @Override + public String toString() { + if ( optionalType.getFullyQualifiedName().equals( "java.util.Optional" ) ) { + return getAssignment() + ".get()"; + } + return getAssignment() + ".getAs" + Strings.capitalize( optionalType.getOptionalBaseType().getName() ) + "()"; + } +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java index 73ec84b6b7..c37b12e311 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/SourceReference.java @@ -325,6 +325,9 @@ private List matchWithSourceAccessorTypes(Type type, String[] ent for ( int i = 0; i < entryNames.length; i++ ) { boolean matchFound = false; Type noBoundsType = newType.withoutBounds(); + if ( noBoundsType.isOptionalType() ) { + noBoundsType = noBoundsType.getOptionalBaseType(); + } ReadAccessor readAccessor = noBoundsType.getReadAccessor( entryNames[i], i > 0 || allowedMapToBean ); if ( readAccessor != null ) { PresenceCheckAccessor presenceChecker = noBoundsType.getPresenceChecker( entryNames[i] ); @@ -465,4 +468,11 @@ public List push(TypeFactory typeFactory, FormattingMessager me return result; } + public SourceReference withParameter(Parameter parameter) { + if ( parameter == null || getParameter() == parameter ) { + return this; + } + return new SourceReference( parameter, getPropertyEntries(), isValid() ); + } + } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java index 96d3d6fe78..d3a29e30a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/ConversionContext.java @@ -21,6 +21,13 @@ public interface ConversionContext { */ Type getTargetType(); + /** + * Returns the source type of this conversion. + * + * @return The source type of this conversion. + */ + Type getSourceType(); + /** * Returns the date format if this conversion or built-in method is from String to a date type (e.g. {@link Date}) * or vice versa. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java index 159f1663e2..4e5eed47a8 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/DefaultConversionContext.java @@ -61,6 +61,11 @@ public Type getTargetType() { return targetType; } + @Override + public Type getSourceType() { + return sourceType; + } + @Override public String getNumberFormat() { return numberFormat; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java index aaab7f46ca..c5091869a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Parameter.java @@ -51,12 +51,13 @@ private Parameter(Element element, Type type, boolean varArgs) { this.varArgs = varArgs; } - private Parameter(String name, Type type, boolean mappingTarget, boolean targetType, boolean mappingContext, + private Parameter(String name, String originalName, Type type, boolean mappingTarget, boolean targetType, + boolean mappingContext, boolean sourcePropertyName, boolean targetPropertyName, boolean varArgs) { this.element = null; this.name = name; - this.originalName = name; + this.originalName = originalName; this.type = type; this.mappingTarget = mappingTarget; this.targetType = targetType; @@ -67,7 +68,11 @@ private Parameter(String name, Type type, boolean mappingTarget, boolean targetT } public Parameter(String name, Type type) { - this( name, type, false, false, false, false, false, false ); + this( name, name, type ); + } + + public Parameter(String name, String originalName, Type type) { + this( name, originalName, type, false, false, false, false, false, false ); } public Element getElement() { @@ -141,6 +146,20 @@ public boolean isSourceParameter() { !isTargetPropertyName(); } + public Parameter withName(String name) { + return new Parameter( + name, + this.name, + type, + mappingTarget, + targetType, + mappingContext, + sourcePropertyName, + targetPropertyName, + varArgs + ); + } + @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; @@ -176,6 +195,7 @@ public static Parameter forElementAndType(VariableElement element, Type paramete public static Parameter forForgedMappingTarget(Type parameterType) { return new Parameter( + "mappingTarget", "mappingTarget", parameterType, true, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 8fb10090c2..29bb3cd906 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -397,11 +397,32 @@ private boolean isType(Class type) { return type.getName().equals( getFullyQualifiedName() ); } - private boolean isOptionalType() { + public boolean isOptionalType() { return isType( Optional.class ) || isType( OptionalInt.class ) || isType( OptionalDouble.class ) || isType( OptionalLong.class ); } + public Type getOptionalBaseType() { + if ( isType( Optional.class ) ) { + return getTypeParameters().get( 0 ); + } + + if ( isType( OptionalInt.class ) ) { + return typeFactory.getType( int.class ); + } + + if ( isType( OptionalDouble.class ) ) { + return typeFactory.getType( double.class ); + } + + if ( isType( OptionalLong.class ) ) { + return typeFactory.getType( long.class ); + } + + throw new IllegalStateException( "getOptionalBaseType should only be called for Optional types." ); + + } + public boolean isTypeVar() { return (typeMirror.getKind() == TypeKind.TYPEVAR); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.java new file mode 100644 index 0000000000..d727c30f24 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.java @@ -0,0 +1,77 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.model.presence; + +import java.util.Collections; +import java.util.Objects; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ModelElement; +import org.mapstruct.ap.internal.model.common.PresenceCheck; +import org.mapstruct.ap.internal.model.common.Type; +import org.mapstruct.ap.internal.version.VersionInformation; + +/** + * Presence checker for {@link java.util.Optional} types. + * + * @author Ken Wang + */ +public class OptionalPresenceCheck extends ModelElement implements PresenceCheck { + + private final String sourceReference; + private final VersionInformation versionInformation; + private final boolean negate; + + public OptionalPresenceCheck(String sourceReference, VersionInformation versionInformation) { + this( sourceReference, versionInformation, false ); + } + + public OptionalPresenceCheck(String sourceReference, VersionInformation versionInformation, boolean negate) { + this.sourceReference = sourceReference; + this.versionInformation = versionInformation; + this.negate = negate; + } + + public String getSourceReference() { + return sourceReference; + } + + public VersionInformation getVersionInformation() { + return versionInformation; + } + + @Override + public Set getImportTypes() { + return Collections.emptySet(); + } + + public boolean isNegate() { + return negate; + } + + @Override + public PresenceCheck negate() { + return new OptionalPresenceCheck( sourceReference, versionInformation, !negate ); + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + OptionalPresenceCheck that = (OptionalPresenceCheck) o; + return Objects.equals( sourceReference, that.sourceReference ); + } + + @Override + public int hashCode() { + return Objects.hash( sourceReference ); + } + +} diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java index ba32b12b46..d9c9ce41fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/Method.java @@ -182,15 +182,6 @@ default ConditionMethodOptions getConditionOptions() { return ConditionMethodOptions.empty(); } - /** - * - * @return true when @MappingTarget annotated parameter is the same type as the return type. The method has - * to be an update method in order for this to be true. - */ - default boolean isMappingTargetAssignableToReturnType() { - return isUpdateMethod() && getResultType().isAssignableTo( getReturnType() ); - } - /** * @return the first source type, intended for mapping methods from single source to target */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java index 84bd04d7db..79351ae868 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectionContext.java @@ -106,8 +106,9 @@ public static SelectionContext forMappingMethods(Method mappingMethod, Type sour } public static SelectionContext forLifecycleMethods(Method mappingMethod, Type targetType, - SelectionParameters selectionParameters, - TypeFactory typeFactory) { + SelectionParameters selectionParameters, + TypeFactory typeFactory, + Supplier> additionalParameterBindingsProvider) { SelectionCriteria criteria = SelectionCriteria.forLifecycleMethods( selectionParameters ); return new SelectionContext( null, @@ -115,12 +116,16 @@ public static SelectionContext forLifecycleMethods(Method mappingMethod, Type ta mappingMethod, targetType, mappingMethod.getResultType(), - () -> getAvailableParameterBindingsFromMethod( - mappingMethod, - targetType, - criteria.getSourceRHS(), - typeFactory - ) + () -> { + List parameterBindings = getAvailableParameterBindingsFromMethod( + mappingMethod, + targetType, + criteria.getSourceRHS(), + typeFactory + ); + parameterBindings.addAll( additionalParameterBindingsProvider.get() ); + return parameterBindings; + } ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java index 055bfe6095..0457a66da4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/DefaultVersionInformation.java @@ -41,6 +41,7 @@ public class DefaultVersionInformation implements VersionInformation { private final String runtimeVendor; private final String compiler; private final boolean sourceVersionAtLeast9; + private final boolean sourceVersionAtLeast11; private final boolean sourceVersionAtLeast19; private final boolean eclipseJDT; private final boolean javac; @@ -54,6 +55,7 @@ public class DefaultVersionInformation implements VersionInformation { this.javac = compiler.startsWith( COMPILER_NAME_JAVAC ); // If the difference between the source version and RELEASE_6 is more that 2 than we are at least on 9 this.sourceVersionAtLeast9 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 2; + this.sourceVersionAtLeast11 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 4; this.sourceVersionAtLeast19 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 12; } @@ -82,6 +84,11 @@ public boolean isSourceVersionAtLeast9() { return sourceVersionAtLeast9; } + @Override + public boolean isSourceVersionAtLeast11() { + return sourceVersionAtLeast11; + } + @Override public boolean isSourceVersionAtLeast19() { return sourceVersionAtLeast19; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java index ba24e868aa..03e8bf977f 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/MapperCreationProcessor.java @@ -119,6 +119,7 @@ public Mapper process(ProcessorContext context, TypeElement mapperTypeElement, L elementUtils, typeUtils, messager, + versionInformation, accessorNaming, context.getEnumMappingStrategy(), context.getEnumTransformationStrategies(), diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index ba903b6048..2a36f6b890 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -464,7 +464,7 @@ private ConversionAssignment resolveViaConversion(Type sourceType, Type targetTy Assignment conversion = conversionProvider.to( ctx ); if ( conversion != null ) { - return new ConversionAssignment( sourceType, targetType, conversionProvider.to( ctx ) ); + return new ConversionAssignment( sourceType, targetType, conversion ); } return null; } @@ -673,7 +673,16 @@ Assignment getAssignment() { void reportMessageWhenNarrowing(FormattingMessager messager, ResolvingAttempt attempt) { - if ( NativeTypes.isNarrowing( sourceType.getFullyQualifiedName(), targetType.getFullyQualifiedName() ) ) { + Type source = sourceType; + if ( sourceType.isOptionalType() ) { + source = sourceType.getOptionalBaseType(); + } + + Type target = targetType; + if ( targetType.isOptionalType() ) { + target = targetType.getOptionalBaseType(); + } + if ( NativeTypes.isNarrowing( source.getFullyQualifiedName(), target.getFullyQualifiedName() ) ) { ReportingPolicyGem policy = attempt.mappingMethod.getOptions().getMapper().typeConversionPolicy(); if ( policy == ReportingPolicyGem.WARN ) { report( messager, attempt, Message.CONVERSION_LOSSY_WARNING ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java index 5e1972fcae..411e11bf9e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/version/VersionInformation.java @@ -21,6 +21,8 @@ public interface VersionInformation { boolean isSourceVersionAtLeast9(); + boolean isSourceVersionAtLeast11(); + boolean isSourceVersionAtLeast19(); boolean isEclipseJDTCompiler(); diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl index 059e2d77d4..4ad6ae20db 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/BeanMappingMethod.ftl @@ -21,14 +21,22 @@ <#list beforeMappingReferencesWithFinalizedReturnType as callback> - <@includeModel object=callback targetBeanName=finalizedResultName targetType=returnType/> + <@includeModel object=callback targetBeanName=finalizedResultName targetType=finalizedReturnType/> <#if !callback_has_next> <#if !mapNullToDefault && !sourcePresenceChecks.empty> if ( <#list sourcePresenceChecks as sourcePresenceCheck><@includeModel object=sourcePresenceCheck.negate() /><#if sourcePresenceCheck_has_next> && ) { - return<#if returnType.name != "void"> <#if existingInstanceMapping>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /><#else>null; + <#if returnType.name == "void"> + return; + <#else> + <#if existingInstanceMapping> + <@createReturn applyOptionalAfterMapping=false>${resultName}<#if finalizerMethod??>.<@includeModel object=finalizerMethod /> + <#else> + return ${returnType.null}; + + } @@ -52,6 +60,11 @@ <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; if ( <@includeModel object=getPresenceCheckByParameter(sourceParam) /> ) { + <#assign sourceParamReassignment = getSourceParameterReassignment(sourceParam)!'' /> + <#if sourceParamReassignment?has_content> + <@includeModel object=sourceParamReassignment.type /> ${sourceParamReassignment.name} = ${sourceParam.name}.get(); + + <#list constructorPropertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -71,6 +84,11 @@ <@includeModel object=propertyMapping.targetType /> ${propertyMapping.targetWriteAccessorName} = ${propertyMapping.targetType.null}; <#if mapNullToDefault>if ( <@includeModel object=getPresenceCheckByParameter(sourceParameters[0]) /> ) { + <#assign sourceParamReassignment = getSourceParameterReassignment(sourceParameters[0])!'' /> + <#if sourceParamReassignment?has_content> + <@includeModel object=sourceParamReassignment.type /> ${sourceParamReassignment.name} = ${sourceParameters[0].name}.get(); + + <#list constructorPropertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -102,6 +120,11 @@ <#list sourceParametersNeedingPresenceCheck as sourceParam> <#if (propertyMappingsByParameter(sourceParam)?size > 0)> if ( <@includeModel object=getPresenceCheckByParameter(sourceParam) /> ) { + <#assign sourceParamReassignment = getSourceParameterReassignment(sourceParam)!'' /> + <#if sourceParamReassignment?has_content> + <@includeModel object=sourceParamReassignment.type /> ${sourceParamReassignment.name} = ${sourceParam.name}.get(); + + <#list propertyMappingsByParameter(sourceParam) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -117,6 +140,11 @@ <#elseif !propertyMappingsByParameter(sourceParameters[0]).empty> <#if mapNullToDefault>if ( <@includeModel object=getPresenceCheckByParameter(sourceParameters[0]) /> ) { + <#assign sourceParamReassignment = getSourceParameterReassignment(sourceParameters[0])!'' /> + <#if sourceParamReassignment?has_content> + <@includeModel object=sourceParamReassignment.type /> ${sourceParamReassignment.name} = ${sourceParameters[0].name}.get(); + + <#list propertyMappingsByParameter(sourceParameters[0]) as propertyMapping> <@includeModel object=propertyMapping targetBeanName=resultName existingInstanceMapping=existingInstanceMapping defaultValueAssignment=propertyMapping.defaultValueAssignment/> @@ -133,24 +161,24 @@ <#if returnType.name != "void"> - <#if finalizerMethod??> - <#if (afterMappingReferencesWithFinalizedReturnType?size > 0)> - <@includeModel object=returnType /> ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; + <#if finalizerMethod??> + <#if (afterMappingReferencesWithFinalizedReturnType?size > 0)> + <@includeModel object=finalizedReturnType /> ${finalizedResultName} = ${resultName}.<@includeModel object=finalizerMethod />; - <#list afterMappingReferencesWithFinalizedReturnType as callback> - <#if callback_index = 0> + <#list afterMappingReferencesWithFinalizedReturnType as callback> + <#if callback_index = 0> - - <@includeModel object=callback targetBeanName=finalizedResultName targetType=returnType/> - + + <@includeModel object=callback targetBeanName=finalizedResultName targetType=finalizedReturnType/> + - return ${finalizedResultName}; + <@createReturn>${finalizedResultName} + <#else> + <@createReturn>${resultName}.<@includeModel object=finalizerMethod /> + <#else> - return ${resultName}.<@includeModel object=finalizerMethod />; + <@createReturn>${resultName} - <#else> - return ${resultName}; - <#if hasSubclassMappings()> @@ -164,4 +192,27 @@ <#if exceptionType_has_next>, <#t> + +<#macro createReturn applyOptionalAfterMapping=true> +<#-- <@compress single_line=true>--> + <#if returnType.optionalType> + <#if (afterMappingReferencesWithOptionalReturnType?size > 0)> + <@includeModel object=returnType /> ${optionalResultName} = <@includeModel object=returnType.asRawType()/>.of( <#nested/> ); + + <#list afterMappingReferencesWithOptionalReturnType as callback> + <#if callback_index = 0> + + + <@includeModel object=callback targetBeanName=optionalResultName targetType=returnType/> + + + return ${optionalResultName}; + <#else> + return <@includeModel object=returnType.asRawType()/>.of( <#nested/> ); + + <#else> + return <#nested/>; + +<#-- --> + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.ftl new file mode 100644 index 0000000000..50ab97e5b4 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.ftl @@ -0,0 +1,16 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.FromOptionalTypeConversion" --> +<@includeModel object=assignment + targetBeanName=ext.targetBeanName + existingInstanceMapping=ext.existingInstanceMapping + targetReadAccessorName=ext.targetReadAccessorName + targetWriteAccessorName=ext.targetWriteAccessorName + sourcePropertyName=ext.sourcePropertyName + targetPropertyName=ext.targetPropertyName + targetType=ext.targetType/> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.ftl new file mode 100644 index 0000000000..48e20e7017 --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.ftl @@ -0,0 +1,21 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.ToOptionalTypeConversion" --> +<@compress single_line=true> +<@includeModel object=targetType.asRawType() />.of( <@_assignment/> ) +<#macro _assignment> + <@includeModel object=assignment + targetBeanName=ext.targetBeanName + existingInstanceMapping=ext.existingInstanceMapping + targetReadAccessorName=ext.targetReadAccessorName + targetWriteAccessorName=ext.targetWriteAccessorName + sourcePropertyName=ext.sourcePropertyName + targetPropertyName=ext.targetPropertyName + targetType=ext.targetType/> + + diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.ftl new file mode 100644 index 0000000000..7bbc089d7c --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.ftl @@ -0,0 +1,15 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.OptionalGetWrapper" --> +<@compress single_line=true> +<#if optionalType.optionalBaseType.isPrimitive()> +${assignment}.getAs${optionalType.optionalBaseType.name?cap_first}() +<#else> +${assignment}.get() + + \ No newline at end of file diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index ea8eed2438..d8ed4b53f6 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -6,6 +6,8 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.UpdateWrapper" --> +<#-- @ftlvariable name="ext" type="java.util.Map" --> +<#-- @ftlvariable name="ext.targetType" type="org.mapstruct.ap.internal.model.common.Type" --> <#import '../macro/CommonMacros.ftl' as lib > <@lib.handleExceptions> <#if includeSourceNullCheck> @@ -16,7 +18,7 @@ } <#if setExplicitlyToDefault || setExplicitlyToNull> else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>${ext.targetType.null}; } <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 278b441aa9..9c4ad26e03 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -13,6 +13,8 @@ requires: caller to implement boolean:getIncludeSourceNullCheck() --> +<#-- @ftlvariable name="ext" type="java.util.Map" --> +<#-- @ftlvariable name="ext.targetType" type="org.mapstruct.ap.internal.model.common.Type" --> <#macro handleSourceReferenceNullCheck> <#if sourcePresenceCheckerReference??> if ( <@includeModel object=sourcePresenceCheckerReference @@ -23,7 +25,7 @@ } <@elseDefaultAssignment/> <#elseif includeSourceNullCheck || ext.defaultValueAssignment??> - if ( <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference} != null ) { + if ( <#if sourceLocalVarName??>${sourceLocalVarName}<#else>${sourceReference}<#if sourceType.optionalType>.isPresent()<#else> != null ) { <#nested> } <@elseDefaultAssignment/> @@ -43,7 +45,7 @@ } <#elseif setExplicitlyToDefault || setExplicitlyToNull> else { - <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>null; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>${ext.targetType.null}; } @@ -156,7 +158,7 @@ Performs a default assignment with a default value. <#if factoryMethod??> <@includeModel object=factoryMethod targetType=ext.targetType/> <#else> - <@constructTargetObject/> + <@constructTargetObject targetType=ext.targetType/> <#-- @@ -164,15 +166,18 @@ Performs a default assignment with a default value. purpose: Either call the constructor of the target object directly or of the implementing type. --> -<#macro constructTargetObject><@compress single_line=true> - <#if ext.targetType.implementationType??> - new <@includeModel object=ext.targetType.implementationType/>() - <#elseif ext.targetType.arrayType> - new <@includeModel object=ext.targetType.componentType/>[0] - <#elseif ext.targetType.sensibleDefault??> - ${ext.targetType.sensibleDefault} +<#-- @ftlvariable name="targetType" type="org.mapstruct.ap.internal.model.common.Type" --> +<#macro constructTargetObject targetType><@compress single_line=true> + <#if targetType.implementationType??> + new <@includeModel object=targetType.implementationType/>() + <#elseif targetType.arrayType> + new <@includeModel object=targetType.componentType/>[0] + <#elseif targetType.sensibleDefault??> + ${targetType.sensibleDefault} + <#elseif targetType.optionalType> + <@includeModel object=targetType.asRawType()/>.of( <@constructTargetObject targetType=targetType.optionalBaseType/> ) <#else> - new <@includeModel object=ext.targetType/>() + new <@includeModel object=targetType/>() <#-- @@ -181,6 +186,7 @@ Performs a default assignment with a default value. purpose: assignment for source local variables. The sourceLocalVarName replaces the sourceReference in the assignmentcall. --> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.common.Assignment" --> <#macro sourceLocalVarAssignment> <#if sourceLocalVarName??> <@includeModel object=sourceType/> ${sourceLocalVarName} = ${sourceReference}; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.ftl new file mode 100644 index 0000000000..c321ce20ec --- /dev/null +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/presence/OptionalPresenceCheck.ftl @@ -0,0 +1,19 @@ +<#-- + + Copyright MapStruct Authors. + + Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + +--> +<#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.presence.OptionalPresenceCheck" --> +<@compress single_line=true> + <#if isNegate()> + <#if versionInformation.isSourceVersionAtLeast11()> + ${sourceReference}.isEmpty() + <#else> + !${sourceReference}.isPresent() + + <#else> + ${sourceReference}.isPresent() + + \ No newline at end of file diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerConversionTest.java new file mode 100644 index 0000000000..e1e557a897 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerConversionTest.java @@ -0,0 +1,73 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +import java.util.Optional; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +@WithClasses({ + OptionalEnumToIntegerSource.class, + EnumToIntegerTarget.class, + OptionalEnumToIntegerMapper.class, + EnumToIntegerEnum.class +}) +public class OptionalEnumToIntegerConversionTest { + + @ProcessorTest + public void shouldApplyEnumToIntegerConversion() { + OptionalEnumToIntegerSource source = new OptionalEnumToIntegerSource(); + + for ( EnumToIntegerEnum value : EnumToIntegerEnum.values() ) { + source.setEnumValue( Optional.of( value ) ); + + EnumToIntegerTarget target = OptionalEnumToIntegerMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getEnumValue() ).isEqualTo( value.ordinal() ); + } + } + + @ProcessorTest + public void shouldApplyReverseEnumToIntegerConversion() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + + EnumToIntegerEnum[] enumValues = EnumToIntegerEnum.values(); + int numberOfValues = enumValues.length; + for ( int value = 0; value < numberOfValues; value++ ) { + target.setEnumValue( value ); + + OptionalEnumToIntegerSource source = OptionalEnumToIntegerMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getEnumValue() ).contains( enumValues[target.getEnumValue()] ); + } + } + + @ProcessorTest + public void shouldHandleOutOfBoundsEnumOrdinal() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + target.setInvalidEnumValue( EnumToIntegerEnum.values().length + 1 ); + + assertThatThrownBy( () -> OptionalEnumToIntegerMapper.INSTANCE.targetToSource( target ) ) + .isInstanceOf( ArrayIndexOutOfBoundsException.class ); + } + + @ProcessorTest + public void shouldHandleNullIntegerValue() { + EnumToIntegerTarget target = new EnumToIntegerTarget(); + + OptionalEnumToIntegerSource source = OptionalEnumToIntegerMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getEnumValue() ).isEmpty(); + assertThat( source.getInvalidEnumValue() ).isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerMapper.java new file mode 100644 index 0000000000..d07d9b879c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface OptionalEnumToIntegerMapper { + OptionalEnumToIntegerMapper INSTANCE = Mappers.getMapper( OptionalEnumToIntegerMapper.class ); + + EnumToIntegerTarget sourceToTarget(OptionalEnumToIntegerSource source); + + OptionalEnumToIntegerSource targetToSource(EnumToIntegerTarget target); +} + diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerSource.java new file mode 100644 index 0000000000..700c3198bc --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/_enum/OptionalEnumToIntegerSource.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion._enum; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class OptionalEnumToIntegerSource { + private Optional enumValue = Optional.empty(); + + private Optional invalidEnumValue = Optional.empty(); + + public Optional getEnumValue() { + return enumValue; + } + + public void setEnumValue(Optional enumValue) { + this.enumValue = enumValue; + } + + public Optional getInvalidEnumValue() { + return invalidEnumValue; + } + + public void setInvalidEnumValue(Optional invalidEnumValue) { + this.invalidEnumValue = invalidEnumValue; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalMapper.java new file mode 100644 index 0000000000..986de6a0ed --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.bignumbers; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BigDecimalOptionalMapper { + + BigDecimalOptionalMapper INSTANCE = Mappers.getMapper( BigDecimalOptionalMapper.class ); + + BigDecimalTarget sourceToTarget(BigDecimalOptionalSource source); + + BigDecimalOptionalSource targetToSource(BigDecimalTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalSource.java new file mode 100644 index 0000000000..bf4e53e5d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigDecimalOptionalSource.java @@ -0,0 +1,139 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.bignumbers; + +import java.math.BigDecimal; +import java.util.Optional; + +public class BigDecimalOptionalSource { + + private Optional b; + private Optional bb; + private Optional s; + private Optional ss; + private Optional i; + private Optional ii; + private Optional l; + private Optional ll; + private Optional f; + private Optional ff; + private Optional d; + private Optional dd; + private Optional string; + private Optional bigInteger; + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } + + public Optional getString() { + return string; + } + + public void setString(Optional string) { + this.string = string; + } + + public Optional getBigInteger() { + return bigInteger; + } + + public void setBigInteger(Optional bigInteger) { + this.bigInteger = bigInteger; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalMapper.java new file mode 100644 index 0000000000..d39b48c7e5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.bignumbers; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BigIntegerOptionalMapper { + + BigIntegerOptionalMapper INSTANCE = Mappers.getMapper( BigIntegerOptionalMapper.class ); + + BigIntegerTarget sourceToTarget(BigIntegerOptionalSource source); + + BigIntegerOptionalSource targetToSource(BigIntegerTarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalSource.java new file mode 100644 index 0000000000..f4bb0f03c8 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigIntegerOptionalSource.java @@ -0,0 +1,131 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.bignumbers; + +import java.math.BigInteger; +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class BigIntegerOptionalSource { + + private Optional b; + private Optional bb; + private Optional s; + private Optional ss; + private Optional i; + private Optional ii; + private Optional l; + private Optional ll; + private Optional f; + private Optional ff; + private Optional d; + private Optional dd; + private Optional string; + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } + + public Optional getString() { + return string; + } + + public void setString(Optional string) { + this.string = string; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java index 69f87f3980..2ddddec02e 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/bignumbers/BigNumbersConversionTest.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.util.Optional; import org.junit.jupiter.api.extension.RegisterExtension; import org.mapstruct.ap.testutil.IssueKey; @@ -100,6 +101,79 @@ public void shouldApplyReverseBigIntegerConversions() { assertThat( source.getString() ).isEqualTo( new BigInteger( "13" ) ); } + @ProcessorTest + @WithClasses({ BigIntegerOptionalSource.class, BigIntegerTarget.class, BigIntegerOptionalMapper.class }) + public void shouldApplyOptionalBigIntegerConversions() { + BigIntegerOptionalSource source = new BigIntegerOptionalSource(); + source.setB( Optional.of( new BigInteger( "1" ) ) ); + source.setBb( Optional.of( new BigInteger( "2" ) ) ); + source.setS( Optional.of( new BigInteger( "3" ) ) ); + source.setSs( Optional.of( new BigInteger( "4" ) ) ); + source.setI( Optional.of( new BigInteger( "5" ) ) ); + source.setIi( Optional.of( new BigInteger( "6" ) ) ); + source.setL( Optional.of( new BigInteger( "7" ) ) ); + source.setLl( Optional.of( new BigInteger( "8" ) ) ); + source.setF( Optional.of( new BigInteger( "9" ) ) ); + source.setFf( Optional.of( new BigInteger( "10" ) ) ); + source.setD( Optional.of( new BigInteger( "11" ) ) ); + source.setDd( Optional.of( new BigInteger( "12" ) ) ); + source.setString( Optional.of( new BigInteger( "13" ) ) ); + + BigIntegerTarget target = BigIntegerOptionalMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( (byte) 2 ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( (short) 4 ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( 6 ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( 8 ); + assertThat( target.getF() ).isEqualTo( 9.0f ); + assertThat( target.getFf() ).isEqualTo( 10.0f ); + assertThat( target.getD() ).isEqualTo( 11.0d ); + assertThat( target.getDd() ).isEqualTo( 12.0d ); + assertThat( target.getString() ).isEqualTo( "13" ); + } + + @ProcessorTest + @IssueKey("21") + @WithClasses({ BigIntegerOptionalSource.class, BigIntegerTarget.class, BigIntegerOptionalMapper.class }) + public void shouldApplyReverseOptionalBigIntegerConversions() { + BigIntegerTarget target = new BigIntegerTarget(); + target.setB( (byte) 1 ); + target.setBb( (byte) 2 ); + target.setS( (short) 3 ); + target.setSs( (short) 4 ); + target.setI( 5 ); + target.setIi( 6 ); + target.setL( 7 ); + target.setLl( 8L ); + target.setF( 9.0f ); + target.setFf( 10.0f ); + target.setD( 11.0d ); + target.setDd( 12.0d ); + target.setString( "13" ); + + BigIntegerOptionalSource source = BigIntegerOptionalMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getB() ).contains( new BigInteger( "1" ) ); + assertThat( source.getBb() ).contains( new BigInteger( "2" ) ); + assertThat( source.getS() ).contains( new BigInteger( "3" ) ); + assertThat( source.getSs() ).contains( new BigInteger( "4" ) ); + assertThat( source.getI() ).contains( new BigInteger( "5" ) ); + assertThat( source.getIi() ).contains( new BigInteger( "6" ) ); + assertThat( source.getL() ).contains( new BigInteger( "7" ) ); + assertThat( source.getLl() ).contains( new BigInteger( "8" ) ); + assertThat( source.getF() ).contains( new BigInteger( "9" ) ); + assertThat( source.getFf() ).contains( new BigInteger( "10" ) ); + assertThat( source.getD() ).contains( new BigInteger( "11" ) ); + assertThat( source.getDd() ).contains( new BigInteger( "12" ) ); + assertThat( source.getString() ).contains( new BigInteger( "13" ) ); + } + @ProcessorTest @IssueKey("21") @WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class }) @@ -178,6 +252,82 @@ public void shouldApplyReverseBigDecimalConversions() { assertThat( source.getBigInteger() ).isEqualTo( new BigDecimal( "14" ) ); } + @ProcessorTest + @WithClasses({ BigDecimalOptionalSource.class, BigDecimalTarget.class, BigDecimalOptionalMapper.class }) + public void shouldApplyOptionalBigDecimalConversions() { + BigDecimalOptionalSource source = new BigDecimalOptionalSource(); + source.setB( Optional.of( new BigDecimal( "1.45" ) ) ); + source.setBb( Optional.of( new BigDecimal( "2.45" ) ) ); + source.setS( Optional.of( new BigDecimal( "3.45" ) ) ); + source.setSs( Optional.of( new BigDecimal( "4.45" ) ) ); + source.setI( Optional.of( new BigDecimal( "5.45" ) ) ); + source.setIi( Optional.of( new BigDecimal( "6.45" ) ) ); + source.setL( Optional.of( new BigDecimal( "7.45" ) ) ); + source.setLl( Optional.of( new BigDecimal( "8.45" ) ) ); + source.setF( Optional.of( new BigDecimal( "9.45" ) ) ); + source.setFf( Optional.of( new BigDecimal( "10.45" ) ) ); + source.setD( Optional.of( new BigDecimal( "11.45" ) ) ); + source.setDd( Optional.of( new BigDecimal( "12.45" ) ) ); + source.setString( Optional.of( new BigDecimal( "13.45" ) ) ); + source.setBigInteger( Optional.of( new BigDecimal( "14.45" ) ) ); + + BigDecimalTarget target = BigDecimalOptionalMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( (byte) 2 ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( (short) 4 ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( 6 ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( 8 ); + assertThat( target.getF() ).isEqualTo( 9.45f ); + assertThat( target.getFf() ).isEqualTo( 10.45f ); + assertThat( target.getD() ).isEqualTo( 11.45d ); + assertThat( target.getDd() ).isEqualTo( 12.45d ); + assertThat( target.getString() ).isEqualTo( "13.45" ); + assertThat( target.getBigInteger() ).isEqualTo( new BigInteger( "14" ) ); + } + + @ProcessorTest + @WithClasses({ BigDecimalOptionalSource.class, BigDecimalTarget.class, BigDecimalOptionalMapper.class }) + public void shouldApplyReverseOptionalBigDecimalConversions() { + BigDecimalTarget target = new BigDecimalTarget(); + target.setB( (byte) 1 ); + target.setBb( (byte) 2 ); + target.setS( (short) 3 ); + target.setSs( (short) 4 ); + target.setI( 5 ); + target.setIi( 6 ); + target.setL( 7 ); + target.setLl( 8L ); + target.setF( 9.0f ); + target.setFf( 10.0f ); + target.setD( 11.0d ); + target.setDd( 12.0d ); + target.setString( "13.45" ); + target.setBigInteger( new BigInteger( "14" ) ); + + BigDecimalOptionalSource source = BigDecimalOptionalMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getB() ).contains( new BigDecimal( "1" ) ); + assertThat( source.getBb() ).contains( new BigDecimal( "2" ) ); + assertThat( source.getS() ).contains( new BigDecimal( "3" ) ); + assertThat( source.getSs() ).contains( new BigDecimal( "4" ) ); + assertThat( source.getI() ).contains( new BigDecimal( "5" ) ); + assertThat( source.getIi() ).contains( new BigDecimal( "6" ) ); + assertThat( source.getL() ).contains( new BigDecimal( "7" ) ); + assertThat( source.getLl() ).contains( new BigDecimal( "8" ) ); + assertThat( source.getF() ).contains( new BigDecimal( "9.0" ) ); + assertThat( source.getFf() ).contains( new BigDecimal( "10.0" ) ); + assertThat( source.getD() ).contains( new BigDecimal( "11.0" ) ); + assertThat( source.getDd() ).contains( new BigDecimal( "12.0" ) ); + assertThat( source.getString() ).contains( new BigDecimal( "13.45" ) ); + assertThat( source.getBigInteger() ).contains( new BigDecimal( "14" ) ); + } + @ProcessorTest @IssueKey("1009") @WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class }) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8OptionalTimeConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8OptionalTimeConversionTest.java new file mode 100644 index 0000000000..1a9bb50b67 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/Java8OptionalTimeConversionTest.java @@ -0,0 +1,466 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Date; +import java.util.Optional; +import java.util.TimeZone; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junitpioneer.jupiter.DefaultTimeZone; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for conversions to/from Java 8 date and time types wrapped in {@link Optional}. + */ +@WithClasses({ OptionalSource.class, Target.class, OptionalSourceTargetMapper.class }) +public class Java8OptionalTimeConversionTest { + + @RegisterExtension + GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void generatedCode() { + generatedSource.addComparisonToFixtureFor( OptionalSourceTargetMapper.class ); + } + + @ProcessorTest + public void testDateTimeToString() { + OptionalSource src = new OptionalSource(); + src.setZonedDateTime( Optional.of( ZonedDateTime.of( + LocalDateTime.of( 2014, 1, 1, 0, 0 ), + ZoneId.of( "UTC" ) + ) ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDateTimeMapped( src ); + assertThat( target ).isNotNull(); + assertThat( target.getZonedDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); + } + + @ProcessorTest + public void testLocalDateTimeToString() { + OptionalSource src = new OptionalSource(); + src.setLocalDateTime( Optional.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetLocalDateTimeMapped( src ); + assertThat( target ).isNotNull(); + assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); + } + + @ProcessorTest + public void testLocalDateToString() { + OptionalSource src = new OptionalSource(); + src.setLocalDate( Optional.of( LocalDate.of( 2014, 1, 1 ) ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetLocalDateMapped( src ); + assertThat( target ).isNotNull(); + assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); + } + + @ProcessorTest + public void testLocalTimeToString() { + OptionalSource src = new OptionalSource(); + src.setLocalTime( Optional.ofNullable( LocalTime.of( 0, 0 ) ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetLocalTimeMapped( src ); + assertThat( target ).isNotNull(); + assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); + } + + @ProcessorTest + public void testSourceToTargetMappingForStrings() { + OptionalSource src = new OptionalSource(); + src.setLocalTime( Optional.ofNullable( LocalTime.of( 0, 0 ) ) ); + src.setLocalDate( Optional.of( LocalDate.of( 2014, 1, 1 ) ) ); + src.setLocalDateTime( Optional.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ) ); + src.setZonedDateTime( Optional.of( ZonedDateTime.of( + LocalDateTime.of( 2014, 1, 1, 0, 0 ), + ZoneId.of( "UTC" ) + ) ) ); + + // with given format + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( src ); + + assertThat( target ).isNotNull(); + assertThat( target.getZonedDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); + assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); + assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); + assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); + + // and now with default mappings + target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( src ); + assertThat( target ).isNotNull(); + assertThat( target.getZonedDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); + assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); + assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); + assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); + } + + @ProcessorTest + public void testStringToDateTime() { + String dateTimeAsString = "01.01.2014 00:00 UTC"; + Target target = new Target(); + target.setZonedDateTime( dateTimeAsString ); + ZonedDateTime sourceDateTime = + ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); + + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSourceDateTimeMapped( target ); + assertThat( src ).isNotNull(); + assertThat( src.getZonedDateTime() ).contains( sourceDateTime ); + } + + @ProcessorTest + public void testStringToLocalDateTime() { + String dateTimeAsString = "01.01.2014 00:00"; + Target target = new Target(); + target.setLocalDateTime( dateTimeAsString ); + LocalDateTime sourceDateTime = + LocalDateTime.of( 2014, 1, 1, 0, 0, 0 ); + + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSourceLocalDateTimeMapped( target ); + assertThat( src ).isNotNull(); + assertThat( src.getLocalDateTime() ).contains( sourceDateTime ); + } + + @ProcessorTest + public void testStringToLocalDate() { + String dateTimeAsString = "01.01.2014"; + Target target = new Target(); + target.setLocalDate( dateTimeAsString ); + LocalDate sourceDate = + LocalDate.of( 2014, 1, 1 ); + + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSourceLocalDateMapped( target ); + assertThat( src ).isNotNull(); + assertThat( src.getLocalDate() ).contains( sourceDate ); + } + + @ProcessorTest + public void testStringToLocalTime() { + String dateTimeAsString = "00:00"; + Target target = new Target(); + target.setLocalTime( dateTimeAsString ); + LocalTime sourceTime = + LocalTime.of( 0, 0 ); + + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSourceLocalTimeMapped( target ); + assertThat( src ).isNotNull(); + assertThat( src.getLocalTime() ).contains( sourceTime ); + } + + @ProcessorTest + public void testTargetToSourceNullMapping() { + Target target = new Target(); + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( src ).isNotNull(); + assertThat( src.getZonedDateTime() ).isEmpty(); + assertThat( src.getLocalDate() ).isEmpty(); + assertThat( src.getLocalDateTime() ).isEmpty(); + assertThat( src.getLocalTime() ).isEmpty(); + } + + @ProcessorTest + public void testTargetToSourceMappingForStrings() { + Target target = new Target(); + + target.setZonedDateTime( "01.01.2014 00:00 UTC" ); + target.setLocalDateTime( "01.01.2014 00:00" ); + target.setLocalDate( "01.01.2014" ); + target.setLocalTime( "00:00" ); + + OptionalSource src = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( src.getZonedDateTime() ).contains( + ZonedDateTime.of( + LocalDateTime.of( + 2014, + 1, + 1, + 0, + 0 + ), ZoneId.of( "UTC" ) + ) ); + assertThat( src.getLocalDateTime() ).contains( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ); + assertThat( src.getLocalDate() ).contains( LocalDate.of( 2014, 1, 1 ) ); + assertThat( src.getLocalTime() ).contains( LocalTime.of( 0, 0 ) ); + } + + @ProcessorTest + public void testCalendarMapping() { + OptionalSource source = new OptionalSource(); + ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); + source.setForCalendarConversion( Optional.of( dateTime ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target.getForCalendarConversion() ).isNotNull(); + assertThat( target.getForCalendarConversion().getTimeZone() ).isEqualTo( + TimeZone.getTimeZone( + "UTC" ) ); + assertThat( target.getForCalendarConversion().get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() ); + assertThat( target.getForCalendarConversion().get( Calendar.MONTH ) ).isEqualTo( + dateTime.getMonthValue() - 1 ); + assertThat( target.getForCalendarConversion().get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() ); + assertThat( target.getForCalendarConversion().get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() ); + assertThat( target.getForCalendarConversion().get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForCalendarConversion() ).contains( dateTime ); + } + + @ProcessorTest + @DefaultTimeZone("UTC") + public void testZonedDateTimeToDateMapping() { + OptionalSource source = new OptionalSource(); + ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) ); + source.setForDateConversionWithZonedDateTime( Optional.of( dateTime ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + + assertThat( target.getForDateConversionWithZonedDateTime() ).isNotNull(); + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); + instance.setTimeInMillis( target.getForDateConversionWithZonedDateTime().getTime() ); + + assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() ); + assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( dateTime.getMonthValue() - 1 ); + assertThat( instance.get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() ); + assertThat( instance.get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() ); + assertThat( instance.get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForDateConversionWithZonedDateTime() ).contains( dateTime ); + } + + @ProcessorTest + public void testInstantToDateMapping() { + Instant instant = Instant.ofEpochMilli( 1539366615000L ); + + OptionalSource source = new OptionalSource(); + source.setForDateConversionWithInstant( Optional.ofNullable( instant ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + Date date = target.getForDateConversionWithInstant(); + assertThat( date ).isNotNull(); + assertThat( date.getTime() ).isEqualTo( 1539366615000L ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForDateConversionWithInstant() ).contains( instant ); + } + + @ProcessorTest + public void testLocalDateTimeToLocalDateMapping() { + LocalDate localDate = LocalDate.of( 2014, 1, 1 ); + + OptionalSource source = new OptionalSource(); + source.setForLocalDateTimeConversionWithLocalDate( Optional.of( localDate ) ); + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + LocalDateTime localDateTime = target.getForLocalDateTimeConversionWithLocalDate(); + assertThat( localDateTime ).isNotNull(); + assertThat( localDateTime ).isEqualTo( LocalDateTime.of( 2014, 1, 1, 0, 0 ) ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForLocalDateTimeConversionWithLocalDate() ).contains( localDate ); + } + + @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") + public void testLocalDateTimeToDateMapping() { + + OptionalSource source = new OptionalSource(); + LocalDateTime dateTime = LocalDateTime.of( 2014, 1, 1, 0, 0 ); + source.setForDateConversionWithLocalDateTime( Optional.of( dateTime ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + + assertThat( target.getForDateConversionWithLocalDateTime() ).isNotNull(); + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); + instance.setTimeInMillis( target.getForDateConversionWithLocalDateTime().getTime() ); + + assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() ); + assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( dateTime.getMonthValue() - 1 ); + assertThat( instance.get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() ); + assertThat( instance.get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() ); + assertThat( instance.get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForDateConversionWithLocalDateTime() ).contains( dateTime ); + } + + @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") + public void testLocalDateToDateMapping() { + + OptionalSource source = new OptionalSource(); + LocalDate localDate = LocalDate.of( 2016, 3, 1 ); + source.setForDateConversionWithLocalDate( Optional.of( localDate ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + + assertThat( target.getForDateConversionWithLocalDate() ).isNotNull(); + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); + instance.setTimeInMillis( target.getForDateConversionWithLocalDate().getTime() ); + + assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( localDate.getYear() ); + assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( localDate.getMonthValue() - 1 ); + assertThat( instance.get( Calendar.DATE ) ).isEqualTo( localDate.getDayOfMonth() ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForDateConversionWithLocalDate() ).contains( localDate ); + } + + @ProcessorTest + @DefaultTimeZone("Australia/Melbourne") + public void testLocalDateToSqlDateMapping() { + + OptionalSource source = new OptionalSource(); + LocalDate localDate = LocalDate.of( 2016, 3, 1 ); + source.setForSqlDateConversionWithLocalDate( Optional.of( localDate ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source ); + + assertThat( target.getForSqlDateConversionWithLocalDate() ).isNotNull(); + + Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ); + instance.setTimeInMillis( target.getForSqlDateConversionWithLocalDate().getTime() ); + + assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( localDate.getYear() ); + assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( localDate.getMonthValue() - 1 ); + assertThat( instance.get( Calendar.DATE ) ).isEqualTo( localDate.getDayOfMonth() ); + + source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + + assertThat( source.getForSqlDateConversionWithLocalDate() ).contains( localDate ); + } + + @ProcessorTest + public void testInstantToStringMapping() { + OptionalSource source = new OptionalSource(); + source.setForInstantConversionWithString( Optional.ofNullable( Instant.ofEpochSecond( 42L ) ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForInstantConversionWithString(); + assertThat( periodString ).isEqualTo( "1970-01-01T00:00:42Z" ); + } + + @ProcessorTest + public void testInstantToStringNullMapping() { + OptionalSource source = new OptionalSource(); + source.setForInstantConversionWithString( Optional.empty() ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForInstantConversionWithString(); + assertThat( periodString ).isNull(); + } + + @ProcessorTest + public void testStringToInstantMapping() { + Target target = new Target(); + target.setForInstantConversionWithString( "1970-01-01T00:00:00.000Z" ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForInstantConversionWithString() ).contains( Instant.EPOCH ); + } + + @ProcessorTest + public void testStringToInstantNullMapping() { + Target target = new Target(); + target.setForInstantConversionWithString( null ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForInstantConversionWithString() ).isEmpty(); + } + + @ProcessorTest + public void testPeriodToStringMapping() { + OptionalSource source = new OptionalSource(); + source.setForPeriodConversionWithString( Optional.ofNullable( Period.ofDays( 42 ) ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForPeriodConversionWithString(); + assertThat( periodString ).isEqualTo( "P42D" ); + } + + @ProcessorTest + public void testPeriodToStringNullMapping() { + OptionalSource source = new OptionalSource(); + source.setForPeriodConversionWithString( Optional.empty() ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String periodString = target.getForPeriodConversionWithString(); + assertThat( periodString ).isNull(); + } + + @ProcessorTest + public void testStringToPeriodMapping() { + Target target = new Target(); + target.setForPeriodConversionWithString( "P1Y2M3D" ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForPeriodConversionWithString() ).contains( Period.of( 1, 2, 3 ) ); + } + + @ProcessorTest + public void testStringToPeriodNullMapping() { + Target target = new Target(); + target.setForPeriodConversionWithString( null ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForPeriodConversionWithString() ).isEmpty(); + } + + @ProcessorTest + public void testDurationToStringMapping() { + OptionalSource source = new OptionalSource(); + source.setForDurationConversionWithString( Optional.ofNullable( Duration.ofMinutes( 42L ) ) ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String durationString = target.getForDurationConversionWithString(); + assertThat( durationString ).isEqualTo( "PT42M" ); + } + + @ProcessorTest + public void testDurationToStringNullMapping() { + OptionalSource source = new OptionalSource(); + source.setForDurationConversionWithString( Optional.empty() ); + + Target target = OptionalSourceTargetMapper.INSTANCE.sourceToTarget( source ); + String durationString = target.getForDurationConversionWithString(); + assertThat( durationString ).isNull(); + } + + @ProcessorTest + public void testStringToDurationMapping() { + Target target = new Target(); + target.setForDurationConversionWithString( "PT20.345S" ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForDurationConversionWithString() ).contains( Duration.ofSeconds( 20L, 345000000L ) ); + } + + @ProcessorTest + public void testStringToDurationNullMapping() { + Target target = new Target(); + target.setForDurationConversionWithString( null ); + + OptionalSource source = OptionalSourceTargetMapper.INSTANCE.targetToSource( target ); + assertThat( source.getForDurationConversionWithString() ).isEmpty(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSource.java new file mode 100644 index 0000000000..cf94f31869 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSource.java @@ -0,0 +1,160 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Period; +import java.time.ZonedDateTime; +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class OptionalSource { + + private Optional zonedDateTime = Optional.empty(); + + private Optional localDateTime = Optional.empty(); + + private Optional localDate = Optional.empty(); + + private Optional localTime = Optional.empty(); + + private Optional forCalendarConversion = Optional.empty(); + + private Optional forDateConversionWithZonedDateTime = Optional.empty(); + + private Optional forDateConversionWithLocalDateTime = Optional.empty(); + + private Optional forDateConversionWithLocalDate = Optional.empty(); + + private Optional forSqlDateConversionWithLocalDate = Optional.empty(); + + private Optional forDateConversionWithInstant = Optional.empty(); + + private Optional forLocalDateTimeConversionWithLocalDate = Optional.empty(); + + private Optional forInstantConversionWithString = Optional.empty(); + + private Optional forPeriodConversionWithString = Optional.empty(); + + private Optional forDurationConversionWithString = Optional.empty(); + + public Optional getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(Optional dateTime) { + this.zonedDateTime = dateTime; + } + + public Optional getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(Optional localDateTime) { + this.localDateTime = localDateTime; + } + + public Optional getLocalDate() { + return localDate; + } + + public void setLocalDate(Optional localDate) { + this.localDate = localDate; + } + + public Optional getLocalTime() { + return localTime; + } + + public void setLocalTime(Optional localTime) { + this.localTime = localTime; + } + + public Optional getForCalendarConversion() { + return forCalendarConversion; + } + + public void setForCalendarConversion(Optional forCalendarConversion) { + this.forCalendarConversion = forCalendarConversion; + } + + public Optional getForDateConversionWithZonedDateTime() { + return forDateConversionWithZonedDateTime; + } + + public void setForDateConversionWithZonedDateTime(Optional forDateConversionWithZonedDateTime) { + this.forDateConversionWithZonedDateTime = forDateConversionWithZonedDateTime; + } + + public Optional getForDateConversionWithLocalDateTime() { + return forDateConversionWithLocalDateTime; + } + + public void setForDateConversionWithLocalDateTime(Optional forDateConversionWithLocalDateTime) { + this.forDateConversionWithLocalDateTime = forDateConversionWithLocalDateTime; + } + + public Optional getForDateConversionWithLocalDate() { + return forDateConversionWithLocalDate; + } + + public void setForDateConversionWithLocalDate(Optional forDateConversionWithLocalDate) { + this.forDateConversionWithLocalDate = forDateConversionWithLocalDate; + } + + public Optional getForSqlDateConversionWithLocalDate() { + return forSqlDateConversionWithLocalDate; + } + + public void setForSqlDateConversionWithLocalDate(Optional forSqlDateConversionWithLocalDate) { + this.forSqlDateConversionWithLocalDate = forSqlDateConversionWithLocalDate; + } + + public Optional getForDateConversionWithInstant() { + return forDateConversionWithInstant; + } + + public void setForDateConversionWithInstant(Optional forDateConversionWithInstant) { + this.forDateConversionWithInstant = forDateConversionWithInstant; + } + + public Optional getForLocalDateTimeConversionWithLocalDate() { + return forLocalDateTimeConversionWithLocalDate; + } + + public void setForLocalDateTimeConversionWithLocalDate( + Optional forLocalDateTimeConversionWithLocalDate) { + this.forLocalDateTimeConversionWithLocalDate = forLocalDateTimeConversionWithLocalDate; + } + + public Optional getForInstantConversionWithString() { + return forInstantConversionWithString; + } + + public void setForInstantConversionWithString(Optional forInstantConversionWithString) { + this.forInstantConversionWithString = forInstantConversionWithString; + } + + public Optional getForPeriodConversionWithString() { + return forPeriodConversionWithString; + } + + public void setForPeriodConversionWithString(Optional forPeriodConversionWithString) { + this.forPeriodConversionWithString = forPeriodConversionWithString; + } + + public Optional getForDurationConversionWithString() { + return forDurationConversionWithString; + } + + public void setForDurationConversionWithString(Optional forDurationConversionWithString) { + this.forDurationConversionWithString = forDurationConversionWithString; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSourceTargetMapper.java new file mode 100644 index 0000000000..a266309b61 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/java8time/OptionalSourceTargetMapper.java @@ -0,0 +1,70 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.java8time; + +import org.mapstruct.InheritInverseConfiguration; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface OptionalSourceTargetMapper { + + String DATE_TIME_FORMAT = "dd.MM.yyyy HH:mm z"; + + String LOCAL_DATE_TIME_FORMAT = "dd.MM.yyyy HH:mm"; + + String LOCAL_DATE_FORMAT = "dd.MM.yyyy"; + + String LOCAL_TIME_FORMAT = "HH:mm"; + + OptionalSourceTargetMapper INSTANCE = Mappers.getMapper( OptionalSourceTargetMapper.class ); + + @Mapping(target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT) + @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT) + @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT) + @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT) + Target sourceToTarget(OptionalSource source); + + @Mapping(target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT) + @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT) + @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT) + @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT) + Target sourceToTargetDefaultMapping(OptionalSource source); + + @Mapping(target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT) + Target sourceToTargetDateTimeMapped(OptionalSource source); + + @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT) + Target sourceToTargetLocalDateTimeMapped(OptionalSource source); + + @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT) + Target sourceToTargetLocalDateMapped(OptionalSource source); + + @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT) + Target sourceToTargetLocalTimeMapped(OptionalSource source); + + @Mapping(target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT) + @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT) + @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT) + @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT) + OptionalSource targetToSource(Target target); + + @Mapping(target = "zonedDateTime", dateFormat = DATE_TIME_FORMAT) + OptionalSource targetToSourceDateTimeMapped(Target target); + + @Mapping(target = "localDateTime", dateFormat = LOCAL_DATE_TIME_FORMAT) + OptionalSource targetToSourceLocalDateTimeMapped(Target target); + + @Mapping(target = "localDate", dateFormat = LOCAL_DATE_FORMAT) + OptionalSource targetToSourceLocalDateMapped(Target target); + + @Mapping(target = "localTime", dateFormat = LOCAL_TIME_FORMAT) + OptionalSource targetToSourceLocalTimeMapped(Target target); + + @InheritInverseConfiguration(name = "sourceToTarget") + OptionalSource targetToSourceDefaultMapping(Target target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper1.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper1.java new file mode 100644 index 0000000000..d83b368bce --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper1.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerOptionalMapper1 { + + ErroneousKitchenDrawerOptionalMapper1 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerOptionalMapper1.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfForks", source = "numberOfForks" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper3.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper3.java new file mode 100644 index 0000000000..7d1824a5b1 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper3.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR, uses = VerySpecialNumberMapper.class ) +public interface ErroneousKitchenDrawerOptionalMapper3 { + + ErroneousKitchenDrawerOptionalMapper3 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerOptionalMapper3.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfSpoons", source = "numberOfSpoons" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper4.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper4.java new file mode 100644 index 0000000000..edd33c71d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper4.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerOptionalMapper4 { + + ErroneousKitchenDrawerOptionalMapper4 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerOptionalMapper4.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "depth", source = "depth" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper5.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper5.java new file mode 100644 index 0000000000..bad921a7c2 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper5.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerOptionalMapper5 { + + ErroneousKitchenDrawerOptionalMapper5 INSTANCE = Mappers.getMapper( ErroneousKitchenDrawerOptionalMapper5.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "length", source = "length" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper6.java new file mode 100644 index 0000000000..acd2e0876f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/ErroneousKitchenDrawerOptionalMapper6.java @@ -0,0 +1,20 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; + +@Mapper( typeConversionPolicy = ReportingPolicy.ERROR ) +public interface ErroneousKitchenDrawerOptionalMapper6 { + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "drawerId", source = "drawerId" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper2.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper2.java new file mode 100644 index 0000000000..92862d3320 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper2.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.WARN ) +public interface KitchenDrawerOptionalMapper2 { + + KitchenDrawerOptionalMapper2 INSTANCE = Mappers.getMapper( KitchenDrawerOptionalMapper2.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "numberOfKnifes", source = "numberOfKnifes" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper6.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper6.java new file mode 100644 index 0000000000..2b3e982584 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/KitchenDrawerOptionalMapper6.java @@ -0,0 +1,23 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( typeConversionPolicy = ReportingPolicy.WARN, uses = VerySpecialNumberMapper.class ) +public interface KitchenDrawerOptionalMapper6 { + + KitchenDrawerOptionalMapper6 INSTANCE = Mappers.getMapper( KitchenDrawerOptionalMapper6.class ); + + @BeanMapping( ignoreByDefault = true ) + @Mapping( target = "height", source = "height" ) + RegularKitchenDrawerEntity map( OversizedKitchenDrawerOptionalDto dto ); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java index 629f727273..604ff9bffa 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/LossyConversionTest.java @@ -22,6 +22,7 @@ */ @WithClasses({ OversizedKitchenDrawerDto.class, + OversizedKitchenDrawerOptionalDto.class, RegularKitchenDrawerEntity.class, VerySpecialNumber.class, VerySpecialNumberMapper.class, @@ -63,6 +64,19 @@ public void testNoErrorCase() { public void testConversionFromLongToInt() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerOptionalMapper1.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerOptionalMapper1.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Can't map property \"OptionalLong numberOfForks\". It has a possibly lossy conversion from " + + "OptionalLong to int.") + }) + public void testConversionFromOptionalLongToInt() { + } + @ProcessorTest @WithClasses(KitchenDrawerMapper2.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, @@ -76,6 +90,19 @@ public void testConversionFromLongToInt() { public void testConversionFromBigIntegerToInteger() { } + @ProcessorTest + @WithClasses(KitchenDrawerOptionalMapper2.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = KitchenDrawerOptionalMapper2.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 20, + message = "property \"Optional numberOfKnifes\" has a possibly lossy conversion " + + "from Optional to Integer.") + }) + public void testConversionFromOptionalBigIntegerToInteger() { + } + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper6.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, @@ -89,6 +116,19 @@ public void testConversionFromBigIntegerToInteger() { public void testConversionFromStringToInt() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerOptionalMapper6.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerOptionalMapper6.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 17, + message = "Can't map property \"Optional drawerId\". It has a possibly lossy conversion from " + + "Optional to int.") + }) + public void testConversionFromOptionalStringToInt() { + } + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper3.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, @@ -102,6 +142,19 @@ public void testConversionFromStringToInt() { public void test2StepConversionFromBigIntegerToLong() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerOptionalMapper3.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerOptionalMapper3.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = "Can't map property \"Optional numberOfSpoons\". " + + "It has a possibly lossy conversion from BigInteger to Long.") + }) + public void test2StepConversionFromOptionalBigIntegerToLong() { + } + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper4.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, @@ -115,6 +168,20 @@ public void test2StepConversionFromBigIntegerToLong() { public void testConversionFromDoubleToFloat() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerOptionalMapper4.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerOptionalMapper4.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = + "Can't map property \"Optional depth\". " + + "It has a possibly lossy conversion from Optional to float.") + }) + public void testConversionFromOptionalDoubleToFloat() { + } + @ProcessorTest @WithClasses(ErroneousKitchenDrawerMapper5.class) @ExpectedCompilationOutcome(value = CompilationResult.FAILED, @@ -128,6 +195,20 @@ public void testConversionFromDoubleToFloat() { public void testConversionFromBigDecimalToFloat() { } + @ProcessorTest + @WithClasses(ErroneousKitchenDrawerOptionalMapper5.class) + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = ErroneousKitchenDrawerOptionalMapper5.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 20, + message = + "Can't map property \"Optional length\". " + + "It has a possibly lossy conversion from Optional to Float.") + }) + public void testConversionFromOptionalBigDecimalToFloat() { + } + @ProcessorTest @WithClasses(KitchenDrawerMapper6.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, @@ -140,6 +221,19 @@ public void testConversionFromBigDecimalToFloat() { public void test2StepConversionFromDoubleToFloat() { } + @ProcessorTest + @WithClasses(KitchenDrawerOptionalMapper6.class) + @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, + diagnostics = { + @Diagnostic(type = KitchenDrawerOptionalMapper6.class, + kind = javax.tools.Diagnostic.Kind.WARNING, + line = 20, + message = "property \"OptionalDouble height\" has a possibly lossy conversion from " + + "OptionalDouble to float.") + }) + public void test2StepConversionFromOptionalDoubleToFloat() { + } + @ProcessorTest @WithClasses(ListMapper.class) @ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerOptionalDto.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerOptionalDto.java new file mode 100644 index 0000000000..f214fecd1d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/OversizedKitchenDrawerOptionalDto.java @@ -0,0 +1,84 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.lossy; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalLong; + +/** + * @author Filip Hrisafov + */ +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class OversizedKitchenDrawerOptionalDto { + + /* yes, its a big drawer */ + private OptionalLong numberOfForks; + private Optional numberOfKnifes; + private Optional numberOfSpoons; + private Optional depth; + private Optional length; + private OptionalDouble height; + private Optional drawerId; + + public OptionalLong getNumberOfForks() { + return numberOfForks; + } + + public void setNumberOfForks(OptionalLong numberOfForks) { + this.numberOfForks = numberOfForks; + } + + public Optional getNumberOfKnifes() { + return numberOfKnifes; + } + + public void setNumberOfKnifes(Optional numberOfKnifes) { + this.numberOfKnifes = numberOfKnifes; + } + + public Optional getNumberOfSpoons() { + return numberOfSpoons; + } + + public void setNumberOfSpoons(Optional numberOfSpoons) { + this.numberOfSpoons = numberOfSpoons; + } + + public Optional getDepth() { + return depth; + } + + public void setDepth(Optional depth) { + this.depth = depth; + } + + public Optional getLength() { + return length; + } + + public void setLength(Optional length) { + this.length = length; + } + + public OptionalDouble getHeight() { + return height; + } + + public void setHeight(OptionalDouble height) { + this.height = height; + } + + public Optional getDrawerId() { + return drawerId; + } + + public void setDrawerId(Optional drawerId) { + this.drawerId = drawerId; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java index d49a263deb..00b543c728 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/lossy/VerySpecialNumberMapper.java @@ -6,6 +6,7 @@ package org.mapstruct.ap.test.conversion.lossy; import java.math.BigInteger; +import java.util.Optional; /** * @author Sjaak Derksen @@ -19,4 +20,9 @@ VerySpecialNumber fromFloat(float f) { BigInteger toBigInteger(VerySpecialNumber v) { return new BigInteger( "10" ); } + + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + BigInteger toBigInteger(Optional v) { + return new BigInteger( "10" ); + } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperOptionalSource.java new file mode 100644 index 0000000000..a92b029b14 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ByteWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class ByteWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleOptionalSource.java new file mode 100644 index 0000000000..e469c44390 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.OptionalDouble; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class DoubleOptionalSource { + + private OptionalDouble b = OptionalDouble.empty(); + private OptionalDouble bb = OptionalDouble.empty(); + private OptionalDouble s = OptionalDouble.empty(); + private OptionalDouble ss = OptionalDouble.empty(); + private OptionalDouble i = OptionalDouble.empty(); + private OptionalDouble ii = OptionalDouble.empty(); + private OptionalDouble l = OptionalDouble.empty(); + private OptionalDouble ll = OptionalDouble.empty(); + private OptionalDouble f = OptionalDouble.empty(); + private OptionalDouble ff = OptionalDouble.empty(); + private OptionalDouble d = OptionalDouble.empty(); + private OptionalDouble dd = OptionalDouble.empty(); + + public OptionalDouble getB() { + return b; + } + + public void setB(OptionalDouble b) { + this.b = b; + } + + public OptionalDouble getBb() { + return bb; + } + + public void setBb(OptionalDouble bb) { + this.bb = bb; + } + + public OptionalDouble getS() { + return s; + } + + public void setS(OptionalDouble s) { + this.s = s; + } + + public OptionalDouble getSs() { + return ss; + } + + public void setSs(OptionalDouble ss) { + this.ss = ss; + } + + public OptionalDouble getI() { + return i; + } + + public void setI(OptionalDouble i) { + this.i = i; + } + + public OptionalDouble getIi() { + return ii; + } + + public void setIi(OptionalDouble ii) { + this.ii = ii; + } + + public OptionalDouble getL() { + return l; + } + + public void setL(OptionalDouble l) { + this.l = l; + } + + public OptionalDouble getLl() { + return ll; + } + + public void setLl(OptionalDouble ll) { + this.ll = ll; + } + + public OptionalDouble getF() { + return f; + } + + public void setF(OptionalDouble f) { + this.f = f; + } + + public OptionalDouble getFf() { + return ff; + } + + public void setFf(OptionalDouble ff) { + this.ff = ff; + } + + public OptionalDouble getD() { + return d; + } + + public void setD(OptionalDouble d) { + this.d = d; + } + + public OptionalDouble getDd() { + return dd; + } + + public void setDd(OptionalDouble dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperOptionalSource.java new file mode 100644 index 0000000000..ecf0d9bc41 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/DoubleWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class DoubleWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperOptionalSource.java new file mode 100644 index 0000000000..f20e6fa5d9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/FloatWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class FloatWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntOptionalSource.java new file mode 100644 index 0000000000..6543b7bc0b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.OptionalInt; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class IntOptionalSource { + + private OptionalInt b = OptionalInt.empty(); + private OptionalInt bb = OptionalInt.empty(); + private OptionalInt s = OptionalInt.empty(); + private OptionalInt ss = OptionalInt.empty(); + private OptionalInt i = OptionalInt.empty(); + private OptionalInt ii = OptionalInt.empty(); + private OptionalInt l = OptionalInt.empty(); + private OptionalInt ll = OptionalInt.empty(); + private OptionalInt f = OptionalInt.empty(); + private OptionalInt ff = OptionalInt.empty(); + private OptionalInt d = OptionalInt.empty(); + private OptionalInt dd = OptionalInt.empty(); + + public OptionalInt getB() { + return b; + } + + public void setB(OptionalInt b) { + this.b = b; + } + + public OptionalInt getBb() { + return bb; + } + + public void setBb(OptionalInt bb) { + this.bb = bb; + } + + public OptionalInt getS() { + return s; + } + + public void setS(OptionalInt s) { + this.s = s; + } + + public OptionalInt getSs() { + return ss; + } + + public void setSs(OptionalInt ss) { + this.ss = ss; + } + + public OptionalInt getI() { + return i; + } + + public void setI(OptionalInt i) { + this.i = i; + } + + public OptionalInt getIi() { + return ii; + } + + public void setIi(OptionalInt ii) { + this.ii = ii; + } + + public OptionalInt getL() { + return l; + } + + public void setL(OptionalInt l) { + this.l = l; + } + + public OptionalInt getLl() { + return ll; + } + + public void setLl(OptionalInt ll) { + this.ll = ll; + } + + public OptionalInt getF() { + return f; + } + + public void setF(OptionalInt f) { + this.f = f; + } + + public OptionalInt getFf() { + return ff; + } + + public void setFf(OptionalInt ff) { + this.ff = ff; + } + + public OptionalInt getD() { + return d; + } + + public void setD(OptionalInt d) { + this.d = d; + } + + public OptionalInt getDd() { + return dd; + } + + public void setDd(OptionalInt dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperOptionalSource.java new file mode 100644 index 0000000000..b1243d9c1c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/IntWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class IntWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongOptionalSource.java new file mode 100644 index 0000000000..1df7baaec9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.OptionalLong; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class LongOptionalSource { + + private OptionalLong b = OptionalLong.empty(); + private OptionalLong bb = OptionalLong.empty(); + private OptionalLong s = OptionalLong.empty(); + private OptionalLong ss = OptionalLong.empty(); + private OptionalLong i = OptionalLong.empty(); + private OptionalLong ii = OptionalLong.empty(); + private OptionalLong l = OptionalLong.empty(); + private OptionalLong ll = OptionalLong.empty(); + private OptionalLong f = OptionalLong.empty(); + private OptionalLong ff = OptionalLong.empty(); + private OptionalLong d = OptionalLong.empty(); + private OptionalLong dd = OptionalLong.empty(); + + public OptionalLong getB() { + return b; + } + + public void setB(OptionalLong b) { + this.b = b; + } + + public OptionalLong getBb() { + return bb; + } + + public void setBb(OptionalLong bb) { + this.bb = bb; + } + + public OptionalLong getS() { + return s; + } + + public void setS(OptionalLong s) { + this.s = s; + } + + public OptionalLong getSs() { + return ss; + } + + public void setSs(OptionalLong ss) { + this.ss = ss; + } + + public OptionalLong getI() { + return i; + } + + public void setI(OptionalLong i) { + this.i = i; + } + + public OptionalLong getIi() { + return ii; + } + + public void setIi(OptionalLong ii) { + this.ii = ii; + } + + public OptionalLong getL() { + return l; + } + + public void setL(OptionalLong l) { + this.l = l; + } + + public OptionalLong getLl() { + return ll; + } + + public void setLl(OptionalLong ll) { + this.ll = ll; + } + + public OptionalLong getF() { + return f; + } + + public void setF(OptionalLong f) { + this.f = f; + } + + public OptionalLong getFf() { + return ff; + } + + public void setFf(OptionalLong ff) { + this.ff = ff; + } + + public OptionalLong getD() { + return d; + } + + public void setD(OptionalLong d) { + this.d = d; + } + + public OptionalLong getDd() { + return dd; + } + + public void setDd(OptionalLong dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperOptionalSource.java new file mode 100644 index 0000000000..bed8ab6b59 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/LongWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class LongWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberOptionalConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberOptionalConversionTest.java new file mode 100644 index 0000000000..0857b20473 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/NumberOptionalConversionTest.java @@ -0,0 +1,357 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; +import java.util.OptionalDouble; +import java.util.OptionalInt; +import java.util.OptionalLong; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + ByteTarget.class, + ByteWrapperOptionalSource.class, + ByteWrapperTarget.class, + ShortTarget.class, + ShortWrapperOptionalSource.class, + ShortWrapperTarget.class, + IntOptionalSource.class, + IntTarget.class, + IntWrapperOptionalSource.class, + IntWrapperTarget.class, + LongOptionalSource.class, + LongTarget.class, + LongWrapperOptionalSource.class, + LongWrapperTarget.class, + FloatWrapperOptionalSource.class, + FloatWrapperTarget.class, + DoubleOptionalSource.class, + DoubleTarget.class, + DoubleWrapperOptionalSource.class, + DoubleWrapperTarget.class, + OptionalNumberConversionMapper.class +}) +public class NumberOptionalConversionTest { + + @ProcessorTest + public void shouldApplyByteWrapperConversions() { + ByteWrapperOptionalSource source = new ByteWrapperOptionalSource(); + source.setB( Optional.of( (byte) 1 ) ); + source.setBb( Optional.of( (byte) 2 ) ); + source.setS( Optional.of( (byte) 3 ) ); + source.setSs( Optional.of( (byte) 4 ) ); + source.setI( Optional.of( (byte) 5 ) ); + source.setIi( Optional.of( (byte) 6 ) ); + source.setL( Optional.of( (byte) 7 ) ); + source.setLl( Optional.of( (byte) 8 ) ); + source.setF( Optional.of( (byte) 9 ) ); + source.setFf( Optional.of( (byte) 10 ) ); + source.setD( Optional.of( (byte) 11 ) ); + source.setDd( Optional.of( (byte) 12 ) ); + + ByteWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyShortWrapperConversions() { + ShortWrapperOptionalSource source = new ShortWrapperOptionalSource(); + source.setB( Optional.of( (short) 1 ) ); + source.setBb( Optional.of( (short) 2 ) ); + source.setS( Optional.of( (short) 3 ) ); + source.setSs( Optional.of( (short) 4 ) ); + source.setI( Optional.of( (short) 5 ) ); + source.setIi( Optional.of( (short) 6 ) ); + source.setL( Optional.of( (short) 7 ) ); + source.setLl( Optional.of( (short) 8 ) ); + source.setF( Optional.of( (short) 9 ) ); + source.setFf( Optional.of( (short) 10 ) ); + source.setD( Optional.of( (short) 11 ) ); + source.setDd( Optional.of( (short) 12 ) ); + + ShortWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyIntConversions() { + IntOptionalSource source = new IntOptionalSource(); + source.setB( OptionalInt.of( 1 ) ); + source.setBb( OptionalInt.of( 2 ) ); + source.setS( OptionalInt.of( 3 ) ); + source.setSs( OptionalInt.of( 4 ) ); + source.setI( OptionalInt.of( 5 ) ); + source.setIi( OptionalInt.of( 6 ) ); + source.setL( OptionalInt.of( 7 ) ); + source.setLl( OptionalInt.of( 8 ) ); + source.setF( OptionalInt.of( 9 ) ); + source.setFf( OptionalInt.of( 10 ) ); + source.setD( OptionalInt.of( 11 ) ); + source.setDd( OptionalInt.of( 12 ) ); + + IntTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyIntWrapperConversions() { + IntWrapperOptionalSource source = new IntWrapperOptionalSource(); + source.setB( Optional.of( 1 ) ); + source.setBb( Optional.of( 2 ) ); + source.setS( Optional.of( 3 ) ); + source.setSs( Optional.of( 4 ) ); + source.setI( Optional.of( 5 ) ); + source.setIi( Optional.of( 6 ) ); + source.setL( Optional.of( 7 ) ); + source.setLl( Optional.of( 8 ) ); + source.setF( Optional.of( 9 ) ); + source.setFf( Optional.of( 10 ) ); + source.setD( Optional.of( 11 ) ); + source.setDd( Optional.of( 12 ) ); + + IntWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyLongConversions() { + LongOptionalSource source = new LongOptionalSource(); + source.setB( OptionalLong.of( 1 ) ); + source.setBb( OptionalLong.of( 2 ) ); + source.setS( OptionalLong.of( 3 ) ); + source.setSs( OptionalLong.of( 4 ) ); + source.setI( OptionalLong.of( 5 ) ); + source.setIi( OptionalLong.of( 6 ) ); + source.setL( OptionalLong.of( 7 ) ); + source.setLl( OptionalLong.of( 8 ) ); + source.setF( OptionalLong.of( 9 ) ); + source.setFf( OptionalLong.of( 10 ) ); + source.setD( OptionalLong.of( 11 ) ); + source.setDd( OptionalLong.of( 12 ) ); + + LongTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyLongWrapperConversions() { + LongWrapperOptionalSource source = new LongWrapperOptionalSource(); + source.setB( Optional.of( (long) 1 ) ); + source.setBb( Optional.of( (long) 2 ) ); + source.setS( Optional.of( (long) 3 ) ); + source.setSs( Optional.of( (long) 4 ) ); + source.setI( Optional.of( (long) 5 ) ); + source.setIi( Optional.of( (long) 6 ) ); + source.setL( Optional.of( (long) 7 ) ); + source.setLl( Optional.of( (long) 8 ) ); + source.setF( Optional.of( (long) 9 ) ); + source.setFf( Optional.of( (long) 10 ) ); + source.setD( Optional.of( (long) 11 ) ); + source.setDd( Optional.of( (long) 12 ) ); + + LongWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyFloatWrapperConversions() { + FloatWrapperOptionalSource source = new FloatWrapperOptionalSource(); + source.setB( Optional.of( 1f ) ); + source.setBb( Optional.of( 2f ) ); + source.setS( Optional.of( 3f ) ); + source.setSs( Optional.of( 4f ) ); + source.setI( Optional.of( 5f ) ); + source.setIi( Optional.of( 6f ) ); + source.setL( Optional.of( 7f ) ); + source.setLl( Optional.of( 8f ) ); + source.setF( Optional.of( 9f ) ); + source.setFf( Optional.of( 10f ) ); + source.setD( Optional.of( 11f ) ); + source.setDd( Optional.of( 12f ) ); + + FloatWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyDoubleConversions() { + DoubleOptionalSource source = new DoubleOptionalSource(); + source.setB( OptionalDouble.of( 1 ) ); + source.setBb( OptionalDouble.of( 2 ) ); + source.setS( OptionalDouble.of( 3 ) ); + source.setSs( OptionalDouble.of( 4 ) ); + source.setI( OptionalDouble.of( 5 ) ); + source.setIi( OptionalDouble.of( 6 ) ); + source.setL( OptionalDouble.of( 7 ) ); + source.setLl( OptionalDouble.of( 8 ) ); + source.setF( OptionalDouble.of( 9 ) ); + source.setFf( OptionalDouble.of( 10 ) ); + source.setD( OptionalDouble.of( 11 ) ); + source.setDd( OptionalDouble.of( 12 ) ); + + DoubleTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + public void shouldApplyDoubleWrapperConversions() { + DoubleWrapperOptionalSource source = new DoubleWrapperOptionalSource(); + source.setB( Optional.of( 1d ) ); + source.setBb( Optional.of( 2d ) ); + source.setS( Optional.of( 3d ) ); + source.setSs( Optional.of( 4d ) ); + source.setI( Optional.of( 5d ) ); + source.setIi( Optional.of( 6d ) ); + source.setL( Optional.of( 7d ) ); + source.setLl( Optional.of( 8d ) ); + source.setF( Optional.of( 9d ) ); + source.setFf( Optional.of( 10d ) ); + source.setD( Optional.of( 11d ) ); + source.setDd( Optional.of( 12d ) ); + + DoubleWrapperTarget target = OptionalNumberConversionMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getB() ).isEqualTo( (byte) 1 ); + assertThat( target.getBb() ).isEqualTo( Byte.valueOf( (byte) 2 ) ); + assertThat( target.getS() ).isEqualTo( (short) 3 ); + assertThat( target.getSs() ).isEqualTo( Short.valueOf( (short) 4 ) ); + assertThat( target.getI() ).isEqualTo( 5 ); + assertThat( target.getIi() ).isEqualTo( Integer.valueOf( 6 ) ); + assertThat( target.getL() ).isEqualTo( 7 ); + assertThat( target.getLl() ).isEqualTo( Long.valueOf( 8 ) ); + assertThat( target.getF() ).isEqualTo( 9f ); + assertThat( target.getFf() ).isEqualTo( Float.valueOf( 10f ) ); + assertThat( target.getD() ).isEqualTo( 11d ); + assertThat( target.getDd() ).isEqualTo( Double.valueOf( 12d ) ); + } + + @ProcessorTest + @IssueKey("229") + public void wrapperToPrimitiveIsNullSafe() { + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new ByteWrapperOptionalSource() ) ) + .isNotNull(); + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new DoubleWrapperOptionalSource() ) ) + .isNotNull(); + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new ShortWrapperOptionalSource() ) ) + .isNotNull(); + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new IntWrapperOptionalSource() ) ) + .isNotNull(); + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new FloatWrapperOptionalSource() ) ) + .isNotNull(); + assertThat( OptionalNumberConversionMapper.INSTANCE.sourceToTarget( new LongWrapperOptionalSource() ) ) + .isNotNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/OptionalNumberConversionMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/OptionalNumberConversionMapper.java new file mode 100644 index 0000000000..94472586fa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/OptionalNumberConversionMapper.java @@ -0,0 +1,52 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface OptionalNumberConversionMapper { + + OptionalNumberConversionMapper INSTANCE = Mappers.getMapper( OptionalNumberConversionMapper.class ); + + ByteWrapperTarget sourceToTarget(ByteWrapperOptionalSource source); + + ByteWrapperOptionalSource targetToSource(ByteWrapperTarget target); + + ShortWrapperTarget sourceToTarget(ShortWrapperOptionalSource source); + + ShortWrapperOptionalSource targetToSource(ShortWrapperTarget target); + + IntTarget sourceToTarget(IntOptionalSource source); + + IntOptionalSource targetToSource(IntTarget target); + + IntWrapperTarget sourceToTarget(IntWrapperOptionalSource source); + + IntWrapperOptionalSource targetToSource(IntWrapperTarget target); + + LongTarget sourceToTarget(LongOptionalSource source); + + LongOptionalSource targetToSource(LongTarget target); + + LongWrapperTarget sourceToTarget(LongWrapperOptionalSource source); + + LongWrapperOptionalSource targetToSource(LongWrapperTarget target); + + FloatWrapperTarget sourceToTarget(FloatWrapperOptionalSource source); + + FloatWrapperOptionalSource targetToSource(FloatWrapperTarget target); + + DoubleTarget sourceToTarget(DoubleOptionalSource source); + + DoubleOptionalSource targetToSource(DoubleTarget target); + + DoubleWrapperTarget sourceToTarget(DoubleWrapperOptionalSource source); + + DoubleWrapperOptionalSource targetToSource(DoubleWrapperTarget target); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperOptionalSource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperOptionalSource.java new file mode 100644 index 0000000000..16acf6c69b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/nativetypes/ShortWrapperOptionalSource.java @@ -0,0 +1,121 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.nativetypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class ShortWrapperOptionalSource { + + private Optional b = Optional.empty(); + private Optional bb = Optional.empty(); + private Optional s = Optional.empty(); + private Optional ss = Optional.empty(); + private Optional i = Optional.empty(); + private Optional ii = Optional.empty(); + private Optional l = Optional.empty(); + private Optional ll = Optional.empty(); + private Optional f = Optional.empty(); + private Optional ff = Optional.empty(); + private Optional d = Optional.empty(); + private Optional dd = Optional.empty(); + + public Optional getB() { + return b; + } + + public void setB(Optional b) { + this.b = b; + } + + public Optional getBb() { + return bb; + } + + public void setBb(Optional bb) { + this.bb = bb; + } + + public Optional getS() { + return s; + } + + public void setS(Optional s) { + this.s = s; + } + + public Optional getSs() { + return ss; + } + + public void setSs(Optional ss) { + this.ss = ss; + } + + public Optional getI() { + return i; + } + + public void setI(Optional i) { + this.i = i; + } + + public Optional getIi() { + return ii; + } + + public void setIi(Optional ii) { + this.ii = ii; + } + + public Optional getL() { + return l; + } + + public void setL(Optional l) { + this.l = l; + } + + public Optional getLl() { + return ll; + } + + public void setLl(Optional ll) { + this.ll = ll; + } + + public Optional getF() { + return f; + } + + public void setF(Optional f) { + this.f = f; + } + + public Optional getFf() { + return ff; + } + + public void setFf(Optional ff) { + this.ff = ff; + } + + public Optional getD() { + return d; + } + + public void setD(Optional d) { + this.d = d; + } + + public Optional getDd() { + return dd; + } + + public void setDd(Optional dd) { + this.dd = dd; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterMapper.java new file mode 100644 index 0000000000..30dca2cf39 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterMapper.java @@ -0,0 +1,76 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.beforeafter; + +import java.util.Optional; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetType; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface OptionalBeforeAfterMapper { + + OptionalBeforeAfterMapper INSTANCE = Mappers.getMapper( OptionalBeforeAfterMapper.class ); + + Target toTarget(Source source); + + @BeforeMapping + default void beforeDeepOptionalSourceWithNoTargetType(Optional source) { + } + + @BeforeMapping + default void beforeDeepOptionalSourceWithNonOptionalTargetType(@TargetType Class targetType, + Optional source) { + } + + @AfterMapping + default void afterDeepOptionalSourceWithNoTarget(Optional source) { + + } + + @AfterMapping + default void afterDeepOptionalSourceWithNonOptionalTarget(@MappingTarget Target.SubType target, + Optional source) { + } + + @AfterMapping + default void afterDeepOptionalSourceWithOptionalTarget(@MappingTarget Optional target, + Optional source) { + } + + @AfterMapping + default void afterDeepNonOptionalSourceOptionalTarget(@MappingTarget Optional target, + Source.SubType source) { + } + + @BeforeMapping + default void beforeShallowOptionalSourceWithNoTargetType(Optional source) { + } + + @BeforeMapping + default void beforeShallowOptionalSourceWithNonOptionalTargetType(@TargetType Class targetType, + Optional source) { + } + + @AfterMapping + default void afterShallowOptionalSourceWithNoTarget(Optional source) { + + } + + @AfterMapping + default void afterShallowOptionalSourceWithNonOptionalTarget(@MappingTarget String target, + Optional source) { + } + + @AfterMapping + default void afterShallowNonOptionalSourceOptionalTarget(@MappingTarget Optional target, String source) { + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterTest.java new file mode 100644 index 0000000000..ba1a7b09d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/OptionalBeforeAfterTest.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.beforeafter; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +@WithClasses({ + OptionalBeforeAfterMapper.class, Source.class, Target.class +}) +class OptionalBeforeAfterTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void generatedCode() { + generatedSource.addComparisonToFixtureFor( OptionalBeforeAfterMapper.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Source.java b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Source.java new file mode 100644 index 0000000000..1284bca7ea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Source.java @@ -0,0 +1,87 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.beforeafter; + +import java.util.Objects; +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class Source { + + private final Optional deepOptionalToOptional; + private final Optional deepOptionalToNonOptional; + private final SubType deepNonOptionalToOptional; + + private final Optional shallowOptionalToOptional; + private final Optional shallowOptionalToNonOptional; + private final String shallowNonOptionalToOptional; + + public Source(Optional deepOptionalToOptional, Optional deepOptionalToNonOptional, + SubType deepNonOptionalToOptional, Optional shallowOptionalToOptional, + Optional shallowOptionalToNonOptional, String shallowNonOptionalToOptional) { + this.deepOptionalToOptional = deepOptionalToOptional; + this.deepOptionalToNonOptional = deepOptionalToNonOptional; + this.deepNonOptionalToOptional = deepNonOptionalToOptional; + this.shallowOptionalToOptional = shallowOptionalToOptional; + this.shallowOptionalToNonOptional = shallowOptionalToNonOptional; + this.shallowNonOptionalToOptional = shallowNonOptionalToOptional; + } + + public Optional getDeepOptionalToOptional() { + return deepOptionalToOptional; + } + + public Optional getDeepOptionalToNonOptional() { + return deepOptionalToNonOptional; + } + + public SubType getDeepNonOptionalToOptional() { + return deepNonOptionalToOptional; + } + + public Optional getShallowOptionalToOptional() { + return shallowOptionalToOptional; + } + + public Optional getShallowOptionalToNonOptional() { + return shallowOptionalToNonOptional; + } + + public String getShallowNonOptionalToOptional() { + return shallowNonOptionalToOptional; + } + + public static class SubType { + + private final String value; + + public SubType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SubType subType = (SubType) o; + return Objects.equals( value, subType.value ); + } + + @Override + public int hashCode() { + return Objects.hash( value ); + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Target.java b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Target.java new file mode 100644 index 0000000000..592e3338fe --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/beforeafter/Target.java @@ -0,0 +1,86 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.beforeafter; + +import java.util.Objects; +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class Target { + + private final Optional deepOptionalToOptional; + private final SubType deepOptionalToNonOptional; + private final Optional deepNonOptionalToOptional; + + private final Optional shallowOptionalToOptional; + private final String shallowOptionalToNonOptional; + private final Optional shallowNonOptionalToOptional; + + public Target(Optional deepOptionalToOptional, SubType deepOptionalToNonOptional, + Optional deepNonOptionalToOptional, Optional shallowOptionalToOptional, + String shallowOptionalToNonOptional, Optional shallowNonOptionalToOptional) { + this.deepOptionalToOptional = deepOptionalToOptional; + this.deepOptionalToNonOptional = deepOptionalToNonOptional; + this.deepNonOptionalToOptional = deepNonOptionalToOptional; + this.shallowOptionalToOptional = shallowOptionalToOptional; + this.shallowOptionalToNonOptional = shallowOptionalToNonOptional; + this.shallowNonOptionalToOptional = shallowNonOptionalToOptional; + } + + public Optional getDeepOptionalToOptional() { + return deepOptionalToOptional; + } + + public SubType getDeepOptionalToNonOptional() { + return deepOptionalToNonOptional; + } + + public Optional getDeepNonOptionalToOptional() { + return deepNonOptionalToOptional; + } + + public Optional getShallowOptionalToOptional() { + return shallowOptionalToOptional; + } + + public String getShallowOptionalToNonOptional() { + return shallowOptionalToNonOptional; + } + + public Optional getShallowNonOptionalToOptional() { + return shallowNonOptionalToOptional; + } + + public static class SubType { + + private final String value; + + public SubType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public boolean equals(Object o) { + if ( this == o ) { + return true; + } + if ( o == null || getClass() != o.getClass() ) { + return false; + } + SubType subType = (SubType) o; + return Objects.equals( value, subType.value ); + } + + @Override + public int hashCode() { + return Objects.hash( value ); + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/builder/OptionalBuilderTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/builder/OptionalBuilderTest.java new file mode 100644 index 0000000000..9dd4b01256 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/builder/OptionalBuilderTest.java @@ -0,0 +1,31 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.builder; + +import java.util.Optional; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +class OptionalBuilderTest { + + @ProcessorTest + @WithClasses(SimpleOptionalBuilderMapper.class) + void simpleOptionalBuilder() { + Optional targetOpt = SimpleOptionalBuilderMapper.INSTANCE.map( null ); + assertThat( targetOpt ).isEmpty(); + + targetOpt = SimpleOptionalBuilderMapper.INSTANCE.map( new SimpleOptionalBuilderMapper.Source( "test" ) ); + assertThat( targetOpt ).isNotEmpty(); + SimpleOptionalBuilderMapper.Target target = targetOpt.get(); + assertThat( target.getValue() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/builder/SimpleOptionalBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/builder/SimpleOptionalBuilderMapper.java new file mode 100644 index 0000000000..5f24aa0cae --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/builder/SimpleOptionalBuilderMapper.java @@ -0,0 +1,67 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.builder; + +import java.util.Optional; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface SimpleOptionalBuilderMapper { + + SimpleOptionalBuilderMapper INSTANCE = Mappers.getMapper( SimpleOptionalBuilderMapper.class ); + + Optional map(Source source); + + class Source { + private final String value; + + public Source(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + class Target { + + private final String value; + + private Target(TargetBuilder builder) { + this.value = builder.value; + } + + public String getValue() { + return value; + } + + public static TargetBuilder builder() { + return new TargetBuilder(); + } + + } + + class TargetBuilder { + + private String value; + + public TargetBuilder value(String value) { + this.value = value; + return this; + } + + public Target build() { + return new Target(this); + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalMapper.java new file mode 100644 index 0000000000..a6f8c155d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalMapper.java @@ -0,0 +1,63 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.custom; + +import java.util.Optional; + +import org.mapstruct.Condition; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) +@SuppressWarnings("OptionalAssignedToNull") +public interface CustomOptionalMapper { + + CustomOptionalMapper INSTANCE = Mappers.getMapper( CustomOptionalMapper.class ); + + Target map(Source source); + + void update(@MappingTarget Target target, Source source); + + @Condition + default boolean isPresent(Optional optional) { + return optional != null; + } + + default E unwrapFromOptional(Optional optional) { + return optional == null + ? null + : optional.orElse( null ); + } + + class Target { + private String value = "initial"; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + + class Source { + private final Optional value; + + public Source(Optional value) { + this.value = value; + } + + public Optional getValue() { + return value; + } + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalTest.java new file mode 100644 index 0000000000..51991ac478 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/custom/CustomOptionalTest.java @@ -0,0 +1,60 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.custom; + +import java.util.Optional; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses(CustomOptionalMapper.class) +class CustomOptionalTest { + + @ProcessorTest + void shouldUseCustomMethodsWhenMapping() { + CustomOptionalMapper.Target target = CustomOptionalMapper.INSTANCE. + map( new CustomOptionalMapper.Source( null ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "initial" ); + + target = CustomOptionalMapper.INSTANCE.map( new CustomOptionalMapper.Source( Optional.empty() ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + + target = CustomOptionalMapper.INSTANCE.map( new CustomOptionalMapper.Source( Optional.of( "test" ) ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "test" ); + } + + @ProcessorTest + void shouldUseCustomMethodsWhenUpdating() { + CustomOptionalMapper.Target target = new CustomOptionalMapper.Target(); + + CustomOptionalMapper.INSTANCE.update( target, new CustomOptionalMapper.Source( null ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "initial" ); + + CustomOptionalMapper.INSTANCE.update( target, new CustomOptionalMapper.Source( Optional.empty() ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isNull(); + + target = new CustomOptionalMapper.Target(); + CustomOptionalMapper.INSTANCE.update( target, new CustomOptionalMapper.Source( Optional.of( "test" ) ) ); + + assertThat( target ).isNotNull(); + assertThat( target.getValue() ).isEqualTo( "test" ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesMapper.java new file mode 100644 index 0000000000..5a276b4745 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesMapper.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.differenttypes; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface OptionalDifferentTypesMapper { + + OptionalDifferentTypesMapper INSTANCE = Mappers.getMapper( OptionalDifferentTypesMapper.class ); + + Target toTarget(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesTest.java new file mode 100644 index 0000000000..74ab85e174 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/OptionalDifferentTypesTest.java @@ -0,0 +1,204 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.differenttypes; + +import java.util.Optional; + +import org.junit.jupiter.api.extension.RegisterExtension; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; +import org.mapstruct.ap.testutil.runner.GeneratedSource; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + OptionalDifferentTypesMapper.class, Source.class, Target.class +}) +class OptionalDifferentTypesTest { + + @RegisterExtension + final GeneratedSource generatedSource = new GeneratedSource(); + + @ProcessorTest + void generatedCode() { + generatedSource.addComparisonToFixtureFor( OptionalDifferentTypesMapper.class ); + } + + @ProcessorTest + void constructorOptionalToOptionalWhenPresent() { + Source source = new Source( Optional.of( new Source.SubType( "some value" ) ), Optional.empty(), null ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getConstructorOptionalToOptional() ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void constructorOptionalToOptionalWhenEmpty() { + Source source = new Source(); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getConstructorOptionalToOptional() ).isEmpty(); + } + + @ProcessorTest + void constructorOptionalToNonOptionalWhenPresent() { + Source source = new Source( Optional.empty(), Optional.of( new Source.SubType( "some value" ) ), null ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + Target.SubType subType = target.getConstructorOptionalToNonOptional(); + assertThat( subType ).isNotNull(); + assertThat( subType.getValue() ).isEqualTo( "some value" ); + } + + @ProcessorTest + void constructorOptionalToNonOptionalWhenEmpty() { + Source source = new Source(); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getConstructorOptionalToNonOptional() ).isNull(); + } + + @ProcessorTest + void constructorNonOptionalToOptionalWhenNotNull() { + Source source = new Source( Optional.empty(), Optional.empty(), new Source.SubType( "some value" ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getConstructorNonOptionalToOptional() ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void constructorNonOptionalToOptionalWhenNull() { + Source source = new Source(); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getConstructorNonOptionalToOptional() ).isEmpty(); + } + + @ProcessorTest + void optionalToOptionalWhenPresent() { + Source source = new Source(); + source.setOptionalToOptional( Optional.of( new Source.SubType( "some value" ) ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getOptionalToOptional() ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void optionalToOptionalWhenEmpty() { + Source source = new Source(); + source.setOptionalToOptional( Optional.empty() ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getOptionalToOptional() ).isEmpty(); + } + + @ProcessorTest + void optionalToNonOptionalWhenPresent() { + Source source = new Source(); + source.setOptionalToNonOptional( Optional.of( new Source.SubType( "some value" ) ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + Target.SubType subType = target.getOptionalToNonOptional(); + assertThat( subType ).isNotNull(); + assertThat( subType.getValue() ).isEqualTo( "some value" ); + } + + @ProcessorTest + void optionalToNonOptionalWhenEmpty() { + Source source = new Source(); + source.setOptionalToNonOptional( Optional.empty() ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getOptionalToNonOptional() ).isNull(); + } + + @ProcessorTest + void nonOptionalToOptionalWhenNotNull() { + Source source = new Source(); + source.setNonOptionalToOptional( new Source.SubType( "some value" ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getNonOptionalToOptional() ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void nonOptionalToOptionalWhenNull() { + Source source = new Source(); + source.setNonOptionalToOptional( null ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.getNonOptionalToOptional() ).isEmpty(); + } + + @ProcessorTest + void publicOptionalToOptionalWhenPresent() { + Source source = new Source(); + source.publicOptionalToOptional = Optional.of( new Source.SubType( "some value" ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.publicOptionalToOptional ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void publicOptionalToOptionalWhenEmpty() { + Source source = new Source(); + source.publicOptionalToOptional = Optional.empty(); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.publicOptionalToOptional ).isEmpty(); + } + + @ProcessorTest + void publicOptionalToNonOptionalWhenPresent() { + Source source = new Source(); + source.publicOptionalToNonOptional = Optional.of( new Source.SubType( "some value" ) ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + Target.SubType subType = target.publicOptionalToNonOptional; + assertThat( subType ).isNotNull(); + assertThat( subType.getValue() ).isEqualTo( "some value" ); + } + + @ProcessorTest + void publicOptionalToNonOptionalWhenEmpty() { + Source source = new Source(); + source.publicOptionalToNonOptional = Optional.empty(); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.publicOptionalToNonOptional ).isNull(); + } + + @ProcessorTest + void publicNonOptionalToOptionalWhenNotNull() { + Source source = new Source(); + source.publicNonOptionalToOptional = new Source.SubType( "some value" ); + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.publicNonOptionalToOptional ) + .hasValueSatisfying( subType -> + assertThat( subType.getValue() ).isEqualTo( "some value" ) ); + } + + @ProcessorTest + void publicNonOptionalToOptionalWhenNull() { + Source source = new Source(); + source.publicNonOptionalToOptional = null; + + Target target = OptionalDifferentTypesMapper.INSTANCE.toTarget( source ); + assertThat( target.publicNonOptionalToOptional ).isEmpty(); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Source.java b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Source.java new file mode 100644 index 0000000000..0c0648000a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Source.java @@ -0,0 +1,89 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.differenttypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class Source { + + private final Optional constructorOptionalToOptional; + private final Optional constructorOptionalToNonOptional; + private final SubType constructorNonOptionalToOptional; + + private Optional optionalToOptional = Optional.empty(); + private Optional optionalToNonOptional = Optional.empty(); + private SubType nonOptionalToOptional; + + @SuppressWarnings( "VisibilityModifier" ) + public Optional publicOptionalToOptional = Optional.empty(); + @SuppressWarnings( "VisibilityModifier" ) + public Optional publicOptionalToNonOptional = Optional.empty(); + @SuppressWarnings( "VisibilityModifier" ) + public SubType publicNonOptionalToOptional; + + public Source() { + this( Optional.empty(), Optional.empty(), null ); + } + + public Source(Optional constructorOptionalToOptional, Optional constructorOptionalToNonOptional, + SubType constructorNonOptionalToOptional) { + this.constructorOptionalToOptional = constructorOptionalToOptional; + this.constructorOptionalToNonOptional = constructorOptionalToNonOptional; + this.constructorNonOptionalToOptional = constructorNonOptionalToOptional; + } + + public Optional getConstructorOptionalToOptional() { + return constructorOptionalToOptional; + } + + public Optional getConstructorOptionalToNonOptional() { + return constructorOptionalToNonOptional; + } + + public SubType getConstructorNonOptionalToOptional() { + return constructorNonOptionalToOptional; + } + + public Optional getOptionalToOptional() { + return optionalToOptional; + } + + public void setOptionalToOptional(Optional optionalToOptional) { + this.optionalToOptional = optionalToOptional; + } + + public Optional getOptionalToNonOptional() { + return optionalToNonOptional; + } + + public void setOptionalToNonOptional(Optional optionalToNonOptional) { + this.optionalToNonOptional = optionalToNonOptional; + } + + public SubType getNonOptionalToOptional() { + return nonOptionalToOptional; + } + + public void setNonOptionalToOptional(SubType nonOptionalToOptional) { + this.nonOptionalToOptional = nonOptionalToOptional; + } + + public static class SubType { + + private final String value; + + public SubType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Target.java b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Target.java new file mode 100644 index 0000000000..4f2b21c8a7 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/differenttypes/Target.java @@ -0,0 +1,84 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.differenttypes; + +import java.util.Optional; + +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class Target { + + private final Optional constructorOptionalToOptional; + private final SubType constructorOptionalToNonOptional; + private final Optional constructorNonOptionalToOptional; + + private Optional optionalToOptional = Optional.of( new SubType( "initial" ) ); + private SubType optionalToNonOptional; + private Optional nonOptionalToOptional = Optional.of( new SubType( "initial" ) ); + + @SuppressWarnings( "VisibilityModifier" ) + public Optional publicOptionalToOptional = Optional.of( new SubType( "initial" ) ); + @SuppressWarnings( "VisibilityModifier" ) + public SubType publicOptionalToNonOptional; + @SuppressWarnings( "VisibilityModifier" ) + public Optional publicNonOptionalToOptional = Optional.of( new SubType( "initial" ) ); + + public Target(Optional constructorOptionalToOptional, SubType constructorOptionalToNonOptional, + Optional constructorNonOptionalToOptional) { + this.constructorOptionalToOptional = constructorOptionalToOptional; + this.constructorOptionalToNonOptional = constructorOptionalToNonOptional; + this.constructorNonOptionalToOptional = constructorNonOptionalToOptional; + } + + public Optional getConstructorOptionalToOptional() { + return constructorOptionalToOptional; + } + + public SubType getConstructorOptionalToNonOptional() { + return constructorOptionalToNonOptional; + } + + public Optional getConstructorNonOptionalToOptional() { + return constructorNonOptionalToOptional; + } + + public Optional getOptionalToOptional() { + return optionalToOptional; + } + + public void setOptionalToOptional(Optional optionalToOptional) { + this.optionalToOptional = optionalToOptional; + } + + public SubType getOptionalToNonOptional() { + return optionalToNonOptional; + } + + public void setOptionalToNonOptional(SubType optionalToNonOptional) { + this.optionalToNonOptional = optionalToNonOptional; + } + + public Optional getNonOptionalToOptional() { + return nonOptionalToOptional; + } + + public void setNonOptionalToOptional(Optional nonOptionalToOptional) { + this.nonOptionalToOptional = nonOptionalToOptional; + } + + public static class SubType { + + private final String value; + + public SubType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/MappingContext.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/MappingContext.java new file mode 100644 index 0000000000..3624efb00e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/MappingContext.java @@ -0,0 +1,108 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.mapstruct.AfterMapping; +import org.mapstruct.BeforeMapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.TargetType; + +/** + * @author Filip Hrisafov + */ +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class MappingContext { + + private final List invokedMethods = new ArrayList<>(); + + @BeforeMapping + public void beforeWithoutParameters() { + invokedMethods.add( "beforeWithoutParameters" ); + } + + @BeforeMapping + public void beforeWithOptionalSource(Optional source) { + invokedMethods.add( "beforeWithOptionalSource" ); + } + + @BeforeMapping + public void beforeWithSource(Source source) { + invokedMethods.add( "beforeWithSource" ); + } + + @BeforeMapping + public void beforeWithTargetType(@TargetType Class targetClass) { + invokedMethods.add( "beforeWithTargetType" ); + } + + @BeforeMapping + public void beforeWithBuilderTargetType(@TargetType Class targetBuilderClass) { + invokedMethods.add( "beforeWithBuilderTargetType" ); + } + + @BeforeMapping + public void beforeWithOptionalTarget(@MappingTarget Optional target) { + invokedMethods.add( "beforeWithOptionalTarget" ); + } + + @BeforeMapping + public void beforeWithTarget(@MappingTarget Target target) { + invokedMethods.add( "beforeWithTarget" ); + } + + @BeforeMapping + public void beforeWithTargetBuilder(@MappingTarget Target.Builder target) { + invokedMethods.add( "beforeWithTargetBuilder" ); + } + + @AfterMapping + public void afterWithoutParameters() { + invokedMethods.add( "afterWithoutParameters" ); + } + + @AfterMapping + public void afterWithOptionalSource(Optional source) { + invokedMethods.add( "afterWithOptionalSource" ); + } + + @AfterMapping + public void afterWithSource(Source source) { + invokedMethods.add( "afterWithSource" ); + } + + @AfterMapping + public void afterWithTargetType(@TargetType Class targetClass) { + invokedMethods.add( "afterWithTargetType" ); + } + + @AfterMapping + public void afterWithBuilderTargetType(@TargetType Class targetClass) { + invokedMethods.add( "afterWithBuilderTargetType" ); + } + + @AfterMapping + public void afterWithTarget(@MappingTarget Target target) { + invokedMethods.add( "afterWithTarget" ); + } + + @AfterMapping + public void afterWithTargetBuilder(@MappingTarget Target.Builder target) { + invokedMethods.add( "afterWithTargetBuilder" ); + } + + @AfterMapping + public void afterWithOptionalTarget(@MappingTarget Optional target) { + invokedMethods.add( "afterWithOptionalTarget" ); + } + + public List getInvokedMethods() { + return invokedMethods; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalLifecycleTest.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalLifecycleTest.java new file mode 100644 index 0000000000..c80dfcb6b6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalLifecycleTest.java @@ -0,0 +1,165 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.Optional; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Filip Hrisafov + */ +@WithClasses({ + MappingContext.class, + Source.class, + Target.class, +}) +public class OptionalLifecycleTest { + + @ProcessorTest + @WithClasses(OptionalToOptionalMapper.class) + void optionalToOptional() { + MappingContext context = new MappingContext(); + + OptionalToOptionalMapper.INSTANCE.map( Optional.empty(), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType" + ); + + context = new MappingContext(); + OptionalToOptionalMapper.INSTANCE.map( Optional.of( new Source() ), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithTarget", + "afterWithoutParameters", + "afterWithOptionalSource", + "afterWithTargetType", + "afterWithTarget", + "afterWithOptionalTarget" + ); + } + + @ProcessorTest + @WithClasses(OptionalToOptionalWithBuilderMapper.class) + void optionalToOptionalWithBuilder() { + MappingContext context = new MappingContext(); + + OptionalToOptionalWithBuilderMapper.INSTANCE.map( Optional.empty(), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithBuilderTargetType" + ); + + context = new MappingContext(); + OptionalToOptionalWithBuilderMapper.INSTANCE.map( Optional.of( new Source() ), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithBuilderTargetType", + "beforeWithTargetBuilder", + "afterWithoutParameters", + "afterWithOptionalSource", + "afterWithTargetType", + "afterWithBuilderTargetType", + "afterWithTarget", + "afterWithTargetBuilder", + "afterWithOptionalTarget" + ); + } + + @ProcessorTest + @WithClasses(OptionalToTypeMapper.class) + void optionalToType() { + MappingContext context = new MappingContext(); + + OptionalToTypeMapper.INSTANCE.map( Optional.empty(), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType" + ); + + context = new MappingContext(); + OptionalToTypeMapper.INSTANCE.map( Optional.of( new Source() ), context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithTarget", + "afterWithoutParameters", + "afterWithOptionalSource", + "afterWithTargetType", + "afterWithTarget" + ); + } + + @ProcessorTest + @WithClasses(OptionalToTypeMultiSourceMapper.class) + void optionalToTypeMultiSource() { + MappingContext context = new MappingContext(); + + OptionalToTypeMultiSourceMapper.INSTANCE.map( Optional.empty(), null, context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType" + ); + + context = new MappingContext(); + OptionalToTypeMultiSourceMapper.INSTANCE.map( Optional.of( new Source() ), null, context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithTarget", + "afterWithoutParameters", + "afterWithOptionalSource", + "afterWithTargetType", + "afterWithTarget" + ); + + context = new MappingContext(); + OptionalToTypeMultiSourceMapper.INSTANCE.map( Optional.empty(), "Test", context ); + + assertThat( context.getInvokedMethods() ) + .containsExactlyInAnyOrder( + "beforeWithoutParameters", + "beforeWithOptionalSource", + "beforeWithTargetType", + "beforeWithTarget", + "afterWithoutParameters", + "afterWithOptionalSource", + "afterWithTargetType", + "afterWithTarget" + ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalMapper.java new file mode 100644 index 0000000000..d7c5d08173 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.Optional; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OptionalToOptionalMapper { + + OptionalToOptionalMapper INSTANCE = Mappers.getMapper( OptionalToOptionalMapper.class ); + + @BeanMapping(builder = @Builder(disableBuilder = true)) + Optional map(Optional source, @Context MappingContext context); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalWithBuilderMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalWithBuilderMapper.java new file mode 100644 index 0000000000..8cfab7fd00 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToOptionalWithBuilderMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.Optional; + +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OptionalToOptionalWithBuilderMapper { + + OptionalToOptionalWithBuilderMapper INSTANCE = Mappers.getMapper( OptionalToOptionalWithBuilderMapper.class ); + + Optional map(Optional source, @Context MappingContext context); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMapper.java new file mode 100644 index 0000000000..6a6f3e096e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.Optional; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OptionalToTypeMapper { + + OptionalToTypeMapper INSTANCE = Mappers.getMapper( OptionalToTypeMapper.class ); + + @BeanMapping(builder = @Builder(disableBuilder = true)) + Target map(Optional source, @Context MappingContext context); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMultiSourceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMultiSourceMapper.java new file mode 100644 index 0000000000..d672f2ec05 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/OptionalToTypeMultiSourceMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +import java.util.Optional; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Builder; +import org.mapstruct.Context; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * @author Filip Hrisafov + */ +@Mapper +public interface OptionalToTypeMultiSourceMapper { + + OptionalToTypeMultiSourceMapper INSTANCE = Mappers.getMapper( OptionalToTypeMultiSourceMapper.class ); + + @BeanMapping(builder = @Builder(disableBuilder = true)) + Target map(Optional source, String otherValue, @Context MappingContext context); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Source.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Source.java new file mode 100644 index 0000000000..c7005c6ca6 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Source.java @@ -0,0 +1,21 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +/** + * @author Filip Hrisafov + */ +public class Source { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Target.java b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Target.java new file mode 100644 index 0000000000..d5f68a1844 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/lifecycle/Target.java @@ -0,0 +1,39 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.lifecycle; + +/** + * @author Filip Hrisafov + */ +public class Target { + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public static class Builder { + + private String value; + + public Builder value(String value) { + this.value = value; + return this; + } + + public Target build() { + Target target = new Target(); + target.setValue( value ); + return target; + } + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/optional/nested/Artist.java b/processor/src/test/java/org/mapstruct/ap/test/optional/nested/Artist.java new file mode 100644 index 0000000000..e6ce6faa65 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/optional/nested/Artist.java @@ -0,0 +1,81 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.optional.nested; + +import java.util.Optional; + +/** + * @author Filip Hrisafov + */ +public class Artist { + private final String name; + private final Label label; + + public Artist(String name, Label label) { + this.name = name; + this.label = label; + } + + public boolean hasName() { + return name != null; + } + + public String getName() { + return name; + } + + public boolean hasLabel() { + return label != null; + } + + public Optional
      *

      @@ -446,13 +445,11 @@ * If not possible, MapStruct will try to apply a user defined mapping method. * * - *

      * *

    18. other *

      * MapStruct handles the constant as {@code String}. The value will be converted by applying a matching method, * type conversion method or built-in conversion. - *

      *

    19. * *

      diff --git a/core/src/main/java/org/mapstruct/SubclassMapping.java b/core/src/main/java/org/mapstruct/SubclassMapping.java index f5463b9026..4d635d8aa3 100644 --- a/core/src/main/java/org/mapstruct/SubclassMapping.java +++ b/core/src/main/java/org/mapstruct/SubclassMapping.java @@ -73,12 +73,17 @@ @Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Experimental public @interface SubclassMapping { + /** + * The source subclass to check for before using the default mapping as fallback. + * * @return the source subclass to check for before using the default mapping as fallback. */ Class source(); /** + * The target subclass to map the source to. + * * @return the target subclass to map the source to. */ Class target(); diff --git a/core/src/main/java/org/mapstruct/SubclassMappings.java b/core/src/main/java/org/mapstruct/SubclassMappings.java index 2ddafaf516..d6aac264d4 100644 --- a/core/src/main/java/org/mapstruct/SubclassMappings.java +++ b/core/src/main/java/org/mapstruct/SubclassMappings.java @@ -51,6 +51,8 @@ public @interface SubclassMappings { /** + * The subclassMappings that should be applied. + * * @return the subclassMappings to apply. */ SubclassMapping[] value(); diff --git a/core/src/main/java/org/mapstruct/ValueMappings.java b/core/src/main/java/org/mapstruct/ValueMappings.java index bb593f53d1..95d4c7d5ce 100644 --- a/core/src/main/java/org/mapstruct/ValueMappings.java +++ b/core/src/main/java/org/mapstruct/ValueMappings.java @@ -44,6 +44,11 @@ @Retention(RetentionPolicy.CLASS) public @interface ValueMappings { + /** + * The value mappings that should be applied. + * + * @return the value mappings + */ ValueMapping[] value(); } diff --git a/core/src/main/java/org/mapstruct/control/MappingControl.java b/core/src/main/java/org/mapstruct/control/MappingControl.java index c44797602a..1cb5bf2bb1 100644 --- a/core/src/main/java/org/mapstruct/control/MappingControl.java +++ b/core/src/main/java/org/mapstruct/control/MappingControl.java @@ -99,8 +99,16 @@ @MappingControl( MappingControl.Use.COMPLEX_MAPPING ) public @interface MappingControl { + /** + * The type of mapping control that should be used. + * + * @return What should be used for the mapping control + */ Use value(); + /** + * Defines the options that can be used for the mapping control. + */ enum Use { /** diff --git a/core/src/main/java/org/mapstruct/control/MappingControls.java b/core/src/main/java/org/mapstruct/control/MappingControls.java index a3efef661f..c1663e551e 100644 --- a/core/src/main/java/org/mapstruct/control/MappingControls.java +++ b/core/src/main/java/org/mapstruct/control/MappingControls.java @@ -21,5 +21,10 @@ @Target(ElementType.ANNOTATION_TYPE) public @interface MappingControls { + /** + * The mapping controls that should be applied to the annotated class. + * + * @return The mapping controls that should be applied to the annotated class. + */ MappingControl[] value(); } diff --git a/core/src/main/java/org/mapstruct/util/Experimental.java b/core/src/main/java/org/mapstruct/util/Experimental.java index a945a87d7c..5fd5eb3b5c 100644 --- a/core/src/main/java/org/mapstruct/util/Experimental.java +++ b/core/src/main/java/org/mapstruct/util/Experimental.java @@ -17,5 +17,11 @@ @Documented @Retention(RetentionPolicy.SOURCE) public @interface Experimental { + + /** + * The reason why the feature is considered experimental. + * + * @return the reason why the feature is considered experimental. + */ String value() default ""; } diff --git a/processor/pom.xml b/processor/pom.xml index 01b8cbe263..622ba924ee 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -172,6 +172,13 @@ + + org.apache.maven.plugins + maven-javadoc-plugin + + all,-missing + + org.apache.maven.plugins maven-surefire-plugin diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java index 31d4d27585..b392281bf4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionProvider.java @@ -46,6 +46,8 @@ public interface ConversionProvider { Assignment from(ConversionContext conversionContext); /** + * Retrieves any helper methods required for creating the conversion. + * * @param conversionContext ConversionContext providing optional information required for creating the conversion. * * @return any helper methods when required. @@ -53,6 +55,8 @@ public interface ConversionProvider { List getRequiredHelperMethods(ConversionContext conversionContext); /** + * Retrieves any fields required for creating the conversion. + * * @param conversionContext ConversionContext providing optional information required for creating the conversion. * * @return any fields when required. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java index 99797f898c..3f32994734 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/CurrencyToStringConversion.java @@ -15,6 +15,8 @@ import static org.mapstruct.ap.internal.conversion.ConversionUtils.currency; /** + * Conversion between {@link Currency} and {@link String}. + * * @author Darren Rambaud */ public class CurrencyToStringConversion extends SimpleConversion { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java index 2b3e1bd960..db9480662d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/OptionalWrapperConversionProvider.java @@ -17,6 +17,9 @@ import org.mapstruct.ap.internal.model.common.TypeFactory; /** + * A conversion provider that wraps / unwraps the underlying conversion in Optional. + * e.g., For conversion from {@code Optional} to {@code Integer}. + * * @author Filip Hrisafov */ public class OptionalWrapperConversionProvider implements ConversionProvider { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java index ad488d1a8f..dbab6bc4ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/TypeToOptionalConversion.java @@ -15,6 +15,8 @@ import static org.mapstruct.ap.internal.conversion.ReverseConversion.inverse; /** + * Conversion between {@link java.util.Optional Optional} and its base type. + * * @author Filip Hrisafov */ public class TypeToOptionalConversion extends SimpleConversion { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java index 3b6e3c1686..80b900bb57 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractMappingMethodBuilder.java @@ -19,6 +19,8 @@ /** * An abstract builder that can be reused for building {@link MappingMethod}(s). * + * @param the builder itself that needs to be used for chaining + * @param the method that the builder builds * @author Filip Hrisafov */ public abstract class AbstractMappingMethodBuilder, diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java index 3f0b2123ae..cb9289e057 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AdditionalAnnotationsBuilder.java @@ -50,6 +50,8 @@ import static javax.lang.model.util.ElementFilter.methodsIn; /** + * Helper class which is responsible for collecting all additional annotations that should be added. + * * @author Ben Zegveld * @since 1.5 */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java index 5614376ea4..8f60b052b9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AnnotatedSetter.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A method in a generated type that represents a setter with annotations. + * * @author Lucas Resch */ public class AnnotatedSetter extends GeneratedTypeMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java index 9b7912f752..9b0507f399 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BuilderFinisherMethodResolver.java @@ -19,6 +19,8 @@ import static org.mapstruct.ap.internal.util.Collections.first; /** + * Factory for creating the appropriate builder finisher method. + * * @author Filip Hrisafov */ public class BuilderFinisherMethodResolver { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java index f8c596a368..e1c320e16b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/FromOptionalTypeConversion.java @@ -15,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * An inline conversion from an optional source to it's value. + * * @author Filip Hrisafov */ public class FromOptionalTypeConversion extends ModelElement implements Assignment { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java index f02cc16b2c..8d6a999665 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedTypeMethod.java @@ -8,6 +8,8 @@ import org.mapstruct.ap.internal.model.common.ModelElement; /** + * Base class for methods available in a generated type. + * * @author Filip Hrisafov */ public abstract class GeneratedTypeMethod extends ModelElement { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java index 879a76efbe..29904ff416 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MethodReferencePresenceCheck.java @@ -13,6 +13,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A {@link PresenceCheck} that is based on a {@link MethodReference}. + * * @author Filip Hrisafov */ public class MethodReferencePresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 89f295981f..8b526b9177 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -26,6 +26,7 @@ import static org.mapstruct.ap.internal.util.Collections.first; /** + * Factory for creating the appropriate object factory method. * * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java index 784342b8d7..2de61089ca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PresenceCheckMethodResolver.java @@ -25,6 +25,8 @@ import org.mapstruct.ap.internal.util.Message; /** + * Factory for creating {@link PresenceCheck}s. + * * @author Filip Hrisafov */ public final class PresenceCheckMethodResolver { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java index 727518dad8..0d97c1a523 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ServicesEntry.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * Represents a service entry for the service loader file. + * * @author Christophe Labouisse on 14/07/2015. */ public class ServicesEntry extends ModelElement { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java index 5925540e10..45bbc9d4b0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ToOptionalTypeConversion.java @@ -15,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * An inline conversion from a source to an optional of the source. + * * @author Filip Hrisafov */ public class ToOptionalTypeConversion extends ModelElement implements Assignment { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java index 6ecde886bf..f242b51f47 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/annotation/AnnotationElement.java @@ -15,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * Represents an annotation element. + * * @author Ben Zegveld */ public class AnnotationElement extends ModelElement { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java index a334312007..eaa2fe68ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/EnumConstantWrapper.java @@ -12,6 +12,7 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * Decorates the assignment as an {@link Enum} constant access. * * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java index 9064640bb4..6c405c871d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/OptionalGetWrapper.java @@ -10,6 +10,8 @@ import org.mapstruct.ap.internal.util.Strings; /** + * Decorates the assignment as an {@link java.util.Optional#get()} call. + * * @author Filip Hrisafov */ public class OptionalGetWrapper extends AssignmentWrapper { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index b94bb82efd..9300f683ce 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -14,6 +14,9 @@ import org.mapstruct.ap.spi.BuilderInfo; /** + * Represents the information about a builder. + * How it can be constructed, the type it is building etc. + * * @author Filip Hrisafov */ public class BuilderType { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java index 48cee4bbe5..7ef818630a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/FormattingParameters.java @@ -10,6 +10,7 @@ import javax.lang.model.element.Element; /** + * Represent information about the configured formatting. * * @author Sjaak Derksen */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java index f8844edcdd..78357affb8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/NegatePresenceCheck.java @@ -9,6 +9,8 @@ import java.util.Set; /** + * A {@link PresenceCheck} that negates the result of another presence check. + * * @author Filip Hrisafov */ public class NegatePresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java index 6bb191214f..d71f67a2a4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AllPresenceChecksPresenceCheck.java @@ -16,6 +16,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A {@link PresenceCheck} that checks if all the given presence checks are present. + * * @author Filip Hrisafov */ public class AllPresenceChecksPresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java index 0b5770e42f..5f8fac9623 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/AnyPresenceChecksPresenceCheck.java @@ -16,6 +16,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A {@link PresenceCheck} that checks if any of the given presence checks are present. + * * @author Filip Hrisafov */ public class AnyPresenceChecksPresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java index e100be7e79..0c7c132023 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/JavaExpressionPresenceCheck.java @@ -15,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A {@link PresenceCheck} that calls a Java expression. + * * @author Filip Hrisafov */ public class JavaExpressionPresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java index 3496486e1d..2da4ae4023 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/NullPresenceCheck.java @@ -14,6 +14,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A presence check that checks if the source reference is null. + * * @author Filip Hrisafov */ public class NullPresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java index 0f75fbba69..d35e89fce2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/presence/SuffixPresenceCheck.java @@ -15,6 +15,8 @@ import org.mapstruct.ap.internal.model.common.Type; /** + * A {@link PresenceCheck} that calls the suffix on the source reference. + * * @author Filip Hrisafov */ public class SuffixPresenceCheck extends ModelElement implements PresenceCheck { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java index 936d049af8..83e2bf2819 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/ConditionOptions.java @@ -23,6 +23,8 @@ import org.mapstruct.ap.internal.util.Message; /** + * Represents a condition configuration as configured via {@code @Condition}. + * * @author Filip Hrisafov */ public class ConditionOptions { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java index 85734c3083..41b74aa13a 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/EnumMappingOptions.java @@ -21,6 +21,8 @@ import static org.mapstruct.ap.internal.util.Message.ENUMMAPPING_NO_ELEMENTS; /** + * Represents an enum mapping as configured via {@code @EnumMapping}. + * * @author Filip Hrisafov */ public class EnumMappingOptions extends DelegatingOptions { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java index 50ea5df6e0..7d0ab3a7ec 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodUtils.java @@ -10,6 +10,8 @@ import static org.mapstruct.ap.internal.util.Collections.first; /** + * Utility class for mapping methods. + * * @author Filip Hrisafov */ public final class MappingMethodUtils { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java index e2ccc3f476..df9c8e0b0c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/AbstractToXmlGregorianCalendar.java @@ -17,6 +17,8 @@ import org.mapstruct.ap.internal.util.XmlConstants; /** + * Base class for built-in methods for converting from a particular type to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public abstract class AbstractToXmlGregorianCalendar extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java index c8cd89169b..3461538c41 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/CalendarToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link Calendar} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class CalendarToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java index 036edd83a2..fb556e68a1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/DateToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link Date} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class DateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java index d0b06300c4..ef57e03175 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaDateTimeToXmlGregorianCalendar.java @@ -13,6 +13,8 @@ import org.mapstruct.ap.internal.util.JodaTimeConstants; /** + * A built-in method for converting from Joda {@code DateTime} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class JodaDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java index 80fa9ba326..285ebb29fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateTimeToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from Joda {@code LocalDateTime} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class JodaLocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java index 37c89ef360..8163aa2fb2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalDateToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from Joda {@code LocalDate} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class JodaLocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java index b29c7aec54..4fca4e0ed3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/JodaLocalTimeToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from Joda {@code LocalTime} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class JodaLocalTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java index 178a77b5fa..b52c7fb586 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateTimeToXmlGregorianCalendar.java @@ -17,6 +17,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link LocalDateTime} to {@code XMLGregorianCalendar}. + * * @author Andrei Arlou */ public class LocalDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java index 2e2544ade0..e2ec7d7696 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/LocalDateToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link LocalDate} to {@code XMLGregorianCalendar}. + * * @author Gunnar Morling */ public class LocalDateToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java index 9f0d2ad207..635853d0fe 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/StringToXmlGregorianCalendar.java @@ -19,6 +19,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link String} to {@code XMLGregorianCalendar}. + * * @author Sjaak Derksen */ public class StringToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java index 03927fd869..e52b306af0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to {@link Calendar}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToCalendar extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java index 38f76a66ee..fd3d9a33a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToDate.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to {@link Date}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToDate extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java index ab6658bfc5..93ec3e8f96 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaDateTime.java @@ -5,6 +5,7 @@ */ package org.mapstruct.ap.internal.model.source.builtin; +import java.util.Calendar; import java.util.Set; import org.mapstruct.ap.internal.model.common.Parameter; @@ -16,6 +17,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from Joda {@code DateTime} to {@link Calendar}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToJodaDateTime extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java index f45488755c..9a9c1561fc 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDate.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to Joda {@code LocalDate}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToJodaLocalDate extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java index af7fd9e9fd..a8d36a13cf 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalDateTime.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to Joda {@code LocalDateTime}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToJodaLocalDateTime extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java index 3725691134..b26450d560 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToJodaLocalTime.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * Conversion from {@code XMLGregorianCalendar} to Joda {@code LocalTime}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToJodaLocalTime extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java index 2c9ced3413..7bcd5902a5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDate.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to {@link LocalDate}. + * * @author Gunnar Morling */ public class XmlGregorianCalendarToLocalDate extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java index b676bd03a4..21b4c57854 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToLocalDateTime.java @@ -17,6 +17,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to {@link LocalDateTime}. + * * @author Andrei Arlou */ public class XmlGregorianCalendarToLocalDateTime extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java index c932da6675..e293a9c80b 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/XmlGregorianCalendarToString.java @@ -18,6 +18,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@code XMLGregorianCalendar} to {@link String}. + * * @author Sjaak Derksen */ public class XmlGregorianCalendarToString extends BuiltInMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java index 27a39cd2b7..d9e39b388e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/builtin/ZonedDateTimeToXmlGregorianCalendar.java @@ -16,6 +16,8 @@ import static org.mapstruct.ap.internal.util.Collections.asSet; /** + * A built-in method for converting from {@link ZonedDateTime} to {@code XMLGregorianCalendar}. + * * @author Christian Bandowski */ public class ZonedDateTimeToXmlGregorianCalendar extends AbstractToXmlGregorianCalendar { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java index 23af0a55f9..87ec3b4dc1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java @@ -12,6 +12,8 @@ import org.mapstruct.ap.internal.model.source.Method; /** + * A {@link MethodSelector} that selects the most specific result type. + * * @author Filip Hrisafov */ public class MostSpecificResultTypeSelector implements MethodSelector { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java index 7acb1af210..1702a8d4d6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/SelectedMethod.java @@ -14,6 +14,8 @@ /** * A selected method with additional metadata that might be required for further usage of the selected method. * + * @param the type of the method + * * @author Andreas Gudian */ public class SelectedMethod { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java b/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java index d35b2c0dc6..fedbe997a6 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/option/MappingOption.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.internal.option; /** + * The different compiler mapping options that are available in MapStruct. + * * @author Filip Hrisafov */ public enum MappingOption { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java index 72a44d106f..67ce6e10ff 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AbstractElementUtilsDecorator.java @@ -34,6 +34,11 @@ import static javax.lang.model.util.ElementFilter.fieldsIn; import static javax.lang.model.util.ElementFilter.methodsIn; +/** + * MapStruct specific abstract implementation of {@link ElementUtils}. + * This allows us to provide different implementations for different compilers and / or + * to allow us for easier implementation of using the module system. + */ public abstract class AbstractElementUtilsDecorator implements ElementUtils { private final Elements delegate; @@ -312,6 +317,8 @@ private TypeElement asTypeElement(TypeMirror mirror) { } /** + * Checks whether the {@code executable} does not have a private modifier. + * * @param executable the executable to check * @return {@code true}, iff the executable does not have a private modifier */ diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java b/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java index f2328a91cc..96768daf56 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/MetaAnnotations.java @@ -16,6 +16,11 @@ import org.mapstruct.tools.gem.Gem; /** + * A base helper class that provides utility methods for working with meta annotations. + * + * @param The type of the processed annotation + * @param The type of the underlying holder for the processed annotation + * * @author Filip Hrisafov */ public abstract class MetaAnnotations { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java b/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java index accae77718..76126bf488 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/RepeatableAnnotations.java @@ -16,6 +16,12 @@ import org.mapstruct.tools.gem.Gem; /** + * A base helper class that provides utility methods for working with repeatable annotations. + * + * @param The singular annotation type + * @param The multiple annotation type + * @param The underlying holder for the processed annotations + * * @author Ben Zegveld */ public abstract class RepeatableAnnotations { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java index 9b2981d7c5..5ebc835ba1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/DelegateAccessor.java @@ -11,6 +11,8 @@ import javax.lang.model.type.TypeMirror; /** + * An {@link Accessor} which delegates all calls to another {@link Accessor}. + * * @author Filip Hrisafov */ public abstract class DelegateAccessor implements Accessor { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java index cc974b939f..d96788b7f7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/PresenceCheckAccessor.java @@ -8,6 +8,8 @@ import javax.lang.model.element.ExecutableElement; /** + * Accessor for presence checks. + * * @author Filip Hrisafov */ public interface PresenceCheckAccessor { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java index 31edf3a6da..4be3c26ff9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadAccessor.java @@ -11,6 +11,8 @@ import javax.lang.model.type.TypeMirror; /** + * An {@link Accessor} that can be used for reading a property from a bean. + * * @author Filip Hrisafov */ public interface ReadAccessor extends Accessor { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java index 608c1b21cf..aa93936662 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/accessor/ReadDelegateAccessor.java @@ -6,6 +6,9 @@ package org.mapstruct.ap.internal.util.accessor; /** + * {@link ReadAccessor} that delegates to another {@link Accessor} and requires an implementation of + * {@link #getSimpleName()} + * * @author Filip Hrisafov */ public abstract class ReadDelegateAccessor extends DelegateAccessor implements ReadAccessor { diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index 511504c937..e7529dcd08 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -188,7 +188,6 @@ private boolean isAdderWithUpperCase4thCharacter(ExecutableElement method) { * {@link #getElementName(ExecutableElement) }. *

      * The calling MapStruct code guarantees there's only one argument. - *

      * * @param method to be analyzed * diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index afcee7d247..333a11dbcc 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -317,7 +317,7 @@ protected boolean isPossibleBuilderCreationMethod(ExecutableElement method, Type *

      * The default implementation uses {@link DefaultBuilderProvider#shouldIgnore(TypeElement)} to check if the * {@code builderElement} should be ignored, i.e. not checked for build elements. - *

      + * * @param builderElement the element for the builder * @param typeElement the element for the type that is being built * @return the build method for the {@code typeElement} if it exists, or {@code null} if it does not diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java index 62d6c32809..11e1257be1 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultEnumMappingStrategy.java @@ -10,6 +10,8 @@ import javax.lang.model.util.Types; /** + * The default implementation of the {@link EnumMappingStrategy} service provider interface. + * * @author Filip Hrisafov * * @since 1.4 diff --git a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java index 9dae81cda2..2a1cacfb1f 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/MappingExclusionProvider.java @@ -15,7 +15,6 @@ *

      * When generating the implementation of a mapping method, MapStruct will apply the following routine for each * attribute pair in the source and target object: - *

      *

        *
      • If source and target attribute have the same type, the value will be simply copied from source to target. * If the attribute is a collection (e.g. a `List`) a copy of the collection will be set into the target diff --git a/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java index abb6e9cb4f..226251dfab 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/PrefixEnumTransformationStrategy.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.spi; /** + * An {@link EnumTransformationStrategy} that prepends a prefix to the enum value. + * * @author Filip Hrisafov * * @since 1.4 diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java index d3f0c515b3..dec7af6de4 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripPrefixEnumTransformationStrategy.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.spi; /** + * An {@link EnumTransformationStrategy} that strips a prefix from the enum value. + * * @author Filip Hrisafov * * @since 1.4 diff --git a/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java index cf239600d4..3b76354fa7 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/StripSuffixEnumTransformationStrategy.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.spi; /** + * An {@link EnumTransformationStrategy} that strips a suffix from the enum value. + * * @author Filip Hrisafov * * @since 1.4 diff --git a/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java index 4cd92b9af8..1f4eb89217 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/SuffixEnumTransformationStrategy.java @@ -6,6 +6,8 @@ package org.mapstruct.ap.spi; /** + * An {@link EnumTransformationStrategy} that appends a suffix to the enum value. + * * @author Filip Hrisafov * * @since 1.4 diff --git a/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java b/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java index 7b8f374cf7..93bccf51d0 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/util/package-info.java @@ -4,4 +4,7 @@ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ +/** + * Utility classes for the SPI package. + */ package org.mapstruct.ap.spi.util; From d59e6a04aa3fb4bb1ca313959d4eecc9891287c9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 31 Jan 2026 17:09:36 +0100 Subject: [PATCH 0931/1006] Cleanup checks for JRE prior 21 in processor test module The processor test module is compiled using Java 21. Therefore, all tests that were configured to run prior Java 21 are no longer executed and can be safely removed --- .../conversion/date/DateConversionTest.java | 75 ------------------- .../jodatime/JodaConversionTest.java | 32 -------- .../runner/JdkCompilingExtension.java | 33 -------- 3 files changed, 140 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java index bc90228206..346f34a054 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/date/DateConversionTest.java @@ -13,9 +13,6 @@ import java.util.GregorianCalendar; import java.util.List; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.EnabledOnJre; -import org.junit.jupiter.api.condition.JRE; import org.junitpioneer.jupiter.DefaultLocale; import org.junitpioneer.jupiter.ReadsDefaultTimeZone; import org.mapstruct.ap.testutil.IssueKey; @@ -40,38 +37,6 @@ public class DateConversionTest { @ProcessorTest - @EnabledOnJre( JRE.JAVA_8 ) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ - public void shouldApplyDateFormatForConversions() { - Source source = new Source(); - source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); - source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); - - Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); - - assertThat( target ).isNotNull(); - assertThat( target.getDate() ).isEqualTo( "06.07.2013" ); - assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13 00:00" ); - } - - @ProcessorTest - @EnabledOnJre( JRE.JAVA_8 ) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ - public void shouldApplyDateFormatForConversionsWithCustomLocale() { - Source source = new Source(); - source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); - source.setAnotherDate( new GregorianCalendar( 2013, Calendar.FEBRUARY, 14 ).getTime() ); - - Target target = SourceTargetMapper.INSTANCE.sourceToTargetWithCustomLocale( source ); - - assertThat( target ).isNotNull(); - assertThat( target.getDate() ).isEqualTo( "juillet 06, 2013" ); - assertThat( target.getAnotherDate() ).isEqualTo( "14.02.13, 00:00" ); - } - - @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_11) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionsJdk11() { Source source = new Source(); source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); @@ -85,8 +50,6 @@ public void shouldApplyDateFormatForConversionsJdk11() { } @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_11) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionsJdk11WithCustomLocale() { Source source = new Source(); source.setDate( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); @@ -100,42 +63,6 @@ public void shouldApplyDateFormatForConversionsJdk11WithCustomLocale() { } @ProcessorTest - @EnabledOnJre(JRE.JAVA_8) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ - public void shouldApplyDateFormatForConversionInReverseMapping() { - Target target = new Target(); - target.setDate( "06.07.2013" ); - target.setAnotherDate( "14.02.13 8:30" ); - - Source source = SourceTargetMapper.INSTANCE.targetToSource( target ); - - assertThat( source ).isNotNull(); - assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); - assertThat( source.getAnotherDate() ).isEqualTo( - new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() - ); - } - - @ProcessorTest - @EnabledOnJre(JRE.JAVA_8) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ - public void shouldApplyDateFormatForConversionInReverseMappingWithCustomLocale() { - Target target = new Target(); - target.setDate( "juillet 06, 2013" ); - target.setAnotherDate( "14.02.13 8:30" ); - - Source source = SourceTargetMapper.INSTANCE.targetToSourceWithCustomLocale( target ); - - assertThat( source ).isNotNull(); - assertThat( source.getDate() ).isEqualTo( new GregorianCalendar( 2013, Calendar.JULY, 6 ).getTime() ); - assertThat( source.getAnotherDate() ).isEqualTo( - new GregorianCalendar( 2013, Calendar.FEBRUARY, 14, 8, 30 ).getTime() - ); - } - - @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_11) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { Target target = new Target(); target.setDate( "06.07.2013" ); @@ -151,8 +78,6 @@ public void shouldApplyDateFormatForConversionInReverseMappingJdk11() { } @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_11) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void shouldApplyDateFormatForConversionInReverseMappingJdk11WithCustomLocale() { Target target = new Target(); target.setDate( "juillet 06, 2013" ); diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java index 8574c7a6be..d447c455ff 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/jodatime/JodaConversionTest.java @@ -13,8 +13,6 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; -import org.junit.jupiter.api.condition.EnabledForJreRange; -import org.junit.jupiter.api.condition.JRE; import org.junitpioneer.jupiter.DefaultLocale; import org.mapstruct.ap.testutil.IssueKey; import org.mapstruct.ap.testutil.ProcessorTest; @@ -71,8 +69,6 @@ public void testLocalTimeToString() { } @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_21) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ public void testSourceToTargetMappingForStrings() { Source src = new Source(); src.setLocalTime( new LocalTime( 0, 0 ) ); @@ -98,34 +94,6 @@ public void testSourceToTargetMappingForStrings() { assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); } - @ProcessorTest - @EnabledForJreRange(min = JRE.JAVA_11, max = JRE.JAVA_17) - // See https://bugs.openjdk.java.net/browse/JDK-8211262, there is a difference in the default formats on Java 9+ - public void testSourceToTargetMappingForStringsJdk11() { - Source src = new Source(); - src.setLocalTime( new LocalTime( 0, 0 ) ); - src.setLocalDate( new LocalDate( 2014, 1, 1 ) ); - src.setLocalDateTime( new LocalDateTime( 2014, 1, 1, 0, 0 ) ); - src.setDateTime( new DateTime( 2014, 1, 1, 0, 0, 0, DateTimeZone.UTC ) ); - - // with given format - Target target = SourceTargetMapper.INSTANCE.sourceToTarget( src ); - - assertThat( target ).isNotNull(); - assertThat( target.getDateTime() ).isEqualTo( "01.01.2014 00:00 UTC" ); - assertThat( target.getLocalDateTime() ).isEqualTo( "01.01.2014 00:00" ); - assertThat( target.getLocalDate() ).isEqualTo( "01.01.2014" ); - assertThat( target.getLocalTime() ).isEqualTo( "00:00" ); - - // and now with default mappings - target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( src ); - assertThat( target ).isNotNull(); - assertThat( target.getDateTime() ).isEqualTo( "1. Januar 2014 um 00:00:00 UTC" ); - assertThat( target.getLocalDateTime() ).isEqualTo( "1. Januar 2014 um 00:00:00" ); - assertThat( target.getLocalDate() ).isEqualTo( "1. Januar 2014" ); - assertThat( target.getLocalTime() ).isEqualTo( "00:00:00" ); - } - @ProcessorTest public void testStringToDateTime() { String dateTimeAsString = "01.01.2014 00:00 UTC"; diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java index 115618382c..1e9a1bc22f 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/JdkCompilingExtension.java @@ -12,9 +12,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Objects; import javax.annotation.processing.Processor; -import javax.tools.Diagnostic.Kind; import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaCompiler.CompilationTask; @@ -23,10 +21,8 @@ import javax.tools.StandardLocation; import javax.tools.ToolProvider; -import org.junit.jupiter.api.condition.JRE; import org.mapstruct.ap.MappingProcessor; import org.mapstruct.ap.testutil.compilation.model.CompilationOutcomeDescriptor; -import org.mapstruct.ap.testutil.compilation.model.DiagnosticDescriptor; /** * Extension that uses the JDK compiler to compile. @@ -140,35 +136,6 @@ private static List asFiles(List paths) { return classpath; } - /** - * The JDK 8 compiler needs some special treatment for the diagnostics. - * See comment in the function. - */ - @Override - protected List filterExpectedDiagnostics(List expectedDiagnostics) { - if ( JRE.currentVersion() != JRE.JAVA_8 ) { - // The JDK 8+ compilers report all ERROR diagnostics properly. Also when there are multiple per line. - return expectedDiagnostics; - } - List filtered = new ArrayList<>(expectedDiagnostics.size()); - - // The JDK 8 compiler only reports the first message of kind ERROR that is reported for one source file line, - // so we filter out the surplus diagnostics. The input list is already sorted by file name and line number, - // with the order for the diagnostics in the same line being kept at the order as given in the test. - DiagnosticDescriptor previous = null; - for ( DiagnosticDescriptor diag : expectedDiagnostics ) { - if ( diag.getKind() != Kind.ERROR - || previous == null - || !previous.getSourceFileName().equals( diag.getSourceFileName() ) - || !Objects.equals( previous.getLine(), diag.getLine() ) ) { - filtered.add( diag ); - previous = diag; - } - } - - return filtered; - } - private static FilteringParentClassLoader newFilteringClassLoaderForJdk() { return new FilteringParentClassLoader( "kotlin.", From 73f042bdc5906a3d5a0774c6535dabce64a83799 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 31 Jan 2026 17:25:06 +0100 Subject: [PATCH 0932/1006] Use explicit version instead of JRE#OTHER to disable on Java 27-ea `@DisabledOnJre(JRE.OTHER)` no longer disables the test if the JRE is unknown. --- .../org/mapstruct/itest/tests/MavenIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java index 4596efd630..60784d206a 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java @@ -89,7 +89,7 @@ void jsr330Test() { @ProcessorTest(baseDir = "lombokBuilderTest", processorTypes = { ProcessorTest.ProcessorType.JAVAC }) - @DisabledOnJre(JRE.OTHER) + @DisabledOnJre(versions = 27) void lombokBuilderTest() { } @@ -98,7 +98,7 @@ void lombokBuilderTest() { ProcessorTest.ProcessorType.JAVAC_WITH_PATHS }) @EnabledForJreRange(min = JRE.JAVA_11) - @DisabledOnJre(JRE.OTHER) + @DisabledOnJre(versions = 27) void lombokModuleTest() { } @@ -155,7 +155,7 @@ void expressionTextBlocksTest() { }, forkJvm = true) // We have to fork the jvm because there is an NPE in com.intellij.openapi.util.SystemInfo.getRtVersion // and the kotlin-maven-plugin uses that. See also https://youtrack.jetbrains.com/issue/IDEA-238907 - @DisabledOnJre(JRE.OTHER) + @DisabledOnJre(versions = 27) void kotlinDataTest() { } From 6708e3592539ec5b4f94c09643c039e359b78eae Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sat, 31 Jan 2026 19:49:02 +0100 Subject: [PATCH 0933/1006] Remove testing with no longer maintained org.bsc.maven:maven-processor-plugin The last release of the plugin was in April 2024. In addition to that, the maven-compiler-plugin is de-facto the standard for compiling Java. Therefore, we are removing testing with the maven-processor-plugin. --- .../ProcessorInvocationInterceptor.java | 23 +++++------- .../testutil/extension/ProcessorTest.java | 5 +-- integrationtest/src/test/resources/pom.xml | 37 ------------------- 3 files changed, 10 insertions(+), 55 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java index 85ce64952f..39cd5fdae6 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorInvocationInterceptor.java @@ -136,21 +136,16 @@ private void addAdditionalCliArguments(Verifier verifier) private void configureProcessor(Verifier verifier) { ProcessorTest.ProcessorType processor = processorTestContext.getProcessor(); String compilerId = processor.getCompilerId(); - if ( compilerId != null ) { - String profile = processor.getProfile(); - if ( profile == null ) { - profile = "generate-via-compiler-plugin"; + String profile = processor.getProfile(); + if ( profile == null ) { + profile = "generate-via-compiler-plugin"; + } + verifier.addCliOption( "-P" + profile ); + verifier.addCliOption( "-Dcompiler-id=" + compilerId ); + if ( processor == ProcessorTest.ProcessorType.JAVAC ) { + if ( CURRENT_VERSION.ordinal() >= JRE.JAVA_21.ordinal() ) { + verifier.addCliOption( "-Dmaven.compiler.proc=full" ); } - verifier.addCliOption( "-P" + profile ); - verifier.addCliOption( "-Dcompiler-id=" + compilerId ); - if ( processor == ProcessorTest.ProcessorType.JAVAC ) { - if ( CURRENT_VERSION.ordinal() >= JRE.JAVA_21.ordinal() ) { - verifier.addCliOption( "-Dmaven.compiler.proc=full" ); - } - } - } - else { - verifier.addCliOption( "-Pgenerate-via-processor-plugin" ); } } diff --git a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java index 95480eee9d..d5b4860d5b 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/testutil/extension/ProcessorTest.java @@ -46,9 +46,7 @@ enum ProcessorType { JAVAC( "javac" ), JAVAC_WITH_PATHS( "javac", JRE.OTHER, "generate-via-compiler-plugin-with-annotation-processor-paths" ), - ECLIPSE_JDT( "jdt", JRE.JAVA_8 ), - - PROCESSOR_PLUGIN( null, JRE.JAVA_8 ); + ECLIPSE_JDT( "jdt", JRE.JAVA_8 ); private final String compilerId; private final JRE max; @@ -111,7 +109,6 @@ ProcessorType[] processorTypes() default { ProcessorType.JAVAC, ProcessorType.JAVAC_WITH_PATHS, ProcessorType.ECLIPSE_JDT, - ProcessorType.PROCESSOR_PLUGIN }; /** diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index c8a19228f0..c2ece3b38d 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -97,43 +97,6 @@ - - generate-via-processor-plugin - - false - - - - - org.bsc.maven - maven-processor-plugin - 3.3.3 - - - process - generate-sources - - process - - - - - \${project.build.directory}/generated-sources/mapstruct - - org.mapstruct.ap.MappingProcessor - - - - - ${project.groupId} - mapstruct-processor - ${mapstruct.version} - - - - - - debug-forked-javac From df97305df070ee5a33233a9072bd4c38d8d99e53 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 12:09:53 +0100 Subject: [PATCH 0934/1006] #3940 Use deterministic order for supporting fields and methods --- .../ap/internal/model/BeanMappingMethod.java | 4 ++-- .../ap/internal/model/SupportingField.java | 2 +- .../creation/MappingResolverImpl.java | 7 ++++--- .../numbers/SourceTargetMapperImpl.java | 8 ++++---- .../OptionalSourceTargetMapperImpl.java | 20 +++++++++---------- .../java8time/SourceTargetMapperImpl.java | 20 +++++++++---------- .../numbers/SourceTargetMapperImpl.java | 8 ++++---- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index c6fc7753f2..d67b550ad4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -301,8 +301,8 @@ else if ( !method.isUpdateMethod() ) { } // get bean mapping (when specified as annotation ) - this.missingIgnoredSourceProperties = new HashSet<>(); - this.redundantIgnoredSourceProperties = new HashSet<>(); + this.missingIgnoredSourceProperties = new LinkedHashSet<>(); + this.redundantIgnoredSourceProperties = new LinkedHashSet<>(); if ( beanMapping != null && !beanMapping.getIgnoreUnmappedSourceProperties().isEmpty() ) { // Get source properties explicitly mapped using @Mapping annotations Set mappedSourceProperties = method.getOptions().getMappings().stream() diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java index caf6d6160e..2cac1ef351 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/SupportingField.java @@ -47,7 +47,7 @@ public static void addAllFieldsIn(Set supportingMapping for ( SupportingMappingMethod supportingMappingMethod : supportingMappingMethods ) { Field field = supportingMappingMethod.getSupportingField(); if ( field != null ) { - targets.add( supportingMappingMethod.getSupportingField() ); + targets.add( field ); } } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java index 2a36f6b890..67cdc09fc9 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java @@ -13,6 +13,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -97,12 +98,12 @@ public class MappingResolverImpl implements MappingResolver { * Private methods which are not present in the original mapper interface and are added to map certain property * types. */ - private final Set usedSupportedMappings = new HashSet<>(); + private final Set usedSupportedMappings = new LinkedHashSet<>(); /** * Private fields which are added to map certain property types. */ - private final Set usedSupportedFields = new HashSet<>(); + private final Set usedSupportedFields = new LinkedHashSet<>(); public MappingResolverImpl(FormattingMessager messager, ElementUtils elementUtils, TypeUtils typeUtils, TypeFactory typeFactory, List sourceModel, @@ -199,7 +200,7 @@ private ResolvingAttempt(List sourceModel, Method mappingMethod, ForgedM this.formattingParameters = formattingParameters == null ? FormattingParameters.EMPTY : formattingParameters; this.sourceRHS = sourceRHS; - this.supportingMethodCandidates = new HashSet<>(); + this.supportingMethodCandidates = new LinkedHashSet<>(); this.selectionCriteria = criteria; this.positionHint = positionHint; this.forger = forger; diff --git a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java index ccf8042e6b..941bd929a7 100644 --- a/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/21/org/mapstruct/ap/test/conversion/numbers/SourceTargetMapperImpl.java @@ -509,16 +509,16 @@ public Map targetToSourceWithCustomLocale(Map targetToSourceWithCustomLocale(Map Date: Sun, 1 Feb 2026 12:41:20 +0100 Subject: [PATCH 0935/1006] #1830 Add support for NullValuePropertyMappingStrategy.CLEAR strategy Using this strategy will clear target collections / maps when the source property is null --- NEXT_RELEASE_CHANGELOG.md | 1 + .../NullValuePropertyMappingStrategy.java | 9 +- ...apter-10-advanced-mapping-options.asciidoc | 3 + .../NullValuePropertyMappingStrategyGem.java | 3 +- ...nceSetterWrapperForCollectionsAndMaps.java | 27 ++-- .../model/source/MapperConfigOptions.java | 2 +- .../internal/model/source/MapperOptions.java | 2 +- ...anceSetterWrapperForCollectionsAndMaps.ftl | 8 +- .../nullvaluepropertymapping/clear/Bean.java | 40 ++++++ .../clear/BeanDTO.java | 40 ++++++ .../clear/BeanDTOWithId.java | 19 +++ .../clear/BeanMapper.java | 34 +++++ .../clear/BeanMapperWithStrategyOnMapper.java | 25 ++++ .../clear/NestedBean.java | 18 +++ .../NullValuePropertyMappingClearTest.java | 116 ++++++++++++++++++ 15 files changed, 329 insertions(+), 18 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/Bean.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTO.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTOWithId.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapperWithStrategyOnMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NestedBean.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NullValuePropertyMappingClearTest.java diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 59fed4fed3..476f3e025d 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -22,6 +22,7 @@ it will be treated as a potential builder. Builders through static methods on the type have a precedence. * Behaviour change: Warning when the target has no target properties (#1140) +* Add new `NullValuePropertyMappingStrategy#CLEAR` for clearing Collection and Map properties when updating a bean (#1830) diff --git a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java index a58eed8a2a..0ab30d5271 100644 --- a/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java +++ b/core/src/main/java/org/mapstruct/NullValuePropertyMappingStrategy.java @@ -56,5 +56,12 @@ public enum NullValuePropertyMappingStrategy { * If a source bean property equals {@code null} the target bean property will be ignored and retain its * existing value. */ - IGNORE; + IGNORE, + + /** + * If a source bean property equals {@code null} the target bean property will be cleared. + * This strategy is only applicable to target properties that are of type {@link java.util.Collection Collection} + * or {@link java.util.Map Map}. + */ + CLEAR; } diff --git a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc index 43f8fc38a0..34f1e19817 100644 --- a/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc +++ b/documentation/src/main/asciidoc/chapter-10-advanced-mapping-options.asciidoc @@ -254,6 +254,9 @@ For all other objects an new instance is created. Please note that a default con 2. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the mapping result will be equal to the original value of the `@MappingTarget` annotated target. +3. By specifying `nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR` on `@Mapping`, `@BeanMapping`, `@Mapper` or `@MapperConfig`, the target collection or map will be cleared when the source property is `null`. +This strategy only applies to `Collection` and `Map` target properties. + The strategy works in a hierarchical fashion. Setting `nullValuePropertyMappingStrategy` on mapping method level will override `@Mapper#nullValuePropertyMappingStrategy`, and `@Mapper#nullValuePropertyMappingStrategy` will override `@MapperConfig#nullValuePropertyMappingStrategy`. [NOTE] diff --git a/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java index 77e4aa48d6..93c98b73ac 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/gem/NullValuePropertyMappingStrategyGem.java @@ -15,5 +15,6 @@ public enum NullValuePropertyMappingStrategyGem { SET_TO_NULL, SET_TO_DEFAULT, - IGNORE; + IGNORE, + CLEAR; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java index 2dd7f81a0b..875368b014 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.java @@ -5,19 +5,18 @@ */ package org.mapstruct.ap.internal.model.assignment; -import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; -import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; - import java.util.HashSet; import java.util.List; import java.util.Set; +import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; +import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; import org.mapstruct.ap.internal.model.common.TypeFactory; -import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; -import org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem; + +import static org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem.ALWAYS; +import static org.mapstruct.ap.internal.gem.NullValuePropertyMappingStrategyGem.IGNORE; /** * This wrapper handles the situation where an assignment is done for an update method. @@ -34,8 +33,8 @@ public class ExistingInstanceSetterWrapperForCollectionsAndMaps extends SetterWrapperForCollectionsAndMapsWithNullCheck { - private final boolean includeElseBranch; - private final boolean mapNullToDefault; + private final NullValuePropertyMappingStrategyGem nvpms; + private final NullValueCheckStrategyGem nvcs; private final Type targetType; public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAssignment, @@ -53,9 +52,9 @@ public ExistingInstanceSetterWrapperForCollectionsAndMaps(Assignment decoratedAs typeFactory, fieldAssignment ); - this.mapNullToDefault = SET_TO_DEFAULT == nvpms; + this.nvcs = nvcs; + this.nvpms = nvpms; this.targetType = targetType; - this.includeElseBranch = ALWAYS != nvcs && IGNORE != nvpms; } @Override @@ -68,11 +67,15 @@ public Set getImportTypes() { } public boolean isIncludeElseBranch() { - return includeElseBranch; + return nvcs != ALWAYS && nvpms != IGNORE; } public boolean isMapNullToDefault() { - return mapNullToDefault; + return nvpms == NullValuePropertyMappingStrategyGem.SET_TO_DEFAULT; + } + + public boolean isMapNullToClear() { + return nvpms == NullValuePropertyMappingStrategyGem.CLEAR; } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java index d606658878..2766faa64c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperConfigOptions.java @@ -8,8 +8,8 @@ import java.util.Set; import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; import org.mapstruct.ap.internal.gem.InjectionStrategyGem; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java index 9c2203efd5..21cb7813c4 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MapperOptions.java @@ -12,8 +12,8 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import org.mapstruct.ap.internal.util.ElementUtils; +import org.mapstruct.ap.internal.util.ElementUtils; import org.mapstruct.ap.internal.option.Options; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.CollectionMappingStrategyGem; diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl index 95662c4c79..8e771f0ddb 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/ExistingInstanceSetterWrapperForCollectionsAndMaps.ftl @@ -15,8 +15,12 @@ ${ext.targetBeanName}.${ext.targetReadAccessorName}.<#if ext.targetType.collectionType>addAll<#else>putAll( <@lib.handleWithAssignmentOrNullCheckVar/> ); <#if !ext.defaultValueAssignment?? && !sourcePresenceCheckerReference?? && includeElseBranch>else {<#-- the opposite (defaultValueAssignment) case is handeld inside lib.handleLocalVarNullCheck --> - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; - } + <#if mapNullToClear> + ${ext.targetBeanName}.${ext.targetReadAccessorName}.clear(); + <#else > + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if mapNullToDefault><@lib.initTargetObject/><#else>null; + + } } else { diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/Bean.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/Bean.java new file mode 100644 index 0000000000..545ddffe8b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/Bean.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +import java.util.Collection; +import java.util.Map; + +public class Bean { + + private String id; + private Collection list; + private Map map; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Collection getList() { + return list; + } + + public void setList(Collection list) { + this.list = list; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTO.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTO.java new file mode 100644 index 0000000000..9529da8113 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTO.java @@ -0,0 +1,40 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +import java.util.Collection; +import java.util.Map; + +public class BeanDTO { + + private String id; + private Collection list; + private Map map; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public Collection getList() { + return list; + } + + public void setList(Collection list) { + this.list = list; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTOWithId.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTOWithId.java new file mode 100644 index 0000000000..152a872d82 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanDTOWithId.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +public class BeanDTOWithId extends BeanDTO { + + private String id; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapper.java new file mode 100644 index 0000000000..4d453579ea --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapper.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface BeanMapper { + + BeanMapper INSTANCE = Mappers.getMapper( BeanMapper.class ); + + @Mapping(target = "list", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) + @Mapping(target = "map", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) + BeanDTO map(Bean source, @MappingTarget BeanDTO target); + + @Mapping(target = "id", source = "bean.id") + @Mapping(target = "list", source = "bean.list", + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) + @Mapping(target = "map", source = "bean.map", + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) + BeanDTO map(NestedBean source, @MappingTarget BeanDTO target); + + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) + BeanDTO mapWithBeanMapping(Bean source, @MappingTarget BeanDTO target); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapperWithStrategyOnMapper.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapperWithStrategyOnMapper.java new file mode 100644 index 0000000000..0e26b91b5b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/BeanMapperWithStrategyOnMapper.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.CLEAR) +public interface BeanMapperWithStrategyOnMapper { + + BeanMapperWithStrategyOnMapper INSTANCE = Mappers.getMapper( BeanMapperWithStrategyOnMapper.class ); + + BeanDTO map(Bean source, @MappingTarget BeanDTO target); + + @Mapping(target = "id", source = "bean.id") + @Mapping(target = "list", source = "bean.list") + @Mapping(target = "map", source = "bean.map") + BeanDTO map(NestedBean source, @MappingTarget BeanDTO target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NestedBean.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NestedBean.java new file mode 100644 index 0000000000..448645c107 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NestedBean.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +public class NestedBean { + private Bean bean; + + public Bean getBean() { + return bean; + } + + public void setBean(Bean bean) { + this.bean = bean; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NullValuePropertyMappingClearTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NullValuePropertyMappingClearTest.java new file mode 100644 index 0000000000..20cbcdc2b4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/clear/NullValuePropertyMappingClearTest.java @@ -0,0 +1,116 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.nullvaluepropertymapping.clear; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +@WithClasses({ + Bean.class, + BeanDTO.class, + NestedBean.class, +}) +class NullValuePropertyMappingClearTest { + + @ProcessorTest + @WithClasses(BeanMapper.class) + void generatedMapperMethodsShouldCallClear() { + BeanDTO target = new BeanDTO(); + target.setId( "target" ); + List targetList = new ArrayList<>(); + targetList.add( "a" ); + targetList.add( "b" ); + target.setList( targetList ); + Map targetMap = new HashMap<>(); + targetMap.put( "a", "aValue" ); + target.setMap( targetMap ); + Bean source = new Bean(); + + BeanMapper.INSTANCE.map( source, target ); + assertThat( target.getId() ).isNull(); + assertThat( target.getList() ) + .isSameAs( targetList ) + .isEmpty(); + assertThat( target.getMap() ) + .isSameAs( targetMap ) + .isEmpty(); + + NestedBean nestedBean = new NestedBean(); + nestedBean.setBean( source ); + targetList.add( "a" ); + targetList.add( "b" ); + targetMap.put( "a", "aValue" ); + target.setId( "target" ); + BeanMapper.INSTANCE.map( nestedBean, target ); + assertThat( target.getId() ).isNull(); + assertThat( target.getList() ) + .isSameAs( targetList ) + .isEmpty(); + assertThat( target.getMap() ) + .isSameAs( targetMap ) + .isEmpty(); + + targetList.add( "a" ); + targetList.add( "b" ); + targetMap.put( "a", "aValue" ); + target.setId( "target" ); + BeanMapper.INSTANCE.mapWithBeanMapping( source, target ); + assertThat( target.getId() ).isNull(); + assertThat( target.getList() ) + .isSameAs( targetList ) + .isEmpty(); + assertThat( target.getMap() ) + .isSameAs( targetMap ) + .isEmpty(); + } + + @ProcessorTest + @WithClasses(BeanMapperWithStrategyOnMapper.class) + void generatedMapperWithMappingDefinedInConfigMethodsShouldCallClear() { + BeanDTO target = new BeanDTO(); + target.setId( "target" ); + List targetList = new ArrayList<>(); + targetList.add( "a" ); + targetList.add( "b" ); + target.setList( targetList ); + Map targetMap = new HashMap<>(); + targetMap.put( "a", "aValue" ); + target.setMap( targetMap ); + Bean source = new Bean(); + + BeanMapperWithStrategyOnMapper.INSTANCE.map( source, target ); + assertThat( target.getId() ).isNull(); + assertThat( target.getList() ) + .isSameAs( targetList ) + .isEmpty(); + assertThat( target.getMap() ) + .isSameAs( targetMap ) + .isEmpty(); + + NestedBean nestedBean = new NestedBean(); + nestedBean.setBean( source ); + targetList.add( "a" ); + targetList.add( "b" ); + targetMap.put( "a", "aValue" ); + target.setId( "target" ); + BeanMapperWithStrategyOnMapper.INSTANCE.map( nestedBean, target ); + assertThat( target.getId() ).isNull(); + assertThat( target.getList() ) + .isSameAs( targetList ) + .isEmpty(); + assertThat( target.getMap() ) + .isSameAs( targetMap ) + .isEmpty(); + } + +} From a5614dd798dbb6c07ed41e21708eaa2ecd153aad Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 19:41:07 +0100 Subject: [PATCH 0936/1006] Prepare release notes and update copyright.txt --- NEXT_RELEASE_CHANGELOG.md | 47 ++++++++++++++++++++++++++++++++++----- copyright.txt | 14 +++++++++++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index 476f3e025d..c4ba49e24d 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -13,7 +13,7 @@ - Data classes with multiple constructors - Data classes with all default parameters - Sealed Classes (#3404) - Subclass exhaustiveness is now checked for Kotlin sealed classes - +* Add support for ignoring multiple target properties at once (#3838) - Using new annotation `@Ignored` ### Enhancements @@ -21,22 +21,59 @@ * Detect Builder without a factory method (#3729) - With this if there is an inner class that ends with `Builder` and has a constructor with parameters, it will be treated as a potential builder. Builders through static methods on the type have a precedence. -* Behaviour change: Warning when the target has no target properties (#1140) +* Add support for custom exception for subclass exhaustive strategy for `@SubclassMapping` mapping (#3821) - Available on `@BeanMapping`, `@Mapper` and `@MappingConfig`. * Add new `NullValuePropertyMappingStrategy#CLEAR` for clearing Collection and Map properties when updating a bean (#1830) - - +* Use deterministic order for supporting fields and methods (#3940) +* Support `@AnnotatedWith` on decorators (#3659) +* Behaviour change: Add warning/error for redundant `ignoreUnmappedSourceProperties` entries (#3906) +* Behaviour change: Warning when the target has no target properties (#1140) +* Behaviour change: Initialize `Optional` with `Optional.empty` instead of `null` (#3852) +* Behaviour change: Mark `String` to `Number` as lossy conversion (#3848) ### Bugs * Improve error message when mapping non-iterable to array (#3786) +* Fix conditional mapping with `@TargetPropertyName` failing for nested update mappings (#3809) +* Resolve duplicate invocation of overloaded lifecycle methods with inheritance (#3849) - It is possible to disable this by using the new compiler option `mapstruct.disableLifecycleOverloadDeduplicateSelector`. +* Support generic `@Context` (#3711) +* Properly apply `NullValuePropertyMappingStrategy.IGNORE` for collections / maps without setters (#3806) +* Properly recognize the type of public generic fields (#3807) +* Fix method in Record is treated as a fluent setter (#3886) +* Ensure `NullValuePropertyMappingStrategy.SET_TO_DEFAULT` initializes empty collection/map when target is null (#3884) +* Fix Compiler error when mapping an object named `Override` (#3905) ### Documentation +* General Improvements + * Javadoc + * Typos in comments + * Small code refactorings + ### Build +* Move Windows and MacOS builds outside of the main workflow +* Update release to release using the new Maven Central Portal +* Skip codecov coverage on forks +* Improve testing support for Kotlin + ### Behaviour Change -#### Warning when the target has no target properties +#### Warning when the target has no target properties (#1140) With this change, if the target bean does not have any target properties, a warning will be shown. This is like this to avoid potential mistakes by users, where they might think that the target bean has properties, but it does not. + +#### Warning for redundant `ignoreUnmappedSourceProperties` entries (#3906) + +With this change, if the `ignoreUnmappedSourceProperties` configuration contains properties that are actually mapped, a warning or compiler error will be shown. +The `unmappedSourcePolicy` is used to determine whether a warning, or an error is shown. + +#### Initialize `Optional` with `Optional.empty` instead of `null` (#3852) + +With this change, if the target `Optional` property is null, it will be initialized with `Optional.empty()` instead of `null`. + +#### Mark `String` to `Number` as lossy conversion (#3848) + +With this change, if the source `String` property is mapped to a `Number` property, a warning will be shown. +This is similar to what is happening when mapping `long` to `int`, etc. +The `typeConversionPolicy` `ReportingPolicy` is used to determine whether a warning, error or ignore is shown. diff --git a/copyright.txt b/copyright.txt index bd0034b076..356deb904d 100644 --- a/copyright.txt +++ b/copyright.txt @@ -1,12 +1,14 @@ Contributors ============ +Aleksey Ivashin - https://github.com/xumk Alexandr Shalugin - https://github.com/shalugin Amine Touzani - https://github.com/ttzn Andreas Gudian - https://github.com/agudian Andrei Arlou - https://github.com/Captain1653 Andres Jose Sebastian Rincon Gonzalez - https://github.com/stianrincon Arne Seime - https://github.com/seime +Cause Chung - https://github.com/cuzfrog Christian Bandowski - https://github.com/chris922 Chris DeLashmutt - https://github.com/cdelashmutt-pivotal Christian Kosmowski - https://github.com/ckosmowski @@ -15,6 +17,7 @@ Christophe Labouisse - https://github.com/ggtools Ciaran Liedeman - https://github.com/cliedeman Cindy Wang - https://github.com/birdfriend Cornelius Dirmeier - https://github.com/cornzy +Dennis Melzer - https://github.com/ David Feinblum - https://github.com/dvfeinblum Darren Rambaud - https://github.com/xyzst Dekel Pilli - https://github.com/dekelpilli @@ -53,7 +56,11 @@ Pavel Makhov - https://github.com/streetturtle Peter Larson - https://github.com/pjlarson Remko Plantenga - https://github.com/sonata82 Remo Meier - https://github.com/remmeier +Roel Mangelschots - https://github.com/rmschots +Ritesh Chopade - https://github.com/codeswithritesh Richard Lea - https://github.com/chigix +Roman Obolonskyi - https://github.com/Obolrom +Samil Can - https://github.com/SamilCan Saheb Preet Singh - https://github.com/sahebpreet Samuel Wright - https://github.com/samwright Sebastian Haberey - https://github.com/sebastianhaberey @@ -65,10 +72,15 @@ Taras Mychaskiw - https://github.com/twentylemon Thibault Duperron - https://github.com/Zomzog Tomáš Poledný - https://github.com/Saljack Tobias Meggendorfer - https://github.com/incaseoftrouble +Tran Ngoc Nhan - https://github.com/ Tillmann Gaida - https://github.com/Tillerino Timo Eckhardt - https://github.com/timoe Tomek Gubala - https://github.com/vgtworld Valentin Kulesh - https://github.com/unshare Vincent Alexander Beelte - https://github.com/grandmasterpixel Winter Andreas - https://github.dev/wandi34 -Xiu Hong Kooi - https://github.com/kooixh \ No newline at end of file +Xiu Hong Kooi - https://github.com/kooixh +Yang Tang - https://github.com/tangyang9464 +Zegveld - https://github.com/Zegveld +znight1020 - https://github.com/znight1020 +zral - https://github.com/zyberzebra From 14f9f6e2877e5ae1b28ce3b59e381628f72fa349 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 20:10:29 +0000 Subject: [PATCH 0937/1006] Releasing version 1.7.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..b1545ceb00 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..42ea5baec4 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..b3af781388 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b480e24a06..fb4444e00d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..d36a6428d6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 71a61fc2fe..a9037e613c 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index f2b85d4969..ae877ef10c 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2026-02-01T20:10:28Z 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index f55f0955d3..114085f46e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 622ba924ee..608175a8e2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml From 561d5dad858a4ba621bcab1f50452ea3851c17eb Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 21:56:00 +0100 Subject: [PATCH 0938/1006] Adjust release to use Maven Central Publishing Portal --- .github/workflows/release.yml | 2 ++ parent/pom.xml | 31 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b4dffe0586..a4feca94a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,6 +62,8 @@ jobs: JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: ${{ secrets.SONATYPE_CENTRAL_USERNAME }} + JRELEASER_MAVENCENTRAL_SONATYPE_TOKEN: ${{ secrets.SONATYPE_CENTRAL_TOKEN }} JRELEASER_NEXUS2_MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} JRELEASER_NEXUS2_MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} run: | diff --git a/parent/pom.xml b/parent/pom.xml index ae877ef10c..0043cfb44a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -880,24 +880,21 @@ - - - ALWAYS - https://oss.sonatype.org/service/local - https://oss.sonatype.org/content/repositories/snapshots/ - true - true + + + RELEASE + https://central.sonatype.com/api/v1/publisher ${maven.multiModuleProjectDirectory}/target/staging-deploy - - - org.mapstruct - mapstruct-jdk8 - false - false - - - - + + + + org.mapstruct + mapstruct-jdk8 + false + false + + + From 6389f2a8056b01e792d02acee6dd1bf9ef3a3718 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 21:58:29 +0100 Subject: [PATCH 0939/1006] Revert "Releasing version 1.7.0.Beta1" This reverts commit 14f9f6e2877e5ae1b28ce3b59e381628f72fa349. --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index b1545ceb00..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 42ea5baec4..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index b3af781388..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index fb4444e00d..b480e24a06 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index d36a6428d6..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a9037e613c..71a61fc2fe 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 0043cfb44a..01b97c10bf 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2026-02-01T20:10:28Z + ${git.commit.author.time} 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index 114085f46e..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 608175a8e2..622ba924ee 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml From ab72ced6fb7a71591d51343493bf736379c61beb Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 20:59:33 +0000 Subject: [PATCH 0940/1006] Releasing version 1.7.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..b1545ceb00 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..42ea5baec4 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..b3af781388 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b480e24a06..fb4444e00d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..d36a6428d6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 71a61fc2fe..a9037e613c 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 01b97c10bf..f81ea2c5d1 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2026-02-01T20:59:32Z 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index f55f0955d3..114085f46e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 622ba924ee..608175a8e2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml From fc2d5e520c5bceff54c302641431465410bdf031 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 22:44:20 +0100 Subject: [PATCH 0941/1006] Move jReleaser artifactOverrides in the right place --- parent/pom.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index f81ea2c5d1..962839bf19 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -885,15 +885,15 @@ RELEASE https://central.sonatype.com/api/v1/publisher ${maven.multiModuleProjectDirectory}/target/staging-deploy + + + org.mapstruct + mapstruct-jdk8 + false + false + + - - - org.mapstruct - mapstruct-jdk8 - false - false - - From 744c398326e9fa281134330dafdbdfecf1653c02 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 1 Feb 2026 22:44:32 +0100 Subject: [PATCH 0942/1006] Revert "Releasing version 1.7.0.Beta1" This reverts commit ab72ced6fb7a71591d51343493bf736379c61beb. --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index b1545ceb00..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 42ea5baec4..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index b3af781388..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index fb4444e00d..b480e24a06 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index d36a6428d6..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a9037e613c..71a61fc2fe 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 962839bf19..8a46290cb8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2026-02-01T20:59:32Z + ${git.commit.author.time} 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index 114085f46e..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 608175a8e2..622ba924ee 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml From 84318113ae02adae62e1d92ee5b884d6b58337b1 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 21:45:33 +0000 Subject: [PATCH 0943/1006] Releasing version 1.7.0.Beta1 --- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 ++-- pom.xml | 2 +- processor/pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build-config/pom.xml b/build-config/pom.xml index 0b3ca1c113..b1545ceb00 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index c73676192b..42ea5baec4 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index e62d5e4682..b3af781388 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index b480e24a06..fb4444e00d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index 21a2b151bd..d36a6428d6 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index 71a61fc2fe..a9037e613c 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 8a46290cb8..02fd68fcff 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - ${git.commit.author.time} + 2026-02-01T21:45:32Z 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index f55f0955d3..114085f46e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 622ba924ee..608175a8e2 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0-SNAPSHOT + 1.7.0.Beta1 ../parent/pom.xml From c7a0385903bfadfb8ef4779be2707b469fc2ace1 Mon Sep 17 00:00:00 2001 From: GitHub Action <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 22:02:16 +0000 Subject: [PATCH 0944/1006] Next version 1.7.0-SNAPSHOT --- NEXT_RELEASE_CHANGELOG.md | 69 --------------------------------------- build-config/pom.xml | 2 +- core-jdk8/pom.xml | 2 +- core/pom.xml | 2 +- distribution/pom.xml | 2 +- documentation/pom.xml | 2 +- integrationtest/pom.xml | 2 +- parent/pom.xml | 4 +-- pom.xml | 2 +- processor/pom.xml | 2 +- 10 files changed, 10 insertions(+), 79 deletions(-) diff --git a/NEXT_RELEASE_CHANGELOG.md b/NEXT_RELEASE_CHANGELOG.md index c4ba49e24d..e0f4cd31f0 100644 --- a/NEXT_RELEASE_CHANGELOG.md +++ b/NEXT_RELEASE_CHANGELOG.md @@ -1,79 +1,10 @@ ### Features -* Support for Java 21 Sequenced Collections (#3240) -* Native support for `java.util.Optional` mapping (#674) - MapStruct now fully supports Optional as both source and target types: - - `Optional` to `Optional` - Both source and target wrapped in `Optional` - - `Optional` to Non-`Optional` - Unwrapping `Optional` values - - Non-`Optional` to `Optional` - Wrapping values in `Optional` - - `Optional` properties in beans with automatic presence checks. Note, there is no null check done for `Optional` properties. -* Improved support for Kotlin. Requires use of `org.jetbrains.kotlin:kotlin-metadata-jvm`. - - Data Classes (#2281, #2577, #3031) - MapStruct now properly handles: - - Single field data classes - - Proper primary constructor detection - - Data classes with multiple constructors - - Data classes with all default parameters - - Sealed Classes (#3404) - Subclass exhaustiveness is now checked for Kotlin sealed classes -* Add support for ignoring multiple target properties at once (#3838) - Using new annotation `@Ignored` - ### Enhancements -* Add support for locale parameter for numberFormat and dateFormat (#3628) -* Detect Builder without a factory method (#3729) - With this if there is an inner class that ends with `Builder` and has a constructor with parameters, -it will be treated as a potential builder. -Builders through static methods on the type have a precedence. -* Add support for custom exception for subclass exhaustive strategy for `@SubclassMapping` mapping (#3821) - Available on `@BeanMapping`, `@Mapper` and `@MappingConfig`. -* Add new `NullValuePropertyMappingStrategy#CLEAR` for clearing Collection and Map properties when updating a bean (#1830) -* Use deterministic order for supporting fields and methods (#3940) -* Support `@AnnotatedWith` on decorators (#3659) -* Behaviour change: Add warning/error for redundant `ignoreUnmappedSourceProperties` entries (#3906) -* Behaviour change: Warning when the target has no target properties (#1140) -* Behaviour change: Initialize `Optional` with `Optional.empty` instead of `null` (#3852) -* Behaviour change: Mark `String` to `Number` as lossy conversion (#3848) - ### Bugs -* Improve error message when mapping non-iterable to array (#3786) -* Fix conditional mapping with `@TargetPropertyName` failing for nested update mappings (#3809) -* Resolve duplicate invocation of overloaded lifecycle methods with inheritance (#3849) - It is possible to disable this by using the new compiler option `mapstruct.disableLifecycleOverloadDeduplicateSelector`. -* Support generic `@Context` (#3711) -* Properly apply `NullValuePropertyMappingStrategy.IGNORE` for collections / maps without setters (#3806) -* Properly recognize the type of public generic fields (#3807) -* Fix method in Record is treated as a fluent setter (#3886) -* Ensure `NullValuePropertyMappingStrategy.SET_TO_DEFAULT` initializes empty collection/map when target is null (#3884) -* Fix Compiler error when mapping an object named `Override` (#3905) - ### Documentation -* General Improvements - * Javadoc - * Typos in comments - * Small code refactorings - ### Build -* Move Windows and MacOS builds outside of the main workflow -* Update release to release using the new Maven Central Portal -* Skip codecov coverage on forks -* Improve testing support for Kotlin - -### Behaviour Change - -#### Warning when the target has no target properties (#1140) - -With this change, if the target bean does not have any target properties, a warning will be shown. -This is like this to avoid potential mistakes by users, where they might think that the target bean has properties, but it does not. - -#### Warning for redundant `ignoreUnmappedSourceProperties` entries (#3906) - -With this change, if the `ignoreUnmappedSourceProperties` configuration contains properties that are actually mapped, a warning or compiler error will be shown. -The `unmappedSourcePolicy` is used to determine whether a warning, or an error is shown. - -#### Initialize `Optional` with `Optional.empty` instead of `null` (#3852) - -With this change, if the target `Optional` property is null, it will be initialized with `Optional.empty()` instead of `null`. - -#### Mark `String` to `Number` as lossy conversion (#3848) - -With this change, if the source `String` property is mapped to a `Number` property, a warning will be shown. -This is similar to what is happening when mapping `long` to `int`, etc. -The `typeConversionPolicy` `ReportingPolicy` is used to determine whether a warning, error or ignore is shown. diff --git a/build-config/pom.xml b/build-config/pom.xml index b1545ceb00..0b3ca1c113 100644 --- a/build-config/pom.xml +++ b/build-config/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core-jdk8/pom.xml b/core-jdk8/pom.xml index 42ea5baec4..c73676192b 100644 --- a/core-jdk8/pom.xml +++ b/core-jdk8/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/core/pom.xml b/core/pom.xml index b3af781388..e62d5e4682 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/distribution/pom.xml b/distribution/pom.xml index fb4444e00d..b480e24a06 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/documentation/pom.xml b/documentation/pom.xml index d36a6428d6..21a2b151bd 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/integrationtest/pom.xml b/integrationtest/pom.xml index a9037e613c..71a61fc2fe 100644 --- a/integrationtest/pom.xml +++ b/integrationtest/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml diff --git a/parent/pom.xml b/parent/pom.xml index 02fd68fcff..8a46290cb8 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -11,7 +11,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT pom MapStruct Parent @@ -28,7 +28,7 @@ ${java.version} ${java.version} - 2026-02-01T21:45:32Z + ${git.commit.author.time} 1.0.0.Alpha3 3.6.2 diff --git a/pom.xml b/pom.xml index 114085f46e..f55f0955d3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT parent/pom.xml diff --git a/processor/pom.xml b/processor/pom.xml index 608175a8e2..622ba924ee 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -12,7 +12,7 @@ org.mapstruct mapstruct-parent - 1.7.0.Beta1 + 1.7.0-SNAPSHOT ../parent/pom.xml From 5cf1a98d29975aa32fa4a6e2a78e2808bc8fdec9 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Feb 2026 11:48:24 +0100 Subject: [PATCH 0945/1006] Fix location for Javadoc when generating distribution zip --- distribution/src/main/assembly/dist.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/src/main/assembly/dist.xml b/distribution/src/main/assembly/dist.xml index f0c727f8da..e0bc00496b 100644 --- a/distribution/src/main/assembly/dist.xml +++ b/distribution/src/main/assembly/dist.xml @@ -76,7 +76,7 @@ - target/site/apidocs + target/reports/apidocs docs/api From 06e27d575365147ed17a991c5cc90a1f63436eda Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 2 Feb 2026 11:56:16 +0100 Subject: [PATCH 0946/1006] Remove unnecessary `keySet()` invocation (#3989) --- .../ap/internal/model/NestedTargetPropertyMappingHolder.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java index 2b407e240c..f7b28b3f84 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedTargetPropertyMappingHolder.java @@ -151,8 +151,7 @@ public NestedTargetPropertyMappingHolder build() { entryByTP.getValue(), groupedByTP.singleTargetReferences.get( targetProperty ) ); - boolean multipleSourceParametersForTP = - groupedBySourceParam.groupedBySourceParameter.keySet().size() > 1; + boolean multipleSourceParametersForTP = groupedBySourceParam.groupedBySourceParameter.size() > 1; // All not processed mappings that should have been applied to all are part of the unprocessed // defined targets From aff971d7b713bcc15eb750840b00369b61cb28f5 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Feb 2026 14:08:13 +0100 Subject: [PATCH 0947/1006] Let GitHub determine whether or not the released version is the latest or not --- parent/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/parent/pom.xml b/parent/pom.xml index 8a46290cb8..ffa9952de5 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -904,6 +904,11 @@ ${maven.multiModuleProjectDirectory}/NEXT_RELEASE_CHANGELOG.md + + legacy From e9ebec2307fed606fb58f60d2e2226caf9f47614 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 2 Feb 2026 14:08:56 +0100 Subject: [PATCH 0948/1006] Factory method for LinkedHashMap and LinkedHashSet is always there for SequencedSet and SequencedMap (#3990) --- .../mapstruct/ap/internal/model/common/TypeFactory.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index c2646f63db..eb2c1dee07 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -152,15 +152,11 @@ public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMes ); implementationTypes.put( JavaCollectionConstants.SEQUENCED_SET_FQN, - sourceVersionAtLeast19 ? - withFactoryMethod( getType( LinkedHashSet.class ), LINKED_HASH_SET_FACTORY_METHOD_NAME ) : - withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) + withFactoryMethod( getType( LinkedHashSet.class ), LINKED_HASH_SET_FACTORY_METHOD_NAME ) ); implementationTypes.put( JavaCollectionConstants.SEQUENCED_MAP_FQN, - sourceVersionAtLeast19 ? - withFactoryMethod( getType( LinkedHashMap.class ), LINKED_HASH_MAP_FACTORY_METHOD_NAME ) : - withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) + withFactoryMethod( getType( LinkedHashMap.class ), LINKED_HASH_MAP_FACTORY_METHOD_NAME ) ); this.loggingVerbose = loggingVerbose; From 15312d6e46fb7744cf63e90ec70f20f518190457 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sat, 14 Feb 2026 21:14:53 +0100 Subject: [PATCH 0949/1006] Fix self check in equals of Type (#3995) --- .../java/org/mapstruct/ap/internal/model/common/Type.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 29bb3cd906..8a91c80f03 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -1303,8 +1303,8 @@ public boolean equals(Object obj) { Type other = (Type) obj; if ( this.isWildCardBoundByTypeVar() && other.isWildCardBoundByTypeVar() ) { - return ( this.hasExtendsBound() == this.hasExtendsBound() - || this.hasSuperBound() == this.hasSuperBound() ) + return ( this.hasExtendsBound() == other.hasExtendsBound() + || this.hasSuperBound() == other.hasSuperBound() ) && typeUtils.isSameType( getTypeBound().getTypeMirror(), other.getTypeBound().getTypeMirror() ); } else { From 588006727dea2beb8e0c6019e52bab95ec57993e Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Sat, 14 Feb 2026 21:53:45 +0100 Subject: [PATCH 0950/1006] Improve performance of `Type.describe()` by removing regex matching (#3991) --- .../org/mapstruct/ap/internal/model/common/Type.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 8a91c80f03..3e81cd622d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -1331,7 +1331,7 @@ public String describe() { } else { // name allows for inner classes - String name = getFullyQualifiedName().replaceFirst( "^" + getPackageName() + ".", "" ); + String name = getNameKeepingInnerClasses(); List typeParams = getTypeParameters(); if ( typeParams.isEmpty() ) { return name; @@ -1343,6 +1343,15 @@ public String describe() { } } + private String getNameKeepingInnerClasses() { + String packageNamePrefix = getPackageName() + "."; + String fullyQualifiedName = getFullyQualifiedName(); + if (fullyQualifiedName.startsWith( packageNamePrefix ) ) { + return fullyQualifiedName.substring( packageNamePrefix.length() ); + } + return fullyQualifiedName; + } + /** * * @return an identification that can be used as part in a forged method name. From 4a75490e6d8b622083720bf60596680b49ce5e31 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Wed, 4 Mar 2026 15:56:19 +0100 Subject: [PATCH 0951/1006] Simplified boolean logic in ValueMappingMethod by removing inversion (#4007) --- .../ap/internal/model/ValueMappingMethod.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java index 66b6a75961..46af8f0efd 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ValueMappingMethod.java @@ -184,8 +184,8 @@ private List enumToEnumMapping(Method method, Type sourceType, Typ List mappings = new ArrayList<>(); List unmappedSourceConstants = new ArrayList<>( sourceType.getEnumConstants() ); - boolean sourceErrorOccurred = !reportErrorIfMappedSourceEnumConstantsDontExist( method, sourceType ); - boolean targetErrorOccurred = !reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType ); + boolean sourceErrorOccurred = reportErrorIfMappedSourceEnumConstantsDontExist( method, sourceType ); + boolean targetErrorOccurred = reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType ); if ( sourceErrorOccurred || targetErrorOccurred ) { return mappings; } @@ -268,8 +268,8 @@ private List enumToStringMapping(Method method, Type sourceType ) List mappings = new ArrayList<>(); List unmappedSourceConstants = new ArrayList<>( sourceType.getEnumConstants() ); - boolean sourceErrorOccurred = !reportErrorIfMappedSourceEnumConstantsDontExist( method, sourceType ); - boolean anyRemainingUsedError = !reportErrorIfSourceEnumConstantsContainsAnyRemaining( method ); + boolean sourceErrorOccurred = reportErrorIfMappedSourceEnumConstantsDontExist( method, sourceType ); + boolean anyRemainingUsedError = reportErrorIfSourceEnumConstantsContainsAnyRemaining( method ); if ( sourceErrorOccurred || anyRemainingUsedError ) { return mappings; } @@ -298,7 +298,7 @@ private List stringToEnumMapping(Method method, Type targetType ) List mappings = new ArrayList<>(); List unmappedSourceConstants = new ArrayList<>( targetType.getEnumConstants() ); - boolean sourceErrorOccurred = !reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType ); + boolean sourceErrorOccurred = reportErrorIfMappedTargetEnumConstantsDontExist( method, targetType ); reportWarningIfAnyRemainingOrAnyUnMappedMissing( method ); if ( sourceErrorOccurred ) { return mappings; @@ -372,7 +372,7 @@ else if ( !sourceEnumConstants.contains( mappedConstant.getSource() ) ) { foundIncorrectMapping = true; } } - return !foundIncorrectMapping; + return foundIncorrectMapping; } private boolean reportErrorIfSourceEnumConstantsContainsAnyRemaining(Method method) { @@ -388,7 +388,7 @@ private boolean reportErrorIfSourceEnumConstantsContainsAnyRemaining(Method meth ); foundIncorrectMapping = true; } - return !foundIncorrectMapping; + return foundIncorrectMapping; } private void reportWarningIfAnyRemainingOrAnyUnMappedMissing(Method method) { @@ -462,7 +462,7 @@ else if ( valueMappings.nullTarget == null && valueMappings.nullValueTarget != n ); } - return !foundIncorrectMapping; + return foundIncorrectMapping; } private Type determineUnexpectedValueMappingException() { From 66625e61a4c4cbe72b58cb4187fde2cdf8e84fe4 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:01:38 +0100 Subject: [PATCH 0952/1006] Simplify fail in assertCheckstyleRules (#4003) --- .../org/mapstruct/ap/testutil/runner/CompilingExtension.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index a02ab2fe47..2599e62c2f 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -55,6 +55,7 @@ import org.xml.sax.InputSource; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation; import static org.junit.platform.commons.support.AnnotationSupport.findRepeatableAnnotations; @@ -237,8 +238,7 @@ private void assertCheckstyleRules() throws Exception { int errors = checker.process( findGeneratedFiles( new File( sourceOutputDir ) ) ); if ( errors > 0 ) { String errorLog = errorStream.toString( "UTF-8" ); - assertThat( true ).describedAs( "Expected checkstyle compliant output, but got errors:\n" + errorLog ) - .isEqualTo( false ); + fail( "Expected checkstyle compliant output, but got errors:\n" + errorLog ); } } } From 876a62d282af0ca0c5b6bf21070c5441db95c9b7 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Wed, 4 Mar 2026 16:04:23 +0100 Subject: [PATCH 0953/1006] Update license plugin (#3999) --- .../build.gradle | 5 ++ .../settings.gradle | 5 ++ parent/pom.xml | 72 ++++++++++--------- pom.xml | 10 ++- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/build.gradle b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/build.gradle index e62a8d087f..0df032f0f2 100644 --- a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/build.gradle +++ b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/build.gradle @@ -1,3 +1,8 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ plugins { id 'java' } diff --git a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/settings.gradle b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/settings.gradle index f62a77ab7b..b6ca918e91 100644 --- a/integrationtest/src/test/resources/gradleIncrementalCompilationTest/settings.gradle +++ b/integrationtest/src/test/resources/gradleIncrementalCompilationTest/settings.gradle @@ -1 +1,6 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ rootProject.name = 'gradle-incremental-compilation-test' \ No newline at end of file diff --git a/parent/pom.xml b/parent/pom.xml index ffa9952de5..ad95ffacf3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -509,9 +509,9 @@ ${kotlin.version} - com.mycila.maven-license-plugin - maven-license-plugin - 1.10.b1 + com.mycila + license-maven-plugin + 4.6 org.codehaus.mojo @@ -649,39 +649,43 @@ - com.mycila.maven-license-plugin - maven-license-plugin + com.mycila + license-maven-plugin -
        ${basedir}/../etc/license.txt
        true - - **/.idea/** - **/.mvn/** - **/build-config/checkstyle.xml - **/build-config/import-control.xml - copyright.txt - **/LICENSE.txt - **/mapstruct.xml - **/ci-settings.xml - **/eclipse-formatter-config.xml - **/forbidden-apis.txt - **/checkstyle-for-generated-sources.xml - **/nb-configuration.xml - **/junit-platform.properties - maven-settings.xml - readme.md - CONTRIBUTING.md - NEXT_RELEASE_CHANGELOG.md - .gitattributes - .gitignore - .factorypath - .checkstyle - *.yml - mvnw* - **/*.asciidoc - **/binding.xjb - **/*.flattened-pom.xml - + + +
        ${basedir}/../etc/license.txt
        + + **/.idea/** + **/.mvn/** + **/build-config/checkstyle.xml + **/build-config/import-control.xml + copyright.txt + **/LICENSE.txt + **/mapstruct.xml + **/ci-settings.xml + **/eclipse-formatter-config.xml + **/forbidden-apis.txt + **/checkstyle-for-generated-sources.xml + **/nb-configuration.xml + **/junit-platform.properties + maven-settings.xml + readme.md + CONTRIBUTING.md + NEXT_RELEASE_CHANGELOG.md + .gitattributes + .gitignore + .factorypath + .checkstyle + *.yml + mvnw* + **/*.asciidoc + **/binding.xjb + **/*.flattened-pom.xml + +
        +
        SLASHSTAR_STYLE SLASHSTAR_STYLE diff --git a/pom.xml b/pom.xml index f55f0955d3..c753e3c1e4 100644 --- a/pom.xml +++ b/pom.xml @@ -35,10 +35,14 @@ - com.mycila.maven-license-plugin - maven-license-plugin + com.mycila + license-maven-plugin -
        etc/license.txt
        + + +
        etc/license.txt
        +
        +
        XML_STYLE SLASHSTAR_STYLE From f0d488712f76e02a51218e5eeaefb65bd2680a32 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Wed, 4 Mar 2026 22:43:48 +0100 Subject: [PATCH 0954/1006] Use StandardCharsets.UTF_8 in tests (#4002) --- .../mapstruct/ap/testutil/runner/CompilingExtension.java | 3 ++- .../org/mapstruct/ap/testutil/runner/GeneratedSource.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java index 2599e62c2f..cb12be725c 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingExtension.java @@ -10,6 +10,7 @@ import java.io.FileWriter; import java.io.IOException; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -237,7 +238,7 @@ private void assertCheckstyleRules() throws Exception { int errors = checker.process( findGeneratedFiles( new File( sourceOutputDir ) ) ); if ( errors > 0 ) { - String errorLog = errorStream.toString( "UTF-8" ); + String errorLog = errorStream.toString( StandardCharsets.UTF_8 ); fail( "Expected checkstyle compliant output, but got errors:\n" + errorLog ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java index 18a53b4971..6785ea5cf2 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/GeneratedSource.java @@ -6,9 +6,9 @@ package org.mapstruct.ap.testutil.runner; import java.io.File; -import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -119,7 +119,7 @@ public JavaFileAssert forJavaFile(String path) { return new JavaFileAssert( new File( sourceOutputDir.get() + "/" + path ) ); } - private void handleFixtureComparison() throws UnsupportedEncodingException { + private void handleFixtureComparison() { for ( Class fixture : fixturesFor ) { String fixtureName = getMapperName( fixture ); URL expectedFile = getExpectedResource( fixtureName ); @@ -131,7 +131,7 @@ private void handleFixtureComparison() throws UnsupportedEncodingException { ) ); } else { - File expectedResource = new File( URLDecoder.decode( expectedFile.getFile(), "UTF-8" ) ); + File expectedResource = new File( URLDecoder.decode( expectedFile.getFile(), StandardCharsets.UTF_8 ) ); forMapper( fixture ).hasSameMapperContent( expectedResource ); } fixture.getPackage().getName(); From 1f3524570e362c34f4d0d7ce983c3596c83ad7c7 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:25:03 +0100 Subject: [PATCH 0955/1006] Add missing self reference in GeneratedTypeBuilder (#4009) --- .../java/org/mapstruct/ap/internal/model/GeneratedType.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java index 0bc3ec7bf0..4b39e92273 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/GeneratedType.java @@ -30,9 +30,9 @@ public abstract class GeneratedType extends ModelElement { private static final String JAVA_LANG_PACKAGE = "java.lang"; - protected abstract static class GeneratedTypeBuilder { + protected abstract static class GeneratedTypeBuilder> { - private T myself; + private final T myself; protected TypeFactory typeFactory; protected ElementUtils elementUtils; protected Options options; From bff3efd10640170a5ad10dea8a5fa0e4173a932a Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Mon, 16 Mar 2026 00:25:54 +0100 Subject: [PATCH 0956/1006] Remove obsolete override of AssertJ version in integration tests (#4015) --- integrationtest/src/test/resources/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index c2ece3b38d..3053b211e1 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -26,8 +26,6 @@ ${mapstruct.version} - - 1.7.1 From 94da2c3f05af31ab9693056aab9785549212940b Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:30:40 +0100 Subject: [PATCH 0957/1006] Remove unsued methods in Fields leftover from c2e803403027f3fae92bd15b0ba50ab7df5063e6 (#4010) --- .../mapstruct/ap/internal/util/Fields.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java index 8e16a95274..b2f8ac1442 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/Fields.java @@ -6,13 +6,7 @@ package org.mapstruct.ap.internal.util; import javax.lang.model.element.Modifier; -import javax.lang.model.element.TypeElement; import javax.lang.model.element.VariableElement; -import javax.lang.model.type.DeclaredType; -import javax.lang.model.type.TypeKind; -import javax.lang.model.type.TypeMirror; - -import org.mapstruct.ap.spi.TypeHierarchyErroneousException; /** * Provides functionality around {@link VariableElement}s. @@ -35,17 +29,4 @@ static boolean isPublic(VariableElement method) { private static boolean isNotStatic(VariableElement method) { return !method.getModifiers().contains( Modifier.STATIC ); } - - private static TypeElement asTypeElement(TypeMirror mirror) { - return (TypeElement) ( (DeclaredType) mirror ).asElement(); - } - - private static boolean hasNonObjectSuperclass(TypeElement element) { - if ( element.getSuperclass().getKind() == TypeKind.ERROR ) { - throw new TypeHierarchyErroneousException( element ); - } - - return element.getSuperclass().getKind() == TypeKind.DECLARED - && !asTypeElement( element.getSuperclass() ).getQualifiedName().toString().equals( "java.lang.Object" ); - } } From ded3daa5fcad390d60fe04d4d8e9479466722d63 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:31:23 +0100 Subject: [PATCH 0958/1006] Upgrade Visitor6 to Visitor8 (#4011) --- .../src/main/java/org/mapstruct/ap/MappingProcessor.java | 4 ++-- .../mapstruct/ap/internal/util/AccessorNamingUtils.java | 8 ++++---- .../mapstruct/ap/spi/DefaultAccessorNamingStrategy.java | 8 ++++---- .../java/org/mapstruct/ap/spi/DefaultBuilderProvider.java | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index a66762d739..32e65c7047 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -30,7 +30,7 @@ import javax.lang.model.element.QualifiedNameable; import javax.lang.model.element.TypeElement; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.ElementKindVisitor6; +import javax.lang.model.util.ElementKindVisitor8; import javax.tools.Diagnostic.Kind; import org.mapstruct.ap.internal.gem.MapperGem; @@ -402,7 +402,7 @@ private R process(ProcessorContext context, ModelElementProcessor p private TypeElement asTypeElement(Element element) { return element.accept( - new ElementKindVisitor6() { + new ElementKindVisitor8() { @Override public TypeElement visitTypeAsInterface(TypeElement e, Void p) { return e; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java index 0f17946f72..8025acfeb1 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/util/AccessorNamingUtils.java @@ -10,8 +10,8 @@ import javax.lang.model.type.DeclaredType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; -import javax.lang.model.util.SimpleElementVisitor6; -import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.SimpleElementVisitor8; +import javax.lang.model.util.SimpleTypeVisitor8; import org.mapstruct.ap.internal.util.accessor.Accessor; import org.mapstruct.ap.internal.util.accessor.AccessorType; @@ -84,7 +84,7 @@ public String getElementNameForAdder(Accessor adderMethod) { private static String getQualifiedName(TypeMirror type) { DeclaredType declaredType = type.accept( - new SimpleTypeVisitor6() { + new SimpleTypeVisitor8() { @Override public DeclaredType visitDeclared(DeclaredType t, Void p) { return t; @@ -98,7 +98,7 @@ public DeclaredType visitDeclared(DeclaredType t, Void p) { } TypeElement typeElement = declaredType.asElement().accept( - new SimpleElementVisitor6() { + new SimpleElementVisitor8() { @Override public TypeElement visitType(TypeElement e, Void p) { return e; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java index e7529dcd08..a726e9691f 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultAccessorNamingStrategy.java @@ -14,8 +14,8 @@ import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Elements; -import javax.lang.model.util.SimpleElementVisitor6; -import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.SimpleElementVisitor8; +import javax.lang.model.util.SimpleTypeVisitor8; import javax.lang.model.util.Types; import kotlin.Metadata; @@ -273,7 +273,7 @@ public String getElementName(ExecutableElement adderMethod) { */ protected static String getQualifiedName(TypeMirror type) { DeclaredType declaredType = type.accept( - new SimpleTypeVisitor6() { + new SimpleTypeVisitor8() { @Override public DeclaredType visitDeclared(DeclaredType t, Void p) { return t; @@ -287,7 +287,7 @@ public DeclaredType visitDeclared(DeclaredType t, Void p) { } TypeElement typeElement = declaredType.asElement().accept( - new SimpleElementVisitor6() { + new SimpleElementVisitor8() { @Override public TypeElement visitType(TypeElement e, Void p) { return e; diff --git a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java index 333a11dbcc..c1126fa9fb 100644 --- a/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java +++ b/processor/src/main/java/org/mapstruct/ap/spi/DefaultBuilderProvider.java @@ -21,8 +21,8 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; -import javax.lang.model.util.SimpleElementVisitor6; -import javax.lang.model.util.SimpleTypeVisitor6; +import javax.lang.model.util.SimpleElementVisitor8; +import javax.lang.model.util.SimpleTypeVisitor8; import javax.lang.model.util.Types; /** @@ -126,7 +126,7 @@ private TypeElement getTypeElement(DeclaredType declaredType) { } return declaredType.asElement().accept( - new SimpleElementVisitor6() { + new SimpleElementVisitor8() { @Override public TypeElement visitType(TypeElement e, Void p) { return e; @@ -148,7 +148,7 @@ private DeclaredType getDeclaredType(TypeMirror type) { throw new TypeHierarchyErroneousException( type ); } return type.accept( - new SimpleTypeVisitor6() { + new SimpleTypeVisitor8() { @Override public DeclaredType visitDeclared(DeclaredType t, Void p) { return t; From 0780d98fc2045092adbfe4417e46d853ecd946b7 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:37:00 +0100 Subject: [PATCH 0959/1006] Upgrade freemarker to 2.3.34 (#4012) --- parent/pom.xml | 2 +- .../org/mapstruct/ap/internal/model/Annotation.ftl | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/parent/pom.xml b/parent/pom.xml index ad95ffacf3..88bfd5053c 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -119,7 +119,7 @@ org.freemarker freemarker - 2.3.32 + 2.3.34 org.assertj diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl index 81f3d2ba8b..0b6737fbe4 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/Annotation.ftl @@ -7,12 +7,10 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.Annotation" --> <#switch properties?size> - <#case 0> + <#on 0> @<@includeModel object=type/><#rt> - <#break> - <#case 1> + <#on 1> @<@includeModel object=type/>(<@includeModel object=properties[0]/>)<#rt> - <#break> <#default> @<@includeModel object=type/>( <#list properties as property> From e0fa28868d8e01ecdb9df23440464aa9f1f07832 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:37:41 +0100 Subject: [PATCH 0960/1006] Remove deprecated Number api usage from tests (#4013) --- .../ap/test/selection/twosteperror/ErroneousMapperMC.java | 2 +- .../mapstruct/ap/test/source/constants/SourceConstantsTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java index 4b7dcf90a3..b6381cf6da 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java +++ b/processor/src/test/java/org/mapstruct/ap/test/selection/twosteperror/ErroneousMapperMC.java @@ -22,7 +22,7 @@ default BigDecimal methodX1(SourceType s) { } default Double methodX2(SourceType s) { - return new Double( s.t1 ); + return Double.valueOf( s.t1 ); } // CHECKSTYLE:OFF diff --git a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java index b331a2efba..1b1764fe56 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/source/constants/SourceConstantsTest.java @@ -47,7 +47,7 @@ public void shouldMapSameSourcePropertyToSeveralTargetProperties() throws ParseE assertThat( target.getStringConstant() ).isEqualTo( "stringConstant" ); assertThat( target.getEmptyStringConstant() ).isEqualTo( "" ); assertThat( target.getIntegerConstant() ).isEqualTo( 14 ); - assertThat( target.getLongWrapperConstant() ).isEqualTo( new Long( 3001L ) ); + assertThat( target.getLongWrapperConstant() ).isEqualTo( Long.valueOf( 3001L ) ); assertThat( target.getDateConstant() ).isEqualTo( getDate( "dd-MM-yyyy", "09-01-2014" ) ); assertThat( target.getNameConstants() ).isEqualTo( Arrays.asList( "jack", "jill", "tom" ) ); assertThat( target.getCountry() ).isEqualTo( CountryEnum.THE_NETHERLANDS ); From dab3eaf237eb025a0d59f997263fea515cb6db64 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 16 Mar 2026 00:44:29 +0100 Subject: [PATCH 0961/1006] #3949: Support SET_TO_NULL for overloaded target methods, requiring a cast (#3988) --- .../model/CollectionAssignmentBuilder.java | 3 +- .../ap/internal/model/PropertyMapping.java | 34 ++++++- .../model/assignment/SetterWrapper.java | 24 ++++- .../model/assignment/UpdateWrapper.java | 9 +- .../ap/internal/model/common/Type.java | 2 +- .../model/assignment/UpdateWrapper.ftl | 2 +- .../ap/internal/model/macro/CommonMacros.ftl | 2 +- .../ap/test/bugs/_3949/DateSource.java | 14 +++ .../test/bugs/_3949/Issue3949ClassMapper.java | 29 ++++++ .../bugs/_3949/Issue3949InterfaceMapper.java | 29 ++++++ .../ap/test/bugs/_3949/Issue3949Test.java | 94 +++++++++++++++++++ .../ap/test/bugs/_3949/ParentSource.java | 12 +++ .../ap/test/bugs/_3949/ParentTarget.java | 25 +++++ .../bugs/_3949/ParentTargetInterface.java | 14 +++ .../ap/test/bugs/_3949/StringSource.java | 12 +++ .../ap/test/bugs/_3949/TargetDate.java | 33 +++++++ .../test/bugs/_3949/TargetDateInterface.java | 18 ++++ .../ap/test/bugs/_3949/TargetString.java | 34 +++++++ .../bugs/_3949/TargetStringInterface.java | 18 ++++ 19 files changed, 399 insertions(+), 9 deletions(-) create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/DateSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949ClassMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949InterfaceMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949Test.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTarget.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTargetInterface.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/StringSource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDate.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDateInterface.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetString.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetStringInterface.java diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java index 76e56cd976..db9e012d78 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/CollectionAssignmentBuilder.java @@ -163,7 +163,8 @@ public Assignment build() { targetType, true, nvpms == SET_TO_NULL && !targetType.isPrimitive(), - nvpms == SET_TO_DEFAULT + nvpms == SET_TO_DEFAULT, + false ); } else if ( method.isUpdateMethod() && !targetImmutable ) { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index 622ba9cef0..c120f035b2 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -13,6 +13,8 @@ import java.util.Set; import java.util.function.Supplier; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; import org.mapstruct.ap.internal.gem.BuilderGem; import org.mapstruct.ap.internal.gem.NullValueCheckStrategyGem; @@ -454,7 +456,8 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { targetType, !rhs.isSourceReferenceParameter(), nvpms == SET_TO_NULL && !targetType.isPrimitive(), - nvpms == SET_TO_DEFAULT + nvpms == SET_TO_DEFAULT, + hasTwoOrMoreSettersWithName() ); } else { @@ -471,7 +474,10 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { isFieldAssignment(), includeSourceNullCheck, includeSourceNullCheck && nvpms == SET_TO_NULL && !targetType.isPrimitive(), - nvpms == SET_TO_DEFAULT ); + nvpms == SET_TO_DEFAULT, + hasTwoOrMoreSettersWithName(), + targetType + ); } } @@ -547,12 +553,33 @@ else if ( result.getSourceType().isStreamType() ) { isFieldAssignment(), true, nvpms == SET_TO_NULL && !targetType.isPrimitive(), - nvpms == SET_TO_DEFAULT + nvpms == SET_TO_DEFAULT, + hasTwoOrMoreSettersWithName(), + targetType ); } return result; } + private boolean hasTwoOrMoreSettersWithName() { + Element enclosingClass = this.targetWriteAccessor.getElement().getEnclosingElement(); + if ( enclosingClass == null || !( ElementKind.CLASS.equals( enclosingClass.getKind() ) + || ElementKind.INTERFACE.equals( enclosingClass.getKind() ) ) ) { + return false; + } + String simpleWriteAccessorName = this.targetWriteAccessor.getSimpleName(); + boolean firstMatchFound = false; + for ( Accessor setter : ctx.getTypeFactory().getType( enclosingClass.asType() ).getSetters() ) { + if ( setter.getSimpleName().equals( simpleWriteAccessorName ) ) { + if ( firstMatchFound ) { + return true; + } + firstMatchFound = true; + } + } + return false; + } + private Assignment assignToCollection(Type targetType, AccessorType targetAccessorType, Assignment rhs) { return new CollectionAssignmentBuilder() @@ -991,6 +1018,7 @@ public PropertyMapping build() { targetType, false, false, + false, false ); } else { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java index 7be948c857..94b031c622 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapper.java @@ -6,7 +6,9 @@ package org.mapstruct.ap.internal.model.assignment; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.mapstruct.ap.internal.model.common.Assignment; import org.mapstruct.ap.internal.model.common.Type; @@ -22,19 +24,25 @@ public class SetterWrapper extends AssignmentWrapper { private final boolean includeSourceNullCheck; private final boolean setExplicitlyToNull; private final boolean setExplicitlyToDefault; + private final boolean mustCastForNull; + private final Type nullCastType; public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment, boolean includeSourceNullCheck, boolean setExplicitlyToNull, - boolean setExplicitlyToDefault) { + boolean setExplicitlyToDefault, + boolean mustCastForNull, + Type nullCastType) { super( rhs, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.includeSourceNullCheck = includeSourceNullCheck; this.setExplicitlyToDefault = setExplicitlyToDefault; this.setExplicitlyToNull = setExplicitlyToNull; + this.mustCastForNull = mustCastForNull; + this.nullCastType = nullCastType; } public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fieldAssignment ) { @@ -43,6 +51,8 @@ public SetterWrapper(Assignment rhs, List thrownTypesToExclude, boolean fi this.includeSourceNullCheck = false; this.setExplicitlyToNull = false; this.setExplicitlyToDefault = false; + this.mustCastForNull = false; + this.nullCastType = null; } @Override @@ -59,6 +69,15 @@ public List getThrownTypes() { return result; } + @Override + public Set getImportTypes() { + Set imported = new HashSet<>( super.getImportTypes() ); + if ( isSetExplicitlyToNull() && isMustCastForNull() ) { + imported.add( nullCastType ); + } + return imported; + } + public boolean isSetExplicitlyToNull() { return setExplicitlyToNull; } @@ -71,4 +90,7 @@ public boolean isIncludeSourceNullCheck() { return includeSourceNullCheck; } + public boolean isMustCastForNull() { + return mustCastForNull; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java index ff5089d6c2..c3d3f9c446 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.java @@ -26,6 +26,7 @@ public class UpdateWrapper extends AssignmentWrapper { private final boolean includeSourceNullCheck; private final boolean setExplicitlyToNull; private final boolean setExplicitlyToDefault; + private final boolean mustCastForNull; public UpdateWrapper( Assignment decoratedAssignment, List thrownTypesToExclude, @@ -34,7 +35,8 @@ public UpdateWrapper( Assignment decoratedAssignment, Type targetType, boolean includeSourceNullCheck, boolean setExplicitlyToNull, - boolean setExplicitlyToDefault ) { + boolean setExplicitlyToDefault, + boolean mustCastForNull) { super( decoratedAssignment, fieldAssignment ); this.thrownTypesToExclude = thrownTypesToExclude; this.factoryMethod = factoryMethod; @@ -42,6 +44,7 @@ public UpdateWrapper( Assignment decoratedAssignment, this.includeSourceNullCheck = includeSourceNullCheck; this.setExplicitlyToDefault = setExplicitlyToDefault; this.setExplicitlyToNull = setExplicitlyToNull; + this.mustCastForNull = mustCastForNull; } private static Type determineImplType(Assignment factoryMethod, Type targetType) { @@ -100,4 +103,8 @@ public boolean isSetExplicitlyToNull() { public boolean isSetExplicitlyToDefault() { return setExplicitlyToDefault; } + + public boolean isMustCastForNull() { + return mustCastForNull; + } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 3e81cd622d..6287403ba3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -1061,7 +1061,7 @@ private TypeMirror boxed(TypeMirror possiblePrimitive) { * * @return an unmodifiable list of all setters */ - private List getSetters() { + public List getSetters() { if ( setters == null ) { setters = Collections.unmodifiableList( filters.setterMethodsIn( getAllMethods() ) ); } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl index d8ed4b53f6..933612f579 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/UpdateWrapper.ftl @@ -18,7 +18,7 @@ } <#if setExplicitlyToDefault || setExplicitlyToNull> else { - ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>${ext.targetType.null}; + ${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else><#if mustCastForNull>(<@includeModel object=ext.targetType/>) ${ext.targetType.null}; } <#else> diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index 9c4ad26e03..f409fda793 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -45,7 +45,7 @@ } <#elseif setExplicitlyToDefault || setExplicitlyToNull> else { - <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else>${ext.targetType.null}; + <#if ext.targetBeanName?has_content>${ext.targetBeanName}.${ext.targetWriteAccessorName}<@lib.handleWrite><#if setExplicitlyToDefault><@lib.initTargetObject/><#else><#if mustCastForNull!false>(<@includeModel object=ext.targetType/>) ${ext.targetType.null}; } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/DateSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/DateSource.java new file mode 100644 index 0000000000..e542c388d4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/DateSource.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import java.time.LocalDate; + +public class DateSource { + public LocalDate getDate() { + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949ClassMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949ClassMapper.java new file mode 100644 index 0000000000..135aa79056 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949ClassMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL) +public interface Issue3949ClassMapper { + + Issue3949ClassMapper INSTANCE = Mappers.getMapper( Issue3949ClassMapper.class ); + + void overwriteDate(@MappingTarget TargetDate target, DateSource dateSource); + + void overwriteString(@MappingTarget TargetString target, StringSource stringSource); + + void overwriteDateWithConversion(@MappingTarget TargetDate target, StringSource dateSource); + + void overwriteStringWithConversion(@MappingTarget TargetString target, DateSource stringSource); + + void updateParent(@MappingTarget ParentTarget target, ParentSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949InterfaceMapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949InterfaceMapper.java new file mode 100644 index 0000000000..c25041ad2f --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949InterfaceMapper.java @@ -0,0 +1,29 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValueCheckStrategy; +import org.mapstruct.NullValuePropertyMappingStrategy; +import org.mapstruct.factory.Mappers; + +@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL) +public interface Issue3949InterfaceMapper { + + Issue3949InterfaceMapper INSTANCE = Mappers.getMapper( Issue3949InterfaceMapper.class ); + + void overwriteDate(@MappingTarget TargetDateInterface target, DateSource dateSource); + + void overwriteString(@MappingTarget TargetStringInterface target, StringSource stringSource); + + void overwriteDateWithConversion(@MappingTarget TargetDateInterface target, StringSource dateSource); + + void overwriteStringWithConversion(@MappingTarget TargetStringInterface target, DateSource stringSource); + + void updateParent(@MappingTarget ParentTargetInterface target, ParentSource source); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949Test.java new file mode 100644 index 0000000000..b6abee819c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/Issue3949Test.java @@ -0,0 +1,94 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests if overloaded targets are correctly cast when set to null + * + * @author hduelme + */ +@IssueKey("3949") +@WithClasses({ + ParentSource.class, + ParentTargetInterface.class, + ParentTarget.class, + StringSource.class, + TargetStringInterface.class, + TargetString.class, + DateSource.class, + TargetDateInterface.class, + TargetDate.class +}) +public class Issue3949Test { + + @ProcessorTest + @WithClasses({ + Issue3949ClassMapper.class + }) + void shouldCompileAndSetCorrectlyToNullForClass() { + TargetDate shouldSetDateToNull = new TargetDate(); + Issue3949ClassMapper.INSTANCE.overwriteDate( shouldSetDateToNull, new DateSource() ); + assertThat( shouldSetDateToNull.getString() ).isNotNull(); + assertThat( shouldSetDateToNull.getDate() ).isNull(); + + shouldSetDateToNull = new TargetDate(); + Issue3949ClassMapper.INSTANCE.overwriteDateWithConversion( shouldSetDateToNull, new StringSource() ); + assertThat( shouldSetDateToNull.getString() ).isNotNull(); + assertThat( shouldSetDateToNull.getDate() ).isNull(); + + TargetString shouldSetStringToNull = new TargetString(); + Issue3949ClassMapper.INSTANCE.overwriteString( shouldSetStringToNull, new StringSource() ); + assertThat( shouldSetStringToNull.getDate() ).isNull(); + assertThat( shouldSetStringToNull.getDateValue() ).isNotNull(); + + shouldSetStringToNull = new TargetString(); + Issue3949ClassMapper.INSTANCE.overwriteStringWithConversion( shouldSetStringToNull, new DateSource() ); + assertThat( shouldSetStringToNull.getDate() ).isNull(); + assertThat( shouldSetStringToNull.getDateValue() ).isNotNull(); + + ParentTarget parentTarget = new ParentTarget(); + parentTarget.setChild( new ParentTarget() ); + Issue3949ClassMapper.INSTANCE.updateParent( parentTarget, new ParentSource() ); + assertThat( parentTarget.getChild() ).isNull(); + } + + @ProcessorTest + @WithClasses({ + Issue3949InterfaceMapper.class + }) + void shouldCompileAndSetCorrectlyToNullForInterface() { + TargetDateInterface shouldSetDateToNull = new TargetDate(); + Issue3949InterfaceMapper.INSTANCE.overwriteDate( shouldSetDateToNull, new DateSource() ); + assertThat( shouldSetDateToNull.getString() ).isNotNull(); + assertThat( shouldSetDateToNull.getDate() ).isNull(); + + shouldSetDateToNull = new TargetDate(); + Issue3949InterfaceMapper.INSTANCE.overwriteDateWithConversion( shouldSetDateToNull, new StringSource() ); + assertThat( shouldSetDateToNull.getString() ).isNotNull(); + assertThat( shouldSetDateToNull.getDate() ).isNull(); + + TargetStringInterface shouldSetStringToNull = new TargetString(); + Issue3949InterfaceMapper.INSTANCE.overwriteString( shouldSetStringToNull, new StringSource() ); + assertThat( shouldSetStringToNull.getDate() ).isNull(); + assertThat( shouldSetStringToNull.getDateValue() ).isNotNull(); + + shouldSetStringToNull = new TargetString(); + Issue3949InterfaceMapper.INSTANCE.overwriteStringWithConversion( shouldSetStringToNull, new DateSource() ); + assertThat( shouldSetStringToNull.getDate() ).isNull(); + assertThat( shouldSetStringToNull.getDateValue() ).isNotNull(); + + ParentTargetInterface parentTarget = new ParentTarget(); + parentTarget.setChild( new ParentTarget() ); + Issue3949InterfaceMapper.INSTANCE.updateParent( parentTarget, new ParentSource() ); + assertThat( parentTarget.getChild() ).isNull(); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentSource.java new file mode 100644 index 0000000000..551501aa24 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentSource.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +public class ParentSource { + public ParentSource getChild() { + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTarget.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTarget.java new file mode 100644 index 0000000000..3d8ca3b51b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTarget.java @@ -0,0 +1,25 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +public class ParentTarget implements ParentTargetInterface { + private ParentTarget child; + + @Override + public ParentTarget getChild() { + return child; + } + + @Override + public void setChild(String child) { + throw new IllegalArgumentException(); + } + + @Override + public void setChild(ParentTarget child) { + this.child = child; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTargetInterface.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTargetInterface.java new file mode 100644 index 0000000000..5311fb4c9b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/ParentTargetInterface.java @@ -0,0 +1,14 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +public interface ParentTargetInterface { + ParentTarget getChild(); + + void setChild(String child); + + void setChild(ParentTarget child); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/StringSource.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/StringSource.java new file mode 100644 index 0000000000..11ba1419d5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/StringSource.java @@ -0,0 +1,12 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +public class StringSource { + public String getDate() { + return null; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDate.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDate.java new file mode 100644 index 0000000000..85b12a618d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDate.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import java.time.LocalDate; + +public class TargetDate implements TargetDateInterface { + private LocalDate date = LocalDate.now(); + private String string = ""; + + @Override + public void setDate(LocalDate date) { + this.date = date; + } + + @Override + public void setDate(String date) { + this.string = date; + } + + @Override + public LocalDate getDate() { + return date; + } + + @Override + public String getString() { + return string; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDateInterface.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDateInterface.java new file mode 100644 index 0000000000..df28936914 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetDateInterface.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import java.time.LocalDate; + +public interface TargetDateInterface { + void setDate(LocalDate date); + + void setDate(String date); + + LocalDate getDate(); + + String getString(); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetString.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetString.java new file mode 100644 index 0000000000..b8cbbb2bbb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetString.java @@ -0,0 +1,34 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import java.time.LocalDate; + +public class TargetString implements TargetStringInterface { + private LocalDate date = LocalDate.now(); + private String string = ""; + + @Override + public void setDate(LocalDate date) { + this.date = date; + } + + @Override + public void setDate(String date) { + this.string = date; + } + + @Override + public String getDate() { + return string; + } + + @Override + public LocalDate getDateValue() { + return date; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetStringInterface.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetStringInterface.java new file mode 100644 index 0000000000..dd82231a51 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_3949/TargetStringInterface.java @@ -0,0 +1,18 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.bugs._3949; + +import java.time.LocalDate; + +public interface TargetStringInterface { + void setDate(LocalDate date); + + void setDate(String date); + + String getDate(); + + LocalDate getDateValue(); +} From 6d61c3ab9ea577ef12c0ff2e77e723f946696791 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 23 Mar 2026 23:34:11 +0100 Subject: [PATCH 0962/1006] #3972: Update maven compiler plugin (#4022) * Revert "Block plexus.snapshots repository in GitHub actions #3972" This reverts commit 9d75a48df5e40c1ed87d2f68d96fbb35807e3b91 and updates the maven compiler plugin to 3.15.0 --- .github/workflows/java-ea.yml | 3 --- .github/workflows/macos.yml | 3 --- .github/workflows/main.yml | 6 ------ .github/workflows/release.yml | 4 ---- .github/workflows/windows.yml | 3 --- parent/pom.xml | 2 +- 6 files changed, 1 insertion(+), 20 deletions(-) diff --git a/.github/workflows/java-ea.yml b/.github/workflows/java-ea.yml index 70b81c40f1..fc3a4a0fb1 100644 --- a/.github/workflows/java-ea.yml +++ b/.github/workflows/java-ea.yml @@ -17,8 +17,5 @@ jobs: with: website: jdk.java.net release: EA - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=true install -DskipDistribution=true diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 98b4e156e0..833bb6ba39 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,8 +16,5 @@ jobs: with: distribution: 'zulu' java-version: 21 - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} install diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ca66a22291..c4def2a89d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -23,9 +23,6 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw ${MAVEN_ARGS} -Djacoco.skip=${{ matrix.java != 21 }} install -DskipDistribution=${{ matrix.java != 21 }} - name: 'Generate coverage report' @@ -62,8 +59,5 @@ jobs: with: distribution: 'zulu' java-version: ${{ matrix.java }} - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Run integration tests' run: ./mvnw ${MAVEN_ARGS} verify -pl integrationtest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4feca94a0..666a74656d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,10 +26,6 @@ jobs: distribution: 'zulu' cache: maven - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - - name: Set release version id: version run: | diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index fc37af6a9d..bda38f8783 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -16,8 +16,5 @@ jobs: with: distribution: 'zulu' java-version: 21 - - uses: s4u/maven-settings-action@v4.0.0 - with: - mirrors: '[{"id": "block-plexus-snapshots", "name": "Block Plexus Snapshots", "mirrorOf": "plexus.snapshots", "url": "http://localhost"}]' - name: 'Test' run: ./mvnw %MAVEN_ARGS% install diff --git a/parent/pom.xml b/parent/pom.xml index 88bfd5053c..c4ba63948d 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -413,7 +413,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.14.1 + 3.15.0 org.apache.maven.plugins From 0d3104908196b3ad22101dd5928ea5e6f4d85c88 Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 23 Mar 2026 23:35:47 +0100 Subject: [PATCH 0963/1006] Use multi-catch in generated code (#4021) --- .../model/assignment/Java8FunctionWrapper.ftl | 10 +++------- .../model/assignment/LocalVarWrapper.ftl | 10 +++------- .../ap/internal/model/macro/CommonMacros.ftl | 11 +++++++--- .../adder/SourceTargetMapperImpl.java | 20 ++++--------------- 4 files changed, 18 insertions(+), 33 deletions(-) diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl index ce1fcdcd6c..4c3b6d4804 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/Java8FunctionWrapper.ftl @@ -6,6 +6,7 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.Java8FunctionWrapper" --> +<#import "../macro/CommonMacros.ftl" as lib> <#assign sourceVarName><#if assignment.sourceLocalVarName?? >${assignment.sourceLocalVarName}<#else>${assignment.sourceReference} <#if (thrownTypes?size == 0) > <#compress> @@ -17,14 +18,9 @@ <#else> <#compress> ${sourceVarName} -> { - try { + <@lib.handleExceptions> return <@_assignment/>; - } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - + } diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl index 97ea856ece..163a52896a 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/assignment/LocalVarWrapper.ftl @@ -6,18 +6,14 @@ --> <#-- @ftlvariable name="" type="org.mapstruct.ap.internal.model.assignment.LocalVarWrapper" --> +<#import "../macro/CommonMacros.ftl" as lib> <#if (thrownTypes?size == 0) > <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/> ${ext.targetWriteAccessorName} = <@_assignment/>; <#else> <#if !ext.isTargetDefined?? ><@includeModel object=ext.targetType/> ${ext.targetWriteAccessorName}; - try { + <@lib.handleExceptions> ${ext.targetWriteAccessorName} = <@_assignment/>; - } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { - throw new RuntimeException( e ); - } - + <#macro _assignment> <@includeModel object=assignment diff --git a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl index f409fda793..e857a807af 100644 --- a/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl +++ b/processor/src/main/resources/org/mapstruct/ap/internal/model/macro/CommonMacros.ftl @@ -104,11 +104,16 @@ try { <#nested> } - <#list thrownTypes as exceptionType> - catch ( <@includeModel object=exceptionType/> e ) { + <@compress single_line=true>catch ( + <#list thrownTypes as exceptionType> + <#if exceptionType_index > 0> | + <@includeModel object=exceptionType/> + + e ) { + + throw new RuntimeException( e ); } - <#-- diff --git a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java index 823fbb1908..52d661c3f7 100644 --- a/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java +++ b/processor/src/test/resources/fixtures/org/mapstruct/ap/test/collection/adder/SourceTargetMapperImpl.java @@ -59,10 +59,7 @@ public Source toSource(Target source) { try { source1.setPets( petMapper.toSourcePets( source.getPets() ) ); } - catch ( CatException e ) { - throw new RuntimeException( e ); - } - catch ( DogException e ) { + catch ( CatException | DogException e ) { throw new RuntimeException( e ); } @@ -82,10 +79,7 @@ public void toExistingTarget(Source source, Target target) { } } } - catch ( CatException e ) { - throw new RuntimeException( e ); - } - catch ( DogException e ) { + catch ( CatException | DogException e ) { throw new RuntimeException( e ); } } @@ -161,10 +155,7 @@ public TargetViaTargetType toTargetViaTargetType(Source source) { } } } - catch ( CatException e ) { - throw new RuntimeException( e ); - } - catch ( DogException e ) { + catch ( CatException | DogException e ) { throw new RuntimeException( e ); } @@ -184,10 +175,7 @@ public Target fromSingleElementSource(SingleElementSource source) { target.addPet( petMapper.toPet( source.getPet() ) ); } } - catch ( CatException e ) { - throw new RuntimeException( e ); - } - catch ( DogException e ) { + catch ( CatException | DogException e ) { throw new RuntimeException( e ); } From 2d51aa0695272b1198d6c4cbe3458ca3ecbdeb9f Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Mon, 23 Mar 2026 23:39:41 +0100 Subject: [PATCH 0964/1006] Refactor TypeFactory.getTypeParameters (#4020) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improves readability and avoids unnecessary overhead: * Stores `typeArguments` in a local variable (since calling `getTypeArguments()` is not cached in eclipse compiler) * Replace if/else with a ternary expression * Avoids repeated `getType(...)` calls --- .../ap/internal/model/common/TypeFactory.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index eb2c1dee07..606bbce69d 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -523,15 +523,12 @@ private List getTypeParameters(TypeMirror mirror, boolean isImplementation } DeclaredType declaredType = (DeclaredType) mirror; - List typeParameters = new ArrayList<>( declaredType.getTypeArguments().size() ); + List typeArguments = declaredType.getTypeArguments(); + List typeParameters = new ArrayList<>( typeArguments.size() ); - for ( TypeMirror typeParameter : declaredType.getTypeArguments() ) { - if ( isImplementationType ) { - typeParameters.add( getType( typeParameter ).getTypeBound() ); - } - else { - typeParameters.add( getType( typeParameter ) ); - } + for ( TypeMirror typeParameter : typeArguments) { + Type type = getType( typeParameter ); + typeParameters.add( isImplementationType ? type.getTypeBound() : type ); } return typeParameters; From 9aea5a8e93c28fb824b59bd883b5c88bcb6c2e6d Mon Sep 17 00:00:00 2001 From: mk868 Date: Fri, 27 Mar 2026 07:44:34 +0100 Subject: [PATCH 0965/1006] #4018 Add URI to String built-in conversions (#4019) --- .../chapter-5-data-type-conversions.asciidoc | 3 + .../internal/conversion/ConversionUtils.java | 12 ++++ .../ap/internal/conversion/Conversions.java | 10 ++-- .../conversion/URIToStringConversion.java | 37 ++++++++++++ .../conversion/uri/URIConversionTest.java | 56 +++++++++++++++++++ .../ap/test/conversion/uri/URIMapper.java | 19 +++++++ .../ap/test/conversion/uri/URISource.java | 33 +++++++++++ .../ap/test/conversion/uri/URITarget.java | 30 ++++++++++ 8 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 processor/src/main/java/org/mapstruct/ap/internal/conversion/URIToStringConversion.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIConversionTest.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIMapper.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URISource.java create mode 100644 processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URITarget.java diff --git a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc index 9da7ff75c1..d95e6c7a62 100644 --- a/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc +++ b/documentation/src/main/asciidoc/chapter-5-data-type-conversions.asciidoc @@ -127,6 +127,9 @@ public interface CarMapper { * Between `String` and `StringBuilder` +* Between `java.net.URI` and `String`. +** When converting from a `String`, the value needs to be a valid https://datatracker.ietf.org/doc/html/rfc2396[RFC 2396 URI] otherwise an `IllegalArgumentException` is thrown. + * Between `java.net.URL` and `String`. ** When converting from a `String`, the value needs to be a valid https://en.wikipedia.org/wiki/URL[URL] otherwise a `MalformedURLException` is thrown. diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java index 96960c4a11..ee052b5405 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/ConversionUtils.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.net.URI; import java.net.URL; import java.sql.Time; import java.sql.Timestamp; @@ -269,6 +270,17 @@ public static String uuid(ConversionContext conversionContext) { return typeReferenceName( conversionContext, UUID.class ); } + /** + * Name for {@link java.net.URI}. + * + * @param conversionContext Conversion context + * + * @return Name or fully-qualified name. + */ + public static String uri(ConversionContext conversionContext) { + return typeReferenceName( conversionContext, URI.class ); + } + /** * Name for {@link java.net.URL}. * diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 076cd2f42e..7b2f8702b1 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -7,6 +7,7 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.net.URI; import java.net.URL; import java.sql.Time; import java.sql.Timestamp; @@ -201,7 +202,7 @@ public Conversions(TypeFactory typeFactory) { register( UUID.class, String.class, new UUIDToStringConversion() ); register( Locale.class, String.class, new LocaleToStringConversion() ); - registerURLConversion(); + registerJavaNetConversions(); } private void registerJodaConversions() { @@ -306,13 +307,14 @@ private void registerBigDecimalConversion(Class targetType) { } } - private void registerURLConversion() { - if ( isJavaURLAvailable() ) { + private void registerJavaNetConversions() { + if ( isJavaNetAvailable() ) { + register( URI.class, String.class, new URIToStringConversion() ); register( URL.class, String.class, new URLToStringConversion() ); } } - private boolean isJavaURLAvailable() { + private boolean isJavaNetAvailable() { return typeFactory.isTypeAvailable( "java.net.URL" ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/URIToStringConversion.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/URIToStringConversion.java new file mode 100644 index 0000000000..c25383ae05 --- /dev/null +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/URIToStringConversion.java @@ -0,0 +1,37 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.internal.conversion; + +import java.net.URI; +import java.util.Set; + +import org.mapstruct.ap.internal.model.common.ConversionContext; +import org.mapstruct.ap.internal.model.common.Type; + +import static org.mapstruct.ap.internal.conversion.ConversionUtils.uri; +import static org.mapstruct.ap.internal.util.Collections.asSet; + +/** + * Conversion between {@link java.net.URI} and {@link String}. + * + * @author Maciej Kucharczyk + */ +public class URIToStringConversion extends SimpleConversion { + @Override + protected String getToExpression(ConversionContext conversionContext) { + return ".toString()"; + } + + @Override + protected String getFromExpression(ConversionContext conversionContext) { + return uri( conversionContext ) + ".create( )"; + } + + @Override + protected Set getFromConversionImportTypes(final ConversionContext conversionContext) { + return asSet( conversionContext.getTypeFactory().getType( URI.class ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIConversionTest.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIConversionTest.java new file mode 100644 index 0000000000..d7d3ef4142 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIConversionTest.java @@ -0,0 +1,56 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uri; + +import java.net.URI; + +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.ProcessorTest; +import org.mapstruct.ap.testutil.WithClasses; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Tests conversions between {@link java.net.URI} and String. + * + * @author Maciej Kucharczyk + */ +@IssueKey("4018") +@WithClasses({ URISource.class, URITarget.class, URIMapper.class }) +public class URIConversionTest { + + @ProcessorTest + public void shouldApplyURIConversion() { + URISource source = new URISource(); + source.setUriA( URI.create( "https://mapstruct.org/" ) ); + + URITarget target = URIMapper.INSTANCE.sourceToTarget( source ); + + assertThat( target ).isNotNull(); + assertThat( target.getUriA() ).isEqualTo( source.getUriA().toString() ); + } + + @ProcessorTest + public void shouldApplyReverseURIConversion() { + URITarget target = new URITarget(); + target.setUriA( "https://mapstruct.org/" ); + + URISource source = URIMapper.INSTANCE.targetToSource( target ); + + assertThat( source ).isNotNull(); + assertThat( source.getUriA() ).isEqualTo( URI.create( target.getUriA() ) ); + } + + @ProcessorTest + public void shouldHandleInvalidURIString() { + URITarget target = new URITarget(); + target.setInvalidURI( "ht!tp://example.com" ); + + assertThatThrownBy( () -> URIMapper.INSTANCE.targetToSource( target ) ) + .isInstanceOf( IllegalArgumentException.class ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIMapper.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIMapper.java new file mode 100644 index 0000000000..cac94a4efa --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URIMapper.java @@ -0,0 +1,19 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uri; + +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface URIMapper { + + URIMapper INSTANCE = Mappers.getMapper( URIMapper.class ); + + URITarget sourceToTarget(URISource source); + + URISource targetToSource(URITarget target); +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URISource.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URISource.java new file mode 100644 index 0000000000..502169fccb --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URISource.java @@ -0,0 +1,33 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uri; + +import java.net.URI; + +/** + * @author Maciej Kucharczyk + */ +public class URISource { + private URI uriA; + + private URI invalidURI; + + public URI getUriA() { + return uriA; + } + + public void setUriA(URI uriA) { + this.uriA = uriA; + } + + public URI getInvalidURI() { + return invalidURI; + } + + public void setInvalidURI(URI invalidURI) { + this.invalidURI = invalidURI; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URITarget.java b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URITarget.java new file mode 100644 index 0000000000..b221392127 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/conversion/uri/URITarget.java @@ -0,0 +1,30 @@ +/* + * Copyright MapStruct Authors. + * + * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 + */ +package org.mapstruct.ap.test.conversion.uri; + +/** + * @author Maciej Kucharczyk + */ +public class URITarget { + private String uriA; + private String invalidURI; + + public String getUriA() { + return uriA; + } + + public void setUriA(String uriA) { + this.uriA = uriA; + } + + public String getInvalidURI() { + return invalidURI; + } + + public void setInvalidURI(String invalidURI) { + this.invalidURI = invalidURI; + } +} From 6a567516be5e2e38a7314d892b08468c7823c6db Mon Sep 17 00:00:00 2001 From: hduelme <46139144+hduelme@users.noreply.github.com> Date: Fri, 27 Mar 2026 18:06:09 +0100 Subject: [PATCH 0966/1006] Upgrade integration tests to junit5 (#4023) --- .../GradleIncrementalCompilationTest.java | 50 +++++++++---------- .../itest/auto/value/AutoValueMapperTest.java | 8 +-- .../src/test/resources/cdiTest/pom.xml | 8 +-- .../itest/cdi/CdiBasedMapperTest.java | 14 +++--- .../test/java/DefaultPackageTest.java | 6 +-- .../itest/textBlocks/TextBlocksTest.java | 6 +-- .../itest/externalbeanjar/ConversionTest.java | 6 +-- .../generator/pom.xml | 4 +- .../usage/pom.xml | 4 +- .../usage/FaultyAstModifyingTestTest.java | 6 +-- .../freebuilder/FreeBuilderMapperTest.java | 8 +-- .../mapstruct/itest/simple/AnimalTest.java | 8 +-- .../immutables/ImmutablesMapperTest.java | 8 +-- .../jaxb/JakartaJaxbBasedMapperTest.java | 8 +-- .../ap/test/bugs/_603/Issue603Test.java | 7 ++- .../ap/test/bugs/_636/Issue636Test.java | 6 +-- .../itest/java8/Java8MapperTest.java | 6 +-- .../itest/jaxb/JaxbBasedMapperTest.java | 8 +-- .../src/test/resources/jsr330Test/pom.xml | 4 ++ .../itest/jsr330/Jsr330BasedMapperTest.java | 16 +++--- .../itest/kotlin/data/KotlinDataTest.java | 8 +-- .../itest/lombok/LombokMapperTest.java | 8 +-- .../itest/lombok/LombokMapperTest.java | 8 +-- .../mapstruct/itest/modules/ModulesTest.java | 6 +-- .../mapstruct/itest/naming/NamingTest.java | 6 +-- integrationtest/src/test/resources/pom.xml | 5 +- .../itest/protobuf/ProtobufMapperTest.java | 8 +-- .../itest/records/module2/RecordsTest.java | 6 +-- .../itest/records/mapper/RecordsTest.java | 8 +-- .../mapstruct/itest/records/RecordsTest.java | 22 ++++---- .../records/nested/NestedRecordsTest.java | 6 +-- .../sealedsubclass/SealedSubclassTest.java | 10 ++-- .../itest/simple/ConversionTest.java | 18 +++---- .../src/test/resources/springTest/pom.xml | 4 ++ .../itest/spring/SpringBasedMapperTest.java | 16 +++--- .../superTypeGenerationTest/generator/pom.xml | 4 +- .../superTypeGenerationTest/usage/pom.xml | 4 +- .../usage/GeneratedBasesTest.java | 8 +-- .../generator/pom.xml | 4 +- .../targetTypeGenerationTest/usage/pom.xml | 4 +- .../usage/GeneratedTargetTypeTest.java | 8 +-- .../usesTypeGenerationTest/generator/pom.xml | 4 +- .../usesTypeGenerationTest/usage/pom.xml | 4 +- .../usage/GeneratedUsesTypeTest.java | 6 +-- parent/pom.xml | 7 +-- 45 files changed, 193 insertions(+), 190 deletions(-) diff --git a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java index 3d496906c0..a12af7690f 100644 --- a/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java +++ b/integrationtest/src/test/java/org/mapstruct/itest/tests/GradleIncrementalCompilationTest.java @@ -13,47 +13,49 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; import org.apache.commons.io.FileUtils; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Named; import org.junit.jupiter.api.condition.DisabledForJreRange; import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.runners.Parameterized.Parameters; +import static org.assertj.core.api.Assertions.assertThat; import static org.gradle.testkit.runner.TaskOutcome.SUCCESS; import static org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE; -import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; /** *

        This is supposed to be run from the mapstruct root project folder. * Otherwise, use -Dmapstruct_root=path_to_project. */ @DisabledForJreRange(min = JRE.JAVA_11) -public class GradleIncrementalCompilationTest { +class GradleIncrementalCompilationTest { private static Path rootPath; - private static String projectDir = "integrationtest/src/test/resources/gradleIncrementalCompilationTest"; - private static String compileTaskName = "compileJava"; + private static final String PROJECT_DIR = "integrationtest/src/test/resources/gradleIncrementalCompilationTest"; + private static final String COMPILE_TASK_NAME = "compileJava"; @TempDir - File testBuildDir; + private File testBuildDir; @TempDir - File testProjectDir; + private File testProjectDir; private GradleRunner runner; private File sourceDirectory; private List compileArgs; // Gradle compile task arguments - @Parameters(name = "Gradle {0}") - public static List gradleVersions() { - return Arrays.asList( "5.0", "6.0" ); + static Stream gradleVersions() { + return Stream.of( + Arguments.of( Named.of( "Gradle 5.0", "5.0" ) ), + Arguments.of( Named.of( "Gradle 6.0", "6.0" ) ) ); } private void replaceInFile(File file, CharSequence target, CharSequence replacement) throws IOException { @@ -68,15 +70,13 @@ private GradleRunner getRunner(String... additionalArguments) { } private void assertCompileOutcome(BuildResult result, TaskOutcome outcome) { - assertEquals( outcome, result.task( ":" + compileTaskName ).getOutcome() ); + assertEquals( outcome, result.task( ":" + COMPILE_TASK_NAME ).getOutcome() ); } private void assertRecompiled(BuildResult result, int recompiledCount) { assertCompileOutcome( result, recompiledCount > 0 ? SUCCESS : UP_TO_DATE ); - assertThat( - result.getOutput(), - containsString( String.format( "Incremental compilation of %d classes completed", recompiledCount ) ) - ); + assertThat( result.getOutput() ) + .contains( String.format( "Incremental compilation of %d classes completed", recompiledCount ) ); } private List buildCompileArgs() { @@ -85,11 +85,11 @@ private List buildCompileArgs() { // Inject the path to the folder containing the mapstruct-processor JAR String jarDirectoryArg = "-PmapstructRootPath=" + rootPath.toString(); - return Arrays.asList( compileTaskName, buildDirPropertyArg, jarDirectoryArg ); + return Arrays.asList( COMPILE_TASK_NAME, buildDirPropertyArg, jarDirectoryArg ); } @BeforeAll - public static void setupClass() throws Exception { + static void setupClass() { rootPath = Paths.get( System.getProperty( "mapstruct_root", "." ) ).toAbsolutePath(); } @@ -102,7 +102,7 @@ public void setup(String gradleVersion) throws IOException { testProjectDir.mkdirs(); } // Copy test project files to the temp dir - Path gradleProjectPath = rootPath.resolve( projectDir ); + Path gradleProjectPath = rootPath.resolve( PROJECT_DIR ); FileUtils.copyDirectory( gradleProjectPath.toFile(), testProjectDir ); compileArgs = buildCompileArgs(); sourceDirectory = new File( testProjectDir, "src/main/java" ); @@ -111,7 +111,7 @@ public void setup(String gradleVersion) throws IOException { @ParameterizedTest @MethodSource("gradleVersions") - public void testBuildSucceeds(String gradleVersion) throws IOException { + void testBuildSucceeds(String gradleVersion) throws IOException { setup( gradleVersion ); // Make sure the test build setup actually compiles BuildResult buildResult = getRunner().build(); @@ -120,7 +120,7 @@ public void testBuildSucceeds(String gradleVersion) throws IOException { @ParameterizedTest @MethodSource("gradleVersions") - public void testUpToDate(String gradleVersion) throws IOException { + void testUpToDate(String gradleVersion) throws IOException { setup( gradleVersion ); getRunner().build(); BuildResult secondBuildResult = getRunner().build(); @@ -129,7 +129,7 @@ public void testUpToDate(String gradleVersion) throws IOException { @ParameterizedTest @MethodSource("gradleVersions") - public void testChangeConstant(String gradleVersion) throws IOException { + void testChangeConstant(String gradleVersion) throws IOException { setup( gradleVersion ); getRunner().build(); // Change return value in class Target @@ -143,7 +143,7 @@ public void testChangeConstant(String gradleVersion) throws IOException { @ParameterizedTest @MethodSource("gradleVersions") - public void testChangeTargetField(String gradleVersion) throws IOException { + void testChangeTargetField(String gradleVersion) throws IOException { setup( gradleVersion ); getRunner().build(); // Change target field in mapper interface @@ -157,7 +157,7 @@ public void testChangeTargetField(String gradleVersion) throws IOException { @ParameterizedTest @MethodSource("gradleVersions") - public void testChangeUnrelatedFile(String gradleVersion) throws IOException { + void testChangeUnrelatedFile(String gradleVersion) throws IOException { setup( gradleVersion ); getRunner().build(); File unrelatedFile = new File( sourceDirectory, "org/mapstruct/itest/gradle/lib/UnrelatedComponent.java" ); diff --git a/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java index 8f640780f3..4ce5530a5d 100644 --- a/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java +++ b/integrationtest/src/test/resources/autoValueBuilderTest/src/test/java/org/mapstruct/itest/auto/value/AutoValueMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.auto.value; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Eric Martineau */ -public class AutoValueMapperTest { +class AutoValueMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.builder() .age( 33 ) .name( "Bob" ) @@ -32,7 +32,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); assertThat( person.getName() ).isEqualTo( "Bob" ); diff --git a/integrationtest/src/test/resources/cdiTest/pom.xml b/integrationtest/src/test/resources/cdiTest/pom.xml index 0b3c394e82..cb00fbaa01 100644 --- a/integrationtest/src/test/resources/cdiTest/pom.xml +++ b/integrationtest/src/test/resources/cdiTest/pom.xml @@ -30,8 +30,8 @@ javax.inject - org.jboss.arquillian.junit - arquillian-junit-container + org.jboss.arquillian.junit5 + arquillian-junit5-container test @@ -45,8 +45,8 @@ test - org.jboss.arquillian.junit - arquillian-junit-core + org.jboss.arquillian.junit5 + arquillian-junit5-core test diff --git a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java index 0c343fce27..4ede2eb78a 100644 --- a/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java +++ b/integrationtest/src/test/resources/cdiTest/src/test/java/org/mapstruct/itest/cdi/CdiBasedMapperTest.java @@ -10,12 +10,12 @@ import javax.inject.Inject; import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.junit5.ArquillianExtension; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mapstruct.itest.cdi.other.DateMapper; /** @@ -23,8 +23,8 @@ * * @author Gunnar Morling */ -@RunWith( Arquillian.class ) -public class CdiBasedMapperTest { +@ExtendWith( ArquillianExtension.class ) +class CdiBasedMapperTest { @Inject private SourceTargetMapper mapper; @@ -45,7 +45,7 @@ public static JavaArchive createDeployment() { } @Test - public void shouldCreateCdiBasedMapper() { + void shouldCreateCdiBasedMapper() { Source source = new Source(); Target target = mapper.sourceToTarget( source ); @@ -56,7 +56,7 @@ public void shouldCreateCdiBasedMapper() { } @Test - public void shouldInjectDecorator() { + void shouldInjectDecorator() { Source source = new Source(); Target target = decoratedMapper.sourceToTarget( source ); diff --git a/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java b/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java index ddc834cc8e..c3f84b6ab6 100644 --- a/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java +++ b/integrationtest/src/test/resources/defaultPackage/test/java/DefaultPackageTest.java @@ -4,7 +4,7 @@ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 */ -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -12,10 +12,10 @@ * @author Filip Hrisafov */ -public class DefaultPackageTest { +class DefaultPackageTest { @Test - public void shouldWorkCorrectlyInDefaultPackage() { + void shouldWorkCorrectlyInDefaultPackage() { DefaultPackageObject.CarDto carDto = DefaultPackageObject.CarMapper.INSTANCE.carToCarDto( new DefaultPackageObject.Car( "Morris", diff --git a/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java b/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java index 42ed70b18e..504a961437 100644 --- a/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java +++ b/integrationtest/src/test/resources/expressionTextBlocksTest/src/test/java/org/mapstruct/itest/textBlocks/TextBlocksTest.java @@ -9,12 +9,12 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TextBlocksTest { +class TextBlocksTest { @Test - public void textBlockExpressionShouldWork() { + void textBlockExpressionShouldWork() { Car car = new Car(); car.setWheelPosition( new WheelPosition( "left" ) ); diff --git a/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java index 8a18e9e4fc..af10a63428 100644 --- a/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java +++ b/integrationtest/src/test/resources/externalbeanjar/mapper/src/test/java/org/mapstruct/itest/externalbeanjar/ConversionTest.java @@ -8,15 +8,15 @@ import java.math.BigDecimal; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.externalbeanjar.Source; import org.mapstruct.itest.externalbeanjar.Issue1121Mapper; import org.mapstruct.itest.externalbeanjar.Target; -public class ConversionTest { +class ConversionTest { @Test - public void shouldApplyConversions() { + void shouldApplyConversions() { Source source = new Source(); source.setBigDecimal( new BigDecimal( "42" ) ); diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml index 08390085dd..60b73b856c 100644 --- a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/generator/pom.xml @@ -27,8 +27,8 @@ provided - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml index 90c95aa83b..976664f88d 100644 --- a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java index 06bfa3c533..ed6a5c0d89 100644 --- a/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java +++ b/integrationtest/src/test/resources/faultyAstModifyingAnnotationProcessorTest/usage/src/test/java/org/mapstruct/itest/faultyAstModifyingProcessor/usage/FaultyAstModifyingTestTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.faultyAstModifyingProcessor.usage; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Filip Hrisafov */ -public class FaultyAstModifyingTestTest { +class FaultyAstModifyingTestTest { @Test - public void testMapping() { + void testMapping() { Order order = new Order(); order.setItem( "my item" ); diff --git a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java index 5047451798..3b1caebf9c 100644 --- a/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java +++ b/integrationtest/src/test/resources/freeBuilderBuilderTest/src/test/java/org/mapstruct/itest/freebuilder/FreeBuilderMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.freebuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Eric Martineau */ -public class FreeBuilderMapperTest { +class FreeBuilderMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.builder() .setAge( 33 ) .setName( "Bob" ) @@ -32,7 +32,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); assertThat( person.getName() ).isEqualTo( "Bob" ); diff --git a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java index a180b4df52..14dd576fe0 100644 --- a/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java +++ b/integrationtest/src/test/resources/fullFeatureTest/src/test/java/org/mapstruct/itest/simple/AnimalTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.ap.test.ignore.AnimalMapper; import org.mapstruct.ap.test.ignore.Animal; @@ -18,10 +18,10 @@ * * @author Gunnar Morling */ -public class AnimalTest { +class AnimalTest { @Test - public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { + void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { Animal animal = new Animal( "Bruno", 100, 23, "black" ); AnimalDto animalDto = AnimalMapper.INSTANCE.animalToDto( animal ); @@ -34,7 +34,7 @@ public void shouldNotPropagateIgnoredPropertyGivenViaTargetAttribute() { } @Test - public void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTargetAreSpecified() { + void shouldNotPropagateIgnoredPropertyInReverseMappingWhenSourceAndTargetAreSpecified() { AnimalDto animalDto = new AnimalDto( "Bruno", 100, 23, "black" ); Animal animal = AnimalMapper.INSTANCE.animalDtoToAnimal( animalDto ); diff --git a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java index 421954fc90..9990f4278c 100644 --- a/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java +++ b/integrationtest/src/test/resources/immutablesBuilderTest/mapper/src/test/java/org/mapstruct/itest/immutables/ImmutablesMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.immutables; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Eric Martineau */ -public class ImmutablesMapperTest { +class ImmutablesMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( ImmutablePerson.builder() .age( 33 ) .name( "Bob" ) @@ -32,7 +32,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); assertThat( person.getName() ).isEqualTo( "Bob" ); diff --git a/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java b/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java index b81c946d9c..afd5ba0289 100644 --- a/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java +++ b/integrationtest/src/test/resources/jakartaJaxbTest/src/test/java/org/mapstruct/itest/jakarta/jaxb/JakartaJaxbBasedMapperTest.java @@ -18,7 +18,7 @@ import jakarta.xml.bind.JAXBException; import jakarta.xml.bind.Marshaller; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.jakarta.jaxb.xsd.test1.ObjectFactory; import org.mapstruct.itest.jakarta.jaxb.xsd.test1.OrderType; import org.mapstruct.itest.jakarta.jaxb.xsd.underscores.SubType; @@ -28,10 +28,10 @@ * * @author Iaroslav Bogdanchikov */ -public class JakartaJaxbBasedMapperTest { +class JakartaJaxbBasedMapperTest { @Test - public void shouldMapJakartaJaxb() throws ParseException, JAXBException { + void shouldMapJakartaJaxb() throws ParseException, JAXBException { SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; @@ -81,7 +81,7 @@ public void shouldMapJakartaJaxb() throws ParseException, JAXBException { } @Test - public void underscores() throws ParseException, JAXBException { + void underscores() throws ParseException, JAXBException { SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java index c732b96f22..efe68a48ee 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_603/Issue603Test.java @@ -5,15 +5,14 @@ */ package org.mapstruct.ap.test.bugs._603; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -public class Issue603Test { +class Issue603Test { @Test - public void shouldMapDataFromJava8Interface() { + void shouldMapDataFromJava8Interface() { final Source source = new Source(); diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java index 99b7a515eb..837eb0b53a 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/ap/test/bugs/_636/Issue636Test.java @@ -5,14 +5,14 @@ */ package org.mapstruct.ap.test.bugs._636; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; -public class Issue636Test { +class Issue636Test { @Test - public void shouldMapDataFromJava8Interface() { + void shouldMapDataFromJava8Interface() { final long idFoo = 123; final String idBar = "Bar456"; diff --git a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java index 556dd2f1e4..3f88889380 100644 --- a/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java +++ b/integrationtest/src/test/resources/java8Test/src/test/java/org/mapstruct/itest/java8/Java8MapperTest.java @@ -7,17 +7,17 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for generation of Java8 based mapper implementations. * * @author Christian Schuster */ -public class Java8MapperTest { +class Java8MapperTest { @Test - public void shouldMapWithRepeatedMappingAnnotation() { + void shouldMapWithRepeatedMappingAnnotation() { Java8Mapper mapper = Java8Mapper.INSTANCE; Source source = new Source(); diff --git a/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java b/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java index f54658ba06..4c81dc91d2 100644 --- a/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java +++ b/integrationtest/src/test/resources/jaxbTest/src/test/java/org/mapstruct/itest/jaxb/JaxbBasedMapperTest.java @@ -18,7 +18,7 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.jaxb.xsd.test1.ObjectFactory; import org.mapstruct.itest.jaxb.xsd.test1.OrderType; import org.mapstruct.itest.jaxb.xsd.underscores.SubType; @@ -28,9 +28,9 @@ * * @author Sjaak Derksen */ -public class JaxbBasedMapperTest { +class JaxbBasedMapperTest { @Test - public void shouldMapJaxb() throws ParseException, JAXBException { + void shouldMapJaxb() throws ParseException, JAXBException { SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; @@ -80,7 +80,7 @@ public void shouldMapJaxb() throws ParseException, JAXBException { } @Test - public void underscores() throws ParseException, JAXBException { + void underscores() throws ParseException, JAXBException { SourceTargetMapper mapper = SourceTargetMapper.INSTANCE; diff --git a/integrationtest/src/test/resources/jsr330Test/pom.xml b/integrationtest/src/test/resources/jsr330Test/pom.xml index 9a7dbcbc8a..e1cf959a90 100644 --- a/integrationtest/src/test/resources/jsr330Test/pom.xml +++ b/integrationtest/src/test/resources/jsr330Test/pom.xml @@ -18,6 +18,10 @@ jsr330Test jar + + + ${org.junit6.jupiter.version} + diff --git a/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java b/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java index 525930f0ec..6cf9043472 100644 --- a/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java +++ b/integrationtest/src/test/resources/jsr330Test/src/test/java/org/mapstruct/itest/jsr330/Jsr330BasedMapperTest.java @@ -8,13 +8,13 @@ import jakarta.inject.Inject; import jakarta.inject.Named; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mapstruct.itest.jsr330.Jsr330BasedMapperTest.SpringTestConfig; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -24,8 +24,8 @@ * @author Andreas Gudian */ @ContextConfiguration(classes = SpringTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class Jsr330BasedMapperTest { +@ExtendWith(SpringExtension.class) +class Jsr330BasedMapperTest { @Configuration @ComponentScan(basePackageClasses = Jsr330BasedMapperTest.class) public static class SpringTestConfig { @@ -43,7 +43,7 @@ public static class SpringTestConfig { private SecondDecoratedSourceTargetMapper secondDecoratedMapper; @Test - public void shouldInjectJsr330BasedMapper() { + void shouldInjectJsr330BasedMapper() { Source source = new Source(); Target target = mapper.sourceToTarget( source ); @@ -54,7 +54,7 @@ public void shouldInjectJsr330BasedMapper() { } @Test - public void shouldInjectDecorator() { + void shouldInjectDecorator() { Source source = new Source(); Target target = decoratedMapper.sourceToTarget( source ); @@ -71,7 +71,7 @@ public void shouldInjectDecorator() { } @Test - public void shouldInjectSecondDecorator() { + void shouldInjectSecondDecorator() { Source source = new Source(); Target target = secondDecoratedMapper.sourceToTarget( source ); diff --git a/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java b/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java index 513f080a8b..e46b76f5f0 100644 --- a/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java +++ b/integrationtest/src/test/resources/kotlinDataTest/src/test/java/org/mapstruct/itest/kotlin/data/KotlinDataTest.java @@ -7,15 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.kotlin.data.CustomerDto; import org.mapstruct.itest.kotlin.data.CustomerEntity; import org.mapstruct.itest.kotlin.data.CustomerMapper; -public class KotlinDataTest { +class KotlinDataTest { @Test - public void shouldMapData() { + void shouldMapData() { CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); assertThat( customer ).isNotNull(); @@ -24,7 +24,7 @@ public void shouldMapData() { } @Test - public void shouldMapIntoData() { + void shouldMapIntoData() { CustomerEntity entity = new CustomerEntity(); entity.setName( "Kermit" ); entity.setMail( "kermit@test.com" ); diff --git a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java index 6053f294c3..060fb5a990 100644 --- a/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java +++ b/integrationtest/src/test/resources/lombokBuilderTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.lombok; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; import static org.assertj.core.api.Assertions.assertThat; @@ -15,10 +15,10 @@ * * @author Eric Martineau */ -public class LombokMapperTest { +class LombokMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( Person.foo() .age( 33 ) .name( "Bob" ) @@ -33,7 +33,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); assertThat( person.getName() ).isEqualTo( "Bob" ); diff --git a/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java b/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java index f8b702896d..bdf8f46a57 100644 --- a/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java +++ b/integrationtest/src/test/resources/lombokModuleTest/src/test/java/org/mapstruct/itest/lombok/LombokMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.lombok; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; import static org.assertj.core.api.Assertions.assertThat; @@ -15,10 +15,10 @@ * * @author Eric Martineau */ -public class LombokMapperTest { +class LombokMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( new Person( "Bob", 33, new Address( "Wild Drive" ) ) ); assertThat( personDto.getAge() ).isEqualTo( 33 ); assertThat( personDto.getName() ).isEqualTo( "Bob" ); @@ -27,7 +27,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); assertThat( person.getName() ).isEqualTo( "Bob" ); diff --git a/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java b/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java index 805662c806..aae996c842 100644 --- a/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java +++ b/integrationtest/src/test/resources/moduleInfoTest/src/test/java/org/mapstruct/itest/modules/ModulesTest.java @@ -7,15 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.modules.CustomerDto; import org.mapstruct.itest.modules.CustomerEntity; import org.mapstruct.itest.modules.CustomerMapper; -public class ModulesTest { +class ModulesTest { @Test - public void shouldMapRecord() { + void shouldMapRecord() { CustomerDto dto = new CustomerDto(); dto.setName( "Kermit" ); dto.setEmail( "kermit@test.com" ); diff --git a/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java b/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java index d3a45db26b..adc7aac7cb 100644 --- a/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java +++ b/integrationtest/src/test/resources/namingStrategyTest/usage/src/test/java/org/mapstruct/itest/naming/NamingTest.java @@ -7,7 +7,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.naming.GolfPlayer; import org.mapstruct.itest.naming.GolfPlayerDto; import org.mapstruct.itest.naming.GolfPlayerMapper; @@ -17,10 +17,10 @@ * * @author Gunnar Morling */ -public class NamingTest { +class NamingTest { @Test - public void shouldApplyCustomNamingStrategy() { + void shouldApplyCustomNamingStrategy() { GolfPlayer player = new GolfPlayer() .withName( "Jared" ) .withHandicap( 9.2D ); diff --git a/integrationtest/src/test/resources/pom.xml b/integrationtest/src/test/resources/pom.xml index 3053b211e1..f4cd0b51de 100644 --- a/integrationtest/src/test/resources/pom.xml +++ b/integrationtest/src/test/resources/pom.xml @@ -26,6 +26,7 @@ ${mapstruct.version} + 6.0.3 @@ -135,8 +136,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java b/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java index ae3740848f..ac97eba8b4 100644 --- a/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java +++ b/integrationtest/src/test/resources/protobufBuilderTest/src/test/java/org/mapstruct/itest/protobuf/ProtobufMapperTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.protobuf; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Christian Bandowski */ -public class ProtobufMapperTest { +class ProtobufMapperTest { @Test - public void testSimpleImmutableBuilderHappyPath() { + void testSimpleImmutableBuilderHappyPath() { PersonDto personDto = PersonMapper.INSTANCE.toDto( PersonProtos.Person.newBuilder() .setAge( 33 ) .setName( "Bob" ) @@ -33,7 +33,7 @@ public void testSimpleImmutableBuilderHappyPath() { } @Test - public void testLombokToImmutable() { + void testLombokToImmutable() { PersonProtos.Person person = PersonMapper.INSTANCE.fromDto( new PersonDto( "Bob", 33, new AddressDto( "Wild Drive" ) ) ); assertThat( person.getAge() ).isEqualTo( 33 ); diff --git a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java index 5f7a99273a..4064e0fe3f 100644 --- a/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsCrossModuleInterfaceTest/module-2/src/test/java/org/mapstruct/itest/records/module2/RecordsTest.java @@ -7,14 +7,14 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.records.module1.SourceRootRecord; import org.mapstruct.itest.records.module1.SourceNestedRecord; -public class RecordsTest { +class RecordsTest { @Test - public void shouldMap() { + void shouldMap() { SourceRootRecord source = new SourceRootRecord( new SourceNestedRecord( "test" ) ); TargetRootRecord target = RecordInterfaceIssueMapper.INSTANCE.map( source ); diff --git a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java index 2f274792b8..218fd82c6a 100644 --- a/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsCrossModuleTest/mapper/src/test/java/org/mapstruct/itest/records/mapper/RecordsTest.java @@ -7,15 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.records.api.CustomerDto; import org.mapstruct.itest.records.mapper.CustomerEntity; import org.mapstruct.itest.records.mapper.CustomerMapper; -public class RecordsTest { +class RecordsTest { @Test - public void shouldMapRecord() { + void shouldMapRecord() { CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); assertThat( customer ).isNotNull(); @@ -24,7 +24,7 @@ public void shouldMapRecord() { } @Test - public void shouldMapIntoRecord() { + void shouldMapIntoRecord() { CustomerEntity entity = new CustomerEntity(); entity.setName( "Kermit" ); entity.setMail( "kermit@test.com" ); diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java index 2f77e8d49f..2a510edafd 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/RecordsTest.java @@ -9,15 +9,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.records.CustomerDto; import org.mapstruct.itest.records.CustomerEntity; import org.mapstruct.itest.records.CustomerMapper; -public class RecordsTest { +class RecordsTest { @Test - public void shouldMapRecord() { + void shouldMapRecord() { CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) ); assertThat( customer ).isNotNull(); @@ -26,7 +26,7 @@ public void shouldMapRecord() { } @Test - public void shouldMapIntoRecord() { + void shouldMapIntoRecord() { CustomerEntity entity = new CustomerEntity(); entity.setName( "Kermit" ); entity.setMail( "kermit@test.com" ); @@ -39,7 +39,7 @@ public void shouldMapIntoRecord() { } @Test - public void shouldMapIntoGenericRecord() { + void shouldMapIntoGenericRecord() { CustomerEntity entity = new CustomerEntity(); entity.setName( "Kermit" ); entity.setMail( "kermit@test.com" ); @@ -51,7 +51,7 @@ public void shouldMapIntoGenericRecord() { } @Test - public void shouldMapIntoRecordWithList() { + void shouldMapIntoRecordWithList() { Car car = new Car(); car.setWheelPositions( Arrays.asList( new WheelPosition( "left" ) ) ); @@ -63,7 +63,7 @@ public void shouldMapIntoRecordWithList() { } @Test - public void shouldMapMemberRecord() { + void shouldMapMemberRecord() { MemberEntity member = MemberMapper.INSTANCE.fromRecord( new MemberDto( true, false ) ); assertThat( member ).isNotNull(); @@ -72,7 +72,7 @@ public void shouldMapMemberRecord() { } @Test - public void shouldMapIntoMemberRecord() { + void shouldMapIntoMemberRecord() { MemberEntity entity = new MemberEntity(); entity.setIsActive( false ); entity.setPremium( true ); @@ -80,12 +80,12 @@ public void shouldMapIntoMemberRecord() { MemberDto value = MemberMapper.INSTANCE.toRecord( entity ); assertThat( value ).isNotNull(); - assertThat( value.isActive() ).isEqualTo( false ); - assertThat( value.premium() ).isEqualTo( true ); + assertThat( value.isActive() ).isFalse(); + assertThat( value.premium() ).isTrue(); } @Test - public void shouldUseDefaultConstructor() { + void shouldUseDefaultConstructor() { Task entity = new Task( "some-id", 1000L ); TaskDto value = TaskMapper.INSTANCE.toRecord( entity ); diff --git a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java index c8ccaf1a65..c70937fa84 100644 --- a/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java +++ b/integrationtest/src/test/resources/recordsTest/src/test/java/org/mapstruct/itest/records/nested/NestedRecordsTest.java @@ -9,12 +9,12 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class NestedRecordsTest { +class NestedRecordsTest { @Test - public void shouldMapRecord() { + void shouldMapRecord() { CareProvider source = new CareProvider( "kermit", new Address( "Sesame Street", "New York" ) ); CareProviderDto target = CareProviderMapper.INSTANCE.map( source ); diff --git a/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java b/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java index 379341ff66..171b6519c6 100644 --- a/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java +++ b/integrationtest/src/test/resources/sealedSubclassTest/src/test/java/org/mapstruct/itest/sealedsubclass/SealedSubclassTest.java @@ -7,12 +7,12 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class SealedSubclassTest { +class SealedSubclassTest { @Test - public void mappingIsDoneUsingSubclassMapping() { + void mappingIsDoneUsingSubclassMapping() { VehicleCollection vehicles = new VehicleCollection(); vehicles.getVehicles().add( new Car() ); vehicles.getVehicles().add( new Bike() ); @@ -28,7 +28,7 @@ public void mappingIsDoneUsingSubclassMapping() { } @Test - public void inverseMappingIsDoneUsingSubclassMapping() { + void inverseMappingIsDoneUsingSubclassMapping() { VehicleCollectionDto vehicles = new VehicleCollectionDto(); vehicles.getVehicles().add( new CarDto() ); vehicles.getVehicles().add( new BikeDto() ); @@ -44,7 +44,7 @@ public void inverseMappingIsDoneUsingSubclassMapping() { } @Test - public void subclassMappingInheritsInverseMapping() { + void subclassMappingInheritsInverseMapping() { VehicleCollectionDto vehiclesDto = new VehicleCollectionDto(); CarDto carDto = new CarDto(); carDto.setMaker( "BenZ" ); diff --git a/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java b/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java index 2b6a0bc93b..69c94322bd 100644 --- a/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java +++ b/integrationtest/src/test/resources/simpleTest/src/test/java/org/mapstruct/itest/simple/ConversionTest.java @@ -7,15 +7,15 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.simple.Source; import org.mapstruct.itest.simple.SourceTargetMapper; import org.mapstruct.itest.simple.Target; -public class ConversionTest { +class ConversionTest { @Test - public void shouldApplyConversions() { + void shouldApplyConversions() { Source source = new Source(); source.setFoo( 42 ); source.setBar( 23L ); @@ -30,18 +30,18 @@ public void shouldApplyConversions() { } @Test - public void shouldHandleNulls() { + void shouldHandleNulls() { Source source = new Source(); Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source ); assertThat( target ).isNotNull(); assertThat( target.getFoo() ).isEqualTo( Long.valueOf( 1 ) ); - assertThat( target.getBar() ).isEqualTo( 0 ); + assertThat( target.getBar() ).isZero(); assertThat( target.getZip() ).isEqualTo( "0" ); } @Test - public void shouldApplyConversionsToMappedProperties() { + void shouldApplyConversionsToMappedProperties() { Source source = new Source(); source.setQax( 42 ); source.setBaz( 23L ); @@ -54,7 +54,7 @@ public void shouldApplyConversionsToMappedProperties() { } @Test - public void shouldApplyConversionsForReverseMapping() { + void shouldApplyConversionsForReverseMapping() { Target target = new Target(); target.setFoo( 42L ); target.setBar( 23 ); @@ -69,7 +69,7 @@ public void shouldApplyConversionsForReverseMapping() { } @Test - public void shouldApplyConversionsToMappedPropertiesForReverseMapping() { + void shouldApplyConversionsToMappedPropertiesForReverseMapping() { Target target = new Target(); target.setQax( 42 ); target.setBaz( 23L ); @@ -82,7 +82,7 @@ public void shouldApplyConversionsToMappedPropertiesForReverseMapping() { } @Test - public void shouldWorkWithAbstractClass() { + void shouldWorkWithAbstractClass() { Source source = new Source(); source.setFoo( 42 ); source.setBar( 23L ); diff --git a/integrationtest/src/test/resources/springTest/pom.xml b/integrationtest/src/test/resources/springTest/pom.xml index 3c1fb54552..e4210c0cba 100644 --- a/integrationtest/src/test/resources/springTest/pom.xml +++ b/integrationtest/src/test/resources/springTest/pom.xml @@ -18,6 +18,10 @@ springTest jar + + + ${org.junit6.jupiter.version} + diff --git a/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java b/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java index a5b3bb0e65..c0f3de4ce2 100644 --- a/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java +++ b/integrationtest/src/test/resources/springTest/src/test/java/org/mapstruct/itest/spring/SpringBasedMapperTest.java @@ -5,14 +5,14 @@ */ package org.mapstruct.itest.spring; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mapstruct.itest.spring.SpringBasedMapperTest.SpringTestConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; @@ -22,8 +22,8 @@ * @author Andreas Gudian */ @ContextConfiguration(classes = SpringTestConfig.class) -@RunWith(SpringJUnit4ClassRunner.class) -public class SpringBasedMapperTest { +@ExtendWith(SpringExtension.class) +class SpringBasedMapperTest { @Configuration @ComponentScan(basePackageClasses = SpringBasedMapperTest.class) @@ -40,7 +40,7 @@ public static class SpringTestConfig { private SecondDecoratedSourceTargetMapper secondDecoratedMapper; @Test - public void shouldInjectSpringBasedMapper() { + void shouldInjectSpringBasedMapper() { Source source = new Source(); Target target = mapper.sourceToTarget( source ); @@ -51,7 +51,7 @@ public void shouldInjectSpringBasedMapper() { } @Test - public void shouldInjectDecorator() { + void shouldInjectDecorator() { Source source = new Source(); Target target = decoratedMapper.sourceToTarget( source ); @@ -68,7 +68,7 @@ public void shouldInjectDecorator() { } @Test - public void shouldInjectSecondDecorator() { + void shouldInjectSecondDecorator() { Source source = new Source(); Target target = secondDecoratedMapper.sourceToTarget( source ); diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml index 5ab2d0d18f..f122047093 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/generator/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml index d1e1dd7dff..4c5e4611f0 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java index 4a012283d3..f34bebe36d 100644 --- a/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java +++ b/integrationtest/src/test/resources/superTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/supertypegeneration/usage/GeneratedBasesTest.java @@ -5,9 +5,9 @@ */ package org.mapstruct.itest.supertypegeneration.usage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mapstruct.itest.supertypegeneration.usage.Order; import org.mapstruct.itest.supertypegeneration.usage.OrderDto; import org.mapstruct.itest.supertypegeneration.usage.OrderMapper; @@ -18,10 +18,10 @@ * * @author Gunnar Morling */ -public class GeneratedBasesTest { +class GeneratedBasesTest { @Test - public void considersPropertiesOnGeneratedSourceAndTargetTypes() { + void considersPropertiesOnGeneratedSourceAndTargetTypes() { Order order = new Order(); order.setItem( "my item" ); order.setBaseName2( "my base name 2" ); diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml index 67df383a18..89bd9c2d2f 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/generator/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml index bd06b79a49..0726580592 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java index d9e3f8d789..d7fb6b00fa 100644 --- a/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java +++ b/integrationtest/src/test/resources/targetTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/targettypegeneration/usage/GeneratedTargetTypeTest.java @@ -5,9 +5,9 @@ */ package org.mapstruct.itest.targettypegeneration.usage; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Integration test for using MapStruct with another annotation processor that generates the target type of a mapping @@ -15,10 +15,10 @@ * * @author Gunnar Morling */ -public class GeneratedTargetTypeTest { +class GeneratedTargetTypeTest { @Test - public void considersPropertiesOnGeneratedSourceAndTargetTypes() { + void considersPropertiesOnGeneratedSourceAndTargetTypes() { Order order = new Order(); order.setItem( "my item" ); diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml index 6ac3a01297..24d3436533 100644 --- a/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/generator/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml index 79696df47d..d7154c6246 100644 --- a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/pom.xml @@ -21,8 +21,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter test diff --git a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java index e715e66620..55ea60a0ad 100644 --- a/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java +++ b/integrationtest/src/test/resources/usesTypeGenerationTest/usage/src/test/java/org/mapstruct/itest/usestypegeneration/usage/GeneratedUsesTypeTest.java @@ -5,7 +5,7 @@ */ package org.mapstruct.itest.usestypegeneration.usage; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -14,10 +14,10 @@ * * @author Filip Hrisafov */ -public class GeneratedUsesTypeTest { +class GeneratedUsesTypeTest { @Test - public void considersPropertiesOnGeneratedSourceAndTargetTypes() { + void considersPropertiesOnGeneratedSourceAndTargetTypes() { Order order = new Order(); order.setItem( "my item" ); diff --git a/parent/pom.xml b/parent/pom.xml index c4ba63948d..f3b0fe25f9 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -141,11 +141,6 @@ gem-processor ${org.mapstruct.gem.version} - - junit - junit - 4.13.1 - com.puppycrawl.tools checkstyle @@ -201,7 +196,7 @@ org.jboss.arquillian arquillian-bom - 1.6.0.Final + 1.7.2.Final import pom From f76f11c08defcc8bb507c9247e7c217087397634 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Sun, 15 Mar 2026 15:20:33 +0100 Subject: [PATCH 0967/1006] Enforce spaces inside parentheses for control flow statements via checkstyle --- .../src/main/resources/build-config/checkstyle.xml | 2 +- core/src/main/java/org/mapstruct/factory/Mappers.java | 4 ++-- .../main/java/org/mapstruct/ap/MappingProcessor.java | 2 +- .../mapstruct/ap/internal/conversion/Conversions.java | 2 +- .../ap/internal/model/AbstractBaseBuilder.java | 4 ++-- .../mapstruct/ap/internal/model/BeanMappingMethod.java | 2 +- .../ap/internal/model/DefaultMapperReference.java | 2 +- .../java/org/mapstruct/ap/internal/model/Mapper.java | 6 +++--- .../ap/internal/model/MappingBuilderContext.java | 2 +- .../ap/internal/model/NestedPropertyMappingMethod.java | 2 +- .../ap/internal/model/ObjectFactoryMethodResolver.java | 2 +- .../mapstruct/ap/internal/model/PropertyMapping.java | 10 +++++----- ...etterWrapperForCollectionsAndMapsWithNullCheck.java | 2 +- .../internal/model/beanmapping/MappingReference.java | 8 ++++---- .../internal/model/beanmapping/MappingReferences.java | 2 +- .../ap/internal/model/common/BuilderType.java | 2 +- .../org/mapstruct/ap/internal/model/common/Type.java | 8 ++++---- .../ap/internal/model/common/TypeFactory.java | 6 +++--- .../ap/internal/model/source/MappingMethodOptions.java | 4 ++-- .../ap/internal/model/source/MethodMatcher.java | 2 +- .../source/selector/JakartaXmlElementDeclSelector.java | 4 ++-- .../source/selector/JavaxXmlElementDeclSelector.java | 4 ++-- .../selector/MostSpecificResultTypeSelector.java | 2 +- .../internal/model/source/selector/TypeSelector.java | 2 +- .../processor/creation/MappingResolverImpl.java | 6 +++--- .../java/org/mapstruct/ap/internal/util/Strings.java | 4 ++-- .../ap/test/bugs/_1482/TargetSourceMapper.java | 2 +- .../ap/test/bugs/_1801/Issue1801BuilderProvider.java | 2 +- .../org/mapstruct/ap/test/bugs/_2663/JsonNullable.java | 2 +- .../org/mapstruct/ap/test/bugs/_2663/Nullable.java | 2 +- .../ap/test/bugs/_3089/Issue3089BuilderProvider.java | 2 +- ...nalMethodWithSourcePropertyNameInContextMapper.java | 2 +- ...nalMethodWithTargetPropertyNameInContextMapper.java | 2 +- .../mapstruct/ap/test/nestedbeans/RecursionTest.java | 6 +++--- .../selection/ExternalHandWrittenMapper.java | 2 +- 35 files changed, 59 insertions(+), 59 deletions(-) diff --git a/build-config/src/main/resources/build-config/checkstyle.xml b/build-config/src/main/resources/build-config/checkstyle.xml index 71a7d35899..14567bf067 100644 --- a/build-config/src/main/resources/build-config/checkstyle.xml +++ b/build-config/src/main/resources/build-config/checkstyle.xml @@ -141,7 +141,7 @@ - + diff --git a/core/src/main/java/org/mapstruct/factory/Mappers.java b/core/src/main/java/org/mapstruct/factory/Mappers.java index 05b616fe9a..d20bd59fa3 100644 --- a/core/src/main/java/org/mapstruct/factory/Mappers.java +++ b/core/src/main/java/org/mapstruct/factory/Mappers.java @@ -84,10 +84,10 @@ private static T doGetMapper(Class clazz, ClassLoader classLoader) throws return constructor.newInstance(); } - catch (ClassNotFoundException e) { + catch ( ClassNotFoundException e ) { return getMapperFromServiceLoader( clazz, classLoader ); } - catch ( InstantiationException | InvocationTargetException | IllegalAccessException e) { + catch ( InstantiationException | InvocationTargetException | IllegalAccessException e ) { throw new RuntimeException( e ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java index 32e65c7047..01a2a35955 100644 --- a/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/MappingProcessor.java @@ -264,7 +264,7 @@ private Set getMappers(final Set annotations try { Set annotatedMappers = roundEnvironment.getElementsAnnotatedWith( annotation ); - for (Element mapperElement : annotatedMappers) { + for ( Element mapperElement : annotatedMappers ) { TypeElement mapperTypeElement = asTypeElement( mapperElement ); // on some JDKs, RoundEnvironment.getElementsAnnotatedWith( ... ) returns types with diff --git a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java index 7b2f8702b1..c29ad5141e 100755 --- a/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/conversion/Conversions.java @@ -355,7 +355,7 @@ public ConversionProvider getConversion(Type sourceType, Type targetType) { else if ( targetType.isOptionalType() ) { // Type -> Optional Type targetBaseType = targetType.getOptionalBaseType(); - if ( targetBaseType.equals( sourceType )) { + if ( targetBaseType.equals( sourceType ) ) { return TypeToOptionalConversion.TYPE_TO_OPTIONAL_CONVERSION; } ConversionProvider conversionProvider = getInternalConversion( sourceType, targetBaseType ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java index 584e0260bc..8859e542b8 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/AbstractBaseBuilder.java @@ -115,8 +115,8 @@ Assignment createForgedAssignment(SourceRHS source, ForgedMethod methodRef, Mapp if ( mappingMethod == null ) { return null; } - if (methodRef.getMappingReferences().isRestrictToDefinedMappings() || - !ctx.getMappingsToGenerate().contains( mappingMethod )) { + if ( methodRef.getMappingReferences().isRestrictToDefinedMappings() || + !ctx.getMappingsToGenerate().contains( mappingMethod ) ) { // If the mapping options are restricted only to the defined mappings, then use the mapping method. // See https://github.com/mapstruct/mapstruct/issues/1148 ctx.getMappingsToGenerate().add( mappingMethod ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java index d67b550ad4..a73bce56e3 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/BeanMappingMethod.java @@ -629,7 +629,7 @@ private boolean isCorrectlySealed(Type mappingSourceType) { List unusedPermittedSubclasses = new ArrayList<>( mappingSourceType.getPermittedSubclasses() ); method.getOptions().getSubclassMappings().forEach( subClassOption -> { - for (Iterator iterator = unusedPermittedSubclasses.iterator(); + for ( Iterator iterator = unusedPermittedSubclasses.iterator(); iterator.hasNext(); ) { if ( ctx.getTypeUtils().isSameType( iterator.next(), subClassOption.getSource() ) ) { iterator.remove(); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java index 6ac0c1c74d..2728f99323 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/DefaultMapperReference.java @@ -36,7 +36,7 @@ private DefaultMapperReference(Type type, boolean isAnnotatedMapper, boolean isS public static DefaultMapperReference getInstance(Type type, boolean isAnnotatedMapper, boolean isSingleton, TypeFactory typeFactory, List otherMapperReferences) { Set importTypes = Collections.asSet( type ); - if ( isAnnotatedMapper && !isSingleton) { + if ( isAnnotatedMapper && !isSingleton ) { importTypes.add( typeFactory.getType( "org.mapstruct.factory.Mappers" ) ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java index cd092ca4f4..bcf7e840e5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/Mapper.java @@ -199,12 +199,12 @@ protected String getTemplateName() { * @return the flat name for the type element */ public static String getFlatName(TypeElement element) { - if (!(element.getEnclosingElement() instanceof TypeElement)) { + if ( !(element.getEnclosingElement() instanceof TypeElement) ) { return element.getSimpleName().toString(); } StringBuilder nameBuilder = new StringBuilder( element.getSimpleName().toString() ); - for (Element enclosing = element.getEnclosingElement(); enclosing instanceof TypeElement; enclosing = - enclosing.getEnclosingElement()) { + for ( Element enclosing = element.getEnclosingElement(); enclosing instanceof TypeElement; enclosing = + enclosing.getEnclosingElement() ) { nameBuilder.insert( 0, '$' ); nameBuilder.insert( 0, enclosing.getSimpleName().toString() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java index 1ebf99ffeb..59c3efd141 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/MappingBuilderContext.java @@ -228,7 +228,7 @@ public List getReservedNames() { nameSet.add( method.getName() ); } // add existing names - for ( SourceMethod method : sourceModel) { + for ( SourceMethod method : sourceModel ) { if ( method.isAbstract() ) { nameSet.add( method.getName() ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java index ed841ba5bc..6fbd5e6f82 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/NestedPropertyMappingMethod.java @@ -179,7 +179,7 @@ public List getPropertyEntries() { @Override public Set getImportTypes() { Set types = super.getImportTypes(); - for ( SafePropertyEntry propertyEntry : safePropertyEntries) { + for ( SafePropertyEntry propertyEntry : safePropertyEntries ) { types.addAll( propertyEntry.getType().getImportTypes() ); if ( propertyEntry.getPresenceChecker() != null ) { types.addAll( propertyEntry.getPresenceChecker().getImportTypes() ); diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java index 8b526b9177..88965dedca 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/ObjectFactoryMethodResolver.java @@ -74,7 +74,7 @@ public static MethodReference getFactoryMethod( Method method, ctx ); - if (matchingFactoryMethods.isEmpty()) { + if ( matchingFactoryMethods.isEmpty() ) { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java index c120f035b2..5defa65bf5 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java @@ -314,7 +314,7 @@ private Assignment forge( ) { else if ( sourceType.isMapType() && targetType.isMapType() ) { assignment = forgeMapMapping( sourceType, targetType, rightHandSide ); } - else if ( sourceType.isMapType() && !targetType.isMapType()) { + else if ( sourceType.isMapType() && !targetType.isMapType() ) { assignment = forgeMapping( sourceType, targetType.withoutBounds(), rightHandSide ); } else if ( ( sourceType.isIterableType() && targetType.isStreamType() ) @@ -427,7 +427,7 @@ private Assignment assignToPlainViaSetter(Type targetType, Assignment rhs) { Assignment factory = ObjectFactoryMethodResolver .getFactoryMethod( method, targetType, SelectionParameters.forSourceRHS( rightHandSide ), ctx ); - if ( factory == null && targetBuilderType != null) { + if ( factory == null && targetBuilderType != null ) { // If there is no dedicated factory method and the target has a builder we will try to use that MethodReference builderFactoryMethod = ObjectFactoryMethodResolver.getBuilderFactoryMethod( targetType, @@ -732,9 +732,9 @@ private PresenceCheck getSourcePresenceCheckerRef(SourceReference sourceReferenc String variableName = sourceParam.getName() + "." + propertyEntry.getReadAccessor().getReadValueSource(); Type variableType = propertyEntry.getType(); - for (int i = 1; i < sourceReference.getPropertyEntries().size(); i++) { + for ( int i = 1; i < sourceReference.getPropertyEntries().size(); i++ ) { PropertyEntry entry = sourceReference.getPropertyEntries().get( i ); - if (entry.getPresenceChecker() != null && entry.getReadAccessor() != null) { + if ( entry.getPresenceChecker() != null && entry.getReadAccessor() != null ) { if ( variableType.isOptionalType() ) { presenceChecks.add( new OptionalPresenceCheck( variableName, @@ -852,7 +852,7 @@ private Assignment forgeMapping(Type sourceType, Type targetType, SourceRHS sour // because we are forging a Mapping for a method with multiple source parameters. // If the target type is enum, then we can't create an update method if ( !targetType.isEnumType() && ( method.isUpdateMethod() || forceUpdateMethod ) - && targetWriteAccessorType != AccessorType.ADDER) { + && targetWriteAccessorType != AccessorType.ADDER ) { parameters.add( Parameter.forForgedMappingTarget( targetType ) ); returnType = ctx.getTypeFactory().createVoidType(); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java index a0c9f799e9..b9f1d2acb0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/assignment/SetterWrapperForCollectionsAndMapsWithNullCheck.java @@ -57,7 +57,7 @@ public Set getImportTypes() { imported.add( typeFactory.getType( EnumSet.class ) ); } } - if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) { + if ( isDirectAssignment() || getSourcePresenceCheckerReference() == null ) { imported.addAll( getNullCheckLocalVarType().getImportTypes() ); } return imported; diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java index d013a77a7a..9baa84dc77 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReference.java @@ -45,7 +45,7 @@ public TargetReference getTargetReference() { public MappingReference popTargetReference() { if ( targetReference != null ) { TargetReference newTargetReference = targetReference.pop(); - if (newTargetReference != null ) { + if ( newTargetReference != null ) { return new MappingReference(mapping, newTargetReference, sourceReference ); } } @@ -55,7 +55,7 @@ public MappingReference popTargetReference() { public MappingReference popSourceReference() { if ( sourceReference != null ) { SourceReference newSourceReference = sourceReference.pop(); - if (newSourceReference != null ) { + if ( newSourceReference != null ) { return new MappingReference(mapping, targetReference, newSourceReference ); } } @@ -76,7 +76,7 @@ public boolean equals(Object o) { return false; } - if (!Objects.equals( mapping.getTargetName(), that.mapping.getTargetName() ) ) { + if ( !Objects.equals( mapping.getTargetName(), that.mapping.getTargetName() ) ) { return false; } @@ -97,7 +97,7 @@ public boolean equals(Object o) { } - if (!Objects.equals( sourceReference.getPropertyEntries(), that.sourceReference.getPropertyEntries() ) ) { + if ( !Objects.equals( sourceReference.getPropertyEntries(), that.sourceReference.getPropertyEntries() ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java index ced945bb90..edc5b3157e 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/beanmapping/MappingReferences.java @@ -109,7 +109,7 @@ public boolean hasNestedTargetReferences() { for ( MappingReference mappingRef : mappingReferences ) { TargetReference targetReference = mappingRef.getTargetReference(); - if ( targetReference.isNested()) { + if ( targetReference.isNested() ) { return true; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java index 9300f683ce..f399c46dc9 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/BuilderType.java @@ -108,7 +108,7 @@ else if ( typeUtils.isSameType( builder.getTypeMirror(), builderCreationOwner ) // When the builderCreationMethod is constructor, its return type is Void. In this case the // builder type should be the owner type. - if (builderInfo.getBuilderCreationMethod().getKind() == ElementKind.CONSTRUCTOR) { + if ( builderInfo.getBuilderCreationMethod().getKind() == ElementKind.CONSTRUCTOR ) { builder = owner; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java index 6287403ba3..8f512c3ace 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/Type.java @@ -285,7 +285,7 @@ public String createReferenceName() { return name; } - if ( isTopLevelTypeToBeImported() && nameWithTopLevelTypeName != null) { + if ( isTopLevelTypeToBeImported() && nameWithTopLevelTypeName != null ) { return nameWithTopLevelTypeName; } @@ -1346,7 +1346,7 @@ public String describe() { private String getNameKeepingInnerClasses() { String packageNamePrefix = getPackageName() + "."; String fullyQualifiedName = getFullyQualifiedName(); - if (fullyQualifiedName.startsWith( packageNamePrefix ) ) { + if ( fullyQualifiedName.startsWith( packageNamePrefix ) ) { return fullyQualifiedName.substring( packageNamePrefix.length() ); } return fullyQualifiedName; @@ -1665,7 +1665,7 @@ else if ( typeToMatch.hasSuperBound() && parameterized.getSuperBound() != null return new ResolvedPair( typeFactory.getType( parameterized ), declared ); } } - else if (parameterized.getSuperBound() != null ) { + else if ( parameterized.getSuperBound() != null ) { ResolvedPair match = visit( parameterized.getSuperBound(), declared ); if ( match.match != null ) { return new ResolvedPair( typeFactory.getType( parameterized ), declared ); @@ -1897,7 +1897,7 @@ public List getPermittedSubclasses() { if ( kotlinMetadata != null ) { return kotlinMetadata.getPermittedSubclasses(); } - if (SEALED_PERMITTED_SUBCLASSES_METHOD == null) { + if ( SEALED_PERMITTED_SUBCLASSES_METHOD == null ) { return emptyList(); } try { diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java index 606bbce69d..37c38ab590 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/common/TypeFactory.java @@ -294,7 +294,7 @@ else if ( mirror.getKind() == TypeKind.ARRAY ) { packageName = elementUtils.getPackageOf( componentTypeElement ).getQualifiedName().toString(); qualifiedName = componentTypeElement.getQualifiedName().toString() + arraySuffix; } - else if (componentTypeMirror.getKind().isPrimitive()) { + else if ( componentTypeMirror.getKind().isPrimitive() ) { // When the component type is primitive and is annotated with ElementType.TYPE_USE then // the typeMirror#toString returns (@CustomAnnotation :: byte) for the javac compiler name = NativeTypes.getName( componentTypeMirror.getKind() ) + builder.toString(); @@ -497,7 +497,7 @@ public List getThrownTypes(ExecutableType method) { } public List getThrownTypes(Accessor accessor) { - if (accessor.getAccessorType().isFieldAssignment()) { + if ( accessor.getAccessorType().isFieldAssignment() ) { return new ArrayList<>(); } Element element = accessor.getElement(); @@ -526,7 +526,7 @@ private List getTypeParameters(TypeMirror mirror, boolean isImplementation List typeArguments = declaredType.getTypeArguments(); List typeParameters = new ArrayList<>( typeArguments.size() ); - for ( TypeMirror typeParameter : typeArguments) { + for ( TypeMirror typeParameter : typeArguments ) { Type type = getType( typeParameter ); typeParameters.add( isImplementationType ? type.getTypeBound() : type ); } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java index 08ac1a683a..ea62ee3657 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MappingMethodOptions.java @@ -246,11 +246,11 @@ private boolean methodsHaveIdenticalSignature(SourceMethod templateMethod, Sourc } private boolean parametersAreOfIdenticalTypeAndOrder(SourceMethod templateMethod, SourceMethod sourceMethod) { - if (templateMethod.getParameters().size() != sourceMethod.getParameters().size()) { + if ( templateMethod.getParameters().size() != sourceMethod.getParameters().size() ) { return false; } for ( int i = 0; i < templateMethod.getParameters().size(); i++ ) { - if (!templateMethod.getParameters().get( i ).getType().equals( + if ( !templateMethod.getParameters().get( i ).getType().equals( sourceMethod.getParameters().get( i ).getType() ) ) { return false; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java index 3d8bfea135..c62012472c 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/MethodMatcher.java @@ -165,7 +165,7 @@ private boolean lineUp() { // Represent result as map. Map resolvedPairs = new HashMap<>(); for ( TypeVarCandidate candidate : methodParCandidates.values() ) { - for ( Type.ResolvedPair pair : candidate.pairs) { + for ( Type.ResolvedPair pair : candidate.pairs ) { resolvedPairs.put( pair.getParameter(), pair.getMatch() ); } } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java index df5cd848a5..d5595ef6b7 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JakartaXmlElementDeclSelector.java @@ -28,7 +28,7 @@ class JakartaXmlElementDeclSelector extends XmlElementDeclSelector { XmlElementDeclInfo getXmlElementDeclInfo(Element element) { XmlElementDeclGem gem = XmlElementDeclGem.instanceOn( element ); - if (gem == null) { + if ( gem == null ) { return null; } @@ -39,7 +39,7 @@ XmlElementDeclInfo getXmlElementDeclInfo(Element element) { XmlElementRefInfo getXmlElementRefInfo(Element element) { XmlElementRefGem gem = XmlElementRefGem.instanceOn( element ); - if (gem == null) { + if ( gem == null ) { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java index 1d02e97e90..912da3e696 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/JavaxXmlElementDeclSelector.java @@ -28,7 +28,7 @@ class JavaxXmlElementDeclSelector extends XmlElementDeclSelector { XmlElementDeclInfo getXmlElementDeclInfo(Element element) { XmlElementDeclGem gem = XmlElementDeclGem.instanceOn( element ); - if (gem == null) { + if ( gem == null ) { return null; } @@ -39,7 +39,7 @@ XmlElementDeclInfo getXmlElementDeclInfo(Element element) { XmlElementRefInfo getXmlElementRefInfo(Element element) { XmlElementRefGem gem = XmlElementRefGem.instanceOn( element ); - if (gem == null) { + if ( gem == null ) { return null; } diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java index 87ec3b4dc1..88e302eba0 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/selector/MostSpecificResultTypeSelector.java @@ -23,7 +23,7 @@ public List> getMatchingMethods(List